ultra-builder-pro-cli 0.12.1 → 0.13.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 (57) hide show
  1. package/.ultra-template/docs/research/README.md +21 -44
  2. package/.ultra-template/specs/discovery.md +10 -0
  3. package/CHANGELOG.md +53 -1
  4. package/README.md +25 -9
  5. package/adapters/_shared/handbook.cjs +2 -2
  6. package/adapters/tests/codex.test.cjs +8 -0
  7. package/commands/ultra-init.md +1 -1
  8. package/docs/AGENT-CONTEXT.md +4 -3
  9. package/docs/ARCHITECTURE.md +32 -16
  10. package/docs/PLAN.zh-CN.md +5 -4
  11. package/docs/ROADMAP.md +1 -1
  12. package/docs/STATE-DB-ACCESS-POLICY.md +3 -3
  13. package/docs/USER-HANDBOOK-CONTRACT.md +5 -4
  14. package/hooks/context_spine.py +37 -4
  15. package/mcp-server/lib/archive-journal.cjs +192 -0
  16. package/mcp-server/lib/archive-journal.test.cjs +35 -0
  17. package/mcp-server/lib/baseline-workflow.cjs +404 -38
  18. package/mcp-server/lib/baseline-workflow.test.cjs +252 -0
  19. package/mcp-server/lib/change-workflow.cjs +249 -75
  20. package/mcp-server/lib/change-workflow.test.cjs +235 -1
  21. package/mcp-server/lib/context-spine.test.cjs +5 -0
  22. package/mcp-server/lib/doctor.cjs +14 -1
  23. package/mcp-server/lib/doctor.test.cjs +42 -4
  24. package/mcp-server/lib/init-project.cjs +292 -9
  25. package/mcp-server/lib/spec-learning.test.cjs +1 -1
  26. package/mcp-server/lib/state-authority.cjs +9 -3
  27. package/mcp-server/lib/state-db.cjs +154 -32
  28. package/mcp-server/lib/state-db.test.cjs +136 -4
  29. package/mcp-server/lib/state-ops.cjs +68 -6
  30. package/mcp-server/lib/task-expander.cjs +7 -1
  31. package/mcp-server/lib/task-expander.test.cjs +71 -0
  32. package/mcp-server/server.cjs +14 -3
  33. package/mcp-server/tests/init-project.test.cjs +162 -1
  34. package/mcp-server/tests/migrate.test.cjs +33 -0
  35. package/mcp-server/tests/server-contract.test.cjs +384 -6
  36. package/mcp-server/tests/state-db.test.cjs +14 -2
  37. package/mcp-server/tests/state-ops.test.cjs +108 -0
  38. package/package.json +1 -1
  39. package/skills/ultra-change/SKILL.md +18 -10
  40. package/skills/ultra-deliver/SKILL.md +13 -9
  41. package/skills/ultra-dev/SKILL.md +6 -4
  42. package/skills/ultra-doctor/SKILL.md +22 -7
  43. package/skills/ultra-init/SKILL.md +104 -59
  44. package/skills/ultra-init/references/brownfield-adoption.md +65 -37
  45. package/skills/ultra-plan/SKILL.md +8 -5
  46. package/skills/ultra-research/SKILL.md +12 -5
  47. package/skills/ultra-status/SKILL.md +6 -4
  48. package/spec/cli-protocol.md +11 -1
  49. package/spec/mcp-tools.yaml +95 -9
  50. package/spec/schemas/state-db.sql +11 -0
  51. package/ultra-tools/cli.cjs +9 -5
  52. package/ultra-tools/commands/migrate.cjs +62 -36
  53. package/ultra-tools/commands/status.cjs +18 -9
  54. package/ultra-tools/commands/system.cjs +340 -6
  55. package/ultra-tools/commands/task.cjs +7 -1
  56. package/ultra-tools/status-command.test.cjs +29 -0
  57. package/ultra-tools/system-command.test.cjs +252 -1
@@ -1,53 +1,30 @@
1
- # Research Reports
1
+ # Research Evidence
2
2
 
3
- This directory contains research reports generated by `/ultra-research` step-file architecture.
3
+ Store durable research evidence here only when it is too detailed for the baseline
4
+ specification. Baseline decisions and accepted behavior remain in `.ultra/specs/`.
4
5
 
5
- ## Structure
6
+ ## When to create a report
6
7
 
7
- Each round generates a report with quality metadata:
8
+ Create a report for external facts, repository investigations, experiments, runtime
9
+ observations, or decision evidence that must remain inspectable. Use a descriptive
10
+ file name and include the observation date when freshness matters.
8
11
 
9
- | Steps | Round | Report File |
10
- |-------|-------|-------------|
11
- | 00-05 | R0: Product Discovery | `product-discovery-{date}.md` |
12
- | 10-11 | R1: User & Scenario | `user-scenario-{date}.md` |
13
- | 20-22 | R2: Feature Definition | `feature-definition-{date}.md` |
14
- | 30-32 | R3: Architecture Design | `architecture-design-{date}.md` |
15
- | 40-41 | R4: Quality & Deployment | `quality-deployment-{date}.md` |
12
+ ## Report contract
16
13
 
17
- ## Report Format
14
+ Record:
18
15
 
19
- Each report includes quality tracking in header:
16
+ - scope and the decision the evidence informs;
17
+ - observed facts with source references and dates;
18
+ - verification commands or runtime evidence;
19
+ - accepted decisions and their owner;
20
+ - unresolved unknowns and whether they block the baseline;
21
+ - links to the product or architecture sections updated from the evidence.
20
22
 
21
- ```markdown
22
- # Round {N}: {Round Name}
23
+ Keep inference distinct from observation. Link to external provider content instead of
24
+ copying memory, code-graph payloads, or large source material into Ultra.
23
25
 
24
- > **Confidence**: 92%
25
- > **Steps completed**: {list}
26
- > **Completed**: {date}
26
+ ## Completion
27
27
 
28
- ## Key Findings
29
- [3-5 bullet points]
30
-
31
- ## Decisions Made
32
- [Choices and rationale]
33
-
34
- ## Open Questions
35
- [What remains uncertain]
36
- ```
37
-
38
- ## Quality Gate
39
-
40
- - Each step uses [C] Continue user gate — user confirms before proceeding
41
- - Per-step SUCCESS METRICS and FAILURE MODES enforce output quality
42
- - Step 99 (Synthesis) validates field-level completeness of all spec files
43
-
44
- ## Research Distillate
45
-
46
- After all steps complete, `step-99-synthesis` generates:
47
- - `.ultra/specs/research-distillate.md` — Token-efficient summary (<2000 tokens) for `/ultra-plan` consumption
48
-
49
- ## Integration
50
-
51
- - Reports are referenced in `specs/` for technology decisions
52
- - Research distillate is the primary input for `/ultra-plan`
53
- - Quality summary displayed at end of `/ultra-research`
28
+ Update the affected baseline specification, include the report in `baseline.record`
29
+ evidence when material, and record unresolved work in the authoritative gap ledger.
30
+ Do not create a condensed duplicate of the baseline.
@@ -36,6 +36,16 @@ Separate blocking unknowns from questions that are outside the accepted scope.
36
36
  |---|---|---|---|
37
37
  | | | | |
38
38
 
39
+ ## Baseline Gaps
40
+
41
+ Reference the authoritative gap ids recorded in `.ultra/state.db`. Use one of
42
+ `baseline_blocker`, `documentation_drift`, `known_defect`, `technical_debt`,
43
+ `unknown`, or `future_change`.
44
+
45
+ | Gap id | Category | Status | Evidence reference | Owner |
46
+ |---|---|---|---|---|
47
+ | | | | | |
48
+
39
49
  ## Current Behavior Notes
40
50
 
41
51
  For an existing project, describe only behavior confirmed from source, tests, runtime,
package/CHANGELOG.md CHANGED
@@ -7,6 +7,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.13.0] — 2026-07-18
11
+
12
+ ### Added
13
+
14
+ - Added schema 12 repository snapshots, branch and dirty-worktree evidence,
15
+ classification metadata, and a categorized baseline gap ledger with explicit
16
+ blocker, ownership, acceptance, and resolution state.
17
+ - Added safe `task.init_project` resume semantics, bounded monorepo scope
18
+ detection, projection-only import routing, explicit migrated-baseline
19
+ replacement, and backup-first recovery for old state databases.
20
+ - Added explicit corrupt-state restore and rebaseline commands that quarantine
21
+ the original database, WAL, SHM, and task projection and restore every moved
22
+ artifact when recovery fails.
23
+ - Added approved incident break-glass records and mandatory post-incident
24
+ baseline reconciliation gaps, plus durable archive-journal crash recovery.
25
+
26
+ ### Changed
27
+
28
+ - Made `ultra-init` the single route for empty repositories, existing
29
+ codebases, healthy installations, incomplete adoptions, prior Ultra state,
30
+ and corrupt databases. Existing application and baseline files are preserved;
31
+ resume installs only missing current scaffold assets.
32
+ - New ordinary changes now require a healthy ready baseline. Already-active
33
+ work remains executable with visible drift warnings, while convergence still
34
+ requires current approved authority.
35
+ - Ready-baseline replacement now requires durable owner identity and rationale;
36
+ a bare `replace_ready` boolean is rejected and cannot erase provenance.
37
+ - Reworked baseline templates and host-neutral Skills around
38
+ `Observed`/`Verified`/`Decided`/`Unknown` evidence, characterization results,
39
+ owner approval, and one deterministic next action.
40
+
41
+ ### Fixed
42
+
43
+ - Prevented prior-version projects from being treated as approved after a
44
+ schema upgrade; compatibility baselines remain `migrated/adopting` until an
45
+ evidence-backed brownfield replacement is approved.
46
+ - Made status and doctor report old or corrupt state as structured recovery
47
+ guidance, retain pre-migration backup paths on failure, and close failed
48
+ database handles safely.
49
+ - Prevented maintenance CLI telemetry from opening corrupt authority before
50
+ evidence-preserving recovery checks, and made task creation enforce the same
51
+ baseline boundary as change creation.
52
+ - Closed bulk-parse and task-expansion task-creation bypasses; persisted PRD
53
+ tasks now carry their active change id, and expanded children inherit the
54
+ parent task's authorized change ownership.
55
+ - Rejected task writes against missing or terminal changes even when the
56
+ baseline is healthy, and enforced parent-child change ownership for generic
57
+ task creation and reassignment paths.
58
+ - Fixed installed npm tarballs so direct `ultra-tools task init-project` calls
59
+ can locate the packaged scaffold outside a source checkout.
60
+
10
61
  ## [0.12.1] — 2026-07-18
11
62
 
12
63
  ### Fixed
@@ -490,7 +541,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
490
541
  skill manifest, CLI protocol + mapping table; 5 spec validators.
491
542
  - **Phase 0 — skeleton**: multi-runtime installer scaffolding.
492
543
 
493
- [Unreleased]: https://github.com/rocky2431/ultra-builder-pro-cli/compare/v0.12.1...HEAD
544
+ [Unreleased]: https://github.com/rocky2431/ultra-builder-pro-cli/compare/v0.13.0...HEAD
545
+ [0.13.0]: https://github.com/rocky2431/ultra-builder-pro-cli/compare/v0.12.1...v0.13.0
494
546
  [0.12.1]: https://github.com/rocky2431/ultra-builder-pro-cli/compare/v0.12.0...v0.12.1
495
547
  [0.12.0]: https://github.com/rocky2431/ultra-builder-pro-cli/compare/v0.11.0...v0.12.0
496
548
  [0.11.0]: https://github.com/rocky2431/ultra-builder-pro-cli/compare/v0.10.0...v0.11.0
package/README.md CHANGED
@@ -8,7 +8,7 @@ authoritative `.ultra/state.db`.
8
8
 
9
9
  <div align="center">
10
10
 
11
- [![Version](https://img.shields.io/badge/version-0.12.1-blue)](./CHANGELOG.md)
11
+ [![Version](https://img.shields.io/badge/version-0.13.0-blue)](./CHANGELOG.md)
12
12
  [![Tests](https://img.shields.io/badge/tests-passing-brightgreen)](#verification)
13
13
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
14
14
  [![Node](https://img.shields.io/badge/node-%E2%89%A522-informational)](./package.json)
@@ -44,9 +44,10 @@ authoritative `.ultra/state.db`.
44
44
  Incident changes additionally require a five-section `diagnosis.md` covering
45
45
  reproduction, hypotheses, root cause, regression test, and recovery.
46
46
  - **Adopts existing repositories without pretending they are new.** `ultra-init`
47
- auto-detects greenfield versus brownfield work. Brownfield adoption records
48
- current specifications, repository/runtime evidence, known-red verification,
49
- unknowns, and explicit approval without rewriting application code.
47
+ classifies greenfield, brownfield, and monorepo scope. Brownfield adoption records
48
+ current specifications, repository/runtime evidence, worktree snapshot, known-red
49
+ verification, categorized gaps, unknowns, and explicit approval without rewriting
50
+ application code. v4.4 and v4.5 projection-only projects have backup-first imports.
50
51
  - **Keeps external context external.** Memory and code-graph providers retain
51
52
  their own content; Ultra stores only provider/project/revision/status metadata
52
53
  references in a compiled change context.
@@ -89,10 +90,10 @@ for per-runtime capabilities.
89
90
  Start with `ultra-init` in both new and existing projects. An empty project opens
90
91
  a `draft` greenfield baseline. An existing codebase opens an `adopting`
91
92
  brownfield baseline; inspect current behavior, call `baseline.record`, then
92
- approve it through `baseline.converge` before normal planning or delivery. An
93
- urgent active fix may continue while adoption or context-size warnings are
94
- visible. `change.converge` requires approved adoption, while normal HEAD/spec drift
95
- from that change is declared and health-checked atomically by `change.archive`.
93
+ approve it through `baseline.converge` before normal planning or delivery. Existing
94
+ active work may continue while adoption drift is visible. A new incident requires an
95
+ explicit break-glass approver and leaves a blocking reconciliation gap at archive;
96
+ new ordinary work always requires a healthy ready baseline.
96
97
 
97
98
  ## Three-layer architecture
98
99
 
@@ -133,9 +134,13 @@ Full details in [`docs/RUNTIME-COMPAT-MATRIX.md`](./docs/RUNTIME-COMPAT-MATRIX.m
133
134
  ## Typical workflow
134
135
 
135
136
  ```bash
136
- # 1. Initialize a new project or adopt an existing repository automatically
137
+ # 1. Bootstrap project state (the ultra-init skill completes adoption and approval)
137
138
  ultra-tools task init-project --project-name myapp --mode auto
138
139
 
140
+ # Projection-only projects from prior releases use one backup-first import:
141
+ ultra-tools migrate --from=4.4 --to=4.5 --source-dir .
142
+ ultra-tools migrate --from=4.5 --to=12.0 --source-dir .
143
+
139
144
  # 2. Record and converge the greenfield/brownfield baseline, then turn accepted
140
145
  # behavior into a task graph (normally driven by ultra-init/research/plan)
141
146
 
@@ -208,6 +213,17 @@ Individual suites: `test:state`, `test:orch`, `test:spec`, `test:rest`.
208
213
  the recorded install provenance with current asset hashes and validates the
209
214
  host-specific hook, MCP, plugin, and runtime-manifest entry points. Reinstall
210
215
  only after preserving the degraded report as evidence.
216
+ - **Projection tasks exist but state.db has no tasks**: run the exact v4.4 or v4.5
217
+ `ultra-tools migrate` command returned by MCP, verify the backup and imported counts,
218
+ then run `ultra-init` to replace the compatibility row with a reviewed brownfield
219
+ baseline.
220
+ - **Old or corrupt state.db**: `ultra-tools system doctor` is read-only;
221
+ `ultra-tools system doctor --repair` upgrades supported schemas with two backup
222
+ checkpoints. A corrupt database is never overwritten automatically. After explicit
223
+ owner approval, restore a verified managed copy with
224
+ `ultra-tools system restore --backup <path> --confirm REPLACE_CORRUPT_ULTRA_STATE`,
225
+ or preserve the corrupt DB and legacy projection before rebuilding authority with
226
+ `ultra-tools system rebaseline --project-name <name> --confirm REBASELINE_CORRUPT_ULTRA_STATE`.
211
227
  - **Legacy Ultra memory data remains on disk**: inspect first with
212
228
  `ultra-tools legacy-memory inspect`, archive with
213
229
  `ultra-tools legacy-memory archive`, then prune only with the explicit
@@ -60,12 +60,12 @@ function renderHandbook(runtime) {
60
60
  `- Collaboration boundary: ${value.collaboration}. The current host remains primary and owns final verification.`,
61
61
  `- Coordination boundary: ${value.coordination}.`,
62
62
  '- Authority: `.ultra/state.db` is the only durable Ultra authority for baselines, changes, tasks, sessions, events, incidents, projection state, telemetry, and review evidence. Generated JSON and Markdown are projections or workflow artifacts.',
63
- '- Baseline boundary: `task.init_project` detects greenfield or brownfield work; `baseline.start`, `baseline.record`, and `baseline.converge` adopt the project without rewriting application code. An incomplete baseline is advisory during active work but blocks change convergence; normal HEAD or tracked-spec drift from that change is reconciled and health-checked atomically at archive.',
63
+ '- Baseline boundary: `task.init_project` classifies greenfield or brownfield work and records repository scope. Projection-only prior state uses the exact supported backup-first import returned by the authority check; migrated compatibility rows require explicit brownfield re-adoption. `baseline.record` owns evidence, verification, repository snapshot, and the gap ledger; `baseline.converge` requires explicit owner approval. New ordinary changes require a healthy ready baseline. Existing active work may continue with warnings, but baseline readiness blocks change convergence; normal drift reconciliation is health-checked atomically at archive. Only an explicitly approved incident break-glass may start without baseline readiness, and its archive creates a blocking reconciliation gap.',
64
64
  '- Context Spine boundary: `change.context` compiles role/gate readiness, required references, a fresh-context budget, public seam, verification command, and one next action. File, token, and context-share budgets are advisory attention signals, not refusal gates. Hooks inject only the DB-derived `change.breadcrumb`; missing required evidence or stale execution context must be recompiled.',
65
65
  '- Specification learning boundary: stable implementation discoveries use approval-gated propose/approve-or-reject/apply transitions. Unresolved learning blocks convergence; review requires independent specification-fidelity and engineering-standards evidence.',
66
66
  '- Memory and graph boundary: Ultra Builder Pro does not capture prompts, transcripts, observations, summaries, cross-session memory, or code-graph content. Separately installed providers own that data; Ultra may store only their metadata references in a change context manifest.',
67
67
  '- Hook boundary: Ultra hooks observe workflow/change lifecycle only. Health/context may run when `.ultra/state.db` exists; advisory warnings never reject work, and an incomplete workflow never traps session stop. Direct projection protection remains authoritative; compact and subagent recovery stays active-workflow scoped. Generic command blocking and post-edit policy stay in user or repository governance.',
68
- '- Installation boundary: `ubp --doctor` is the read-only authority for installed asset provenance, content hashes, and host entry-point wiring; `system.doctor` remains scoped to project state and workflow recovery.',
68
+ '- Installation boundary: `ubp --doctor` is the read-only authority for installed asset provenance, content hashes, and host entry-point wiring. Project `system.doctor` diagnoses state and performs only authorized backup-first schema, projection, session, and archive-journal recovery; it never approves a baseline.',
69
69
  '- Agent boundary: the bundled review and debugging agents are bounded workers. They use the current checkout and parent-supplied context, do not own private persistent state, and never replace the primary agent.',
70
70
  '- Package boundary: only the twelve Ultra workflows, four internal review-rule skills, host-specific collaboration companions, and the minimal host bootstrap belong to this plugin. General browser, deployment, discovery, and framework skills must be installed from their owners.',
71
71
  END_MARKER,
@@ -9,6 +9,7 @@ const { spawnSync } = require('node:child_process');
9
9
  const yaml = require('js-yaml');
10
10
  const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
11
11
  const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
12
+ const { initStateDb, closeStateDb } = require('../../mcp-server/lib/state-db.cjs');
12
13
 
13
14
  const codex = require('../codex.js');
14
15
  const { parse: parseFrontmatter } = require('../_shared/frontmatter.cjs');
@@ -263,6 +264,13 @@ test('bundled plugin MCP runs outside the source checkout and keeps state in the
263
264
  let client;
264
265
  try {
265
266
  install(layout);
267
+ const seededState = initStateDb(path.join(projectDir, '.ultra', 'state.db'));
268
+ seededState.db.prepare(
269
+ `INSERT INTO baselines
270
+ (id, project_name, mode, status, approved_by, approval_note, converged_at)
271
+ VALUES ('test-baseline', 'codex-bundle', 'greenfield', 'ready', 'test', 'smoke fixture', ?)`,
272
+ ).run(new Date().toISOString());
273
+ closeStateDb(seededState.db);
266
274
  const mcp = JSON.parse(fs.readFileSync(path.join(layout.pluginRoot, '.mcp.json'), 'utf8'));
267
275
  const server = mcp.mcpServers['ultra-builder-pro'];
268
276
  const env = { ...process.env };
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  description: Initialize a new project or adopt an existing repository into authoritative Ultra baseline state
3
- argument-hint: "[name] [type] [stack] [auto|greenfield|brownfield]"
3
+ argument-hint: "[name] [type] [stack] [auto|greenfield|brownfield] [--scope <path>]"
4
4
  workflow-ref: "@skills/ultra-init/SKILL.md"
5
5
  ---
6
6
 
@@ -78,9 +78,10 @@ necessary context when they do not.
78
78
  role, gate, readiness, blockers, and one next action. They must not inject intent
79
79
  bodies, transcripts, external memory, or graph payloads. Missing references,
80
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.
81
+ size and baseline drift are advisory for a change that is already active. New ordinary
82
+ work requires a healthy baseline. Only an explicitly approved incident break-glass may
83
+ start without it; incident archive records a blocking reconciliation gap. Revision and
84
+ tracked-spec integrity are reconciled and rechecked atomically for ordinary archive.
84
85
 
85
86
  Stable discoveries use `change.learning_propose`; they reach the baseline only
86
87
  through approve/reject/apply transitions in `change.learning_resolve`. Unresolved
@@ -74,7 +74,7 @@ covers seventeen tables:
74
74
 
75
75
  | Table | Holds | Phase |
76
76
  |--------------------|---------------------------------------------------|-------|
77
- | `baselines` | greenfield/brownfield adoption, specs, verification, unknowns, and approval | 11 |
77
+ | `baselines` | repository classification, greenfield/brownfield adoption, worktree snapshot, specs, evidence, verification, gap ledger, and approval | 12 |
78
78
  | `tasks` | task rows — id, status, deps, files_modified, … | 2 |
79
79
  | `events` | append-only event stream; `id` is subscription cursor (D31) | 2 |
80
80
  | `sessions` | execution sessions, **including lease + heartbeat fields** (D32) | 4.5 |
@@ -83,7 +83,7 @@ covers seventeen tables:
83
83
  | `telemetry` | per-session token / cost / tool-call counters | 6 |
84
84
  | `specs_refs` | spec change tracking → staleness propagation | 5 |
85
85
  | `circuit_breaker` | bounded retry and halt state for failed tasks | 5 |
86
- | `changes` | continuous feature/fix/incident lifecycle | 8C |
86
+ | `changes` | continuous feature/fix/incident lifecycle and incident baseline bypass | 12 |
87
87
  | `artifacts` | intent/context/verification artifact registry | 8C |
88
88
  | `context_snapshots`| role/gate context, readiness, budget, execution seam, hashes, git head, provider refs | 10 |
89
89
  | `spec_learning_candidates` | approval-gated implementation discoveries for baseline convergence | 10 |
@@ -128,23 +128,34 @@ archive/prune command for data created by older releases.
128
128
 
129
129
  ### Project baseline adoption
130
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.
131
+ `task.init_project` classifies source, tests, deployment, persistence, package
132
+ scripts, and monorepo markers. It detects `greenfield` or `brownfield`, records
133
+ bounded classification evidence and selected repository scope, and creates the
134
+ same authoritative state shape without rewriting application code.
135
+
136
+ Projection-only v4.4 and v4.5 projects use `ultra-tools migrate` to preserve the
137
+ entire `.ultra` tree, import tasks and events, and create a `migrated/adopting`
138
+ compatibility row. Schema upgrades use `ultra-tools system doctor --repair` and
139
+ produce a pre-migration backup. Compatibility state never grants baseline approval;
140
+ `baseline.start` with `replace_migrated: true` opens the actual brownfield adoption.
134
141
 
135
142
  `baseline.start` opens adoption, `baseline.record` captures server-hashed spec
136
143
  references, bounded repository/runtime evidence, actual verification results,
137
- known unknowns, and metadata-only external provider references, and
144
+ known unknowns, repository branch and worktree snapshot, the categorized gap ledger,
145
+ and metadata-only external provider references, and
138
146
  `baseline.converge` records explicit owner approval. A ready baseline is replaced
139
147
  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
+ For a selected monorepo scope, the worktree digest and dirty-file list include only
149
+ that scope; out-of-scope changes remain visible repository context but cannot be
150
+ accepted implicitly by `accept_dirty_worktree`.
151
+
152
+ New ordinary changes require a healthy `ready` baseline. A change that was already
153
+ active may continue with baseline drift surfaced as a warning. A new incident can
154
+ start on an unhealthy baseline only with an explicit reason and approver stored in
155
+ `baseline_bypass_json`. Ordinary convergence and archive reconcile HEAD, worktree,
156
+ and tracked-spec drift atomically. Break-glass incident archive creates an open
157
+ blocking reconciliation gap, so incident recovery can finish without falsely marking
158
+ the project baseline healthy.
148
159
 
149
160
  ## 4. Continuous changes — the daily unit of convergence
150
161
 
@@ -204,8 +215,13 @@ evidence, and final convergence decision.
204
215
 
205
216
  Mutating MCP calls enqueue durable `projection_jobs`. Success is exposed in MCP
206
217
  response metadata; failure becomes a retryable structured incident instead of a
207
- swallowed warning. `system.doctor` is read-only by default and performs only
208
- backup-first mechanical recovery when explicitly requested.
218
+ swallowed warning. `system.doctor` is read-only by default. Explicit repair performs
219
+ backup-first schema upgrade, archive-journal recovery, session and projection
220
+ recovery, and regenerated projections. It cannot approve a baseline or replace a
221
+ corrupt SQLite file silently. `system restore` accepts only a verified SQLite backup
222
+ inside `.ultra/backups`, quarantines the corrupt authority, and rolls back on failure.
223
+ When no valid backup exists, confirmed `system rebaseline` preserves both corrupt
224
+ authority and the legacy task projection before creating a new brownfield adoption.
209
225
 
210
226
  ## 5. Sessions — the execution unit
211
227
 
@@ -1,6 +1,6 @@
1
1
  # ultra-builder-pro-cli — 历史执行计划与决策日志
2
2
 
3
- > **2026-07-18 当前生效边界(D50-D54,覆盖下文旧 Phase 6/7 的内置图谱、memory 与 runtime 设计)**:
3
+ > **2026-07-18 当前生效边界(D50-D55,覆盖下文旧 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.12.1;四宿主 native plugin、36 个 live MCP tool、
14
- schema 11.0(17 表)、portable Skill authoring contract、双轴 review、
13
+ **当前状态**:v0.13.0;四宿主 native plugin、36 个 live MCP tool、
14
+ schema 12.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 的实施历史,不再作为
@@ -29,7 +29,7 @@ checkpoint 恢复消费与跨宿主安装 provenance/doctor 已落地;npm 发
29
29
  - **Phase 4.6 拆 a/b**(R6 + D35):v0.1 只跑 smoke flow,full conformance 推 v0.2
30
30
  - **Codex 第二轮结论**:"小改后开工"(tl;dr);本版已完成小改
31
31
 
32
- **总决策数**:D1-D53(当前边界以 D50-D53 为准)
32
+ **总决策数**:D1-D55(当前边界以 D50-D55 为准)
33
33
  **总风险数**:R1-R32(v0.3.1 新增 R25-R32 共 8 条)
34
34
 
35
35
  ---
@@ -1643,6 +1643,7 @@ Week 18 buffer(ship 中任何 Phase 的 25% 滑动吃掉)
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
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 因四个大文件超预算而无法施工;限制只在损坏权威、缺少执行契约、证据陈旧和最终收敛边界阻断 |
1646
+ | **D55** | **2026-07-18** | **新项目、老项目与旧版 Ultra 接入完成统一闭环**:schema 12.0 增加 repository branch/worktree digest、classification、gap ledger 与 incident bypass authority;`ultra-init` 自动分类、resume 只补缺失 scaffold、projection-only state 走支持的备份式 import、旧 DB 备份后升级、migrated baseline 必须显式 brownfield replacement;普通新 change 要求 ready baseline,已开工 change 保持可执行,紧急 incident 只允许有审批记录的 break-glass 并在 archive 写阻断 reconciliation gap | 老项目不再被重置或伪装成 greenfield/ready;历史任务、事件与文档可恢复迁移;健康项目可直接进入日常 change,损坏权威停在明确的 restore-or-rebaseline 决策边界 |
1646
1647
 
1647
1648
  ---
1648
1649
 
package/docs/ROADMAP.md CHANGED
@@ -70,7 +70,7 @@ ultra-tools/ ← CLI fallback, migration, and diagnostics
70
70
  ├── cli.cjs
71
71
  └── commands/
72
72
  ├── db.cjs (init/checkpoint/vacuum/integrity/backup)
73
- ├── migrate.cjs (v4.4 → v4.5 + dry/rollback)
73
+ ├── migrate.cjs (v4.4 projection → v4.5 authority; v4.5 projection → schema 12; dry/rollback)
74
74
  └── legacy-memory.cjs (explicit inspect/archive/confirmed prune)
75
75
 
76
76
  bin/install.js ← multi-runtime installer
@@ -70,7 +70,7 @@ Detection happens at boot: `statvfs` of `.ultra/state.db`'s mount;
70
70
 
71
71
  | Table | Writer of record |
72
72
  |--------------------|--------------------------------------------------------|
73
- | `baselines` | MCP server (`baseline.start` / `baseline.record` / `baseline.converge`); initialization CLI may create the first row |
73
+ | `baselines` | MCP server (`baseline.start` / `baseline.record` / `baseline.converge`); initialization and legacy-projection migration may create only the first draft or compatibility row |
74
74
  | `tasks` | MCP server (`task.create` / `task.update` / `task.delete`) |
75
75
  | `changes` | MCP server (`change.create` / `change.update` / `change.converge` / `change.archive`) |
76
76
  | `artifacts`, `context_snapshots`, `spec_learning_candidates`, `trace_links` | MCP server through change lifecycle tools |
@@ -79,8 +79,8 @@ Detection happens at boot: `statvfs` of `.ultra/state.db`'s mount;
79
79
  | `sessions` | MCP server (`session.spawn` / `session.close` / `session.heartbeat`); orchestrator may write status transitions |
80
80
  | `telemetry` | MCP server (collected from tool-call wrappers); orchestrator may dump bulk samples |
81
81
  | `specs_refs` | MCP server (rebuilt on `spec_changed` event); orchestrator may rebuild |
82
- | `migration_history`| `ultra-tools migrate` CLI only |
83
- | `schema_version` | `ultra-tools db init` and `ultra-tools migrate` only |
82
+ | `migration_history`| schema initializer and `ultra-tools migrate` or doctor repair |
83
+ | `schema_version` | schema initializer, `ultra-tools db init`, migration, and doctor repair |
84
84
 
85
85
  ## 5. Forbidden patterns
86
86
 
@@ -22,10 +22,11 @@ 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; 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
25
+ fresh-context budget, public seam, and exact verification; size budgets are advisory,
26
+ new ordinary work requires a healthy baseline, existing active work may continue with
27
+ warnings, and only an approved incident break-glass may start without baseline
28
+ readiness; ordinary archive restores baseline health while break-glass archive records
29
+ a blocking reconciliation gap; hooks inject only the DB-derived
29
30
  `change.breadcrumb`; and unresolved specification learning or either failed review
30
31
  axis blocks convergence. Detailed procedures remain in the plugin skills so user
31
32
  handbooks do not accumulate duplicated prompt sediment.
@@ -56,11 +56,29 @@ def git_head(root: Path):
56
56
  return result.stdout.strip() if result.returncode == 0 else None
57
57
 
58
58
 
59
+ def git_branch(root: Path):
60
+ result = subprocess.run(
61
+ ["git", "branch", "--show-current"],
62
+ cwd=root,
63
+ text=True,
64
+ capture_output=True,
65
+ check=False,
66
+ timeout=2,
67
+ )
68
+ return (result.stdout.strip() or None) if result.returncode == 0 else None
69
+
70
+
59
71
  def baseline_health(conn, root: Path):
72
+ columns = {row[1] for row in conn.execute("PRAGMA table_info(baselines)")}
73
+ optional = [
74
+ name for name in (
75
+ "repository_branch", "worktree_state", "worktree_accepted", "gaps_json"
76
+ ) if name in columns
77
+ ]
60
78
  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"""
79
+ f"""SELECT id, mode, status, repository_revision, spec_refs_json{''.join(f', {name}' for name in optional)}
80
+ FROM baselines WHERE status != 'superseded'
81
+ ORDER BY updated_at DESC, rowid DESC LIMIT 1"""
64
82
  ).fetchone()
65
83
  if row is None:
66
84
  return {"status": "fail", "blockers": ["BASELINE_MISSING"], "warnings": [], "baseline": None}
@@ -70,8 +88,22 @@ def baseline_health(conn, root: Path):
70
88
  if baseline["status"] != "ready":
71
89
  blockers.append(f"BASELINE_NOT_READY:{baseline['status']}")
72
90
  elif baseline["mode"] == "migrated":
73
- warnings.append("BASELINE_MIGRATION_REVIEW_RECOMMENDED")
91
+ blockers.append("BASELINE_MIGRATION_REVIEW_REQUIRED")
74
92
  else:
93
+ if "gaps_json" not in columns:
94
+ blockers.append("BASELINE_SCHEMA_MIGRATION_REQUIRED")
95
+ for gap in safe_json(baseline.get("gaps_json"), []):
96
+ if (
97
+ isinstance(gap, dict)
98
+ and gap.get("status") == "open"
99
+ and gap.get("blocking") is True
100
+ ):
101
+ blockers.append(f"BASELINE_GAP_BLOCKING:{gap.get('id', 'unknown')}")
102
+ if baseline.get("worktree_state") == "dirty" and not baseline.get("worktree_accepted"):
103
+ blockers.append("BASELINE_DIRTY_WORKTREE_NOT_ACCEPTED")
104
+ branch = git_branch(root)
105
+ if baseline.get("repository_branch") and branch and baseline["repository_branch"] != branch:
106
+ blockers.append("BASELINE_BRANCH_STALE")
75
107
  for spec in safe_json(baseline.get("spec_refs_json"), []):
76
108
  ref = spec.get("path") if isinstance(spec, dict) else None
77
109
  expected = spec.get("digest") if isinstance(spec, dict) else None
@@ -95,6 +127,7 @@ def baseline_health(conn, root: Path):
95
127
  if head and revision and not str(revision).startswith("workspace:") and head != revision:
96
128
  blockers.append("BASELINE_HEAD_STALE")
97
129
  baseline.pop("spec_refs_json", None)
130
+ baseline.pop("gaps_json", None)
98
131
  return {
99
132
  "status": "fail" if blockers else "pass",
100
133
  "blockers": blockers,