@codeworksh/cli 0.9.0-canary.157.1.g0c59cb43 → 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-8-tGD7v8.mjs → acp-D1X6PAQd.mjs} +4 -4
- package/{acp-8-tGD7v8.mjs.map → acp-D1X6PAQd.mjs.map} +1 -1
- package/{add-DHMnQW99.mjs → add-BO0TXkKX.mjs} +8 -7
- package/add-BO0TXkKX.mjs.map +1 -0
- package/{add-zUESl6ET.mjs → add-BwC5Yb3Z.mjs} +5 -5
- package/{add-zUESl6ET.mjs.map → add-BwC5Yb3Z.mjs.map} +1 -1
- package/{catalog-XfqtqMDz.mjs → catalog-BhnZFkoq.mjs} +2 -2
- package/{catalog-XfqtqMDz.mjs.map → catalog-BhnZFkoq.mjs.map} +1 -1
- package/{check-DaAohHQB.mjs → check-n2oLWYrZ.mjs} +4 -4
- package/{check-DaAohHQB.mjs.map → check-n2oLWYrZ.mjs.map} +1 -1
- package/connect-CO-oR-Br.mjs +35 -0
- package/connect-CO-oR-Br.mjs.map +1 -0
- package/{control-Bumzv5lJ.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-utTS2IQu.mjs → discovery-D07MPnKd.mjs} +13 -37
- package/discovery-D07MPnKd.mjs.map +1 -0
- package/{entries-DEIZstjm.mjs → entries-BzfySpSJ.mjs} +3 -3
- package/{entries-DEIZstjm.mjs.map → entries-BzfySpSJ.mjs.map} +1 -1
- package/{error-CDGBK9Du.mjs → error-ippxl2z7.mjs} +552 -9
- package/error-ippxl2z7.mjs.map +1 -0
- package/{fork-D9G8UFMP.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-oH9PJv_L.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-B3Jrv5qY.mjs → install-dfD5hzCS.mjs} +4 -4
- package/{install-B3Jrv5qY.mjs.map → install-dfD5hzCS.mjs.map} +1 -1
- package/{jsonc-CwZ1q4tQ.mjs → jsonc-CWL4-4yz.mjs} +2 -2
- package/{jsonc-CwZ1q4tQ.mjs.map → jsonc-CWL4-4yz.mjs.map} +1 -1
- package/{link-XTnNYTMG.mjs → link-D1cicwAl.mjs} +8 -6
- package/link-D1cicwAl.mjs.map +1 -0
- package/{list-CkcQPdvs.mjs → list-BKJgNMJm.mjs} +10 -12
- package/list-BKJgNMJm.mjs.map +1 -0
- package/{list-BWMsbeuT.mjs → list-C3McEC0O.mjs} +4 -4
- package/{list-BWMsbeuT.mjs.map → list-C3McEC0O.mjs.map} +1 -1
- package/{list-B56MDFRg.mjs → list-CGT6jT-r.mjs} +4 -4
- package/{list-B56MDFRg.mjs.map → list-CGT6jT-r.mjs.map} +1 -1
- package/{list-2wagSRhT.mjs → list-DZK016LF.mjs} +4 -4
- package/{list-2wagSRhT.mjs.map → list-DZK016LF.mjs.map} +1 -1
- package/{login-DEDr2Vyx.mjs → login-DuFDeGH-.mjs} +4 -4
- package/{login-DEDr2Vyx.mjs.map → login-DuFDeGH-.mjs.map} +1 -1
- package/{login-k_5cpvOg.mjs → login-XhIIF5Yu.mjs} +4 -4
- package/{login-k_5cpvOg.mjs.map → login-XhIIF5Yu.mjs.map} +1 -1
- package/{logout-CuhgmxyS.mjs → logout-CA1No9_2.mjs} +4 -4
- package/{logout-CuhgmxyS.mjs.map → logout-CA1No9_2.mjs.map} +1 -1
- package/{logout-DgfjJ4Qs.mjs → logout-Dpqw8tQZ.mjs} +4 -4
- package/{logout-DgfjJ4Qs.mjs.map → logout-Dpqw8tQZ.mjs.map} +1 -1
- 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-DFBL85KS.mjs → providers--giKGohM.mjs} +4 -4
- package/{providers-DFBL85KS.mjs.map → providers--giKGohM.mjs.map} +1 -1
- package/reconnect-I9-Do_DK.mjs +2 -0
- package/{refresh-BevzQTKE.mjs → refresh-BIH3qn5A.mjs} +4 -4
- package/{refresh-BevzQTKE.mjs.map → refresh-BIH3qn5A.mjs.map} +1 -1
- package/{refresh-D1ikVUxv.mjs → refresh-Dg8WvRcq.mjs} +4 -4
- package/{refresh-D1ikVUxv.mjs.map → refresh-Dg8WvRcq.mjs.map} +1 -1
- package/{identity-jiAiU7Z0.mjs → registration-C6yiv31r.mjs} +27 -36
- package/registration-C6yiv31r.mjs.map +1 -0
- package/relay-CLPWErNw.mjs +319 -0
- package/relay-CLPWErNw.mjs.map +1 -0
- package/{relink-D-74aBQZ.mjs → relink-D8Koos_q.mjs} +9 -7
- package/relink-D8Koos_q.mjs.map +1 -0
- package/{reload-DQDThDsu.mjs → reload-C5-B0s9x.mjs} +6 -5
- package/reload-C5-B0s9x.mjs.map +1 -0
- package/{remove-DbGeM1mo.mjs → remove-6m5n17il.mjs} +4 -4
- package/{remove-DbGeM1mo.mjs.map → remove-6m5n17il.mjs.map} +1 -1
- package/{remove-C5Cdkluk.mjs → remove-VZO51J2m.mjs} +5 -5
- package/{remove-C5Cdkluk.mjs.map → remove-VZO51J2m.mjs.map} +1 -1
- package/{restart-B41PrPeq.mjs → restart-4NoPj76N.mjs} +5 -4
- package/{restart-B41PrPeq.mjs.map → restart-4NoPj76N.mjs.map} +1 -1
- package/revoke-Gu5N3Vzy.mjs +13 -0
- package/revoke-Gu5N3Vzy.mjs.map +1 -0
- package/{run-tgTFwaz6.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-u3l-ZR4V.mjs → serve-BZ5FAU3h.mjs} +397 -35
- package/serve-BZ5FAU3h.mjs.map +1 -0
- package/service-CRnqz89w.mjs +79 -0
- package/service-CRnqz89w.mjs.map +1 -0
- package/{settings-DIqNg65Q.mjs → settings-DU140UBM.mjs} +3 -3
- package/{settings-DIqNg65Q.mjs.map → settings-DU140UBM.mjs.map} +1 -1
- package/{shared-DasNo1nI.mjs → shared-CC4WukJX.mjs} +4 -4
- package/{shared-DasNo1nI.mjs.map → shared-CC4WukJX.mjs.map} +1 -1
- package/{shared-D9lJX6cL.mjs → shared-Dzwbs5Lk.mjs} +7 -9
- package/shared-Dzwbs5Lk.mjs.map +1 -0
- package/{start-DaHslind.mjs → start-COhahq2E.mjs} +5 -4
- package/{start-DaHslind.mjs.map → start-COhahq2E.mjs.map} +1 -1
- package/{status-CvPbXQCn.mjs → status-Cau7bzuQ.mjs} +5 -4
- package/{status-CvPbXQCn.mjs.map → status-Cau7bzuQ.mjs.map} +1 -1
- package/{status-B1V5lctj.mjs → status-DJJOuCzL.mjs} +4 -4
- package/{status-B1V5lctj.mjs.map → status-DJJOuCzL.mjs.map} +1 -1
- package/{stop-BSy13mZw.mjs → stop-CC--mxXp.mjs} +5 -4
- package/{stop-BSy13mZw.mjs.map → stop-CC--mxXp.mjs.map} +1 -1
- package/{update-DKaDSMmZ.mjs → update-DMQLgDm3.mjs} +4 -4
- package/{update-DKaDSMmZ.mjs.map → update-DMQLgDm3.mjs.map} +1 -1
- package/add-DHMnQW99.mjs.map +0 -1
- package/control-Bumzv5lJ.mjs.map +0 -1
- package/disconnect-DyZh1VIG.mjs +0 -2
- package/error-CDGBK9Du.mjs.map +0 -1
- package/fork-D9G8UFMP.mjs.map +0 -1
- package/identity-jiAiU7Z0.mjs.map +0 -1
- package/link-XTnNYTMG.mjs.map +0 -1
- package/list-CkcQPdvs.mjs.map +0 -1
- package/package-CKwlCT6j.mjs +0 -6
- package/package-CKwlCT6j.mjs.map +0 -1
- package/reconnect-CfSVaPkd.mjs +0 -2
- package/relink-D-74aBQZ.mjs.map +0 -1
- package/reload-DQDThDsu.mjs.map +0 -1
- package/run-tgTFwaz6.mjs.map +0 -1
- package/runtime-CK2CunDw.mjs.map +0 -1
- package/serve-u3l-ZR4V.mjs.map +0 -1
- package/service-utTS2IQu.mjs.map +0 -1
- package/shared-D9lJX6cL.mjs.map +0 -1
- package/thread-oH9PJv_L.mjs.map +0 -1
|
@@ -1,28 +1,41 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import {
|
|
1
|
+
import { $ as sign, A as decode, B as ticketsPath, C as Current, D as Unauthorized, E as Token, F as Exchange, I as Proof, J as fingerprint, L as Signed, M as Core, N as encode, O as layerToken, P as ofThread, Q as publicOf, R as devicesPath, S as path, T as Forbidden, V as ConnectError, X as peek, Z as peekClaims, at as make$3, b as OAuthError, et as thumbprint, f as writeError, i as renderError, it as layer$8, j as Connected, k as local, nt as encrypted, ot as matches, q as PublicKey, rt as peer, t as InvalidInputError, tt as verify, v as Api, w as Door, y as HostError, z as proofWindow } from "./error-ippxl2z7.mjs";
|
|
2
|
+
import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
|
|
3
3
|
import { t as harnessOptions } from "./harness-6d8TlAVk.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { a as register, o as write, r as log } from "./registration-C6yiv31r.mjs";
|
|
5
|
+
import { i as layer$9, t as Service$5 } from "./identity-DbK4fABs.mjs";
|
|
6
|
+
import { a as rename, c as read, i as heartbeat, n as connect, o as status, r as disconnect, s as identity, t as Client } from "./relay-CLPWErNw.mjs";
|
|
7
|
+
import { Cause, Clock, Config, Context, Data, DateTime, Deferred, Duration, Effect, Exit, Fiber, FileSystem, Layer, Logger, Option, Path, Predicate, PubSub, Queue, Ref, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
|
|
6
8
|
import { Model } from "@codeworksh/aikit";
|
|
7
|
-
import { HttpRouter, HttpServer } from "effect/http";
|
|
9
|
+
import { Headers, HttpRouter, HttpServer, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
8
10
|
import { Control, DaemonHost, Event, EventList, EventRegistry, EventSchema, Git, Global, Harness, Mcp, McpConfig, ModelCatalog, Project, PromptSchema, Sandbox, Session, SessionStore, Settings, SettingsFile, State, Store, Sync, ThreadSchema, ThreadStore, expandTilde } from "@codeworksh/harness/effect";
|
|
9
|
-
import
|
|
11
|
+
import * as NetAddress from "effect/net/NetAddress";
|
|
12
|
+
import { NodeHttpServer, NodeServices } from "@effect/platform-node";
|
|
10
13
|
import { RpcSerialization, RpcServer } from "effect/rpc";
|
|
11
14
|
import { summarizeGitHubCopilot, summarizeOpenAICodex } from "@codeworksh/aikit/oauth/summary";
|
|
12
15
|
import { GitHubCopilotOAuthClient, JsonGitHubCopilotAuthStorage } from "@codeworksh/aikit/oauth/github/copilot";
|
|
13
16
|
import { JsonOpenAICodexAuthStorage, OpenAICodexOAuthClient } from "@codeworksh/aikit/oauth/openai/codex";
|
|
14
|
-
import
|
|
15
|
-
import { createServer } from "node:http";
|
|
17
|
+
import { homedir } from "node:os";
|
|
16
18
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
19
|
+
import { createServer } from "node:http";
|
|
17
20
|
import { readdir } from "node:fs/promises";
|
|
18
|
-
|
|
21
|
+
//#region src/machine/heartbeat.ts
|
|
22
|
+
/**
|
|
23
|
+
* While the server runs, each connected workspace hears from this machine every 30 seconds; the relay
|
|
24
|
+
* shows it online for 90. `machine.json` is read on every beat, so a `codework connect` made while the
|
|
25
|
+
* server runs is picked up without a restart. Nothing here is fatal: local work never waits on the relay.
|
|
26
|
+
*/
|
|
27
|
+
const layer$7 = Layer.effectDiscard(Effect.gen(function* () {
|
|
28
|
+
const global = yield* Global.Service;
|
|
29
|
+
yield* heartbeat(global.home).pipe(Effect.catch((error) => Effect.logDebug("Machine heartbeat failed", error)), Effect.repeat(Schedule.spaced("30 seconds")), Effect.forkScoped);
|
|
30
|
+
}));
|
|
31
|
+
//#endregion
|
|
19
32
|
//#region src/server/clones.ts
|
|
20
33
|
/**
|
|
21
34
|
* Background clones into host folders. Each is tracked by its destination from start until 30 seconds
|
|
22
35
|
* after it is done (a failed or cancelled one stays until retried or discarded), and git's progress
|
|
23
36
|
* is streamed as it arrives. Tracking is in memory: a restart forgets every clone.
|
|
24
37
|
*/
|
|
25
|
-
var Service$
|
|
38
|
+
var Service$4 = class extends Context.Service()("@codeworksh/cli/server/clones/Service") {};
|
|
26
39
|
const DONE_RETENTION = "30 seconds";
|
|
27
40
|
const STALL_AFTER = "20 seconds";
|
|
28
41
|
const DETAIL_MAX = 200;
|
|
@@ -511,7 +524,7 @@ const make$2 = Effect.gen(function* () {
|
|
|
511
524
|
bufferSize: 1,
|
|
512
525
|
strategy: "sliding"
|
|
513
526
|
});
|
|
514
|
-
return Service$
|
|
527
|
+
return Service$4.of({
|
|
515
528
|
start: (input) => locked(start(input)),
|
|
516
529
|
cancel: (path) => locked(cancel(path)),
|
|
517
530
|
retry: (path) => locked(retry(path)),
|
|
@@ -520,7 +533,307 @@ const make$2 = Effect.gen(function* () {
|
|
|
520
533
|
stream
|
|
521
534
|
});
|
|
522
535
|
});
|
|
523
|
-
const layer$
|
|
536
|
+
const layer$6 = Layer.effect(Service$4, make$2);
|
|
537
|
+
//#endregion
|
|
538
|
+
//#region src/server/pairing.ts
|
|
539
|
+
/**
|
|
540
|
+
* How another computer becomes a device of this machine, as a key pairs over SSH. A person reads it a
|
|
541
|
+
* pairing code from `codework service pair`, which it exchanges at `POST /api/v1/devices` with its public
|
|
542
|
+
* key, and gets back this machine's identity key. For each socket it opens it then signs a proof with its
|
|
543
|
+
* key at `POST /api/v1/tickets`, and gets back a ticket signed with the identity key, which it offers where
|
|
544
|
+
* a local client offers the home's token. Codes, tickets and spent nonces live in memory; devices persist in
|
|
545
|
+
* `<home>/devices.json`: each one's public key, and whether its last request came over TLS.
|
|
546
|
+
*/
|
|
547
|
+
const codeLife = Duration.toMillis("10 minutes");
|
|
548
|
+
const ticketLife = Duration.toMillis("60 seconds");
|
|
549
|
+
/** How long a device may go without taking a ticket before it is refused. */
|
|
550
|
+
const idleLife = Duration.toMillis("30 days");
|
|
551
|
+
/** Crockford's base32: no I, L, O or U, so a code read aloud is typed back right. */
|
|
552
|
+
const alphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
553
|
+
/** `length` random base32 characters, each from a byte's low 5 bits, so each is uniform. */
|
|
554
|
+
const random = (length) => Effect.sync(() => Array.from(crypto.getRandomValues(new Uint8Array(length)), (byte) => alphabet.charAt(byte & 31)).join(""));
|
|
555
|
+
/** A code as a person may type it back: any case, with or without its dash, I and L for 1, O for 0. */
|
|
556
|
+
const normalize = (code) => code.toUpperCase().replace(/[\s-]/g, "").replace(/[IL]/g, "1").replace(/O/g, "0");
|
|
557
|
+
const Device = Schema.Struct({
|
|
558
|
+
id: Schema.String,
|
|
559
|
+
label: Schema.String,
|
|
560
|
+
key: PublicKey,
|
|
561
|
+
createdAt: Schema.Finite,
|
|
562
|
+
seenAt: Schema.Finite,
|
|
563
|
+
encrypted: Schema.optional(Schema.Boolean)
|
|
564
|
+
});
|
|
565
|
+
const devicesJson = Schema.fromJsonString(Schema.Array(Device));
|
|
566
|
+
const isDevice = Schema.is(Device);
|
|
567
|
+
const decodeProof = Schema.decodeUnknownEffect(Proof);
|
|
568
|
+
/** The nonce a refusal echoes, read from a proof it never trusts, so only one a proof could carry. */
|
|
569
|
+
const decodeNonce = Schema.decodeUnknownEffect(Schema.Struct({ nonce: Schema.String.check(Schema.isMaxLength(64), Schema.isPattern(/^[A-Za-z0-9_-]+$/)) }));
|
|
570
|
+
/** `<home>/devices.json`: written by its server alone. */
|
|
571
|
+
const file = (home) => `${home}/devices.json`;
|
|
572
|
+
/** One-time secrets held until used or expired; each is taken at most once. */
|
|
573
|
+
const passes = () => {
|
|
574
|
+
let held = [];
|
|
575
|
+
return {
|
|
576
|
+
issue: (secret, expiresAt, value) => {
|
|
577
|
+
held = [...held, {
|
|
578
|
+
secret,
|
|
579
|
+
expiresAt,
|
|
580
|
+
value
|
|
581
|
+
}];
|
|
582
|
+
},
|
|
583
|
+
take: (given, now) => {
|
|
584
|
+
held = held.filter((pass) => pass.expiresAt > now);
|
|
585
|
+
const found = held.find((pass) => matches(given, pass.secret));
|
|
586
|
+
held = held.filter((pass) => pass !== found);
|
|
587
|
+
return found?.value;
|
|
588
|
+
},
|
|
589
|
+
drop: (value) => {
|
|
590
|
+
held = held.filter((pass) => pass.value !== value);
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
};
|
|
594
|
+
var Service$3 = class extends Context.Service()("@codeworksh/cli/server/pairing/Service") {};
|
|
595
|
+
const layer$5 = Layer.effect(Service$3, Effect.gen(function* () {
|
|
596
|
+
const fs = yield* FileSystem.FileSystem;
|
|
597
|
+
const files = yield* Effect.context();
|
|
598
|
+
const home = (yield* Global.Service).home;
|
|
599
|
+
const path = file(home);
|
|
600
|
+
const stored = (yield* fs.exists(path)) ? yield* fs.readFileString(path).pipe(Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(Schema.Array(Schema.Unknown)))), Effect.catch(() => Effect.die(`${path} is not a valid devices file`))) : [];
|
|
601
|
+
let devices = stored.filter(isDevice);
|
|
602
|
+
if (devices.length < stored.length) yield* Effect.logWarning(`${path}: ${stored.length - devices.length} device(s) must pair again`);
|
|
603
|
+
const codes = passes();
|
|
604
|
+
const tickets = passes();
|
|
605
|
+
/** Each proof's nonce, until its proof is past the window. */
|
|
606
|
+
const nonces = /* @__PURE__ */ new Map();
|
|
607
|
+
const lock = yield* Semaphore.make(1);
|
|
608
|
+
const save = (next) => Effect.gen(function* () {
|
|
609
|
+
yield* write(path, yield* Schema.encodeEffect(devicesJson)(next));
|
|
610
|
+
devices = next;
|
|
611
|
+
}).pipe(Effect.provideContext(files), Effect.orDie);
|
|
612
|
+
const identity$1 = identity(home).pipe(Effect.provideContext(files), Effect.orDie);
|
|
613
|
+
const fingerprint$1 = (key) => fingerprint(key).pipe(Effect.orDie);
|
|
614
|
+
/**
|
|
615
|
+
* The device a proof is good for, by id: signed by the key of the device it names, inside the window,
|
|
616
|
+
* its nonce unseen and now spent. Checked outside the lock, so a flood of bad proofs holds up no write.
|
|
617
|
+
*/
|
|
618
|
+
const proven = Effect.fnUntraced(function* (proof, now) {
|
|
619
|
+
const { kid } = yield* peek(proof);
|
|
620
|
+
const holders = yield* Effect.filter(devices, (device) => Effect.map(thumbprint(device.key), (thumbprint) => thumbprint === kid));
|
|
621
|
+
const [holder] = holders;
|
|
622
|
+
if (holder === void 0) return void 0;
|
|
623
|
+
const claims = yield* verify(proof, holder.key).pipe(Effect.flatMap(decodeProof));
|
|
624
|
+
const device = holders.find((each) => each.id === claims.device);
|
|
625
|
+
if (device === void 0 || claims.aud !== (yield* identity$1).keyId) return void 0;
|
|
626
|
+
if (Math.abs(now - claims.iat) > 3e5) return void 0;
|
|
627
|
+
for (const [nonce, until] of nonces) if (until < now) nonces.delete(nonce);
|
|
628
|
+
if (nonces.has(claims.nonce)) return void 0;
|
|
629
|
+
nonces.set(claims.nonce, claims.iat + proofWindow);
|
|
630
|
+
return {
|
|
631
|
+
id: device.id,
|
|
632
|
+
nonce: claims.nonce
|
|
633
|
+
};
|
|
634
|
+
}, Effect.orElseSucceed(() => void 0));
|
|
635
|
+
return Service$3.of({
|
|
636
|
+
code: Effect.gen(function* () {
|
|
637
|
+
const code = yield* random(10);
|
|
638
|
+
const expiresAt = (yield* Clock.currentTimeMillis) + codeLife;
|
|
639
|
+
const key = publicOf((yield* identity$1).key);
|
|
640
|
+
codes.issue(code, expiresAt, true);
|
|
641
|
+
return {
|
|
642
|
+
code: `${code.slice(0, 5)}-${code.slice(5)}`,
|
|
643
|
+
expiresAt,
|
|
644
|
+
fingerprint: yield* fingerprint$1(key)
|
|
645
|
+
};
|
|
646
|
+
}),
|
|
647
|
+
exchange: (code, label, key, encrypted) => Effect.gen(function* () {
|
|
648
|
+
const now = yield* Clock.currentTimeMillis;
|
|
649
|
+
if (codes.take(normalize(code), now) === void 0) return void 0;
|
|
650
|
+
const machine = publicOf((yield* identity$1).key);
|
|
651
|
+
const device = {
|
|
652
|
+
id: `dev_${(yield* random(10)).toLowerCase()}`,
|
|
653
|
+
label,
|
|
654
|
+
key,
|
|
655
|
+
createdAt: now,
|
|
656
|
+
seenAt: now,
|
|
657
|
+
encrypted
|
|
658
|
+
};
|
|
659
|
+
yield* lock.withPermit(Effect.suspend(() => save([...devices, device])));
|
|
660
|
+
return {
|
|
661
|
+
id: device.id,
|
|
662
|
+
machine
|
|
663
|
+
};
|
|
664
|
+
}),
|
|
665
|
+
ticket: (proof, encrypted) => Effect.gen(function* () {
|
|
666
|
+
const refuse = Effect.gen(function* () {
|
|
667
|
+
const echoed = yield* peekClaims(proof).pipe(Effect.flatMap(decodeNonce), Effect.option);
|
|
668
|
+
if (Option.isNone(echoed)) return { _tag: "Refused" };
|
|
669
|
+
const { key, keyId } = yield* identity$1;
|
|
670
|
+
const refusal = {
|
|
671
|
+
op: "ticket.refuse",
|
|
672
|
+
nonce: echoed.value.nonce,
|
|
673
|
+
at: yield* Clock.currentTimeMillis
|
|
674
|
+
};
|
|
675
|
+
return {
|
|
676
|
+
_tag: "Refused",
|
|
677
|
+
jws: yield* sign(refusal, key, { kid: keyId }).pipe(Effect.orDie)
|
|
678
|
+
};
|
|
679
|
+
});
|
|
680
|
+
const proved = yield* proven(proof, yield* Clock.currentTimeMillis);
|
|
681
|
+
if (proved === void 0) return yield* refuse;
|
|
682
|
+
const ticket = yield* lock.withPermit(Effect.gen(function* () {
|
|
683
|
+
const now = yield* Clock.currentTimeMillis;
|
|
684
|
+
const device = devices.find((each) => each.id === proved.id);
|
|
685
|
+
if (device === void 0 || now - device.seenAt > idleLife) return void 0;
|
|
686
|
+
yield* save(devices.map((each) => each === device ? {
|
|
687
|
+
...device,
|
|
688
|
+
seenAt: now,
|
|
689
|
+
encrypted
|
|
690
|
+
} : each));
|
|
691
|
+
const ticket = yield* make$3;
|
|
692
|
+
tickets.issue(ticket, now + ticketLife, device.id);
|
|
693
|
+
return ticket;
|
|
694
|
+
}));
|
|
695
|
+
if (ticket === void 0) return yield* refuse;
|
|
696
|
+
const { key, keyId } = yield* identity$1;
|
|
697
|
+
const grant = {
|
|
698
|
+
op: "ticket.grant",
|
|
699
|
+
ticket,
|
|
700
|
+
nonce: proved.nonce
|
|
701
|
+
};
|
|
702
|
+
return {
|
|
703
|
+
_tag: "Granted",
|
|
704
|
+
jws: yield* sign(grant, key, { kid: keyId }).pipe(Effect.orDie)
|
|
705
|
+
};
|
|
706
|
+
}),
|
|
707
|
+
redeem: (ticket) => Effect.map(Clock.currentTimeMillis, (now) => {
|
|
708
|
+
const id = tickets.take(ticket, now);
|
|
709
|
+
return devices.some((device) => device.id === id) ? id : void 0;
|
|
710
|
+
}),
|
|
711
|
+
list: Effect.suspend(() => Effect.forEach(devices, ({ id, label, key, createdAt, seenAt, encrypted }) => Effect.map(fingerprint$1(key), (fingerprint) => ({
|
|
712
|
+
id,
|
|
713
|
+
label,
|
|
714
|
+
fingerprint,
|
|
715
|
+
createdAt,
|
|
716
|
+
seenAt,
|
|
717
|
+
...encrypted === void 0 ? {} : { encrypted }
|
|
718
|
+
})))),
|
|
719
|
+
revoke: (id) => lock.withPermit(Effect.gen(function* () {
|
|
720
|
+
if (!devices.some((device) => device.id === id)) return false;
|
|
721
|
+
yield* save(devices.filter((device) => device.id !== id));
|
|
722
|
+
tickets.drop(id);
|
|
723
|
+
return true;
|
|
724
|
+
}))
|
|
725
|
+
});
|
|
726
|
+
})).pipe(Layer.provide(NodeServices.layer));
|
|
727
|
+
const refused = HttpServerResponse.empty({ status: 401 });
|
|
728
|
+
/** The peers besides loopback whose `X-Forwarded-Proto` the pairing routes believe. */
|
|
729
|
+
const TrustedProxy = Context.Reference("@codeworksh/cli/server/pairing/TrustedProxy", { defaultValue: () => [] });
|
|
730
|
+
/** The routes {@link routes} serves, which take no socket credential. */
|
|
731
|
+
const paths = [devicesPath, ticketsPath];
|
|
732
|
+
/** The pairing routes of the shared wire contract. */
|
|
733
|
+
const routes = HttpRouter.use((router) => Effect.gen(function* () {
|
|
734
|
+
const pairing = yield* Service$3;
|
|
735
|
+
const trusted = yield* TrustedProxy;
|
|
736
|
+
yield* router.add("POST", devicesPath, Effect.gen(function* () {
|
|
737
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
738
|
+
const body = yield* HttpServerRequest.schemaBodyJson(Exchange).pipe(Effect.option);
|
|
739
|
+
if (body._tag === "None") return HttpServerResponse.empty({ status: 400 });
|
|
740
|
+
const device = yield* pairing.exchange(body.value.code, body.value.label, body.value.key, encrypted(request, trusted));
|
|
741
|
+
return device === void 0 ? refused : HttpServerResponse.jsonUnsafe(device, { status: 201 });
|
|
742
|
+
}));
|
|
743
|
+
yield* router.add("POST", ticketsPath, Effect.gen(function* () {
|
|
744
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
745
|
+
const body = yield* HttpServerRequest.schemaBodyJson(Signed).pipe(Effect.option);
|
|
746
|
+
if (Option.isNone(body)) return refused;
|
|
747
|
+
const answer = yield* pairing.ticket(body.value.jws, encrypted(request, trusted));
|
|
748
|
+
if (answer.jws === void 0) return refused;
|
|
749
|
+
return HttpServerResponse.jsonUnsafe({ jws: answer.jws }, { status: answer._tag === "Granted" ? 201 : 401 });
|
|
750
|
+
}));
|
|
751
|
+
}));
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/server/door.ts
|
|
754
|
+
/**
|
|
755
|
+
* How a caller gets in, and stays in only as long as it may. The door judges a socket's credential
|
|
756
|
+
* once, before the upgrade, and files the connection under a key it adds to the upgrade request as
|
|
757
|
+
* {@link header}. The upgrade request's headers come with every call on that socket, so each call
|
|
758
|
+
* finds its caller by that key. A key never leaves the server, so a client cannot claim another
|
|
759
|
+
* connection by sending one in a call's own headers, which would override the upgrade's.
|
|
760
|
+
*/
|
|
761
|
+
const header = "x-codework-connection";
|
|
762
|
+
/** The connections the door let in, by key. */
|
|
763
|
+
var Connections = class extends Context.Service()("@codeworksh/cli/server/door/Connections") {};
|
|
764
|
+
const layerConnections = Layer.sync(Connections, () => {
|
|
765
|
+
const held = /* @__PURE__ */ new Map();
|
|
766
|
+
const end = (key) => Effect.suspend(() => {
|
|
767
|
+
const connection = held.get(key);
|
|
768
|
+
held.delete(key);
|
|
769
|
+
return connection === void 0 ? Effect.void : Deferred.succeed(connection.ended, void 0);
|
|
770
|
+
});
|
|
771
|
+
return Connections.of({
|
|
772
|
+
open: (principal) => Effect.gen(function* () {
|
|
773
|
+
const key = yield* make$3;
|
|
774
|
+
held.set(key, {
|
|
775
|
+
principal,
|
|
776
|
+
ended: yield* Deferred.make()
|
|
777
|
+
});
|
|
778
|
+
return key;
|
|
779
|
+
}),
|
|
780
|
+
find: (key) => key === void 0 ? void 0 : held.get(key)?.principal,
|
|
781
|
+
device: (id) => [...held].flatMap(([key, { principal }]) => principal.kind === "device" && principal.id === id ? [key] : []),
|
|
782
|
+
end,
|
|
783
|
+
serve: (key, effect) => {
|
|
784
|
+
const connection = held.get(key);
|
|
785
|
+
if (connection === void 0) return Effect.succeed(HttpServerResponse.empty({ status: 401 }));
|
|
786
|
+
return Effect.raceFirst(effect, Deferred.await(connection.ended).pipe(Effect.as(HttpServerResponse.empty()))).pipe(Effect.ensuring(end(key)));
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
/** Whether `request` comes from this computer, by its peer address: no header can say so. */
|
|
791
|
+
const fromLoopback = (request) => {
|
|
792
|
+
const peer$1 = peer(request);
|
|
793
|
+
return peer$1 !== void 0 && NetAddress.isLoopback(peer$1);
|
|
794
|
+
};
|
|
795
|
+
const pathname = (request) => new URL(request.url, "http://localhost").pathname;
|
|
796
|
+
/**
|
|
797
|
+
* The listener's door before any upgrade: no browser origin is served. The pairing routes take no
|
|
798
|
+
* credential here, as each checks its own. The socket takes the home's token from a loopback peer,
|
|
799
|
+
* or a live ticket, which it spends.
|
|
800
|
+
*/
|
|
801
|
+
const listener = Layer.unwrap(Effect.gen(function* () {
|
|
802
|
+
const token = yield* Token;
|
|
803
|
+
const pairing = yield* Service$3;
|
|
804
|
+
const connections = yield* Connections;
|
|
805
|
+
const caller = (offered, request) => matches(offered, token) ? Effect.succeed(fromLoopback(request) ? { kind: "local" } : void 0) : Effect.map(pairing.redeem(offered), (id) => id === void 0 ? void 0 : {
|
|
806
|
+
kind: "device",
|
|
807
|
+
id
|
|
808
|
+
});
|
|
809
|
+
return layer$8({
|
|
810
|
+
origins: [],
|
|
811
|
+
admit: (offered, request) => Effect.gen(function* () {
|
|
812
|
+
const path$1 = pathname(request);
|
|
813
|
+
if (request.method === "POST" && paths.includes(path$1)) return request;
|
|
814
|
+
if (request.method !== "GET" || path$1 !== "/rpc/v1" || offered === void 0) return void 0;
|
|
815
|
+
const principal = yield* caller(offered, request);
|
|
816
|
+
if (principal === void 0) return void 0;
|
|
817
|
+
const key = yield* connections.open(principal);
|
|
818
|
+
return request.modify({ headers: Headers.set(request.headers, header, key) });
|
|
819
|
+
})
|
|
820
|
+
});
|
|
821
|
+
}));
|
|
822
|
+
/** The socket route of the RPC server: each connection runs until it closes or is ended. */
|
|
823
|
+
const protocol = Layer.effect(RpcServer.Protocol, Effect.gen(function* () {
|
|
824
|
+
const { httpEffect, protocol } = yield* RpcServer.makeProtocolWithHttpEffectWebsocket;
|
|
825
|
+
const connections = yield* Connections;
|
|
826
|
+
yield* (yield* HttpRouter.HttpRouter).add("GET", path, (request) => connections.serve(request.headers["x-codework-connection"] ?? "", Effect.scoped(httpEffect)));
|
|
827
|
+
return protocol;
|
|
828
|
+
}));
|
|
829
|
+
/** The door on every call: the caller of the connection it came on, which must still be open. */
|
|
830
|
+
const rpc = Layer.effect(Door, Effect.gen(function* () {
|
|
831
|
+
const connections = yield* Connections;
|
|
832
|
+
return Door.of((effect, { headers }) => {
|
|
833
|
+
const principal = connections.find(Option.getOrUndefined(Headers.get(headers, header)));
|
|
834
|
+
return principal === void 0 ? Effect.fail(new Unauthorized({ message: "This connection is not open to this server" })) : Effect.provideService(effect, Current, principal);
|
|
835
|
+
});
|
|
836
|
+
}));
|
|
524
837
|
//#endregion
|
|
525
838
|
//#region src/server/feed.ts
|
|
526
839
|
const SubscriberCapacity = 4096;
|
|
@@ -898,6 +1211,7 @@ const resume = (after, boot, page, synced) => Stream.unwrap(Effect.gen(function*
|
|
|
898
1211
|
}));
|
|
899
1212
|
//#endregion
|
|
900
1213
|
//#region src/server/handlers.ts
|
|
1214
|
+
const isConnectError = Schema.is(ConnectError);
|
|
901
1215
|
const toSandboxInfo = (info) => ({
|
|
902
1216
|
id: info.id,
|
|
903
1217
|
driver: info.driver,
|
|
@@ -1112,13 +1426,18 @@ const layer$1 = Api.toLayer(Effect.gen(function* () {
|
|
|
1112
1426
|
const resolve = (ref) => control.resolve(ref).pipe(Effect.map((thread) => ThreadSchema.ID.make(thread.id)));
|
|
1113
1427
|
const state = yield* State.Service;
|
|
1114
1428
|
const oauth = yield* Service;
|
|
1115
|
-
const identity = yield* Service$
|
|
1429
|
+
const identity = yield* Service$5;
|
|
1116
1430
|
const events = yield* Event.Service;
|
|
1117
1431
|
const registry = yield* EventRegistry.Service;
|
|
1118
1432
|
const mcp = yield* Mcp.Service;
|
|
1119
1433
|
const host = yield* Service$1;
|
|
1120
|
-
const clones = yield* Service$
|
|
1434
|
+
const clones = yield* Service$4;
|
|
1121
1435
|
const store = yield* Store.Service;
|
|
1436
|
+
const global = yield* Global.Service;
|
|
1437
|
+
const pairing = yield* Service$3;
|
|
1438
|
+
const connections = yield* Connections;
|
|
1439
|
+
/** Forgets a device and ends its open connections; false when none has `id`. */
|
|
1440
|
+
const forget = (id) => pairing.revoke(id).pipe(Effect.tap(() => Effect.forEach(connections.device(id), connections.end, { discard: true })));
|
|
1122
1441
|
const mcpControl = (operation) => Effect.fnUntraced(function* ({ server, ...ref }) {
|
|
1123
1442
|
return yield* mcp[operation](yield* resolve(ref), server);
|
|
1124
1443
|
});
|
|
@@ -1133,10 +1452,12 @@ const layer$1 = Api.toLayer(Effect.gen(function* () {
|
|
|
1133
1452
|
return Api.of({
|
|
1134
1453
|
"server.info": Effect.fnUntraced(function* () {
|
|
1135
1454
|
const head = yield* store.head;
|
|
1455
|
+
const machine = yield* read(global.home).pipe(Effect.provide(NodeServices.layer), Effect.orElseSucceed(() => Option.none()));
|
|
1136
1456
|
return {
|
|
1137
1457
|
...identity,
|
|
1138
1458
|
storeId: head.id,
|
|
1139
|
-
rev: head.rev
|
|
1459
|
+
rev: head.rev,
|
|
1460
|
+
...Option.isSome(machine) ? { machineId: machine.value.id } : {}
|
|
1140
1461
|
};
|
|
1141
1462
|
}),
|
|
1142
1463
|
"index.sync": ({ after, boot }) => resume(after, boot, (from, upto) => Sync.index(from, upto, 500).pipe(Effect.map(({ items, next }) => ({
|
|
@@ -1367,6 +1688,31 @@ const layer$1 = Api.toLayer(Effect.gen(function* () {
|
|
|
1367
1688
|
}),
|
|
1368
1689
|
"mcp.connect": mcpControl("connect"),
|
|
1369
1690
|
"mcp.disconnect": mcpControl("disconnect"),
|
|
1691
|
+
"machine.info": () => status(global.home).pipe(Effect.provide(NodeServices.layer), Effect.orDie),
|
|
1692
|
+
"machine.rename": ({ givenName }) => rename(global.home, givenName).pipe(Effect.tap(() => heartbeat(global.home).pipe(Effect.provide(NodeServices.layer), Effect.ignore, Effect.forkDetach)), Effect.provide(NodeServices.layer), Effect.orDie),
|
|
1693
|
+
"machine.disconnect": ({ workspaceId, keyId }) => disconnect(global.home, workspaceId, keyId).pipe(Effect.flatMap(({ revoked }) => status(global.home).pipe(Effect.map((status) => ({
|
|
1694
|
+
status,
|
|
1695
|
+
revoked
|
|
1696
|
+
})))), Effect.provide(NodeServices.layer), Effect.catchIf((error) => !isConnectError(error), (error) => Effect.fail(new ConnectError({ message: `Could not disconnect: ${String(error)}` })))),
|
|
1697
|
+
"machine.connect": ({ workspaceId }) => Stream.callback((queue) => connect({
|
|
1698
|
+
home: global.home,
|
|
1699
|
+
workspaceId,
|
|
1700
|
+
onCode: (userCode) => Queue.offer(queue, {
|
|
1701
|
+
_tag: "Code",
|
|
1702
|
+
userCode
|
|
1703
|
+
}).pipe(Effect.asVoid)
|
|
1704
|
+
}).pipe(Effect.tap(() => heartbeat(global.home).pipe(Effect.provide(NodeServices.layer), Effect.ignore, Effect.forkDetach)), Effect.flatMap((connected) => Queue.offer(queue, {
|
|
1705
|
+
_tag: "Connected",
|
|
1706
|
+
connected
|
|
1707
|
+
})), Effect.andThen(Queue.end(queue)), Effect.provide([Client.layer, NodeServices.layer]), Effect.catch((error) => Queue.fail(queue, isConnectError(error) ? error : new ConnectError({ message: `Could not connect: ${String(error)}` }))), Effect.forkScoped)),
|
|
1708
|
+
"device.pair": () => local(pairing.code),
|
|
1709
|
+
"device.list": () => local(pairing.list),
|
|
1710
|
+
"device.revoke": ({ id }) => local(Effect.map(forget(id), (applied) => ({ applied }))),
|
|
1711
|
+
"device.leave": () => Effect.gen(function* () {
|
|
1712
|
+
const caller = yield* Current;
|
|
1713
|
+
if (caller.kind !== "device") return yield* new Forbidden({ message: "This computer has no pairing to leave" });
|
|
1714
|
+
yield* forget(caller.id);
|
|
1715
|
+
}),
|
|
1370
1716
|
"host.info": () => Effect.succeed(host.info),
|
|
1371
1717
|
"host.browse": ({ path }) => host.browse(path),
|
|
1372
1718
|
"host.create": ({ name }) => host.create(name),
|
|
@@ -1445,37 +1791,38 @@ const resumeUnfinished = Layer.effectDiscard(Effect.gen(function* () {
|
|
|
1445
1791
|
yield* Effect.forkScoped(control.resumeUnfinished);
|
|
1446
1792
|
}));
|
|
1447
1793
|
/**
|
|
1448
|
-
* Advertises the listener once it has an address:
|
|
1449
|
-
* the
|
|
1794
|
+
* Advertises the listener once it has an address: files the registration later
|
|
1795
|
+
* invocations discover it through, with the token they call it with, then logs
|
|
1796
|
+
* the endpoint, so whoever reads that line finds the server registered.
|
|
1450
1797
|
*/
|
|
1451
1798
|
const announce = Layer.unwrap(Effect.gen(function* () {
|
|
1452
1799
|
const server = yield* HttpServer.HttpServer;
|
|
1800
|
+
const token = yield* Token;
|
|
1453
1801
|
const global = yield* Global.Service;
|
|
1454
|
-
const identity = yield* Service$
|
|
1802
|
+
const identity = yield* Service$5;
|
|
1455
1803
|
const address = server.address;
|
|
1456
1804
|
const url = `${NetAddress.formatUrlUnsafe(address, "ws")}${path}`;
|
|
1457
|
-
|
|
1458
|
-
if (!NetAddress.isInetAddress(address)) return
|
|
1459
|
-
return register({
|
|
1805
|
+
const listening = Layer.effectDiscard(Effect.log(`codework serve listening on ${url}`));
|
|
1806
|
+
if (!NetAddress.isInetAddress(address)) return listening;
|
|
1807
|
+
return listening.pipe(Layer.provide(register({
|
|
1460
1808
|
home: global.home,
|
|
1461
1809
|
info: {
|
|
1462
1810
|
pid: identity.pid,
|
|
1463
1811
|
version: identity.version,
|
|
1464
1812
|
url,
|
|
1465
|
-
port: address.port
|
|
1813
|
+
port: address.port,
|
|
1814
|
+
token
|
|
1466
1815
|
}
|
|
1467
|
-
});
|
|
1816
|
+
})));
|
|
1468
1817
|
}));
|
|
1818
|
+
const trusted = (given) => Layer.effect(TrustedProxy, given === void 0 ? Effect.flatMap(Settings.Service, (settings) => settings.load(void 0)).pipe(Effect.map(({ server }) => server.trustedProxy.flatMap((entry) => Settings.proxyNetwork(entry) ?? []))) : Effect.succeed(given));
|
|
1819
|
+
/** The RPC endpoint for `group` and the pairing routes, behind the door, which turns a refused request away. */
|
|
1820
|
+
const endpoint = (group) => RpcServer.layer(group).pipe(Layer.provide(protocol), Layer.provide(layer$1.pipe(Layer.provide(layer$4))), Layer.provide(rpc), Layer.merge(routes), Layer.merge(listener), Layer.provide(layerConnections), Layer.provide(layer$5));
|
|
1469
1821
|
const layer = (options) => {
|
|
1470
|
-
|
|
1471
|
-
group: Api,
|
|
1472
|
-
path,
|
|
1473
|
-
protocol: "websocket"
|
|
1474
|
-
}).pipe(Layer.provide(layer$1.pipe(Layer.provide(layer$4))));
|
|
1475
|
-
return HttpRouter.serve(rpc, { disableListenLog: true }).pipe(Layer.provideMerge(managedShutdown), Layer.provideMerge(resumeUnfinished), Layer.provide(layer$2(options.harness.home === void 0 ? {} : { home: options.harness.home })), Layer.provide(layer$3), Layer.provide(layer$5)).pipe(Layer.provideMerge(announce), Layer.provideMerge(NodeHttpServer.layer(createServer, {
|
|
1822
|
+
return HttpRouter.serve(endpoint(Api), { disableListenLog: true }).pipe(Layer.provideMerge(managedShutdown), Layer.provideMerge(resumeUnfinished), Layer.provideMerge(layer$7), Layer.provide(layer$2(options.harness.home === void 0 ? {} : { home: options.harness.home })), Layer.provide(layer$3), Layer.provide(layer$6), Layer.provide(trusted(options.trustedProxy))).pipe(Layer.provideMerge(announce), Layer.provideMerge(NodeHttpServer.layer(createServer, {
|
|
1476
1823
|
host: options.host,
|
|
1477
1824
|
port: options.port
|
|
1478
|
-
})), Layer.provide(RpcSerialization.layerNdjson), Layer.provide(options.identity ?? layer$
|
|
1825
|
+
})), Layer.provide(RpcSerialization.layerNdjson), Layer.provide(options.identity ?? layer$9), Layer.provide(layerToken), Layer.provide(sweep), Layer.provide(Harness.layer(options.harness)));
|
|
1479
1826
|
};
|
|
1480
1827
|
//#endregion
|
|
1481
1828
|
//#region src/cli/cmd/handlers/serve.ts
|
|
@@ -1483,17 +1830,32 @@ const failed = Effect.sync(() => {
|
|
|
1483
1830
|
process.exitCode = 1;
|
|
1484
1831
|
});
|
|
1485
1832
|
const report = (error) => writeError(renderError(error)).pipe(Effect.andThen(failed));
|
|
1486
|
-
|
|
1833
|
+
const entries = (values) => values.flatMap((value) => value.split(",")).map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
1834
|
+
/**
|
|
1835
|
+
* The proxies `--trusted-proxy` names, else `CODEWORK_TRUSTED_PROXY`; none from either leaves the
|
|
1836
|
+
* user settings' `server.trustedProxy`, which settings decode themselves.
|
|
1837
|
+
*/
|
|
1838
|
+
const trustedProxy = Effect.fn(function* (flag) {
|
|
1839
|
+
const env = entries([yield* Config.String("CODEWORK_TRUSTED_PROXY").pipe(Config.withDefault(""))]);
|
|
1840
|
+
const [source, given] = flag.length > 0 ? ["--trusted-proxy", entries(flag)] : ["CODEWORK_TRUSTED_PROXY", env];
|
|
1841
|
+
if (given.length === 0) return void 0;
|
|
1842
|
+
return yield* Effect.forEach(given, (entry) => {
|
|
1843
|
+
const network = Settings.proxyNetwork(entry);
|
|
1844
|
+
return network === void 0 ? Effect.fail(new InvalidInputError({ message: `${source}: "${entry}" is not an IP address or CIDR range` })) : Effect.succeed(network);
|
|
1845
|
+
});
|
|
1846
|
+
});
|
|
1847
|
+
var serve_default = handler(Cmd.commands.serve, Effect.fn("CLI.serve", { level: "Info" })(function* ({ host, port, service, trustedProxy: flag }) {
|
|
1487
1848
|
const shared = yield* Cmd.spec;
|
|
1488
1849
|
const harness = {
|
|
1489
1850
|
...harnessOptions(shared),
|
|
1490
1851
|
watchModels: true
|
|
1491
1852
|
};
|
|
1492
|
-
const serve = Layer.launch(layer({
|
|
1853
|
+
const serve = Effect.flatMap(trustedProxy(flag), (trusted) => Layer.launch(layer({
|
|
1493
1854
|
host,
|
|
1494
1855
|
port,
|
|
1495
|
-
harness
|
|
1496
|
-
|
|
1856
|
+
harness,
|
|
1857
|
+
...trusted === void 0 ? {} : { trustedProxy: trusted }
|
|
1858
|
+
})));
|
|
1497
1859
|
if (!service) return yield* serve.pipe(Effect.catch(report));
|
|
1498
1860
|
yield* Effect.gen(function* () {
|
|
1499
1861
|
const paths = yield* Global.resolve(harness.home === void 0 ? {} : { home: harness.home });
|
|
@@ -1505,4 +1867,4 @@ var serve_default = handler(Cmd.commands.serve, Effect.fn("CLI.serve", { level:
|
|
|
1505
1867
|
//#endregion
|
|
1506
1868
|
export { serve_default as default };
|
|
1507
1869
|
|
|
1508
|
-
//# sourceMappingURL=serve-
|
|
1870
|
+
//# sourceMappingURL=serve-BZ5FAU3h.mjs.map
|