@codeworksh/cli 0.9.0-canary.167.1.g6ddcc8db → 0.9.0-canary.168.1.ge6d0f923
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-CmtcmhuX.mjs → acp-C2GCSrJd.mjs} +6 -5
- package/acp-C2GCSrJd.mjs.map +1 -0
- package/{add-Bmholf85.mjs → add-Be7-HfBj.mjs} +2 -2
- package/{add-Bmholf85.mjs.map → add-Be7-HfBj.mjs.map} +1 -1
- package/{add-Ct20ZUEC.mjs → add-D2ly9-x3.mjs} +3 -3
- package/{add-Ct20ZUEC.mjs.map → add-D2ly9-x3.mjs.map} +1 -1
- package/{catalog-BJScfJLW.mjs → catalog-Dzi9__Rq.mjs} +2 -2
- package/{catalog-BJScfJLW.mjs.map → catalog-Dzi9__Rq.mjs.map} +1 -1
- package/categories-DYD_3Pt8.mjs +19 -0
- package/categories-DYD_3Pt8.mjs.map +1 -0
- package/{check-ki1450h-.mjs → check-DzxfN43i.mjs} +2 -2
- package/{check-ki1450h-.mjs.map → check-DzxfN43i.mjs.map} +1 -1
- package/{connect-KX-A0EzQ.mjs → connect-D4w0dmRc.mjs} +5 -5
- package/{connect-KX-A0EzQ.mjs.map → connect-D4w0dmRc.mjs.map} +1 -1
- package/{control-Cotypk4e.mjs → control-CFQeKIKx.mjs} +4 -4
- package/{control-Cotypk4e.mjs.map → control-CFQeKIKx.mjs.map} +1 -1
- package/create-Bt56MHKu.mjs +35 -0
- package/create-Bt56MHKu.mjs.map +1 -0
- package/{devices-BcuQ11QF.mjs → devices-DNzXKhNy.mjs} +3 -3
- package/{devices-BcuQ11QF.mjs.map → devices-DNzXKhNy.mjs.map} +1 -1
- package/disconnect-CHEHx_ic.mjs +2 -0
- package/{disconnect-CCI1DLJ0.mjs → disconnect-CXha4LTk.mjs} +4 -4
- package/{disconnect-CCI1DLJ0.mjs.map → disconnect-CXha4LTk.mjs.map} +1 -1
- package/disconnect-Cx0sydNl.mjs +19 -0
- package/disconnect-Cx0sydNl.mjs.map +1 -0
- package/discover-wWs8qDQd.mjs +35 -0
- package/discover-wWs8qDQd.mjs.map +1 -0
- package/{discovery-D2ftXE5a.mjs → discovery-C-ploGdg.mjs} +2 -2
- package/{discovery-D2ftXE5a.mjs.map → discovery-C-ploGdg.mjs.map} +1 -1
- package/{fork-DkYRL_nQ.mjs → fork-TUz05qSe.mjs} +3 -3
- package/{fork-DkYRL_nQ.mjs.map → fork-TUz05qSe.mjs.map} +1 -1
- package/{identity-Llk4K_8w.mjs → identity-Cjr43dhQ.mjs} +2 -2
- package/{identity-Llk4K_8w.mjs.map → identity-Cjr43dhQ.mjs.map} +1 -1
- package/index.mjs +49 -39
- package/index.mjs.map +1 -1
- package/{install-hs3tvWLA.mjs → install-BtoWHZoI.mjs} +2 -2
- package/{install-hs3tvWLA.mjs.map → install-BtoWHZoI.mjs.map} +1 -1
- package/{link-BzFGtDKJ.mjs → link-Cd6T22_n.mjs} +3 -3
- package/{link-BzFGtDKJ.mjs.map → link-Cd6T22_n.mjs.map} +1 -1
- package/{list-sLzs2Y7w.mjs → list-Bn5CvS1y.mjs} +3 -3
- package/{list-sLzs2Y7w.mjs.map → list-Bn5CvS1y.mjs.map} +1 -1
- package/{list-D1c5uzCc.mjs → list-CdS1_gFF.mjs} +2 -2
- package/{list-D1c5uzCc.mjs.map → list-CdS1_gFF.mjs.map} +1 -1
- package/list-D6ABpoQC.mjs +27 -0
- package/list-D6ABpoQC.mjs.map +1 -0
- package/{list-DhL_z5v2.mjs → list-DAA92mUG.mjs} +3 -3
- package/{list-DhL_z5v2.mjs.map → list-DAA92mUG.mjs.map} +1 -1
- package/{list-Dt0_ol5P.mjs → list-MiZ6rD_w.mjs} +3 -3
- package/{list-Dt0_ol5P.mjs.map → list-MiZ6rD_w.mjs.map} +1 -1
- package/{login-BxiN8frI.mjs → login-C_tBeHg6.mjs} +3 -3
- package/{login-BxiN8frI.mjs.map → login-C_tBeHg6.mjs.map} +1 -1
- package/login-DnOTWBy8.mjs +26 -0
- package/login-DnOTWBy8.mjs.map +1 -0
- package/{login-S-2L5YYB.mjs → login-Q_ezdpon.mjs} +3 -3
- package/{login-S-2L5YYB.mjs.map → login-Q_ezdpon.mjs.map} +1 -1
- package/{logout-BeMvfZkG.mjs → logout-BjL1W-0I.mjs} +3 -3
- package/{logout-BeMvfZkG.mjs.map → logout-BjL1W-0I.mjs.map} +1 -1
- package/{logout-CKcRACIf.mjs → logout-E_dRjl1L.mjs} +3 -3
- package/{logout-CKcRACIf.mjs.map → logout-E_dRjl1L.mjs.map} +1 -1
- package/package-BsCtRg3n.mjs +6 -0
- package/package-BsCtRg3n.mjs.map +1 -0
- package/package.json +4 -4
- package/{pair-BhGzBBV8.mjs → pair-BBneOJZJ.mjs} +3 -3
- package/{pair-BhGzBBV8.mjs.map → pair-BBneOJZJ.mjs.map} +1 -1
- package/{providers-DdBYxi9t.mjs → providers-BYnMGDs7.mjs} +3 -3
- package/{providers-DdBYxi9t.mjs.map → providers-BYnMGDs7.mjs.map} +1 -1
- package/reconnect-BKpud0ma.mjs +2 -0
- package/{refresh-BgQfD2zv.mjs → refresh-CvE_f1Fa.mjs} +3 -3
- package/{refresh-BgQfD2zv.mjs.map → refresh-CvE_f1Fa.mjs.map} +1 -1
- package/{refresh-Cy6abMk_.mjs → refresh-Dy9kI2El.mjs} +3 -3
- package/{refresh-Cy6abMk_.mjs.map → refresh-Dy9kI2El.mjs.map} +1 -1
- package/{relay-BmHXs1yg.mjs → relay-CO46Wh73.mjs} +3 -3
- package/{relay-BmHXs1yg.mjs.map → relay-CO46Wh73.mjs.map} +1 -1
- package/{relink-Dxg1kstB.mjs → relink-DxftNq9n.mjs} +3 -3
- package/{relink-Dxg1kstB.mjs.map → relink-DxftNq9n.mjs.map} +1 -1
- package/{reload-CUyG343t.mjs → reload-DRp3UlHQ.mjs} +3 -3
- package/{reload-CUyG343t.mjs.map → reload-DRp3UlHQ.mjs.map} +1 -1
- package/remove-Bad0ln8h.mjs +22 -0
- package/remove-Bad0ln8h.mjs.map +1 -0
- package/{remove-BXmNNX2f.mjs → remove-C0e5sHqb.mjs} +3 -3
- package/{remove-BXmNNX2f.mjs.map → remove-C0e5sHqb.mjs.map} +1 -1
- package/{remove-CJ__oofS.mjs → remove-CdcoheOp.mjs} +2 -2
- package/{remove-CJ__oofS.mjs.map → remove-CdcoheOp.mjs.map} +1 -1
- package/{restart-CMDZZJ4N.mjs → restart-CvkGtFq2.mjs} +4 -4
- package/{restart-CMDZZJ4N.mjs.map → restart-CvkGtFq2.mjs.map} +1 -1
- package/{revoke-DigrkMoL.mjs → revoke-DoMHa1vL.mjs} +3 -3
- package/{revoke-DigrkMoL.mjs.map → revoke-DoMHa1vL.mjs.map} +1 -1
- package/{run-BN0xfxh_.mjs → run-n_t47yPB.mjs} +8 -5
- package/run-n_t47yPB.mjs.map +1 -0
- package/{runtime-Q4G4z83G.mjs → runtime-CyXV7HH_.mjs} +152 -9
- package/runtime-CyXV7HH_.mjs.map +1 -0
- package/{serve-CfjS09-r.mjs → serve-BaNbYK1f.mjs} +27 -11
- package/serve-BaNbYK1f.mjs.map +1 -0
- package/service-CA6VAOdR.mjs +1652 -0
- package/service-CA6VAOdR.mjs.map +1 -0
- package/{service-B0O4PjbL.mjs → service-YVNwFMNf.mjs} +2 -2
- package/{service-B0O4PjbL.mjs.map → service-YVNwFMNf.mjs.map} +1 -1
- package/shared-CA47qIai.mjs +212 -0
- package/shared-CA47qIai.mjs.map +1 -0
- package/{shared-C2sMimyK.mjs → shared-CDJQxUb9.mjs} +4 -4
- package/{shared-C2sMimyK.mjs.map → shared-CDJQxUb9.mjs.map} +1 -1
- package/{shared-C4j4rGe4.mjs → shared-D_MVXtOf.mjs} +3 -3
- package/{shared-C4j4rGe4.mjs.map → shared-D_MVXtOf.mjs.map} +1 -1
- package/{start-DbCTFswo.mjs → start-D3lqmljh.mjs} +4 -4
- package/{start-DbCTFswo.mjs.map → start-D3lqmljh.mjs.map} +1 -1
- package/{status-CR_E6RiI.mjs → status-BoTZqXwd.mjs} +3 -3
- package/{status-CR_E6RiI.mjs.map → status-BoTZqXwd.mjs.map} +1 -1
- package/{status-Dcbdl6Sv.mjs → status-P0hOBrM6.mjs} +4 -4
- package/{status-Dcbdl6Sv.mjs.map → status-P0hOBrM6.mjs.map} +1 -1
- package/status-tYcs05sk.mjs +23 -0
- package/status-tYcs05sk.mjs.map +1 -0
- package/{stop-ML5Yeo_s.mjs → stop-BuDB-rqB.mjs} +4 -4
- package/{stop-ML5Yeo_s.mjs.map → stop-BuDB-rqB.mjs.map} +1 -1
- package/{update-BK_LdUUv.mjs → update-mWc5cR7q.mjs} +2 -2
- package/{update-BK_LdUUv.mjs.map → update-mWc5cR7q.mjs.map} +1 -1
- package/acp-CmtcmhuX.mjs.map +0 -1
- package/disconnect-DKi3PmC2.mjs +0 -2
- package/package-D_TWKUKk.mjs +0 -6
- package/package-D_TWKUKk.mjs.map +0 -1
- package/reconnect-DgUK2fwU.mjs +0 -2
- package/run-BN0xfxh_.mjs.map +0 -1
- package/runtime-Q4G4z83G.mjs.map +0 -1
- package/serve-CfjS09-r.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-
|
|
1
|
+
{"version":3,"file":"list-MiZ6rD_w.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,SAAS,CAAC;GAChC,MAAM,YAAY,MAAM,QAAQ,SAAS,KAAK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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, g as make, m as writeOut, t as InvalidInputError } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { a as oauthProviderLabel, i as makeOps, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { a as oauthProviderLabel, i as makeOps, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-CDJQxUb9.mjs";
|
|
4
4
|
import { Effect, Option } from "effect";
|
|
5
5
|
import { formatOAuthSummary, oauthLoginIssue, oauthNotice } from "@codeworksh/aikit/oauth/summary";
|
|
6
6
|
//#region src/cli/cmd/handlers/auth/login.ts
|
|
@@ -42,4 +42,4 @@ var login_default = handler(Cmd.commands.auth.commands.login, Effect.fn("CLI.aut
|
|
|
42
42
|
//#endregion
|
|
43
43
|
export { login_default as default };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=login-
|
|
45
|
+
//# sourceMappingURL=login-C_tBeHg6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-
|
|
1
|
+
{"version":3,"file":"login-C_tBeHg6.mjs","names":["Runtime.handler","Client.make"],"sources":["../../src/cli/cmd/handlers/auth/login.ts"],"sourcesContent":["import { formatOAuthSummary, oauthLoginIssue, oauthNotice } from \"@codeworksh/aikit/oauth/summary\";\nimport { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { InvalidInputError, reportFailure } from \"../../../error.ts\";\nimport { writeError, writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tassertServerScope,\n\tattempt,\n\tClient,\n\tlocalOps,\n\tmakeOps,\n\toauthProviderLabel,\n\tselectProvider,\n\twithServer,\n\ttype LoginOptions,\n} from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.auth.commands.login,\n\tEffect.fn(\"CLI.auth.login\")(function* ({\n\t\tserver,\n\t\topenaiCodex,\n\t\tgithubCopilot,\n\t\tauthFile,\n\t\tbrowser,\n\t\tdevice,\n\t\tenterprise,\n\t\tenableModels,\n\t\tjson,\n\t}) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst provider = yield* selectProvider({ openaiCodex, githubCopilot });\n\t\t\tconst issue = oauthLoginIssue(provider, {\n\t\t\t\tdevice,\n\t\t\t\tenableModels,\n\t\t\t\t...(Option.isSome(enterprise) && { enterprise: enterprise.value }),\n\t\t\t});\n\t\t\tif (issue !== undefined) return yield* new InvalidInputError({ message: issue });\n\n\t\t\tconst name = oauthProviderLabel(provider);\n\t\t\tconst options: LoginOptions = { browser, device, enterprise, enableModels };\n\n\t\t\tif (Option.isSome(server)) {\n\t\t\t\tyield* assertServerScope(authFile);\n\t\t\t\treturn yield* withServer(\n\t\t\t\t\tserver.value,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst rpc = yield* Client.make;\n\t\t\t\t\t\t// The browser callback and the device prompt both need this\n\t\t\t\t\t\t// terminal, so the login runs here and only the result travels.\n\t\t\t\t\t\tconst { wire } = yield* attempt(`${name} login failed`, () =>\n\t\t\t\t\t\t\tmakeOps(provider, { persist: false }).login(options),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst info = yield* rpc[\"auth.save\"]({ credentials: wire });\n\t\t\t\t\t\tyield* writeError(`${oauthNotice(\"saved\", provider, \"the server\")}\\n`);\n\t\t\t\t\t\tyield* writeOut(formatOAuthSummary(info, { json }));\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst ops = yield* localOps(provider, authFile);\n\t\t\tconst { summary } = yield* attempt(`${name} login failed`, () => ops.login(options));\n\t\t\tyield* writeError(`${oauthNotice(\"saved\", provider, ops.path)}\\n`);\n\t\t\tyield* writeOut(formatOAuthSummary(summary, { json }));\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAkBA,IAAA,gBAAeA,QACd,IAAI,SAAS,KAAK,SAAS,OAC3B,OAAO,GAAG,gBAAgB,CAAC,CAAC,WAAW,EACtC,QACA,aACA,eACA,UACA,SACA,QACA,YACA,cACA,QACE;CAqCF,OAAO,OApCS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,eAAe;GAAE;GAAa;EAAc,CAAC;EACrE,MAAM,QAAQ,gBAAgB,UAAU;GACvC;GACA;GACA,GAAI,OAAO,OAAO,UAAU,KAAK,EAAE,YAAY,WAAW,MAAM;EACjE,CAAC;EACD,IAAI,UAAU,KAAA,GAAW,OAAO,OAAO,IAAI,kBAAkB,EAAE,SAAS,MAAM,CAAC;EAE/E,MAAM,OAAO,mBAAmB,QAAQ;EACxC,MAAM,UAAwB;GAAE;GAAS;GAAQ;GAAY;EAAa;EAE1E,IAAI,OAAO,OAAO,MAAM,GAAG;GAC1B,OAAO,kBAAkB,QAAQ;GACjC,OAAO,OAAO,WACb,OAAO,OACP,OAAO,IAAI,aAAa;IACvB,MAAM,MAAM,OAAOC;IAGnB,MAAM,EAAE,SAAS,OAAO,QAAQ,GAAG,KAAK,sBACvC,QAAQ,UAAU,EAAE,SAAS,MAAM,CAAC,CAAC,CAAC,MAAM,OAAO,CACpD;IACA,MAAM,OAAO,OAAO,IAAI,YAAY,CAAC,EAAE,aAAa,KAAK,CAAC;IAC1D,OAAO,WAAW,GAAG,YAAY,SAAS,UAAU,YAAY,EAAE,GAAG;IACrE,OAAO,SAAS,mBAAmB,MAAM,EAAE,KAAK,CAAC,CAAC;GACnD,CAAC,CACF;EACD;EAEA,MAAM,MAAM,OAAO,SAAS,UAAU,QAAQ;EAC9C,MAAM,EAAE,YAAY,OAAO,QAAQ,GAAG,KAAK,sBAAsB,IAAI,MAAM,OAAO,CAAC;EACnF,OAAO,WAAW,GAAG,YAAY,SAAS,UAAU,IAAI,IAAI,EAAE,GAAG;EACjE,OAAO,SAAS,mBAAmB,SAAS,EAAE,KAAK,CAAC,CAAC;CACtD,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { a as reportFailure, m as writeOut } from "./error-BsI8iNna.mjs";
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { i as withConnectApi, n as formatConnectionLine, r as printJson, t as authenticateConnection } from "./shared-CA47qIai.mjs";
|
|
4
|
+
import { Effect, Option } from "effect";
|
|
5
|
+
//#region src/cli/cmd/handlers/connect/login.ts
|
|
6
|
+
var login_default = handler(Cmd.commands.connect.commands.login, Effect.fn("CLI.connect.login")(function* ({ ref, apiKey, device, enterprise, browser, server, json }) {
|
|
7
|
+
return yield* withConnectApi(server, (api) => Effect.gen(function* () {
|
|
8
|
+
const existing = yield* api.get(ref);
|
|
9
|
+
const spec = (yield* api.catalog({})).connectors.find((c) => c.id === existing.connectorId);
|
|
10
|
+
const updated = yield* authenticateConnection(api, existing, spec, {
|
|
11
|
+
apiKey: Option.getOrUndefined(apiKey),
|
|
12
|
+
device,
|
|
13
|
+
enterpriseUrl: Option.getOrUndefined(enterprise),
|
|
14
|
+
browser
|
|
15
|
+
});
|
|
16
|
+
if (json) {
|
|
17
|
+
yield* printJson(updated);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
yield* writeOut(`Authenticated ${formatConnectionLine(updated)}\n`);
|
|
21
|
+
})).pipe(Effect.catch(reportFailure));
|
|
22
|
+
}));
|
|
23
|
+
//#endregion
|
|
24
|
+
export { login_default as default };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=login-DnOTWBy8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-DnOTWBy8.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/connect/login.ts"],"sourcesContent":["import { Effect, Option } 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 { authenticateConnection, formatConnectionLine, printJson, withConnectApi } from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.connect.commands.login,\n\tEffect.fn(\"CLI.connect.login\")(function* ({ ref, apiKey, device, enterprise, browser, server, json }) {\n\t\tconst program = withConnectApi(server, (api) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst existing = yield* api.get(ref);\n\t\t\t\tconst cat = yield* api.catalog({});\n\t\t\t\tconst spec = cat.connectors.find((c) => c.id === existing.connectorId);\n\t\t\t\tconst updated = yield* authenticateConnection(api, existing, spec, {\n\t\t\t\t\tapiKey: Option.getOrUndefined(apiKey),\n\t\t\t\t\tdevice,\n\t\t\t\t\tenterpriseUrl: Option.getOrUndefined(enterprise),\n\t\t\t\t\tbrowser,\n\t\t\t\t});\n\t\t\t\tif (json) {\n\t\t\t\t\tyield* printJson(updated);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tyield* writeOut(`Authenticated ${formatConnectionLine(updated)}\\n`);\n\t\t\t}),\n\t\t);\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;AAOA,IAAA,gBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,OAC9B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,KAAK,QAAQ,QAAQ,YAAY,SAAS,QAAQ,QAAQ;CAmBrG,OAAO,OAlBS,eAAe,SAAS,QACvC,OAAO,IAAI,aAAa;EACvB,MAAM,WAAW,OAAO,IAAI,IAAI,GAAG;EAEnC,MAAM,QAAO,OADM,IAAI,QAAQ,CAAC,CAAC,EAAA,CAChB,WAAW,MAAM,MAAM,EAAE,OAAO,SAAS,WAAW;EACrE,MAAM,UAAU,OAAO,uBAAuB,KAAK,UAAU,MAAM;GAClE,QAAQ,OAAO,eAAe,MAAM;GACpC;GACA,eAAe,OAAO,eAAe,UAAU;GAC/C;EACD,CAAC;EACD,IAAI,MAAM;GACT,OAAO,UAAU,OAAO;GACxB;EACD;EACA,OAAO,SAAS,iBAAiB,qBAAqB,OAAO,EAAE,GAAG;CACnE,CAAC,CAEkB,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-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { i as oauthServer } from "./shared-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { i as oauthServer } from "./shared-D_MVXtOf.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-Q_ezdpon.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-
|
|
1
|
+
{"version":3,"file":"login-Q_ezdpon.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-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { i as oauthServer } from "./shared-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { i as oauthServer } from "./shared-D_MVXtOf.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-BjL1W-0I.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout-
|
|
1
|
+
{"version":3,"file":"logout-BjL1W-0I.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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, f as writeError, g as make } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { a as oauthProviderLabel, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { a as oauthProviderLabel, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-CDJQxUb9.mjs";
|
|
4
4
|
import { Effect, Option } from "effect";
|
|
5
5
|
import { oauthNotice } from "@codeworksh/aikit/oauth/summary";
|
|
6
6
|
//#region src/cli/cmd/handlers/auth/logout.ts
|
|
@@ -26,4 +26,4 @@ var logout_default = handler(Cmd.commands.auth.commands.logout, Effect.fn("CLI.a
|
|
|
26
26
|
//#endregion
|
|
27
27
|
export { logout_default as default };
|
|
28
28
|
|
|
29
|
-
//# sourceMappingURL=logout-
|
|
29
|
+
//# sourceMappingURL=logout-E_dRjl1L.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout-
|
|
1
|
+
{"version":3,"file":"logout-E_dRjl1L.mjs","names":["Runtime.handler","Client.make"],"sources":["../../src/cli/cmd/handlers/auth/logout.ts"],"sourcesContent":["import { oauthNotice } from \"@codeworksh/aikit/oauth/summary\";\nimport { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeError } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tassertServerScope,\n\tattempt,\n\tClient,\n\tlocalOps,\n\toauthProviderLabel,\n\tselectProvider,\n\twithServer,\n} from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.auth.commands.logout,\n\tEffect.fn(\"CLI.auth.logout\")(function* ({ server, openaiCodex, githubCopilot, authFile }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst provider = yield* selectProvider({ openaiCodex, githubCopilot });\n\t\t\tconst name = oauthProviderLabel(provider);\n\n\t\t\tif (Option.isSome(server)) {\n\t\t\t\tyield* assertServerScope(authFile);\n\t\t\t\treturn yield* withServer(\n\t\t\t\t\tserver.value,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst rpc = yield* Client.make;\n\t\t\t\t\t\tyield* rpc[\"auth.logout\"]({ provider });\n\t\t\t\t\t\tyield* writeError(`${oauthNotice(\"cleared\", provider, \"the server\")}\\n`);\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst ops = yield* localOps(provider, authFile);\n\t\t\tyield* attempt(`failed to clear ${name} credentials`, () => ops.logout());\n\t\t\tyield* writeError(`${oauthNotice(\"cleared\", provider, ops.path)}\\n`);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,iBAAeA,QACd,IAAI,SAAS,KAAK,SAAS,QAC3B,OAAO,GAAG,iBAAiB,CAAC,CAAC,WAAW,EAAE,QAAQ,aAAa,eAAe,YAAY;CAsBzF,OAAO,OArBS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,eAAe;GAAE;GAAa;EAAc,CAAC;EACrE,MAAM,OAAO,mBAAmB,QAAQ;EAExC,IAAI,OAAO,OAAO,MAAM,GAAG;GAC1B,OAAO,kBAAkB,QAAQ;GACjC,OAAO,OAAO,WACb,OAAO,OACP,OAAO,IAAI,aAAa;IAEvB,QAAO,OADYC,KAAAA,CACR,cAAc,CAAC,EAAE,SAAS,CAAC;IACtC,OAAO,WAAW,GAAG,YAAY,WAAW,UAAU,YAAY,EAAE,GAAG;GACxE,CAAC,CACF;EACD;EAEA,MAAM,MAAM,OAAO,SAAS,UAAU,QAAQ;EAC9C,OAAO,QAAQ,mBAAmB,KAAK,qBAAqB,IAAI,OAAO,CAAC;EACxE,OAAO,WAAW,GAAG,YAAY,WAAW,UAAU,IAAI,IAAI,EAAE,GAAG;CACpE,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-BsCtRg3n.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.168.1.ge6d0f923",
|
|
4
4
|
"description": "CLI for running CodeWork coding agent harness.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -40,9 +40,9 @@
|
|
|
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.
|
|
45
|
-
"@codeworksh/schema": "0.1.0-canary.
|
|
43
|
+
"@codeworksh/aikit": "0.14.1-canary.168.1.ge6d0f923",
|
|
44
|
+
"@codeworksh/harness": "0.9.0-canary.168.1.ge6d0f923",
|
|
45
|
+
"@codeworksh/schema": "0.1.0-canary.168.1.ge6d0f923",
|
|
46
46
|
"@effect/platform-node": "4.0.5",
|
|
47
47
|
"@effect/platform-node-shared": "4.0.5",
|
|
48
48
|
"effect": "4.0.5",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, f as writeError, g as make, m as writeOut } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { t as connect } from "./service-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { t as connect } from "./service-YVNwFMNf.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
//#region src/cli/cmd/handlers/service/pair.ts
|
|
6
6
|
var pair_default = handler(Cmd.commands.service.commands.pair, Effect.fn("CLI.service.pair")(function* () {
|
|
@@ -12,4 +12,4 @@ var pair_default = handler(Cmd.commands.service.commands.pair, Effect.fn("CLI.se
|
|
|
12
12
|
//#endregion
|
|
13
13
|
export { pair_default as default };
|
|
14
14
|
|
|
15
|
-
//# sourceMappingURL=pair-
|
|
15
|
+
//# sourceMappingURL=pair-BBneOJZJ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pair-
|
|
1
|
+
{"version":3,"file":"pair-BBneOJZJ.mjs","names":["Runtime.handler","Client.make","Service.connect"],"sources":["../../src/cli/cmd/handlers/service/pair.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Client from \"../../../../server/client.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeError, 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.pair,\n\tEffect.fn(\"CLI.service.pair\")(function* () {\n\t\tconst { code, fingerprint } = yield* Effect.flatMap(Client.make, (rpc) => rpc[\"device.pair\"]({})).pipe(\n\t\t\tService.connect(),\n\t\t);\n\t\tyield* writeOut(`${code}\\n`);\n\t\tyield* writeError(`machine key: ${fingerprint}\\n`);\n\t\tyield* writeError(\"note: this code gives the computer that uses it full access to this machine\\n\");\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;AAQA,IAAA,eAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,MAC9B,OAAO,GAAG,kBAAkB,CAAC,CAAC,aAAa;CAC1C,MAAM,EAAE,MAAM,gBAAgB,OAAO,OAAO,QAAQC,OAAc,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KACjGC,QAAgB,CACjB;CACA,OAAO,SAAS,GAAG,KAAK,GAAG;CAC3B,OAAO,WAAW,gBAAgB,YAAY,GAAG;CACjD,OAAO,WAAW,+EAA+E;AAClG,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, m as writeOut } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { n as synced } from "./catalog-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { n as synced } from "./catalog-Dzi9__Rq.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import { ModelCatalog } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/models/providers.ts
|
|
@@ -14,4 +14,4 @@ var providers_default = handler(Cmd.commands.models.commands.providers, Effect.f
|
|
|
14
14
|
//#endregion
|
|
15
15
|
export { providers_default as default };
|
|
16
16
|
|
|
17
|
-
//# sourceMappingURL=providers-
|
|
17
|
+
//# sourceMappingURL=providers-BYnMGDs7.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers-
|
|
1
|
+
{"version":3,"file":"providers-BYnMGDs7.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/models/providers.ts"],"sourcesContent":["import { ModelCatalog } 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 { synced } from \"./catalog.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.models.commands.providers,\n\tEffect.fn(\"CLI.models.providers\")(function* () {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tyield* synced;\n\t\t\tconst providers = yield* ModelCatalog.providers;\n\t\t\tconst sorted = [...providers].sort((a, b) => a.localeCompare(b));\n\t\t\tyield* writeOut(sorted.map((providerId) => `${providerId}\\n`).join(\"\"));\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,oBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,WAC7B,OAAO,GAAG,sBAAsB,CAAC,CAAC,aAAa;CAQ9C,OAAO,OAPS,OAAO,IAAI,aAAa;EACvC,OAAO;EAEP,MAAM,SAAS,CAAC,GAAG,OADM,aAAa,SACV,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;EAC/D,OAAO,SAAS,OAAO,KAAK,eAAe,GAAG,WAAW,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;CACvE,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, f as writeError, g as make, m as writeOut, n as OAuthError, t as InvalidInputError } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { a as oauthProviderLabel, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { a as oauthProviderLabel, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-CDJQxUb9.mjs";
|
|
4
4
|
import { Effect, Option } from "effect";
|
|
5
5
|
import { formatOAuthSummary, oauthNotice, oauthRefreshIssue } from "@codeworksh/aikit/oauth/summary";
|
|
6
6
|
//#region src/cli/cmd/handlers/auth/refresh.ts
|
|
@@ -32,4 +32,4 @@ var refresh_default = handler(Cmd.commands.auth.commands.refresh, Effect.fn("CLI
|
|
|
32
32
|
//#endregion
|
|
33
33
|
export { refresh_default as default };
|
|
34
34
|
|
|
35
|
-
//# sourceMappingURL=refresh-
|
|
35
|
+
//# sourceMappingURL=refresh-CvE_f1Fa.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh-
|
|
1
|
+
{"version":3,"file":"refresh-CvE_f1Fa.mjs","names":["Runtime.handler","Client.make"],"sources":["../../src/cli/cmd/handlers/auth/refresh.ts"],"sourcesContent":["import { formatOAuthSummary, oauthNotice, oauthRefreshIssue } from \"@codeworksh/aikit/oauth/summary\";\nimport { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { InvalidInputError, OAuthError, reportFailure } from \"../../../error.ts\";\nimport { writeError, writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tassertServerScope,\n\tattempt,\n\tClient,\n\tlocalOps,\n\toauthProviderLabel,\n\tselectProvider,\n\twithServer,\n} from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.auth.commands.refresh,\n\tEffect.fn(\"CLI.auth.refresh\")(function* ({ server, openaiCodex, githubCopilot, authFile, json }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst provider = yield* selectProvider({ openaiCodex, githubCopilot });\n\t\t\tconst blocked = oauthRefreshIssue(provider);\n\t\t\tif (blocked !== undefined) return yield* new InvalidInputError({ message: blocked });\n\n\t\t\tconst name = oauthProviderLabel(provider);\n\n\t\t\tif (Option.isSome(server)) {\n\t\t\t\tyield* assertServerScope(authFile);\n\t\t\t\treturn yield* withServer(\n\t\t\t\t\tserver.value,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst rpc = yield* Client.make;\n\t\t\t\t\t\tconst info = yield* rpc[\"auth.refresh\"]({ provider });\n\t\t\t\t\t\tif (info === null) {\n\t\t\t\t\t\t\treturn yield* new OAuthError({ message: oauthNotice(\"missing\", provider, \"the server\") });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield* writeError(`${oauthNotice(\"refreshed\", provider, \"the server\")}\\n`);\n\t\t\t\t\t\tyield* writeOut(formatOAuthSummary(info, { json }));\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst ops = yield* localOps(provider, authFile);\n\t\t\tconst summary = yield* attempt(`failed to read ${name} credentials`, () => ops.refreshed());\n\t\t\tif (summary === undefined) {\n\t\t\t\treturn yield* new OAuthError({ message: oauthNotice(\"missing\", provider, ops.path) });\n\t\t\t}\n\t\t\tyield* writeError(`${oauthNotice(\"refreshed\", provider, ops.path)}\\n`);\n\t\t\tyield* writeOut(formatOAuthSummary(summary, { json }));\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,kBAAeA,QACd,IAAI,SAAS,KAAK,SAAS,SAC3B,OAAO,GAAG,kBAAkB,CAAC,CAAC,WAAW,EAAE,QAAQ,aAAa,eAAe,UAAU,QAAQ;CAiChG,OAAO,OAhCS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,eAAe;GAAE;GAAa;EAAc,CAAC;EACrE,MAAM,UAAU,kBAAkB,QAAQ;EAC1C,IAAI,YAAY,KAAA,GAAW,OAAO,OAAO,IAAI,kBAAkB,EAAE,SAAS,QAAQ,CAAC;EAEnF,MAAM,OAAO,mBAAmB,QAAQ;EAExC,IAAI,OAAO,OAAO,MAAM,GAAG;GAC1B,OAAO,kBAAkB,QAAQ;GACjC,OAAO,OAAO,WACb,OAAO,OACP,OAAO,IAAI,aAAa;IAEvB,MAAM,OAAO,QAAO,OADDC,KAAAA,CACK,eAAe,CAAC,EAAE,SAAS,CAAC;IACpD,IAAI,SAAS,MACZ,OAAO,OAAO,IAAI,WAAW,EAAE,SAAS,YAAY,WAAW,UAAU,YAAY,EAAE,CAAC;IAEzF,OAAO,WAAW,GAAG,YAAY,aAAa,UAAU,YAAY,EAAE,GAAG;IACzE,OAAO,SAAS,mBAAmB,MAAM,EAAE,KAAK,CAAC,CAAC;GACnD,CAAC,CACF;EACD;EAEA,MAAM,MAAM,OAAO,SAAS,UAAU,QAAQ;EAC9C,MAAM,UAAU,OAAO,QAAQ,kBAAkB,KAAK,qBAAqB,IAAI,UAAU,CAAC;EAC1F,IAAI,YAAY,KAAA,GACf,OAAO,OAAO,IAAI,WAAW,EAAE,SAAS,YAAY,WAAW,UAAU,IAAI,IAAI,EAAE,CAAC;EAErF,OAAO,WAAW,GAAG,YAAY,aAAa,UAAU,IAAI,IAAI,EAAE,GAAG;EACrE,OAAO,SAAS,mBAAmB,SAAS,EAAE,KAAK,CAAC,CAAC;CACtD,CAEoB,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 } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { t as home } from "./catalog-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { t as home } from "./catalog-Dzi9__Rq.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import { ModelCatalog } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/models/refresh.ts
|
|
@@ -14,4 +14,4 @@ var refresh_default = handler(Cmd.commands.models.commands.refresh, Effect.fn("C
|
|
|
14
14
|
//#endregion
|
|
15
15
|
export { refresh_default as default };
|
|
16
16
|
|
|
17
|
-
//# sourceMappingURL=refresh-
|
|
17
|
+
//# sourceMappingURL=refresh-Dy9kI2El.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh-
|
|
1
|
+
{"version":3,"file":"refresh-Dy9kI2El.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/models/refresh.ts"],"sourcesContent":["import { ModelCatalog } from \"@codeworksh/harness/effect\";\nimport { Effect } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeError, writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { home } from \"./catalog.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.models.commands.refresh,\n\tEffect.fn(\"CLI.models.refresh\")(function* ({ force }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst status = yield* ModelCatalog.refresh(yield* home, { force });\n\t\t\tyield* writeError(\n\t\t\t\tstatus.refreshed\n\t\t\t\t\t? `Refreshed model catalog at ${status.path}\\n`\n\t\t\t\t\t: `Model catalog at ${status.path} is fresh; pass --force to download it anyway\\n`,\n\t\t\t);\n\t\t\tyield* writeOut(`${status.path}\\n`);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,kBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,SAC7B,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,EAAE,SAAS;CAWrD,OAAO,OAVS,OAAO,IAAI,aAAa;EACvC,MAAM,SAAS,OAAO,aAAa,QAAQ,OAAO,MAAM,EAAE,MAAM,CAAC;EACjE,OAAO,WACN,OAAO,YACJ,8BAA8B,OAAO,KAAK,MAC1C,oBAAoB,OAAO,KAAK,gDACpC;EACA,OAAO,SAAS,GAAG,OAAO,KAAK,GAAG;CACnC,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as version } from "./package-
|
|
1
|
+
import { t as version } from "./package-BsCtRg3n.mjs";
|
|
2
2
|
import { o as write$1 } from "./registration-C6yiv31r.mjs";
|
|
3
|
-
import { r as hostName } from "./identity-
|
|
3
|
+
import { r as hostName } from "./identity-Cjr43dhQ.mjs";
|
|
4
4
|
import { Clock, Config, Context, Duration, Effect, FileSystem, Layer, Option, Schedule, Schema } from "effect";
|
|
5
5
|
import { FetchHttpClient } from "effect/http";
|
|
6
6
|
import { uuidv7 } from "uuidv7";
|
|
@@ -322,4 +322,4 @@ const disconnect = Effect.fn("Machine.disconnect")(function* (home, workspaceId,
|
|
|
322
322
|
//#endregion
|
|
323
323
|
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 };
|
|
324
324
|
|
|
325
|
-
//# sourceMappingURL=relay-
|
|
325
|
+
//# sourceMappingURL=relay-CO46Wh73.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-BmHXs1yg.mjs","names":["Machine","Private.write","pkg.version","File.read","File.update","File.checkId","File.removeLink","File.markLeaving"],"sources":["../../src/machine/file.ts","../../src/machine/relay.ts"],"sourcesContent":["import { Jws } from \"@codeworksh/schema/jws\";\nimport { Relay } from \"@codeworksh/schema/relay\";\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\taccount: 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: // `serve` generates an id at startup, so a rebuilt machine has one before it reclaims its old id;\n\t\t\t\t\t\t\t// one no workspace has seen yet can still give way.\n\t\t\t\t\t\t\tmachine.source === \"generated\" && Object.keys(machine.workspaces).length === 0\n\t\t\t\t\t\t\t? Effect.succeed({ ...machine, id: options.machineId, source: \"flag\" as const })\n\t\t\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\t\t\tnew MachineError({\n\t\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\t}),\n\t\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 } from \"@codeworksh/schema/jws\";\nimport { Machine } from \"@codeworksh/schema/machine\";\nimport { Relay } from \"@codeworksh/schema/relay\";\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\taccount: connected.account,\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":";;;;;;;;;;;;;;;;;;AAYA,MAAM,OAAO,OAAO,OAAO;CAC1B,MAAM,OAAO;CACb,SAAS,OAAO,OAAO;EAAE,IAAI,OAAO;EAAQ,MAAM,OAAO,OAAO,OAAO,MAAM;CAAE,CAAC;;CAEhF,OAAO,OAAO;CACd,KAAK,IAAI;CACT,OAAO,OAAO;;CAEd,SAAS,OAAO,YAAY,OAAO,OAAO;AAC3C,CAAC;;AAGD,MAAM,WAAW,OAAO,OAAO;CAAE,KAAK,IAAI;CAAY,OAAO,OAAO;AAAO,CAAC;AAG5E,MAAaA,YAAU,OAAO,OAAO;CACpC,IAAI,OAAO;CACX,QAAQ,MAAM;;CAEd,WAAW,OAAO,SAAS,OAAO,MAAM;CAExC,UAAU,OAAO,SAAS,QAAQ;CAClC,YAAY,OAAO,OAAO,OAAO,QAAQ,IAAI;AAC9C,CAAC;AAKD,MAAM,OAAO,OAAO,eAAeA,SAAO;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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AAK,IAAIC,YAAiB,MAAM,aAAa,KAAK,KAAK;CAChH,OAAO;EAAE,WAAW,KAAK;EAAM;CAAQ;AACxC,CAAC"}
|
|
1
|
+
{"version":3,"file":"relay-CO46Wh73.mjs","names":["Machine","Private.write","pkg.version","File.read","File.update","File.checkId","File.removeLink","File.markLeaving"],"sources":["../../src/machine/file.ts","../../src/machine/relay.ts"],"sourcesContent":["import { Jws } from \"@codeworksh/schema/jws\";\nimport { Relay } from \"@codeworksh/schema/relay\";\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\taccount: 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: // `serve` generates an id at startup, so a rebuilt machine has one before it reclaims its old id;\n\t\t\t\t\t\t\t// one no workspace has seen yet can still give way.\n\t\t\t\t\t\t\tmachine.source === \"generated\" && Object.keys(machine.workspaces).length === 0\n\t\t\t\t\t\t\t? Effect.succeed({ ...machine, id: options.machineId, source: \"flag\" as const })\n\t\t\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\t\t\tnew MachineError({\n\t\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\t}),\n\t\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 } from \"@codeworksh/schema/jws\";\nimport { Machine } from \"@codeworksh/schema/machine\";\nimport { Relay } from \"@codeworksh/schema/relay\";\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\taccount: connected.account,\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":";;;;;;;;;;;;;;;;;;AAYA,MAAM,OAAO,OAAO,OAAO;CAC1B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s";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { t as connect } from "./service-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { t as connect } from "./service-YVNwFMNf.mjs";
|
|
4
4
|
import { n as threadFlag, t as sessionId } from "./ids-BW5msGUm.mjs";
|
|
5
5
|
import { Effect, Option } from "effect";
|
|
6
6
|
import { Sandbox } from "@codeworksh/harness/effect";
|
|
@@ -22,4 +22,4 @@ var relink_default = handler(Cmd.commands.session.commands.relink, Effect.fn("CL
|
|
|
22
22
|
//#endregion
|
|
23
23
|
export { relink_default as default };
|
|
24
24
|
|
|
25
|
-
//# sourceMappingURL=relink-
|
|
25
|
+
//# sourceMappingURL=relink-DxftNq9n.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relink-
|
|
1
|
+
{"version":3,"file":"relink-DxftNq9n.mjs","names":["Runtime.handler","Client.make","ThreadInfo","Service.connect"],"sources":["../../src/cli/cmd/handlers/session/relink.ts"],"sourcesContent":["import { Sandbox } from \"@codeworksh/harness/effect\";\nimport { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Client from \"../../../../server/client.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { ThreadInfo } from \"../../../../server/contract.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeJson, writeOut } from \"../../../output.ts\";\nimport { sessionId, threadFlag } from \"../../../ids.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.session.commands.relink,\n\tEffect.fn(\"CLI.session.relink\")(function* ({ session, thread, directory, sandboxId, json, server }) {\n\t\tconst id = yield* sessionId(session);\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst threadId = yield* threadFlag(thread);\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst info = yield* rpc[\"session.relink\"]({\n\t\t\t\tsessionId: id,\n\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t...(Option.isNone(sandboxId) ? {} : { sandbox: { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) } }),\n\t\t\t\t...(Option.isNone(directory) ? {} : { directory: directory.value }),\n\t\t\t});\n\t\t\tif (json) return yield* writeJson(ThreadInfo, info);\n\t\t\t// Without `--thread` the session's default moved; a thread with its own placement stays put.\n\t\t\tyield* writeOut(\n\t\t\t\tthreadId === undefined\n\t\t\t\t\t? `Moved ${info.session.id} to ${info.session.directory}\\n`\n\t\t\t\t\t: `Moved thread ${info.id} of ${info.session.id} to ${info.placement?.directory ?? info.session.directory}\\n`,\n\t\t\t);\n\t\t});\n\n\t\treturn yield* program.pipe(Service.connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;;AAWA,IAAA,iBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,QAC9B,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,EAAE,SAAS,QAAQ,WAAW,WAAW,MAAM,UAAU;CACnG,MAAM,KAAK,OAAO,UAAU,OAAO;CAmBnC,OAAO,OAlBS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,WAAW,MAAM;EAEzC,MAAM,OAAO,QAAO,OADDC,KAAAA,CACK,iBAAiB,CAAC;GACzC,WAAW;GACX,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC7C,GAAI,OAAO,OAAO,SAAS,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,QAAQ,gBAAgB,GAAG,KAAK,UAAU,KAAK,EAAE,EAAE;GACxG,GAAI,OAAO,OAAO,SAAS,IAAI,CAAC,IAAI,EAAE,WAAW,UAAU,MAAM;EAClE,CAAC;EACD,IAAI,MAAM,OAAO,OAAO,UAAUC,iBAAAA,YAAY,IAAI;EAElD,OAAO,SACN,aAAa,KAAA,IACV,SAAS,KAAK,QAAQ,GAAG,MAAM,KAAK,QAAQ,UAAU,MACtD,gBAAgB,KAAK,GAAG,MAAM,KAAK,QAAQ,GAAG,MAAM,KAAK,WAAW,aAAa,KAAK,QAAQ,UAAU,GAC5G;CACD,CAEoB,CAAC,CAAC,KAAKC,QAAgB,OAAO,eAAe,MAAM,CAAC,GAAG,OAAO,MAAM,aAAa,CAAC;AACvG,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as reportFailure, g as make, m as writeOut } from "./error-BsI8iNna.mjs";
|
|
2
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
3
|
-
import { t as connect } from "./service-
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CyXV7HH_.mjs";
|
|
3
|
+
import { t as connect } from "./service-YVNwFMNf.mjs";
|
|
4
4
|
import { Effect, Option } from "effect";
|
|
5
5
|
//#region src/cli/cmd/handlers/plugin/reload.ts
|
|
6
6
|
/**
|
|
@@ -24,4 +24,4 @@ var reload_default = handler(Cmd.commands.plugin.commands.reload, Effect.fn("CLI
|
|
|
24
24
|
//#endregion
|
|
25
25
|
export { reload_default as default };
|
|
26
26
|
|
|
27
|
-
//# sourceMappingURL=reload-
|
|
27
|
+
//# sourceMappingURL=reload-DRp3UlHQ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload-
|
|
1
|
+
{"version":3,"file":"reload-DRp3UlHQ.mjs","names":["Runtime.handler","Client.make","Service.connect"],"sources":["../../src/cli/cmd/handlers/plugin/reload.ts"],"sourcesContent":["import { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Client from \"../../../../server/client.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\n/**\n * Re-import every configured plugin in a running server.\n *\n * It exists for exactly one case: a **local** plugin edited in place. Nothing in settings changed\n * and no generation moved -- a local source is never copied into the store, so it has none -- and\n * the module registry holds the old module against an unchanged URL. Everything else the runtime\n * notices for itself at the next exchange.\n *\n * There is no local form, and that is not an omission. In a CLI every run is a fresh process, so\n * the load pass happens at startup and a reload would have nothing to do.\n */\nexport default Runtime.handler(\n\tCmd.commands.plugin.commands.reload,\n\tEffect.fn(\"CLI.plugin.reload\")(function* ({ server }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst result = yield* rpc[\"plugin.reload\"]({});\n\t\t\t// A reload that failed still reports the set that stayed loaded: the server kept\n\t\t\t// working, which is the whole point of not failing it.\n\t\t\tyield* writeOut(\n\t\t\t\tresult.failure === undefined\n\t\t\t\t\t? `Reloaded ${result.plugins} plugin${result.plugins === 1 ? \"\" : \"s\"}.\\n`\n\t\t\t\t\t: `Reload failed, keeping ${result.plugins} loaded: ${result.failure}\\n`,\n\t\t\t);\n\t\t\tif (result.failure !== undefined) process.exitCode = 1;\n\t\t});\n\n\t\treturn yield* program.pipe(Service.connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,IAAA,iBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,QAC7B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,UAAU;CAcrD,OAAO,OAbS,OAAO,IAAI,aAAa;EAEvC,MAAM,SAAS,QAAO,OADHC,KAAAA,CACO,gBAAgB,CAAC,CAAC,CAAC;EAG7C,OAAO,SACN,OAAO,YAAY,KAAA,IAChB,YAAY,OAAO,QAAQ,SAAS,OAAO,YAAY,IAAI,KAAK,IAAI,OACpE,0BAA0B,OAAO,QAAQ,WAAW,OAAO,QAAQ,GACvE;EACA,IAAI,OAAO,YAAY,KAAA,GAAW,QAAQ,WAAW;CACtD,CAEoB,CAAC,CAAC,KAAKC,QAAgB,OAAO,eAAe,MAAM,CAAC,GAAG,OAAO,MAAM,aAAa,CAAC;AACvG,CAAC,CACF"}
|