@modootoday/pmcp 0.17.4 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/CHANGELOG.md +60 -0
  5. package/README.md +29 -24
  6. package/dist/apply-4IGTXOCQ.js +242 -0
  7. package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
  8. package/dist/available-DBSIVVJ6.js +73 -0
  9. package/dist/broadcast-3RY3OZGY.js +18 -0
  10. package/dist/chunk-25GHX674.js +1246 -0
  11. package/dist/chunk-2P4Z2NUX.js +28 -0
  12. package/dist/chunk-34DECPVC.js +22 -0
  13. package/dist/chunk-3NYG4SGU.js +45 -0
  14. package/dist/chunk-3PW4FI7U.js +32 -0
  15. package/dist/chunk-3Y3HDMHA.js +108 -0
  16. package/dist/chunk-47O3X4VS.js +113 -0
  17. package/dist/chunk-4NDEP7HU.js +26 -0
  18. package/dist/chunk-4VCC2NXE.js +104 -0
  19. package/dist/chunk-5OMOPUE6.js +39 -0
  20. package/dist/chunk-5QQWS4US.js +53 -0
  21. package/dist/chunk-5ZABTVSW.js +48 -0
  22. package/dist/chunk-65ZHM5RH.js +4985 -0
  23. package/dist/chunk-665TA55Z.js +419 -0
  24. package/dist/chunk-6STKGOCW.js +27 -0
  25. package/dist/chunk-6WXMJOMI.js +9 -0
  26. package/dist/chunk-73AKO4UL.js +24 -0
  27. package/dist/chunk-7BLPN3W6.js +31 -0
  28. package/dist/chunk-7DLZC73N.js +29 -0
  29. package/dist/chunk-7GBYECSK.js +72 -0
  30. package/dist/chunk-7TD53M7L.js +13 -0
  31. package/dist/chunk-A4PKLESO.js +112 -0
  32. package/dist/chunk-ABTJQ4QV.js +74 -0
  33. package/dist/chunk-BBTBJCFA.js +380 -0
  34. package/dist/chunk-BU65MNVU.js +13 -0
  35. package/dist/chunk-BVCTKPT3.js +83 -0
  36. package/dist/chunk-C4NHQGHL.js +142 -0
  37. package/dist/chunk-CJTKR6K6.js +1213 -0
  38. package/dist/chunk-DCU2EXQV.js +78 -0
  39. package/dist/chunk-DZ2MRTYT.js +135 -0
  40. package/dist/chunk-E2YOZ2FF.js +207 -0
  41. package/dist/chunk-E3DQB5LS.js +48 -0
  42. package/dist/chunk-E7OOHLQR.js +7 -0
  43. package/dist/chunk-EATCUWGG.js +66 -0
  44. package/dist/chunk-EIDIVIAD.js +33 -0
  45. package/dist/chunk-EJBZGIDK.js +1934 -0
  46. package/dist/chunk-ELAGZ635.js +252 -0
  47. package/dist/chunk-GZHHEHKY.js +44 -0
  48. package/dist/chunk-HDMBVLCZ.js +53 -0
  49. package/dist/chunk-HQOB7OQS.js +81 -0
  50. package/dist/chunk-IGYRMM62.js +28 -0
  51. package/dist/chunk-IJBSOWHK.js +86 -0
  52. package/dist/chunk-INT7QLEU.js +114 -0
  53. package/dist/chunk-J6QLLQVL.js +1025 -0
  54. package/dist/chunk-J7UYNJCR.js +9 -0
  55. package/dist/chunk-JEL35P7S.js +53 -0
  56. package/dist/chunk-JGJ4INEN.js +32 -0
  57. package/dist/chunk-JS5RTH4I.js +84 -0
  58. package/dist/chunk-JUXNIXN4.js +42 -0
  59. package/dist/chunk-JWRZDYB5.js +59 -0
  60. package/dist/chunk-KMXRRSKT.js +660 -0
  61. package/dist/chunk-LAZQBMAU.js +67 -0
  62. package/dist/chunk-LLBPVZXM.js +67 -0
  63. package/dist/chunk-LLT5FQBE.js +57 -0
  64. package/dist/chunk-LMT3PPXJ.js +17 -0
  65. package/dist/chunk-MM2Y43LC.js +87 -0
  66. package/dist/chunk-MPSQXSC6.js +346 -0
  67. package/dist/chunk-MVFH26QT.js +97 -0
  68. package/dist/chunk-MWFOUBFC.js +39 -0
  69. package/dist/chunk-N5AQ3PP7.js +211 -0
  70. package/dist/chunk-NQPURJT5.js +44 -0
  71. package/dist/chunk-NRBQK6UX.js +105 -0
  72. package/dist/chunk-NZS5CD72.js +333 -0
  73. package/dist/chunk-OEH47H6A.js +48 -0
  74. package/dist/chunk-OG7QR2DP.js +75 -0
  75. package/dist/chunk-OPYFEHKG.js +52 -0
  76. package/dist/chunk-P4N7DBD5.js +83 -0
  77. package/dist/chunk-PAX3QXX2.js +140 -0
  78. package/dist/chunk-PLX3BOOS.js +396 -0
  79. package/dist/chunk-PMJG2CXF.js +122 -0
  80. package/dist/chunk-PWSJJXLQ.js +643 -0
  81. package/dist/chunk-Q5H3L6Y4.js +23 -0
  82. package/dist/chunk-Q65R3XKX.js +155 -0
  83. package/dist/chunk-QEW4J3IZ.js +74 -0
  84. package/dist/chunk-QPL7E2HW.js +464 -0
  85. package/dist/chunk-R2GPCZUX.js +22 -0
  86. package/dist/chunk-R4L6LJJ2.js +778 -0
  87. package/dist/chunk-R5MT42JS.js +284 -0
  88. package/dist/chunk-RK4PYD7L.js +73 -0
  89. package/dist/chunk-RMATE45Z.js +197 -0
  90. package/dist/chunk-S3PIAMXV.js +230 -0
  91. package/dist/chunk-SG5TPMKH.js +93 -0
  92. package/dist/chunk-T3LKX23M.js +168 -0
  93. package/dist/chunk-T6GOWHK6.js +30 -0
  94. package/dist/chunk-TIA4SPU2.js +10 -0
  95. package/dist/chunk-TNCZ6444.js +57 -0
  96. package/dist/chunk-TVL5RTE6.js +269 -0
  97. package/dist/chunk-UOCLRM7P.js +151 -0
  98. package/dist/chunk-UPQTAHUK.js +189 -0
  99. package/dist/chunk-V4NPDK6X.js +14 -0
  100. package/dist/chunk-VJFEN6DJ.js +38 -0
  101. package/dist/chunk-WIW772I3.js +25 -0
  102. package/dist/chunk-XELAZAIM.js +136 -0
  103. package/dist/chunk-XNML2KIC.js +23 -0
  104. package/dist/chunk-XP2U3LO3.js +30 -0
  105. package/dist/chunk-YGOWIJPE.js +51 -0
  106. package/dist/chunk-YIXDHQYE.js +11 -0
  107. package/dist/chunk-YMHUM7AV.js +22 -0
  108. package/dist/chunk-YSAWTGNA.js +117 -0
  109. package/dist/chunk-Z4HRRXRF.js +478 -0
  110. package/dist/chunk-ZH6R642Z.js +102 -0
  111. package/dist/claude-U2JC2DNQ.js +77 -0
  112. package/dist/cli-VYCQJZ5X.js +41 -0
  113. package/dist/cli-ZTCBSDW4.js +46 -0
  114. package/dist/cli.js +144 -16197
  115. package/dist/completion-E7RRG3ZT.js +142 -0
  116. package/dist/config-DnpLL2kT.d.ts +46 -0
  117. package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
  118. package/dist/diagnostics-XXH4FLUG.js +93 -0
  119. package/dist/doctor-ZIOESU3N.js +538 -0
  120. package/dist/entry-ZNFCTDVE.js +305 -0
  121. package/dist/exec-mcp-X6372BLE.js +365 -0
  122. package/dist/harness-F2XFDYXF.js +177 -0
  123. package/dist/harness-egress-bridge.js +4 -4
  124. package/dist/harness-launch-gate.js +47 -940
  125. package/dist/harness-pane-runner.js +13 -80
  126. package/dist/harness-worker.js +21 -2703
  127. package/dist/hook-body.js +5221 -0
  128. package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
  129. package/dist/hook.js +26 -0
  130. package/dist/hooks-FYE2L5RW.js +21 -0
  131. package/dist/host-GRY3VAHH.js +22 -0
  132. package/dist/host-X6BR6X4O.js +200 -0
  133. package/dist/host-run-GCA6H6SR.js +307 -0
  134. package/dist/http.d.ts +5 -42
  135. package/dist/http.js +21 -2234
  136. package/dist/import-mcp-2TTBPVLY.js +400 -0
  137. package/dist/index.d.ts +146 -168
  138. package/dist/index.js +133 -4948
  139. package/dist/init-627KFXTG.js +14 -0
  140. package/dist/install-GG7HHZK2.js +796 -0
  141. package/dist/invoke-LW22Z6ET.js +23 -0
  142. package/dist/list-MCP2FXUF.js +68 -0
  143. package/dist/list-NGMSQ5SH.js +65 -0
  144. package/dist/load-BEUBABtB.d.ts +21 -0
  145. package/dist/logout-6CSHUWWE.js +44 -0
  146. package/dist/logs-SPB6AANY.js +107 -0
  147. package/dist/mailbox/index.d.ts +10 -5
  148. package/dist/mailbox/index.js +53 -1572
  149. package/dist/mailbox-7BV54Q4R.js +285 -0
  150. package/dist/mailbox-GDJ7BWQN.js +189 -0
  151. package/dist/mainline-JQTTYJMI.js +639 -0
  152. package/dist/marketplace-G4VQET5W.js +191 -0
  153. package/dist/mcp-2DKVU3SW.js +15 -0
  154. package/dist/mcp-V23HC3LB.js +193 -0
  155. package/dist/models-ISU4DCMA.js +32 -0
  156. package/dist/opencode-CN7JLQYO.js +60 -0
  157. package/dist/pause-FFAYRBWI.js +18 -0
  158. package/dist/preview-DT7DWG5F.js +91 -0
  159. package/dist/project/hook-adapter.d.ts +5 -2
  160. package/dist/project/hook-adapter.js +41 -27
  161. package/dist/project-FY62G55N.js +70 -0
  162. package/dist/pty-XTJ4MIWK.js +94 -0
  163. package/dist/recovery-U6QB3PMT.js +100 -0
  164. package/dist/reindex-Y27QJFDB.js +22 -0
  165. package/dist/resume-UU4HZIUP.js +18 -0
  166. package/dist/run-HALGEJNJ.js +19 -0
  167. package/dist/run-OGA3P7FC.js +126 -0
  168. package/dist/serve-NBKT5BKY.js +104 -0
  169. package/dist/session-XM2CR425.js +159 -0
  170. package/dist/setup-DTKZLZUT.js +18 -0
  171. package/dist/start-login-UIQYQBMC.js +416 -0
  172. package/dist/status-A2OUTNGK.js +9 -0
  173. package/dist/status-H2VAHIDV.js +10 -0
  174. package/dist/status-NOOHW5WA.js +43 -0
  175. package/dist/status-VHODZPXB.js +55 -0
  176. package/dist/status-XQANBVXW.js +286 -0
  177. package/dist/stdio.d.ts +3 -13
  178. package/dist/stdio.js +16 -3186
  179. package/dist/sweep-64JDCGK6.js +18 -0
  180. package/dist/test-MKAXFJOL.js +561 -0
  181. package/dist/tools-gpHNq9Dh.d.ts +328 -0
  182. package/dist/tui-MWKAXE4K.js +153 -0
  183. package/dist/unbroadcast-KPUEFLZD.js +18 -0
  184. package/dist/validate-5GZ5YWNA.js +46 -0
  185. package/dist/worker-RQ575EJL.js +80 -0
  186. package/dist/worktree-create-PZSRB7PH.js +89 -0
  187. package/dist/worktree-list-JYB6VXLW.js +51 -0
  188. package/dist/worktree-sync-UF5CXPWV.js +30 -0
  189. package/docs/hooks/capabilities/antigravity.json +199 -0
  190. package/docs/hooks/capabilities/claude.json +179 -0
  191. package/docs/hooks/capabilities/codex.json +179 -0
  192. package/docs/hooks/capabilities/gemini.json +196 -0
  193. package/docs/hooks/capabilities/grok.json +192 -0
  194. package/docs/hooks/capabilities/opencode.json +184 -0
  195. package/docs/project-configuration.md +821 -4
  196. package/docs/terminal-harness.md +71 -28
  197. package/docs/terminal-workspace.md +91 -170
  198. package/gemini-extension.json +1 -1
  199. package/package.json +13 -1
  200. package/plugin.json +1 -1
  201. package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
  202. package/plugins/pmcp/gemini-extension.json +1 -1
  203. package/plugins/pmcp/mod/commands.ts +72 -0
  204. package/plugins/pmcp/mod/contract.d.ts +39 -0
  205. package/plugins/pmcp/mod/draw.tsx +216 -0
  206. package/plugins/pmcp/mod/guard.ts +42 -0
  207. package/plugins/pmcp/mod/hooks.json +4 -0
  208. package/plugins/pmcp/mod/host.ts +46 -0
  209. package/plugins/pmcp/mod/model.ts +144 -0
  210. package/plugins/pmcp/mod/reader/index.ts +18 -0
  211. package/plugins/pmcp/mod/reader/read.ts +76 -0
  212. package/plugins/pmcp/mod/reader/settings.ts +54 -0
  213. package/plugins/pmcp/mod/reader/types.ts +38 -0
  214. package/plugins/pmcp/mod/register.tsx +73 -0
  215. package/plugins/pmcp/mod/sessions/format.ts +91 -0
  216. package/plugins/pmcp/mod/sessions/types.ts +162 -0
  217. package/plugins/pmcp/mod/snapshot.ts +75 -0
  218. package/plugins/pmcp/mod/spinner.tsx +30 -0
  219. package/plugins/pmcp/mod/state.ts +28 -0
  220. package/plugins/pmcp/plugin.json +1 -1
  221. package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
  222. package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
  223. package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
  224. package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -11
  225. package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +145 -0
  226. package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +104 -0
  227. package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +88 -0
  228. package/schema/catalog-v1.json +158 -0
  229. package/schema/library.json +164 -0
  230. package/schema/marketplace-manifest.json +130 -0
  231. package/schema/plugin-manifest.json +55 -0
  232. package/schema/skill-frontmatter.json +144 -0
  233. package/schema/skill-metadata-core.json +110 -0
  234. package/skills/agent-assets-migrate/SKILL.md +96 -0
  235. package/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
  236. package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
  237. package/skills/package-skill-catalog/SKILL.md +51 -11
  238. package/skills/pmcp-project-init/SKILL.md +145 -0
  239. package/skills/pmcp-sessions-and-git/SKILL.md +104 -0
  240. package/skills/skill-package-scaffold/SKILL.md +88 -0
  241. package/dist/config-BkSpjUG6.d.ts +0 -50
  242. package/dist/embed-DRROSD3F.d.ts +0 -53
  243. package/dist/hook-spec-CSJJySsH.d.ts +0 -11
  244. package/dist/server-VWSY3Shw.d.ts +0 -543
  245. package/dist/tui-worker.js +0 -6549
  246. /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
@@ -0,0 +1,285 @@
1
+ import {
2
+ storeFrom
3
+ } from "./chunk-RK4PYD7L.js";
4
+ import {
5
+ pmcpCommand
6
+ } from "./chunk-EATCUWGG.js";
7
+ import {
8
+ ptyRef
9
+ } from "./chunk-3PW4FI7U.js";
10
+ import "./chunk-SG5TPMKH.js";
11
+ import {
12
+ addressedTo,
13
+ inboxKey,
14
+ normalizeSelector,
15
+ sentBy
16
+ } from "./chunk-Z4HRRXRF.js";
17
+ import {
18
+ ancestors
19
+ } from "./chunk-C4NHQGHL.js";
20
+ import {
21
+ ArgumentError,
22
+ many,
23
+ one
24
+ } from "./chunk-A4PKLESO.js";
25
+ import "./chunk-OEH47H6A.js";
26
+ import "./chunk-IJBSOWHK.js";
27
+ import "./chunk-QPL7E2HW.js";
28
+ import "./chunk-PMJG2CXF.js";
29
+
30
+ // src/sessions/cli/mailbox.ts
31
+ import { readFileSync } from "fs";
32
+ import { homedir } from "os";
33
+
34
+ // src/sessions/identity.ts
35
+ var SESSION_VARIABLES = [
36
+ ["codex", "CODEX_THREAD_ID"],
37
+ ["grok", "GROK_SESSION_ID"],
38
+ ["antigravity", "ANTIGRAVITY_CONVERSATION_ID"],
39
+ ["claude", "CLAUDE_CODE_SESSION_ID"]
40
+ ];
41
+ var MARKERS = [
42
+ ["codex", "CODEX_THREAD_ID"],
43
+ ["grok", "GROK_AGENT"],
44
+ ["antigravity", "ANTIGRAVITY_AGENT"],
45
+ ["opencode", "OPENCODE"],
46
+ ["gemini", "GEMINI_CLI"],
47
+ ["claude", "CLAUDECODE"]
48
+ ];
49
+ function inferSession(env, records, chain) {
50
+ const live = records.filter(
51
+ (record) => record.live && record.pid !== void 0
52
+ );
53
+ for (const pid of chain) {
54
+ const record = live.find((entry) => entry.pid === pid);
55
+ if (record)
56
+ return {
57
+ session: record.session,
58
+ ...record.runtime ? { runtime: record.runtime } : {},
59
+ via: "process"
60
+ };
61
+ }
62
+ for (const [runtime, name] of SESSION_VARIABLES) {
63
+ const value = env[name];
64
+ if (value) return { session: value, runtime, via: "environment" };
65
+ }
66
+ const marker = MARKERS.find(([, name]) => env[name]);
67
+ return marker ? { runtime: marker[0] } : {};
68
+ }
69
+
70
+ // src/sessions/wake/index.ts
71
+ var TRANSPORTS = {
72
+ claude: async () => (await import("./claude-U2JC2DNQ.js")).claudeInbox,
73
+ opencode: async () => (await import("./opencode-CN7JLQYO.js")).opencodeServer
74
+ };
75
+ function recipientOf(record) {
76
+ const roles = Array.isArray(record["roles"]) ? record["roles"] : [];
77
+ return {
78
+ key: inboxKey({ session: record.session }),
79
+ session: record.session,
80
+ ...record.alias ? { alias: record.alias } : {},
81
+ roles,
82
+ ...record.worktree ? { desk: record.worktree } : {},
83
+ ...record.startedAt ? { since: record.startedAt } : {}
84
+ };
85
+ }
86
+ function wakeText(session, mail, pmcp = "pmcp") {
87
+ const subjects = mail.map((message) => message.subject).filter(Boolean);
88
+ const about = subjects.length > 0 ? ` (${subjects.join("; ")})` : "";
89
+ return `pmcp mail: ${mail.length} new message(s) for you${about}. Run exactly this one command and follow what it prints, nothing else first: ${pmcp} sessions inbox --session ${session}`;
90
+ }
91
+ var NONE = "no wake transport for this runtime; the mail arrives at its next event";
92
+ async function wakeOne(record, text, context) {
93
+ if (ptyRef(record))
94
+ return (await import("./pty-XTJ4MIWK.js")).ptyTurn(record, text, context);
95
+ const load = TRANSPORTS[record.runtime ?? ""];
96
+ if (load) return (await load()).wake(record, text, context);
97
+ const runtime = record.runtime ?? "unknown";
98
+ return {
99
+ session: record.session,
100
+ runtime,
101
+ outcome: "not-wakeable",
102
+ detail: NONE
103
+ };
104
+ }
105
+ async function wakeRecipients(store, message, context) {
106
+ const results = [];
107
+ for (const record of store.registry.list().filter((entry) => entry.live)) {
108
+ const recipient = recipientOf(record);
109
+ if (!addressedTo(message, recipient) || sentBy(message, recipient))
110
+ continue;
111
+ const mail = store.mailbox.inbox(recipient);
112
+ const text = wakeText(record.session, mail, context.pmcp);
113
+ const result = await wakeOne(record, text, context);
114
+ const receipt = result.receipt?.["receipt"] ?? {};
115
+ store.mailbox.record("woken", {
116
+ id: message.id,
117
+ to: recipient.key,
118
+ outcome: result.outcome,
119
+ transport: result.transport ?? null,
120
+ ...receipt["channel"] ? { channel: receipt["channel"] } : {},
121
+ detail: result.detail
122
+ });
123
+ results.push(result);
124
+ }
125
+ return results;
126
+ }
127
+
128
+ // src/sessions/cli/mailbox.ts
129
+ function mailboxOf(context) {
130
+ const { store } = storeFrom(context);
131
+ if (!store.mailbox.settings.enabled)
132
+ throw new ArgumentError(
133
+ "the mailbox is off; declare [sessions.mailbox] in pmcp.toml"
134
+ );
135
+ return store;
136
+ }
137
+ function sessionOf(context, store) {
138
+ const given = one(context.args, "session");
139
+ if (given || one(context.args, "by")) return given;
140
+ const found = inferSession(context.env, store.registry.list(), ancestors());
141
+ if (!found.session && found.runtime)
142
+ context.ui.warn(
143
+ `running inside ${found.runtime} but its session is unknown; acting as operator. Pass --session <id> (the id is in the mailbox notice).`
144
+ );
145
+ return found.session;
146
+ }
147
+ function caller(context, store) {
148
+ const session = sessionOf(context, store);
149
+ const record = session ? store.registry.get(session) : null;
150
+ const alias = one(context.args, "by") ?? record?.alias ?? (session ? void 0 : "operator");
151
+ const roles = Array.isArray(record?.["roles"]) ? record["roles"] : [];
152
+ return {
153
+ key: inboxKey({
154
+ ...session ? { session } : {},
155
+ ...alias ? { alias } : {}
156
+ }),
157
+ ...session ? { session } : {},
158
+ ...alias ? { alias } : {},
159
+ roles,
160
+ ...record?.worktree ? { desk: record.worktree } : {},
161
+ ...record?.startedAt ? { since: record.startedAt } : {}
162
+ };
163
+ }
164
+ function bodyOf(context, skip) {
165
+ const words = context.args.positional.slice(skip);
166
+ const body = (words.length === 1 && words[0] === "-" ? readFileSync(0, "utf8") : words.join(" ")).trim();
167
+ if (!body)
168
+ throw new ArgumentError("the message needs a body (words, or - for stdin)");
169
+ return body;
170
+ }
171
+ function ttlOf(context) {
172
+ const raw = one(context.args, "ttl");
173
+ if (raw === void 0) return void 0;
174
+ const minutes = Number(raw);
175
+ if (!Number.isSafeInteger(minutes) || minutes <= 0)
176
+ throw new ArgumentError("--ttl takes a positive number of minutes");
177
+ return minutes;
178
+ }
179
+ function print(context, value, line) {
180
+ if (context.args.flags.has("json"))
181
+ context.ui.data(`${JSON.stringify(value, null, 2)}
182
+ `);
183
+ else context.ui.line(line);
184
+ }
185
+ async function sent(context, store, to, replyTo) {
186
+ const me = caller(context, store);
187
+ const subject = one(context.args, "subject");
188
+ const ttlMinutes = ttlOf(context);
189
+ const message = store.mailbox.send({
190
+ from: {
191
+ ...me.session ? { session: me.session } : {},
192
+ ...me.alias ? { alias: me.alias } : {}
193
+ },
194
+ to,
195
+ body: bodyOf(context, replyTo ? 2 : 1),
196
+ ...subject ? { subject } : {},
197
+ ...ttlMinutes ? { ttlMinutes } : {},
198
+ ...replyTo ? { replyTo } : {},
199
+ once: context.args.flags.has("once")
200
+ });
201
+ const wanted = context.args.flags.has("wake") || store.mailbox.settings.wake === true;
202
+ const home = context.env["HOME"] ?? homedir();
203
+ const woken = wanted ? await wakeRecipients(store, message, {
204
+ home,
205
+ env: context.env,
206
+ pmcp: pmcpCommand(
207
+ storeFrom(context).root,
208
+ store.dir,
209
+ context.env["PATH"]
210
+ )
211
+ }) : [];
212
+ const lines = woken.map(
213
+ (result) => `wake ${result.session.slice(0, 8)} (${result.runtime}) via ${result.transport ?? "none"}: ${result.outcome}; ${result.detail}`
214
+ );
215
+ print(
216
+ context,
217
+ wanted ? { ...message, wake: woken } : message,
218
+ [`sent ${message.id} to ${message.to.join(", ")}`, ...lines].join("\n")
219
+ );
220
+ return 0;
221
+ }
222
+ function send(context) {
223
+ const store = mailboxOf(context);
224
+ const to = many(context.args, "to").map(
225
+ (selector) => normalizeSelector(selector, context.cwd)
226
+ );
227
+ if (to.length === 0)
228
+ throw new ArgumentError("pmcp sessions send needs --to <selector>");
229
+ return sent(context, store, to, one(context.args, "reply-to"));
230
+ }
231
+ function reply(context) {
232
+ const store = mailboxOf(context);
233
+ const id = context.args.positional[1];
234
+ const original = id ? store.mailbox.get(id) : null;
235
+ if (!original) throw new ArgumentError(`no message ${id ?? ""} to reply to`);
236
+ const { session, alias } = original.from;
237
+ const to = session ? [`session:${session}`] : [`alias:${alias ?? "operator"}`];
238
+ return sent(context, store, to, original.id);
239
+ }
240
+ var sender = (message) => message.from.alias ?? message.from.session?.slice(0, 8) ?? "unknown";
241
+ function inbox(context) {
242
+ const store = mailboxOf(context);
243
+ const me = caller(context, store);
244
+ const all = context.args.flags.has("all");
245
+ const messages = all ? store.mailbox.list() : store.mailbox.inbox(me);
246
+ const rows = messages.map((message) => ({
247
+ ...message,
248
+ acked: store.mailbox.acked(me.key, message.id)
249
+ }));
250
+ if (context.args.flags.has("json")) {
251
+ context.ui.data(`${JSON.stringify(rows, null, 2)}
252
+ `);
253
+ return 0;
254
+ }
255
+ if (rows.length === 0) context.ui.line("no messages");
256
+ for (const row of rows) {
257
+ const subject = row.subject ? ` (${row.subject})` : "";
258
+ const once = row.once ? " [once]" : "";
259
+ context.ui.line(
260
+ `${row.id} from ${sender(row)} to ${row.to.join(", ")}${subject}${once}: ${row.body}`
261
+ );
262
+ }
263
+ return 0;
264
+ }
265
+ function ack(context) {
266
+ const store = mailboxOf(context);
267
+ const ids = context.args.positional.slice(1);
268
+ if (ids.length === 0)
269
+ throw new ArgumentError("pmcp sessions ack needs message ids");
270
+ const done = store.mailbox.ack(caller(context, store).key, ids);
271
+ const missing = ids.filter((id) => !done.includes(id));
272
+ print(
273
+ context,
274
+ { acked: done, missing },
275
+ `acknowledged ${done.length}${missing.length ? `; unknown: ${missing.join(", ")}` : ""}`
276
+ );
277
+ return missing.length > 0 ? 1 : 0;
278
+ }
279
+ export {
280
+ ack,
281
+ inbox,
282
+ reply,
283
+ send
284
+ };
285
+ //# sourceMappingURL=mailbox-7BV54Q4R.js.map
@@ -0,0 +1,189 @@
1
+ import {
2
+ configFrom
3
+ } from "./chunk-7DLZC73N.js";
4
+ import {
5
+ mailboxSpec
6
+ } from "./chunk-JWRZDYB5.js";
7
+ import "./chunk-XNML2KIC.js";
8
+ import {
9
+ ArgumentError,
10
+ one
11
+ } from "./chunk-A4PKLESO.js";
12
+ import {
13
+ MailboxError,
14
+ MailboxService,
15
+ MailboxStore,
16
+ failure,
17
+ initializeMailboxConfig,
18
+ mailboxConfigFrom,
19
+ readBinding,
20
+ readCredential,
21
+ restoreBackup,
22
+ writePrivateJson
23
+ } from "./chunk-CJTKR6K6.js";
24
+ import {
25
+ operationSchema
26
+ } from "./chunk-47O3X4VS.js";
27
+ import "./chunk-6STKGOCW.js";
28
+ import "./chunk-QPL7E2HW.js";
29
+ import "./chunk-PMJG2CXF.js";
30
+
31
+ // src/commands/mailbox.ts
32
+ import { readFileSync, writeFileSync } from "fs";
33
+ import { resolve } from "path";
34
+ var allowed = {
35
+ init: ["config", "state-dir"],
36
+ actor: ["config", "actor", "actor-file", "parent-binding"],
37
+ rotate: ["config", "actor", "actor-file", "operator"],
38
+ send: ["config", "actor-file", "binding-file", "input"],
39
+ inbox: ["config", "actor-file", "binding-file", "input"],
40
+ read: ["config", "actor-file", "binding-file", "input"],
41
+ ack: ["config", "actor-file", "binding-file", "input"],
42
+ sessions: ["config", "actor-file", "binding-file"],
43
+ export: ["config", "operator", "output", "scope-actor"],
44
+ backup: ["config", "operator", "output"],
45
+ restore: ["config", "operator", "input", "output"]
46
+ };
47
+ function required(context, name) {
48
+ const value = one(context.args, name);
49
+ if (!value) throw new ArgumentError(`Provide --${name}`);
50
+ return value;
51
+ }
52
+ var mailboxCommand = {
53
+ ...mailboxSpec,
54
+ async run(context) {
55
+ const [verb, ...extra] = context.args.positional;
56
+ const supported = verb ? allowed[verb] : void 0;
57
+ if (!supported || extra.length > 0)
58
+ throw new ArgumentError("Provide one supported mailbox operation");
59
+ for (const key of [...context.args.options.keys(), ...context.args.flags]) {
60
+ if (!supported.includes(key))
61
+ throw new ArgumentError(`--${key} is not supported by mailbox ${verb}`);
62
+ }
63
+ if (verb === "init") {
64
+ const config2 = initializeMailboxConfig(
65
+ resolve(context.cwd, one(context.args, "config") ?? "pmcp.toml"),
66
+ one(context.args, "state-dir")
67
+ );
68
+ const store2 = await MailboxStore.open(config2);
69
+ await store2.close();
70
+ context.ui.data(
71
+ `${JSON.stringify({ ok: true, data: { projectId: config2.projectId } })}
72
+ `
73
+ );
74
+ return 0;
75
+ }
76
+ const project = configFrom(context);
77
+ const config = project ? mailboxConfigFrom(project, context.env) : void 0;
78
+ if (!config?.enabled)
79
+ throw new MailboxError(
80
+ "mailbox_disabled",
81
+ "Enable [mailbox] in pmcp.toml first"
82
+ );
83
+ if (["export", "backup", "restore", "rotate"].includes(verb)) {
84
+ if (!context.args.flags.has("operator"))
85
+ throw new ArgumentError("Provide --operator for local administration");
86
+ }
87
+ if (verb === "restore") {
88
+ await restoreBackup(required(context, "input"), {
89
+ ...config,
90
+ databasePath: resolve(context.cwd, required(context, "output"))
91
+ });
92
+ context.ui.data(
93
+ `${JSON.stringify({ ok: true, data: { restored: true } })}
94
+ `
95
+ );
96
+ return 0;
97
+ }
98
+ const store = await MailboxStore.open(config);
99
+ let binding;
100
+ let ownsBinding = false;
101
+ try {
102
+ if (verb === "actor") {
103
+ const parentFile = one(context.args, "parent-binding");
104
+ const parent = parentFile ? readBinding(parentFile) : void 0;
105
+ const destination = required(context, "actor-file");
106
+ const credential = await store.registerActor(
107
+ required(context, "actor"),
108
+ parent?.actorId,
109
+ (value) => writePrivateJson(destination, value),
110
+ 6e4,
111
+ parent
112
+ );
113
+ context.ui.data(
114
+ `${JSON.stringify({ ok: true, data: { actorId: credential.actorId } })}
115
+ `
116
+ );
117
+ return 0;
118
+ }
119
+ if (verb === "rotate") {
120
+ const destination = required(context, "actor-file");
121
+ const credential = await store.rotateActor(
122
+ required(context, "actor"),
123
+ (value) => writePrivateJson(destination, value)
124
+ );
125
+ context.ui.data(
126
+ `${JSON.stringify({ ok: true, data: { actorId: credential.actorId } })}
127
+ `
128
+ );
129
+ return 0;
130
+ }
131
+ if (verb === "backup" || verb === "export") {
132
+ const destination = required(context, "output");
133
+ if (verb === "backup") {
134
+ await store.backup(destination);
135
+ } else {
136
+ const records = await store.exportRecords(
137
+ one(context.args, "scope-actor")
138
+ );
139
+ writeFileSync(
140
+ destination,
141
+ `${records.map((record) => JSON.stringify(record)).join("\n")}
142
+ `,
143
+ { flag: "wx", mode: 384 }
144
+ );
145
+ }
146
+ context.ui.data(
147
+ `${JSON.stringify({ ok: true, data: { completed: verb } })}
148
+ `
149
+ );
150
+ return 0;
151
+ }
152
+ const operation = operationSchema.parse(verb);
153
+ const actorFile = one(context.args, "actor-file");
154
+ const bindingFile = one(context.args, "binding-file");
155
+ if (Boolean(actorFile) === Boolean(bindingFile))
156
+ throw new ArgumentError("Choose one --actor-file or --binding-file");
157
+ if (bindingFile) {
158
+ binding = readBinding(bindingFile);
159
+ } else {
160
+ binding = await store.attach(readCredential(actorFile), "operator");
161
+ ownsBinding = true;
162
+ }
163
+ const inputFile = one(context.args, "input");
164
+ const input = inputFile ? JSON.parse(readFileSync(inputFile, "utf8")) : {};
165
+ const result = await new MailboxService(store, binding).call(
166
+ operation,
167
+ input
168
+ );
169
+ context.ui.data(`${JSON.stringify(result)}
170
+ `);
171
+ return result.ok ? 0 : 1;
172
+ } catch (error) {
173
+ if (error instanceof ArgumentError) throw error;
174
+ context.ui.data(`${JSON.stringify(failure(error))}
175
+ `);
176
+ return 1;
177
+ } finally {
178
+ try {
179
+ if (ownsBinding && binding) await store.detach(binding);
180
+ } finally {
181
+ await store.close();
182
+ }
183
+ }
184
+ }
185
+ };
186
+ export {
187
+ mailboxCommand
188
+ };
189
+ //# sourceMappingURL=mailbox-GDJ7BWQN.js.map