@modootoday/pmcp 0.20.0 → 0.22.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.
Files changed (124) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.mcp.json +1 -1
  5. package/dist/{apply-QJ6MGLBX.js → apply-3PR4UOES.js} +58 -24
  6. package/dist/{available-HYSDAFYH.js → available-BFXLII4A.js} +7 -7
  7. package/dist/{broadcast-LYOA6BEW.js → broadcast-ZALGUJVR.js} +4 -4
  8. package/dist/chunk-2GI5RM3M.js +53 -0
  9. package/dist/chunk-2QJGUR23.js +274 -0
  10. package/dist/{chunk-FD6VGFYZ.js → chunk-3LADLKAI.js} +207 -15
  11. package/dist/{chunk-MZEMLFFD.js → chunk-3OBJVG5R.js} +2 -2
  12. package/dist/{chunk-IQD4W53M.js → chunk-57Q75MS4.js} +18 -18
  13. package/dist/chunk-5YCKFU5Q.js +1672 -0
  14. package/dist/{chunk-IZABPDAO.js → chunk-5ZUDBC3P.js} +2 -2
  15. package/dist/{chunk-EKPMVEIA.js → chunk-73IDLWRI.js} +7 -4
  16. package/dist/{chunk-QYH2NR6G.js → chunk-7FV2LORT.js} +2 -2
  17. package/dist/{chunk-4VK5G3SV.js → chunk-E6YP2PMO.js} +3 -5
  18. package/dist/{chunk-RMHZFWHF.js → chunk-EPNTYTDZ.js} +33 -33
  19. package/dist/{chunk-5JPD6VIH.js → chunk-GBKRDRMZ.js} +22 -7
  20. package/dist/{chunk-T6GOWHK6.js → chunk-GFOQDLPL.js} +6 -1
  21. package/dist/{chunk-RBNMNKNN.js → chunk-JQVSDPFL.js} +3 -3
  22. package/dist/{chunk-OG7QR2DP.js → chunk-KEHB4FZP.js} +17 -2
  23. package/dist/chunk-KUBHGVTD.js +126 -0
  24. package/dist/chunk-L42U5XKC.js +7 -0
  25. package/dist/chunk-LFFIQBNY.js +115 -0
  26. package/dist/{chunk-O2JWF7ZM.js → chunk-LVNGMGOM.js} +2 -2
  27. package/dist/{chunk-PQTM27GU.js → chunk-MR5IBS6L.js} +6 -7
  28. package/dist/{chunk-OAIQ7A3R.js → chunk-NDED2O5B.js} +5 -5
  29. package/dist/{chunk-M2RYXWX2.js → chunk-NHUMPEPV.js} +2 -2
  30. package/dist/{chunk-ONP6JRFZ.js → chunk-OFJIMBTL.js} +2 -2
  31. package/dist/{chunk-YN5GQCHN.js → chunk-RHJEGLYM.js} +6 -1
  32. package/dist/{chunk-JBHGJKSL.js → chunk-RNC7PGW2.js} +2 -2
  33. package/dist/{chunk-J6HNP6HA.js → chunk-RNE4WPBS.js} +2 -2
  34. package/dist/{chunk-YDICIB2A.js → chunk-S4Y44CCC.js} +2 -2
  35. package/dist/{chunk-K2C3KFGB.js → chunk-SEM6WD7J.js} +29 -17
  36. package/dist/{chunk-CQZYQAAV.js → chunk-SLCNCAWY.js} +3 -3
  37. package/dist/{chunk-L4MFGGSI.js → chunk-SPZ42EWE.js} +2 -2
  38. package/dist/{chunk-QOFSPFJ6.js → chunk-TCW2H47H.js} +3405 -3395
  39. package/dist/{chunk-FQAJSNNU.js → chunk-TPGJXENR.js} +3 -3
  40. package/dist/chunk-UKR64U7J.js +20 -0
  41. package/dist/{chunk-66F3HLW4.js → chunk-XB363ZXT.js} +122 -4
  42. package/dist/{chunk-UD3BEEBQ.js → chunk-XZ2TDH3J.js} +80 -3
  43. package/dist/{chunk-QSIADSMQ.js → chunk-Z6WRFOFT.js} +3 -3
  44. package/dist/{claude-GT2BPXEL.js → claude-XVLF4N4S.js} +3 -3
  45. package/dist/{cli-IV5DJCXU.js → cli-6FWRBCWM.js} +8 -8
  46. package/dist/{cli-6HTAJ54L.js → cli-BEEDAD4E.js} +7 -7
  47. package/dist/cli.js +11 -11
  48. package/dist/{completion-PPM7MEI2.js → completion-LHYNCQ3N.js} +7 -7
  49. package/dist/{diagnostics-EWU2ROTG.js → diagnostics-ABTJUYZQ.js} +5 -6
  50. package/dist/{doctor-ZWZQMDKZ.js → doctor-GPPO5L4F.js} +36 -36
  51. package/dist/{entry-NDICBQ2F.js → entry-ARGY5CKA.js} +14 -15
  52. package/dist/{exec-mcp-AG4G7SG7.js → exec-mcp-JEF74XVP.js} +16 -14
  53. package/dist/{harness-JABSZCAA.js → harness-OCXW6YE4.js} +6 -6
  54. package/dist/harness-launch-gate.js +3 -4
  55. package/dist/harness-worker.js +5 -6
  56. package/dist/hook-body.js +247 -86
  57. package/dist/{hook-spec-C7umArqw.d.ts → hook-spec-hZL4MSgi.d.ts} +8 -3
  58. package/dist/hooks-JHXUN5MD.js +24 -0
  59. package/dist/{host-2SZRMHZX.js → host-OBRHBDRE.js} +6 -7
  60. package/dist/{host-BWZ5LA4Q.js → host-VI4ZFCZP.js} +18 -16
  61. package/dist/{host-run-SXLV4LHI.js → host-run-H7AITG7C.js} +5 -7
  62. package/dist/http.js +1 -1
  63. package/dist/{import-mcp-2M7SZRVQ.js → import-mcp-3Y33CUHF.js} +15 -12
  64. package/dist/index.d.ts +11 -2
  65. package/dist/index.js +25 -25
  66. package/dist/{init-HOOIFBAD.js → init-WZJHMWNJ.js} +3 -3
  67. package/dist/{install-HF6CROQP.js → install-7V6NIA7W.js} +4 -4
  68. package/dist/{invoke-JP4MILYY.js → invoke-GWWTXQLO.js} +7 -8
  69. package/dist/{list-UBSBUZKS.js → list-Y6UPLGNF.js} +21 -18
  70. package/dist/{logout-OO3DERRK.js → logout-KAUW4JZZ.js} +16 -13
  71. package/dist/{logs-K3QXKRD4.js → logs-74JGLQG6.js} +4 -4
  72. package/dist/{mailbox-DAJV6VAI.js → mailbox-VK5AVTHI.js} +7 -7
  73. package/dist/{mainline-6K5BA3WX.js → mainline-Q42M2GJ2.js} +173 -34
  74. package/dist/{mcp-JXNTKRJG.js → mcp-IDEUIY2F.js} +2 -2
  75. package/dist/{pause-GRVTSKOK.js → pause-CZ2OZYLC.js} +4 -4
  76. package/dist/project/hook-adapter.d.ts +1 -1
  77. package/dist/{project-M672MKQH.js → project-GVVWLDOJ.js} +5 -5
  78. package/dist/{pty-LHKJKY2E.js → pty-CDLQ4NP2.js} +3 -3
  79. package/dist/report-Z3JV2PCT.js +105 -0
  80. package/dist/{resume-6DMPGG3N.js → resume-DFIHT2RO.js} +4 -4
  81. package/dist/{run-ORBIERI3.js → run-HVNKQHVU.js} +4 -4
  82. package/dist/{run-5W566T3V.js → run-RRWB7U2Q.js} +15 -12
  83. package/dist/{serve-73SRPAV4.js → serve-KJSOU3BR.js} +3 -3
  84. package/dist/{session-XM2CR425.js → session-YZVX4NGN.js} +4 -4
  85. package/dist/{setup-ULKDPF5B.js → setup-3GET6K3J.js} +4 -4
  86. package/dist/smoke-FQQJOQBD.js +16 -0
  87. package/dist/{start-login-BGFAMCZL.js → start-login-RNHSEX5P.js} +16 -13
  88. package/dist/{status-YHXEAJ7U.js → status-3RTGDN2K.js} +10 -10
  89. package/dist/{status-YCW6YJ3S.js → status-RR4VZARJ.js} +40 -23
  90. package/dist/{status-73FEFQUQ.js → status-Y25ONHA5.js} +16 -13
  91. package/dist/stdio.js +2 -2
  92. package/dist/{sweep-XF2HG3EO.js → sweep-EPJMEZR6.js} +4 -4
  93. package/dist/{test-IMNBXOYW.js → test-7NYPQ6YU.js} +30 -20
  94. package/dist/{tui-5GDA22TB.js → tui-H5RPSF4B.js} +4 -4
  95. package/dist/{unbroadcast-XP3OCVN3.js → unbroadcast-NTOC3PY3.js} +4 -4
  96. package/dist/{worker-RV6NGSXT.js → worker-YWFTWIBP.js} +9 -10
  97. package/dist/{worktree-list-4PLE7K6L.js → worktree-list-EMKUMCTQ.js} +2 -2
  98. package/dist/{worktree-sync-GQVYAXGJ.js → worktree-sync-A277AF4M.js} +4 -6
  99. package/docs/commands.md +14 -7
  100. package/docs/git-workflow.md +53 -13
  101. package/docs/hooks.md +138 -10
  102. package/docs/project-configuration.md +31 -1
  103. package/docs/upgrading.md +58 -0
  104. package/gemini-extension.json +2 -2
  105. package/mcp.json +1 -1
  106. package/package.json +5 -5
  107. package/plugin.json +1 -1
  108. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  109. package/plugins/pmcp/.mcp.json +1 -1
  110. package/plugins/pmcp/gemini-extension.json +2 -2
  111. package/plugins/pmcp/mcp.json +1 -1
  112. package/plugins/pmcp/mod/sessions/format.ts +2 -2
  113. package/plugins/pmcp/plugin.json +1 -1
  114. package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +11 -8
  115. package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +11 -7
  116. package/skills/agent-assets-migrate/SKILL.md +11 -8
  117. package/skills/pmcp-project-init/SKILL.md +11 -7
  118. package/dist/chunk-7SDOSTW7.js +0 -130
  119. package/dist/chunk-AWZF72SH.js +0 -1025
  120. package/dist/chunk-FGYFA6JY.js +0 -7
  121. package/dist/chunk-ICF2JZSN.js +0 -92
  122. package/dist/chunk-ISNRDHSD.js +0 -74
  123. package/dist/chunk-QDY6BWE6.js +0 -396
  124. package/dist/hooks-YVQSDQV3.js +0 -21
package/dist/hook-body.js CHANGED
@@ -1550,8 +1550,8 @@ import { basename as basename3 } from "node:path";
1550
1550
  // src/sessions/format.ts
1551
1551
  var STATE_FILES = {
1552
1552
  records: "sessions",
1553
- // The records' former directory. Deprecated: 0.20 still writes every record there too and
1554
- // reads it when sessions/ lacks one; 0.21 stops writing it.
1553
+ // The records' former directory. Deprecated: read beside sessions/ but no longer written; a
1554
+ // pmcp before 0.20 sharing the state directory still writes there.
1555
1555
  legacyRecords: "fleet",
1556
1556
  pause: "pause.json",
1557
1557
  broadcast: "broadcast.json",
@@ -3131,6 +3131,53 @@ function installIfStale(root, spec, report2) {
3131
3131
  return 0;
3132
3132
  }
3133
3133
 
3134
+ // src/git/superseded.ts
3135
+ import { join as join8 } from "node:path";
3136
+ var GITLINK2 = /^:160000 160000 [0-9a-f]{40} ([0-9a-f]{40}) M$/u;
3137
+ function submoduleRepo(cwd, path) {
3138
+ const checkout = join8(cwd, path);
3139
+ if (existsSync(join8(checkout, ".git"))) return checkout;
3140
+ const common = gitText(cwd, [
3141
+ "rev-parse",
3142
+ "--path-format=absolute",
3143
+ "--git-common-dir"
3144
+ ]);
3145
+ const kept = common ? join8(common, "modules", path) : "";
3146
+ return kept && existsSync(kept) ? kept : null;
3147
+ }
3148
+ function pinsSuperseded(cwd, upstream, sha) {
3149
+ const parents = gitText(cwd, ["rev-list", "--parents", "-n", "1", sha]);
3150
+ if (parents.split(" ").length !== 2) return false;
3151
+ const diff = git(cwd, [
3152
+ "diff-tree",
3153
+ "--raw",
3154
+ "--no-commit-id",
3155
+ "--no-renames",
3156
+ "--abbrev=40",
3157
+ "-z",
3158
+ "-r",
3159
+ `${sha}^`,
3160
+ sha
3161
+ ]);
3162
+ const fields2 = diff.stdout.split("\0").slice(0, -1);
3163
+ if (diff.status !== 0 || fields2.length === 0 || fields2.length % 2 !== 0)
3164
+ return false;
3165
+ for (let index = 0; index < fields2.length; index += 2) {
3166
+ const pin = GITLINK2.exec(fields2[index] ?? "")?.[1];
3167
+ const path = fields2[index + 1];
3168
+ if (pin === void 0 || !path) return false;
3169
+ const listed = gitText(cwd, ["ls-tree", upstream, "--", path]);
3170
+ const theirs = /^160000 commit ([0-9a-f]{40})\t/u.exec(listed)?.[1];
3171
+ if (theirs === void 0) return false;
3172
+ if (theirs === pin) continue;
3173
+ const repo = submoduleRepo(cwd, path);
3174
+ if (repo === null) return false;
3175
+ if (git(repo, ["merge-base", "--is-ancestor", pin, theirs]).status !== 0)
3176
+ return false;
3177
+ }
3178
+ return true;
3179
+ }
3180
+
3134
3181
  // src/git/landed.ts
3135
3182
  function cherry(cwd, upstream, head = "HEAD") {
3136
3183
  const listed = git(cwd, ["cherry", "-v", upstream, head]).stdout;
@@ -3138,7 +3185,10 @@ function cherry(cwd, upstream, head = "HEAD") {
3138
3185
  const missing = [];
3139
3186
  for (const line of listed.split("\n")) {
3140
3187
  if (line.startsWith("- ")) carried.push(line.slice(2));
3141
- if (line.startsWith("+ ")) missing.push(line.slice(2));
3188
+ if (!line.startsWith("+ ")) continue;
3189
+ const sha = line.slice(2).split(" ")[0] ?? "";
3190
+ if (pinsSuperseded(cwd, upstream, sha)) carried.push(line.slice(2));
3191
+ else missing.push(line.slice(2));
3142
3192
  }
3143
3193
  return { carried, missing };
3144
3194
  }
@@ -3155,7 +3205,7 @@ function distance(cwd, upstream) {
3155
3205
  }
3156
3206
 
3157
3207
  // src/git/submodules.ts
3158
- import { join as join8 } from "node:path";
3208
+ import { join as join9 } from "node:path";
3159
3209
  function clean(dir) {
3160
3210
  return git(dir, ["status", "--porcelain"]).stdout.trim() === "";
3161
3211
  }
@@ -3165,8 +3215,8 @@ function hasCommit(dir, sha) {
3165
3215
  function movableSubmodules(root) {
3166
3216
  const listed = git(root, ["submodule", "status"]).stdout;
3167
3217
  return listed.split("\n").filter((line) => /^[ +]/u.test(line)).map((line) => line.trim().split(/\s+/u)[1] ?? "").filter((path) => {
3168
- const dir = join8(root, path);
3169
- if (!path || !existsSync(join8(dir, ".git"))) return false;
3218
+ const dir = join9(root, path);
3219
+ if (!path || !existsSync(join9(dir, ".git"))) return false;
3170
3220
  const local = gitText(dir, [
3171
3221
  "rev-list",
3172
3222
  "--count",
@@ -3181,7 +3231,7 @@ function updateToPins(root, paths) {
3181
3231
  const lines = [];
3182
3232
  for (const path of paths) {
3183
3233
  const pin = gitText(root, ["rev-parse", `HEAD:${path}`]);
3184
- const dir = join8(root, path);
3234
+ const dir = join9(root, path);
3185
3235
  if (!pin || !hasCommit(dir, pin)) {
3186
3236
  lines.push(
3187
3237
  `${path}: left alone, ${pin.slice(0, 10) || "its pin"} is not in its checkout`
@@ -3375,6 +3425,20 @@ var worktreeSync = {
3375
3425
  // src/hooks/policies/custom.ts
3376
3426
  import { isAbsolute as isAbsolute6, relative as relative7, resolve as resolve12 } from "node:path";
3377
3427
  var FAILED = "Guard failed validation or execution";
3428
+ var GUARD_PROTOCOL = "pmcp.guard.v1";
3429
+ var MAX_FINDINGS = 20;
3430
+ var MAX_REASON = 2e3;
3431
+ var EVENTS = {
3432
+ before_shell: { event: "before_tool", tool: "shell" },
3433
+ after_edit: { event: "after_tool", tool: "edit" },
3434
+ stop: { event: "stop" },
3435
+ session_start: { event: "session_start" },
3436
+ prompt: { event: "prompt" }
3437
+ };
3438
+ function customMode(entry) {
3439
+ const mode = entry.mode ?? "deny";
3440
+ return entry.event === "session_start" && (mode === "deny" || mode === "ask") ? "warn" : mode;
3441
+ }
3378
3442
  function inside(base, path) {
3379
3443
  const rest = relative7(base, path);
3380
3444
  return rest !== "" && !rest.startsWith("..") && !isAbsolute6(rest);
@@ -3382,7 +3446,9 @@ function inside(base, path) {
3382
3446
  function guardScript(root, command6) {
3383
3447
  const script = command6[0]?.startsWith(".agents/guards/") ? command6[0] : command6[1];
3384
3448
  if (!script?.startsWith(".agents/guards/")) {
3385
- throw new Error("Hook command must execute a script under .agents/guards/");
3449
+ throw new Error(
3450
+ "Hook command must execute a script under .agents/guards/, or name an installed program with version"
3451
+ );
3386
3452
  }
3387
3453
  const base = resolve12(root, ".agents/guards");
3388
3454
  if (!inside(base, resolve12(root, script)))
@@ -3399,13 +3465,48 @@ function guardHash(root, command6) {
3399
3465
  }
3400
3466
  function applies(entry, input) {
3401
3467
  if (!entry.targets.includes(input.runtime)) return false;
3402
- if (entry.event === "before_shell")
3403
- return input.event === "before_tool" && input.tool?.kind === "shell";
3404
- return input.event === "after_tool" && input.tool?.kind === "edit";
3468
+ const { event, tool } = EVENTS[entry.event];
3469
+ return input.event === event && (!tool || input.tool?.kind === tool);
3405
3470
  }
3406
- function run2(entry, input) {
3471
+ function readFindings(value) {
3472
+ if (value === void 0) return [];
3473
+ if (!Array.isArray(value)) return null;
3474
+ const found = [];
3475
+ for (const item of value) {
3476
+ if (!item || typeof item !== "object" || Array.isArray(item)) return null;
3477
+ const { path, line, message, ...rest } = item;
3478
+ if (Object.keys(rest).length > 0 || typeof message !== "string")
3479
+ return null;
3480
+ if (path !== void 0 && typeof path !== "string") return null;
3481
+ if (line !== void 0 && (!Number.isSafeInteger(line) || line < 1))
3482
+ return null;
3483
+ found.push({
3484
+ message,
3485
+ ...path !== void 0 ? { path } : {},
3486
+ ...line !== void 0 ? { line } : {}
3487
+ });
3488
+ }
3489
+ return found;
3490
+ }
3491
+ function findingLine(finding) {
3492
+ const where = finding.path ? `${finding.path}${finding.line ? `:${finding.line}` : ""}: ` : "";
3493
+ return `${where}${finding.message}`;
3494
+ }
3495
+ function request(entry, input) {
3496
+ return JSON.stringify({
3497
+ protocol: GUARD_PROTOCOL,
3498
+ runtime: input.runtime,
3499
+ event: entry.event,
3500
+ session: input.session.id,
3501
+ command: input.tool?.command ?? "",
3502
+ cwd: input.cwd,
3503
+ paths: input.tool?.paths ?? [],
3504
+ ...entry.event === "prompt" ? { prompt: input.prompt ?? "" } : {}
3505
+ });
3506
+ }
3507
+ function run2(entry, input, log) {
3407
3508
  const root = input.projectRoot;
3408
- if (guardHash(root, entry.command) !== entry.guardSha256) {
3509
+ if (entry.guardSha256 !== void 0 && guardHash(root, entry.command) !== entry.guardSha256) {
3409
3510
  return {
3410
3511
  verdict: "deny",
3411
3512
  reason: "Guard source changed; review it and run pmcp project"
@@ -3417,13 +3518,7 @@ function run2(entry, input) {
3417
3518
  const result = spawnSync(args[0], args.slice(1), {
3418
3519
  cwd: root,
3419
3520
  env: { PATH: process.env["PATH"], LANG: "C.UTF-8" },
3420
- input: JSON.stringify({
3421
- runtime: input.runtime,
3422
- event: entry.event,
3423
- command: input.tool?.command ?? "",
3424
- cwd: input.cwd,
3425
- paths: input.tool?.paths ?? []
3426
- }),
3521
+ input: request(entry, input),
3427
3522
  encoding: "utf8",
3428
3523
  timeout: entry.timeoutMs,
3429
3524
  killSignal: "SIGKILL",
@@ -3433,28 +3528,40 @@ function run2(entry, input) {
3433
3528
  return { verdict: "deny", reason: FAILED };
3434
3529
  const response = JSON.parse(result.stdout);
3435
3530
  const extra = Object.keys(response).some(
3436
- (key) => key !== "decision" && key !== "reason"
3531
+ (key) => !["decision", "reason", "findings", "protocol"].includes(key)
3437
3532
  );
3438
3533
  const reason2 = response["reason"];
3439
- if (extra || reason2 !== void 0 && typeof reason2 !== "string")
3534
+ const findings = readFindings(response["findings"]);
3535
+ if (extra || findings === null || reason2 !== void 0 && typeof reason2 !== "string" || response["protocol"] !== void 0 && response["protocol"] !== GUARD_PROTOCOL)
3440
3536
  return { verdict: "deny", reason: FAILED };
3441
- if (response["decision"] === "allow") return pass;
3537
+ const lines = findings.slice(0, MAX_FINDINGS).map(findingLine);
3538
+ if (findings.length > MAX_FINDINGS)
3539
+ lines.push(`and ${findings.length - MAX_FINDINGS} more`);
3540
+ if (lines.length > 0)
3541
+ log.info("guard findings", {
3542
+ decision: String(response["decision"]),
3543
+ findings: findings.length
3544
+ });
3545
+ if (response["decision"] === "allow")
3546
+ return lines.length > 0 ? { context: [`pmcp custom.${entry.name}:
3547
+ ${lines.join("\n")}`] } : pass;
3442
3548
  if (response["decision"] !== "deny")
3443
3549
  return { verdict: "deny", reason: FAILED };
3444
- return {
3445
- verdict: "deny",
3446
- reason: typeof reason2 === "string" ? reason2.slice(0, 2e3) : FAILED
3447
- };
3550
+ const text9 = [typeof reason2 === "string" ? reason2 : FAILED, ...lines].join(
3551
+ "\n"
3552
+ );
3553
+ return { verdict: "deny", reason: text9.slice(0, MAX_REASON) };
3448
3554
  }
3449
3555
  function customPolicy(entry) {
3556
+ const { event, tool } = EVENTS[entry.event];
3450
3557
  return {
3451
3558
  id: `custom.${entry.name}`,
3452
- events: [entry.event === "before_shell" ? "before_tool" : "after_tool"],
3453
- tools: [entry.event === "before_shell" ? "shell" : "edit"],
3559
+ events: [event],
3560
+ ...tool ? { tools: [tool] } : {},
3454
3561
  fail: "closed",
3455
3562
  defaultMode: "deny",
3456
3563
  options: () => ({}),
3457
- evaluate: (input) => applies(entry, input) ? run2(entry, input) : pass
3564
+ evaluate: (input, ctx) => applies(entry, input) ? run2(entry, input, ctx.log) : pass
3458
3565
  };
3459
3566
  }
3460
3567
 
@@ -3526,7 +3633,7 @@ function selectPolicies(compiled, input) {
3526
3633
  }));
3527
3634
  const custom = compiled.custom.map((entry) => ({
3528
3635
  policy: customPolicy(entry),
3529
- mode: "deny",
3636
+ mode: customMode(entry),
3530
3637
  options: {}
3531
3638
  }));
3532
3639
  return [...guards, ...custom].filter((selected) => listens(selected, input));
@@ -3579,14 +3686,30 @@ function toolKind(name) {
3579
3686
  return TOOL_KINDS[name] ?? "other";
3580
3687
  }
3581
3688
 
3689
+ // src/hooks/runtimes/answer.ts
3690
+ function readAnswer(stdout, pick) {
3691
+ const text9 = stdout.trim();
3692
+ if (!text9) return "allow";
3693
+ try {
3694
+ const out = JSON.parse(text9);
3695
+ if (!out || typeof out !== "object" || Array.isArray(out)) return null;
3696
+ return pick(out);
3697
+ } catch {
3698
+ return null;
3699
+ }
3700
+ }
3701
+ function field(value, key) {
3702
+ return value && typeof value === "object" ? value[key] : void 0;
3703
+ }
3704
+
3582
3705
  // src/hooks/runtimes/antigravity/output.ts
3583
- var MAX_REASON = 2e3;
3706
+ var MAX_REASON2 = 2e3;
3584
3707
  function silent(event) {
3585
3708
  return event === "before_tool" ? '{"decision":"allow"}\n' : "{}\n";
3586
3709
  }
3587
3710
  function render(input, decision) {
3588
3711
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
3589
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON);
3712
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON2);
3590
3713
  if (input.event === "before_tool") {
3591
3714
  const out2 = blocking ? { decision: "deny", reason: reason2 } : { decision: "allow" };
3592
3715
  return { stdout: `${JSON.stringify(out2)}
@@ -3605,6 +3728,12 @@ function render(input, decision) {
3605
3728
  return { stdout: `${JSON.stringify(out)}
3606
3729
  `, exitCode: 0 };
3607
3730
  }
3731
+ function verdict(stdout) {
3732
+ return readAnswer(
3733
+ stdout,
3734
+ (out) => out["decision"] === "deny" ? "deny" : "allow"
3735
+ );
3736
+ }
3608
3737
 
3609
3738
  // src/hooks/runtimes/antigravity/payload.ts
3610
3739
  import { isAbsolute as isAbsolute7, resolve as resolve13 } from "node:path";
@@ -3723,6 +3852,7 @@ var antigravity = {
3723
3852
  },
3724
3853
  normalize,
3725
3854
  render,
3855
+ readVerdict: verdict,
3726
3856
  silent,
3727
3857
  project,
3728
3858
  nativeFiles: [{ file: HOOKS_FILE, root: HOOK_SET }],
@@ -3783,11 +3913,11 @@ function matcherFor(tools) {
3783
3913
  }
3784
3914
 
3785
3915
  // src/hooks/runtimes/claude/output.ts
3786
- var MAX_REASON2 = 2e3;
3916
+ var MAX_REASON3 = 2e3;
3787
3917
  function render2(input, decision) {
3788
3918
  const hookEventName = NATIVE_EVENTS2[input.event];
3789
3919
  const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
3790
- const reason2 = decision.reason?.slice(0, MAX_REASON2);
3920
+ const reason2 = decision.reason?.slice(0, MAX_REASON3);
3791
3921
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
3792
3922
  const out = shape(input, decision, {
3793
3923
  hookEventName,
@@ -3829,6 +3959,12 @@ function shape(input, decision, parts) {
3829
3959
  if (input.event === "session_start" && context) return contextOnly;
3830
3960
  return null;
3831
3961
  }
3962
+ function verdict2(stdout) {
3963
+ return readAnswer(stdout, (out) => {
3964
+ const decision = field(out["hookSpecificOutput"], "permissionDecision");
3965
+ return decision === "deny" || decision === "ask" ? decision : "allow";
3966
+ });
3967
+ }
3832
3968
 
3833
3969
  // src/hooks/runtimes/claude/payload.ts
3834
3970
  import { isAbsolute as isAbsolute8, resolve as resolve14 } from "node:path";
@@ -3978,6 +4114,7 @@ var claude = {
3978
4114
  },
3979
4115
  normalize: normalize2,
3980
4116
  render: render2,
4117
+ readVerdict: verdict2,
3981
4118
  project: project2,
3982
4119
  nativeFiles: [{ file: SETTINGS_FILE, root: "hooks" }],
3983
4120
  nativeEvent: (event) => NATIVE_EVENTS2[event],
@@ -4033,11 +4170,11 @@ function matcherFor2(tools) {
4033
4170
  }
4034
4171
 
4035
4172
  // src/hooks/runtimes/codex/output.ts
4036
- var MAX_REASON3 = 2e3;
4173
+ var MAX_REASON4 = 2e3;
4037
4174
  function render3(input, decision) {
4038
4175
  const hookEventName = NATIVE_EVENTS3[input.event];
4039
4176
  const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
4040
- const reason2 = decision.reason?.slice(0, MAX_REASON3);
4177
+ const reason2 = decision.reason?.slice(0, MAX_REASON4);
4041
4178
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4042
4179
  const out = shape2(input, decision, {
4043
4180
  hookEventName,
@@ -4080,6 +4217,12 @@ function shape2(input, decision, parts) {
4080
4217
  if (input.event === "session_start" && context) return contextOnly;
4081
4218
  return null;
4082
4219
  }
4220
+ function verdict3(stdout) {
4221
+ return readAnswer(stdout, (out) => {
4222
+ const decision = field(out["hookSpecificOutput"], "permissionDecision");
4223
+ return decision === "deny" || decision === "ask" ? decision : "allow";
4224
+ });
4225
+ }
4083
4226
 
4084
4227
  // src/hooks/runtimes/codex/payload.ts
4085
4228
  import { isAbsolute as isAbsolute9, resolve as resolve15 } from "node:path";
@@ -4209,6 +4352,7 @@ var codex = {
4209
4352
  },
4210
4353
  normalize: normalize3,
4211
4354
  render: render3,
4355
+ readVerdict: verdict3,
4212
4356
  project: project3,
4213
4357
  nativeFiles: [{ file: HOOKS_FILE2, root: "hooks" }],
4214
4358
  nativeEvent: (event) => NATIVE_EVENTS3[event],
@@ -4267,7 +4411,7 @@ function matcherFor3(tools) {
4267
4411
  }
4268
4412
 
4269
4413
  // src/hooks/runtimes/gemini/output.ts
4270
- var MAX_REASON4 = 2e3;
4414
+ var MAX_REASON5 = 2e3;
4271
4415
  var DELIVERS = [
4272
4416
  "session_start",
4273
4417
  "prompt",
@@ -4275,7 +4419,7 @@ var DELIVERS = [
4275
4419
  ];
4276
4420
  function render4(input, decision) {
4277
4421
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4278
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON4);
4422
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON5);
4279
4423
  const out = {};
4280
4424
  const notes = [...decision.context ?? []];
4281
4425
  if (blocking && input.event === "before_tool")
@@ -4290,6 +4434,12 @@ function render4(input, decision) {
4290
4434
  return { stdout: `${JSON.stringify(out)}
4291
4435
  `, exitCode: 0 };
4292
4436
  }
4437
+ function verdict4(stdout) {
4438
+ return readAnswer(
4439
+ stdout,
4440
+ (out) => out["decision"] === "deny" ? "deny" : "allow"
4441
+ );
4442
+ }
4293
4443
 
4294
4444
  // src/hooks/runtimes/gemini/payload.ts
4295
4445
  import { isAbsolute as isAbsolute10, resolve as resolve16 } from "node:path";
@@ -4405,6 +4555,7 @@ var gemini = {
4405
4555
  },
4406
4556
  normalize: normalize4,
4407
4557
  render: render4,
4558
+ readVerdict: verdict4,
4408
4559
  project: project4,
4409
4560
  nativeFiles: [{ file: SETTINGS_FILE2, root: "hooks" }],
4410
4561
  nativeEvent: (event) => NATIVE_EVENTS4[event],
@@ -4456,7 +4607,7 @@ function toolKind5(name) {
4456
4607
  }
4457
4608
 
4458
4609
  // src/hooks/runtimes/grok/output.ts
4459
- var MAX_REASON5 = 2e3;
4610
+ var MAX_REASON6 = 2e3;
4460
4611
  var DELIVERS2 = [
4461
4612
  "before_tool",
4462
4613
  "after_tool",
@@ -4464,7 +4615,7 @@ var DELIVERS2 = [
4464
4615
  ];
4465
4616
  function render5(input, decision) {
4466
4617
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4467
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON5);
4618
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
4468
4619
  const notes = [...decision.context ?? []];
4469
4620
  const refuse = blocking && input.event === "before_tool";
4470
4621
  if (blocking && !refuse) notes.unshift(reason2);
@@ -4482,6 +4633,12 @@ function render5(input, decision) {
4482
4633
  return { stdout: `${JSON.stringify(out)}
4483
4634
  `, exitCode: 0 };
4484
4635
  }
4636
+ function verdict5(stdout) {
4637
+ return readAnswer(stdout, (out) => {
4638
+ const decision = field(out["hookSpecificOutput"], "permissionDecision");
4639
+ return decision === "deny" || decision === "ask" ? decision : "allow";
4640
+ });
4641
+ }
4485
4642
 
4486
4643
  // src/hooks/runtimes/grok/payload.ts
4487
4644
  import { isAbsolute as isAbsolute11, resolve as resolve17 } from "node:path";
@@ -4604,6 +4761,7 @@ var grok = {
4604
4761
  },
4605
4762
  normalize: normalize5,
4606
4763
  render: render5,
4764
+ readVerdict: verdict5,
4607
4765
  project: project5,
4608
4766
  nativeFiles: [{ file: HOOKS_FILE3, root: "hooks" }],
4609
4767
  nativeEvent: (event) => NATIVE_EVENTS5[event],
@@ -4657,7 +4815,7 @@ function toolKind6(name) {
4657
4815
  }
4658
4816
 
4659
4817
  // src/hooks/runtimes/opencode/output.ts
4660
- var MAX_REASON6 = 2e3;
4818
+ var MAX_REASON7 = 2e3;
4661
4819
  var DELIVERS3 = [
4662
4820
  "session_start",
4663
4821
  "prompt",
@@ -4665,7 +4823,7 @@ var DELIVERS3 = [
4665
4823
  ];
4666
4824
  function render6(input, decision) {
4667
4825
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4668
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
4826
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON7);
4669
4827
  if (input.event === "before_tool") {
4670
4828
  const out2 = blocking ? { deny: reason2 } : {};
4671
4829
  return { stdout: `${JSON.stringify(out2)}
@@ -4678,6 +4836,9 @@ function render6(input, decision) {
4678
4836
  return { stdout: `${JSON.stringify(out)}
4679
4837
  `, exitCode: 0 };
4680
4838
  }
4839
+ function verdict6(stdout) {
4840
+ return readAnswer(stdout, (out) => "deny" in out ? "deny" : "allow");
4841
+ }
4681
4842
 
4682
4843
  // src/hooks/runtimes/opencode/payload.ts
4683
4844
  import { isAbsolute as isAbsolute12, resolve as resolve18 } from "node:path";
@@ -4860,6 +5021,7 @@ var opencode = {
4860
5021
  },
4861
5022
  normalize: normalize6,
4862
5023
  render: render6,
5024
+ readVerdict: verdict6,
4863
5025
  // opencode has no hook configuration to edit; the projection is the generated plugin file.
4864
5026
  project: () => [],
4865
5027
  files,
@@ -4920,18 +5082,18 @@ async function dispatch(raw, compiled, deps) {
4920
5082
  }
4921
5083
 
4922
5084
  // src/hooks/entry/fail-closed.ts
4923
- import { join as join11 } from "node:path";
5085
+ import { join as join12 } from "node:path";
4924
5086
 
4925
5087
  // src/hooks/compiled.ts
4926
- import { join as join10 } from "node:path";
5088
+ import { join as join11 } from "node:path";
4927
5089
 
4928
5090
  // src/hooks/integrity-cache.ts
4929
5091
  import { homedir as homedir2 } from "node:os";
4930
- import { dirname as dirname7, join as join9 } from "node:path";
5092
+ import { dirname as dirname7, join as join10 } from "node:path";
4931
5093
  var LIMIT = 64;
4932
5094
  function cacheFile() {
4933
- const base = process.env["XDG_CACHE_HOME"] || join9(homedir2(), ".cache");
4934
- return join9(base, "pmcp", "hook-verified.json");
5095
+ const base = process.env["XDG_CACHE_HOME"] || join10(homedir2(), ".cache");
5096
+ return join10(base, "pmcp", "hook-verified.json");
4935
5097
  }
4936
5098
  function readCache() {
4937
5099
  try {
@@ -4983,8 +5145,8 @@ var PolicyIntegrityError = class extends Error {
4983
5145
  };
4984
5146
  var MISMATCH = "policy.json does not match pmcp.lock; review the change and run pmcp project";
4985
5147
  function readCompiled(root) {
4986
- const policyPath = join10(root, POLICY_FILE);
4987
- const files2 = [policyPath, join10(root, LOCK_FILE)];
5148
+ const policyPath = join11(root, POLICY_FILE);
5149
+ const files2 = [policyPath, join11(root, LOCK_FILE)];
4988
5150
  const before2 = stampOf(files2);
4989
5151
  const text9 = readFileSync(policyPath, "utf8");
4990
5152
  const lock = JSON.parse(readFileSync(files2[1], "utf8"));
@@ -5007,7 +5169,7 @@ function readCompiled(root) {
5007
5169
  var FAILED_CLOSED = "pmcp hook could not evaluate this call and refused it";
5008
5170
  function rawFailure(root) {
5009
5171
  try {
5010
- const raw = JSON.parse(readFileSync(join11(root, POLICY_FILE), "utf8"))["failure"];
5172
+ const raw = JSON.parse(readFileSync(join12(root, POLICY_FILE), "utf8"))["failure"];
5011
5173
  if (!raw || typeof raw.timeoutMs !== "number" || typeof raw.retry !== "number" || !Array.isArray(raw.pass) || !raw.pass.every(
5012
5174
  (kind) => PASS_KINDS.includes(kind)
5013
5175
  ))
@@ -5042,7 +5204,7 @@ function failClosed(adapter, event, root, error, stated = false) {
5042
5204
  }
5043
5205
 
5044
5206
  // src/hooks/entry/logger.ts
5045
- import { dirname as dirname8, join as join14 } from "node:path";
5207
+ import { dirname as dirname8, join as join15 } from "node:path";
5046
5208
 
5047
5209
  // src/logging/levels.ts
5048
5210
  var LEVEL_RANK = {
@@ -5129,7 +5291,7 @@ function createLogger(sink, settings = DEFAULT_LOG_SETTINGS, fields2 = {}) {
5129
5291
  const enabled = (at) => resolved.enabled && LEVEL_RANK[at] <= limit;
5130
5292
  const write3 = (at, msg, data) => {
5131
5293
  if (!enabled(at)) return;
5132
- const { verdict, duration_ms, ...rest } = data ?? {};
5294
+ const { verdict: verdict7, duration_ms, ...rest } = data ?? {};
5133
5295
  const record = {
5134
5296
  ts: (/* @__PURE__ */ new Date()).toISOString(),
5135
5297
  level: at,
@@ -5139,7 +5301,7 @@ function createLogger(sink, settings = DEFAULT_LOG_SETTINGS, fields2 = {}) {
5139
5301
  event: fields2.event,
5140
5302
  session: fields2.session,
5141
5303
  policy: fields2.policy,
5142
- verdict,
5304
+ verdict: verdict7,
5143
5305
  duration_ms,
5144
5306
  msg,
5145
5307
  data: Object.keys(rest).length > 0 ? redact(rest, resolved.redact) : void 0
@@ -5166,11 +5328,11 @@ var silentLogger = createLogger(() => {
5166
5328
  });
5167
5329
 
5168
5330
  // src/logging/sinks/file.ts
5169
- import { join as join12 } from "node:path";
5331
+ import { join as join13 } from "node:path";
5170
5332
  var FILE = /^pmcp-(\d{8})(?:\.\d+)?\.jsonl$/u;
5171
5333
  function dailyLogFile(dir, now = /* @__PURE__ */ new Date()) {
5172
5334
  const day = now.toISOString().slice(0, 10).replaceAll("-", "");
5173
- return join12(dir, `pmcp-${day}.jsonl`);
5335
+ return join13(dir, `pmcp-${day}.jsonl`);
5174
5336
  }
5175
5337
  function roll(file2) {
5176
5338
  let index = 1;
@@ -5201,7 +5363,7 @@ function logFiles(dir) {
5201
5363
  const part = (name) => Number(/\.(\d+)\.jsonl$/u.exec(name)?.[1] ?? Number.MAX_SAFE_INTEGER);
5202
5364
  return names2.sort(
5203
5365
  (a, b) => a.slice(5, 13).localeCompare(b.slice(5, 13)) || part(a) - part(b)
5204
- ).map((name) => join12(dir, name));
5366
+ ).map((name) => join13(dir, name));
5205
5367
  }
5206
5368
  function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
5207
5369
  const cutoff = new Date(now.getTime() - keepDays * 864e5).toISOString().slice(0, 10).replaceAll("-", "");
@@ -5217,13 +5379,13 @@ function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
5217
5379
 
5218
5380
  // src/sessions/state-dir.ts
5219
5381
  import { homedir as homedir3 } from "node:os";
5220
- import { join as join13 } from "node:path";
5382
+ import { join as join14 } from "node:path";
5221
5383
  function projectStateDir(root, override, env = process.env) {
5222
5384
  if (override) return expandPath(root, override);
5223
5385
  const anchor = gitCommonDir(root) ?? realpathSync(root);
5224
5386
  const id = createHash("sha256").update(anchor).digest("hex").slice(0, 16);
5225
- const base = env["XDG_STATE_HOME"] || join13(homedir3(), ".local", "state");
5226
- return join13(base, "pmcp", "projects", id);
5387
+ const base = env["XDG_STATE_HOME"] || join14(homedir3(), ".local", "state");
5388
+ return join14(base, "pmcp", "projects", id);
5227
5389
  }
5228
5390
 
5229
5391
  // src/hooks/entry/logger.ts
@@ -5238,7 +5400,7 @@ function hookLogger(root, compiled, runtime2, event) {
5238
5400
  process.env["PMCP_LOG"]
5239
5401
  );
5240
5402
  const file2 = compiled?.logFile ? expandPath(root, compiled.logFile) : void 0;
5241
- const dir = file2 ? dirname8(file2) : join14(projectStateDir(root, compiled?.stateDir), "logs");
5403
+ const dir = file2 ? dirname8(file2) : join15(projectStateDir(root, compiled?.stateDir), "logs");
5242
5404
  const sink = fileSink({
5243
5405
  dir,
5244
5406
  ...file2 ? { file: file2 } : {},
@@ -5298,7 +5460,7 @@ var gitProbe = {
5298
5460
  };
5299
5461
 
5300
5462
  // src/sessions/files/broadcast.ts
5301
- import { join as join15 } from "node:path";
5463
+ import { join as join16 } from "node:path";
5302
5464
 
5303
5465
  // src/sessions/files/json.ts
5304
5466
  import { dirname as dirname9 } from "node:path";
@@ -5345,8 +5507,8 @@ function writeLines(path, values) {
5345
5507
 
5346
5508
  // src/sessions/files/broadcast.ts
5347
5509
  function filesBroadcast(dir, keep, registry2) {
5348
- const latestPath = join15(dir, STATE_FILES.broadcast);
5349
- const historyPath = join15(dir, STATE_FILES.history);
5510
+ const latestPath = join16(dir, STATE_FILES.broadcast);
5511
+ const historyPath = join16(dir, STATE_FILES.history);
5350
5512
  const list = () => {
5351
5513
  const latest = asBroadcast(readJson3(latestPath));
5352
5514
  if (!latest) return [];
@@ -5390,9 +5552,9 @@ function filesBroadcast(dir, keep, registry2) {
5390
5552
  }
5391
5553
 
5392
5554
  // src/sessions/files/leases.ts
5393
- import { dirname as dirname10, join as join16 } from "node:path";
5555
+ import { dirname as dirname10, join as join17 } from "node:path";
5394
5556
  function filesLeases(dir, files2 = {}) {
5395
- const leasePath = (name) => files2[name]?.file ?? join16(dir, leaseFile(name));
5557
+ const leasePath = (name) => files2[name]?.file ?? join17(dir, leaseFile(name));
5396
5558
  const read3 = (name) => {
5397
5559
  const lease = asLease(readJson3(leasePath(name)));
5398
5560
  if (!lease || !alive(lease.pid)) return null;
@@ -5442,28 +5604,28 @@ function filesLeases(dir, files2 = {}) {
5442
5604
  }
5443
5605
 
5444
5606
  // src/sessions/files/mailbox.ts
5445
- import { join as join17 } from "node:path";
5607
+ import { join as join18 } from "node:path";
5446
5608
  var ID = /^\d{13}-[0-9a-f]{8}$/u;
5447
5609
  var SAFE_KEY = /^@?[\w.-]+$/u;
5448
5610
  function filesMailbox(dir, settings) {
5449
- const messages = join17(dir, "messages");
5450
- const inbox = join17(dir, "inbox");
5451
- const pathOf = (id) => join17(messages, `${id}.json`);
5611
+ const messages = join18(dir, "messages");
5612
+ const inbox = join18(dir, "inbox");
5613
+ const pathOf = (id) => join18(messages, `${id}.json`);
5452
5614
  const marker = (key, id, kind) => {
5453
5615
  if (!SAFE_KEY.test(key) || !ID.test(id))
5454
5616
  throw new Error(`invalid mailbox key ${key} or id ${id}`);
5455
- return join17(inbox, key, `${id}.${kind}`);
5617
+ return join18(inbox, key, `${id}.${kind}`);
5456
5618
  };
5457
5619
  const audit = (event, fields2) => {
5458
5620
  if (!settings.audit) return;
5459
5621
  const line = { at: (/* @__PURE__ */ new Date()).toISOString(), event, ...fields2 };
5460
- appendFileSync(join17(dir, "messages.jsonl"), `${JSON.stringify(line)}
5622
+ appendFileSync(join18(dir, "messages.jsonl"), `${JSON.stringify(line)}
5461
5623
  `, {
5462
5624
  mode: 384
5463
5625
  });
5464
5626
  };
5465
5627
  const touch = (path) => {
5466
- mkdirSync(join17(path, ".."), { recursive: true, mode: 448 });
5628
+ mkdirSync(join18(path, ".."), { recursive: true, mode: 448 });
5467
5629
  try {
5468
5630
  writeFileSync(path, "", { flag: "wx", mode: 384 });
5469
5631
  return true;
@@ -5480,7 +5642,7 @@ function filesMailbox(dir, settings) {
5480
5642
  if (existsSync(inbox))
5481
5643
  for (const key of readdirSync(inbox))
5482
5644
  for (const kind of ["ack", "delivered"])
5483
- rmSync(join17(inbox, key, `${message.id}.${kind}`), { force: true });
5645
+ rmSync(join18(inbox, key, `${message.id}.${kind}`), { force: true });
5484
5646
  audit(event, { id: message.id });
5485
5647
  };
5486
5648
  return {
@@ -5556,9 +5718,9 @@ function filesMailbox(dir, settings) {
5556
5718
  }
5557
5719
 
5558
5720
  // src/sessions/files/pause.ts
5559
- import { join as join18 } from "node:path";
5721
+ import { join as join19 } from "node:path";
5560
5722
  function filesPause(dir) {
5561
- const path = join18(dir, STATE_FILES.pause);
5723
+ const path = join19(dir, STATE_FILES.pause);
5562
5724
  return {
5563
5725
  read: () => asPause(readJson3(path)),
5564
5726
  write(pause2) {
@@ -5576,13 +5738,12 @@ function filesPause(dir) {
5576
5738
  }
5577
5739
 
5578
5740
  // src/sessions/files/registry.ts
5579
- import { join as join19 } from "node:path";
5741
+ import { join as join20 } from "node:path";
5580
5742
  var SESSION_ID = /^[A-Za-z0-9_-]{8,64}$/u;
5581
5743
  function filesRegistry(dir, staleMs) {
5582
- const dirs = [STATE_FILES.records, STATE_FILES.legacyRecords].map(
5583
- (name) => join19(dir, name)
5584
- );
5585
- const pathsOf = (session) => dirs.map((records) => join19(records, `${session}.json`));
5744
+ const records = join20(dir, STATE_FILES.records);
5745
+ const dirs = [records, join20(dir, STATE_FILES.legacyRecords)];
5746
+ const pathsOf = (session) => dirs.map((records2) => join20(records2, `${session}.json`));
5586
5747
  const get = (session) => {
5587
5748
  if (!SESSION_ID.test(session)) return null;
5588
5749
  return latestRecord(
@@ -5601,7 +5762,7 @@ function filesRegistry(dir, staleMs) {
5601
5762
  for (const name of names2)
5602
5763
  found.set(name, [
5603
5764
  ...found.get(name) ?? [],
5604
- asRecord(readJson3(join19(folder, name)))
5765
+ asRecord(readJson3(join20(folder, name)))
5605
5766
  ]);
5606
5767
  }
5607
5768
  return [...found.values()].map(latestRecord).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
@@ -5628,7 +5789,7 @@ function filesRegistry(dir, staleMs) {
5628
5789
  next["worktree"] = checkout?.root ?? "";
5629
5790
  next["branch"] = checkout?.branch ?? "";
5630
5791
  }
5631
- for (const path of pathsOf(session)) writeJson(path, next);
5792
+ writeJson(join20(records, `${session}.json`), next);
5632
5793
  return next;
5633
5794
  },
5634
5795
  sweep(now = Date.now()) {
@@ -5679,15 +5840,15 @@ function createFilesStore(dir, options2 = {}) {
5679
5840
  }
5680
5841
 
5681
5842
  // src/sessions/lease-files.ts
5682
- import { dirname as dirname11, isAbsolute as isAbsolute13, join as join20 } from "node:path";
5843
+ import { dirname as dirname11, isAbsolute as isAbsolute13, join as join21 } from "node:path";
5683
5844
  var GATE_DIR = "${gate_dir}/";
5684
5845
  function gateTree(root, stateDir, gate, env) {
5685
5846
  const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
5686
5847
  if (override) return override;
5687
- return gate.tree ? expandPath(root, gate.tree) : join20(stateDir, "gate", "tree");
5848
+ return gate.tree ? expandPath(root, gate.tree) : join21(stateDir, "gate", "tree");
5688
5849
  }
5689
5850
  function resolveLeaseFiles(files2, gateDir) {
5690
- const resolve20 = (path) => path?.startsWith(GATE_DIR) ? join20(gateDir, path.slice(GATE_DIR.length)) : path;
5851
+ const resolve20 = (path) => path?.startsWith(GATE_DIR) ? join21(gateDir, path.slice(GATE_DIR.length)) : path;
5691
5852
  return Object.fromEntries(
5692
5853
  Object.entries(files2 ?? {}).map(([name, f]) => {
5693
5854
  const file2 = resolve20(f.file);