ultra-builder-pro-cli 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ultra-template/docs/research/README.md +26 -5
- package/.ultra-template/specs/discovery.md +1 -1
- package/.ultra-template/tasks/tasks.json +10 -3
- package/.ultra-template/templates/task-context.md +19 -0
- package/CHANGELOG.md +106 -0
- package/README.md +215 -41
- package/adapters/_shared/codex-assets.cjs +69 -11
- package/adapters/_shared/interaction-contract.cjs +36 -3
- package/adapters/_shared/runtime-assets.cjs +41 -1
- package/adapters/claude.js +7 -5
- package/adapters/codex.js +1 -1
- package/adapters/kimi.js +2 -8
- package/adapters/opencode.js +43 -30
- package/bin/orchestrator.js +64 -24
- package/docs/AGENT-CONTEXT.md +89 -49
- package/docs/ARCHITECTURE.md +112 -45
- package/docs/ARTIFACT-AUTHORITY.md +274 -0
- package/docs/COMMIT-HASH-BACKFILL.md +33 -90
- package/docs/DECISIONS.md +14 -6
- package/docs/LEGACY-CLI-CROSSWALK.md +16 -6
- package/docs/PLUGIN-ISOLATION-CONTRACT.md +6 -4
- package/docs/ROADMAP.md +20 -6
- package/docs/RUNTIME-COMPAT-MATRIX.md +29 -16
- package/docs/STATE-DB-ACCESS-POLICY.md +43 -13
- package/docs/WORKFLOW-LIFECYCLE.md +105 -50
- package/hooks/README.md +10 -8
- package/hooks/active_task_context.py +105 -18
- package/hooks/context_spine.py +16 -4
- package/hooks/health_check.py +5 -4
- package/hooks/pre_stop_check.py +5 -2
- package/hooks/runtime_paths.py +396 -0
- package/hooks/subagent_tracker.py +5 -2
- package/hooks/workflow_checkpoint.py +16 -3
- package/hooks/workflow_context.py +11 -3
- package/hooks/workflow_resume.py +7 -4
- package/mcp-server/breadcrumb.cjs +20 -2
- package/mcp-server/lib/archive-journal.cjs +1026 -111
- package/mcp-server/lib/archive-mutation-worker.py +365 -0
- package/mcp-server/lib/artifact-registry.cjs +1127 -0
- package/mcp-server/lib/baseline-workflow.cjs +69 -28
- package/mcp-server/lib/change-packet.cjs +818 -0
- package/mcp-server/lib/change-workflow.cjs +932 -176
- package/mcp-server/lib/context-paths.cjs +142 -0
- package/mcp-server/lib/context-spine.cjs +511 -45
- package/mcp-server/lib/decision-dialogue.cjs +345 -3
- package/mcp-server/lib/delivery-transaction.cjs +471 -0
- package/mcp-server/lib/doctor-backup-worker.cjs +328 -0
- package/mcp-server/lib/doctor.cjs +401 -11
- package/mcp-server/lib/git-bootstrap.cjs +458 -47
- package/mcp-server/lib/init-project.cjs +240 -95
- package/mcp-server/lib/plan-publication-worker.cjs +830 -0
- package/mcp-server/lib/plan-store.cjs +700 -5
- package/mcp-server/lib/project-breadcrumb.cjs +23 -4
- package/mcp-server/lib/projector.cjs +211 -42
- package/mcp-server/lib/runtime-paths.cjs +1687 -0
- package/mcp-server/lib/safe-project-file.cjs +385 -0
- package/mcp-server/lib/spec-learning.cjs +28 -12
- package/mcp-server/lib/state-authority.cjs +19 -3
- package/mcp-server/lib/state-db.cjs +263 -9
- package/mcp-server/lib/state-ops.cjs +254 -50
- package/mcp-server/lib/task-ledger.cjs +1342 -0
- package/mcp-server/lib/telemetry.cjs +12 -3
- package/mcp-server/lib/workflow-state.cjs +610 -58
- package/mcp-server/server.cjs +423 -42
- package/orchestrator/daemon.cjs +2 -10
- package/orchestrator/parallel-orchestrator.cjs +314 -50
- package/orchestrator/planner/plan-builder.cjs +1 -1
- package/orchestrator/recovery.cjs +125 -7
- package/orchestrator/session-close-journal-worker.cjs +5 -0
- package/orchestrator/session-close-journal.cjs +1014 -0
- package/orchestrator/session-runner.cjs +679 -69
- package/orchestrator/worktree-manager.cjs +186 -35
- package/package.json +2 -3
- package/skills/cc-collab/SKILL.md +4 -1
- package/skills/codex-collab/SKILL.md +5 -2
- package/skills/ultra-change/SKILL.md +34 -8
- package/skills/ultra-deliver/SKILL.md +26 -11
- package/skills/ultra-dev/SKILL.md +52 -10
- package/skills/ultra-doctor/SKILL.md +16 -3
- package/skills/ultra-init/SKILL.md +22 -11
- package/skills/ultra-plan/SKILL.md +58 -18
- package/skills/ultra-research/SKILL.md +37 -35
- package/skills/ultra-review/SKILL.md +14 -8
- package/skills/ultra-status/SKILL.md +18 -9
- package/skills/ultra-test/SKILL.md +11 -5
- package/skills/ultra-think/SKILL.md +6 -2
- package/skills/ultra-think/references/decision-dialogue.md +17 -6
- package/skills/ultra-verify/SKILL.md +4 -1
- package/spec/cli-protocol.md +21 -7
- package/spec/mcp-tools.yaml +629 -44
- package/spec/schemas/change-delta.v1.schema.json +153 -0
- package/spec/schemas/context-file.v4.5.schema.json +1 -1
- package/spec/schemas/documentation-reconciliation.v1.schema.json +106 -0
- package/spec/schemas/mcp-tools.schema.json +1 -1
- package/spec/schemas/state-db.sql +51 -14
- package/spec/schemas/task-ledger.v1.schema.json +217 -0
- package/spec/schemas/tasks.v4.5.schema.json +1 -1
- package/ultra-tools/cli.cjs +3 -2
- package/ultra-tools/commands/db.cjs +76 -25
- package/ultra-tools/commands/migrate.cjs +1000 -82
- package/ultra-tools/commands/session.cjs +34 -8
- package/ultra-tools/commands/status.cjs +32 -6
- package/ultra-tools/commands/system.cjs +129 -22
- package/.ultra-template/tasks/contexts/TEMPLATE.md +0 -19
- package/commands/learn.md +0 -10
- package/orchestrator/skill-miner.cjs +0 -133
- package/output-styles/coding-vibes.md +0 -67
- package/output-styles/structural-thinking.md +0 -61
- package/skills/learn/SKILL.md +0 -58
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('node:crypto');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
|
|
7
|
+
class SafeProjectFileError extends Error {
|
|
8
|
+
constructor(code, message, details = undefined) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'SafeProjectFileError';
|
|
11
|
+
this.code = code;
|
|
12
|
+
if (details !== undefined) this.details = details;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fail(code, message, details = undefined) {
|
|
17
|
+
throw new SafeProjectFileError(code, message, details);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeProjectRelative(value) {
|
|
21
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
22
|
+
fail('PROJECT_FILE_PATH_INVALID', 'project file path is required');
|
|
23
|
+
}
|
|
24
|
+
const raw = value.trim().replaceAll('\\', '/');
|
|
25
|
+
if (path.posix.isAbsolute(raw) || path.win32.isAbsolute(raw)) {
|
|
26
|
+
fail('PROJECT_FILE_PATH_INVALID', 'project file path must be project-relative');
|
|
27
|
+
}
|
|
28
|
+
const relative = path.posix.normalize(raw).replace(/^\.\//, '');
|
|
29
|
+
if (relative === '.' || relative === '..' || relative.startsWith('../')) {
|
|
30
|
+
fail('PROJECT_FILE_PATH_INVALID', `project file path escapes the project: ${value}`);
|
|
31
|
+
}
|
|
32
|
+
return relative;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function identity(stat) {
|
|
36
|
+
return {
|
|
37
|
+
dev: String(stat.dev),
|
|
38
|
+
ino: String(stat.ino),
|
|
39
|
+
mode: stat.mode,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sameIdentity(left, right) {
|
|
44
|
+
return left.dev === right.dev && left.ino === right.ino && left.mode === right.mode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fileVersion(stat) {
|
|
48
|
+
return {
|
|
49
|
+
size: String(stat.size),
|
|
50
|
+
mtime_ns: String(stat.mtimeNs),
|
|
51
|
+
ctime_ns: String(stat.ctimeNs),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function sameFileVersion(left, right) {
|
|
56
|
+
return left.size === right.size
|
|
57
|
+
&& left.mtime_ns === right.mtime_ns
|
|
58
|
+
&& left.ctime_ns === right.ctime_ns;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function inspectProjectRoot(rootDir) {
|
|
62
|
+
const root = path.resolve(rootDir);
|
|
63
|
+
let stat;
|
|
64
|
+
try {
|
|
65
|
+
stat = fs.lstatSync(root);
|
|
66
|
+
} catch (cause) {
|
|
67
|
+
fail('PROJECT_ROOT_UNSAFE', `project root is unavailable: ${root}`, {
|
|
68
|
+
cause: cause.message,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
72
|
+
fail('PROJECT_ROOT_UNSAFE', `project root must be a real directory: ${root}`);
|
|
73
|
+
}
|
|
74
|
+
let physicalRoot;
|
|
75
|
+
try {
|
|
76
|
+
physicalRoot = fs.realpathSync.native(root);
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
fail('PROJECT_ROOT_UNSAFE', `project root cannot be resolved safely: ${root}`, {
|
|
79
|
+
cause: cause.message,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
root,
|
|
84
|
+
physicalRoot,
|
|
85
|
+
rootIdentity: identity(stat),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function inspectProjectFile(rootDir, candidate) {
|
|
90
|
+
const relative = normalizeProjectRelative(candidate);
|
|
91
|
+
const project = inspectProjectRoot(rootDir);
|
|
92
|
+
const components = relative.split('/').filter(Boolean);
|
|
93
|
+
const identities = [{
|
|
94
|
+
file: project.root,
|
|
95
|
+
relative: '.',
|
|
96
|
+
kind: 'directory',
|
|
97
|
+
...project.rootIdentity,
|
|
98
|
+
}];
|
|
99
|
+
let current = project.physicalRoot;
|
|
100
|
+
for (let index = 0; index < components.length; index += 1) {
|
|
101
|
+
current = path.join(current, components[index]);
|
|
102
|
+
const final = index === components.length - 1;
|
|
103
|
+
let stat;
|
|
104
|
+
try {
|
|
105
|
+
stat = fs.lstatSync(current);
|
|
106
|
+
} catch (cause) {
|
|
107
|
+
if (cause?.code === 'ENOENT' || cause?.code === 'ENOTDIR') {
|
|
108
|
+
fail('PROJECT_FILE_MISSING', `project file does not exist: ${relative}`);
|
|
109
|
+
}
|
|
110
|
+
fail('PROJECT_FILE_UNSAFE', `project file cannot be inspected safely: ${relative}`, {
|
|
111
|
+
component: components.slice(0, index + 1).join('/'),
|
|
112
|
+
cause: cause.message,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (stat.isSymbolicLink()) {
|
|
116
|
+
fail('PROJECT_FILE_UNSAFE', `project file path contains a symbolic link: ${relative}`, {
|
|
117
|
+
component: components.slice(0, index + 1).join('/'),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (final ? !stat.isFile() : !stat.isDirectory()) {
|
|
121
|
+
fail(
|
|
122
|
+
'PROJECT_FILE_UNSAFE',
|
|
123
|
+
`project file path contains a non-regular ${final ? 'file' : 'ancestor'}: ${relative}`,
|
|
124
|
+
{ component: components.slice(0, index + 1).join('/') },
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
let physical;
|
|
128
|
+
try {
|
|
129
|
+
physical = fs.realpathSync.native(current);
|
|
130
|
+
} catch (cause) {
|
|
131
|
+
fail('PROJECT_FILE_UNSAFE', `project file cannot be resolved safely: ${relative}`, {
|
|
132
|
+
component: components.slice(0, index + 1).join('/'),
|
|
133
|
+
cause: cause.message,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (physical !== project.physicalRoot
|
|
137
|
+
&& !physical.startsWith(`${project.physicalRoot}${path.sep}`)) {
|
|
138
|
+
fail('PROJECT_FILE_UNSAFE', `project file escapes the physical project root: ${relative}`, {
|
|
139
|
+
component: components.slice(0, index + 1).join('/'),
|
|
140
|
+
physical,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
identities.push({
|
|
144
|
+
file: current,
|
|
145
|
+
relative: components.slice(0, index + 1).join('/'),
|
|
146
|
+
kind: final ? 'file' : 'directory',
|
|
147
|
+
...identity(stat),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
...project,
|
|
152
|
+
relative,
|
|
153
|
+
file: current,
|
|
154
|
+
identities,
|
|
155
|
+
final: identities.at(-1),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function verifyProjectFileSnapshot(before, fd) {
|
|
160
|
+
const after = inspectProjectFile(before.root, before.relative);
|
|
161
|
+
let opened;
|
|
162
|
+
try {
|
|
163
|
+
opened = fs.fstatSync(fd);
|
|
164
|
+
} catch (cause) {
|
|
165
|
+
fail('PROJECT_FILE_UNSAFE', `project file descriptor is unavailable: ${before.relative}`, {
|
|
166
|
+
cause: cause.message,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (!opened.isFile()
|
|
170
|
+
|| !sameIdentity(identity(opened), before.final)
|
|
171
|
+
|| before.identities.length !== after.identities.length
|
|
172
|
+
|| before.identities.some((entry, index) => (
|
|
173
|
+
entry.relative !== after.identities[index].relative
|
|
174
|
+
|| entry.kind !== after.identities[index].kind
|
|
175
|
+
|| !sameIdentity(entry, after.identities[index])
|
|
176
|
+
))) {
|
|
177
|
+
fail('PROJECT_FILE_UNSAFE', `project file path changed identity while it was read: ${before.relative}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function readStableFdSnapshot(fd, relative) {
|
|
182
|
+
let before;
|
|
183
|
+
try {
|
|
184
|
+
before = fs.fstatSync(fd, { bigint: true });
|
|
185
|
+
} catch (cause) {
|
|
186
|
+
fail('PROJECT_FILE_UNSAFE', `project file descriptor is unavailable: ${relative}`, {
|
|
187
|
+
cause: cause.message,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (!before.isFile()) {
|
|
191
|
+
fail('PROJECT_FILE_UNSAFE', `project file descriptor is not a regular file: ${relative}`);
|
|
192
|
+
}
|
|
193
|
+
const size = Number(before.size);
|
|
194
|
+
if (!Number.isSafeInteger(size) || size < 0) {
|
|
195
|
+
fail('PROJECT_FILE_UNSAFE', `project file is too large to read safely: ${relative}`);
|
|
196
|
+
}
|
|
197
|
+
const bytes = Buffer.allocUnsafe(size);
|
|
198
|
+
let offset = 0;
|
|
199
|
+
while (offset < size) {
|
|
200
|
+
const count = fs.readSync(fd, bytes, offset, size - offset, offset);
|
|
201
|
+
if (count === 0) {
|
|
202
|
+
fail('PROJECT_FILE_CHANGED', `project file changed while it was read: ${relative}`);
|
|
203
|
+
}
|
|
204
|
+
offset += count;
|
|
205
|
+
}
|
|
206
|
+
const overflow = Buffer.allocUnsafe(1);
|
|
207
|
+
if (fs.readSync(fd, overflow, 0, 1, size) !== 0) {
|
|
208
|
+
fail('PROJECT_FILE_CHANGED', `project file changed while it was read: ${relative}`);
|
|
209
|
+
}
|
|
210
|
+
const after = fs.fstatSync(fd, { bigint: true });
|
|
211
|
+
const beforeVersion = fileVersion(before);
|
|
212
|
+
const afterVersion = fileVersion(after);
|
|
213
|
+
if (!after.isFile() || !sameFileVersion(beforeVersion, afterVersion)) {
|
|
214
|
+
fail('PROJECT_FILE_CHANGED', `project file changed while it was read: ${relative}`, {
|
|
215
|
+
before: beforeVersion,
|
|
216
|
+
after: afterVersion,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
bytes,
|
|
221
|
+
version: afterVersion,
|
|
222
|
+
digest: crypto.createHash('sha256').update(bytes).digest('hex'),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function openStableProjectRead(rootDir, candidate) {
|
|
227
|
+
const snapshot = inspectProjectFile(rootDir, candidate);
|
|
228
|
+
let fd;
|
|
229
|
+
try {
|
|
230
|
+
fd = fs.openSync(
|
|
231
|
+
snapshot.file,
|
|
232
|
+
fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW || 0),
|
|
233
|
+
);
|
|
234
|
+
verifyProjectFileSnapshot(snapshot, fd);
|
|
235
|
+
const initial = readStableFdSnapshot(fd, snapshot.relative);
|
|
236
|
+
verifyProjectFileSnapshot(snapshot, fd);
|
|
237
|
+
return {
|
|
238
|
+
root: snapshot.root,
|
|
239
|
+
physicalRoot: snapshot.physicalRoot,
|
|
240
|
+
relative: snapshot.relative,
|
|
241
|
+
file: snapshot.file,
|
|
242
|
+
bytes: initial.bytes,
|
|
243
|
+
digest: initial.digest,
|
|
244
|
+
verify() {
|
|
245
|
+
verifyProjectFileSnapshot(snapshot, fd);
|
|
246
|
+
const current = readStableFdSnapshot(fd, snapshot.relative);
|
|
247
|
+
if (!sameFileVersion(initial.version, current.version)
|
|
248
|
+
|| initial.digest !== current.digest) {
|
|
249
|
+
fail('PROJECT_FILE_CHANGED', `project file changed after it was read: ${snapshot.relative}`, {
|
|
250
|
+
expected_digest: initial.digest,
|
|
251
|
+
actual_digest: current.digest,
|
|
252
|
+
expected_version: initial.version,
|
|
253
|
+
actual_version: current.version,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
verifyProjectFileSnapshot(snapshot, fd);
|
|
257
|
+
},
|
|
258
|
+
close() {
|
|
259
|
+
if (fd !== undefined) {
|
|
260
|
+
fs.closeSync(fd);
|
|
261
|
+
fd = undefined;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (fd !== undefined) fs.closeSync(fd);
|
|
267
|
+
if (error instanceof SafeProjectFileError) throw error;
|
|
268
|
+
if (error?.code === 'ENOENT') {
|
|
269
|
+
fail('PROJECT_FILE_MISSING', `project file does not exist: ${snapshot.relative}`);
|
|
270
|
+
}
|
|
271
|
+
fail(
|
|
272
|
+
'PROJECT_FILE_UNSAFE',
|
|
273
|
+
`project file cannot be opened without following links: ${snapshot.relative}`,
|
|
274
|
+
{ cause: error.message },
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function readStableProjectFile(rootDir, candidate, { encoding = null } = {}) {
|
|
280
|
+
const reader = openStableProjectRead(rootDir, candidate);
|
|
281
|
+
try {
|
|
282
|
+
reader.verify();
|
|
283
|
+
return {
|
|
284
|
+
root: reader.root,
|
|
285
|
+
physicalRoot: reader.physicalRoot,
|
|
286
|
+
relative: reader.relative,
|
|
287
|
+
file: reader.file,
|
|
288
|
+
bytes: reader.bytes,
|
|
289
|
+
text: encoding ? reader.bytes.toString(encoding) : null,
|
|
290
|
+
digest: reader.digest,
|
|
291
|
+
};
|
|
292
|
+
} finally {
|
|
293
|
+
reader.close();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function walkStableProjectTree(rootDir, candidate, {
|
|
298
|
+
ignore = () => false,
|
|
299
|
+
} = {}) {
|
|
300
|
+
const relativeRoot = normalizeProjectRelative(candidate);
|
|
301
|
+
const project = inspectProjectRoot(rootDir);
|
|
302
|
+
const absoluteRoot = path.join(project.physicalRoot, ...relativeRoot.split('/'));
|
|
303
|
+
let rootStat;
|
|
304
|
+
try {
|
|
305
|
+
rootStat = fs.lstatSync(absoluteRoot);
|
|
306
|
+
} catch (cause) {
|
|
307
|
+
if (cause?.code === 'ENOENT') return { files: [], unsafe: [] };
|
|
308
|
+
return {
|
|
309
|
+
files: [],
|
|
310
|
+
unsafe: [{ path: relativeRoot, reason: cause.message }],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) {
|
|
314
|
+
return {
|
|
315
|
+
files: [],
|
|
316
|
+
unsafe: [{
|
|
317
|
+
path: relativeRoot,
|
|
318
|
+
reason: rootStat.isSymbolicLink()
|
|
319
|
+
? 'tree root is a symbolic link'
|
|
320
|
+
: 'tree root is not a directory',
|
|
321
|
+
}],
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const files = [];
|
|
325
|
+
const unsafe = [];
|
|
326
|
+
|
|
327
|
+
const visit = (directory, relative, expected) => {
|
|
328
|
+
let entries;
|
|
329
|
+
try {
|
|
330
|
+
const before = fs.lstatSync(directory);
|
|
331
|
+
if (before.isSymbolicLink() || !before.isDirectory()
|
|
332
|
+
|| !sameIdentity(identity(before), expected)) {
|
|
333
|
+
unsafe.push({ path: relative, reason: 'directory identity changed' });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
337
|
+
const after = fs.lstatSync(directory);
|
|
338
|
+
if (after.isSymbolicLink() || !after.isDirectory()
|
|
339
|
+
|| !sameIdentity(identity(after), expected)) {
|
|
340
|
+
unsafe.push({ path: relative, reason: 'directory identity changed while listed' });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
} catch (cause) {
|
|
344
|
+
unsafe.push({ path: relative, reason: cause.message });
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
for (const entry of entries) {
|
|
348
|
+
const childRelative = `${relative}/${entry.name}`;
|
|
349
|
+
const child = path.join(directory, entry.name);
|
|
350
|
+
let stat;
|
|
351
|
+
try {
|
|
352
|
+
stat = fs.lstatSync(child);
|
|
353
|
+
} catch (cause) {
|
|
354
|
+
unsafe.push({ path: childRelative, reason: cause.message });
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (stat.isSymbolicLink()) {
|
|
358
|
+
unsafe.push({ path: childRelative, reason: 'tree entry is a symbolic link' });
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (ignore(childRelative, entry, stat)) continue;
|
|
362
|
+
if (stat.isDirectory()) {
|
|
363
|
+
visit(child, childRelative, identity(stat));
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (!stat.isFile()) {
|
|
367
|
+
unsafe.push({ path: childRelative, reason: 'tree entry is not a regular file' });
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
files.push(childRelative);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
visit(absoluteRoot, relativeRoot, identity(rootStat));
|
|
375
|
+
return { files, unsafe };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
module.exports = {
|
|
379
|
+
SafeProjectFileError,
|
|
380
|
+
inspectProjectFile,
|
|
381
|
+
normalizeProjectRelative,
|
|
382
|
+
openStableProjectRead,
|
|
383
|
+
readStableProjectFile,
|
|
384
|
+
walkStableProjectTree,
|
|
385
|
+
};
|
|
@@ -5,6 +5,7 @@ const fs = require('node:fs');
|
|
|
5
5
|
const path = require('node:path');
|
|
6
6
|
|
|
7
7
|
const ops = require('./state-ops.cjs');
|
|
8
|
+
const artifacts = require('./artifact-registry.cjs');
|
|
8
9
|
|
|
9
10
|
const CANDIDATE_ID = /^[a-zA-Z0-9_-]+$/;
|
|
10
11
|
const TRANSITIONS = Object.freeze({
|
|
@@ -66,7 +67,7 @@ function upsertProjectionArtifact(db, change, rootDir, candidates) {
|
|
|
66
67
|
), '1970-01-01T00:00:00.000Z');
|
|
67
68
|
const payload = {
|
|
68
69
|
schema_version: '1.0',
|
|
69
|
-
source: '.ultra/state.db',
|
|
70
|
+
source: '.ultra/.runtime/state.db',
|
|
70
71
|
change_id: change.id,
|
|
71
72
|
generated_at: generatedAt,
|
|
72
73
|
candidates,
|
|
@@ -75,17 +76,32 @@ function upsertProjectionArtifact(db, change, rootDir, candidates) {
|
|
|
75
76
|
writeAtomic(file, serialized);
|
|
76
77
|
const relative = path.relative(rootDir, file);
|
|
77
78
|
const hash = crypto.createHash('sha256').update(serialized).digest('hex');
|
|
78
|
-
db.prepare(
|
|
79
|
-
`
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
)
|
|
79
|
+
const workflow = db.prepare(
|
|
80
|
+
`SELECT id FROM workflow_runs WHERE change_id = ?
|
|
81
|
+
ORDER BY started_at DESC, rowid DESC LIMIT 1`,
|
|
82
|
+
).get(change.id);
|
|
83
|
+
if (!workflow) {
|
|
84
|
+
throw new SpecLearningError(
|
|
85
|
+
'ARTIFACT_CONSUMER_MISSING',
|
|
86
|
+
`change ${change.id} has no workflow consumer for spec learning`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const taskConsumers = [...new Set(candidates.map((candidate) => candidate.task_id).filter(Boolean))]
|
|
90
|
+
.map((taskId) => ({ type: 'task', id: taskId, relation: 'consumed_by' }));
|
|
91
|
+
artifacts.recordArtifactInTx(db, {
|
|
92
|
+
owner_type: 'change',
|
|
93
|
+
owner_id: change.id,
|
|
94
|
+
kind: 'spec_learning',
|
|
95
|
+
path: relative,
|
|
96
|
+
content_digest: hash,
|
|
97
|
+
source_refs: [{ type: 'change', id: change.id, relation: 'produced_for' }],
|
|
98
|
+
consumer_refs: [
|
|
99
|
+
{ type: 'workflow', id: workflow.id, relation: 'consumed_by' },
|
|
100
|
+
...taskConsumers,
|
|
101
|
+
],
|
|
102
|
+
provenance: { writer: 'spec-learning', workflow_run_id: workflow.id },
|
|
103
|
+
metadata: { candidates: candidates.length },
|
|
104
|
+
}, { rootDir });
|
|
89
105
|
return { path: file, hash };
|
|
90
106
|
}
|
|
91
107
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
4
|
const path = require('node:path');
|
|
5
|
+
const taskLedger = require('./task-ledger.cjs');
|
|
5
6
|
|
|
6
7
|
class StateAuthorityError extends Error {
|
|
7
8
|
constructor(code, message, details) {
|
|
@@ -32,24 +33,39 @@ function inspectProjection(rootDir) {
|
|
|
32
33
|
{ projection_path: projectionPath },
|
|
33
34
|
);
|
|
34
35
|
}
|
|
36
|
+
if (projection.kind === taskLedger.LEDGER_KIND) {
|
|
37
|
+
const ledger = taskLedger.validateLedger(projection, projectionPath);
|
|
38
|
+
return {
|
|
39
|
+
path: projectionPath,
|
|
40
|
+
version: ledger.schema_version,
|
|
41
|
+
kind: ledger.kind,
|
|
42
|
+
taskCount: ledger.tasks.length,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
35
45
|
return {
|
|
36
46
|
path: projectionPath,
|
|
37
47
|
version: String(projection.version || projection.schema_version || 'unknown'),
|
|
48
|
+
kind: 'legacy-task-projection',
|
|
38
49
|
taskCount: projection.tasks.length,
|
|
39
50
|
};
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
function assertStateAuthority(db, rootDir) {
|
|
53
|
+
function assertStateAuthority(db, rootDir, { importTeamLedger = false } = {}) {
|
|
43
54
|
const authoritativeCount = db.prepare('SELECT COUNT(*) AS count FROM tasks').get().count;
|
|
44
|
-
if (authoritativeCount > 0) return;
|
|
45
55
|
const projection = inspectProjection(rootDir);
|
|
46
|
-
if (
|
|
56
|
+
if (projection?.kind === taskLedger.LEDGER_KIND) {
|
|
57
|
+
return importTeamLedger
|
|
58
|
+
? taskLedger.syncTaskLedger(db, { rootDir })
|
|
59
|
+
: taskLedger.inspectTaskLedger(db, { rootDir });
|
|
60
|
+
}
|
|
61
|
+
if (authoritativeCount > 0 || !projection || projection.taskCount === 0) return null;
|
|
47
62
|
|
|
48
63
|
const details = {
|
|
49
64
|
authoritative_task_count: authoritativeCount,
|
|
50
65
|
legacy_task_count: projection.taskCount,
|
|
51
66
|
projection_path: projection.path,
|
|
52
67
|
projection_version: projection.version,
|
|
68
|
+
projection_kind: projection.kind,
|
|
53
69
|
};
|
|
54
70
|
const migrationTargets = {
|
|
55
71
|
'4.4': '4.5',
|