@mulmoclaude/core 7.7.1 → 7.8.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 (191) hide show
  1. package/README.md +1 -1
  2. package/assets/helps/error-recovery.md +23 -2
  3. package/assets/helps/sandbox.md +4 -2
  4. package/assets/helps/spreadsheet.md +8 -7
  5. package/dist/{atomic-C3NMg6-j.js → atomic-Dw7dV4TL.js} +1 -1
  6. package/dist/{atomic-C3NMg6-j.js.map → atomic-Dw7dV4TL.js.map} +1 -1
  7. package/dist/{atomic-cqafMWEI.cjs → atomic-bzFw4-ix.cjs} +3 -3
  8. package/dist/atomic-bzFw4-ix.cjs.map +1 -0
  9. package/dist/collection/index.cjs +6 -6
  10. package/dist/collection/index.js +6 -6
  11. package/dist/collection/paths.cjs +1 -1
  12. package/dist/collection/paths.js +1 -1
  13. package/dist/collection/registry/index.cjs +1 -1
  14. package/dist/collection/registry/index.js +1 -1
  15. package/dist/collection/registry/server/index.cjs +11 -11
  16. package/dist/collection/registry/server/index.cjs.map +1 -1
  17. package/dist/collection/registry/server/index.js +10 -10
  18. package/dist/collection/server/index.cjs +5 -5
  19. package/dist/collection/server/index.js +5 -5
  20. package/dist/collection-watchers/index.cjs +6 -6
  21. package/dist/collection-watchers/index.cjs.map +1 -1
  22. package/dist/collection-watchers/index.js +6 -6
  23. package/dist/collection-watchers/index.js.map +1 -1
  24. package/dist/{containment-Dc3gO4wD.cjs → containment-NZYJbiaa.cjs} +2 -2
  25. package/dist/{containment-Dc3gO4wD.cjs.map → containment-NZYJbiaa.cjs.map} +1 -1
  26. package/dist/{containment-D_vAa6eT.js → containment-Ne0w06jN.js} +1 -1
  27. package/dist/{containment-D_vAa6eT.js.map → containment-Ne0w06jN.js.map} +1 -1
  28. package/dist/{discovery-D1cjgQRo.cjs → discovery-Cu35oXeW.cjs} +14 -14
  29. package/dist/discovery-Cu35oXeW.cjs.map +1 -0
  30. package/dist/{discovery-c5OKO0dI.js → discovery-DTOodl_M.js} +11 -11
  31. package/dist/discovery-DTOodl_M.js.map +1 -0
  32. package/dist/{dist--k7dcIzm.cjs → dist-DK0zTPR1.cjs} +2 -2
  33. package/dist/dist-DK0zTPR1.cjs.map +1 -0
  34. package/dist/{dist-Cb-KNFRA.js → dist-wmt60Ec-.js} +2 -2
  35. package/dist/dist-wmt60Ec-.js.map +1 -0
  36. package/dist/errorMessage-CEWGPYzN.js +1 -0
  37. package/dist/errorMessage-DCZuXjO4.cjs +1 -0
  38. package/dist/{errors-D-LZwNSI.js → errors-DfW0e2uv.js} +2 -2
  39. package/dist/{errors-D-LZwNSI.js.map → errors-DfW0e2uv.js.map} +1 -1
  40. package/dist/{errors-DVKixTWx.cjs → errors-WLfupg-H.cjs} +2 -2
  41. package/dist/{errors-DVKixTWx.cjs.map → errors-WLfupg-H.cjs.map} +1 -1
  42. package/dist/feeds/index.cjs +2 -2
  43. package/dist/feeds/index.js +2 -2
  44. package/dist/feeds/paths.cjs +1 -1
  45. package/dist/feeds/server/index.cjs +14 -14
  46. package/dist/feeds/server/index.cjs.map +1 -1
  47. package/dist/feeds/server/index.js +12 -12
  48. package/dist/feeds/server/index.js.map +1 -1
  49. package/dist/file-change/index.cjs +2 -2
  50. package/dist/file-change/index.js +1 -1
  51. package/dist/files/index.cjs +9 -9
  52. package/dist/files/index.js +7 -7
  53. package/dist/global-config/index.cjs +1 -1
  54. package/dist/global-config/index.js +1 -1
  55. package/dist/google/index.cjs +16 -16
  56. package/dist/google/index.cjs.map +1 -1
  57. package/dist/google/index.js +14 -14
  58. package/dist/google/index.js.map +1 -1
  59. package/dist/{graph-DBbzemby.js → graph-CVoiWp8B.js} +2 -2
  60. package/dist/{graph-DBbzemby.js.map → graph-CVoiWp8B.js.map} +1 -1
  61. package/dist/{graph-BvVMZfDV.cjs → graph-RyHEgm-F.cjs} +2 -2
  62. package/dist/{graph-BvVMZfDV.cjs.map → graph-RyHEgm-F.cjs.map} +1 -1
  63. package/dist/{iconGlyph-CFOiFsmq.cjs → iconGlyph-BhtU1a9P.cjs} +1 -1
  64. package/dist/{iconGlyph-CFOiFsmq.cjs.map → iconGlyph-BhtU1a9P.cjs.map} +1 -1
  65. package/dist/{iconGlyph-D9h__VaM.js → iconGlyph-DjE_HLf4.js} +1 -1
  66. package/dist/{iconGlyph-D9h__VaM.js.map → iconGlyph-DjE_HLf4.js.map} +1 -1
  67. package/dist/{ingestTypes-CLDvn7kw.cjs → ingestTypes-CmO3SNaO.cjs} +2 -2
  68. package/dist/{ingestTypes-CLDvn7kw.cjs.map → ingestTypes-CmO3SNaO.cjs.map} +1 -1
  69. package/dist/{ingestTypes-DuXuSBSn.js → ingestTypes-V3bHEQ2i.js} +2 -2
  70. package/dist/{ingestTypes-DuXuSBSn.js.map → ingestTypes-V3bHEQ2i.js.map} +1 -1
  71. package/dist/{itemId-D2XAQ8RU.cjs → itemId-D3mJhGu0.cjs} +1 -1
  72. package/dist/{itemId-D2XAQ8RU.cjs.map → itemId-D3mJhGu0.cjs.map} +1 -1
  73. package/dist/{itemId-D_pSpa3U.js → itemId-D7pPwaX6.js} +1 -1
  74. package/dist/{itemId-D_pSpa3U.js.map → itemId-D7pPwaX6.js.map} +1 -1
  75. package/dist/{json-BizOSThv.js → json-C23c3t1W.js} +2 -2
  76. package/dist/{json-BizOSThv.js.map → json-C23c3t1W.js.map} +1 -1
  77. package/dist/{json-BGdV2cz6.cjs → json-CWiVjlka.cjs} +2 -2
  78. package/dist/{json-BGdV2cz6.cjs.map → json-CWiVjlka.cjs.map} +1 -1
  79. package/dist/{listen-CPZX9gpR.js → listen-DFP9Lrbd.js} +2 -2
  80. package/dist/{listen-CPZX9gpR.js.map → listen-DFP9Lrbd.js.map} +1 -1
  81. package/dist/{listen-Bu1QX69l.cjs → listen-jSwqWZfE.cjs} +2 -2
  82. package/dist/{listen-Bu1QX69l.cjs.map → listen-jSwqWZfE.cjs.map} +1 -1
  83. package/dist/notifier/index.cjs +1 -1
  84. package/dist/notifier/index.js +1 -1
  85. package/dist/{notifier-B3cqvwts.js → notifier-BkIAgskG.js} +3 -3
  86. package/dist/{notifier-B3cqvwts.js.map → notifier-BkIAgskG.js.map} +1 -1
  87. package/dist/{notifier-Cq2UbCTW.cjs → notifier-nv9c1r6T.cjs} +3 -3
  88. package/dist/{notifier-Cq2UbCTW.cjs.map → notifier-nv9c1r6T.cjs.map} +1 -1
  89. package/dist/{paths-DUHAueEv.cjs → paths-D0WRbJTV.cjs} +2 -2
  90. package/dist/{paths-DUHAueEv.cjs.map → paths-D0WRbJTV.cjs.map} +1 -1
  91. package/dist/{paths-BMQNHdaJ.js → paths-qvo3SsnP.js} +2 -2
  92. package/dist/{paths-BMQNHdaJ.js.map → paths-qvo3SsnP.js.map} +1 -1
  93. package/dist/plugin-vue/i18n.cjs +1 -1
  94. package/dist/plugin-vue/i18n.cjs.map +1 -1
  95. package/dist/plugin-vue/i18n.js +1 -1
  96. package/dist/plugin-vue/index.cjs +3 -3
  97. package/dist/plugin-vue/index.cjs.map +1 -1
  98. package/dist/plugin-vue/index.js +3 -3
  99. package/dist/plugin-vue/index.js.map +1 -1
  100. package/dist/{project-mU6-xLfy.js → project-CSx7gqgs.js} +1 -1
  101. package/dist/{project-mU6-xLfy.js.map → project-CSx7gqgs.js.map} +1 -1
  102. package/dist/{project-DDTIVEMU.cjs → project-sS_ltoWz.cjs} +1 -1
  103. package/dist/{project-DDTIVEMU.cjs.map → project-sS_ltoWz.cjs.map} +1 -1
  104. package/dist/prompt-files/index.cjs +3 -3
  105. package/dist/prompt-files/index.cjs.map +1 -1
  106. package/dist/prompt-files/index.js +1 -1
  107. package/dist/{promptSafety-Ctl7rOvA.cjs → promptSafety-BkFiS7El.cjs} +3 -3
  108. package/dist/{promptSafety-Ctl7rOvA.cjs.map → promptSafety-BkFiS7El.cjs.map} +1 -1
  109. package/dist/{promptSafety-B_Jbtlcb.js → promptSafety-Dp9Zga_t.js} +3 -3
  110. package/dist/{promptSafety-B_Jbtlcb.js.map → promptSafety-Dp9Zga_t.js.map} +1 -1
  111. package/dist/{relPath-CZiP2S_a.cjs → relPath-B-c9FUkm.cjs} +2 -2
  112. package/dist/{relPath-CZiP2S_a.cjs.map → relPath-B-c9FUkm.cjs.map} +1 -1
  113. package/dist/{relPath-BkKmqiiF.js → relPath-DV2ZrxF_.js} +1 -1
  114. package/dist/{relPath-BkKmqiiF.js.map → relPath-DV2ZrxF_.js.map} +1 -1
  115. package/dist/remote-host/index.cjs +1 -1
  116. package/dist/remote-host/index.js +1 -1
  117. package/dist/remote-host/server/index.cjs +4 -4
  118. package/dist/remote-host/server/index.cjs.map +1 -1
  119. package/dist/remote-host/server/index.js +4 -4
  120. package/dist/remote-host/server/index.js.map +1 -1
  121. package/dist/{remote-host-gvsvPRli.cjs → remote-host-B6r8BkA1.cjs} +2 -2
  122. package/dist/{remote-host-gvsvPRli.cjs.map → remote-host-B6r8BkA1.cjs.map} +1 -1
  123. package/dist/{remote-host-DyAlq52o.js → remote-host-BI_3SnK1.js} +2 -2
  124. package/dist/{remote-host-DyAlq52o.js.map → remote-host-BI_3SnK1.js.map} +1 -1
  125. package/dist/remote-view/index.cjs +2 -2
  126. package/dist/remote-view/index.js +2 -2
  127. package/dist/{rolldown-runtime-CmQyd0Gu.cjs → rolldown-runtime-C5rMTSut.cjs} +8 -6
  128. package/dist/{root-s0MUUMQU.js → root-DDMQu5hb.js} +1 -1
  129. package/dist/{root-s0MUUMQU.js.map → root-DDMQu5hb.js.map} +1 -1
  130. package/dist/{root-Ccgd3H5S.cjs → root-kKYFqEMf.cjs} +2 -2
  131. package/dist/{root-Ccgd3H5S.cjs.map → root-kKYFqEMf.cjs.map} +1 -1
  132. package/dist/runtime-plugins/index.cjs +104 -15
  133. package/dist/runtime-plugins/index.cjs.map +1 -1
  134. package/dist/runtime-plugins/index.d.ts +1 -0
  135. package/dist/runtime-plugins/index.js +99 -15
  136. package/dist/runtime-plugins/index.js.map +1 -1
  137. package/dist/runtime-plugins/ledgerLock.d.ts +16 -0
  138. package/dist/scheduler/index.cjs +5 -5
  139. package/dist/scheduler/index.js +4 -4
  140. package/dist/{server-B6usmOfY.cjs → server-BNmwQGcq.cjs} +15 -15
  141. package/dist/server-BNmwQGcq.cjs.map +1 -0
  142. package/dist/{server-CtghuxhH.js → server-BpCUehxP.js} +14 -14
  143. package/dist/{server-CtghuxhH.js.map → server-BpCUehxP.js.map} +1 -1
  144. package/dist/skill-bridge/index.cjs +3 -3
  145. package/dist/skill-bridge/index.cjs.map +1 -1
  146. package/dist/skill-bridge/index.js +2 -2
  147. package/dist/{slug-DVkuPjIv.cjs → slug-BRj6KEiN.cjs} +1 -1
  148. package/dist/{slug-DVkuPjIv.cjs.map → slug-BRj6KEiN.cjs.map} +1 -1
  149. package/dist/{slug-D24AYqCZ.js → slug-X5tnZoc-.js} +1 -1
  150. package/dist/{slug-D24AYqCZ.js.map → slug-X5tnZoc-.js.map} +1 -1
  151. package/dist/{templatePath-CB3wtVpe.js → templatePath-B5mHTFDX.js} +1 -1
  152. package/dist/{templatePath-CB3wtVpe.js.map → templatePath-B5mHTFDX.js.map} +1 -1
  153. package/dist/{templatePath-BIh7wqgS.cjs → templatePath-DSawCKNy.cjs} +1 -1
  154. package/dist/{templatePath-BIh7wqgS.cjs.map → templatePath-DSawCKNy.cjs.map} +1 -1
  155. package/dist/{text-BQAuwKVj.js → text-BpGv7qxC.js} +1 -1
  156. package/dist/{text-BQAuwKVj.js.map → text-BpGv7qxC.js.map} +1 -1
  157. package/dist/{text-BQiyo5R9.cjs → text-CPK6ABnv.cjs} +1 -1
  158. package/dist/{text-BQiyo5R9.cjs.map → text-CPK6ABnv.cjs.map} +1 -1
  159. package/dist/{types-DPycxnDf.cjs → types-Bmk0fWDr.cjs} +1 -1
  160. package/dist/{types-DPycxnDf.cjs.map → types-Bmk0fWDr.cjs.map} +1 -1
  161. package/dist/{types-BLCZTGW2.js → types-CuiYCIof.js} +1 -1
  162. package/dist/{types-BLCZTGW2.js.map → types-CuiYCIof.js.map} +1 -1
  163. package/dist/utils/index.cjs +3 -3
  164. package/dist/utils/index.js +3 -3
  165. package/dist/whisper/client.cjs.map +1 -1
  166. package/dist/whisper/client.js.map +1 -1
  167. package/dist/whisper/index.cjs +7 -7
  168. package/dist/whisper/index.cjs.map +1 -1
  169. package/dist/whisper/index.js +5 -5
  170. package/dist/wiki/index.cjs +3 -3
  171. package/dist/wiki/index.js +3 -3
  172. package/dist/wiki/paths.cjs +2 -2
  173. package/dist/wiki/paths.js +1 -1
  174. package/dist/wiki/server/index.cjs +7 -7
  175. package/dist/wiki/server/index.js +5 -5
  176. package/dist/{withinRoot-CheaBWt0.js → withinRoot-Dc756J5K.js} +2 -2
  177. package/dist/{withinRoot-CheaBWt0.js.map → withinRoot-Dc756J5K.js.map} +1 -1
  178. package/dist/{withinRoot-CHPN9eHD.cjs → withinRoot-OaOVCBHa.cjs} +2 -2
  179. package/dist/withinRoot-OaOVCBHa.cjs.map +1 -0
  180. package/dist/workspace-setup/index.js +2 -2
  181. package/dist/workspace-setup/index.js.map +1 -1
  182. package/package.json +5 -5
  183. package/dist/atomic-cqafMWEI.cjs.map +0 -1
  184. package/dist/discovery-D1cjgQRo.cjs.map +0 -1
  185. package/dist/discovery-c5OKO0dI.js.map +0 -1
  186. package/dist/dist--k7dcIzm.cjs.map +0 -1
  187. package/dist/dist-Cb-KNFRA.js.map +0 -1
  188. package/dist/errorMessage-BDEhi5qf.cjs +0 -1
  189. package/dist/errorMessage-BFkRmkyh.js +0 -1
  190. package/dist/server-B6usmOfY.cjs.map +0 -1
  191. package/dist/withinRoot-CHPN9eHD.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { c as isRecord$1 } from "./dist-Cb-KNFRA.js";
1
+ import { c as isRecord$1 } from "./dist-wmt60Ec-.js";
2
2
  // src/remote-host/health.ts
3
3
  var RUNNER_HEALTH_STATES = [
4
4
  "online",
@@ -111,4 +111,4 @@ var buildHostPresence = (channel, handlers, online, machine) => ({
111
111
  });
112
112
  export { coerceJsonObject as a, toJsonObject as c, isRunnerHealthState as d, byCreatedAt as i, RUNNER_HEALTH_STATES as l, REMOTE_HOST_PROTOCOL_VERSION as n, isExpired as o, buildHostPresence as r, readCommandScope as s, COMMAND_SCOPE_PARAM as t, isRunnerHealth as u };
113
113
 
114
- //# sourceMappingURL=remote-host-DyAlq52o.js.map
114
+ //# sourceMappingURL=remote-host-BI_3SnK1.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-host-DyAlq52o.js","names":["isRecord"],"sources":["../src/remote-host/health.ts","../src/remote-host/index.ts"],"sourcesContent":["// Health of the remote-host command channel, as reported by the resilient runner\n// and rendered by a host's toolbar control. Browser-safe on purpose: the client\n// narrows the parsed HTTP payload with the same guard the server writes it from,\n// so the two sides cannot drift on the state names.\n//\n// online — the Firestore subscription is up; the phone can reach this host\n// reconnecting — it died and is being re-subscribed with backoff (self-healing)\n// offline — re-subscribing stopped helping, or nothing is connected at all;\n// recovering needs a re-auth from the browser's parked session\n//\n// Deliberately no UI wording here — how a state reads to a user is each host's\n// i18n, and core owning it would make the shared package a translation authority.\nexport const RUNNER_HEALTH_STATES = [\"online\", \"reconnecting\", \"offline\"] as const;\nexport type RunnerHealthState = (typeof RUNNER_HEALTH_STATES)[number];\n\nexport interface RunnerHealth {\n state: RunnerHealthState;\n /** Last channel error seen, for the popover and the log. Null before the first one. */\n lastError: string | null;\n /** ms epoch of the last state change, so the UI can say how long it has been down. */\n changedAt: number;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null;\n\nexport const isRunnerHealthState = (value: unknown): value is RunnerHealthState => RUNNER_HEALTH_STATES.some((state) => state === value);\n\n/** Narrows a parsed HTTP payload. The client renders whatever this accepts, so a\n * half-shaped health has to read as \"no health reported\" rather than as a state. */\nexport const isRunnerHealth = (value: unknown): value is RunnerHealth =>\n isRecord(value) &&\n isRunnerHealthState(value.state) &&\n (value.lastError === null || typeof value.lastError === \"string\") &&\n typeof value.changedAt === \"number\";\n","// Remote-host command-channel protocol — the browser-safe contract shared by a\n// host (MulmoClaude, MulmoTerminal) and the remote/mobile client (mulmoserver).\n//\n// A host signs in to Firebase as the user, listens to that user's per-host\n// command queue in Firestore, runs a handler, and writes the result back; the\n// remote writes commands and reads results via a real-time listener. This module\n// owns the wire types + pure helpers, and must load without the Firebase SDK; the\n// Firestore path helpers live in `./server/paths.ts`. It is the single source of\n// truth so the host runner and the client never drift on the protocol.\n//\n// Ported from ../mulmoserver/src/firestore/commandChannel.ts and the per-host\n// copy that lived in MulmoClaude's server/remoteHost/. The hostId is\n// host-specific (\"mulmoclaude\", \"mulmoterminal\") and is supplied by each host.\nimport { isRecord } from \"@mulmoclaude/common\";\n\n// JSON payloads carried by the command channel. Explicit JSON types keep the\n// channel typed without resorting to any/unknown.\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\nexport type JsonObject = Record<string, JsonValue>;\n\n/** Structural JSON view of `T`, recursively.\n *\n * TypeScript gives an implicit index signature to type aliases and mapped\n * types but NOT to interfaces, so a payload assembled from domain interfaces\n * (`Shortcut`, `FeedSummary`, …) cannot satisfy `Record<string, JsonValue>`\n * structurally — even though it is plain JSON at runtime. Mapping over `T`\n * reconstructs it as an anonymous type, which does get that index signature.\n *\n * Recursive on purpose: a top-level-only map would still leave nested\n * interfaces (`{ shortcuts: Shortcut[] }`) unassignable, which is the case\n * every handler here actually has. */\n// The function branch must come BEFORE the object branch: a function IS an\n// object to TypeScript, so without it a function maps to `{}` and sails\n// through — the helper would accept a payload that serialises to nothing.\n// Verified: `toJsonObject({ callback: () => undefined })` compiled clean until\n// this branch existed (CodeRabbit, #2596).\nexport type Jsonify<T> = T extends JsonValue\n ? T\n : T extends (...args: never[]) => unknown\n ? never\n : T extends (infer U)[]\n ? Jsonify<U>[]\n : T extends object\n ? { [K in keyof T]: Jsonify<T[K]> }\n : never;\n\n/** Widen a JSON-shaped handler payload to the channel's `JsonObject`.\n *\n * Exists so the `Jsonify` reasoning above lives in ONE place. Before this,\n * eight remote-host handlers each carried their own `as unknown as JsonObject`\n * with the justification re-argued in eight slightly different comments —\n * which is how a rule stops being reviewable. */\nexport const toJsonObject = <T extends object>(payload: Jsonify<T>): JsonObject => payload as JsonObject;\n\nconst describeNonJson = (value: unknown): string => {\n if (typeof value === \"number\") return String(value);\n if (typeof value === \"object\") return \"a non-plain object\";\n return `a ${typeof value}`;\n};\n\n/** Anything carrying its own JSON form — `Date` above all — must be asked for\n * it rather than walked, because walking a `Date`'s own enumerable keys finds\n * none and flattens the timestamp to `{}`. This is the step `JSON.stringify`\n * performs before it recurses, and the channel used to get it for free. */\nconst hasToJson = (value: object): value is { toJSON: () => unknown } => \"toJSON\" in value && typeof value.toJSON === \"function\";\n\nconst jsonRepresentationOf = (value: object): unknown => (hasToJson(value) ? value.toJSON() : value);\n\n/** Rebuild `value` as JSON, or throw naming the property that cannot be. */\nfunction toJsonValue(value: unknown, path: string): JsonValue {\n if (Array.isArray(value)) return toJsonItems(value, path);\n if (isRecord(value)) {\n const represented = jsonRepresentationOf(value);\n if (represented !== value) return toJsonValue(represented, path);\n return toJsonEntries(value, path);\n }\n return toJsonScalar(value, path);\n}\n\n/** JSON's four scalar forms. Anything else — a function, a class instance, a\n * non-finite number — is what the channel cannot carry. */\nfunction toJsonScalar(value: unknown, path: string): JsonValue {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n throw new Error(`${path} is ${describeNonJson(value)}, which JSON cannot represent`);\n}\n\nfunction toJsonItems(items: unknown[], path: string): JsonValue[] {\n // An absent element becomes `null`, matching `JSON.stringify` — an array has\n // to keep its length, so a hole cannot simply be dropped the way a key is.\n // `Array.from` rather than `map`, which SKIPS holes and would leave them in\n // the result: `JSON.stringify` renders a hole as null and hides that, but\n // `1 in arr` / `Object.keys` / `forEach` all still see the gap.\n return Array.from(items, (entry, index) => (entry === undefined ? null : toJsonValue(entry, `${path}[${index}]`)));\n}\n\nfunction toJsonEntries(record: Record<string, unknown>, path: string): JsonObject {\n const usable = Object.entries(record).filter(([, value]) => value !== undefined);\n return Object.fromEntries(usable.map(([key, value]) => [key, toJsonValue(value, `${path}.${key}`)]));\n}\n\n/** Runtime counterpart to `toJsonObject`, for payloads whose values are typed\n * `unknown` — a collection record, a projected view row — so no amount of\n * mapped-type work can PROVE them JSON.\n *\n * Walks the payload and rebuilds it from the values it actually inspected, so\n * the returned `JsonObject` is earned rather than asserted. Absent (`undefined`)\n * properties are dropped exactly as `JSON.stringify` drops them; anything the\n * channel could not carry — a function, a class instance, `NaN` — throws\n * naming its path, instead of reaching Firestore as a silently mangled write. */\nexport const coerceJsonObject = (payload: Record<string, unknown>): JsonObject => toJsonEntries(payload, \"payload\");\n\n// A channel routes commands to one specific host. A host's first machine uses the\n// host's fixed id (\"mulmoclaude\", \"mulmoterminal\"); a host that runs on several\n// machines gives each later one \"<id>-<8 hex>\" (RemoteHostDeps.resolveHostId), and\n// the remote finds those by listing users/{uid}/hosts.\nexport interface Channel {\n uid: string;\n hostId: string;\n}\n\nexport type CommandStatus = \"queued\" | \"processing\" | \"done\" | \"error\";\n\nexport interface CommandError {\n code: string;\n message: string;\n}\n\n// One document in a channel's commands subcollection is one API-call-like\n// request. The remote (mobile) writes method/params; the host writes\n// result/error/status.\nexport interface Command {\n method: string;\n params: JsonObject;\n status: CommandStatus;\n result: JsonValue;\n error: CommandError | null;\n createdBy: \"remote\" | \"host\";\n // Offline-queue fields (all optional; absent ⇒ pre-offline-queue behaviour, so\n // this is backward-compatible with every deployed client). Epoch-millisecond\n // NUMBERS set by the remote at enqueue time — deliberately plain numbers, not\n // Firestore Timestamps, so `isExpired` / `byCreatedAt` stay pure + browser-safe\n // and unit-testable without a Firestore fake. Clock skew over a multi-day expiry\n // window is immaterial. See plans/done/feat-remote-offline-queue.md.\n createdAt?: number; // enqueue time — age/display + best-effort dispatch bias (NOT a strict order guarantee; chat is async)\n expiresAt?: number; // deadline; past it the host deletes the command + its staged attachments\n queuedOffline?: boolean; // emitted while the host was offline (gates the remote's attachment rollback)\n}\n\n// A command is expired once `now` reaches its remote-set deadline. Absent\n// `expiresAt` ⇒ it never expires (pre-offline-queue commands). Pure with an\n// injected `now` for deterministic tests; the runner passes `Date.now()`.\nexport const isExpired = (command: Pick<Command, \"expiresAt\">, now: number): boolean => typeof command.expiresAt === \"number\" && now >= command.expiresAt;\n\n// Best-effort dispatch bias for a drained batch: oldest enqueue first. This is\n// NOT an ordering guarantee — commands run concurrently and may complete out of\n// order (chat is asynchronous, by design); it only nudges which one starts first.\n// A command with no `createdAt` sorts as oldest (0) so it is never starved.\nexport const byCreatedAt = (left: Pick<Command, \"createdAt\">, right: Pick<Command, \"createdAt\">): number => (left.createdAt ?? 0) - (right.createdAt ?? 0);\n\nexport type CommandHandler = (params: JsonObject) => JsonValue | Promise<JsonValue>;\nexport type CommandHandlers = Record<string, CommandHandler>;\n\n/** The param name a collection-serving command uses to say WHICH project's\n * collections it means. Reserved and documented now, before a phone client\n * ships, because the parts that are hard to change later are the ones being\n * written today. Four rules go with it:\n *\n * 1. **It is an OPAQUE scope, never a path.** The phone is a genuinely remote\n * client; an absolute root in a command, an artifact or a token publishes\n * the user's home directory over the wire. Mint a project id host-side and\n * resolve it host-side.\n * 2. **The phone must be able to LEARN the list.** A picker needs\n * `{ id, label }` pairs from the host — a command of its own, or a field on\n * an existing listing. Designing the scope value now is what keeps that the\n * ONLY new thing when the feature lands.\n * 3. **Handlers RESOLVE a scope; they do not hard-code one.** Write each\n * collection handler as \"read the scope from params, defaulting to the\n * host's root\" rather than calling the workspace accessor inline. Today\n * every call resolves the default and behaves exactly as it does now; the\n * day the param arrives, no handler changes.\n * 4. **The artifact stays host-built.** A remote view's srcdoc, its inlined\n * image thumbnails and its token are assembled on the host, so the phone\n * never resolves a path itself. That is what makes (1) hold without\n * trusting the client. */\nexport const COMMAND_SCOPE_PARAM = \"project\";\n\n/** Read the opaque project scope off a command's params, or `undefined` for\n * \"the host's own root\" — which is what every command means today. A\n * non-string (or empty) value is treated as absent rather than as an error: a\n * scope the host cannot resolve must fall back to the default, never to a\n * guess. Hosts pass the result to their own id → root resolver; this module\n * deliberately never sees a path. */\nexport const readCommandScope = (params: JsonObject): string | undefined => {\n const raw = params[COMMAND_SCOPE_PARAM];\n return typeof raw === \"string\" && raw.trim().length > 0 ? raw.trim() : undefined;\n};\n\n// Bumped when the command-channel wire protocol changes in a way the remote must\n// gate on. Advertised in the presence doc so the remote can check compatibility\n// before issuing commands.\n//\n// v2: offline queueing. The host honours `expiresAt` (deletes an expired command\n// + its staged attachments instead of spawning a stale chat). A remote MUST see\n// protocolVersion >= 2 before queueing a startChat while the host is offline —\n// a v1 host silently ignores `expiresAt`, so a queued chat would spawn stale on\n// reconnect with its uploads never cleaned up.\nexport const REMOTE_HOST_PROTOCOL_VERSION = 2;\n\n// The presence doc's payload: online flag + a capability advertisement. Written\n// by the host on every heartbeat; the remote reads it from the presence listener\n// it already runs (no extra round trip, known the instant the host is online).\n// Browser-safe so the mobile client compiles against the same shape.\n// `updatedAt` (a Firestore serverTimestamp) is added by the runner at write time\n// and is intentionally not part of this capability contract.\n// Which machine a presence comes from, for a host that can run on several machines\n// under one account (mulmoterminal#3092): a stable id the host recognises itself by,\n// and the name the remote shows for it.\nexport interface HostMachine {\n machineId: string;\n label: string;\n}\n\nexport interface HostPresence {\n online: boolean;\n hostId: string;\n protocolVersion: number;\n // Method names the host serves — the keys of the live handler table.\n capabilities: string[];\n machineId?: string;\n label?: string;\n}\n\n// Build the presence payload from the live handler table. Capabilities are\n// `Object.keys(handlers)` so registering a handler is the ONLY step needed to\n// advertise it — there is no second list to keep in sync.\nexport const buildHostPresence = (channel: Channel, handlers: CommandHandlers, online: boolean, machine?: HostMachine): HostPresence => ({\n online,\n hostId: channel.hostId,\n protocolVersion: REMOTE_HOST_PROTOCOL_VERSION,\n capabilities: Object.keys(handlers),\n ...(machine ? { machineId: machine.machineId, label: machine.label } : {}),\n});\n\n// Channel health as the resilient runner reports it. Browser-safe alongside the\n// wire types because the control that renders it runs in the client.\nexport { RUNNER_HEALTH_STATES, isRunnerHealth, isRunnerHealthState } from \"./health.js\";\nexport type { RunnerHealth, RunnerHealthState } from \"./health.js\";\n"],"mappings":";;AAYA,IAAa,uBAAuB;CAAC;CAAU;CAAgB;AAAS;AAWxE,IAAM,YAAY,UAAqD,OAAO,UAAU,YAAY,UAAU;AAE9G,IAAa,uBAAuB,UAA+C,qBAAqB,MAAM,UAAU,UAAU,KAAK;;;AAIvI,IAAa,kBAAkB,UAC7B,SAAS,KAAK,KACd,oBAAoB,MAAM,KAAK,MAC9B,MAAM,cAAc,QAAQ,OAAO,MAAM,cAAc,aACxD,OAAO,MAAM,cAAc;;;;;;;;ACmB7B,IAAa,gBAAkC,YAAoC;AAEnF,IAAM,mBAAmB,UAA2B;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO,KAAK;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,KAAK,OAAO;AACrB;;;;;AAMA,IAAM,aAAa,UAAsD,YAAY,SAAS,OAAO,MAAM,WAAW;AAEtH,IAAM,wBAAwB,UAA4B,UAAU,KAAK,IAAI,MAAM,OAAO,IAAI;;AAG9F,SAAS,YAAY,OAAgB,MAAyB;CAC5D,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,YAAY,OAAO,IAAI;CACxD,IAAIA,WAAS,KAAK,GAAG;EACnB,MAAM,cAAc,qBAAqB,KAAK;EAC9C,IAAI,gBAAgB,OAAO,OAAO,YAAY,aAAa,IAAI;EAC/D,OAAO,cAAc,OAAO,IAAI;CAClC;CACA,OAAO,aAAa,OAAO,IAAI;AACjC;;;AAIA,SAAS,aAAa,OAAgB,MAAyB;CAC7D,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO;CACtF,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO;CAChE,MAAM,IAAI,MAAM,GAAG,KAAK,MAAM,gBAAgB,KAAK,EAAE,8BAA8B;AACrF;AAEA,SAAS,YAAY,OAAkB,MAA2B;CAMhE,OAAO,MAAM,KAAK,QAAQ,OAAO,UAAW,UAAU,KAAA,IAAY,OAAO,YAAY,OAAO,GAAG,KAAK,GAAG,MAAM,EAAE,CAAE;AACnH;AAEA,SAAS,cAAc,QAAiC,MAA0B;CAChF,MAAM,SAAS,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS;CAC/E,OAAO,OAAO,YAAY,OAAO,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;AACrG;;;;;;;;;;AAWA,IAAa,oBAAoB,YAAiD,cAAc,SAAS,SAAS;AA0ClH,IAAa,aAAa,SAAqC,QAAyB,OAAO,QAAQ,cAAc,YAAY,OAAO,QAAQ;AAMhJ,IAAa,eAAe,MAAkC,WAA+C,KAAK,aAAa,MAAM,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;AA2BxJ,IAAa,sBAAsB;;;;;;;AAQnC,IAAa,oBAAoB,WAA2C;CAC1E,MAAM,MAAM,OAAO;CACnB,OAAO,OAAO,QAAQ,YAAY,IAAI,KAAK,CAAC,CAAC,SAAS,IAAI,IAAI,KAAK,IAAI,KAAA;AACzE;AAWA,IAAa,+BAA+B;AA6B5C,IAAa,qBAAqB,SAAkB,UAA2B,QAAiB,aAAyC;CACvI;CACA,QAAQ,QAAQ;CAChB,iBAAA;CACA,cAAc,OAAO,KAAK,QAAQ;CAClC,GAAI,UAAU;EAAE,WAAW,QAAQ;EAAW,OAAO,QAAQ;CAAM,IAAI,CAAC;AAC1E"}
1
+ {"version":3,"file":"remote-host-BI_3SnK1.js","names":["isRecord"],"sources":["../src/remote-host/health.ts","../src/remote-host/index.ts"],"sourcesContent":["// Health of the remote-host command channel, as reported by the resilient runner\n// and rendered by a host's toolbar control. Browser-safe on purpose: the client\n// narrows the parsed HTTP payload with the same guard the server writes it from,\n// so the two sides cannot drift on the state names.\n//\n// online — the Firestore subscription is up; the phone can reach this host\n// reconnecting — it died and is being re-subscribed with backoff (self-healing)\n// offline — re-subscribing stopped helping, or nothing is connected at all;\n// recovering needs a re-auth from the browser's parked session\n//\n// Deliberately no UI wording here — how a state reads to a user is each host's\n// i18n, and core owning it would make the shared package a translation authority.\nexport const RUNNER_HEALTH_STATES = [\"online\", \"reconnecting\", \"offline\"] as const;\nexport type RunnerHealthState = (typeof RUNNER_HEALTH_STATES)[number];\n\nexport interface RunnerHealth {\n state: RunnerHealthState;\n /** Last channel error seen, for the popover and the log. Null before the first one. */\n lastError: string | null;\n /** ms epoch of the last state change, so the UI can say how long it has been down. */\n changedAt: number;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null;\n\nexport const isRunnerHealthState = (value: unknown): value is RunnerHealthState => RUNNER_HEALTH_STATES.some((state) => state === value);\n\n/** Narrows a parsed HTTP payload. The client renders whatever this accepts, so a\n * half-shaped health has to read as \"no health reported\" rather than as a state. */\nexport const isRunnerHealth = (value: unknown): value is RunnerHealth =>\n isRecord(value) &&\n isRunnerHealthState(value.state) &&\n (value.lastError === null || typeof value.lastError === \"string\") &&\n typeof value.changedAt === \"number\";\n","// Remote-host command-channel protocol — the browser-safe contract shared by a\n// host (MulmoClaude, MulmoTerminal) and the remote/mobile client (mulmoserver).\n//\n// A host signs in to Firebase as the user, listens to that user's per-host\n// command queue in Firestore, runs a handler, and writes the result back; the\n// remote writes commands and reads results via a real-time listener. This module\n// owns the wire types + pure helpers, and must load without the Firebase SDK; the\n// Firestore path helpers live in `./server/paths.ts`. It is the single source of\n// truth so the host runner and the client never drift on the protocol.\n//\n// Ported from ../mulmoserver/src/firestore/commandChannel.ts and the per-host\n// copy that lived in MulmoClaude's server/remoteHost/. The hostId is\n// host-specific (\"mulmoclaude\", \"mulmoterminal\") and is supplied by each host.\nimport { isRecord } from \"@mulmoclaude/common\";\n\n// JSON payloads carried by the command channel. Explicit JSON types keep the\n// channel typed without resorting to any/unknown.\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\nexport type JsonObject = Record<string, JsonValue>;\n\n/** Structural JSON view of `T`, recursively.\n *\n * TypeScript gives an implicit index signature to type aliases and mapped\n * types but NOT to interfaces, so a payload assembled from domain interfaces\n * (`Shortcut`, `FeedSummary`, …) cannot satisfy `Record<string, JsonValue>`\n * structurally — even though it is plain JSON at runtime. Mapping over `T`\n * reconstructs it as an anonymous type, which does get that index signature.\n *\n * Recursive on purpose: a top-level-only map would still leave nested\n * interfaces (`{ shortcuts: Shortcut[] }`) unassignable, which is the case\n * every handler here actually has. */\n// The function branch must come BEFORE the object branch: a function IS an\n// object to TypeScript, so without it a function maps to `{}` and sails\n// through — the helper would accept a payload that serialises to nothing.\n// Verified: `toJsonObject({ callback: () => undefined })` compiled clean until\n// this branch existed (CodeRabbit, #2596).\nexport type Jsonify<T> = T extends JsonValue\n ? T\n : T extends (...args: never[]) => unknown\n ? never\n : T extends (infer U)[]\n ? Jsonify<U>[]\n : T extends object\n ? { [K in keyof T]: Jsonify<T[K]> }\n : never;\n\n/** Widen a JSON-shaped handler payload to the channel's `JsonObject`.\n *\n * Exists so the `Jsonify` reasoning above lives in ONE place. Before this,\n * eight remote-host handlers each carried their own `as unknown as JsonObject`\n * with the justification re-argued in eight slightly different comments —\n * which is how a rule stops being reviewable. */\nexport const toJsonObject = <T extends object>(payload: Jsonify<T>): JsonObject => payload as JsonObject;\n\nconst describeNonJson = (value: unknown): string => {\n if (typeof value === \"number\") return String(value);\n if (typeof value === \"object\") return \"a non-plain object\";\n return `a ${typeof value}`;\n};\n\n/** Anything carrying its own JSON form — `Date` above all — must be asked for\n * it rather than walked, because walking a `Date`'s own enumerable keys finds\n * none and flattens the timestamp to `{}`. This is the step `JSON.stringify`\n * performs before it recurses, and the channel used to get it for free. */\nconst hasToJson = (value: object): value is { toJSON: () => unknown } => \"toJSON\" in value && typeof value.toJSON === \"function\";\n\nconst jsonRepresentationOf = (value: object): unknown => (hasToJson(value) ? value.toJSON() : value);\n\n/** Rebuild `value` as JSON, or throw naming the property that cannot be. */\nfunction toJsonValue(value: unknown, path: string): JsonValue {\n if (Array.isArray(value)) return toJsonItems(value, path);\n if (isRecord(value)) {\n const represented = jsonRepresentationOf(value);\n if (represented !== value) return toJsonValue(represented, path);\n return toJsonEntries(value, path);\n }\n return toJsonScalar(value, path);\n}\n\n/** JSON's four scalar forms. Anything else — a function, a class instance, a\n * non-finite number — is what the channel cannot carry. */\nfunction toJsonScalar(value: unknown, path: string): JsonValue {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n throw new Error(`${path} is ${describeNonJson(value)}, which JSON cannot represent`);\n}\n\nfunction toJsonItems(items: unknown[], path: string): JsonValue[] {\n // An absent element becomes `null`, matching `JSON.stringify` — an array has\n // to keep its length, so a hole cannot simply be dropped the way a key is.\n // `Array.from` rather than `map`, which SKIPS holes and would leave them in\n // the result: `JSON.stringify` renders a hole as null and hides that, but\n // `1 in arr` / `Object.keys` / `forEach` all still see the gap.\n return Array.from(items, (entry, index) => (entry === undefined ? null : toJsonValue(entry, `${path}[${index}]`)));\n}\n\nfunction toJsonEntries(record: Record<string, unknown>, path: string): JsonObject {\n const usable = Object.entries(record).filter(([, value]) => value !== undefined);\n return Object.fromEntries(usable.map(([key, value]) => [key, toJsonValue(value, `${path}.${key}`)]));\n}\n\n/** Runtime counterpart to `toJsonObject`, for payloads whose values are typed\n * `unknown` — a collection record, a projected view row — so no amount of\n * mapped-type work can PROVE them JSON.\n *\n * Walks the payload and rebuilds it from the values it actually inspected, so\n * the returned `JsonObject` is earned rather than asserted. Absent (`undefined`)\n * properties are dropped exactly as `JSON.stringify` drops them; anything the\n * channel could not carry — a function, a class instance, `NaN` — throws\n * naming its path, instead of reaching Firestore as a silently mangled write. */\nexport const coerceJsonObject = (payload: Record<string, unknown>): JsonObject => toJsonEntries(payload, \"payload\");\n\n// A channel routes commands to one specific host. A host's first machine uses the\n// host's fixed id (\"mulmoclaude\", \"mulmoterminal\"); a host that runs on several\n// machines gives each later one \"<id>-<8 hex>\" (RemoteHostDeps.resolveHostId), and\n// the remote finds those by listing users/{uid}/hosts.\nexport interface Channel {\n uid: string;\n hostId: string;\n}\n\nexport type CommandStatus = \"queued\" | \"processing\" | \"done\" | \"error\";\n\nexport interface CommandError {\n code: string;\n message: string;\n}\n\n// One document in a channel's commands subcollection is one API-call-like\n// request. The remote (mobile) writes method/params; the host writes\n// result/error/status.\nexport interface Command {\n method: string;\n params: JsonObject;\n status: CommandStatus;\n result: JsonValue;\n error: CommandError | null;\n createdBy: \"remote\" | \"host\";\n // Offline-queue fields (all optional; absent ⇒ pre-offline-queue behaviour, so\n // this is backward-compatible with every deployed client). Epoch-millisecond\n // NUMBERS set by the remote at enqueue time — deliberately plain numbers, not\n // Firestore Timestamps, so `isExpired` / `byCreatedAt` stay pure + browser-safe\n // and unit-testable without a Firestore fake. Clock skew over a multi-day expiry\n // window is immaterial. See plans/done/feat-remote-offline-queue.md.\n createdAt?: number; // enqueue time — age/display + best-effort dispatch bias (NOT a strict order guarantee; chat is async)\n expiresAt?: number; // deadline; past it the host deletes the command + its staged attachments\n queuedOffline?: boolean; // emitted while the host was offline (gates the remote's attachment rollback)\n}\n\n// A command is expired once `now` reaches its remote-set deadline. Absent\n// `expiresAt` ⇒ it never expires (pre-offline-queue commands). Pure with an\n// injected `now` for deterministic tests; the runner passes `Date.now()`.\nexport const isExpired = (command: Pick<Command, \"expiresAt\">, now: number): boolean => typeof command.expiresAt === \"number\" && now >= command.expiresAt;\n\n// Best-effort dispatch bias for a drained batch: oldest enqueue first. This is\n// NOT an ordering guarantee — commands run concurrently and may complete out of\n// order (chat is asynchronous, by design); it only nudges which one starts first.\n// A command with no `createdAt` sorts as oldest (0) so it is never starved.\nexport const byCreatedAt = (left: Pick<Command, \"createdAt\">, right: Pick<Command, \"createdAt\">): number => (left.createdAt ?? 0) - (right.createdAt ?? 0);\n\nexport type CommandHandler = (params: JsonObject) => JsonValue | Promise<JsonValue>;\nexport type CommandHandlers = Record<string, CommandHandler>;\n\n/** The param name a collection-serving command uses to say WHICH project's\n * collections it means. Reserved and documented now, before a phone client\n * ships, because the parts that are hard to change later are the ones being\n * written today. Four rules go with it:\n *\n * 1. **It is an OPAQUE scope, never a path.** The phone is a genuinely remote\n * client; an absolute root in a command, an artifact or a token publishes\n * the user's home directory over the wire. Mint a project id host-side and\n * resolve it host-side.\n * 2. **The phone must be able to LEARN the list.** A picker needs\n * `{ id, label }` pairs from the host — a command of its own, or a field on\n * an existing listing. Designing the scope value now is what keeps that the\n * ONLY new thing when the feature lands.\n * 3. **Handlers RESOLVE a scope; they do not hard-code one.** Write each\n * collection handler as \"read the scope from params, defaulting to the\n * host's root\" rather than calling the workspace accessor inline. Today\n * every call resolves the default and behaves exactly as it does now; the\n * day the param arrives, no handler changes.\n * 4. **The artifact stays host-built.** A remote view's srcdoc, its inlined\n * image thumbnails and its token are assembled on the host, so the phone\n * never resolves a path itself. That is what makes (1) hold without\n * trusting the client. */\nexport const COMMAND_SCOPE_PARAM = \"project\";\n\n/** Read the opaque project scope off a command's params, or `undefined` for\n * \"the host's own root\" — which is what every command means today. A\n * non-string (or empty) value is treated as absent rather than as an error: a\n * scope the host cannot resolve must fall back to the default, never to a\n * guess. Hosts pass the result to their own id → root resolver; this module\n * deliberately never sees a path. */\nexport const readCommandScope = (params: JsonObject): string | undefined => {\n const raw = params[COMMAND_SCOPE_PARAM];\n return typeof raw === \"string\" && raw.trim().length > 0 ? raw.trim() : undefined;\n};\n\n// Bumped when the command-channel wire protocol changes in a way the remote must\n// gate on. Advertised in the presence doc so the remote can check compatibility\n// before issuing commands.\n//\n// v2: offline queueing. The host honours `expiresAt` (deletes an expired command\n// + its staged attachments instead of spawning a stale chat). A remote MUST see\n// protocolVersion >= 2 before queueing a startChat while the host is offline —\n// a v1 host silently ignores `expiresAt`, so a queued chat would spawn stale on\n// reconnect with its uploads never cleaned up.\nexport const REMOTE_HOST_PROTOCOL_VERSION = 2;\n\n// The presence doc's payload: online flag + a capability advertisement. Written\n// by the host on every heartbeat; the remote reads it from the presence listener\n// it already runs (no extra round trip, known the instant the host is online).\n// Browser-safe so the mobile client compiles against the same shape.\n// `updatedAt` (a Firestore serverTimestamp) is added by the runner at write time\n// and is intentionally not part of this capability contract.\n// Which machine a presence comes from, for a host that can run on several machines\n// under one account (mulmoterminal#3092): a stable id the host recognises itself by,\n// and the name the remote shows for it.\nexport interface HostMachine {\n machineId: string;\n label: string;\n}\n\nexport interface HostPresence {\n online: boolean;\n hostId: string;\n protocolVersion: number;\n // Method names the host serves — the keys of the live handler table.\n capabilities: string[];\n machineId?: string;\n label?: string;\n}\n\n// Build the presence payload from the live handler table. Capabilities are\n// `Object.keys(handlers)` so registering a handler is the ONLY step needed to\n// advertise it — there is no second list to keep in sync.\nexport const buildHostPresence = (channel: Channel, handlers: CommandHandlers, online: boolean, machine?: HostMachine): HostPresence => ({\n online,\n hostId: channel.hostId,\n protocolVersion: REMOTE_HOST_PROTOCOL_VERSION,\n capabilities: Object.keys(handlers),\n ...(machine ? { machineId: machine.machineId, label: machine.label } : {}),\n});\n\n// Channel health as the resilient runner reports it. Browser-safe alongside the\n// wire types because the control that renders it runs in the client.\nexport { RUNNER_HEALTH_STATES, isRunnerHealth, isRunnerHealthState } from \"./health.js\";\nexport type { RunnerHealth, RunnerHealthState } from \"./health.js\";\n"],"mappings":";;AAYA,IAAa,uBAAuB;CAAC;CAAU;CAAgB;AAAS;AAWxE,IAAM,YAAY,UAAqD,OAAO,UAAU,YAAY,UAAU;AAE9G,IAAa,uBAAuB,UAA+C,qBAAqB,MAAM,UAAU,UAAU,KAAK;;;AAIvI,IAAa,kBAAkB,UAC7B,SAAS,KAAK,KACd,oBAAoB,MAAM,KAAK,MAC9B,MAAM,cAAc,QAAQ,OAAO,MAAM,cAAc,aACxD,OAAO,MAAM,cAAc;;;;;;;;ACmB7B,IAAa,gBAAkC,YAAoC;AAEnF,IAAM,mBAAmB,UAA2B;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO,OAAO,KAAK;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,KAAK,OAAO;AACrB;;;;;AAMA,IAAM,aAAa,UAAsD,YAAY,SAAS,OAAO,MAAM,WAAW;AAEtH,IAAM,wBAAwB,UAA4B,UAAU,KAAK,IAAI,MAAM,OAAO,IAAI;;AAG9F,SAAS,YAAY,OAAgB,MAAyB;CAC5D,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,YAAY,OAAO,IAAI;CACxD,IAAIA,WAAS,KAAK,GAAG;EACnB,MAAM,cAAc,qBAAqB,KAAK;EAC9C,IAAI,gBAAgB,OAAO,OAAO,YAAY,aAAa,IAAI;EAC/D,OAAO,cAAc,OAAO,IAAI;CAClC;CACA,OAAO,aAAa,OAAO,IAAI;AACjC;;;AAIA,SAAS,aAAa,OAAgB,MAAyB;CAC7D,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO;CACtF,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO;CAChE,MAAM,IAAI,MAAM,GAAG,KAAK,MAAM,gBAAgB,KAAK,EAAE,8BAA8B;AACrF;AAEA,SAAS,YAAY,OAAkB,MAA2B;CAMhE,OAAO,MAAM,KAAK,QAAQ,OAAO,UAAW,UAAU,KAAA,IAAY,OAAO,YAAY,OAAO,GAAG,KAAK,GAAG,MAAM,EAAE,CAAE;AACnH;AAEA,SAAS,cAAc,QAAiC,MAA0B;CAChF,MAAM,SAAS,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS;CAC/E,OAAO,OAAO,YAAY,OAAO,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;AACrG;;;;;;;;;;AAWA,IAAa,oBAAoB,YAAiD,cAAc,SAAS,SAAS;AA0ClH,IAAa,aAAa,SAAqC,QAAyB,OAAO,QAAQ,cAAc,YAAY,OAAO,QAAQ;AAMhJ,IAAa,eAAe,MAAkC,WAA+C,KAAK,aAAa,MAAM,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;AA2BxJ,IAAa,sBAAsB;;;;;;;AAQnC,IAAa,oBAAoB,WAA2C;CAC1E,MAAM,MAAM,OAAO;CACnB,OAAO,OAAO,QAAQ,YAAY,IAAI,KAAK,CAAC,CAAC,SAAS,IAAI,IAAI,KAAK,IAAI,KAAA;AACzE;AAWA,IAAa,+BAA+B;AA6B5C,IAAa,qBAAqB,SAAkB,UAA2B,QAAiB,aAAyC;CACvI;CACA,QAAQ,QAAQ;CAChB,iBAAA;CACA,cAAc,OAAO,KAAK,QAAQ;CAClC,GAAI,UAAU;EAAE,WAAW,QAAQ;EAAW,OAAO,QAAQ;CAAM,IAAI,CAAC;AAC1E"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("../dist--k7dcIzm.cjs");
3
- const require_project = require("../project-DDTIVEMU.cjs");
2
+ const require_dist = require("../dist-DK0zTPR1.cjs");
3
+ const require_project = require("../project-sS_ltoWz.cjs");
4
4
  // src/remote-view/index.ts
5
5
  /** Bump when the bootstrap/message contract changes shape; the bootstrap
6
6
  * exposes it as `__MC_VIEW.protocol` so a parent can refuse a stale view.
@@ -1,5 +1,5 @@
1
- import { c as isRecord } from "../dist-Cb-KNFRA.js";
2
- import { n as projectRecordFields } from "../project-mU6-xLfy.js";
1
+ import { c as isRecord } from "../dist-wmt60Ec-.js";
2
+ import { n as projectRecordFields } from "../project-CSx7gqgs.js";
3
3
  // src/remote-view/index.ts
4
4
  /** Bump when the bootstrap/message contract changes shape; the bootstrap
5
5
  * exposes it as `__MC_VIEW.protocol` so a parent can refuse a stale view.
@@ -6,12 +6,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
11
+ desc = __getOwnPropDesc(from, key);
12
+ __defProp(to, key, {
13
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
14
+ enumerable: !desc || desc.enumerable
15
+ });
16
+ }
15
17
  }
16
18
  return to;
17
19
  };
@@ -19,4 +19,4 @@ function canonicalRoot(root) {
19
19
  }
20
20
  export { canonicalRoot as t };
21
21
 
22
- //# sourceMappingURL=root-s0MUUMQU.js.map
22
+ //# sourceMappingURL=root-DDMQu5hb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"root-s0MUUMQU.js","names":[],"sources":["../src/files/root.ts"],"sourcesContent":["// The canonical form of a workspace / project root.\n//\n// Lives here rather than in the collection engine because a root is an IDENTITY\n// in several subsystems that do not depend on each other — a watcher generation\n// key, a change payload, a completion-bell id, a scheduled task id — and every\n// one of them has to agree on it or the same project registers twice.\n\nimport path from \"node:path\";\n\n/** The canonical form of a root, for every place a root becomes an IDENTITY\n * rather than a path to read.\n *\n * `path.resolve` only — it collapses `.`/`..` and the trailing separator, so\n * `/work/project` and `/work/project/` are one root instead of two watcher\n * generations over the same tree, two bells per record, and two scheduled\n * refresh jobs.\n *\n * Deliberately NOT `realpath`. Resolving symlinks is async (so it could not run\n * on a synchronous claim path), it fails for a root that does not exist yet,\n * and it would put a path the host never named into an id that is written to\n * disk. The policy is therefore lexical: a host that hands the same tree under\n * two different symlink spellings gets two roots, and it is the host's job to\n * name a project the same way every time. */\nexport function canonicalRoot(root: string): string {\n return path.resolve(root);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAAK,QAAQ,IAAI;AAC1B"}
1
+ {"version":3,"file":"root-DDMQu5hb.js","names":[],"sources":["../src/files/root.ts"],"sourcesContent":["// The canonical form of a workspace / project root.\n//\n// Lives here rather than in the collection engine because a root is an IDENTITY\n// in several subsystems that do not depend on each other — a watcher generation\n// key, a change payload, a completion-bell id, a scheduled task id — and every\n// one of them has to agree on it or the same project registers twice.\n\nimport path from \"node:path\";\n\n/** The canonical form of a root, for every place a root becomes an IDENTITY\n * rather than a path to read.\n *\n * `path.resolve` only — it collapses `.`/`..` and the trailing separator, so\n * `/work/project` and `/work/project/` are one root instead of two watcher\n * generations over the same tree, two bells per record, and two scheduled\n * refresh jobs.\n *\n * Deliberately NOT `realpath`. Resolving symlinks is async (so it could not run\n * on a synchronous claim path), it fails for a root that does not exist yet,\n * and it would put a path the host never named into an id that is written to\n * disk. The policy is therefore lexical: a host that hands the same tree under\n * two different symlink spellings gets two roots, and it is the host's job to\n * name a project the same way every time. */\nexport function canonicalRoot(root: string): string {\n return path.resolve(root);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAAK,QAAQ,IAAI;AAC1B"}
@@ -1,4 +1,4 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C5rMTSut.cjs");
2
2
  let node_path = require("node:path");
3
3
  node_path = require_rolldown_runtime.__toESM(node_path, 1);
4
4
  // src/files/root.ts
@@ -26,4 +26,4 @@ Object.defineProperty(exports, "canonicalRoot", {
26
26
  }
27
27
  });
28
28
 
29
- //# sourceMappingURL=root-Ccgd3H5S.cjs.map
29
+ //# sourceMappingURL=root-kKYFqEMf.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"root-Ccgd3H5S.cjs","names":["path"],"sources":["../src/files/root.ts"],"sourcesContent":["// The canonical form of a workspace / project root.\n//\n// Lives here rather than in the collection engine because a root is an IDENTITY\n// in several subsystems that do not depend on each other — a watcher generation\n// key, a change payload, a completion-bell id, a scheduled task id — and every\n// one of them has to agree on it or the same project registers twice.\n\nimport path from \"node:path\";\n\n/** The canonical form of a root, for every place a root becomes an IDENTITY\n * rather than a path to read.\n *\n * `path.resolve` only — it collapses `.`/`..` and the trailing separator, so\n * `/work/project` and `/work/project/` are one root instead of two watcher\n * generations over the same tree, two bells per record, and two scheduled\n * refresh jobs.\n *\n * Deliberately NOT `realpath`. Resolving symlinks is async (so it could not run\n * on a synchronous claim path), it fails for a root that does not exist yet,\n * and it would put a path the host never named into an id that is written to\n * disk. The policy is therefore lexical: a host that hands the same tree under\n * two different symlink spellings gets two roots, and it is the host's job to\n * name a project the same way every time. */\nexport function canonicalRoot(root: string): string {\n return path.resolve(root);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc,MAAsB;CAClD,OAAOA,UAAAA,QAAK,QAAQ,IAAI;AAC1B"}
1
+ {"version":3,"file":"root-kKYFqEMf.cjs","names":["path"],"sources":["../src/files/root.ts"],"sourcesContent":["// The canonical form of a workspace / project root.\n//\n// Lives here rather than in the collection engine because a root is an IDENTITY\n// in several subsystems that do not depend on each other — a watcher generation\n// key, a change payload, a completion-bell id, a scheduled task id — and every\n// one of them has to agree on it or the same project registers twice.\n\nimport path from \"node:path\";\n\n/** The canonical form of a root, for every place a root becomes an IDENTITY\n * rather than a path to read.\n *\n * `path.resolve` only — it collapses `.`/`..` and the trailing separator, so\n * `/work/project` and `/work/project/` are one root instead of two watcher\n * generations over the same tree, two bells per record, and two scheduled\n * refresh jobs.\n *\n * Deliberately NOT `realpath`. Resolving symlinks is async (so it could not run\n * on a synchronous claim path), it fails for a root that does not exist yet,\n * and it would put a path the host never named into an id that is written to\n * disk. The policy is therefore lexical: a host that hands the same tree under\n * two different symlink spellings gets two roots, and it is the host's job to\n * name a project the same way every time. */\nexport function canonicalRoot(root: string): string {\n return path.resolve(root);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc,MAAsB;CAClD,OAAOA,UAAAA,QAAK,QAAQ,IAAI;AAC1B"}
@@ -1,18 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("../rolldown-runtime-CmQyd0Gu.cjs");
3
- const require_dist = require("../dist--k7dcIzm.cjs");
4
- const require_containment = require("../containment-Dc3gO4wD.cjs");
5
- const require_json = require("../json-BGdV2cz6.cjs");
6
- const require_atomic = require("../atomic-cqafMWEI.cjs");
7
- let gui_chat_protocol = require("gui-chat-protocol");
2
+ const require_rolldown_runtime = require("../rolldown-runtime-C5rMTSut.cjs");
3
+ const require_dist = require("../dist-DK0zTPR1.cjs");
8
4
  let node_fs = require("node:fs");
5
+ let node_child_process = require("node:child_process");
9
6
  let node_path = require("node:path");
10
- node_path = require_rolldown_runtime.__toESM(node_path, 1);
11
7
  let node_crypto = require("node:crypto");
12
- let node_fs_promises = require("node:fs/promises");
13
- let node_child_process = require("node:child_process");
14
8
  let node_url = require("node:url");
9
+ let gui_chat_protocol = require("gui-chat-protocol");
10
+ const require_containment = require("../containment-NZYJbiaa.cjs");
11
+ let node_fs_promises = require("node:fs/promises");
12
+ const require_json = require("../json-CWiVjlka.cjs");
15
13
  let node_zlib = require("node:zlib");
14
+ const require_atomic = require("../atomic-bzFw4-ix.cjs");
15
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
16
16
  // src/runtime-plugins/ledger.ts
17
17
  var hasValidSource = (value) => !Object.hasOwn(value, "source") || typeof value.source === "string";
18
18
  var isLedgerEntry = (value) => require_dist.hasStringProp(value, "name") && require_dist.hasStringProp(value, "version") && require_dist.hasStringProp(value, "tgz") && require_dist.hasStringProp(value, "installedAt") && hasValidSource(value);
@@ -695,6 +695,71 @@ async function readLedgerForWrite(ledgerPath) {
695
695
  } : parseLedgerText(ledgerPath, read.text);
696
696
  }
697
697
  var writeLedger = (ledgerPath, raw) => require_json.writeJsonAtomic(ledgerPath, raw);
698
+ // src/runtime-plugins/ledgerLock.ts
699
+ /** How long a writer waits for another to finish before giving up. */
700
+ var LEDGER_LOCK_WAIT_MS = 1e4;
701
+ var LEDGER_LOCK_RETRY_MS = 50;
702
+ var LedgerBusyError = class extends Error {};
703
+ var ledgerLockPath = (ledgerPath) => `${ledgerPath}.lock`;
704
+ var hasCode = (err, code) => require_dist.isRecord(err) && err.code === code;
705
+ /** Creates the lock holding `token`; false when another writer holds it. A failed write leaves no lock. */
706
+ async function tryCreate(lockPath, token) {
707
+ const opened = await (0, node_fs_promises.open)(lockPath, "wx").catch((err) => {
708
+ if (hasCode(err, "EEXIST")) return null;
709
+ throw err;
710
+ });
711
+ if (opened === null) return false;
712
+ try {
713
+ await opened.writeFile(token);
714
+ } catch (err) {
715
+ await opened.close().catch(() => void 0);
716
+ await (0, node_fs_promises.rm)(lockPath, { force: true });
717
+ throw err;
718
+ }
719
+ await opened.close();
720
+ return true;
721
+ }
722
+ /** Removes the lock only while it still carries `token`: if someone removed it by hand, it is not ours. */
723
+ async function release(lockPath, token) {
724
+ const held = await (0, node_fs_promises.readFile)(lockPath).catch(() => null);
725
+ const ours = Buffer.from(token);
726
+ if (held !== null && held.length === ours.length && (0, node_crypto.timingSafeEqual)(held, ours)) await (0, node_fs_promises.rm)(lockPath, { force: true });
727
+ }
728
+ /** `kill(pid, 0)` sends nothing: ESRCH means no such process, EPERM means one we may not signal. */
729
+ function processIsRunning(pid) {
730
+ try {
731
+ process.kill(pid, 0);
732
+ return true;
733
+ } catch (err) {
734
+ return hasCode(err, "EPERM");
735
+ }
736
+ }
737
+ var PID_PREFIX = /^(\d+) /;
738
+ async function busyError(lockPath, ledgerPath, isRunning) {
739
+ const held = await (0, node_fs_promises.readFile)(lockPath, "utf-8").catch(() => "");
740
+ const pid = Number(PID_PREFIX.exec(held)?.[1] ?? NaN);
741
+ if (Number.isInteger(pid) && pid > 0 && !isRunning(pid)) return new LedgerBusyError(`${lockPath} was left by a writer that is no longer running (pid ${pid}); remove it and try again`);
742
+ return new LedgerBusyError(`another install or removal is editing ${ledgerPath}; try again when it finishes`);
743
+ }
744
+ var defaultSleep = (delayMs) => new Promise((resolve) => setTimeout(resolve, delayMs));
745
+ /** Runs `work` holding the ledger's lock; throws LedgerBusyError when another writer keeps it past the wait. */
746
+ async function withLedgerLock(ledgerPath, work, deps = {}) {
747
+ const now = deps.now ?? Date.now;
748
+ const sleep = deps.sleep ?? defaultSleep;
749
+ const lockPath = ledgerLockPath(ledgerPath);
750
+ const token = `${process.pid} ${(0, node_crypto.randomUUID)()}\n`;
751
+ await (0, node_fs_promises.mkdir)(node_path.default.dirname(lockPath), { recursive: true });
752
+ const deadline = now() + (deps.waitMs ?? 1e4);
753
+ while (!await tryCreate(lockPath, token)) {
754
+ if (now() >= deadline) throw await busyError(lockPath, ledgerPath, deps.isRunning ?? processIsRunning);
755
+ await sleep(LEDGER_LOCK_RETRY_MS);
756
+ }
757
+ try {
758
+ return await work();
759
+ } finally {
760
+ await release(lockPath, token);
761
+ }
762
+ }
698
763
  // src/runtime-plugins/download.ts
699
764
  var DownloadError = class extends Error {};
700
765
  async function readCapped(body, url, maxBytes, signal) {
@@ -1088,8 +1153,7 @@ async function preparePlan(source, deps) {
1088
1153
  tgz,
1089
1154
  replaces
1090
1155
  },
1091
- bytes: fetched.bytes,
1092
- raw: ledger.raw
1156
+ bytes: fetched.bytes
1093
1157
  };
1094
1158
  }
1095
1159
  async function writePackageFile(plan, bytes, pluginsDir) {
@@ -1102,7 +1166,20 @@ async function writePackageFile(plan, bytes, pluginsDir) {
1102
1166
  fileWasThere
1103
1167
  };
1104
1168
  }
1105
- async function commit(plan, bytes, raw, deps) {
1169
+ var sameEntry = (left, right) => left === null || right === null ? left === right : left.version === right.version && left.tgz === right.tgz && left.installedAt === right.installedAt && (left.source ?? null) === (right.source ?? null);
1170
+ /** The ledger as it is now, under the lock, refused when the entry this install replaces is no longer
1171
+ * the one the plan showed: another writer installed or removed it while this one downloaded. */
1172
+ async function currentLedger(plan, deps) {
1173
+ const ledger = await readLedgerForWrite(deps.paths.ledgerPath);
1174
+ if (!ledger.ok) throw new InstallError(ledger.error);
1175
+ if (!sameEntry(parseLedger(ledger.raw).find((entry) => entry.name === plan.name) ?? null, plan.replaces)) throw new InstallError(`${plan.name} changed in the ledger while this install ran; check it again`);
1176
+ return ledger.raw;
1177
+ }
1178
+ async function commit(plan, bytes, deps) {
1179
+ return withLedgerLock(deps.paths.ledgerPath, () => commitLocked(plan, bytes, deps));
1180
+ }
1181
+ async function commitLocked(plan, bytes, deps) {
1182
+ const raw = await currentLedger(plan, deps);
1106
1183
  const { tgzPath, fileWasThere } = await writePackageFile(plan, bytes, deps.paths.pluginsDir);
1107
1184
  const installedAt = (deps.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
1108
1185
  const entry = {
@@ -1121,7 +1198,7 @@ async function commit(plan, bytes, raw, deps) {
1121
1198
  return entry;
1122
1199
  }
1123
1200
  var failure = (err, action) => {
1124
- if (err instanceof InstallError || err instanceof DownloadError) return {
1201
+ if (err instanceof InstallError || err instanceof DownloadError || err instanceof LedgerBusyError) return {
1125
1202
  status: "failed",
1126
1203
  error: err.message
1127
1204
  };
@@ -1138,14 +1215,14 @@ async function installRuntimePlugin(input, deps) {
1138
1215
  error: parsed.error
1139
1216
  };
1140
1217
  try {
1141
- const { plan, bytes, raw } = await preparePlan(parsed.source, deps);
1218
+ const { plan, bytes } = await preparePlan(parsed.source, deps);
1142
1219
  if (!await deps.confirm(plan)) return {
1143
1220
  status: "cancelled",
1144
1221
  plan
1145
1222
  };
1146
1223
  return {
1147
1224
  status: "installed",
1148
- entry: await commit(plan, bytes, raw, deps),
1225
+ entry: await commit(plan, bytes, deps),
1149
1226
  replaced: plan.replaces
1150
1227
  };
1151
1228
  } catch (err) {
@@ -1154,6 +1231,13 @@ async function installRuntimePlugin(input, deps) {
1154
1231
  }
1155
1232
  /** Take `name` out of the ledger. Its package file, unpacked copy and data folders are left in place. */
1156
1233
  async function uninstallRuntimePlugin(name, paths) {
1234
+ try {
1235
+ return await withLedgerLock(paths.ledgerPath, () => removeFromLedger(name, paths));
1236
+ } catch (err) {
1237
+ return failure(err, "uninstall");
1238
+ }
1239
+ }
1240
+ async function removeFromLedger(name, paths) {
1157
1241
  const ledger = await readLedgerForWrite(paths.ledgerPath);
1158
1242
  if (!ledger.ok) return {
1159
1243
  status: "failed",
@@ -1175,6 +1259,8 @@ async function uninstallRuntimePlugin(name, paths) {
1175
1259
  exports.DownloadError = DownloadError;
1176
1260
  exports.EXTRACT_MARKER = EXTRACT_MARKER;
1177
1261
  exports.GITHUB_API = GITHUB_API;
1262
+ exports.LEDGER_LOCK_WAIT_MS = LEDGER_LOCK_WAIT_MS;
1263
+ exports.LedgerBusyError = LedgerBusyError;
1178
1264
  exports.NPM_REGISTRY = NPM_REGISTRY;
1179
1265
  exports.downloadBytes = downloadBytes;
1180
1266
  exports.downloadJson = downloadJson;
@@ -1189,6 +1275,7 @@ exports.isExactVersion = isExactVersion;
1189
1275
  exports.isLedgerEntry = isLedgerEntry;
1190
1276
  exports.isNpmPackageName = isNpmPackageName;
1191
1277
  exports.isNpmVersionSpec = isNpmVersionSpec;
1278
+ exports.ledgerLockPath = ledgerLockPath;
1192
1279
  exports.linkLeadingOut = linkLeadingOut;
1193
1280
  exports.loadPluginFromCacheDir = loadPluginFromCacheDir;
1194
1281
  exports.matchesIntegrity = matchesIntegrity;
@@ -1196,6 +1283,7 @@ exports.packageFileName = packageFileName;
1196
1283
  exports.parseInstallSource = parseInstallSource;
1197
1284
  exports.parseLedger = parseLedger;
1198
1285
  exports.prepareLedgerEntry = prepareLedgerEntry;
1286
+ exports.processIsRunning = processIsRunning;
1199
1287
  exports.readLedgerForWrite = readLedgerForWrite;
1200
1288
  exports.resolveEntrySpecifier = resolveEntrySpecifier;
1201
1289
  exports.resolveExecute = resolveExecute;
@@ -1208,6 +1296,7 @@ exports.uninstallRuntimePlugin = uninstallRuntimePlugin;
1208
1296
  exports.verifyGithubBytes = verifyGithubBytes;
1209
1297
  exports.verifyNpmBytes = verifyNpmBytes;
1210
1298
  exports.withLedgerEntry = withLedgerEntry;
1299
+ exports.withLedgerLock = withLedgerLock;
1211
1300
  exports.withoutLedgerEntry = withoutLedgerEntry;
1212
1301
  exports.writeLedger = writeLedger;
1213
1302