@modootoday/pmcp 0.22.1 → 0.22.3

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 (103) 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-VMOFDOCN.js → apply-CYVC5LDG.js} +15 -14
  6. package/dist/{broadcast-ZALGUJVR.js → broadcast-DZGMSZRG.js} +3 -3
  7. package/dist/{chunk-57Q75MS4.js → chunk-5QKXEWDB.js} +2 -2
  8. package/dist/{chunk-5YCKFU5Q.js → chunk-7DYWCQVB.js} +1 -1
  9. package/dist/{chunk-MR5IBS6L.js → chunk-7I7O7ZNT.js} +41 -10
  10. package/dist/{chunk-ALX7BECI.js → chunk-7LUYI7QM.js} +2 -2
  11. package/dist/{chunk-M5LC5TKQ.js → chunk-7Q3AIS4Q.js} +2 -2
  12. package/dist/{chunk-7FV2LORT.js → chunk-B2WRYGHJ.js} +4 -3
  13. package/dist/{chunk-P2LJADGI.js → chunk-CALWIRAI.js} +14 -14
  14. package/dist/{chunk-2GI5RM3M.js → chunk-CILQCERV.js} +2 -2
  15. package/dist/{chunk-XYEI7KRO.js → chunk-ESCOMAPX.js} +3 -3
  16. package/dist/{chunk-GBKRDRMZ.js → chunk-FE7WOHZM.js} +17 -5
  17. package/dist/{chunk-D5BLJIAA.js → chunk-HV52EUSL.js} +9 -9
  18. package/dist/{chunk-GRRURNVA.js → chunk-ICZH4NFR.js} +5 -5
  19. package/dist/chunk-JTRFZQTB.js +7 -0
  20. package/dist/{chunk-3W2GELNR.js → chunk-JUG4W7RF.js} +2 -2
  21. package/dist/{chunk-6HCEEC6V.js → chunk-MLGXDSHZ.js} +17 -15
  22. package/dist/{chunk-TMXWSGXH.js → chunk-MQMWVJZB.js} +3 -3
  23. package/dist/{chunk-3TS3CX3R.js → chunk-MZF7VOQA.js} +2 -2
  24. package/dist/{chunk-SB6X342E.js → chunk-NQFULJZC.js} +3 -3
  25. package/dist/{chunk-V6LLHO4S.js → chunk-ONYZIC2F.js} +7 -7
  26. package/dist/{chunk-DPVLHB3K.js → chunk-PR2RBEXI.js} +2 -2
  27. package/dist/{chunk-XWAE3VEQ.js → chunk-RZZZHQCE.js} +2 -2
  28. package/dist/{chunk-UVGW56SY.js → chunk-ULFV3EIZ.js} +27 -7
  29. package/dist/{chunk-FHK5BE2D.js → chunk-UQNRGU3V.js} +2 -2
  30. package/dist/{chunk-NYA4GX44.js → chunk-V7LZTVWS.js} +2 -2
  31. package/dist/{chunk-OKMWYNZF.js → chunk-WPX4ONFT.js} +24 -7
  32. package/dist/chunk-XWLMZKH2.js +12 -0
  33. package/dist/{cli-6FWRBCWM.js → cli-34EDFXJA.js} +8 -8
  34. package/dist/{cli-BEEDAD4E.js → cli-A6HKRICM.js} +4 -4
  35. package/dist/cli.js +3 -3
  36. package/dist/{completion-XA7SR2OU.js → completion-FDLVWLAC.js} +2 -2
  37. package/dist/{diagnostics-AYSD3454.js → diagnostics-DYLW7WYV.js} +7 -5
  38. package/dist/{doctor-PDLZL4BR.js → doctor-FRQ5H5FU.js} +21 -14
  39. package/dist/{entry-5CKOI3QK.js → entry-XPZZNQ4L.js} +11 -9
  40. package/dist/{exec-mcp-EJZVPVU5.js → exec-mcp-HOM2ZANM.js} +12 -11
  41. package/dist/{harness-VMQJY3KY.js → harness-WIGJRE5P.js} +3 -3
  42. package/dist/harness-launch-gate.js +5 -3
  43. package/dist/harness-worker.js +7 -5
  44. package/dist/hook-body.js +189 -76
  45. package/dist/{hook-spec-hZL4MSgi.d.ts → hook-spec-Bd24eo2L.d.ts} +1 -0
  46. package/dist/{hooks-SKD67KMA.js → hooks-MIF3FONJ.js} +4 -4
  47. package/dist/{host-GY2LFEZX.js → host-CE5TW5SC.js} +12 -11
  48. package/dist/{host-4BA3LM7Z.js → host-JKZLOCZS.js} +8 -6
  49. package/dist/{host-run-X3VDTIQ2.js → host-run-MJGJ7NVE.js} +6 -4
  50. package/dist/http.js +1 -1
  51. package/dist/{import-mcp-G2VTD5KR.js → import-mcp-T3GZYEE5.js} +11 -10
  52. package/dist/index.d.ts +2 -2
  53. package/dist/index.js +16 -15
  54. package/dist/{init-JEK3QUAK.js → init-D5VPDF2B.js} +2 -2
  55. package/dist/{invoke-7BUFBFJU.js → invoke-HEAOQLFQ.js} +9 -7
  56. package/dist/{list-D3Y3TIC6.js → list-PCLCFG2J.js} +11 -10
  57. package/dist/{logout-T4JLFE2D.js → logout-3ZXFXKHB.js} +10 -9
  58. package/dist/{logs-74JGLQG6.js → logs-UHJM7ZCL.js} +3 -3
  59. package/dist/{mailbox-VK5AVTHI.js → mailbox-NIMBOQPA.js} +3 -3
  60. package/dist/{mainline-Q42M2GJ2.js → mainline-6CTSVOWP.js} +63 -29
  61. package/dist/{mcp-GPIHVL65.js → mcp-T6PYHRUL.js} +2 -2
  62. package/dist/{pause-CZ2OZYLC.js → pause-CBZ3BTJL.js} +3 -3
  63. package/dist/project/hook-adapter.d.ts +1 -1
  64. package/dist/{project-6QRKXOMM.js → project-H4R3Q3QO.js} +7 -7
  65. package/dist/{report-Z3JV2PCT.js → report-ZHOHQ4PZ.js} +3 -3
  66. package/dist/{resume-DFIHT2RO.js → resume-UJEWQ66P.js} +3 -3
  67. package/dist/{run-YHOLKUYB.js → run-FMTHUOAZ.js} +4 -4
  68. package/dist/{run-MVP22ENA.js → run-V74M7PZK.js} +9 -8
  69. package/dist/{serve-EAESQK2I.js → serve-JKNEC4AX.js} +3 -3
  70. package/dist/{setup-3GET6K3J.js → setup-HYEYYVDU.js} +3 -3
  71. package/dist/{smoke-FQQJOQBD.js → smoke-UA7VVDKD.js} +4 -3
  72. package/dist/{start-login-K3TAZ3IH.js → start-login-JRMVLK5J.js} +10 -9
  73. package/dist/{status-25DRPV7U.js → status-6273XFHT.js} +10 -9
  74. package/dist/{status-3RTGDN2K.js → status-KN2ZE64O.js} +3 -3
  75. package/dist/{status-DPPNTGHB.js → status-RG2GFDQU.js} +12 -11
  76. package/dist/stdio.js +2 -2
  77. package/dist/{sweep-EPJMEZR6.js → sweep-EPZCW63Q.js} +3 -3
  78. package/dist/{test-I2V5AMQF.js → test-M365FK5N.js} +23 -15
  79. package/dist/{tui-VCEN2L5I.js → tui-PKPYE76A.js} +4 -4
  80. package/dist/{unbroadcast-NTOC3PY3.js → unbroadcast-N6LXHAMT.js} +3 -3
  81. package/dist/{worker-NPQFYEBU.js → worker-C23EAPCY.js} +9 -7
  82. package/docs/commands.md +1 -1
  83. package/docs/git-workflow.md +21 -12
  84. package/docs/hooks.md +7 -1
  85. package/docs/project-configuration.md +1 -0
  86. package/docs/upgrading.md +13 -0
  87. package/gemini-extension.json +2 -2
  88. package/mcp.json +1 -1
  89. package/package.json +5 -5
  90. package/plugin.json +1 -1
  91. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  92. package/plugins/pmcp/.mcp.json +1 -1
  93. package/plugins/pmcp/gemini-extension.json +2 -2
  94. package/plugins/pmcp/mcp.json +1 -1
  95. package/plugins/pmcp/mod/commands.ts +10 -4
  96. package/plugins/pmcp/mod/host.ts +17 -1
  97. package/plugins/pmcp/mod/reader/read.ts +3 -1
  98. package/plugins/pmcp/mod/reader/types.ts +2 -0
  99. package/plugins/pmcp/mod/register.tsx +2 -1
  100. package/plugins/pmcp/mod/snapshot.ts +1 -0
  101. package/plugins/pmcp/mod/state.ts +1 -0
  102. package/plugins/pmcp/plugin.json +1 -1
  103. package/dist/chunk-ACHBHIGD.js +0 -7
@@ -8,38 +8,39 @@ import {
8
8
  } from "./chunk-UPQTAHUK.js";
9
9
  import {
10
10
  specFrom
11
- } from "./chunk-DPVLHB3K.js";
11
+ } from "./chunk-PR2RBEXI.js";
12
12
  import "./chunk-RPCIROW7.js";
13
13
  import {
14
14
  launch
15
- } from "./chunk-6HCEEC6V.js";
15
+ } from "./chunk-MLGXDSHZ.js";
16
16
  import "./chunk-UKR64U7J.js";
17
17
  import "./chunk-XZ2TDH3J.js";
18
18
  import "./chunk-KUBHGVTD.js";
19
19
  import "./chunk-EATCUWGG.js";
20
20
  import "./chunk-OFJIMBTL.js";
21
- import {
22
- ProjectError
23
- } from "./chunk-NRBQK6UX.js";
24
21
  import "./chunk-LFFIQBNY.js";
25
22
  import "./chunk-HQOB7OQS.js";
26
23
  import "./chunk-73AKO4UL.js";
27
24
  import "./chunk-P6LNYYYH.js";
28
- import "./chunk-GBKRDRMZ.js";
25
+ import "./chunk-FE7WOHZM.js";
29
26
  import "./chunk-2Q6MNGU5.js";
30
- import "./chunk-MR5IBS6L.js";
27
+ import "./chunk-7I7O7ZNT.js";
31
28
  import "./chunk-Z6WRFOFT.js";
32
29
  import "./chunk-G7JONWL4.js";
33
30
  import {
34
31
  McpAuthError
35
32
  } from "./chunk-Q5H3L6Y4.js";
36
- import "./chunk-5YCKFU5Q.js";
33
+ import "./chunk-7DYWCQVB.js";
37
34
  import "./chunk-A4PKLESO.js";
38
35
  import "./chunk-V4NPDK6X.js";
39
- import "./chunk-UVGW56SY.js";
36
+ import "./chunk-ULFV3EIZ.js";
37
+ import {
38
+ ProjectError
39
+ } from "./chunk-NRBQK6UX.js";
40
40
  import "./chunk-OEH47H6A.js";
41
41
  import "./chunk-IJBSOWHK.js";
42
- import "./chunk-ACHBHIGD.js";
42
+ import "./chunk-XWLMZKH2.js";
43
+ import "./chunk-JTRFZQTB.js";
43
44
  import "./chunk-GJXOFDJT.js";
44
45
  import "./chunk-PMJG2CXF.js";
45
46
  import "./chunk-J6KL3COD.js";
@@ -365,4 +366,4 @@ function runExecMcp(context, name) {
365
366
  export {
366
367
  runExecMcp
367
368
  };
368
- //# sourceMappingURL=exec-mcp-EJZVPVU5.js.map
369
+ //# sourceMappingURL=exec-mcp-HOM2ZANM.js.map
@@ -151,12 +151,12 @@ var harnessCommand = {
151
151
  return runPtyMcp(context);
152
152
  }
153
153
  if (context.args.positional[0] === "host") {
154
- const { runHost } = await import("./host-GY2LFEZX.js");
154
+ const { runHost } = await import("./host-CE5TW5SC.js");
155
155
  return runHost(context);
156
156
  }
157
157
  try {
158
158
  const operation = parseInvocation(context);
159
- const { invoke } = await import("./invoke-7BUFBFJU.js");
159
+ const { invoke } = await import("./invoke-HEAOQLFQ.js");
160
160
  const receipt = await invoke(operation);
161
161
  context.ui.data(`${JSON.stringify(receipt)}
162
162
  `);
@@ -174,4 +174,4 @@ var harnessCommand = {
174
174
  export {
175
175
  harnessCommand
176
176
  };
177
- //# sourceMappingURL=harness-VMQJY3KY.js.map
177
+ //# sourceMappingURL=harness-WIGJRE5P.js.map
@@ -7,12 +7,14 @@ import {
7
7
  assertProof,
8
8
  assertResourceFresh,
9
9
  createProof
10
- } from "./chunk-FHK5BE2D.js";
10
+ } from "./chunk-UQNRGU3V.js";
11
11
  import "./chunk-34DECPVC.js";
12
- import "./chunk-UVGW56SY.js";
12
+ import "./chunk-ULFV3EIZ.js";
13
+ import "./chunk-NRBQK6UX.js";
13
14
  import "./chunk-OEH47H6A.js";
14
15
  import "./chunk-IJBSOWHK.js";
15
- import "./chunk-ACHBHIGD.js";
16
+ import "./chunk-XWLMZKH2.js";
17
+ import "./chunk-JTRFZQTB.js";
16
18
  import "./chunk-GJXOFDJT.js";
17
19
  import "./chunk-PMJG2CXF.js";
18
20
  import {
@@ -1,14 +1,16 @@
1
1
  import {
2
2
  runOperation
3
- } from "./chunk-SB6X342E.js";
4
- import "./chunk-M5LC5TKQ.js";
3
+ } from "./chunk-NQFULJZC.js";
4
+ import "./chunk-7Q3AIS4Q.js";
5
5
  import "./chunk-R2GPCZUX.js";
6
- import "./chunk-FHK5BE2D.js";
6
+ import "./chunk-UQNRGU3V.js";
7
7
  import "./chunk-34DECPVC.js";
8
- import "./chunk-UVGW56SY.js";
8
+ import "./chunk-ULFV3EIZ.js";
9
+ import "./chunk-NRBQK6UX.js";
9
10
  import "./chunk-OEH47H6A.js";
10
11
  import "./chunk-IJBSOWHK.js";
11
- import "./chunk-ACHBHIGD.js";
12
+ import "./chunk-XWLMZKH2.js";
13
+ import "./chunk-JTRFZQTB.js";
12
14
  import "./chunk-GJXOFDJT.js";
13
15
  import "./chunk-PMJG2CXF.js";
14
16
  import {
package/dist/hook-body.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/hooks/entry.ts
2
- import { dirname as dirname12, resolve as resolve19 } from "node:path";
2
+ import { dirname as dirname12, resolve as resolve20 } from "node:path";
3
3
 
4
4
  // src/hooks/contract.ts
5
5
  var NEUTRAL_EVENTS = [
@@ -741,11 +741,12 @@ async function runPolicy(selected, input, deps) {
741
741
  const { policy, mode } = selected;
742
742
  const log = deps.log.child({ policy: policy.id });
743
743
  const started = deps.now();
744
- const finish = (decision) => {
744
+ const finish = (decision, raw) => {
745
745
  deps.onPolicy?.({
746
746
  policy: policy.id,
747
747
  mode,
748
748
  decision,
749
+ ...raw ? { raw } : {},
749
750
  durationMs: deps.now() - started
750
751
  });
751
752
  return decision;
@@ -785,7 +786,7 @@ async function runPolicy(selected, input, deps) {
785
786
  ...input.tool ? { tool: input.tool.kind, native: input.tool.native } : {},
786
787
  duration_ms: deps.now() - started
787
788
  });
788
- return finish(decision);
789
+ return finish(decision, raw);
789
790
  } catch (error) {
790
791
  log.error("policy failed", {
791
792
  error: error instanceof Error ? error.message : String(error)
@@ -2252,7 +2253,7 @@ function classEnd(pattern, start) {
2252
2253
  function patternCost(pattern, flavor, onlyMatching, limits) {
2253
2254
  const largest = Math.max(0, ...repetitionCounts(pattern, flavor));
2254
2255
  if (largest > limits.threshold)
2255
- return `a repetition count of ${largest} (the limit is ${limits.threshold})`;
2256
+ return `a repetition count of ${largest} (the limit is ${limits.threshold}), whose cost is in compiling the pattern, so even an empty input holds the core`;
2256
2257
  if (flavor === "perl" && nestedQuantifier(pattern))
2257
2258
  return "a -P pattern with a quantified group inside a quantifier, such as (a+)+ or (.*)*";
2258
2259
  if (limits.onlyMatchingWildcards && onlyMatching && (pattern.match(/\.\*/gu) ?? []).length > 1)
@@ -5132,6 +5133,14 @@ function rememberVerified(key, stamp, sha) {
5132
5133
  }
5133
5134
  }
5134
5135
 
5136
+ // src/hooks/lock-text.ts
5137
+ var MARKER = /^(?:<{7}|={7}|>{7})(?: |$)/mu;
5138
+ function lockProblem(text9) {
5139
+ const at = text9.split("\n").findIndex((line) => MARKER.test(line));
5140
+ const what = at >= 0 ? `pmcp.lock holds git conflict markers (line ${at + 1})` : "pmcp.lock is not valid JSON";
5141
+ return `${what}; restore it with git checkout <rev> -- pmcp.lock or git show <rev>:pmcp.lock > pmcp.lock, then run pmcp project`;
5142
+ }
5143
+
5135
5144
  // src/hooks/compiled.ts
5136
5145
  var HOOK_DIRECTORY = ".agents/pmcp-hooks";
5137
5146
  var POLICY_FILE = `${HOOK_DIRECTORY}/policy.json`;
@@ -5143,13 +5152,23 @@ function sha256(text9) {
5143
5152
  }
5144
5153
  var PolicyIntegrityError = class extends Error {
5145
5154
  };
5155
+ var LockUnreadableError = class extends PolicyIntegrityError {
5156
+ };
5146
5157
  var MISMATCH = "policy.json does not match pmcp.lock; review the change and run pmcp project";
5158
+ function readLockFile(path) {
5159
+ const text9 = readFileSync(path, "utf8");
5160
+ try {
5161
+ return JSON.parse(text9);
5162
+ } catch {
5163
+ throw new LockUnreadableError(lockProblem(text9));
5164
+ }
5165
+ }
5147
5166
  function readCompiled(root) {
5148
5167
  const policyPath = join11(root, POLICY_FILE);
5149
5168
  const files2 = [policyPath, join11(root, LOCK_FILE)];
5150
5169
  const before2 = stampOf(files2);
5151
5170
  const text9 = readFileSync(policyPath, "utf8");
5152
- const lock = JSON.parse(readFileSync(files2[1], "utf8"));
5171
+ const lock = readLockFile(files2[1]);
5153
5172
  const entry = lock.outputs?.find((output) => output.path === POLICY_FILE);
5154
5173
  const expected = typeof entry?.sha256 === "string" ? entry.sha256 : null;
5155
5174
  if (expected === null) throw new PolicyIntegrityError(MISMATCH);
@@ -5203,8 +5222,48 @@ function failClosed(adapter, event, root, error, stated = false) {
5203
5222
  return adapter.render(input, { verdict: "deny", reason: reason2 }).stdout;
5204
5223
  }
5205
5224
 
5225
+ // src/hooks/entry/lock-repair.ts
5226
+ import { join as join13, resolve as resolve19 } from "node:path";
5227
+ var REV = String.raw`[\w./~^@{}-]+`;
5228
+ var LOCK = String.raw`(?:\./)?pmcp\.lock`;
5229
+ var REPAIRS = [
5230
+ new RegExp(String.raw`^git show ${REV}:${LOCK} > ${LOCK}$`, "u"),
5231
+ new RegExp(
5232
+ String.raw`^git checkout (?:(?:--ours|--theirs|${REV}) )?(?:-- )?${LOCK}$`,
5233
+ "u"
5234
+ ),
5235
+ new RegExp(
5236
+ String.raw`^git restore (?:(?:--source=${REV}|--staged|--worktree|--ours|--theirs|-[SW]+) )*(?:-- )?${LOCK}$`,
5237
+ "u"
5238
+ )
5239
+ ];
5240
+ function repairsLock(input, root) {
5241
+ const tool = input.tool;
5242
+ if (!tool) return false;
5243
+ if (tool.kind === "read") return true;
5244
+ if (tool.kind === "edit") {
5245
+ const lock = join13(root, LOCK_FILE);
5246
+ return tool.paths.length > 0 && tool.paths.every((path) => resolve19(input.cwd, path) === lock);
5247
+ }
5248
+ if (tool.kind === "shell") {
5249
+ const command6 = (tool.command ?? "").trim().replace(/\s+/gu, " ");
5250
+ return REPAIRS.some((pattern) => pattern.test(command6));
5251
+ }
5252
+ return false;
5253
+ }
5254
+ function lockRepair(adapter, event, root, input, error) {
5255
+ if (event !== "before_tool") return "";
5256
+ if (input && repairsLock(input, root))
5257
+ return adapter.render(input, {
5258
+ context: [
5259
+ `pmcp hooks: ${error.message}; this call repairs it, so it passes`
5260
+ ]
5261
+ }).stdout;
5262
+ return failClosed(adapter, event, root, error);
5263
+ }
5264
+
5206
5265
  // src/hooks/entry/logger.ts
5207
- import { dirname as dirname8, join as join15 } from "node:path";
5266
+ import { dirname as dirname8, join as join16 } from "node:path";
5208
5267
 
5209
5268
  // src/logging/levels.ts
5210
5269
  var LEVEL_RANK = {
@@ -5328,11 +5387,11 @@ var silentLogger = createLogger(() => {
5328
5387
  });
5329
5388
 
5330
5389
  // src/logging/sinks/file.ts
5331
- import { join as join13 } from "node:path";
5390
+ import { join as join14 } from "node:path";
5332
5391
  var FILE = /^pmcp-(\d{8})(?:\.\d+)?\.jsonl$/u;
5333
5392
  function dailyLogFile(dir, now = /* @__PURE__ */ new Date()) {
5334
5393
  const day = now.toISOString().slice(0, 10).replaceAll("-", "");
5335
- return join13(dir, `pmcp-${day}.jsonl`);
5394
+ return join14(dir, `pmcp-${day}.jsonl`);
5336
5395
  }
5337
5396
  function roll(file2) {
5338
5397
  let index = 1;
@@ -5363,7 +5422,7 @@ function logFiles(dir) {
5363
5422
  const part = (name) => Number(/\.(\d+)\.jsonl$/u.exec(name)?.[1] ?? Number.MAX_SAFE_INTEGER);
5364
5423
  return names2.sort(
5365
5424
  (a, b) => a.slice(5, 13).localeCompare(b.slice(5, 13)) || part(a) - part(b)
5366
- ).map((name) => join13(dir, name));
5425
+ ).map((name) => join14(dir, name));
5367
5426
  }
5368
5427
  function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
5369
5428
  const cutoff = new Date(now.getTime() - keepDays * 864e5).toISOString().slice(0, 10).replaceAll("-", "");
@@ -5379,13 +5438,13 @@ function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
5379
5438
 
5380
5439
  // src/sessions/state-dir.ts
5381
5440
  import { homedir as homedir3 } from "node:os";
5382
- import { join as join14 } from "node:path";
5441
+ import { join as join15 } from "node:path";
5383
5442
  function projectStateDir(root, override, env = process.env) {
5384
5443
  if (override) return expandPath(root, override);
5385
5444
  const anchor = gitCommonDir(root) ?? realpathSync(root);
5386
5445
  const id = createHash("sha256").update(anchor).digest("hex").slice(0, 16);
5387
- const base = env["XDG_STATE_HOME"] || join14(homedir3(), ".local", "state");
5388
- return join14(base, "pmcp", "projects", id);
5446
+ const base = env["XDG_STATE_HOME"] || join15(homedir3(), ".local", "state");
5447
+ return join15(base, "pmcp", "projects", id);
5389
5448
  }
5390
5449
 
5391
5450
  // src/hooks/entry/logger.ts
@@ -5400,7 +5459,7 @@ function hookLogger(root, compiled, runtime2, event) {
5400
5459
  process.env["PMCP_LOG"]
5401
5460
  );
5402
5461
  const file2 = compiled?.logFile ? expandPath(root, compiled.logFile) : void 0;
5403
- const dir = file2 ? dirname8(file2) : join15(projectStateDir(root, compiled?.stateDir), "logs");
5462
+ const dir = file2 ? dirname8(file2) : join16(projectStateDir(root, compiled?.stateDir), "logs");
5404
5463
  const sink = fileSink({
5405
5464
  dir,
5406
5465
  ...file2 ? { file: file2 } : {},
@@ -5416,13 +5475,73 @@ function hookLogger(root, compiled, runtime2, event) {
5416
5475
  }
5417
5476
 
5418
5477
  // src/hooks/entry/state-dir.ts
5419
- function stateDirAnswer(root) {
5420
- let declared;
5478
+ import { join as join18 } from "node:path";
5479
+
5480
+ // src/sessions/lease-files.ts
5481
+ import { dirname as dirname9, isAbsolute as isAbsolute13, join as join17 } from "node:path";
5482
+ var GATE_DIR = "${gate_dir}/";
5483
+ function gateTree(root, stateDir, gate, env) {
5484
+ const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
5485
+ if (override) return override;
5486
+ return gate.tree ? expandPath(root, gate.tree) : join17(stateDir, "gate", "tree");
5487
+ }
5488
+ function atGateDir(path, gateDir) {
5489
+ return path.startsWith(GATE_DIR) ? join17(gateDir, path.slice(GATE_DIR.length)) : path;
5490
+ }
5491
+ function resolvePauseFile(file2, gateDir) {
5492
+ return file2 === void 0 ? void 0 : atGateDir(file2, gateDir);
5493
+ }
5494
+ function resolveLeaseFiles(files2, gateDir) {
5495
+ const resolve21 = (path) => path === void 0 ? void 0 : atGateDir(path, gateDir);
5496
+ return Object.fromEntries(
5497
+ Object.entries(files2 ?? {}).map(([name, f]) => {
5498
+ const file2 = resolve21(f.file);
5499
+ const events2 = resolve21(f.events);
5500
+ return [
5501
+ name,
5502
+ { ...file2 ? { file: file2 } : {}, ...events2 ? { events: events2 } : {} }
5503
+ ];
5504
+ })
5505
+ );
5506
+ }
5507
+ function leaseFilesFor(root, stateDir, files2, gate, env) {
5508
+ if (!files2 || Object.keys(files2).length === 0) return {};
5509
+ return resolveLeaseFiles(
5510
+ files2,
5511
+ dirname9(gateTree(root, stateDir, gate ?? {}, env))
5512
+ );
5513
+ }
5514
+ function pauseFileFor(root, stateDir, file2, gate, env) {
5515
+ if (!file2) return void 0;
5516
+ return resolvePauseFile(
5517
+ file2,
5518
+ dirname9(gateTree(root, stateDir, gate ?? {}, env))
5519
+ );
5520
+ }
5521
+
5522
+ // src/hooks/entry/state-dir.ts
5523
+ function verified(root) {
5421
5524
  try {
5422
- declared = readCompiled(root).stateDir;
5525
+ return readCompiled(root);
5423
5526
  } catch {
5527
+ return null;
5424
5528
  }
5425
- return `${projectStateDir(root, declared)}
5529
+ }
5530
+ function stateDirAnswer(root) {
5531
+ return `${projectStateDir(root, verified(root)?.stateDir)}
5532
+ `;
5533
+ }
5534
+ function pauseFileAnswer(root) {
5535
+ const compiled = verified(root);
5536
+ const stateDir = projectStateDir(root, compiled?.stateDir);
5537
+ const file2 = pauseFileFor(
5538
+ root,
5539
+ stateDir,
5540
+ compiled?.sessions.pauseFile,
5541
+ compiled?.sessions.gate,
5542
+ process.env
5543
+ );
5544
+ return `${file2 ?? join18(stateDir, STATE_FILES.pause)}
5426
5545
  `;
5427
5546
  }
5428
5547
 
@@ -5460,10 +5579,10 @@ var gitProbe = {
5460
5579
  };
5461
5580
 
5462
5581
  // src/sessions/files/broadcast.ts
5463
- import { join as join16 } from "node:path";
5582
+ import { join as join19 } from "node:path";
5464
5583
 
5465
5584
  // src/sessions/files/json.ts
5466
- import { dirname as dirname9 } from "node:path";
5585
+ import { dirname as dirname10 } from "node:path";
5467
5586
  function readJson3(path) {
5468
5587
  try {
5469
5588
  return JSON.parse(readFileSync(path, "utf8"));
@@ -5472,7 +5591,7 @@ function readJson3(path) {
5472
5591
  }
5473
5592
  }
5474
5593
  function writeJson(path, value) {
5475
- mkdirSync(dirname9(path), { recursive: true, mode: 448 });
5594
+ mkdirSync(dirname10(path), { recursive: true, mode: 448 });
5476
5595
  const temporary = `${path}.${process.pid}.tmp`;
5477
5596
  writeFileSync(temporary, `${JSON.stringify(value, null, 2)}
5478
5597
  `, {
@@ -5496,7 +5615,7 @@ function readLines(path) {
5496
5615
  });
5497
5616
  }
5498
5617
  function writeLines(path, values) {
5499
- mkdirSync(dirname9(path), { recursive: true, mode: 448 });
5618
+ mkdirSync(dirname10(path), { recursive: true, mode: 448 });
5500
5619
  writeFileSync(
5501
5620
  path,
5502
5621
  `${values.map((value) => JSON.stringify(value)).join("\n")}
@@ -5507,8 +5626,8 @@ function writeLines(path, values) {
5507
5626
 
5508
5627
  // src/sessions/files/broadcast.ts
5509
5628
  function filesBroadcast(dir, keep, registry2) {
5510
- const latestPath = join16(dir, STATE_FILES.broadcast);
5511
- const historyPath = join16(dir, STATE_FILES.history);
5629
+ const latestPath = join19(dir, STATE_FILES.broadcast);
5630
+ const historyPath = join19(dir, STATE_FILES.history);
5512
5631
  const list = () => {
5513
5632
  const latest = asBroadcast(readJson3(latestPath));
5514
5633
  if (!latest) return [];
@@ -5552,9 +5671,9 @@ function filesBroadcast(dir, keep, registry2) {
5552
5671
  }
5553
5672
 
5554
5673
  // src/sessions/files/leases.ts
5555
- import { dirname as dirname10, join as join17 } from "node:path";
5674
+ import { dirname as dirname11, join as join20 } from "node:path";
5556
5675
  function filesLeases(dir, files2 = {}) {
5557
- const leasePath = (name) => files2[name]?.file ?? join17(dir, leaseFile(name));
5676
+ const leasePath = (name) => files2[name]?.file ?? join20(dir, leaseFile(name));
5558
5677
  const read3 = (name) => {
5559
5678
  const lease = asLease(readJson3(leasePath(name)));
5560
5679
  if (!lease || !alive(lease.pid)) return null;
@@ -5574,7 +5693,7 @@ function filesLeases(dir, files2 = {}) {
5574
5693
  ...lease.cwd ? { cwd: lease.cwd } : {},
5575
5694
  since: (/* @__PURE__ */ new Date()).toISOString()
5576
5695
  };
5577
- mkdirSync(dirname10(path), { recursive: true });
5696
+ mkdirSync(dirname11(path), { recursive: true });
5578
5697
  const temp = `${path}.${process.pid}.${Date.now()}.tmp`;
5579
5698
  writeFileSync(temp, `${JSON.stringify(record)}
5580
5699
  `);
@@ -5604,28 +5723,28 @@ function filesLeases(dir, files2 = {}) {
5604
5723
  }
5605
5724
 
5606
5725
  // src/sessions/files/mailbox.ts
5607
- import { join as join18 } from "node:path";
5726
+ import { join as join21 } from "node:path";
5608
5727
  var ID = /^\d{13}-[0-9a-f]{8}$/u;
5609
5728
  var SAFE_KEY = /^@?[\w.-]+$/u;
5610
5729
  function filesMailbox(dir, settings) {
5611
- const messages = join18(dir, "messages");
5612
- const inbox = join18(dir, "inbox");
5613
- const pathOf = (id) => join18(messages, `${id}.json`);
5730
+ const messages = join21(dir, "messages");
5731
+ const inbox = join21(dir, "inbox");
5732
+ const pathOf = (id) => join21(messages, `${id}.json`);
5614
5733
  const marker = (key, id, kind) => {
5615
5734
  if (!SAFE_KEY.test(key) || !ID.test(id))
5616
5735
  throw new Error(`invalid mailbox key ${key} or id ${id}`);
5617
- return join18(inbox, key, `${id}.${kind}`);
5736
+ return join21(inbox, key, `${id}.${kind}`);
5618
5737
  };
5619
5738
  const audit = (event, fields2) => {
5620
5739
  if (!settings.audit) return;
5621
5740
  const line = { at: (/* @__PURE__ */ new Date()).toISOString(), event, ...fields2 };
5622
- appendFileSync(join18(dir, "messages.jsonl"), `${JSON.stringify(line)}
5741
+ appendFileSync(join21(dir, "messages.jsonl"), `${JSON.stringify(line)}
5623
5742
  `, {
5624
5743
  mode: 384
5625
5744
  });
5626
5745
  };
5627
5746
  const touch = (path) => {
5628
- mkdirSync(join18(path, ".."), { recursive: true, mode: 448 });
5747
+ mkdirSync(join21(path, ".."), { recursive: true, mode: 448 });
5629
5748
  try {
5630
5749
  writeFileSync(path, "", { flag: "wx", mode: 384 });
5631
5750
  return true;
@@ -5642,7 +5761,7 @@ function filesMailbox(dir, settings) {
5642
5761
  if (existsSync(inbox))
5643
5762
  for (const key of readdirSync(inbox))
5644
5763
  for (const kind of ["ack", "delivered"])
5645
- rmSync(join18(inbox, key, `${message.id}.${kind}`), { force: true });
5764
+ rmSync(join21(inbox, key, `${message.id}.${kind}`), { force: true });
5646
5765
  audit(event, { id: message.id });
5647
5766
  };
5648
5767
  return {
@@ -5718,9 +5837,9 @@ function filesMailbox(dir, settings) {
5718
5837
  }
5719
5838
 
5720
5839
  // src/sessions/files/pause.ts
5721
- import { join as join19 } from "node:path";
5722
- function filesPause(dir) {
5723
- const path = join19(dir, STATE_FILES.pause);
5840
+ import { join as join22 } from "node:path";
5841
+ function filesPause(dir, file2) {
5842
+ const path = file2 ?? join22(dir, STATE_FILES.pause);
5724
5843
  return {
5725
5844
  read: () => asPause(readJson3(path)),
5726
5845
  write(pause2) {
@@ -5738,12 +5857,12 @@ function filesPause(dir) {
5738
5857
  }
5739
5858
 
5740
5859
  // src/sessions/files/registry.ts
5741
- import { join as join20 } from "node:path";
5860
+ import { join as join23 } from "node:path";
5742
5861
  var SESSION_ID = /^[A-Za-z0-9_-]{8,64}$/u;
5743
5862
  function filesRegistry(dir, staleMs) {
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`));
5863
+ const records = join23(dir, STATE_FILES.records);
5864
+ const dirs = [records, join23(dir, STATE_FILES.legacyRecords)];
5865
+ const pathsOf = (session) => dirs.map((records2) => join23(records2, `${session}.json`));
5747
5866
  const get = (session) => {
5748
5867
  if (!SESSION_ID.test(session)) return null;
5749
5868
  return latestRecord(
@@ -5762,7 +5881,7 @@ function filesRegistry(dir, staleMs) {
5762
5881
  for (const name of names2)
5763
5882
  found.set(name, [
5764
5883
  ...found.get(name) ?? [],
5765
- asRecord(readJson3(join20(folder, name)))
5884
+ asRecord(readJson3(join23(folder, name)))
5766
5885
  ]);
5767
5886
  }
5768
5887
  return [...found.values()].map(latestRecord).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
@@ -5789,7 +5908,7 @@ function filesRegistry(dir, staleMs) {
5789
5908
  next["worktree"] = checkout?.root ?? "";
5790
5909
  next["branch"] = checkout?.branch ?? "";
5791
5910
  }
5792
- writeJson(join20(records, `${session}.json`), next);
5911
+ writeJson(join23(records, `${session}.json`), next);
5793
5912
  return next;
5794
5913
  },
5795
5914
  sweep(now = Date.now()) {
@@ -5814,7 +5933,7 @@ function createFilesStore(dir, options2 = {}) {
5814
5933
  return {
5815
5934
  dir,
5816
5935
  registry: registry2,
5817
- pause: filesPause(dir),
5936
+ pause: filesPause(dir, options2.pauseFile),
5818
5937
  leases: filesLeases(dir, options2.leaseFiles),
5819
5938
  // With the mailbox on, a broadcast is also a message to all, which the mailbox delivers;
5820
5939
  // broadcast.json stays the record status, snapshot and the Claude band read.
@@ -5839,41 +5958,16 @@ function createFilesStore(dir, options2 = {}) {
5839
5958
  };
5840
5959
  }
5841
5960
 
5842
- // src/sessions/lease-files.ts
5843
- import { dirname as dirname11, isAbsolute as isAbsolute13, join as join21 } from "node:path";
5844
- var GATE_DIR = "${gate_dir}/";
5845
- function gateTree(root, stateDir, gate, env) {
5846
- const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
5847
- if (override) return override;
5848
- return gate.tree ? expandPath(root, gate.tree) : join21(stateDir, "gate", "tree");
5849
- }
5850
- function resolveLeaseFiles(files2, gateDir) {
5851
- const resolve20 = (path) => path?.startsWith(GATE_DIR) ? join21(gateDir, path.slice(GATE_DIR.length)) : path;
5852
- return Object.fromEntries(
5853
- Object.entries(files2 ?? {}).map(([name, f]) => {
5854
- const file2 = resolve20(f.file);
5855
- const events2 = resolve20(f.events);
5856
- return [
5857
- name,
5858
- { ...file2 ? { file: file2 } : {}, ...events2 ? { events: events2 } : {} }
5859
- ];
5860
- })
5861
- );
5862
- }
5863
- function leaseFilesFor(root, stateDir, files2, gate, env) {
5864
- if (!files2 || Object.keys(files2).length === 0) return {};
5865
- return resolveLeaseFiles(
5866
- files2,
5867
- dirname11(gateTree(root, stateDir, gate ?? {}, env))
5868
- );
5869
- }
5870
-
5871
5961
  // src/hooks/entry.ts
5872
5962
  async function main(argv, root) {
5873
5963
  if (argv[0] === "--state-dir") {
5874
5964
  writeStdout(stateDirAnswer(root));
5875
5965
  return 0;
5876
5966
  }
5967
+ if (argv[0] === "--pause-file") {
5968
+ writeStdout(pauseFileAnswer(root));
5969
+ return 0;
5970
+ }
5877
5971
  const projected = runtime(argv[0] ?? "");
5878
5972
  const event = argv[1];
5879
5973
  if (!projected || !NEUTRAL_EVENTS.includes(event) || !projected.nativeEvent(event)) {
@@ -5901,6 +5995,13 @@ async function main(argv, root) {
5901
5995
  if (!input) return pass2();
5902
5996
  const run3 = log.child({ session: input.session.id });
5903
5997
  const stateDir = projectStateDir(root, compiled.stateDir);
5998
+ const pauseFile = pauseFileFor(
5999
+ root,
6000
+ stateDir,
6001
+ compiled.sessions.pauseFile,
6002
+ compiled.sessions.gate,
6003
+ process.env
6004
+ );
5904
6005
  const store = createFilesStore(stateDir, {
5905
6006
  ...compiled.sessions,
5906
6007
  leaseFiles: leaseFilesFor(
@@ -5909,7 +6010,8 @@ async function main(argv, root) {
5909
6010
  compiled.sessions.leaseFiles,
5910
6011
  compiled.sessions.gate,
5911
6012
  process.env
5912
- )
6013
+ ),
6014
+ ...pauseFile ? { pauseFile } : {}
5913
6015
  });
5914
6016
  const decision = await dispatch(input, compiled, {
5915
6017
  log: run3,
@@ -5932,6 +6034,17 @@ async function main(argv, root) {
5932
6034
  log.error("hook failed", {
5933
6035
  error: error instanceof Error ? error.message : String(error)
5934
6036
  });
6037
+ if (error instanceof LockUnreadableError) {
6038
+ try {
6039
+ payload ??= JSON.parse(readStdin() || "{}");
6040
+ const native = adapter.nativeEvent(event);
6041
+ input = native ? adapter.normalize(native, payload, root) : null;
6042
+ } catch {
6043
+ input = null;
6044
+ }
6045
+ writeStdout(lockRepair(adapter, event, root, input, error));
6046
+ return 0;
6047
+ }
5935
6048
  const failure = error instanceof PolicyIntegrityError ? void 0 : compiled?.failure ?? rawFailure(root);
5936
6049
  if (failure) {
5937
6050
  if (!input && payload !== null) {
@@ -5950,10 +6063,10 @@ async function main(argv, root) {
5950
6063
  }
5951
6064
  }
5952
6065
  var self = import.meta.filename;
5953
- if (process.argv[1] && resolve19(process.argv[1]) === self) {
6066
+ if (process.argv[1] && resolve20(process.argv[1]) === self) {
5954
6067
  process.exitCode = await main(
5955
6068
  process.argv.slice(2),
5956
- resolve19(dirname12(self), "../..")
6069
+ resolve20(dirname12(self), "../..")
5957
6070
  );
5958
6071
  }
5959
6072
  export {
@@ -68,6 +68,7 @@ interface CompiledPolicy {
68
68
  readonly keepBroadcasts: number;
69
69
  readonly mailbox?: MailboxSettings;
70
70
  readonly leaseFiles?: Readonly<Record<string, LeaseFiles>>;
71
+ readonly pauseFile?: string;
71
72
  readonly gate?: GateLocation;
72
73
  };
73
74
  readonly guards: readonly CompiledGuard[];
@@ -11,14 +11,14 @@ async function run(context) {
11
11
  const [verb = "list", ...extra] = context.args.positional;
12
12
  const usage = "Use hooks list, hooks test or hooks report";
13
13
  if (extra.length) throw new ArgumentError(usage);
14
- if (verb === "list") return (await import("./list-D3Y3TIC6.js")).run(context);
15
- if (verb === "test") return (await import("./test-I2V5AMQF.js")).run(context);
14
+ if (verb === "list") return (await import("./list-PCLCFG2J.js")).run(context);
15
+ if (verb === "test") return (await import("./test-M365FK5N.js")).run(context);
16
16
  if (verb === "report")
17
- return (await import("./report-Z3JV2PCT.js")).run(context);
17
+ return (await import("./report-ZHOHQ4PZ.js")).run(context);
18
18
  throw new ArgumentError(usage);
19
19
  }
20
20
  var hooksCommand = { ...hooksSpec, run };
21
21
  export {
22
22
  hooksCommand
23
23
  };
24
- //# sourceMappingURL=hooks-SKD67KMA.js.map
24
+ //# sourceMappingURL=hooks-MIF3FONJ.js.map