@codeworksh/cli 0.8.0 → 0.9.0-canary.158.1.gdff28d0d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{acp-DodCRypZ.mjs → acp-D1X6PAQd.mjs} +16 -11
- package/acp-D1X6PAQd.mjs.map +1 -0
- package/{add-Dgy0iTEQ.mjs → add-BO0TXkKX.mjs} +8 -7
- package/add-BO0TXkKX.mjs.map +1 -0
- package/{add-31QB-o0_.mjs → add-BwC5Yb3Z.mjs} +5 -5
- package/add-BwC5Yb3Z.mjs.map +1 -0
- package/{catalog-XfqtqMDz.mjs → catalog-BhnZFkoq.mjs} +2 -2
- package/{catalog-XfqtqMDz.mjs.map → catalog-BhnZFkoq.mjs.map} +1 -1
- package/{check-BoANDJxT.mjs → check-n2oLWYrZ.mjs} +4 -4
- package/check-n2oLWYrZ.mjs.map +1 -0
- package/connect-CO-oR-Br.mjs +35 -0
- package/connect-CO-oR-Br.mjs.map +1 -0
- package/{control-CQxWGS4k.mjs → control-Clr9Xyw9.mjs} +10 -9
- package/control-Clr9Xyw9.mjs.map +1 -0
- package/devices-aPlpoGGA.mjs +29 -0
- package/devices-aPlpoGGA.mjs.map +1 -0
- package/disconnect-B7HoGP0E.mjs +21 -0
- package/disconnect-B7HoGP0E.mjs.map +1 -0
- package/disconnect-gKR8hsnU.mjs +2 -0
- package/{service-CjOS-xCw.mjs → discovery-D07MPnKd.mjs} +13 -37
- package/discovery-D07MPnKd.mjs.map +1 -0
- package/{entries-DpL4xhu0.mjs → entries-BzfySpSJ.mjs} +3 -3
- package/{entries-DpL4xhu0.mjs.map → entries-BzfySpSJ.mjs.map} +1 -1
- package/{error-CPyvkO4x.mjs → error-ippxl2z7.mjs} +775 -31
- package/error-ippxl2z7.mjs.map +1 -0
- package/{fork-CjZteIbk.mjs → fork-lbhh_6QP.mjs} +8 -7
- package/fork-lbhh_6QP.mjs.map +1 -0
- package/identity-DbK4fABs.mjs +26 -0
- package/identity-DbK4fABs.mjs.map +1 -0
- package/{thread-I6vNdC0y.mjs → ids-cNIRx0-c.mjs} +11 -5
- package/ids-cNIRx0-c.mjs.map +1 -0
- package/index.mjs +39 -34
- package/index.mjs.map +1 -1
- package/{install-BUfEBtrj.mjs → install-dfD5hzCS.mjs} +4 -4
- package/install-dfD5hzCS.mjs.map +1 -0
- package/jsonc-CWL4-4yz.mjs +33 -0
- package/jsonc-CWL4-4yz.mjs.map +1 -0
- package/{link-ZuzWj9qt.mjs → link-D1cicwAl.mjs} +8 -6
- package/link-D1cicwAl.mjs.map +1 -0
- package/{list-DDuzyNv0.mjs → list-BKJgNMJm.mjs} +10 -12
- package/list-BKJgNMJm.mjs.map +1 -0
- package/{list-6QTwXTKO.mjs → list-C3McEC0O.mjs} +4 -4
- package/list-C3McEC0O.mjs.map +1 -0
- package/{list-DPbF2uMB.mjs → list-CGT6jT-r.mjs} +4 -4
- package/list-CGT6jT-r.mjs.map +1 -0
- package/{list-BnIIcMI3.mjs → list-DZK016LF.mjs} +4 -4
- package/list-DZK016LF.mjs.map +1 -0
- package/{login-BtuROCPJ.mjs → login-DuFDeGH-.mjs} +4 -4
- package/login-DuFDeGH-.mjs.map +1 -0
- package/{login-CGXU21AK.mjs → login-XhIIF5Yu.mjs} +4 -4
- package/login-XhIIF5Yu.mjs.map +1 -0
- package/{logout-DUn8KSjX.mjs → logout-CA1No9_2.mjs} +4 -4
- package/logout-CA1No9_2.mjs.map +1 -0
- package/{logout-Bnk2hxfZ.mjs → logout-Dpqw8tQZ.mjs} +4 -4
- package/logout-Dpqw8tQZ.mjs.map +1 -0
- package/package-DgfSc9nY.mjs +6 -0
- package/package-DgfSc9nY.mjs.map +1 -0
- package/package.json +3 -3
- package/pair-BC8a_KYX.mjs +15 -0
- package/pair-BC8a_KYX.mjs.map +1 -0
- package/{providers-GEdlDJHp.mjs → providers--giKGohM.mjs} +4 -4
- package/providers--giKGohM.mjs.map +1 -0
- package/reconnect-I9-Do_DK.mjs +2 -0
- package/{refresh-DGJW3rSp.mjs → refresh-BIH3qn5A.mjs} +4 -4
- package/refresh-BIH3qn5A.mjs.map +1 -0
- package/{refresh-93t2pSpb.mjs → refresh-Dg8WvRcq.mjs} +4 -4
- package/refresh-Dg8WvRcq.mjs.map +1 -0
- package/{identity-LhURGrcS.mjs → registration-C6yiv31r.mjs} +27 -25
- package/registration-C6yiv31r.mjs.map +1 -0
- package/relay-CLPWErNw.mjs +319 -0
- package/relay-CLPWErNw.mjs.map +1 -0
- package/{relink-Djy5t7D2.mjs → relink-D8Koos_q.mjs} +9 -7
- package/relink-D8Koos_q.mjs.map +1 -0
- package/{reload-Dm464rPC.mjs → reload-C5-B0s9x.mjs} +6 -5
- package/{reload-Dm464rPC.mjs.map → reload-C5-B0s9x.mjs.map} +1 -1
- package/{remove-DBT19X2j.mjs → remove-6m5n17il.mjs} +4 -4
- package/remove-6m5n17il.mjs.map +1 -0
- package/{remove-f7C_vEOD.mjs → remove-VZO51J2m.mjs} +5 -5
- package/remove-VZO51J2m.mjs.map +1 -0
- package/{restart-DXMDjblc.mjs → restart-4NoPj76N.mjs} +5 -4
- package/restart-4NoPj76N.mjs.map +1 -0
- package/revoke-Gu5N3Vzy.mjs +13 -0
- package/revoke-Gu5N3Vzy.mjs.map +1 -0
- package/{run-CTFksYXE.mjs → run-RHrJN2Pv.mjs} +12 -14
- package/run-RHrJN2Pv.mjs.map +1 -0
- package/{runtime-CK2CunDw.mjs → runtime-CtLWuLd-.mjs} +48 -12
- package/runtime-CtLWuLd-.mjs.map +1 -0
- package/{serve-BntJRQed.mjs → serve-BZ5FAU3h.mjs} +586 -64
- package/serve-BZ5FAU3h.mjs.map +1 -0
- package/service-CRnqz89w.mjs +79 -0
- package/service-CRnqz89w.mjs.map +1 -0
- package/{settings-DasbTMFs.mjs → settings-DU140UBM.mjs} +3 -3
- package/settings-DU140UBM.mjs.map +1 -0
- package/{shared-CDyNsYBy.mjs → shared-CC4WukJX.mjs} +4 -4
- package/shared-CC4WukJX.mjs.map +1 -0
- package/{shared-CiSbTY59.mjs → shared-Dzwbs5Lk.mjs} +7 -9
- package/shared-Dzwbs5Lk.mjs.map +1 -0
- package/{start-CTYwK1Z4.mjs → start-COhahq2E.mjs} +5 -4
- package/start-COhahq2E.mjs.map +1 -0
- package/{status-CPKssQFk.mjs → status-Cau7bzuQ.mjs} +5 -4
- package/status-Cau7bzuQ.mjs.map +1 -0
- package/{status-CHcJyF_7.mjs → status-DJJOuCzL.mjs} +4 -4
- package/status-DJJOuCzL.mjs.map +1 -0
- package/{stop-CpQr3fUv.mjs → stop-CC--mxXp.mjs} +5 -4
- package/stop-CC--mxXp.mjs.map +1 -0
- package/{update-C3llbIB0.mjs → update-DMQLgDm3.mjs} +4 -4
- package/update-DMQLgDm3.mjs.map +1 -0
- package/acp-DodCRypZ.mjs.map +0 -1
- package/add-31QB-o0_.mjs.map +0 -1
- package/add-Dgy0iTEQ.mjs.map +0 -1
- package/check-BoANDJxT.mjs.map +0 -1
- package/control-CQxWGS4k.mjs.map +0 -1
- package/disconnect-BiLuV4JZ.mjs +0 -2
- package/error-CPyvkO4x.mjs.map +0 -1
- package/fork-CjZteIbk.mjs.map +0 -1
- package/identity-LhURGrcS.mjs.map +0 -1
- package/install-BUfEBtrj.mjs.map +0 -1
- package/jsonc-Ca0uQLm-.mjs +0 -58
- package/jsonc-Ca0uQLm-.mjs.map +0 -1
- package/link-ZuzWj9qt.mjs.map +0 -1
- package/list-6QTwXTKO.mjs.map +0 -1
- package/list-BnIIcMI3.mjs.map +0 -1
- package/list-DDuzyNv0.mjs.map +0 -1
- package/list-DPbF2uMB.mjs.map +0 -1
- package/login-BtuROCPJ.mjs.map +0 -1
- package/login-CGXU21AK.mjs.map +0 -1
- package/logout-Bnk2hxfZ.mjs.map +0 -1
- package/logout-DUn8KSjX.mjs.map +0 -1
- package/package-C5s94xPy.mjs +0 -6
- package/package-C5s94xPy.mjs.map +0 -1
- package/providers-GEdlDJHp.mjs.map +0 -1
- package/reconnect-ChE5ETwx.mjs +0 -2
- package/refresh-93t2pSpb.mjs.map +0 -1
- package/refresh-DGJW3rSp.mjs.map +0 -1
- package/relink-Djy5t7D2.mjs.map +0 -1
- package/remove-DBT19X2j.mjs.map +0 -1
- package/remove-f7C_vEOD.mjs.map +0 -1
- package/restart-DXMDjblc.mjs.map +0 -1
- package/run-CTFksYXE.mjs.map +0 -1
- package/runtime-CK2CunDw.mjs.map +0 -1
- package/serve-BntJRQed.mjs.map +0 -1
- package/service-CjOS-xCw.mjs.map +0 -1
- package/settings-DasbTMFs.mjs.map +0 -1
- package/shared-CDyNsYBy.mjs.map +0 -1
- package/shared-CiSbTY59.mjs.map +0 -1
- package/start-CTYwK1Z4.mjs.map +0 -1
- package/status-CHcJyF_7.mjs.map +0 -1
- package/status-CPKssQFk.mjs.map +0 -1
- package/stop-CpQr3fUv.mjs.map +0 -1
- package/thread-I6vNdC0y.mjs.map +0 -1
- package/update-C3llbIB0.mjs.map +0 -1
package/runtime-CK2CunDw.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-CK2CunDw.mjs","names":["Spec.make","Otel.layer"],"sources":["../../src/framework/spec.ts","../../src/cli/cmd/cmd.ts","../../src/framework/otel.ts","../../src/framework/runtime.ts"],"sourcesContent":["import { Command } from \"effect/cli\";\n\n/**\n * A declarative command tree. Specs carry only the shape of a command -- its\n * name, parameters, description, and children -- so the whole CLI surface can\n * be read in one file. Handlers are attached separately by {@link Runtime}, which\n * keeps their imports (and the harness they pull in) off the startup path.\n */\n\nexport interface Example {\n\treadonly command: string;\n\treadonly description: string;\n}\n\ninterface Options<\n\tConfig extends Command.Command.Config,\n\tShared extends Command.Command.FlagConfig,\n\tCommands extends ReadonlyArray<Any>,\n> {\n\treadonly description?: string;\n\treadonly params?: Config;\n\t/** Flags declared here are also parsed by every descendant command. */\n\treadonly shared?: Shared;\n\treadonly examples?: ReadonlyArray<Example>;\n\treadonly commands?: Commands;\n}\n\nexport interface Node<\n\tName extends string,\n\t// The tree is heterogeneous, so a node has to accept any command shape here.\n\t// Concrete types are recovered per-command through `Runtime.Input`.\n\t// biome-ignore lint/suspicious/noExplicitAny: heterogeneous command tree\n\tSpec extends Command.Command<Name, any, any, any, any>,\n\tCommands extends Children,\n> {\n\treadonly name: Name;\n\treadonly spec: Spec;\n\treadonly commands: Commands;\n}\n\n// The command name is invariant on `Command`, so the erased node type has to\n// admit any name for concrete nodes to be assignable to it.\n// biome-ignore lint/suspicious/noExplicitAny: heterogeneous command tree\nexport type Any = Node<string, Command.Command<any, any, any, any, any>, Children>;\nexport type Children = Readonly<Record<string, Any>>;\n\ntype ChildrenOf<Commands extends ReadonlyArray<Any>> = {\n\treadonly [Node in Commands[number] as Node[\"name\"]]: Node;\n};\n\nexport function make<\n\tconst Name extends string,\n\tconst Config extends Command.Command.Config = {},\n\tconst Shared extends Command.Command.FlagConfig = {},\n\tconst Commands extends ReadonlyArray<Any> = [],\n>(name: Name, options: Options<Config, Shared, Commands> = {}) {\n\tlet spec = Command.make(name, options.params ?? ({} as Config)).pipe(\n\t\tCommand.withSharedFlags(options.shared ?? ({} as Shared)),\n\t);\n\tif (options.description !== undefined) spec = spec.pipe(Command.withDescription(options.description));\n\tif (options.examples !== undefined) spec = spec.pipe(Command.withExamples(options.examples));\n\treturn {\n\t\tname,\n\t\tspec,\n\t\tcommands: Object.fromEntries(\n\t\t\t(options.commands ?? []).map((command) => [command.name, command]),\n\t\t) as ChildrenOf<Commands>,\n\t};\n}\n\nexport * as Spec from \"./spec.ts\";\n","import { Model } from \"@codeworksh/aikit\";\nimport { Schema } from \"effect\";\nimport { Argument, Flag } from \"effect/cli\";\nimport { Spec } from \"../../framework/spec.ts\";\n\n/**\n * The full command surface of the `codework` CLI. Declarations only -- each\n * command's behaviour lives in `./handlers`, wired up in `src/index.ts`.\n */\n\nexport const thinkingLevels = Object.values(Model.ThinkingLevelEnum);\n\n/**\n * Every `auth` subcommand answers the same three questions: which provider,\n * whose credentials, and where they live. Only `login` needs anything more.\n */\nconst AuthParams = {\n\topenaiCodex: Flag.Boolean(\"openai-codex\").pipe(\n\t\tFlag.withDescription(\"Use OpenAI Codex OAuth\"),\n\t\tFlag.withDefault(false),\n\t),\n\tgithubCopilot: Flag.Boolean(\"github-copilot\").pipe(\n\t\tFlag.withDescription(\"Use GitHub Copilot OAuth (device flow)\"),\n\t\tFlag.withDefault(false),\n\t),\n\tserver: Flag.String(\"server\").pipe(Flag.withDescription(\"RPC server URL (ws://host:port/rpc/v1)\"), Flag.optional),\n\tauthFile: Flag.String(\"auth-file\").pipe(\n\t\tFlag.withDescription(\"Credential file (defaults to <home>/aikit/auth.json)\"),\n\t\tFlag.optional,\n\t),\n};\n\n/** Where the background server binds when `service` has to start one. */\nconst ServerAddress = {\n\thost: Flag.String(\"host\").pipe(\n\t\tFlag.withDescription(\"Host interface the background server binds\"),\n\t\tFlag.withDefault(\"127.0.0.1\"),\n\t),\n\tport: Flag.Int(\"port\").pipe(\n\t\tFlag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 65535 }))),\n\t\tFlag.withDescription(\"Port the background server listens on\"),\n\t\tFlag.withDefault(7433),\n\t),\n};\n\n/** For commands that only talk to a server that is already running. */\nconst RunningServer = Flag.String(\"server\").pipe(\n\tFlag.withDescription(\"RPC server URL (ws://host:port/rpc/v1)\"),\n\tFlag.withDefault(\"ws://127.0.0.1:7433/rpc/v1\"),\n);\n\n/** A thread's MCP server in a running server: every thread sharing its instance is affected. */\nconst McpControlParams = {\n\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\tsession: Flag.String(\"session\").pipe(Flag.withAlias(\"s\"), Flag.withDescription(\"The session\")),\n\tthread: Flag.String(\"thread\").pipe(\n\t\tFlag.withDescription(\"Thread of --session whose server it is: a thread ID, or main (default)\"),\n\t\tFlag.optional,\n\t),\n\tserver: RunningServer,\n};\n\nconst JsonFlag = Flag.Boolean(\"json\").pipe(\n\tFlag.withDescription(\"Print machine-readable output\"),\n\tFlag.withDefault(false),\n);\n\nexport const Cmd = Spec.make(\"codework\", {\n\tdescription: \"CodeWork Command Line Interface\",\n\tshared: {\n\t\tuserConfigDir: Flag.String(\"user-config-dir\").pipe(\n\t\t\tFlag.withDescription(\"Directory whose settings.jsonc replaces the user settings in --home\"),\n\t\t\tFlag.optional,\n\t\t),\n\t\thome: Flag.String(\"home\").pipe(\n\t\t\tFlag.withDescription(\"CodeWork home: user settings, credentials, cache and data (default: ~/.codework)\"),\n\t\t\tFlag.optional,\n\t\t),\n\t\tdatabase: Flag.String(\"database\").pipe(Flag.withDescription(\"SQLite database path or :memory:\"), Flag.optional),\n\t},\n\tcommands: [\n\t\tSpec.make(\"auth\", {\n\t\t\tdescription: \"Manage OAuth credentials\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"login\", {\n\t\t\t\t\tdescription: \"Sign in to a provider\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\t...AuthParams,\n\t\t\t\t\t\tbrowser: Flag.Boolean(\"browser\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Open the authorization URL in the default browser\"),\n\t\t\t\t\t\t\tFlag.withDefault(true),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdevice: Flag.Boolean(\"device\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Use the device-code flow instead of a localhost browser callback\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tenterprise: Flag.String(\"enterprise\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"GitHub Enterprise domain for GitHub Copilot login\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tenableModels: Flag.Boolean(\"enable-models\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Enable unconfigured Copilot catalog models after login\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework auth login --openai-codex\", description: \"Sign in with ChatGPT\" },\n\t\t\t\t\t\t{ command: \"codework auth login --github-copilot\", description: \"Sign in with GitHub Copilot\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework auth login --openai-codex --device\",\n\t\t\t\t\t\t\tdescription: \"Sign in with a device code, no local port\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework auth login --openai-codex --server ws://127.0.0.1:7433/rpc/v1\",\n\t\t\t\t\t\t\tdescription: \"Sign in the running server\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"status\", {\n\t\t\t\t\tdescription: \"Show a stored login without refreshing it\",\n\t\t\t\t\tparams: { ...AuthParams, json: JsonFlag },\n\t\t\t\t\texamples: [{ command: \"codework auth status --openai-codex\", description: \"Show the stored login\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"refresh\", {\n\t\t\t\t\tdescription: \"Refresh a stored login if it has expired\",\n\t\t\t\t\tparams: { ...AuthParams, json: JsonFlag },\n\t\t\t\t\texamples: [{ command: \"codework auth refresh --openai-codex\", description: \"Renew an expired login\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"logout\", {\n\t\t\t\t\tdescription: \"Clear a stored login\",\n\t\t\t\t\tparams: AuthParams,\n\t\t\t\t\texamples: [{ command: \"codework auth logout --github-copilot\", description: \"Clear the stored login\" }],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"mcp\", {\n\t\t\tdescription: \"Manage MCP servers\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"add\", {\n\t\t\t\t\tdescription: \"Add or replace a server in mcp.json\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name\")),\n\t\t\t\t\t\tcommand: Argument.String(\"command\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Command and arguments of a stdio server, after --\"),\n\t\t\t\t\t\t\tArgument.variadic({ min: 0 }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\turl: Flag.String(\"url\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Streamable HTTP server URL (instead of a command)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tenv: Flag.KeyValuePair(\"env\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Environment variable of a stdio server, as KEY=VALUE\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcwd: Flag.String(\"cwd\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Working directory of a stdio server\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\theader: Flag.KeyValuePair(\"header\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"HTTP header, as KEY=VALUE\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tbearerTokenEnvVar: Flag.String(\"bearer-token-env-var\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription('Send \"Authorization: Bearer ${NAME}\"'),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthClientId: Flag.String(\"oauth-client-id\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Pre-registered OAuth client id\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthClientSecret: Flag.String(\"oauth-client-secret\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"OAuth client secret (may be ${NAME} or !command)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthCallbackPort: Flag.Int(\"oauth-callback-port\").pipe(\n\t\t\t\t\t\t\tFlag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 }))),\n\t\t\t\t\t\t\tFlag.withDescription(\"Fixed OAuth callback port\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthClientName: Flag.String(\"oauth-client-name\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Client name sent when registering with the OAuth server\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\texposure: Flag.Literals(\"exposure\", [\"direct\", \"hidden\", \"codemode\", \"deferred\"]).pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"How the model reaches the server's tools (default: direct)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdescription: Flag.String(\"description\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"What the server offers\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tlocal: Flag.Boolean(\"local\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"l\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Write the project's .codework/mcp.json instead of the user one\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp add fs -- npx -y @modelcontextprotocol/server-filesystem .\",\n\t\t\t\t\t\t\tdescription: \"Add a stdio server\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp add linear --url https://mcp.linear.app/mcp\",\n\t\t\t\t\t\t\tdescription: \"Add an HTTP server; sign in with codework mcp login linear\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp add tools -l --url http://127.0.0.1:8080/mcp\",\n\t\t\t\t\t\t\tdescription: \"Add a server to this project only\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"remove\", {\n\t\t\t\t\tdescription: \"Remove a server from mcp.json\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\t\t\t\t\t\tlocal: Flag.Boolean(\"local\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"l\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Remove it from the project's .codework/mcp.json instead of the user one\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework mcp remove linear\", description: \"Remove the linear server\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"list\", {\n\t\t\t\t\tdescription: \"Connect to every enabled server and show its state, tools and errors\",\n\t\t\t\t\tparams: { json: JsonFlag },\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework mcp list\", description: \"Check every configured server; exits 1 on a failure\" },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"login\", {\n\t\t\t\t\tdescription: \"Sign in to an MCP server with OAuth\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\t\t\t\t\t\tbrowser: Flag.Boolean(\"browser\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Open the authorization URL in the default browser\"),\n\t\t\t\t\t\t\tFlag.withDefault(true),\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttimeout: Flag.Int(\"timeout\").pipe(\n\t\t\t\t\t\t\tFlag.withSchema(Schema.Int.check(Schema.isGreaterThan(0))),\n\t\t\t\t\t\t\tFlag.withDescription(\"Seconds the whole sign-in may take\"),\n\t\t\t\t\t\t\tFlag.withDefault(300),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework mcp login linear\", description: \"Sign in to the linear server\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp login linear --browser=false\",\n\t\t\t\t\t\t\tdescription: \"Print the URL; paste the redirected URL back if the browser is elsewhere\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"logout\", {\n\t\t\t\t\tdescription: \"Remove the stored OAuth credentials of an MCP server\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework mcp logout linear\", description: \"Sign out of the linear server\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"reconnect\", {\n\t\t\t\t\tdescription: \"Connect a thread's MCP server afresh in a running server\",\n\t\t\t\t\tparams: McpControlParams,\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp reconnect linear --session ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Restart the linear server the main thread uses; its tools return from the next turn\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp reconnect linear --session ses_01h9 --thread thr_01ja\",\n\t\t\t\t\t\t\tdescription: \"Restart the one a thread of the session uses\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"disconnect\", {\n\t\t\t\t\tdescription: \"Close a thread's MCP server in a running server until it is reconnected\",\n\t\t\t\t\tparams: McpControlParams,\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp disconnect linear --session ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Close the linear server the main thread uses\",\n\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\tSpec.make(\"run\", {\n\t\t\tdescription: \"Start or continue an agent session\",\n\t\t\tparams: {\n\t\t\t\tserver: Flag.String(\"server\").pipe(\n\t\t\t\t\tFlag.withDescription(\"RPC server URL (ws://host:port/rpc/v1)\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tprompt: Argument.String(\"prompt\").pipe(Argument.withDescription(\"Prompt for the agent\")),\n\t\t\t\tsession: Flag.String(\"session\").pipe(\n\t\t\t\t\tFlag.withAlias(\"s\"),\n\t\t\t\t\tFlag.withDescription(\"Continue an existing session\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tthread: Flag.String(\"thread\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Thread of --session to continue: a thread ID, or main (default)\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tcwd: Flag.String(\"cwd\").pipe(\n\t\t\t\t\tFlag.withAlias(\"C\"),\n\t\t\t\t\tFlag.withDescription(\"Working directory for a new session\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tsandboxDriver: Flag.String(\"sandbox-driver\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Sandbox driver for a new session (default: local)\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tsandboxId: Flag.String(\"sandbox-id\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Reuse an existing sandbox instance\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tsandboxProviderId: Flag.String(\"sandbox-provider-id\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Provider ID of an existing remote sandbox\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tprovider: Flag.String(\"provider\").pipe(Flag.withDescription(\"Model catalog provider ID\"), Flag.optional),\n\t\t\t\tmodel: Flag.String(\"model\").pipe(Flag.withDescription(\"Model ID\"), Flag.optional),\n\t\t\t\tthinking: Flag.Literals(\"thinking\", thinkingLevels).pipe(\n\t\t\t\t\tFlag.withDescription(\"Reasoning effort the model uses before answering\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t},\n\t\t\texamples: [\n\t\t\t\t{ command: 'codework run \"Inspect the failing tests\"', description: \"Create a session\" },\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --provider openai --model gpt-5.5 --thinking high \"Inspect the failing tests\"',\n\t\t\t\t\tdescription: \"Create a session with an explicit model\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --sandbox-driver daytona \"Inspect the repository\"',\n\t\t\t\t\tdescription: \"Create a Daytona sandbox and session\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --sandbox-driver daytona --sandbox-provider-id <id> \"Inspect the repository\"',\n\t\t\t\t\tdescription: \"Use an existing remote sandbox\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --session <id> --provider openai --model gpt-5.6-luna \"Now fix them\"',\n\t\t\t\t\tdescription: \"Continue a session with explicit model bindings\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --session <id> --thread <thread-id> \"Try OAuth instead\"',\n\t\t\t\t\tdescription: \"Continue one of the session's threads\",\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"serve\", {\n\t\t\tdescription: \"Start the CodeWork RPC server\",\n\t\t\tparams: {\n\t\t\t\thost: Flag.String(\"host\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Host interface to bind\"),\n\t\t\t\t\tFlag.withDefault(\"127.0.0.1\"),\n\t\t\t\t),\n\t\t\t\tport: Flag.Int(\"port\").pipe(\n\t\t\t\t\tFlag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 65535 }))),\n\t\t\t\t\tFlag.withDescription(\"Port to listen on (0 for an ephemeral port)\"),\n\t\t\t\t\tFlag.withDefault(7433),\n\t\t\t\t),\n\t\t\t\tservice: Flag.Boolean(\"service\").pipe(\n\t\t\t\t\tFlag.withDescription(\n\t\t\t\t\t\t\"Run as the background server `codework service` manages, logging to <home>/log/server.log\",\n\t\t\t\t\t),\n\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t),\n\t\t\t},\n\t\t\texamples: [\n\t\t\t\t{ command: \"codework serve\", description: \"Start the RPC server on 127.0.0.1:7433\" },\n\t\t\t\t{ command: \"codework serve --port 0\", description: \"Choose an available local port\" },\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"service\", {\n\t\t\tdescription: \"Manage the background server\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"start\", { description: \"Start the background server\", params: ServerAddress }),\n\t\t\t\tSpec.make(\"restart\", { description: \"Restart the background server\", params: ServerAddress }),\n\t\t\t\tSpec.make(\"status\", { description: \"Show background server status\" }),\n\t\t\t\tSpec.make(\"stop\", { description: \"Stop the background server\" }),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"session\", {\n\t\t\tdescription: \"Manage sessions\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"link\", {\n\t\t\t\t\tdescription: \"Anchor a session to a host directory\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session to link\")),\n\t\t\t\t\t\tpath: Argument.String(\"path\").pipe(\n\t\t\t\t\t\t\t// The anchor is not a configuration mechanism, but `.codework` is the landmark\n\t\t\t\t\t\t\t// a person recognises, so the help names it to make the directory concrete.\n\t\t\t\t\t\t\tArgument.withDescription(\n\t\t\t\t\t\t\t\t\"Host directory to anchor to — typically the directory holding your .codework configuration; defaults to the shell's\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tArgument.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tunlink: Flag.Boolean(\"unlink\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Clear the anchor, leaving the session with no host directory\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session link ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Link it to the directory you are standing in\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session link ses_01h9 ~/work/api\",\n\t\t\t\t\t\t\tdescription: \"Link it to a project elsewhere on this machine\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session link ses_01h9 --unlink\",\n\t\t\t\t\t\t\tdescription: \"Clear the anchor\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"relink\", {\n\t\t\t\t\tdescription: \"Move where a session's work, or one thread's, happens\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session to move\")),\n\t\t\t\t\t\tthread: Flag.String(\"thread\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\n\t\t\t\t\t\t\t\t\"Move only this thread: a thread ID, or main; omitted moves the session's default\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdirectory: Flag.String(\"directory\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"C\"),\n\t\t\t\t\t\t\tFlag.withDescription(\n\t\t\t\t\t\t\t\t\"Checkout to move into; the work keeps its position under it when that path exists there\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tsandboxId: Flag.String(\"sandbox-id\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Sandbox instance to move to (default: local)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session relink ses_01h9 -C ~/work/api\",\n\t\t\t\t\t\t\tdescription: \"Move the session to a local checkout\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session relink ses_01h9 --thread thr_01ja --sandbox-id sbx_01k2\",\n\t\t\t\t\t\t\tdescription: \"Run one thread in a sandbox, leaving the others where they are\",\n\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\tSpec.make(\"thread\", {\n\t\t\tdescription: \"Manage a session's threads\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"list\", {\n\t\t\t\t\tdescription: \"List a session's threads, newest first\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session\")),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework thread list ses_01h9\", description: \"List the session's threads\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"fork\", {\n\t\t\t\t\tdescription: \"Start a new thread from a committed entry of a thread's history\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session\")),\n\t\t\t\t\t\tthread: Flag.String(\"thread\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Thread to fork: a thread ID, or main (default)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tat: Flag.String(\"at\").pipe(Flag.withDescription(\"Keep history through this entry\"), Flag.optional),\n\t\t\t\t\t\tbefore: Flag.String(\"before\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Keep history up to this user entry, and print its text to edit\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework thread fork ses_01h9 --at 01jb\",\n\t\t\t\t\t\t\tdescription: \"Continue the main thread's history through an entry in a new thread\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework thread fork ses_01h9 --thread thr_01ja --before 01jc\",\n\t\t\t\t\t\t\tdescription: \"Branch just before a prompt, to send it again differently\",\n\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\tSpec.make(\"plugin\", {\n\t\t\tdescription: \"Manage plugins\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"add\", {\n\t\t\t\t\tdescription: \"Install a plugin and add it to a settings file\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tpackage: Argument.String(\"package\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Package spec, path, or file: URL\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tglobal: Flag.Boolean(\"global\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"g\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Write the user-wide settings file instead of this project's\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tsession: Flag.String(\"session\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Write the project a session is linked to, rather than this directory's\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin add @acme/codework-tool-proc@1.2.0\",\n\t\t\t\t\t\t\tdescription: \"Install a published plugin into this project's settings\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin add @acme/codework-tool-proc --session ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Write the project that session is linked to, from anywhere\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin add @acme/codework-tool-proc -g\",\n\t\t\t\t\t\t\tdescription: \"Install it for every project this user runs\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"install\", {\n\t\t\t\t\tdescription: \"Install every plugin the settings files name\",\n\t\t\t\t\tparams: {},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin install\",\n\t\t\t\t\t\t\tdescription: \"Materialise what a fresh checkout already declares\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"list\", {\n\t\t\t\t\tdescription: \"List configured plugins and what each one resolved to\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tverbose: Flag.Boolean(\"verbose\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Show the message behind a failure, not only its reason\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework plugin list\", description: \"Show every configured plugin\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"check\", {\n\t\t\t\t\tdescription: \"Report which configured plugins have a newer revision available\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tspec: Argument.String(\"spec\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Only this configured plugin: a package name or spec, git spec, or path\"),\n\t\t\t\t\t\t\tArgument.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// An answer is reused for an hour, which is right for a command someone may\n\t\t\t\t\t\t// run repeatedly and wrong for the minute after they pushed a plugin. Without\n\t\t\t\t\t\t// this there is no way to say \"ask again\", and `check` reports a moving branch\n\t\t\t\t\t\t// as current while `update` — which always refreshes — moves it.\n\t\t\t\t\t\trefresh: Flag.Boolean(\"refresh\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Ask the remote again instead of reusing a recent answer\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework plugin check\", description: \"Ask the registry what has moved\" },\n\t\t\t\t\t\t{ command: \"codework plugin check @acme/codework-tool-proc\", description: \"Ask about one plugin\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin check --refresh\",\n\t\t\t\t\t\t\tdescription: \"Ignore the cached answer, after pushing a plugin\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"update\", {\n\t\t\t\t\tdescription: \"Fetch a newer revision of every plugin that has one\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tspec: Argument.String(\"spec\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Only this configured plugin: a package name or spec, git spec, or path\"),\n\t\t\t\t\t\t\tArgument.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework plugin update\", description: \"Take whatever `check` found\" },\n\t\t\t\t\t\t{ command: \"codework plugin update @acme/codework-tool-proc\", description: \"Update one plugin\" },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"reload\", {\n\t\t\t\t\tdescription: \"Re-import configured plugins in a running server\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin reload\",\n\t\t\t\t\t\t\tdescription: \"Pick up edits to a local plugin without restarting\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"remove\", {\n\t\t\t\t\tdescription: \"Remove a plugin from a settings file\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tpackage: Argument.String(\"package\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Configured package spec, path, or plugin ID\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tglobal: Flag.Boolean(\"global\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"g\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Edit the user-wide settings file instead of this project's\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin remove @acme/codework-tool-proc\",\n\t\t\t\t\t\t\tdescription: \"Drop a plugin and any configuration written against it\",\n\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\tSpec.make(\"models\", {\n\t\t\tdescription: \"List or refresh the model catalog\",\n\t\t\tparams: {\n\t\t\t\tprovider: Flag.String(\"provider\").pipe(Flag.withDescription(\"Model catalog provider ID\"), Flag.optional),\n\t\t\t},\n\t\t\texamples: [\n\t\t\t\t{ command: \"codework models\", description: \"List all models from all providers\" },\n\t\t\t\t{\n\t\t\t\t\tcommand: \"codework models --provider openai\",\n\t\t\t\t\tdescription: \"List models for a specific provider\",\n\t\t\t\t},\n\t\t\t\t{ command: \"codework models providers\", description: \"List all available provider IDs\" },\n\t\t\t],\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"providers\", {\n\t\t\t\t\tdescription: \"List available model providers in the catalog\",\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"refresh\", {\n\t\t\t\t\tdescription: \"Download the model catalog into the home if it is stale\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tforce: Flag.Boolean(\"force\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Download it even if it is still fresh\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework models refresh\", description: \"Refresh a catalog older than 15 minutes\" },\n\t\t\t\t\t\t{ command: \"codework models refresh --force\", description: \"Download the catalog now\" },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"acp\", {\n\t\t\tdescription: \"Start the CodeWork Agent Client Protocol (ACP) server over stdio\",\n\t\t\texamples: [{ command: \"codework acp\", description: \"Start the ACP server on stdio\" }],\n\t\t}),\n\t],\n});\n","import { Config, ConfigProvider, Effect, Layer, Metric, Option, References, Schema } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { OtlpMetrics, OtlpSerialization, OtlpTracer } from \"effect/observability\";\nimport { uuidv7 } from \"uuidv7\";\n\n// Configured by the standard `OTEL_*` variables alone. A configuration that fails\n// to build runs the command without export rather than failing it.\n\n// The OTel spec defaults `OTEL_{TRACES,METRICS}_EXPORTER` to `otlp`; Effect reads an\n// unset list as none, so an endpoint alone would export nothing.\nconst exporterDefaults = ConfigProvider.layerAdd(\n\tConfigProvider.fromUnknown({ OTEL_TRACES_EXPORTER: [\"otlp\"], OTEL_METRICS_EXPORTER: [\"otlp\"] }),\n);\n\n// Effect's fiber metrics hook every fiber start and end, so they follow metrics export.\nconst metricsEnabled = Config.all({\n\tdisabled: Config.Boolean(\"OTEL_SDK_DISABLED\").pipe(Config.withDefault(false)),\n\tendpoint: Config.String(\"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT\").pipe(\n\t\tConfig.orElse(() => Config.String(\"OTEL_EXPORTER_OTLP_ENDPOINT\")),\n\t\tConfig.option,\n\t),\n\texporters: Config.Array(Schema.String, \"OTEL_METRICS_EXPORTER\"),\n}).pipe(\n\tConfig.map(\n\t\t({ disabled, endpoint, exporters }) =>\n\t\t\t!disabled && Option.isSome(endpoint) && exporters.some((exporter) => exporter.trim().toLowerCase() === \"otlp\"),\n\t),\n);\n\nconst fiberMetrics = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\treturn (yield* metricsEnabled) ? Metric.enableRuntimeMetricsLayer : Layer.empty;\n\t}),\n);\n\n// Only spans marked `level: \"Info\"` are exported; the rest, Effect's own `sql.*`\n// among them, default to `Debug`. Effect drops a span's children with it, so every\n// span on the path from a command to a model or tool call must be `Info`.\nconst levels = { all: \"All\", trace: \"Trace\", debug: \"Debug\", info: \"Info\", warn: \"Warn\", error: \"Error\" } as const;\n\nconst traceLevels = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\tconst name = yield* Config.String(\"CODEWORK_TRACE_LEVEL\").pipe(Config.withDefault(\"info\"));\n\t\tconst minimum = levels[name.trim().toLowerCase() as keyof typeof levels] ?? \"Info\";\n\t\treturn Layer.mergeAll(\n\t\t\tLayer.succeed(References.CurrentTraceLevel, \"Debug\"),\n\t\t\tLayer.succeed(References.MinimumTraceLevel, minimum),\n\t\t);\n\t}),\n);\n\ninterface OtlpResource {\n\treadonly serviceName: string;\n\treadonly serviceVersion: string;\n\treadonly attributes: Record<string, string>;\n}\n\n// Effect has no gRPC exporter: `grpc` exports nothing rather than sending HTTP to a gRPC port.\nconst exporters = (resource: OtlpResource) =>\n\tLayer.unwrap(\n\t\tEffect.gen(function* () {\n\t\t\tconst protocol = yield* Config.String(\"OTEL_EXPORTER_OTLP_PROTOCOL\").pipe(Config.withDefault(\"http/protobuf\"));\n\t\t\tconst format = {\n\t\t\t\t\"http/json\": OtlpSerialization.layerJson,\n\t\t\t\t\"http/protobuf\": OtlpSerialization.layerProtobuf,\n\t\t\t}[protocol.trim().toLowerCase()];\n\t\t\tif (format === undefined) return Layer.empty;\n\t\t\treturn Layer.mergeAll(\n\t\t\t\tOtlpTracer.layerFromConfig({ resource }),\n\t\t\t\tOtlpMetrics.layerFromConfig({ resource }),\n\t\t\t).pipe(Layer.provide(format));\n\t\t}),\n\t);\n\nconst channel = (version: string) =>\n\tversion.includes(\"-canary.\") ? \"canary\" : version.includes(\"-dev.\") ? \"dev\" : \"latest\";\n\nconst instanceId = uuidv7();\n\nexport const layer = (options: { readonly version: string; readonly command: string }) => {\n\tconst resource: OtlpResource = {\n\t\tserviceName: \"codework\",\n\t\tserviceVersion: options.version,\n\t\tattributes: {\n\t\t\t\"service.instance.id\": instanceId,\n\t\t\t\"deployment.environment.name\": channel(options.version),\n\t\t\t\"codework.command\": options.command,\n\t\t},\n\t};\n\treturn Layer.mergeAll(exporters(resource), fiberMetrics, traceLevels).pipe(\n\t\tLayer.provide(FetchHttpClient.layer),\n\t\tLayer.provide(exporterDefaults),\n\t\tLayer.catchCause(() => Layer.empty),\n\t);\n};\n\nexport * as Otel from \"./otel.ts\";\n","import { Effect } from \"effect\";\nimport { Command } from \"effect/cli\";\nimport type { CommandError } from \"../cli/error.ts\";\nimport { Otel } from \"./otel.ts\";\nimport { Spec } from \"./spec.ts\";\n\n/**\n * Binds handlers to a {@link Spec} tree. Handlers are loaded through dynamic\n * imports so that starting the process -- or printing `--help` -- never pulls in\n * the harness, its sandbox drivers, or the model catalog.\n */\n\n/** Recovers the parsed input type of a spec node, for typing its handler. */\nexport type Input<Value> =\n\tValue extends Spec.Node<infer _Name, infer Spec, infer _Commands>\n\t\t? Input<Spec>\n\t\t: Value extends Command.Command<infer _Name, infer Parsed, infer _Context, infer _Error, infer _Requirements>\n\t\t\t? Parsed\n\t\t\t: never;\n\n/**\n * A handler may yield an ancestor's spec to read its shared flags, which shows up\n * as a `CommandContext` requirement; `withSubcommands` discharges it when the tree\n * is assembled.\n */\ntype Requirements = Command.Environment | Command.CommandContext<string>;\ntype Run<Parsed> = (input: Parsed) => Effect.Effect<void, CommandError, Requirements>;\ntype Loader<Node extends Spec.Any> = () => Promise<{ readonly default: Run<Input<Node>> }>;\n\n/**\n * The handler registry for a spec tree: a loader per leaf, mirroring the shape of\n * the tree. A parent with children takes its own handler under `$`.\n */\nexport type Handlers<Node extends Spec.Any> = keyof Node[\"commands\"] extends never\n\t? Loader<Node>\n\t: { readonly $?: Loader<Node> } & { readonly [Key in keyof Node[\"commands\"]]: Handlers<Node[\"commands\"][Key]> };\n\ninterface LazyHandler {\n\treadonly spec: Command.Command.Any;\n\t// biome-ignore lint/suspicious/noExplicitAny: input is recovered per-command by `Input`\n\treadonly load: () => Promise<{ readonly default: Run<any> }>;\n}\n\ntype LazyHandlers = LazyHandler[\"load\"] | { readonly [key: string]: LazyHandlers | undefined };\n\ntype ProvidedCommand = Command.Command<string, unknown, unknown, CommandError, Command.Environment>;\n\n/** Type-checks a handler against the spec node it implements. */\nexport function handler<const Node extends Spec.Any>(_node: Node, run: Run<Input<Node>>) {\n\treturn run;\n}\n\nexport function handlers<const Root extends Spec.Any>(\n\troot: Root,\n\thandlers: Handlers<Root>,\n): ReadonlyArray<LazyHandler> {\n\tconst result: LazyHandler[] = [];\n\n\tfunction add(node: Spec.Any, value: LazyHandlers) {\n\t\tif (typeof value === \"function\") {\n\t\t\tresult.push({ spec: node.spec, load: value });\n\t\t\treturn;\n\t\t}\n\t\tif (value.$ !== undefined) result.push({ spec: node.spec, load: value.$ as LazyHandler[\"load\"] });\n\t\tfor (const [name, child] of Object.entries(node.commands)) {\n\t\t\tconst nested = value[name];\n\t\t\tif (nested !== undefined) add(child, nested);\n\t\t}\n\t}\n\n\tadd(root, handlers as LazyHandlers);\n\treturn result;\n}\n\nexport function run(root: Spec.Any, handlers: ReadonlyArray<LazyHandler>, options: { readonly version: string }) {\n\treturn Command.run(provide(root, handlers, { version: options.version, path: [] }), options);\n}\n\nfunction provide(\n\tnode: Spec.Any,\n\thandlers: ReadonlyArray<LazyHandler>,\n\tcontext: { readonly version: string; readonly path: ReadonlyArray<string> },\n): ProvidedCommand {\n\tconst found = handlers.find((entry) => entry.spec === node.spec);\n\tconst command = context.path.length === 0 ? node.name : context.path.join(\" \");\n\tconst spec = found\n\t\t? node.spec.pipe(\n\t\t\t\tCommand.withHandler((input) =>\n\t\t\t\t\tEffect.promise(found.load).pipe(\n\t\t\t\t\t\tEffect.flatMap((module) => module.default(input)),\n\t\t\t\t\t\tEffect.provide(Otel.layer({ version: context.version, command })),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t: node.spec;\n\tconst children = Object.values(node.commands);\n\tif (children.length === 0) return spec as ProvidedCommand;\n\treturn spec.pipe(\n\t\tCommand.withSubcommands(\n\t\t\tchildren.map((child) => provide(child, handlers, { ...context, path: [...context.path, child.name] })),\n\t\t),\n\t) as ProvidedCommand;\n}\n\nexport * as Runtime from \"./runtime.ts\";\n"],"mappings":";;;;;;;AAkDA,SAAgB,KAKd,MAAY,UAA6C,CAAC,GAAG;CAC9D,IAAI,OAAO,QAAQ,KAAK,MAAM,QAAQ,UAAW,CAAC,CAAY,CAAC,CAAC,KAC/D,QAAQ,gBAAgB,QAAQ,UAAW,CAAC,CAAY,CACzD;CACA,IAAI,QAAQ,gBAAgB,KAAA,GAAW,OAAO,KAAK,KAAK,QAAQ,gBAAgB,QAAQ,WAAW,CAAC;CACpG,IAAI,QAAQ,aAAa,KAAA,GAAW,OAAO,KAAK,KAAK,QAAQ,aAAa,QAAQ,QAAQ,CAAC;CAC3F,OAAO;EACN;EACA;EACA,UAAU,OAAO,aACf,QAAQ,YAAY,CAAC,EAAA,CAAG,KAAK,YAAY,CAAC,QAAQ,MAAM,OAAO,CAAC,CAClE;CACD;AACD;;;;;;;AC1DA,MAAa,iBAAiB,OAAO,OAAO,MAAM,iBAAiB;;;;;AAMnE,MAAM,aAAa;CAClB,aAAa,KAAK,QAAQ,cAAc,CAAC,CAAC,KACzC,KAAK,gBAAgB,wBAAwB,GAC7C,KAAK,YAAY,KAAK,CACvB;CACA,eAAe,KAAK,QAAQ,gBAAgB,CAAC,CAAC,KAC7C,KAAK,gBAAgB,wCAAwC,GAC7D,KAAK,YAAY,KAAK,CACvB;CACA,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,KAAK,OAAO,QAAQ,KAAK,KAAK,GAAG;CAC7E,MAAM,OAAO,QACV,KAAK,KAAK,KACV,QAAQ,aAAa,UACpB,OAAO,QAAQ,MAAM,IAAI,CAAC,CAAC,KAC1B,OAAO,SAAS,WAAW,OAAO,QAAQ,KAAK,CAAC,GAChD,OAAO,QAAQC,MAAW;EAAE,SAAS,QAAQ;EAAS;CAAQ,CAAC,CAAC,CACjE,CACD,CACD,IACC,KAAK;CACR,MAAM,WAAW,OAAO,OAAO,KAAK,QAAQ;CAC5C,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,OAAO,KAAK,KACX,QAAQ,gBACP,SAAS,KAAK,UAAU,QAAQ,OAAO,UAAU;EAAE,GAAG;EAAS,MAAM,CAAC,GAAG,QAAQ,MAAM,MAAM,IAAI;CAAE,CAAC,CAAC,CACtG,CACD;AACD"}
|
package/serve-BntJRQed.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serve-BntJRQed.mjs","names":["Service","fail","Contract.HostError","make","layer","Service","make","Envelope.Core","Envelope.encode","layer","Service","Contract.HostError","layer","layer","Contract.OAuthError","MessagePart.decode","Envelope.encode","layer","EventFeed.Service","OAuth.Service","Identity.Service","Host.Service","Clones.Service","Rows.follow","Envelope.ofThread","Rows.watch","Identity.Service","Contract.path","Registration.register","Contract.Api","EventFeed.layer","OAuth.layer","Host.layer","Clones.layer","Identity.layer","Runtime.handler","Server.layer","Registration.log"],"sources":["../../src/server/clones.ts","../../src/server/feed.ts","../../src/server/host.ts","../../src/server/oauth.ts","../../src/server/rows.ts","../../src/server/handlers.ts","../../src/server/server.ts","../../src/cli/cmd/handlers/serve.ts"],"sourcesContent":["/**\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 { 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\nexport * as Clones from \"./clones.ts\";\n","import { Event, EventRegistry, EventSchema } from \"@codeworksh/harness/effect\";\nimport { Cause, Context, Effect, Layer, Queue, Scope, Stream } from \"effect\";\nimport { EncodingError, type EventEnvelope, Envelope } from \"./envelope.ts\";\n\nexport const SubscriberCapacity = 4096;\n\nexport type Error = Event.SubscriptionOverflowError | EncodingError;\n\nexport interface Interface {\n\t/** A live envelope stream for one client; releasing the scope unregisters it. */\n\treadonly subscribe: Effect.Effect<Stream.Stream<EventEnvelope, Error>, never, Scope.Scope>;\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 Set<Queue.Queue<EventEnvelope, Error>>();\n\n\tconst failAll = (error: Error) =>\n\t\tEffect.sync(() => {\n\t\t\tconst current = Array.from(subscribers);\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 of subscribers) {\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 unsubscribe = yield* listen(publish);\n\tyield* Effect.addFinalizer(() => unsubscribe);\n\n\treturn Service.of({\n\t\tsubscribe: Effect.acquireRelease(\n\t\t\tQueue.dropping<EventEnvelope, Error>(capacity).pipe(\n\t\t\t\tEffect.tap((queue) => Effect.sync(() => subscribers.add(queue))),\n\t\t\t),\n\t\t\t(queue) => Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue))),\n\t\t).pipe(Effect.map(Stream.fromQueue)),\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\nexport * as EventFeed from \"./feed.ts\";\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 { 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<{ readonly path: string; readonly entries: ReadonlyArray<Contract.Folder> }, Contract.HostError>;\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}\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) => new Contract.HostError({ message });\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. */\nexport const 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. */\nexport const 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\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 entries = 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.catchIf(\n\t\t\t\t(code) => code === \"EACCES\" || code === \"EPERM\",\n\t\t\t\t() => Effect.succeed([]),\n\t\t\t),\n\t\t\tEffect.mapError((code) =>\n\t\t\t\tfail(\n\t\t\t\t\tcode === \"ENOENT\"\n\t\t\t\t\t\t? `${directory} does not exist.`\n\t\t\t\t\t\t: code === \"ENOTDIR\"\n\t\t\t\t\t\t\t? `${directory} is not a directory.`\n\t\t\t\t\t\t\t: `Could not read ${directory}.`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t\treturn {\n\t\t\tpath: directory,\n\t\t\tentries: 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.`);\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\treturn Service.of({ info, browse, add, create, status, lookup });\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\nexport * as Host from \"./host.ts\";\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 { 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 */\nexport const codexInfo = summarizeOpenAICodex;\nexport const 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\nexport * as OAuth from \"./oauth.ts\";\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\nexport * as Rows from \"./rows.ts\";\n","import { Model } from \"@codeworksh/aikit\";\nimport {\n\tControl,\n\tEvent,\n\tEventList,\n\tEventRegistry,\n\tEventSchema,\n\tMcp,\n\tModelCatalog,\n\tProject,\n\tPromptSchema,\n\tSandbox,\n\tSession,\n\tSessionStore,\n\tSettings,\n\tState,\n\tStore,\n\tSync,\n\tThreadSchema,\n\tThreadStore,\n} from \"@codeworksh/harness/effect\";\nimport { DateTime, Effect, Option, Predicate, Schema, Stream } from \"effect\";\nimport {\n\tContract,\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} from \"./contract.ts\";\nimport { type EncodingError, Envelope, type EventEnvelope } from \"./envelope.ts\";\nimport { Clones } from \"./clones.ts\";\nimport { EventFeed } from \"./feed.ts\";\nimport { Host } from \"./host.ts\";\nimport { Identity } from \"./identity.ts\";\nimport { OAuth } from \"./oauth.ts\";\nimport { MessagePart } from \"./part.ts\";\nimport { Rows } from \"./rows.ts\";\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\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\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/** 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 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 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\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\treturn { pid: identity.pid, version: identity.version, storeId: head.id, rev: head.rev };\n\t\t\t}),\n\t\t\t\"index.sync\": ({ after }) =>\n\t\t\t\tRows.follow(\n\t\t\t\t\tafter,\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\t(head): IndexItem => ({ _tag: \"Synced\", storeId: head.id, rev: head.rev }),\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 { model } = loaded;\n\t\t\t\tconst providers = yield* ModelCatalog.available(filter);\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 = (yield* ModelCatalog.effective(loaded.models))[model.provider]?.[model.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\tdefault: {\n\t\t\t\t\t\tprovider: model.provider,\n\t\t\t\t\t\tid: model.id,\n\t\t\t\t\t\tthinkingLevel: model.thinkingLevel,\n\t\t\t\t\t\t...(entry === undefined ? {} : { name: entry.name, providerName: entry.provider.name }),\n\t\t\t\t\t},\n\t\t\t\t};\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\"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\"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 }) =>\n\t\t\t\tStream.unwrap(\n\t\t\t\t\tfeed.subscribe.pipe(\n\t\t\t\t\t\tEffect.map((events) =>\n\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\tStream.concat(\n\t\t\t\t\t\t\t\t\tthreadId === undefined ? events : events.pipe(Stream.filter(Envelope.ofThread(threadId))),\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});\n\t}),\n);\n\nexport * as Handlers from \"./handlers.ts\";\n","import { Control, Global, Harness, Sandbox } from \"@codeworksh/harness/effect\";\nimport { NodeHttpServer } from \"@effect/platform-node\";\nimport { Effect, Layer } from \"effect\";\nimport { HttpRouter, HttpServer } from \"effect/http\";\nimport * as NetAddress from \"effect/net/NetAddress\";\nimport { RpcSerialization, RpcServer } from \"effect/rpc\";\n/* @effect-diagnostics nodeBuiltinImport:off -- the RPC listener needs a raw node server. */\nimport { createServer } from \"node:http\";\nimport { Clones } from \"./clones.ts\";\nimport { Contract } from \"./contract.ts\";\nimport { EventFeed } from \"./feed.ts\";\nimport { Handlers } from \"./handlers.ts\";\nimport { Host } from \"./host.ts\";\nimport { Identity } from \"./identity.ts\";\nimport { OAuth } from \"./oauth.ts\";\nimport { 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 * Resumes the runs the last server left unfinished, whether it crashed or shut down: the session\n * table records them as they start, so this needs nothing from the 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: logs the endpoint and files\n * the registration later invocations discover it through.\n */\nconst announce = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\tconst server = yield* HttpServer.HttpServer;\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\tyield* Effect.log(`codework serve listening on ${url}`);\n\t\tif (!NetAddress.isInetAddress(address)) return Layer.empty;\n\t\treturn Registration.register({\n\t\t\thome: global.home,\n\t\t\tinfo: { pid: identity.pid, version: identity.version, url, port: address.port },\n\t\t});\n\t}),\n);\n\nexport const layer = (options: { host: string; port: number; harness: Harness.Options }) => {\n\tconst rpc = RpcServer.layerHttp({ group: Contract.Api, path: Contract.path, protocol: \"websocket\" }).pipe(\n\t\tLayer.provide(Handlers.layer.pipe(Layer.provide(EventFeed.layer))),\n\t);\n\tconst app = HttpRouter.serve(rpc, { disableListenLog: true }).pipe(\n\t\tLayer.provideMerge(managedShutdown),\n\t\tLayer.provideMerge(resumeUnfinished),\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);\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(Identity.layer),\n\t\t// Built after the harness and before everything above it, the listener included.\n\t\tLayer.provide(sweep),\n\t\tLayer.provide(Harness.layer(options.harness)),\n\t);\n};\n\nexport * as Server from \"./server.ts\";\n","import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, FileSystem, Layer, Logger } from \"effect\";\nimport { Runtime } from \"../../../framework/runtime.ts\";\nimport { Registration } from \"../../../server/registration.ts\";\nimport { Server } from \"../../../server/server.ts\";\nimport { 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\nexport default Runtime.handler(\n\tCmd.commands.serve,\n\tEffect.fn(\"CLI.serve\", { level: \"Info\" })(function* ({ host, port, service }) {\n\t\tconst shared = yield* Cmd.spec;\n\t\tconst harness = { ...harnessOptions(shared), watchModels: true };\n\t\tconst serve = Layer.launch(Server.layer({ host, port, harness }));\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":";;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAaA,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,KAA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AAC,WAAW,EAAE,MAAM,MAAM,WAAW;CAC7E,MAAM,SAAS,OAAO,IAAI;CAC1B,MAAM,UAAU;EAAE,GAAG,eAAe,MAAM;EAAG,aAAa;CAAK;CAC/D,MAAM,QAAQ,MAAM,OAAOC,MAAa;EAAE;EAAM;EAAM;CAAQ,CAAC,CAAC;CAChE,IAAI,CAAC,SAAS,OAAO,OAAO,MAAM,KAAK,OAAO,MAAM,MAAM,CAAC;CAc3D,OAVmB,OAAO,IAAI,aAAa;EAC1C,MAAM,QAAQ,OAAO,OAAO,QAAQ,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK,CAAC;EAE5F,QAAO,OADW,WAAW,WAAA,CACnB,cAAc,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;EACtD,MAAM,SAAS,OAAO,aAAa,KAAK,OAAO,OAAOC,IAAiB,MAAM,GAAG,GAAG,EAAE,MAAM,IAAI,CAAC,CAAC;EACjG,OAAO,MAAM,KACZ,OAAO,OAAO,UAAU,OAAO,SAAS,YAAY,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,MAAM,CAAC,CAAC,GAC/F,OAAO,QAAQ,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CACtC;CACD,CACgB,CAAC,CAAC,KAAK,OAAO,MAAM,MAAM,CAAC;AAC5C,CAAC,CACF"}
|
package/service-CjOS-xCw.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service-CjOS-xCw.mjs","names":["Client.layer","Client.make","Registration.infoJson","Health.probe","Registration.file","log","Registration.log","Registration.command"],"sources":["../../src/server/health.ts","../../src/server/discovery.ts","../../src/cli/service.ts"],"sourcesContent":["import { Effect, Layer } from \"effect\";\nimport { Client } from \"./client.ts\";\n\n/**\n * One `server.info` call, with the answer normalized to `undefined` for every\n * way a server can fail to answer: unreachable, slow, or speaking a different\n * protocol. A health check that throws where it should say \"no\" would make\n * every caller wrap it in a catch.\n */\nexport const probe = (url: string) =>\n\tEffect.gen(function* () {\n\t\tconst context = yield* Layer.build(Client.layer(url)).pipe(Effect.orElseSucceed(() => undefined));\n\t\tif (context === undefined) return undefined;\n\t\treturn yield* Effect.gen(function* () {\n\t\t\tconst rpc = yield* Client.make;\n\t\t\treturn yield* rpc[\"server.info\"]({}).pipe(Effect.timeout(\"1 second\"));\n\t\t}).pipe(\n\t\t\tEffect.provideContext(context),\n\t\t\tEffect.orElseSucceed(() => undefined),\n\t\t);\n\t}).pipe(Effect.scoped);\n\nexport * as Health from \"./health.ts\";\n","import { type Duration, Effect, FileSystem, Option, Schedule, Schema } from \"effect\";\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\";\nimport { Health } from \"./health.ts\";\nimport { Identity } from \"./identity.ts\";\nimport { Registration } from \"./registration.ts\";\n\n/** A server a client can connect to, and the process and port behind it. */\nexport interface Endpoint {\n\treadonly url: string;\n\treadonly pid: number;\n\treadonly port: number;\n}\n\n/** A managed server could not be produced, in the words the CLI prints. */\nexport class ServerStartError extends Schema.TaggedError<ServerStartError>()(\"Discovery.ServerStartError\", {\n\tmessage: Schema.String,\n}) {}\n\nexport interface Options {\n\t/** The CodeWork home whose `service.json` names the server. */\n\treadonly home: string;\n\t/** The home's log directory, where a background server writes `server.log`. */\n\treadonly log: string;\n\treadonly host: string;\n\treadonly port: number;\n\t/** Server-owned flags placed before `serve`. */\n\treadonly args: ReadonlyArray<string>;\n}\n\nconst START_TIMEOUT = \"20 seconds\";\nconst RACE_GRACE = \"2 seconds\";\nconst STOP_TIMEOUT = \"5 seconds\";\n\nconst decode = Schema.decodeUnknownEffect(Registration.infoJson);\n\nconst read = (path: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst text = yield* fs.readFileString(path).pipe(Effect.option);\n\t\tif (Option.isNone(text)) return undefined;\n\t\treturn yield* decode(text.value).pipe(Effect.option, Effect.map(Option.getOrUndefined));\n\t});\n\nconst remove = (path: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tyield* fs.remove(path);\n\t}).pipe(Effect.ignore);\n\n/** Whether `pid` is a running process. EPERM means it exists but belongs to someone else. */\nconst alive = (pid: number) =>\n\tEffect.try({ try: () => process.kill(pid, 0), catch: (error) => (error as NodeJS.ErrnoException).code }).pipe(\n\t\tEffect.as(true),\n\t\tEffect.catch((code) => Effect.succeed(code === \"EPERM\")),\n\t);\n\n/** Whether `pid` exits within `timeout`. */\nconst exits = (pid: number, timeout: typeof STOP_TIMEOUT) =>\n\talive(pid).pipe(\n\t\tEffect.repeat({ while: (running) => running, schedule: Schedule.spaced(\"50 millis\") }),\n\t\tEffect.timeoutOption(timeout),\n\t\tEffect.map(Option.isSome),\n\t);\n\n/**\n * The registered server, with `live` set when the process answering its endpoint\n * is the one that registered. The file is a hint, never proof: a different server\n * on a reused port must not pass for it.\n */\nconst registered = (path: string) =>\n\tEffect.gen(function* () {\n\t\tconst info = yield* read(path);\n\t\tif (info === undefined) return undefined;\n\t\tconst live = yield* Health.probe(info.url);\n\t\treturn { info, live: live?.pid === info.pid ? live : undefined };\n\t});\n\nconst endpoint = (info: Registration.Info): Endpoint => ({ url: info.url, pid: info.pid, port: info.port });\n\n/** The running server registered for `home`, with the build it reports. */\nexport const discover = (home: string) =>\n\tregistered(Registration.file(home)).pipe(\n\t\tEffect.map((found) =>\n\t\t\tfound?.live === undefined ? undefined : { ...endpoint(found.info), version: found.live.version },\n\t\t),\n\t);\n\n/**\n * Stop the server registered for `home`, returning it, or undefined when none\n * answers. Only a server that confirms it is the registrant is signalled: a pid\n * on file may since have been reused by an unrelated process.\n */\nexport const stop = (home: string) =>\n\tEffect.gen(function* () {\n\t\tconst path = Registration.file(home);\n\t\tconst found = yield* registered(path);\n\t\tif (found === undefined) return undefined;\n\t\tif (found.live === undefined) {\n\t\t\tif (!(yield* alive(found.info.pid))) yield* remove(path);\n\t\t\treturn undefined;\n\t\t}\n\t\tyield* terminate(path, found.info.pid);\n\t\treturn endpoint(found.info);\n\t});\n\n/**\n * Ensure a healthy local server for `home`: reuse the registered one, replace it\n * when `replace` is set and it runs a different build, or start a background one.\n *\n * The background server is detached and outlives this caller, so the next\n * invocation reuses it. When two callers race, only the contender that binds the\n * port registers; the loser exits and both adopt the winner, because a caller\n * only ever believes a registration it can confirm over the wire.\n */\nexport const ensure = (options: Options & { readonly replace: boolean }) =>\n\tEffect.gen(function* () {\n\t\tconst path = Registration.file(options.home);\n\t\tconst found = yield* registered(path);\n\t\tif (found?.live !== undefined) {\n\t\t\tif (!options.replace || found.live.version === Identity.current.version) return endpoint(found.info);\n\t\t\tyield* terminate(path, found.info.pid);\n\t\t} else {\n\t\t\t// A file nothing answers for, left by a crash, must not mislead the next caller.\n\t\t\tif (found !== undefined && !(yield* alive(found.info.pid))) yield* remove(path);\n\t\t}\n\t\treturn yield* start(path, options);\n\t});\n\n/** The registered server once it answers, polled every 200ms for up to `timeout`. */\nconst ready = (path: string, timeout: Duration.Input, pending: Effect.Effect<boolean>) =>\n\tEffect.gen(function* () {\n\t\tconst next = yield* registered(path);\n\t\tif (next?.live !== undefined) return Option.some(endpoint(next.info));\n\t\t// A live registrant that does not answer yet is another caller's server starting up.\n\t\tconst waiting = (yield* pending) || (next !== undefined && (yield* alive(next.info.pid)));\n\t\treturn waiting ? Option.none() : yield* Effect.fail(\"exited\" as const);\n\t}).pipe(\n\t\tEffect.repeat({ until: Option.isSome, schedule: Schedule.spaced(\"200 millis\") }),\n\t\tEffect.timeoutOption(timeout),\n\t\tEffect.map(Option.flatten),\n\t\tEffect.orElseSucceed(() => Option.none<Endpoint>()),\n\t);\n\n/**\n * Start a background server and wait for it to register, quoting the reason\n * from its log when it cannot.\n *\n * The contender stays tied to this scope until it is the server adopted: a\n * timeout, an interrupt, or another caller winning the race stops it rather than\n * leaving an unmanaged server behind.\n */\nconst start = (path: string, options: Options) =>\n\tEffect.gen(function* () {\n\t\tconst contender = yield* spawn(options);\n\t\tconst won = yield* ready(path, START_TIMEOUT, contender.isRunning.pipe(Effect.orElseSucceed(() => false)));\n\t\t// A contender that lost the bind race exits before the winner may have filed its\n\t\t// registration; give the winner a moment before calling the start a failure.\n\t\tconst server = Option.isSome(won) ? won : yield* ready(path, RACE_GRACE, Effect.succeed(true));\n\t\tif (Option.isSome(server)) {\n\t\t\tif (server.value.pid === contender.pid) yield* contender.unref.pipe(Effect.asVoid);\n\t\t\treturn server.value;\n\t\t}\n\n\t\tconst log = Registration.log(options.log);\n\t\tconst reason = yield* lastLine(log);\n\t\treturn yield* new ServerStartError({\n\t\t\tmessage: [\n\t\t\t\t`could not start a CodeWork server on ${options.host}:${options.port}`,\n\t\t\t\t...(reason === undefined ? [] : [`reason: ${reason}`]),\n\t\t\t\t`log: ${log}`,\n\t\t\t\t\"hint: pass --port to use another port\",\n\t\t\t].join(\"\\n\"),\n\t\t});\n\t}).pipe(Effect.scoped);\n\n/** Ask `pid` to shut down, escalating to SIGKILL, and retire its registration. */\nconst terminate = (path: string, pid: number) =>\n\tEffect.gen(function* () {\n\t\tconst signal = (name: NodeJS.Signals) => Effect.try(() => process.kill(pid, name)).pipe(Effect.ignore);\n\t\tyield* signal(\"SIGTERM\");\n\t\tif (!(yield* exits(pid, STOP_TIMEOUT))) {\n\t\t\tyield* signal(\"SIGKILL\");\n\t\t\tyield* exits(pid, STOP_TIMEOUT);\n\t\t}\n\t\t// A server removes its own file on a clean exit; this covers the SIGKILL path.\n\t\tconst info = yield* read(path);\n\t\tif (info?.pid === pid) yield* remove(path);\n\t});\n\nconst lastLine = (path: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst text = yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => \"\"));\n\t\treturn text\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trim())\n\t\t\t.findLast((line) => line.length > 0);\n\t});\n\n/**\n * Spawn `codework serve --service` detached, inheriting this environment so it\n * resolves the same home, catalog and credentials. It writes its own log, so no\n * stdio is tied to this short-lived caller. It stays referenced, and so stopped\n * with the scope, until `start` adopts it.\n */\nconst spawn = (options: Options) =>\n\tEffect.gen(function* () {\n\t\tconst [file, ...base] = Registration.command();\n\t\tif (file === undefined) return yield* Effect.die(new Error(\"could not resolve the codework entrypoint\"));\n\t\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n\t\tconst handle = yield* spawner.spawn(\n\t\t\tChildProcess.make(\n\t\t\t\tfile,\n\t\t\t\t[...base, ...options.args, \"serve\", \"--service\", \"--host\", options.host, \"--port\", String(options.port)],\n\t\t\t\t{ detached: true, stdin: \"ignore\", stdout: \"ignore\", stderr: \"ignore\" },\n\t\t\t),\n\t\t);\n\t\treturn handle;\n\t});\n\nexport * as Discovery from \"./discovery.ts\";\n","import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, Option } from \"effect\";\nimport type { Discovery } from \"../server/discovery.ts\";\n\ninterface Shared {\n\treadonly userConfigDir: Option.Option<string>;\n\treadonly home: Option.Option<string>;\n\treadonly database: Option.Option<string>;\n}\n\n/** The CodeWork home the shared flags name, resolved the way the harness resolves it. */\nexport const home = (shared: Shared) => Global.resolve(Option.isSome(shared.home) ? { home: shared.home.value } : {});\n\n/**\n * How `service` finds or starts the background server: the home whose\n * `service.json` names it, and the server-owned flags it is started with, in the\n * order `serve` parses them.\n */\nexport const options = (shared: Shared, server: { readonly host: string; readonly port: number }) =>\n\thome(shared).pipe(\n\t\tEffect.map((paths): Discovery.Options => ({\n\t\t\thome: paths.home,\n\t\t\tlog: paths.log,\n\t\t\t...server,\n\t\t\targs: [\n\t\t\t\t...(Option.isSome(shared.home) ? [\"--home\", shared.home.value] : []),\n\t\t\t\t...(Option.isSome(shared.database) ? [\"--database\", shared.database.value] : []),\n\t\t\t\t...(Option.isSome(shared.userConfigDir) ? [\"--user-config-dir\", shared.userConfigDir.value] : []),\n\t\t\t],\n\t\t})),\n\t);\n\nexport *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C,CAAC;CASvG,OAAO,QAPe,OADC,oBAAoB,oBAAA,CACb,MAC7B,aAAa,KACZ,MACA;EAAC,GAAG;EAAM,GAAG,QAAQ;EAAM;EAAS;EAAa;EAAU,QAAQ;EAAM;EAAU,OAAO,QAAQ,IAAI;CAAC,GACvG;EAAE,UAAU;EAAM,OAAO;EAAU,QAAQ;EAAU,QAAQ;CAAS,CACvE,CACD;AAED,CAAC;;;;AC/MF,MAAa,QAAQ,WAAmB,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI,IAAI,EAAE,MAAM,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC;;;;;;AAOpH,MAAa,WAAW,QAAgB,WACvC,KAAK,MAAM,CAAC,CAAC,KACZ,OAAO,KAAK,WAA8B;CACzC,MAAM,MAAM;CACZ,KAAK,MAAM;CACX,GAAG;CACH,MAAM;EACL,GAAI,OAAO,OAAO,OAAO,IAAI,IAAI,CAAC,UAAU,OAAO,KAAK,KAAK,IAAI,CAAC;EAClE,GAAI,OAAO,OAAO,OAAO,QAAQ,IAAI,CAAC,cAAc,OAAO,SAAS,KAAK,IAAI,CAAC;EAC9E,GAAI,OAAO,OAAO,OAAO,aAAa,IAAI,CAAC,qBAAqB,OAAO,cAAc,KAAK,IAAI,CAAC;CAChG;AACD,EAAE,CACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settings-DasbTMFs.mjs","names":["Jsonc.read","Jsonc.write","Jsonc.locked"],"sources":["../../src/cli/cmd/handlers/plugin/settings.ts"],"sourcesContent":["import { Global, Plugin, Settings } from \"@codeworksh/harness/effect\";\nimport { Effect, FileSystem, Option, Path } from \"effect\";\nimport { InvalidInputError } from \"../../../error.ts\";\nimport { Jsonc } from \"../../../jsonc.ts\";\n\n/**\n * Reading and rewriting the `plugins` array of one settings file, through {@link Jsonc}: a plugin\n * added by the CLI must not reformat a file its owner maintains.\n */\n\nexport interface Shared {\n\treadonly userConfigDir: Option.Option<string>;\n\treadonly home: Option.Option<string>;\n}\n\n/**\n * The user layer a command reads and writes: `--user-config-dir` when given -- a hard override of\n * the home's settings file -- resolved, like every app-level flag, against the directory the\n * command runs in (`hostCwd`), never against a linked session's `hostDir`.\n */\nexport const userLayer = (shared: Shared, hostCwd: string) =>\n\tOption.isNone(shared.userConfigDir)\n\t\t? {}\n\t\t: { userConfigDir: Settings.userConfigDir(shared.userConfigDir.value, hostCwd) };\n\nexport interface Target {\n\treadonly path: string;\n\t/** Set when this command had to create the project directory, so the caller can say so. */\n\treadonly created?: string;\n\t/** The project this file belongs to, which a local entry is written relative to. */\n\treadonly root?: string;\n}\n\n/** The module an entry names: a bare loader string, or the `package` of a config object. */\nconst moduleOf = (entry: unknown): string | undefined => {\n\tif (typeof entry === \"string\") return entry;\n\tif (typeof entry !== \"object\" || entry === null) return undefined;\n\tconst { package: located } = entry as { package?: unknown };\n\treturn typeof located === \"string\" ? located : undefined;\n};\n\n/** The plugin ID an entry configures, if it names one. */\nconst idOf = (entry: unknown): string | undefined => {\n\tif (typeof entry !== \"object\" || entry === null) return undefined;\n\tconst { plugin } = entry as { plugin?: unknown };\n\treturn typeof plugin === \"string\" ? plugin : undefined;\n};\n\n/**\n * Every spelling a reference answers to, without touching the filesystem.\n *\n * `canonical` drops a version suffix and resolves a relative path against the file that declared\n * it, so `@acme/x@1.2.0` and `@acme/x` are one name. The literal string is kept alongside it\n * because a plugin ID is not a module reference and survives `canonical` unchanged.\n */\nconst aliases = (reference: string, directory: string): Effect.Effect<ReadonlyArray<string>> =>\n\tPlugin.canonical(reference, directory).pipe(\n\t\tEffect.map((canonical) => [reference, canonical] as ReadonlyArray<string>),\n\t\t// A reference that does not parse still answers to itself: a plugin ID is not a module\n\t\t// reference, and it has to keep matching an entry that names it.\n\t\tEffect.orElseSucceed(() => [reference] as ReadonlyArray<string>),\n\t);\n\n/** Every spelling `reference` answers to, computed once for a whole command. */\nexport const spellings = (reference: string, directory: string): Effect.Effect<ReadonlySet<string>> =>\n\tEffect.map(aliases(reference, directory), (found) => new Set(found));\n\nexport interface Entry {\n\treadonly value: unknown;\n\treadonly answers: ReadonlySet<string>;\n\treadonly loads: boolean;\n}\n\n/**\n * What each configured entry answers to.\n *\n * Comparing the string as written is not enough. `plugin add @acme/x@1.2.0` records a version the\n * user will not repeat when removing it, and one plugin can be named three ways: by package, by\n * path, or by the ID it declares -- a `{ \"plugin\": \"<id>\" }` configuration object sits next to the\n * module entry that loaded it, and removing the plugin has to take both.\n *\n * The declared ID is only knowable by importing the module, so it is read from what is already\n * installed: `resolveCached` reads a published package out of the harness cache and never runs an\n * installer, so editing a settings file cannot fetch anything. An entry that does not resolve --\n * uninstalled, moved, or broken -- keeps the names it was written with rather than failing the\n * command, because an unusable plugin is exactly the one a user is trying to remove.\n */\nexport const identify = Effect.fn(\"CLI.plugin.identify\")(function* (\n\tplugins: ReadonlyArray<unknown>,\n\tfile: string,\n\tcache: string,\n) {\n\tconst nodePath = yield* Path.Path;\n\tconst directory = nodePath.dirname(file);\n\tconst entries: Entry[] = [];\n\tfor (const value of plugins) {\n\t\tconst answers = new Set<string>();\n\t\tconst id = idOf(value);\n\t\tif (id !== undefined) answers.add(id);\n\t\tconst module = moduleOf(value);\n\t\tif (module !== undefined) {\n\t\t\tfor (const alias of yield* aliases(module, directory)) answers.add(alias);\n\t\t\tconst declared = yield* Plugin.inspect(module, {\n\t\t\t\tcache,\n\t\t\t\thostDir: directory,\n\t\t\t\tfile,\n\t\t\t\tinstall: Plugin.resolveCached,\n\t\t\t}).pipe(Effect.option);\n\t\t\tif (Option.isSome(declared)) {\n\t\t\t\tanswers.add(declared.value.id);\n\t\t\t\tif (declared.value.name !== undefined) answers.add(declared.value.name);\n\t\t\t}\n\t\t}\n\t\tentries.push({ value, answers, loads: typeof value === \"string\" });\n\t}\n\treturn entries as ReadonlyArray<Entry>;\n});\n\n/**\n * What a local reference should be *written* as, which is rarely what was typed.\n *\n * A relative path on the command line is relative to the command's host directory; in a settings file it is relative to\n * that file's own directory. Those differ the moment the command runs anywhere but the directory\n * holding the file, and writing the string verbatim produces a silently wrong entry:\n *\n * ```\n * $ cd ~/workspace/app/packages/fubar\n * $ codework plugin add ./plugins/x.ts # means packages/fubar/plugins/x.ts\n * → the project is ~/workspace/app, so the entry lands in app/.codework/settings.jsonc\n * → written verbatim, the harness loads app/.codework/plugins/x.ts ← a different file\n * ```\n *\n * With both ends inside one project the entry is written relative to the file, which is portable\n * to any checkout of that repository and therefore worth committing. Otherwise -- a `-g` write\n * into `<home>`, a `--user-config-dir` elsewhere, or a target outside the project -- relative\n * would be a lie, and an absolute path means the same thing read from anywhere.\n *\n * A package spec is returned untouched: it names no location.\n */\nexport const written = Effect.fn(\"CLI.plugin.written\")(function* (\n\treference: string,\n\tinput: { readonly hostDir: string; readonly file: string; readonly root: string | undefined },\n) {\n\tconst nodePath = yield* Path.Path;\n\tconst target = yield* Plugin.parse(reference, input.hostDir).pipe(Effect.option);\n\tif (Option.isNone(target) || target.value.kind !== \"local\") return reference;\n\n\tconst absolute = target.value.path;\n\tconst inside = (root: string, path: string) => path === root || path.startsWith(`${root}${nodePath.sep}`);\n\tif (input.root !== undefined && inside(input.root, input.file) && inside(input.root, absolute)) {\n\t\tconst relative = nodePath.relative(nodePath.dirname(input.file), absolute);\n\t\treturn relative.startsWith(\"..\") ? relative : `./${relative}`;\n\t}\n\treturn absolute;\n});\n\n/** `reference` selects `entry` when any spelling of one is a spelling of the other. */\nexport const matches = (entry: Entry, spelled: ReadonlySet<string>) =>\n\t[...spelled].some((alias) => entry.answers.has(alias));\n\n/** Every entry connected to a reference through a package spelling or declared plugin ID. */\nexport const matching = (entries: ReadonlyArray<Entry>, spelled: ReadonlySet<string>) => {\n\tconst answers = new Set(spelled);\n\tconst found = new Set<Entry>();\n\tfor (;;) {\n\t\tconst next = entries.filter(\n\t\t\t(entry) => !found.has(entry) && [...entry.answers].some((answer) => answers.has(answer)),\n\t\t);\n\t\tif (next.length === 0) return found as ReadonlySet<Entry>;\n\t\tfor (const entry of next) {\n\t\t\tfound.add(entry);\n\t\t\tfor (const answer of entry.answers) answers.add(answer);\n\t\t}\n\t}\n};\n\nexport const readPlugins = Effect.fn(\"CLI.plugin.readPlugins\")(function* (path: string) {\n\tconst { source, document } = yield* Jsonc.read(path, \"settings file\");\n\tconst plugins = document.plugins;\n\tif (plugins !== undefined && !Array.isArray(plugins)) {\n\t\treturn yield* new InvalidInputError({ message: `${path}: \"plugins\" must be an array` });\n\t}\n\treturn { source, plugins: (plugins ?? []) as ReadonlyArray<unknown> };\n});\n\nexport const writePlugins = (path: string, source: string, plugins: ReadonlyArray<unknown>) =>\n\tJsonc.write(path, source, [\"plugins\"], plugins);\n\n/**\n * Serialize one settings read-modify-rename across CLI processes. The install or inspection that\n * precedes an edit stays outside it, so unrelated downloads do not wait behind one another.\n */\nexport const withPluginsLock = Jsonc.locked;\n\n/**\n * Which file the edit lands in.\n *\n * A plugin belongs to a project by default — it is part of how that repository is worked on, so\n * the entry belongs in a file the repository can commit. `--global` writes the user settings file\n * instead, the way `npm -g` installs outside a package: `<--home>/settings.jsonc`, or the\n * `--user-config-dir` one that replaces it.\n *\n * The project is found the way the harness finds it: the nearest ancestor holding a `.codework`\n * directory, so a command run from `packages/app` edits the repository's own file rather than\n * creating a second one beside it. When no ancestor has one, the project begins here -- the\n * directory is created and the caller is told, because that decision changes where every future\n * plugin entry lands, and a mistyped `cd` is the way it goes wrong.\n *\n * There is nothing to warn about between layers: plugin entries from every layer accumulate, so a\n * user-wide entry still applies inside a project that declares its own.\n */\nexport const resolveTarget = Effect.fn(\"CLI.plugin.resolveTarget\")(function* (\n\tshared: Shared,\n\tglobal: boolean,\n\t/**\n\t * Where to discover the project from, when it is not the shell's directory.\n\t *\n\t * A session's host directory is the only other honest answer: it is a declared host path. The\n\t * session's *space* is not, and neither is its project -- a `Project` is env-independent by\n\t * design, so it has no host directory to offer.\n\t */\n\tfrom?: string,\n\t/** Only `plugin add` may establish a project marker when no project exists yet. */\n\tcreate = true,\n) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst nodePath = yield* Path.Path;\n\tconst hostCwd = nodePath.resolve(\".\");\n\t// The linked session's host directory, or -- with none -- the one the command runs in.\n\tconst hostDir = from ?? hostCwd;\n\tconst home = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\tconst root = global ? undefined : yield* Settings.projectRoot(hostDir, home.home);\n\t// `paths` is ordered lowest priority first: the user layer, then the project.\n\tconst groups = Settings.paths({\n\t\thome: home.home,\n\t\t...(root === undefined ? {} : { root }),\n\t\t...userLayer(shared, hostCwd),\n\t});\n\tconst chosen = global ? 0 : 1;\n\t// An empty group is the project layer saying there is no project above this directory. Then\n\t// this directory becomes one -- reported, not silent, because the marker shadows any outer\n\t// project from now on, so a `.codework/` created by a mistyped `cd` is worth spotting at once.\n\tconst found = groups[chosen] ?? [];\n\tif (found.length > 0) {\n\t\tconst existing = yield* Effect.findFirst(found, (candidate) => fs.exists(candidate));\n\t\treturn {\n\t\t\tpath: Option.getOrElse(existing, () => found[0]!),\n\t\t\t...(root === undefined ? {} : { root }),\n\t\t} satisfies Target;\n\t}\n\tconst marker = nodePath.join(hostDir, \".codework\");\n\t// `created` is reported either way: with `create` unset the marker is named, not made, so a\n\t// caller can say what its write is about to establish without establishing it early.\n\tif (!create)\n\t\treturn { path: nodePath.join(marker, \"settings.jsonc\"), created: marker, root: hostDir } satisfies Target;\n\tyield* fs.makeDirectory(marker, { recursive: true });\n\treturn { path: nodePath.join(marker, \"settings.jsonc\"), created: marker, root: hostDir } satisfies Target;\n});\n"],"mappings":";;;;;;;;;;AAoBA,MAAa,aAAa,QAAgB,YACzC,OAAO,OAAO,OAAO,aAAa,IAC/B,CAAC,IACD,EAAE,eAAe,SAAS,cAAc,OAAO,cAAc,OAAO,OAAO,EAAE;;AAWjF,MAAM,YAAY,UAAuC;CACxD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,KAAA;CAC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AAM,EAAG;GAChD,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;EACtC;CACD;CACA,MAAM,SAAS,SAAS,KAAK,SAAS,WAAW;CAGjD,IAAI,CAAC,QACJ,OAAO;EAAE,MAAM,SAAS,KAAK,QAAQ,gBAAgB;EAAG,SAAS;EAAQ,MAAM;CAAQ;CACxF,OAAO,GAAG,cAAc,QAAQ,EAAE,WAAW,KAAK,CAAC;CACnD,OAAO;EAAE,MAAM,SAAS,KAAK,QAAQ,gBAAgB;EAAG,SAAS;EAAQ,MAAM;CAAQ;AACxF,CAAC"}
|
package/shared-CDyNsYBy.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared-CDyNsYBy.mjs","names":["Jsonc.read"],"sources":["../../src/cli/cmd/handlers/mcp/shared.ts"],"sourcesContent":["import { type EventList, Global, type Mcp, McpConfig, McpOAuth, Settings } from \"@codeworksh/harness/effect\";\nimport { Effect, Option, Path, Predicate } from \"effect\";\nimport { InvalidInputError } from \"../../../error.ts\";\nimport { Jsonc } from \"../../../jsonc.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\n/**\n * Where this directory's `mcp.json` files are: the user one in the home, or the `--user-config-dir`\n * that replaces it, and the project's under the nearest `.codework`, or this directory's when there\n * is none. Then what they configure.\n */\nexport const configured = Effect.fn(\"CLI.mcp.configured\")(function* () {\n\tconst shared = yield* Cmd.spec;\n\tconst path = yield* Path.Path;\n\tconst hostCwd = path.resolve(\".\");\n\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\tconst root = yield* Settings.projectRoot(hostCwd, paths.home);\n\tconst userDir = Option.isNone(shared.userConfigDir)\n\t\t? paths.home\n\t\t: Settings.userConfigDir(shared.userConfigDir.value, hostCwd);\n\tconst loaded = yield* McpConfig.load({ userDir, root });\n\treturn {\n\t\thome: paths.home,\n\t\tauthFile: Global.authFile(Option.isNone(shared.home) ? undefined : paths.home),\n\t\thostCwd,\n\t\troot,\n\t\tuser: path.join(userDir, \"mcp.json\"),\n\t\tproject: path.join(root ?? hostCwd, Global.appConfigDir, \"mcp.json\"),\n\t\t...loaded,\n\t};\n});\n\nexport const MARKS: Record<Mcp.State, string> = {\n\tconnected: \"✓\",\n\tauthenticate: \"⚠\",\n\tfailed: \"✗\",\n\tconnecting: \"○\",\n\tdisconnected: \"○\",\n\tdisabled: \"○\",\n};\n\nconst plural = (count: number, noun: string) => `${count} ${noun}${count === 1 ? \"\" : \"s\"}`;\n\n/** A server's state as the commands print it, with the tools its listing left out. */\nexport const describe = (state: Mcp.State, tools: number, skipped?: EventList.McpSkipped) => {\n\tif (state !== \"connected\") return state;\n\tconst connected = `connected, ${plural(tools, \"tool\")}`;\n\tif (skipped === undefined) return connected;\n\tconst left = [...skipped.names, ...(skipped.unnamed === 0 ? [] : [plural(skipped.unnamed, \"unnamed tool\")])];\n\treturn `${connected} — skipped ${left.join(\", \")}`;\n};\n\n/** The `mcpServers` of one `mcp.json`, and the text an edit rewrites. */\nexport const readServers = Effect.fn(\"CLI.mcp.readServers\")(function* (path: string) {\n\tconst { source, document } = yield* Jsonc.read(path, \"mcp.json\");\n\tconst servers = document.mcpServers ?? {};\n\tif (!Predicate.isObject(servers) || Array.isArray(servers))\n\t\treturn yield* new InvalidInputError({ message: `${path}: expected an object with an \"mcpServers\" object` });\n\treturn { source, servers: servers as Record<string, unknown> };\n});\n\n/**\n * The OAuth server `name` names in the `mcp.json` this directory reads, the user file and the\n * project's, and the credential store of the home. A server that sends a credential of its own\n * never signs in.\n */\nexport const oauthServer = Effect.fn(\"CLI.mcp.oauthServer\")(function* (name: string) {\n\tconst { home, servers, errors } = yield* configured();\n\tconst entry = servers.find((server) => server.name === name);\n\tif (entry === undefined) {\n\t\tconst problems = errors.length === 0 ? \"\" : `\\n${errors.join(\"\\n\")}`;\n\t\treturn yield* new InvalidInputError({ message: `no MCP server named \"${name}\" in mcp.json${problems}` });\n\t}\n\tconst config = entry.config;\n\tif (!(\"url\" in config))\n\t\treturn yield* new InvalidInputError({\n\t\t\tmessage: `MCP server \"${name}\" runs over stdio; only HTTP servers sign in`,\n\t\t});\n\tif (config.auth !== undefined)\n\t\treturn yield* new InvalidInputError({\n\t\t\tmessage: `MCP server \"${name}\" sends the credential of provider \"${config.auth.provider}\"; sign in to the provider with codework auth login`,\n\t\t});\n\tif (Object.keys(config.headers ?? {}).some((header) => header.toLowerCase() === \"authorization\"))\n\t\treturn yield* new InvalidInputError({\n\t\t\tmessage: `MCP server \"${name}\" sends its own Authorization header; remove it to sign in with OAuth`,\n\t\t});\n\treturn {\n\t\tstore: McpOAuth.store(home),\n\t\tserver: { name, url: config.url, oauth: config.oauth },\n\t\tconfig,\n\t};\n});\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,aAAa,OAAO,GAAG,oBAAoB,CAAC,CAAC,aAAa;CACtE,MAAM,SAAS,OAAO,IAAI;CAC1B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,UAAU,KAAK,QAAQ,GAAG;CAChC,MAAM,QAAQ,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,OAAO,KAAK,MAAM,CAAC;CACjG,MAAM,OAAO,OAAO,SAAS,YAAY,SAAS,MAAM,IAAI;CAC5D,MAAM,UAAU,OAAO,OAAO,OAAO,aAAa,IAC/C,MAAM,OACN,SAAS,cAAc,OAAO,cAAc,OAAO,OAAO;CAC7D,MAAM,SAAS,OAAO,UAAU,KAAK;EAAE;EAAS;CAAK,CAAC;CACtD,OAAO;EACN,MAAM,MAAM;EACZ,UAAU,OAAO,SAAS,OAAO,OAAO,OAAO,IAAI,IAAI,KAAA,IAAY,MAAM,IAAI;EAC7E;EACA;EACA,MAAM,KAAK,KAAK,SAAS,UAAU;EACnC,SAAS,KAAK,KAAK,QAAQ,SAAS,OAAO,cAAc,UAAU;EACnE,GAAG;CACJ;AACD,CAAC;AAED,MAAa,QAAmC;CAC/C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,SAAS,eAAe,KAAK,8CAC9B,CAAC;CACF,IAAI,OAAO,SAAS,KAAA,GACnB,OAAO,OAAO,IAAI,kBAAkB,EACnC,SAAS,eAAe,KAAK,sCAAsC,OAAO,KAAK,SAAS,qDACzF,CAAC;CACF,IAAI,OAAO,KAAK,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,WAAW,OAAO,YAAY,MAAM,eAAe,GAC9F,OAAO,OAAO,IAAI,kBAAkB,EACnC,SAAS,eAAe,KAAK,uEAC9B,CAAC;CACF,OAAO;EACN,OAAO,SAAS,MAAM,IAAI;EAC1B,QAAQ;GAAE;GAAM,KAAK,OAAO;GAAK,OAAO,OAAO;EAAM;EACrD;CACD;AACD,CAAC"}
|
package/shared-CiSbTY59.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared-CiSbTY59.mjs","names":["Client.layer"],"sources":["../../src/cli/cmd/handlers/auth/shared.ts"],"sourcesContent":["/* @effect-diagnostics nodeBuiltinImport:off -- OAuth login opens the system browser. */\n/* @effect-diagnostics globalDate:off -- Stored expiry timestamps are rendered for the user. */\n/* oxlint-disable effecttsgo/async-function -- Aikit OAuth callbacks require Promise-returning functions. */\nimport {\n\tGitHubCopilotOAuthClient,\n\tJsonGitHubCopilotAuthStorage,\n\ttype GitHubCopilotAuthStorage,\n} from \"@codeworksh/aikit/oauth/github/copilot\";\nimport {\n\tJsonOpenAICodexAuthStorage,\n\tOpenAICodexOAuthClient,\n\ttype OpenAICodexAuthStorage,\n} from \"@codeworksh/aikit/oauth/openai/codex\";\nimport { openBrowser, promptLine } from \"@codeworksh/aikit/oauth/interactive\";\nimport {\n\tcheckOAuthProvider,\n\toauthProviderLabel,\n\tsummarizeGitHubCopilot,\n\tsummarizeOpenAICodex,\n\ttype OAuthSummary,\n} from \"@codeworksh/aikit/oauth/summary\";\nimport { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, Option, Path } from \"effect\";\nimport { Client } from \"../../../../server/client.ts\";\nimport type { Contract } from \"../../../../server/contract.ts\";\nimport { InvalidInputError, OAuthError } from \"../../../error.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport type Provider = Contract.OAuthProvider;\n\n// The wire shape and aikit's summary are the same record.\nexport type Summary = Contract.OAuthInfo & OAuthSummary;\n\nconst announce = (\n\tinfo: { url: string; userCode?: string | undefined; instructions?: string | undefined },\n\tbrowser: boolean,\n): void => {\n\tprocess.stderr.write(\n\t\t`${info.instructions ?? \"Complete authentication in your browser.\"}\\n${\n\t\t\tinfo.userCode === undefined ? \"\" : `Enter code: ${info.userCode}\\n`\n\t\t}${info.url}\\n`,\n\t);\n\tif (browser) {\n\t\tvoid openBrowser(info.url, (error) => void process.stderr.write(`Failed to open browser: ${error.message}\\n`));\n\t}\n};\n\nexport interface LoginOptions {\n\treadonly browser: boolean;\n\treadonly device: boolean;\n\treadonly enterprise: Option.Option<string>;\n\treadonly enableModels: boolean;\n}\n\nexport interface Ops {\n\treadonly path: string;\n\treadonly login: (options: LoginOptions) => Promise<{ wire: Contract.OAuthCredentials; summary: Summary }>;\n\treadonly stored: () => Promise<Summary | undefined>;\n\treadonly refreshed: () => Promise<Summary | undefined>;\n\treadonly logout: () => Promise<void>;\n}\n\n/** Holds nothing: a server's credentials live on the server, not on this disk. */\nconst transient: OpenAICodexAuthStorage & GitHubCopilotAuthStorage = {\n\tget: async () => undefined,\n\tset: async () => {},\n\tclear: async () => {},\n};\n\nconst codexOps = (storage: OpenAICodexAuthStorage, path: string): Ops => {\n\tconst client = new OpenAICodexOAuthClient({ storage });\n\treturn {\n\t\tpath,\n\t\tlogin: async (options) => {\n\t\t\tconst credentials = await client.login({\n\t\t\t\tdevice: options.device,\n\t\t\t\tonAuth: (info) => announce(info, options.browser),\n\t\t\t\tonProgress: (message) => void process.stderr.write(`${message}\\n`),\n\t\t\t\tonPrompt: (prompt) => promptLine(prompt.message),\n\t\t\t});\n\t\t\treturn { wire: { provider: \"openai-codex\", ...credentials }, summary: summarizeOpenAICodex(credentials) };\n\t\t},\n\t\tstored: async () => {\n\t\t\tconst credentials = await storage.get();\n\t\t\treturn credentials && summarizeOpenAICodex(credentials);\n\t\t},\n\t\trefreshed: async () => {\n\t\t\tconst credentials = await client.getCredentials();\n\t\t\treturn credentials && summarizeOpenAICodex(credentials);\n\t\t},\n\t\tlogout: () => client.logout(),\n\t};\n};\n\nconst copilotOps = (storage: GitHubCopilotAuthStorage, path: string): Ops => {\n\tconst client = new GitHubCopilotOAuthClient({ storage });\n\tconst read = async () => {\n\t\tconst credentials = await storage.get();\n\t\treturn credentials && summarizeGitHubCopilot(credentials);\n\t};\n\treturn {\n\t\tpath,\n\t\tlogin: async (options) => {\n\t\t\tconst credentials = await client.login({\n\t\t\t\t...(Option.isSome(options.enterprise) && { enterpriseUrl: options.enterprise.value }),\n\t\t\t\tenableModels: options.enableModels,\n\t\t\t\tonAuth: (info) => announce(info, options.browser),\n\t\t\t\tonProgress: (message) => void process.stderr.write(`${message}\\n`),\n\t\t\t});\n\t\t\treturn { wire: { provider: \"github-copilot\", ...credentials }, summary: summarizeGitHubCopilot(credentials) };\n\t\t},\n\t\tstored: read,\n\t\t// GitHub OAuth tokens never expire, so there is nothing to refresh.\n\t\trefreshed: read,\n\t\tlogout: () => client.logout(),\n\t};\n};\n\nexport const makeOps = (provider: Provider, options: { path?: string | undefined; persist?: boolean } = {}): Ops => {\n\tconst file = options.path === undefined ? {} : { path: options.path };\n\tif (provider === \"openai-codex\") {\n\t\tconst storage = options.persist === false ? undefined : new JsonOpenAICodexAuthStorage(file);\n\t\treturn codexOps(storage ?? transient, storage?.path ?? \"\");\n\t}\n\tconst storage = options.persist === false ? undefined : new JsonGitHubCopilotAuthStorage(file);\n\treturn copilotOps(storage ?? transient, storage?.path ?? \"\");\n};\n\nexport const attempt = <A>(message: string, run: () => Promise<A>) =>\n\tEffect.tryPromise({ try: run, catch: (cause) => new OAuthError({ message, cause }) });\n\n/** The provider named by the two mutually exclusive flags. */\nexport const selectProvider = (flags: {\n\treadonly openaiCodex: boolean;\n\treadonly githubCopilot: boolean;\n}): Effect.Effect<Provider, InvalidInputError> => {\n\tconst checked = checkOAuthProvider(flags);\n\treturn checked.ok\n\t\t? Effect.succeed(checked.provider)\n\t\t: Effect.fail(new InvalidInputError({ message: checked.message }));\n};\n\n/** Reject the local-credential flags when the credentials live on a server. */\nexport const assertServerScope = (authFile: Option.Option<string>) =>\n\tEffect.gen(function* () {\n\t\tconst shared = yield* Cmd.spec;\n\t\tif (Option.isSome(authFile) || Option.isSome(shared.home)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--auth-file and --home belong on codework serve when using --server\",\n\t\t\t});\n\t\t}\n\t});\n\n/** Credential operations against this machine's auth.json. */\nexport const localOps = (provider: Provider, authFile: Option.Option<string>) =>\n\tEffect.gen(function* () {\n\t\tconst shared = yield* Cmd.spec;\n\t\tconst path = yield* Path.Path;\n\t\tconst file = Option.isSome(authFile)\n\t\t\t? authFile.value\n\t\t\t: Option.isSome(shared.home)\n\t\t\t\t? path.join((yield* Global.resolve({ home: shared.home.value })).home, \"aikit\", \"auth.json\")\n\t\t\t\t: undefined;\n\t\treturn makeOps(provider, file === undefined ? {} : { path: file });\n\t});\n\n/** Run an effect against the RPC server at `url`, discharging the client. */\nexport const withServer = <A, E, R>(url: string, program: Effect.Effect<A, E, R>) =>\n\tprogram.pipe(Effect.provide(Client.layer(url)), Effect.scoped);\n\nexport { Client, oauthProviderLabel };\n"],"mappings":";;;;;;;;;AAiCA,MAAM,YACL,MACA,YACU;CACV,QAAQ,OAAO,MACd,GAAG,KAAK,gBAAgB,2CAA2C,IAClE,KAAK,aAAa,KAAA,IAAY,KAAK,eAAe,KAAK,SAAS,MAC9D,KAAK,IAAI,GACb;CACA,IAAI,SACH,YAAiB,KAAK,MAAM,UAAU,KAAK,QAAQ,OAAO,MAAM,2BAA2B,MAAM,QAAQ,GAAG,CAAC;AAE/G;;AAkBA,MAAM,YAA+D;CACp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AAI,IACxB,KAAK,MAAM,OAAO,OAAO,QAAQ,EAAE,MAAM,OAAO,KAAK,MAAM,CAAC,EAAA,CAAG,MAAM,SAAS,WAAW,IACzF,KAAA;CACJ,OAAO,QAAQ,UAAU,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC;AAClE,CAAC;;AAGF,MAAa,cAAuB,KAAa,YAChD,QAAQ,KAAK,OAAO,QAAQA,MAAa,GAAG,CAAC,GAAG,OAAO,MAAM"}
|
package/start-CTYwK1Z4.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"start-CTYwK1Z4.mjs","names":["Runtime.handler","options","Service.options","Discovery.ensure"],"sources":["../../src/cli/cmd/handlers/service/start.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { Discovery } from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { 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"}
|