@planu/cli 5.7.15 → 5.7.17

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,36 @@
1
+ ## [5.7.17] - 2026-09-04
2
+
3
+ ### Bug Fixes
4
+ - fix(handoff): degrade the handoff digest when a relative spec path has no project root (SPEC-1796)
5
+ - fix(validate): let a stage supply its own gate deadline so blast-radius keeps its budget (SPEC-1797)
6
+ - fix(handoff): resolve spec.specPath against project root before digesting
7
+ - fix(handoff): fold spec content into handoff job identity
8
+ - fix(release): give release pushes a hook-aware timeout budget (SPEC-1795)
9
+
10
+
11
+ ## [5.7.16] - 2026-09-04
12
+
13
+ ### Bug Fixes
14
+ - fix(audit): give the advisories endpoint enough time before giving up
15
+ - fix(audit-security): narrow the [23] transport signature to the timeout message
16
+ - fix(audit-security): retry once and classify registry timeouts as noise
17
+ - fix(release): fail closed on empty remote main and require smoke/promotion effects (SPEC-1788)
18
+ - fix(release): mirror origin/main in the shared roll-forward sync instead of local main
19
+ - fix(release): fail closed on registry visibility and dedupe mirror-sync roll-forward (SPEC-1788)
20
+ - fix(release): roll forward and close the ledger for an already-public release (SPEC-1788)
21
+ - fix(release-ledger): preserve a pending entry's implementation commit on cascade replay (SPEC-1790)
22
+ - fix(status-store): self-heal recordStatusChange counters against spec directory count (SPEC-1789)
23
+ - fix(planu): re-restore SPEC-1786 implementation commit reverted by the SPEC-1787 rebase
24
+ - fix(cascade-hooks): verify captured HEAD commit and auto-commit on shipped reconciliation (SPEC-1787)
25
+ - fix(cascade): skip pending-release append for already-released specs (SPEC-1787)
26
+ - fix(planu): restore SPEC-1786 implementation commit overwritten by a replayed cascade
27
+ - fix(release): classify npm advisories timeout as environment noise (SPEC-1786)
28
+
29
+ ### Refactoring
30
+ - refactor(status-store): drop the spec-id comment from recordStatusChange
31
+ - refactor(cascade): extract isAlreadyShipped to satisfy the function-length lint budget (SPEC-1787)
32
+
33
+
1
34
  ## [5.7.15] - 2026-09-03
2
35
 
3
36
  ### Bug Fixes
@@ -1 +1 @@
1
- {"schemaVersion":1,"commit":"c98d593f0b05bdf5da7ae4ff737b7757c0a76b6c"}
1
+ {"schemaVersion":1,"commit":"eaee88d4fafb9a457c4a32ace39b3666e4b30108"}
@@ -2,7 +2,7 @@
2
2
  // engine/autopilot/state-updater.ts — SPEC-459: Auto-update external project status on every status change
3
3
  // Fire-and-forget: never blocks the event pipeline, never throws to callers.
4
4
  // SPEC-753: File-lock applied to all writes; self-healing on corrupt reads.
5
- import { readFile } from 'node:fs/promises';
5
+ import { readFile, readdir } from 'node:fs/promises';
6
6
  import { join } from 'node:path';
7
7
  // eslint-disable-next-line no-restricted-imports -- grandfathered layer violation, remediation SPEC-1661 SPEC-1662 SPEC-1663
8
8
  import { withStatusLock } from '../../storage/status-store/file-lock.js';
@@ -60,6 +60,54 @@ async function saveStatus(projectPath, status) {
60
60
  const filePath = getStatusPath(projectPath);
61
61
  await atomicStatusWrite(filePath, status);
62
62
  }
63
+ const SPEC_DIR_PREFIX = 'SPEC-';
64
+ async function countSpecDirectories(projectPath) {
65
+ const specsDir = join(projectPath, 'planu', 'specs');
66
+ try {
67
+ const entries = await readdir(specsDir, { withFileTypes: true });
68
+ return entries.filter((entry) => entry.isDirectory() && entry.name.startsWith(SPEC_DIR_PREFIX))
69
+ .length;
70
+ }
71
+ catch {
72
+ return undefined;
73
+ }
74
+ }
75
+ function countersAreConsistent(status, specDirCount) {
76
+ const bucketSum = Object.values(status.byStatus).reduce((a, b) => a + b, 0);
77
+ return (bucketSum === status.totalSpecs &&
78
+ (specDirCount === undefined || status.totalSpecs === specDirCount));
79
+ }
80
+ async function reconcileCounters(projectPath, incremental) {
81
+ const specDirCount = await countSpecDirectories(projectPath);
82
+ if (countersAreConsistent(incremental, specDirCount)) {
83
+ return incremental;
84
+ }
85
+ try {
86
+ const rebuilt = await rebuildStatusFromFrontmatters({ projectPath });
87
+ return {
88
+ ...incremental,
89
+ totalSpecs: rebuilt.totalSpecs,
90
+ byStatus: rebuilt.byStatus,
91
+ byType: rebuilt.byType,
92
+ version: rebuilt.version,
93
+ };
94
+ }
95
+ catch {
96
+ return incremental;
97
+ }
98
+ }
99
+ function applyIncrementalTransition(status, specId, fromStatus, toStatus) {
100
+ const byStatus = { ...status.byStatus };
101
+ if (fromStatus && byStatus[fromStatus] !== undefined) {
102
+ byStatus[fromStatus] = Math.max(0, (byStatus[fromStatus] ?? 0) - 1);
103
+ }
104
+ byStatus[toStatus] = (byStatus[toStatus] ?? 0) + 1;
105
+ const recentChanges = [
106
+ { specId, from: fromStatus, to: toStatus, at: new Date().toISOString() },
107
+ ...status.recentChanges,
108
+ ].slice(0, MAX_RECENT_CHANGES);
109
+ return { ...status, byStatus, recentChanges };
110
+ }
63
111
  /**
64
112
  * Record a spec status change and recalculate counts.
65
113
  * Called fire-and-forget from the autopilot event bus.
@@ -69,24 +117,10 @@ export async function recordStatusChange(projectPath, _projectId, specId, fromSt
69
117
  const filePath = getStatusPath(projectPath);
70
118
  try {
71
119
  await withStatusLock(filePath, async () => {
72
- const status = await loadStatus(projectPath);
73
- // Update byStatus counts
74
- if (fromStatus && status.byStatus[fromStatus] !== undefined) {
75
- status.byStatus[fromStatus] = Math.max(0, (status.byStatus[fromStatus] ?? 0) - 1);
76
- }
77
- status.byStatus[toStatus] = (status.byStatus[toStatus] ?? 0) + 1;
78
- // Add to recent changes
79
- status.recentChanges.unshift({
80
- specId,
81
- from: fromStatus,
82
- to: toStatus,
83
- at: new Date().toISOString(),
84
- });
85
- if (status.recentChanges.length > MAX_RECENT_CHANGES) {
86
- status.recentChanges = status.recentChanges.slice(0, MAX_RECENT_CHANGES);
87
- }
88
- status.updatedAt = new Date().toISOString();
89
- await saveStatus(projectPath, status);
120
+ const loaded = await loadStatus(projectPath);
121
+ const incremental = applyIncrementalTransition(loaded, specId, fromStatus, toStatus);
122
+ const reconciled = await reconcileCounters(projectPath, incremental);
123
+ await saveStatus(projectPath, { ...reconciled, updatedAt: new Date().toISOString() });
90
124
  });
91
125
  }
92
126
  catch {
@@ -68,6 +68,11 @@ export function reconcilePublishedPendingEntries(entries, release, isCommitReach
68
68
  }
69
69
  });
70
70
  }
71
+ function scheduleAutoCommit(projectPath) {
72
+ void import('../../git/planu-autocommit.js')
73
+ .then(({ planuAutoCommit }) => planuAutoCommit({ projectPath, reason: 'status-update' }))
74
+ .catch(() => undefined);
75
+ }
71
76
  async function captureHeadCommit(projectPath) {
72
77
  try {
73
78
  const { stdout } = await execFile('git', ['rev-parse', 'HEAD'], {
@@ -89,7 +94,7 @@ function extractReleasesField(parsedProject) {
89
94
  ? parsedProject.releases
90
95
  : undefined;
91
96
  }
92
- async function rewritePendingLedger(input) {
97
+ async function loadReconciledPendingList(input) {
93
98
  let pendingList = [];
94
99
  try {
95
100
  const raw = await readFile(input.projectJsonPath, 'utf-8');
@@ -101,7 +106,20 @@ async function rewritePendingLedger(input) {
101
106
  throw error instanceof Error ? error : new Error(String(error));
102
107
  }
103
108
  }
104
- pendingList = reconcilePublishedPendingEntries(pendingList, input.releaseInfo, input.isCommitReachable).filter((entry) => entry.specId !== input.specId);
109
+ return reconcilePublishedPendingEntries(pendingList, input.releaseInfo, input.isCommitReachable);
110
+ }
111
+ async function reconcileAndDropPendingLedgerEntry(input) {
112
+ const pendingList = (await loadReconciledPendingList(input)).filter((entry) => entry.specId !== input.specId);
113
+ await input.writePendingReleaseLedger(input.projectJsonPath, pendingList);
114
+ }
115
+ async function rewritePendingLedger(input) {
116
+ const reconciledList = await loadReconciledPendingList(input);
117
+ const existingEntry = reconciledList.find((entry) => entry.specId === input.specId);
118
+ if (existingEntry?.implementationCommit) {
119
+ await input.writePendingReleaseLedger(input.projectJsonPath, reconciledList);
120
+ return;
121
+ }
122
+ const pendingList = reconciledList.filter((entry) => entry.specId !== input.specId);
105
123
  pendingList.push({
106
124
  specId: input.specId,
107
125
  title: input.title,
@@ -110,6 +128,25 @@ async function rewritePendingLedger(input) {
110
128
  });
111
129
  await input.writePendingReleaseLedger(input.projectJsonPath, pendingList);
112
130
  }
131
+ function resolveDoneTransitionAt(spec) {
132
+ const history = spec?.statusHistory;
133
+ if (!history) {
134
+ return undefined;
135
+ }
136
+ for (let index = history.length - 1; index >= 0; index -= 1) {
137
+ const entry = history[index];
138
+ if (entry?.status === 'done') {
139
+ return Date.parse(entry.changedAt);
140
+ }
141
+ }
142
+ return undefined;
143
+ }
144
+ function isAlreadyShipped(spec, releaseInfo) {
145
+ const doneTransitionAt = resolveDoneTransitionAt(spec);
146
+ return (releaseInfo?.committedAt !== undefined &&
147
+ doneTransitionAt !== undefined &&
148
+ doneTransitionAt <= Date.parse(releaseInfo.committedAt));
149
+ }
113
150
  async function actuallyAppendReleasesPending(ctx, opts) {
114
151
  const { projectPath, projectId, specId } = ctx;
115
152
  if (!projectPath || ctx.newStatus !== 'done') {
@@ -137,6 +174,17 @@ async function actuallyAppendReleasesPending(ctx, opts) {
137
174
  await mkdir(planuDir, { recursive: true });
138
175
  const spec = await specStore.getSpec(projectId, specId);
139
176
  const releaseInfo = await resolveLatestReleaseTag(projectPath);
177
+ if (isAlreadyShipped(spec, releaseInfo)) {
178
+ await withPendingReleaseLock(projectJsonPath, { timeoutMs: 1_500, signal: opts.signal }, () => reconcileAndDropPendingLedgerEntry({
179
+ projectJsonPath,
180
+ specId,
181
+ releaseInfo,
182
+ isCommitReachable,
183
+ writePendingReleaseLedger,
184
+ }));
185
+ scheduleAutoCommit(projectPath);
186
+ return;
187
+ }
140
188
  const implementationCommit = await captureHeadCommit(projectPath);
141
189
  await withPendingReleaseLock(projectJsonPath, { timeoutMs: 1_500, signal: opts.signal }, () => rewritePendingLedger({
142
190
  projectJsonPath,
@@ -147,15 +195,7 @@ async function actuallyAppendReleasesPending(ctx, opts) {
147
195
  isCommitReachable,
148
196
  writePendingReleaseLedger,
149
197
  }));
150
- void (async () => {
151
- try {
152
- const { planuAutoCommit } = await import('../../git/planu-autocommit.js');
153
- await planuAutoCommit({ projectPath, reason: 'status-update' });
154
- }
155
- catch {
156
- /* best-effort */
157
- }
158
- })();
198
+ scheduleAutoCommit(projectPath);
159
199
  })()
160
200
  .then(() => {
161
201
  resolve();
@@ -52,7 +52,9 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
52
52
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
53
53
  });
54
54
  import { createHash } from 'node:crypto';
55
- import { specStore } from '../storage/index.js';
55
+ import { readFile } from 'node:fs/promises';
56
+ import { isAbsolute, resolve as resolvePath } from 'node:path';
57
+ import { specStore, knowledgeStore } from '../storage/index.js';
56
58
  import { DurableJobRuntime, DurableJobNotFoundError, publicJobCursor, } from '../engine/execution/job-runtime.js';
57
59
  import { schedulePackageHandoffJobExecution } from '../engine/execution/package-handoff-job-executor.js';
58
60
  import { acquireLock, releaseLock } from '../engine/safety/cross-process-lock.js';
@@ -61,10 +63,33 @@ export { formatHandoff } from '../engine/handoff-format.js';
61
63
  const SUBMISSION_LOCK_WAIT_MS = 5_000;
62
64
  const SUBMISSION_LOCK_POLL_MS = 100;
63
65
  const TERMINAL_RECOVERABLE_STATES = new Set(['failed', 'cancelled', 'dead-letter']);
64
- function deriveOperationId(projectId, specId, specVersion) {
65
- const digest = createHash('sha256').update(`${projectId}|${specId}|${specVersion}`).digest('hex');
66
+ function deriveOperationId(projectId, specId, specVersion, specContentDigest) {
67
+ const digest = createHash('sha256')
68
+ .update(`${projectId}|${specId}|${specVersion}|${specContentDigest}`)
69
+ .digest('hex');
66
70
  return `handoff-${digest}`;
67
71
  }
72
+ async function resolveProjectRoot(projectId, projectPath) {
73
+ if (projectPath) {
74
+ return projectPath;
75
+ }
76
+ const knowledge = await knowledgeStore.getKnowledge(projectId);
77
+ return knowledge?.projectPath;
78
+ }
79
+ async function digestSpecFile(projectId, projectPath, specPath) {
80
+ if (!specPath) {
81
+ return '';
82
+ }
83
+ if (isAbsolute(specPath)) {
84
+ return readFile(specPath).then((bytes) => createHash('sha256').update(bytes).digest('hex'), () => '');
85
+ }
86
+ const projectRoot = await resolveProjectRoot(projectId, projectPath);
87
+ if (!projectRoot) {
88
+ return '';
89
+ }
90
+ const absoluteSpecPath = resolvePath(projectRoot, specPath);
91
+ return readFile(absoluteSpecPath).then((bytes) => createHash('sha256').update(bytes).digest('hex'), () => '');
92
+ }
68
93
  async function acquireSubmissionLock(projectId, operationId) {
69
94
  const deadlineAt = Date.now() + SUBMISSION_LOCK_WAIT_MS;
70
95
  while (Date.now() < deadlineAt) {
@@ -99,7 +124,8 @@ export async function handlePackageHandoff(args) {
99
124
  };
100
125
  }
101
126
  const specVersion = spec.spec_version ?? '0.0.0';
102
- const operationId = deriveOperationId(projectId, specId, specVersion);
127
+ const specContentDigest = await digestSpecFile(projectId, args.projectPath, spec.specPath);
128
+ const operationId = deriveOperationId(projectId, specId, specVersion, specContentDigest);
103
129
  const submissionLock = await acquireSubmissionLock(projectId, operationId);
104
130
  try {
105
131
  const env_1 = { stack: [], error: void 0, hasError: false };
@@ -4,7 +4,7 @@ import type { ValidateInput, ToolResult, ContractSpec, ContractValidation } from
4
4
  import type { ValidateWorkerProgress } from '../types/validate-worker.js';
5
5
  export { validateContractCompliance };
6
6
  export type { ContractSpec, ContractValidation };
7
- export declare function createValidationStageRunner(onProgress?: (progress: ValidateWorkerProgress) => void): <T>(phase: string, command: string, work: () => T | Promise<T>) => Promise<T>;
7
+ export declare function createValidationStageRunner(onProgress?: (progress: ValidateWorkerProgress) => void): <T>(phase: string, command: string, work: () => T | Promise<T>, deadlineMs?: number) => Promise<T>;
8
8
  /** Public MCP boundary: persist and acknowledge validation work without running it inline. */
9
9
  export declare function handleValidate(args: ValidateInput): Promise<ToolResult>;
10
10
  export declare function executeValidate(args: ValidateInput, server?: McpServer, onProgress?: (progress: ValidateWorkerProgress) => void): Promise<ToolResult>;
@@ -90,16 +90,19 @@ import { createPendingValidationSubmission } from '../engine/validation/durable-
90
90
  import { PROJECT_ID as CANONICAL_PROJECT_ID } from '../engine/validation/validation-receipt-codec.js';
91
91
  import { acquireLock, releaseLock } from '../engine/safety/cross-process-lock.js';
92
92
  import { getRuntimePolicy } from '../engine/runtime-policy.js';
93
+ import { PROCESS_TERMINATION_GRACE_MS, PROCESS_TREE_EXTINCTION_TIMEOUT_MS, PROCESS_CHILD_CLOSE_TIMEOUT_MS, } from '../engine/abortable-process-runner.js';
93
94
  import { resolveValidationWorktree, ValidationWorktreeError, } from '../engine/validation/validation-worktree.js';
94
95
  // Re-export for external use (SPEC-018)
95
96
  export { validateContractCompliance };
96
97
  const VALIDATION_GATE_TOTAL = 11;
97
98
  const GATE_DEADLINE_EXEMPT_PHASES = new Set(['lint', 'compliance']);
98
- async function runWithGateDeadline(phase, command, work) {
99
+ const BLAST_RADIUS_TERMINATION_MARGIN_MS = PROCESS_TERMINATION_GRACE_MS +
100
+ PROCESS_TREE_EXTINCTION_TIMEOUT_MS +
101
+ PROCESS_CHILD_CLOSE_TIMEOUT_MS;
102
+ async function runWithGateDeadline(phase, command, work, deadlineMs = getRuntimePolicy().validation.perGateTimeoutMs) {
99
103
  if (GATE_DEADLINE_EXEMPT_PHASES.has(phase)) {
100
104
  return work();
101
105
  }
102
- const deadlineMs = getRuntimePolicy().validation.perGateTimeoutMs;
103
106
  let timer;
104
107
  const deadline = new Promise((_resolve, reject) => {
105
108
  timer = setTimeout(() => {
@@ -180,7 +183,7 @@ function strictAuditsSuggestions(strictAuditsGate) {
180
183
  export function createValidationStageRunner(onProgress) {
181
184
  const startedAt = Date.now();
182
185
  let completedGates = 0;
183
- return async (phase, command, work) => {
186
+ return async (phase, command, work, deadlineMs) => {
184
187
  const emit = (status) => {
185
188
  onProgress?.({
186
189
  phase,
@@ -194,7 +197,7 @@ export function createValidationStageRunner(onProgress) {
194
197
  };
195
198
  emit('running');
196
199
  try {
197
- const result = await runWithGateDeadline(phase, command, work);
200
+ const result = await runWithGateDeadline(phase, command, work, deadlineMs);
198
201
  completedGates += 1;
199
202
  emit('passed');
200
203
  return result;
@@ -440,6 +443,8 @@ export async function executeValidate(args, server, onProgress) {
440
443
  const auditedFiles = [...new Set(result.qualityIssues.map((i) => i.file))];
441
444
  const codeState = await scanCodeForSpec(executionSpec, projectPath);
442
445
  const reliabilityGate = await runStage('reliability', 'scripts/check-reliability-policies.mjs --json', () => runReliabilityGate(projectPath, codeState.affectedFiles));
446
+ const blastRadiusTimeoutMs = getRuntimePolicy().validation.blastRadiusTimeoutMs;
447
+ const integrationTimeoutMs = computeIntegrationTimeoutMs();
443
448
  const blastRadiusGate = await runStage('blast-radius', "vitest related over the spec's affected source files", async () => {
444
449
  const absoluteSpecPath = isAbsolute(executionSpec.specPath)
445
450
  ? executionSpec.specPath
@@ -449,11 +454,11 @@ export async function executeValidate(args, server, onProgress) {
449
454
  ...new Set([...collectDeclaredSpecFiles(raw), ...codeState.affectedFiles]),
450
455
  ];
451
456
  return runBlastRadiusGate(projectPath, candidateFiles, {
452
- timeoutMs: getRuntimePolicy().validation.blastRadiusTimeoutMs,
453
- integrationTimeoutMs: computeIntegrationTimeoutMs(),
457
+ timeoutMs: blastRadiusTimeoutMs,
458
+ integrationTimeoutMs,
454
459
  signal: getToolExecutionSignal(),
455
460
  });
456
- });
461
+ }, blastRadiusTimeoutMs + integrationTimeoutMs + BLAST_RADIUS_TERMINATION_MARGIN_MS);
457
462
  const { conventionViolations, regressionDetected } = await runStage('conventions', 'validate project conventions', () => scanProjectConventions(projectId, projectPath));
458
463
  const lintCheck = await runStage('lint', knowledge.lintCommand ?? 'pnpm lint', () => runLintCheck(projectPath, knowledge.lintCommand ?? null, {
459
464
  projectId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planu/cli",
3
- "version": "5.7.15",
3
+ "version": "5.7.17",
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",
package/planu-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dev.planu.cli",
3
3
  "displayName": "Planu — Spec Driven Development",
4
4
  "description": "Manage software specs, estimations, and autonomous SDD workflows. Language-agnostic MCP server for Claude Code.",
5
- "version": "5.7.15",
5
+ "version": "5.7.17",
6
6
  "icon": "assets/plugin/icon.svg",
7
7
  "command": ["npx", "@planu/cli@latest"],
8
8
  "packageName": "@planu/cli",
@@ -96,7 +96,16 @@ export async function resolveLatestReleaseTag(repoRoot) {
96
96
  maxBuffer: 16 * 1024,
97
97
  });
98
98
  const commit = stdout.trim();
99
- return commit ? { tag, commit, repoRoot } : null;
99
+ if (!commit) {
100
+ return null;
101
+ }
102
+ const { stdout: committedAtOutput } = await execFile(
103
+ 'git',
104
+ ['log', '-1', '--format=%cI', commit],
105
+ { cwd: repoRoot, timeout: 1_000, maxBuffer: 16 * 1024 },
106
+ );
107
+ const committedAt = committedAtOutput.trim();
108
+ return committedAt ? { tag, commit, repoRoot, committedAt } : null;
100
109
  } catch {
101
110
  return null;
102
111
  }