@mulmoclaude/core 7.4.0 → 7.6.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.
- package/dist/{root-CqxPNSyK.js → atomic-C3NMg6-j.js} +2 -20
- package/dist/atomic-C3NMg6-j.js.map +1 -0
- package/dist/{root-9lRFeXbm.cjs → atomic-cqafMWEI.cjs} +1 -25
- package/dist/atomic-cqafMWEI.cjs.map +1 -0
- package/dist/collection/index.cjs +3 -3
- package/dist/collection/index.js +3 -3
- package/dist/collection/registry/server/index.cjs +5 -5
- package/dist/collection/registry/server/index.cjs.map +1 -1
- package/dist/collection/registry/server/index.js +4 -4
- package/dist/collection/server/index.cjs +3 -3
- package/dist/collection/server/index.js +3 -3
- package/dist/collection-watchers/index.cjs +5 -5
- package/dist/collection-watchers/index.js +5 -5
- package/dist/{discovery-DxmMcpFo.cjs → discovery-BSvWBOGB.cjs} +7 -6
- package/dist/discovery-BSvWBOGB.cjs.map +1 -0
- package/dist/{discovery-RyuhNKjx.js → discovery-DEhLlDVW.js} +6 -5
- package/dist/discovery-DEhLlDVW.js.map +1 -0
- package/dist/{dist-BmO4oSQy.js → dist--searOB5.js} +2 -2
- package/dist/dist--searOB5.js.map +1 -0
- package/dist/{dist-734JaRYi.cjs → dist-CdSEjlVx.cjs} +2 -2
- package/dist/dist-CdSEjlVx.cjs.map +1 -0
- package/dist/errorMessage-B-iVKe5R.cjs +1 -0
- package/dist/errorMessage-D-HWCI2W.js +1 -0
- package/dist/{errors-B9mCEVG9.cjs → errors-B7ShVbIB.cjs} +2 -2
- package/dist/{errors-B9mCEVG9.cjs.map → errors-B7ShVbIB.cjs.map} +1 -1
- package/dist/{errors-0QwjDxsv.js → errors-BbH5CeKm.js} +2 -2
- package/dist/{errors-0QwjDxsv.js.map → errors-BbH5CeKm.js.map} +1 -1
- package/dist/feeds/server/index.cjs +6 -6
- package/dist/feeds/server/index.cjs.map +1 -1
- package/dist/feeds/server/index.js +6 -6
- package/dist/feeds/server/index.js.map +1 -1
- package/dist/files/index.cjs +8 -13
- package/dist/files/index.cjs.map +1 -1
- package/dist/files/index.js +3 -8
- package/dist/files/index.js.map +1 -1
- package/dist/google/index.cjs +5 -5
- package/dist/google/index.cjs.map +1 -1
- package/dist/google/index.js +4 -4
- package/dist/json-BGdV2cz6.cjs +16 -0
- package/dist/json-BGdV2cz6.cjs.map +1 -0
- package/dist/json-BizOSThv.js +11 -0
- package/dist/json-BizOSThv.js.map +1 -0
- package/dist/{listen-uiEnXcW9.js → listen-Bm8N0g9o.js} +2 -2
- package/dist/{listen-uiEnXcW9.js.map → listen-Bm8N0g9o.js.map} +1 -1
- package/dist/{listen-OmfLDX1l.cjs → listen-OGOFPIdk.cjs} +2 -2
- package/dist/{listen-OmfLDX1l.cjs.map → listen-OGOFPIdk.cjs.map} +1 -1
- package/dist/notifier/index.cjs +1 -1
- package/dist/notifier/index.js +1 -1
- package/dist/{notifier-CRTk34EC.cjs → notifier-8R05SHLj.cjs} +2 -2
- package/dist/{notifier-CRTk34EC.cjs.map → notifier-8R05SHLj.cjs.map} +1 -1
- package/dist/{notifier-htdf4ekH.js → notifier-D7TmVus0.js} +2 -2
- package/dist/{notifier-htdf4ekH.js.map → notifier-D7TmVus0.js.map} +1 -1
- package/dist/plugin-vue/index.cjs +1 -1
- package/dist/plugin-vue/index.cjs.map +1 -1
- package/dist/plugin-vue/index.js +1 -1
- package/dist/plugin-vue/index.js.map +1 -1
- package/dist/prompt-files/index.cjs +1 -1
- package/dist/prompt-files/index.js +1 -1
- package/dist/{promptSafety-CjxafW2b.cjs → promptSafety-CF6OCtor.cjs} +2 -2
- package/dist/{promptSafety-CjxafW2b.cjs.map → promptSafety-CF6OCtor.cjs.map} +1 -1
- package/dist/{promptSafety-B8LECAkY.js → promptSafety-CYU_kLUL.js} +2 -2
- package/dist/{promptSafety-B8LECAkY.js.map → promptSafety-CYU_kLUL.js.map} +1 -1
- package/dist/remote-host/index.cjs +1 -1
- package/dist/remote-host/index.js +1 -1
- package/dist/remote-host/server/index.cjs +4 -4
- package/dist/remote-host/server/index.js +4 -4
- package/dist/{remote-host-TiMhcW1o.js → remote-host-BiCg_ioB.js} +2 -2
- package/dist/{remote-host-TiMhcW1o.js.map → remote-host-BiCg_ioB.js.map} +1 -1
- package/dist/{remote-host-11euEZKP.cjs → remote-host-neXWDACl.cjs} +2 -2
- package/dist/{remote-host-11euEZKP.cjs.map → remote-host-neXWDACl.cjs.map} +1 -1
- package/dist/remote-view/index.cjs +1 -1
- package/dist/remote-view/index.js +1 -1
- package/dist/root-Ccgd3H5S.cjs +29 -0
- package/dist/root-Ccgd3H5S.cjs.map +1 -0
- package/dist/root-s0MUUMQU.js +22 -0
- package/dist/root-s0MUUMQU.js.map +1 -0
- package/dist/runtime-plugins/containment.d.ts +5 -0
- package/dist/runtime-plugins/download.d.ts +12 -0
- package/dist/runtime-plugins/fetchPackage.d.ts +65 -0
- package/dist/runtime-plugins/index.cjs +810 -5
- package/dist/runtime-plugins/index.cjs.map +1 -1
- package/dist/runtime-plugins/index.d.ts +7 -0
- package/dist/runtime-plugins/index.js +786 -8
- package/dist/runtime-plugins/index.js.map +1 -1
- package/dist/runtime-plugins/inspect.d.ts +18 -0
- package/dist/runtime-plugins/install.d.ts +48 -0
- package/dist/runtime-plugins/installSource.d.ts +37 -0
- package/dist/runtime-plugins/ledger.d.ts +3 -0
- package/dist/runtime-plugins/ledgerWrite.d.ts +17 -0
- package/dist/runtime-plugins/load.d.ts +2 -2
- package/dist/runtime-plugins/npmBuiltinNames.d.ts +1 -0
- package/dist/scheduler/index.cjs +2 -2
- package/dist/scheduler/index.js +2 -2
- package/dist/{server-ZKTtI8_W.cjs → server-BxwOUg_l.cjs} +9 -9
- package/dist/{server-ZKTtI8_W.cjs.map → server-BxwOUg_l.cjs.map} +1 -1
- package/dist/{server-xdXBsiba.js → server-C3HNV-PG.js} +6 -6
- package/dist/{server-xdXBsiba.js.map → server-C3HNV-PG.js.map} +1 -1
- package/dist/utils/index.cjs +2 -2
- package/dist/utils/index.js +2 -2
- package/dist/whisper/index.cjs +2 -2
- package/dist/whisper/index.js +2 -2
- package/dist/wiki/index.cjs +1 -1
- package/dist/wiki/index.js +1 -1
- package/dist/workspace-setup/index.js +1 -1
- package/dist/workspace-setup/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/discovery-DxmMcpFo.cjs.map +0 -1
- package/dist/discovery-RyuhNKjx.js.map +0 -1
- package/dist/dist-734JaRYi.cjs.map +0 -1
- package/dist/dist-BmO4oSQy.js.map +0 -1
- package/dist/errorMessage-D0kR547_.cjs +0 -1
- package/dist/errorMessage-TpKxrmeo.js +0 -1
- package/dist/root-9lRFeXbm.cjs.map +0 -1
- package/dist/root-CqxPNSyK.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-host-11euEZKP.cjs","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,aAAAA,SAAS,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-neXWDACl.cjs","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,aAAAA,SAAS,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,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_dist = require("../dist-
|
|
2
|
+
const require_dist = require("../dist-CdSEjlVx.cjs");
|
|
3
3
|
const require_project = require("../project-DDTIVEMU.cjs");
|
|
4
4
|
// src/remote-view/index.ts
|
|
5
5
|
/** Bump when the bootstrap/message contract changes shape; the bootstrap
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as isRecord } from "../dist
|
|
1
|
+
import { c as isRecord } from "../dist--searOB5.js";
|
|
2
2
|
import { n as projectRecordFields } from "../project-mU6-xLfy.js";
|
|
3
3
|
// src/remote-view/index.ts
|
|
4
4
|
/** Bump when the bootstrap/message contract changes shape; the bootstrap
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
4
|
+
// src/files/root.ts
|
|
5
|
+
/** The canonical form of a root, for every place a root becomes an IDENTITY
|
|
6
|
+
* rather than a path to read.
|
|
7
|
+
*
|
|
8
|
+
* `path.resolve` only — it collapses `.`/`..` and the trailing separator, so
|
|
9
|
+
* `/work/project` and `/work/project/` are one root instead of two watcher
|
|
10
|
+
* generations over the same tree, two bells per record, and two scheduled
|
|
11
|
+
* refresh jobs.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately NOT `realpath`. Resolving symlinks is async (so it could not run
|
|
14
|
+
* on a synchronous claim path), it fails for a root that does not exist yet,
|
|
15
|
+
* and it would put a path the host never named into an id that is written to
|
|
16
|
+
* disk. The policy is therefore lexical: a host that hands the same tree under
|
|
17
|
+
* two different symlink spellings gets two roots, and it is the host's job to
|
|
18
|
+
* name a project the same way every time. */
|
|
19
|
+
function canonicalRoot(root) {
|
|
20
|
+
return node_path.default.resolve(root);
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(exports, "canonicalRoot", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function() {
|
|
25
|
+
return canonicalRoot;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=root-Ccgd3H5S.cjs.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
// src/files/root.ts
|
|
3
|
+
/** The canonical form of a root, for every place a root becomes an IDENTITY
|
|
4
|
+
* rather than a path to read.
|
|
5
|
+
*
|
|
6
|
+
* `path.resolve` only — it collapses `.`/`..` and the trailing separator, so
|
|
7
|
+
* `/work/project` and `/work/project/` are one root instead of two watcher
|
|
8
|
+
* generations over the same tree, two bells per record, and two scheduled
|
|
9
|
+
* refresh jobs.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately NOT `realpath`. Resolving symlinks is async (so it could not run
|
|
12
|
+
* on a synchronous claim path), it fails for a root that does not exist yet,
|
|
13
|
+
* and it would put a path the host never named into an id that is written to
|
|
14
|
+
* disk. The policy is therefore lexical: a host that hands the same tree under
|
|
15
|
+
* two different symlink spellings gets two roots, and it is the host's job to
|
|
16
|
+
* name a project the same way every time. */
|
|
17
|
+
function canonicalRoot(root) {
|
|
18
|
+
return path.resolve(root);
|
|
19
|
+
}
|
|
20
|
+
export { canonicalRoot as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=root-s0MUUMQU.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** True when `file` exists and, with every link followed, is inside `root`. */
|
|
2
|
+
export declare function resolvesInside(file: string, root: string): boolean;
|
|
3
|
+
/** The first symlink under `root` that leads outside it (or nowhere), relative to `root`; null when
|
|
4
|
+
* every link stays inside. */
|
|
5
|
+
export declare function linkLeadingOut(root: string, dir?: string): string | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type FetchFn = typeof fetch;
|
|
2
|
+
export interface DownloadLimits {
|
|
3
|
+
timeoutMs: number;
|
|
4
|
+
maxBytes: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class DownloadError extends Error {
|
|
7
|
+
}
|
|
8
|
+
export declare function downloadBytes(fetchFn: FetchFn, url: string, headers: Record<string, string>, limits: DownloadLimits): Promise<Buffer>;
|
|
9
|
+
export declare function downloadJson(fetchFn: FetchFn, url: string, headers: Record<string, string>, limits: DownloadLimits): Promise<unknown>;
|
|
10
|
+
/** Whether `bytes` match an npm `dist.integrity` (Subresource Integrity, possibly several space-
|
|
11
|
+
* separated hashes) — the strongest algorithm present must match. False when none is recognised. */
|
|
12
|
+
export declare function matchesIntegrity(bytes: Uint8Array, integrity: string): boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FetchFn } from './download.js';
|
|
2
|
+
import { InstallSource } from './installSource.js';
|
|
3
|
+
export declare const NPM_REGISTRY = "https://registry.npmjs.org";
|
|
4
|
+
export declare const GITHUB_API = "https://api.github.com";
|
|
5
|
+
export interface FetchedPackage {
|
|
6
|
+
bytes: Buffer;
|
|
7
|
+
/** The npm version, GitHub tag or file path that was resolved, for the ledger's `source`. */
|
|
8
|
+
resolved: string;
|
|
9
|
+
}
|
|
10
|
+
export interface NpmRelease {
|
|
11
|
+
version: string;
|
|
12
|
+
tarball: string;
|
|
13
|
+
integrity: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** A decision that either holds a value or says why there is none. */
|
|
16
|
+
export type Resolved<T> = {
|
|
17
|
+
ok: true;
|
|
18
|
+
value: T;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
/** The version a packument resolves `spec` to — exact, a dist-tag, or `latest` when absent. */
|
|
24
|
+
export declare function resolveNpmRelease(packument: unknown, spec: string | null): Resolved<NpmRelease>;
|
|
25
|
+
/** Whether the downloaded bytes are the ones the registry published, by its strongest hash. */
|
|
26
|
+
export declare function verifyNpmBytes(bytes: Uint8Array, release: NpmRelease): string | null;
|
|
27
|
+
export interface GithubAsset {
|
|
28
|
+
tag: string;
|
|
29
|
+
name: string;
|
|
30
|
+
/** The browser download URL, for an unauthenticated download. */
|
|
31
|
+
downloadUrl: string;
|
|
32
|
+
/** The API URL of the asset, for a download with a token (private repositories). */
|
|
33
|
+
apiUrl: string;
|
|
34
|
+
/** GitHub's own `sha256:<hex>` for the asset, when the API gives one (assets uploaded before GitHub
|
|
35
|
+
* started recording digests have none). */
|
|
36
|
+
digest: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** The release's one `.tgz` asset. None, or several, is refused: guessing which file is the plugin
|
|
39
|
+
* is exactly what a user should not have to trust. */
|
|
40
|
+
export declare function resolveGithubAsset(release: unknown): Resolved<GithubAsset>;
|
|
41
|
+
/** Whether the bytes are the asset GitHub recorded. An asset with no digest is accepted — older
|
|
42
|
+
* uploads carry none, and the bytes still came over https from GitHub — but a digest that is present
|
|
43
|
+
* must be a sha256 and must match. */
|
|
44
|
+
export declare function verifyGithubBytes(bytes: Uint8Array, asset: GithubAsset): string | null;
|
|
45
|
+
export interface FetchDeps {
|
|
46
|
+
fetch: FetchFn;
|
|
47
|
+
/** Sent to GitHub when present: raises the rate limit and reaches private repositories. */
|
|
48
|
+
githubToken?: string | undefined;
|
|
49
|
+
npmRegistry?: string | undefined;
|
|
50
|
+
githubApi?: string | undefined;
|
|
51
|
+
}
|
|
52
|
+
/** Something to read from in chunks: a FileHandle, or a stand-in in tests. */
|
|
53
|
+
export interface ChunkReader {
|
|
54
|
+
read: (buffer: Buffer, offset: number, length: number, position: null) => Promise<{
|
|
55
|
+
bytesRead: number;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
/** Reads to the end, refusing as soon as more than `maxBytes` arrive: never holds more than one chunk past it.
|
|
59
|
+
* Once `signal` aborts, no further read is started. */
|
|
60
|
+
export declare function readAtMost(reader: ChunkReader, maxBytes: number, what: string, signal?: AbortSignal): Promise<Buffer>;
|
|
61
|
+
/** Rejects with a DownloadError once `timeoutMs` pass, and aborts the signal `work` was given so it starts
|
|
62
|
+
* nothing more. A read already stuck in the kernel cannot be cancelled from Node — closing its handle waits
|
|
63
|
+
* for it — so at most that one read stays in flight, and its handle closes once it returns. */
|
|
64
|
+
export declare function withDeadline<T>(work: (signal: AbortSignal) => Promise<T>, timeoutMs: number, what: string): Promise<T>;
|
|
65
|
+
export declare function fetchPackage(source: InstallSource, deps: FetchDeps): Promise<FetchedPackage>;
|