@codeworksh/cli 0.9.0-canary.158.1.gdff28d0d → 0.9.0-canary.160.1.g8b6596ff
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/README.md +53 -215
- package/{acp-D1X6PAQd.mjs → acp-DuWjGq3q.mjs} +2 -2
- package/{acp-D1X6PAQd.mjs.map → acp-DuWjGq3q.mjs.map} +1 -1
- package/{add-BO0TXkKX.mjs → add-Bf7S3xyS.mjs} +2 -2
- package/{add-BO0TXkKX.mjs.map → add-Bf7S3xyS.mjs.map} +1 -1
- package/{add-BwC5Yb3Z.mjs → add-CdqkkEgo.mjs} +3 -3
- package/{add-BwC5Yb3Z.mjs.map → add-CdqkkEgo.mjs.map} +1 -1
- package/{check-n2oLWYrZ.mjs → check-qniur0f-.mjs} +2 -2
- package/{check-n2oLWYrZ.mjs.map → check-qniur0f-.mjs.map} +1 -1
- package/{connect-CO-oR-Br.mjs → connect-C9Qlstmk.mjs} +3 -3
- package/{connect-CO-oR-Br.mjs.map → connect-C9Qlstmk.mjs.map} +1 -1
- package/{control-Clr9Xyw9.mjs → control-BN5pPW6Z.mjs} +2 -2
- package/{control-Clr9Xyw9.mjs.map → control-BN5pPW6Z.mjs.map} +1 -1
- package/disconnect-BTG_FVoG.mjs +2 -0
- package/{disconnect-B7HoGP0E.mjs → disconnect-D98vTza4.mjs} +2 -2
- package/{disconnect-B7HoGP0E.mjs.map → disconnect-D98vTza4.mjs.map} +1 -1
- package/{discovery-D07MPnKd.mjs → discovery-RAocoXhu.mjs} +2 -2
- package/{discovery-D07MPnKd.mjs.map → discovery-RAocoXhu.mjs.map} +1 -1
- package/{entries-BzfySpSJ.mjs → entries-B6pHaiVs.mjs} +2 -2
- package/{entries-BzfySpSJ.mjs.map → entries-B6pHaiVs.mjs.map} +1 -1
- package/{identity-DbK4fABs.mjs → identity-Dps5qkHz.mjs} +2 -2
- package/{identity-DbK4fABs.mjs.map → identity-Dps5qkHz.mjs.map} +1 -1
- package/index.mjs +22 -22
- package/{install-dfD5hzCS.mjs → install-Dzk6gQ3R.mjs} +2 -2
- package/{install-dfD5hzCS.mjs.map → install-Dzk6gQ3R.mjs.map} +1 -1
- package/{jsonc-CWL4-4yz.mjs → jsonc-CXTpkzZe.mjs} +2 -2
- package/{jsonc-CWL4-4yz.mjs.map → jsonc-CXTpkzZe.mjs.map} +1 -1
- package/{list-CGT6jT-r.mjs → list-BvMEYZss.mjs} +2 -2
- package/{list-CGT6jT-r.mjs.map → list-BvMEYZss.mjs.map} +1 -1
- package/{list-C3McEC0O.mjs → list-e5NT4i9D.mjs} +2 -2
- package/{list-C3McEC0O.mjs.map → list-e5NT4i9D.mjs.map} +1 -1
- package/{login-XhIIF5Yu.mjs → login-CXRvj9pQ.mjs} +2 -2
- package/{login-XhIIF5Yu.mjs.map → login-CXRvj9pQ.mjs.map} +1 -1
- package/{logout-Dpqw8tQZ.mjs → logout-Dp3FLxH-.mjs} +2 -2
- package/{logout-Dpqw8tQZ.mjs.map → logout-Dp3FLxH-.mjs.map} +1 -1
- package/package-D8VAWqDw.mjs +6 -0
- package/package-D8VAWqDw.mjs.map +1 -0
- package/package.json +3 -3
- package/reconnect-b5LQebj0.mjs +2 -0
- package/{relay-CLPWErNw.mjs → relay-UTS7NtSR.mjs} +3 -3
- package/{relay-CLPWErNw.mjs.map → relay-UTS7NtSR.mjs.map} +1 -1
- package/{remove-6m5n17il.mjs → remove-CReTs9O7.mjs} +2 -2
- package/{remove-6m5n17il.mjs.map → remove-CReTs9O7.mjs.map} +1 -1
- package/{remove-VZO51J2m.mjs → remove-W7QswkaH.mjs} +3 -3
- package/{remove-VZO51J2m.mjs.map → remove-W7QswkaH.mjs.map} +1 -1
- package/{restart-4NoPj76N.mjs → restart-B1CsEzlL.mjs} +2 -2
- package/{restart-4NoPj76N.mjs.map → restart-B1CsEzlL.mjs.map} +1 -1
- package/{serve-BZ5FAU3h.mjs → serve-DGQOucNu.mjs} +3 -3
- package/{serve-BZ5FAU3h.mjs.map → serve-DGQOucNu.mjs.map} +1 -1
- package/{settings-DU140UBM.mjs → settings-CyvcSIcs.mjs} +2 -2
- package/{settings-DU140UBM.mjs.map → settings-CyvcSIcs.mjs.map} +1 -1
- package/{shared-CC4WukJX.mjs → shared-BzfKCE2E.mjs} +2 -2
- package/{shared-CC4WukJX.mjs.map → shared-BzfKCE2E.mjs.map} +1 -1
- package/{start-COhahq2E.mjs → start-DVU9_HiQ.mjs} +2 -2
- package/{start-COhahq2E.mjs.map → start-DVU9_HiQ.mjs.map} +1 -1
- package/{status-Cau7bzuQ.mjs → status-B2s6iBck.mjs} +2 -2
- package/{status-Cau7bzuQ.mjs.map → status-B2s6iBck.mjs.map} +1 -1
- package/{stop-CC--mxXp.mjs → stop-C9hSMdVa.mjs} +2 -2
- package/{stop-CC--mxXp.mjs.map → stop-C9hSMdVa.mjs.map} +1 -1
- package/{update-DMQLgDm3.mjs → update-XBsVxrRL.mjs} +2 -2
- package/{update-DMQLgDm3.mjs.map → update-XBsVxrRL.mjs.map} +1 -1
- package/disconnect-gKR8hsnU.mjs +0 -2
- package/package-DgfSc9nY.mjs +0 -6
- package/package-DgfSc9nY.mjs.map +0 -1
- package/reconnect-I9-Do_DK.mjs +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-
|
|
1
|
+
{"version":3,"file":"list-e5NT4i9D.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/mcp/list.ts"],"sourcesContent":["/* @effect-diagnostics preferSchemaOverJson:off -- `--json` prints the report as it is built. */\nimport { Database, Event, type EventList, Mcp } from \"@codeworksh/harness/effect\";\nimport { Effect, Layer, References } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { configured, describe, MARKS } from \"./shared.ts\";\n\ninterface Report {\n\treadonly name: string;\n\treadonly level: \"user\" | \"project\";\n\treadonly file: string;\n\t/** The project `mcp.json` that overrides `enabled` or exposure of this user server. */\n\treadonly override?: string;\n\treadonly enabled: boolean;\n\treadonly exposure: string;\n\treadonly transport: string;\n\treadonly state: Mcp.State;\n\treadonly tools: ReadonlyArray<string>;\n\t/** Tools it listed that were left out because the MCP SDK rejects them. */\n\treadonly skipped?: EventList.McpSkipped;\n\t/** Tools whose exposure differs from the server's, from `toolExposure`. */\n\treadonly toolExposure?: Record<string, string>;\n\t/** Whether the server offers resources. They are not listed: listing every one can take long. */\n\treadonly resources?: true;\n\treadonly error?: string;\n}\n\nexport default Runtime.handler(\n\tCmd.commands.mcp.commands.list,\n\tEffect.fn(\"CLI.mcp.list\")(function* ({ json }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst { home, authFile, hostCwd, root, user, servers, errors } = yield* configured();\n\t\t\t// Every connect problem is in the report; the service's own logs would only repeat it.\n\t\t\tconst statuses = yield* Mcp.check({\n\t\t\t\tservers: servers.map((server) => [server.name, server.config] as const),\n\t\t\t\tdirectory: hostCwd,\n\t\t\t\thostDir: root ?? hostCwd,\n\t\t\t}).pipe(\n\t\t\t\t// Status events need an event service; nothing reads them here, so it keeps them in memory.\n\t\t\t\tEffect.provide(\n\t\t\t\t\tMcp.layer({ hostCwd, home, authFile }).pipe(\n\t\t\t\t\t\tLayer.provide(Event.layer.pipe(Layer.provide(Database.layer(\":memory:\")))),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\tEffect.provideService(References.MinimumLogLevel, \"None\"),\n\t\t\t);\n\t\t\tconst reports = servers.map((server): Report => {\n\t\t\t\tconst { config } = server;\n\t\t\t\tconst status = statuses.find((one) => one.server === server.name);\n\t\t\t\tconst exposure = config.exposure ?? \"direct\";\n\t\t\t\tconst tools = status?.tools ?? [];\n\t\t\t\tconst overrides = tools.filter((tool) => tool.exposure !== exposure);\n\t\t\t\tconst state = status?.state ?? \"disabled\";\n\t\t\t\treturn {\n\t\t\t\t\tname: server.name,\n\t\t\t\t\tlevel: server.file === user ? \"user\" : \"project\",\n\t\t\t\t\tfile: server.file,\n\t\t\t\t\t...(server.override === undefined ? {} : { override: server.override }),\n\t\t\t\t\tenabled: config.enabled !== false,\n\t\t\t\t\texposure,\n\t\t\t\t\ttransport: \"url\" in config ? config.url : [config.command, ...(config.args ?? [])].join(\" \"),\n\t\t\t\t\tstate,\n\t\t\t\t\ttools: tools.map((tool) => tool.name),\n\t\t\t\t\t...(status?.skipped === undefined ? {} : { skipped: status.skipped }),\n\t\t\t\t\t...(overrides.length === 0\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { toolExposure: Object.fromEntries(overrides.map((tool) => [tool.name, tool.exposure])) }),\n\t\t\t\t\t...(status?.resources ? { resources: true as const } : {}),\n\t\t\t\t\t...(state !== \"connected\" && status?.error !== undefined ? { error: status.error } : {}),\n\t\t\t\t};\n\t\t\t});\n\t\t\tconst failed = errors.length > 0 || reports.some((report) => report.enabled && report.state !== \"connected\");\n\t\t\tif (failed)\n\t\t\t\tyield* Effect.sync(() => {\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t});\n\n\t\t\tif (json) return yield* writeOut(`${JSON.stringify({ servers: reports, errors }, null, 2)}\\n`);\n\t\t\tconst lines: string[] = [];\n\t\t\tif (reports.length === 0 && errors.length === 0)\n\t\t\t\tlines.push(`No MCP servers configured. Add them to ${user} or .codework/mcp.json.`);\n\t\t\tconst width = Math.max(0, ...reports.map((report) => report.name.length));\n\t\t\tfor (const report of reports) {\n\t\t\t\tlines.push(\n\t\t\t\t\t`${MARKS[report.state]} ${report.name.padEnd(width)} ${describe(report.state, report.tools.length, report.skipped)} (${report.exposure}, ${report.level})`,\n\t\t\t\t);\n\t\t\t\tconst detail = (line: string) => lines.push(` ${line}`);\n\t\t\t\tdetail(report.transport);\n\t\t\t\tif (report.override !== undefined) detail(`project override: ${report.override}`);\n\t\t\t\tif (report.tools.length > 0)\n\t\t\t\t\tdetail(\n\t\t\t\t\t\t`tools: ${report.tools\n\t\t\t\t\t\t\t.map((tool) => {\n\t\t\t\t\t\t\t\tconst exposure = report.toolExposure?.[tool];\n\t\t\t\t\t\t\t\treturn exposure === undefined ? tool : `${tool} [${exposure}]`;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\tif (report.resources) detail(\"offers resources\");\n\t\t\t\tif (report.error !== undefined) for (const line of report.error.split(\"\\n\")) detail(line);\n\t\t\t}\n\t\t\tfor (const error of errors) lines.push(`config error: ${error}`);\n\t\t\tyield* writeOut(`${lines.join(\"\\n\")}\\n`);\n\t\t});\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AA6BA,IAAA,eAAeA,QACd,IAAI,SAAS,IAAI,SAAS,MAC1B,OAAO,GAAG,cAAc,CAAC,CAAC,WAAW,EAAE,QAAQ;CA2E9C,OAAO,OA1ES,OAAO,IAAI,aAAa;EACvC,MAAM,EAAE,MAAM,UAAU,SAAS,MAAM,MAAM,SAAS,WAAW,OAAO,WAAW;EAEnF,MAAM,WAAW,OAAO,IAAI,MAAM;GACjC,SAAS,QAAQ,KAAK,WAAW,CAAC,OAAO,MAAM,OAAO,MAAM,CAAU;GACtE,WAAW;GACX,SAAS,QAAQ;EAClB,CAAC,CAAC,CAAC,KAEF,OAAO,QACN,IAAI,MAAM;GAAE;GAAS;GAAM;EAAS,CAAC,CAAC,CAAC,KACtC,MAAM,QAAQ,MAAM,MAAM,KAAK,MAAM,QAAQ,SAAS,MAAM,UAAU,CAAC,CAAC,CAAC,CAC1E,CACD,GACA,OAAO,eAAe,WAAW,iBAAiB,MAAM,CACzD;EACA,MAAM,UAAU,QAAQ,KAAK,WAAmB;GAC/C,MAAM,EAAE,WAAW;GACnB,MAAM,SAAS,SAAS,MAAM,QAAQ,IAAI,WAAW,OAAO,IAAI;GAChE,MAAM,WAAW,OAAO,YAAY;GACpC,MAAM,QAAQ,QAAQ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,KAAK,MAAM,CAAC;EACxE,KAAK,MAAM,UAAU,SAAS;GAC7B,MAAM,KACL,GAAG,MAAM,OAAO,OAAO,GAAG,OAAO,KAAK,OAAO,KAAK,EAAE,IAAI,SAAS,OAAO,OAAO,OAAO,MAAM,QAAQ,OAAO,OAAO,EAAE,IAAI,OAAO,SAAS,IAAI,OAAO,MAAM,EAC1J;GACA,MAAM,UAAU,SAAiB,MAAM,KAAK,OAAO,MAAM;GACzD,OAAO,OAAO,SAAS;GACvB,IAAI,OAAO,aAAa,KAAA,GAAW,OAAO,qBAAqB,OAAO,UAAU;GAChF,IAAI,OAAO,MAAM,SAAS,GACzB,OACC,UAAU,OAAO,MACf,KAAK,SAAS;IACd,MAAM,WAAW,OAAO,eAAe;IACvC,OAAO,aAAa,KAAA,IAAY,OAAO,GAAG,KAAK,IAAI,SAAS;GAC7D,CAAC,CAAC,CACD,KAAK,IAAI,GACZ;GACD,IAAI,OAAO,WAAW,OAAO,kBAAkB;GAC/C,IAAI,OAAO,UAAU,KAAA,GAAW,KAAK,MAAM,QAAQ,OAAO,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI;EACzF;EACA,KAAK,MAAM,SAAS,QAAQ,MAAM,KAAK,iBAAiB,OAAO;EAC/D,OAAO,SAAS,GAAG,MAAM,KAAK,IAAI,EAAE,GAAG;CACxC,CACoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, f as writeError, m as writeOut, n as OAuthError } from "./error-ippxl2z7.mjs";
|
|
2
2
|
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
-
import { i as oauthServer } from "./shared-
|
|
3
|
+
import { i as oauthServer } from "./shared-BzfKCE2E.mjs";
|
|
4
4
|
import { Duration, Effect, Logger } from "effect";
|
|
5
5
|
import { McpOAuth } from "@codeworksh/harness/effect";
|
|
6
6
|
import { openBrowser } from "@codeworksh/aikit/oauth/interactive";
|
|
@@ -56,4 +56,4 @@ var login_default = handler(Cmd.commands.mcp.commands.login, Effect.fn("CLI.mcp.
|
|
|
56
56
|
//#endregion
|
|
57
57
|
export { login_default as default };
|
|
58
58
|
|
|
59
|
-
//# sourceMappingURL=login-
|
|
59
|
+
//# sourceMappingURL=login-CXRvj9pQ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-
|
|
1
|
+
{"version":3,"file":"login-CXRvj9pQ.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/mcp/login.ts"],"sourcesContent":["/* @effect-diagnostics nodeBuiltinImport:off -- the pasted redirect URL is read from standard input. */\nimport { createInterface } from \"node:readline\";\nimport { openBrowser } from \"@codeworksh/aikit/oauth/interactive\";\nimport { McpOAuth } from \"@codeworksh/harness/effect\";\nimport { Duration, Effect, Logger } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { OAuthError, reportFailure } from \"../../../error.ts\";\nimport { writeError, writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { oauthServer } from \"./shared.ts\";\n\n/**\n * The redirected URL, typed or piped in when the browser cannot reach this machine's callback (over\n * SSH, say). Piped input that ends without a line leaves the callback to finish the sign-in; a\n * terminal that closes (Ctrl+C, Ctrl+D) cancels it.\n */\nconst paste: Effect.Effect<string> = Effect.acquireUseRelease(\n\tEffect.sync(() => ({\n\t\treadline: createInterface({ input: process.stdin, output: process.stderr }),\n\t\tanswered: false,\n\t})),\n\t(asking) =>\n\t\tEffect.callback<string>((resume) => {\n\t\t\tconst answer = (line: string) => {\n\t\t\t\tasking.answered = true;\n\t\t\t\tresume(Effect.succeed(line));\n\t\t\t};\n\t\t\tasking.readline.question(\"Or paste the URL the browser was redirected to: \", answer);\n\t\t\t// An empty answer cancels the sign-in.\n\t\t\tif (process.stdin.isTTY) asking.readline.once(\"close\", () => answer(\"\"));\n\t\t}),\n\t(asking) =>\n\t\tEffect.sync(() => {\n\t\t\tconst unanswered = !asking.answered;\n\t\t\tasking.readline.close();\n\t\t\t// A pipe still open would keep the process alive after the sign-in.\n\t\t\tprocess.stdin.destroy();\n\t\t\t// What follows starts on its own line, not after the prompt.\n\t\t\tif (unanswered) process.stderr.write(\"\\n\");\n\t\t}),\n);\n\nexport default Runtime.handler(\n\tCmd.commands.mcp.commands.login,\n\tEffect.fn(\"CLI.mcp.login\")(function* ({ name, browser, timeout }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst { store, config } = yield* oauthServer(name);\n\t\t\tconst limit = Duration.seconds(timeout);\n\t\t\tconst result = yield* McpOAuth.login({\n\t\t\t\tstore,\n\t\t\t\tname,\n\t\t\t\tconfig,\n\t\t\t\tprompt: {\n\t\t\t\t\tshow: (url) =>\n\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\tyield* writeError(`Sign in to MCP server \"${name}\" in your browser:\\n${url.href}\\n`);\n\t\t\t\t\t\t\tif (browser)\n\t\t\t\t\t\t\t\tyield* Effect.sync(\n\t\t\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\t\t\tvoid openBrowser(url.href, (error) =>\n\t\t\t\t\t\t\t\t\t\t\tprocess.stderr.write(`Failed to open browser: ${error.message}\\n`),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}),\n\t\t\t\t\tpaste,\n\t\t\t\t},\n\t\t\t}).pipe(\n\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\tduration: limit,\n\t\t\t\t\torElse: () =>\n\t\t\t\t\t\tEffect.fail(new OAuthError({ message: `sign-in timed out after ${Duration.format(limit)}` })),\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst tools = `${result.tools} tool${result.tools === 1 ? \"\" : \"s\"}`;\n\t\t\tyield* writeOut(\n\t\t\t\tresult.signedIn\n\t\t\t\t\t? `Signed in to MCP server \"${name}\" (${tools}).\\n`\n\t\t\t\t\t: `Already signed in to MCP server \"${name}\" (${tools}).\\n`,\n\t\t\t);\n\t\t});\n\t\t// Stdout carries only the outcome; harness logs go with the rest of the diagnostics.\n\t\treturn yield* program.pipe(Effect.provideService(Logger.LogToStderr, true), Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,QAA+B,OAAO,kBAC3C,OAAO,YAAY;CAClB,UAAU,gBAAgB;EAAE,OAAO,QAAQ;EAAO,QAAQ,QAAQ;CAAO,CAAC;CAC1E,UAAU;AACX,EAAE,IACD,WACA,OAAO,UAAkB,WAAW;CACnC,MAAM,UAAU,SAAiB;EAChC,OAAO,WAAW;EAClB,OAAO,OAAO,QAAQ,IAAI,CAAC;CAC5B;CACA,OAAO,SAAS,SAAS,oDAAoD,MAAM;CAEnF,IAAI,QAAQ,MAAM,OAAO,OAAO,SAAS,KAAK,eAAe,OAAO,EAAE,CAAC;AACxE,CAAC,IACD,WACA,OAAO,WAAW;CACjB,MAAM,aAAa,CAAC,OAAO;CAC3B,OAAO,SAAS,MAAM;CAEtB,QAAQ,MAAM,QAAQ;CAEtB,IAAI,YAAY,QAAQ,OAAO,MAAM,IAAI;AAC1C,CAAC,CACH;AAEA,IAAA,gBAAeA,QACd,IAAI,SAAS,IAAI,SAAS,OAC1B,OAAO,GAAG,eAAe,CAAC,CAAC,WAAW,EAAE,MAAM,SAAS,WAAW;CAqCjE,OAAO,OApCS,OAAO,IAAI,aAAa;EACvC,MAAM,EAAE,OAAO,WAAW,OAAO,YAAY,IAAI;EACjD,MAAM,QAAQ,SAAS,QAAQ,OAAO;EACtC,MAAM,SAAS,OAAO,SAAS,MAAM;GACpC;GACA;GACA;GACA,QAAQ;IACP,OAAO,QACN,OAAO,IAAI,aAAa;KACvB,OAAO,WAAW,0BAA0B,KAAK,sBAAsB,IAAI,KAAK,GAAG;KACnF,IAAI,SACH,OAAO,OAAO,WAEZ,KAAK,YAAY,IAAI,OAAO,UAC3B,QAAQ,OAAO,MAAM,2BAA2B,MAAM,QAAQ,GAAG,CAClE,CACF;IACF,CAAC;IACF;GACD;EACD,CAAC,CAAC,CAAC,KACF,OAAO,cAAc;GACpB,UAAU;GACV,cACC,OAAO,KAAK,IAAI,WAAW,EAAE,SAAS,2BAA2B,SAAS,OAAO,KAAK,IAAI,CAAC,CAAC;EAC9F,CAAC,CACF;EACA,MAAM,QAAQ,GAAG,OAAO,MAAM,OAAO,OAAO,UAAU,IAAI,KAAK;EAC/D,OAAO,SACN,OAAO,WACJ,4BAA4B,KAAK,KAAK,MAAM,QAC5C,oCAAoC,KAAK,KAAK,MAAM,KACxD;CACD,CAEoB,CAAC,CAAC,KAAK,OAAO,eAAe,OAAO,aAAa,IAAI,GAAG,OAAO,MAAM,aAAa,CAAC;AACxG,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, m as writeOut } from "./error-ippxl2z7.mjs";
|
|
2
2
|
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
-
import { i as oauthServer } from "./shared-
|
|
3
|
+
import { i as oauthServer } from "./shared-BzfKCE2E.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import { McpOAuth } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/mcp/logout.ts
|
|
@@ -14,4 +14,4 @@ var logout_default = handler(Cmd.commands.mcp.commands.logout, Effect.fn("CLI.mc
|
|
|
14
14
|
//#endregion
|
|
15
15
|
export { logout_default as default };
|
|
16
16
|
|
|
17
|
-
//# sourceMappingURL=logout-
|
|
17
|
+
//# sourceMappingURL=logout-Dp3FLxH-.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout-
|
|
1
|
+
{"version":3,"file":"logout-Dp3FLxH-.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/mcp/logout.ts"],"sourcesContent":["import { McpOAuth } from \"@codeworksh/harness/effect\";\nimport { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { oauthServer } from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.mcp.commands.logout,\n\tEffect.fn(\"CLI.mcp.logout\")(function* ({ name }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst { store, server } = yield* oauthServer(name);\n\t\t\tconst removed = yield* McpOAuth.signOut(store, server);\n\t\t\tyield* writeOut(\n\t\t\t\tremoved ? `Signed out of MCP server \"${name}\".\\n` : `MCP server \"${name}\" has no stored sign-in.\\n`,\n\t\t\t);\n\t\t});\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,iBAAeA,QACd,IAAI,SAAS,IAAI,SAAS,QAC1B,OAAO,GAAG,gBAAgB,CAAC,CAAC,WAAW,EAAE,QAAQ;CAQhD,OAAO,OAPS,OAAO,IAAI,aAAa;EACvC,MAAM,EAAE,OAAO,WAAW,OAAO,YAAY,IAAI;EACjD,MAAM,UAAU,OAAO,SAAS,QAAQ,OAAO,MAAM;EACrD,OAAO,SACN,UAAU,6BAA6B,KAAK,QAAQ,eAAe,KAAK,2BACzE;CACD,CACoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-D8VAWqDw.mjs","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeworksh/cli",
|
|
3
|
-
"version": "0.9.0-canary.
|
|
3
|
+
"version": "0.9.0-canary.160.1.g8b6596ff",
|
|
4
4
|
"description": "CLI for running CodeWork coding agent harness.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@agentclientprotocol/sdk": "1.5.1",
|
|
43
|
-
"@codeworksh/aikit": "0.14.1-canary.
|
|
44
|
-
"@codeworksh/harness": "0.9.0-canary.
|
|
43
|
+
"@codeworksh/aikit": "0.14.1-canary.160.1.g8b6596ff",
|
|
44
|
+
"@codeworksh/harness": "0.9.0-canary.160.1.g8b6596ff",
|
|
45
45
|
"@effect/platform-node": "4.0.5",
|
|
46
46
|
"@effect/platform-node-shared": "4.0.5",
|
|
47
47
|
"effect": "4.0.5",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { $ as sign, H as Api, K as PrivateKey, Q as publicOf, U as IdSource, V as ConnectError, W as MachineId, Y as generate, et as thumbprint } from "./error-ippxl2z7.mjs";
|
|
2
|
-
import { t as version } from "./package-
|
|
2
|
+
import { t as version } from "./package-D8VAWqDw.mjs";
|
|
3
3
|
import { o as write$1 } from "./registration-C6yiv31r.mjs";
|
|
4
|
-
import { r as hostName } from "./identity-
|
|
4
|
+
import { r as hostName } from "./identity-Dps5qkHz.mjs";
|
|
5
5
|
import { Clock, Config, Context, Duration, Effect, FileSystem, Layer, Option, Schedule, Schema } from "effect";
|
|
6
6
|
import { FetchHttpClient } from "effect/http";
|
|
7
7
|
import { uuidv7 } from "uuidv7";
|
|
@@ -316,4 +316,4 @@ const disconnect = Effect.fn("Machine.disconnect")(function* (home, workspaceId,
|
|
|
316
316
|
//#endregion
|
|
317
317
|
export { rename as a, read as c, heartbeat as i, connect as n, status as o, disconnect as r, identity as s, Client as t };
|
|
318
318
|
|
|
319
|
-
//# sourceMappingURL=relay-
|
|
319
|
+
//# sourceMappingURL=relay-UTS7NtSR.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-CLPWErNw.mjs","names":["Jws.PrivateKey","Relay.IdSource","Private.write","Jws.generate","Jws.thumbprint","Jws.publicOf","Relay.MachineId","Relay.Api","pkg.version","File.read","File.update","File.checkId","Jws.generate","Jws.thumbprint","Jws.publicOf","Jws.sign","Machine.ConnectError","File.removeLink","File.markLeaving"],"sources":["../../src/machine/file.ts","../../src/machine/relay.ts"],"sourcesContent":["import { Jws, Relay } from \"@codeworksh/schema\";\nimport { Effect, FileSystem, Option, Schedule, Schema } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\nimport * as Private from \"../framework/private.ts\";\n\n/**\n * `<home>/machine.json`: who this home is as a machine, and its link to each connected workspace.\n *\n * It survives restarts (unlike `service.json`, which a server writes and removes) and holds private\n * keys, so it is written 0600, atomically, and under a lock shared by `serve` and `codework connect`.\n */\nconst Link = Schema.Struct({\n\tname: Schema.String,\n\towner: Schema.Struct({ id: Schema.String, name: Schema.NullOr(Schema.String) }),\n\t/** The relay the link was made with; heartbeats and disconnect go there. */\n\trelay: Schema.String,\n\tkey: Jws.PrivateKey,\n\tkeyId: Schema.String,\n\t/** Left locally, but the relay hasn't confirmed: the key is kept to revoke it once the relay answers. */\n\tleaving: Schema.optionalKey(Schema.Boolean),\n});\n\n/** One key per home, vouching for each link key, so the relay knows every link of this home is one machine. */\nconst Identity = Schema.Struct({ key: Jws.PrivateKey, keyId: Schema.String });\ntype Identity = typeof Identity.Type;\n\nexport const Machine = Schema.Struct({\n\tid: Schema.String,\n\tsource: Relay.IdSource,\n\t/** The user's own name for the machine; shown in place of the OS host name when set. */\n\tgivenName: Schema.optional(Schema.String),\n\t// Optional only for homes connected before identities existed; `update` gives every home one.\n\tidentity: Schema.optional(Identity),\n\tworkspaces: Schema.Record(Schema.String, Link),\n});\nexport type Machine = typeof Machine.Type;\n/** The machine as {@link update} hands it out: always with its identity. */\ntype Identified = Machine & { readonly identity: Identity };\n\nconst json = Schema.fromJsonString(Machine);\n\nclass MachineError extends Schema.TaggedError<MachineError>()(\"Machine.MachineError\", {\n\tmessage: Schema.String,\n}) {}\n\nconst file = (home: string) => `${home}/machine.json`;\n\n/** The machine as stored, or none before its first run. */\nexport const read = Effect.fn(\"Machine.read\")(function* (home: string) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst path = file(home);\n\tif (!(yield* fs.exists(path))) return Option.none<Machine>();\n\tconst text = yield* fs.readFileString(path);\n\treturn Option.some(\n\t\tyield* Schema.decodeEffect(json)(text).pipe(\n\t\t\tEffect.mapError(() => new MachineError({ message: `${path} is not a valid machine file` })),\n\t\t),\n\t);\n});\n\n// One writer at a time: creating a directory either succeeds or fails, so it serves as a lock.\nconst locked = <A, E, R>(home: string, effect: Effect.Effect<A, E, R>) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst lock = `${file(home)}.lock`;\n\t\tyield* fs.makeDirectory(home, { recursive: true });\n\t\tyield* fs.makeDirectory(lock).pipe(\n\t\t\tEffect.retry({ schedule: Schedule.spaced(\"50 millis\"), times: 100 }),\n\t\t\tEffect.mapError(() => new MachineError({ message: `${lock} is held by another process` })),\n\t\t);\n\t\treturn yield* effect.pipe(Effect.ensuring(fs.remove(lock, { recursive: true }).pipe(Effect.ignore)));\n\t});\n\nconst write = (home: string, machine: Machine) =>\n\tSchema.encodeEffect(json)(machine).pipe(Effect.flatMap((encoded) => Private.write(file(home), encoded)));\n\nconst newIdentity = Effect.gen(function* () {\n\tconst key = yield* Jws.generate();\n\treturn { key, keyId: yield* Jws.thumbprint(Jws.publicOf(key)) } satisfies Identity;\n});\n\n/** Reads, changes and writes the machine under the lock, creating its identity on first use. */\nexport const update = <E, R>(\n\thome: string,\n\toptions: { readonly machineId?: string | undefined },\n\tchange: (machine: Identified) => Effect.Effect<Identified, E, R>,\n) =>\n\tlocked(\n\t\thome,\n\t\tEffect.gen(function* () {\n\t\t\tconst existing = yield* read(home);\n\t\t\tconst machine = yield* Option.match(existing, {\n\t\t\t\tonNone: () => Effect.succeed(created(options.machineId)),\n\t\t\t\tonSome: (machine) =>\n\t\t\t\t\toptions.machineId === undefined || options.machineId === machine.id\n\t\t\t\t\t\t? Effect.succeed(machine)\n\t\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\t\tnew MachineError({\n\t\t\t\t\t\t\t\t\tmessage: `This home is machine ${machine.id}; its id can't change to ${options.machineId}. Use another --home.`,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t});\n\t\t\tconst identity = machine.identity ?? (yield* newIdentity);\n\t\t\tconst next = yield* change({ ...machine, identity });\n\t\t\tyield* write(home, next);\n\t\t\treturn next;\n\t\t}),\n\t);\n\n/** The home's identity, created with the machine on first use. */\nexport const identity = Effect.fn(\"Machine.identity\")(function* (home: string) {\n\tconst stored = yield* read(home);\n\tif (Option.isSome(stored) && stored.value.identity !== undefined) return stored.value.identity;\n\treturn (yield* update(home, {}, Effect.succeed)).identity;\n});\n\nconst created = (machineId: string | undefined): Machine =>\n\tmachineId === undefined\n\t\t? { id: uuidv7(), source: \"generated\", workspaces: {} }\n\t\t: { id: machineId, source: \"flag\", workspaces: {} };\n\n/** Validates a `--machine-id` before anything is written. */\nexport const checkId = (machineId: string | undefined) =>\n\tmachineId === undefined || Schema.is(Relay.MachineId)(machineId)\n\t\t? Effect.void\n\t\t: Effect.fail(\n\t\t\t\tnew MachineError({\n\t\t\t\t\tmessage: `--machine-id must be 1-64 lowercase letters, digits or dashes, starting with a letter or digit`,\n\t\t\t\t}),\n\t\t\t);\n\n/**\n * Forgets the link to a workspace, only while it still holds `keyId`: a reconnect that saved a new key in\n * the meantime keeps its link.\n */\nexport const removeLink = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst { [workspaceId]: link, ...workspaces } = machine.workspaces;\n\t\treturn Effect.succeed(link === undefined || link.keyId !== keyId ? machine : { ...machine, workspaces });\n\t});\n\n/** Marks the link as leaving, only while it still holds `keyId`. */\nexport const markLeaving = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst link = machine.workspaces[workspaceId];\n\t\treturn Effect.succeed(\n\t\t\tlink === undefined || link.keyId !== keyId\n\t\t\t\t? machine\n\t\t\t\t: { ...machine, workspaces: { ...machine.workspaces, [workspaceId]: { ...link, leaving: true } } },\n\t\t);\n\t});\n","import { NodeServices } from \"@effect/platform-node\";\nimport { Jws, Machine, Relay } from \"@codeworksh/schema\";\nimport { Clock, Config, Context, Duration, Effect, Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { HttpApiClient } from \"effect/http-api\";\nimport { uuidv7 } from \"uuidv7\";\nimport pkg from \"../../package.json\" with { type: \"json\" };\nimport { hostName } from \"../server/identity.ts\";\nimport * as File from \"./file.ts\";\n\n/** The relay's typed client at `url`. */\nconst at = (url: string) => HttpApiClient.make(Relay.Api, { baseUrl: url }).pipe(Effect.provide(FetchHttpClient.layer));\n\n/**\n * The relay new connects go to: `CODEWORK_RELAY_URL`, default https://relay.codework.sh. A link keeps\n * talking to the relay it was made with, whatever this says later.\n */\nexport class Client extends Context.Service<\n\tClient,\n\t{ readonly url: string; readonly api: HttpApiClient.ForApi<typeof Relay.Api> }\n>()(\"@codeworksh/cli/machine/relay/Client\") {\n\tstatic readonly layer = Layer.effect(\n\t\tClient,\n\t\tEffect.gen(function* () {\n\t\t\tconst url = yield* Config.String(\"CODEWORK_RELAY_URL\").pipe(Config.withDefault(\"https://relay.codework.sh\"));\n\t\t\treturn { url, api: yield* at(url) };\n\t\t}),\n\t);\n}\n\n/** What this machine says about itself to the relay. */\nconst describe = Effect.fn(\"Machine.describe\")(function* (machine: File.Machine) {\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\treturn {\n\t\tid: machine.id,\n\t\tsource: machine.source,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tos: process.platform,\n\t\tarch: process.arch,\n\t\tversion: pkg.version,\n\t} satisfies Relay.MachineInfo;\n});\n\n/** This machine and its workspaces, as the desktop app shows them. */\nexport const status = Effect.fn(\"Machine.status\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\tif (stored._tag === \"None\")\n\t\treturn { id: null, localHostName, givenName: null, workspaces: [] } satisfies Machine.Status;\n\tconst machine = stored.value;\n\treturn {\n\t\tid: machine.id,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tworkspaces: Object.entries(machine.workspaces).map(([id, link]) => ({\n\t\t\tid,\n\t\t\tname: link.name,\n\t\t\tkeyId: link.keyId,\n\t\t\tleaving: link.leaving === true,\n\t\t})),\n\t} satisfies Machine.Status;\n});\n\n/**\n * Names this machine for people: empty clears the name back to the OS's. The relay hears it on the\n * next heartbeat.\n */\nexport const rename = Effect.fn(\"Machine.rename\")(function* (home: string, givenName: string) {\n\tconst name = givenName.trim();\n\tyield* File.update(home, {}, ({ givenName: _previous, ...machine }) =>\n\t\tEffect.succeed(name === \"\" ? machine : { ...machine, givenName: name }),\n\t);\n\treturn yield* status(home);\n});\n\n/**\n * Pairs this home with a workspace: registers a fresh key with the relay, shows the code a member\n * approves, and polls with that key until the relay links it, then saves the link. Each workspace gets\n * its own key, and only this process can take the link: a connect that stops is never linked.\n */\nexport const connect = Effect.fn(\"Machine.connect\")(function* (options: {\n\treadonly home: string;\n\treadonly workspaceId?: string | undefined;\n\treadonly machineId?: string | undefined;\n\treadonly onCode: (userCode: string) => Effect.Effect<void>;\n}) {\n\tconst client = yield* Client;\n\tyield* File.checkId(options.machineId);\n\tconst machine = yield* File.update(options.home, { machineId: options.machineId }, Effect.succeed);\n\tconst key = yield* Jws.generate();\n\tconst keyId = yield* Jws.thumbprint(Jws.publicOf(key));\n\tconst iat = yield* Clock.currentTimeMillis;\n\tconst binding: Relay.IdentityClaims = { op: \"identity.bind\", iat, keyId };\n\tconst claims: Relay.PairingClaims = {\n\t\top: \"pairing.create\",\n\t\tiat,\n\t\tmachine: yield* describe(machine),\n\t\tworkspaceId: options.workspaceId ?? null,\n\t\tidentity: yield* Jws.sign(binding, machine.identity.key, { embed: true }),\n\t};\n\tconst pairing = yield* client.api.machine\n\t\t.pair({ payload: { jws: yield* Jws.sign(claims, key, { embed: true }) } })\n\t\t.pipe(\n\t\t\tEffect.catchTag(\"Relay.NotFound\", () =>\n\t\t\t\tEffect.fail(new Machine.ConnectError({ message: \"No such workspace\" })),\n\t\t\t),\n\t\t);\n\tyield* options.onCode(pairing.userCode);\n\n\tconst poll = Effect.gen(function* () {\n\t\tconst claims: Relay.PollClaims = { op: \"pairing.poll\", iat: yield* Clock.currentTimeMillis };\n\t\treturn yield* client.api.machine.poll({ payload: { jws: yield* Jws.sign(claims, key, { kid: keyId }) } });\n\t}).pipe(\n\t\t// A dropped request or a relay restart doesn't end the connect; the next poll asks again.\n\t\tEffect.catchTag(\"HttpClientError\", (error) =>\n\t\t\tEffect.logDebug(\"Pairing poll failed\", error).pipe(Effect.as(undefined)),\n\t\t),\n\t);\n\tlet previous = machine;\n\tconst deadline = (yield* Clock.currentTimeMillis) + pairing.expiresIn * 1000;\n\twhile ((yield* Clock.currentTimeMillis) < deadline) {\n\t\tyield* Effect.sleep(Duration.seconds(pairing.interval));\n\t\tconst status = yield* poll;\n\t\tif (status === undefined) continue;\n\t\tif (status.status !== \"approved\") {\n\t\t\tif (status.status === \"pending\") continue;\n\t\t\tif (status.status === \"expired\") break;\n\t\t\treturn yield* new Machine.ConnectError({\n\t\t\t\tmessage:\n\t\t\t\t\tstatus.status === \"declined\"\n\t\t\t\t\t\t? \"The connect was declined; run connect again for a new code\"\n\t\t\t\t\t\t: \"Another connect for this machine finished first\",\n\t\t\t});\n\t\t}\n\t\tconst { connected } = status;\n\t\t// A poll response can arrive after another connect saved a different key.\n\t\t// Observe that change under the lock, then poll again before replacing it.\n\t\tconst id = connected.workspace.id;\n\t\tconst stored = yield* File.update(options.home, {}, (current) =>\n\t\t\tEffect.succeed(\n\t\t\t\tcurrent.workspaces[id]?.keyId !== previous.workspaces[id]?.keyId\n\t\t\t\t\t? current\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t...current,\n\t\t\t\t\t\t\tworkspaces: {\n\t\t\t\t\t\t\t\t...current.workspaces,\n\t\t\t\t\t\t\t\t[connected.workspace.id]: {\n\t\t\t\t\t\t\t\t\tname: connected.workspace.name,\n\t\t\t\t\t\t\t\t\towner: connected.owner,\n\t\t\t\t\t\t\t\t\trelay: client.url,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tkeyId,\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),\n\t\t);\n\t\tif (stored.workspaces[id]?.keyId === keyId) return connected;\n\t\tprevious = stored;\n\t}\n\treturn yield* new Machine.ConnectError({ message: \"The code expired before it was approved; run connect again\" });\n});\n\n/**\n * Asks the link's relay to revoke it, signed with its own key: true once the relay confirms, or says it\n * was revoked already; false when it can't be reached in time.\n */\nconst revoke = (machineId: string, workspaceId: string, link: File.Machine[\"workspaces\"][string]) =>\n\tEffect.gen(function* () {\n\t\tconst claims: Relay.RevokeClaims = {\n\t\t\top: \"machine.revoke\",\n\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\tjti: uuidv7(),\n\t\t\tworkspaceId,\n\t\t\tmachineId,\n\t\t};\n\t\tconst api = yield* at(link.relay);\n\t\tyield* api.machine.revoke({ payload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) } });\n\t}).pipe(\n\t\t// Leave time for the local update before the desktop RPC expires.\n\t\tEffect.timeout(\"3 seconds\"),\n\t\tEffect.as(true),\n\t\tEffect.catchTag(\"Relay.MachineRevoked\", () => Effect.succeed(true)),\n\t\tEffect.catch((error) => Effect.logDebug(`Revoke at ${link.name} failed`, error).pipe(Effect.as(false))),\n\t);\n\n/**\n * One heartbeat per connected workspace, each to the relay its link was made with, all at once. A link\n * the relay refuses as revoked is removed, but only while it still holds the refused key. A leaving link\n * asks for its revoke again instead, and is removed once the relay confirms.\n */\nexport const heartbeat = Effect.fn(\"Machine.heartbeat\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tif (stored._tag === \"None\") return;\n\tconst machine = stored.value;\n\tconst info = yield* describe(machine);\n\tyield* Effect.forEach(\n\t\tObject.entries(machine.workspaces),\n\t\t([workspaceId, link]) =>\n\t\t\tlink.leaving === true\n\t\t\t\t? revoke(machine.id, workspaceId, link).pipe(\n\t\t\t\t\t\tEffect.flatMap((revoked) =>\n\t\t\t\t\t\t\trevoked ? File.removeLink(home, workspaceId, link.keyId).pipe(Effect.asVoid) : Effect.void,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Leaving ${link.name} failed`, error)),\n\t\t\t\t\t)\n\t\t\t\t: Effect.gen(function* () {\n\t\t\t\t\t\tconst api = yield* at(link.relay);\n\t\t\t\t\t\tconst claims: Relay.HeartbeatClaims = {\n\t\t\t\t\t\t\top: \"machine.heartbeat\",\n\t\t\t\t\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\t\t\t\t\tworkspaceId,\n\t\t\t\t\t\t\tmachine: info,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tyield* api.machine.heartbeat({\n\t\t\t\t\t\t\tpayload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) },\n\t\t\t\t\t\t});\n\t\t\t\t\t}).pipe(\n\t\t\t\t\t\tEffect.timeout(\"10 seconds\"),\n\t\t\t\t\t\tEffect.catchTags({\n\t\t\t\t\t\t\t\"Relay.MachineRevoked\": (revoked) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Disconnected from ${link.name}: ${revoked.message}`).pipe(\n\t\t\t\t\t\t\t\t\tEffect.andThen(File.removeLink(home, workspaceId, link.keyId)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t// Refused but not revoked, most often a clock more than a minute off: worth seeing in the log.\n\t\t\t\t\t\t\t\"Relay.Unauthorized\": (refused) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Heartbeat to ${link.name} refused: ${refused.message}`),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Heartbeat to ${link.name} failed`, error)),\n\t\t\t\t\t),\n\t\t{ concurrency: \"unbounded\", discard: true },\n\t);\n});\n\n/**\n * Leaves a workspace: asks the link's relay to revoke it, then forgets it locally. When the relay can't\n * confirm, the link is kept as leaving, with its key, and each heartbeat asks again until it does; the\n * relay still lists it until then. `revoked` says whether it confirmed now.\n */\nexport const disconnect = Effect.fn(\"Machine.disconnect\")(function* (\n\thome: string,\n\tworkspaceId: string,\n\texpectedKeyId?: string,\n) {\n\tconst stored = yield* File.read(home);\n\tconst link = stored._tag === \"Some\" ? stored.value.workspaces[workspaceId] : undefined;\n\tif (stored._tag === \"None\" || link === undefined) {\n\t\treturn yield* new Machine.ConnectError({ message: `This machine is not connected to workspace ${workspaceId}` });\n\t}\n\tif (expectedKeyId !== undefined && link.keyId !== expectedKeyId)\n\t\treturn yield* new Machine.ConnectError({ message: \"This machine link has changed\" });\n\tconst revoked = yield* revoke(stored.value.id, workspaceId, link);\n\tyield* revoked ? File.removeLink(home, workspaceId, link.keyId) : File.markLeaving(home, workspaceId, link.keyId);\n\treturn { workspace: link.name, revoked };\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAM,OAAO,OAAO,OAAO;CAC1B,MAAM,OAAO;CACb,OAAO,OAAO,OAAO;EAAE,IAAI,OAAO;EAAQ,MAAM,OAAO,OAAO,OAAO,MAAM;CAAE,CAAC;;CAE9E,OAAO,OAAO;CACd,KAAKA;CACL,OAAO,OAAO;;CAEd,SAAS,OAAO,YAAY,OAAO,OAAO;AAC3C,CAAC;;AAGD,MAAM,WAAW,OAAO,OAAO;CAAE,KAAKA;CAAgB,OAAO,OAAO;AAAO,CAAC;AAG5E,MAAa,UAAU,OAAO,OAAO;CACpC,IAAI,OAAO;CACX,QAAQC;;CAER,WAAW,OAAO,SAAS,OAAO,MAAM;CAExC,UAAU,OAAO,SAAS,QAAQ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AAO,OAAO,SAAS,SAAS,OAAO,MAAM,WAAW,eAAe,KAAA;CAC7E,IAAI,OAAO,SAAS,UAAU,SAAS,KAAA,GACtC,OAAO,OAAO,IAAIO,aAAqB,EAAE,SAAS,8CAA8C,cAAc,CAAC;CAEhH,IAAI,kBAAkB,KAAA,KAAa,KAAK,UAAU,eACjD,OAAO,OAAO,IAAIA,aAAqB,EAAE,SAAS,gCAAgC,CAAC;CACpF,MAAM,UAAU,OAAO,OAAO,OAAO,MAAM,IAAI,aAAa,IAAI;CAChE,OAAO,UAAUC,WAAgB,MAAM,aAAa,KAAK,KAAK,IAAIC,YAAiB,MAAM,aAAa,KAAK,KAAK;CAChH,OAAO;EAAE,WAAW,KAAK;EAAM;CAAQ;AACxC,CAAC"}
|
|
1
|
+
{"version":3,"file":"relay-UTS7NtSR.mjs","names":["Jws.PrivateKey","Relay.IdSource","Private.write","Jws.generate","Jws.thumbprint","Jws.publicOf","Relay.MachineId","Relay.Api","pkg.version","File.read","File.update","File.checkId","Jws.generate","Jws.thumbprint","Jws.publicOf","Jws.sign","Machine.ConnectError","File.removeLink","File.markLeaving"],"sources":["../../src/machine/file.ts","../../src/machine/relay.ts"],"sourcesContent":["import { Jws, Relay } from \"@codeworksh/schema\";\nimport { Effect, FileSystem, Option, Schedule, Schema } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\nimport * as Private from \"../framework/private.ts\";\n\n/**\n * `<home>/machine.json`: who this home is as a machine, and its link to each connected workspace.\n *\n * It survives restarts (unlike `service.json`, which a server writes and removes) and holds private\n * keys, so it is written 0600, atomically, and under a lock shared by `serve` and `codework connect`.\n */\nconst Link = Schema.Struct({\n\tname: Schema.String,\n\towner: Schema.Struct({ id: Schema.String, name: Schema.NullOr(Schema.String) }),\n\t/** The relay the link was made with; heartbeats and disconnect go there. */\n\trelay: Schema.String,\n\tkey: Jws.PrivateKey,\n\tkeyId: Schema.String,\n\t/** Left locally, but the relay hasn't confirmed: the key is kept to revoke it once the relay answers. */\n\tleaving: Schema.optionalKey(Schema.Boolean),\n});\n\n/** One key per home, vouching for each link key, so the relay knows every link of this home is one machine. */\nconst Identity = Schema.Struct({ key: Jws.PrivateKey, keyId: Schema.String });\ntype Identity = typeof Identity.Type;\n\nexport const Machine = Schema.Struct({\n\tid: Schema.String,\n\tsource: Relay.IdSource,\n\t/** The user's own name for the machine; shown in place of the OS host name when set. */\n\tgivenName: Schema.optional(Schema.String),\n\t// Optional only for homes connected before identities existed; `update` gives every home one.\n\tidentity: Schema.optional(Identity),\n\tworkspaces: Schema.Record(Schema.String, Link),\n});\nexport type Machine = typeof Machine.Type;\n/** The machine as {@link update} hands it out: always with its identity. */\ntype Identified = Machine & { readonly identity: Identity };\n\nconst json = Schema.fromJsonString(Machine);\n\nclass MachineError extends Schema.TaggedError<MachineError>()(\"Machine.MachineError\", {\n\tmessage: Schema.String,\n}) {}\n\nconst file = (home: string) => `${home}/machine.json`;\n\n/** The machine as stored, or none before its first run. */\nexport const read = Effect.fn(\"Machine.read\")(function* (home: string) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst path = file(home);\n\tif (!(yield* fs.exists(path))) return Option.none<Machine>();\n\tconst text = yield* fs.readFileString(path);\n\treturn Option.some(\n\t\tyield* Schema.decodeEffect(json)(text).pipe(\n\t\t\tEffect.mapError(() => new MachineError({ message: `${path} is not a valid machine file` })),\n\t\t),\n\t);\n});\n\n// One writer at a time: creating a directory either succeeds or fails, so it serves as a lock.\nconst locked = <A, E, R>(home: string, effect: Effect.Effect<A, E, R>) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst lock = `${file(home)}.lock`;\n\t\tyield* fs.makeDirectory(home, { recursive: true });\n\t\tyield* fs.makeDirectory(lock).pipe(\n\t\t\tEffect.retry({ schedule: Schedule.spaced(\"50 millis\"), times: 100 }),\n\t\t\tEffect.mapError(() => new MachineError({ message: `${lock} is held by another process` })),\n\t\t);\n\t\treturn yield* effect.pipe(Effect.ensuring(fs.remove(lock, { recursive: true }).pipe(Effect.ignore)));\n\t});\n\nconst write = (home: string, machine: Machine) =>\n\tSchema.encodeEffect(json)(machine).pipe(Effect.flatMap((encoded) => Private.write(file(home), encoded)));\n\nconst newIdentity = Effect.gen(function* () {\n\tconst key = yield* Jws.generate();\n\treturn { key, keyId: yield* Jws.thumbprint(Jws.publicOf(key)) } satisfies Identity;\n});\n\n/** Reads, changes and writes the machine under the lock, creating its identity on first use. */\nexport const update = <E, R>(\n\thome: string,\n\toptions: { readonly machineId?: string | undefined },\n\tchange: (machine: Identified) => Effect.Effect<Identified, E, R>,\n) =>\n\tlocked(\n\t\thome,\n\t\tEffect.gen(function* () {\n\t\t\tconst existing = yield* read(home);\n\t\t\tconst machine = yield* Option.match(existing, {\n\t\t\t\tonNone: () => Effect.succeed(created(options.machineId)),\n\t\t\t\tonSome: (machine) =>\n\t\t\t\t\toptions.machineId === undefined || options.machineId === machine.id\n\t\t\t\t\t\t? Effect.succeed(machine)\n\t\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\t\tnew MachineError({\n\t\t\t\t\t\t\t\t\tmessage: `This home is machine ${machine.id}; its id can't change to ${options.machineId}. Use another --home.`,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t});\n\t\t\tconst identity = machine.identity ?? (yield* newIdentity);\n\t\t\tconst next = yield* change({ ...machine, identity });\n\t\t\tyield* write(home, next);\n\t\t\treturn next;\n\t\t}),\n\t);\n\n/** The home's identity, created with the machine on first use. */\nexport const identity = Effect.fn(\"Machine.identity\")(function* (home: string) {\n\tconst stored = yield* read(home);\n\tif (Option.isSome(stored) && stored.value.identity !== undefined) return stored.value.identity;\n\treturn (yield* update(home, {}, Effect.succeed)).identity;\n});\n\nconst created = (machineId: string | undefined): Machine =>\n\tmachineId === undefined\n\t\t? { id: uuidv7(), source: \"generated\", workspaces: {} }\n\t\t: { id: machineId, source: \"flag\", workspaces: {} };\n\n/** Validates a `--machine-id` before anything is written. */\nexport const checkId = (machineId: string | undefined) =>\n\tmachineId === undefined || Schema.is(Relay.MachineId)(machineId)\n\t\t? Effect.void\n\t\t: Effect.fail(\n\t\t\t\tnew MachineError({\n\t\t\t\t\tmessage: `--machine-id must be 1-64 lowercase letters, digits or dashes, starting with a letter or digit`,\n\t\t\t\t}),\n\t\t\t);\n\n/**\n * Forgets the link to a workspace, only while it still holds `keyId`: a reconnect that saved a new key in\n * the meantime keeps its link.\n */\nexport const removeLink = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst { [workspaceId]: link, ...workspaces } = machine.workspaces;\n\t\treturn Effect.succeed(link === undefined || link.keyId !== keyId ? machine : { ...machine, workspaces });\n\t});\n\n/** Marks the link as leaving, only while it still holds `keyId`. */\nexport const markLeaving = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst link = machine.workspaces[workspaceId];\n\t\treturn Effect.succeed(\n\t\t\tlink === undefined || link.keyId !== keyId\n\t\t\t\t? machine\n\t\t\t\t: { ...machine, workspaces: { ...machine.workspaces, [workspaceId]: { ...link, leaving: true } } },\n\t\t);\n\t});\n","import { NodeServices } from \"@effect/platform-node\";\nimport { Jws, Machine, Relay } from \"@codeworksh/schema\";\nimport { Clock, Config, Context, Duration, Effect, Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { HttpApiClient } from \"effect/http-api\";\nimport { uuidv7 } from \"uuidv7\";\nimport pkg from \"../../package.json\" with { type: \"json\" };\nimport { hostName } from \"../server/identity.ts\";\nimport * as File from \"./file.ts\";\n\n/** The relay's typed client at `url`. */\nconst at = (url: string) => HttpApiClient.make(Relay.Api, { baseUrl: url }).pipe(Effect.provide(FetchHttpClient.layer));\n\n/**\n * The relay new connects go to: `CODEWORK_RELAY_URL`, default https://relay.codework.sh. A link keeps\n * talking to the relay it was made with, whatever this says later.\n */\nexport class Client extends Context.Service<\n\tClient,\n\t{ readonly url: string; readonly api: HttpApiClient.ForApi<typeof Relay.Api> }\n>()(\"@codeworksh/cli/machine/relay/Client\") {\n\tstatic readonly layer = Layer.effect(\n\t\tClient,\n\t\tEffect.gen(function* () {\n\t\t\tconst url = yield* Config.String(\"CODEWORK_RELAY_URL\").pipe(Config.withDefault(\"https://relay.codework.sh\"));\n\t\t\treturn { url, api: yield* at(url) };\n\t\t}),\n\t);\n}\n\n/** What this machine says about itself to the relay. */\nconst describe = Effect.fn(\"Machine.describe\")(function* (machine: File.Machine) {\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\treturn {\n\t\tid: machine.id,\n\t\tsource: machine.source,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tos: process.platform,\n\t\tarch: process.arch,\n\t\tversion: pkg.version,\n\t} satisfies Relay.MachineInfo;\n});\n\n/** This machine and its workspaces, as the desktop app shows them. */\nexport const status = Effect.fn(\"Machine.status\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\tif (stored._tag === \"None\")\n\t\treturn { id: null, localHostName, givenName: null, workspaces: [] } satisfies Machine.Status;\n\tconst machine = stored.value;\n\treturn {\n\t\tid: machine.id,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tworkspaces: Object.entries(machine.workspaces).map(([id, link]) => ({\n\t\t\tid,\n\t\t\tname: link.name,\n\t\t\tkeyId: link.keyId,\n\t\t\tleaving: link.leaving === true,\n\t\t})),\n\t} satisfies Machine.Status;\n});\n\n/**\n * Names this machine for people: empty clears the name back to the OS's. The relay hears it on the\n * next heartbeat.\n */\nexport const rename = Effect.fn(\"Machine.rename\")(function* (home: string, givenName: string) {\n\tconst name = givenName.trim();\n\tyield* File.update(home, {}, ({ givenName: _previous, ...machine }) =>\n\t\tEffect.succeed(name === \"\" ? machine : { ...machine, givenName: name }),\n\t);\n\treturn yield* status(home);\n});\n\n/**\n * Pairs this home with a workspace: registers a fresh key with the relay, shows the code a member\n * approves, and polls with that key until the relay links it, then saves the link. Each workspace gets\n * its own key, and only this process can take the link: a connect that stops is never linked.\n */\nexport const connect = Effect.fn(\"Machine.connect\")(function* (options: {\n\treadonly home: string;\n\treadonly workspaceId?: string | undefined;\n\treadonly machineId?: string | undefined;\n\treadonly onCode: (userCode: string) => Effect.Effect<void>;\n}) {\n\tconst client = yield* Client;\n\tyield* File.checkId(options.machineId);\n\tconst machine = yield* File.update(options.home, { machineId: options.machineId }, Effect.succeed);\n\tconst key = yield* Jws.generate();\n\tconst keyId = yield* Jws.thumbprint(Jws.publicOf(key));\n\tconst iat = yield* Clock.currentTimeMillis;\n\tconst binding: Relay.IdentityClaims = { op: \"identity.bind\", iat, keyId };\n\tconst claims: Relay.PairingClaims = {\n\t\top: \"pairing.create\",\n\t\tiat,\n\t\tmachine: yield* describe(machine),\n\t\tworkspaceId: options.workspaceId ?? null,\n\t\tidentity: yield* Jws.sign(binding, machine.identity.key, { embed: true }),\n\t};\n\tconst pairing = yield* client.api.machine\n\t\t.pair({ payload: { jws: yield* Jws.sign(claims, key, { embed: true }) } })\n\t\t.pipe(\n\t\t\tEffect.catchTag(\"Relay.NotFound\", () =>\n\t\t\t\tEffect.fail(new Machine.ConnectError({ message: \"No such workspace\" })),\n\t\t\t),\n\t\t);\n\tyield* options.onCode(pairing.userCode);\n\n\tconst poll = Effect.gen(function* () {\n\t\tconst claims: Relay.PollClaims = { op: \"pairing.poll\", iat: yield* Clock.currentTimeMillis };\n\t\treturn yield* client.api.machine.poll({ payload: { jws: yield* Jws.sign(claims, key, { kid: keyId }) } });\n\t}).pipe(\n\t\t// A dropped request or a relay restart doesn't end the connect; the next poll asks again.\n\t\tEffect.catchTag(\"HttpClientError\", (error) =>\n\t\t\tEffect.logDebug(\"Pairing poll failed\", error).pipe(Effect.as(undefined)),\n\t\t),\n\t);\n\tlet previous = machine;\n\tconst deadline = (yield* Clock.currentTimeMillis) + pairing.expiresIn * 1000;\n\twhile ((yield* Clock.currentTimeMillis) < deadline) {\n\t\tyield* Effect.sleep(Duration.seconds(pairing.interval));\n\t\tconst status = yield* poll;\n\t\tif (status === undefined) continue;\n\t\tif (status.status !== \"approved\") {\n\t\t\tif (status.status === \"pending\") continue;\n\t\t\tif (status.status === \"expired\") break;\n\t\t\treturn yield* new Machine.ConnectError({\n\t\t\t\tmessage:\n\t\t\t\t\tstatus.status === \"declined\"\n\t\t\t\t\t\t? \"The connect was declined; run connect again for a new code\"\n\t\t\t\t\t\t: \"Another connect for this machine finished first\",\n\t\t\t});\n\t\t}\n\t\tconst { connected } = status;\n\t\t// A poll response can arrive after another connect saved a different key.\n\t\t// Observe that change under the lock, then poll again before replacing it.\n\t\tconst id = connected.workspace.id;\n\t\tconst stored = yield* File.update(options.home, {}, (current) =>\n\t\t\tEffect.succeed(\n\t\t\t\tcurrent.workspaces[id]?.keyId !== previous.workspaces[id]?.keyId\n\t\t\t\t\t? current\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t...current,\n\t\t\t\t\t\t\tworkspaces: {\n\t\t\t\t\t\t\t\t...current.workspaces,\n\t\t\t\t\t\t\t\t[connected.workspace.id]: {\n\t\t\t\t\t\t\t\t\tname: connected.workspace.name,\n\t\t\t\t\t\t\t\t\towner: connected.owner,\n\t\t\t\t\t\t\t\t\trelay: client.url,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tkeyId,\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),\n\t\t);\n\t\tif (stored.workspaces[id]?.keyId === keyId) return connected;\n\t\tprevious = stored;\n\t}\n\treturn yield* new Machine.ConnectError({ message: \"The code expired before it was approved; run connect again\" });\n});\n\n/**\n * Asks the link's relay to revoke it, signed with its own key: true once the relay confirms, or says it\n * was revoked already; false when it can't be reached in time.\n */\nconst revoke = (machineId: string, workspaceId: string, link: File.Machine[\"workspaces\"][string]) =>\n\tEffect.gen(function* () {\n\t\tconst claims: Relay.RevokeClaims = {\n\t\t\top: \"machine.revoke\",\n\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\tjti: uuidv7(),\n\t\t\tworkspaceId,\n\t\t\tmachineId,\n\t\t};\n\t\tconst api = yield* at(link.relay);\n\t\tyield* api.machine.revoke({ payload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) } });\n\t}).pipe(\n\t\t// Leave time for the local update before the desktop RPC expires.\n\t\tEffect.timeout(\"3 seconds\"),\n\t\tEffect.as(true),\n\t\tEffect.catchTag(\"Relay.MachineRevoked\", () => Effect.succeed(true)),\n\t\tEffect.catch((error) => Effect.logDebug(`Revoke at ${link.name} failed`, error).pipe(Effect.as(false))),\n\t);\n\n/**\n * One heartbeat per connected workspace, each to the relay its link was made with, all at once. A link\n * the relay refuses as revoked is removed, but only while it still holds the refused key. A leaving link\n * asks for its revoke again instead, and is removed once the relay confirms.\n */\nexport const heartbeat = Effect.fn(\"Machine.heartbeat\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tif (stored._tag === \"None\") return;\n\tconst machine = stored.value;\n\tconst info = yield* describe(machine);\n\tyield* Effect.forEach(\n\t\tObject.entries(machine.workspaces),\n\t\t([workspaceId, link]) =>\n\t\t\tlink.leaving === true\n\t\t\t\t? revoke(machine.id, workspaceId, link).pipe(\n\t\t\t\t\t\tEffect.flatMap((revoked) =>\n\t\t\t\t\t\t\trevoked ? File.removeLink(home, workspaceId, link.keyId).pipe(Effect.asVoid) : Effect.void,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Leaving ${link.name} failed`, error)),\n\t\t\t\t\t)\n\t\t\t\t: Effect.gen(function* () {\n\t\t\t\t\t\tconst api = yield* at(link.relay);\n\t\t\t\t\t\tconst claims: Relay.HeartbeatClaims = {\n\t\t\t\t\t\t\top: \"machine.heartbeat\",\n\t\t\t\t\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\t\t\t\t\tworkspaceId,\n\t\t\t\t\t\t\tmachine: info,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tyield* api.machine.heartbeat({\n\t\t\t\t\t\t\tpayload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) },\n\t\t\t\t\t\t});\n\t\t\t\t\t}).pipe(\n\t\t\t\t\t\tEffect.timeout(\"10 seconds\"),\n\t\t\t\t\t\tEffect.catchTags({\n\t\t\t\t\t\t\t\"Relay.MachineRevoked\": (revoked) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Disconnected from ${link.name}: ${revoked.message}`).pipe(\n\t\t\t\t\t\t\t\t\tEffect.andThen(File.removeLink(home, workspaceId, link.keyId)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t// Refused but not revoked, most often a clock more than a minute off: worth seeing in the log.\n\t\t\t\t\t\t\t\"Relay.Unauthorized\": (refused) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Heartbeat to ${link.name} refused: ${refused.message}`),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Heartbeat to ${link.name} failed`, error)),\n\t\t\t\t\t),\n\t\t{ concurrency: \"unbounded\", discard: true },\n\t);\n});\n\n/**\n * Leaves a workspace: asks the link's relay to revoke it, then forgets it locally. When the relay can't\n * confirm, the link is kept as leaving, with its key, and each heartbeat asks again until it does; the\n * relay still lists it until then. `revoked` says whether it confirmed now.\n */\nexport const disconnect = Effect.fn(\"Machine.disconnect\")(function* (\n\thome: string,\n\tworkspaceId: string,\n\texpectedKeyId?: string,\n) {\n\tconst stored = yield* File.read(home);\n\tconst link = stored._tag === \"Some\" ? stored.value.workspaces[workspaceId] : undefined;\n\tif (stored._tag === \"None\" || link === undefined) {\n\t\treturn yield* new Machine.ConnectError({ message: `This machine is not connected to workspace ${workspaceId}` });\n\t}\n\tif (expectedKeyId !== undefined && link.keyId !== expectedKeyId)\n\t\treturn yield* new Machine.ConnectError({ message: \"This machine link has changed\" });\n\tconst revoked = yield* revoke(stored.value.id, workspaceId, link);\n\tyield* revoked ? File.removeLink(home, workspaceId, link.keyId) : File.markLeaving(home, workspaceId, link.keyId);\n\treturn { workspace: link.name, revoked };\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAM,OAAO,OAAO,OAAO;CAC1B,MAAM,OAAO;CACb,OAAO,OAAO,OAAO;EAAE,IAAI,OAAO;EAAQ,MAAM,OAAO,OAAO,OAAO,MAAM;CAAE,CAAC;;CAE9E,OAAO,OAAO;CACd,KAAKA;CACL,OAAO,OAAO;;CAEd,SAAS,OAAO,YAAY,OAAO,OAAO;AAC3C,CAAC;;AAGD,MAAM,WAAW,OAAO,OAAO;CAAE,KAAKA;CAAgB,OAAO,OAAO;AAAO,CAAC;AAG5E,MAAa,UAAU,OAAO,OAAO;CACpC,IAAI,OAAO;CACX,QAAQC;;CAER,WAAW,OAAO,SAAS,OAAO,MAAM;CAExC,UAAU,OAAO,SAAS,QAAQ;CAClC,YAAY,OAAO,OAAO,OAAO,QAAQ,IAAI;AAC9C,CAAC;AAKD,MAAM,OAAO,OAAO,eAAe,OAAO;AAE1C,IAAM,eAAN,cAA2B,OAAO,YAA0B,CAAC,CAAC,wBAAwB,EACrF,SAAS,OAAO,OACjB,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAM,QAAQ,SAAiB,GAAG,KAAK;;AAGvC,MAAa,OAAO,OAAO,GAAG,cAAc,CAAC,CAAC,WAAW,MAAc;CACtE,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,KAAK,IAAI;CACtB,IAAI,EAAE,OAAO,GAAG,OAAO,IAAI,IAAI,OAAO,OAAO,KAAc;CAC3D,MAAM,OAAO,OAAO,GAAG,eAAe,IAAI;CAC1C,OAAO,OAAO,KACb,OAAO,OAAO,aAAa,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KACtC,OAAO,eAAe,IAAI,aAAa,EAAE,SAAS,GAAG,KAAK,8BAA8B,CAAC,CAAC,CAC3F,CACD;AACD,CA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M,CAAC,EAAE,EACxE,CAAC;CACF,CAAC,CAAC,CAAC,KACF,OAAO,QAAQ,YAAY,GAC3B,OAAO,UAAU;EAChB,yBAAyB,YACxB,OAAO,WAAW,qBAAqB,KAAK,KAAK,IAAI,QAAQ,SAAS,CAAC,CAAC,KACvE,OAAO,QAAQE,WAAgB,MAAM,aAAa,KAAK,KAAK,CAAC,CAC9D;EAED,uBAAuB,YACtB,OAAO,WAAW,gBAAgB,KAAK,KAAK,YAAY,QAAQ,SAAS;CAC3E,CAAC,GACD,OAAO,OAAO,UAAU,OAAO,SAAS,gBAAgB,KAAK,KAAK,UAAU,KAAK,CAAC,CACnF,GACH;EAAE,aAAa;EAAa,SAAS;CAAK,CAC3C;AACD,CAAC;;;;;;AAOD,MAAa,aAAa,OAAO,GAAG,oBAAoB,CAAC,CAAC,WACzD,MACA,aACA,eACC;CACD,MAAM,SAAS,OAAOR,KAAU,IAAI;CACpC,MAAM,OAAO,OAAO,SAAS,SAAS,OAAO,MAAM,WAAW,eAAe,KAAA;CAC7E,IAAI,OAAO,SAAS,UAAU,SAAS,KAAA,GACtC,OAAO,OAAO,IAAIO,aAAqB,EAAE,SAAS,8CAA8C,cAAc,CAAC;CAEhH,IAAI,kBAAkB,KAAA,KAAa,KAAK,UAAU,eACjD,OAAO,OAAO,IAAIA,aAAqB,EAAE,SAAS,gCAAgC,CAAC;CACpF,MAAM,UAAU,OAAO,OAAO,OAAO,MAAM,IAAI,aAAa,IAAI;CAChE,OAAO,UAAUC,WAAgB,MAAM,aAAa,KAAK,KAAK,IAAIC,YAAiB,MAAM,aAAa,KAAK,KAAK;CAChH,OAAO;EAAE,WAAW,KAAK;EAAM;CAAQ;AACxC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, m as writeOut } from "./error-ippxl2z7.mjs";
|
|
2
2
|
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
-
import { a as resolveTarget, c as withPluginsLock, i as readPlugins, l as writePlugins, o as spellings, r as matching, t as identify } from "./settings-
|
|
3
|
+
import { a as resolveTarget, c as withPluginsLock, i as readPlugins, l as writePlugins, o as spellings, r as matching, t as identify } from "./settings-CyvcSIcs.mjs";
|
|
4
4
|
import { Effect, FileSystem, Option, Path } from "effect";
|
|
5
5
|
import { Global } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/plugin/remove.ts
|
|
@@ -34,4 +34,4 @@ var remove_default = handler(Cmd.commands.plugin.commands.remove, Effect.fn("CLI
|
|
|
34
34
|
//#endregion
|
|
35
35
|
export { remove_default as default };
|
|
36
36
|
|
|
37
|
-
//# sourceMappingURL=remove-
|
|
37
|
+
//# sourceMappingURL=remove-CReTs9O7.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-
|
|
1
|
+
{"version":3,"file":"remove-CReTs9O7.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/plugin/remove.ts"],"sourcesContent":["import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, FileSystem, Option, Path } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tidentify,\n\tmatching,\n\treadPlugins,\n\tresolveTarget,\n\tspellings,\n\twithPluginsLock,\n\twritePlugins,\n} from \"./settings.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.plugin.commands.remove,\n\tEffect.fn(\"CLI.plugin.remove\")(function* ({ package: reference, global: userWide }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst shared = yield* Cmd.spec;\n\t\t\tconst path = yield* Path.Path;\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\t\t\tconst target = yield* resolveTarget(shared, userWide, undefined, false);\n\t\t\t// Removing from a directory that is not a project is a read-only no-op. In particular, it\n\t\t\t// must not create the marker that would make this directory shadow a real project later.\n\t\t\tif (!(yield* fs.exists(path.dirname(target.path)))) {\n\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst spelled = yield* spellings(reference, path.resolve(\".\"));\n\t\t\tyield* withPluginsLock(\n\t\t\t\ttarget.path,\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { source, plugins } = yield* readPlugins(target.path);\n\t\t\t\t\t// Both the module entry and any configuration written against it: the package it was\n\t\t\t\t\t// added as, the path or version it was written with, and the ID it declares all name\n\t\t\t\t\t// the one plugin being removed.\n\t\t\t\t\tconst entries = yield* identify(plugins, target.path, paths.cache);\n\t\t\t\t\tconst selected = matching(entries, spelled);\n\t\t\t\t\tconst kept = entries.filter((entry) => !selected.has(entry)).map((entry) => entry.value);\n\t\t\t\t\tif (kept.length === plugins.length) {\n\t\t\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tyield* writePlugins(target.path, source, kept);\n\t\t\t\t\tconst dropped = plugins.length - kept.length;\n\t\t\t\t\tyield* writeOut(\n\t\t\t\t\t\t`Removed ${dropped} ${dropped === 1 ? \"entry\" : \"entries\"} for \"${reference}\" from ${target.path}\\n`,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,iBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,QAC7B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,SAAS,WAAW,QAAQ,YAAY;CAqCnF,OAAO,OApCS,OAAO,IAAI,aAAa;EACvC,MAAM,SAAS,OAAO,IAAI;EAC1B,MAAM,OAAO,OAAO,KAAK;EACzB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s";
|
|
3
|
-
import { r as write, t as locked } from "./jsonc-
|
|
4
|
-
import { a as readServers, n as configured } from "./shared-
|
|
3
|
+
import { r as write, t as locked } from "./jsonc-CXTpkzZe.mjs";
|
|
4
|
+
import { a as readServers, n as configured } from "./shared-BzfKCE2E.mjs";
|
|
5
5
|
import { Effect, FileSystem } from "effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/mcp/remove.ts
|
|
7
7
|
var remove_default = handler(Cmd.commands.mcp.commands.remove, Effect.fn("CLI.mcp.remove")(function* ({ name, local }) {
|
|
@@ -23,4 +23,4 @@ var remove_default = handler(Cmd.commands.mcp.commands.remove, Effect.fn("CLI.mc
|
|
|
23
23
|
//#endregion
|
|
24
24
|
export { remove_default as default };
|
|
25
25
|
|
|
26
|
-
//# sourceMappingURL=remove-
|
|
26
|
+
//# sourceMappingURL=remove-W7QswkaH.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-
|
|
1
|
+
{"version":3,"file":"remove-W7QswkaH.mjs","names":["Runtime.handler","Jsonc.locked","Jsonc.write"],"sources":["../../src/cli/cmd/handlers/mcp/remove.ts"],"sourcesContent":["import { Effect, FileSystem } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { InvalidInputError, reportFailure } from \"../../../error.ts\";\nimport * as Jsonc from \"../../../jsonc.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { configured, readServers } from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.mcp.commands.remove,\n\tEffect.fn(\"CLI.mcp.remove\")(function* ({ name, local }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst { user, project, servers } = yield* configured();\n\t\t\tconst path = local ? project : user;\n\t\t\tconst level = local ? \"project\" : \"user\";\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\t// No file, nothing to remove: locking it would make its directory, and a `.codework/` here.\n\t\t\tconst removed =\n\t\t\t\t(yield* fs.exists(path)) &&\n\t\t\t\t(yield* Jsonc.locked(\n\t\t\t\t\tpath,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst { source, servers } = yield* readServers(path);\n\t\t\t\t\t\tif (servers[name] === undefined) return false;\n\t\t\t\t\t\tyield* Jsonc.write(path, source, [\"mcpServers\", name], undefined);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}),\n\t\t\t\t));\n\t\t\tif (removed) return yield* writeOut(`Removed ${level} MCP server \"${name}\" from ${path}.\\n`);\n\t\t\tconst other = servers.find((server) => server.name === name && server.file !== path);\n\t\t\tconst hint =\n\t\t\t\tother === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` It is defined in ${other.file}; ${other.file === project ? \"use --local\" : \"omit --local\"}.`;\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: `no ${level} MCP server named \"${name}\" in ${path}.${hint}`,\n\t\t\t});\n\t\t});\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,iBAAeA,QACd,IAAI,SAAS,IAAI,SAAS,QAC1B,OAAO,GAAG,gBAAgB,CAAC,CAAC,WAAW,EAAE,MAAM,SAAS;CA4BvD,OAAO,OA3BS,OAAO,IAAI,aAAa;EACvC,MAAM,EAAE,MAAM,SAAS,YAAY,OAAO,WAAW;EACrD,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,QAAQ,QAAQ,YAAY;EAclC,KAVE,QAAO,OAHS,WAAW,WAAA,CAGjB,OAAO,IAAI,OACrB,OAAOC,OACP,MACA,OAAO,IAAI,aAAa;GACvB,MAAM,EAAE,QAAQ,YAAY,OAAO,YAAY,IAAI;GACnD,IAAI,QAAQ,UAAU,KAAA,GAAW,OAAO;GACxC,OAAOC,MAAY,MAAM,QAAQ,CAAC,cAAc,IAAI,GAAG,KAAA,CAAS;GAChE,OAAO;EACR,CAAC,CACF,IACY,OAAO,OAAO,SAAS,WAAW,MAAM,eAAe,KAAK,SAAS,KAAK,IAAI;EAC3F,MAAM,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,QAAQ,OAAO,SAAS,IAAI;EACnF,MAAM,OACL,UAAU,KAAA,IACP,KACA,qBAAqB,MAAM,KAAK,IAAI,MAAM,SAAS,UAAU,gBAAgB,eAAe;EAChG,OAAO,OAAO,IAAI,kBAAkB,EACnC,SAAS,MAAM,MAAM,qBAAqB,KAAK,OAAO,KAAK,GAAG,OAC/D,CAAC;CACF,CACoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as reportFailure, m as writeOut } from "./error-ippxl2z7.mjs";
|
|
2
2
|
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
3
|
import { r as options } from "./service-CRnqz89w.mjs";
|
|
4
|
-
import { n as ensure, r as stop } from "./discovery-
|
|
4
|
+
import { n as ensure, r as stop } from "./discovery-RAocoXhu.mjs";
|
|
5
5
|
import { Effect } from "effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/service/restart.ts
|
|
7
7
|
var restart_default = handler(Cmd.commands.service.commands.restart, Effect.fn("CLI.service.restart")(function* ({ host, port }) {
|
|
@@ -19,4 +19,4 @@ var restart_default = handler(Cmd.commands.service.commands.restart, Effect.fn("
|
|
|
19
19
|
//#endregion
|
|
20
20
|
export { restart_default as default };
|
|
21
21
|
|
|
22
|
-
//# sourceMappingURL=restart-
|
|
22
|
+
//# sourceMappingURL=restart-B1CsEzlL.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restart-
|
|
1
|
+
{"version":3,"file":"restart-B1CsEzlL.mjs","names":["Runtime.handler","options","Service.options","Discovery.stop","Discovery.ensure"],"sources":["../../src/cli/cmd/handlers/service/restart.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Discovery from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.restart,\n\tEffect.fn(\"CLI.service.restart\")(function* ({ host, port }) {\n\t\tconst options = yield* Service.options(yield* Cmd.spec, { host, port });\n\t\tyield* Discovery.stop(options.home);\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,kBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,SAC9B,OAAO,GAAG,qBAAqB,CAAC,CAAC,WAAW,EAAE,MAAM,QAAQ;CAC3D,MAAMC,YAAU,OAAOC,QAAgB,OAAO,IAAI,MAAM;EAAE;EAAM;CAAK,CAAC;CACtE,OAAOC,KAAeF,UAAQ,IAAI;CAClC,MAAM,SAAS,OAAOG,OAAiB;EAAE,GAAGH;EAAS,SAAS;CAAK,CAAC;CACpE,OAAO,SAAS,GAAG,OAAO,IAAI,GAAG;AAClC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
|
|
@@ -2,8 +2,8 @@ import { $ as sign, A as decode, B as ticketsPath, C as Current, D as Unauthoriz
|
|
|
2
2
|
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
3
|
import { t as harnessOptions } from "./harness-6d8TlAVk.mjs";
|
|
4
4
|
import { a as register, o as write, r as log } from "./registration-C6yiv31r.mjs";
|
|
5
|
-
import { i as layer$9, t as Service$5 } from "./identity-
|
|
6
|
-
import { a as rename, c as read, i as heartbeat, n as connect, o as status, r as disconnect, s as identity, t as Client } from "./relay-
|
|
5
|
+
import { i as layer$9, t as Service$5 } from "./identity-Dps5qkHz.mjs";
|
|
6
|
+
import { a as rename, c as read, i as heartbeat, n as connect, o as status, r as disconnect, s as identity, t as Client } from "./relay-UTS7NtSR.mjs";
|
|
7
7
|
import { Cause, Clock, Config, Context, Data, DateTime, Deferred, Duration, Effect, Exit, Fiber, FileSystem, Layer, Logger, Option, Path, Predicate, PubSub, Queue, Ref, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
|
|
8
8
|
import { Model } from "@codeworksh/aikit";
|
|
9
9
|
import { Headers, HttpRouter, HttpServer, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
@@ -1867,4 +1867,4 @@ var serve_default = handler(Cmd.commands.serve, Effect.fn("CLI.serve", { level:
|
|
|
1867
1867
|
//#endregion
|
|
1868
1868
|
export { serve_default as default };
|
|
1869
1869
|
|
|
1870
|
-
//# sourceMappingURL=serve-
|
|
1870
|
+
//# sourceMappingURL=serve-DGQOucNu.mjs.map
|