@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.
- 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/{affected-IPFJM2KD.js → affected-4FILH743.js} +174 -77
- package/dist/{apply-CDJQJAZH.js → apply-HJUCYQDQ.js} +18 -15
- package/dist/{broadcast-VKZY7WSD.js → broadcast-U7ZYOJWE.js} +7 -4
- package/dist/{chunk-GEDRPMBH.js → chunk-2GL5L2G5.js} +2 -2
- package/dist/{chunk-AQM2JZMB.js → chunk-2JUHFM4V.js} +2 -2
- package/dist/{chunk-UKR64U7J.js → chunk-374AZ4J4.js} +2 -2
- package/dist/{chunk-MZ52S4YJ.js → chunk-3JOFDNL4.js} +2 -2
- package/dist/{chunk-264DIB5U.js → chunk-3KISMGVP.js} +4 -4
- package/dist/{chunk-V5PXMLLL.js → chunk-6XE3WW7S.js} +3 -3
- package/dist/{chunk-7CGGDX7X.js → chunk-7FHOSWNQ.js} +2 -2
- package/dist/{chunk-5NQZGNKT.js → chunk-7PBWLYCO.js} +3 -3
- package/dist/{chunk-2GZKA33O.js → chunk-A4P3IIPE.js} +2 -2
- package/dist/{chunk-3O3JZTUU.js → chunk-C7Y2MBCN.js} +3 -3
- package/dist/chunk-D7IDT7OA.js +21 -0
- package/dist/chunk-E272CFPS.js +14 -0
- package/dist/chunk-FLG7VRTC.js +1 -0
- package/dist/{chunk-X3RUXLAV.js → chunk-FXDGW2IH.js} +3 -3
- package/dist/{chunk-DLIO2D7S.js → chunk-GIL3RBRX.js} +27 -20
- package/dist/{chunk-ARXCYFFZ.js → chunk-GQRDEIQA.js} +22 -2
- package/dist/chunk-J43Z4O3G.js +7 -0
- package/dist/chunk-KLIYFD3W.js +32 -0
- package/dist/{chunk-PG62GOPU.js → chunk-KQV2EPAP.js} +2 -2
- package/dist/{chunk-LNKAR3IS.js → chunk-LCPCRZ7N.js} +2 -2
- package/dist/chunk-NQCAKDRY.js +156 -0
- package/dist/{chunk-3SEJNT6F.js → chunk-NQZMGQFG.js} +5 -5
- package/dist/{chunk-DGXZBQCA.js → chunk-OBCBCLS2.js} +7 -7
- package/dist/{chunk-D4FIBB2G.js → chunk-OG2ESRQP.js} +5 -5
- package/dist/{chunk-43MXRTKH.js → chunk-OHCUPXU4.js} +26 -8
- package/dist/chunk-OIKT4SYO.js +42 -0
- package/dist/{chunk-3V37OZQH.js → chunk-PAY6HEEY.js} +2 -2
- package/dist/{chunk-QY2P54Z2.js → chunk-PZ6D3WKD.js} +125 -8
- package/dist/{chunk-MOKZPZZO.js → chunk-Q5BQIRM3.js} +2 -2
- package/dist/{chunk-VYQJPT27.js → chunk-S2FUWBLO.js} +18 -4
- package/dist/{chunk-OGCJO6HQ.js → chunk-TQRLWO4F.js} +2 -2
- package/dist/{chunk-VBWB2T3C.js → chunk-UVPIVSZB.js} +14 -6
- package/dist/{chunk-MHKY6TNF.js → chunk-VN34GLGJ.js} +3 -3
- package/dist/chunk-WUFNKK3U.js +71 -0
- package/dist/{chunk-2ZH77O2D.js → chunk-Y7FYCVUK.js} +646 -103
- package/dist/{chunk-HES44LTA.js → chunk-YJVSN6UN.js} +29 -5
- package/dist/{chunk-EWYLWBKS.js → chunk-YKICVMF7.js} +22 -5
- package/dist/{cli-OV5LSSGE.js → cli-FVUHK2NB.js} +7 -7
- package/dist/{cli-GFDT4YXM.js → cli-ZOY2274X.js} +9 -9
- package/dist/cli.js +40 -6
- package/dist/{completion-QNDCU4MF.js → completion-ZKWGPMEK.js} +6 -5
- package/dist/{diagnostics-TPK3VC5F.js → diagnostics-IM2OPAPL.js} +7 -7
- package/dist/{doctor-K2LADSW2.js → doctor-VZTHEPVC.js} +32 -20
- package/dist/{entry-HFQHKL5L.js → entry-Q4EI4PNO.js} +13 -13
- package/dist/{exec-mcp-I2YGGWY4.js → exec-mcp-AWGUQVT2.js} +15 -12
- package/dist/{harness-BMWGAXCF.js → harness-L4C5XWKR.js} +3 -3
- package/dist/harness-launch-gate.js +5 -5
- package/dist/harness-worker.js +7 -7
- package/dist/{heavy-G6CYQQ7O.js → heavy-OG3UVZNY.js} +327 -131
- package/dist/hook-body.js +664 -161
- package/dist/{hook-spec-Bd24eo2L.d.ts → hook-spec-u7hnz571.d.ts} +10 -0
- package/dist/{hooks-R7AYQXHY.js → hooks-2E6PJJQK.js} +4 -4
- package/dist/{host-PLE2T55E.js → host-OQDBQJB2.js} +8 -8
- package/dist/{host-EUD6GLWV.js → host-RJJGTKWA.js} +20 -65
- package/dist/{host-run-QFNGIDL5.js → host-run-PWCIXJDN.js} +6 -6
- package/dist/http.js +1 -1
- package/dist/{import-mcp-DVKJOEOE.js → import-mcp-2H2NRUCL.js} +14 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -15
- package/dist/{init-DKWNL62M.js → init-O2UCU2WT.js} +2 -2
- package/dist/{invoke-U6JTPTXT.js → invoke-SJ3JHRJU.js} +9 -9
- package/dist/{list-YKQFJN3G.js → list-SJVXZGKK.js} +17 -14
- package/dist/{logout-5YSKC46N.js → logout-ROKXWR3T.js} +15 -12
- package/dist/{logs-2JEMSNSG.js → logs-J4W6GFMK.js} +4 -4
- package/dist/{mailbox-5FVFMQ2J.js → mailbox-6MHH6CUA.js} +22 -8
- package/dist/{mainline-D3PSR6AJ.js → mainline-SWZPKA7U.js} +19 -9
- package/dist/{mcp-CHKKXHBB.js → mcp-U7MVFAB4.js} +2 -2
- package/dist/owners-MPI22SFU.js +63 -0
- package/dist/{pause-CMZOIHTJ.js → pause-3IMVYXQQ.js} +7 -4
- package/dist/project/hook-adapter.d.ts +1 -1
- package/dist/{project-QEYXISHC.js → project-MGUYHUF7.js} +4 -4
- package/dist/{report-UB7MXAUB.js → report-MWXB5XKE.js} +5 -5
- package/dist/{resume-PAKIT4TT.js → resume-7LCSV4X3.js} +7 -4
- package/dist/{run-HKMYYEZJ.js → run-DDWLS6FY.js} +14 -11
- package/dist/{run-FYKDIW4C.js → run-TBO5JO4Y.js} +4 -4
- package/dist/{serve-QZNG5UUV.js → serve-RBQYB3FP.js} +3 -3
- package/dist/{setup-GRWLDBVB.js → setup-7JHWLV7K.js} +6 -4
- package/dist/{smoke-6X6IXQIQ.js → smoke-GZECLXOJ.js} +3 -3
- package/dist/{start-login-4GPM32RA.js → start-login-SOTNDUP6.js} +15 -12
- package/dist/{status-55CD352M.js → status-EBIUQIGY.js} +35 -30
- package/dist/{status-4PYPTYUB.js → status-QFMN7IUG.js} +8 -5
- package/dist/{status-W6SCF2GF.js → status-TSTOFNZU.js} +15 -12
- package/dist/stdio.js +2 -2
- package/dist/{sweep-VURZU6DI.js → sweep-BS7HVSNP.js} +7 -4
- package/dist/{test-XYEMYZ2P.js → test-4PZHHWOQ.js} +28 -16
- package/dist/{tui-FXSWN2PV.js → tui-QD2LMXHV.js} +4 -4
- package/dist/{unbroadcast-7AMLURCG.js → unbroadcast-GRGX3F6T.js} +7 -4
- package/dist/{worker-Q4I4EIAJ.js → worker-SPJ4HFWV.js} +11 -11
- package/dist/{worktree-list-2HV6ODBS.js → worktree-list-WZC75NLF.js} +8 -9
- package/dist/{worktree-sync-MUVKK2CV.js → worktree-sync-BQZD4J73.js} +5 -2
- package/docs/commands.md +18 -7
- package/docs/git-workflow.md +40 -5
- package/docs/glossary.md +1 -1
- package/docs/hooks.md +75 -16
- package/docs/project-configuration.md +136 -40
- package/docs/sessions.md +9 -2
- package/docs/upgrading.md +71 -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/plugin.json +1 -1
- package/dist/chunk-65H4PN33.js +0 -7
- package/dist/chunk-7TD53M7L.js +0 -13
- package/dist/chunk-FQLCD4HU.js +0 -24
package/dist/hook-body.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/hooks/entry.ts
|
|
2
|
-
import { dirname as dirname13, resolve as
|
|
2
|
+
import { dirname as dirname13, resolve as resolve22 } from "node:path";
|
|
3
3
|
|
|
4
4
|
// src/hooks/contract.ts
|
|
5
5
|
var NEUTRAL_EVENTS = [
|
|
@@ -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:
|
|
49
|
+
const { verdict: _verdict, reason: reason3, ...rest } = decision;
|
|
50
50
|
return {
|
|
51
51
|
...rest,
|
|
52
|
-
context: [...decision.context ?? [], `pmcp: ${
|
|
52
|
+
context: [...decision.context ?? [], `pmcp: ${reason3 ?? "would ask"}`]
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -256,24 +256,24 @@ function gitCommonDir(root) {
|
|
|
256
256
|
return checkoutOf(root)?.commonDir ?? null;
|
|
257
257
|
}
|
|
258
258
|
function worktreesOf(checkout) {
|
|
259
|
-
const
|
|
259
|
+
const found2 = [
|
|
260
260
|
{ path: dirname(checkout.commonDir), branch: branchOf(checkout.commonDir) }
|
|
261
261
|
];
|
|
262
262
|
let names4 = [];
|
|
263
263
|
try {
|
|
264
264
|
names4 = readdirSync(join2(checkout.commonDir, "worktrees"));
|
|
265
265
|
} catch {
|
|
266
|
-
return
|
|
266
|
+
return found2;
|
|
267
267
|
}
|
|
268
268
|
for (const name of names4) {
|
|
269
269
|
const admin = join2(checkout.commonDir, "worktrees", name);
|
|
270
270
|
try {
|
|
271
271
|
const dotGit = readFileSync(join2(admin, "gitdir"), "utf8").trim();
|
|
272
|
-
|
|
272
|
+
found2.push({ path: dirname(dotGit), branch: branchOf(admin) });
|
|
273
273
|
} catch {
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
-
return
|
|
276
|
+
return found2;
|
|
277
277
|
}
|
|
278
278
|
function hasLinkedWorktrees(checkout) {
|
|
279
279
|
try {
|
|
@@ -575,7 +575,7 @@ var Scanner = class _Scanner {
|
|
|
575
575
|
// Index just past the )) closing the (( at open, or -1 when a lone ) closes it first.
|
|
576
576
|
arithmeticEnd(open2, nested) {
|
|
577
577
|
const { text: text9 } = this;
|
|
578
|
-
const
|
|
578
|
+
const found2 = [];
|
|
579
579
|
let depth = 0;
|
|
580
580
|
let index = open2 + 2;
|
|
581
581
|
while (index < text9.length) {
|
|
@@ -586,7 +586,7 @@ var Scanner = class _Scanner {
|
|
|
586
586
|
}
|
|
587
587
|
if (text9.startsWith("$(", index) && !text9.startsWith("$((", index)) {
|
|
588
588
|
const inner = this.nested.at(text9, index + 2);
|
|
589
|
-
|
|
589
|
+
found2.push(inner.list);
|
|
590
590
|
index = inner.end;
|
|
591
591
|
continue;
|
|
592
592
|
}
|
|
@@ -594,7 +594,7 @@ var Scanner = class _Scanner {
|
|
|
594
594
|
if (char === ")") {
|
|
595
595
|
if (depth === 0) {
|
|
596
596
|
if (text9[index + 1] !== ")") return -1;
|
|
597
|
-
nested.push(...
|
|
597
|
+
nested.push(...found2);
|
|
598
598
|
return index + 2;
|
|
599
599
|
}
|
|
600
600
|
depth -= 1;
|
|
@@ -830,9 +830,9 @@ var Parser = class {
|
|
|
830
830
|
return token;
|
|
831
831
|
}
|
|
832
832
|
fail(token, expected) {
|
|
833
|
-
const
|
|
833
|
+
const found2 = describe(token);
|
|
834
834
|
throw new ShellSyntaxError(
|
|
835
|
-
expected ? `expected ${expected}, found ${
|
|
835
|
+
expected ? `expected ${expected}, found ${found2}` : `unexpected ${found2}`,
|
|
836
836
|
token.start
|
|
837
837
|
);
|
|
838
838
|
}
|
|
@@ -1098,7 +1098,7 @@ var Parser = class {
|
|
|
1098
1098
|
return redirect;
|
|
1099
1099
|
}
|
|
1100
1100
|
simple() {
|
|
1101
|
-
const
|
|
1101
|
+
const assigns2 = [];
|
|
1102
1102
|
const words = [];
|
|
1103
1103
|
const redirects = [];
|
|
1104
1104
|
let first = "";
|
|
@@ -1107,29 +1107,29 @@ var Parser = class {
|
|
|
1107
1107
|
const token = this.peek();
|
|
1108
1108
|
if (token.kind === "redirect") {
|
|
1109
1109
|
redirects.push(this.redirect());
|
|
1110
|
-
if (
|
|
1110
|
+
if (assigns2.length > 0) redirectedAfterAssign = true;
|
|
1111
1111
|
continue;
|
|
1112
1112
|
}
|
|
1113
1113
|
if (token.kind !== "word") break;
|
|
1114
1114
|
this.next();
|
|
1115
1115
|
if (words.length === 0 && ASSIGNMENT.test(token.raw)) {
|
|
1116
1116
|
if (redirectedAfterAssign && ARRAY.test(token.raw)) this.fail(token);
|
|
1117
|
-
|
|
1117
|
+
assigns2.push(token.word);
|
|
1118
1118
|
continue;
|
|
1119
1119
|
}
|
|
1120
1120
|
if (ARRAY.test(token.raw) && !DECLARES.has(first)) this.fail(token);
|
|
1121
1121
|
if (words.length === 0) first = token.raw;
|
|
1122
1122
|
words.push(token.word);
|
|
1123
1123
|
const after = this.peek();
|
|
1124
|
-
if (words.length === 1 &&
|
|
1124
|
+
if (words.length === 1 && assigns2.length === 0 && redirects.length === 0 && after.kind === "op" && after.op === "(") {
|
|
1125
1125
|
this.next();
|
|
1126
1126
|
this.op(")");
|
|
1127
1127
|
return { kind: "function", name: token.raw, body: this.functionBody() };
|
|
1128
1128
|
}
|
|
1129
1129
|
}
|
|
1130
|
-
if (
|
|
1130
|
+
if (assigns2.length + words.length + redirects.length === 0)
|
|
1131
1131
|
this.fail(this.peek());
|
|
1132
|
-
return { kind: "simple", assigns, words, redirects };
|
|
1132
|
+
return { kind: "simple", assigns: assigns2, words, redirects };
|
|
1133
1133
|
}
|
|
1134
1134
|
};
|
|
1135
1135
|
|
|
@@ -1275,8 +1275,8 @@ function changeDir(place, target) {
|
|
|
1275
1275
|
if (isAbsolute2(target) || place.dir === "") return target;
|
|
1276
1276
|
return join4(place.dir, target);
|
|
1277
1277
|
}
|
|
1278
|
-
function assign(place,
|
|
1279
|
-
for (const word of
|
|
1278
|
+
function assign(place, assigns2, exporting) {
|
|
1279
|
+
for (const word of assigns2) {
|
|
1280
1280
|
const name = /^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(word.text)?.[1];
|
|
1281
1281
|
if (!name) continue;
|
|
1282
1282
|
if (exporting) place.exported.add(name);
|
|
@@ -1477,8 +1477,8 @@ function touchesLock(words, scripts) {
|
|
|
1477
1477
|
return runsScript(words, scripts);
|
|
1478
1478
|
}
|
|
1479
1479
|
var DEFAULT_MUTATING_COMMANDS = [
|
|
1480
|
-
...[...DOCKER_MUTATING].map((
|
|
1481
|
-
...[...WRANGLER_MUTATING].map((
|
|
1480
|
+
...[...DOCKER_MUTATING].map((verb2) => ["docker", verb2]),
|
|
1481
|
+
...[...WRANGLER_MUTATING].map((verb2) => ["wrangler", verb2])
|
|
1482
1482
|
];
|
|
1483
1483
|
var DEFAULT_MUTATING_SCRIPT_NAMES = [
|
|
1484
1484
|
"^git:",
|
|
@@ -1564,8 +1564,8 @@ function withSteps(input) {
|
|
|
1564
1564
|
|
|
1565
1565
|
// src/hooks/policies/_shared.ts
|
|
1566
1566
|
var UnreadableCommand = class extends Error {
|
|
1567
|
-
constructor(
|
|
1568
|
-
super(`not shell syntax: ${
|
|
1567
|
+
constructor(reason3) {
|
|
1568
|
+
super(`not shell syntax: ${reason3}`);
|
|
1569
1569
|
}
|
|
1570
1570
|
};
|
|
1571
1571
|
function shellCall(input) {
|
|
@@ -1650,14 +1650,14 @@ async function runPolicy(selected, input, deps) {
|
|
|
1650
1650
|
now: deps.now,
|
|
1651
1651
|
...deps.policySha256 ? { policySha256: deps.policySha256 } : {}
|
|
1652
1652
|
};
|
|
1653
|
-
const
|
|
1653
|
+
const evaluate2 = () => Promise.resolve(
|
|
1654
1654
|
deps.evaluate ? deps.evaluate(selected, input, context) : policy.evaluate(input, context)
|
|
1655
1655
|
);
|
|
1656
1656
|
const tries = (deps.failure?.retry ?? 0) + 1;
|
|
1657
1657
|
let raw;
|
|
1658
1658
|
for (let attempt = 1; ; attempt += 1) {
|
|
1659
1659
|
try {
|
|
1660
|
-
raw = await within(
|
|
1660
|
+
raw = await within(evaluate2(), deps.failure?.timeoutMs);
|
|
1661
1661
|
break;
|
|
1662
1662
|
} catch (error) {
|
|
1663
1663
|
if (attempt >= tries) throw error;
|
|
@@ -1667,7 +1667,8 @@ async function runPolicy(selected, input, deps) {
|
|
|
1667
1667
|
}
|
|
1668
1668
|
}
|
|
1669
1669
|
const decision = applyMode(policy.id, raw, mode);
|
|
1670
|
-
|
|
1670
|
+
const letThrough = (raw.verdict ?? "allow") !== "allow" && decision.verdict !== "deny" && decision.verdict !== raw.verdict;
|
|
1671
|
+
log[letThrough ? "info" : "debug"]("policy", {
|
|
1671
1672
|
raw: raw.verdict ?? "allow",
|
|
1672
1673
|
mode,
|
|
1673
1674
|
verdict: decision.verdict ?? "allow",
|
|
@@ -2751,8 +2752,8 @@ function fields(input) {
|
|
|
2751
2752
|
return { ...cwd, status: "working", waiting: "" };
|
|
2752
2753
|
if (input.event === "after_tool") return { ...cwd, status: "working" };
|
|
2753
2754
|
if (input.event === "notification") {
|
|
2754
|
-
const
|
|
2755
|
-
return { status: "waiting", waiting:
|
|
2755
|
+
const reason3 = input.notification?.type || input.notification?.message;
|
|
2756
|
+
return { status: "waiting", waiting: reason3 ?? "" };
|
|
2756
2757
|
}
|
|
2757
2758
|
if (input.event === "stop") {
|
|
2758
2759
|
return {
|
|
@@ -2894,13 +2895,13 @@ function composeArgs(argv) {
|
|
|
2894
2895
|
function teardownReason(argv) {
|
|
2895
2896
|
const args = composeArgs(argv);
|
|
2896
2897
|
if (!args) return null;
|
|
2897
|
-
const { value:
|
|
2898
|
-
if (
|
|
2898
|
+
const { value: verb2, rest } = firstArgument(args, GLOBAL_VALUE_FLAGS);
|
|
2899
|
+
if (verb2 === "down") {
|
|
2899
2900
|
return "docker compose down takes no service argument: it tears down every container and network in the project, including ones this task never touched.";
|
|
2900
2901
|
}
|
|
2901
|
-
if (!
|
|
2902
|
-
if (firstArgument(rest, VERB_VALUE_FLAGS[
|
|
2903
|
-
return `docker compose ${
|
|
2902
|
+
if (!verb2 || !SCOPED_VERBS.has(verb2)) return null;
|
|
2903
|
+
if (firstArgument(rest, VERB_VALUE_FLAGS[verb2]).value) return null;
|
|
2904
|
+
return `docker compose ${verb2} with no service named applies to every service in the project. Name the service you mean.`;
|
|
2904
2905
|
}
|
|
2905
2906
|
var composeTeardown = {
|
|
2906
2907
|
id: "shell.compose_teardown",
|
|
@@ -2913,8 +2914,8 @@ var composeTeardown = {
|
|
|
2913
2914
|
const call = shellCall(input);
|
|
2914
2915
|
if (!call) return pass;
|
|
2915
2916
|
for (const step of realSteps(call.steps)) {
|
|
2916
|
-
const
|
|
2917
|
-
if (
|
|
2917
|
+
const reason3 = teardownReason(step.argv);
|
|
2918
|
+
if (reason3) return { verdict: "deny", reason: reason3 };
|
|
2918
2919
|
}
|
|
2919
2920
|
return pass;
|
|
2920
2921
|
}
|
|
@@ -3355,12 +3356,12 @@ function runsVerb(argv, commands) {
|
|
|
3355
3356
|
if (program(word) !== entry.binary) return false;
|
|
3356
3357
|
const end = argv.indexOf("--", at + 1);
|
|
3357
3358
|
const args = argv.slice(at + 1, end < 0 ? void 0 : end);
|
|
3358
|
-
return entry.verbs.some((
|
|
3359
|
+
return entry.verbs.some((verb2) => {
|
|
3359
3360
|
let from = 0;
|
|
3360
|
-
for (const part of
|
|
3361
|
-
const
|
|
3362
|
-
if (
|
|
3363
|
-
from =
|
|
3361
|
+
for (const part of verb2) {
|
|
3362
|
+
const found2 = args.indexOf(part, from);
|
|
3363
|
+
if (found2 < 0) return false;
|
|
3364
|
+
from = found2 + 1;
|
|
3364
3365
|
}
|
|
3365
3366
|
return true;
|
|
3366
3367
|
});
|
|
@@ -3412,7 +3413,7 @@ function severity(steps, options2) {
|
|
|
3412
3413
|
return wire ? "exfil" : "read";
|
|
3413
3414
|
}
|
|
3414
3415
|
function verbsOf(table, key) {
|
|
3415
|
-
return (stringList(table, key) ?? []).map((
|
|
3416
|
+
return (stringList(table, key) ?? []).map((verb2) => verb2.split(/\s+/u));
|
|
3416
3417
|
}
|
|
3417
3418
|
function commandTables(raw) {
|
|
3418
3419
|
if (raw === void 0) return { value: [], publish: [] };
|
|
@@ -3452,14 +3453,14 @@ var secretExfiltration = {
|
|
|
3452
3453
|
evaluate(input, ctx) {
|
|
3453
3454
|
const call = shellCall(input);
|
|
3454
3455
|
if (!call) return pass;
|
|
3455
|
-
const
|
|
3456
|
-
if (
|
|
3456
|
+
const found2 = severity(call.steps, ctx.options);
|
|
3457
|
+
if (found2 === "exfil") {
|
|
3457
3458
|
return {
|
|
3458
3459
|
verdict: "deny",
|
|
3459
3460
|
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."
|
|
3460
3461
|
};
|
|
3461
3462
|
}
|
|
3462
|
-
if (
|
|
3463
|
+
if (found2 === "read") {
|
|
3463
3464
|
return {
|
|
3464
3465
|
verdict: "ask",
|
|
3465
3466
|
reason: `This prints credential values to stdout, where they enter the transcript and every log that carries it. ${NO_VALUES}`
|
|
@@ -3469,6 +3470,103 @@ var secretExfiltration = {
|
|
|
3469
3470
|
}
|
|
3470
3471
|
};
|
|
3471
3472
|
|
|
3473
|
+
// src/hooks/policies/shell/self-matching-wait.ts
|
|
3474
|
+
var MENTIONS = /\b(?:pgrep|pkill|pidwait|ps)\b/u;
|
|
3475
|
+
var LOOPS = /* @__PURE__ */ new Set(["while", "until", "for", "select"]);
|
|
3476
|
+
var FULL_MATCHERS = /* @__PURE__ */ new Set(["pgrep", "pkill", "pidwait"]);
|
|
3477
|
+
var GREPS2 = /* @__PURE__ */ new Set(["grep", "egrep", "fgrep", "rg"]);
|
|
3478
|
+
var MAX_DEPTH2 = 4;
|
|
3479
|
+
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>.`;
|
|
3480
|
+
function fullMatch(argv) {
|
|
3481
|
+
return argv.slice(1).some(
|
|
3482
|
+
(arg) => arg === "--full" || /^-[a-zA-Z]+$/u.test(arg) && arg.includes("f")
|
|
3483
|
+
);
|
|
3484
|
+
}
|
|
3485
|
+
function psBySelection(argv) {
|
|
3486
|
+
return argv.slice(1).some(
|
|
3487
|
+
(arg) => /^-[a-zA-Z]*[pqC]/u.test(arg) || /^--(?:pid|quick-pid)(?:=|$)/u.test(arg)
|
|
3488
|
+
);
|
|
3489
|
+
}
|
|
3490
|
+
function argvOf(command6) {
|
|
3491
|
+
if (command6.kind !== "simple") return null;
|
|
3492
|
+
return unwrap(command6.words.map((word) => word.text)).words;
|
|
3493
|
+
}
|
|
3494
|
+
function pipeProbe(commands) {
|
|
3495
|
+
const argvs = commands.map(argvOf);
|
|
3496
|
+
const ps = argvs.findIndex(
|
|
3497
|
+
(argv) => argv && program(argv[0]) === "ps" && !psBySelection(argv)
|
|
3498
|
+
);
|
|
3499
|
+
if (ps < 0) return null;
|
|
3500
|
+
const grep = argvs.slice(ps + 1).some((argv) => argv && GREPS2.has(program(argv[0])));
|
|
3501
|
+
return grep ? "ps | grep" : null;
|
|
3502
|
+
}
|
|
3503
|
+
var Finder = class {
|
|
3504
|
+
probe = null;
|
|
3505
|
+
list(list, looping, depth) {
|
|
3506
|
+
for (const item of list)
|
|
3507
|
+
for (const pipeline of item.pipelines) {
|
|
3508
|
+
if (looping) this.probe ??= pipeProbe(pipeline.commands);
|
|
3509
|
+
for (const command6 of pipeline.commands)
|
|
3510
|
+
this.command(command6, looping, depth);
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
words(words, looping, depth) {
|
|
3514
|
+
for (const word of words)
|
|
3515
|
+
for (const nested of word.nested) this.list(nested, looping, depth);
|
|
3516
|
+
}
|
|
3517
|
+
command(command6, looping, depth) {
|
|
3518
|
+
switch (command6.kind) {
|
|
3519
|
+
case "simple":
|
|
3520
|
+
this.words([...command6.assigns, ...command6.words], looping, depth);
|
|
3521
|
+
this.simple(command6, looping, depth);
|
|
3522
|
+
return;
|
|
3523
|
+
case "group":
|
|
3524
|
+
case "subshell":
|
|
3525
|
+
this.list(command6.body, looping, depth);
|
|
3526
|
+
return;
|
|
3527
|
+
case "compound": {
|
|
3528
|
+
this.words(command6.words, looping, depth);
|
|
3529
|
+
const loop = looping || LOOPS.has(command6.keyword);
|
|
3530
|
+
for (const part of command6.parts) this.list(part, loop, depth);
|
|
3531
|
+
return;
|
|
3532
|
+
}
|
|
3533
|
+
case "function":
|
|
3534
|
+
this.command(command6.body, looping, depth);
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
simple(command6, looping, depth) {
|
|
3538
|
+
const argv = argvOf(command6) ?? [];
|
|
3539
|
+
const name = program(argv[0]);
|
|
3540
|
+
if (looping && FULL_MATCHERS.has(name) && fullMatch(argv))
|
|
3541
|
+
this.probe ??= `${name} -f`;
|
|
3542
|
+
const at = SHELLS.has(name) ? argv.findIndex((word) => /^-[a-z]*c$/u.test(word)) : -1;
|
|
3543
|
+
if ((at > 0 || name === "eval") && depth < MAX_DEPTH2) {
|
|
3544
|
+
const source = name === "eval" ? argv.slice(1).join(" ") : argv[at + 1] ?? "";
|
|
3545
|
+
try {
|
|
3546
|
+
this.list(parseScript(source), looping, depth + 1);
|
|
3547
|
+
} catch (error) {
|
|
3548
|
+
if (!(error instanceof ShellSyntaxError)) throw error;
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
};
|
|
3553
|
+
var selfMatchingWait = {
|
|
3554
|
+
id: "shell.self_matching_wait",
|
|
3555
|
+
events: ["before_tool"],
|
|
3556
|
+
tools: ["shell"],
|
|
3557
|
+
fail: "closed",
|
|
3558
|
+
defaultMode: "observe",
|
|
3559
|
+
options: noOptions,
|
|
3560
|
+
evaluate(input) {
|
|
3561
|
+
if (!MENTIONS.test(input.tool?.command ?? "")) return pass;
|
|
3562
|
+
const call = shellCall(input);
|
|
3563
|
+
if (!call) return pass;
|
|
3564
|
+
const finder = new Finder();
|
|
3565
|
+
finder.list(parseScript(call.command), false, 0);
|
|
3566
|
+
return finder.probe ? { verdict: "deny", reason: reason2(finder.probe) } : pass;
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
|
|
3472
3570
|
// src/hooks/policies/shell/stdin-interpreter.ts
|
|
3473
3571
|
var PYTHON = /^i?python[23]?(\.\d+)?$/u;
|
|
3474
3572
|
var REASON7 = "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.";
|
|
@@ -3965,14 +4063,14 @@ function reportModes(report2, fixed) {
|
|
|
3965
4063
|
import { dirname as dirname6, join as join8 } from "node:path";
|
|
3966
4064
|
function lockHash(root, paths) {
|
|
3967
4065
|
const hash = createHash("sha256");
|
|
3968
|
-
let
|
|
4066
|
+
let found2 = false;
|
|
3969
4067
|
for (const path of paths) {
|
|
3970
4068
|
const file2 = join8(root, path);
|
|
3971
4069
|
if (!existsSync(file2)) continue;
|
|
3972
|
-
|
|
4070
|
+
found2 = true;
|
|
3973
4071
|
hash.update(`${path}\0`).update(readFileSync(file2));
|
|
3974
4072
|
}
|
|
3975
|
-
if (!
|
|
4073
|
+
if (!found2) return null;
|
|
3976
4074
|
return hash.digest("hex");
|
|
3977
4075
|
}
|
|
3978
4076
|
function installedHash(root, spec) {
|
|
@@ -4095,7 +4193,27 @@ function distance(cwd, upstream) {
|
|
|
4095
4193
|
}
|
|
4096
4194
|
|
|
4097
4195
|
// src/git/added-submodules.ts
|
|
4098
|
-
import { dirname as dirname7, join as
|
|
4196
|
+
import { dirname as dirname7, join as join11 } from "node:path";
|
|
4197
|
+
|
|
4198
|
+
// src/sessions/state-dir.ts
|
|
4199
|
+
import { homedir as homedir3 } from "node:os";
|
|
4200
|
+
import { join as join10 } from "node:path";
|
|
4201
|
+
function stateHome(env) {
|
|
4202
|
+
return env["XDG_STATE_HOME"] || join10(homedir3(), ".local", "state");
|
|
4203
|
+
}
|
|
4204
|
+
function projectStateId(root) {
|
|
4205
|
+
const anchor = gitCommonDir(root) ?? realpathSync(root);
|
|
4206
|
+
return createHash("sha256").update(anchor).digest("hex").slice(0, 16);
|
|
4207
|
+
}
|
|
4208
|
+
function projectStateDir(root, override, env = process.env) {
|
|
4209
|
+
if (override) return expandPath(root, override);
|
|
4210
|
+
return join10(stateHome(env), "pmcp", "projects", projectStateId(root));
|
|
4211
|
+
}
|
|
4212
|
+
function displacedDir(root, env = process.env) {
|
|
4213
|
+
return join10(stateHome(env), "pmcp", "displaced", projectStateId(root));
|
|
4214
|
+
}
|
|
4215
|
+
|
|
4216
|
+
// src/git/added-submodules.ts
|
|
4099
4217
|
var ADDED_GITLINK = /^:\d{6} 160000 [0-9a-f]{40} ([0-9a-f]{40}) [AT]\t(.+)$/u;
|
|
4100
4218
|
function initAddedSubmodules(root, from, to) {
|
|
4101
4219
|
const raw = gitText(root, [
|
|
@@ -4116,8 +4234,8 @@ function initAddedSubmodules(root, from, to) {
|
|
|
4116
4234
|
return lines;
|
|
4117
4235
|
}
|
|
4118
4236
|
function initOne(root, path, pin, from) {
|
|
4119
|
-
const dir =
|
|
4120
|
-
if (existsSync(
|
|
4237
|
+
const dir = join11(root, path);
|
|
4238
|
+
if (existsSync(join11(dir, ".git"))) return followLeftCheckout(root, path, pin);
|
|
4121
4239
|
let displaced = "";
|
|
4122
4240
|
if (existsSync(dir) && readdirSync(dir).length > 0) {
|
|
4123
4241
|
if (unignoredFiles(root, path, from).length > 0)
|
|
@@ -4131,7 +4249,7 @@ function initOne(root, path, pin, from) {
|
|
|
4131
4249
|
return `new submodule checked out at ${pin.slice(0, 10)}${aside}`;
|
|
4132
4250
|
}
|
|
4133
4251
|
function followLeftCheckout(root, path, pin) {
|
|
4134
|
-
const dir =
|
|
4252
|
+
const dir = join11(root, path);
|
|
4135
4253
|
const head = git(dir, ["rev-parse", "HEAD"]);
|
|
4136
4254
|
if (head.status === 0 && head.stdout.trim() === pin)
|
|
4137
4255
|
return "already checked out";
|
|
@@ -4151,7 +4269,7 @@ function unignoredFiles(root, path, from) {
|
|
|
4151
4269
|
let level = [path];
|
|
4152
4270
|
while (level.length > 0) {
|
|
4153
4271
|
const entries = level.flatMap(
|
|
4154
|
-
(dir) => readdirSync(
|
|
4272
|
+
(dir) => readdirSync(join11(root, dir), { withFileTypes: true }).map((entry) => ({
|
|
4155
4273
|
path: `${dir}/${entry.name}`,
|
|
4156
4274
|
dir: entry.isDirectory()
|
|
4157
4275
|
}))
|
|
@@ -4171,7 +4289,7 @@ function unignoredFiles(root, path, from) {
|
|
|
4171
4289
|
level = open2.filter((entry) => entry.dir).map((entry) => entry.path);
|
|
4172
4290
|
}
|
|
4173
4291
|
} finally {
|
|
4174
|
-
for (const file2 of restored) rmSync(
|
|
4292
|
+
for (const file2 of restored) rmSync(join11(root, file2));
|
|
4175
4293
|
}
|
|
4176
4294
|
return kept;
|
|
4177
4295
|
}
|
|
@@ -4189,7 +4307,7 @@ function restoreIgnoreFiles(root, path, from) {
|
|
|
4189
4307
|
const restored = [];
|
|
4190
4308
|
for (const file2 of listed.stdout.split("\0")) {
|
|
4191
4309
|
if (!file2.endsWith("/.gitignore")) continue;
|
|
4192
|
-
const target =
|
|
4310
|
+
const target = join11(root, file2);
|
|
4193
4311
|
if (existsSync(target) || !existsSync(dirname7(target))) continue;
|
|
4194
4312
|
const body = git(root, ["show", `${from}:${file2}`]);
|
|
4195
4313
|
if (body.status !== 0) continue;
|
|
@@ -4199,16 +4317,26 @@ function restoreIgnoreFiles(root, path, from) {
|
|
|
4199
4317
|
return restored;
|
|
4200
4318
|
}
|
|
4201
4319
|
function displace(root, path) {
|
|
4202
|
-
const gitDir = gitText(root, ["rev-parse", "--absolute-git-dir"]);
|
|
4203
4320
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/gu, "-");
|
|
4204
|
-
const target =
|
|
4321
|
+
const target = join11(displacedDir(root), stamp, path);
|
|
4205
4322
|
mkdirSync(dirname7(target), { recursive: true });
|
|
4206
|
-
|
|
4323
|
+
const source = join11(root, path);
|
|
4324
|
+
try {
|
|
4325
|
+
renameSync(source, target);
|
|
4326
|
+
} catch (error) {
|
|
4327
|
+
if (error.code !== "EXDEV") throw error;
|
|
4328
|
+
cpSync(source, target, {
|
|
4329
|
+
recursive: true,
|
|
4330
|
+
verbatimSymlinks: true,
|
|
4331
|
+
preserveTimestamps: true
|
|
4332
|
+
});
|
|
4333
|
+
rmSync(source, { recursive: true, force: true });
|
|
4334
|
+
}
|
|
4207
4335
|
return target;
|
|
4208
4336
|
}
|
|
4209
4337
|
|
|
4210
4338
|
// src/git/submodules.ts
|
|
4211
|
-
import { join as
|
|
4339
|
+
import { join as join12 } from "node:path";
|
|
4212
4340
|
function clean(dir) {
|
|
4213
4341
|
return git(dir, ["status", "--porcelain"]).stdout.trim() === "";
|
|
4214
4342
|
}
|
|
@@ -4218,8 +4346,8 @@ function hasCommit(dir, sha) {
|
|
|
4218
4346
|
function movableSubmodules(root) {
|
|
4219
4347
|
const listed = git(root, ["submodule", "status"]).stdout;
|
|
4220
4348
|
return listed.split("\n").filter((line) => /^[ +]/u.test(line)).map((line) => line.trim().split(/\s+/u)[1] ?? "").filter((path) => {
|
|
4221
|
-
const dir =
|
|
4222
|
-
if (!path || !existsSync(
|
|
4349
|
+
const dir = join12(root, path);
|
|
4350
|
+
if (!path || !existsSync(join12(dir, ".git"))) return false;
|
|
4223
4351
|
const local = gitText(dir, [
|
|
4224
4352
|
"rev-list",
|
|
4225
4353
|
"--count",
|
|
@@ -4234,7 +4362,7 @@ function updateToPins(root, paths) {
|
|
|
4234
4362
|
const lines = [];
|
|
4235
4363
|
for (const path of paths) {
|
|
4236
4364
|
const pin = gitText(root, ["rev-parse", `HEAD:${path}`]);
|
|
4237
|
-
const dir =
|
|
4365
|
+
const dir = join12(root, path);
|
|
4238
4366
|
if (!pin || !hasCommit(dir, pin)) {
|
|
4239
4367
|
lines.push(
|
|
4240
4368
|
`${path}: left alone, ${pin.slice(0, 10) || "its pin"} is not in its checkout`
|
|
@@ -4429,14 +4557,137 @@ var worktreeSync = {
|
|
|
4429
4557
|
if (input.event === "prompt" && opts.betweenPrompts === "off") return pass;
|
|
4430
4558
|
const git2 = desk(input, opts);
|
|
4431
4559
|
if (!git2) return pass;
|
|
4432
|
-
const
|
|
4433
|
-
if (
|
|
4434
|
-
return input.event === "session_start" ? { context: [`Worktree ${git2.root} was not moved: ${
|
|
4560
|
+
const reason3 = blocked2(input, ctx);
|
|
4561
|
+
if (reason3)
|
|
4562
|
+
return input.event === "session_start" ? { context: [`Worktree ${git2.root} was not moved: ${reason3}.`] } : pass;
|
|
4435
4563
|
const lines = move2(input, ctx, git2);
|
|
4436
4564
|
return lines.length > 0 ? { context: lines } : pass;
|
|
4437
4565
|
}
|
|
4438
4566
|
};
|
|
4439
4567
|
|
|
4568
|
+
// src/hooks/policies/workspace/owners.ts
|
|
4569
|
+
import { isAbsolute as isAbsolute7, relative as relative7, resolve as resolve12 } from "node:path";
|
|
4570
|
+
|
|
4571
|
+
// src/hooks/glob.ts
|
|
4572
|
+
function globPattern(glob2, below = true) {
|
|
4573
|
+
let source = "";
|
|
4574
|
+
for (let at = 0; at < glob2.length; at += 1) {
|
|
4575
|
+
const char = glob2[at];
|
|
4576
|
+
if (char === "*" && glob2[at + 1] === "*") {
|
|
4577
|
+
const slash = glob2[at + 2] === "/";
|
|
4578
|
+
source += slash ? "(?:.*/)?" : ".*";
|
|
4579
|
+
at += slash ? 2 : 1;
|
|
4580
|
+
} else if (char === "*") source += "[^/]*";
|
|
4581
|
+
else if (char === "?") source += "[^/]";
|
|
4582
|
+
else source += char.replace(/[.+^${}()|[\]\\]/gu, "\\$&");
|
|
4583
|
+
}
|
|
4584
|
+
return new RegExp(`^${source}${below ? "(?:/.*)?" : ""}$`, "u");
|
|
4585
|
+
}
|
|
4586
|
+
|
|
4587
|
+
// src/hooks/owners.ts
|
|
4588
|
+
var FIELDS = ["paths", "owner", "note", "mode"];
|
|
4589
|
+
function readEntry(value, at) {
|
|
4590
|
+
const where = `[[owners]] entry ${at + 1}`;
|
|
4591
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
4592
|
+
throw new Error(`${where} must be a table`);
|
|
4593
|
+
const entry = value;
|
|
4594
|
+
const unknown = Object.keys(entry).find((key) => !FIELDS.includes(key));
|
|
4595
|
+
if (unknown) throw new Error(`${where}: unknown key ${unknown}`);
|
|
4596
|
+
const paths = entry["paths"];
|
|
4597
|
+
if (!Array.isArray(paths) || paths.length === 0 || !paths.every(
|
|
4598
|
+
(glob2) => typeof glob2 === "string" && glob2 !== "" && !glob2.startsWith("/") && !glob2.split("/").includes("..")
|
|
4599
|
+
))
|
|
4600
|
+
throw new Error(
|
|
4601
|
+
`${where}: paths must be a nonempty list of globs inside the project`
|
|
4602
|
+
);
|
|
4603
|
+
const owner2 = entry["owner"];
|
|
4604
|
+
if (typeof owner2 !== "string" || owner2.trim() === "")
|
|
4605
|
+
throw new Error(`${where}: owner must be a name`);
|
|
4606
|
+
const note = entry["note"];
|
|
4607
|
+
if (note !== void 0 && typeof note !== "string")
|
|
4608
|
+
throw new Error(`${where}: note must be a string`);
|
|
4609
|
+
const mode = entry["mode"] ?? "warn";
|
|
4610
|
+
if (mode !== "warn" && mode !== "observe")
|
|
4611
|
+
throw new Error(`${where}: mode must be warn or observe`);
|
|
4612
|
+
return {
|
|
4613
|
+
paths,
|
|
4614
|
+
owner: owner2,
|
|
4615
|
+
...note !== void 0 && note !== "" ? { note } : {},
|
|
4616
|
+
mode
|
|
4617
|
+
};
|
|
4618
|
+
}
|
|
4619
|
+
function readOwners(value) {
|
|
4620
|
+
if (value === void 0) return [];
|
|
4621
|
+
if (!Array.isArray(value))
|
|
4622
|
+
throw new Error("[[owners]] must be an array of tables");
|
|
4623
|
+
return value.map(readEntry);
|
|
4624
|
+
}
|
|
4625
|
+
function ownersOf(entries, path) {
|
|
4626
|
+
return entries.filter(
|
|
4627
|
+
(entry) => entry.paths.some((glob2) => globPattern(glob2).test(path))
|
|
4628
|
+
);
|
|
4629
|
+
}
|
|
4630
|
+
function ownerLine(entry, path) {
|
|
4631
|
+
return `${path} belongs to ${entry.owner}${entry.note ? `: ${entry.note}` : ""}`;
|
|
4632
|
+
}
|
|
4633
|
+
|
|
4634
|
+
// src/hooks/policies/workspace/owners.ts
|
|
4635
|
+
function projectPaths(input) {
|
|
4636
|
+
const found2 = [];
|
|
4637
|
+
for (const path of input.tool?.paths ?? []) {
|
|
4638
|
+
const rest = relative7(input.projectRoot, resolve12(input.cwd, path));
|
|
4639
|
+
if (rest === "" || rest.startsWith("..") || isAbsolute7(rest)) continue;
|
|
4640
|
+
found2.push(rest.split("\\").join("/"));
|
|
4641
|
+
}
|
|
4642
|
+
return found2;
|
|
4643
|
+
}
|
|
4644
|
+
function noticed(input, ctx) {
|
|
4645
|
+
try {
|
|
4646
|
+
const raw = ctx.store.registry.get(input.session.id)?.["owners"];
|
|
4647
|
+
return Array.isArray(raw) ? raw.filter((x) => typeof x === "string") : [];
|
|
4648
|
+
} catch {
|
|
4649
|
+
return [];
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
function remember(input, ctx, owners2) {
|
|
4653
|
+
try {
|
|
4654
|
+
ctx.store.registry.upsert(input.session.id, { owners: [...owners2] });
|
|
4655
|
+
} catch (error) {
|
|
4656
|
+
ctx.log.error("owners notice not recorded", {
|
|
4657
|
+
error: error instanceof Error ? error.message : String(error)
|
|
4658
|
+
});
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
var owners = {
|
|
4662
|
+
id: "owners",
|
|
4663
|
+
events: ["after_tool"],
|
|
4664
|
+
tools: ["edit"],
|
|
4665
|
+
fail: "open",
|
|
4666
|
+
defaultMode: "warn",
|
|
4667
|
+
options(raw) {
|
|
4668
|
+
onlyKeys(raw, ["entries"]);
|
|
4669
|
+
return { entries: readOwners(raw["entries"]) };
|
|
4670
|
+
},
|
|
4671
|
+
evaluate(input, ctx) {
|
|
4672
|
+
const seen = noticed(input, ctx);
|
|
4673
|
+
const lines = [];
|
|
4674
|
+
const told = new Set(seen);
|
|
4675
|
+
for (const path of projectPaths(input))
|
|
4676
|
+
for (const entry of ownersOf(ctx.options.entries, path)) {
|
|
4677
|
+
if (entry.mode === "observe") {
|
|
4678
|
+
ctx.log.info("owned path edited", { owner: entry.owner });
|
|
4679
|
+
continue;
|
|
4680
|
+
}
|
|
4681
|
+
if (told.has(entry.owner)) continue;
|
|
4682
|
+
told.add(entry.owner);
|
|
4683
|
+
lines.push(`pmcp owners: ${ownerLine(entry, path)}`);
|
|
4684
|
+
}
|
|
4685
|
+
if (lines.length === 0) return pass;
|
|
4686
|
+
remember(input, ctx, [...told]);
|
|
4687
|
+
return { context: lines };
|
|
4688
|
+
}
|
|
4689
|
+
};
|
|
4690
|
+
|
|
4440
4691
|
// src/hooks/policies/host/lease.ts
|
|
4441
4692
|
function argvList2(value) {
|
|
4442
4693
|
const valid = Array.isArray(value) && value.every(
|
|
@@ -4478,8 +4729,77 @@ var hostLease = {
|
|
|
4478
4729
|
}
|
|
4479
4730
|
};
|
|
4480
4731
|
|
|
4732
|
+
// src/hooks/policies/pmcp/operator-verbs.ts
|
|
4733
|
+
var GLOBAL = /* @__PURE__ */ new Set(["-q", "--quiet", "--color", "--no-color"]);
|
|
4734
|
+
var VARIABLES = ["PMCP_HEAVY_NOW", "PMCP_OPERATOR_TOKEN"];
|
|
4735
|
+
var OPERATOR_SKIP = "PMCP_HEAVY_DISABLE=operator";
|
|
4736
|
+
function launcher(word) {
|
|
4737
|
+
const name = program(word);
|
|
4738
|
+
return name === "pmcp" || name === "cli.js" || /^@modootoday\/pmcp(@|$)/u.test(word);
|
|
4739
|
+
}
|
|
4740
|
+
var RUNNERS2 = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx", "node", "bun", "pnpm", "yarn"]);
|
|
4741
|
+
function pmcpWords(argv) {
|
|
4742
|
+
const reach = RUNNERS2.has(program(argv[0])) ? 4 : 1;
|
|
4743
|
+
const at = argv.slice(0, reach).findIndex(launcher);
|
|
4744
|
+
if (at < 0) return null;
|
|
4745
|
+
const words = argv.slice(at + 1).filter((word) => !GLOBAL.has(word));
|
|
4746
|
+
const cut = words.indexOf("--");
|
|
4747
|
+
return cut < 0 ? words : words.slice(0, cut);
|
|
4748
|
+
}
|
|
4749
|
+
function verb(words) {
|
|
4750
|
+
const [group, sub] = words;
|
|
4751
|
+
const has = (flag2) => words.includes(flag2);
|
|
4752
|
+
if (group === "sessions" && (sub === "pause" || sub === "resume"))
|
|
4753
|
+
return `pmcp sessions ${sub}`;
|
|
4754
|
+
if (group === "heavy" && sub === "promote" && has("--now"))
|
|
4755
|
+
return "pmcp heavy promote --now";
|
|
4756
|
+
if (group === "heavy" && has("--now")) return "pmcp heavy --now";
|
|
4757
|
+
if (group === "heavy" && sub === "cancel" && has("--force"))
|
|
4758
|
+
return "pmcp heavy cancel --force";
|
|
4759
|
+
if (group === "git" && sub === "deliver" && has("--during-pause"))
|
|
4760
|
+
return "pmcp git deliver --during-pause";
|
|
4761
|
+
return null;
|
|
4762
|
+
}
|
|
4763
|
+
function assigns(step) {
|
|
4764
|
+
const name = step.assigned.find((entry) => VARIABLES.includes(entry));
|
|
4765
|
+
if (name) return name;
|
|
4766
|
+
if (program(step.argv[0]) !== "export") return null;
|
|
4767
|
+
return VARIABLES.find(
|
|
4768
|
+
(variable) => step.argv.some((word) => word.split("=")[0] === variable)
|
|
4769
|
+
) ?? null;
|
|
4770
|
+
}
|
|
4771
|
+
function found(step) {
|
|
4772
|
+
const variable = assigns(step);
|
|
4773
|
+
if (variable) return `setting ${variable}`;
|
|
4774
|
+
const skips = step.assigned.includes("PMCP_HEAVY_DISABLE") && step.raw.includes(OPERATOR_SKIP) || program(step.argv[0]) === "export" && step.argv.includes(OPERATOR_SKIP);
|
|
4775
|
+
if (skips) return `the lease skip ${OPERATOR_SKIP}`;
|
|
4776
|
+
const words = pmcpWords(step.argv);
|
|
4777
|
+
return words ? verb(words) : null;
|
|
4778
|
+
}
|
|
4779
|
+
var operatorVerbs = {
|
|
4780
|
+
id: "pmcp.operator_verbs",
|
|
4781
|
+
events: ["before_tool"],
|
|
4782
|
+
tools: ["shell"],
|
|
4783
|
+
fail: "closed",
|
|
4784
|
+
defaultMode: "deny",
|
|
4785
|
+
options: noOptions,
|
|
4786
|
+
evaluate(input) {
|
|
4787
|
+
const call = shellCall(input);
|
|
4788
|
+
if (!call) return pass;
|
|
4789
|
+
for (const step of call.steps) {
|
|
4790
|
+
const what = found(step);
|
|
4791
|
+
if (what)
|
|
4792
|
+
return {
|
|
4793
|
+
verdict: "deny",
|
|
4794
|
+
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.`
|
|
4795
|
+
};
|
|
4796
|
+
}
|
|
4797
|
+
return pass;
|
|
4798
|
+
}
|
|
4799
|
+
};
|
|
4800
|
+
|
|
4481
4801
|
// src/hooks/policies/custom.ts
|
|
4482
|
-
import { isAbsolute as
|
|
4802
|
+
import { isAbsolute as isAbsolute8, relative as relative8, resolve as resolve13 } from "node:path";
|
|
4483
4803
|
var FAILED = "Guard failed validation or execution";
|
|
4484
4804
|
var GUARD_PROTOCOL = "pmcp.guard.v1";
|
|
4485
4805
|
var MAX_FINDINGS = 20;
|
|
@@ -4496,8 +4816,8 @@ function customMode(entry) {
|
|
|
4496
4816
|
return entry.event === "session_start" && (mode === "deny" || mode === "ask") ? "warn" : mode;
|
|
4497
4817
|
}
|
|
4498
4818
|
function inside(base, path) {
|
|
4499
|
-
const rest =
|
|
4500
|
-
return rest !== "" && !rest.startsWith("..") && !
|
|
4819
|
+
const rest = relative8(base, path);
|
|
4820
|
+
return rest !== "" && !rest.startsWith("..") && !isAbsolute8(rest);
|
|
4501
4821
|
}
|
|
4502
4822
|
function guardScript(root, command6) {
|
|
4503
4823
|
const script = command6[0]?.startsWith(".agents/guards/") ? command6[0] : command6[1];
|
|
@@ -4506,12 +4826,12 @@ function guardScript(root, command6) {
|
|
|
4506
4826
|
"Hook command must execute a script under .agents/guards/, or name an installed program with version"
|
|
4507
4827
|
);
|
|
4508
4828
|
}
|
|
4509
|
-
const base =
|
|
4510
|
-
if (!inside(base,
|
|
4829
|
+
const base = resolve13(root, ".agents/guards");
|
|
4830
|
+
if (!inside(base, resolve13(root, script)))
|
|
4511
4831
|
throw new Error("Hook guard must stay under .agents/guards/");
|
|
4512
|
-
if (!existsSync(
|
|
4832
|
+
if (!existsSync(resolve13(root, script)))
|
|
4513
4833
|
throw new Error("Hook guard script must exist");
|
|
4514
|
-
const real4 = realpathSync(
|
|
4834
|
+
const real4 = realpathSync(resolve13(root, script));
|
|
4515
4835
|
if (!inside(realpathSync(base), real4))
|
|
4516
4836
|
throw new Error("Hook guard cannot resolve outside .agents/guards/");
|
|
4517
4837
|
return real4;
|
|
@@ -4527,7 +4847,7 @@ function applies(entry, input) {
|
|
|
4527
4847
|
function readFindings(value) {
|
|
4528
4848
|
if (value === void 0) return [];
|
|
4529
4849
|
if (!Array.isArray(value)) return null;
|
|
4530
|
-
const
|
|
4850
|
+
const found2 = [];
|
|
4531
4851
|
for (const item of value) {
|
|
4532
4852
|
if (!item || typeof item !== "object" || Array.isArray(item)) return null;
|
|
4533
4853
|
const { path, line, message, ...rest } = item;
|
|
@@ -4536,13 +4856,13 @@ function readFindings(value) {
|
|
|
4536
4856
|
if (path !== void 0 && typeof path !== "string") return null;
|
|
4537
4857
|
if (line !== void 0 && (!Number.isSafeInteger(line) || line < 1))
|
|
4538
4858
|
return null;
|
|
4539
|
-
|
|
4859
|
+
found2.push({
|
|
4540
4860
|
message,
|
|
4541
4861
|
...path !== void 0 ? { path } : {},
|
|
4542
4862
|
...line !== void 0 ? { line } : {}
|
|
4543
4863
|
});
|
|
4544
4864
|
}
|
|
4545
|
-
return
|
|
4865
|
+
return found2;
|
|
4546
4866
|
}
|
|
4547
4867
|
function findingLine(finding) {
|
|
4548
4868
|
const where = finding.path ? `${finding.path}${finding.line ? `:${finding.line}` : ""}: ` : "";
|
|
@@ -4572,7 +4892,7 @@ function run2(entry, input, log) {
|
|
|
4572
4892
|
};
|
|
4573
4893
|
}
|
|
4574
4894
|
const args = entry.command.map(
|
|
4575
|
-
(part) => part.startsWith(".agents/guards/") ?
|
|
4895
|
+
(part) => part.startsWith(".agents/guards/") ? resolve13(root, part) : part
|
|
4576
4896
|
);
|
|
4577
4897
|
const result = spawnSync(args[0], args.slice(1), {
|
|
4578
4898
|
cwd: root,
|
|
@@ -4589,9 +4909,9 @@ function run2(entry, input, log) {
|
|
|
4589
4909
|
const extra = Object.keys(response).some(
|
|
4590
4910
|
(key) => !["decision", "reason", "findings", "protocol"].includes(key)
|
|
4591
4911
|
);
|
|
4592
|
-
const
|
|
4912
|
+
const reason3 = response["reason"];
|
|
4593
4913
|
const findings = readFindings(response["findings"]);
|
|
4594
|
-
if (extra || findings === null ||
|
|
4914
|
+
if (extra || findings === null || reason3 !== void 0 && typeof reason3 !== "string" || response["protocol"] !== void 0 && response["protocol"] !== GUARD_PROTOCOL)
|
|
4595
4915
|
return { verdict: "deny", reason: FAILED };
|
|
4596
4916
|
const lines = findings.slice(0, MAX_FINDINGS).map(findingLine);
|
|
4597
4917
|
if (findings.length > MAX_FINDINGS)
|
|
@@ -4606,7 +4926,7 @@ function run2(entry, input, log) {
|
|
|
4606
4926
|
${lines.join("\n")}`] } : pass;
|
|
4607
4927
|
if (response["decision"] !== "deny")
|
|
4608
4928
|
return { verdict: "deny", reason: FAILED };
|
|
4609
|
-
const text9 = [typeof
|
|
4929
|
+
const text9 = [typeof reason3 === "string" ? reason3 : FAILED, ...lines].join(
|
|
4610
4930
|
"\n"
|
|
4611
4931
|
);
|
|
4612
4932
|
return { verdict: "deny", reason: text9.slice(0, MAX_REASON) };
|
|
@@ -4624,6 +4944,170 @@ function customPolicy(entry) {
|
|
|
4624
4944
|
};
|
|
4625
4945
|
}
|
|
4626
4946
|
|
|
4947
|
+
// src/hooks/policies/external.ts
|
|
4948
|
+
import { isAbsolute as isAbsolute9, relative as relative9, resolve as resolve14 } from "node:path";
|
|
4949
|
+
var MAX_LINES = 20;
|
|
4950
|
+
var MAX_REASON2 = 2e3;
|
|
4951
|
+
var MAX_OUTPUT = 1 << 20;
|
|
4952
|
+
function externalId(entry) {
|
|
4953
|
+
return `external.${entry.name}`;
|
|
4954
|
+
}
|
|
4955
|
+
function inProject(input, path) {
|
|
4956
|
+
const rest = relative9(input.projectRoot, resolve14(input.cwd, path));
|
|
4957
|
+
if (rest === "" || rest.startsWith("..") || isAbsolute9(rest)) return null;
|
|
4958
|
+
return rest.split("\\").join("/");
|
|
4959
|
+
}
|
|
4960
|
+
function matchedPaths(entry, input) {
|
|
4961
|
+
const patterns2 = entry.paths.map((glob2) => globPattern(glob2));
|
|
4962
|
+
const found2 = /* @__PURE__ */ new Set();
|
|
4963
|
+
for (const path of input.tool?.paths ?? []) {
|
|
4964
|
+
const rest = inProject(input, path);
|
|
4965
|
+
if (rest !== null && patterns2.some((pattern) => pattern.test(rest)))
|
|
4966
|
+
found2.add(rest);
|
|
4967
|
+
}
|
|
4968
|
+
return [...found2].sort();
|
|
4969
|
+
}
|
|
4970
|
+
function previewText(edit, cwd) {
|
|
4971
|
+
if (edit.content !== void 0) return edit.content;
|
|
4972
|
+
if (!edit.replacements) return null;
|
|
4973
|
+
let text9;
|
|
4974
|
+
try {
|
|
4975
|
+
text9 = readFileSync(resolve14(cwd, edit.path), "utf8");
|
|
4976
|
+
} catch {
|
|
4977
|
+
return null;
|
|
4978
|
+
}
|
|
4979
|
+
for (const change of edit.replacements) {
|
|
4980
|
+
if (change.old === "" || !text9.includes(change.old)) return null;
|
|
4981
|
+
text9 = change.all ? text9.split(change.old).join(change.new) : text9.replace(change.old, () => change.new);
|
|
4982
|
+
}
|
|
4983
|
+
return text9;
|
|
4984
|
+
}
|
|
4985
|
+
function itemLine(item, path) {
|
|
4986
|
+
if (typeof item === "string") return `${path}: ${item}`;
|
|
4987
|
+
const record = item && typeof item === "object" ? item : {};
|
|
4988
|
+
const field2 = (key) => typeof record[key] === "string" && record[key] !== "" ? record[key] : void 0;
|
|
4989
|
+
const message = field2("message") ?? JSON.stringify(item);
|
|
4990
|
+
const where = field2("path") ?? path;
|
|
4991
|
+
const line = Number.isSafeInteger(record["line"]) ? `:${record["line"]}` : "";
|
|
4992
|
+
const rule = field2("rule");
|
|
4993
|
+
return `${where}${line}: ${rule ? `${rule}: ` : ""}${message}`;
|
|
4994
|
+
}
|
|
4995
|
+
function check(entry, input, path, body, timeoutMs) {
|
|
4996
|
+
const placed = entry.command.some((part) => part.includes("{path}"));
|
|
4997
|
+
const argv = placed ? entry.command.map((part) => part.replaceAll("{path}", path)) : [...entry.command, path];
|
|
4998
|
+
const run3 = spawnSync(argv[0], argv.slice(1), {
|
|
4999
|
+
cwd: input.projectRoot,
|
|
5000
|
+
env: {
|
|
5001
|
+
PATH: process.env["PATH"],
|
|
5002
|
+
HOME: process.env["HOME"],
|
|
5003
|
+
LANG: "C.UTF-8"
|
|
5004
|
+
},
|
|
5005
|
+
input: body ?? "",
|
|
5006
|
+
encoding: "utf8",
|
|
5007
|
+
timeout: timeoutMs,
|
|
5008
|
+
killSignal: "SIGKILL",
|
|
5009
|
+
maxBuffer: MAX_OUTPUT
|
|
5010
|
+
});
|
|
5011
|
+
if (run3.error) return { error: `${path}: ${run3.error.message}` };
|
|
5012
|
+
if (run3.status === 0) return { items: [] };
|
|
5013
|
+
if (run3.status !== 1)
|
|
5014
|
+
return { error: `${path}: the checker exited ${run3.status ?? run3.signal}` };
|
|
5015
|
+
let items;
|
|
5016
|
+
try {
|
|
5017
|
+
items = JSON.parse(run3.stdout)["items"];
|
|
5018
|
+
} catch {
|
|
5019
|
+
items = void 0;
|
|
5020
|
+
}
|
|
5021
|
+
if (!Array.isArray(items) || items.length === 0)
|
|
5022
|
+
return {
|
|
5023
|
+
error: `${path}: the checker exited 1 without JSON holding an items list`
|
|
5024
|
+
};
|
|
5025
|
+
return { items: items.map((item) => itemLine(item, path)) };
|
|
5026
|
+
}
|
|
5027
|
+
function bodies(entry, input, paths) {
|
|
5028
|
+
const edit = entry.stdin ? input.tool?.edit : void 0;
|
|
5029
|
+
const target = edit ? inProject(input, edit.path) : null;
|
|
5030
|
+
const found2 = /* @__PURE__ */ new Map();
|
|
5031
|
+
for (const path of paths) {
|
|
5032
|
+
const previewed = edit !== void 0 && path === target;
|
|
5033
|
+
if (input.event === "before_tool") {
|
|
5034
|
+
const text9 = previewed ? previewText(edit, input.cwd) : null;
|
|
5035
|
+
if (text9 !== null) found2.set(path, text9);
|
|
5036
|
+
continue;
|
|
5037
|
+
}
|
|
5038
|
+
if (previewed) continue;
|
|
5039
|
+
if (!entry.stdin) {
|
|
5040
|
+
found2.set(path, void 0);
|
|
5041
|
+
continue;
|
|
5042
|
+
}
|
|
5043
|
+
try {
|
|
5044
|
+
found2.set(path, readFileSync(resolve14(input.projectRoot, path), "utf8"));
|
|
5045
|
+
} catch {
|
|
5046
|
+
}
|
|
5047
|
+
}
|
|
5048
|
+
return found2;
|
|
5049
|
+
}
|
|
5050
|
+
function firstError(entry, input, ctx) {
|
|
5051
|
+
try {
|
|
5052
|
+
const record = ctx.store.registry.get(input.session.id);
|
|
5053
|
+
const raw = record?.["externalErrors"];
|
|
5054
|
+
const seen = Array.isArray(raw) ? raw : [];
|
|
5055
|
+
if (seen.includes(entry.name)) return false;
|
|
5056
|
+
ctx.store.registry.upsert(input.session.id, {
|
|
5057
|
+
externalErrors: [...seen, entry.name]
|
|
5058
|
+
});
|
|
5059
|
+
} catch {
|
|
5060
|
+
}
|
|
5061
|
+
return true;
|
|
5062
|
+
}
|
|
5063
|
+
function evaluate(entry, input, ctx) {
|
|
5064
|
+
const paths = matchedPaths(entry, input);
|
|
5065
|
+
if (paths.length === 0) return pass;
|
|
5066
|
+
const deadline = Date.now() + entry.timeoutMs;
|
|
5067
|
+
const lines = [];
|
|
5068
|
+
const errors = [];
|
|
5069
|
+
for (const [path, body] of bodies(entry, input, paths)) {
|
|
5070
|
+
const left = deadline - Date.now();
|
|
5071
|
+
const result = left > 0 ? check(entry, input, path, body, left) : { error: `${path}: not checked, ${entry.timeoutMs} ms spent` };
|
|
5072
|
+
if ("error" in result) errors.push(result.error);
|
|
5073
|
+
else lines.push(...result.items);
|
|
5074
|
+
}
|
|
5075
|
+
if (lines.length > 0) {
|
|
5076
|
+
ctx.log.info("external findings", { items: lines.length });
|
|
5077
|
+
const listed = lines.slice(0, MAX_LINES);
|
|
5078
|
+
if (lines.length > MAX_LINES)
|
|
5079
|
+
listed.push(`and ${lines.length - MAX_LINES} more`);
|
|
5080
|
+
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`;
|
|
5081
|
+
return {
|
|
5082
|
+
verdict: "deny",
|
|
5083
|
+
reason: [head, ...listed].join("\n").slice(0, MAX_REASON2)
|
|
5084
|
+
};
|
|
5085
|
+
}
|
|
5086
|
+
if (errors.length === 0) return pass;
|
|
5087
|
+
ctx.log.warn("external check failed", {
|
|
5088
|
+
guard: entry.name,
|
|
5089
|
+
error: errors[0].slice(0, 300)
|
|
5090
|
+
});
|
|
5091
|
+
const reason3 = [
|
|
5092
|
+
`the check ${entry.name} could not answer, so the edit is not known to pass`,
|
|
5093
|
+
...errors.slice(0, MAX_LINES)
|
|
5094
|
+
].join("\n").slice(0, MAX_REASON2);
|
|
5095
|
+
if (entry.mode === "deny")
|
|
5096
|
+
return entry.onError === "deny" ? { verdict: "deny", reason: reason3 } : pass;
|
|
5097
|
+
return firstError(entry, input, ctx) ? { verdict: "deny", reason: reason3 } : pass;
|
|
5098
|
+
}
|
|
5099
|
+
function externalPolicy(entry) {
|
|
5100
|
+
return {
|
|
5101
|
+
id: externalId(entry),
|
|
5102
|
+
events: ["before_tool", "after_tool"],
|
|
5103
|
+
tools: ["edit"],
|
|
5104
|
+
fail: "open",
|
|
5105
|
+
defaultMode: "observe",
|
|
5106
|
+
options: () => ({}),
|
|
5107
|
+
evaluate: (input, ctx) => evaluate(entry, input, ctx)
|
|
5108
|
+
};
|
|
5109
|
+
}
|
|
5110
|
+
|
|
4627
5111
|
// src/hooks/policies/index.ts
|
|
4628
5112
|
var byId = (list) => Object.fromEntries(list.map((policy) => [policy.id, policy]));
|
|
4629
5113
|
var GUARDS = byId([
|
|
@@ -4634,10 +5118,12 @@ var GUARDS = byId([
|
|
|
4634
5118
|
hostApproval,
|
|
4635
5119
|
secretExfiltration,
|
|
4636
5120
|
runawayRegex,
|
|
5121
|
+
selfMatchingWait,
|
|
4637
5122
|
pushWithoutVerify,
|
|
4638
5123
|
forcedBranchMove,
|
|
4639
5124
|
gateBypassEnv,
|
|
4640
|
-
stageAll
|
|
5125
|
+
stageAll,
|
|
5126
|
+
operatorVerbs
|
|
4641
5127
|
]);
|
|
4642
5128
|
var FEATURES = byId([
|
|
4643
5129
|
registry,
|
|
@@ -4649,7 +5135,8 @@ var FEATURES = byId([
|
|
|
4649
5135
|
sharedCheckout,
|
|
4650
5136
|
worktreeSync,
|
|
4651
5137
|
mainlineDeliver,
|
|
4652
|
-
hostLease
|
|
5138
|
+
hostLease,
|
|
5139
|
+
owners
|
|
4653
5140
|
]);
|
|
4654
5141
|
var POLICIES = {
|
|
4655
5142
|
...FEATURES,
|
|
@@ -4696,7 +5183,14 @@ function selectPolicies(compiled, input) {
|
|
|
4696
5183
|
mode: customMode(entry),
|
|
4697
5184
|
options: {}
|
|
4698
5185
|
}));
|
|
4699
|
-
|
|
5186
|
+
const external = (compiled.external ?? []).map((entry) => ({
|
|
5187
|
+
policy: externalPolicy(entry),
|
|
5188
|
+
mode: entry.mode,
|
|
5189
|
+
options: {}
|
|
5190
|
+
}));
|
|
5191
|
+
return [...guards, ...custom, ...external].filter(
|
|
5192
|
+
(selected) => listens(selected, input)
|
|
5193
|
+
);
|
|
4700
5194
|
}
|
|
4701
5195
|
|
|
4702
5196
|
// src/hooks/dispatch/stop-loop.ts
|
|
@@ -4763,20 +5257,20 @@ function field(value, key) {
|
|
|
4763
5257
|
}
|
|
4764
5258
|
|
|
4765
5259
|
// src/hooks/runtimes/antigravity/output.ts
|
|
4766
|
-
var
|
|
5260
|
+
var MAX_REASON3 = 2e3;
|
|
4767
5261
|
function silent(event) {
|
|
4768
5262
|
return event === "before_tool" ? '{"decision":"allow"}\n' : "{}\n";
|
|
4769
5263
|
}
|
|
4770
5264
|
function render(input, decision) {
|
|
4771
5265
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
4772
|
-
const
|
|
5266
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON3);
|
|
4773
5267
|
if (input.event === "before_tool") {
|
|
4774
|
-
const out2 = blocking ? { decision: "deny", reason:
|
|
5268
|
+
const out2 = blocking ? { decision: "deny", reason: reason3 } : { decision: "allow" };
|
|
4775
5269
|
return { stdout: `${JSON.stringify(out2)}
|
|
4776
5270
|
`, exitCode: 0 };
|
|
4777
5271
|
}
|
|
4778
5272
|
const notes = [...decision.context ?? []];
|
|
4779
|
-
if (blocking) notes.unshift(
|
|
5273
|
+
if (blocking) notes.unshift(reason3);
|
|
4780
5274
|
if (decision.feedback) notes.push(decision.feedback);
|
|
4781
5275
|
let out = {};
|
|
4782
5276
|
if (notes.length > 0 && input.event !== "after_tool") {
|
|
@@ -4796,7 +5290,7 @@ function verdict(stdout) {
|
|
|
4796
5290
|
}
|
|
4797
5291
|
|
|
4798
5292
|
// src/hooks/runtimes/antigravity/payload.ts
|
|
4799
|
-
import { isAbsolute as
|
|
5293
|
+
import { isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
|
|
4800
5294
|
function object(value) {
|
|
4801
5295
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
4802
5296
|
}
|
|
@@ -4822,7 +5316,7 @@ function normalize(nativeEvent, payload, projectRoot) {
|
|
|
4822
5316
|
const name = text3(call["name"]);
|
|
4823
5317
|
const kind = name ? toolKind(name) : void 0;
|
|
4824
5318
|
const target = text3(args["TargetFile"]);
|
|
4825
|
-
const paths = target ? [
|
|
5319
|
+
const paths = target ? [isAbsolute10(target) ? target : resolve15(cwd, target)] : [];
|
|
4826
5320
|
return {
|
|
4827
5321
|
contract: 2,
|
|
4828
5322
|
runtime: "antigravity",
|
|
@@ -4973,23 +5467,23 @@ function matcherFor(tools) {
|
|
|
4973
5467
|
}
|
|
4974
5468
|
|
|
4975
5469
|
// src/hooks/runtimes/claude/output.ts
|
|
4976
|
-
var
|
|
5470
|
+
var MAX_REASON4 = 2e3;
|
|
4977
5471
|
function render2(input, decision) {
|
|
4978
5472
|
const hookEventName = NATIVE_EVENTS2[input.event];
|
|
4979
5473
|
const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
|
|
4980
|
-
const
|
|
5474
|
+
const reason3 = decision.reason?.slice(0, MAX_REASON4);
|
|
4981
5475
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
4982
5476
|
const out = shape(input, decision, {
|
|
4983
5477
|
hookEventName,
|
|
4984
5478
|
context,
|
|
4985
|
-
reason:
|
|
5479
|
+
reason: reason3,
|
|
4986
5480
|
blocking
|
|
4987
5481
|
});
|
|
4988
5482
|
return { stdout: out ? `${JSON.stringify(out)}
|
|
4989
5483
|
` : "", exitCode: 0 };
|
|
4990
5484
|
}
|
|
4991
5485
|
function shape(input, decision, parts) {
|
|
4992
|
-
const { hookEventName, context, reason:
|
|
5486
|
+
const { hookEventName, context, reason: reason3, blocking } = parts;
|
|
4993
5487
|
const contextOnly = context ? { hookSpecificOutput: { hookEventName, additionalContext: context } } : {};
|
|
4994
5488
|
if (input.event === "before_tool") {
|
|
4995
5489
|
if (!blocking && !context) return null;
|
|
@@ -4997,7 +5491,7 @@ function shape(input, decision, parts) {
|
|
|
4997
5491
|
if (blocking) {
|
|
4998
5492
|
refusal = {
|
|
4999
5493
|
permissionDecision: decision.verdict,
|
|
5000
|
-
...
|
|
5494
|
+
...reason3 ? { permissionDecisionReason: reason3 } : {}
|
|
5001
5495
|
};
|
|
5002
5496
|
}
|
|
5003
5497
|
return {
|
|
@@ -5009,7 +5503,7 @@ function shape(input, decision, parts) {
|
|
|
5009
5503
|
};
|
|
5010
5504
|
}
|
|
5011
5505
|
if (input.event === "prompt" || input.event === "after_tool" || input.event === "stop") {
|
|
5012
|
-
const feedback = blocking ?
|
|
5506
|
+
const feedback = blocking ? reason3 ?? "Refused" : decision.feedback;
|
|
5013
5507
|
if (!feedback && !context) return null;
|
|
5014
5508
|
return {
|
|
5015
5509
|
...feedback ? { decision: "block", reason: feedback } : {},
|
|
@@ -5027,7 +5521,7 @@ function verdict2(stdout) {
|
|
|
5027
5521
|
}
|
|
5028
5522
|
|
|
5029
5523
|
// src/hooks/runtimes/claude/payload.ts
|
|
5030
|
-
import { isAbsolute as
|
|
5524
|
+
import { isAbsolute as isAbsolute11, resolve as resolve16 } from "node:path";
|
|
5031
5525
|
function object2(value) {
|
|
5032
5526
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5033
5527
|
}
|
|
@@ -5044,7 +5538,7 @@ function normalize2(nativeEvent, payload, projectRoot) {
|
|
|
5044
5538
|
toolInput["file_path"],
|
|
5045
5539
|
toolInput["notebook_path"],
|
|
5046
5540
|
kind === "read" ? toolInput["path"] : void 0
|
|
5047
|
-
].filter((value) => typeof value === "string" && !!value).map((path) =>
|
|
5541
|
+
].filter((value) => typeof value === "string" && !!value).map((path) => isAbsolute11(path) ? path : resolve16(cwd, path));
|
|
5048
5542
|
const agentType = text4(raw["agent_type"]);
|
|
5049
5543
|
const turnId = text4(raw["prompt_id"]);
|
|
5050
5544
|
const lastMessage = text4(raw["last_assistant_message"]);
|
|
@@ -5084,10 +5578,30 @@ function toolFields(name, kind, input, paths) {
|
|
|
5084
5578
|
kind,
|
|
5085
5579
|
native: name,
|
|
5086
5580
|
...kind === "shell" ? { command: text4(input["command"]) ?? "" } : {},
|
|
5087
|
-
paths
|
|
5581
|
+
paths,
|
|
5582
|
+
...editFields(name, input, paths)
|
|
5088
5583
|
}
|
|
5089
5584
|
};
|
|
5090
5585
|
}
|
|
5586
|
+
function replacement(value) {
|
|
5587
|
+
const item = object2(value);
|
|
5588
|
+
const old = text4(item["old_string"]);
|
|
5589
|
+
const next = text4(item["new_string"]);
|
|
5590
|
+
if (old === void 0 || next === void 0) return null;
|
|
5591
|
+
return { old, new: next, all: item["replace_all"] === true };
|
|
5592
|
+
}
|
|
5593
|
+
function editFields(name, input, paths) {
|
|
5594
|
+
const path = paths[0];
|
|
5595
|
+
if (path === void 0) return {};
|
|
5596
|
+
if (name === "Write") {
|
|
5597
|
+
const content = text4(input["content"]);
|
|
5598
|
+
return content === void 0 ? {} : { edit: { path, content } };
|
|
5599
|
+
}
|
|
5600
|
+
const list = name === "Edit" ? [replacement(input)] : name === "MultiEdit" && Array.isArray(input["edits"]) ? input["edits"].map(replacement) : null;
|
|
5601
|
+
if (list === null || list.length === 0 || list.some((item) => !item))
|
|
5602
|
+
return {};
|
|
5603
|
+
return { edit: { path, replacements: list } };
|
|
5604
|
+
}
|
|
5091
5605
|
function stopFields(event, raw, lastMessage) {
|
|
5092
5606
|
if (event !== "stop") return {};
|
|
5093
5607
|
return {
|
|
@@ -5230,16 +5744,16 @@ function matcherFor2(tools) {
|
|
|
5230
5744
|
}
|
|
5231
5745
|
|
|
5232
5746
|
// src/hooks/runtimes/codex/output.ts
|
|
5233
|
-
var
|
|
5747
|
+
var MAX_REASON5 = 2e3;
|
|
5234
5748
|
function render3(input, decision) {
|
|
5235
5749
|
const hookEventName = NATIVE_EVENTS3[input.event];
|
|
5236
5750
|
const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
|
|
5237
|
-
const
|
|
5751
|
+
const reason3 = decision.reason?.slice(0, MAX_REASON5);
|
|
5238
5752
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5239
5753
|
const out = shape2(input, decision, {
|
|
5240
5754
|
hookEventName,
|
|
5241
5755
|
context,
|
|
5242
|
-
reason:
|
|
5756
|
+
reason: reason3,
|
|
5243
5757
|
blocking
|
|
5244
5758
|
});
|
|
5245
5759
|
if (!out && input.event === "stop") return { stdout: "{}\n", exitCode: 0 };
|
|
@@ -5247,7 +5761,7 @@ function render3(input, decision) {
|
|
|
5247
5761
|
` : "", exitCode: 0 };
|
|
5248
5762
|
}
|
|
5249
5763
|
function shape2(input, decision, parts) {
|
|
5250
|
-
const { hookEventName, context, reason:
|
|
5764
|
+
const { hookEventName, context, reason: reason3, blocking } = parts;
|
|
5251
5765
|
const contextOnly = context ? { hookSpecificOutput: { hookEventName, additionalContext: context } } : {};
|
|
5252
5766
|
if (input.event === "before_tool") {
|
|
5253
5767
|
if (!blocking && !context) return null;
|
|
@@ -5255,7 +5769,7 @@ function shape2(input, decision, parts) {
|
|
|
5255
5769
|
if (blocking) {
|
|
5256
5770
|
refusal = {
|
|
5257
5771
|
permissionDecision: "deny",
|
|
5258
|
-
...
|
|
5772
|
+
...reason3 ? { permissionDecisionReason: reason3 } : {}
|
|
5259
5773
|
};
|
|
5260
5774
|
}
|
|
5261
5775
|
return {
|
|
@@ -5267,7 +5781,7 @@ function shape2(input, decision, parts) {
|
|
|
5267
5781
|
};
|
|
5268
5782
|
}
|
|
5269
5783
|
if (input.event === "prompt" || input.event === "after_tool" || input.event === "stop") {
|
|
5270
|
-
const feedback = blocking ?
|
|
5784
|
+
const feedback = blocking ? reason3 ?? "Refused" : decision.feedback;
|
|
5271
5785
|
if (!feedback && !context) return null;
|
|
5272
5786
|
return {
|
|
5273
5787
|
...feedback ? { decision: "block", reason: feedback } : {},
|
|
@@ -5285,7 +5799,7 @@ function verdict3(stdout) {
|
|
|
5285
5799
|
}
|
|
5286
5800
|
|
|
5287
5801
|
// src/hooks/runtimes/codex/payload.ts
|
|
5288
|
-
import { isAbsolute as
|
|
5802
|
+
import { isAbsolute as isAbsolute12, resolve as resolve17 } from "node:path";
|
|
5289
5803
|
var PATCH_HEADER = /^\*\*\* (?:Update File|Add File|Delete File|Move to): (.+)$/gmu;
|
|
5290
5804
|
function object3(value) {
|
|
5291
5805
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -5303,7 +5817,7 @@ function normalize3(nativeEvent, payload, projectRoot) {
|
|
|
5303
5817
|
const toolInput = object3(raw["tool_input"]);
|
|
5304
5818
|
const kind = name ? toolKind3(name) : void 0;
|
|
5305
5819
|
const body = text5(toolInput["command"]) ?? "";
|
|
5306
|
-
const paths = (kind === "edit" ? patchPaths(body) : []).filter(Boolean).map((path) =>
|
|
5820
|
+
const paths = (kind === "edit" ? patchPaths(body) : []).filter(Boolean).map((path) => isAbsolute12(path) ? path : resolve17(cwd, path));
|
|
5307
5821
|
const turnId = text5(raw["turn_id"]);
|
|
5308
5822
|
const lastMessage = text5(raw["last_assistant_message"]);
|
|
5309
5823
|
const prompt = text5(raw["prompt"]);
|
|
@@ -5471,7 +5985,7 @@ function matcherFor3(tools) {
|
|
|
5471
5985
|
}
|
|
5472
5986
|
|
|
5473
5987
|
// src/hooks/runtimes/gemini/output.ts
|
|
5474
|
-
var
|
|
5988
|
+
var MAX_REASON6 = 2e3;
|
|
5475
5989
|
var DELIVERS = [
|
|
5476
5990
|
"session_start",
|
|
5477
5991
|
"prompt",
|
|
@@ -5479,12 +5993,12 @@ var DELIVERS = [
|
|
|
5479
5993
|
];
|
|
5480
5994
|
function render4(input, decision) {
|
|
5481
5995
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5482
|
-
const
|
|
5996
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
|
|
5483
5997
|
const out = {};
|
|
5484
5998
|
const notes = [...decision.context ?? []];
|
|
5485
5999
|
if (blocking && input.event === "before_tool")
|
|
5486
|
-
Object.assign(out, { decision: "deny", reason:
|
|
5487
|
-
else if (blocking) notes.unshift(
|
|
6000
|
+
Object.assign(out, { decision: "deny", reason: reason3 });
|
|
6001
|
+
else if (blocking) notes.unshift(reason3);
|
|
5488
6002
|
if (decision.feedback) notes.push(decision.feedback);
|
|
5489
6003
|
if (notes.length > 0 && DELIVERS.includes(input.event))
|
|
5490
6004
|
out["hookSpecificOutput"] = {
|
|
@@ -5502,7 +6016,7 @@ function verdict4(stdout) {
|
|
|
5502
6016
|
}
|
|
5503
6017
|
|
|
5504
6018
|
// src/hooks/runtimes/gemini/payload.ts
|
|
5505
|
-
import { isAbsolute as
|
|
6019
|
+
import { isAbsolute as isAbsolute13, resolve as resolve18 } from "node:path";
|
|
5506
6020
|
function object4(value) {
|
|
5507
6021
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5508
6022
|
}
|
|
@@ -5515,7 +6029,7 @@ function normalize4(nativeEvent, payload, projectRoot) {
|
|
|
5515
6029
|
const name = text6(raw["tool_name"]);
|
|
5516
6030
|
const input = object4(raw["tool_input"]);
|
|
5517
6031
|
const kind = name ? toolKind4(name) : void 0;
|
|
5518
|
-
const paths = [input["file_path"], input["absolute_path"], input["path"]].filter((value) => typeof value === "string" && !!value).map((path) =>
|
|
6032
|
+
const paths = [input["file_path"], input["absolute_path"], input["path"]].filter((value) => typeof value === "string" && !!value).map((path) => isAbsolute13(path) ? path : resolve18(cwd, path));
|
|
5519
6033
|
const prompt = text6(raw["prompt"]);
|
|
5520
6034
|
const lastMessage = text6(raw["prompt_response"]);
|
|
5521
6035
|
return {
|
|
@@ -5667,7 +6181,7 @@ function toolKind5(name) {
|
|
|
5667
6181
|
}
|
|
5668
6182
|
|
|
5669
6183
|
// src/hooks/runtimes/grok/output.ts
|
|
5670
|
-
var
|
|
6184
|
+
var MAX_REASON7 = 2e3;
|
|
5671
6185
|
var DELIVERS2 = [
|
|
5672
6186
|
"before_tool",
|
|
5673
6187
|
"after_tool",
|
|
@@ -5675,10 +6189,10 @@ var DELIVERS2 = [
|
|
|
5675
6189
|
];
|
|
5676
6190
|
function render5(input, decision) {
|
|
5677
6191
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5678
|
-
const
|
|
6192
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON7);
|
|
5679
6193
|
const notes = [...decision.context ?? []];
|
|
5680
6194
|
const refuse = blocking && input.event === "before_tool";
|
|
5681
|
-
if (blocking && !refuse) notes.unshift(
|
|
6195
|
+
if (blocking && !refuse) notes.unshift(reason3);
|
|
5682
6196
|
if (decision.feedback) notes.push(decision.feedback);
|
|
5683
6197
|
const quiet = input.event === "stop" && input.stop?.active === true;
|
|
5684
6198
|
const context = notes.length > 0 && DELIVERS2.includes(input.event) && !quiet ? notes.join("\n\n") : void 0;
|
|
@@ -5686,7 +6200,7 @@ function render5(input, decision) {
|
|
|
5686
6200
|
const out = {
|
|
5687
6201
|
hookSpecificOutput: {
|
|
5688
6202
|
hookEventName: NATIVE_EVENTS5[input.event],
|
|
5689
|
-
...refuse ? { permissionDecision: "deny", permissionDecisionReason:
|
|
6203
|
+
...refuse ? { permissionDecision: "deny", permissionDecisionReason: reason3 } : {},
|
|
5690
6204
|
...context ? { additionalContext: context } : {}
|
|
5691
6205
|
}
|
|
5692
6206
|
};
|
|
@@ -5701,7 +6215,7 @@ function verdict5(stdout) {
|
|
|
5701
6215
|
}
|
|
5702
6216
|
|
|
5703
6217
|
// src/hooks/runtimes/grok/payload.ts
|
|
5704
|
-
import { isAbsolute as
|
|
6218
|
+
import { isAbsolute as isAbsolute14, resolve as resolve19 } from "node:path";
|
|
5705
6219
|
function object5(value) {
|
|
5706
6220
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5707
6221
|
}
|
|
@@ -5719,7 +6233,7 @@ function normalize5(nativeEvent, payload, projectRoot) {
|
|
|
5719
6233
|
const input = object5(raw["toolInput"] ?? raw["tool_input"]);
|
|
5720
6234
|
const kind = name ? toolKind5(name) : void 0;
|
|
5721
6235
|
const path = text7(input["file_path"]);
|
|
5722
|
-
const paths = path ? [
|
|
6236
|
+
const paths = path ? [isAbsolute14(path) ? path : resolve19(cwd, path)] : [];
|
|
5723
6237
|
const turnId = text7(raw["promptId"]);
|
|
5724
6238
|
const prompt = text7(raw["prompt"]);
|
|
5725
6239
|
const lastMessage = text7(raw["lastAssistantMessage"]);
|
|
@@ -5875,7 +6389,7 @@ function toolKind6(name) {
|
|
|
5875
6389
|
}
|
|
5876
6390
|
|
|
5877
6391
|
// src/hooks/runtimes/opencode/output.ts
|
|
5878
|
-
var
|
|
6392
|
+
var MAX_REASON8 = 2e3;
|
|
5879
6393
|
var DELIVERS3 = [
|
|
5880
6394
|
"session_start",
|
|
5881
6395
|
"prompt",
|
|
@@ -5883,14 +6397,14 @@ var DELIVERS3 = [
|
|
|
5883
6397
|
];
|
|
5884
6398
|
function render6(input, decision) {
|
|
5885
6399
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5886
|
-
const
|
|
6400
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON8);
|
|
5887
6401
|
if (input.event === "before_tool") {
|
|
5888
|
-
const out2 = blocking ? { deny:
|
|
6402
|
+
const out2 = blocking ? { deny: reason3 } : {};
|
|
5889
6403
|
return { stdout: `${JSON.stringify(out2)}
|
|
5890
6404
|
`, exitCode: 0 };
|
|
5891
6405
|
}
|
|
5892
6406
|
const notes = [...decision.context ?? []];
|
|
5893
|
-
if (blocking) notes.unshift(
|
|
6407
|
+
if (blocking) notes.unshift(reason3);
|
|
5894
6408
|
if (decision.feedback) notes.push(decision.feedback);
|
|
5895
6409
|
const out = notes.length > 0 && DELIVERS3.includes(input.event) ? { context: notes.join("\n\n") } : {};
|
|
5896
6410
|
return { stdout: `${JSON.stringify(out)}
|
|
@@ -5901,7 +6415,7 @@ function verdict6(stdout) {
|
|
|
5901
6415
|
}
|
|
5902
6416
|
|
|
5903
6417
|
// src/hooks/runtimes/opencode/payload.ts
|
|
5904
|
-
import { isAbsolute as
|
|
6418
|
+
import { isAbsolute as isAbsolute15, resolve as resolve20 } from "node:path";
|
|
5905
6419
|
function object6(value) {
|
|
5906
6420
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5907
6421
|
}
|
|
@@ -5917,7 +6431,7 @@ function normalize6(nativeEvent, payload, projectRoot) {
|
|
|
5917
6431
|
const args = object6(raw["args"] ?? input["args"]);
|
|
5918
6432
|
const kind = name ? toolKind6(name) : void 0;
|
|
5919
6433
|
const path = text8(args["filePath"]);
|
|
5920
|
-
const paths = path ? [
|
|
6434
|
+
const paths = path ? [isAbsolute15(path) ? path : resolve20(cwd, path)] : [];
|
|
5921
6435
|
const session = text8(input["sessionID"]) ?? text8(properties["sessionID"]) ?? "";
|
|
5922
6436
|
return {
|
|
5923
6437
|
contract: 2,
|
|
@@ -6142,18 +6656,18 @@ async function dispatch(raw, compiled, deps) {
|
|
|
6142
6656
|
}
|
|
6143
6657
|
|
|
6144
6658
|
// src/hooks/entry/fail-closed.ts
|
|
6145
|
-
import { join as
|
|
6659
|
+
import { join as join15 } from "node:path";
|
|
6146
6660
|
|
|
6147
6661
|
// src/hooks/compiled.ts
|
|
6148
|
-
import { join as
|
|
6662
|
+
import { join as join14 } from "node:path";
|
|
6149
6663
|
|
|
6150
6664
|
// src/hooks/integrity-cache.ts
|
|
6151
|
-
import { homedir as
|
|
6152
|
-
import { dirname as dirname8, join as
|
|
6665
|
+
import { homedir as homedir4 } from "node:os";
|
|
6666
|
+
import { dirname as dirname8, join as join13 } from "node:path";
|
|
6153
6667
|
var LIMIT = 64;
|
|
6154
6668
|
function cacheFile() {
|
|
6155
|
-
const base = process.env["XDG_CACHE_HOME"] ||
|
|
6156
|
-
return
|
|
6669
|
+
const base = process.env["XDG_CACHE_HOME"] || join13(homedir4(), ".cache");
|
|
6670
|
+
return join13(base, "pmcp", "hook-verified.json");
|
|
6157
6671
|
}
|
|
6158
6672
|
function readCache() {
|
|
6159
6673
|
try {
|
|
@@ -6223,8 +6737,8 @@ function readLockFile(path) {
|
|
|
6223
6737
|
}
|
|
6224
6738
|
}
|
|
6225
6739
|
function readCompiled(root) {
|
|
6226
|
-
const policyPath =
|
|
6227
|
-
const files2 = [policyPath,
|
|
6740
|
+
const policyPath = join14(root, POLICY_FILE);
|
|
6741
|
+
const files2 = [policyPath, join14(root, LOCK_FILE)];
|
|
6228
6742
|
const before2 = stampOf(files2);
|
|
6229
6743
|
const text9 = readFileSync(policyPath, "utf8");
|
|
6230
6744
|
const lock = readLockFile(files2[1]);
|
|
@@ -6247,7 +6761,7 @@ function readCompiled(root) {
|
|
|
6247
6761
|
var FAILED_CLOSED = "pmcp hook could not evaluate this call and refused it";
|
|
6248
6762
|
function rawFailure(root) {
|
|
6249
6763
|
try {
|
|
6250
|
-
const raw = JSON.parse(readFileSync(
|
|
6764
|
+
const raw = JSON.parse(readFileSync(join15(root, POLICY_FILE), "utf8"))["failure"];
|
|
6251
6765
|
if (!raw || typeof raw.timeoutMs !== "number" || typeof raw.retry !== "number" || !Array.isArray(raw.pass) || !raw.pass.every(
|
|
6252
6766
|
(kind) => PASS_KINDS.includes(kind)
|
|
6253
6767
|
))
|
|
@@ -6269,7 +6783,7 @@ function failedEntry(adapter, event, root, input, failure, error) {
|
|
|
6269
6783
|
}
|
|
6270
6784
|
function failClosed(adapter, event, root, error, stated = false) {
|
|
6271
6785
|
if (event !== "before_tool") return "";
|
|
6272
|
-
const
|
|
6786
|
+
const reason3 = error instanceof PolicyIntegrityError || stated && error instanceof Error ? error.message : FAILED_CLOSED;
|
|
6273
6787
|
const input = {
|
|
6274
6788
|
contract: 2,
|
|
6275
6789
|
runtime: adapter.id,
|
|
@@ -6278,11 +6792,11 @@ function failClosed(adapter, event, root, error, stated = false) {
|
|
|
6278
6792
|
cwd: root,
|
|
6279
6793
|
projectRoot: root
|
|
6280
6794
|
};
|
|
6281
|
-
return adapter.render(input, { verdict: "deny", reason:
|
|
6795
|
+
return adapter.render(input, { verdict: "deny", reason: reason3 }).stdout;
|
|
6282
6796
|
}
|
|
6283
6797
|
|
|
6284
6798
|
// src/hooks/entry/lock-repair.ts
|
|
6285
|
-
import { join as
|
|
6799
|
+
import { join as join16, resolve as resolve21 } from "node:path";
|
|
6286
6800
|
var REV = /^[\w./~^@{}][\w./~^@{}-]*$/u;
|
|
6287
6801
|
var LOCK_PATHS = /* @__PURE__ */ new Set([LOCK_FILE, `./${LOCK_FILE}`]);
|
|
6288
6802
|
var RESTORE_OPTIONS = /* @__PURE__ */ new Set([
|
|
@@ -6326,8 +6840,8 @@ function repairsLock(input, root) {
|
|
|
6326
6840
|
if (!tool) return false;
|
|
6327
6841
|
if (tool.kind === "read") return true;
|
|
6328
6842
|
if (tool.kind === "edit") {
|
|
6329
|
-
const lock =
|
|
6330
|
-
return tool.paths.length > 0 && tool.paths.every((path) =>
|
|
6843
|
+
const lock = join16(root, LOCK_FILE);
|
|
6844
|
+
return tool.paths.length > 0 && tool.paths.every((path) => resolve21(input.cwd, path) === lock);
|
|
6331
6845
|
}
|
|
6332
6846
|
if (tool.kind === "shell") return restoresLock(tool.command ?? "");
|
|
6333
6847
|
return false;
|
|
@@ -6468,11 +6982,11 @@ var silentLogger = createLogger(() => {
|
|
|
6468
6982
|
});
|
|
6469
6983
|
|
|
6470
6984
|
// src/logging/sinks/file.ts
|
|
6471
|
-
import { join as
|
|
6985
|
+
import { join as join17 } from "node:path";
|
|
6472
6986
|
var FILE = /^pmcp-(\d{8})(?:\.\d+)?\.jsonl$/u;
|
|
6473
6987
|
function dailyLogFile(dir, now = /* @__PURE__ */ new Date()) {
|
|
6474
6988
|
const day = now.toISOString().slice(0, 10).replaceAll("-", "");
|
|
6475
|
-
return
|
|
6989
|
+
return join17(dir, `pmcp-${day}.jsonl`);
|
|
6476
6990
|
}
|
|
6477
6991
|
function roll(file2) {
|
|
6478
6992
|
let index = 1;
|
|
@@ -6503,7 +7017,7 @@ function logFiles(dir) {
|
|
|
6503
7017
|
const part = (name) => Number(/\.(\d+)\.jsonl$/u.exec(name)?.[1] ?? Number.MAX_SAFE_INTEGER);
|
|
6504
7018
|
return names4.sort(
|
|
6505
7019
|
(a, b) => a.slice(5, 13).localeCompare(b.slice(5, 13)) || part(a) - part(b)
|
|
6506
|
-
).map((name) =>
|
|
7020
|
+
).map((name) => join17(dir, name));
|
|
6507
7021
|
}
|
|
6508
7022
|
function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
|
|
6509
7023
|
const cutoff = new Date(now.getTime() - keepDays * 864e5).toISOString().slice(0, 10).replaceAll("-", "");
|
|
@@ -6517,17 +7031,6 @@ function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
|
|
|
6517
7031
|
return removed;
|
|
6518
7032
|
}
|
|
6519
7033
|
|
|
6520
|
-
// src/sessions/state-dir.ts
|
|
6521
|
-
import { homedir as homedir4 } from "node:os";
|
|
6522
|
-
import { join as join17 } from "node:path";
|
|
6523
|
-
function projectStateDir(root, override, env = process.env) {
|
|
6524
|
-
if (override) return expandPath(root, override);
|
|
6525
|
-
const anchor = gitCommonDir(root) ?? realpathSync(root);
|
|
6526
|
-
const id = createHash("sha256").update(anchor).digest("hex").slice(0, 16);
|
|
6527
|
-
const base = env["XDG_STATE_HOME"] || join17(homedir4(), ".local", "state");
|
|
6528
|
-
return join17(base, "pmcp", "projects", id);
|
|
6529
|
-
}
|
|
6530
|
-
|
|
6531
7034
|
// src/hooks/entry/logger.ts
|
|
6532
7035
|
function traceId() {
|
|
6533
7036
|
const high = Math.floor(Math.random() * 2 ** 32);
|
|
@@ -6559,7 +7062,7 @@ function hookLogger(root, compiled, runtime2, event) {
|
|
|
6559
7062
|
import { join as join20 } from "node:path";
|
|
6560
7063
|
|
|
6561
7064
|
// src/sessions/lease-files.ts
|
|
6562
|
-
import { dirname as dirname10, isAbsolute as
|
|
7065
|
+
import { dirname as dirname10, isAbsolute as isAbsolute16, join as join19 } from "node:path";
|
|
6563
7066
|
var GATE_DIR = "${gate_dir}/";
|
|
6564
7067
|
function gateTree(root, stateDir, gate, env) {
|
|
6565
7068
|
const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
|
|
@@ -6573,11 +7076,11 @@ function resolvePauseFile(file2, gateDir) {
|
|
|
6573
7076
|
return file2 === void 0 ? void 0 : atGateDir(file2, gateDir);
|
|
6574
7077
|
}
|
|
6575
7078
|
function resolveLeaseFiles(files2, gateDir) {
|
|
6576
|
-
const
|
|
7079
|
+
const resolve23 = (path) => path === void 0 ? void 0 : atGateDir(path, gateDir);
|
|
6577
7080
|
return Object.fromEntries(
|
|
6578
7081
|
Object.entries(files2 ?? {}).map(([name, f]) => {
|
|
6579
|
-
const file2 =
|
|
6580
|
-
const events2 =
|
|
7082
|
+
const file2 = resolve23(f.file);
|
|
7083
|
+
const events2 = resolve23(f.events);
|
|
6581
7084
|
return [
|
|
6582
7085
|
name,
|
|
6583
7086
|
{ ...file2 ? { file: file2 } : {}, ...events2 ? { events: events2 } : {} }
|
|
@@ -6951,7 +7454,7 @@ function filesRegistry(dir, staleMs) {
|
|
|
6951
7454
|
);
|
|
6952
7455
|
};
|
|
6953
7456
|
const list = (now = Date.now()) => {
|
|
6954
|
-
const
|
|
7457
|
+
const found2 = /* @__PURE__ */ new Map();
|
|
6955
7458
|
for (const folder of dirs) {
|
|
6956
7459
|
let names4 = [];
|
|
6957
7460
|
try {
|
|
@@ -6960,12 +7463,12 @@ function filesRegistry(dir, staleMs) {
|
|
|
6960
7463
|
continue;
|
|
6961
7464
|
}
|
|
6962
7465
|
for (const name of names4)
|
|
6963
|
-
|
|
6964
|
-
...
|
|
7466
|
+
found2.set(name, [
|
|
7467
|
+
...found2.get(name) ?? [],
|
|
6965
7468
|
asRecord(readJson3(join25(folder, name)))
|
|
6966
7469
|
]);
|
|
6967
7470
|
}
|
|
6968
|
-
return [...
|
|
7471
|
+
return [...found2.values()].map(latestRecord).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
|
|
6969
7472
|
};
|
|
6970
7473
|
const remove = (session) => {
|
|
6971
7474
|
if (!SESSION_ID.test(session)) return;
|
|
@@ -7144,10 +7647,10 @@ async function main(argv, root) {
|
|
|
7144
7647
|
}
|
|
7145
7648
|
}
|
|
7146
7649
|
var self = import.meta.filename;
|
|
7147
|
-
if (process.argv[1] &&
|
|
7650
|
+
if (process.argv[1] && resolve22(process.argv[1]) === self) {
|
|
7148
7651
|
process.exitCode = await main(
|
|
7149
7652
|
process.argv.slice(2),
|
|
7150
|
-
|
|
7653
|
+
resolve22(dirname13(self), "../..")
|
|
7151
7654
|
);
|
|
7152
7655
|
}
|
|
7153
7656
|
export {
|