@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.
Files changed (246) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/CHANGELOG.md +60 -0
  5. package/README.md +29 -24
  6. package/dist/apply-4IGTXOCQ.js +242 -0
  7. package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
  8. package/dist/available-DBSIVVJ6.js +73 -0
  9. package/dist/broadcast-3RY3OZGY.js +18 -0
  10. package/dist/chunk-25GHX674.js +1246 -0
  11. package/dist/chunk-2P4Z2NUX.js +28 -0
  12. package/dist/chunk-34DECPVC.js +22 -0
  13. package/dist/chunk-3NYG4SGU.js +45 -0
  14. package/dist/chunk-3PW4FI7U.js +32 -0
  15. package/dist/chunk-3Y3HDMHA.js +108 -0
  16. package/dist/chunk-47O3X4VS.js +113 -0
  17. package/dist/chunk-4NDEP7HU.js +26 -0
  18. package/dist/chunk-4VCC2NXE.js +104 -0
  19. package/dist/chunk-5OMOPUE6.js +39 -0
  20. package/dist/chunk-5QQWS4US.js +53 -0
  21. package/dist/chunk-5ZABTVSW.js +48 -0
  22. package/dist/chunk-65ZHM5RH.js +4985 -0
  23. package/dist/chunk-665TA55Z.js +419 -0
  24. package/dist/chunk-6STKGOCW.js +27 -0
  25. package/dist/chunk-6WXMJOMI.js +9 -0
  26. package/dist/chunk-73AKO4UL.js +24 -0
  27. package/dist/chunk-7BLPN3W6.js +31 -0
  28. package/dist/chunk-7DLZC73N.js +29 -0
  29. package/dist/chunk-7GBYECSK.js +72 -0
  30. package/dist/chunk-7TD53M7L.js +13 -0
  31. package/dist/chunk-A4PKLESO.js +112 -0
  32. package/dist/chunk-ABTJQ4QV.js +74 -0
  33. package/dist/chunk-BBTBJCFA.js +380 -0
  34. package/dist/chunk-BU65MNVU.js +13 -0
  35. package/dist/chunk-BVCTKPT3.js +83 -0
  36. package/dist/chunk-C4NHQGHL.js +142 -0
  37. package/dist/chunk-CJTKR6K6.js +1213 -0
  38. package/dist/chunk-DCU2EXQV.js +78 -0
  39. package/dist/chunk-DZ2MRTYT.js +135 -0
  40. package/dist/chunk-E2YOZ2FF.js +207 -0
  41. package/dist/chunk-E3DQB5LS.js +48 -0
  42. package/dist/chunk-E7OOHLQR.js +7 -0
  43. package/dist/chunk-EATCUWGG.js +66 -0
  44. package/dist/chunk-EIDIVIAD.js +33 -0
  45. package/dist/chunk-EJBZGIDK.js +1934 -0
  46. package/dist/chunk-ELAGZ635.js +252 -0
  47. package/dist/chunk-GZHHEHKY.js +44 -0
  48. package/dist/chunk-HDMBVLCZ.js +53 -0
  49. package/dist/chunk-HQOB7OQS.js +81 -0
  50. package/dist/chunk-IGYRMM62.js +28 -0
  51. package/dist/chunk-IJBSOWHK.js +86 -0
  52. package/dist/chunk-INT7QLEU.js +114 -0
  53. package/dist/chunk-J6QLLQVL.js +1025 -0
  54. package/dist/chunk-J7UYNJCR.js +9 -0
  55. package/dist/chunk-JEL35P7S.js +53 -0
  56. package/dist/chunk-JGJ4INEN.js +32 -0
  57. package/dist/chunk-JS5RTH4I.js +84 -0
  58. package/dist/chunk-JUXNIXN4.js +42 -0
  59. package/dist/chunk-JWRZDYB5.js +59 -0
  60. package/dist/chunk-KMXRRSKT.js +660 -0
  61. package/dist/chunk-LAZQBMAU.js +67 -0
  62. package/dist/chunk-LLBPVZXM.js +67 -0
  63. package/dist/chunk-LLT5FQBE.js +57 -0
  64. package/dist/chunk-LMT3PPXJ.js +17 -0
  65. package/dist/chunk-MM2Y43LC.js +87 -0
  66. package/dist/chunk-MPSQXSC6.js +346 -0
  67. package/dist/chunk-MVFH26QT.js +97 -0
  68. package/dist/chunk-MWFOUBFC.js +39 -0
  69. package/dist/chunk-N5AQ3PP7.js +211 -0
  70. package/dist/chunk-NQPURJT5.js +44 -0
  71. package/dist/chunk-NRBQK6UX.js +105 -0
  72. package/dist/chunk-NZS5CD72.js +333 -0
  73. package/dist/chunk-OEH47H6A.js +48 -0
  74. package/dist/chunk-OG7QR2DP.js +75 -0
  75. package/dist/chunk-OPYFEHKG.js +52 -0
  76. package/dist/chunk-P4N7DBD5.js +83 -0
  77. package/dist/chunk-PAX3QXX2.js +140 -0
  78. package/dist/chunk-PLX3BOOS.js +396 -0
  79. package/dist/chunk-PMJG2CXF.js +122 -0
  80. package/dist/chunk-PWSJJXLQ.js +643 -0
  81. package/dist/chunk-Q5H3L6Y4.js +23 -0
  82. package/dist/chunk-Q65R3XKX.js +155 -0
  83. package/dist/chunk-QEW4J3IZ.js +74 -0
  84. package/dist/chunk-QPL7E2HW.js +464 -0
  85. package/dist/chunk-R2GPCZUX.js +22 -0
  86. package/dist/chunk-R4L6LJJ2.js +778 -0
  87. package/dist/chunk-R5MT42JS.js +284 -0
  88. package/dist/chunk-RK4PYD7L.js +73 -0
  89. package/dist/chunk-RMATE45Z.js +197 -0
  90. package/dist/chunk-S3PIAMXV.js +230 -0
  91. package/dist/chunk-SG5TPMKH.js +93 -0
  92. package/dist/chunk-T3LKX23M.js +168 -0
  93. package/dist/chunk-T6GOWHK6.js +30 -0
  94. package/dist/chunk-TIA4SPU2.js +10 -0
  95. package/dist/chunk-TNCZ6444.js +57 -0
  96. package/dist/chunk-TVL5RTE6.js +269 -0
  97. package/dist/chunk-UOCLRM7P.js +151 -0
  98. package/dist/chunk-UPQTAHUK.js +189 -0
  99. package/dist/chunk-V4NPDK6X.js +14 -0
  100. package/dist/chunk-VJFEN6DJ.js +38 -0
  101. package/dist/chunk-WIW772I3.js +25 -0
  102. package/dist/chunk-XELAZAIM.js +136 -0
  103. package/dist/chunk-XNML2KIC.js +23 -0
  104. package/dist/chunk-XP2U3LO3.js +30 -0
  105. package/dist/chunk-YGOWIJPE.js +51 -0
  106. package/dist/chunk-YIXDHQYE.js +11 -0
  107. package/dist/chunk-YMHUM7AV.js +22 -0
  108. package/dist/chunk-YSAWTGNA.js +117 -0
  109. package/dist/chunk-Z4HRRXRF.js +478 -0
  110. package/dist/chunk-ZH6R642Z.js +102 -0
  111. package/dist/claude-U2JC2DNQ.js +77 -0
  112. package/dist/cli-VYCQJZ5X.js +41 -0
  113. package/dist/cli-ZTCBSDW4.js +46 -0
  114. package/dist/cli.js +144 -16197
  115. package/dist/completion-E7RRG3ZT.js +142 -0
  116. package/dist/config-DnpLL2kT.d.ts +46 -0
  117. package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
  118. package/dist/diagnostics-XXH4FLUG.js +93 -0
  119. package/dist/doctor-ZIOESU3N.js +538 -0
  120. package/dist/entry-ZNFCTDVE.js +305 -0
  121. package/dist/exec-mcp-X6372BLE.js +365 -0
  122. package/dist/harness-F2XFDYXF.js +177 -0
  123. package/dist/harness-egress-bridge.js +4 -4
  124. package/dist/harness-launch-gate.js +47 -940
  125. package/dist/harness-pane-runner.js +13 -80
  126. package/dist/harness-worker.js +21 -2703
  127. package/dist/hook-body.js +5221 -0
  128. package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
  129. package/dist/hook.js +26 -0
  130. package/dist/hooks-FYE2L5RW.js +21 -0
  131. package/dist/host-GRY3VAHH.js +22 -0
  132. package/dist/host-X6BR6X4O.js +200 -0
  133. package/dist/host-run-GCA6H6SR.js +307 -0
  134. package/dist/http.d.ts +5 -42
  135. package/dist/http.js +21 -2234
  136. package/dist/import-mcp-2TTBPVLY.js +400 -0
  137. package/dist/index.d.ts +146 -168
  138. package/dist/index.js +133 -4948
  139. package/dist/init-627KFXTG.js +14 -0
  140. package/dist/install-GG7HHZK2.js +796 -0
  141. package/dist/invoke-LW22Z6ET.js +23 -0
  142. package/dist/list-MCP2FXUF.js +68 -0
  143. package/dist/list-NGMSQ5SH.js +65 -0
  144. package/dist/load-BEUBABtB.d.ts +21 -0
  145. package/dist/logout-6CSHUWWE.js +44 -0
  146. package/dist/logs-SPB6AANY.js +107 -0
  147. package/dist/mailbox/index.d.ts +10 -5
  148. package/dist/mailbox/index.js +53 -1572
  149. package/dist/mailbox-7BV54Q4R.js +285 -0
  150. package/dist/mailbox-GDJ7BWQN.js +189 -0
  151. package/dist/mainline-JQTTYJMI.js +639 -0
  152. package/dist/marketplace-G4VQET5W.js +191 -0
  153. package/dist/mcp-2DKVU3SW.js +15 -0
  154. package/dist/mcp-V23HC3LB.js +193 -0
  155. package/dist/models-ISU4DCMA.js +32 -0
  156. package/dist/opencode-CN7JLQYO.js +60 -0
  157. package/dist/pause-FFAYRBWI.js +18 -0
  158. package/dist/preview-DT7DWG5F.js +91 -0
  159. package/dist/project/hook-adapter.d.ts +5 -2
  160. package/dist/project/hook-adapter.js +41 -27
  161. package/dist/project-FY62G55N.js +70 -0
  162. package/dist/pty-XTJ4MIWK.js +94 -0
  163. package/dist/recovery-U6QB3PMT.js +100 -0
  164. package/dist/reindex-Y27QJFDB.js +22 -0
  165. package/dist/resume-UU4HZIUP.js +18 -0
  166. package/dist/run-HALGEJNJ.js +19 -0
  167. package/dist/run-OGA3P7FC.js +126 -0
  168. package/dist/serve-NBKT5BKY.js +104 -0
  169. package/dist/session-XM2CR425.js +159 -0
  170. package/dist/setup-DTKZLZUT.js +18 -0
  171. package/dist/start-login-UIQYQBMC.js +416 -0
  172. package/dist/status-A2OUTNGK.js +9 -0
  173. package/dist/status-H2VAHIDV.js +10 -0
  174. package/dist/status-NOOHW5WA.js +43 -0
  175. package/dist/status-VHODZPXB.js +55 -0
  176. package/dist/status-XQANBVXW.js +286 -0
  177. package/dist/stdio.d.ts +3 -13
  178. package/dist/stdio.js +16 -3186
  179. package/dist/sweep-64JDCGK6.js +18 -0
  180. package/dist/test-MKAXFJOL.js +561 -0
  181. package/dist/tools-gpHNq9Dh.d.ts +328 -0
  182. package/dist/tui-MWKAXE4K.js +153 -0
  183. package/dist/unbroadcast-KPUEFLZD.js +18 -0
  184. package/dist/validate-5GZ5YWNA.js +46 -0
  185. package/dist/worker-RQ575EJL.js +80 -0
  186. package/dist/worktree-create-PZSRB7PH.js +89 -0
  187. package/dist/worktree-list-JYB6VXLW.js +51 -0
  188. package/dist/worktree-sync-UF5CXPWV.js +30 -0
  189. package/docs/hooks/capabilities/antigravity.json +199 -0
  190. package/docs/hooks/capabilities/claude.json +179 -0
  191. package/docs/hooks/capabilities/codex.json +179 -0
  192. package/docs/hooks/capabilities/gemini.json +196 -0
  193. package/docs/hooks/capabilities/grok.json +192 -0
  194. package/docs/hooks/capabilities/opencode.json +184 -0
  195. package/docs/project-configuration.md +821 -4
  196. package/docs/terminal-harness.md +71 -28
  197. package/docs/terminal-workspace.md +91 -170
  198. package/gemini-extension.json +1 -1
  199. package/package.json +13 -1
  200. package/plugin.json +1 -1
  201. package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
  202. package/plugins/pmcp/gemini-extension.json +1 -1
  203. package/plugins/pmcp/mod/commands.ts +72 -0
  204. package/plugins/pmcp/mod/contract.d.ts +39 -0
  205. package/plugins/pmcp/mod/draw.tsx +216 -0
  206. package/plugins/pmcp/mod/guard.ts +42 -0
  207. package/plugins/pmcp/mod/hooks.json +4 -0
  208. package/plugins/pmcp/mod/host.ts +46 -0
  209. package/plugins/pmcp/mod/model.ts +144 -0
  210. package/plugins/pmcp/mod/reader/index.ts +18 -0
  211. package/plugins/pmcp/mod/reader/read.ts +76 -0
  212. package/plugins/pmcp/mod/reader/settings.ts +54 -0
  213. package/plugins/pmcp/mod/reader/types.ts +38 -0
  214. package/plugins/pmcp/mod/register.tsx +73 -0
  215. package/plugins/pmcp/mod/sessions/format.ts +91 -0
  216. package/plugins/pmcp/mod/sessions/types.ts +162 -0
  217. package/plugins/pmcp/mod/snapshot.ts +75 -0
  218. package/plugins/pmcp/mod/spinner.tsx +30 -0
  219. package/plugins/pmcp/mod/state.ts +28 -0
  220. package/plugins/pmcp/plugin.json +1 -1
  221. package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
  222. package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
  223. package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
  224. package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -11
  225. package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +145 -0
  226. package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +104 -0
  227. package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +88 -0
  228. package/schema/catalog-v1.json +158 -0
  229. package/schema/library.json +164 -0
  230. package/schema/marketplace-manifest.json +130 -0
  231. package/schema/plugin-manifest.json +55 -0
  232. package/schema/skill-frontmatter.json +144 -0
  233. package/schema/skill-metadata-core.json +110 -0
  234. package/skills/agent-assets-migrate/SKILL.md +96 -0
  235. package/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
  236. package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
  237. package/skills/package-skill-catalog/SKILL.md +51 -11
  238. package/skills/pmcp-project-init/SKILL.md +145 -0
  239. package/skills/pmcp-sessions-and-git/SKILL.md +104 -0
  240. package/skills/skill-package-scaffold/SKILL.md +88 -0
  241. package/dist/config-BkSpjUG6.d.ts +0 -50
  242. package/dist/embed-DRROSD3F.d.ts +0 -53
  243. package/dist/hook-spec-CSJJySsH.d.ts +0 -11
  244. package/dist/server-VWSY3Shw.d.ts +0 -543
  245. package/dist/tui-worker.js +0 -6549
  246. /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
@@ -0,0 +1,140 @@
1
+ import {
2
+ locateExecutable
3
+ } from "./chunk-R2GPCZUX.js";
4
+ import {
5
+ ConfigError,
6
+ findConfig,
7
+ readConfig
8
+ } from "./chunk-QPL7E2HW.js";
9
+ import {
10
+ privateJson,
11
+ readPrivateJson
12
+ } from "./chunk-TVL5RTE6.js";
13
+ import {
14
+ object,
15
+ text
16
+ } from "./chunk-5OMOPUE6.js";
17
+ import {
18
+ runtimeExecutables
19
+ } from "./chunk-BU65MNVU.js";
20
+
21
+ // src/tui/startup/config.ts
22
+ import { realpathSync } from "fs";
23
+ import { resolve } from "path";
24
+ var preference = [
25
+ "codex-cli",
26
+ "gemini-cli",
27
+ "antigravity",
28
+ "grok-cli",
29
+ "claude-code"
30
+ ];
31
+ function startupSettings(request) {
32
+ const path = request.config ? resolve(request.cwd, request.config) : findConfig(request.cwd);
33
+ const config = path ? readConfig(path) : void 0;
34
+ const source = config?.raw.tui;
35
+ const fail = (message) => {
36
+ throw new ConfigError(path ?? "pmcp.toml", `[tui] ${message}`);
37
+ };
38
+ if (source !== void 0 && (source === null || typeof source !== "object" || Array.isArray(source)))
39
+ fail("must be a table");
40
+ const values = source ?? {};
41
+ const allowed = /* @__PURE__ */ new Set([
42
+ "runtime",
43
+ "memory_mb",
44
+ "session_memory_mb",
45
+ "max_active",
46
+ "group_file"
47
+ ]);
48
+ for (const key of Object.keys(values)) {
49
+ if (!allowed.has(key)) fail(`unknown key ${key}`);
50
+ }
51
+ const string = (key) => {
52
+ const value = values[key];
53
+ if (value === void 0) return void 0;
54
+ if (typeof value !== "string" || !value.trim())
55
+ fail(`${key} must be a non-empty string`);
56
+ return value;
57
+ };
58
+ const integer = (key, fallback, min, max) => {
59
+ const value = values[key] ?? fallback;
60
+ if (typeof value !== "number" || !Number.isSafeInteger(value))
61
+ fail(`${key} must be an integer`);
62
+ if (Number(value) < min || Number(value) > max)
63
+ fail(`${key} must be between ${min} and ${max}`);
64
+ return Number(value);
65
+ };
66
+ const configuredRuntime = string("runtime");
67
+ if (configuredRuntime !== void 0 && configuredRuntime !== "auto" && !Object.hasOwn(runtimeExecutables, configuredRuntime))
68
+ fail("runtime must be auto or a supported runtime ID");
69
+ const available = preference.filter(
70
+ (runtime2) => locateExecutable(runtimeExecutables[runtime2], request.cwd)
71
+ );
72
+ let runtime = request.runtime ?? configuredRuntime ?? "auto";
73
+ if (runtime === "auto") runtime = available[0] ?? "codex-cli";
74
+ if (!Object.hasOwn(runtimeExecutables, runtime))
75
+ fail("runtime must be a supported runtime ID");
76
+ const memoryMb = integer("memory_mb", 2048, 128, 4096);
77
+ const sessionMemoryMb = integer("session_memory_mb", 768, 32, 1536);
78
+ if (sessionMemoryMb > memoryMb)
79
+ fail("session memory exceeds the group budget");
80
+ const groupFile = string("group_file");
81
+ return {
82
+ projectRoot: realpathSync(config?.dir ?? request.cwd),
83
+ ...config ? { configFile: config.path } : {},
84
+ runtime,
85
+ allowedRuntimes: [.../* @__PURE__ */ new Set([...available, runtime])],
86
+ memoryMb,
87
+ sessionMemoryMb,
88
+ maxActive: integer("max_active", 2, 1, 5),
89
+ ...groupFile ? { groupFile: resolve(config?.dir ?? request.cwd, groupFile) } : {}
90
+ };
91
+ }
92
+
93
+ // src/tui/startup/state.ts
94
+ import { createHash } from "crypto";
95
+ import { existsSync, lstatSync, mkdirSync } from "fs";
96
+ import { homedir } from "os";
97
+ import { dirname, join } from "path";
98
+ function startupFile(projectRoot) {
99
+ const root = join(
100
+ process.env.XDG_STATE_HOME ?? join(homedir(), ".local/state"),
101
+ "pmcp/launcher"
102
+ );
103
+ const key = createHash("sha256").update(projectRoot).digest("hex");
104
+ return join(root, `${key}.json`);
105
+ }
106
+ function ensureStartupDirectory(file) {
107
+ const directory = dirname(file);
108
+ mkdirSync(directory, { recursive: true, mode: 448 });
109
+ const stat = lstatSync(directory);
110
+ if (!stat.isDirectory() || stat.uid !== process.getuid?.() || (stat.mode & 63) !== 0)
111
+ throw new Error("unsafe_startup_directory");
112
+ }
113
+ function readStartup(file, projectRoot) {
114
+ if (!existsSync(file)) return null;
115
+ const value = object(readPrivateJson(file));
116
+ if (value.schemaVersion !== 1 || value.projectRoot !== projectRoot)
117
+ throw new Error("foreign_startup_state");
118
+ if (!["creating", "starting", "view-pending", "ready"].includes(
119
+ String(value.phase)
120
+ ))
121
+ throw new Error("invalid_startup_state");
122
+ text(value.runtime, "runtime");
123
+ if (value.phase !== "creating") {
124
+ text(value.groupFile, "group_file");
125
+ text(value.generation, "generation");
126
+ }
127
+ return value;
128
+ }
129
+ function saveStartup(file, state) {
130
+ privateJson(file, state);
131
+ }
132
+
133
+ export {
134
+ startupSettings,
135
+ startupFile,
136
+ ensureStartupDirectory,
137
+ readStartup,
138
+ saveStartup
139
+ };
140
+ //# sourceMappingURL=chunk-PAX3QXX2.js.map
@@ -0,0 +1,396 @@
1
+ import {
2
+ MARK,
3
+ blockOutput,
4
+ jsonOutput
5
+ } from "./chunk-65ZHM5RH.js";
6
+ import {
7
+ ProjectError
8
+ } from "./chunk-NRBQK6UX.js";
9
+
10
+ // src/project/mcp/_shared.ts
11
+ var ROOT_VAR = "${PROJECT_ROOT}";
12
+ var ANTIGRAVITY_MCP_PLUGIN = ".agents/plugins/pmcp-mcp";
13
+ var VARIABLE = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/gu;
14
+
15
+ // src/project/mcp/launch.ts
16
+ var quote = (text) => `'${text.replaceAll("'", "'\\''")}'`;
17
+ function shellWord(text) {
18
+ const pieces = [];
19
+ let offset = 0;
20
+ for (const match of text.matchAll(VARIABLE)) {
21
+ const literal = text.slice(offset, match.index);
22
+ if (literal !== "") {
23
+ pieces.push(quote(literal));
24
+ }
25
+ const name = match[1];
26
+ if (name === "PROJECT_ROOT") {
27
+ pieces.push('"$d"');
28
+ } else {
29
+ pieces.push(`"\${${name}:?${name} is required}"`);
30
+ }
31
+ offset = match.index + match[0].length;
32
+ }
33
+ const tail = text.slice(offset);
34
+ if (tail !== "") {
35
+ pieces.push(quote(tail));
36
+ }
37
+ if (pieces.length === 0) {
38
+ return "''";
39
+ }
40
+ return pieces.join("");
41
+ }
42
+ function forwardedVariables(server) {
43
+ const names = new Set(server.envVars ?? []);
44
+ const words = [
45
+ server.command ?? "",
46
+ ...server.args,
47
+ ...Object.values(server.env),
48
+ server.cwd ?? ""
49
+ ];
50
+ for (const word of words) {
51
+ for (const match of word.matchAll(VARIABLE)) {
52
+ if (match[1] !== "PROJECT_ROOT") {
53
+ names.add(match[1]);
54
+ }
55
+ }
56
+ }
57
+ return [...names].sort();
58
+ }
59
+ function launch(spec) {
60
+ if (spec.command === void 0) {
61
+ throw new ProjectError("An HTTP server cannot be launched as stdio");
62
+ }
63
+ const words = [
64
+ spec.command,
65
+ ...spec.args,
66
+ ...Object.values(spec.env),
67
+ spec.cwd ?? ""
68
+ ];
69
+ const variables = forwardedVariables(spec);
70
+ const needsRoot = words.some((word) => word.includes(ROOT_VAR));
71
+ const needsExpansion = words.some(
72
+ (word) => [...word.matchAll(VARIABLE)].length > 0
73
+ );
74
+ if (!needsExpansion && !spec.cwd && variables.length === 0) {
75
+ return { command: spec.command, args: spec.args, env: spec.env };
76
+ }
77
+ const statements = [];
78
+ if (needsRoot) {
79
+ statements.push(
80
+ [
81
+ // The real directory: an inherited $PWD can name a directory the runtime has left.
82
+ "d=$(pwd -P)",
83
+ 'while [ ! -f "$d/pmcp.toml" ]',
84
+ "do",
85
+ ' [ "$d" = / ] && exit 1',
86
+ ' d=$(dirname "$d")',
87
+ "done"
88
+ ].join("\n")
89
+ );
90
+ }
91
+ for (const name of variables) {
92
+ statements.push(`export ${name}="\${${name}:?${name} is required}"`);
93
+ }
94
+ for (const [key, value] of Object.entries(spec.env)) {
95
+ statements.push(`export ${key}=${shellWord(value)}`);
96
+ }
97
+ if (spec.cwd) {
98
+ statements.push(`cd ${shellWord(spec.cwd)} || exit 1`);
99
+ }
100
+ statements.push(
101
+ `exec ${[spec.command, ...spec.args].map(shellWord).join(" ")}`
102
+ );
103
+ return { command: "sh", args: ["-c", statements.join("\n")], env: {} };
104
+ }
105
+
106
+ // src/project/adapters/opencode.ts
107
+ import { existsSync } from "fs";
108
+ import { join } from "path";
109
+ var OPENCODE_CONFIG = "opencode.json";
110
+ function checkOpenCodeConfig(root) {
111
+ if (existsSync(join(root, "opencode.jsonc"))) {
112
+ throw new ProjectError(
113
+ "OpenCode JSONC projection is not supported; reconcile opencode.jsonc before projecting opencode.json"
114
+ );
115
+ }
116
+ }
117
+ function opencodeMcpEntry(server, started) {
118
+ if (server.tools !== void 0) {
119
+ throw new ProjectError(
120
+ "OpenCode per-server tool filtering is not qualified; limit this server's targets"
121
+ );
122
+ }
123
+ const timeout = server.native?.opencode;
124
+ if (server.url !== void 0) {
125
+ const headers = { ...server.headers };
126
+ for (const [key, name] of Object.entries(server.headerEnv ?? {})) {
127
+ headers[key] = `{env:${name}}`;
128
+ }
129
+ if (server.bearerTokenEnvVar) {
130
+ headers["Authorization"] = `Bearer {env:${server.bearerTokenEnvVar}}`;
131
+ }
132
+ return {
133
+ type: "remote",
134
+ url: server.url,
135
+ enabled: true,
136
+ ...Object.keys(headers).length > 0 ? { headers } : {},
137
+ ...timeout
138
+ };
139
+ }
140
+ if (!started) {
141
+ throw new ProjectError(
142
+ "OpenCode local MCP projection requires a launch specification"
143
+ );
144
+ }
145
+ return {
146
+ type: "local",
147
+ command: [started.command, ...started.args],
148
+ enabled: true,
149
+ ...Object.keys(started.env).length > 0 ? { environment: { ...started.env } } : {},
150
+ ...timeout
151
+ };
152
+ }
153
+
154
+ // src/project/mcp/native.ts
155
+ import { relative as relative2, isAbsolute as isAbsolute2 } from "path";
156
+
157
+ // src/project/mcp/http.ts
158
+ function httpEntry(server, tool) {
159
+ const result = {};
160
+ if (tool === "gemini") {
161
+ result["httpUrl"] = server.url;
162
+ } else if (tool === "antigravity") {
163
+ result["serverUrl"] = server.url;
164
+ } else {
165
+ result["url"] = server.url;
166
+ }
167
+ if (tool === "claude") {
168
+ result["type"] = "http";
169
+ }
170
+ const headers = { ...server.headers };
171
+ if (tool === "antigravity" && (Object.keys(headers).length > 0 || Object.keys(server.headerEnv ?? {}).length > 0 || server.bearerTokenEnvVar !== void 0)) {
172
+ throw new ProjectError(
173
+ "Antigravity HTTP header projection is not qualified; limit this server's targets"
174
+ );
175
+ }
176
+ if (tool === "codex") {
177
+ if (Object.keys(headers).length > 0) {
178
+ result["http_headers"] = headers;
179
+ }
180
+ if (Object.keys(server.headerEnv ?? {}).length > 0) {
181
+ result["env_http_headers"] = { ...server.headerEnv };
182
+ }
183
+ if (server.bearerTokenEnvVar) {
184
+ result["bearer_token_env_var"] = server.bearerTokenEnvVar;
185
+ }
186
+ return result;
187
+ }
188
+ for (const [key, name] of Object.entries(server.headerEnv ?? {})) {
189
+ headers[key] = `\${${name}}`;
190
+ }
191
+ if (server.bearerTokenEnvVar) {
192
+ headers["Authorization"] = `Bearer \${${server.bearerTokenEnvVar}}`;
193
+ }
194
+ if (Object.keys(headers).length > 0) {
195
+ result["headers"] = headers;
196
+ }
197
+ return result;
198
+ }
199
+
200
+ // src/project/mcp/driver.ts
201
+ import { isAbsolute, relative } from "path";
202
+ function proxyDriver(spec, alias) {
203
+ const entry = relative(spec.root, process.argv[1] ?? "");
204
+ if (!isAbsolute(entry) && !entry.startsWith("..")) {
205
+ return launch({
206
+ command: "node",
207
+ args: [`${ROOT_VAR}/${entry}`, "project", "exec-mcp", alias],
208
+ env: {}
209
+ });
210
+ }
211
+ return launch({
212
+ command: "pmcp",
213
+ args: ["project", "exec-mcp", alias],
214
+ env: {}
215
+ });
216
+ }
217
+
218
+ // src/project/mcp/native.ts
219
+ var runtimeByTool = {
220
+ claude: "claude-code",
221
+ codex: "codex-cli",
222
+ gemini: "gemini-cli",
223
+ grok: "grok-cli",
224
+ antigravity: "antigravity"
225
+ };
226
+ function mailboxRuntime(tool) {
227
+ const runtime = runtimeByTool[tool];
228
+ if (!runtime) {
229
+ throw new ProjectError(
230
+ "OpenCode mailbox runtime binding is not qualified; limit this server's targets"
231
+ );
232
+ }
233
+ return runtime;
234
+ }
235
+ var PMCP_AUTH_TOOLS = [
236
+ "claude",
237
+ "codex",
238
+ "gemini",
239
+ "antigravity",
240
+ "grok",
241
+ "opencode"
242
+ ];
243
+ function nativeEntry(spec, alias, server, tool) {
244
+ let result;
245
+ if (server.auth === "pmcp") {
246
+ if (!PMCP_AUTH_TOOLS.includes(tool))
247
+ throw new ProjectError(
248
+ `pmcp MCP authentication currently supports ${PMCP_AUTH_TOOLS.join(", ")} targets`
249
+ );
250
+ const started = proxyDriver(spec, alias);
251
+ if (tool === "opencode") {
252
+ const { url: _remote, ...local } = server;
253
+ return opencodeMcpEntry(local, started);
254
+ }
255
+ result = { command: started.command, args: [...started.args] };
256
+ if (Object.keys(started.env).length) result["env"] = started.env;
257
+ if (tool === "codex")
258
+ result["env_vars"] = [
259
+ "XDG_STATE_HOME",
260
+ ...Object.values(server.headerEnv ?? {})
261
+ ];
262
+ } else if (server.url !== void 0) {
263
+ if (tool === "opencode") return opencodeMcpEntry(server);
264
+ result = httpEntry(server, tool);
265
+ } else {
266
+ const env = { ...server.env };
267
+ if (server.mailbox) {
268
+ env["PMCP_MAILBOX_RUNTIME"] = mailboxRuntime(tool);
269
+ }
270
+ let started;
271
+ if (Object.keys(server.envFrom ?? {}).length > 0) {
272
+ const entry = relative2(spec.root, process.argv[1] ?? "");
273
+ const driverEnv = {};
274
+ if (server.mailbox) {
275
+ driverEnv["PMCP_MAILBOX_RUNTIME"] = mailboxRuntime(tool);
276
+ }
277
+ if (!isAbsolute2(entry) && !entry.startsWith("..")) {
278
+ started = launch({
279
+ command: "node",
280
+ args: [`${ROOT_VAR}/${entry}`, "project", "exec-mcp", alias],
281
+ env: driverEnv
282
+ });
283
+ } else {
284
+ started = launch({
285
+ command: "pmcp",
286
+ args: ["project", "exec-mcp", alias],
287
+ env: driverEnv
288
+ });
289
+ }
290
+ } else {
291
+ started = launch({ ...server, env });
292
+ }
293
+ if (tool === "opencode") return opencodeMcpEntry(server, started);
294
+ result = { command: started.command, args: [...started.args] };
295
+ if (Object.keys(started.env).length > 0) {
296
+ result["env"] = { ...started.env };
297
+ }
298
+ const variables = forwardedVariables(server).filter(
299
+ (key) => !Object.hasOwn(server.envFrom ?? {}, key)
300
+ );
301
+ if (tool === "codex" && variables.length > 0) {
302
+ result["env_vars"] = variables;
303
+ }
304
+ }
305
+ if (server.tools) {
306
+ if (tool === "gemini") {
307
+ result["includeTools"] = [...server.tools];
308
+ }
309
+ if (tool === "codex") {
310
+ result["enabled_tools"] = [...server.tools];
311
+ }
312
+ }
313
+ return { ...result, ...server.native?.[tool] };
314
+ }
315
+
316
+ // src/project/mcp/outputs.ts
317
+ var tomlValue = (value) => {
318
+ if (Array.isArray(value)) {
319
+ return `[${value.map(tomlValue).join(", ")}]`;
320
+ }
321
+ if (value !== null && typeof value === "object") {
322
+ const parts = Object.entries(value).map(
323
+ ([key, item]) => `${JSON.stringify(key)} = ${tomlValue(item)}`
324
+ );
325
+ return `{ ${parts.join(", ")} }`;
326
+ }
327
+ return JSON.stringify(value);
328
+ };
329
+ function serversForTool(spec, tool) {
330
+ return Object.entries(spec.mcp).filter(
331
+ ([, server]) => server.targets === void 0 || server.targets.includes(tool)
332
+ );
333
+ }
334
+ function tomlServers(spec, servers, tool) {
335
+ const lines = [`# ${MARK} from pmcp.toml [mcp]`];
336
+ for (const [alias, server] of servers) {
337
+ lines.push("", `[mcp_servers.${alias}]`);
338
+ for (const [key, value] of Object.entries(
339
+ nativeEntry(spec, alias, server, tool)
340
+ )) {
341
+ lines.push(`${key} = ${tomlValue(value)}`);
342
+ }
343
+ }
344
+ return `${lines.join("\n")}
345
+ `;
346
+ }
347
+ function mcpOutputs(spec) {
348
+ const outputs = [];
349
+ const jsonFiles = {
350
+ claude: ".mcp.json",
351
+ gemini: ".gemini/settings.json",
352
+ antigravity: `${ANTIGRAVITY_MCP_PLUGIN}/mcp_config.json`,
353
+ opencode: OPENCODE_CONFIG
354
+ };
355
+ for (const tool of spec.tools) {
356
+ if (tool === "opencode") checkOpenCodeConfig(spec.root);
357
+ const servers = serversForTool(spec, tool);
358
+ if (servers.length === 0) {
359
+ continue;
360
+ }
361
+ if (tool === "antigravity") {
362
+ outputs.push({
363
+ kind: "file",
364
+ path: `${ANTIGRAVITY_MCP_PLUGIN}/plugin.json`,
365
+ content: `${JSON.stringify({ name: "pmcp-mcp" }, null, 2)}
366
+ `
367
+ });
368
+ }
369
+ const file = jsonFiles[tool];
370
+ if (file) {
371
+ for (const [alias, server] of servers) {
372
+ outputs.push(
373
+ jsonOutput(
374
+ file,
375
+ [tool === "opencode" ? "mcp" : "mcpServers", alias],
376
+ nativeEntry(spec, alias, server, tool)
377
+ )
378
+ );
379
+ }
380
+ continue;
381
+ }
382
+ outputs.push(
383
+ blockOutput(`.${tool}/config.toml`, tomlServers(spec, servers, tool))
384
+ );
385
+ }
386
+ return outputs;
387
+ }
388
+
389
+ export {
390
+ ANTIGRAVITY_MCP_PLUGIN,
391
+ launch,
392
+ OPENCODE_CONFIG,
393
+ serversForTool,
394
+ mcpOutputs
395
+ };
396
+ //# sourceMappingURL=chunk-PLX3BOOS.js.map
@@ -0,0 +1,122 @@
1
+ // src/encoder.ts
2
+ import { createHash } from "crypto";
3
+ var DEFAULT_MODEL_ID = "Xenova/multilingual-e5-small";
4
+ var PLAIN = {
5
+ queryPrefix: "",
6
+ passagePrefix: "",
7
+ pooling: "mean"
8
+ };
9
+ var E5 = {
10
+ queryPrefix: "query: ",
11
+ passagePrefix: "passage: ",
12
+ pooling: "mean"
13
+ };
14
+ var GEMMA = {
15
+ queryPrefix: "task: search result | query: ",
16
+ passagePrefix: "title: none | text: ",
17
+ pooling: "mean",
18
+ projected: true
19
+ };
20
+ var MODELS = [
21
+ {
22
+ name: "e5-small",
23
+ modelId: DEFAULT_MODEL_ID,
24
+ dtype: "q8",
25
+ dtypes: ["q8", "fp32"],
26
+ dimensions: [384],
27
+ revision: "main",
28
+ encoder: E5
29
+ },
30
+ {
31
+ name: "embeddinggemma-300m",
32
+ modelId: "onnx-community/embeddinggemma-300m-ONNX",
33
+ dtype: "q4",
34
+ dtypes: ["q4", "q8", "fp32"],
35
+ dimensions: [768, 512, 256, 128],
36
+ revision: "5090578d9565bb06545b4552f76e6bc2c93e4a66",
37
+ encoder: GEMMA
38
+ },
39
+ {
40
+ name: "embeddinggemma-2",
41
+ modelId: "onnx-community/embeddinggemma-2-ONNX",
42
+ dtype: "q4",
43
+ dtypes: ["q4", "q8", "fp32"],
44
+ dimensions: [768, 512, 256, 128],
45
+ revision: "daa72c51243991dfcaf9f9137d2c573d8f7790c0",
46
+ encoder: GEMMA
47
+ }
48
+ ];
49
+ function embeddingModels() {
50
+ return MODELS.map((model) => ({
51
+ ...model,
52
+ dtypes: [...model.dtypes],
53
+ dimensions: [...model.dimensions],
54
+ encoder: { ...model.encoder }
55
+ }));
56
+ }
57
+ function encoderSpec(modelId) {
58
+ const known = MODELS.find(
59
+ (model) => model.name === modelId || model.modelId === modelId
60
+ );
61
+ if (known) return { ...known.encoder };
62
+ if (/^Xenova\/multilingual-e5-(base|large)$/.test(modelId)) return { ...E5 };
63
+ if (modelId === "Xenova/bge-m3") return { ...PLAIN, pooling: "cls" };
64
+ return { ...PLAIN };
65
+ }
66
+ function resolveEncoder(model = DEFAULT_MODEL_ID, options = {}) {
67
+ if (typeof model !== "string" || !model.trim())
68
+ throw new Error("Embedding model must be a non-empty name or model ID");
69
+ const preset = MODELS.find(
70
+ (item) => item.name === model || item.modelId === model
71
+ );
72
+ const modelId = preset?.modelId ?? model;
73
+ const dtype = options.dtype ?? preset?.dtype ?? "q8";
74
+ if (!["q4", "q8", "fp32"].includes(dtype))
75
+ throw new Error("Embedding dtype must be q4, q8 or fp32");
76
+ if (preset && !preset.dtypes.includes(dtype))
77
+ throw new Error(`${preset.name} does not support ${dtype}`);
78
+ const dimensions = options.dimensions;
79
+ if (dimensions !== void 0 && (!Number.isSafeInteger(dimensions) || !preset?.dimensions.includes(dimensions)))
80
+ throw new Error(`Unsupported embedding dimensions for ${model}`);
81
+ const revision = options.revision ?? preset?.revision ?? "main";
82
+ if (typeof revision !== "string" || !revision.trim())
83
+ throw new Error("Embedding revision must be a non-empty string");
84
+ const encoder = { ...encoderSpec(modelId), ...options.encoder };
85
+ if (typeof encoder.queryPrefix !== "string" || typeof encoder.passagePrefix !== "string")
86
+ throw new Error("Encoder prefixes must be strings");
87
+ if (!["mean", "cls"].includes(encoder.pooling))
88
+ throw new Error("Encoder pooling must be mean or cls");
89
+ if (encoder.projected !== void 0 && typeof encoder.projected !== "boolean")
90
+ throw new Error("Encoder projected must be a boolean");
91
+ const identity = {
92
+ version: 1,
93
+ modelId,
94
+ dtype,
95
+ revision,
96
+ dimensions: dimensions ?? preset?.dimensions[0] ?? null,
97
+ encoder: {
98
+ queryPrefix: encoder.queryPrefix,
99
+ passagePrefix: encoder.passagePrefix,
100
+ pooling: encoder.pooling,
101
+ projected: encoder.projected ?? false
102
+ }
103
+ };
104
+ const legacy = modelId === DEFAULT_MODEL_ID && dtype === "q8" && revision === "main" && (dimensions === void 0 || dimensions === 384) && encoder.queryPrefix === E5.queryPrefix && encoder.passagePrefix === E5.passagePrefix && encoder.pooling === E5.pooling && !encoder.projected;
105
+ const fingerprint = createHash("sha256").update(JSON.stringify(identity)).digest("hex");
106
+ return {
107
+ modelId,
108
+ dtype,
109
+ dimensions,
110
+ revision,
111
+ encoder,
112
+ indexKey: legacy ? modelId : `${modelId}#${fingerprint}`
113
+ };
114
+ }
115
+
116
+ export {
117
+ DEFAULT_MODEL_ID,
118
+ embeddingModels,
119
+ encoderSpec,
120
+ resolveEncoder
121
+ };
122
+ //# sourceMappingURL=chunk-PMJG2CXF.js.map