ultra-builder-pro-cli 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/.ultra-template/docs/research/README.md +11 -7
  2. package/.ultra-template/specs/architecture.md +36 -36
  3. package/.ultra-template/specs/discovery.md +46 -33
  4. package/.ultra-template/specs/product.md +38 -29
  5. package/.ultra-template/specs/research-distillate.md +48 -0
  6. package/.ultra-template/tasks/contexts/TEMPLATE.md +11 -28
  7. package/CHANGELOG.md +77 -1
  8. package/README.md +46 -24
  9. package/adapters/_shared/codex-assets.cjs +6 -2
  10. package/adapters/_shared/file-ops.cjs +6 -2
  11. package/adapters/_shared/handbook.cjs +2 -1
  12. package/adapters/claude.js +3 -2
  13. package/adapters/codex.js +1 -0
  14. package/adapters/kimi.js +3 -2
  15. package/adapters/opencode.js +3 -2
  16. package/agents/review-coordinator.md +9 -6
  17. package/commands/ultra-change.md +1 -1
  18. package/commands/ultra-plan.md +1 -1
  19. package/commands/ultra-research.md +1 -1
  20. package/commands/ultra-think.md +2 -2
  21. package/docs/AGENT-CONTEXT.md +43 -19
  22. package/docs/ARCHITECTURE.md +54 -13
  23. package/docs/PLAN.zh-CN.md +4 -2
  24. package/docs/ROADMAP.md +10 -4
  25. package/docs/RUNTIME-COMPAT-MATRIX.md +4 -4
  26. package/docs/STATE-DB-ACCESS-POLICY.md +33 -29
  27. package/docs/USER-HANDBOOK-CONTRACT.md +8 -2
  28. package/docs/WORKFLOW-LIFECYCLE.md +342 -0
  29. package/hooks/README.md +6 -1
  30. package/hooks/health_check.py +12 -3
  31. package/hooks/subagent_tracker.py +52 -77
  32. package/mcp-server/hook-event.cjs +34 -0
  33. package/mcp-server/lib/archive-journal.cjs +17 -5
  34. package/mcp-server/lib/baseline-workflow.cjs +158 -18
  35. package/mcp-server/lib/change-workflow.cjs +598 -85
  36. package/mcp-server/lib/context-spine.cjs +305 -25
  37. package/mcp-server/lib/decision-dialogue.cjs +713 -0
  38. package/mcp-server/lib/doctor.cjs +42 -3
  39. package/mcp-server/lib/init-project.cjs +210 -16
  40. package/mcp-server/lib/plan-store.cjs +4 -1
  41. package/mcp-server/lib/pricing.cjs +7 -10
  42. package/mcp-server/lib/project-breadcrumb.cjs +15 -0
  43. package/mcp-server/lib/projector.cjs +57 -3
  44. package/mcp-server/lib/spec-learning.cjs +79 -2
  45. package/mcp-server/lib/state-db.cjs +168 -8
  46. package/mcp-server/lib/state-ops.cjs +160 -9
  47. package/mcp-server/lib/workflow-state.cjs +2305 -0
  48. package/mcp-server/server.cjs +215 -15
  49. package/orchestrator/daemon.cjs +1 -2
  50. package/orchestrator/dispatch-rules.cjs +5 -31
  51. package/orchestrator/planner/plan-builder.cjs +21 -12
  52. package/package.json +13 -3
  53. package/skills/ultra-change/SKILL.md +94 -80
  54. package/skills/ultra-change/references/change-contract.md +36 -0
  55. package/skills/ultra-deliver/SKILL.md +76 -79
  56. package/skills/ultra-deliver/references/baseline-reconciliation.md +20 -0
  57. package/skills/ultra-dev/SKILL.md +62 -59
  58. package/skills/ultra-doctor/SKILL.md +61 -82
  59. package/skills/ultra-init/SKILL.md +101 -103
  60. package/skills/ultra-init/references/brownfield-adoption.md +2 -2
  61. package/skills/ultra-plan/SKILL.md +99 -85
  62. package/skills/ultra-plan/references/semantic-preflight.md +18 -0
  63. package/skills/ultra-research/SKILL.md +102 -60
  64. package/skills/ultra-research/references/00-problem-validation.md +36 -0
  65. package/skills/ultra-research/references/01-opportunity-discovery.md +33 -0
  66. package/skills/ultra-research/references/02-market-assessment.md +30 -0
  67. package/skills/ultra-research/references/03-competitive-landscape.md +31 -0
  68. package/skills/ultra-research/references/04-product-strategy.md +32 -0
  69. package/skills/ultra-research/references/05-assumptions-validation.md +31 -0
  70. package/skills/ultra-research/references/10-user-personas.md +29 -0
  71. package/skills/ultra-research/references/11-user-scenarios.md +28 -0
  72. package/skills/ultra-research/references/20-user-stories.md +30 -0
  73. package/skills/ultra-research/references/21-features-scope.md +29 -0
  74. package/skills/ultra-research/references/22-success-metrics.md +28 -0
  75. package/skills/ultra-research/references/30-architecture-context.md +30 -0
  76. package/skills/ultra-research/references/31-solution-strategy.md +28 -0
  77. package/skills/ultra-research/references/32-building-blocks.md +28 -0
  78. package/skills/ultra-research/references/40-deployment.md +29 -0
  79. package/skills/ultra-research/references/41-quality-risks.md +28 -0
  80. package/skills/ultra-research/references/99-synthesis.md +35 -0
  81. package/skills/ultra-review/SKILL.md +63 -73
  82. package/skills/ultra-review/references/review-modes.md +27 -0
  83. package/skills/ultra-review/references/unified-schema.md +25 -0
  84. package/skills/ultra-review/scripts/review_wait.py +40 -3
  85. package/skills/ultra-status/SKILL.md +41 -41
  86. package/skills/ultra-test/SKILL.md +54 -55
  87. package/skills/ultra-think/SKILL.md +26 -12
  88. package/skills/ultra-think/references/decision-dialogue.md +130 -0
  89. package/skills/ultra-verify/SKILL.md +1 -1
  90. package/skills/ultra-verify/references/{confidence-system.md → evidence-status.md} +3 -3
  91. package/spec/cli-protocol.md +17 -3
  92. package/spec/mcp-tools.yaml +683 -64
  93. package/spec/schemas/baseline-reconciliation.v1.schema.json +73 -0
  94. package/spec/schemas/delivery-report.v1.schema.json +111 -0
  95. package/spec/schemas/mcp-tools.schema.json +1 -1
  96. package/spec/schemas/state-db.sql +140 -1
  97. package/spec/schemas/tasks.v4.5.schema.json +8 -1
  98. package/spec/schemas/test-report.v1.schema.json +194 -0
  99. package/ultra-tools/cli.cjs +1 -1
  100. package/ultra-tools/commands/migrate.cjs +3 -3
  101. package/ultra-tools/commands/status.cjs +228 -12
  102. package/.ultra-template/delivery-report.json +0 -9
  103. package/.ultra-template/test-report.json +0 -8
  104. package/adapters/_shared/tests/file-ops.test.cjs +0 -54
  105. package/adapters/_shared/tests/frontmatter.test.cjs +0 -47
  106. package/adapters/_shared/tests/handbook.test.cjs +0 -101
  107. package/adapters/_shared/tests/path-rewrite.test.cjs +0 -60
  108. package/adapters/_shared/tests/provenance.test.cjs +0 -133
  109. package/adapters/_shared/tests/resolve-target.test.cjs +0 -75
  110. package/adapters/_shared/tests/runtime-assets.test.cjs +0 -149
  111. package/adapters/_shared/tests/settings-merge.test.cjs +0 -85
  112. package/adapters/_shared/tests/validate.test.cjs +0 -30
  113. package/adapters/tests/claude.test.cjs +0 -138
  114. package/adapters/tests/codex-hook.test.cjs +0 -142
  115. package/adapters/tests/codex.test.cjs +0 -430
  116. package/adapters/tests/kimi-hook.test.cjs +0 -149
  117. package/adapters/tests/kimi.test.cjs +0 -259
  118. package/adapters/tests/opencode.test.cjs +0 -357
  119. package/mcp-server/lib/archive-journal.test.cjs +0 -35
  120. package/mcp-server/lib/baseline-workflow.test.cjs +0 -477
  121. package/mcp-server/lib/change-workflow.test.cjs +0 -971
  122. package/mcp-server/lib/context-spine.test.cjs +0 -93
  123. package/mcp-server/lib/doctor.test.cjs +0 -148
  124. package/mcp-server/lib/plan-store.test.cjs +0 -132
  125. package/mcp-server/lib/prd-parser.test.cjs +0 -82
  126. package/mcp-server/lib/project-breadcrumb.test.cjs +0 -112
  127. package/mcp-server/lib/runtime-state.test.cjs +0 -92
  128. package/mcp-server/lib/spec-learning.test.cjs +0 -67
  129. package/mcp-server/lib/state-db.test.cjs +0 -314
  130. package/mcp-server/lib/task-expander.test.cjs +0 -169
  131. package/mcp-server/lib/topo.test.cjs +0 -158
  132. package/mcp-server/tests/circuit-breaker.test.cjs +0 -125
  133. package/mcp-server/tests/commit-hash-flow.test.cjs +0 -117
  134. package/mcp-server/tests/concurrency-update.test.cjs +0 -96
  135. package/mcp-server/tests/concurrency.test.cjs +0 -112
  136. package/mcp-server/tests/db-ops.test.cjs +0 -121
  137. package/mcp-server/tests/init-project.test.cjs +0 -393
  138. package/mcp-server/tests/migrate.test.cjs +0 -232
  139. package/mcp-server/tests/projector.test.cjs +0 -162
  140. package/mcp-server/tests/server-contract.test.cjs +0 -1467
  141. package/mcp-server/tests/staleness.test.cjs +0 -190
  142. package/mcp-server/tests/state-db.test.cjs +0 -106
  143. package/mcp-server/tests/state-ops.test.cjs +0 -449
  144. package/mcp-server/tests/tagged-tasks.test.cjs +0 -163
  145. package/mcp-server/tests/telemetry.test.cjs +0 -219
  146. package/orchestrator/planner/plan-builder.test.cjs +0 -165
  147. package/orchestrator/tests/auto-merge.test.cjs +0 -216
  148. package/orchestrator/tests/daemon.test.cjs +0 -311
  149. package/orchestrator/tests/dispatch-rules.test.cjs +0 -124
  150. package/orchestrator/tests/parallel-orchestrator.test.cjs +0 -233
  151. package/orchestrator/tests/phase-8b-gate.test.cjs +0 -183
  152. package/orchestrator/tests/recovery.test.cjs +0 -190
  153. package/orchestrator/tests/session-runner.test.cjs +0 -314
  154. package/orchestrator/tests/skill-miner.test.cjs +0 -147
  155. package/orchestrator/tests/worktree-manager.test.cjs +0 -148
  156. package/skills/ultra-research/references/architecture.md +0 -38
  157. package/skills/ultra-research/references/problem-product.md +0 -39
  158. package/skills/ultra-research/references/quality-delivery.md +0 -34
  159. package/skills/ultra-research/references/synthesis.md +0 -38
  160. package/skills/ultra-research/references/users-scope.md +0 -40
  161. package/ultra-tools/legacy-memory.test.cjs +0 -80
  162. package/ultra-tools/status-command.test.cjs +0 -181
  163. package/ultra-tools/system-command.test.cjs +0 -309
@@ -1,86 +1,65 @@
1
1
  ---
2
2
  name: ultra-doctor
3
- description: Diagnose Ultra state, projection, session, incident, change-artifact, and installed-plugin health with bounded recovery. Use when Ultra state appears missing, projections disagree, hooks fail, or MCP operations report degraded health.
3
+ description: Diagnose and recover Ultra DB schema, workflow outputs, projections, sessions, incidents, change artifacts, archives, hooks, and installed host assets. Use when authority is degraded, workflow state disagrees with prompts, outputs are stale, hooks fail, or MCP operations cannot proceed.
4
4
  ---
5
5
 
6
- # Diagnose and recover the Ultra runtime
7
-
8
- Default to read-only diagnosis. Repair only after the user explicitly authorizes it.
9
-
10
- ## Project-state diagnosis
11
-
12
- Call `system.doctor` with `{ "repair": false }` and inspect:
13
-
14
- - SQLite integrity and required tables;
15
- - open structured incidents;
16
- - event and projection cursor lag;
17
- - failed or interrupted projection jobs;
18
- - interrupted archive journals;
19
- - orphan sessions;
20
- - missing active-change artifact roots;
21
- - missing, incomplete, or stale project baseline readiness and specification digests;
22
- - the boundary to separately installed memory and code-graph providers.
23
-
24
- Do not infer health from generated task JSON. Do not mutate external provider state,
25
- delete artifacts, or collect memory during diagnosis.
26
-
27
- ## Interpret failures
28
-
29
- - State integrity failure blocks ordinary workflows and requires preserving database
30
- evidence before recovery.
31
- - An open incident requires its code, source, retryability, and evidence.
32
- - Projection lag may be mechanically repairable when authority is healthy.
33
- - An orphan session may be reconciled; never kill unrelated processes blindly.
34
- - A missing change artifact requires version-control, backup, or deliberate recreation
35
- evidence rather than silent regeneration.
36
- - Missing or incomplete baseline evidence routes to `ultra-init`. Doctor repair does
37
- not approve a baseline, accept known-red verification, or invent adoption evidence.
38
- Baseline readiness is an advisory workflow check, not state-database corruption and
39
- not a reason for doctor repair.
40
- - A compatibility `migrated` baseline requires explicit brownfield re-adoption and
41
- cannot authorize ordinary changes.
42
- - A corrupt SQLite file requires preserving the file, locating a verified backup, and
43
- an explicit restore-or-rebaseline decision.
44
-
45
- ## Explicit repair
46
-
47
- After authorization, call `system.doctor` with `{ "repair": true }` or use the
48
- installed `ultra-tools system doctor --repair` fallback. The CLI applies supported
49
- schema upgrades to the packaged current schema and reports a pre-migration backup path. Doctor then
50
- creates a second timestamped backup before runtime recovery.
51
-
52
- Repair is limited to documented schema upgrades, archive-journal completion,
53
- reconciling orphan sessions, consuming staleness events, requeueing interrupted or
54
- failed projections, and regenerating projections from authoritative state. If either
55
- backup fails, stop. Always inspect the post-repair report; a completed repair action
56
- does not imply healthy state.
57
-
58
- If SQLite integrity prevents doctor from opening authority, preserve the original
59
- database, WAL, and SHM. After the owner chooses a recovery path, either run
60
- `ultra-tools system restore --backup <managed-backup> --confirm
61
- REPLACE_CORRUPT_ULTRA_STATE` or run `ultra-tools system rebaseline --project-name
62
- <name> [--scope <path>] --confirm REBASELINE_CORRUPT_ULTRA_STATE`. Both commands
63
- must report the recovery backup directory. A failed command must restore the
64
- original authority, sidecars, and task projection before returning an error.
65
-
66
- ## Installed-plugin failures
67
-
68
- When a hook points to a missing installed file:
69
-
70
- 1. Capture the hook manifest path and missing target.
71
- 2. Run the installer doctor for the actual host and install scope.
72
- 3. Preserve provenance, asset-hash, and host-contract findings.
73
- 4. Reinstall through the host adapter rather than patching a cache directory.
74
- 5. Rerun installer doctor, `system.doctor`, and a host hook smoke test.
75
-
76
- Project doctor covers `.ultra/state.db`; installer doctor covers packaged files and
77
- host wiring. Neither substitutes for the other.
78
-
79
- ## Output
80
-
81
- Lead with `healthy` or `degraded`. List failing authority checks separately from
82
- baseline warnings, incident identifiers, cursor lag, whether repair ran, the backup
83
- path, and each unresolved action with its owner.
84
-
85
- Do not fix application code, delete state, reset Git, close healthy sessions, or
86
- install and repair external providers through this workflow.
6
+ # Diagnose before repair
7
+
8
+ Default to read-only diagnosis. Call `system.doctor` with repair disabled and inspect:
9
+
10
+ - SQLite integrity, schema version, required tables, and migration provenance;
11
+ - baseline classification/readiness, research provenance, spec/evidence digests, gaps,
12
+ and revision/worktree drift;
13
+ - active, blocked, and ready workflow runs, current steps, blockers, and output health;
14
+ - active decision threads, the sole current question, blocking deferrals, checkpoint
15
+ state, and current checkpoint artifact digests;
16
+ - event/projection cursor lag and failed or interrupted projection jobs;
17
+ - sessions, incidents, circuit state, active-change artifacts, and archive journals;
18
+ - external provider ownership boundaries.
19
+
20
+ An expected blocked workflow is a workflow warning, not DB corruption. A stale or
21
+ missing recorded output is an authority failure for that run. Doctor cannot invent
22
+ evidence, complete a step, accept a failure, approve a baseline, or change product
23
+ scope.
24
+ An awaiting owner decision is also a recoverable warning, not corruption. A missing or
25
+ changed artifact bound to a current confirmed checkpoint is an authority failure;
26
+ doctor may report it but cannot reconstruct the decision or approval.
27
+
28
+ ## Route failures
29
+
30
+ - Missing or migrated baseline evidence: `ultra-init` and the exact research step.
31
+ - Stale workflow output: restore or regenerate the artifact from accepted evidence,
32
+ then record the affected step again and re-run completion.
33
+ - Projection lag with healthy authority: eligible for mechanical regeneration.
34
+ - Orphan session: reconcile the recorded lease; do not kill unrelated processes.
35
+ - Missing change artifact: recover from version control, backup, or explicit owner
36
+ decision rather than silently recreating it.
37
+ - Open decision: resume its exact question through `ultra-think`; checkpoint-ready
38
+ state requires owner confirmation, not mechanical repair.
39
+ - Stale decision artifact: restore or update the artifact from accepted authority,
40
+ then reprepare and reconfirm the same checkpoint through `ultra-think`; do not
41
+ rewrite the owner decision or mark the failure healthy mechanically.
42
+ - Corrupt SQLite: preserve DB/WAL/SHM and obtain a restore-or-rebaseline decision.
43
+
44
+ ## Explicit project repair
45
+
46
+ After authorization, call `system.doctor` with repair enabled. Repair is limited to
47
+ supported schema upgrades, backup-first archive recovery, orphan reconciliation,
48
+ staleness consumption, projection requeue, and projection regeneration. Verify the
49
+ pre-migration and repair backup paths and rerun the read-only report. A completed repair
50
+ action does not imply healthy workflow evidence.
51
+
52
+ When integrity prevents opening the DB, use only the documented restore or rebaseline
53
+ command with its explicit confirmation token. Both must quarantine or back up prior
54
+ authority and roll back on failure.
55
+
56
+ ## Installed host failures
57
+
58
+ For a missing hook adapter or stale plugin path, capture the manifest and missing
59
+ target, run `ubp --doctor` for the actual host, reinstall through the adapter rather
60
+ than patching cache contents, and verify provenance, hashes, entry points, MCP startup,
61
+ and a hook smoke test. Project doctor and installer doctor are separate authorities.
62
+
63
+ Return health first, failing authority checks, workflow warnings, backup/recovery
64
+ paths, whether repair ran, unresolved owners, and one exact next action. Do not edit
65
+ application code or external memory/graph providers through this Skill.
@@ -1,111 +1,109 @@
1
1
  ---
2
2
  name: ultra-init
3
- description: Initialize a new repository, adopt an existing codebase, or upgrade prior Ultra state into an evidence-backed project baseline. Use when `.ultra` is absent, baseline readiness is incomplete, or legacy project state must be migrated.
3
+ description: Initialize a new repository, adopt an existing codebase, or migrate prior Ultra authority into a verified project baseline. Use when `.ultra` is absent, initialization is incomplete, baseline readiness is blocked, or a legacy Ultra project must be resumed.
4
4
  ---
5
5
 
6
- # Establish the project baseline
7
-
8
- Create or recover project-local Ultra authority, classify the repository, and finish
9
- the applicable baseline workflow. Keep application source unchanged during adoption.
10
-
11
- ## Authority rules
12
-
13
- - Treat `.ultra/state.db` as the only durable Ultra authority.
14
- - Preserve every existing `.ultra/` tree and migration backup.
15
- - Require explicit authorization before replacing a healthy baseline or discarding a
16
- corrupt database.
17
- - Store only metadata references for external memory and code-graph providers.
18
- - Create ordinary tasks only after the baseline is ready. Record characterization
19
- needs and adoption gaps in the gap ledger until convergence.
20
-
21
- ## Inspect and route
22
-
23
- 1. Bind the repository root, Git branch and HEAD, worktree status, manifests, package
24
- scripts, workspace markers, deployment files, and existing `.ultra/` assets.
25
- 2. When `.ultra/` is absent, run **Bootstrap**.
26
- 3. When `.ultra/tasks/tasks.json` contains tasks but `state.db` is absent or has no
27
- tasks, run **Import projection-only state** before ordinary state-backed work.
28
- 4. When `state.db` exists, run read-only project doctor first. Call `baseline.get`
29
- only when doctor confirms that the current schema authority is readable. Route an
30
- old schema to repair and a corrupt database to recovery without another DB read.
31
- 5. After current authority is readable, call `task.init_project` with `resume: true` to install
32
- only missing current scaffold files. Verify that existing artifacts were preserved.
33
- 6. Route the result:
34
- - healthy `ready` baseline: return `ultra-change` or `ultra-status`;
35
- - `draft`, `adopting`, or baseline-blocked: resume the matching baseline;
36
- - `migrated`: start evidence-backed brownfield re-adoption;
37
- - old schema: run backup-first schema repair;
38
- - corrupt database: preserve it and stop at the restore-or-rebaseline decision.
39
-
40
- ## Bootstrap
41
-
42
- Derive project metadata from repository evidence. Call `task.init_project` with
43
- `mode: "auto"`. Pass `scope` when the user selected a monorepo boundary; otherwise use
44
- the repository root. Use an explicit mode only when the user supplied an authoritative
45
- classification.
46
-
47
- Verify `repository_profile`, selected scope, detected mode, baseline lifecycle, schema
48
- version, copied templates, initial projection, and `project_initialized` event.
49
-
50
- ## Import projection-only state
51
-
52
- Call `task.init_project` with `resume: true` as the single authority check and run the
53
- exact supported backup-first import command returned in its structured error. Do not
54
- infer an import path or edit the projection manually.
55
-
56
- Verify imported task and event counts, backup path, current schema state, projection
57
- parity, and the `migrated/adopting` compatibility baseline. Then call `baseline.start` with a
58
- new id, `mode: "brownfield"`, `replace_migrated: true`, the selected scope, current
59
- revision, and repository classification. Never treat the compatibility row as owner
60
- approval.
61
-
62
- For an older database schema, run `ultra-tools system doctor --repair`; verify both the
63
- pre-migration backup and post-repair backup plus the current schema before continuing.
64
- Then resume initialization to merge missing scaffold assets without overwriting the
65
- project's existing baseline documents.
66
-
67
- ## Complete the selected mode
68
-
69
- For `brownfield`, `migrated`, or an incomplete existing adoption, read
70
- `references/brownfield-adoption.md` completely and execute it through owner approval.
71
-
72
- For `greenfield`, keep the baseline in `draft` until product and architecture intent is
73
- evidence-backed. Route unresolved intent through `ultra-research`, record the complete
74
- baseline snapshot, obtain owner approval, and converge it before planning.
75
-
76
- ## Recovery handling
77
-
78
- - `ULTRA_DIR_EXISTS`: inspect and resume the existing state.
79
- - `LEGACY_STATE_MIGRATION_REQUIRED`: execute the returned migration command.
80
- - `BASELINE_IN_PROGRESS`: resume the named row; never create a parallel authority.
81
- - `BASELINE_EXISTS`: return the healthy route. Replacing a ready baseline is outside
82
- ordinary initialization; stop for owner authorization before calling
83
- `baseline.start` with a new id, `replace_ready: true`, and
84
- `replacement_authorization: { approved_by, reason }`. The approval identity and
85
- rationale must be persisted in the `baseline_started` event.
86
- - `BASELINE_SCOPE_MISSING`: correct the selected monorepo boundary.
87
- - `TEMPLATE_MISSING`: run installer doctor and reinstall through the host adapter.
88
- - `STATE_DB_CORRUPT`: retain the database, inspect `.ultra/backups`, and obtain the
89
- restore-or-rebaseline decision. Restore only a verified managed backup with
90
- `ultra-tools system restore --backup <path> --confirm REPLACE_CORRUPT_ULTRA_STATE`.
91
- When no valid backup exists and the owner explicitly accepts rebuilding authority,
92
- run `ultra-tools system rebaseline --project-name <name> [--scope <path>] --confirm
93
- REBASELINE_CORRUPT_ULTRA_STATE`; verify the quarantined database and legacy
94
- projection paths before continuing adoption.
95
- - `IO_ERROR`: verify rollback restoration and preserve every reported backup path.
6
+ # Establish project authority
7
+
8
+ Use host reasoning to inspect repository evidence and prepare baseline content. Use
9
+ Ultra MCP for classification records, schema migration, workflow state, evidence
10
+ digests, approval, and convergence. Never treat generated Markdown or JSON as state.
11
+ Read `../ultra-think/references/decision-dialogue.md` before asking about repository
12
+ scope, replacement authority, or another load-bearing owner choice.
13
+
14
+ ## Classify without guessing product scope
15
+
16
+ Run `system.doctor` read-only when `.ultra/state.db` exists. Otherwise call
17
+ `task.init_project` with `mode: "auto"`, the repository root, project name, and an
18
+ owner-selected monorepo scope when applicable.
19
+
20
+ Interpret classification independently from readiness:
21
+
22
+ - `greenfield`: no meaningful delivered application behavior exists outside docs,
23
+ generated output, or a starter skeleton;
24
+ - `brownfield`: source, runtime, deployment, API, schema, or test evidence shows an
25
+ existing maintained system;
26
+ - `migrated`: older DB or projection-only authority was preserved and must be
27
+ replaced by an evidence-backed brownfield baseline.
28
+
29
+ The presence of `.ultra/`, a manifest, or a Git repository does not make a baseline
30
+ ready. Classification never chooses an MVP, reduced scope, or delivery posture.
31
+ Report the detected project type, technology signals, verification commands, and
32
+ monorepo roots. Pass an explicit `project_type` or `stack` only when repository evidence
33
+ or an owner decision supports the override; MCP preserves both detection and selection.
34
+ Inspect first and ask only one unresolved scope or replacement decision at a time. Do
35
+ not request a complete project questionnaire during initialization.
36
+
37
+ ## Resume safely
38
+
39
+ When `.ultra/` exists, call `task.init_project` with `resume: true`. It must preserve
40
+ existing artifacts, create a pre-migration backup when needed, upgrade the schema,
41
+ install only missing assets, and return the durable workflow ids and exact route.
42
+
43
+ For projection-only state, execute only the backup-first migration command returned by
44
+ the structured error. For a `migrated` compatibility row, call `baseline.start` with a
45
+ new brownfield id and `replace_migrated: true`; never treat migration as owner approval.
46
+
47
+ Replacing a healthy baseline requires a new id plus `replace_ready: true` and explicit
48
+ `replacement_authorization`. Preserve corrupt DB, WAL, SHM, and backups; use the
49
+ documented restore or rebaseline command only after the owner selects that destructive
50
+ recovery path.
51
+
52
+ ## Follow durable initialization state
53
+
54
+ Read the returned init and research runs with `workflow.get`.
55
+
56
+ - `inspect-authority`: `task.init_project` records the bounded repository and existing
57
+ Ultra evidence it inspected.
58
+ - `classify-repository`: `task.init_project` records classification, detected signals,
59
+ selected scope, and supported overrides.
60
+ - `scaffold-authority`: `task.init_project` creates or resumes DB authority and installs
61
+ only missing scaffold assets.
62
+ - `establish-baseline`: research completion, `baseline.record`, and owner-approved
63
+ `baseline.converge` establish the evidence-backed authority.
64
+ - `verify-initialization`: convergence re-reads baseline, init, research, repository,
65
+ verification, and output health before completing initialization.
66
+
67
+ The first three steps are deterministic writes owned by `task.init_project`; the final
68
+ two are completed atomically by successful baseline convergence. Do not mark or emulate
69
+ these transitions in Prompt text or projection files.
70
+
71
+ - Greenfield starts a `full` research run.
72
+ - Brownfield starts an `adoption` research run.
73
+ - Both modes require all seventeen research steps before baseline convergence.
74
+ - A migrated project remains routed to re-adoption before research can authorize work.
75
+
76
+ Continue through `ultra-research`. Research completion records output digests; then
77
+ `baseline.record` captures current scope, revision, discovery/product/architecture
78
+ specs, source and runtime evidence, actual verification, unknowns, gaps,
79
+ classification, and external provider metadata references.
80
+
81
+ Call `baseline.converge` only after the compact research checkpoint receives explicit
82
+ owner approval; do not ask for the same approval twice. The MCP rejects missing
83
+ research, missing discovery/product/architecture refs, stale evidence, revision or
84
+ worktree drift, unaccepted known failures, blocking unknowns, and blocking gaps. A
85
+ successful convergence atomically marks the baseline ready and completes the init run.
86
+
87
+ ## Recovery
88
+
89
+ - Record deterministic blockers on the current workflow; never create a parallel run.
90
+ - Use `system.doctor` repair only for supported schema, projection, session, incident,
91
+ archive, or legacy workflow-provenance recovery. A recovered legacy change workflow
92
+ remains blocked for real baseline evidence; repair cannot invent research or approve
93
+ a baseline.
94
+ - Treat context budgets as advisory. Missing authority, evidence, output, or approval
95
+ is blocking.
96
+ - Store only references to external memory and code-graph providers.
96
97
 
97
98
  ## Completion
98
99
 
99
- Initialization is complete only when:
100
+ Read `baseline.get`, `workflow.get`, and `system.doctor` after convergence. Report
101
+ classification evidence, scope, revision, worktree snapshot, migration backups,
102
+ research run and output health, verification, gaps, approval, and one route.
100
103
 
101
- - current schema authority is readable;
102
- - repository classification and scope are recorded;
103
- - product and architecture baseline files exist;
104
- - verification, unknowns, gaps, evidence, and provider references are recorded;
105
- - explicit owner approval has converged the baseline to `ready`;
106
- - `baseline.get` reports current health and project doctor has no authority failure.
107
-
108
- Report the target, classification evidence, migration and backup paths, baseline id,
109
- mode, status, revision, branch, worktree snapshot, verification results, gap summary,
110
- approval state, and one exact next action. Stop at the approval step when owner consent
111
- has not yet been provided.
104
+ Initialization is complete only when the baseline is `ready`, the init workflow is
105
+ `completed`, the research workflow is `completed`, and
106
+ `baseline.research_run_id` names that exact research run with healthy outputs. Route
107
+ every newly converged or already initialized baseline through `ultra-change`; planning
108
+ starts only after that command persists a complete Change Contract, profile, and
109
+ research disposition. Otherwise return the exact current workflow step or blocker.
@@ -89,5 +89,5 @@ items the owner accepted.
89
89
  Resolve returned blockers through evidence or an owner decision, record the replacement
90
90
  snapshot, and retry. Adoption is complete only when `baseline.get` is `ready` and
91
91
  current, the gap ledger has no open blocker, and project doctor has no authority
92
- failure. Route new work through `ultra-change`; route already accepted planned work
93
- through `ultra-plan`.
92
+ failure. Route all selected work through `ultra-change`, including work described by a
93
+ legacy plan. Import its accepted intent into a current Change Contract before planning.
@@ -1,89 +1,103 @@
1
1
  ---
2
2
  name: ultra-plan
3
- description: Convert a validated baseline, active delta, or approved PRD into dependency-valid vertical slices with bounded context and exact verification. Use when requirements are ready to become authoritative Ultra tasks.
3
+ description: Convert a ready Ultra baseline or approved active-change delta into dependency-valid, DB-backed execution contracts and fresh-context vertical slices. Use when accepted requirements are ready for implementation planning or an existing plan must be resumed and verified.
4
4
  ---
5
5
 
6
- # Plan fresh-context execution
7
-
8
- Produce a task graph whose slices can be completed independently and verified through
9
- live product seams. `.ultra/state.db` remains authoritative; task JSON and context
10
- Markdown are generated projections.
11
-
12
- ## Entry gate
13
-
14
- Start with a state-backed MCP read. If state or schema health blocks access, stop and
15
- route to `ultra-doctor`. Never read or write `.ultra/tasks/tasks.json` as a fallback.
16
- Call `baseline.get`. Initial product planning is blocked until the baseline is
17
- `ready` and current; route its missing, adopting, blocked, or stale state to
18
- `ultra-init`. Planning an already active bounded change may continue with the
19
- baseline condition recorded as a warning. Ordinary convergence still requires
20
- approved adoption, and archive atomically reconciles revision and specification
21
- drift. An approved break-glass incident follows its recorded recovery contract and
22
- creates a blocking reconciliation gap at archive.
23
-
24
- Choose one input:
25
-
26
- - validated baseline specifications;
27
- - one active change packet;
28
- - a raw PRD through the approval-gated mode below.
29
-
30
- Ask only for product, scope, cost, or risk decisions that cannot be derived from
31
- current evidence. A material unresolved assumption blocks persistence.
32
-
33
- ## Planning rules
34
-
35
- 1. Trace acceptance through an entry point, domain behavior, side effects, and a
36
- user-observable or public seam.
37
- 2. Prefer a walking skeleton or `tracer_bullet` before horizontal layers.
38
- 3. Give each task one outcome, bounded ownership, explicit dependencies, required
39
- references, and one deterministic verification command.
40
- 4. Use the context budget as an attention signal. Prefer bounded excerpts, direct
41
- reads, or a smaller slice, but keep necessary files when correctness requires them.
42
- Budget overflow is a warning, never a reason to inflate a threshold or manufacture
43
- a smaller but incomplete contract.
44
- 5. Add integration checkpoints at actual boundaries, not after arbitrary task counts.
45
- 6. Put validation, errors, recovery, documentation, and migrations in the task that
46
- owns the behavior.
47
- 7. Reject scaffolding with no reachable consumer.
48
-
49
- Every persisted task must include its slice kind, public seam, verification command,
50
- acceptance evidence, ownership, dependencies, documentation impact, and linked change
51
- id when applicable.
52
-
53
- ## Baseline or change mode
54
-
55
- 1. Read the smallest authoritative references that define acceptance.
56
- 2. Build the task DAG in memory and check dependency and ownership conflicts.
57
- 3. Present the proposed outcome, execution order, risk concentration, and first live
58
- seam. Obtain approval if scope, cost, or delivery semantics change materially.
59
- 4. Persist approved tasks with `task.create`.
60
- 5. For change-linked tasks, compile `change.context` with the planning role and gate.
61
- Resolve every readiness blocker before calling a task executable.
62
- 6. Call `task.dependency_topo`; cycles and missing dependencies block completion.
63
- 7. Call `plan.export`, then verify the persisted result with `plan.get`.
64
- 8. Call `change.breadcrumb` when a change is active and return one next action.
65
-
66
- ## PRD mode
67
-
68
- 1. Read the approved PRD with the current host model and derive the proposed task
69
- objects using the `task.parse_prd` input schema. Do not invoke a second model or
70
- require a provider API key inside Ultra MCP.
71
- 2. Call `task.parse_prd` with those `tasks`, `dry_run: true`, and the active
72
- `change_id` when applicable. The MCP validates the graph but does not supply
73
- product judgment.
74
- 3. Show the proposed slices, topology, conflict surface, and cost estimate.
75
- 4. Require explicit approval; rejection performs no state write.
76
- 5. On approval, repeat with `dry_run: false`, the identical task objects, and the
77
- same change ownership; export
78
- the plan, and verify that the dry-run and persisted task identities agree.
79
-
80
- When one approved task is still too broad, derive its complete child graph with the
81
- current host model and call `task.expand` with the parent `id` and validated
82
- `children`. The MCP assigns parent, tag, and change ownership atomically. Never ask
83
- the MCP runtime to generate child content.
84
-
85
- ## Completion gate
86
-
87
- Planning is complete only when the DAG is valid, each task reaches a public seam, each
88
- verification command is executable, every change-linked context is ready, and no
89
- required documentation or decision remains unknown.
6
+ # Review and persist an executable plan
7
+
8
+ Use host reasoning for decomposition, tradeoffs, and approval. Use Ultra MCP for
9
+ workflow position, decision authority, task contracts, graph validation, projection,
10
+ and recovery. Read `../ultra-think/references/decision-dialogue.md` before presenting a
11
+ planning choice.
12
+
13
+ ## Bind authority
14
+
15
+ 1. Call `system.doctor`, `baseline.get`, `change.list`, and `change.breadcrumb`.
16
+ 2. Require a current ready baseline for new ordinary work. Resume an already-authorized
17
+ active change when appropriate; an incident uses only its recorded break-glass
18
+ authority.
19
+ 3. Ensure exactly one active change owns the plan. For initial implementation, open a
20
+ standard or major change from the accepted baseline before creating tasks.
21
+ 4. Read `references/semantic-preflight.md`. Resolve every blocking Change decision and
22
+ complete the exact recorded bounded research selection before starting the plan.
23
+ 5. Resume the active `plan` workflow from `workflow.list`, or call `workflow.start`
24
+ with its `baseline_id`, `change_id`, subject, and source refs.
25
+
26
+ ## Build a candidate before writing authority
27
+
28
+ Inspect requirements, source, consumers, state, tests, deployment, and recovery before
29
+ drafting slices. Build the candidate plan privately. Separate evidence-backed design
30
+ detail from choices that change accepted scope, public behavior, compatibility, cost,
31
+ risk, delivery semantics, or recovery.
32
+
33
+ When a material planning decision remains, start or resume a decision thread bound to
34
+ the plan workflow. Present exactly one decision with the recommendation, credible
35
+ alternatives, and the tasks or contracts it changes, then STOP. The plan document is
36
+ the result of this review; never use a large plan dump as a substitute for interaction.
37
+
38
+ After all blocking choices are resolved, prepare one checkpoint. Present the compact
39
+ topology, public seams, recovery, and material tradeoffs for approval. After approval,
40
+ write the evidence-linked `plan.md`, confirm the checkpoint with its digest, and reuse
41
+ that same approval for the durable `approve-plan` and workflow completion gates.
42
+
43
+ ## Record the durable steps
44
+
45
+ Record each completed step with `workflow.step`:
46
+
47
+ 1. `validate-baseline`: verify baseline and completed research provenance.
48
+ 2. `select-posture`: preserve the owner-approved scope and delivery posture. Never
49
+ infer an MVP, reduction, phase, or exclusion. Ask only when a proposed plan changes
50
+ accepted scope, cost, risk, compatibility, or delivery semantics.
51
+ 3. `analyze-requirements`: trace stable requirement ids to acceptance and public seams.
52
+ 4. `analyze-codebase`: inspect current entry points, consumers, patterns, state
53
+ authority, tests, deployment, and recovery paths before designing new structure.
54
+ 5. `design-slices`: design a walking skeleton and subsequent vertical slices. Every
55
+ slice must reach a real consumer; include validation, side effects, errors,
56
+ documentation, migration, observability, and recovery in the owning slice.
57
+ 6. `validate-dependencies`: validate ownership, missing dependencies, cycles, conflict
58
+ surfaces, and meaningful integration checkpoints.
59
+ 7. `approve-plan`: persist the already obtained checkpoint approval; do not ask again.
60
+
61
+ ## Persist complete task contracts
62
+
63
+ Only after the plan checkpoint is confirmed, call `task.create` for each approved task
64
+ with:
65
+
66
+ - one observable `outcome` and stable `trace_to`;
67
+ - `slice_kind`, `public_seam`, and exact `verification_command`;
68
+ - structured `acceptance` items with their verification;
69
+ - bounded `context_refs` with reasons;
70
+ - resolved `docs_impact` and durable `ownership`;
71
+ - dependencies, affected files when known, estimates only when evidence supports them,
72
+ and the owning `change_id`.
73
+
74
+ Copy each Change acceptance id into at least one task acceptance item without changing
75
+ its meaning. Set `trace_to` to that accepted id, a current research semantic id, or a
76
+ real project-relative Markdown `path#anchor`. A quick profile has exactly one task.
77
+ The MCP derives the coverage matrix and rejects uncovered acceptance, orphan tasks,
78
+ stale research, and oversized quick plans.
79
+
80
+ Never read or write `.ultra/tasks.json` or generated context Markdown as authority.
81
+ The DB owns the task contract and the projector regenerates both views.
82
+ `persist-task-contracts` completes only after `task.get` reads every field back without
83
+ a contract blocker.
84
+
85
+ Call `task.dependency_topo` with the current `change_id`, then call
86
+ `plan.export` with `change_id`, `format: "json"`, and
87
+ `out_path: ".ultra/execution-plan.json"`. Export records `plan_exported`; it does
88
+ not approve the plan. Read the same change back with `plan.get`.
89
+ The exported artifact is change-bound and may not include tasks from another active
90
+ or historical change. Recompile `change.context`
91
+ for the first task; it derives its execution contract and context refs from DB and
92
+ rejects a conflicting prompt override. Missing required refs block readiness; context
93
+ size is advisory.
94
+
95
+ Record `verify-plan` with `.ultra/execution-plan.json` as its sole output, then call
96
+ `workflow.complete` with
97
+ `approval.approved_by` and `approval.approval_note`. Do not send a task summary: MCP
98
+ derives the complete task set from every task owned by the change. Completion
99
+ revalidates every task contract, change ownership, dependency existence, graph cycles,
100
+ the exact exported topology, approval, and current output digests; it also advances
101
+ the linked change workflow to context compilation.
102
+ Return the persisted topology, first task/public seam,
103
+ approval evidence, plan workflow id, and one `ultra-dev` route.