@modootoday/pmcp 0.19.9 → 0.21.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 (128) 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-TM6B2Y3G.js → apply-6FLMTJDV.js} +57 -23
  6. package/dist/{attachment-D84OGI6n.d.ts → attachment-ms6s8Aow.d.ts} +1 -1
  7. package/dist/{available-HYSDAFYH.js → available-BFXLII4A.js} +7 -7
  8. package/dist/{broadcast-DSCHWUMB.js → broadcast-ZALGUJVR.js} +4 -4
  9. package/dist/chunk-2GI5RM3M.js +53 -0
  10. package/dist/{chunk-ICF2JZSN.js → chunk-2MAD4WNZ.js} +2 -2
  11. package/dist/{chunk-QYQGPDBE.js → chunk-33KGCJB2.js} +2 -2
  12. package/dist/{chunk-XNPOHPMJ.js → chunk-3X5JQYKN.js} +3 -3
  13. package/dist/{chunk-4XNAKVSO.js → chunk-57Q75MS4.js} +18 -18
  14. package/dist/{chunk-2S44RDO4.js → chunk-5FW7A6TG.js} +7 -4
  15. package/dist/chunk-5YCKFU5Q.js +1672 -0
  16. package/dist/{chunk-MCYGYZVZ.js → chunk-7FV2LORT.js} +2 -2
  17. package/dist/{chunk-57FHYW74.js → chunk-DEY23WTH.js} +122 -4
  18. package/dist/chunk-DJZPPCJP.js +274 -0
  19. package/dist/{chunk-4XWVLC23.js → chunk-G6JXCUSK.js} +2 -2
  20. package/dist/{chunk-T6GOWHK6.js → chunk-GFOQDLPL.js} +6 -1
  21. package/dist/{chunk-PG42KALG.js → chunk-GQP4GWU4.js} +5 -5
  22. package/dist/chunk-H4ZOKIER.js +7 -0
  23. package/dist/{chunk-XPWIJOZT.js → chunk-JQVSDPFL.js} +3 -3
  24. package/dist/{chunk-OG7QR2DP.js → chunk-KEHB4FZP.js} +17 -2
  25. package/dist/chunk-KUBHGVTD.js +126 -0
  26. package/dist/{chunk-SPUCY4AG.js → chunk-KVNNVLJR.js} +2 -2
  27. package/dist/chunk-LFFIQBNY.js +115 -0
  28. package/dist/{chunk-V7HG3STC.js → chunk-MR5IBS6L.js} +31 -15
  29. package/dist/{chunk-W5RLIUNC.js → chunk-NHUMPEPV.js} +2 -2
  30. package/dist/{chunk-I4DLMIN5.js → chunk-OFJIMBTL.js} +2 -2
  31. package/dist/{chunk-A6TM4NTI.js → chunk-OFPNCLG7.js} +2 -2
  32. package/dist/{chunk-3UOFHLY4.js → chunk-OS5DF3LL.js} +207 -15
  33. package/dist/{chunk-BZ2RXI5I.js → chunk-POTI2RJ6.js} +2 -2
  34. package/dist/{chunk-QTKD7JEL.js → chunk-R3MVL67T.js} +34 -34
  35. package/dist/{chunk-YN5GQCHN.js → chunk-RHJEGLYM.js} +6 -1
  36. package/dist/{chunk-YKU7KHJO.js → chunk-TBKVC2TA.js} +3 -5
  37. package/dist/{chunk-YYG3GUQW.js → chunk-UFWQTZDX.js} +29 -17
  38. package/dist/{chunk-PBDPWE5J.js → chunk-VBDDFO2V.js} +2 -2
  39. package/dist/{chunk-BRSESCGX.js → chunk-VUM6LO77.js} +4717 -4694
  40. package/dist/{chunk-FR6JHNLC.js → chunk-YLITJLTR.js} +3 -3
  41. package/dist/{chunk-CJ6OFTS3.js → chunk-YOWIYFIV.js} +6 -37
  42. package/dist/{chunk-VDBUZKXC.js → chunk-Z4Q6RYJH.js} +2 -2
  43. package/dist/{chunk-RRKGSYQ4.js → chunk-Z6WRFOFT.js} +13 -2
  44. package/dist/{chunk-YXAPCHXJ.js → chunk-ZIJ5IUXH.js} +31 -5
  45. package/dist/{claude-2C5L2HQL.js → claude-XVLF4N4S.js} +3 -3
  46. package/dist/{cli-BVRPAI23.js → cli-6FWRBCWM.js} +8 -8
  47. package/dist/{cli-YV6SFE4D.js → cli-RVPR3MH3.js} +7 -7
  48. package/dist/cli.js +11 -11
  49. package/dist/{completion-B3UT3GVI.js → completion-YTPHEVEW.js} +7 -7
  50. package/dist/{diagnostics-ONIAKCA3.js → diagnostics-IW54MLFK.js} +5 -6
  51. package/dist/{doctor-MJFU5L6R.js → doctor-EN4JPSKV.js} +35 -35
  52. package/dist/{entry-DZGKCL4G.js → entry-TQWSDTJ4.js} +14 -15
  53. package/dist/{exec-mcp-QK2VC6RX.js → exec-mcp-KKQ75N5O.js} +15 -13
  54. package/dist/{harness-GTED4GLK.js → harness-EB76F6BG.js} +6 -6
  55. package/dist/harness-launch-gate.js +3 -4
  56. package/dist/harness-worker.js +5 -6
  57. package/dist/hook-body.js +281 -98
  58. package/dist/{hook-spec-C7umArqw.d.ts → hook-spec-hZL4MSgi.d.ts} +8 -3
  59. package/dist/hooks-YWSHUNLM.js +24 -0
  60. package/dist/{host-AGNF2AQH.js → host-LSVITS6M.js} +6 -7
  61. package/dist/{host-3HTCZNVJ.js → host-OGGADMBT.js} +17 -15
  62. package/dist/{host-run-2OQZVQID.js → host-run-XO2TS4JC.js} +5 -7
  63. package/dist/http.d.ts +1 -1
  64. package/dist/http.js +1 -1
  65. package/dist/{import-mcp-7KEPR2B6.js → import-mcp-BJDJTPVS.js} +14 -11
  66. package/dist/index.d.ts +12 -3
  67. package/dist/index.js +25 -25
  68. package/dist/{init-BHGCF7JL.js → init-773PTQM5.js} +3 -3
  69. package/dist/{install-HF6CROQP.js → install-7V6NIA7W.js} +4 -4
  70. package/dist/{invoke-CVHF6PEK.js → invoke-Y7XH5S2L.js} +7 -8
  71. package/dist/{list-6XGQ3FR3.js → list-5W65XVES.js} +20 -17
  72. package/dist/{logout-6RJLG2KG.js → logout-XO6ALD45.js} +15 -12
  73. package/dist/{logs-VTW7S2LR.js → logs-74JGLQG6.js} +4 -4
  74. package/dist/mailbox/index.d.ts +3 -3
  75. package/dist/{mailbox-CNAONXN7.js → mailbox-VK5AVTHI.js} +9 -9
  76. package/dist/{mainline-JSG4MUKH.js → mainline-M2NSTAGC.js} +105 -36
  77. package/dist/{mcp-P55VLQLR.js → mcp-R62ZNVGJ.js} +2 -2
  78. package/dist/{pause-V5VCNOSH.js → pause-CZ2OZYLC.js} +4 -4
  79. package/dist/project/hook-adapter.d.ts +1 -1
  80. package/dist/{project-B57IQPDK.js → project-W5DQIZA6.js} +5 -5
  81. package/dist/{pty-FD4JGBZL.js → pty-CDLQ4NP2.js} +3 -3
  82. package/dist/report-Z3JV2PCT.js +105 -0
  83. package/dist/{resume-7S4K3R4X.js → resume-DFIHT2RO.js} +4 -4
  84. package/dist/{run-MC2BPLOE.js → run-OZLGSRHF.js} +14 -11
  85. package/dist/{run-LFJXONLW.js → run-WYJMTLX7.js} +4 -4
  86. package/dist/{serve-TFAEVXX3.js → serve-DCQGAGB7.js} +3 -3
  87. package/dist/{session-XM2CR425.js → session-YZVX4NGN.js} +4 -4
  88. package/dist/{setup-FHFQZJY6.js → setup-D3KEJBGO.js} +4 -4
  89. package/dist/smoke-FQQJOQBD.js +16 -0
  90. package/dist/{start-login-KXOHCR5A.js → start-login-EKXM75XQ.js} +15 -12
  91. package/dist/{status-YXOIEVOJ.js → status-23UDIYYP.js} +39 -22
  92. package/dist/{status-OYRB3KL5.js → status-3RTGDN2K.js} +10 -10
  93. package/dist/{status-AW7DOW7A.js → status-EDSEG32U.js} +15 -12
  94. package/dist/stdio.d.ts +2 -2
  95. package/dist/stdio.js +2 -2
  96. package/dist/{sweep-ZSYG6FNR.js → sweep-EPJMEZR6.js} +4 -4
  97. package/dist/{test-2HTOY4PJ.js → test-TM6PIZTV.js} +26 -18
  98. package/dist/{tui-DQFXYQ4H.js → tui-EQNJIDN5.js} +4 -4
  99. package/dist/{unbroadcast-FONZJWEW.js → unbroadcast-NTOC3PY3.js} +4 -4
  100. package/dist/{validate-WOFI7TMT.js → validate-KFBCUFI4.js} +2 -2
  101. package/dist/{worker-UXPGXAV2.js → worker-7X6WBPEI.js} +9 -10
  102. package/dist/{worktree-list-4PLE7K6L.js → worktree-list-EMKUMCTQ.js} +2 -2
  103. package/dist/{worktree-sync-GQVYAXGJ.js → worktree-sync-T6C5YEYS.js} +3 -3
  104. package/docs/commands.md +13 -6
  105. package/docs/git-workflow.md +46 -10
  106. package/docs/hooks.md +139 -12
  107. package/docs/project-configuration.md +34 -6
  108. package/docs/upgrading.md +94 -0
  109. package/gemini-extension.json +2 -2
  110. package/mcp.json +1 -1
  111. package/package.json +5 -5
  112. package/plugin.json +1 -1
  113. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  114. package/plugins/pmcp/.mcp.json +1 -1
  115. package/plugins/pmcp/gemini-extension.json +2 -2
  116. package/plugins/pmcp/mcp.json +1 -1
  117. package/plugins/pmcp/mod/reader/read.ts +14 -4
  118. package/plugins/pmcp/mod/sessions/format.ts +16 -1
  119. package/plugins/pmcp/mod/sessions/types.ts +1 -1
  120. package/plugins/pmcp/plugin.json +1 -1
  121. package/schema/catalog-v1.json +1 -7
  122. package/dist/chunk-EONAJAMJ.js +0 -130
  123. package/dist/chunk-IACJDHFQ.js +0 -1025
  124. package/dist/chunk-ISNRDHSD.js +0 -74
  125. package/dist/chunk-YGTJQVCK.js +0 -7
  126. package/dist/chunk-YLPXTJJM.js +0 -396
  127. package/dist/hooks-FRZ4SUNJ.js +0 -21
  128. package/dist/{core-C1LPjxK6.d.ts → core-Sug_rZrx.d.ts} +1 -1
package/dist/hook-body.js CHANGED
@@ -653,8 +653,6 @@ function runsScript(words, scripts) {
653
653
  }
654
654
  function touchesLock(words, scripts) {
655
655
  if (words[0] === "bun" && BUN_INSTALLS.has(words[1] ?? "")) return true;
656
- if (words[0] === "bun" && words[1] === "run" && /^git:(land|sync)$/u.test(words[2] ?? ""))
657
- return true;
658
656
  return runsScript(words, scripts);
659
657
  }
660
658
  var DEFAULT_MUTATING_COMMANDS = [
@@ -1524,8 +1522,8 @@ function matches(selector, recipient) {
1524
1522
  return !!recipient.session && recipient.session.startsWith(value);
1525
1523
  if (kind === "alias") return recipient.alias === value;
1526
1524
  if (kind === "role") return (recipient.roles ?? []).includes(value);
1527
- if (!isWorktree(kind) || !recipient.desk) return false;
1528
- return recipient.desk === value || basename2(recipient.desk) === value;
1525
+ if (!isWorktree(kind) || !recipient.worktree) return false;
1526
+ return recipient.worktree === value || basename2(recipient.worktree) === value;
1529
1527
  }
1530
1528
  function before(message, recipient) {
1531
1529
  if (!recipient.since) return false;
@@ -1551,12 +1549,22 @@ import { basename as basename3 } from "node:path";
1551
1549
 
1552
1550
  // src/sessions/format.ts
1553
1551
  var STATE_FILES = {
1554
- records: "fleet",
1552
+ records: "sessions",
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
+ legacyRecords: "fleet",
1555
1556
  pause: "pause.json",
1556
1557
  broadcast: "broadcast.json",
1557
1558
  history: "broadcast-history.jsonl"
1558
1559
  };
1559
1560
  var STALE_MS = 30 * 60 * 1e3;
1561
+ function latestRecord(copies) {
1562
+ const time = (record) => Date.parse(record.updatedAt ?? record.startedAt ?? "") || 0;
1563
+ let latest = null;
1564
+ for (const copy of copies)
1565
+ if (copy && (!latest || time(copy) > time(latest))) latest = copy;
1566
+ return latest;
1567
+ }
1560
1568
  var LEASE_NAME = /^[a-z0-9][a-z0-9_-]*$/u;
1561
1569
  function leaseFile(name) {
1562
1570
  if (!LEASE_NAME.test(name)) throw new Error(`invalid lease name ${name}`);
@@ -1705,7 +1713,7 @@ function recipientOf(input, ctx) {
1705
1713
  session,
1706
1714
  ...record?.alias ? { alias: record.alias } : {},
1707
1715
  roles: roles2,
1708
- desk: record?.worktree || input.cwd,
1716
+ worktree: record?.worktree || input.cwd,
1709
1717
  // The registry records a session at its start, so earlier broadcasts are not its news.
1710
1718
  ...record?.startedAt ? { since: record.startedAt } : {}
1711
1719
  };
@@ -2496,9 +2504,7 @@ function fileOperands(argv) {
2496
2504
  // src/hooks/policies/shell/secret-exfiltration.ts
2497
2505
  var SECRET_PATHS = [
2498
2506
  /(?:^|[^\w.-])\.env(?:\.(?!example\b|sample\b|template\b|dist\b)[\w.-]+)?(?![\w.-])/iu,
2499
- /(?:^|[^\w.-])\.env\.d(?:\/|\b)/iu,
2500
2507
  /\.dev\.vars(?:\.json)?\b/iu,
2501
- /\.bak\.\d{8,}/u,
2502
2508
  /\b(?:id_rsa|id_ed25519|id_ecdsa)\b(?!\.pub)/u,
2503
2509
  /\.(?:pem|p12|pfx)\b/iu,
2504
2510
  // Known credential files only: a name that merely contains "secret" (a test fixture, a
@@ -2526,7 +2532,7 @@ var ENV_DUMPS = [
2526
2532
  ["export", "-p"],
2527
2533
  ["declare", "-x"]
2528
2534
  ];
2529
- var FALLBACK_PATH = /(?:^|[^\w.-])\.env(?![.\w-])|(?:^|[^\w.-])\.env\.d(?:\/|\b)|\.dev\.vars(?:\.json)?\b|\.bak\.\d{8,}/u;
2535
+ var FALLBACK_PATH = /(?:^|[^\w.-])\.env(?![.\w-])|\.dev\.vars(?:\.json)?\b/u;
2530
2536
  var FALLBACK_USE = /(?:^|[;&|(]|&&)\s*(?:sudo\s+)?(?:cat|head|tail|less|grep|rg|jq|base64|cp|curl|wget|nc|scp|rsync)\b/u;
2531
2537
  var NO_VALUES = "Use metadata verbs instead (ls, stat, wc, find), or a command that names keys without resolving values.";
2532
2538
  function names(word, options2) {
@@ -3125,6 +3131,53 @@ function installIfStale(root, spec, report2) {
3125
3131
  return 0;
3126
3132
  }
3127
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
+
3128
3181
  // src/git/landed.ts
3129
3182
  function cherry(cwd, upstream, head = "HEAD") {
3130
3183
  const listed = git(cwd, ["cherry", "-v", upstream, head]).stdout;
@@ -3132,7 +3185,10 @@ function cherry(cwd, upstream, head = "HEAD") {
3132
3185
  const missing = [];
3133
3186
  for (const line of listed.split("\n")) {
3134
3187
  if (line.startsWith("- ")) carried.push(line.slice(2));
3135
- 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));
3136
3192
  }
3137
3193
  return { carried, missing };
3138
3194
  }
@@ -3149,7 +3205,7 @@ function distance(cwd, upstream) {
3149
3205
  }
3150
3206
 
3151
3207
  // src/git/submodules.ts
3152
- import { join as join8 } from "node:path";
3208
+ import { join as join9 } from "node:path";
3153
3209
  function clean(dir) {
3154
3210
  return git(dir, ["status", "--porcelain"]).stdout.trim() === "";
3155
3211
  }
@@ -3159,8 +3215,8 @@ function hasCommit(dir, sha) {
3159
3215
  function movableSubmodules(root) {
3160
3216
  const listed = git(root, ["submodule", "status"]).stdout;
3161
3217
  return listed.split("\n").filter((line) => /^[ +]/u.test(line)).map((line) => line.trim().split(/\s+/u)[1] ?? "").filter((path) => {
3162
- const dir = join8(root, path);
3163
- if (!path || !existsSync(join8(dir, ".git"))) return false;
3218
+ const dir = join9(root, path);
3219
+ if (!path || !existsSync(join9(dir, ".git"))) return false;
3164
3220
  const local = gitText(dir, [
3165
3221
  "rev-list",
3166
3222
  "--count",
@@ -3175,7 +3231,7 @@ function updateToPins(root, paths) {
3175
3231
  const lines = [];
3176
3232
  for (const path of paths) {
3177
3233
  const pin = gitText(root, ["rev-parse", `HEAD:${path}`]);
3178
- const dir = join8(root, path);
3234
+ const dir = join9(root, path);
3179
3235
  if (!pin || !hasCommit(dir, pin)) {
3180
3236
  lines.push(
3181
3237
  `${path}: left alone, ${pin.slice(0, 10) || "its pin"} is not in its checkout`
@@ -3369,6 +3425,20 @@ var worktreeSync = {
3369
3425
  // src/hooks/policies/custom.ts
3370
3426
  import { isAbsolute as isAbsolute6, relative as relative7, resolve as resolve12 } from "node:path";
3371
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
+ }
3372
3442
  function inside(base, path) {
3373
3443
  const rest = relative7(base, path);
3374
3444
  return rest !== "" && !rest.startsWith("..") && !isAbsolute6(rest);
@@ -3376,7 +3446,9 @@ function inside(base, path) {
3376
3446
  function guardScript(root, command6) {
3377
3447
  const script = command6[0]?.startsWith(".agents/guards/") ? command6[0] : command6[1];
3378
3448
  if (!script?.startsWith(".agents/guards/")) {
3379
- 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
+ );
3380
3452
  }
3381
3453
  const base = resolve12(root, ".agents/guards");
3382
3454
  if (!inside(base, resolve12(root, script)))
@@ -3393,13 +3465,48 @@ function guardHash(root, command6) {
3393
3465
  }
3394
3466
  function applies(entry, input) {
3395
3467
  if (!entry.targets.includes(input.runtime)) return false;
3396
- if (entry.event === "before_shell")
3397
- return input.event === "before_tool" && input.tool?.kind === "shell";
3398
- 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);
3399
3470
  }
3400
- 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) {
3401
3508
  const root = input.projectRoot;
3402
- if (guardHash(root, entry.command) !== entry.guardSha256) {
3509
+ if (entry.guardSha256 !== void 0 && guardHash(root, entry.command) !== entry.guardSha256) {
3403
3510
  return {
3404
3511
  verdict: "deny",
3405
3512
  reason: "Guard source changed; review it and run pmcp project"
@@ -3411,13 +3518,7 @@ function run2(entry, input) {
3411
3518
  const result = spawnSync(args[0], args.slice(1), {
3412
3519
  cwd: root,
3413
3520
  env: { PATH: process.env["PATH"], LANG: "C.UTF-8" },
3414
- input: JSON.stringify({
3415
- runtime: input.runtime,
3416
- event: entry.event,
3417
- command: input.tool?.command ?? "",
3418
- cwd: input.cwd,
3419
- paths: input.tool?.paths ?? []
3420
- }),
3521
+ input: request(entry, input),
3421
3522
  encoding: "utf8",
3422
3523
  timeout: entry.timeoutMs,
3423
3524
  killSignal: "SIGKILL",
@@ -3427,28 +3528,40 @@ function run2(entry, input) {
3427
3528
  return { verdict: "deny", reason: FAILED };
3428
3529
  const response = JSON.parse(result.stdout);
3429
3530
  const extra = Object.keys(response).some(
3430
- (key) => key !== "decision" && key !== "reason"
3531
+ (key) => !["decision", "reason", "findings", "protocol"].includes(key)
3431
3532
  );
3432
3533
  const reason2 = response["reason"];
3433
- 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)
3434
3536
  return { verdict: "deny", reason: FAILED };
3435
- 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;
3436
3548
  if (response["decision"] !== "deny")
3437
3549
  return { verdict: "deny", reason: FAILED };
3438
- return {
3439
- verdict: "deny",
3440
- reason: typeof reason2 === "string" ? reason2.slice(0, 2e3) : FAILED
3441
- };
3550
+ const text9 = [typeof reason2 === "string" ? reason2 : FAILED, ...lines].join(
3551
+ "\n"
3552
+ );
3553
+ return { verdict: "deny", reason: text9.slice(0, MAX_REASON) };
3442
3554
  }
3443
3555
  function customPolicy(entry) {
3556
+ const { event, tool } = EVENTS[entry.event];
3444
3557
  return {
3445
3558
  id: `custom.${entry.name}`,
3446
- events: [entry.event === "before_shell" ? "before_tool" : "after_tool"],
3447
- tools: [entry.event === "before_shell" ? "shell" : "edit"],
3559
+ events: [event],
3560
+ ...tool ? { tools: [tool] } : {},
3448
3561
  fail: "closed",
3449
3562
  defaultMode: "deny",
3450
3563
  options: () => ({}),
3451
- evaluate: (input) => applies(entry, input) ? run2(entry, input) : pass
3564
+ evaluate: (input, ctx) => applies(entry, input) ? run2(entry, input, ctx.log) : pass
3452
3565
  };
3453
3566
  }
3454
3567
 
@@ -3520,7 +3633,7 @@ function selectPolicies(compiled, input) {
3520
3633
  }));
3521
3634
  const custom = compiled.custom.map((entry) => ({
3522
3635
  policy: customPolicy(entry),
3523
- mode: "deny",
3636
+ mode: customMode(entry),
3524
3637
  options: {}
3525
3638
  }));
3526
3639
  return [...guards, ...custom].filter((selected) => listens(selected, input));
@@ -3573,14 +3686,30 @@ function toolKind(name) {
3573
3686
  return TOOL_KINDS[name] ?? "other";
3574
3687
  }
3575
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
+
3576
3705
  // src/hooks/runtimes/antigravity/output.ts
3577
- var MAX_REASON = 2e3;
3706
+ var MAX_REASON2 = 2e3;
3578
3707
  function silent(event) {
3579
3708
  return event === "before_tool" ? '{"decision":"allow"}\n' : "{}\n";
3580
3709
  }
3581
3710
  function render(input, decision) {
3582
3711
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
3583
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON);
3712
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON2);
3584
3713
  if (input.event === "before_tool") {
3585
3714
  const out2 = blocking ? { decision: "deny", reason: reason2 } : { decision: "allow" };
3586
3715
  return { stdout: `${JSON.stringify(out2)}
@@ -3599,6 +3728,12 @@ function render(input, decision) {
3599
3728
  return { stdout: `${JSON.stringify(out)}
3600
3729
  `, exitCode: 0 };
3601
3730
  }
3731
+ function verdict(stdout) {
3732
+ return readAnswer(
3733
+ stdout,
3734
+ (out) => out["decision"] === "deny" ? "deny" : "allow"
3735
+ );
3736
+ }
3602
3737
 
3603
3738
  // src/hooks/runtimes/antigravity/payload.ts
3604
3739
  import { isAbsolute as isAbsolute7, resolve as resolve13 } from "node:path";
@@ -3717,6 +3852,7 @@ var antigravity = {
3717
3852
  },
3718
3853
  normalize,
3719
3854
  render,
3855
+ readVerdict: verdict,
3720
3856
  silent,
3721
3857
  project,
3722
3858
  nativeFiles: [{ file: HOOKS_FILE, root: HOOK_SET }],
@@ -3777,11 +3913,11 @@ function matcherFor(tools) {
3777
3913
  }
3778
3914
 
3779
3915
  // src/hooks/runtimes/claude/output.ts
3780
- var MAX_REASON2 = 2e3;
3916
+ var MAX_REASON3 = 2e3;
3781
3917
  function render2(input, decision) {
3782
3918
  const hookEventName = NATIVE_EVENTS2[input.event];
3783
3919
  const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
3784
- const reason2 = decision.reason?.slice(0, MAX_REASON2);
3920
+ const reason2 = decision.reason?.slice(0, MAX_REASON3);
3785
3921
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
3786
3922
  const out = shape(input, decision, {
3787
3923
  hookEventName,
@@ -3823,6 +3959,12 @@ function shape(input, decision, parts) {
3823
3959
  if (input.event === "session_start" && context) return contextOnly;
3824
3960
  return null;
3825
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
+ }
3826
3968
 
3827
3969
  // src/hooks/runtimes/claude/payload.ts
3828
3970
  import { isAbsolute as isAbsolute8, resolve as resolve14 } from "node:path";
@@ -3972,6 +4114,7 @@ var claude = {
3972
4114
  },
3973
4115
  normalize: normalize2,
3974
4116
  render: render2,
4117
+ readVerdict: verdict2,
3975
4118
  project: project2,
3976
4119
  nativeFiles: [{ file: SETTINGS_FILE, root: "hooks" }],
3977
4120
  nativeEvent: (event) => NATIVE_EVENTS2[event],
@@ -4027,11 +4170,11 @@ function matcherFor2(tools) {
4027
4170
  }
4028
4171
 
4029
4172
  // src/hooks/runtimes/codex/output.ts
4030
- var MAX_REASON3 = 2e3;
4173
+ var MAX_REASON4 = 2e3;
4031
4174
  function render3(input, decision) {
4032
4175
  const hookEventName = NATIVE_EVENTS3[input.event];
4033
4176
  const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
4034
- const reason2 = decision.reason?.slice(0, MAX_REASON3);
4177
+ const reason2 = decision.reason?.slice(0, MAX_REASON4);
4035
4178
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4036
4179
  const out = shape2(input, decision, {
4037
4180
  hookEventName,
@@ -4074,6 +4217,12 @@ function shape2(input, decision, parts) {
4074
4217
  if (input.event === "session_start" && context) return contextOnly;
4075
4218
  return null;
4076
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
+ }
4077
4226
 
4078
4227
  // src/hooks/runtimes/codex/payload.ts
4079
4228
  import { isAbsolute as isAbsolute9, resolve as resolve15 } from "node:path";
@@ -4203,6 +4352,7 @@ var codex = {
4203
4352
  },
4204
4353
  normalize: normalize3,
4205
4354
  render: render3,
4355
+ readVerdict: verdict3,
4206
4356
  project: project3,
4207
4357
  nativeFiles: [{ file: HOOKS_FILE2, root: "hooks" }],
4208
4358
  nativeEvent: (event) => NATIVE_EVENTS3[event],
@@ -4261,7 +4411,7 @@ function matcherFor3(tools) {
4261
4411
  }
4262
4412
 
4263
4413
  // src/hooks/runtimes/gemini/output.ts
4264
- var MAX_REASON4 = 2e3;
4414
+ var MAX_REASON5 = 2e3;
4265
4415
  var DELIVERS = [
4266
4416
  "session_start",
4267
4417
  "prompt",
@@ -4269,7 +4419,7 @@ var DELIVERS = [
4269
4419
  ];
4270
4420
  function render4(input, decision) {
4271
4421
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4272
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON4);
4422
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON5);
4273
4423
  const out = {};
4274
4424
  const notes = [...decision.context ?? []];
4275
4425
  if (blocking && input.event === "before_tool")
@@ -4284,6 +4434,12 @@ function render4(input, decision) {
4284
4434
  return { stdout: `${JSON.stringify(out)}
4285
4435
  `, exitCode: 0 };
4286
4436
  }
4437
+ function verdict4(stdout) {
4438
+ return readAnswer(
4439
+ stdout,
4440
+ (out) => out["decision"] === "deny" ? "deny" : "allow"
4441
+ );
4442
+ }
4287
4443
 
4288
4444
  // src/hooks/runtimes/gemini/payload.ts
4289
4445
  import { isAbsolute as isAbsolute10, resolve as resolve16 } from "node:path";
@@ -4399,6 +4555,7 @@ var gemini = {
4399
4555
  },
4400
4556
  normalize: normalize4,
4401
4557
  render: render4,
4558
+ readVerdict: verdict4,
4402
4559
  project: project4,
4403
4560
  nativeFiles: [{ file: SETTINGS_FILE2, root: "hooks" }],
4404
4561
  nativeEvent: (event) => NATIVE_EVENTS4[event],
@@ -4450,7 +4607,7 @@ function toolKind5(name) {
4450
4607
  }
4451
4608
 
4452
4609
  // src/hooks/runtimes/grok/output.ts
4453
- var MAX_REASON5 = 2e3;
4610
+ var MAX_REASON6 = 2e3;
4454
4611
  var DELIVERS2 = [
4455
4612
  "before_tool",
4456
4613
  "after_tool",
@@ -4458,7 +4615,7 @@ var DELIVERS2 = [
4458
4615
  ];
4459
4616
  function render5(input, decision) {
4460
4617
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4461
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON5);
4618
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
4462
4619
  const notes = [...decision.context ?? []];
4463
4620
  const refuse = blocking && input.event === "before_tool";
4464
4621
  if (blocking && !refuse) notes.unshift(reason2);
@@ -4476,6 +4633,12 @@ function render5(input, decision) {
4476
4633
  return { stdout: `${JSON.stringify(out)}
4477
4634
  `, exitCode: 0 };
4478
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
+ }
4479
4642
 
4480
4643
  // src/hooks/runtimes/grok/payload.ts
4481
4644
  import { isAbsolute as isAbsolute11, resolve as resolve17 } from "node:path";
@@ -4598,6 +4761,7 @@ var grok = {
4598
4761
  },
4599
4762
  normalize: normalize5,
4600
4763
  render: render5,
4764
+ readVerdict: verdict5,
4601
4765
  project: project5,
4602
4766
  nativeFiles: [{ file: HOOKS_FILE3, root: "hooks" }],
4603
4767
  nativeEvent: (event) => NATIVE_EVENTS5[event],
@@ -4651,7 +4815,7 @@ function toolKind6(name) {
4651
4815
  }
4652
4816
 
4653
4817
  // src/hooks/runtimes/opencode/output.ts
4654
- var MAX_REASON6 = 2e3;
4818
+ var MAX_REASON7 = 2e3;
4655
4819
  var DELIVERS3 = [
4656
4820
  "session_start",
4657
4821
  "prompt",
@@ -4659,7 +4823,7 @@ var DELIVERS3 = [
4659
4823
  ];
4660
4824
  function render6(input, decision) {
4661
4825
  const blocking = decision.verdict === "deny" || decision.verdict === "ask";
4662
- const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
4826
+ const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON7);
4663
4827
  if (input.event === "before_tool") {
4664
4828
  const out2 = blocking ? { deny: reason2 } : {};
4665
4829
  return { stdout: `${JSON.stringify(out2)}
@@ -4672,6 +4836,9 @@ function render6(input, decision) {
4672
4836
  return { stdout: `${JSON.stringify(out)}
4673
4837
  `, exitCode: 0 };
4674
4838
  }
4839
+ function verdict6(stdout) {
4840
+ return readAnswer(stdout, (out) => "deny" in out ? "deny" : "allow");
4841
+ }
4675
4842
 
4676
4843
  // src/hooks/runtimes/opencode/payload.ts
4677
4844
  import { isAbsolute as isAbsolute12, resolve as resolve18 } from "node:path";
@@ -4854,6 +5021,7 @@ var opencode = {
4854
5021
  },
4855
5022
  normalize: normalize6,
4856
5023
  render: render6,
5024
+ readVerdict: verdict6,
4857
5025
  // opencode has no hook configuration to edit; the projection is the generated plugin file.
4858
5026
  project: () => [],
4859
5027
  files,
@@ -4914,18 +5082,18 @@ async function dispatch(raw, compiled, deps) {
4914
5082
  }
4915
5083
 
4916
5084
  // src/hooks/entry/fail-closed.ts
4917
- import { join as join11 } from "node:path";
5085
+ import { join as join12 } from "node:path";
4918
5086
 
4919
5087
  // src/hooks/compiled.ts
4920
- import { join as join10 } from "node:path";
5088
+ import { join as join11 } from "node:path";
4921
5089
 
4922
5090
  // src/hooks/integrity-cache.ts
4923
5091
  import { homedir as homedir2 } from "node:os";
4924
- import { dirname as dirname7, join as join9 } from "node:path";
5092
+ import { dirname as dirname7, join as join10 } from "node:path";
4925
5093
  var LIMIT = 64;
4926
5094
  function cacheFile() {
4927
- const base = process.env["XDG_CACHE_HOME"] || join9(homedir2(), ".cache");
4928
- 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");
4929
5097
  }
4930
5098
  function readCache() {
4931
5099
  try {
@@ -4977,8 +5145,8 @@ var PolicyIntegrityError = class extends Error {
4977
5145
  };
4978
5146
  var MISMATCH = "policy.json does not match pmcp.lock; review the change and run pmcp project";
4979
5147
  function readCompiled(root) {
4980
- const policyPath = join10(root, POLICY_FILE);
4981
- const files2 = [policyPath, join10(root, LOCK_FILE)];
5148
+ const policyPath = join11(root, POLICY_FILE);
5149
+ const files2 = [policyPath, join11(root, LOCK_FILE)];
4982
5150
  const before2 = stampOf(files2);
4983
5151
  const text9 = readFileSync(policyPath, "utf8");
4984
5152
  const lock = JSON.parse(readFileSync(files2[1], "utf8"));
@@ -5001,7 +5169,7 @@ function readCompiled(root) {
5001
5169
  var FAILED_CLOSED = "pmcp hook could not evaluate this call and refused it";
5002
5170
  function rawFailure(root) {
5003
5171
  try {
5004
- const raw = JSON.parse(readFileSync(join11(root, POLICY_FILE), "utf8"))["failure"];
5172
+ const raw = JSON.parse(readFileSync(join12(root, POLICY_FILE), "utf8"))["failure"];
5005
5173
  if (!raw || typeof raw.timeoutMs !== "number" || typeof raw.retry !== "number" || !Array.isArray(raw.pass) || !raw.pass.every(
5006
5174
  (kind) => PASS_KINDS.includes(kind)
5007
5175
  ))
@@ -5036,7 +5204,7 @@ function failClosed(adapter, event, root, error, stated = false) {
5036
5204
  }
5037
5205
 
5038
5206
  // src/hooks/entry/logger.ts
5039
- import { dirname as dirname8, join as join14 } from "node:path";
5207
+ import { dirname as dirname8, join as join15 } from "node:path";
5040
5208
 
5041
5209
  // src/logging/levels.ts
5042
5210
  var LEVEL_RANK = {
@@ -5123,7 +5291,7 @@ function createLogger(sink, settings = DEFAULT_LOG_SETTINGS, fields2 = {}) {
5123
5291
  const enabled = (at) => resolved.enabled && LEVEL_RANK[at] <= limit;
5124
5292
  const write3 = (at, msg, data) => {
5125
5293
  if (!enabled(at)) return;
5126
- const { verdict, duration_ms, ...rest } = data ?? {};
5294
+ const { verdict: verdict7, duration_ms, ...rest } = data ?? {};
5127
5295
  const record = {
5128
5296
  ts: (/* @__PURE__ */ new Date()).toISOString(),
5129
5297
  level: at,
@@ -5133,7 +5301,7 @@ function createLogger(sink, settings = DEFAULT_LOG_SETTINGS, fields2 = {}) {
5133
5301
  event: fields2.event,
5134
5302
  session: fields2.session,
5135
5303
  policy: fields2.policy,
5136
- verdict,
5304
+ verdict: verdict7,
5137
5305
  duration_ms,
5138
5306
  msg,
5139
5307
  data: Object.keys(rest).length > 0 ? redact(rest, resolved.redact) : void 0
@@ -5160,11 +5328,11 @@ var silentLogger = createLogger(() => {
5160
5328
  });
5161
5329
 
5162
5330
  // src/logging/sinks/file.ts
5163
- import { join as join12 } from "node:path";
5331
+ import { join as join13 } from "node:path";
5164
5332
  var FILE = /^pmcp-(\d{8})(?:\.\d+)?\.jsonl$/u;
5165
5333
  function dailyLogFile(dir, now = /* @__PURE__ */ new Date()) {
5166
5334
  const day = now.toISOString().slice(0, 10).replaceAll("-", "");
5167
- return join12(dir, `pmcp-${day}.jsonl`);
5335
+ return join13(dir, `pmcp-${day}.jsonl`);
5168
5336
  }
5169
5337
  function roll(file2) {
5170
5338
  let index = 1;
@@ -5195,7 +5363,7 @@ function logFiles(dir) {
5195
5363
  const part = (name) => Number(/\.(\d+)\.jsonl$/u.exec(name)?.[1] ?? Number.MAX_SAFE_INTEGER);
5196
5364
  return names2.sort(
5197
5365
  (a, b) => a.slice(5, 13).localeCompare(b.slice(5, 13)) || part(a) - part(b)
5198
- ).map((name) => join12(dir, name));
5366
+ ).map((name) => join13(dir, name));
5199
5367
  }
5200
5368
  function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
5201
5369
  const cutoff = new Date(now.getTime() - keepDays * 864e5).toISOString().slice(0, 10).replaceAll("-", "");
@@ -5211,13 +5379,13 @@ function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
5211
5379
 
5212
5380
  // src/sessions/state-dir.ts
5213
5381
  import { homedir as homedir3 } from "node:os";
5214
- import { join as join13 } from "node:path";
5382
+ import { join as join14 } from "node:path";
5215
5383
  function projectStateDir(root, override, env = process.env) {
5216
5384
  if (override) return expandPath(root, override);
5217
5385
  const anchor = gitCommonDir(root) ?? realpathSync(root);
5218
5386
  const id = createHash("sha256").update(anchor).digest("hex").slice(0, 16);
5219
- const base = env["XDG_STATE_HOME"] || join13(homedir3(), ".local", "state");
5220
- return join13(base, "pmcp", "projects", id);
5387
+ const base = env["XDG_STATE_HOME"] || join14(homedir3(), ".local", "state");
5388
+ return join14(base, "pmcp", "projects", id);
5221
5389
  }
5222
5390
 
5223
5391
  // src/hooks/entry/logger.ts
@@ -5232,7 +5400,7 @@ function hookLogger(root, compiled, runtime2, event) {
5232
5400
  process.env["PMCP_LOG"]
5233
5401
  );
5234
5402
  const file2 = compiled?.logFile ? expandPath(root, compiled.logFile) : void 0;
5235
- const dir = file2 ? dirname8(file2) : join14(projectStateDir(root, compiled?.stateDir), "logs");
5403
+ const dir = file2 ? dirname8(file2) : join15(projectStateDir(root, compiled?.stateDir), "logs");
5236
5404
  const sink = fileSink({
5237
5405
  dir,
5238
5406
  ...file2 ? { file: file2 } : {},
@@ -5292,7 +5460,7 @@ var gitProbe = {
5292
5460
  };
5293
5461
 
5294
5462
  // src/sessions/files/broadcast.ts
5295
- import { join as join15 } from "node:path";
5463
+ import { join as join16 } from "node:path";
5296
5464
 
5297
5465
  // src/sessions/files/json.ts
5298
5466
  import { dirname as dirname9 } from "node:path";
@@ -5339,8 +5507,8 @@ function writeLines(path, values) {
5339
5507
 
5340
5508
  // src/sessions/files/broadcast.ts
5341
5509
  function filesBroadcast(dir, keep, registry2) {
5342
- const latestPath = join15(dir, STATE_FILES.broadcast);
5343
- const historyPath = join15(dir, STATE_FILES.history);
5510
+ const latestPath = join16(dir, STATE_FILES.broadcast);
5511
+ const historyPath = join16(dir, STATE_FILES.history);
5344
5512
  const list = () => {
5345
5513
  const latest = asBroadcast(readJson3(latestPath));
5346
5514
  if (!latest) return [];
@@ -5384,9 +5552,9 @@ function filesBroadcast(dir, keep, registry2) {
5384
5552
  }
5385
5553
 
5386
5554
  // src/sessions/files/leases.ts
5387
- import { dirname as dirname10, join as join16 } from "node:path";
5555
+ import { dirname as dirname10, join as join17 } from "node:path";
5388
5556
  function filesLeases(dir, files2 = {}) {
5389
- const leasePath = (name) => files2[name]?.file ?? join16(dir, leaseFile(name));
5557
+ const leasePath = (name) => files2[name]?.file ?? join17(dir, leaseFile(name));
5390
5558
  const read3 = (name) => {
5391
5559
  const lease = asLease(readJson3(leasePath(name)));
5392
5560
  if (!lease || !alive(lease.pid)) return null;
@@ -5436,28 +5604,28 @@ function filesLeases(dir, files2 = {}) {
5436
5604
  }
5437
5605
 
5438
5606
  // src/sessions/files/mailbox.ts
5439
- import { join as join17 } from "node:path";
5607
+ import { join as join18 } from "node:path";
5440
5608
  var ID = /^\d{13}-[0-9a-f]{8}$/u;
5441
5609
  var SAFE_KEY = /^@?[\w.-]+$/u;
5442
5610
  function filesMailbox(dir, settings) {
5443
- const messages = join17(dir, "messages");
5444
- const inbox = join17(dir, "inbox");
5445
- 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`);
5446
5614
  const marker = (key, id, kind) => {
5447
5615
  if (!SAFE_KEY.test(key) || !ID.test(id))
5448
5616
  throw new Error(`invalid mailbox key ${key} or id ${id}`);
5449
- return join17(inbox, key, `${id}.${kind}`);
5617
+ return join18(inbox, key, `${id}.${kind}`);
5450
5618
  };
5451
5619
  const audit = (event, fields2) => {
5452
5620
  if (!settings.audit) return;
5453
5621
  const line = { at: (/* @__PURE__ */ new Date()).toISOString(), event, ...fields2 };
5454
- appendFileSync(join17(dir, "messages.jsonl"), `${JSON.stringify(line)}
5622
+ appendFileSync(join18(dir, "messages.jsonl"), `${JSON.stringify(line)}
5455
5623
  `, {
5456
5624
  mode: 384
5457
5625
  });
5458
5626
  };
5459
5627
  const touch = (path) => {
5460
- mkdirSync(join17(path, ".."), { recursive: true, mode: 448 });
5628
+ mkdirSync(join18(path, ".."), { recursive: true, mode: 448 });
5461
5629
  try {
5462
5630
  writeFileSync(path, "", { flag: "wx", mode: 384 });
5463
5631
  return true;
@@ -5474,7 +5642,7 @@ function filesMailbox(dir, settings) {
5474
5642
  if (existsSync(inbox))
5475
5643
  for (const key of readdirSync(inbox))
5476
5644
  for (const kind of ["ack", "delivered"])
5477
- rmSync(join17(inbox, key, `${message.id}.${kind}`), { force: true });
5645
+ rmSync(join18(inbox, key, `${message.id}.${kind}`), { force: true });
5478
5646
  audit(event, { id: message.id });
5479
5647
  };
5480
5648
  return {
@@ -5550,9 +5718,9 @@ function filesMailbox(dir, settings) {
5550
5718
  }
5551
5719
 
5552
5720
  // src/sessions/files/pause.ts
5553
- import { join as join18 } from "node:path";
5721
+ import { join as join19 } from "node:path";
5554
5722
  function filesPause(dir) {
5555
- const path = join18(dir, STATE_FILES.pause);
5723
+ const path = join19(dir, STATE_FILES.pause);
5556
5724
  return {
5557
5725
  read: () => asPause(readJson3(path)),
5558
5726
  write(pause2) {
@@ -5570,23 +5738,38 @@ function filesPause(dir) {
5570
5738
  }
5571
5739
 
5572
5740
  // src/sessions/files/registry.ts
5573
- import { join as join19 } from "node:path";
5741
+ import { join as join20 } from "node:path";
5574
5742
  var SESSION_ID = /^[A-Za-z0-9_-]{8,64}$/u;
5575
5743
  function filesRegistry(dir, staleMs) {
5576
- const fleetDir = join19(dir, STATE_FILES.records);
5577
- const pathOf = (session) => join19(fleetDir, `${session}.json`);
5578
- const get = (session) => SESSION_ID.test(session) ? asRecord(readJson3(pathOf(session))) : null;
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`));
5747
+ const get = (session) => {
5748
+ if (!SESSION_ID.test(session)) return null;
5749
+ return latestRecord(
5750
+ pathsOf(session).map((path) => asRecord(readJson3(path)))
5751
+ );
5752
+ };
5579
5753
  const list = (now = Date.now()) => {
5580
- let names2 = [];
5581
- try {
5582
- names2 = readdirSync(fleetDir).filter((name) => name.endsWith(".json"));
5583
- } catch {
5584
- return [];
5754
+ const found = /* @__PURE__ */ new Map();
5755
+ for (const folder of dirs) {
5756
+ let names2 = [];
5757
+ try {
5758
+ names2 = readdirSync(folder).filter((name) => name.endsWith(".json"));
5759
+ } catch {
5760
+ continue;
5761
+ }
5762
+ for (const name of names2)
5763
+ found.set(name, [
5764
+ ...found.get(name) ?? [],
5765
+ asRecord(readJson3(join20(folder, name)))
5766
+ ]);
5585
5767
  }
5586
- return names2.map((name) => asRecord(readJson3(join19(fleetDir, name)))).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
5768
+ return [...found.values()].map(latestRecord).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
5587
5769
  };
5588
5770
  const remove = (session) => {
5589
- if (SESSION_ID.test(session)) rmSync(pathOf(session), { force: true });
5771
+ if (!SESSION_ID.test(session)) return;
5772
+ for (const path of pathsOf(session)) rmSync(path, { force: true });
5590
5773
  };
5591
5774
  return {
5592
5775
  get,
@@ -5606,7 +5789,7 @@ function filesRegistry(dir, staleMs) {
5606
5789
  next["worktree"] = checkout?.root ?? "";
5607
5790
  next["branch"] = checkout?.branch ?? "";
5608
5791
  }
5609
- writeJson(pathOf(session), next);
5792
+ writeJson(join20(records, `${session}.json`), next);
5610
5793
  return next;
5611
5794
  },
5612
5795
  sweep(now = Date.now()) {
@@ -5657,15 +5840,15 @@ function createFilesStore(dir, options2 = {}) {
5657
5840
  }
5658
5841
 
5659
5842
  // src/sessions/lease-files.ts
5660
- 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";
5661
5844
  var GATE_DIR = "${gate_dir}/";
5662
5845
  function gateTree(root, stateDir, gate, env) {
5663
5846
  const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
5664
5847
  if (override) return override;
5665
- return gate.tree ? expandPath(root, gate.tree) : join20(stateDir, "gate", "tree");
5848
+ return gate.tree ? expandPath(root, gate.tree) : join21(stateDir, "gate", "tree");
5666
5849
  }
5667
5850
  function resolveLeaseFiles(files2, gateDir) {
5668
- 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;
5669
5852
  return Object.fromEntries(
5670
5853
  Object.entries(files2 ?? {}).map(([name, f]) => {
5671
5854
  const file2 = resolve20(f.file);