@planu/cli 8.7.3 → 8.9.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 +13 -0
- package/README.md +11 -3
- package/dist/sdd-engine/canonical-tools.d.ts +57 -0
- package/dist/sdd-engine/canonical-tools.js +78 -0
- package/dist/sdd-engine/client-workspace.d.ts +8 -1
- package/dist/sdd-engine/client-workspace.js +168 -1
- package/dist/sdd-engine/contracts.d.ts +1 -23
- package/dist/sdd-engine/contracts.js +1 -18
- package/dist/sdd-engine/feature-manifest.js +1 -1
- package/dist/sdd-engine/host-rule-pack.d.ts +7 -3
- package/dist/sdd-engine/host-rule-pack.js +28 -52
- package/dist/sdd-engine/host-skill-reader.d.ts +12 -10
- package/dist/sdd-engine/host-skill-reader.js +252 -194
- package/dist/sdd-engine/source-descriptor.d.ts +3 -0
- package/dist/sdd-engine/source-descriptor.js +332 -0
- package/dist/sdd-engine/tools/execution-tools.d.ts +2 -1
- package/dist/sdd-engine/tools/execution-tools.js +70 -86
- package/dist/sdd-engine/tools/workspace-tools.d.ts +2 -1
- package/dist/sdd-engine/tools/workspace-tools.js +10 -20
- package/dist/sdd-engine/tools.js +4 -2
- package/dist/sdd-engine/trinity-structure.js +1 -1
- package/dist/sdd-engine/verification-receipts.d.ts +3 -2
- package/dist/sdd-engine/verification-receipts.js +50 -1
- package/dist/sdd-engine/workspace-root.d.ts +33 -7
- package/dist/sdd-engine/workspace-root.js +204 -139
- package/dist/types/completion.d.ts +20 -2
- package/dist/types/resume-views.d.ts +62 -0
- package/dist/types/sdd-engine.d.ts +23 -60
- package/dist/types/verification.d.ts +59 -0
- package/package.json +1 -1
- 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/spec-executor.md +4 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hasReceiptDirective, insideMarkdownBlock } from './task-content.js';
|
|
2
|
-
import { taskIdPattern } from './
|
|
2
|
+
import { taskIdPattern } from './receipt-assessment.js';
|
|
3
3
|
import { disjointPaths, isEvidencePath, CompletionGuardError } from './feature-authority.js';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
5
|
const CHECKBOX_TASK = /^[-*]\s*\[[ xX]\]/u;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReceiptPolicyResult, ReceiptTaskPolicy, WorkspaceRoot, CompletionSnapshot } from '../types/completion.js';
|
|
2
2
|
export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
|
|
3
|
-
import type { CompleteTaskResult, SddResult, VerificationEvidence } from '../types/sdd-engine.js';
|
|
4
|
-
import type
|
|
3
|
+
import type { ActiveTaskResult, CompleteTaskResult, SddResult, VerificationEvidence } from '../types/sdd-engine.js';
|
|
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';
|
|
7
7
|
export declare function captureReceiptEvidence(snapshot: CompletionSnapshot, workspaceRoot: string, policy: Extract<ReceiptPolicyResult, {
|
|
@@ -13,4 +13,5 @@ export declare function captureReceiptEvidence(snapshot: CompletionSnapshot, wor
|
|
|
13
13
|
export declare function completeReceiptTask(snapshot: CompletionSnapshot, workspaceRoot: string, policy: Extract<ReceiptPolicyResult, {
|
|
14
14
|
status: 'ready';
|
|
15
15
|
}>, task: ReceiptTaskPolicy, receipts: unknown, lease: CompletionLease, signal: AbortSignal, timeoutMs: number, runVerification: (options: ScopedVerificationRunnerOptions) => Promise<ScopedVerificationRun>): Promise<SddResult<CompleteTaskResult>>;
|
|
16
|
+
export declare function getReceiptActiveTask(feature: string, previousTaskMarkdown: string, workspaceRoot: string, signal?: AbortSignal): Promise<SddResult<ActiveTaskResult>>;
|
|
16
17
|
//# sourceMappingURL=verification-receipts.d.ts.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { parseManifestContent, parseVerificationReceiptPolicy } from './feature-manifest.js';
|
|
1
2
|
export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
|
|
2
3
|
import { validateVerificationReceiptSet } from './receipt-assessment.js';
|
|
3
4
|
import * as path from 'node:path';
|
|
5
|
+
import { inspectCompletionGuard } from './completion-guard.js';
|
|
4
6
|
import { captureCompletionSnapshot, persistCompletionSnapshot, revalidateCompletionSnapshot, } from './completion-snapshot.js';
|
|
5
7
|
import { hashArtifact } from './feature-authority.js';
|
|
6
8
|
import { activeTaskFromContent, markReceiptTaskVerified, remainingTaskCount, } from './task-content.js';
|
|
7
|
-
import { completionFailure, receiptFailure, unsupportedVerificationPlatform, verificationFailed, verificationProcessEvidence, } from './task-failures.js';
|
|
9
|
+
import { completionError, verificationCommand, completionFailure, receiptFailure, unsupportedVerificationPlatform, verificationFailed, verificationProcessEvidence, } from './task-failures.js';
|
|
8
10
|
import { captureVerificationInputs, captureVerificationRoot, revalidateVerificationInputs, } from './verification-inputs.js';
|
|
9
11
|
export async function captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal) {
|
|
10
12
|
if (path.resolve(snapshot.featDir, '../../..') !== root.canonical) {
|
|
@@ -96,4 +98,51 @@ export async function completeReceiptTask(snapshot, workspaceRoot, policy, task,
|
|
|
96
98
|
},
|
|
97
99
|
};
|
|
98
100
|
}
|
|
101
|
+
export async function getReceiptActiveTask(feature, previousTaskMarkdown, workspaceRoot, signal) {
|
|
102
|
+
const trigger = 'sdd_get_active_task';
|
|
103
|
+
try {
|
|
104
|
+
const root = await captureVerificationRoot(workspaceRoot);
|
|
105
|
+
const snapshot = await captureCompletionSnapshot(feature, {
|
|
106
|
+
workspaceRoot: root.canonical,
|
|
107
|
+
});
|
|
108
|
+
const current = activeTaskFromContent(snapshot.tasksContent, verificationCommand);
|
|
109
|
+
const active = current.success ? current.data.activeTask : null;
|
|
110
|
+
if (!current.success || active?.fullTaskMarkdown !== previousTaskMarkdown) {
|
|
111
|
+
return completionFailure('contract_drift', undefined, trigger);
|
|
112
|
+
}
|
|
113
|
+
const data = current.data;
|
|
114
|
+
const policy = parseVerificationReceiptPolicy(path.basename(snapshot.featDir), snapshot.planContent, snapshot.tasksContent);
|
|
115
|
+
const task = policy.status === 'ready' ? policy.tasks.get(active.taskId) : undefined;
|
|
116
|
+
if (policy.status !== 'ready' || !task) {
|
|
117
|
+
return completionFailure('contract_drift', undefined, trigger);
|
|
118
|
+
}
|
|
119
|
+
const captured = await captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal);
|
|
120
|
+
if (captured.success) {
|
|
121
|
+
await revalidateVerificationInputs(captured.data.inputs, signal);
|
|
122
|
+
}
|
|
123
|
+
await revalidateCompletionSnapshot(snapshot);
|
|
124
|
+
const guard = await inspectCompletionGuard(feature);
|
|
125
|
+
if (guard) {
|
|
126
|
+
return completionFailure(guard.reason, undefined, trigger);
|
|
127
|
+
}
|
|
128
|
+
if (!captured.success) {
|
|
129
|
+
return { ...captured, error: { ...captured.error, trigger } };
|
|
130
|
+
}
|
|
131
|
+
const manifest = [...parseManifestContent(snapshot.planContent).allowedFiles.entries()].map(([filePath, permission]) => ({ path: filePath, permission }));
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
data: {
|
|
135
|
+
...data,
|
|
136
|
+
activeTask: { ...active, verificationCommand: task.command },
|
|
137
|
+
locked: true,
|
|
138
|
+
trinity: 'ready',
|
|
139
|
+
manifest,
|
|
140
|
+
verificationEvidence: captured.data.evidence,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return completionError(error, trigger);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
99
148
|
//# sourceMappingURL=verification-receipts.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
1
|
+
import type * as Models from '../types/resume-views.js';
|
|
2
|
+
import type * as Engine from '../types/sdd-engine.js';
|
|
3
|
+
import type * as Completion from '../types/completion.js';
|
|
4
|
+
import type { SourceCursorPayload } from '../types/resume-views.js';
|
|
5
|
+
import type { HostSkillReadResult } from '../types/sdd-engine.js';
|
|
6
|
+
export { withSourceDescriptor } from './source-descriptor.js';
|
|
7
7
|
export declare function readTextInsideWorkspace(workspaceRoot: string, absolutePath: string, options?: {
|
|
8
8
|
maxBytes: number;
|
|
9
9
|
}): Promise<{
|
|
@@ -13,5 +13,31 @@ export declare function readTextInsideWorkspace(workspaceRoot: string, absoluteP
|
|
|
13
13
|
ok: false;
|
|
14
14
|
reason: 'outside' | 'missing';
|
|
15
15
|
}>;
|
|
16
|
-
export {
|
|
16
|
+
export { parseMcpRootUri, resolveSddWorkspaceRoot, resolveSddWorkspace, isHomeFallbackWorkspace, homeFallbackFailure, } from './client-workspace.js';
|
|
17
|
+
export declare function readTextInsideWorkspaceDetailed(workspaceRoot: string, absolutePath: string, options: {
|
|
18
|
+
maxBytes: number;
|
|
19
|
+
}): Promise<HostSkillReadResult>;
|
|
20
|
+
export declare function sourceRequestSha256(path: string, startLine: number, endLine: number): string;
|
|
21
|
+
export declare class ReadCursorCodec {
|
|
22
|
+
#private;
|
|
23
|
+
encode(payload: SourceCursorPayload): string;
|
|
24
|
+
decode(token: unknown): SourceCursorPayload | null;
|
|
25
|
+
}
|
|
26
|
+
declare const failures: {
|
|
27
|
+
readonly slice_input_invalid: readonly ["ERR_INVALID_SLICE", "fix_inputs"];
|
|
28
|
+
readonly slice_cursor_invalid: readonly ["ERR_INVALID_SLICE", "reread_slice"];
|
|
29
|
+
readonly slice_cursor_stale: readonly ["ERR_SPEC_DRIFT", "reread_slice"];
|
|
30
|
+
readonly slice_path_unsafe: readonly ["ERR_PERMISSION_VIOLATION", "inspect_artifacts"];
|
|
31
|
+
readonly slice_capability_unavailable: readonly ["ERR_PERMISSION_VIOLATION", "use_supported_runtime"];
|
|
32
|
+
readonly slice_unavailable: readonly ["ERR_INVALID_SLICE", "inspect_artifacts"];
|
|
33
|
+
readonly slice_invalid_utf8: readonly ["ERR_INVALID_SLICE", "inspect_artifacts"];
|
|
34
|
+
readonly slice_range_unavailable: readonly ["ERR_INVALID_SLICE", "fix_inputs"];
|
|
35
|
+
readonly slice_response_too_large: readonly ["ERR_INVALID_SLICE", "inspect_artifacts"];
|
|
36
|
+
readonly cancelled: readonly ["ERR_VERIFICATION_FAILED", "retry_read"];
|
|
37
|
+
};
|
|
38
|
+
export declare function failure(reason: keyof typeof failures): Engine.SddResult<never>;
|
|
39
|
+
export declare function slicePath(workspaceRoot: string, input: Engine.ReadFileSliceInput): string | null | undefined;
|
|
40
|
+
export declare function descriptorFailure(cause: Completion.SourceDescriptorFailure, cursor: boolean): keyof typeof failures;
|
|
41
|
+
export declare function initialPosition(cursor: Models.SourceCursorPayload | null, snapshot: Completion.SourceDescriptorSnapshot, input: Engine.ReadFileSliceInput): Models.SourceProgress | keyof typeof failures;
|
|
42
|
+
export declare function requestCursor(input: Engine.ReadFileSliceInput, path: string, codec: ReadCursorCodec): SourceCursorPayload | null | undefined;
|
|
17
43
|
//# sourceMappingURL=workspace-root.d.ts.map
|
|
@@ -1,133 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
2
3
|
import { lstat, open, readFile, realpath } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export function parseMcpRootUri(uri) {
|
|
7
|
-
const trimmed = uri.trim();
|
|
8
|
-
if (!trimmed) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
try {
|
|
12
|
-
if (trimmed.startsWith('file:')) {
|
|
13
|
-
return resolve(fileURLToPath(trimmed));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
if (trimmed.startsWith('/')) {
|
|
20
|
-
return resolve(trimmed);
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
export function resolveSddWorkspaceRoot(startDir = process.cwd(), env = process.env, mcpRootUris = []) {
|
|
25
|
-
return resolveSddWorkspace({ startDir, env, mcpRootUris }).workspaceRoot;
|
|
26
|
-
}
|
|
27
|
-
export function resolveSddWorkspace(input = {}) {
|
|
28
|
-
const env = input.env ?? process.env;
|
|
29
|
-
const startDir = resolve(input.startDir ?? process.cwd());
|
|
30
|
-
if (input.pinnedRoot?.trim()) {
|
|
31
|
-
return finish(resolve(input.pinnedRoot.trim()), 'pin');
|
|
32
|
-
}
|
|
33
|
-
const fromEnv = usablePlanuWorkspaceEnv(env);
|
|
34
|
-
if (fromEnv) {
|
|
35
|
-
return finish(fromEnv, 'env');
|
|
36
|
-
}
|
|
37
|
-
const mcpDirs = unique((input.mcpRootUris ?? [])
|
|
38
|
-
.map((uri) => parseMcpRootUri(uri))
|
|
39
|
-
.filter((dir) => dir !== null));
|
|
40
|
-
for (const dir of mcpDirs) {
|
|
41
|
-
const found = nearestProjectSdd(dir, env);
|
|
42
|
-
if (found) {
|
|
43
|
-
return finish(found, 'mcp_root');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const fromCwd = nearestProjectSdd(startDir, env);
|
|
47
|
-
if (fromCwd) {
|
|
48
|
-
return finish(fromCwd, 'cwd_walk');
|
|
49
|
-
}
|
|
50
|
-
if (mcpDirs[0]) {
|
|
51
|
-
return finish(mcpDirs[0], 'fallback');
|
|
52
|
-
}
|
|
53
|
-
return finish(startDir, 'fallback');
|
|
54
|
-
}
|
|
55
|
-
export function isHomeFallbackWorkspace(resolved, env = process.env) {
|
|
56
|
-
return resolved.source === 'fallback' && isHomeDirectory(resolved.workspaceRoot, env);
|
|
57
|
-
}
|
|
58
|
-
export function homeFallbackFailure(resolved, trigger, env = process.env) {
|
|
59
|
-
if (!isHomeFallbackWorkspace(resolved, env)) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
success: false,
|
|
64
|
-
error: {
|
|
65
|
-
code: 'ERR_WORKSPACE_UNRESOLVED',
|
|
66
|
-
message: ERR_WORKSPACE_UNRESOLVED_MESSAGE,
|
|
67
|
-
trigger,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function finish(workspaceRoot, source) {
|
|
72
|
-
const sddDir = join(workspaceRoot, '.sdd');
|
|
73
|
-
return {
|
|
74
|
-
workspaceRoot,
|
|
75
|
-
sddDir,
|
|
76
|
-
sddPresent: existsSync(sddDir),
|
|
77
|
-
source,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function nearestProjectSdd(startDir, env) {
|
|
81
|
-
let dir = resolve(startDir);
|
|
82
|
-
for (;;) {
|
|
83
|
-
if (existsSync(join(dir, '.sdd')) && !isHomeDirectory(dir, env)) {
|
|
84
|
-
return dir;
|
|
85
|
-
}
|
|
86
|
-
const parent = dirname(dir);
|
|
87
|
-
if (parent === dir) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
dir = parent;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function isHomeDirectory(dir, env) {
|
|
94
|
-
const home = env.HOME?.trim() ?? env.USERPROFILE?.trim();
|
|
95
|
-
if (!home) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return resolve(dir) === resolve(home);
|
|
99
|
-
}
|
|
100
|
-
function usablePlanuWorkspaceEnv(env) {
|
|
101
|
-
const fromEnv = env.PLANU_WORKSPACE?.trim();
|
|
102
|
-
if (!fromEnv || fromEnv.includes('${')) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
const expanded = expandHomePrefix(fromEnv, env);
|
|
106
|
-
if (!expanded) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
const resolved = resolve(expanded);
|
|
110
|
-
if (resolved.includes(`${sep}~${sep}`) || resolved.endsWith(`${sep}~`)) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
if (isHomeDirectory(resolved, env)) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
return resolved;
|
|
117
|
-
}
|
|
118
|
-
function expandHomePrefix(raw, env) {
|
|
119
|
-
if (raw === '~' || raw.startsWith('~/') || raw.startsWith('~\\')) {
|
|
120
|
-
const home = env.HOME?.trim() ?? env.USERPROFILE?.trim();
|
|
121
|
-
if (!home) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
if (raw === '~') {
|
|
125
|
-
return home;
|
|
126
|
-
}
|
|
127
|
-
return join(home, raw.slice(2));
|
|
128
|
-
}
|
|
129
|
-
return raw;
|
|
130
|
-
}
|
|
4
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { withSourceDescriptor } from './source-descriptor.js';
|
|
6
|
+
export { withSourceDescriptor } from './source-descriptor.js';
|
|
131
7
|
export async function readTextInsideWorkspace(workspaceRoot, absolutePath, options) {
|
|
132
8
|
let root;
|
|
133
9
|
try {
|
|
@@ -221,17 +97,206 @@ async function readBoundedDescriptor(handle, maxBytes) {
|
|
|
221
97
|
}
|
|
222
98
|
return { ok: true, text: bytes.subarray(0, total).toString('utf8') };
|
|
223
99
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
100
|
+
export { parseMcpRootUri, resolveSddWorkspaceRoot, resolveSddWorkspace, isHomeFallbackWorkspace, homeFallbackFailure, } from './client-workspace.js';
|
|
101
|
+
export async function readTextInsideWorkspaceDetailed(workspaceRoot, absolutePath, options) {
|
|
102
|
+
const { maxBytes } = options;
|
|
103
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0 || maxBytes > 65_536) {
|
|
104
|
+
return { ok: false, cause: 'read_failed' };
|
|
105
|
+
}
|
|
106
|
+
const root = resolve(workspaceRoot);
|
|
107
|
+
const local = relative(root, resolve(absolutePath));
|
|
108
|
+
if (!local || local === '..' || local.startsWith(`..${sep}`) || resolve(local) === local) {
|
|
109
|
+
return { ok: false, cause: 'unsafe_path' };
|
|
110
|
+
}
|
|
111
|
+
const result = await withSourceDescriptor(root, local, async (context) => {
|
|
112
|
+
let bytes = new Uint8Array(0);
|
|
113
|
+
while (bytes.length < maxBytes) {
|
|
114
|
+
const next = await context.read(bytes.length, maxBytes - bytes.length);
|
|
115
|
+
if (!next.length) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
bytes = new Uint8Array(next.buffer, next.byteOffset - bytes.length, bytes.length + next.length);
|
|
119
|
+
}
|
|
120
|
+
return bytes;
|
|
121
|
+
}, maxBytes);
|
|
122
|
+
if (!result.ok) {
|
|
123
|
+
return {
|
|
124
|
+
ok: false,
|
|
125
|
+
cause: result.cause === 'cancelled' || result.cause === 'capability_unavailable'
|
|
126
|
+
? 'read_failed'
|
|
127
|
+
: result.cause,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
text: new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(result.value),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return { ok: false, cause: 'invalid_content' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const sourceCursorDomain = 'planu.read-cursor.v1';
|
|
141
|
+
const cursorHashPattern = /^[0-9a-f]{64}$/;
|
|
142
|
+
const cursorBase64Pattern = /^[A-Za-z0-9_-]+$/;
|
|
143
|
+
function isCursorInteger(value, min) {
|
|
144
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= min;
|
|
145
|
+
}
|
|
146
|
+
function isSourceCursorPayload(value) {
|
|
147
|
+
if (!Array.isArray(value) || value.length !== 8) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const [domain, kind, root, request, snapshot, consumed, line, offset] = value;
|
|
151
|
+
if (domain !== sourceCursorDomain || kind !== 'source') {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (![root, request, snapshot].every((hash) => typeof hash === 'string' && cursorHashPattern.test(hash))) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
if (!isCursorInteger(consumed, 1) || !isCursorInteger(line, 1) || !isCursorInteger(offset, 0)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return (line - 1 <= consumed && offset <= consumed - (line - 1) && (line !== 1 || offset === consumed));
|
|
161
|
+
}
|
|
162
|
+
export function sourceRequestSha256(path, startLine, endLine) {
|
|
163
|
+
return createHash('sha256')
|
|
164
|
+
.update(JSON.stringify([sourceCursorDomain, 'source', path, startLine, endLine]))
|
|
165
|
+
.digest('hex');
|
|
166
|
+
}
|
|
167
|
+
export class ReadCursorCodec {
|
|
168
|
+
#key = randomBytes(32);
|
|
169
|
+
encode(payload) {
|
|
170
|
+
if (!isSourceCursorPayload(payload)) {
|
|
171
|
+
throw new TypeError('Invalid source cursor payload');
|
|
172
|
+
}
|
|
173
|
+
const mac = createHmac('sha256', this.#key).update(JSON.stringify(payload)).digest('base64url');
|
|
174
|
+
const token = Buffer.from(JSON.stringify([payload, mac]), 'utf8').toString('base64url');
|
|
175
|
+
if (token.length > 1024) {
|
|
176
|
+
throw new TypeError('Invalid source cursor payload');
|
|
230
177
|
}
|
|
231
|
-
|
|
232
|
-
|
|
178
|
+
return token;
|
|
179
|
+
}
|
|
180
|
+
decode(token) {
|
|
181
|
+
if (typeof token !== 'string' || token.length > 1024 || !cursorBase64Pattern.test(token)) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const bytes = Buffer.from(token, 'base64url');
|
|
186
|
+
if (bytes.toString('base64url') !== token) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const json = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
190
|
+
const envelope = JSON.parse(json);
|
|
191
|
+
if (!Array.isArray(envelope) || envelope.length !== 2 || JSON.stringify(envelope) !== json) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const [payload, mac] = envelope;
|
|
195
|
+
if (!isSourceCursorPayload(payload) ||
|
|
196
|
+
typeof mac !== 'string' ||
|
|
197
|
+
!cursorBase64Pattern.test(mac)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const actual = Buffer.from(mac, 'base64url');
|
|
201
|
+
if (actual.length !== 32 || actual.toString('base64url') !== mac) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const expected = createHmac('sha256', this.#key).update(JSON.stringify(payload)).digest();
|
|
205
|
+
return timingSafeEqual(actual, expected) ? payload : null;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const failures = {
|
|
213
|
+
slice_input_invalid: ['ERR_INVALID_SLICE', 'fix_inputs'],
|
|
214
|
+
slice_cursor_invalid: ['ERR_INVALID_SLICE', 'reread_slice'],
|
|
215
|
+
slice_cursor_stale: ['ERR_SPEC_DRIFT', 'reread_slice'],
|
|
216
|
+
slice_path_unsafe: ['ERR_PERMISSION_VIOLATION', 'inspect_artifacts'],
|
|
217
|
+
slice_capability_unavailable: ['ERR_PERMISSION_VIOLATION', 'use_supported_runtime'],
|
|
218
|
+
slice_unavailable: ['ERR_INVALID_SLICE', 'inspect_artifacts'],
|
|
219
|
+
slice_invalid_utf8: ['ERR_INVALID_SLICE', 'inspect_artifacts'],
|
|
220
|
+
slice_range_unavailable: ['ERR_INVALID_SLICE', 'fix_inputs'],
|
|
221
|
+
slice_response_too_large: ['ERR_INVALID_SLICE', 'inspect_artifacts'],
|
|
222
|
+
cancelled: ['ERR_VERIFICATION_FAILED', 'retry_read'],
|
|
223
|
+
};
|
|
224
|
+
export function failure(reason) {
|
|
225
|
+
const [code, nextAction] = failures[reason];
|
|
226
|
+
return {
|
|
227
|
+
success: false,
|
|
228
|
+
error: {
|
|
229
|
+
code,
|
|
230
|
+
message: 'Bounded source read is unavailable.',
|
|
231
|
+
trigger: 'sdd_read_file_slice',
|
|
232
|
+
details: { reason, nextAction },
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
export function slicePath(workspaceRoot, input) {
|
|
237
|
+
const { path, start_line: start, end_line: end } = input;
|
|
238
|
+
if (typeof path !== 'string' ||
|
|
239
|
+
!path ||
|
|
240
|
+
Buffer.byteLength(path, 'utf8') > 4096 ||
|
|
241
|
+
path.includes('\0') ||
|
|
242
|
+
![start, end].every(Number.isSafeInteger) ||
|
|
243
|
+
start < 1 ||
|
|
244
|
+
start > end) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
const local = relative(resolve(workspaceRoot), resolve(workspaceRoot, path));
|
|
248
|
+
if (/^[A-Za-z]:/.test(path) ||
|
|
249
|
+
local === '..' ||
|
|
250
|
+
local.startsWith(`..${sep}`) ||
|
|
251
|
+
isAbsolute(local)) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const parts = path.split('/');
|
|
255
|
+
if (isAbsolute(path)) {
|
|
256
|
+
parts.shift();
|
|
257
|
+
}
|
|
258
|
+
return !local || parts.some((part) => ['', '.', '..'].includes(part) || part.includes('\\'))
|
|
259
|
+
? undefined
|
|
260
|
+
: local;
|
|
261
|
+
}
|
|
262
|
+
export function descriptorFailure(cause, cursor) {
|
|
263
|
+
switch (cause) {
|
|
264
|
+
case 'cancelled':
|
|
265
|
+
return 'cancelled';
|
|
266
|
+
case 'capability_unavailable':
|
|
267
|
+
return 'slice_capability_unavailable';
|
|
268
|
+
case 'unstable':
|
|
269
|
+
return 'slice_cursor_stale';
|
|
270
|
+
case 'not_found':
|
|
271
|
+
return cursor ? 'slice_cursor_stale' : 'slice_unavailable';
|
|
272
|
+
case 'unsafe_path':
|
|
273
|
+
return cursor ? 'slice_cursor_stale' : 'slice_path_unsafe';
|
|
274
|
+
case 'access_denied':
|
|
275
|
+
case 'invalid_content':
|
|
276
|
+
case 'over_limit':
|
|
277
|
+
case 'read_failed':
|
|
278
|
+
return 'slice_unavailable';
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export function initialPosition(cursor, snapshot, input) {
|
|
282
|
+
if (!cursor) {
|
|
283
|
+
return { consumedBytes: 0, line: 1, lineOffsetBytes: 0 };
|
|
284
|
+
}
|
|
285
|
+
const [, , rootHash, , snapshotHash, consumedBytes, line, lineOffsetBytes] = cursor;
|
|
286
|
+
if (rootHash !== snapshot.rootIdentitySha256 || snapshotHash !== snapshot.snapshotSha256) {
|
|
287
|
+
return 'slice_cursor_stale';
|
|
288
|
+
}
|
|
289
|
+
if (consumedBytes >= snapshot.size || line > input.end_line) {
|
|
290
|
+
return 'slice_cursor_invalid';
|
|
291
|
+
}
|
|
292
|
+
return { consumedBytes, line, lineOffsetBytes };
|
|
293
|
+
}
|
|
294
|
+
export function requestCursor(input, path, codec) {
|
|
295
|
+
const cursor = input.cursor === undefined ? null : codec.decode(input.cursor);
|
|
296
|
+
if (input.cursor !== undefined &&
|
|
297
|
+
cursor?.[3] !== sourceRequestSha256(path, input.start_line, input.end_line)) {
|
|
298
|
+
return undefined;
|
|
233
299
|
}
|
|
234
|
-
return
|
|
300
|
+
return cursor;
|
|
235
301
|
}
|
|
236
|
-
export { readTextInsideWorkspaceDetailed } from './host-skill-reader.js';
|
|
237
302
|
//# sourceMappingURL=workspace-root.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KeyObject } from 'node:crypto';
|
|
2
2
|
import type { BigIntStats } from 'node:fs';
|
|
3
|
-
import type { SddLockFile, ErrorCode, TrinityIssue, FilePermission,
|
|
4
|
-
import type { ScopedVerificationSnapshot, ScopedTaskSelector, ScopedTaskSelection, VerificationBudgetDiagnostic } from './verification.js';
|
|
3
|
+
import type { HostSkillReadCause, SddLockFile, ErrorCode, TrinityIssue, FilePermission, SddResult, CompleteTaskResult, CheckpointJournalReference } from './sdd-engine.js';
|
|
4
|
+
import type { VerificationGate, VerificationReceipt, VerificationPreflight, ScopedVerificationSnapshot, ScopedTaskSelector, ScopedTaskSelection, VerificationBudgetDiagnostic } from './verification.js';
|
|
5
5
|
export type CompletionFailureReason = 'guard_present' | 'contract_drift' | 'cancelled' | 'persistence_uncertain';
|
|
6
6
|
export interface PhysicalIdentity {
|
|
7
7
|
dev: number;
|
|
@@ -260,5 +260,23 @@ export interface VerificationBudgetContext {
|
|
|
260
260
|
export type BudgetDeniedReason = Extract<VerificationBudgetDiagnostic, {
|
|
261
261
|
admission: 'denied';
|
|
262
262
|
}>['reason'];
|
|
263
|
+
export interface SourceDescriptorSnapshot {
|
|
264
|
+
readonly size: number;
|
|
265
|
+
readonly rootIdentitySha256: string;
|
|
266
|
+
readonly snapshotSha256: string;
|
|
267
|
+
}
|
|
268
|
+
export interface SourceDescriptorContext {
|
|
269
|
+
readonly snapshot: SourceDescriptorSnapshot;
|
|
270
|
+
read(position: number, length: number): Promise<Uint8Array>;
|
|
271
|
+
}
|
|
272
|
+
export type SourceDescriptorCallback<T> = (context: SourceDescriptorContext) => Promise<T>;
|
|
273
|
+
export type SourceDescriptorFailure = HostSkillReadCause | 'cancelled' | 'capability_unavailable';
|
|
274
|
+
export type SourceDescriptorResult<T> = {
|
|
275
|
+
ok: true;
|
|
276
|
+
value: T;
|
|
277
|
+
} | {
|
|
278
|
+
ok: false;
|
|
279
|
+
cause: SourceDescriptorFailure;
|
|
280
|
+
};
|
|
263
281
|
export {};
|
|
264
282
|
//# sourceMappingURL=completion.d.ts.map
|
|
@@ -223,7 +223,54 @@ export interface SetupRow {
|
|
|
223
223
|
cause: HostSkillReadCause | 'content_mismatch' | 'reference_unavailable' | null;
|
|
224
224
|
proposedAction: 'none' | 'create_on_authorized_setup' | 'replace_on_authorized_setup' | 'inspect_path' | 'inspect_installation';
|
|
225
225
|
}
|
|
226
|
+
export interface EngineCapabilitiesV1 {
|
|
227
|
+
readonly version: 1;
|
|
228
|
+
readonly scope: 'server_implementation';
|
|
229
|
+
readonly readOnlyTools: readonly [
|
|
230
|
+
'sdd_list_features',
|
|
231
|
+
'sdd_read_spec_artifact',
|
|
232
|
+
'sdd_read_file_slice',
|
|
233
|
+
'sdd_get_active_task'
|
|
234
|
+
];
|
|
235
|
+
readonly views: {
|
|
236
|
+
readonly sdd_list_features: readonly ['setup_diagnostics'];
|
|
237
|
+
readonly sdd_read_file_slice?: readonly ['bounded'];
|
|
238
|
+
readonly sdd_get_active_task: readonly [
|
|
239
|
+
'verification_preflight',
|
|
240
|
+
'resume',
|
|
241
|
+
'relock_history',
|
|
242
|
+
'execution_window',
|
|
243
|
+
'execution_detail',
|
|
244
|
+
'evidence_history'
|
|
245
|
+
];
|
|
246
|
+
};
|
|
247
|
+
readonly operations: {
|
|
248
|
+
readonly sdd_lock_spec: readonly ['lock', 'evidence_checkpoint'];
|
|
249
|
+
};
|
|
250
|
+
readonly observations: {
|
|
251
|
+
readonly sourceSlice?: 1;
|
|
252
|
+
readonly setupDiagnostics: 1;
|
|
253
|
+
readonly verificationPreflight: 1;
|
|
254
|
+
readonly resume: 1;
|
|
255
|
+
readonly relockHistory: 1;
|
|
256
|
+
readonly executionWindow: 1;
|
|
257
|
+
readonly executionDetail: 1;
|
|
258
|
+
readonly evidenceHistory: 1;
|
|
259
|
+
readonly evidenceCheckpoint: 1;
|
|
260
|
+
readonly verificationBudget: 1;
|
|
261
|
+
readonly verificationProcess: 1;
|
|
262
|
+
};
|
|
263
|
+
readonly limits: {
|
|
264
|
+
readonly sourceSliceBytes?: 65536;
|
|
265
|
+
readonly sourceSliceReadCalls?: 64;
|
|
266
|
+
readonly sourceSliceLines?: 200;
|
|
267
|
+
readonly sourceSliceCursorCharacters?: 1024;
|
|
268
|
+
readonly compactTextBytes: 8192;
|
|
269
|
+
readonly defaultVerificationTimeoutMs: 180000;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
226
272
|
export interface SetupDiagnostics {
|
|
273
|
+
engineCapabilities: EngineCapabilitiesV1;
|
|
227
274
|
version: 1;
|
|
228
275
|
server: {
|
|
229
276
|
version: string;
|
|
@@ -271,4 +318,19 @@ export interface HostScanRow extends HostScanTarget {
|
|
|
271
318
|
read: HostSkillReadResult;
|
|
272
319
|
matches: boolean;
|
|
273
320
|
}
|
|
321
|
+
export interface SourceProgress {
|
|
322
|
+
consumedBytes: number;
|
|
323
|
+
line: number;
|
|
324
|
+
lineOffsetBytes: number;
|
|
325
|
+
}
|
|
326
|
+
export type SourceCursorPayload = [
|
|
327
|
+
domain: 'planu.read-cursor.v1',
|
|
328
|
+
kind: 'source',
|
|
329
|
+
rootIdentitySha256: string,
|
|
330
|
+
requestSha256: string,
|
|
331
|
+
snapshotSha256: string,
|
|
332
|
+
consumedBytes: number,
|
|
333
|
+
line: number,
|
|
334
|
+
lineOffsetBytes: number
|
|
335
|
+
];
|
|
274
336
|
//# sourceMappingURL=resume-views.d.ts.map
|