@deslop/deploy 0.1.1318 → 0.1.1328

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/dist/server.js +171 -186
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -7,7 +7,7 @@ npm install --global @deslop/deploy
7
7
  deploy service install --domain mp281x.xyz --workers desktop,macbook-pro
8
8
  ```
9
9
 
10
- - **`--workers`** lists Tailscale machine names. Deploy derives each HTTPS URL from the tailnet's MagicDNS suffix and its package port; every worker keeps the same `DEPLOY_KEY` in `~/.deslop/deploy.env`.
11
- - **Platforms.** Linux x64 and macOS arm64. Public exposure runs the bundled Caddy, a Linux x64 build, so a Mac exposes ports to the tailnet only; its apps are its `deslop-*` launch agents, measured without per-app history.
10
+ - **`--workers`** lists Tailscale machine names. Deploy derives each HTTPS URL from the tailnet's MagicDNS suffix and its package port. Auth identifies peers by their tailnet owner; local commands require an admin.
11
+ - **Platforms.** Linux x64 and macOS arm64. Public exposure runs the bundled Caddy, a Linux x64 build, so a Mac exposes ports to the tailnet only. Its apps are running regular (Dock) GUI applications and running user launch agents other than `com.apple.*` and Deslop `-update` agents, with process trees and listeners but no per-app history.
12
12
 
13
13
  Common flags and service commands: [Deslop app runtime](https://github.com/MP281X/deslop/blob/main/packages/runtime/README.md).
package/dist/server.js CHANGED
@@ -10986,8 +10986,6 @@ const succeedSome$1 = (a) => succeed$9(some$1(a));
10986
10986
  /** @internal */
10987
10987
  const succeedNone$1 = /*#__PURE__*/ succeed$9(/*#__PURE__*/ none());
10988
10988
  /** @internal */
10989
- const transposeOption$1 = (self) => isNone(self) ? succeedNone$1 : map$9(self.value, some$1);
10990
- /** @internal */
10991
10989
  const failCauseSync$1 = (evaluate) => suspend$4(() => failCause$6(evaluate()));
10992
10990
  /** @internal */
10993
10991
  const die$5 = (defect) => exitDie(defect);
@@ -19310,39 +19308,6 @@ const fromResult = fromResult$1;
19310
19308
  */
19311
19309
  const fromOption = fromOption$1;
19312
19310
  /**
19313
- * Converts an `Option` of an `Effect` into an `Effect` of an `Option`.
19314
- *
19315
- * **When to use**
19316
- *
19317
- * Use when an effect should run only when an optional value is present, while
19318
- * preserving absence as a successful `None`.
19319
- *
19320
- * **Details**
19321
- *
19322
- * - `None` becomes an effect that succeeds with `None`
19323
- * - `Some(effect)` runs the inner effect and wraps its success value in `Some`
19324
- * - Inner failures are preserved in the resulting effect
19325
- *
19326
- * **Example** (Transposing an Option of an Effect)
19327
- *
19328
- * ```ts import.meta.vitest
19329
- * import { Effect, Option } from "effect"
19330
- *
19331
- * const some = Option.some(Effect.succeed(42))
19332
- *
19333
- * // ┌─── Effect<Option<number>, never, never>
19334
- * // ▼
19335
- * const program = Effect.transposeOption(some)
19336
- *
19337
- * Effect.runSync(program) // => Option.some(42)
19338
- * ```
19339
- *
19340
- * @stability stable
19341
- * @category converting
19342
- * @since 3.13.0
19343
- */
19344
- const transposeOption = transposeOption$1;
19345
- /**
19346
19311
  * Chains effects to produce new `Effect` instances, useful for combining
19347
19312
  * operations that depend on previous results.
19348
19313
  *
@@ -42355,7 +42320,7 @@ function OptionFromOptional(schema) {
42355
42320
  * @category schemas
42356
42321
  * @since 3.10.0
42357
42322
  */
42358
- function Redacted$1(value, options) {
42323
+ function Redacted(value, options) {
42359
42324
  const label = typeof options?.label === "string" ? options.label : void 0;
42360
42325
  const disallowJsonEncode = options?.disallowJsonEncode === true;
42361
42326
  const normalizedOptions = label !== void 0 ? disallowJsonEncode ? {
@@ -51833,46 +51798,6 @@ function Record(key, value, pathOrOptions, options) {
51833
51798
  function Port$1(name) {
51834
51799
  return schema$1(PortSchema, name);
51835
51800
  }
51836
- /**
51837
- * Creates a config for a redacted string value. The parsed result is wrapped
51838
- * in a `Redacted` container that hides the value from logs and `toString`.
51839
- *
51840
- * **When to use**
51841
- *
51842
- * Use to read secret string settings that should not be exposed in logs or
51843
- * string output.
51844
- *
51845
- * **Details**
51846
- *
51847
- * Shortcut for `Config.schema(Schema.Redacted(Schema.String), name)`.
51848
- *
51849
- * **Example** (Reading a secret)
51850
- *
51851
- * ```ts import.meta.vitest
51852
- * import { Config, ConfigProvider, Effect } from "effect"
51853
- *
51854
- * const program = Config.Redacted("API_KEY").pipe(Effect.map(String))
51855
- *
51856
- * const provider = ConfigProvider.fromEnv({
51857
- * env: {
51858
- * API_KEY: "sk-1234567890abcdef"
51859
- * }
51860
- * })
51861
- *
51862
- * Effect.runSync(
51863
- * program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
51864
- * ) // => "<redacted>"
51865
- * ```
51866
- *
51867
- * @see {@link String} for non-secret string settings
51868
- *
51869
- * @stability stable
51870
- * @category constructors
51871
- * @since 2.0.0
51872
- */
51873
- function Redacted(name) {
51874
- return schema$1(Redacted$1(String$6), name);
51875
- }
51876
51801
  // ../../node_modules/.pnpm/effect@4.1.4/node_modules/effect/dist/Console.js
51877
51802
  /**
51878
51803
  * Context reference for the current console service in the Effect system, allowing access to the active console implementation from within the Effect context.
@@ -58551,7 +58476,7 @@ const TypeId$22 = "~effect/http/HttpIncomingMessage";
58551
58476
  * @category schemas
58552
58477
  * @since 4.0.0
58553
58478
  */
58554
- const schemaBodyJson = (schema, options) => {
58479
+ const schemaBodyJson$1 = (schema, options) => {
58555
58480
  const decode = decodeEffect(toCodecJson(schema));
58556
58481
  const decodeJson = options?.reviver === void 0 ? void 0 : decodeEffect(fromJsonString(toCodecJson(schema), options));
58557
58482
  return (self) => decodeJson === void 0 ? flatMap$3(self.json, (u) => decode(u, options)) : flatMap$3(self.text, (body) => body === "" ? flatMap$3(self.json, (u) => decode(u, options)) : decodeJson(body, options));
@@ -61436,6 +61361,22 @@ const HttpServerRequest = /*#__PURE__*/ Service$1("effect/http/HttpServerRequest
61436
61361
  */
61437
61362
  var ParsedSearchParams = class extends (/*#__PURE__*/ Service$1()("effect/http/ParsedSearchParams")) {};
61438
61363
  /**
61364
+ * Reads the current request body as JSON and decodes it with the supplied schema.
61365
+ *
61366
+ * **Details**
61367
+ *
61368
+ * The effect can fail if the body cannot be read or parsed, or if schema decoding
61369
+ * fails.
61370
+ *
61371
+ * @stability unstable
61372
+ * @category schemas
61373
+ * @since 4.0.0
61374
+ */
61375
+ const schemaBodyJson = (schema, options) => {
61376
+ const parse = schemaBodyJson$1(schema, options);
61377
+ return flatMap$3(HttpServerRequest, parse);
61378
+ };
61379
+ /**
61439
61380
  * Attempts to construct an absolute `URL` for a server request safely.
61440
61381
  *
61441
61382
  * **Details**
@@ -63441,7 +63382,7 @@ var Retry = class Retry extends (/*#__PURE__*/ TaggedClass("Retry")) {
63441
63382
  */
63442
63383
  const HttpResponseDetails$1 = /*#__PURE__*/ Struct$2({
63443
63384
  status: Int$1,
63444
- headers: Record$1(String$6, Union$2([String$6, Redacted$1(String$6)]))
63385
+ headers: Record$1(String$6, Union$2([String$6, Redacted(String$6)]))
63445
63386
  }).annotate({ identifier: "HttpResponseDetails" });
63446
63387
  const ReasonTypeId = "~effect/ai/AiError/Reason";
63447
63388
  const providerMetadataWithDefaults = () => ProviderMetadata$1.pipe(withConstructorDefault(succeed$5({})), withDecodingDefault(succeed$5({})));
@@ -103792,8 +103733,8 @@ const make$8 = (httpClient, options = {}) => {
103792
103733
  const executeStreamRequest = (request) => suspend$3(() => options.transformClient ? flatMap$3(options.transformClient(httpClient), (client) => filterStatusOk(client).execute(request)) : filterStatusOk(httpClient).execute(request));
103793
103734
  const decodeBinary = (response) => map$7(response.arrayBuffer, (buffer) => new Uint8Array(buffer));
103794
103735
  const binaryRequest = (request) => executeStreamRequest(request).pipe(map$7((response) => response.stream), unwrap$4);
103795
- const decodeSuccess = (schema) => (response) => schemaBodyJson(schema)(response);
103796
- const decodeError = (tag, schema) => (response) => flatMap$3(schemaBodyJson(schema)(response), (cause) => fail$6(AnthropicClientError(tag, cause, response)));
103736
+ const decodeSuccess = (schema) => (response) => schemaBodyJson$1(schema)(response);
103737
+ const decodeError = (tag, schema) => (response) => flatMap$3(schemaBodyJson$1(schema)(response), (cause) => fail$6(AnthropicClientError(tag, cause, response)));
103797
103738
  return {
103798
103739
  httpClient,
103799
103740
  "messagesPost": (options) => post("/v1/messages").pipe(setHeaders$1({
@@ -106902,6 +106843,13 @@ const PackageMetadata = Struct$2({
106902
106843
  });
106903
106844
  // ../../packages/runtime/src/server/auth.ts
106904
106845
  const localAuth = map$3(option(String$5("AUTH_URL")), isNone);
106846
+ function requireAdmin(user, message) {
106847
+ if (user.admin) return void_$2;
106848
+ return fail$6(AuthError.make({
106849
+ error: "access_denied",
106850
+ message
106851
+ }));
106852
+ }
106905
106853
  function identifyRequestOf(headers) {
106906
106854
  return IdentifyRequest.make({
106907
106855
  address: fromNullishOr$1(headers[CLIENT_HEADER]),
@@ -106951,7 +106899,7 @@ var Auth = class Auth extends Service$1()("@deslop/runtime/server/auth") {
106951
106899
  const answers = yield* makeWith$2(fnUntraced(function* (body) {
106952
106900
  const response = yield* pipe(post(new URL(IDENTIFY_PATH, issuer).href), bodyText(body, "application/json"), client.execute, timeout("10 seconds"));
106953
106901
  if (response.status === 401 || response.status === 403) return yield* refusalOf(response.status, getOrElse$1(yield* option$1(response.text), constant("Sign in first")));
106954
- return yield* schemaBodyJson(Account)(yield* filterStatusOk$1(response));
106902
+ return yield* schemaBodyJson$1(Account)(yield* filterStatusOk$1(response));
106955
106903
  }, asAuthError("The authorization service is temporarily unavailable")), {
106956
106904
  capacity: 1024,
106957
106905
  timeToLive: match$3({
@@ -106994,7 +106942,7 @@ var AiGateway = class AiGateway extends Service$1()("@deslop/runtime/server/ai/A
106994
106942
  });
106995
106943
  const gateway = yield* AiGateway;
106996
106944
  const client = yield* make$7({
106997
- apiUrl: `${yield* gateway.apiUrl}/connection`,
106945
+ apiUrl: `${yield* gateway.apiUrl}/anthropic`,
106998
106946
  transformClient: yield* gateway.authorize(userId)
106999
106947
  });
107000
106948
  return yield* provideService$2(make$6({
@@ -107024,6 +106972,13 @@ var AiGateway = class AiGateway extends Service$1()("@deslop/runtime/server/ai/A
107024
106972
  }));
107025
106973
  };
107026
106974
  // ../../packages/runtime/src/server/mcp.ts
106975
+ const McpStream = middleware()((app) => gen(function* () {
106976
+ if ((yield* HttpServerRequest).method === "POST") {
106977
+ const subscription = yield* option$1(schemaBodyJson(Struct$2({ method: Literal("subscriptions/listen") })));
106978
+ if (isSome(subscription)) yield* annotateCurrentSpan("rpc.stream", true);
106979
+ }
106980
+ return yield* app;
106981
+ }));
107027
106982
  const layerStructuredTools = effect(McpServer, gen(function* () {
107028
106983
  const registry = yield* McpServer;
107029
106984
  return McpServer.of({
@@ -107901,7 +107856,7 @@ function layerMcp(options) {
107901
107856
  ],
107902
107857
  registrations: provide$2(options.registrations, layerStructuredTools),
107903
107858
  version: metadata.version
107904
- }), HttpAuth.layer);
107859
+ }), merge$4(HttpAuth.layer, McpStream.layer));
107905
107860
  }));
107906
107861
  }
107907
107862
  const layerNodeHttpServer = layerConfig(createServer, {
@@ -108405,7 +108360,7 @@ const updateRelease = fnUntraced(function* (name) {
108405
108360
  const path = yield* Path$1;
108406
108361
  const root = yield* serviceDirectory(name);
108407
108362
  const running = (yield* decodeEffect(fromJsonString(Struct$2({ version: AppVersion })))(yield* fs.readFileString(path.join(root, "current", "package.json")))).version;
108408
- const latest = (yield* pipe(filterStatusOk(yield* HttpClient).get(`https://registry.npmjs.org/@deslop%2f${name}/latest`), flatMap$3(schemaBodyJson(Struct$2({ version: AppVersion }))), timeout("15 seconds"))).version;
108363
+ const latest = (yield* pipe(filterStatusOk(yield* HttpClient).get(`https://registry.npmjs.org/@deslop%2f${name}/latest`), flatMap$3(schemaBodyJson$1(Struct$2({ version: AppVersion }))), timeout("15 seconds"))).version;
108409
108364
  if (latest === running) return `${name} ${running} is current\n`;
108410
108365
  const npm = path.resolve(path.dirname(execPath), "../lib/node_modules/npm/bin/npm-cli.js");
108411
108366
  if (!(yield* fs.exists(npm))) return yield* AppError.make({ message: "This Node runtime does not include npm; install Node with Vite+" });
@@ -109394,19 +109349,42 @@ function unitFailures(text) {
109394
109349
  }));
109395
109350
  }
109396
109351
  // src/services/inventory/lib/launchd.ts
109397
- const launchAgents = fnUntraced(function* (text) {
109398
- return yield* forEach$1(getSomes(map$10(pipe(trim(text), split$1("\n"), drop$1(1)), (line) => {
109399
- const [pid, status, label] = split$1(line, " ");
109400
- return pipe(label ?? "", liftPredicate((name) => startsWith("deslop-")(name) && !endsWith("-update")(name)), map$13((name) => ({
109401
- label: decodeSync(UnitId)(name),
109402
- pid: flatMap$8(parse$2(pid), decodeOption(ProcessId)),
109403
- status: status ?? ""
109404
- })));
109405
- })), (agent) => map$7(decodeEffect(FiniteFromString.check(isInt()))(agent.status), (status) => ({
109406
- ...agent,
109407
- status
109408
- })), { concurrency: "unbounded" });
109409
- });
109352
+ function launchAgents(text) {
109353
+ return getSomes(pipe(text, split$1("\n"), map$10((line) => {
109354
+ const [pid, status = "", label = ""] = split$1(trim(line), " ");
109355
+ if (!isNonEmpty$1(label) || startsWith("com.apple.")(label) || startsWith("application.")(label) || startsWith("deslop-")(label) && endsWith("-update")(label)) return none();
109356
+ const processId = filter$7(decodeOption(ProcessIdFromString)(pid), (value) => value > 0);
109357
+ if (isNone(processId) && pid !== "-") return none();
109358
+ return some$1({
109359
+ detail: "user · launch agent",
109360
+ label: UnitId.make(label),
109361
+ pid: processId,
109362
+ status: parse$2(status)
109363
+ });
109364
+ })));
109365
+ }
109366
+ function dockApplications(text) {
109367
+ return getSomes(pipe(text, split$1(/\n(?=\s*[0-9]+\))/u), map$10((block) => {
109368
+ const name = pipe(match$2(/^\s*[0-9]+\) "(.+)" ASN:/u)(block), map$13((match) => match[1] ?? ""), filter$7(isNonEmpty$1));
109369
+ const pid = pipe(match$2(/^\s+pid = ([0-9]+) .*\btype="Foreground"(?:\s|$)/mu)(block), flatMap$8((match) => decodeOption(ProcessIdFromString)(match[1] ?? "")), filter$7((value) => value > 0));
109370
+ return map$13(all$4({
109371
+ name,
109372
+ pid
109373
+ }), (app) => ({
109374
+ detail: "user · application",
109375
+ label: UnitId.make(app.name),
109376
+ pid: app.pid
109377
+ }));
109378
+ })));
109379
+ }
109380
+ function macApplications(agents, applications) {
109381
+ const running = getSomes(map$10(agents, (agent) => map$13(agent.pid, (pid) => ({
109382
+ detail: agent.detail,
109383
+ label: agent.label,
109384
+ pid
109385
+ }))));
109386
+ return dedupeWith([...applications, ...running], (left, right) => left.pid === right.pid);
109387
+ }
109410
109388
  // src/services/inventory/lib/command.ts
109411
109389
  const WRAPPERS = [
109412
109390
  "env",
@@ -110039,8 +110017,10 @@ function launchdProcesses(text, agents) {
110039
110017
  start: match[5] ?? ""
110040
110018
  }))))));
110041
110019
  const parents = fromIterable$5(map$10(rows, (row) => [row.pid, row.parent]));
110042
- function agent(pid) {
110043
- return pipe(agents, get$8(pid), orElse$3(() => flatMap$8(pipe(parents, get$8(pid), filter$7((parent) => parent !== pid)), agent)));
110020
+ function agent(pid, visited = empty$5()) {
110021
+ if (has(visited, pid)) return none();
110022
+ add$1(visited, pid);
110023
+ return pipe(agents, get$8(pid), orElse$3(() => pipe(parents, get$8(pid), flatMap$8((parent) => agent(parent, visited)))));
110044
110024
  }
110045
110025
  return getSomes(map$10(rows, (row) => flatMap$8(agent(row.pid), (unit) => map$13(all$4({
110046
110026
  start: make$76(row.start),
@@ -110402,7 +110382,8 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
110402
110382
  });
110403
110383
  const darwin = gen(function* () {
110404
110384
  const launchd = yield* all$1({
110405
- agents: result$1(flatMap$3(command("launchctl", ["list"]), launchAgents)),
110385
+ agents: result$1(map$7(command("launchctl", ["list"]), launchAgents)),
110386
+ applications: result$1(map$7(command("/usr/bin/lsappinfo", ["list"]), dockApplications)),
110406
110387
  table: result$1(command("env", [
110407
110388
  "LC_ALL=C",
110408
110389
  "ps",
@@ -110413,8 +110394,23 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
110413
110394
  }, { concurrency: "unbounded" });
110414
110395
  const time = yield* now;
110415
110396
  const total = millis(sumAll(flatMap$6(cpus(), (cpu) => values(cpu.times))));
110397
+ const apps = macApplications(getOrElse(launchd.agents, () => []), getOrElse(launchd.applications, () => []));
110398
+ function appItems(found) {
110399
+ return map$10(found, (app) => InventoryItem.make({
110400
+ active: true,
110401
+ detail: app.detail,
110402
+ id: ItemId.make(`${worker}:user:${app.label}`),
110403
+ kind: "service",
110404
+ name: app.label,
110405
+ running: true,
110406
+ scope: some$1("user"),
110407
+ state: "running",
110408
+ url: none(),
110409
+ worker
110410
+ }));
110411
+ }
110416
110412
  const records = map$12(launchd.table, (text) => {
110417
- const agents = fromIterable$5(getSomes(pipe(launchd.agents, getOrElse(() => []), map$10((agent) => map$13(agent.pid, (processId) => [processId, agent.label])))));
110413
+ const agents = fromIterable$5(map$10(apps, (app) => [app.pid, app.label]));
110418
110414
  return filter$5(launchdProcesses(text, agents), (record) => record.process.pid === selfProcess || !pipe(agents, get$8(selfProcess), contains$2(record.unit)));
110419
110415
  });
110420
110416
  const owned = getOrElse(records, empty$15);
@@ -110424,53 +110420,57 @@ var Inventory = class extends Service$1()("@deslop/deploy/services/inventory/ser
110424
110420
  time,
110425
110421
  total
110426
110422
  })),
110427
- sources: [collect("Launch agents", map$7(fromResult(launchd.agents), (agents) => map$10(agents, (agent) => InventoryItem.make({
110428
- active: isSome(agent.pid),
110429
- detail: "user · launch agent",
110430
- failure: pipe(agent.status, liftPredicate((status) => isNone(agent.pid) && status !== 0), map$13((status) => ({
110431
- at: none(),
110432
- reason: exitFailure(status)
110433
- }))),
110434
- health: match(isNone(agent.pid) && agent.status !== 0, {
110435
- onFalse: constant("quiet"),
110436
- onTrue: constant("error")
110437
- }),
110438
- id: ItemId.make(`${worker}:user:${agent.label}`),
110439
- kind: "service",
110440
- name: agent.label,
110441
- running: isSome(agent.pid),
110442
- scope: some$1("user"),
110443
- state: match$8(agent.pid, {
110444
- onNone: () => match(agent.status === 0, {
110445
- onFalse: constant("failed · failed"),
110446
- onTrue: constant("inactive · dead")
110423
+ sources: [
110424
+ collect("Launch agents", map$7(fromResult(launchd.agents), (agents) => pipe(agents, filter$5((agent) => match$8(agent.pid, {
110425
+ onNone: () => exists(agent.status, (status) => status !== 0),
110426
+ onSome: (id) => some(apps, (app) => app.pid === id && app.label === agent.label)
110427
+ })), map$10((agent) => InventoryItem.make({
110428
+ active: isSome(agent.pid),
110429
+ detail: agent.detail,
110430
+ failure: pipe(agent.status, filter$7((status) => isNone(agent.pid) && status !== 0), map$13((status) => ({
110431
+ at: none(),
110432
+ reason: exitFailure(status)
110433
+ }))),
110434
+ health: match(isNone(agent.pid), {
110435
+ onFalse: constant("quiet"),
110436
+ onTrue: constant("error")
110447
110437
  }),
110448
- onSome: constant("running")
110449
- }),
110450
- url: none(),
110451
- worker
110452
- })))), collect("Listening ports", flatMap$3(command("lsof", [
110453
- "-nP",
110454
- "+c0",
110455
- "-iTCP",
110456
- "-sTCP:LISTEN",
110457
- "-iUDP",
110458
- "-F",
110459
- "pctPnT"
110460
- ]), (text) => portItems(lsofSockets(text), worker, http, {
110461
- cwd: fnUntraced(function* (processId) {
110462
- return pipe(yield* option$1(command("lsof", [
110463
- "-nP",
110464
- "-a",
110465
- "-p",
110466
- `${processId}`,
110467
- "-d",
110468
- "cwd",
110469
- "-Fn"
110470
- ])), getOrElse$1(constant("")), split$1("\n"), findFirst(startsWith("n")), map$13(slice(1)));
110471
- }),
110472
- unit: (processId) => succeed$5(pipe(owned, findFirst((record) => record.process.pid === processId), map$13((record) => record.unit)))
110473
- })))]
110438
+ id: ItemId.make(`${worker}:user:${agent.label}`),
110439
+ kind: "service",
110440
+ name: agent.label,
110441
+ running: isSome(agent.pid),
110442
+ scope: some$1("user"),
110443
+ state: match$8(agent.pid, {
110444
+ onNone: constant("failed · failed"),
110445
+ onSome: constant("running")
110446
+ }),
110447
+ url: none(),
110448
+ worker
110449
+ }))))),
110450
+ collect("Applications", map$7(fromResult(launchd.applications), appItems)),
110451
+ collect("Listening ports", flatMap$3(command("lsof", [
110452
+ "-nP",
110453
+ "+c0",
110454
+ "-iTCP",
110455
+ "-sTCP:LISTEN",
110456
+ "-iUDP",
110457
+ "-F",
110458
+ "pctPnT"
110459
+ ]), (text) => portItems(lsofSockets(text), worker, http, {
110460
+ cwd: fnUntraced(function* (processId) {
110461
+ return pipe(yield* option$1(command("lsof", [
110462
+ "-nP",
110463
+ "-a",
110464
+ "-p",
110465
+ `${processId}`,
110466
+ "-d",
110467
+ "cwd",
110468
+ "-Fn"
110469
+ ])), getOrElse$1(constant("")), split$1("\n"), findFirst(startsWith("n")), map$13(slice(1)));
110470
+ }),
110471
+ unit: (processId) => succeed$5(pipe(owned, findFirst((record) => record.process.pid === processId), map$13((record) => record.unit)))
110472
+ })))
110473
+ ]
110474
110474
  };
110475
110475
  });
110476
110476
  const start = fnUntraced(function* (input) {
@@ -111108,32 +111108,13 @@ var Metrics = class extends Service$1()("@deslop/deploy/services/metrics/service
111108
111108
  static layer = provide$2(effect(this, this.make), this.migrations);
111109
111109
  };
111110
111110
  // src/services/fleet/service.ts
111111
- const PEER = {
111112
- admin: false,
111113
- id: UserId.make("deploy:peer"),
111114
- name: "deploy"
111115
- };
111116
111111
  const makeRemoteClient = make$26(RpcContracts.middleware(RpcStream), { flatten: true });
111117
- const layerPeerAuth = effectContext(gen(function* () {
111112
+ const layerPeerAuth = effect(PeerRpcAuth, gen(function* () {
111118
111113
  const auth = yield* Auth;
111119
- const digest = yield* Digest;
111120
- function hash(text) {
111121
- return digest.digestHex(sha256, new TextEncoder().encode(text));
111122
- }
111123
- const expected = yield* transposeOption(map$13(yield* option(Redacted("DEPLOY_KEY")), (key) => hash(`Bearer ${value$2(key)}`)));
111124
- function isPeer(headers) {
111125
- return map$7(hash(headers["authorization"] ?? ""), (actual) => contains$2(expected, actual));
111126
- }
111127
- return add$2(Auth.makeContext(fnUntraced(function* (headers) {
111128
- if (yield* isPeer(headers)) return {
111129
- ...PEER,
111130
- signOut: false
111131
- };
111132
- return yield* auth.account(headers);
111133
- })), PeerRpcAuth, PeerRpcAuth.of((effect, request) => flatMap$3(isPeer(request.headers), (allowed) => {
111134
- if (allowed) return effect;
111135
- return fail$6(AuthError.make({ message: "Only another Deploy worker may issue a local command" }));
111136
- })));
111114
+ return PeerRpcAuth.of((effect, request) => gen(function* () {
111115
+ yield* requireAdmin(yield* auth.user(request.headers), "Only an admin may issue a local command");
111116
+ return yield* effect;
111117
+ }));
111137
111118
  }));
111138
111119
  function asDeployError(effect) {
111139
111120
  return mapError$2(effect, (cause) => {
@@ -111179,18 +111160,21 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111179
111160
  name,
111180
111161
  url: `https://${name}.${suffix}:${port}`
111181
111162
  }), { concurrency: 1 });
111182
- const peerHeaders = match$8(yield* option(Redacted("DEPLOY_KEY")), {
111183
- onNone: () => ({}),
111184
- onSome: (key) => ({ authorization: `Bearer ${value$2(key)}` })
111185
- });
111186
111163
  const clients = yield* forEach$1(workers, (worker) => gen(function* () {
111164
+ const connected = yield* make$54(false);
111187
111165
  const url = new URL(RPC_PATH, worker.url);
111188
111166
  url.protocol = match(new URL(worker.url).protocol === "http:", {
111189
111167
  onFalse: constant("wss:"),
111190
111168
  onTrue: constant("ws:")
111191
111169
  });
111192
- const protocol = yield* build(pipe(layerProtocolSocket({ pingTimeout: seconds(15) }), provide$2(layerWebSocket(url.href)), provide$2(layerSchemaBinary()), provideMerge(layerRpcStreamClient)));
111193
- return [worker.name, yield* provideContext$2(makeRemoteClient, protocol)];
111170
+ const protocol = yield* build(pipe(layerProtocolSocket({ pingTimeout: seconds(15) }), provide$2(succeed$6(ConnectionHooks, {
111171
+ onConnect: set(connected, true),
111172
+ onDisconnect: set(connected, false)
111173
+ })), provide$2(layerWebSocket(url.href)), provide$2(layerSchemaBinary()), provideMerge(layerRpcStreamClient)));
111174
+ return [worker.name, {
111175
+ client: yield* provideContext$2(makeRemoteClient, protocol),
111176
+ connected
111177
+ }];
111194
111178
  }), { concurrency: "unbounded" });
111195
111179
  const peers = fromEntries(clients);
111196
111180
  const previous = yield* make$54({});
@@ -111216,10 +111200,11 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111216
111200
  workers: dedupe([...snapshot.workers, ...map$10(workers, (worker) => worker.name)])
111217
111201
  };
111218
111202
  }), "Fleet.local");
111219
- const remote = fn("Fleet.remote")(function* (worker, use) {
111220
- yield* annotateCurrentSpan("worker", worker.name);
111221
- return yield* use(getOrThrow$1(get$12(peers, worker.name)), peerHeaders);
111222
- }, timeout(seconds(15)));
111203
+ const remote = fnUntraced(function* (worker, use) {
111204
+ const peer = getOrThrow$1(get$12(peers, worker.name));
111205
+ if (!(yield* get$2(peer.connected))) return yield* DeployError.make({ message: "Worker is unreachable" });
111206
+ return yield* pipe(use(peer.client), timeout(seconds(15)), withSpan("Fleet.remote", { attributes: { worker: worker.name } }));
111207
+ });
111223
111208
  function selectedWorker(target) {
111224
111209
  return pipe(workers, findFirst((worker) => worker.name === target), fromOption, mapError$2((cause) => DeployError.make({
111225
111210
  cause,
@@ -111257,7 +111242,7 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111257
111242
  worker: input.worker
111258
111243
  });
111259
111244
  if (input.worker === localWorker) return yield* tap$2(exposures.expose(omit(input, ["worker"])), () => inventory.refresh);
111260
- return yield* remote(yield* selectedWorker(input.worker), (client, headers) => client("exposures.apply", omit(input, ["worker"]), { headers }));
111245
+ return yield* remote(yield* selectedWorker(input.worker), (client) => client("exposures.apply", omit(input, ["worker"])));
111261
111246
  }, tap$2(() => reactivity.invalidate(["deployInventory"])), asDeployError),
111262
111247
  hide: fn("Fleet.hide")(function* (input) {
111263
111248
  yield* annotateCurrentSpan({
@@ -111265,7 +111250,7 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111265
111250
  worker: input.worker
111266
111251
  });
111267
111252
  if (input.worker === localWorker) return yield* tap$2(exposures.hide(input.name), () => inventory.refresh);
111268
- return yield* remote(yield* selectedWorker(input.worker), (client, headers) => client("exposures.remove", { name: input.name }, { headers }));
111253
+ return yield* remote(yield* selectedWorker(input.worker), (client) => client("exposures.remove", { name: input.name }));
111269
111254
  }, tap$2(() => reactivity.invalidate(["deployInventory"])), asDeployError),
111270
111255
  history: fn("Fleet.history")(function* (query) {
111271
111256
  yield* annotateCurrentSpan("minutes", toMinutes(query.minutes));
@@ -111277,7 +111262,7 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111277
111262
  minutes: toMinutes(query.minutes),
111278
111263
  workers: workers.length + 1
111279
111264
  });
111280
- return [yield* metrics.read(query), ...yield* forEach$1(workers, (worker) => pipe(remote(worker, (client, headers) => client("metrics.history", query, { headers })), timeout(seconds(2)), map$7((value) => ({
111265
+ return [yield* metrics.read(query), ...yield* forEach$1(workers, (worker) => pipe(remote(worker, (client) => client("metrics.history", query)), timeout(seconds(2)), map$7((value) => ({
111281
111266
  ...value,
111282
111267
  worker: worker.name
111283
111268
  })), tapError$3((cause) => logWarning("A worker history could not be read", cause)), catch_$2(fnUntraced(function* (cause) {
@@ -111295,7 +111280,7 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111295
111280
  worker: input.worker
111296
111281
  });
111297
111282
  if (input.worker === localWorker) return yield* inventory.run(omit(input, ["worker"]));
111298
- return yield* remote(yield* selectedWorker(input.worker), (client, headers) => client("inventory.start", omit(input, ["worker"]), { headers }));
111283
+ return yield* remote(yield* selectedWorker(input.worker), (client) => client("inventory.start", omit(input, ["worker"])));
111299
111284
  }, tap$2(() => reactivity.invalidate(["deployInventory"])), mapError$2((cause) => {
111300
111285
  if (is$2(DeployError)(cause)) return cause;
111301
111286
  return DeployError.make({
@@ -111305,7 +111290,7 @@ var Fleet = class Fleet extends Service$1()("@deslop/deploy/services/fleet/servi
111305
111290
  })),
111306
111291
  snapshot: withSpan(gen(function* () {
111307
111292
  const own = yield* local;
111308
- const others = yield* forEach$1(workers, (worker) => pipe(remote(worker, (client, headers) => client("inventory.snapshot", void 0, { headers })), timeout(seconds(2)), map$7((snapshot) => ({
111293
+ const others = yield* forEach$1(workers, (worker) => pipe(remote(worker, (client) => client("inventory.snapshot", void 0)), timeout(seconds(2)), map$7((snapshot) => ({
111309
111294
  ...snapshot,
111310
111295
  items: map$10(snapshot.items, (item) => ({
111311
111296
  ...item,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deslop/deploy",
3
- "version": "0.1.1318",
3
+ "version": "0.1.1328",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/MP281X/deslop.git",
@@ -40,5 +40,5 @@
40
40
  "engines": {
41
41
  "node": ">=26"
42
42
  },
43
- "fingerprint": "74803ea34f7f0bae3f78d30d1b3e51478a03d46be489ff707a0f218dc388e63c"
43
+ "fingerprint": "3beb663bbbd5c2028d97ef47ee5abf674ed851c26fc098ae4286a90d9400f35b"
44
44
  }