ultra-builder-pro-cli 0.11.0 → 0.12.1

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 (63) hide show
  1. package/.ultra-template/specs/architecture.md +54 -223
  2. package/.ultra-template/specs/discovery.md +34 -231
  3. package/.ultra-template/specs/product.md +44 -200
  4. package/.ultra-template/tasks/contexts/TEMPLATE.md +36 -0
  5. package/.ultra-template/tasks/tasks.json +6 -0
  6. package/CHANGELOG.md +42 -1
  7. package/README.md +21 -9
  8. package/adapters/_shared/codex-assets.cjs +1 -1
  9. package/adapters/_shared/handbook.cjs +4 -3
  10. package/adapters/_shared/tests/handbook.test.cjs +4 -0
  11. package/adapters/opencode.js +8 -2
  12. package/adapters/tests/codex.test.cjs +2 -2
  13. package/adapters/tests/kimi-hook.test.cjs +1 -1
  14. package/adapters/tests/opencode.test.cjs +36 -1
  15. package/commands/ultra-init.md +3 -3
  16. package/docs/AGENT-CONTEXT.md +16 -8
  17. package/docs/ARCHITECTURE.md +32 -5
  18. package/docs/PLAN.zh-CN.md +7 -5
  19. package/docs/ROADMAP.md +4 -2
  20. package/docs/RUNTIME-COMPAT-MATRIX.md +8 -5
  21. package/docs/STATE-DB-ACCESS-POLICY.md +17 -11
  22. package/docs/USER-HANDBOOK-CONTRACT.md +8 -5
  23. package/hooks/README.md +4 -3
  24. package/hooks/adapters/codex.py +1 -1
  25. package/hooks/adapters/kimi.py +1 -1
  26. package/hooks/context_spine.py +120 -16
  27. package/hooks/health_check.py +11 -0
  28. package/hooks/pre_stop_check.py +6 -5
  29. package/mcp-server/lib/baseline-workflow.cjs +415 -0
  30. package/mcp-server/lib/baseline-workflow.test.cjs +225 -0
  31. package/mcp-server/lib/change-workflow.cjs +24 -27
  32. package/mcp-server/lib/change-workflow.test.cjs +202 -6
  33. package/mcp-server/lib/context-spine.cjs +74 -9
  34. package/mcp-server/lib/context-spine.test.cjs +15 -0
  35. package/mcp-server/lib/doctor.cjs +14 -0
  36. package/mcp-server/lib/doctor.test.cjs +25 -1
  37. package/mcp-server/lib/init-project.cjs +49 -14
  38. package/mcp-server/lib/provider-refs.cjs +42 -0
  39. package/mcp-server/lib/spec-learning.test.cjs +5 -0
  40. package/mcp-server/lib/state-db.cjs +63 -4
  41. package/mcp-server/lib/state-db.test.cjs +8 -3
  42. package/mcp-server/server.cjs +48 -3
  43. package/mcp-server/tests/init-project.test.cjs +54 -8
  44. package/mcp-server/tests/server-contract.test.cjs +99 -2
  45. package/mcp-server/tests/state-db.test.cjs +11 -2
  46. package/package.json +1 -1
  47. package/skills/ultra-change/SKILL.md +24 -13
  48. package/skills/ultra-deliver/SKILL.md +15 -5
  49. package/skills/ultra-dev/SKILL.md +4 -0
  50. package/skills/ultra-doctor/SKILL.md +8 -2
  51. package/skills/ultra-init/SKILL.md +46 -50
  52. package/skills/ultra-init/references/brownfield-adoption.md +65 -0
  53. package/skills/ultra-plan/SKILL.md +9 -2
  54. package/skills/ultra-research/SKILL.md +10 -5
  55. package/skills/ultra-status/SKILL.md +13 -6
  56. package/spec/cli-protocol.md +4 -0
  57. package/spec/mcp-tools.yaml +223 -4
  58. package/spec/schemas/mcp-tools.schema.json +1 -1
  59. package/spec/schemas/state-db.sql +33 -2
  60. package/ultra-tools/commands/status.cjs +20 -2
  61. package/ultra-tools/commands/task.cjs +4 -1
  62. package/ultra-tools/status-command.test.cjs +20 -0
  63. package/ultra-tools/system-command.test.cjs +5 -0
@@ -37,18 +37,19 @@ native command or skill -> MCP workflow-state operation -> .ultra/state.db
37
37
  | MCP | `mcp-server/server.cjs` | Authoritative typed operations over `.ultra/state.db` |
38
38
  | CLI | `ultra-tools`, `ubp-orchestrator` | Selected initialization, backup-first recovery, automation, and diagnostics; not a change-state mirror |
39
39
 
40
- `.ultra/state.db` is the only durable Ultra authority for changes, tasks,
40
+ `.ultra/state.db` is the only durable Ultra authority for baselines, changes, tasks,
41
41
  sessions, events, incidents, projection jobs/cursors, telemetry, review evidence,
42
42
  and circuit-breaker state. `tasks.json`, context Markdown, execution plans, and
43
43
  reports are projections or workflow artifacts.
44
44
 
45
45
  ## 3. Live MCP and declared contracts
46
46
 
47
- `spec/mcp-tools.yaml` declares and the bundled server registers 32 tools across
48
- five families:
47
+ `spec/mcp-tools.yaml` declares and the bundled server registers 36 tools across
48
+ six families:
49
49
 
50
50
  | Family | Live tools |
51
51
  |---|---|
52
+ | `baseline.*` | start, record, get, converge |
52
53
  | `task.*` | create, update, list, get, switch_tag, delete, init_project, expand, parse_prd, dependency_topo, append_event, subscribe_events |
53
54
  | `session.*` | spawn, close, get, list, admission_check, heartbeat, subscribe_events |
54
55
  | `change.*` | create, update, get, list, context, breadcrumb, learning_propose, learning_resolve, converge, archive |
@@ -67,14 +68,19 @@ fixtures. Do not add an ad-hoc server handler first.
67
68
  Context Manifest v2 is a DB-backed role handoff, not a static codebase summary.
68
69
  `change.context` compiles required references, digests, readiness, context budget,
69
70
  public seam, exact verification command, and one next action for `plan`,
70
- `implement`, `check`, or `review`. The default fresh-context contract is at most
71
- 12 files, about 12k tokens, and 40% of the host context; wider work must use an
72
- explicit `expand_contract`.
71
+ `implement`, `check`, or `review`. The default 12-file, about 12k-token, and 40%
72
+ fresh-context values are attention guidance. Overflow produces warnings; it does
73
+ not block work or require raising a threshold. Prefer direct reads, bounded
74
+ excerpts, or a smaller slice when they preserve correctness, and retain all
75
+ necessary context when they do not.
73
76
 
74
77
  `change.breadcrumb` is the only compact router. Hooks may inject its change/task,
75
78
  role, gate, readiness, blockers, and one next action. They must not inject intent
76
79
  bodies, transcripts, external memory, or graph payloads. Missing references,
77
- digest drift, HEAD drift, or budget overflow blocks readiness.
80
+ digest drift, HEAD drift, or a missing execution seam blocks readiness. Context
81
+ size and an incomplete baseline are advisory during an active bounded change;
82
+ baseline adoption becomes a hard gate at convergence; revision and tracked-spec
83
+ integrity are reconciled and rechecked atomically at archive.
78
84
 
79
85
  Stable discoveries use `change.learning_propose`; they reach the baseline only
80
86
  through approve/reject/apply transitions in `change.learning_resolve`. Unresolved
@@ -103,7 +109,7 @@ the shared read-only `context_spine.py` breadcrumb helper:
103
109
  - `active_task_context.py` before an edit;
104
110
  - `workflow_checkpoint.py` before compaction;
105
111
  - `workflow_resume.py` after compaction/resume;
106
- - `pre_stop_check.py` at stop;
112
+ - `pre_stop_check.py` reports unfinished workflow position at stop without denial;
107
113
  - `subagent_tracker.py` for bounded worker lifecycle evidence.
108
114
 
109
115
  `workflow_context.py`, `active_task_context.py`, and `workflow_resume.py` read the
@@ -114,6 +120,8 @@ edit guidance to an active workflow. Compact/stop/subagent hooks remain
114
120
  active-workflow scoped. OpenCode natively injects baseline/change context and
115
121
  protects the projection; full health inspection is available through
116
122
  `system.doctor` rather than a session-start health hook.
123
+ Advisory baseline or context-budget warnings are presentation only and never
124
+ reject an edit, stop, or tool call.
117
125
  Generic command blocking, post-edit governance, and unrelated user hooks are not
118
126
  copied into Ultra Builder Pro.
119
127
 
@@ -53,7 +53,7 @@ the supported hosts share.
53
53
  | Layer | Role | Form |
54
54
  |--------------|----------------------------------------------|-------------------------------------------------------|
55
55
  | **skill** | knowledge carrier; tells the runtime *what to do* | `skills/<name>/SKILL.md` discovered natively by all supported runtimes |
56
- | **MCP** | authoritative workflow-state and Context Spine API | stdio MCP server exposing 32 live tools across task/session/change/system/plan families in [`spec/mcp-tools.yaml`](../spec/mcp-tools.yaml) |
56
+ | **MCP** | authoritative workflow-state and Context Spine API | stdio MCP server exposing 36 live tools across baseline/task/session/change/system/plan families in [`spec/mcp-tools.yaml`](../spec/mcp-tools.yaml) |
57
57
  | **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)) |
58
58
 
59
59
  Why three: skills give us behavior portability across runtimes; MCP gives
@@ -70,10 +70,11 @@ RPC, and host-native loaders own resolution and invocation.
70
70
 
71
71
  All durable Ultra workflow state lives in one SQLite file with WAL enabled. Schema is
72
72
  fixed in [`spec/schemas/state-db.sql`](../spec/schemas/state-db.sql) and
73
- covers sixteen tables:
73
+ covers seventeen tables:
74
74
 
75
75
  | Table | Holds | Phase |
76
76
  |--------------------|---------------------------------------------------|-------|
77
+ | `baselines` | greenfield/brownfield adoption, specs, verification, unknowns, and approval | 11 |
77
78
  | `tasks` | task rows — id, status, deps, files_modified, … | 2 |
78
79
  | `events` | append-only event stream; `id` is subscription cursor (D31) | 2 |
79
80
  | `sessions` | execution sessions, **including lease + heartbeat fields** (D32) | 4.5 |
@@ -101,7 +102,7 @@ Two rules make this work:
101
102
 
102
103
  2. **Single writer for mutable tables, multi-writer for `events`.**
103
104
  `.ultra/state.db` opens in WAL with `busy_timeout=5000`. The MCP
104
- server holds the single writer connection for `tasks`, `sessions`,
105
+ server holds the single writer connection for `baselines`, `tasks`, `sessions`,
105
106
  `changes`, `context_snapshots`, `spec_learning_candidates`, `telemetry`,
106
107
  `specs_refs`, and `migration_history`; the CLI calls
107
108
  those tools over stdio rather than opening its own writer. The
@@ -125,6 +126,26 @@ such as cloud-mem/claude-mem owns persistent memory and its own lifecycle. The
125
126
  only related migration surface is the explicit `ultra-tools legacy-memory`
126
127
  archive/prune command for data created by older releases.
127
128
 
129
+ ### Project baseline adoption
130
+
131
+ `task.init_project` detects an empty repository as `greenfield` and an existing
132
+ codebase as `brownfield` unless the caller supplies an explicit mode. It creates
133
+ the same authoritative state shape without rewriting application code.
134
+
135
+ `baseline.start` opens adoption, `baseline.record` captures server-hashed spec
136
+ references, bounded repository/runtime evidence, actual verification results,
137
+ known unknowns, and metadata-only external provider references, and
138
+ `baseline.converge` records explicit owner approval. A ready baseline is replaced
139
+ only by an explicit re-adoption, preserving the superseded row for recovery.
140
+
141
+ With no active change, a missing, incomplete, or stale baseline routes to
142
+ `ultra-init`. During an already active bounded fix or incident it is an advisory
143
+ warning so recovery work remains possible. `change.converge` requires that adoption
144
+ has produced a `ready` baseline, but does not reject the HEAD or tracked-spec drift
145
+ created by the change itself. `change.archive` declares baseline updates, refreshes
146
+ the revision and digests, rechecks full baseline health inside the same transaction,
147
+ and rolls back both state and artifacts if reconciliation remains incomplete.
148
+
128
149
  ## 4. Continuous changes — the daily unit of convergence
129
150
 
130
151
  After the initial baseline delivery, every fix, feature, redesign, or incident
@@ -151,8 +172,9 @@ checking, review, convergence, and recovery. Each snapshot records:
151
172
 
152
173
  - one role (`plan`, `implement`, `check`, or `review`) and lifecycle gate;
153
174
  - required context references with local digests and reasons;
154
- - readiness blockers for missing/stale references or budget overflow;
155
- - a fresh-context budget (12 files / about 12k tokens / 40% by default);
175
+ - readiness blockers for missing/stale required references or an incomplete
176
+ execution contract;
177
+ - advisory attention budgets (12 files / about 12k tokens / 40% by default);
156
178
  - an execution contract (`slice_kind`, public seam, exact verification command);
157
179
  - one deterministic next action.
158
180
 
@@ -161,6 +183,11 @@ edit, and resume hooks inject only this breadcrumb, never the intent body,
161
183
  provider content, or a conversation summary. A changed git HEAD marks the
162
184
  snapshot stale and routes back to `change.context`.
163
185
 
186
+ File count, token estimate, and context-share overflow produce warnings, never a
187
+ refusal. The agent may narrow reads, load files lazily, or split a slice when that
188
+ preserves correctness; it must not raise a threshold merely to clear a gate or
189
+ drop required incident evidence.
190
+
164
191
  `change.learning_propose` records a durable implementation discovery without
165
192
  silently rewriting the baseline. `change.learning_resolve` enforces approval,
166
193
  rejection, and applied transitions. Proposed or merely approved candidates block
@@ -1,6 +1,6 @@
1
1
  # ultra-builder-pro-cli — 历史执行计划与决策日志
2
2
 
3
- > **2026-07-17 当前生效边界(D50-D53,覆盖下文旧 Phase 6/7 的内置图谱、memory 与 runtime 设计)**:
3
+ > **2026-07-18 当前生效边界(D50-D54,覆盖下文旧 Phase 6/7 的内置图谱、memory 与 runtime 设计)**:
4
4
  > Ultra Builder Pro 不再拥有 `memory.*`、recall、prompt/transcript/observation/summary
5
5
  > 收集 hook 或私有 agent memory。跨会话记忆全部交给独立安装的 cloud-mem/claude-mem。
6
6
  > 插件只保留 12 个 Ultra 公共 workflow(新增 daily `ultra-change` 与诊断
@@ -10,8 +10,8 @@
10
10
  > Kimi Code 采用各自 native plugin 呈现,其他旧 runtime adapter 已退役。下文所有与此冲突的
11
11
  > memory/hindsight 章节仅作为历史实施记录,不再是当前需求或运行时契约。
12
12
 
13
- **当前状态**:v0.11.0;四宿主 native plugin、32 个 live MCP tool、
14
- schema 10.0(16 表)、portable Skill authoring contract、双轴 review、
13
+ **当前状态**:v0.12.1;四宿主 native plugin、36 个 live MCP tool、
14
+ schema 11.0(17 表)、portable Skill authoring contract、双轴 review、
15
15
  Context Spine v2 / breadcrumb / spec-learning、持续 change/context/convergence/doctor、incident debug lane、
16
16
  checkpoint 恢复消费与跨宿主安装 provenance/doctor 已落地;npm 发布由
17
17
  `v*.*.*` tag 触发。以下 Phase 0-9 正文保留为 2026-04 的实施历史,不再作为
@@ -1642,6 +1642,7 @@ Week 18 buffer(ship 中任何 Phase 的 25% 滑动吃掉)
1642
1642
  | **D51** | **2026-07-17** | **runtime 收敛为 Claude Code、OpenCode、Codex**:删除第四 runtime 的 adapter、安装参数、collab skill、prompt、schema、pricing、调度与测试面;`ultra-verify` 改为当前宿主主责加单一只读外部顾问 | 用户确认不再需要第四 runtime;0.6.0 退役契约阻止其重新进入活跃源码或发布包 |
1643
1643
  | **D52** | **2026-07-17** | **初始交付后进入持续变更闭环**:新增 `ultra-change` / `ultra-doctor`、change/context/artifact/trace/incident/projection/consumer 状态、delta-first spec、确定性 convergence 与 baseline reconciliation;删除内置 code-graph watcher 和通用命令代理,Memory/图谱只保留外部 provider 元数据引用 | 用户确认采用最佳组合落地;解决日常小改导致 spec/context 漂移、投影失败静默和异常无恢复证据的问题 |
1644
1644
  | **D53** | **2026-07-17** | **Harness 缺口一次性闭环**:`incident` 成为带五段 `diagnosis.md` 结构门禁的 canonical debug lane;compact checkpoint 由 resume 消费、校验、择新并原子恢复;三宿主安装写 normalized provenance,`ubp --doctor` 只读校验 asset hash 与 plugin/hook/MCP/runtime contract | 将 GSD 的 debug/fresh context、GStack 的 checkpoint/readiness 与 ECC 的 doctor/provenance 思路收敛为 Ultra 自有契约;Memory 与图谱继续由外部 provider 所有,且不恢复任何已退役 surface |
1645
+ | **D54** | **2026-07-18** | **老项目接入与非阻断门禁闭环**:schema 11.0 新增 greenfield/brownfield baseline authority 与 `baseline.start/record/get/converge`;`task.init_project` 自动识别新旧仓库;上下文文件数、token 和占比改为 advisory warning,active change 的 baseline 问题同样只告警,`change.converge` / delivery 恢复硬门禁 | 避免 Ultra 把既有项目当新产品,也避免必要的 IM incident 因四个大文件超预算而无法施工;限制只在损坏权威、缺少执行契约、证据陈旧和最终收敛边界阻断 |
1645
1646
 
1646
1647
  ---
1647
1648
 
@@ -1666,8 +1667,9 @@ Week 18 buffer(ship 中任何 Phase 的 25% 滑动吃掉)
1666
1667
  - **Session**:GSD-2 模式升级版(D20):新进程 + 独立 worktree + lease/
1667
1668
  heartbeat(存 sessions 表) + artifact dir;Phase 4.5 实装。
1668
1669
  - **state.db**:`.ultra/state.db` SQLite + WAL 数据库,所有 Ultra workflow
1669
- 状态的权威源;当前 15 表,新增 changes/artifacts/context_snapshots/
1670
- trace_links/incidents/projection_jobs/event_consumers;Phase 2 建立,D52 扩展。
1670
+ 状态的权威源;当前 17 表,包含 baselines、changes、artifacts、
1671
+ context_snapshots、spec_learning_candidates、trace_links、incidents、
1672
+ projection_jobs 与 event_consumers;Phase 2 建立,D52-D54 扩展。
1671
1673
  - **三层架构**:§4.1;skill(知识,只读发现)+ MCP(状态操作主路径)+
1672
1674
  CLI(兜底)。
1673
1675
  - **staleness**:task 的 spec 被改后,未开工的 pending task 自动标记
package/docs/ROADMAP.md CHANGED
@@ -44,23 +44,25 @@ sharing one authoritative workflow store.
44
44
  | 8B | Execution automation (dispatch / parallel worktree / merge) | ✅ done (D48, `8224159`) — **v0.3 ready** |
45
45
  | 8C | Continuous change packets + context compiler + convergence + doctor | ✅ done (D52) |
46
46
  | 10 | Context Spine v2 + breadcrumb + fresh-context budget + spec learning + two-axis review | ✅ done |
47
+ | 11 | Greenfield/brownfield baseline adoption + advisory context budgets + convergence gate | ✅ done |
47
48
  | 9 | Release pipeline | npm tag publishing live; Homebrew / pip not implemented |
48
49
 
49
50
  ## What is in the repo today
50
51
 
51
52
  ```
52
53
  spec/ ← Phase 1 single source of truth
53
- ├── mcp-tools.yaml (32 live tools across 5 families)
54
+ ├── mcp-tools.yaml (36 live tools across 6 families)
54
55
  ├── cli-protocol.md (CLI ↔ MCP mapping table)
55
56
  ├── schemas/ (state-db.sql + 4 JSON schemas)
56
57
  ├── fixtures/{valid,invalid}/ (+ v4.4-project for migration)
57
58
  └── scripts/test-all.cjs (npm run test:spec — 7 validation stages)
58
59
 
59
60
  mcp-server/ ← Phase 2 authoritative state layer
60
- ├── server.cjs (stdio MCP server, 32 task/session/change/system/plan tools)
61
+ ├── server.cjs (stdio MCP server, 36 baseline/task/session/change/system/plan tools)
61
62
  ├── lib/
62
63
  │ ├── state-db.cjs (SQLite + WAL + pragmas)
63
64
  │ ├── state-ops.cjs (full write API, status state machine)
65
+ │ ├── baseline-workflow.cjs (project adoption + approval + reconciliation)
64
66
  │ └── projector.cjs (state.db → tasks.json + context md)
65
67
  └── tests/ (npm run test:state)
66
68
 
@@ -50,7 +50,7 @@ not presented as nonexistent custom agents.
50
50
  | Active edit boundary | FULL, `PreToolUse Edit|Write` | FULL, `tool.execute.before` rejects projection writes | FULL, `PreToolUse Edit|Write|apply_patch` | FULL, native `PreToolUse Edit|Write` deny contract |
51
51
  | Pre-compact checkpoint | FULL | FULL | FULL | FULL, native `PreCompact` |
52
52
  | Post-compact context injection | FULL | FULL, native compacting context | FULL, native `PostCompact` restore | DEGRADED; checkpoint restoration runs, but Kimi 0.26/0.27 does not reinject fire-and-forget hook text |
53
- | Incomplete-stop gate | FULL, native blocking `Stop` | DEGRADED, no equivalent blocking stop hook | FULL, native blocking `Stop` | FULL, native structured deny |
53
+ | Stop lifecycle advisory | FULL, native non-blocking `Stop` | N/A, no equivalent stop event needed | FULL, native non-blocking `Stop` | FULL, native non-blocking `Stop` |
54
54
  | Subagent lifecycle evidence | FULL | DEGRADED, no equivalent packaged event | FULL | FULL, native `SubagentStart` / `SubagentStop` |
55
55
 
56
56
  Kimi's session bootstrap therefore also instructs recovery to inspect
@@ -63,20 +63,23 @@ applies at baseline, while compact/stop/subagent enforcement remains
63
63
  active-workflow scoped. No host receives prompt capture, transcript capture,
64
64
  observation journaling, session-summary memory, generic command blocking, or
65
65
  generic post-edit policy.
66
+ Baseline-adoption and context-budget warnings are injected as advisory context;
67
+ they do not deny edits or stop active incident work.
66
68
 
67
69
  ## 4. MCP and state
68
70
 
69
71
  | Capability | Claude Code | OpenCode | Codex | Kimi Code 0.26+ |
70
72
  |---|---|---|---|---|
71
73
  | stdio MCP registration | plugin `.mcp.json` | `opencode.json` local MCP entry | plugin `.mcp.json` | plugin `mcpServers` entry |
72
- | Live/declared contracts | 32 | 32 | 32 | 32 |
74
+ | Live/declared contracts | 36 | 36 | 36 | 36 |
75
+ | Greenfield/brownfield baseline adoption | FULL | FULL | FULL | FULL |
73
76
  | Context Spine v2 / breadcrumb | FULL | FULL, DB-generated projection consumed by native JS | FULL | FULL |
74
77
  | Approval-gated spec learning | FULL | FULL | FULL | FULL |
75
78
  | Host-native review/discovery/ask | native | native | documented in `codex-capability-map.json` | native Kimi tools and workers |
76
79
  | Durable authority | project `.ultra/state.db` | project `.ultra/state.db` | project `.ultra/state.db` | project `.ultra/state.db` |
77
80
  | Ultra memory API | N/A | N/A | N/A | N/A |
78
81
 
79
- All 32 `task.*`, `session.*`, `change.*`, `system.*`, and `plan.*` operations
82
+ All 36 `baseline.*`, `task.*`, `session.*`, `change.*`, `system.*`, and `plan.*` operations
80
83
  registered by `mcp-server/server.cjs` are live. Review, impact discovery, skill
81
84
  loading, and user interaction remain host-native surfaces.
82
85
 
@@ -123,9 +126,9 @@ records. Uninstall refuses an unmanaged or conflicting root.
123
126
 
124
127
  | Capability | Contract |
125
128
  |---|---|
126
- | Current state schema | `10.0` |
129
+ | Current state schema | `11.0` |
127
130
  | Runtime values | `claude`, `opencode`, `codex`, `kimi` |
128
- | Upgrade from earlier schema | preserves Kimi runtime rows, adds Context Spine columns and `spec_learning_candidates` transactionally |
131
+ | Upgrade from earlier schema | preserves runtime rows, adds Context Spine state through 10.0, then adds authoritative baseline adoption state transactionally in 11.0 |
129
132
  | Preservation gate | rows, IDs, indexes, foreign keys, telemetry, incidents, and migration history remain intact |
130
133
  | Failure behavior | rollback; no partially upgraded authority database |
131
134
 
@@ -3,28 +3,30 @@
3
3
  > Phase 2.2 contract. Trace: PLAN §6 Phase 2.2, decisions D18 / D32 / D37,
4
4
  > risks R21 / R25.
5
5
 
6
- `.ultra/state.db` is the only authoritative state store for tasks,
7
- events, sessions, telemetry, and spec references (D18). Every process
6
+ `.ultra/state.db` is the only authoritative state store for baselines, changes,
7
+ tasks, events, sessions, incidents, projections, telemetry, and spec references
8
+ (D18, D52, D54). Every process
8
9
  that touches it must follow the rules below; deviations are bugs.
9
10
 
10
11
  ## 1. Three-role write matrix
11
12
 
12
- | Role | tasks | events | sessions | telemetry | specs_refs | migration_history |
13
- |----------------------------|:-----:|:------:|:--------:|:---------:|:----------:|:-----------------:|
14
- | **MCP server** (single writer for mutables) | RW | RW | RW | RW | RW | RW |
15
- | **CLI** (`ultra-tools …`) | R | RW (append-only) | R | R | R | R |
16
- | **Orchestrator daemon** (Phase 5+) | R | RW | RW | RW | RW | R |
13
+ | Role | tasks | baselines | change/artifact state | events | sessions | telemetry | specs_refs | migration_history |
14
+ |---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
15
+ | **MCP server** (single writer for mutables) | RW | RW | RW | RW | RW | RW | RW | RW |
16
+ | **CLI** (`ultra-tools …`) | R | RW (init only) | R | RW (append-only) | R | R | R | RW (migration only) |
17
+ | **Orchestrator daemon** | R | R | R | RW | RW | RW | RW | R |
17
18
 
18
19
  - **R** = read-only;
19
20
  - **RW** = read + write;
20
21
  - A `(append-only)` qualifier means the role may execute `INSERT INTO`
21
22
  but never `UPDATE` / `DELETE`.
22
23
 
23
- The CLI may indirectly mutate any table by spawning the MCP server over
24
+ The CLI may indirectly mutate ordinary workflow tables by spawning the MCP server over
24
25
  stdio and calling `task.update`, `session.spawn`, etc. — but the actual
25
- SQLite write is performed by the MCP server's writer connection. The CLI
26
- never opens a writer connection on `tasks`, `sessions`, `telemetry`,
27
- `specs_refs`, or `migration_history`.
26
+ SQLite write is performed by the MCP server's writer connection. The documented
27
+ exceptions are initial schema/baseline creation, migration, and explicitly
28
+ authorized backup-first doctor recovery. The CLI never provides a parallel raw
29
+ write API for normal task, change, session, or baseline lifecycle updates.
28
30
 
29
31
  The append-only carve-out for `events` exists because `events.id INTEGER
30
32
  PRIMARY KEY AUTOINCREMENT` makes concurrent inserts collision-free under
@@ -68,7 +70,11 @@ Detection happens at boot: `statvfs` of `.ultra/state.db`'s mount;
68
70
 
69
71
  | Table | Writer of record |
70
72
  |--------------------|--------------------------------------------------------|
73
+ | `baselines` | MCP server (`baseline.start` / `baseline.record` / `baseline.converge`); initialization CLI may create the first row |
71
74
  | `tasks` | MCP server (`task.create` / `task.update` / `task.delete`) |
75
+ | `changes` | MCP server (`change.create` / `change.update` / `change.converge` / `change.archive`) |
76
+ | `artifacts`, `context_snapshots`, `spec_learning_candidates`, `trace_links` | MCP server through change lifecycle tools |
77
+ | `incidents`, `projection_jobs`, `event_consumers`, `circuit_breaker` | MCP server; backup-first doctor recovery may perform only documented mechanical transitions |
72
78
  | `events` | MCP server **and** any process via append-only INSERT |
73
79
  | `sessions` | MCP server (`session.spawn` / `session.close` / `session.heartbeat`); orchestrator may write status transitions |
74
80
  | `telemetry` | MCP server (collected from tool-call wrappers); orchestrator may dump bulk samples |
@@ -7,7 +7,7 @@ only one small managed section describing its runtime boundary.
7
7
  ## Source and render targets
8
8
 
9
9
  `adapters/_shared/handbook.cjs` is the canonical source. It renders the common
10
- authority, Context Spine, specification-learning, memory, hook, agent, and
10
+ authority, baseline adoption, Context Spine, specification-learning, memory, hook, agent, and
11
11
  package boundaries with host-native command syntax:
12
12
 
13
13
  | Runtime | Default target | Main invocation form |
@@ -22,10 +22,13 @@ host receives only its native invocation and collaboration names.
22
22
 
23
23
  The managed block deliberately stays short. It says that `.ultra/state.db` is
24
24
  authoritative; `change.context` compiles role/gate readiness, bounded references,
25
- fresh-context budget, public seam, and exact verification; hooks inject only the
26
- DB-derived `change.breadcrumb`; and unresolved specification learning or either
27
- failed review axis blocks convergence. Detailed procedures remain in the plugin
28
- skills so user handbooks do not accumulate duplicated prompt sediment.
25
+ fresh-context budget, public seam, and exact verification; size budgets and an
26
+ incomplete baseline during active work are advisory, while an approved baseline is
27
+ required for convergence and full baseline health is restored atomically at archive;
28
+ hooks inject only the DB-derived
29
+ `change.breadcrumb`; and unresolved specification learning or either failed review
30
+ axis blocks convergence. Detailed procedures remain in the plugin skills so user
31
+ handbooks do not accumulate duplicated prompt sediment.
29
32
 
30
33
  ## Managed-block contract
31
34
 
package/hooks/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Ultra Builder Pro workflow hooks
2
2
 
3
3
  These hooks observe only Ultra-owned state. Session health/context recognizes an initialized
4
- `.ultra/state.db` and active continuous changes; edit/compact/stop/subagent enforcement remains
5
- bounded to the relevant Ultra projection or a non-terminal workflow.
4
+ `.ultra/state.db` and active continuous changes. Direct projection writes remain blocked;
5
+ context, compact, stop, and subagent lifecycle behavior is recovery-oriented and does not turn
6
+ advisory workflow conditions into refusal gates.
6
7
 
7
8
  | Lifecycle | Hook | Purpose |
8
9
  |---|---|---|
@@ -12,7 +13,7 @@ bounded to the relevant Ultra projection or a non-terminal workflow.
12
13
  | Before edit | `active_task_context.py` | Protect `tasks.json` and restate the same DB-derived task breadcrumb |
13
14
  | Before compact | `workflow_checkpoint.py` | Validate and atomically save a minimal workflow checkpoint |
14
15
  | After compact/resume | `workflow_resume.py` | Prefer the DB breadcrumb; restore the minimal file checkpoint only when no active change owns recovery |
15
- | Stop | `pre_stop_check.py` | Block once when the Ultra workflow is incomplete |
16
+ | Stop | `pre_stop_check.py` | Report an incomplete workflow boundary and allow stop |
16
17
  | Subagent lifecycle | `subagent_tracker.py` | Append lifecycle evidence under `.ultra/runtime/` |
17
18
 
18
19
  The plugin deliberately does not capture prompts, tool observations, transcripts, summaries, or
@@ -175,7 +175,7 @@ def adapt_output(output: dict[str, Any], event: str) -> dict[str, Any]:
175
175
  if event == "Stop":
176
176
  if output.get("decision") == "block":
177
177
  result["decision"] = "block"
178
- result["reason"] = str(output.get("reason") or "Ultra completion gate blocked stop")
178
+ result["reason"] = str(output.get("reason") or "Ultra hook blocked stop")
179
179
  return result
180
180
 
181
181
  if event in {"PreCompact", "PostCompact", "SubagentStop"}:
@@ -3,7 +3,7 @@
3
3
 
4
4
  Kimi 0.26 uses snake_case JSON input compatible with the workflow hooks, but
5
5
  its output contract accepts only ``message`` plus an optional structured deny.
6
- This adapter preserves real projection/stop blocks, converts foreign context
6
+ This adapter preserves explicit projection denials and optional Stop decisions, converts foreign context
7
7
  fields into Kimi messages, and fails open with diagnostic evidence.
8
8
  """
9
9
 
@@ -2,6 +2,7 @@
2
2
  """Read and render the compact DB-derived Ultra Context Spine breadcrumb."""
3
3
 
4
4
  import json
5
+ import hashlib
5
6
  import sqlite3
6
7
  import subprocess
7
8
  from pathlib import Path
@@ -13,6 +14,12 @@ CONTEXT_COLUMNS = {
13
14
  "role", "gate", "next_action", "readiness", "blockers_json",
14
15
  "context_json", "manifest_path", "manifest_hash", "git_head", "task_id",
15
16
  }
17
+ ADVISORY_CONTEXT_CODES = {
18
+ "CONTEXT_FILE_BUDGET_EXCEEDED",
19
+ "CONTEXT_TOKEN_BUDGET_EXCEEDED",
20
+ "EXECUTION_CONTEXT_BUDGET_EXCEEDED",
21
+ "EXECUTION_CONTEXT_BUDGET_ADVISORY",
22
+ }
16
23
 
17
24
 
18
25
  def find_root(start: Path):
@@ -49,8 +56,57 @@ def git_head(root: Path):
49
56
  return result.stdout.strip() if result.returncode == 0 else None
50
57
 
51
58
 
52
- def _next_action(change, task, tasks, role, readiness, stored, state_changed):
59
+ def baseline_health(conn, root: Path):
60
+ row = conn.execute(
61
+ """SELECT id, mode, status, repository_revision, spec_refs_json
62
+ FROM baselines WHERE status != 'superseded'
63
+ ORDER BY updated_at DESC, rowid DESC LIMIT 1"""
64
+ ).fetchone()
65
+ if row is None:
66
+ return {"status": "fail", "blockers": ["BASELINE_MISSING"], "warnings": [], "baseline": None}
67
+ baseline = dict(row)
68
+ blockers = []
69
+ warnings = []
70
+ if baseline["status"] != "ready":
71
+ blockers.append(f"BASELINE_NOT_READY:{baseline['status']}")
72
+ elif baseline["mode"] == "migrated":
73
+ warnings.append("BASELINE_MIGRATION_REVIEW_RECOMMENDED")
74
+ else:
75
+ for spec in safe_json(baseline.get("spec_refs_json"), []):
76
+ ref = spec.get("path") if isinstance(spec, dict) else None
77
+ expected = spec.get("digest") if isinstance(spec, dict) else None
78
+ if not isinstance(ref, str) or not ref or Path(ref).is_absolute():
79
+ blockers.append(f"BASELINE_SPEC_INVALID:{ref}")
80
+ continue
81
+ candidate = (root / ref).resolve()
82
+ try:
83
+ candidate.relative_to(root.resolve())
84
+ except ValueError:
85
+ blockers.append(f"BASELINE_SPEC_INVALID:{ref}")
86
+ continue
87
+ if not candidate.is_file():
88
+ blockers.append(f"BASELINE_SPEC_MISSING:{ref}")
89
+ continue
90
+ digest = hashlib.sha256(candidate.read_bytes()).hexdigest()
91
+ if not expected or digest != expected:
92
+ blockers.append(f"BASELINE_SPEC_STALE:{ref}")
93
+ head = git_head(root)
94
+ revision = baseline.get("repository_revision")
95
+ if head and revision and not str(revision).startswith("workspace:") and head != revision:
96
+ blockers.append("BASELINE_HEAD_STALE")
97
+ baseline.pop("spec_refs_json", None)
98
+ return {
99
+ "status": "fail" if blockers else "pass",
100
+ "blockers": blockers,
101
+ "warnings": warnings,
102
+ "baseline": baseline,
103
+ }
104
+
105
+
106
+ def _next_action(change, task, tasks, role, readiness, stored, state_changed, blockers=None):
53
107
  if readiness != "ready":
108
+ if any(str(item).startswith("BASELINE_") for item in (blockers or [])):
109
+ return "Complete or refresh the Ultra project baseline through ultra-init."
54
110
  return "Resolve the context readiness blockers, then recompile change.context."
55
111
  if not state_changed and isinstance(stored, str) and stored.strip():
56
112
  return stored.strip()
@@ -77,7 +133,7 @@ def _next_action(change, task, tasks, role, readiness, stored, state_changed):
77
133
  return f"Create the first fresh-context tracer-bullet task for change {change['id']}."
78
134
 
79
135
 
80
- def _route(change, task, tasks, readiness):
136
+ def _route(change, task, tasks, readiness, blockers=None):
81
137
  if readiness != "ready" or change["status"] == "blocked":
82
138
  return "ultra-change"
83
139
  if change["status"] == "ready":
@@ -99,15 +155,39 @@ def read_breadcrumb(root: Path):
99
155
  row[0]
100
156
  for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
101
157
  }
102
- if not {"changes", "tasks", "context_snapshots"}.issubset(tables):
158
+ if not {"baselines", "changes", "tasks", "context_snapshots"}.issubset(tables):
103
159
  return None
160
+ baseline = baseline_health(conn, root)
104
161
  change = conn.execute(
105
162
  """SELECT id, status FROM changes
106
163
  WHERE status IN ('active', 'blocked', 'ready')
107
164
  ORDER BY updated_at DESC LIMIT 1"""
108
165
  ).fetchone()
109
166
  if change is None:
110
- return None
167
+ current = baseline["baseline"]
168
+ if baseline["status"] == "pass":
169
+ next_action = "Start daily work with ultra-change."
170
+ route = "ultra-change"
171
+ readiness = "ready"
172
+ else:
173
+ next_action = "Initialize or complete project baseline adoption through ultra-init."
174
+ route = "ultra-init"
175
+ readiness = "blocked"
176
+ return {
177
+ "change_id": None,
178
+ "task_id": None,
179
+ "role": "plan",
180
+ "gate": "alignment",
181
+ "readiness": readiness,
182
+ "blockers": baseline["blockers"],
183
+ "warnings": baseline["warnings"],
184
+ "next_action": next_action,
185
+ "recommended_workflow": route,
186
+ "context_manifest_path": None,
187
+ "context_manifest_hash": None,
188
+ "git_head": git_head(root),
189
+ "baseline": current,
190
+ }
111
191
  tasks = list(conn.execute(
112
192
  "SELECT id, status, session_id FROM tasks WHERE change_id = ? ORDER BY created_at ASC",
113
193
  (change["id"],),
@@ -145,6 +225,7 @@ def read_breadcrumb(root: Path):
145
225
  not isinstance(context.get("resume"), dict)
146
226
  or not isinstance(context.get("context"), dict)
147
227
  or not isinstance(context.get("readiness"), dict)
228
+ or "baseline" not in context
148
229
  )
149
230
  )
150
231
  stored_status = context.get("resume", {}).get("task_status")
@@ -152,6 +233,7 @@ def read_breadcrumb(root: Path):
152
233
  state_changed = stored_status is not None and stored_status != current_status
153
234
  stored_action = snapshot["next_action"] if snapshot else None
154
235
  blockers = []
236
+ warnings = list(dict.fromkeys([*baseline["blockers"], *baseline["warnings"]]))
155
237
  if snapshot_missing:
156
238
  blockers.append("CONTEXT_NOT_COMPILED")
157
239
  else:
@@ -162,8 +244,14 @@ def read_breadcrumb(root: Path):
162
244
  if state_changed:
163
245
  blockers.append("CONTEXT_TASK_STATE_STALE")
164
246
  for blocker in safe_json(snapshot["blockers_json"], []):
165
- if blocker not in blockers:
247
+ if blocker in ADVISORY_CONTEXT_CODES or str(blocker).startswith("BASELINE_"):
248
+ if blocker not in warnings:
249
+ warnings.append(blocker)
250
+ elif blocker not in blockers:
166
251
  blockers.append(blocker)
252
+ for warning in context.get("readiness", {}).get("warnings", []):
253
+ if warning not in warnings:
254
+ warnings.append(warning)
167
255
  readiness = "blocked" if blockers else snapshot["readiness"]
168
256
  if snapshot_missing:
169
257
  next_action = f"Compile change.context for change {change['id']} before continuing."
@@ -174,7 +262,9 @@ def read_breadcrumb(root: Path):
174
262
  elif state_changed:
175
263
  next_action = "Task state changed after context compilation; recompile change.context."
176
264
  else:
177
- next_action = _next_action(change, task, tasks, role, readiness, stored_action, False)
265
+ next_action = _next_action(
266
+ change, task, tasks, role, readiness, stored_action, False, blockers
267
+ )
178
268
  return {
179
269
  "change_id": change["id"],
180
270
  "change_status": change["status"],
@@ -185,28 +275,42 @@ def read_breadcrumb(root: Path):
185
275
  "gate": gate,
186
276
  "readiness": readiness,
187
277
  "blockers": blockers,
278
+ "warnings": warnings,
188
279
  "next_action": next_action,
189
- "recommended_workflow": _route(change, task, tasks, readiness),
280
+ "recommended_workflow": _route(change, task, tasks, readiness, blockers),
190
281
  "context_manifest_path": snapshot["manifest_path"] if snapshot else None,
191
282
  "context_manifest_hash": snapshot["manifest_hash"] if snapshot else None,
192
283
  "git_head": current_head,
284
+ "baseline": baseline["baseline"],
193
285
  }
194
286
 
195
287
 
196
288
  def render_breadcrumb(root: Path, breadcrumb: dict) -> str:
197
289
  task = breadcrumb.get("task_id") or "none"
198
290
  task_status = breadcrumb.get("task_status") or "none"
199
- lines = [
200
- "[Ultra context spine]",
201
- f"Project: {root}",
202
- f"Change: {breadcrumb['change_id']} ({breadcrumb.get('change_status', 'active')})",
203
- f"Task: {task} ({task_status})",
204
- f"Role: {breadcrumb.get('role', 'plan')}",
205
- f"Gate: {breadcrumb.get('gate', 'alignment')}",
206
- f"Readiness: {breadcrumb.get('readiness', 'ready')}",
207
- ]
291
+ baseline = breadcrumb.get("baseline") or {}
292
+ if breadcrumb.get("change_id"):
293
+ lines = [
294
+ "[Ultra context spine]",
295
+ f"Project: {root}",
296
+ f"Baseline: {baseline.get('id', 'unknown')} ({baseline.get('mode', 'unknown')}/{baseline.get('status', 'unknown')})",
297
+ f"Change: {breadcrumb['change_id']} ({breadcrumb.get('change_status', 'active')})",
298
+ f"Task: {task} ({task_status})",
299
+ f"Role: {breadcrumb.get('role', 'plan')}",
300
+ f"Gate: {breadcrumb.get('gate', 'alignment')}",
301
+ f"Readiness: {breadcrumb.get('readiness', 'ready')}",
302
+ ]
303
+ else:
304
+ lines = [
305
+ "[Ultra baseline]",
306
+ f"Project: {root}",
307
+ f"Baseline: {baseline.get('id', 'missing')} ({baseline.get('mode', 'unknown')}/{baseline.get('status', 'missing')})",
308
+ f"Readiness: {breadcrumb.get('readiness', 'blocked')}",
309
+ ]
208
310
  if breadcrumb.get("blockers"):
209
311
  lines.append("Blockers: " + ", ".join(breadcrumb["blockers"]))
312
+ if breadcrumb.get("warnings"):
313
+ lines.append("Warnings: " + ", ".join(breadcrumb["warnings"]))
210
314
  lines.extend([
211
315
  f"Next: {breadcrumb.get('next_action', 'Inspect Ultra status.')}",
212
316
  f"Route: {breadcrumb.get('recommended_workflow', 'ultra-change')}",