@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,778 @@
1
+ import {
2
+ command
3
+ } from "./chunk-34DECPVC.js";
4
+ import {
5
+ ptyBinary
6
+ } from "./chunk-DMZHQZ7P.js";
7
+ import {
8
+ GroupStore,
9
+ egressPolicy,
10
+ privateJson,
11
+ profileName,
12
+ readPrivateJson,
13
+ selectedProfile
14
+ } from "./chunk-TVL5RTE6.js";
15
+ import {
16
+ integer,
17
+ object,
18
+ strings,
19
+ text
20
+ } from "./chunk-5OMOPUE6.js";
21
+
22
+ // src/harness/adapters/docker/claims.ts
23
+ import { createHash } from "crypto";
24
+
25
+ // src/harness/adapters/docker/identity.ts
26
+ var containerLabels = {
27
+ owner: "pmcp.harness.owner",
28
+ nonce: "pmcp.harness.nonce",
29
+ role: "pmcp.harness.role"
30
+ };
31
+ function containerName(owner, sessionId) {
32
+ return `pmcp-harness-${owner.slice(0, 8)}-${sessionId}`;
33
+ }
34
+
35
+ // src/harness/adapters/docker/claims.ts
36
+ function resourceClaim(value, owner) {
37
+ const record = object(value);
38
+ if (record.kind !== "docker" || record.owner !== owner)
39
+ throw new Error("foreign_container_resource");
40
+ if (!/^[a-f0-9]{64}$/.test(text(record.id, "container_id")))
41
+ throw new Error("invalid_container_id");
42
+ if (!/^sha256:[a-f0-9]{64}$/.test(text(record.image, "container_image")))
43
+ throw new Error("invalid_container_image");
44
+ if (!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(
45
+ text(record.nonce, "container_nonce")
46
+ ))
47
+ throw new Error("invalid_container_nonce");
48
+ if (record.role !== "main" && record.role !== "worker")
49
+ throw new Error("invalid_container_role");
50
+ if (!/^[a-f0-9]{64}$/.test(
51
+ text(record.configurationDigest, "container_configuration")
52
+ ))
53
+ throw new Error("invalid_container_configuration");
54
+ integer(record.memoryMb, "container_memory", 32, 1472);
55
+ integer(record.cpuQuota, "container_cpu", 1, 5e4);
56
+ if (record.managed !== void 0 && record.managed !== true)
57
+ throw new Error("invalid_container_custody");
58
+ if (record.privateProfile !== void 0) {
59
+ profileName(record.privateProfile);
60
+ if (record.managed !== true)
61
+ throw new Error("private_profile_requires_cli_owned_creation");
62
+ }
63
+ return record;
64
+ }
65
+ function assertResourceOwner(resource, actual) {
66
+ const config = object(actual.Config);
67
+ const labels2 = object(config.Labels);
68
+ if (actual.Id !== resource.id || actual.Image !== resource.image || labels2[containerLabels.owner] !== resource.owner || labels2[containerLabels.nonce] !== resource.nonce || labels2[containerLabels.role] !== resource.role)
69
+ throw new Error("foreign_container_identity");
70
+ }
71
+ function configurationDigest(actual) {
72
+ const host = object(actual.HostConfig);
73
+ if (host.OomKillDisable !== false && host.OomKillDisable !== null)
74
+ throw new Error("container_oom_protection_disabled");
75
+ if (!Array.isArray(actual.Mounts))
76
+ throw new Error("invalid_container_mounts");
77
+ const mounts = actual.Mounts.map(object).sort(
78
+ (left, right) => text(left.Destination, "mount_destination").localeCompare(
79
+ text(right.Destination, "mount_destination")
80
+ )
81
+ );
82
+ return createHash("sha256").update(
83
+ JSON.stringify(
84
+ canonicalValue({
85
+ config: actual.Config,
86
+ host: { ...host, OomKillDisable: false },
87
+ mounts
88
+ })
89
+ )
90
+ ).digest("hex");
91
+ }
92
+ function canonicalValue(value) {
93
+ if (Array.isArray(value)) return value.map(canonicalValue);
94
+ if (value === null || typeof value !== "object") return value;
95
+ return Object.fromEntries(
96
+ Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => [key, canonicalValue(entry)])
97
+ );
98
+ }
99
+
100
+ // src/harness/adapters/docker/observation.ts
101
+ function inspectResource(resource, enforceConfiguration = true) {
102
+ const result = JSON.parse(command("docker", ["inspect", resource.id]));
103
+ if (!Array.isArray(result) || result.length !== 1)
104
+ throw new Error("invalid_container_inspection");
105
+ const actual = object(result[0]);
106
+ assertResourceOwner(resource, actual);
107
+ if (enforceConfiguration && configurationDigest(actual) !== resource.configurationDigest)
108
+ throw new Error("container_configuration_changed");
109
+ return actual;
110
+ }
111
+ function resourceAbsent(error, id) {
112
+ const failure = error;
113
+ const message = String(failure.stderr).toLowerCase();
114
+ return ["object", "container"].some(
115
+ (kind) => message.includes(`no such ${kind}: ${id}`)
116
+ );
117
+ }
118
+ function assertResourceFresh(resource) {
119
+ const state = object(inspectResource(resource).State);
120
+ if (state.Status !== "created" || state.Running !== false || state.Pid !== 0)
121
+ throw new Error("container_requires_fresh_creation");
122
+ }
123
+ function resourceRunning(resource) {
124
+ let actual;
125
+ try {
126
+ actual = inspectResource(resource);
127
+ } catch (error) {
128
+ if (resourceAbsent(error, resource.id)) return false;
129
+ throw error;
130
+ }
131
+ const state = object(actual.State);
132
+ if (typeof state.Running !== "boolean")
133
+ throw new Error("unknown_container_lifecycle");
134
+ return state.Running;
135
+ }
136
+
137
+ // src/harness/adapters/terminal/connection.ts
138
+ import { execFileSync, spawn, spawnSync } from "child_process";
139
+ import { closeSync, existsSync, openSync, readFileSync } from "fs";
140
+ import { join } from "path";
141
+ var Connection = class {
142
+ constructor(records) {
143
+ this.records = records;
144
+ }
145
+ records;
146
+ binary() {
147
+ const found = ptyBinary(process.env);
148
+ if (!found)
149
+ throw new Error(
150
+ "terminal_host_missing: set PMCP_PTY_BIN or put pmcp-pty on PATH"
151
+ );
152
+ return found;
153
+ }
154
+ call(request, timeoutMs = 1e4) {
155
+ let out;
156
+ try {
157
+ out = execFileSync(
158
+ this.binary(),
159
+ ["call", "--socket", this.records.socket, JSON.stringify(request)],
160
+ {
161
+ encoding: "utf8",
162
+ timeout: timeoutMs,
163
+ maxBuffer: 1024 * 1024,
164
+ stdio: ["ignore", "pipe", "pipe"]
165
+ }
166
+ );
167
+ } catch (error) {
168
+ throw new Error("terminal_host_unavailable", { cause: error });
169
+ }
170
+ return JSON.parse(out);
171
+ }
172
+ // A call that must succeed; pmcp-pty's code becomes the error, prefixed for the receipt.
173
+ must(request, timeoutMs) {
174
+ const reply = this.call(request, timeoutMs);
175
+ if (reply["ok"] !== true)
176
+ throw new Error(`terminal_${String(reply["code"] ?? "refused")}`);
177
+ return reply;
178
+ }
179
+ alive() {
180
+ if (!existsSync(this.records.socket)) return false;
181
+ try {
182
+ return this.call({ op: "list" }, 3e3)["ok"] === true;
183
+ } catch {
184
+ return false;
185
+ }
186
+ }
187
+ instance() {
188
+ return String(this.must({ op: "list" })["instance"]);
189
+ }
190
+ // Starts the group's daemon when none answers. Its output goes to pmcp-pty.log beside the
191
+ // socket, so a failed start can say why.
192
+ ensure() {
193
+ if (this.alive()) return this.instance();
194
+ const log = join(this.records.directory, "pmcp-pty.log");
195
+ const fd = openSync(log, "a", 384);
196
+ try {
197
+ spawn(this.binary(), ["daemon", "--socket", this.records.socket], {
198
+ detached: true,
199
+ stdio: ["ignore", fd, fd]
200
+ }).unref();
201
+ } finally {
202
+ closeSync(fd);
203
+ }
204
+ for (let waited = 0; waited < 5e3; waited += 100) {
205
+ if (this.alive()) return this.instance();
206
+ spawnSync("sleep", ["0.1"]);
207
+ }
208
+ const tail = existsSync(log) ? readFileSync(log, "utf8").slice(-400) : "";
209
+ throw new Error(
210
+ `terminal_host_start_failed${tail ? `: ${tail.trim()}` : ""}`
211
+ );
212
+ }
213
+ inspect(id) {
214
+ const record = this.records.read(id);
215
+ const seen = this.must({ op: "observe", id: record.ptySession, lines: 0 });
216
+ if (seen["instance"] !== record.ptyInstance)
217
+ throw new Error("stale_server");
218
+ if (Number(seen["pid"]) !== record.pid) throw new Error("stale_pane");
219
+ const labels2 = seen["labels"] ?? {};
220
+ if (labels2["pmcp.owner"] !== this.records.owner || labels2["pmcp.session"] !== id)
221
+ throw new Error("foreign_pane");
222
+ const size = seen["size"] ?? {};
223
+ return {
224
+ ...record,
225
+ alive: seen["alive"] === true && (!record.resource || resourceRunning(record.resource)),
226
+ width: Number(size.cols ?? 0),
227
+ height: Number(size.rows ?? 0)
228
+ };
229
+ }
230
+ // The identity every input carries, so pmcp-pty refuses a restarted daemon or a reused id.
231
+ expect(record, lease) {
232
+ return {
233
+ instance: record.ptyInstance,
234
+ pid: record.pid,
235
+ ...lease ? { lease } : {}
236
+ };
237
+ }
238
+ };
239
+
240
+ // src/harness/adapters/terminal/records.ts
241
+ import { randomUUID } from "crypto";
242
+ import { lstatSync, mkdirSync, readdirSync, realpathSync } from "fs";
243
+ import { homedir } from "os";
244
+ import { join as join2 } from "path";
245
+ function stateDirectory() {
246
+ return join2(
247
+ process.env.XDG_STATE_HOME ?? join2(homedir(), ".local/state"),
248
+ "pmcp/harness"
249
+ );
250
+ }
251
+ function runtimeUnit(id) {
252
+ if (!/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(id))
253
+ throw new Error("invalid_session_id");
254
+ return `pmcp-${id}.scope`;
255
+ }
256
+ function budgetSlice(owner) {
257
+ runtimeUnit(owner);
258
+ return `pmcp${owner.replaceAll("-", "")}.slice`;
259
+ }
260
+ var RecordStore = class _RecordStore {
261
+ directory;
262
+ socket;
263
+ metadataPath;
264
+ owner;
265
+ constructor(directory) {
266
+ const stat = lstatSync(directory);
267
+ if (!stat.isDirectory() || stat.uid !== process.getuid?.() || (stat.mode & 63) !== 0)
268
+ throw new Error("unsafe_group_directory");
269
+ this.directory = realpathSync(directory);
270
+ this.socket = join2(this.directory, "s");
271
+ if (Buffer.byteLength(this.socket) > 100)
272
+ throw new Error("socket_path_too_long");
273
+ this.metadataPath = join2(this.directory, "harness.json");
274
+ this.owner = text(
275
+ object(readPrivateJson(this.metadataPath)).owner,
276
+ "owner"
277
+ );
278
+ runtimeUnit(this.owner);
279
+ }
280
+ static create() {
281
+ const root = stateDirectory();
282
+ mkdirSync(root, { recursive: true, mode: 448 });
283
+ const directory = join2(root, randomUUID().slice(0, 16));
284
+ if (Buffer.byteLength(join2(directory, "s")) > 100)
285
+ throw new Error("socket_path_too_long");
286
+ mkdirSync(directory, { mode: 448 });
287
+ mkdirSync(join2(directory, "sessions"), { mode: 448 });
288
+ privateJson(join2(directory, "harness.json"), {
289
+ owner: randomUUID(),
290
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
291
+ });
292
+ return new _RecordStore(directory);
293
+ }
294
+ path(id) {
295
+ runtimeUnit(id);
296
+ return join2(this.directory, "sessions", `${id}.json`);
297
+ }
298
+ read(id) {
299
+ const record = object(readPrivateJson(this.path(id)));
300
+ if (record.id !== id || record.owner !== this.owner || record.socket !== this.socket || record.unit !== runtimeUnit(id))
301
+ throw new Error("foreign_backend_record");
302
+ for (const [field, pattern] of [
303
+ ["ptySession", /^s\d+$/],
304
+ ["ptyInstance", /^\d+-\d+$/]
305
+ ]) {
306
+ if (!pattern.test(text(record[field], field)))
307
+ throw new Error("invalid_terminal_identity");
308
+ }
309
+ if (!Number.isSafeInteger(record.pid) || Number(record.pid) < 1)
310
+ throw new Error("invalid_session_process");
311
+ if (record.resource !== void 0)
312
+ resourceClaim(record.resource, this.owner);
313
+ return record;
314
+ }
315
+ all() {
316
+ return readdirSync(join2(this.directory, "sessions")).filter((name) => name.endsWith(".json")).map((name) => this.read(name.slice(0, -5)));
317
+ }
318
+ save(record) {
319
+ privateJson(this.path(record.id), record);
320
+ }
321
+ };
322
+
323
+ // src/harness/adapters/process/identity.ts
324
+ import { spawnSync as spawnSync2 } from "child_process";
325
+ import { readFileSync as readFileSync2 } from "fs";
326
+ function processIdentity(pid) {
327
+ if (!Number.isSafeInteger(pid) || pid < 1)
328
+ throw new Error("invalid_process_id");
329
+ if (process.platform === "darwin") return `${pid}:${darwinStart(pid)}`;
330
+ const stat = readFileSync2(`/proc/${pid}/stat`, "utf8");
331
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
332
+ if (!/^\d+$/.test(fields[19] ?? ""))
333
+ throw new Error("process_identity_unknown");
334
+ return `${pid}:${fields[19]}`;
335
+ }
336
+ function darwinStart(pid) {
337
+ const run = spawnSync2("ps", ["-o", "lstart=", "-p", String(pid)], {
338
+ encoding: "utf8"
339
+ });
340
+ const started = Date.parse(run.stdout.trim());
341
+ if (run.status !== 0 || !Number.isFinite(started)) {
342
+ const gone = new Error("process_gone");
343
+ gone.code = "ENOENT";
344
+ throw gone;
345
+ }
346
+ return Math.floor(started / 1e3);
347
+ }
348
+ function controllerExited(identity) {
349
+ if (!/^\d+:\d+$/.test(identity))
350
+ throw new Error("invalid_controller_identity");
351
+ const [pid] = identity.split(":");
352
+ try {
353
+ return processIdentity(Number(pid)) !== identity;
354
+ } catch (error) {
355
+ if (error.code === "ENOENT") return true;
356
+ throw new Error("controller_liveness_unknown", { cause: error });
357
+ }
358
+ }
359
+
360
+ // src/harness/adapters/terminal/launch-identity.ts
361
+ function labels(reply) {
362
+ return reply["labels"] ?? {};
363
+ }
364
+ function createProof(connection, intent) {
365
+ const socket = text(process.env.PMCP_PTY_SOCKET, "native_host");
366
+ if (socket !== intent.socket) throw new Error("foreign_native_socket");
367
+ const ptySession = text(process.env.PMCP_PTY_SESSION, "native_session");
368
+ const ptyInstance = text(process.env.PMCP_PTY_INSTANCE, "native_instance");
369
+ const seen = connection.must({ op: "observe", id: ptySession, lines: 0 });
370
+ const tags = labels(seen);
371
+ if (seen["instance"] !== ptyInstance || tags["pmcp.owner"] !== intent.owner || tags["pmcp.session"] !== intent.id || tags["pmcp.launch"] !== intent.nonce)
372
+ throw new Error("foreign_launch_pane");
373
+ return {
374
+ nonce: intent.nonce,
375
+ runnerIdentity: processIdentity(process.pid),
376
+ session: {
377
+ id: intent.id,
378
+ owner: intent.owner,
379
+ socket: intent.socket,
380
+ runtime: intent.runtime,
381
+ cwd: intent.cwd,
382
+ memoryMb: intent.memoryMb,
383
+ ptySession,
384
+ ptyInstance,
385
+ pid: integer(
386
+ Number(seen["pid"]),
387
+ "session_process",
388
+ 1,
389
+ Number.MAX_SAFE_INTEGER
390
+ ),
391
+ unit: intent.unit,
392
+ createdAt: intent.createdAt,
393
+ ...intent.resource ? { resource: intent.resource } : {}
394
+ }
395
+ };
396
+ }
397
+ function assertProof(connection, proof) {
398
+ const record = proof.session;
399
+ const seen = connection.must({
400
+ op: "observe",
401
+ id: record.ptySession,
402
+ lines: 0
403
+ });
404
+ if (seen["instance"] !== record.ptyInstance)
405
+ throw new Error("stale_launch_server");
406
+ if (Number(seen["pid"]) !== record.pid) throw new Error("stale_launch_pane");
407
+ const tags = labels(seen);
408
+ if (tags["pmcp.owner"] !== record.owner || tags["pmcp.session"] !== record.id || tags["pmcp.launch"] !== proof.nonce)
409
+ throw new Error("foreign_launch_pane");
410
+ }
411
+ function panePresent(connection, proof) {
412
+ if (!connection.alive()) return false;
413
+ const listed = connection.must({ op: "list" });
414
+ if (listed["instance"] !== proof.session.ptyInstance)
415
+ throw new Error("stale_launch_server");
416
+ const sessions = listed["sessions"] ?? [];
417
+ return sessions.some((s) => s["id"] === proof.session.ptySession);
418
+ }
419
+
420
+ // src/harness/launch/journal.ts
421
+ import { createHash as createHash2 } from "crypto";
422
+ import { existsSync as existsSync2, readdirSync as readdirSync2 } from "fs";
423
+ import { join as join3 } from "path";
424
+ var LaunchJournal = class {
425
+ constructor(records, id) {
426
+ this.records = records;
427
+ this.id = id;
428
+ runtimeUnit(id);
429
+ }
430
+ records;
431
+ id;
432
+ path(kind) {
433
+ if (!["intent", "proof", "grant", "committed", "aborted"].includes(kind))
434
+ throw new Error("invalid_launch_artifact");
435
+ return join3(this.records.directory, `${this.id}.${kind}.json`);
436
+ }
437
+ intent() {
438
+ const value = object(readPrivateJson(this.path("intent")));
439
+ if (value.id !== this.id || value.owner !== this.records.owner || value.socket !== this.records.socket || value.unit !== runtimeUnit(this.id) || value.slice !== budgetSlice(this.records.owner))
440
+ throw new Error("foreign_launch_intent");
441
+ if (!/^\d+:\d+$/.test(text(value.controllerIdentity, "controller")))
442
+ throw new Error("invalid_launch_controller");
443
+ for (const field of ["groupId", "generation", "nonce"])
444
+ runtimeUnit(text(value[field], field));
445
+ if (value.role !== "main" && value.role !== "worker")
446
+ throw new Error("invalid_launch_role");
447
+ strings(value.argv, "argv");
448
+ text(value.cwd, "cwd");
449
+ text(value.runtime, "runtime");
450
+ text(value.createdAt, "created_at");
451
+ integer(value.memoryMb, "session_memory", 32, 1536);
452
+ if (value.resource !== void 0)
453
+ resourceClaim(value.resource, this.records.owner);
454
+ if (value.dockerCreation !== void 0) {
455
+ const creation = object(value.dockerCreation);
456
+ const config = object(creation.configuration);
457
+ const labels2 = object(config.Labels);
458
+ if (creation.egress !== void 0) egressPolicy(creation.egress);
459
+ const bridge = creation.egress === void 0 ? void 0 : egressPolicy(creation.egress).bridgeExecutable;
460
+ if (bridge && !/^[a-f0-9]{64}$/.test(String(creation.bridgeSha256)))
461
+ throw new Error("invalid_docker_bridge_digest");
462
+ if (!bridge && creation.bridgeSha256 !== void 0)
463
+ throw new Error("ungranted_docker_bridge_digest");
464
+ const policy = new GroupStore(join3(this.records.directory, "group.json")).state.group.dockerPolicy;
465
+ const profile = selectedProfile(
466
+ policy,
467
+ creation.privateProfile,
468
+ text(value.runtime, "runtime")
469
+ );
470
+ const expectedState = profile?.directory ?? join3(
471
+ this.records.directory,
472
+ "containers",
473
+ text(value.nonce, "nonce"),
474
+ "profile"
475
+ );
476
+ if (value.resource !== void 0 && object(value.resource).privateProfile !== creation.privateProfile)
477
+ throw new Error("launch_private_profile_mismatch");
478
+ if (creation.name !== containerName(this.records.owner, this.id) || creation.nonce !== value.nonce || creation.state !== expectedState || labels2[containerLabels.owner] !== this.records.owner || labels2[containerLabels.role] !== value.role || labels2[containerLabels.nonce] !== value.nonce)
479
+ throw new Error("foreign_container_creation");
480
+ }
481
+ return value;
482
+ }
483
+ proof() {
484
+ const intent = this.intent();
485
+ const value = object(readPrivateJson(this.path("proof")));
486
+ const session = object(value.session);
487
+ if (value.nonce !== intent.nonce || session.id !== intent.id || session.owner !== intent.owner || session.socket !== intent.socket || session.unit !== intent.unit || session.cwd !== intent.cwd || session.memoryMb !== intent.memoryMb || session.runtime !== intent.runtime || session.createdAt !== intent.createdAt || JSON.stringify(session.resource) !== JSON.stringify(intent.resource))
488
+ throw new Error("foreign_launch_proof");
489
+ for (const [field, pattern] of [
490
+ ["ptySession", /^s\d+$/],
491
+ ["ptyInstance", /^\d+-\d+$/]
492
+ ]) {
493
+ if (!pattern.test(text(session[field], field)))
494
+ throw new Error("invalid_launch_identity");
495
+ }
496
+ integer(session.pid, "session_process", 1, Number.MAX_SAFE_INTEGER);
497
+ if (!/^\d+:\d+$/.test(text(value.runnerIdentity, "runner")))
498
+ throw new Error("invalid_launch_runner");
499
+ return value;
500
+ }
501
+ grant() {
502
+ const intent = this.intent();
503
+ return {
504
+ id: intent.id,
505
+ owner: intent.owner,
506
+ groupId: intent.groupId,
507
+ generation: intent.generation,
508
+ nonce: intent.nonce,
509
+ proofDigest: createHash2("sha256").update(JSON.stringify(this.proof())).digest("hex")
510
+ };
511
+ }
512
+ assertRegistered() {
513
+ const intent = this.intent();
514
+ const group = new GroupStore(join3(this.records.directory, "group.json")).state.group;
515
+ if (group.id !== intent.groupId || group.generation !== intent.generation)
516
+ throw new Error("launch_group_generation_mismatch");
517
+ if (intent.dockerCreation && JSON.stringify(intent.dockerCreation.egress) !== JSON.stringify(group.dockerPolicy?.egress))
518
+ throw new Error("launch_egress_grant_mismatch");
519
+ if (group.state !== "ready" || !group.allowedRuntimes.includes(intent.runtime))
520
+ throw new Error("launch_group_not_ready");
521
+ if (!group.sessions.some(
522
+ (session) => session.id === intent.id && session.role === intent.role && !session.stopped
523
+ ))
524
+ throw new Error("launch_registration_missing");
525
+ const record = this.records.read(this.id);
526
+ if (JSON.stringify(record) !== JSON.stringify(this.proof().session))
527
+ throw new Error("launch_record_mismatch");
528
+ }
529
+ authorize() {
530
+ if (existsSync2(this.path("aborted"))) throw new Error("launch_was_aborted");
531
+ this.assertRegistered();
532
+ privateJson(this.path("grant"), this.grant());
533
+ }
534
+ assertGrant() {
535
+ if (existsSync2(this.path("aborted"))) throw new Error("launch_was_aborted");
536
+ const grant = object(readPrivateJson(this.path("grant")));
537
+ if (JSON.stringify(grant) !== JSON.stringify(this.grant()))
538
+ throw new Error("launch_grant_mismatch");
539
+ }
540
+ commit() {
541
+ this.assertRegistered();
542
+ this.assertGrant();
543
+ privateJson(this.path("committed"), this.grant());
544
+ }
545
+ assertCommitted() {
546
+ this.assertGrant();
547
+ const committed = object(readPrivateJson(this.path("committed")));
548
+ if (JSON.stringify(committed) !== JSON.stringify(this.grant()))
549
+ throw new Error("launch_commit_mismatch");
550
+ }
551
+ abortRecord() {
552
+ if (!existsSync2(this.path("aborted"))) return;
553
+ const value = object(readPrivateJson(this.path("aborted")));
554
+ if (value.id !== this.id || value.owner !== this.records.owner || !["stopping", "stopped"].includes(String(value.state)))
555
+ throw new Error("foreign_launch_abort");
556
+ return value;
557
+ }
558
+ };
559
+ function launchJournals(records) {
560
+ return readdirSync2(records.directory).filter((name) => name.endsWith(".intent.json")).map((name) => new LaunchJournal(records, name.slice(0, -12)));
561
+ }
562
+ function pendingLaunches(records) {
563
+ return launchJournals(records).filter((journal) => {
564
+ const aborted = journal.abortRecord();
565
+ if (aborted) return aborted.state !== "stopped";
566
+ if (!existsSync2(journal.path("committed"))) return true;
567
+ journal.assertCommitted();
568
+ return false;
569
+ });
570
+ }
571
+
572
+ // src/harness/adapters/docker/bridge-artifact.ts
573
+ import { createHash as createHash3 } from "crypto";
574
+ import {
575
+ closeSync as closeSync3,
576
+ constants as constants2,
577
+ fstatSync as fstatSync2,
578
+ fsyncSync,
579
+ openSync as openSync3,
580
+ readFileSync as readFileSync3,
581
+ writeFileSync
582
+ } from "fs";
583
+ import { join as join5 } from "path";
584
+
585
+ // src/harness/adapters/process/artifact.ts
586
+ import { fileURLToPath } from "url";
587
+ var sources = {
588
+ worker: "../../application/worker.ts",
589
+ "pane-runner": "./pane-runner.ts",
590
+ "launch-gate": "./launch-gate.ts",
591
+ "egress-bridge": "../egress/bridge-runtime.ts"
592
+ };
593
+ function artifact(name) {
594
+ if (import.meta.url.endsWith(".ts"))
595
+ return fileURLToPath(new URL(sources[name], import.meta.url));
596
+ return fileURLToPath(new URL(`./harness-${name}.js`, import.meta.url));
597
+ }
598
+
599
+ // src/harness/adapters/docker/private-profile.ts
600
+ import { homedir as homedir2 } from "os";
601
+ import {
602
+ closeSync as closeSync2,
603
+ constants,
604
+ existsSync as existsSync3,
605
+ fstatSync,
606
+ lstatSync as lstatSync2,
607
+ openSync as openSync2,
608
+ realpathSync as realpathSync2,
609
+ statfsSync
610
+ } from "fs";
611
+ import { join as join4, relative } from "path";
612
+ var privateProfileLock = "profile.lock";
613
+ function overlap(left, right) {
614
+ const scope = relative(left, right);
615
+ return scope === "" || scope !== ".." && !scope.startsWith("../");
616
+ }
617
+ function profileIdentity(directory, projectRoot) {
618
+ if (directory === "/" || directory === realpathSync2(homedir2()) || overlap(directory, projectRoot) || overlap(projectRoot, directory) || realpathSync2(directory) !== directory)
619
+ throw new Error("private_profile_scope_not_admitted");
620
+ const stat = lstatSync2(directory);
621
+ if (!stat.isDirectory() || stat.uid !== process.getuid?.() || (stat.mode & 511) !== 448)
622
+ throw new Error("unsafe_private_profile_directory");
623
+ if ([26985, 4283649346, 4266872130].includes(statfsSync(directory).type))
624
+ throw new Error("remote_private_profile_not_admitted");
625
+ const lock = openSync2(
626
+ join4(directory, privateProfileLock),
627
+ constants.O_RDONLY | constants.O_NOFOLLOW
628
+ );
629
+ try {
630
+ const value = fstatSync(lock);
631
+ if (!value.isFile() || value.nlink !== 1 || value.uid !== process.getuid?.() || (value.mode & 511) !== 384)
632
+ throw new Error("unsafe_private_profile_lock");
633
+ return `${stat.dev}:${stat.ino}:${value.dev}:${value.ino}`;
634
+ } finally {
635
+ closeSync2(lock);
636
+ }
637
+ }
638
+ function captureProfile(grant, projectRoot) {
639
+ const directory = realpathSync2(grant.directory);
640
+ if (directory !== grant.directory || overlap(directory, projectRoot) || overlap(projectRoot, directory) || directory === "/" || directory === realpathSync2(homedir2()))
641
+ throw new Error("private_profile_scope_not_admitted");
642
+ const stat = lstatSync2(directory);
643
+ if (!stat.isDirectory() || stat.uid !== process.getuid?.() || (stat.mode & 511) !== 448)
644
+ throw new Error("unsafe_private_profile_directory");
645
+ const lock = join4(directory, privateProfileLock);
646
+ if (!existsSync3(lock)) closeSync2(openSync2(lock, "wx", 384));
647
+ const identity = profileIdentity(directory, projectRoot);
648
+ if (grant.identity && grant.identity !== identity)
649
+ throw new Error("private_profile_identity_changed");
650
+ return { ...grant, identity };
651
+ }
652
+ function assertProfileIdentity(grant, projectRoot) {
653
+ if (!grant.identity || profileIdentity(grant.directory, projectRoot) !== grant.identity)
654
+ throw new Error("private_profile_identity_changed");
655
+ }
656
+ function assertProfileAvailable(grant, projectRoot) {
657
+ assertProfileIdentity(grant, projectRoot);
658
+ try {
659
+ command("flock", [
660
+ "--exclusive",
661
+ "--nonblock",
662
+ "--conflict-exit-code",
663
+ "73",
664
+ join4(grant.directory, privateProfileLock),
665
+ "true"
666
+ ]);
667
+ } catch (error) {
668
+ if (error.status === 73)
669
+ throw new Error("private_profile_busy");
670
+ throw error;
671
+ }
672
+ }
673
+
674
+ // src/harness/adapters/docker/entrypoint.ts
675
+ function bridgeName(nonce) {
676
+ return `.pmcp-egress-${nonce.slice(0, 8)}.mjs`;
677
+ }
678
+ function containerEntrypoint(policy, runtime, nonce, privateProfile) {
679
+ const native = policy.commands[runtime];
680
+ if (!native) throw new Error("docker_runtime_command_not_granted");
681
+ const command2 = policy.egress?.bridgeExecutable ? [
682
+ policy.egress.bridgeExecutable,
683
+ `/state/${bridgeName(nonce)}`,
684
+ "--",
685
+ ...native
686
+ ] : native;
687
+ const profile = selectedProfile(policy, privateProfile, runtime);
688
+ if (!profile) return command2;
689
+ return [
690
+ profile.lockExecutable,
691
+ "--exclusive",
692
+ "--nonblock",
693
+ "--close",
694
+ "--conflict-exit-code",
695
+ "73",
696
+ `/state/${privateProfileLock}`,
697
+ ...command2
698
+ ];
699
+ }
700
+
701
+ // src/harness/adapters/docker/bridge-artifact.ts
702
+ function source() {
703
+ const path = artifact("egress-bridge");
704
+ if (!path.endsWith(".js"))
705
+ throw new Error("docker_bridge_requires_compiled_cli");
706
+ return readFileSync3(path);
707
+ }
708
+ function digest(value) {
709
+ return createHash3("sha256").update(value).digest("hex");
710
+ }
711
+ function bridgeDigest() {
712
+ return digest(source());
713
+ }
714
+ function prepareBridge(creation) {
715
+ if (!creation.egress?.bridgeExecutable) return;
716
+ const content = source();
717
+ if (digest(content) !== creation.bridgeSha256)
718
+ throw new Error("docker_bridge_source_changed");
719
+ const descriptor = openSync3(
720
+ join5(creation.state, bridgeName(creation.nonce)),
721
+ "wx",
722
+ 384
723
+ );
724
+ try {
725
+ writeFileSync(descriptor, content);
726
+ fsyncSync(descriptor);
727
+ } finally {
728
+ closeSync3(descriptor);
729
+ }
730
+ }
731
+ function assertBridge(creation) {
732
+ if (!creation.egress?.bridgeExecutable) return;
733
+ const descriptor = openSync3(
734
+ join5(creation.state, bridgeName(creation.nonce)),
735
+ constants2.O_RDONLY | constants2.O_NOFOLLOW
736
+ );
737
+ try {
738
+ const stat = fstatSync2(descriptor);
739
+ if (!stat.isFile() || stat.uid !== process.getuid?.() || stat.nlink !== 1 || (stat.mode & 63) !== 0 || stat.size > 2097152 || digest(readFileSync3(descriptor)) !== creation.bridgeSha256)
740
+ throw new Error("docker_bridge_artifact_changed");
741
+ } finally {
742
+ closeSync3(descriptor);
743
+ }
744
+ }
745
+
746
+ export {
747
+ artifact,
748
+ containerLabels,
749
+ containerName,
750
+ resourceClaim,
751
+ assertResourceOwner,
752
+ configurationDigest,
753
+ inspectResource,
754
+ resourceAbsent,
755
+ assertResourceFresh,
756
+ resourceRunning,
757
+ Connection,
758
+ stateDirectory,
759
+ runtimeUnit,
760
+ budgetSlice,
761
+ RecordStore,
762
+ processIdentity,
763
+ controllerExited,
764
+ createProof,
765
+ assertProof,
766
+ panePresent,
767
+ LaunchJournal,
768
+ launchJournals,
769
+ pendingLaunches,
770
+ captureProfile,
771
+ assertProfileIdentity,
772
+ assertProfileAvailable,
773
+ containerEntrypoint,
774
+ bridgeDigest,
775
+ prepareBridge,
776
+ assertBridge
777
+ };
778
+ //# sourceMappingURL=chunk-7UCZAN4J.js.map