@moondeck/station 1.0.4 → 1.0.5

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.
@@ -38,41 +38,48 @@ UAI_TTYD_BIND="${UAI_TTYD_BIND:-127.0.0.1}"
38
38
  UAI_LOG_DIR="${UAI_LOG_DIR:-$UAI_DATA_DIR/logs}"
39
39
  mkdir -p "$UAI_LOG_DIR"
40
40
 
41
- # Optional dependencies — fail fast with a structured error if missing.
42
- # docker is only a dependency of the docker runtime mode: the Apple runtime
43
- # path must work on a Docker-free Mac (ADR-106), and its own CLI is validated
44
- # by validate_task_runtime_selection instead.
45
- agent_required_bins="sqlite3 jq git"
46
- if [ "${UAI_TASK_RUNTIME:-docker}" != "apple-container" ]; then
47
- agent_required_bins="$agent_required_bins docker"
48
- fi
49
- # Collect EVERY missing tool before failing: reporting them one at a time
50
- # cost one full fix-and-Resume round trip per binary on a fresh Amazon
51
- # Linux box (sqlite3, then jq — live 2026-08-21). Bash 3.2: plain string
52
- # accumulation, no arrays.
53
- missing_bins=""
54
- for bin in $agent_required_bins; do
55
- if ! command -v "$bin" >/dev/null 2>&1; then
56
- missing_bins="$missing_bins $bin"
57
- fi
58
- done
41
+ # Required dependencies — fail fast with a structured error if missing. The
42
+ # list, and how it follows the runtime choice, live in _deps.sh, which
43
+ # check-deps.sh shares to report the same gaps on the host page.
44
+ # The directory holding the real file behind $1, following file symlinks
45
+ # (bash 3.2: macOS has no `readlink -f`, so loop on plain `readlink`).
46
+ _uai_real_dir() {
47
+ local path="$1" dir link hops=0
48
+ while [ -L "$path" ]; do
49
+ hops=$((hops + 1))
50
+ if [ "$hops" -gt 40 ]; then
51
+ printf 'too many levels of symbolic links: %s\n' "$1" >&2
52
+ return 1
53
+ fi
54
+ dir=$(cd -P "$(dirname "$path")" && pwd) || return 1
55
+ link=$(readlink "$path") || return 1
56
+ case "$link" in
57
+ /*) path=$link ;;
58
+ *) path="$dir/$link" ;;
59
+ esac
60
+ done
61
+ cd -P "$(dirname "$path")" && pwd
62
+ }
63
+ # _deps.sh sits beside the real _common.sh, which may be reached through a
64
+ # symlink (review #5r0tze).
65
+ _uai_agent_dir=$(_uai_real_dir "${BASH_SOURCE[0]}") || {
66
+ printf '{"ok":false,"error":{"code":"BAD_ARGS","message":"cannot locate the agent scripts beside %s"}}\n' "${BASH_SOURCE[0]}" >&2
67
+ exit 2
68
+ }
69
+ # shellcheck source=_deps.sh
70
+ . "$_uai_agent_dir/_deps.sh"
71
+ missing_bins=$(uai_missing_required_bins)
59
72
  if [ -n "$missing_bins" ]; then
60
- missing_bins="${missing_bins# }"
61
73
  printf '{"ok":false,"error":{"code":"MISSING_DEPENDENCY","message":"missing on PATH: %s — install with your package manager (dnf/apt/brew), then Resume"}}\n' "$missing_bins" >&2
62
74
  exit 127
63
75
  fi
64
76
 
65
-
66
- # The docker BINARY existing does not make `docker compose` work: the v2
67
- # compose plugin ships separately, and a bare-engine install (Amazon Linux
68
- # 2023's docker package) answers `docker compose` with the top-level help
69
- # text — the operator saw exactly that as their task error (live
70
- # 2026-08-21). Called LAZILY by the task scripts right before their first
71
- # compose use, never at source time: argument validation must precede any
72
- # docker invocation (the task-down/task-up tests enforce that ordering).
77
+ # Called LAZILY by the task scripts right before their first compose use,
78
+ # never at source time: argument validation must precede any docker
79
+ # invocation (the task-down/task-up tests enforce that ordering). A no-op on
80
+ # the Apple runtime (_deps.sh).
73
81
  uai_require_compose_plugin() {
74
- [ "${UAI_TASK_RUNTIME:-docker}" = "apple-container" ] && return 0
75
- if ! docker compose version >/dev/null 2>&1; then
82
+ if uai_compose_plugin_missing; then
76
83
  printf '{"ok":false,"error":{"code":"MISSING_DEPENDENCY","message":"missing on PATH: docker-compose-plugin — install the Docker Compose v2 plugin, then Resume"}}\n' >&2
77
84
  exit 127
78
85
  fi
@@ -0,0 +1,47 @@
1
+ # shellcheck shell=bash
2
+ # uai agent — the binaries the task scripts need, in one place.
3
+ #
4
+ # Sourced by _common.sh, which refuses to run a task script without them,
5
+ # and by check-deps.sh, which only reports them (the Station's
6
+ # `agentDependencies` capability). Side-effect free: no `set`, no output,
7
+ # no environment requirements. Bash 3.2 (CLAUDE.md).
8
+ #
9
+ # The runtime choice is the one the Station publishes to every agent
10
+ # script (lib/container-runtime.ts): UAI_TASK_RUNTIME=apple-container means
11
+ # the Apple runtime, whose own CLI validate_task_runtime_selection checks;
12
+ # anything else is Docker, which needs the docker CLI and the Compose v2
13
+ # plugin. The Apple runtime path must work on a Docker-free Mac (ADR-106).
14
+
15
+ agent_required_bins="sqlite3 jq git"
16
+ if [ "${UAI_TASK_RUNTIME:-docker}" != "apple-container" ]; then
17
+ agent_required_bins="$agent_required_bins docker"
18
+ fi
19
+
20
+ # Prints every missing required binary, space-separated; nothing when none.
21
+ # Collects them all: reporting them one at a time cost one full
22
+ # fix-and-Resume round trip per binary on a fresh Amazon Linux box
23
+ # (sqlite3, then jq — live 2026-08-21).
24
+ uai_missing_required_bins() {
25
+ local bin missing=""
26
+ for bin in $agent_required_bins; do
27
+ if ! command -v "$bin" >/dev/null 2>&1; then
28
+ missing="$missing $bin"
29
+ fi
30
+ done
31
+ printf '%s' "${missing# }"
32
+ }
33
+
34
+ # Succeeds when the Docker runtime applies and `docker compose` does not
35
+ # run. The docker BINARY existing does not make `docker compose` work: the
36
+ # v2 plugin ships separately, and a bare-engine install (Amazon Linux 2023's
37
+ # docker package) answers `docker compose` with the top-level help text
38
+ # (live 2026-08-21). `docker compose version` never dials the daemon.
39
+ uai_compose_plugin_missing() {
40
+ if [ "${UAI_TASK_RUNTIME:-docker}" = "apple-container" ]; then
41
+ return 1
42
+ fi
43
+ if docker compose version >/dev/null 2>&1; then
44
+ return 1
45
+ fi
46
+ return 0
47
+ }
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ # uai agent — report the task scripts' missing dependencies.
3
+ #
4
+ # Usage: check-deps.sh
5
+ #
6
+ # stdout: {"ok":true,"data":{"missing":["sqlite3","docker-compose-plugin"]}}
7
+ #
8
+ # Reports, never refuses: exits 0 whenever the check ran, whatever is
9
+ # missing. The Station runs it at boot and on a timer and advertises the
10
+ # result as its `agentDependencies` capability; the task scripts keep their
11
+ # own refusal (_common.sh). Needs no database and no jq (jq may be one of the
12
+ # missing). Follows the same runtime choice as the task scripts (_deps.sh).
13
+ # Bash 3.2.
14
+
15
+ set -euo pipefail
16
+
17
+ # The directory holding the real file behind $1, following file symlinks
18
+ # (bash 3.2: macOS has no `readlink -f`, so loop on plain `readlink`).
19
+ _uai_real_dir() {
20
+ local path="$1" dir link hops=0
21
+ while [ -L "$path" ]; do
22
+ hops=$((hops + 1))
23
+ if [ "$hops" -gt 40 ]; then
24
+ printf 'too many levels of symbolic links: %s\n' "$1" >&2
25
+ return 1
26
+ fi
27
+ dir=$(cd -P "$(dirname "$path")" && pwd) || return 1
28
+ link=$(readlink "$path") || return 1
29
+ case "$link" in
30
+ /*) path=$link ;;
31
+ *) path="$dir/$link" ;;
32
+ esac
33
+ done
34
+ cd -P "$(dirname "$path")" && pwd
35
+ }
36
+ # _deps.sh sits beside the real script, which may be reached through a
37
+ # symlink (review #5r0tze).
38
+ SCRIPT_DIR=$(_uai_real_dir "${BASH_SOURCE[0]}")
39
+ # shellcheck source=_deps.sh
40
+ . "$SCRIPT_DIR/_deps.sh"
41
+
42
+ missing=$(uai_missing_required_bins)
43
+ # Whether the plugin is installed is unknowable without the docker CLI, so
44
+ # it is reported only once docker itself is on PATH.
45
+ case " $missing " in
46
+ *" docker "*) ;;
47
+ *)
48
+ if uai_compose_plugin_missing; then
49
+ missing="${missing:+$missing }docker-compose-plugin"
50
+ fi
51
+ ;;
52
+ esac
53
+
54
+ # Every name comes from the fixed lists above: no JSON escaping needed.
55
+ json=""
56
+ for name in $missing; do
57
+ json="$json${json:+,}\"$name\""
58
+ done
59
+ printf '{"ok":true,"data":{"missing":[%s]}}\n' "$json"
package/src/cli.ts CHANGED
@@ -646,7 +646,7 @@ async function boundedResponseJson(
646
646
 
647
647
  // --- aws setup (ADR-125 BYO-AWS: mint the host's scoped AWS identity) --------
648
648
 
649
- /** Mirrors scripts/machine-ami/byo-aws-quickcreate.yaml — keep in sync. */
649
+ /** Mirrors host-agent/scripts/machine-ami/byo-aws-quickcreate.yaml — keep in sync. */
650
650
  const AWS_MACHINE_POLICY = {
651
651
  Version: "2012-10-17",
652
652
  Statement: [
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { requestAgentDependencyRecheck } from "../lib/agent-dependencies";
1
2
  import { assertShareablePath, normalizedWorkspacePath } from "./workspace-path-policy";
2
3
  import { hasPreviewUpstream, parsePreviewUpstream, tunnelPreviewUpstream } from "./preview-upstream";
3
4
  import { readBoundedFile } from "../lib/task-environment/workspace-files";
@@ -2821,6 +2822,9 @@ function failFromUnknown<T = never>(err: unknown): HostCommandResult<T> {
2821
2822
  };
2822
2823
  }
2823
2824
  if (AgentError.is(err)) {
2825
+ // The script's own text ("missing on PATH: sqlite3 — install …") is the
2826
+ // message the user reads; the host page catches up on the next check.
2827
+ if (err.code === "MISSING_DEPENDENCY") requestAgentDependencyRecheck();
2824
2828
  return {
2825
2829
  ok: false,
2826
2830
  code: mapAgentError(err.code),
package/src/main.ts CHANGED
@@ -1,8 +1,18 @@
1
1
  #!/usr/bin/env tsx
2
2
  import { stationAgentCliAdvertisable } from "../lib/agent-cli";
3
+ import {
4
+ AGENT_DEPENDENCY_RECHECK_MS,
5
+ AgentDependencyMonitor,
6
+ agentDependencyFix,
7
+ currentHostOs,
8
+ runCheckDeps,
9
+ setAgentDependencyRecheckRequester,
10
+ type AgentDependencyRuntime,
11
+ } from "../lib/agent-dependencies";
3
12
  import { PREVIEW_UPSTREAM_PROTOCOL_FEATURE, parsePreviewUpstream, tunnelPreviewUpstream } from "./preview-upstream";
4
13
  import { preparePreviewUpstream, previewRequestHeaders, isPreviewConnectFailure } from "../lib/preview-upstream";
5
14
  import { describeClose, suspendedFor } from "./bridge-diagnostics";
15
+ import { startProcessWakeDetector } from "./process-wake";
6
16
  import { internalHostGatewayAdvertisable } from "../lib/custom-connection-launch";
7
17
  import "./load-env";
8
18
  import { discoverCustomConnection, saveCustomConnection, saveCustomConnectionManual } from "../lib/custom-connection-capture";
@@ -184,7 +194,8 @@ import {
184
194
  onContainerRuntimeChange,
185
195
  containerRuntimeRecheckRequester,
186
196
  setContainerRuntimeRecheckRequester,
187
- startContainerRuntimeAutoRecheck,
197
+ syncContainerRuntimeAutoRecheck,
198
+ nudgeContainerRuntimeAutoRecheck,
188
199
  suspendContainerRuntime,
189
200
  containerRuntimeMachineIdentity,
190
201
  pinnedContainerRuntimeMachineIdentity,
@@ -192,6 +203,7 @@ import {
192
203
  rejectContainerRuntimeSelection,
193
204
  reprobeContainerRuntimeMachineIdentity,
194
205
  } from "../lib/container-runtime";
206
+ import { startStandardImageMaintenanceSchedule } from "../lib/standard-image-schedule";
195
207
  import { machineTasksEnabled, persistedTaskEnvironmentsMatchMachine, reconstructPersistedTaskEnvironment } from "../lib/task-environment";
196
208
  import { reconcileRunningTaskPersonCredentials } from "../lib/task-person-credentials";
197
209
  import { logVnodePressure } from "../lib/vnode-pressure";
@@ -523,6 +535,27 @@ const bridgeUrl =
523
535
 
524
536
  let ws: WebSocket | null = null;
525
537
  let stopping = false;
538
+
539
+ // Owner ask 4 (2026-11-09): the task scripts' dependency check, advertised
540
+ // as `agentDependencies` and never a gate (lib/agent-dependencies.ts). It
541
+ // follows the pinned runtime, so it runs only once one is pinned; the timer
542
+ // clears the state after an install without a restart.
543
+ const hostOs = currentHostOs();
544
+ const agentDependencies = new AgentDependencyMonitor({
545
+ check: (runtime) => runCheckDeps(runtime),
546
+ fix: (missing) => agentDependencyFix(missing, hostOs),
547
+ changed: () => sendCapabilities(),
548
+ warn: (message) => console.warn(message),
549
+ });
550
+ function agentDependencyRuntime(): AgentDependencyRuntime | null {
551
+ if (sidecarMode()) return null;
552
+ const runtime = containerRuntimeState();
553
+ return runtime.status === "ready" ? runtime.provider : null;
554
+ }
555
+ function recheckAgentDependencies(): void {
556
+ if (stopping) return;
557
+ void agentDependencies.recheck(agentDependencyRuntime());
558
+ }
526
559
  const openRouterBudgets = new OpenRouterBudgetPoller({ emit: frame => {
527
560
  if (!stopping && credentialFramesReady && ws?.readyState === WebSocket.OPEN) send(ws, frame);
528
561
  } });
@@ -619,6 +652,7 @@ const pendingRuntimeIsolationStatuses = new StoppedTaskStatusQueue(
619
652
  },
620
653
  );
621
654
  let stopRuntimeAutoRecheck = (): void => {};
655
+ let stopProcessWakeDetector = (): void => {};
622
656
  const runtimeActivationTail = new RuntimeActivationTail({
623
657
  isCurrent: runtimeActivationIsCurrent,
624
658
  onError: reportRuntimeActivationError,
@@ -954,10 +988,13 @@ function reconcileStores(): Promise<void> {
954
988
  // UAI_IMAGE_MAINTENANCE=external — a cloud job keeps the payload AMI fresh —
955
989
  // and reconciles only once, at start. A sidecar (ADR-133) has no image.
956
990
  if (env.UAI_IMAGE_MAINTENANCE === "host" && !sidecarMode()) {
957
- const maintenanceTimer = setInterval(() => {
958
- void ensureStandardImage().catch(() => undefined);
959
- }, MAINTENANCE_INTERVAL_MS);
960
- maintenanceTimer.unref?.();
991
+ startStandardImageMaintenanceSchedule({
992
+ intervalMs: MAINTENANCE_INTERVAL_MS,
993
+ // The public state: `ready` only once activation's fences (persisted
994
+ // environment identity, writable-container quarantine) have released it.
995
+ runtimeStatus: () => containerRuntimeCapabilityState().status,
996
+ run: () => ensureStandardImage(),
997
+ });
961
998
  }
962
999
  // ADR-135: one refresher per rotating credential. Owned host → the in-process
963
1000
  // loop refreshes and re-pushes; Uai-operated host → the broker Lambda
@@ -1654,6 +1691,8 @@ function buildCapabilities(): HostCapabilities {
1654
1691
  githubUsers: connectedUserIds(),
1655
1692
  // ADR-154 §13: where the switch to cloud credentials stands, and why.
1656
1693
  credentialsSwitch: credentialsActivation.status(),
1694
+ // Owner ask 4: what the task scripts lack on PATH. Report-only.
1695
+ ...(agentDependencies.state() === undefined ? {} : { agentDependencies: agentDependencies.state() }),
1657
1696
  };
1658
1697
  }
1659
1698
 
@@ -2155,17 +2194,16 @@ setAdvertisementFallback((kind) => hasStoredEngineAccounts(kind));
2155
2194
  // says: the leased lanes and the Managed Engine, which leases nothing (Kimi,
2156
2195
  // with no lane yet, is left out).
2157
2196
  setLeasedAdvertisement(() => (credentialsMode() === "active" ? CLOUD_CREDENTIAL_KINDS : null));
2197
+ setAgentDependencyRecheckRequester(recheckAgentDependencies);
2198
+ recheckAgentDependencies();
2199
+ setInterval(recheckAgentDependencies, AGENT_DEPENDENCY_RECHECK_MS).unref();
2158
2200
  onRegistryChange(() => sendCapabilities());
2159
2201
  onContainerRuntimeChange((next, previous) => {
2160
2202
  if (stopping) return;
2161
2203
  sendCapabilities();
2162
- if (next.status === "ready") {
2163
- stopRuntimeAutoRecheck();
2164
- stopRuntimeAutoRecheck = () => {};
2165
- } else if (previous.status === "ready") {
2166
- stopRuntimeAutoRecheck();
2167
- stopRuntimeAutoRecheck = startContainerRuntimeAutoRecheck();
2168
- }
2204
+ recheckAgentDependencies();
2205
+ // Idempotent: never a second loop, and a running one keeps its backoff.
2206
+ stopRuntimeAutoRecheck = syncContainerRuntimeAutoRecheck();
2169
2207
  if (
2170
2208
  containerRuntimeBecameReady(next, previous) ||
2171
2209
  containerRuntimeActivationRequired()
@@ -2176,8 +2214,15 @@ onContainerRuntimeChange((next, previous) => {
2176
2214
  );
2177
2215
  }
2178
2216
  });
2179
- stopRuntimeAutoRecheck = startContainerRuntimeAutoRecheck();
2217
+ stopRuntimeAutoRecheck = syncContainerRuntimeAutoRecheck();
2180
2218
  installContainerRuntimeRecheckRequester();
2219
+ // A wake is when a daemon hung in sleep/dark-wake comes back: an unavailable
2220
+ // runtime is probed now, not at its next backoff step. Process-level, so a
2221
+ // Mac that lost its bridge before sleeping still nudges; the per-connection
2222
+ // suspended-for warning in connect() only logs. A no-op while ready.
2223
+ stopProcessWakeDetector = startProcessWakeDetector({
2224
+ onWake: () => void nudgeContainerRuntimeAutoRecheck("system wake detected"),
2225
+ });
2181
2226
  // Re-advertise when a gh token is added/removed (ADR-033) so the host page's
2182
2227
  // per-host connected state updates promptly.
2183
2228
  onGithubChange(() => sendCapabilities());
@@ -6298,6 +6343,7 @@ function requestShutdown(signal: NodeJS.Signals): void {
6298
6343
  }
6299
6344
  void mcpGateway.stop();
6300
6345
  managedMutationDrain.stopAccepting();
6346
+ stopProcessWakeDetector();
6301
6347
  stopRuntimeAutoRecheck();
6302
6348
  runtimeActivationTail.stop();
6303
6349
  shutdownRequested = true;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Process-level suspend detector: one unref'd interval for the life of the
3
+ * process, independent of the bridge. The per-connection check in connect()
4
+ * only runs while a socket is open, so a Mac that dropped its connection
5
+ * before it slept never reported its wake (and an unavailable container
6
+ * runtime waited for its next backoff step instead of being probed).
7
+ */
8
+
9
+ import { suspendedFor } from "./bridge-diagnostics";
10
+
11
+ export const PROCESS_WAKE_TICK_MS = 5_000;
12
+
13
+ export function startProcessWakeDetector(deps: {
14
+ onWake: (suspendedMs: number) => void;
15
+ intervalMs?: number;
16
+ now?: () => number;
17
+ }): () => void {
18
+ const intervalMs = deps.intervalMs ?? PROCESS_WAKE_TICK_MS;
19
+ const now = deps.now ?? Date.now;
20
+ let lastTick = now();
21
+ const timer = setInterval(() => {
22
+ const at = now();
23
+ const suspended = suspendedFor(lastTick, at, intervalMs);
24
+ lastTick = at;
25
+ if (suspended === null) return;
26
+ try {
27
+ deps.onWake(suspended);
28
+ } catch (error) {
29
+ console.warn(
30
+ `[host-agent] wake handler failed: ${error instanceof Error ? error.message : String(error)}`,
31
+ );
32
+ }
33
+ }, intervalMs);
34
+ timer.unref?.();
35
+ return () => clearInterval(timer);
36
+ }
package/src/protocol.ts CHANGED
@@ -4202,6 +4202,11 @@ export interface HostCapabilities {
4202
4202
  * what stops it. Optional: hosts before 0.9.171 omit it, and the cloud
4203
4203
  * then says only that the runner has not switched. */
4204
4204
  credentialsSwitch?: CredentialsSwitchCapability;
4205
+ /** What this Station's task scripts need on PATH and lack (their own gate,
4206
+ * scripts/agent/_deps.sh). Report-only: the Station never refuses a task
4207
+ * over it. Absent while unchecked (runtime not ready, sidecar mode) and on
4208
+ * Stations before 1.0.5. The cloud drops a malformed one alone. */
4209
+ agentDependencies?: AgentDependencyCapability;
4205
4210
  }
4206
4211
 
4207
4212
  /**
@@ -4241,6 +4246,54 @@ export const MAX_CREDENTIALS_SWITCH_BLOCKERS = 20;
4241
4246
  export const MAX_CREDENTIALS_SWITCH_BLOCKER_CHARS = 300;
4242
4247
  export const MAX_CREDENTIALS_SWITCH_PROJECTS = 100;
4243
4248
 
4249
+ /**
4250
+ * The task scripts' dependency check, as the Station last ran it
4251
+ * (check-deps.sh). `missing` names binaries (`sqlite3`, `docker`, …) and
4252
+ * `docker-compose-plugin`; `fix` is a copyable command for this machine's
4253
+ * OS when the Station knows one (e.g. `sudo dnf install -y sqlite` on
4254
+ * Amazon Linux 2023). The Compose plugin has no such package there.
4255
+ */
4256
+ export type AgentDependencyCapability =
4257
+ | { status: "ok" }
4258
+ | { status: "missing"; missing: string[]; fix?: string };
4259
+
4260
+ export const MAX_AGENT_DEPENDENCIES = 8;
4261
+ export const MAX_AGENT_DEPENDENCY_FIX_CHARS = 200;
4262
+ /** A dependency name: a binary on PATH, or `docker-compose-plugin`. */
4263
+ export const AGENT_DEPENDENCY_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/;
4264
+
4265
+ /** The capability, exact and bounded; undefined when it is not one. The
4266
+ * cloud drops a malformed one alone, never the frame around it. */
4267
+ export function parseAgentDependencyCapability(value: unknown): AgentDependencyCapability | undefined {
4268
+ if (!isPlainRecord(value)) return undefined;
4269
+ if (value.status === "ok") {
4270
+ return Object.keys(value).length === 1 ? { status: "ok" } : undefined;
4271
+ }
4272
+ if (value.status !== "missing") return undefined;
4273
+ if (Object.keys(value).some((key) => key !== "status" && key !== "missing" && key !== "fix")) return undefined;
4274
+ const { missing, fix } = value;
4275
+ if (
4276
+ !Array.isArray(missing) ||
4277
+ missing.length < 1 ||
4278
+ missing.length > MAX_AGENT_DEPENDENCIES ||
4279
+ !missing.every((name) => typeof name === "string" && AGENT_DEPENDENCY_NAME.test(name)) ||
4280
+ new Set(missing).size !== missing.length
4281
+ ) {
4282
+ return undefined;
4283
+ }
4284
+ if (fix === undefined) return { status: "missing", missing: [...missing] as string[] };
4285
+ if (
4286
+ typeof fix !== "string" ||
4287
+ fix.trim().length === 0 ||
4288
+ fix.length > MAX_AGENT_DEPENDENCY_FIX_CHARS ||
4289
+ // One line, printable: it is shown as a copyable command.
4290
+ !/^[\x20-\x7e]+$/.test(fix)
4291
+ ) {
4292
+ return undefined;
4293
+ }
4294
+ return { status: "missing", missing: [...missing] as string[], fix };
4295
+ }
4296
+
4244
4297
  /** The capability, exact and bounded; undefined when it is not one. The
4245
4298
  * cloud drops a malformed one alone, never the frame around it. */
4246
4299
  export function parseCredentialsSwitchCapability(value: unknown): CredentialsSwitchCapability | undefined {