peaks-loop 4.1.26 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +52 -0
- package/dist/cli/commands/core/session-info-command.js +3 -4
- 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 +13 -46
- 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/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/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/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/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/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/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-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,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"metadata": {
|
|
3
3
|
"pluginRoot": ".",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0"
|
|
5
5
|
},
|
|
6
6
|
"plugins": [
|
|
7
7
|
{
|
|
8
8
|
"name": "peaks-loop",
|
|
9
9
|
"description": "Loop Engineering CLI — workflow primitive / loop guards / evaluators / slice orchestration",
|
|
10
|
-
"version": "4.
|
|
10
|
+
"version": "4.2.0",
|
|
11
11
|
"author": {
|
|
12
12
|
"name": "SquabbyZ"
|
|
13
13
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.2.0 — 2026-11-06(运行态接缝收口)
|
|
4
|
+
|
|
5
|
+
**版本级别**:**minor**(新增 `peaks mut run --ignore` 能力,并把一个新的 workspace 包发到 registry)。
|
|
6
|
+
本次**没有**改任何门禁阈值或放行条件;**没有**改事件 schema 版本号(`schemaVersion` 仍是 `z.literal(1)`)。
|
|
7
|
+
门禁的天花板只降不升:`eslintFindings` 1667 → 1666、`eslintErrors` 553 → 552、
|
|
8
|
+
`fileSizeExcessLines` 21825 → 21801。
|
|
9
|
+
|
|
10
|
+
**一句话:这一版把「运行态路径从哪里拼」收成一个入口,并把 `peaks mut run` 从「只在一个仓库上能用」
|
|
11
|
+
修成「在任何仓库上都能用」。**
|
|
12
|
+
|
|
13
|
+
### 1. 72 处手拼路径收进 state-root 接缝
|
|
14
|
+
|
|
15
|
+
`src/**` 里 72 处手写 `join(root, '.peaks', '_runtime', sid)` 全部改走
|
|
16
|
+
`getSessionDir` / `tryGetSessionDir` / `defaultStateRoot`。**抛错 / 保持 total 的语义逐个核对过**:
|
|
17
|
+
原本会抛的仍然抛,原本承诺不抛的改走 `tryGetSessionDir` 并把 `ok:false` 映射回该帧原有的失败形态
|
|
18
|
+
(例如 `gcStalePresenceLeases` 对无法解析的 lease 记一条告警行,而不是抛)。
|
|
19
|
+
单行形态的棘轮基线由 72 条降到 **2 条**——剩下两条是「项目相对路径、无 `projectRoot`、纯函数且从不抛」,
|
|
20
|
+
接缝表达不了,已注明原因。**多行 `join(...)` / `resolve(...)` 形态不在本次范围内**(属已排期的后续清扫)。
|
|
21
|
+
|
|
22
|
+
### 2. `--branch` 的 shell 注入面关闭
|
|
23
|
+
|
|
24
|
+
`peaks worktree spawn --branch` 的值此前经双引号拼进 `execSync` 的命令串。现改为
|
|
25
|
+
`execFileSync('git', argv, …)`:不再经过任何 shell,含引号、反引号、`$(...)` 的分支名以**单个 argv 元素**
|
|
26
|
+
到达 git。失败信息形状随之变为不带引号的 `Command failed: git worktree add <path> -b <branch>`(已实测确认,
|
|
27
|
+
仓库内无测试钉住旧形状)。独立安全审计由 `warn` 转为 **`pass`**。
|
|
28
|
+
|
|
29
|
+
### 3. Windows 分隔符 bug
|
|
30
|
+
|
|
31
|
+
`workflow-graph-store-helpers.ts` 用 `resolve()` 得到的原生分隔符去和接缝产出的正斜杠根路径做
|
|
32
|
+
`startsWith`,在 Windows 上对**每一个**合法图引用都判为越界,`peaks workflow init` 直接失败。
|
|
33
|
+
改为 `relative()` 包含判断,并补了一个在旧代码下必红的测试。
|
|
34
|
+
|
|
35
|
+
### 4. `peaks mut run` 真正可用
|
|
36
|
+
|
|
37
|
+
- 新增 `--ignore <patterns...>`:沙箱复制时排除指定路径(默认空,`.stryker-tmp` 始终排除)。
|
|
38
|
+
此前仓库里任何 gitignored 目录带符号链接都会让 Stryker 复制沙箱 `EPERM`。
|
|
39
|
+
- 失败时写出 `stryker-failure.log` 并在信封里给出其路径——此前 `logLevel: 'off'` 把真因吞掉,
|
|
40
|
+
只能看到一句 `Something went wrong in the initial test run`。
|
|
41
|
+
- 变异面新增 `src/services/session/getSessionDir.ts`(本次 72 处调用的共同入口),
|
|
42
|
+
**33 个变异体全部被杀死**(killRate 1.0)。
|
|
43
|
+
|
|
44
|
+
### 5. 构建完整性
|
|
45
|
+
|
|
46
|
+
`packages/peaks-loop-workspace-runtime` 的 `package.json#exports` 声明 `./lease` / `./worktree`,
|
|
47
|
+
而 `check-build-integrity.mjs` 按子路径推导 `src/<subpath>.ts`。补两个一行 re-export shim 之后
|
|
48
|
+
`pnpm build` 端到端干净(此前是 `phantom export` 失败)。
|
|
49
|
+
|
|
50
|
+
### 6. 新包首次发布
|
|
51
|
+
|
|
52
|
+
`peaks-loop-workspace-runtime@0.0.1` 首次发到公共 registry;`peaks-loop` 依赖它,
|
|
53
|
+
`workspace:*` 由 `pnpm pack` 改写成精确版本。
|
|
54
|
+
|
|
3
55
|
## 4.1.26 — 2026-10-30(授权与发布物)
|
|
4
56
|
> **这一版原定是 4.1.25。** 那个 tag 已在 2026-10-30 推送,但发布没有完成 —— publish job 的
|
|
5
57
|
> 30 分钟预算不足以跑完它要跑的链(install + build + 窄测试 + 五道门 + **五个包的 OIDC 带 provenance
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { defaultStateRoot } from 'peaks-loop-workspace-runtime';
|
|
3
4
|
import { getSessionMeta } from '../../../services/session/session-manager.js';
|
|
4
5
|
import { resolveCanonicalProjectRoot } from '../../../services/config/config-service.js';
|
|
5
6
|
import { findProjectRoot } from '../../../services/config/config-safety.js';
|
|
@@ -12,13 +13,11 @@ const EXIT_DATAERR = 65;
|
|
|
12
13
|
const LEGACY_WARNING = 'Read from legacy back-compat path .peaks/.session.json. Run `peaks workspace reconcile --apply` to migrate to the canonical home (.peaks/_runtime/session.json).';
|
|
13
14
|
/** `canonical` = `.peaks/_runtime/session.json`; `legacy` = `.peaks/.session.json`. */
|
|
14
15
|
function bindingSourceOf(projectRoot) {
|
|
15
|
-
return existsSync(join(projectRoot, '.
|
|
16
|
-
? 'canonical'
|
|
17
|
-
: 'legacy';
|
|
16
|
+
return existsSync(join(defaultStateRoot(projectRoot), 'session.json')) ? 'canonical' : 'legacy';
|
|
18
17
|
}
|
|
19
18
|
function bindingPathOf(projectRoot, source) {
|
|
20
19
|
return source === 'canonical'
|
|
21
|
-
? join(projectRoot, '
|
|
20
|
+
? join(defaultStateRoot(projectRoot), 'session.json')
|
|
22
21
|
: join(projectRoot, '.peaks', '.session.json');
|
|
23
22
|
}
|
|
24
23
|
/** A `--caller-id` the resolver rejected (D5 → exit 65; EX_USAGE → exit 64). */
|
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { resolveCanonicalProjectRoot } from '../../services/config/config-service.js';
|
|
4
4
|
import { isUnsafePathInput } from '../../shared/path-safety.js';
|
|
5
|
+
import { getSessionDir } from '../../services/session/getSessionDir.js';
|
|
5
6
|
import { read24hState } from '../../services/24h-mode/index.js';
|
|
6
7
|
import { getErrorMessage } from '../cli-helpers.js';
|
|
7
8
|
const SINCE_PATTERN = /^(\d+)([smhd])$/i;
|
|
@@ -36,7 +37,7 @@ function readSlices(projectRoot, sessionId) {
|
|
|
36
37
|
if (isUnsafePathInput(sessionId)) {
|
|
37
38
|
throw new Error(`Invalid session id: ${sessionId} (must be a single path segment)`);
|
|
38
39
|
}
|
|
39
|
-
const path = join(projectRoot,
|
|
40
|
+
const path = join(getSessionDir(projectRoot, sessionId), 'metrics', 'slices.jsonl');
|
|
40
41
|
if (!existsSync(path))
|
|
41
42
|
return 0;
|
|
42
43
|
try {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
|
+
import { defaultStateRoot, sessionRuntimeDir } from 'peaks-loop-workspace-runtime';
|
|
9
10
|
import { isUnsafePathInput } from '../../../shared/path-safety.js';
|
|
10
11
|
export async function doctorInvokeFromCode(opts) {
|
|
11
12
|
// Sid axis: `opts.sid` is the sole path segment between the runtime root and
|
|
@@ -13,7 +14,11 @@ export async function doctorInvokeFromCode(opts) {
|
|
|
13
14
|
if (isUnsafePathInput(opts.sid)) {
|
|
14
15
|
throw new Error(`Invalid session id: ${opts.sid} (must be a single path segment)`);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
// No project root reaches this frame: the stub is written relative to the
|
|
18
|
+
// caller's cwd on purpose, and the returned path stays relative. So the
|
|
19
|
+
// runtime root is the one of the current directory ("."), and the session
|
|
20
|
+
// segment goes through the same seam as every other session-scoped path.
|
|
21
|
+
const dir = join(sessionRuntimeDir({ stateRoot: defaultStateRoot('.'), sessionId: opts.sid }), 'doctor');
|
|
17
22
|
mkdirSync(dir, { recursive: true });
|
|
18
23
|
const proposalPath = join(dir, 'proposal.md');
|
|
19
24
|
// Stub: real implementation invokes peaks-doctor sub-skill
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// `<project>/.peaks/_runtime/<sessionId>/job/<jobId>/state.json`.
|
|
4
4
|
import { existsSync, readdirSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
|
+
import { defaultStateRoot } from 'peaks-loop-workspace-runtime';
|
|
6
7
|
import { isUnsafePathInput } from '../../shared/path-safety.js';
|
|
8
|
+
import { getSessionDir } from '../../services/session/getSessionDir.js';
|
|
7
9
|
import { getCurrentSessionId } from '../../services/skills/skill-presence-service.js';
|
|
8
10
|
import { projectRoot } from './job-command-shared.js';
|
|
9
11
|
/**
|
|
@@ -20,7 +22,7 @@ export const SESSION_ID_HELP = 'session id (default: resolve from .peaks/_runtim
|
|
|
20
22
|
* session must be reported by name so the caller can re-run with --session-id.
|
|
21
23
|
*/
|
|
22
24
|
function findSessionHoldingJob(project, jobId) {
|
|
23
|
-
const runtimeDir =
|
|
25
|
+
const runtimeDir = defaultStateRoot(project);
|
|
24
26
|
if (!existsSync(runtimeDir))
|
|
25
27
|
return null;
|
|
26
28
|
for (const entry of readdirSync(runtimeDir, { withFileTypes: true })) {
|
|
@@ -65,7 +67,7 @@ export function resolveJobStateRoot(opts, jobId) {
|
|
|
65
67
|
if (isUnsafePathInput(sessionId)) {
|
|
66
68
|
throw new Error(`Invalid session id: ${sessionId} (must be a single path segment)`);
|
|
67
69
|
}
|
|
68
|
-
const rootDir = join(project,
|
|
70
|
+
const rootDir = join(getSessionDir(project, sessionId), 'job');
|
|
69
71
|
if (jobId && !existsSync(join(rootDir, jobId, 'state.json'))) {
|
|
70
72
|
const other = findSessionHoldingJob(project, jobId);
|
|
71
73
|
throw new Error(other
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
14
14
|
import { join } from 'node:path';
|
|
15
|
+
import { defaultStateRoot } from 'peaks-loop-workspace-runtime';
|
|
15
16
|
import { readObservabilityEvents } from '../../services/observability/observability-service.js';
|
|
16
17
|
export const EMPTY_COUNTS = {
|
|
17
18
|
spawn: 0,
|
|
@@ -29,7 +30,7 @@ export const EMPTY_COUNTS = {
|
|
|
29
30
|
* has no lease events to report; that's not an error).
|
|
30
31
|
*/
|
|
31
32
|
export function readAllSessionLeaseEvents(projectRoot) {
|
|
32
|
-
const runtimeDir =
|
|
33
|
+
const runtimeDir = defaultStateRoot(projectRoot);
|
|
33
34
|
if (!existsSync(runtimeDir))
|
|
34
35
|
return { sessions: [], missingSessions: 0 };
|
|
35
36
|
let entries;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { existsSync, readdirSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { isUnsafePathInput } from '../../shared/path-safety.js';
|
|
7
|
+
import { getSessionDir } from '../../services/session/getSessionDir.js';
|
|
7
8
|
/** Test seam: pick the next cycle-N.json number for capture-score
|
|
8
9
|
* writes. The run-driver also writes to the same dir; the next
|
|
9
10
|
* index = max(prior)+1, or 1. */
|
|
@@ -19,7 +20,7 @@ export function nextEvalCaptureIndex(projectRoot, sid, rid) {
|
|
|
19
20
|
if (isUnsafePathInput(rid)) {
|
|
20
21
|
throw new Error(`Invalid request id: ${rid} (must be a single path segment)`);
|
|
21
22
|
}
|
|
22
|
-
const dir = join(projectRoot,
|
|
23
|
+
const dir = join(getSessionDir(projectRoot, sid), 'loop', rid, 'cycles');
|
|
23
24
|
if (!existsSync(dir))
|
|
24
25
|
return 1;
|
|
25
26
|
let entries;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { isUnsafePathInput } from '../../shared/path-safety.js';
|
|
4
|
+
import { getSessionDir } from '../../services/session/getSessionDir.js';
|
|
4
5
|
import { dispatchEvaluator } from '../../services/loop/evaluator-dispatcher.js';
|
|
5
6
|
import { addJsonOption, getErrorMessage, printResult } from '../cli-helpers.js';
|
|
6
7
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
@@ -65,7 +66,7 @@ function captureEvalScore(rid, sid, projectRoot, envelope) {
|
|
|
65
66
|
: envelope.gateAction === 'warn'
|
|
66
67
|
? 0.5
|
|
67
68
|
: 0.0;
|
|
68
|
-
const dir = join(projectRoot,
|
|
69
|
+
const dir = join(getSessionDir(projectRoot, sid), 'loop', rid, 'cycles');
|
|
69
70
|
const n = nextEvalCaptureIndex(projectRoot, sid, rid);
|
|
70
71
|
const path = join(dir, `cycle-${n}.json`);
|
|
71
72
|
try {
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* `peaks mut` — command builders and helper functions.
|
|
3
3
|
*
|
|
4
4
|
* Originally extracted from `mut-commands.ts` (file-size cap campaign).
|
|
5
|
-
* It holds the stub-report factories, the summary emitter
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* It holds the stub-report factories, the summary emitter and — after the
|
|
6
|
+
* `max-lines-per-function` rule was measured at 209 code lines for
|
|
7
|
+
* `createMutCommands` — the three subcommand builders that drive the
|
|
8
|
+
* mutation pipeline (`run`, `mutants`, `asserts`).
|
|
9
9
|
* The `report` subcommand — a pure reader of an already-written file —
|
|
10
|
-
* lives with the CLI surface in `mut-commands.ts
|
|
10
|
+
* lives with the CLI surface in `mut-commands.ts`; the named-error mapping
|
|
11
|
+
* and the failure diagnostic live in `mut-failure-diagnostic.ts`.
|
|
11
12
|
*
|
|
12
13
|
* The named-error part exists for R7: a missing or unloadable mutation
|
|
13
14
|
* toolchain must surface a MACHINE-READABLE error code (for example
|
|
@@ -18,13 +19,7 @@
|
|
|
18
19
|
*/
|
|
19
20
|
import { Command } from 'commander';
|
|
20
21
|
import { type AssertionsReport, type MutationReport, type StrykerInvoker } from 'peaks-loop-mut';
|
|
21
|
-
import {
|
|
22
|
-
/**
|
|
23
|
-
* Fallback code for a mutation failure that carries no named code of its
|
|
24
|
-
* own. The production invoker raises the specific codes; anything that
|
|
25
|
-
* escapes it without one still gets a stable, greppable name.
|
|
26
|
-
*/
|
|
27
|
-
export declare const MUT_CLI_ERROR_CODE = "MUT_FAILED";
|
|
22
|
+
import type { ProgramIO } from '../cli-helpers.js';
|
|
28
23
|
/**
|
|
29
24
|
* The IO the mut family writes to when the caller injects none. Same
|
|
30
25
|
* shape as `src/cli/program.ts`'s default sinks: one trailing newline
|
|
@@ -36,6 +31,8 @@ export interface MutCommandArgs {
|
|
|
36
31
|
readonly project: string;
|
|
37
32
|
readonly testFiles: string[];
|
|
38
33
|
readonly mutate?: string[];
|
|
34
|
+
/** Patterns NOT to copy into the Stryker sandbox. Empty by default. */
|
|
35
|
+
readonly ignore?: string[];
|
|
39
36
|
readonly inputSig: string;
|
|
40
37
|
readonly sessionId: string;
|
|
41
38
|
readonly out: string;
|
|
@@ -65,22 +62,6 @@ export declare function emitSummary(io: ProgramIO, json: boolean, payload: {
|
|
|
65
62
|
passed: boolean;
|
|
66
63
|
path: string;
|
|
67
64
|
}): void;
|
|
68
|
-
/**
|
|
69
|
-
* Read the machine-readable code off a failure. The production invoker
|
|
70
|
-
* raises named codes (`MUT_TOOLCHAIN_UNAVAILABLE`, `MUT_NO_MUTANTS`,
|
|
71
|
-
* `MUT_MUTATE_PATTERN_REQUIRED`, …) and `runMutation` preserves them
|
|
72
|
-
* while wrapping. Anything without a recognised code falls back to
|
|
73
|
-
* `MUT_FAILED` so the envelope is never anonymous.
|
|
74
|
-
*/
|
|
75
|
-
export declare function mutErrorCode(err: unknown): string;
|
|
76
|
-
/** The human-readable half of the envelope. */
|
|
77
|
-
export declare function mutErrorMessage(err: unknown): string;
|
|
78
|
-
/**
|
|
79
|
-
* Emit the failure envelope on stderr and set a non-zero exit code. Its
|
|
80
|
-
* `data` field carries the machine-readable detail — where an ABSOLUTE path
|
|
81
|
-
* belongs; stdout stays reserved for the `--json` payload (R6).
|
|
82
|
-
*/
|
|
83
|
-
export declare function emitMutError(io: ProgramIO, err: unknown): void;
|
|
84
65
|
/**
|
|
85
66
|
* `peaks mut run` — the full mut pipeline (Stryker + assertion scan +
|
|
86
67
|
* report). One-axis: --session-id required.
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* `peaks mut` — command builders and helper functions.
|
|
3
3
|
*
|
|
4
4
|
* Originally extracted from `mut-commands.ts` (file-size cap campaign).
|
|
5
|
-
* It holds the stub-report factories, the summary emitter
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* It holds the stub-report factories, the summary emitter and — after the
|
|
6
|
+
* `max-lines-per-function` rule was measured at 209 code lines for
|
|
7
|
+
* `createMutCommands` — the three subcommand builders that drive the
|
|
8
|
+
* mutation pipeline (`run`, `mutants`, `asserts`).
|
|
9
9
|
* The `report` subcommand — a pure reader of an already-written file —
|
|
10
|
-
* lives with the CLI surface in `mut-commands.ts
|
|
10
|
+
* lives with the CLI surface in `mut-commands.ts`; the named-error mapping
|
|
11
|
+
* and the failure diagnostic live in `mut-failure-diagnostic.ts`.
|
|
11
12
|
*
|
|
12
13
|
* The named-error part exists for R7: a missing or unloadable mutation
|
|
13
14
|
* toolchain must surface a MACHINE-READABLE error code (for example
|
|
@@ -18,15 +19,7 @@
|
|
|
18
19
|
*/
|
|
19
20
|
import { Command } from 'commander';
|
|
20
21
|
import { assertTestFilesUsable, buildMutReport, runMutation, scanAssertions } from 'peaks-loop-mut';
|
|
21
|
-
import {
|
|
22
|
-
/**
|
|
23
|
-
* Fallback code for a mutation failure that carries no named code of its
|
|
24
|
-
* own. The production invoker raises the specific codes; anything that
|
|
25
|
-
* escapes it without one still gets a stable, greppable name.
|
|
26
|
-
*/
|
|
27
|
-
export const MUT_CLI_ERROR_CODE = 'MUT_FAILED';
|
|
28
|
-
/** Named mutation codes are always `MUT_` + upper snake case. */
|
|
29
|
-
const NAMED_CODE_PATTERN = /^MUT_[A-Z0-9_]+$/;
|
|
22
|
+
import { emitMutError, mutationFailureLogPath } from './mut-failure-diagnostic.js';
|
|
30
23
|
/**
|
|
31
24
|
* The IO the mut family writes to when the caller injects none. Same
|
|
32
25
|
* shape as `src/cli/program.ts`'s default sinks: one trailing newline
|
|
@@ -78,36 +71,6 @@ export function emitSummary(io, json, payload) {
|
|
|
78
71
|
}
|
|
79
72
|
io.stdout(`mut-report.json: ${payload.path}\nsha256: ${payload.sha256}\npassed: ${payload.passed}`);
|
|
80
73
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Read the machine-readable code off a failure. The production invoker
|
|
83
|
-
* raises named codes (`MUT_TOOLCHAIN_UNAVAILABLE`, `MUT_NO_MUTANTS`,
|
|
84
|
-
* `MUT_MUTATE_PATTERN_REQUIRED`, …) and `runMutation` preserves them
|
|
85
|
-
* while wrapping. Anything without a recognised code falls back to
|
|
86
|
-
* `MUT_FAILED` so the envelope is never anonymous.
|
|
87
|
-
*/
|
|
88
|
-
export function mutErrorCode(err) {
|
|
89
|
-
if (err && typeof err === 'object' && 'code' in err) {
|
|
90
|
-
const code = err.code;
|
|
91
|
-
if (typeof code === 'string' && NAMED_CODE_PATTERN.test(code)) {
|
|
92
|
-
return code;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return MUT_CLI_ERROR_CODE;
|
|
96
|
-
}
|
|
97
|
-
/** The human-readable half of the envelope. */
|
|
98
|
-
export function mutErrorMessage(err) {
|
|
99
|
-
return err instanceof Error ? err.message : String(err);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Emit the failure envelope on stderr and set a non-zero exit code. Its
|
|
103
|
-
* `data` field carries the machine-readable detail — where an ABSOLUTE path
|
|
104
|
-
* belongs; stdout stays reserved for the `--json` payload (R6).
|
|
105
|
-
*/
|
|
106
|
-
export function emitMutError(io, err) {
|
|
107
|
-
const details = err?.details;
|
|
108
|
-
const data = details && typeof details === 'object' ? details : {};
|
|
109
|
-
printErrorEnvelope(io, 'mut', mutErrorCode(err), mutErrorMessage(err), data, []);
|
|
110
|
-
}
|
|
111
74
|
/**
|
|
112
75
|
* Validate `--test-files` BEFORE any Stryker run, scan or report write: a
|
|
113
76
|
* missing path must fail with the named code, never reach the mutation
|
|
@@ -125,6 +88,7 @@ function assertMutTestFiles(a) {
|
|
|
125
88
|
.requiredOption('--project <path>', 'project root')
|
|
126
89
|
.requiredOption('--test-files <files...>', 'test files to mutate against')
|
|
127
90
|
.option('--mutate <patterns...>', 'source patterns to mutate, relative to --project')
|
|
91
|
+
.option('--ignore <patterns...>', 'paths or globs NOT to copy into the Stryker sandbox')
|
|
128
92
|
.requiredOption('--input-sig <hex>', 'TACT.sig (sha256) for chain')
|
|
129
93
|
.requiredOption('--session-id <sid>', 'session id; CLI writes artifacts only under .peaks/_runtime/<sid>/mut/ (one-axis layout)')
|
|
130
94
|
.requiredOption('--out <path>', 'output path for mut-report.json')
|
|
@@ -136,6 +100,7 @@ function assertMutTestFiles(a) {
|
|
|
136
100
|
project: a.project,
|
|
137
101
|
testFiles: a.testFiles,
|
|
138
102
|
mutate: a.mutate ?? [],
|
|
103
|
+
ignorePatterns: a.ignore ?? [],
|
|
139
104
|
invokeStryker
|
|
140
105
|
});
|
|
141
106
|
const assertions = await scanAssertions({
|
|
@@ -163,7 +128,7 @@ function assertMutTestFiles(a) {
|
|
|
163
128
|
catch (err) {
|
|
164
129
|
// R7: a named code + actionable message + non-zero exit, never an
|
|
165
130
|
// UNHANDLED_ERROR envelope with a bare "Cannot find package".
|
|
166
|
-
emitMutError(io, err);
|
|
131
|
+
emitMutError(io, err, mutationFailureLogPath(a.out));
|
|
167
132
|
}
|
|
168
133
|
});
|
|
169
134
|
}
|
|
@@ -177,6 +142,7 @@ export function buildMutMutantsCommand(invokeStryker, io) {
|
|
|
177
142
|
.requiredOption('--project <path>', 'project root')
|
|
178
143
|
.requiredOption('--test-files <files...>', 'test files to mutate against')
|
|
179
144
|
.option('--mutate <patterns...>', 'source patterns to mutate, relative to --project')
|
|
145
|
+
.option('--ignore <patterns...>', 'paths or globs NOT to copy into the Stryker sandbox')
|
|
180
146
|
.requiredOption('--input-sig <hex>', 'TACT.sig')
|
|
181
147
|
.requiredOption('--session-id <sid>', 'session id')
|
|
182
148
|
.requiredOption('--out <path>', 'output path for mut-report.json')
|
|
@@ -188,6 +154,7 @@ export function buildMutMutantsCommand(invokeStryker, io) {
|
|
|
188
154
|
project: a.project,
|
|
189
155
|
testFiles: a.testFiles,
|
|
190
156
|
mutate: a.mutate ?? [],
|
|
157
|
+
ignorePatterns: a.ignore ?? [],
|
|
191
158
|
invokeStryker
|
|
192
159
|
});
|
|
193
160
|
const report = await buildMutReport({
|
|
@@ -207,7 +174,7 @@ export function buildMutMutantsCommand(invokeStryker, io) {
|
|
|
207
174
|
}
|
|
208
175
|
}
|
|
209
176
|
catch (err) {
|
|
210
|
-
emitMutError(io, err);
|
|
177
|
+
emitMutError(io, err, mutationFailureLogPath(a.out));
|
|
211
178
|
}
|
|
212
179
|
});
|
|
213
180
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ProgramIO } from '../cli-helpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fallback code for a mutation failure that carries no named code of its
|
|
4
|
+
* own. The production invoker raises the specific codes; anything that
|
|
5
|
+
* escapes it without one still gets a stable, greppable name.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MUT_CLI_ERROR_CODE = "MUT_FAILED";
|
|
8
|
+
/**
|
|
9
|
+
* Read the machine-readable code off a failure. The production invoker
|
|
10
|
+
* raises named codes (`MUT_TOOLCHAIN_UNAVAILABLE`, `MUT_NO_MUTANTS`,
|
|
11
|
+
* `MUT_MUTATE_PATTERN_REQUIRED`, …) and `runMutation` preserves them
|
|
12
|
+
* while wrapping. Anything without a recognised code falls back to
|
|
13
|
+
* `MUT_FAILED` so the envelope is never anonymous.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mutErrorCode(err: unknown): string;
|
|
16
|
+
/** The human-readable half of the envelope. */
|
|
17
|
+
export declare function mutErrorMessage(err: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* Emit the failure envelope on stderr and set a non-zero exit code. Its
|
|
20
|
+
* `data` field carries the machine-readable detail — where an ABSOLUTE path
|
|
21
|
+
* belongs; stdout stays reserved for the `--json` payload (R6).
|
|
22
|
+
*
|
|
23
|
+
* `diagnosticPath` is set by the Stryker-backed subcommands. When it is
|
|
24
|
+
* given the failure is ALSO written to that file, together with Stryker's
|
|
25
|
+
* own file log when the invoker captured one. The path is then named in the
|
|
26
|
+
* envelope's `data` and `nextActions` so the next caller does not have to
|
|
27
|
+
* guess it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function emitMutError(io: ProgramIO, err: unknown, diagnosticPath?: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Where a failed Stryker run writes its diagnostic — NEXT TO the report the
|
|
32
|
+
* run was going to produce, so both artifacts of one run live together.
|
|
33
|
+
*/
|
|
34
|
+
export declare function mutationFailureLogPath(outPath: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* What became of the diagnostic write. A discriminated result rather than
|
|
37
|
+
* `string | undefined`, so a caller cannot mistake a failed write for "no
|
|
38
|
+
* diagnostic requested" — and a diagnostic must never mask the original error.
|
|
39
|
+
*/
|
|
40
|
+
export type MutDiagnosticResult = {
|
|
41
|
+
readonly ok: true;
|
|
42
|
+
readonly path: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly ok: false;
|
|
45
|
+
readonly reason: string;
|
|
46
|
+
};
|
|
47
|
+
/** Persist the failure; the reason a write failed is kept, not swallowed. */
|
|
48
|
+
export declare function writeMutFailureDiagnostic(path: string, err: unknown, details: Record<string, unknown>): MutDiagnosticResult;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failure surface of `peaks mut` — the named-error mapping and the
|
|
3
|
+
* diagnostic file a failed Stryker run leaves behind.
|
|
4
|
+
*
|
|
5
|
+
* WHY IT IS ITS OWN MODULE
|
|
6
|
+
* -------------------------
|
|
7
|
+
* R7 needs a MACHINE-READABLE error code (for example
|
|
8
|
+
* `MUT_TOOLCHAIN_UNAVAILABLE`) plus an actionable message and a non-zero
|
|
9
|
+
* exit code — never `UNHANDLED_ERROR` with a bare "Cannot find package".
|
|
10
|
+
* The Stryker-backed subcommands ALSO need the failure written down:
|
|
11
|
+
* Stryker reports several distinct failures as the bare
|
|
12
|
+
* "Something went wrong in the initial test run", and because the runner
|
|
13
|
+
* keeps its console log off (`logLevel: 'off'`, stdout belongs to the
|
|
14
|
+
* `--json` envelope) its own file log is the only place the real reason
|
|
15
|
+
* appears. The production invoker captures that log into the error's
|
|
16
|
+
* `details.strykerLog`; this module turns the error into the file and the
|
|
17
|
+
* envelope that points at it.
|
|
18
|
+
*
|
|
19
|
+
* Split out of `mut-commands-helpers.ts` for the `src/` raw-line cap (300).
|
|
20
|
+
*/
|
|
21
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { dirname, join, resolve } from 'node:path';
|
|
23
|
+
import { printErrorEnvelope } from '../cli-helpers.js';
|
|
24
|
+
/**
|
|
25
|
+
* Fallback code for a mutation failure that carries no named code of its
|
|
26
|
+
* own. The production invoker raises the specific codes; anything that
|
|
27
|
+
* escapes it without one still gets a stable, greppable name.
|
|
28
|
+
*/
|
|
29
|
+
export const MUT_CLI_ERROR_CODE = 'MUT_FAILED';
|
|
30
|
+
/** Named mutation codes are always `MUT_` + upper snake case. */
|
|
31
|
+
const NAMED_CODE_PATTERN = /^MUT_[A-Z0-9_]+$/;
|
|
32
|
+
/** How many `cause` links the diagnostic walks before it stops. */
|
|
33
|
+
const MAX_CAUSE_DEPTH = 4;
|
|
34
|
+
/**
|
|
35
|
+
* Read the machine-readable code off a failure. The production invoker
|
|
36
|
+
* raises named codes (`MUT_TOOLCHAIN_UNAVAILABLE`, `MUT_NO_MUTANTS`,
|
|
37
|
+
* `MUT_MUTATE_PATTERN_REQUIRED`, …) and `runMutation` preserves them
|
|
38
|
+
* while wrapping. Anything without a recognised code falls back to
|
|
39
|
+
* `MUT_FAILED` so the envelope is never anonymous.
|
|
40
|
+
*/
|
|
41
|
+
export function mutErrorCode(err) {
|
|
42
|
+
if (err && typeof err === 'object' && 'code' in err) {
|
|
43
|
+
const code = err.code;
|
|
44
|
+
if (typeof code === 'string' && NAMED_CODE_PATTERN.test(code)) {
|
|
45
|
+
return code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return MUT_CLI_ERROR_CODE;
|
|
49
|
+
}
|
|
50
|
+
/** The human-readable half of the envelope. */
|
|
51
|
+
export function mutErrorMessage(err) {
|
|
52
|
+
return err instanceof Error ? err.message : String(err);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Emit the failure envelope on stderr and set a non-zero exit code. Its
|
|
56
|
+
* `data` field carries the machine-readable detail — where an ABSOLUTE path
|
|
57
|
+
* belongs; stdout stays reserved for the `--json` payload (R6).
|
|
58
|
+
*
|
|
59
|
+
* `diagnosticPath` is set by the Stryker-backed subcommands. When it is
|
|
60
|
+
* given the failure is ALSO written to that file, together with Stryker's
|
|
61
|
+
* own file log when the invoker captured one. The path is then named in the
|
|
62
|
+
* envelope's `data` and `nextActions` so the next caller does not have to
|
|
63
|
+
* guess it.
|
|
64
|
+
*/
|
|
65
|
+
export function emitMutError(io, err, diagnosticPath) {
|
|
66
|
+
const details = mutErrorDetails(err);
|
|
67
|
+
const written = diagnosticPath
|
|
68
|
+
? writeMutFailureDiagnostic(diagnosticPath, err, details)
|
|
69
|
+
: undefined;
|
|
70
|
+
// Stryker's log can be large; it belongs in the file, not in stderr.
|
|
71
|
+
const data = { ...details };
|
|
72
|
+
delete data.strykerLog;
|
|
73
|
+
if (written?.ok) {
|
|
74
|
+
data.diagnosticPath = written.path;
|
|
75
|
+
}
|
|
76
|
+
else if (written) {
|
|
77
|
+
// The original failure stays primary; this only says the file is absent.
|
|
78
|
+
data.diagnosticWriteFailure = written.reason;
|
|
79
|
+
}
|
|
80
|
+
printErrorEnvelope(io, 'mut', mutErrorCode(err), mutErrorMessage(err), data, written?.ok ? [`Read the Stryker diagnostic log at ${written.path}`] : []);
|
|
81
|
+
}
|
|
82
|
+
/** The machine-readable `details` an invoker attached to its error, if any. */
|
|
83
|
+
function mutErrorDetails(err) {
|
|
84
|
+
const details = err?.details;
|
|
85
|
+
return details && typeof details === 'object' ? { ...details } : {};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Where a failed Stryker run writes its diagnostic — NEXT TO the report the
|
|
89
|
+
* run was going to produce, so both artifacts of one run live together.
|
|
90
|
+
*/
|
|
91
|
+
export function mutationFailureLogPath(outPath) {
|
|
92
|
+
return join(dirname(resolve(outPath)), 'stryker-failure.log');
|
|
93
|
+
}
|
|
94
|
+
/** Persist the failure; the reason a write failed is kept, not swallowed. */
|
|
95
|
+
export function writeMutFailureDiagnostic(path, err, details) {
|
|
96
|
+
try {
|
|
97
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
98
|
+
writeFileSync(path, renderMutFailureLog(err, details), 'utf8');
|
|
99
|
+
return { ok: true, path };
|
|
100
|
+
}
|
|
101
|
+
catch (writeError) {
|
|
102
|
+
const reason = writeError instanceof Error ? writeError.message : String(writeError);
|
|
103
|
+
return { ok: false, reason };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The diagnostic file's body: what failed, and whatever Stryker logged. */
|
|
107
|
+
function renderMutFailureLog(err, details) {
|
|
108
|
+
const lines = [
|
|
109
|
+
'# peaks mut failure diagnostic',
|
|
110
|
+
`time: ${new Date().toISOString()}`,
|
|
111
|
+
`code: ${mutErrorCode(err)}`,
|
|
112
|
+
`message: ${mutErrorMessage(err)}`,
|
|
113
|
+
'',
|
|
114
|
+
'## Error',
|
|
115
|
+
err instanceof Error ? (err.stack ?? err.message) : String(err)
|
|
116
|
+
];
|
|
117
|
+
const causes = describeCauses(err);
|
|
118
|
+
if (causes.length > 0) {
|
|
119
|
+
lines.push('', '## Cause chain', ...causes);
|
|
120
|
+
}
|
|
121
|
+
const strykerLog = details.strykerLog;
|
|
122
|
+
if (typeof strykerLog === 'string' && strykerLog.trim().length > 0) {
|
|
123
|
+
lines.push('', '## Stryker log', strykerLog.trimEnd());
|
|
124
|
+
}
|
|
125
|
+
return `${lines.join('\n')}\n`;
|
|
126
|
+
}
|
|
127
|
+
/** The `cause` chain of an error, nearest first. Bounded so it cannot loop. */
|
|
128
|
+
function describeCauses(err, depth = 0) {
|
|
129
|
+
if (depth >= MAX_CAUSE_DEPTH || !err || typeof err !== 'object') {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
const cause = err.cause;
|
|
133
|
+
if (!cause) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
return [describeCause(cause), ...describeCauses(cause, depth + 1)];
|
|
137
|
+
}
|
|
138
|
+
/** `Error`s keep their stack; anything else is serialised, never stringified blind. */
|
|
139
|
+
function describeCause(cause) {
|
|
140
|
+
if (cause instanceof Error) {
|
|
141
|
+
return cause.stack ?? cause.message;
|
|
142
|
+
}
|
|
143
|
+
if (typeof cause === 'string') {
|
|
144
|
+
return cause;
|
|
145
|
+
}
|
|
146
|
+
return JSON.stringify(cause) ?? 'unserialisable cause';
|
|
147
|
+
}
|
|
@@ -27,12 +27,13 @@
|
|
|
27
27
|
import { existsSync, readFileSync } from 'node:fs';
|
|
28
28
|
import { join } from 'node:path';
|
|
29
29
|
import { fail, ok } from 'peaks-loop-shared/result';
|
|
30
|
+
import { defaultStateRoot } from 'peaks-loop-workspace-runtime';
|
|
30
31
|
import { atomicWriteJson } from '../../services/ide/shared/atomic-json.js';
|
|
31
32
|
import { addJsonOption, printResult } from '../cli-helpers.js';
|
|
32
33
|
import { findProjectRoot } from '../../services/config/config-safety.js';
|
|
33
|
-
const
|
|
34
|
+
const OUTER_SESSION_CACHE_FILE = '.outer-session-cache.json';
|
|
34
35
|
function resolveCachePath(projectRoot) {
|
|
35
|
-
return join(projectRoot,
|
|
36
|
+
return join(defaultStateRoot(projectRoot), OUTER_SESSION_CACHE_FILE);
|
|
36
37
|
}
|
|
37
38
|
function readEnvOuter() {
|
|
38
39
|
const peaks = process.env.PEAKS_OUTER_SESSION_ID;
|
|
@@ -9,6 +9,7 @@ import { spawn } from 'node:child_process';
|
|
|
9
9
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync } from 'node:fs';
|
|
10
10
|
import net from 'node:net';
|
|
11
11
|
import { join, dirname, resolve } from 'node:path';
|
|
12
|
+
import { defaultStateRoot } from 'peaks-loop-workspace-runtime';
|
|
12
13
|
import { isUnsafePathInput } from '../../shared/path-safety.js';
|
|
13
14
|
export const DEFAULT_PORT = 8931;
|
|
14
15
|
export const MAX_PORT = 8949;
|
|
@@ -22,8 +23,10 @@ const TERMINAL_HASH_CHARS = 16;
|
|
|
22
23
|
const TERMINAL_ID_MAX_CHARS = 64;
|
|
23
24
|
export const BROWSERS = ['chromium', 'firefox', 'webkit'];
|
|
24
25
|
export const PLAYWRIGHT_SESSIONS_DIR = 'playwright-sessions';
|
|
26
|
+
/** The runtime root's non-session child holding per-terminal browser profiles. */
|
|
27
|
+
const PLAYWRIGHT_USERDATA_DIR = 'playwright-userdata';
|
|
25
28
|
export function playwrightSessionsDir(projectRoot) {
|
|
26
|
-
return join(projectRoot,
|
|
29
|
+
return join(defaultStateRoot(projectRoot), PLAYWRIGHT_SESSIONS_DIR);
|
|
27
30
|
}
|
|
28
31
|
export function sessionFilePath(projectRoot, terminalId) {
|
|
29
32
|
// Terminal-id axis. The derived id is already sanitised (`deriveTerminalId`),
|
|
@@ -50,7 +53,7 @@ export function defaultUserDataDir(projectRoot, terminalId) {
|
|
|
50
53
|
if (isUnsafePathInput(terminalId)) {
|
|
51
54
|
throw new Error(`Invalid terminal id: ${terminalId} (must be a single path segment)`);
|
|
52
55
|
}
|
|
53
|
-
return join(projectRoot,
|
|
56
|
+
return join(defaultStateRoot(projectRoot), PLAYWRIGHT_USERDATA_DIR, terminalId);
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
56
59
|
* Derive a stable terminal id from the process environment. Prefers
|