overvues 0.0.1 → 0.4.10

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 (78) hide show
  1. package/README.md +58 -2
  2. package/dist/ansi.js +24 -0
  3. package/dist/attach-client.js +586 -0
  4. package/dist/auth-connect-browser.js +112 -0
  5. package/dist/auth-connect.js +306 -0
  6. package/dist/browser-bootstrap.js +190 -0
  7. package/dist/browser-loopback.js +289 -0
  8. package/dist/build-identity.js +6 -0
  9. package/dist/codex-reviewer-apparmor.json +4 -0
  10. package/dist/codex-reviewer-seccomp.json +1238 -0
  11. package/dist/codex-runtime-protocol.js +1 -0
  12. package/dist/codex-subscription.js +53 -0
  13. package/dist/config.js +297 -0
  14. package/dist/connect-comparison-code.js +26 -0
  15. package/dist/development-runner.js +109 -0
  16. package/dist/dns-doctor.js +390 -0
  17. package/dist/docker-names.js +47 -0
  18. package/dist/doctor.js +114 -0
  19. package/dist/gadget-job.js +804 -0
  20. package/dist/health-check.js +112 -0
  21. package/dist/help.js +71 -0
  22. package/dist/host-auth.js +22 -0
  23. package/dist/host-diagnostics.js +20 -0
  24. package/dist/host-runtime-identity.js +39 -0
  25. package/dist/host-runtime-metadata.js +56 -0
  26. package/dist/host-service.js +377 -0
  27. package/dist/host-stack.js +484 -0
  28. package/dist/host-supervisor.js +237 -0
  29. package/dist/host-update.js +387 -0
  30. package/dist/hub-address.js +100 -0
  31. package/dist/hub-client.js +459 -0
  32. package/dist/hub-kind.js +88 -0
  33. package/dist/identity.js +73 -0
  34. package/dist/index.js +185 -0
  35. package/dist/init.js +295 -0
  36. package/dist/isolated-run-cache.js +116 -0
  37. package/dist/local-stack.js +685 -0
  38. package/dist/machine-capacity.js +128 -0
  39. package/dist/managed-runner-image.js +13 -0
  40. package/dist/os-acted-record.js +49 -0
  41. package/dist/os-adapter.js +8190 -0
  42. package/dist/os-command.js +292 -0
  43. package/dist/os-handoff.js +274 -0
  44. package/dist/os-keychain.js +247 -0
  45. package/dist/os-machine.js +818 -0
  46. package/dist/os-owner.js +61 -0
  47. package/dist/os-private-file.js +98 -0
  48. package/dist/os-protocol.js +468 -0
  49. package/dist/os-session-store.js +133 -0
  50. package/dist/os-status.js +102 -0
  51. package/dist/picker.js +863 -0
  52. package/dist/portable-workspace-capability.js +60 -0
  53. package/dist/project-environment-capability.js +62 -0
  54. package/dist/project-environment.js +28 -0
  55. package/dist/project-preparation.js +134 -0
  56. package/dist/readiness.js +28 -0
  57. package/dist/redaction.js +27 -0
  58. package/dist/reviewer-isolation-capability.js +61 -0
  59. package/dist/runner-api-auth.js +80 -0
  60. package/dist/runner-command-fence.js +536 -0
  61. package/dist/runner-inspection.js +57 -0
  62. package/dist/runner-inventory.js +587 -0
  63. package/dist/runner-server.js +2520 -0
  64. package/dist/runner-session.js +470 -0
  65. package/dist/runner-slug-folder.js +39 -0
  66. package/dist/runner-slug.js +40 -0
  67. package/dist/setup.js +139 -0
  68. package/dist/shutdown.js +102 -0
  69. package/dist/splash.js +65 -0
  70. package/dist/staged-workspaces.js +441 -0
  71. package/dist/staging-disk.js +97 -0
  72. package/dist/terminal-lane.js +339 -0
  73. package/dist/terminal-recovery.js +502 -0
  74. package/licenses/capnweb.txt +23 -0
  75. package/licenses/moby-profiles.txt +212 -0
  76. package/licenses/ws.txt +22 -0
  77. package/package.json +28 -7
  78. package/cli.js +0 -2
@@ -0,0 +1,128 @@
1
+ import { spawn } from "node:child_process";
2
+ import { freemem, loadavg, totalmem } from "node:os";
3
+ import { dockerLabel } from "./docker-names.js";
4
+ /**
5
+ * A guess at one environment's working memory; to check against `docker stats`.
6
+ * An agent that is editing or waiting uses well under this; one running a
7
+ * heavy test suite can use more, so the limit counts environments and does
8
+ * not reserve memory.
9
+ */
10
+ export const ENVIRONMENT_MEMORY_BYTES = 1024 ** 3;
11
+ const CAPACITY_DOCKER_TIMEOUT_MS = 10_000;
12
+ export const DOCKER_RESOURCES_ARGS = ["info", "--format", "{{.NCPU}} {{.MemTotal}}"];
13
+ /** Parses `docker info --format '{{.NCPU}} {{.MemTotal}}'`. */
14
+ export function parseDockerResources(text) {
15
+ const match = /^\s*(\d+)\s+(\d+)\s*$/.exec(text);
16
+ if (!match)
17
+ return null;
18
+ const cpus = Number(match[1]);
19
+ const memoryBytes = Number(match[2]);
20
+ if (!Number.isSafeInteger(cpus) || cpus < 1 || !Number.isSafeInteger(memoryBytes) || memoryBytes < 1)
21
+ return null;
22
+ return { cpus, memoryBytes };
23
+ }
24
+ export async function readDockerResources(runDocker) {
25
+ try {
26
+ return parseDockerResources(await runDocker(DOCKER_RESOURCES_ARGS));
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ /**
33
+ * The label `buildContainerRunArgs` puts on one-shot isolated runs (plan
34
+ * writer, planner, reviewer, publish, land), which never count toward the
35
+ * environment limit. Docker filters cannot exclude a label, so the count
36
+ * prints it and leaves those containers out.
37
+ */
38
+ export const ISOLATED_RUN_LABEL_KEY = "isolated";
39
+ function defaultLabels() {
40
+ return { slug: dockerLabel("slug"), isolated: dockerLabel(ISOLATED_RUN_LABEL_KEY) };
41
+ }
42
+ export function runningEnvironmentsArgs(labels = defaultLabels()) {
43
+ return [
44
+ "ps", "--filter", `label=${labels.slug}`, "--filter", "status=running",
45
+ "--format", `{{.ID}} {{.Label "${labels.isolated}"}}`,
46
+ ];
47
+ }
48
+ /** Counts running environment containers, leaving isolated runs out; null when Docker does not answer. */
49
+ export async function countRunningEnvironments(runDocker, labels = defaultLabels()) {
50
+ try {
51
+ const output = await runDocker(runningEnvironmentsArgs(labels));
52
+ return output
53
+ .split(/\r?\n/)
54
+ .map((line) => line.trim().split(/\s+/))
55
+ .filter(([id, isolated]) => id && isolated !== "true")
56
+ .length;
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ }
62
+ /** True when a report says the machine has no free environment slot. */
63
+ export function isMachineFull(runningEnvironments, limit) {
64
+ return runningEnvironments !== null && limit !== null && runningEnvironments >= limit;
65
+ }
66
+ /**
67
+ * Docker memory divided by `ENVIRONMENT_MEMORY_BYTES`, rounded down, at least
68
+ * 1. The CLI's `MAX_ENVIRONMENTS` setting (`TILLER_MAX_ENVIRONMENTS` or
69
+ * `OVERVUES_MAX_ENVIRONMENTS`, `envVar` in identity.ts), a whole number of 1
70
+ * or more, replaces it.
71
+ */
72
+ export function environmentLimit(memoryBytes, override) {
73
+ const configured = override?.trim();
74
+ if (configured && /^\d+$/.test(configured)) {
75
+ const value = Number(configured);
76
+ if (Number.isSafeInteger(value) && value >= 1)
77
+ return value;
78
+ }
79
+ return Math.max(1, Math.floor(memoryBytes / ENVIRONMENT_MEMORY_BYTES));
80
+ }
81
+ export function readHostResources(os = { totalmem, freemem, loadavg }) {
82
+ const load1 = os.loadavg()[0];
83
+ return {
84
+ hostMemoryBytes: os.totalmem(),
85
+ hostMemoryAvailableBytes: os.freemem(),
86
+ load1: Number.isFinite(load1) && load1 >= 0 ? Math.round(load1 * 100) / 100 : 0,
87
+ };
88
+ }
89
+ export function buildMachineCapacity(input) {
90
+ if (!input.docker || input.runningEnvironments === null)
91
+ return null;
92
+ return {
93
+ cpus: input.docker.cpus,
94
+ memoryBytes: input.docker.memoryBytes,
95
+ runningEnvironments: input.runningEnvironments,
96
+ environmentLimit: environmentLimit(input.docker.memoryBytes, input.maxEnvironments),
97
+ ...(input.jobs ? { runningJobs: input.jobs.running, jobLimit: input.jobs.limit } : {}),
98
+ ...input.host,
99
+ measuredAt: input.now.toISOString(),
100
+ };
101
+ }
102
+ /** Runs one `docker` command for a capacity read, killed after `timeoutMs`. */
103
+ export function runCapacityDocker(args, timeoutMs = CAPACITY_DOCKER_TIMEOUT_MS) {
104
+ return new Promise((resolvePromise, reject) => {
105
+ const child = spawn("docker", args, { stdio: ["ignore", "pipe", "ignore"] });
106
+ let stdout = "";
107
+ let settled = false;
108
+ const finish = (error) => {
109
+ if (settled)
110
+ return;
111
+ settled = true;
112
+ clearTimeout(timer);
113
+ if (error)
114
+ reject(error);
115
+ else
116
+ resolvePromise(stdout.trim());
117
+ };
118
+ const timer = setTimeout(() => {
119
+ child.kill("SIGKILL");
120
+ finish(new Error(`docker ${args[0]} timed out`));
121
+ }, timeoutMs);
122
+ child.stdout.on("data", (chunk) => {
123
+ stdout += chunk.toString();
124
+ });
125
+ child.on("error", (error) => finish(error));
126
+ child.on("close", (code) => finish(code === 0 ? null : new Error(`docker ${args[0]} failed`)));
127
+ });
128
+ }
@@ -0,0 +1,13 @@
1
+ export const MANAGED_LOCAL_RUNNER_IMAGE_PREFIX = "docker.io/jamieatlason/tiller-sandbox";
2
+ const MANAGED_LOCAL_RUNNER_IMAGE_RE = /^(?:docker\.io\/)?jamieatlason\/tiller-sandbox(?::[^\s/]+|@sha256:[0-9a-f]{64})$/;
3
+ const PINNED_MANAGED_LOCAL_RUNNER_IMAGE_RE = /^docker\.io\/jamieatlason\/tiller-sandbox@(sha256:[0-9a-f]{64})$/;
4
+ const LEGACY_PINNED_MANAGED_LOCAL_RUNNER_IMAGE_RE = /^docker\.io\/jamieatlason\/tiller-sandbox:([0-9a-f]{40})$/;
5
+ export function isManagedLocalRunnerImageRef(image) {
6
+ return MANAGED_LOCAL_RUNNER_IMAGE_RE.test(image.trim());
7
+ }
8
+ export function parseManagedLocalRunnerImageSourceId(image) {
9
+ const normalized = image.trim();
10
+ return normalized.match(PINNED_MANAGED_LOCAL_RUNNER_IMAGE_RE)?.[1]
11
+ ?? normalized.match(LEGACY_PINNED_MANAGED_LOCAL_RUNNER_IMAGE_RE)?.[1]
12
+ ?? null;
13
+ }
@@ -0,0 +1,49 @@
1
+ // The record of what this machine has done on the OS: one entry per Ship id and per approval
2
+ // id. `tiller` writes "started" to disk before it sends anything to the OS and the outcome
3
+ // after, and never acts on an id twice. A repeat is answered from here.
4
+ //
5
+ // The file is `<config folder>/os/acted.json`, mode 0600 in a 0700 folder. If it is there and
6
+ // cannot be trusted or read, nothing that changes the OS is done until a person looks.
7
+ import { join } from "node:path";
8
+ import { osFolder, readPrivateFile, writePrivateFile } from "./os-private-file.js";
9
+ import { CLI } from "./identity.js";
10
+ /** Entries kept. The oldest are dropped past this; an approval is long out of date by then. */
11
+ const MAX_ENTRIES = 2000;
12
+ const key = (kind, id) => `${kind}:${id}`;
13
+ export function fileActedRecord(configDir) {
14
+ const path = join(osFolder(configDir), "acted.json");
15
+ const read = () => {
16
+ const text = readPrivateFile(path);
17
+ if (text === null)
18
+ return {};
19
+ let parsed;
20
+ try {
21
+ parsed = JSON.parse(text);
22
+ }
23
+ catch {
24
+ parsed = null;
25
+ }
26
+ const entries = parsed?.entries;
27
+ if (parsed?.version !== 1 || !entries || typeof entries !== "object" || Array.isArray(entries)) {
28
+ throw new Error(`${path} is not a record this version of ${CLI.command} wrote`);
29
+ }
30
+ return entries;
31
+ };
32
+ return {
33
+ get(kind, id) {
34
+ const entries = read();
35
+ return Object.hasOwn(entries, key(kind, id)) ? entries[key(kind, id)] : null;
36
+ },
37
+ put(entry) {
38
+ // Read again each time: `tiller os` commands and the daemon are separate processes.
39
+ const entries = read();
40
+ entries[key(entry.kind, entry.id)] = entry;
41
+ const kept = Object.entries(entries);
42
+ if (kept.length > MAX_ENTRIES) {
43
+ kept.sort(([, a], [, b]) => (a.startedAt < b.startedAt ? -1 : a.startedAt > b.startedAt ? 1 : 0));
44
+ kept.splice(0, kept.length - MAX_ENTRIES);
45
+ }
46
+ writePrivateFile(path, `${JSON.stringify({ version: 1, entries: Object.fromEntries(kept) })}\n`);
47
+ },
48
+ };
49
+ }