@planu/cli 8.3.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +61 -2
  3. package/dist/sdd-engine/contracts.d.ts +5 -3
  4. package/dist/sdd-engine/contracts.js +23 -10
  5. package/dist/sdd-engine/feature-manifest.d.ts +2 -5
  6. package/dist/sdd-engine/feature-manifest.js +109 -184
  7. package/dist/sdd-engine/host-rule-pack.d.ts +5 -0
  8. package/dist/sdd-engine/host-rule-pack.js +102 -43
  9. package/dist/sdd-engine/host-skill-reader.d.ts +6 -0
  10. package/dist/sdd-engine/host-skill-reader.js +187 -0
  11. package/dist/sdd-engine/lock-integrity.d.ts +1 -0
  12. package/dist/sdd-engine/lock-integrity.js +25 -17
  13. package/dist/sdd-engine/receipt-assessment.d.ts +12 -0
  14. package/dist/sdd-engine/receipt-assessment.js +223 -0
  15. package/dist/sdd-engine/server.js +2 -4
  16. package/dist/sdd-engine/task-content.d.ts +11 -0
  17. package/dist/sdd-engine/task-content.js +28 -0
  18. package/dist/sdd-engine/task-window.d.ts +1 -0
  19. package/dist/sdd-engine/task-window.js +8 -1
  20. package/dist/sdd-engine/tools/execution-tools.d.ts +1 -11
  21. package/dist/sdd-engine/tools/execution-tools.js +5 -29
  22. package/dist/sdd-engine/tools/workspace-tools.d.ts +1 -1
  23. package/dist/sdd-engine/tools/workspace-tools.js +17 -9
  24. package/dist/sdd-engine/tools.d.ts +2 -1
  25. package/dist/sdd-engine/tools.js +4 -2
  26. package/dist/sdd-engine/trinity-structure.d.ts +25 -0
  27. package/dist/sdd-engine/trinity-structure.js +317 -0
  28. package/dist/sdd-engine/verification-preflight.d.ts +4 -0
  29. package/dist/sdd-engine/verification-preflight.js +271 -0
  30. package/dist/sdd-engine/verification-receipts.d.ts +2 -10
  31. package/dist/sdd-engine/verification-receipts.js +2 -169
  32. package/dist/sdd-engine/workspace-root.d.ts +1 -0
  33. package/dist/sdd-engine/workspace-root.js +1 -0
  34. package/dist/types/completion.d.ts +9 -2
  35. package/dist/types/sdd-engine.d.ts +71 -0
  36. package/package.json +1 -1
  37. package/templates/AGENTS.md +8 -0
  38. package/templates/host/planu-sdd.md +8 -0
@@ -1,178 +1,11 @@
1
- import { createHash, createPublicKey, verify } from 'node:crypto';
1
+ export { maxVerificationReceipts, gateIdPattern, taskIdPattern, featureIdPattern, sha256Schema, importReceiptPublicKey, validateVerificationReceiptSet, assessVerificationReceiptSet, } from './receipt-assessment.js';
2
+ import { validateVerificationReceiptSet } from './receipt-assessment.js';
2
3
  import * as path from 'node:path';
3
- import { z } from 'zod';
4
4
  import { captureCompletionSnapshot, persistCompletionSnapshot, revalidateCompletionSnapshot, } from './completion-snapshot.js';
5
5
  import { hashArtifact } from './feature-authority.js';
6
6
  import { activeTaskFromContent, markReceiptTaskVerified, remainingTaskCount, } from './task-content.js';
7
7
  import { completionFailure, receiptFailure, unsupportedVerificationPlatform, verificationFailed, } from './task-failures.js';
8
8
  import { captureVerificationInputs, captureVerificationRoot, revalidateVerificationInputs, } from './verification-inputs.js';
9
- export const maxVerificationReceipts = 32;
10
- export const gateIdPattern = /^[a-z][a-z0-9-]{0,31}$/u;
11
- export const taskIdPattern = /^TASK-[1-9][0-9]{0,18}$/u;
12
- export const featureIdPattern = /^FEAT[-_][A-Z0-9_-]{1,123}$/u;
13
- export const sha256Schema = z.string().regex(/^[0-9a-f]{64}$/u);
14
- function decodeCanonicalBase64Url(value) {
15
- if (!/^[A-Za-z0-9_-]+$/u.test(value)) {
16
- return undefined;
17
- }
18
- const decoded = Buffer.from(value, 'base64url');
19
- return decoded.toString('base64url') === value ? decoded : undefined;
20
- }
21
- export function importReceiptPublicKey(value) {
22
- const der = value.length <= 128 ? decodeCanonicalBase64Url(value) : undefined;
23
- if (!der) {
24
- return undefined;
25
- }
26
- try {
27
- const key = createPublicKey({ key: der, format: 'der', type: 'spki' });
28
- if (key.asymmetricKeyType !== 'ed25519') {
29
- return undefined;
30
- }
31
- return key.export({ format: 'der', type: 'spki' }).equals(der) ? key : undefined;
32
- }
33
- catch {
34
- return undefined;
35
- }
36
- }
37
- const receiptSchema = z.strictObject({
38
- version: z.literal(1),
39
- featureId: z.string().regex(featureIdPattern),
40
- taskId: z.string().regex(taskIdPattern),
41
- workspaceSha256: sha256Schema,
42
- lockSha256: sha256Schema,
43
- candidateSha256: sha256Schema,
44
- observedSha256: sha256Schema,
45
- gateId: z.string().regex(gateIdPattern),
46
- procedureSha256: sha256Schema,
47
- environmentSha256: sha256Schema,
48
- outcome: z.enum(['pass', 'fail', 'skipped', 'partial']),
49
- evidenceSha256: sha256Schema,
50
- signature: z.string().regex(/^[A-Za-z0-9_-]{86}$/u),
51
- });
52
- const RECEIPT_KEY_COUNT = Object.keys(receiptSchema.shape).length;
53
- function receiptMessage(receipt) {
54
- return [
55
- 'planu.verification-receipt.v1',
56
- receipt.featureId,
57
- receipt.taskId,
58
- receipt.workspaceSha256,
59
- receipt.lockSha256,
60
- receipt.candidateSha256,
61
- receipt.observedSha256,
62
- receipt.gateId,
63
- receipt.procedureSha256,
64
- receipt.environmentSha256,
65
- receipt.outcome,
66
- receipt.evidenceSha256,
67
- ];
68
- }
69
- function decodeReceipt(input) {
70
- if (typeof input !== 'object' ||
71
- input === null ||
72
- Object.keys(input).length !== RECEIPT_KEY_COUNT) {
73
- return undefined;
74
- }
75
- const parsed = receiptSchema.safeParse(input);
76
- if (!parsed.success) {
77
- return undefined;
78
- }
79
- const signature = decodeCanonicalBase64Url(parsed.data.signature);
80
- if (signature?.length !== 64) {
81
- return undefined;
82
- }
83
- return { receipt: parsed.data, message: receiptMessage(parsed.data), signature };
84
- }
85
- function matchCoverage(signed, gates) {
86
- const required = new Set(gates.map((gate) => gate.id));
87
- const byGate = new Map();
88
- for (const entry of signed) {
89
- const gateId = entry.receipt.gateId;
90
- if (!required.has(gateId)) {
91
- return { ok: false, reason: 'receipt_unexpected' };
92
- }
93
- if (byGate.has(gateId)) {
94
- return { ok: false, reason: 'receipt_duplicate', gateId };
95
- }
96
- byGate.set(gateId, entry);
97
- }
98
- const matched = [];
99
- for (const gate of gates) {
100
- const entry = byGate.get(gate.id);
101
- if (!entry) {
102
- return { ok: false, reason: 'receipt_missing', gateId: gate.id };
103
- }
104
- matched.push({ ...entry, gate });
105
- }
106
- return { ok: true, matched };
107
- }
108
- function validateClaims(matched, challenge) {
109
- const checks = [
110
- [
111
- (receipt) => receipt.workspaceSha256 === challenge.workspaceSha256 &&
112
- receipt.featureId === challenge.featureId &&
113
- receipt.taskId === challenge.taskId &&
114
- receipt.lockSha256 === challenge.lockSha256,
115
- 'receipt_context_mismatch',
116
- ],
117
- [
118
- (receipt) => receipt.candidateSha256 === challenge.candidateSha256,
119
- 'receipt_candidate_mismatch',
120
- ],
121
- [(receipt) => receipt.observedSha256 === challenge.observedSha256, 'receipt_observed_mismatch'],
122
- [
123
- (receipt, gate) => receipt.procedureSha256 === gate.procedureSha256,
124
- 'receipt_procedure_mismatch',
125
- ],
126
- [
127
- (receipt, gate) => receipt.environmentSha256 === gate.environmentSha256,
128
- 'receipt_environment_mismatch',
129
- ],
130
- [(receipt) => receipt.outcome === 'pass', 'receipt_non_pass'],
131
- ];
132
- for (const [accepts, reason] of checks) {
133
- const failed = matched.find(({ receipt, gate }) => !accepts(receipt, gate));
134
- if (failed) {
135
- return { ok: false, reason, gateId: failed.gate.id };
136
- }
137
- }
138
- return undefined;
139
- }
140
- export function validateVerificationReceiptSet(input, challenge, publicKey) {
141
- const gates = [...challenge.gates].sort((left, right) => left.id < right.id ? -1 : left.id === right.id ? 0 : 1);
142
- if (input === undefined) {
143
- const gateId = gates[0]?.id;
144
- return { ok: false, reason: 'receipt_missing', ...(gateId ? { gateId } : {}) };
145
- }
146
- if (!Array.isArray(input) || input.length < 1 || input.length > maxVerificationReceipts) {
147
- return { ok: false, reason: 'receipt_malformed' };
148
- }
149
- const signed = [];
150
- for (const raw of input) {
151
- const receipt = decodeReceipt(raw);
152
- if (!receipt) {
153
- return { ok: false, reason: 'receipt_malformed' };
154
- }
155
- signed.push(receipt);
156
- }
157
- const coverage = matchCoverage(signed, gates);
158
- if (!coverage.ok) {
159
- return coverage;
160
- }
161
- for (const { receipt, message, signature } of coverage.matched) {
162
- if (!verify(null, Buffer.from(JSON.stringify(message), 'utf8'), publicKey, signature)) {
163
- return { ok: false, reason: 'receipt_invalid_signature', gateId: receipt.gateId };
164
- }
165
- }
166
- const rejected = validateClaims(coverage.matched, challenge);
167
- if (rejected) {
168
- return rejected;
169
- }
170
- const entries = coverage.matched.map(({ message, receipt }) => [message, receipt.signature]);
171
- const receiptSetSha256 = createHash('sha256')
172
- .update(JSON.stringify(['planu.verification-receipt-set.v1', entries]), 'utf8')
173
- .digest('hex');
174
- return { ok: true, gateCount: entries.length, receiptSetSha256 };
175
- }
176
9
  export async function captureReceiptEvidence(snapshot, workspaceRoot, policy, task, root, signal) {
177
10
  if (path.resolve(snapshot.featDir, '../../..') !== root.canonical) {
178
11
  return completionFailure('contract_drift');
@@ -13,4 +13,5 @@ export declare function readTextInsideWorkspace(workspaceRoot: string, absoluteP
13
13
  ok: false;
14
14
  reason: 'outside' | 'missing';
15
15
  }>;
16
+ export { readTextInsideWorkspaceDetailed } from './host-skill-reader.js';
16
17
  //# sourceMappingURL=workspace-root.d.ts.map
@@ -233,4 +233,5 @@ function unique(values) {
233
233
  }
234
234
  return out;
235
235
  }
236
+ export { readTextInsideWorkspaceDetailed } from './host-skill-reader.js';
236
237
  //# sourceMappingURL=workspace-root.js.map
@@ -1,4 +1,4 @@
1
- import type { SddLockFile, ErrorCode } from './sdd-engine.js';
1
+ import type { SddLockFile, ErrorCode, TrinityIssue } from './sdd-engine.js';
2
2
  export type CompletionFailureReason = 'guard_present' | 'contract_drift' | 'cancelled' | 'persistence_uncertain';
3
3
  export interface PhysicalIdentity {
4
4
  dev: number;
@@ -58,7 +58,8 @@ export type TrinityCompleteness = {
58
58
  code: ErrorCode;
59
59
  message: string;
60
60
  details?: {
61
- missing: string[];
61
+ missing?: string[];
62
+ issues?: TrinityIssue[];
62
63
  };
63
64
  };
64
65
  export type SealResult = {
@@ -74,4 +75,10 @@ export interface PreviousLock {
74
75
  previous?: SddLockFile;
75
76
  artifact?: ArtifactCapture;
76
77
  }
78
+ export interface PreflightReadSnapshot {
79
+ feature: string;
80
+ directories: AuthorityDirectory[];
81
+ artifacts: Partial<Record<'spec.md' | 'plan.md' | 'tasks.md' | '.lock', ArtifactCapture | undefined>>;
82
+ locked?: CompletionSnapshot;
83
+ }
77
84
  //# sourceMappingURL=completion.d.ts.map
@@ -51,6 +51,29 @@ export interface TaskBlock {
51
51
  lineIndex: number;
52
52
  lines: string[];
53
53
  }
54
+ export type TrinityRule = 'out_of_scope' | 'error_matrix' | 'bdd' | 'frozen_dependencies' | 'manifest_path' | 'checkbox_task' | 'glob_delete' | 'protected_write' | 'receipt_policy_invalid' | 'artifact_missing' | 'artifact_unreadable';
55
+ export interface TrinityIssue {
56
+ artifact: 'spec.md' | 'plan.md' | 'tasks.md';
57
+ rule: TrinityRule;
58
+ line?: number;
59
+ }
60
+ export interface ManifestEntry {
61
+ rawPath: string;
62
+ permission: FilePermission;
63
+ line: number;
64
+ }
65
+ export interface PolicySourceFrame {
66
+ path: string;
67
+ root: boolean;
68
+ kind: 'object' | 'array';
69
+ indent: number;
70
+ nextArrayIndex: number;
71
+ }
72
+ export interface ReceiptPolicyText {
73
+ locations?: ReadonlyMap<string, number>;
74
+ text: string | null | undefined;
75
+ line?: number;
76
+ }
54
77
  export interface ReceiptSealFailure {
55
78
  ok: false;
56
79
  code: 'ERR_TRINITY_INCOMPLETE';
@@ -58,6 +81,7 @@ export interface ReceiptSealFailure {
58
81
  details: {
59
82
  reason: 'receipt_policy_invalid';
60
83
  taskId?: string;
84
+ issues: TrinityIssue[];
61
85
  };
62
86
  }
63
87
  export type VerificationReceipt = Omit<VerificationEvidence, 'gates'> & {
@@ -83,6 +107,30 @@ export type ReceiptSetResult = {
83
107
  reason: ReceiptRejectionReason;
84
108
  gateId?: string;
85
109
  };
110
+ export interface GateAssessment {
111
+ gateId: string;
112
+ state: 'receipt_valid' | 'receipt_missing' | 'receipt_rejected';
113
+ reason?: ReceiptRejectionReason;
114
+ }
115
+ export type PreflightBlockerReason = ReceiptRejectionReason | 'unlocked' | 'command_missing' | 'platform_unsupported' | 'receipt_input_unavailable' | 'receipt_observed_baseline_drift' | 'receipt_scoped_unsupported' | 'receipt_not_configured';
116
+ interface PreflightBlocker {
117
+ reason: PreflightBlockerReason;
118
+ }
119
+ export type PreflightAction = 'fix_inputs' | 'review_observed_drift' | 'obtain_receipts' | 'use_supported_runtime' | 'review_lock' | 'restore_verification' | 'attempt_integration' | 'none';
120
+ export interface VerificationPreflight {
121
+ version: 1;
122
+ taskId: string | null;
123
+ status: 'blocked' | 'ready_to_attempt' | 'not_applicable';
124
+ gates: GateAssessment[];
125
+ blockers: PreflightBlocker[];
126
+ integration: 'not_run';
127
+ nextAction: PreflightAction;
128
+ }
129
+ export interface ReceiptSetAssessment {
130
+ result: ReceiptSetResult;
131
+ gates: GateAssessment[];
132
+ blockers: PreflightBlocker[];
133
+ }
86
134
  export interface ReceiptTaskPolicy {
87
135
  taskId: string;
88
136
  gates: readonly VerificationGate[];
@@ -101,6 +149,7 @@ export type ReceiptPolicyResult = {
101
149
  } | {
102
150
  status: 'invalid';
103
151
  taskId?: string;
152
+ issue?: TrinityIssue;
104
153
  } | {
105
154
  status: 'ready';
106
155
  publicKey: KeyObject;
@@ -208,6 +257,7 @@ export interface ActiveTaskResult {
208
257
  permission: FilePermission;
209
258
  }[];
210
259
  verificationEvidence?: VerificationEvidence;
260
+ verificationPreflight?: VerificationPreflight;
211
261
  }
212
262
  export interface CompleteTaskResult {
213
263
  completedTaskId: string;
@@ -278,5 +328,26 @@ export interface ResolveSddWorkspaceInput {
278
328
  export interface SddWorkspaceHandle {
279
329
  resolve(): Promise<ResolvedSddWorkspace>;
280
330
  }
331
+ export type HostSkillReadCause = 'not_found' | 'access_denied' | 'unsafe_path' | 'invalid_content' | 'over_limit' | 'unstable' | 'read_failed';
332
+ export interface HostSkillIssue {
333
+ path: string;
334
+ status: 'missing' | 'different' | 'unreadable';
335
+ cause: HostSkillReadCause | 'content_mismatch';
336
+ }
337
+ export interface HostSkillDiagnostics {
338
+ version: 1;
339
+ bundledVersion: string;
340
+ baseline: 'available' | 'unavailable';
341
+ catalog: 'unverified';
342
+ issues: HostSkillIssue[];
343
+ nextAction: 'none' | 'review_project_setup' | 'inspect_unsafe_paths' | 'inspect_installation';
344
+ }
345
+ export type HostSkillReadResult = {
346
+ ok: true;
347
+ text: string;
348
+ } | {
349
+ ok: false;
350
+ cause: HostSkillReadCause;
351
+ };
281
352
  export {};
282
353
  //# sourceMappingURL=sdd-engine.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planu/cli",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "description": "Planu — MCP server for Spec Driven Development. Planning and file operations on macOS/Linux/Windows; automated verification requires macOS/Linux (POSIX).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -7,6 +7,14 @@ Canonical contract: `PLANU_V8_MANIFESTO.txt`.
7
7
 
8
8
  After the local client has registered the MCP server and the intended project is open, use `sdd_list_features` to inspect setup. A setup request authorizes `sdd_init_workspace(scope="project")` in that identified project; connecting or inspecting alone does not. Use the default `force=false` to preserve an existing current AGENTS.md. Read `.agents/skills/planu-preflight-guardian/SKILL.md` and the matching role immediately with `sdd_read_file_slice` before feature work. Initialization installs nine roles in four host formats. Matching files do not prove that the host has loaded them: a host/session catalog reload may be required, separately from restarting the MCP server. Do not promise automatic compliance by every client or model. For tasks using the locked receipt policy, take the current challenge from sdd_get_active_task. Obtain gate evidence from the operator-controlled issuer and pass the signed receipts to sdd_complete_task. The server still runs the task integration command. A changed observed baseline requires reviewed resolution.
9
9
 
10
+ ## Read-only diagnostics
11
+
12
+ Use `sdd_list_features.hostSkills` to identify fixed installed role paths, causes and the bundled reference version. `catalog` stays `unverified` even when files match. An unavailable baseline requires inspecting the installation; unsafe paths require inspection before authorized setup. Project setup and client catalogue reload are explicit, separate actions.
13
+
14
+ For a rejected `sdd_lock_spec`, inspect `error.details.issues` for artifact, stable rule and optional 1-based original source line. Missing or ambiguous locations omit the line. Existing rejection codes and legacy details remain authoritative; rejection writes no lock. Do not automatically relock.
15
+
16
+ Before verification, request `sdd_get_active_task` with `view="verification_preflight"` and optional `verification_receipts`. Require `verificationPreflight.version=1`; older servers may ignore the view. Inspect per-gate states, aggregate blockers and `nextAction`. `ready_to_attempt` only permits attempting integration; runtime prerequisites and integration remain unverified. Preflight runs no command, consumes no grant, writes no artifact and issues no certificate. Keep the default task read and all nine tools unchanged.
17
+
10
18
  ## Delegation
11
19
 
12
20
  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.
@@ -6,6 +6,14 @@ The only SDD contract is `.sdd/features/{FEAT-*}/spec.md`, `plan.md`, and `tasks
6
6
 
7
7
  After the local client has registered the MCP server and the intended project is open, use `sdd_list_features` to inspect setup. A setup request authorizes `sdd_init_workspace(scope="project")` in that identified project; connecting or inspecting alone does not. Use the default `force=false` to preserve an existing current AGENTS.md. Read `.agents/skills/planu-preflight-guardian/SKILL.md` and the matching role immediately with `sdd_read_file_slice` before feature work. Initialization installs nine roles in four host formats. Matching files do not prove that the host has loaded them: a host/session catalog reload may be required, separately from restarting the MCP server. Do not promise automatic compliance by every client or model.
8
8
 
9
+ ## Read-only diagnostics
10
+
11
+ Use `sdd_list_features.hostSkills` to identify fixed installed role paths, causes and the bundled reference version. `catalog` stays `unverified` even when files match. An unavailable baseline requires inspecting the installation; unsafe paths require inspection before authorized setup. Project setup and client catalogue reload are explicit, separate actions.
12
+
13
+ For a rejected `sdd_lock_spec`, inspect `error.details.issues` for artifact, stable rule and optional 1-based original source line. Missing or ambiguous locations omit the line. Existing rejection codes and legacy details remain authoritative; rejection writes no lock. Do not automatically relock.
14
+
15
+ Before verification, request `sdd_get_active_task` with `view="verification_preflight"` and optional `verification_receipts`. Require `verificationPreflight.version=1`; older servers may ignore the view. Inspect per-gate states, aggregate blockers and `nextAction`. `ready_to_attempt` only permits attempting integration; runtime prerequisites and integration remain unverified. Preflight runs no command, consumes no grant, writes no artifact and issues no certificate. Keep the default task read and all nine tools unchanged.
16
+
9
17
  ## Delegation
10
18
 
11
19
  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.