@ulm0/gonogo 0.0.0-stage → 0.1.1
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.
- package/LICENSE +21 -0
- package/README.md +30 -2
- package/bin/gonogo.js +18 -0
- package/dist/client/THIRD-PARTY-NOTICES.md +409 -0
- package/dist/client/apple-touch-icon.png +0 -0
- package/dist/client/assets/doto-latin-900-normal-D1bF_x6I.woff +0 -0
- package/dist/client/assets/geist-latin-400-normal-B40WzpMT.woff2 +0 -0
- package/dist/client/assets/geist-latin-400-normal-akEymXtG.woff +0 -0
- package/dist/client/assets/geist-latin-500-normal-BDXIbFrL.woff +0 -0
- package/dist/client/assets/geist-latin-500-normal-CTWBw9NS.woff2 +0 -0
- package/dist/client/assets/geist-latin-600-normal-CSETrqM2.woff2 +0 -0
- package/dist/client/assets/geist-latin-600-normal-DsPlZH-9.woff +0 -0
- package/dist/client/assets/geist-mono-latin-400-normal-B2yvC1Cq.woff +0 -0
- package/dist/client/assets/geist-mono-latin-400-normal-DTRLJnHl.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-500-normal-D-GG86Jb.woff +0 -0
- package/dist/client/assets/geist-mono-latin-500-normal-YINYabwD.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-600-normal-V-KvD_pi.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-600-normal-bZn07FKM.woff +0 -0
- package/dist/client/assets/index-B6MsSoeo.css +1 -0
- package/dist/client/assets/index-DRtiRh1Y.js +31 -0
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.svg +1 -0
- package/dist/client/index.html +19 -0
- package/dist/server/cleanroom.js +214 -0
- package/dist/server/cli.js +630 -0
- package/dist/server/command.js +44 -0
- package/dist/server/constants.js +427 -0
- package/dist/server/docking.js +541 -0
- package/dist/server/downlink.js +191 -0
- package/dist/server/home.js +497 -0
- package/dist/server/hooks.js +166 -0
- package/dist/server/hub.js +2484 -0
- package/dist/server/launcher.js +542 -0
- package/dist/server/livery.js +210 -0
- package/dist/server/logsearch.js +112 -0
- package/dist/server/mcp.js +196 -0
- package/dist/server/migrate.js +119 -0
- package/dist/server/missionlog.js +209 -0
- package/dist/server/payload.js +168 -0
- package/dist/server/propellant.js +314 -0
- package/dist/server/providers.js +137 -0
- package/dist/server/relay.js +300 -0
- package/dist/server/relaykinds.js +182 -0
- package/dist/server/schedules.js +277 -0
- package/dist/server/tasks.js +272 -0
- package/dist/server/terminal.js +635 -0
- package/dist/server/uplinks.js +356 -0
- package/dist/server/web.js +1466 -0
- package/dist/shared/cron.js +149 -0
- package/dist/shared/fuel.js +18 -0
- package/dist/shared/livery.js +348 -0
- package/dist/shared/positions.js +132 -0
- package/dist/shared/protocol.js +212 -0
- package/package.json +84 -3
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="gonogo"><title>gonogo</title><style>@media (prefers-color-scheme: dark){.gok{fill:#4b4e53}.goke{fill:#323438}}</style><rect x="2" y="20" width="28" height="28" rx="7" fill="#141517" class="goke"/><rect x="4" y="22" width="24" height="24" rx="5" fill="#26272b" class="gok"/><circle cx="16" cy="34" r="6" fill="#7cc493"/><rect x="34" y="16" width="28" height="32" rx="7" fill="#b1aea6"/><rect x="36" y="18" width="24" height="24" rx="5" fill="#faf9f6"/><circle cx="48" cy="30" r="6" fill="#c2414b"/></svg>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<!-- Livery sets the next two with the look it shows (src/client/look.ts) -->
|
|
7
|
+
<meta name="color-scheme" content="light" />
|
|
8
|
+
<meta name="theme-color" content="#e4e2dc" />
|
|
9
|
+
<link rel="icon" href="./favicon.ico" sizes="32x32" />
|
|
10
|
+
<link rel="icon" href="./favicon.svg" type="image/svg+xml" />
|
|
11
|
+
<link rel="apple-touch-icon" href="./apple-touch-icon.png" />
|
|
12
|
+
<title>gonogo</title>
|
|
13
|
+
<script type="module" crossorigin src="./assets/index-DRtiRh1Y.js"></script>
|
|
14
|
+
<link rel="stylesheet" crossorigin href="./assets/index-B6MsSoeo.css">
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<div id="root"></div>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clean Room (docs/clean-room-spec.md): an agent that runs in a container on its own git worktree. This file reads the
|
|
3
|
+
* setting, checks Docker and the repository, makes the worktree once and builds the `docker run` arguments. The launcher
|
|
4
|
+
* puts them together with the files and the environment of a Claude Code start.
|
|
5
|
+
*/
|
|
6
|
+
import { execFile } from 'node:child_process';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { lookup } from 'node:dns/promises';
|
|
9
|
+
import { lstat, mkdir, realpath, stat } from 'node:fs/promises';
|
|
10
|
+
import { hostname } from 'node:os';
|
|
11
|
+
import { basename, dirname, join, relative } from 'node:path';
|
|
12
|
+
import { CLEAN_ROOM_DIR, cleanRoomBranch } from '../shared/protocol.js';
|
|
13
|
+
import { CLEAN_ROOM_COMMAND_MS, CLEAN_ROOM_DEFAULT_IMAGE, CLEAN_ROOM_HOME_DIR, CLEAN_ROOM_HOST, CLEAN_ROOM_IMAGE_ENV, CLEAN_ROOM_IMAGE_PATTERN, CLEAN_ROOM_NETWORK_ENV, CLEAN_ROOM_NETWORK_PATTERN, CLEAN_ROOM_NETWORK_SELF, DIR_MODE, DOCKER_BIN, GIT_BIN, } from './constants.js';
|
|
14
|
+
const IMAGE_RE = new RegExp(CLEAN_ROOM_IMAGE_PATTERN);
|
|
15
|
+
const NETWORK_RE = new RegExp(CLEAN_ROOM_NETWORK_PATTERN);
|
|
16
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
18
|
+
/** The one reader of a Clean Room setting: the hub uses it for hire and edit, home.ts for the roster file. `{}` is the default image. */
|
|
19
|
+
export function parseCleanRoom(value, provider) {
|
|
20
|
+
if (!isRecord(value))
|
|
21
|
+
return { ok: false, error: 'cleanRoom must be an object' };
|
|
22
|
+
if ((provider ?? 'claude') !== 'claude')
|
|
23
|
+
return { ok: false, error: 'a Clean Room runs Claude Code agents only' };
|
|
24
|
+
const unknown = Object.keys(value).find((key) => key !== 'image');
|
|
25
|
+
if (unknown !== undefined)
|
|
26
|
+
return { ok: false, error: `cleanRoom has no field "${unknown}"` };
|
|
27
|
+
const { image } = value;
|
|
28
|
+
if (image === undefined)
|
|
29
|
+
return { ok: true, cleanRoom: {} };
|
|
30
|
+
if (typeof image !== 'string' || !IMAGE_RE.test(image))
|
|
31
|
+
return { ok: false, error: 'the image must be a Docker image name or id (letters, digits and . _ / : @ -)' };
|
|
32
|
+
return { ok: true, cleanRoom: { image } };
|
|
33
|
+
}
|
|
34
|
+
/** The agent's own image, else GONOGO_CLEANROOM_IMAGE, else the project's `ghcr.io/ulm0/gonogo`. */
|
|
35
|
+
export function cleanRoomImage(cleanRoom, env) {
|
|
36
|
+
const image = cleanRoom.image ?? (env[CLEAN_ROOM_IMAGE_ENV]?.trim() || CLEAN_ROOM_DEFAULT_IMAGE);
|
|
37
|
+
if (!IMAGE_RE.test(image))
|
|
38
|
+
throw new Error(`${CLEAN_ROOM_IMAGE_ENV} is not a Docker image name: ${JSON.stringify(image)}`);
|
|
39
|
+
return image;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* GONOGO_CLEANROOM_NETWORK, or null when unset. Only `container:<name>`: the container shares gonogo's network and its
|
|
43
|
+
* hosts file, where host.docker.internal must name 127.0.0.1. Another network would need a private address, and Claude
|
|
44
|
+
* Code blocks HTTP hooks to those. `container:self` is gonogo's own container by its host name, which Docker sets to the
|
|
45
|
+
* container's short id unless `hostname` is set, so compose needs no fixed container name.
|
|
46
|
+
*/
|
|
47
|
+
export function cleanRoomNetwork(env, host = hostname()) {
|
|
48
|
+
const raw = env[CLEAN_ROOM_NETWORK_ENV]?.trim();
|
|
49
|
+
if (!raw)
|
|
50
|
+
return null;
|
|
51
|
+
const value = raw === CLEAN_ROOM_NETWORK_SELF ? `container:${host}` : raw;
|
|
52
|
+
if (!NETWORK_RE.test(value))
|
|
53
|
+
throw new Error(`${CLEAN_ROOM_NETWORK_ENV} must be ${CLEAN_ROOM_NETWORK_SELF} or container:<name of gonogo's own container>, not ${JSON.stringify(raw)}`);
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* With gonogo in a container, the host's Docker mounts a Clean Room's folders by their paths on the host, so gonogo's
|
|
58
|
+
* home must be a bind mount from the same path of the host. `mounts` is `.Mounts` of `docker inspect`. Null when it is.
|
|
59
|
+
*/
|
|
60
|
+
export function sameMountError(mounts, homeDir, container) {
|
|
61
|
+
const covers = (dest) => homeDir === dest || homeDir.startsWith(dest.endsWith('/') ? dest : `${dest}/`);
|
|
62
|
+
const mount = (Array.isArray(mounts) ? mounts : [])
|
|
63
|
+
.filter(isRecord)
|
|
64
|
+
.filter((m) => typeof m.Destination === 'string' && covers(m.Destination))
|
|
65
|
+
.sort((a, b) => String(b.Destination).length - String(a.Destination).length)[0];
|
|
66
|
+
if (mount?.Type === 'bind' && mount.Source === mount.Destination)
|
|
67
|
+
return null;
|
|
68
|
+
return `gonogo's home ${homeDir} is not mounted into the container ${container} from the same path of the host: the host's Docker mounts a Clean Room's folders by their host paths, so mount it as -v ${homeDir}:${homeDir}`;
|
|
69
|
+
}
|
|
70
|
+
/** Runs a program without a shell and answers its output. A failure is an Error whose text is the first line the program printed on stderr. */
|
|
71
|
+
function run(file, args, env) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
execFile(file, args, { env: env, timeout: CLEAN_ROOM_COMMAND_MS, maxBuffer: 1024 * 1024 }, (error, stdout, stderr) => {
|
|
74
|
+
if (error === null)
|
|
75
|
+
return resolve(stdout);
|
|
76
|
+
const code = error.code;
|
|
77
|
+
const line = stderr.split('\n').find((l) => l.trim() !== '')?.trim() ?? error.message.split('\n')[0] ?? '';
|
|
78
|
+
reject(new Error(code === 'ENOENT' ? `${file} was not found on PATH` : line.slice(0, 300)));
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Docker is there and its daemon answers: `docker version` exits 0 only then. */
|
|
83
|
+
export async function checkDocker(env) {
|
|
84
|
+
try {
|
|
85
|
+
await run(DOCKER_BIN, ['version'], env);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new Error(`Clean Room needs Docker, and "docker version" failed: ${messageOf(error)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The top folder of the git repository that holds `dir`. */
|
|
92
|
+
export async function repoRoot(dir, env) {
|
|
93
|
+
try {
|
|
94
|
+
return (await run(GIT_BIN, ['-C', dir, 'rev-parse', '--show-toplevel'], env)).trim();
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`Clean Room needs the directory to be inside a git repository: ${messageOf(error)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** What the hub asks at hire and edit: null when Docker works and `dir` is in a repository, else why not. */
|
|
101
|
+
export async function checkCleanRoom(dir, env) {
|
|
102
|
+
try {
|
|
103
|
+
cleanRoomNetwork(env);
|
|
104
|
+
await checkDocker(env);
|
|
105
|
+
await repoRoot(dir, env);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return messageOf(error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Makes the worktree on its branch the first time and finds it again after that. A folder in its place that git does not know is an error, never reused. */
|
|
113
|
+
export async function ensureWorktree(repo, path, branch, env) {
|
|
114
|
+
const git = (...args) => run(GIT_BIN, ['-C', repo, ...args], env);
|
|
115
|
+
const real = await realpath(path).catch(() => null);
|
|
116
|
+
if (real !== null) {
|
|
117
|
+
const listed = (await git('worktree', 'list', '--porcelain')).split('\n').filter((l) => l.startsWith('worktree ')).map((l) => l.slice(9));
|
|
118
|
+
if (!(await Promise.all(listed.map((p) => realpath(p).catch(() => p)))).includes(real)) {
|
|
119
|
+
throw new Error(`${path} exists but is not a worktree of ${repo}; move it away or give the agent a folder of the repository it was made for`);
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
await mkdir(dirname(path), { recursive: true, mode: DIR_MODE });
|
|
124
|
+
try {
|
|
125
|
+
await git('worktree', 'prune'); // a worktree whose folder was deleted still holds its branch
|
|
126
|
+
const known = await git('show-ref', '--verify', '--quiet', `refs/heads/${branch}`).then(() => true, () => false);
|
|
127
|
+
await git('worktree', 'add', ...(known ? [path, branch] : ['-b', branch, path]));
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
throw new Error(`could not make the worktree ${path} on ${branch}: ${messageOf(error)}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** `gonogo-<name>-<hash of the worktree path>`: two gonogo homes on one Docker never share a name. */
|
|
134
|
+
export const containerName = (worktree) => `gonogo-${basename(worktree)}-${createHash('sha256').update(worktree).digest('hex').slice(0, 12)}`;
|
|
135
|
+
/**
|
|
136
|
+
* `docker rm -f`: with `-t` the docker CLI does not pass signals on, so a stopped console's container would keep running
|
|
137
|
+
* after its docker process ended. Called after every exit and before every start. Never fails: no such container is fine.
|
|
138
|
+
*/
|
|
139
|
+
export async function removeContainer(name, env) {
|
|
140
|
+
await run(DOCKER_BIN, ['rm', '-f', name], env).catch(() => undefined);
|
|
141
|
+
}
|
|
142
|
+
/** Everything a start needs on disk: Docker checked, the worktree there, the container's home made. `base` is agents/<name>. */
|
|
143
|
+
export async function prepareCleanRoom(agent, homeDir, base, env) {
|
|
144
|
+
const network = cleanRoomNetwork(env);
|
|
145
|
+
await checkDocker(env);
|
|
146
|
+
if (network !== null) {
|
|
147
|
+
const self = network.slice('container:'.length);
|
|
148
|
+
let mounts;
|
|
149
|
+
try {
|
|
150
|
+
mounts = JSON.parse(await run(DOCKER_BIN, ['inspect', '--format', '{{json .Mounts}}', self], env));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
throw new Error(`${CLEAN_ROOM_NETWORK_ENV} names the container ${self}, and "docker inspect" failed: ${messageOf(error)}`);
|
|
154
|
+
}
|
|
155
|
+
const error = sameMountError(mounts, homeDir, self);
|
|
156
|
+
if (error !== null)
|
|
157
|
+
throw new Error(error);
|
|
158
|
+
// The Clean Room shares this container's hosts file; keeping the name (not 127.0.0.1) keeps the Host rule: hooks and MCP only.
|
|
159
|
+
const address = await lookup(CLEAN_ROOM_HOST).then((found) => found.address, () => 'nothing');
|
|
160
|
+
if (!address.startsWith('127.'))
|
|
161
|
+
throw new Error(`${CLEAN_ROOM_HOST} names ${address} in the container ${self}, not 127.0.0.1: start it with --add-host ${CLEAN_ROOM_HOST}:127.0.0.1 (compose.yaml has it)`);
|
|
162
|
+
}
|
|
163
|
+
const top = await realpath(await repoRoot(agent.dir, env));
|
|
164
|
+
const worktree = join(homeDir, CLEAN_ROOM_DIR, agent.name);
|
|
165
|
+
await ensureWorktree(top, worktree, cleanRoomBranch(agent.name), env);
|
|
166
|
+
const inside = relative(top, await realpath(agent.dir));
|
|
167
|
+
const cwd = join(worktree, inside);
|
|
168
|
+
if (!(await stat(cwd).then((info) => info.isDirectory(), () => false))) {
|
|
169
|
+
throw new Error(`${inside} is not in the worktree ${worktree}: the worktree is a copy of the last commit, and that folder is not committed`);
|
|
170
|
+
}
|
|
171
|
+
const container = containerName(worktree);
|
|
172
|
+
await removeContainer(container, env);
|
|
173
|
+
const home = join(base, CLEAN_ROOM_HOME_DIR);
|
|
174
|
+
await mkdir(home, { recursive: true, mode: DIR_MODE });
|
|
175
|
+
// The container can write the agent's folder: a link planted there would make gonogo write trust into a file outside it.
|
|
176
|
+
for (const path of [home, join(home, '.claude.json')]) {
|
|
177
|
+
if ((await lstat(path).catch(() => null))?.isSymbolicLink())
|
|
178
|
+
throw new Error(`${path} is a symbolic link, and a Clean Room never follows one out of its folder: delete it`);
|
|
179
|
+
}
|
|
180
|
+
return { worktree, cwd, home, container, network };
|
|
181
|
+
}
|
|
182
|
+
/** The URL an agent in a container reaches gonogo by: the loopback host of the server's URL becomes the host's name. */
|
|
183
|
+
export const containerUrl = (hubUrl) => hubUrl.replace(/^http:\/\/(?:127\.0\.0\.1|\[::1\])/, `http://${CLEAN_ROOM_HOST}`);
|
|
184
|
+
/**
|
|
185
|
+
* `docker run` for one agent: the worktree and the agent's own folder at the same paths, nothing else, as the owner's
|
|
186
|
+
* uid. The worktree's `.git` file is read-only: rewritten, it could point the owner's next git command in the worktree
|
|
187
|
+
* at a config (core.fsmonitor) that runs a program on the host. Variables are named without a value, so docker reads them from its own environment and no secret is on the
|
|
188
|
+
* command line. `command` is the program to run inside and its arguments: the program goes in `--entrypoint`, because the
|
|
189
|
+
* project's own image has `gonogo` as its entrypoint, and HOME and CLAUDE_CONFIG_DIR are set because the image points the
|
|
190
|
+
* second one at a folder this user cannot write.
|
|
191
|
+
*/
|
|
192
|
+
export function buildDockerArgs(input) {
|
|
193
|
+
const { place } = input;
|
|
194
|
+
for (const path of [place.worktree, input.agentDir]) {
|
|
195
|
+
if (path.includes(':'))
|
|
196
|
+
throw new Error(`the path ${path} has a colon, which docker cannot mount`);
|
|
197
|
+
}
|
|
198
|
+
return [
|
|
199
|
+
'run', '--rm', '-i', '-t', '--init',
|
|
200
|
+
'--name', place.container,
|
|
201
|
+
'--user', `${input.uid}:${input.gid}`,
|
|
202
|
+
...(place.network === null ? ['--add-host', `${CLEAN_ROOM_HOST}:host-gateway`] : ['--network', place.network]),
|
|
203
|
+
'-e', `HOME=${place.home}`,
|
|
204
|
+
'-e', `CLAUDE_CONFIG_DIR=${place.home}`,
|
|
205
|
+
...input.names.flatMap((name) => ['-e', name]),
|
|
206
|
+
'-v', `${place.worktree}:${place.worktree}`,
|
|
207
|
+
'-v', `${join(place.worktree, '.git')}:${join(place.worktree, '.git')}:ro`,
|
|
208
|
+
'-v', `${input.agentDir}:${input.agentDir}`,
|
|
209
|
+
'-w', place.cwd,
|
|
210
|
+
'--entrypoint', input.command[0],
|
|
211
|
+
input.image,
|
|
212
|
+
...input.command.slice(1),
|
|
213
|
+
];
|
|
214
|
+
}
|