ultra-builder-pro-cli 0.25.1 → 0.26.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 (243) hide show
  1. package/.ultra-template/changes/abandoned/.gitkeep +0 -0
  2. package/.ultra-template/contexts/TEMPLATE.md +94 -0
  3. package/.ultra-template/decisions/.gitkeep +1 -0
  4. package/.ultra-template/evidence/.gitkeep +1 -0
  5. package/.ultra-template/north-star.md +46 -0
  6. package/.ultra-template/research/.gitkeep +1 -0
  7. package/.ultra-template/specs/discovery.md +2 -2
  8. package/.ultra-template/tasks.json +3 -0
  9. package/.ultra-template/test-report.json +27 -0
  10. package/CHANGELOG.md +107 -1
  11. package/README.md +217 -579
  12. package/adapters/_shared/delegate-profiles/kimi-read-only.md +15 -0
  13. package/adapters/_shared/delegate-profiles/kimi-write.md +17 -0
  14. package/adapters/_shared/file-ops.cjs +76 -2
  15. package/adapters/_shared/host-profile.cjs +97 -0
  16. package/adapters/_shared/plugin-core.cjs +204 -0
  17. package/adapters/_shared/runtime-assets.cjs +31 -96
  18. package/adapters/claude.js +92 -291
  19. package/adapters/codex.js +309 -842
  20. package/adapters/grok.js +143 -1469
  21. package/adapters/kimi.js +124 -1053
  22. package/adapters/opencode.js +230 -742
  23. package/bin/delegate-worker.cjs +328 -0
  24. package/bin/delegate.cjs +463 -0
  25. package/bin/install.js +38 -11
  26. package/docs/ARCHITECTURE.md +125 -216
  27. package/docs/ARTIFACT-AUTHORITY.md +90 -268
  28. package/docs/DECISIONS.md +77 -87
  29. package/docs/PHILOSOPHY.md +208 -0
  30. package/docs/PLUGIN-ISOLATION-CONTRACT.md +65 -39
  31. package/docs/RUNTIME-COMPAT-MATRIX.md +140 -155
  32. package/docs/SKILL-AUTHORING.md +94 -73
  33. package/docs/WORKFLOW-LIFECYCLE.md +97 -189
  34. package/hooks/README.md +19 -37
  35. package/hooks/_common.py +113 -0
  36. package/hooks/adapters/codex.py +9 -16
  37. package/hooks/adapters/grok.py +5 -5
  38. package/hooks/adapters/kimi.py +8 -14
  39. package/hooks/block_dangerous_commands.py +201 -0
  40. package/hooks/compact_context.py +65 -0
  41. package/hooks/mid_workflow_recall.py +25 -0
  42. package/hooks/post_edit_guard.py +105 -0
  43. package/hooks/session_context.py +30 -0
  44. package/package.json +17 -52
  45. package/skills/ultra-change/SKILL.md +115 -50
  46. package/skills/ultra-change/references/change-contract.md +68 -3
  47. package/skills/ultra-delegate/SKILL.md +89 -0
  48. package/skills/ultra-delegate/references/delegation-contract.md +59 -0
  49. package/skills/ultra-delegate/scripts/delegate_wait.py +86 -0
  50. package/skills/ultra-deliver/SKILL.md +98 -42
  51. package/skills/ultra-deliver/references/baseline-reconciliation.md +39 -20
  52. package/skills/ultra-dev/SKILL.md +115 -62
  53. package/skills/ultra-dev/references/debugging.md +22 -0
  54. package/skills/ultra-domain-modeling/SKILL.md +79 -0
  55. package/skills/ultra-grilling/SKILL.md +118 -0
  56. package/skills/ultra-grilling/references/reframing.md +72 -0
  57. package/skills/ultra-init/SKILL.md +102 -37
  58. package/skills/ultra-init/references/brownfield-adoption.md +33 -83
  59. package/skills/ultra-init/scripts/init_project.cjs +84 -0
  60. package/skills/ultra-plan/SKILL.md +101 -68
  61. package/skills/ultra-research/SKILL.md +68 -48
  62. package/skills/ultra-research/references/00-problem-validation.md +5 -5
  63. package/skills/ultra-research/references/01-opportunity-discovery.md +3 -3
  64. package/skills/ultra-research/references/02-market-assessment.md +5 -4
  65. package/skills/ultra-research/references/03-competitive-landscape.md +3 -3
  66. package/skills/ultra-research/references/04-product-strategy.md +3 -3
  67. package/skills/ultra-research/references/05-assumptions-validation.md +5 -5
  68. package/skills/ultra-research/references/10-user-personas.md +3 -2
  69. package/skills/ultra-research/references/11-user-scenarios.md +3 -3
  70. package/skills/ultra-research/references/20-user-stories.md +4 -3
  71. package/skills/ultra-research/references/21-features-scope.md +3 -2
  72. package/skills/ultra-research/references/22-success-metrics.md +3 -3
  73. package/skills/ultra-research/references/30-architecture-context.md +3 -3
  74. package/skills/ultra-research/references/31-solution-strategy.md +3 -3
  75. package/skills/ultra-research/references/32-building-blocks.md +3 -3
  76. package/skills/ultra-research/references/40-deployment.md +3 -3
  77. package/skills/ultra-research/references/41-quality-risks.md +3 -3
  78. package/skills/ultra-research/references/99-synthesis.md +7 -7
  79. package/skills/ultra-review/SKILL.md +84 -32
  80. package/skills/ultra-review/references/code.md +17 -0
  81. package/skills/ultra-review/references/comments.md +12 -0
  82. package/skills/ultra-review/references/design.md +12 -0
  83. package/skills/ultra-review/references/errors.md +13 -0
  84. package/skills/ultra-review/references/spec.md +13 -0
  85. package/skills/ultra-review/references/tests.md +12 -0
  86. package/skills/ultra-review/references/worker-packet.md +40 -0
  87. package/skills/ultra-review/scripts/review_wait.py +26 -15
  88. package/skills/ultra-status/SKILL.md +61 -36
  89. package/skills/ultra-tdd/SKILL.md +81 -0
  90. package/skills/ultra-tdd/references/templates/README.md +20 -0
  91. package/skills/ultra-tdd/references/templates/feature-flag-default-audit.sh +79 -0
  92. package/skills/ultra-tdd/references/templates/persistence-real.ts +78 -0
  93. package/skills/ultra-tdd/references/templates/testcontainer-postgres.py +78 -0
  94. package/skills/ultra-tdd/references/templates/testcontainer-postgres.ts +73 -0
  95. package/skills/ultra-tdd/references/templates/vertical-slice.ts +66 -0
  96. package/skills/ultra-tdd/references/test-execution.md +18 -0
  97. package/skills/ultra-test/SKILL.md +75 -30
  98. package/skills/ultra-test/references/export-syntax.md +18 -0
  99. package/skills/ultra-test/scripts/worktree_digest.cjs +54 -0
  100. package/skills/ultra-think/SKILL.md +49 -27
  101. package/skills/ultra-think/references/autonomy-boundary.md +48 -0
  102. package/skills/ultra-think/references/interaction-boundary.md +18 -33
  103. package/.ultra-template/docs/research/README.md +0 -55
  104. package/.ultra-template/reports/templates/delivery-report.json +0 -17
  105. package/.ultra-template/reports/templates/test-report.json +0 -18
  106. package/.ultra-template/tasks/tasks.json +0 -15
  107. package/.ultra-template/templates/task-context.md +0 -19
  108. package/adapters/_shared/codex-assets.cjs +0 -725
  109. package/adapters/_shared/codex-ultra-tools-entry.cjs +0 -11
  110. package/adapters/_shared/interaction-contract.cjs +0 -129
  111. package/adapters/_shared/path-rewrite.cjs +0 -79
  112. package/adapters/_shared/runtime-native.cjs +0 -132
  113. package/adapters/_shared/settings-merge.cjs +0 -76
  114. package/agents/code-reviewer.md +0 -42
  115. package/agents/debugger.md +0 -40
  116. package/agents/review-code.md +0 -49
  117. package/agents/review-comments.md +0 -38
  118. package/agents/review-coordinator.md +0 -56
  119. package/agents/review-design.md +0 -40
  120. package/agents/review-errors.md +0 -43
  121. package/agents/review-spec.md +0 -39
  122. package/agents/review-tests.md +0 -40
  123. package/agents/tdd-runner.md +0 -38
  124. package/bin/orchestrator.js +0 -383
  125. package/commands/ultra-change.md +0 -10
  126. package/commands/ultra-deliver.md +0 -10
  127. package/commands/ultra-dev.md +0 -10
  128. package/commands/ultra-doctor.md +0 -10
  129. package/commands/ultra-init.md +0 -10
  130. package/commands/ultra-plan.md +0 -10
  131. package/commands/ultra-research.md +0 -10
  132. package/commands/ultra-review.md +0 -10
  133. package/commands/ultra-status.md +0 -10
  134. package/commands/ultra-test.md +0 -10
  135. package/commands/ultra-think.md +0 -10
  136. package/docs/AGENT-CONTEXT.md +0 -191
  137. package/docs/COMMIT-HASH-BACKFILL.md +0 -51
  138. package/docs/LEGACY-CLI-CROSSWALK.md +0 -175
  139. package/docs/ROADMAP.md +0 -101
  140. package/docs/STATE-DB-ACCESS-POLICY.md +0 -161
  141. package/hooks/active_task_context.py +0 -152
  142. package/hooks/context_envelope.py +0 -100
  143. package/hooks/health_check.py +0 -196
  144. package/hooks/pre_stop_check.py +0 -66
  145. package/hooks/runtime_paths.py +0 -396
  146. package/hooks/subagent_tracker.py +0 -88
  147. package/hooks/workflow_checkpoint.py +0 -76
  148. package/hooks/workflow_context.py +0 -48
  149. package/hooks/workflow_resume.py +0 -84
  150. package/mcp-server/hook-context.cjs +0 -38
  151. package/mcp-server/hook-event.cjs +0 -34
  152. package/mcp-server/lib/archive-journal.cjs +0 -1119
  153. package/mcp-server/lib/archive-mutation-worker.py +0 -365
  154. package/mcp-server/lib/artifact-registry.cjs +0 -1232
  155. package/mcp-server/lib/baseline-workflow.cjs +0 -1193
  156. package/mcp-server/lib/canonical-json.cjs +0 -19
  157. package/mcp-server/lib/change-authority.cjs +0 -26
  158. package/mcp-server/lib/change-packet.cjs +0 -790
  159. package/mcp-server/lib/change-workflow.cjs +0 -65
  160. package/mcp-server/lib/context-envelope.cjs +0 -581
  161. package/mcp-server/lib/context-paths.cjs +0 -142
  162. package/mcp-server/lib/decision-records.cjs +0 -423
  163. package/mcp-server/lib/delivery-transaction.cjs +0 -471
  164. package/mcp-server/lib/doctor-backup-worker.cjs +0 -328
  165. package/mcp-server/lib/doctor.cjs +0 -627
  166. package/mcp-server/lib/git-bootstrap.cjs +0 -651
  167. package/mcp-server/lib/init-project.cjs +0 -1021
  168. package/mcp-server/lib/kernel-change-workflow.cjs +0 -2029
  169. package/mcp-server/lib/legacy-change-workflow.cjs +0 -3032
  170. package/mcp-server/lib/managed-file-write.cjs +0 -172
  171. package/mcp-server/lib/plan-checkpoint.cjs +0 -177
  172. package/mcp-server/lib/plan-publication-worker.cjs +0 -830
  173. package/mcp-server/lib/plan-store.cjs +0 -794
  174. package/mcp-server/lib/prd-parser.cjs +0 -83
  175. package/mcp-server/lib/pricing.cjs +0 -44
  176. package/mcp-server/lib/project-context.cjs +0 -178
  177. package/mcp-server/lib/projector.cjs +0 -386
  178. package/mcp-server/lib/provider-refs.cjs +0 -42
  179. package/mcp-server/lib/runtime-paths.cjs +0 -1714
  180. package/mcp-server/lib/runtime-state.cjs +0 -222
  181. package/mcp-server/lib/safe-project-file.cjs +0 -385
  182. package/mcp-server/lib/stage-checkpoints.cjs +0 -463
  183. package/mcp-server/lib/state-authority.cjs +0 -95
  184. package/mcp-server/lib/state-db.cjs +0 -1580
  185. package/mcp-server/lib/state-ops.cjs +0 -1428
  186. package/mcp-server/lib/task-contract.cjs +0 -404
  187. package/mcp-server/lib/task-expander.cjs +0 -105
  188. package/mcp-server/lib/task-ledger.cjs +0 -1964
  189. package/mcp-server/lib/telemetry.cjs +0 -85
  190. package/mcp-server/lib/topo.cjs +0 -131
  191. package/mcp-server/lib/ultra-facade.cjs +0 -2684
  192. package/mcp-server/lib/worker-packet.cjs +0 -358
  193. package/mcp-server/server.cjs +0 -437
  194. package/orchestrator/auto-merge.cjs +0 -128
  195. package/orchestrator/daemon.cjs +0 -264
  196. package/orchestrator/dispatch-rules.cjs +0 -78
  197. package/orchestrator/parallel-orchestrator.cjs +0 -903
  198. package/orchestrator/planner/plan-builder.cjs +0 -125
  199. package/orchestrator/recovery.cjs +0 -188
  200. package/orchestrator/session-close-journal-worker.cjs +0 -5
  201. package/orchestrator/session-close-journal.cjs +0 -1014
  202. package/orchestrator/session-runner.cjs +0 -1153
  203. package/orchestrator/worktree-manager.cjs +0 -282
  204. package/settings.json +0 -7
  205. package/skills/cc-collab/SKILL.md +0 -42
  206. package/skills/code-review-expert/SKILL.md +0 -43
  207. package/skills/code-review-expert/references/correctness-reliability.md +0 -30
  208. package/skills/code-review-expert/references/design-boundaries.md +0 -26
  209. package/skills/code-review-expert/references/removal-plan.md +0 -24
  210. package/skills/codex-collab/SKILL.md +0 -49
  211. package/skills/codex-collab/evals/evals.json +0 -35
  212. package/skills/integration-rules/SKILL.md +0 -32
  213. package/skills/security-rules/SKILL.md +0 -38
  214. package/skills/testing-rules/SKILL.md +0 -32
  215. package/skills/ultra-doctor/SKILL.md +0 -41
  216. package/skills/ultra-plan/references/semantic-preflight.md +0 -20
  217. package/skills/ultra-verify/SKILL.md +0 -46
  218. package/skills/ultra-verify/evals/evals.json +0 -46
  219. package/skills/ultra-verify/references/cross-verify-modes.md +0 -28
  220. package/skills/ultra-verify/references/evidence-status.md +0 -21
  221. package/skills/ultra-verify/scripts/verify_wait.py +0 -94
  222. package/spec/cli-protocol.md +0 -102
  223. package/spec/mcp-tools.yaml +0 -312
  224. package/spec/schemas/baseline-reconciliation.v1.schema.json +0 -73
  225. package/spec/schemas/change-delta.v1.schema.json +0 -153
  226. package/spec/schemas/command-manifest.schema.json +0 -29
  227. package/spec/schemas/context-file.v4.5.schema.json +0 -54
  228. package/spec/schemas/delivery-report.v1.schema.json +0 -66
  229. package/spec/schemas/documentation-reconciliation.v1.schema.json +0 -106
  230. package/spec/schemas/mcp-tools.schema.json +0 -136
  231. package/spec/schemas/skill-manifest.schema.json +0 -24
  232. package/spec/schemas/state-db.sql +0 -641
  233. package/spec/schemas/task-ledger.v2.schema.json +0 -296
  234. package/spec/schemas/tasks.v4.5.schema.json +0 -96
  235. package/spec/schemas/test-report.v1.schema.json +0 -225
  236. package/ultra-tools/cli.cjs +0 -129
  237. package/ultra-tools/commands/db.cjs +0 -226
  238. package/ultra-tools/commands/legacy-memory.cjs +0 -159
  239. package/ultra-tools/commands/migrate.cjs +0 -1386
  240. package/ultra-tools/commands/session.cjs +0 -213
  241. package/ultra-tools/commands/status.cjs +0 -559
  242. package/ultra-tools/commands/system.cjs +0 -498
  243. package/ultra-tools/commands/task.cjs +0 -105
@@ -1,172 +0,0 @@
1
- 'use strict';
2
-
3
- const crypto = require('node:crypto');
4
- const fs = require('node:fs');
5
- const path = require('node:path');
6
-
7
- const { normalizeProjectRelative } = require('./safe-project-file.cjs');
8
-
9
- class ManagedFileWriteError extends Error {
10
- constructor(code, message, details) {
11
- super(message);
12
- this.name = 'ManagedFileWriteError';
13
- this.code = code;
14
- if (details) this.details = details;
15
- }
16
- }
17
-
18
- function physicalProjectRoot(rootDir) {
19
- const root = path.resolve(rootDir);
20
- const stat = fs.lstatSync(root, { throwIfNoEntry: false });
21
- if (!stat || !stat.isDirectory() || stat.isSymbolicLink()) {
22
- throw new ManagedFileWriteError('PATH_AUTHORITY_VIOLATION', `unsafe project root: ${root}`);
23
- }
24
- return { root, physical: fs.realpathSync.native(root) };
25
- }
26
-
27
- function ensureDirectory(rootDir, relativeDir) {
28
- const project = physicalProjectRoot(rootDir);
29
- const components = normalizeProjectRelative(`${relativeDir}/.managed-target`).split('/').slice(0, -1);
30
- let current = project.physical;
31
- for (const component of components) {
32
- current = path.join(current, component);
33
- let stat = fs.lstatSync(current, { throwIfNoEntry: false });
34
- if (!stat) {
35
- fs.mkdirSync(current, { mode: 0o700 });
36
- stat = fs.lstatSync(current);
37
- }
38
- if (!stat.isDirectory() || stat.isSymbolicLink()) {
39
- throw new ManagedFileWriteError(
40
- 'PATH_AUTHORITY_VIOLATION',
41
- `managed artifact ancestor is unsafe: ${path.relative(project.root, current)}`,
42
- );
43
- }
44
- const physical = fs.realpathSync.native(current);
45
- if (physical !== project.physical && !physical.startsWith(`${project.physical}${path.sep}`)) {
46
- throw new ManagedFileWriteError(
47
- 'PATH_AUTHORITY_VIOLATION',
48
- `managed artifact ancestor escapes the project: ${relativeDir}`,
49
- );
50
- }
51
- }
52
- return { project, directory: current };
53
- }
54
-
55
- function writeManagedFile(rootDir, relativePath, bytes, { mode = 0o600 } = {}) {
56
- const relative = normalizeProjectRelative(relativePath);
57
- const directoryRelative = path.posix.dirname(relative);
58
- const basename = path.posix.basename(relative);
59
- const prepared = ensureDirectory(rootDir, directoryRelative);
60
- const target = path.join(prepared.directory, basename);
61
- const existing = fs.lstatSync(target, { throwIfNoEntry: false });
62
- if (existing && (existing.isSymbolicLink() || !existing.isFile())) {
63
- throw new ManagedFileWriteError(
64
- 'PATH_AUTHORITY_VIOLATION',
65
- `managed artifact target is unsafe: ${relative}`,
66
- );
67
- }
68
- const tempName = `.${basename}.${process.pid}.${crypto.randomUUID()}.tmp`;
69
- const temporary = path.join(prepared.directory, tempName);
70
- let fd;
71
- try {
72
- fd = fs.openSync(
73
- temporary,
74
- fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL
75
- | (fs.constants.O_NOFOLLOW || 0),
76
- mode,
77
- );
78
- fs.writeFileSync(fd, bytes);
79
- fs.fsyncSync(fd);
80
- fs.closeSync(fd);
81
- fd = undefined;
82
- fs.renameSync(temporary, target);
83
- const targetStat = fs.lstatSync(target);
84
- if (!targetStat.isFile() || targetStat.isSymbolicLink()) {
85
- throw new ManagedFileWriteError(
86
- 'PATH_AUTHORITY_VIOLATION',
87
- `managed artifact publication changed identity: ${relative}`,
88
- );
89
- }
90
- return {
91
- path: relative,
92
- digest: crypto.createHash('sha256').update(bytes).digest('hex'),
93
- bytes: Buffer.byteLength(bytes),
94
- };
95
- } catch (error) {
96
- if (fd !== undefined) fs.closeSync(fd);
97
- try { fs.unlinkSync(temporary); } catch {}
98
- if (error instanceof ManagedFileWriteError) throw error;
99
- const wrapped = new ManagedFileWriteError(
100
- 'PATH_AUTHORITY_VIOLATION',
101
- `managed artifact write failed: ${relative}`,
102
- { cause: error.message },
103
- );
104
- throw wrapped;
105
- }
106
- }
107
-
108
- function writeManagedJson(rootDir, relativePath, value) {
109
- return writeManagedFile(rootDir, relativePath, `${JSON.stringify(value, null, 2)}\n`);
110
- }
111
-
112
- function snapshotManagedFile(rootDir, relativePath) {
113
- const relative = normalizeProjectRelative(relativePath);
114
- const directoryRelative = path.posix.dirname(relative);
115
- const basename = path.posix.basename(relative);
116
- const prepared = ensureDirectory(rootDir, directoryRelative);
117
- const target = path.join(prepared.directory, basename);
118
- const stat = fs.lstatSync(target, { throwIfNoEntry: false });
119
- if (!stat) return { path: relative, existed: false, bytes: null };
120
- if (!stat.isFile() || stat.isSymbolicLink()) {
121
- throw new ManagedFileWriteError(
122
- 'PATH_AUTHORITY_VIOLATION',
123
- `managed artifact target is unsafe: ${relative}`,
124
- );
125
- }
126
- return {
127
- path: relative,
128
- existed: true,
129
- bytes: fs.readFileSync(target),
130
- };
131
- }
132
-
133
- function removeManagedFile(rootDir, relativePath) {
134
- const relative = normalizeProjectRelative(relativePath);
135
- const directoryRelative = path.posix.dirname(relative);
136
- const basename = path.posix.basename(relative);
137
- const prepared = ensureDirectory(rootDir, directoryRelative);
138
- const target = path.join(prepared.directory, basename);
139
- const stat = fs.lstatSync(target, { throwIfNoEntry: false });
140
- if (!stat) return false;
141
- if (!stat.isFile() || stat.isSymbolicLink()) {
142
- throw new ManagedFileWriteError(
143
- 'PATH_AUTHORITY_VIOLATION',
144
- `managed artifact rollback target is unsafe: ${relative}`,
145
- );
146
- }
147
- fs.unlinkSync(target);
148
- return true;
149
- }
150
-
151
- function restoreManagedFile(rootDir, snapshot) {
152
- if (!snapshot || typeof snapshot.path !== 'string') {
153
- throw new ManagedFileWriteError(
154
- 'PATH_AUTHORITY_VIOLATION',
155
- 'managed artifact rollback snapshot is invalid',
156
- );
157
- }
158
- if (snapshot.existed) {
159
- return writeManagedFile(rootDir, snapshot.path, snapshot.bytes);
160
- }
161
- removeManagedFile(rootDir, snapshot.path);
162
- return { path: snapshot.path, removed: true };
163
- }
164
-
165
- module.exports = {
166
- ManagedFileWriteError,
167
- removeManagedFile,
168
- restoreManagedFile,
169
- snapshotManagedFile,
170
- writeManagedFile,
171
- writeManagedJson,
172
- };
@@ -1,177 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('node:path');
4
-
5
- const artifacts = require('./artifact-registry.cjs');
6
- const changes = require('./change-workflow.cjs');
7
- const ops = require('./state-ops.cjs');
8
- const planStore = require('./plan-store.cjs');
9
- const taskLedger = require('./task-ledger.cjs');
10
-
11
- class PlanCheckpointError extends Error {
12
- constructor(code, message, details) {
13
- super(message);
14
- this.name = 'PlanCheckpointError';
15
- this.code = code;
16
- if (details !== undefined) this.details = details;
17
- }
18
- }
19
-
20
- function publishPlan(db, {
21
- change_id: changeId,
22
- context,
23
- } = {}, {
24
- rootDir = process.cwd(),
25
- markRecoveryRequired = null,
26
- } = {}) {
27
- const change = changes.readChange(db, changeId);
28
- if (!change) {
29
- throw new PlanCheckpointError('CHANGE_NOT_FOUND', `change ${changeId} not found`);
30
- }
31
- if (change.status !== 'active') {
32
- throw new PlanCheckpointError(
33
- 'CHANGE_NOT_MUTABLE',
34
- `change ${change.id} is ${change.status}`,
35
- );
36
- }
37
- const tasks = ops.listTasks(db, { change_id: change.id });
38
- if (tasks.length === 0) {
39
- throw new PlanCheckpointError('NO_TASKS', 'a Plan checkpoint requires at least one task');
40
- }
41
- if (!context?.id || !context?.artifact_path || !context?.digest) {
42
- throw new PlanCheckpointError(
43
- 'PLAN_CONTEXT_REQUIRED',
44
- 'a Plan checkpoint requires one canonical Context Envelope',
45
- );
46
- }
47
-
48
- const plan = planStore.buildPlan(tasks, { changeId: change.id });
49
- const publication = planStore.prepareChangePlanPublication(plan, {
50
- rootDir,
51
- change,
52
- tasks,
53
- context: {
54
- snapshot_id: context.id,
55
- manifest_path: context.artifact_path,
56
- manifest_digest: context.digest,
57
- },
58
- });
59
- const contextArtifact = db.prepare(
60
- `SELECT id FROM artifacts
61
- WHERE path = ? AND status <> 'archived'
62
- ORDER BY updated_at DESC, rowid DESC LIMIT 1`,
63
- ).get(context.artifact_path);
64
- const artifactInputs = publication.artifacts.map(({ kind, path: file, digest }) => ({
65
- digest,
66
- input: {
67
- owner_type: 'change',
68
- owner_id: change.id,
69
- kind,
70
- path: path.relative(rootDir, file).split(path.sep).join('/'),
71
- source_refs: [
72
- { type: 'change', id: change.id, relation: 'planned_for' },
73
- ...(contextArtifact
74
- ? [{ type: 'artifact', id: contextArtifact.id, relation: 'compiled_from' }]
75
- : []),
76
- ...tasks.map((task) => ({
77
- type: 'task',
78
- id: task.id,
79
- relation: 'compiled_from_task_contract',
80
- })),
81
- ],
82
- consumer_refs: [{
83
- type: 'external',
84
- id: 'ultra-dev',
85
- relation: 'consumed_by',
86
- }],
87
- provenance: {
88
- writer: 'ultra.checkpoint',
89
- stage: 'plan',
90
- publication_transaction_id: publication.transaction_id,
91
- },
92
- metadata: {
93
- context_envelope_id: context.id,
94
- context_digest: context.digest,
95
- terminal_role: true,
96
- },
97
- },
98
- }));
99
-
100
- try {
101
- ops.tx(db, () => {
102
- const preflight = artifactInputs.map(({ input }) => (
103
- artifacts.preflightArtifactPublication(db, input, { rootDir })
104
- ));
105
- publication.publish();
106
- artifactInputs.forEach(({ input, digest }, index) => {
107
- artifacts.recordArtifactInTx(db, {
108
- ...input,
109
- id: preflight[index].artifact_id || undefined,
110
- expected_before_digest: preflight[index].expected_before_digest,
111
- content_digest: digest,
112
- }, { rootDir });
113
- });
114
- ops.appendEventInTx(db, {
115
- type: 'plan_checkpoint_published',
116
- change_id: change.id,
117
- payload: {
118
- context_envelope_id: context.id,
119
- context_digest: context.digest,
120
- plan_path: path.relative(rootDir, publication.plan_path).split(path.sep).join('/'),
121
- plan_md_path: path.relative(rootDir, publication.plan_md_path).split(path.sep).join('/'),
122
- publication_transaction_id: publication.transaction_id,
123
- wave_count: plan.waves.length,
124
- },
125
- });
126
- });
127
- } catch (error) {
128
- const rollback = publication.rollback();
129
- const failure = rollback?.rolled_back === false
130
- ? planStore.planRecoveryRequiredError(error, rollback, publication.transaction_id)
131
- : error;
132
- if (failure.code === 'PLAN_RECOVERY_REQUIRED') {
133
- markRecoveryRequired?.({
134
- recovered: 0,
135
- finalized: 0,
136
- pending: 1,
137
- issues: [failure.details?.rollback_issue || {
138
- code: failure.cause?.code || 'PLAN_RECOVERY_FAILED',
139
- message: failure.cause?.message || failure.message,
140
- }],
141
- });
142
- }
143
- throw failure;
144
- }
145
-
146
- try {
147
- publication.commit();
148
- } catch (error) {
149
- markRecoveryRequired?.({
150
- recovered: 0,
151
- finalized: 0,
152
- pending: 1,
153
- issues: [error.details?.issue || {
154
- code: error.cause?.code || 'PLAN_RECOVERY_FAILED',
155
- message: error.cause?.message || error.message,
156
- }],
157
- });
158
- throw error;
159
- }
160
-
161
- return {
162
- plan_path: path.relative(rootDir, publication.plan_path).split(path.sep).join('/'),
163
- plan_md_path: path.relative(rootDir, publication.plan_md_path).split(path.sep).join('/'),
164
- wave_count: plan.waves.length,
165
- task_count: tasks.length,
166
- task_contract_digests: Object.fromEntries(
167
- tasks.map((task) => [task.id, taskLedger.durableTask(task).digest]),
168
- ),
169
- context_envelope_id: context.id,
170
- context_digest: context.digest,
171
- };
172
- }
173
-
174
- module.exports = {
175
- PlanCheckpointError,
176
- publishPlan,
177
- };