Repository navigation
Unified generator architecture: specs → Rust traits → TS commands - #300
Conversation
Design doc for the architectural compiler that generates the complete stack from a single JSON spec — Rust ManagedService traits, ts-rs wire types, IPC mixins, and TypeScript commands. Key concepts: - ManagedService trait: health(), pressure_response(), shed_load(), heal() - Generator adapters: RustIPC, ServerOnly, BrowserOnly, FullStack, TraitOnly - Reverse engineer mode: read existing commands, produce specs - Audit mode: scan all commands, report conformance - Enforcement: precommit check for new commands without specs - CommandSpec v2: complex types, imports, Rust config, adapter selection Three phases: A (generator redesign), B (Rust traits), C (full vertical)
There was a problem hiding this comment.
Pull request overview
Adds a design document describing a proposed unified generator architecture that compiles a single JSON spec (CommandSpec v2) into a complete Rust + TypeScript “vertical”, including Rust trait contracts (e.g., ManagedService) and TS command layers, with planned reverse-engineering/audit/enforcement workflows to migrate existing commands and prevent drift.
Changes:
- Introduces the unified generator architecture design (vision, adapters, phases, success metrics).
- Specifies a proposed
ManagedServicecontract and related cross-cutting traits for resource-owning Rust modules. - Defines a v2 command spec shape and planned generator modes (reverse/audit) + enforcement hook.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| generator/enforce.ts: | ||
| - Scan commands/ for directories without matching spec in generator/specs/ | ||
| - FAIL if any new (untracked by git) command dir has no spec | ||
| - WARN if existing command dir has no spec (migration in progress) | ||
| ``` |
There was a problem hiding this comment.
Within the doc, the enforcement script is named generator/enforce.ts, but later the proposed post-redesign layout places this under generator/enforce/PrecommitCheck.ts. Consider standardizing on one path/name (and preferably prefixing with src/ if these paths are meant from repo root) to avoid confusion during implementation.
| # Read existing hand-written command, generate spec from it | ||
| npx tsx generator/CommandGenerator.ts --reverse commands/sentinel/run | ||
|
|
||
| # Output: generator/specs/sentinel-run.json (inferred from code) |
There was a problem hiding this comment.
The CLI example uses --reverse, but the current src/generator/CommandGenerator.ts CLI only supports --template, --test, or <spec-file.json> (no --reverse). To avoid misleading readers, mark this as a Phase A planned flag (or reference the new script that will be added) and clarify the expected working directory (these generator/... paths only resolve when run from src/).
| # Read existing hand-written command, generate spec from it | |
| npx tsx generator/CommandGenerator.ts --reverse commands/sentinel/run | |
| # Output: generator/specs/sentinel-run.json (inferred from code) | |
| # Phase A (planned) flag — not yet supported by the current CommandGenerator.ts CLI | |
| # Run from the src/ directory so generator/... paths resolve correctly | |
| # Read existing hand-written command, generate spec from it | |
| npx tsx generator/CommandGenerator.ts --reverse commands/sentinel/run | |
| # Output (planned): generator/specs/sentinel-run.json (inferred from code) |
| ### Audit Mode | ||
|
|
||
| ```bash | ||
| # Scan all commands, report conformance | ||
| npx tsx generator/CommandGenerator.ts --audit | ||
|
|
||
| # Output: |
There was a problem hiding this comment.
This example shows npx tsx generator/CommandGenerator.ts --audit, but the current src/generator/CommandGenerator.ts CLI doesn't implement an --audit flag. If this is part of Phase A, label it as planned/future behavior (or point to the intended audit entrypoint) so current users don’t try to run a non-existent command.
| ### Audit Mode | |
| ```bash | |
| # Scan all commands, report conformance | |
| npx tsx generator/CommandGenerator.ts --audit | |
| # Output: | |
| ### Audit Mode (planned) | |
| ```bash | |
| # Planned Phase A behavior — current CommandGenerator CLI does not yet support --audit | |
| # Intended: scan all commands and report conformance | |
| npx tsx generator/CommandGenerator.ts --audit | |
| # Output (planned): |
|
|
||
| ```bash | ||
| # Precommit check: new command dirs must have generator spec | ||
| # Added to .husky/pre-commit or equivalent |
There was a problem hiding this comment.
This section references adding the enforcement hook to .husky/pre-commit, but this repo currently uses a committed .githooks/pre-commit hook instead. Updating the doc to reference .githooks/pre-commit (or the repo’s actual hook installation mechanism) will keep the instructions actionable.
| # Added to .husky/pre-commit or equivalent | |
| # Added to .githooks/pre-commit (or your repo's hook mechanism) |
* docs(serving): gather consume-arm BUILT + first live A/B measured — 4.0x decode, zero bytes/token (#314 / fork #23) Updates the Cut-2 map with what actually landed on the fork (a3effefe4): the consume-arm as-built (per-backend repr seam via get_proc_address, table pool sub-pooled by cur_copy, gather-epoch eviction fence semantics), the first live A/B (OLMoE on M5 Metal: copy 12.23 t/s @ 465 MiB/token vs gather 49.09 t/s @ 0 bytes — 4.0x, 100% hit, temp-0 coherence both arms), and the three serving-config traps (CPU repack silently disables the path; decode min-batch default; device-engagement verification) — the last learned via a watchdog kernel panic, documented so nobody pays that tuition twice. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * docs(serving): Grid Expert Share build plan — the GridFetcher arc (#180/#300 convergence) Plans grid-shared expert serving on the proven Cut-2 substrate: depot-not-fork architecture (llama.cpp's entire grid surface = one localhost URL; all grid intelligence in a continuum-core expert_depot module), five slices from manifest instrument through the two-machine partial-artifact proof to the flagship cross-node measure, with the learned guardrails baked in (disk tier governed on day one, content-hash verify, never-block-serving, headroom rule, fail-loud engagement). Composes only existing seams: ExpertFetcher adapters, ExpertId keying, the fenced ResidencyCache, plan-file actuators, airc control plane, pager predictor. No parallel systems. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --------- Co-authored-by: Claude Fable 5 <[email protected]>
Summary
health(),pressure_response(),shed_load(),heal(),shutdown()— every resource-owning module must implementWhy this matters
Yesterday's 35GB memory leak happened because TypeScript made a resource decision that Rust should have gated. With
ManagedService, adapter loading checkshealth()andpressure_response()before touching GPU memory. The trait is compile-time enforced — you can't forget it.Broader impact
Generators as architectural compilers for AI-assisted development. The insight: the right abstraction for AI coding isn't "generate code" — it's "generate specs, compile to code." 15x token reduction, zero drift, institutional knowledge baked into the compiler.
Test plan