@planu/cli 8.5.1 → 8.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +12 -4
  3. package/dist/sdd-engine/completion-guard.js +2 -3
  4. package/dist/sdd-engine/contracts.d.ts +172 -0
  5. package/dist/sdd-engine/contracts.js +235 -10
  6. package/dist/sdd-engine/evidence-checkpoints.d.ts +6 -0
  7. package/dist/sdd-engine/evidence-checkpoints.js +280 -0
  8. package/dist/sdd-engine/evidence-journal.d.ts +25 -0
  9. package/dist/sdd-engine/evidence-journal.js +326 -0
  10. package/dist/sdd-engine/feature-manifest.d.ts +2 -1
  11. package/dist/sdd-engine/host-rule-pack.d.ts +4 -0
  12. package/dist/sdd-engine/host-rule-pack.js +112 -55
  13. package/dist/sdd-engine/host-skill-reader.d.ts +8 -1
  14. package/dist/sdd-engine/host-skill-reader.js +73 -0
  15. package/dist/sdd-engine/resume-history.d.ts +35 -3
  16. package/dist/sdd-engine/resume-history.js +242 -13
  17. package/dist/sdd-engine/resume-views.d.ts +6 -6
  18. package/dist/sdd-engine/resume-views.js +222 -78
  19. package/dist/sdd-engine/task-content.d.ts +2 -1
  20. package/dist/sdd-engine/tools/compact-result.d.ts +35 -5
  21. package/dist/sdd-engine/tools/compact-result.js +279 -2
  22. package/dist/sdd-engine/tools/execution-tools.js +17 -5
  23. package/dist/sdd-engine/tools/workspace-tools.js +80 -51
  24. package/dist/sdd-engine/trinity-structure.d.ts +2 -2
  25. package/dist/sdd-engine/verification-inputs.d.ts +2 -1
  26. package/dist/sdd-engine/verification-policy.d.ts +2 -1
  27. package/dist/sdd-engine/verification-preflight.d.ts +2 -2
  28. package/dist/sdd-engine/verification-receipts.d.ts +2 -2
  29. package/dist/sdd-engine/verification-runner.d.ts +2 -1
  30. package/dist/types/completion.d.ts +168 -3
  31. package/dist/types/resume-views.d.ts +220 -2
  32. package/dist/types/sdd-engine.d.ts +47 -110
  33. package/dist/types/verification.d.ts +0 -10
  34. package/package.json +5 -5
  35. package/templates/AGENTS.md +2 -0
  36. package/templates/host/planu-sdd.md +2 -0
  37. package/templates/skills/preflight-guardian.md +4 -0
  38. package/templates/skills/reconciler.md +6 -0
  39. package/templates/skills/spec-architect.md +44 -0
  40. package/templates/skills/spec-executor.md +6 -0
  41. package/templates/skills/verification-auditor.md +6 -0
  42. package/dist/sdd-engine/tools/format-result.d.ts +0 -3
  43. package/dist/sdd-engine/tools/format-result.js +0 -22
@@ -1,7 +1,11 @@
1
- import { CompletionGuardError } from '../feature-authority.js';
1
+ import { CompletionGuardError, hashArtifact } from '../feature-authority.js';
2
2
  import { VerificationInputError } from '../verification-inputs.js';
3
3
  const actions = {
4
4
  unlocked: 'review_lock',
5
+ detail_cursor_invalid: 'reread_checkpoint',
6
+ detail_cursor_stale: 'reread_checkpoint',
7
+ journal_cursor_invalid: 'reread_checkpoint',
8
+ journal_cursor_stale: 'reread_checkpoint',
5
9
  history_cursor_stale: 'reread_checkpoint',
6
10
  history_cursor_invalid: 'reread_checkpoint',
7
11
  workspace_unresolved: 'inspect_workspace',
@@ -28,6 +32,12 @@ export function compactFailure(reason, code = 'ERR_INVALID_ARTIFACT') {
28
32
  };
29
33
  }
30
34
  export function compactReadError(error) {
35
+ if (error instanceof CheckpointCapabilityError) {
36
+ return checkpointCapabilityFailure('sdd_get_active_task');
37
+ }
38
+ if (error instanceof CheckpointError) {
39
+ return checkpointError(error.reason, 'sdd_get_active_task');
40
+ }
31
41
  if (error instanceof VerificationInputError && error.reason === 'cancelled') {
32
42
  return compactFailure('cancelled', 'ERR_VERIFICATION_FAILED');
33
43
  }
@@ -61,6 +71,273 @@ export function formatCompactResult(result) {
61
71
  if (Buffer.byteLength(text, 'utf8') > 8192) {
62
72
  return formatCompactResult(compactFailure('compact_response_too_large'));
63
73
  }
64
- return { content: [{ type: 'text', text }], ...(!result.success ? { isError: true } : {}) };
74
+ return {
75
+ content: [{ type: 'text', text }],
76
+ ...(!result.success ? { isError: true } : {}),
77
+ };
78
+ }
79
+ export function formatResult(result) {
80
+ if (!result.success) {
81
+ return {
82
+ content: [
83
+ {
84
+ type: 'text',
85
+ text: JSON.stringify(result, null, 2),
86
+ },
87
+ ],
88
+ isError: true,
89
+ };
90
+ }
91
+ return {
92
+ content: [
93
+ {
94
+ type: 'text',
95
+ text: JSON.stringify(result, null, 2),
96
+ },
97
+ ],
98
+ };
99
+ }
100
+ export class CheckpointCapabilityError extends Error {
101
+ }
102
+ export function checkpointCapabilityFailure(trigger = 'sdd_lock_spec') {
103
+ return {
104
+ success: false,
105
+ error: {
106
+ code: 'ERR_PERMISSION_VIOLATION',
107
+ message: 'Evidence checkpoint requires a supported native runtime.',
108
+ trigger,
109
+ details: {
110
+ reason: 'checkpoint_capability_unavailable',
111
+ nextAction: 'use_supported_runtime',
112
+ },
113
+ },
114
+ };
115
+ }
116
+ const checkpointFailures = {
117
+ checkpoint_input_invalid: {
118
+ code: 'ERR_INVALID_ARTIFACT',
119
+ nextAction: 'fix_inputs',
120
+ },
121
+ checkpoint_requires_lock: { code: 'ERR_SPEC_NOT_LOCKED' },
122
+ checkpoint_requires_active_task: { code: 'ERR_TASK_OUT_OF_SEQUENCE' },
123
+ checkpoint_context_stale: {
124
+ code: 'ERR_SPEC_DRIFT',
125
+ nextAction: 'reread_checkpoint',
126
+ },
127
+ checkpoint_path_unsafe: {
128
+ code: 'ERR_PERMISSION_VIOLATION',
129
+ nextAction: 'inspect_artifacts',
130
+ },
131
+ checkpoint_history_invalid: {
132
+ code: 'ERR_INVALID_ARTIFACT',
133
+ nextAction: 'inspect_artifacts',
134
+ },
135
+ checkpoint_sequence_exhausted: {
136
+ code: 'ERR_INVALID_ARTIFACT',
137
+ nextAction: 'inspect_artifacts',
138
+ },
139
+ guard_present: { code: 'ERR_TASK_OUT_OF_SEQUENCE' },
140
+ persistence_uncertain: {
141
+ code: 'ERR_VERIFICATION_FAILED',
142
+ nextAction: 'inspect_recovery',
143
+ },
144
+ cancelled: { code: 'ERR_VERIFICATION_FAILED' },
145
+ checkpoint_unavailable: { code: 'ERR_VERIFICATION_FAILED' },
146
+ };
147
+ export class CheckpointError extends Error {
148
+ reason;
149
+ code;
150
+ nextAction;
151
+ constructor(reason) {
152
+ super('Checkpoint operation failed.');
153
+ this.reason = reason;
154
+ this.code = checkpointFailures[reason].code;
155
+ this.nextAction = checkpointFailures[reason].nextAction;
156
+ }
157
+ }
158
+ export function checkpointError(reason, trigger = 'sdd_lock_spec') {
159
+ const { code, nextAction } = checkpointFailures[reason];
160
+ return {
161
+ success: false,
162
+ error: {
163
+ code,
164
+ message: 'Evidence checkpoint was denied.',
165
+ trigger,
166
+ details: { reason, ...(nextAction ? { nextAction } : {}) },
167
+ },
168
+ };
169
+ }
170
+ export function checkpointSuccess(seq, recordSha256, journal) {
171
+ return {
172
+ success: true,
173
+ data: {
174
+ checkpoint: {
175
+ version: 1,
176
+ seq,
177
+ recordSha256,
178
+ journal,
179
+ certification: 'none',
180
+ },
181
+ },
182
+ };
183
+ }
184
+ export function checkpointException(error, capabilityUnavailable) {
185
+ if (capabilityUnavailable || checkpointOpenUnsupported(error)) {
186
+ return checkpointCapabilityFailure();
187
+ }
188
+ if (error instanceof CheckpointError) {
189
+ return checkpointError(error.reason);
190
+ }
191
+ if (error instanceof VerificationInputError) {
192
+ if (error.reason === 'cancelled') {
193
+ return checkpointError('cancelled');
194
+ }
195
+ return checkpointError(error.reason === 'receipt_input_drift'
196
+ ? 'checkpoint_context_stale'
197
+ : 'checkpoint_path_unsafe');
198
+ }
199
+ if (error instanceof CompletionGuardError) {
200
+ if (error.reason === 'guard_present' ||
201
+ error.reason === 'persistence_uncertain' ||
202
+ error.reason === 'cancelled') {
203
+ return checkpointError(error.reason);
204
+ }
205
+ if (error.code === 'ERR_SPEC_NOT_LOCKED') {
206
+ return checkpointError('checkpoint_requires_lock');
207
+ }
208
+ if (error.code === 'ERR_PERMISSION_VIOLATION') {
209
+ return checkpointError('checkpoint_path_unsafe');
210
+ }
211
+ return checkpointError('checkpoint_context_stale');
212
+ }
213
+ if (checkpointOpenDenied(error)) {
214
+ return checkpointError('checkpoint_path_unsafe');
215
+ }
216
+ return checkpointError('checkpoint_unavailable');
217
+ }
218
+ export function checkpointOpenUnsupported(error) {
219
+ const native = error instanceof Error ? error : undefined;
220
+ return native?.syscall === 'open' && checkpointUnsupported(error);
221
+ }
222
+ export function checkpointUnsupported(error) {
223
+ const code = error instanceof Error ? error.code : undefined;
224
+ return ['EINVAL', 'ENOTSUP', 'EOPNOTSUPP', 'ENOSYS'].includes(code ?? '');
225
+ }
226
+ export function checkpointOpenDenied(error) {
227
+ const code = error instanceof Error ? error.code : undefined;
228
+ return (checkpointUnsupported(error) ||
229
+ ['EEXIST', 'EACCES', 'EPERM', 'EROFS', 'ENOENT', 'ENOTDIR', 'ELOOP', 'ENAMETOOLONG'].includes(code ?? ''));
230
+ }
231
+ export function checkpointRevalidationError(error) {
232
+ if (error instanceof CompletionGuardError && error.code === 'ERR_SPEC_NOT_LOCKED') {
233
+ throw new CheckpointError('checkpoint_context_stale');
234
+ }
235
+ if (error instanceof Error && error.code === 'EIO') {
236
+ throw new CheckpointError('checkpoint_path_unsafe');
237
+ }
238
+ throw error;
239
+ }
240
+ export function checkpointInitialLockError(error) {
241
+ if (error instanceof Error && error.code === 'ENOENT') {
242
+ throw new CheckpointError('checkpoint_requires_lock');
243
+ }
244
+ if (checkpointOpenUnsupported(error)) {
245
+ throw new CheckpointCapabilityError();
246
+ }
247
+ throw new CheckpointError('checkpoint_path_unsafe');
248
+ }
249
+ export function checkpointDirectoryError() {
250
+ throw new CheckpointError('checkpoint_path_unsafe');
251
+ }
252
+ export function checkpointAcquireIoError(error) {
253
+ if (!(error instanceof Error)) {
254
+ return false;
255
+ }
256
+ const native = error;
257
+ return (checkpointOpenDenied(error) ||
258
+ ['EIO', 'EINTR', 'EBADF', 'ENOSPC', 'EDQUOT', 'EMFILE', 'ENFILE'].includes(native.code ?? '') ||
259
+ (typeof native.errno === 'number' && typeof native.syscall === 'string'));
260
+ }
261
+ export function checkpointGuardInspectionError(error) {
262
+ if (error instanceof CompletionGuardError &&
263
+ (error.reason === 'guard_present' || error.reason === 'persistence_uncertain')) {
264
+ throw error;
265
+ }
266
+ throw new CheckpointError('guard_present');
267
+ }
268
+ function journalEnvelope(featureId, snapshotSha256, journal, records) {
269
+ const last = records.at(-1);
270
+ const nextCursor = journal && last && last.seq > 1
271
+ ? {
272
+ snapshotSha256,
273
+ journalSnapshotSha256: journal.snapshotSha256,
274
+ headSha256: journal.headSha256,
275
+ startSeq: last.seq - 1,
276
+ }
277
+ : null;
278
+ return { version: 1, featureId, snapshotSha256, journal, records, nextCursor };
279
+ }
280
+ export function journalPage(featureId, snapshotSha256, journal, records, startSeq) {
281
+ const selected = [];
282
+ for (const record of records.slice().reverse()) {
283
+ const candidate = [...selected, record];
284
+ const page = journalEnvelope(featureId, snapshotSha256, journal, candidate);
285
+ if (Buffer.byteLength(JSON.stringify({ success: true, data: { evidenceHistory: page } })) > 8192) {
286
+ break;
287
+ }
288
+ selected.push(record);
289
+ }
290
+ if (journal && !selected.length && startSeq > 0) {
291
+ return null;
292
+ }
293
+ return journalEnvelope(featureId, snapshotSha256, journal, selected);
294
+ }
295
+ export function detailEnvelope(featureId, cursor, bytes, end) {
296
+ return {
297
+ version: 1,
298
+ featureId,
299
+ snapshotSha256: cursor.snapshotSha256,
300
+ journalSnapshotSha256: cursor.journalSnapshotSha256,
301
+ section: cursor.section,
302
+ contentSha256: cursor.contentSha256,
303
+ totalBytes: bytes.length,
304
+ offset: cursor.offset,
305
+ text: bytes.subarray(cursor.offset, end).toString('utf8'),
306
+ nextCursor: end < bytes.length ? { ...cursor, offset: end } : null,
307
+ };
308
+ }
309
+ export function resumeProjection(featureId, progress, presentation, contract, assessment, history) {
310
+ const evidence = assessment?.evidence;
311
+ return {
312
+ version: 1,
313
+ featureId,
314
+ progress,
315
+ ...presentation,
316
+ contract,
317
+ candidate: evidence
318
+ ? {
319
+ workspaceSha256: evidence.workspaceSha256,
320
+ candidateSha256: evidence.candidateSha256,
321
+ observedSha256: evidence.observedSha256,
322
+ }
323
+ : null,
324
+ gates: assessment?.preflight.gates ?? [],
325
+ history,
326
+ };
327
+ }
328
+ export function executionWindowResult(window) {
329
+ return { success: true, data: { executionWindow: window } };
330
+ }
331
+ export function historyRef(locked, count) {
332
+ return {
333
+ count,
334
+ lockSha256: hashArtifact(locked.lockContent),
335
+ firstCursor: count ? { snapshotSha256: locked.digest, startIndex: count - 1 } : null,
336
+ };
337
+ }
338
+ export function executionReadError(error) {
339
+ return checkpointOpenUnsupported(error)
340
+ ? checkpointCapabilityFailure('sdd_get_active_task')
341
+ : compactReadError(error);
65
342
  }
66
343
  //# sourceMappingURL=compact-result.js.map
@@ -8,7 +8,7 @@ import { parseManifestContent, parseVerificationReceiptPolicy, toPosixPath, } fr
8
8
  import { captureReceiptEvidence } from '../verification-receipts.js';
9
9
  import { captureVerificationRoot, checkReceiptPatchTarget, revalidateVerificationInputs, } from '../verification-inputs.js';
10
10
  import { completionError, completionFailure, patchMutationError } from '../task-failures.js';
11
- import { formatResult } from './format-result.js';
11
+ import { formatResult } from './compact-result.js';
12
12
  import { getResumeToolResult } from '../resume-views.js';
13
13
  import { acquireCompletionLease, inspectCompletionGuard } from '../completion-guard.js';
14
14
  import { captureCompletionSnapshot, revalidateCompletionSnapshot } from '../completion-snapshot.js';
@@ -70,8 +70,15 @@ function registerGetActiveTaskTool(server, workspace, taskWindow, policy) {
70
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.',
71
71
  inputSchema: GetActiveTaskInputSchema.shape,
72
72
  }, async (rawArgs, extra) => {
73
- if (rawArgs.view === 'resume' ||
74
- rawArgs.view === 'relock_history' ||
73
+ if ([
74
+ 'resume',
75
+ 'execution_window',
76
+ 'execution_detail',
77
+ 'evidence_history',
78
+ 'relock_history',
79
+ ].includes(rawArgs.view ?? '') ||
80
+ rawArgs.execution_cursor !== undefined ||
81
+ rawArgs.evidence_cursor !== undefined ||
75
82
  rawArgs.history_cursor !== undefined) {
76
83
  return getResumeToolResult(rawArgs, workspace, policy, extra.signal);
77
84
  }
@@ -99,7 +106,9 @@ async function getReceiptActiveTask(feature, previousTaskMarkdown, workspaceRoot
99
106
  const trigger = 'sdd_get_active_task';
100
107
  try {
101
108
  const root = await captureVerificationRoot(workspaceRoot);
102
- const snapshot = await captureCompletionSnapshot(feature, { workspaceRoot: root.canonical });
109
+ const snapshot = await captureCompletionSnapshot(feature, {
110
+ workspaceRoot: root.canonical,
111
+ });
103
112
  const current = activeTaskFromContent(snapshot.tasksContent, verificationCommand);
104
113
  const active = current.success ? current.data.activeTask : null;
105
114
  if (!current.success || active?.fullTaskMarkdown !== previousTaskMarkdown) {
@@ -222,7 +231,10 @@ async function executeApplyPatch(workspaceRoot, args) {
222
231
  const root = await captureVerificationRoot(workspaceRoot);
223
232
  const featDir = path.join(root.canonical, '.sdd', 'features', args.feature_id);
224
233
  const authority = { workspaceRoot: root.canonical };
225
- const lease = await acquireCompletionLease(featDir, { ...authority, operation: 'patch' });
234
+ const lease = await acquireCompletionLease(featDir, {
235
+ ...authority,
236
+ operation: 'patch',
237
+ });
226
238
  try {
227
239
  const snapshot = await captureCompletionSnapshot(featDir, authority);
228
240
  const manifest = parseManifestContent(snapshot.planContent);
@@ -1,17 +1,16 @@
1
1
  import * as fs from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- import { InitWorkspaceInputSchema, ListFeaturesInputSchema, CreateFeatureInputSchema, LockSpecInputSchema, } from '../contracts.js';
3
+ import * as contracts from '../contracts.js';
5
4
  import { TaskWindowManager } from '../task-window.js';
6
- import { formatResult } from './format-result.js';
5
+ import * as compact from './compact-result.js';
7
6
  import { homeFallbackFailure } from '../workspace-root.js';
8
7
  import { prepareProjectInitialization } from '../workspace-init.js';
9
8
  import { readTrinityFailureIssues, writeLockedTrinity } from '../lock-integrity.js';
10
9
  import { CompletionGuardError } from '../feature-authority.js';
10
+ import { checkpointCapability } from '../evidence-journal.js';
11
+ import { appendEvidenceCheckpoint } from '../evidence-checkpoints.js';
11
12
  import { reserveAutomaticFeatureDirectory, createExplicitFeatureDirectory, collectFeatures, featurePathFailure, writeFeatureArtifacts, } from './feature-store.js';
12
- import { copyGlobalRules, installCursorGuard, installHostRulePack, installHostSkillPack, inspectHostSkillPack, inspectHostSkillPackDetailed, } from '../host-rule-pack.js';
13
- const moduleDir = path.dirname(fileURLToPath(import.meta.url));
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.';
13
+ import * as hostPack from '../host-rule-pack.js';
15
14
  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
15
  async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
17
16
  const legacySpecsPresent = await fs
@@ -20,7 +19,9 @@ async function composeWorkspaceHint(workspaceRoot, extra, suppliedPack) {
20
19
  .catch(() => false);
21
20
  const pack = suppliedPack
22
21
  ? 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
+ : await hostPack
23
+ .inspectHostSkillPack(workspaceRoot)
24
+ .catch(() => 'Planu host skill verification was unavailable. Run sdd_init_workspace for requested project setup and read the matching role.');
24
25
  const combined = [extra, pack, legacySpecsPresent ? LEGACY_SPECS_HINT : undefined]
25
26
  .filter((item) => item !== undefined)
26
27
  .join(' ');
@@ -49,14 +50,14 @@ export function registerWorkspaceTools(server, workspace, bundledVersion) {
49
50
  function registerInitTool(server, workspace) {
50
51
  server.registerTool('sdd_init_workspace', {
51
52
  description: 'Initializes the SDD workspace creating .sdd/ directory and decoupled skills.',
52
- inputSchema: InitWorkspaceInputSchema.shape,
53
+ inputSchema: contracts.InitWorkspaceInputSchema.shape,
53
54
  }, async (rawArgs) => {
54
- const args = InitWorkspaceInputSchema.parse(rawArgs);
55
+ const args = contracts.InitWorkspaceInputSchema.parse(rawArgs);
55
56
  const resolved = await workspace.resolve();
56
57
  if (args.scope === 'project') {
57
58
  const homeError = homeFallbackFailure(resolved, 'sdd_init_workspace');
58
59
  if (homeError) {
59
- return formatResult(homeError);
60
+ return compact.formatResult(homeError);
60
61
  }
61
62
  }
62
63
  const targetBase = args.scope === 'global'
@@ -71,14 +72,14 @@ function registerInitTool(server, workspace) {
71
72
  await refreshMirrors?.();
72
73
  if (args.scope === 'global') {
73
74
  await fs.mkdir(skillsDir, { recursive: true });
74
- await copySkillTemplates(skillsDir);
75
+ await hostPack.copySkillTemplates(skillsDir);
75
76
  }
76
- const agentsMd = await copyGlobalRules(resolved.workspaceRoot, args.force);
77
- const hostRules = args.scope === 'project' ? await installHostRulePack(resolved.workspaceRoot) : [];
78
- const cursorGuard = args.scope === 'project' ? await installCursorGuard(resolved.workspaceRoot) : [];
79
- const hostSkills = args.scope === 'project' ? await installHostSkillPack(resolved.workspaceRoot) : [];
77
+ const agentsMd = await hostPack.copyGlobalRules(resolved.workspaceRoot, args.force);
78
+ const hostRules = args.scope === 'project' ? await hostPack.installHostRulePack(resolved.workspaceRoot) : [];
79
+ const cursorGuard = args.scope === 'project' ? await hostPack.installCursorGuard(resolved.workspaceRoot) : [];
80
+ const hostSkills = args.scope === 'project' ? await hostPack.installHostSkillPack(resolved.workspaceRoot) : [];
80
81
  const hint = await composeWorkspaceHint(resolved.workspaceRoot, 'Commit .sdd/features with the project. Host quality gates must map .sdd/ as versioned documentation. Cursor, Claude, Gemini, and Codex load Planu skills from sdd_init_workspace host folders, not .sdd/skills. Read .agents/skills/planu-preflight-guardian/SKILL.md and the matching role with sdd_read_file_slice now. Host catalog discovery may require a client/session reload; restarting MCP and reloading host skills are separate actions.');
81
- return formatResult({
82
+ return compact.formatResult({
82
83
  success: true,
83
84
  data: {
84
85
  initializedPath: targetBase,
@@ -98,30 +99,58 @@ function registerInitTool(server, workspace) {
98
99
  });
99
100
  });
100
101
  }
102
+ function listFailure(reason) {
103
+ const failure = compact.compactFailure(reason);
104
+ if (!failure.success) {
105
+ failure.error.trigger = 'sdd_list_features';
106
+ }
107
+ return compact.formatCompactResult(failure);
108
+ }
109
+ async function setupDiagnosticResult(server, workspace, version, args) {
110
+ try {
111
+ const resolved = await workspace.resolve();
112
+ const homeError = homeFallbackFailure(resolved, 'sdd_list_features');
113
+ if (homeError) {
114
+ return compact.formatCompactResult(homeError);
115
+ }
116
+ const setupDiagnostics = await hostPack.inspectSetupDiagnostics(resolved.workspaceRoot, version ?? 'unknown', (args.host ?? 'all'), server.server.getClientVersion());
117
+ return compact.formatCompactResult({ success: true, data: { setupDiagnostics } });
118
+ }
119
+ catch {
120
+ return listFailure('artifact_unavailable');
121
+ }
122
+ }
101
123
  function registerListTool(server, workspace, taskWindow, bundledVersion) {
102
124
  server.registerTool('sdd_list_features', {
103
125
  description: 'Lists executable Planu v8 FEAT-* features from .sdd/features only.',
104
- inputSchema: ListFeaturesInputSchema.shape,
126
+ inputSchema: contracts.ListFeaturesInputSchema,
105
127
  }, async (rawArgs) => {
106
- const args = ListFeaturesInputSchema.parse(rawArgs);
128
+ const parsed = contracts.ListFeaturesInputSchema.safeParse(rawArgs);
129
+ if (!parsed.success) {
130
+ return listFailure('compact_input_invalid');
131
+ }
132
+ const args = parsed.data;
133
+ if (args.view !== undefined || args.host !== undefined) {
134
+ return setupDiagnosticResult(server, workspace, bundledVersion, args);
135
+ }
107
136
  const resolved = await workspace.resolve();
108
137
  const homeError = homeFallbackFailure(resolved, 'sdd_list_features');
109
138
  if (homeError) {
110
- return formatResult(homeError);
139
+ return compact.formatResult(homeError);
111
140
  }
112
141
  const featuresDir = path.join(resolved.sddDir, 'features');
113
142
  const safety = await featurePathFailure(resolved.workspaceRoot, featuresDir, 'sdd_list_features');
114
143
  if (safety) {
115
- return formatResult(safety);
144
+ return compact.formatResult(safety);
116
145
  }
117
146
  const collected = await collectFeatures(featuresDir, taskWindow, args.status_filter);
118
147
  if (!collected.success) {
119
- return formatResult(collected);
148
+ return compact.formatResult(collected);
120
149
  }
121
150
  const featuresList = collected.data;
122
- const skillScan = await inspectHostSkillPackDetailed(resolved.workspaceRoot, bundledVersion ?? 'unknown');
123
- const hint = await composeWorkspaceHint(resolved.workspaceRoot, resolved.sddPresent ? undefined : MISSING_SDD_HINT, skillScan);
124
- return formatResult({
151
+ const skillScan = await hostPack.inspectHostSkillPackDetailed(resolved.workspaceRoot, bundledVersion ?? 'unknown');
152
+ const hint = await composeWorkspaceHint(resolved.workspaceRoot, resolved.sddPresent ? undefined : hostPack.MISSING_SDD_HINT, skillScan);
153
+ return compact.formatResult({
125
154
  success: true,
126
155
  data: {
127
156
  total: featuresList.length,
@@ -138,23 +167,23 @@ function registerListTool(server, workspace, taskWindow, bundledVersion) {
138
167
  function registerCreateTool(server, workspace) {
139
168
  server.registerTool('sdd_create_feature', {
140
169
  description: 'Creates a Holy Trinity feature. Omit id to atomically reserve the next global FEAT-NNNN-TITLE identifier; explicit FEAT-* IDs remain supported.',
141
- inputSchema: CreateFeatureInputSchema.shape,
170
+ inputSchema: contracts.CreateFeatureInputSchema.shape,
142
171
  }, async (rawArgs) => {
143
- const args = CreateFeatureInputSchema.parse(rawArgs);
172
+ const args = contracts.CreateFeatureInputSchema.parse(rawArgs);
144
173
  const resolved = await workspace.resolve();
145
174
  const homeError = homeFallbackFailure(resolved, 'sdd_create_feature');
146
175
  if (homeError) {
147
- return formatResult(homeError);
176
+ return compact.formatResult(homeError);
148
177
  }
149
178
  const featuresDir = path.join(resolved.sddDir, 'features');
150
179
  const safety = await featurePathFailure(resolved.workspaceRoot, featuresDir, 'sdd_create_feature');
151
180
  if (safety) {
152
- return formatResult(safety);
181
+ return compact.formatResult(safety);
153
182
  }
154
183
  await fs.mkdir(featuresDir, { recursive: true });
155
184
  const afterCreation = await featurePathFailure(resolved.workspaceRoot, featuresDir, 'sdd_create_feature');
156
185
  if (afterCreation) {
157
- return formatResult(afterCreation);
186
+ return compact.formatResult(afterCreation);
158
187
  }
159
188
  let featureId = args.id;
160
189
  let featDir;
@@ -162,11 +191,11 @@ function registerCreateTool(server, workspace) {
162
191
  featDir = path.join(featuresDir, featureId);
163
192
  const existingSafety = await featurePathFailure(resolved.workspaceRoot, featDir, 'sdd_create_feature');
164
193
  if (existingSafety) {
165
- return formatResult(existingSafety);
194
+ return compact.formatResult(existingSafety);
166
195
  }
167
196
  const creationFailure = await createExplicitFeatureDirectory(featDir, featureId);
168
197
  if (creationFailure) {
169
- return formatResult(creationFailure);
198
+ return compact.formatResult(creationFailure);
170
199
  }
171
200
  }
172
201
  else {
@@ -176,11 +205,11 @@ function registerCreateTool(server, workspace) {
176
205
  }
177
206
  const featureSafety = await featurePathFailure(resolved.workspaceRoot, featDir, 'sdd_create_feature');
178
207
  if (featureSafety) {
179
- return formatResult(featureSafety);
208
+ return compact.formatResult(featureSafety);
180
209
  }
181
210
  await writeFeatureArtifacts(featDir, featureId, args.title);
182
211
  const hint = await composeWorkspaceHint(resolved.workspaceRoot);
183
- return formatResult({
212
+ return compact.formatResult({
184
213
  success: true,
185
214
  data: {
186
215
  featureId,
@@ -194,29 +223,29 @@ function registerCreateTool(server, workspace) {
194
223
  }
195
224
  function registerLockTool(server, workspace) {
196
225
  server.registerTool('sdd_lock_spec', {
197
- description: 'Locks spec.md, plan.md, and tasks.md. Pass relock=true and reason to reseal after review.',
198
- inputSchema: LockSpecInputSchema.shape,
199
- }, async (rawArgs) => {
200
- const args = LockSpecInputSchema.parse(rawArgs);
226
+ description: 'Locks spec.md, plan.md, and tasks.md. Pass relock=true and reason to reseal after review. The explicit evidence_checkpoint operation records a caller-reported, non-certifying observation.',
227
+ inputSchema: contracts.LockSpecInputSchema,
228
+ }, async (rawArgs, extra) => {
229
+ const args = contracts.LockSpecInputSchema.parse(rawArgs);
230
+ const capability = args.operation === 'evidence_checkpoint' ? checkpointCapability() : null;
231
+ if (args.operation === 'evidence_checkpoint' && !capability) {
232
+ return compact.formatResult(compact.checkpointCapabilityFailure());
233
+ }
201
234
  const resolved = await workspace.resolve();
202
235
  const homeError = homeFallbackFailure(resolved, 'sdd_lock_spec');
203
236
  if (homeError) {
204
- return formatResult(homeError);
237
+ return compact.formatResult(homeError);
205
238
  }
206
239
  const featDir = path.join(resolved.sddDir, 'features', args.feature_id);
240
+ if (args.operation === 'evidence_checkpoint' &&
241
+ capability &&
242
+ args.task_id &&
243
+ args.checkpoint) {
244
+ return compact.formatResult(await appendEvidenceCheckpoint(args.feature_id, args.task_id, args.checkpoint, resolved.workspaceRoot, featDir, capability, extra.signal));
245
+ }
207
246
  return executeLockSpec(featDir, args.feature_id, args.relock === true, args.reason);
208
247
  });
209
248
  }
210
- async function copySkillTemplates(skillsDir) {
211
- const sourceSkillsDir = path.resolve(moduleDir, '..', '..', '..', 'templates', 'skills');
212
- const files = await fs.readdir(sourceSkillsDir);
213
- for (const file of files) {
214
- if (file.endsWith('.md')) {
215
- const content = await fs.readFile(path.join(sourceSkillsDir, file), 'utf-8');
216
- await fs.writeFile(path.join(skillsDir, file), content, 'utf-8');
217
- }
218
- }
219
- }
220
249
  async function executeLockSpec(featDir, featureId, relock, reason) {
221
250
  let outcome;
222
251
  try {
@@ -224,7 +253,7 @@ async function executeLockSpec(featDir, featureId, relock, reason) {
224
253
  }
225
254
  catch (error) {
226
255
  const issues = readTrinityFailureIssues(error);
227
- return formatResult({
256
+ return compact.formatResult({
228
257
  success: false,
229
258
  error: {
230
259
  code: error instanceof CompletionGuardError ? error.code : 'ERR_INVALID_ARTIFACT',
@@ -240,7 +269,7 @@ async function executeLockSpec(featDir, featureId, relock, reason) {
240
269
  });
241
270
  }
242
271
  if (!outcome.ok) {
243
- return formatResult({
272
+ return compact.formatResult({
244
273
  success: false,
245
274
  error: {
246
275
  code: outcome.code,
@@ -250,7 +279,7 @@ async function executeLockSpec(featDir, featureId, relock, reason) {
250
279
  },
251
280
  });
252
281
  }
253
- return formatResult({
282
+ return compact.formatResult({
254
283
  success: true,
255
284
  data: {
256
285
  featureId,
@@ -1,7 +1,7 @@
1
+ import type { ReceiptPolicyText, ReceiptPolicyResult, TaskBlock, ManifestEntry, TrinityCompleteness } from '../types/completion.js';
1
2
  import type { z } from 'zod';
2
3
  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';
4
+ import type { ParsedManifest, TrinityIssue } from '../types/sdd-engine.js';
5
5
  export declare function assessTrinityCompleteness(specContent: string, planContent: string, tasksContent: string): TrinityCompleteness;
6
6
  export declare function parseManifestContent(content: string): ParsedManifest;
7
7
  export declare function manifestEntries(content: string): ManifestEntry[];
@@ -1,4 +1,5 @@
1
- import type { FilePermission, ReceiptCandidate, ReceiptTaskPolicy, VerificationInputCategory, VerificationInputReason, WorkspaceRoot, VerificationInputSnapshot } from '../types/sdd-engine.js';
1
+ import type { ReceiptCandidate, ReceiptTaskPolicy, VerificationInputCategory, VerificationInputReason, WorkspaceRoot, VerificationInputSnapshot } from '../types/completion.js';
2
+ import type { FilePermission } from '../types/sdd-engine.js';
2
3
  export declare class VerificationInputError extends Error {
3
4
  readonly reason: VerificationInputReason;
4
5
  readonly category?: VerificationInputCategory | undefined;
@@ -1,5 +1,6 @@
1
+ import type { ScopedSnapshotResult } from '../types/completion.js';
1
2
  import type { SddFailure, SddResult } from '../types/sdd-engine.js';
2
- import type { ScopedPolicy, ScopedSnapshotResult, ScopedTaskSelector, ScopedVerificationSnapshot, VerificationPolicy } from '../types/verification.js';
3
+ import type { ScopedPolicy, ScopedTaskSelector, ScopedVerificationSnapshot, VerificationPolicy } from '../types/verification.js';
3
4
  export declare const DEFAULT_VERIFICATION_TIMEOUT_MS = 180000;
4
5
  export declare function resolveVerificationPolicy(input?: unknown, workspaceRoot?: string, platform?: NodeJS.Platform): VerificationPolicy;
5
6
  export declare function captureVerificationPolicy(raw: string | undefined, workspaceRoot?: string): VerificationPolicy;
@@ -1,6 +1,6 @@
1
+ import type { WorkspaceRoot, CompletionSnapshot, PreflightReadSnapshot } from '../types/completion.js';
1
2
  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';
3
+ import type { ActiveTaskDetails, ActiveTaskResult, SddResult } from '../types/sdd-engine.js';
4
4
  import type { ScopedPolicy } from '../types/verification.js';
5
5
  /** The same captured authority can be assessed by other read views without selecting again. */
6
6
  export declare function assessVerificationPreflight(snapshot: CompletionSnapshot, root: WorkspaceRoot, workspaceRoot: string, active: ActiveTaskDetails | null, receipts?: unknown, scopedPolicy?: ScopedPolicy, signal?: AbortSignal): Promise<PreflightAssessment>;
@@ -1,6 +1,6 @@
1
+ import type { ReceiptPolicyResult, ReceiptTaskPolicy, WorkspaceRoot, CompletionSnapshot } from '../types/completion.js';
1
2
  export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
2
- import type { CompleteTaskResult, ReceiptPolicyResult, ReceiptTaskPolicy, SddResult, VerificationEvidence, WorkspaceRoot } from '../types/sdd-engine.js';
3
- import type { CompletionSnapshot } from '../types/completion.js';
3
+ import type { CompleteTaskResult, SddResult, VerificationEvidence } from '../types/sdd-engine.js';
4
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';