export const DOCUMENT_CONTRACT = `# The System document contract Use .system bundles only. Every authored document lives at .system//-/index.md. ID shape: --<8 chars from A-Z0-9_->. Use lowercase slugs. Frontmatter refs store IDs only. Config schemaVersion is 0. Type directories: research, specs, phases, plans, issues. Required frontmatter: - research: id, type: research, title - spec: id, type: spec, title, optional research: string[] - phase: id, type: phase, title, label - plan: id, type: plan, title, spec, status: draft|approved, optional depends_on: plan ID[] - issue: id, type: issue, title, specs: string[] Research references no System stage type. Specs may reference research. Operate only the explicitly invoked /system lifecycle stage. Never auto-chain stages or create artifacts for another stage. You may recommend another stage; wait for explicit human invocation. Phases are project-wide operating epochs related to MISSION, not spec decomposition or work breakdown. Phase labels contain 1-12 ASCII letters, digits, dots, underscores, or hyphens. Plans reference one spec and may depend on earlier plans for the same spec. Issues may reference zero or more specs and have no status field. Approved plans are immutable outside an explicitly approved /system init bundle migration; otherwise create a new artifact. Mutating existing core files or files in phase and spec bundles requires one-shot human approval. The optional config currentPhase ID selects the project-wide operating phase. Changing currentPhase requires explicit human confirmation. Keep prose terse, minimal, and essential. After creating or materially editing an artifact, end with: View: /system view `; export const MARKDOWN_CONTRACT = `# The System Markdown contract Use readable Markdown. Prefer visual explanations and diagrams when they clarify structure or relationships. Use GFM tables/task lists only when they clarify. Use Mermaid, TeX, raw HTML, and assets only when prose is worse. After choosing GFM, TeX, or Mermaid, load its matching the-system-* skill. Keep local Markdown links relative so /system view and /system book can resolve them. System documents contain no real code snippets; use terse pseudocode only when essential. `; const BOARD_CONTRACT = `# The System board contract Board state lives only in .system/board.json at schema version 0. Specs and plans use todo|done; issues use open|done. A spec may be done without plans, but cannot be done while any linked plan is todo. Issues never change spec state. Assessment proposes board changes for human review; it never applies them. `; const EXEC_CONTRACT = `# The System exec contract Implement only what the referenced System artifacts require. Valid exec inputs: spec; spec+plan; optional issue context. Plan inputs must be status: approved. The current phase is already project context; do not request or attach it as an exec input. Load the vertical-slices skill before implementation. Execute in thin vertical slices of artifact-required behavior. Each slice delivers one complete, observable behavior through the system's user-facing or public interface, crossing every layer that behavior requires. Do not batch work horizontally by architectural layer or component. Integrate, test, and freshly verify each slice before starting the next; leave the repository working after every slice. Use tests for nontrivial behavior. Debug root cause before fixing bugs. Before claiming implementation complete, run fresh verification and read the full result. After fresh verification, call system_board_propose exactly once with evidence-backed state changes for referenced artifacts; use an empty items list when no changes are justified. Board proposals require human review and never apply automatically. Final log includes refs, changed areas, verification, and a copyable View block. Commit messages tell the document-linked story, not file/test inventory. `; const STAGE_PROMPTS: Readonly> = { init: `Initialize .system only after explicit human approval. Inspect current project docs and rules first. Ask focused questions for missing project truth. Never overwrite existing core law silently. The /system init command updates config and board schema markers mechanically. When it reports a prior config schema, migrate existing bundles to schema 0 and the current contracts. Preserve current meaning where compatible; do not preserve obsolete bundle fields or add runtime migration code.`, doctor: `Diagnose .system without mutation. Run the deterministic doctor and explain each finding. Do not initialize, repair, rename, delete, or rewrite files.`, research: `Develop terse research artifacts as context requires. Collect technical or domain knowledge vital to the project. Record facts, sources, conclusions, and unresolved questions only. If relevant specs exist, ask whether later specs should reference the research; research artifacts never link to stages.`, spec: `Create or amend terse specs as context requires. Capture high-level intent, scope, behavior, constraints, and acceptance criteria. Use mockup for visual elements, UI, layout, and interaction choices. After acceptance, save the selected HTML as a spec-bundle asset, link it from index.md, and encode feedback as behavior and constraints. Do not prescribe implementation. Specs may reference research.`, "spec-verify": `Verify a spec experimentally. Find logical inconsistencies, holes, risky claims, or false assumptions. Use ephemeral probes only. Produce evidence and proposed spec amendments; do not create a canonical artifact.`, assess: `${BOARD_CONTRACT} Assess current implementation progress for the requested specs, plans, and issues. Inspect current code and tests deeply enough to justify each proposed state. Do not edit bundles or .system/board.json. Submit the assessment through system_board_propose. Omit items whose state cannot be assessed responsibly.`, phase: `Inspect MISSION and the current phase first. Create, amend, or transition one terse project-wide operating phase as context requires. A phase is a sub-mission and decision posture for an epoch, never a work breakdown or delivery milestone. Capture its sub-mission, ranked priorities, decision defaults, explicit non-goals, and observable exit criteria. Decision defaults cover concerns such as compatibility, migrations, stability, quality, speed, experimentation, and debt only when relevant. If it contains implementation steps, move those steps to a plan. Use a short label suitable for the Pi footer. When transitioning, create or amend the phase first, then update config currentPhase only after explicit human confirmation. Do not mutate MISSION.`, plan: `Create or amend terse implementation plans for specs as context requires. Plan at module, interface, package, or class level. Avoid function and line detail except critical paths. Do not include real code snippets. Use terse pseudocode only when necessary. Use status: draft until approval. Status: approved requires human approval and makes each plan immutable.`, issue: `Create or amend terse issues as context requires. Record symptom, impact, reproduction or evidence, and related specs. Use specs: [] while the violated contract is unknown. Amend or create specs only when issues expose spec gaps.`, exec: EXEC_CONTRACT, }; const NEEDS_MARKDOWN = new Set([ "init", "research", "spec", "spec-verify", "phase", "plan", "issue", ]); export function systemPromptFor( subcommand: string, instructions: string, ): string { const stage = STAGE_PROMPTS[subcommand]; if (!stage) throw new Error(`Unknown /system subcommand: ${subcommand}`); return [ DOCUMENT_CONTRACT, ...(NEEDS_MARKDOWN.has(subcommand) ? [MARKDOWN_CONTRACT] : []), `# /system ${subcommand}`, stage, instructions.trim() ? `# Human instructions\n\n${instructions.trim()}` : "# Human instructions\n\nNo instructions were supplied. Infer intent with focused questions or selection before writing.", ].join("\n\n"); }