@codeworksh/cli 0.8.0 → 0.9.0-canary.158.1.gdff28d0d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{acp-DodCRypZ.mjs → acp-D1X6PAQd.mjs} +16 -11
- package/acp-D1X6PAQd.mjs.map +1 -0
- package/{add-Dgy0iTEQ.mjs → add-BO0TXkKX.mjs} +8 -7
- package/add-BO0TXkKX.mjs.map +1 -0
- package/{add-31QB-o0_.mjs → add-BwC5Yb3Z.mjs} +5 -5
- package/add-BwC5Yb3Z.mjs.map +1 -0
- package/{catalog-XfqtqMDz.mjs → catalog-BhnZFkoq.mjs} +2 -2
- package/{catalog-XfqtqMDz.mjs.map → catalog-BhnZFkoq.mjs.map} +1 -1
- package/{check-BoANDJxT.mjs → check-n2oLWYrZ.mjs} +4 -4
- package/check-n2oLWYrZ.mjs.map +1 -0
- package/connect-CO-oR-Br.mjs +35 -0
- package/connect-CO-oR-Br.mjs.map +1 -0
- package/{control-CQxWGS4k.mjs → control-Clr9Xyw9.mjs} +10 -9
- package/control-Clr9Xyw9.mjs.map +1 -0
- package/devices-aPlpoGGA.mjs +29 -0
- package/devices-aPlpoGGA.mjs.map +1 -0
- package/disconnect-B7HoGP0E.mjs +21 -0
- package/disconnect-B7HoGP0E.mjs.map +1 -0
- package/disconnect-gKR8hsnU.mjs +2 -0
- package/{service-CjOS-xCw.mjs → discovery-D07MPnKd.mjs} +13 -37
- package/discovery-D07MPnKd.mjs.map +1 -0
- package/{entries-DpL4xhu0.mjs → entries-BzfySpSJ.mjs} +3 -3
- package/{entries-DpL4xhu0.mjs.map → entries-BzfySpSJ.mjs.map} +1 -1
- package/{error-CPyvkO4x.mjs → error-ippxl2z7.mjs} +775 -31
- package/error-ippxl2z7.mjs.map +1 -0
- package/{fork-CjZteIbk.mjs → fork-lbhh_6QP.mjs} +8 -7
- package/fork-lbhh_6QP.mjs.map +1 -0
- package/identity-DbK4fABs.mjs +26 -0
- package/identity-DbK4fABs.mjs.map +1 -0
- package/{thread-I6vNdC0y.mjs → ids-cNIRx0-c.mjs} +11 -5
- package/ids-cNIRx0-c.mjs.map +1 -0
- package/index.mjs +39 -34
- package/index.mjs.map +1 -1
- package/{install-BUfEBtrj.mjs → install-dfD5hzCS.mjs} +4 -4
- package/install-dfD5hzCS.mjs.map +1 -0
- package/jsonc-CWL4-4yz.mjs +33 -0
- package/jsonc-CWL4-4yz.mjs.map +1 -0
- package/{link-ZuzWj9qt.mjs → link-D1cicwAl.mjs} +8 -6
- package/link-D1cicwAl.mjs.map +1 -0
- package/{list-DDuzyNv0.mjs → list-BKJgNMJm.mjs} +10 -12
- package/list-BKJgNMJm.mjs.map +1 -0
- package/{list-6QTwXTKO.mjs → list-C3McEC0O.mjs} +4 -4
- package/list-C3McEC0O.mjs.map +1 -0
- package/{list-DPbF2uMB.mjs → list-CGT6jT-r.mjs} +4 -4
- package/list-CGT6jT-r.mjs.map +1 -0
- package/{list-BnIIcMI3.mjs → list-DZK016LF.mjs} +4 -4
- package/list-DZK016LF.mjs.map +1 -0
- package/{login-BtuROCPJ.mjs → login-DuFDeGH-.mjs} +4 -4
- package/login-DuFDeGH-.mjs.map +1 -0
- package/{login-CGXU21AK.mjs → login-XhIIF5Yu.mjs} +4 -4
- package/login-XhIIF5Yu.mjs.map +1 -0
- package/{logout-DUn8KSjX.mjs → logout-CA1No9_2.mjs} +4 -4
- package/logout-CA1No9_2.mjs.map +1 -0
- package/{logout-Bnk2hxfZ.mjs → logout-Dpqw8tQZ.mjs} +4 -4
- package/logout-Dpqw8tQZ.mjs.map +1 -0
- package/package-DgfSc9nY.mjs +6 -0
- package/package-DgfSc9nY.mjs.map +1 -0
- package/package.json +3 -3
- package/pair-BC8a_KYX.mjs +15 -0
- package/pair-BC8a_KYX.mjs.map +1 -0
- package/{providers-GEdlDJHp.mjs → providers--giKGohM.mjs} +4 -4
- package/providers--giKGohM.mjs.map +1 -0
- package/reconnect-I9-Do_DK.mjs +2 -0
- package/{refresh-DGJW3rSp.mjs → refresh-BIH3qn5A.mjs} +4 -4
- package/refresh-BIH3qn5A.mjs.map +1 -0
- package/{refresh-93t2pSpb.mjs → refresh-Dg8WvRcq.mjs} +4 -4
- package/refresh-Dg8WvRcq.mjs.map +1 -0
- package/{identity-LhURGrcS.mjs → registration-C6yiv31r.mjs} +27 -25
- package/registration-C6yiv31r.mjs.map +1 -0
- package/relay-CLPWErNw.mjs +319 -0
- package/relay-CLPWErNw.mjs.map +1 -0
- package/{relink-Djy5t7D2.mjs → relink-D8Koos_q.mjs} +9 -7
- package/relink-D8Koos_q.mjs.map +1 -0
- package/{reload-Dm464rPC.mjs → reload-C5-B0s9x.mjs} +6 -5
- package/{reload-Dm464rPC.mjs.map → reload-C5-B0s9x.mjs.map} +1 -1
- package/{remove-DBT19X2j.mjs → remove-6m5n17il.mjs} +4 -4
- package/remove-6m5n17il.mjs.map +1 -0
- package/{remove-f7C_vEOD.mjs → remove-VZO51J2m.mjs} +5 -5
- package/remove-VZO51J2m.mjs.map +1 -0
- package/{restart-DXMDjblc.mjs → restart-4NoPj76N.mjs} +5 -4
- package/restart-4NoPj76N.mjs.map +1 -0
- package/revoke-Gu5N3Vzy.mjs +13 -0
- package/revoke-Gu5N3Vzy.mjs.map +1 -0
- package/{run-CTFksYXE.mjs → run-RHrJN2Pv.mjs} +12 -14
- package/run-RHrJN2Pv.mjs.map +1 -0
- package/{runtime-CK2CunDw.mjs → runtime-CtLWuLd-.mjs} +48 -12
- package/runtime-CtLWuLd-.mjs.map +1 -0
- package/{serve-BntJRQed.mjs → serve-BZ5FAU3h.mjs} +586 -64
- package/serve-BZ5FAU3h.mjs.map +1 -0
- package/service-CRnqz89w.mjs +79 -0
- package/service-CRnqz89w.mjs.map +1 -0
- package/{settings-DasbTMFs.mjs → settings-DU140UBM.mjs} +3 -3
- package/settings-DU140UBM.mjs.map +1 -0
- package/{shared-CDyNsYBy.mjs → shared-CC4WukJX.mjs} +4 -4
- package/shared-CC4WukJX.mjs.map +1 -0
- package/{shared-CiSbTY59.mjs → shared-Dzwbs5Lk.mjs} +7 -9
- package/shared-Dzwbs5Lk.mjs.map +1 -0
- package/{start-CTYwK1Z4.mjs → start-COhahq2E.mjs} +5 -4
- package/start-COhahq2E.mjs.map +1 -0
- package/{status-CPKssQFk.mjs → status-Cau7bzuQ.mjs} +5 -4
- package/status-Cau7bzuQ.mjs.map +1 -0
- package/{status-CHcJyF_7.mjs → status-DJJOuCzL.mjs} +4 -4
- package/status-DJJOuCzL.mjs.map +1 -0
- package/{stop-CpQr3fUv.mjs → stop-CC--mxXp.mjs} +5 -4
- package/stop-CC--mxXp.mjs.map +1 -0
- package/{update-C3llbIB0.mjs → update-DMQLgDm3.mjs} +4 -4
- package/update-DMQLgDm3.mjs.map +1 -0
- package/acp-DodCRypZ.mjs.map +0 -1
- package/add-31QB-o0_.mjs.map +0 -1
- package/add-Dgy0iTEQ.mjs.map +0 -1
- package/check-BoANDJxT.mjs.map +0 -1
- package/control-CQxWGS4k.mjs.map +0 -1
- package/disconnect-BiLuV4JZ.mjs +0 -2
- package/error-CPyvkO4x.mjs.map +0 -1
- package/fork-CjZteIbk.mjs.map +0 -1
- package/identity-LhURGrcS.mjs.map +0 -1
- package/install-BUfEBtrj.mjs.map +0 -1
- package/jsonc-Ca0uQLm-.mjs +0 -58
- package/jsonc-Ca0uQLm-.mjs.map +0 -1
- package/link-ZuzWj9qt.mjs.map +0 -1
- package/list-6QTwXTKO.mjs.map +0 -1
- package/list-BnIIcMI3.mjs.map +0 -1
- package/list-DDuzyNv0.mjs.map +0 -1
- package/list-DPbF2uMB.mjs.map +0 -1
- package/login-BtuROCPJ.mjs.map +0 -1
- package/login-CGXU21AK.mjs.map +0 -1
- package/logout-Bnk2hxfZ.mjs.map +0 -1
- package/logout-DUn8KSjX.mjs.map +0 -1
- package/package-C5s94xPy.mjs +0 -6
- package/package-C5s94xPy.mjs.map +0 -1
- package/providers-GEdlDJHp.mjs.map +0 -1
- package/reconnect-ChE5ETwx.mjs +0 -2
- package/refresh-93t2pSpb.mjs.map +0 -1
- package/refresh-DGJW3rSp.mjs.map +0 -1
- package/relink-Djy5t7D2.mjs.map +0 -1
- package/remove-DBT19X2j.mjs.map +0 -1
- package/remove-f7C_vEOD.mjs.map +0 -1
- package/restart-DXMDjblc.mjs.map +0 -1
- package/run-CTFksYXE.mjs.map +0 -1
- package/runtime-CK2CunDw.mjs.map +0 -1
- package/serve-BntJRQed.mjs.map +0 -1
- package/service-CjOS-xCw.mjs.map +0 -1
- package/settings-DasbTMFs.mjs.map +0 -1
- package/shared-CDyNsYBy.mjs.map +0 -1
- package/shared-CiSbTY59.mjs.map +0 -1
- package/start-CTYwK1Z4.mjs.map +0 -1
- package/status-CHcJyF_7.mjs.map +0 -1
- package/status-CPKssQFk.mjs.map +0 -1
- package/stop-CpQr3fUv.mjs.map +0 -1
- package/thread-I6vNdC0y.mjs.map +0 -1
- package/update-C3llbIB0.mjs.map +0 -1
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Effect, FileSystem, Layer, Path, Schedule, Schema } from "effect";
|
|
2
|
+
import { uuidv7 } from "uuidv7";
|
|
3
3
|
import { isSea } from "node:sea";
|
|
4
|
+
//#region src/framework/private.ts
|
|
5
|
+
/**
|
|
6
|
+
* Writes `text` to `path` for this user alone (0600): beside it first, then renamed over it, so a
|
|
7
|
+
* reader never sees half a file.
|
|
8
|
+
*/
|
|
9
|
+
const write$1 = Effect.fn("Private.write")(function* (path, text) {
|
|
10
|
+
const fs = yield* FileSystem.FileSystem;
|
|
11
|
+
yield* fs.makeDirectory((yield* Path.Path).dirname(path), { recursive: true });
|
|
12
|
+
const temp = `${path}.${uuidv7()}.tmp`;
|
|
13
|
+
yield* fs.writeFileString(temp, text, { mode: 384 });
|
|
14
|
+
yield* fs.rename(temp, path);
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
4
17
|
//#region src/server/registration.ts
|
|
5
18
|
/**
|
|
6
19
|
* How a running server advertises itself so later invocations can find it
|
|
@@ -19,7 +32,9 @@ const Info = Schema.Struct({
|
|
|
19
32
|
/** The `ws://host:port/rpc/v1` endpoint a client connects to. */
|
|
20
33
|
url: Schema.String,
|
|
21
34
|
/** The TCP port the server bound, for a caller that would rather reuse it than default. */
|
|
22
|
-
port: Schema.Int
|
|
35
|
+
port: Schema.Int,
|
|
36
|
+
/** The server's token for the life of its process: a local client sends it on every call. */
|
|
37
|
+
token: Schema.String
|
|
23
38
|
});
|
|
24
39
|
const infoJson = Schema.fromJsonString(Info);
|
|
25
40
|
/** The registration file for a CodeWork home: `<home>/service.json`. */
|
|
@@ -27,15 +42,11 @@ const file = (home) => `${home}/service.json`;
|
|
|
27
42
|
/** Where a background (`serve --service`) server writes its log: `<log>/server.log`, truncated per start. */
|
|
28
43
|
const log = (logDir) => `${logDir}/server.log`;
|
|
29
44
|
const decode = Schema.decodeUnknownEffect(infoJson);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
yield* fs.makeDirectory(paths.dirname(path), { recursive: true });
|
|
34
|
-
const encoded = yield* Schema.encodeEffect(infoJson)(info);
|
|
35
|
-
const temp = `${path}.${info.pid}.tmp`;
|
|
36
|
-
yield* fs.writeFileString(temp, encoded, { mode: 384 });
|
|
37
|
-
yield* fs.rename(temp, path);
|
|
45
|
+
/** The registration at `path`; a missing or unreadable file is none. */
|
|
46
|
+
const read = (path) => Effect.gen(function* () {
|
|
47
|
+
return yield* (yield* FileSystem.FileSystem).readFileString(path).pipe(Effect.flatMap(decode), Effect.orElseSucceed(() => void 0));
|
|
38
48
|
});
|
|
49
|
+
const write = (path, info) => Schema.encodeEffect(infoJson)(info).pipe(Effect.flatMap((encoded) => write$1(path, encoded)));
|
|
39
50
|
/**
|
|
40
51
|
* Publishes a registration for as long as this server lives, removing it on the
|
|
41
52
|
* way out if it is still the one on file. A file left by a crash is overwritten
|
|
@@ -49,11 +60,11 @@ const write = Effect.fn("ServerRegistration.write")(function* (path, info) {
|
|
|
49
60
|
const register = (options) => Layer.effectDiscard(Effect.gen(function* () {
|
|
50
61
|
const path = file(options.home);
|
|
51
62
|
const fs = yield* FileSystem.FileSystem;
|
|
52
|
-
const current =
|
|
63
|
+
const current = read(path);
|
|
53
64
|
const owns = (found) => found.pid === options.info.pid && found.url === options.info.url;
|
|
54
65
|
yield* write(path, options.info);
|
|
55
|
-
yield* Effect.addFinalizer(() => current.pipe(Effect.flatMap((found) =>
|
|
56
|
-
yield* current.pipe(Effect.flatMap((found) =>
|
|
66
|
+
yield* Effect.addFinalizer(() => current.pipe(Effect.flatMap((found) => found !== void 0 && owns(found) ? fs.remove(path) : Effect.void), Effect.ignore));
|
|
67
|
+
yield* current.pipe(Effect.flatMap((found) => found === void 0 ? write(path, options.info).pipe(Effect.ignore, Effect.as(true)) : Effect.succeed(owns(found))), Effect.repeat({
|
|
57
68
|
while: (ours) => ours,
|
|
58
69
|
schedule: Schedule.spaced("5 seconds")
|
|
59
70
|
}), Effect.andThen(Effect.logWarning(`${path} names another server; shutting down`)), Effect.andThen(Effect.sync(() => process.kill(process.pid, "SIGTERM"))), Effect.forkScoped);
|
|
@@ -78,15 +89,6 @@ const command = () => {
|
|
|
78
89
|
];
|
|
79
90
|
};
|
|
80
91
|
//#endregion
|
|
81
|
-
|
|
82
|
-
var Service = class extends Context.Service()("@codeworksh/cli/server/identity/Service") {};
|
|
83
|
-
/** This process: a server answers with it, a client compares a server's version against it. */
|
|
84
|
-
const current = {
|
|
85
|
-
pid: process.pid,
|
|
86
|
-
version
|
|
87
|
-
};
|
|
88
|
-
const layer = Layer.succeed(Service, Service.of(current));
|
|
89
|
-
//#endregion
|
|
90
|
-
export { file as a, register as c, command as i, current as n, infoJson as o, layer as r, log as s, Service as t };
|
|
92
|
+
export { register as a, read as i, file as n, write$1 as o, log as r, command as t };
|
|
91
93
|
|
|
92
|
-
//# sourceMappingURL=
|
|
94
|
+
//# sourceMappingURL=registration-C6yiv31r.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration-C6yiv31r.mjs","names":["write","Private.write"],"sources":["../../src/framework/private.ts","../../src/server/registration.ts"],"sourcesContent":["import { Effect, FileSystem, Path } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\n\n/**\n * Writes `text` to `path` for this user alone (0600): beside it first, then renamed over it, so a\n * reader never sees half a file.\n */\nexport const write = Effect.fn(\"Private.write\")(function* (path: string, text: string) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tyield* fs.makeDirectory((yield* Path.Path).dirname(path), { recursive: true });\n\tconst temp = `${path}.${uuidv7()}.tmp`;\n\tyield* fs.writeFileString(temp, text, { mode: 0o600 });\n\tyield* fs.rename(temp, path);\n});\n","import { Effect, FileSystem, Layer, Schedule, Schema } from \"effect\";\nimport { isSea } from \"node:sea\";\nimport * as Private from \"../framework/private.ts\";\n\n/**\n * How a running server advertises itself so later invocations can find it\n * without scanning ports or the process table.\n *\n * The file is a discovery hint, never proof: a caller reads it for the endpoint,\n * then asks the endpoint `server.info` and believes the answer only when the\n * live pid and version match the ones on file. A crashed server leaves a\n * registration behind; the failed probe is what retires it.\n */\nexport const Info = Schema.Struct({\n\t/** Operating system process identifier of the server that wrote this. */\n\tpid: Schema.Int,\n\t/** The build serving this endpoint; a mismatch means a different binary. */\n\tversion: Schema.String,\n\t/** The `ws://host:port/rpc/v1` endpoint a client connects to. */\n\turl: Schema.String,\n\t/** The TCP port the server bound, for a caller that would rather reuse it than default. */\n\tport: Schema.Int,\n\t/** The server's token for the life of its process: a local client sends it on every call. */\n\ttoken: Schema.String,\n});\nexport type Info = typeof Info.Type;\n\nconst infoJson = Schema.fromJsonString(Info);\n\n/** The registration file for a CodeWork home: `<home>/service.json`. */\nexport const file = (home: string) => `${home}/service.json`;\n\n/** Where a background (`serve --service`) server writes its log: `<log>/server.log`, truncated per start. */\nexport const log = (logDir: string) => `${logDir}/server.log`;\n\nconst decode = Schema.decodeUnknownEffect(infoJson);\n\n/** The registration at `path`; a missing or unreadable file is none. */\nexport const read = (path: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\treturn yield* fs.readFileString(path).pipe(\n\t\t\tEffect.flatMap(decode),\n\t\t\tEffect.orElseSucceed(() => undefined),\n\t\t);\n\t});\n\n// Private because it carries the token.\nconst write = (path: string, info: Info) =>\n\tSchema.encodeEffect(infoJson)(info).pipe(Effect.flatMap((encoded) => Private.write(path, encoded)));\n\n/**\n * Publishes a registration for as long as this server lives, removing it on the\n * way out if it is still the one on file. A file left by a crash is overwritten\n * by the next server to start, and retired by a probe that cannot confirm it.\n *\n * One home has one discoverable server. Every few seconds the file is checked:\n * a missing or unreadable file is written again, and a file naming another\n * server means this one lost discovery for good, so it shuts down rather than\n * run on where nothing can find or stop it.\n */\nexport const register = (options: { readonly home: string; readonly info: Info }) =>\n\tLayer.effectDiscard(\n\t\tEffect.gen(function* () {\n\t\t\tconst path = file(options.home);\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tconst current = read(path);\n\t\t\tconst owns = (found: Info) => found.pid === options.info.pid && found.url === options.info.url;\n\n\t\t\tyield* write(path, options.info);\n\t\t\tyield* Effect.addFinalizer(() =>\n\t\t\t\tcurrent.pipe(\n\t\t\t\t\tEffect.flatMap((found) => (found !== undefined && owns(found) ? fs.remove(path) : Effect.void)),\n\t\t\t\t\tEffect.ignore,\n\t\t\t\t),\n\t\t\t);\n\t\t\t// Forked after the finalizer, so shutdown stops the watch before the file is removed.\n\t\t\tyield* current.pipe(\n\t\t\t\tEffect.flatMap((found) =>\n\t\t\t\t\tfound === undefined\n\t\t\t\t\t\t? write(path, options.info).pipe(Effect.ignore, Effect.as(true))\n\t\t\t\t\t\t: Effect.succeed(owns(found)),\n\t\t\t\t),\n\t\t\t\tEffect.repeat({ while: (ours) => ours, schedule: Schedule.spaced(\"5 seconds\") }),\n\t\t\t\tEffect.andThen(Effect.logWarning(`${path} names another server; shutting down`)),\n\t\t\t\t// The same graceful path `codework service stop` takes.\n\t\t\t\tEffect.andThen(Effect.sync(() => process.kill(process.pid, \"SIGTERM\"))),\n\t\t\t\tEffect.forkScoped,\n\t\t\t);\n\t\t}),\n\t);\n\n/**\n * The launcher command for a managed server: this same CLI, asked to serve.\n *\n * A packaged install runs `dist/pack/index.mjs`; under `--conditions=development`\n * the entry is TypeScript, and `process.execArgv` carries the conditions forward\n * so a managed server resolves workspace sources the same way this process did.\n * The standalone binary is its own entry.\n */\nexport const command = (): ReadonlyArray<string> => {\n\tif (isSea()) return [process.execPath];\n\tconst entry = process.argv[1];\n\tif (entry === undefined) return [process.execPath];\n\tconst runtime = import.meta.url.endsWith(\".ts\") ? process.execArgv : [];\n\treturn [process.execPath, ...runtime, entry];\n};\n"],"mappings":";;;;;;;;AAOA,MAAaA,UAAQ,OAAO,GAAG,eAAe,CAAC,CAAC,WAAW,MAAc,MAAc;CACtF,MAAM,KAAK,OAAO,WAAW;CAC7B,OAAO,GAAG,eAAe,OAAO,KAAK,KAAA,CAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC7E,MAAM,OAAO,GAAG,KAAK,GAAG,OAAO,EAAE;CACjC,OAAO,GAAG,gBAAgB,MAAM,MAAM,EAAE,MAAM,IAAM,CAAC;CACrD,OAAO,GAAG,OAAO,MAAM,IAAI;AAC5B,CAAC;;;;;;;;;;;;ACAD,MAAa,OAAO,OAAO,OAAO;;CAEjC,KAAK,OAAO;;CAEZ,SAAS,OAAO;;CAEhB,KAAK,OAAO;;CAEZ,MAAM,OAAO;;CAEb,OAAO,OAAO;AACf,CAAC;AAGD,MAAM,WAAW,OAAO,eAAe,IAAI;;AAG3C,MAAa,QAAQ,SAAiB,GAAG,KAAK;;AAG9C,MAAa,OAAO,WAAmB,GAAG,OAAO;AAEjD,MAAM,SAAS,OAAO,oBAAoB,QAAQ;;AAGlD,MAAa,QAAQ,SACpB,OAAO,IAAI,aAAa;CAEvB,OAAO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Q,QAAQ,KAAK;CAC3B,IAAI,UAAU,KAAA,GAAW,OAAO,CAAC,QAAQ,QAAQ;CACjD,MAAM,UAAU,YAAY,IAAI,SAAS,KAAK,IAAI,QAAQ,WAAW,CAAC;CACtE,OAAO;EAAC,QAAQ;EAAU,GAAG;EAAS;CAAK;AAC5C"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { $ as sign, H as Api, K as PrivateKey, Q as publicOf, U as IdSource, V as ConnectError, W as MachineId, Y as generate, et as thumbprint } from "./error-ippxl2z7.mjs";
|
|
2
|
+
import { t as version } from "./package-DgfSc9nY.mjs";
|
|
3
|
+
import { o as write$1 } from "./registration-C6yiv31r.mjs";
|
|
4
|
+
import { r as hostName } from "./identity-DbK4fABs.mjs";
|
|
5
|
+
import { Clock, Config, Context, Duration, Effect, FileSystem, Layer, Option, Schedule, Schema } from "effect";
|
|
6
|
+
import { FetchHttpClient } from "effect/http";
|
|
7
|
+
import { uuidv7 } from "uuidv7";
|
|
8
|
+
import { HttpApiClient } from "effect/http-api";
|
|
9
|
+
import { NodeServices } from "@effect/platform-node";
|
|
10
|
+
//#region src/machine/file.ts
|
|
11
|
+
/**
|
|
12
|
+
* `<home>/machine.json`: who this home is as a machine, and its link to each connected workspace.
|
|
13
|
+
*
|
|
14
|
+
* It survives restarts (unlike `service.json`, which a server writes and removes) and holds private
|
|
15
|
+
* keys, so it is written 0600, atomically, and under a lock shared by `serve` and `codework connect`.
|
|
16
|
+
*/
|
|
17
|
+
const Link = Schema.Struct({
|
|
18
|
+
name: Schema.String,
|
|
19
|
+
owner: Schema.Struct({
|
|
20
|
+
id: Schema.String,
|
|
21
|
+
name: Schema.NullOr(Schema.String)
|
|
22
|
+
}),
|
|
23
|
+
/** The relay the link was made with; heartbeats and disconnect go there. */
|
|
24
|
+
relay: Schema.String,
|
|
25
|
+
key: PrivateKey,
|
|
26
|
+
keyId: Schema.String,
|
|
27
|
+
/** Left locally, but the relay hasn't confirmed: the key is kept to revoke it once the relay answers. */
|
|
28
|
+
leaving: Schema.optionalKey(Schema.Boolean)
|
|
29
|
+
});
|
|
30
|
+
/** One key per home, vouching for each link key, so the relay knows every link of this home is one machine. */
|
|
31
|
+
const Identity = Schema.Struct({
|
|
32
|
+
key: PrivateKey,
|
|
33
|
+
keyId: Schema.String
|
|
34
|
+
});
|
|
35
|
+
const Machine = Schema.Struct({
|
|
36
|
+
id: Schema.String,
|
|
37
|
+
source: IdSource,
|
|
38
|
+
/** The user's own name for the machine; shown in place of the OS host name when set. */
|
|
39
|
+
givenName: Schema.optional(Schema.String),
|
|
40
|
+
identity: Schema.optional(Identity),
|
|
41
|
+
workspaces: Schema.Record(Schema.String, Link)
|
|
42
|
+
});
|
|
43
|
+
const json = Schema.fromJsonString(Machine);
|
|
44
|
+
var MachineError = class extends Schema.TaggedError()("Machine.MachineError", { message: Schema.String }) {};
|
|
45
|
+
const file = (home) => `${home}/machine.json`;
|
|
46
|
+
/** The machine as stored, or none before its first run. */
|
|
47
|
+
const read = Effect.fn("Machine.read")(function* (home) {
|
|
48
|
+
const fs = yield* FileSystem.FileSystem;
|
|
49
|
+
const path = file(home);
|
|
50
|
+
if (!(yield* fs.exists(path))) return Option.none();
|
|
51
|
+
const text = yield* fs.readFileString(path);
|
|
52
|
+
return Option.some(yield* Schema.decodeEffect(json)(text).pipe(Effect.mapError(() => new MachineError({ message: `${path} is not a valid machine file` }))));
|
|
53
|
+
});
|
|
54
|
+
const locked = (home, effect) => Effect.gen(function* () {
|
|
55
|
+
const fs = yield* FileSystem.FileSystem;
|
|
56
|
+
const lock = `${file(home)}.lock`;
|
|
57
|
+
yield* fs.makeDirectory(home, { recursive: true });
|
|
58
|
+
yield* fs.makeDirectory(lock).pipe(Effect.retry({
|
|
59
|
+
schedule: Schedule.spaced("50 millis"),
|
|
60
|
+
times: 100
|
|
61
|
+
}), Effect.mapError(() => new MachineError({ message: `${lock} is held by another process` })));
|
|
62
|
+
return yield* effect.pipe(Effect.ensuring(fs.remove(lock, { recursive: true }).pipe(Effect.ignore)));
|
|
63
|
+
});
|
|
64
|
+
const write = (home, machine) => Schema.encodeEffect(json)(machine).pipe(Effect.flatMap((encoded) => write$1(file(home), encoded)));
|
|
65
|
+
const newIdentity = Effect.gen(function* () {
|
|
66
|
+
const key = yield* generate();
|
|
67
|
+
return {
|
|
68
|
+
key,
|
|
69
|
+
keyId: yield* thumbprint(publicOf(key))
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
/** Reads, changes and writes the machine under the lock, creating its identity on first use. */
|
|
73
|
+
const update = (home, options, change) => locked(home, Effect.gen(function* () {
|
|
74
|
+
const existing = yield* read(home);
|
|
75
|
+
const machine = yield* Option.match(existing, {
|
|
76
|
+
onNone: () => Effect.succeed(created(options.machineId)),
|
|
77
|
+
onSome: (machine) => options.machineId === void 0 || options.machineId === machine.id ? Effect.succeed(machine) : Effect.fail(new MachineError({ message: `This home is machine ${machine.id}; its id can't change to ${options.machineId}. Use another --home.` }))
|
|
78
|
+
});
|
|
79
|
+
const identity = machine.identity ?? (yield* newIdentity);
|
|
80
|
+
const next = yield* change({
|
|
81
|
+
...machine,
|
|
82
|
+
identity
|
|
83
|
+
});
|
|
84
|
+
yield* write(home, next);
|
|
85
|
+
return next;
|
|
86
|
+
}));
|
|
87
|
+
/** The home's identity, created with the machine on first use. */
|
|
88
|
+
const identity = Effect.fn("Machine.identity")(function* (home) {
|
|
89
|
+
const stored = yield* read(home);
|
|
90
|
+
if (Option.isSome(stored) && stored.value.identity !== void 0) return stored.value.identity;
|
|
91
|
+
return (yield* update(home, {}, Effect.succeed)).identity;
|
|
92
|
+
});
|
|
93
|
+
const created = (machineId) => machineId === void 0 ? {
|
|
94
|
+
id: uuidv7(),
|
|
95
|
+
source: "generated",
|
|
96
|
+
workspaces: {}
|
|
97
|
+
} : {
|
|
98
|
+
id: machineId,
|
|
99
|
+
source: "flag",
|
|
100
|
+
workspaces: {}
|
|
101
|
+
};
|
|
102
|
+
/** Validates a `--machine-id` before anything is written. */
|
|
103
|
+
const checkId = (machineId) => machineId === void 0 || Schema.is(MachineId)(machineId) ? Effect.void : Effect.fail(new MachineError({ message: `--machine-id must be 1-64 lowercase letters, digits or dashes, starting with a letter or digit` }));
|
|
104
|
+
/**
|
|
105
|
+
* Forgets the link to a workspace, only while it still holds `keyId`: a reconnect that saved a new key in
|
|
106
|
+
* the meantime keeps its link.
|
|
107
|
+
*/
|
|
108
|
+
const removeLink = (home, workspaceId, keyId) => update(home, {}, (machine) => {
|
|
109
|
+
const { [workspaceId]: link, ...workspaces } = machine.workspaces;
|
|
110
|
+
return Effect.succeed(link === void 0 || link.keyId !== keyId ? machine : {
|
|
111
|
+
...machine,
|
|
112
|
+
workspaces
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
/** Marks the link as leaving, only while it still holds `keyId`. */
|
|
116
|
+
const markLeaving = (home, workspaceId, keyId) => update(home, {}, (machine) => {
|
|
117
|
+
const link = machine.workspaces[workspaceId];
|
|
118
|
+
return Effect.succeed(link === void 0 || link.keyId !== keyId ? machine : {
|
|
119
|
+
...machine,
|
|
120
|
+
workspaces: {
|
|
121
|
+
...machine.workspaces,
|
|
122
|
+
[workspaceId]: {
|
|
123
|
+
...link,
|
|
124
|
+
leaving: true
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/machine/relay.ts
|
|
131
|
+
/** The relay's typed client at `url`. */
|
|
132
|
+
const at = (url) => HttpApiClient.make(Api, { baseUrl: url }).pipe(Effect.provide(FetchHttpClient.layer));
|
|
133
|
+
/**
|
|
134
|
+
* The relay new connects go to: `CODEWORK_RELAY_URL`, default https://relay.codework.sh. A link keeps
|
|
135
|
+
* talking to the relay it was made with, whatever this says later.
|
|
136
|
+
*/
|
|
137
|
+
var Client = class Client extends Context.Service()("@codeworksh/cli/machine/relay/Client") {
|
|
138
|
+
static layer = Layer.effect(Client, Effect.gen(function* () {
|
|
139
|
+
const url = yield* Config.String("CODEWORK_RELAY_URL").pipe(Config.withDefault("https://relay.codework.sh"));
|
|
140
|
+
return {
|
|
141
|
+
url,
|
|
142
|
+
api: yield* at(url)
|
|
143
|
+
};
|
|
144
|
+
}));
|
|
145
|
+
};
|
|
146
|
+
/** What this machine says about itself to the relay. */
|
|
147
|
+
const describe = Effect.fn("Machine.describe")(function* (machine) {
|
|
148
|
+
const localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));
|
|
149
|
+
return {
|
|
150
|
+
id: machine.id,
|
|
151
|
+
source: machine.source,
|
|
152
|
+
localHostName,
|
|
153
|
+
givenName: machine.givenName ?? null,
|
|
154
|
+
os: process.platform,
|
|
155
|
+
arch: process.arch,
|
|
156
|
+
version
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
/** This machine and its workspaces, as the desktop app shows them. */
|
|
160
|
+
const status = Effect.fn("Machine.status")(function* (home) {
|
|
161
|
+
const stored = yield* read(home);
|
|
162
|
+
const localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));
|
|
163
|
+
if (stored._tag === "None") return {
|
|
164
|
+
id: null,
|
|
165
|
+
localHostName,
|
|
166
|
+
givenName: null,
|
|
167
|
+
workspaces: []
|
|
168
|
+
};
|
|
169
|
+
const machine = stored.value;
|
|
170
|
+
return {
|
|
171
|
+
id: machine.id,
|
|
172
|
+
localHostName,
|
|
173
|
+
givenName: machine.givenName ?? null,
|
|
174
|
+
workspaces: Object.entries(machine.workspaces).map(([id, link]) => ({
|
|
175
|
+
id,
|
|
176
|
+
name: link.name,
|
|
177
|
+
keyId: link.keyId,
|
|
178
|
+
leaving: link.leaving === true
|
|
179
|
+
}))
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
/**
|
|
183
|
+
* Names this machine for people: empty clears the name back to the OS's. The relay hears it on the
|
|
184
|
+
* next heartbeat.
|
|
185
|
+
*/
|
|
186
|
+
const rename = Effect.fn("Machine.rename")(function* (home, givenName) {
|
|
187
|
+
const name = givenName.trim();
|
|
188
|
+
yield* update(home, {}, ({ givenName: _previous, ...machine }) => Effect.succeed(name === "" ? machine : {
|
|
189
|
+
...machine,
|
|
190
|
+
givenName: name
|
|
191
|
+
}));
|
|
192
|
+
return yield* status(home);
|
|
193
|
+
});
|
|
194
|
+
/**
|
|
195
|
+
* Pairs this home with a workspace: registers a fresh key with the relay, shows the code a member
|
|
196
|
+
* approves, and polls with that key until the relay links it, then saves the link. Each workspace gets
|
|
197
|
+
* its own key, and only this process can take the link: a connect that stops is never linked.
|
|
198
|
+
*/
|
|
199
|
+
const connect = Effect.fn("Machine.connect")(function* (options) {
|
|
200
|
+
const client = yield* Client;
|
|
201
|
+
yield* checkId(options.machineId);
|
|
202
|
+
const machine = yield* update(options.home, { machineId: options.machineId }, Effect.succeed);
|
|
203
|
+
const key = yield* generate();
|
|
204
|
+
const keyId = yield* thumbprint(publicOf(key));
|
|
205
|
+
const iat = yield* Clock.currentTimeMillis;
|
|
206
|
+
const binding = {
|
|
207
|
+
op: "identity.bind",
|
|
208
|
+
iat,
|
|
209
|
+
keyId
|
|
210
|
+
};
|
|
211
|
+
const claims = {
|
|
212
|
+
op: "pairing.create",
|
|
213
|
+
iat,
|
|
214
|
+
machine: yield* describe(machine),
|
|
215
|
+
workspaceId: options.workspaceId ?? null,
|
|
216
|
+
identity: yield* sign(binding, machine.identity.key, { embed: true })
|
|
217
|
+
};
|
|
218
|
+
const pairing = yield* client.api.machine.pair({ payload: { jws: yield* sign(claims, key, { embed: true }) } }).pipe(Effect.catchTag("Relay.NotFound", () => Effect.fail(new ConnectError({ message: "No such workspace" }))));
|
|
219
|
+
yield* options.onCode(pairing.userCode);
|
|
220
|
+
const poll = Effect.gen(function* () {
|
|
221
|
+
const claims = {
|
|
222
|
+
op: "pairing.poll",
|
|
223
|
+
iat: yield* Clock.currentTimeMillis
|
|
224
|
+
};
|
|
225
|
+
return yield* client.api.machine.poll({ payload: { jws: yield* sign(claims, key, { kid: keyId }) } });
|
|
226
|
+
}).pipe(Effect.catchTag("HttpClientError", (error) => Effect.logDebug("Pairing poll failed", error).pipe(Effect.as(void 0))));
|
|
227
|
+
let previous = machine;
|
|
228
|
+
const deadline = (yield* Clock.currentTimeMillis) + pairing.expiresIn * 1e3;
|
|
229
|
+
while ((yield* Clock.currentTimeMillis) < deadline) {
|
|
230
|
+
yield* Effect.sleep(Duration.seconds(pairing.interval));
|
|
231
|
+
const status = yield* poll;
|
|
232
|
+
if (status === void 0) continue;
|
|
233
|
+
if (status.status !== "approved") {
|
|
234
|
+
if (status.status === "pending") continue;
|
|
235
|
+
if (status.status === "expired") break;
|
|
236
|
+
return yield* new ConnectError({ message: status.status === "declined" ? "The connect was declined; run connect again for a new code" : "Another connect for this machine finished first" });
|
|
237
|
+
}
|
|
238
|
+
const { connected } = status;
|
|
239
|
+
const id = connected.workspace.id;
|
|
240
|
+
const stored = yield* update(options.home, {}, (current) => Effect.succeed(current.workspaces[id]?.keyId !== previous.workspaces[id]?.keyId ? current : {
|
|
241
|
+
...current,
|
|
242
|
+
workspaces: {
|
|
243
|
+
...current.workspaces,
|
|
244
|
+
[connected.workspace.id]: {
|
|
245
|
+
name: connected.workspace.name,
|
|
246
|
+
owner: connected.owner,
|
|
247
|
+
relay: client.url,
|
|
248
|
+
key,
|
|
249
|
+
keyId
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}));
|
|
253
|
+
if (stored.workspaces[id]?.keyId === keyId) return connected;
|
|
254
|
+
previous = stored;
|
|
255
|
+
}
|
|
256
|
+
return yield* new ConnectError({ message: "The code expired before it was approved; run connect again" });
|
|
257
|
+
});
|
|
258
|
+
/**
|
|
259
|
+
* Asks the link's relay to revoke it, signed with its own key: true once the relay confirms, or says it
|
|
260
|
+
* was revoked already; false when it can't be reached in time.
|
|
261
|
+
*/
|
|
262
|
+
const revoke = (machineId, workspaceId, link) => Effect.gen(function* () {
|
|
263
|
+
const claims = {
|
|
264
|
+
op: "machine.revoke",
|
|
265
|
+
iat: yield* Clock.currentTimeMillis,
|
|
266
|
+
jti: uuidv7(),
|
|
267
|
+
workspaceId,
|
|
268
|
+
machineId
|
|
269
|
+
};
|
|
270
|
+
yield* (yield* at(link.relay)).machine.revoke({ payload: { jws: yield* sign(claims, link.key, { kid: link.keyId }) } });
|
|
271
|
+
}).pipe(Effect.timeout("3 seconds"), Effect.as(true), Effect.catchTag("Relay.MachineRevoked", () => Effect.succeed(true)), Effect.catch((error) => Effect.logDebug(`Revoke at ${link.name} failed`, error).pipe(Effect.as(false))));
|
|
272
|
+
/**
|
|
273
|
+
* One heartbeat per connected workspace, each to the relay its link was made with, all at once. A link
|
|
274
|
+
* the relay refuses as revoked is removed, but only while it still holds the refused key. A leaving link
|
|
275
|
+
* asks for its revoke again instead, and is removed once the relay confirms.
|
|
276
|
+
*/
|
|
277
|
+
const heartbeat = Effect.fn("Machine.heartbeat")(function* (home) {
|
|
278
|
+
const stored = yield* read(home);
|
|
279
|
+
if (stored._tag === "None") return;
|
|
280
|
+
const machine = stored.value;
|
|
281
|
+
const info = yield* describe(machine);
|
|
282
|
+
yield* Effect.forEach(Object.entries(machine.workspaces), ([workspaceId, link]) => link.leaving === true ? revoke(machine.id, workspaceId, link).pipe(Effect.flatMap((revoked) => revoked ? removeLink(home, workspaceId, link.keyId).pipe(Effect.asVoid) : Effect.void), Effect.catch((error) => Effect.logDebug(`Leaving ${link.name} failed`, error))) : Effect.gen(function* () {
|
|
283
|
+
const api = yield* at(link.relay);
|
|
284
|
+
const claims = {
|
|
285
|
+
op: "machine.heartbeat",
|
|
286
|
+
iat: yield* Clock.currentTimeMillis,
|
|
287
|
+
workspaceId,
|
|
288
|
+
machine: info
|
|
289
|
+
};
|
|
290
|
+
yield* api.machine.heartbeat({ payload: { jws: yield* sign(claims, link.key, { kid: link.keyId }) } });
|
|
291
|
+
}).pipe(Effect.timeout("10 seconds"), Effect.catchTags({
|
|
292
|
+
"Relay.MachineRevoked": (revoked) => Effect.logWarning(`Disconnected from ${link.name}: ${revoked.message}`).pipe(Effect.andThen(removeLink(home, workspaceId, link.keyId))),
|
|
293
|
+
"Relay.Unauthorized": (refused) => Effect.logWarning(`Heartbeat to ${link.name} refused: ${refused.message}`)
|
|
294
|
+
}), Effect.catch((error) => Effect.logDebug(`Heartbeat to ${link.name} failed`, error))), {
|
|
295
|
+
concurrency: "unbounded",
|
|
296
|
+
discard: true
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
/**
|
|
300
|
+
* Leaves a workspace: asks the link's relay to revoke it, then forgets it locally. When the relay can't
|
|
301
|
+
* confirm, the link is kept as leaving, with its key, and each heartbeat asks again until it does; the
|
|
302
|
+
* relay still lists it until then. `revoked` says whether it confirmed now.
|
|
303
|
+
*/
|
|
304
|
+
const disconnect = Effect.fn("Machine.disconnect")(function* (home, workspaceId, expectedKeyId) {
|
|
305
|
+
const stored = yield* read(home);
|
|
306
|
+
const link = stored._tag === "Some" ? stored.value.workspaces[workspaceId] : void 0;
|
|
307
|
+
if (stored._tag === "None" || link === void 0) return yield* new ConnectError({ message: `This machine is not connected to workspace ${workspaceId}` });
|
|
308
|
+
if (expectedKeyId !== void 0 && link.keyId !== expectedKeyId) return yield* new ConnectError({ message: "This machine link has changed" });
|
|
309
|
+
const revoked = yield* revoke(stored.value.id, workspaceId, link);
|
|
310
|
+
yield* revoked ? removeLink(home, workspaceId, link.keyId) : markLeaving(home, workspaceId, link.keyId);
|
|
311
|
+
return {
|
|
312
|
+
workspace: link.name,
|
|
313
|
+
revoked
|
|
314
|
+
};
|
|
315
|
+
});
|
|
316
|
+
//#endregion
|
|
317
|
+
export { rename as a, read as c, heartbeat as i, connect as n, status as o, disconnect as r, identity as s, Client as t };
|
|
318
|
+
|
|
319
|
+
//# sourceMappingURL=relay-CLPWErNw.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-CLPWErNw.mjs","names":["Jws.PrivateKey","Relay.IdSource","Private.write","Jws.generate","Jws.thumbprint","Jws.publicOf","Relay.MachineId","Relay.Api","pkg.version","File.read","File.update","File.checkId","Jws.generate","Jws.thumbprint","Jws.publicOf","Jws.sign","Machine.ConnectError","File.removeLink","File.markLeaving"],"sources":["../../src/machine/file.ts","../../src/machine/relay.ts"],"sourcesContent":["import { Jws, Relay } from \"@codeworksh/schema\";\nimport { Effect, FileSystem, Option, Schedule, Schema } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\nimport * as Private from \"../framework/private.ts\";\n\n/**\n * `<home>/machine.json`: who this home is as a machine, and its link to each connected workspace.\n *\n * It survives restarts (unlike `service.json`, which a server writes and removes) and holds private\n * keys, so it is written 0600, atomically, and under a lock shared by `serve` and `codework connect`.\n */\nconst Link = Schema.Struct({\n\tname: Schema.String,\n\towner: Schema.Struct({ id: Schema.String, name: Schema.NullOr(Schema.String) }),\n\t/** The relay the link was made with; heartbeats and disconnect go there. */\n\trelay: Schema.String,\n\tkey: Jws.PrivateKey,\n\tkeyId: Schema.String,\n\t/** Left locally, but the relay hasn't confirmed: the key is kept to revoke it once the relay answers. */\n\tleaving: Schema.optionalKey(Schema.Boolean),\n});\n\n/** One key per home, vouching for each link key, so the relay knows every link of this home is one machine. */\nconst Identity = Schema.Struct({ key: Jws.PrivateKey, keyId: Schema.String });\ntype Identity = typeof Identity.Type;\n\nexport const Machine = Schema.Struct({\n\tid: Schema.String,\n\tsource: Relay.IdSource,\n\t/** The user's own name for the machine; shown in place of the OS host name when set. */\n\tgivenName: Schema.optional(Schema.String),\n\t// Optional only for homes connected before identities existed; `update` gives every home one.\n\tidentity: Schema.optional(Identity),\n\tworkspaces: Schema.Record(Schema.String, Link),\n});\nexport type Machine = typeof Machine.Type;\n/** The machine as {@link update} hands it out: always with its identity. */\ntype Identified = Machine & { readonly identity: Identity };\n\nconst json = Schema.fromJsonString(Machine);\n\nclass MachineError extends Schema.TaggedError<MachineError>()(\"Machine.MachineError\", {\n\tmessage: Schema.String,\n}) {}\n\nconst file = (home: string) => `${home}/machine.json`;\n\n/** The machine as stored, or none before its first run. */\nexport const read = Effect.fn(\"Machine.read\")(function* (home: string) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst path = file(home);\n\tif (!(yield* fs.exists(path))) return Option.none<Machine>();\n\tconst text = yield* fs.readFileString(path);\n\treturn Option.some(\n\t\tyield* Schema.decodeEffect(json)(text).pipe(\n\t\t\tEffect.mapError(() => new MachineError({ message: `${path} is not a valid machine file` })),\n\t\t),\n\t);\n});\n\n// One writer at a time: creating a directory either succeeds or fails, so it serves as a lock.\nconst locked = <A, E, R>(home: string, effect: Effect.Effect<A, E, R>) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst lock = `${file(home)}.lock`;\n\t\tyield* fs.makeDirectory(home, { recursive: true });\n\t\tyield* fs.makeDirectory(lock).pipe(\n\t\t\tEffect.retry({ schedule: Schedule.spaced(\"50 millis\"), times: 100 }),\n\t\t\tEffect.mapError(() => new MachineError({ message: `${lock} is held by another process` })),\n\t\t);\n\t\treturn yield* effect.pipe(Effect.ensuring(fs.remove(lock, { recursive: true }).pipe(Effect.ignore)));\n\t});\n\nconst write = (home: string, machine: Machine) =>\n\tSchema.encodeEffect(json)(machine).pipe(Effect.flatMap((encoded) => Private.write(file(home), encoded)));\n\nconst newIdentity = Effect.gen(function* () {\n\tconst key = yield* Jws.generate();\n\treturn { key, keyId: yield* Jws.thumbprint(Jws.publicOf(key)) } satisfies Identity;\n});\n\n/** Reads, changes and writes the machine under the lock, creating its identity on first use. */\nexport const update = <E, R>(\n\thome: string,\n\toptions: { readonly machineId?: string | undefined },\n\tchange: (machine: Identified) => Effect.Effect<Identified, E, R>,\n) =>\n\tlocked(\n\t\thome,\n\t\tEffect.gen(function* () {\n\t\t\tconst existing = yield* read(home);\n\t\t\tconst machine = yield* Option.match(existing, {\n\t\t\t\tonNone: () => Effect.succeed(created(options.machineId)),\n\t\t\t\tonSome: (machine) =>\n\t\t\t\t\toptions.machineId === undefined || options.machineId === machine.id\n\t\t\t\t\t\t? Effect.succeed(machine)\n\t\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\t\tnew MachineError({\n\t\t\t\t\t\t\t\t\tmessage: `This home is machine ${machine.id}; its id can't change to ${options.machineId}. Use another --home.`,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t});\n\t\t\tconst identity = machine.identity ?? (yield* newIdentity);\n\t\t\tconst next = yield* change({ ...machine, identity });\n\t\t\tyield* write(home, next);\n\t\t\treturn next;\n\t\t}),\n\t);\n\n/** The home's identity, created with the machine on first use. */\nexport const identity = Effect.fn(\"Machine.identity\")(function* (home: string) {\n\tconst stored = yield* read(home);\n\tif (Option.isSome(stored) && stored.value.identity !== undefined) return stored.value.identity;\n\treturn (yield* update(home, {}, Effect.succeed)).identity;\n});\n\nconst created = (machineId: string | undefined): Machine =>\n\tmachineId === undefined\n\t\t? { id: uuidv7(), source: \"generated\", workspaces: {} }\n\t\t: { id: machineId, source: \"flag\", workspaces: {} };\n\n/** Validates a `--machine-id` before anything is written. */\nexport const checkId = (machineId: string | undefined) =>\n\tmachineId === undefined || Schema.is(Relay.MachineId)(machineId)\n\t\t? Effect.void\n\t\t: Effect.fail(\n\t\t\t\tnew MachineError({\n\t\t\t\t\tmessage: `--machine-id must be 1-64 lowercase letters, digits or dashes, starting with a letter or digit`,\n\t\t\t\t}),\n\t\t\t);\n\n/**\n * Forgets the link to a workspace, only while it still holds `keyId`: a reconnect that saved a new key in\n * the meantime keeps its link.\n */\nexport const removeLink = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst { [workspaceId]: link, ...workspaces } = machine.workspaces;\n\t\treturn Effect.succeed(link === undefined || link.keyId !== keyId ? machine : { ...machine, workspaces });\n\t});\n\n/** Marks the link as leaving, only while it still holds `keyId`. */\nexport const markLeaving = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst link = machine.workspaces[workspaceId];\n\t\treturn Effect.succeed(\n\t\t\tlink === undefined || link.keyId !== keyId\n\t\t\t\t? machine\n\t\t\t\t: { ...machine, workspaces: { ...machine.workspaces, [workspaceId]: { ...link, leaving: true } } },\n\t\t);\n\t});\n","import { NodeServices } from \"@effect/platform-node\";\nimport { Jws, Machine, Relay } from \"@codeworksh/schema\";\nimport { Clock, Config, Context, Duration, Effect, Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { HttpApiClient } from \"effect/http-api\";\nimport { uuidv7 } from \"uuidv7\";\nimport pkg from \"../../package.json\" with { type: \"json\" };\nimport { hostName } from \"../server/identity.ts\";\nimport * as File from \"./file.ts\";\n\n/** The relay's typed client at `url`. */\nconst at = (url: string) => HttpApiClient.make(Relay.Api, { baseUrl: url }).pipe(Effect.provide(FetchHttpClient.layer));\n\n/**\n * The relay new connects go to: `CODEWORK_RELAY_URL`, default https://relay.codework.sh. A link keeps\n * talking to the relay it was made with, whatever this says later.\n */\nexport class Client extends Context.Service<\n\tClient,\n\t{ readonly url: string; readonly api: HttpApiClient.ForApi<typeof Relay.Api> }\n>()(\"@codeworksh/cli/machine/relay/Client\") {\n\tstatic readonly layer = Layer.effect(\n\t\tClient,\n\t\tEffect.gen(function* () {\n\t\t\tconst url = yield* Config.String(\"CODEWORK_RELAY_URL\").pipe(Config.withDefault(\"https://relay.codework.sh\"));\n\t\t\treturn { url, api: yield* at(url) };\n\t\t}),\n\t);\n}\n\n/** What this machine says about itself to the relay. */\nconst describe = Effect.fn(\"Machine.describe\")(function* (machine: File.Machine) {\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\treturn {\n\t\tid: machine.id,\n\t\tsource: machine.source,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tos: process.platform,\n\t\tarch: process.arch,\n\t\tversion: pkg.version,\n\t} satisfies Relay.MachineInfo;\n});\n\n/** This machine and its workspaces, as the desktop app shows them. */\nexport const status = Effect.fn(\"Machine.status\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\tif (stored._tag === \"None\")\n\t\treturn { id: null, localHostName, givenName: null, workspaces: [] } satisfies Machine.Status;\n\tconst machine = stored.value;\n\treturn {\n\t\tid: machine.id,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tworkspaces: Object.entries(machine.workspaces).map(([id, link]) => ({\n\t\t\tid,\n\t\t\tname: link.name,\n\t\t\tkeyId: link.keyId,\n\t\t\tleaving: link.leaving === true,\n\t\t})),\n\t} satisfies Machine.Status;\n});\n\n/**\n * Names this machine for people: empty clears the name back to the OS's. The relay hears it on the\n * next heartbeat.\n */\nexport const rename = Effect.fn(\"Machine.rename\")(function* (home: string, givenName: string) {\n\tconst name = givenName.trim();\n\tyield* File.update(home, {}, ({ givenName: _previous, ...machine }) =>\n\t\tEffect.succeed(name === \"\" ? machine : { ...machine, givenName: name }),\n\t);\n\treturn yield* status(home);\n});\n\n/**\n * Pairs this home with a workspace: registers a fresh key with the relay, shows the code a member\n * approves, and polls with that key until the relay links it, then saves the link. Each workspace gets\n * its own key, and only this process can take the link: a connect that stops is never linked.\n */\nexport const connect = Effect.fn(\"Machine.connect\")(function* (options: {\n\treadonly home: string;\n\treadonly workspaceId?: string | undefined;\n\treadonly machineId?: string | undefined;\n\treadonly onCode: (userCode: string) => Effect.Effect<void>;\n}) {\n\tconst client = yield* Client;\n\tyield* File.checkId(options.machineId);\n\tconst machine = yield* File.update(options.home, { machineId: options.machineId }, Effect.succeed);\n\tconst key = yield* Jws.generate();\n\tconst keyId = yield* Jws.thumbprint(Jws.publicOf(key));\n\tconst iat = yield* Clock.currentTimeMillis;\n\tconst binding: Relay.IdentityClaims = { op: \"identity.bind\", iat, keyId };\n\tconst claims: Relay.PairingClaims = {\n\t\top: \"pairing.create\",\n\t\tiat,\n\t\tmachine: yield* describe(machine),\n\t\tworkspaceId: options.workspaceId ?? null,\n\t\tidentity: yield* Jws.sign(binding, machine.identity.key, { embed: true }),\n\t};\n\tconst pairing = yield* client.api.machine\n\t\t.pair({ payload: { jws: yield* Jws.sign(claims, key, { embed: true }) } })\n\t\t.pipe(\n\t\t\tEffect.catchTag(\"Relay.NotFound\", () =>\n\t\t\t\tEffect.fail(new Machine.ConnectError({ message: \"No such workspace\" })),\n\t\t\t),\n\t\t);\n\tyield* options.onCode(pairing.userCode);\n\n\tconst poll = Effect.gen(function* () {\n\t\tconst claims: Relay.PollClaims = { op: \"pairing.poll\", iat: yield* Clock.currentTimeMillis };\n\t\treturn yield* client.api.machine.poll({ payload: { jws: yield* Jws.sign(claims, key, { kid: keyId }) } });\n\t}).pipe(\n\t\t// A dropped request or a relay restart doesn't end the connect; the next poll asks again.\n\t\tEffect.catchTag(\"HttpClientError\", (error) =>\n\t\t\tEffect.logDebug(\"Pairing poll failed\", error).pipe(Effect.as(undefined)),\n\t\t),\n\t);\n\tlet previous = machine;\n\tconst deadline = (yield* Clock.currentTimeMillis) + pairing.expiresIn * 1000;\n\twhile ((yield* Clock.currentTimeMillis) < deadline) {\n\t\tyield* Effect.sleep(Duration.seconds(pairing.interval));\n\t\tconst status = yield* poll;\n\t\tif (status === undefined) continue;\n\t\tif (status.status !== \"approved\") {\n\t\t\tif (status.status === \"pending\") continue;\n\t\t\tif (status.status === \"expired\") break;\n\t\t\treturn yield* new Machine.ConnectError({\n\t\t\t\tmessage:\n\t\t\t\t\tstatus.status === \"declined\"\n\t\t\t\t\t\t? \"The connect was declined; run connect again for a new code\"\n\t\t\t\t\t\t: \"Another connect for this machine finished first\",\n\t\t\t});\n\t\t}\n\t\tconst { connected } = status;\n\t\t// A poll response can arrive after another connect saved a different key.\n\t\t// Observe that change under the lock, then poll again before replacing it.\n\t\tconst id = connected.workspace.id;\n\t\tconst stored = yield* File.update(options.home, {}, (current) =>\n\t\t\tEffect.succeed(\n\t\t\t\tcurrent.workspaces[id]?.keyId !== previous.workspaces[id]?.keyId\n\t\t\t\t\t? current\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t...current,\n\t\t\t\t\t\t\tworkspaces: {\n\t\t\t\t\t\t\t\t...current.workspaces,\n\t\t\t\t\t\t\t\t[connected.workspace.id]: {\n\t\t\t\t\t\t\t\t\tname: connected.workspace.name,\n\t\t\t\t\t\t\t\t\towner: connected.owner,\n\t\t\t\t\t\t\t\t\trelay: client.url,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tkeyId,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t),\n\t\t);\n\t\tif (stored.workspaces[id]?.keyId === keyId) return connected;\n\t\tprevious = stored;\n\t}\n\treturn yield* new Machine.ConnectError({ message: \"The code expired before it was approved; run connect again\" });\n});\n\n/**\n * Asks the link's relay to revoke it, signed with its own key: true once the relay confirms, or says it\n * was revoked already; false when it can't be reached in time.\n */\nconst revoke = (machineId: string, workspaceId: string, link: File.Machine[\"workspaces\"][string]) =>\n\tEffect.gen(function* () {\n\t\tconst claims: Relay.RevokeClaims = {\n\t\t\top: \"machine.revoke\",\n\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\tjti: uuidv7(),\n\t\t\tworkspaceId,\n\t\t\tmachineId,\n\t\t};\n\t\tconst api = yield* at(link.relay);\n\t\tyield* api.machine.revoke({ payload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) } });\n\t}).pipe(\n\t\t// Leave time for the local update before the desktop RPC expires.\n\t\tEffect.timeout(\"3 seconds\"),\n\t\tEffect.as(true),\n\t\tEffect.catchTag(\"Relay.MachineRevoked\", () => Effect.succeed(true)),\n\t\tEffect.catch((error) => Effect.logDebug(`Revoke at ${link.name} failed`, error).pipe(Effect.as(false))),\n\t);\n\n/**\n * One heartbeat per connected workspace, each to the relay its link was made with, all at once. A link\n * the relay refuses as revoked is removed, but only while it still holds the refused key. A leaving link\n * asks for its revoke again instead, and is removed once the relay confirms.\n */\nexport const heartbeat = Effect.fn(\"Machine.heartbeat\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tif (stored._tag === \"None\") return;\n\tconst machine = stored.value;\n\tconst info = yield* describe(machine);\n\tyield* Effect.forEach(\n\t\tObject.entries(machine.workspaces),\n\t\t([workspaceId, link]) =>\n\t\t\tlink.leaving === true\n\t\t\t\t? revoke(machine.id, workspaceId, link).pipe(\n\t\t\t\t\t\tEffect.flatMap((revoked) =>\n\t\t\t\t\t\t\trevoked ? File.removeLink(home, workspaceId, link.keyId).pipe(Effect.asVoid) : Effect.void,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Leaving ${link.name} failed`, error)),\n\t\t\t\t\t)\n\t\t\t\t: Effect.gen(function* () {\n\t\t\t\t\t\tconst api = yield* at(link.relay);\n\t\t\t\t\t\tconst claims: Relay.HeartbeatClaims = {\n\t\t\t\t\t\t\top: \"machine.heartbeat\",\n\t\t\t\t\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\t\t\t\t\tworkspaceId,\n\t\t\t\t\t\t\tmachine: info,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tyield* api.machine.heartbeat({\n\t\t\t\t\t\t\tpayload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) },\n\t\t\t\t\t\t});\n\t\t\t\t\t}).pipe(\n\t\t\t\t\t\tEffect.timeout(\"10 seconds\"),\n\t\t\t\t\t\tEffect.catchTags({\n\t\t\t\t\t\t\t\"Relay.MachineRevoked\": (revoked) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Disconnected from ${link.name}: ${revoked.message}`).pipe(\n\t\t\t\t\t\t\t\t\tEffect.andThen(File.removeLink(home, workspaceId, link.keyId)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t// Refused but not revoked, most often a clock more than a minute off: worth seeing in the log.\n\t\t\t\t\t\t\t\"Relay.Unauthorized\": (refused) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Heartbeat to ${link.name} refused: ${refused.message}`),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Heartbeat to ${link.name} failed`, error)),\n\t\t\t\t\t),\n\t\t{ concurrency: \"unbounded\", discard: true },\n\t);\n});\n\n/**\n * Leaves a workspace: asks the link's relay to revoke it, then forgets it locally. When the relay can't\n * confirm, the link is kept as leaving, with its key, and each heartbeat asks again until it does; the\n * relay still lists it until then. `revoked` says whether it confirmed now.\n */\nexport const disconnect = Effect.fn(\"Machine.disconnect\")(function* (\n\thome: string,\n\tworkspaceId: string,\n\texpectedKeyId?: string,\n) {\n\tconst stored = yield* File.read(home);\n\tconst link = stored._tag === \"Some\" ? stored.value.workspaces[workspaceId] : undefined;\n\tif (stored._tag === \"None\" || link === undefined) {\n\t\treturn yield* new Machine.ConnectError({ message: `This machine is not connected to workspace ${workspaceId}` });\n\t}\n\tif (expectedKeyId !== undefined && link.keyId !== expectedKeyId)\n\t\treturn yield* new Machine.ConnectError({ message: \"This machine link has changed\" });\n\tconst revoked = yield* revoke(stored.value.id, workspaceId, link);\n\tyield* revoked ? File.removeLink(home, workspaceId, link.keyId) : File.markLeaving(home, workspaceId, link.keyId);\n\treturn { workspace: link.name, revoked };\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAM,OAAO,OAAO,OAAO;CAC1B,MAAM,OAAO;CACb,OAAO,OAAO,OAAO;EAAE,IAAI,OAAO;EAAQ,MAAM,OAAO,OAAO,OAAO,MAAM;CAAE,CAAC;;CAE9E,OAAO,OAAO;CACd,KAAKA;CACL,OAAO,OAAO;;CAEd,SAAS,OAAO,YAAY,OAAO,OAAO;AAC3C,CAAC;;AAGD,MAAM,WAAW,OAAO,OAAO;CAAE,KAAKA;CAAgB,OAAO,OAAO;AAAO,CAAC;AAG5E,MAAa,UAAU,OAAO,OAAO;CACpC,IAAI,OAAO;CACX,QAAQC;;CAER,WAAW,OAAO,SAAS,OAAO,MAAM;CAExC,UAAU,OAAO,SAAS,QAAQ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AAO,OAAO,SAAS,SAAS,OAAO,MAAM,WAAW,eAAe,KAAA;CAC7E,IAAI,OAAO,SAAS,UAAU,SAAS,KAAA,GACtC,OAAO,OAAO,IAAIO,aAAqB,EAAE,SAAS,8CAA8C,cAAc,CAAC;CAEhH,IAAI,kBAAkB,KAAA,KAAa,KAAK,UAAU,eACjD,OAAO,OAAO,IAAIA,aAAqB,EAAE,SAAS,gCAAgC,CAAC;CACpF,MAAM,UAAU,OAAO,OAAO,OAAO,MAAM,IAAI,aAAa,IAAI;CAChE,OAAO,UAAUC,WAAgB,MAAM,aAAa,KAAK,KAAK,IAAIC,YAAiB,MAAM,aAAa,KAAK,KAAK;CAChH,OAAO;EAAE,WAAW,KAAK;EAAM;CAAQ;AACxC,CAAC"}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { a as reportFailure, g as make, m as writeOut, p as writeJson, x as ThreadInfo } from "./error-ippxl2z7.mjs";
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
+
import { t as connect } from "./service-CRnqz89w.mjs";
|
|
4
|
+
import { n as threadFlag, t as sessionId } from "./ids-cNIRx0-c.mjs";
|
|
4
5
|
import { Effect, Option } from "effect";
|
|
5
|
-
import { Sandbox
|
|
6
|
+
import { Sandbox } from "@codeworksh/harness/effect";
|
|
6
7
|
//#region src/cli/cmd/handlers/session/relink.ts
|
|
7
8
|
var relink_default = handler(Cmd.commands.session.commands.relink, Effect.fn("CLI.session.relink")(function* ({ session, thread, directory, sandboxId, json, server }) {
|
|
9
|
+
const id = yield* sessionId(session);
|
|
8
10
|
return yield* Effect.gen(function* () {
|
|
9
11
|
const threadId = yield* threadFlag(thread);
|
|
10
12
|
const info = yield* (yield* make)["session.relink"]({
|
|
11
|
-
sessionId:
|
|
13
|
+
sessionId: id,
|
|
12
14
|
...threadId === void 0 ? {} : { threadId },
|
|
13
15
|
...Option.isNone(sandboxId) ? {} : { sandbox: { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) } },
|
|
14
16
|
...Option.isNone(directory) ? {} : { directory: directory.value }
|
|
15
17
|
});
|
|
16
18
|
if (json) return yield* writeJson(ThreadInfo, info);
|
|
17
19
|
yield* writeOut(threadId === void 0 ? `Moved ${info.session.id} to ${info.session.directory}\n` : `Moved thread ${info.id} of ${info.session.id} to ${info.placement?.directory ?? info.session.directory}\n`);
|
|
18
|
-
}).pipe(
|
|
20
|
+
}).pipe(connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));
|
|
19
21
|
}));
|
|
20
22
|
//#endregion
|
|
21
23
|
export { relink_default as default };
|
|
22
24
|
|
|
23
|
-
//# sourceMappingURL=relink-
|
|
25
|
+
//# sourceMappingURL=relink-D8Koos_q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relink-D8Koos_q.mjs","names":["Runtime.handler","Client.make","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,UAAU,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,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a as reportFailure, g as make, m as writeOut } from "./error-ippxl2z7.mjs";
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
+
import { t as connect } from "./service-CRnqz89w.mjs";
|
|
4
|
+
import { Effect, Option } from "effect";
|
|
4
5
|
//#region src/cli/cmd/handlers/plugin/reload.ts
|
|
5
6
|
/**
|
|
6
7
|
* Re-import every configured plugin in a running server.
|
|
@@ -18,9 +19,9 @@ var reload_default = handler(Cmd.commands.plugin.commands.reload, Effect.fn("CLI
|
|
|
18
19
|
const result = yield* (yield* make)["plugin.reload"]({});
|
|
19
20
|
yield* writeOut(result.failure === void 0 ? `Reloaded ${result.plugins} plugin${result.plugins === 1 ? "" : "s"}.\n` : `Reload failed, keeping ${result.plugins} loaded: ${result.failure}\n`);
|
|
20
21
|
if (result.failure !== void 0) process.exitCode = 1;
|
|
21
|
-
}).pipe(
|
|
22
|
+
}).pipe(connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));
|
|
22
23
|
}));
|
|
23
24
|
//#endregion
|
|
24
25
|
export { reload_default as default };
|
|
25
26
|
|
|
26
|
-
//# sourceMappingURL=reload-
|
|
27
|
+
//# sourceMappingURL=reload-C5-B0s9x.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload-
|
|
1
|
+
{"version":3,"file":"reload-C5-B0s9x.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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as resolveTarget, c as withPluginsLock, i as readPlugins, l as writePlugins, o as spellings, r as matching, t as identify } from "./settings-
|
|
1
|
+
import { a as reportFailure, m as writeOut } from "./error-ippxl2z7.mjs";
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
+
import { a as resolveTarget, c as withPluginsLock, i as readPlugins, l as writePlugins, o as spellings, r as matching, t as identify } from "./settings-DU140UBM.mjs";
|
|
4
4
|
import { Effect, FileSystem, Option, Path } from "effect";
|
|
5
5
|
import { Global } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/plugin/remove.ts
|
|
@@ -34,4 +34,4 @@ var remove_default = handler(Cmd.commands.plugin.commands.remove, Effect.fn("CLI
|
|
|
34
34
|
//#endregion
|
|
35
35
|
export { remove_default as default };
|
|
36
36
|
|
|
37
|
-
//# sourceMappingURL=remove-
|
|
37
|
+
//# sourceMappingURL=remove-6m5n17il.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-6m5n17il.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/plugin/remove.ts"],"sourcesContent":["import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, FileSystem, Option, Path } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tidentify,\n\tmatching,\n\treadPlugins,\n\tresolveTarget,\n\tspellings,\n\twithPluginsLock,\n\twritePlugins,\n} from \"./settings.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.plugin.commands.remove,\n\tEffect.fn(\"CLI.plugin.remove\")(function* ({ package: reference, global: userWide }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst shared = yield* Cmd.spec;\n\t\t\tconst path = yield* Path.Path;\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\t\t\tconst target = yield* resolveTarget(shared, userWide, undefined, false);\n\t\t\t// Removing from a directory that is not a project is a read-only no-op. In particular, it\n\t\t\t// must not create the marker that would make this directory shadow a real project later.\n\t\t\tif (!(yield* fs.exists(path.dirname(target.path)))) {\n\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst spelled = yield* spellings(reference, path.resolve(\".\"));\n\t\t\tyield* withPluginsLock(\n\t\t\t\ttarget.path,\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { source, plugins } = yield* readPlugins(target.path);\n\t\t\t\t\t// Both the module entry and any configuration written against it: the package it was\n\t\t\t\t\t// added as, the path or version it was written with, and the ID it declares all name\n\t\t\t\t\t// the one plugin being removed.\n\t\t\t\t\tconst entries = yield* identify(plugins, target.path, paths.cache);\n\t\t\t\t\tconst selected = matching(entries, spelled);\n\t\t\t\t\tconst kept = entries.filter((entry) => !selected.has(entry)).map((entry) => entry.value);\n\t\t\t\t\tif (kept.length === plugins.length) {\n\t\t\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tyield* writePlugins(target.path, source, kept);\n\t\t\t\t\tconst dropped = plugins.length - kept.length;\n\t\t\t\t\tyield* writeOut(\n\t\t\t\t\t\t`Removed ${dropped} ${dropped === 1 ? \"entry\" : \"entries\"} for \"${reference}\" from ${target.path}\\n`,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,iBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,QAC7B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,SAAS,WAAW,QAAQ,YAAY;CAqCnF,OAAO,OApCS,OAAO,IAAI,aAAa;EACvC,MAAM,SAAS,OAAO,IAAI;EAC1B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,QAAQ,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,OAAO,KAAK,MAAM,CAAC;EACjG,MAAM,SAAS,OAAO,cAAc,QAAQ,UAAU,KAAA,GAAW,KAAK;EAGtE,IAAI,EAAE,OAAO,GAAG,OAAO,KAAK,QAAQ,OAAO,IAAI,CAAC,IAAI;GACnD,OAAO,SAAS,WAAW,UAAU,yBAAyB,OAAO,KAAK,GAAG;GAC7E;EACD;EACA,MAAM,UAAU,OAAO,UAAU,WAAW,KAAK,QAAQ,GAAG,CAAC;EAC7D,OAAO,gBACN,OAAO,MACP,OAAO,IAAI,aAAa;GACvB,MAAM,EAAE,QAAQ,YAAY,OAAO,YAAY,OAAO,IAAI;GAI1D,MAAM,UAAU,OAAO,SAAS,SAAS,OAAO,MAAM,MAAM,KAAK;GACjE,MAAM,WAAW,SAAS,SAAS,OAAO;GAC1C,MAAM,OAAO,QAAQ,QAAQ,UAAU,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,UAAU,MAAM,KAAK;GACvF,IAAI,KAAK,WAAW,QAAQ,QAAQ;IACnC,OAAO,SAAS,WAAW,UAAU,yBAAyB,OAAO,KAAK,GAAG;IAC7E;GACD;GACA,OAAO,aAAa,OAAO,MAAM,QAAQ,IAAI;GAC7C,MAAM,UAAU,QAAQ,SAAS,KAAK;GACtC,OAAO,SACN,WAAW,QAAQ,GAAG,YAAY,IAAI,UAAU,UAAU,QAAQ,UAAU,SAAS,OAAO,KAAK,GAClG;EACD,CAAC,CACF;CACD,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { r as write, t as locked } from "./jsonc-
|
|
4
|
-
import { a as readServers, n as configured } from "./shared-
|
|
1
|
+
import { a as reportFailure, m as writeOut, t as InvalidInputError } from "./error-ippxl2z7.mjs";
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
|
+
import { r as write, t as locked } from "./jsonc-CWL4-4yz.mjs";
|
|
4
|
+
import { a as readServers, n as configured } from "./shared-CC4WukJX.mjs";
|
|
5
5
|
import { Effect, FileSystem } from "effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/mcp/remove.ts
|
|
7
7
|
var remove_default = handler(Cmd.commands.mcp.commands.remove, Effect.fn("CLI.mcp.remove")(function* ({ name, local }) {
|
|
@@ -23,4 +23,4 @@ var remove_default = handler(Cmd.commands.mcp.commands.remove, Effect.fn("CLI.mc
|
|
|
23
23
|
//#endregion
|
|
24
24
|
export { remove_default as default };
|
|
25
25
|
|
|
26
|
-
//# sourceMappingURL=remove-
|
|
26
|
+
//# sourceMappingURL=remove-VZO51J2m.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-VZO51J2m.mjs","names":["Runtime.handler","Jsonc.locked","Jsonc.write"],"sources":["../../src/cli/cmd/handlers/mcp/remove.ts"],"sourcesContent":["import { Effect, FileSystem } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { InvalidInputError, reportFailure } from \"../../../error.ts\";\nimport * as Jsonc from \"../../../jsonc.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { configured, readServers } from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.mcp.commands.remove,\n\tEffect.fn(\"CLI.mcp.remove\")(function* ({ name, local }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst { user, project, servers } = yield* configured();\n\t\t\tconst path = local ? project : user;\n\t\t\tconst level = local ? \"project\" : \"user\";\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\t// No file, nothing to remove: locking it would make its directory, and a `.codework/` here.\n\t\t\tconst removed =\n\t\t\t\t(yield* fs.exists(path)) &&\n\t\t\t\t(yield* Jsonc.locked(\n\t\t\t\t\tpath,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst { source, servers } = yield* readServers(path);\n\t\t\t\t\t\tif (servers[name] === undefined) return false;\n\t\t\t\t\t\tyield* Jsonc.write(path, source, [\"mcpServers\", name], undefined);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}),\n\t\t\t\t));\n\t\t\tif (removed) return yield* writeOut(`Removed ${level} MCP server \"${name}\" from ${path}.\\n`);\n\t\t\tconst other = servers.find((server) => server.name === name && server.file !== path);\n\t\t\tconst hint =\n\t\t\t\tother === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` It is defined in ${other.file}; ${other.file === project ? \"use --local\" : \"omit --local\"}.`;\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: `no ${level} MCP server named \"${name}\" in ${path}.${hint}`,\n\t\t\t});\n\t\t});\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,iBAAeA,QACd,IAAI,SAAS,IAAI,SAAS,QAC1B,OAAO,GAAG,gBAAgB,CAAC,CAAC,WAAW,EAAE,MAAM,SAAS;CA4BvD,OAAO,OA3BS,OAAO,IAAI,aAAa;EACvC,MAAM,EAAE,MAAM,SAAS,YAAY,OAAO,WAAW;EACrD,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,QAAQ,QAAQ,YAAY;EAclC,KAVE,QAAO,OAHS,WAAW,WAAA,CAGjB,OAAO,IAAI,OACrB,OAAOC,OACP,MACA,OAAO,IAAI,aAAa;GACvB,MAAM,EAAE,QAAQ,YAAY,OAAO,YAAY,IAAI;GACnD,IAAI,QAAQ,UAAU,KAAA,GAAW,OAAO;GACxC,OAAOC,MAAY,MAAM,QAAQ,CAAC,cAAc,IAAI,GAAG,KAAA,CAAS;GAChE,OAAO;EACR,CAAC,CACF,IACY,OAAO,OAAO,SAAS,WAAW,MAAM,eAAe,KAAK,SAAS,KAAK,IAAI;EAC3F,MAAM,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,QAAQ,OAAO,SAAS,IAAI;EACnF,MAAM,OACL,UAAU,KAAA,IACP,KACA,qBAAqB,MAAM,KAAK,IAAI,MAAM,SAAS,UAAU,gBAAgB,eAAe;EAChG,OAAO,OAAO,IAAI,kBAAkB,EACnC,SAAS,MAAM,MAAM,qBAAqB,KAAK,OAAO,KAAK,GAAG,OAC/D,CAAC;CACF,CACoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|