@modootoday/pmcp 0.19.8 → 0.20.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.
- package/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.mcp.json +1 -1
- package/dist/{apply-6OEABVQT.js → apply-QJ6MGLBX.js} +17 -17
- package/dist/{attachment-D84OGI6n.d.ts → attachment-ms6s8Aow.d.ts} +1 -1
- package/dist/{available-GFMTJW4E.js → available-HYSDAFYH.js} +4 -4
- package/dist/{broadcast-56NPEJWM.js → broadcast-LYOA6BEW.js} +5 -5
- package/dist/{chunk-44YE6B63.js → chunk-4VK5G3SV.js} +3 -3
- package/dist/{chunk-7B2KRL2H.js → chunk-5JPD6VIH.js} +74 -7
- package/dist/{chunk-42RFOVU3.js → chunk-66F3HLW4.js} +17 -5
- package/dist/{chunk-CVZEVTTX.js → chunk-7SDOSTW7.js} +3 -3
- package/dist/{chunk-6U623E6Y.js → chunk-AWZF72SH.js} +6 -6
- package/dist/{chunk-J5ZS7GLA.js → chunk-C3G75JH7.js} +2 -2
- package/dist/{chunk-PTDMSVKS.js → chunk-CQZYQAAV.js} +3 -3
- package/dist/{chunk-SRX2ONSZ.js → chunk-EKPMVEIA.js} +2 -2
- package/dist/{chunk-GXACIGVS.js → chunk-FD6VGFYZ.js} +5 -5
- package/dist/chunk-FGYFA6JY.js +7 -0
- package/dist/{chunk-RXKX33WU.js → chunk-FQAJSNNU.js} +3 -3
- package/dist/{chunk-QPL7E2HW.js → chunk-GJXOFDJT.js} +9 -2
- package/dist/{chunk-JZK7ZO7K.js → chunk-I4U2A6HP.js} +2 -2
- package/dist/{chunk-UGODVKBJ.js → chunk-IQD4W53M.js} +2 -2
- package/dist/{chunk-TFZLX66B.js → chunk-IZABPDAO.js} +2 -2
- package/dist/{chunk-VHTRCE5G.js → chunk-J6HNP6HA.js} +3 -3
- package/dist/{chunk-QXDD75DY.js → chunk-JBHGJKSL.js} +3 -3
- package/dist/{chunk-NWOV2E26.js → chunk-JZKAJUVT.js} +2 -2
- package/dist/{chunk-VUSA7POL.js → chunk-K2C3KFGB.js} +9 -9
- package/dist/{chunk-TLIOBOZ2.js → chunk-L4MFGGSI.js} +2 -2
- package/dist/{chunk-XP2U3LO3.js → chunk-M2RYXWX2.js} +2 -2
- package/dist/{chunk-LJL4L73I.js → chunk-MZEMLFFD.js} +3 -3
- package/dist/{chunk-6QM5OWGZ.js → chunk-O2JWF7ZM.js} +2 -2
- package/dist/{chunk-SHZPE6FD.js → chunk-OAIQ7A3R.js} +5 -5
- package/dist/{chunk-3PW4FI7U.js → chunk-ONP6JRFZ.js} +2 -2
- package/dist/{chunk-HEBCQTOD.js → chunk-PEMMV5YQ.js} +2 -2
- package/dist/{chunk-DHAPQUEF.js → chunk-PQTM27GU.js} +32 -15
- package/dist/{chunk-7B6IC3F7.js → chunk-PUIWESU3.js} +3 -3
- package/dist/{chunk-P4424VLT.js → chunk-QDY6BWE6.js} +2 -2
- package/dist/{chunk-3CYQWRGM.js → chunk-QOFSPFJ6.js} +351 -86
- package/dist/{chunk-C4NHQGHL.js → chunk-QSIADSMQ.js} +13 -2
- package/dist/{chunk-E4FJOLPJ.js → chunk-QYH2NR6G.js} +3 -3
- package/dist/{chunk-XLXDXJY2.js → chunk-RBNMNKNN.js} +5 -5
- package/dist/{chunk-ZYSALKKW.js → chunk-RMHZFWHF.js} +21 -21
- package/dist/{chunk-7DLZC73N.js → chunk-RPCIROW7.js} +2 -2
- package/dist/{chunk-CTA7255D.js → chunk-YDICIB2A.js} +2 -2
- package/dist/{chunk-HEWZ6INU.js → chunk-YOWIYFIV.js} +27 -41
- package/dist/{claude-U2JC2DNQ.js → claude-GT2BPXEL.js} +3 -3
- package/dist/{cli-UFCFDIVI.js → cli-6HTAJ54L.js} +5 -5
- package/dist/{cli-BTPTJWCC.js → cli-IV5DJCXU.js} +8 -8
- package/dist/cli.js +3 -3
- package/dist/{completion-UI4IOYXY.js → completion-PPM7MEI2.js} +2 -2
- package/dist/{config-DnpLL2kT.d.ts → config-DzHB75Jz.d.ts} +2 -0
- package/dist/{diagnostics-QSQDE2KO.js → diagnostics-EWU2ROTG.js} +7 -7
- package/dist/{doctor-EOBNGAAB.js → doctor-ZWZQMDKZ.js} +20 -20
- package/dist/{entry-HBROO3YP.js → entry-NDICBQ2F.js} +12 -12
- package/dist/{exec-mcp-DZU2DEPD.js → exec-mcp-AG4G7SG7.js} +13 -13
- package/dist/{harness-H4OKGO6F.js → harness-JABSZCAA.js} +3 -3
- package/dist/harness-launch-gate.js +5 -5
- package/dist/harness-worker.js +7 -7
- package/dist/hook-body.js +361 -81
- package/dist/{hooks-T5JAK3VQ.js → hooks-YVQSDQV3.js} +3 -3
- package/dist/{host-5JOCZURV.js → host-2SZRMHZX.js} +8 -8
- package/dist/{host-IRPBT5AL.js → host-BWZ5LA4Q.js} +16 -16
- package/dist/{host-run-KPH5ZNYU.js → host-run-SXLV4LHI.js} +21 -13
- package/dist/http.d.ts +1 -1
- package/dist/http.js +1 -1
- package/dist/{import-mcp-24QRNZBJ.js → import-mcp-2M7SZRVQ.js} +11 -11
- package/dist/index.d.ts +6 -4
- package/dist/index.js +19 -19
- package/dist/{init-EPIJY23S.js → init-HOOIFBAD.js} +2 -2
- package/dist/{install-MQ7QSJQ7.js → install-HF6CROQP.js} +19 -9
- package/dist/{invoke-2SXY6G3P.js → invoke-JP4MILYY.js} +9 -9
- package/dist/{list-C3WEYY3N.js → list-UBSBUZKS.js} +13 -13
- package/dist/{list-FB6RNYYB.js → list-WK2IYUK7.js} +4 -4
- package/dist/{logout-J4SFSWMA.js → logout-OO3DERRK.js} +12 -12
- package/dist/{logs-H3RPKNTE.js → logs-K3QXKRD4.js} +6 -6
- package/dist/mailbox/index.d.ts +4 -4
- package/dist/mailbox/index.js +3 -3
- package/dist/{mailbox-UECKDZ3Q.js → mailbox-DAJV6VAI.js} +10 -10
- package/dist/{mailbox-5DWLH4W2.js → mailbox-YN6PG66A.js} +4 -4
- package/dist/{mainline-FPK4HWFF.js → mainline-6K5BA3WX.js} +55 -33
- package/dist/{mcp-W6OADCKB.js → mcp-JXNTKRJG.js} +2 -2
- package/dist/{pause-2HQ7CKMR.js → pause-GRVTSKOK.js} +5 -5
- package/dist/{project-TZAYGUHM.js → project-M672MKQH.js} +4 -4
- package/dist/{pty-XTJ4MIWK.js → pty-LHKJKY2E.js} +3 -3
- package/dist/{recovery-54KHNJX4.js → recovery-HB2YFQSQ.js} +3 -3
- package/dist/{reindex-ZULHSQWY.js → reindex-I7RYWCUR.js} +5 -5
- package/dist/{resume-ETFTR5V3.js → resume-6DMPGG3N.js} +5 -5
- package/dist/{run-QQB74HRI.js → run-5W566T3V.js} +14 -14
- package/dist/{run-XZ75CAFL.js → run-ORBIERI3.js} +4 -4
- package/dist/{serve-TILM4DH5.js → serve-73SRPAV4.js} +9 -9
- package/dist/{setup-63E3TVJK.js → setup-ULKDPF5B.js} +5 -6
- package/dist/{start-login-C2BWQNO5.js → start-login-BGFAMCZL.js} +12 -12
- package/dist/{status-3AU65SCN.js → status-73FEFQUQ.js} +12 -12
- package/dist/{status-JMXH6XG4.js → status-YCW6YJ3S.js} +23 -23
- package/dist/{status-CM753VKY.js → status-YHXEAJ7U.js} +8 -8
- package/dist/stdio.d.ts +2 -2
- package/dist/stdio.js +5 -5
- package/dist/{sweep-VY2TNOO5.js → sweep-XF2HG3EO.js} +5 -5
- package/dist/{test-MCM44GOL.js → test-IMNBXOYW.js} +15 -17
- package/dist/{tui-BL4OSDW4.js → tui-5GDA22TB.js} +6 -6
- package/dist/{unbroadcast-RKTBP57G.js → unbroadcast-XP3OCVN3.js} +5 -5
- package/dist/{validate-AVM2VHMM.js → validate-KFBCUFI4.js} +5 -5
- package/dist/{worker-GHQKC5XU.js → worker-RV6NGSXT.js} +10 -10
- package/dist/{worktree-list-NEIDD66X.js → worktree-list-4PLE7K6L.js} +4 -4
- package/docs/git-workflow.md +48 -12
- package/docs/hooks.md +23 -14
- package/docs/project-configuration.md +21 -12
- package/docs/upgrading.md +52 -0
- package/gemini-extension.json +2 -2
- package/mcp.json +1 -1
- package/package.json +5 -5
- package/plugin.json +1 -1
- package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
- package/plugins/pmcp/.mcp.json +1 -1
- package/plugins/pmcp/gemini-extension.json +2 -2
- package/plugins/pmcp/mcp.json +1 -1
- package/plugins/pmcp/mod/draw.tsx +9 -2
- package/plugins/pmcp/mod/guard.ts +3 -3
- package/plugins/pmcp/mod/model.ts +15 -4
- package/plugins/pmcp/mod/reader/read.ts +33 -8
- package/plugins/pmcp/mod/reader/settings.ts +7 -0
- package/plugins/pmcp/mod/reader/types.ts +2 -0
- package/plugins/pmcp/mod/sessions/format.ts +25 -2
- package/plugins/pmcp/mod/sessions/types.ts +1 -1
- package/plugins/pmcp/plugin.json +1 -1
- package/schema/catalog-v1.json +4 -15
- package/schema/library.json +3 -8
- package/schema/marketplace-manifest.json +2 -6
- package/schema/skill-frontmatter.json +3 -8
- package/schema/skill-metadata-core.json +3 -8
- package/dist/chunk-DXJZ2ZCX.js +0 -56
- package/dist/chunk-QHH3TXOA.js +0 -7
- package/dist/{core-C1LPjxK6.d.ts → core-Sug_rZrx.d.ts} +1 -1
package/dist/hook-body.js
CHANGED
|
@@ -46,10 +46,10 @@ function compose(decisions) {
|
|
|
46
46
|
function lower(decision, lowering) {
|
|
47
47
|
if (decision.verdict !== "ask" || !lowering) return decision;
|
|
48
48
|
if (lowering.ask === "deny") return { ...decision, verdict: "deny" };
|
|
49
|
-
const { verdict: _verdict, reason, ...rest } = decision;
|
|
49
|
+
const { verdict: _verdict, reason: reason2, ...rest } = decision;
|
|
50
50
|
return {
|
|
51
51
|
...rest,
|
|
52
|
-
context: [...decision.context ?? [], `pmcp: ${
|
|
52
|
+
context: [...decision.context ?? [], `pmcp: ${reason2 ?? "would ask"}`]
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -653,24 +653,41 @@ function runsScript(words, scripts) {
|
|
|
653
653
|
}
|
|
654
654
|
function touchesLock(words, scripts) {
|
|
655
655
|
if (words[0] === "bun" && BUN_INSTALLS.has(words[1] ?? "")) return true;
|
|
656
|
-
if (words[0] === "bun" && words[1] === "run" && /^git:(land|sync)$/u.test(words[2] ?? ""))
|
|
657
|
-
return true;
|
|
658
656
|
return runsScript(words, scripts);
|
|
659
657
|
}
|
|
660
|
-
|
|
658
|
+
var DEFAULT_MUTATING_COMMANDS = [
|
|
659
|
+
...[...DOCKER_MUTATING].map((verb) => ["docker", verb]),
|
|
660
|
+
...[...WRANGLER_MUTATING].map((verb) => ["wrangler", verb])
|
|
661
|
+
];
|
|
662
|
+
var DEFAULT_MUTATING_SCRIPT_NAMES = [
|
|
663
|
+
"^git:",
|
|
664
|
+
"^docker:",
|
|
665
|
+
"^deploy",
|
|
666
|
+
"^release",
|
|
667
|
+
"^publish"
|
|
668
|
+
];
|
|
669
|
+
var DEFAULT_MUTATING_RULES = {
|
|
670
|
+
scripts: [],
|
|
671
|
+
commands: DEFAULT_MUTATING_COMMANDS,
|
|
672
|
+
scriptNames: DEFAULT_MUTATING_SCRIPT_NAMES.map(
|
|
673
|
+
(source) => new RegExp(source, "u")
|
|
674
|
+
)
|
|
675
|
+
};
|
|
676
|
+
var RUNNERS = /* @__PURE__ */ new Set(["bun", "npm", "pnpm", "yarn"]);
|
|
677
|
+
function mutates(words, rules = DEFAULT_MUTATING_RULES) {
|
|
661
678
|
const [name = "", sub = ""] = words;
|
|
662
679
|
if (name === "git") {
|
|
663
680
|
const call = gitCall(words);
|
|
664
681
|
if (GIT_MUTATING.has(call.sub)) return true;
|
|
665
682
|
return call.sub === "worktree" && ["add", "remove", "move"].includes(call.next);
|
|
666
683
|
}
|
|
667
|
-
if (touchesLock(words, scripts)) return true;
|
|
668
|
-
if (name
|
|
669
|
-
return
|
|
684
|
+
if (touchesLock(words, rules.scripts)) return true;
|
|
685
|
+
if (RUNNERS.has(name) && sub === "run")
|
|
686
|
+
return rules.scriptNames.some((pattern) => pattern.test(words[2] ?? ""));
|
|
670
687
|
if (["npm", "pnpm", "yarn"].includes(name)) return PACKAGE_MUTATING.has(sub);
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
688
|
+
return rules.commands.some(
|
|
689
|
+
(prefix) => prefix.length > 0 && prefix.every((word, at) => words[at] === word)
|
|
690
|
+
);
|
|
674
691
|
}
|
|
675
692
|
|
|
676
693
|
// src/hooks/dispatch/enrich.ts
|
|
@@ -1505,8 +1522,8 @@ function matches(selector, recipient) {
|
|
|
1505
1522
|
return !!recipient.session && recipient.session.startsWith(value);
|
|
1506
1523
|
if (kind === "alias") return recipient.alias === value;
|
|
1507
1524
|
if (kind === "role") return (recipient.roles ?? []).includes(value);
|
|
1508
|
-
if (!isWorktree(kind) || !recipient.
|
|
1509
|
-
return recipient.
|
|
1525
|
+
if (!isWorktree(kind) || !recipient.worktree) return false;
|
|
1526
|
+
return recipient.worktree === value || basename2(recipient.worktree) === value;
|
|
1510
1527
|
}
|
|
1511
1528
|
function before(message, recipient) {
|
|
1512
1529
|
if (!recipient.since) return false;
|
|
@@ -1532,12 +1549,22 @@ import { basename as basename3 } from "node:path";
|
|
|
1532
1549
|
|
|
1533
1550
|
// src/sessions/format.ts
|
|
1534
1551
|
var STATE_FILES = {
|
|
1535
|
-
records: "
|
|
1552
|
+
records: "sessions",
|
|
1553
|
+
// The records' former directory. Deprecated: 0.20 still writes every record there too and
|
|
1554
|
+
// reads it when sessions/ lacks one; 0.21 stops writing it.
|
|
1555
|
+
legacyRecords: "fleet",
|
|
1536
1556
|
pause: "pause.json",
|
|
1537
1557
|
broadcast: "broadcast.json",
|
|
1538
1558
|
history: "broadcast-history.jsonl"
|
|
1539
1559
|
};
|
|
1540
1560
|
var STALE_MS = 30 * 60 * 1e3;
|
|
1561
|
+
function latestRecord(copies) {
|
|
1562
|
+
const time = (record) => Date.parse(record.updatedAt ?? record.startedAt ?? "") || 0;
|
|
1563
|
+
let latest = null;
|
|
1564
|
+
for (const copy of copies)
|
|
1565
|
+
if (copy && (!latest || time(copy) > time(latest))) latest = copy;
|
|
1566
|
+
return latest;
|
|
1567
|
+
}
|
|
1541
1568
|
var LEASE_NAME = /^[a-z0-9][a-z0-9_-]*$/u;
|
|
1542
1569
|
function leaseFile(name) {
|
|
1543
1570
|
if (!LEASE_NAME.test(name)) throw new Error(`invalid lease name ${name}`);
|
|
@@ -1686,7 +1713,7 @@ function recipientOf(input, ctx) {
|
|
|
1686
1713
|
session,
|
|
1687
1714
|
...record?.alias ? { alias: record.alias } : {},
|
|
1688
1715
|
roles: roles2,
|
|
1689
|
-
|
|
1716
|
+
worktree: record?.worktree || input.cwd,
|
|
1690
1717
|
// The registry records a session at its start, so earlier broadcasts are not its news.
|
|
1691
1718
|
...record?.startedAt ? { since: record.startedAt } : {}
|
|
1692
1719
|
};
|
|
@@ -1749,18 +1776,41 @@ var mailbox = {
|
|
|
1749
1776
|
};
|
|
1750
1777
|
|
|
1751
1778
|
// src/hooks/policies/sessions/pause.ts
|
|
1752
|
-
var
|
|
1779
|
+
var BUILT_IN = /\b(git\s+(commit|push|merge|rebase|reset|checkout|switch|cherry-pick|revert|am|stash|tag|clean|restore|rm|mv|worktree\s+(add|remove|move))|bun\s+(install|i|add|remove|rm|update|link)\b|(npm|pnpm|yarn)\s+(install|i|add|remove|publish|ci)\b)\b/u;
|
|
1780
|
+
var escape2 = (word) => word.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
1753
1781
|
function changes(input, options2) {
|
|
1754
1782
|
const tool = input.tool;
|
|
1755
1783
|
if (tool?.kind === "edit") return true;
|
|
1756
1784
|
if (tool?.kind !== "shell") return false;
|
|
1757
1785
|
if (!tool.steps) {
|
|
1758
1786
|
const command6 = tool.command ?? "";
|
|
1759
|
-
return
|
|
1787
|
+
return BUILT_IN.test(command6) || options2.commands.some(
|
|
1788
|
+
(prefix) => new RegExp(`\\b${prefix.map(escape2).join("\\s+")}\\b`, "u").test(
|
|
1789
|
+
command6
|
|
1790
|
+
)
|
|
1791
|
+
) || options2.scripts.some((s) => s.test(command6));
|
|
1760
1792
|
}
|
|
1761
|
-
return realSteps(tool.steps).some(
|
|
1762
|
-
|
|
1763
|
-
|
|
1793
|
+
return realSteps(tool.steps).some((step) => mutates(step.argv, options2));
|
|
1794
|
+
}
|
|
1795
|
+
function patterns(raw, key) {
|
|
1796
|
+
const list = stringList(raw, key);
|
|
1797
|
+
if (list === void 0) return null;
|
|
1798
|
+
return list.map((source) => {
|
|
1799
|
+
try {
|
|
1800
|
+
return new RegExp(source, "u");
|
|
1801
|
+
} catch {
|
|
1802
|
+
throw new Error(`${key}: ${source} is not a regular expression`);
|
|
1803
|
+
}
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
function prefixes(raw) {
|
|
1807
|
+
const value = raw["commands"];
|
|
1808
|
+
if (value === void 0) return null;
|
|
1809
|
+
if (!Array.isArray(value) || !value.every(
|
|
1810
|
+
(prefix) => Array.isArray(prefix) && prefix.length > 0 && prefix.every((word) => typeof word === "string" && word !== "")
|
|
1811
|
+
))
|
|
1812
|
+
throw new Error("commands must be a list of argv prefixes");
|
|
1813
|
+
return value;
|
|
1764
1814
|
}
|
|
1765
1815
|
function foreign(pause2, input, ctx) {
|
|
1766
1816
|
const session = input.session.id;
|
|
@@ -1775,17 +1825,14 @@ var pause = {
|
|
|
1775
1825
|
fail: "closed",
|
|
1776
1826
|
defaultMode: "deny",
|
|
1777
1827
|
options(raw) {
|
|
1778
|
-
onlyKeys(raw, ["refuses", "scripts"]);
|
|
1828
|
+
onlyKeys(raw, ["refuses", "scripts", "commands", "script_names"]);
|
|
1779
1829
|
if (raw["refuses"] !== void 0 && raw["refuses"] !== "mutating")
|
|
1780
1830
|
throw new Error("refuses must be mutating");
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
}
|
|
1787
|
-
});
|
|
1788
|
-
return { scripts };
|
|
1831
|
+
return {
|
|
1832
|
+
scripts: patterns(raw, "scripts") ?? [],
|
|
1833
|
+
commands: prefixes(raw) ?? DEFAULT_MUTATING_COMMANDS,
|
|
1834
|
+
scriptNames: patterns(raw, "script_names") ?? DEFAULT_MUTATING_SCRIPT_NAMES.map((source) => new RegExp(source, "u"))
|
|
1835
|
+
};
|
|
1789
1836
|
},
|
|
1790
1837
|
evaluate(input, ctx) {
|
|
1791
1838
|
const current = ctx.store.pause.read();
|
|
@@ -1859,8 +1906,8 @@ function fields(input) {
|
|
|
1859
1906
|
return { ...cwd, status: "working", waiting: "" };
|
|
1860
1907
|
if (input.event === "after_tool") return { ...cwd, status: "working" };
|
|
1861
1908
|
if (input.event === "notification") {
|
|
1862
|
-
const
|
|
1863
|
-
return { status: "waiting", waiting:
|
|
1909
|
+
const reason2 = input.notification?.type || input.notification?.message;
|
|
1910
|
+
return { status: "waiting", waiting: reason2 ?? "" };
|
|
1864
1911
|
}
|
|
1865
1912
|
if (input.event === "stop") {
|
|
1866
1913
|
return {
|
|
@@ -2029,8 +2076,8 @@ var composeTeardown = {
|
|
|
2029
2076
|
};
|
|
2030
2077
|
}
|
|
2031
2078
|
for (const step of realSteps(call.steps)) {
|
|
2032
|
-
const
|
|
2033
|
-
if (
|
|
2079
|
+
const reason2 = teardownReason(step.argv);
|
|
2080
|
+
if (reason2) return { verdict: "deny", reason: reason2 };
|
|
2034
2081
|
}
|
|
2035
2082
|
return pass;
|
|
2036
2083
|
}
|
|
@@ -2138,6 +2185,220 @@ var inPlaceEdit = {
|
|
|
2138
2185
|
}
|
|
2139
2186
|
};
|
|
2140
2187
|
|
|
2188
|
+
// src/hooks/policies/shell/regex-cost.ts
|
|
2189
|
+
var BASIC_INTERVAL = /^\\\{(\d*)(?:,(\d*))?\\\}/u;
|
|
2190
|
+
var INTERVAL = /^\{(\d*)(?:,(\d*))?\}/u;
|
|
2191
|
+
function repetitionCounts(pattern, flavor) {
|
|
2192
|
+
const counts = [];
|
|
2193
|
+
for (let at = 0; at < pattern.length; at += 1) {
|
|
2194
|
+
const char = pattern[at];
|
|
2195
|
+
if (char !== "\\" && char !== "{") continue;
|
|
2196
|
+
const shape3 = flavor === "basic" ? BASIC_INTERVAL : INTERVAL;
|
|
2197
|
+
const interval = char === "{" && flavor === "basic" ? null : shape3.exec(pattern.slice(at));
|
|
2198
|
+
if (!interval) {
|
|
2199
|
+
if (char === "\\") at += 1;
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2202
|
+
for (const bound of [interval[1], interval[2]])
|
|
2203
|
+
if (bound) counts.push(Number(bound));
|
|
2204
|
+
at += interval[0].length - 1;
|
|
2205
|
+
}
|
|
2206
|
+
return counts;
|
|
2207
|
+
}
|
|
2208
|
+
function nestedQuantifier(pattern) {
|
|
2209
|
+
const groups = [];
|
|
2210
|
+
let quantified = false;
|
|
2211
|
+
for (let at = 0; at < pattern.length; at += 1) {
|
|
2212
|
+
const char = pattern[at];
|
|
2213
|
+
if (char === "\\") {
|
|
2214
|
+
at += 1;
|
|
2215
|
+
continue;
|
|
2216
|
+
}
|
|
2217
|
+
if (char === "[") {
|
|
2218
|
+
at = classEnd(pattern, at);
|
|
2219
|
+
continue;
|
|
2220
|
+
}
|
|
2221
|
+
if (char === "(") {
|
|
2222
|
+
groups.push(quantified);
|
|
2223
|
+
quantified = false;
|
|
2224
|
+
continue;
|
|
2225
|
+
}
|
|
2226
|
+
if (char === ")") {
|
|
2227
|
+
const inner = quantified;
|
|
2228
|
+
quantified = groups.pop() ?? false;
|
|
2229
|
+
if (inner && repeats(pattern, at + 1)) return true;
|
|
2230
|
+
quantified ||= inner;
|
|
2231
|
+
continue;
|
|
2232
|
+
}
|
|
2233
|
+
if (repeats(pattern, at)) quantified = true;
|
|
2234
|
+
}
|
|
2235
|
+
return false;
|
|
2236
|
+
}
|
|
2237
|
+
function repeats(pattern, at) {
|
|
2238
|
+
const char = pattern[at];
|
|
2239
|
+
if (char === "*" || char === "+") return true;
|
|
2240
|
+
return char === "{" && /^\{\d*,\}/u.test(pattern.slice(at));
|
|
2241
|
+
}
|
|
2242
|
+
function classEnd(pattern, start) {
|
|
2243
|
+
let at = start + 1;
|
|
2244
|
+
if (pattern[at] === "^") at += 1;
|
|
2245
|
+
if (pattern[at] === "]") at += 1;
|
|
2246
|
+
for (; at < pattern.length; at += 1) {
|
|
2247
|
+
if (pattern[at] === "\\") at += 1;
|
|
2248
|
+
else if (pattern[at] === "]") return at;
|
|
2249
|
+
}
|
|
2250
|
+
return pattern.length;
|
|
2251
|
+
}
|
|
2252
|
+
function patternCost(pattern, flavor, onlyMatching, limits) {
|
|
2253
|
+
const largest = Math.max(0, ...repetitionCounts(pattern, flavor));
|
|
2254
|
+
if (largest > limits.threshold)
|
|
2255
|
+
return `a repetition count of ${largest} (the limit is ${limits.threshold})`;
|
|
2256
|
+
if (flavor === "perl" && nestedQuantifier(pattern))
|
|
2257
|
+
return "a -P pattern with a quantified group inside a quantifier, such as (a+)+ or (.*)*";
|
|
2258
|
+
if (limits.onlyMatchingWildcards && onlyMatching && (pattern.match(/\.\*/gu) ?? []).length > 1)
|
|
2259
|
+
return "-o with more than one .*";
|
|
2260
|
+
return null;
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
// src/hooks/policies/shell/runaway-regex.ts
|
|
2264
|
+
var GREPS = {
|
|
2265
|
+
grep: "basic",
|
|
2266
|
+
zgrep: "basic",
|
|
2267
|
+
egrep: "extended",
|
|
2268
|
+
fgrep: "fixed"
|
|
2269
|
+
};
|
|
2270
|
+
var VALUE_SHORT = /* @__PURE__ */ new Set(["e", "f", "m", "A", "B", "C", "d", "D", "O"]);
|
|
2271
|
+
var VALUE_LONG = /* @__PURE__ */ new Set([
|
|
2272
|
+
"regexp",
|
|
2273
|
+
"file",
|
|
2274
|
+
"max-count",
|
|
2275
|
+
"after-context",
|
|
2276
|
+
"before-context",
|
|
2277
|
+
"context",
|
|
2278
|
+
"include",
|
|
2279
|
+
"exclude",
|
|
2280
|
+
"exclude-dir",
|
|
2281
|
+
"exclude-from",
|
|
2282
|
+
"binary-files",
|
|
2283
|
+
"devices",
|
|
2284
|
+
"directories",
|
|
2285
|
+
"label",
|
|
2286
|
+
"max-depth",
|
|
2287
|
+
"threads"
|
|
2288
|
+
]);
|
|
2289
|
+
var FLAVOR_SHORT = {
|
|
2290
|
+
E: "extended",
|
|
2291
|
+
P: "perl",
|
|
2292
|
+
F: "fixed",
|
|
2293
|
+
G: "basic"
|
|
2294
|
+
};
|
|
2295
|
+
var FLAVOR_LONG = {
|
|
2296
|
+
"extended-regexp": "extended",
|
|
2297
|
+
"perl-regexp": "perl",
|
|
2298
|
+
"fixed-strings": "fixed",
|
|
2299
|
+
"basic-regexp": "basic"
|
|
2300
|
+
};
|
|
2301
|
+
function readGrep(args, start) {
|
|
2302
|
+
const patterns2 = [];
|
|
2303
|
+
let flavor = start;
|
|
2304
|
+
let onlyMatching = false;
|
|
2305
|
+
let operand;
|
|
2306
|
+
let fromFile = false;
|
|
2307
|
+
for (let at = 0; at < args.length; at += 1) {
|
|
2308
|
+
const arg = args[at];
|
|
2309
|
+
if (arg === "--") {
|
|
2310
|
+
operand ??= args[at + 1];
|
|
2311
|
+
break;
|
|
2312
|
+
}
|
|
2313
|
+
if (arg.startsWith("--")) {
|
|
2314
|
+
const [name = "", inline] = arg.slice(2).split(/=(.*)/su);
|
|
2315
|
+
if (FLAVOR_LONG[name]) flavor = FLAVOR_LONG[name];
|
|
2316
|
+
if (name === "only-matching") onlyMatching = true;
|
|
2317
|
+
const value = VALUE_LONG.has(name) && inline === void 0 ? args[at += 1] : inline;
|
|
2318
|
+
if (name === "regexp" && value !== void 0) patterns2.push(value);
|
|
2319
|
+
if (name === "file") fromFile = true;
|
|
2320
|
+
continue;
|
|
2321
|
+
}
|
|
2322
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
2323
|
+
for (let i = 1; i < arg.length; i += 1) {
|
|
2324
|
+
const flag2 = arg[i];
|
|
2325
|
+
if (FLAVOR_SHORT[flag2]) flavor = FLAVOR_SHORT[flag2];
|
|
2326
|
+
if (flag2 === "o") onlyMatching = true;
|
|
2327
|
+
if (!VALUE_SHORT.has(flag2)) continue;
|
|
2328
|
+
const value = i + 1 < arg.length ? arg.slice(i + 1) : args[at += 1];
|
|
2329
|
+
if (flag2 === "e" && value !== void 0) patterns2.push(value);
|
|
2330
|
+
if (flag2 === "f") fromFile = true;
|
|
2331
|
+
break;
|
|
2332
|
+
}
|
|
2333
|
+
continue;
|
|
2334
|
+
}
|
|
2335
|
+
operand ??= arg;
|
|
2336
|
+
}
|
|
2337
|
+
if (patterns2.length === 0 && !fromFile && operand !== void 0)
|
|
2338
|
+
patterns2.push(operand);
|
|
2339
|
+
return { patterns: patterns2, flavor, onlyMatching };
|
|
2340
|
+
}
|
|
2341
|
+
function grepOf(argv) {
|
|
2342
|
+
const name = program(argv[0]);
|
|
2343
|
+
if (GREPS[name]) return readGrep(argv.slice(1), GREPS[name]);
|
|
2344
|
+
if (name !== "git") return null;
|
|
2345
|
+
const call = gitCall(argv);
|
|
2346
|
+
return call.sub === "grep" ? readGrep(argv.slice(call.at + 1), "basic") : null;
|
|
2347
|
+
}
|
|
2348
|
+
function timed(step) {
|
|
2349
|
+
const at = step.raw.indexOf(step.argv[0]);
|
|
2350
|
+
return step.raw.slice(0, at < 0 ? 0 : at).some((word) => program(word) === "timeout");
|
|
2351
|
+
}
|
|
2352
|
+
function costOf(step, options2) {
|
|
2353
|
+
const grep = grepOf(step.argv);
|
|
2354
|
+
if (!grep || grep.flavor === "fixed") return null;
|
|
2355
|
+
if (options2.allowTimeout && timed(step)) return null;
|
|
2356
|
+
for (const pattern of grep.patterns) {
|
|
2357
|
+
const why = patternCost(pattern, grep.flavor, grep.onlyMatching, options2);
|
|
2358
|
+
if (why) return why;
|
|
2359
|
+
}
|
|
2360
|
+
return null;
|
|
2361
|
+
}
|
|
2362
|
+
var reason = (why, threshold) => `This grep can keep a CPU core busy for minutes: ${why}. Find the line with grep -n and no -o or large count, then print a window around it with sed -n 'N,+K p' FILE; or use rg, which matches in linear time; or bring the count to ${threshold} or below; or bound the run with timeout 20 grep \u2026.`;
|
|
2363
|
+
function integer(raw, key, fallback3) {
|
|
2364
|
+
const value = raw[key] ?? fallback3;
|
|
2365
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 32767)
|
|
2366
|
+
throw new Error(`${key} must be an integer from 1 to 32767`);
|
|
2367
|
+
return value;
|
|
2368
|
+
}
|
|
2369
|
+
function bool(raw, key, fallback3) {
|
|
2370
|
+
const value = raw[key] ?? fallback3;
|
|
2371
|
+
if (typeof value !== "boolean")
|
|
2372
|
+
throw new Error(`${key} must be true or false`);
|
|
2373
|
+
return value;
|
|
2374
|
+
}
|
|
2375
|
+
var runawayRegex = {
|
|
2376
|
+
id: "shell.runaway_regex",
|
|
2377
|
+
events: ["before_tool"],
|
|
2378
|
+
tools: ["shell"],
|
|
2379
|
+
fail: "closed",
|
|
2380
|
+
defaultMode: "deny",
|
|
2381
|
+
options(raw) {
|
|
2382
|
+
onlyKeys(raw, ["threshold", "only_matching_wildcards", "allow_timeout"]);
|
|
2383
|
+
return {
|
|
2384
|
+
threshold: integer(raw, "threshold", 255),
|
|
2385
|
+
onlyMatchingWildcards: bool(raw, "only_matching_wildcards", false),
|
|
2386
|
+
allowTimeout: bool(raw, "allow_timeout", true)
|
|
2387
|
+
};
|
|
2388
|
+
},
|
|
2389
|
+
// Unreadable shell syntax passes: a wrong refusal here costs more than a slow grep.
|
|
2390
|
+
evaluate(input, ctx) {
|
|
2391
|
+
const call = shellCall(input);
|
|
2392
|
+
if (!call?.steps) return pass;
|
|
2393
|
+
for (const step of realSteps(call.steps)) {
|
|
2394
|
+
const why = costOf(step, ctx.options);
|
|
2395
|
+
if (why)
|
|
2396
|
+
return { verdict: "deny", reason: reason(why, ctx.options.threshold) };
|
|
2397
|
+
}
|
|
2398
|
+
return pass;
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
|
|
2141
2402
|
// src/hooks/policies/shell/operands.ts
|
|
2142
2403
|
var SEARCH = {
|
|
2143
2404
|
code: ["-e", "--regexp"],
|
|
@@ -2243,9 +2504,7 @@ function fileOperands(argv) {
|
|
|
2243
2504
|
// src/hooks/policies/shell/secret-exfiltration.ts
|
|
2244
2505
|
var SECRET_PATHS = [
|
|
2245
2506
|
/(?:^|[^\w.-])\.env(?:\.(?!example\b|sample\b|template\b|dist\b)[\w.-]+)?(?![\w.-])/iu,
|
|
2246
|
-
/(?:^|[^\w.-])\.env\.d(?:\/|\b)/iu,
|
|
2247
2507
|
/\.dev\.vars(?:\.json)?\b/iu,
|
|
2248
|
-
/\.bak\.\d{8,}/u,
|
|
2249
2508
|
/\b(?:id_rsa|id_ed25519|id_ecdsa)\b(?!\.pub)/u,
|
|
2250
2509
|
/\.(?:pem|p12|pfx)\b/iu,
|
|
2251
2510
|
// Known credential files only: a name that merely contains "secret" (a test fixture, a
|
|
@@ -2273,7 +2532,7 @@ var ENV_DUMPS = [
|
|
|
2273
2532
|
["export", "-p"],
|
|
2274
2533
|
["declare", "-x"]
|
|
2275
2534
|
];
|
|
2276
|
-
var FALLBACK_PATH = /(?:^|[^\w.-])\.env(?![.\w-])
|
|
2535
|
+
var FALLBACK_PATH = /(?:^|[^\w.-])\.env(?![.\w-])|\.dev\.vars(?:\.json)?\b/u;
|
|
2277
2536
|
var FALLBACK_USE = /(?:^|[;&|(]|&&)\s*(?:sudo\s+)?(?:cat|head|tail|less|grep|rg|jq|base64|cp|curl|wget|nc|scp|rsync)\b/u;
|
|
2278
2537
|
var NO_VALUES = "Use metadata verbs instead (ls, stat, wc, find), or a command that names keys without resolving values.";
|
|
2279
2538
|
function names(word, options2) {
|
|
@@ -3026,8 +3285,12 @@ function blocked2(input, ctx) {
|
|
|
3026
3285
|
const pause2 = ctx.store.pause.read();
|
|
3027
3286
|
if (pause2 && pause2.by !== input.session.id)
|
|
3028
3287
|
return `the workspace is paused (${pause2.reason})`;
|
|
3029
|
-
const
|
|
3030
|
-
|
|
3288
|
+
for (const name of ctx.options.leases ?? ["lockfile"]) {
|
|
3289
|
+
const lease = ctx.store.leases.read(name);
|
|
3290
|
+
if (lease)
|
|
3291
|
+
return `a change under lease ${name} is being delivered (${lease.subject})`;
|
|
3292
|
+
}
|
|
3293
|
+
return null;
|
|
3031
3294
|
}
|
|
3032
3295
|
function changed(root, from, paths, to = "HEAD") {
|
|
3033
3296
|
if (paths.length === 0) return [];
|
|
@@ -3076,7 +3339,7 @@ function move(input, ctx, git2) {
|
|
|
3076
3339
|
});
|
|
3077
3340
|
if (result === "current") return [];
|
|
3078
3341
|
if (result === "held")
|
|
3079
|
-
return lines.map((line) => `
|
|
3342
|
+
return lines.map((line) => `Worktree ${git2.root}: ${line}`);
|
|
3080
3343
|
if (opts.install && opts.installAfterMove === "background" && changed(git2.root, before2, opts.installWhen).length > 0) {
|
|
3081
3344
|
backgroundInstall(git2.root, opts.install, opts.umask);
|
|
3082
3345
|
lines.push(`installing in the background: ${opts.install.join(" ")}`);
|
|
@@ -3086,7 +3349,7 @@ function move(input, ctx, git2) {
|
|
|
3086
3349
|
lines.push(
|
|
3087
3350
|
`These rule files changed with the move; re-read them before going on: ${rules.join(", ")}`
|
|
3088
3351
|
);
|
|
3089
|
-
return lines.map((line) => `
|
|
3352
|
+
return lines.map((line) => `Worktree ${git2.root}: ${line}`);
|
|
3090
3353
|
}
|
|
3091
3354
|
var worktreeSync = {
|
|
3092
3355
|
id: "git.worktrees.sync",
|
|
@@ -3101,9 +3364,9 @@ var worktreeSync = {
|
|
|
3101
3364
|
if (input.event === "prompt" && opts.betweenPrompts === "off") return pass;
|
|
3102
3365
|
const git2 = desk(input, opts);
|
|
3103
3366
|
if (!git2) return pass;
|
|
3104
|
-
const
|
|
3105
|
-
if (
|
|
3106
|
-
return input.event === "session_start" ? { context: [`
|
|
3367
|
+
const reason2 = blocked2(input, ctx);
|
|
3368
|
+
if (reason2)
|
|
3369
|
+
return input.event === "session_start" ? { context: [`Worktree ${git2.root} was not moved: ${reason2}.`] } : pass;
|
|
3107
3370
|
const lines = move(input, ctx, git2);
|
|
3108
3371
|
return lines.length > 0 ? { context: lines } : pass;
|
|
3109
3372
|
}
|
|
@@ -3172,15 +3435,15 @@ function run2(entry, input) {
|
|
|
3172
3435
|
const extra = Object.keys(response).some(
|
|
3173
3436
|
(key) => key !== "decision" && key !== "reason"
|
|
3174
3437
|
);
|
|
3175
|
-
const
|
|
3176
|
-
if (extra ||
|
|
3438
|
+
const reason2 = response["reason"];
|
|
3439
|
+
if (extra || reason2 !== void 0 && typeof reason2 !== "string")
|
|
3177
3440
|
return { verdict: "deny", reason: FAILED };
|
|
3178
3441
|
if (response["decision"] === "allow") return pass;
|
|
3179
3442
|
if (response["decision"] !== "deny")
|
|
3180
3443
|
return { verdict: "deny", reason: FAILED };
|
|
3181
3444
|
return {
|
|
3182
3445
|
verdict: "deny",
|
|
3183
|
-
reason: typeof
|
|
3446
|
+
reason: typeof reason2 === "string" ? reason2.slice(0, 2e3) : FAILED
|
|
3184
3447
|
};
|
|
3185
3448
|
}
|
|
3186
3449
|
function customPolicy(entry) {
|
|
@@ -3204,6 +3467,7 @@ var GUARDS = byId([
|
|
|
3204
3467
|
composeTeardown,
|
|
3205
3468
|
hostApproval,
|
|
3206
3469
|
secretExfiltration,
|
|
3470
|
+
runawayRegex,
|
|
3207
3471
|
pushWithoutVerify,
|
|
3208
3472
|
forcedBranchMove,
|
|
3209
3473
|
gateBypassEnv,
|
|
@@ -3322,14 +3586,14 @@ function silent(event) {
|
|
|
3322
3586
|
}
|
|
3323
3587
|
function render(input, decision) {
|
|
3324
3588
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
3325
|
-
const
|
|
3589
|
+
const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON);
|
|
3326
3590
|
if (input.event === "before_tool") {
|
|
3327
|
-
const out2 = blocking ? { decision: "deny", reason } : { decision: "allow" };
|
|
3591
|
+
const out2 = blocking ? { decision: "deny", reason: reason2 } : { decision: "allow" };
|
|
3328
3592
|
return { stdout: `${JSON.stringify(out2)}
|
|
3329
3593
|
`, exitCode: 0 };
|
|
3330
3594
|
}
|
|
3331
3595
|
const notes = [...decision.context ?? []];
|
|
3332
|
-
if (blocking) notes.unshift(
|
|
3596
|
+
if (blocking) notes.unshift(reason2);
|
|
3333
3597
|
if (decision.feedback) notes.push(decision.feedback);
|
|
3334
3598
|
let out = {};
|
|
3335
3599
|
if (notes.length > 0 && input.event !== "after_tool") {
|
|
@@ -3523,19 +3787,19 @@ var MAX_REASON2 = 2e3;
|
|
|
3523
3787
|
function render2(input, decision) {
|
|
3524
3788
|
const hookEventName = NATIVE_EVENTS2[input.event];
|
|
3525
3789
|
const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
|
|
3526
|
-
const
|
|
3790
|
+
const reason2 = decision.reason?.slice(0, MAX_REASON2);
|
|
3527
3791
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
3528
3792
|
const out = shape(input, decision, {
|
|
3529
3793
|
hookEventName,
|
|
3530
3794
|
context,
|
|
3531
|
-
reason,
|
|
3795
|
+
reason: reason2,
|
|
3532
3796
|
blocking
|
|
3533
3797
|
});
|
|
3534
3798
|
return { stdout: out ? `${JSON.stringify(out)}
|
|
3535
3799
|
` : "", exitCode: 0 };
|
|
3536
3800
|
}
|
|
3537
3801
|
function shape(input, decision, parts) {
|
|
3538
|
-
const { hookEventName, context, reason, blocking } = parts;
|
|
3802
|
+
const { hookEventName, context, reason: reason2, blocking } = parts;
|
|
3539
3803
|
const contextOnly = context ? { hookSpecificOutput: { hookEventName, additionalContext: context } } : {};
|
|
3540
3804
|
if (input.event === "before_tool") {
|
|
3541
3805
|
if (!blocking && !context) return null;
|
|
@@ -3543,7 +3807,7 @@ function shape(input, decision, parts) {
|
|
|
3543
3807
|
if (blocking) {
|
|
3544
3808
|
refusal = {
|
|
3545
3809
|
permissionDecision: decision.verdict,
|
|
3546
|
-
...
|
|
3810
|
+
...reason2 ? { permissionDecisionReason: reason2 } : {}
|
|
3547
3811
|
};
|
|
3548
3812
|
}
|
|
3549
3813
|
return {
|
|
@@ -3555,7 +3819,7 @@ function shape(input, decision, parts) {
|
|
|
3555
3819
|
};
|
|
3556
3820
|
}
|
|
3557
3821
|
if (input.event === "prompt" || input.event === "after_tool" || input.event === "stop") {
|
|
3558
|
-
const feedback = blocking ?
|
|
3822
|
+
const feedback = blocking ? reason2 ?? "Refused" : decision.feedback;
|
|
3559
3823
|
if (!feedback && !context) return null;
|
|
3560
3824
|
return {
|
|
3561
3825
|
...feedback ? { decision: "block", reason: feedback } : {},
|
|
@@ -3773,12 +4037,12 @@ var MAX_REASON3 = 2e3;
|
|
|
3773
4037
|
function render3(input, decision) {
|
|
3774
4038
|
const hookEventName = NATIVE_EVENTS3[input.event];
|
|
3775
4039
|
const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
|
|
3776
|
-
const
|
|
4040
|
+
const reason2 = decision.reason?.slice(0, MAX_REASON3);
|
|
3777
4041
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
3778
4042
|
const out = shape2(input, decision, {
|
|
3779
4043
|
hookEventName,
|
|
3780
4044
|
context,
|
|
3781
|
-
reason,
|
|
4045
|
+
reason: reason2,
|
|
3782
4046
|
blocking
|
|
3783
4047
|
});
|
|
3784
4048
|
if (!out && input.event === "stop") return { stdout: "{}\n", exitCode: 0 };
|
|
@@ -3786,7 +4050,7 @@ function render3(input, decision) {
|
|
|
3786
4050
|
` : "", exitCode: 0 };
|
|
3787
4051
|
}
|
|
3788
4052
|
function shape2(input, decision, parts) {
|
|
3789
|
-
const { hookEventName, context, reason, blocking } = parts;
|
|
4053
|
+
const { hookEventName, context, reason: reason2, blocking } = parts;
|
|
3790
4054
|
const contextOnly = context ? { hookSpecificOutput: { hookEventName, additionalContext: context } } : {};
|
|
3791
4055
|
if (input.event === "before_tool") {
|
|
3792
4056
|
if (!blocking && !context) return null;
|
|
@@ -3794,7 +4058,7 @@ function shape2(input, decision, parts) {
|
|
|
3794
4058
|
if (blocking) {
|
|
3795
4059
|
refusal = {
|
|
3796
4060
|
permissionDecision: "deny",
|
|
3797
|
-
...
|
|
4061
|
+
...reason2 ? { permissionDecisionReason: reason2 } : {}
|
|
3798
4062
|
};
|
|
3799
4063
|
}
|
|
3800
4064
|
return {
|
|
@@ -3806,7 +4070,7 @@ function shape2(input, decision, parts) {
|
|
|
3806
4070
|
};
|
|
3807
4071
|
}
|
|
3808
4072
|
if (input.event === "prompt" || input.event === "after_tool" || input.event === "stop") {
|
|
3809
|
-
const feedback = blocking ?
|
|
4073
|
+
const feedback = blocking ? reason2 ?? "Refused" : decision.feedback;
|
|
3810
4074
|
if (!feedback && !context) return null;
|
|
3811
4075
|
return {
|
|
3812
4076
|
...feedback ? { decision: "block", reason: feedback } : {},
|
|
@@ -4011,12 +4275,12 @@ var DELIVERS = [
|
|
|
4011
4275
|
];
|
|
4012
4276
|
function render4(input, decision) {
|
|
4013
4277
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
4014
|
-
const
|
|
4278
|
+
const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON4);
|
|
4015
4279
|
const out = {};
|
|
4016
4280
|
const notes = [...decision.context ?? []];
|
|
4017
4281
|
if (blocking && input.event === "before_tool")
|
|
4018
|
-
Object.assign(out, { decision: "deny", reason });
|
|
4019
|
-
else if (blocking) notes.unshift(
|
|
4282
|
+
Object.assign(out, { decision: "deny", reason: reason2 });
|
|
4283
|
+
else if (blocking) notes.unshift(reason2);
|
|
4020
4284
|
if (decision.feedback) notes.push(decision.feedback);
|
|
4021
4285
|
if (notes.length > 0 && DELIVERS.includes(input.event))
|
|
4022
4286
|
out["hookSpecificOutput"] = {
|
|
@@ -4200,10 +4464,10 @@ var DELIVERS2 = [
|
|
|
4200
4464
|
];
|
|
4201
4465
|
function render5(input, decision) {
|
|
4202
4466
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
4203
|
-
const
|
|
4467
|
+
const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON5);
|
|
4204
4468
|
const notes = [...decision.context ?? []];
|
|
4205
4469
|
const refuse = blocking && input.event === "before_tool";
|
|
4206
|
-
if (blocking && !refuse) notes.unshift(
|
|
4470
|
+
if (blocking && !refuse) notes.unshift(reason2);
|
|
4207
4471
|
if (decision.feedback) notes.push(decision.feedback);
|
|
4208
4472
|
const quiet = input.event === "stop" && input.stop?.active === true;
|
|
4209
4473
|
const context = notes.length > 0 && DELIVERS2.includes(input.event) && !quiet ? notes.join("\n\n") : void 0;
|
|
@@ -4211,7 +4475,7 @@ function render5(input, decision) {
|
|
|
4211
4475
|
const out = {
|
|
4212
4476
|
hookSpecificOutput: {
|
|
4213
4477
|
hookEventName: NATIVE_EVENTS5[input.event],
|
|
4214
|
-
...refuse ? { permissionDecision: "deny", permissionDecisionReason:
|
|
4478
|
+
...refuse ? { permissionDecision: "deny", permissionDecisionReason: reason2 } : {},
|
|
4215
4479
|
...context ? { additionalContext: context } : {}
|
|
4216
4480
|
}
|
|
4217
4481
|
};
|
|
@@ -4401,14 +4665,14 @@ var DELIVERS3 = [
|
|
|
4401
4665
|
];
|
|
4402
4666
|
function render6(input, decision) {
|
|
4403
4667
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
4404
|
-
const
|
|
4668
|
+
const reason2 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
|
|
4405
4669
|
if (input.event === "before_tool") {
|
|
4406
|
-
const out2 = blocking ? { deny:
|
|
4670
|
+
const out2 = blocking ? { deny: reason2 } : {};
|
|
4407
4671
|
return { stdout: `${JSON.stringify(out2)}
|
|
4408
4672
|
`, exitCode: 0 };
|
|
4409
4673
|
}
|
|
4410
4674
|
const notes = [...decision.context ?? []];
|
|
4411
|
-
if (blocking) notes.unshift(
|
|
4675
|
+
if (blocking) notes.unshift(reason2);
|
|
4412
4676
|
if (decision.feedback) notes.push(decision.feedback);
|
|
4413
4677
|
const out = notes.length > 0 && DELIVERS3.includes(input.event) ? { context: notes.join("\n\n") } : {};
|
|
4414
4678
|
return { stdout: `${JSON.stringify(out)}
|
|
@@ -4765,7 +5029,7 @@ function failedEntry(adapter, event, root, input, failure, error) {
|
|
|
4765
5029
|
}
|
|
4766
5030
|
function failClosed(adapter, event, root, error, stated = false) {
|
|
4767
5031
|
if (event !== "before_tool") return "";
|
|
4768
|
-
const
|
|
5032
|
+
const reason2 = error instanceof PolicyIntegrityError || stated && error instanceof Error ? error.message : FAILED_CLOSED;
|
|
4769
5033
|
const input = {
|
|
4770
5034
|
contract: 2,
|
|
4771
5035
|
runtime: adapter.id,
|
|
@@ -4774,7 +5038,7 @@ function failClosed(adapter, event, root, error, stated = false) {
|
|
|
4774
5038
|
cwd: root,
|
|
4775
5039
|
projectRoot: root
|
|
4776
5040
|
};
|
|
4777
|
-
return adapter.render(input, { verdict: "deny", reason }).stdout;
|
|
5041
|
+
return adapter.render(input, { verdict: "deny", reason: reason2 }).stdout;
|
|
4778
5042
|
}
|
|
4779
5043
|
|
|
4780
5044
|
// src/hooks/entry/logger.ts
|
|
@@ -5315,20 +5579,36 @@ function filesPause(dir) {
|
|
|
5315
5579
|
import { join as join19 } from "node:path";
|
|
5316
5580
|
var SESSION_ID = /^[A-Za-z0-9_-]{8,64}$/u;
|
|
5317
5581
|
function filesRegistry(dir, staleMs) {
|
|
5318
|
-
const
|
|
5319
|
-
|
|
5320
|
-
|
|
5582
|
+
const dirs = [STATE_FILES.records, STATE_FILES.legacyRecords].map(
|
|
5583
|
+
(name) => join19(dir, name)
|
|
5584
|
+
);
|
|
5585
|
+
const pathsOf = (session) => dirs.map((records) => join19(records, `${session}.json`));
|
|
5586
|
+
const get = (session) => {
|
|
5587
|
+
if (!SESSION_ID.test(session)) return null;
|
|
5588
|
+
return latestRecord(
|
|
5589
|
+
pathsOf(session).map((path) => asRecord(readJson3(path)))
|
|
5590
|
+
);
|
|
5591
|
+
};
|
|
5321
5592
|
const list = (now = Date.now()) => {
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
names2 =
|
|
5325
|
-
|
|
5326
|
-
|
|
5593
|
+
const found = /* @__PURE__ */ new Map();
|
|
5594
|
+
for (const folder of dirs) {
|
|
5595
|
+
let names2 = [];
|
|
5596
|
+
try {
|
|
5597
|
+
names2 = readdirSync(folder).filter((name) => name.endsWith(".json"));
|
|
5598
|
+
} catch {
|
|
5599
|
+
continue;
|
|
5600
|
+
}
|
|
5601
|
+
for (const name of names2)
|
|
5602
|
+
found.set(name, [
|
|
5603
|
+
...found.get(name) ?? [],
|
|
5604
|
+
asRecord(readJson3(join19(folder, name)))
|
|
5605
|
+
]);
|
|
5327
5606
|
}
|
|
5328
|
-
return
|
|
5607
|
+
return [...found.values()].map(latestRecord).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
|
|
5329
5608
|
};
|
|
5330
5609
|
const remove = (session) => {
|
|
5331
|
-
if (SESSION_ID.test(session))
|
|
5610
|
+
if (!SESSION_ID.test(session)) return;
|
|
5611
|
+
for (const path of pathsOf(session)) rmSync(path, { force: true });
|
|
5332
5612
|
};
|
|
5333
5613
|
return {
|
|
5334
5614
|
get,
|
|
@@ -5348,7 +5628,7 @@ function filesRegistry(dir, staleMs) {
|
|
|
5348
5628
|
next["worktree"] = checkout?.root ?? "";
|
|
5349
5629
|
next["branch"] = checkout?.branch ?? "";
|
|
5350
5630
|
}
|
|
5351
|
-
|
|
5631
|
+
for (const path of pathsOf(session)) writeJson(path, next);
|
|
5352
5632
|
return next;
|
|
5353
5633
|
},
|
|
5354
5634
|
sweep(now = Date.now()) {
|