Build a minimal, reliable software factory in this repository using the currently…
- User
Build a minimal, reliable software factory in this repository using the currently installed Pi and pi-subagents APIs.
This is an implementation task. Keep the parent Pi session as the orchestrator, use one writer at a time, and run fresh-context reviewers after implementation.
Goal
Add a reusable
/factory <task>command that launches an asynchronous, bounded software-delivery workflow:scout → plan → implement → deterministic checks → parallel review → optional fix → final checks
The factory should provide reliable outcome-oriented software delivery. It should not attempt to recreate Nika’s language, static proof system, hash-chained traces, or general-purpose workflow engine.
Before editing
- Read the relevant current documentation and source directly:
- installed pi-subagents
docs/workflows.md - installed pi-subagents
docs/missions.md - installed pi-subagents
docs/extension-api.md - installed pi-subagents
src/extension/public-execution.ts - Pi
docs/extensions.md - Pi
docs/sdk.md
- installed pi-subagents
- Confirm the installed pi-subagents version and use its actual APIs.
- Do not use removed legacy
/chain,/parallel, or checkpoint APIs. - Inspect this repository’s existing extension, agent, testing, and README patterns.
- If a product or architecture decision is genuinely required, ask once before editing. Otherwise choose the smallest compatible design.
Architecture
Prefer a thin Pi extension that calls pi-subagents through its documented in-process RPC API.
The extension should:
- register
/factory <task> - validate project trust and repository state before launch
- construct one fixed
workflowScriptwith the human-provided task safely JSON-encoded - launch it asynchronously through
subagents:rpc:v1:request - correlate RPC replies by request ID
- report the workflow run ID and mission ID
- expose
/factory-statusfor the latest factory run - avoid implementing its own child runner, process supervisor, scheduler, worktree manager, or transcript store
Use pi-subagents as the owner of execution, lifecycle, missions, artifacts, status, resume, and Herdr integration.
Herdr is observational only. Do not orchestrate the workflow by sending terminal keystrokes or scraping panes.
- Read the relevant current documentation and source directly:
Assistant
I'll start by reading the required documentation and inspecting the repository.
Assistant
Now let me check how
runs.hostis gated in workflows — the docs hint inline scripts can't use it. Let me verify in source:Assistant
The docs confirm an important boundary. Let me verify the installed agents and a few runtime details:
Assistant
Let me verify what the async spawn RPC reply contains (run id, mission id) and check the agent name for the builtin reviewer override resolution:
Assistant
Let me check the async-complete event shape and the
ping/ready flow, then look at how the repo's other extensions run tests, plus Node/tooling availability:Assistant
Let me check what's available for running tests (jiti, node_modules layout) and how big
validateWorkflowScript's export surface is:Assistant
Let me check the RPC spawn params schema for allowed fields (mission, timeoutMs, globalConcurrencyLimit):
Assistant
I have a full picture now. Let me check a couple of repo details, then build:
Assistant
Design is settled. Two quick feasibility checks for the test harness (importing the real installed pi-subagents source under Node's type-stripping, with
NODE_PATHforacorn), including the heavierrpc.tsmodule:Assistant
The harness works. Now I'll build the factory. Starting with the pure modules:
Assistant
Let me clean up leftover cruft in the build script:
Assistant
The
$TASKplaceholder escaping is fragile — let me replace it with straightforward string-literal concatenation in the generated script:Assistant
The edit tool choked on my no-op entries. Let me just rewrite the file cleanly:
Assistant
Now the RPC client, checks runner, and state module:
Assistant
Now the main extension. First verify
CONFIG_DIR_NAMEis exported from the installed pi:Assistant
Good. Now the main extension entry point:
Assistant
I introduced a stray line in that last edit. Let me inspect and clean up:
Assistant
Extension modules all load. Now the test suite — helpers first:
Assistant
Now the checks, state, and RPC tests (including the real-bridge smoke test):
Assistant
The state validator silently drops wrong-typed optional fields; fail-closed requires rejection. Let me tighten it:
Assistant
Now the workflow sandbox and validator tests:
Assistant
Validator tests pass against the real pi-subagents. Let me see why the sandbox tests fail:
- User
Assistant
I'll first check the current state of the work (including the one failing test from my implementation run), then launch fresh-context reviewers.
Assistant
Let me debug the one failing test quickly before launching reviewers:
Assistant
Found it — a test bug:
structuredOutput: reviewResult("fix", ...)double-wraps the result object (reviewResult already returns a{runId, structuredOutput}wrapper), so the verdict lookup correctly failed closed toblocked. The workflow behaved correctly; the fixture was wrong:Assistant
Same double-wrap in the inverse fixture:
Assistant
All 37 tests pass now. Launching three fresh-context reviewers in parallel with distinct angles:
Assistant
All three reviews returned. Synthesis:
Fixes worth doing now (the original task pre-authorized applying these):
- P0 (all 3 reviewers):
package.jsonmissing./extensions/factory/index.ts→ extension never loads. - P0 (all 3):
agent: "planner"doesn't exist → build workflow fails at plan stage. Needagents/planner.md. - P0 (2/3): success path never sets
phase = "complete"→ stuck active phase, "Factory failed: undefined". - P1: implement-stage
decisionsRequiringApprovalignored inhandleBuildCompletion. - P1: fix child that ran but produced a malformed handoff is misreported as outcome
"ok". - P1: AGENTS.md README sync missing + error message points to non-existent
extensions/factory/README.md. - Cheap P2s: paused-workflow →
needs_attentioninstead of ; dead import; misleading timeout-test name; contradictory fix-task rule text; double cast; TDZ-reading declaration order; doc comment.
- P0 (all 3 reviewers):
Assistant
Now the index.ts fixes:
Assistant
Now the factory README (schema docs) and the root README sync required by AGENTS.md:
Assistant
Now rerun the full suite and verify everything still loads:
Assistant
defaultProgress: falseparses correctly. Final diff inspection:Assistant
The diff is clean and all identified fixes are in. One final full-suite run via the new
pnpm testscript:Assistant
- User
Ok commit and push the changes