Repository navigation
feat(modules/generator): v2 enriched scaffold — types.rs + DESIGN.md + envelope dispatch + concurrency test (re-opens #1494) - #1499
Merged
Conversation
…+ envelope dispatch + concurrency test Per Joel 2026-05-30: > "Let's make sure we have detailed designs for this command > infrastructure into modules and properly built from the ground up > by using our own generators." Builds on the field manual (PR #1493) which codified the Module Design Template. This PR makes the GeneratorModule emit modules that MATCH that template — eat own dogfood, no future hand-rolled scaffolds. # Before vs after **v1 scaffold (PR #1487)** produced 2 files: - `mod.rs` — ServiceModule with raw-Err dispatch arms - `README.md` — author-facing summary The author had to hand-author types.rs, the typed envelope wiring, the test module, the concurrency stress-test scaffold, and the DESIGN.md. Every migration repeated the same boilerplate. **v2 scaffold** produces 4 files: - `mod.rs` — ServiceModule with typed envelope dispatch + handler methods + concurrency test scaffold (multi-thread tokio, `worker_threads = 4`) - `types.rs` — `<Cmd>Params` + `<Cmd>Result` per declared command, with `#[derive(TS)]`, `serde(rename_all = "camelCase")`, `export_to "../../../shared/generated/<name>/<Cmd>Params.ts"` - `DESIGN.md` — canonical per-module design skeleton with required section headers (Role / Command surface / Cross-module deps / State model / Events emitted / Concurrency contract / Migration notes / Kinks found) - `README.md` — author-facing summary referencing all four files + cross-refs to the field manual # New `--stateful` flag When `params.stateful = true`, the generator additionally emits: - `use dashmap::DashMap;` import - `ResourceState` placeholder struct - `resource_locks: DashMap<String, Arc<tokio::sync::Mutex<ResourceState>>>` field on the module struct - `fn resource_lock(&self, id: &str)` get-or-create helper - A second concurrency test (`resource_locks_stay_parallel_across_distinct_ids`) pinning the "different ids stay parallel" invariant Authors who set `stateful = true` get the per-resource lock pattern (per field manual §4.1) without writing any of the boilerplate. # Generated `mod.rs` shape (the substantive change) Each declared command now emits: ```rust // Dispatch arm: "<cmd>" => { let req = CommandRequest::<<CmdName>Params>::from_value(params)?; let result = self.handle_<verb>(req.params).await?; CommandResponse::ok(result).into_command_result() } // Typed handler method (scaffolded stub): pub async fn handle_<verb>( &self, params: <CmdName>Params, ) -> Result<<CmdName>Result, String> { Err("<cmd>: not yet implemented in this scaffolded module".to_string()) } ``` Authors replace ONE line — the `Err(...)` body — to fill in real logic. The envelope wiring is already in place; the typed params flow through to the handler; the typed result materializes through the response envelope automatically. # Naming helpers - `command_to_type_stem("chat", "chat/poll")` → `"Poll"` - `command_to_type_stem("chat", "chat/analyze/findings")` → `"AnalyzeFindings"` - `command_to_handler_name("chat", "chat/poll")` → `"handle_poll"` - `command_to_handler_name("chat", "chat/analyze/findings")` → `"handle_analyze_findings"` Strips the leading `<module>/` prefix when present; falls back to the full command path (PascalCase / snake_case). # Tests (39/39 pass — 22 new + 17 pre-existing) ## New template tests (14) - `mod_rs_contains_struct_definition_and_trait_impl` - `mod_rs_uses_typed_envelope_dispatch_for_each_command` ← v2 core - `mod_rs_emits_typed_handler_methods_for_each_command` ← v2 core - `mod_rs_imports_envelope_types_from_runtime` - `mod_rs_includes_with_executor_constructor_for_tests` - `mod_rs_emits_concurrency_stress_test_with_multi_thread_runtime` - `mod_rs_for_stateless_module_omits_resource_lock_scaffold` - `mod_rs_for_stateful_module_emits_per_resource_lock_scaffold` ← --stateful - `types_rs_emits_params_and_result_for_each_command` - `types_rs_annotates_for_ts_rs_export_with_camel_case` - `types_rs_for_command_less_module_emits_no_params_structs` - `design_md_includes_all_required_sections` - `design_md_lists_each_command_in_the_surface_table` - `design_md_state_section_reflects_stateful_flag` - `command_to_type_stem_strips_module_prefix_and_pascals` - `command_to_handler_name_strips_module_prefix_and_snakes` ## New filesystem dogfood (1) - `stateful_multi_command_scaffold_has_consistent_cross_references` — scaffolds a stateful 3-command module to a tempdir, then verifies every dispatch arm has a matching typed handler, every handler has a matching Params/Result type in types.rs, and the stateful lock scaffold cross-references match. Closest unit-level proof that a real consumer can `cargo check` the scaffold untouched. ## Pre-existing (all still pass) - All v1 generator tests + the per-name concurrency tests landed in PR #1487 still green. The `--stateful` flag is additive; the default `stateful: false` preserves v1 behavior at the dispatch level. # What this PR does NOT do - **Does NOT auto-wire the generated module** into `modules/mod.rs` at the parent or register at runtime startup. The README + next_step message both spell out the manual steps. A future `generate/refresh` command can automate this. - **Does NOT generate aliases** for legacy command prefixes (e.g., `collaboration/chat/*` → `chat/*`). The chat module's hand-written alias dispatch is the reference pattern; authors wire aliases manually until a `--alias` flag is added. - **Does NOT enforce specific Params/Result fields** — only scaffolds empty structs with the right derives. Authors add typed fields per the field manual's ts-rs annotation rules. - **Does NOT add `generate/command`** (add a new command to an existing module). That's a separate follow-up — flagged in field manual §6.1. # Migration story: next chat-analyze migration With v2 in place, the chat-analyze migration (the worked example from field manual §5.3) becomes: ```bash ./jtag generate/module \ --name "chat_analyze" \ --description "Long-running chat analysis with HandleRef + event streaming" \ --commands "chat/analyze,chat/analyze/findings,chat/analyze/complete,chat/analyze/cancel" \ --events-published "chat:analyze:finding,chat:analyze:complete,chat:analyze:cancelled" \ --priority normal \ --stateful # mints + tracks per-run state ``` Output: 4 files, all the boilerplate done. Author opens mod.rs, implements 4 handler bodies, opens types.rs, fills in 4 Params/Result pairs, opens DESIGN.md, writes the rationale. That's it — concurrency tests already primed, envelope wiring already correct, ts-rs bindings already declared. # References - [docs/architecture/COMMAND-INFRASTRUCTURE-FIELD-MANUAL.md](docs/architecture/COMMAND-INFRASTRUCTURE-FIELD-MANUAL.md) §3 (Module Design Template) — what this PR makes the generator emit - §4 (Concurrency doctrine) — what `--stateful` mode scaffolds - §6 (Generator usage) — the v2 invocation pattern - PR #1493 (field manual) - PR #1487 (v1 generator) Co-Authored-By: Claude Opus 4.7 <[email protected]>
Merged
3 tasks
joelteply
added a commit
that referenced
this pull request
May 31, 2026
…om workflow w14iiocs7 (#1500) * docs(planning): PERSONA-AS-DEVELOPER-GAP.md — substrate gap report from workflow w14iiocs7 Synthesis of the multi-agent audit run after PRs #1486–#1499 landed and the persona-as-developer + alignment-via-substrate-economics vision crystallized. # Headline finding 70% of the self-coding loop is in place. The remaining 30% is concentrated in three predictable seams: 1. **Filesystem introspection** — no `code/exists`, no flat `code/list` (readdir), no standalone `code/glob` 2. **Rust toolchain wrappers** — no structured `continuum-core/build` or `continuum-core/test`; only raw `code/shell/execute` 3. **Event-driven execution feedback** — `Stream` + `Lambda` cell shapes reserved but erroring; `events/command-completed` missing Close those seams and a persona can scaffold a module via `generate/module`, edit, build+test with structured errors, and subscribe to results on the realtime bus — full inner dev loop, no human in the path. # Recommended sprint ordering 1. **`code/exists` + `code/list` + `code/glob`** (Small, bundled) — highest leverage, lowest cost; unblocks safe self-scaffolding 2. **`continuum-core/build` + `continuum-core/test`** (Medium) — Rust iteration parity with TypeScript via `--message-format=json` 3. **`events/command-completed`** (Large) — restores RTOS-brain doctrine; touches dispatch hot path 4. **`code/shell/stream`** (Medium) — activates the reserved Stream cell shape 5. **`code/delete` + `code/move`** (Small) — rounds out file CRUD # Doc-set placement - Lives under `docs/planning/` next to ALPHA-GAP-ANALYSIS.md (existing planning convention) - Cross-references COMMAND-INFRASTRUCTURE-FIELD-MANUAL.md (the author guide), MODULE-CATALOG.md §0 (live status), GENOME-FOUNDRY- SENTINEL.md (the artifact economy the commands feed), and the per-module DESIGN.md pages (reference patterns) - Methodology section names the originating workflow + survey approach so future regenerations can follow the same shape # Connection to alignment-via-substrate-economics Per the memory [[alignment-via-substrate-economics]] + [[continuum-thesis-airc-is-the-medium]]: the proposed `continuum-core/ build` + `test` envelopes become serializable across the grid the moment they exist; combined with `events/command-completed` they make module-authorship attribution observable in real time. That's the cooperation incentive structure made concrete — the foundation the foundry's tiered genome cache (L1-L5 per GENOME-FOUNDRY- SENTINEL.md) needs to distribute persona-authored modules and route credit by cache-hit attribution. # Follow-up Next concrete sprint (separate PR): the bundled `code/exists` + `code/list` + `code/glob` cluster. Plan is to dogfood by using `generate/module` v2 (PR #1499) to scaffold the receiving module, then fill in handlers — proves the recursive bootstrap end-to-end. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(docs/planning): correct code/delete claim — it already exists; only code/move is missing Adversarial review of #1500 caught: the gap report lists `code/delete` + `code/move` as missing under Priority 5, but `code/delete` is genuinely implemented at `src/workers/continuum-core/src/modules/ code.rs:205` (backed by `FileEngine::delete`). Only `code/move` is absent. Three places fixed: - "Critical missing pieces" table row reduced to just `code/move` with a note about the `code/delete` confusion - "Suggested next-sprint priorities" §5 retitled `code/move` only with the same correction inline - "Alignment with three-primitive doctrine" table row updated with `data:file:moved` as the relevant event surface The underlying premise (need a move/rename command for scaffold reorganization) is sound; only the bundling with `code/delete` was wrong. Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-opens #1494 which auto-closed when its base (
feat/generator-module) was deleted on #1487's merge.What lands
Same content as #1494 — v2 enriched scaffold for the GeneratorModule. Now emits 4 files matching the Module Design Template instead of 2:
mod.rs— typed envelope dispatch + handler stubs + multi-thread concurrency test scaffoldtypes.rs—<Cmd>Params+<Cmd>Resultper command with#[derive(TS)](NEW)DESIGN.md— 8-section design skeleton (NEW)README.md— updated to reference all 4 filesPlus the
--statefulflag that adds per-resource lock scaffold for modules holding mutable state across.await.39 tests pass (17 pre-existing v1 + 22 new v2 template tests + filesystem dogfood).
Original PR
Full description + roadmap on #1494.