agentleFS
joelbarmettlerUZHjoelbarmettlerUZH/ultrainit.sh/lib/CLAUDE.md

ultrainit.sh / lib

CLAUDE.md8 starsChanged 7 months agoApache-2.0View on GitHub

Nine shell modules implementing ultrainit's five-phase pipeline. Each file exposes one top-level entry function. All inter-module communication happens via exported globals and files in $WORK_DIR. All tests and ultrainit.sh source libs in this exact order: utils.sh must come first (logging). config.sh requires utils logging. agent.sh requires both. Phase modules can reference any earlier module's functions. Never source a single lib in isolation — synthesize.sh sets shopt -s nullglob globally at source time, which affects glob patterns in other modules. Every…

  • Deletes or force-pushes

The file

We split this CLAUDE.md into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All tests and ultrainit.sh source libs in this exact order:

    line 21
  2. Very specific:

    Every phase entry function begins with this exact pattern (gather.sh:7, synthesize.sh:16, ask.sh:28):

    line 31
  3. Very specific:

    Budget retries consume additional budget: If synthesis retries 3 times and fails, all attempt costs accumulate in .cost files.

    line 94

≈ “Common” is an estimate: at least 1 in 5 of the 28,029 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

lib/ — Core Orchestration Library

Nine shell modules implementing ultrainit's five-phase pipeline. Each file exposes one top-level entry function. All inter-module communication happens via exported globals and files in $WORK_DIR.

Module Map

FileEntry FunctionPhaseResponsibility
utils.sh(foundation)allLogging, state.json, JSON helpers, cost reporting, spinner
config.shsetup_work_dir()startupDependency checks, budget arithmetic, global defaults
agent.shrun_agent()allAgent spawning, parallel execution, failure diagnosis
gather.shgather_evidence()18 parallel gather agents + deep-dive agents
ask.shask_developer()2Interactive developer interview (5 questions)
research.shrun_research()3Domain research + MCP discovery
synthesize.shsynthesize()4Two-pass synthesis with retry logic
validate.shvalidate_artifacts()5aQuality checks + revision agent
merge.shwrite_artifacts()5bBackup + atomic file writes

Sourcing Order

All tests and ultrainit.sh source libs in this exact order:

utils.sh → config.sh → agent.sh → gather.sh → ask.sh → research.sh → synthesize.sh → validate.sh → merge.sh

utils.sh must come first (logging). config.sh requires utils logging. agent.sh requires both. Phase modules can reference any earlier module's functions. Never source a single lib in isolation — synthesize.sh sets shopt -s nullglob globally at source time, which affects glob patterns in other modules.

Key Patterns

Resumable Phase Guard

Every phase entry function begins with this exact pattern (gather.sh:7, synthesize.sh:16, ask.sh:28):

if is_phase_complete "phase_name" && [[ "$FORCE" != "true" ]]; then
    log_info "Phase already complete. Use --force to rerun."
    return 0
fi

is_phase_complete reads $WORK_DIR/state.json. mark_phase_complete writes to it atomically via a jq pipeline that re-initializes to {} on corruption. Never write to state.json directly.

Agent Invocation

All claude -p calls route through run_agent() in agent.sh. The signature:

run_agent <name> <prompt> <schema_file> <allowed_tools> [model] [phase]
  • name: used as the findings filename, log filename, cost filename, and mock dispatch key
  • prompt: if prefixed with @, treated as a file path and read before calling claude
  • schema_file: absolute path to $SCRIPT_DIR/schemas/<name>.json
  • allowed_tools: comma-separated list passed directly to --allowedTools

Prompts with shell-special characters (apostrophes, parens, backticks, $) must use the @file form. Inline prompts with these characters break parallel temp-script expansion. Always use absolute paths with @.

Parallel Execution

run_agents_parallel() receives agent invocation strings, writes each to a temp bash script, and spawns them with bash script &. Each temp script hard-bakes current variable values as export VAR="$VAR" literals before sourcing lib files. This prevents re-sourcing config.sh from overwriting already-computed AGENT_BUDGET. After all agents complete, failures are counted; temp dir is rm -rf'd.

Budget Tracking

  • Each agent writes phase|agent|cost to $WORK_DIR/costs/${name}.cost — one file per agent to avoid race conditions
  • check_budget() aggregates with awk -F'|' '{ sum += $3 }' across all .cost files
  • Budget arithmetic uses bc with scale=2 — result may be .20 not 0.20 for values < 1
  • Budget check is optimistic under parallelism: all agents in a batch check before any write costs

Failure Diagnosis

diagnose_phase_failure() collects the last 50 lines of each failed agent's stderr log and makes a low-cost Haiku call to interpret errors. Falls back to printing raw logs if Claude is unavailable. Always surfaces the error_max_structured_output_retries and error_max_budget_usd subtypes specifically.

Synthesis Context Building

build_docs_context() assembles all Phase 1+3 findings for Pass 1. build_tooling_context() assembles a reduced context for Pass 2 — it intentionally excludes key_files details, domain_terms, and skill_opportunities from module analyses to reduce token count. Pass 2 receives the Pass 1 CLAUDE.md output as its primary architecture reference.

estimate_tokens() uses bytes/4 heuristic. Actual token count for dense JSON may be higher. If synthesis fails with a context-length error, check logs/synthesis-docs.stderr and consider removing low-priority module findings from .ultrainit/findings/.

Merge Safety

merge_settings() uses jq -s '.[0] * .[1]' (deep merge). write_artifacts() checks file existence before every skill/hook/subagent write and silently skips existing files. backup_existing() copies CLAUDE.md and .claude/settings.json to a timestamped dir under $WORK_DIR/backups/ before any overwrites.

Critical Gotchas

config.sh recomputes budgets when re-sourced. Parallel child scripts use literal-baked values precisely to avoid this. Never add logic to config.sh that overwrites a variable that may already be exported.

postprocess_descriptions() strips angle brackets from skill descriptions. This runs in synthesize.sh after extraction. If a skill still has angle brackets after synthesis, validate-skill.sh catches it and the revision agent fixes it. Never add angle brackets to prompt examples for skill descriptions.

ask.sh reads from /dev/tty. In Docker or CI, /dev/tty may not exist. Always pass --non-interactive in headless environments — don't rely on the auto-detection fallback.

sed -i is not portable. GNU and BSD sed -i have mutually incompatible syntax. Use tmp=$(mktemp); sed 'expr' <"$file" >"$tmp" && mv "$tmp" "$file" for portable in-place edits. See utils.sh for the portable iso_date() pattern.

gensub() in awk is gawk-only. macOS stock awk and mawk do not have it. Use gsub() (POSIX) for simple replacements. The Dockerfile installs gawk, but check_dependencies() only checks that awk exists, not that it is gawk.

Budget retries consume additional budget. If synthesis retries 3 times and fails, all attempt costs accumulate in .cost files. Use --budget to raise the limit when debugging retries, or delete specific .cost files to reset individual agent budgets.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.