@modootoday/pmcp 0.25.0 → 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 (110) 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-6XLLYLJT.js → apply-HJUCYQDQ.js} +17 -15
  7. package/dist/{broadcast-34CEG2NQ.js → broadcast-U7ZYOJWE.js} +4 -4
  8. package/dist/{chunk-BG6TONJO.js → chunk-2GL5L2G5.js} +2 -2
  9. package/dist/{chunk-PGZZI42O.js → chunk-2JUHFM4V.js} +2 -2
  10. package/dist/{chunk-UKR64U7J.js → chunk-374AZ4J4.js} +2 -2
  11. package/dist/{chunk-ISWR2XIU.js → chunk-3JOFDNL4.js} +2 -2
  12. package/dist/{chunk-2TXVOHRS.js → chunk-3KISMGVP.js} +4 -4
  13. package/dist/{chunk-SRSKCFFS.js → chunk-6XE3WW7S.js} +3 -3
  14. package/dist/{chunk-5MUD7FHP.js → chunk-7FHOSWNQ.js} +2 -2
  15. package/dist/{chunk-QYHM6554.js → chunk-7PBWLYCO.js} +3 -3
  16. package/dist/{chunk-PECS47OL.js → chunk-C7Y2MBCN.js} +3 -3
  17. package/dist/chunk-D7IDT7OA.js +21 -0
  18. package/dist/chunk-E272CFPS.js +14 -0
  19. package/dist/chunk-FLG7VRTC.js +1 -0
  20. package/dist/{chunk-3P6Y2BAO.js → chunk-FXDGW2IH.js} +3 -3
  21. package/dist/{chunk-RF6RDJYH.js → chunk-GIL3RBRX.js} +26 -19
  22. package/dist/{chunk-ARXCYFFZ.js → chunk-GQRDEIQA.js} +22 -2
  23. package/dist/chunk-J43Z4O3G.js +7 -0
  24. package/dist/chunk-KLIYFD3W.js +32 -0
  25. package/dist/{chunk-UQHJUTDW.js → chunk-KQV2EPAP.js} +2 -2
  26. package/dist/{chunk-DWHM5BAY.js → chunk-LCPCRZ7N.js} +2 -2
  27. package/dist/{chunk-MBHI2TKQ.js → chunk-NQZMGQFG.js} +5 -5
  28. package/dist/{chunk-SSQ6EWNA.js → chunk-OBCBCLS2.js} +7 -7
  29. package/dist/{chunk-LZVHFPN6.js → chunk-OG2ESRQP.js} +5 -5
  30. package/dist/{chunk-NAHAESFV.js → chunk-OHCUPXU4.js} +18 -5
  31. package/dist/{chunk-3V37OZQH.js → chunk-PAY6HEEY.js} +2 -2
  32. package/dist/{chunk-DITIXBFB.js → chunk-PZ6D3WKD.js} +65 -1
  33. package/dist/{chunk-TJW4DP26.js → chunk-Q5BQIRM3.js} +2 -2
  34. package/dist/{chunk-VYQJPT27.js → chunk-S2FUWBLO.js} +18 -4
  35. package/dist/{chunk-OGCJO6HQ.js → chunk-TQRLWO4F.js} +2 -2
  36. package/dist/{chunk-EC5QLEZD.js → chunk-UVPIVSZB.js} +14 -6
  37. package/dist/{chunk-MHKY6TNF.js → chunk-VN34GLGJ.js} +3 -3
  38. package/dist/chunk-WUFNKK3U.js +71 -0
  39. package/dist/{chunk-TOR6SKRB.js → chunk-Y7FYCVUK.js} +508 -48
  40. package/dist/{chunk-C3KRMTIZ.js → chunk-YJVSN6UN.js} +2 -2
  41. package/dist/{chunk-EWYLWBKS.js → chunk-YKICVMF7.js} +22 -5
  42. package/dist/{cli-QDQYUHAP.js → cli-FVUHK2NB.js} +6 -6
  43. package/dist/{cli-5G2OYTIL.js → cli-ZOY2274X.js} +8 -8
  44. package/dist/cli.js +6 -5
  45. package/dist/{completion-3GVNPLZY.js → completion-ZKWGPMEK.js} +5 -4
  46. package/dist/{diagnostics-2W7QDQNG.js → diagnostics-IM2OPAPL.js} +7 -7
  47. package/dist/{doctor-3TDO5LJ5.js → doctor-VZTHEPVC.js} +31 -20
  48. package/dist/{entry-E62DZQJF.js → entry-Q4EI4PNO.js} +13 -13
  49. package/dist/{exec-mcp-4N7FLY52.js → exec-mcp-AWGUQVT2.js} +14 -12
  50. package/dist/{harness-E2AUZDLV.js → harness-L4C5XWKR.js} +3 -3
  51. package/dist/harness-launch-gate.js +5 -5
  52. package/dist/harness-worker.js +7 -7
  53. package/dist/{heavy-HZQVFI6P.js → heavy-OG3UVZNY.js} +181 -99
  54. package/dist/hook-body.js +548 -116
  55. package/dist/{hook-spec-Bd24eo2L.d.ts → hook-spec-u7hnz571.d.ts} +10 -0
  56. package/dist/{hooks-VAEAK2FY.js → hooks-2E6PJJQK.js} +4 -4
  57. package/dist/{host-4GJDGTLW.js → host-OQDBQJB2.js} +8 -8
  58. package/dist/{host-I2EMQ7UE.js → host-RJJGTKWA.js} +16 -14
  59. package/dist/{host-run-DDMKD3BU.js → host-run-PWCIXJDN.js} +6 -6
  60. package/dist/http.js +1 -1
  61. package/dist/{import-mcp-TNSAMJXI.js → import-mcp-2H2NRUCL.js} +13 -11
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.js +17 -15
  64. package/dist/{init-UA7MDNTZ.js → init-O2UCU2WT.js} +2 -2
  65. package/dist/{invoke-HW7NBPGP.js → invoke-SJ3JHRJU.js} +9 -9
  66. package/dist/{list-A7VQJXE5.js → list-SJVXZGKK.js} +16 -14
  67. package/dist/{logout-HNPLUKJY.js → logout-ROKXWR3T.js} +14 -12
  68. package/dist/{logs-2JEMSNSG.js → logs-J4W6GFMK.js} +4 -4
  69. package/dist/{mailbox-MR6TPD3P.js → mailbox-6MHH6CUA.js} +4 -4
  70. package/dist/{mainline-MSLW3UFD.js → mainline-SWZPKA7U.js} +13 -9
  71. package/dist/{mcp-6C23GX2E.js → mcp-U7MVFAB4.js} +2 -2
  72. package/dist/owners-MPI22SFU.js +63 -0
  73. package/dist/{pause-H6ZYZF7C.js → pause-3IMVYXQQ.js} +4 -4
  74. package/dist/project/hook-adapter.d.ts +1 -1
  75. package/dist/{project-BX6NCGKB.js → project-MGUYHUF7.js} +4 -4
  76. package/dist/{report-43SFNNCF.js → report-MWXB5XKE.js} +4 -4
  77. package/dist/{resume-2BWGSTCN.js → resume-7LCSV4X3.js} +4 -4
  78. package/dist/{run-2UVAWBAF.js → run-DDWLS6FY.js} +13 -11
  79. package/dist/{run-7TRWZFEZ.js → run-TBO5JO4Y.js} +4 -4
  80. package/dist/{serve-4XZ5SKJJ.js → serve-RBQYB3FP.js} +3 -3
  81. package/dist/{setup-GRWLDBVB.js → setup-7JHWLV7K.js} +6 -4
  82. package/dist/{smoke-6X6IXQIQ.js → smoke-GZECLXOJ.js} +3 -3
  83. package/dist/{start-login-AR7ITWNV.js → start-login-SOTNDUP6.js} +14 -12
  84. package/dist/{status-VQCMJFVE.js → status-EBIUQIGY.js} +18 -16
  85. package/dist/{status-2GDYLIR3.js → status-QFMN7IUG.js} +4 -4
  86. package/dist/{status-ZY6LDQSF.js → status-TSTOFNZU.js} +14 -12
  87. package/dist/stdio.js +2 -2
  88. package/dist/{sweep-76BUOGEI.js → sweep-BS7HVSNP.js} +4 -4
  89. package/dist/{test-VWGNFSH5.js → test-4PZHHWOQ.js} +25 -15
  90. package/dist/{tui-TUMOQBE7.js → tui-QD2LMXHV.js} +4 -4
  91. package/dist/{unbroadcast-HJHYUHZL.js → unbroadcast-GRGX3F6T.js} +4 -4
  92. package/dist/{worker-NEEPJRVV.js → worker-SPJ4HFWV.js} +11 -11
  93. package/dist/{worktree-sync-MUVKK2CV.js → worktree-sync-BQZD4J73.js} +5 -2
  94. package/docs/commands.md +12 -3
  95. package/docs/git-workflow.md +40 -5
  96. package/docs/hooks.md +69 -14
  97. package/docs/project-configuration.md +63 -4
  98. package/docs/upgrading.md +13 -0
  99. package/gemini-extension.json +2 -2
  100. package/mcp.json +1 -1
  101. package/package.json +5 -5
  102. package/plugin.json +1 -1
  103. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  104. package/plugins/pmcp/.mcp.json +1 -1
  105. package/plugins/pmcp/gemini-extension.json +2 -2
  106. package/plugins/pmcp/mcp.json +1 -1
  107. package/plugins/pmcp/plugin.json +1 -1
  108. package/dist/chunk-7TD53M7L.js +0 -13
  109. package/dist/chunk-FQLCD4HU.js +0 -24
  110. package/dist/chunk-SMBU3QLE.js +0 -7
@@ -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,
@@ -31,7 +28,15 @@ import {
31
28
  import {
32
29
  leaseSpecs,
33
30
  readGitConfig
34
- } 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";
35
40
  import {
36
41
  detect
37
42
  } from "./chunk-SDFJJJB5.js";
@@ -39,7 +44,7 @@ import {
39
44
  inboxKey,
40
45
  noticeOf,
41
46
  readStoreSettings
42
- } from "./chunk-3V37OZQH.js";
47
+ } from "./chunk-PAY6HEEY.js";
43
48
  import {
44
49
  STATE_FILES,
45
50
  runtimePid
@@ -61,7 +66,7 @@ import {
61
66
  RUNTIME_IDS,
62
67
  climbCommand,
63
68
  readTestTable
64
- } from "./chunk-ARXCYFFZ.js";
69
+ } from "./chunk-GQRDEIQA.js";
65
70
  import {
66
71
  TOOLS
67
72
  } from "./chunk-V4NPDK6X.js";
@@ -72,11 +77,11 @@ import {
72
77
  readHost,
73
78
  readLock,
74
79
  readLockFile
75
- } from "./chunk-2TXVOHRS.js";
80
+ } from "./chunk-3KISMGVP.js";
76
81
  import {
77
82
  DISABLE_ENV,
78
83
  readLeaseSettings
79
- } from "./chunk-DITIXBFB.js";
84
+ } from "./chunk-PZ6D3WKD.js";
80
85
  import {
81
86
  ProjectError,
82
87
  RULES_DIR,
@@ -1033,15 +1038,15 @@ function marketplaceOutputs(spec) {
1033
1038
  function marketplaceDoctor(spec, run3) {
1034
1039
  const declared = spec.marketplaces ?? [];
1035
1040
  if (forRuntime(declared, "codex").length === 0) return [];
1036
- const check = "declared plugins";
1041
+ const check2 = "declared plugins";
1037
1042
  const result = run3("codex", CODEX_PLUGIN_LIST, spec.root);
1038
- if (result.missing) return [{ tool: "codex", check, status: "skip" }];
1043
+ if (result.missing) return [{ tool: "codex", check: check2, status: "skip" }];
1039
1044
  const states = parseCodexPluginList(result.stdout);
1040
1045
  if (!states)
1041
1046
  return [
1042
1047
  {
1043
1048
  tool: "codex",
1044
- check,
1049
+ check: check2,
1045
1050
  status: "fail",
1046
1051
  detail: "codex plugin list printed no JSON"
1047
1052
  }
@@ -1907,19 +1912,19 @@ function pluginBinaryDoctor(servers, from) {
1907
1912
  if (command === void 0) continue;
1908
1913
  const name = command.split("/").pop();
1909
1914
  if (!isPlugin(name)) continue;
1910
- const check = `[mcp.${alias}] ${name}`;
1915
+ const check2 = `[mcp.${alias}] ${name}`;
1911
1916
  const found2 = packagedBinary(name, from);
1912
1917
  if (isPlugin(command))
1913
1918
  findings.push({
1914
1919
  tool: "project",
1915
- check,
1920
+ check: check2,
1916
1921
  status: "warn",
1917
1922
  detail: `not resolved: ${"reason" in found2 ? found2.reason : "unknown"}; runs ${name} from PATH`
1918
1923
  });
1919
1924
  else
1920
1925
  findings.push({
1921
1926
  tool: "project",
1922
- check,
1927
+ check: check2,
1923
1928
  status: "ok",
1924
1929
  detail: "path" in found2 && found2.path === command ? `resolved to ${command} (platform package)` : `explicit command kept: ${command}`
1925
1930
  });
@@ -3251,8 +3256,8 @@ function mutates(words, rules2 = DEFAULT_MUTATING_RULES) {
3251
3256
 
3252
3257
  // src/hooks/policies/_shared.ts
3253
3258
  var UnreadableCommand = class extends Error {
3254
- constructor(reason2) {
3255
- super(`not shell syntax: ${reason2}`);
3259
+ constructor(reason3) {
3260
+ super(`not shell syntax: ${reason3}`);
3256
3261
  }
3257
3262
  };
3258
3263
  function shellCall(input) {
@@ -4038,8 +4043,8 @@ function fields(input) {
4038
4043
  return { ...cwd, status: "working", waiting: "" };
4039
4044
  if (input.event === "after_tool") return { ...cwd, status: "working" };
4040
4045
  if (input.event === "notification") {
4041
- const reason2 = input.notification?.type || input.notification?.message;
4042
- return { status: "waiting", waiting: reason2 ?? "" };
4046
+ const reason3 = input.notification?.type || input.notification?.message;
4047
+ return { status: "waiting", waiting: reason3 ?? "" };
4043
4048
  }
4044
4049
  if (input.event === "stop") {
4045
4050
  return {
@@ -4200,8 +4205,8 @@ var composeTeardown = {
4200
4205
  const call = shellCall(input);
4201
4206
  if (!call) return pass;
4202
4207
  for (const step of realSteps(call.steps)) {
4203
- const reason2 = teardownReason(step.argv);
4204
- if (reason2) return { verdict: "deny", reason: reason2 };
4208
+ const reason3 = teardownReason(step.argv);
4209
+ if (reason3) return { verdict: "deny", reason: reason3 };
4205
4210
  }
4206
4211
  return pass;
4207
4212
  }
@@ -4756,6 +4761,103 @@ var secretExfiltration = {
4756
4761
  }
4757
4762
  };
4758
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
+
4759
4861
  // src/hooks/policies/shell/stdin-interpreter.ts
4760
4862
  var PYTHON = /^i?python[23]?(\.\d+)?$/u;
4761
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.";
@@ -5159,14 +5261,72 @@ var worktreeSync = {
5159
5261
  if (input.event === "prompt" && opts.betweenPrompts === "off") return pass;
5160
5262
  const git = desk(input, opts);
5161
5263
  if (!git) return pass;
5162
- const reason2 = blocked2(input, ctx);
5163
- if (reason2)
5164
- 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;
5165
5267
  const lines = move2(input, ctx, git);
5166
5268
  return lines.length > 0 ? { context: lines } : pass;
5167
5269
  }
5168
5270
  };
5169
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
+
5170
5330
  // src/hooks/policies/host/lease.ts
5171
5331
  function argvList2(value) {
5172
5332
  const valid = Array.isArray(value) && value.every(
@@ -5281,7 +5441,7 @@ var operatorVerbs = {
5281
5441
  import { spawnSync as spawnSync6 } from "child_process";
5282
5442
  import { createHash as createHash5 } from "crypto";
5283
5443
  import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync3 } from "fs";
5284
- 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";
5285
5445
  var FAILED = "Guard failed validation or execution";
5286
5446
  var GUARD_PROTOCOL = "pmcp.guard.v1";
5287
5447
  var MAX_FINDINGS = 20;
@@ -5301,8 +5461,8 @@ function customMode(entry) {
5301
5461
  return entry.event === "session_start" && (mode === "deny" || mode === "ask") ? "warn" : mode;
5302
5462
  }
5303
5463
  function inside(base, path) {
5304
- const rest = relative8(base, path);
5305
- return rest !== "" && !rest.startsWith("..") && !isAbsolute8(rest);
5464
+ const rest = relative9(base, path);
5465
+ return rest !== "" && !rest.startsWith("..") && !isAbsolute9(rest);
5306
5466
  }
5307
5467
  function namesScript(command) {
5308
5468
  return [command[0], command[1]].some(
@@ -5316,12 +5476,12 @@ function guardScript(root, command) {
5316
5476
  "Hook command must execute a script under .agents/guards/, or name an installed program with version"
5317
5477
  );
5318
5478
  }
5319
- const base = resolve8(root, ".agents/guards");
5320
- if (!inside(base, resolve8(root, script)))
5479
+ const base = resolve9(root, ".agents/guards");
5480
+ if (!inside(base, resolve9(root, script)))
5321
5481
  throw new Error("Hook guard must stay under .agents/guards/");
5322
- if (!existsSync9(resolve8(root, script)))
5482
+ if (!existsSync9(resolve9(root, script)))
5323
5483
  throw new Error("Hook guard script must exist");
5324
- const real = realpathSync3(resolve8(root, script));
5484
+ const real = realpathSync3(resolve9(root, script));
5325
5485
  if (!inside(realpathSync3(base), real))
5326
5486
  throw new Error("Hook guard cannot resolve outside .agents/guards/");
5327
5487
  return real;
@@ -5401,7 +5561,7 @@ function run2(entry, input, log) {
5401
5561
  };
5402
5562
  }
5403
5563
  const args = entry.command.map(
5404
- (part) => part.startsWith(".agents/guards/") ? resolve8(root, part) : part
5564
+ (part) => part.startsWith(".agents/guards/") ? resolve9(root, part) : part
5405
5565
  );
5406
5566
  const result = spawnSync6(args[0], args.slice(1), {
5407
5567
  cwd: root,
@@ -5418,9 +5578,9 @@ function run2(entry, input, log) {
5418
5578
  const extra = Object.keys(response).some(
5419
5579
  (key) => !["decision", "reason", "findings", "protocol"].includes(key)
5420
5580
  );
5421
- const reason2 = response["reason"];
5581
+ const reason3 = response["reason"];
5422
5582
  const findings = readFindings(response["findings"]);
5423
- 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)
5424
5584
  return { verdict: "deny", reason: FAILED };
5425
5585
  const lines = findings.slice(0, MAX_FINDINGS).map(findingLine);
5426
5586
  if (findings.length > MAX_FINDINGS)
@@ -5435,7 +5595,7 @@ function run2(entry, input, log) {
5435
5595
  ${lines.join("\n")}`] } : pass;
5436
5596
  if (response["decision"] !== "deny")
5437
5597
  return { verdict: "deny", reason: FAILED };
5438
- const text = [typeof reason2 === "string" ? reason2 : FAILED, ...lines].join(
5598
+ const text = [typeof reason3 === "string" ? reason3 : FAILED, ...lines].join(
5439
5599
  "\n"
5440
5600
  );
5441
5601
  return { verdict: "deny", reason: text.slice(0, MAX_REASON) };
@@ -5453,6 +5613,172 @@ function customPolicy(entry) {
5453
5613
  };
5454
5614
  }
5455
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
+
5456
5782
  // src/hooks/policies/index.ts
5457
5783
  var byId = (list2) => Object.fromEntries(list2.map((policy) => [policy.id, policy]));
5458
5784
  var GUARDS = byId([
@@ -5463,6 +5789,7 @@ var GUARDS = byId([
5463
5789
  hostApproval,
5464
5790
  secretExfiltration,
5465
5791
  runawayRegex,
5792
+ selfMatchingWait,
5466
5793
  pushWithoutVerify,
5467
5794
  forcedBranchMove,
5468
5795
  gateBypassEnv,
@@ -5479,7 +5806,8 @@ var FEATURES = byId([
5479
5806
  sharedCheckout,
5480
5807
  worktreeSync,
5481
5808
  mainlineDeliver,
5482
- hostLease
5809
+ hostLease,
5810
+ owners
5483
5811
  ]);
5484
5812
  var POLICIES = {
5485
5813
  ...FEATURES,
@@ -5499,7 +5827,10 @@ function listeners(policy, id) {
5499
5827
  (guard2) => listening(POLICIES[guard2.id], guard2.options)
5500
5828
  );
5501
5829
  const custom = policy.custom.filter((entry) => entry.targets.includes(id)).map((entry) => listening(customPolicy(entry), {}));
5502
- return [...guards, ...custom];
5830
+ const external = (policy.external ?? []).map(
5831
+ (entry) => listening(externalPolicy(entry), {})
5832
+ );
5833
+ return [...guards, ...custom, ...external];
5503
5834
  }
5504
5835
  function bindingsFor(policy, id) {
5505
5836
  const adapter = RUNTIMES[id];
@@ -5517,7 +5848,8 @@ function bindingsFor(policy, id) {
5517
5848
  const tries = policy.failure ? policy.failure.timeoutMs * (policy.failure.retry + 1) : 0;
5518
5849
  const slowest = Math.max(
5519
5850
  tries,
5520
- ...policy.custom.map((entry) => entry.timeoutMs)
5851
+ ...policy.custom.map((entry) => entry.timeoutMs),
5852
+ ...(policy.external ?? []).map((entry) => entry.timeoutMs)
5521
5853
  );
5522
5854
  const timeoutSec = Math.max(
5523
5855
  BASE_TIMEOUT_SEC,
@@ -5743,7 +6075,7 @@ function readGuard(id, raw) {
5743
6075
  function readGuards(guards) {
5744
6076
  const found2 = [];
5745
6077
  for (const [group, value] of Object.entries(guards)) {
5746
- if (group === "custom") continue;
6078
+ if (group === "custom" || group === "external") continue;
5747
6079
  if (!GROUPS.includes(group))
5748
6080
  throw new Error(`unknown guard group hooks.guards.${group}`);
5749
6081
  for (const [name, raw] of Object.entries(
@@ -5756,6 +6088,88 @@ function readGuards(guards) {
5756
6088
  return found2.sort((a, b) => compareIdentifiers(a.id, b.id));
5757
6089
  }
5758
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 } };
6171
+ }
6172
+
5759
6173
  // src/hooks/compile/checks.ts
5760
6174
  function readChecks(raw) {
5761
6175
  const table3 = asTable(raw, "[hooks.checks]");
@@ -5770,7 +6184,7 @@ function readChecks(raw) {
5770
6184
  }
5771
6185
 
5772
6186
  // src/hooks/dispatch/failure.ts
5773
- 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";
5774
6188
  var PASS_KINDS = ["read", "edit-own-worktree"];
5775
6189
  function readFailure(value) {
5776
6190
  if (value === void 0) return void 0;
@@ -5804,8 +6218,8 @@ function ownWorktree(input) {
5804
6218
  if (!checkout || checkout.main) return false;
5805
6219
  const paths = input.tool?.paths ?? [];
5806
6220
  return paths.length > 0 && paths.every((path) => {
5807
- const rest = relative9(checkout.root, resolve9(input.cwd, path));
5808
- return rest !== "" && !rest.startsWith("..") && !isAbsolute9(rest);
6221
+ const rest = relative11(checkout.root, resolve11(input.cwd, path));
6222
+ return rest !== "" && !rest.startsWith("..") && !isAbsolute11(rest);
5809
6223
  });
5810
6224
  }
5811
6225
  function passes(input, pass2) {
@@ -5918,7 +6332,7 @@ var KEYS5 = [
5918
6332
  "mailbox",
5919
6333
  "operator"
5920
6334
  ];
5921
- var MODES3 = ["deny", "ask", "warn", "off"];
6335
+ var MODES4 = ["deny", "ask", "warn", "off"];
5922
6336
  function guard(id, options2, mode) {
5923
6337
  try {
5924
6338
  FEATURES[id].options(options2);
@@ -5931,8 +6345,8 @@ function guard(id, options2, mode) {
5931
6345
  }
5932
6346
  function pauseGuard(raw) {
5933
6347
  const { mode = "deny", ...options2 } = asTable(raw, "[sessions.pause]");
5934
- if (!MODES3.includes(mode))
5935
- 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(", ")}`);
5936
6350
  return guard("sessions.pause", options2, mode);
5937
6351
  }
5938
6352
  function registryCheck(raw) {
@@ -6119,6 +6533,7 @@ function compileHooks(tables, options2) {
6119
6533
  const table3 = readHooksTable(hooks, options2.tools);
6120
6534
  const guardsTable = asTable(hooks["guards"], "[hooks.guards]");
6121
6535
  const entries = readCustom(options2.root, hooks, guardsTable);
6536
+ const external = readExternal(guardsTable["external"]);
6122
6537
  const sessions = readSessions(tables.sessions, tables.git);
6123
6538
  readOperatorSettings(tables.sessions, options2.root);
6124
6539
  const operator = operatorGuard(sessions.declared, guardsTable);
@@ -6127,7 +6542,8 @@ function compileHooks(tables, options2) {
6127
6542
  const directPush = readMainlineDeliver(tables, options2.root);
6128
6543
  const host = hostGuard(tables.host, guardsTable);
6129
6544
  const heavy = readHostLease(tables.host, options2.root);
6130
- 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;
6131
6547
  const legacy = legacyEntries(entries, enabled, table3.targets);
6132
6548
  if (!enabled)
6133
6549
  return {
@@ -6146,6 +6562,7 @@ function compileHooks(tables, options2) {
6146
6562
  ...host ? [host] : [],
6147
6563
  ...heavy ? [heavy] : [],
6148
6564
  ...operator ? [operator] : [],
6565
+ ...owned2 ? [owned2] : [],
6149
6566
  ...readGuards(guardsTable),
6150
6567
  ...readChecks(hooks["checks"])
6151
6568
  ];
@@ -6170,6 +6587,7 @@ function compileHooks(tables, options2) {
6170
6587
  },
6171
6588
  guards,
6172
6589
  custom: pinnedEntries(options2.root, entries, table3.targets),
6590
+ ...external.length > 0 ? { external } : {},
6173
6591
  lowering: loweringFor(table3.targets, table3.askFallback, asks)
6174
6592
  };
6175
6593
  const projecting = table3.targets.filter((id) => {
@@ -6203,7 +6621,8 @@ function readHooks(path, root, raw, tools) {
6203
6621
  sessions: raw["sessions"],
6204
6622
  git: raw["git"],
6205
6623
  logging: raw["logging"],
6206
- host: raw["host"]
6624
+ host: raw["host"],
6625
+ owners: raw["owners"]
6207
6626
  },
6208
6627
  { root, tools }
6209
6628
  );
@@ -6241,6 +6660,44 @@ function deprecations(hooks) {
6241
6660
  );
6242
6661
  }
6243
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
+
6244
6701
  // src/project/spec.ts
6245
6702
  var NAME = /^[a-z0-9][a-z0-9-]*$/u;
6246
6703
  function table2(path, where, value) {
@@ -6379,6 +6836,7 @@ function readSpec(config) {
6379
6836
  let budget;
6380
6837
  try {
6381
6838
  budget = readBudget(raw["budget"]);
6839
+ readBudgets(raw["budgets"]);
6382
6840
  } catch (error) {
6383
6841
  throw new ConfigError(path, error.message);
6384
6842
  }
@@ -6412,6 +6870,8 @@ export {
6412
6870
  programVersion,
6413
6871
  versionMatches,
6414
6872
  customPolicy,
6873
+ externalId,
6874
+ externalPolicy,
6415
6875
  GUARDS,
6416
6876
  FEATURES,
6417
6877
  POLICIES,
@@ -6450,4 +6910,4 @@ export {
6450
6910
  checkBudget,
6451
6911
  readSpec
6452
6912
  };
6453
- //# sourceMappingURL=chunk-TOR6SKRB.js.map
6913
+ //# sourceMappingURL=chunk-Y7FYCVUK.js.map