@modootoday/pmcp 0.17.3 → 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 -16160
  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 -4911
  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 +6 -3
  160. package/dist/project/hook-adapter.js +66 -35
  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 +844 -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-PRSnYGLV.d.ts +0 -10
  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,478 @@
1
+ import {
2
+ STALE_MS,
3
+ STATE_FILES,
4
+ alive,
5
+ asBroadcast,
6
+ asLease,
7
+ asPause,
8
+ asRecord,
9
+ isLive,
10
+ leaseFile
11
+ } from "./chunk-C4NHQGHL.js";
12
+ import {
13
+ checkoutOf
14
+ } from "./chunk-IJBSOWHK.js";
15
+
16
+ // src/sessions/mailbox/select.ts
17
+ import { basename, resolve } from "path";
18
+ var KINDS = ["session", "alias", "role", "desk"];
19
+ function checkSelector(selector) {
20
+ if (selector === "all") return selector;
21
+ const [kind, value] = splitSelector(selector);
22
+ if (!KINDS.includes(kind) || !value)
23
+ throw new Error(
24
+ `--to ${selector}: use all, session:<id>, alias:<name>, role:<name> or desk:<path>`
25
+ );
26
+ return selector;
27
+ }
28
+ function splitSelector(selector) {
29
+ const at = selector.indexOf(":");
30
+ if (at < 0) return [selector, ""];
31
+ return [selector.slice(0, at), selector.slice(at + 1)];
32
+ }
33
+ function normalizeSelector(selector, cwd) {
34
+ const [kind, value] = splitSelector(checkSelector(selector));
35
+ return kind === "desk" ? `desk:${resolve(cwd, value)}` : selector;
36
+ }
37
+ function matches(selector, recipient) {
38
+ if (selector === "all") return true;
39
+ const [kind, value] = splitSelector(selector);
40
+ if (kind === "session")
41
+ return !!recipient.session && recipient.session.startsWith(value);
42
+ if (kind === "alias") return recipient.alias === value;
43
+ if (kind === "role") return (recipient.roles ?? []).includes(value);
44
+ if (kind !== "desk" || !recipient.desk) return false;
45
+ return recipient.desk === value || basename(recipient.desk) === value;
46
+ }
47
+ function before(message, recipient) {
48
+ if (!recipient.since) return false;
49
+ return Date.parse(message.createdAt) < Date.parse(recipient.since);
50
+ }
51
+ function addressedTo(message, recipient) {
52
+ return message.to.some(
53
+ (selector) => matches(selector, recipient) && !(selector === "all" && before(message, recipient))
54
+ );
55
+ }
56
+ function sentBy(message, recipient) {
57
+ const { session, alias } = message.from;
58
+ if (session && session === recipient.session) return true;
59
+ return !!alias && alias === recipient.alias;
60
+ }
61
+ function inboxKey(recipient) {
62
+ if (recipient.session) return recipient.session.replace(/[^\w-]/gu, "_");
63
+ return `@${(recipient.alias ?? "operator").replace(/[^\w.-]/gu, "_")}`;
64
+ }
65
+
66
+ // src/sessions/files/broadcast.ts
67
+ import { rmSync } from "fs";
68
+ import { join } from "path";
69
+
70
+ // src/sessions/files/json.ts
71
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
72
+ import { dirname } from "path";
73
+ function readJson(path) {
74
+ try {
75
+ return JSON.parse(readFileSync(path, "utf8"));
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
80
+ function writeJson(path, value) {
81
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
82
+ const temporary = `${path}.${process.pid}.tmp`;
83
+ writeFileSync(temporary, `${JSON.stringify(value, null, 2)}
84
+ `, {
85
+ mode: 384
86
+ });
87
+ renameSync(temporary, path);
88
+ }
89
+ function readLines(path) {
90
+ let text2 = "";
91
+ try {
92
+ text2 = readFileSync(path, "utf8");
93
+ } catch {
94
+ return [];
95
+ }
96
+ return text2.split("\n").filter(Boolean).flatMap((line) => {
97
+ try {
98
+ return [JSON.parse(line)];
99
+ } catch {
100
+ return [];
101
+ }
102
+ });
103
+ }
104
+ function writeLines(path, values) {
105
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
106
+ writeFileSync(
107
+ path,
108
+ `${values.map((value) => JSON.stringify(value)).join("\n")}
109
+ `,
110
+ { mode: 384 }
111
+ );
112
+ }
113
+
114
+ // src/sessions/files/broadcast.ts
115
+ function filesBroadcast(dir, keep, registry) {
116
+ const latestPath = join(dir, STATE_FILES.broadcast);
117
+ const historyPath = join(dir, STATE_FILES.history);
118
+ const list = () => {
119
+ const latest = asBroadcast(readJson(latestPath));
120
+ if (!latest) return [];
121
+ const earlier = readLines(historyPath).map(asBroadcast).filter(
122
+ (entry) => entry !== null && Number(entry.id) < Number(latest.id)
123
+ );
124
+ return [...earlier, latest];
125
+ };
126
+ return {
127
+ list,
128
+ unseen(session) {
129
+ const record = registry.get(session);
130
+ const own = new Set([session, record?.alias].filter(Boolean));
131
+ const seen = Number(record?.seenBroadcast ?? 0);
132
+ const started = Date.parse(record?.startedAt ?? "") || 0;
133
+ const all = list();
134
+ const latest = all.at(-1);
135
+ const unseen = all.filter(
136
+ (entry) => !own.has(entry.by) && Number(entry.id) > seen && (seen > 0 || entry === latest || Number(entry.id) >= started)
137
+ );
138
+ if (latest && Number(latest.id) > seen)
139
+ registry.upsert(session, { seenBroadcast: latest.id });
140
+ return unseen;
141
+ },
142
+ post({ by, text: text2 }) {
143
+ const entry = {
144
+ id: `${Date.now()}`,
145
+ by,
146
+ text: text2,
147
+ since: (/* @__PURE__ */ new Date()).toISOString()
148
+ };
149
+ writeLines(historyPath, [...list(), entry].slice(-keep));
150
+ writeJson(latestPath, entry);
151
+ return entry;
152
+ },
153
+ clear() {
154
+ rmSync(latestPath, { force: true });
155
+ rmSync(historyPath, { force: true });
156
+ }
157
+ };
158
+ }
159
+
160
+ // src/sessions/files/leases.ts
161
+ import { rmSync as rmSync2 } from "fs";
162
+ import { join as join2 } from "path";
163
+ var leasePath = (dir, name) => join2(dir, leaseFile(name));
164
+ function filesLeases(dir) {
165
+ const read = (name) => {
166
+ const lease = asLease(readJson(leasePath(dir, name)));
167
+ if (!lease || !alive(lease.pid)) return null;
168
+ return lease;
169
+ };
170
+ return {
171
+ read,
172
+ take(name, lease) {
173
+ const held = read(name);
174
+ const pid = lease.pid ?? process.pid;
175
+ if (held && held.pid !== pid) return false;
176
+ writeJson(leasePath(dir, name), {
177
+ pid,
178
+ subject: lease.subject,
179
+ ...lease.cwd ? { cwd: lease.cwd } : {},
180
+ since: (/* @__PURE__ */ new Date()).toISOString()
181
+ });
182
+ return true;
183
+ },
184
+ release(name, pid = process.pid) {
185
+ const held = asLease(readJson(leasePath(dir, name)));
186
+ if (!held || held.pid === pid || !alive(held.pid)) {
187
+ rmSync2(leasePath(dir, name), { force: true });
188
+ }
189
+ }
190
+ };
191
+ }
192
+
193
+ // src/sessions/files/mailbox.ts
194
+ import {
195
+ appendFileSync,
196
+ existsSync,
197
+ linkSync,
198
+ mkdirSync as mkdirSync2,
199
+ readdirSync,
200
+ rmSync as rmSync3,
201
+ unlinkSync,
202
+ writeFileSync as writeFileSync2
203
+ } from "fs";
204
+ import { join as join3 } from "path";
205
+
206
+ // src/sessions/mailbox/format.ts
207
+ var text = (value) => typeof value === "string";
208
+ function asMessage(value) {
209
+ if (value === null || typeof value !== "object" || Array.isArray(value))
210
+ return null;
211
+ const fields = value;
212
+ const from = fields["from"];
213
+ const to = fields["to"];
214
+ const valid = text(fields["id"]) && text(fields["body"]) && text(fields["createdAt"]) && text(fields["expiresAt"]) && Array.isArray(to) && to.every(text) && from !== null && typeof from === "object";
215
+ return valid ? value : null;
216
+ }
217
+ var MAX_BODY = 600;
218
+ function noticeOf(fresh, earlier, limit, session, pmcp = "pmcp") {
219
+ const shown = fresh.slice(-limit);
220
+ const as = session ? ` --session ${session}` : "";
221
+ const lines = [
222
+ `Mailbox: ${fresh.length} new message${fresh.length === 1 ? "" : "s"} for this session.`
223
+ ];
224
+ for (const message of shown) {
225
+ const sender = message.from.alias ?? message.from.session?.slice(0, 8) ?? "unknown";
226
+ const subject = message.subject ? ` (${message.subject})` : "";
227
+ const body = message.body.length > MAX_BODY ? `${message.body.slice(0, MAX_BODY)}...` : message.body;
228
+ lines.push(`- ${message.id} from ${sender}${subject}: ${body}`);
229
+ if (message.once)
230
+ lines.push(
231
+ " One-time request: act on it once. Do not keep its instructions as standing rules."
232
+ );
233
+ }
234
+ const hidden = fresh.length - shown.length;
235
+ if (hidden > 0) lines.push(`${hidden} more new message(s) not shown.`);
236
+ if (earlier > 0)
237
+ lines.push(`${earlier} earlier message(s) are still unacknowledged.`);
238
+ lines.push(
239
+ `Read: ${pmcp} sessions inbox${as}`,
240
+ `Acknowledge: ${pmcp} sessions ack <id>${as}`,
241
+ `Reply: ${pmcp} sessions reply <id>${as} '<text>'`
242
+ );
243
+ return lines.join("\n");
244
+ }
245
+
246
+ // src/sessions/files/mailbox.ts
247
+ var ID = /^\d{13}-[0-9a-f]{8}$/u;
248
+ var SAFE_KEY = /^@?[\w.-]+$/u;
249
+ function filesMailbox(dir, settings) {
250
+ const messages = join3(dir, "messages");
251
+ const inbox = join3(dir, "inbox");
252
+ const pathOf = (id) => join3(messages, `${id}.json`);
253
+ const marker = (key, id, kind) => {
254
+ if (!SAFE_KEY.test(key) || !ID.test(id))
255
+ throw new Error(`invalid mailbox key ${key} or id ${id}`);
256
+ return join3(inbox, key, `${id}.${kind}`);
257
+ };
258
+ const audit = (event, fields) => {
259
+ if (!settings.audit) return;
260
+ const line = { at: (/* @__PURE__ */ new Date()).toISOString(), event, ...fields };
261
+ appendFileSync(join3(dir, "messages.jsonl"), `${JSON.stringify(line)}
262
+ `, {
263
+ mode: 384
264
+ });
265
+ };
266
+ const touch = (path) => {
267
+ mkdirSync2(join3(path, ".."), { recursive: true, mode: 448 });
268
+ try {
269
+ writeFileSync2(path, "", { flag: "wx", mode: 384 });
270
+ return true;
271
+ } catch {
272
+ return false;
273
+ }
274
+ };
275
+ const get = (id) => ID.test(id) ? asMessage(readJson(pathOf(id))) : null;
276
+ const all = () => existsSync(messages) ? readdirSync(messages).filter((name) => name.endsWith(".json")).map((name) => get(name.slice(0, -5))).filter((message) => message !== null).sort((a, b) => a.id.localeCompare(b.id)) : [];
277
+ const live = (now) => all().filter((message) => Date.parse(message.expiresAt) > now);
278
+ const acked = (key, id) => existsSync(marker(key, id, "ack"));
279
+ const remove = (message, event) => {
280
+ rmSync3(pathOf(message.id), { force: true });
281
+ if (existsSync(inbox))
282
+ for (const key of readdirSync(inbox))
283
+ for (const kind of ["ack", "delivered"])
284
+ rmSync3(join3(inbox, key, `${message.id}.${kind}`), { force: true });
285
+ audit(event, { id: message.id });
286
+ };
287
+ return {
288
+ settings,
289
+ send(input) {
290
+ mkdirSync2(messages, { recursive: true, mode: 448 });
291
+ const created = Date.now();
292
+ const ttl = input.ttlMinutes ?? settings.ttlMinutes;
293
+ for (let attempt = 0; ; attempt += 1) {
294
+ if (attempt === 8)
295
+ throw new Error(`could not create a message in ${messages}`);
296
+ const id = `${created}-${Math.random().toString(16).slice(2, 10).padEnd(8, "0")}`;
297
+ const message = {
298
+ id,
299
+ from: input.from,
300
+ to: [...input.to],
301
+ ...input.subject ? { subject: input.subject } : {},
302
+ body: input.body,
303
+ createdAt: new Date(created).toISOString(),
304
+ expiresAt: new Date(created + ttl * 6e4).toISOString(),
305
+ ...input.replyTo ? { replyTo: input.replyTo } : {},
306
+ once: input.once === true,
307
+ ...input.broadcastId ? { broadcastId: input.broadcastId } : {}
308
+ };
309
+ const temporary = `${pathOf(id)}.${process.pid}.tmp`;
310
+ writeFileSync2(temporary, `${JSON.stringify(message, null, 2)}
311
+ `, {
312
+ mode: 384
313
+ });
314
+ try {
315
+ linkSync(temporary, pathOf(id));
316
+ } catch {
317
+ continue;
318
+ } finally {
319
+ unlinkSync(temporary);
320
+ }
321
+ audit("sent", { id, from: input.from, to: message.to });
322
+ return message;
323
+ }
324
+ },
325
+ get,
326
+ list: (now = Date.now()) => live(now),
327
+ inbox: (recipient, now = Date.now()) => live(now).filter(
328
+ (message) => addressedTo(message, recipient) && !sentBy(message, recipient) && !acked(recipient.key, message.id)
329
+ ),
330
+ delivered: (key, id) => existsSync(marker(key, id, "delivered")),
331
+ markDelivered(key, ids) {
332
+ for (const id of ids)
333
+ if (touch(marker(key, id, "delivered")))
334
+ audit("delivered", { id, to: key });
335
+ },
336
+ acked,
337
+ ack(key, ids) {
338
+ const done = ids.filter((id) => get(id) !== null);
339
+ for (const id of done)
340
+ if (touch(marker(key, id, "ack"))) audit("acked", { id, by: key });
341
+ return done;
342
+ },
343
+ withdraw(match) {
344
+ const gone = all().filter(match);
345
+ for (const message of gone) remove(message, "withdrawn");
346
+ return gone.length;
347
+ },
348
+ sweep(now = Date.now()) {
349
+ const expired = all().filter(
350
+ (message) => Date.parse(message.expiresAt) <= now
351
+ );
352
+ for (const message of expired) remove(message, "expired");
353
+ return expired.length;
354
+ },
355
+ record: (event, fields) => audit(event, fields)
356
+ };
357
+ }
358
+
359
+ // src/sessions/files/pause.ts
360
+ import { rmSync as rmSync4 } from "fs";
361
+ import { join as join4 } from "path";
362
+ function filesPause(dir) {
363
+ const path = join4(dir, STATE_FILES.pause);
364
+ return {
365
+ read: () => asPause(readJson(path)),
366
+ write(pause) {
367
+ if (!pause) {
368
+ rmSync4(path, { force: true });
369
+ return;
370
+ }
371
+ writeJson(path, {
372
+ by: pause.by,
373
+ reason: pause.reason,
374
+ since: (/* @__PURE__ */ new Date()).toISOString()
375
+ });
376
+ }
377
+ };
378
+ }
379
+
380
+ // src/sessions/files/registry.ts
381
+ import { readdirSync as readdirSync2, rmSync as rmSync5 } from "fs";
382
+ import { join as join5 } from "path";
383
+ var SESSION_ID = /^[A-Za-z0-9_-]{8,64}$/u;
384
+ function filesRegistry(dir, staleMs) {
385
+ const fleetDir = join5(dir, STATE_FILES.records);
386
+ const pathOf = (session) => join5(fleetDir, `${session}.json`);
387
+ const get = (session) => SESSION_ID.test(session) ? asRecord(readJson(pathOf(session))) : null;
388
+ const list = (now = Date.now()) => {
389
+ let names = [];
390
+ try {
391
+ names = readdirSync2(fleetDir).filter((name) => name.endsWith(".json"));
392
+ } catch {
393
+ return [];
394
+ }
395
+ return names.map((name) => asRecord(readJson(join5(fleetDir, name)))).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
396
+ };
397
+ const remove = (session) => {
398
+ if (SESSION_ID.test(session)) rmSync5(pathOf(session), { force: true });
399
+ };
400
+ return {
401
+ get,
402
+ list,
403
+ remove,
404
+ upsert(session, fields) {
405
+ if (!SESSION_ID.test(session)) return null;
406
+ const now = (/* @__PURE__ */ new Date()).toISOString();
407
+ const previous = get(session) ?? { session, startedAt: now };
408
+ const next = {
409
+ ...previous,
410
+ ...fields,
411
+ updatedAt: now
412
+ };
413
+ if (typeof fields.cwd === "string" && fields.cwd !== previous.cwd) {
414
+ const checkout = checkoutOf(fields.cwd);
415
+ next["worktree"] = checkout?.root ?? "";
416
+ next["branch"] = checkout?.branch ?? "";
417
+ }
418
+ writeJson(pathOf(session), next);
419
+ return next;
420
+ },
421
+ sweep(now = Date.now()) {
422
+ const stale = list(now).filter((record) => !record.live);
423
+ stale.forEach((record) => remove(record.session));
424
+ return stale.length;
425
+ }
426
+ };
427
+ }
428
+
429
+ // src/sessions/files-store.ts
430
+ var OFF = {
431
+ enabled: false,
432
+ ttlMinutes: 1440,
433
+ maxDelivered: 5,
434
+ audit: true
435
+ };
436
+ function createFilesStore(dir, options = {}) {
437
+ const registry = filesRegistry(dir, options.staleMs ?? STALE_MS);
438
+ const mailbox = filesMailbox(dir, options.mailbox ?? OFF);
439
+ const broadcast = filesBroadcast(dir, options.keepBroadcasts ?? 10, registry);
440
+ return {
441
+ dir,
442
+ registry,
443
+ pause: filesPause(dir),
444
+ leases: filesLeases(dir),
445
+ // With the mailbox on, a broadcast is also a message to all, which the mailbox delivers;
446
+ // broadcast.json stays the record status, snapshot and the Claude band read.
447
+ broadcast: !mailbox.settings.enabled ? broadcast : {
448
+ ...broadcast,
449
+ post(entry) {
450
+ const posted = broadcast.post(entry);
451
+ mailbox.send({
452
+ from: { alias: entry.by },
453
+ to: ["all"],
454
+ body: entry.text,
455
+ broadcastId: posted.id
456
+ });
457
+ return posted;
458
+ },
459
+ clear() {
460
+ broadcast.clear();
461
+ mailbox.withdraw((message) => message.broadcastId !== void 0);
462
+ }
463
+ },
464
+ mailbox
465
+ };
466
+ }
467
+
468
+ export {
469
+ noticeOf,
470
+ normalizeSelector,
471
+ addressedTo,
472
+ sentBy,
473
+ inboxKey,
474
+ writeJson,
475
+ SESSION_ID,
476
+ createFilesStore
477
+ };
478
+ //# sourceMappingURL=chunk-Z4HRRXRF.js.map
@@ -0,0 +1,102 @@
1
+ import {
2
+ HOST_MANIFEST,
3
+ HOST_POLICY
4
+ } from "./chunk-4VCC2NXE.js";
5
+ import {
6
+ projectStateDir
7
+ } from "./chunk-OEH47H6A.js";
8
+
9
+ // src/project/host-approval.ts
10
+ import { createHash } from "crypto";
11
+ import {
12
+ chmodSync,
13
+ existsSync,
14
+ mkdirSync,
15
+ readFileSync,
16
+ writeFileSync
17
+ } from "fs";
18
+ import { basename, dirname, join } from "path";
19
+ function approvalDir(root, env = process.env) {
20
+ const projects = projectStateDir(root, void 0, env);
21
+ return join(dirname(dirname(projects)), "host-approvals", basename(projects));
22
+ }
23
+ function projectedFiles(root) {
24
+ const manifest = join(root, HOST_MANIFEST);
25
+ const policy = join(root, HOST_POLICY);
26
+ if (!existsSync(manifest) || !existsSync(policy)) return null;
27
+ return {
28
+ manifest: readFileSync(manifest, "utf8"),
29
+ policy: readFileSync(policy, "utf8")
30
+ };
31
+ }
32
+ function hostDigest(files) {
33
+ return createHash("sha256").update(`host.json
34
+ ${files.manifest}\0policy.json
35
+ ${files.policy}`).digest("hex");
36
+ }
37
+ function readApproval(dir) {
38
+ try {
39
+ const raw = JSON.parse(readFileSync(join(dir, "approval.json"), "utf8"));
40
+ const files = {
41
+ manifest: readFileSync(join(dir, "host.json"), "utf8"),
42
+ policy: readFileSync(join(dir, "policy.json"), "utf8")
43
+ };
44
+ if (raw.sha256 !== hostDigest(files)) return null;
45
+ return { sha256: raw.sha256, approvedAt: String(raw.approvedAt) };
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+ function approvalState(root, env = process.env) {
51
+ const files = projectedFiles(root);
52
+ const approved = readApproval(approvalDir(root, env)) ?? void 0;
53
+ if (!files)
54
+ return { state: "unprojected", ...approved ? { approved } : {} };
55
+ const projected = hostDigest(files);
56
+ if (!approved) return { state: "unapproved", projected };
57
+ const state = approved.sha256 === projected ? "approved" : "differs";
58
+ return { state, projected, approved };
59
+ }
60
+ var DETAIL = {
61
+ approved: "pmcp-pty loads this policy",
62
+ differs: "the projected policy differs from the approved one, which stays in force; run pmcp harness host approve",
63
+ unapproved: "not approved; pmcp-pty loads no host policy until pmcp harness host approve",
64
+ unprojected: "run pmcp project"
65
+ };
66
+ function hostApprovalDoctor(root, env = process.env) {
67
+ const { state } = approvalState(root, env);
68
+ const status = state === "approved" ? "ok" : "warn";
69
+ return {
70
+ tool: "project",
71
+ check: "pmcp-pty host approved",
72
+ status,
73
+ detail: DETAIL[state]
74
+ };
75
+ }
76
+ function privateFile(path, text) {
77
+ writeFileSync(path, text, { mode: 384 });
78
+ chmodSync(path, 384);
79
+ }
80
+ function writeApproval(dir, files, now = /* @__PURE__ */ new Date()) {
81
+ mkdirSync(dir, { recursive: true, mode: 448 });
82
+ chmodSync(dir, 448);
83
+ const approval = { sha256: hostDigest(files), approvedAt: now.toISOString() };
84
+ privateFile(join(dir, "host.json"), files.manifest);
85
+ privateFile(join(dir, "policy.json"), files.policy);
86
+ privateFile(
87
+ join(dir, "approval.json"),
88
+ `${JSON.stringify(approval, null, 2)}
89
+ `
90
+ );
91
+ return approval;
92
+ }
93
+
94
+ export {
95
+ approvalDir,
96
+ projectedFiles,
97
+ hostDigest,
98
+ approvalState,
99
+ hostApprovalDoctor,
100
+ writeApproval
101
+ };
102
+ //# sourceMappingURL=chunk-ZH6R642Z.js.map
@@ -0,0 +1,77 @@
1
+ import {
2
+ claudeSocket
3
+ } from "./chunk-XP2U3LO3.js";
4
+ import "./chunk-C4NHQGHL.js";
5
+
6
+ // src/sessions/wake/claude.ts
7
+ import { randomUUID } from "crypto";
8
+ import { createConnection } from "net";
9
+ var socketOf = (record, context) => claudeSocket(record.session, context.home);
10
+ function frames(text, socket, env) {
11
+ const lines = [];
12
+ const token = env["CLAUDE_CODE_MESSAGING_TOKEN"];
13
+ if (token && env["CLAUDE_CODE_MESSAGING_SOCKET"] === socket)
14
+ lines.push(JSON.stringify({ type: "auth", token }));
15
+ lines.push(
16
+ JSON.stringify({
17
+ type: "user",
18
+ message: { role: "user", content: text },
19
+ from: "pmcp",
20
+ msg_id: randomUUID()
21
+ })
22
+ );
23
+ return `${lines.join("\n")}
24
+ `;
25
+ }
26
+ function post(socket, payload) {
27
+ return new Promise((resolve, reject) => {
28
+ const connection = createConnection(socket);
29
+ const timer = setTimeout(
30
+ () => connection.destroy(new Error("timed out")),
31
+ 5e3
32
+ );
33
+ connection.on("error", (error) => {
34
+ clearTimeout(timer);
35
+ reject(error);
36
+ });
37
+ connection.on("connect", () => connection.end(payload));
38
+ connection.on("close", (failed) => {
39
+ clearTimeout(timer);
40
+ if (!failed) resolve();
41
+ });
42
+ });
43
+ }
44
+ var claudeInbox = {
45
+ probe: (record, context) => socketOf(record, context) ? "claude-inbox" : null,
46
+ async wake(record, text, context) {
47
+ const base = { session: record.session, runtime: "claude" };
48
+ const file = socketOf(record, context);
49
+ if (!file?.messagingSocketPath)
50
+ return {
51
+ ...base,
52
+ outcome: "not-wakeable",
53
+ detail: "no live Claude session file with an inbox socket"
54
+ };
55
+ try {
56
+ await post(
57
+ file.messagingSocketPath,
58
+ frames(text, file.messagingSocketPath, context.env)
59
+ );
60
+ } catch (error) {
61
+ const reason = error instanceof Error ? error.message : String(error);
62
+ return {
63
+ ...base,
64
+ outcome: "failed",
65
+ transport: "claude-inbox",
66
+ detail: reason
67
+ };
68
+ }
69
+ const detail = `posted to ${file.messagingSocketPath} (target ${file.status ?? "unknown"}); a target in bypassPermissions without crossSessionInbound accept holds it for approval`;
70
+ return { ...base, outcome: "woken", transport: "claude-inbox", detail };
71
+ }
72
+ };
73
+ export {
74
+ claudeInbox,
75
+ frames
76
+ };
77
+ //# sourceMappingURL=claude-U2JC2DNQ.js.map
@@ -0,0 +1,41 @@
1
+ import {
2
+ JSON_VERBS,
3
+ SESSION_VERBS,
4
+ sessionsSpec
5
+ } from "./chunk-BVCTKPT3.js";
6
+ import "./chunk-XNML2KIC.js";
7
+ import {
8
+ ArgumentError
9
+ } from "./chunk-A4PKLESO.js";
10
+
11
+ // src/sessions/cli.ts
12
+ async function run(context) {
13
+ const verb = context.args.positional[0] ?? "status";
14
+ if (!SESSION_VERBS.includes(verb))
15
+ throw new ArgumentError(
16
+ `unknown verb ${verb}; use ${SESSION_VERBS.join(", ")}`
17
+ );
18
+ if (verb === "status")
19
+ return (await import("./status-VHODZPXB.js")).status(context);
20
+ if (context.args.flags.has("json") && !JSON_VERBS.includes(verb))
21
+ throw new ArgumentError(`--json works with ${JSON_VERBS.join(", ")}`);
22
+ if (["send", "inbox", "ack", "reply"].includes(verb)) {
23
+ const mailbox = await import("./mailbox-7BV54Q4R.js");
24
+ if (verb === "send") return mailbox.send(context);
25
+ if (verb === "inbox") return mailbox.inbox(context);
26
+ if (verb === "ack") return mailbox.ack(context);
27
+ return mailbox.reply(context);
28
+ }
29
+ if (verb === "pause") return (await import("./pause-FFAYRBWI.js")).run(context);
30
+ if (verb === "resume") return (await import("./resume-UU4HZIUP.js")).run(context);
31
+ if (verb === "broadcast")
32
+ return (await import("./broadcast-3RY3OZGY.js")).run(context);
33
+ if (verb === "unbroadcast")
34
+ return (await import("./unbroadcast-KPUEFLZD.js")).run(context);
35
+ return (await import("./sweep-64JDCGK6.js")).run(context);
36
+ }
37
+ var sessionsCommand = { ...sessionsSpec, run };
38
+ export {
39
+ sessionsCommand
40
+ };
41
+ //# sourceMappingURL=cli-VYCQJZ5X.js.map