ultra-builder-pro-cli 0.22.0 → 0.24.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 (93) hide show
  1. package/.ultra-template/docs/research/README.md +4 -4
  2. package/CHANGELOG.md +83 -0
  3. package/README.md +68 -35
  4. package/adapters/_shared/codex-assets.cjs +121 -60
  5. package/adapters/_shared/interaction-contract.cjs +20 -7
  6. package/adapters/_shared/provenance.cjs +7 -2
  7. package/adapters/_shared/runtime-assets.cjs +4 -3
  8. package/adapters/_shared/runtime-native.cjs +132 -0
  9. package/adapters/claude.js +61 -31
  10. package/adapters/codex.js +178 -81
  11. package/adapters/grok.js +372 -0
  12. package/adapters/kimi.js +8 -4
  13. package/adapters/opencode.js +211 -33
  14. package/agents/code-reviewer.md +4 -2
  15. package/agents/debugger.md +4 -1
  16. package/agents/review-code.md +7 -3
  17. package/agents/review-comments.md +7 -4
  18. package/agents/review-coordinator.md +11 -7
  19. package/agents/review-design.md +8 -4
  20. package/agents/review-errors.md +8 -4
  21. package/agents/review-spec.md +8 -5
  22. package/agents/review-tests.md +7 -4
  23. package/agents/tdd-runner.md +5 -2
  24. package/bin/install.js +9 -4
  25. package/bin/orchestrator.js +4 -13
  26. package/docs/AGENT-CONTEXT.md +141 -231
  27. package/docs/ARCHITECTURE.md +203 -498
  28. package/docs/ARTIFACT-AUTHORITY.md +38 -35
  29. package/docs/PLUGIN-ISOLATION-CONTRACT.md +12 -9
  30. package/docs/ROADMAP.md +85 -110
  31. package/docs/RUNTIME-COMPAT-MATRIX.md +139 -174
  32. package/docs/SKILL-AUTHORING.md +3 -3
  33. package/docs/STATE-DB-ACCESS-POLICY.md +25 -20
  34. package/docs/WORKFLOW-LIFECYCLE.md +174 -442
  35. package/hooks/README.md +11 -8
  36. package/hooks/active_task_context.py +16 -16
  37. package/hooks/adapters/grok.py +134 -0
  38. package/hooks/{context_spine.py → context_envelope.py} +26 -22
  39. package/hooks/health_check.py +19 -29
  40. package/hooks/pre_stop_check.py +22 -12
  41. package/hooks/subagent_tracker.py +1 -1
  42. package/hooks/workflow_checkpoint.py +14 -13
  43. package/hooks/workflow_context.py +11 -12
  44. package/hooks/workflow_resume.py +14 -13
  45. package/mcp-server/{breadcrumb.cjs → hook-context.cjs} +7 -9
  46. package/mcp-server/lib/artifact-registry.cjs +25 -1
  47. package/mcp-server/lib/baseline-workflow.cjs +36 -38
  48. package/mcp-server/lib/canonical-json.cjs +19 -0
  49. package/mcp-server/lib/change-workflow.cjs +637 -49
  50. package/mcp-server/lib/context-envelope.cjs +508 -0
  51. package/mcp-server/lib/decision-records.cjs +337 -0
  52. package/mcp-server/lib/doctor.cjs +91 -33
  53. package/mcp-server/lib/init-project.cjs +78 -39
  54. package/mcp-server/lib/managed-file-write.cjs +116 -0
  55. package/mcp-server/lib/plan-checkpoint.cjs +177 -0
  56. package/mcp-server/lib/project-context.cjs +178 -0
  57. package/mcp-server/lib/stage-checkpoints.cjs +309 -0
  58. package/mcp-server/lib/state-db.cjs +155 -24
  59. package/mcp-server/lib/task-ledger.cjs +522 -13
  60. package/mcp-server/lib/ultra-facade.cjs +834 -0
  61. package/mcp-server/lib/worker-packet.cjs +358 -0
  62. package/mcp-server/server.cjs +208 -1059
  63. package/orchestrator/daemon.cjs +27 -9
  64. package/orchestrator/parallel-orchestrator.cjs +111 -76
  65. package/orchestrator/session-runner.cjs +135 -34
  66. package/package.json +10 -3
  67. package/skills/ultra-change/SKILL.md +39 -98
  68. package/skills/ultra-deliver/SKILL.md +42 -65
  69. package/skills/ultra-dev/SKILL.md +52 -99
  70. package/skills/ultra-doctor/SKILL.md +35 -57
  71. package/skills/ultra-init/SKILL.md +48 -88
  72. package/skills/ultra-init/references/brownfield-adoption.md +11 -8
  73. package/skills/ultra-plan/SKILL.md +54 -132
  74. package/skills/ultra-research/SKILL.md +58 -112
  75. package/skills/ultra-review/SKILL.md +28 -46
  76. package/skills/ultra-review/references/unified-schema.md +2 -0
  77. package/skills/ultra-review/scripts/review_wait.py +8 -0
  78. package/skills/ultra-status/SKILL.md +22 -45
  79. package/skills/ultra-test/SKILL.md +27 -61
  80. package/skills/ultra-think/SKILL.md +29 -48
  81. package/skills/ultra-think/references/interaction-boundary.md +56 -0
  82. package/spec/cli-protocol.md +80 -187
  83. package/spec/mcp-tools.yaml +130 -2738
  84. package/spec/schemas/mcp-tools.schema.json +1 -1
  85. package/spec/schemas/state-db.sql +107 -4
  86. package/spec/schemas/{task-ledger.v1.schema.json → task-ledger.v2.schema.json} +70 -6
  87. package/ultra-tools/commands/status.cjs +369 -243
  88. package/mcp-server/lib/context-spine.cjs +0 -1208
  89. package/mcp-server/lib/decision-dialogue.cjs +0 -1128
  90. package/mcp-server/lib/project-breadcrumb.cjs +0 -173
  91. package/mcp-server/lib/spec-learning.cjs +0 -284
  92. package/mcp-server/lib/workflow-state.cjs +0 -2965
  93. package/skills/ultra-think/references/decision-dialogue.md +0 -153
@@ -1,514 +1,219 @@
1
- # Ultra Builder Pro CLI — Architecture
1
+ # Ultra Builder Pro architecture
2
+
3
+ Ultra Builder Pro is an adaptive delivery harness distributed as native plugins for
4
+ Claude Code, Codex, OpenCode, Kimi Code, and Grok Build. The host model reasons and
5
+ chooses semantic routes. Ultra preserves the accepted intent, current evidence, safe
6
+ execution state, and recoverable delivery history across sessions and hosts.
7
+
8
+ ## One authority graph
9
+
10
+ ```mermaid
11
+ flowchart LR
12
+ U["User<br/>intent, trade-offs, authorization"]
13
+ H["Host model<br/>inspect, recommend, implement"]
14
+ S["11 explicit Skills<br/>adaptive semantic workflows"]
15
+ C["Canonical Context Envelope"]
16
+ M["7-tool MCP kernel"]
17
+ D[("SQLite<br/>facts, indexes, CAS, leases, journals")]
18
+ F[".ultra semantic files<br/>intent, specs, plans, decisions, evidence"]
19
+ K["Hooks<br/>observe, inject, recover, protect"]
20
+ A["Agents<br/>bounded Worker Packets"]
21
+ G["Git team checkpoint"]
22
+
23
+ U <--> H
24
+ H --> S
25
+ S --> C
26
+ K --> C
27
+ C --> M
28
+ M <--> D
29
+ H --> F
30
+ M <--> F
31
+ S --> A
32
+ C --> A
33
+ A --> F
34
+ F --> G
35
+ M <--> G
36
+ ```
2
37
 
3
- > Single-page entry point for reviewers and contributors. Current authority and
4
- > package boundaries live in [`docs/DECISIONS.md`](./DECISIONS.md); executable
5
- > behavior remains defined by source, schemas, and tests.
38
+ There is no second semantic authority:
6
39
 
7
- ## 1. One sentence
40
+ - Skills own recommendations, conditional procedure, and the meaning of completion.
41
+ - The host model owns evidence synthesis and reversible implementation choices.
42
+ - The user owns goals, material trade-offs, risk acceptance, and external effects.
43
+ - MCP owns structure validation, idempotency, digests, CAS, leases, safe paths,
44
+ filesystem journals, recovery, and accepted checkpoints.
45
+ - Hooks own deterministic observation and bounded injection only.
46
+ - Agents receive one immutable Worker Packet and write only the declared output.
8
47
 
9
- `ultra-builder-pro-cli` is a multi-runtime plugin suite that **distributes** the
10
- Ultra Builder Pro engineering loop (skills + commands + workflow hooks) as
11
- native Claude Code, OpenCode, Codex, and Kimi Code plugins, and
12
- **runs** that loop with isolated sessions sharing checkout-local operational
13
- authority (`.ultra/.runtime/state.db`) plus one MCP-published Git team checkpoint
14
- (`.ultra/tasks/tasks.json`).
48
+ SQLite never chooses the next capability and never requires a fixed sequence of
49
+ reasoning steps. Semantic gaps appear in `diagnostics`, `warnings`, or
50
+ `needs_attention`; hard errors are reserved for corrupt authority, unsafe paths,
51
+ real concurrency conflicts, missing runtime prerequisites, permissions, and
52
+ irreversible external effects.
15
53
 
16
- It is not an agent or a general conversational-memory provider. It is the workflow
17
- substrate the supported hosts share, including project-local cross-session workflow
18
- memory under `.ultra/`.
54
+ ## Public MCP kernel
19
55
 
20
- ## 2. Three layers
56
+ Every host discovers exactly seven tools:
21
57
 
58
+ | Tool | Contract |
59
+ |---|---|
60
+ | `ultra.context` | Side-effect-free, bounded Context Envelope read |
61
+ | `ultra.record` | Typed, idempotent recording of facts, decisions, artifacts, tasks, outcomes, and observations |
62
+ | `ultra.checkpoint` | Reversible draft validation and immutable accepted Stage Checkpoint |
63
+ | `ultra.sync` | Inspect, migrate, import, or publish the Git team checkpoint |
64
+ | `ultra.session` | Lease/worktree acquisition plus immutable Worker Packet handoff |
65
+ | `ultra.archive` | Crash-safe delivery convergence and immutable archive |
66
+ | `ultra.doctor` | Mechanical diagnosis and backup-first repair |
67
+
68
+ Retired fine-grained tool names are not registered and return `UNKNOWN_TOOL`. The
69
+ source repository retains migration readers and regression fixtures for old authority,
70
+ but those modules are excluded from the npm distribution and have no live public
71
+ consumer.
72
+
73
+ ## Canonical Context Envelope
74
+
75
+ One generator supplies MCP reads, Hook breadcrumbs, compact recovery, Session handoff,
76
+ and review/debug Workers:
77
+
78
+ ```text
79
+ UltraContextEnvelope
80
+ ├── project and host identity
81
+ ├── Git head, branch, scope digest, and drift class
82
+ ├── accepted baseline and evidence references
83
+ ├── active Change contract and diagnostics
84
+ ├── selected Task contract and dependencies
85
+ ├── accepted normalized Decision Records
86
+ ├── typed evidence references and freshness
87
+ ├── execution lease, worktree, and Worker Packet
88
+ └── warnings, needs_attention, and hard_conflicts
22
89
  ```
23
- ┌──────────────────────────┐
24
- │ runtime CLI │
25
- │ (claude / opencode / │
26
- │ codex / kimi) │
27
- └────────────┬─────────────┘
28
- │
29
- ┌───────────────────┼────────────────────┐
30
- │ │ │
31
- ▼ ▼ ▼
32
- ╔══════════════╗ ╔════════════════╗ ╔══════════════╗
33
- ║ skill/ ║ ║ MCP server ║ ║ ultra-tools ║
34
- ║ (knowledge) ║ ║ (state ops) ║ ║ (Bash ║
35
- ║ ║ ║ ║ ║ fallback) ║
36
- ╚══════╤═══════╝ ╚════════╤═══════╝ ╚══════╤═══════╝
37
- │ │ │
38
- │ resolve / read │ task.* etc. │ selected init /
39
- │ (D29 read-only) │ │ recovery / ops
40
- └────────────┬───────┴──────────────────┘
41
- ▼
42
- ┌─────────────────────┐
43
- │ .ultra/.runtime/state.db │
44
- │ (SQLite + WAL) │ ← lifecycle + index authority
45
- └──────────┬──────────┘
46
- │
47
- ┌─────────┴──────────┐
48
- │ │
49
- ▼ ▼
50
- .ultra/.runtime/projections/ .ultra/tasks/tasks.json
51
- (local generated views) (Git team checkpoint:
52
- baseline + Changes + tasks)
53
- ```
54
90
 
55
- | Layer | Role | Form |
56
- |--------------|----------------------------------------------|-------------------------------------------------------|
57
- | **skill** | knowledge carrier; tells the runtime *what to do* | `skills/<name>/SKILL.md` discovered natively by all supported runtimes |
58
- | **MCP** | authoritative workflow-state, decision, artifact, and Context Spine API | stdio MCP server exposing 60 live tools across task/session/baseline/change/decision/workflow/artifact/system/plan families in [`spec/mcp-tools.yaml`](../spec/mcp-tools.yaml) |
59
- | **CLI** | explicit initialization, recovery, diagnostics, and orchestration | `ultra-tools` / `ubp-orchestrator`; only commands listed by `--help` are executable (see [`spec/cli-protocol.md`](../spec/cli-protocol.md)) |
60
-
61
- Why three: skills give us behavior portability across runtimes; MCP gives
62
- us a strongly-typed contract so we can refactor implementations without
63
- rewriting prompts; the CLI supplies bounded maintenance and recovery paths when
64
- the MCP cannot start. It is deliberately not a second change-state API:
65
- continuous change mutations remain MCP-only and fail closed (D12).
66
-
67
- The skill layer is **read-only by design** (D29) and is discovered directly by
68
- each host. Ultra exposes no `skill.*` MCP family: skills are documentation, not
69
- RPC, and host-native loaders own resolution and invocation.
70
-
71
- ## 3. Workflow memory and authoritative state
72
-
73
- Together, `.ultra/` retains project-local cross-session workflow memory:
74
- normalized intent, progress, tasks, bounded context, specifications, evidence,
75
- provenance, and recovery. `.ultra/.runtime/state.db` is operational authority for
76
- lifecycle, indexing, transitions, freshness, and coordination in one checkout.
77
- Registered digest-bound files carry semantic and evidence bodies.
78
- `.ultra/tasks/tasks.json` is a portable, digest-chained Git handoff for baseline,
79
- Change, and durable task records; it never owns sessions, leases, or live
80
- `in_progress` state. Generated projections and working scratch do not become
81
- authority merely because they live under `.ultra/`. The complete classification and
82
- promotion contract is
83
- [`ARTIFACT-AUTHORITY.md`](./ARTIFACT-AUTHORITY.md).
84
-
85
- All durable Ultra lifecycle and index state lives in one SQLite file with WAL enabled.
86
- Schema is fixed in [`spec/schemas/state-db.sql`](../spec/schemas/state-db.sql) and
87
- covers twenty-one tables:
88
-
89
- | Table | Holds | Phase |
90
- |--------------------|---------------------------------------------------|-------|
91
- | `baselines` | repository classification, greenfield/brownfield adoption, explicit unborn/clean/dirty Git snapshot, specs, evidence, verification, gap ledger, persisted known-red acceptance, and approval | 12→17 |
92
- | `tasks` | task rows — id, status, deps, files_modified, … | 2 |
93
- | `events` | append-only event stream; `id` is subscription cursor (D31) | 2 |
94
- | `sessions` | execution sessions, **including lease + heartbeat fields** (D32) | 4.5 |
95
- | `schema_version` | applied schema version (cross-version misread guard, D30) | 2 |
96
- | `migration_history`| one row per migration attempt (audit trail) | 2 |
97
- | `telemetry` | per-session token / cost / tool-call counters | 6 |
98
- | `specs_refs` | spec change tracking → staleness propagation | 5 |
99
- | `circuit_breaker` | bounded retry and halt state for failed tasks | 5 |
100
- | `changes` | continuous feature/fix/incident lifecycle, alignment-thread link, and incident baseline bypass | 12→16 |
101
- | `artifacts` | typed semantic/evidence ownership, digest, status, and provenance | 8C→20 |
102
- | `artifact_edges` | normalized source and consumer dependency graph | 20 |
103
- | `context_snapshots`| role/gate context, readiness, budget, execution seam, hashes, git head, provider refs | 10 |
104
- | `spec_learning_candidates` | approval-gated implementation discoveries for baseline convergence | 10 |
105
- | `trace_links` | task/spec/change traceability | 8C |
106
- | `incidents` | structured runtime failures and resolutions | 8C |
107
- | `projection_jobs` | durable projection outbox/retry state | 8C |
108
- | `event_consumers` | durable monotonic consumer cursors | 8C |
109
- | `workflow_runs` | init/research/plan/change/dev/test/review/deliver run authority, position, blockers, approval, and derived summary | 13 |
110
- | `workflow_steps` | ordered step state, evidence, decisions, immutable output paths, and recorded SHA-256 digests | 13 |
111
- | `decision_threads` | baseline/change/workflow-bound owner-agent alignment, interaction mode, normalized completion, and optional checkpoint authority | 16/19 |
112
- | `decision_items` | one-at-a-time owner choices, evidence, recommendations, durable effects, resolutions, delegation, deferral, and supersession history | 16 |
113
-
114
- Two rules make this work:
115
-
116
- 1. **No double source (D32).** lease/heartbeat live only in `sessions`,
117
- not in a `lease.json` file. Activity log lives only in `events`, not
118
- in JSON files. `.ultra/.runtime/projections/tasks.json` and its complete
119
- `contexts/task-*.md` files are local projections generated by the projector;
120
- manual edits are overwritten on the next state.db change. The tracked
121
- `.ultra/tasks/tasks.json` is a different surface: only MCP publishes or imports
122
- this versioned team checkpoint, and digest validation rejects manual edits.
123
-
124
- 2. **Single writer for mutable tables, multi-writer for `events`.**
125
- `.ultra/.runtime/state.db` opens in WAL with `busy_timeout=5000`. The MCP
126
- server holds the single writer connection for `baselines`, `tasks`, `sessions`,
127
- `changes`, `decision_threads`, `decision_items`, `workflow_runs`, `workflow_steps`,
128
- `artifacts`, `artifact_edges`, `context_snapshots`,
129
- `spec_learning_candidates`, `incidents`, `projection_jobs`, `telemetry`,
130
- `specs_refs`, and `migration_history`; the CLI calls
131
- those tools over stdio rather than opening its own writer. The
132
- `events` table is append-only and explicitly multi-writer — CLI and
133
- orchestrator processes append directly to it under the same WAL +
134
- `busy_timeout` discipline, since independent INSERTs do not conflict.
135
- External writers and public `task.append_event` may append observations only;
136
- lifecycle event names are emitted by the mutation that owns the corresponding
137
- DB transition and no event row can substitute for that transition.
138
- In `spec/mcp-tools.yaml` this split is captured by `writer_role: mcp`
139
- (must go through the MCP server) versus `writer_role: any` (any
140
- process may execute). Full policy lives in
141
- `docs/STATE-DB-ACCESS-POLICY.md` (Phase 2.2 / R25).
142
-
143
- Subscribers always pull `events.id > since_id` rather than `max(ts)`,
144
- because two events may share the same millisecond timestamp (D31).
145
-
146
- ### General memory and graph ownership remain outside Ultra Builder Pro
147
-
148
- Ultra Builder Pro does not retain prompts, transcripts, tool observations,
149
- session summaries, general conversational memory, or code-graph payloads. It ships
150
- no `memory.*` MCP family, general recall skill, or memory-capture hook. A separately
151
- installed provider such as cloud-mem/claude-mem owns general persistent memory and
152
- its own lifecycle. Ultra stores only bounded provider metadata references needed by
153
- workflow context. The only related migration surface is the explicit
154
- `ultra-tools legacy-memory` inspect/archive/confirmed-prune command for general memory
155
- data created by older releases. It is never called by a hook, MCP operation, or
156
- session lifecycle; it does not collect, recall, reflect, or remove Ultra workflow
157
- authority.
158
-
159
- ### Project baseline adoption
160
-
161
- `task.init_project` classifies source, tests, deployment, persistence, package
162
- scripts, and monorepo markers. It detects `greenfield` or `brownfield`, records
163
- bounded classification evidence and selected repository scope, and creates the
164
- same authoritative state shape without rewriting application code.
165
-
166
- Initialization completes after local authority, classification, Git/scaffold setup,
167
- and read-back verification. It does not start or complete research. An explicit
168
- `ultra-research` invocation lets the model inspect evidence and recommend a semantic
169
- route. The owner selects, modifies, delegates, or defers through the host-native
170
- question surface unless current intent already resolves the route. The normalized
171
- accepted coverage is then recorded, and research executes, verifies, or reuses only
172
- the evidence needed to converge the baseline. Omitted catalog areas create no
173
- workflow row. MCP validates the stored state and evidence, not the preceding user
174
- interaction.
175
-
176
- Auto initialization preserves an existing Git repository and HEAD. When Git is absent,
177
- it initializes `main`, adds the symlink-safe `.ultra` rule to `.gitignore`, and persists
178
- the resulting `unborn` snapshot. Existing repositories keep their tracked ignore file
179
- unchanged. It never creates a commit, remote, tag, or push. An initialized
180
- repository cannot use a non-Git workspace hash: research must obtain approval for a
181
- local checkpoint commit before `baseline.record`.
182
-
183
- Projection-only v4.4 and v4.5 projects use `ultra-tools migrate` to preserve the
184
- entire `.ultra` tree, import tasks and events, and create a `migrated/adopting`
185
- compatibility row. Schema upgrades use `ultra-tools system doctor --repair` and
186
- produce a pre-migration backup. Compatibility state never grants baseline approval;
187
- `baseline.start` with `replace_migrated: true` opens the actual brownfield adoption.
188
-
189
- `baseline.start` opens adoption, `baseline.record` captures server-hashed spec
190
- references, bounded repository/runtime evidence, actual verification results,
191
- known unknowns, repository branch and worktree snapshot, the categorized gap ledger,
192
- and metadata-only external provider references, and
193
- `baseline.converge` records explicit owner approval, including a durable
194
- `known_red_accepted` decision when applicable. Read paths continuously revalidate
195
- ready authority: scope, three specifications, source/runtime evidence, verification,
196
- known-red rationale and acceptance, research provenance and output digests, repository
197
- revision/worktree state, blocking gaps and unknowns, approver, and convergence time.
198
- A row cannot become trusted merely because its stored status says `ready`. A ready
199
- baseline is replaced only by an explicit re-adoption, preserving the superseded row
200
- for recovery.
201
- For a selected monorepo scope, the worktree digest and dirty-file list include only
202
- that scope; out-of-scope changes remain visible repository context but cannot be
203
- accepted implicitly by `accept_dirty_worktree`.
204
-
205
- New ordinary changes require a healthy `ready` baseline. An active ordinary change may
206
- continue through only the expected HEAD/worktree/spec/source drift created after its
207
- durable `bind-baseline` step; loss of ready approval, missing evidence, blocking gaps,
208
- or any other structural defect stops task/context/stage progression. A new incident can
209
- start on an unhealthy baseline only with an explicit reason and approver stored in
210
- `baseline_bypass_json`. Ordinary convergence and archive reconcile HEAD, worktree,
211
- and tracked-spec drift atomically. Break-glass incident archive creates an open
212
- blocking reconciliation gap, so incident recovery can finish without falsely marking
213
- the project baseline healthy.
214
-
215
- ### Human-agent decision authority
216
-
217
- Ultra separates autonomous evidence work from owner decision authority. The host reads
218
- the repository, runtime, tests, and primary sources first, then exposes only the earliest
219
- unresolved load-bearing choice. `decision.open` stores the recommendation, credible
220
- alternatives, evidence refs, and durable effects; a partial unique index guarantees one
221
- current question per thread. The host ends that turn and waits.
222
-
223
- The next response becomes a normalized owner decision, explicit reversible delegation,
224
- or consequence-bearing deferral. Prompts and transcripts are never persisted. The host
225
- applies accepted intent through the owning MCP operation or digest-bound artifact,
226
- reads it back, and records typed `applied_refs` when another authority changed. Routine
227
- settled state then closes through `decision.complete`, which is lifecycle completion
228
- rather than another approval. The breadcrumb recalls normalized accepted intent after
229
- the thread closes. Only a coherent cluster that needs an artifact-bound recovery
230
- boundary moves through prepare/confirm checkpointing. Matching workflow steps fail
231
- closed while a blocking question, blocking deferral, prepared checkpoint, or stale
232
- checkpoint artifact remains. Supersession preserves prior history and reopens alignment
233
- instead of silently editing an old decision. The shared procedure lives in
234
- `skills/ultra-think/references/decision-dialogue.md`; status, breadcrumb, and doctor expose
235
- only the current recovery surface.
236
-
237
- ## 4. Continuous changes — the daily unit of convergence
238
-
239
- After the initial baseline delivery, every fix, feature, redesign, or incident
240
- is represented by a `changes` row and an inspectable packet:
91
+ Summary output is bounded to 16 KiB. A selected stage-scoped full envelope is bounded
92
+ to 64 KiB. Large bodies remain lazy file references. Identical authority inputs reuse
93
+ the same content-addressed snapshot and digest.
94
+
95
+ ## Durable records
96
+
97
+ ### Decision Records
98
+
99
+ The host first inspects evidence, recommends a route, and asks one material question
100
+ only when current user intent does not already answer it. `ultra.record` persists the
101
+ normalized question, recommendation, selected result, effects, non-goals, provenance,
102
+ applied references, digest, status, and supersession link. It never stores raw
103
+ transcripts, prompts, chain-of-thought, or UI receipts.
104
+
105
+ Decision artifacts are team-visible:
241
106
 
242
107
  ```text
243
- active -> blocked -> active -> ready -> archived
244
- | |
245
- ├─ intent + adaptive research + findings
246
- ├─ typed delta + documentation reconciliation + deterministic progress
247
- ├─ plan + linked tasks + immutable contexts
248
- ├─ Change-scoped test/review/delivery evidence
249
- └─ atomic baseline apply + self-contained archive
108
+ .ultra/decisions/baseline/<decision-id>.json
109
+ .ultra/changes/active/<change-id>/decisions/<decision-id>.json
250
110
  ```
251
111
 
252
- `quick`, `standard`, `major`, and `incident` kinds require different evidence,
253
- but all require completed linked tasks, current context, declared documentation
254
- impact, and no open incident. Memory and graph payloads never enter Ultra;
255
- `context_snapshots.provider_refs_json` stores metadata references only.
256
-
257
- Baseline files are immutable while a Change is active. `change.delta` registers
258
- overlay payloads against exact baseline revision and specification digests.
259
- `change.documentation_reconcile` records exact document before/after evidence and
260
- consumer trace. Standard and major convergence requires both current authorities.
261
- `change.archive` preflights the whole write set and uses a recoverable transaction;
262
- only after all writes and baseline reconciliation succeed does it rebind the complete
263
- Change root into the archive.
264
-
265
- Workflow revisions preserve prior accepted runs. A candidate becomes current only
266
- through `workflow.supersede`; the artifact graph then invalidates the prior run's true
267
- transitive consumers without staling unrelated tasks.
268
-
269
- ### Context Spine
270
-
271
- Context Manifest v3 is the immutable handoff contract between planning,
272
- implementation, checking, review, convergence, and recovery. Each snapshot records:
273
-
274
- - one role (`plan`, `implement`, `check`, or `review`) and lifecycle gate;
275
- - required context references with local digests and reasons;
276
- - readiness blockers for missing/stale required references or an incomplete
277
- execution contract;
278
- - advisory attention budgets (12 files / about 12k tokens / 40% by default);
279
- - a DB-derived execution contract (`slice_kind`, public seam, exact verification command);
280
- - mechanically valid `allowed_transitions` and a `required_transition` only when a
281
- hard invariant leaves one recovery route;
282
- - a digest of the accepted Change authority so semantic updates invalidate the
283
- snapshot.
284
-
285
- Prompt input may identify the intended role/gate, add bounded reference candidates,
286
- and lower advisory budgets. It cannot supply or override the task seam, verification
287
- command, task context references, evidence digest, gate verdict, workflow summary, or
288
- machine transitions. A host may attach a clearly non-authoritative recommendation.
289
- Critical dev/test/review/deliver workflow steps record the matching
290
- snapshot as an output; test, review, and delivery reports carry its digest forward.
291
-
292
- `change.breadcrumb` derives the compact current position from state.db. Session,
293
- edit, resume, and OpenCode lifecycle hooks invoke one bundled read-only reader
294
- and inject it only while state.db proves an active, blocked, or ready workflow,
295
- never the intent body,
296
- provider content, or a conversation summary. A changed Git HEAD, task contract, or
297
- Change semantic authority marks the snapshot stale and permits recompilation through
298
- `change.context`.
299
-
300
- PRD decomposition and complex-task subdivision use the active host model. The
301
- MCP accepts the resulting structured tasks, validates schema, topology,
302
- baseline/change ownership, and transaction boundaries, then persists them. It
303
- does not call Anthropic, OpenAI, or another model provider and needs no separate
304
- model API credential.
305
-
306
- Plugin installation does not activate a semantic workflow and never edits the
307
- user's `CLAUDE.md`, `AGENTS.md`, or equivalent durable instructions. Public
308
- workflows require explicit user invocation. A completed workflow returns
309
- mechanically allowed transitions and a host-owned recommendation, then stops;
310
- it never launches the next public workflow. OpenCode realizes this boundary
311
- with explicit commands backed by private plugin workflow assets, while Claude,
312
- Codex, and Kimi use their native implicit-invocation controls.
313
-
314
- File count, token estimate, and context-share overflow produce warnings, never a
315
- refusal. The agent may narrow reads, load files lazily, or split a slice when that
316
- preserves correctness; it must not raise a threshold merely to clear a gate or
317
- drop required incident evidence.
318
-
319
- `change.learning_propose` records a durable implementation discovery without
320
- silently rewriting the baseline. `change.learning_resolve` enforces approval,
321
- rejection, and applied transitions. Proposed or merely approved candidates block
322
- convergence, so daily work cannot leave accepted behavior stranded in chat or a
323
- delta packet.
324
-
325
- `incident` is the canonical debug lane. Creating one also registers a durable
326
- `diagnosis.md` artifact with five mandatory sections: reproduction, hypotheses,
327
- root cause, regression test, and recovery. Convergence validates the artifact
328
- structure and refreshes its content hash, so a debugger result that exists only
329
- in chat cannot satisfy delivery. A host-native debugger may produce the bounded
330
- analysis, but the primary agent owns the artifact, linked task, regression
331
- evidence, and final convergence decision.
332
-
333
- Mutating MCP calls enqueue durable `projection_jobs`. Success is exposed in MCP
334
- response metadata; failure becomes a retryable structured incident instead of a
335
- swallowed warning. These jobs regenerate only checkout-local views below
336
- `.ultra/.runtime/projections/`; they never rewrite the Git team checkpoint. Durable
337
- semantic operations publish the checkpoint directly at baseline, Change, plan, and
338
- task handoff boundaries. `system.doctor` is read-only by default. Explicit repair
339
- performs backup-first schema upgrade, archive-journal recovery, session and local
340
- projection recovery, and regenerated local views. It cannot import or publish semantic
341
- team state, approve a baseline, or replace a corrupt SQLite file silently. `system
342
- restore` accepts only a verified SQLite backup inside `.ultra/.runtime/backups`,
343
- quarantines the corrupt authority, and rolls back on failure.
344
- When no valid backup exists, confirmed `system rebaseline` preserves both corrupt
345
- authority and the legacy task projection before creating a new brownfield adoption.
346
-
347
- ### Git team checkpoint and checkout merge
348
-
349
- `task.ledger_publish` serializes the current portable baseline, all Change summaries,
350
- and durable task contracts to `.ultra/tasks/tasks.json`. Per-record digests and
351
- revisions make independent fast-forward possible; the document state digest, parent
352
- digest, and bounded ancestor list reject stale or unrelated histories. Local process
353
- ownership fields are deliberately absent.
354
-
355
- The MCP server imports the checkpoint once when it opens project authority. A
356
- long-running host explicitly calls `task.ledger_import` after receiving a newer Git
357
- version. Import is transactional: it validates every record first, preserves local-only
358
- fields, fast-forwards clean records, and rejects same-record concurrency or an active
359
- task collision. Re-reading an already imported checkpoint performs no write. A ready
360
- baseline is never trusted from Git alone; import creates a local revalidation gap and
361
- clears checkout-specific approval until current scope bytes, HEAD, and verification
362
- converge.
363
-
364
- Baseline freshness hashes scoped application content independently of Git staging and
365
- excludes `.ultra/`, then checks commit ancestry. This removes the metadata treadmill:
366
- committing a checkpoint or another Ultra artifact advances HEAD without staling the
367
- baseline, while changing scoped application bytes still does.
368
-
369
- ## 5. Sessions — the execution unit
370
-
371
- A **session** is the standard unit of execution across all four runtimes
372
- (D20). One session =
373
-
374
- - one authoritative task/runtime lease;
375
- - an isolated `git worktree` created by `session.spawn`,
376
- - an ignored `.ultra` link from that checkout to the one central authority,
377
- - a lease + heartbeat row in `sessions` (D32),
378
- - an `artifact_dir` under `.ultra/.runtime/sessions/<sid>/` for logs and scratch;
379
- - either the active host operating in that exact worktree or an explicitly configured
380
- worker process.
381
-
382
- Spawning a new session for a task is gated by `session.admission_check`
383
- (D33). If another session already owns an active lease on the same task,
384
- the caller must pick one of three strategies before proceeding:
385
-
386
- - `takeover` — kill the prior process, claim the lease,
387
- - `resume` — attach to the existing session and continue,
388
- - `abandon` — give up and let the existing session finish.
389
-
390
- This admission gate is the smallest piece that prevents two agents from
391
- silently double-writing the same task — it is part of the v0.1 minimum
392
- execution layer, not deferred to Phase 5.
393
-
394
- Process status is not task status. Exit zero closes transport evidence but leaves the
395
- task `in_progress` until workflow gates pass; failure blocks the task and records
396
- circuit evidence. `session.close` preserves its worktree by default. Explicit cleanup
397
- is allowed only when the worktree is clean and its commit is an ancestor of the
398
- current checkout.
399
-
400
- The optional `ubp-orchestrator` daemon requires both `auto_dispatch: true` and an
401
- explicit executable plus argument array. It refuses to create a session when no real
402
- worker can consume it. Before launch, the runner verifies that Git ignores the
403
- symlink itself. When a legacy repository has only the directory-specific `.ultra/`
404
- rule, the runner adds `.ultra` to the repository-local `info/exclude` file without
405
- changing a tracked file. It then binds the checkout to the central `.ultra` and rolls
406
- the worktree back if the ignore rule or binding cannot be established safely. The
407
- executable is launched without a shell and receives
408
- the session, task, runtime, worktree, artifact, central DB, checkout root, and
409
- authority-root paths through reserved `UBP_*` environment variables that caller
410
- configuration cannot override.
411
- Pending tasks are skipped while stale, dependency-blocked, circuit-broken, leased, or
412
- overlapping the declared files of an active task.
413
-
414
- `execute-plan` is a resumable dispatcher, not a second workflow authority. It runs
415
- only the exact current DB task graph whose change-bound `plan` workflow is completed,
416
- healthy, and current. Empty, cyclic, duplicate-task, cross-change, stale, and merely
417
- exported plans fail before session creation. Owner approval is present only when a
418
- material planning choice required it. The dispatcher then runs only pending tasks whose
419
- dependencies are DB-terminal and re-reads task state. If a
420
- worker exits before the task converges, the current wave and plan become `paused`;
421
- later waves remain pending. Re-running the command skips completed waves and resumes
422
- the first unfinished one. `wave_completed` and `plan_completed` therefore describe
423
- Ultra task convergence, while `wave_paused` and `plan_paused` preserve unfinished
424
- gate state. Even with explicit auto-merge, integration is attempted only when the
425
- change task is `completed`, its completion commit matches the session HEAD, its dev
426
- workflow is ready, and its task review is current; process exit zero is insufficient.
427
- If task or plan authority changes after wave selection but before worktree creation,
428
- dispatch reports an authority pause without recording a worker failure or incrementing
429
- the circuit breaker.
430
-
431
- ## 6. Compaction recovery — checkpoint as a validated consumer
432
-
433
- `workflow_checkpoint.py` validates the current non-terminal workflow and writes
434
- a schema-versioned checkpoint atomically before compaction. On resume,
435
- `workflow_resume.py` reads both the live workflow and checkpoint defensively,
436
- rejects corrupt, non-object, schema-mismatched, or terminal candidates, and
437
- selects the newest valid state. A newer live state wins; a newer checkpoint can
438
- atomically restore a missing or older live state before context is re-injected.
439
- The checkpoint is therefore a recovery artifact and consumer, never a second
440
- durable authority alongside `.ultra/.runtime/state.db`.
441
-
442
- ## 7. Installation provenance — read-only cross-host diagnosis
443
-
444
- Every Claude Code, OpenCode, Codex, and Kimi Code adapter writes a normalized
445
- `provenance.json` for the assets it owns. The manifest records adapter/package
446
- identity, source metadata, per-file SHA-256 hashes, an aggregate digest, and the
447
- host-specific plugin, MCP, hook, launcher, and runtime contracts expected at
448
- that install scope. It never attributes a package to an enclosing consumer
449
- repository commit.
450
-
451
- `ubp --all --global --doctor [--json]` is read-only: it recomputes hashes and
452
- validates those entry points, returning a non-zero degraded result for
453
- missing/corrupt provenance, content drift, or broken host wiring. A single host
454
- can be selected instead of `--all`. This is separate from `system.doctor`, which
455
- diagnoses project state, projection, incidents, sessions, and backup-first
456
- workflow recovery.
457
-
458
- ## 8. Two timelines — rule layer vs execution layer
459
-
460
- The roadmap separates two concerns that compete for the same surface
461
- area (D13):
112
+ ### Stage Checkpoints
113
+
114
+ Each semantic stage has an editable draft. Acceptance creates an immutable revision.
115
+ A later accepted revision supersedes the prior one without erasing history:
462
116
 
117
+ ```text
118
+ draft N -> accepted N -> superseded by accepted N+1
463
119
  ```
464
- ┌─ Rule layer (Phase 1-4.5) ────────────────────────────────┐
465
- │ contracts, state schema, command shells, runtime │
466
- │ installers, smoke flow, execution-lite │
467
- │ │
468
- │ v0.1 (Week 8) = rule layer fully wired + execution-lite │
469
- └────────────────────────────────────────────────────────────┘
470
-
471
- ┌─ Execution layer (Phase 4.5-8B) ───────────────────────────┐
472
- │ recovery, staleness, monitoring, intelligence, planning │
473
- │ automation, parallel worktree dispatch │
474
- │ │
475
- │ v0.2 (Week 11) = recovery + monitoring + full conformance │
476
- │ v0.3 (Week 16) = PRD → execution-plan → parallel factory │
477
- │ v1.0 (Week 17-18) = npm + Homebrew + pip distribution │
478
- └────────────────────────────────────────────────────────────┘
120
+
121
+ There is no fixed step authorization table. Skills decide which evidence is relevant
122
+ to the actual work. Checkpoint validation verifies declared facts, files, digests, and
123
+ scope; an incomplete draft remains mutable.
124
+
125
+ ### Worker Packets
126
+
127
+ Every delegated worker receives a digest-bound packet containing the exact Context
128
+ Envelope, accepted decisions, Git boundary, Task contract, acceptance, evidence
129
+ references, output path, and output schema. The worker must echo `packet_digest`.
130
+ Workers do not write SQLite or accept their own result.
131
+
132
+ ## `.ultra` storage planes
133
+
134
+ ```text
135
+ .ultra/
136
+ ├── specs/ # tracked baseline semantic authority
137
+ ├── decisions/baseline/ # tracked normalized decisions
138
+ ├── docs/research/ # tracked research evidence
139
+ ├── changes/
140
+ │ ├── active/<change-id>/
141
+ │ │ ├── intent.md
142
+ │ │ ├── diagnosis.md # incident only
143
+ │ │ ├── decisions/
144
+ │ │ ├── research/
145
+ │ │ ├── delta/
146
+ │ │ ├── plan.json
147
+ │ │ ├── plan.md
148
+ │ │ ├── contexts/
149
+ │ │ ├── test/
150
+ │ │ ├── review/
151
+ │ │ ├── documentation/
152
+ │ │ └── delivery/
153
+ │ └── archive/ # immutable self-contained deliveries
154
+ ├── tasks/tasks.json # tracked digest-chained team checkpoint
155
+ ├── reports/templates/ # fixed schemas/templates
156
+ └── .runtime/ # ignored checkout-local state
157
+ ├── state.db[-wal|-shm]
158
+ ├── projections/
159
+ ├── sessions/
160
+ ├── worktrees/
161
+ ├── recovery/
162
+ ├── backups/
163
+ ├── telemetry/
164
+ ├── debug/
165
+ └── collab/
479
166
  ```
480
167
 
481
- The rule layer is shipped before the execution layer because users get
482
- value from "skills + tasks survive across sessions" long before they get
483
- value from "ten agents in parallel." Each milestone is independently
484
- shippable; downstream slip never blocks an earlier release.
485
-
486
- ## 9. Where to look next
487
-
488
- | Question | File |
489
- |----------------------------------------------------|-----------------------------------------------------|
490
- | What does each MCP tool accept and return? | [`spec/mcp-tools.yaml`](../spec/mcp-tools.yaml) |
491
- | How do CLI subcommands map to MCP tools? | [`spec/cli-protocol.md`](../spec/cli-protocol.md) |
492
- | Exact SQLite schema? | [`spec/schemas/state-db.sql`](../spec/schemas/state-db.sql) |
493
- | What does the Git team checkpoint look like? | [`spec/schemas/task-ledger.v1.schema.json`](../spec/schemas/task-ledger.v1.schema.json) |
494
- | What does the local task projection look like? | [`spec/fixtures/valid/tasks.v4.5.json`](../spec/fixtures/valid/tasks.v4.5.json) |
495
- | Current authority and package decisions | [`docs/DECISIONS.md`](./DECISIONS.md) |
496
- | When does each workflow write, invalidate, and converge state? | [`docs/WORKFLOW-LIFECYCLE.md`](./WORKFLOW-LIFECYCLE.md) |
497
-
498
- ## 10. Verifying the architecture
499
-
500
- Every contract on this page is enforced by `npm run test:spec`:
501
-
502
- - `validate-mcp-tools.cjs` — meta-schema for the tool manifest, plus
503
- per-tool sample input/output fixtures.
504
- - `validate-state-db.cjs` — schema applies cleanly to a fresh in-memory
505
- SQLite, valid fixtures insert, invalid fixtures are rejected by
506
- CHECK / NOT NULL / FK constraints.
507
- - `validate-json-schemas.cjs` — the team-checkpoint schema plus local projection
508
- schemas for `tasks.json` and `contexts/task-*.md`.
509
- - `validate-skills.cjs` — every existing skill passes the manifest
510
- contract; failures are recorded in `spec/migration-notes.md`.
511
- - `check-cli-mapping.cjs` — every MCP tool has exactly one CLI
512
- subcommand and the doc table never drifts from the YAML manifest.
513
-
514
- If any of these fails, the architecture is no longer the architecture.
168
+ Tracked Markdown and JSON carry inspectable semantic bodies and evidence. SQLite
169
+ stores their typed ownership, digest, references, freshness, and mechanical state.
170
+ The team checkpoint carries portable baseline, Change, Decision summary/reference,
171
+ Task contracts, dependencies, accepted Stage Checkpoints, and durable outcomes. It
172
+ excludes leases, PIDs, worktrees, telemetry, local `in_progress` ownership, and
173
+ completion commit backfill.
174
+
175
+ ## Host boundary
176
+
177
+ | Host | Native plugin surface | Context truth |
178
+ |---|---|---|
179
+ | Claude Code | plugin commands, Skills, agents, hooks, MCP | SessionStart breadcrumb plus Skill-entry full read |
180
+ | Codex | namespaced Skills, TOML agents, native hooks, MCP | session/prompt breadcrumb plus Skill-entry full read |
181
+ | OpenCode | command bundle, native agents, JavaScript events, MCP | system transform plus Skill-entry full read |
182
+ | Kimi Code | managed plugin commands, Skills, native hooks, MCP | native event breadcrumb plus Skill-entry full read |
183
+ | Grok Build | plugin Skills, commands, agents, camelCase hooks, MCP | Skill entry is authoritative; ignored hook stdout is never claimed as injection |
184
+
185
+ Adapters translate host-native questions and lifecycle events. They never own semantic
186
+ selection or durable state. Unsupported host lifecycle surfaces are described as
187
+ degraded, not emulated dishonestly.
188
+
189
+ ## Native runtime and installation
190
+
191
+ The MCP runtime externalizes `better-sqlite3` and installs its JavaScript package plus
192
+ the exact native `.node` binary. Provenance records platform, architecture, Node ABI,
193
+ runtime command, asset digests, and native digest. Launchers resolve a stable Node
194
+ executable and reject ABI drift before opening project authority.
195
+
196
+ Each host installation uses staging, the final host command for preflight, and atomic
197
+ swap. Preflight verifies initialization, exactly seven tools, a public write/read,
198
+ Doctor backup, close/reopen consistency, and no project initialization from
199
+ `tools/list`. A failed update preserves the previous installation.
200
+
201
+ ## Recovery and migration
202
+
203
+ `ultra.sync` owns semantic migration. `ultra.doctor` calls the same migration service
204
+ for mechanical repair and does not make semantic conflict choices. Supported inputs
205
+ include v4.4/v4.5 task projections, the legacy root-level state database, legacy Task
206
+ Contexts, and v0.22/v0.23 database and ledger authority.
207
+
208
+ Migration is inspectable, exact-byte backup-first, transactional, and fail-closed on
209
+ conflict. Old workflow and dialogue rows are retained as non-authoritative history;
210
+ current Context, Decisions, Checkpoints, and the team ledger are rebuilt from verified
211
+ facts. No user should edit SQLite or move a legacy file manually to recover.
212
+
213
+ ## External boundaries
214
+
215
+ Ultra does not own general conversational memory, prompt capture, transcript capture,
216
+ code-graph payloads, browser automation, deployment providers, framework guidance, or
217
+ global engineering policy. Those belong to independent providers or host/user
218
+ instruction files. Ultra may store only bounded provider references needed by an
219
+ accepted project checkpoint.