@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.
Files changed (272) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +2 -2
  4. package/.mcp.json +1 -1
  5. package/CHANGELOG.md +152 -0
  6. package/CONTRIBUTING.md +71 -0
  7. package/README.md +98 -201
  8. package/SECURITY.md +17 -1
  9. package/dist/apply-JUTGS5WZ.js +242 -0
  10. package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
  11. package/dist/available-DBSIVVJ6.js +73 -0
  12. package/dist/broadcast-CBMVOV3G.js +18 -0
  13. package/dist/chunk-26WLNWDG.js +93 -0
  14. package/dist/chunk-2FIV63WC.js +252 -0
  15. package/dist/chunk-2P4Z2NUX.js +28 -0
  16. package/dist/chunk-34DECPVC.js +22 -0
  17. package/dist/chunk-3FCFAQDG.js +42 -0
  18. package/dist/chunk-3IDXEV5E.js +1934 -0
  19. package/dist/chunk-3PW4FI7U.js +32 -0
  20. package/dist/chunk-3Y3HDMHA.js +108 -0
  21. package/dist/chunk-47O3X4VS.js +113 -0
  22. package/dist/chunk-4NDEP7HU.js +26 -0
  23. package/dist/chunk-5OMOPUE6.js +39 -0
  24. package/dist/chunk-5QQWS4US.js +53 -0
  25. package/dist/chunk-5ZABTVSW.js +48 -0
  26. package/dist/chunk-65KAQSJP.js +7 -0
  27. package/dist/chunk-6STKGOCW.js +27 -0
  28. package/dist/chunk-6WXMJOMI.js +9 -0
  29. package/dist/chunk-73AKO4UL.js +24 -0
  30. package/dist/chunk-7DLZC73N.js +29 -0
  31. package/dist/chunk-7GBYECSK.js +72 -0
  32. package/dist/chunk-7HFIGCSL.js +419 -0
  33. package/dist/chunk-7TD53M7L.js +13 -0
  34. package/dist/chunk-7UCZAN4J.js +778 -0
  35. package/dist/chunk-A4PKLESO.js +112 -0
  36. package/dist/chunk-A7VF7A35.js +1025 -0
  37. package/dist/chunk-ABTJQ4QV.js +74 -0
  38. package/dist/chunk-AJ4VXM2U.js +349 -0
  39. package/dist/chunk-BBTBJCFA.js +380 -0
  40. package/dist/chunk-BU65MNVU.js +13 -0
  41. package/dist/chunk-C4NHQGHL.js +142 -0
  42. package/dist/chunk-CJTKR6K6.js +1213 -0
  43. package/dist/chunk-D77IRGHO.js +1246 -0
  44. package/dist/chunk-DCU2EXQV.js +78 -0
  45. package/dist/chunk-DMZHQZ7P.js +104 -0
  46. package/dist/chunk-DZ2MRTYT.js +135 -0
  47. package/dist/chunk-E2YOZ2FF.js +207 -0
  48. package/dist/chunk-E3DQB5LS.js +48 -0
  49. package/dist/chunk-EATCUWGG.js +66 -0
  50. package/dist/chunk-EAWPJHJ7.js +155 -0
  51. package/dist/chunk-EIDIVIAD.js +33 -0
  52. package/dist/chunk-F5QYZK7E.js +396 -0
  53. package/dist/chunk-F5XMGOOX.js +28 -0
  54. package/dist/chunk-FENOGX3U.js +31 -0
  55. package/dist/chunk-GZHHEHKY.js +44 -0
  56. package/dist/chunk-HDMBVLCZ.js +53 -0
  57. package/dist/chunk-HQOB7OQS.js +81 -0
  58. package/dist/chunk-I2ZP2PSA.js +211 -0
  59. package/dist/chunk-IG33DXLT.js +151 -0
  60. package/dist/chunk-IJBSOWHK.js +86 -0
  61. package/dist/chunk-INT7QLEU.js +114 -0
  62. package/dist/chunk-J7UYNJCR.js +9 -0
  63. package/dist/chunk-JEL35P7S.js +53 -0
  64. package/dist/chunk-JGJ4INEN.js +32 -0
  65. package/dist/chunk-JS5RTH4I.js +84 -0
  66. package/dist/chunk-JWRZDYB5.js +59 -0
  67. package/dist/chunk-KMXRRSKT.js +660 -0
  68. package/dist/chunk-LBXO4VPG.js +73 -0
  69. package/dist/chunk-LLBPVZXM.js +67 -0
  70. package/dist/chunk-LLT5FQBE.js +57 -0
  71. package/dist/chunk-LMT3PPXJ.js +17 -0
  72. package/dist/chunk-LMUBBIE2.js +83 -0
  73. package/dist/chunk-LTZH5E3G.js +479 -0
  74. package/dist/chunk-LW4TG7EL.js +39 -0
  75. package/dist/chunk-MPSQXSC6.js +346 -0
  76. package/dist/chunk-MVFH26QT.js +97 -0
  77. package/dist/chunk-NLEXKE7U.js +67 -0
  78. package/dist/chunk-NQPURJT5.js +44 -0
  79. package/dist/chunk-NRBQK6UX.js +105 -0
  80. package/dist/chunk-OEH47H6A.js +48 -0
  81. package/dist/chunk-OG7QR2DP.js +75 -0
  82. package/dist/chunk-OPYFEHKG.js +52 -0
  83. package/dist/chunk-P4N7DBD5.js +83 -0
  84. package/dist/chunk-PAX3QXX2.js +140 -0
  85. package/dist/chunk-PKODFR5F.js +102 -0
  86. package/dist/chunk-PMJG2CXF.js +122 -0
  87. package/dist/chunk-Q5H3L6Y4.js +23 -0
  88. package/dist/chunk-QEF7EK3T.js +28 -0
  89. package/dist/chunk-QEW4J3IZ.js +74 -0
  90. package/dist/chunk-QPL7E2HW.js +464 -0
  91. package/dist/chunk-R2GPCZUX.js +22 -0
  92. package/dist/chunk-R5MT42JS.js +284 -0
  93. package/dist/chunk-RMATE45Z.js +197 -0
  94. package/dist/chunk-RPQOBHVU.js +87 -0
  95. package/dist/chunk-S3PIAMXV.js +230 -0
  96. package/dist/chunk-T3LKX23M.js +168 -0
  97. package/dist/chunk-T6GOWHK6.js +30 -0
  98. package/dist/chunk-TIA4SPU2.js +10 -0
  99. package/dist/chunk-TNCZ6444.js +57 -0
  100. package/dist/chunk-TVL5RTE6.js +269 -0
  101. package/dist/chunk-TXQ7L33K.js +45 -0
  102. package/dist/chunk-UPQTAHUK.js +189 -0
  103. package/dist/chunk-V4NPDK6X.js +14 -0
  104. package/dist/chunk-VJFEN6DJ.js +38 -0
  105. package/dist/chunk-VMHUEOT5.js +643 -0
  106. package/dist/chunk-VRPMYPZU.js +4985 -0
  107. package/dist/chunk-WIW772I3.js +25 -0
  108. package/dist/chunk-XELAZAIM.js +136 -0
  109. package/dist/chunk-XNML2KIC.js +23 -0
  110. package/dist/chunk-XP2U3LO3.js +30 -0
  111. package/dist/chunk-YGOWIJPE.js +51 -0
  112. package/dist/chunk-YIXDHQYE.js +11 -0
  113. package/dist/chunk-YSAWTGNA.js +117 -0
  114. package/dist/claude-U2JC2DNQ.js +77 -0
  115. package/dist/cli-MI4ZCAZ3.js +41 -0
  116. package/dist/cli-ZN7ZVDEZ.js +46 -0
  117. package/dist/cli.js +144 -16197
  118. package/dist/completion-ILSRB3LW.js +142 -0
  119. package/dist/config-DnpLL2kT.d.ts +46 -0
  120. package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
  121. package/dist/diagnostics-XKXVVQWH.js +93 -0
  122. package/dist/doctor-O2E63YGO.js +538 -0
  123. package/dist/entry-X6CSYQRQ.js +305 -0
  124. package/dist/exec-mcp-2PMWBPD7.js +365 -0
  125. package/dist/harness-L2KSI2ZB.js +177 -0
  126. package/dist/harness-egress-bridge.js +4 -4
  127. package/dist/harness-launch-gate.js +47 -940
  128. package/dist/harness-pane-runner.js +13 -80
  129. package/dist/harness-worker.js +21 -2703
  130. package/dist/hook-body.js +5222 -0
  131. package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
  132. package/dist/hook.js +26 -0
  133. package/dist/hooks-BHTA44X7.js +21 -0
  134. package/dist/host-UIZAXXQH.js +22 -0
  135. package/dist/host-UWK754BW.js +210 -0
  136. package/dist/host-run-BI2OTZDZ.js +307 -0
  137. package/dist/http.d.ts +5 -42
  138. package/dist/http.js +21 -2234
  139. package/dist/import-mcp-GPKJI7DI.js +400 -0
  140. package/dist/index.d.ts +146 -168
  141. package/dist/index.js +133 -4948
  142. package/dist/init-3C2Y7BNJ.js +14 -0
  143. package/dist/install-GG7HHZK2.js +796 -0
  144. package/dist/invoke-44CJRVMK.js +23 -0
  145. package/dist/list-MCP2FXUF.js +68 -0
  146. package/dist/list-WL6L4J5H.js +65 -0
  147. package/dist/load-BEUBABtB.d.ts +21 -0
  148. package/dist/logout-F5EJ5MOU.js +44 -0
  149. package/dist/logs-TBUA4UWU.js +107 -0
  150. package/dist/mailbox/index.d.ts +10 -5
  151. package/dist/mailbox/index.js +53 -1572
  152. package/dist/mailbox-BMTZOSZ7.js +285 -0
  153. package/dist/mailbox-GDJ7BWQN.js +189 -0
  154. package/dist/mainline-KAD2ERLP.js +639 -0
  155. package/dist/marketplace-G4VQET5W.js +191 -0
  156. package/dist/mcp-235QZN2A.js +15 -0
  157. package/dist/mcp-FJ2UQ4RH.js +193 -0
  158. package/dist/models-ISU4DCMA.js +32 -0
  159. package/dist/opencode-CN7JLQYO.js +60 -0
  160. package/dist/pause-7LILUVGL.js +18 -0
  161. package/dist/preview-DT7DWG5F.js +91 -0
  162. package/dist/project/hook-adapter.d.ts +5 -2
  163. package/dist/project/hook-adapter.js +41 -27
  164. package/dist/project-5YV5CUEG.js +70 -0
  165. package/dist/pty-XTJ4MIWK.js +94 -0
  166. package/dist/recovery-U6QB3PMT.js +100 -0
  167. package/dist/reindex-Y27QJFDB.js +22 -0
  168. package/dist/resume-26VFAAMH.js +18 -0
  169. package/dist/run-3AXTZSR7.js +126 -0
  170. package/dist/run-3SOVRQIA.js +19 -0
  171. package/dist/serve-DQMKTFIV.js +104 -0
  172. package/dist/session-XM2CR425.js +159 -0
  173. package/dist/setup-DTKZLZUT.js +18 -0
  174. package/dist/start-login-YTZV6KMF.js +416 -0
  175. package/dist/status-A2OUTNGK.js +9 -0
  176. package/dist/status-H2VAHIDV.js +10 -0
  177. package/dist/status-MROQ7WR7.js +43 -0
  178. package/dist/status-RO55QPKV.js +55 -0
  179. package/dist/status-UME2L33L.js +286 -0
  180. package/dist/stdio.d.ts +3 -13
  181. package/dist/stdio.js +16 -3186
  182. package/dist/sweep-35LGQTTO.js +18 -0
  183. package/dist/test-AGZOJLRZ.js +561 -0
  184. package/dist/tools-gpHNq9Dh.d.ts +328 -0
  185. package/dist/tui-G5LLWCSV.js +153 -0
  186. package/dist/unbroadcast-5QNGAJR2.js +18 -0
  187. package/dist/validate-IU52H2IC.js +46 -0
  188. package/dist/worker-QZ5T6LJD.js +80 -0
  189. package/dist/worktree-create-PZSRB7PH.js +89 -0
  190. package/dist/worktree-list-JYB6VXLW.js +51 -0
  191. package/dist/worktree-sync-UF5CXPWV.js +30 -0
  192. package/docs/authoring.md +82 -0
  193. package/docs/browser-and-desktop.md +46 -0
  194. package/docs/commands.md +325 -0
  195. package/docs/compare.md +35 -0
  196. package/docs/compatibility.md +55 -0
  197. package/docs/embeddings.md +1 -1
  198. package/docs/getting-started.md +105 -0
  199. package/docs/git-workflow.md +60 -0
  200. package/docs/glossary.md +31 -0
  201. package/docs/hooks/capabilities/antigravity.json +199 -0
  202. package/docs/hooks/capabilities/claude.json +179 -0
  203. package/docs/hooks/capabilities/codex.json +179 -0
  204. package/docs/hooks/capabilities/gemini.json +196 -0
  205. package/docs/hooks/capabilities/grok.json +192 -0
  206. package/docs/hooks/capabilities/opencode.json +184 -0
  207. package/docs/hooks.md +264 -0
  208. package/docs/install.md +72 -0
  209. package/docs/library-skills.md +132 -0
  210. package/docs/mailbox.md +16 -5
  211. package/docs/project-configuration.md +540 -58
  212. package/docs/sessions.md +64 -0
  213. package/docs/skills.md +4 -45
  214. package/docs/terminal-harness.md +92 -44
  215. package/docs/terminal-workspace.md +81 -169
  216. package/gemini-extension.json +2 -2
  217. package/mcp.json +1 -1
  218. package/package.json +16 -2
  219. package/plugin.json +2 -2
  220. package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
  221. package/plugins/pmcp/.mcp.json +1 -1
  222. package/plugins/pmcp/gemini-extension.json +2 -2
  223. package/plugins/pmcp/mcp.json +1 -1
  224. package/plugins/pmcp/mod/commands.ts +72 -0
  225. package/plugins/pmcp/mod/contract.d.ts +39 -0
  226. package/plugins/pmcp/mod/draw.tsx +216 -0
  227. package/plugins/pmcp/mod/guard.ts +42 -0
  228. package/plugins/pmcp/mod/hooks.json +4 -0
  229. package/plugins/pmcp/mod/host.ts +46 -0
  230. package/plugins/pmcp/mod/model.ts +144 -0
  231. package/plugins/pmcp/mod/reader/index.ts +18 -0
  232. package/plugins/pmcp/mod/reader/read.ts +76 -0
  233. package/plugins/pmcp/mod/reader/settings.ts +54 -0
  234. package/plugins/pmcp/mod/reader/types.ts +38 -0
  235. package/plugins/pmcp/mod/register.tsx +73 -0
  236. package/plugins/pmcp/mod/sessions/format.ts +91 -0
  237. package/plugins/pmcp/mod/sessions/types.ts +162 -0
  238. package/plugins/pmcp/mod/snapshot.ts +75 -0
  239. package/plugins/pmcp/mod/spinner.tsx +30 -0
  240. package/plugins/pmcp/mod/state.ts +28 -0
  241. package/plugins/pmcp/plugin.json +2 -2
  242. package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
  243. package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +101 -0
  244. package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
  245. package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -15
  246. package/plugins/pmcp/skills/pmcp-browser/SKILL.md +27 -0
  247. package/plugins/pmcp/skills/pmcp-desktop/SKILL.md +25 -0
  248. package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +153 -0
  249. package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +96 -0
  250. package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +89 -0
  251. package/schema/catalog-v1.json +187 -0
  252. package/schema/library.json +196 -0
  253. package/schema/marketplace-manifest.json +144 -0
  254. package/schema/plugin-manifest.json +59 -0
  255. package/schema/skill-frontmatter.json +170 -0
  256. package/schema/skill-metadata-core.json +131 -0
  257. package/skills/agent-assets-migrate/SKILL.md +96 -0
  258. package/skills/headless-agents-ci-scaffold/SKILL.md +101 -0
  259. package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
  260. package/skills/package-skill-catalog/SKILL.md +51 -15
  261. package/skills/pmcp-browser/SKILL.md +27 -0
  262. package/skills/pmcp-desktop/SKILL.md +25 -0
  263. package/skills/pmcp-project-init/SKILL.md +153 -0
  264. package/skills/pmcp-sessions-and-git/SKILL.md +96 -0
  265. package/skills/skill-package-scaffold/SKILL.md +89 -0
  266. package/dist/config-BkSpjUG6.d.ts +0 -50
  267. package/dist/embed-DRROSD3F.d.ts +0 -53
  268. package/dist/hook-spec-CSJJySsH.d.ts +0 -11
  269. package/dist/server-VWSY3Shw.d.ts +0 -543
  270. package/dist/tui-worker.js +0 -6549
  271. package/docs/manual-library-skills.md +0 -74
  272. /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
@@ -0,0 +1,78 @@
1
+ import {
2
+ installIfStale,
3
+ movableSubmodules,
4
+ updateToPins
5
+ } from "./chunk-XELAZAIM.js";
6
+ import {
7
+ cherry,
8
+ distance
9
+ } from "./chunk-QEW4J3IZ.js";
10
+ import {
11
+ git,
12
+ gitText
13
+ } from "./chunk-OPYFEHKG.js";
14
+
15
+ // src/git/worktrees/sync.ts
16
+ function heldBy(root, upstream, ahead) {
17
+ const dirty = gitText(root, [
18
+ "status",
19
+ "--porcelain",
20
+ "--untracked-files=no",
21
+ "--ignore-submodules=all"
22
+ ]);
23
+ if (dirty) return "uncommitted changes";
24
+ if (ahead === 0) return null;
25
+ const own = cherry(root, upstream).missing.length;
26
+ if (own > 0) return `${own} unlanded commit(s)`;
27
+ return null;
28
+ }
29
+ function syncWorktree(options) {
30
+ const { ctx, report } = options;
31
+ if (!ctx.linked)
32
+ throw new Error(
33
+ "worktree sync moves a linked worktree; the main checkout uses pmcp git sync"
34
+ );
35
+ if (options.fetch !== false && git(ctx.root, ["fetch", "-q", ctx.remote, ctx.mainline]).status !== 0)
36
+ report.warn(
37
+ `fetch from ${ctx.remote} failed; judging against the last fetched ${ctx.upstream}`
38
+ );
39
+ const counted = distance(ctx.root, ctx.upstream);
40
+ if (counted === null)
41
+ throw new Error(`cannot compare HEAD with ${ctx.upstream}`);
42
+ if (counted.behind === 0) {
43
+ report.info(`already on ${ctx.upstream}`);
44
+ if (options.install !== void 0)
45
+ installIfStale(ctx.root, options.install, report);
46
+ return "current";
47
+ }
48
+ const holds = heldBy(ctx.root, ctx.upstream, counted.ahead);
49
+ if (holds !== null) {
50
+ report.warn(
51
+ `${counted.behind} commit(s) behind ${ctx.upstream} and holds ${holds}; left where it is`
52
+ );
53
+ return "held";
54
+ }
55
+ const submodules = options.followSubmodules ? movableSubmodules(ctx.root) : [];
56
+ const before = gitText(ctx.root, ["rev-parse", "HEAD"]);
57
+ const args = counted.ahead > 0 ? ["reset", "--keep", "-q", ctx.upstream] : ["merge", "--ff-only", "-q", ctx.upstream];
58
+ const moved = git(ctx.root, args);
59
+ if (moved.status !== 0) {
60
+ report.warn(
61
+ `could not move to ${ctx.upstream}: ${moved.stderr.trim().split("\n")[0] ?? ""}`
62
+ );
63
+ return "held";
64
+ }
65
+ const after = gitText(ctx.root, ["rev-parse", "HEAD"]);
66
+ report.info(
67
+ `moved ${before.slice(0, 10)} -> ${after.slice(0, 10)}, ${counted.behind} commit(s)`
68
+ );
69
+ for (const line of updateToPins(ctx.root, submodules)) report.info(line);
70
+ if (options.install !== void 0)
71
+ installIfStale(ctx.root, options.install, report);
72
+ return "moved";
73
+ }
74
+
75
+ export {
76
+ syncWorktree
77
+ };
78
+ //# sourceMappingURL=chunk-DCU2EXQV.js.map
@@ -0,0 +1,104 @@
1
+ import {
2
+ nativeBinary,
3
+ readLock
4
+ } from "./chunk-7HFIGCSL.js";
5
+
6
+ // src/project/host.ts
7
+ import { createHash } from "crypto";
8
+ import { existsSync, readFileSync } from "fs";
9
+ import { join } from "path";
10
+ var HOST_DIRECTORY = ".agents/pmcp-pty";
11
+ var HOST_MANIFEST = `${HOST_DIRECTORY}/host.json`;
12
+ var HOST_POLICY = `${HOST_DIRECTORY}/policy.json`;
13
+ function hostPolicy(host) {
14
+ const browser = host.browser.allowPrivate;
15
+ const launch = host.desktop.launch;
16
+ return {
17
+ version: 1,
18
+ mcp_write: host.mcpWrite,
19
+ roots: host.roots,
20
+ allow: host.answers.map((a) => ({
21
+ profile: a.runtime,
22
+ dialog: a.dialog,
23
+ options: a.options
24
+ })),
25
+ ...browser.length > 0 ? { browser: { allow_private: browser } } : {},
26
+ ...launch.length > 0 ? { desktop: { launch } } : {}
27
+ };
28
+ }
29
+ function hostManifest(host) {
30
+ return {
31
+ version: 1,
32
+ sessions: host.sessions.map((s) => ({
33
+ name: s.name,
34
+ profile: s.runtime,
35
+ cwd: s.cwd,
36
+ argv: s.argv,
37
+ labels: { ...s.labels, "pmcp.host": s.name },
38
+ restart: s.restart,
39
+ max_restarts: s.maxRestarts,
40
+ delivery_setup: true
41
+ }))
42
+ };
43
+ }
44
+ var json = (value) => `${JSON.stringify(value, null, 2)}
45
+ `;
46
+ function hostOutputs(spec) {
47
+ if (!spec.host) return [];
48
+ return [
49
+ {
50
+ kind: "file",
51
+ path: HOST_MANIFEST,
52
+ content: json(hostManifest(spec.host))
53
+ },
54
+ { kind: "file", path: HOST_POLICY, content: json(hostPolicy(spec.host)) }
55
+ ];
56
+ }
57
+ function ptyBinary(env) {
58
+ return nativeBinary("pmcp-pty", "PMCP_PTY_BIN", env);
59
+ }
60
+ function ptyBinaryDoctor(env) {
61
+ const found = ptyBinary(env);
62
+ return found ? { tool: "project", check: "pmcp-pty binary", status: "ok", detail: found } : {
63
+ tool: "project",
64
+ check: "pmcp-pty binary",
65
+ status: "warn",
66
+ detail: "pmcp-pty not found; set PMCP_PTY_BIN or put it on PATH"
67
+ };
68
+ }
69
+ var sha256 = (text) => createHash("sha256").update(text).digest("hex");
70
+ function hostDoctor(spec) {
71
+ if (!spec.host) return [];
72
+ const lock = new Map(readLock(spec.root).map((e) => [e.path, e]));
73
+ const bad = [HOST_MANIFEST, HOST_POLICY].filter((path) => {
74
+ const file = join(spec.root, path);
75
+ if (!existsSync(file)) return true;
76
+ const entry = lock.get(path);
77
+ return entry?.sha256 !== sha256(readFileSync(file, "utf8"));
78
+ });
79
+ const { sessions, answers, mcpWrite } = spec.host;
80
+ const summary = `${sessions.length} session(s), ${answers.length} answer rule(s), mcp_write ${mcpWrite}`;
81
+ return [
82
+ bad.length === 0 ? {
83
+ tool: "project",
84
+ check: "pmcp-pty host projected",
85
+ status: "ok",
86
+ detail: summary
87
+ } : {
88
+ tool: "project",
89
+ check: "pmcp-pty host projected",
90
+ status: "fail",
91
+ detail: `run pmcp project: ${bad.join(", ")}`
92
+ }
93
+ ];
94
+ }
95
+
96
+ export {
97
+ HOST_MANIFEST,
98
+ HOST_POLICY,
99
+ hostOutputs,
100
+ ptyBinary,
101
+ ptyBinaryDoctor,
102
+ hostDoctor
103
+ };
104
+ //# sourceMappingURL=chunk-DMZHQZ7P.js.map
@@ -0,0 +1,135 @@
1
+ // src/locks/file-lock.ts
2
+ import { spawnSync } from "child_process";
3
+ import {
4
+ closeSync,
5
+ constants,
6
+ openSync,
7
+ readFileSync,
8
+ renameSync,
9
+ unlinkSync,
10
+ writeSync
11
+ } from "fs";
12
+ var flockSeen;
13
+ function flockAvailable() {
14
+ flockSeen ??= spawnSync("flock", ["--version"], { stdio: "ignore" }).status === 0;
15
+ return flockSeen;
16
+ }
17
+ function processStart(pid) {
18
+ if (process.platform === "linux") {
19
+ try {
20
+ const text = readFileSync(`/proc/${pid}/stat`, "utf8");
21
+ return text.slice(text.lastIndexOf(")") + 2).split(" ")[19] ?? null;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+ const run = spawnSync("ps", ["-o", "lstart=", "-p", String(pid)], {
27
+ encoding: "utf8"
28
+ });
29
+ const start = run.status === 0 ? run.stdout.trim() : "";
30
+ return start || null;
31
+ }
32
+ function alive(pid) {
33
+ try {
34
+ process.kill(pid, 0);
35
+ return true;
36
+ } catch (error) {
37
+ return error.code === "EPERM";
38
+ }
39
+ }
40
+ function owner(path) {
41
+ try {
42
+ const value = JSON.parse(readFileSync(path, "utf8"));
43
+ return Number.isInteger(value.pid) ? value : null;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+ function stale(found) {
49
+ if (!found) return true;
50
+ return !alive(found.pid) || processStart(found.pid) !== found.start;
51
+ }
52
+ function tryCreate(path, me) {
53
+ let fd;
54
+ try {
55
+ fd = openSync(
56
+ path,
57
+ constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY,
58
+ 384
59
+ );
60
+ } catch (error) {
61
+ if (error.code === "EEXIST") return false;
62
+ throw error;
63
+ }
64
+ try {
65
+ writeSync(fd, `${JSON.stringify(me)}
66
+ `);
67
+ } finally {
68
+ closeSync(fd);
69
+ }
70
+ return true;
71
+ }
72
+ function takeOver(path, me) {
73
+ if (tryCreate(path, me)) return true;
74
+ if (!stale(owner(path))) return false;
75
+ const aside = `${path}.stale-${process.pid}-${Date.now()}`;
76
+ try {
77
+ renameSync(path, aside);
78
+ unlinkSync(aside);
79
+ } catch {
80
+ return false;
81
+ }
82
+ return tryCreate(path, me);
83
+ }
84
+ function sleep(ms) {
85
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
86
+ }
87
+ function lockFile(path, waitMs) {
88
+ const me = { pid: process.pid, start: processStart(process.pid) ?? "" };
89
+ const end = Date.now() + waitMs;
90
+ while (!takeOver(path, me)) {
91
+ if (Date.now() >= end) return null;
92
+ sleep(100);
93
+ }
94
+ let held = true;
95
+ return {
96
+ release: () => {
97
+ if (!held) return;
98
+ held = false;
99
+ if (owner(path)?.pid === process.pid) unlinkSync(path);
100
+ }
101
+ };
102
+ }
103
+ async function lockFileAsync(path, waitMs) {
104
+ const end = Date.now() + waitMs;
105
+ for (; ; ) {
106
+ const lock = lockFile(path, 0);
107
+ if (lock || Date.now() >= end) return lock;
108
+ await new Promise((resolve) => setTimeout(resolve, 100));
109
+ }
110
+ }
111
+ function runLocked(lock, waitSeconds, argv, options) {
112
+ if (flockAvailable()) {
113
+ const wait = waitSeconds > 0 ? ["--wait", String(waitSeconds)] : ["--nonblock"];
114
+ const flags = [...wait, "--close", "--conflict-exit-code", "73", lock];
115
+ return spawnSync("flock", [...flags, ...argv], options);
116
+ }
117
+ const held = lockFile(lock, waitSeconds * 1e3);
118
+ if (!held) {
119
+ const busy = { status: 73, stdout: "", stderr: "", output: [] };
120
+ return { ...busy, pid: 0, signal: null };
121
+ }
122
+ try {
123
+ return spawnSync(argv[0], argv.slice(1), options);
124
+ } finally {
125
+ held.release();
126
+ }
127
+ }
128
+
129
+ export {
130
+ flockAvailable,
131
+ lockFile,
132
+ lockFileAsync,
133
+ runLocked
134
+ };
135
+ //# sourceMappingURL=chunk-DZ2MRTYT.js.map
@@ -0,0 +1,207 @@
1
+ import {
2
+ flockAvailable,
3
+ lockFileAsync
4
+ } from "./chunk-DZ2MRTYT.js";
5
+ import {
6
+ boundSession,
7
+ clearCredentials,
8
+ credentialPath,
9
+ privateDirectory,
10
+ readCredentials,
11
+ request,
12
+ responseObject,
13
+ writeCredentials
14
+ } from "./chunk-UPQTAHUK.js";
15
+ import {
16
+ McpAuthError,
17
+ safeEndpoint
18
+ } from "./chunk-Q5H3L6Y4.js";
19
+
20
+ // src/mcp-auth/store/lock.ts
21
+ import { spawn } from "child_process";
22
+ import { closeSync, constants, openSync } from "fs";
23
+ async function withCredentialLock(name, env, action) {
24
+ privateDirectory(env);
25
+ const path = `${credentialPath(name, env)}.lock`;
26
+ const fd = openSync(
27
+ path,
28
+ constants.O_CREAT | constants.O_RDWR | constants.O_NOFOLLOW,
29
+ 384
30
+ );
31
+ closeSync(fd);
32
+ if (!flockAvailable()) {
33
+ const held = await lockFileAsync(path, 3e4);
34
+ if (!held) throw new McpAuthError("MCP credential lock timed out");
35
+ try {
36
+ return await action();
37
+ } finally {
38
+ held.release();
39
+ }
40
+ }
41
+ const holder = spawn(
42
+ "flock",
43
+ [
44
+ "--exclusive",
45
+ "--timeout",
46
+ "30",
47
+ path,
48
+ process.execPath,
49
+ "-e",
50
+ 'process.stdout.write("locked\\n");\nprocess.stdin.resume();'
51
+ ],
52
+ { stdio: ["pipe", "pipe", "ignore"] }
53
+ );
54
+ const exited = new Promise(
55
+ (resolve) => holder.once("close", () => resolve())
56
+ );
57
+ try {
58
+ await new Promise((resolve, reject) => {
59
+ holder.once(
60
+ "error",
61
+ () => reject(
62
+ new McpAuthError(
63
+ "Cannot acquire MCP credential lock; flock is required"
64
+ )
65
+ )
66
+ );
67
+ holder.once(
68
+ "exit",
69
+ () => reject(new McpAuthError("MCP credential lock timed out"))
70
+ );
71
+ holder.stdout.once("data", () => resolve());
72
+ });
73
+ return await action();
74
+ } finally {
75
+ holder.stdin.end();
76
+ await exited;
77
+ }
78
+ }
79
+
80
+ // src/mcp-auth/oauth/tokens.ts
81
+ async function tokenRequest(oauth, serverUrl, grant, previous) {
82
+ if (safeEndpoint(oauth.tokenEndpoint).origin !== safeEndpoint(oauth.issuer).origin)
83
+ throw new McpAuthError("OAuth token endpoint does not match the issuer");
84
+ const form = new URLSearchParams({
85
+ ...grant,
86
+ client_id: oauth.clientId,
87
+ resource: serverUrl
88
+ });
89
+ if (oauth.clientSecret) form.set("client_secret", oauth.clientSecret);
90
+ const response = await request(oauth.tokenEndpoint, {
91
+ method: "POST",
92
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
93
+ body: form.toString()
94
+ });
95
+ if (!response.ok) {
96
+ await response.body?.cancel();
97
+ throw new McpAuthError(
98
+ "MCP authentication failed or was revoked; run pmcp mcp login again"
99
+ );
100
+ }
101
+ const body = await responseObject(response);
102
+ if (typeof body.access_token !== "string" || !body.access_token || body.token_type !== void 0 && String(body.token_type).toLowerCase() !== "bearer")
103
+ throw new McpAuthError(
104
+ "OAuth response is missing a supported access token"
105
+ );
106
+ const lifetime = body.expires_in === void 0 ? void 0 : Number(body.expires_in);
107
+ if (lifetime !== void 0 && (!Number.isFinite(lifetime) || lifetime < 0))
108
+ throw new McpAuthError("OAuth response has an invalid expiry");
109
+ const scopes = typeof body.scope === "string" ? body.scope.split(/\s+/u).filter(Boolean) : previous?.scopes ?? [];
110
+ return {
111
+ serverUrl,
112
+ kind: "oauth",
113
+ oauth,
114
+ accessToken: body.access_token,
115
+ refreshToken: typeof body.refresh_token === "string" ? body.refresh_token : previous?.refreshToken,
116
+ expiresAt: lifetime === void 0 ? void 0 : Date.now() + lifetime * 1e3,
117
+ scopes
118
+ };
119
+ }
120
+ async function revokeSession(session) {
121
+ const oauth = session.oauth;
122
+ if (!oauth?.revocationEndpoint) return;
123
+ if (safeEndpoint(oauth.revocationEndpoint).origin !== safeEndpoint(oauth.issuer).origin)
124
+ throw new McpAuthError(
125
+ "OAuth revocation endpoint does not match the issuer"
126
+ );
127
+ for (const token of [session.refreshToken, session.accessToken]) {
128
+ if (!token) continue;
129
+ const form = new URLSearchParams({ token, client_id: oauth.clientId });
130
+ if (oauth.clientSecret) form.set("client_secret", oauth.clientSecret);
131
+ const response = await request(oauth.revocationEndpoint, {
132
+ method: "POST",
133
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
134
+ body: form.toString()
135
+ });
136
+ await response.body?.cancel();
137
+ if (!response.ok)
138
+ throw new McpAuthError(
139
+ "Remote OAuth revocation failed; local credentials were cleared"
140
+ );
141
+ }
142
+ }
143
+
144
+ // src/mcp-auth/session.ts
145
+ async function accessToken(name, serverUrl, env = process.env, rejected) {
146
+ const current = boundSession(name, serverUrl, env);
147
+ if (!current) return void 0;
148
+ const usable = (session) => session.accessToken !== rejected && (session.expiresAt === void 0 || session.expiresAt > Date.now() + 3e4);
149
+ if (usable(current)) return current.accessToken;
150
+ return withCredentialLock(name, env, async () => {
151
+ const session = boundSession(name, serverUrl, env);
152
+ if (!session)
153
+ throw new McpAuthError(
154
+ "MCP credentials were removed; run pmcp mcp login again"
155
+ );
156
+ if (usable(session)) return session.accessToken;
157
+ if (!session.refreshToken || !session.oauth)
158
+ throw new McpAuthError(
159
+ "MCP authentication expired or was revoked; run pmcp mcp login again"
160
+ );
161
+ const refreshed = await tokenRequest(
162
+ session.oauth,
163
+ serverUrl,
164
+ { grant_type: "refresh_token", refresh_token: session.refreshToken },
165
+ session
166
+ );
167
+ writeCredentials(
168
+ name,
169
+ { ...readCredentials(name, env), session: refreshed },
170
+ env
171
+ );
172
+ return refreshed.accessToken;
173
+ });
174
+ }
175
+ async function storeBearer(name, serverUrl, token, env = process.env) {
176
+ if (!token || /[\r\n]/u.test(token))
177
+ throw new McpAuthError(
178
+ "The bearer token environment variable is missing or invalid"
179
+ );
180
+ await withCredentialLock(
181
+ name,
182
+ env,
183
+ async () => writeCredentials(
184
+ name,
185
+ {
186
+ session: { serverUrl, kind: "bearer", accessToken: token, scopes: [] }
187
+ },
188
+ env
189
+ )
190
+ );
191
+ }
192
+ async function logout(name, serverUrl, env = process.env) {
193
+ await withCredentialLock(name, env, async () => {
194
+ const session = boundSession(name, serverUrl, env);
195
+ clearCredentials(name, env);
196
+ if (session) await revokeSession(session);
197
+ });
198
+ }
199
+
200
+ export {
201
+ withCredentialLock,
202
+ tokenRequest,
203
+ accessToken,
204
+ storeBearer,
205
+ logout
206
+ };
207
+ //# sourceMappingURL=chunk-E2YOZ2FF.js.map
@@ -0,0 +1,48 @@
1
+ import {
2
+ jsonOption
3
+ } from "./chunk-XNML2KIC.js";
4
+
5
+ // src/commands/specs/mcp.ts
6
+ var mcpSpec = {
7
+ name: "mcp",
8
+ describe: "Manage the project's shared remote MCP authentication",
9
+ usage: "pmcp mcp <login|logout|status> <name> [--config <file>]",
10
+ options: [
11
+ jsonOption,
12
+ {
13
+ name: "config",
14
+ describe: "Read this project configuration.",
15
+ placeholder: "<file>"
16
+ },
17
+ {
18
+ name: "code",
19
+ describe: "Complete a pending login with a callback URL or authorization code.",
20
+ placeholder: "<callback-or-code>"
21
+ },
22
+ {
23
+ name: "no-wait",
24
+ describe: "Print the authorization URL and save a pending login for later completion.",
25
+ boolean: true
26
+ },
27
+ {
28
+ name: "port",
29
+ describe: "Loopback callback port; zero chooses an available port.",
30
+ placeholder: "<port>"
31
+ },
32
+ {
33
+ name: "client-id",
34
+ describe: "Use a pre-registered OAuth client identifier.",
35
+ placeholder: "<id>"
36
+ },
37
+ {
38
+ name: "bearer-env",
39
+ describe: "Store a bearer session from this environment variable without printing it.",
40
+ placeholder: "<name>"
41
+ }
42
+ ]
43
+ };
44
+
45
+ export {
46
+ mcpSpec
47
+ };
48
+ //# sourceMappingURL=chunk-E3DQB5LS.js.map
@@ -0,0 +1,66 @@
1
+ // src/sessions/projector-cli.ts
2
+ import { existsSync, readFileSync, realpathSync } from "fs";
3
+ import { delimiter, join } from "path";
4
+ var PROJECTOR_FILE = "projector.json";
5
+ function readJson(path) {
6
+ try {
7
+ return JSON.parse(readFileSync(path, "utf8"));
8
+ } catch {
9
+ return null;
10
+ }
11
+ }
12
+ function localCli(root) {
13
+ const own = join(root, "node_modules/@modootoday/pmcp/dist/cli.js");
14
+ if (existsSync(own)) return own;
15
+ try {
16
+ const target = realpathSync(join(root, "node_modules/.bin/pmcp"));
17
+ return /\.[cm]?js$/u.test(target) ? target : null;
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+ function recordedCli(root, stateDir) {
23
+ const known = readJson(join(stateDir, PROJECTOR_FILE));
24
+ let checkout;
25
+ try {
26
+ checkout = realpathSync(root);
27
+ } catch {
28
+ return null;
29
+ }
30
+ const entry = known?.[checkout];
31
+ return typeof entry?.cli === "string" ? entry.cli : null;
32
+ }
33
+ function projectingCli(root, stateDir) {
34
+ const cli = localCli(root) ?? recordedCli(root, stateDir);
35
+ return cli && existsSync(cli) ? cli : null;
36
+ }
37
+ function pathPmcp(path) {
38
+ for (const dir of (path ?? "").split(delimiter).filter(Boolean)) {
39
+ try {
40
+ return realpathSync(join(dir, "pmcp"));
41
+ } catch {
42
+ continue;
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+ var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
48
+ function pmcpCommand(root, stateDir, path) {
49
+ const cli = projectingCli(root, stateDir);
50
+ if (!cli) return "pmcp";
51
+ let real = cli;
52
+ try {
53
+ real = realpathSync(cli);
54
+ } catch {
55
+ return "pmcp";
56
+ }
57
+ return pathPmcp(path) === real ? "pmcp" : `node ${quote(real)}`;
58
+ }
59
+
60
+ export {
61
+ localCli,
62
+ recordedCli,
63
+ pathPmcp,
64
+ pmcpCommand
65
+ };
66
+ //# sourceMappingURL=chunk-EATCUWGG.js.map