@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +118 -3
  3. package/dist/sdd-engine/completion-snapshot.d.ts +5 -1
  4. package/dist/sdd-engine/completion-snapshot.js +79 -2
  5. package/dist/sdd-engine/contracts.d.ts +6 -3
  6. package/dist/sdd-engine/contracts.js +30 -3
  7. package/dist/sdd-engine/feature-authority.d.ts +3 -1
  8. package/dist/sdd-engine/feature-authority.js +33 -1
  9. package/dist/sdd-engine/feature-manifest.d.ts +4 -5
  10. package/dist/sdd-engine/feature-manifest.js +206 -93
  11. package/dist/sdd-engine/host-rule-pack.d.ts +5 -0
  12. package/dist/sdd-engine/host-rule-pack.js +103 -43
  13. package/dist/sdd-engine/host-skill-reader.d.ts +6 -0
  14. package/dist/sdd-engine/host-skill-reader.js +187 -0
  15. package/dist/sdd-engine/lock-integrity.d.ts +3 -2
  16. package/dist/sdd-engine/lock-integrity.js +30 -18
  17. package/dist/sdd-engine/receipt-assessment.d.ts +12 -0
  18. package/dist/sdd-engine/receipt-assessment.js +223 -0
  19. package/dist/sdd-engine/server.js +2 -4
  20. package/dist/sdd-engine/task-content.d.ts +19 -1
  21. package/dist/sdd-engine/task-content.js +128 -3
  22. package/dist/sdd-engine/task-failures.d.ts +2 -0
  23. package/dist/sdd-engine/task-failures.js +34 -0
  24. package/dist/sdd-engine/task-window.d.ts +3 -4
  25. package/dist/sdd-engine/task-window.js +49 -79
  26. package/dist/sdd-engine/tools/execution-tools.d.ts +1 -11
  27. package/dist/sdd-engine/tools/execution-tools.js +86 -57
  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-inputs.d.ts +12 -0
  35. package/dist/sdd-engine/verification-inputs.js +302 -0
  36. package/dist/sdd-engine/verification-preflight.d.ts +4 -0
  37. package/dist/sdd-engine/verification-preflight.js +271 -0
  38. package/dist/sdd-engine/verification-receipts.d.ts +16 -0
  39. package/dist/sdd-engine/verification-receipts.js +98 -0
  40. package/dist/sdd-engine/workspace-root.d.ts +1 -0
  41. package/dist/sdd-engine/workspace-root.js +1 -0
  42. package/dist/types/completion.d.ts +9 -2
  43. package/dist/types/sdd-engine.d.ts +203 -0
  44. package/package.json +1 -1
  45. package/templates/AGENTS.md +9 -1
  46. package/templates/host/planu-sdd.md +9 -0
  47. package/templates/skills/spec-architect.md +1 -0
@@ -1,4 +1,4 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
3
- export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle): void;
3
+ export declare function registerWorkspaceTools(server: McpServer, workspace: SddWorkspaceHandle, bundledVersion?: string): void;
4
4
  //# sourceMappingURL=workspace-tools.d.ts.map
@@ -6,19 +6,21 @@ import { TaskWindowManager } from '../task-window.js';
6
6
  import { formatResult } from './format-result.js';
7
7
  import { homeFallbackFailure } from '../workspace-root.js';
8
8
  import { prepareProjectInitialization } from '../workspace-init.js';
9
- import { writeLockedTrinity } from '../lock-integrity.js';
9
+ import { readTrinityFailureIssues, writeLockedTrinity } from '../lock-integrity.js';
10
10
  import { CompletionGuardError } from '../feature-authority.js';
11
11
  import { reserveAutomaticFeatureDirectory, createExplicitFeatureDirectory, collectFeatures, featurePathFailure, writeFeatureArtifacts, } from './feature-store.js';
12
- import { copyGlobalRules, installCursorGuard, installHostRulePack, installHostSkillPack, inspectHostSkillPack, } from '../host-rule-pack.js';
12
+ import { copyGlobalRules, installCursorGuard, installHostRulePack, installHostSkillPack, inspectHostSkillPack, inspectHostSkillPackDetailed, } from '../host-rule-pack.js';
13
13
  const moduleDir = path.dirname(fileURLToPath(import.meta.url));
14
14
  const MISSING_SDD_HINT = 'No .sdd directory in the client project. Call sdd_init_workspace with scope=project. MCP hosts should advertise roots; do not pin PLANU_WORKSPACE globally.';
15
15
  const LEGACY_SPECS_HINT = 'Planu ignores planu/specs. Do not create SPEC-* stubs or copy a FEAT into that tree. Retire host hooks that require planu/specs/SPEC-*/spec.md; the only contract is .sdd/features/FEAT-*.';
16
- async function composeWorkspaceHint(workspaceRoot, extra) {
16
+ async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
17
17
  const legacySpecsPresent = await fs
18
18
  .access(path.join(workspaceRoot, 'planu', 'specs'))
19
19
  .then(() => true)
20
20
  .catch(() => false);
21
- const pack = await inspectHostSkillPack(workspaceRoot).catch(() => 'Planu host skill verification was unavailable. Run sdd_init_workspace for requested project setup and read the matching role.');
21
+ const pack = suppliedPack
22
+ ? suppliedPack.hint
23
+ : await inspectHostSkillPack(workspaceRoot).catch(() => 'Planu host skill verification was unavailable. Run sdd_init_workspace for requested project setup and read the matching role.');
22
24
  const combined = [extra, pack, legacySpecsPresent ? LEGACY_SPECS_HINT : undefined]
23
25
  .filter((item) => item !== undefined)
24
26
  .join(' ');
@@ -37,10 +39,10 @@ async function composeWorkspaceHint(workspaceRoot, extra) {
37
39
  }
38
40
  return bounded;
39
41
  }
40
- export function registerWorkspaceTools(server, workspace) {
42
+ export function registerWorkspaceTools(server, workspace, bundledVersion) {
41
43
  const taskWindow = new TaskWindowManager();
42
44
  registerInitTool(server, workspace);
43
- registerListTool(server, workspace, taskWindow);
45
+ registerListTool(server, workspace, taskWindow, bundledVersion);
44
46
  registerCreateTool(server, workspace);
45
47
  registerLockTool(server, workspace);
46
48
  }
@@ -96,7 +98,7 @@ function registerInitTool(server, workspace) {
96
98
  });
97
99
  });
98
100
  }
99
- function registerListTool(server, workspace, taskWindow) {
101
+ function registerListTool(server, workspace, taskWindow, bundledVersion) {
100
102
  server.registerTool('sdd_list_features', {
101
103
  description: 'Lists executable Planu v8 FEAT-* features from .sdd/features only.',
102
104
  inputSchema: ListFeaturesInputSchema.shape,
@@ -117,12 +119,14 @@ function registerListTool(server, workspace, taskWindow) {
117
119
  return formatResult(collected);
118
120
  }
119
121
  const featuresList = collected.data;
120
- const hint = await composeWorkspaceHint(resolved.workspaceRoot, resolved.sddPresent ? undefined : MISSING_SDD_HINT);
122
+ const skillScan = await inspectHostSkillPackDetailed(resolved.workspaceRoot, bundledVersion ?? 'unknown');
123
+ const hint = await composeWorkspaceHint(resolved.workspaceRoot, resolved.sddPresent ? undefined : MISSING_SDD_HINT, skillScan);
121
124
  return formatResult({
122
125
  success: true,
123
126
  data: {
124
127
  total: featuresList.length,
125
128
  features: featuresList,
129
+ hostSkills: skillScan.hostSkills,
126
130
  workspaceRoot: resolved.workspaceRoot,
127
131
  sddPresent: resolved.sddPresent,
128
132
  source: resolved.source,
@@ -219,6 +223,7 @@ async function executeLockSpec(featDir, featureId, relock, reason) {
219
223
  outcome = await writeLockedTrinity(featDir, featureId, relock, reason);
220
224
  }
221
225
  catch (error) {
226
+ const issues = readTrinityFailureIssues(error);
222
227
  return formatResult({
223
228
  success: false,
224
229
  error: {
@@ -227,7 +232,10 @@ async function executeLockSpec(featDir, featureId, relock, reason) {
227
232
  ? error.message
228
233
  : 'The feature could not be safely locked.',
229
234
  trigger: 'sdd_lock_spec',
230
- details: { reason: error instanceof CompletionGuardError ? error.reason : 'failed' },
235
+ details: {
236
+ reason: error instanceof CompletionGuardError ? error.reason : 'failed',
237
+ ...(issues ? { issues } : {}),
238
+ },
231
239
  },
232
240
  });
233
241
  }
@@ -1,5 +1,6 @@
1
1
  import type { VerificationPolicy } from '../types/verification.js';
2
2
  import type { TaskWindowManager } from './task-window.js';
3
3
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
- export declare function registerUltralightSddTools(server: McpServer, pinnedRoot?: string, policy?: VerificationPolicy): TaskWindowManager;
4
+ export declare const bundledPackageVersion: string;
5
+ export declare function registerUltralightSddTools(server: McpServer, pinnedRoot?: string, policy?: VerificationPolicy, bundledVersion?: string): TaskWindowManager;
5
6
  //# sourceMappingURL=tools.d.ts.map
@@ -1,9 +1,11 @@
1
+ import { readFileSync } from 'node:fs';
1
2
  import { McpClientWorkspace } from './client-workspace.js';
2
3
  import { registerWorkspaceTools } from './tools/workspace-tools.js';
3
4
  import { registerExecutionTools } from './tools/execution-tools.js';
4
- export function registerUltralightSddTools(server, pinnedRoot, policy) {
5
+ export const bundledPackageVersion = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
6
+ export function registerUltralightSddTools(server, pinnedRoot, policy, bundledVersion = bundledPackageVersion) {
5
7
  const workspace = new McpClientWorkspace(server, pinnedRoot);
6
- registerWorkspaceTools(server, workspace);
8
+ registerWorkspaceTools(server, workspace, bundledVersion);
7
9
  return registerExecutionTools(server, workspace, policy);
8
10
  }
9
11
  //# sourceMappingURL=tools.js.map
@@ -0,0 +1,25 @@
1
+ import type { z } from 'zod';
2
+ import { CompletionGuardError } from './feature-authority.js';
3
+ import type { ReceiptPolicyText, ReceiptPolicyResult, TaskBlock, ManifestEntry, ParsedManifest, TrinityIssue } from '../types/sdd-engine.js';
4
+ import type { TrinityCompleteness } from '../types/completion.js';
5
+ export declare function assessTrinityCompleteness(specContent: string, planContent: string, tasksContent: string): TrinityCompleteness;
6
+ export declare function parseManifestContent(content: string): ParsedManifest;
7
+ export declare function manifestEntries(content: string): ManifestEntry[];
8
+ export declare function toPosixPath(value: string): string;
9
+ export declare class TrinityReadError extends CompletionGuardError {
10
+ readonly issues: TrinityIssue[];
11
+ constructor(error: CompletionGuardError, artifact: TrinityIssue['artifact']);
12
+ }
13
+ export declare function readTrinityFailureIssues(error: unknown): TrinityIssue[] | undefined;
14
+ export declare function policyText(plan: string): ReceiptPolicyText;
15
+ export declare function invalidTask(block: TaskBlock, duplicateLineIndex?: number): Extract<ReceiptPolicyResult, {
16
+ status: 'invalid';
17
+ }>;
18
+ export declare function invalidCandidate(entries: readonly ManifestEntry[], paths: readonly string[]): ManifestEntry | undefined;
19
+ export declare function candidateIssue(entry: ManifestEntry | undefined): TrinityIssue;
20
+ export declare function policyIssueLine(issue: z.core.$ZodIssue, locations: ReadonlyMap<string, number>): number | undefined;
21
+ export declare function candidateCreationIssue(rawPath: string, creates: readonly {
22
+ path: string;
23
+ requiredFromTaskId: string;
24
+ }[], requiredFrom: number | undefined, locations: ReadonlyMap<string, number>): TrinityIssue;
25
+ //# sourceMappingURL=trinity-structure.d.ts.map
@@ -0,0 +1,317 @@
1
+ import { hasReceiptDirective, insideMarkdownBlock } from './task-content.js';
2
+ import { taskIdPattern } from './verification-receipts.js';
3
+ import { disjointPaths, isEvidencePath, CompletionGuardError } from './feature-authority.js';
4
+ import * as path from 'node:path';
5
+ const CHECKBOX_TASK = /^[-*]\s*\[[ xX]\]/u;
6
+ const BDD_KEYWORDS = [/\bGIVEN\b/u, /\bWHEN\b/u, /\bTHEN\b/u];
7
+ export function assessTrinityCompleteness(specContent, planContent, tasksContent) {
8
+ const missing = [];
9
+ if (!hasHeading(specContent, 'Out-of-Scope')) {
10
+ missing.push('out_of_scope');
11
+ }
12
+ if (!hasHeading(specContent, 'Error Matrix')) {
13
+ missing.push('error_matrix');
14
+ }
15
+ if (!BDD_KEYWORDS.every((keyword) => keyword.test(specContent))) {
16
+ missing.push('bdd');
17
+ }
18
+ if (!hasHeading(planContent, 'Frozen Dependencies')) {
19
+ missing.push('frozen_dependencies');
20
+ }
21
+ const hasTask = tasksContent.split('\n').some((line) => CHECKBOX_TASK.test(line.trim()));
22
+ const manifest = scanManifest(planContent);
23
+ if (!manifest.hasPath) {
24
+ missing.push('manifest_path');
25
+ }
26
+ if (!hasTask) {
27
+ missing.push('checkbox_task');
28
+ }
29
+ const issues = boundedTrinityIssues([...missing.map(missingIssue), ...manifest.issues]);
30
+ if (manifest.globDelete) {
31
+ return {
32
+ ok: false,
33
+ code: 'ERR_TRINITY_INCOMPLETE',
34
+ message: 'DELETE File Manifest entries must be exact paths, not globs.',
35
+ details: { issues },
36
+ };
37
+ }
38
+ if (manifest.protectedWrite !== null) {
39
+ return {
40
+ ok: false,
41
+ code: 'ERR_TRINITY_INCOMPLETE',
42
+ message: 'File Manifest cannot grant writes on protected root paths.',
43
+ details: { issues },
44
+ };
45
+ }
46
+ if (missing.length === 0) {
47
+ return { ok: true };
48
+ }
49
+ return {
50
+ ok: false,
51
+ code: 'ERR_TRINITY_INCOMPLETE',
52
+ message: 'Lock requires Out-of-Scope, Error Matrix, GIVEN/WHEN/THEN acceptance criteria, Frozen Dependencies, a File Manifest path, and at least one checkbox task.',
53
+ details: { missing, issues },
54
+ };
55
+ }
56
+ function hasHeading(content, needle) {
57
+ const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
58
+ return new RegExp(`^#{1,3}\\s+.*${escaped}`, 'imu').test(content);
59
+ }
60
+ const PROTECTED_ROOTS = ['.sdd', '.git', 'planu/specs'];
61
+ function scanManifest(planContent) {
62
+ const effective = new Map(manifestEntries(planContent).map((entry) => [toPosixPath(entry.rawPath), entry]));
63
+ const issues = [];
64
+ let globDelete = false;
65
+ let protectedWrite = null;
66
+ for (const [entryPath, { permission, line }] of effective) {
67
+ if (permission === 'DELETE' && entryPath.includes('*')) {
68
+ globDelete = true;
69
+ issues.push({ artifact: 'plan.md', rule: 'glob_delete', line });
70
+ }
71
+ const normalized = path.posix.normalize(entryPath).toLowerCase();
72
+ if (permission !== 'READ_ONLY' &&
73
+ PROTECTED_ROOTS.some((root) => normalized === root || normalized.startsWith(`${root}/`))) {
74
+ protectedWrite ??= entryPath;
75
+ issues.push({ artifact: 'plan.md', rule: 'protected_write', line });
76
+ }
77
+ }
78
+ return { hasPath: effective.size > 0, globDelete, protectedWrite, issues };
79
+ }
80
+ function missingIssue(rule) {
81
+ const artifact = ['out_of_scope', 'error_matrix', 'bdd'].includes(rule)
82
+ ? 'spec.md'
83
+ : rule === 'checkbox_task'
84
+ ? 'tasks.md'
85
+ : 'plan.md';
86
+ return { artifact, rule: rule };
87
+ }
88
+ function boundedTrinityIssues(issues) {
89
+ const order = ['spec.md', 'plan.md', 'tasks.md'];
90
+ return [...issues]
91
+ .sort((left, right) => order.indexOf(left.artifact) - order.indexOf(right.artifact) ||
92
+ (left.line ?? 0) - (right.line ?? 0) ||
93
+ (left.rule < right.rule ? -1 : left.rule > right.rule ? 1 : 0))
94
+ .slice(0, 12);
95
+ }
96
+ export function parseManifestContent(content) {
97
+ const allowedFiles = new Map();
98
+ for (const { rawPath, permission } of manifestEntries(content)) {
99
+ allowedFiles.set(toPosixPath(rawPath), permission);
100
+ }
101
+ return { allowedFiles };
102
+ }
103
+ export function manifestEntries(content) {
104
+ const entries = [];
105
+ let inManifestSection = false;
106
+ for (const [index, rawLine] of content.split('\n').entries()) {
107
+ const line = rawLine.trim();
108
+ if (/^#{1,3}\s+/.test(line)) {
109
+ inManifestSection = /^#{1,3}\s+.*file\s+manifest/i.test(line);
110
+ continue;
111
+ }
112
+ if (inManifestSection && /^[-*]\s+/.test(line)) {
113
+ const entry = parseManifestLine(line);
114
+ if (entry && toPosixPath(entry.rawPath).toLowerCase() !== 'none') {
115
+ entries.push({ ...entry, line: index + 1 });
116
+ }
117
+ }
118
+ }
119
+ return entries;
120
+ }
121
+ function parseManifestLine(rawLine) {
122
+ const item = rawLine.replace(/^[-*]\s+/, '').trim();
123
+ const prefix = /^(CREATE|MODIFY|READ_ONLY|DELETE):\s*`?([^`\s#]+)`?\s*$/i.exec(item);
124
+ if (prefix?.[1] && prefix[2]) {
125
+ return {
126
+ rawPath: prefix[2],
127
+ permission: prefix[1].toUpperCase(),
128
+ };
129
+ }
130
+ const postfix = /^`?([^`\s:#]+)`?:\s*(CREATE|MODIFY|READ_ONLY|DELETE)\s*$/i.exec(item);
131
+ if (postfix?.[1] && postfix[2]) {
132
+ return {
133
+ rawPath: postfix[1],
134
+ permission: postfix[2].toUpperCase(),
135
+ };
136
+ }
137
+ return undefined;
138
+ }
139
+ export function toPosixPath(value) {
140
+ const posix = value.replaceAll('\\', '/');
141
+ const absolute = posix.startsWith('/');
142
+ const joined = posix
143
+ .split('/')
144
+ .filter((part) => part !== '' && part !== '.')
145
+ .join('/');
146
+ return absolute ? `/${joined}` : joined;
147
+ }
148
+ export class TrinityReadError extends CompletionGuardError {
149
+ issues;
150
+ constructor(error, artifact) {
151
+ super(error.reason, error.message, error.code);
152
+ this.issues = [{ artifact, rule: 'artifact_unreadable' }];
153
+ }
154
+ }
155
+ export function readTrinityFailureIssues(error) {
156
+ return error instanceof TrinityReadError ? [...error.issues] : undefined;
157
+ }
158
+ function policySourceLocations(text, firstLine) {
159
+ const locations = new Map();
160
+ const stack = [];
161
+ for (const [index, line] of text.split('\n').entries()) {
162
+ const value = line.trim().replace(/,$/u, '');
163
+ const indent = line.length - line.trimStart().length;
164
+ if (index === 0 && value === '{') {
165
+ stack.push({ path: '', root: true, kind: 'object', indent, nextArrayIndex: 0 });
166
+ continue;
167
+ }
168
+ const parent = stack.at(-1);
169
+ if (!parent) {
170
+ return new Map();
171
+ }
172
+ if (value === '}' || value === ']') {
173
+ if (indent !== parent.indent) {
174
+ return new Map();
175
+ }
176
+ stack.pop();
177
+ continue;
178
+ }
179
+ const located = policyValueSource(value, parent);
180
+ if (parent.kind === 'array') {
181
+ stack[stack.length - 1] = { ...parent, nextArrayIndex: parent.nextArrayIndex + 1 };
182
+ }
183
+ if (!located || indent !== parent.indent + 2) {
184
+ return new Map();
185
+ }
186
+ locations.set(located.path, firstLine + index);
187
+ if (located.value === '{' || located.value === '[') {
188
+ stack.push({
189
+ path: located.path,
190
+ root: false,
191
+ kind: located.value === '{' ? 'object' : 'array',
192
+ indent,
193
+ nextArrayIndex: 0,
194
+ });
195
+ }
196
+ }
197
+ return stack.length === 0 ? locations : new Map();
198
+ }
199
+ function policyValueSource(value, parent) {
200
+ if (parent.kind === 'array') {
201
+ const result = { path: parent.path + '/' + String(parent.nextArrayIndex), value };
202
+ return result;
203
+ }
204
+ const property = /^("(?:[^"\\]|\\.)*"): (.+)$/u.exec(value);
205
+ if (!property?.[1] || property[2] === undefined) {
206
+ return undefined;
207
+ }
208
+ let key;
209
+ try {
210
+ key = JSON.parse(property[1]);
211
+ }
212
+ catch {
213
+ return undefined;
214
+ }
215
+ if (typeof key !== 'string') {
216
+ return undefined;
217
+ }
218
+ const segment = policySourceKey(key);
219
+ return {
220
+ path: parent.root ? segment : parent.path + '/' + segment,
221
+ value: property[2],
222
+ };
223
+ }
224
+ const POLICY_LIMIT = 65_536;
225
+ const RECEIPT_HEADING = /^#{1,6}\s+Verification\s+Receipts(?:\s*$|\s*v[0-9])/iu;
226
+ const FENCE = String.fromCharCode(96).repeat(3);
227
+ export function policyText(plan) {
228
+ const lines = plan.replaceAll('\r\n', '\n').split('\n');
229
+ const headings = lines.flatMap((line, index) => RECEIPT_HEADING.test(line.trim()) ? [index] : []);
230
+ const start = headings[0];
231
+ if (start === undefined) {
232
+ return { text: undefined };
233
+ }
234
+ const invalidStart = insideMarkdownBlock(lines.slice(0, start)) ||
235
+ lines[start]?.trim() !== '## Verification Receipts v1';
236
+ const offendingHeading = invalidStart ? start : (headings[1] ?? start);
237
+ const headingLine = offendingHeading + 1;
238
+ if (headings.length !== 1 || invalidStart) {
239
+ return { text: null, line: headingLine };
240
+ }
241
+ const after = lines.findIndex((line, index) => index > start && /^#{1,2}\s/u.test(line.trim()));
242
+ const sectionLines = lines.slice(start + 1, after < 0 ? undefined : after);
243
+ const section = sectionLines.join('\n').trim();
244
+ const prefix = FENCE + 'json\n';
245
+ const suffix = '\n' + FENCE;
246
+ if (!section.startsWith(prefix) || !section.endsWith(suffix)) {
247
+ return { text: null };
248
+ }
249
+ const payload = section.slice(prefix.length, -suffix.length);
250
+ const fenceIndex = sectionLines.findIndex((line) => line.trim().length > 0);
251
+ const blankLines = payload.split('\n').findIndex((line) => line.trim().length > 0);
252
+ const text = Buffer.byteLength(payload) <= POLICY_LIMIT ? payload.trim() : null;
253
+ return {
254
+ text,
255
+ locations: text === null
256
+ ? undefined
257
+ : policySourceLocations(text, start + fenceIndex + Math.max(blankLines, 0) + 3),
258
+ };
259
+ }
260
+ export function invalidTask(block, duplicateLineIndex) {
261
+ const id = block.explicitId ?? block.id;
262
+ const directives = block.lines.flatMap((line, index) => hasReceiptDirective(line) ? [index] : []);
263
+ const offset = directives[1] ?? directives[0] ?? -1;
264
+ const issue = {
265
+ artifact: 'tasks.md',
266
+ rule: 'receipt_policy_invalid',
267
+ ...(duplicateLineIndex !== undefined
268
+ ? { line: duplicateLineIndex + 1 }
269
+ : offset < 0
270
+ ? {}
271
+ : { line: block.lineIndex + offset + 2 }),
272
+ };
273
+ return {
274
+ status: 'invalid',
275
+ ...(taskIdPattern.test(id) ? { taskId: id } : {}),
276
+ issue,
277
+ };
278
+ }
279
+ export function invalidCandidate(entries, paths) {
280
+ const bad = entries.find(({ rawPath, permission }, index) => !isEvidencePath(rawPath) ||
281
+ permission === 'DELETE' ||
282
+ !disjointPaths(paths.slice(0, index + 1)));
283
+ return bad && (!isEvidencePath(bad.rawPath) || bad.permission === 'DELETE') ? bad : undefined;
284
+ }
285
+ export function candidateIssue(entry) {
286
+ return {
287
+ artifact: 'plan.md',
288
+ rule: 'receipt_policy_invalid',
289
+ ...(entry ? { line: entry.line } : {}),
290
+ };
291
+ }
292
+ export function policyIssueLine(issue, locations) {
293
+ const unknownKey = issue.code === 'unrecognized_keys' ? issue.keys[0] : undefined;
294
+ const issuePath = issue.code === 'unrecognized_keys'
295
+ ? issue.keys.length === 1 && unknownKey !== undefined
296
+ ? [...issue.path, unknownKey]
297
+ : undefined
298
+ : issue.path;
299
+ return issuePath
300
+ ? locations.get(issuePath.map((key) => policySourceKey(String(key))).join('/'))
301
+ : undefined;
302
+ }
303
+ function policySourceKey(key) {
304
+ return key.replaceAll('~', '~0').replaceAll('/', '~1');
305
+ }
306
+ export function candidateCreationIssue(rawPath, creates, requiredFrom, locations) {
307
+ const index = creates.findIndex(({ path: candidatePath }) => candidatePath === rawPath);
308
+ const line = requiredFrom === undefined
309
+ ? locations.get('candidateCreates/' + String(index) + '/requiredFromTaskId')
310
+ : undefined;
311
+ return {
312
+ artifact: 'plan.md',
313
+ rule: 'receipt_policy_invalid',
314
+ ...(line === undefined ? {} : { line }),
315
+ };
316
+ }
317
+ //# sourceMappingURL=trinity-structure.js.map
@@ -0,0 +1,12 @@
1
+ import type { FilePermission, ReceiptCandidate, ReceiptTaskPolicy, VerificationInputCategory, VerificationInputReason, WorkspaceRoot, VerificationInputSnapshot } from '../types/sdd-engine.js';
2
+ export declare class VerificationInputError extends Error {
3
+ readonly reason: VerificationInputReason;
4
+ readonly category?: VerificationInputCategory | undefined;
5
+ readonly path?: string | undefined;
6
+ constructor(reason: VerificationInputReason, category?: VerificationInputCategory | undefined, path?: string | undefined);
7
+ }
8
+ export declare function captureVerificationRoot(workspaceRoot: string): Promise<WorkspaceRoot>;
9
+ export declare function captureVerificationInputs(workspaceRoot: string, candidates: readonly ReceiptCandidate[], task: ReceiptTaskPolicy, signal?: AbortSignal, expectedRoot?: WorkspaceRoot): Promise<VerificationInputSnapshot>;
10
+ export declare function checkReceiptPatchTarget(root: WorkspaceRoot, workspaceRoot: string, path: string, permission: FilePermission | undefined, searchContent: string): Promise<void>;
11
+ export declare function revalidateVerificationInputs(snapshot: VerificationInputSnapshot, signal?: AbortSignal): Promise<void>;
12
+ //# sourceMappingURL=verification-inputs.d.ts.map