@cat-factory/local-server 0.6.0 → 0.7.3

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 (40) hide show
  1. package/LICENSE +21 -21
  2. package/dist/LocalContainerRunnerTransport.d.ts +83 -0
  3. package/dist/LocalContainerRunnerTransport.d.ts.map +1 -0
  4. package/dist/LocalContainerRunnerTransport.js +247 -0
  5. package/dist/LocalContainerRunnerTransport.js.map +1 -0
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +9 -4
  8. package/dist/config.js.map +1 -1
  9. package/dist/container.d.ts.map +1 -1
  10. package/dist/container.js +14 -4
  11. package/dist/container.js.map +1 -1
  12. package/dist/index.d.ts +2 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/runtimes/appleContainerRuntime.d.ts +21 -0
  17. package/dist/runtimes/appleContainerRuntime.d.ts.map +1 -0
  18. package/dist/runtimes/appleContainerRuntime.js +191 -0
  19. package/dist/runtimes/appleContainerRuntime.js.map +1 -0
  20. package/dist/runtimes/containerRuntime.d.ts +96 -0
  21. package/dist/runtimes/containerRuntime.d.ts.map +1 -0
  22. package/dist/runtimes/containerRuntime.js +99 -0
  23. package/dist/runtimes/containerRuntime.js.map +1 -0
  24. package/dist/runtimes/dockerRuntime.d.ts +27 -0
  25. package/dist/runtimes/dockerRuntime.d.ts.map +1 -0
  26. package/dist/runtimes/dockerRuntime.js +124 -0
  27. package/dist/runtimes/dockerRuntime.js.map +1 -0
  28. package/dist/runtimes/index.d.ts +13 -0
  29. package/dist/runtimes/index.d.ts.map +1 -0
  30. package/dist/runtimes/index.js +33 -0
  31. package/dist/runtimes/index.js.map +1 -0
  32. package/dist/server.d.ts +3 -0
  33. package/dist/server.d.ts.map +1 -1
  34. package/dist/server.js +67 -17
  35. package/dist/server.js.map +1 -1
  36. package/package.json +13 -8
  37. package/dist/LocalDockerRunnerTransport.d.ts +0 -95
  38. package/dist/LocalDockerRunnerTransport.d.ts.map +0 -1
  39. package/dist/LocalDockerRunnerTransport.js +0 -342
  40. package/dist/LocalDockerRunnerTransport.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAahD,wBAAsB,UAAU,CAC9B,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;CAAO,GACxC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CA8C5C"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAyB9D,wBAAsB,UAAU,CAC9B,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IACvB,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;CACT,GACL,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAwD5C"}
package/dist/server.js CHANGED
@@ -1,23 +1,46 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
1
3
  import { start } from '@cat-factory/node-server';
2
4
  import { logger } from '@cat-factory/server';
3
5
  import { applyLocalDefaults } from './config.js';
4
6
  import { buildLocalContainer } from './container.js';
5
7
  import { githubPatCreationUrl } from './github.js';
6
- import { createLocalDockerTransportFromEnv } from './LocalDockerRunnerTransport.js';
8
+ import { createLocalContainerTransportFromEnv } from './LocalContainerRunnerTransport.js';
9
+ import { createRuntimeAdapter, resolveRuntimeId } from './runtimes/index.js';
10
+ const execFileAsync = promisify(execFile);
7
11
  // Boot the local-mode service. It reuses the Node facade's `start()` — Postgres +
8
12
  // pg-boss + the execution worker + sweepers, served over @hono/node-server — passing
9
- // the local composition root so agent jobs run in local Docker containers and GitHub
10
- // is reached via a PAT. Requires DATABASE_URL (point it at the local Postgres); set
11
- // LOCAL_HARNESS_IMAGE to run repo-operating agent jobs (without it the board still
12
- // serves and only container kinds fail, loudly).
13
+ // the local composition root so agent jobs run in local containers (Docker/Podman/
14
+ // OrbStack/Colima/Apple `container`) and GitHub is reached via a PAT. Requires
15
+ // DATABASE_URL (point it at the local Postgres); set LOCAL_HARNESS_IMAGE to run
16
+ // repo-operating agent jobs (without it the board still serves and only container
17
+ // kinds fail, loudly).
18
+ //
19
+ // `environmentProvider` injects a NATIVE ephemeral-environment adapter (e.g. Kargo)
20
+ // in place of the generic HttpEnvironmentProvider — this is the supported seam for a
21
+ // local deployment to wire its own provider while keeping local mode's preflight
22
+ // (orphan reaping, PAT/auth warnings) and differentiators (local container transport,
23
+ // PAT-backed GitHub client). It threads straight through to `buildNodeContainer`'s
24
+ // `environmentProvider` option. `buildContainer` is intentionally NOT exposed: overriding
25
+ // it would discard local mode's differentiators.
13
26
  export async function startLocal(options = {}) {
14
27
  const env = options.env ?? process.env;
15
- // Best-effort: reap per-job containers a previous run orphaned (a crash or hard kill
16
- // can leave exited `cat-factory.managed=local-docker` containers behind, since their
17
- // `release()` never ran). Skipped when no image is configured (nothing to reap).
18
- if (env.LOCAL_HARNESS_IMAGE?.trim()) {
28
+ // The auth gate defaults OPEN in local mode and the listener binds to all interfaces
29
+ // (so on native Linux Docker the agent containers can reach the LLM proxy via the
30
+ // bridge gateway). That combination means anyone on your network can reach the API —
31
+ // surface it so it is a choice, not a surprise. Lock it down with AUTH_DEV_OPEN=false,
32
+ // or HOST=127.0.0.1 on Docker Desktop (where host.docker.internal still resolves).
33
+ const localized = applyLocalDefaults(env);
34
+ // Container-runtime preflight: log the selected runtime + its capabilities + the host
35
+ // alias the harness will use to reach this service, and probe that the CLI is present.
36
+ // A misconfigured runtime then fails loud at boot rather than on the first dispatch.
37
+ await preflightRuntime(localized);
38
+ // Best-effort: reap per-run containers a previous run orphaned (a crash or hard kill
39
+ // can leave exited managed containers behind, since their `release()` never ran).
40
+ // Skipped when no image is configured (nothing to reap).
41
+ if (localized.LOCAL_HARNESS_IMAGE?.trim()) {
19
42
  try {
20
- const reaped = await createLocalDockerTransportFromEnv(env).reapExited();
43
+ const reaped = await createLocalContainerTransportFromEnv(localized).reapExited();
21
44
  if (reaped > 0)
22
45
  logger.info({ reaped }, 'reaped orphaned local job containers');
23
46
  }
@@ -25,12 +48,6 @@ export async function startLocal(options = {}) {
25
48
  logger.warn({ err: err instanceof Error ? err.message : String(err) }, 'could not reap orphaned local job containers');
26
49
  }
27
50
  }
28
- // The auth gate defaults OPEN in local mode and the listener binds to all interfaces
29
- // (so on native Linux Docker the agent containers can reach the LLM proxy via the
30
- // bridge gateway). That combination means anyone on your network can reach the API —
31
- // surface it so it is a choice, not a surprise. Lock it down with AUTH_DEV_OPEN=false,
32
- // or HOST=127.0.0.1 on Docker Desktop (where host.docker.internal still resolves).
33
- const localized = applyLocalDefaults(env);
34
51
  // GitHub is reached via a PAT in local mode (there is no GitHub-App connect flow). Without
35
52
  // one the board still serves, but every repo-operating agent step — clone, push, open PR,
36
53
  // the CI gate, the real merge — fails. Surface it at boot with a click-through URL that
@@ -45,6 +62,39 @@ export async function startLocal(options = {}) {
45
62
  'on your network can reach the API. Set AUTH_DEV_OPEN=false, or HOST=127.0.0.1 on ' +
46
63
  'Docker Desktop, to restrict it.');
47
64
  }
48
- return start({ env, buildContainer: buildLocalContainer });
65
+ return start({
66
+ env,
67
+ host: options.host,
68
+ buildContainer: (o) => buildLocalContainer({ ...o, environmentProvider: options.environmentProvider }),
69
+ });
70
+ }
71
+ /**
72
+ * Log the resolved container runtime + capabilities + networking, and probe that its CLI
73
+ * is installed. Non-fatal: the board still boots if the binary is missing (only
74
+ * container-backed agent kinds then fail), mirroring how a missing image is handled.
75
+ */
76
+ async function preflightRuntime(localized) {
77
+ const adapter = createRuntimeAdapter(localized);
78
+ logger.info({
79
+ runtime: resolveRuntimeId(localized),
80
+ binary: adapter.binary,
81
+ localDind: adapter.capabilities.localDind,
82
+ hostAlias: adapter.hostAlias,
83
+ publicUrl: localized.PUBLIC_URL,
84
+ }, 'local mode: container runtime selected');
85
+ if (!adapter.capabilities.localDind) {
86
+ logger.info(`local mode: the '${resolveRuntimeId(localized)}' runtime cannot run the Tester's local ` +
87
+ `docker-compose infra (no Docker-in-Docker). Tasks must use the ephemeral test ` +
88
+ `environment (with an environment provider configured) or a 'No infra dependencies' ` +
89
+ `service; a local-infra Tester run is refused at start.`);
90
+ }
91
+ try {
92
+ await execFileAsync(adapter.binary, ['--version'], { timeout: 10_000 });
93
+ }
94
+ catch (err) {
95
+ logger.warn({ err: err instanceof Error ? err.message : String(err), binary: adapter.binary }, `local mode: container CLI '${adapter.binary}' is not runnable — repo-operating agent ` +
96
+ `steps will fail until it is installed and on PATH (or set LOCAL_DOCKER_BINARY / ` +
97
+ `LOCAL_CONTAINER_RUNTIME).`);
98
+ }
49
99
  }
50
100
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,iCAAiC,EAAE,MAAM,iCAAiC,CAAA;AAEnF,kFAAkF;AAClF,qFAAqF;AACrF,qFAAqF;AACrF,oFAAoF;AACpF,mFAAmF;AACnF,iDAAiD;AACjD,M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ACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,gBAAgB,CAAC,SAA4B;IAC1D,MAAM,OAAO,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAA;IAC/C,MAAM,CAAC,IAAI,CACT;QACE,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC;QACpC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,SAAS;QACzC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS,EAAE,SAAS,CAAC,UAAU;KAChC,EACD,wCAAwC,CACzC,CAAA;IACD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CACT,oBAAoB,gBAAgB,CAAC,SAAS,CAAC,0CAA0C;YACvF,gFAAgF;YAChF,qFAAqF;YACrF,wDAAwD,CAC3D,CAAA;IACH,CAAC;IACD,IAAI,CAAC;QACH,MAAM,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;IACzE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CACT,EAAE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,EACjF,8BAA8B,OAAO,CAAC,MAAM,2CAA2C;YACrF,kFAAkF;YAClF,2BAA2B,CAC9B,CAAA;IACH,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@cat-factory/local-server",
3
- "version": "0.6.0",
3
+ "version": "0.7.3",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/kibertoad/cat-factory.git",
7
+ "directory": "backend/runtimes/local"
8
+ },
4
9
  "description": "Local-mode runtime facade for the Agent Architecture Board: the @cat-factory/node-server stack with agent jobs run as local Docker/Podman containers and GitHub accessed via a personal access token — a developer can run the whole product on their own machine.",
5
10
  "files": [
6
11
  "dist"
@@ -20,18 +25,18 @@
20
25
  },
21
26
  "dependencies": {
22
27
  "drizzle-orm": "1.0.0-rc.3",
23
- "@cat-factory/agents": "0.6.0",
24
- "@cat-factory/contracts": "0.6.0",
25
- "@cat-factory/kernel": "0.6.0",
26
- "@cat-factory/orchestration": "0.6.0",
27
- "@cat-factory/node-server": "0.6.0",
28
- "@cat-factory/server": "0.6.0"
28
+ "@cat-factory/agents": "0.7.2",
29
+ "@cat-factory/contracts": "0.7.2",
30
+ "@cat-factory/node-server": "0.7.2",
31
+ "@cat-factory/orchestration": "0.7.2",
32
+ "@cat-factory/kernel": "0.7.2",
33
+ "@cat-factory/server": "0.7.2"
29
34
  },
30
35
  "devDependencies": {
31
36
  "@types/node": "^24.13.2",
32
37
  "typescript": "7.0.1-rc",
33
38
  "vitest": "^4.1.9",
34
- "@cat-factory/conformance": "0.6.0"
39
+ "@cat-factory/conformance": "0.7.2"
35
40
  },
36
41
  "scripts": {
37
42
  "build": "tsc -b tsconfig.build.json",
@@ -1,95 +0,0 @@
1
- import type { RunnerDispatchKind, RunnerDispatchOptions, RunnerJobRef, RunnerJobView, RunnerTransport } from '@cat-factory/kernel';
2
- /** Injectable docker/podman CLI runner — overridable in tests. */
3
- export type DockerExec = (args: string[]) => Promise<{
4
- stdout: string;
5
- stderr: string;
6
- }>;
7
- export interface LocalDockerRunnerTransportOptions {
8
- /** The executor-harness image ref (a GHCR pull or a locally built tag). */
9
- image: string;
10
- /** The container CLI binary. Default `docker` (Podman works via the same surface). */
11
- binary?: string;
12
- /**
13
- * Shared secret injected as `HARNESS_SHARED_SECRET` and sent as the
14
- * `x-harness-secret` header on every call. Defaults to a random per-process value.
15
- */
16
- sharedSecret?: string;
17
- /**
18
- * Add `--add-host=host.docker.internal:host-gateway` so the harness can reach the
19
- * backend LLM proxy at `host.docker.internal` (needed on Linux; harmless on
20
- * Docker Desktop). Default true.
21
- */
22
- addHostGateway?: boolean;
23
- /** Optional `--network` for the container. */
24
- network?: string;
25
- /** Extra `-e KEY=VALUE` env passed into the container (rarely needed). */
26
- env?: Record<string, string>;
27
- /** Injectable docker exec — defaults to running {@link binary} via execFile. */
28
- exec?: DockerExec;
29
- /** Injectable fetch — defaults to the global. */
30
- fetchImpl?: typeof fetch;
31
- /** How long to wait for the container's port + `/health` after start. Default 60s. */
32
- readyTimeoutMs?: number;
33
- /** Per-HTTP-call timeout. Default 30s. */
34
- requestTimeoutMs?: number;
35
- /**
36
- * Run the Tester (`test`) job container with `--privileged` so its in-container
37
- * Docker-in-Docker daemon can start and the Tester can `docker compose up` the
38
- * service's local infra. This is the local analogue of the Cloudflare harness's
39
- * rootless-dockerd path, but reliable: on a developer machine privileged DinD
40
- * "just works", keeping the service's dependencies on the job container's own
41
- * `localhost` (exactly what the Tester prompt assumes). Default true; set false to
42
- * fall back to the harness's best-effort rootless daemon (e.g. under Podman, whose
43
- * rootless containers can run nested Podman without `--privileged`). Only the
44
- * `test` kind gets it — every other kind runs unprivileged. See entrypoint.sh.
45
- */
46
- privilegedTestJobs?: boolean;
47
- }
48
- export declare class LocalDockerRunnerTransport implements RunnerTransport {
49
- private readonly image;
50
- private readonly binary;
51
- private readonly sharedSecret;
52
- private readonly addHostGateway;
53
- private readonly network?;
54
- private readonly extraEnv;
55
- private readonly exec;
56
- private readonly fetchImpl;
57
- private readonly readyTimeoutMs;
58
- private readonly requestTimeoutMs;
59
- private readonly privilegedTestJobs;
60
- /** runId → resolved container handle, to spare a `docker` lookup on the hot poll path. */
61
- private readonly cache;
62
- constructor(options: LocalDockerRunnerTransportOptions);
63
- dispatch(ref: RunnerJobRef, spec: Record<string, unknown>, kind?: RunnerDispatchKind, options?: RunnerDispatchOptions): Promise<void>;
64
- poll(ref: RunnerJobRef): Promise<RunnerJobView>;
65
- /**
66
- * Reclaim the per-RUN container now (`docker rm -f`) rather than leaving it idle —
67
- * this tears down the whole run's container (and with it any step still running in
68
- * it). Best-effort and idempotent: removing an already-gone container is a no-op.
69
- */
70
- release(ref: RunnerJobRef): Promise<void>;
71
- /**
72
- * Reap exited per-job containers this transport manages — orphans a crash or hard
73
- * kill left behind (release() never ran for them). Best-effort; returns the count
74
- * removed. Call once at boot, before any job is in flight.
75
- */
76
- reapExited(): Promise<number>;
77
- /** Force-remove every (running or exited) container labelled with this run id. */
78
- private removeContainersForRun;
79
- private url;
80
- /** The container handle for a run from the cache, else rediscovered by label. */
81
- private resolve;
82
- /** The (running-or-exited) container id labelled with this run id, if any. */
83
- private findContainer;
84
- /** Parse the published host port for the harness port, or undefined if unmapped. */
85
- private hostPort;
86
- private waitForPort;
87
- private waitForHealth;
88
- private isRunning;
89
- }
90
- /**
91
- * Build a {@link LocalDockerRunnerTransport} from the process environment. The image
92
- * ref (`LOCAL_HARNESS_IMAGE`) is required; everything else has sane local defaults.
93
- */
94
- export declare function createLocalDockerTransportFromEnv(env: NodeJS.ProcessEnv): LocalDockerRunnerTransport;
95
- //# sourceMappingURL=LocalDockerRunnerTransport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalDockerRunnerTransport.d.ts","sourceRoot":"","sources":["../src/LocalDockerRunnerTransport.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAkD5B,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAExF,MAAM,WAAW,iCAAiC;IAChD,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAA;IACb,sFAAsF;IACtF,MAAM,CAAC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MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,GAAE,kBAA0B,EAChC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA+Df;IAEK,IAAI,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAmCpD;IAED;;;;OAIG;IACG,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAM9C;IAED;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAgBlC;IAID,kFAAkF;YACpE,sBAAsB;IAiBpC,OAAO,CAAC,GAAG;IAIX,iFAAiF;YACnE,OAAO;IAYrB,8EAA8E;YAChE,aAAa;IAY3B,oFAAoF;YACtE,QAAQ;YAUR,WAAW;YAYX,aAAa;YAmBb,SAAS;CASxB;AAUD;;;GAGG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,0BAA0B,CAmB5B"}
@@ -1,342 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { randomBytes } from 'node:crypto';
3
- import { promisify } from 'node:util';
4
- import { resolveDockerResources } from '@cat-factory/contracts';
5
- const execFileAsync = promisify(execFile);
6
- // The local-mode runner backend: each RUN gets its OWN local Docker/Podman container
7
- // — the SAME executor-harness image the Cloudflare Worker runs per-run Containers
8
- // from — which hosts that run's whole sequence of step jobs. It is the local analogue
9
- // of `CloudflareContainerTransport` (a per-run Cloudflare Container) and of
10
- // `RunnerPoolTransport` (an org's self-hosted pool): the ContainerAgentExecutor drives
11
- // all three identically through the `RunnerTransport` port, addressed by a
12
- // {@link RunnerJobRef} — the run id (which container) plus the per-step job id.
13
- //
14
- // A container is started per RUN (`docker run -d`, harness `:8080` published to an
15
- // ephemeral host port), labelled with the run id so the run's later steps re-attach to
16
- // it instead of starting a duplicate, and the harness keys each step's job by the
17
- // per-step job id (so siblings never collide). The harness reaches this service's LLM proxy at
18
- // `host.docker.internal` — published via `--add-host` on Linux — and clones/pushes
19
- // to github.com directly with the per-job token in the request body. Nothing
20
- // long-lived is mounted: the per-job GitHub + proxy tokens travel in the POST body
21
- // and live only for the job, in the container's ephemeral filesystem.
22
- /** Maps a dispatch kind to the harness HTTP route that starts that job. */
23
- const KIND_ROUTE = {
24
- run: '/run',
25
- blueprint: '/blueprint',
26
- spec: '/spec',
27
- explore: '/explore',
28
- bootstrap: '/bootstrap',
29
- 'ci-fix': '/ci-fix',
30
- 'resolve-conflicts': '/resolve-conflicts',
31
- merge: '/merge',
32
- test: '/test',
33
- 'fix-tests': '/fix-tests',
34
- };
35
- // The failed-poll error the engine classifies as a container eviction (matched by
36
- // orchestration `isContainerEvictionError`, also used by the bootstrap flow). A
37
- // vanished/exited local container maps to it so the run stops and the stale-run
38
- // sweeper can re-drive it — mirroring the Worker transport's 404 mapping.
39
- const EVICTION_ERROR = 'Job not found (container evicted or crashed)';
40
- // Labels the per-RUN container by its run id (the container key). A run's steps share
41
- // one container, so this is the run id, not a per-step job id.
42
- const LABEL_RUN = 'cat-factory.runId';
43
- const LABEL_MANAGED = 'cat-factory.managed=local-docker';
44
- /** The port the harness listens on inside the container. */
45
- const HARNESS_PORT = 8080;
46
- const SECRET_HEADER = 'x-harness-secret';
47
- const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
48
- export class LocalDockerRunnerTransport {
49
- image;
50
- binary;
51
- sharedSecret;
52
- addHostGateway;
53
- network;
54
- extraEnv;
55
- exec;
56
- fetchImpl;
57
- readyTimeoutMs;
58
- requestTimeoutMs;
59
- privilegedTestJobs;
60
- /** runId → resolved container handle, to spare a `docker` lookup on the hot poll path. */
61
- cache = new Map();
62
- constructor(options) {
63
- this.image = options.image;
64
- this.binary = options.binary ?? 'docker';
65
- this.sharedSecret = options.sharedSecret ?? randomBytes(24).toString('hex');
66
- this.addHostGateway = options.addHostGateway ?? true;
67
- this.network = options.network;
68
- this.extraEnv = options.env ?? {};
69
- this.exec =
70
- options.exec ?? ((args) => execFileAsync(this.binary, args, { maxBuffer: 16 * 1024 * 1024 }));
71
- this.fetchImpl = options.fetchImpl ?? fetch;
72
- this.readyTimeoutMs = options.readyTimeoutMs ?? 60_000;
73
- this.requestTimeoutMs = options.requestTimeoutMs ?? 30_000;
74
- this.privilegedTestJobs = options.privilegedTestJobs ?? true;
75
- }
76
- async dispatch(ref, spec, kind = 'run', options) {
77
- // The container is per-RUN: a run's first step starts it, later steps re-attach to
78
- // it (resolved by the run-id label), and the harness keys each step's job by the
79
- // per-step `ref.jobId` carried in the spec body.
80
- const runId = ref.runId;
81
- let resolved = await this.resolve(runId);
82
- if (!resolved) {
83
- // A prior attempt may have left an exited/dead container under this run label
84
- // (resolve() returns undefined for one whose port is no longer published). Remove
85
- // any such container first so it can't shadow the fresh one in later label lookups
86
- // (findContainer returns the first match).
87
- await this.removeContainersForRun(runId);
88
- const args = [
89
- 'run',
90
- '-d',
91
- '--label',
92
- `${LABEL_RUN}=${runId}`,
93
- '--label',
94
- LABEL_MANAGED,
95
- '-p',
96
- `127.0.0.1:0:${HARNESS_PORT}`,
97
- '-e',
98
- `HARNESS_SHARED_SECRET=${this.sharedSecret}`,
99
- ];
100
- // Size the per-job container on the host daemon from the service's abstract
101
- // instance size — the local backend never touches a cloud, it just provisions a
102
- // bigger/smaller Docker container (`--memory`/`--cpus`).
103
- if (options?.instanceSize) {
104
- const { memory, cpus } = resolveDockerResources(options.instanceSize);
105
- args.push('--memory', memory, '--cpus', cpus);
106
- }
107
- // The Tester stands its infra up with `docker compose` INSIDE the job container
108
- // (Docker-in-Docker), so the dependencies sit on the container's own localhost.
109
- // Run that one kind privileged so the in-container daemon can start. No other
110
- // kind needs Docker, so none other gets elevated.
111
- if (kind === 'test' && this.privilegedTestJobs)
112
- args.push('--privileged');
113
- if (this.addHostGateway)
114
- args.push('--add-host=host.docker.internal:host-gateway');
115
- if (this.network)
116
- args.push('--network', this.network);
117
- for (const [k, v] of Object.entries(this.extraEnv))
118
- args.push('-e', `${k}=${v}`);
119
- args.push(this.image);
120
- const { stdout } = await this.exec(args);
121
- const containerId = stdout.trim().split(/\s+/).pop();
122
- if (!containerId)
123
- throw new Error('docker run returned no container id');
124
- const port = await this.waitForPort(containerId);
125
- resolved = { containerId, port };
126
- this.cache.set(runId, resolved);
127
- await this.waitForHealth(resolved.port);
128
- }
129
- // POST the job to the kind's route. Idempotent: re-attaching to an already-running
130
- // container re-POSTs, which the harness's per-id registry treats as a re-attach.
131
- const res = await this.fetchImpl(this.url(resolved.port, KIND_ROUTE[kind]), {
132
- method: 'POST',
133
- headers: { 'content-type': 'application/json', [SECRET_HEADER]: this.sharedSecret },
134
- body: JSON.stringify(spec),
135
- signal: AbortSignal.timeout(this.requestTimeoutMs),
136
- });
137
- if (!res.ok) {
138
- throw new Error(`Local container dispatch failed (HTTP ${res.status}): ${await safeText(res)}`);
139
- }
140
- }
141
- async poll(ref) {
142
- const resolved = await this.resolve(ref.runId);
143
- // No container for this run at all → it was evicted/reaped (or never started).
144
- if (!resolved)
145
- return { state: 'failed', error: EVICTION_ERROR };
146
- let res;
147
- try {
148
- // Address the per-RUN container, but read the per-step job by its own id.
149
- res = await this.fetchImpl(this.url(resolved.port, `/jobs/${encodeURIComponent(ref.jobId)}`), {
150
- method: 'GET',
151
- headers: { [SECRET_HEADER]: this.sharedSecret },
152
- signal: AbortSignal.timeout(this.requestTimeoutMs),
153
- });
154
- }
155
- catch (err) {
156
- // Connection refused / DNS gone: the container most likely exited. Confirm via
157
- // the daemon — if it is no longer running, report an eviction so the run stops;
158
- // otherwise surface the transient error so the caller can retry.
159
- if (!(await this.isRunning(resolved.containerId))) {
160
- this.cache.delete(ref.runId);
161
- return { state: 'failed', error: EVICTION_ERROR };
162
- }
163
- throw err;
164
- }
165
- // The container is up but the harness no longer knows this job id (it was reaped
166
- // after completion, or the container was recreated): treat as an eviction.
167
- if (res.status === 404)
168
- return { state: 'failed', error: EVICTION_ERROR };
169
- if (!res.ok) {
170
- throw new Error(`Local container job poll failed (HTTP ${res.status}): ${await safeText(res)}`);
171
- }
172
- return (await res.json());
173
- }
174
- /**
175
- * Reclaim the per-RUN container now (`docker rm -f`) rather than leaving it idle —
176
- * this tears down the whole run's container (and with it any step still running in
177
- * it). Best-effort and idempotent: removing an already-gone container is a no-op.
178
- */
179
- async release(ref) {
180
- const containerId = this.cache.get(ref.runId)?.containerId ?? (await this.findContainer(ref.runId));
181
- this.cache.delete(ref.runId);
182
- if (!containerId)
183
- return;
184
- await this.exec(['rm', '-f', containerId]).catch(() => undefined);
185
- }
186
- /**
187
- * Reap exited per-job containers this transport manages — orphans a crash or hard
188
- * kill left behind (release() never ran for them). Best-effort; returns the count
189
- * removed. Call once at boot, before any job is in flight.
190
- */
191
- async reapExited() {
192
- const { stdout } = await this.exec([
193
- 'ps',
194
- '-aq',
195
- '--filter',
196
- `label=${LABEL_MANAGED}`,
197
- '--filter',
198
- 'status=exited',
199
- ]);
200
- const ids = stdout
201
- .trim()
202
- .split('\n')
203
- .map((s) => s.trim())
204
- .filter(Boolean);
205
- if (ids.length)
206
- await this.exec(['rm', '-f', ...ids]).catch(() => undefined);
207
- return ids.length;
208
- }
209
- // --- internals ----------------------------------------------------------
210
- /** Force-remove every (running or exited) container labelled with this run id. */
211
- async removeContainersForRun(runId) {
212
- const { stdout } = await this.exec([
213
- 'ps',
214
- '-aq',
215
- '--filter',
216
- `label=${LABEL_RUN}=${runId}`,
217
- '--filter',
218
- `label=${LABEL_MANAGED}`,
219
- ]);
220
- const ids = stdout
221
- .trim()
222
- .split('\n')
223
- .map((s) => s.trim())
224
- .filter(Boolean);
225
- if (ids.length)
226
- await this.exec(['rm', '-f', ...ids]).catch(() => undefined);
227
- }
228
- url(port, path) {
229
- return `http://127.0.0.1:${port}${path}`;
230
- }
231
- /** The container handle for a run from the cache, else rediscovered by label. */
232
- async resolve(runId) {
233
- const cached = this.cache.get(runId);
234
- if (cached)
235
- return cached;
236
- const containerId = await this.findContainer(runId);
237
- if (!containerId)
238
- return undefined;
239
- const port = await this.hostPort(containerId);
240
- if (port === undefined)
241
- return undefined;
242
- const resolved = { containerId, port };
243
- this.cache.set(runId, resolved);
244
- return resolved;
245
- }
246
- /** The (running-or-exited) container id labelled with this run id, if any. */
247
- async findContainer(runId) {
248
- const { stdout } = await this.exec([
249
- 'ps',
250
- '-aq',
251
- '--filter',
252
- `label=${LABEL_RUN}=${runId}`,
253
- '--filter',
254
- `label=${LABEL_MANAGED}`,
255
- ]);
256
- return stdout.trim().split('\n')[0]?.trim() || undefined;
257
- }
258
- /** Parse the published host port for the harness port, or undefined if unmapped. */
259
- async hostPort(containerId) {
260
- const { stdout } = await this.exec(['port', containerId, `${HARNESS_PORT}/tcp`]);
261
- // e.g. "127.0.0.1:49153" (possibly several lines for IPv4/IPv6); take the last
262
- // numeric segment of the first line.
263
- const line = stdout.trim().split('\n')[0]?.trim();
264
- if (!line)
265
- return undefined;
266
- const port = Number(line.slice(line.lastIndexOf(':') + 1));
267
- return Number.isFinite(port) && port > 0 ? port : undefined;
268
- }
269
- async waitForPort(containerId) {
270
- const deadline = Date.now() + this.readyTimeoutMs;
271
- for (;;) {
272
- const port = await this.hostPort(containerId).catch(() => undefined);
273
- if (port !== undefined)
274
- return port;
275
- if (Date.now() >= deadline) {
276
- throw new Error(`Timed out waiting for container ${containerId} to publish its port`);
277
- }
278
- await delay(250);
279
- }
280
- }
281
- async waitForHealth(port) {
282
- const deadline = Date.now() + this.readyTimeoutMs;
283
- for (;;) {
284
- try {
285
- const res = await this.fetchImpl(this.url(port, '/health'), {
286
- method: 'GET',
287
- signal: AbortSignal.timeout(Math.min(this.requestTimeoutMs, 5_000)),
288
- });
289
- if (res.ok)
290
- return;
291
- }
292
- catch {
293
- // not up yet
294
- }
295
- if (Date.now() >= deadline) {
296
- throw new Error(`Timed out waiting for the harness on :${port} to become healthy`);
297
- }
298
- await delay(300);
299
- }
300
- }
301
- async isRunning(containerId) {
302
- try {
303
- const { stdout } = await this.exec(['inspect', '-f', '{{.State.Running}}', containerId]);
304
- return stdout.trim() === 'true';
305
- }
306
- catch {
307
- // No such container → not running.
308
- return false;
309
- }
310
- }
311
- }
312
- async function safeText(res) {
313
- try {
314
- return (await res.text()).slice(0, 500);
315
- }
316
- catch {
317
- return '(no body)';
318
- }
319
- }
320
- /**
321
- * Build a {@link LocalDockerRunnerTransport} from the process environment. The image
322
- * ref (`LOCAL_HARNESS_IMAGE`) is required; everything else has sane local defaults.
323
- */
324
- export function createLocalDockerTransportFromEnv(env) {
325
- const image = env.LOCAL_HARNESS_IMAGE?.trim();
326
- if (!image) {
327
- throw new Error('LOCAL_HARNESS_IMAGE is required for local mode: set it to the executor-harness image ref ' +
328
- '(a GHCR pull or a tag built from backend/internal/executor-harness/Dockerfile).');
329
- }
330
- return new LocalDockerRunnerTransport({
331
- image,
332
- binary: env.LOCAL_DOCKER_BINARY?.trim() || 'docker',
333
- sharedSecret: env.HARNESS_SHARED_SECRET?.trim() || undefined,
334
- network: env.LOCAL_DOCKER_NETWORK?.trim() || undefined,
335
- addHostGateway: env.LOCAL_DOCKER_ADD_HOST_GATEWAY?.trim() !== 'false',
336
- // Default on: the Tester stands its docker-compose infra up via Docker-in-Docker,
337
- // which needs a privileged job container. Set to `false` for runtimes that run
338
- // nested containers without it (e.g. rootless Podman).
339
- privilegedTestJobs: env.LOCAL_DOCKER_PRIVILEGED_TEST_JOBS?.trim() !== 'false',
340
- });
341
- }
342
- //# sourceMappingURL=LocalDockerRunnerTransport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalDockerRunnerTransport.js","sourceRoot":"","sources":["../src/LocalDockerRunnerTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAQrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,MA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