peaks-loop 4.1.26 → 4.2.1
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +160 -0
- package/contracts/readonly-argv-whitelist.json +116 -0
- package/dist/cli/commands/code-auto-compact-command.js +15 -3
- package/dist/cli/commands/core/session-info-command.js +3 -4
- package/dist/cli/commands/core/skill-presence-housekeeping-commands.js +7 -1
- package/dist/cli/commands/dashboard-long-run.js +2 -1
- package/dist/cli/commands/doctor/invoke-from-code.js +6 -1
- package/dist/cli/commands/job-state-root.js +4 -2
- package/dist/cli/commands/lease-metrics-commands-support.js +2 -1
- package/dist/cli/commands/loop-eval-capture-index.js +2 -1
- package/dist/cli/commands/loop-eval-eval-command.js +2 -1
- package/dist/cli/commands/mut-commands-helpers.d.ts +9 -28
- package/dist/cli/commands/mut-commands-helpers.js +53 -80
- package/dist/cli/commands/mut-failure-diagnostic.d.ts +48 -0
- package/dist/cli/commands/mut-failure-diagnostic.js +147 -0
- package/dist/cli/commands/outer-cache-commands.js +3 -2
- package/dist/cli/commands/playwright-session-store.js +5 -2
- package/dist/cli/commands/project-context-command.js +7 -2
- package/dist/cli/commands/qa-archive-screenshots-command.js +2 -1
- package/dist/cli/commands/request-transition-preflight.js +2 -2
- package/dist/cli/commands/slice-decompose-artifacts.js +10 -2
- package/dist/cli/commands/verdict-aggregate-command.js +4 -3
- package/dist/cli/commands/workspace/init-actions.js +5 -0
- package/dist/cli/commands/workspace/init-context.js +1 -0
- package/dist/cli/commands/worktree-lease-effects.d.ts +13 -0
- package/dist/cli/commands/worktree-lease-effects.js +23 -0
- package/dist/cli/commands/worktree-lease-gc-command.d.ts +3 -4
- package/dist/cli/commands/worktree-lease-gc-command.js +59 -58
- package/dist/cli/commands/worktree-lease-git.d.ts +13 -18
- package/dist/cli/commands/worktree-lease-git.js +21 -44
- package/dist/cli/commands/worktree-lease-list-command.js +1 -1
- package/dist/cli/commands/worktree-lease-load.d.ts +19 -7
- package/dist/cli/commands/worktree-lease-load.js +37 -9
- package/dist/cli/commands/worktree-lease-release-command.d.ts +4 -5
- package/dist/cli/commands/worktree-lease-release-command.js +60 -47
- package/dist/cli/commands/worktree-lease-renew-command.d.ts +5 -4
- package/dist/cli/commands/worktree-lease-renew-command.js +36 -32
- package/dist/cli/commands/worktree-lease-session.d.ts +7 -5
- package/dist/cli/commands/worktree-lease-session.js +9 -6
- package/dist/cli/commands/worktree-lease-spawn-command.d.ts +4 -3
- package/dist/cli/commands/worktree-lease-spawn-command.js +38 -46
- package/dist/cli/commands/worktree-lease-status-command.js +1 -1
- package/dist/cli/commands/worktree-lease-store.d.ts +3 -2
- package/dist/cli/commands/worktree-lease-store.js +3 -2
- package/dist/services/artifacts/prerequisite-path-resolver.js +5 -1
- package/dist/services/audit/enforcers/lint-output-style.js +5 -1
- package/dist/services/audit/enforcers/lint-rd-handoff-coverage.js +9 -4
- package/dist/services/audit-independent/handoff-missing-refusal.js +16 -1
- package/dist/services/audit-independent/judged-declaration-check.js +5 -1
- package/dist/services/audit-independent/perf-audit-service.d.ts +2 -4
- package/dist/services/audit-independent/perf-audit-service.js +4 -5
- package/dist/services/audit-independent/security-audit-artifact.js +5 -1
- package/dist/services/capability-audit-service/runner.js +4 -1
- package/dist/services/capability-baseline/store.js +2 -1
- package/dist/services/capability-guard-runner/contracts/J05.js +4 -2
- package/dist/services/capability-guard-runner/contracts/J12.js +2 -2
- package/dist/services/code/auto-compact-artifacts.js +42 -10
- package/dist/services/code/auto-compact-checkpoint-content.d.ts +49 -0
- package/dist/services/code/auto-compact-checkpoint-content.js +157 -0
- package/dist/services/code/auto-compact-envelopes.d.ts +11 -2
- package/dist/services/code/auto-compact-envelopes.js +18 -4
- package/dist/services/code/auto-compact-orchestrator.js +1 -1
- package/dist/services/code/emit-handoff.js +8 -1
- package/dist/services/code/job-shape-decision.js +13 -2
- package/dist/services/code/job-shape-provisional.js +9 -1
- package/dist/services/code/post-compact-detector.js +9 -1
- package/dist/services/code/step-08-session-readers.js +14 -5
- package/dist/services/compact/request-transition-hook.js +6 -1
- package/dist/services/compact/suggest-service.js +8 -1
- package/dist/services/context/post-compact-reinjection.js +15 -14
- package/dist/services/context/spillover-store.js +2 -1
- package/dist/services/dispatch/contract-store.d.ts +11 -4
- package/dist/services/dispatch/contract-store.js +21 -8
- package/dist/services/doctor/doctor-service/checks/workspace-layout.js +8 -3
- package/dist/services/doctor/doctor-service/index.js +2 -1
- package/dist/services/final-review/final-review-evidence-collect.js +5 -1
- package/dist/services/fresh-context/fresh-context-block.js +5 -1
- package/dist/services/hooks/auto-compact-hook-install.d.ts +13 -3
- package/dist/services/hooks/auto-compact-hook-install.js +13 -3
- package/dist/services/hooks/worktree-authorization-gate.d.ts +1 -1
- package/dist/services/hooks/worktree-authorization-gate.js +14 -11
- package/dist/services/loop/evaluator-dispatcher.js +7 -7
- package/dist/services/loop/monotonic-runner.js +2 -1
- package/dist/services/loop/spec-service.js +10 -9
- package/dist/services/mcp/context-tool.d.ts +3 -0
- package/dist/services/mcp/context-tool.js +135 -0
- package/dist/services/mcp/surface.js +7 -1
- package/dist/services/mcp/tools.js +3 -1
- package/dist/services/memory/project-context-service.d.ts +10 -1
- package/dist/services/memory/project-context-service.js +13 -6
- package/dist/services/observability/jsonl-store.js +4 -1
- package/dist/services/polyrepo/polyrepo-dispatcher.js +5 -1
- package/dist/services/prd/prd-blocks-checker.js +12 -6
- package/dist/services/prd/project-scan-body-tables.d.ts +33 -0
- package/dist/services/prd/project-scan-body-tables.js +185 -0
- package/dist/services/prd/project-scan-bootstrap-service.d.ts +16 -3
- package/dist/services/prd/project-scan-bootstrap-service.js +127 -231
- package/dist/services/prd/project-scan-content.d.ts +24 -0
- package/dist/services/prd/project-scan-content.js +207 -0
- package/dist/services/prd/project-scan-existing-state.d.ts +22 -0
- package/dist/services/prd/project-scan-existing-state.js +61 -0
- package/dist/services/prd/project-scan-field-refresh.d.ts +87 -0
- package/dist/services/prd/project-scan-field-refresh.js +217 -0
- package/dist/services/prd/project-scan-frontmatter.d.ts +32 -0
- package/dist/services/prd/project-scan-frontmatter.js +34 -0
- package/dist/services/prd/project-scan-library-versions.d.ts +60 -0
- package/dist/services/prd/project-scan-library-versions.js +135 -0
- package/dist/services/prd/project-scan-techstack.d.ts +34 -0
- package/dist/services/prd/project-scan-techstack.js +167 -0
- package/dist/services/reviewer/reviewer-artifacts.js +2 -1
- package/dist/services/sc/sc-service.js +8 -8
- package/dist/services/scan/api-diff-recorded.d.ts +2 -3
- package/dist/services/scan/api-diff-recorded.js +5 -5
- package/dist/services/session/binding-status-service.js +2 -1
- package/dist/services/session/binding-store.js +6 -7
- package/dist/services/session/caller-binding-service.js +5 -2
- package/dist/services/session/getSessionDir.d.ts +4 -0
- package/dist/services/session/getSessionDir.js +38 -13
- package/dist/services/session/session-binding-bridge.d.ts +3 -6
- package/dist/services/session/session-binding-bridge.js +13 -13
- package/dist/services/session/session-checkpoint-service.js +22 -3
- package/dist/services/session/session-manager.js +16 -20
- package/dist/services/skills/presence-lease-resolver.js +3 -2
- package/dist/services/skills/presence-lease-service.js +7 -15
- package/dist/services/skills/presence-lease-store.d.ts +26 -0
- package/dist/services/skills/presence-lease-store.js +60 -5
- package/dist/services/skills/skill-presence-service.js +13 -20
- package/dist/services/skills/skill-statusline-model.js +7 -2
- package/dist/services/slice/slice-archive-service.js +4 -1
- package/dist/services/standards/missing-standards-detector.js +2 -1
- package/dist/services/test-cache/test-cache-service.js +2 -1
- package/dist/services/workflow/artifact-paths.js +6 -2
- package/dist/services/workflow/pipeline-verify-gate-support.d.ts +1 -1
- package/dist/services/workflow/pipeline-verify-gate-support.js +23 -11
- package/dist/services/workflow/workflow-graph-store-helpers.js +12 -3
- package/dist/services/workflow/workflow-state-store.js +11 -4
- package/dist/services/workspace/migrate-1-4-1-service.js +2 -1
- package/dist/services/workspace/reconcile-migrate.js +2 -2
- package/dist/services/workspace/reconcile-service.d.ts +4 -6
- package/dist/services/workspace/reconcile-service.js +11 -11
- package/dist/services/workspace/workspace-service.js +5 -5
- package/dist/services/worktree/dispatch-provenance.d.ts +1 -1
- package/dist/services/worktree/dispatch-provenance.js +9 -2
- package/dist/services/worktree/host-worktree-reconciler.d.ts +1 -1
- package/dist/services/worktree/host-worktree-reconciler.js +5 -3
- package/dist/shared/runtime-root.js +6 -1
- package/package.json +6 -5
- package/skills/peaks-code/SKILL.md +1 -1
- package/skills/peaks-code/references/project-scan-checklist.md +3 -1
- package/skills/peaks-mut/SKILL.md +6 -2
- package/dist/services/worktree/git-worktree-parser.d.ts +0 -8
- package/dist/services/worktree/git-worktree-parser.js +0 -55
- package/dist/services/worktree/worktree-lease-types.d.ts +0 -52
- package/dist/services/worktree/worktree-lease-types.js +0 -9
- package/dist/services/worktree/worktree-lease.d.ts +0 -116
- package/dist/services/worktree/worktree-lease.js +0 -252
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `peaks worktree gc` — sweep released/expired leases.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
4
|
+
* The sweep is `runGc` from `peaks-loop-workspace-runtime`; this file owns the
|
|
5
|
+
* host policy, the effects, the per-lease metric emit and the envelope. The
|
|
6
6
|
* `--lease-id` / `--dry-run` semantics, the expired-active transition, the
|
|
7
|
-
* best-effort git removal + prune
|
|
8
|
-
* ok/fail envelopes are unchanged.
|
|
7
|
+
* best-effort git removal + prune and the ok/fail envelopes are unchanged.
|
|
9
8
|
*/
|
|
10
9
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
10
|
+
import { defaultStateRoot, runGc } from 'peaks-loop-workspace-runtime';
|
|
11
11
|
import { addJsonOption, getErrorMessage, printResult } from '../cli-helpers.js';
|
|
12
|
-
import { atomicWriteJson } from '../../services/ide/shared/atomic-json.js';
|
|
13
12
|
import { emitLeaseEvent } from '../../services/observability/observability-service.js';
|
|
14
|
-
import {
|
|
15
|
-
import { pruneWorktreesBestEffort, removeWorktreeBestEffort } from './worktree-lease-git.js';
|
|
13
|
+
import { leaseEffects } from './worktree-lease-effects.js';
|
|
16
14
|
import { loadLeaseStore, malformedLeaseWarnings } from './worktree-lease-store.js';
|
|
17
|
-
import {
|
|
15
|
+
import { resolveProjectRoot, resolveSessionId } from './worktree-lease-session.js';
|
|
18
16
|
const GC_DESCRIPTION = "Sweep released/expired leases: remove their git worktree (if still attached), prune git's " +
|
|
19
17
|
'worktree references, and mark the lease as "gc". With --lease-id <id>, only that lease is ' +
|
|
20
18
|
"considered. With --dry-run, report what would be gc'd without mutating. Expired-active " +
|
|
@@ -22,40 +20,6 @@ const GC_DESCRIPTION = "Sweep released/expired leases: remove their git worktree
|
|
|
22
20
|
'then their worktree is removed.';
|
|
23
21
|
const GC_LEASE_ID_DESCRIPTION = 'only consider this specific lease';
|
|
24
22
|
const GC_DRY_RUN_DESCRIPTION = "report what would be gc'd without mutating";
|
|
25
|
-
function sweepLease(ctx) {
|
|
26
|
-
const { lease, dryRun, now, projectRoot, sessionId } = ctx;
|
|
27
|
-
let prevStatus = lease.status;
|
|
28
|
-
let updated = lease;
|
|
29
|
-
// If the lease is still marked active but past expiresAt, transition to expired first.
|
|
30
|
-
if (lease.status === 'active' && lease.expiresAt <= now) {
|
|
31
|
-
updated = markExpired(lease);
|
|
32
|
-
prevStatus = 'active';
|
|
33
|
-
}
|
|
34
|
-
if (dryRun) {
|
|
35
|
-
return {
|
|
36
|
-
leaseId: lease.leaseId,
|
|
37
|
-
path: lease.path,
|
|
38
|
-
prevStatus,
|
|
39
|
-
gitWorktreeRemoveFailed: false
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// `git worktree remove --force` is best-effort — if the path is
|
|
43
|
-
// already gone we still mark the lease gc.
|
|
44
|
-
const gitWorktreeRemoveFailed = removeWorktreeBestEffort(projectRoot, updated.path);
|
|
45
|
-
pruneWorktreesBestEffort(projectRoot);
|
|
46
|
-
const finalLease = markGc(updated);
|
|
47
|
-
atomicWriteJson(leaseFilePath(joinPathSession(projectRoot, sessionId), lease.leaseId), finalLease);
|
|
48
|
-
// Part 4.A: emit gc metric (per swept lease).
|
|
49
|
-
emitLeaseEvent({
|
|
50
|
-
sessionId,
|
|
51
|
-
projectRoot,
|
|
52
|
-
kind: 'gc',
|
|
53
|
-
leaseId: lease.leaseId,
|
|
54
|
-
rid: lease.rid,
|
|
55
|
-
role: lease.role
|
|
56
|
-
});
|
|
57
|
-
return { leaseId: lease.leaseId, path: lease.path, prevStatus, gitWorktreeRemoveFailed };
|
|
58
|
-
}
|
|
59
23
|
function printGcStoreMissing(io, options, ctx) {
|
|
60
24
|
const { sessionId, projectRoot, storeDir } = ctx;
|
|
61
25
|
printResult(io, ok('worktree.gc', { sessionId, projectRoot, swept: 0, storeMissing: true }, [], [`No lease store at ${storeDir}; nothing to gc.`]), options.json);
|
|
@@ -75,30 +39,67 @@ function printGcFailed(io, options, err, sessionId) {
|
|
|
75
39
|
]), options.json);
|
|
76
40
|
process.exitCode = 1;
|
|
77
41
|
}
|
|
78
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The rid/role the gc metric row needs, keyed by lease id. The package's sweep
|
|
44
|
+
* result carries the id and path but not the lease itself, so the store is
|
|
45
|
+
* read once more here — the single directory scan this command made before.
|
|
46
|
+
*/
|
|
47
|
+
function leaseIdentity(projectRoot, sessionId) {
|
|
48
|
+
const listed = loadLeaseStore(projectRoot, sessionId);
|
|
49
|
+
const leases = listed.result.kind === 'ok' ? listed.result.leases : [];
|
|
50
|
+
return new Map(leases.map((lease) => [lease.leaseId, { rid: lease.rid, role: lease.role }]));
|
|
51
|
+
}
|
|
52
|
+
/** Part 4.A: one gc metric per swept lease; a dry run emits nothing. */
|
|
53
|
+
function emitGcMetrics(result, ctx) {
|
|
54
|
+
if (result.kind !== 'ok' || result.dryRun)
|
|
55
|
+
return;
|
|
56
|
+
for (const entry of result.swept) {
|
|
57
|
+
const identity = ctx.identity.get(entry.leaseId);
|
|
58
|
+
// A swept lease came from the store just read, so a miss only happens if
|
|
59
|
+
// the store changed underneath us; never emit a row with an invented rid.
|
|
60
|
+
if (identity === undefined)
|
|
61
|
+
continue;
|
|
62
|
+
emitLeaseEvent({
|
|
63
|
+
sessionId: ctx.sessionId,
|
|
64
|
+
projectRoot: ctx.projectRoot,
|
|
65
|
+
kind: 'gc',
|
|
66
|
+
leaseId: entry.leaseId,
|
|
67
|
+
rid: identity.rid,
|
|
68
|
+
role: identity.role
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function runGcAction(options, io) {
|
|
79
73
|
const projectRoot = resolveProjectRoot(options);
|
|
80
74
|
const sessionId = resolveSessionId(options, projectRoot);
|
|
81
75
|
try {
|
|
82
|
-
|
|
76
|
+
// Read BEFORE the sweep, as before: a store that cannot be read fails the
|
|
77
|
+
// command without having mutated anything.
|
|
78
|
+
const identity = leaseIdentity(projectRoot, sessionId);
|
|
79
|
+
const result = runGc({
|
|
80
|
+
projectRoot,
|
|
81
|
+
stateRoot: defaultStateRoot(projectRoot),
|
|
82
|
+
sessionId,
|
|
83
|
+
// A falsy `--lease-id` means "every lease", as before.
|
|
84
|
+
...(options.leaseId ? { leaseId: options.leaseId } : {}),
|
|
85
|
+
dryRun: options.dryRun === true
|
|
86
|
+
}, leaseEffects(Date.now()));
|
|
83
87
|
if (result.kind === 'store-missing') {
|
|
84
|
-
printGcStoreMissing(io, options, { sessionId, projectRoot, storeDir });
|
|
88
|
+
printGcStoreMissing(io, options, { sessionId, projectRoot, storeDir: result.storeDir });
|
|
85
89
|
return;
|
|
86
90
|
}
|
|
87
|
-
|
|
88
|
-
const candidates = result.leases
|
|
89
|
-
.filter((l) => (options.leaseId ? l.leaseId === options.leaseId : true))
|
|
90
|
-
.filter((l) => isLeaseGcEligible(l, now));
|
|
91
|
-
const dryRun = options.dryRun === true;
|
|
92
|
-
const swept = [];
|
|
93
|
-
for (const lease of candidates) {
|
|
94
|
-
swept.push(sweepLease({ lease, dryRun, now, projectRoot, sessionId }));
|
|
95
|
-
}
|
|
91
|
+
emitGcMetrics(result, { projectRoot, sessionId, identity });
|
|
96
92
|
printGcOk(io, options, {
|
|
97
93
|
sessionId,
|
|
98
94
|
projectRoot,
|
|
99
|
-
dryRun,
|
|
100
|
-
candidates: candidates
|
|
101
|
-
swept
|
|
95
|
+
dryRun: result.dryRun,
|
|
96
|
+
candidates: result.candidates,
|
|
97
|
+
swept: result.swept.map((entry) => ({
|
|
98
|
+
leaseId: entry.leaseId,
|
|
99
|
+
path: entry.path,
|
|
100
|
+
prevStatus: entry.previousStatus,
|
|
101
|
+
gitWorktreeRemoveFailed: entry.gitWorktreeRemoveFailed
|
|
102
|
+
})),
|
|
102
103
|
errors: result.errors
|
|
103
104
|
});
|
|
104
105
|
}
|
|
@@ -113,5 +114,5 @@ export function registerWorktreeLeaseGcCommand(auth, io) {
|
|
|
113
114
|
.option('--lease-id <id>', GC_LEASE_ID_DESCRIPTION)
|
|
114
115
|
.option('--dry-run', GC_DRY_RUN_DESCRIPTION)
|
|
115
116
|
.option('--session <sid>', 'override session id')
|
|
116
|
-
.option('--project <path>', 'project root (default: findProjectRoot(cwd))')).action((options) =>
|
|
117
|
+
.option('--project <path>', 'project root (default: findProjectRoot(cwd))')).action((options) => runGcAction(options, io));
|
|
117
118
|
}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The peaks-loop `RunGit` implementation handed to the workspace-runtime
|
|
3
|
+
* package.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* `git worktree remove --force` is best-effort: when the path is already
|
|
11
|
-
* pruned the caller still marks the lease released / gc. Returns whether
|
|
12
|
-
* the git invocation failed.
|
|
5
|
+
* `execFileSync('git', argv, …)`, not a shell command string. The package's
|
|
6
|
+
* `RunGit` contract is an argv array, and the shell is what used to reinterpret
|
|
7
|
+
* it: a path or branch containing `"`, `$(…)` or a backtick reached the shell
|
|
8
|
+
* as syntax because this module quoted the argument by hand. No hand-rolled
|
|
9
|
+
* quoting helper is provably correct for both `cmd.exe` and POSIX `sh`, so the
|
|
10
|
+
* shell is gone rather than escaped.
|
|
13
11
|
*
|
|
14
|
-
*
|
|
15
|
-
* guard
|
|
16
|
-
*
|
|
17
|
-
* `as const`, frozen, `let`, or imported from another file — measured: both
|
|
18
|
-
* call sites below were reported while the shared constant was `as const`.
|
|
12
|
+
* The `{ cwd, stdio, encoding, windowsHide }` object literal is spelled at the
|
|
13
|
+
* call site on purpose: the guard in `tests/unit/spawn-windows-hide-guard.test.ts`
|
|
14
|
+
* resolves an inline object literal, not one imported or declared `as const`.
|
|
19
15
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export declare function pruneWorktreesBestEffort(projectRoot: string): void;
|
|
16
|
+
import type { RunGit } from 'peaks-loop-workspace-runtime';
|
|
17
|
+
export declare const runGitCli: RunGit;
|
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The peaks-loop `RunGit` implementation handed to the workspace-runtime
|
|
3
|
+
* package.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* `git worktree remove --force` is best-effort: when the path is already
|
|
12
|
-
* pruned the caller still marks the lease released / gc. Returns whether
|
|
13
|
-
* the git invocation failed.
|
|
5
|
+
* `execFileSync('git', argv, …)`, not a shell command string. The package's
|
|
6
|
+
* `RunGit` contract is an argv array, and the shell is what used to reinterpret
|
|
7
|
+
* it: a path or branch containing `"`, `$(…)` or a backtick reached the shell
|
|
8
|
+
* as syntax because this module quoted the argument by hand. No hand-rolled
|
|
9
|
+
* quoting helper is provably correct for both `cmd.exe` and POSIX `sh`, so the
|
|
10
|
+
* shell is gone rather than escaped.
|
|
14
11
|
*
|
|
15
|
-
*
|
|
16
|
-
* guard
|
|
17
|
-
*
|
|
18
|
-
* `as const`, frozen, `let`, or imported from another file — measured: both
|
|
19
|
-
* call sites below were reported while the shared constant was `as const`.
|
|
12
|
+
* The `{ cwd, stdio, encoding, windowsHide }` object literal is spelled at the
|
|
13
|
+
* call site on purpose: the guard in `tests/unit/spawn-windows-hide-guard.test.ts`
|
|
14
|
+
* resolves an inline object literal, not one imported or declared `as const`.
|
|
20
15
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
catch {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/** `git worktree prune` clears stale admin entries. Best-effort. */
|
|
36
|
-
export function pruneWorktreesBestEffort(projectRoot) {
|
|
37
|
-
try {
|
|
38
|
-
execSync('git worktree prune', {
|
|
39
|
-
cwd: projectRoot,
|
|
40
|
-
stdio: 'pipe',
|
|
41
|
-
encoding: 'utf8',
|
|
42
|
-
windowsHide: true
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// ignore — prune is idempotent
|
|
47
|
-
}
|
|
48
|
-
}
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
export const runGitCli = (argv, opts) => {
|
|
18
|
+
const stdout = execFileSync('git', argv, {
|
|
19
|
+
cwd: opts.cwd,
|
|
20
|
+
stdio: 'pipe',
|
|
21
|
+
encoding: 'utf8',
|
|
22
|
+
windowsHide: true
|
|
23
|
+
});
|
|
24
|
+
return { ok: true, stdout };
|
|
25
|
+
};
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* ok/fail envelopes are unchanged.
|
|
9
9
|
*/
|
|
10
10
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
11
|
+
import { isLeaseActive } from 'peaks-loop-workspace-runtime';
|
|
11
12
|
import { addJsonOption, getErrorMessage, printResult } from '../cli-helpers.js';
|
|
12
|
-
import { isLeaseActive } from '../../services/worktree/worktree-lease.js';
|
|
13
13
|
import { loadLeaseStore, malformedLeaseWarnings } from './worktree-lease-store.js';
|
|
14
14
|
import { resolveProjectRoot, resolveSessionId } from './worktree-lease-session.js';
|
|
15
15
|
const LIST_DESCRIPTION = "List every lease under the current session's lease store. " +
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared single-lease
|
|
2
|
+
* Shared single-lease failure envelopes for the read-by-lease-id commands
|
|
3
3
|
* (`release`, `renew`, `lease-status`).
|
|
4
4
|
*
|
|
5
|
-
* All
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* All of them surface the same two failure shapes — a missing lease file
|
|
6
|
+
* (`LEASE_NOT_FOUND`) and an unparseable one (`LEASE_FILE_INVALID`) — differing
|
|
7
|
+
* only in the envelope `command` string and the two hint lines. Both are
|
|
8
|
+
* parameters here. The message text, the `{ leaseId, file }` data payload and
|
|
9
|
+
* the caller's `process.exitCode = 1` are unchanged.
|
|
10
|
+
*
|
|
11
|
+
* `printLeaseFileFailure` takes the failure record the workspace-runtime
|
|
12
|
+
* package's actions return, so `release` and `renew` keep this exact envelope
|
|
13
|
+
* even though the load now happens inside the package.
|
|
10
14
|
*/
|
|
15
|
+
import { type LeaseFileFailure, type WorktreeLease } from 'peaks-loop-workspace-runtime';
|
|
11
16
|
import { type ProgramIO } from '../cli-helpers.js';
|
|
12
|
-
import { type WorktreeLease } from '../../services/worktree/worktree-lease.js';
|
|
13
17
|
/** The option surface the loader reads: the lease id and `--json`. */
|
|
14
18
|
export interface LeaseIdOptions {
|
|
15
19
|
leaseId: string;
|
|
@@ -34,4 +38,12 @@ export type LeaseLoadResult = {
|
|
|
34
38
|
stop: false;
|
|
35
39
|
lease: WorktreeLease;
|
|
36
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Print the envelope for a lease-file failure and report that the caller must
|
|
43
|
+
* stop: `release` and `renew` both set `process.exitCode = 1` on it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function stopOnLeaseFileFailure(io: ProgramIO, options: LeaseIdOptions, request: {
|
|
46
|
+
command: string;
|
|
47
|
+
hints: LeaseLoadHints;
|
|
48
|
+
}, failure: LeaseFileFailure): true;
|
|
37
49
|
export declare function loadLeaseOrStop(io: ProgramIO, options: LeaseIdOptions, request: LeaseLoadRequest): LeaseLoadResult;
|
|
@@ -1,28 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared single-lease
|
|
2
|
+
* Shared single-lease failure envelopes for the read-by-lease-id commands
|
|
3
3
|
* (`release`, `renew`, `lease-status`).
|
|
4
4
|
*
|
|
5
|
-
* All
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* All of them surface the same two failure shapes — a missing lease file
|
|
6
|
+
* (`LEASE_NOT_FOUND`) and an unparseable one (`LEASE_FILE_INVALID`) — differing
|
|
7
|
+
* only in the envelope `command` string and the two hint lines. Both are
|
|
8
|
+
* parameters here. The message text, the `{ leaseId, file }` data payload and
|
|
9
|
+
* the caller's `process.exitCode = 1` are unchanged.
|
|
10
|
+
*
|
|
11
|
+
* `printLeaseFileFailure` takes the failure record the workspace-runtime
|
|
12
|
+
* package's actions return, so `release` and `renew` keep this exact envelope
|
|
13
|
+
* even though the load now happens inside the package.
|
|
10
14
|
*/
|
|
11
15
|
import { fail } from 'peaks-loop-shared/result';
|
|
12
16
|
import { existsSync, readFileSync as readFileSyncNode } from 'node:fs';
|
|
17
|
+
import { deserializeLease } from 'peaks-loop-workspace-runtime';
|
|
13
18
|
import { getErrorMessage, printResult } from '../cli-helpers.js';
|
|
14
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Print the envelope for a lease-file failure and report that the caller must
|
|
21
|
+
* stop: `release` and `renew` both set `process.exitCode = 1` on it.
|
|
22
|
+
*/
|
|
23
|
+
export function stopOnLeaseFileFailure(io, options, request, failure) {
|
|
24
|
+
printLeaseFileFailure(io, options, request, failure);
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
/** Print the envelope for a missing or malformed lease file. */
|
|
29
|
+
function printLeaseFileFailure(io, options, request, failure) {
|
|
30
|
+
const { command, hints } = request;
|
|
31
|
+
if (failure.kind === 'lease-not-found') {
|
|
32
|
+
printResult(io, fail(command, 'LEASE_NOT_FOUND', `no lease on disk at ${failure.file}`, { leaseId: options.leaseId, file: failure.file }, hints.missing), options.json);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
printResult(io, fail(command, 'LEASE_FILE_INVALID', failure.error, { leaseId: options.leaseId, file: failure.file }, hints.invalid), options.json);
|
|
36
|
+
}
|
|
15
37
|
export function loadLeaseOrStop(io, options, request) {
|
|
16
38
|
const { command, file, hints } = request;
|
|
17
39
|
if (!existsSync(file)) {
|
|
18
|
-
|
|
40
|
+
printLeaseFileFailure(io, options, request, { kind: 'lease-not-found', file });
|
|
19
41
|
return { stop: true };
|
|
20
42
|
}
|
|
21
43
|
try {
|
|
44
|
+
// Re-uses the package's deserializer so a malformed file is rejected by
|
|
45
|
+
// the same validator the lifecycle actions apply.
|
|
22
46
|
return { stop: false, lease: deserializeLease(readFileSyncNode(file, 'utf8')) };
|
|
23
47
|
}
|
|
24
48
|
catch (error) {
|
|
25
|
-
|
|
49
|
+
printLeaseFileFailure(io, options, { command, hints }, {
|
|
50
|
+
kind: 'lease-invalid',
|
|
51
|
+
file,
|
|
52
|
+
error: getErrorMessage(error)
|
|
53
|
+
});
|
|
26
54
|
return { stop: true };
|
|
27
55
|
}
|
|
28
56
|
}
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
* `peaks worktree release` — transition a lease to 'released' and run
|
|
3
3
|
* `git worktree remove`.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the ok/fail envelopes are unchanged.
|
|
5
|
+
* The action body is `runRelease` from `peaks-loop-workspace-runtime`; this
|
|
6
|
+
* file owns the host policy, the effects and the envelope. The idempotent
|
|
7
|
+
* already-released branch, the best-effort git removal, the lease-file failure
|
|
8
|
+
* envelopes and the metric emit are unchanged.
|
|
10
9
|
*/
|
|
11
10
|
import type { Command } from 'commander';
|
|
12
11
|
import { type ProgramIO } from '../cli-helpers.js';
|
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
* `peaks worktree release` — transition a lease to 'released' and run
|
|
3
3
|
* `git worktree remove`.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the ok/fail envelopes are unchanged.
|
|
5
|
+
* The action body is `runRelease` from `peaks-loop-workspace-runtime`; this
|
|
6
|
+
* file owns the host policy, the effects and the envelope. The idempotent
|
|
7
|
+
* already-released branch, the best-effort git removal, the lease-file failure
|
|
8
|
+
* envelopes and the metric emit are unchanged.
|
|
10
9
|
*/
|
|
11
10
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
11
|
+
import { defaultStateRoot, runRelease } from 'peaks-loop-workspace-runtime';
|
|
12
12
|
import { addJsonOption, getErrorMessage, printResult } from '../cli-helpers.js';
|
|
13
|
-
import { atomicWriteJson } from '../../services/ide/shared/atomic-json.js';
|
|
14
13
|
import { emitLeaseEvent } from '../../services/observability/observability-service.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { joinPathSession, resolveProjectRoot, resolveSessionId } from './worktree-lease-session.js';
|
|
14
|
+
import { leaseEffects } from './worktree-lease-effects.js';
|
|
15
|
+
import { stopOnLeaseFileFailure } from './worktree-lease-load.js';
|
|
16
|
+
import { resolveProjectRoot, resolveSessionId } from './worktree-lease-session.js';
|
|
19
17
|
const RELEASE_DESCRIPTION = 'Transition a lease to released and run `git worktree remove`. Idempotent on already-released leases.';
|
|
20
18
|
const RELEASE_MISSING_HINTS = [
|
|
21
19
|
'Run `peaks worktree list` to inspect active leases.',
|
|
@@ -47,48 +45,63 @@ function printReleaseFailed(io, options, error, sessionId) {
|
|
|
47
45
|
printResult(io, fail('worktree.release', 'RELEASE_FAILED', getErrorMessage(error), { leaseId: options.leaseId, sessionId }, ['Verify the lease id and re-run.', 'If the lease was never spawned, no-op.']), options.json);
|
|
48
46
|
process.exitCode = 1;
|
|
49
47
|
}
|
|
50
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The success tail: the release metric, then the envelope.
|
|
50
|
+
* Part 4.A: the manual path emits here; auto-release is recorded in
|
|
51
|
+
* dispatch-record-writer's tryAutoReleaseLease.
|
|
52
|
+
*/
|
|
53
|
+
function finishRelease(io, options, ctx) {
|
|
54
|
+
const { lease, released, sessionId, projectRoot, gitWorktreeRemoveFailed } = ctx;
|
|
55
|
+
emitLeaseEvent({
|
|
56
|
+
sessionId,
|
|
57
|
+
projectRoot,
|
|
58
|
+
kind: 'release',
|
|
59
|
+
leaseId: released.leaseId,
|
|
60
|
+
rid: released.rid,
|
|
61
|
+
role: released.role
|
|
62
|
+
});
|
|
63
|
+
printReleaseDone(io, options, {
|
|
64
|
+
lease,
|
|
65
|
+
released,
|
|
66
|
+
sessionId,
|
|
67
|
+
projectRoot,
|
|
68
|
+
gitWorktreeRemoveFailed
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function runReleaseAction(options, io) {
|
|
51
72
|
const projectRoot = resolveProjectRoot(options);
|
|
52
73
|
const sessionId = resolveSessionId(options, projectRoot);
|
|
53
74
|
try {
|
|
54
|
-
const
|
|
55
|
-
const loaded = loadLeaseOrStop(io, options, {
|
|
56
|
-
command: 'worktree.release',
|
|
57
|
-
file,
|
|
58
|
-
hints: { missing: RELEASE_MISSING_HINTS, invalid: RELEASE_INVALID_HINTS }
|
|
59
|
-
});
|
|
60
|
-
if (loaded.stop) {
|
|
61
|
-
process.exitCode = 1;
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const lease = loaded.lease;
|
|
65
|
-
if (lease.status === 'released') {
|
|
66
|
-
printReleaseAlreadyReleased(io, options, { lease, sessionId, projectRoot });
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
// Run `git worktree remove` from the project root. If the path is
|
|
70
|
-
// missing on disk (e.g. manually pruned), this fails; we still
|
|
71
|
-
// update the lease state so the L2 hook (Part 2) treats it as
|
|
72
|
-
// released.
|
|
73
|
-
const gitWorktreeRemoveFailed = removeWorktreeBestEffort(projectRoot, lease.path);
|
|
74
|
-
const released = markReleased(lease);
|
|
75
|
-
atomicWriteJson(file, released);
|
|
76
|
-
// Part 4.A: emit release metric (manual path; auto-release is
|
|
77
|
-
// recorded in dispatch-record-writer's tryAutoReleaseLease).
|
|
78
|
-
emitLeaseEvent({
|
|
79
|
-
sessionId,
|
|
75
|
+
const result = runRelease({
|
|
80
76
|
projectRoot,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
lease
|
|
88
|
-
|
|
77
|
+
stateRoot: defaultStateRoot(projectRoot),
|
|
78
|
+
sessionId,
|
|
79
|
+
leaseId: options.leaseId
|
|
80
|
+
}, leaseEffects(Date.now()));
|
|
81
|
+
switch (result.kind) {
|
|
82
|
+
case 'lease-not-found':
|
|
83
|
+
case 'lease-invalid':
|
|
84
|
+
stopOnLeaseFileFailure(io, options, {
|
|
85
|
+
command: 'worktree.release',
|
|
86
|
+
hints: { missing: RELEASE_MISSING_HINTS, invalid: RELEASE_INVALID_HINTS }
|
|
87
|
+
}, result);
|
|
88
|
+
return;
|
|
89
|
+
case 'already-released':
|
|
90
|
+
printReleaseAlreadyReleased(io, options, {
|
|
91
|
+
lease: result.lease,
|
|
92
|
+
sessionId,
|
|
93
|
+
projectRoot
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
case 'ok':
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
finishRelease(io, options, {
|
|
100
|
+
lease: result.previous,
|
|
101
|
+
released: result.lease,
|
|
89
102
|
sessionId,
|
|
90
103
|
projectRoot,
|
|
91
|
-
gitWorktreeRemoveFailed
|
|
104
|
+
gitWorktreeRemoveFailed: result.gitWorktreeRemoveFailed
|
|
92
105
|
});
|
|
93
106
|
}
|
|
94
107
|
catch (error) {
|
|
@@ -101,5 +114,5 @@ export function registerWorktreeLeaseReleaseCommand(auth, io) {
|
|
|
101
114
|
.description(RELEASE_DESCRIPTION)
|
|
102
115
|
.requiredOption('--lease-id <id>', 'lease id returned by `peaks worktree spawn`')
|
|
103
116
|
.option('--session <sid>', 'override session id')
|
|
104
|
-
.option('--project <path>', 'project root (default: findProjectRoot(cwd))')).action((options) =>
|
|
117
|
+
.option('--project <path>', 'project root (default: findProjectRoot(cwd))')).action((options) => runReleaseAction(options, io));
|
|
105
118
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `peaks worktree renew` — extend an active lease's `expiresAt`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The action body is `runRenew` from `peaks-loop-workspace-runtime`; this file
|
|
5
|
+
* owns the host policy, the effects and the envelope. Every result kind is
|
|
6
|
+
* mapped back onto the envelope/exit code it produced before the extraction
|
|
7
|
+
* (LEASE_NOT_FOUND / LEASE_FILE_INVALID / LEASE_NOT_RENEWABLE / INVALID_TTL),
|
|
8
|
+
* and the metric emit stays here.
|
|
8
9
|
*/
|
|
9
10
|
import type { Command } from 'commander';
|
|
10
11
|
import { type ProgramIO } from '../cli-helpers.js';
|