ultra-builder-pro-cli 0.15.0 → 0.17.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 (71) hide show
  1. package/.ultra-template/specs/research-distillate.md +4 -3
  2. package/CHANGELOG.md +120 -1
  3. package/README.md +67 -30
  4. package/adapters/_shared/codex-assets.cjs +10 -5
  5. package/adapters/_shared/handbook.cjs +3 -2
  6. package/adapters/_shared/interaction-contract.cjs +61 -0
  7. package/adapters/claude.js +1 -1
  8. package/adapters/opencode.js +1 -1
  9. package/bin/orchestrator.js +175 -19
  10. package/commands/ultra-change.md +1 -1
  11. package/commands/ultra-deliver.md +3 -3
  12. package/commands/ultra-init.md +1 -1
  13. package/commands/ultra-plan.md +1 -1
  14. package/commands/ultra-research.md +2 -2
  15. package/commands/ultra-review.md +10 -0
  16. package/commands/ultra-status.md +1 -1
  17. package/commands/ultra-test.md +1 -1
  18. package/commands/ultra-think.md +2 -2
  19. package/docs/AGENT-CONTEXT.md +38 -18
  20. package/docs/ARCHITECTURE.md +91 -13
  21. package/docs/LEGACY-CLI-CROSSWALK.md +163 -0
  22. package/docs/PLAN.zh-CN.md +19 -12
  23. package/docs/ROADMAP.md +5 -3
  24. package/docs/RUNTIME-COMPAT-MATRIX.md +4 -4
  25. package/docs/STATE-DB-ACCESS-POLICY.md +8 -6
  26. package/docs/USER-HANDBOOK-CONTRACT.md +8 -2
  27. package/docs/WORKFLOW-LIFECYCLE.md +179 -39
  28. package/hooks/pre_stop_check.py +3 -2
  29. package/mcp-server/lib/baseline-workflow.cjs +84 -16
  30. package/mcp-server/lib/change-workflow.cjs +107 -39
  31. package/mcp-server/lib/context-spine.cjs +215 -87
  32. package/mcp-server/lib/decision-dialogue.cjs +713 -0
  33. package/mcp-server/lib/doctor.cjs +9 -0
  34. package/mcp-server/lib/git-bootstrap.cjs +240 -0
  35. package/mcp-server/lib/init-project.cjs +178 -41
  36. package/mcp-server/lib/project-breadcrumb.cjs +23 -14
  37. package/mcp-server/lib/state-db.cjs +279 -9
  38. package/mcp-server/lib/state-ops.cjs +64 -1
  39. package/mcp-server/lib/workflow-state.cjs +313 -205
  40. package/mcp-server/server.cjs +112 -34
  41. package/orchestrator/auto-merge.cjs +19 -0
  42. package/orchestrator/daemon.cjs +104 -0
  43. package/orchestrator/parallel-orchestrator.cjs +371 -49
  44. package/orchestrator/session-runner.cjs +354 -25
  45. package/package.json +2 -1
  46. package/skills/ultra-change/SKILL.md +69 -65
  47. package/skills/ultra-deliver/SKILL.md +37 -58
  48. package/skills/ultra-dev/SKILL.md +55 -49
  49. package/skills/ultra-doctor/SKILL.md +44 -49
  50. package/skills/ultra-init/SKILL.md +78 -100
  51. package/skills/ultra-plan/SKILL.md +78 -79
  52. package/skills/ultra-research/SKILL.md +99 -98
  53. package/skills/ultra-review/SKILL.md +38 -47
  54. package/skills/ultra-review/references/review-modes.md +5 -3
  55. package/skills/ultra-review/references/unified-schema.md +26 -6
  56. package/skills/ultra-review/scripts/review_wait.py +12 -0
  57. package/skills/ultra-status/SKILL.md +34 -40
  58. package/skills/ultra-test/SKILL.md +61 -48
  59. package/skills/ultra-think/SKILL.md +47 -47
  60. package/skills/ultra-think/references/decision-dialogue.md +106 -0
  61. package/spec/cli-protocol.md +46 -2
  62. package/spec/mcp-tools.yaml +444 -29
  63. package/spec/schemas/delivery-report.v1.schema.json +1 -46
  64. package/spec/schemas/mcp-tools.schema.json +1 -1
  65. package/spec/schemas/state-db.sql +66 -2
  66. package/spec/schemas/test-report.v1.schema.json +45 -14
  67. package/ultra-tools/cli.cjs +1 -1
  68. package/ultra-tools/commands/session.cjs +10 -3
  69. package/ultra-tools/commands/status.cjs +34 -14
  70. package/ultra-tools/commands/system.cjs +2 -2
  71. package/ultra-tools/commands/task.cjs +3 -0
@@ -1,77 +1,56 @@
1
1
  ---
2
2
  name: ultra-deliver
3
- description: Converge one verified Ultra change, reconcile specification learning and baseline authority, archive recoverably, and optionally release when explicitly authorized. Use when current test and independent review evidence are ready for delivery.
3
+ description: Converge a verified Ultra change, reconcile baseline specifications, and archive it with recoverable local evidence. Use when implementation, testing, and review are current.
4
4
  ---
5
5
 
6
- # Converge and deliver one change
6
+ # Converge and archive local authority
7
7
 
8
- Use host judgment for release scope and authorization. Use Ultra MCP for evidence
9
- binding, workflow state, convergence, baseline reconciliation, archive recovery, and
10
- output digests.
8
+ Delivery closes Ultra's local change authority. It does not grant or perform commit,
9
+ push, tag, registry publication, deployment, or another external effect.
11
10
 
12
11
  ## Bind current evidence
13
12
 
14
- 1. Read `system.doctor`, `baseline.get`, `change.get`, `change.breadcrumb`, linked
15
- tasks, and current test/review workflows and artifacts.
16
- 2. Resume or start a `deliver` workflow linked to the change and baseline.
17
- 3. Require completed tasks, current context, a passing test report at full HEAD with a
18
- verified public seam, and current independent `spec_fidelity` and
19
- `engineering_standards` verdicts. Record `bind-evidence`.
13
+ 1. Read doctor, baseline, change, breadcrumb, decisions, tasks, test, review, learning,
14
+ and current checkout.
15
+ 2. Resume or start a deliver workflow bound to the change and baseline.
16
+ 3. Require complete task evidence, a current test report, both review axes, current
17
+ context, and resolved material decisions. Record `bind-evidence`.
20
18
 
21
- Evidence from another revision, task set, change, or stale output is invalid. An
22
- approved break-glass incident follows only its recorded recovery contract.
19
+ Evidence from another revision, task set, or change is invalid.
23
20
 
24
- ## Reconcile and verify
21
+ ## Reconcile specifications
25
22
 
26
- Resolve every specification-learning proposal. Apply an approved item to its declared
27
- target and verify it before marking it applied; preserve rejection reasons. Reconcile
28
- accepted delta and documentation impact into baseline documents, or record an exact
29
- no-change reason. Record `reconcile-specifications`.
23
+ Resolve every specification-learning candidate. Apply approved learning to its target
24
+ with before/after digests and verification; preserve rejection reasons.
30
25
 
31
- Read `references/baseline-reconciliation.md` and write the bound reconciliation
32
- manifest inside the active change directory. It must record every baseline update as a
33
- semantic add or update with a real source anchor, before/after digests, verification,
34
- resolved gap ids, and resolved unknowns. A no-update delivery records one evidenced
35
- semantic no-change reason.
26
+ Read `references/baseline-reconciliation.md` and write the reconciliation manifest
27
+ inside the active change directory. Record semantic additions or updates, resolved
28
+ gaps and unknowns, and verification. If baseline semantics did not change, record an
29
+ evidenced no-change reason. Record `reconcile-specifications`.
36
30
 
37
- Verify the release candidate with repository-native focused/regression checks,
38
- type/lint/build where applicable, install/doctor smoke for distributed packages,
39
- public seams, and rollback or recovery sanity. Compile final convergence context and
40
- record its immutable manifest as the `verify-candidate` output. Any edit invalidates
41
- affected evidence.
31
+ Compile final convergence context and run the risk-selected candidate checks, install
32
+ or doctor smoke when this change modifies distributed assets, public-seam verification,
33
+ and recovery sanity. Record the immutable context under `verify-candidate`.
42
34
 
43
- Call `change.converge` with only the change id. Do not submit verdicts or evidence
44
- summaries: MCP derives development, test report, public seam, specification,
45
- documentation, both review axes, and incident diagnosis evidence from DB-backed
46
- workflows and current artifacts. Resolve named blockers and rerun invalidated gates. Record
47
- `converge-authority` only when the change is ready.
35
+ Call `change.converge`; MCP derives readiness from durable dev, test, review,
36
+ specification, docs, diagnosis, and current checkout evidence. Record
37
+ `converge-authority` only when ready.
48
38
 
49
- Call `change.archive` with the summary, `reconciliation_path`, and baseline updates or
50
- exact no-change reason.
51
- Ordinary archive refreshes baseline revision and digests atomically and rolls back on
52
- incomplete reconciliation. Record `archive-change`. For break-glass delivery, verify
53
- the returned bypass and blocking reconciliation gap.
39
+ Call `change.archive` with the reconciliation manifest and summary. Verify the refreshed
40
+ baseline and archived packet, then record `archive-change`.
54
41
 
55
- ## Release only with authority
42
+ Write `.ultra/reports/delivery/<workflow-id>.json` with
43
+ `ultra-delivery-report-v1`: archived change, baseline, HEAD, worktree and context
44
+ digests, local checks, rollback notes, and timestamp. The report must not contain a
45
+ release decision. Record it under `verify-delivery` and complete the workflow.
56
46
 
57
- The `release-if-authorized` step is not permission. When publication is outside the
58
- user's request, complete it with exactly one `release_authorization` decision containing
59
- `authorized: false` and the reason. When explicitly authorized, record
60
- `authorized: true`, `approved_by`, the exact release `scope`, and the reason; then
61
- determine compatibility impact, update version and
62
- changelog, rerun invalidated checks, create a non-force commit/tag, push, publish, and
63
- verify remote commit, tag, release, and registry version independently.
47
+ ## External effects
64
48
 
65
- Write `.ultra/reports/delivery/<workflow-id>.json` atomically using
66
- `ultra-delivery-report-v1`, with change/archive state, baseline id/status, full HEAD,
67
- worktree digest, convergence-context digest, exact passing
68
- checks, the explicit release authorization/performed decision, release identifiers
69
- when applicable, structured evidence for every performed commit/push/tag/registry/
70
- deployment action, rollback notes, and timestamp. The report authorization must match
71
- the DB-recorded decision. Record `verify-delivery` with that
72
- output and call `workflow.complete` only after the change is archived and local and
73
- remote evidence agree for every authorized action. MCP derives the delivery summary
74
- from this report rather than a Prompt claim.
49
+ If the user separately requests commit, push, tag, publish, or deploy, handle that as a
50
+ host-owned effect after Ultra delivery. Confirm only missing material authority, run
51
+ the repository's release checks, and report remote evidence separately. Never infer an
52
+ external effect from `ultra-deliver`, and never encode it as completed Ultra delivery
53
+ state.
75
54
 
76
- Return workflow id, archive and baseline state, evidence digests, commit/release facts,
77
- recovery notes, residual risks, and one next route.
55
+ Return archive and baseline state, evidence digests, recovery notes, residual risks,
56
+ and allowed transitions.
@@ -1,58 +1,64 @@
1
1
  ---
2
2
  name: ultra-dev
3
- description: Execute one authoritative Ultra task through a fresh-context, test-driven, review-backed live-path slice with resumable DB state. Use when a planned task is ready to implement, resume, or recover after a blocker or interrupted session.
3
+ description: Implement one authoritative Ultra task through a fresh-context, test-driven, review-backed live path. Use when a planned task is executable, interrupted, or ready for focused recovery.
4
4
  ---
5
5
 
6
- # Implement one executable task
7
-
8
- Bind exactly one task and change. Use the host for code reasoning and edits; use Ultra
9
- MCP for workflow state, context authority, task/session transitions, evidence, and
10
- recovery.
11
-
12
- ## Start or resume
13
-
14
- 1. Read `system.doctor`, `change.breadcrumb`, `task.get`, workflow state, dependencies,
15
- active sessions, Git HEAD, and worktree scope.
16
- 2. Resume an existing `dev` workflow or call `workflow.start` with `change_id` and
17
- `task_id`. Startup fails when the DB-backed task execution contract is incomplete or
18
- owned by another change.
19
- 3. Record `bind-task` with task, dependency, branch, and worktree evidence.
20
- 4. Compile `change.context` for `implement`. It derives public seam, verification, and
21
- required refs from the task row. Record its immutable manifest as the
22
- `compile-context` output only when ready. That starting snapshot remains historical
23
- task evidence; later task commits do not invalidate it when its commit stays on the
24
- current ancestry and the task contract is unchanged.
25
- 5. Run session admission before spawning an isolated session. Do not open a second
26
- active lease without the documented resume, takeover, or abandon decision.
27
-
28
- ## Red, green, verify
29
-
30
- 1. Reproduce the behavior or establish a characterization signal before logic edits.
31
- Record `establish-feedback-loop` with the exact failing command and observed result.
32
- 2. Set the task `in_progress`; implement the smallest complete vertical slice through
33
- the declared public seam. Preserve unrelated worktree changes.
34
- 3. Keep application judgment and edits in the host. Do not write projections, raw DB,
35
- workflow output digests, or evidence state by hand.
36
- 4. Refactor only inside the accepted slice while the focused signal stays green.
37
- 5. Record `implement-slice`, then run focused, adjacent, static/build, public-seam,
38
- error, and recovery checks proportional to risk. Record exact evidence under
39
- `verify-slice`.
40
- 6. Run `ultra-review` at the current diff. Record both independent verdict axes under
41
- `review-slice`; unresolved blocking findings return to implementation.
6
+ # Implement one task
7
+
8
+ The host model owns code reasoning and edits. Ultra owns the task and workflow state,
9
+ fresh context contract, session lease, evidence references, and recovery.
10
+
11
+ ## Bind and resume
12
+
13
+ 1. Read doctor, breadcrumb, active decisions, task contract, dependencies, dev runs,
14
+ sessions, HEAD, and worktree.
15
+ 2. Resume the matching dev run or start one with `change_id` and `task_id`.
16
+ 3. Record `bind-task` with current authority and dependency evidence.
17
+ 4. Compile `change.context` for `implement` using DB-backed public seam, verification
18
+ command, and refs. Context budgets are advisory; missing required evidence is
19
+ blocking. Record the immutable manifest as `compile-context`.
20
+ 5. Reuse an existing valid session. Otherwise pass admission and call `session.spawn`.
21
+ Work only in the returned worktree and preserve unrelated changes.
22
+
23
+ Do not spawn recursively from a parent-owned worker session. Process exit is transport
24
+ evidence, never task completion.
25
+
26
+ ## Focused inner loop
27
+
28
+ 1. Reproduce the bug, write a failing test, or establish a characterization signal
29
+ before a logic change. Record `establish-feedback-loop`.
30
+ 2. Mark the task `in_progress` and implement the smallest complete slice through the
31
+ declared public seam.
32
+ 3. Keep the loop adaptive. The model may choose implementation details inside the
33
+ accepted contract. If new evidence changes product intent, compatibility, security,
34
+ material cost, external effects, or recovery, use the host's native question UI and
35
+ the decision protocol; do not ask about ordinary reversible details.
36
+ 4. Record `implement-slice`, then run focused tests plus the adjacent checks justified
37
+ by the task risk. Record exact results under `verify-slice`.
38
+ 5. Run a task-scoped independent review on specification fidelity and relevant
39
+ engineering risks. Record `review-slice`. Fix blocking findings and refresh affected
40
+ evidence.
41
+ 6. Create the authorized local task commit. Do not push, publish, tag, or deploy unless
42
+ the user separately authorized that external effect.
43
+
44
+ Task-level tests and review belong to this inner loop. They do not replace aggregate
45
+ change testing or review when multiple slices, integrations, or broader risks require
46
+ those capabilities.
42
47
 
43
48
  ## Complete or recover
44
49
 
45
- Close the admitted session with `session.close` after its final heartbeat and verify
46
- that no running lease remains for the task. Then update the task to `completed` only
47
- after acceptance, verification, documentation, and review are current. Record
48
- `record-completion` with commands, results, changed paths, commit when authorized, and
49
- context/review references; then call `workflow.complete`. The MCP refuses dev
50
- convergence while the task is incomplete or a session is still running.
50
+ In direct mode, integrate the task commit through the repository's accepted path,
51
+ verify ancestry and the public seam, close the session, update the task to `completed`,
52
+ record `record-completion`, and complete the dev workflow.
53
+
54
+ In a parent-supervised worker, record completion evidence and exit without closing the
55
+ parent-owned lease. The primary host verifies the exact session commit, performs any
56
+ integration, refreshes review if the reviewed checkout changed, settles the lease, and
57
+ completes the workflow.
51
58
 
52
- On interruption or an external blocker, record the current step as `blocked`, update
53
- the task consistently, and preserve the session and evidence. Resume the same run;
54
- completed steps remain durable. Any code or contract change invalidates affected test,
55
- review, or context evidence.
59
+ Preserve worktrees by default. Remove one only when Git proves it is clean and
60
+ integrated. On interruption, record the current step and task as blocked, preserve
61
+ worktree and evidence, and resume the same run later.
56
62
 
57
- Return the task outcome, public seam, changed paths, exact checks, review results,
58
- workflow id, session state, residual risks, and one next route.
63
+ Return outcome, changed paths, public seam, exact checks, review axes, commit and
64
+ session state, residual risk, and allowed transitions.
@@ -1,55 +1,50 @@
1
1
  ---
2
2
  name: ultra-doctor
3
- description: Diagnose and recover Ultra DB schema, workflow outputs, projections, sessions, incidents, change artifacts, archives, hooks, and installed host assets. Use when authority is degraded, workflow state disagrees with prompts, outputs are stale, hooks fail, or MCP operations cannot proceed.
3
+ description: Diagnose and mechanically recover Ultra schema, workflow, projection, session, archive, hook, and installed-asset faults. Use when authority is degraded, stale, contradictory, or unavailable.
4
4
  ---
5
5
 
6
6
  # Diagnose before repair
7
7
 
8
- Default to read-only diagnosis. Call `system.doctor` with repair disabled and inspect:
9
-
10
- - SQLite integrity, schema version, required tables, and migration provenance;
11
- - baseline classification/readiness, research provenance, spec/evidence digests, gaps,
12
- and revision/worktree drift;
13
- - active, blocked, and ready workflow runs, current steps, blockers, and output health;
14
- - event/projection cursor lag and failed or interrupted projection jobs;
15
- - sessions, incidents, circuit state, active-change artifacts, and archive journals;
16
- - external provider ownership boundaries.
17
-
18
- An expected blocked workflow is a workflow warning, not DB corruption. A stale or
19
- missing recorded output is an authority failure for that run. Doctor cannot invent
20
- evidence, complete a step, accept a failure, approve a baseline, or change product
21
- scope.
22
-
23
- ## Route failures
24
-
25
- - Missing or migrated baseline evidence: `ultra-init` and the exact research step.
26
- - Stale workflow output: restore or regenerate the artifact from accepted evidence,
27
- then record the affected step again and re-run completion.
28
- - Projection lag with healthy authority: eligible for mechanical regeneration.
29
- - Orphan session: reconcile the recorded lease; do not kill unrelated processes.
30
- - Missing change artifact: recover from version control, backup, or explicit owner
31
- decision rather than silently recreating it.
32
- - Corrupt SQLite: preserve DB/WAL/SHM and obtain a restore-or-rebaseline decision.
33
-
34
- ## Explicit project repair
35
-
36
- After authorization, call `system.doctor` with repair enabled. Repair is limited to
37
- supported schema upgrades, backup-first archive recovery, orphan reconciliation,
38
- staleness consumption, projection requeue, and projection regeneration. Verify the
39
- pre-migration and repair backup paths and rerun the read-only report. A completed repair
40
- action does not imply healthy workflow evidence.
41
-
42
- When integrity prevents opening the DB, use only the documented restore or rebaseline
43
- command with its explicit confirmation token. Both must quarantine or back up prior
44
- authority and roll back on failure.
45
-
46
- ## Installed host failures
47
-
48
- For a missing hook adapter or stale plugin path, capture the manifest and missing
49
- target, run `ubp --doctor` for the actual host, reinstall through the adapter rather
50
- than patching cache contents, and verify provenance, hashes, entry points, MCP startup,
51
- and a hook smoke test. Project doctor and installer doctor are separate authorities.
52
-
53
- Return health first, failing authority checks, workflow warnings, backup/recovery
54
- paths, whether repair ran, unresolved owners, and one exact next action. Do not edit
55
- application code or external memory/graph providers through this Skill.
8
+ Doctor owns deterministic health and supported recovery. It cannot decide product
9
+ scope, invent evidence, approve a baseline, answer a user decision, or mark semantic
10
+ work complete.
11
+
12
+ ## Read-only diagnosis
13
+
14
+ Run `system.doctor` without repair and inspect:
15
+
16
+ - SQLite integrity, schema 18 migration, required tables, and backups;
17
+ - baseline and research provenance, gaps, digests, and Git/worktree drift;
18
+ - workflow status, obsolete-step migration, blockers, and output freshness;
19
+ - decisions and checkpoint artifact freshness;
20
+ - projection jobs and event cursors;
21
+ - sessions, preserved worktrees, incidents, circuit state, and archive journals;
22
+ - external provider boundaries.
23
+
24
+ An expected workflow pause or awaiting user decision is a warning, not corruption.
25
+ Missing or changed required evidence is an authority failure but cannot be reconstructed
26
+ by doctor.
27
+
28
+ ## Recovery boundary
29
+
30
+ With explicit repair authorization, `system.doctor` may:
31
+
32
+ - apply backup-first supported schema migrations;
33
+ - migrate active pre-18 rigid workflows into recoverable adaptive state;
34
+ - requeue or regenerate projections from healthy DB authority;
35
+ - reconcile orphan sessions without deleting unrelated or dirty worktrees;
36
+ - resume supported archive journals;
37
+ - recover missing workflow provenance as a blocked run requiring real evidence.
38
+
39
+ It may not create a Git checkpoint, replace a healthy baseline, accept known failures,
40
+ resolve decisions, regenerate semantic content, or edit application code.
41
+
42
+ Corrupt SQLite requires preservation of DB, WAL, and SHM followed by an explicit
43
+ restore-or-rebaseline choice. Missing hook adapters or stale cache paths require
44
+ `ubp --doctor` and adapter reinstall; never patch plugin cache contents by hand.
45
+
46
+ After repair, rerun doctor read-only and verify backup paths, schema, installed hashes,
47
+ entry points, MCP startup, and hook smoke tests as applicable.
48
+
49
+ Return health first, failed checks, mechanical repairs performed, preserved recovery
50
+ paths, unresolved owners, and allowed transitions plus any unique required transition.
@@ -1,104 +1,82 @@
1
1
  ---
2
2
  name: ultra-init
3
- description: Initialize a new repository, adopt an existing codebase, or migrate prior Ultra authority into a verified project baseline. Use when `.ultra` is absent, initialization is incomplete, baseline readiness is blocked, or a legacy Ultra project must be resumed.
3
+ description: Create or recover Ultra project authority for a new repository, an existing codebase, or an older Ultra installation. Use when `.ultra` is absent, initialization is incomplete, or doctor reports a migration or initialization fault.
4
4
  ---
5
5
 
6
- # Establish project authority
7
-
8
- Use host reasoning to inspect repository evidence and prepare baseline content. Use
9
- Ultra MCP for classification records, schema migration, workflow state, evidence
10
- digests, approval, and convergence. Never treat generated Markdown or JSON as state.
11
-
12
- ## Classify without guessing product scope
13
-
14
- Run `system.doctor` read-only when `.ultra/state.db` exists. Otherwise call
15
- `task.init_project` with `mode: "auto"`, the repository root, project name, and an
16
- owner-selected monorepo scope when applicable.
17
-
18
- Interpret classification independently from readiness:
19
-
20
- - `greenfield`: no meaningful delivered application behavior exists outside docs,
21
- generated output, or a starter skeleton;
22
- - `brownfield`: source, runtime, deployment, API, schema, or test evidence shows an
23
- existing maintained system;
24
- - `migrated`: older DB or projection-only authority was preserved and must be
25
- replaced by an evidence-backed brownfield baseline.
26
-
27
- The presence of `.ultra/`, a manifest, or a Git repository does not make a baseline
28
- ready. Classification never chooses an MVP, reduced scope, or delivery posture.
29
- Report the detected project type, technology signals, verification commands, and
30
- monorepo roots. Pass an explicit `project_type` or `stack` only when repository evidence
31
- or an owner decision supports the override; MCP preserves both detection and selection.
32
-
33
- ## Resume safely
34
-
35
- When `.ultra/` exists, call `task.init_project` with `resume: true`. It must preserve
36
- existing artifacts, create a pre-migration backup when needed, upgrade the schema,
37
- install only missing assets, and return the durable workflow ids and exact route.
38
-
39
- For projection-only state, execute only the backup-first migration command returned by
40
- the structured error. For a `migrated` compatibility row, call `baseline.start` with a
41
- new brownfield id and `replace_migrated: true`; never treat migration as owner approval.
42
-
43
- Replacing a healthy baseline requires a new id plus `replace_ready: true` and explicit
44
- `replacement_authorization`. Preserve corrupt DB, WAL, SHM, and backups; use the
45
- documented restore or rebaseline command only after the owner selects that destructive
46
- recovery path.
47
-
48
- ## Follow durable initialization state
49
-
50
- Read the returned init and research runs with `workflow.get`.
51
-
52
- - `inspect-authority`: `task.init_project` records the bounded repository and existing
53
- Ultra evidence it inspected.
54
- - `classify-repository`: `task.init_project` records classification, detected signals,
55
- selected scope, and supported overrides.
56
- - `scaffold-authority`: `task.init_project` creates or resumes DB authority and installs
57
- only missing scaffold assets.
58
- - `establish-baseline`: research completion, `baseline.record`, and owner-approved
59
- `baseline.converge` establish the evidence-backed authority.
60
- - `verify-initialization`: convergence re-reads baseline, init, research, repository,
61
- verification, and output health before completing initialization.
62
-
63
- The first three steps are deterministic writes owned by `task.init_project`; the final
64
- two are completed atomically by successful baseline convergence. Do not mark or emulate
65
- these transitions in Prompt text or projection files.
66
-
67
- - Greenfield starts a `full` research run.
68
- - Brownfield starts an `adoption` research run.
69
- - Both modes require all seventeen research steps before baseline convergence.
70
- - A migrated project remains routed to re-adoption before research can authorize work.
71
-
72
- Continue through `ultra-research`. Research completion records output digests; then
73
- `baseline.record` captures current scope, revision, discovery/product/architecture
74
- specs, source and runtime evidence, actual verification, unknowns, gaps,
75
- classification, and external provider metadata references.
76
-
77
- Call `baseline.converge` only after explicit owner approval. The MCP rejects missing
78
- research, missing discovery/product/architecture refs, stale evidence, revision or
79
- worktree drift, unaccepted known failures, blocking unknowns, and blocking gaps. A
80
- successful convergence atomically marks the baseline ready and completes the init run.
81
-
82
- ## Recovery
83
-
84
- - Record deterministic blockers on the current workflow; never create a parallel run.
85
- - Use `system.doctor` repair only for supported schema, projection, session, incident,
86
- archive, or legacy workflow-provenance recovery. A recovered legacy change workflow
87
- remains blocked for real baseline evidence; repair cannot invent research or approve
88
- a baseline.
89
- - Treat context budgets as advisory. Missing authority, evidence, output, or approval
90
- is blocking.
91
- - Store only references to external memory and code-graph providers.
92
-
93
- ## Completion
94
-
95
- Read `baseline.get`, `workflow.get`, and `system.doctor` after convergence. Report
96
- classification evidence, scope, revision, worktree snapshot, migration backups,
97
- research run and output health, verification, gaps, approval, and one route.
98
-
99
- Initialization is complete only when the baseline is `ready`, the init workflow is
100
- `completed`, the research workflow is `completed`, and
101
- `baseline.research_run_id` names that exact research run with healthy outputs. Route
102
- every newly converged or already initialized baseline through `ultra-change`; planning
103
- starts only after that command persists a complete Change Contract, profile, and
104
- research disposition. Otherwise return the exact current workflow step or blocker.
6
+ # Initialize project authority
7
+
8
+ Initialization is a bounded setup capability. It creates or repairs the repository and
9
+ Ultra authority; it does not perform product research, approve a baseline, or choose
10
+ the next semantic workflow.
11
+
12
+ ## Inspect before mutation
13
+
14
+ 1. Identify the repository root, existing `.ultra` state, Git state, meaningful source,
15
+ monorepo boundaries, and current owner request.
16
+ 2. If `.ultra/state.db` exists, run `system.doctor` read-only and resume with
17
+ `task.init_project` only when its report permits it.
18
+ 3. Otherwise call `task.init_project` with `mode: "auto"`, the project name, and an
19
+ explicit scope only when the repository contains multiple plausible roots.
20
+ 4. Leave `git_mode` as `auto` unless the user explicitly requires a non-Git workspace.
21
+
22
+ Use repository evidence to classify:
23
+
24
+ - `greenfield`: no meaningful delivered application behavior is present;
25
+ - `brownfield`: source, runtime, API, data, deployment, or tests describe an existing
26
+ maintained system;
27
+ - `migrated`: older Ultra authority was preserved but is not a trusted baseline.
28
+
29
+ The model may override an automatic classification only with evidence or an explicit
30
+ user decision. Classification must not infer product scope, an MVP, or a release plan.
31
+
32
+ ## Interaction boundary
33
+
34
+ Read `../ultra-think/references/decision-dialogue.md` before asking a material question.
35
+ Inspect observable facts yourself. Use the host's native question UI when available and
36
+ plain direct interaction otherwise. Ask only when repository scope, replacement of
37
+ healthy authority, destructive recovery, or another material owner decision is truly
38
+ unresolved. Normalize clear intent already present in the request without asking again.
39
+
40
+ ## Deterministic initialization contract
41
+
42
+ `task.init_project` owns these steps:
43
+
44
+ 1. `inspect-authority`
45
+ 2. `classify-repository`
46
+ 3. `scaffold-authority`
47
+ 4. `verify-initialization`
48
+
49
+ The operation must:
50
+
51
+ - create or migrate `.ultra/state.db` with a backup before schema migration;
52
+ - install only missing scaffold assets on resume;
53
+ - preserve existing artifacts and unrelated work;
54
+ - preserve an existing Git repository and HEAD;
55
+ - initialize Git and a safe `.gitignore` entry when Git is absent;
56
+ - report an unborn repository as `initial_commit_required` without manufacturing a
57
+ commit, remote, tag, or push;
58
+ - read back the created DB, classification, projection, and Git result before
59
+ completing the init workflow.
60
+
61
+ Projection-only projects must use the exact backup-first migration command returned by
62
+ the runtime. A migrated compatibility baseline requires a new brownfield adoption with
63
+ `replace_migrated: true`. Replacing a healthy baseline requires explicit replacement
64
+ authority. Corrupt DB, WAL, SHM, and backups must be preserved until the user chooses a
65
+ documented recovery operation.
66
+
67
+ ## Completion and handoff
68
+
69
+ Initialization is complete when the init workflow is `completed`, the current schema is
70
+ healthy, the scaffold is readable, and repository classification and Git state are
71
+ durable. Research status may still be `not_started`; that is not incomplete init.
72
+
73
+ Read the returned `allowed_transitions` and `required_transition`:
74
+
75
+ - a required transition represents a hard recovery invariant and must be followed;
76
+ - otherwise the host model recommends among the allowed capabilities using the user's
77
+ goal and current evidence;
78
+ - start `ultra-research` only when the user invoked it or the host selects it after init.
79
+
80
+ Report classification, scope, schema and backup result, Git state, init workflow id,
81
+ baseline state, and allowed transitions. Do not claim that a baseline is ready until a
82
+ separate research/adoption workflow has recorded and converged it.