Crate Structure
Foundry is organised as a Cargo workspace with three crates:
foundry/
├── Cargo.toml # Workspace root
├── proto/foundry.proto # gRPC service definition
├── crates/
│ ├── foundry-core/ # Shared types (library)
│ ├── foundryd/ # Daemon (binary)
│ └── foundry-cli/ # CLI controller (binary)
└── book/ # This documentation
foundry-core
Shared types used by both the daemon and CLI:
event.rs—Eventstruct,EventTypeenum, deterministic ID generationthrottle.rs—Throttleenum (Full,AuditOnly,DryRun)task_block.rs—TaskBlocktrait,BlockKind,TaskBlockResult,RetryPolicyregistry.rs—Registry,ProjectEntry,ActionFlags,Stack,InstallConfigtrace.rs—TraceIndex,BlockExecution,ProcessResult— the structured types used to persist and display execution traces. Moved here fromfoundrydso the CLI can deserialise on-disk traces without depending on the daemon crate.
This crate has no async runtime dependency. It defines the vocabulary that the rest of the system speaks.
foundryd
The daemon process. Listens on gRPC (127.0.0.1:50051 by default) and runs
the workflow engine.
Core engine
engine.rs— event router: matches events to task blocks, executes them with retry logic, propagates emitted events respecting the throttle level. ExposesBlockExecutionandProcessResultfor structured telemetry.service.rs— gRPC service implementation (Emit,Status,Watch,Trace)
Daemon support modules
orchestrator.rs— coordinates per-project maintenance runs with concurrency control. DispatchesMaintenanceRunStartedper project, enforcesmax_concurrentvia a semaphore, and prevents double-running via an active project set with a drop-guard cleanup.event_writer.rs— appends every event to monthly JSONL files (YYYY-MM.jsonl) inside~/.foundry/events/(orFOUNDRY_EVENTS_DIR). Crash-safe: each write opens, flushes, and closes the file. AMutexserializes concurrent writes.trace_store.rs— in-memory store of recentProcessResultchains, keyed by root event ID. Used for fastTraceRPC lookups of workflows still in progress or recently completed.trace_writer.rs— persists completedProcessResultobjects to disk as pretty-printed JSON files under~/.foundry/traces/YYYY-MM-DD/{event_id}.json. Traces written here survive daemon restarts indefinitely and are read byfoundry historyandfoundry tracewhen the in-memory store has no match.workflow_tracker.rs— tracks workflows that are currently being processed by background tasks. Thread-safe viaRwLock. EachEmitRPC inserts anActiveWorkflowentry on start; a RAIIWorkflowGuardremoves it on completion or panic. TheStatusRPC reads this tracker to show live in-flight workflows.shell.rs— async shell runner used by block implementations. Runs an external command with configurable timeout (default 5 min), captures stdout and stderr, and returns aCommandResult.scanner.rs— vulnerability scanner abstraction. Dispatches to the stack-appropriate tool (cargo audit,npm audit,pip-audit,mix deps.audit) and normalizes output into aVec<Vulnerability>.gateway.rs— I/O abstraction layer for task blocks. DefinesShellGatewayandScannerGatewaytraits withProcessShellGatewayandProcessScannerGatewayproduction implementations. Also providesFakeShellGatewayandFakeScannerGatewaytest doubles (available under#[cfg(test)]only) that record invocations and return pre-configured results, enabling hermetic unit testing of every block without spawning real processes.summary.rs— renders aMaintenanceRunSummaryas a Markdown report (project table with success/failure/skipped, a failures section, and timing statistics).
Task block implementations (blocks/)
validate.rs—ValidateProject: pre-flight checks before a maintenance runresolve_gates.rs—ResolveGates: reads.hone-gates.jsonand emits gate definitionsrun_preflight_gates.rs—RunPreflightGates: runs gates on unmodified codebaserun_verify_gates.rs—RunVerifyGates: runs gates after code changesroute_gate_result.rs—RouteGateResult: routes pass/fail to completion or retryroute_validation_result.rs—RouteValidationResult: routes validation-only resultscheck_charter.rs—CheckCharter: validates project charter before iterationassess_project.rs—AssessProject: AI-driven project assessmenttriage_assessment.rs—TriageAssessment: prioritises assessment findingscreate_plan.rs—CreatePlan: generates an execution plan from triaged findingsexecute_plan.rs—ExecutePlan: executes the generated planexecute_maintain.rs—ExecuteMaintain: runs maintenance tasksretry_execution.rs—RetryExecution: retries failed executions with contextsummarize_result.rs—SummarizeResult: generates workflow summary and tracesgit_ops.rs—CommitAndPush: stages, commits, and optionally pushes changesaudit.rs—AuditReleaseTag,AuditMainBranch: vulnerability scanningrelease.rs—CutRelease,WatchPipeline: tagging and CI monitoringinstall.rs—InstallLocally: reinstalls the project locally after a fixremediate.rs—RemediateVulnerability: invokes the AI agent to fix a CVEscan.rs—ScanDependencies: scans for known vulnerabilitiesgreet.rs—ComposeGreeting,DeliverGreeting: hello-world engine validation
foundry-cli
The CLI controller. Connects to foundryd over gRPC.
main.rs—clap-based argument parsing; subcommands:emit,status,watch,trace,run,history,registrycommands.rs— async implementations of each subcommand viatonicgRPC client; also contains thehistorycommand which reads on-disk traces directly from~/.foundry/traces/without a daemon connectionregistry_commands.rs— pure I/O implementations of theregistrysubcommands (init,list,show,add,remove,edit); reads and writes~/.foundry/registry.jsonusingfoundry_core::registrytypes
proto/foundry.proto
The gRPC contract between CLI and daemon:
Emit— fire an event with type, project, throttle, and optional JSON payloadStatus— query active workflow states (all or by workflow ID)Watch— server-side streaming of live events, filterable by projectTrace— retrieve the full event chain and block execution records for a completed workflow