@planu/cli 8.3.0 → 8.5.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +86 -2
  3. package/dist/sdd-engine/contracts.d.ts +13 -3
  4. package/dist/sdd-engine/contracts.js +48 -10
  5. package/dist/sdd-engine/feature-manifest.d.ts +2 -5
  6. package/dist/sdd-engine/feature-manifest.js +109 -184
  7. package/dist/sdd-engine/host-rule-pack.d.ts +5 -0
  8. package/dist/sdd-engine/host-rule-pack.js +106 -43
  9. package/dist/sdd-engine/host-skill-reader.d.ts +6 -0
  10. package/dist/sdd-engine/host-skill-reader.js +187 -0
  11. package/dist/sdd-engine/lock-integrity.d.ts +1 -0
  12. package/dist/sdd-engine/lock-integrity.js +25 -17
  13. package/dist/sdd-engine/receipt-assessment.d.ts +12 -0
  14. package/dist/sdd-engine/receipt-assessment.js +223 -0
  15. package/dist/sdd-engine/resume-history.d.ts +6 -0
  16. package/dist/sdd-engine/resume-history.js +117 -0
  17. package/dist/sdd-engine/resume-views.d.ts +9 -0
  18. package/dist/sdd-engine/resume-views.js +149 -0
  19. package/dist/sdd-engine/server.js +2 -4
  20. package/dist/sdd-engine/task-content.d.ts +18 -0
  21. package/dist/sdd-engine/task-content.js +36 -1
  22. package/dist/sdd-engine/task-window.d.ts +1 -0
  23. package/dist/sdd-engine/task-window.js +8 -1
  24. package/dist/sdd-engine/tools/compact-result.d.ts +6 -0
  25. package/dist/sdd-engine/tools/compact-result.js +66 -0
  26. package/dist/sdd-engine/tools/execution-tools.d.ts +1 -11
  27. package/dist/sdd-engine/tools/execution-tools.js +14 -32
  28. package/dist/sdd-engine/tools/workspace-tools.d.ts +1 -1
  29. package/dist/sdd-engine/tools/workspace-tools.js +17 -9
  30. package/dist/sdd-engine/tools.d.ts +2 -1
  31. package/dist/sdd-engine/tools.js +4 -2
  32. package/dist/sdd-engine/trinity-structure.d.ts +25 -0
  33. package/dist/sdd-engine/trinity-structure.js +317 -0
  34. package/dist/sdd-engine/verification-preflight.d.ts +11 -0
  35. package/dist/sdd-engine/verification-preflight.js +275 -0
  36. package/dist/sdd-engine/verification-receipts.d.ts +2 -10
  37. package/dist/sdd-engine/verification-receipts.js +2 -169
  38. package/dist/sdd-engine/workspace-root.d.ts +1 -0
  39. package/dist/sdd-engine/workspace-root.js +1 -0
  40. package/dist/types/completion.d.ts +9 -2
  41. package/dist/types/resume-views.d.ts +55 -0
  42. package/dist/types/resume-views.js +2 -0
  43. package/dist/types/sdd-engine.d.ts +78 -0
  44. package/package.json +1 -1
  45. package/templates/AGENTS.md +12 -0
  46. package/templates/host/planu-sdd.md +12 -0
@@ -0,0 +1,275 @@
1
+ import * as path from 'node:path';
2
+ import { CompletionGuardError, captureDirectories, lastAuthorityDirectory, readArtifact, revalidateDirectories, sameIdentity, } from './feature-authority.js';
3
+ import { inspectCompletionGuard } from './completion-guard.js';
4
+ import { captureCompletionSnapshot, revalidateCompletionSnapshot } from './completion-snapshot.js';
5
+ import { parseManifestContent, parseVerificationReceiptPolicy } from './feature-manifest.js';
6
+ import { activeTaskFromContent } from './task-content.js';
7
+ import { completionError } from './task-failures.js';
8
+ import { captureReceiptEvidence, assessVerificationReceiptSet } from './verification-receipts.js';
9
+ import { captureVerificationRoot, revalidateVerificationInputs, VerificationInputError, } from './verification-inputs.js';
10
+ import { isScopedVerificationFeature } from './verification-policy.js';
11
+ function report(taskId, reasons, gates = [], applicable = true) {
12
+ const blockers = [...new Set(reasons)]
13
+ .sort()
14
+ .slice(0, 16)
15
+ .map((reason) => ({ reason }));
16
+ const rejectedGate = gates.some((gate) => gate.state !== 'receipt_valid');
17
+ const actionReasons = new Set(reasons);
18
+ for (const gate of gates) {
19
+ if (gate.reason) {
20
+ actionReasons.add(gate.reason);
21
+ }
22
+ }
23
+ return {
24
+ version: 1,
25
+ taskId,
26
+ status: !applicable
27
+ ? 'not_applicable'
28
+ : blockers.length || rejectedGate
29
+ ? 'blocked'
30
+ : 'ready_to_attempt',
31
+ gates,
32
+ blockers,
33
+ integration: 'not_run',
34
+ nextAction: applicable ? nextAction(actionReasons) : 'none',
35
+ };
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
+ function taskBlockers(active, task) {
59
+ const reasons = [];
60
+ if (!(task ? task.command : active.verificationCommand)) {
61
+ reasons.push('command_missing');
62
+ }
63
+ if (!['darwin', 'linux'].includes(process.platform)) {
64
+ reasons.push('platform_unsupported');
65
+ }
66
+ return reasons;
67
+ }
68
+ /** The same captured authority can be assessed by other read views without selecting again. */
69
+ export async function assessVerificationPreflight(snapshot, root, workspaceRoot, active, receipts, scopedPolicy, signal) {
70
+ if (!active) {
71
+ return { preflight: report(null, [], [], false) };
72
+ }
73
+ const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
74
+ if (policy.status === 'invalid') {
75
+ throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
76
+ }
77
+ const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
78
+ const reasons = taskBlockers(active, task);
79
+ if (policy.status !== 'ready' || !task) {
80
+ if (receipts !== undefined) {
81
+ reasons.push('receipt_not_configured');
82
+ }
83
+ return { preflight: report(active.taskId, reasons) };
84
+ }
85
+ if (scopedPolicy && (await isScopedVerificationFeature(scopedPolicy, snapshot.featDir))) {
86
+ reasons.push('receipt_scoped_unsupported');
87
+ }
88
+ try {
89
+ const captured = await captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal);
90
+ if (!captured.success) {
91
+ if (captured.error.details?.reason !== 'receipt_observed_baseline_drift') {
92
+ throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
93
+ }
94
+ return { preflight: report(active.taskId, [...reasons, 'receipt_observed_baseline_drift']) };
95
+ }
96
+ const assessed = assessVerificationReceiptSet(receipts, captured.data.evidence, policy.publicKey);
97
+ await revalidateVerificationInputs(captured.data.inputs, signal);
98
+ return {
99
+ preflight: report(active.taskId, [...reasons, ...assessed.blockers.map(({ reason }) => reason)], assessed.gates),
100
+ evidence: captured.data.evidence,
101
+ inputs: captured.data.inputs,
102
+ };
103
+ }
104
+ catch (error) {
105
+ if (error instanceof VerificationInputError && error.reason === 'receipt_input_unavailable') {
106
+ return { preflight: report(active.taskId, [...reasons, 'receipt_input_unavailable']) };
107
+ }
108
+ throw error;
109
+ }
110
+ }
111
+ async function optionalArtifact(feature, name) {
112
+ try {
113
+ return await readArtifact(feature, name);
114
+ }
115
+ catch (error) {
116
+ if (error.code === 'ENOENT') {
117
+ return undefined;
118
+ }
119
+ throw error;
120
+ }
121
+ }
122
+ async function requiredTaskArtifact(feature) {
123
+ const task = await optionalArtifact(feature, 'tasks.md');
124
+ if (!task) {
125
+ throw new CompletionGuardError('contract_drift', 'Task authority is unavailable.', 'ERR_TASK_NOT_FOUND');
126
+ }
127
+ return task;
128
+ }
129
+ export async function captureReadSnapshot(feature, root) {
130
+ try {
131
+ const locked = await captureCompletionSnapshot(feature, {
132
+ workspaceRoot: root.canonical,
133
+ });
134
+ return {
135
+ feature: locked.featDir,
136
+ directories: locked.directories,
137
+ artifacts: locked.artifacts,
138
+ locked,
139
+ };
140
+ }
141
+ catch (error) {
142
+ if (error.code === 'ENOENT') {
143
+ await requiredTaskArtifact(feature);
144
+ throw new CompletionGuardError('contract_drift', 'Preflight authority is unavailable.');
145
+ }
146
+ if (!(error instanceof CompletionGuardError) || error.code !== 'ERR_SPEC_NOT_LOCKED') {
147
+ throw error;
148
+ }
149
+ }
150
+ const directories = await captureDirectories(feature, root.canonical);
151
+ const canonical = lastAuthorityDirectory(directories).directory;
152
+ const artifacts = {};
153
+ for (const name of ['.lock', 'spec.md', 'plan.md', 'tasks.md']) {
154
+ artifacts[name] =
155
+ name === 'tasks.md'
156
+ ? await requiredTaskArtifact(canonical)
157
+ : await optionalArtifact(canonical, name);
158
+ }
159
+ if (artifacts['.lock']) {
160
+ throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
161
+ }
162
+ return { feature: canonical, directories, artifacts };
163
+ }
164
+ export async function revalidateReadSnapshot(snapshot, root, workspaceRoot) {
165
+ if (snapshot.locked) {
166
+ await revalidateCompletionSnapshot(snapshot.locked);
167
+ }
168
+ else {
169
+ await revalidateDirectories(snapshot.directories);
170
+ for (const name of ['.lock', 'spec.md', 'plan.md', 'tasks.md']) {
171
+ const current = await optionalArtifact(snapshot.feature, name);
172
+ const expected = snapshot.artifacts[name];
173
+ if (current?.content !== expected?.content ||
174
+ (current && expected && !sameIdentity(current.identity, expected.identity))) {
175
+ throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
176
+ }
177
+ }
178
+ await revalidateDirectories(snapshot.directories);
179
+ }
180
+ const currentRoot = await captureVerificationRoot(workspaceRoot);
181
+ if (root.canonical !== currentRoot.canonical ||
182
+ root.stat.dev !== currentRoot.stat.dev ||
183
+ root.stat.ino !== currentRoot.stat.ino ||
184
+ root.stat.mode !== currentRoot.stat.mode ||
185
+ root.stat.uid !== currentRoot.stat.uid ||
186
+ root.stat.gid !== currentRoot.stat.gid) {
187
+ throw new CompletionGuardError('contract_drift', 'Preflight authority changed.');
188
+ }
189
+ await assertGuardAbsent(snapshot.feature);
190
+ }
191
+ export async function assertGuardAbsent(feature) {
192
+ const guard = await inspectCompletionGuard(feature);
193
+ if (guard) {
194
+ throw new CompletionGuardError(guard.reason, 'Preflight authority is guarded.', 'ERR_VERIFICATION_FAILED');
195
+ }
196
+ }
197
+ function receiptActiveTask(snapshot, active) {
198
+ if (!snapshot || !active) {
199
+ return active;
200
+ }
201
+ const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
202
+ const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
203
+ return task ? { ...active, verificationCommand: task.command } : active;
204
+ }
205
+ function preflightError(error) {
206
+ const failure = completionError(error, 'sdd_get_active_task');
207
+ if (failure.success) {
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
+ };
216
+ }
217
+ const rawReason = failure.error.details?.reason;
218
+ const reasons = new Set([
219
+ 'guard_present',
220
+ 'contract_drift',
221
+ 'cancelled',
222
+ 'persistence_uncertain',
223
+ 'receipt_input_drift',
224
+ 'receipt_input_unavailable',
225
+ ]);
226
+ const reason = typeof rawReason === 'string' && reasons.has(rawReason) ? rawReason : 'failed';
227
+ return {
228
+ success: false,
229
+ error: {
230
+ code: failure.error.code,
231
+ message: 'Verification preflight is unavailable; inspect the bounded reason before retrying.',
232
+ trigger: 'sdd_get_active_task',
233
+ details: { reason },
234
+ },
235
+ };
236
+ }
237
+ export async function getVerificationPreflight(tasksPath, workspaceRoot, extractCommand, receipts, scopedPolicy, signal) {
238
+ try {
239
+ const root = await captureVerificationRoot(workspaceRoot);
240
+ const snapshot = await captureReadSnapshot(path.dirname(tasksPath), root);
241
+ await assertGuardAbsent(snapshot.feature);
242
+ const current = activeTaskFromContent(snapshot.artifacts['tasks.md']?.content ?? '', extractCommand);
243
+ if (!current.success) {
244
+ return current;
245
+ }
246
+ const data = {
247
+ ...current.data,
248
+ activeTask: receiptActiveTask(snapshot.locked, current.data.activeTask),
249
+ };
250
+ const verificationPreflight = snapshot.locked
251
+ ? (await assessVerificationPreflight(snapshot.locked, root, workspaceRoot, data.activeTask, receipts, scopedPolicy, signal)).preflight
252
+ : report(data.activeTask?.taskId ?? null, ['unlocked']);
253
+ if (signal?.aborted) {
254
+ throw new CompletionGuardError('cancelled', 'Preflight was cancelled.');
255
+ }
256
+ await revalidateReadSnapshot(snapshot, root, workspaceRoot);
257
+ const manifest = [
258
+ ...parseManifestContent(snapshot.artifacts['plan.md']?.content ?? '').allowedFiles.entries(),
259
+ ].map(([filePath, permission]) => ({ path: filePath, permission }));
260
+ return {
261
+ success: true,
262
+ data: {
263
+ ...data,
264
+ locked: !!snapshot.locked,
265
+ trinity: snapshot.locked ? 'ready' : 'unlocked',
266
+ manifest,
267
+ verificationPreflight,
268
+ },
269
+ };
270
+ }
271
+ catch (error) {
272
+ return preflightError(error);
273
+ }
274
+ }
275
+ //# sourceMappingURL=verification-preflight.js.map
@@ -1,17 +1,9 @@
1
- import { type KeyObject } from 'node:crypto';
2
- import { z } from 'zod';
3
- import type { CompleteTaskResult, ReceiptPolicyResult, ReceiptSetResult, ReceiptTaskPolicy, SddResult, VerificationEvidence, WorkspaceRoot } from '../types/sdd-engine.js';
1
+ export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
2
+ import type { CompleteTaskResult, ReceiptPolicyResult, ReceiptTaskPolicy, SddResult, VerificationEvidence, WorkspaceRoot } from '../types/sdd-engine.js';
4
3
  import type { CompletionSnapshot } from '../types/completion.js';
5
4
  import type { CompletionLease } from './completion-guard.js';
6
5
  import { captureVerificationInputs } from './verification-inputs.js';
7
6
  import type { ScopedVerificationRun, ScopedVerificationRunnerOptions } from '../types/verification.js';
8
- export declare const maxVerificationReceipts = 32;
9
- export declare const gateIdPattern: RegExp;
10
- export declare const taskIdPattern: RegExp;
11
- export declare const featureIdPattern: RegExp;
12
- export declare const sha256Schema: z.ZodString;
13
- export declare function importReceiptPublicKey(value: string): KeyObject | undefined;
14
- export declare function validateVerificationReceiptSet(input: unknown, challenge: VerificationEvidence, publicKey: KeyObject): ReceiptSetResult;
15
7
  export declare function captureReceiptEvidence(snapshot: CompletionSnapshot, workspaceRoot: string, policy: Extract<ReceiptPolicyResult, {
16
8
  status: 'ready';
17
9
  }>, task: ReceiptTaskPolicy, root: WorkspaceRoot, signal?: AbortSignal): Promise<SddResult<{
@@ -1,178 +1,11 @@
1
- import { createHash, createPublicKey, verify } from 'node:crypto';
1
+ export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
2
+ import { validateVerificationReceiptSet } from './receipt-assessment.js';
2
3
  import * as path from 'node:path';
3
- import { z } from 'zod';
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
7
  import { completionFailure, receiptFailure, unsupportedVerificationPlatform, verificationFailed, } from './task-failures.js';
8
8
  import { captureVerificationInputs, captureVerificationRoot, revalidateVerificationInputs, } from './verification-inputs.js';
9
- export const maxVerificationReceipts = 32;
10
- export const gateIdPattern = /^[a-z][a-z0-9-]{0,31}$/u;
11
- export const taskIdPattern = /^TASK-[1-9][0-9]{0,18}$/u;
12
- export const featureIdPattern = /^FEAT[-_][A-Z0-9_-]{1,123}$/u;
13
- export const sha256Schema = z.string().regex(/^[0-9a-f]{64}$/u);
14
- function decodeCanonicalBase64Url(value) {
15
- if (!/^[A-Za-z0-9_-]+$/u.test(value)) {
16
- return undefined;
17
- }
18
- const decoded = Buffer.from(value, 'base64url');
19
- return decoded.toString('base64url') === value ? decoded : undefined;
20
- }
21
- export function importReceiptPublicKey(value) {
22
- const der = value.length <= 128 ? decodeCanonicalBase64Url(value) : undefined;
23
- if (!der) {
24
- return undefined;
25
- }
26
- try {
27
- const key = createPublicKey({ key: der, format: 'der', type: 'spki' });
28
- if (key.asymmetricKeyType !== 'ed25519') {
29
- return undefined;
30
- }
31
- return key.export({ format: 'der', type: 'spki' }).equals(der) ? key : undefined;
32
- }
33
- catch {
34
- return undefined;
35
- }
36
- }
37
- const receiptSchema = z.strictObject({
38
- version: z.literal(1),
39
- featureId: z.string().regex(featureIdPattern),
40
- taskId: z.string().regex(taskIdPattern),
41
- workspaceSha256: sha256Schema,
42
- lockSha256: sha256Schema,
43
- candidateSha256: sha256Schema,
44
- observedSha256: sha256Schema,
45
- gateId: z.string().regex(gateIdPattern),
46
- procedureSha256: sha256Schema,
47
- environmentSha256: sha256Schema,
48
- outcome: z.enum(['pass', 'fail', 'skipped', 'partial']),
49
- evidenceSha256: sha256Schema,
50
- signature: z.string().regex(/^[A-Za-z0-9_-]{86}$/u),
51
- });
52
- const RECEIPT_KEY_COUNT = Object.keys(receiptSchema.shape).length;
53
- function receiptMessage(receipt) {
54
- return [
55
- 'planu.verification-receipt.v1',
56
- receipt.featureId,
57
- receipt.taskId,
58
- receipt.workspaceSha256,
59
- receipt.lockSha256,
60
- receipt.candidateSha256,
61
- receipt.observedSha256,
62
- receipt.gateId,
63
- receipt.procedureSha256,
64
- receipt.environmentSha256,
65
- receipt.outcome,
66
- receipt.evidenceSha256,
67
- ];
68
- }
69
- function decodeReceipt(input) {
70
- if (typeof input !== 'object' ||
71
- input === null ||
72
- Object.keys(input).length !== RECEIPT_KEY_COUNT) {
73
- return undefined;
74
- }
75
- const parsed = receiptSchema.safeParse(input);
76
- if (!parsed.success) {
77
- return undefined;
78
- }
79
- const signature = decodeCanonicalBase64Url(parsed.data.signature);
80
- if (signature?.length !== 64) {
81
- return undefined;
82
- }
83
- return { receipt: parsed.data, message: receiptMessage(parsed.data), signature };
84
- }
85
- function matchCoverage(signed, gates) {
86
- const required = new Set(gates.map((gate) => gate.id));
87
- const byGate = new Map();
88
- for (const entry of signed) {
89
- const gateId = entry.receipt.gateId;
90
- if (!required.has(gateId)) {
91
- return { ok: false, reason: 'receipt_unexpected' };
92
- }
93
- if (byGate.has(gateId)) {
94
- return { ok: false, reason: 'receipt_duplicate', gateId };
95
- }
96
- byGate.set(gateId, entry);
97
- }
98
- const matched = [];
99
- for (const gate of gates) {
100
- const entry = byGate.get(gate.id);
101
- if (!entry) {
102
- return { ok: false, reason: 'receipt_missing', gateId: gate.id };
103
- }
104
- matched.push({ ...entry, gate });
105
- }
106
- return { ok: true, matched };
107
- }
108
- function validateClaims(matched, challenge) {
109
- const checks = [
110
- [
111
- (receipt) => receipt.workspaceSha256 === challenge.workspaceSha256 &&
112
- receipt.featureId === challenge.featureId &&
113
- receipt.taskId === challenge.taskId &&
114
- receipt.lockSha256 === challenge.lockSha256,
115
- 'receipt_context_mismatch',
116
- ],
117
- [
118
- (receipt) => receipt.candidateSha256 === challenge.candidateSha256,
119
- 'receipt_candidate_mismatch',
120
- ],
121
- [(receipt) => receipt.observedSha256 === challenge.observedSha256, 'receipt_observed_mismatch'],
122
- [
123
- (receipt, gate) => receipt.procedureSha256 === gate.procedureSha256,
124
- 'receipt_procedure_mismatch',
125
- ],
126
- [
127
- (receipt, gate) => receipt.environmentSha256 === gate.environmentSha256,
128
- 'receipt_environment_mismatch',
129
- ],
130
- [(receipt) => receipt.outcome === 'pass', 'receipt_non_pass'],
131
- ];
132
- for (const [accepts, reason] of checks) {
133
- const failed = matched.find(({ receipt, gate }) => !accepts(receipt, gate));
134
- if (failed) {
135
- return { ok: false, reason, gateId: failed.gate.id };
136
- }
137
- }
138
- return undefined;
139
- }
140
- export function validateVerificationReceiptSet(input, challenge, publicKey) {
141
- const gates = [...challenge.gates].sort((left, right) => left.id < right.id ? -1 : left.id === right.id ? 0 : 1);
142
- if (input === undefined) {
143
- const gateId = gates[0]?.id;
144
- return { ok: false, reason: 'receipt_missing', ...(gateId ? { gateId } : {}) };
145
- }
146
- if (!Array.isArray(input) || input.length < 1 || input.length > maxVerificationReceipts) {
147
- return { ok: false, reason: 'receipt_malformed' };
148
- }
149
- const signed = [];
150
- for (const raw of input) {
151
- const receipt = decodeReceipt(raw);
152
- if (!receipt) {
153
- return { ok: false, reason: 'receipt_malformed' };
154
- }
155
- signed.push(receipt);
156
- }
157
- const coverage = matchCoverage(signed, gates);
158
- if (!coverage.ok) {
159
- return coverage;
160
- }
161
- for (const { receipt, message, signature } of coverage.matched) {
162
- if (!verify(null, Buffer.from(JSON.stringify(message), 'utf8'), publicKey, signature)) {
163
- return { ok: false, reason: 'receipt_invalid_signature', gateId: receipt.gateId };
164
- }
165
- }
166
- const rejected = validateClaims(coverage.matched, challenge);
167
- if (rejected) {
168
- return rejected;
169
- }
170
- const entries = coverage.matched.map(({ message, receipt }) => [message, receipt.signature]);
171
- const receiptSetSha256 = createHash('sha256')
172
- .update(JSON.stringify(['planu.verification-receipt-set.v1', entries]), 'utf8')
173
- .digest('hex');
174
- return { ok: true, gateCount: entries.length, receiptSetSha256 };
175
- }
176
9
  export async function captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal) {
177
10
  if (path.resolve(snapshot.featDir, '../../..') !== root.canonical) {
178
11
  return completionFailure('contract_drift');
@@ -13,4 +13,5 @@ export declare function readTextInsideWorkspace(workspaceRoot: string, absoluteP
13
13
  ok: false;
14
14
  reason: 'outside' | 'missing';
15
15
  }>;
16
+ export { readTextInsideWorkspaceDetailed } from './host-skill-reader.js';
16
17
  //# sourceMappingURL=workspace-root.d.ts.map
@@ -233,4 +233,5 @@ function unique(values) {
233
233
  }
234
234
  return out;
235
235
  }
236
+ export { readTextInsideWorkspaceDetailed } from './host-skill-reader.js';
236
237
  //# sourceMappingURL=workspace-root.js.map
@@ -1,4 +1,4 @@
1
- import type { SddLockFile, ErrorCode } from './sdd-engine.js';
1
+ import type { SddLockFile, ErrorCode, TrinityIssue } from './sdd-engine.js';
2
2
  export type CompletionFailureReason = 'guard_present' | 'contract_drift' | 'cancelled' | 'persistence_uncertain';
3
3
  export interface PhysicalIdentity {
4
4
  dev: number;
@@ -58,7 +58,8 @@ export type TrinityCompleteness = {
58
58
  code: ErrorCode;
59
59
  message: string;
60
60
  details?: {
61
- missing: string[];
61
+ missing?: string[];
62
+ issues?: TrinityIssue[];
62
63
  };
63
64
  };
64
65
  export type SealResult = {
@@ -74,4 +75,10 @@ export interface PreviousLock {
74
75
  previous?: SddLockFile;
75
76
  artifact?: ArtifactCapture;
76
77
  }
78
+ export interface PreflightReadSnapshot {
79
+ feature: string;
80
+ directories: AuthorityDirectory[];
81
+ artifacts: Partial<Record<'spec.md' | 'plan.md' | 'tasks.md' | '.lock', ArtifactCapture | undefined>>;
82
+ locked?: CompletionSnapshot;
83
+ }
77
84
  //# sourceMappingURL=completion.d.ts.map
@@ -0,0 +1,55 @@
1
+ import type { PreflightAction, RelockHistoryCursor, VerificationEvidence, VerificationInputSnapshot, VerificationPreflight } from './sdd-engine.js';
2
+ export interface PreflightAssessment {
3
+ preflight: VerificationPreflight;
4
+ evidence?: VerificationEvidence;
5
+ inputs?: VerificationInputSnapshot;
6
+ }
7
+ export interface ResumeCheckpoint {
8
+ version: 1;
9
+ featureId: string;
10
+ status: 'active' | 'unlocked' | 'complete' | 'no_tasks';
11
+ progress: {
12
+ total: number;
13
+ completed: number;
14
+ };
15
+ task: {
16
+ id: string;
17
+ index: number;
18
+ } | null;
19
+ contract: {
20
+ specSha256: string;
21
+ planSha256: string;
22
+ tasksSha256: string;
23
+ lockSha256: string;
24
+ } | null;
25
+ candidate: Pick<VerificationEvidence, 'workspaceSha256' | 'candidateSha256' | 'observedSha256'> | null;
26
+ gates: VerificationPreflight['gates'];
27
+ readiness: VerificationPreflight['status'];
28
+ integration: 'pending' | 'not_applicable';
29
+ blockers: VerificationPreflight['blockers'];
30
+ nextAction: PreflightAction | 'inspect_tasks';
31
+ history: {
32
+ count: number;
33
+ lockSha256: string;
34
+ firstCursor: RelockHistoryCursor | null;
35
+ } | null;
36
+ }
37
+ export interface RelockHistoryRecord {
38
+ index: number;
39
+ lockedAt: string;
40
+ specHash: string;
41
+ planHash: string;
42
+ tasksHash?: string;
43
+ recordSha256: string;
44
+ reasonSha256: string;
45
+ }
46
+ export interface RelockHistoryPage {
47
+ version: 1;
48
+ featureId: string;
49
+ lockSha256: string;
50
+ count: number;
51
+ records: RelockHistoryRecord[];
52
+ nextCursor: RelockHistoryCursor | null;
53
+ }
54
+ export type CompactFailureReason = 'unlocked' | 'history_cursor_stale' | 'history_cursor_invalid' | 'workspace_unresolved' | 'guard_present' | 'persistence_uncertain' | 'contract_drift' | 'tasks_missing' | 'artifact_unavailable' | 'history_invalid' | 'compact_identifier_invalid' | 'compact_input_invalid' | 'compact_response_too_large' | 'cancelled';
55
+ //# sourceMappingURL=resume-views.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resume-views.js.map