@codeworksh/cli 0.9.0-canary.165.2.g336229f9 → 0.9.0-canary.167.1.g6ddcc8db

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 (29) hide show
  1. package/{acp-wxLiqsce.mjs → acp-CmtcmhuX.mjs} +2 -2
  2. package/{acp-wxLiqsce.mjs.map → acp-CmtcmhuX.mjs.map} +1 -1
  3. package/{connect-Da_1ZXLf.mjs → connect-KX-A0EzQ.mjs} +3 -3
  4. package/{connect-Da_1ZXLf.mjs.map → connect-KX-A0EzQ.mjs.map} +1 -1
  5. package/{disconnect-B-Pgh2uG.mjs → disconnect-CCI1DLJ0.mjs} +2 -2
  6. package/{disconnect-B-Pgh2uG.mjs.map → disconnect-CCI1DLJ0.mjs.map} +1 -1
  7. package/{discovery-CYiDVyU6.mjs → discovery-D2ftXE5a.mjs} +2 -2
  8. package/{discovery-CYiDVyU6.mjs.map → discovery-D2ftXE5a.mjs.map} +1 -1
  9. package/{identity-M1WZUqu0.mjs → identity-Llk4K_8w.mjs} +2 -2
  10. package/{identity-M1WZUqu0.mjs.map → identity-Llk4K_8w.mjs.map} +1 -1
  11. package/index.mjs +9 -9
  12. package/package-D_TWKUKk.mjs +6 -0
  13. package/package-D_TWKUKk.mjs.map +1 -0
  14. package/package.json +4 -4
  15. package/{relay-CbB-VCsr.mjs → relay-BmHXs1yg.mjs} +3 -3
  16. package/{relay-CbB-VCsr.mjs.map → relay-BmHXs1yg.mjs.map} +1 -1
  17. package/{restart-bMtkLGXM.mjs → restart-CMDZZJ4N.mjs} +2 -2
  18. package/{restart-bMtkLGXM.mjs.map → restart-CMDZZJ4N.mjs.map} +1 -1
  19. package/{serve-Dba-6XyV.mjs → serve-CfjS09-r.mjs} +10 -4
  20. package/serve-CfjS09-r.mjs.map +1 -0
  21. package/{start-_OgO4fEe.mjs → start-DbCTFswo.mjs} +2 -2
  22. package/{start-_OgO4fEe.mjs.map → start-DbCTFswo.mjs.map} +1 -1
  23. package/{status-Dnw-3t4J.mjs → status-Dcbdl6Sv.mjs} +2 -2
  24. package/{status-Dnw-3t4J.mjs.map → status-Dcbdl6Sv.mjs.map} +1 -1
  25. package/{stop-BcbFFErk.mjs → stop-ML5Yeo_s.mjs} +2 -2
  26. package/{stop-BcbFFErk.mjs.map → stop-ML5Yeo_s.mjs.map} +1 -1
  27. package/package-DZfIu4Eq.mjs +0 -6
  28. package/package-DZfIu4Eq.mjs.map +0 -1
  29. package/serve-Dba-6XyV.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve-CfjS09-r.mjs","names":["layer","Relay.heartbeat","Service","fail","Contract","make","layer","Wire","Service","layer","Private.write","identity","MachineFile.identity","Knock","Knock","Principal.Token","Pairing.Service","Contract","Principal.Door","Principal.Unauthorized","Principal.Current","Principal.actorOf","Service","make","Envelope.Core","Envelope.encode","Envelope.ofThread","layer","Service","Contract","layer","layer","Contract","MessagePart.decode","Envelope.encode","layer","Contract","EventFeed.Service","OAuth.Service","Identity.Service","Host.Service","Clones.Service","Pairing.Service","Door.Connections","MachineFile.read","Rows.resume","Envelope.ofThread","Rows.watch","Rows.follow","MachineRelay.status","MachineRelay.rename","MachineRelay.heartbeat","MachineRelay.disconnect","MachineRelay.connect","Principal.local","Principal.Current","Principal.Forbidden","MachineFile.identity","Principal.Token","Identity.Service","Contract","Registration.register","Pairing.TrustedProxy","Door.protocol","EventFeed.layer","Door.rpc","Pairing.routes","Door.listener","Door.layerConnections","Pairing.layer","Heartbeat.layer","OAuth.layer","Host.layer","Clones.layer","Identity.layer","Principal.layerToken","Runtime.handler","Server.layer","Registration.log"],"sources":["../../src/machine/heartbeat.ts","../../src/server/clones.ts","../../src/server/pairing.ts","../../src/server/principal.ts","../../src/server/door.ts","../../src/server/feed.ts","../../src/server/host.ts","../../src/server/oauth.ts","../../src/server/part.ts","../../src/server/rows.ts","../../src/server/handlers.ts","../../src/server/server.ts","../../src/cli/cmd/handlers/serve.ts"],"sourcesContent":["import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, Layer, Schedule } from \"effect\";\nimport * as Relay from \"./relay.ts\";\n\n/**\n * While the server runs, each connected workspace hears from this machine every 30 seconds; the relay\n * shows it online for 90. `machine.json` is read on every beat, so a `codework connect` made while the\n * server runs is picked up without a restart. Nothing here is fatal: local work never waits on the relay.\n */\nexport const layer = Layer.effectDiscard(\n\tEffect.gen(function* () {\n\t\tconst global = yield* Global.Service;\n\t\tyield* Relay.heartbeat(global.home).pipe(\n\t\t\tEffect.catch((error) => Effect.logDebug(\"Machine heartbeat failed\", error)),\n\t\t\tEffect.repeat(Schedule.spaced(\"30 seconds\")),\n\t\t\tEffect.forkScoped,\n\t\t);\n\t}),\n);\n","/**\n * Background clones into host folders. Each is tracked by its destination from start until 30 seconds\n * after it is done (a failed or cancelled one stays until retried or discarded), and git's progress\n * is streamed as it arrives. Tracking is in memory: a restart forgets every clone.\n */\nimport { expandTilde } from \"@codeworksh/harness/effect\";\nimport {\n\tCause,\n\tClock,\n\tContext,\n\tData,\n\tEffect,\n\tExit,\n\tFiber,\n\tFileSystem,\n\tLayer,\n\tOption,\n\tPath,\n\ttype PlatformError,\n\tPubSub,\n\tQueue,\n\tRef,\n\tSchedule,\n\tScope,\n\tSemaphore,\n\tStream,\n} from \"effect\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport * as Contract from \"./contract.ts\";\n\ninterface Interface {\n\treadonly start: (input: {\n\t\treadonly remote: string;\n\t\treadonly path: string;\n\t}) => Effect.Effect<{ readonly path: string; readonly remote: string }, Contract.HostError>;\n\t/** Interrupts a running clone and empties its folder. */\n\treadonly cancel: (path: string) => Effect.Effect<boolean>;\n\treadonly retry: (path: string) => Effect.Effect<boolean, Contract.HostError>;\n\t/** Stops tracking, interrupts a running clone and empties an unfinished folder. */\n\treadonly discard: (path: string) => Effect.Effect<void>;\n\t/** Refuses a session in a folder whose clone is running, failed or cancelled. */\n\treadonly guard: (path: string) => Effect.Effect<void, Contract.HostError>;\n\treadonly stream: Stream.Stream<ReadonlyArray<Contract.Clone>>;\n}\n\nexport class Service extends Context.Service<Service, Interface>()(\"@codeworksh/cli/server/clones/Service\") {}\n\nconst DONE_RETENTION = \"30 seconds\";\n// Git prints nothing while a transfer waits on the network, and the kernel can take 15+ minutes to\n// give up on a dead connection; without this the last transfer speed shows as if data still arrived.\nconst STALL_AFTER = \"20 seconds\";\nconst DETAIL_MAX = 200;\nconst ERROR_MAX = 1000;\n// Only the tail is read, and progress can be huge; lines keep flowing past the cap.\nconst MAX_OUTPUT_BYTES = 256 * 1024;\nconst MAX_PENDING_LINE = 64 * 1024;\nconst NOT_CLONED = \"The repository could not be cloned.\";\n// Unexpected file system failures; matches the generic text clones report for them.\nconst UNCOMPLETED = \"The source control operation could not be completed.\";\n\nconst CLONE_ENV = {\n\t// Piped progress at once; credential prompts would hang without a tty.\n\tGIT_PROGRESS_DELAY: \"0\",\n\tGIT_TERMINAL_PROMPT: \"0\",\n\t// English progress without overriding LC_CTYPE, which a global post-checkout hook inherits.\n\tLANGUAGE: \"C\",\n};\n\nconst clampText = (text: string, maxLength: number) =>\n\ttext.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}…`;\n\nconst fail = (message: string) => new Contract.HostError({ message });\n\ntype Reason = \"not_a_repository\" | \"conflict\" | \"authentication_failed\" | \"host_key_unverified\";\n\nclass CloneError extends Data.TaggedError(\"CloneError\")<{\n\treadonly message: string;\n\treadonly reason: Reason | null;\n}> {}\n\n// --- Progress --------------------------------------------------------------------------------\n\ninterface Progress {\n\treadonly stage: Contract.CloneStage;\n\treadonly percent: number | null;\n\treadonly detail: string | null;\n}\n\nconst STAGE_PREFIXES: ReadonlyArray<readonly [RegExp, Contract.CloneStage]> = [\n\t[/^remote: Enumerating objects/, \"counting\"],\n\t[/^remote: Counting objects/, \"counting\"],\n\t[/^remote: Compressing objects/, \"counting\"],\n\t[/^Receiving objects/, \"receiving\"],\n\t[/^Resolving deltas/, \"resolving\"],\n\t[/^Updating files/, \"checkout\"],\n\t[/^Checking out files/, \"checkout\"],\n];\n\nconst PERCENT = /:\\s+(\\d+)%\\s+\\((\\d+)\\/(\\d+)\\)(?:,\\s*(.*?))?\\s*(?:,\\s*done\\.)?\\s*$/;\n\n/** One progress redraw; git separates them with a bare CR. */\nconst parseProgress = (line: string): Progress | null => {\n\tconst trimmed = line.trim();\n\tconst stageEntry = STAGE_PREFIXES.find(([pattern]) => pattern.test(trimmed));\n\tif (!stageEntry) return null;\n\tconst stage = stageEntry[1];\n\tconst match = PERCENT.exec(trimmed);\n\tif (!match) return { stage, percent: null, detail: null };\n\tconst percent = Number(match[1]);\n\tconst rawDetail = match[4]?.trim() ?? \"\";\n\tconst detail = rawDetail.length > 0 && rawDetail !== \"done.\" ? rawDetail : null;\n\treturn {\n\t\tstage,\n\t\tpercent: Number.isFinite(percent) ? Math.max(0, Math.min(100, percent)) : null,\n\t\tdetail,\n\t};\n};\n\n// --- URLs ------------------------------------------------------------------------------------\n\ntype Protocol = \"ssh\" | \"https\";\n\nconst SCP_LIKE_URL = /^(?:[^@/\\s]+@)?([^:/\\s]+):(?!\\/)(.+)$/;\n// Userinfo may contain `@`; the last one before the first slash separates the host.\nconst SSH_URL = /^ssh:\\/\\/(?:[^/\\s]*@)?([^@:/\\s]+)(:\\d+)?\\/(.+)$/;\nconst HTTPS_URL = /^https?:\\/\\/(?:[^/\\s]*@)?([^@:/\\s]+)(:\\d+)?\\/(.+)$/;\n\nconst parseCloneUrl = (url: string) => {\n\tconst trimmed = url.trim();\n\tconst ssh = SSH_URL.exec(trimmed);\n\tif (ssh) return { protocol: \"ssh\" as Protocol, host: ssh[1]!, path: ssh[3]!, customPort: !!ssh[2] };\n\tconst https = HTTPS_URL.exec(trimmed);\n\tif (https) return { protocol: \"https\" as Protocol, host: https[1]!, path: https[3]!, customPort: !!https[2] };\n\tconst scp = SCP_LIKE_URL.exec(trimmed);\n\tif (scp) return { protocol: \"ssh\" as Protocol, host: scp[1]!, path: scp[2]!, customPort: false };\n\treturn null;\n};\n\n/**\n * A clone URL in the other protocol, as the host may only have SSH keys or only an HTTPS credential\n * helper; null when it cannot be rewritten safely, such as with a custom port.\n */\nconst cloneUrlForProtocol = (url: string, protocol: Protocol): string | null => {\n\tconst parsed = parseCloneUrl(url);\n\tif (!parsed) return null;\n\tif (parsed.protocol === protocol) return url.trim();\n\tif (parsed.customPort) return null;\n\t// Azure's transports use different hosts and put the repository marker in different positions;\n\t// changing only the scheme produces an invalid clone URL.\n\tif (parsed.protocol === \"ssh\" && parsed.host.toLowerCase() === \"ssh.dev.azure.com\") {\n\t\tconst azure = /^v3\\/([^/?#]+)\\/([^/?#]+)\\/([^/?#]+)$/.exec(parsed.path);\n\t\treturn azure ? `https://dev.azure.com/${azure[1]}/${azure[2]}/_git/${azure[3]}` : null;\n\t}\n\tif (parsed.protocol === \"https\" && parsed.host.toLowerCase() === \"dev.azure.com\") {\n\t\tconst azure = /^([^/?#]+)\\/([^/?#]+)\\/_git\\/([^/?#]+)$/.exec(parsed.path);\n\t\treturn azure ? `git@ssh.dev.azure.com:v3/${azure[1]}/${azure[2]}/${azure[3]}` : null;\n\t}\n\treturn protocol === \"ssh\" ? `git@${parsed.host}:${parsed.path}` : `https://${parsed.host}/${parsed.path}`;\n};\n\n/** An SSH rejection is retried over HTTPS; other URL shapes are never guessed. */\nconst httpsFallbackUrl = (cloneUrl: string) =>\n\tparseCloneUrl(cloneUrl)?.protocol === \"ssh\" ? cloneUrlForProtocol(cloneUrl, \"https\") : null;\n\n/** The remote as clients see it: git still gets the credentials. */\nconst redactRemoteUrl = (remoteUrl: string) => {\n\tconst url = URL.parse(remoteUrl);\n\t// Clone URLs have no legitimate query; when one is present it is a token.\n\tif (url === null || (url.username.length === 0 && url.password.length === 0 && url.search.length === 0)) {\n\t\treturn remoteUrl;\n\t}\n\turl.username = \"\";\n\turl.password = \"\";\n\turl.search = \"\";\n\treturn url.toString();\n};\n\n// Userinfo can contain @; remove through the last one before the host boundary.\nconst URL_WITH_USERINFO = /\\b([a-z][a-z0-9+.-]*:\\/\\/)[^\\s/?#]+@/gi;\n// Git leaves quotes inside query tokens unescaped; consume through the closing quote.\nconst QUOTED_URL_QUERY = /(['\"])([a-z][a-z0-9+.-]*:\\/\\/[^\\s?]*)\\?.*\\1(?=[\\s:]|$)/gi;\nconst URL_QUERY = /\\b([a-z][a-z0-9+.-]*:\\/\\/[^\\s?]*)\\?[^\\s]*/gi;\n\nconst redactUrlCredentials = (text: string) =>\n\ttext.replace(QUOTED_URL_QUERY, \"$1$2$1\").replace(URL_QUERY, \"$1\").replace(URL_WITH_USERINFO, \"$1\");\n\n// --- Failure classification ------------------------------------------------------------------\n\n// Only the reasons up to the two that switch to HTTPS matter, in git's order of precedence.\nconst FAILURE_PATTERNS: ReadonlyArray<readonly [RegExp, Reason]> = [\n\t[/would clobber existing tag/i, \"conflict\"],\n\t[/is already (?:used by worktree at|checked out at)/i, \"conflict\"],\n\t[/a branch named .+ already exists/i, \"conflict\"],\n\t[/could not lock config file .+: File exists/i, \"conflict\"],\n\t[\n\t\t/(?:authentication failed|could not read Username|could not read Password|permission denied \\([a-z-]+(?:,[a-z-]+)*\\)|permission denied, please try again)/i,\n\t\t\"authentication_failed\",\n\t],\n\t[/host key verification failed/i, \"host_key_unverified\"],\n];\n\n// Trust only git's diagnostic prefixes: local hooks can write indistinguishable text, and `remote:`\n// prefixes remote hook output as well as server diagnostics.\nconst DIAGNOSTIC_LINE = /^(?:fatal|error):|^!\\s|^\\s+!\\s/;\n// SSH credential refusals are unprefixed; git's later generic error would otherwise hide them.\nconst SSH_TRANSPORT_REFUSAL =\n\t/Permission denied \\((?:publickey|password|keyboard-interactive)|Permission denied, please try again|Host key verification failed/i;\n\nconst classify = (stderr: string): Reason | null => {\n\tconst diagnostics = stderr\n\t\t.split(/\\r?\\n/)\n\t\t.filter((line) => DIAGNOSTIC_LINE.test(line) || (!line.startsWith(\"remote:\") && SSH_TRANSPORT_REFUSAL.test(line)))\n\t\t.join(\"\\n\");\n\tif (diagnostics.length === 0) return null;\n\tif (diagnostics.toLowerCase().includes(\"not a git repository\")) return \"not_a_repository\";\n\treturn FAILURE_PATTERNS.find(([pattern]) => pattern.test(diagnostics))?.[1] ?? null;\n};\n\nconst isSshRejection = (error: CloneError) =>\n\terror.reason === \"authentication_failed\" || error.reason === \"host_key_unverified\";\n\n/**\n * Appends a git config entry through the environment, after any inherited ones, without touching\n * argv or the user's config; an invalid inherited count is left for git to report.\n */\nconst gitConfigEnv = (env: Record<string, string | undefined>, key: string, value: string) => {\n\tconst inherited = env.GIT_CONFIG_COUNT;\n\tif (\n\t\tinherited !== undefined &&\n\t\tinherited !== \"\" &&\n\t\t/^[ \\t\\r\\n\\v\\f]*(?:\\+?\\d+|-0+)/.exec(inherited)?.[0] !== inherited\n\t) {\n\t\treturn {};\n\t}\n\tconst count = inherited === undefined || inherited === \"\" ? 0 : Number.parseInt(inherited, 10);\n\treturn {\n\t\tGIT_CONFIG_COUNT: String(count + 1),\n\t\t[`GIT_CONFIG_KEY_${count}`]: key,\n\t\t[`GIT_CONFIG_VALUE_${count}`]: value,\n\t};\n};\n\nconst LINE_SEPARATOR = /\\r\\n|\\r|\\n/;\n\n/** Reads a git output stream, keeping its first 256 KiB as text and passing every non-empty line on. */\nconst collect = Effect.fnUntraced(function* (\n\tstream: Stream.Stream<Uint8Array, PlatformError.PlatformError>,\n\tonLine?: (line: string) => Effect.Effect<void>,\n) {\n\tconst decoder = new TextDecoder(\"utf-8\", { ignoreBOM: true });\n\tconst lineDecoder = new TextDecoder();\n\tlet bytes = 0;\n\tlet text = \"\";\n\tlet pending = \"\";\n\tlet truncated = false;\n\n\tconst emit = Effect.fnUntraced(function* (flush: boolean) {\n\t\tif (onLine === undefined) return;\n\t\tlet separator = LINE_SEPARATOR.exec(pending);\n\t\twhile (separator) {\n\t\t\tconst line = pending.slice(0, separator.index);\n\t\t\tpending = pending.slice(separator.index + separator[0].length);\n\t\t\tif (line.length > 0) yield* onLine(line);\n\t\t\tseparator = LINE_SEPARATOR.exec(pending);\n\t\t}\n\t\tif (flush) {\n\t\t\tconst trailing = pending;\n\t\t\tpending = \"\";\n\t\t\tif (trailing.length > 0) yield* onLine(trailing);\n\t\t}\n\t});\n\n\tyield* Stream.runForEach(\n\t\tstream,\n\t\tEffect.fnUntraced(function* (chunk) {\n\t\t\tif (!truncated) {\n\t\t\t\tconst room = MAX_OUTPUT_BYTES - bytes;\n\t\t\t\tconst kept = chunk.byteLength > room ? chunk.subarray(0, Math.max(0, room)) : chunk;\n\t\t\t\tbytes += kept.byteLength;\n\t\t\t\ttruncated = chunk.byteLength > room;\n\t\t\t\ttext += decoder.decode(kept, { stream: !truncated });\n\t\t\t}\n\t\t\tif (onLine === undefined) return;\n\t\t\tpending += lineDecoder.decode(chunk, { stream: true });\n\t\t\tyield* emit(false);\n\t\t\t// A newline-free run that long is no use to anyone reading lines.\n\t\t\tif (truncated && pending.length > MAX_PENDING_LINE) pending = \"\";\n\t\t}),\n\t);\n\tif (!truncated) text += decoder.decode();\n\tpending += lineDecoder.decode();\n\tyield* emit(true);\n\treturn text;\n});\n\n// --- Tracker ---------------------------------------------------------------------------------\n\ninterface Tracked {\n\treadonly snapshot: Contract.Clone;\n\treadonly fiber: Fiber.Fiber<unknown, unknown> | null;\n\t/** What git is given; may carry credentials and never leaves the server. */\n\treadonly cloneUrl: string;\n}\n\nconst make = Effect.gen(function* () {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst path = yield* Path.Path;\n\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n\n\tconst clones = yield* Ref.make(new Map<string, Tracked>());\n\tconst changes = yield* PubSub.unbounded<ReadonlyArray<Contract.Clone>>();\n\tconst retentionFibers = new Map<string, Fiber.Fiber<unknown, never>>();\n\tlet sequence = 0;\n\tconst cloneScope = yield* Scope.make(\"parallel\");\n\tyield* Effect.addFinalizer(() => Scope.close(cloneScope, Exit.void));\n\t// Serialize actions on an entry and its folder so a retry cannot race a clone.\n\tconst actionLock = yield* Semaphore.make(1);\n\tconst locked = <A, E, R>(effect: Effect.Effect<A, E, R>) => actionLock.withPermits(1)(effect);\n\n\tconst resolve = (value: string) => path.resolve(expandTilde(value.trim(), path));\n\tconst failed = () => fail(UNCOMPLETED);\n\n\tconst normalizeDestination = Effect.fn(\"Clones.normalizeDestination\")(function* (destination: string) {\n\t\tif (destination.trim().length === 0) return yield* fail(\"Choose a destination path before cloning.\");\n\t\treturn resolve(destination);\n\t});\n\n\tconst prepareDestination = Effect.fn(\"Clones.prepareDestination\")(function* (input: string) {\n\t\tconst destination = yield* normalizeDestination(input);\n\t\tif (yield* fs.exists(destination).pipe(Effect.mapError(failed))) {\n\t\t\tconst entries = yield* fs\n\t\t\t\t.readDirectory(destination)\n\t\t\t\t.pipe(Effect.mapError(() => fail(\"Destination path already exists and is not a directory.\")));\n\t\t\tif (entries.length > 0) return yield* fail(\"Destination path already exists and is not empty.\");\n\t\t} else {\n\t\t\tconst parent = path.dirname(destination);\n\t\t\tif (!(yield* fs.exists(parent).pipe(Effect.mapError(failed)))) {\n\t\t\t\tyield* fs.makeDirectory(parent, { recursive: true }).pipe(Effect.mapError(failed));\n\t\t\t}\n\t\t}\n\t\treturn destination;\n\t});\n\n\tconst prepare = Effect.fn(\"Clones.prepare\")(function* (input: { readonly remote: string; readonly path: string }) {\n\t\tconst destination = yield* prepareDestination(input.path);\n\t\tconst cloneUrl = input.remote.trim();\n\t\tif (cloneUrl.length === 0) return yield* fail(\"Enter a repository path or clone URL before cloning.\");\n\t\treturn { destination, cloneUrl, remote: redactRemoteUrl(cloneUrl) };\n\t});\n\n\t/** Empties a partial clone's folder, keeping the folder; refuses one holding files git did not write. */\n\tconst discardClone = Effect.fn(\"Clones.discardClone\")(function* (input: string) {\n\t\tconst destination = yield* normalizeDestination(input);\n\t\tconst entries = yield* fs.readDirectory(destination).pipe(\n\t\t\tEffect.catchIf(\n\t\t\t\t(error) => error.reason._tag === \"NotFound\",\n\t\t\t\t() => Effect.succeed<ReadonlyArray<string>>([]),\n\t\t\t),\n\t\t\tEffect.mapError(() => fail(\"The clone destination could not be inspected.\")),\n\t\t);\n\t\tif (entries.length > 0 && !entries.includes(\".git\")) {\n\t\t\treturn yield* fail(\"Destination path contains files that are not from the clone.\");\n\t\t}\n\t\t// Retried while an interrupted git still closes its files.\n\t\tyield* fs.remove(destination, { recursive: true, force: true }).pipe(\n\t\t\tEffect.andThen(fs.makeDirectory(destination, { recursive: true })),\n\t\t\tEffect.retry({ schedule: Schedule.spaced(\"200 millis\"), times: 5 }),\n\t\t\tEffect.mapError(() => fail(\"The partial clone could not be removed.\")),\n\t\t);\n\t});\n\n\tconst attempt = Effect.fn(\"Clones.attempt\")(function* (\n\t\tdestination: string,\n\t\tcloneUrl: string,\n\t\tonProgress: (update: Progress) => Effect.Effect<void>,\n\t) {\n\t\t// Git mixes progress and diagnostics on stderr; the last few other lines explain a failure.\n\t\tconst tail: Array<string> = [];\n\t\tconst onLine = (line: string) => {\n\t\t\tconst parsed = parseProgress(line);\n\t\t\tif (parsed) return onProgress(parsed);\n\t\t\treturn Effect.sync(() => {\n\t\t\t\tconst trimmed = line.trim();\n\t\t\t\tif (trimmed.length === 0 || trimmed.startsWith(\"Cloning into\")) return;\n\t\t\t\t// Git echoes the remote in some failures, and the tail is shown to the user.\n\t\t\t\ttail.push(redactUrlCredentials(trimmed));\n\t\t\t\tif (tail.length > 4) tail.shift();\n\t\t\t});\n\t\t};\n\t\t// Git misreads @ in a pathless URL's query as userinfo and echoes its suffix as the host.\n\t\tconst normalized = cloneUrl.replace(/^([a-z][a-z0-9+.-]*:\\/\\/[^/?#]+)\\?/i, \"$1/?\");\n\t\tconst base = { ...process.env, GIT_OPTIONAL_LOCKS: \"0\", ...CLONE_ENV };\n\t\t// A fake bare repository's config can run commands; git before 2.38 ignores this.\n\t\tconst env = { ...base, ...gitConfigEnv(base, \"safe.bareRepository\", \"explicit\") };\n\t\tyield* Effect.gen(function* () {\n\t\t\tconst handle = yield* spawner.spawn(\n\t\t\t\tChildProcess.make(\"git\", [\"clone\", \"--progress\", \"--\", normalized, path.basename(destination)], {\n\t\t\t\t\tcwd: path.dirname(destination),\n\t\t\t\t\tenv,\n\t\t\t\t\textendEnv: false,\n\t\t\t\t\tstdin: \"ignore\",\n\t\t\t\t\tstdout: \"pipe\",\n\t\t\t\t\tstderr: \"pipe\",\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst [, stderr, exitCode] = yield* Effect.all(\n\t\t\t\t[collect(handle.stdout), collect(handle.stderr, onLine), handle.exitCode],\n\t\t\t\t{ concurrency: \"unbounded\" },\n\t\t\t);\n\t\t\tif (exitCode !== 0) return yield* new CloneError({ message: \"\", reason: classify(stderr) });\n\t\t}).pipe(\n\t\t\tEffect.scoped,\n\t\t\tEffect.mapError(\n\t\t\t\t(error) =>\n\t\t\t\t\tnew CloneError({\n\t\t\t\t\t\tmessage: tail.length > 0 ? tail.join(\" \") : NOT_CLONED,\n\t\t\t\t\t\treason: error instanceof CloneError ? error.reason : null,\n\t\t\t\t\t}),\n\t\t\t),\n\t\t);\n\t});\n\n\t/** Clones over the URL as given, then over HTTPS when SSH was refused; the folder is not emptied in between. */\n\tconst cloneRepository = Effect.fn(\"Clones.cloneRepository\")(function* (\n\t\tinput: string,\n\t\tcloneUrl: string,\n\t\tonProgress: (update: Progress) => Effect.Effect<void>,\n\t) {\n\t\tconst destination = yield* prepareDestination(input);\n\t\tconst httpsUrl = httpsFallbackUrl(cloneUrl);\n\t\tconst first = attempt(destination, cloneUrl, onProgress);\n\t\tif (httpsUrl === null) return yield* first;\n\t\tyield* first.pipe(\n\t\t\tEffect.catchIf(isSshRejection, (sshError) =>\n\t\t\t\tattempt(destination, httpsUrl, onProgress).pipe(\n\t\t\t\t\tEffect.mapError(\n\t\t\t\t\t\t(httpsError) =>\n\t\t\t\t\t\t\tnew CloneError({\n\t\t\t\t\t\t\t\tmessage: `${sshError.message} Cloning over HTTPS instead also failed: ${httpsError.message}`,\n\t\t\t\t\t\t\t\treason: httpsError.reason,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t});\n\n\tconst list = Ref.get(clones).pipe(\n\t\tEffect.map((current) => Array.from(current.values(), (tracked) => tracked.snapshot)),\n\t);\n\tconst publish = list.pipe(Effect.flatMap((snapshots) => PubSub.publish(changes, snapshots)));\n\n\tconst modify = (id: string, mutate: (tracked: Tracked) => Tracked) =>\n\t\tRef.modify(clones, (current): readonly [Contract.Clone | null, Map<string, Tracked>] => {\n\t\t\tconst existing = current.get(id);\n\t\t\tif (!existing) return [null, current];\n\t\t\tconst nextTracked = mutate(existing);\n\t\t\tconst nextSnapshot = { ...nextTracked.snapshot, sequence: ++sequence };\n\t\t\tconst next = new Map(current);\n\t\t\tnext.set(id, { ...nextTracked, snapshot: nextSnapshot });\n\t\t\treturn [nextSnapshot, next];\n\t\t}).pipe(Effect.tap((snapshot) => (snapshot ? publish : Effect.void)));\n\n\tconst clearRetention = (id: string) => {\n\t\tconst fiber = retentionFibers.get(id);\n\t\tretentionFibers.delete(id);\n\t\treturn fiber ? Fiber.interrupt(fiber).pipe(Effect.ignore) : Effect.void;\n\t};\n\n\tconst remove = (id: string) =>\n\t\tRef.update(clones, (current) => {\n\t\t\tif (!current.has(id)) return current;\n\t\t\tconst next = new Map(current);\n\t\t\tnext.delete(id);\n\t\t\treturn next;\n\t\t}).pipe(Effect.andThen(publish));\n\n\tconst scheduleRemoval = Effect.fn(\"Clones.scheduleRemoval\")(function* (id: string) {\n\t\tyield* clearRetention(id);\n\t\tconst fiber: Fiber.Fiber<unknown> = yield* remove(id).pipe(\n\t\t\tEffect.delay(DONE_RETENTION),\n\t\t\tEffect.ensuring(\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tif (retentionFibers.get(id) === fiber) retentionFibers.delete(id);\n\t\t\t\t}),\n\t\t\t),\n\t\t\tEffect.forkDetach,\n\t\t);\n\t\tretentionFibers.set(id, fiber);\n\t});\n\n\tconst progress = (id: string, update: Progress) =>\n\t\tmodify(id, (tracked) => ({\n\t\t\t...tracked,\n\t\t\tsnapshot: {\n\t\t\t\t...tracked.snapshot,\n\t\t\t\tstage: update.stage,\n\t\t\t\tpercent: update.percent,\n\t\t\t\tdetail: update.detail === null ? null : clampText(update.detail, DETAIL_MAX),\n\t\t\t\tstalled: false,\n\t\t\t},\n\t\t})).pipe(Effect.asVoid);\n\n\tconst markStalled = (id: string) =>\n\t\tmodify(id, (tracked) => ({ ...tracked, snapshot: { ...tracked.snapshot, stalled: true } })).pipe(Effect.asVoid);\n\n\t/** Marks the clone stalled once, then waits for git to speak again. */\n\tconst watchForStall = (id: string, pulses: Queue.Dequeue<void>) =>\n\t\tQueue.take(pulses).pipe(\n\t\t\tEffect.timeoutOption(STALL_AFTER),\n\t\t\tEffect.flatMap((pulse) =>\n\t\t\t\tOption.isSome(pulse) ? Effect.void : markStalled(id).pipe(Effect.andThen(Queue.take(pulses))),\n\t\t\t),\n\t\t\tEffect.forever,\n\t\t);\n\n\tconst finish = Effect.fn(\"Clones.finish\")(function* (\n\t\tid: string,\n\t\tphase: \"done\" | \"failed\" | \"cancelled\",\n\t\terror: string | null,\n\t) {\n\t\tconst endedAt = yield* Clock.currentTimeMillis;\n\t\tyield* modify(id, (tracked) => ({\n\t\t\t...tracked,\n\t\t\tfiber: null,\n\t\t\tsnapshot: {\n\t\t\t\t...tracked.snapshot,\n\t\t\t\tphase,\n\t\t\t\tendedAt,\n\t\t\t\tpercent: phase === \"done\" ? 100 : tracked.snapshot.percent,\n\t\t\t\tstalled: false,\n\t\t\t\terror: error === null ? null : clampText(error, ERROR_MAX),\n\t\t\t},\n\t\t}));\n\t\tif (phase === \"done\") yield* scheduleRemoval(id);\n\t});\n\n\tconst cloneWatchingForStall = Effect.fn(\"Clones.cloneWatchingForStall\")(function* (id: string, tracked: Tracked) {\n\t\tconst pulses = yield* Queue.sliding<void>(1);\n\t\tyield* watchForStall(id, pulses).pipe(Effect.forkScoped);\n\t\treturn yield* cloneRepository(id, tracked.cloneUrl, (update) =>\n\t\t\tQueue.offer(pulses, undefined).pipe(Effect.andThen(progress(id, update))),\n\t\t);\n\t}, Effect.scoped);\n\n\tconst describeFailure = (cause: Cause.Cause<unknown>) => {\n\t\tconst error = Cause.squash(cause);\n\t\treturn error instanceof Error && error.message.trim().length > 0 ? error.message : NOT_CLONED;\n\t};\n\n\t// `onExit` records the outcome even on interruption, which `matchCause` would skip.\n\tconst runClone = (id: string, tracked: Tracked) =>\n\t\tcloneWatchingForStall(id, tracked).pipe(\n\t\t\tEffect.onExit((exit) =>\n\t\t\t\tExit.isSuccess(exit)\n\t\t\t\t\t? finish(id, \"done\", null)\n\t\t\t\t\t: Cause.hasInterruptsOnly(exit.cause)\n\t\t\t\t\t\t? finish(id, \"cancelled\", null)\n\t\t\t\t\t\t: finish(id, \"failed\", describeFailure(exit.cause)),\n\t\t\t),\n\t\t\tEffect.ignoreCause(),\n\t\t);\n\n\tconst launch = Effect.fn(\"Clones.launch\")(function* (id: string) {\n\t\tconst tracked = (yield* Ref.get(clones)).get(id);\n\t\tif (!tracked) return;\n\t\tconst fiber = yield* runClone(id, tracked).pipe(Effect.forkIn(cloneScope));\n\t\tyield* Ref.update(clones, (map) => {\n\t\t\tconst existing = map.get(id);\n\t\t\tif (!existing) return map;\n\t\t\tconst next = new Map(map);\n\t\t\tnext.set(id, { ...existing, fiber });\n\t\t\treturn next;\n\t\t});\n\t});\n\n\tconst get = (id: string) => Ref.get(clones).pipe(Effect.map((current) => current.get(id)?.snapshot ?? null));\n\n\tconst start = Effect.fn(\"Clones.start\")(function* (input: { readonly remote: string; readonly path: string }) {\n\t\tconst prepared = yield* prepare(input);\n\t\tconst id = prepared.destination;\n\t\tconst snapshot: Contract.Clone = {\n\t\t\tpath: id,\n\t\t\tremote: prepared.remote,\n\t\t\tphase: \"running\",\n\t\t\tstage: \"connecting\",\n\t\t\tpercent: null,\n\t\t\tdetail: null,\n\t\t\tstalled: false,\n\t\t\terror: null,\n\t\t\tstartedAt: yield* Clock.currentTimeMillis,\n\t\t\tendedAt: null,\n\t\t\tsequence: ++sequence,\n\t\t};\n\t\tconst claimed = yield* Ref.modify(clones, (current): readonly [boolean, Map<string, Tracked>] => {\n\t\t\tif (current.has(id)) return [false, current];\n\t\t\tconst next = new Map(current);\n\t\t\tnext.set(id, { snapshot, fiber: null, cloneUrl: prepared.cloneUrl });\n\t\t\treturn [true, next];\n\t\t});\n\t\tif (!claimed) return yield* fail(\"A clone into this destination is already in progress.\");\n\t\t// A claim without a fiber can be neither cancelled nor retried, so it finishes or is released despite disconnects.\n\t\tyield* Effect.uninterruptible(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tyield* clearRetention(id);\n\t\t\t\tconst created = () => fail(\"Failed to create the clone destination.\");\n\t\t\t\tif (!(yield* fs.exists(id).pipe(Effect.mapError(created)))) {\n\t\t\t\t\tyield* fs.makeDirectory(id, { recursive: true }).pipe(Effect.mapError(created));\n\t\t\t\t}\n\t\t\t\tyield* publish;\n\t\t\t\tyield* launch(id);\n\t\t\t}).pipe(Effect.tapError(() => remove(id))),\n\t\t);\n\t\treturn { path: id, remote: prepared.remote };\n\t});\n\n\tconst cancel = Effect.fn(\"Clones.cancel\")(function* (input: string) {\n\t\tconst id = resolve(input);\n\t\tconst tracked = (yield* Ref.get(clones)).get(id);\n\t\tif (!tracked || tracked.snapshot.phase !== \"running\" || !tracked.fiber) return false;\n\t\tconst fiber = tracked.fiber;\n\t\t// Finished despite disconnects, so no running snapshot is left behind a dead fiber.\n\t\tyield* Effect.uninterruptible(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tyield* Fiber.interrupt(fiber);\n\t\t\t\tconst after = yield* get(id);\n\t\t\t\tif (after?.phase === \"done\") return;\n\t\t\t\tif (after?.phase === \"running\") yield* finish(id, \"cancelled\", null);\n\t\t\t\tyield* discardClone(id).pipe(Effect.ignore);\n\t\t\t}),\n\t\t);\n\t\treturn true;\n\t});\n\n\tconst retry = Effect.fn(\"Clones.retry\")(function* (input: string) {\n\t\tconst id = resolve(input);\n\t\tconst tracked = (yield* Ref.get(clones)).get(id);\n\t\tif (!tracked || (tracked.snapshot.phase !== \"failed\" && tracked.snapshot.phase !== \"cancelled\")) return false;\n\t\tyield* discardClone(id);\n\t\tconst startedAt = yield* Clock.currentTimeMillis;\n\t\tyield* modify(id, (entry) => ({\n\t\t\t...entry,\n\t\t\tsnapshot: {\n\t\t\t\t...entry.snapshot,\n\t\t\t\tphase: \"running\",\n\t\t\t\tstage: \"connecting\",\n\t\t\t\tpercent: null,\n\t\t\t\tdetail: null,\n\t\t\t\tstalled: false,\n\t\t\t\terror: null,\n\t\t\t\tstartedAt,\n\t\t\t\tendedAt: null,\n\t\t\t},\n\t\t}));\n\t\tyield* launch(id);\n\t\treturn true;\n\t});\n\n\tconst discard = Effect.fn(\"Clones.discard\")(function* (input: string) {\n\t\tconst id = resolve(input);\n\t\tconst tracked = (yield* Ref.get(clones)).get(id);\n\t\tif (!tracked) return;\n\t\tif (tracked.fiber) yield* Fiber.interrupt(tracked.fiber);\n\t\t// Git may have finished while the interrupt landed; a complete checkout is the user's.\n\t\tconst after = yield* get(id);\n\t\tif (after?.phase !== \"done\") yield* discardClone(id).pipe(Effect.ignore);\n\t\tyield* clearRetention(id);\n\t\tyield* remove(id);\n\t});\n\n\tconst guard = Effect.fn(\"Clones.guard\")(function* (input: string) {\n\t\tconst clone = yield* get(resolve(input));\n\t\tif (clone === null || clone.phase === \"done\") return;\n\t\treturn yield* fail(\n\t\t\tclone.phase === \"running\"\n\t\t\t\t? \"The repository is still being cloned.\"\n\t\t\t\t: \"The repository was not cloned. Retry the clone first.\",\n\t\t);\n\t});\n\n\tconst stream = Stream.callback<ReadonlyArray<Contract.Clone>>(\n\t\t(mailbox) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst subscription = yield* PubSub.subscribe(changes);\n\t\t\t\tQueue.offerUnsafe(mailbox, yield* list);\n\t\t\t\tyield* Stream.fromSubscription(subscription).pipe(\n\t\t\t\t\tStream.runForEach((snapshots) => Effect.sync(() => Queue.offerUnsafe(mailbox, snapshots))),\n\t\t\t\t\tEffect.forkScoped,\n\t\t\t\t);\n\t\t\t}),\n\t\t{ bufferSize: 1, strategy: \"sliding\" },\n\t);\n\n\treturn Service.of({\n\t\tstart: (input) => locked(start(input)),\n\t\tcancel: (path) => locked(cancel(path)),\n\t\tretry: (path) => locked(retry(path)),\n\t\tdiscard: (path) => locked(discard(path)),\n\t\tguard,\n\t\tstream,\n\t});\n});\n\nexport const layer = Layer.effect(Service, make);\n","import { Global } from \"@codeworksh/harness/effect\";\nimport { Door } from \"@codeworksh/schema/door\";\nimport { Forwarded } from \"@codeworksh/schema/forwarded\";\nimport { Jws } from \"@codeworksh/schema/jws\";\nimport { Pairing as Wire } from \"@codeworksh/schema/pairing\";\nimport { NodeServices } from \"@effect/platform-node\";\nimport { Clock, Context, Duration, Effect, FileSystem, Layer, Option, Path, Semaphore, Schema } from \"effect\";\nimport { HttpRouter, HttpServerRequest, HttpServerResponse } from \"effect/http\";\nimport type * as IpNetwork from \"effect/net/IpNetwork\";\nimport * as Private from \"../framework/private.ts\";\nimport * as MachineFile from \"../machine/file.ts\";\nimport type { DeviceInfo } from \"./contract.ts\";\n\n/**\n * How another computer becomes a device of this machine, as a key pairs over SSH. A person reads it a\n * pairing code from `codework service pair`, which it exchanges at `POST /api/v1/devices` with its public\n * key, and gets back this machine's identity key. For each socket it opens it then signs a proof with its\n * key at `POST /api/v1/tickets`, and gets back a ticket signed with the identity key, which it offers where\n * a local client offers the home's token. Codes, tickets and spent nonces live in memory; devices persist in\n * `<home>/devices.json`: each one's public key, and whether its last request came over TLS.\n */\n\nconst codeLife = Duration.toMillis(\"10 minutes\");\nconst ticketLife = Duration.toMillis(\"60 seconds\");\n/** How long a device may go without taking a ticket before it is refused. */\nconst idleLife = Duration.toMillis(\"30 days\");\n\n/** Crockford's base32: no I, L, O or U, so a code read aloud is typed back right. */\nconst alphabet = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\n/** `length` random base32 characters, each from a byte's low 5 bits, so each is uniform. */\nconst random = (length: number) =>\n\tEffect.sync(() =>\n\t\tArray.from(crypto.getRandomValues(new Uint8Array(length)), (byte) => alphabet.charAt(byte & 31)).join(\"\"),\n\t);\n\n/** A code as a person may type it back: any case, with or without its dash, I and L for 1, O for 0. */\nconst normalize = (code: string) => code.toUpperCase().replace(/[\\s-]/g, \"\").replace(/[IL]/g, \"1\").replace(/O/g, \"0\");\n\nconst Device = Schema.Struct({\n\tid: Schema.String,\n\tlabel: Schema.String,\n\tkey: Jws.PublicKey,\n\tcreatedAt: Schema.Finite,\n\tseenAt: Schema.Finite,\n\tencrypted: Schema.optional(Schema.Boolean),\n});\ntype Device = typeof Device.Type;\n\nconst devicesJson = Schema.fromJsonString(Schema.Array(Device));\nconst isDevice = Schema.is(Device);\nconst decodeProof = Schema.decodeUnknownEffect(Wire.Proof);\n/** The nonce a refusal echoes, read from a proof it never trusts, so only one a proof could carry. */\nconst decodeNonce = Schema.decodeUnknownEffect(\n\tSchema.Struct({ nonce: Schema.String.check(Schema.isMaxLength(64), Schema.isPattern(/^[A-Za-z0-9_-]+$/)) }),\n);\n\n/** `<home>/devices.json`: written by its server alone. */\nexport const file = (home: string) => `${home}/devices.json`;\n\n/** One-time secrets held until used or expired; each is taken at most once. */\nconst passes = <A>() => {\n\tlet held: ReadonlyArray<{ readonly secret: string; readonly expiresAt: number; readonly value: A }> = [];\n\treturn {\n\t\tissue: (secret: string, expiresAt: number, value: A) => {\n\t\t\theld = [...held, { secret, expiresAt, value }];\n\t\t},\n\t\ttake: (given: string, now: number) => {\n\t\t\theld = held.filter((pass) => pass.expiresAt > now);\n\t\t\tconst found = held.find((pass) => Door.matches(given, pass.secret));\n\t\t\theld = held.filter((pass) => pass !== found);\n\t\t\treturn found?.value;\n\t\t},\n\t\tdrop: (value: A) => {\n\t\t\theld = held.filter((pass) => pass.value !== value);\n\t\t},\n\t};\n};\n\nexport class Service extends Context.Service<\n\tService,\n\t{\n\t\t/** A fresh pairing code, `XXXXX-XXXXX`, and the fingerprint of the key the device will keep. */\n\t\treadonly code: Effect.Effect<{ readonly code: string; readonly expiresAt: number; readonly fingerprint: string }>;\n\t\t/** A new device holding `key` for a live code, which is spent, and the identity key; none for any other code. */\n\t\treadonly exchange: (\n\t\t\tcode: string,\n\t\t\tlabel: string,\n\t\t\tkey: Jws.PublicKey,\n\t\t\tencrypted: boolean,\n\t\t) => Effect.Effect<typeof Wire.Device.Type | undefined>;\n\t\t/**\n\t\t * A signed {@link Wire.Grant} for a good proof. Any other, or an unknown, revoked or idle device, is\n\t\t * refused: with a signed {@link Wire.Refusal} when the proof names a nonce, else with nothing.\n\t\t */\n\t\treadonly ticket: (\n\t\t\tproof: string,\n\t\t\tencrypted: boolean,\n\t\t) => Effect.Effect<\n\t\t\t{ readonly _tag: \"Granted\"; readonly jws: string } | { readonly _tag: \"Refused\"; readonly jws?: string }\n\t\t>;\n\t\t/** The device a live ticket was issued to, spending it; none otherwise. */\n\t\treadonly redeem: (ticket: string) => Effect.Effect<string | undefined>;\n\t\treadonly list: Effect.Effect<ReadonlyArray<DeviceInfo>>;\n\t\t/** Forgets a device and its tickets; false when none has `id`. */\n\t\treadonly revoke: (id: string) => Effect.Effect<boolean>;\n\t}\n>()(\"@codeworksh/cli/server/pairing/Service\") {}\n\nexport const layer = Layer.effect(\n\tService,\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst files = yield* Effect.context<FileSystem.FileSystem | Path.Path>();\n\t\tconst home = (yield* Global.Service).home;\n\t\tconst path = file(home);\n\t\tconst stored: ReadonlyArray<unknown> = (yield* fs.exists(path))\n\t\t\t? yield* fs.readFileString(path).pipe(\n\t\t\t\t\tEffect.flatMap(Schema.decodeEffect(Schema.fromJsonString(Schema.Array(Schema.Unknown)))),\n\t\t\t\t\tEffect.catch(() => Effect.die(`${path} is not a valid devices file`)),\n\t\t\t\t)\n\t\t\t: [];\n\t\t// A device paired before devices held keys pairs again; the next write drops it.\n\t\tlet devices: ReadonlyArray<Device> = stored.filter(isDevice);\n\t\tif (devices.length < stored.length)\n\t\t\tyield* Effect.logWarning(`${path}: ${stored.length - devices.length} device(s) must pair again`);\n\t\tconst codes = passes<true>();\n\t\tconst tickets = passes<string>();\n\t\t/** Each proof's nonce, until its proof is past the window. */\n\t\tconst nonces = new Map<string, number>();\n\t\t// One write at a time, each from the list the last one left.\n\t\tconst lock = yield* Semaphore.make(1);\n\t\tconst save = (next: ReadonlyArray<Device>) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tyield* Private.write(path, yield* Schema.encodeEffect(devicesJson)(next));\n\t\t\t\tdevices = next;\n\t\t\t}).pipe(Effect.provideContext(files), Effect.orDie);\n\t\tconst identity = MachineFile.identity(home).pipe(Effect.provideContext(files), Effect.orDie);\n\t\tconst fingerprint = (key: Jws.PublicKey) => Jws.fingerprint(key).pipe(Effect.orDie);\n\n\t\t/**\n\t\t * The device a proof is good for, by id: signed by the key of the device it names, inside the window,\n\t\t * its nonce unseen and now spent. Checked outside the lock, so a flood of bad proofs holds up no write.\n\t\t */\n\t\tconst proven = Effect.fnUntraced(\n\t\t\tfunction* (proof: string, now: number) {\n\t\t\t\tconst { kid } = yield* Jws.peek(proof);\n\t\t\t\tconst holders = yield* Effect.filter(devices, (device) =>\n\t\t\t\t\tEffect.map(Jws.thumbprint(device.key), (thumbprint) => thumbprint === kid),\n\t\t\t\t);\n\t\t\t\tconst [holder] = holders;\n\t\t\t\tif (holder === undefined) return undefined;\n\t\t\t\tconst claims = yield* Jws.verify(proof, holder.key).pipe(Effect.flatMap(decodeProof));\n\t\t\t\tconst device = holders.find((each) => each.id === claims.device);\n\t\t\t\tif (device === undefined || claims.aud !== (yield* identity).keyId) return undefined;\n\t\t\t\tif (Math.abs(now - claims.iat) > Wire.proofWindow) return undefined;\n\t\t\t\tfor (const [nonce, until] of nonces) if (until < now) nonces.delete(nonce);\n\t\t\t\tif (nonces.has(claims.nonce)) return undefined;\n\t\t\t\t// Held in memory only: a proof taken in the window before a restart is good once more after it.\n\t\t\t\tnonces.set(claims.nonce, claims.iat + Wire.proofWindow);\n\t\t\t\treturn { id: device.id, nonce: claims.nonce };\n\t\t\t},\n\t\t\tEffect.orElseSucceed(() => undefined),\n\t\t);\n\n\t\treturn Service.of({\n\t\t\tcode: Effect.gen(function* () {\n\t\t\t\tconst code = yield* random(10);\n\t\t\t\tconst expiresAt = (yield* Clock.currentTimeMillis) + codeLife;\n\t\t\t\tconst key = Jws.publicOf((yield* identity).key);\n\t\t\t\tcodes.issue(code, expiresAt, true);\n\t\t\t\treturn { code: `${code.slice(0, 5)}-${code.slice(5)}`, expiresAt, fingerprint: yield* fingerprint(key) };\n\t\t\t}),\n\t\t\texchange: (code, label, key, encrypted) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst now = yield* Clock.currentTimeMillis;\n\t\t\t\t\tif (codes.take(normalize(code), now) === undefined) return undefined;\n\t\t\t\t\tconst machine = Jws.publicOf((yield* identity).key);\n\t\t\t\t\tconst device: Device = {\n\t\t\t\t\t\tid: `dev_${(yield* random(10)).toLowerCase()}`,\n\t\t\t\t\t\tlabel,\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\t\tseenAt: now,\n\t\t\t\t\t\tencrypted,\n\t\t\t\t\t};\n\t\t\t\t\tyield* lock.withPermit(Effect.suspend(() => save([...devices, device])));\n\t\t\t\t\treturn { id: device.id, machine };\n\t\t\t\t}),\n\t\t\tticket: (proof, encrypted) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst refuse = Effect.gen(function* () {\n\t\t\t\t\t\tconst echoed = yield* Jws.peekClaims(proof).pipe(Effect.flatMap(decodeNonce), Effect.option);\n\t\t\t\t\t\tif (Option.isNone(echoed)) return { _tag: \"Refused\" } as const;\n\t\t\t\t\t\tconst { key, keyId } = yield* identity;\n\t\t\t\t\t\tconst refusal: Wire.Refusal = {\n\t\t\t\t\t\t\top: \"ticket.refuse\",\n\t\t\t\t\t\t\tnonce: echoed.value.nonce,\n\t\t\t\t\t\t\tat: yield* Clock.currentTimeMillis,\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t_tag: \"Refused\",\n\t\t\t\t\t\t\tjws: yield* Jws.sign(refusal, key, { kid: keyId }).pipe(Effect.orDie),\n\t\t\t\t\t\t} as const;\n\t\t\t\t\t});\n\t\t\t\t\tconst proved = yield* proven(proof, yield* Clock.currentTimeMillis);\n\t\t\t\t\tif (proved === undefined) return yield* refuse;\n\t\t\t\t\tconst ticket = yield* lock.withPermit(\n\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\tconst now = yield* Clock.currentTimeMillis;\n\t\t\t\t\t\t\t// Found again: it may have been revoked since its proof was checked.\n\t\t\t\t\t\t\tconst device = devices.find((each) => each.id === proved.id);\n\t\t\t\t\t\t\tif (device === undefined || now - device.seenAt > idleLife) return undefined;\n\t\t\t\t\t\t\tyield* save(\n\t\t\t\t\t\t\t\tdevices.map((each) => (each === device ? { ...device, seenAt: now, encrypted } : each)),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst ticket = yield* Door.make;\n\t\t\t\t\t\t\ttickets.issue(ticket, now + ticketLife, device.id);\n\t\t\t\t\t\t\treturn ticket;\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tif (ticket === undefined) return yield* refuse;\n\t\t\t\t\tconst { key, keyId } = yield* identity;\n\t\t\t\t\tconst grant: Wire.Grant = { op: \"ticket.grant\", ticket, nonce: proved.nonce };\n\t\t\t\t\treturn { _tag: \"Granted\", jws: yield* Jws.sign(grant, key, { kid: keyId }).pipe(Effect.orDie) } as const;\n\t\t\t\t}),\n\t\t\tredeem: (ticket) =>\n\t\t\t\tEffect.map(Clock.currentTimeMillis, (now) => {\n\t\t\t\t\tconst id = tickets.take(ticket, now);\n\t\t\t\t\treturn devices.some((device) => device.id === id) ? id : undefined;\n\t\t\t\t}),\n\t\t\tlist: Effect.suspend(() =>\n\t\t\t\tEffect.forEach(devices, ({ id, label, key, createdAt, seenAt, encrypted }) =>\n\t\t\t\t\tEffect.map(fingerprint(key), (fingerprint) => ({\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tlabel,\n\t\t\t\t\t\tfingerprint,\n\t\t\t\t\t\tcreatedAt,\n\t\t\t\t\t\tseenAt,\n\t\t\t\t\t\t...(encrypted === undefined ? {} : { encrypted }),\n\t\t\t\t\t})),\n\t\t\t\t),\n\t\t\t),\n\t\t\trevoke: (id) =>\n\t\t\t\tlock.withPermit(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tif (!devices.some((device) => device.id === id)) return false;\n\t\t\t\t\t\tyield* save(devices.filter((device) => device.id !== id));\n\t\t\t\t\t\ttickets.drop(id);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t});\n\t}),\n).pipe(Layer.provide(NodeServices.layer));\n\nconst refused = HttpServerResponse.empty({ status: 401 });\n\n/** The peers besides loopback whose `X-Forwarded-Proto` the pairing routes believe. */\nexport const TrustedProxy = Context.Reference<ReadonlyArray<IpNetwork.IpNetwork>>(\n\t\"@codeworksh/cli/server/pairing/TrustedProxy\",\n\t{ defaultValue: () => [] },\n);\n\n/** The routes {@link routes} serves, which take no socket credential. */\nexport const paths: ReadonlyArray<string> = [Wire.devicesPath, Wire.ticketsPath];\n\n/** The pairing routes of the shared wire contract. */\nexport const routes = HttpRouter.use((router) =>\n\tEffect.gen(function* () {\n\t\tconst pairing = yield* Service;\n\t\tconst trusted = yield* TrustedProxy;\n\t\tyield* router.add(\n\t\t\t\"POST\",\n\t\t\tWire.devicesPath,\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst request = yield* HttpServerRequest.HttpServerRequest;\n\t\t\t\tconst body = yield* HttpServerRequest.schemaBodyJson(Wire.Exchange).pipe(Effect.option);\n\t\t\t\tif (body._tag === \"None\") return HttpServerResponse.empty({ status: 400 });\n\t\t\t\tconst device = yield* pairing.exchange(\n\t\t\t\t\tbody.value.code,\n\t\t\t\t\tbody.value.label,\n\t\t\t\t\tbody.value.key,\n\t\t\t\t\tForwarded.encrypted(request, trusted),\n\t\t\t\t);\n\t\t\t\treturn device === undefined ? refused : HttpServerResponse.jsonUnsafe(device, { status: 201 });\n\t\t\t}),\n\t\t);\n\t\tyield* router.add(\n\t\t\t\"POST\",\n\t\t\tWire.ticketsPath,\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst request = yield* HttpServerRequest.HttpServerRequest;\n\t\t\t\tconst body = yield* HttpServerRequest.schemaBodyJson(Wire.Signed).pipe(Effect.option);\n\t\t\t\tif (Option.isNone(body)) return refused;\n\t\t\t\tconst answer = yield* pairing.ticket(body.value.jws, Forwarded.encrypted(request, trusted));\n\t\t\t\tif (answer.jws === undefined) return refused;\n\t\t\t\treturn HttpServerResponse.jsonUnsafe(\n\t\t\t\t\t{ jws: answer.jws },\n\t\t\t\t\t{ status: answer._tag === \"Granted\" ? 201 : 401 },\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t}),\n);\n","import { Global } from \"@codeworksh/harness/effect\";\nimport { Actor } from \"@codeworksh/schema/actor\";\nimport { Door as Knock } from \"@codeworksh/schema/door\";\nimport { NodeServices } from \"@effect/platform-node\";\nimport { Current, Forbidden, type Principal } from \"@codeworksh/schema/host/principal\";\nimport { Context, Effect, FileSystem, Layer } from \"effect\";\n\nexport { Current, Door, Forbidden, type Principal, Unauthorized } from \"@codeworksh/schema/host/principal\";\n\n/** Outer-layer actor resolved at the door; the harness only ever receives `ref`. */\nexport type HostActor =\n\t| { readonly kind: \"root\"; readonly ref: Actor.ActorRef }\n\t| { readonly kind: \"user\"; readonly ref: Actor.ActorRef; readonly name: string }\n\t| {\n\t\t\treadonly kind: \"app\";\n\t\t\treadonly ref: Actor.ActorRef;\n\t\t\treadonly name: string;\n\t\t\treadonly issuer: string;\n\t\t\treadonly owner: string;\n\t };\n\n/** Every caller the door admits today (local token or paired device) acts as root on this home. */\nexport const actorOf = (_principal: Principal): HostActor => ({ kind: \"root\", ref: Actor.root });\n\n/** `effect`, for a local caller only; a device is refused. */\nexport const local = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n\tEffect.gen(function* () {\n\t\tif ((yield* Current).kind !== \"local\")\n\t\t\treturn yield* new Forbidden({ message: \"Only this computer manages its paired devices\" });\n\t\treturn yield* effect;\n\t});\n\n/** The home's token for the life of the server, which every local client sends. */\nexport class Token extends Context.Service<Token, string>()(\"@codeworksh/cli/server/principal/Token\") {}\n\n/**\n * A fresh token per start, published in `service.json` alone. A `<home>/token` an earlier build kept\n * is deleted, so no stale copy of a credential stays behind.\n */\nexport const layerToken = Layer.effect(\n\tToken,\n\tEffect.gen(function* () {\n\t\tconst global = yield* Global.Service;\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tyield* fs.remove(`${global.home}/token`).pipe(Effect.ignore);\n\t\treturn yield* Knock.make;\n\t}).pipe(Effect.provide(NodeServices.layer)),\n);\n","import { Actor } from \"@codeworksh/schema/actor\";\nimport { Forwarded } from \"@codeworksh/schema/forwarded\";\nimport { Door as Knock } from \"@codeworksh/schema/door\";\nimport { Context, Deferred, Effect, Layer, Option } from \"effect\";\nimport { Headers, HttpRouter, type HttpServerRequest, HttpServerResponse } from \"effect/http\";\nimport * as NetAddress from \"effect/net/NetAddress\";\nimport { RpcServer } from \"effect/rpc\";\nimport * as Contract from \"./contract.ts\";\nimport * as Pairing from \"./pairing.ts\";\nimport * as Principal from \"./principal.ts\";\n\n/**\n * How a caller gets in, and stays in only as long as it may. The door judges a socket's credential\n * once, before the upgrade, and files the connection under a key it adds to the upgrade request as\n * {@link header}. The upgrade request's headers come with every call on that socket, so each call\n * finds its caller by that key. A key never leaves the server, so a client cannot claim another\n * connection by sending one in a call's own headers, which would override the upgrade's.\n */\nexport const header = \"x-codework-connection\";\n\ninterface Connection {\n\treadonly principal: Principal.Principal;\n\treadonly ended: Deferred.Deferred<void>;\n}\n\n/** The connections the door let in, by key. */\nexport class Connections extends Context.Service<\n\tConnections,\n\t{\n\t\t/** Files a connection for `principal`, answering its key. */\n\t\treadonly open: (principal: Principal.Principal) => Effect.Effect<string>;\n\t\t/** Who is on the connection `key` names; none once it ended. */\n\t\treadonly find: (key: string | undefined) => Principal.Principal | undefined;\n\t\t/** The keys of a device's open connections. */\n\t\treadonly device: (id: string) => ReadonlyArray<string>;\n\t\t/** Ends a connection: its calls stop, and its socket closes. */\n\t\treadonly end: (key: string) => Effect.Effect<void>;\n\t\t/** Runs `effect`, the connection's socket, until it finishes or the connection is ended. */\n\t\treadonly serve: <E, R>(\n\t\t\tkey: string,\n\t\t\teffect: Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>,\n\t\t) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>;\n\t}\n>()(\"@codeworksh/cli/server/door/Connections\") {}\n\nexport const layerConnections = Layer.sync(Connections, () => {\n\tconst held = new Map<string, Connection>();\n\tconst end = (key: string) =>\n\t\tEffect.suspend(() => {\n\t\t\tconst connection = held.get(key);\n\t\t\theld.delete(key);\n\t\t\treturn connection === undefined ? Effect.void : Deferred.succeed(connection.ended, undefined);\n\t\t});\n\treturn Connections.of({\n\t\topen: (principal) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst key = yield* Knock.make;\n\t\t\t\theld.set(key, { principal, ended: yield* Deferred.make<void>() });\n\t\t\t\treturn key;\n\t\t\t}),\n\t\tfind: (key) => (key === undefined ? undefined : held.get(key)?.principal),\n\t\tdevice: (id) =>\n\t\t\t[...held].flatMap(([key, { principal }]) => (principal.kind === \"device\" && principal.id === id ? [key] : [])),\n\t\tend,\n\t\tserve: (key, effect) => {\n\t\t\tconst connection = held.get(key);\n\t\t\tif (connection === undefined) return Effect.succeed(HttpServerResponse.empty({ status: 401 }));\n\t\t\treturn Effect.raceFirst(\n\t\t\t\teffect,\n\t\t\t\tDeferred.await(connection.ended).pipe(Effect.as(HttpServerResponse.empty())),\n\t\t\t).pipe(Effect.ensuring(end(key)));\n\t\t},\n\t});\n});\n\n/** Whether `request` comes from this computer, by its peer address: no header can say so. */\nconst fromLoopback = (request: HttpServerRequest.HttpServerRequest) => {\n\tconst peer = Forwarded.peer(request);\n\treturn peer !== undefined && NetAddress.isLoopback(peer);\n};\n\nconst pathname = (request: HttpServerRequest.HttpServerRequest) => new URL(request.url, \"http://localhost\").pathname;\n\n/**\n * The listener's door before any upgrade: no browser origin is served. The pairing routes take no\n * credential here, as each checks its own. The socket takes the home's token from a loopback peer,\n * or a live ticket, which it spends.\n */\nexport const listener = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\tconst token = yield* Principal.Token;\n\t\tconst pairing = yield* Pairing.Service;\n\t\tconst connections = yield* Connections;\n\t\tconst caller = (offered: string, request: HttpServerRequest.HttpServerRequest) =>\n\t\t\tKnock.matches(offered, token)\n\t\t\t\t? Effect.succeed<Principal.Principal | undefined>(fromLoopback(request) ? { kind: \"local\" } : undefined)\n\t\t\t\t: Effect.map(pairing.redeem(offered), (id) =>\n\t\t\t\t\t\tid === undefined ? undefined : ({ kind: \"device\", id } as const),\n\t\t\t\t\t);\n\t\treturn Knock.layer({\n\t\t\torigins: [],\n\t\t\tadmit: (offered, request) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst path = pathname(request);\n\t\t\t\t\tif (request.method === \"POST\" && Pairing.paths.includes(path)) return request;\n\t\t\t\t\tif (request.method !== \"GET\" || path !== Contract.path || offered === undefined) return undefined;\n\t\t\t\t\tconst principal = yield* caller(offered, request);\n\t\t\t\t\tif (principal === undefined) return undefined;\n\t\t\t\t\tconst key = yield* connections.open(principal);\n\t\t\t\t\treturn request.modify({ headers: Headers.set(request.headers, header, key) });\n\t\t\t\t}),\n\t\t});\n\t}),\n);\n\n/** The socket route of the RPC server: each connection runs until it closes or is ended. */\nexport const protocol = Layer.effect(\n\tRpcServer.Protocol,\n\tEffect.gen(function* () {\n\t\tconst { httpEffect, protocol } = yield* RpcServer.makeProtocolWithHttpEffectWebsocket;\n\t\tconst connections = yield* Connections;\n\t\tconst router = yield* HttpRouter.HttpRouter;\n\t\tyield* router.add(\"GET\", Contract.path, (request) =>\n\t\t\t// Scoped here, so ending the connection closes its socket and drops its calls at once.\n\t\t\tconnections.serve(request.headers[header] ?? \"\", Effect.scoped(httpEffect)),\n\t\t);\n\t\treturn protocol;\n\t}),\n);\n\n/** The door on every call: the caller of the connection it came on, which must still be open. */\nexport const rpc = Layer.effect(\n\tPrincipal.Door,\n\tEffect.gen(function* () {\n\t\tconst connections = yield* Connections;\n\t\treturn Principal.Door.of((effect, { headers }) => {\n\t\t\tconst principal = connections.find(Option.getOrUndefined(Headers.get(headers, header)));\n\t\t\treturn principal === undefined\n\t\t\t\t? Effect.fail(new Principal.Unauthorized({ message: \"This connection is not open to this server\" }))\n\t\t\t\t: effect.pipe(\n\t\t\t\t\t\tEffect.provideService(Principal.Current, principal),\n\t\t\t\t\t\tEffect.provideService(Actor.Current, Principal.actorOf(principal).ref),\n\t\t\t\t\t);\n\t\t});\n\t}),\n);\n","import { Event, EventRegistry, EventSchema } from \"@codeworksh/harness/effect\";\nimport { Cause, Context, Effect, Layer, Option, Queue, type Scope, Stream } from \"effect\";\nimport * as Envelope from \"./envelope.ts\";\nimport { EncodingError, type EventEnvelope } from \"./envelope.ts\";\n\nconst SubscriberCapacity = 4096;\n\nexport type Error = Event.SubscriptionOverflowError | EncodingError;\n\n/** What one client receives; checked before an event takes a place in its queue. */\nexport interface Filter {\n\t/** Only these types. */\n\treadonly types?: ReadonlySet<string>;\n\t/** Only events naming this thread. */\n\treadonly threadId?: string;\n}\n\ntype Stream_ = Effect.Effect<Stream.Stream<EventEnvelope, Error>, never, Scope.Scope>;\n\nexport interface Interface {\n\t/** A live envelope stream for one client; releasing the scope unregisters it. */\n\treadonly subscribe: Stream_;\n\t/**\n\t * {@link subscribe}, with a filter applied before an event takes a place in the queue. `replay` is\n\t * read in the step that registers the client, and its events lead the stream.\n\t */\n\treadonly filtered: (filter: Filter, replay?: () => ReadonlyArray<EventSchema.Payload>) => Stream_;\n}\n\nexport class Service extends Context.Service<Service, Interface>()(\"@codeworksh/cli/server/feed/Service\") {}\n\n/**\n * Fan-out for `event.subscribe`. One listener on the event bus encodes each\n * event once and hands the same envelope to every client, rather than every\n * client re-encoding the same payload.\n *\n * Failure is per-cause, not per-feed: a client that cannot keep up fails alone\n * with its own overflow, while an event that cannot be encoded is a server bug\n * that disconnects everyone currently attached -- the feed stays usable for\n * whoever connects next. Types outside the server's registry are dropped\n * before they can consume a client's capacity.\n */\nexport const make = Effect.fn(\"EventFeed.make\")(function* (\n\tlisten: (subscriber: Event.Subscriber) => Effect.Effect<Event.Unsubscribe>,\n\toptions?: { readonly capacity?: number; readonly registry?: Envelope.Registry },\n) {\n\tconst capacity = options?.capacity ?? SubscriberCapacity;\n\t// Whatever this server knows how to describe, plugin registrations included.\n\tconst registry = options?.registry ?? Envelope.Core;\n\tconst subscribers = new Map<Queue.Queue<EventEnvelope, Error>, Filter>();\n\n\tconst failAll = (error: Error) =>\n\t\tEffect.sync(() => {\n\t\t\tconst current = Array.from(subscribers.keys());\n\t\t\tsubscribers.clear();\n\t\t\tfor (const subscriber of current) Queue.failCauseUnsafe(subscriber, Cause.fail(error));\n\t\t});\n\n\tconst deliver = Effect.fnUntraced(function* (event: EventSchema.Payload) {\n\t\tif (subscribers.size === 0) return;\n\t\t// Dropped here rather than after the queue: a burst of events this server\n\t\t// cannot describe must not spend a client's capacity on its way to nowhere.\n\t\tif (registry(event.type) === undefined) return;\n\t\tconst envelope = yield* Envelope.encode(event, registry);\n\t\tfor (const [subscriber, filter] of subscribers) {\n\t\t\tif (!accepts(filter, envelope)) continue;\n\t\t\tif (Queue.offerUnsafe(subscriber, envelope)) continue;\n\t\t\tsubscribers.delete(subscriber);\n\t\t\tQueue.failCauseUnsafe(subscriber, Cause.fail(new Event.SubscriptionOverflowError({ capacity })));\n\t\t}\n\t});\n\n\tconst publish = (event: EventSchema.Payload) =>\n\t\tdeliver(event).pipe(\n\t\t\tEffect.catchTags({\n\t\t\t\tEventEncodingError: (error) =>\n\t\t\t\t\tEffect.logError(\"Failed to encode public event\", { type: error.type, cause: error.cause }).pipe(\n\t\t\t\t\t\tEffect.andThen(failAll(error)),\n\t\t\t\t\t),\n\t\t\t\t// The registry guard in `deliver` already returned for unknown types.\n\t\t\t\tUnknownEventTypeError: Effect.die,\n\t\t\t}),\n\t\t);\n\n\tconst accepts = (filter: Filter, envelope: EventEnvelope) =>\n\t\t(filter.types === undefined || filter.types.has(envelope.type)) &&\n\t\t(filter.threadId === undefined || Envelope.ofThread(filter.threadId)(envelope));\n\n\tconst filtered: Interface[\"filtered\"] = (filter, replay = () => []) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst queue = yield* Effect.acquireRelease(Queue.dropping<EventEnvelope, Error>(capacity), (queue) =>\n\t\t\t\tEffect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue))),\n\t\t\t);\n\t\t\t// Read and registered in one step: an event published after the snapshot is delivered live.\n\t\t\tconst missed = yield* Effect.sync(() => {\n\t\t\t\tsubscribers.set(queue, filter);\n\t\t\t\treturn replay();\n\t\t\t});\n\t\t\tconst replayed: Array<EventEnvelope> = [];\n\t\t\tfor (const event of missed) {\n\t\t\t\tif (registry(event.type) === undefined) continue;\n\t\t\t\tconst envelope = yield* Envelope.encode(event, registry).pipe(Effect.option);\n\t\t\t\tif (Option.isSome(envelope) && accepts(filter, envelope.value)) replayed.push(envelope.value);\n\t\t\t}\n\t\t\treturn Stream.fromIterable(replayed).pipe(Stream.concat(Stream.fromQueue(queue)));\n\t\t});\n\n\tconst unsubscribe = yield* listen(publish);\n\tyield* Effect.addFinalizer(() => unsubscribe);\n\n\treturn Service.of({\n\t\tsubscribe: filtered({}),\n\t\tfiltered,\n\t});\n});\n\nexport const layer = Layer.effect(\n\tService,\n\tEffect.gen(function* () {\n\t\tconst events = yield* Event.Service;\n\t\tconst registered = yield* EventRegistry.Service;\n\t\treturn yield* make(events.listen, { registry: registered.get });\n\t}),\n);\n","/**\n * Host folders for adding a project: browsing directories, creating and adding one, and looking\n * repositories up through the GitHub CLI. Everything here runs on the server's host.\n */\n/* @effect-diagnostics nodeBuiltinImport:off -- browsing needs directory entries with their types, and the OS home. */\nimport { readdir } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { expandTilde, Git } from \"@codeworksh/harness/effect\";\nimport { Context, Effect, FileSystem, Layer, Option, Path, type PlatformError, Schema, Stream } from \"effect\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport * as Contract from \"./contract.ts\";\n\nexport interface Status {\n\treadonly ready: boolean;\n\treadonly hint?: string;\n}\n\ninterface Interface {\n\treadonly info: { readonly home: string; readonly projects: string };\n\treadonly browse: (\n\t\tpath: string,\n\t) => Effect.Effect<\n\t\t{ readonly path: string; readonly entries: ReadonlyArray<Contract.Folder>; readonly readable: boolean },\n\t\tContract.HostError\n\t>;\n\treadonly add: (path: string) => Effect.Effect<{ readonly path: string }, Contract.HostError>;\n\treadonly create: (\n\t\tname: string,\n\t) => Effect.Effect<{ readonly path: string; readonly commitError?: string }, Contract.HostError>;\n\treadonly status: () => Effect.Effect<Status>;\n\treadonly lookup: (repository: string) => Effect.Effect<Contract.Repository, Contract.HostError>;\n\t/** The `origin` URL of the checkout at `directory`, with any credentials taken out; none without one. */\n\treadonly remote: (directory: string) => Effect.Effect<string | undefined>;\n}\n\nexport class Service extends Context.Service<Service, Interface>()(\"@codeworksh/cli/server/host/Service\") {}\n\nconst MAX_NAME = 200;\nconst MAX_ATTEMPTS = 100;\nconst INSTALL_GH = \"Install the GitHub CLI (gh) to clone GitHub repositories.\";\nconst LOGIN_GH = \"Run `gh auth login` to sign in to GitHub.\";\nconst NOT_FOUND = \"Repository not found. Check the owner and name and try again.\";\nconst NOT_NAMED = \"Repositories are named owner/name.\";\n\nconst fail = (message: string, reason?: \"missing\" | \"file\") =>\n\tnew Contract.HostError(reason === undefined ? { message } : { message, reason });\n\nconst describe = (error: PlatformError.PlatformError, target: string) =>\n\terror.reason._tag === \"NotFound\"\n\t\t? `${target} does not exist.`\n\t\t: error.reason._tag === \"PermissionDenied\"\n\t\t\t? `Permission denied: ${target}`\n\t\t\t: error.message;\n\n/** The folder `host.create` claims for a project name: a slug that is never empty or a reserved Windows name. */\nconst folderName = (name: string) => {\n\tconst slug = name\n\t\t.normalize(\"NFKD\")\n\t\t.replace(/[̀-ͯ]/g, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+/, \"\")\n\t\t.slice(0, 64)\n\t\t.replace(/-+$/, \"\");\n\tif (slug.length === 0) return \"project\";\n\treturn /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/.test(slug) ? `${slug}-project` : slug;\n};\n\nconst commitFailure = (stderr: string) => {\n\tif (\n\t\t/identity unknown|tell me who you are|no (name|email) was given|unable to auto-detect email|empty ident/i.test(\n\t\t\tstderr,\n\t\t)\n\t) {\n\t\treturn \"Git has no name or email set, so the first commit was skipped.\";\n\t}\n\tconst line = stderr\n\t\t.split(\"\\n\")\n\t\t.map((text) => text.trim())\n\t\t.filter(Boolean)\n\t\t.at(-1);\n\treturn `The first commit was skipped: ${line ?? \"git could not make it.\"}`;\n};\n\nexport interface Selector {\n\treadonly host: string;\n\t/** Absent for a bare name: the signed-in user's. */\n\treadonly owner?: string;\n\treadonly name: string;\n}\n\n// Owner and name land in an API path, so anything outside GitHub's own alphabet is refused.\nconst SEGMENT = /^[A-Za-z0-9_.-]+$/;\nconst isGitHubHost = (host: string) => host === \"github.com\" || host.includes(\"github\");\n\n/** `owner/name`, `host/owner/name`, an http(s) URL, or a bare `name`; undefined for anything else. */\nconst parseRepository = (selector: string): Selector | undefined => {\n\t// Like gh, a clone URL's `.git` comes off the path, before any trailing slash.\n\tconst segments = (value: string) =>\n\t\tvalue\n\t\t\t.replace(/\\.git\\/*$/i, \"\")\n\t\t\t.split(\"/\")\n\t\t\t.filter(Boolean);\n\tconst named = (host: string, owner: string | undefined, name: string | undefined): Selector | undefined =>\n\t\tname !== undefined && SEGMENT.test(name) && (owner === undefined || SEGMENT.test(owner))\n\t\t\t? { host, name, ...(owner === undefined ? {} : { owner }) }\n\t\t\t: undefined;\n\tconst trimmed = selector.trim();\n\tif (/^https?:\\/\\//i.test(trimmed)) {\n\t\tconst url = URL.parse(trimmed);\n\t\tconst parts = url === null ? [] : segments(url.pathname);\n\t\treturn url !== null && parts.length === 2 ? named(url.host.toLowerCase(), parts[0], parts[1]) : undefined;\n\t}\n\tconst parts = segments(trimmed);\n\tconst [first, second, third] = parts;\n\tif (parts.length === 1) return named(\"github.com\", undefined, first);\n\tif (parts.length === 2) return named(\"github.com\", first, second);\n\tconst host = first?.toLowerCase();\n\treturn parts.length === 3 && host !== undefined && isGitHubHost(host) ? named(host, second, third) : undefined;\n};\n\n/**\n * A remote URL safe to show: an http(s) URL loses its user and password, which may be a token\n * (`https://x-access-token:...@github.com/...`). SSH and local forms carry none and pass as they are.\n */\nconst shownRemote = (url: string) => {\n\tif (!/^https?:\\/\\//i.test(url)) return url;\n\tconst parsed = URL.parse(url);\n\tif (parsed === null) return url;\n\tparsed.username = \"\";\n\tparsed.password = \"\";\n\treturn parsed.toString();\n};\n\nconst decodeRepository = Schema.decodeUnknownEffect(\n\tSchema.fromJsonString(Schema.Struct({ full_name: Schema.String, html_url: Schema.String, ssh_url: Schema.String })),\n);\n\nconst make = Effect.gen(function* () {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst path = yield* Path.Path;\n\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n\tconst git = yield* Git.Service;\n\tconst home = homedir();\n\t// Projects are the user's work, so they live in plain sight rather than in the CodeWork home.\n\tconst info = { home, projects: path.join(home, \"codework\", \"projects\") };\n\tconst resolve = (value: string) => path.resolve(expandTilde(value, path));\n\tconst failed = (target: string) => (error: PlatformError.PlatformError) => fail(describe(error, target));\n\tconst stat = (target: string) =>\n\t\tfs.stat(target).pipe(\n\t\t\tEffect.asSome,\n\t\t\tEffect.catchIf(\n\t\t\t\t(error) => error.reason._tag === \"NotFound\",\n\t\t\t\t() => Effect.succeedNone,\n\t\t\t),\n\t\t\tEffect.mapError(failed(target)),\n\t\t);\n\n\tconst browse = Effect.fn(\"Host.browse\")(function* (input: string) {\n\t\tconst directory = resolve(input);\n\t\tconst listed = yield* Effect.tryPromise({\n\t\t\ttry: () => readdir(directory, { withFileTypes: true }),\n\t\t\tcatch: (cause) => (cause instanceof Error && \"code\" in cause ? String(cause.code) : undefined),\n\t\t}).pipe(\n\t\t\tEffect.map((entries) => ({ entries, readable: true })),\n\t\t\tEffect.catchIf(\n\t\t\t\t(code) => code === \"EACCES\" || code === \"EPERM\",\n\t\t\t\t() => Effect.succeed({ entries: [], readable: false }),\n\t\t\t),\n\t\t\tEffect.mapError((code) =>\n\t\t\t\tcode === \"ENOENT\"\n\t\t\t\t\t? fail(`${directory} does not exist.`, \"missing\")\n\t\t\t\t\t: code === \"ENOTDIR\"\n\t\t\t\t\t\t? fail(`${directory} is not a directory.`, \"file\")\n\t\t\t\t\t\t: fail(`Could not read ${directory}.`),\n\t\t\t),\n\t\t);\n\t\treturn {\n\t\t\tpath: directory,\n\t\t\treadable: listed.readable,\n\t\t\tentries: listed.entries\n\t\t\t\t.filter((entry) => entry.isDirectory())\n\t\t\t\t.map((entry) => ({ name: entry.name, path: path.join(directory, entry.name) }))\n\t\t\t\t.toSorted((a, b) => a.name.localeCompare(b.name)),\n\t\t};\n\t});\n\n\tconst add = Effect.fn(\"Host.add\")(function* (input: string) {\n\t\tconst directory = resolve(input);\n\t\tconst found = yield* stat(directory);\n\t\tif (Option.isNone(found)) {\n\t\t\tyield* fs.makeDirectory(directory, { recursive: true }).pipe(Effect.mapError(failed(directory)));\n\t\t} else if (found.value.type !== \"Directory\") {\n\t\t\treturn yield* fail(`${directory} is not a directory.`, \"file\");\n\t\t}\n\t\treturn { path: directory };\n\t});\n\n\t// A non-recursive mkdir claims a name atomically; a racer that loses moves on to the next.\n\tconst claim = Effect.fn(\"Host.claim\")(function* (slug: string) {\n\t\tfor (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {\n\t\t\tconst folder = path.join(info.projects, attempt === 1 ? slug : `${slug}-${attempt}`);\n\t\t\tconst claimed = yield* fs.makeDirectory(folder).pipe(\n\t\t\t\tEffect.as(true),\n\t\t\t\tEffect.catchIf(\n\t\t\t\t\t(error) => error.reason._tag === \"AlreadyExists\",\n\t\t\t\t\t() => Effect.succeed(false),\n\t\t\t\t),\n\t\t\t\tEffect.mapError(failed(folder)),\n\t\t\t);\n\t\t\tif (claimed) return folder;\n\t\t}\n\t\treturn yield* fail(`Every folder name for \"${slug}\" is taken in ${info.projects}.`);\n\t});\n\n\t/** A repository with a README; answers why the first commit was skipped, if it was. */\n\tconst scaffold = Effect.fn(\"Host.scaffold\")(function* (folder: string, name: string) {\n\t\tconst configured = yield* git.exec(folder, [\"config\", \"--get\", \"init.defaultBranch\"]).pipe(\n\t\t\tEffect.map((result) => (result.exitCode === 0 ? result.text.trim() : \"\")),\n\t\t\tEffect.orElseSucceed(() => \"\"),\n\t\t);\n\t\tyield* git.init(folder, { branch: configured || \"main\" }).pipe(Effect.mapError((error) => fail(error.message)));\n\t\tconst readme = path.join(folder, \"README.md\");\n\t\tyield* fs.writeFileString(readme, `# ${name}\\n`).pipe(Effect.mapError(failed(readme)));\n\t\t// Named and forced, so a global ignore rule cannot leave the first commit empty.\n\t\tconst added = yield* git\n\t\t\t.exec(folder, [\"add\", \"--force\", \"--\", \"README.md\"])\n\t\t\t.pipe(Effect.mapError(() => fail(\"Could not run git add.\")));\n\t\tif (added.exitCode !== 0) return yield* fail(added.stderr.trim() || \"git add failed.\");\n\t\tconst committed = yield* git.exec(folder, [\"commit\", \"--message\", \"Initial commit\"]).pipe(Effect.option);\n\t\tif (Option.isNone(committed)) return \"Could not run git commit, so the first commit was skipped.\";\n\t\treturn committed.value.exitCode === 0 ? undefined : commitFailure(committed.value.stderr);\n\t});\n\n\tconst create = Effect.fn(\"Host.create\")(function* (input: string) {\n\t\tconst name = input.trim();\n\t\tif (name.length === 0) return yield* fail(\"A project needs a name.\");\n\t\tif (name.length > MAX_NAME) return yield* fail(`A project name is at most ${MAX_NAME} characters.`);\n\t\tyield* fs.makeDirectory(info.projects, { recursive: true }).pipe(Effect.mapError(failed(info.projects)));\n\t\tconst folder = yield* claim(folderName(name));\n\t\tconst commitError = yield* scaffold(folder, name).pipe(\n\t\t\tEffect.onError(() => fs.remove(folder, { recursive: true }).pipe(Effect.ignore)),\n\t\t);\n\t\treturn { path: folder, ...(commitError === undefined ? {} : { commitError }) };\n\t});\n\n\tconst gh = Effect.fn(\"Host.gh\")(function* (args: ReadonlyArray<string>) {\n\t\tconst handle = yield* spawner.spawn(\n\t\t\tChildProcess.make(\"gh\", [...args], {\n\t\t\t\tenv: { GH_PROMPT_DISABLED: \"1\", NO_COLOR: \"1\" },\n\t\t\t\textendEnv: true,\n\t\t\t\tstdin: \"ignore\",\n\t\t\t\tstdout: \"pipe\",\n\t\t\t\tstderr: \"pipe\",\n\t\t\t}),\n\t\t);\n\t\t// Drained alongside the exit wait: a full pipe would otherwise stall gh.\n\t\treturn yield* Effect.all(\n\t\t\t{\n\t\t\t\texitCode: handle.exitCode,\n\t\t\t\tstdout: handle.stdout.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t\tstderr: handle.stderr.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t},\n\t\t\t{ concurrency: \"unbounded\" },\n\t\t);\n\t}, Effect.scoped);\n\n\tconst status = Effect.fn(\"Host.status\")(function* () {\n\t\tconst version = yield* gh([\"--version\"]).pipe(Effect.option);\n\t\tif (Option.isNone(version) || version.value.exitCode !== 0) return { ready: false, hint: INSTALL_GH };\n\t\tconst auth = yield* gh([\"auth\", \"status\"]).pipe(Effect.option);\n\t\tif (Option.isNone(auth) || auth.value.exitCode !== 0) return { ready: false, hint: LOGIN_GH };\n\t\treturn { ready: true };\n\t});\n\n\tconst lookup = Effect.fn(\"Host.lookup\")(function* (repository: string) {\n\t\tconst selector = parseRepository(repository);\n\t\tif (selector === undefined) return yield* fail(NOT_NAMED);\n\t\tconst hostname = selector.host === \"github.com\" ? [] : [\"--hostname\", selector.host];\n\t\tconst api = (args: ReadonlyArray<string>) =>\n\t\t\tgh([\"api\", ...hostname, ...args]).pipe(Effect.mapError(() => fail(INSTALL_GH)));\n\t\tlet owner = selector.owner;\n\t\tif (owner === undefined) {\n\t\t\tconst user = yield* api([\"user\", \"--jq\", \".login\"]);\n\t\t\towner = user.stdout.trim();\n\t\t\tif (user.exitCode !== 0 || owner.length === 0) {\n\t\t\t\treturn yield* fail(user.stderr.trim() || \"Could not read the signed-in GitHub user.\");\n\t\t\t}\n\t\t}\n\t\tconst result = yield* api([`repos/${owner}/${selector.name}`]);\n\t\tif (result.exitCode !== 0) {\n\t\t\treturn yield* fail(\n\t\t\t\t/HTTP 404|Not Found/i.test(result.stderr) ? NOT_FOUND : result.stderr.trim() || \"gh api failed.\",\n\t\t\t);\n\t\t}\n\t\tconst found = yield* decodeRepository(result.stdout).pipe(\n\t\t\tEffect.mapError(() => fail(\"GitHub answered with something other than a repository.\")),\n\t\t);\n\t\treturn { nameWithOwner: found.full_name, url: found.html_url, sshUrl: found.ssh_url };\n\t});\n\n\tconst remote = Effect.fn(\"Host.remote\")(function* (directory: string) {\n\t\tconst url = yield* git.remote(directory);\n\t\treturn url === undefined ? undefined : shownRemote(url);\n\t});\n\n\treturn Service.of({ info, browse, add, create, status, lookup, remote });\n});\n\n// Git runs on the host; every call names its own directory, so the mount root is never read.\nexport const layer = Layer.effect(Service, make).pipe(Layer.provide(Git.defaultLayer(\"/\")));\n","/**\n * Server-side OAuth credential storage.\n *\n * The CLI runs the interactive part of every login locally — a browser\n * callback or a device code cannot travel over RPC — and sends the resulting\n * credentials here, so this service only ever reads, writes, refreshes and\n * clears the server home's `auth.json`.\n */\nimport {\n\tGitHubCopilotOAuthClient,\n\tJsonGitHubCopilotAuthStorage,\n\ttype GitHubCopilotOAuthCredentials,\n} from \"@codeworksh/aikit/oauth/github/copilot\";\nimport {\n\tJsonOpenAICodexAuthStorage,\n\tOpenAICodexOAuthClient,\n\ttype OpenAICodexOAuthCredentials,\n} from \"@codeworksh/aikit/oauth/openai/codex\";\nimport { summarizeGitHubCopilot, summarizeOpenAICodex } from \"@codeworksh/aikit/oauth/summary\";\nimport { Global } from \"@codeworksh/harness/effect\";\nimport { Context, Effect, Layer } from \"effect\";\nimport * as Contract from \"./contract.ts\";\n\ninterface Interface {\n\treadonly save: (credentials: Contract.OAuthCredentials) => Effect.Effect<Contract.OAuthInfo, Contract.OAuthError>;\n\treadonly status: (provider: Contract.OAuthProvider) => Effect.Effect<Contract.OAuthInfo | null, Contract.OAuthError>;\n\treadonly refresh: (\n\t\tprovider: Contract.OAuthProvider,\n\t) => Effect.Effect<Contract.OAuthInfo | null, Contract.OAuthError>;\n\treadonly logout: (provider: Contract.OAuthProvider) => Effect.Effect<void, Contract.OAuthError>;\n}\n\nexport class Service extends Context.Service<Service, Interface>()(\"@codeworksh/cli/server/oauth/Service\") {}\n\nconst message = (cause: unknown): string =>\n\tcause instanceof Error && cause.message.trim().length > 0 ? cause.message : String(cause);\n\n/**\n * Re-exported so the server, the CLI and aikit all describe a login the same\n * way; `Contract.OAuthInfo` is the wire shape of {@link OAuthSummary}.\n */\nconst codexInfo = summarizeOpenAICodex;\nconst copilotInfo = summarizeGitHubCopilot;\n\nexport const layer = (options: { readonly home?: string | undefined } = {}) =>\n\tLayer.effect(\n\t\tService,\n\t\tEffect.gen(function* () {\n\t\t\tconst global = yield* Global.Service;\n\t\t\tconst authFile = Global.authFile(options.home === undefined ? undefined : global.home);\n\t\t\tconst file = authFile === undefined ? {} : { path: authFile };\n\t\t\tconst codex = new OpenAICodexOAuthClient({ storage: new JsonOpenAICodexAuthStorage(file) });\n\t\t\tconst copilot = new GitHubCopilotOAuthClient({ storage: new JsonGitHubCopilotAuthStorage(file) });\n\t\t\tconst attempt = <A>(run: () => Promise<A>) =>\n\t\t\t\tEffect.tryPromise({\n\t\t\t\t\ttry: run,\n\t\t\t\t\tcatch: (cause) => new Contract.OAuthError({ message: message(cause) }),\n\t\t\t\t});\n\t\t\tconst optional = <A>(run: () => Promise<A | undefined>, info: (value: A) => Contract.OAuthInfo) =>\n\t\t\t\tattempt(run).pipe(Effect.map((value) => (value === undefined ? null : info(value))));\n\n\t\t\treturn Service.of({\n\t\t\t\t// The `provider` tag is routing, not a credential: it never reaches disk.\n\t\t\t\tsave: (wire) => {\n\t\t\t\t\tif (wire.provider === \"openai-codex\") {\n\t\t\t\t\t\tconst credentials: OpenAICodexOAuthCredentials = {\n\t\t\t\t\t\t\taccess: wire.access,\n\t\t\t\t\t\t\trefresh: wire.refresh,\n\t\t\t\t\t\t\texpires: wire.expires,\n\t\t\t\t\t\t\taccountId: wire.accountId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn attempt(() => codex.storage.set(credentials)).pipe(Effect.as(codexInfo(credentials)));\n\t\t\t\t\t}\n\t\t\t\t\tconst credentials: GitHubCopilotOAuthCredentials = {\n\t\t\t\t\t\taccess: wire.access,\n\t\t\t\t\t\trefresh: wire.refresh,\n\t\t\t\t\t\texpires: wire.expires,\n\t\t\t\t\t\t...(wire.enterpriseUrl === undefined ? {} : { enterpriseUrl: wire.enterpriseUrl }),\n\t\t\t\t\t\t...(wire.apiEndpoint === undefined ? {} : { apiEndpoint: wire.apiEndpoint }),\n\t\t\t\t\t\t...(wire.availableModelIds === undefined ? {} : { availableModelIds: [...wire.availableModelIds] }),\n\t\t\t\t\t};\n\t\t\t\t\treturn attempt(() => copilot.storage.set(credentials)).pipe(Effect.as(copilotInfo(credentials)));\n\t\t\t\t},\n\t\t\t\tstatus: (provider) =>\n\t\t\t\t\tprovider === \"openai-codex\"\n\t\t\t\t\t\t? optional(() => codex.storage.get(), codexInfo)\n\t\t\t\t\t\t: optional(() => copilot.storage.get(), copilotInfo),\n\t\t\t\t// GitHub OAuth tokens never expire, so a Copilot \"refresh\" is a read.\n\t\t\t\trefresh: (provider) =>\n\t\t\t\t\tprovider === \"openai-codex\"\n\t\t\t\t\t\t? optional(() => codex.getCredentials(), codexInfo)\n\t\t\t\t\t\t: optional(() => copilot.getCredentials(), copilotInfo),\n\t\t\t\tlogout: (provider) => attempt(() => (provider === \"openai-codex\" ? codex.logout() : copilot.logout())),\n\t\t\t});\n\t\t}),\n\t);\n","import { Part } from \"@codeworksh/schema/host/part\";\nimport { Schema } from \"effect\";\n\n/** A stored part row's JSON, or none when it is not a part a client renders. */\nexport const decode = Schema.decodeUnknownOption(Schema.fromJsonString(Part));\n","import { Store, type Sync } from \"@codeworksh/harness/effect\";\nimport { Effect, Option, Stream } from \"effect\";\n\n/** Rows per page; each page is one read transaction, which writes wait behind. */\nexport const batch = 500;\n\ntype Pages<A, R> = (from: Sync.Cursor, upto: number) => Effect.Effect<Sync.Page<A>, never, R>;\n\n/** Every row past `from` up to `head`, page by page, then `synced` at that head. */\nconst range = <A, R>(from: number, head: Store.Head, page: Pages<A, R>, synced: (head: Store.Head) => A) =>\n\tStream.paginate<Sync.Cursor, A, never, R>({ rev: from }, (cursor) =>\n\t\tpage(cursor, head.rev).pipe(Effect.map(({ items, next }) => [items, Option.fromUndefinedOr(next)] as const)),\n\t).pipe(Stream.concat(Stream.make(synced(head))));\n\n/**\n * A revision-ordered stream: `start` at the head when it opens, then every row past the last head\n * sent, page by page, and `synced` at the new head after each commit. The doorbell is registered\n * before the first read, so no commit falls between.\n */\nexport const watch = <A, R, R2>(\n\tstart: (head: Store.Head) => Stream.Stream<A, never, R2>,\n\tpage: Pages<A, R>,\n\tsynced: (head: Store.Head) => A,\n): Stream.Stream<A, never, R | R2 | Store.Service> =>\n\tStream.unwrap(\n\t\tEffect.gen(function* () {\n\t\t\tconst store = yield* Store.Service;\n\t\t\tconst wake = yield* store.wake;\n\t\t\tlet sent: number | undefined;\n\t\t\tconst round = Stream.unwrap(\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst head = yield* store.head;\n\t\t\t\t\tif (head.rev === sent) return Stream.empty;\n\t\t\t\t\tconst from = sent;\n\t\t\t\t\tsent = head.rev;\n\t\t\t\t\tconst next: Stream.Stream<A, never, R | R2> =\n\t\t\t\t\t\tfrom === undefined ? start(head) : range(from, head, page, synced);\n\t\t\t\t\treturn next;\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn Stream.make(undefined).pipe(\n\t\t\t\tStream.concat(Stream.fromSubscription(wake)),\n\t\t\t\tStream.flatMap(() => round),\n\t\t\t);\n\t\t}),\n\t);\n\n/** `watch` from revision `after`: every row past it first, then the same live. */\nexport const follow = <A, R>(\n\tafter: number,\n\tpage: Pages<A, R>,\n\tsynced: (head: Store.Head) => A,\n): Stream.Stream<A, never, R | Store.Service> => watch((head) => range(after, head, page, synced), page, synced);\n\n/**\n * `follow` from `after` on the line of `boot`, the one the client's last `synced` carried: when the\n * store left that line (a restored backup), it reads from zero instead and the first `synced` is told\n * so by `reset`.\n */\nexport const resume = <A, R>(\n\tafter: number,\n\tboot: string | undefined,\n\tpage: Pages<A, R>,\n\tsynced: (head: Store.Head, reset: boolean) => A,\n): Stream.Stream<A, never, R | Store.Service> =>\n\tStream.unwrap(\n\t\tEffect.gen(function* () {\n\t\t\tconst store = yield* Store.Service;\n\t\t\tlet reset = after > 0 && boot !== undefined && !(yield* store.onLine(boot, after));\n\t\t\treturn follow(reset ? 0 : after, page, (head) => {\n\t\t\t\tconst item = synced(head, reset);\n\t\t\t\treset = false;\n\t\t\t\treturn item;\n\t\t\t});\n\t\t}),\n\t);\n","import { Model } from \"@codeworksh/aikit\";\nimport {\n\tControl,\n\tDaemonHost,\n\tGlobal,\n\tEvent,\n\tEventList,\n\tEventRegistry,\n\tEventSchema,\n\tMcp,\n\tMcpConfig,\n\tModelCatalog,\n\tProject,\n\tPromptSchema,\n\tSandbox,\n\tSession,\n\tSessionStore,\n\tSettings,\n\tSettingsFile,\n\tState,\n\tStore,\n\tSync,\n\tThreadSchema,\n\tThreadStore,\n} from \"@codeworksh/harness/effect\";\nimport { Machine } from \"@codeworksh/schema/machine\";\nimport { DateTime, Effect, Option, Predicate, Queue, Schema, Stream } from \"effect\";\nimport { NodeServices } from \"@effect/platform-node\";\nimport * as MachineFile from \"../machine/file.ts\";\nimport * as MachineRelay from \"../machine/relay.ts\";\nimport * as Contract from \"./contract.ts\";\nimport {\n\ttype HistoryEntry,\n\ttype IndexItem,\n\ttype LogSynced,\n\ttype RuntimeConfig,\n\ttype SandboxInfo,\n\ttype SessionInfo,\n\ttype LiveDelta,\n\ttype QueuedPrompt,\n\ttype ThreadInfo,\n\ttype ThreadItem,\n\ttype ThreadSummary,\n\ttype UsageItem,\n} from \"./contract.ts\";\nimport * as Envelope from \"./envelope.ts\";\nimport { type EncodingError, type EventEnvelope } from \"./envelope.ts\";\nimport * as Clones from \"./clones.ts\";\nimport * as Door from \"./door.ts\";\nimport * as EventFeed from \"./feed.ts\";\nimport * as Host from \"./host.ts\";\nimport * as Identity from \"./identity.ts\";\nimport * as OAuth from \"./oauth.ts\";\nimport * as Pairing from \"./pairing.ts\";\nimport * as MessagePart from \"./part.ts\";\nimport * as Principal from \"./principal.ts\";\nimport * as Rows from \"./rows.ts\";\n\nconst isConnectError = Schema.is(Machine.ConnectError);\n\nconst toSandboxInfo = (info: Sandbox.Info): SandboxInfo => ({\n\tid: info.id,\n\tdriver: info.driver,\n\tkind: info.kind,\n\tproviderResourceId: info.providerResourceId,\n\townership: info.ownership,\n\tstatus: info.status,\n\tusage: info.usage,\n\trefCount: info.refCount,\n\tcreatedAt: info.createdAt,\n\tupdatedAt: info.updatedAt,\n});\n\nconst toSessionInfo = (info: Session.Info): SessionInfo => ({\n\tid: info.id,\n\tspaceId: info.spaceId,\n\tslug: info.slug,\n\tdirectory: info.directory,\n\t...(info.hostDir === undefined ? {} : { hostDir: info.hostDir }),\n\t...(info.sandbox === undefined ? {} : { sandbox: toSandboxInfo(info.sandbox) }),\n\t...(info.project === undefined ? {} : { project: info.project }),\n\t...(info.tag === undefined ? {} : { tag: info.tag }),\n\t...(info.metadata === undefined ? {} : { metadata: info.metadata }),\n\tcreatedAt: info.createdAt,\n\tupdatedAt: info.updatedAt,\n\tmainThreadId: info.mainThreadId,\n});\n\nconst toThreadSummary = (info: Session.ThreadSummary): ThreadSummary => ({\n\tid: info.id,\n\tsessionId: info.sessionId,\n\torigin: info.origin,\n\t...(info.title === undefined ? {} : { title: info.title }),\n\tupdatedAt: info.updatedAt,\n\t...(info.model === undefined ? {} : { model: info.model }),\n\t...(info.thinkingLevel === undefined ? {} : { thinkingLevel: info.thinkingLevel }),\n\t...(info.foundation === undefined ? {} : { foundation: info.foundation }),\n\t...(info.placement === undefined ? {} : { placement: info.placement }),\n\tusage: info.usage,\n\trunState: info.runState,\n\t...(info.runStateAt === undefined ? {} : { runStateAt: info.runStateAt }),\n\t...(info.lastRun === undefined ? {} : { lastRun: info.lastRun }),\n\tparked: info.parked,\n\trestarts: info.restarts,\n\t...(info.attempt === undefined ? {} : { attempt: info.attempt }),\n\tcreatedSeq: info.createdSeq,\n\tcreatedAt: info.createdAt,\n});\n\nconst toThreadInfo = (info: Session.ThreadInfo): ThreadInfo => {\n\tconst { sessionId: _, ...summary } = toThreadSummary(info);\n\treturn { ...summary, session: toSessionInfo(info.session) };\n};\n\nconst toIndexItem = (change: Sync.IndexChange): IndexItem => {\n\tswitch (change._tag) {\n\t\tcase \"Session\":\n\t\t\treturn { _tag: \"Session\", session: toSessionInfo(change.session), rev: change.rev };\n\t\tcase \"Thread\":\n\t\t\treturn { _tag: \"Thread\", thread: toThreadSummary(change.thread), rev: change.rev };\n\t\tdefault:\n\t\t\treturn change;\n\t}\n};\n\nconst toUsageItem = (change: Sync.UsageChange): UsageItem => {\n\tif (change._tag === \"Tally\") {\n\t\tconst { hour, threadId, sessionId, projectId, kind, name, count, rev } = change.tally;\n\t\treturn { _tag: \"Tally\", hour, threadId, sessionId, projectId, kind, name, count, rev };\n\t}\n\tconst row = change.usage;\n\treturn {\n\t\t_tag: \"Usage\",\n\t\thour: row.hour,\n\t\tthreadId: row.threadId,\n\t\tsessionId: row.sessionId,\n\t\tprojectId: row.projectId,\n\t\tprovider: row.provider,\n\t\tmodel: row.model,\n\t\tthinking: row.thinking,\n\t\trequests: row.requests,\n\t\ttokens: {\n\t\t\tinput: row.input,\n\t\t\toutput: row.output,\n\t\t\tcacheRead: row.cacheRead,\n\t\t\tcacheWrite: row.cacheWrite,\n\t\t\treasoning: row.reasoning,\n\t\t},\n\t\tcost: {\n\t\t\ttotal: row.cost,\n\t\t\tinput: row.costInput,\n\t\t\toutput: row.costOutput,\n\t\t\tcacheRead: row.costCacheRead,\n\t\t\tcacheWrite: row.costCacheWrite,\n\t\t},\n\t\tduration: row.duration,\n\t\ttimed: row.timed,\n\t\tdurations: row.durations,\n\t\trev: row.rev,\n\t};\n};\n\n// Wire configs name only the keys they set, so `undefined` never reaches the harness under\n// exactOptionalPropertyTypes. Creating takes choices only; `null` clears nothing there.\nconst runtimeInput = (runtime: RuntimeConfig | undefined): Session.RuntimeInput => ({\n\t...(runtime?.model == null ? {} : { model: runtime.model }),\n\t...(runtime?.thinkingLevel == null ? {} : { thinkingLevel: runtime.thinkingLevel }),\n\t...(runtime?.foundation == null ? {} : { foundation: runtime.foundation }),\n});\n\n// A failed reply's envelope keeps the provider's reason; it reads as the live failure does.\nconst decodeFailedReply = Schema.decodeUnknownOption(\n\tSchema.fromJsonString(\n\t\tSchema.Struct({\n\t\t\tstopReason: Schema.Literal(\"error\"),\n\t\t\terrorMessage: Schema.String,\n\t\t\tprovider: Schema.Struct({ id: Schema.String }),\n\t\t\tmodel: Schema.String,\n\t\t}),\n\t),\n);\nconst replyError = (data: string) =>\n\tOption.map(decodeFailedReply(data), (reply) => `${reply.provider.id}/${reply.model}: ${reply.errorMessage}`);\n\n/** A line entry for the wire; the harness's own entries (compactions, resets, notices) are left out. */\nconst toHistoryEntries = ({ entry, parts, size }: ThreadStore.HydratedEntry): ReadonlyArray<HistoryEntry> =>\n\tentry.type === \"user\" || entry.type === \"assistant\"\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tid: entry.id,\n\t\t\t\t\tthreadId: entry.threadId,\n\t\t\t\t\tseq: entry.seq,\n\t\t\t\t\trole: entry.type,\n\t\t\t\t\tstate: entry.state,\n\t\t\t\t\tcreatedAt: DateTime.toEpochMillis(entry.createdAt),\n\t\t\t\t\tupdatedAt: DateTime.toEpochMillis(entry.updatedAt),\n\t\t\t\t\t// A part this schema does not render (a future aikit type) is skipped, not fatal.\n\t\t\t\t\tparts: parts.flatMap((part) => Option.toArray(MessagePart.decode(part.data))),\n\t\t\t\t\tsize,\n\t\t\t\t\t...Option.match(entry.type === \"assistant\" ? replyError(entry.data) : Option.none(), {\n\t\t\t\t\t\tonNone: () => ({}),\n\t\t\t\t\t\tonSome: (error) => ({ error }),\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t]\n\t\t: [];\n\nconst toQueuedPrompt = (input: Extract<Sync.ThreadChange, { _tag: \"Inbox\" }>[\"prompt\"]): QueuedPrompt => ({\n\tid: input.id,\n\tdelivery: input.delivery,\n\ttext: PromptSchema.Prompt.text(input.prompt),\n\tadmittedSeq: input.admittedSeq,\n\tcreatedAt: DateTime.toEpochMillis(input.timeCreated),\n});\n\nconst toThreadItems = (change: Sync.ThreadChange): ReadonlyArray<ThreadItem> =>\n\tchange._tag === \"Entry\"\n\t\t? toHistoryEntries(change.entry).map((entry) => ({ _tag: \"Entry\", entry, rev: change.rev }))\n\t\t: [{ _tag: \"Inbox\", prompt: toQueuedPrompt(change.prompt), state: change.state, rev: change.rev }];\n\nconst deltaKinds: Partial<Record<string, LiveDelta[\"kind\"]>> = {\n\t[EventList.LLMTextDelta.type]: \"text\",\n\t[EventList.LLMThinkingDelta.type]: \"thinking\",\n};\nconst decodeDelta = Schema.decodeUnknownOption(\n\tSchema.Struct({ messageId: Schema.String, partIndex: Schema.Int, offset: Schema.Int, delta: Schema.String }),\n);\n\n/** A live text or thinking delta of the feed as a `thread.sync` item. */\nconst toDeltaItem = (envelope: EventEnvelope): ThreadItem | undefined => {\n\tconst kind = deltaKinds[envelope.type];\n\tif (kind === undefined) return undefined;\n\treturn Option.match(decodeDelta(envelope.data), {\n\t\tonNone: () => undefined,\n\t\tonSome: ({ messageId, partIndex, offset, delta }) => ({\n\t\t\t_tag: \"Delta\",\n\t\t\tdelta: { entryId: messageId, partIndex, kind, offset, delta },\n\t\t}),\n\t});\n};\n\n/** The `Synced` of `index.sync` and `usage.sync`. */\nconst resynced = (head: Store.Head, reset: boolean) => ({\n\t_tag: \"Synced\" as const,\n\tstoreId: head.id,\n\trev: head.rev,\n\tboot: head.boot,\n\t...(reset ? { reset: true as const } : {}),\n});\n\n/** Bytes of entries a first `thread.sync` or a `thread.page` sends when the client names no budget. */\nconst defaultBudget = 1024 * 1024;\n\nconst threadInfo = (threadId: ThreadSchema.ID) => Session.threadInfo(threadId).pipe(Effect.map(toThreadInfo));\n\n// RpcServer's request span has no level, so it is Debug and drops every Info span under it.\n// Provisioning a sandbox is worth exporting, so it starts a trace of its own.\nconst exported = <A, E, R>(name: string, self: Effect.Effect<A, E, R>) =>\n\tself.pipe(Effect.withSpan(name, { level: \"Info\", root: true }));\n\nconst releaseOnFailure = (selection: Effect.Success<ReturnType<typeof Sandbox.resolve>> | undefined) =>\n\tselection?.created && selection.info !== undefined\n\t\t? Sandbox.stop(selection.info.id).pipe(Effect.catchCause(Effect.logError))\n\t\t: Effect.void;\n\n/** A `session.log` item for the wire: a stored event as its envelope, or the replay marker. */\nconst toLogItem =\n\t(registry: Envelope.Registry) =>\n\t(item: Event.LogItem): Effect.Effect<EventEnvelope | LogSynced, EncodingError> =>\n\t\tEvent.isSynced(item)\n\t\t\t? Effect.succeed(item)\n\t\t\t: Envelope.encode(item, registry).pipe(\n\t\t\t\t\t// Every stored type is a kernel durable one, which the registry always knows.\n\t\t\t\t\tEffect.catchTag(\"UnknownEventTypeError\", Effect.die),\n\t\t\t\t);\n\nexport const layer = Contract.Api.toLayer(\n\tEffect.gen(function* () {\n\t\tconst control = yield* Control.Service;\n\t\tconst feed = yield* EventFeed.Service;\n\t\tconst daemons = yield* DaemonHost.Service;\n\t\tconst sessions = yield* SessionStore.Service;\n\t\tconst threads = yield* ThreadStore.Service;\n\t\tconst resolve = (ref: Control.ThreadRef) =>\n\t\t\tcontrol.resolve(ref).pipe(Effect.map((thread) => ThreadSchema.ID.make(thread.id)));\n\t\tconst state = yield* State.Service;\n\t\tconst oauth = yield* OAuth.Service;\n\t\tconst identity = yield* Identity.Service;\n\t\tconst events = yield* Event.Service;\n\t\tconst registry = yield* EventRegistry.Service;\n\t\tconst mcp = yield* Mcp.Service;\n\t\tconst host = yield* Host.Service;\n\t\tconst clones = yield* Clones.Service;\n\t\tconst store = yield* Store.Service;\n\t\tconst global = yield* Global.Service;\n\t\tconst pairing = yield* Pairing.Service;\n\t\tconst connections = yield* Door.Connections;\n\t\t/** Forgets a device and ends its open connections; false when none has `id`. */\n\t\tconst forget = (id: string) =>\n\t\t\tpairing\n\t\t\t\t.revoke(id)\n\t\t\t\t.pipe(Effect.tap(() => Effect.forEach(connections.device(id), connections.end, { discard: true })));\n\t\tconst mcpControl = (operation: \"connect\" | \"disconnect\") =>\n\t\t\tEffect.fnUntraced(function* ({ server, ...ref }: Control.ThreadRef & { readonly server: string }) {\n\t\t\t\treturn yield* mcp[operation](yield* resolve(ref), server);\n\t\t\t});\n\n\t\tconst settings = yield* Settings.Service;\n\t\t/** The project's file is the one sessions in its main checkout read. */\n\t\tconst settingsTarget = Effect.fnUntraced(function* (projectId: string | undefined, file: \"settings\" | \"mcp\") {\n\t\t\tif (projectId === undefined) return yield* settings.locate(undefined, file);\n\t\t\tconst checkout = yield* Project.mainCheckout(projectId);\n\t\t\tif (checkout === undefined) return yield* new Project.ProjectCheckoutError({ projectId });\n\t\t\treturn yield* settings.locate(checkout, file);\n\t\t});\n\n\t\treturn Contract.Api.of({\n\t\t\t\"server.info\": Effect.fnUntraced(function* () {\n\t\t\t\tconst head = yield* store.head;\n\t\t\t\t// Read per call, so a `codework connect` made while the server runs shows without a restart. An\n\t\t\t\t// unreadable file reads as none: this is the health probe, and must still answer.\n\t\t\t\tconst machine = yield* MachineFile.read(global.home).pipe(\n\t\t\t\t\tEffect.provide(NodeServices.layer),\n\t\t\t\t\tEffect.orElseSucceed(() => Option.none<MachineFile.Machine>()),\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\t...identity,\n\t\t\t\t\tstoreId: head.id,\n\t\t\t\t\trev: head.rev,\n\t\t\t\t\t...(Option.isSome(machine) ? { machineId: machine.value.id } : {}),\n\t\t\t\t};\n\t\t\t}),\n\t\t\t\"index.sync\": ({ after, boot }) =>\n\t\t\t\tRows.resume(\n\t\t\t\t\tafter,\n\t\t\t\t\tboot,\n\t\t\t\t\t(from, upto) =>\n\t\t\t\t\t\tSync.index(from, upto, Rows.batch).pipe(\n\t\t\t\t\t\t\tEffect.map(({ items, next }) => ({\n\t\t\t\t\t\t\t\titems: items.map(toIndexItem),\n\t\t\t\t\t\t\t\t...(next === undefined ? {} : { next }),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t),\n\t\t\t\t\tresynced,\n\t\t\t\t),\n\t\t\t\"usage.sync\": ({ after, boot }) =>\n\t\t\t\tRows.resume(\n\t\t\t\t\tafter,\n\t\t\t\t\tboot,\n\t\t\t\t\t(from, upto) =>\n\t\t\t\t\t\tSync.usage(from, upto, Rows.batch).pipe(\n\t\t\t\t\t\t\tEffect.map(({ items, next }) => ({\n\t\t\t\t\t\t\t\titems: items.map(toUsageItem),\n\t\t\t\t\t\t\t\t...(next === undefined ? {} : { next }),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t),\n\t\t\t\t\tresynced,\n\t\t\t\t),\n\t\t\t\"auth.save\": ({ credentials }) => oauth.save(credentials),\n\t\t\t\"auth.status\": ({ provider }) => oauth.status(provider),\n\t\t\t\"auth.refresh\": ({ provider }) => oauth.refresh(provider),\n\t\t\t\"auth.logout\": ({ provider }) => oauth.logout(provider),\n\t\t\t\"session.create\": Effect.fnUntraced(function* ({ title, directory, hostDir, sandbox, runtime, project }) {\n\t\t\t\t// Refused before anything is resolved, so no session starts on a half-cloned tree.\n\t\t\t\tif (hostDir !== undefined) yield* clones.guard(hostDir);\n\t\t\t\tconst selection =\n\t\t\t\t\tsandbox === undefined ? undefined : yield* exported(\"Server.session.create\", Sandbox.resolve(sandbox));\n\t\t\t\tconst selected = selection?.info;\n\t\t\t\tconst handle = yield* Session.create({\n\t\t\t\t\t...(title === undefined ? {} : { title }),\n\t\t\t\t\t...(directory === undefined ? {} : { directory }),\n\t\t\t\t\t// Passed through as given, never defaulted to the server's own directory: a\n\t\t\t\t\t// session the client did not place has no project, which is a normal state.\n\t\t\t\t\t...(hostDir === undefined ? {} : { hostDir }),\n\t\t\t\t\t...(selected === undefined ? {} : { sandbox: selected }),\n\t\t\t\t\t...(project === undefined ? {} : { project }),\n\t\t\t\t\t...runtimeInput(runtime),\n\t\t\t\t}).pipe(Effect.onError(() => releaseOnFailure(selection)));\n\t\t\t\treturn toThreadInfo(yield* handle.main.info);\n\t\t\t}),\n\t\t\t\"model.list\": Effect.fnUntraced(function* ({ hostDir }) {\n\t\t\t\tconst filter = hostDir === undefined ? {} : { hostDir };\n\t\t\t\tconst settings = yield* Settings.Service;\n\t\t\t\tconst loaded = yield* settings.load(hostDir);\n\t\t\t\tconst providers = yield* ModelCatalog.available(filter);\n\t\t\t\tconst chosen = yield* ModelCatalog.selected(loaded, hostDir);\n\t\t\t\t// Named from the whole catalog, so a default without credentials still reads as itself.\n\t\t\t\tconst entry =\n\t\t\t\t\tchosen === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (yield* ModelCatalog.effective(loaded.models))[chosen.provider]?.[chosen.id];\n\t\t\t\treturn {\n\t\t\t\t\tproviders: providers.flatMap((provider) => {\n\t\t\t\t\t\tconst models = Object.values(provider.models);\n\t\t\t\t\t\tconst first = models[0];\n\t\t\t\t\t\treturn first === undefined\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: provider.id,\n\t\t\t\t\t\t\t\t\t\tname: first.provider.name,\n\t\t\t\t\t\t\t\t\t\tmodels: models.map((info) => ({\n\t\t\t\t\t\t\t\t\t\t\tid: info.id,\n\t\t\t\t\t\t\t\t\t\t\tname: info.name,\n\t\t\t\t\t\t\t\t\t\t\tthinkingLevels: Model.getSupportedThinkingLevels(info),\n\t\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t];\n\t\t\t\t\t}),\n\t\t\t\t\t...(chosen === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tdefault: {\n\t\t\t\t\t\t\t\t\t...chosen,\n\t\t\t\t\t\t\t\t\tthinkingLevel: loaded.model.thinkingLevel,\n\t\t\t\t\t\t\t\t\t...(entry === undefined ? {} : { name: entry.name, providerName: entry.provider.name }),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t\t\"project.remote\": Effect.fnUntraced(function* ({ projectId }) {\n\t\t\t\tconst checkout = yield* Project.mainCheckout(projectId);\n\t\t\t\tconst url = checkout === undefined ? undefined : yield* host.remote(checkout);\n\t\t\t\treturn { url: url ?? null };\n\t\t\t}),\n\t\t\t\"project.rename\": Effect.fnUntraced(function* ({ projectId, name }) {\n\t\t\t\tconst renamed = yield* Project.rename({ projectId, name });\n\t\t\t\treturn { id: renamed.id, name: renamed.name };\n\t\t\t}),\n\t\t\t\"settings.read\": Effect.fnUntraced(function* ({ projectId, file }) {\n\t\t\t\tconst target = yield* settingsTarget(projectId, file);\n\t\t\t\tconst current = yield* SettingsFile.read(target.path);\n\t\t\t\tconst problem = yield* Effect.flip(SettingsFile.check(target, current.source)).pipe(Effect.option);\n\t\t\t\tconst parsed = SettingsFile.parse(current.source);\n\t\t\t\t// Below a project's file are the user's settings; below the user's, the defaults.\n\t\t\t\tconst below =\n\t\t\t\t\tfile !== \"settings\"\n\t\t\t\t\t\t? Option.none()\n\t\t\t\t\t\t: projectId === undefined\n\t\t\t\t\t\t\t? Option.some(Settings.defaults)\n\t\t\t\t\t\t\t: yield* settings.load(undefined).pipe(Effect.option);\n\t\t\t\t// The servers as sessions merge them, so a list drawn from this never disagrees with a run.\n\t\t\t\tconst merged =\n\t\t\t\t\tfile !== \"mcp\"\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: yield* McpConfig.load({\n\t\t\t\t\t\t\t\tuserDir: target.userDir,\n\t\t\t\t\t\t\t\t...(target.root === undefined ? {} : { root: target.root }),\n\t\t\t\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tpath: target.path,\n\t\t\t\t\tsource: current.source,\n\t\t\t\t\texists: current.exists,\n\t\t\t\t\tversion: current.version,\n\t\t\t\t\t...(\"value\" in parsed ? { value: parsed.value } : {}),\n\t\t\t\t\t...(Option.isSome(problem) ? { error: problem.value.detail } : {}),\n\t\t\t\t\t...(Option.isSome(below) ? { inherited: { retry: below.value.retry } } : {}),\n\t\t\t\t\t...(merged === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tservers: merged.servers.map((server) => ({\n\t\t\t\t\t\t\t\t\tname: server.name,\n\t\t\t\t\t\t\t\t\tfrom:\n\t\t\t\t\t\t\t\t\t\tserver.file === target.path && target.scope === \"project\"\n\t\t\t\t\t\t\t\t\t\t\t? (\"project\" as const)\n\t\t\t\t\t\t\t\t\t\t\t: (\"user\" as const),\n\t\t\t\t\t\t\t\t\tenabled: server.config.enabled !== false,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t\t\"settings.write\": Effect.fnUntraced(function* ({ projectId, file, source, version }) {\n\t\t\t\tconst target = yield* settingsTarget(projectId, file);\n\t\t\t\treturn { version: yield* SettingsFile.replace(target, source, version) };\n\t\t\t}),\n\t\t\t\"settings.set\": Effect.fnUntraced(function* ({ projectId, file, at, value }) {\n\t\t\t\tconst target = yield* settingsTarget(projectId, file);\n\t\t\t\treturn { version: yield* SettingsFile.set(target, at, value) };\n\t\t\t}),\n\t\t\t\"plugin.reload\": Effect.fnUntraced(function* () {\n\t\t\t\treturn yield* state.reload;\n\t\t\t}),\n\t\t\t\"session.link\": Effect.fnUntraced(function* ({ sessionId, hostDir }) {\n\t\t\t\tconst handle = yield* Session.link({ sessionId, hostDir: hostDir ?? null });\n\t\t\t\treturn toSessionInfo(yield* handle.info);\n\t\t\t}),\n\t\t\t\"session.relink\": Effect.fnUntraced(function* ({ sessionId, threadId, sandbox, directory }) {\n\t\t\t\tconst selection =\n\t\t\t\t\tsandbox === undefined ? undefined : yield* exported(\"Server.session.relink\", Sandbox.resolve(sandbox));\n\t\t\t\tconst selected = selection?.info;\n\t\t\t\tconst handle = yield* Session.relink({\n\t\t\t\t\tsessionId,\n\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t...(selected === undefined ? {} : { sandbox: selected }),\n\t\t\t\t\t...(directory === undefined ? {} : { directory }),\n\t\t\t\t}).pipe(Effect.onError(() => releaseOnFailure(selection)));\n\t\t\t\tconst thread = yield* handle.thread(threadId ?? ThreadSchema.MAIN);\n\t\t\t\treturn toThreadInfo(yield* thread.info);\n\t\t\t}),\n\t\t\t\"session.delete\": Effect.fnUntraced(function* ({ sessionId }) {\n\t\t\t\treturn { deleted: yield* Session.remove(sessionId) };\n\t\t\t}),\n\t\t\t\"session.interrupt\": Effect.fnUntraced(function* ({ sessionId }) {\n\t\t\t\t// Ack only: the wire answers \"was there work to stop\", and the caller\n\t\t\t\t// uses `thread.wait` when it needs cleanup to have finished.\n\t\t\t\treturn { interrupted: yield* control.interruptSession(sessionId, { reason: \"user\" }) };\n\t\t\t}),\n\t\t\t\"session.log\": ({ sessionId, threadId, after, follow }) =>\n\t\t\t\tStream.unwrap(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tif (Option.isNone(yield* sessions.get(sessionId))) {\n\t\t\t\t\t\t\treturn yield* new SessionStore.SessionNotFoundError({ sessionId });\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn events\n\t\t\t\t\t\t\t.log({\n\t\t\t\t\t\t\t\taggregateId: sessionId,\n\t\t\t\t\t\t\t\tfollow: follow ?? false,\n\t\t\t\t\t\t\t\t...(after === undefined ? {} : { after }),\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\t\tStream.filter(\n\t\t\t\t\t\t\t\t\t(item) =>\n\t\t\t\t\t\t\t\t\t\tthreadId === undefined || Event.isSynced(item) || Envelope.ofThread(threadId)(item),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tStream.mapEffect(toLogItem(registry.get)),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\"thread.list\": Effect.fnUntraced(function* ({ sessionId }) {\n\t\t\t\tconst rows = yield* threads.list(sessionId);\n\t\t\t\treturn yield* Effect.forEach(rows, (row) => threadInfo(ThreadSchema.ID.make(row.id)).pipe(Effect.orDie));\n\t\t\t}),\n\t\t\t\"thread.info\": Effect.fnUntraced(function* (ref) {\n\t\t\t\treturn yield* threadInfo(yield* resolve(ref));\n\t\t\t}),\n\t\t\t\"thread.configure\": Effect.fnUntraced(function* ({ runtime, ...ref }) {\n\t\t\t\tconst threadId = yield* resolve(ref);\n\t\t\t\tconst change = {\n\t\t\t\t\t...(runtime.model === undefined ? {} : { model: runtime.model }),\n\t\t\t\t\t...(runtime.thinkingLevel === undefined ? {} : { thinkingLevel: runtime.thinkingLevel }),\n\t\t\t\t\t...(runtime.foundation === undefined ? {} : { foundation: runtime.foundation }),\n\t\t\t\t};\n\t\t\t\tif (Object.keys(change).length > 0) {\n\t\t\t\t\tyield* events.publish(EventList.ThreadConfigured, {\n\t\t\t\t\t\tsessionId: ref.sessionId,\n\t\t\t\t\t\tthreadId,\n\t\t\t\t\t\ttimestamp: yield* DateTime.now,\n\t\t\t\t\t\tchange,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn yield* threadInfo(threadId);\n\t\t\t}),\n\t\t\t\"thread.fork\": Effect.fnUntraced(function* ({ entryId, mode, ...ref }) {\n\t\t\t\tconst forked = yield* threads.fork({\n\t\t\t\t\tthreadId: yield* resolve(ref),\n\t\t\t\t\tentryId,\n\t\t\t\t\t...(mode === undefined ? {} : { mode }),\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tthread: yield* threadInfo(ThreadSchema.ID.make(forked.thread.id)),\n\t\t\t\t\t...(forked.text === undefined ? {} : { text: forked.text }),\n\t\t\t\t};\n\t\t\t}),\n\t\t\t\"thread.history\": Effect.fnUntraced(function* (ref) {\n\t\t\t\treturn { entries: (yield* threads.line(yield* resolve(ref))).flatMap(toHistoryEntries) };\n\t\t\t}),\n\t\t\t\"thread.queue\": Effect.fnUntraced(function* (ref) {\n\t\t\t\treturn { entries: (yield* control.pending(yield* resolve(ref))).map(toQueuedPrompt) };\n\t\t\t}),\n\t\t\t// The feed subscription is taken before the first read, so no delta after it is missed.\n\t\t\t\"thread.sync\": ({ after, budget, ...ref }) =>\n\t\t\t\tStream.unwrap(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst threadId = yield* resolve(ref);\n\t\t\t\t\t\tconst deltas = yield* feed.subscribe;\n\t\t\t\t\t\tconst synced = (head: Store.Head, floor?: number): ThreadItem => ({\n\t\t\t\t\t\t\t_tag: \"Synced\",\n\t\t\t\t\t\t\tstoreId: head.id,\n\t\t\t\t\t\t\trev: head.rev,\n\t\t\t\t\t\t\t...(floor === undefined ? {} : { floor }),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst page = (from: Sync.Cursor, upto: number) =>\n\t\t\t\t\t\t\tSync.thread(threadId, from, upto, Rows.batch).pipe(\n\t\t\t\t\t\t\t\tEffect.map(({ items, next }) => ({\n\t\t\t\t\t\t\t\t\titems: items.flatMap(toThreadItems),\n\t\t\t\t\t\t\t\t\t...(next === undefined ? {} : { next }),\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tconst rows =\n\t\t\t\t\t\t\tafter === undefined\n\t\t\t\t\t\t\t\t? Rows.watch(\n\t\t\t\t\t\t\t\t\t\t(head) =>\n\t\t\t\t\t\t\t\t\t\t\tStream.fromEffect(Sync.open(threadId, budget ?? defaultBudget, Rows.batch)).pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tStream.flatMap(({ items, floor }) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tStream.fromIterable([...items.flatMap(toThreadItems), synced(head, floor)]),\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\tpage,\n\t\t\t\t\t\t\t\t\t\tsynced,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: Rows.follow(after, page, synced);\n\t\t\t\t\t\treturn rows.pipe(\n\t\t\t\t\t\t\tStream.merge(\n\t\t\t\t\t\t\t\tdeltas.pipe(\n\t\t\t\t\t\t\t\t\tStream.filter(Envelope.ofThread(threadId)),\n\t\t\t\t\t\t\t\t\tStream.map(toDeltaItem),\n\t\t\t\t\t\t\t\t\tStream.filter(Predicate.isNotUndefined),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\"thread.page\": Effect.fnUntraced(function* ({ before, limit, budget, ...ref }) {\n\t\t\t\tconst entries = yield* threads.linePage({\n\t\t\t\t\tthreadId: yield* resolve(ref),\n\t\t\t\t\tbefore,\n\t\t\t\t\tlimit,\n\t\t\t\t\tbudget: budget ?? defaultBudget,\n\t\t\t\t});\n\t\t\t\treturn { entries: entries.toReversed().flatMap(toHistoryEntries) };\n\t\t\t}),\n\t\t\t\"thread.prompt\": Effect.fnUntraced(function* ({ text, delivery, id, ...ref }) {\n\t\t\t\tconst admitted = yield* control.prompt({\n\t\t\t\t\t...ref,\n\t\t\t\t\tprompt: PromptSchema.Prompt.fromText(text),\n\t\t\t\t\t...(delivery === undefined ? {} : { delivery }),\n\t\t\t\t\t...(id === undefined ? {} : { id }),\n\t\t\t\t});\n\t\t\t\treturn { threadId: admitted.threadId };\n\t\t\t}),\n\t\t\t\"thread.interrupt\": Effect.fnUntraced(function* (ref) {\n\t\t\t\t// Ack only: the wire answers \"was there work to stop\", and the caller\n\t\t\t\t// uses `thread.wait` when it needs cleanup to have finished.\n\t\t\t\treturn { interrupted: yield* control.interrupt(yield* resolve(ref), { reason: \"user\" }) };\n\t\t\t}),\n\t\t\t\"thread.cancel\": Effect.fnUntraced(function* ({ messageId, ...ref }) {\n\t\t\t\treturn { cancelled: yield* control.cancel(yield* resolve(ref), messageId) };\n\t\t\t}),\n\t\t\t\"thread.update\": Effect.fnUntraced(function* ({ messageId, delivery, text, ...ref }) {\n\t\t\t\tconst updated = yield* control.update(yield* resolve(ref), messageId, {\n\t\t\t\t\t...(delivery === undefined ? {} : { delivery }),\n\t\t\t\t\t...(text === undefined ? {} : { prompt: PromptSchema.Prompt.fromText(text) }),\n\t\t\t\t});\n\t\t\t\treturn { updated };\n\t\t\t}),\n\t\t\t\"thread.message\": Effect.fnUntraced(function* ({ messageId, ...ref }) {\n\t\t\t\t// Scoped to the thread's line: an entry id is global, and a client should not learn\n\t\t\t\t// about conversations it did not ask for. An inherited prompt is in the thread's.\n\t\t\t\tconst line = yield* threads.line(yield* resolve(ref));\n\t\t\t\treturn { found: line.some(({ entry }) => entry.id === messageId) };\n\t\t\t}),\n\t\t\t\"thread.wait\": Effect.fnUntraced(function* (ref) {\n\t\t\t\tyield* control.wait(yield* resolve(ref));\n\t\t\t}),\n\t\t\t\"mcp.connect\": mcpControl(\"connect\"),\n\t\t\t\"mcp.disconnect\": mcpControl(\"disconnect\"),\n\t\t\t\"machine.info\": () => MachineRelay.status(global.home).pipe(Effect.provide(NodeServices.layer), Effect.orDie),\n\t\t\t\"machine.rename\": ({ givenName }) =>\n\t\t\t\tMachineRelay.rename(global.home, givenName).pipe(\n\t\t\t\t\t// The relay hears the new name now rather than on the next beat; a miss is retried then.\n\t\t\t\t\tEffect.tap(() =>\n\t\t\t\t\t\tMachineRelay.heartbeat(global.home).pipe(\n\t\t\t\t\t\t\tEffect.provide(NodeServices.layer),\n\t\t\t\t\t\t\tEffect.ignore,\n\t\t\t\t\t\t\tEffect.forkDetach,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\tEffect.provide(NodeServices.layer),\n\t\t\t\t\tEffect.orDie,\n\t\t\t\t),\n\t\t\t\"machine.disconnect\": ({ workspaceId, keyId }) =>\n\t\t\t\tMachineRelay.disconnect(global.home, workspaceId, keyId).pipe(\n\t\t\t\t\tEffect.flatMap(({ revoked }) =>\n\t\t\t\t\t\tMachineRelay.status(global.home).pipe(Effect.map((status) => ({ status, revoked }))),\n\t\t\t\t\t),\n\t\t\t\t\tEffect.provide(NodeServices.layer),\n\t\t\t\t\tEffect.catchIf(\n\t\t\t\t\t\t(error) => !isConnectError(error),\n\t\t\t\t\t\t(error) =>\n\t\t\t\t\t\t\tEffect.fail(new Machine.ConnectError({ message: `Could not disconnect: ${String(error)}` })),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\"machine.connect\": ({ workspaceId }) =>\n\t\t\t\tStream.callback<Machine.ConnectEvent, Machine.ConnectError>((queue) =>\n\t\t\t\t\tMachineRelay.connect({\n\t\t\t\t\t\thome: global.home,\n\t\t\t\t\t\tworkspaceId,\n\t\t\t\t\t\tonCode: (userCode) => Queue.offer(queue, { _tag: \"Code\", userCode }).pipe(Effect.asVoid),\n\t\t\t\t\t}).pipe(\n\t\t\t\t\t\t// The workspace sees it online now rather than on the next beat; a miss is retried then.\n\t\t\t\t\t\tEffect.tap(() =>\n\t\t\t\t\t\t\tMachineRelay.heartbeat(global.home).pipe(\n\t\t\t\t\t\t\t\tEffect.provide(NodeServices.layer),\n\t\t\t\t\t\t\t\tEffect.ignore,\n\t\t\t\t\t\t\t\tEffect.forkDetach,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.flatMap((connected) => Queue.offer(queue, { _tag: \"Connected\", connected })),\n\t\t\t\t\t\tEffect.andThen(Queue.end(queue)),\n\t\t\t\t\t\tEffect.provide([MachineRelay.Client.layer, NodeServices.layer]),\n\t\t\t\t\t\tEffect.catch((error) =>\n\t\t\t\t\t\t\tQueue.fail(\n\t\t\t\t\t\t\t\tqueue,\n\t\t\t\t\t\t\t\tisConnectError(error)\n\t\t\t\t\t\t\t\t\t? error\n\t\t\t\t\t\t\t\t\t: new Machine.ConnectError({ message: `Could not connect: ${String(error)}` }),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.forkScoped,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\"device.pair\": () => Principal.local(pairing.code),\n\t\t\t\"device.list\": () => Principal.local(pairing.list),\n\t\t\t\"device.revoke\": ({ id }) => Principal.local(Effect.map(forget(id), (applied) => ({ applied }))),\n\t\t\t\"device.leave\": () =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst caller = yield* Principal.Current;\n\t\t\t\t\tif (caller.kind !== \"device\")\n\t\t\t\t\t\treturn yield* new Principal.Forbidden({ message: \"This computer has no pairing to leave\" });\n\t\t\t\t\tyield* forget(caller.id);\n\t\t\t\t}),\n\t\t\t\"host.info\": () => Effect.succeed(host.info),\n\t\t\t\"host.browse\": ({ path }) => host.browse(path),\n\t\t\t\"host.create\": ({ name }) => host.create(name),\n\t\t\t\"host.add\": ({ path }) => host.add(path),\n\t\t\t\"host.clone\": (input) => clones.start(input),\n\t\t\t\"host.clones\": () => clones.stream,\n\t\t\t\"host.cancel\": ({ path }) => clones.cancel(path).pipe(Effect.map((applied) => ({ applied }))),\n\t\t\t\"host.retry\": ({ path }) => clones.retry(path).pipe(Effect.map((applied) => ({ applied }))),\n\t\t\t\"host.discard\": ({ path }) => clones.discard(path),\n\t\t\t\"github.status\": () => host.status(),\n\t\t\t\"github.lookup\": ({ repository }) => host.lookup(repository),\n\t\t\t\"sandbox.drivers\": Effect.fnUntraced(function* () {\n\t\t\t\tconst drivers = yield* Sandbox.drivers();\n\t\t\t\treturn drivers.map(({ name, kind }) => ({ name, kind }));\n\t\t\t}),\n\t\t\t\"sandbox.list\": Effect.fnUntraced(function* () {\n\t\t\t\treturn (yield* Sandbox.list()).map(toSandboxInfo);\n\t\t\t}),\n\t\t\t\"sandbox.create\": Effect.fnUntraced(function* ({ driver }) {\n\t\t\t\treturn toSandboxInfo(yield* exported(\"Server.sandbox.create\", Sandbox.create({ driver })));\n\t\t\t}),\n\t\t\t\"sandbox.register\": Effect.fnUntraced(function* ({ driver, providerResourceId }) {\n\t\t\t\treturn toSandboxInfo(yield* Sandbox.register({ driver, providerResourceId }));\n\t\t\t}),\n\t\t\t\"sandbox.stop\": Effect.fnUntraced(function* ({ sandboxId }) {\n\t\t\t\tyield* Sandbox.stop(sandboxId);\n\t\t\t}),\n\t\t\t// Acquiring the feed subscription is the readiness barrier: `server.connected`\n\t\t\t// is only emitted once this client is registered, so a prompt admitted after\n\t\t\t// it cannot land in the gap.\n\t\t\t\"event.subscribe\": ({ threadId, types }) => {\n\t\t\t\tconst only = types === undefined ? undefined : new Set(types);\n\t\t\t\treturn Stream.unwrap(\n\t\t\t\t\tfeed\n\t\t\t\t\t\t.filtered(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t...(only === undefined ? {} : { types: only }),\n\t\t\t\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonly === undefined ? undefined : () => daemons.last(only),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tEffect.map((events) =>\n\t\t\t\t\t\t\t\tStream.make({ id: EventSchema.ID.create(), type: Envelope.Connected.type, data: {} }).pipe(\n\t\t\t\t\t\t\t\t\tStream.concat(events),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"daemon.call\": (input) => daemons.call(input),\n\t\t});\n\t}),\n);\n","import { Control, Global, Harness, Sandbox, Settings } from \"@codeworksh/harness/effect\";\nimport { NodeHttpServer, NodeServices } from \"@effect/platform-node\";\nimport { Effect, Layer } from \"effect\";\nimport { HttpRouter, HttpServer } from \"effect/http\";\nimport type * as IpNetwork from \"effect/net/IpNetwork\";\nimport * as NetAddress from \"effect/net/NetAddress\";\nimport { type Rpc, type RpcGroup, RpcSerialization, RpcServer } from \"effect/rpc\";\n/* @effect-diagnostics nodeBuiltinImport:off -- the RPC listener needs a raw node server. */\nimport { createServer } from \"node:http\";\nimport * as MachineFile from \"../machine/file.ts\";\nimport * as Heartbeat from \"../machine/heartbeat.ts\";\nimport * as Clones from \"./clones.ts\";\nimport * as Contract from \"./contract.ts\";\nimport * as Door from \"./door.ts\";\nimport * as EventFeed from \"./feed.ts\";\nimport * as Handlers from \"./handlers.ts\";\nimport * as Host from \"./host.ts\";\nimport * as Identity from \"./identity.ts\";\nimport * as OAuth from \"./oauth.ts\";\nimport * as Pairing from \"./pairing.ts\";\nimport * as Principal from \"./principal.ts\";\nimport * as Registration from \"./registration.ts\";\n\n// Managed instances outlive any single RPC; the serve scope is what stops them.\nconst managedShutdown = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\tconst control = yield* Control.Service;\n\t\tyield* Effect.addFinalizer(() =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\t// Release drain leases before stopping the server's managed sandboxes.\n\t\t\t\t// Both phases are best effort and bounded so a provider cannot prevent\n\t\t\t\t// process shutdown; an interrupted stop is persisted as faulted and can\n\t\t\t\t// recover the next time that sandbox is mounted.\n\t\t\t\tyield* Effect.forEach(\n\t\t\t\t\tyield* control.active,\n\t\t\t\t\t(id) =>\n\t\t\t\t\t\tcontrol\n\t\t\t\t\t\t\t.interrupt(id, { reason: \"shutdown\", awaitSettlement: true })\n\t\t\t\t\t\t\t.pipe(Effect.timeout(\"10 seconds\"), Effect.ignore),\n\t\t\t\t\t{ concurrency: \"unbounded\", discard: true },\n\t\t\t\t);\n\t\t\t\tconst infos = yield* Sandbox.list();\n\t\t\t\tyield* Effect.forEach(\n\t\t\t\t\tinfos.filter((info) => info.ownership === \"managed\"),\n\t\t\t\t\t(info) =>\n\t\t\t\t\t\tSandbox.stop(info.id).pipe(\n\t\t\t\t\t\t\tEffect.timeout(\"10 seconds\"),\n\t\t\t\t\t\t\tEffect.catchCause((cause) =>\n\t\t\t\t\t\t\t\tEffect.logError(\"Failed to stop managed sandbox during shutdown\", cause).pipe(\n\t\t\t\t\t\t\t\t\tEffect.annotateLogs({ sandboxInstanceId: info.id }),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t{ concurrency: \"unbounded\", discard: true },\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\treturn Layer.empty;\n\t}),\n);\n\n/** Ends the stored runs the last server left open, before the listener opens: a client never sees them live. */\nconst sweep = Layer.effectDiscard(Effect.flatMap(Control.Service, (control) => control.sweep));\n\n/**\n * This computer is a machine from the moment its server runs: `machine.json`, with the id and identity key,\n * is made at startup rather than on the first connect or pairing, so This Machine always has an id. A file\n * it can't read or write is logged, not fatal; local work doesn't need it.\n */\nconst machine = Layer.effectDiscard(\n\tEffect.flatMap(Global.Service, (global) => MachineFile.identity(global.home)).pipe(\n\t\tEffect.provide(NodeServices.layer),\n\t\tEffect.catch((error) => Effect.logWarning(\"Could not set up this machine's id\", error)),\n\t),\n);\n\n/**\n * Resumes the runs the last server left unfinished, whether it crashed or shut down, and the prompts\n * woken past a thread's head: the log and its projections record both, so this needs nothing from the\n * previous process.\n */\nconst resumeUnfinished = Layer.effectDiscard(\n\tEffect.gen(function* () {\n\t\tconst control = yield* Control.Service;\n\t\tyield* Effect.forkScoped(control.resumeUnfinished);\n\t}),\n);\n\n/**\n * Advertises the listener once it has an address: files the registration later\n * invocations discover it through, with the token they call it with, then logs\n * the endpoint, so whoever reads that line finds the server registered.\n */\nconst announce = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\tconst server = yield* HttpServer.HttpServer;\n\t\tconst token = yield* Principal.Token;\n\t\tconst global = yield* Global.Service;\n\t\tconst identity = yield* Identity.Service;\n\t\t// A ws server always binds TCP; the guard keeps the logger honest if that ever changes.\n\t\tconst address = server.address;\n\t\tconst url = `${NetAddress.formatUrlUnsafe(address, \"ws\")}${Contract.path}`;\n\t\tconst listening = Layer.effectDiscard(Effect.log(`codework serve listening on ${url}`));\n\t\tif (!NetAddress.isInetAddress(address)) return listening;\n\t\treturn listening.pipe(\n\t\t\tLayer.provide(\n\t\t\t\tRegistration.register({\n\t\t\t\t\thome: global.home,\n\t\t\t\t\tinfo: { pid: identity.pid, version: identity.version, url, port: address.port, token },\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\t}),\n);\n\nconst trusted = (given: ReadonlyArray<IpNetwork.IpNetwork> | undefined) =>\n\tLayer.effect(\n\t\tPairing.TrustedProxy,\n\t\tgiven === undefined\n\t\t\t? Effect.flatMap(Settings.Service, (settings) => settings.load(undefined)).pipe(\n\t\t\t\t\t// Settings decode each entry, so every one parses.\n\t\t\t\t\tEffect.map(({ server }) => server.trustedProxy.flatMap((entry) => Settings.proxyNetwork(entry) ?? [])),\n\t\t\t\t)\n\t\t\t: Effect.succeed(given),\n\t);\n\n/** The RPC endpoint for `group` and the pairing routes, behind the door, which turns a refused request away. */\nexport const endpoint = <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>) =>\n\tRpcServer.layer(group).pipe(\n\t\tLayer.provide(Door.protocol),\n\t\tLayer.provide(Handlers.layer.pipe(Layer.provide(EventFeed.layer))),\n\t\tLayer.provide(Door.rpc),\n\t\tLayer.merge(Pairing.routes),\n\t\tLayer.merge(Door.listener),\n\t\tLayer.provide(Door.layerConnections),\n\t\tLayer.provide(Pairing.layer),\n\t);\n\nexport const layer = (options: {\n\thost: string;\n\tport: number;\n\tharness: Harness.Options;\n\t/** Proxies besides loopback whose `X-Forwarded-Proto` is believed; the user settings' `server.trustedProxy` without. */\n\ttrustedProxy?: ReadonlyArray<IpNetwork.IpNetwork>;\n\t/** Who the server says it is; tests name its host. */\n\tidentity?: Layer.Layer<Identity.Service>;\n}) => {\n\tconst app = HttpRouter.serve(endpoint(Contract.Api), { disableListenLog: true }).pipe(\n\t\tLayer.provideMerge(managedShutdown),\n\t\tLayer.provideMerge(resumeUnfinished),\n\t\tLayer.provideMerge(Heartbeat.layer),\n\t\tLayer.provide(OAuth.layer(options.harness.home === undefined ? {} : { home: options.harness.home })),\n\t\tLayer.provide(Host.layer),\n\t\tLayer.provide(Clones.layer),\n\t\tLayer.provide(trusted(options.trustedProxy)),\n\t);\n\treturn app.pipe(\n\t\tLayer.provideMerge(announce),\n\t\tLayer.provideMerge(NodeHttpServer.layer(createServer, { host: options.host, port: options.port })),\n\t\tLayer.provide(RpcSerialization.layerNdjson),\n\t\tLayer.provide(options.identity ?? Identity.layer),\n\t\tLayer.provide(Principal.layerToken),\n\t\t// Built after the harness and before everything above it, the listener included.\n\t\tLayer.provide(sweep),\n\t\tLayer.provide(machine),\n\t\tLayer.provide(Harness.layer(options.harness)),\n\t);\n};\n","import { Global, Settings } from \"@codeworksh/harness/effect\";\nimport { Config, Effect, FileSystem, Layer, Logger } from \"effect\";\nimport * as Runtime from \"../../../framework/runtime.ts\";\nimport * as Registration from \"../../../server/registration.ts\";\nimport * as Server from \"../../../server/server.ts\";\nimport { InvalidInputError, renderError } from \"../../error.ts\";\nimport { harnessOptions } from \"../../harness.ts\";\nimport { writeError } from \"../../output.ts\";\nimport { Cmd } from \"../cmd.ts\";\n\nconst failed = Effect.sync(() => {\n\tprocess.exitCode = 1;\n});\n\nconst report = (error: unknown) => writeError(renderError(error)).pipe(Effect.andThen(failed));\n\nconst entries = (values: ReadonlyArray<string>) =>\n\tvalues\n\t\t.flatMap((value) => value.split(\",\"))\n\t\t.map((entry) => entry.trim())\n\t\t.filter((entry) => entry !== \"\");\n\n/**\n * The proxies `--trusted-proxy` names, else `CODEWORK_TRUSTED_PROXY`; none from either leaves the\n * user settings' `server.trustedProxy`, which settings decode themselves.\n */\nconst trustedProxy = Effect.fn(function* (flag: ReadonlyArray<string>) {\n\tconst env = entries([yield* Config.String(\"CODEWORK_TRUSTED_PROXY\").pipe(Config.withDefault(\"\"))]);\n\tconst [source, given] = flag.length > 0 ? [\"--trusted-proxy\", entries(flag)] : [\"CODEWORK_TRUSTED_PROXY\", env];\n\tif (given.length === 0) return undefined;\n\treturn yield* Effect.forEach(given, (entry) => {\n\t\tconst network = Settings.proxyNetwork(entry);\n\t\treturn network === undefined\n\t\t\t? Effect.fail(new InvalidInputError({ message: `${source}: \"${entry}\" is not an IP address or CIDR range` }))\n\t\t\t: Effect.succeed(network);\n\t});\n});\n\nexport default Runtime.handler(\n\tCmd.commands.serve,\n\tEffect.fn(\"CLI.serve\", { level: \"Info\" })(function* ({ host, port, service, trustedProxy: flag }) {\n\t\tconst shared = yield* Cmd.spec;\n\t\tconst harness = { ...harnessOptions(shared), watchModels: true };\n\t\tconst serve = Effect.flatMap(trustedProxy(flag), (trusted) =>\n\t\t\tLayer.launch(\n\t\t\t\tServer.layer({ host, port, harness, ...(trusted === undefined ? {} : { trustedProxy: trusted }) }),\n\t\t\t),\n\t\t);\n\t\tif (!service) return yield* serve.pipe(Effect.catch(report));\n\n\t\t// A background server has no terminal: its log, and the reason it stopped, go to a\n\t\t// file the CLI that started it reads back when startup fails.\n\t\tconst background = Effect.gen(function* () {\n\t\t\tconst paths = yield* Global.resolve(harness.home === undefined ? {} : { home: harness.home });\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tyield* fs.makeDirectory(paths.log, { recursive: true });\n\t\t\tconst logger = Logger.formatSimple.pipe(Logger.toFile(Registration.log(paths.log), { flag: \"w\" }));\n\t\t\tyield* serve.pipe(\n\t\t\t\tEffect.catch((error) => Effect.logError(renderError(error).trim()).pipe(Effect.andThen(failed))),\n\t\t\t\tEffect.provide(Logger.layer([logger])),\n\t\t\t);\n\t\t});\n\t\tyield* background.pipe(Effect.catch(report));\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAaA,UAAQ,MAAM,cAC1B,OAAO,IAAI,aAAa;CACvB,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAOC,UAAgB,OAAO,IAAI,CAAC,CAAC,KACnC,OAAO,OAAO,UAAU,OAAO,SAAS,4BAA4B,KAAK,CAAC,GAC1E,OAAO,OAAO,SAAS,OAAO,YAAY,CAAC,GAC3C,OAAO,UACR;AACD,CAAC,CACF;;;;;;;;AC2BA,IAAaC,YAAb,cAA6B,QAAQ,QAA4B,CAAC,CAAC,uCAAuC,CAAC,CAAC,CAAC;AAE7G,MAAM,iBAAiB;AAGvB,MAAM,cAAc;AACpB,MAAM,aAAa;AACnB,MAAM,YAAY;AAElB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,aAAa;AAEnB,MAAM,cAAc;AAEpB,MAAM,YAAY;CAEjB,oBAAoB;CACpB,qBAAqB;CAErB,UAAU;AACX;AAEA,MAAM,aAAa,MAAc,cAChC,KAAK,UAAU,YAAY,OAAO,GAAG,KAAK,MAAM,GAAG,YAA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
@@ -1,7 +1,7 @@
1
1
  import { a as reportFailure, m as writeOut } from "./error-BsI8iNna.mjs";
2
2
  import { i as Cmd, t as handler } from "./runtime-Q4G4z83G.mjs";
3
3
  import { r as options } from "./service-B0O4PjbL.mjs";
4
- import { n as ensure } from "./discovery-CYiDVyU6.mjs";
4
+ import { n as ensure } from "./discovery-D2ftXE5a.mjs";
5
5
  import { Effect } from "effect";
6
6
  //#region src/cli/cmd/handlers/service/start.ts
7
7
  var start_default = handler(Cmd.commands.service.commands.start, Effect.fn("CLI.service.start")(function* ({ host, port }) {
@@ -18,4 +18,4 @@ var start_default = handler(Cmd.commands.service.commands.start, Effect.fn("CLI.
18
18
  //#endregion
19
19
  export { start_default as default };
20
20
 
21
- //# sourceMappingURL=start-_OgO4fEe.mjs.map
21
+ //# sourceMappingURL=start-DbCTFswo.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-_OgO4fEe.mjs","names":["Runtime.handler","options","Service.options","Discovery.ensure"],"sources":["../../src/cli/cmd/handlers/service/start.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.start,\n\tEffect.fn(\"CLI.service.start\")(function* ({ host, port }) {\n\t\tconst options = yield* Service.options(yield* Cmd.spec, { host, port });\n\t\tconst server = yield* Discovery.ensure({ ...options, replace: true });\n\t\tyield* writeOut(`${server.url}\\n`);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;;AAQA,IAAA,gBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,OAC9B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,MAAM,QAAQ;CACzD,MAAMC,YAAU,OAAOC,QAAgB,OAAO,IAAI,MAAM;EAAE;EAAM;CAAK,CAAC;CACtE,MAAM,SAAS,OAAOC,OAAiB;EAAE,GAAGF;EAAS,SAAS;CAAK,CAAC;CACpE,OAAO,SAAS,GAAG,OAAO,IAAI,GAAG;AAClC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
1
+ {"version":3,"file":"start-DbCTFswo.mjs","names":["Runtime.handler","options","Service.options","Discovery.ensure"],"sources":["../../src/cli/cmd/handlers/service/start.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.start,\n\tEffect.fn(\"CLI.service.start\")(function* ({ host, port }) {\n\t\tconst options = yield* Service.options(yield* Cmd.spec, { host, port });\n\t\tconst server = yield* Discovery.ensure({ ...options, replace: true });\n\t\tyield* writeOut(`${server.url}\\n`);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;;AAQA,IAAA,gBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,OAC9B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,MAAM,QAAQ;CACzD,MAAMC,YAAU,OAAOC,QAAgB,OAAO,IAAI,MAAM;EAAE;EAAM;CAAK,CAAC;CACtE,MAAM,SAAS,OAAOC,OAAiB;EAAE,GAAGF;EAAS,SAAS;CAAK,CAAC;CACpE,OAAO,SAAS,GAAG,OAAO,IAAI,GAAG;AAClC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
@@ -1,7 +1,7 @@
1
1
  import { a as reportFailure, m as writeOut } from "./error-BsI8iNna.mjs";
2
2
  import { i as Cmd, t as handler } from "./runtime-Q4G4z83G.mjs";
3
3
  import { n as home } from "./service-B0O4PjbL.mjs";
4
- import { t as discover } from "./discovery-CYiDVyU6.mjs";
4
+ import { t as discover } from "./discovery-D2ftXE5a.mjs";
5
5
  import { Effect } from "effect";
6
6
  //#region src/cli/cmd/handlers/service/status.ts
7
7
  var status_default = handler(Cmd.commands.service.commands.status, Effect.fn("CLI.service.status")(function* () {
@@ -12,4 +12,4 @@ var status_default = handler(Cmd.commands.service.commands.status, Effect.fn("CL
12
12
  //#endregion
13
13
  export { status_default as default };
14
14
 
15
- //# sourceMappingURL=status-Dnw-3t4J.mjs.map
15
+ //# sourceMappingURL=status-Dcbdl6Sv.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"status-Dnw-3t4J.mjs","names":["Runtime.handler","Service.home","Discovery.discover"],"sources":["../../src/cli/cmd/handlers/service/status.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.status,\n\tEffect.fn(\"CLI.service.status\")(function* () {\n\t\tconst paths = yield* Service.home(yield* Cmd.spec);\n\t\tconst server = yield* Discovery.discover(paths.home);\n\t\tyield* writeOut(`${server?.url ?? \"stopped\"}\\n`);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;;AAQA,IAAA,iBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,QAC9B,OAAO,GAAG,oBAAoB,CAAC,CAAC,aAAa;CAC5C,MAAM,QAAQ,OAAOC,KAAa,OAAO,IAAI,IAAI;CACjD,MAAM,SAAS,OAAOC,SAAmB,MAAM,IAAI;CACnD,OAAO,SAAS,GAAG,QAAQ,OAAO,UAAU,GAAG;AAChD,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
1
+ {"version":3,"file":"status-Dcbdl6Sv.mjs","names":["Runtime.handler","Service.home","Discovery.discover"],"sources":["../../src/cli/cmd/handlers/service/status.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.status,\n\tEffect.fn(\"CLI.service.status\")(function* () {\n\t\tconst paths = yield* Service.home(yield* Cmd.spec);\n\t\tconst server = yield* Discovery.discover(paths.home);\n\t\tyield* writeOut(`${server?.url ?? \"stopped\"}\\n`);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;;AAQA,IAAA,iBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,QAC9B,OAAO,GAAG,oBAAoB,CAAC,CAAC,aAAa;CAC5C,MAAM,QAAQ,OAAOC,KAAa,OAAO,IAAI,IAAI;CACjD,MAAM,SAAS,OAAOC,SAAmB,MAAM,IAAI;CACnD,OAAO,SAAS,GAAG,QAAQ,OAAO,UAAU,GAAG;AAChD,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
@@ -1,7 +1,7 @@
1
1
  import { a as reportFailure } from "./error-BsI8iNna.mjs";
2
2
  import { i as Cmd, t as handler } from "./runtime-Q4G4z83G.mjs";
3
3
  import { n as home } from "./service-B0O4PjbL.mjs";
4
- import { r as stop } from "./discovery-CYiDVyU6.mjs";
4
+ import { r as stop } from "./discovery-D2ftXE5a.mjs";
5
5
  import { Effect } from "effect";
6
6
  //#region src/cli/cmd/handlers/service/stop.ts
7
7
  var stop_default = handler(Cmd.commands.service.commands.stop, Effect.fn("CLI.service.stop")(function* () {
@@ -11,4 +11,4 @@ var stop_default = handler(Cmd.commands.service.commands.stop, Effect.fn("CLI.se
11
11
  //#endregion
12
12
  export { stop_default as default };
13
13
 
14
- //# sourceMappingURL=stop-BcbFFErk.mjs.map
14
+ //# sourceMappingURL=stop-ML5Yeo_s.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"stop-BcbFFErk.mjs","names":["Runtime.handler","Service.home","Discovery.stop"],"sources":["../../src/cli/cmd/handlers/service/stop.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.stop,\n\tEffect.fn(\"CLI.service.stop\")(function* () {\n\t\tconst paths = yield* Service.home(yield* Cmd.spec);\n\t\tyield* Discovery.stop(paths.home);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;;AAOA,IAAA,eAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,MAC9B,OAAO,GAAG,kBAAkB,CAAC,CAAC,aAAa;CAC1C,MAAM,QAAQ,OAAOC,KAAa,OAAO,IAAI,IAAI;CACjD,OAAOC,KAAe,MAAM,IAAI;AACjC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
1
+ {"version":3,"file":"stop-ML5Yeo_s.mjs","names":["Runtime.handler","Service.home","Discovery.stop"],"sources":["../../src/cli/cmd/handlers/service/stop.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.stop,\n\tEffect.fn(\"CLI.service.stop\")(function* () {\n\t\tconst paths = yield* Service.home(yield* Cmd.spec);\n\t\tyield* Discovery.stop(paths.home);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;;AAOA,IAAA,eAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,MAC9B,OAAO,GAAG,kBAAkB,CAAC,CAAC,aAAa;CAC1C,MAAM,QAAQ,OAAOC,KAAa,OAAO,IAAI,IAAI;CACjD,OAAOC,KAAe,MAAM,IAAI;AACjC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
@@ -1,6 +0,0 @@
1
- //#region package.json
2
- var version = "0.9.0-canary.165.2.g336229f9";
3
- //#endregion
4
- export { version as t };
5
-
6
- //# sourceMappingURL=package-DZfIu4Eq.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-DZfIu4Eq.mjs","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}