@planu/cli 8.2.17 → 8.2.18
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/CHANGELOG.md +12 -0
- package/README.md +14 -2
- package/dist/sdd-engine/completion-guard.d.ts +28 -0
- package/dist/sdd-engine/completion-guard.js +320 -0
- package/dist/sdd-engine/completion-snapshot.d.ts +11 -0
- package/dist/sdd-engine/completion-snapshot.js +155 -0
- package/dist/sdd-engine/feature-authority.d.ts +20 -0
- package/dist/sdd-engine/feature-authority.js +199 -0
- package/dist/sdd-engine/feature-manifest.d.ts +6 -0
- package/dist/sdd-engine/feature-manifest.js +116 -0
- package/dist/sdd-engine/host-rule-pack.d.ts +1 -0
- package/dist/sdd-engine/host-rule-pack.js +63 -7
- package/dist/sdd-engine/lock-integrity.d.ts +3 -18
- package/dist/sdd-engine/lock-integrity.js +192 -217
- package/dist/sdd-engine/patch-sandbox.js +1 -1
- package/dist/sdd-engine/server.js +4 -6
- package/dist/sdd-engine/task-content.d.ts +8 -0
- package/dist/sdd-engine/task-content.js +132 -0
- package/dist/sdd-engine/task-failures.d.ts +12 -0
- package/dist/sdd-engine/task-failures.js +125 -0
- package/dist/sdd-engine/task-window.d.ts +10 -4
- package/dist/sdd-engine/task-window.js +177 -246
- package/dist/sdd-engine/tools/execution-tools.js +29 -26
- package/dist/sdd-engine/tools/feature-store.d.ts +11 -0
- package/dist/sdd-engine/tools/feature-store.js +224 -0
- package/dist/sdd-engine/tools/workspace-tools.js +65 -127
- package/dist/sdd-engine/workspace-root.d.ts +3 -1
- package/dist/sdd-engine/workspace-root.js +69 -3
- package/dist/types/completion.d.ts +77 -0
- package/dist/types/completion.js +2 -0
- package/package.json +2 -2
- package/templates/AGENTS.md +4 -0
- package/templates/host/planu-sdd.md +4 -0
|
@@ -1,234 +1,199 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { constants as fsConstants } from 'node:fs';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
missing.push('out_of_scope');
|
|
13
|
-
}
|
|
14
|
-
if (!hasHeading(specContent, 'Error Matrix')) {
|
|
15
|
-
missing.push('error_matrix');
|
|
16
|
-
}
|
|
17
|
-
if (!BDD_KEYWORDS.every((keyword) => keyword.test(specContent))) {
|
|
18
|
-
missing.push('bdd');
|
|
19
|
-
}
|
|
20
|
-
if (!hasHeading(planContent, 'Frozen Dependencies')) {
|
|
21
|
-
missing.push('frozen_dependencies');
|
|
22
|
-
}
|
|
23
|
-
const hasTask = tasksContent.split('\n').some((line) => CHECKBOX_TASK.test(line.trim()));
|
|
24
|
-
const manifest = scanManifest(planContent);
|
|
25
|
-
if (!manifest.hasPath) {
|
|
26
|
-
missing.push('manifest_path');
|
|
27
|
-
}
|
|
28
|
-
if (!hasTask) {
|
|
29
|
-
missing.push('checkbox_task');
|
|
30
|
-
}
|
|
31
|
-
if (manifest.globDelete) {
|
|
32
|
-
return {
|
|
33
|
-
ok: false,
|
|
34
|
-
code: 'ERR_TRINITY_INCOMPLETE',
|
|
35
|
-
message: 'DELETE File Manifest entries must be exact paths, not globs.',
|
|
36
|
-
};
|
|
4
|
+
import { CompletionGuardError, captureDirectories, lastAuthorityDirectory, checkWritable, guardFailure, hashArtifact, readArtifact, readFeatureArtifact, revalidateDirectories, rewriteArtifact, sameIdentity, } from './feature-authority.js';
|
|
5
|
+
import { acquireCompletionLease, claimStoppedCompletion, inspectCompletionGuard, } from './completion-guard.js';
|
|
6
|
+
import { captureCompletionSnapshot } from './completion-snapshot.js';
|
|
7
|
+
import { assessTrinityCompleteness, parseManifestContent } from './feature-manifest.js';
|
|
8
|
+
export async function verifyLockedTrinity(featDir) {
|
|
9
|
+
try {
|
|
10
|
+
await captureCompletionSnapshot(featDir);
|
|
11
|
+
return { ok: true };
|
|
37
12
|
}
|
|
38
|
-
|
|
13
|
+
catch (error) {
|
|
14
|
+
const missingLock = (error instanceof CompletionGuardError && error.code === 'ERR_SPEC_NOT_LOCKED') ||
|
|
15
|
+
(error.code === 'ENOENT' &&
|
|
16
|
+
path.basename(error.path ?? '') === '.lock');
|
|
39
17
|
return {
|
|
40
18
|
ok: false,
|
|
41
|
-
code: '
|
|
42
|
-
message:
|
|
19
|
+
code: missingLock ? 'ERR_SPEC_NOT_LOCKED' : 'ERR_SPEC_DRIFT',
|
|
20
|
+
message: missingLock
|
|
21
|
+
? 'Feature spec must be locked before execution.'
|
|
22
|
+
: 'Locked artifacts are unsafe, unreadable, or changed after sdd_lock_spec. Re-lock is required.',
|
|
43
23
|
};
|
|
44
24
|
}
|
|
45
|
-
if (missing.length === 0) {
|
|
46
|
-
return { ok: true };
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
ok: false,
|
|
50
|
-
code: 'ERR_TRINITY_INCOMPLETE',
|
|
51
|
-
message: 'Lock requires Out-of-Scope, Error Matrix, GIVEN/WHEN/THEN acceptance criteria, Frozen Dependencies, a File Manifest path, and at least one checkbox task.',
|
|
52
|
-
details: { missing },
|
|
53
|
-
};
|
|
54
25
|
}
|
|
55
|
-
export async function
|
|
26
|
+
export async function writeLockedTrinity(requestedFeatDir, featureId, relock, reason) {
|
|
27
|
+
const featDir = lastAuthorityDirectory(await captureDirectories(requestedFeatDir)).directory;
|
|
56
28
|
const lockPath = path.join(featDir, '.lock');
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
raw = await fs.readFile(lockPath, 'utf-8');
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
29
|
+
const lockExists = await lockAlreadyExists(lockPath);
|
|
30
|
+
if (lockExists && !relock) {
|
|
62
31
|
return {
|
|
63
32
|
ok: false,
|
|
64
|
-
code: '
|
|
65
|
-
message: `Feature
|
|
33
|
+
code: 'ERR_SPEC_ALREADY_LOCKED',
|
|
34
|
+
message: `Feature '${featureId}' is already locked for execution.`,
|
|
66
35
|
};
|
|
67
36
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
lock = JSON.parse(raw);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
37
|
+
const trimmedReason = reason?.trim() ?? '';
|
|
38
|
+
if (relock && trimmedReason.length < 8) {
|
|
73
39
|
return {
|
|
74
40
|
ok: false,
|
|
75
|
-
code: '
|
|
76
|
-
message:
|
|
41
|
+
code: 'ERR_LOCK_REASON_REQUIRED',
|
|
42
|
+
message: 'relock requires reason with at least 8 non-whitespace characters.',
|
|
77
43
|
};
|
|
78
44
|
}
|
|
79
|
-
let
|
|
80
|
-
let
|
|
45
|
+
let lease;
|
|
46
|
+
let recovering = false;
|
|
81
47
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
48
|
+
const guard = await inspectCompletionGuard(featDir);
|
|
49
|
+
recovering = guard !== null && relock;
|
|
50
|
+
lease = recovering
|
|
51
|
+
? await claimStoppedCompletion(featDir)
|
|
52
|
+
: await acquireCompletionLease(featDir, { operation: 'lock' });
|
|
53
|
+
const outcome = await sealTrinityArtifacts(featDir, featureId, lockPath, lockExists, relock, trimmedReason, lease);
|
|
54
|
+
if (recovering && !outcome.ok) {
|
|
55
|
+
lease.retain();
|
|
56
|
+
}
|
|
57
|
+
return outcome;
|
|
84
58
|
}
|
|
85
|
-
catch {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (recovering) {
|
|
61
|
+
lease?.retain();
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
91
64
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
ok: false,
|
|
95
|
-
code: 'ERR_SPEC_DRIFT',
|
|
96
|
-
message: 'Locked spec.md or plan.md changed after sdd_lock_spec. Re-lock is required.',
|
|
97
|
-
};
|
|
65
|
+
finally {
|
|
66
|
+
await lease?.release();
|
|
98
67
|
}
|
|
99
|
-
|
|
68
|
+
}
|
|
69
|
+
async function readTrinity(featDir, featureId) {
|
|
70
|
+
try {
|
|
71
|
+
const spec = await readArtifact(featDir, 'spec.md');
|
|
72
|
+
const plan = await readArtifact(featDir, 'plan.md');
|
|
73
|
+
const tasks = await readArtifact(featDir, 'tasks.md');
|
|
74
|
+
return { 'spec.md': spec, 'plan.md': plan, 'tasks.md': tasks };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof CompletionGuardError) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
100
80
|
return {
|
|
101
81
|
ok: false,
|
|
102
|
-
code: '
|
|
103
|
-
message:
|
|
82
|
+
code: 'ERR_FEATURE_NOT_FOUND',
|
|
83
|
+
message: `Failed to read base artifacts for '${featureId}'.`,
|
|
104
84
|
};
|
|
105
85
|
}
|
|
106
|
-
|
|
86
|
+
}
|
|
87
|
+
async function readPreviousLock(featDir, lockPath, lockExists) {
|
|
88
|
+
if (!lockExists) {
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
const artifact = await readArtifact(featDir, '.lock');
|
|
92
|
+
checkWritable(await fs.lstat(lockPath));
|
|
93
|
+
let previous;
|
|
107
94
|
try {
|
|
108
|
-
|
|
95
|
+
previous = JSON.parse(artifact.content);
|
|
109
96
|
}
|
|
110
97
|
catch {
|
|
111
|
-
return
|
|
112
|
-
ok: false,
|
|
113
|
-
code: 'ERR_SPEC_DRIFT',
|
|
114
|
-
message: 'Locked tasks.md is missing after sdd_lock_spec. Re-lock is required.',
|
|
115
|
-
};
|
|
98
|
+
return guardFailure('contract_drift', 'A malformed lock cannot be silently resealed. Reconcile the actual evidence first.');
|
|
116
99
|
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
100
|
+
if (!previous ||
|
|
101
|
+
typeof previous !== 'object' ||
|
|
102
|
+
Array.isArray(previous) ||
|
|
103
|
+
('relockHistory' in previous &&
|
|
104
|
+
previous.relockHistory !== undefined &&
|
|
105
|
+
!Array.isArray(previous.relockHistory))) {
|
|
106
|
+
guardFailure('contract_drift', 'Existing lock history is malformed; it was retained.');
|
|
123
107
|
}
|
|
124
|
-
return {
|
|
108
|
+
return { previous, artifact };
|
|
125
109
|
}
|
|
126
|
-
function
|
|
127
|
-
const
|
|
128
|
-
|
|
110
|
+
function prepareLock(captured, previous, relock, trimmedReason) {
|
|
111
|
+
const specHash = hashArtifact(captured['spec.md'].content);
|
|
112
|
+
const planHash = hashArtifact(captured['plan.md'].content);
|
|
113
|
+
const tasksHash = hashArtifact(captured['tasks.md'].content);
|
|
114
|
+
const lockedAt = new Date().toISOString();
|
|
115
|
+
const history = [...(previous?.relockHistory ?? [])];
|
|
116
|
+
if (relock && previous?.specHash && previous.planHash) {
|
|
117
|
+
history.push({
|
|
118
|
+
lockedAt: previous.lockedAt ?? lockedAt,
|
|
119
|
+
specHash: previous.specHash,
|
|
120
|
+
planHash: previous.planHash,
|
|
121
|
+
tasksHash: previous.tasksHash,
|
|
122
|
+
reason: trimmedReason,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
...previous,
|
|
127
|
+
lockedAt,
|
|
128
|
+
specHash,
|
|
129
|
+
planHash,
|
|
130
|
+
tasksHash,
|
|
131
|
+
...(history.length > 0 ? { relockHistory: history } : {}),
|
|
132
|
+
};
|
|
129
133
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
const normalized = path.posix.normalize(entryPath).toLowerCase();
|
|
140
|
-
if (permission !== 'READ_ONLY' &&
|
|
141
|
-
protectedWrite === null &&
|
|
142
|
-
PROTECTED_ROOTS.some((root) => normalized === root || normalized.startsWith(`${root}/`))) {
|
|
143
|
-
protectedWrite = entryPath;
|
|
134
|
+
async function revalidateReseal(featDir, directories, captured) {
|
|
135
|
+
await revalidateDirectories(directories);
|
|
136
|
+
for (const name of ['spec.md', 'plan.md', 'tasks.md']) {
|
|
137
|
+
const current = await readArtifact(featDir, name);
|
|
138
|
+
const expected = captured[name];
|
|
139
|
+
if (current.content !== expected.content ||
|
|
140
|
+
!sameIdentity(current.identity, expected.identity)) {
|
|
141
|
+
guardFailure('contract_drift', 'Trinity changed before reviewed reseal.');
|
|
144
142
|
}
|
|
145
143
|
}
|
|
146
|
-
return { hasPath: allowedFiles.size > 0, globDelete, protectedWrite };
|
|
147
144
|
}
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
if (inManifestSection && /^[-*]\s+/.test(line)) {
|
|
158
|
-
parseManifestLine(line, allowedFiles);
|
|
159
|
-
}
|
|
145
|
+
async function createLock(lockPath, serialized) {
|
|
146
|
+
const handle = await fs.open(lockPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_WRONLY | fsConstants.O_NOFOLLOW, 0o600);
|
|
147
|
+
try {
|
|
148
|
+
await handle.writeFile(serialized, 'utf8');
|
|
149
|
+
await handle.sync();
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
await handle.close();
|
|
160
153
|
}
|
|
161
|
-
return { allowedFiles };
|
|
162
154
|
}
|
|
163
|
-
function
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const prefixPath = toPosixPath(prefixMatch[2].trim());
|
|
168
|
-
if (prefixPath.toLowerCase() === 'none') {
|
|
169
|
-
return;
|
|
155
|
+
function validateResealReadback(readback, captured, previousArtifact, serialized) {
|
|
156
|
+
for (const name of ['spec.md', 'plan.md', 'tasks.md']) {
|
|
157
|
+
if (!sameIdentity(readback.artifacts[name].identity, captured[name].identity)) {
|
|
158
|
+
guardFailure('persistence_uncertain', 'Reviewed reseal readback identity changed.');
|
|
170
159
|
}
|
|
171
|
-
allowedFiles.set(prefixPath, prefixMatch[1].toUpperCase());
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const postfixMatch = /^`?([^`\s:#]+)`?:\s*(CREATE|MODIFY|READ_ONLY|DELETE)\s*$/i.exec(item);
|
|
175
|
-
if (postfixMatch?.[1] && postfixMatch[2]) {
|
|
176
|
-
const postfixPath = toPosixPath(postfixMatch[1].trim());
|
|
177
|
-
if (postfixPath.toLowerCase() === 'none') {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
allowedFiles.set(postfixPath, postfixMatch[2].toUpperCase());
|
|
181
160
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const absolute = posix.startsWith('/');
|
|
186
|
-
const joined = posix
|
|
187
|
-
.split('/')
|
|
188
|
-
.filter((part) => part !== '' && part !== '.')
|
|
189
|
-
.join('/');
|
|
190
|
-
return absolute ? `/${joined}` : joined;
|
|
191
|
-
}
|
|
192
|
-
export async function writeLockedTrinity(featDir, featureId, relock, reason) {
|
|
193
|
-
const lockPath = path.join(featDir, '.lock');
|
|
194
|
-
const lockExists = await fs
|
|
195
|
-
.access(lockPath)
|
|
196
|
-
.then(() => true)
|
|
197
|
-
.catch(() => false);
|
|
198
|
-
if (lockExists && !relock) {
|
|
199
|
-
return {
|
|
200
|
-
ok: false,
|
|
201
|
-
code: 'ERR_SPEC_ALREADY_LOCKED',
|
|
202
|
-
message: `Feature '${featureId}' is already locked for execution.`,
|
|
203
|
-
};
|
|
161
|
+
if (previousArtifact &&
|
|
162
|
+
!sameIdentity(readback.artifacts['.lock'].identity, previousArtifact.identity)) {
|
|
163
|
+
guardFailure('persistence_uncertain', 'Reviewed lock identity changed.');
|
|
204
164
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
message: 'relock requires reason with at least 8 non-whitespace characters.',
|
|
211
|
-
};
|
|
165
|
+
if (readback.specContent !== captured['spec.md'].content ||
|
|
166
|
+
readback.planContent !== captured['plan.md'].content ||
|
|
167
|
+
readback.tasksContent !== captured['tasks.md'].content ||
|
|
168
|
+
readback.lockContent !== serialized) {
|
|
169
|
+
guardFailure('persistence_uncertain', 'Reviewed reseal readback does not match actual bytes.');
|
|
212
170
|
}
|
|
213
|
-
return sealTrinityArtifacts(featDir, featureId, lockPath, lockExists, relock, trimmedReason);
|
|
214
171
|
}
|
|
215
|
-
async function
|
|
216
|
-
let specContent;
|
|
217
|
-
let planContent;
|
|
218
|
-
let tasksContent;
|
|
172
|
+
async function persistReseal(featDir, lockPath, directories, captured, previousArtifact, serialized, lease) {
|
|
219
173
|
try {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
174
|
+
if (previousArtifact) {
|
|
175
|
+
await rewriteArtifact(featDir, '.lock', previousArtifact, serialized);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
await createLock(lockPath, serialized);
|
|
179
|
+
}
|
|
180
|
+
await revalidateDirectories(directories);
|
|
181
|
+
const readback = await captureCompletionSnapshot(featDir);
|
|
182
|
+
await revalidateDirectories(directories);
|
|
183
|
+
validateResealReadback(readback, captured, previousArtifact, serialized);
|
|
223
184
|
}
|
|
224
185
|
catch {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
186
|
+
lease.retain();
|
|
187
|
+
guardFailure('persistence_uncertain', 'Lock persistence is uncertain; reviewed stopped-owner relock is required.');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function sealTrinityArtifacts(featDir, featureId, lockPath, lockExists, relock, trimmedReason, lease) {
|
|
191
|
+
const directories = await captureDirectories(featDir);
|
|
192
|
+
const captured = await readTrinity(featDir, featureId);
|
|
193
|
+
if ('ok' in captured) {
|
|
194
|
+
return captured;
|
|
230
195
|
}
|
|
231
|
-
const completeness = assessTrinityCompleteness(
|
|
196
|
+
const completeness = assessTrinityCompleteness(captured['spec.md'].content, captured['plan.md'].content, captured['tasks.md'].content);
|
|
232
197
|
if (!completeness.ok) {
|
|
233
198
|
return {
|
|
234
199
|
ok: false,
|
|
@@ -237,43 +202,40 @@ async function sealTrinityArtifacts(featDir, featureId, lockPath, lockExists, re
|
|
|
237
202
|
...(completeness.details ? { details: completeness.details } : {}),
|
|
238
203
|
};
|
|
239
204
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const lockedAt = new Date().toISOString();
|
|
253
|
-
const history = [...(previous?.relockHistory ?? [])];
|
|
254
|
-
if (relock && previous?.specHash && previous.planHash) {
|
|
255
|
-
history.push({
|
|
256
|
-
lockedAt: previous.lockedAt ?? lockedAt,
|
|
257
|
-
specHash: previous.specHash,
|
|
258
|
-
planHash: previous.planHash,
|
|
259
|
-
tasksHash: previous.tasksHash,
|
|
260
|
-
reason: trimmedReason,
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
const lockFile = {
|
|
264
|
-
lockedAt,
|
|
265
|
-
specHash,
|
|
266
|
-
planHash,
|
|
267
|
-
tasksHash,
|
|
268
|
-
...(history.length > 0 ? { relockHistory: history } : {}),
|
|
205
|
+
const { previous, artifact } = await readPreviousLock(featDir, lockPath, lockExists);
|
|
206
|
+
const lockFile = prepareLock(captured, previous, relock, trimmedReason);
|
|
207
|
+
await revalidateReseal(featDir, directories, captured);
|
|
208
|
+
await lease.beginPersistence();
|
|
209
|
+
const serialized = JSON.stringify(lockFile, null, 2);
|
|
210
|
+
await persistReseal(featDir, lockPath, directories, captured, artifact, serialized, lease);
|
|
211
|
+
return {
|
|
212
|
+
ok: true,
|
|
213
|
+
specHash: lockFile.specHash,
|
|
214
|
+
planHash: lockFile.planHash,
|
|
215
|
+
tasksHash: lockFile.tasksHash,
|
|
216
|
+
relocked: relock,
|
|
269
217
|
};
|
|
270
|
-
await fs.writeFile(lockPath, JSON.stringify(lockFile, null, 2), 'utf-8');
|
|
271
|
-
return { ok: true, specHash, planHash, tasksHash, relocked: relock };
|
|
272
218
|
}
|
|
273
219
|
export async function executionCard(featDir) {
|
|
274
|
-
|
|
220
|
+
let plan;
|
|
221
|
+
try {
|
|
222
|
+
plan = await readFeatureArtifact(featDir, 'plan.md');
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
if (error.code !== 'ENOENT') {
|
|
226
|
+
if (error instanceof CompletionGuardError) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
throw new CompletionGuardError('contract_drift', 'Required plan inspection failed.', 'ERR_INVALID_ARTIFACT');
|
|
230
|
+
}
|
|
231
|
+
plan = '';
|
|
232
|
+
}
|
|
275
233
|
const entries = [...parseManifestContent(plan).allowedFiles.entries()];
|
|
276
234
|
const manifest = entries.map(([filePath, permission]) => ({ path: filePath, permission }));
|
|
235
|
+
const guard = await inspectCompletionGuard(featDir);
|
|
236
|
+
if (guard) {
|
|
237
|
+
throw new CompletionGuardError(guard.reason, 'Feature ownership requires completion or explicit reviewed recovery.', 'ERR_VERIFICATION_FAILED');
|
|
238
|
+
}
|
|
277
239
|
const integrity = await verifyLockedTrinity(featDir);
|
|
278
240
|
if (integrity.ok) {
|
|
279
241
|
return { locked: true, trinity: 'ready', manifest };
|
|
@@ -294,4 +256,17 @@ export function scopedVerificationEnvironment() {
|
|
|
294
256
|
}
|
|
295
257
|
return env;
|
|
296
258
|
}
|
|
259
|
+
async function lockAlreadyExists(lockPath) {
|
|
260
|
+
let lockExists = true;
|
|
261
|
+
try {
|
|
262
|
+
await fs.access(lockPath);
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (error.code !== 'ENOENT') {
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
lockExists = false;
|
|
269
|
+
}
|
|
270
|
+
return lockExists;
|
|
271
|
+
}
|
|
297
272
|
//# sourceMappingURL=lock-integrity.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { parseManifestContent, toPosixPath } from './
|
|
3
|
+
import { parseManifestContent, toPosixPath } from './feature-manifest.js';
|
|
4
4
|
export class PatchSandbox {
|
|
5
5
|
workspaceRoot;
|
|
6
6
|
constructor(workspaceRoot) {
|
|
@@ -8,11 +8,11 @@ export function createUltralightSddServer(workspaceRoot, options) {
|
|
|
8
8
|
const policy = resolveVerificationPolicy(options?.verificationPolicy, workspaceRoot);
|
|
9
9
|
const server = new McpServer({ name: 'sdd-engine', version }, {
|
|
10
10
|
capabilities: { tools: {} },
|
|
11
|
-
instructions: '
|
|
11
|
+
instructions: 'First use: call sdd_list_features. If setup is missing or unverified, call sdd_init_workspace(scope=project) only for the identified project and requested setup. Then use sdd_read_file_slice to read .agents/skills/planu-preflight-guardian/SKILL.md and the matching role. Keep one active task, the locked File Manifest and all nine tools. Installed files do not prove a host catalog reload; explain client-dependent discovery and never initialize on connect.',
|
|
12
12
|
});
|
|
13
13
|
const pinnedRoot = policy.mode === 'scoped' ? policy.workspaceRoot : workspaceRoot;
|
|
14
14
|
const tasks = registerUltralightSddTools(server, pinnedRoot, policy);
|
|
15
|
-
|
|
15
|
+
{
|
|
16
16
|
const close = server.close.bind(server);
|
|
17
17
|
server.close = async () => {
|
|
18
18
|
await tasks.shutdown();
|
|
@@ -31,13 +31,11 @@ export function createUltralightSddServer(workspaceRoot, options) {
|
|
|
31
31
|
export async function runServer() {
|
|
32
32
|
const policy = captureVerificationPolicy(process.env.PLANU_VERIFICATION_TIMEOUT_POLICY);
|
|
33
33
|
const server = createUltralightSddServer(undefined, policy.mode === 'scoped' ? { verificationPolicy: policy } : undefined);
|
|
34
|
-
|
|
35
|
-
bindScopedShutdown(server);
|
|
36
|
-
}
|
|
34
|
+
bindVerificationShutdown(server);
|
|
37
35
|
const transport = new StdioServerTransport();
|
|
38
36
|
await server.connect(transport);
|
|
39
37
|
}
|
|
40
|
-
function
|
|
38
|
+
function bindVerificationShutdown(server) {
|
|
41
39
|
let closing = false;
|
|
42
40
|
const shutdown = () => {
|
|
43
41
|
if (closing) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActiveTaskResult, FeatureSummary, SddResult } from '../types/sdd-engine.js';
|
|
2
|
+
export declare function activeTaskFromContent(content: string, extractCommand: (markdown: string) => string | null): SddResult<ActiveTaskResult>;
|
|
3
|
+
export declare function markTaskVerified(lines: string[], taskId: string, cleanOutput: string): string[] | null;
|
|
4
|
+
export declare function remainingTaskCount(checkRes: SddResult<ActiveTaskResult>): number;
|
|
5
|
+
export declare function summarizeEvidence(output: string): string;
|
|
6
|
+
export declare function wasTaskCompleted(tasksContent: string, taskId: string): boolean;
|
|
7
|
+
export declare function catalogueFromContent(id: string, locked: boolean, tasksContent: string, extractCommand: (markdown: string) => string | null): SddResult<FeatureSummary>;
|
|
8
|
+
//# sourceMappingURL=task-content.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const UNLOCKED_CARD = { locked: false, trinity: 'unlocked', manifest: [] };
|
|
2
|
+
export function activeTaskFromContent(content, extractCommand) {
|
|
3
|
+
return buildActiveTaskResult(parseTasks(content.split('\n')), extractCommand);
|
|
4
|
+
}
|
|
5
|
+
function buildActiveTaskResult(acc, extractCommand) {
|
|
6
|
+
if (acc.totalTasks === 0) {
|
|
7
|
+
return {
|
|
8
|
+
success: true,
|
|
9
|
+
data: { activeTask: null, allCompleted: false, status: 'NO_TASKS', ...UNLOCKED_CARD },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (acc.activeTaskIndex === -1 || acc.completedTasks === acc.totalTasks) {
|
|
13
|
+
return {
|
|
14
|
+
success: true,
|
|
15
|
+
data: { activeTask: null, allCompleted: true, status: 'ALL_COMPLETED', ...UNLOCKED_CARD },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
success: true,
|
|
20
|
+
data: {
|
|
21
|
+
activeTask: {
|
|
22
|
+
taskId: acc.activeTaskId,
|
|
23
|
+
taskTitle: acc.activeTaskTitle,
|
|
24
|
+
fullTaskMarkdown: acc.activeTaskLines.join('\n').trim(),
|
|
25
|
+
verificationCommand: extractCommand(acc.activeTaskLines.join('\n')),
|
|
26
|
+
taskIndex: acc.activeTaskIndex,
|
|
27
|
+
totalTasks: acc.totalTasks,
|
|
28
|
+
completedTasks: acc.completedTasks,
|
|
29
|
+
},
|
|
30
|
+
allCompleted: false,
|
|
31
|
+
status: 'IN_PROGRESS',
|
|
32
|
+
...UNLOCKED_CARD,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function parseTasks(lines) {
|
|
37
|
+
const acc = {
|
|
38
|
+
totalTasks: 0,
|
|
39
|
+
completedTasks: 0,
|
|
40
|
+
activeTaskIndex: -1,
|
|
41
|
+
activeTaskId: '',
|
|
42
|
+
activeTaskTitle: '',
|
|
43
|
+
activeTaskLines: [],
|
|
44
|
+
isCapturingActive: false,
|
|
45
|
+
};
|
|
46
|
+
const taskRegex = /^[-*]\s*\[([\s/xX])\]\s*(.*)$/;
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const match = taskRegex.exec(line.trim());
|
|
49
|
+
if (match?.[1] && match[2]) {
|
|
50
|
+
acc.totalTasks++;
|
|
51
|
+
const statusChar = match[1].trim().toLowerCase();
|
|
52
|
+
if (statusChar === 'x') {
|
|
53
|
+
acc.completedTasks++;
|
|
54
|
+
if (acc.isCapturingActive) {
|
|
55
|
+
acc.isCapturingActive = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (!acc.isCapturingActive && acc.activeTaskIndex === -1) {
|
|
59
|
+
acc.isCapturingActive = true;
|
|
60
|
+
acc.activeTaskIndex = acc.totalTasks;
|
|
61
|
+
const parsed = extractTaskId(match[2].trim(), acc.activeTaskIndex);
|
|
62
|
+
acc.activeTaskId = parsed.id;
|
|
63
|
+
acc.activeTaskTitle = parsed.title;
|
|
64
|
+
acc.activeTaskLines.push(line);
|
|
65
|
+
}
|
|
66
|
+
else if (acc.isCapturingActive) {
|
|
67
|
+
acc.isCapturingActive = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (acc.isCapturingActive) {
|
|
71
|
+
acc.activeTaskLines.push(line);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return acc;
|
|
75
|
+
}
|
|
76
|
+
function extractTaskId(rawTitle, index) {
|
|
77
|
+
const idMatch = /^(TASK-[A-Z0-9_-]+|[A-Z0-9_-]+):\s*(.*)$/i.exec(rawTitle);
|
|
78
|
+
if (idMatch?.[1] && idMatch[2]) {
|
|
79
|
+
return { id: idMatch[1].toUpperCase(), title: idMatch[2].trim() };
|
|
80
|
+
}
|
|
81
|
+
return { id: `TASK-${index}`, title: rawTitle };
|
|
82
|
+
}
|
|
83
|
+
export function markTaskVerified(lines, taskId, cleanOutput) {
|
|
84
|
+
const regexExact = new RegExp(`^(\\s*[-*]\\s*\\[)[\\s/](\\]\\s*(?:${taskId}\\b|.*\\b${taskId}\\b.*))`, 'i');
|
|
85
|
+
const next = [...lines];
|
|
86
|
+
for (let i = 0; i < next.length; i++) {
|
|
87
|
+
const line = next[i];
|
|
88
|
+
if (line !== undefined && regexExact.test(line)) {
|
|
89
|
+
next[i] = line.replace(regexExact, (_, open, rest) => `${open}x${rest} — [Verified: ${cleanOutput}]`);
|
|
90
|
+
return next;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
export function remainingTaskCount(checkRes) {
|
|
96
|
+
if (!checkRes.success || !checkRes.data.activeTask) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
return checkRes.data.activeTask.totalTasks - checkRes.data.activeTask.completedTasks;
|
|
100
|
+
}
|
|
101
|
+
const EVIDENCE_LIMIT = 500;
|
|
102
|
+
export function summarizeEvidence(output) {
|
|
103
|
+
const collapsed = output.trim().replace(/\s+/g, ' ');
|
|
104
|
+
if (collapsed.length <= EVIDENCE_LIMIT) {
|
|
105
|
+
return collapsed;
|
|
106
|
+
}
|
|
107
|
+
const head = Array.from(collapsed).slice(0, EVIDENCE_LIMIT).join('');
|
|
108
|
+
const lastSpace = head.lastIndexOf(' ');
|
|
109
|
+
return `${(lastSpace > 0 ? head.slice(0, lastSpace) : head).trimEnd()}…`;
|
|
110
|
+
}
|
|
111
|
+
export function wasTaskCompleted(tasksContent, taskId) {
|
|
112
|
+
return tasksContent.split('\n').some((line) => {
|
|
113
|
+
const completedId = /^[-*]\s*\[[xX]\]\s*(TASK-[A-Z0-9_-]+|[A-Z0-9_-]+)\b/iu.exec(line.trim())?.[1];
|
|
114
|
+
return completedId?.toUpperCase() === taskId.toUpperCase();
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
export function catalogueFromContent(id, locked, tasksContent, extractCommand) {
|
|
118
|
+
const parsed = activeTaskFromContent(tasksContent, extractCommand);
|
|
119
|
+
if (!parsed.success) {
|
|
120
|
+
return parsed;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
data: {
|
|
125
|
+
id,
|
|
126
|
+
status: !locked ? 'planning' : parsed.data.allCompleted ? 'done' : 'executing',
|
|
127
|
+
locked: locked,
|
|
128
|
+
activeTaskId: parsed.data.activeTask?.taskId ?? null,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=task-content.js.map
|