@modootoday/pmcp 0.17.4 → 0.18.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/CHANGELOG.md +60 -0
- package/README.md +29 -24
- package/dist/apply-4IGTXOCQ.js +242 -0
- package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
- package/dist/available-DBSIVVJ6.js +73 -0
- package/dist/broadcast-3RY3OZGY.js +18 -0
- package/dist/chunk-25GHX674.js +1246 -0
- package/dist/chunk-2P4Z2NUX.js +28 -0
- package/dist/chunk-34DECPVC.js +22 -0
- package/dist/chunk-3NYG4SGU.js +45 -0
- package/dist/chunk-3PW4FI7U.js +32 -0
- package/dist/chunk-3Y3HDMHA.js +108 -0
- package/dist/chunk-47O3X4VS.js +113 -0
- package/dist/chunk-4NDEP7HU.js +26 -0
- package/dist/chunk-4VCC2NXE.js +104 -0
- package/dist/chunk-5OMOPUE6.js +39 -0
- package/dist/chunk-5QQWS4US.js +53 -0
- package/dist/chunk-5ZABTVSW.js +48 -0
- package/dist/chunk-65ZHM5RH.js +4985 -0
- package/dist/chunk-665TA55Z.js +419 -0
- package/dist/chunk-6STKGOCW.js +27 -0
- package/dist/chunk-6WXMJOMI.js +9 -0
- package/dist/chunk-73AKO4UL.js +24 -0
- package/dist/chunk-7BLPN3W6.js +31 -0
- package/dist/chunk-7DLZC73N.js +29 -0
- package/dist/chunk-7GBYECSK.js +72 -0
- package/dist/chunk-7TD53M7L.js +13 -0
- package/dist/chunk-A4PKLESO.js +112 -0
- package/dist/chunk-ABTJQ4QV.js +74 -0
- package/dist/chunk-BBTBJCFA.js +380 -0
- package/dist/chunk-BU65MNVU.js +13 -0
- package/dist/chunk-BVCTKPT3.js +83 -0
- package/dist/chunk-C4NHQGHL.js +142 -0
- package/dist/chunk-CJTKR6K6.js +1213 -0
- package/dist/chunk-DCU2EXQV.js +78 -0
- package/dist/chunk-DZ2MRTYT.js +135 -0
- package/dist/chunk-E2YOZ2FF.js +207 -0
- package/dist/chunk-E3DQB5LS.js +48 -0
- package/dist/chunk-E7OOHLQR.js +7 -0
- package/dist/chunk-EATCUWGG.js +66 -0
- package/dist/chunk-EIDIVIAD.js +33 -0
- package/dist/chunk-EJBZGIDK.js +1934 -0
- package/dist/chunk-ELAGZ635.js +252 -0
- package/dist/chunk-GZHHEHKY.js +44 -0
- package/dist/chunk-HDMBVLCZ.js +53 -0
- package/dist/chunk-HQOB7OQS.js +81 -0
- package/dist/chunk-IGYRMM62.js +28 -0
- package/dist/chunk-IJBSOWHK.js +86 -0
- package/dist/chunk-INT7QLEU.js +114 -0
- package/dist/chunk-J6QLLQVL.js +1025 -0
- package/dist/chunk-J7UYNJCR.js +9 -0
- package/dist/chunk-JEL35P7S.js +53 -0
- package/dist/chunk-JGJ4INEN.js +32 -0
- package/dist/chunk-JS5RTH4I.js +84 -0
- package/dist/chunk-JUXNIXN4.js +42 -0
- package/dist/chunk-JWRZDYB5.js +59 -0
- package/dist/chunk-KMXRRSKT.js +660 -0
- package/dist/chunk-LAZQBMAU.js +67 -0
- package/dist/chunk-LLBPVZXM.js +67 -0
- package/dist/chunk-LLT5FQBE.js +57 -0
- package/dist/chunk-LMT3PPXJ.js +17 -0
- package/dist/chunk-MM2Y43LC.js +87 -0
- package/dist/chunk-MPSQXSC6.js +346 -0
- package/dist/chunk-MVFH26QT.js +97 -0
- package/dist/chunk-MWFOUBFC.js +39 -0
- package/dist/chunk-N5AQ3PP7.js +211 -0
- package/dist/chunk-NQPURJT5.js +44 -0
- package/dist/chunk-NRBQK6UX.js +105 -0
- package/dist/chunk-NZS5CD72.js +333 -0
- package/dist/chunk-OEH47H6A.js +48 -0
- package/dist/chunk-OG7QR2DP.js +75 -0
- package/dist/chunk-OPYFEHKG.js +52 -0
- package/dist/chunk-P4N7DBD5.js +83 -0
- package/dist/chunk-PAX3QXX2.js +140 -0
- package/dist/chunk-PLX3BOOS.js +396 -0
- package/dist/chunk-PMJG2CXF.js +122 -0
- package/dist/chunk-PWSJJXLQ.js +643 -0
- package/dist/chunk-Q5H3L6Y4.js +23 -0
- package/dist/chunk-Q65R3XKX.js +155 -0
- package/dist/chunk-QEW4J3IZ.js +74 -0
- package/dist/chunk-QPL7E2HW.js +464 -0
- package/dist/chunk-R2GPCZUX.js +22 -0
- package/dist/chunk-R4L6LJJ2.js +778 -0
- package/dist/chunk-R5MT42JS.js +284 -0
- package/dist/chunk-RK4PYD7L.js +73 -0
- package/dist/chunk-RMATE45Z.js +197 -0
- package/dist/chunk-S3PIAMXV.js +230 -0
- package/dist/chunk-SG5TPMKH.js +93 -0
- package/dist/chunk-T3LKX23M.js +168 -0
- package/dist/chunk-T6GOWHK6.js +30 -0
- package/dist/chunk-TIA4SPU2.js +10 -0
- package/dist/chunk-TNCZ6444.js +57 -0
- package/dist/chunk-TVL5RTE6.js +269 -0
- package/dist/chunk-UOCLRM7P.js +151 -0
- package/dist/chunk-UPQTAHUK.js +189 -0
- package/dist/chunk-V4NPDK6X.js +14 -0
- package/dist/chunk-VJFEN6DJ.js +38 -0
- package/dist/chunk-WIW772I3.js +25 -0
- package/dist/chunk-XELAZAIM.js +136 -0
- package/dist/chunk-XNML2KIC.js +23 -0
- package/dist/chunk-XP2U3LO3.js +30 -0
- package/dist/chunk-YGOWIJPE.js +51 -0
- package/dist/chunk-YIXDHQYE.js +11 -0
- package/dist/chunk-YMHUM7AV.js +22 -0
- package/dist/chunk-YSAWTGNA.js +117 -0
- package/dist/chunk-Z4HRRXRF.js +478 -0
- package/dist/chunk-ZH6R642Z.js +102 -0
- package/dist/claude-U2JC2DNQ.js +77 -0
- package/dist/cli-VYCQJZ5X.js +41 -0
- package/dist/cli-ZTCBSDW4.js +46 -0
- package/dist/cli.js +144 -16197
- package/dist/completion-E7RRG3ZT.js +142 -0
- package/dist/config-DnpLL2kT.d.ts +46 -0
- package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
- package/dist/diagnostics-XXH4FLUG.js +93 -0
- package/dist/doctor-ZIOESU3N.js +538 -0
- package/dist/entry-ZNFCTDVE.js +305 -0
- package/dist/exec-mcp-X6372BLE.js +365 -0
- package/dist/harness-F2XFDYXF.js +177 -0
- package/dist/harness-egress-bridge.js +4 -4
- package/dist/harness-launch-gate.js +47 -940
- package/dist/harness-pane-runner.js +13 -80
- package/dist/harness-worker.js +21 -2703
- package/dist/hook-body.js +5221 -0
- package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
- package/dist/hook.js +26 -0
- package/dist/hooks-FYE2L5RW.js +21 -0
- package/dist/host-GRY3VAHH.js +22 -0
- package/dist/host-X6BR6X4O.js +200 -0
- package/dist/host-run-GCA6H6SR.js +307 -0
- package/dist/http.d.ts +5 -42
- package/dist/http.js +21 -2234
- package/dist/import-mcp-2TTBPVLY.js +400 -0
- package/dist/index.d.ts +146 -168
- package/dist/index.js +133 -4948
- package/dist/init-627KFXTG.js +14 -0
- package/dist/install-GG7HHZK2.js +796 -0
- package/dist/invoke-LW22Z6ET.js +23 -0
- package/dist/list-MCP2FXUF.js +68 -0
- package/dist/list-NGMSQ5SH.js +65 -0
- package/dist/load-BEUBABtB.d.ts +21 -0
- package/dist/logout-6CSHUWWE.js +44 -0
- package/dist/logs-SPB6AANY.js +107 -0
- package/dist/mailbox/index.d.ts +10 -5
- package/dist/mailbox/index.js +53 -1572
- package/dist/mailbox-7BV54Q4R.js +285 -0
- package/dist/mailbox-GDJ7BWQN.js +189 -0
- package/dist/mainline-JQTTYJMI.js +639 -0
- package/dist/marketplace-G4VQET5W.js +191 -0
- package/dist/mcp-2DKVU3SW.js +15 -0
- package/dist/mcp-V23HC3LB.js +193 -0
- package/dist/models-ISU4DCMA.js +32 -0
- package/dist/opencode-CN7JLQYO.js +60 -0
- package/dist/pause-FFAYRBWI.js +18 -0
- package/dist/preview-DT7DWG5F.js +91 -0
- package/dist/project/hook-adapter.d.ts +5 -2
- package/dist/project/hook-adapter.js +41 -27
- package/dist/project-FY62G55N.js +70 -0
- package/dist/pty-XTJ4MIWK.js +94 -0
- package/dist/recovery-U6QB3PMT.js +100 -0
- package/dist/reindex-Y27QJFDB.js +22 -0
- package/dist/resume-UU4HZIUP.js +18 -0
- package/dist/run-HALGEJNJ.js +19 -0
- package/dist/run-OGA3P7FC.js +126 -0
- package/dist/serve-NBKT5BKY.js +104 -0
- package/dist/session-XM2CR425.js +159 -0
- package/dist/setup-DTKZLZUT.js +18 -0
- package/dist/start-login-UIQYQBMC.js +416 -0
- package/dist/status-A2OUTNGK.js +9 -0
- package/dist/status-H2VAHIDV.js +10 -0
- package/dist/status-NOOHW5WA.js +43 -0
- package/dist/status-VHODZPXB.js +55 -0
- package/dist/status-XQANBVXW.js +286 -0
- package/dist/stdio.d.ts +3 -13
- package/dist/stdio.js +16 -3186
- package/dist/sweep-64JDCGK6.js +18 -0
- package/dist/test-MKAXFJOL.js +561 -0
- package/dist/tools-gpHNq9Dh.d.ts +328 -0
- package/dist/tui-MWKAXE4K.js +153 -0
- package/dist/unbroadcast-KPUEFLZD.js +18 -0
- package/dist/validate-5GZ5YWNA.js +46 -0
- package/dist/worker-RQ575EJL.js +80 -0
- package/dist/worktree-create-PZSRB7PH.js +89 -0
- package/dist/worktree-list-JYB6VXLW.js +51 -0
- package/dist/worktree-sync-UF5CXPWV.js +30 -0
- package/docs/hooks/capabilities/antigravity.json +199 -0
- package/docs/hooks/capabilities/claude.json +179 -0
- package/docs/hooks/capabilities/codex.json +179 -0
- package/docs/hooks/capabilities/gemini.json +196 -0
- package/docs/hooks/capabilities/grok.json +192 -0
- package/docs/hooks/capabilities/opencode.json +184 -0
- package/docs/project-configuration.md +821 -4
- package/docs/terminal-harness.md +71 -28
- package/docs/terminal-workspace.md +91 -170
- package/gemini-extension.json +1 -1
- package/package.json +13 -1
- package/plugin.json +1 -1
- package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
- package/plugins/pmcp/gemini-extension.json +1 -1
- package/plugins/pmcp/mod/commands.ts +72 -0
- package/plugins/pmcp/mod/contract.d.ts +39 -0
- package/plugins/pmcp/mod/draw.tsx +216 -0
- package/plugins/pmcp/mod/guard.ts +42 -0
- package/plugins/pmcp/mod/hooks.json +4 -0
- package/plugins/pmcp/mod/host.ts +46 -0
- package/plugins/pmcp/mod/model.ts +144 -0
- package/plugins/pmcp/mod/reader/index.ts +18 -0
- package/plugins/pmcp/mod/reader/read.ts +76 -0
- package/plugins/pmcp/mod/reader/settings.ts +54 -0
- package/plugins/pmcp/mod/reader/types.ts +38 -0
- package/plugins/pmcp/mod/register.tsx +73 -0
- package/plugins/pmcp/mod/sessions/format.ts +91 -0
- package/plugins/pmcp/mod/sessions/types.ts +162 -0
- package/plugins/pmcp/mod/snapshot.ts +75 -0
- package/plugins/pmcp/mod/spinner.tsx +30 -0
- package/plugins/pmcp/mod/state.ts +28 -0
- package/plugins/pmcp/plugin.json +1 -1
- package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
- package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -11
- package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +145 -0
- package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +88 -0
- package/schema/catalog-v1.json +158 -0
- package/schema/library.json +164 -0
- package/schema/marketplace-manifest.json +130 -0
- package/schema/plugin-manifest.json +55 -0
- package/schema/skill-frontmatter.json +144 -0
- package/schema/skill-metadata-core.json +110 -0
- package/skills/agent-assets-migrate/SKILL.md +96 -0
- package/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/skills/package-skill-catalog/SKILL.md +51 -11
- package/skills/pmcp-project-init/SKILL.md +145 -0
- package/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/skills/skill-package-scaffold/SKILL.md +88 -0
- package/dist/config-BkSpjUG6.d.ts +0 -50
- package/dist/embed-DRROSD3F.d.ts +0 -53
- package/dist/hook-spec-CSJJySsH.d.ts +0 -11
- package/dist/server-VWSY3Shw.d.ts +0 -543
- package/dist/tui-worker.js +0 -6549
- /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
change
|
|
3
|
+
} from "./chunk-RK4PYD7L.js";
|
|
4
|
+
import "./chunk-SG5TPMKH.js";
|
|
5
|
+
import "./chunk-Z4HRRXRF.js";
|
|
6
|
+
import "./chunk-C4NHQGHL.js";
|
|
7
|
+
import "./chunk-A4PKLESO.js";
|
|
8
|
+
import "./chunk-OEH47H6A.js";
|
|
9
|
+
import "./chunk-IJBSOWHK.js";
|
|
10
|
+
import "./chunk-QPL7E2HW.js";
|
|
11
|
+
import "./chunk-PMJG2CXF.js";
|
|
12
|
+
|
|
13
|
+
// src/sessions/cli/sweep.ts
|
|
14
|
+
var run = (context) => change(context, "sweep");
|
|
15
|
+
export {
|
|
16
|
+
run
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=sweep-64JDCGK6.js.map
|
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import {
|
|
2
|
+
specFrom
|
|
3
|
+
} from "./chunk-7BLPN3W6.js";
|
|
4
|
+
import {
|
|
5
|
+
sourceFor
|
|
6
|
+
} from "./chunk-7TD53M7L.js";
|
|
7
|
+
import "./chunk-7DLZC73N.js";
|
|
8
|
+
import {
|
|
9
|
+
NEUTRAL_EVENTS,
|
|
10
|
+
POLICIES,
|
|
11
|
+
RUNTIMES,
|
|
12
|
+
RUNTIME_IDS,
|
|
13
|
+
commandsOf,
|
|
14
|
+
customPolicy
|
|
15
|
+
} from "./chunk-65ZHM5RH.js";
|
|
16
|
+
import {
|
|
17
|
+
DEFAULT_LOG_SETTINGS,
|
|
18
|
+
LEVEL_RANK
|
|
19
|
+
} from "./chunk-HQOB7OQS.js";
|
|
20
|
+
import "./chunk-S3PIAMXV.js";
|
|
21
|
+
import "./chunk-JS5RTH4I.js";
|
|
22
|
+
import "./chunk-DCU2EXQV.js";
|
|
23
|
+
import "./chunk-XELAZAIM.js";
|
|
24
|
+
import "./chunk-QEW4J3IZ.js";
|
|
25
|
+
import "./chunk-OPYFEHKG.js";
|
|
26
|
+
import "./chunk-EATCUWGG.js";
|
|
27
|
+
import "./chunk-NRBQK6UX.js";
|
|
28
|
+
import "./chunk-3PW4FI7U.js";
|
|
29
|
+
import "./chunk-SG5TPMKH.js";
|
|
30
|
+
import {
|
|
31
|
+
SESSION_ID,
|
|
32
|
+
createFilesStore,
|
|
33
|
+
writeJson
|
|
34
|
+
} from "./chunk-Z4HRRXRF.js";
|
|
35
|
+
import {
|
|
36
|
+
STATE_FILES,
|
|
37
|
+
asBroadcast,
|
|
38
|
+
asLease,
|
|
39
|
+
asPause,
|
|
40
|
+
asRecord,
|
|
41
|
+
fieldsOf,
|
|
42
|
+
leaseFile
|
|
43
|
+
} from "./chunk-C4NHQGHL.js";
|
|
44
|
+
import "./chunk-Q5H3L6Y4.js";
|
|
45
|
+
import {
|
|
46
|
+
ArgumentError,
|
|
47
|
+
one
|
|
48
|
+
} from "./chunk-A4PKLESO.js";
|
|
49
|
+
import "./chunk-V4NPDK6X.js";
|
|
50
|
+
import "./chunk-665TA55Z.js";
|
|
51
|
+
import {
|
|
52
|
+
expandPath
|
|
53
|
+
} from "./chunk-OEH47H6A.js";
|
|
54
|
+
import {
|
|
55
|
+
checkoutOf,
|
|
56
|
+
worktreesOf
|
|
57
|
+
} from "./chunk-IJBSOWHK.js";
|
|
58
|
+
import "./chunk-E7OOHLQR.js";
|
|
59
|
+
import "./chunk-QPL7E2HW.js";
|
|
60
|
+
import "./chunk-PMJG2CXF.js";
|
|
61
|
+
|
|
62
|
+
// src/commands/hooks/test.ts
|
|
63
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
64
|
+
import { tmpdir } from "os";
|
|
65
|
+
import { join as join3 } from "path";
|
|
66
|
+
|
|
67
|
+
// src/commands/hooks/state.ts
|
|
68
|
+
import { readFileSync } from "fs";
|
|
69
|
+
import { join, resolve } from "path";
|
|
70
|
+
function seedState(store, cwd, path) {
|
|
71
|
+
if (!path) return;
|
|
72
|
+
let value;
|
|
73
|
+
try {
|
|
74
|
+
value = JSON.parse(readFileSync(resolve(cwd, path), "utf8"));
|
|
75
|
+
} catch {
|
|
76
|
+
throw new ArgumentError("--session-state must be a readable JSON object");
|
|
77
|
+
}
|
|
78
|
+
const raw = fieldsOf(value);
|
|
79
|
+
if (!raw) throw new ArgumentError("--session-state must be an object");
|
|
80
|
+
const unknown = Object.keys(raw).find(
|
|
81
|
+
(key) => !["records", "pause", "leases", "broadcast"].includes(key)
|
|
82
|
+
);
|
|
83
|
+
if (unknown) throw new ArgumentError("unknown session-state key " + unknown);
|
|
84
|
+
if (raw.records !== void 0 && !Array.isArray(raw.records))
|
|
85
|
+
throw new ArgumentError("records must be an array");
|
|
86
|
+
for (const value2 of raw.records ?? []) {
|
|
87
|
+
const record = asRecord(value2);
|
|
88
|
+
if (!record || !SESSION_ID.test(record.session))
|
|
89
|
+
throw new ArgumentError("records need valid session identifiers");
|
|
90
|
+
writeJson(
|
|
91
|
+
join(store.dir, STATE_FILES.records, record.session + ".json"),
|
|
92
|
+
record
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (raw.pause !== void 0 && raw.pause !== null) {
|
|
96
|
+
const pause = asPause(raw.pause);
|
|
97
|
+
if (!pause) throw new ArgumentError("pause needs by, reason and since");
|
|
98
|
+
writeJson(join(store.dir, STATE_FILES.pause), pause);
|
|
99
|
+
}
|
|
100
|
+
if (raw.leases !== void 0 && !fieldsOf(raw.leases))
|
|
101
|
+
throw new ArgumentError("leases must be an object");
|
|
102
|
+
for (const [name, value2] of Object.entries(raw.leases ?? {})) {
|
|
103
|
+
const lease = asLease(value2);
|
|
104
|
+
if (!lease) throw new ArgumentError("lease needs pid and subject");
|
|
105
|
+
writeJson(join(store.dir, leaseFile(name)), lease);
|
|
106
|
+
}
|
|
107
|
+
if (raw.broadcast !== void 0 && raw.broadcast !== null) {
|
|
108
|
+
const broadcast = asBroadcast(raw.broadcast);
|
|
109
|
+
if (!broadcast)
|
|
110
|
+
throw new ArgumentError("broadcast needs id, by, text and since");
|
|
111
|
+
writeJson(join(store.dir, STATE_FILES.broadcast), broadcast);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/hooks/dispatch/compose.ts
|
|
116
|
+
var RANK = { allow: 0, ask: 1, deny: 2 };
|
|
117
|
+
function applyMode(id, decision, mode) {
|
|
118
|
+
if (!decision.verdict || decision.verdict === "allow") return decision;
|
|
119
|
+
if (mode === "off") return {};
|
|
120
|
+
if (mode === "graded") return decision;
|
|
121
|
+
if (mode === "warn") {
|
|
122
|
+
const note = `pmcp ${id}: ${decision.reason ?? "would refuse this call"}`;
|
|
123
|
+
return { context: [...decision.context ?? [], note] };
|
|
124
|
+
}
|
|
125
|
+
return { ...decision, verdict: mode };
|
|
126
|
+
}
|
|
127
|
+
function compose(decisions) {
|
|
128
|
+
let winner = {};
|
|
129
|
+
const context = [];
|
|
130
|
+
const feedback = [];
|
|
131
|
+
for (const decision of decisions) {
|
|
132
|
+
context.push(...decision.context ?? []);
|
|
133
|
+
if (decision.feedback) feedback.push(decision.feedback);
|
|
134
|
+
if (!decision.verdict) continue;
|
|
135
|
+
if (!winner.verdict || RANK[decision.verdict] > RANK[winner.verdict])
|
|
136
|
+
winner = decision;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
...winner.verdict ? { verdict: winner.verdict } : {},
|
|
140
|
+
...winner.reason ? { reason: winner.reason } : {},
|
|
141
|
+
...context.length > 0 ? { context } : {},
|
|
142
|
+
...feedback.length > 0 ? { feedback: feedback.join("\n\n") } : {}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function lower(decision, lowering) {
|
|
146
|
+
if (decision.verdict !== "ask" || !lowering) return decision;
|
|
147
|
+
if (lowering.ask === "deny") return { ...decision, verdict: "deny" };
|
|
148
|
+
const { verdict: _verdict, reason, ...rest } = decision;
|
|
149
|
+
return {
|
|
150
|
+
...rest,
|
|
151
|
+
context: [...decision.context ?? [], `pmcp: ${reason ?? "would ask"}`]
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/hooks/dispatch/defer.ts
|
|
156
|
+
import { mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "fs";
|
|
157
|
+
import { join as join2 } from "path";
|
|
158
|
+
var SAFE = /[^A-Za-z0-9_-]/gu;
|
|
159
|
+
function file(store, session) {
|
|
160
|
+
return join2(
|
|
161
|
+
store.dir,
|
|
162
|
+
"pending-context",
|
|
163
|
+
`${session.replace(SAFE, "_")}.json`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
function read(path) {
|
|
167
|
+
try {
|
|
168
|
+
const value = JSON.parse(readFileSync2(path, "utf8"));
|
|
169
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
170
|
+
} catch {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function write(path, notes) {
|
|
175
|
+
mkdirSync(join2(path, ".."), { recursive: true });
|
|
176
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
177
|
+
writeFileSync(temporary, JSON.stringify(notes));
|
|
178
|
+
renameSync(temporary, path);
|
|
179
|
+
}
|
|
180
|
+
function deferContext(input, decision, delivers, store) {
|
|
181
|
+
const session = input.session.id;
|
|
182
|
+
if (!session) return decision;
|
|
183
|
+
const path = file(store, session);
|
|
184
|
+
if (!delivers.includes(input.event)) {
|
|
185
|
+
if (!decision.context?.length) return decision;
|
|
186
|
+
write(path, [...read(path), ...decision.context]);
|
|
187
|
+
const { context: _held, ...rest } = decision;
|
|
188
|
+
return rest;
|
|
189
|
+
}
|
|
190
|
+
const pending = read(path);
|
|
191
|
+
if (pending.length === 0) return decision;
|
|
192
|
+
write(path, []);
|
|
193
|
+
return { ...decision, context: [...pending, ...decision.context ?? []] };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/hooks/dispatch/emergency.ts
|
|
197
|
+
import { existsSync } from "fs";
|
|
198
|
+
import { resolve as resolve2 } from "path";
|
|
199
|
+
var READ_ONLY = /* @__PURE__ */ new Set([
|
|
200
|
+
"cat",
|
|
201
|
+
"ls",
|
|
202
|
+
"stat",
|
|
203
|
+
"test",
|
|
204
|
+
"[",
|
|
205
|
+
"head",
|
|
206
|
+
"tail",
|
|
207
|
+
"wc",
|
|
208
|
+
"file"
|
|
209
|
+
]);
|
|
210
|
+
var REASON = "The emergency off switch belongs to the operator; agents may not create, change or delete it.";
|
|
211
|
+
function emergencyActive(root, file2) {
|
|
212
|
+
return file2 !== void 0 && existsSync(expandPath(root, file2));
|
|
213
|
+
}
|
|
214
|
+
function protectOffFile(input, file2) {
|
|
215
|
+
const tool = input.tool;
|
|
216
|
+
if (!file2 || input.event !== "before_tool" || !tool) return {};
|
|
217
|
+
const target = expandPath(input.projectRoot, file2);
|
|
218
|
+
if (tool.kind === "edit") {
|
|
219
|
+
return tool.paths.some((path) => resolve2(path) === target) ? { verdict: "deny", reason: REASON } : {};
|
|
220
|
+
}
|
|
221
|
+
if (tool.kind !== "shell") return {};
|
|
222
|
+
if (!tool.steps) {
|
|
223
|
+
return (tool.command ?? "").includes(file2) ? { verdict: "deny", reason: REASON } : {};
|
|
224
|
+
}
|
|
225
|
+
const names = tool.steps.some(
|
|
226
|
+
(step) => !READ_ONLY.has(step.argv[0] ?? "") && step.raw.some(
|
|
227
|
+
(word) => word === file2 || expandPath(resolve2(input.cwd, step.dir), word) === target
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
return names ? { verdict: "deny", reason: REASON } : {};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/hooks/dispatch/enrich.ts
|
|
234
|
+
function withSteps(input) {
|
|
235
|
+
const tool = input.tool;
|
|
236
|
+
if (tool?.kind !== "shell" || !tool.command) return input;
|
|
237
|
+
const steps = commandsOf(tool.command);
|
|
238
|
+
if (!steps) return input;
|
|
239
|
+
return { ...input, tool: { ...tool, steps } };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/hooks/dispatch/run-policy.ts
|
|
243
|
+
async function runPolicy(selected, input, deps) {
|
|
244
|
+
const { policy, mode } = selected;
|
|
245
|
+
const log = deps.log.child({ policy: policy.id });
|
|
246
|
+
const started = deps.now();
|
|
247
|
+
const finish = (decision) => {
|
|
248
|
+
deps.onPolicy?.({
|
|
249
|
+
policy: policy.id,
|
|
250
|
+
mode,
|
|
251
|
+
decision,
|
|
252
|
+
durationMs: deps.now() - started
|
|
253
|
+
});
|
|
254
|
+
return decision;
|
|
255
|
+
};
|
|
256
|
+
try {
|
|
257
|
+
const options = policy.options(selected.options);
|
|
258
|
+
const context = {
|
|
259
|
+
options,
|
|
260
|
+
mode,
|
|
261
|
+
git: deps.git,
|
|
262
|
+
store: deps.store,
|
|
263
|
+
log,
|
|
264
|
+
now: deps.now,
|
|
265
|
+
...deps.policySha256 ? { policySha256: deps.policySha256 } : {}
|
|
266
|
+
};
|
|
267
|
+
const raw = await (deps.evaluate ? deps.evaluate(selected, input, context) : policy.evaluate(input, context));
|
|
268
|
+
const decision = applyMode(policy.id, raw, mode);
|
|
269
|
+
log.debug("policy", {
|
|
270
|
+
verdict: decision.verdict,
|
|
271
|
+
duration_ms: deps.now() - started
|
|
272
|
+
});
|
|
273
|
+
return finish(decision);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
log.error("policy failed", {
|
|
276
|
+
error: error instanceof Error ? error.message : String(error)
|
|
277
|
+
});
|
|
278
|
+
if (policy.fail === "open") return finish({});
|
|
279
|
+
return finish({
|
|
280
|
+
verdict: "deny",
|
|
281
|
+
reason: `pmcp ${policy.id} failed, refusing to be safe`
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/hooks/dispatch/select.ts
|
|
287
|
+
var unknownGuard = (id) => ({
|
|
288
|
+
id,
|
|
289
|
+
events: ["before_tool"],
|
|
290
|
+
fail: "closed",
|
|
291
|
+
defaultMode: "deny",
|
|
292
|
+
options: () => ({}),
|
|
293
|
+
evaluate: () => ({
|
|
294
|
+
verdict: "deny",
|
|
295
|
+
reason: `pmcp does not know guard ${id}; update the hook bundle`
|
|
296
|
+
})
|
|
297
|
+
});
|
|
298
|
+
var TOOL_EVENTS = /* @__PURE__ */ new Set(["before_tool", "after_tool"]);
|
|
299
|
+
function events(selected) {
|
|
300
|
+
const { policy } = selected;
|
|
301
|
+
if (!policy.eventsFor) return policy.events;
|
|
302
|
+
try {
|
|
303
|
+
return policy.eventsFor(policy.options(selected.options));
|
|
304
|
+
} catch {
|
|
305
|
+
return policy.events;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function listens(selected, input) {
|
|
309
|
+
if (!events(selected).includes(input.event)) return false;
|
|
310
|
+
const tools = selected.policy.tools;
|
|
311
|
+
if (!tools || !TOOL_EVENTS.has(input.event)) return true;
|
|
312
|
+
return input.tool !== void 0 && tools.includes(input.tool.kind);
|
|
313
|
+
}
|
|
314
|
+
function selectPolicies(compiled, input) {
|
|
315
|
+
const guards = compiled.guards.map((guard) => ({
|
|
316
|
+
policy: POLICIES[guard.id] ?? unknownGuard(guard.id),
|
|
317
|
+
mode: guard.mode,
|
|
318
|
+
options: guard.options
|
|
319
|
+
}));
|
|
320
|
+
const custom = compiled.custom.map((entry) => ({
|
|
321
|
+
policy: customPolicy(entry),
|
|
322
|
+
mode: "deny",
|
|
323
|
+
options: {}
|
|
324
|
+
}));
|
|
325
|
+
return [...guards, ...custom].filter((selected) => listens(selected, input));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/hooks/dispatch/stop-loop.ts
|
|
329
|
+
function quietRepeatedStop(input, decision) {
|
|
330
|
+
if (input.event !== "stop" || !input.stop?.active) return decision;
|
|
331
|
+
return {};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/hooks/dispatch.ts
|
|
335
|
+
async function dispatch(raw, compiled, deps) {
|
|
336
|
+
const input = withSteps(raw);
|
|
337
|
+
const protect = protectOffFile(input, compiled.emergencyOffFile);
|
|
338
|
+
const off = emergencyActive(input.projectRoot, compiled.emergencyOffFile);
|
|
339
|
+
const selected = off ? [] : selectPolicies(compiled, input);
|
|
340
|
+
if (off) deps.log.warn("emergency off file present; guards pass");
|
|
341
|
+
const decisions = await Promise.all(
|
|
342
|
+
selected.map((entry) => runPolicy(entry, input, deps))
|
|
343
|
+
);
|
|
344
|
+
const composed = lower(
|
|
345
|
+
compose([protect, ...decisions]),
|
|
346
|
+
compiled.lowering[input.runtime]
|
|
347
|
+
);
|
|
348
|
+
const continued = input.event === "stop" && input.stop?.active === true;
|
|
349
|
+
const delivers = continued ? [] : RUNTIMES[input.runtime].capabilities.context;
|
|
350
|
+
return deferContext(
|
|
351
|
+
input,
|
|
352
|
+
quietRepeatedStop(input, composed),
|
|
353
|
+
delivers,
|
|
354
|
+
deps.store
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/logging/redact.ts
|
|
359
|
+
import { createHash } from "crypto";
|
|
360
|
+
var SECRET_KEY = /secret|token|password|passwd|credential|api[_-]?key/iu;
|
|
361
|
+
var ENV_KEY = /^(env|environment)$/iu;
|
|
362
|
+
var PROMPT_KEY = /^(prompt|lastMessage|last_message)$/u;
|
|
363
|
+
var ALL = [
|
|
364
|
+
"secret_values",
|
|
365
|
+
"prompt_text",
|
|
366
|
+
"env_values"
|
|
367
|
+
];
|
|
368
|
+
function redact(value, kinds = ALL, key = "") {
|
|
369
|
+
if (kinds.includes("secret_values") && SECRET_KEY.test(key))
|
|
370
|
+
return "[redacted]";
|
|
371
|
+
if (kinds.includes("env_values") && ENV_KEY.test(key)) return "[redacted]";
|
|
372
|
+
if (kinds.includes("prompt_text") && PROMPT_KEY.test(key) && typeof value === "string") {
|
|
373
|
+
return {
|
|
374
|
+
length: value.length,
|
|
375
|
+
sha256: createHash("sha256").update(value).digest("hex").slice(0, 16)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (Array.isArray(value)) return value.map((item) => redact(item, kinds));
|
|
379
|
+
if (value !== null && typeof value === "object") {
|
|
380
|
+
return Object.fromEntries(
|
|
381
|
+
Object.entries(value).map(([name, item]) => [
|
|
382
|
+
name,
|
|
383
|
+
redact(item, kinds, name)
|
|
384
|
+
])
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/logging/logger.ts
|
|
391
|
+
function levelFor(settings, component) {
|
|
392
|
+
let name = component;
|
|
393
|
+
while (name) {
|
|
394
|
+
const level = settings.components[name];
|
|
395
|
+
if (level) return level;
|
|
396
|
+
const dot = name.lastIndexOf(".");
|
|
397
|
+
name = dot < 0 ? void 0 : name.slice(0, dot);
|
|
398
|
+
}
|
|
399
|
+
return settings.level;
|
|
400
|
+
}
|
|
401
|
+
function createLogger(sink, settings = DEFAULT_LOG_SETTINGS, fields = {}) {
|
|
402
|
+
const resolved = typeof settings === "string" ? { ...DEFAULT_LOG_SETTINGS, level: settings } : settings;
|
|
403
|
+
const limit = LEVEL_RANK[levelFor(resolved, fields.component)];
|
|
404
|
+
const enabled = (at) => resolved.enabled && LEVEL_RANK[at] <= limit;
|
|
405
|
+
const write2 = (at, msg, data) => {
|
|
406
|
+
if (!enabled(at)) return;
|
|
407
|
+
const { verdict, duration_ms, ...rest } = data ?? {};
|
|
408
|
+
const record = {
|
|
409
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
410
|
+
level: at,
|
|
411
|
+
component: fields.component,
|
|
412
|
+
trace: fields.trace,
|
|
413
|
+
runtime: fields.runtime,
|
|
414
|
+
event: fields.event,
|
|
415
|
+
session: fields.session,
|
|
416
|
+
policy: fields.policy,
|
|
417
|
+
verdict,
|
|
418
|
+
duration_ms,
|
|
419
|
+
msg,
|
|
420
|
+
data: Object.keys(rest).length > 0 ? redact(rest, resolved.redact) : void 0
|
|
421
|
+
};
|
|
422
|
+
try {
|
|
423
|
+
sink(JSON.stringify(record));
|
|
424
|
+
} catch {
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
return {
|
|
428
|
+
enabled,
|
|
429
|
+
child: (more) => createLogger(sink, resolved, { ...fields, ...more }),
|
|
430
|
+
error: (msg, data) => write2("error", msg, data),
|
|
431
|
+
warn: (msg, data) => write2("warn", msg, data),
|
|
432
|
+
info: (msg, data) => write2("info", msg, data),
|
|
433
|
+
debug: (msg, data) => write2("debug", msg, data),
|
|
434
|
+
trace: (msg, data) => write2("trace", msg, data)
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
var silentLogger = createLogger(() => {
|
|
438
|
+
}, {
|
|
439
|
+
...DEFAULT_LOG_SETTINGS,
|
|
440
|
+
enabled: false
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// src/hooks/policies/git-probe.ts
|
|
444
|
+
import { realpathSync } from "fs";
|
|
445
|
+
var real = (path) => {
|
|
446
|
+
try {
|
|
447
|
+
return realpathSync(path);
|
|
448
|
+
} catch {
|
|
449
|
+
return path;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
var gitProbe = {
|
|
453
|
+
toplevel(cwd) {
|
|
454
|
+
return checkoutOf(cwd)?.root ?? null;
|
|
455
|
+
},
|
|
456
|
+
worktrees(cwd) {
|
|
457
|
+
const checkout = checkoutOf(cwd);
|
|
458
|
+
if (!checkout) return [];
|
|
459
|
+
return worktreesOf(checkout).map((tree) => ({
|
|
460
|
+
path: real(tree.path),
|
|
461
|
+
branch: tree.branch || null
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// src/hooks/inspection/simulate.ts
|
|
467
|
+
async function simulate(input, compiled, store) {
|
|
468
|
+
const policies = [];
|
|
469
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
470
|
+
const decision = await dispatch(input, compiled, {
|
|
471
|
+
log: silentLogger,
|
|
472
|
+
git: gitProbe,
|
|
473
|
+
store,
|
|
474
|
+
now: Date.now,
|
|
475
|
+
evaluate(selected, event, context) {
|
|
476
|
+
const id = selected.policy.id;
|
|
477
|
+
if (id.startsWith("custom.") || id.startsWith("checks.") || id === "git.worktrees.sync") {
|
|
478
|
+
skipped.add(id);
|
|
479
|
+
return { context: ["Simulation skipped external effects for " + id] };
|
|
480
|
+
}
|
|
481
|
+
return selected.policy.evaluate(event, context);
|
|
482
|
+
},
|
|
483
|
+
onPolicy(result) {
|
|
484
|
+
policies.push({
|
|
485
|
+
...result,
|
|
486
|
+
source: sourceFor(result.policy),
|
|
487
|
+
skipped: skipped.has(result.policy),
|
|
488
|
+
verdict: result.decision.verdict ?? "allow",
|
|
489
|
+
reason: result.decision.reason ?? result.decision.context?.join("\n") ?? null
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
return { decision, policies };
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/commands/hooks/test.ts
|
|
497
|
+
async function run(context) {
|
|
498
|
+
const runtime = one(context.args, "runtime");
|
|
499
|
+
if (!RUNTIME_IDS.includes(runtime))
|
|
500
|
+
throw new ArgumentError("--runtime must be claude or codex");
|
|
501
|
+
const requested = one(context.args, "event");
|
|
502
|
+
if (!requested) throw new ArgumentError("--event is required");
|
|
503
|
+
const adapter = RUNTIMES[runtime];
|
|
504
|
+
const event = NEUTRAL_EVENTS.includes(requested) ? adapter.nativeEvent(requested) : requested;
|
|
505
|
+
if (!event) throw new ArgumentError("Unsupported event for " + runtime);
|
|
506
|
+
const command = one(context.args, "command");
|
|
507
|
+
const path = one(context.args, "path");
|
|
508
|
+
const tool = one(context.args, "tool");
|
|
509
|
+
if ([command, path, tool].filter((value) => value !== void 0).length > 1)
|
|
510
|
+
throw new ArgumentError("Choose one of --command, --path or --tool");
|
|
511
|
+
const spec = specFrom(context);
|
|
512
|
+
const compiled = spec.hookBundle?.policy;
|
|
513
|
+
if (!compiled?.targets.includes(runtime))
|
|
514
|
+
throw new ArgumentError("No compiled hooks for " + runtime);
|
|
515
|
+
const payload = adapter.synthetic({
|
|
516
|
+
cwd: context.cwd,
|
|
517
|
+
session: "pmcp-hooks-test",
|
|
518
|
+
event,
|
|
519
|
+
command,
|
|
520
|
+
path,
|
|
521
|
+
tool
|
|
522
|
+
});
|
|
523
|
+
const input = adapter.normalize(event, payload, spec.root);
|
|
524
|
+
if (!input || adapter.capabilities.events[input.event] === "unsupported")
|
|
525
|
+
throw new ArgumentError("Unsupported event " + requested);
|
|
526
|
+
if ((command !== void 0 || path !== void 0 || tool !== void 0) && !["before_tool", "after_tool"].includes(input.event))
|
|
527
|
+
throw new ArgumentError("Tool selectors require before_tool or after_tool");
|
|
528
|
+
const scratch = mkdtempSync(join3(tmpdir(), "pmcp-hooks-test-"));
|
|
529
|
+
try {
|
|
530
|
+
const store = createFilesStore(scratch, compiled.sessions);
|
|
531
|
+
seedState(store, context.cwd, one(context.args, "session-state"));
|
|
532
|
+
const report = await simulate(input, compiled, store);
|
|
533
|
+
const rendered = adapter.render(input, report.decision);
|
|
534
|
+
const result = {
|
|
535
|
+
version: 1,
|
|
536
|
+
runtime,
|
|
537
|
+
event: input.event,
|
|
538
|
+
payload,
|
|
539
|
+
...report,
|
|
540
|
+
rendered
|
|
541
|
+
};
|
|
542
|
+
if (context.args.flags.has("json"))
|
|
543
|
+
context.ui.data(JSON.stringify(result) + "\n");
|
|
544
|
+
if (!context.args.flags.has("json")) {
|
|
545
|
+
for (const row of report.policies)
|
|
546
|
+
context.ui.line(
|
|
547
|
+
row.policy + ": " + row.verdict + " " + row.durationMs + "ms" + (row.skipped ? " (external effects skipped)" : "") + (row.reason ? " " + row.reason : "")
|
|
548
|
+
);
|
|
549
|
+
context.ui.data(
|
|
550
|
+
"Rendered (exit " + rendered.exitCode + "):\n" + rendered.stdout + "\n"
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
return 0;
|
|
554
|
+
} finally {
|
|
555
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
export {
|
|
559
|
+
run
|
|
560
|
+
};
|
|
561
|
+
//# sourceMappingURL=test-MKAXFJOL.js.map
|