@planu/cli 8.5.1 → 8.7.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 +16 -4
- package/dist/sdd-engine/completion-guard.js +2 -3
- package/dist/sdd-engine/contracts.d.ts +172 -0
- package/dist/sdd-engine/contracts.js +235 -10
- package/dist/sdd-engine/evidence-checkpoints.d.ts +6 -0
- package/dist/sdd-engine/evidence-checkpoints.js +280 -0
- package/dist/sdd-engine/evidence-journal.d.ts +25 -0
- package/dist/sdd-engine/evidence-journal.js +326 -0
- package/dist/sdd-engine/feature-manifest.d.ts +2 -1
- package/dist/sdd-engine/host-rule-pack.d.ts +4 -0
- package/dist/sdd-engine/host-rule-pack.js +114 -55
- package/dist/sdd-engine/host-skill-reader.d.ts +8 -1
- package/dist/sdd-engine/host-skill-reader.js +73 -0
- package/dist/sdd-engine/resume-history.d.ts +35 -3
- package/dist/sdd-engine/resume-history.js +242 -13
- package/dist/sdd-engine/resume-views.d.ts +7 -6
- package/dist/sdd-engine/resume-views.js +246 -114
- package/dist/sdd-engine/task-content.d.ts +2 -1
- package/dist/sdd-engine/task-failures.d.ts +30 -13
- package/dist/sdd-engine/task-failures.js +284 -115
- package/dist/sdd-engine/task-window.d.ts +6 -3
- package/dist/sdd-engine/task-window.js +12 -23
- package/dist/sdd-engine/tools/compact-result.d.ts +35 -5
- package/dist/sdd-engine/tools/compact-result.js +279 -2
- package/dist/sdd-engine/tools/execution-tools.js +20 -9
- package/dist/sdd-engine/tools/workspace-tools.js +80 -51
- package/dist/sdd-engine/trinity-structure.d.ts +2 -2
- package/dist/sdd-engine/verification-inputs.d.ts +2 -1
- package/dist/sdd-engine/verification-policy.d.ts +7 -6
- package/dist/sdd-engine/verification-policy.js +74 -85
- package/dist/sdd-engine/verification-preflight.d.ts +9 -7
- package/dist/sdd-engine/verification-preflight.js +108 -89
- package/dist/sdd-engine/verification-receipts.d.ts +2 -2
- package/dist/sdd-engine/verification-receipts.js +2 -1
- package/dist/sdd-engine/verification-runner.d.ts +3 -1
- package/dist/sdd-engine/verification-runner.js +12 -7
- package/dist/types/completion.d.ts +183 -3
- package/dist/types/resume-views.d.ts +221 -2
- package/dist/types/sdd-engine.d.ts +52 -112
- package/dist/types/verification.d.ts +26 -9
- package/package.json +5 -5
- package/templates/AGENTS.md +4 -0
- package/templates/host/planu-sdd.md +4 -0
- package/templates/skills/preflight-guardian.md +4 -0
- package/templates/skills/reconciler.md +6 -0
- package/templates/skills/spec-architect.md +44 -0
- package/templates/skills/spec-executor.md +6 -0
- package/templates/skills/verification-auditor.md +6 -0
- package/dist/sdd-engine/tools/format-result.d.ts +0 -3
- package/dist/sdd-engine/tools/format-result.js +0 -22
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
export { uncertainCompletion, scopedFailure, cancelledVerification } from './task-failures.js';
|
|
2
|
+
import type * as completion from '../types/completion.js';
|
|
1
3
|
import type { SddFailure, SddResult } from '../types/sdd-engine.js';
|
|
2
|
-
import type { ScopedPolicy,
|
|
4
|
+
import type { ScopedPolicy, ScopedTaskSelector, ScopedVerificationSnapshot, VerificationPolicy } from '../types/verification.js';
|
|
3
5
|
export declare const DEFAULT_VERIFICATION_TIMEOUT_MS = 180000;
|
|
4
6
|
export declare function resolveVerificationPolicy(input?: unknown, workspaceRoot?: string, platform?: NodeJS.Platform): VerificationPolicy;
|
|
5
7
|
export declare function captureVerificationPolicy(raw: string | undefined, workspaceRoot?: string): VerificationPolicy;
|
|
6
8
|
export declare function verificationDigest(content: string | Uint8Array): string;
|
|
7
9
|
export declare function isScopedVerificationFeature(policy: ScopedPolicy, featureDirectory: string): Promise<boolean>;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function scopedVerificationPathMatches(policy: ScopedPolicy, workspaceRoot: string, tasksPath: string): boolean;
|
|
11
|
+
export declare function compareScopedVerificationPins(policy: ScopedPolicy, capture: completion.ScopedVerificationPinCapture): SddResult<completion.ScopedVerificationTaskPinCheck>;
|
|
12
|
+
export declare function readScopedVerificationSnapshot(policy: ScopedPolicy, tasksPath: string, workspaceRoot: string, requestedTaskId: string, selectTask: ScopedTaskSelector): Promise<completion.ScopedSnapshotResult>;
|
|
13
|
+
export declare function revalidateScopedVerificationSnapshot(policy: ScopedPolicy, snapshot: ScopedVerificationSnapshot, selectTask: ScopedTaskSelector): Promise<completion.ScopedSnapshotResult>;
|
|
11
14
|
export declare function persistScopedCompletionFiles(policy: ScopedPolicy, snapshot: ScopedVerificationSnapshot, writtenTasks: string, signal: AbortSignal): Promise<SddResult<null>>;
|
|
12
15
|
export declare function scopedFeaturePathFailure(policy: ScopedPolicy): Promise<SddFailure | null>;
|
|
13
16
|
export { scopedVerificationEnvironment } from './lock-integrity.js';
|
|
14
|
-
export declare function scopedFailure(details: Record<string, unknown>): SddFailure;
|
|
15
|
-
export declare function cancelledVerification(signal: AbortSignal): SddFailure | null;
|
|
16
17
|
//# sourceMappingURL=verification-policy.d.ts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { snapshotFailure, uncertainCompletion, cancelledVerification } from './task-failures.js';
|
|
2
|
+
export { uncertainCompletion, scopedFailure, cancelledVerification } from './task-failures.js';
|
|
1
3
|
import { createHash } from 'node:crypto';
|
|
2
4
|
import { lstatSync, realpathSync } from 'node:fs';
|
|
3
5
|
import * as fs from 'node:fs/promises';
|
|
@@ -79,21 +81,6 @@ export async function isScopedVerificationFeature(policy, featureDirectory) {
|
|
|
79
81
|
return false;
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
function snapshotFailure(workspace = false) {
|
|
83
|
-
return {
|
|
84
|
-
success: false,
|
|
85
|
-
error: {
|
|
86
|
-
code: workspace ? 'ERR_WORKSPACE_UNRESOLVED' : 'ERR_SPEC_DRIFT',
|
|
87
|
-
message: 'Scoped verification context does not match the trusted startup policy.',
|
|
88
|
-
trigger: 'sdd_complete_task',
|
|
89
|
-
details: {
|
|
90
|
-
reason: workspace
|
|
91
|
-
? 'verification_policy_workspace_mismatch'
|
|
92
|
-
: 'verification_policy_mismatch',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
84
|
class ScopedPathBindingError extends Error {
|
|
98
85
|
}
|
|
99
86
|
async function physicalIdentity(expected, directory) {
|
|
@@ -135,14 +122,63 @@ async function readUtf8(file, signal) {
|
|
|
135
122
|
const bytes = await fs.readFile(file, { signal });
|
|
136
123
|
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
137
124
|
}
|
|
138
|
-
export
|
|
139
|
-
|
|
125
|
+
export function scopedVerificationPathMatches(policy, workspaceRoot, tasksPath) {
|
|
126
|
+
return (workspaceRoot === policy.workspaceRoot &&
|
|
127
|
+
tasksPath === path.join(policy.workspaceRoot, '.sdd', 'features', policy.featureId, 'tasks.md'));
|
|
128
|
+
}
|
|
129
|
+
export function compareScopedVerificationPins(policy, capture) {
|
|
130
|
+
if (!scopedVerificationPathMatches(policy, capture.workspaceRoot, capture.tasksPath)) {
|
|
140
131
|
return snapshotFailure(true);
|
|
141
132
|
}
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
try {
|
|
134
|
+
const lock = JSON.parse(capture.lockContent);
|
|
135
|
+
const parsed = lockSchema.parse(lock);
|
|
136
|
+
if (verificationDigest(capture.lockContent) !== policy.lockSha256 ||
|
|
137
|
+
verificationDigest(capture.specContent) !== parsed.specHash ||
|
|
138
|
+
verificationDigest(capture.planContent) !== parsed.planHash ||
|
|
139
|
+
verificationDigest(capture.tasksContent) !== parsed.tasksHash) {
|
|
140
|
+
return snapshotFailure();
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
success: true,
|
|
144
|
+
data: (selected) => checkScopedSelection(policy, capture.taskId, selected),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return snapshotFailure();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function checkScopedSelection(policy, taskId, selected) {
|
|
152
|
+
if (taskId.toUpperCase() !== policy.taskId ||
|
|
153
|
+
selected?.taskId.toUpperCase() !== taskId.toUpperCase()) {
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
error: {
|
|
157
|
+
code: 'ERR_TASK_OUT_OF_SEQUENCE',
|
|
158
|
+
message: 'The requested task is not the granted active task.',
|
|
159
|
+
trigger: 'sdd_complete_task',
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (selected.command === null) {
|
|
164
|
+
return {
|
|
165
|
+
success: false,
|
|
166
|
+
error: {
|
|
167
|
+
code: 'ERR_VERIFICATION_MISSING',
|
|
168
|
+
message: 'The granted active task requires one valid Verification command.',
|
|
169
|
+
trigger: 'sdd_complete_task',
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return verificationDigest(selected.command) === policy.verificationCommandSha256
|
|
174
|
+
? { success: true, data: selected.command }
|
|
175
|
+
: snapshotFailure();
|
|
176
|
+
}
|
|
177
|
+
export async function readScopedVerificationSnapshot(policy, tasksPath, workspaceRoot, requestedTaskId, selectTask) {
|
|
178
|
+
if (!scopedVerificationPathMatches(policy, workspaceRoot, tasksPath)) {
|
|
144
179
|
return snapshotFailure(true);
|
|
145
180
|
}
|
|
181
|
+
const featurePath = path.dirname(tasksPath);
|
|
146
182
|
try {
|
|
147
183
|
const identities = await snapshotIdentities(policy);
|
|
148
184
|
const [specContent, planContent, tasksContent, lockContent] = await Promise.all([
|
|
@@ -151,52 +187,33 @@ export async function readScopedVerificationSnapshot(policy, tasksPath, workspac
|
|
|
151
187
|
readUtf8(path.join(featurePath, 'tasks.md')),
|
|
152
188
|
readUtf8(path.join(featurePath, '.lock')),
|
|
153
189
|
]);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
success: false,
|
|
168
|
-
error: {
|
|
169
|
-
code: 'ERR_TASK_OUT_OF_SEQUENCE',
|
|
170
|
-
message: 'The requested task is not the granted active task.',
|
|
171
|
-
trigger: 'sdd_complete_task',
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
if (selected.command === null) {
|
|
176
|
-
return {
|
|
177
|
-
success: false,
|
|
178
|
-
error: {
|
|
179
|
-
code: 'ERR_VERIFICATION_MISSING',
|
|
180
|
-
message: 'The granted active task requires one valid Verification command.',
|
|
181
|
-
trigger: 'sdd_complete_task',
|
|
182
|
-
},
|
|
183
|
-
};
|
|
190
|
+
const capture = {
|
|
191
|
+
workspaceRoot,
|
|
192
|
+
tasksPath,
|
|
193
|
+
taskId: requestedTaskId,
|
|
194
|
+
specContent,
|
|
195
|
+
planContent,
|
|
196
|
+
tasksContent,
|
|
197
|
+
lockContent,
|
|
198
|
+
};
|
|
199
|
+
const pins = compareScopedVerificationPins(policy, capture);
|
|
200
|
+
if (!pins.success) {
|
|
201
|
+
return pins;
|
|
184
202
|
}
|
|
185
|
-
if (
|
|
203
|
+
if (!sameIdentities(identities, await snapshotIdentities(policy))) {
|
|
186
204
|
return snapshotFailure();
|
|
187
205
|
}
|
|
206
|
+
const selected = pins.data(selectTask(tasksContent));
|
|
207
|
+
if (!selected.success) {
|
|
208
|
+
return selected;
|
|
209
|
+
}
|
|
188
210
|
return {
|
|
189
211
|
success: true,
|
|
190
212
|
data: Object.freeze({
|
|
191
|
-
|
|
213
|
+
...capture,
|
|
192
214
|
featureId: policy.featureId,
|
|
193
215
|
taskId: policy.taskId,
|
|
194
|
-
|
|
195
|
-
specContent,
|
|
196
|
-
planContent,
|
|
197
|
-
tasksContent,
|
|
198
|
-
lockContent,
|
|
199
|
-
command: selected.command,
|
|
216
|
+
command: selected.data,
|
|
200
217
|
timeoutMs: policy.timeoutMs,
|
|
201
218
|
identities,
|
|
202
219
|
}),
|
|
@@ -223,17 +240,6 @@ export async function revalidateScopedVerificationSnapshot(policy, snapshot, sel
|
|
|
223
240
|
}
|
|
224
241
|
return current;
|
|
225
242
|
}
|
|
226
|
-
export function uncertainCompletion() {
|
|
227
|
-
return {
|
|
228
|
-
success: false,
|
|
229
|
-
error: {
|
|
230
|
-
code: 'ERR_VERIFICATION_FAILED',
|
|
231
|
-
message: 'Completion persistence is uncertain; operator reconciliation is required.',
|
|
232
|
-
trigger: 'sdd_complete_task',
|
|
233
|
-
details: { reason: 'verification_completion_io', completionState: 'uncertain' },
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
243
|
export async function persistScopedCompletionFiles(policy, snapshot, writtenTasks, signal) {
|
|
238
244
|
const feature = path.dirname(snapshot.tasksPath);
|
|
239
245
|
const lockPath = path.join(feature, '.lock');
|
|
@@ -313,21 +319,4 @@ export async function scopedFeaturePathFailure(policy) {
|
|
|
313
319
|
}
|
|
314
320
|
}
|
|
315
321
|
export { scopedVerificationEnvironment } from './lock-integrity.js';
|
|
316
|
-
export function scopedFailure(details) {
|
|
317
|
-
return {
|
|
318
|
-
success: false,
|
|
319
|
-
error: {
|
|
320
|
-
code: 'ERR_VERIFICATION_FAILED',
|
|
321
|
-
message: 'Scoped verification did not produce a safely committed certificate.',
|
|
322
|
-
trigger: 'sdd_complete_task',
|
|
323
|
-
details,
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
export function cancelledVerification(signal) {
|
|
328
|
-
if (!signal.aborted) {
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
return scopedFailure({ reason: 'verification_cancelled', cancelled: true, timedOut: false });
|
|
332
|
-
}
|
|
333
322
|
//# sourceMappingURL=verification-policy.js.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import type * as completion from '../types/completion.js';
|
|
1
2
|
import type { PreflightAssessment } from '../types/resume-views.js';
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type * as engine from '../types/sdd-engine.js';
|
|
4
|
+
import type { ScopedPolicy, VerificationBudgetDiagnostic } from '../types/verification.js';
|
|
5
|
+
export declare function report(taskId: string | null, reasons: readonly engine.PreflightBlockerReason[], gates?: engine.VerificationPreflight['gates'], applicable?: boolean): engine.VerificationPreflight;
|
|
5
6
|
/** The same captured authority can be assessed by other read views without selecting again. */
|
|
6
|
-
export declare function assessVerificationPreflight(snapshot: CompletionSnapshot, root: WorkspaceRoot, workspaceRoot: string, active: ActiveTaskDetails | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal): Promise<PreflightAssessment>;
|
|
7
|
-
export declare function captureReadSnapshot(feature: string, root: WorkspaceRoot): Promise<PreflightReadSnapshot>;
|
|
8
|
-
export declare function revalidateReadSnapshot(snapshot: PreflightReadSnapshot, root: WorkspaceRoot, workspaceRoot: string): Promise<void>;
|
|
7
|
+
export declare function assessVerificationPreflight(snapshot: completion.CompletionSnapshot, root: completion.WorkspaceRoot, workspaceRoot: string, active: engine.ActiveTaskDetails | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal): Promise<PreflightAssessment>;
|
|
8
|
+
export declare function captureReadSnapshot(feature: string, root: completion.WorkspaceRoot): Promise<completion.PreflightReadSnapshot>;
|
|
9
|
+
export declare function revalidateReadSnapshot(snapshot: completion.PreflightReadSnapshot, root: completion.WorkspaceRoot, workspaceRoot: string): Promise<void>;
|
|
9
10
|
export declare function assertGuardAbsent(feature: string): Promise<void>;
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function observeVerificationBudget(context: completion.VerificationBudgetContext, policy?: ScopedPolicy, reader?: completion.VerificationBudgetReader): Promise<VerificationBudgetDiagnostic>;
|
|
12
|
+
export declare function getVerificationPreflight(tasksPath: string, workspaceRoot: string, extractCommand: (markdown: string) => string | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal, reader?: completion.VerificationBudgetReader): Promise<engine.SddResult<engine.ActiveTaskResult>>;
|
|
11
13
|
//# sourceMappingURL=verification-preflight.d.ts.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
|
-
import
|
|
2
|
+
import * as authority from './feature-authority.js';
|
|
3
3
|
import { inspectCompletionGuard } from './completion-guard.js';
|
|
4
4
|
import { captureCompletionSnapshot, revalidateCompletionSnapshot } from './completion-snapshot.js';
|
|
5
5
|
import { parseManifestContent, parseVerificationReceiptPolicy } from './feature-manifest.js';
|
|
6
6
|
import { activeTaskFromContent } from './task-content.js';
|
|
7
|
-
import
|
|
7
|
+
import * as failures from './task-failures.js';
|
|
8
8
|
import { captureReceiptEvidence, assessVerificationReceiptSet } from './verification-receipts.js';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
function report(taskId, reasons, gates = [], applicable = true) {
|
|
9
|
+
import * as inputs from './verification-inputs.js';
|
|
10
|
+
import * as policyOps from './verification-policy.js';
|
|
11
|
+
export function report(taskId, reasons, gates = [], applicable = true) {
|
|
12
12
|
const blockers = [...new Set(reasons)]
|
|
13
13
|
.sort()
|
|
14
14
|
.slice(0, 16)
|
|
@@ -31,39 +31,14 @@ function report(taskId, reasons, gates = [], applicable = true) {
|
|
|
31
31
|
gates,
|
|
32
32
|
blockers,
|
|
33
33
|
integration: 'not_run',
|
|
34
|
-
nextAction: applicable ? nextAction(actionReasons) : 'none',
|
|
34
|
+
nextAction: applicable ? failures.nextAction(actionReasons) : 'none',
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
function nextAction(reasons) {
|
|
38
|
-
if (reasons.has('unlocked')) {
|
|
39
|
-
return 'review_lock';
|
|
40
|
-
}
|
|
41
|
-
if (reasons.has('platform_unsupported') || reasons.has('receipt_scoped_unsupported')) {
|
|
42
|
-
return 'use_supported_runtime';
|
|
43
|
-
}
|
|
44
|
-
if (reasons.has('command_missing')) {
|
|
45
|
-
return 'restore_verification';
|
|
46
|
-
}
|
|
47
|
-
if (reasons.has('receipt_input_unavailable')) {
|
|
48
|
-
return 'fix_inputs';
|
|
49
|
-
}
|
|
50
|
-
if (reasons.has('receipt_observed_baseline_drift')) {
|
|
51
|
-
return 'review_observed_drift';
|
|
52
|
-
}
|
|
53
|
-
if (reasons.has('receipt_not_configured')) {
|
|
54
|
-
return 'restore_verification';
|
|
55
|
-
}
|
|
56
|
-
return reasons.size ? 'obtain_receipts' : 'attempt_integration';
|
|
57
|
-
}
|
|
58
37
|
function taskBlockers(active, task) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!['darwin', 'linux'].includes(process.platform)) {
|
|
64
|
-
reasons.push('platform_unsupported');
|
|
65
|
-
}
|
|
66
|
-
return reasons;
|
|
38
|
+
return [
|
|
39
|
+
...(!(task ? task.command : active.verificationCommand) ? ['command_missing'] : []),
|
|
40
|
+
...(!['darwin', 'linux'].includes(process.platform) ? ['platform_unsupported'] : []),
|
|
41
|
+
];
|
|
67
42
|
}
|
|
68
43
|
/** The same captured authority can be assessed by other read views without selecting again. */
|
|
69
44
|
export async function assessVerificationPreflight(snapshot, root, workspaceRoot, active, receipts, scopedPolicy, signal) {
|
|
@@ -72,7 +47,7 @@ export async function assessVerificationPreflight(snapshot, root, workspaceRoot,
|
|
|
72
47
|
}
|
|
73
48
|
const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
|
|
74
49
|
if (policy.status === 'invalid') {
|
|
75
|
-
throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
50
|
+
throw new authority.CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
76
51
|
}
|
|
77
52
|
const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
|
|
78
53
|
const reasons = taskBlockers(active, task);
|
|
@@ -82,19 +57,20 @@ export async function assessVerificationPreflight(snapshot, root, workspaceRoot,
|
|
|
82
57
|
}
|
|
83
58
|
return { preflight: report(active.taskId, reasons) };
|
|
84
59
|
}
|
|
85
|
-
if (scopedPolicy &&
|
|
60
|
+
if (scopedPolicy &&
|
|
61
|
+
(await policyOps.isScopedVerificationFeature(scopedPolicy, snapshot.featDir))) {
|
|
86
62
|
reasons.push('receipt_scoped_unsupported');
|
|
87
63
|
}
|
|
88
64
|
try {
|
|
89
65
|
const captured = await captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal);
|
|
90
66
|
if (!captured.success) {
|
|
91
67
|
if (captured.error.details?.reason !== 'receipt_observed_baseline_drift') {
|
|
92
|
-
throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
68
|
+
throw new authority.CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
93
69
|
}
|
|
94
70
|
return { preflight: report(active.taskId, [...reasons, 'receipt_observed_baseline_drift']) };
|
|
95
71
|
}
|
|
96
72
|
const assessed = assessVerificationReceiptSet(receipts, captured.data.evidence, policy.publicKey);
|
|
97
|
-
await revalidateVerificationInputs(captured.data.inputs, signal);
|
|
73
|
+
await inputs.revalidateVerificationInputs(captured.data.inputs, signal);
|
|
98
74
|
return {
|
|
99
75
|
preflight: report(active.taskId, [...reasons, ...assessed.blockers.map(({ reason }) => reason)], assessed.gates),
|
|
100
76
|
evidence: captured.data.evidence,
|
|
@@ -102,7 +78,8 @@ export async function assessVerificationPreflight(snapshot, root, workspaceRoot,
|
|
|
102
78
|
};
|
|
103
79
|
}
|
|
104
80
|
catch (error) {
|
|
105
|
-
if (error instanceof VerificationInputError &&
|
|
81
|
+
if (error instanceof inputs.VerificationInputError &&
|
|
82
|
+
error.reason === 'receipt_input_unavailable') {
|
|
106
83
|
return { preflight: report(active.taskId, [...reasons, 'receipt_input_unavailable']) };
|
|
107
84
|
}
|
|
108
85
|
throw error;
|
|
@@ -110,7 +87,7 @@ export async function assessVerificationPreflight(snapshot, root, workspaceRoot,
|
|
|
110
87
|
}
|
|
111
88
|
async function optionalArtifact(feature, name) {
|
|
112
89
|
try {
|
|
113
|
-
return await readArtifact(feature, name);
|
|
90
|
+
return await authority.readArtifact(feature, name);
|
|
114
91
|
}
|
|
115
92
|
catch (error) {
|
|
116
93
|
if (error.code === 'ENOENT') {
|
|
@@ -122,7 +99,7 @@ async function optionalArtifact(feature, name) {
|
|
|
122
99
|
async function requiredTaskArtifact(feature) {
|
|
123
100
|
const task = await optionalArtifact(feature, 'tasks.md');
|
|
124
101
|
if (!task) {
|
|
125
|
-
throw new CompletionGuardError('contract_drift', 'Task authority is unavailable.', 'ERR_TASK_NOT_FOUND');
|
|
102
|
+
throw new authority.CompletionGuardError('contract_drift', 'Task authority is unavailable.', 'ERR_TASK_NOT_FOUND');
|
|
126
103
|
}
|
|
127
104
|
return task;
|
|
128
105
|
}
|
|
@@ -141,14 +118,15 @@ export async function captureReadSnapshot(feature, root) {
|
|
|
141
118
|
catch (error) {
|
|
142
119
|
if (error.code === 'ENOENT') {
|
|
143
120
|
await requiredTaskArtifact(feature);
|
|
144
|
-
throw new CompletionGuardError('contract_drift', 'Preflight authority is unavailable.');
|
|
121
|
+
throw new authority.CompletionGuardError('contract_drift', 'Preflight authority is unavailable.');
|
|
145
122
|
}
|
|
146
|
-
if (!(error instanceof CompletionGuardError) ||
|
|
123
|
+
if (!(error instanceof authority.CompletionGuardError) ||
|
|
124
|
+
error.code !== 'ERR_SPEC_NOT_LOCKED') {
|
|
147
125
|
throw error;
|
|
148
126
|
}
|
|
149
127
|
}
|
|
150
|
-
const directories = await captureDirectories(feature, root.canonical);
|
|
151
|
-
const canonical = lastAuthorityDirectory(directories).directory;
|
|
128
|
+
const directories = await authority.captureDirectories(feature, root.canonical);
|
|
129
|
+
const canonical = authority.lastAuthorityDirectory(directories).directory;
|
|
152
130
|
const artifacts = {};
|
|
153
131
|
for (const name of ['.lock', 'spec.md', 'plan.md', 'tasks.md']) {
|
|
154
132
|
artifacts[name] =
|
|
@@ -157,7 +135,7 @@ export async function captureReadSnapshot(feature, root) {
|
|
|
157
135
|
: await optionalArtifact(canonical, name);
|
|
158
136
|
}
|
|
159
137
|
if (artifacts['.lock']) {
|
|
160
|
-
throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
138
|
+
throw new authority.CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
161
139
|
}
|
|
162
140
|
return { feature: canonical, directories, artifacts };
|
|
163
141
|
}
|
|
@@ -166,32 +144,32 @@ export async function revalidateReadSnapshot(snapshot, root, workspaceRoot) {
|
|
|
166
144
|
await revalidateCompletionSnapshot(snapshot.locked);
|
|
167
145
|
}
|
|
168
146
|
else {
|
|
169
|
-
await revalidateDirectories(snapshot.directories);
|
|
147
|
+
await authority.revalidateDirectories(snapshot.directories);
|
|
170
148
|
for (const name of ['.lock', 'spec.md', 'plan.md', 'tasks.md']) {
|
|
171
149
|
const current = await optionalArtifact(snapshot.feature, name);
|
|
172
150
|
const expected = snapshot.artifacts[name];
|
|
173
151
|
if (current?.content !== expected?.content ||
|
|
174
|
-
(current && expected && !sameIdentity(current.identity, expected.identity))) {
|
|
175
|
-
throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
152
|
+
(current && expected && !authority.sameIdentity(current.identity, expected.identity))) {
|
|
153
|
+
throw new authority.CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
176
154
|
}
|
|
177
155
|
}
|
|
178
|
-
await revalidateDirectories(snapshot.directories);
|
|
156
|
+
await authority.revalidateDirectories(snapshot.directories);
|
|
179
157
|
}
|
|
180
|
-
const currentRoot = await captureVerificationRoot(workspaceRoot);
|
|
158
|
+
const currentRoot = await inputs.captureVerificationRoot(workspaceRoot);
|
|
181
159
|
if (root.canonical !== currentRoot.canonical ||
|
|
182
160
|
root.stat.dev !== currentRoot.stat.dev ||
|
|
183
161
|
root.stat.ino !== currentRoot.stat.ino ||
|
|
184
162
|
root.stat.mode !== currentRoot.stat.mode ||
|
|
185
163
|
root.stat.uid !== currentRoot.stat.uid ||
|
|
186
164
|
root.stat.gid !== currentRoot.stat.gid) {
|
|
187
|
-
throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
165
|
+
throw new authority.CompletionGuardError('contract_drift', 'Preflight authority changed.');
|
|
188
166
|
}
|
|
189
167
|
await assertGuardAbsent(snapshot.feature);
|
|
190
168
|
}
|
|
191
169
|
export async function assertGuardAbsent(feature) {
|
|
192
170
|
const guard = await inspectCompletionGuard(feature);
|
|
193
171
|
if (guard) {
|
|
194
|
-
throw new CompletionGuardError(guard.reason, 'Preflight authority is guarded.', 'ERR_VERIFICATION_FAILED');
|
|
172
|
+
throw new authority.CompletionGuardError(guard.reason, 'Preflight authority is guarded.', 'ERR_VERIFICATION_FAILED');
|
|
195
173
|
}
|
|
196
174
|
}
|
|
197
175
|
function receiptActiveTask(snapshot, active) {
|
|
@@ -202,41 +180,70 @@ function receiptActiveTask(snapshot, active) {
|
|
|
202
180
|
const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
|
|
203
181
|
return task ? { ...active, verificationCommand: task.command } : active;
|
|
204
182
|
}
|
|
205
|
-
function
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
return
|
|
209
|
-
success: false,
|
|
210
|
-
error: {
|
|
211
|
-
code: 'ERR_VERIFICATION_FAILED',
|
|
212
|
-
message: 'Verification preflight is unavailable.',
|
|
213
|
-
trigger: 'sdd_get_active_task',
|
|
214
|
-
},
|
|
215
|
-
};
|
|
183
|
+
function scopedPinDenial(context, policy) {
|
|
184
|
+
const { snapshot, workspaceRoot, tasksPath, selected } = context;
|
|
185
|
+
if (!snapshot.locked || !selected) {
|
|
186
|
+
return 'verification_state_unavailable';
|
|
216
187
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
trigger: 'sdd_get_active_task',
|
|
233
|
-
details: { reason },
|
|
234
|
-
},
|
|
235
|
-
};
|
|
188
|
+
const pins = policyOps.compareScopedVerificationPins(policy, {
|
|
189
|
+
...snapshot.locked,
|
|
190
|
+
workspaceRoot,
|
|
191
|
+
tasksPath,
|
|
192
|
+
taskId: selected.taskId,
|
|
193
|
+
});
|
|
194
|
+
const checked = pins.success ? pins.data(selected) : pins;
|
|
195
|
+
if (!checked.success) {
|
|
196
|
+
return checked.error.details?.reason === 'verification_policy_workspace_mismatch'
|
|
197
|
+
? 'verification_policy_workspace_mismatch'
|
|
198
|
+
: checked.error.code === 'ERR_VERIFICATION_MISSING'
|
|
199
|
+
? 'command_missing'
|
|
200
|
+
: 'verification_policy_mismatch';
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
236
203
|
}
|
|
237
|
-
export async function
|
|
204
|
+
export async function observeVerificationBudget(context, policy, reader) {
|
|
205
|
+
const { tasksPath, workspaceRoot, snapshot, root, selected } = context;
|
|
206
|
+
const early = failures.budgetPrecondition(context);
|
|
207
|
+
if (early) {
|
|
208
|
+
return failures.deniedBudget(early);
|
|
209
|
+
}
|
|
210
|
+
if (!selected || !snapshot.locked) {
|
|
211
|
+
return failures.deniedBudget('verification_state_unavailable');
|
|
212
|
+
}
|
|
213
|
+
if (!policy) {
|
|
214
|
+
return failures.defaultBudget('default_policy');
|
|
215
|
+
}
|
|
216
|
+
if (!(await policyOps.isScopedVerificationFeature(policy, snapshot.feature))) {
|
|
217
|
+
return failures.defaultBudget('outside_scoped_grant');
|
|
218
|
+
}
|
|
219
|
+
if (!policyOps.scopedVerificationPathMatches(policy, workspaceRoot, tasksPath) ||
|
|
220
|
+
root.canonical !== policy.workspaceRoot ||
|
|
221
|
+
snapshot.feature !== path.dirname(tasksPath)) {
|
|
222
|
+
return failures.deniedBudget('verification_policy_workspace_mismatch');
|
|
223
|
+
}
|
|
224
|
+
const state = reader?.(selected.taskId);
|
|
225
|
+
if (state === undefined) {
|
|
226
|
+
return failures.deniedBudget('verification_state_unavailable');
|
|
227
|
+
}
|
|
228
|
+
if (state !== null) {
|
|
229
|
+
return failures.deniedBudget(state);
|
|
230
|
+
}
|
|
231
|
+
if (selected.taskId.toUpperCase() !== policy.taskId) {
|
|
232
|
+
return failures.defaultBudget('outside_scoped_grant');
|
|
233
|
+
}
|
|
234
|
+
const mismatch = scopedPinDenial(context, policy);
|
|
235
|
+
return mismatch
|
|
236
|
+
? failures.deniedBudget(mismatch)
|
|
237
|
+
: {
|
|
238
|
+
version: 1,
|
|
239
|
+
admission: 'scoped',
|
|
240
|
+
effectiveTimeoutMs: policy.timeoutMs,
|
|
241
|
+
reason: 'trusted_startup_match',
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export async function getVerificationPreflight(tasksPath, workspaceRoot, extractCommand, receipts, scopedPolicy, signal, reader) {
|
|
238
245
|
try {
|
|
239
|
-
const root = await captureVerificationRoot(workspaceRoot);
|
|
246
|
+
const root = await inputs.captureVerificationRoot(workspaceRoot);
|
|
240
247
|
const snapshot = await captureReadSnapshot(path.dirname(tasksPath), root);
|
|
241
248
|
await assertGuardAbsent(snapshot.feature);
|
|
242
249
|
const current = activeTaskFromContent(snapshot.artifacts['tasks.md']?.content ?? '', extractCommand);
|
|
@@ -247,11 +254,23 @@ export async function getVerificationPreflight(tasksPath, workspaceRoot, extract
|
|
|
247
254
|
...current.data,
|
|
248
255
|
activeTask: receiptActiveTask(snapshot.locked, current.data.activeTask),
|
|
249
256
|
};
|
|
250
|
-
const
|
|
257
|
+
const basePreflight = snapshot.locked
|
|
251
258
|
? (await assessVerificationPreflight(snapshot.locked, root, workspaceRoot, data.activeTask, receipts, scopedPolicy, signal)).preflight
|
|
252
259
|
: report(data.activeTask?.taskId ?? null, ['unlocked']);
|
|
260
|
+
const budget = await observeVerificationBudget({
|
|
261
|
+
tasksPath,
|
|
262
|
+
workspaceRoot,
|
|
263
|
+
root,
|
|
264
|
+
snapshot,
|
|
265
|
+
selected: data.activeTask && {
|
|
266
|
+
taskId: data.activeTask.taskId,
|
|
267
|
+
command: data.activeTask.verificationCommand,
|
|
268
|
+
},
|
|
269
|
+
preflight: basePreflight,
|
|
270
|
+
}, scopedPolicy, reader);
|
|
271
|
+
const verificationPreflight = failures.withVerificationBudget(basePreflight, budget);
|
|
253
272
|
if (signal?.aborted) {
|
|
254
|
-
throw new CompletionGuardError('cancelled', 'Preflight was cancelled.');
|
|
273
|
+
throw new authority.CompletionGuardError('cancelled', 'Preflight was cancelled.');
|
|
255
274
|
}
|
|
256
275
|
await revalidateReadSnapshot(snapshot, root, workspaceRoot);
|
|
257
276
|
const manifest = [
|
|
@@ -269,7 +288,7 @@ export async function getVerificationPreflight(tasksPath, workspaceRoot, extract
|
|
|
269
288
|
};
|
|
270
289
|
}
|
|
271
290
|
catch (error) {
|
|
272
|
-
return preflightError(error);
|
|
291
|
+
return failures.preflightError(error);
|
|
273
292
|
}
|
|
274
293
|
}
|
|
275
294
|
//# sourceMappingURL=verification-preflight.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ReceiptPolicyResult, ReceiptTaskPolicy, WorkspaceRoot, CompletionSnapshot } from '../types/completion.js';
|
|
1
2
|
export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
|
|
2
|
-
import type { CompleteTaskResult,
|
|
3
|
-
import type { CompletionSnapshot } from '../types/completion.js';
|
|
3
|
+
import type { CompleteTaskResult, SddResult, VerificationEvidence } from '../types/sdd-engine.js';
|
|
4
4
|
import type { CompletionLease } from './completion-guard.js';
|
|
5
5
|
import { captureVerificationInputs } from './verification-inputs.js';
|
|
6
6
|
import type { ScopedVerificationRun, ScopedVerificationRunnerOptions } from '../types/verification.js';
|
|
@@ -4,7 +4,7 @@ import * as path from 'node:path';
|
|
|
4
4
|
import { captureCompletionSnapshot, persistCompletionSnapshot, revalidateCompletionSnapshot, } from './completion-snapshot.js';
|
|
5
5
|
import { hashArtifact } from './feature-authority.js';
|
|
6
6
|
import { activeTaskFromContent, markReceiptTaskVerified, remainingTaskCount, } from './task-content.js';
|
|
7
|
-
import { completionFailure, receiptFailure, unsupportedVerificationPlatform, verificationFailed, } from './task-failures.js';
|
|
7
|
+
import { completionFailure, receiptFailure, unsupportedVerificationPlatform, verificationFailed, verificationProcessEvidence, } from './task-failures.js';
|
|
8
8
|
import { captureVerificationInputs, captureVerificationRoot, revalidateVerificationInputs, } from './verification-inputs.js';
|
|
9
9
|
export async function captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal) {
|
|
10
10
|
if (path.resolve(snapshot.featDir, '../../..') !== root.canonical) {
|
|
@@ -86,6 +86,7 @@ export async function completeReceiptTask(snapshot, workspaceRoot, policy, task,
|
|
|
86
86
|
data: {
|
|
87
87
|
completedTaskId: task.taskId,
|
|
88
88
|
verificationSummary: summary,
|
|
89
|
+
verificationProcess: verificationProcessEvidence(run),
|
|
89
90
|
remainingTasks,
|
|
90
91
|
verificationEvidenceSummary: {
|
|
91
92
|
version: 1,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ScopedVerificationCompletionContext, VerificationBudgetReader } from '../types/completion.js';
|
|
1
2
|
import type { SddResult, CompleteTaskResult } from '../types/sdd-engine.js';
|
|
2
|
-
import type { ScopedVerificationRun, ScopedPolicy,
|
|
3
|
+
import type { ScopedVerificationRun, ScopedPolicy, ScopedVerificationRunnerOptions, ScopedVerificationRunnerTiming } from '../types/verification.js';
|
|
3
4
|
export declare function runScopedVerification(options: ScopedVerificationRunnerOptions, timing?: ScopedVerificationRunnerTiming): Promise<ScopedVerificationRun>;
|
|
4
5
|
export declare class ScopedVerificationCoordinator {
|
|
5
6
|
private readonly policy;
|
|
@@ -11,6 +12,7 @@ export declare class ScopedVerificationCoordinator {
|
|
|
11
12
|
constructor(policy: ScopedPolicy);
|
|
12
13
|
shutdown(): Promise<void>;
|
|
13
14
|
complete(context: ScopedVerificationCompletionContext): Promise<SddResult<CompleteTaskResult> | null>;
|
|
15
|
+
readonly inspectState: VerificationBudgetReader;
|
|
14
16
|
private stateFailure;
|
|
15
17
|
private execute;
|
|
16
18
|
}
|