@modootoday/pmcp 0.25.0 → 0.26.1
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-6XLLYLJT.js → apply-7HWNHSQB.js} +17 -15
- package/dist/{broadcast-34CEG2NQ.js → broadcast-U7ZYOJWE.js} +4 -4
- package/dist/{chunk-2TXVOHRS.js → chunk-2VL3C52Y.js} +4 -4
- package/dist/{chunk-UKR64U7J.js → chunk-374AZ4J4.js} +2 -2
- package/dist/{chunk-ISWR2XIU.js → chunk-3T7CJS4A.js} +2 -2
- package/dist/{chunk-PGZZI42O.js → chunk-5ZP3ABPI.js} +2 -2
- package/dist/{chunk-SSQ6EWNA.js → chunk-A7MF7RMO.js} +7 -7
- package/dist/{chunk-3P6Y2BAO.js → chunk-BSG74PTY.js} +3 -3
- package/dist/{chunk-SRSKCFFS.js → chunk-CJD2HFXF.js} +3 -3
- package/dist/chunk-D7IDT7OA.js +21 -0
- package/dist/chunk-E272CFPS.js +14 -0
- package/dist/{chunk-LZVHFPN6.js → chunk-E7BPELYH.js} +5 -5
- package/dist/chunk-EIBKHS74.js +7 -0
- package/dist/chunk-FLG7VRTC.js +1 -0
- package/dist/{chunk-BG6TONJO.js → chunk-GIK4TROM.js} +2 -2
- package/dist/{chunk-ARXCYFFZ.js → chunk-GQRDEIQA.js} +22 -2
- package/dist/{chunk-UQHJUTDW.js → chunk-GYL2C2Y5.js} +2 -2
- package/dist/{chunk-TOR6SKRB.js → chunk-JDVDA5HW.js} +508 -48
- package/dist/chunk-KLIYFD3W.js +32 -0
- package/dist/{chunk-5MUD7FHP.js → chunk-KWEW5EBE.js} +2 -2
- package/dist/{chunk-PECS47OL.js → chunk-M2XABD33.js} +3 -3
- package/dist/{chunk-MBHI2TKQ.js → chunk-MFQAQ4IJ.js} +5 -5
- package/dist/{chunk-NAHAESFV.js → chunk-OHCUPXU4.js} +18 -5
- package/dist/{chunk-3V37OZQH.js → chunk-PAY6HEEY.js} +2 -2
- package/dist/{chunk-DITIXBFB.js → chunk-PZ6D3WKD.js} +65 -1
- package/dist/{chunk-QYHM6554.js → chunk-RGTWJWQ7.js} +3 -3
- package/dist/{chunk-VYQJPT27.js → chunk-S2FUWBLO.js} +18 -4
- package/dist/{chunk-DWHM5BAY.js → chunk-T52AGUO7.js} +2 -2
- package/dist/{chunk-OGCJO6HQ.js → chunk-TQRLWO4F.js} +2 -2
- package/dist/{chunk-EC5QLEZD.js → chunk-UHKHXS3E.js} +14 -6
- package/dist/{chunk-MHKY6TNF.js → chunk-VN34GLGJ.js} +3 -3
- package/dist/chunk-WUFNKK3U.js +71 -0
- package/dist/chunk-X6W7JIED.js +25 -0
- package/dist/{chunk-RF6RDJYH.js → chunk-XPLT6DJC.js} +26 -19
- package/dist/{chunk-C3KRMTIZ.js → chunk-YJVSN6UN.js} +2 -2
- package/dist/{chunk-EWYLWBKS.js → chunk-YKICVMF7.js} +22 -5
- package/dist/{chunk-TJW4DP26.js → chunk-ZT75ACJ2.js} +2 -2
- package/dist/{cli-QDQYUHAP.js → cli-FVUHK2NB.js} +6 -6
- package/dist/{cli-5G2OYTIL.js → cli-ZOY2274X.js} +8 -8
- package/dist/cli.js +9 -14
- package/dist/{completion-3GVNPLZY.js → completion-O3KRUSJG.js} +5 -4
- package/dist/{diagnostics-2W7QDQNG.js → diagnostics-PB5TKIAL.js} +7 -7
- package/dist/{doctor-3TDO5LJ5.js → doctor-JVWINJT5.js} +31 -20
- package/dist/{entry-E62DZQJF.js → entry-CY74PLN3.js} +13 -13
- package/dist/{exec-mcp-4N7FLY52.js → exec-mcp-HAKUGQZM.js} +14 -12
- package/dist/{harness-E2AUZDLV.js → harness-N234LNM7.js} +3 -3
- package/dist/harness-launch-gate.js +5 -5
- package/dist/harness-worker.js +7 -7
- package/dist/{heavy-HZQVFI6P.js → heavy-X3KZ7WBU.js} +186 -99
- package/dist/hook-body.js +548 -116
- package/dist/{hook-spec-Bd24eo2L.d.ts → hook-spec-u7hnz571.d.ts} +10 -0
- package/dist/{hooks-VAEAK2FY.js → hooks-7K624JQC.js} +4 -4
- package/dist/{host-I2EMQ7UE.js → host-CCJFOCZJ.js} +16 -14
- package/dist/{host-4GJDGTLW.js → host-PT7NRWG6.js} +8 -8
- package/dist/{host-run-DDMKD3BU.js → host-run-RRBFTVYW.js} +6 -6
- package/dist/http.js +1 -1
- package/dist/{import-mcp-TNSAMJXI.js → import-mcp-GCNNSLWH.js} +13 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -15
- package/dist/{init-UA7MDNTZ.js → init-A4NLTERR.js} +2 -2
- package/dist/{invoke-HW7NBPGP.js → invoke-G4LNWPTL.js} +9 -9
- package/dist/{list-A7VQJXE5.js → list-EZYULVDW.js} +16 -14
- package/dist/{logout-HNPLUKJY.js → logout-BYO3UJUH.js} +14 -12
- package/dist/{logs-2JEMSNSG.js → logs-J4W6GFMK.js} +4 -4
- package/dist/{mailbox-MR6TPD3P.js → mailbox-6MHH6CUA.js} +4 -4
- package/dist/{mainline-MSLW3UFD.js → mainline-SWZPKA7U.js} +13 -9
- package/dist/{mcp-6C23GX2E.js → mcp-CZNYDYTJ.js} +2 -2
- package/dist/owners-MPI22SFU.js +63 -0
- package/dist/{pause-H6ZYZF7C.js → pause-3IMVYXQQ.js} +4 -4
- package/dist/project/hook-adapter.d.ts +1 -1
- package/dist/{project-BX6NCGKB.js → project-GLT3SO7Y.js} +4 -4
- package/dist/{report-43SFNNCF.js → report-MWXB5XKE.js} +4 -4
- package/dist/{resume-2BWGSTCN.js → resume-7LCSV4X3.js} +4 -4
- package/dist/{run-2UVAWBAF.js → run-J5O2V3MB.js} +13 -11
- package/dist/{run-7TRWZFEZ.js → run-OBQBKBPV.js} +4 -4
- package/dist/{serve-4XZ5SKJJ.js → serve-QCG4PCVS.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-AR7ITWNV.js → start-login-LRO3RTHD.js} +14 -12
- package/dist/{status-ZY6LDQSF.js → status-BQLT7JRE.js} +14 -12
- package/dist/{status-VQCMJFVE.js → status-EZTFSD5S.js} +18 -16
- package/dist/{status-2GDYLIR3.js → status-QFMN7IUG.js} +4 -4
- package/dist/stdio.js +2 -2
- package/dist/{sweep-76BUOGEI.js → sweep-BS7HVSNP.js} +4 -4
- package/dist/{test-VWGNFSH5.js → test-O7TN5SBA.js} +25 -15
- package/dist/{tui-TUMOQBE7.js → tui-ODLF6QWC.js} +4 -4
- package/dist/{unbroadcast-HJHYUHZL.js → unbroadcast-GRGX3F6T.js} +4 -4
- package/dist/{worker-NEEPJRVV.js → worker-AK4GLGPZ.js} +11 -11
- package/dist/{worktree-sync-MUVKK2CV.js → worktree-sync-BQZD4J73.js} +5 -2
- package/docs/commands.md +12 -3
- package/docs/git-workflow.md +40 -5
- package/docs/hooks.md +69 -14
- package/docs/project-configuration.md +63 -4
- package/docs/upgrading.md +13 -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-7TD53M7L.js +0 -13
- package/dist/chunk-FQLCD4HU.js +0 -24
- package/dist/chunk-SMBU3QLE.js +0 -7
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
|
|
|
@@ -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;
|
|
@@ -2752,8 +2752,8 @@ function fields(input) {
|
|
|
2752
2752
|
return { ...cwd, status: "working", waiting: "" };
|
|
2753
2753
|
if (input.event === "after_tool") return { ...cwd, status: "working" };
|
|
2754
2754
|
if (input.event === "notification") {
|
|
2755
|
-
const
|
|
2756
|
-
return { status: "waiting", waiting:
|
|
2755
|
+
const reason3 = input.notification?.type || input.notification?.message;
|
|
2756
|
+
return { status: "waiting", waiting: reason3 ?? "" };
|
|
2757
2757
|
}
|
|
2758
2758
|
if (input.event === "stop") {
|
|
2759
2759
|
return {
|
|
@@ -2914,8 +2914,8 @@ var composeTeardown = {
|
|
|
2914
2914
|
const call = shellCall(input);
|
|
2915
2915
|
if (!call) return pass;
|
|
2916
2916
|
for (const step of realSteps(call.steps)) {
|
|
2917
|
-
const
|
|
2918
|
-
if (
|
|
2917
|
+
const reason3 = teardownReason(step.argv);
|
|
2918
|
+
if (reason3) return { verdict: "deny", reason: reason3 };
|
|
2919
2919
|
}
|
|
2920
2920
|
return pass;
|
|
2921
2921
|
}
|
|
@@ -3470,6 +3470,103 @@ var secretExfiltration = {
|
|
|
3470
3470
|
}
|
|
3471
3471
|
};
|
|
3472
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
|
+
|
|
3473
3570
|
// src/hooks/policies/shell/stdin-interpreter.ts
|
|
3474
3571
|
var PYTHON = /^i?python[23]?(\.\d+)?$/u;
|
|
3475
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.";
|
|
@@ -4096,7 +4193,27 @@ function distance(cwd, upstream) {
|
|
|
4096
4193
|
}
|
|
4097
4194
|
|
|
4098
4195
|
// src/git/added-submodules.ts
|
|
4099
|
-
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
|
|
4100
4217
|
var ADDED_GITLINK = /^:\d{6} 160000 [0-9a-f]{40} ([0-9a-f]{40}) [AT]\t(.+)$/u;
|
|
4101
4218
|
function initAddedSubmodules(root, from, to) {
|
|
4102
4219
|
const raw = gitText(root, [
|
|
@@ -4117,8 +4234,8 @@ function initAddedSubmodules(root, from, to) {
|
|
|
4117
4234
|
return lines;
|
|
4118
4235
|
}
|
|
4119
4236
|
function initOne(root, path, pin, from) {
|
|
4120
|
-
const dir =
|
|
4121
|
-
if (existsSync(
|
|
4237
|
+
const dir = join11(root, path);
|
|
4238
|
+
if (existsSync(join11(dir, ".git"))) return followLeftCheckout(root, path, pin);
|
|
4122
4239
|
let displaced = "";
|
|
4123
4240
|
if (existsSync(dir) && readdirSync(dir).length > 0) {
|
|
4124
4241
|
if (unignoredFiles(root, path, from).length > 0)
|
|
@@ -4132,7 +4249,7 @@ function initOne(root, path, pin, from) {
|
|
|
4132
4249
|
return `new submodule checked out at ${pin.slice(0, 10)}${aside}`;
|
|
4133
4250
|
}
|
|
4134
4251
|
function followLeftCheckout(root, path, pin) {
|
|
4135
|
-
const dir =
|
|
4252
|
+
const dir = join11(root, path);
|
|
4136
4253
|
const head = git(dir, ["rev-parse", "HEAD"]);
|
|
4137
4254
|
if (head.status === 0 && head.stdout.trim() === pin)
|
|
4138
4255
|
return "already checked out";
|
|
@@ -4152,7 +4269,7 @@ function unignoredFiles(root, path, from) {
|
|
|
4152
4269
|
let level = [path];
|
|
4153
4270
|
while (level.length > 0) {
|
|
4154
4271
|
const entries = level.flatMap(
|
|
4155
|
-
(dir) => readdirSync(
|
|
4272
|
+
(dir) => readdirSync(join11(root, dir), { withFileTypes: true }).map((entry) => ({
|
|
4156
4273
|
path: `${dir}/${entry.name}`,
|
|
4157
4274
|
dir: entry.isDirectory()
|
|
4158
4275
|
}))
|
|
@@ -4172,7 +4289,7 @@ function unignoredFiles(root, path, from) {
|
|
|
4172
4289
|
level = open2.filter((entry) => entry.dir).map((entry) => entry.path);
|
|
4173
4290
|
}
|
|
4174
4291
|
} finally {
|
|
4175
|
-
for (const file2 of restored) rmSync(
|
|
4292
|
+
for (const file2 of restored) rmSync(join11(root, file2));
|
|
4176
4293
|
}
|
|
4177
4294
|
return kept;
|
|
4178
4295
|
}
|
|
@@ -4190,7 +4307,7 @@ function restoreIgnoreFiles(root, path, from) {
|
|
|
4190
4307
|
const restored = [];
|
|
4191
4308
|
for (const file2 of listed.stdout.split("\0")) {
|
|
4192
4309
|
if (!file2.endsWith("/.gitignore")) continue;
|
|
4193
|
-
const target =
|
|
4310
|
+
const target = join11(root, file2);
|
|
4194
4311
|
if (existsSync(target) || !existsSync(dirname7(target))) continue;
|
|
4195
4312
|
const body = git(root, ["show", `${from}:${file2}`]);
|
|
4196
4313
|
if (body.status !== 0) continue;
|
|
@@ -4200,16 +4317,26 @@ function restoreIgnoreFiles(root, path, from) {
|
|
|
4200
4317
|
return restored;
|
|
4201
4318
|
}
|
|
4202
4319
|
function displace(root, path) {
|
|
4203
|
-
const gitDir = gitText(root, ["rev-parse", "--absolute-git-dir"]);
|
|
4204
4320
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/gu, "-");
|
|
4205
|
-
const target =
|
|
4321
|
+
const target = join11(displacedDir(root), stamp, path);
|
|
4206
4322
|
mkdirSync(dirname7(target), { recursive: true });
|
|
4207
|
-
|
|
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
|
+
}
|
|
4208
4335
|
return target;
|
|
4209
4336
|
}
|
|
4210
4337
|
|
|
4211
4338
|
// src/git/submodules.ts
|
|
4212
|
-
import { join as
|
|
4339
|
+
import { join as join12 } from "node:path";
|
|
4213
4340
|
function clean(dir) {
|
|
4214
4341
|
return git(dir, ["status", "--porcelain"]).stdout.trim() === "";
|
|
4215
4342
|
}
|
|
@@ -4219,8 +4346,8 @@ function hasCommit(dir, sha) {
|
|
|
4219
4346
|
function movableSubmodules(root) {
|
|
4220
4347
|
const listed = git(root, ["submodule", "status"]).stdout;
|
|
4221
4348
|
return listed.split("\n").filter((line) => /^[ +]/u.test(line)).map((line) => line.trim().split(/\s+/u)[1] ?? "").filter((path) => {
|
|
4222
|
-
const dir =
|
|
4223
|
-
if (!path || !existsSync(
|
|
4349
|
+
const dir = join12(root, path);
|
|
4350
|
+
if (!path || !existsSync(join12(dir, ".git"))) return false;
|
|
4224
4351
|
const local = gitText(dir, [
|
|
4225
4352
|
"rev-list",
|
|
4226
4353
|
"--count",
|
|
@@ -4235,7 +4362,7 @@ function updateToPins(root, paths) {
|
|
|
4235
4362
|
const lines = [];
|
|
4236
4363
|
for (const path of paths) {
|
|
4237
4364
|
const pin = gitText(root, ["rev-parse", `HEAD:${path}`]);
|
|
4238
|
-
const dir =
|
|
4365
|
+
const dir = join12(root, path);
|
|
4239
4366
|
if (!pin || !hasCommit(dir, pin)) {
|
|
4240
4367
|
lines.push(
|
|
4241
4368
|
`${path}: left alone, ${pin.slice(0, 10) || "its pin"} is not in its checkout`
|
|
@@ -4430,14 +4557,137 @@ var worktreeSync = {
|
|
|
4430
4557
|
if (input.event === "prompt" && opts.betweenPrompts === "off") return pass;
|
|
4431
4558
|
const git2 = desk(input, opts);
|
|
4432
4559
|
if (!git2) return pass;
|
|
4433
|
-
const
|
|
4434
|
-
if (
|
|
4435
|
-
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;
|
|
4436
4563
|
const lines = move2(input, ctx, git2);
|
|
4437
4564
|
return lines.length > 0 ? { context: lines } : pass;
|
|
4438
4565
|
}
|
|
4439
4566
|
};
|
|
4440
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
|
+
|
|
4441
4691
|
// src/hooks/policies/host/lease.ts
|
|
4442
4692
|
function argvList2(value) {
|
|
4443
4693
|
const valid = Array.isArray(value) && value.every(
|
|
@@ -4549,7 +4799,7 @@ var operatorVerbs = {
|
|
|
4549
4799
|
};
|
|
4550
4800
|
|
|
4551
4801
|
// src/hooks/policies/custom.ts
|
|
4552
|
-
import { isAbsolute as
|
|
4802
|
+
import { isAbsolute as isAbsolute8, relative as relative8, resolve as resolve13 } from "node:path";
|
|
4553
4803
|
var FAILED = "Guard failed validation or execution";
|
|
4554
4804
|
var GUARD_PROTOCOL = "pmcp.guard.v1";
|
|
4555
4805
|
var MAX_FINDINGS = 20;
|
|
@@ -4566,8 +4816,8 @@ function customMode(entry) {
|
|
|
4566
4816
|
return entry.event === "session_start" && (mode === "deny" || mode === "ask") ? "warn" : mode;
|
|
4567
4817
|
}
|
|
4568
4818
|
function inside(base, path) {
|
|
4569
|
-
const rest =
|
|
4570
|
-
return rest !== "" && !rest.startsWith("..") && !
|
|
4819
|
+
const rest = relative8(base, path);
|
|
4820
|
+
return rest !== "" && !rest.startsWith("..") && !isAbsolute8(rest);
|
|
4571
4821
|
}
|
|
4572
4822
|
function guardScript(root, command6) {
|
|
4573
4823
|
const script = command6[0]?.startsWith(".agents/guards/") ? command6[0] : command6[1];
|
|
@@ -4576,12 +4826,12 @@ function guardScript(root, command6) {
|
|
|
4576
4826
|
"Hook command must execute a script under .agents/guards/, or name an installed program with version"
|
|
4577
4827
|
);
|
|
4578
4828
|
}
|
|
4579
|
-
const base =
|
|
4580
|
-
if (!inside(base,
|
|
4829
|
+
const base = resolve13(root, ".agents/guards");
|
|
4830
|
+
if (!inside(base, resolve13(root, script)))
|
|
4581
4831
|
throw new Error("Hook guard must stay under .agents/guards/");
|
|
4582
|
-
if (!existsSync(
|
|
4832
|
+
if (!existsSync(resolve13(root, script)))
|
|
4583
4833
|
throw new Error("Hook guard script must exist");
|
|
4584
|
-
const real4 = realpathSync(
|
|
4834
|
+
const real4 = realpathSync(resolve13(root, script));
|
|
4585
4835
|
if (!inside(realpathSync(base), real4))
|
|
4586
4836
|
throw new Error("Hook guard cannot resolve outside .agents/guards/");
|
|
4587
4837
|
return real4;
|
|
@@ -4642,7 +4892,7 @@ function run2(entry, input, log) {
|
|
|
4642
4892
|
};
|
|
4643
4893
|
}
|
|
4644
4894
|
const args = entry.command.map(
|
|
4645
|
-
(part) => part.startsWith(".agents/guards/") ?
|
|
4895
|
+
(part) => part.startsWith(".agents/guards/") ? resolve13(root, part) : part
|
|
4646
4896
|
);
|
|
4647
4897
|
const result = spawnSync(args[0], args.slice(1), {
|
|
4648
4898
|
cwd: root,
|
|
@@ -4659,9 +4909,9 @@ function run2(entry, input, log) {
|
|
|
4659
4909
|
const extra = Object.keys(response).some(
|
|
4660
4910
|
(key) => !["decision", "reason", "findings", "protocol"].includes(key)
|
|
4661
4911
|
);
|
|
4662
|
-
const
|
|
4912
|
+
const reason3 = response["reason"];
|
|
4663
4913
|
const findings = readFindings(response["findings"]);
|
|
4664
|
-
if (extra || findings === null ||
|
|
4914
|
+
if (extra || findings === null || reason3 !== void 0 && typeof reason3 !== "string" || response["protocol"] !== void 0 && response["protocol"] !== GUARD_PROTOCOL)
|
|
4665
4915
|
return { verdict: "deny", reason: FAILED };
|
|
4666
4916
|
const lines = findings.slice(0, MAX_FINDINGS).map(findingLine);
|
|
4667
4917
|
if (findings.length > MAX_FINDINGS)
|
|
@@ -4676,7 +4926,7 @@ function run2(entry, input, log) {
|
|
|
4676
4926
|
${lines.join("\n")}`] } : pass;
|
|
4677
4927
|
if (response["decision"] !== "deny")
|
|
4678
4928
|
return { verdict: "deny", reason: FAILED };
|
|
4679
|
-
const text9 = [typeof
|
|
4929
|
+
const text9 = [typeof reason3 === "string" ? reason3 : FAILED, ...lines].join(
|
|
4680
4930
|
"\n"
|
|
4681
4931
|
);
|
|
4682
4932
|
return { verdict: "deny", reason: text9.slice(0, MAX_REASON) };
|
|
@@ -4694,6 +4944,170 @@ function customPolicy(entry) {
|
|
|
4694
4944
|
};
|
|
4695
4945
|
}
|
|
4696
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
|
+
|
|
4697
5111
|
// src/hooks/policies/index.ts
|
|
4698
5112
|
var byId = (list) => Object.fromEntries(list.map((policy) => [policy.id, policy]));
|
|
4699
5113
|
var GUARDS = byId([
|
|
@@ -4704,6 +5118,7 @@ var GUARDS = byId([
|
|
|
4704
5118
|
hostApproval,
|
|
4705
5119
|
secretExfiltration,
|
|
4706
5120
|
runawayRegex,
|
|
5121
|
+
selfMatchingWait,
|
|
4707
5122
|
pushWithoutVerify,
|
|
4708
5123
|
forcedBranchMove,
|
|
4709
5124
|
gateBypassEnv,
|
|
@@ -4720,7 +5135,8 @@ var FEATURES = byId([
|
|
|
4720
5135
|
sharedCheckout,
|
|
4721
5136
|
worktreeSync,
|
|
4722
5137
|
mainlineDeliver,
|
|
4723
|
-
hostLease
|
|
5138
|
+
hostLease,
|
|
5139
|
+
owners
|
|
4724
5140
|
]);
|
|
4725
5141
|
var POLICIES = {
|
|
4726
5142
|
...FEATURES,
|
|
@@ -4767,7 +5183,14 @@ function selectPolicies(compiled, input) {
|
|
|
4767
5183
|
mode: customMode(entry),
|
|
4768
5184
|
options: {}
|
|
4769
5185
|
}));
|
|
4770
|
-
|
|
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
|
+
);
|
|
4771
5194
|
}
|
|
4772
5195
|
|
|
4773
5196
|
// src/hooks/dispatch/stop-loop.ts
|
|
@@ -4834,20 +5257,20 @@ function field(value, key) {
|
|
|
4834
5257
|
}
|
|
4835
5258
|
|
|
4836
5259
|
// src/hooks/runtimes/antigravity/output.ts
|
|
4837
|
-
var
|
|
5260
|
+
var MAX_REASON3 = 2e3;
|
|
4838
5261
|
function silent(event) {
|
|
4839
5262
|
return event === "before_tool" ? '{"decision":"allow"}\n' : "{}\n";
|
|
4840
5263
|
}
|
|
4841
5264
|
function render(input, decision) {
|
|
4842
5265
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
4843
|
-
const
|
|
5266
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON3);
|
|
4844
5267
|
if (input.event === "before_tool") {
|
|
4845
|
-
const out2 = blocking ? { decision: "deny", reason:
|
|
5268
|
+
const out2 = blocking ? { decision: "deny", reason: reason3 } : { decision: "allow" };
|
|
4846
5269
|
return { stdout: `${JSON.stringify(out2)}
|
|
4847
5270
|
`, exitCode: 0 };
|
|
4848
5271
|
}
|
|
4849
5272
|
const notes = [...decision.context ?? []];
|
|
4850
|
-
if (blocking) notes.unshift(
|
|
5273
|
+
if (blocking) notes.unshift(reason3);
|
|
4851
5274
|
if (decision.feedback) notes.push(decision.feedback);
|
|
4852
5275
|
let out = {};
|
|
4853
5276
|
if (notes.length > 0 && input.event !== "after_tool") {
|
|
@@ -4867,7 +5290,7 @@ function verdict(stdout) {
|
|
|
4867
5290
|
}
|
|
4868
5291
|
|
|
4869
5292
|
// src/hooks/runtimes/antigravity/payload.ts
|
|
4870
|
-
import { isAbsolute as
|
|
5293
|
+
import { isAbsolute as isAbsolute10, resolve as resolve15 } from "node:path";
|
|
4871
5294
|
function object(value) {
|
|
4872
5295
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
4873
5296
|
}
|
|
@@ -4893,7 +5316,7 @@ function normalize(nativeEvent, payload, projectRoot) {
|
|
|
4893
5316
|
const name = text3(call["name"]);
|
|
4894
5317
|
const kind = name ? toolKind(name) : void 0;
|
|
4895
5318
|
const target = text3(args["TargetFile"]);
|
|
4896
|
-
const paths = target ? [
|
|
5319
|
+
const paths = target ? [isAbsolute10(target) ? target : resolve15(cwd, target)] : [];
|
|
4897
5320
|
return {
|
|
4898
5321
|
contract: 2,
|
|
4899
5322
|
runtime: "antigravity",
|
|
@@ -5044,23 +5467,23 @@ function matcherFor(tools) {
|
|
|
5044
5467
|
}
|
|
5045
5468
|
|
|
5046
5469
|
// src/hooks/runtimes/claude/output.ts
|
|
5047
|
-
var
|
|
5470
|
+
var MAX_REASON4 = 2e3;
|
|
5048
5471
|
function render2(input, decision) {
|
|
5049
5472
|
const hookEventName = NATIVE_EVENTS2[input.event];
|
|
5050
5473
|
const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
|
|
5051
|
-
const
|
|
5474
|
+
const reason3 = decision.reason?.slice(0, MAX_REASON4);
|
|
5052
5475
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5053
5476
|
const out = shape(input, decision, {
|
|
5054
5477
|
hookEventName,
|
|
5055
5478
|
context,
|
|
5056
|
-
reason:
|
|
5479
|
+
reason: reason3,
|
|
5057
5480
|
blocking
|
|
5058
5481
|
});
|
|
5059
5482
|
return { stdout: out ? `${JSON.stringify(out)}
|
|
5060
5483
|
` : "", exitCode: 0 };
|
|
5061
5484
|
}
|
|
5062
5485
|
function shape(input, decision, parts) {
|
|
5063
|
-
const { hookEventName, context, reason:
|
|
5486
|
+
const { hookEventName, context, reason: reason3, blocking } = parts;
|
|
5064
5487
|
const contextOnly = context ? { hookSpecificOutput: { hookEventName, additionalContext: context } } : {};
|
|
5065
5488
|
if (input.event === "before_tool") {
|
|
5066
5489
|
if (!blocking && !context) return null;
|
|
@@ -5068,7 +5491,7 @@ function shape(input, decision, parts) {
|
|
|
5068
5491
|
if (blocking) {
|
|
5069
5492
|
refusal = {
|
|
5070
5493
|
permissionDecision: decision.verdict,
|
|
5071
|
-
...
|
|
5494
|
+
...reason3 ? { permissionDecisionReason: reason3 } : {}
|
|
5072
5495
|
};
|
|
5073
5496
|
}
|
|
5074
5497
|
return {
|
|
@@ -5080,7 +5503,7 @@ function shape(input, decision, parts) {
|
|
|
5080
5503
|
};
|
|
5081
5504
|
}
|
|
5082
5505
|
if (input.event === "prompt" || input.event === "after_tool" || input.event === "stop") {
|
|
5083
|
-
const feedback = blocking ?
|
|
5506
|
+
const feedback = blocking ? reason3 ?? "Refused" : decision.feedback;
|
|
5084
5507
|
if (!feedback && !context) return null;
|
|
5085
5508
|
return {
|
|
5086
5509
|
...feedback ? { decision: "block", reason: feedback } : {},
|
|
@@ -5098,7 +5521,7 @@ function verdict2(stdout) {
|
|
|
5098
5521
|
}
|
|
5099
5522
|
|
|
5100
5523
|
// src/hooks/runtimes/claude/payload.ts
|
|
5101
|
-
import { isAbsolute as
|
|
5524
|
+
import { isAbsolute as isAbsolute11, resolve as resolve16 } from "node:path";
|
|
5102
5525
|
function object2(value) {
|
|
5103
5526
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5104
5527
|
}
|
|
@@ -5115,7 +5538,7 @@ function normalize2(nativeEvent, payload, projectRoot) {
|
|
|
5115
5538
|
toolInput["file_path"],
|
|
5116
5539
|
toolInput["notebook_path"],
|
|
5117
5540
|
kind === "read" ? toolInput["path"] : void 0
|
|
5118
|
-
].filter((value) => typeof value === "string" && !!value).map((path) =>
|
|
5541
|
+
].filter((value) => typeof value === "string" && !!value).map((path) => isAbsolute11(path) ? path : resolve16(cwd, path));
|
|
5119
5542
|
const agentType = text4(raw["agent_type"]);
|
|
5120
5543
|
const turnId = text4(raw["prompt_id"]);
|
|
5121
5544
|
const lastMessage = text4(raw["last_assistant_message"]);
|
|
@@ -5155,10 +5578,30 @@ function toolFields(name, kind, input, paths) {
|
|
|
5155
5578
|
kind,
|
|
5156
5579
|
native: name,
|
|
5157
5580
|
...kind === "shell" ? { command: text4(input["command"]) ?? "" } : {},
|
|
5158
|
-
paths
|
|
5581
|
+
paths,
|
|
5582
|
+
...editFields(name, input, paths)
|
|
5159
5583
|
}
|
|
5160
5584
|
};
|
|
5161
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
|
+
}
|
|
5162
5605
|
function stopFields(event, raw, lastMessage) {
|
|
5163
5606
|
if (event !== "stop") return {};
|
|
5164
5607
|
return {
|
|
@@ -5301,16 +5744,16 @@ function matcherFor2(tools) {
|
|
|
5301
5744
|
}
|
|
5302
5745
|
|
|
5303
5746
|
// src/hooks/runtimes/codex/output.ts
|
|
5304
|
-
var
|
|
5747
|
+
var MAX_REASON5 = 2e3;
|
|
5305
5748
|
function render3(input, decision) {
|
|
5306
5749
|
const hookEventName = NATIVE_EVENTS3[input.event];
|
|
5307
5750
|
const context = decision.context?.length ? decision.context.join("\n\n") : void 0;
|
|
5308
|
-
const
|
|
5751
|
+
const reason3 = decision.reason?.slice(0, MAX_REASON5);
|
|
5309
5752
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5310
5753
|
const out = shape2(input, decision, {
|
|
5311
5754
|
hookEventName,
|
|
5312
5755
|
context,
|
|
5313
|
-
reason:
|
|
5756
|
+
reason: reason3,
|
|
5314
5757
|
blocking
|
|
5315
5758
|
});
|
|
5316
5759
|
if (!out && input.event === "stop") return { stdout: "{}\n", exitCode: 0 };
|
|
@@ -5318,7 +5761,7 @@ function render3(input, decision) {
|
|
|
5318
5761
|
` : "", exitCode: 0 };
|
|
5319
5762
|
}
|
|
5320
5763
|
function shape2(input, decision, parts) {
|
|
5321
|
-
const { hookEventName, context, reason:
|
|
5764
|
+
const { hookEventName, context, reason: reason3, blocking } = parts;
|
|
5322
5765
|
const contextOnly = context ? { hookSpecificOutput: { hookEventName, additionalContext: context } } : {};
|
|
5323
5766
|
if (input.event === "before_tool") {
|
|
5324
5767
|
if (!blocking && !context) return null;
|
|
@@ -5326,7 +5769,7 @@ function shape2(input, decision, parts) {
|
|
|
5326
5769
|
if (blocking) {
|
|
5327
5770
|
refusal = {
|
|
5328
5771
|
permissionDecision: "deny",
|
|
5329
|
-
...
|
|
5772
|
+
...reason3 ? { permissionDecisionReason: reason3 } : {}
|
|
5330
5773
|
};
|
|
5331
5774
|
}
|
|
5332
5775
|
return {
|
|
@@ -5338,7 +5781,7 @@ function shape2(input, decision, parts) {
|
|
|
5338
5781
|
};
|
|
5339
5782
|
}
|
|
5340
5783
|
if (input.event === "prompt" || input.event === "after_tool" || input.event === "stop") {
|
|
5341
|
-
const feedback = blocking ?
|
|
5784
|
+
const feedback = blocking ? reason3 ?? "Refused" : decision.feedback;
|
|
5342
5785
|
if (!feedback && !context) return null;
|
|
5343
5786
|
return {
|
|
5344
5787
|
...feedback ? { decision: "block", reason: feedback } : {},
|
|
@@ -5356,7 +5799,7 @@ function verdict3(stdout) {
|
|
|
5356
5799
|
}
|
|
5357
5800
|
|
|
5358
5801
|
// src/hooks/runtimes/codex/payload.ts
|
|
5359
|
-
import { isAbsolute as
|
|
5802
|
+
import { isAbsolute as isAbsolute12, resolve as resolve17 } from "node:path";
|
|
5360
5803
|
var PATCH_HEADER = /^\*\*\* (?:Update File|Add File|Delete File|Move to): (.+)$/gmu;
|
|
5361
5804
|
function object3(value) {
|
|
5362
5805
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -5374,7 +5817,7 @@ function normalize3(nativeEvent, payload, projectRoot) {
|
|
|
5374
5817
|
const toolInput = object3(raw["tool_input"]);
|
|
5375
5818
|
const kind = name ? toolKind3(name) : void 0;
|
|
5376
5819
|
const body = text5(toolInput["command"]) ?? "";
|
|
5377
|
-
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));
|
|
5378
5821
|
const turnId = text5(raw["turn_id"]);
|
|
5379
5822
|
const lastMessage = text5(raw["last_assistant_message"]);
|
|
5380
5823
|
const prompt = text5(raw["prompt"]);
|
|
@@ -5542,7 +5985,7 @@ function matcherFor3(tools) {
|
|
|
5542
5985
|
}
|
|
5543
5986
|
|
|
5544
5987
|
// src/hooks/runtimes/gemini/output.ts
|
|
5545
|
-
var
|
|
5988
|
+
var MAX_REASON6 = 2e3;
|
|
5546
5989
|
var DELIVERS = [
|
|
5547
5990
|
"session_start",
|
|
5548
5991
|
"prompt",
|
|
@@ -5550,12 +5993,12 @@ var DELIVERS = [
|
|
|
5550
5993
|
];
|
|
5551
5994
|
function render4(input, decision) {
|
|
5552
5995
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5553
|
-
const
|
|
5996
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON6);
|
|
5554
5997
|
const out = {};
|
|
5555
5998
|
const notes = [...decision.context ?? []];
|
|
5556
5999
|
if (blocking && input.event === "before_tool")
|
|
5557
|
-
Object.assign(out, { decision: "deny", reason:
|
|
5558
|
-
else if (blocking) notes.unshift(
|
|
6000
|
+
Object.assign(out, { decision: "deny", reason: reason3 });
|
|
6001
|
+
else if (blocking) notes.unshift(reason3);
|
|
5559
6002
|
if (decision.feedback) notes.push(decision.feedback);
|
|
5560
6003
|
if (notes.length > 0 && DELIVERS.includes(input.event))
|
|
5561
6004
|
out["hookSpecificOutput"] = {
|
|
@@ -5573,7 +6016,7 @@ function verdict4(stdout) {
|
|
|
5573
6016
|
}
|
|
5574
6017
|
|
|
5575
6018
|
// src/hooks/runtimes/gemini/payload.ts
|
|
5576
|
-
import { isAbsolute as
|
|
6019
|
+
import { isAbsolute as isAbsolute13, resolve as resolve18 } from "node:path";
|
|
5577
6020
|
function object4(value) {
|
|
5578
6021
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5579
6022
|
}
|
|
@@ -5586,7 +6029,7 @@ function normalize4(nativeEvent, payload, projectRoot) {
|
|
|
5586
6029
|
const name = text6(raw["tool_name"]);
|
|
5587
6030
|
const input = object4(raw["tool_input"]);
|
|
5588
6031
|
const kind = name ? toolKind4(name) : void 0;
|
|
5589
|
-
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));
|
|
5590
6033
|
const prompt = text6(raw["prompt"]);
|
|
5591
6034
|
const lastMessage = text6(raw["prompt_response"]);
|
|
5592
6035
|
return {
|
|
@@ -5738,7 +6181,7 @@ function toolKind5(name) {
|
|
|
5738
6181
|
}
|
|
5739
6182
|
|
|
5740
6183
|
// src/hooks/runtimes/grok/output.ts
|
|
5741
|
-
var
|
|
6184
|
+
var MAX_REASON7 = 2e3;
|
|
5742
6185
|
var DELIVERS2 = [
|
|
5743
6186
|
"before_tool",
|
|
5744
6187
|
"after_tool",
|
|
@@ -5746,10 +6189,10 @@ var DELIVERS2 = [
|
|
|
5746
6189
|
];
|
|
5747
6190
|
function render5(input, decision) {
|
|
5748
6191
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5749
|
-
const
|
|
6192
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON7);
|
|
5750
6193
|
const notes = [...decision.context ?? []];
|
|
5751
6194
|
const refuse = blocking && input.event === "before_tool";
|
|
5752
|
-
if (blocking && !refuse) notes.unshift(
|
|
6195
|
+
if (blocking && !refuse) notes.unshift(reason3);
|
|
5753
6196
|
if (decision.feedback) notes.push(decision.feedback);
|
|
5754
6197
|
const quiet = input.event === "stop" && input.stop?.active === true;
|
|
5755
6198
|
const context = notes.length > 0 && DELIVERS2.includes(input.event) && !quiet ? notes.join("\n\n") : void 0;
|
|
@@ -5757,7 +6200,7 @@ function render5(input, decision) {
|
|
|
5757
6200
|
const out = {
|
|
5758
6201
|
hookSpecificOutput: {
|
|
5759
6202
|
hookEventName: NATIVE_EVENTS5[input.event],
|
|
5760
|
-
...refuse ? { permissionDecision: "deny", permissionDecisionReason:
|
|
6203
|
+
...refuse ? { permissionDecision: "deny", permissionDecisionReason: reason3 } : {},
|
|
5761
6204
|
...context ? { additionalContext: context } : {}
|
|
5762
6205
|
}
|
|
5763
6206
|
};
|
|
@@ -5772,7 +6215,7 @@ function verdict5(stdout) {
|
|
|
5772
6215
|
}
|
|
5773
6216
|
|
|
5774
6217
|
// src/hooks/runtimes/grok/payload.ts
|
|
5775
|
-
import { isAbsolute as
|
|
6218
|
+
import { isAbsolute as isAbsolute14, resolve as resolve19 } from "node:path";
|
|
5776
6219
|
function object5(value) {
|
|
5777
6220
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5778
6221
|
}
|
|
@@ -5790,7 +6233,7 @@ function normalize5(nativeEvent, payload, projectRoot) {
|
|
|
5790
6233
|
const input = object5(raw["toolInput"] ?? raw["tool_input"]);
|
|
5791
6234
|
const kind = name ? toolKind5(name) : void 0;
|
|
5792
6235
|
const path = text7(input["file_path"]);
|
|
5793
|
-
const paths = path ? [
|
|
6236
|
+
const paths = path ? [isAbsolute14(path) ? path : resolve19(cwd, path)] : [];
|
|
5794
6237
|
const turnId = text7(raw["promptId"]);
|
|
5795
6238
|
const prompt = text7(raw["prompt"]);
|
|
5796
6239
|
const lastMessage = text7(raw["lastAssistantMessage"]);
|
|
@@ -5946,7 +6389,7 @@ function toolKind6(name) {
|
|
|
5946
6389
|
}
|
|
5947
6390
|
|
|
5948
6391
|
// src/hooks/runtimes/opencode/output.ts
|
|
5949
|
-
var
|
|
6392
|
+
var MAX_REASON8 = 2e3;
|
|
5950
6393
|
var DELIVERS3 = [
|
|
5951
6394
|
"session_start",
|
|
5952
6395
|
"prompt",
|
|
@@ -5954,14 +6397,14 @@ var DELIVERS3 = [
|
|
|
5954
6397
|
];
|
|
5955
6398
|
function render6(input, decision) {
|
|
5956
6399
|
const blocking = decision.verdict === "deny" || decision.verdict === "ask";
|
|
5957
|
-
const
|
|
6400
|
+
const reason3 = (decision.reason ?? "Refused by pmcp").slice(0, MAX_REASON8);
|
|
5958
6401
|
if (input.event === "before_tool") {
|
|
5959
|
-
const out2 = blocking ? { deny:
|
|
6402
|
+
const out2 = blocking ? { deny: reason3 } : {};
|
|
5960
6403
|
return { stdout: `${JSON.stringify(out2)}
|
|
5961
6404
|
`, exitCode: 0 };
|
|
5962
6405
|
}
|
|
5963
6406
|
const notes = [...decision.context ?? []];
|
|
5964
|
-
if (blocking) notes.unshift(
|
|
6407
|
+
if (blocking) notes.unshift(reason3);
|
|
5965
6408
|
if (decision.feedback) notes.push(decision.feedback);
|
|
5966
6409
|
const out = notes.length > 0 && DELIVERS3.includes(input.event) ? { context: notes.join("\n\n") } : {};
|
|
5967
6410
|
return { stdout: `${JSON.stringify(out)}
|
|
@@ -5972,7 +6415,7 @@ function verdict6(stdout) {
|
|
|
5972
6415
|
}
|
|
5973
6416
|
|
|
5974
6417
|
// src/hooks/runtimes/opencode/payload.ts
|
|
5975
|
-
import { isAbsolute as
|
|
6418
|
+
import { isAbsolute as isAbsolute15, resolve as resolve20 } from "node:path";
|
|
5976
6419
|
function object6(value) {
|
|
5977
6420
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5978
6421
|
}
|
|
@@ -5988,7 +6431,7 @@ function normalize6(nativeEvent, payload, projectRoot) {
|
|
|
5988
6431
|
const args = object6(raw["args"] ?? input["args"]);
|
|
5989
6432
|
const kind = name ? toolKind6(name) : void 0;
|
|
5990
6433
|
const path = text8(args["filePath"]);
|
|
5991
|
-
const paths = path ? [
|
|
6434
|
+
const paths = path ? [isAbsolute15(path) ? path : resolve20(cwd, path)] : [];
|
|
5992
6435
|
const session = text8(input["sessionID"]) ?? text8(properties["sessionID"]) ?? "";
|
|
5993
6436
|
return {
|
|
5994
6437
|
contract: 2,
|
|
@@ -6213,18 +6656,18 @@ async function dispatch(raw, compiled, deps) {
|
|
|
6213
6656
|
}
|
|
6214
6657
|
|
|
6215
6658
|
// src/hooks/entry/fail-closed.ts
|
|
6216
|
-
import { join as
|
|
6659
|
+
import { join as join15 } from "node:path";
|
|
6217
6660
|
|
|
6218
6661
|
// src/hooks/compiled.ts
|
|
6219
|
-
import { join as
|
|
6662
|
+
import { join as join14 } from "node:path";
|
|
6220
6663
|
|
|
6221
6664
|
// src/hooks/integrity-cache.ts
|
|
6222
|
-
import { homedir as
|
|
6223
|
-
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";
|
|
6224
6667
|
var LIMIT = 64;
|
|
6225
6668
|
function cacheFile() {
|
|
6226
|
-
const base = process.env["XDG_CACHE_HOME"] ||
|
|
6227
|
-
return
|
|
6669
|
+
const base = process.env["XDG_CACHE_HOME"] || join13(homedir4(), ".cache");
|
|
6670
|
+
return join13(base, "pmcp", "hook-verified.json");
|
|
6228
6671
|
}
|
|
6229
6672
|
function readCache() {
|
|
6230
6673
|
try {
|
|
@@ -6294,8 +6737,8 @@ function readLockFile(path) {
|
|
|
6294
6737
|
}
|
|
6295
6738
|
}
|
|
6296
6739
|
function readCompiled(root) {
|
|
6297
|
-
const policyPath =
|
|
6298
|
-
const files2 = [policyPath,
|
|
6740
|
+
const policyPath = join14(root, POLICY_FILE);
|
|
6741
|
+
const files2 = [policyPath, join14(root, LOCK_FILE)];
|
|
6299
6742
|
const before2 = stampOf(files2);
|
|
6300
6743
|
const text9 = readFileSync(policyPath, "utf8");
|
|
6301
6744
|
const lock = readLockFile(files2[1]);
|
|
@@ -6318,7 +6761,7 @@ function readCompiled(root) {
|
|
|
6318
6761
|
var FAILED_CLOSED = "pmcp hook could not evaluate this call and refused it";
|
|
6319
6762
|
function rawFailure(root) {
|
|
6320
6763
|
try {
|
|
6321
|
-
const raw = JSON.parse(readFileSync(
|
|
6764
|
+
const raw = JSON.parse(readFileSync(join15(root, POLICY_FILE), "utf8"))["failure"];
|
|
6322
6765
|
if (!raw || typeof raw.timeoutMs !== "number" || typeof raw.retry !== "number" || !Array.isArray(raw.pass) || !raw.pass.every(
|
|
6323
6766
|
(kind) => PASS_KINDS.includes(kind)
|
|
6324
6767
|
))
|
|
@@ -6340,7 +6783,7 @@ function failedEntry(adapter, event, root, input, failure, error) {
|
|
|
6340
6783
|
}
|
|
6341
6784
|
function failClosed(adapter, event, root, error, stated = false) {
|
|
6342
6785
|
if (event !== "before_tool") return "";
|
|
6343
|
-
const
|
|
6786
|
+
const reason3 = error instanceof PolicyIntegrityError || stated && error instanceof Error ? error.message : FAILED_CLOSED;
|
|
6344
6787
|
const input = {
|
|
6345
6788
|
contract: 2,
|
|
6346
6789
|
runtime: adapter.id,
|
|
@@ -6349,11 +6792,11 @@ function failClosed(adapter, event, root, error, stated = false) {
|
|
|
6349
6792
|
cwd: root,
|
|
6350
6793
|
projectRoot: root
|
|
6351
6794
|
};
|
|
6352
|
-
return adapter.render(input, { verdict: "deny", reason:
|
|
6795
|
+
return adapter.render(input, { verdict: "deny", reason: reason3 }).stdout;
|
|
6353
6796
|
}
|
|
6354
6797
|
|
|
6355
6798
|
// src/hooks/entry/lock-repair.ts
|
|
6356
|
-
import { join as
|
|
6799
|
+
import { join as join16, resolve as resolve21 } from "node:path";
|
|
6357
6800
|
var REV = /^[\w./~^@{}][\w./~^@{}-]*$/u;
|
|
6358
6801
|
var LOCK_PATHS = /* @__PURE__ */ new Set([LOCK_FILE, `./${LOCK_FILE}`]);
|
|
6359
6802
|
var RESTORE_OPTIONS = /* @__PURE__ */ new Set([
|
|
@@ -6397,8 +6840,8 @@ function repairsLock(input, root) {
|
|
|
6397
6840
|
if (!tool) return false;
|
|
6398
6841
|
if (tool.kind === "read") return true;
|
|
6399
6842
|
if (tool.kind === "edit") {
|
|
6400
|
-
const lock =
|
|
6401
|
-
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);
|
|
6402
6845
|
}
|
|
6403
6846
|
if (tool.kind === "shell") return restoresLock(tool.command ?? "");
|
|
6404
6847
|
return false;
|
|
@@ -6539,11 +6982,11 @@ var silentLogger = createLogger(() => {
|
|
|
6539
6982
|
});
|
|
6540
6983
|
|
|
6541
6984
|
// src/logging/sinks/file.ts
|
|
6542
|
-
import { join as
|
|
6985
|
+
import { join as join17 } from "node:path";
|
|
6543
6986
|
var FILE = /^pmcp-(\d{8})(?:\.\d+)?\.jsonl$/u;
|
|
6544
6987
|
function dailyLogFile(dir, now = /* @__PURE__ */ new Date()) {
|
|
6545
6988
|
const day = now.toISOString().slice(0, 10).replaceAll("-", "");
|
|
6546
|
-
return
|
|
6989
|
+
return join17(dir, `pmcp-${day}.jsonl`);
|
|
6547
6990
|
}
|
|
6548
6991
|
function roll(file2) {
|
|
6549
6992
|
let index = 1;
|
|
@@ -6574,7 +7017,7 @@ function logFiles(dir) {
|
|
|
6574
7017
|
const part = (name) => Number(/\.(\d+)\.jsonl$/u.exec(name)?.[1] ?? Number.MAX_SAFE_INTEGER);
|
|
6575
7018
|
return names4.sort(
|
|
6576
7019
|
(a, b) => a.slice(5, 13).localeCompare(b.slice(5, 13)) || part(a) - part(b)
|
|
6577
|
-
).map((name) =>
|
|
7020
|
+
).map((name) => join17(dir, name));
|
|
6578
7021
|
}
|
|
6579
7022
|
function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
|
|
6580
7023
|
const cutoff = new Date(now.getTime() - keepDays * 864e5).toISOString().slice(0, 10).replaceAll("-", "");
|
|
@@ -6588,17 +7031,6 @@ function pruneLogs(dir, keepDays, now = /* @__PURE__ */ new Date()) {
|
|
|
6588
7031
|
return removed;
|
|
6589
7032
|
}
|
|
6590
7033
|
|
|
6591
|
-
// src/sessions/state-dir.ts
|
|
6592
|
-
import { homedir as homedir4 } from "node:os";
|
|
6593
|
-
import { join as join17 } from "node:path";
|
|
6594
|
-
function projectStateDir(root, override, env = process.env) {
|
|
6595
|
-
if (override) return expandPath(root, override);
|
|
6596
|
-
const anchor = gitCommonDir(root) ?? realpathSync(root);
|
|
6597
|
-
const id = createHash("sha256").update(anchor).digest("hex").slice(0, 16);
|
|
6598
|
-
const base = env["XDG_STATE_HOME"] || join17(homedir4(), ".local", "state");
|
|
6599
|
-
return join17(base, "pmcp", "projects", id);
|
|
6600
|
-
}
|
|
6601
|
-
|
|
6602
7034
|
// src/hooks/entry/logger.ts
|
|
6603
7035
|
function traceId() {
|
|
6604
7036
|
const high = Math.floor(Math.random() * 2 ** 32);
|
|
@@ -6630,7 +7062,7 @@ function hookLogger(root, compiled, runtime2, event) {
|
|
|
6630
7062
|
import { join as join20 } from "node:path";
|
|
6631
7063
|
|
|
6632
7064
|
// src/sessions/lease-files.ts
|
|
6633
|
-
import { dirname as dirname10, isAbsolute as
|
|
7065
|
+
import { dirname as dirname10, isAbsolute as isAbsolute16, join as join19 } from "node:path";
|
|
6634
7066
|
var GATE_DIR = "${gate_dir}/";
|
|
6635
7067
|
function gateTree(root, stateDir, gate, env) {
|
|
6636
7068
|
const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
|
|
@@ -6644,11 +7076,11 @@ function resolvePauseFile(file2, gateDir) {
|
|
|
6644
7076
|
return file2 === void 0 ? void 0 : atGateDir(file2, gateDir);
|
|
6645
7077
|
}
|
|
6646
7078
|
function resolveLeaseFiles(files2, gateDir) {
|
|
6647
|
-
const
|
|
7079
|
+
const resolve23 = (path) => path === void 0 ? void 0 : atGateDir(path, gateDir);
|
|
6648
7080
|
return Object.fromEntries(
|
|
6649
7081
|
Object.entries(files2 ?? {}).map(([name, f]) => {
|
|
6650
|
-
const file2 =
|
|
6651
|
-
const events2 =
|
|
7082
|
+
const file2 = resolve23(f.file);
|
|
7083
|
+
const events2 = resolve23(f.events);
|
|
6652
7084
|
return [
|
|
6653
7085
|
name,
|
|
6654
7086
|
{ ...file2 ? { file: file2 } : {}, ...events2 ? { events: events2 } : {} }
|
|
@@ -7215,10 +7647,10 @@ async function main(argv, root) {
|
|
|
7215
7647
|
}
|
|
7216
7648
|
}
|
|
7217
7649
|
var self = import.meta.filename;
|
|
7218
|
-
if (process.argv[1] &&
|
|
7650
|
+
if (process.argv[1] && resolve22(process.argv[1]) === self) {
|
|
7219
7651
|
process.exitCode = await main(
|
|
7220
7652
|
process.argv.slice(2),
|
|
7221
|
-
|
|
7653
|
+
resolve22(dirname13(self), "../..")
|
|
7222
7654
|
);
|
|
7223
7655
|
}
|
|
7224
7656
|
export {
|