@ulm0/gonogo 0.1.1 → 0.1.2
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/README.md +5 -11
- package/dist/client/assets/index-BqCn1SM7.js +50 -0
- package/dist/client/assets/index-KZtFVMJG.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/audited.js +133 -0
- package/dist/server/blackbox.js +261 -0
- package/dist/server/board.js +123 -0
- package/dist/server/clearance.js +158 -0
- package/dist/server/cli.js +145 -12
- package/dist/server/constants.js +39 -1
- package/dist/server/hangar.js +311 -0
- package/dist/server/home.js +24 -1
- package/dist/server/hub.js +181 -23
- package/dist/server/launcher.js +11 -6
- package/dist/server/logchart.js +58 -0
- package/dist/server/massbudget.js +169 -0
- package/dist/server/mcp.js +33 -1
- package/dist/server/migrate.js +6 -3
- package/dist/server/missionlog.js +2 -0
- package/dist/server/providers.js +71 -9
- package/dist/server/recorder.js +176 -0
- package/dist/server/relief.js +226 -0
- package/dist/server/rollout.js +172 -0
- package/dist/server/telemetry.js +110 -0
- package/dist/server/web.js +146 -5
- package/dist/shared/livery.js +1 -1
- package/dist/shared/positions.js +1 -1
- package/dist/shared/protocol.js +47 -14
- package/package.json +1 -1
- package/dist/client/assets/index-B6MsSoeo.css +0 -1
- package/dist/client/assets/index-DRtiRh1Y.js +0 -31
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plot Board: the one current plan of the room (docs/plot-board-spec.md).
|
|
3
|
+
*
|
|
4
|
+
* One file, `<home>/board.md`: a small front matter (version, revision, author, updatedAt; each value JSON on one line) and then the
|
|
5
|
+
* plan as plain text. The Director (the browser route) and the boss (the MCP tool board_write) write it; every agent reads it. Who
|
|
6
|
+
* may write is decided by the caller (the route is the Director's, the tool checks for the boss): this store only checks the text and
|
|
7
|
+
* the revision. A write names the revision it read and is refused when the board has moved on, so a write never replaces text its
|
|
8
|
+
* author did not see. The file is written whole to a temporary file and renamed. A file without our front matter (written by hand) is
|
|
9
|
+
* read as the plan itself. The clock is injected for tests.
|
|
10
|
+
*
|
|
11
|
+
* shortcut: a hand edit made while gonogo runs is not seen until the next start, and the next write replaces it; read the file again
|
|
12
|
+
* on each get if that ever matters.
|
|
13
|
+
*/
|
|
14
|
+
import { randomBytes } from 'node:crypto';
|
|
15
|
+
import { readFile, rename, stat, writeFile } from 'node:fs/promises';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { BOARD_MAX_CHARS } from '../shared/protocol.js';
|
|
18
|
+
import { BOARD_FILE, FILE_MODE } from './constants.js';
|
|
19
|
+
import { isRecord } from './hooks.js';
|
|
20
|
+
import { HubError } from './hub.js';
|
|
21
|
+
const FIELDS = ['text', 'revision'];
|
|
22
|
+
/** The keys of our front matter; a file whose first lines are anything else is a plan written by hand. */
|
|
23
|
+
const FRONT_KEYS = ['version', 'revision', 'author', 'updatedAt'];
|
|
24
|
+
const bad = (message, field) => new HubError('bad_request', message, field);
|
|
25
|
+
const render = (view) => [
|
|
26
|
+
'---',
|
|
27
|
+
'version: 1',
|
|
28
|
+
`revision: ${JSON.stringify(view.revision)}`,
|
|
29
|
+
`author: ${JSON.stringify(view.author)}`,
|
|
30
|
+
`updatedAt: ${JSON.stringify(view.updatedAt === null ? null : new Date(view.updatedAt).toISOString())}`,
|
|
31
|
+
'---',
|
|
32
|
+
view.text,
|
|
33
|
+
'',
|
|
34
|
+
].join('\n');
|
|
35
|
+
/** The board in a file; one that has our front matter is read by it, any other text is the plan itself. */
|
|
36
|
+
function parse(text, mtime, path) {
|
|
37
|
+
const found = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(text.replace(/\r\n/g, '\n'));
|
|
38
|
+
const values = new Map();
|
|
39
|
+
try {
|
|
40
|
+
for (const line of found === null ? [] : (found[1] ?? '').split('\n')) {
|
|
41
|
+
const at = line.indexOf(': ');
|
|
42
|
+
if (at < 0 || !FRONT_KEYS.includes(line.slice(0, at)))
|
|
43
|
+
throw new Error('not ours');
|
|
44
|
+
values.set(line.slice(0, at), JSON.parse(line.slice(at + 2)));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
values.clear();
|
|
49
|
+
}
|
|
50
|
+
if (found === null || values.size === 0)
|
|
51
|
+
return { text: text.replace(/\r\n/g, '\n').trimEnd().slice(0, BOARD_MAX_CHARS), revision: 0, author: null, updatedAt: mtime };
|
|
52
|
+
const { version, revision, author, updatedAt } = Object.fromEntries(values);
|
|
53
|
+
if (version !== undefined && version !== 1) {
|
|
54
|
+
throw new Error(`${path} was saved by a newer gonogo (format version ${String(version)}; this one reads up to 1). Start the gonogo that saved it, or move the file away to start without it.`);
|
|
55
|
+
}
|
|
56
|
+
const at = typeof updatedAt === 'string' ? Date.parse(updatedAt) : Number.NaN;
|
|
57
|
+
return {
|
|
58
|
+
text: (found[2] ?? '').replace(/\n$/, '').slice(0, BOARD_MAX_CHARS),
|
|
59
|
+
revision: typeof revision === 'number' && Number.isSafeInteger(revision) && revision >= 0 ? revision : 0,
|
|
60
|
+
author: typeof author === 'string' && author !== '' ? author : null,
|
|
61
|
+
updatedAt: Number.isNaN(at) ? mtime : at,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function createBoard(options) {
|
|
65
|
+
const { now } = options;
|
|
66
|
+
const path = join(options.dir, BOARD_FILE);
|
|
67
|
+
let current = { text: '', revision: 0, author: null, updatedAt: null };
|
|
68
|
+
let chain = Promise.resolve();
|
|
69
|
+
/** One write at a time, so that two writers of one revision cannot both succeed; a failure goes to the caller and the next write goes on. */
|
|
70
|
+
const locked = (fn) => {
|
|
71
|
+
const run = chain.then(fn);
|
|
72
|
+
chain = run.catch(() => undefined);
|
|
73
|
+
return run;
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
async load() {
|
|
77
|
+
let text;
|
|
78
|
+
try {
|
|
79
|
+
text = await readFile(path, 'utf8');
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error.code === 'ENOENT')
|
|
83
|
+
return;
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
current = parse(text, (await stat(path)).mtimeMs, path);
|
|
87
|
+
},
|
|
88
|
+
get: () => ({ ...current }),
|
|
89
|
+
write(by, input) {
|
|
90
|
+
return locked(async () => {
|
|
91
|
+
if (!isRecord(input))
|
|
92
|
+
throw bad('request body must be a JSON object');
|
|
93
|
+
for (const key of Object.keys(input))
|
|
94
|
+
if (!FIELDS.includes(key))
|
|
95
|
+
throw bad(`unknown field "${key}"`, key);
|
|
96
|
+
if (typeof input.text !== 'string')
|
|
97
|
+
throw bad('text is required', 'text');
|
|
98
|
+
const text = input.text.replace(/\r\n?/g, '\n').trimEnd();
|
|
99
|
+
if (text.length > BOARD_MAX_CHARS)
|
|
100
|
+
throw bad(`text must be at most ${BOARD_MAX_CHARS} characters`, 'text');
|
|
101
|
+
if (text.includes('\0'))
|
|
102
|
+
throw bad('text must not hold a NUL character', 'text');
|
|
103
|
+
if (typeof input.revision !== 'number' || !Number.isSafeInteger(input.revision) || input.revision < 0)
|
|
104
|
+
throw bad('revision must be a whole number, the one you read', 'revision');
|
|
105
|
+
if (input.revision !== current.revision) {
|
|
106
|
+
throw new HubError('conflict', `the Plot Board is at revision ${current.revision}, not ${input.revision}: read it again, then write`, 'revision');
|
|
107
|
+
}
|
|
108
|
+
// the same text again changes nothing: no new revision, no new file
|
|
109
|
+
if (text === current.text)
|
|
110
|
+
return { ...current };
|
|
111
|
+
const next = { text, revision: current.revision + 1, author: by, updatedAt: now() };
|
|
112
|
+
const tmp = join(options.dir, `.${BOARD_FILE}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`);
|
|
113
|
+
await writeFile(tmp, render(next), { mode: FILE_MODE, flag: 'wx' });
|
|
114
|
+
await rename(tmp, path);
|
|
115
|
+
current = next;
|
|
116
|
+
return { ...current };
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
close() {
|
|
120
|
+
return chain.then(() => undefined);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clearance (docs/engine-bay-spec.md): environment variables the Director sets for one agent, usually API keys.
|
|
3
|
+
*
|
|
4
|
+
* keys.json (mode 0600, written whole through a temporary file and a rename) holds the values: agent name to name to value.
|
|
5
|
+
* The roster keeps the names and the time each was set, so the page can say "set"; a value is never sent to a browser and
|
|
6
|
+
* never logged. The launcher puts an agent's keys in that agent's environment only (launcher.ts).
|
|
7
|
+
*
|
|
8
|
+
* shortcut: the values are stored as text (an API key has to be sent as it is), so the file is 0600 and nothing else; encrypt
|
|
9
|
+
* it if the home folder is ever shared.
|
|
10
|
+
*/
|
|
11
|
+
import { randomBytes } from 'node:crypto';
|
|
12
|
+
import { readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { KEY_NAME_PATTERN, KEY_VALUE_PATTERN, KEYS_MAX } from '../shared/protocol.js';
|
|
15
|
+
import { FILE_MODE, KEYS_FILE, nullLogger } from './constants.js';
|
|
16
|
+
const NAME_RE = new RegExp(KEY_NAME_PATTERN);
|
|
17
|
+
const VALUE_RE = new RegExp(KEY_VALUE_PATTERN);
|
|
18
|
+
/** Variables that change what runs or where, or that gonogo sets itself: a key is data, so these are refused. */
|
|
19
|
+
const RESERVED_EXACT = new Set([
|
|
20
|
+
'PATH', 'HOME', 'SHELL', 'USER', 'LOGNAME', 'PWD', 'TMPDIR', 'TERM', 'COLORTERM', 'IS_DEMO', 'NODE_OPTIONS', 'NODE_PATH', 'CLAUDE_CONFIG_DIR',
|
|
21
|
+
// shell and interpreter start-up hooks: each runs a file or a command before the program the agent started
|
|
22
|
+
'BASH_ENV', 'SHELLOPTS', 'BASHOPTS', 'PROMPT_COMMAND', 'IFS', 'PYTHONSTARTUP', 'PYTHONPATH', 'PYTHONHOME', 'RUBYOPT', 'RUBYLIB', 'PERL5OPT', 'PERL5LIB',
|
|
23
|
+
'GIT_SSH_COMMAND', 'GIT_ASKPASS', 'SSH_ASKPASS', 'GIT_EXEC_PATH',
|
|
24
|
+
]);
|
|
25
|
+
// DOCKER_: a Clean Room's docker client runs with the agent's keys in its environment, and DOCKER_HOST would move the container to another daemon.
|
|
26
|
+
// shortcut: the usual start-up hooks, not every variable some program reads as a command; the Director owns the agent anyway, so extend the list when one turns up.
|
|
27
|
+
const RESERVED_PREFIXES = ['GONOGO_', 'LD_', 'DYLD_', 'BASH_FUNC_', 'DOCKER_', 'GIT_CONFIG_'];
|
|
28
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
29
|
+
/** Why this name cannot be a key, or null. */
|
|
30
|
+
export function keyNameProblem(name) {
|
|
31
|
+
// the name is not echoed: a value pasted in the wrong field must not come back in an error
|
|
32
|
+
if (!NAME_RE.test(name))
|
|
33
|
+
return 'a key name uses capital letters, digits and _, starting with a letter (at most 64 characters)';
|
|
34
|
+
if (RESERVED_EXACT.has(name) || RESERVED_PREFIXES.some((prefix) => name.startsWith(prefix)))
|
|
35
|
+
return `${name} is set by gonogo or changes what runs, so it cannot be a key`;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The shape of a hire's or an edit's keys: name to value, and for an edit also name to null (remove). `current` is the names
|
|
40
|
+
* the agent has (name to time), `names` the names it will have, new and changed ones stamped `now`. Values stay in `patch`.
|
|
41
|
+
* An error names the key and says what is wrong, never what the value was.
|
|
42
|
+
*/
|
|
43
|
+
export function checkKeys(value, current, now, hire) {
|
|
44
|
+
if (!isRecord(value))
|
|
45
|
+
return { ok: false, error: 'keys must be an object of names and values' };
|
|
46
|
+
const entries = Object.entries(value);
|
|
47
|
+
if (entries.length > KEYS_MAX)
|
|
48
|
+
return { ok: false, error: `at most ${KEYS_MAX} keys` };
|
|
49
|
+
const names = { ...current };
|
|
50
|
+
const patch = {};
|
|
51
|
+
for (const [name, item] of entries) {
|
|
52
|
+
const problem = keyNameProblem(name);
|
|
53
|
+
if (problem !== null)
|
|
54
|
+
return { ok: false, error: problem };
|
|
55
|
+
if (item === null && !hire) {
|
|
56
|
+
delete names[name];
|
|
57
|
+
patch[name] = null;
|
|
58
|
+
}
|
|
59
|
+
else if (typeof item === 'string' && VALUE_RE.test(item)) {
|
|
60
|
+
names[name] = now;
|
|
61
|
+
patch[name] = item;
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
return { ok: false, error: `${name} must be text of 1 to 4096 printable characters without a space${hire ? '' : ', or null to remove it'}` };
|
|
65
|
+
}
|
|
66
|
+
if (Object.keys(names).length > KEYS_MAX)
|
|
67
|
+
return { ok: false, error: `at most ${KEYS_MAX} keys` };
|
|
68
|
+
return { ok: true, patch, names };
|
|
69
|
+
}
|
|
70
|
+
export function createClearance(options) {
|
|
71
|
+
const log = options.log ?? nullLogger;
|
|
72
|
+
const path = join(options.dir, KEYS_FILE);
|
|
73
|
+
let agents = new Map();
|
|
74
|
+
let chain = Promise.resolve();
|
|
75
|
+
/** One write after the other; a failed one rejects to its caller and does not stop the next. A change that returns the same map writes nothing. */
|
|
76
|
+
const write = (change) => {
|
|
77
|
+
const run = chain.then(async () => {
|
|
78
|
+
const before = agents;
|
|
79
|
+
agents = change();
|
|
80
|
+
if (agents === before)
|
|
81
|
+
return;
|
|
82
|
+
const temp = `${path}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
|
|
83
|
+
try {
|
|
84
|
+
await writeFile(temp, JSON.stringify({ version: 1, agents: Object.fromEntries(agents) }, null, 2), { flag: 'wx', mode: FILE_MODE });
|
|
85
|
+
await rename(temp, path);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
agents = before;
|
|
89
|
+
await rm(temp, { force: true }).catch(() => undefined);
|
|
90
|
+
// the message of a file error holds a path, not a value
|
|
91
|
+
throw new Error(`could not save the keys: ${error instanceof Error ? error.message : String(error)}`);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
chain = run.catch(() => undefined);
|
|
95
|
+
return run;
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
async load() {
|
|
99
|
+
let saved;
|
|
100
|
+
try {
|
|
101
|
+
saved = JSON.parse(await readFile(path, 'utf8'));
|
|
102
|
+
if (!isRecord(saved) || saved.version !== 1 || !isRecord(saved.agents))
|
|
103
|
+
throw new Error('not a version 1 keys file');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.code === 'ENOENT')
|
|
107
|
+
return;
|
|
108
|
+
// kept aside, so that the next save cannot overwrite the keys; a SyntaxError quotes the text around the fault, which can be a key
|
|
109
|
+
log.error(`${KEYS_FILE} could not be read; agents start without keys and the file is kept as ${KEYS_FILE}.bad`, error instanceof SyntaxError ? 'not valid JSON' : error);
|
|
110
|
+
await rename(path, `${path}.bad`).catch(() => undefined);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
for (const [agent, keys] of Object.entries(saved.agents)) {
|
|
114
|
+
if (!isRecord(keys))
|
|
115
|
+
continue;
|
|
116
|
+
const own = Object.fromEntries(Object.entries(keys).filter(([name, value]) => keyNameProblem(name) === null && typeof value === 'string' && VALUE_RE.test(value)));
|
|
117
|
+
if (Object.keys(own).length > 0)
|
|
118
|
+
agents.set(agent, own);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
values: (name) => ({ ...agents.get(name) }),
|
|
122
|
+
apply: (name, patch, fresh = false) => write(() => {
|
|
123
|
+
const keys = { ...(fresh ? {} : agents.get(name)) };
|
|
124
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
125
|
+
if (value === null)
|
|
126
|
+
delete keys[key];
|
|
127
|
+
else
|
|
128
|
+
keys[key] = value;
|
|
129
|
+
}
|
|
130
|
+
const empty = Object.keys(keys).length === 0;
|
|
131
|
+
if (empty && !agents.has(name))
|
|
132
|
+
return agents;
|
|
133
|
+
const next = new Map(agents);
|
|
134
|
+
if (empty)
|
|
135
|
+
next.delete(name);
|
|
136
|
+
else
|
|
137
|
+
next.set(name, keys);
|
|
138
|
+
return next;
|
|
139
|
+
}),
|
|
140
|
+
rename: (oldName, newName) => write(() => {
|
|
141
|
+
const keys = agents.get(oldName);
|
|
142
|
+
if (keys === undefined)
|
|
143
|
+
return agents;
|
|
144
|
+
const next = new Map(agents);
|
|
145
|
+
next.delete(oldName);
|
|
146
|
+
next.set(newName, keys);
|
|
147
|
+
return next;
|
|
148
|
+
}),
|
|
149
|
+
remove: (name) => write(() => {
|
|
150
|
+
if (!agents.has(name))
|
|
151
|
+
return agents;
|
|
152
|
+
const next = new Map(agents);
|
|
153
|
+
next.delete(name);
|
|
154
|
+
return next;
|
|
155
|
+
}),
|
|
156
|
+
close: () => chain.then(() => undefined),
|
|
157
|
+
};
|
|
158
|
+
}
|
package/dist/server/cli.js
CHANGED
|
@@ -7,33 +7,50 @@ import { fileURLToPath } from 'node:url';
|
|
|
7
7
|
import { PROTOCOL_VERSION } from '../shared/protocol.js';
|
|
8
8
|
import { MAX_AGENTS } from '../shared/protocol.js';
|
|
9
9
|
import { CLAUDE_BIN, DEFAULT_HOME_DIRNAME, DEFAULT_HOST, DEFAULT_MAX_HOPS, DEFAULT_PORT, DOWNLINK_HISTORY, MAX_HOPS_LIMIT, MAX_WORKING_ENV, REDLINE_ENV, ROSTER_ROLE_CHARS, SHUTDOWN_MAX_MS, STATION_ENV, TRANSIENT_ERROR_CODES, TRANSIENT_ERROR_PREFIXES, createLogger, nullLogger, } from './constants.js';
|
|
10
|
+
import { audited, BOARD_AUDIT, DOCKING_AUDIT, HUB_AUDIT, LIVERIES_AUDIT, pollText, PROPELLANT_AUDIT, RELAY_AUDIT, SCHEDULES_AUDIT, TASKS_AUDIT, tripText, UPLINKS_AUDIT } from './audited.js';
|
|
11
|
+
import { createBlackBox } from './blackbox.js';
|
|
12
|
+
import { createBoard } from './board.js';
|
|
10
13
|
import { createDocking, stationName } from './docking.js';
|
|
11
14
|
import { createDownlink } from './downlink.js';
|
|
12
15
|
import { createHub } from './hub.js';
|
|
16
|
+
import { createHangar, createRoots } from './hangar.js';
|
|
17
|
+
import { createRecorder } from './recorder.js';
|
|
13
18
|
import { checkCleanRoom } from './cleanroom.js';
|
|
14
19
|
import { openHome } from './home.js';
|
|
15
20
|
import { createLauncher, parseAgentCmd } from './launcher.js';
|
|
16
21
|
import { createTerminalHost } from './terminal.js';
|
|
17
22
|
import { createWebServer } from './web.js';
|
|
18
23
|
import { createPropellant } from './propellant.js';
|
|
24
|
+
import { createTelemetry } from './telemetry.js';
|
|
19
25
|
import { createRelay } from './relay.js';
|
|
20
26
|
import { createSchedules } from './schedules.js';
|
|
21
27
|
import { createLiveries } from './livery.js';
|
|
28
|
+
import { createRelief } from './relief.js';
|
|
29
|
+
import { createMassBudget } from './massbudget.js';
|
|
22
30
|
import { createMissionLog } from './missionlog.js';
|
|
23
31
|
import { createTasks } from './tasks.js';
|
|
24
32
|
import { createUplinks } from './uplinks.js';
|
|
25
|
-
import { installedProviders, onPath } from './providers.js';
|
|
33
|
+
import { checkEngines, formatDoctor, installedProviders, onPath } from './providers.js';
|
|
34
|
+
import { createClearance } from './clearance.js';
|
|
35
|
+
import { cachedLatest, createRollout, isNewer, updateCheckOff, updateCommand, updateText } from './rollout.js';
|
|
26
36
|
/* ---------------------------------------------------------------- arguments */
|
|
27
37
|
export const USAGE = `Usage: gonogo [options]
|
|
38
|
+
gonogo doctor
|
|
39
|
+
gonogo update
|
|
28
40
|
|
|
29
41
|
Run a mission-control room of Claude Code agents from a browser tab.
|
|
30
42
|
|
|
43
|
+
Commands:
|
|
44
|
+
doctor list the agent CLIs on the PATH with their versions, and the install command of each missing one
|
|
45
|
+
update print the command that updates gonogo the way it was installed (it never runs it)
|
|
46
|
+
|
|
31
47
|
Options:
|
|
32
48
|
--port <n> listen port (default ${DEFAULT_PORT}; env GONOGO_PORT)
|
|
33
49
|
--host <addr> bind address (default ${DEFAULT_HOST}; env GONOGO_HOST)
|
|
34
50
|
--home <dir> state directory (default ~/${DEFAULT_HOME_DIRNAME}; env GONOGO_HOME)
|
|
35
51
|
--seed-claude record Claude's folder trust and skip its startup dialogs (env GONOGO_SEED_CLAUDE=1)
|
|
36
52
|
--allow-host <name> accept this Host name too, for a reverse proxy; repeatable (env GONOGO_ALLOWED_HOSTS, comma list)
|
|
53
|
+
--no-update-check do not ask the npm registry once a day whether a newer gonogo exists (env GONOGO_UPDATE_CHECK=0)
|
|
37
54
|
-h, --help show this help
|
|
38
55
|
-v, --version show the version
|
|
39
56
|
|
|
@@ -45,6 +62,7 @@ Environment:
|
|
|
45
62
|
GONOGO_CLEANROOM_IMAGE Docker image of a Clean Room console (default ghcr.io/ulm0/gonogo)
|
|
46
63
|
GONOGO_LOG_LEVEL debug, info, warn or error (default info)
|
|
47
64
|
GONOGO_SCRUB_ENV extra variables to keep out of the agents (comma list; a name ending in _ is a prefix)
|
|
65
|
+
GONOGO_UPDATE_CHECK 0, off, false or no: do not check for a newer gonogo (default on)
|
|
48
66
|
`;
|
|
49
67
|
const VALUE_FLAGS = ['--port', '--host', '--home', '--allow-host'];
|
|
50
68
|
function parsePort(value, label) {
|
|
@@ -59,6 +77,8 @@ export function parseArgs(argv) {
|
|
|
59
77
|
return { kind: 'help' };
|
|
60
78
|
if (argv.includes('--version') || argv.includes('-v'))
|
|
61
79
|
return { kind: 'version' };
|
|
80
|
+
if (argv[0] === 'doctor' || argv[0] === 'update')
|
|
81
|
+
return argv.length === 1 ? { kind: argv[0] } : { kind: 'error', message: `${argv[0]} takes no arguments` };
|
|
62
82
|
const options = {};
|
|
63
83
|
const allowedHosts = [];
|
|
64
84
|
for (let i = 0; i < argv.length; i += 1) {
|
|
@@ -67,6 +87,10 @@ export function parseArgs(argv) {
|
|
|
67
87
|
options.seed = true;
|
|
68
88
|
continue;
|
|
69
89
|
}
|
|
90
|
+
if (arg === '--no-update-check') {
|
|
91
|
+
options.updateCheck = false;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
70
94
|
const eq = arg.startsWith('--') ? arg.indexOf('=') : -1;
|
|
71
95
|
const flag = eq === -1 ? arg : arg.slice(0, eq);
|
|
72
96
|
if (!VALUE_FLAGS.includes(flag))
|
|
@@ -176,6 +200,14 @@ function packageVersion() {
|
|
|
176
200
|
}
|
|
177
201
|
return '0.0.0';
|
|
178
202
|
}
|
|
203
|
+
/** How this gonogo was installed, from where its own file is: in a container, a git checkout, or one of the package managers (Rollout). */
|
|
204
|
+
function installInfo() {
|
|
205
|
+
const docker = existsSync('/.dockerenv') || existsSync('/run/.containerenv');
|
|
206
|
+
const clone = existsSync(fileURLToPath(new URL('../../.git', import.meta.url)));
|
|
207
|
+
return { docker, command: updateCommand({ file: fileURLToPath(import.meta.url), docker, clone }) };
|
|
208
|
+
}
|
|
209
|
+
/** The home as `gonogo --version` and `gonogo update` find it: GONOGO_HOME or the default, with no flag read (they read the cache only). */
|
|
210
|
+
const homeOf = (env) => resolve(env.GONOGO_HOME || join(homedir(), DEFAULT_HOME_DIRNAME));
|
|
179
211
|
/** The host of the printed URL: a wildcard bind is reached on loopback, an IPv6 address needs brackets (contract 0.5 item 14). */
|
|
180
212
|
function displayHost(host) {
|
|
181
213
|
if (['0.0.0.0', '::', '127.0.0.1'].includes(host))
|
|
@@ -225,12 +257,15 @@ export async function startGonogo(options = {}) {
|
|
|
225
257
|
log.warn(`${dir} is not writable by uid ${process.getuid?.() ?? '?'}; chown it to that uid`);
|
|
226
258
|
}
|
|
227
259
|
}
|
|
260
|
+
const clearance = createClearance({ dir: home.dir, log: log.child('clearance') });
|
|
261
|
+
await clearance.load();
|
|
228
262
|
const launcher = createLauncher({
|
|
229
263
|
homeDir: home.dir,
|
|
230
264
|
hubUrl: () => baseUrl,
|
|
231
265
|
seed,
|
|
232
266
|
env,
|
|
233
267
|
agentCmd,
|
|
268
|
+
keys: (name) => clearance.values(name),
|
|
234
269
|
log: log.child('launcher'),
|
|
235
270
|
});
|
|
236
271
|
const propellant = createPropellant({
|
|
@@ -240,6 +275,8 @@ export async function startGonogo(options = {}) {
|
|
|
240
275
|
log: log.child('propellant'),
|
|
241
276
|
});
|
|
242
277
|
await propellant.load();
|
|
278
|
+
const telemetry = createTelemetry({ dir: home.dir, now: () => Date.now(), log: log.child('telemetry') });
|
|
279
|
+
await telemetry.load();
|
|
243
280
|
const downlink = createDownlink({
|
|
244
281
|
dir: home.dir,
|
|
245
282
|
now: () => Date.now(),
|
|
@@ -256,10 +293,22 @@ export async function startGonogo(options = {}) {
|
|
|
256
293
|
log: log.child('relay'),
|
|
257
294
|
});
|
|
258
295
|
await relay.load();
|
|
259
|
-
|
|
296
|
+
const blackBox = createBlackBox({
|
|
297
|
+
dir: home.dir,
|
|
298
|
+
now: () => Date.now(),
|
|
299
|
+
setTimer: (fn, ms) => setTimeout(fn, ms).unref(),
|
|
300
|
+
clearTimer: (handle) => clearTimeout(handle),
|
|
301
|
+
path: env.PATH,
|
|
302
|
+
log: log.child('black box'),
|
|
303
|
+
});
|
|
304
|
+
/** What the parts of the server tell the Director's inbox goes to the targets of Relay too; a trip and a poll result go to the Black Box. */
|
|
260
305
|
const tell = (kind, text) => {
|
|
261
306
|
downlink.post(kind, text);
|
|
262
307
|
relay.event(kind, text);
|
|
308
|
+
if (kind === 'redline')
|
|
309
|
+
blackBox.record('redline', tripText(text));
|
|
310
|
+
else if (kind === 'tminus')
|
|
311
|
+
blackBox.record('poll', pollText(text));
|
|
263
312
|
};
|
|
264
313
|
let seq = home.lastMessageSeq();
|
|
265
314
|
// arrow functions on purpose: nothing here relies on `this` of the object it came from
|
|
@@ -290,8 +339,16 @@ export async function startGonogo(options = {}) {
|
|
|
290
339
|
logMessage: (r) => home.appendMessage(r),
|
|
291
340
|
renameAgentFiles: async (oldName, newName) => {
|
|
292
341
|
await launcher.renameAgentFiles(oldName, newName);
|
|
342
|
+
try {
|
|
343
|
+
await clearance.rename(oldName, newName);
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
await launcher.renameAgentFiles(newName, oldName).catch(() => undefined);
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
293
349
|
terminalHost.rename(oldName, newName);
|
|
294
350
|
},
|
|
351
|
+
keys: clearance,
|
|
295
352
|
spawn: async (req) => {
|
|
296
353
|
const prepared = await launcher.prepareStart(req.agent, { generation: req.generation, flag: req.flag });
|
|
297
354
|
try {
|
|
@@ -330,6 +387,7 @@ export async function startGonogo(options = {}) {
|
|
|
330
387
|
}
|
|
331
388
|
});
|
|
332
389
|
},
|
|
390
|
+
toolHook: (name, event, payload) => telemetry.hook(name, event, payload),
|
|
333
391
|
screen: (name) => terminalHost.screen(name),
|
|
334
392
|
title: (name) => terminalHost.title(name),
|
|
335
393
|
outputBytes: (name) => terminalHost.outputBytes(name),
|
|
@@ -383,7 +441,7 @@ export async function startGonogo(options = {}) {
|
|
|
383
441
|
inbound: relay,
|
|
384
442
|
log: log.child('uplink'),
|
|
385
443
|
});
|
|
386
|
-
const tasks = createTasks({
|
|
444
|
+
const tasks = audited(createTasks({
|
|
387
445
|
dir: home.dir,
|
|
388
446
|
now: io.now,
|
|
389
447
|
isAgent: (name) => hubInstance.views().some((v) => v.name === name),
|
|
@@ -395,7 +453,7 @@ export async function startGonogo(options = {}) {
|
|
|
395
453
|
emit: (list) => web?.broadcast({ t: 'tasks', tasks: list }),
|
|
396
454
|
notify: tell,
|
|
397
455
|
log: log.child('flight plan'),
|
|
398
|
-
});
|
|
456
|
+
}), blackBox.record, TASKS_AUDIT);
|
|
399
457
|
const docking = createDocking({
|
|
400
458
|
dir: home.dir,
|
|
401
459
|
name: stationName(env[STATION_ENV], hostname()),
|
|
@@ -414,6 +472,13 @@ export async function startGonogo(options = {}) {
|
|
|
414
472
|
emit: (frame) => web?.broadcast(frame),
|
|
415
473
|
log: log.child('mission log'),
|
|
416
474
|
});
|
|
475
|
+
const board = createBoard({ dir: home.dir, now: io.now });
|
|
476
|
+
const massBudget = createMassBudget({
|
|
477
|
+
memoryPath: (name) => launcher.memoryPath(name),
|
|
478
|
+
agent: (name) => hubInstance.views().find((v) => v.name === name),
|
|
479
|
+
send: (request) => hubInstance.sendFromUser(request),
|
|
480
|
+
log: log.child('mass budget'),
|
|
481
|
+
});
|
|
417
482
|
const liveries = createLiveries({
|
|
418
483
|
dir: home.dir,
|
|
419
484
|
send: (request) => hubInstance.sendFromUser(request),
|
|
@@ -421,26 +486,64 @@ export async function startGonogo(options = {}) {
|
|
|
421
486
|
notify: tell,
|
|
422
487
|
log: log.child('livery'),
|
|
423
488
|
});
|
|
489
|
+
const roots = createRoots({
|
|
490
|
+
home: home.dir,
|
|
491
|
+
agent: (name) => {
|
|
492
|
+
const view = hubInstance.views().find((v) => v.name === name);
|
|
493
|
+
return view === undefined ? null : { dir: view.dir, cleanRoom: view.cleanRoom !== null };
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
const relief = createRelief({
|
|
497
|
+
hub: hubInstance,
|
|
498
|
+
checkDirectory: io.checkDirectory,
|
|
499
|
+
now: io.now,
|
|
500
|
+
setTimer: io.setTimer,
|
|
501
|
+
clearTimer: io.clearTimer,
|
|
502
|
+
emit: (frame) => web?.broadcast(frame),
|
|
503
|
+
notify: tell,
|
|
504
|
+
log: log.child('relief'),
|
|
505
|
+
});
|
|
506
|
+
const rollout = createRollout({
|
|
507
|
+
dir: home.dir,
|
|
508
|
+
now: io.now,
|
|
509
|
+
fetch: options.fetch ?? ((url, init) => fetch(url, init)),
|
|
510
|
+
enabled: options.updateCheck === true,
|
|
511
|
+
current: version,
|
|
512
|
+
command: installInfo().command,
|
|
513
|
+
emit: (view) => web?.broadcast({ t: 'rollout', rollout: view }),
|
|
514
|
+
log: log.child('rollout'),
|
|
515
|
+
});
|
|
516
|
+
await rollout.load();
|
|
424
517
|
const webServer = createWebServer({
|
|
425
518
|
host,
|
|
426
519
|
port,
|
|
427
520
|
browserToken: home.browserToken,
|
|
428
521
|
allowedHosts,
|
|
429
522
|
staticDir,
|
|
430
|
-
|
|
523
|
+
// what the Director does through the browser is told to the Black Box by these copies
|
|
524
|
+
hub: audited(hubInstance, blackBox.record, HUB_AUDIT),
|
|
431
525
|
terminals: terminalHost,
|
|
432
526
|
resolveToken: (token) => launcher.resolveToken(token),
|
|
433
527
|
info,
|
|
434
528
|
isReady: () => ready,
|
|
435
|
-
propellant,
|
|
436
|
-
|
|
437
|
-
|
|
529
|
+
propellant: audited(propellant, blackBox.record, PROPELLANT_AUDIT),
|
|
530
|
+
telemetry,
|
|
531
|
+
schedules: audited(schedules, blackBox.record, SCHEDULES_AUDIT),
|
|
532
|
+
uplinks: audited(uplinks, blackBox.record, UPLINKS_AUDIT),
|
|
438
533
|
tasks,
|
|
439
534
|
downlink,
|
|
440
535
|
missionLog,
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
536
|
+
massBudget,
|
|
537
|
+
board: audited(board, blackBox.record, BOARD_AUDIT),
|
|
538
|
+
blackBox,
|
|
539
|
+
liveries: audited(liveries, blackBox.record, LIVERIES_AUDIT),
|
|
540
|
+
relay: audited(relay, blackBox.record, RELAY_AUDIT),
|
|
541
|
+
docking: audited(docking, blackBox.record, DOCKING_AUDIT),
|
|
542
|
+
relief,
|
|
543
|
+
rollout,
|
|
544
|
+
engines: () => checkEngines(env),
|
|
545
|
+
hangar: createHangar(roots),
|
|
546
|
+
recorder: createRecorder(roots, env),
|
|
444
547
|
log: log.child('web'),
|
|
445
548
|
});
|
|
446
549
|
web = webServer;
|
|
@@ -458,6 +561,9 @@ export async function startGonogo(options = {}) {
|
|
|
458
561
|
// before the hub starts any agent: a task_create that came first would take an id of the file and lose that task
|
|
459
562
|
await tasks.load();
|
|
460
563
|
await missionLog.load();
|
|
564
|
+
await board.load();
|
|
565
|
+
await blackBox.load();
|
|
566
|
+
blackBox.record('audit', `gonogo ${version} started`);
|
|
461
567
|
await liveries.load();
|
|
462
568
|
await docking.load();
|
|
463
569
|
hubStarting = true;
|
|
@@ -466,6 +572,7 @@ export async function startGonogo(options = {}) {
|
|
|
466
572
|
await uplinks.load();
|
|
467
573
|
ready = true;
|
|
468
574
|
docking.start();
|
|
575
|
+
rollout.start();
|
|
469
576
|
let stopping;
|
|
470
577
|
const step = async (what, run) => {
|
|
471
578
|
try {
|
|
@@ -486,10 +593,17 @@ export async function startGonogo(options = {}) {
|
|
|
486
593
|
await step('uplinks close', () => uplinks.close());
|
|
487
594
|
await step('tasks close', () => tasks.close());
|
|
488
595
|
await step('mission log close', () => missionLog.close());
|
|
596
|
+
await step('board close', () => board.close());
|
|
597
|
+
blackBox.record('audit', 'gonogo stopped');
|
|
598
|
+
await step('black box close', () => blackBox.close());
|
|
489
599
|
await step('livery close', () => liveries.close());
|
|
600
|
+
await step('relief close', async () => relief.close());
|
|
490
601
|
await step('relay close', () => relay.close());
|
|
491
602
|
await step('downlink close', () => downlink.close());
|
|
492
603
|
await step('propellant close', () => propellant.close());
|
|
604
|
+
await step('telemetry close', () => telemetry.close());
|
|
605
|
+
await step('rollout close', () => rollout.close());
|
|
606
|
+
await step('clearance close', () => clearance.close());
|
|
493
607
|
await step('home close', () => home.close());
|
|
494
608
|
};
|
|
495
609
|
const stop = () => {
|
|
@@ -603,6 +717,25 @@ export async function main(argv, env = process.env) {
|
|
|
603
717
|
}
|
|
604
718
|
if (parsed.kind === 'version') {
|
|
605
719
|
process.stdout.write(`gonogo ${packageVersion()}\n`);
|
|
720
|
+
// From the file the last check left, never from the network; nothing when the check is off.
|
|
721
|
+
const latest = updateCheckOff(env.GONOGO_UPDATE_CHECK) || argv.includes('--no-update-check') ? null : cachedLatest(homeOf(env));
|
|
722
|
+
if (latest !== null && isNewer(latest, packageVersion()))
|
|
723
|
+
process.stdout.write(`${latest} is out. To update, run: gonogo update\n`);
|
|
724
|
+
exit(0);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
if (parsed.kind === 'doctor') {
|
|
728
|
+
const checks = await checkEngines(env);
|
|
729
|
+
process.stdout.write(formatDoctor(checks, env.GONOGO_AGENT_CMD?.trim() || null));
|
|
730
|
+
// the same refusal as the start: no claude and nothing in its place
|
|
731
|
+
exit(checks.find((c) => c.provider === 'claude')?.path === null && !env.GONOGO_AGENT_CMD?.trim() ? 1 : 0);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (parsed.kind === 'update') {
|
|
735
|
+
const current = packageVersion();
|
|
736
|
+
const latest = cachedLatest(homeOf(env));
|
|
737
|
+
const { command, docker } = installInfo();
|
|
738
|
+
process.stdout.write(updateText(command, docker, { current, latest, newer: latest !== null && isNewer(latest, current) }));
|
|
606
739
|
exit(0);
|
|
607
740
|
return;
|
|
608
741
|
}
|
|
@@ -616,7 +749,7 @@ export async function main(argv, env = process.env) {
|
|
|
616
749
|
// shortcut: a signal during the start-up (about a second) takes Node's default and ends the process at once; the ptys hang up on their children and the next start replaces the stale lock
|
|
617
750
|
let running;
|
|
618
751
|
try {
|
|
619
|
-
running = await startGonogo({ ...parsed.options, env, log });
|
|
752
|
+
running = await startGonogo({ ...parsed.options, updateCheck: parsed.options.updateCheck ?? !updateCheckOff(env.GONOGO_UPDATE_CHECK), env, log });
|
|
620
753
|
}
|
|
621
754
|
catch (e) {
|
|
622
755
|
process.stderr.write(`gonogo: ${e instanceof Error ? e.message : String(e)}\n`);
|