@planu/cli 8.2.13 → 8.2.15

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 CHANGED
@@ -1,3 +1,18 @@
1
+ ## [8.2.15] - 2026-10-22
2
+
3
+ - state that Planu does not upload the project, that npx contacts the npm registry, and that the source is not published
4
+ - publish the proprietary license at planu.dev/license and describe the local package in the privacy notice
5
+ - show a project .mcp.json pinned to the package version, and keep @latest for individual installs
6
+ - remove the dead github.com/planu-dev/planu link from live package metadata
7
+
8
+ ## [8.2.14] - 2026-10-21
9
+
10
+ - retain the default 180-second verification limit and nine-tool contract; allow an operator-reviewed startup-only grant for one exact task, up to 600 seconds on Darwin/Linux
11
+ - pin canonical paths and full lock/command hashes; consume the grant at first spawn and quarantine uncertain cleanup or persistence
12
+ - propagate request cancellation, stdio EOF and repeated shutdown signals to owned-group cleanup; bound completion I/O and verify persisted task/lock bytes
13
+ - refresh devDependencies: commitlint 21.2.4, vitest 5.0.5, eslint 10.13.0, typescript-eslint 8.72.0, knip 6.42.1, happy-dom 21.0.4, tsc-alias 1.9.8, and type-coverage 2.30.4
14
+ - keep @types/node on 22.20.5, Vite on 8.3.4, and engines on Node >=22.13.0
15
+
1
16
  ## [8.2.13] - 2026-10-14
2
17
 
3
18
  - the bug report form keeps the prefilled Planu version and host after a successful send and clears the previous status while sending
package/README.md CHANGED
@@ -34,7 +34,7 @@ Claude Code users can install Planu as a plugin instead of hand-editing `.mcp.js
34
34
  /plugin install planu@planu
35
35
  ```
36
36
 
37
- This registers the same `npx -y @planu/cli@latest` server. The plugin also ships `planu-guard` hooks: while a locked feature has an unchecked task, native `Write`/`Edit` inside the workspace is denied in favor of `sdd_apply_file_patch`; `git ... --no-verify` is denied; and session start re-injects the active task. Disable them with the plugin manager.
37
+ This registers the same `npx -y @planu/cli@latest` server. `planu-dev/planu` is not a public source repository. Use a project `.mcp.json` and do not point the server at `$HOME`. The plugin also ships `planu-guard` hooks: while a locked feature has an unchecked task, native `Write`/`Edit` inside the workspace is denied in favor of `sdd_apply_file_patch`; `git ... --no-verify` is denied; and session start re-injects the active task. Disable them with the plugin manager.
38
38
 
39
39
  ### Codex plugin
40
40
 
@@ -108,6 +108,14 @@ The published server asks the host for MCP roots and binds to the open project t
108
108
 
109
109
  ---
110
110
 
111
+ ## Trusted verification budget
112
+
113
+ Normal task verification still has a 180000 ms limit. An operator may authorize one pinned task in an isolated Darwin/Linux server with a strict startup-only budget of 180001–600000 ms. The grant binds the canonical workspace, feature, task, raw lock SHA-256 and exact command SHA-256. It is consumed before the first spawn, including failed attempts; uncertain cleanup or persistence quarantines that feature.
114
+
115
+ There is no timeout tool argument. The nine tools and the three complete-task fields are unchanged. The programmatic factory ignores the CLI environment unless its optional typed policy is explicitly supplied. Agents must not create or widen grants themselves.
116
+
117
+ The reviewed operator procedure is in the repository guide `docs/verification-budget.md`: finite local-build fingerprint, exact policy schema, per-process Node 24.22.1 PATH, SDK request budget of 660000 ms, one-use launch and safe disable/reconciliation. The grant is not a global registration or a cache replacement. Barbuno acceptance remains a separate handoff.
118
+
111
119
  ## The SDD Lifecycle (v8)
112
120
 
113
121
  ```text
@@ -175,8 +183,23 @@ node dist/sdd-engine/cli.js
175
183
 
176
184
  ## Reporting bugs
177
185
 
178
- Report a bug at https://planu.dev/report. The form takes a summary, details, the Planu version, the host, and an optional contact email. The engine itself sends nothing.
186
+ Report a bug at https://planu.dev/report. The form takes a summary, details, the Planu version, the host, and an optional contact email. The engine itself sends nothing. npx still contacts the npm registry. The CLI does not upload the workspace.
179
187
 
180
188
  ## License
181
189
 
182
- See the [Planu Proprietary Free-Use License](LICENSE) for the complete terms.
190
+ See the [Planu Proprietary Free-Use License](LICENSE) and [planu.dev/license](https://planu.dev/license/) for the complete terms. Individuals use `@planu/cli@latest`, which asks npm for the current release on every start. Teams pin one version in a project `.mcp.json`. The home page renders that pin from the package version.
191
+
192
+ ```json
193
+ {
194
+ "mcpServers": {
195
+ "planu": {
196
+ "command": "npx",
197
+ "args": ["-y", "@planu/cli@8.2.15"],
198
+ "cwd": ".",
199
+ "env": {
200
+ "PLANU_WORKSPACE": "."
201
+ }
202
+ }
203
+ }
204
+ }
205
+ ```
@@ -12,6 +12,7 @@ The only SDD contract is \`.sdd/features/{FEAT-*}/spec.md\`, \`plan.md\`, and \`
12
12
  - Never create, thin, or copy files under \`planu/specs/\`. Planu does not read that tree.
13
13
  - If a pre-push, commitlint, or husky guard still requires \`planu/specs/SPEC-*/spec.md\`, that guard is the defect. Delete or rewrite it. Do not stub a SPEC file.
14
14
  - Quality lives in \`.claude/skills/\`, \`.cursor/skills/\`, \`.agents/skills/\`, and \`.gemini/skills/\`. Specs stay in \`.sdd/features\`. There is no validate MCP tool.
15
+ - Agents must never grant themselves extra verification time or edit trusted launcher policy. Report budget failures for operator review; an approved startup grant does not change task or File Manifest authority.
15
16
  `;
16
17
  const PROHIBITION = /\b(never|do not|don't|no longer|not|forbidden|prohibited|deleted|removed|retired|invalid|reject(?:s|ed)?)\b/iu;
17
18
  const LEGACY_TREE = /planu\/specs\/SPEC-|write (?:specs )?to planu\/specs/iu;
@@ -1,4 +1,5 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- export declare function createUltralightSddServer(workspaceRoot?: string): McpServer;
2
+ import type { VerificationServerOptions } from '../types/verification.js';
3
+ export declare function createUltralightSddServer(workspaceRoot?: string, options?: VerificationServerOptions): McpServer;
3
4
  export declare function runServer(): Promise<void>;
4
5
  //# sourceMappingURL=server.d.ts.map
@@ -1,24 +1,72 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { captureVerificationPolicy, resolveVerificationPolicy } from './verification-policy.js';
4
5
  import { registerUltralightSddTools } from './tools.js';
5
6
  const { version } = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
6
- export function createUltralightSddServer(workspaceRoot) {
7
- const server = new McpServer({
8
- name: 'sdd-engine',
9
- version,
10
- }, {
11
- capabilities: {
12
- tools: {},
13
- },
7
+ export function createUltralightSddServer(workspaceRoot, options) {
8
+ const policy = resolveVerificationPolicy(options?.verificationPolicy, workspaceRoot);
9
+ const server = new McpServer({ name: 'sdd-engine', version }, {
10
+ capabilities: { tools: {} },
14
11
  instructions: 'SDD Engine v8: FEAT-only state arbiter, File Manifest sandbox, and single-task context window for Spec-Driven Development.',
15
12
  });
16
- registerUltralightSddTools(server, workspaceRoot);
13
+ const pinnedRoot = policy.mode === 'scoped' ? policy.workspaceRoot : workspaceRoot;
14
+ const tasks = registerUltralightSddTools(server, pinnedRoot, policy);
15
+ if (policy.mode === 'scoped') {
16
+ const close = server.close.bind(server);
17
+ server.close = async () => {
18
+ await tasks.shutdown();
19
+ await close();
20
+ };
21
+ const previous = server.server.onclose;
22
+ server.server.onclose = () => {
23
+ previous?.();
24
+ void tasks.shutdown().catch(() => {
25
+ console.error('ERR_VERIFICATION_SHUTDOWN');
26
+ });
27
+ };
28
+ }
17
29
  return server;
18
30
  }
19
31
  export async function runServer() {
20
- const server = createUltralightSddServer();
32
+ const policy = captureVerificationPolicy(process.env.PLANU_VERIFICATION_TIMEOUT_POLICY);
33
+ const server = createUltralightSddServer(undefined, policy.mode === 'scoped' ? { verificationPolicy: policy } : undefined);
34
+ if (policy.mode === 'scoped') {
35
+ bindScopedShutdown(server);
36
+ }
21
37
  const transport = new StdioServerTransport();
22
38
  await server.connect(transport);
23
39
  }
40
+ function bindScopedShutdown(server) {
41
+ let closing = false;
42
+ const shutdown = () => {
43
+ if (closing) {
44
+ return;
45
+ }
46
+ closing = true;
47
+ void server
48
+ .close()
49
+ .catch(() => {
50
+ console.error('ERR_VERIFICATION_SHUTDOWN');
51
+ })
52
+ .finally(() => {
53
+ process.stdin.pause();
54
+ });
55
+ };
56
+ process.stdin.once('end', shutdown);
57
+ process.stdin.once('close', shutdown);
58
+ for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) {
59
+ process.on(signal, shutdown);
60
+ }
61
+ const protocol = server.server;
62
+ const previous = protocol.onclose;
63
+ protocol.onclose = () => {
64
+ previous?.();
65
+ process.stdin.removeListener('end', shutdown);
66
+ process.stdin.removeListener('close', shutdown);
67
+ for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) {
68
+ process.removeListener(signal, shutdown);
69
+ }
70
+ };
71
+ }
24
72
  //# sourceMappingURL=server.js.map
@@ -1,10 +1,18 @@
1
1
  import type { ActiveTaskResult, CompleteTaskResult, SddResult } from '../types/sdd-engine.js';
2
+ import type { VerificationPolicy } from '../types/verification.js';
2
3
  export declare class TaskWindowManager {
4
+ private readonly scopedPolicy;
5
+ private readonly scoped;
6
+ constructor(policy?: VerificationPolicy);
7
+ shutdown(): Promise<void>;
8
+ private activeTaskFromContent;
9
+ private selectScopedTask;
10
+ private commitScopedTask;
3
11
  getActiveTask(tasksFilePath: string): Promise<SddResult<ActiveTaskResult>>;
4
12
  private buildActiveTaskResult;
5
13
  private parseTasks;
6
14
  private extractTaskId;
7
- completeTask(tasksFilePath: string, taskId: string, workspaceRoot: string, _verificationOutput: string): Promise<SddResult<CompleteTaskResult>>;
15
+ completeTask(tasksFilePath: string, taskId: string, workspaceRoot: string, _verificationOutput: string, signal?: AbortSignal): Promise<SddResult<CompleteTaskResult>>;
8
16
  }
9
17
  export declare function verificationCommand(taskMarkdown: string): string | null;
10
18
  //# sourceMappingURL=task-window.d.ts.map
@@ -1,8 +1,54 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import * as fs from 'node:fs/promises';
3
3
  import * as path from 'node:path';
4
+ import { ScopedVerificationCoordinator } from './verification-runner.js';
5
+ import { persistScopedCompletionFiles, scopedVerificationEnvironment, } from './verification-policy.js';
4
6
  import { hashArtifact } from './lock-integrity.js';
5
7
  export class TaskWindowManager {
8
+ scopedPolicy;
9
+ scoped;
10
+ constructor(policy) {
11
+ this.scopedPolicy = policy?.mode === 'scoped' ? policy : undefined;
12
+ this.scoped = this.scopedPolicy
13
+ ? new ScopedVerificationCoordinator(this.scopedPolicy)
14
+ : undefined;
15
+ }
16
+ async shutdown() {
17
+ await this.scoped?.shutdown();
18
+ }
19
+ activeTaskFromContent(content) {
20
+ return this.buildActiveTaskResult(this.parseTasks(content.split('\n')));
21
+ }
22
+ selectScopedTask(content) {
23
+ const result = this.activeTaskFromContent(content);
24
+ const active = result.success ? result.data.activeTask : null;
25
+ return active
26
+ ? {
27
+ taskId: active.taskId,
28
+ command: verificationCommand(active.fullTaskMarkdown),
29
+ }
30
+ : null;
31
+ }
32
+ async commitScopedTask(policy, taskId, snapshot, output, signal) {
33
+ const summary = summarizeEvidence(output);
34
+ const marked = markTaskVerified(snapshot.tasksContent.split('\n'), taskId, summary);
35
+ if (marked === null) {
36
+ return taskOutOfSequence(taskId, null);
37
+ }
38
+ const written = marked.join('\n');
39
+ const persisted = await persistScopedCompletionFiles(policy, snapshot, written, signal);
40
+ if (!persisted.success) {
41
+ return persisted;
42
+ }
43
+ return {
44
+ success: true,
45
+ data: {
46
+ completedTaskId: taskId,
47
+ verificationSummary: summary,
48
+ remainingTasks: remainingTaskCount(this.activeTaskFromContent(written)),
49
+ },
50
+ };
51
+ }
6
52
  async getActiveTask(tasksFilePath) {
7
53
  let content;
8
54
  try {
@@ -18,8 +64,7 @@ export class TaskWindowManager {
18
64
  },
19
65
  };
20
66
  }
21
- const acc = this.parseTasks(content.split('\n'));
22
- return this.buildActiveTaskResult(acc);
67
+ return this.activeTaskFromContent(content);
23
68
  }
24
69
  buildActiveTaskResult(acc) {
25
70
  if (acc.totalTasks === 0) {
@@ -97,7 +142,21 @@ export class TaskWindowManager {
97
142
  }
98
143
  return { id: `TASK-${index}`, title: rawTitle };
99
144
  }
100
- async completeTask(tasksFilePath, taskId, workspaceRoot, _verificationOutput) {
145
+ async completeTask(tasksFilePath, taskId, workspaceRoot, _verificationOutput, signal) {
146
+ const policy = this.scopedPolicy;
147
+ if (this.scoped && policy) {
148
+ const scoped = await this.scoped.complete({
149
+ tasksPath: tasksFilePath,
150
+ taskId,
151
+ workspaceRoot,
152
+ signal,
153
+ selectTask: (content) => this.selectScopedTask(content),
154
+ commit: (snapshot, output, abortSignal) => this.commitScopedTask(policy, taskId, snapshot, output, abortSignal),
155
+ });
156
+ if (scoped) {
157
+ return scoped;
158
+ }
159
+ }
101
160
  let content;
102
161
  try {
103
162
  content = await fs.readFile(tasksFilePath, 'utf-8');
@@ -117,7 +176,7 @@ export class TaskWindowManager {
117
176
  if (command === null) {
118
177
  return verificationMissing();
119
178
  }
120
- const run = await runVerification(workspaceRoot, command);
179
+ const run = await runVerification(workspaceRoot, command, this.scopedPolicy ? scopedVerificationEnvironment() : undefined);
121
180
  if (!run.ok) {
122
181
  return verificationFailed(run);
123
182
  }
@@ -224,12 +283,13 @@ export function verificationCommand(taskMarkdown) {
224
283
  }
225
284
  return command;
226
285
  }
227
- function runVerification(cwd, command) {
286
+ function runVerification(cwd, command, env) {
228
287
  return new Promise((resolve) => {
229
288
  const child = spawn(command, {
230
289
  cwd,
231
290
  shell: true,
232
291
  timeout: VERIFICATION_TIMEOUT_MS,
292
+ ...(env ? { env } : {}),
233
293
  windowsHide: true,
234
294
  });
235
295
  let output = '';
@@ -1,4 +1,6 @@
1
+ import type { VerificationPolicy } from '../../types/verification.js';
1
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { TaskWindowManager } from '../task-window.js';
2
4
  import type { SddWorkspaceHandle } from '../../types/sdd-engine.js';
3
- export declare function registerExecutionTools(server: McpServer, workspace: SddWorkspaceHandle): void;
5
+ export declare function registerExecutionTools(server: McpServer, workspace: SddWorkspaceHandle, policy?: VerificationPolicy): TaskWindowManager;
4
6
  //# sourceMappingURL=execution-tools.d.ts.map
@@ -6,13 +6,14 @@ import { TaskWindowManager } from '../task-window.js';
6
6
  import { formatResult } from './format-result.js';
7
7
  import { verifyLockedTrinity } from '../lock-integrity.js';
8
8
  import { homeFallbackFailure } from '../workspace-root.js';
9
- export function registerExecutionTools(server, workspace) {
10
- const taskWindow = new TaskWindowManager();
9
+ export function registerExecutionTools(server, workspace, policy) {
10
+ const taskWindow = new TaskWindowManager(policy);
11
11
  registerReadArtifactTool(server, workspace);
12
12
  registerReadFileSliceTool(server, workspace);
13
13
  registerGetActiveTaskTool(server, workspace, taskWindow);
14
14
  registerApplyPatchTool(server, workspace);
15
15
  registerCompleteTaskTool(server, workspace, taskWindow);
16
+ return taskWindow;
16
17
  }
17
18
  function registerReadArtifactTool(server, workspace) {
18
19
  server.registerTool('sdd_read_spec_artifact', {
@@ -91,7 +92,7 @@ function registerCompleteTaskTool(server, workspace, taskWindow) {
91
92
  server.registerTool('sdd_complete_task', {
92
93
  description: 'Completes the active task by running its Verification command in the workspace and storing that output. verification_output is accepted and ignored.',
93
94
  inputSchema: CompleteTaskInputSchema.shape,
94
- }, async (rawArgs) => {
95
+ }, async (rawArgs, extra) => {
95
96
  const args = CompleteTaskInputSchema.parse(rawArgs);
96
97
  const resolved = await workspace.resolve();
97
98
  const homeError = homeFallbackFailure(resolved, 'sdd_complete_task');
@@ -104,7 +105,7 @@ function registerCompleteTaskTool(server, workspace, taskWindow) {
104
105
  return lockError;
105
106
  }
106
107
  const tasksPath = path.join(featDir, 'tasks.md');
107
- const result = await taskWindow.completeTask(tasksPath, args.task_id, resolved.workspaceRoot, args.verification_output);
108
+ const result = await taskWindow.completeTask(tasksPath, args.task_id, resolved.workspaceRoot, args.verification_output, extra.signal);
108
109
  return formatResult(result);
109
110
  });
110
111
  }
@@ -1,3 +1,5 @@
1
+ import type { VerificationPolicy } from '../types/verification.js';
2
+ import type { TaskWindowManager } from './task-window.js';
1
3
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- export declare function registerUltralightSddTools(server: McpServer, pinnedRoot?: string): void;
4
+ export declare function registerUltralightSddTools(server: McpServer, pinnedRoot?: string, policy?: VerificationPolicy): TaskWindowManager;
3
5
  //# sourceMappingURL=tools.d.ts.map
@@ -1,9 +1,9 @@
1
1
  import { McpClientWorkspace } from './client-workspace.js';
2
2
  import { registerWorkspaceTools } from './tools/workspace-tools.js';
3
3
  import { registerExecutionTools } from './tools/execution-tools.js';
4
- export function registerUltralightSddTools(server, pinnedRoot) {
4
+ export function registerUltralightSddTools(server, pinnedRoot, policy) {
5
5
  const workspace = new McpClientWorkspace(server, pinnedRoot);
6
6
  registerWorkspaceTools(server, workspace);
7
- registerExecutionTools(server, workspace);
7
+ return registerExecutionTools(server, workspace, policy);
8
8
  }
9
9
  //# sourceMappingURL=tools.js.map
@@ -0,0 +1,16 @@
1
+ import type { SddFailure, SddResult } from '../types/sdd-engine.js';
2
+ import type { ScopedPolicy, ScopedSnapshotResult, ScopedTaskSelector, ScopedVerificationSnapshot, VerificationPolicy } from '../types/verification.js';
3
+ export declare const DEFAULT_VERIFICATION_TIMEOUT_MS = 180000;
4
+ export declare function resolveVerificationPolicy(input?: unknown, workspaceRoot?: string, platform?: NodeJS.Platform): VerificationPolicy;
5
+ export declare function captureVerificationPolicy(raw: string | undefined, workspaceRoot?: string): VerificationPolicy;
6
+ export declare function verificationDigest(content: string | Uint8Array): string;
7
+ export declare function isScopedVerificationFeature(policy: ScopedPolicy, featureDirectory: string): Promise<boolean>;
8
+ export declare function readScopedVerificationSnapshot(policy: ScopedPolicy, tasksPath: string, workspaceRoot: string, requestedTaskId: string, selectTask: ScopedTaskSelector): Promise<ScopedSnapshotResult>;
9
+ export declare function revalidateScopedVerificationSnapshot(policy: ScopedPolicy, snapshot: ScopedVerificationSnapshot, selectTask: ScopedTaskSelector): Promise<ScopedSnapshotResult>;
10
+ export declare function uncertainCompletion(): SddFailure;
11
+ export declare function persistScopedCompletionFiles(policy: ScopedPolicy, snapshot: ScopedVerificationSnapshot, writtenTasks: string, signal: AbortSignal): Promise<SddResult<null>>;
12
+ export declare function scopedFeaturePathFailure(policy: ScopedPolicy): Promise<SddFailure | null>;
13
+ export declare function scopedVerificationEnvironment(): NodeJS.ProcessEnv;
14
+ export declare function scopedFailure(details: Record<string, unknown>): SddFailure;
15
+ export declare function cancelledVerification(signal: AbortSignal): SddFailure | null;
16
+ //# sourceMappingURL=verification-policy.d.ts.map
@@ -0,0 +1,337 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { lstatSync, realpathSync } from 'node:fs';
3
+ import * as fs from 'node:fs/promises';
4
+ import * as path from 'node:path';
5
+ import { z } from 'zod';
6
+ export const DEFAULT_VERIFICATION_TIMEOUT_MS = 180000;
7
+ const MAX_VERIFICATION_TIMEOUT_MS = 600000;
8
+ const hashSchema = z.string().regex(/^[a-f0-9]{64}$/u);
9
+ const policySchema = z.discriminatedUnion('mode', [
10
+ z.strictObject({ version: z.literal(1), mode: z.literal('disabled') }),
11
+ z.strictObject({
12
+ version: z.literal(1),
13
+ mode: z.literal('scoped'),
14
+ workspaceRoot: z.string().min(1),
15
+ featureId: z.string().regex(/^FEAT[-_][A-Z0-9_-]+$/u),
16
+ taskId: z.string().regex(/^TASK-[A-Z0-9_-]+$/u),
17
+ timeoutMs: z.number().int().min(180001).max(MAX_VERIFICATION_TIMEOUT_MS),
18
+ lockSha256: hashSchema,
19
+ verificationCommandSha256: hashSchema,
20
+ }),
21
+ ]);
22
+ const lockSchema = z.object({
23
+ specHash: hashSchema,
24
+ planHash: hashSchema,
25
+ tasksHash: hashSchema,
26
+ });
27
+ export function resolveVerificationPolicy(input, workspaceRoot, platform = process.platform) {
28
+ try {
29
+ if (input === undefined) {
30
+ return Object.freeze({ mode: 'default', timeoutMs: DEFAULT_VERIFICATION_TIMEOUT_MS });
31
+ }
32
+ const policy = policySchema.parse(input);
33
+ if (policy.mode === 'disabled') {
34
+ return Object.freeze({ mode: 'default', timeoutMs: DEFAULT_VERIFICATION_TIMEOUT_MS });
35
+ }
36
+ if (!['darwin', 'linux'].includes(platform) ||
37
+ !isCanonicalRoot(policy.workspaceRoot) ||
38
+ (workspaceRoot !== undefined && workspaceRoot !== policy.workspaceRoot)) {
39
+ throw new Error('Invalid pin');
40
+ }
41
+ return Object.freeze({ ...policy });
42
+ }
43
+ catch {
44
+ throw new Error('ERR_VERIFICATION_POLICY_INVALID');
45
+ }
46
+ }
47
+ export function captureVerificationPolicy(raw, workspaceRoot) {
48
+ if (raw === undefined) {
49
+ return resolveVerificationPolicy(undefined, workspaceRoot);
50
+ }
51
+ try {
52
+ const input = JSON.parse(raw);
53
+ return resolveVerificationPolicy(input, workspaceRoot);
54
+ }
55
+ catch {
56
+ throw new Error('ERR_VERIFICATION_POLICY_INVALID');
57
+ }
58
+ }
59
+ function isCanonicalRoot(root) {
60
+ return (path.isAbsolute(root) &&
61
+ path.normalize(root) === root &&
62
+ realpathSync(root) === root &&
63
+ !lstatSync(root).isSymbolicLink() &&
64
+ lstatSync(root).isDirectory());
65
+ }
66
+ export function verificationDigest(content) {
67
+ return createHash('sha256').update(content).digest('hex');
68
+ }
69
+ export async function isScopedVerificationFeature(policy, featureDirectory) {
70
+ const granted = path.join(policy.workspaceRoot, '.sdd', 'features', policy.featureId);
71
+ if (path.resolve(featureDirectory) === granted) {
72
+ return true;
73
+ }
74
+ try {
75
+ const [requested, expected] = await Promise.all([fs.stat(featureDirectory), fs.stat(granted)]);
76
+ return requested.dev === expected.dev && requested.ino === expected.ino;
77
+ }
78
+ catch {
79
+ return false;
80
+ }
81
+ }
82
+ function snapshotFailure(workspace = false) {
83
+ return {
84
+ success: false,
85
+ error: {
86
+ code: workspace ? 'ERR_WORKSPACE_UNRESOLVED' : 'ERR_SPEC_DRIFT',
87
+ message: 'Scoped verification context does not match the trusted startup policy.',
88
+ trigger: 'sdd_complete_task',
89
+ details: {
90
+ reason: workspace
91
+ ? 'verification_policy_workspace_mismatch'
92
+ : 'verification_policy_mismatch',
93
+ },
94
+ },
95
+ };
96
+ }
97
+ class ScopedPathBindingError extends Error {
98
+ }
99
+ async function physicalIdentity(expected, directory) {
100
+ const binding = await Promise.all([fs.realpath(expected), fs.lstat(expected)]).catch(() => {
101
+ if (directory) {
102
+ throw new ScopedPathBindingError('Missing physical directory');
103
+ }
104
+ throw new Error('Missing artifact');
105
+ });
106
+ const [real, stat] = binding;
107
+ if (real !== expected ||
108
+ stat.isSymbolicLink() ||
109
+ (directory ? !stat.isDirectory() : !stat.isFile())) {
110
+ throw new ScopedPathBindingError('Invalid physical binding');
111
+ }
112
+ return Object.freeze({ path: expected, device: stat.dev, inode: stat.ino });
113
+ }
114
+ async function snapshotIdentities(policy) {
115
+ const sdd = path.join(policy.workspaceRoot, '.sdd');
116
+ const features = path.join(sdd, 'features');
117
+ const feature = path.join(features, policy.featureId);
118
+ const directories = [policy.workspaceRoot, sdd, features, feature];
119
+ const files = ['.lock', 'spec.md', 'plan.md', 'tasks.md'].map((name) => path.join(feature, name));
120
+ const directoryBindings = [];
121
+ for (const entry of directories) {
122
+ directoryBindings.push(await physicalIdentity(entry, true));
123
+ }
124
+ const fileBindings = await Promise.all(files.map((entry) => physicalIdentity(entry, false)));
125
+ return Object.freeze([...directoryBindings, ...fileBindings]);
126
+ }
127
+ function sameIdentities(before, after) {
128
+ return (before.length === after.length &&
129
+ before.every((entry, index) => {
130
+ const next = after[index];
131
+ return (entry.path === next?.path && entry.device === next.device && entry.inode === next.inode);
132
+ }));
133
+ }
134
+ async function readUtf8(file, signal) {
135
+ const bytes = await fs.readFile(file, { signal });
136
+ return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
137
+ }
138
+ export async function readScopedVerificationSnapshot(policy, tasksPath, workspaceRoot, requestedTaskId, selectTask) {
139
+ if (workspaceRoot !== policy.workspaceRoot) {
140
+ return snapshotFailure(true);
141
+ }
142
+ const featurePath = path.join(workspaceRoot, '.sdd', 'features', policy.featureId);
143
+ if (tasksPath !== path.join(featurePath, 'tasks.md')) {
144
+ return snapshotFailure(true);
145
+ }
146
+ try {
147
+ const identities = await snapshotIdentities(policy);
148
+ const [specContent, planContent, tasksContent, lockContent] = await Promise.all([
149
+ readUtf8(path.join(featurePath, 'spec.md')),
150
+ readUtf8(path.join(featurePath, 'plan.md')),
151
+ readUtf8(path.join(featurePath, 'tasks.md')),
152
+ readUtf8(path.join(featurePath, '.lock')),
153
+ ]);
154
+ const lockValue = JSON.parse(lockContent);
155
+ const lock = lockSchema.parse(lockValue);
156
+ if (verificationDigest(lockContent) !== policy.lockSha256 ||
157
+ verificationDigest(specContent) !== lock.specHash ||
158
+ verificationDigest(planContent) !== lock.planHash ||
159
+ verificationDigest(tasksContent) !== lock.tasksHash ||
160
+ !sameIdentities(identities, await snapshotIdentities(policy))) {
161
+ return snapshotFailure();
162
+ }
163
+ const selected = selectTask(tasksContent);
164
+ if (requestedTaskId.toUpperCase() !== policy.taskId ||
165
+ selected?.taskId.toUpperCase() !== requestedTaskId.toUpperCase()) {
166
+ return {
167
+ success: false,
168
+ error: {
169
+ code: 'ERR_TASK_OUT_OF_SEQUENCE',
170
+ message: 'The requested task is not the granted active task.',
171
+ trigger: 'sdd_complete_task',
172
+ },
173
+ };
174
+ }
175
+ if (selected.command === null) {
176
+ return {
177
+ success: false,
178
+ error: {
179
+ code: 'ERR_VERIFICATION_MISSING',
180
+ message: 'The granted active task requires one valid Verification command.',
181
+ trigger: 'sdd_complete_task',
182
+ },
183
+ };
184
+ }
185
+ if (verificationDigest(selected.command) !== policy.verificationCommandSha256) {
186
+ return snapshotFailure();
187
+ }
188
+ return {
189
+ success: true,
190
+ data: Object.freeze({
191
+ workspaceRoot,
192
+ featureId: policy.featureId,
193
+ taskId: policy.taskId,
194
+ tasksPath,
195
+ specContent,
196
+ planContent,
197
+ tasksContent,
198
+ lockContent,
199
+ command: selected.command,
200
+ timeoutMs: policy.timeoutMs,
201
+ identities,
202
+ }),
203
+ };
204
+ }
205
+ catch (error) {
206
+ return snapshotFailure(error instanceof ScopedPathBindingError);
207
+ }
208
+ }
209
+ export async function revalidateScopedVerificationSnapshot(policy, snapshot, selectTask) {
210
+ const current = await readScopedVerificationSnapshot(policy, snapshot.tasksPath, snapshot.workspaceRoot, snapshot.taskId, selectTask);
211
+ if (!current.success) {
212
+ return current;
213
+ }
214
+ if (!sameIdentities(snapshot.identities, current.data.identities)) {
215
+ return snapshotFailure(true);
216
+ }
217
+ if (current.data.specContent !== snapshot.specContent ||
218
+ current.data.planContent !== snapshot.planContent ||
219
+ current.data.tasksContent !== snapshot.tasksContent ||
220
+ current.data.lockContent !== snapshot.lockContent ||
221
+ current.data.command !== snapshot.command) {
222
+ return snapshotFailure();
223
+ }
224
+ return current;
225
+ }
226
+ export function uncertainCompletion() {
227
+ return {
228
+ success: false,
229
+ error: {
230
+ code: 'ERR_VERIFICATION_FAILED',
231
+ message: 'Completion persistence is uncertain; operator reconciliation is required.',
232
+ trigger: 'sdd_complete_task',
233
+ details: { reason: 'verification_completion_io', completionState: 'uncertain' },
234
+ },
235
+ };
236
+ }
237
+ export async function persistScopedCompletionFiles(policy, snapshot, writtenTasks, signal) {
238
+ const feature = path.dirname(snapshot.tasksPath);
239
+ const lockPath = path.join(feature, '.lock');
240
+ const lockValue = JSON.parse(snapshot.lockContent);
241
+ const lock = z.record(z.string(), z.unknown()).parse(lockValue);
242
+ const writtenLock = JSON.stringify({ ...lock, tasksHash: verificationDigest(writtenTasks) }, null, 2);
243
+ const cancelled = cancelledVerification(signal);
244
+ if (cancelled) {
245
+ return cancelled;
246
+ }
247
+ const deadline = new AbortController();
248
+ const deadlineAt = performance.now() + 5000;
249
+ const timer = setTimeout(() => {
250
+ deadline.abort();
251
+ }, 5000);
252
+ const step = (operation) => boundedPersistenceStep(operation, deadline.signal);
253
+ try {
254
+ await step((io) => fs.writeFile(snapshot.tasksPath, writtenTasks, { encoding: 'utf8', signal: io }));
255
+ if ((await step((io) => readUtf8(lockPath, io))) !== snapshot.lockContent) {
256
+ return uncertainCompletion();
257
+ }
258
+ await step((io) => fs.writeFile(lockPath, writtenLock, { encoding: 'utf8', signal: io }));
259
+ const identities = await step(() => snapshotIdentities(policy));
260
+ const [tasks, rawLock, spec, plan] = await step((io) => Promise.all([
261
+ readUtf8(snapshot.tasksPath, io),
262
+ readUtf8(lockPath, io),
263
+ readUtf8(path.join(feature, 'spec.md'), io),
264
+ readUtf8(path.join(feature, 'plan.md'), io),
265
+ ]));
266
+ const finalIdentities = await step(() => snapshotIdentities(policy));
267
+ signal.throwIfAborted();
268
+ if (performance.now() >= deadlineAt) {
269
+ return uncertainCompletion();
270
+ }
271
+ if (!sameIdentities(snapshot.identities, identities) ||
272
+ !sameIdentities(identities, finalIdentities) ||
273
+ tasks !== writtenTasks ||
274
+ rawLock !== writtenLock ||
275
+ spec !== snapshot.specContent ||
276
+ plan !== snapshot.planContent) {
277
+ return uncertainCompletion();
278
+ }
279
+ return { success: true, data: null };
280
+ }
281
+ catch {
282
+ return uncertainCompletion();
283
+ }
284
+ finally {
285
+ clearTimeout(timer);
286
+ }
287
+ }
288
+ async function boundedPersistenceStep(operation, signal) {
289
+ signal.throwIfAborted();
290
+ let rejectAbort;
291
+ const aborted = new Promise((_resolve, reject) => {
292
+ rejectAbort = () => {
293
+ reject(new Error('Completion I/O deadline exceeded'));
294
+ };
295
+ signal.addEventListener('abort', rejectAbort, { once: true });
296
+ });
297
+ try {
298
+ return await Promise.race([operation(signal), aborted]);
299
+ }
300
+ finally {
301
+ if (rejectAbort) {
302
+ signal.removeEventListener('abort', rejectAbort);
303
+ }
304
+ }
305
+ }
306
+ export async function scopedFeaturePathFailure(policy) {
307
+ try {
308
+ await snapshotIdentities(policy);
309
+ return null;
310
+ }
311
+ catch {
312
+ return snapshotFailure(true);
313
+ }
314
+ }
315
+ export function scopedVerificationEnvironment() {
316
+ const env = { ...process.env };
317
+ delete env.PLANU_VERIFICATION_TIMEOUT_POLICY;
318
+ return env;
319
+ }
320
+ export function scopedFailure(details) {
321
+ return {
322
+ success: false,
323
+ error: {
324
+ code: 'ERR_VERIFICATION_FAILED',
325
+ message: 'Scoped verification did not produce a safely committed certificate.',
326
+ trigger: 'sdd_complete_task',
327
+ details,
328
+ },
329
+ };
330
+ }
331
+ export function cancelledVerification(signal) {
332
+ if (!signal.aborted) {
333
+ return null;
334
+ }
335
+ return scopedFailure({ reason: 'verification_cancelled', cancelled: true, timedOut: false });
336
+ }
337
+ //# sourceMappingURL=verification-policy.js.map
@@ -0,0 +1,17 @@
1
+ import type { SddResult, CompleteTaskResult } from '../types/sdd-engine.js';
2
+ import type { ScopedVerificationRun, ScopedPolicy, ScopedVerificationCompletionContext, ScopedVerificationRunnerOptions, ScopedVerificationRunnerTiming } from '../types/verification.js';
3
+ export declare function runScopedVerification(options: ScopedVerificationRunnerOptions, timing?: ScopedVerificationRunnerTiming): Promise<ScopedVerificationRun>;
4
+ export declare class ScopedVerificationCoordinator {
5
+ private readonly policy;
6
+ private running;
7
+ private consumed;
8
+ private quarantined;
9
+ private readonly shutdownController;
10
+ private pending;
11
+ constructor(policy: ScopedPolicy);
12
+ shutdown(): Promise<void>;
13
+ complete(context: ScopedVerificationCompletionContext): Promise<SddResult<CompleteTaskResult> | null>;
14
+ private stateFailure;
15
+ private execute;
16
+ }
17
+ //# sourceMappingURL=verification-runner.d.ts.map
@@ -0,0 +1,347 @@
1
+ import * as path from 'node:path';
2
+ import { isScopedVerificationFeature, scopedFeaturePathFailure, scopedVerificationEnvironment, scopedFailure, cancelledVerification, uncertainCompletion, readScopedVerificationSnapshot, revalidateScopedVerificationSnapshot, } from './verification-policy.js';
3
+ import { spawn } from 'node:child_process';
4
+ function groupState(pid) {
5
+ if (pid === undefined) {
6
+ return 'absent';
7
+ }
8
+ try {
9
+ process.kill(-pid, 0);
10
+ return 'present';
11
+ }
12
+ catch (error) {
13
+ return error instanceof Error && 'code' in error && error.code === 'ESRCH'
14
+ ? 'absent'
15
+ : 'unknown';
16
+ }
17
+ }
18
+ class ScopedVerificationExecution {
19
+ options;
20
+ resolve;
21
+ child;
22
+ output = '';
23
+ exitCode = null;
24
+ exitSignal = null;
25
+ timedOut = false;
26
+ cancelled = false;
27
+ closed = false;
28
+ exited = false;
29
+ spawnFailed = false;
30
+ residual = false;
31
+ settled = false;
32
+ cleaning = false;
33
+ killed = false;
34
+ cleanupStartedAt = 0;
35
+ deadlineAt = Infinity;
36
+ deadlineTimer;
37
+ pollTimer;
38
+ terminationGraceMs;
39
+ closureGraceMs;
40
+ pollIntervalMs;
41
+ constructor(options, timing, resolve) {
42
+ this.options = options;
43
+ this.resolve = resolve;
44
+ this.terminationGraceMs = Math.min(Math.max(timing.terminationGraceMs ?? 3000, 0), 3000);
45
+ this.closureGraceMs = Math.min(Math.max(timing.closureGraceMs ?? 2000, 0), 2000);
46
+ this.pollIntervalMs = Math.min(Math.max(timing.pollIntervalMs ?? 25, 1), 100);
47
+ }
48
+ start() {
49
+ if (this.options.signal?.aborted) {
50
+ this.cancelled = true;
51
+ this.closed = true;
52
+ this.finish(true);
53
+ return;
54
+ }
55
+ const env = scopedVerificationEnvironment();
56
+ try {
57
+ this.deadlineAt = performance.now() + this.options.timeoutMs;
58
+ this.child = spawn(this.options.command, {
59
+ cwd: this.options.cwd,
60
+ shell: true,
61
+ detached: true,
62
+ windowsHide: true,
63
+ env,
64
+ });
65
+ this.child.stdout.on('data', this.append);
66
+ this.child.stderr.on('data', this.append);
67
+ this.child.on('error', this.onError);
68
+ this.child.on('exit', this.onExit);
69
+ this.child.on('close', this.onClose);
70
+ this.options.signal?.addEventListener('abort', this.onAbort, { once: true });
71
+ this.deadlineTimer = setTimeout(this.onDeadline, Math.max(0, this.deadlineAt - performance.now()));
72
+ if (this.options.signal?.aborted) {
73
+ this.onAbort();
74
+ }
75
+ }
76
+ catch {
77
+ this.spawnFailed = true;
78
+ this.closed = true;
79
+ this.finish(groupState(this.child?.pid) === 'absent');
80
+ }
81
+ }
82
+ append = (chunk) => {
83
+ this.output = (this.output + chunk.toString('utf8')).slice(-100000);
84
+ };
85
+ onError = () => {
86
+ this.spawnFailed = true;
87
+ this.startCleanup();
88
+ };
89
+ onExit = (code, signal) => {
90
+ this.exited = true;
91
+ this.exitCode = code;
92
+ this.exitSignal = signal;
93
+ if (groupState(this.child?.pid) !== 'absent') {
94
+ if (!this.cleaning) {
95
+ this.residual = true;
96
+ }
97
+ this.startCleanup();
98
+ }
99
+ else if (this.closed) {
100
+ this.finish(true);
101
+ }
102
+ else {
103
+ this.startCleanup();
104
+ }
105
+ };
106
+ onClose = (code, signal) => {
107
+ this.closed = true;
108
+ this.exitCode = code;
109
+ this.exitSignal = signal;
110
+ if (groupState(this.child?.pid) === 'absent') {
111
+ this.finish(true);
112
+ }
113
+ else {
114
+ if (!this.cleaning) {
115
+ this.residual = true;
116
+ }
117
+ this.startCleanup();
118
+ }
119
+ };
120
+ onDeadline = () => {
121
+ this.timedOut = true;
122
+ this.startCleanup();
123
+ };
124
+ onAbort = () => {
125
+ this.cancelled = true;
126
+ this.startCleanup();
127
+ };
128
+ signalGroup(signal) {
129
+ const pid = this.child?.pid;
130
+ if (pid === undefined) {
131
+ return;
132
+ }
133
+ try {
134
+ process.kill(-pid, signal);
135
+ }
136
+ catch {
137
+ // The following group probe determines whether cleanup was actually observed.
138
+ }
139
+ }
140
+ startCleanup() {
141
+ if (this.settled || this.cleaning) {
142
+ return;
143
+ }
144
+ this.cleaning = true;
145
+ this.cleanupStartedAt = performance.now();
146
+ this.signalGroup('SIGTERM');
147
+ this.pollCleanup();
148
+ }
149
+ pollCleanup = () => {
150
+ if (this.settled) {
151
+ return;
152
+ }
153
+ const state = groupState(this.child?.pid);
154
+ if (state === 'absent' && this.closed) {
155
+ this.finish(true);
156
+ return;
157
+ }
158
+ const elapsed = performance.now() - this.cleanupStartedAt;
159
+ if (!this.killed && elapsed >= this.terminationGraceMs) {
160
+ this.killed = true;
161
+ this.signalGroup('SIGKILL');
162
+ }
163
+ if (elapsed >= this.terminationGraceMs + this.closureGraceMs) {
164
+ this.finish(state === 'absent' && this.closed);
165
+ return;
166
+ }
167
+ const nextBoundary = this.killed
168
+ ? this.terminationGraceMs + this.closureGraceMs
169
+ : this.terminationGraceMs;
170
+ this.pollTimer = setTimeout(this.pollCleanup, Math.min(this.pollIntervalMs, Math.max(0, nextBoundary - elapsed)));
171
+ };
172
+ finish(cleanupComplete) {
173
+ if (this.settled) {
174
+ return;
175
+ }
176
+ this.settled = true;
177
+ if (performance.now() >= this.deadlineAt) {
178
+ this.timedOut = true;
179
+ }
180
+ clearTimeout(this.deadlineTimer);
181
+ clearTimeout(this.pollTimer);
182
+ this.options.signal?.removeEventListener('abort', this.onAbort);
183
+ this.child?.stdout.removeListener('data', this.append);
184
+ this.child?.stderr.removeListener('data', this.append);
185
+ this.child?.removeListener('error', this.onError);
186
+ this.child?.removeListener('exit', this.onExit);
187
+ this.child?.removeListener('close', this.onClose);
188
+ this.resolve({
189
+ ok: this.exited &&
190
+ this.exitCode === 0 &&
191
+ !this.timedOut &&
192
+ !this.cancelled &&
193
+ !this.spawnFailed &&
194
+ !this.residual &&
195
+ cleanupComplete,
196
+ exitCode: this.exitCode,
197
+ signal: this.exitSignal,
198
+ output: this.output,
199
+ timedOut: this.timedOut,
200
+ cancelled: this.cancelled,
201
+ timeoutMs: this.options.timeoutMs,
202
+ cleanupComplete,
203
+ });
204
+ }
205
+ }
206
+ export function runScopedVerification(options, timing = {}) {
207
+ if (!['darwin', 'linux'].includes(process.platform) ||
208
+ !Number.isInteger(options.timeoutMs) ||
209
+ options.timeoutMs <= 0 ||
210
+ options.timeoutMs > 600000) {
211
+ return Promise.resolve({
212
+ ok: false,
213
+ exitCode: null,
214
+ signal: null,
215
+ output: '',
216
+ timedOut: false,
217
+ cancelled: false,
218
+ timeoutMs: options.timeoutMs,
219
+ cleanupComplete: true,
220
+ });
221
+ }
222
+ return new Promise((resolve) => {
223
+ new ScopedVerificationExecution(options, timing, resolve).start();
224
+ });
225
+ }
226
+ export class ScopedVerificationCoordinator {
227
+ policy;
228
+ running = false;
229
+ consumed = false;
230
+ quarantined = false;
231
+ shutdownController = new AbortController();
232
+ pending;
233
+ constructor(policy) {
234
+ this.policy = policy;
235
+ }
236
+ async shutdown() {
237
+ this.shutdownController.abort();
238
+ await this.pending?.catch(() => undefined);
239
+ }
240
+ async complete(context) {
241
+ if (!(await isScopedVerificationFeature(this.policy, path.dirname(context.tasksPath)))) {
242
+ return null;
243
+ }
244
+ const stateError = this.stateFailure(context.taskId);
245
+ if (stateError) {
246
+ return stateError;
247
+ }
248
+ const grantedTasksPath = path.join(this.policy.workspaceRoot, '.sdd', 'features', this.policy.featureId, 'tasks.md');
249
+ if (context.tasksPath !== grantedTasksPath) {
250
+ return {
251
+ success: false,
252
+ error: {
253
+ code: 'ERR_WORKSPACE_UNRESOLVED',
254
+ message: 'Scoped verification path is not canonical.',
255
+ trigger: 'sdd_complete_task',
256
+ details: { reason: 'verification_policy_workspace_mismatch' },
257
+ },
258
+ };
259
+ }
260
+ if (context.taskId.toUpperCase() !== this.policy.taskId) {
261
+ const pathError = await scopedFeaturePathFailure(this.policy);
262
+ return this.stateFailure(context.taskId) ?? pathError;
263
+ }
264
+ this.running = true;
265
+ this.pending = this.execute(context);
266
+ try {
267
+ return await this.pending;
268
+ }
269
+ catch {
270
+ this.quarantined = this.consumed;
271
+ return scopedFailure({ reason: 'verification_runner_error' });
272
+ }
273
+ finally {
274
+ this.running = false;
275
+ this.pending = undefined;
276
+ }
277
+ }
278
+ stateFailure(taskId) {
279
+ if (this.quarantined) {
280
+ return scopedFailure({ reason: 'verification_grant_quarantined' });
281
+ }
282
+ if (this.running) {
283
+ return scopedFailure({ reason: 'verification_in_progress' });
284
+ }
285
+ if (this.consumed && taskId.toUpperCase() === this.policy.taskId) {
286
+ return scopedFailure({ reason: 'verification_grant_consumed' });
287
+ }
288
+ return null;
289
+ }
290
+ async execute(context) {
291
+ const snapshot = await readScopedVerificationSnapshot(this.policy, context.tasksPath, context.workspaceRoot, context.taskId, context.selectTask);
292
+ if (!snapshot.success) {
293
+ return snapshot;
294
+ }
295
+ const before = await revalidateScopedVerificationSnapshot(this.policy, snapshot.data, context.selectTask);
296
+ if (!before.success) {
297
+ return before;
298
+ }
299
+ const signal = AbortSignal.any([
300
+ this.shutdownController.signal,
301
+ ...(context.signal ? [context.signal] : []),
302
+ ]);
303
+ const cancelled = cancelledVerification(signal);
304
+ if (cancelled) {
305
+ return cancelled;
306
+ }
307
+ this.consumed = true;
308
+ const run = await runScopedVerification({
309
+ cwd: snapshot.data.workspaceRoot,
310
+ command: snapshot.data.command,
311
+ timeoutMs: snapshot.data.timeoutMs,
312
+ signal,
313
+ });
314
+ if (!run.cleanupComplete) {
315
+ this.quarantined = true;
316
+ }
317
+ if (!run.ok) {
318
+ return scopedFailure({
319
+ reason: 'verification_process_failed',
320
+ exitCode: run.exitCode,
321
+ signal: run.signal,
322
+ timedOut: run.timedOut,
323
+ cancelled: run.cancelled,
324
+ timeoutMs: run.timeoutMs,
325
+ cleanupComplete: run.cleanupComplete,
326
+ });
327
+ }
328
+ const after = await revalidateScopedVerificationSnapshot(this.policy, snapshot.data, context.selectTask);
329
+ if (!after.success) {
330
+ return after;
331
+ }
332
+ const cancelledAfter = cancelledVerification(signal);
333
+ if (cancelledAfter) {
334
+ return cancelledAfter;
335
+ }
336
+ const committed = await context.commit(snapshot.data, run.output, signal);
337
+ if (committed.success && signal.aborted) {
338
+ this.quarantined = true;
339
+ return uncertainCompletion();
340
+ }
341
+ if (!committed.success && committed.error.details?.completionState === 'uncertain') {
342
+ this.quarantined = true;
343
+ }
344
+ return committed;
345
+ }
346
+ }
347
+ //# sourceMappingURL=verification-runner.js.map
@@ -0,0 +1,83 @@
1
+ import type { SddResult, CompleteTaskResult } from './sdd-engine.js';
2
+ export type VerificationPolicyInput = Readonly<{
3
+ version: 1;
4
+ mode: 'disabled';
5
+ }> | Readonly<{
6
+ version: 1;
7
+ mode: 'scoped';
8
+ workspaceRoot: string;
9
+ featureId: string;
10
+ taskId: string;
11
+ timeoutMs: number;
12
+ lockSha256: string;
13
+ verificationCommandSha256: string;
14
+ }>;
15
+ export type VerificationPolicy = Readonly<{
16
+ mode: 'default';
17
+ timeoutMs: 180000;
18
+ }> | Exclude<VerificationPolicyInput, Readonly<{
19
+ version: 1;
20
+ mode: 'disabled';
21
+ }>>;
22
+ export interface VerificationServerOptions {
23
+ readonly verificationPolicy?: VerificationPolicyInput;
24
+ }
25
+ export interface ScopedPathIdentity {
26
+ readonly path: string;
27
+ readonly device: number;
28
+ readonly inode: number;
29
+ }
30
+ export interface ScopedVerificationSnapshot {
31
+ readonly workspaceRoot: string;
32
+ readonly featureId: string;
33
+ readonly taskId: string;
34
+ readonly tasksPath: string;
35
+ readonly specContent: string;
36
+ readonly planContent: string;
37
+ readonly tasksContent: string;
38
+ readonly lockContent: string;
39
+ readonly command: string;
40
+ readonly timeoutMs: number;
41
+ readonly identities: readonly ScopedPathIdentity[];
42
+ }
43
+ export interface ScopedTaskSelection {
44
+ readonly taskId: string;
45
+ readonly command: string | null;
46
+ }
47
+ export type ScopedTaskSelector = (content: string) => ScopedTaskSelection | null;
48
+ export type ScopedPolicy = Extract<VerificationPolicy, {
49
+ mode: 'scoped';
50
+ }>;
51
+ export type ScopedSnapshotResult = SddResult<ScopedVerificationSnapshot>;
52
+ export interface ScopedVerificationRun {
53
+ readonly ok: boolean;
54
+ readonly exitCode: number | null;
55
+ readonly signal: NodeJS.Signals | null;
56
+ readonly output: string;
57
+ readonly timedOut: boolean;
58
+ readonly cancelled: boolean;
59
+ readonly timeoutMs: number;
60
+ readonly cleanupComplete: boolean;
61
+ }
62
+ export interface ScopedVerificationRunnerOptions {
63
+ readonly cwd: string;
64
+ readonly command: string;
65
+ readonly timeoutMs: number;
66
+ readonly signal?: AbortSignal;
67
+ }
68
+ /** Internal test seam, never populated from MCP or startup policy. */
69
+ export interface ScopedVerificationRunnerTiming {
70
+ readonly terminationGraceMs?: number;
71
+ readonly closureGraceMs?: number;
72
+ readonly pollIntervalMs?: number;
73
+ }
74
+ export type VerificationGroupState = 'absent' | 'present' | 'unknown';
75
+ export interface ScopedVerificationCompletionContext {
76
+ readonly tasksPath: string;
77
+ readonly taskId: string;
78
+ readonly workspaceRoot: string;
79
+ readonly selectTask: ScopedTaskSelector;
80
+ readonly signal?: AbortSignal;
81
+ readonly commit: (snapshot: ScopedVerificationSnapshot, output: string, signal: AbortSignal) => Promise<SddResult<CompleteTaskResult>>;
82
+ }
83
+ //# sourceMappingURL=verification.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=verification.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planu/cli",
3
- "version": "8.2.13",
3
+ "version": "8.2.15",
4
4
  "description": "Planu — MCP Server for Spec Driven Development. Cross-platform (Linux/macOS/Windows, x64/arm64).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -41,12 +41,8 @@
41
41
  "access": "public"
42
42
  },
43
43
  "homepage": "https://planu.dev",
44
- "repository": {
45
- "type": "git",
46
- "url": "git+https://github.com/planu-dev/planu.git"
47
- },
48
44
  "bugs": {
49
- "url": "https://github.com/planu-dev/planu/issues"
45
+ "url": "https://planu.dev/report"
50
46
  },
51
47
  "funding": {
52
48
  "type": "individual",
@@ -75,33 +71,33 @@
75
71
  "zod": "^4.6.7"
76
72
  },
77
73
  "devDependencies": {
78
- "@commitlint/cli": "^21.2.3",
79
- "@commitlint/config-conventional": "^21.2.3",
74
+ "@commitlint/cli": "^21.2.4",
75
+ "@commitlint/config-conventional": "^21.2.4",
80
76
  "@eslint/js": "^10.0.1",
81
77
  "@secretlint/secretlint-rule-no-homedir": "^13.0.7",
82
78
  "@secretlint/secretlint-rule-preset-recommend": "^13.0.7",
83
79
  "@types/node": "^22.20.5",
84
80
  "@typescript/native": "npm:typescript@^7.0.2",
85
- "@vitest/coverage-v8": "^5.0.4",
86
- "eslint": "10.12.0",
81
+ "@vitest/coverage-v8": "^5.0.5",
82
+ "eslint": "10.13.0",
87
83
  "eslint-config-prettier": "^10.1.8",
88
84
  "eslint-import-resolver-typescript": "^4.4.5",
89
85
  "eslint-plugin-import": "^2.32.0",
90
- "happy-dom": "^21.0.1",
86
+ "happy-dom": "^21.0.4",
91
87
  "husky": "^9.1.7",
92
88
  "jiti": "2.7.0",
93
- "knip": "^6.41.0",
89
+ "knip": "^6.42.1",
94
90
  "lint-staged": "^17.6.0",
95
91
  "madge": "^8.0.0",
96
92
  "prettier": "^3.9.10",
97
93
  "qrcode": "1.5.4",
98
94
  "secretlint": "^13.0.7",
99
- "tsc-alias": "^1.9.7",
100
- "type-coverage": "^2.30.3",
95
+ "tsc-alias": "^1.9.8",
96
+ "type-coverage": "^2.30.4",
101
97
  "typescript": "npm:@typescript/typescript6@^6.0.2",
102
- "typescript-eslint": "^8.71.2",
98
+ "typescript-eslint": "^8.72.0",
103
99
  "vite": "^8.3.4",
104
- "vitest": "^5.0.4"
100
+ "vitest": "^5.0.5"
105
101
  },
106
102
  "scripts": {
107
103
  "check:tool-registration": "bash scripts/check-tool-registration.sh",
@@ -37,6 +37,9 @@ Canonical contract: `PLANU_V8_MANIFESTO.txt`.
37
37
  4. **Language Requirements:**
38
38
  - All generated SDD artifacts MUST be written entirely in Technical English.
39
39
 
40
+ 4a. **Trusted verification authority:**
41
+ - Agents must never grant themselves extra verification time or edit trusted launcher policy. Report budget failures for operator review; an approved startup grant does not change task or File Manifest authority.
42
+
40
43
  5. **Atomic Task Progression:**
41
44
  - Work strictly task-by-task via `sdd_get_active_task`. Verify with the task command before `sdd_complete_task`.
42
45
 
@@ -7,3 +7,4 @@ The only SDD contract is `.sdd/features/{FEAT-*}/spec.md`, `plan.md`, and `tasks
7
7
  - Never create, thin, or copy files under `planu/specs/`. Planu does not read that tree.
8
8
  - If a pre-push, commitlint, or husky guard still requires `planu/specs/SPEC-*/spec.md`, that guard is the defect. Delete or rewrite it. Do not stub a SPEC file.
9
9
  - Quality lives in `.claude/skills/`, `.cursor/skills/`, `.agents/skills/`, and `.gemini/skills/`. Specs stay in `.sdd/features`. There is no validate MCP tool.
10
+ - Agents must never grant themselves extra verification time or edit trusted launcher policy. Report budget failures for operator review; an approved startup grant does not change task or File Manifest authority.