@modootoday/pmcp 0.24.1 → 0.26.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 (116) 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/{affected-IPFJM2KD.js → affected-4FILH743.js} +174 -77
  6. package/dist/{apply-CDJQJAZH.js → apply-HJUCYQDQ.js} +18 -15
  7. package/dist/{broadcast-VKZY7WSD.js → broadcast-U7ZYOJWE.js} +7 -4
  8. package/dist/{chunk-GEDRPMBH.js → chunk-2GL5L2G5.js} +2 -2
  9. package/dist/{chunk-AQM2JZMB.js → chunk-2JUHFM4V.js} +2 -2
  10. package/dist/{chunk-UKR64U7J.js → chunk-374AZ4J4.js} +2 -2
  11. package/dist/{chunk-MZ52S4YJ.js → chunk-3JOFDNL4.js} +2 -2
  12. package/dist/{chunk-264DIB5U.js → chunk-3KISMGVP.js} +4 -4
  13. package/dist/{chunk-V5PXMLLL.js → chunk-6XE3WW7S.js} +3 -3
  14. package/dist/{chunk-7CGGDX7X.js → chunk-7FHOSWNQ.js} +2 -2
  15. package/dist/{chunk-5NQZGNKT.js → chunk-7PBWLYCO.js} +3 -3
  16. package/dist/{chunk-2GZKA33O.js → chunk-A4P3IIPE.js} +2 -2
  17. package/dist/{chunk-3O3JZTUU.js → chunk-C7Y2MBCN.js} +3 -3
  18. package/dist/chunk-D7IDT7OA.js +21 -0
  19. package/dist/chunk-E272CFPS.js +14 -0
  20. package/dist/chunk-FLG7VRTC.js +1 -0
  21. package/dist/{chunk-X3RUXLAV.js → chunk-FXDGW2IH.js} +3 -3
  22. package/dist/{chunk-DLIO2D7S.js → chunk-GIL3RBRX.js} +27 -20
  23. package/dist/{chunk-ARXCYFFZ.js → chunk-GQRDEIQA.js} +22 -2
  24. package/dist/chunk-J43Z4O3G.js +7 -0
  25. package/dist/chunk-KLIYFD3W.js +32 -0
  26. package/dist/{chunk-PG62GOPU.js → chunk-KQV2EPAP.js} +2 -2
  27. package/dist/{chunk-LNKAR3IS.js → chunk-LCPCRZ7N.js} +2 -2
  28. package/dist/chunk-NQCAKDRY.js +156 -0
  29. package/dist/{chunk-3SEJNT6F.js → chunk-NQZMGQFG.js} +5 -5
  30. package/dist/{chunk-DGXZBQCA.js → chunk-OBCBCLS2.js} +7 -7
  31. package/dist/{chunk-D4FIBB2G.js → chunk-OG2ESRQP.js} +5 -5
  32. package/dist/{chunk-43MXRTKH.js → chunk-OHCUPXU4.js} +26 -8
  33. package/dist/chunk-OIKT4SYO.js +42 -0
  34. package/dist/{chunk-3V37OZQH.js → chunk-PAY6HEEY.js} +2 -2
  35. package/dist/{chunk-QY2P54Z2.js → chunk-PZ6D3WKD.js} +125 -8
  36. package/dist/{chunk-MOKZPZZO.js → chunk-Q5BQIRM3.js} +2 -2
  37. package/dist/{chunk-VYQJPT27.js → chunk-S2FUWBLO.js} +18 -4
  38. package/dist/{chunk-OGCJO6HQ.js → chunk-TQRLWO4F.js} +2 -2
  39. package/dist/{chunk-VBWB2T3C.js → chunk-UVPIVSZB.js} +14 -6
  40. package/dist/{chunk-MHKY6TNF.js → chunk-VN34GLGJ.js} +3 -3
  41. package/dist/chunk-WUFNKK3U.js +71 -0
  42. package/dist/{chunk-2ZH77O2D.js → chunk-Y7FYCVUK.js} +646 -103
  43. package/dist/{chunk-HES44LTA.js → chunk-YJVSN6UN.js} +29 -5
  44. package/dist/{chunk-EWYLWBKS.js → chunk-YKICVMF7.js} +22 -5
  45. package/dist/{cli-OV5LSSGE.js → cli-FVUHK2NB.js} +7 -7
  46. package/dist/{cli-GFDT4YXM.js → cli-ZOY2274X.js} +9 -9
  47. package/dist/cli.js +40 -6
  48. package/dist/{completion-QNDCU4MF.js → completion-ZKWGPMEK.js} +6 -5
  49. package/dist/{diagnostics-TPK3VC5F.js → diagnostics-IM2OPAPL.js} +7 -7
  50. package/dist/{doctor-K2LADSW2.js → doctor-VZTHEPVC.js} +32 -20
  51. package/dist/{entry-HFQHKL5L.js → entry-Q4EI4PNO.js} +13 -13
  52. package/dist/{exec-mcp-I2YGGWY4.js → exec-mcp-AWGUQVT2.js} +15 -12
  53. package/dist/{harness-BMWGAXCF.js → harness-L4C5XWKR.js} +3 -3
  54. package/dist/harness-launch-gate.js +5 -5
  55. package/dist/harness-worker.js +7 -7
  56. package/dist/{heavy-G6CYQQ7O.js → heavy-OG3UVZNY.js} +327 -131
  57. package/dist/hook-body.js +664 -161
  58. package/dist/{hook-spec-Bd24eo2L.d.ts → hook-spec-u7hnz571.d.ts} +10 -0
  59. package/dist/{hooks-R7AYQXHY.js → hooks-2E6PJJQK.js} +4 -4
  60. package/dist/{host-PLE2T55E.js → host-OQDBQJB2.js} +8 -8
  61. package/dist/{host-EUD6GLWV.js → host-RJJGTKWA.js} +20 -65
  62. package/dist/{host-run-QFNGIDL5.js → host-run-PWCIXJDN.js} +6 -6
  63. package/dist/http.js +1 -1
  64. package/dist/{import-mcp-DVKJOEOE.js → import-mcp-2H2NRUCL.js} +14 -11
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.js +18 -15
  67. package/dist/{init-DKWNL62M.js → init-O2UCU2WT.js} +2 -2
  68. package/dist/{invoke-U6JTPTXT.js → invoke-SJ3JHRJU.js} +9 -9
  69. package/dist/{list-YKQFJN3G.js → list-SJVXZGKK.js} +17 -14
  70. package/dist/{logout-5YSKC46N.js → logout-ROKXWR3T.js} +15 -12
  71. package/dist/{logs-2JEMSNSG.js → logs-J4W6GFMK.js} +4 -4
  72. package/dist/{mailbox-5FVFMQ2J.js → mailbox-6MHH6CUA.js} +22 -8
  73. package/dist/{mainline-D3PSR6AJ.js → mainline-SWZPKA7U.js} +19 -9
  74. package/dist/{mcp-CHKKXHBB.js → mcp-U7MVFAB4.js} +2 -2
  75. package/dist/owners-MPI22SFU.js +63 -0
  76. package/dist/{pause-CMZOIHTJ.js → pause-3IMVYXQQ.js} +7 -4
  77. package/dist/project/hook-adapter.d.ts +1 -1
  78. package/dist/{project-QEYXISHC.js → project-MGUYHUF7.js} +4 -4
  79. package/dist/{report-UB7MXAUB.js → report-MWXB5XKE.js} +5 -5
  80. package/dist/{resume-PAKIT4TT.js → resume-7LCSV4X3.js} +7 -4
  81. package/dist/{run-HKMYYEZJ.js → run-DDWLS6FY.js} +14 -11
  82. package/dist/{run-FYKDIW4C.js → run-TBO5JO4Y.js} +4 -4
  83. package/dist/{serve-QZNG5UUV.js → serve-RBQYB3FP.js} +3 -3
  84. package/dist/{setup-GRWLDBVB.js → setup-7JHWLV7K.js} +6 -4
  85. package/dist/{smoke-6X6IXQIQ.js → smoke-GZECLXOJ.js} +3 -3
  86. package/dist/{start-login-4GPM32RA.js → start-login-SOTNDUP6.js} +15 -12
  87. package/dist/{status-55CD352M.js → status-EBIUQIGY.js} +35 -30
  88. package/dist/{status-4PYPTYUB.js → status-QFMN7IUG.js} +8 -5
  89. package/dist/{status-W6SCF2GF.js → status-TSTOFNZU.js} +15 -12
  90. package/dist/stdio.js +2 -2
  91. package/dist/{sweep-VURZU6DI.js → sweep-BS7HVSNP.js} +7 -4
  92. package/dist/{test-XYEMYZ2P.js → test-4PZHHWOQ.js} +28 -16
  93. package/dist/{tui-FXSWN2PV.js → tui-QD2LMXHV.js} +4 -4
  94. package/dist/{unbroadcast-7AMLURCG.js → unbroadcast-GRGX3F6T.js} +7 -4
  95. package/dist/{worker-Q4I4EIAJ.js → worker-SPJ4HFWV.js} +11 -11
  96. package/dist/{worktree-list-2HV6ODBS.js → worktree-list-WZC75NLF.js} +8 -9
  97. package/dist/{worktree-sync-MUVKK2CV.js → worktree-sync-BQZD4J73.js} +5 -2
  98. package/docs/commands.md +18 -7
  99. package/docs/git-workflow.md +40 -5
  100. package/docs/glossary.md +1 -1
  101. package/docs/hooks.md +75 -16
  102. package/docs/project-configuration.md +136 -40
  103. package/docs/sessions.md +9 -2
  104. package/docs/upgrading.md +71 -0
  105. package/gemini-extension.json +2 -2
  106. package/mcp.json +1 -1
  107. package/package.json +5 -5
  108. package/plugin.json +1 -1
  109. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  110. package/plugins/pmcp/.mcp.json +1 -1
  111. package/plugins/pmcp/gemini-extension.json +2 -2
  112. package/plugins/pmcp/mcp.json +1 -1
  113. package/plugins/pmcp/plugin.json +1 -1
  114. package/dist/chunk-65H4PN33.js +0 -7
  115. package/dist/chunk-7TD53M7L.js +0 -13
  116. package/dist/chunk-FQLCD4HU.js +0 -24
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  syncWorktree
3
- } from "./chunk-VYQJPT27.js";
4
- import {
5
- globPattern
6
- } from "./chunk-UKR64U7J.js";
3
+ } from "./chunk-S2FUWBLO.js";
7
4
  import {
8
5
  localCli,
9
6
  pmcpCommand,
@@ -13,6 +10,9 @@ import {
13
10
  ptyFields,
14
11
  ptyRef
15
12
  } from "./chunk-OFJIMBTL.js";
13
+ import {
14
+ readOperatorSettings
15
+ } from "./chunk-NQCAKDRY.js";
16
16
  import {
17
17
  readReportTable
18
18
  } from "./chunk-LFFIQBNY.js";
@@ -28,7 +28,15 @@ import {
28
28
  import {
29
29
  leaseSpecs,
30
30
  readGitConfig
31
- } from "./chunk-EWYLWBKS.js";
31
+ } from "./chunk-YKICVMF7.js";
32
+ import {
33
+ ownerLine,
34
+ ownersOf,
35
+ readOwners
36
+ } from "./chunk-WUFNKK3U.js";
37
+ import {
38
+ globPattern
39
+ } from "./chunk-374AZ4J4.js";
32
40
  import {
33
41
  detect
34
42
  } from "./chunk-SDFJJJB5.js";
@@ -36,7 +44,7 @@ import {
36
44
  inboxKey,
37
45
  noticeOf,
38
46
  readStoreSettings
39
- } from "./chunk-3V37OZQH.js";
47
+ } from "./chunk-PAY6HEEY.js";
40
48
  import {
41
49
  STATE_FILES,
42
50
  runtimePid
@@ -58,7 +66,7 @@ import {
58
66
  RUNTIME_IDS,
59
67
  climbCommand,
60
68
  readTestTable
61
- } from "./chunk-ARXCYFFZ.js";
69
+ } from "./chunk-GQRDEIQA.js";
62
70
  import {
63
71
  TOOLS
64
72
  } from "./chunk-V4NPDK6X.js";
@@ -69,11 +77,11 @@ import {
69
77
  readHost,
70
78
  readLock,
71
79
  readLockFile
72
- } from "./chunk-264DIB5U.js";
80
+ } from "./chunk-3KISMGVP.js";
73
81
  import {
74
82
  DISABLE_ENV,
75
83
  readLeaseSettings
76
- } from "./chunk-QY2P54Z2.js";
84
+ } from "./chunk-PZ6D3WKD.js";
77
85
  import {
78
86
  ProjectError,
79
87
  RULES_DIR,
@@ -1030,15 +1038,15 @@ function marketplaceOutputs(spec) {
1030
1038
  function marketplaceDoctor(spec, run3) {
1031
1039
  const declared = spec.marketplaces ?? [];
1032
1040
  if (forRuntime(declared, "codex").length === 0) return [];
1033
- const check = "declared plugins";
1041
+ const check2 = "declared plugins";
1034
1042
  const result = run3("codex", CODEX_PLUGIN_LIST, spec.root);
1035
- if (result.missing) return [{ tool: "codex", check, status: "skip" }];
1043
+ if (result.missing) return [{ tool: "codex", check: check2, status: "skip" }];
1036
1044
  const states = parseCodexPluginList(result.stdout);
1037
1045
  if (!states)
1038
1046
  return [
1039
1047
  {
1040
1048
  tool: "codex",
1041
- check,
1049
+ check: check2,
1042
1050
  status: "fail",
1043
1051
  detail: "codex plugin list printed no JSON"
1044
1052
  }
@@ -1151,7 +1159,7 @@ function currentRules(settings, bucket) {
1151
1159
  return { rules: raw, present: true };
1152
1160
  }
1153
1161
  function overlaps(settings, declared, owned2) {
1154
- const found = [];
1162
+ const found2 = [];
1155
1163
  for (const [bucket, rules2] of Object.entries(declared)) {
1156
1164
  for (const other of BUCKETS) {
1157
1165
  if (other === bucket) continue;
@@ -1160,12 +1168,12 @@ function overlaps(settings, declared, owned2) {
1160
1168
  (rule) => !mine.includes(rule)
1161
1169
  );
1162
1170
  for (const rule of rules2.filter((item) => native2.includes(item)))
1163
- found.push(
1171
+ found2.push(
1164
1172
  `overlap: ${SETTINGS}#permissions.${other} has unmanaged ${rule}, declared in ${bucket}`
1165
1173
  );
1166
1174
  }
1167
1175
  }
1168
- return found;
1176
+ return found2;
1169
1177
  }
1170
1178
  function reconcile(settings, bucket, owned2, declared) {
1171
1179
  const where = `${SETTINGS}#permissions.${bucket}`;
@@ -1177,12 +1185,12 @@ function reconcile(settings, bucket, owned2, declared) {
1177
1185
  }
1178
1186
  const rules2 = current.rules;
1179
1187
  for (const rule of owned2) {
1180
- const found = count(rules2, rule);
1181
- if (found === 0 && current.present && current.problem === void 0)
1188
+ const found2 = count(rules2, rule);
1189
+ if (found2 === 0 && current.present && current.problem === void 0)
1182
1190
  conflicts.push(
1183
1191
  `conflict: ${where} owned entry edited or removed ${rule}`
1184
1192
  );
1185
- if (found > 1)
1193
+ if (found2 > 1)
1186
1194
  conflicts.push(`conflict: ${where} owned entry is duplicated ${rule}`);
1187
1195
  }
1188
1196
  const dropped = owned2.filter(
@@ -1718,14 +1726,14 @@ function checkBudget(spec, settings) {
1718
1726
  );
1719
1727
  for (const glob of settings.forbidPaths) {
1720
1728
  const pattern = globPattern(glob);
1721
- const found = tracked.filter((file) => pattern.test(file));
1729
+ const found2 = tracked.filter((file) => pattern.test(file));
1722
1730
  rows.push({
1723
1731
  key: "forbid_paths",
1724
1732
  subject: glob,
1725
- value: found.length,
1733
+ value: found2.length,
1726
1734
  limit: 0
1727
1735
  });
1728
- for (const file of found)
1736
+ for (const file of found2)
1729
1737
  problems.push(`[budget] forbid_paths: ${file} matches ${glob}`);
1730
1738
  }
1731
1739
  return { rows, problems };
@@ -1894,8 +1902,8 @@ var PLUGIN_BINARIES = ["pmcp-browser", "pmcp-desktop"];
1894
1902
  var isPlugin = (command) => PLUGIN_BINARIES.includes(command);
1895
1903
  function resolvePluginCommand(command, from) {
1896
1904
  if (!isPlugin(command)) return command;
1897
- const found = packagedBinary(command, from);
1898
- return "path" in found ? found.path : command;
1905
+ const found2 = packagedBinary(command, from);
1906
+ return "path" in found2 ? found2.path : command;
1899
1907
  }
1900
1908
  function pluginBinaryDoctor(servers, from) {
1901
1909
  const findings = [];
@@ -1904,21 +1912,21 @@ function pluginBinaryDoctor(servers, from) {
1904
1912
  if (command === void 0) continue;
1905
1913
  const name = command.split("/").pop();
1906
1914
  if (!isPlugin(name)) continue;
1907
- const check = `[mcp.${alias}] ${name}`;
1908
- const found = packagedBinary(name, from);
1915
+ const check2 = `[mcp.${alias}] ${name}`;
1916
+ const found2 = packagedBinary(name, from);
1909
1917
  if (isPlugin(command))
1910
1918
  findings.push({
1911
1919
  tool: "project",
1912
- check,
1920
+ check: check2,
1913
1921
  status: "warn",
1914
- detail: `not resolved: ${"reason" in found ? found.reason : "unknown"}; runs ${name} from PATH`
1922
+ detail: `not resolved: ${"reason" in found2 ? found2.reason : "unknown"}; runs ${name} from PATH`
1915
1923
  });
1916
1924
  else
1917
1925
  findings.push({
1918
1926
  tool: "project",
1919
- check,
1927
+ check: check2,
1920
1928
  status: "ok",
1921
- detail: "path" in found && found.path === command ? `resolved to ${command} (platform package)` : `explicit command kept: ${command}`
1929
+ detail: "path" in found2 && found2.path === command ? `resolved to ${command} (platform package)` : `explicit command kept: ${command}`
1922
1930
  });
1923
1931
  }
1924
1932
  return findings;
@@ -2310,7 +2318,7 @@ var Scanner = class _Scanner {
2310
2318
  // Index just past the )) closing the (( at open, or -1 when a lone ) closes it first.
2311
2319
  arithmeticEnd(open, nested) {
2312
2320
  const { text } = this;
2313
- const found = [];
2321
+ const found2 = [];
2314
2322
  let depth = 0;
2315
2323
  let index = open + 2;
2316
2324
  while (index < text.length) {
@@ -2321,7 +2329,7 @@ var Scanner = class _Scanner {
2321
2329
  }
2322
2330
  if (text.startsWith("$(", index) && !text.startsWith("$((", index)) {
2323
2331
  const inner = this.nested.at(text, index + 2);
2324
- found.push(inner.list);
2332
+ found2.push(inner.list);
2325
2333
  index = inner.end;
2326
2334
  continue;
2327
2335
  }
@@ -2329,7 +2337,7 @@ var Scanner = class _Scanner {
2329
2337
  if (char === ")") {
2330
2338
  if (depth === 0) {
2331
2339
  if (text[index + 1] !== ")") return -1;
2332
- nested.push(...found);
2340
+ nested.push(...found2);
2333
2341
  return index + 2;
2334
2342
  }
2335
2343
  depth -= 1;
@@ -2565,9 +2573,9 @@ var Parser = class {
2565
2573
  return token;
2566
2574
  }
2567
2575
  fail(token, expected) {
2568
- const found = describe(token);
2576
+ const found2 = describe(token);
2569
2577
  throw new ShellSyntaxError(
2570
- expected ? `expected ${expected}, found ${found}` : `unexpected ${found}`,
2578
+ expected ? `expected ${expected}, found ${found2}` : `unexpected ${found2}`,
2571
2579
  token.start
2572
2580
  );
2573
2581
  }
@@ -2833,7 +2841,7 @@ var Parser = class {
2833
2841
  return redirect;
2834
2842
  }
2835
2843
  simple() {
2836
- const assigns = [];
2844
+ const assigns2 = [];
2837
2845
  const words = [];
2838
2846
  const redirects = [];
2839
2847
  let first = "";
@@ -2842,29 +2850,29 @@ var Parser = class {
2842
2850
  const token = this.peek();
2843
2851
  if (token.kind === "redirect") {
2844
2852
  redirects.push(this.redirect());
2845
- if (assigns.length > 0) redirectedAfterAssign = true;
2853
+ if (assigns2.length > 0) redirectedAfterAssign = true;
2846
2854
  continue;
2847
2855
  }
2848
2856
  if (token.kind !== "word") break;
2849
2857
  this.next();
2850
2858
  if (words.length === 0 && ASSIGNMENT.test(token.raw)) {
2851
2859
  if (redirectedAfterAssign && ARRAY.test(token.raw)) this.fail(token);
2852
- assigns.push(token.word);
2860
+ assigns2.push(token.word);
2853
2861
  continue;
2854
2862
  }
2855
2863
  if (ARRAY.test(token.raw) && !DECLARES.has(first)) this.fail(token);
2856
2864
  if (words.length === 0) first = token.raw;
2857
2865
  words.push(token.word);
2858
2866
  const after = this.peek();
2859
- if (words.length === 1 && assigns.length === 0 && redirects.length === 0 && after.kind === "op" && after.op === "(") {
2867
+ if (words.length === 1 && assigns2.length === 0 && redirects.length === 0 && after.kind === "op" && after.op === "(") {
2860
2868
  this.next();
2861
2869
  this.op(")");
2862
2870
  return { kind: "function", name: token.raw, body: this.functionBody() };
2863
2871
  }
2864
2872
  }
2865
- if (assigns.length + words.length + redirects.length === 0)
2873
+ if (assigns2.length + words.length + redirects.length === 0)
2866
2874
  this.fail(this.peek());
2867
- return { kind: "simple", assigns, words, redirects };
2875
+ return { kind: "simple", assigns: assigns2, words, redirects };
2868
2876
  }
2869
2877
  };
2870
2878
 
@@ -3010,8 +3018,8 @@ function changeDir(place, target) {
3010
3018
  if (isAbsolute4(target) || place.dir === "") return target;
3011
3019
  return join8(place.dir, target);
3012
3020
  }
3013
- function assign(place, assigns, exporting) {
3014
- for (const word of assigns) {
3021
+ function assign(place, assigns2, exporting) {
3022
+ for (const word of assigns2) {
3015
3023
  const name = /^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(word.text)?.[1];
3016
3024
  if (!name) continue;
3017
3025
  if (exporting) place.exported.add(name);
@@ -3212,8 +3220,8 @@ function touchesLock(words, scripts) {
3212
3220
  return runsScript(words, scripts);
3213
3221
  }
3214
3222
  var DEFAULT_MUTATING_COMMANDS = [
3215
- ...[...DOCKER_MUTATING].map((verb) => ["docker", verb]),
3216
- ...[...WRANGLER_MUTATING].map((verb) => ["wrangler", verb])
3223
+ ...[...DOCKER_MUTATING].map((verb2) => ["docker", verb2]),
3224
+ ...[...WRANGLER_MUTATING].map((verb2) => ["wrangler", verb2])
3217
3225
  ];
3218
3226
  var DEFAULT_MUTATING_SCRIPT_NAMES = [
3219
3227
  "^git:",
@@ -3248,8 +3256,8 @@ function mutates(words, rules2 = DEFAULT_MUTATING_RULES) {
3248
3256
 
3249
3257
  // src/hooks/policies/_shared.ts
3250
3258
  var UnreadableCommand = class extends Error {
3251
- constructor(reason2) {
3252
- super(`not shell syntax: ${reason2}`);
3259
+ constructor(reason3) {
3260
+ super(`not shell syntax: ${reason3}`);
3253
3261
  }
3254
3262
  };
3255
3263
  function shellCall(input) {
@@ -4035,8 +4043,8 @@ function fields(input) {
4035
4043
  return { ...cwd, status: "working", waiting: "" };
4036
4044
  if (input.event === "after_tool") return { ...cwd, status: "working" };
4037
4045
  if (input.event === "notification") {
4038
- const reason2 = input.notification?.type || input.notification?.message;
4039
- return { status: "waiting", waiting: reason2 ?? "" };
4046
+ const reason3 = input.notification?.type || input.notification?.message;
4047
+ return { status: "waiting", waiting: reason3 ?? "" };
4040
4048
  }
4041
4049
  if (input.event === "stop") {
4042
4050
  return {
@@ -4178,13 +4186,13 @@ function composeArgs(argv) {
4178
4186
  function teardownReason(argv) {
4179
4187
  const args = composeArgs(argv);
4180
4188
  if (!args) return null;
4181
- const { value: verb, rest } = firstArgument(args, GLOBAL_VALUE_FLAGS);
4182
- if (verb === "down") {
4189
+ const { value: verb2, rest } = firstArgument(args, GLOBAL_VALUE_FLAGS);
4190
+ if (verb2 === "down") {
4183
4191
  return "docker compose down takes no service argument: it tears down every container and network in the project, including ones this task never touched.";
4184
4192
  }
4185
- if (!verb || !SCOPED_VERBS.has(verb)) return null;
4186
- if (firstArgument(rest, VERB_VALUE_FLAGS[verb]).value) return null;
4187
- return `docker compose ${verb} with no service named applies to every service in the project. Name the service you mean.`;
4193
+ if (!verb2 || !SCOPED_VERBS.has(verb2)) return null;
4194
+ if (firstArgument(rest, VERB_VALUE_FLAGS[verb2]).value) return null;
4195
+ return `docker compose ${verb2} with no service named applies to every service in the project. Name the service you mean.`;
4188
4196
  }
4189
4197
  var composeTeardown = {
4190
4198
  id: "shell.compose_teardown",
@@ -4197,8 +4205,8 @@ var composeTeardown = {
4197
4205
  const call = shellCall(input);
4198
4206
  if (!call) return pass;
4199
4207
  for (const step of realSteps(call.steps)) {
4200
- const reason2 = teardownReason(step.argv);
4201
- if (reason2) return { verdict: "deny", reason: reason2 };
4208
+ const reason3 = teardownReason(step.argv);
4209
+ if (reason3) return { verdict: "deny", reason: reason3 };
4202
4210
  }
4203
4211
  return pass;
4204
4212
  }
@@ -4639,12 +4647,12 @@ function runsVerb(argv, commands) {
4639
4647
  if (program(word) !== entry.binary) return false;
4640
4648
  const end = argv.indexOf("--", at + 1);
4641
4649
  const args = argv.slice(at + 1, end < 0 ? void 0 : end);
4642
- return entry.verbs.some((verb) => {
4650
+ return entry.verbs.some((verb2) => {
4643
4651
  let from = 0;
4644
- for (const part of verb) {
4645
- const found = args.indexOf(part, from);
4646
- if (found < 0) return false;
4647
- from = found + 1;
4652
+ for (const part of verb2) {
4653
+ const found2 = args.indexOf(part, from);
4654
+ if (found2 < 0) return false;
4655
+ from = found2 + 1;
4648
4656
  }
4649
4657
  return true;
4650
4658
  });
@@ -4696,7 +4704,7 @@ function severity(steps, options2) {
4696
4704
  return wire ? "exfil" : "read";
4697
4705
  }
4698
4706
  function verbsOf(table3, key) {
4699
- return (stringList(table3, key) ?? []).map((verb) => verb.split(/\s+/u));
4707
+ return (stringList(table3, key) ?? []).map((verb2) => verb2.split(/\s+/u));
4700
4708
  }
4701
4709
  function commandTables(raw) {
4702
4710
  if (raw === void 0) return { value: [], publish: [] };
@@ -4736,14 +4744,14 @@ var secretExfiltration = {
4736
4744
  evaluate(input, ctx) {
4737
4745
  const call = shellCall(input);
4738
4746
  if (!call) return pass;
4739
- const found = severity(call.steps, ctx.options);
4740
- if (found === "exfil") {
4747
+ const found2 = severity(call.steps, ctx.options);
4748
+ if (found2 === "exfil") {
4741
4749
  return {
4742
4750
  verdict: "deny",
4743
4751
  reason: "This sends a credential, or changes a live one, over the network. Credential values must not leave the host; send a reference, never the material."
4744
4752
  };
4745
4753
  }
4746
- if (found === "read") {
4754
+ if (found2 === "read") {
4747
4755
  return {
4748
4756
  verdict: "ask",
4749
4757
  reason: `This prints credential values to stdout, where they enter the transcript and every log that carries it. ${NO_VALUES}`
@@ -4753,6 +4761,103 @@ var secretExfiltration = {
4753
4761
  }
4754
4762
  };
4755
4763
 
4764
+ // src/hooks/policies/shell/self-matching-wait.ts
4765
+ var MENTIONS = /\b(?:pgrep|pkill|pidwait|ps)\b/u;
4766
+ var LOOPS = /* @__PURE__ */ new Set(["while", "until", "for", "select"]);
4767
+ var FULL_MATCHERS = /* @__PURE__ */ new Set(["pgrep", "pkill", "pidwait"]);
4768
+ var GREPS2 = /* @__PURE__ */ new Set(["grep", "egrep", "fgrep", "rg"]);
4769
+ var MAX_DEPTH2 = 4;
4770
+ var reason2 = (probe) => `This loop polls with ${probe}, whose pattern also matches the shell running the loop (its command line holds the pattern), so the wait may never end. Wait on a process id with pmcp wait --pid <pid>, on a process by its text with pmcp wait --until no-process:<text> (it never matches itself), or on a queued job with pmcp heavy wait <ticket>.`;
4771
+ function fullMatch(argv) {
4772
+ return argv.slice(1).some(
4773
+ (arg) => arg === "--full" || /^-[a-zA-Z]+$/u.test(arg) && arg.includes("f")
4774
+ );
4775
+ }
4776
+ function psBySelection(argv) {
4777
+ return argv.slice(1).some(
4778
+ (arg) => /^-[a-zA-Z]*[pqC]/u.test(arg) || /^--(?:pid|quick-pid)(?:=|$)/u.test(arg)
4779
+ );
4780
+ }
4781
+ function argvOf(command) {
4782
+ if (command.kind !== "simple") return null;
4783
+ return unwrap(command.words.map((word) => word.text)).words;
4784
+ }
4785
+ function pipeProbe(commands) {
4786
+ const argvs = commands.map(argvOf);
4787
+ const ps = argvs.findIndex(
4788
+ (argv) => argv && program(argv[0]) === "ps" && !psBySelection(argv)
4789
+ );
4790
+ if (ps < 0) return null;
4791
+ const grep = argvs.slice(ps + 1).some((argv) => argv && GREPS2.has(program(argv[0])));
4792
+ return grep ? "ps | grep" : null;
4793
+ }
4794
+ var Finder = class {
4795
+ probe = null;
4796
+ list(list2, looping, depth) {
4797
+ for (const item of list2)
4798
+ for (const pipeline of item.pipelines) {
4799
+ if (looping) this.probe ??= pipeProbe(pipeline.commands);
4800
+ for (const command of pipeline.commands)
4801
+ this.command(command, looping, depth);
4802
+ }
4803
+ }
4804
+ words(words, looping, depth) {
4805
+ for (const word of words)
4806
+ for (const nested of word.nested) this.list(nested, looping, depth);
4807
+ }
4808
+ command(command, looping, depth) {
4809
+ switch (command.kind) {
4810
+ case "simple":
4811
+ this.words([...command.assigns, ...command.words], looping, depth);
4812
+ this.simple(command, looping, depth);
4813
+ return;
4814
+ case "group":
4815
+ case "subshell":
4816
+ this.list(command.body, looping, depth);
4817
+ return;
4818
+ case "compound": {
4819
+ this.words(command.words, looping, depth);
4820
+ const loop = looping || LOOPS.has(command.keyword);
4821
+ for (const part of command.parts) this.list(part, loop, depth);
4822
+ return;
4823
+ }
4824
+ case "function":
4825
+ this.command(command.body, looping, depth);
4826
+ }
4827
+ }
4828
+ simple(command, looping, depth) {
4829
+ const argv = argvOf(command) ?? [];
4830
+ const name = program(argv[0]);
4831
+ if (looping && FULL_MATCHERS.has(name) && fullMatch(argv))
4832
+ this.probe ??= `${name} -f`;
4833
+ const at = SHELLS.has(name) ? argv.findIndex((word) => /^-[a-z]*c$/u.test(word)) : -1;
4834
+ if ((at > 0 || name === "eval") && depth < MAX_DEPTH2) {
4835
+ const source = name === "eval" ? argv.slice(1).join(" ") : argv[at + 1] ?? "";
4836
+ try {
4837
+ this.list(parseScript(source), looping, depth + 1);
4838
+ } catch (error) {
4839
+ if (!(error instanceof ShellSyntaxError)) throw error;
4840
+ }
4841
+ }
4842
+ }
4843
+ };
4844
+ var selfMatchingWait = {
4845
+ id: "shell.self_matching_wait",
4846
+ events: ["before_tool"],
4847
+ tools: ["shell"],
4848
+ fail: "closed",
4849
+ defaultMode: "observe",
4850
+ options: noOptions,
4851
+ evaluate(input) {
4852
+ if (!MENTIONS.test(input.tool?.command ?? "")) return pass;
4853
+ const call = shellCall(input);
4854
+ if (!call) return pass;
4855
+ const finder = new Finder();
4856
+ finder.list(parseScript(call.command), false, 0);
4857
+ return finder.probe ? { verdict: "deny", reason: reason2(finder.probe) } : pass;
4858
+ }
4859
+ };
4860
+
4756
4861
  // src/hooks/policies/shell/stdin-interpreter.ts
4757
4862
  var PYTHON = /^i?python[23]?(\.\d+)?$/u;
4758
4863
  var REASON6 = "This interpreter reads its program from stdin, so the command text does not contain it and whatever fed the pipe already expanded it. Write the script with the editor tool, then run it.";
@@ -5156,14 +5261,72 @@ var worktreeSync = {
5156
5261
  if (input.event === "prompt" && opts.betweenPrompts === "off") return pass;
5157
5262
  const git = desk(input, opts);
5158
5263
  if (!git) return pass;
5159
- const reason2 = blocked2(input, ctx);
5160
- if (reason2)
5161
- return input.event === "session_start" ? { context: [`Worktree ${git.root} was not moved: ${reason2}.`] } : pass;
5264
+ const reason3 = blocked2(input, ctx);
5265
+ if (reason3)
5266
+ return input.event === "session_start" ? { context: [`Worktree ${git.root} was not moved: ${reason3}.`] } : pass;
5162
5267
  const lines = move2(input, ctx, git);
5163
5268
  return lines.length > 0 ? { context: lines } : pass;
5164
5269
  }
5165
5270
  };
5166
5271
 
5272
+ // src/hooks/policies/workspace/owners.ts
5273
+ import { isAbsolute as isAbsolute8, relative as relative8, resolve as resolve8 } from "path";
5274
+ function projectPaths(input) {
5275
+ const found2 = [];
5276
+ for (const path of input.tool?.paths ?? []) {
5277
+ const rest = relative8(input.projectRoot, resolve8(input.cwd, path));
5278
+ if (rest === "" || rest.startsWith("..") || isAbsolute8(rest)) continue;
5279
+ found2.push(rest.split("\\").join("/"));
5280
+ }
5281
+ return found2;
5282
+ }
5283
+ function noticed(input, ctx) {
5284
+ try {
5285
+ const raw = ctx.store.registry.get(input.session.id)?.["owners"];
5286
+ return Array.isArray(raw) ? raw.filter((x) => typeof x === "string") : [];
5287
+ } catch {
5288
+ return [];
5289
+ }
5290
+ }
5291
+ function remember(input, ctx, owners2) {
5292
+ try {
5293
+ ctx.store.registry.upsert(input.session.id, { owners: [...owners2] });
5294
+ } catch (error) {
5295
+ ctx.log.error("owners notice not recorded", {
5296
+ error: error instanceof Error ? error.message : String(error)
5297
+ });
5298
+ }
5299
+ }
5300
+ var owners = {
5301
+ id: "owners",
5302
+ events: ["after_tool"],
5303
+ tools: ["edit"],
5304
+ fail: "open",
5305
+ defaultMode: "warn",
5306
+ options(raw) {
5307
+ onlyKeys(raw, ["entries"]);
5308
+ return { entries: readOwners(raw["entries"]) };
5309
+ },
5310
+ evaluate(input, ctx) {
5311
+ const seen = noticed(input, ctx);
5312
+ const lines = [];
5313
+ const told = new Set(seen);
5314
+ for (const path of projectPaths(input))
5315
+ for (const entry of ownersOf(ctx.options.entries, path)) {
5316
+ if (entry.mode === "observe") {
5317
+ ctx.log.info("owned path edited", { owner: entry.owner });
5318
+ continue;
5319
+ }
5320
+ if (told.has(entry.owner)) continue;
5321
+ told.add(entry.owner);
5322
+ lines.push(`pmcp owners: ${ownerLine(entry, path)}`);
5323
+ }
5324
+ if (lines.length === 0) return pass;
5325
+ remember(input, ctx, [...told]);
5326
+ return { context: lines };
5327
+ }
5328
+ };
5329
+
5167
5330
  // src/hooks/policies/host/lease.ts
5168
5331
  function argvList2(value) {
5169
5332
  const valid = Array.isArray(value) && value.every(
@@ -5205,11 +5368,80 @@ var hostLease = {
5205
5368
  }
5206
5369
  };
5207
5370
 
5371
+ // src/hooks/policies/pmcp/operator-verbs.ts
5372
+ var GLOBAL = /* @__PURE__ */ new Set(["-q", "--quiet", "--color", "--no-color"]);
5373
+ var VARIABLES = ["PMCP_HEAVY_NOW", "PMCP_OPERATOR_TOKEN"];
5374
+ var OPERATOR_SKIP = "PMCP_HEAVY_DISABLE=operator";
5375
+ function launcher(word) {
5376
+ const name = program(word);
5377
+ return name === "pmcp" || name === "cli.js" || /^@modootoday\/pmcp(@|$)/u.test(word);
5378
+ }
5379
+ var RUNNERS2 = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx", "node", "bun", "pnpm", "yarn"]);
5380
+ function pmcpWords(argv) {
5381
+ const reach = RUNNERS2.has(program(argv[0])) ? 4 : 1;
5382
+ const at = argv.slice(0, reach).findIndex(launcher);
5383
+ if (at < 0) return null;
5384
+ const words = argv.slice(at + 1).filter((word) => !GLOBAL.has(word));
5385
+ const cut = words.indexOf("--");
5386
+ return cut < 0 ? words : words.slice(0, cut);
5387
+ }
5388
+ function verb(words) {
5389
+ const [group, sub] = words;
5390
+ const has = (flag2) => words.includes(flag2);
5391
+ if (group === "sessions" && (sub === "pause" || sub === "resume"))
5392
+ return `pmcp sessions ${sub}`;
5393
+ if (group === "heavy" && sub === "promote" && has("--now"))
5394
+ return "pmcp heavy promote --now";
5395
+ if (group === "heavy" && has("--now")) return "pmcp heavy --now";
5396
+ if (group === "heavy" && sub === "cancel" && has("--force"))
5397
+ return "pmcp heavy cancel --force";
5398
+ if (group === "git" && sub === "deliver" && has("--during-pause"))
5399
+ return "pmcp git deliver --during-pause";
5400
+ return null;
5401
+ }
5402
+ function assigns(step) {
5403
+ const name = step.assigned.find((entry) => VARIABLES.includes(entry));
5404
+ if (name) return name;
5405
+ if (program(step.argv[0]) !== "export") return null;
5406
+ return VARIABLES.find(
5407
+ (variable) => step.argv.some((word) => word.split("=")[0] === variable)
5408
+ ) ?? null;
5409
+ }
5410
+ function found(step) {
5411
+ const variable = assigns(step);
5412
+ if (variable) return `setting ${variable}`;
5413
+ const skips = step.assigned.includes("PMCP_HEAVY_DISABLE") && step.raw.includes(OPERATOR_SKIP) || program(step.argv[0]) === "export" && step.argv.includes(OPERATOR_SKIP);
5414
+ if (skips) return `the lease skip ${OPERATOR_SKIP}`;
5415
+ const words = pmcpWords(step.argv);
5416
+ return words ? verb(words) : null;
5417
+ }
5418
+ var operatorVerbs = {
5419
+ id: "pmcp.operator_verbs",
5420
+ events: ["before_tool"],
5421
+ tools: ["shell"],
5422
+ fail: "closed",
5423
+ defaultMode: "deny",
5424
+ options: noOptions,
5425
+ evaluate(input) {
5426
+ const call = shellCall(input);
5427
+ if (!call) return pass;
5428
+ for (const step of call.steps) {
5429
+ const what = found(step);
5430
+ if (what)
5431
+ return {
5432
+ verdict: "deny",
5433
+ reason: `${what} is the operator's to run, not an agent session's. Ask the operator to run it from their own terminal, and say why.`
5434
+ };
5435
+ }
5436
+ return pass;
5437
+ }
5438
+ };
5439
+
5208
5440
  // src/hooks/policies/custom.ts
5209
5441
  import { spawnSync as spawnSync6 } from "child_process";
5210
5442
  import { createHash as createHash5 } from "crypto";
5211
5443
  import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync3 } from "fs";
5212
- import { isAbsolute as isAbsolute8, relative as relative8, resolve as resolve8 } from "path";
5444
+ import { isAbsolute as isAbsolute9, relative as relative9, resolve as resolve9 } from "path";
5213
5445
  var FAILED = "Guard failed validation or execution";
5214
5446
  var GUARD_PROTOCOL = "pmcp.guard.v1";
5215
5447
  var MAX_FINDINGS = 20;
@@ -5229,8 +5461,8 @@ function customMode(entry) {
5229
5461
  return entry.event === "session_start" && (mode === "deny" || mode === "ask") ? "warn" : mode;
5230
5462
  }
5231
5463
  function inside(base, path) {
5232
- const rest = relative8(base, path);
5233
- return rest !== "" && !rest.startsWith("..") && !isAbsolute8(rest);
5464
+ const rest = relative9(base, path);
5465
+ return rest !== "" && !rest.startsWith("..") && !isAbsolute9(rest);
5234
5466
  }
5235
5467
  function namesScript(command) {
5236
5468
  return [command[0], command[1]].some(
@@ -5244,12 +5476,12 @@ function guardScript(root, command) {
5244
5476
  "Hook command must execute a script under .agents/guards/, or name an installed program with version"
5245
5477
  );
5246
5478
  }
5247
- const base = resolve8(root, ".agents/guards");
5248
- if (!inside(base, resolve8(root, script)))
5479
+ const base = resolve9(root, ".agents/guards");
5480
+ if (!inside(base, resolve9(root, script)))
5249
5481
  throw new Error("Hook guard must stay under .agents/guards/");
5250
- if (!existsSync9(resolve8(root, script)))
5482
+ if (!existsSync9(resolve9(root, script)))
5251
5483
  throw new Error("Hook guard script must exist");
5252
- const real = realpathSync3(resolve8(root, script));
5484
+ const real = realpathSync3(resolve9(root, script));
5253
5485
  if (!inside(realpathSync3(base), real))
5254
5486
  throw new Error("Hook guard cannot resolve outside .agents/guards/");
5255
5487
  return real;
@@ -5284,7 +5516,7 @@ function applies(entry, input) {
5284
5516
  function readFindings(value) {
5285
5517
  if (value === void 0) return [];
5286
5518
  if (!Array.isArray(value)) return null;
5287
- const found = [];
5519
+ const found2 = [];
5288
5520
  for (const item of value) {
5289
5521
  if (!item || typeof item !== "object" || Array.isArray(item)) return null;
5290
5522
  const { path, line, message, ...rest } = item;
@@ -5293,13 +5525,13 @@ function readFindings(value) {
5293
5525
  if (path !== void 0 && typeof path !== "string") return null;
5294
5526
  if (line !== void 0 && (!Number.isSafeInteger(line) || line < 1))
5295
5527
  return null;
5296
- found.push({
5528
+ found2.push({
5297
5529
  message,
5298
5530
  ...path !== void 0 ? { path } : {},
5299
5531
  ...line !== void 0 ? { line } : {}
5300
5532
  });
5301
5533
  }
5302
- return found;
5534
+ return found2;
5303
5535
  }
5304
5536
  function findingLine(finding) {
5305
5537
  const where = finding.path ? `${finding.path}${finding.line ? `:${finding.line}` : ""}: ` : "";
@@ -5329,7 +5561,7 @@ function run2(entry, input, log) {
5329
5561
  };
5330
5562
  }
5331
5563
  const args = entry.command.map(
5332
- (part) => part.startsWith(".agents/guards/") ? resolve8(root, part) : part
5564
+ (part) => part.startsWith(".agents/guards/") ? resolve9(root, part) : part
5333
5565
  );
5334
5566
  const result = spawnSync6(args[0], args.slice(1), {
5335
5567
  cwd: root,
@@ -5346,9 +5578,9 @@ function run2(entry, input, log) {
5346
5578
  const extra = Object.keys(response).some(
5347
5579
  (key) => !["decision", "reason", "findings", "protocol"].includes(key)
5348
5580
  );
5349
- const reason2 = response["reason"];
5581
+ const reason3 = response["reason"];
5350
5582
  const findings = readFindings(response["findings"]);
5351
- if (extra || findings === null || reason2 !== void 0 && typeof reason2 !== "string" || response["protocol"] !== void 0 && response["protocol"] !== GUARD_PROTOCOL)
5583
+ if (extra || findings === null || reason3 !== void 0 && typeof reason3 !== "string" || response["protocol"] !== void 0 && response["protocol"] !== GUARD_PROTOCOL)
5352
5584
  return { verdict: "deny", reason: FAILED };
5353
5585
  const lines = findings.slice(0, MAX_FINDINGS).map(findingLine);
5354
5586
  if (findings.length > MAX_FINDINGS)
@@ -5363,7 +5595,7 @@ function run2(entry, input, log) {
5363
5595
  ${lines.join("\n")}`] } : pass;
5364
5596
  if (response["decision"] !== "deny")
5365
5597
  return { verdict: "deny", reason: FAILED };
5366
- const text = [typeof reason2 === "string" ? reason2 : FAILED, ...lines].join(
5598
+ const text = [typeof reason3 === "string" ? reason3 : FAILED, ...lines].join(
5367
5599
  "\n"
5368
5600
  );
5369
5601
  return { verdict: "deny", reason: text.slice(0, MAX_REASON) };
@@ -5381,6 +5613,172 @@ function customPolicy(entry) {
5381
5613
  };
5382
5614
  }
5383
5615
 
5616
+ // src/hooks/policies/external.ts
5617
+ import { spawnSync as spawnSync7 } from "child_process";
5618
+ import { readFileSync as readFileSync10 } from "fs";
5619
+ import { isAbsolute as isAbsolute10, relative as relative10, resolve as resolve10 } from "path";
5620
+ var MAX_LINES = 20;
5621
+ var MAX_REASON2 = 2e3;
5622
+ var MAX_OUTPUT = 1 << 20;
5623
+ function externalId(entry) {
5624
+ return `external.${entry.name}`;
5625
+ }
5626
+ function inProject(input, path) {
5627
+ const rest = relative10(input.projectRoot, resolve10(input.cwd, path));
5628
+ if (rest === "" || rest.startsWith("..") || isAbsolute10(rest)) return null;
5629
+ return rest.split("\\").join("/");
5630
+ }
5631
+ function matchedPaths(entry, input) {
5632
+ const patterns2 = entry.paths.map((glob) => globPattern(glob));
5633
+ const found2 = /* @__PURE__ */ new Set();
5634
+ for (const path of input.tool?.paths ?? []) {
5635
+ const rest = inProject(input, path);
5636
+ if (rest !== null && patterns2.some((pattern) => pattern.test(rest)))
5637
+ found2.add(rest);
5638
+ }
5639
+ return [...found2].sort();
5640
+ }
5641
+ function previewText(edit, cwd) {
5642
+ if (edit.content !== void 0) return edit.content;
5643
+ if (!edit.replacements) return null;
5644
+ let text;
5645
+ try {
5646
+ text = readFileSync10(resolve10(cwd, edit.path), "utf8");
5647
+ } catch {
5648
+ return null;
5649
+ }
5650
+ for (const change of edit.replacements) {
5651
+ if (change.old === "" || !text.includes(change.old)) return null;
5652
+ text = change.all ? text.split(change.old).join(change.new) : text.replace(change.old, () => change.new);
5653
+ }
5654
+ return text;
5655
+ }
5656
+ function itemLine(item, path) {
5657
+ if (typeof item === "string") return `${path}: ${item}`;
5658
+ const record = item && typeof item === "object" ? item : {};
5659
+ const field = (key) => typeof record[key] === "string" && record[key] !== "" ? record[key] : void 0;
5660
+ const message = field("message") ?? JSON.stringify(item);
5661
+ const where = field("path") ?? path;
5662
+ const line = Number.isSafeInteger(record["line"]) ? `:${record["line"]}` : "";
5663
+ const rule = field("rule");
5664
+ return `${where}${line}: ${rule ? `${rule}: ` : ""}${message}`;
5665
+ }
5666
+ function check(entry, input, path, body, timeoutMs) {
5667
+ const placed = entry.command.some((part) => part.includes("{path}"));
5668
+ const argv = placed ? entry.command.map((part) => part.replaceAll("{path}", path)) : [...entry.command, path];
5669
+ const run3 = spawnSync7(argv[0], argv.slice(1), {
5670
+ cwd: input.projectRoot,
5671
+ env: {
5672
+ PATH: process.env["PATH"],
5673
+ HOME: process.env["HOME"],
5674
+ LANG: "C.UTF-8"
5675
+ },
5676
+ input: body ?? "",
5677
+ encoding: "utf8",
5678
+ timeout: timeoutMs,
5679
+ killSignal: "SIGKILL",
5680
+ maxBuffer: MAX_OUTPUT
5681
+ });
5682
+ if (run3.error) return { error: `${path}: ${run3.error.message}` };
5683
+ if (run3.status === 0) return { items: [] };
5684
+ if (run3.status !== 1)
5685
+ return { error: `${path}: the checker exited ${run3.status ?? run3.signal}` };
5686
+ let items;
5687
+ try {
5688
+ items = JSON.parse(run3.stdout)["items"];
5689
+ } catch {
5690
+ items = void 0;
5691
+ }
5692
+ if (!Array.isArray(items) || items.length === 0)
5693
+ return {
5694
+ error: `${path}: the checker exited 1 without JSON holding an items list`
5695
+ };
5696
+ return { items: items.map((item) => itemLine(item, path)) };
5697
+ }
5698
+ function bodies(entry, input, paths) {
5699
+ const edit = entry.stdin ? input.tool?.edit : void 0;
5700
+ const target = edit ? inProject(input, edit.path) : null;
5701
+ const found2 = /* @__PURE__ */ new Map();
5702
+ for (const path of paths) {
5703
+ const previewed = edit !== void 0 && path === target;
5704
+ if (input.event === "before_tool") {
5705
+ const text = previewed ? previewText(edit, input.cwd) : null;
5706
+ if (text !== null) found2.set(path, text);
5707
+ continue;
5708
+ }
5709
+ if (previewed) continue;
5710
+ if (!entry.stdin) {
5711
+ found2.set(path, void 0);
5712
+ continue;
5713
+ }
5714
+ try {
5715
+ found2.set(path, readFileSync10(resolve10(input.projectRoot, path), "utf8"));
5716
+ } catch {
5717
+ }
5718
+ }
5719
+ return found2;
5720
+ }
5721
+ function firstError(entry, input, ctx) {
5722
+ try {
5723
+ const record = ctx.store.registry.get(input.session.id);
5724
+ const raw = record?.["externalErrors"];
5725
+ const seen = Array.isArray(raw) ? raw : [];
5726
+ if (seen.includes(entry.name)) return false;
5727
+ ctx.store.registry.upsert(input.session.id, {
5728
+ externalErrors: [...seen, entry.name]
5729
+ });
5730
+ } catch {
5731
+ }
5732
+ return true;
5733
+ }
5734
+ function evaluate(entry, input, ctx) {
5735
+ const paths = matchedPaths(entry, input);
5736
+ if (paths.length === 0) return pass;
5737
+ const deadline = Date.now() + entry.timeoutMs;
5738
+ const lines = [];
5739
+ const errors = [];
5740
+ for (const [path, body] of bodies(entry, input, paths)) {
5741
+ const left = deadline - Date.now();
5742
+ const result = left > 0 ? check(entry, input, path, body, left) : { error: `${path}: not checked, ${entry.timeoutMs} ms spent` };
5743
+ if ("error" in result) errors.push(result.error);
5744
+ else lines.push(...result.items);
5745
+ }
5746
+ if (lines.length > 0) {
5747
+ ctx.log.info("external findings", { items: lines.length });
5748
+ const listed = lines.slice(0, MAX_LINES);
5749
+ if (lines.length > MAX_LINES)
5750
+ listed.push(`and ${lines.length - MAX_LINES} more`);
5751
+ const head = `the check ${entry.name} found ${lines.length} problem${lines.length === 1 ? "" : "s"} in the edit; fix ${lines.length === 1 ? "it" : "them"} before going on`;
5752
+ return {
5753
+ verdict: "deny",
5754
+ reason: [head, ...listed].join("\n").slice(0, MAX_REASON2)
5755
+ };
5756
+ }
5757
+ if (errors.length === 0) return pass;
5758
+ ctx.log.warn("external check failed", {
5759
+ guard: entry.name,
5760
+ error: errors[0].slice(0, 300)
5761
+ });
5762
+ const reason3 = [
5763
+ `the check ${entry.name} could not answer, so the edit is not known to pass`,
5764
+ ...errors.slice(0, MAX_LINES)
5765
+ ].join("\n").slice(0, MAX_REASON2);
5766
+ if (entry.mode === "deny")
5767
+ return entry.onError === "deny" ? { verdict: "deny", reason: reason3 } : pass;
5768
+ return firstError(entry, input, ctx) ? { verdict: "deny", reason: reason3 } : pass;
5769
+ }
5770
+ function externalPolicy(entry) {
5771
+ return {
5772
+ id: externalId(entry),
5773
+ events: ["before_tool", "after_tool"],
5774
+ tools: ["edit"],
5775
+ fail: "open",
5776
+ defaultMode: "observe",
5777
+ options: () => ({}),
5778
+ evaluate: (input, ctx) => evaluate(entry, input, ctx)
5779
+ };
5780
+ }
5781
+
5384
5782
  // src/hooks/policies/index.ts
5385
5783
  var byId = (list2) => Object.fromEntries(list2.map((policy) => [policy.id, policy]));
5386
5784
  var GUARDS = byId([
@@ -5391,10 +5789,12 @@ var GUARDS = byId([
5391
5789
  hostApproval,
5392
5790
  secretExfiltration,
5393
5791
  runawayRegex,
5792
+ selfMatchingWait,
5394
5793
  pushWithoutVerify,
5395
5794
  forcedBranchMove,
5396
5795
  gateBypassEnv,
5397
- stageAll
5796
+ stageAll,
5797
+ operatorVerbs
5398
5798
  ]);
5399
5799
  var FEATURES = byId([
5400
5800
  registry,
@@ -5406,7 +5806,8 @@ var FEATURES = byId([
5406
5806
  sharedCheckout,
5407
5807
  worktreeSync,
5408
5808
  mainlineDeliver,
5409
- hostLease
5809
+ hostLease,
5810
+ owners
5410
5811
  ]);
5411
5812
  var POLICIES = {
5412
5813
  ...FEATURES,
@@ -5426,7 +5827,10 @@ function listeners(policy, id) {
5426
5827
  (guard2) => listening(POLICIES[guard2.id], guard2.options)
5427
5828
  );
5428
5829
  const custom = policy.custom.filter((entry) => entry.targets.includes(id)).map((entry) => listening(customPolicy(entry), {}));
5429
- return [...guards, ...custom];
5830
+ const external = (policy.external ?? []).map(
5831
+ (entry) => listening(externalPolicy(entry), {})
5832
+ );
5833
+ return [...guards, ...custom, ...external];
5430
5834
  }
5431
5835
  function bindingsFor(policy, id) {
5432
5836
  const adapter = RUNTIMES[id];
@@ -5444,7 +5848,8 @@ function bindingsFor(policy, id) {
5444
5848
  const tries = policy.failure ? policy.failure.timeoutMs * (policy.failure.retry + 1) : 0;
5445
5849
  const slowest = Math.max(
5446
5850
  tries,
5447
- ...policy.custom.map((entry) => entry.timeoutMs)
5851
+ ...policy.custom.map((entry) => entry.timeoutMs),
5852
+ ...(policy.external ?? []).map((entry) => entry.timeoutMs)
5448
5853
  );
5449
5854
  const timeoutSec = Math.max(
5450
5855
  BASE_TIMEOUT_SEC,
@@ -5615,7 +6020,7 @@ function readCustom(root, hooks, guards) {
5615
6020
  [guards["custom"], void 0]
5616
6021
  ];
5617
6022
  const names4 = /* @__PURE__ */ new Set();
5618
- const found = [];
6023
+ const found2 = [];
5619
6024
  for (const [list2, implied] of sources) {
5620
6025
  if (list2 === void 0) continue;
5621
6026
  if (!Array.isArray(list2))
@@ -5625,10 +6030,10 @@ function readCustom(root, hooks, guards) {
5625
6030
  if (names4.has(entry.name))
5626
6031
  throw new Error("shell names must be unique lowercase names");
5627
6032
  names4.add(entry.name);
5628
- if (entry.mode !== "off") found.push(entry);
6033
+ if (entry.mode !== "off") found2.push(entry);
5629
6034
  }
5630
6035
  }
5631
- return found.sort((a, b) => compareIdentifiers(a.name, b.name));
6036
+ return found2.sort((a, b) => compareIdentifiers(a.name, b.name));
5632
6037
  }
5633
6038
 
5634
6039
  // src/hooks/compile/guards.ts
@@ -5640,7 +6045,7 @@ var MODES2 = [
5640
6045
  "off",
5641
6046
  "graded"
5642
6047
  ];
5643
- var GROUPS = ["shell", "git"];
6048
+ var GROUPS = ["shell", "git", "pmcp"];
5644
6049
  function readGuard(id, raw) {
5645
6050
  const policy = GUARDS[id];
5646
6051
  if (!policy) throw new Error(`unknown guard hooks.guards.${id}`);
@@ -5668,19 +6073,101 @@ function readGuard(id, raw) {
5668
6073
  return { id, mode, options: options2 };
5669
6074
  }
5670
6075
  function readGuards(guards) {
5671
- const found = [];
6076
+ const found2 = [];
5672
6077
  for (const [group, value] of Object.entries(guards)) {
5673
- if (group === "custom") continue;
6078
+ if (group === "custom" || group === "external") continue;
5674
6079
  if (!GROUPS.includes(group))
5675
6080
  throw new Error(`unknown guard group hooks.guards.${group}`);
5676
6081
  for (const [name, raw] of Object.entries(
5677
6082
  asTable(value, `[hooks.guards.${group}]`)
5678
6083
  )) {
5679
6084
  const guard2 = readGuard(`${group}.${name}`, raw);
5680
- if (guard2) found.push(guard2);
6085
+ if (guard2) found2.push(guard2);
5681
6086
  }
5682
6087
  }
5683
- return found.sort((a, b) => compareIdentifiers(a.id, b.id));
6088
+ return found2.sort((a, b) => compareIdentifiers(a.id, b.id));
6089
+ }
6090
+
6091
+ // src/hooks/compile/external.ts
6092
+ var FIELDS2 = [
6093
+ "name",
6094
+ "paths",
6095
+ "command",
6096
+ "timeout_ms",
6097
+ "mode",
6098
+ "stdin",
6099
+ "on_error"
6100
+ ];
6101
+ var MODES3 = ["deny", "warn", "observe", "off"];
6102
+ function stringList2(value, what) {
6103
+ if (!Array.isArray(value) || value.length === 0 || !value.every(
6104
+ (item) => typeof item === "string" && item !== "" && !item.includes("\0")
6105
+ ))
6106
+ throw new Error(`${what} must be a nonempty list of strings`);
6107
+ return value;
6108
+ }
6109
+ function readEntry2(value) {
6110
+ if (value === null || typeof value !== "object" || Array.isArray(value))
6111
+ throw new Error("[[hooks.guards.external]] entries must be tables");
6112
+ const entry = value;
6113
+ const unknown = Object.keys(entry).find((key) => !FIELDS2.includes(key));
6114
+ if (unknown)
6115
+ throw new Error(`[[hooks.guards.external]] unknown field ${unknown}`);
6116
+ const name = entry["name"];
6117
+ if (typeof name !== "string" || !/^[a-z0-9][a-z0-9-]*$/u.test(name))
6118
+ throw new Error(
6119
+ "[[hooks.guards.external]] name must be a lowercase name (a-z, 0-9, -)"
6120
+ );
6121
+ const where = `[[hooks.guards.external]] ${name}:`;
6122
+ const paths = stringList2(entry["paths"], `${where} paths`);
6123
+ if (paths.some((glob) => glob.startsWith("/") || glob.includes("..")))
6124
+ throw new Error(`${where} paths are globs inside the project`);
6125
+ const command = stringList2(entry["command"], `${where} command`);
6126
+ const timeoutMs = entry["timeout_ms"] ?? 15e3;
6127
+ if (typeof timeoutMs !== "number" || !Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 6e4)
6128
+ throw new Error(`${where} timeout_ms must be an integer from 100 to 60000`);
6129
+ const mode = entry["mode"] ?? "observe";
6130
+ if (typeof mode !== "string" || !MODES3.includes(mode))
6131
+ throw new Error(`${where} mode must be one of ${MODES3.join(", ")}`);
6132
+ if (mode === "off") return null;
6133
+ const stdin = entry["stdin"] ?? false;
6134
+ if (typeof stdin !== "boolean")
6135
+ throw new Error(`${where} stdin must be true or false`);
6136
+ const onError = entry["on_error"] ?? "allow";
6137
+ if (onError !== "allow" && onError !== "deny")
6138
+ throw new Error(`${where} on_error must be allow or deny`);
6139
+ return {
6140
+ name,
6141
+ paths,
6142
+ command,
6143
+ timeoutMs,
6144
+ mode,
6145
+ ...stdin ? { stdin: true } : {},
6146
+ ...onError === "deny" ? { onError: "deny" } : {}
6147
+ };
6148
+ }
6149
+ function readExternal(value) {
6150
+ if (value === void 0) return [];
6151
+ if (!Array.isArray(value))
6152
+ throw new Error("[[hooks.guards.external]] must be an array of tables");
6153
+ const names4 = /* @__PURE__ */ new Set();
6154
+ const found2 = [];
6155
+ for (const item of value) {
6156
+ const name = item?.name;
6157
+ if (typeof name === "string" && names4.has(name))
6158
+ throw new Error(`[[hooks.guards.external]] ${name} is declared twice`);
6159
+ if (typeof name === "string") names4.add(name);
6160
+ const entry = readEntry2(item);
6161
+ if (entry) found2.push(entry);
6162
+ }
6163
+ return found2.sort((a, b) => compareIdentifiers(a.name, b.name));
6164
+ }
6165
+
6166
+ // src/hooks/compile/owners.ts
6167
+ function readOwnersGuard(value) {
6168
+ const entries = readOwners(value);
6169
+ if (entries.length === 0) return null;
6170
+ return { id: "owners", mode: "warn", options: { entries } };
5684
6171
  }
5685
6172
 
5686
6173
  // src/hooks/compile/checks.ts
@@ -5697,7 +6184,7 @@ function readChecks(raw) {
5697
6184
  }
5698
6185
 
5699
6186
  // src/hooks/dispatch/failure.ts
5700
- import { isAbsolute as isAbsolute9, relative as relative9, resolve as resolve9 } from "path";
6187
+ import { isAbsolute as isAbsolute11, relative as relative11, resolve as resolve11 } from "path";
5701
6188
  var PASS_KINDS = ["read", "edit-own-worktree"];
5702
6189
  function readFailure(value) {
5703
6190
  if (value === void 0) return void 0;
@@ -5731,8 +6218,8 @@ function ownWorktree(input) {
5731
6218
  if (!checkout || checkout.main) return false;
5732
6219
  const paths = input.tool?.paths ?? [];
5733
6220
  return paths.length > 0 && paths.every((path) => {
5734
- const rest = relative9(checkout.root, resolve9(input.cwd, path));
5735
- return rest !== "" && !rest.startsWith("..") && !isAbsolute9(rest);
6221
+ const rest = relative11(checkout.root, resolve11(input.cwd, path));
6222
+ return rest !== "" && !rest.startsWith("..") && !isAbsolute11(rest);
5736
6223
  });
5737
6224
  }
5738
6225
  function passes(input, pass2) {
@@ -5842,9 +6329,10 @@ var KEYS5 = [
5842
6329
  "broadcast",
5843
6330
  "leases",
5844
6331
  "roles",
5845
- "mailbox"
6332
+ "mailbox",
6333
+ "operator"
5846
6334
  ];
5847
- var MODES3 = ["deny", "ask", "warn", "off"];
6335
+ var MODES4 = ["deny", "ask", "warn", "off"];
5848
6336
  function guard(id, options2, mode) {
5849
6337
  try {
5850
6338
  FEATURES[id].options(options2);
@@ -5857,8 +6345,8 @@ function guard(id, options2, mode) {
5857
6345
  }
5858
6346
  function pauseGuard(raw) {
5859
6347
  const { mode = "deny", ...options2 } = asTable(raw, "[sessions.pause]");
5860
- if (!MODES3.includes(mode))
5861
- throw new Error(`[sessions.pause] mode must be one of ${MODES3.join(", ")}`);
6348
+ if (!MODES4.includes(mode))
6349
+ throw new Error(`[sessions.pause] mode must be one of ${MODES4.join(", ")}`);
5862
6350
  return guard("sessions.pause", options2, mode);
5863
6351
  }
5864
6352
  function registryCheck(raw) {
@@ -6034,18 +6522,28 @@ function hostGuard(host, guards) {
6034
6522
  if (shell["host_approval"] !== void 0) return null;
6035
6523
  return { id: "shell.host_approval", mode: "deny", options: {} };
6036
6524
  }
6525
+ function operatorGuard(declared, guards) {
6526
+ if (!declared) return null;
6527
+ const pmcp = asTable(guards["pmcp"], "[hooks.guards.pmcp]");
6528
+ if (pmcp["operator_verbs"] !== void 0) return null;
6529
+ return { id: "pmcp.operator_verbs", mode: "deny", options: {} };
6530
+ }
6037
6531
  function compileHooks(tables, options2) {
6038
6532
  const hooks = asTable(tables.hooks, "[hooks]");
6039
6533
  const table3 = readHooksTable(hooks, options2.tools);
6040
6534
  const guardsTable = asTable(hooks["guards"], "[hooks.guards]");
6041
6535
  const entries = readCustom(options2.root, hooks, guardsTable);
6536
+ const external = readExternal(guardsTable["external"]);
6042
6537
  const sessions = readSessions(tables.sessions, tables.git);
6538
+ readOperatorSettings(tables.sessions, options2.root);
6539
+ const operator = operatorGuard(sessions.declared, guardsTable);
6043
6540
  const workspace = readWorkspace(tables.git, options2.root);
6044
6541
  const deskSync = readWorktreeSync(tables, options2.root);
6045
6542
  const directPush = readMainlineDeliver(tables, options2.root);
6046
6543
  const host = hostGuard(tables.host, guardsTable);
6047
6544
  const heavy = readHostLease(tables.host, options2.root);
6048
- const enabled = table3.enabled || host !== null || heavy !== null || sessions.declared || workspace.declared || !!deskSync || !!directPush;
6545
+ const owned2 = readOwnersGuard(tables.owners);
6546
+ const enabled = table3.enabled || host !== null || heavy !== null || owned2 !== null || sessions.declared || workspace.declared || !!deskSync || !!directPush;
6049
6547
  const legacy = legacyEntries(entries, enabled, table3.targets);
6050
6548
  if (!enabled)
6051
6549
  return {
@@ -6063,6 +6561,8 @@ function compileHooks(tables, options2) {
6063
6561
  ...directPush ? [directPush] : [],
6064
6562
  ...host ? [host] : [],
6065
6563
  ...heavy ? [heavy] : [],
6564
+ ...operator ? [operator] : [],
6565
+ ...owned2 ? [owned2] : [],
6066
6566
  ...readGuards(guardsTable),
6067
6567
  ...readChecks(hooks["checks"])
6068
6568
  ];
@@ -6087,6 +6587,7 @@ function compileHooks(tables, options2) {
6087
6587
  },
6088
6588
  guards,
6089
6589
  custom: pinnedEntries(options2.root, entries, table3.targets),
6590
+ ...external.length > 0 ? { external } : {},
6090
6591
  lowering: loweringFor(table3.targets, table3.askFallback, asks)
6091
6592
  };
6092
6593
  const projecting = table3.targets.filter((id) => {
@@ -6120,7 +6621,8 @@ function readHooks(path, root, raw, tools) {
6120
6621
  sessions: raw["sessions"],
6121
6622
  git: raw["git"],
6122
6623
  logging: raw["logging"],
6123
- host: raw["host"]
6624
+ host: raw["host"],
6625
+ owners: raw["owners"]
6124
6626
  },
6125
6627
  { root, tools }
6126
6628
  );
@@ -6158,6 +6660,44 @@ function deprecations(hooks) {
6158
6660
  );
6159
6661
  }
6160
6662
 
6663
+ // src/project/budgets.ts
6664
+ var FIELDS3 = ["bytes", "lines"];
6665
+ function readEntry3(glob, value) {
6666
+ const where = `[budgets] "${glob}"`;
6667
+ if (!value || typeof value !== "object" || Array.isArray(value))
6668
+ throw new Error(`${where} must be a table such as { bytes = 4096 }`);
6669
+ const entry = value;
6670
+ const unknown = Object.keys(entry).find((key) => !FIELDS3.includes(key));
6671
+ if (unknown) throw new Error(`${where}: unknown key ${unknown}`);
6672
+ const limit = (key) => {
6673
+ const raw = entry[key];
6674
+ if (raw === void 0) return void 0;
6675
+ if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < 1)
6676
+ throw new Error(`${where}: ${key} must be a whole number from 1`);
6677
+ return raw;
6678
+ };
6679
+ const bytes = limit("bytes");
6680
+ const lines = limit("lines");
6681
+ if (bytes === void 0 && lines === void 0)
6682
+ throw new Error(`${where}: set bytes, lines or both`);
6683
+ return {
6684
+ ...bytes !== void 0 ? { bytes } : {},
6685
+ ...lines !== void 0 ? { lines } : {}
6686
+ };
6687
+ }
6688
+ function readBudgets(value) {
6689
+ if (value === void 0) return {};
6690
+ if (!value || typeof value !== "object" || Array.isArray(value))
6691
+ throw new Error("[budgets] must be a table of glob = { bytes, lines }");
6692
+ const out = {};
6693
+ for (const [glob, entry] of Object.entries(value)) {
6694
+ if (glob === "" || glob.startsWith("/") || glob.split("/").includes(".."))
6695
+ throw new Error(`[budgets] "${glob}" must be a glob inside the project`);
6696
+ out[glob] = readEntry3(glob, entry);
6697
+ }
6698
+ return out;
6699
+ }
6700
+
6161
6701
  // src/project/spec.ts
6162
6702
  var NAME = /^[a-z0-9][a-z0-9-]*$/u;
6163
6703
  function table2(path, where, value) {
@@ -6296,6 +6836,7 @@ function readSpec(config) {
6296
6836
  let budget;
6297
6837
  try {
6298
6838
  budget = readBudget(raw["budget"]);
6839
+ readBudgets(raw["budgets"]);
6299
6840
  } catch (error) {
6300
6841
  throw new ConfigError(path, error.message);
6301
6842
  }
@@ -6329,6 +6870,8 @@ export {
6329
6870
  programVersion,
6330
6871
  versionMatches,
6331
6872
  customPolicy,
6873
+ externalId,
6874
+ externalPolicy,
6332
6875
  GUARDS,
6333
6876
  FEATURES,
6334
6877
  POLICIES,
@@ -6367,4 +6910,4 @@ export {
6367
6910
  checkBudget,
6368
6911
  readSpec
6369
6912
  };
6370
- //# sourceMappingURL=chunk-2ZH77O2D.js.map
6913
+ //# sourceMappingURL=chunk-Y7FYCVUK.js.map