@cat-factory/local-server 0.7.2 → 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 (57) hide show
  1. package/dist/LocalContainerRunnerTransport.d.ts +83 -0
  2. package/dist/LocalContainerRunnerTransport.d.ts.map +1 -0
  3. package/dist/LocalContainerRunnerTransport.js +247 -0
  4. package/dist/LocalContainerRunnerTransport.js.map +1 -0
  5. package/dist/config.d.ts +9 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +47 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/container.d.ts +4 -0
  10. package/dist/container.d.ts.map +1 -0
  11. package/dist/container.js +94 -0
  12. package/dist/container.js.map +1 -0
  13. package/dist/github.d.ts +36 -0
  14. package/dist/github.d.ts.map +1 -0
  15. package/dist/github.js +174 -0
  16. package/dist/github.js.map +1 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +23 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/installations.d.ts +31 -0
  22. package/dist/installations.d.ts.map +1 -0
  23. package/dist/installations.js +76 -0
  24. package/dist/installations.js.map +1 -0
  25. package/dist/link-repo.d.ts +2 -0
  26. package/dist/link-repo.d.ts.map +1 -0
  27. package/dist/link-repo.js +21 -0
  28. package/dist/link-repo.js.map +1 -0
  29. package/dist/linkRepo.d.ts +31 -0
  30. package/dist/linkRepo.d.ts.map +1 -0
  31. package/dist/linkRepo.js +113 -0
  32. package/dist/linkRepo.js.map +1 -0
  33. package/dist/main.d.ts +2 -0
  34. package/dist/main.d.ts.map +1 -0
  35. package/dist/main.js +10 -0
  36. package/dist/main.js.map +1 -0
  37. package/dist/runtimes/appleContainerRuntime.d.ts +21 -0
  38. package/dist/runtimes/appleContainerRuntime.d.ts.map +1 -0
  39. package/dist/runtimes/appleContainerRuntime.js +191 -0
  40. package/dist/runtimes/appleContainerRuntime.js.map +1 -0
  41. package/dist/runtimes/containerRuntime.d.ts +96 -0
  42. package/dist/runtimes/containerRuntime.d.ts.map +1 -0
  43. package/dist/runtimes/containerRuntime.js +99 -0
  44. package/dist/runtimes/containerRuntime.js.map +1 -0
  45. package/dist/runtimes/dockerRuntime.d.ts +27 -0
  46. package/dist/runtimes/dockerRuntime.d.ts.map +1 -0
  47. package/dist/runtimes/dockerRuntime.js +124 -0
  48. package/dist/runtimes/dockerRuntime.js.map +1 -0
  49. package/dist/runtimes/index.d.ts +13 -0
  50. package/dist/runtimes/index.d.ts.map +1 -0
  51. package/dist/runtimes/index.js +33 -0
  52. package/dist/runtimes/index.js.map +1 -0
  53. package/dist/server.d.ts +8 -0
  54. package/dist/server.d.ts.map +1 -0
  55. package/dist/server.js +100 -0
  56. package/dist/server.js.map +1 -0
  57. package/package.json +2 -2
package/dist/server.js ADDED
@@ -0,0 +1,100 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { start } from '@cat-factory/node-server';
4
+ import { logger } from '@cat-factory/server';
5
+ import { applyLocalDefaults } from './config.js';
6
+ import { buildLocalContainer } from './container.js';
7
+ import { githubPatCreationUrl } from './github.js';
8
+ import { createLocalContainerTransportFromEnv } from './LocalContainerRunnerTransport.js';
9
+ import { createRuntimeAdapter, resolveRuntimeId } from './runtimes/index.js';
10
+ const execFileAsync = promisify(execFile);
11
+ // Boot the local-mode service. It reuses the Node facade's `start()` — Postgres +
12
+ // pg-boss + the execution worker + sweepers, served over @hono/node-server — passing
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.
26
+ export async function startLocal(options = {}) {
27
+ const env = options.env ?? process.env;
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()) {
42
+ try {
43
+ const reaped = await createLocalContainerTransportFromEnv(localized).reapExited();
44
+ if (reaped > 0)
45
+ logger.info({ reaped }, 'reaped orphaned local job containers');
46
+ }
47
+ catch (err) {
48
+ logger.warn({ err: err instanceof Error ? err.message : String(err) }, 'could not reap orphaned local job containers');
49
+ }
50
+ }
51
+ // GitHub is reached via a PAT in local mode (there is no GitHub-App connect flow). Without
52
+ // one the board still serves, but every repo-operating agent step — clone, push, open PR,
53
+ // the CI gate, the real merge — fails. Surface it at boot with a click-through URL that
54
+ // pre-selects the scopes, so it is a one-step fix rather than a runtime surprise.
55
+ if (!localized.GITHUB_PAT?.trim()) {
56
+ logger.warn(`local mode: GITHUB_PAT is not set — agent steps that clone, push, open PRs, gate on ` +
57
+ `CI or merge will fail. Create a token (scopes pre-selected) at ${githubPatCreationUrl()} ` +
58
+ `then set GITHUB_PAT and restart.`);
59
+ }
60
+ if (localized.AUTH_DEV_OPEN !== 'false' && !env.HOST?.trim()) {
61
+ logger.warn('local mode: the auth gate is OPEN and the server binds to all interfaces — anyone ' +
62
+ 'on your network can reach the API. Set AUTH_DEV_OPEN=false, or HOST=127.0.0.1 on ' +
63
+ 'Docker Desktop, to restrict it.');
64
+ }
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
+ }
99
+ }
100
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @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,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,6 @@
1
1
  {
2
2
  "name": "@cat-factory/local-server",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/kibertoad/cat-factory.git",
@@ -27,9 +27,9 @@
27
27
  "drizzle-orm": "1.0.0-rc.3",
28
28
  "@cat-factory/agents": "0.7.2",
29
29
  "@cat-factory/contracts": "0.7.2",
30
- "@cat-factory/kernel": "0.7.2",
31
30
  "@cat-factory/node-server": "0.7.2",
32
31
  "@cat-factory/orchestration": "0.7.2",
32
+ "@cat-factory/kernel": "0.7.2",
33
33
  "@cat-factory/server": "0.7.2"
34
34
  },
35
35
  "devDependencies": {