@planu/cli 8.2.20 → 8.4.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/CHANGELOG.md +12 -0
- package/README.md +118 -3
- package/dist/sdd-engine/completion-snapshot.d.ts +5 -1
- package/dist/sdd-engine/completion-snapshot.js +79 -2
- package/dist/sdd-engine/contracts.d.ts +6 -3
- package/dist/sdd-engine/contracts.js +30 -3
- package/dist/sdd-engine/feature-authority.d.ts +3 -1
- package/dist/sdd-engine/feature-authority.js +33 -1
- package/dist/sdd-engine/feature-manifest.d.ts +4 -5
- package/dist/sdd-engine/feature-manifest.js +206 -93
- package/dist/sdd-engine/host-rule-pack.d.ts +5 -0
- package/dist/sdd-engine/host-rule-pack.js +103 -43
- package/dist/sdd-engine/host-skill-reader.d.ts +6 -0
- package/dist/sdd-engine/host-skill-reader.js +187 -0
- package/dist/sdd-engine/lock-integrity.d.ts +3 -2
- package/dist/sdd-engine/lock-integrity.js +30 -18
- package/dist/sdd-engine/receipt-assessment.d.ts +12 -0
- package/dist/sdd-engine/receipt-assessment.js +223 -0
- package/dist/sdd-engine/server.js +2 -4
- package/dist/sdd-engine/task-content.d.ts +19 -1
- package/dist/sdd-engine/task-content.js +128 -3
- package/dist/sdd-engine/task-failures.d.ts +2 -0
- package/dist/sdd-engine/task-failures.js +34 -0
- package/dist/sdd-engine/task-window.d.ts +3 -4
- package/dist/sdd-engine/task-window.js +49 -79
- package/dist/sdd-engine/tools/execution-tools.d.ts +1 -11
- package/dist/sdd-engine/tools/execution-tools.js +86 -57
- package/dist/sdd-engine/tools/workspace-tools.d.ts +1 -1
- package/dist/sdd-engine/tools/workspace-tools.js +17 -9
- package/dist/sdd-engine/tools.d.ts +2 -1
- package/dist/sdd-engine/tools.js +4 -2
- package/dist/sdd-engine/trinity-structure.d.ts +25 -0
- package/dist/sdd-engine/trinity-structure.js +317 -0
- package/dist/sdd-engine/verification-inputs.d.ts +12 -0
- package/dist/sdd-engine/verification-inputs.js +302 -0
- package/dist/sdd-engine/verification-preflight.d.ts +4 -0
- package/dist/sdd-engine/verification-preflight.js +271 -0
- package/dist/sdd-engine/verification-receipts.d.ts +16 -0
- package/dist/sdd-engine/verification-receipts.js +98 -0
- package/dist/sdd-engine/workspace-root.d.ts +1 -0
- package/dist/sdd-engine/workspace-root.js +1 -0
- package/dist/types/completion.d.ts +9 -2
- package/dist/types/sdd-engine.d.ts +203 -0
- package/package.json +1 -1
- package/templates/AGENTS.md +9 -1
- package/templates/host/planu-sdd.md +9 -0
- package/templates/skills/spec-architect.md +1 -0
|
@@ -43,9 +43,8 @@ function parseTasks(lines) {
|
|
|
43
43
|
activeTaskLines: [],
|
|
44
44
|
isCapturingActive: false,
|
|
45
45
|
};
|
|
46
|
-
const taskRegex = /^[-*]\s*\[([\s/xX])\]\s*(.*)$/;
|
|
47
46
|
for (const line of lines) {
|
|
48
|
-
const match =
|
|
47
|
+
const match = TASK_CHECKBOX.exec(line.trim());
|
|
49
48
|
if (match?.[1] && match[2]) {
|
|
50
49
|
acc.totalTasks++;
|
|
51
50
|
const statusChar = match[1].trim().toLowerCase();
|
|
@@ -73,8 +72,34 @@ function parseTasks(lines) {
|
|
|
73
72
|
}
|
|
74
73
|
return acc;
|
|
75
74
|
}
|
|
75
|
+
const TASK_CHECKBOX = /^[-*]\s*\[([\s/xX])\]\s*(.*)$/u;
|
|
76
|
+
const EXPLICIT_TASK_ID = /^(TASK-[A-Z0-9_-]+|[A-Z0-9_-]+):\s*(.*)$/i;
|
|
77
|
+
const LEGACY_COMPLETED_ID = /^([A-Z0-9_-]+) — \[Verified: .*?\]:\s*/i;
|
|
78
|
+
export function taskBlocks(content) {
|
|
79
|
+
const blocks = [];
|
|
80
|
+
for (const [lineIndex, line] of content.split('\n').entries()) {
|
|
81
|
+
const match = TASK_CHECKBOX.exec(line.trim());
|
|
82
|
+
if (!match?.[1] || !match[2]) {
|
|
83
|
+
blocks.at(-1)?.lines.push(line);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const title = match[2].trim();
|
|
87
|
+
const ordinal = blocks.length + 1;
|
|
88
|
+
const explicit = EXPLICIT_TASK_ID.exec(title);
|
|
89
|
+
const historical = match[1].toLowerCase() === 'x' ? LEGACY_COMPLETED_ID.exec(title) : null;
|
|
90
|
+
blocks.push({
|
|
91
|
+
id: historical?.[1]?.toUpperCase() ?? extractTaskId(title, ordinal).id,
|
|
92
|
+
explicitId: explicit?.[2] ? explicit[1] : undefined,
|
|
93
|
+
legacyId: historical?.[1],
|
|
94
|
+
ordinal,
|
|
95
|
+
lineIndex,
|
|
96
|
+
lines: [],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return blocks;
|
|
100
|
+
}
|
|
76
101
|
function extractTaskId(rawTitle, index) {
|
|
77
|
-
const idMatch =
|
|
102
|
+
const idMatch = EXPLICIT_TASK_ID.exec(rawTitle);
|
|
78
103
|
if (idMatch?.[1] && idMatch[2]) {
|
|
79
104
|
return { id: idMatch[1].toUpperCase(), title: idMatch[2].trim() };
|
|
80
105
|
}
|
|
@@ -92,6 +117,20 @@ export function markTaskVerified(lines, taskId, cleanOutput) {
|
|
|
92
117
|
}
|
|
93
118
|
return null;
|
|
94
119
|
}
|
|
120
|
+
export function markReceiptTaskVerified(content, lineIndex, summary) {
|
|
121
|
+
const lines = content.split('\n');
|
|
122
|
+
const line = lines[lineIndex];
|
|
123
|
+
if (!line) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const checked = line.replace(/^(\s*[-*]\s*\[)[\s/](\])/u, '$1x$2');
|
|
127
|
+
if (checked === line) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const lineEnding = checked.endsWith('\r') ? '\r' : '';
|
|
131
|
+
lines[lineIndex] = checked.trimEnd() + ' — [Verified: ' + summary + ']' + lineEnding;
|
|
132
|
+
return lines.join('\n');
|
|
133
|
+
}
|
|
95
134
|
export function remainingTaskCount(checkRes) {
|
|
96
135
|
if (!checkRes.success || !checkRes.data.activeTask) {
|
|
97
136
|
return 0;
|
|
@@ -129,4 +168,90 @@ export function catalogueFromContent(id, locked, tasksContent, extractCommand) {
|
|
|
129
168
|
},
|
|
130
169
|
};
|
|
131
170
|
}
|
|
171
|
+
const RECEIPT_DIRECTIVE = /^verification\s*\(\s*receipts(?:\b|v[0-9])/iu;
|
|
172
|
+
const COMMAND_DIRECTIVE = 'Verification (receipts v1):';
|
|
173
|
+
export function insideMarkdownBlock(lines) {
|
|
174
|
+
let fence;
|
|
175
|
+
let comment = false;
|
|
176
|
+
for (const raw of lines) {
|
|
177
|
+
const line = raw.trimStart();
|
|
178
|
+
const delimiter = /^(\u0060{3,}|~{3,})/u.exec(line)?.[0];
|
|
179
|
+
if (fence) {
|
|
180
|
+
if (delimiter?.startsWith(fence) && !line.slice(delimiter.length).trim()) {
|
|
181
|
+
fence = undefined;
|
|
182
|
+
}
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!comment && delimiter) {
|
|
186
|
+
fence = delimiter;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
for (const marker of line.matchAll(/<!--|-->/gu)) {
|
|
190
|
+
comment = marker[0] === '<!--';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return comment || fence !== undefined;
|
|
194
|
+
}
|
|
195
|
+
export function hasReceiptDirective(line) {
|
|
196
|
+
return RECEIPT_DIRECTIVE.test(line.trim());
|
|
197
|
+
}
|
|
198
|
+
export function receiptCommand(block) {
|
|
199
|
+
const lines = block.lines.map((line) => line.trim());
|
|
200
|
+
const directives = lines.filter((line) => RECEIPT_DIRECTIVE.test(line));
|
|
201
|
+
const directive = directives[0];
|
|
202
|
+
const precedingLines = lines.slice(0, directive ? lines.indexOf(directive) : 0);
|
|
203
|
+
if (directives.length !== 1 ||
|
|
204
|
+
!directive?.startsWith(COMMAND_DIRECTIVE) ||
|
|
205
|
+
insideMarkdownBlock(precedingLines) ||
|
|
206
|
+
lines.some((line) => /^verification:/iu.test(line))) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
const command = directive.slice(COMMAND_DIRECTIVE.length).trim();
|
|
210
|
+
return command && !/[<>]/u.test(command) ? command : undefined;
|
|
211
|
+
}
|
|
212
|
+
export function countTaskIds(blocks) {
|
|
213
|
+
const counts = new Map();
|
|
214
|
+
for (const { id } of blocks) {
|
|
215
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
216
|
+
}
|
|
217
|
+
return counts;
|
|
218
|
+
}
|
|
219
|
+
export function dueTaskOrdinals(blocks, counts) {
|
|
220
|
+
const due = new Map();
|
|
221
|
+
for (const block of blocks) {
|
|
222
|
+
const id = (block.explicitId ?? block.legacyId)?.toUpperCase();
|
|
223
|
+
if (id !== undefined && counts.get(id) === 1) {
|
|
224
|
+
due.set(id, block.ordinal);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return due;
|
|
228
|
+
}
|
|
229
|
+
const SLICE_LINE_CAP = 200;
|
|
230
|
+
function sourceLines(fileData) {
|
|
231
|
+
if (fileData.length === 0) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
const parts = fileData.split('\n');
|
|
235
|
+
if (fileData.endsWith('\n')) {
|
|
236
|
+
parts.pop();
|
|
237
|
+
}
|
|
238
|
+
return parts;
|
|
239
|
+
}
|
|
240
|
+
export function sliceNumberedSource(fileData, startLine, endLine) {
|
|
241
|
+
const lines = sourceLines(fileData);
|
|
242
|
+
if (startLine > lines.length) {
|
|
243
|
+
return { ok: false, totalLines: lines.length };
|
|
244
|
+
}
|
|
245
|
+
const requestedEnd = Math.min(endLine, lines.length);
|
|
246
|
+
const cappedEnd = Math.min(requestedEnd, startLine + SLICE_LINE_CAP - 1);
|
|
247
|
+
const slice = lines.slice(startLine - 1, cappedEnd);
|
|
248
|
+
return {
|
|
249
|
+
ok: true,
|
|
250
|
+
totalLines: lines.length,
|
|
251
|
+
startLine,
|
|
252
|
+
endLine: cappedEnd,
|
|
253
|
+
truncated: cappedEnd < requestedEnd,
|
|
254
|
+
text: slice.map((content, index) => `${startLine + index}: ${content}`).join('\n'),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
132
257
|
//# sourceMappingURL=task-content.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CompleteTaskResult, SddResult } from '../types/sdd-engine.js';
|
|
2
2
|
import type { ScopedVerificationRun } from '../types/verification.js';
|
|
3
3
|
export declare function completionFailure(reason: string, code?: 'ERR_VERIFICATION_FAILED' | 'ERR_SPEC_DRIFT', trigger?: string): SddResult<never>;
|
|
4
|
+
export declare function patchMutationError(error: unknown): SddResult<never>;
|
|
5
|
+
export declare function receiptFailure(reason: string, details?: Record<string, unknown>, trigger?: string): SddResult<never>;
|
|
4
6
|
export declare function completionError(error: unknown, trigger?: string): SddResult<never>;
|
|
5
7
|
export declare function taskOutOfSequence(taskId: string, activeTaskId: string | null, alreadyCompleted?: boolean): SddResult<CompleteTaskResult>;
|
|
6
8
|
export declare function verificationMissing(): SddResult<CompleteTaskResult>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CompletionGuardError } from './feature-authority.js';
|
|
2
|
+
import { VerificationInputError } from './verification-inputs.js';
|
|
2
3
|
export function completionFailure(reason, code = reason === 'contract_drift'
|
|
3
4
|
? 'ERR_SPEC_DRIFT'
|
|
4
5
|
: 'ERR_VERIFICATION_FAILED', trigger = 'sdd_complete_task') {
|
|
@@ -14,7 +15,40 @@ export function completionFailure(reason, code = reason === 'contract_drift'
|
|
|
14
15
|
},
|
|
15
16
|
};
|
|
16
17
|
}
|
|
18
|
+
export function patchMutationError(error) {
|
|
19
|
+
const guarded = error instanceof CompletionGuardError || error instanceof VerificationInputError;
|
|
20
|
+
return {
|
|
21
|
+
success: false,
|
|
22
|
+
error: {
|
|
23
|
+
code: error instanceof VerificationInputError
|
|
24
|
+
? 'ERR_PERMISSION_VIOLATION'
|
|
25
|
+
: error instanceof CompletionGuardError
|
|
26
|
+
? error.code
|
|
27
|
+
: 'ERR_VERIFICATION_FAILED',
|
|
28
|
+
message: guarded ? error.message : 'Feature mutation was denied.',
|
|
29
|
+
trigger: 'sdd_apply_file_patch',
|
|
30
|
+
details: { reason: guarded ? error.reason : 'failed' },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function receiptFailure(reason, details = {}, trigger = 'sdd_complete_task') {
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
error: {
|
|
38
|
+
code: 'ERR_VERIFICATION_FAILED',
|
|
39
|
+
message: 'Receipt verification was denied.',
|
|
40
|
+
trigger,
|
|
41
|
+
details: { reason, ...details },
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
17
45
|
export function completionError(error, trigger = 'sdd_complete_task') {
|
|
46
|
+
if (error instanceof VerificationInputError) {
|
|
47
|
+
return receiptFailure(error.reason, {
|
|
48
|
+
...(error.category ? { category: error.category } : {}),
|
|
49
|
+
...(error.path ? { path: error.path } : {}),
|
|
50
|
+
}, trigger);
|
|
51
|
+
}
|
|
18
52
|
if (error instanceof CompletionGuardError) {
|
|
19
53
|
return {
|
|
20
54
|
success: false,
|
|
@@ -9,16 +9,15 @@ export declare class TaskWindowManager {
|
|
|
9
9
|
shutdown(): Promise<void>;
|
|
10
10
|
private activeTaskFromContent;
|
|
11
11
|
private selectScopedTask;
|
|
12
|
-
private commitScopedTask;
|
|
13
12
|
getActiveTask(tasksFilePath: string): Promise<SddResult<ActiveTaskResult>>;
|
|
13
|
+
getVerificationPreflight(tasksPath: string, workspaceRoot: string, receipts?: unknown, signal?: AbortSignal): Promise<SddResult<ActiveTaskResult>>;
|
|
14
14
|
getCatalogueEntry(featDir: string): Promise<SddResult<FeatureSummary>>;
|
|
15
|
-
completeTask(tasksFilePath: string, taskId: string, workspaceRoot: string, _verificationOutput: string, signal?: AbortSignal): Promise<SddResult<CompleteTaskResult>>;
|
|
15
|
+
completeTask(tasksFilePath: string, taskId: string, workspaceRoot: string, _verificationOutput: string, signal?: AbortSignal, receipts?: unknown): Promise<SddResult<CompleteTaskResult>>;
|
|
16
16
|
private completeOwned;
|
|
17
|
+
private completeIfReceiptTask;
|
|
17
18
|
private checkScopedPaths;
|
|
18
19
|
private attemptScopedCompletion;
|
|
19
|
-
private commitOwnedScopedTask;
|
|
20
20
|
private completeOrdinary;
|
|
21
|
-
private commitOrdinary;
|
|
22
21
|
}
|
|
23
22
|
export declare function verificationCommand(taskMarkdown: string): string | null;
|
|
24
23
|
//# sourceMappingURL=task-window.d.ts.map
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { ScopedVerificationCoordinator, runScopedVerification } from './verification-runner.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isScopedVerificationFeature, persistScopedCompletionFiles, scopedFeaturePathFailure, } from './verification-policy.js';
|
|
4
|
+
import { getVerificationPreflight } from './verification-preflight.js';
|
|
4
5
|
import { executionCard } from './lock-integrity.js';
|
|
6
|
+
import { parseVerificationReceiptPolicy } from './feature-manifest.js';
|
|
7
|
+
import { completeReceiptTask } from './verification-receipts.js';
|
|
5
8
|
import { CompletionGuardError, readFeatureArtifact } from './feature-authority.js';
|
|
6
9
|
import { acquireCompletionLease, inspectCompletionGuard, } from './completion-guard.js';
|
|
7
|
-
import { captureCompletionSnapshot, revalidateCompletionSnapshot,
|
|
8
|
-
import { activeTaskFromContent, catalogueFromContent,
|
|
9
|
-
import { completionFailure, completionError, taskOutOfSequence, verificationMissing, verificationFailed, unsupportedVerificationPlatform, scopedPathMismatch, taskFileMissing, catalogueReadFailure, } from './task-failures.js';
|
|
10
|
+
import { captureCompletionSnapshot, revalidateCompletionSnapshot, commitOrdinaryTask, commitOwnedScopedTask, readCatalogueArtifacts, } from './completion-snapshot.js';
|
|
11
|
+
import { activeTaskFromContent, catalogueFromContent, wasTaskCompleted } from './task-content.js';
|
|
12
|
+
import { completionFailure, completionError, taskOutOfSequence, receiptFailure, verificationMissing, verificationFailed, unsupportedVerificationPlatform, scopedPathMismatch, taskFileMissing, catalogueReadFailure, } from './task-failures.js';
|
|
10
13
|
export class TaskWindowManager {
|
|
11
14
|
scopedPolicy;
|
|
12
15
|
scoped;
|
|
@@ -36,26 +39,6 @@ export class TaskWindowManager {
|
|
|
36
39
|
}
|
|
37
40
|
: null;
|
|
38
41
|
}
|
|
39
|
-
async commitScopedTask(policy, taskId, snapshot, output, signal) {
|
|
40
|
-
const summary = summarizeEvidence(output);
|
|
41
|
-
const marked = markTaskVerified(snapshot.tasksContent.split('\n'), taskId, summary);
|
|
42
|
-
if (marked === null) {
|
|
43
|
-
return taskOutOfSequence(taskId, null);
|
|
44
|
-
}
|
|
45
|
-
const written = marked.join('\n');
|
|
46
|
-
const persisted = await persistScopedCompletionFiles(policy, snapshot, written, signal);
|
|
47
|
-
if (!persisted.success) {
|
|
48
|
-
return persisted;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
success: true,
|
|
52
|
-
data: {
|
|
53
|
-
completedTaskId: taskId,
|
|
54
|
-
verificationSummary: summary,
|
|
55
|
-
remainingTasks: remainingTaskCount(this.activeTaskFromContent(written)),
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
42
|
async getActiveTask(tasksFilePath) {
|
|
60
43
|
let content;
|
|
61
44
|
try {
|
|
@@ -77,8 +60,13 @@ export class TaskWindowManager {
|
|
|
77
60
|
return built;
|
|
78
61
|
}
|
|
79
62
|
try {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
63
|
+
const feature = path.dirname(tasksFilePath);
|
|
64
|
+
const card = await executionCard(feature);
|
|
65
|
+
if (card.trinity === 'ready' &&
|
|
66
|
+
(await readFeatureArtifact(feature, 'tasks.md')) !== content) {
|
|
67
|
+
return completionFailure('contract_drift', undefined, 'sdd_get_active_task');
|
|
68
|
+
}
|
|
69
|
+
const guard = await inspectCompletionGuard(feature);
|
|
82
70
|
if (guard) {
|
|
83
71
|
return completionFailure(guard.reason, undefined, 'sdd_get_active_task');
|
|
84
72
|
}
|
|
@@ -88,6 +76,9 @@ export class TaskWindowManager {
|
|
|
88
76
|
return completionError(error, 'sdd_get_active_task');
|
|
89
77
|
}
|
|
90
78
|
}
|
|
79
|
+
async getVerificationPreflight(tasksPath, workspaceRoot, receipts, signal) {
|
|
80
|
+
return getVerificationPreflight(tasksPath, workspaceRoot, verificationCommand, receipts, this.scopedPolicy, signal);
|
|
81
|
+
}
|
|
91
82
|
async getCatalogueEntry(featDir) {
|
|
92
83
|
const id = path.basename(featDir);
|
|
93
84
|
try {
|
|
@@ -98,8 +89,8 @@ export class TaskWindowManager {
|
|
|
98
89
|
return catalogueReadFailure(error, id);
|
|
99
90
|
}
|
|
100
91
|
}
|
|
101
|
-
async completeTask(tasksFilePath, taskId, workspaceRoot, _verificationOutput, signal) {
|
|
102
|
-
const operation = this.completeOwned(tasksFilePath, taskId, workspaceRoot, signal);
|
|
92
|
+
async completeTask(tasksFilePath, taskId, workspaceRoot, _verificationOutput, signal, receipts) {
|
|
93
|
+
const operation = this.completeOwned(tasksFilePath, taskId, workspaceRoot, signal, receipts);
|
|
103
94
|
this.pending.add(operation);
|
|
104
95
|
try {
|
|
105
96
|
return await operation;
|
|
@@ -108,7 +99,7 @@ export class TaskWindowManager {
|
|
|
108
99
|
this.pending.delete(operation);
|
|
109
100
|
}
|
|
110
101
|
}
|
|
111
|
-
async completeOwned(tasksFilePath, taskId, workspaceRoot, signal) {
|
|
102
|
+
async completeOwned(tasksFilePath, taskId, workspaceRoot, signal, receipts) {
|
|
112
103
|
try {
|
|
113
104
|
const feature = path.dirname(tasksFilePath);
|
|
114
105
|
const abortSignal = AbortSignal.any([
|
|
@@ -119,7 +110,10 @@ export class TaskWindowManager {
|
|
|
119
110
|
if (pathFailure) {
|
|
120
111
|
return pathFailure;
|
|
121
112
|
}
|
|
122
|
-
const lease = await acquireCompletionLease(feature, {
|
|
113
|
+
const lease = await acquireCompletionLease(feature, {
|
|
114
|
+
operation: 'complete',
|
|
115
|
+
workspaceRoot,
|
|
116
|
+
});
|
|
123
117
|
try {
|
|
124
118
|
const snapshot = await captureCompletionSnapshot(feature, {
|
|
125
119
|
writable: true,
|
|
@@ -127,6 +121,10 @@ export class TaskWindowManager {
|
|
|
127
121
|
validateLock: this.scopedPolicy === undefined,
|
|
128
122
|
});
|
|
129
123
|
const selected = this.selectScopedTask(snapshot.tasksContent);
|
|
124
|
+
const receiptResult = await this.completeIfReceiptTask(snapshot, lease, selected, taskId, workspaceRoot, abortSignal, receipts);
|
|
125
|
+
if (receiptResult) {
|
|
126
|
+
return receiptResult;
|
|
127
|
+
}
|
|
130
128
|
await lease.bind(taskId, selected?.command ?? '', snapshot.digest);
|
|
131
129
|
const scoped = await this.attemptScopedCompletion(tasksFilePath, taskId, workspaceRoot, abortSignal, snapshot, lease);
|
|
132
130
|
if (scoped !== null) {
|
|
@@ -143,6 +141,25 @@ export class TaskWindowManager {
|
|
|
143
141
|
return completionError(error);
|
|
144
142
|
}
|
|
145
143
|
}
|
|
144
|
+
async completeIfReceiptTask(snapshot, lease, selected, taskId, workspaceRoot, signal, receipts) {
|
|
145
|
+
const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
|
|
146
|
+
if (policy.status === 'invalid') {
|
|
147
|
+
return completionFailure('contract_drift');
|
|
148
|
+
}
|
|
149
|
+
const task = policy.status === 'ready' && selected ? policy.tasks.get(selected.taskId) : undefined;
|
|
150
|
+
if (policy.status !== 'ready' || !task) {
|
|
151
|
+
return receipts === undefined ? undefined : receiptFailure('receipt_not_configured');
|
|
152
|
+
}
|
|
153
|
+
if (task.taskId !== taskId.toUpperCase()) {
|
|
154
|
+
return taskOutOfSequence(taskId, task.taskId, wasTaskCompleted(snapshot.tasksContent, taskId));
|
|
155
|
+
}
|
|
156
|
+
if (this.scopedPolicy &&
|
|
157
|
+
(await isScopedVerificationFeature(this.scopedPolicy, snapshot.featDir))) {
|
|
158
|
+
return receiptFailure('receipt_scoped_unsupported');
|
|
159
|
+
}
|
|
160
|
+
await lease.bind(taskId, task.command, snapshot.digest);
|
|
161
|
+
return completeReceiptTask(snapshot, workspaceRoot, policy, task, receipts, lease, signal, VERIFICATION_TIMEOUT_MS, runScopedVerification);
|
|
162
|
+
}
|
|
146
163
|
async checkScopedPaths(tasksFilePath, workspaceRoot, feature) {
|
|
147
164
|
const policy = this.scopedPolicy;
|
|
148
165
|
if (policy && (await isScopedVerificationFeature(policy, feature))) {
|
|
@@ -169,7 +186,7 @@ export class TaskWindowManager {
|
|
|
169
186
|
workspaceRoot,
|
|
170
187
|
signal,
|
|
171
188
|
selectTask: (content) => this.selectScopedTask(content),
|
|
172
|
-
commit: (scopedSnapshot, output, commitSignal) =>
|
|
189
|
+
commit: (scopedSnapshot, output, commitSignal) => commitOwnedScopedTask(taskId, scopedSnapshot, output, commitSignal, snapshot, lease, (written) => persistScopedCompletionFiles(policy, scopedSnapshot, written, commitSignal)),
|
|
173
190
|
});
|
|
174
191
|
if (scoped !== null) {
|
|
175
192
|
if (!scoped.success && scoped.error.details?.cleanupComplete === false) {
|
|
@@ -181,28 +198,6 @@ export class TaskWindowManager {
|
|
|
181
198
|
await revalidateCompletionSnapshot(snapshot);
|
|
182
199
|
return null;
|
|
183
200
|
}
|
|
184
|
-
async commitOwnedScopedTask(policy, taskId, scopedSnapshot, output, signal, snapshot, lease) {
|
|
185
|
-
await revalidateCompletionSnapshot(snapshot);
|
|
186
|
-
if (signal.aborted) {
|
|
187
|
-
return completionFailure('cancelled');
|
|
188
|
-
}
|
|
189
|
-
await lease.beginPersistence();
|
|
190
|
-
try {
|
|
191
|
-
const outcome = await this.commitScopedTask(policy, taskId, scopedSnapshot, output, signal);
|
|
192
|
-
if (outcome.success) {
|
|
193
|
-
lease.notePersistenceWrite();
|
|
194
|
-
}
|
|
195
|
-
if (isAborted(signal) ||
|
|
196
|
-
(!outcome.success && outcome.error.details?.completionState === 'uncertain')) {
|
|
197
|
-
lease.retain();
|
|
198
|
-
}
|
|
199
|
-
return outcome;
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
lease.retain();
|
|
203
|
-
throw error;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
201
|
async completeOrdinary(snapshot, lease, taskId, workspaceRoot, signal) {
|
|
207
202
|
const active = this.activeTaskFromContent(snapshot.tasksContent);
|
|
208
203
|
if (!active.success) {
|
|
@@ -242,29 +237,7 @@ export class TaskWindowManager {
|
|
|
242
237
|
if (!run.ok) {
|
|
243
238
|
return verificationFailed(run);
|
|
244
239
|
}
|
|
245
|
-
return
|
|
246
|
-
}
|
|
247
|
-
async commitOrdinary(snapshot, lease, taskId, output, signal) {
|
|
248
|
-
await revalidateCompletionSnapshot(snapshot);
|
|
249
|
-
if (signal.aborted) {
|
|
250
|
-
return completionFailure('cancelled');
|
|
251
|
-
}
|
|
252
|
-
const summary = summarizeEvidence(output);
|
|
253
|
-
const marked = markTaskVerified(snapshot.tasksContent.split('\n'), taskId, summary);
|
|
254
|
-
if (marked === null) {
|
|
255
|
-
return taskOutOfSequence(taskId, null, true);
|
|
256
|
-
}
|
|
257
|
-
const written = marked.join('\n');
|
|
258
|
-
await persistCompletionSnapshot(lease, snapshot, written, signal);
|
|
259
|
-
const next = this.activeTaskFromContent(written);
|
|
260
|
-
return {
|
|
261
|
-
success: true,
|
|
262
|
-
data: {
|
|
263
|
-
completedTaskId: taskId,
|
|
264
|
-
verificationSummary: summary,
|
|
265
|
-
remainingTasks: remainingTaskCount(next),
|
|
266
|
-
},
|
|
267
|
-
};
|
|
240
|
+
return commitOrdinaryTask(snapshot, lease, taskId, run.output, signal);
|
|
268
241
|
}
|
|
269
242
|
}
|
|
270
243
|
const VERIFICATION_TIMEOUT_MS = 180_000;
|
|
@@ -282,7 +255,4 @@ export function verificationCommand(taskMarkdown) {
|
|
|
282
255
|
}
|
|
283
256
|
return command;
|
|
284
257
|
}
|
|
285
|
-
function isAborted(signal) {
|
|
286
|
-
return signal.aborted;
|
|
287
|
-
}
|
|
288
258
|
//# sourceMappingURL=task-window.js.map
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import type { VerificationPolicy } from '../../types/verification.js';
|
|
2
2
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { TaskWindowManager } from '../task-window.js';
|
|
4
|
+
export { sliceNumberedSource } from '../task-content.js';
|
|
4
5
|
import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
|
|
5
|
-
export declare function sliceNumberedSource(fileData: string, startLine: number, endLine: number): {
|
|
6
|
-
ok: true;
|
|
7
|
-
totalLines: number;
|
|
8
|
-
startLine: number;
|
|
9
|
-
endLine: number;
|
|
10
|
-
truncated: boolean;
|
|
11
|
-
text: string;
|
|
12
|
-
} | {
|
|
13
|
-
ok: false;
|
|
14
|
-
totalLines: number;
|
|
15
|
-
};
|
|
16
6
|
export declare function registerExecutionTools(server: McpServer, workspace: SddWorkspaceHandle, policy?: VerificationPolicy): TaskWindowManager;
|
|
17
7
|
//# sourceMappingURL=execution-tools.d.ts.map
|
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { ReadSpecArtifactInputSchema, ReadFileSliceInputSchema, GetActiveTaskInputSchema, ApplyFilePatchInputSchema, CompleteTaskInputSchema, } from '../contracts.js';
|
|
3
3
|
import { PatchSandbox } from '../patch-sandbox.js';
|
|
4
|
-
import { TaskWindowManager } from '../task-window.js';
|
|
4
|
+
import { TaskWindowManager, verificationCommand } from '../task-window.js';
|
|
5
|
+
import { activeTaskFromContent, hasReceiptDirective, sliceNumberedSource, } from '../task-content.js';
|
|
6
|
+
export { sliceNumberedSource } from '../task-content.js';
|
|
7
|
+
import { parseManifestContent, parseVerificationReceiptPolicy, toPosixPath, } from '../feature-manifest.js';
|
|
8
|
+
import { captureReceiptEvidence } from '../verification-receipts.js';
|
|
9
|
+
import { captureVerificationRoot, checkReceiptPatchTarget, revalidateVerificationInputs, } from '../verification-inputs.js';
|
|
10
|
+
import { completionError, completionFailure, patchMutationError } from '../task-failures.js';
|
|
5
11
|
import { formatResult } from './format-result.js';
|
|
6
|
-
import { acquireCompletionLease } from '../completion-guard.js';
|
|
7
|
-
import { captureCompletionSnapshot } from '../completion-snapshot.js';
|
|
8
|
-
import { CompletionGuardError } from '../feature-authority.js';
|
|
12
|
+
import { acquireCompletionLease, inspectCompletionGuard } from '../completion-guard.js';
|
|
13
|
+
import { captureCompletionSnapshot, revalidateCompletionSnapshot } from '../completion-snapshot.js';
|
|
9
14
|
import { homeFallbackFailure, readTextInsideWorkspace } from '../workspace-root.js';
|
|
10
|
-
|
|
11
|
-
function sourceLines(fileData) {
|
|
12
|
-
if (fileData.length === 0) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
const parts = fileData.split('\n');
|
|
16
|
-
if (fileData.endsWith('\n')) {
|
|
17
|
-
parts.pop();
|
|
18
|
-
}
|
|
19
|
-
return parts;
|
|
20
|
-
}
|
|
21
|
-
export function sliceNumberedSource(fileData, startLine, endLine) {
|
|
22
|
-
const lines = sourceLines(fileData);
|
|
23
|
-
if (startLine > lines.length) {
|
|
24
|
-
return { ok: false, totalLines: lines.length };
|
|
25
|
-
}
|
|
26
|
-
const requestedEnd = Math.min(endLine, lines.length);
|
|
27
|
-
const cappedEnd = Math.min(requestedEnd, startLine + SLICE_LINE_CAP - 1);
|
|
28
|
-
const slice = lines.slice(startLine - 1, cappedEnd);
|
|
29
|
-
return {
|
|
30
|
-
ok: true,
|
|
31
|
-
totalLines: lines.length,
|
|
32
|
-
startLine,
|
|
33
|
-
endLine: cappedEnd,
|
|
34
|
-
truncated: cappedEnd < requestedEnd,
|
|
35
|
-
text: slice.map((content, index) => `${startLine + index}: ${content}`).join('\n'),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
15
|
+
import { guardFailure } from '../feature-authority.js';
|
|
38
16
|
export function registerExecutionTools(server, workspace, policy) {
|
|
39
17
|
const taskWindow = new TaskWindowManager(policy);
|
|
40
18
|
registerReadArtifactTool(server, workspace);
|
|
@@ -90,7 +68,7 @@ function registerGetActiveTaskTool(server, workspace, taskWindow) {
|
|
|
90
68
|
server.registerTool('sdd_get_active_task', {
|
|
91
69
|
description: 'Delivers exclusively the active task (Single Task Window). Zero future backlog.',
|
|
92
70
|
inputSchema: GetActiveTaskInputSchema.shape,
|
|
93
|
-
}, async (rawArgs) => {
|
|
71
|
+
}, async (rawArgs, extra) => {
|
|
94
72
|
const args = GetActiveTaskInputSchema.parse(rawArgs);
|
|
95
73
|
const resolved = await workspace.resolve();
|
|
96
74
|
const homeError = homeFallbackFailure(resolved, 'sdd_get_active_task');
|
|
@@ -98,10 +76,64 @@ function registerGetActiveTaskTool(server, workspace, taskWindow) {
|
|
|
98
76
|
return formatResult(homeError);
|
|
99
77
|
}
|
|
100
78
|
const tasksPath = path.join(resolved.sddDir, 'features', args.feature_id, 'tasks.md');
|
|
79
|
+
if (args.view === 'verification_preflight') {
|
|
80
|
+
return formatResult(await taskWindow.getVerificationPreflight(tasksPath, resolved.workspaceRoot, args.verification_receipts, extra.signal));
|
|
81
|
+
}
|
|
101
82
|
const result = await taskWindow.getActiveTask(tasksPath);
|
|
83
|
+
const active = result.success ? result.data.activeTask : null;
|
|
84
|
+
if (result.success &&
|
|
85
|
+
result.data.trinity === 'ready' &&
|
|
86
|
+
active?.fullTaskMarkdown.split('\n').some(hasReceiptDirective)) {
|
|
87
|
+
return formatResult(await getReceiptActiveTask(path.dirname(tasksPath), active.fullTaskMarkdown, resolved.workspaceRoot, extra.signal));
|
|
88
|
+
}
|
|
102
89
|
return formatResult(result);
|
|
103
90
|
});
|
|
104
91
|
}
|
|
92
|
+
async function getReceiptActiveTask(feature, previousTaskMarkdown, workspaceRoot, signal) {
|
|
93
|
+
const trigger = 'sdd_get_active_task';
|
|
94
|
+
try {
|
|
95
|
+
const root = await captureVerificationRoot(workspaceRoot);
|
|
96
|
+
const snapshot = await captureCompletionSnapshot(feature, { workspaceRoot: root.canonical });
|
|
97
|
+
const current = activeTaskFromContent(snapshot.tasksContent, verificationCommand);
|
|
98
|
+
const active = current.success ? current.data.activeTask : null;
|
|
99
|
+
if (!current.success || active?.fullTaskMarkdown !== previousTaskMarkdown) {
|
|
100
|
+
return completionFailure('contract_drift', undefined, trigger);
|
|
101
|
+
}
|
|
102
|
+
const data = current.data;
|
|
103
|
+
const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
|
|
104
|
+
const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
|
|
105
|
+
if (policy.status !== 'ready' || !task) {
|
|
106
|
+
return completionFailure('contract_drift', undefined, trigger);
|
|
107
|
+
}
|
|
108
|
+
const captured = await captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal);
|
|
109
|
+
if (captured.success) {
|
|
110
|
+
await revalidateVerificationInputs(captured.data.inputs, signal);
|
|
111
|
+
}
|
|
112
|
+
await revalidateCompletionSnapshot(snapshot);
|
|
113
|
+
const guard = await inspectCompletionGuard(feature);
|
|
114
|
+
if (guard) {
|
|
115
|
+
return completionFailure(guard.reason, undefined, trigger);
|
|
116
|
+
}
|
|
117
|
+
if (!captured.success) {
|
|
118
|
+
return { ...captured, error: { ...captured.error, trigger } };
|
|
119
|
+
}
|
|
120
|
+
const manifest = [...parseManifestContent(snapshot.planContent).allowedFiles.entries()].map(([filePath, permission]) => ({ path: filePath, permission }));
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
data: {
|
|
124
|
+
...data,
|
|
125
|
+
activeTask: { ...active, verificationCommand: task.command },
|
|
126
|
+
locked: true,
|
|
127
|
+
trinity: 'ready',
|
|
128
|
+
manifest,
|
|
129
|
+
verificationEvidence: captured.data.evidence,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
return completionError(error, trigger);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
105
137
|
function registerApplyPatchTool(server, workspace) {
|
|
106
138
|
server.registerTool('sdd_apply_file_patch', {
|
|
107
139
|
description: 'Applies CREATE and MODIFY patches, or exact DELETE operations, strictly authorized in plan.md File Manifest. DELETE requires empty search_content and replace_content.',
|
|
@@ -113,8 +145,7 @@ function registerApplyPatchTool(server, workspace) {
|
|
|
113
145
|
if (homeError) {
|
|
114
146
|
return formatResult(homeError);
|
|
115
147
|
}
|
|
116
|
-
|
|
117
|
-
return executeApplyPatch(resolved.sddDir, patchSandbox, args);
|
|
148
|
+
return executeApplyPatch(resolved.workspaceRoot, args);
|
|
118
149
|
});
|
|
119
150
|
}
|
|
120
151
|
function registerCompleteTaskTool(server, workspace, taskWindow) {
|
|
@@ -128,9 +159,8 @@ function registerCompleteTaskTool(server, workspace, taskWindow) {
|
|
|
128
159
|
if (homeError) {
|
|
129
160
|
return formatResult(homeError);
|
|
130
161
|
}
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const result = await taskWindow.completeTask(tasksPath, args.task_id, resolved.workspaceRoot, args.verification_output ?? '', extra.signal);
|
|
162
|
+
const tasksPath = path.join(resolved.sddDir, 'features', args.feature_id, 'tasks.md');
|
|
163
|
+
const result = await taskWindow.completeTask(tasksPath, args.task_id, resolved.workspaceRoot, args.verification_output ?? '', extra.signal, args.verification_receipts);
|
|
134
164
|
return formatResult(result);
|
|
135
165
|
});
|
|
136
166
|
}
|
|
@@ -181,18 +211,25 @@ async function executeReadFileSlice(workspaceRoot, relPath, startLine, endLine)
|
|
|
181
211
|
},
|
|
182
212
|
});
|
|
183
213
|
}
|
|
184
|
-
async function executeApplyPatch(
|
|
185
|
-
const featDir = path.join(sddDir, 'features', args.feature_id);
|
|
214
|
+
async function executeApplyPatch(workspaceRoot, args) {
|
|
186
215
|
try {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
216
|
+
const root = await captureVerificationRoot(workspaceRoot);
|
|
217
|
+
const featDir = path.join(root.canonical, '.sdd', 'features', args.feature_id);
|
|
218
|
+
const authority = { workspaceRoot: root.canonical };
|
|
219
|
+
const lease = await acquireCompletionLease(featDir, { ...authority, operation: 'patch' });
|
|
191
220
|
try {
|
|
192
|
-
await captureCompletionSnapshot(featDir,
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
|
|
221
|
+
const snapshot = await captureCompletionSnapshot(featDir, authority);
|
|
222
|
+
const manifest = parseManifestContent(snapshot.planContent);
|
|
223
|
+
const receiptPolicy = parseVerificationReceiptPolicy(args.feature_id, snapshot.planContent, snapshot.tasksContent);
|
|
224
|
+
if (receiptPolicy.status === 'invalid') {
|
|
225
|
+
guardFailure('contract_drift', 'The locked receipt policy is invalid.');
|
|
226
|
+
}
|
|
227
|
+
if (receiptPolicy.status === 'ready') {
|
|
228
|
+
const target = toPosixPath(args.path);
|
|
229
|
+
await checkReceiptPatchTarget(root, workspaceRoot, target, manifest.allowedFiles.get(target), args.search_content);
|
|
230
|
+
await revalidateCompletionSnapshot(snapshot);
|
|
231
|
+
}
|
|
232
|
+
const patchResult = await new PatchSandbox(root.canonical).applyPatch(manifest, args.path, args.search_content, args.replace_content);
|
|
196
233
|
return formatResult(patchResult);
|
|
197
234
|
}
|
|
198
235
|
finally {
|
|
@@ -200,15 +237,7 @@ async function executeApplyPatch(sddDir, patchSandbox, args) {
|
|
|
200
237
|
}
|
|
201
238
|
}
|
|
202
239
|
catch (error) {
|
|
203
|
-
return formatResult(
|
|
204
|
-
success: false,
|
|
205
|
-
error: {
|
|
206
|
-
code: error instanceof CompletionGuardError ? error.code : 'ERR_VERIFICATION_FAILED',
|
|
207
|
-
message: error instanceof CompletionGuardError ? error.message : 'Feature mutation was denied.',
|
|
208
|
-
trigger: 'sdd_apply_file_patch',
|
|
209
|
-
details: { reason: error instanceof CompletionGuardError ? error.reason : 'failed' },
|
|
210
|
-
},
|
|
211
|
-
});
|
|
240
|
+
return formatResult(patchMutationError(error));
|
|
212
241
|
}
|
|
213
242
|
}
|
|
214
243
|
//# sourceMappingURL=execution-tools.js.map
|