@planu/cli 5.7.7 → 5.7.8
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 +18 -0
- package/dist/.planu-build.json +1 -1
- package/dist/engine/execution/job-runtime.d.ts +7 -3
- package/dist/engine/execution/job-runtime.js +18 -6
- package/dist/engine/execution/validate-job-executor.d.ts +2 -0
- package/dist/engine/execution/validate-job-executor.js +25 -0
- package/dist/storage/runtime-db.d.ts +4 -2
- package/dist/storage/runtime-db.js +50 -12
- package/dist/storage/spec-store.d.ts +2 -1
- package/dist/storage/spec-store.js +21 -3
- package/dist/tools/create-spec.js +4 -1
- package/dist/tools/jobs/handlers.js +18 -11
- package/dist/tools/list-specs.js +33 -15
- package/dist/tools/schemas/output-schemas.d.ts +14 -0
- package/dist/tools/schemas/output-schemas.js +14 -0
- package/dist/tools/schemas/package-handoff-output-schema.d.ts +1 -0
- package/dist/tools/schemas/package-handoff-output-schema.js +3 -1
- package/dist/tools/schemas/validate-output-schema.d.ts +1 -0
- package/dist/tools/schemas/validate-output-schema.js +3 -1
- package/dist/tools/sync-spec-state-handler.js +92 -23
- package/dist/types/durable-job.d.ts +1 -0
- package/dist/types/spec/core.d.ts +4 -0
- package/package.json +3 -3
- package/planu-plugin.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [5.7.8] - 2026-09-02
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
- fix(create-spec): emit the double-dash joiner only for npm in verification commands
|
|
5
|
+
- fix(hooks): route unmirrored sources through the vitest related lane in the pre-push selector
|
|
6
|
+
- fix(deps): override qs to >=6.16.0 to clear moderate advisories
|
|
7
|
+
- fix(jobs): expose restarts in public job projections
|
|
8
|
+
- fix(sync-spec-state): quarantine only missing or empty specs and reject unresolvable terminal paths
|
|
9
|
+
- fix(jobs): recover expired validate leases, surface stalled queue status and cap restarts
|
|
10
|
+
- fix(spec-store): resolve specPath against project root for ghost detection
|
|
11
|
+
|
|
12
|
+
### Refactoring
|
|
13
|
+
- refactor(preflight): drop duplicated gates from check:preflight and cap coverage at 6 workers
|
|
14
|
+
|
|
15
|
+
### Chores
|
|
16
|
+
- chore(deps): raise the fast-uri override to the patched 4.1.3 range
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
## [5.7.7] - 2026-09-02
|
|
2
20
|
|
|
3
21
|
### Bug Fixes
|
package/dist/.planu-build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schemaVersion":1,"commit":"
|
|
1
|
+
{"schemaVersion":1,"commit":"bb0b76967c77e4a602407783d6fdfcee6f0be92d"}
|
|
@@ -19,7 +19,10 @@ export declare class DurableJobRuntime implements Disposable {
|
|
|
19
19
|
}): DurableJobRecord;
|
|
20
20
|
get(input: DurableJobIdentity): DurableJobRecord;
|
|
21
21
|
/** Return the allowlisted public projection for one job and its current queue scope. */
|
|
22
|
-
observe(input: DurableJobIdentity | DurableJobRecord
|
|
22
|
+
observe(input: DurableJobIdentity | DurableJobRecord, options?: {
|
|
23
|
+
readonly scopeActive?: boolean;
|
|
24
|
+
}): ReturnType<typeof publicJobObservation>;
|
|
25
|
+
recoverExpired(projectId: string, workspaceId: string): number;
|
|
23
26
|
list(projectId: string, workspaceId?: string): readonly DurableJobRecord[];
|
|
24
27
|
listRunnableScopes(): readonly {
|
|
25
28
|
projectId: string;
|
|
@@ -71,7 +74,7 @@ export declare class DurableJobRuntime implements Disposable {
|
|
|
71
74
|
/** Stable watcher cursor that detects state changes even within one clock millisecond. */
|
|
72
75
|
export declare function durableJobCursor(job: DurableJobRecord): string;
|
|
73
76
|
/** Build a privacy-safe job projection from existing durable records. */
|
|
74
|
-
export declare function publicJobObservation(job: DurableJobRecord, scopeJobs: readonly DurableJobRecord[], now?: number): {
|
|
77
|
+
export declare function publicJobObservation(job: DurableJobRecord, scopeJobs: readonly DurableJobRecord[], now?: number, scopeActive?: boolean): {
|
|
75
78
|
id: string;
|
|
76
79
|
projectId: string;
|
|
77
80
|
workspaceId: string;
|
|
@@ -81,11 +84,12 @@ export declare function publicJobObservation(job: DurableJobRecord, scopeJobs: r
|
|
|
81
84
|
error?: string;
|
|
82
85
|
attempts: number;
|
|
83
86
|
maxAttempts: number;
|
|
87
|
+
restarts: number;
|
|
84
88
|
cancelRequested: boolean;
|
|
85
89
|
createdAt: string;
|
|
86
90
|
updatedAt: string;
|
|
87
91
|
queue: {
|
|
88
|
-
status: 'active' | 'queued' | 'terminal';
|
|
92
|
+
status: 'active' | 'queued' | 'stalled' | 'terminal';
|
|
89
93
|
position: number | null;
|
|
90
94
|
aheadCount: number;
|
|
91
95
|
capacity: number;
|
|
@@ -47,9 +47,12 @@ export class DurableJobRuntime {
|
|
|
47
47
|
return this.requireJob(input);
|
|
48
48
|
}
|
|
49
49
|
/** Return the allowlisted public projection for one job and its current queue scope. */
|
|
50
|
-
observe(input) {
|
|
50
|
+
observe(input, options) {
|
|
51
51
|
const job = 'id' in input ? input : this.requireJob(input);
|
|
52
|
-
return publicJobObservation(job, this.list(job.projectId, job.workspaceId));
|
|
52
|
+
return publicJobObservation(job, this.list(job.projectId, job.workspaceId), Date.now(), options?.scopeActive ?? true);
|
|
53
|
+
}
|
|
54
|
+
recoverExpired(projectId, workspaceId) {
|
|
55
|
+
return this.database.recoverExpiredJobs(new Date().toISOString(), projectId, workspaceId);
|
|
53
56
|
}
|
|
54
57
|
list(projectId, workspaceId = DEFAULT_WORKSPACE_ID) {
|
|
55
58
|
return this.database.listJobs(projectId, workspaceId);
|
|
@@ -184,8 +187,8 @@ export function durableJobCursor(job) {
|
|
|
184
187
|
});
|
|
185
188
|
}
|
|
186
189
|
/** Build a privacy-safe job projection from existing durable records. */
|
|
187
|
-
export function publicJobObservation(job, scopeJobs, now = Date.now()) {
|
|
188
|
-
const status = queueStatus(job);
|
|
190
|
+
export function publicJobObservation(job, scopeJobs, now = Date.now(), scopeActive = true) {
|
|
191
|
+
const status = queueStatus(job, now, scopeActive);
|
|
189
192
|
const queueJobs = scopeJobs.filter(isQueueRelevant).filter((candidate) => !isTerminal(candidate));
|
|
190
193
|
const positionIndex = queueJobs.findIndex((candidate) => candidate.id === job.id);
|
|
191
194
|
const position = status === 'terminal' ? null : Math.max(0, positionIndex) + 1;
|
|
@@ -230,16 +233,25 @@ function publicJobFields(job) {
|
|
|
230
233
|
...(job.error === undefined ? {} : { error: sanitizePublicJobValue(job.error) }),
|
|
231
234
|
attempts: job.attempts,
|
|
232
235
|
maxAttempts: job.maxAttempts,
|
|
236
|
+
restarts: job.restarts,
|
|
233
237
|
cancelRequested: job.cancelRequested,
|
|
234
238
|
createdAt: job.createdAt,
|
|
235
239
|
updatedAt: job.updatedAt,
|
|
236
240
|
};
|
|
237
241
|
}
|
|
238
|
-
function queueStatus(job) {
|
|
242
|
+
function queueStatus(job, now = Date.now(), scopeActive = true) {
|
|
239
243
|
if (isTerminal(job)) {
|
|
240
244
|
return 'terminal';
|
|
241
245
|
}
|
|
242
|
-
|
|
246
|
+
if (job.state === 'running') {
|
|
247
|
+
return 'active';
|
|
248
|
+
}
|
|
249
|
+
if ((job.state === 'accepted' || job.state === 'checkpointed') &&
|
|
250
|
+
!scopeActive &&
|
|
251
|
+
now - Date.parse(job.updatedAt) > getRuntimePolicy().validation.workerLeaseMs) {
|
|
252
|
+
return 'stalled';
|
|
253
|
+
}
|
|
254
|
+
return 'queued';
|
|
243
255
|
}
|
|
244
256
|
function isTerminal(job) {
|
|
245
257
|
return TERMINAL_STATES.has(job.state);
|
|
@@ -9,6 +9,7 @@ export declare class ValidateJobExecutor {
|
|
|
9
9
|
constructor(runtime: DurableJobRuntime, workerId?: string, options?: ValidateJobExecutorOptions);
|
|
10
10
|
runOnce(projectId: string, workspaceId?: string): Promise<readonly DurableJobRecord[]>;
|
|
11
11
|
runUntilIdle(projectId: string, workspaceId?: string): Promise<void>;
|
|
12
|
+
private ownLeaseWaitMs;
|
|
12
13
|
private execute;
|
|
13
14
|
private runClaimedValidation;
|
|
14
15
|
private resumeReceiptPublication;
|
|
@@ -28,6 +29,7 @@ export declare class ValidateJobExecutor {
|
|
|
28
29
|
private preparePublicationLease;
|
|
29
30
|
private persistReceiptArtifacts;
|
|
30
31
|
}
|
|
32
|
+
export declare function isValidateScopeActive(projectId: string, workspaceId?: string): boolean;
|
|
31
33
|
/** Schedules background execution after the submit response can be flushed. */
|
|
32
34
|
export declare function scheduleValidateJobExecution(projectId: string, workspaceId?: string): void;
|
|
33
35
|
/** Re-enqueues accepted/checkpointed validate work discovered after a process restart. */
|
|
@@ -24,6 +24,7 @@ import { redactSensitiveValue, redactText } from '../../security/redactor.js';
|
|
|
24
24
|
import { MacOSKeychainOperationError } from '../../security/adapters/macos-keychain.js';
|
|
25
25
|
import { createDurableJobHeartbeat } from './durable-job-heartbeat-runtime.js';
|
|
26
26
|
const WORKSPACE_ID = 'global';
|
|
27
|
+
const MIN_LEASE_WAIT_MS = 50;
|
|
27
28
|
const activeScopes = new Map();
|
|
28
29
|
const RECEIPT_PUBLICATION_FAILURE_MESSAGES = {
|
|
29
30
|
keychain_timeout: '[Planu] VALIDATION_RECEIPT_PENDING action=restart_job cause=keychain_timeout: the signing key could not be read from the keychain before the read timed out',
|
|
@@ -89,6 +90,9 @@ function truncateUtf8ByBytes(value, maximumBytes) {
|
|
|
89
90
|
function canonicalJson(value) {
|
|
90
91
|
return JSON.stringify(value);
|
|
91
92
|
}
|
|
93
|
+
function delay(ms) {
|
|
94
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
95
|
+
}
|
|
92
96
|
function hasReceipt(result) {
|
|
93
97
|
const structured = result.structuredContent;
|
|
94
98
|
return typeof structured?.receiptId === 'string' && typeof structured.receiptKey === 'string';
|
|
@@ -180,8 +184,10 @@ export class ValidateJobExecutor {
|
|
|
180
184
|
}
|
|
181
185
|
async runUntilIdle(projectId, workspaceId = WORKSPACE_ID) {
|
|
182
186
|
const capacity = getRuntimePolicy().validation.workerConcurrency;
|
|
187
|
+
const workerLeaseMs = getRuntimePolicy().validation.workerLeaseMs;
|
|
183
188
|
const active = new Set();
|
|
184
189
|
for (;;) {
|
|
190
|
+
this.runtime.recoverExpired(projectId, workspaceId);
|
|
185
191
|
const available = capacity - active.size;
|
|
186
192
|
const candidates = this.runtime
|
|
187
193
|
.list(projectId, workspaceId)
|
|
@@ -200,6 +206,15 @@ export class ValidateJobExecutor {
|
|
|
200
206
|
active.add(execution);
|
|
201
207
|
}
|
|
202
208
|
if (active.size === 0) {
|
|
209
|
+
const ownLostLease = this.runtime
|
|
210
|
+
.list(projectId, workspaceId)
|
|
211
|
+
.find((job) => job.state === 'running' &&
|
|
212
|
+
job.leaseOwner === this.workerId &&
|
|
213
|
+
isValidateJob(job.payload));
|
|
214
|
+
if (ownLostLease) {
|
|
215
|
+
await delay(this.ownLeaseWaitMs(ownLostLease.leaseExpiresAt, workerLeaseMs));
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
203
218
|
return;
|
|
204
219
|
}
|
|
205
220
|
if (active.size >= capacity || candidates.length === 0) {
|
|
@@ -207,6 +222,13 @@ export class ValidateJobExecutor {
|
|
|
207
222
|
}
|
|
208
223
|
}
|
|
209
224
|
}
|
|
225
|
+
ownLeaseWaitMs(leaseExpiresAt, workerLeaseMs) {
|
|
226
|
+
const expiresAtMs = leaseExpiresAt ? Date.parse(leaseExpiresAt) : Number.NaN;
|
|
227
|
+
if (!Number.isFinite(expiresAtMs)) {
|
|
228
|
+
return workerLeaseMs;
|
|
229
|
+
}
|
|
230
|
+
return Math.min(Math.max(expiresAtMs - Date.now(), MIN_LEASE_WAIT_MS), workerLeaseMs);
|
|
231
|
+
}
|
|
210
232
|
async execute(job) {
|
|
211
233
|
const identity = {
|
|
212
234
|
operationId: job.id,
|
|
@@ -818,6 +840,9 @@ export class ValidateJobExecutor {
|
|
|
818
840
|
return undefined;
|
|
819
841
|
}
|
|
820
842
|
}
|
|
843
|
+
export function isValidateScopeActive(projectId, workspaceId = WORKSPACE_ID) {
|
|
844
|
+
return activeScopes.has(`${projectId}:${workspaceId}`);
|
|
845
|
+
}
|
|
821
846
|
/** Schedules background execution after the submit response can be flushed. */
|
|
822
847
|
export function scheduleValidateJobExecution(projectId, workspaceId = WORKSPACE_ID) {
|
|
823
848
|
const scope = `${projectId}:${workspaceId}`;
|
|
@@ -62,7 +62,7 @@ export interface JobLeaseInput {
|
|
|
62
62
|
readonly now?: string;
|
|
63
63
|
}
|
|
64
64
|
export interface RuntimeWorkspaceRecovery {
|
|
65
|
-
readonly schemaVersion:
|
|
65
|
+
readonly schemaVersion: 5;
|
|
66
66
|
readonly projectId: string;
|
|
67
67
|
readonly workspaceId: string;
|
|
68
68
|
readonly records: readonly RuntimeRecord[];
|
|
@@ -83,7 +83,7 @@ export declare class RuntimeDatabaseResourceExhaustedError extends Error {
|
|
|
83
83
|
/** A bounded (one connection), transactional SQLite runtime store. */
|
|
84
84
|
export declare class RuntimeDatabase implements Disposable {
|
|
85
85
|
readonly path: string;
|
|
86
|
-
readonly schemaVersion =
|
|
86
|
+
readonly schemaVersion = 5;
|
|
87
87
|
private readonly database;
|
|
88
88
|
private readonly connectionKey;
|
|
89
89
|
private closed;
|
|
@@ -135,6 +135,8 @@ export declare class RuntimeDatabase implements Disposable {
|
|
|
135
135
|
restartReceiptPublication(projectId: string, workspaceId: string, id: string, limits: ValidationReceiptCheckpointLimits): DurableJobRecord;
|
|
136
136
|
restartJobWithPayload(projectId: string, workspaceId: string, id: string, payload: unknown): DurableJobRecord;
|
|
137
137
|
cancelJob(projectId: string, workspaceId: string, id: string): DurableJobRecord;
|
|
138
|
+
private assertRestartCeiling;
|
|
139
|
+
private freshRestartDeadline;
|
|
138
140
|
private archiveCheckpointBeforeRestart;
|
|
139
141
|
recoverExpiredJobs(now?: string, projectId?: string, workspaceId?: string): number;
|
|
140
142
|
private requireLeasedJob;
|
|
@@ -4,8 +4,10 @@ import { dirname, isAbsolute, resolve } from 'node:path';
|
|
|
4
4
|
import { DatabaseSync } from 'node:sqlite';
|
|
5
5
|
import { DURABLE_JOB_STATES, } from '../types/durable-job.js';
|
|
6
6
|
import { parseValidationReceiptPendingCheckpoint, } from '../types/durable-validation.js';
|
|
7
|
+
// eslint-disable-next-line no-restricted-imports -- grandfathered layer violation, remediation SPEC-1661 SPEC-1662 SPEC-1663
|
|
8
|
+
import { getRuntimePolicy } from '../engine/runtime-policy.js';
|
|
7
9
|
export { DURABLE_JOB_STATES };
|
|
8
|
-
const CURRENT_SCHEMA_VERSION =
|
|
10
|
+
const CURRENT_SCHEMA_VERSION = 5;
|
|
9
11
|
const DEFAULT_BUSY_TIMEOUT_MS = 5_000;
|
|
10
12
|
const DEFAULT_MAX_CONNECTIONS = 4;
|
|
11
13
|
/**
|
|
@@ -38,6 +40,7 @@ const OUTBOX_ELIGIBILITY_CLAUSE = `
|
|
|
38
40
|
OR json_extract(fence.value_json, '$.nextAttemptAt')
|
|
39
41
|
NOT GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*'
|
|
40
42
|
OR json_extract(fence.value_json, '$.nextAttemptAt') <= ?)`;
|
|
43
|
+
const VALIDATE_DEADLINE_REFRESH_SQL = `CASE WHEN json_extract(payload_json, '$.kind') = 'validate' THEN json_set(payload_json, '$.deadlineAt', ?) ELSE payload_json END`;
|
|
41
44
|
const openConnections = new Map();
|
|
42
45
|
let integrityCheckedOpens = 0;
|
|
43
46
|
let integrityBypassedOpens = 0;
|
|
@@ -87,6 +90,14 @@ function stringifyJson(value) {
|
|
|
87
90
|
}
|
|
88
91
|
return serialized;
|
|
89
92
|
}
|
|
93
|
+
function withFreshValidateDeadline(payload, deadlineAt) {
|
|
94
|
+
if (!payload ||
|
|
95
|
+
typeof payload !== 'object' ||
|
|
96
|
+
payload.kind !== 'validate') {
|
|
97
|
+
return payload;
|
|
98
|
+
}
|
|
99
|
+
return { ...payload, deadlineAt };
|
|
100
|
+
}
|
|
90
101
|
/** A bounded (one connection), transactional SQLite runtime store. */
|
|
91
102
|
export class RuntimeDatabase {
|
|
92
103
|
path;
|
|
@@ -324,6 +335,15 @@ export class RuntimeDatabase {
|
|
|
324
335
|
COMMIT;
|
|
325
336
|
`);
|
|
326
337
|
}
|
|
338
|
+
const afterFencingToken = this.database.prepare('PRAGMA user_version').get();
|
|
339
|
+
if (afterFencingToken.user_version === 4) {
|
|
340
|
+
this.database.exec(`
|
|
341
|
+
BEGIN IMMEDIATE;
|
|
342
|
+
ALTER TABLE jobs ADD COLUMN restarts INTEGER NOT NULL DEFAULT 0 CHECK (restarts >= 0);
|
|
343
|
+
PRAGMA user_version = 5;
|
|
344
|
+
COMMIT;
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
327
347
|
}
|
|
328
348
|
assertIntegrity() {
|
|
329
349
|
this.assertOpen();
|
|
@@ -575,21 +595,23 @@ export class RuntimeDatabase {
|
|
|
575
595
|
requireIdentifier(projectId, 'projectId');
|
|
576
596
|
requireIdentifier(workspaceId, 'workspaceId');
|
|
577
597
|
requireIdentifier(id, 'job id');
|
|
578
|
-
const now = new Date().toISOString();
|
|
579
598
|
this.transaction(() => {
|
|
580
599
|
const current = this.getJob(projectId, workspaceId, id);
|
|
581
600
|
if (!current ||
|
|
582
601
|
!['accepted', 'checkpointed', 'failed', 'dead-letter', 'cancelled', 'completed'].includes(current.state)) {
|
|
583
602
|
throw new Error('[Planu] Job is not restartable');
|
|
584
603
|
}
|
|
604
|
+
this.assertRestartCeiling(current, id);
|
|
605
|
+
const { now, deadlineAt } = this.freshRestartDeadline();
|
|
585
606
|
this.archiveCheckpointBeforeRestart(projectId, workspaceId, id, now);
|
|
586
607
|
const result = this.database
|
|
587
|
-
.prepare(`UPDATE jobs SET state = 'accepted', attempts = 0, cancel_requested = 0,
|
|
608
|
+
.prepare(`UPDATE jobs SET state = 'accepted', attempts = 0, restarts = restarts + 1, cancel_requested = 0,
|
|
588
609
|
checkpoint_json = NULL, result_json = NULL, error_message = NULL,
|
|
589
|
-
lease_owner = NULL, lease_expires_at = NULL, updated_at =
|
|
610
|
+
lease_owner = NULL, lease_expires_at = NULL, updated_at = ?,
|
|
611
|
+
payload_json = ${VALIDATE_DEADLINE_REFRESH_SQL}
|
|
590
612
|
WHERE project_id = ? AND workspace_id = ? AND id = ?
|
|
591
613
|
AND state IN ('accepted', 'checkpointed', 'failed', 'dead-letter', 'cancelled', 'completed')`)
|
|
592
|
-
.run(now, projectId, workspaceId, id);
|
|
614
|
+
.run(now, deadlineAt, projectId, workspaceId, id);
|
|
593
615
|
if (result.changes !== 1) {
|
|
594
616
|
throw new Error('[Planu] Job is not restartable');
|
|
595
617
|
}
|
|
@@ -601,7 +623,6 @@ export class RuntimeDatabase {
|
|
|
601
623
|
requireIdentifier(projectId, 'projectId');
|
|
602
624
|
requireIdentifier(workspaceId, 'workspaceId');
|
|
603
625
|
requireIdentifier(id, 'job id');
|
|
604
|
-
const now = new Date().toISOString();
|
|
605
626
|
this.transaction(() => {
|
|
606
627
|
const current = this.getJob(projectId, workspaceId, id);
|
|
607
628
|
if (!current ||
|
|
@@ -610,13 +631,16 @@ export class RuntimeDatabase {
|
|
|
610
631
|
!parseValidationReceiptPendingCheckpoint(current.checkpoint, limits)) {
|
|
611
632
|
throw new Error('[Planu] Job receipt publication is not restartable');
|
|
612
633
|
}
|
|
634
|
+
this.assertRestartCeiling(current, id);
|
|
635
|
+
const { now, deadlineAt } = this.freshRestartDeadline();
|
|
613
636
|
const changed = this.database
|
|
614
|
-
.prepare(`UPDATE jobs SET state = 'accepted', attempts = 0, cancel_requested = 0,
|
|
637
|
+
.prepare(`UPDATE jobs SET state = 'accepted', attempts = 0, restarts = restarts + 1, cancel_requested = 0,
|
|
615
638
|
result_json = NULL, error_message = NULL, lease_owner = NULL,
|
|
616
|
-
lease_expires_at = NULL, updated_at =
|
|
639
|
+
lease_expires_at = NULL, updated_at = ?,
|
|
640
|
+
payload_json = ${VALIDATE_DEADLINE_REFRESH_SQL}
|
|
617
641
|
WHERE project_id = ? AND workspace_id = ? AND id = ?
|
|
618
642
|
AND state IN ('failed', 'dead-letter') AND cancel_requested = 0`)
|
|
619
|
-
.run(now, projectId, workspaceId, id);
|
|
643
|
+
.run(now, deadlineAt, projectId, workspaceId, id);
|
|
620
644
|
if (changed.changes !== 1) {
|
|
621
645
|
throw new Error('[Planu] Job receipt publication is not restartable');
|
|
622
646
|
}
|
|
@@ -628,21 +652,22 @@ export class RuntimeDatabase {
|
|
|
628
652
|
requireIdentifier(projectId, 'projectId');
|
|
629
653
|
requireIdentifier(workspaceId, 'workspaceId');
|
|
630
654
|
requireIdentifier(id, 'job id');
|
|
631
|
-
const now = new Date().toISOString();
|
|
632
655
|
this.transaction(() => {
|
|
633
656
|
const current = this.getJob(projectId, workspaceId, id);
|
|
634
657
|
if (!current ||
|
|
635
658
|
!['failed', 'dead-letter', 'cancelled', 'completed'].includes(current.state)) {
|
|
636
659
|
throw new Error('[Planu] Job payload is not replaceable while work is active');
|
|
637
660
|
}
|
|
661
|
+
this.assertRestartCeiling(current, id);
|
|
662
|
+
const { now, deadlineAt } = this.freshRestartDeadline();
|
|
638
663
|
this.archiveCheckpointBeforeRestart(projectId, workspaceId, id, now);
|
|
639
664
|
const result = this.database
|
|
640
|
-
.prepare(`UPDATE jobs SET state = 'accepted', attempts = 0, cancel_requested = 0,
|
|
665
|
+
.prepare(`UPDATE jobs SET state = 'accepted', attempts = 0, restarts = restarts + 1, cancel_requested = 0,
|
|
641
666
|
payload_json = ?, checkpoint_json = NULL, result_json = NULL, error_message = NULL,
|
|
642
667
|
lease_owner = NULL, lease_expires_at = NULL, updated_at = ?
|
|
643
668
|
WHERE project_id = ? AND workspace_id = ? AND id = ?
|
|
644
669
|
AND state IN ('failed', 'dead-letter', 'cancelled', 'completed')`)
|
|
645
|
-
.run(stringifyJson(payload), now, projectId, workspaceId, id);
|
|
670
|
+
.run(stringifyJson(withFreshValidateDeadline(payload, deadlineAt)), now, projectId, workspaceId, id);
|
|
646
671
|
if (result.changes !== 1) {
|
|
647
672
|
throw new Error('[Planu] Job payload is not replaceable while work is active');
|
|
648
673
|
}
|
|
@@ -671,6 +696,18 @@ export class RuntimeDatabase {
|
|
|
671
696
|
.run(now, projectId, workspaceId, id);
|
|
672
697
|
return requireJobRecord(this.getJob(projectId, workspaceId, id), id);
|
|
673
698
|
}
|
|
699
|
+
assertRestartCeiling(current, id) {
|
|
700
|
+
if (current.restarts >= current.maxAttempts) {
|
|
701
|
+
throw new Error(`[Planu] Job ${id} was restarted ${String(current.restarts)} times (ceiling ${String(current.maxAttempts)}); call cancel_job and submit a fresh operation`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
freshRestartDeadline() {
|
|
705
|
+
const nowMs = Date.now();
|
|
706
|
+
return {
|
|
707
|
+
now: new Date(nowMs).toISOString(),
|
|
708
|
+
deadlineAt: nowMs + getRuntimePolicy().validation.defaultDeadlineMs,
|
|
709
|
+
};
|
|
710
|
+
}
|
|
674
711
|
archiveCheckpointBeforeRestart(projectId, workspaceId, id, restartedAt) {
|
|
675
712
|
const current = this.getJob(projectId, workspaceId, id);
|
|
676
713
|
if (current?.checkpoint === undefined) {
|
|
@@ -1162,6 +1199,7 @@ function mapJobRow(row) {
|
|
|
1162
1199
|
error: typeof row.error_message === 'string' ? row.error_message : undefined,
|
|
1163
1200
|
attempts: Number(row.attempts),
|
|
1164
1201
|
maxAttempts: Number(row.max_attempts),
|
|
1202
|
+
restarts: Number(row.restarts),
|
|
1165
1203
|
cancelRequested: row.cancel_requested === 1,
|
|
1166
1204
|
leaseOwner: typeof row.lease_owner === 'string' ? row.lease_owner : undefined,
|
|
1167
1205
|
fencingToken: Number(row.fencing_token),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Spec, SpecStatus, SpecVersion, SpecSummary, DefinitionOfReady, DefinitionOfDone, StatusHistoryEntry, PostCommitTaskClaim } from '../types/index.js';
|
|
1
|
+
import type { Spec, SpecStatus, SpecVersion, SpecSummary, DefinitionOfReady, DefinitionOfDone, StatusHistoryEntry, PostCommitTaskClaim, SpecStoreListing } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Thrown when code tries to write `status` via `updateSpec` directly.
|
|
4
4
|
* All status transitions must go through `handleUpdateStatus` → `transitionSpec`.
|
|
@@ -34,6 +34,7 @@ export declare function discoverCanonicalSpecPath(specId: string, canonicalRoot:
|
|
|
34
34
|
* verified against the current spec.md before being returned (SPEC-1699).
|
|
35
35
|
*/
|
|
36
36
|
export declare function listSpecs(projectId: string, canonicalRoot?: string): Promise<Spec[]>;
|
|
37
|
+
export declare function listSpecsWithGhosts(projectId: string, canonicalRoot: string): Promise<SpecStoreListing>;
|
|
37
38
|
/**
|
|
38
39
|
* Run a read-modify side effect against a fresh spec snapshot while holding the
|
|
39
40
|
* same cross-process lock used by status mutations.
|
|
@@ -273,6 +273,9 @@ async function refreshSpecFromDisk(projectId, spec, canonicalRoot) {
|
|
|
273
273
|
reportClassifiedDegradation('SPEC_CONTENT_DIGEST_CHECK_SKIPPED', error);
|
|
274
274
|
return spec;
|
|
275
275
|
}
|
|
276
|
+
if (content.length === 0) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
276
279
|
const digest = digestOf(content);
|
|
277
280
|
if (digest === spec.contentDigest) {
|
|
278
281
|
return spec;
|
|
@@ -292,12 +295,27 @@ async function refreshSpecFromDisk(projectId, spec, canonicalRoot) {
|
|
|
292
295
|
* verified against the current spec.md before being returned (SPEC-1699).
|
|
293
296
|
*/
|
|
294
297
|
export async function listSpecs(projectId, canonicalRoot) {
|
|
295
|
-
const specs = await loadAll(projectId);
|
|
296
298
|
if (canonicalRoot === undefined) {
|
|
297
|
-
return
|
|
299
|
+
return loadAll(projectId);
|
|
298
300
|
}
|
|
301
|
+
const { specs } = await listSpecsWithGhosts(projectId, canonicalRoot);
|
|
302
|
+
return specs;
|
|
303
|
+
}
|
|
304
|
+
export async function listSpecsWithGhosts(projectId, canonicalRoot) {
|
|
305
|
+
const specs = await loadAll(projectId);
|
|
299
306
|
const refreshed = await Promise.all(specs.map((spec) => refreshSpecFromDisk(projectId, spec, canonicalRoot)));
|
|
300
|
-
|
|
307
|
+
const listing = { specs: [], ghosts: [] };
|
|
308
|
+
refreshed.forEach((refreshedSpec, index) => {
|
|
309
|
+
if (refreshedSpec === null) {
|
|
310
|
+
const original = specs[index];
|
|
311
|
+
if (original) {
|
|
312
|
+
listing.ghosts.push(original);
|
|
313
|
+
}
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
listing.specs.push(refreshedSpec);
|
|
317
|
+
});
|
|
318
|
+
return listing;
|
|
301
319
|
}
|
|
302
320
|
/**
|
|
303
321
|
* Run a read-modify side effect against a fresh spec snapshot while holding the
|
|
@@ -1083,7 +1083,10 @@ export async function resolveGroundedVerificationCommands(projectPath, testPaths
|
|
|
1083
1083
|
if (typeof manifest.scripts?.test !== 'string' || manifest.scripts.test.trim() === '') {
|
|
1084
1084
|
return [];
|
|
1085
1085
|
}
|
|
1086
|
-
|
|
1086
|
+
const joiner = packageManager === 'npm' ? ' -- ' : ' ';
|
|
1087
|
+
return [
|
|
1088
|
+
`${packageManager} run test${joiner}${testPaths.map(quotePosixShellArgument).join(' ')}`,
|
|
1089
|
+
];
|
|
1087
1090
|
}
|
|
1088
1091
|
catch {
|
|
1089
1092
|
return [];
|
|
@@ -51,7 +51,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
53
|
import { DurableJobRuntime, publicJobCursor } from '../../engine/execution/job-runtime.js';
|
|
54
|
-
import { scheduleValidateJobExecution } from '../../engine/execution/validate-job-executor.js';
|
|
54
|
+
import { isValidateScopeActive, scheduleValidateJobExecution, } from '../../engine/execution/validate-job-executor.js';
|
|
55
55
|
import { schedulePackageHandoffJobExecution } from '../../engine/execution/package-handoff-job-executor.js';
|
|
56
56
|
import { isValidationReceiptPendingIntent, parseValidationReceiptPendingCheckpoint, } from '../../types/durable-validation.js';
|
|
57
57
|
import { redactText } from '../../security/redactor.js';
|
|
@@ -63,7 +63,11 @@ function result(payload) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function publicJob(runtime, job) {
|
|
66
|
-
const
|
|
66
|
+
const scopeActive = isValidateScopeActive(job.projectId, job.workspaceId);
|
|
67
|
+
const sanitized = runtime.observe(job, { scopeActive });
|
|
68
|
+
if (sanitized.queue.status === 'stalled') {
|
|
69
|
+
rescheduleStalledJob(job);
|
|
70
|
+
}
|
|
67
71
|
if (job.state === 'completed') {
|
|
68
72
|
const { checkpoint: _checkpoint, error: _error, ...completed } = sanitized;
|
|
69
73
|
return completed;
|
|
@@ -75,6 +79,17 @@ function publicJob(runtime, job) {
|
|
|
75
79
|
return { ...sanitized, error: errorMessage, errorMessage };
|
|
76
80
|
}
|
|
77
81
|
const RECEIPT_PENDING_MESSAGE = '[Planu] VALIDATION_RECEIPT_PENDING action=restart_job';
|
|
82
|
+
function rescheduleStalledJob(job) {
|
|
83
|
+
const kind = job.payload && typeof job.payload === 'object'
|
|
84
|
+
? job.payload.kind
|
|
85
|
+
: undefined;
|
|
86
|
+
if (kind === 'validate') {
|
|
87
|
+
scheduleValidateJobExecution(job.projectId, job.workspaceId);
|
|
88
|
+
}
|
|
89
|
+
else if (kind === 'package-handoff') {
|
|
90
|
+
schedulePackageHandoffJobExecution(job.projectId, job.workspaceId);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
78
93
|
function checkpointLimits() {
|
|
79
94
|
const policy = getRuntimePolicy().validation;
|
|
80
95
|
return {
|
|
@@ -108,15 +123,7 @@ export function handleRestartJob(input) {
|
|
|
108
123
|
throw new Error('[Planu] Invalid validation receipt checkpoint');
|
|
109
124
|
}
|
|
110
125
|
const job = pending ? runtime.restartReceiptPublication(input) : runtime.restart(input);
|
|
111
|
-
|
|
112
|
-
? job.payload.kind
|
|
113
|
-
: undefined;
|
|
114
|
-
if (kind === 'validate') {
|
|
115
|
-
scheduleValidateJobExecution(job.projectId, job.workspaceId);
|
|
116
|
-
}
|
|
117
|
-
else if (kind === 'package-handoff') {
|
|
118
|
-
schedulePackageHandoffJobExecution(job.projectId, job.workspaceId);
|
|
119
|
-
}
|
|
126
|
+
rescheduleStalledJob(job);
|
|
120
127
|
const observation = publicJob(runtime, job);
|
|
121
128
|
return Promise.resolve(result({ schemaVersion: 1, job: observation, cursor: publicJobCursor(observation) }));
|
|
122
129
|
}
|
package/dist/tools/list-specs.js
CHANGED
|
@@ -35,6 +35,31 @@ function buildLegacyMigrationNextAction(directives) {
|
|
|
35
35
|
`legacyFiles into their targetSection, then call migrate_legacy_spec with the merged spec.md ` +
|
|
36
36
|
`body and filesToRetire.`);
|
|
37
37
|
}
|
|
38
|
+
async function loadSpecsWithGhosts(projectId, projectPath) {
|
|
39
|
+
if (projectPath) {
|
|
40
|
+
const listing = await specStore.listSpecsWithGhosts(projectId, projectPath);
|
|
41
|
+
return { allSpecs: listing.specs, ghosts: listing.ghosts, ghostDetectionSkipped: false };
|
|
42
|
+
}
|
|
43
|
+
const allSpecs = await specStore.listSpecs(projectId);
|
|
44
|
+
return { allSpecs, ghosts: [], ghostDetectionSkipped: true };
|
|
45
|
+
}
|
|
46
|
+
function filterSpecs(allSpecs, status, type) {
|
|
47
|
+
const byStatus = status
|
|
48
|
+
? allSpecs.filter((s) => s.status === status)
|
|
49
|
+
: allSpecs.filter((s) => s.status !== 'discarded');
|
|
50
|
+
return type ? byStatus.filter((s) => s.type === type) : byStatus;
|
|
51
|
+
}
|
|
52
|
+
function buildGhostReport(ghosts) {
|
|
53
|
+
return ghosts
|
|
54
|
+
.filter((g) => g.status !== 'discarded')
|
|
55
|
+
.map((g) => ({
|
|
56
|
+
id: g.id,
|
|
57
|
+
title: g.title,
|
|
58
|
+
status: g.status,
|
|
59
|
+
specPath: g.specPath,
|
|
60
|
+
nextAction: `update_status(${g.id}, discarded) with a reason, or restore spec.md from git`,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
38
63
|
/** Track which projects have been auto-discovered this session (once per project). */
|
|
39
64
|
const discoveredProjects = new Set();
|
|
40
65
|
const MAX_STRUCTURED_SPECS = 50;
|
|
@@ -124,21 +149,10 @@ export async function handleListSpecs(params) {
|
|
|
124
149
|
if (detail === 'full' && knowledge.projectPath) {
|
|
125
150
|
await collectReadOnlyProjectSignals(projectId, knowledge.projectPath, collector);
|
|
126
151
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (status) {
|
|
131
|
-
specs = specs.filter((s) => s.status === status);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
// Exclude discarded specs from default (unfiltered) results
|
|
135
|
-
specs = specs.filter((s) => s.status !== 'discarded');
|
|
136
|
-
}
|
|
137
|
-
if (type) {
|
|
138
|
-
specs = specs.filter((s) => s.type === type);
|
|
139
|
-
}
|
|
152
|
+
const { allSpecs, ghosts, ghostDetectionSkipped } = await loadSpecsWithGhosts(projectId, knowledge.projectPath);
|
|
153
|
+
const specs = filterSpecs(allSpecs, status, type);
|
|
154
|
+
const reportedGhosts = buildGhostReport(ghosts);
|
|
140
155
|
// Build summary statistics
|
|
141
|
-
const allSpecs = await specStore.listSpecs(projectId);
|
|
142
156
|
const statusCounts = {};
|
|
143
157
|
const typeCounts = {};
|
|
144
158
|
for (const s of allSpecs) {
|
|
@@ -221,11 +235,14 @@ export async function handleListSpecs(params) {
|
|
|
221
235
|
});
|
|
222
236
|
}
|
|
223
237
|
const filterApplied = Boolean(status) || Boolean(type);
|
|
224
|
-
const
|
|
238
|
+
const baseHumanSummary = filterApplied && specs.length === 0
|
|
225
239
|
? `No plans match the current filter.`
|
|
226
240
|
: filterApplied
|
|
227
241
|
? buildListSpecsSummary(specs.length, specs.reduce((acc, s) => ({ ...acc, [s.status]: (acc[s.status] ?? 0) + 1 }), {}))
|
|
228
242
|
: buildListSpecsSummary(allSpecs.length, statusCounts);
|
|
243
|
+
const humanSummary = ghostDetectionSkipped
|
|
244
|
+
? `${baseHumanSummary}\nGhost detection skipped: project path is unknown.`
|
|
245
|
+
: baseHumanSummary;
|
|
229
246
|
// SPEC-467: Detect branches and include info for LLM branch-awareness
|
|
230
247
|
let branchInfo = null;
|
|
231
248
|
if (detail === 'full' && knowledge.projectPath) {
|
|
@@ -315,6 +332,7 @@ export async function handleListSpecs(params) {
|
|
|
315
332
|
staleStatusWarnings: staleStatusWarnings.length > 0 ? staleStatusWarnings : undefined,
|
|
316
333
|
legacyMigrationDirectives: legacyMigrationDirectives.length > 0 ? legacyMigrationDirectives : undefined,
|
|
317
334
|
nextAction: legacyMigrationNextAction,
|
|
335
|
+
ghosts: reportedGhosts.length > 0 ? reportedGhosts : undefined,
|
|
318
336
|
};
|
|
319
337
|
return {
|
|
320
338
|
content: [
|
|
@@ -81,6 +81,13 @@ export declare const ListSpecsOutputSchema: {
|
|
|
81
81
|
directive: z.ZodLiteral<"migrate_legacy_spec">;
|
|
82
82
|
}, z.core.$strip>>>;
|
|
83
83
|
nextAction: z.ZodOptional<z.ZodString>;
|
|
84
|
+
ghosts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
85
|
+
id: z.ZodString;
|
|
86
|
+
title: z.ZodString;
|
|
87
|
+
status: z.ZodString;
|
|
88
|
+
specPath: z.ZodString;
|
|
89
|
+
nextAction: z.ZodString;
|
|
90
|
+
}, z.core.$strip>>>;
|
|
84
91
|
};
|
|
85
92
|
/** Canonical DTO inferred from the exact MCP output contract. */
|
|
86
93
|
export declare const ListSpecsOutputObjectSchema: z.ZodObject<{
|
|
@@ -165,6 +172,13 @@ export declare const ListSpecsOutputObjectSchema: z.ZodObject<{
|
|
|
165
172
|
directive: z.ZodLiteral<"migrate_legacy_spec">;
|
|
166
173
|
}, z.core.$strip>>>;
|
|
167
174
|
nextAction: z.ZodOptional<z.ZodString>;
|
|
175
|
+
ghosts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
176
|
+
id: z.ZodString;
|
|
177
|
+
title: z.ZodString;
|
|
178
|
+
status: z.ZodString;
|
|
179
|
+
specPath: z.ZodString;
|
|
180
|
+
nextAction: z.ZodString;
|
|
181
|
+
}, z.core.$strip>>>;
|
|
168
182
|
}, z.core.$strip>;
|
|
169
183
|
export type ListSpecsStructuredContent = z.infer<typeof ListSpecsOutputObjectSchema>;
|
|
170
184
|
export declare const EstimateOutputSchema: {
|
|
@@ -94,6 +94,20 @@ export const ListSpecsOutputSchema = {
|
|
|
94
94
|
}))
|
|
95
95
|
.optional(),
|
|
96
96
|
nextAction: z.string().optional(),
|
|
97
|
+
ghosts: z
|
|
98
|
+
.array(z.object({
|
|
99
|
+
id: z.string().describe('Spec identifier of the ghost store entry.'),
|
|
100
|
+
title: z.string().describe('Title recorded in the store for the ghost entry.'),
|
|
101
|
+
status: z.string().describe('Store status of the ghost entry.'),
|
|
102
|
+
specPath: z
|
|
103
|
+
.string()
|
|
104
|
+
.describe('Store-recorded specPath that could not be resolved to spec.md on disk.'),
|
|
105
|
+
nextAction: z
|
|
106
|
+
.string()
|
|
107
|
+
.describe('Recommended remediation: discard the entry or restore spec.md from git.'),
|
|
108
|
+
}))
|
|
109
|
+
.optional()
|
|
110
|
+
.describe('Store entries whose spec.md is missing or empty on disk, excluded from the normal listing.'),
|
|
97
111
|
};
|
|
98
112
|
/** Canonical DTO inferred from the exact MCP output contract. */
|
|
99
113
|
export const ListSpecsOutputObjectSchema = z.object(ListSpecsOutputSchema);
|
|
@@ -30,7 +30,9 @@ export const PackageHandoffOutputSchema = {
|
|
|
30
30
|
.regex(/^[a-f0-9]{64}$/)
|
|
31
31
|
.describe('Content-derived observation cursor.'),
|
|
32
32
|
queue: z.object({
|
|
33
|
-
status: z
|
|
33
|
+
status: z
|
|
34
|
+
.enum(['active', 'queued', 'stalled', 'terminal'])
|
|
35
|
+
.describe('Queue lifecycle bucket: active (a worker is running it), queued (waiting behind capacity), stalled (nothing is draining it; get_job will re-schedule it), terminal (reached a final state).'),
|
|
34
36
|
position: z
|
|
35
37
|
.number()
|
|
36
38
|
.int()
|
|
@@ -202,7 +202,9 @@ export const ValidateOutputSchema = {
|
|
|
202
202
|
.describe('True when this request attached to an already-running validation job instead of dispatching new work.'),
|
|
203
203
|
cursor: z.string().regex(/^[a-f0-9]{64}$/),
|
|
204
204
|
queue: z.object({
|
|
205
|
-
status: z
|
|
205
|
+
status: z
|
|
206
|
+
.enum(['active', 'queued', 'stalled', 'terminal'])
|
|
207
|
+
.describe('Queue lifecycle bucket: active (a worker is running it), queued (waiting behind capacity), stalled (nothing is draining it; get_job will re-schedule it), terminal (reached a final state).'),
|
|
206
208
|
position: z.number().int().positive().nullable(),
|
|
207
209
|
aheadCount: z.number().int().nonnegative(),
|
|
208
210
|
capacity: z.number().int().positive(),
|
|
@@ -13,6 +13,8 @@ import { verifyTerminalFrontmatter } from '../engine/frontmatter-sha/index.js';
|
|
|
13
13
|
import { appendTransitionEvent, streamJsonlLines, transitionLogPath, } from '../storage/transition-log.js';
|
|
14
14
|
import { cleanEphemeralArtifacts } from '../engine/housekeeping/index.js';
|
|
15
15
|
import { readFile, stat } from 'node:fs/promises';
|
|
16
|
+
import { resolve } from 'node:path';
|
|
17
|
+
import { resolvePortableSpecPath, PortablePathError } from '../storage/project-identity.js';
|
|
16
18
|
// ---------------------------------------------------------------------------
|
|
17
19
|
// Sync helpers (exported for startup use)
|
|
18
20
|
// ---------------------------------------------------------------------------
|
|
@@ -37,12 +39,14 @@ export async function syncSpecState(projectPath, projectId, options = {}) {
|
|
|
37
39
|
ghosts: [],
|
|
38
40
|
};
|
|
39
41
|
}
|
|
42
|
+
const resolvedPaths = await resolveSpecPaths(projectPath, dataEntries);
|
|
40
43
|
// SPEC-1351 (AC3): quarantine store entries whose spec.md is missing on
|
|
41
44
|
// disk — ghost registrations left behind by a create_spec attempt that
|
|
42
45
|
// reported success but never persisted (or whose file was later deleted).
|
|
43
|
-
const ghosts = await detectGhostSpecs(projectId, dataEntries);
|
|
46
|
+
const { ghosts, unresolvable } = await detectGhostSpecs(projectId, projectPath, dataEntries, resolvedPaths);
|
|
44
47
|
const { updates, report } = await detectSpecStateDivergences(projectPath, dataEntries);
|
|
45
48
|
report.ghosts = ghosts;
|
|
49
|
+
report.rejected.push(...unresolvable);
|
|
46
50
|
// SyncReport.rejected is always defined (SPEC-720)
|
|
47
51
|
const TERMINAL_STATUSES = ['done', 'discarded'];
|
|
48
52
|
for (const { specId, newStatus } of updates) {
|
|
@@ -50,10 +54,23 @@ export async function syncSpecState(projectPath, projectId, options = {}) {
|
|
|
50
54
|
const currentStoreStatus = dataEntry?.status;
|
|
51
55
|
// SPEC-723: If data-store status is terminal, verify SHA before any sync action
|
|
52
56
|
if (dataEntry && currentStoreStatus && TERMINAL_STATUSES.includes(currentStoreStatus)) {
|
|
53
|
-
const
|
|
54
|
-
|
|
57
|
+
const pathResolution = resolvedPaths.get(specId);
|
|
58
|
+
const resolvedSpecPath = pathResolution?.resolvedPath;
|
|
59
|
+
if (!resolvedSpecPath && dataEntry.specPath) {
|
|
60
|
+
report.rejected.push({
|
|
61
|
+
specId,
|
|
62
|
+
reason: `terminal_spec_path_unresolvable — code=${pathResolution?.failureCode ?? 'MISSING_SPEC_PATH'}; ` +
|
|
63
|
+
`store status '${currentStoreStatus}' is authoritative`,
|
|
64
|
+
});
|
|
65
|
+
const idx = report.divergences.findIndex((d) => d.specId === specId);
|
|
66
|
+
if (idx !== -1) {
|
|
67
|
+
report.divergences.splice(idx, 1);
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (resolvedSpecPath) {
|
|
55
72
|
try {
|
|
56
|
-
const content = await readFile(
|
|
73
|
+
const content = await readFile(resolvedSpecPath, 'utf-8');
|
|
57
74
|
const { metadata } = parseFrontmatter(content);
|
|
58
75
|
const verification = await verifyTerminalFrontmatter({
|
|
59
76
|
projectId,
|
|
@@ -166,38 +183,90 @@ async function collectQuarantinedSpecIds(projectId) {
|
|
|
166
183
|
}
|
|
167
184
|
return quarantined;
|
|
168
185
|
}
|
|
169
|
-
async function
|
|
186
|
+
async function resolveSpecPaths(projectPath, dataEntries) {
|
|
187
|
+
const resolved = new Map();
|
|
188
|
+
await Promise.all(dataEntries.map(async (entry) => {
|
|
189
|
+
if (!entry.specPath) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const resolvedPath = await resolvePortableSpecPath(entry.id, entry.specPath, projectPath);
|
|
194
|
+
resolved.set(entry.id, { resolvedPath });
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error instanceof PortablePathError) {
|
|
198
|
+
resolved.set(entry.id, { failureCode: error.code });
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
resolved.set(entry.id, { failureCode: 'UNEXPECTED' });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}));
|
|
205
|
+
return resolved;
|
|
206
|
+
}
|
|
207
|
+
async function detectGhostSpecs(projectId, projectPath, dataEntries, resolvedPaths) {
|
|
170
208
|
const ghosts = [];
|
|
209
|
+
const unresolvable = [];
|
|
171
210
|
const alreadyQuarantined = await collectQuarantinedSpecIds(projectId);
|
|
172
211
|
await Promise.all(dataEntries.map(async (entry) => {
|
|
173
212
|
if (!entry.specPath) {
|
|
174
213
|
return;
|
|
175
214
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
215
|
+
const resolution = resolvedPaths.get(entry.id);
|
|
216
|
+
let absolutePath;
|
|
217
|
+
let isGhost;
|
|
218
|
+
if (resolution?.resolvedPath) {
|
|
219
|
+
absolutePath = resolution.resolvedPath;
|
|
220
|
+
try {
|
|
221
|
+
const fileStat = await stat(absolutePath);
|
|
222
|
+
isGhost = fileStat.size === 0;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
const code = error instanceof Error && 'code' in error ? String(error.code) : undefined;
|
|
226
|
+
if (code !== 'ENOENT') {
|
|
227
|
+
unresolvable.push({
|
|
228
|
+
specId: entry.id,
|
|
229
|
+
reason: `spec_path_unresolvable — code=${code ?? 'UNEXPECTED'}`,
|
|
230
|
+
});
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
isGhost = true;
|
|
180
234
|
}
|
|
181
235
|
}
|
|
182
|
-
|
|
183
|
-
|
|
236
|
+
else if (resolution?.failureCode === 'NOT_FOUND') {
|
|
237
|
+
absolutePath = resolve(projectPath, entry.specPath);
|
|
238
|
+
isGhost = true;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
unresolvable.push({
|
|
242
|
+
specId: entry.id,
|
|
243
|
+
reason: `spec_path_unresolvable — code=${resolution?.failureCode ?? 'UNEXPECTED'}`,
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
184
246
|
}
|
|
185
|
-
|
|
186
|
-
|
|
247
|
+
if (!isGhost) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const reason = `Store entry ${entry.id} references spec.md at ${absolutePath}, which is missing or empty on disk. Recreate the spec via create_spec or restore spec.md from git/backup.`;
|
|
251
|
+
ghosts.push({ specId: entry.id, specPath: absolutePath, reason });
|
|
187
252
|
if (alreadyQuarantined.has(entry.id)) {
|
|
188
253
|
return;
|
|
189
254
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
255
|
+
alreadyQuarantined.add(entry.id);
|
|
256
|
+
try {
|
|
257
|
+
await appendTransitionEvent({
|
|
258
|
+
projectId,
|
|
259
|
+
specId: entry.id,
|
|
260
|
+
eventType: 'ghost_spec_quarantined',
|
|
261
|
+
actor: 'sync_spec_state',
|
|
262
|
+
reason,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
alreadyQuarantined.delete(entry.id);
|
|
267
|
+
}
|
|
199
268
|
}));
|
|
200
|
-
return ghosts;
|
|
269
|
+
return { ghosts, unresolvable };
|
|
201
270
|
}
|
|
202
271
|
/**
|
|
203
272
|
* Startup sync: iterates all registered projects and calls syncSpecState for each.
|
|
@@ -93,6 +93,7 @@ export interface DurableJobRecord {
|
|
|
93
93
|
readonly error?: string;
|
|
94
94
|
readonly attempts: number;
|
|
95
95
|
readonly maxAttempts: number;
|
|
96
|
+
readonly restarts: number;
|
|
96
97
|
readonly cancelRequested: boolean;
|
|
97
98
|
readonly leaseOwner?: string;
|
|
98
99
|
readonly leaseExpiresAt?: string;
|
|
@@ -440,6 +440,10 @@ export interface SyncSpecStateOptions {
|
|
|
440
440
|
/** When false, non-terminal drift is reported read-only instead of applied via handleUpdateStatus. */
|
|
441
441
|
applyTransitions?: boolean;
|
|
442
442
|
}
|
|
443
|
+
export interface SpecStoreListing {
|
|
444
|
+
specs: Spec[];
|
|
445
|
+
ghosts: Spec[];
|
|
446
|
+
}
|
|
443
447
|
/** Report produced by spec state synchronisation. */
|
|
444
448
|
export interface SyncReport {
|
|
445
449
|
synced: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planu/cli",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.8",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"verify:typescript-migration": "node scripts/verify-typescript-migration.mjs",
|
|
47
47
|
"test": "vitest run --maxWorkers=6",
|
|
48
48
|
"test:watch": "vitest",
|
|
49
|
-
"test:coverage": "vitest run --coverage --testTimeout=60000 --maxWorkers=
|
|
49
|
+
"test:coverage": "vitest run --coverage --testTimeout=60000 --maxWorkers=6",
|
|
50
50
|
"test:release-gate": "vitest run --exclude 'tests/integration/**'",
|
|
51
51
|
"test:pre-push-scripts": "PLANU_PRE_PUSH_SCRIPTS_LANE=1 vitest run tests/scripts --reporter=dot",
|
|
52
52
|
"test:integration": "vitest run tests/integration",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"check": "pnpm typecheck && pnpm lint:gate && pnpm format:check && pnpm check:destructive-ops && pnpm check:commercial-surfaces && pnpm check:tool-registration && pnpm check:public-privacy && pnpm check:website-proof && pnpm check:donation-assets && pnpm check:website-public-assets",
|
|
58
58
|
"check:destructive-ops": "bash scripts/check-no-automatic-destructive-ops.sh",
|
|
59
59
|
"check:strict": "pnpm check && pnpm generate:host-tool-registry -- --check && pnpm check:environment-schema && pnpm audit:hardcodes && pnpm audit:deadcode && pnpm audit:circular && pnpm audit:types && pnpm audit:security && pnpm audit:i18n",
|
|
60
|
-
"check:preflight": "pnpm typecheck &&
|
|
60
|
+
"check:preflight": "pnpm typecheck && node scripts/check-preflight.mjs && bash scripts/release-preflight.sh --run-and-write && bash scripts/release-preflight.sh --verify",
|
|
61
61
|
"check:reliability": "node scripts/check-reliability-policies.mjs",
|
|
62
62
|
"check:environment-schema": "node scripts/check-environment-schema.mjs",
|
|
63
63
|
"test:contracts": "vitest run tests/contracts tests/integration/package-consumer-hono.test.ts",
|
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.
|
|
5
|
+
"version": "5.7.8",
|
|
6
6
|
"icon": "assets/plugin/icon.svg",
|
|
7
7
|
"command": ["npx", "@planu/cli@latest"],
|
|
8
8
|
"packageName": "@planu/cli",
|