@modootoday/pmcp 0.17.4 → 0.18.2
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 +2 -2
- package/.mcp.json +1 -1
- package/CHANGELOG.md +152 -0
- package/CONTRIBUTING.md +71 -0
- package/README.md +98 -201
- package/SECURITY.md +17 -1
- package/dist/apply-JUTGS5WZ.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-CBMVOV3G.js +18 -0
- package/dist/chunk-26WLNWDG.js +93 -0
- package/dist/chunk-2FIV63WC.js +252 -0
- package/dist/chunk-2P4Z2NUX.js +28 -0
- package/dist/chunk-34DECPVC.js +22 -0
- package/dist/chunk-3FCFAQDG.js +42 -0
- package/dist/chunk-3IDXEV5E.js +1934 -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-5OMOPUE6.js +39 -0
- package/dist/chunk-5QQWS4US.js +53 -0
- package/dist/chunk-5ZABTVSW.js +48 -0
- package/dist/chunk-65KAQSJP.js +7 -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-7DLZC73N.js +29 -0
- package/dist/chunk-7GBYECSK.js +72 -0
- package/dist/chunk-7HFIGCSL.js +419 -0
- package/dist/chunk-7TD53M7L.js +13 -0
- package/dist/chunk-7UCZAN4J.js +778 -0
- package/dist/chunk-A4PKLESO.js +112 -0
- package/dist/chunk-A7VF7A35.js +1025 -0
- package/dist/chunk-ABTJQ4QV.js +74 -0
- package/dist/chunk-AJ4VXM2U.js +349 -0
- package/dist/chunk-BBTBJCFA.js +380 -0
- package/dist/chunk-BU65MNVU.js +13 -0
- package/dist/chunk-C4NHQGHL.js +142 -0
- package/dist/chunk-CJTKR6K6.js +1213 -0
- package/dist/chunk-D77IRGHO.js +1246 -0
- package/dist/chunk-DCU2EXQV.js +78 -0
- package/dist/chunk-DMZHQZ7P.js +104 -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-EATCUWGG.js +66 -0
- package/dist/chunk-EAWPJHJ7.js +155 -0
- package/dist/chunk-EIDIVIAD.js +33 -0
- package/dist/chunk-F5QYZK7E.js +396 -0
- package/dist/chunk-F5XMGOOX.js +28 -0
- package/dist/chunk-FENOGX3U.js +31 -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-I2ZP2PSA.js +211 -0
- package/dist/chunk-IG33DXLT.js +151 -0
- package/dist/chunk-IJBSOWHK.js +86 -0
- package/dist/chunk-INT7QLEU.js +114 -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-JWRZDYB5.js +59 -0
- package/dist/chunk-KMXRRSKT.js +660 -0
- package/dist/chunk-LBXO4VPG.js +73 -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-LMUBBIE2.js +83 -0
- package/dist/chunk-LTZH5E3G.js +479 -0
- package/dist/chunk-LW4TG7EL.js +39 -0
- package/dist/chunk-MPSQXSC6.js +346 -0
- package/dist/chunk-MVFH26QT.js +97 -0
- package/dist/chunk-NLEXKE7U.js +67 -0
- package/dist/chunk-NQPURJT5.js +44 -0
- package/dist/chunk-NRBQK6UX.js +105 -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-PKODFR5F.js +102 -0
- package/dist/chunk-PMJG2CXF.js +122 -0
- package/dist/chunk-Q5H3L6Y4.js +23 -0
- package/dist/chunk-QEF7EK3T.js +28 -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-R5MT42JS.js +284 -0
- package/dist/chunk-RMATE45Z.js +197 -0
- package/dist/chunk-RPQOBHVU.js +87 -0
- package/dist/chunk-S3PIAMXV.js +230 -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-TXQ7L33K.js +45 -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-VMHUEOT5.js +643 -0
- package/dist/chunk-VRPMYPZU.js +4985 -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-YSAWTGNA.js +117 -0
- package/dist/claude-U2JC2DNQ.js +77 -0
- package/dist/cli-MI4ZCAZ3.js +41 -0
- package/dist/cli-ZN7ZVDEZ.js +46 -0
- package/dist/cli.js +144 -16197
- package/dist/completion-ILSRB3LW.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-XKXVVQWH.js +93 -0
- package/dist/doctor-O2E63YGO.js +538 -0
- package/dist/entry-X6CSYQRQ.js +305 -0
- package/dist/exec-mcp-2PMWBPD7.js +365 -0
- package/dist/harness-L2KSI2ZB.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 +5222 -0
- package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
- package/dist/hook.js +26 -0
- package/dist/hooks-BHTA44X7.js +21 -0
- package/dist/host-UIZAXXQH.js +22 -0
- package/dist/host-UWK754BW.js +210 -0
- package/dist/host-run-BI2OTZDZ.js +307 -0
- package/dist/http.d.ts +5 -42
- package/dist/http.js +21 -2234
- package/dist/import-mcp-GPKJI7DI.js +400 -0
- package/dist/index.d.ts +146 -168
- package/dist/index.js +133 -4948
- package/dist/init-3C2Y7BNJ.js +14 -0
- package/dist/install-GG7HHZK2.js +796 -0
- package/dist/invoke-44CJRVMK.js +23 -0
- package/dist/list-MCP2FXUF.js +68 -0
- package/dist/list-WL6L4J5H.js +65 -0
- package/dist/load-BEUBABtB.d.ts +21 -0
- package/dist/logout-F5EJ5MOU.js +44 -0
- package/dist/logs-TBUA4UWU.js +107 -0
- package/dist/mailbox/index.d.ts +10 -5
- package/dist/mailbox/index.js +53 -1572
- package/dist/mailbox-BMTZOSZ7.js +285 -0
- package/dist/mailbox-GDJ7BWQN.js +189 -0
- package/dist/mainline-KAD2ERLP.js +639 -0
- package/dist/marketplace-G4VQET5W.js +191 -0
- package/dist/mcp-235QZN2A.js +15 -0
- package/dist/mcp-FJ2UQ4RH.js +193 -0
- package/dist/models-ISU4DCMA.js +32 -0
- package/dist/opencode-CN7JLQYO.js +60 -0
- package/dist/pause-7LILUVGL.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-5YV5CUEG.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-26VFAAMH.js +18 -0
- package/dist/run-3AXTZSR7.js +126 -0
- package/dist/run-3SOVRQIA.js +19 -0
- package/dist/serve-DQMKTFIV.js +104 -0
- package/dist/session-XM2CR425.js +159 -0
- package/dist/setup-DTKZLZUT.js +18 -0
- package/dist/start-login-YTZV6KMF.js +416 -0
- package/dist/status-A2OUTNGK.js +9 -0
- package/dist/status-H2VAHIDV.js +10 -0
- package/dist/status-MROQ7WR7.js +43 -0
- package/dist/status-RO55QPKV.js +55 -0
- package/dist/status-UME2L33L.js +286 -0
- package/dist/stdio.d.ts +3 -13
- package/dist/stdio.js +16 -3186
- package/dist/sweep-35LGQTTO.js +18 -0
- package/dist/test-AGZOJLRZ.js +561 -0
- package/dist/tools-gpHNq9Dh.d.ts +328 -0
- package/dist/tui-G5LLWCSV.js +153 -0
- package/dist/unbroadcast-5QNGAJR2.js +18 -0
- package/dist/validate-IU52H2IC.js +46 -0
- package/dist/worker-QZ5T6LJD.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/authoring.md +82 -0
- package/docs/browser-and-desktop.md +46 -0
- package/docs/commands.md +325 -0
- package/docs/compare.md +35 -0
- package/docs/compatibility.md +55 -0
- package/docs/embeddings.md +1 -1
- package/docs/getting-started.md +105 -0
- package/docs/git-workflow.md +60 -0
- package/docs/glossary.md +31 -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/hooks.md +264 -0
- package/docs/install.md +72 -0
- package/docs/library-skills.md +132 -0
- package/docs/mailbox.md +16 -5
- package/docs/project-configuration.md +540 -58
- package/docs/sessions.md +64 -0
- package/docs/skills.md +4 -45
- package/docs/terminal-harness.md +92 -44
- package/docs/terminal-workspace.md +81 -169
- package/gemini-extension.json +2 -2
- package/mcp.json +1 -1
- package/package.json +16 -2
- package/plugin.json +2 -2
- package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
- package/plugins/pmcp/.mcp.json +1 -1
- package/plugins/pmcp/gemini-extension.json +2 -2
- package/plugins/pmcp/mcp.json +1 -1
- package/plugins/pmcp/mod/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 +2 -2
- package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
- package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +101 -0
- package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -15
- package/plugins/pmcp/skills/pmcp-browser/SKILL.md +27 -0
- package/plugins/pmcp/skills/pmcp-desktop/SKILL.md +25 -0
- package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +153 -0
- package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +96 -0
- package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +89 -0
- package/schema/catalog-v1.json +187 -0
- package/schema/library.json +196 -0
- package/schema/marketplace-manifest.json +144 -0
- package/schema/plugin-manifest.json +59 -0
- package/schema/skill-frontmatter.json +170 -0
- package/schema/skill-metadata-core.json +131 -0
- package/skills/agent-assets-migrate/SKILL.md +96 -0
- package/skills/headless-agents-ci-scaffold/SKILL.md +101 -0
- package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/skills/package-skill-catalog/SKILL.md +51 -15
- package/skills/pmcp-browser/SKILL.md +27 -0
- package/skills/pmcp-desktop/SKILL.md +25 -0
- package/skills/pmcp-project-init/SKILL.md +153 -0
- package/skills/pmcp-sessions-and-git/SKILL.md +96 -0
- package/skills/skill-package-scaffold/SKILL.md +89 -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/docs/manual-library-skills.md +0 -74
- /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
|
@@ -0,0 +1,1025 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPENCODE_CONFIG,
|
|
3
|
+
mcpOutputs
|
|
4
|
+
} from "./chunk-F5QYZK7E.js";
|
|
5
|
+
import {
|
|
6
|
+
MARK,
|
|
7
|
+
NATIVE_HOOK_FILES,
|
|
8
|
+
SETTINGS,
|
|
9
|
+
block,
|
|
10
|
+
blockOutput,
|
|
11
|
+
changedSincePlan,
|
|
12
|
+
climbCommand,
|
|
13
|
+
deleteKey,
|
|
14
|
+
fingerprint,
|
|
15
|
+
getKey,
|
|
16
|
+
isPermissionPath,
|
|
17
|
+
jsonOutput,
|
|
18
|
+
linkOf,
|
|
19
|
+
permissionOutputs,
|
|
20
|
+
permissionProblems,
|
|
21
|
+
permissionWarnings,
|
|
22
|
+
readJson,
|
|
23
|
+
same,
|
|
24
|
+
setKey,
|
|
25
|
+
splitKeyed,
|
|
26
|
+
uiClaudeOutputs,
|
|
27
|
+
withoutBlock
|
|
28
|
+
} from "./chunk-VRPMYPZU.js";
|
|
29
|
+
import {
|
|
30
|
+
ProjectError,
|
|
31
|
+
RULES_DIR,
|
|
32
|
+
packageRuleOutputs,
|
|
33
|
+
trackedFiles
|
|
34
|
+
} from "./chunk-NRBQK6UX.js";
|
|
35
|
+
import {
|
|
36
|
+
publicMarketplaceRoot
|
|
37
|
+
} from "./chunk-73AKO4UL.js";
|
|
38
|
+
import {
|
|
39
|
+
hostOutputs
|
|
40
|
+
} from "./chunk-DMZHQZ7P.js";
|
|
41
|
+
import {
|
|
42
|
+
lockVersionProblem,
|
|
43
|
+
readLock,
|
|
44
|
+
replaceFile
|
|
45
|
+
} from "./chunk-7HFIGCSL.js";
|
|
46
|
+
import {
|
|
47
|
+
CODEX_PLUGIN_LIST,
|
|
48
|
+
claudeSettings,
|
|
49
|
+
codexConfig,
|
|
50
|
+
codexMarketplaceChecks,
|
|
51
|
+
forRuntime,
|
|
52
|
+
parseCodexPluginList
|
|
53
|
+
} from "./chunk-QPL7E2HW.js";
|
|
54
|
+
|
|
55
|
+
// src/project/plan.ts
|
|
56
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6, readdirSync } from "fs";
|
|
57
|
+
import { join as join4 } from "path";
|
|
58
|
+
|
|
59
|
+
// src/project/frontmatter.ts
|
|
60
|
+
import { createRequire } from "module";
|
|
61
|
+
var require2 = createRequire(import.meta.url);
|
|
62
|
+
function splitFrontmatter(source) {
|
|
63
|
+
const match = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/u.exec(source);
|
|
64
|
+
if (!match) return { meta: {}, body: source };
|
|
65
|
+
const { parse } = require2("yaml");
|
|
66
|
+
const meta = parse(match[1] ?? "");
|
|
67
|
+
const object3 = meta !== null && typeof meta === "object" && !Array.isArray(meta) ? meta : {};
|
|
68
|
+
return { meta: object3, body: match[2] ?? "" };
|
|
69
|
+
}
|
|
70
|
+
function scalar(value) {
|
|
71
|
+
if (typeof value === "string") return value;
|
|
72
|
+
return JSON.stringify(value);
|
|
73
|
+
}
|
|
74
|
+
function renderFrontmatter(meta) {
|
|
75
|
+
const lines = [];
|
|
76
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
77
|
+
if (value === void 0 || value === null) continue;
|
|
78
|
+
if (typeof value === "string" && value.includes("\n")) {
|
|
79
|
+
const block2 = value.replace(/\n$/u, "").split("\n").map((line) => ` ${line}`);
|
|
80
|
+
lines.push(`${key}: |`, ...block2);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
lines.push(`${key}: [${value.map((v) => JSON.stringify(v)).join(", ")}]`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
lines.push(`${key}: ${scalar(value)}`);
|
|
88
|
+
}
|
|
89
|
+
return `---
|
|
90
|
+
${lines.join("\n")}
|
|
91
|
+
---
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/project/hooks.ts
|
|
96
|
+
import { createHash as createHash3 } from "crypto";
|
|
97
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
98
|
+
import { join as join3 } from "path";
|
|
99
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
100
|
+
|
|
101
|
+
// src/project/hook-adapter/run.ts
|
|
102
|
+
import { createHash } from "crypto";
|
|
103
|
+
import { readFileSync } from "fs";
|
|
104
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
105
|
+
|
|
106
|
+
// src/project/hook-adapter/_shared.ts
|
|
107
|
+
var denied = () => ({
|
|
108
|
+
decision: "deny",
|
|
109
|
+
reason: "Shell guard failed validation or execution"
|
|
110
|
+
});
|
|
111
|
+
function object(value) {
|
|
112
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
function scalar2(value) {
|
|
118
|
+
if (typeof value !== "string") {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
if (value.startsWith('"')) {
|
|
122
|
+
try {
|
|
123
|
+
const parsed = JSON.parse(value);
|
|
124
|
+
if (typeof parsed === "string") {
|
|
125
|
+
return parsed;
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/project/hook-adapter/path.ts
|
|
135
|
+
import { existsSync, realpathSync, statSync } from "fs";
|
|
136
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
137
|
+
function guardPath(root, command) {
|
|
138
|
+
const script = command[0]?.startsWith(".agents/guards/") ? command[0] : command[1];
|
|
139
|
+
if (!script?.startsWith(".agents/guards/")) {
|
|
140
|
+
throw new Error("Hook command must execute a script under .agents/guards/");
|
|
141
|
+
}
|
|
142
|
+
const absolute = resolve(root, script);
|
|
143
|
+
const base = resolve(root, ".agents/guards");
|
|
144
|
+
const inside = relative(base, absolute);
|
|
145
|
+
if (isAbsolute(inside) || inside === ".." || inside.startsWith("../") || inside.startsWith("..\\")) {
|
|
146
|
+
throw new Error("Hook guard must stay under .agents/guards/");
|
|
147
|
+
}
|
|
148
|
+
if (!existsSync(absolute) || !statSync(absolute).isFile()) {
|
|
149
|
+
throw new Error("Hook guard script must exist");
|
|
150
|
+
}
|
|
151
|
+
const actual = relative(base, realpathSync(absolute));
|
|
152
|
+
if (isAbsolute(actual) || actual === ".." || actual.startsWith("../") || actual.startsWith("..\\")) {
|
|
153
|
+
throw new Error("Hook guard cannot resolve outside .agents/guards/");
|
|
154
|
+
}
|
|
155
|
+
return absolute;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/project/hook-adapter/evaluate.ts
|
|
159
|
+
import { spawnSync } from "child_process";
|
|
160
|
+
function evaluateShellHook(root, policy, tool, payload) {
|
|
161
|
+
try {
|
|
162
|
+
const value = object(payload);
|
|
163
|
+
const call = object(value["toolCall"]);
|
|
164
|
+
const input = tool === "antigravity" ? object(call["args"]) : object(value["tool_input"]);
|
|
165
|
+
const name = tool === "antigravity" ? call["name"] : value["tool_name"];
|
|
166
|
+
const shellNames = {
|
|
167
|
+
codex: ["Bash", "exec_command", "shell", "shell_command"],
|
|
168
|
+
gemini: ["run_shell_command"],
|
|
169
|
+
antigravity: ["run_command"]
|
|
170
|
+
};
|
|
171
|
+
if (typeof name !== "string") {
|
|
172
|
+
return denied();
|
|
173
|
+
}
|
|
174
|
+
const afterEdit = policy.event === "after_edit";
|
|
175
|
+
if (afterEdit && tool !== "codex") {
|
|
176
|
+
return denied();
|
|
177
|
+
}
|
|
178
|
+
const matches = afterEdit ? name === "apply_patch" : shellNames[tool].includes(name);
|
|
179
|
+
if (!matches) {
|
|
180
|
+
return { decision: "allow" };
|
|
181
|
+
}
|
|
182
|
+
const command = scalar2(
|
|
183
|
+
input[tool === "antigravity" ? "CommandLine" : "command"]
|
|
184
|
+
);
|
|
185
|
+
const limit = afterEdit ? 16 * 1024 * 1024 : 65536;
|
|
186
|
+
if (command === void 0 || command.length > limit) {
|
|
187
|
+
return denied();
|
|
188
|
+
}
|
|
189
|
+
const cwd = scalar2(input["Cwd"]) ?? scalar2(value["cwd"]) ?? root;
|
|
190
|
+
const args = [...policy.command];
|
|
191
|
+
const script = guardPath(root, args);
|
|
192
|
+
if (args[0]?.startsWith(".agents/guards/")) {
|
|
193
|
+
args[0] = script;
|
|
194
|
+
} else {
|
|
195
|
+
args[1] = script;
|
|
196
|
+
}
|
|
197
|
+
const executable = args.shift();
|
|
198
|
+
if (!executable) {
|
|
199
|
+
return denied();
|
|
200
|
+
}
|
|
201
|
+
const result = spawnSync(executable, args, {
|
|
202
|
+
cwd: root,
|
|
203
|
+
env: { PATH: process.env["PATH"], LANG: "C.UTF-8" },
|
|
204
|
+
input: JSON.stringify({
|
|
205
|
+
runtime: tool,
|
|
206
|
+
event: afterEdit ? "after_edit" : "before_shell",
|
|
207
|
+
command,
|
|
208
|
+
cwd
|
|
209
|
+
}),
|
|
210
|
+
encoding: "utf8",
|
|
211
|
+
timeout: policy.timeoutMs,
|
|
212
|
+
killSignal: "SIGKILL",
|
|
213
|
+
maxBuffer: 65536
|
|
214
|
+
});
|
|
215
|
+
if (result.status !== 0 || result.error) {
|
|
216
|
+
return denied();
|
|
217
|
+
}
|
|
218
|
+
const response = object(JSON.parse(result.stdout));
|
|
219
|
+
if (Object.keys(response).some(
|
|
220
|
+
(key) => !["decision", "reason"].includes(key)
|
|
221
|
+
) || !["allow", "deny"].includes(String(response["decision"])) || response["reason"] !== void 0 && typeof response["reason"] !== "string") {
|
|
222
|
+
return denied();
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
decision: response["decision"],
|
|
226
|
+
...typeof response["reason"] === "string" ? { reason: response["reason"].slice(0, 2e3) } : {}
|
|
227
|
+
};
|
|
228
|
+
} catch {
|
|
229
|
+
return denied();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/project/hook-adapter/render.ts
|
|
234
|
+
function nativeHookDecision(tool, decision, event) {
|
|
235
|
+
if (tool === "codex" && event === "after_edit") {
|
|
236
|
+
if (decision.decision === "allow") return {};
|
|
237
|
+
return {
|
|
238
|
+
decision: "block",
|
|
239
|
+
reason: decision.reason ?? "Edit guard failed validation or execution"
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (tool === "codex") {
|
|
243
|
+
return {
|
|
244
|
+
hookSpecificOutput: {
|
|
245
|
+
hookEventName: "PreToolUse",
|
|
246
|
+
permissionDecision: decision.decision,
|
|
247
|
+
...decision.reason ? { permissionDecisionReason: decision.reason } : {}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return decision;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/project/hook-adapter/run.ts
|
|
255
|
+
async function main() {
|
|
256
|
+
const [, , , tool, file, integrity, event] = process.argv;
|
|
257
|
+
const afterEdit = event === "after_edit";
|
|
258
|
+
const supported = tool === "codex" || tool === "gemini" || tool === "antigravity";
|
|
259
|
+
if (!supported) {
|
|
260
|
+
process.exitCode = 2;
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
let decision = denied();
|
|
264
|
+
try {
|
|
265
|
+
if (event !== void 0 && !afterEdit) {
|
|
266
|
+
throw new Error("Unknown hook event");
|
|
267
|
+
}
|
|
268
|
+
if (!file) {
|
|
269
|
+
throw new Error("Missing hook policy");
|
|
270
|
+
}
|
|
271
|
+
const bytes = readFileSync(file);
|
|
272
|
+
const adapter = readFileSync(process.argv[1]);
|
|
273
|
+
const actual = createHash("sha256").update(adapter).update(bytes).digest("hex");
|
|
274
|
+
if (actual !== integrity) {
|
|
275
|
+
throw new Error("Hook integrity mismatch");
|
|
276
|
+
}
|
|
277
|
+
const policy = JSON.parse(bytes.toString("utf8"));
|
|
278
|
+
if (!policy.targets.includes(tool) || policy.event !== event) {
|
|
279
|
+
throw new Error("Hook target mismatch");
|
|
280
|
+
}
|
|
281
|
+
const chunks = [];
|
|
282
|
+
let size = 0;
|
|
283
|
+
for await (const chunk of process.stdin) {
|
|
284
|
+
const bytes2 = Buffer.from(chunk);
|
|
285
|
+
size += bytes2.length;
|
|
286
|
+
if (size > (afterEdit ? 16 * 1024 * 1024 : 131072)) {
|
|
287
|
+
throw new Error("Hook input too large");
|
|
288
|
+
}
|
|
289
|
+
chunks.push(bytes2);
|
|
290
|
+
}
|
|
291
|
+
const root = resolve2(dirname(file), "../..");
|
|
292
|
+
const guardSha256 = createHash("sha256").update(readFileSync(guardPath(root, policy.command))).digest("hex");
|
|
293
|
+
if (policy.contractVersion !== 1 || guardSha256 !== policy.guardSha256) {
|
|
294
|
+
throw new Error(
|
|
295
|
+
"Hook guard source changed; reproject and review native trust"
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
decision = evaluateShellHook(
|
|
299
|
+
root,
|
|
300
|
+
policy,
|
|
301
|
+
tool,
|
|
302
|
+
JSON.parse(Buffer.concat(chunks).toString("utf8"))
|
|
303
|
+
);
|
|
304
|
+
} catch {
|
|
305
|
+
decision = denied();
|
|
306
|
+
}
|
|
307
|
+
process.stdout.write(
|
|
308
|
+
`${JSON.stringify(nativeHookDecision(tool, decision, afterEdit ? "after_edit" : void 0))}
|
|
309
|
+
`
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/project/hook-adapter.ts
|
|
314
|
+
if (process.argv[2] === "--pmcp-shell-hook") {
|
|
315
|
+
await main();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/project/hook-bundle.ts
|
|
319
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
|
|
320
|
+
import { fileURLToPath } from "url";
|
|
321
|
+
|
|
322
|
+
// src/hooks/compiled.ts
|
|
323
|
+
import { createHash as createHash2 } from "crypto";
|
|
324
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
325
|
+
import { join as join2 } from "path";
|
|
326
|
+
|
|
327
|
+
// src/hooks/integrity-cache.ts
|
|
328
|
+
import {
|
|
329
|
+
mkdirSync,
|
|
330
|
+
readFileSync as readFileSync2,
|
|
331
|
+
renameSync,
|
|
332
|
+
statSync as statSync2,
|
|
333
|
+
writeFileSync
|
|
334
|
+
} from "fs";
|
|
335
|
+
import { homedir } from "os";
|
|
336
|
+
import { dirname as dirname2, join } from "path";
|
|
337
|
+
|
|
338
|
+
// src/hooks/compiled.ts
|
|
339
|
+
var HOOK_DIRECTORY = ".agents/pmcp-hooks";
|
|
340
|
+
var POLICY_FILE = `${HOOK_DIRECTORY}/policy.json`;
|
|
341
|
+
var HOOK_FILE = `${HOOK_DIRECTORY}/hook.mjs`;
|
|
342
|
+
var HOOK_BODY_FILE = `${HOOK_DIRECTORY}/hook-body.mjs`;
|
|
343
|
+
var LOCK_FILE = "pmcp.lock";
|
|
344
|
+
function sha256(text) {
|
|
345
|
+
return createHash2("sha256").update(text).digest("hex");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/project/hook-bundle.ts
|
|
349
|
+
var BUNDLE_NATIVE_FILES = [
|
|
350
|
+
...new Set(NATIVE_HOOK_FILES.map((native2) => native2.file))
|
|
351
|
+
];
|
|
352
|
+
function bundleOwns(file, key) {
|
|
353
|
+
return NATIVE_HOOK_FILES.some(
|
|
354
|
+
(native2) => native2.file === file && key.length === 2 && key[0] === native2.root
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
function bundleSource(name) {
|
|
358
|
+
const published = fileURLToPath(new URL(`./${name}`, import.meta.url));
|
|
359
|
+
const sourceBuild = fileURLToPath(
|
|
360
|
+
new URL(`../../dist/${name}`, import.meta.url)
|
|
361
|
+
);
|
|
362
|
+
const file = existsSync2(published) ? published : sourceBuild;
|
|
363
|
+
if (!existsSync2(file)) {
|
|
364
|
+
throw new ProjectError("Build pmcp before projecting the hook bundle");
|
|
365
|
+
}
|
|
366
|
+
return readFileSync4(file, "utf8");
|
|
367
|
+
}
|
|
368
|
+
function bundleFiles(spec) {
|
|
369
|
+
if (!spec.hookBundle?.policy) return [];
|
|
370
|
+
return [
|
|
371
|
+
{ kind: "file", path: HOOK_FILE, content: bundleSource("hook.js") },
|
|
372
|
+
{
|
|
373
|
+
kind: "file",
|
|
374
|
+
path: HOOK_BODY_FILE,
|
|
375
|
+
content: bundleSource("hook-body.js")
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
kind: "file",
|
|
379
|
+
path: POLICY_FILE,
|
|
380
|
+
content: `${JSON.stringify(spec.hookBundle.policy, null, 2)}
|
|
381
|
+
`
|
|
382
|
+
},
|
|
383
|
+
...(spec.hookBundle.files ?? []).map((file) => ({
|
|
384
|
+
kind: "file",
|
|
385
|
+
path: file.path,
|
|
386
|
+
content: file.content
|
|
387
|
+
}))
|
|
388
|
+
];
|
|
389
|
+
}
|
|
390
|
+
function bundleEdits(spec) {
|
|
391
|
+
return spec.hookBundle?.edits ?? [];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/project/hooks.ts
|
|
395
|
+
var HOOK_DIRECTORY2 = ".agents/pmcp-hooks";
|
|
396
|
+
var ADAPTER = `${HOOK_DIRECTORY2}/adapter.mjs`;
|
|
397
|
+
var native = {
|
|
398
|
+
codex: {
|
|
399
|
+
file: ".codex/hooks.json",
|
|
400
|
+
key: ["hooks", "PreToolUse"],
|
|
401
|
+
matcher: "Bash"
|
|
402
|
+
},
|
|
403
|
+
gemini: {
|
|
404
|
+
file: ".gemini/settings.json",
|
|
405
|
+
key: ["hooks", "BeforeTool"],
|
|
406
|
+
matcher: "run_shell_command"
|
|
407
|
+
},
|
|
408
|
+
antigravity: {
|
|
409
|
+
file: ".agents/hooks.json",
|
|
410
|
+
key: ["pmcp-shell", "PreToolUse"],
|
|
411
|
+
matcher: "run_command"
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var editNative = {
|
|
415
|
+
file: ".codex/hooks.json",
|
|
416
|
+
key: ["hooks", "PostToolUse"],
|
|
417
|
+
matcher: "^apply_patch$"
|
|
418
|
+
};
|
|
419
|
+
function object2(value) {
|
|
420
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
421
|
+
throw new ProjectError(
|
|
422
|
+
"Native hook configuration must be an object; contents are redacted"
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
return value;
|
|
426
|
+
}
|
|
427
|
+
function groups(root, file, key) {
|
|
428
|
+
const absolute = join3(root, file);
|
|
429
|
+
if (!existsSync3(absolute)) {
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
let value;
|
|
433
|
+
try {
|
|
434
|
+
value = JSON.parse(readFileSync5(absolute, "utf8"));
|
|
435
|
+
} catch {
|
|
436
|
+
throw new ProjectError(
|
|
437
|
+
"Cannot parse native hook configuration; contents are redacted"
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
for (const part of key) {
|
|
441
|
+
value = object2(value)[part];
|
|
442
|
+
if (value === void 0) {
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!Array.isArray(value)) {
|
|
447
|
+
throw new ProjectError("Native shell hook entries must be an array");
|
|
448
|
+
}
|
|
449
|
+
return value;
|
|
450
|
+
}
|
|
451
|
+
function adapterSource() {
|
|
452
|
+
const published = fileURLToPath2(
|
|
453
|
+
new URL("./project/hook-adapter.js", import.meta.url)
|
|
454
|
+
);
|
|
455
|
+
const sourceBuild = fileURLToPath2(
|
|
456
|
+
new URL("../../dist/project/hook-adapter.js", import.meta.url)
|
|
457
|
+
);
|
|
458
|
+
const file = existsSync3(published) ? published : sourceBuild;
|
|
459
|
+
if (!existsSync3(file)) {
|
|
460
|
+
throw new ProjectError("Build pmcp before projecting shell hook adapters");
|
|
461
|
+
}
|
|
462
|
+
return readFileSync5(file, "utf8");
|
|
463
|
+
}
|
|
464
|
+
function hookOutputs(spec) {
|
|
465
|
+
const lockFile = join3(spec.root, "pmcp.lock");
|
|
466
|
+
const lock = existsSync3(lockFile) ? JSON.parse(readFileSync5(lockFile, "utf8")) : {};
|
|
467
|
+
const previous = new Map(
|
|
468
|
+
(lock.outputs ?? []).filter((entry) => entry.managed !== void 0).filter((entry) => /#(hooks|pmcp-shell|pmcp)\./u.test(entry.path)).map((entry) => [entry.path, entry.managed])
|
|
469
|
+
);
|
|
470
|
+
const selected = (spec.hooks ?? []).filter(
|
|
471
|
+
(hook) => hook.targets.some((tool) => spec.tools.has(tool))
|
|
472
|
+
);
|
|
473
|
+
if (selected.length === 0 && previous.size === 0 && !spec.hookBundle) {
|
|
474
|
+
return [];
|
|
475
|
+
}
|
|
476
|
+
const outputs = [];
|
|
477
|
+
const desired = /* @__PURE__ */ new Map();
|
|
478
|
+
if (selected.length > 0) {
|
|
479
|
+
const adapter = adapterSource();
|
|
480
|
+
outputs.push({ kind: "file", path: ADAPTER, content: adapter });
|
|
481
|
+
for (const hook of selected) {
|
|
482
|
+
const policyFile = `${HOOK_DIRECTORY2}/${hook.name}.json`;
|
|
483
|
+
const guardSha256 = createHash3("sha256").update(readFileSync5(guardPath(spec.root, hook.command))).digest("hex");
|
|
484
|
+
const policy = `${JSON.stringify({ ...hook, contractVersion: 1, guardSha256 }, null, 2)}
|
|
485
|
+
`;
|
|
486
|
+
outputs.push({ kind: "file", path: policyFile, content: policy });
|
|
487
|
+
const integrity = createHash3("sha256").update(adapter).update(policy).digest("hex");
|
|
488
|
+
for (const tool of hook.targets) {
|
|
489
|
+
if (!spec.tools.has(tool)) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (hook.event === "after_edit" && tool !== "codex") {
|
|
493
|
+
throw new ProjectError("Edit hooks currently support codex only");
|
|
494
|
+
}
|
|
495
|
+
const target = hook.event === "after_edit" ? editNative : native[tool];
|
|
496
|
+
const eventArgument = hook.event === "after_edit" ? " after_edit" : "";
|
|
497
|
+
const command = climbCommand(
|
|
498
|
+
`node ${ADAPTER} --pmcp-shell-hook ${tool} ${policyFile} ${integrity}${eventArgument}`,
|
|
499
|
+
tool === "antigravity" ? `printf '%s\\n' '{"decision":"allow"}'` : void 0
|
|
500
|
+
);
|
|
501
|
+
const timeout = tool === "gemini" ? hook.timeoutMs + 2e3 : Math.ceil(hook.timeoutMs / 1e3) + 2;
|
|
502
|
+
const value = {
|
|
503
|
+
matcher: target.matcher,
|
|
504
|
+
hooks: [{ type: "command", command, timeout }]
|
|
505
|
+
};
|
|
506
|
+
const path = `${target.file}#${target.key.join(".")}`;
|
|
507
|
+
const entry = desired.get(path) ?? {
|
|
508
|
+
file: target.file,
|
|
509
|
+
key: target.key,
|
|
510
|
+
managed: []
|
|
511
|
+
};
|
|
512
|
+
entry.managed.push(value);
|
|
513
|
+
desired.set(path, entry);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
outputs.push(...bundleFiles(spec));
|
|
518
|
+
for (const edit of bundleEdits(spec)) {
|
|
519
|
+
const path = `${edit.file}#${edit.key.join(".")}`;
|
|
520
|
+
const entry = desired.get(path) ?? {
|
|
521
|
+
file: edit.file,
|
|
522
|
+
key: edit.key,
|
|
523
|
+
managed: []
|
|
524
|
+
};
|
|
525
|
+
entry.managed.push(...edit.entries);
|
|
526
|
+
desired.set(path, entry);
|
|
527
|
+
}
|
|
528
|
+
const same2 = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
|
529
|
+
for (const path of /* @__PURE__ */ new Set([...desired.keys(), ...previous.keys()])) {
|
|
530
|
+
const parts = splitKeyed(path);
|
|
531
|
+
const bundleOwned = parts !== null && bundleOwns(parts.file, parts.key);
|
|
532
|
+
if (!parts || !bundleOwned && ![...Object.values(native), editNative].some(
|
|
533
|
+
(entry) => entry.file === parts.file && entry.key.join(".") === parts.key.join(".")
|
|
534
|
+
)) {
|
|
535
|
+
throw new ProjectError("Unknown managed hook path in pmcp.lock");
|
|
536
|
+
}
|
|
537
|
+
const current = groups(spec.root, parts.file, parts.key);
|
|
538
|
+
const owned = previous.get(path) ?? [];
|
|
539
|
+
const planned = desired.get(path)?.managed ?? [];
|
|
540
|
+
const missingOwned = owned.some(
|
|
541
|
+
(entry) => !current.some((value) => same2(value, entry))
|
|
542
|
+
);
|
|
543
|
+
const reconciled = owned.length === planned.length && planned.every((entry) => current.some((value) => same2(value, entry)));
|
|
544
|
+
if (current.length > 0 && missingOwned && !reconciled) {
|
|
545
|
+
throw new ProjectError(
|
|
546
|
+
"Owned shell hook entries were edited or removed; review native configuration before projecting"
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
const unowned = current.filter(
|
|
550
|
+
(value) => !owned.some((entry) => same2(value, entry)) && !planned.some((entry) => same2(value, entry))
|
|
551
|
+
);
|
|
552
|
+
if (unowned.some((value) => JSON.stringify(value).includes(HOOK_DIRECTORY2))) {
|
|
553
|
+
throw new ProjectError(
|
|
554
|
+
"Refusing an unowned PMCP shell hook adapter conflict"
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
outputs.push({
|
|
558
|
+
...jsonOutput(parts.file, parts.key, [...unowned, ...planned]),
|
|
559
|
+
managed: planned
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
return outputs;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// src/project/adapters/opencode-skills.ts
|
|
566
|
+
function opencodeSkillOutputs(spec, names) {
|
|
567
|
+
if (!spec.tools.has("opencode")) return [];
|
|
568
|
+
return names.filter((name) => spec.skills[name]?.invocation === "user").map(
|
|
569
|
+
(name) => jsonOutput(OPENCODE_CONFIG, ["permission", "skill", name], "deny")
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// src/project/blocks.ts
|
|
574
|
+
function mergeBlocks(outputs) {
|
|
575
|
+
const contents = /* @__PURE__ */ new Map();
|
|
576
|
+
for (const output of outputs) {
|
|
577
|
+
if (output.kind !== "block") continue;
|
|
578
|
+
contents.set(output.file, [
|
|
579
|
+
...contents.get(output.file) ?? [],
|
|
580
|
+
output.content
|
|
581
|
+
]);
|
|
582
|
+
}
|
|
583
|
+
const merged = [];
|
|
584
|
+
const done = /* @__PURE__ */ new Set();
|
|
585
|
+
for (const output of outputs) {
|
|
586
|
+
if (output.kind !== "block") {
|
|
587
|
+
merged.push(output);
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
if (done.has(output.file)) continue;
|
|
591
|
+
done.add(output.file);
|
|
592
|
+
const parts = contents.get(output.file) ?? [];
|
|
593
|
+
if (parts.length === 1) {
|
|
594
|
+
merged.push(output);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
const content = `${parts.map((part) => part.trimEnd()).join("\n\n")}
|
|
598
|
+
`;
|
|
599
|
+
merged.push(blockOutput(output.file, content));
|
|
600
|
+
}
|
|
601
|
+
return merged;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// src/project/marketplaces.ts
|
|
605
|
+
var CLAUDE_SETTINGS = ".claude/settings.json";
|
|
606
|
+
var CODEX_CONFIG = ".codex/config.toml";
|
|
607
|
+
var builtinRoot = () => publicMarketplaceRoot();
|
|
608
|
+
function marketplaceOutputs(spec) {
|
|
609
|
+
const declared = spec.marketplaces ?? [];
|
|
610
|
+
const outputs = [];
|
|
611
|
+
if (spec.tools.has("claude")) {
|
|
612
|
+
for (const { key, value } of claudeSettings(declared, builtinRoot))
|
|
613
|
+
outputs.push(jsonOutput(CLAUDE_SETTINGS, key, value));
|
|
614
|
+
}
|
|
615
|
+
const toml = spec.tools.has("codex") ? codexConfig(declared, builtinRoot) : "";
|
|
616
|
+
if (toml) outputs.push(blockOutput(CODEX_CONFIG, toml));
|
|
617
|
+
return outputs;
|
|
618
|
+
}
|
|
619
|
+
function marketplaceDoctor(spec, run) {
|
|
620
|
+
const declared = spec.marketplaces ?? [];
|
|
621
|
+
if (forRuntime(declared, "codex").length === 0) return [];
|
|
622
|
+
const check = "declared plugins";
|
|
623
|
+
const result = run("codex", CODEX_PLUGIN_LIST, spec.root);
|
|
624
|
+
if (result.missing) return [{ tool: "codex", check, status: "skip" }];
|
|
625
|
+
const states = parseCodexPluginList(result.stdout);
|
|
626
|
+
if (!states)
|
|
627
|
+
return [
|
|
628
|
+
{
|
|
629
|
+
tool: "codex",
|
|
630
|
+
check,
|
|
631
|
+
status: "fail",
|
|
632
|
+
detail: "codex plugin list printed no JSON"
|
|
633
|
+
}
|
|
634
|
+
];
|
|
635
|
+
return codexMarketplaceChecks(declared, states, builtinRoot).map((item) => ({
|
|
636
|
+
tool: "codex",
|
|
637
|
+
check: item.check,
|
|
638
|
+
status: item.ok ? "ok" : "fail",
|
|
639
|
+
...item.detail ? { detail: item.detail } : {}
|
|
640
|
+
}));
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// src/project/plan.ts
|
|
644
|
+
var AGENT_FIELDS = {
|
|
645
|
+
claude: ["name", "description", "tools", "model", "effort"],
|
|
646
|
+
gemini: ["name", "description"]
|
|
647
|
+
};
|
|
648
|
+
var SETTINGS2 = ".claude/settings.json";
|
|
649
|
+
function listDirs(dir) {
|
|
650
|
+
if (!existsSync4(dir)) return [];
|
|
651
|
+
return readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
|
|
652
|
+
}
|
|
653
|
+
var tomlString = (value) => JSON.stringify(typeof value === "string" ? value : String(value ?? ""));
|
|
654
|
+
function skillNames(root) {
|
|
655
|
+
const dir = join4(root, ".agents/skills");
|
|
656
|
+
return listDirs(dir).filter(
|
|
657
|
+
(name) => existsSync4(join4(dir, name, "SKILL.md"))
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
function agentNames(root) {
|
|
661
|
+
const dir = join4(root, ".agents/agents");
|
|
662
|
+
return listDirs(dir).filter(
|
|
663
|
+
(name) => existsSync4(join4(dir, name, "agent.md"))
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
function skillOutputs(spec) {
|
|
667
|
+
const names = skillNames(spec.root);
|
|
668
|
+
const outputs = opencodeSkillOutputs(spec, names);
|
|
669
|
+
for (const name of names) {
|
|
670
|
+
const target = `../../.agents/skills/${name}`;
|
|
671
|
+
if (spec.tools.has("claude")) {
|
|
672
|
+
outputs.push({ kind: "link", path: `.claude/skills/${name}`, target });
|
|
673
|
+
}
|
|
674
|
+
if (spec.tools.has("grok")) {
|
|
675
|
+
outputs.push({ kind: "link", path: `.grok/skills/${name}`, target });
|
|
676
|
+
}
|
|
677
|
+
if (spec.skills[name]?.invocation !== "user") continue;
|
|
678
|
+
if (spec.tools.has("claude")) {
|
|
679
|
+
outputs.push(
|
|
680
|
+
jsonOutput(SETTINGS2, ["skillOverrides", name], "user-invocable-only")
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
if (spec.tools.has("codex")) {
|
|
684
|
+
outputs.push({
|
|
685
|
+
kind: "file",
|
|
686
|
+
path: `.agents/skills/${name}/agents/openai.yaml`,
|
|
687
|
+
content: `# ${MARK}
|
|
688
|
+
policy:
|
|
689
|
+
allow_implicit_invocation: false
|
|
690
|
+
`
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return outputs;
|
|
695
|
+
}
|
|
696
|
+
function ruleOutputs(spec) {
|
|
697
|
+
if (!spec.tools.has("claude")) return [];
|
|
698
|
+
const dir = join4(spec.root, ".agents/rules");
|
|
699
|
+
if (!existsSync4(dir)) return [];
|
|
700
|
+
const outputs = [];
|
|
701
|
+
for (const file of readdirSync(dir).filter((f) => f.endsWith(".md")).sort()) {
|
|
702
|
+
const rel = `.agents/rules/${file}`;
|
|
703
|
+
const { meta, body } = splitFrontmatter(
|
|
704
|
+
readFileSync6(join4(spec.root, rel), "utf8")
|
|
705
|
+
);
|
|
706
|
+
const globs = [meta["globs"] ?? []].flat().filter((g) => typeof g === "string" && g !== "");
|
|
707
|
+
const head = globs.length > 0 ? renderFrontmatter({ paths: globs }) : "";
|
|
708
|
+
outputs.push({
|
|
709
|
+
kind: "file",
|
|
710
|
+
path: `${RULES_DIR}/pmcp/${file}`,
|
|
711
|
+
content: `${head}
|
|
712
|
+
<!-- ${MARK} from ${rel} -->
|
|
713
|
+
${body}`
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
return outputs;
|
|
717
|
+
}
|
|
718
|
+
function agentOutputs(spec) {
|
|
719
|
+
const outputs = [];
|
|
720
|
+
for (const name of agentNames(spec.root)) {
|
|
721
|
+
const rel = `.agents/agents/${name}/agent.md`;
|
|
722
|
+
const { meta, body } = splitFrontmatter(
|
|
723
|
+
readFileSync6(join4(spec.root, rel), "utf8")
|
|
724
|
+
);
|
|
725
|
+
const overrides = spec.agents[name] ?? {};
|
|
726
|
+
const note = `<!-- ${MARK} from ${rel} -->
|
|
727
|
+
`;
|
|
728
|
+
const pick = (tool) => {
|
|
729
|
+
const merged = {
|
|
730
|
+
...meta,
|
|
731
|
+
...overrides[tool] ?? {}
|
|
732
|
+
};
|
|
733
|
+
const kept = {};
|
|
734
|
+
for (const key of AGENT_FIELDS[tool] ?? []) {
|
|
735
|
+
if (merged[key] !== void 0) kept[key] = merged[key];
|
|
736
|
+
}
|
|
737
|
+
return kept;
|
|
738
|
+
};
|
|
739
|
+
for (const tool of ["claude", "gemini"]) {
|
|
740
|
+
if (!spec.tools.has(tool)) continue;
|
|
741
|
+
outputs.push({
|
|
742
|
+
kind: "file",
|
|
743
|
+
path: `.${tool}/agents/${name}.md`,
|
|
744
|
+
content: `${renderFrontmatter(pick(tool))}
|
|
745
|
+
${note}${body}`
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
if (spec.tools.has("codex")) {
|
|
749
|
+
const toml = [
|
|
750
|
+
`# ${MARK} from ${rel}`,
|
|
751
|
+
`name = ${tomlString(meta["name"])}`,
|
|
752
|
+
`description = ${tomlString(meta["description"])}`,
|
|
753
|
+
`developer_instructions = ${tomlString(body.trim())}`,
|
|
754
|
+
""
|
|
755
|
+
].join("\n");
|
|
756
|
+
outputs.push({
|
|
757
|
+
kind: "file",
|
|
758
|
+
path: `.codex/agents/${name}.toml`,
|
|
759
|
+
content: toml
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return outputs;
|
|
764
|
+
}
|
|
765
|
+
function plan(spec, owned = /* @__PURE__ */ new Map()) {
|
|
766
|
+
const outputs = [
|
|
767
|
+
...skillOutputs(spec),
|
|
768
|
+
...ruleOutputs(spec),
|
|
769
|
+
...agentOutputs(spec),
|
|
770
|
+
...mcpOutputs(spec),
|
|
771
|
+
...marketplaceOutputs(spec),
|
|
772
|
+
...hookOutputs(spec),
|
|
773
|
+
...hostOutputs(spec),
|
|
774
|
+
...uiClaudeOutputs(spec),
|
|
775
|
+
...permissionOutputs(spec)
|
|
776
|
+
];
|
|
777
|
+
if (spec.packageRules && spec.tools.has("claude")) {
|
|
778
|
+
outputs.push(...packageRuleOutputs(spec.root, spec.packageRules, owned));
|
|
779
|
+
}
|
|
780
|
+
return mergeBlocks(outputs);
|
|
781
|
+
}
|
|
782
|
+
function censusDirs(spec) {
|
|
783
|
+
const dirs = [
|
|
784
|
+
".claude/skills",
|
|
785
|
+
".claude/agents",
|
|
786
|
+
".claude/commands",
|
|
787
|
+
".gemini/agents",
|
|
788
|
+
".codex/agents",
|
|
789
|
+
".grok/skills",
|
|
790
|
+
`${RULES_DIR}/pmcp`
|
|
791
|
+
];
|
|
792
|
+
if (spec.packageRules) dirs.push(`${RULES_DIR}/${spec.packageRules.dir}`);
|
|
793
|
+
return dirs;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/project/apply/census.ts
|
|
797
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7, readdirSync as readdirSync2 } from "fs";
|
|
798
|
+
import { join as join5, posix } from "path";
|
|
799
|
+
function undeclared(spec, outputs) {
|
|
800
|
+
const declared = new Set(outputs.map((o) => o.path));
|
|
801
|
+
const found = [];
|
|
802
|
+
for (const dir of censusDirs(spec)) {
|
|
803
|
+
const abs = join5(spec.root, dir);
|
|
804
|
+
if (!existsSync5(abs)) continue;
|
|
805
|
+
for (const entry of readdirSync2(abs)) {
|
|
806
|
+
const path = `${dir}/${entry}`;
|
|
807
|
+
if (!declared.has(path)) found.push(path);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
const rules = join5(spec.root, RULES_DIR);
|
|
811
|
+
if (spec.tools.has("grok") && existsSync5(rules)) {
|
|
812
|
+
for (const entry of readdirSync2(rules, { withFileTypes: true })) {
|
|
813
|
+
if (entry.isDirectory()) continue;
|
|
814
|
+
found.push(`${RULES_DIR}/${entry.name}`);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return found.sort();
|
|
818
|
+
}
|
|
819
|
+
function deadGlobs(root, outputs) {
|
|
820
|
+
const rules = outputs.filter(
|
|
821
|
+
(o) => (o.kind === "link" || o.kind === "file") && o.path.startsWith(`${RULES_DIR}/`)
|
|
822
|
+
);
|
|
823
|
+
if (rules.length === 0) return [];
|
|
824
|
+
const tracked = trackedFiles(root, true);
|
|
825
|
+
if (tracked.length === 0) return [];
|
|
826
|
+
const seen = /* @__PURE__ */ new Set();
|
|
827
|
+
for (const file of tracked) {
|
|
828
|
+
const parts = file.split("/");
|
|
829
|
+
for (let i = 1; i <= parts.length; i += 1)
|
|
830
|
+
seen.add(parts.slice(0, i).join("/"));
|
|
831
|
+
}
|
|
832
|
+
const dead = [];
|
|
833
|
+
for (const rule of rules) {
|
|
834
|
+
let text;
|
|
835
|
+
if (rule.kind === "file") {
|
|
836
|
+
text = rule.content;
|
|
837
|
+
} else if (rule.kind === "link") {
|
|
838
|
+
const abs = join5(root, posix.join(posix.dirname(rule.path), rule.target));
|
|
839
|
+
if (!existsSync5(abs)) continue;
|
|
840
|
+
text = readFileSync7(abs, "utf8");
|
|
841
|
+
} else {
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
const paths = splitFrontmatter(text).meta["paths"];
|
|
845
|
+
for (const glob of [paths ?? []].flat()) {
|
|
846
|
+
if (typeof glob !== "string") continue;
|
|
847
|
+
const prefix = glob.replace(/\*.*$/u, "").replace(/\/$/u, "");
|
|
848
|
+
if (prefix !== "" && !seen.has(prefix))
|
|
849
|
+
dead.push(`${rule.path}: ${glob}`);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return dead;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// src/project/apply/native.ts
|
|
856
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync8, rmSync } from "fs";
|
|
857
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
858
|
+
function readNativeJson(root, outputs, stale) {
|
|
859
|
+
const jsonPaths = new Set(
|
|
860
|
+
outputs.filter((output) => output.kind === "json").map((output) => output.file)
|
|
861
|
+
);
|
|
862
|
+
for (const entry of stale) {
|
|
863
|
+
const keyed = splitKeyed(entry.path);
|
|
864
|
+
if (entry.kind === "json" && keyed) {
|
|
865
|
+
jsonPaths.add(keyed.file);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
for (const path of jsonPaths) {
|
|
869
|
+
readJson(join6(root, path));
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function writeJson(root, file, sets, drops) {
|
|
873
|
+
const abs = join6(root, file);
|
|
874
|
+
const before = readJson(abs);
|
|
875
|
+
const after = structuredClone(before);
|
|
876
|
+
for (const key of drops) deleteKey(after, key);
|
|
877
|
+
for (const output of sets) {
|
|
878
|
+
if (output.kind !== "json") {
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
if (output.managed && Array.isArray(output.value) && output.value.length === 0) {
|
|
882
|
+
deleteKey(after, output.key);
|
|
883
|
+
} else {
|
|
884
|
+
setKey(after, output.key, output.value);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (same(before, after)) return;
|
|
888
|
+
if (!existsSync6(abs) && Object.keys(after).length === 0) return;
|
|
889
|
+
mkdirSync2(dirname3(abs), { recursive: true });
|
|
890
|
+
replaceFile(abs, `${JSON.stringify(after, null, 2)}
|
|
891
|
+
`);
|
|
892
|
+
}
|
|
893
|
+
function separator(before) {
|
|
894
|
+
if (before === "" || before.endsWith("\n\n")) return "";
|
|
895
|
+
return before.endsWith("\n") ? "\n" : "\n\n";
|
|
896
|
+
}
|
|
897
|
+
function writeBlock(root, file, content) {
|
|
898
|
+
const abs = join6(root, file);
|
|
899
|
+
const before = existsSync6(abs) ? readFileSync8(abs, "utf8") : "";
|
|
900
|
+
let after = withoutBlock(before);
|
|
901
|
+
if (content !== null) {
|
|
902
|
+
const sep = separator(after);
|
|
903
|
+
after = `${after}${sep}${block(content)}`;
|
|
904
|
+
}
|
|
905
|
+
if (after === before) return;
|
|
906
|
+
mkdirSync2(dirname3(abs), { recursive: true });
|
|
907
|
+
replaceFile(abs, after);
|
|
908
|
+
}
|
|
909
|
+
function writeNative(root, outputs, stale, basis = /* @__PURE__ */ new Map()) {
|
|
910
|
+
const moved = changedSincePlan(root, basis);
|
|
911
|
+
if (moved.length > 0) throw new ProjectError(moved.join("; "));
|
|
912
|
+
let pruned = 0;
|
|
913
|
+
const jsonFiles = /* @__PURE__ */ new Map();
|
|
914
|
+
const blockFiles = /* @__PURE__ */ new Map();
|
|
915
|
+
for (const output of outputs) {
|
|
916
|
+
if (output.kind === "json") {
|
|
917
|
+
const entry = jsonFiles.get(output.file) ?? { sets: [], drops: [] };
|
|
918
|
+
entry.sets.push(output);
|
|
919
|
+
jsonFiles.set(output.file, entry);
|
|
920
|
+
}
|
|
921
|
+
if (output.kind === "block") blockFiles.set(output.file, output.content);
|
|
922
|
+
}
|
|
923
|
+
for (const entry of stale) {
|
|
924
|
+
const keyed = splitKeyed(entry.path);
|
|
925
|
+
if (keyed && keyed.key.length === 1 && keyed.key[0] === "pmcp") {
|
|
926
|
+
if (!blockFiles.has(keyed.file)) blockFiles.set(keyed.file, null);
|
|
927
|
+
} else if (keyed) {
|
|
928
|
+
const group = jsonFiles.get(keyed.file) ?? { sets: [], drops: [] };
|
|
929
|
+
group.drops.push(keyed.key);
|
|
930
|
+
jsonFiles.set(keyed.file, group);
|
|
931
|
+
} else {
|
|
932
|
+
rmSync(join6(root, entry.path), { force: true, recursive: true });
|
|
933
|
+
}
|
|
934
|
+
pruned += 1;
|
|
935
|
+
}
|
|
936
|
+
for (const [file, { sets, drops }] of jsonFiles)
|
|
937
|
+
writeJson(root, file, sets, drops);
|
|
938
|
+
for (const [file, content] of blockFiles) writeBlock(root, file, content);
|
|
939
|
+
return pruned;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/project/apply/prepare.ts
|
|
943
|
+
import { join as join7 } from "path";
|
|
944
|
+
function prepare(spec) {
|
|
945
|
+
const basis = /* @__PURE__ */ new Map([
|
|
946
|
+
[SETTINGS, fingerprint(join7(spec.root, SETTINGS))]
|
|
947
|
+
]);
|
|
948
|
+
const lock = readLock(spec.root);
|
|
949
|
+
const ownedTargets = new Map(
|
|
950
|
+
lock.filter((entry) => entry.kind === "link" && entry.target !== void 0).map((entry) => [entry.path, entry.target])
|
|
951
|
+
);
|
|
952
|
+
const outputs = plan(spec, ownedTargets);
|
|
953
|
+
const owned = new Set(lock.map((entry) => entry.path));
|
|
954
|
+
const planned = new Set(outputs.map((output) => output.path));
|
|
955
|
+
const stale = lock.filter((entry) => !planned.has(entry.path));
|
|
956
|
+
readNativeJson(spec.root, outputs, stale);
|
|
957
|
+
return { outputs, owned, stale, basis };
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
// src/project/apply/present.ts
|
|
961
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
|
|
962
|
+
import { join as join8 } from "path";
|
|
963
|
+
function present(root, output) {
|
|
964
|
+
const abs = join8(root, "file" in output ? output.file : output.path);
|
|
965
|
+
switch (output.kind) {
|
|
966
|
+
case "link":
|
|
967
|
+
return linkOf(abs) === output.target;
|
|
968
|
+
case "file":
|
|
969
|
+
return existsSync7(abs) && linkOf(abs) === null && readFileSync9(abs, "utf8") === output.content;
|
|
970
|
+
case "json":
|
|
971
|
+
if (output.managed && Array.isArray(output.value) && output.value.length === 0) {
|
|
972
|
+
return getKey(readJson(abs), output.key) === void 0;
|
|
973
|
+
}
|
|
974
|
+
return same(getKey(readJson(abs), output.key), output.value);
|
|
975
|
+
case "block":
|
|
976
|
+
return existsSync7(abs) && readFileSync9(abs, "utf8").includes(block(output.content));
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// src/project/apply/check.ts
|
|
981
|
+
function checkProblems(spec, outputs, stale) {
|
|
982
|
+
return [
|
|
983
|
+
...outputs.filter((o) => !isPermissionPath(o.path) && !present(spec.root, o)).map((o) => `drift: ${o.path}`),
|
|
984
|
+
...permissionProblems(spec),
|
|
985
|
+
...stale.map((e) => `stale: ${e.path}`),
|
|
986
|
+
...undeclared(spec, outputs).map((p) => `undeclared: ${p}`),
|
|
987
|
+
...deadGlobs(spec.root, outputs).map((p) => `dead glob: ${p}`),
|
|
988
|
+
...[lockVersionProblem(spec.root)].filter((p) => p !== null)
|
|
989
|
+
];
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// src/project/apply/check-project.ts
|
|
993
|
+
function checkProject(spec) {
|
|
994
|
+
const { outputs, stale } = prepare(spec);
|
|
995
|
+
const problems = checkProblems(spec, outputs, stale);
|
|
996
|
+
const warnings = [...permissionWarnings(spec), ...spec.deprecations ?? []];
|
|
997
|
+
return {
|
|
998
|
+
code: problems.length > 0 ? 2 : 0,
|
|
999
|
+
problems,
|
|
1000
|
+
...warnings.length > 0 ? { warnings } : {},
|
|
1001
|
+
outputs: outputs.length,
|
|
1002
|
+
pruned: 0
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
export {
|
|
1007
|
+
splitFrontmatter,
|
|
1008
|
+
renderFrontmatter,
|
|
1009
|
+
POLICY_FILE,
|
|
1010
|
+
HOOK_FILE,
|
|
1011
|
+
LOCK_FILE,
|
|
1012
|
+
sha256,
|
|
1013
|
+
BUNDLE_NATIVE_FILES,
|
|
1014
|
+
HOOK_DIRECTORY2 as HOOK_DIRECTORY,
|
|
1015
|
+
marketplaceDoctor,
|
|
1016
|
+
skillNames,
|
|
1017
|
+
agentNames,
|
|
1018
|
+
plan,
|
|
1019
|
+
deadGlobs,
|
|
1020
|
+
present,
|
|
1021
|
+
writeNative,
|
|
1022
|
+
prepare,
|
|
1023
|
+
checkProject
|
|
1024
|
+
};
|
|
1025
|
+
//# sourceMappingURL=chunk-A7VF7A35.js.map
|