@planu/cli 8.5.1 → 8.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +16 -4
- package/dist/sdd-engine/completion-guard.js +2 -3
- package/dist/sdd-engine/contracts.d.ts +172 -0
- package/dist/sdd-engine/contracts.js +235 -10
- package/dist/sdd-engine/evidence-checkpoints.d.ts +6 -0
- package/dist/sdd-engine/evidence-checkpoints.js +280 -0
- package/dist/sdd-engine/evidence-journal.d.ts +25 -0
- package/dist/sdd-engine/evidence-journal.js +326 -0
- package/dist/sdd-engine/feature-manifest.d.ts +2 -1
- package/dist/sdd-engine/host-rule-pack.d.ts +4 -0
- package/dist/sdd-engine/host-rule-pack.js +114 -55
- package/dist/sdd-engine/host-skill-reader.d.ts +8 -1
- package/dist/sdd-engine/host-skill-reader.js +73 -0
- package/dist/sdd-engine/resume-history.d.ts +35 -3
- package/dist/sdd-engine/resume-history.js +242 -13
- package/dist/sdd-engine/resume-views.d.ts +7 -6
- package/dist/sdd-engine/resume-views.js +246 -114
- package/dist/sdd-engine/task-content.d.ts +2 -1
- package/dist/sdd-engine/task-failures.d.ts +30 -13
- package/dist/sdd-engine/task-failures.js +284 -115
- package/dist/sdd-engine/task-window.d.ts +6 -3
- package/dist/sdd-engine/task-window.js +12 -23
- package/dist/sdd-engine/tools/compact-result.d.ts +35 -5
- package/dist/sdd-engine/tools/compact-result.js +279 -2
- package/dist/sdd-engine/tools/execution-tools.js +20 -9
- package/dist/sdd-engine/tools/workspace-tools.js +80 -51
- package/dist/sdd-engine/trinity-structure.d.ts +2 -2
- package/dist/sdd-engine/verification-inputs.d.ts +2 -1
- package/dist/sdd-engine/verification-policy.d.ts +7 -6
- package/dist/sdd-engine/verification-policy.js +74 -85
- package/dist/sdd-engine/verification-preflight.d.ts +9 -7
- package/dist/sdd-engine/verification-preflight.js +108 -89
- package/dist/sdd-engine/verification-receipts.d.ts +2 -2
- package/dist/sdd-engine/verification-receipts.js +2 -1
- package/dist/sdd-engine/verification-runner.d.ts +3 -1
- package/dist/sdd-engine/verification-runner.js +12 -7
- package/dist/types/completion.d.ts +183 -3
- package/dist/types/resume-views.d.ts +221 -2
- package/dist/types/sdd-engine.d.ts +52 -112
- package/dist/types/verification.d.ts +26 -9
- package/package.json +5 -5
- package/templates/AGENTS.md +4 -0
- package/templates/host/planu-sdd.md +4 -0
- package/templates/skills/preflight-guardian.md +4 -0
- package/templates/skills/reconciler.md +6 -0
- package/templates/skills/spec-architect.md +44 -0
- package/templates/skills/spec-executor.md +6 -0
- package/templates/skills/verification-auditor.md +6 -0
- package/dist/sdd-engine/tools/format-result.d.ts +0 -3
- package/dist/sdd-engine/tools/format-result.js +0 -22
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { readTextInsideWorkspaceDetailed } from './workspace-root.js';
|
|
2
|
+
import { CANONICAL_SDD_TOOL_NAMES } from './canonical-tools.js';
|
|
1
3
|
import * as fs from 'node:fs/promises';
|
|
2
4
|
import * as path from 'node:path';
|
|
3
5
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import {
|
|
6
|
+
import { scanPack, legacyIssue, hostDisposition } from './host-skill-reader.js';
|
|
5
7
|
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
6
8
|
const TEMPLATES_ROOT = path.resolve(moduleDir, '..', '..', 'templates');
|
|
9
|
+
export 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.';
|
|
7
10
|
const FALLBACK_HOST_BODY = `# Planu v8 host contract
|
|
8
11
|
|
|
9
12
|
The only SDD contract is \`.sdd/features/{FEAT-*}/spec.md\`, \`plan.md\`, and \`tasks.md\`.
|
|
@@ -24,6 +27,10 @@ To resume, request \`sdd_get_active_task\` with \`view="resume"\` and optional \
|
|
|
24
27
|
|
|
25
28
|
If \`history\` is null, follow \`nextAction\` without requesting history. If \`history.firstCursor\` is null, there are no records; do not request history. Otherwise use \`view="relock_history"\` with the checkpoint's \`history.firstCursor\` as \`history_cursor\`, then each \`nextCursor\`, to read at most eight descending records per page. \`history_cursor\` is accepted only with \`view="relock_history"\`. Stop when \`nextCursor\` is null. Require \`data.relockHistory.version=1\`; stale cursors require rereading the checkpoint. Each handler-produced compact result has exactly one text block of at most 8,192 UTF-8 bytes, without \`structuredContent\`; SDK validation before dispatch is a separate boundary. History digests reference the original unmodified lock; they do not attest historical actions. Preserve guards, locked authority and verification budgets.
|
|
26
29
|
|
|
30
|
+
For setup diagnostics and execution window, detail and evidence history views, load \`preflight-guardian.md\` and \`spec-executor.md\` on demand. Verify the selected connection advertises the checkpoint inputs and a supporting engine before any checkpoint mutation; never probe the global 8.5.1 server or fall back to lock/relock. Recorded observations are caller-reported, non-certifying and never automatic. Matching files do not prove a loaded catalogue. Preserve uncertain guards for operator review.
|
|
31
|
+
|
|
32
|
+
Before attempting completion, request a fresh explicit \`verification_preflight\` or \`resume\` and require \`budget.version=1\`; absence is unavailable, never a grant. An older producer may omit it. The observation is advisory, not a reservation or grant. \`execution_window\` and \`execution_detail\` are not decorated with budget and cannot substitute for that fresh request. When a verification process actually ran, its \`verificationProcess\` reports the effective timeout, outcome and owned process group cleanup; \`fixturePostconditions\` remains \`unknown\`. Group cleanup alone does not prove fixture safety. These diagnostics do not record attempts automatically or authorize policy changes, retries or extra time. Reconcile uncertain state before acting.
|
|
33
|
+
|
|
27
34
|
## Delegation
|
|
28
35
|
|
|
29
36
|
Delegate useful independent work within the active TASK through available native agents; keep trivial/dependent work sequential. Load the bounded protocol from \`spec-executor.md\` on demand; use \`spec-architect.md\` for workstream routing and \`verification-auditor.md\` for provenance checks. The parent alone applies canonical patches and certifies. Preserve all nine tools, lock, File Manifest, limits and protected-root controls; host capabilities grant no extra authority.
|
|
@@ -103,31 +110,6 @@ function hostSkillTargets(slug) {
|
|
|
103
110
|
export async function inspectHostSkillPack(workspaceRoot) {
|
|
104
111
|
return (await inspectHostSkillPackDetailed(workspaceRoot, 'unknown')).hint;
|
|
105
112
|
}
|
|
106
|
-
async function batches(items, read) {
|
|
107
|
-
const results = [];
|
|
108
|
-
for (let offset = 0; offset < items.length; offset += 8) {
|
|
109
|
-
results.push(...(await Promise.allSettled(items.slice(offset, offset + 8).map(read))));
|
|
110
|
-
}
|
|
111
|
-
return results;
|
|
112
|
-
}
|
|
113
|
-
function collectHostSkillIssues(installed, targets) {
|
|
114
|
-
const issues = installed.flatMap((result, index) => {
|
|
115
|
-
if (result.status === 'fulfilled') {
|
|
116
|
-
return result.value ? [result.value] : [];
|
|
117
|
-
}
|
|
118
|
-
const target = targets[index];
|
|
119
|
-
return target
|
|
120
|
-
? [
|
|
121
|
-
{
|
|
122
|
-
path: target.relative.split(path.sep).join('/'),
|
|
123
|
-
status: 'unreadable',
|
|
124
|
-
cause: 'read_failed',
|
|
125
|
-
},
|
|
126
|
-
]
|
|
127
|
-
: [];
|
|
128
|
-
});
|
|
129
|
-
return issues;
|
|
130
|
-
}
|
|
131
113
|
function hostSkillAdvice(action) {
|
|
132
114
|
const setup = 'For requested project setup, use sdd_init_workspace(scope="project", force=false), then read the matching role. Catalog reload may require a host session refresh, separately from restarting MCP.';
|
|
133
115
|
switch (action) {
|
|
@@ -143,36 +125,11 @@ function hostSkillAdvice(action) {
|
|
|
143
125
|
}
|
|
144
126
|
}
|
|
145
127
|
export async function inspectHostSkillPackDetailed(workspaceRoot, bundledVersion) {
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (source.ok) {
|
|
151
|
-
expected.set(slug, toHostSkillMarkdown(slug, source.text));
|
|
152
|
-
}
|
|
128
|
+
const { available, rows } = await scanPack(workspaceRoot, TEMPLATES_ROOT, Object.keys(HOST_SKILL_DESCRIPTIONS).sort(), hostSkillTargets, toHostSkillMarkdown, readTextInsideWorkspaceDetailed);
|
|
129
|
+
const issues = rows.flatMap((row) => {
|
|
130
|
+
const issue = legacyIssue(row, available);
|
|
131
|
+
return issue ? [issue] : [];
|
|
153
132
|
});
|
|
154
|
-
const available = sources.every((result) => result.status === 'fulfilled') && expected.size === slugs.length;
|
|
155
|
-
const targets = slugs.flatMap((slug) => hostSkillTargets(slug).map((relative) => ({ slug, relative })));
|
|
156
|
-
const installed = await batches(targets, async ({ slug, relative }) => {
|
|
157
|
-
const read = await readTextInsideWorkspaceDetailed(workspaceRoot, path.join(workspaceRoot, relative), { maxBytes: 65_536 });
|
|
158
|
-
const fixedPath = relative.split(path.sep).join('/');
|
|
159
|
-
if (!read.ok) {
|
|
160
|
-
return {
|
|
161
|
-
path: fixedPath,
|
|
162
|
-
status: read.cause === 'not_found' ? 'missing' : 'unreadable',
|
|
163
|
-
cause: read.cause,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (available && read.text !== expected.get(slug)) {
|
|
167
|
-
return {
|
|
168
|
-
path: fixedPath,
|
|
169
|
-
status: 'different',
|
|
170
|
-
cause: 'content_mismatch',
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return undefined;
|
|
174
|
-
});
|
|
175
|
-
const issues = collectHostSkillIssues(installed, targets);
|
|
176
133
|
issues.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
177
134
|
const nextAction = !available
|
|
178
135
|
? 'inspect_installation'
|
|
@@ -193,6 +150,108 @@ export async function inspectHostSkillPackDetailed(workspaceRoot, bundledVersion
|
|
|
193
150
|
...(nextAction !== 'none' ? { hint: hostSkillAdvice(nextAction) } : {}),
|
|
194
151
|
};
|
|
195
152
|
}
|
|
153
|
+
const HOSTS = ['claude', 'cursor', 'codex', 'gemini'];
|
|
154
|
+
function diagnosticRow(row, version) {
|
|
155
|
+
const host = { '.claude': 'claude', '.cursor': 'cursor', '.agents': 'codex', '.gemini': 'gemini' }[row.relative.split(path.sep)[0]];
|
|
156
|
+
const base = {
|
|
157
|
+
host,
|
|
158
|
+
role: row.slug,
|
|
159
|
+
path: row.relative.split(path.sep).join('/'),
|
|
160
|
+
referenceVersion: version,
|
|
161
|
+
referenceSha256: row.referenceSha256,
|
|
162
|
+
installedSha256: row.installedSha256,
|
|
163
|
+
installedVersion: 'unverified',
|
|
164
|
+
};
|
|
165
|
+
const disposition = hostDisposition(row);
|
|
166
|
+
const proposedAction = {
|
|
167
|
+
match: 'none',
|
|
168
|
+
missing: 'create_on_authorized_setup',
|
|
169
|
+
different: 'replace_on_authorized_setup',
|
|
170
|
+
unreadable: 'inspect_path',
|
|
171
|
+
reference_unavailable: 'inspect_installation',
|
|
172
|
+
};
|
|
173
|
+
return { ...base, ...disposition, proposedAction: proposedAction[disposition.status] };
|
|
174
|
+
}
|
|
175
|
+
function clientInfo(value) {
|
|
176
|
+
if (value === undefined || value === null) {
|
|
177
|
+
return { client: null, clientMetadataCause: 'unavailable' };
|
|
178
|
+
}
|
|
179
|
+
if (typeof value !== 'object' ||
|
|
180
|
+
!('name' in value) ||
|
|
181
|
+
!('version' in value) ||
|
|
182
|
+
typeof value.name !== 'string' ||
|
|
183
|
+
typeof value.version !== 'string' ||
|
|
184
|
+
Array.from(value.name + value.version).some((char) => {
|
|
185
|
+
const code = char.codePointAt(0) ?? 0;
|
|
186
|
+
return code < 32 || (code >= 127 && code <= 159);
|
|
187
|
+
})) {
|
|
188
|
+
return { client: null, clientMetadataCause: 'invalid' };
|
|
189
|
+
}
|
|
190
|
+
if (Buffer.byteLength(value.name) > 128 || Buffer.byteLength(value.version) > 128) {
|
|
191
|
+
return { client: null, clientMetadataCause: 'over_limit' };
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
client: {
|
|
195
|
+
name: value.name,
|
|
196
|
+
version: value.version,
|
|
197
|
+
source: 'initialize',
|
|
198
|
+
provenance: 'client_reported',
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function hostSummary(host, rows, available) {
|
|
203
|
+
const own = rows.filter((row) => row.host === host);
|
|
204
|
+
const count = (status) => own.filter((row) => row.status === status).length;
|
|
205
|
+
return {
|
|
206
|
+
host,
|
|
207
|
+
expectedRoles: 9,
|
|
208
|
+
matched: count('match'),
|
|
209
|
+
missing: count('missing'),
|
|
210
|
+
different: count('different'),
|
|
211
|
+
unreadable: count('unreadable'),
|
|
212
|
+
nextAction: !available
|
|
213
|
+
? 'inspect_installation'
|
|
214
|
+
: count('unreadable')
|
|
215
|
+
? 'inspect_path'
|
|
216
|
+
: count('missing') || count('different')
|
|
217
|
+
? 'request_selected_host'
|
|
218
|
+
: 'none',
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export async function inspectSetupDiagnostics(root, version, selectedHost, client) {
|
|
222
|
+
const { available, rows: scanned } = await scanPack(root, TEMPLATES_ROOT, Object.keys(HOST_SKILL_DESCRIPTIONS).sort(), hostSkillTargets, toHostSkillMarkdown, readTextInsideWorkspaceDetailed);
|
|
223
|
+
const rows = scanned.map((row) => diagnosticRow(row, version));
|
|
224
|
+
return {
|
|
225
|
+
version: 1,
|
|
226
|
+
server: { version, tools: CANONICAL_SDD_TOOL_NAMES, count: 9, scope: 'server_registration' },
|
|
227
|
+
...clientInfo(client),
|
|
228
|
+
effectiveMcpCatalogue: 'unverified',
|
|
229
|
+
skillCatalogue: 'unverified',
|
|
230
|
+
bundledVersion: version,
|
|
231
|
+
baseline: available ? 'available' : 'unavailable',
|
|
232
|
+
selectedHost,
|
|
233
|
+
...(selectedHost === 'all'
|
|
234
|
+
? { hosts: HOSTS.map((host) => hostSummary(host, rows, available)) }
|
|
235
|
+
: { rows: rows.filter((row) => row.host === selectedHost) }),
|
|
236
|
+
setup: {
|
|
237
|
+
operation: 'sdd_init_workspace',
|
|
238
|
+
scope: 'project',
|
|
239
|
+
force: false,
|
|
240
|
+
existingCurrentAgents: 'preserve',
|
|
241
|
+
authorization: 'required_for_setup',
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
export async function copySkillTemplates(skillsDir) {
|
|
246
|
+
const sourceSkillsDir = path.join(TEMPLATES_ROOT, 'skills');
|
|
247
|
+
const files = await fs.readdir(sourceSkillsDir);
|
|
248
|
+
for (const file of files) {
|
|
249
|
+
if (file.endsWith('.md')) {
|
|
250
|
+
const content = await fs.readFile(path.join(sourceSkillsDir, file), 'utf-8');
|
|
251
|
+
await fs.writeFile(path.join(skillsDir, file), content, 'utf-8');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
196
255
|
async function readHostBody() {
|
|
197
256
|
try {
|
|
198
257
|
return await fs.readFile(path.join(TEMPLATES_ROOT, 'host', 'planu-sdd.md'), 'utf-8');
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HostScanRow, SetupRow } from '../types/resume-views.js';
|
|
2
|
+
import type { HostSkillReadResult, HostSkillIssue } from '../types/sdd-engine.js';
|
|
2
3
|
/** Strict bounded reader for host diagnostics; legacy reader semantics remain unchanged. */
|
|
3
4
|
export declare function readTextInsideWorkspaceDetailed(workspaceRoot: string, absolutePath: string, options: {
|
|
4
5
|
maxBytes: number;
|
|
5
6
|
}): Promise<HostSkillReadResult>;
|
|
7
|
+
export declare function scanPack(workspaceRoot: string, templatesRoot: string, slugs: string[], targetsFor: (slug: string) => string[], render: (slug: string, source: string) => string, readTarget: typeof readTextInsideWorkspaceDetailed): Promise<{
|
|
8
|
+
available: boolean;
|
|
9
|
+
rows: HostScanRow[];
|
|
10
|
+
}>;
|
|
11
|
+
export declare function legacyIssue(row: HostScanRow, available: boolean): HostSkillIssue | undefined;
|
|
12
|
+
export declare function hostDisposition(row: HostScanRow): Pick<SetupRow, 'status' | 'cause'>;
|
|
6
13
|
//# sourceMappingURL=host-skill-reader.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { constants } from 'node:fs';
|
|
2
3
|
import { lstat, open, realpath } from 'node:fs/promises';
|
|
3
4
|
import { join, relative, resolve, sep } from 'node:path';
|
|
@@ -184,4 +185,76 @@ export function readTextInsideWorkspaceDetailed(workspaceRoot, absolutePath, opt
|
|
|
184
185
|
}
|
|
185
186
|
return new HostSkillReader(root, local, maxBytes).run();
|
|
186
187
|
}
|
|
188
|
+
function digest(text) {
|
|
189
|
+
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
190
|
+
}
|
|
191
|
+
async function scanHostSkills(workspaceRoot, targets, expected, readTarget) {
|
|
192
|
+
const rows = [];
|
|
193
|
+
for (let offset = 0; offset < targets.length; offset += 8) {
|
|
194
|
+
const chunk = targets.slice(offset, offset + 8);
|
|
195
|
+
rows.push(...(await Promise.all(chunk.map(async (target) => {
|
|
196
|
+
const reference = expected.get(target.slug);
|
|
197
|
+
const read = await readTarget(workspaceRoot, join(workspaceRoot, target.relative), {
|
|
198
|
+
maxBytes: 65_536,
|
|
199
|
+
}).catch(() => ({ ok: false, cause: 'read_failed' }));
|
|
200
|
+
return {
|
|
201
|
+
...target,
|
|
202
|
+
referenceSha256: reference === undefined ? null : digest(reference),
|
|
203
|
+
installedSha256: read.ok ? digest(read.text) : null,
|
|
204
|
+
read,
|
|
205
|
+
matches: read.ok && reference !== undefined && read.text === reference,
|
|
206
|
+
};
|
|
207
|
+
}))));
|
|
208
|
+
}
|
|
209
|
+
return rows;
|
|
210
|
+
}
|
|
211
|
+
async function batches(items, read) {
|
|
212
|
+
const results = [];
|
|
213
|
+
for (let offset = 0; offset < items.length; offset += 8) {
|
|
214
|
+
results.push(...(await Promise.allSettled(items.slice(offset, offset + 8).map(read))));
|
|
215
|
+
}
|
|
216
|
+
return results;
|
|
217
|
+
}
|
|
218
|
+
export async function scanPack(workspaceRoot, templatesRoot, slugs, targetsFor, render, readTarget) {
|
|
219
|
+
const expected = new Map();
|
|
220
|
+
const sources = await batches(slugs, async (slug) => {
|
|
221
|
+
const source = await readTarget(templatesRoot, join(templatesRoot, 'skills', `${slug}.md`), {
|
|
222
|
+
maxBytes: 65_536,
|
|
223
|
+
});
|
|
224
|
+
if (source.ok) {
|
|
225
|
+
expected.set(slug, render(slug, source.text));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
const available = sources.every((result) => result.status === 'fulfilled') && expected.size === slugs.length;
|
|
229
|
+
const targets = slugs.flatMap((slug) => targetsFor(slug).map((targetPath) => ({ slug, relative: targetPath })));
|
|
230
|
+
return { available, rows: await scanHostSkills(workspaceRoot, targets, expected, readTarget) };
|
|
231
|
+
}
|
|
232
|
+
export function legacyIssue(row, available) {
|
|
233
|
+
const fixedPath = row.relative.split(sep).join('/');
|
|
234
|
+
if (!row.read.ok) {
|
|
235
|
+
return {
|
|
236
|
+
path: fixedPath,
|
|
237
|
+
status: row.read.cause === 'not_found' ? 'missing' : 'unreadable',
|
|
238
|
+
cause: row.read.cause,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (available && !row.matches) {
|
|
242
|
+
return { path: fixedPath, status: 'different', cause: 'content_mismatch' };
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
export function hostDisposition(row) {
|
|
247
|
+
if (!row.read.ok && row.read.cause !== 'not_found') {
|
|
248
|
+
return { status: 'unreadable', cause: row.read.cause };
|
|
249
|
+
}
|
|
250
|
+
if (row.referenceSha256 === null) {
|
|
251
|
+
return { status: 'reference_unavailable', cause: 'reference_unavailable' };
|
|
252
|
+
}
|
|
253
|
+
if (!row.read.ok) {
|
|
254
|
+
return { status: 'missing', cause: row.read.cause };
|
|
255
|
+
}
|
|
256
|
+
return row.matches
|
|
257
|
+
? { status: 'match', cause: null }
|
|
258
|
+
: { status: 'different', cause: 'content_mismatch' };
|
|
259
|
+
}
|
|
187
260
|
//# sourceMappingURL=host-skill-reader.js.map
|
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type * as resumeTypes from '../types/resume-views.js';
|
|
3
|
+
import type { RelockHistoryCursor, SddResult, ExecutionDetailCursor } from '../types/sdd-engine.js';
|
|
4
|
+
import type { PreflightReadSnapshot } from '../types/completion.js';
|
|
5
|
+
export declare class InvalidHistoryError extends Error {
|
|
6
|
+
}
|
|
3
7
|
export declare function getRelockHistory(tasksPath: string, workspaceRoot: string, cursor?: RelockHistoryCursor, signal?: AbortSignal): Promise<SddResult<{
|
|
4
|
-
relockHistory: RelockHistoryPage;
|
|
8
|
+
relockHistory: resumeTypes.RelockHistoryPage;
|
|
5
9
|
}>>;
|
|
10
|
+
export declare const ExecutionCursorInputSchema: z.ZodPreprocess<z.ZodObject<{
|
|
11
|
+
snapshotSha256: z.ZodString;
|
|
12
|
+
journalSnapshotSha256: z.ZodNullable<z.ZodString>;
|
|
13
|
+
section: z.ZodEnum<{
|
|
14
|
+
active_task: "active_task";
|
|
15
|
+
read_scope: "read_scope";
|
|
16
|
+
verification: "verification";
|
|
17
|
+
write_scope: "write_scope";
|
|
18
|
+
}>;
|
|
19
|
+
contentSha256: z.ZodString;
|
|
20
|
+
offset: z.ZodNumber;
|
|
21
|
+
}, z.core.$strict>, unknown>;
|
|
22
|
+
export declare const EvidenceCursorInputSchema: z.ZodPreprocess<z.ZodObject<{
|
|
23
|
+
snapshotSha256: z.ZodString;
|
|
24
|
+
journalSnapshotSha256: z.ZodString;
|
|
25
|
+
headSha256: z.ZodString;
|
|
26
|
+
startSeq: z.ZodNumber;
|
|
27
|
+
}, z.core.$strict>, unknown>;
|
|
28
|
+
export declare function sections(c: resumeTypes.CompactCapture): resumeTypes.ScopeSections;
|
|
29
|
+
export declare function detailCursor(c: resumeTypes.CompactCapture, section: ExecutionDetailCursor['section'], content: string): ExecutionDetailCursor | null;
|
|
30
|
+
export declare function scopeProjection(c: resumeTypes.CompactCapture, data: ReturnType<typeof sections>): resumeTypes.ExecutionWindow['scope'];
|
|
31
|
+
export declare function journalProjection(c: resumeTypes.CompactCapture, last: resumeTypes.EvidenceCheckpointRecord | undefined): resumeTypes.ExecutionWindow['journal'];
|
|
32
|
+
export declare function gateCounts(resume: resumeTypes.ResumeCheckpoint): resumeTypes.ExecutionWindow['verification']['gateCounts'];
|
|
33
|
+
export declare function deltaProjection(resume: resumeTypes.ResumeCheckpoint, last?: resumeTypes.EvidenceCheckpointRecord): resumeTypes.ExecutionWindow['delta'];
|
|
34
|
+
export declare function relockProjection(c: resumeTypes.CompactCapture, resume: resumeTypes.ResumeCheckpoint): resumeTypes.ExecutionWindow['relocks'];
|
|
35
|
+
export declare function detailPage(featureId: string, cursor: ExecutionDetailCursor, content: string): resumeTypes.ExecutionDetailPage | null;
|
|
36
|
+
export declare function contractReference(snapshot: PreflightReadSnapshot): resumeTypes.ResumeCheckpoint['contract'];
|
|
37
|
+
export declare function historyRef(snapshot: PreflightReadSnapshot): resumeTypes.ResumeHistory;
|
|
6
38
|
//# sourceMappingURL=resume-history.d.ts.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { parseManifestContent } from './feature-manifest.js';
|
|
2
|
+
import { z } from 'zod';
|
|
1
3
|
import * as path from 'node:path';
|
|
2
4
|
import { CompletionGuardError, hashArtifact } from './feature-authority.js';
|
|
3
5
|
import { captureVerificationRoot } from './verification-inputs.js';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
+
import * as preflight from './verification-preflight.js';
|
|
7
|
+
import * as compact from './tools/compact-result.js';
|
|
6
8
|
const hashPattern = /^[a-f0-9]{64}$/u;
|
|
7
|
-
class InvalidHistoryError extends Error {
|
|
9
|
+
export class InvalidHistoryError extends Error {
|
|
8
10
|
}
|
|
9
11
|
function historyRecords(lockContent) {
|
|
10
12
|
const raw = JSON.parse(lockContent);
|
|
@@ -28,13 +30,13 @@ function cursorFailure(cursor, count, digest) {
|
|
|
28
30
|
cursor.startIndex < 0 ||
|
|
29
31
|
!hashPattern.test(cursor.snapshotSha256) ||
|
|
30
32
|
count === 0) {
|
|
31
|
-
return compactFailure('history_cursor_invalid', 'ERR_INVALID_SLICE');
|
|
33
|
+
return compact.compactFailure('history_cursor_invalid', 'ERR_INVALID_SLICE');
|
|
32
34
|
}
|
|
33
35
|
if (cursor.snapshotSha256 !== digest) {
|
|
34
|
-
return compactFailure('history_cursor_stale', 'ERR_INVALID_SLICE');
|
|
36
|
+
return compact.compactFailure('history_cursor_stale', 'ERR_INVALID_SLICE');
|
|
35
37
|
}
|
|
36
38
|
return cursor.startIndex >= count
|
|
37
|
-
? compactFailure('history_cursor_invalid', 'ERR_INVALID_SLICE')
|
|
39
|
+
? compact.compactFailure('history_cursor_invalid', 'ERR_INVALID_SLICE')
|
|
38
40
|
: undefined;
|
|
39
41
|
}
|
|
40
42
|
function projectRecord(record, index) {
|
|
@@ -80,12 +82,12 @@ export async function getRelockHistory(tasksPath, workspaceRoot, cursor, signal)
|
|
|
80
82
|
try {
|
|
81
83
|
assertReadActive(signal);
|
|
82
84
|
const root = await captureVerificationRoot(workspaceRoot);
|
|
83
|
-
const snapshot = await captureReadSnapshot(path.dirname(tasksPath), root);
|
|
84
|
-
await assertGuardAbsent(snapshot.feature);
|
|
85
|
+
const snapshot = await preflight.captureReadSnapshot(path.dirname(tasksPath), root);
|
|
86
|
+
await preflight.assertGuardAbsent(snapshot.feature);
|
|
85
87
|
if (!snapshot.locked) {
|
|
86
|
-
await revalidateReadSnapshot(snapshot, root, workspaceRoot);
|
|
88
|
+
await preflight.revalidateReadSnapshot(snapshot, root, workspaceRoot);
|
|
87
89
|
assertReadActive(signal);
|
|
88
|
-
return compactFailure('unlocked', 'ERR_SPEC_NOT_LOCKED');
|
|
90
|
+
return compact.compactFailure('unlocked', 'ERR_SPEC_NOT_LOCKED');
|
|
89
91
|
}
|
|
90
92
|
const locked = snapshot.locked;
|
|
91
93
|
const history = historyRecords(locked.lockContent);
|
|
@@ -104,14 +106,241 @@ export async function getRelockHistory(tasksPath, workspaceRoot, cursor, signal)
|
|
|
104
106
|
nextCursor: startIndex >= 8 ? { snapshotSha256: locked.digest, startIndex: startIndex - 8 } : null,
|
|
105
107
|
};
|
|
106
108
|
assertReadActive(signal);
|
|
107
|
-
await revalidateReadSnapshot(snapshot, root, workspaceRoot);
|
|
109
|
+
await preflight.revalidateReadSnapshot(snapshot, root, workspaceRoot);
|
|
108
110
|
assertReadActive(signal);
|
|
109
111
|
return { success: true, data: { relockHistory } };
|
|
110
112
|
}
|
|
111
113
|
catch (error) {
|
|
112
114
|
return error instanceof InvalidHistoryError
|
|
113
|
-
? compactFailure('history_invalid')
|
|
114
|
-
: compactReadError(error);
|
|
115
|
+
? compact.compactFailure('history_invalid')
|
|
116
|
+
: compact.compactReadError(error);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
119
|
+
// Cursor input is normalized before SDK validation to avoid echoing arbitrary keys.
|
|
120
|
+
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
|
121
|
+
const executionCursorShape = z.strictObject({
|
|
122
|
+
snapshotSha256: digestSchema,
|
|
123
|
+
journalSnapshotSha256: digestSchema.nullable(),
|
|
124
|
+
section: z.enum(['write_scope', 'read_scope', 'active_task', 'verification']),
|
|
125
|
+
offset: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
126
|
+
contentSha256: digestSchema,
|
|
127
|
+
});
|
|
128
|
+
const evidenceCursorShape = z.strictObject({
|
|
129
|
+
snapshotSha256: digestSchema,
|
|
130
|
+
journalSnapshotSha256: digestSchema,
|
|
131
|
+
headSha256: digestSchema,
|
|
132
|
+
startSeq: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
133
|
+
});
|
|
134
|
+
export const ExecutionCursorInputSchema = z.preprocess((input) => {
|
|
135
|
+
const parsed = executionCursorShape.safeParse(input);
|
|
136
|
+
return parsed.success
|
|
137
|
+
? parsed.data
|
|
138
|
+
: {
|
|
139
|
+
snapshotSha256: '0'.repeat(64),
|
|
140
|
+
journalSnapshotSha256: null,
|
|
141
|
+
section: 'active_task',
|
|
142
|
+
offset: -1,
|
|
143
|
+
contentSha256: '0'.repeat(64),
|
|
144
|
+
};
|
|
145
|
+
}, executionCursorShape.extend({
|
|
146
|
+
offset: z.number().int().min(-1).max(Number.MAX_SAFE_INTEGER),
|
|
147
|
+
}));
|
|
148
|
+
export const EvidenceCursorInputSchema = z.preprocess((input) => {
|
|
149
|
+
const parsed = evidenceCursorShape.safeParse(input);
|
|
150
|
+
return parsed.success
|
|
151
|
+
? parsed.data
|
|
152
|
+
: {
|
|
153
|
+
snapshotSha256: '0'.repeat(64),
|
|
154
|
+
journalSnapshotSha256: '0'.repeat(64),
|
|
155
|
+
headSha256: '0'.repeat(64),
|
|
156
|
+
startSeq: 0,
|
|
157
|
+
};
|
|
158
|
+
}, evidenceCursorShape.extend({
|
|
159
|
+
startSeq: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
160
|
+
}));
|
|
161
|
+
function latestRelockTransition(lockContent) {
|
|
162
|
+
const history = historyRecords(lockContent);
|
|
163
|
+
if (!history.length) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const index = history.length - 1;
|
|
167
|
+
const prior = projectRecord(history[index], index);
|
|
168
|
+
const current = JSON.parse(lockContent);
|
|
169
|
+
const changedArtifacts = [];
|
|
170
|
+
if (prior.specHash !== current.specHash) {
|
|
171
|
+
changedArtifacts.push('spec');
|
|
172
|
+
}
|
|
173
|
+
if (prior.planHash !== current.planHash) {
|
|
174
|
+
changedArtifacts.push('plan');
|
|
175
|
+
}
|
|
176
|
+
if (prior.tasksHash && prior.tasksHash !== current.tasksHash) {
|
|
177
|
+
changedArtifacts.push('tasks');
|
|
178
|
+
}
|
|
179
|
+
const kind = changedArtifacts.length
|
|
180
|
+
? 'contract_change'
|
|
181
|
+
: prior.tasksHash && typeof current.tasksHash === 'string'
|
|
182
|
+
? 'identical_contract_reseal'
|
|
183
|
+
: 'legacy_unknown';
|
|
184
|
+
return {
|
|
185
|
+
index,
|
|
186
|
+
kind,
|
|
187
|
+
changedArtifacts,
|
|
188
|
+
reasonSha256: prior.reasonSha256,
|
|
189
|
+
recordSha256: prior.recordSha256,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export function sections(c) {
|
|
193
|
+
const entries = c.snapshot.locked
|
|
194
|
+
? [...parseManifestContent(c.snapshot.locked.planContent).allowedFiles].map(([filePath, permission]) => ({ path: filePath, permission }))
|
|
195
|
+
: [];
|
|
196
|
+
const writes = entries.filter((entry) => entry.permission !== 'READ_ONLY');
|
|
197
|
+
const reads = entries.filter((entry) => entry.permission === 'READ_ONLY');
|
|
198
|
+
return {
|
|
199
|
+
entries,
|
|
200
|
+
writes,
|
|
201
|
+
reads,
|
|
202
|
+
texts: {
|
|
203
|
+
write_scope: writes.length ? JSON.stringify(writes) : '',
|
|
204
|
+
read_scope: reads.length ? JSON.stringify(reads) : '',
|
|
205
|
+
active_task: c.active?.fullTaskMarkdown ?? '',
|
|
206
|
+
verification: c.assessment ? JSON.stringify(c.assessment.preflight) : '',
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export function detailCursor(c, section, content) {
|
|
211
|
+
return c.authority && content
|
|
212
|
+
? {
|
|
213
|
+
snapshotSha256: c.authority,
|
|
214
|
+
journalSnapshotSha256: c.journal?.snapshotSha256 ?? null,
|
|
215
|
+
section,
|
|
216
|
+
offset: 0,
|
|
217
|
+
contentSha256: hashArtifact(content),
|
|
218
|
+
}
|
|
219
|
+
: null;
|
|
220
|
+
}
|
|
221
|
+
function deltaValue(a, b) {
|
|
222
|
+
return !a || !b ? 'unavailable' : a === b ? 'same' : 'changed';
|
|
223
|
+
}
|
|
224
|
+
export function scopeProjection(c, data) {
|
|
225
|
+
return c.snapshot.locked
|
|
226
|
+
? {
|
|
227
|
+
declaredEntries: data.entries.length,
|
|
228
|
+
create: data.entries.filter((e) => e.permission === 'CREATE').length,
|
|
229
|
+
modify: data.entries.filter((e) => e.permission === 'MODIFY').length,
|
|
230
|
+
delete: data.entries.filter((e) => e.permission === 'DELETE').length,
|
|
231
|
+
readOnly: data.reads.length,
|
|
232
|
+
manifestSha256: hashArtifact(JSON.stringify(data.entries)),
|
|
233
|
+
writes: detailCursor(c, 'write_scope', data.texts.write_scope),
|
|
234
|
+
reads: detailCursor(c, 'read_scope', data.texts.read_scope),
|
|
235
|
+
}
|
|
236
|
+
: null;
|
|
237
|
+
}
|
|
238
|
+
export function journalProjection(c, last) {
|
|
239
|
+
const ref = c.journal;
|
|
240
|
+
return {
|
|
241
|
+
state: ref ? 'available' : 'absent',
|
|
242
|
+
count: ref?.count ?? 0,
|
|
243
|
+
reference: ref,
|
|
244
|
+
last: last
|
|
245
|
+
? {
|
|
246
|
+
seq: last.seq,
|
|
247
|
+
recordSha256: last.recordSha256,
|
|
248
|
+
kind: last.reported.kind,
|
|
249
|
+
outcome: last.reported.outcome,
|
|
250
|
+
cause: last.reported.cause,
|
|
251
|
+
provenance: 'caller_reported',
|
|
252
|
+
certification: 'none',
|
|
253
|
+
}
|
|
254
|
+
: null,
|
|
255
|
+
firstCursor: ref && c.authority
|
|
256
|
+
? {
|
|
257
|
+
snapshotSha256: c.authority,
|
|
258
|
+
journalSnapshotSha256: ref.snapshotSha256,
|
|
259
|
+
headSha256: ref.headSha256,
|
|
260
|
+
startSeq: ref.count,
|
|
261
|
+
}
|
|
262
|
+
: null,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export function gateCounts(resume) {
|
|
266
|
+
const counts = { valid: 0, missing: 0, rejected: 0 };
|
|
267
|
+
for (const gate of resume.gates) {
|
|
268
|
+
if (gate.state === 'receipt_valid') {
|
|
269
|
+
counts.valid++;
|
|
270
|
+
}
|
|
271
|
+
else if (gate.state === 'receipt_missing') {
|
|
272
|
+
counts.missing++;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
counts.rejected++;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return counts;
|
|
279
|
+
}
|
|
280
|
+
export function deltaProjection(resume, last) {
|
|
281
|
+
const contract = resume.contract;
|
|
282
|
+
const old = last?.context;
|
|
283
|
+
const contractDelta = contract && old
|
|
284
|
+
? ['specSha256', 'planSha256', 'tasksSha256'].every((field) => contract[field] === old.contract[field])
|
|
285
|
+
? 'same'
|
|
286
|
+
: 'changed'
|
|
287
|
+
: 'unavailable';
|
|
288
|
+
return {
|
|
289
|
+
basis: last ? 'latest_recorded_checkpoint' : 'none',
|
|
290
|
+
contract: contractDelta,
|
|
291
|
+
candidate: deltaValue(old?.candidate?.candidateSha256, resume.candidate?.candidateSha256),
|
|
292
|
+
observed: deltaValue(old?.candidate?.observedSha256, resume.candidate?.observedSha256),
|
|
293
|
+
pathDiff: 'unavailable',
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
export function relockProjection(c, resume) {
|
|
297
|
+
return resume.history && c.snapshot.locked
|
|
298
|
+
? {
|
|
299
|
+
count: resume.history.count,
|
|
300
|
+
firstCursor: resume.history.firstCursor,
|
|
301
|
+
latestTransition: latestRelockTransition(c.snapshot.locked.lockContent),
|
|
302
|
+
}
|
|
303
|
+
: null;
|
|
304
|
+
}
|
|
305
|
+
export function detailPage(featureId, cursor, content) {
|
|
306
|
+
const bytes = Buffer.from(content, 'utf8');
|
|
307
|
+
if (cursor.offset < 0 ||
|
|
308
|
+
cursor.offset >= bytes.length ||
|
|
309
|
+
((bytes[cursor.offset] ?? 0) & 0xc0) === 0x80) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
let end = Math.min(bytes.length, cursor.offset + 1024);
|
|
313
|
+
while (end < bytes.length && ((bytes[end] ?? 0) & 0xc0) === 0x80) {
|
|
314
|
+
end--;
|
|
315
|
+
}
|
|
316
|
+
while (end > cursor.offset) {
|
|
317
|
+
const page = compact.detailEnvelope(featureId, cursor, bytes, end);
|
|
318
|
+
if (Buffer.byteLength(JSON.stringify({ success: true, data: { executionDetail: page } })) <= 8192) {
|
|
319
|
+
return page;
|
|
320
|
+
}
|
|
321
|
+
end--;
|
|
322
|
+
while (end > cursor.offset && ((bytes[end] ?? 0) & 0xc0) === 0x80) {
|
|
323
|
+
end--;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
export function contractReference(snapshot) {
|
|
329
|
+
const locked = snapshot.locked;
|
|
330
|
+
return locked
|
|
331
|
+
? {
|
|
332
|
+
specSha256: hashArtifact(locked.specContent),
|
|
333
|
+
planSha256: hashArtifact(locked.planContent),
|
|
334
|
+
tasksSha256: hashArtifact(locked.tasksContent),
|
|
335
|
+
lockSha256: hashArtifact(locked.lockContent),
|
|
336
|
+
}
|
|
337
|
+
: null;
|
|
338
|
+
}
|
|
339
|
+
export function historyRef(snapshot) {
|
|
340
|
+
const locked = snapshot.locked;
|
|
341
|
+
if (!locked) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
return compact.historyRef(locked, historyRecords(locked.lockContent).length);
|
|
345
|
+
}
|
|
117
346
|
//# sourceMappingURL=resume-history.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import type * as completion from '../types/completion.js';
|
|
2
|
+
import type * as resumeTypes from '../types/resume-views.js';
|
|
3
|
+
import type * as engineTypes from '../types/sdd-engine.js';
|
|
3
4
|
import type { ScopedPolicy, VerificationPolicy } from '../types/verification.js';
|
|
4
|
-
import
|
|
5
|
-
export declare function getResumeCheckpoint(tasksPath: string, workspaceRoot: string, extractCommand: (markdown: string) => string | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal): Promise<SddResult<{
|
|
6
|
-
resume: ResumeCheckpoint;
|
|
5
|
+
import * as compact from './tools/compact-result.js';
|
|
6
|
+
export declare function getResumeCheckpoint(tasksPath: string, workspaceRoot: string, extractCommand: (markdown: string) => string | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal, reader?: completion.VerificationBudgetReader, explicit?: boolean): Promise<engineTypes.SddResult<{
|
|
7
|
+
resume: resumeTypes.ResumeCheckpoint;
|
|
7
8
|
}>>;
|
|
8
|
-
export declare function getResumeToolResult(rawArgs: unknown, workspace: SddWorkspaceHandle, policy?: VerificationPolicy, signal?: AbortSignal): Promise<ReturnType<typeof formatCompactResult>>;
|
|
9
|
+
export declare function getResumeToolResult(rawArgs: unknown, workspace: engineTypes.SddWorkspaceHandle, policy?: VerificationPolicy, signal?: AbortSignal, reader?: completion.VerificationBudgetReader): Promise<ReturnType<typeof compact.formatCompactResult>>;
|
|
9
10
|
//# sourceMappingURL=resume-views.d.ts.map
|