ultra-builder-pro-cli 0.20.0 → 0.22.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 (109) hide show
  1. package/.ultra-template/docs/research/README.md +26 -5
  2. package/.ultra-template/specs/discovery.md +1 -1
  3. package/.ultra-template/tasks/tasks.json +10 -3
  4. package/.ultra-template/templates/task-context.md +19 -0
  5. package/CHANGELOG.md +106 -0
  6. package/README.md +215 -41
  7. package/adapters/_shared/codex-assets.cjs +69 -11
  8. package/adapters/_shared/interaction-contract.cjs +36 -3
  9. package/adapters/_shared/runtime-assets.cjs +41 -1
  10. package/adapters/claude.js +7 -5
  11. package/adapters/codex.js +1 -1
  12. package/adapters/kimi.js +2 -8
  13. package/adapters/opencode.js +43 -30
  14. package/bin/orchestrator.js +64 -24
  15. package/docs/AGENT-CONTEXT.md +89 -49
  16. package/docs/ARCHITECTURE.md +112 -45
  17. package/docs/ARTIFACT-AUTHORITY.md +274 -0
  18. package/docs/COMMIT-HASH-BACKFILL.md +33 -90
  19. package/docs/DECISIONS.md +14 -6
  20. package/docs/LEGACY-CLI-CROSSWALK.md +16 -6
  21. package/docs/PLUGIN-ISOLATION-CONTRACT.md +6 -4
  22. package/docs/ROADMAP.md +20 -6
  23. package/docs/RUNTIME-COMPAT-MATRIX.md +29 -16
  24. package/docs/STATE-DB-ACCESS-POLICY.md +43 -13
  25. package/docs/WORKFLOW-LIFECYCLE.md +105 -50
  26. package/hooks/README.md +10 -8
  27. package/hooks/active_task_context.py +105 -18
  28. package/hooks/context_spine.py +16 -4
  29. package/hooks/health_check.py +5 -4
  30. package/hooks/pre_stop_check.py +5 -2
  31. package/hooks/runtime_paths.py +396 -0
  32. package/hooks/subagent_tracker.py +5 -2
  33. package/hooks/workflow_checkpoint.py +16 -3
  34. package/hooks/workflow_context.py +11 -3
  35. package/hooks/workflow_resume.py +7 -4
  36. package/mcp-server/breadcrumb.cjs +20 -2
  37. package/mcp-server/lib/archive-journal.cjs +1026 -111
  38. package/mcp-server/lib/archive-mutation-worker.py +365 -0
  39. package/mcp-server/lib/artifact-registry.cjs +1127 -0
  40. package/mcp-server/lib/baseline-workflow.cjs +69 -28
  41. package/mcp-server/lib/change-packet.cjs +818 -0
  42. package/mcp-server/lib/change-workflow.cjs +932 -176
  43. package/mcp-server/lib/context-paths.cjs +142 -0
  44. package/mcp-server/lib/context-spine.cjs +511 -45
  45. package/mcp-server/lib/decision-dialogue.cjs +345 -3
  46. package/mcp-server/lib/delivery-transaction.cjs +471 -0
  47. package/mcp-server/lib/doctor-backup-worker.cjs +328 -0
  48. package/mcp-server/lib/doctor.cjs +401 -11
  49. package/mcp-server/lib/git-bootstrap.cjs +458 -47
  50. package/mcp-server/lib/init-project.cjs +240 -95
  51. package/mcp-server/lib/plan-publication-worker.cjs +830 -0
  52. package/mcp-server/lib/plan-store.cjs +700 -5
  53. package/mcp-server/lib/project-breadcrumb.cjs +23 -4
  54. package/mcp-server/lib/projector.cjs +211 -42
  55. package/mcp-server/lib/runtime-paths.cjs +1687 -0
  56. package/mcp-server/lib/safe-project-file.cjs +385 -0
  57. package/mcp-server/lib/spec-learning.cjs +28 -12
  58. package/mcp-server/lib/state-authority.cjs +19 -3
  59. package/mcp-server/lib/state-db.cjs +263 -9
  60. package/mcp-server/lib/state-ops.cjs +254 -50
  61. package/mcp-server/lib/task-ledger.cjs +1342 -0
  62. package/mcp-server/lib/telemetry.cjs +12 -3
  63. package/mcp-server/lib/workflow-state.cjs +610 -58
  64. package/mcp-server/server.cjs +423 -42
  65. package/orchestrator/daemon.cjs +2 -10
  66. package/orchestrator/parallel-orchestrator.cjs +314 -50
  67. package/orchestrator/planner/plan-builder.cjs +1 -1
  68. package/orchestrator/recovery.cjs +125 -7
  69. package/orchestrator/session-close-journal-worker.cjs +5 -0
  70. package/orchestrator/session-close-journal.cjs +1014 -0
  71. package/orchestrator/session-runner.cjs +679 -69
  72. package/orchestrator/worktree-manager.cjs +186 -35
  73. package/package.json +2 -3
  74. package/skills/cc-collab/SKILL.md +4 -1
  75. package/skills/codex-collab/SKILL.md +5 -2
  76. package/skills/ultra-change/SKILL.md +34 -8
  77. package/skills/ultra-deliver/SKILL.md +26 -11
  78. package/skills/ultra-dev/SKILL.md +52 -10
  79. package/skills/ultra-doctor/SKILL.md +16 -3
  80. package/skills/ultra-init/SKILL.md +22 -11
  81. package/skills/ultra-plan/SKILL.md +58 -18
  82. package/skills/ultra-research/SKILL.md +37 -35
  83. package/skills/ultra-review/SKILL.md +14 -8
  84. package/skills/ultra-status/SKILL.md +18 -9
  85. package/skills/ultra-test/SKILL.md +11 -5
  86. package/skills/ultra-think/SKILL.md +6 -2
  87. package/skills/ultra-think/references/decision-dialogue.md +17 -6
  88. package/skills/ultra-verify/SKILL.md +4 -1
  89. package/spec/cli-protocol.md +21 -7
  90. package/spec/mcp-tools.yaml +629 -44
  91. package/spec/schemas/change-delta.v1.schema.json +153 -0
  92. package/spec/schemas/context-file.v4.5.schema.json +1 -1
  93. package/spec/schemas/documentation-reconciliation.v1.schema.json +106 -0
  94. package/spec/schemas/mcp-tools.schema.json +1 -1
  95. package/spec/schemas/state-db.sql +51 -14
  96. package/spec/schemas/task-ledger.v1.schema.json +217 -0
  97. package/spec/schemas/tasks.v4.5.schema.json +1 -1
  98. package/ultra-tools/cli.cjs +3 -2
  99. package/ultra-tools/commands/db.cjs +76 -25
  100. package/ultra-tools/commands/migrate.cjs +1000 -82
  101. package/ultra-tools/commands/session.cjs +34 -8
  102. package/ultra-tools/commands/status.cjs +32 -6
  103. package/ultra-tools/commands/system.cjs +129 -22
  104. package/.ultra-template/tasks/contexts/TEMPLATE.md +0 -19
  105. package/commands/learn.md +0 -10
  106. package/orchestrator/skill-miner.cjs +0 -133
  107. package/output-styles/coding-vibes.md +0 -67
  108. package/output-styles/structural-thinking.md +0 -61
  109. package/skills/learn/SKILL.md +0 -58
@@ -9,11 +9,13 @@
9
9
  `ultra-builder-pro-cli` is a multi-runtime plugin suite that **distributes** the
10
10
  Ultra Builder Pro engineering loop (skills + commands + workflow hooks) as
11
11
  native Claude Code, OpenCode, Codex, and Kimi Code plugins, and
12
- **runs** that loop with isolated sessions sharing one authoritative state
13
- store (`.ultra/state.db`).
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`).
14
15
 
15
- It is not an agent and it is not a memory provider. It is the workflow substrate
16
- the supported hosts share.
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/`.
17
19
 
18
20
  ## 2. Three layers
19
21
 
@@ -38,20 +40,22 @@ the supported hosts share.
38
40
  └────────────┬───────┴──────────────────┘
39
41
  ▼
40
42
  ┌─────────────────────┐
41
- │ .ultra/state.db │
42
- │ (SQLite + WAL) │ ← single authoritative store
43
+ │ .ultra/.runtime/state.db │
44
+ │ (SQLite + WAL) │ ← lifecycle + index authority
43
45
  └──────────┬──────────┘
44
- │ projector (Phase 2.6)
45
- ▼
46
- .ultra/tasks/tasks.json (read-only view)
47
- .ultra/tasks/contexts/*.md (read-only header)
48
- .ultra/activity-log.json (optional dump)
46
+ │
47
+ ┌─────────┴──────────┐
48
+ │ │
49
+ ▼ ▼
50
+ .ultra/.runtime/projections/ .ultra/tasks/tasks.json
51
+ (local generated views) (Git team checkpoint:
52
+ baseline + Changes + tasks)
49
53
  ```
50
54
 
51
55
  | Layer | Role | Form |
52
56
  |--------------|----------------------------------------------|-------------------------------------------------------|
53
57
  | **skill** | knowledge carrier; tells the runtime *what to do* | `skills/<name>/SKILL.md` discovered natively by all supported runtimes |
54
- | **MCP** | authoritative workflow-state, decision, and Context Spine API | stdio MCP server exposing 51 live tools across task/session/baseline/change/decision/workflow/system/plan families in [`spec/mcp-tools.yaml`](../spec/mcp-tools.yaml) |
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) |
55
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)) |
56
60
 
57
61
  Why three: skills give us behavior portability across runtimes; MCP gives
@@ -64,10 +68,22 @@ The skill layer is **read-only by design** (D29) and is discovered directly by
64
68
  each host. Ultra exposes no `skill.*` MCP family: skills are documentation, not
65
69
  RPC, and host-native loaders own resolution and invocation.
66
70
 
67
- ## 3. Authoritative state — `.ultra/state.db`
68
-
69
- All durable Ultra workflow state lives in one SQLite file with WAL enabled. Schema is
70
- fixed in [`spec/schemas/state-db.sql`](../spec/schemas/state-db.sql) and
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
71
87
  covers twenty-one tables:
72
88
 
73
89
  | Table | Holds | Phase |
@@ -82,7 +98,8 @@ covers twenty-one tables:
82
98
  | `specs_refs` | spec change tracking → staleness propagation | 5 |
83
99
  | `circuit_breaker` | bounded retry and halt state for failed tasks | 5 |
84
100
  | `changes` | continuous feature/fix/incident lifecycle, alignment-thread link, and incident baseline bypass | 12→16 |
85
- | `artifacts` | intent/context/verification artifact registry | 8C |
101
+ | `artifacts` | typed semantic/evidence ownership, digest, status, and provenance | 8C→20 |
102
+ | `artifact_edges` | normalized source and consumer dependency graph | 20 |
86
103
  | `context_snapshots`| role/gate context, readiness, budget, execution seam, hashes, git head, provider refs | 10 |
87
104
  | `spec_learning_candidates` | approval-gated implementation discoveries for baseline convergence | 10 |
88
105
  | `trace_links` | task/spec/change traceability | 8C |
@@ -98,14 +115,17 @@ Two rules make this work:
98
115
 
99
116
  1. **No double source (D32).** lease/heartbeat live only in `sessions`,
100
117
  not in a `lease.json` file. Activity log lives only in `events`, not
101
- in JSON files. `tasks.json` and the status header in
102
- `contexts/task-*.md` are **projections** generated by the projector;
103
- manual edits are overwritten on the next state.db change.
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.
104
123
 
105
124
  2. **Single writer for mutable tables, multi-writer for `events`.**
106
- `.ultra/state.db` opens in WAL with `busy_timeout=5000`. The MCP
125
+ `.ultra/.runtime/state.db` opens in WAL with `busy_timeout=5000`. The MCP
107
126
  server holds the single writer connection for `baselines`, `tasks`, `sessions`,
108
- `changes`, `decision_threads`, `decision_items`, `workflow_runs`, `workflow_steps`, `artifacts`, `context_snapshots`,
127
+ `changes`, `decision_threads`, `decision_items`, `workflow_runs`, `workflow_steps`,
128
+ `artifacts`, `artifact_edges`, `context_snapshots`,
109
129
  `spec_learning_candidates`, `incidents`, `projection_jobs`, `telemetry`,
110
130
  `specs_refs`, and `migration_history`; the CLI calls
111
131
  those tools over stdio rather than opening its own writer. The
@@ -123,14 +143,18 @@ Two rules make this work:
123
143
  Subscribers always pull `events.id > since_id` rather than `max(ts)`,
124
144
  because two events may share the same millisecond timestamp (D31).
125
145
 
126
- ### Memory ownership is outside Ultra Builder Pro
146
+ ### General memory and graph ownership remain outside Ultra Builder Pro
127
147
 
128
148
  Ultra Builder Pro does not retain prompts, transcripts, tool observations,
129
- session summaries, or cross-session memory. It ships no `memory.*` MCP family,
130
- no recall skill, and no memory-capture hook. A separately installed provider
131
- such as cloud-mem/claude-mem owns persistent memory and its own lifecycle. The
132
- only related migration surface is the explicit `ultra-tools legacy-memory`
133
- archive/prune command for data created by older releases.
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.
134
158
 
135
159
  ### Project baseline adoption
136
160
 
@@ -197,9 +221,12 @@ alternatives, evidence refs, and durable effects; a partial unique index guarant
197
221
  current question per thread. The host ends that turn and waits.
198
222
 
199
223
  The next response becomes a normalized owner decision, explicit reversible delegation,
200
- or consequence-bearing deferral. Prompts and transcripts are never persisted. Routine
201
- settled state closes through `decision.complete`, which is lifecycle completion rather
202
- than another approval. Only a coherent cluster that needs an artifact-bound recovery
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
203
230
  boundary moves through prepare/confirm checkpointing. Matching workflow steps fail
204
231
  closed while a blocking question, blocking deferral, prepared checkpoint, or stale
205
232
  checkpoint artifact remains. Supersession preserves prior history and reopens alignment
@@ -215,10 +242,11 @@ is represented by a `changes` row and an inspectable packet:
215
242
  ```text
216
243
  active -> blocked -> active -> ready -> archived
217
244
  | |
218
- ├─ intent + delta + plan └─ verification + baseline reconciliation
219
- ├─ linked tasks
220
- ├─ immutable context snapshots (role + gate + readiness + execution seam)
221
- └─ spec-learning candidates (proposed -> approved/rejected -> applied)
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
222
250
  ```
223
251
 
224
252
  `quick`, `standard`, `major`, and `incident` kinds require different evidence,
@@ -226,6 +254,18 @@ but all require completed linked tasks, current context, declared documentation
226
254
  impact, and no open incident. Memory and graph payloads never enter Ultra;
227
255
  `context_snapshots.provider_refs_json` stores metadata references only.
228
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
+
229
269
  ### Context Spine
230
270
 
231
271
  Context Manifest v3 is the immutable handoff contract between planning,
@@ -292,14 +332,40 @@ evidence, and final convergence decision.
292
332
 
293
333
  Mutating MCP calls enqueue durable `projection_jobs`. Success is exposed in MCP
294
334
  response metadata; failure becomes a retryable structured incident instead of a
295
- swallowed warning. `system.doctor` is read-only by default. Explicit repair performs
296
- backup-first schema upgrade, archive-journal recovery, session and projection
297
- recovery, and regenerated projections. It cannot approve a baseline or replace a
298
- corrupt SQLite file silently. `system restore` accepts only a verified SQLite backup
299
- inside `.ultra/backups`, quarantines the corrupt authority, and rolls back on failure.
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.
300
344
  When no valid backup exists, confirmed `system rebaseline` preserves both corrupt
301
345
  authority and the legacy task projection before creating a new brownfield adoption.
302
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
+
303
369
  ## 5. Sessions — the execution unit
304
370
 
305
371
  A **session** is the standard unit of execution across all four runtimes
@@ -309,7 +375,7 @@ A **session** is the standard unit of execution across all four runtimes
309
375
  - an isolated `git worktree` created by `session.spawn`,
310
376
  - an ignored `.ultra` link from that checkout to the one central authority,
311
377
  - a lease + heartbeat row in `sessions` (D32),
312
- - an `artifact_dir` under `.ultra/sessions/<sid>/` for logs and scratch;
378
+ - an `artifact_dir` under `.ultra/.runtime/sessions/<sid>/` for logs and scratch;
313
379
  - either the active host operating in that exact worktree or an explicitly configured
314
380
  worker process.
315
381
 
@@ -371,7 +437,7 @@ rejects corrupt, non-object, schema-mismatched, or terminal candidates, and
371
437
  selects the newest valid state. A newer live state wins; a newer checkpoint can
372
438
  atomically restore a missing or older live state before context is re-injected.
373
439
  The checkpoint is therefore a recovery artifact and consumer, never a second
374
- durable authority alongside `.ultra/state.db`.
440
+ durable authority alongside `.ultra/.runtime/state.db`.
375
441
 
376
442
  ## 7. Installation provenance — read-only cross-host diagnosis
377
443
 
@@ -424,7 +490,8 @@ shippable; downstream slip never blocks an earlier release.
424
490
  | What does each MCP tool accept and return? | [`spec/mcp-tools.yaml`](../spec/mcp-tools.yaml) |
425
491
  | How do CLI subcommands map to MCP tools? | [`spec/cli-protocol.md`](../spec/cli-protocol.md) |
426
492
  | Exact SQLite schema? | [`spec/schemas/state-db.sql`](../spec/schemas/state-db.sql) |
427
- | What does a tasks.json look like after projection? | [`spec/fixtures/valid/tasks.v4.5.json`](../spec/fixtures/valid/tasks.v4.5.json) |
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) |
428
495
  | Current authority and package decisions | [`docs/DECISIONS.md`](./DECISIONS.md) |
429
496
  | When does each workflow write, invalidate, and converge state? | [`docs/WORKFLOW-LIFECYCLE.md`](./WORKFLOW-LIFECYCLE.md) |
430
497
 
@@ -437,8 +504,8 @@ Every contract on this page is enforced by `npm run test:spec`:
437
504
  - `validate-state-db.cjs` — schema applies cleanly to a fresh in-memory
438
505
  SQLite, valid fixtures insert, invalid fixtures are rejected by
439
506
  CHECK / NOT NULL / FK constraints.
440
- - `validate-json-schemas.cjs` — projection schemas for `tasks.json` and
441
- `contexts/task-*.md`.
507
+ - `validate-json-schemas.cjs` — the team-checkpoint schema plus local projection
508
+ schemas for `tasks.json` and `contexts/task-*.md`.
442
509
  - `validate-skills.cjs` — every existing skill passes the manifest
443
510
  contract; failures are recorded in `spec/migration-notes.md`.
444
511
  - `check-cli-mapping.cjs` — every MCP tool has exactly one CLI
@@ -0,0 +1,274 @@
1
+ # Ultra artifact authority
2
+
3
+ This document defines what `.ultra/` remembers across sessions, which surface owns
4
+ each fact, and how working output becomes durable Ultra authority.
5
+
6
+ ## Boundary
7
+
8
+ `.ultra/` is the project-local cross-session workflow-memory envelope for Ultra
9
+ Builder Pro. It retains normalized intent, lifecycle progress, tasks, bounded execution
10
+ context, specifications, evidence, provenance, recovery state, and external provider
11
+ references. It is not a general conversational-memory system and does not retain raw
12
+ prompts, transcripts, chain-of-thought, general episodic summaries, or code-graph
13
+ payloads.
14
+
15
+ Semantic and evidence artifacts under `.ultra/` are trackable so reviewed intent and
16
+ verification can travel with the repository. `.ultra/.runtime/` is always ignored:
17
+ the SQLite authority, leases, worktrees, local telemetry, and recovery snapshots remain
18
+ checkout-local. `.ultra/tasks/tasks.json` is the narrow MCP-owned Git handoff for
19
+ portable baseline, Change, and durable task records; it is not a copy of live runtime
20
+ state.
21
+
22
+ ## Artifact classes
23
+
24
+ | Class | Examples | Authority |
25
+ |---|---|---|
26
+ | Checkout-local lifecycle and index | `.ultra/.runtime/state.db` | Operational authority for identifiers, normalized accepted intent, status, legal transitions, references, digests, freshness, provenance, locks, leases, transactions, recovery, and coordination in one checkout |
27
+ | Git team checkpoint | `.ultra/tasks/tasks.json` | MCP-published, digest-chained handoff of portable baseline, Change, task-contract, dependency, and durable status records; never live session or lease authority |
28
+ | Digest-bound semantic artifacts | specifications, research reports, Change intent/delta/plan, context manifests | Authoritative semantic bodies only while registered by the owning DB row or workflow step and matching its recorded digest |
29
+ | Digest-bound evidence artifacts | test, review, delivery, and verification reports | Authoritative evidence bodies only while registered, immutable where required, and matching the recorded digest and scope |
30
+ | Generated projections | `.ultra/.runtime/projections/tasks.json`, generated task contexts, activity exports | Checkout-local read-only views derived from DB authority; manual edits are overwritten and never become authority |
31
+ | Advisory recovery | `.ultra/.runtime/checkpoint.json` | Compact recovery hint derived from DB authority; stale or missing content never overrides the DB |
32
+ | Working scratch | `.ultra/.runtime/collab/`, temporary session output, incomplete drafts | Non-authoritative working material until verified and promoted through a supported workflow write |
33
+ | External provider references | memory or code-graph provider name, scope, version, stable reference, freshness metadata | Metadata-only context stored by Ultra; the provider remains authority for its payload |
34
+
35
+ The DB is not expected to contain every semantic paragraph. It owns checkout-local
36
+ lifecycle and the binding between a fact and its current content. A digest-bound file
37
+ owns the registered semantic or evidence body. The team checkpoint moves a reviewed
38
+ portable subset through Git and is merged into the receiving DB through MCP. None of
39
+ these surfaces independently owns all three roles.
40
+
41
+ ## Human, model, and mechanical responsibilities
42
+
43
+ | Actor | Responsible for | Must not do |
44
+ |---|---|---|
45
+ | Owner | Goals, acceptance, non-goals, material choices, risk acceptance, and authorization for irreversible or external effects | Supply facts the checkout or runtime can establish directly |
46
+ | Host model | Inspect evidence, recommend a route, ask only for unresolved owner choices, normalize the answer, call the owning write, update semantic artifacts, read back the result, and present the next recommendation | Fabricate evidence, infer owner authorization, or bypass legal transitions |
47
+ | Ultra MCP | Persist normalized inputs, validate structure and current digests, record lifecycle and provenance, enforce legal transitions, project local views, publish/import the Git checkpoint, and expose recovery | Choose product direction, prove a UI click, force a semantic route, or replace model judgment |
48
+ | Host adapter | Render the shared interaction contract through the host-native question and tool surfaces | Become a second workflow authority |
49
+ | Hook | Observe lifecycle, inject compact DB-derived recovery context, and protect MCP-owned checkpoint and generated projection paths | Select a semantic route or block ordinary development |
50
+
51
+ ## Intent persistence
52
+
53
+ The interaction sequence is:
54
+
55
+ ```text
56
+ inspect -> suggest -> host-native ask -> normalize -> persist -> apply -> read back
57
+ ```
58
+
59
+ The host-native ask is conditional. An explicit owner instruction can already resolve
60
+ a choice, so the model must not ask
61
+ again merely to manufacture proof. When interaction is needed, the adapter uses the
62
+ host-native question surface. Once the model writes the normalized result through
63
+ `decision.resolve`, `decision.delegate`, or `decision.defer`, the DB treats that result
64
+ as current cross-session intent authority. It does not store or verify a UI receipt,
65
+ raw prompt, or transcript.
66
+
67
+ If the accepted decision changes another Ultra authority, the model applies that change
68
+ through its owning MCP tool or digest-bound artifact, reads the result back, and passes
69
+ typed `applied_refs` to `decision.complete`. A decision whose normalized record is
70
+ itself the complete authority may have no applied reference. Breadcrumb and decision
71
+ read paths recall accepted intent only after the dialogue thread is completed or
72
+ confirmed. A row-backed applied reference names an exact field and canonical value,
73
+ with an optional digest of that value. A specification or artifact reference names
74
+ the exact file digest. Row existence alone never proves that intent was applied.
75
+
76
+ ## Promotion and evidence
77
+
78
+ Working material becomes durable only when all applicable conditions hold:
79
+
80
+ 1. the active workflow permits the write;
81
+ 2. consequential claims are verified against the checkout, runtime, test result, or
82
+ primary source;
83
+ 3. the model writes through the owning MCP operation or immutable artifact path;
84
+ 4. the DB records the owning baseline, change, workflow, task, or artifact reference;
85
+ 5. content-bearing files match the recorded SHA-256 digest and scope;
86
+ 6. the model reads back the resulting state before reporting completion.
87
+
88
+ The durable evidence trail may include normalized decisions, delegation source,
89
+ durable effects, typed applied references, workflow-step evidence, artifact hashes,
90
+ verification commands and results, provenance, events, and recovery state. It must not
91
+ include chain-of-thought, UI-click proof, raw prompts, or conversation transcripts.
92
+
93
+ Verified conclusions from `.ultra/.runtime/collab/` or other scratch locations must be promoted
94
+ into the invoking DB-bound workflow artifact or report. Keeping a file in the scratch
95
+ directory is not promotion.
96
+
97
+ ## Change overlay authority
98
+
99
+ An active Change is an isolated overlay below
100
+ `.ultra/changes/active/<change-id>/`. Its intent, adaptive research, `findings.md`,
101
+ typed delta payloads, plan, contexts, documentation payloads, progress projection,
102
+ test reports, review artifacts, and delivery evidence remain below that root. Change
103
+ research never edits baseline specifications.
104
+
105
+ `change.delta` registers exact baseline id, repository revision, specification
106
+ digests, accepted decisions, non-goals, acceptance, documentation impact, unknowns,
107
+ and every semantic mutation's before/after digest. A no-semantic-change result is an
108
+ explicit typed delta, not an absent file. `progress.md` is a deterministic projection
109
+ of the registered delta and documentation state; it is never an independent status
110
+ authority.
111
+
112
+ `change.documentation_reconcile` binds the current delta id and digest, every changed
113
+ document's before/after digest, delta and acceptance references, verification, and a
114
+ verified consumer or explicit no-consumer reason. Standard and major delivery require
115
+ one current reconciliation even when its document set is empty.
116
+
117
+ `change.archive` preflights the complete target set before writing, applies overlay
118
+ bytes through a recoverable local transaction, refreshes baseline digests, moves the
119
+ complete Change root to its archive location, and rebinds registry paths. A conflict,
120
+ crash, or DB failure must roll back or resume the whole packet; no subset is reported
121
+ as delivered.
122
+
123
+ ## Context and plan authority
124
+
125
+ `change.context` is a pure compiler. It reads accepted Change, task, baseline, checkout,
126
+ and provider-reference authority and writes one immutable manifest plus its DB snapshot
127
+ row. It never updates provider references or semantic Change fields. Each snapshot is
128
+ identified exactly by `change_id`, nullable `task_id`, `role`, and `gate`; consumers
129
+ must not substitute a newer snapshot from a different tuple.
130
+
131
+ Context refs preserve `expected_digest`, `anchor`, `scope`, and `freshness_policy`.
132
+ Digest-bound refs are revalidated at the consuming gate, existence-bound implementation
133
+ targets may change while remaining present, and advisory drift is retained as a
134
+ warning. File bodies stay lazy. Implementation manifests inline only the selected task,
135
+ its direct dependency/integration neighborhood, and its task-context contract.
136
+
137
+ A current plan is a Change-owned pair:
138
+
139
+ - `<artifact_root>/plan.json` is the machine-readable topology and exact planning
140
+ context binding;
141
+ - `<artifact_root>/plan.md` is the deterministic human projection of the same plan and
142
+ task contracts.
143
+
144
+ `plan.export` selects both paths from the owning Change and accepts no arbitrary output
145
+ path. `verify-plan` binds the JSON digest and the preceding `plan/planning` snapshot;
146
+ the artifact registry records both plan files with that context provenance. Publication
147
+ preflights both path authorities and prior digests, rejects symlinked ancestors or
148
+ targets, and journals the two file replacements so a registry or event failure restores
149
+ both prior files while the SQLite transaction rolls back. The global
150
+ `.ultra/execution-plan.json` remains readable only for explicit legacy migration and is
151
+ never current write or dispatch authority.
152
+
153
+ ## Registry contract
154
+
155
+ `artifact.record` is the public writer for a semantic or evidence file that is not
156
+ already registered by its owning workflow operation. Every managed registry row has:
157
+
158
+ - a typed `owner_type` and `owner_id`;
159
+ - an artifact `kind`, project-relative `path`, lifecycle `status`, and SHA-256
160
+ `digest`;
161
+ - `before_digest` and `after_digest` values for optimistic write validation and
162
+ change evidence;
163
+ - structured `provenance` and optional metadata;
164
+ - normalized source and consumer edges in `artifact_edges`.
165
+
166
+ The write replaces all edges for the artifact in one immediate SQLite transaction.
167
+ It never accumulates stale edges with `INSERT OR IGNORE`. If an existing digest
168
+ changes, the same transaction emits `spec_changed`, marks only reachable artifact
169
+ and task consumers stale through typed artifact/task/workflow/change intermediates,
170
+ and records the exact invalidated endpoints. Self-edges and dependency cycles are
171
+ rejected without changing prior authority. A caller can provide
172
+ `expected_before_digest`; a mismatch fails without changing the row or its edges.
173
+
174
+ `artifact.get` reads by unique ID or unambiguous path. It fails closed when a path
175
+ has multiple active authorities and reports whether the row satisfies the managed
176
+ registry contract. A canonical path can have only one non-archived authority across
177
+ all owners and kinds. Runtime, scratch, the MCP-owned team checkpoint, and generated
178
+ task contexts cannot be promoted through this API.
179
+
180
+ Owning internal writers use the same transaction contract. Change intent, delta and
181
+ documentation packets, contexts, adaptive research, findings, incident diagnosis,
182
+ plan, test, review, delivery, archive reconciliation, and specification learning
183
+ cannot update a managed digest or provenance through a parallel SQL path.
184
+
185
+ Rows migrated from pre-20 schemas remain readable and preserve their original IDs,
186
+ paths, hashes, timestamps, and legacy change/task ownership. They are marked
187
+ `managed = 0` until an owning workflow or `artifact.record` supplies complete
188
+ provenance and dependency edges. This compatibility state preserves data without
189
+ pretending that an old row satisfies the current registry contract.
190
+
191
+ ## Dependency and orphan diagnosis
192
+
193
+ `system.doctor` compares the registry, dependency graph, filesystem, and owner
194
+ tables. It reports:
195
+
196
+ - unregistered semantic or evidence files;
197
+ - registered files that are missing or whose digest/status is stale;
198
+ - missing typed owners;
199
+ - current managed artifacts without a consumer, unless explicitly terminal;
200
+ - dangling source or consumer endpoints;
201
+ - graph cycles that cannot become consumer evidence;
202
+ - more than one active authority for the same canonical path;
203
+ - legacy compatibility rows that remain unmanaged;
204
+ - legacy generated task contexts left outside the runtime projection root.
205
+
206
+ `.ultra/.runtime/**`, `.ultra/scratch/**`, and fixed scaffold support files are outside
207
+ orphan diagnosis. Current generated projections are local runtime files and are not
208
+ semantic artifacts. A retired `.ultra/tasks/contexts/**` entry is diagnosed and any
209
+ generated marker is reported as a ghost projection. Before a baseline is ready, only
210
+ the reserved
211
+ `discovery.md`, `product.md`, `architecture.md`, and `research-distillate.md` scaffold
212
+ paths under `.ultra/specs/` are provisional; every additional specification is subject
213
+ to orphan diagnosis immediately. Completion cannot be manufactured by registering
214
+ empty templates. Doctor and status expose registered, managed, and unmanaged counts,
215
+ and compatibility remains unhealthy until every retained row is deliberately promoted
216
+ or retired.
217
+
218
+ ## Team checkpoint
219
+
220
+ `.ultra/tasks/tasks.json` has kind `ultra-team-task-ledger` and a versioned schema. It
221
+ contains:
222
+
223
+ - one portable baseline record, when present;
224
+ - every Change summary, including a Change that has not yet produced tasks;
225
+ - durable task contracts, dependencies, acceptance mappings, and statuses;
226
+ - per-record revisions, parent digests, the checkpoint state digest, and bounded
227
+ checkpoint ancestry.
228
+
229
+ It excludes `in_progress` ownership, session ids, leases, worktrees, telemetry,
230
+ projection jobs, recovery scratch, and `completion_commit`. Those fields are meaningful
231
+ only in the checkout that owns the active process or Git object.
232
+
233
+ MCP publishes a new generation at semantic handoff points: baseline convergence,
234
+ Change creation or update, plan acceptance, durable task-contract or status change,
235
+ task expansion or deletion, and Change convergence or archive. A direct edit is
236
+ rejected by host hooks and fails digest validation even without hooks.
237
+
238
+ `task.ledger_import` validates schema, full and per-record digests, bounded ancestry,
239
+ Change ownership, task parents, and local active sessions. A clean record fast-forwards.
240
+ A record changed on both sides, a non-descendant checkpoint, or a remote update to a
241
+ locally active task stops with a typed conflict. Re-importing the same checkpoint
242
+ performs no DB write. A ready imported baseline becomes `draft` or `adopting` with a
243
+ blocking checkout-local revalidation gap; Git cannot prove the receiving checkout's
244
+ HEAD, scope bytes, verification, or accepted dirty state. Publication remains blocked
245
+ until that local baseline converges, preventing one unvalidated checkout from
246
+ downgrading team authority.
247
+
248
+ Legacy v4.4/v4.5 projections are replaced only through `task.ledger_publish`. The
249
+ publisher first compares every available durable field with SQLite, writes the exact
250
+ legacy bytes to `.ultra/.runtime/backups/task-ledger/`, and refuses any mismatch.
251
+ Doctor diagnoses this state but never performs the semantic replacement.
252
+
253
+ ## Task-context projection
254
+
255
+ `.ultra/.runtime/projections/contexts/<task-id>.md` is fully generated from current DB
256
+ authority. The projector replaces the whole file, including its execution contract and
257
+ stale banner, and marks it with `generated_by: ultra-projector`. It never preserves
258
+ arbitrary prose inserted into an earlier projection.
259
+
260
+ Before retiring an existing `.ultra/tasks/contexts/<task-id>.md`, the projector
261
+ promotes its exact authored body bytes once into a digest-bound
262
+ `legacy_context_findings` artifact owned and consumed by the task. Legacy frontmatter,
263
+ stale banners, and generated contract marker regions are removed first; any remaining
264
+ authored body is retained exactly, even when an older projector had preserved it after
265
+ a generated contract. Migration fails without deleting the authored body if promotion
266
+ cannot be registered. Both legacy reads and runtime projection writes reject traversal,
267
+ symlink ancestors, and path escape. When a task disappears, only a runtime projection
268
+ carrying the generated marker may be pruned, and the removal emits
269
+ `projection_pruned`.
270
+
271
+ Model findings, decisions, or evidence discovered during development must be written
272
+ below the owning Change root and registered through the workflow or `artifact.record`.
273
+ The next context projection references that authority. Editing the task-context body
274
+ or an accepted baseline specification directly is neither persistence nor promotion.