@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.
- package/CHANGELOG.md +14 -0
- package/README.md +86 -2
- package/dist/sdd-engine/contracts.d.ts +13 -3
- package/dist/sdd-engine/contracts.js +48 -10
- package/dist/sdd-engine/feature-manifest.d.ts +2 -5
- package/dist/sdd-engine/feature-manifest.js +109 -184
- package/dist/sdd-engine/host-rule-pack.d.ts +5 -0
- package/dist/sdd-engine/host-rule-pack.js +106 -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 +1 -0
- package/dist/sdd-engine/lock-integrity.js +25 -17
- package/dist/sdd-engine/receipt-assessment.d.ts +12 -0
- package/dist/sdd-engine/receipt-assessment.js +223 -0
- package/dist/sdd-engine/resume-history.d.ts +6 -0
- package/dist/sdd-engine/resume-history.js +117 -0
- package/dist/sdd-engine/resume-views.d.ts +9 -0
- package/dist/sdd-engine/resume-views.js +149 -0
- package/dist/sdd-engine/server.js +2 -4
- package/dist/sdd-engine/task-content.d.ts +18 -0
- package/dist/sdd-engine/task-content.js +36 -1
- package/dist/sdd-engine/task-window.d.ts +1 -0
- package/dist/sdd-engine/task-window.js +8 -1
- package/dist/sdd-engine/tools/compact-result.d.ts +6 -0
- package/dist/sdd-engine/tools/compact-result.js +66 -0
- package/dist/sdd-engine/tools/execution-tools.d.ts +1 -11
- package/dist/sdd-engine/tools/execution-tools.js +14 -32
- 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-preflight.d.ts +11 -0
- package/dist/sdd-engine/verification-preflight.js +275 -0
- package/dist/sdd-engine/verification-receipts.d.ts +2 -10
- package/dist/sdd-engine/verification-receipts.js +2 -169
- 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/resume-views.d.ts +55 -0
- package/dist/types/resume-views.js +2 -0
- package/dist/types/sdd-engine.d.ts +78 -0
- package/package.json +1 -1
- package/templates/AGENTS.md +12 -0
- package/templates/host/planu-sdd.md +12 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CompletionGuardError } from '../feature-authority.js';
|
|
2
|
+
import { VerificationInputError } from '../verification-inputs.js';
|
|
3
|
+
const actions = {
|
|
4
|
+
unlocked: 'review_lock',
|
|
5
|
+
history_cursor_stale: 'reread_checkpoint',
|
|
6
|
+
history_cursor_invalid: 'reread_checkpoint',
|
|
7
|
+
workspace_unresolved: 'inspect_workspace',
|
|
8
|
+
guard_present: 'wait_for_guard',
|
|
9
|
+
persistence_uncertain: 'inspect_recovery',
|
|
10
|
+
contract_drift: 'reread_checkpoint',
|
|
11
|
+
tasks_missing: 'inspect_tasks',
|
|
12
|
+
artifact_unavailable: 'inspect_artifacts',
|
|
13
|
+
history_invalid: 'inspect_artifacts',
|
|
14
|
+
compact_identifier_invalid: 'inspect_tasks',
|
|
15
|
+
compact_input_invalid: 'fix_inputs',
|
|
16
|
+
compact_response_too_large: 'inspect_artifacts',
|
|
17
|
+
cancelled: 'retry_read',
|
|
18
|
+
};
|
|
19
|
+
export function compactFailure(reason, code = 'ERR_INVALID_ARTIFACT') {
|
|
20
|
+
return {
|
|
21
|
+
success: false,
|
|
22
|
+
error: {
|
|
23
|
+
code,
|
|
24
|
+
message: 'Compact task read is unavailable; follow the bounded next action.',
|
|
25
|
+
trigger: 'sdd_get_active_task',
|
|
26
|
+
details: { reason, nextAction: actions[reason] },
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function compactReadError(error) {
|
|
31
|
+
if (error instanceof VerificationInputError && error.reason === 'cancelled') {
|
|
32
|
+
return compactFailure('cancelled', 'ERR_VERIFICATION_FAILED');
|
|
33
|
+
}
|
|
34
|
+
if (error instanceof VerificationInputError && error.reason === 'receipt_input_drift') {
|
|
35
|
+
return compactFailure('contract_drift', 'ERR_SPEC_DRIFT');
|
|
36
|
+
}
|
|
37
|
+
if (!(error instanceof CompletionGuardError)) {
|
|
38
|
+
return compactFailure('artifact_unavailable');
|
|
39
|
+
}
|
|
40
|
+
if (error.code === 'ERR_PERMISSION_VIOLATION') {
|
|
41
|
+
return compactFailure('artifact_unavailable', error.code);
|
|
42
|
+
}
|
|
43
|
+
if (error.code === 'ERR_INVALID_ARTIFACT') {
|
|
44
|
+
return compactFailure('artifact_unavailable', error.code);
|
|
45
|
+
}
|
|
46
|
+
if (error.code === 'ERR_TASK_NOT_FOUND') {
|
|
47
|
+
return compactFailure('tasks_missing', error.code);
|
|
48
|
+
}
|
|
49
|
+
switch (error.reason) {
|
|
50
|
+
case 'guard_present':
|
|
51
|
+
case 'persistence_uncertain':
|
|
52
|
+
case 'cancelled':
|
|
53
|
+
return compactFailure(error.reason, 'ERR_VERIFICATION_FAILED');
|
|
54
|
+
case 'contract_drift':
|
|
55
|
+
return compactFailure('contract_drift', 'ERR_SPEC_DRIFT');
|
|
56
|
+
}
|
|
57
|
+
return compactFailure('artifact_unavailable');
|
|
58
|
+
}
|
|
59
|
+
export function formatCompactResult(result) {
|
|
60
|
+
const text = JSON.stringify(result);
|
|
61
|
+
if (Buffer.byteLength(text, 'utf8') > 8192) {
|
|
62
|
+
return formatCompactResult(compactFailure('compact_response_too_large'));
|
|
63
|
+
}
|
|
64
|
+
return { content: [{ type: 'text', text }], ...(!result.success ? { isError: true } : {}) };
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=compact-result.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
|
|
@@ -2,49 +2,23 @@ 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
4
|
import { TaskWindowManager, verificationCommand } from '../task-window.js';
|
|
5
|
-
import { activeTaskFromContent, hasReceiptDirective } from '../task-content.js';
|
|
5
|
+
import { activeTaskFromContent, hasReceiptDirective, sliceNumberedSource, } from '../task-content.js';
|
|
6
|
+
export { sliceNumberedSource } from '../task-content.js';
|
|
6
7
|
import { parseManifestContent, parseVerificationReceiptPolicy, toPosixPath, } from '../feature-manifest.js';
|
|
7
8
|
import { captureReceiptEvidence } from '../verification-receipts.js';
|
|
8
9
|
import { captureVerificationRoot, checkReceiptPatchTarget, revalidateVerificationInputs, } from '../verification-inputs.js';
|
|
9
10
|
import { completionError, completionFailure, patchMutationError } from '../task-failures.js';
|
|
10
11
|
import { formatResult } from './format-result.js';
|
|
12
|
+
import { getResumeToolResult } from '../resume-views.js';
|
|
11
13
|
import { acquireCompletionLease, inspectCompletionGuard } from '../completion-guard.js';
|
|
12
14
|
import { captureCompletionSnapshot, revalidateCompletionSnapshot } from '../completion-snapshot.js';
|
|
13
15
|
import { homeFallbackFailure, readTextInsideWorkspace } from '../workspace-root.js';
|
|
14
16
|
import { guardFailure } from '../feature-authority.js';
|
|
15
|
-
const SLICE_LINE_CAP = 200;
|
|
16
|
-
function sourceLines(fileData) {
|
|
17
|
-
if (fileData.length === 0) {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
const parts = fileData.split('\n');
|
|
21
|
-
if (fileData.endsWith('\n')) {
|
|
22
|
-
parts.pop();
|
|
23
|
-
}
|
|
24
|
-
return parts;
|
|
25
|
-
}
|
|
26
|
-
export function sliceNumberedSource(fileData, startLine, endLine) {
|
|
27
|
-
const lines = sourceLines(fileData);
|
|
28
|
-
if (startLine > lines.length) {
|
|
29
|
-
return { ok: false, totalLines: lines.length };
|
|
30
|
-
}
|
|
31
|
-
const requestedEnd = Math.min(endLine, lines.length);
|
|
32
|
-
const cappedEnd = Math.min(requestedEnd, startLine + SLICE_LINE_CAP - 1);
|
|
33
|
-
const slice = lines.slice(startLine - 1, cappedEnd);
|
|
34
|
-
return {
|
|
35
|
-
ok: true,
|
|
36
|
-
totalLines: lines.length,
|
|
37
|
-
startLine,
|
|
38
|
-
endLine: cappedEnd,
|
|
39
|
-
truncated: cappedEnd < requestedEnd,
|
|
40
|
-
text: slice.map((content, index) => `${startLine + index}: ${content}`).join('\n'),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
17
|
export function registerExecutionTools(server, workspace, policy) {
|
|
44
18
|
const taskWindow = new TaskWindowManager(policy);
|
|
45
19
|
registerReadArtifactTool(server, workspace);
|
|
46
20
|
registerReadFileSliceTool(server, workspace);
|
|
47
|
-
registerGetActiveTaskTool(server, workspace, taskWindow);
|
|
21
|
+
registerGetActiveTaskTool(server, workspace, taskWindow, policy);
|
|
48
22
|
registerApplyPatchTool(server, workspace);
|
|
49
23
|
registerCompleteTaskTool(server, workspace, taskWindow);
|
|
50
24
|
return taskWindow;
|
|
@@ -91,11 +65,16 @@ function registerReadFileSliceTool(server, workspace) {
|
|
|
91
65
|
return executeReadFileSlice(resolved.workspaceRoot, args.path, args.start_line, args.end_line);
|
|
92
66
|
});
|
|
93
67
|
}
|
|
94
|
-
function registerGetActiveTaskTool(server, workspace, taskWindow) {
|
|
68
|
+
function registerGetActiveTaskTool(server, workspace, taskWindow, policy) {
|
|
95
69
|
server.registerTool('sdd_get_active_task', {
|
|
96
|
-
description: '
|
|
70
|
+
description: 'Returns only the active task. For fast resumption use view="resume"; use "relock_history" with history_cursor for older lock references, or "verification_preflight" to inspect evidence. Compact views are read-only and do not certify work.',
|
|
97
71
|
inputSchema: GetActiveTaskInputSchema.shape,
|
|
98
72
|
}, async (rawArgs, extra) => {
|
|
73
|
+
if (rawArgs.view === 'resume' ||
|
|
74
|
+
rawArgs.view === 'relock_history' ||
|
|
75
|
+
rawArgs.history_cursor !== undefined) {
|
|
76
|
+
return getResumeToolResult(rawArgs, workspace, policy, extra.signal);
|
|
77
|
+
}
|
|
99
78
|
const args = GetActiveTaskInputSchema.parse(rawArgs);
|
|
100
79
|
const resolved = await workspace.resolve();
|
|
101
80
|
const homeError = homeFallbackFailure(resolved, 'sdd_get_active_task');
|
|
@@ -103,6 +82,9 @@ function registerGetActiveTaskTool(server, workspace, taskWindow) {
|
|
|
103
82
|
return formatResult(homeError);
|
|
104
83
|
}
|
|
105
84
|
const tasksPath = path.join(resolved.sddDir, 'features', args.feature_id, 'tasks.md');
|
|
85
|
+
if (args.view === 'verification_preflight') {
|
|
86
|
+
return formatResult(await taskWindow.getVerificationPreflight(tasksPath, resolved.workspaceRoot, args.verification_receipts, extra.signal));
|
|
87
|
+
}
|
|
106
88
|
const result = await taskWindow.getActiveTask(tasksPath);
|
|
107
89
|
const active = result.success ? result.data.activeTask : null;
|
|
108
90
|
if (result.success &&
|
|
@@ -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 =
|
|
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
|
|
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: {
|
|
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
|
|
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
|
package/dist/sdd-engine/tools.js
CHANGED
|
@@ -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
|
|
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,11 @@
|
|
|
1
|
+
import type { PreflightAssessment } from '../types/resume-views.js';
|
|
2
|
+
import type { ActiveTaskDetails, ActiveTaskResult, SddResult, WorkspaceRoot } from '../types/sdd-engine.js';
|
|
3
|
+
import type { CompletionSnapshot, PreflightReadSnapshot } from '../types/completion.js';
|
|
4
|
+
import type { ScopedPolicy } from '../types/verification.js';
|
|
5
|
+
/** 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>;
|
|
9
|
+
export declare function assertGuardAbsent(feature: string): Promise<void>;
|
|
10
|
+
export declare function getVerificationPreflight(tasksPath: string, workspaceRoot: string, extractCommand: (markdown: string) => string | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal): Promise<SddResult<ActiveTaskResult>>;
|
|
11
|
+
//# sourceMappingURL=verification-preflight.d.ts.map
|