@ulm0/gonogo 0.1.1 → 0.2.0
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-DxUnpGbS.js +52 -0
- package/dist/client/assets/index-tpcmltjw.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/audited.js +156 -0
- package/dist/server/blackbox.js +261 -0
- package/dist/server/board.js +123 -0
- package/dist/server/cleanroom.js +7 -51
- package/dist/server/clearance.js +158 -0
- package/dist/server/cli.js +229 -28
- package/dist/server/constants.js +54 -3
- package/dist/server/hangar.js +311 -0
- package/dist/server/home.js +41 -2
- package/dist/server/hub.js +280 -29
- package/dist/server/launcher.js +25 -13
- package/dist/server/logchart.js +58 -0
- package/dist/server/massbudget.js +169 -0
- package/dist/server/mcp.js +73 -2
- package/dist/server/migrate.js +7 -3
- package/dist/server/missionlog.js +2 -0
- package/dist/server/missions.js +310 -0
- package/dist/server/models.js +73 -0
- package/dist/server/phone.js +122 -0
- package/dist/server/phonetag.js +47 -0
- package/dist/server/prices.js +112 -0
- package/dist/server/propellant.js +243 -16
- package/dist/server/providers.js +123 -9
- package/dist/server/recorder.js +176 -0
- package/dist/server/relay.js +53 -7
- package/dist/server/relaykinds.js +11 -1
- package/dist/server/relief.js +226 -0
- package/dist/server/remotecontrol.js +15 -0
- package/dist/server/rollout.js +172 -0
- package/dist/server/tasks.js +44 -8
- package/dist/server/telemetry.js +110 -0
- package/dist/server/uplinks.js +7 -0
- package/dist/server/web.js +310 -10
- package/dist/server/worktree.js +137 -0
- package/dist/shared/fuel.js +8 -0
- package/dist/shared/livery.js +1 -1
- package/dist/shared/positions.js +1 -1
- package/dist/shared/prices.js +75 -0
- package/dist/shared/protocol.js +61 -15
- package/package.json +1 -1
- package/dist/client/assets/index-B6MsSoeo.css +0 -1
- package/dist/client/assets/index-DRtiRh1Y.js +0 -31
package/dist/server/hub.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { DOING_MAX_CHARS, HISTORY_MAX, HISTORY_WINDOW_MS, HOOK_EVENTS, PERMISSION_MODES, POLL_VOTES, PROVIDERS, providerInfo, RESERVED_NAMES, STATION_NAME_PATTERN, } from '../shared/protocol.js';
|
|
1
|
+
import { DOING_MAX_CHARS, HISTORY_MAX, HISTORY_WINDOW_MS, HOLD_REASON, HOOK_EVENTS, MODEL_PATTERN, PERMISSION_MODES, POLL_VOTES, PROVIDERS, providerInfo, RESERVED_NAMES, STATIC_FIRE_POSITIONS, STATION_NAME_PATTERN, } from '../shared/protocol.js';
|
|
2
2
|
import { POSITION_IDS } from '../shared/positions.js';
|
|
3
3
|
import { ACTIVITY_BACKLOG, ACTIVITY_HUB_MAX, ACTIVITY_WIRE_BODY_CHARS, AGENT_NAME_PATTERN, BODY_MAX_CHARS, BOSS_DEFAULT_NAME, BOSS_ROLE, COMMAND_MAX_CHARS, CUSTOM_ACTIVE_MS, CUSTOM_START_MS, DELIVERY_COALESCE_MS, DELIVERY_SETTLE_MS, DIR_MAX_CHARS, DRAFT_EXPIRY_MS, DRAFT_SCREEN_CLEAR_MS, MAILBOX_MAX_BODY_CHARS, MAILBOX_MAX_MESSAGES, MAX_AGENTS, MAX_STOP_BLOCKS, METER_INTERVAL_MS, NEEDS_YOU_CLEAR_MS, PASTE_END, PERMISSION_SUMMARY_CHARS, POINTER_MAX_ATTEMPTS, POINTER_MAX_SENDERS, POLL_REASON_MAX_CHARS, PROMPT_SUBMIT_CONFIRM_MS, READ_MAX_CHARS, READ_MAX_MESSAGES, RECONCILE_TICK_MS, REDLINE_API_ERROR_WINDOW_MS, REDLINE_API_ERRORS, REDLINE_REPEATS, REDLINE_SEND_WINDOW_MS, REDLINE_SENDS_TO_ONE, REDLINE_TOOL_FAILURE_WINDOW_MS, REDLINE_TOOL_FAILURES, ROLE_MAX_CHARS, ROSTER_ROLE_CHARS, SCREEN_DIALOG_REASON, SEND_RATE_MAX, SEND_RATE_WINDOW_MS, SESSION_FLIP_WINDOW_MS, SESSION_IN_USE_TEXT, SESSION_MISSING_TEXT, STARTUP_DIALOG_REASON, STARTUP_READY_TIMEOUT_MS, STARTUP_RECHECK_MS, SUBJECT_MAX_CHARS, TITLE_IDLE_RECONCILE_MS, TITLE_WORKING_CONFIRM_MS, } from './constants.js';
|
|
4
4
|
import { parseCleanRoom } from './cleanroom.js';
|
|
5
|
+
import { parseWorktree } from './worktree.js';
|
|
6
|
+
import { parseRemoteControl } from './remotecontrol.js';
|
|
7
|
+
import { checkKeys } from './clearance.js';
|
|
5
8
|
import { parsePayload, payloadRefusal } from './payload.js';
|
|
6
9
|
/** Every request the hub rejects is one of these; web.ts maps `code` to the HTTP status (contract 3.3). */
|
|
7
10
|
export class HubError extends Error {
|
|
@@ -22,8 +25,15 @@ const NAME_RE = new RegExp(AGENT_NAME_PATTERN);
|
|
|
22
25
|
const STATION_RE = new RegExp(STATION_NAME_PATTERN);
|
|
23
26
|
/** The payload of a record as text, for comparing: null when it has none. */
|
|
24
27
|
const payloadKey = (record) => (record.payload === undefined ? null : JSON.stringify(record.payload));
|
|
28
|
+
/** The Remote Control setting of a record as text, for comparing. */
|
|
29
|
+
const remoteKey = (record) => (record.remoteControl === undefined ? null : JSON.stringify(record.remoteControl));
|
|
25
30
|
/** The Clean Room setting of a record as text, for comparing: null when the agent runs on the host. */
|
|
26
31
|
const cleanRoomKey = (record) => (record.cleanRoom === undefined ? null : JSON.stringify(record.cleanRoom));
|
|
32
|
+
/** The worktree setting of a record as text, for comparing: null when the agent starts in its own folder. */
|
|
33
|
+
const worktreeKey = (record) => (record.worktree === undefined ? null : JSON.stringify(record.worktree));
|
|
34
|
+
/** The model and the keys (names and times) of a record as text, for comparing: a key set again has a new time, so a changed value shows as dirty too. */
|
|
35
|
+
const engineKey = (record) => JSON.stringify([record.model ?? null, record.keys ?? null]);
|
|
36
|
+
const MODEL_RE = new RegExp(MODEL_PATTERN);
|
|
27
37
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
28
38
|
const REPLY_ID_RE = /^m\d+$/;
|
|
29
39
|
const REPLY_ID_MAX_CHARS = 40;
|
|
@@ -296,6 +306,7 @@ export function createHub(io, options) {
|
|
|
296
306
|
doing: null,
|
|
297
307
|
needsKind: null,
|
|
298
308
|
needsReason: null,
|
|
309
|
+
needSeq: 0,
|
|
299
310
|
generation: 0,
|
|
300
311
|
ready: false,
|
|
301
312
|
transition: null,
|
|
@@ -367,6 +378,7 @@ export function createHub(io, options) {
|
|
|
367
378
|
stateSince: rt.stateSince,
|
|
368
379
|
needsKind: rt.needsKind,
|
|
369
380
|
needsReason: rt.needsReason,
|
|
381
|
+
needSeq: rt.needsKind === 'permission' ? rt.needSeq : null,
|
|
370
382
|
transition: rt.transition,
|
|
371
383
|
draft: rt.draft !== null,
|
|
372
384
|
held: heldInfo(rt),
|
|
@@ -378,7 +390,10 @@ export function createHub(io, options) {
|
|
|
378
390
|
running.mode !== record.mode ||
|
|
379
391
|
running.command !== (record.command ?? null) ||
|
|
380
392
|
running.payload !== payloadKey(record) ||
|
|
381
|
-
running.cleanRoom !== cleanRoomKey(record)
|
|
393
|
+
running.cleanRoom !== cleanRoomKey(record) ||
|
|
394
|
+
running.worktree !== worktreeKey(record) ||
|
|
395
|
+
running.remoteControl !== remoteKey(record) ||
|
|
396
|
+
running.engine !== engineKey(record)),
|
|
382
397
|
generation: rt.generation,
|
|
383
398
|
exit: rt.exit ? { ...rt.exit } : null,
|
|
384
399
|
position: record.position ?? null,
|
|
@@ -386,6 +401,10 @@ export function createHub(io, options) {
|
|
|
386
401
|
command: record.command ?? null,
|
|
387
402
|
payload: record.payload ?? null,
|
|
388
403
|
cleanRoom: record.cleanRoom ?? null,
|
|
404
|
+
worktree: record.worktree ?? null,
|
|
405
|
+
remoteControl: record.remoteControl ?? null,
|
|
406
|
+
model: record.model ?? null,
|
|
407
|
+
keys: { ...record.keys },
|
|
389
408
|
doing: rt.doing,
|
|
390
409
|
history: trimHistory(rt.history, io.now()),
|
|
391
410
|
};
|
|
@@ -584,7 +603,7 @@ export function createHub(io, options) {
|
|
|
584
603
|
return `held: text in ${rt.record.name}'s input`;
|
|
585
604
|
}
|
|
586
605
|
function redlineNote(rt) {
|
|
587
|
-
return `held: redline on ${rt.record.name}`;
|
|
606
|
+
return rt.redline === HOLD_REASON ? `held: ${rt.record.name} is on hold` : `held: redline on ${rt.record.name}`;
|
|
588
607
|
}
|
|
589
608
|
function holdNote(rt) {
|
|
590
609
|
if (rt.redline !== null)
|
|
@@ -770,12 +789,21 @@ export function createHub(io, options) {
|
|
|
770
789
|
function answer(name, request) {
|
|
771
790
|
assertOpen();
|
|
772
791
|
const rt = lookup(name);
|
|
773
|
-
const
|
|
792
|
+
const asked = asObject(request, 'the request');
|
|
793
|
+
const go = asked.go;
|
|
774
794
|
if (typeof go !== 'boolean')
|
|
775
795
|
throw new HubError('bad_request', 'go must be true or false', 'go');
|
|
796
|
+
const { needSeq } = asked;
|
|
797
|
+
if (needSeq !== undefined && (typeof needSeq !== 'number' || !Number.isSafeInteger(needSeq) || needSeq < 0)) {
|
|
798
|
+
throw new HubError('bad_request', 'needSeq must be a whole number', 'needSeq');
|
|
799
|
+
}
|
|
776
800
|
if (rt.state !== 'needs_you' || rt.needsKind !== 'permission' || rt.transition !== null) {
|
|
777
801
|
throw new HubError('conflict', `${rt.record.name} is not asking for a go`);
|
|
778
802
|
}
|
|
803
|
+
// an answer from a phone for a dialog that was answered or replaced since: nothing is typed
|
|
804
|
+
if (needSeq !== undefined && needSeq !== rt.needSeq) {
|
|
805
|
+
throw new HubError('conflict', `${rt.record.name} is asking about something else now: that dialog was answered or replaced`, 'needSeq');
|
|
806
|
+
}
|
|
779
807
|
if (!io.press?.(rt.record.name, rt.generation, go ? '\r' : '\x1b')) {
|
|
780
808
|
throw new HubError('conflict', `could not reach the terminal of ${rt.record.name}`);
|
|
781
809
|
}
|
|
@@ -798,19 +826,23 @@ export function createHub(io, options) {
|
|
|
798
826
|
rt.apiErrorAt = [];
|
|
799
827
|
rt.sentTo.clear();
|
|
800
828
|
}
|
|
801
|
-
/** Trips the breaker: Escape interrupts a turn in progress, the state reads needs_you and the mail waits. */
|
|
802
|
-
function tripRt(rt, reason) {
|
|
829
|
+
/** Trips the breaker: Escape interrupts a turn in progress, the state reads needs_you and the mail waits. A Hold is a trip the Director asked for. */
|
|
830
|
+
function tripRt(rt, reason, byHand = false) {
|
|
803
831
|
if (rt.redline !== null || rt.removed || !hooked(rt) || rt.state === 'stopped' || rt.transition !== null)
|
|
804
832
|
return;
|
|
805
833
|
const wasWorking = rt.state === 'working';
|
|
806
|
-
rt.redline = `redline: ${reason}`;
|
|
807
|
-
|
|
834
|
+
rt.redline = byHand ? HOLD_REASON : `redline: ${reason}`;
|
|
835
|
+
if (byHand)
|
|
836
|
+
log.info(`${rt.record.name} is on hold`);
|
|
837
|
+
else
|
|
838
|
+
log.warn(`${rt.record.name} tripped the redline: ${reason}`);
|
|
808
839
|
if (wasWorking && !io.press?.(rt.record.name, rt.generation, ESC)) {
|
|
809
840
|
log.warn(`could not interrupt ${rt.record.name}`);
|
|
810
841
|
}
|
|
811
842
|
setState(rt, 'needs_you');
|
|
812
843
|
syncHolds(rt);
|
|
813
|
-
|
|
844
|
+
if (!byHand)
|
|
845
|
+
io.notify?.('redline', `${rt.record.name}: ${reason}`);
|
|
814
846
|
}
|
|
815
847
|
/** The automatic detectors trip only when they are on; a Propellant limit trips through Hub.trip either way. */
|
|
816
848
|
function detect(rt, reason) {
|
|
@@ -834,6 +866,22 @@ export function createHub(io, options) {
|
|
|
834
866
|
tripRt(rt, reason);
|
|
835
867
|
flush(rt);
|
|
836
868
|
}
|
|
869
|
+
function hold(name) {
|
|
870
|
+
assertOpen();
|
|
871
|
+
const rt = lookup(name);
|
|
872
|
+
const who = rt.record.name;
|
|
873
|
+
if (!hooked(rt))
|
|
874
|
+
throw new HubError('conflict', `${who} reports no hooks, so gonogo cannot hold it`);
|
|
875
|
+
if (rt.redline !== null)
|
|
876
|
+
throw new HubError('conflict', rt.redline === HOLD_REASON ? `${who} is already on hold` : `${who} has tripped the redline: resume or stop it`);
|
|
877
|
+
if (rt.state === 'needs_you' && rt.transition === null)
|
|
878
|
+
throw new HubError('conflict', `${who} needs you: answer it first`);
|
|
879
|
+
if ((rt.state !== 'idle' && rt.state !== 'working') || rt.transition !== null)
|
|
880
|
+
throw new HubError('conflict', `${who} is not running`);
|
|
881
|
+
tripRt(rt, HOLD_REASON, true);
|
|
882
|
+
flush(rt);
|
|
883
|
+
return buildView(rt);
|
|
884
|
+
}
|
|
837
885
|
function resume(name) {
|
|
838
886
|
assertOpen();
|
|
839
887
|
const rt = lookup(name);
|
|
@@ -848,6 +896,15 @@ export function createHub(io, options) {
|
|
|
848
896
|
flush(rt);
|
|
849
897
|
return buildView(rt);
|
|
850
898
|
}
|
|
899
|
+
/** Telemetry: every tool hook goes to the recorder; a failure there never touches the hub's own handling. */
|
|
900
|
+
function toolHook(rt, event, payload) {
|
|
901
|
+
try {
|
|
902
|
+
io.toolHook?.(rt.record.name, event, payload);
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
log.warn('telemetry failed', error);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
851
908
|
/** Propellant reads the transcript at most every METER_INTERVAL_MS on a tool hook, and at every Stop. */
|
|
852
909
|
function meter(rt, payload, force) {
|
|
853
910
|
const path = payload.transcript_path;
|
|
@@ -985,26 +1042,35 @@ export function createHub(io, options) {
|
|
|
985
1042
|
onPromptSubmit(rt, payload);
|
|
986
1043
|
break;
|
|
987
1044
|
case 'PreToolUse':
|
|
1045
|
+
toolHook(rt, input.event, payload);
|
|
988
1046
|
rt.doing = describeDoing(payload.tool_name, payload.tool_input);
|
|
989
1047
|
onToolHook(rt);
|
|
990
1048
|
detect(rt, repeatReason(rt, payload));
|
|
991
1049
|
meter(rt, payload, false);
|
|
992
1050
|
break;
|
|
993
1051
|
case 'PostToolUse':
|
|
1052
|
+
toolHook(rt, input.event, payload);
|
|
994
1053
|
onToolHook(rt);
|
|
995
1054
|
break;
|
|
996
1055
|
case 'PostToolUseFailure':
|
|
1056
|
+
toolHook(rt, input.event, payload);
|
|
997
1057
|
onToolHook(rt);
|
|
998
1058
|
if (countRecent(rt.toolFailAt, io.now(), REDLINE_TOOL_FAILURE_WINDOW_MS) >= REDLINE_TOOL_FAILURES) {
|
|
999
1059
|
detect(rt, `error storm: ${rt.toolFailAt.length} failed tool calls in 2 min`);
|
|
1000
1060
|
}
|
|
1001
1061
|
break;
|
|
1002
|
-
case 'PermissionRequest':
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1062
|
+
case 'PermissionRequest': {
|
|
1063
|
+
const reason = describePermission(payload.tool_name, payload.tool_input);
|
|
1064
|
+
// the same dialog twice (a repeated hook) is one dialog: no new number, no new event
|
|
1065
|
+
const repeated = rt.state === 'needs_you' && rt.needsKind === 'permission' && rt.needsReason === reason;
|
|
1066
|
+
if (!repeated)
|
|
1067
|
+
rt.needSeq += 1;
|
|
1068
|
+
setState(rt, 'needs_you', { kind: 'permission', reason });
|
|
1069
|
+
// one event for each dialog, unless a Hold or a trip has taken over the state (that one is not a dialog the Director can answer)
|
|
1070
|
+
if (!repeated && rt.needsKind === 'permission')
|
|
1071
|
+
io.notify?.('permission', `${rt.record.name} asks: ${reason.slice(PERMISSION_PREFIX.length)}`, { kind: 'permission', agent: rt.record.name, seq: rt.needSeq });
|
|
1007
1072
|
break;
|
|
1073
|
+
}
|
|
1008
1074
|
case 'Notification':
|
|
1009
1075
|
onNotification(rt, payload);
|
|
1010
1076
|
break;
|
|
@@ -1404,7 +1470,7 @@ export function createHub(io, options) {
|
|
|
1404
1470
|
rt.pointed.clear();
|
|
1405
1471
|
rt.screenClearSince = null;
|
|
1406
1472
|
rt.lastBlockAt = null;
|
|
1407
|
-
rt.running = { role: rt.record.role, dir: rt.record.dir, mode: rt.record.mode, command: rt.record.command ?? null, payload: payloadKey(rt.record), cleanRoom: cleanRoomKey(rt.record) };
|
|
1473
|
+
rt.running = { role: rt.record.role, dir: rt.record.dir, mode: rt.record.mode, command: rt.record.command ?? null, payload: payloadKey(rt.record), cleanRoom: cleanRoomKey(rt.record), worktree: worktreeKey(rt.record), remoteControl: remoteKey(rt.record), engine: engineKey(rt.record) };
|
|
1408
1474
|
rt.flag = flag;
|
|
1409
1475
|
// The browser reacts to a new generation by attaching, so the frame waits until the process exists in the terminal host.
|
|
1410
1476
|
rt.frameHold = true;
|
|
@@ -1522,6 +1588,12 @@ export function createHub(io, options) {
|
|
|
1522
1588
|
settlePoll();
|
|
1523
1589
|
publishPoll();
|
|
1524
1590
|
}
|
|
1591
|
+
try {
|
|
1592
|
+
await io.keys?.remove(rt.record.name);
|
|
1593
|
+
}
|
|
1594
|
+
catch (error) {
|
|
1595
|
+
log.warn(`could not remove the keys of ${rt.record.name}`, error);
|
|
1596
|
+
}
|
|
1525
1597
|
// The process is gone (stopped above, or never ran): the terminal's mirror and scrollback can go too.
|
|
1526
1598
|
try {
|
|
1527
1599
|
io.forget?.(rt.record.name);
|
|
@@ -1612,6 +1684,48 @@ export function createHub(io, options) {
|
|
|
1612
1684
|
delete target.cleanRoom;
|
|
1613
1685
|
else
|
|
1614
1686
|
target.cleanRoom = from.cleanRoom;
|
|
1687
|
+
if (from.worktree === undefined)
|
|
1688
|
+
delete target.worktree;
|
|
1689
|
+
else
|
|
1690
|
+
target.worktree = from.worktree;
|
|
1691
|
+
if (from.remoteControl === undefined)
|
|
1692
|
+
delete target.remoteControl;
|
|
1693
|
+
else
|
|
1694
|
+
target.remoteControl = from.remoteControl;
|
|
1695
|
+
if (from.model === undefined)
|
|
1696
|
+
delete target.model;
|
|
1697
|
+
else
|
|
1698
|
+
target.model = from.model;
|
|
1699
|
+
if (from.keys === undefined)
|
|
1700
|
+
delete target.keys;
|
|
1701
|
+
else
|
|
1702
|
+
target.keys = from.keys;
|
|
1703
|
+
}
|
|
1704
|
+
/** The model for `--model`: empty text is none. Only an engine that takes one (PROVIDER_INFO.model). A bad value is 400, field model. */
|
|
1705
|
+
function checkModel(provider, value) {
|
|
1706
|
+
if (value === undefined || value === null)
|
|
1707
|
+
return undefined;
|
|
1708
|
+
if (typeof value !== 'string')
|
|
1709
|
+
throw new HubError('bad_request', 'model must be text', 'model');
|
|
1710
|
+
const model = value.trim();
|
|
1711
|
+
if (model === '')
|
|
1712
|
+
return undefined;
|
|
1713
|
+
if (providerInfo(provider).model === null) {
|
|
1714
|
+
throw new HubError('bad_request', `${providerInfo(provider).label} takes no model setting`, 'model');
|
|
1715
|
+
}
|
|
1716
|
+
if (!MODEL_RE.test(model)) {
|
|
1717
|
+
throw new HubError('bad_request', 'model must be 1 to 100 letters, digits or . _ : / @ + -, starting with a letter or digit', 'model');
|
|
1718
|
+
}
|
|
1719
|
+
return model;
|
|
1720
|
+
}
|
|
1721
|
+
/** The keys of a request: their values to the key store and their names with times for the record. A bad one is 400, field keys. */
|
|
1722
|
+
function checkKeysOf(value, current, hireRequest) {
|
|
1723
|
+
const checked = checkKeys(value, current, io.now(), hireRequest);
|
|
1724
|
+
if (!checked.ok)
|
|
1725
|
+
throw new HubError('bad_request', checked.error, 'keys');
|
|
1726
|
+
if (io.keys === undefined && Object.keys(checked.patch).length > 0)
|
|
1727
|
+
throw new HubError('bad_request', 'this server cannot keep keys', 'keys');
|
|
1728
|
+
return { patch: checked.patch, names: Object.keys(checked.names).length === 0 ? undefined : checked.names };
|
|
1615
1729
|
}
|
|
1616
1730
|
/** The shape of a payload and whether the engine takes it (no disk). A bad value is 400 with the field it names. */
|
|
1617
1731
|
function checkPayload(provider, value) {
|
|
@@ -1623,6 +1737,32 @@ export function createHub(io, options) {
|
|
|
1623
1737
|
throw new HubError('bad_request', refused.error, refused.field);
|
|
1624
1738
|
return checked.payload;
|
|
1625
1739
|
}
|
|
1740
|
+
/** A Remote Control setting: an object, Claude Code only, not with a Clean Room. A bad one is 400, field remoteControl. */
|
|
1741
|
+
function checkRemoteControl(provider, value, cleanRoom) {
|
|
1742
|
+
const checked = parseRemoteControl(value, provider, cleanRoom);
|
|
1743
|
+
if (!checked.ok)
|
|
1744
|
+
throw new HubError('bad_request', checked.error, 'remoteControl');
|
|
1745
|
+
return checked.remoteControl;
|
|
1746
|
+
}
|
|
1747
|
+
/** A worktree setting: an object, not together with a Clean Room (which has one), and `dir` in a git repository. A bad one is 400, field worktree. */
|
|
1748
|
+
async function checkWorktree(value, dir, cleanRoom) {
|
|
1749
|
+
const checked = parseWorktree(value);
|
|
1750
|
+
if (!checked.ok)
|
|
1751
|
+
throw new HubError('bad_request', checked.error, 'worktree');
|
|
1752
|
+
if (cleanRoom !== undefined && cleanRoom !== null)
|
|
1753
|
+
throw new HubError('bad_request', 'a Clean Room agent has a worktree already: use one of the two', 'worktree');
|
|
1754
|
+
let problem;
|
|
1755
|
+
try {
|
|
1756
|
+
problem = (await io.checkWorktree?.(dir)) ?? null;
|
|
1757
|
+
}
|
|
1758
|
+
catch (error) {
|
|
1759
|
+
log.error('worktree check failed', error);
|
|
1760
|
+
problem = errorMessage(error);
|
|
1761
|
+
}
|
|
1762
|
+
if (problem !== null)
|
|
1763
|
+
throw new HubError('bad_request', problem, 'worktree');
|
|
1764
|
+
return checked.worktree;
|
|
1765
|
+
}
|
|
1626
1766
|
/** A Clean Room setting: Claude Code only, a good image, and (when the check exists) Docker answers and `dir` is in a git repository. A bad one is 400, field cleanRoom. */
|
|
1627
1767
|
async function checkCleanRoom(provider, value, dir) {
|
|
1628
1768
|
const checked = parseCleanRoom(value, provider);
|
|
@@ -1703,6 +1843,8 @@ export function createHub(io, options) {
|
|
|
1703
1843
|
}
|
|
1704
1844
|
const command = custom ? checkCommand(req.command) : undefined;
|
|
1705
1845
|
const payload = checkPayload(provider, req.payload);
|
|
1846
|
+
const model = checkModel(provider, req.model);
|
|
1847
|
+
const kept = req.keys === undefined ? undefined : checkKeysOf(req.keys, undefined, true);
|
|
1706
1848
|
// A CLI without permission modes (a custom command among them): the mode and confirmBypass of the request are ignored.
|
|
1707
1849
|
const mode = providerInfo(provider).modes ? checkMode(req.mode) : 'default';
|
|
1708
1850
|
// The name is claimed while the checks and the save await, so two hires cannot take the same name or the same desk.
|
|
@@ -1716,6 +1858,8 @@ export function createHub(io, options) {
|
|
|
1716
1858
|
}
|
|
1717
1859
|
await checkSkills(payload);
|
|
1718
1860
|
const cleanRoom = req.cleanRoom === undefined ? undefined : await checkCleanRoom(provider, req.cleanRoom, dir);
|
|
1861
|
+
const worktree = req.worktree === undefined ? undefined : await checkWorktree(req.worktree, dir, req.cleanRoom);
|
|
1862
|
+
const remoteControl = req.remoteControl === undefined ? undefined : checkRemoteControl(provider, req.remoteControl, cleanRoom !== undefined);
|
|
1719
1863
|
assertOpen();
|
|
1720
1864
|
const record = {
|
|
1721
1865
|
name,
|
|
@@ -1735,8 +1879,24 @@ export function createHub(io, options) {
|
|
|
1735
1879
|
record.payload = payload;
|
|
1736
1880
|
if (cleanRoom)
|
|
1737
1881
|
record.cleanRoom = cleanRoom;
|
|
1882
|
+
if (worktree)
|
|
1883
|
+
record.worktree = worktree;
|
|
1884
|
+
if (remoteControl)
|
|
1885
|
+
record.remoteControl = remoteControl;
|
|
1886
|
+
if (model)
|
|
1887
|
+
record.model = model;
|
|
1888
|
+
if (kept?.names)
|
|
1889
|
+
record.keys = kept.names;
|
|
1738
1890
|
hiring.set(name, record);
|
|
1739
|
-
|
|
1891
|
+
// The values first, from none (a removed agent of this name may have left some), then the roster; a roster that cannot be saved takes them back.
|
|
1892
|
+
await io.keys?.apply(name, kept?.patch ?? {}, true);
|
|
1893
|
+
try {
|
|
1894
|
+
await saveRecords(rosterRecords());
|
|
1895
|
+
}
|
|
1896
|
+
catch (error) {
|
|
1897
|
+
await io.keys?.remove(name).catch(() => undefined);
|
|
1898
|
+
throw error;
|
|
1899
|
+
}
|
|
1740
1900
|
hired = makeRt(record);
|
|
1741
1901
|
agents.set(name, hired);
|
|
1742
1902
|
}
|
|
@@ -1755,13 +1915,14 @@ export function createHub(io, options) {
|
|
|
1755
1915
|
if (rt.removed)
|
|
1756
1916
|
throw new HubError('not_found', 'unknown agent');
|
|
1757
1917
|
const req = asObject(request, 'the request');
|
|
1758
|
-
const fields = ['name', 'role', 'dir', 'mode', 'confirmBypass', 'position', 'command', 'payload', 'cleanRoom'];
|
|
1918
|
+
const fields = ['name', 'role', 'dir', 'mode', 'confirmBypass', 'position', 'command', 'payload', 'cleanRoom', 'worktree', 'remoteControl', 'model', 'keys'];
|
|
1759
1919
|
if (!fields.some((field) => req[field] !== undefined)) {
|
|
1760
|
-
throw new HubError('bad_request', 'nothing to change: send at least one of name, role, dir, mode, position, command, payload, cleanRoom');
|
|
1920
|
+
throw new HubError('bad_request', 'nothing to change: send at least one of name, role, dir, mode, position, command, payload, cleanRoom, worktree, remoteControl, model, keys');
|
|
1761
1921
|
}
|
|
1762
1922
|
const current = rt.record;
|
|
1763
1923
|
const next = { ...current };
|
|
1764
1924
|
let newName = null;
|
|
1925
|
+
let keyPatch = null;
|
|
1765
1926
|
try {
|
|
1766
1927
|
if (req.name !== undefined) {
|
|
1767
1928
|
const name = checkName(req.name);
|
|
@@ -1769,6 +1930,9 @@ export function createHub(io, options) {
|
|
|
1769
1930
|
if (current.cleanRoom !== undefined && req.cleanRoom !== null) {
|
|
1770
1931
|
throw new HubError('conflict', 'a Clean Room console cannot be renamed: its worktree and branch carry its name (turn Clean Room off to rename it)', 'name');
|
|
1771
1932
|
}
|
|
1933
|
+
if (current.worktree !== undefined && req.worktree !== null) {
|
|
1934
|
+
throw new HubError('conflict', 'a console with a worktree cannot be renamed: its worktree and branch carry its name (turn the worktree off to rename it)', 'name');
|
|
1935
|
+
}
|
|
1772
1936
|
if (agents.has(name) || claimedNames.has(name)) {
|
|
1773
1937
|
throw new HubError('conflict', `an agent named "${name}" already exists`, 'name');
|
|
1774
1938
|
}
|
|
@@ -1805,6 +1969,40 @@ export function createHub(io, options) {
|
|
|
1805
1969
|
else
|
|
1806
1970
|
next.cleanRoom = await checkCleanRoom(current.provider ?? 'claude', req.cleanRoom, next.dir);
|
|
1807
1971
|
}
|
|
1972
|
+
if (req.worktree !== undefined) {
|
|
1973
|
+
if (req.worktree === null)
|
|
1974
|
+
delete next.worktree;
|
|
1975
|
+
else
|
|
1976
|
+
next.worktree = await checkWorktree(req.worktree, next.dir, next.cleanRoom);
|
|
1977
|
+
}
|
|
1978
|
+
else if (next.worktree !== undefined && (req.dir !== undefined || req.cleanRoom !== undefined)) {
|
|
1979
|
+
// a new folder must be in a repository, and a Clean Room has a worktree of its own
|
|
1980
|
+
next.worktree = await checkWorktree(next.worktree, next.dir, next.cleanRoom);
|
|
1981
|
+
}
|
|
1982
|
+
if (req.remoteControl !== undefined) {
|
|
1983
|
+
if (req.remoteControl === null)
|
|
1984
|
+
delete next.remoteControl;
|
|
1985
|
+
else
|
|
1986
|
+
next.remoteControl = checkRemoteControl(current.provider ?? 'claude', req.remoteControl, next.cleanRoom !== undefined);
|
|
1987
|
+
}
|
|
1988
|
+
else if (next.remoteControl !== undefined && next.cleanRoom !== undefined && req.cleanRoom !== undefined) {
|
|
1989
|
+
throw new HubError('bad_request', 'a Clean Room agent cannot use Remote Control: turn Remote Control off first', 'cleanRoom');
|
|
1990
|
+
}
|
|
1991
|
+
if (req.model !== undefined) {
|
|
1992
|
+
const model = checkModel(current.provider ?? 'claude', req.model);
|
|
1993
|
+
if (model)
|
|
1994
|
+
next.model = model;
|
|
1995
|
+
else
|
|
1996
|
+
delete next.model;
|
|
1997
|
+
}
|
|
1998
|
+
if (req.keys !== undefined) {
|
|
1999
|
+
const kept = checkKeysOf(req.keys, current.keys, false);
|
|
2000
|
+
keyPatch = kept.patch;
|
|
2001
|
+
if (kept.names)
|
|
2002
|
+
next.keys = kept.names;
|
|
2003
|
+
else
|
|
2004
|
+
delete next.keys;
|
|
2005
|
+
}
|
|
1808
2006
|
if (next.mode === 'bypassPermissions' && next.mode !== current.mode && req.confirmBypass !== true) {
|
|
1809
2007
|
throw new HubError('bad_request', 'bypassPermissions needs confirmBypass: true', 'confirmBypass');
|
|
1810
2008
|
}
|
|
@@ -1822,7 +2020,10 @@ export function createHub(io, options) {
|
|
|
1822
2020
|
next.position !== current.position ||
|
|
1823
2021
|
next.command !== current.command ||
|
|
1824
2022
|
payloadKey(next) !== payloadKey(current) ||
|
|
1825
|
-
cleanRoomKey(next) !== cleanRoomKey(current)
|
|
2023
|
+
cleanRoomKey(next) !== cleanRoomKey(current) ||
|
|
2024
|
+
worktreeKey(next) !== worktreeKey(current) ||
|
|
2025
|
+
remoteKey(next) !== remoteKey(current) ||
|
|
2026
|
+
engineKey(next) !== engineKey(current);
|
|
1826
2027
|
if (!changed)
|
|
1827
2028
|
return buildView(rt);
|
|
1828
2029
|
const oldName = current.name;
|
|
@@ -1843,10 +2044,19 @@ export function createHub(io, options) {
|
|
|
1843
2044
|
agents.set(newName, rt);
|
|
1844
2045
|
renamePollEntry(oldName, newName);
|
|
1845
2046
|
}
|
|
2047
|
+
// What the keys the edit touches hold now, as a patch that puts them back: a key that was not there goes again (null).
|
|
2048
|
+
const held = io.keys?.values(next.name) ?? {};
|
|
2049
|
+
const putBack = Object.fromEntries(Object.keys(keyPatch ?? {}).map((key) => [key, held[key] ?? null]));
|
|
1846
2050
|
try {
|
|
2051
|
+
if (keyPatch !== null && Object.keys(keyPatch).length > 0)
|
|
2052
|
+
await io.keys?.apply(next.name, keyPatch);
|
|
1847
2053
|
await saveRecords(rosterRecords());
|
|
1848
2054
|
}
|
|
1849
2055
|
catch (error) {
|
|
2056
|
+
// The values were written before the roster; they go back first, while the keys are still under the new name.
|
|
2057
|
+
// shortcut: when this write fails as well, the new values stay and the log says so; upgrade if disk errors matter.
|
|
2058
|
+
if (Object.keys(putBack).length > 0)
|
|
2059
|
+
await io.keys?.apply(next.name, putBack).catch((undo) => log.error('could not put the keys back', undo));
|
|
1850
2060
|
assignFields(current, previous);
|
|
1851
2061
|
if (newName !== null) {
|
|
1852
2062
|
agents.delete(newName);
|
|
@@ -2183,25 +2393,35 @@ export function createHub(io, options) {
|
|
|
2183
2393
|
emit({ t: 'poll', poll: pollView() });
|
|
2184
2394
|
// The inbox hears each result once: a later vote that leaves the status as it is says nothing new.
|
|
2185
2395
|
const result = pollState === null || pollState.status === 'open' ? '' : `${pollState.id}:${pollState.status}`;
|
|
2186
|
-
if (pollState !== null && result !== '' && result !== pollResult)
|
|
2187
|
-
|
|
2396
|
+
if (pollState !== null && result !== '' && result !== pollResult) {
|
|
2397
|
+
const line = `${pollState.status.toUpperCase()}: ${pollState.note}`;
|
|
2398
|
+
// A static fire is about the answers: they go to the inbox with the result.
|
|
2399
|
+
const answers = pollState.entries.flatMap((entry) => (entry.reason !== '' ? [`${entry.agent}: ${entry.reason}`] : []));
|
|
2400
|
+
io.notify?.('tminus', pollState.subject === undefined ? line : [`Static fire on ${pollState.subject}: ${line}`, ...answers].join(' · '));
|
|
2401
|
+
}
|
|
2188
2402
|
pollResult = result;
|
|
2189
2403
|
}
|
|
2190
2404
|
function tellFromUser(to, subject, body) {
|
|
2191
2405
|
sendFromUser({ to, subject, body });
|
|
2192
2406
|
}
|
|
2193
|
-
/**
|
|
2407
|
+
/**
|
|
2408
|
+
* An open poll ends in hold at the first no-go and in go when everybody voted go (and then the boss is told). A static fire
|
|
2409
|
+
* waits for every answer (the break report and the rollback plan both matter) and tells nobody: the Director reads the result.
|
|
2410
|
+
*/
|
|
2194
2411
|
function settlePoll() {
|
|
2195
2412
|
const poll = pollState;
|
|
2196
2413
|
if (!poll || (poll.status !== 'open' && !(poll.status === 'hold' && holdBy === 'vote')))
|
|
2197
2414
|
return;
|
|
2198
|
-
if (poll.entries.some((entry) => entry.vote ===
|
|
2415
|
+
if (poll.subject !== undefined && poll.entries.some((entry) => entry.vote === null)) {
|
|
2416
|
+
poll.status = 'open';
|
|
2417
|
+
}
|
|
2418
|
+
else if (poll.entries.some((entry) => entry.vote === 'no-go')) {
|
|
2199
2419
|
poll.status = 'hold';
|
|
2200
2420
|
holdBy = 'vote';
|
|
2201
2421
|
}
|
|
2202
2422
|
else if (poll.entries.length > 0 && poll.entries.every((entry) => entry.vote === 'go')) {
|
|
2203
2423
|
poll.status = 'go';
|
|
2204
|
-
const boss = bossRt();
|
|
2424
|
+
const boss = poll.subject === undefined ? bossRt() : undefined;
|
|
2205
2425
|
if (boss)
|
|
2206
2426
|
tellFromUser(boss.record.name, 'T-minus: all go', 'Every polled position is go. Proceed.');
|
|
2207
2427
|
}
|
|
@@ -2255,9 +2475,12 @@ export function createHub(io, options) {
|
|
|
2255
2475
|
const req = asObject(request, 'the request');
|
|
2256
2476
|
if (pollState !== null)
|
|
2257
2477
|
throw new HubError('conflict', 'clear the poll first');
|
|
2258
|
-
const
|
|
2478
|
+
const subject = staticFireSubject(req);
|
|
2479
|
+
const targets = subject === undefined
|
|
2480
|
+
? pollTargets(req.agents)
|
|
2481
|
+
: pollTargets(undefined).filter((rt) => STATIC_FIRE_POSITIONS.includes(rt.record.position ?? ''));
|
|
2259
2482
|
if (targets.length === 0)
|
|
2260
|
-
throw new HubError('bad_request', 'nobody to poll');
|
|
2483
|
+
throw new HubError('bad_request', subject === undefined ? 'nobody to poll' : 'no SIMSUP or RETRO is running');
|
|
2261
2484
|
pollSeq += 1;
|
|
2262
2485
|
pollState = {
|
|
2263
2486
|
id: pollSeq,
|
|
@@ -2265,15 +2488,38 @@ export function createHub(io, options) {
|
|
|
2265
2488
|
status: 'open',
|
|
2266
2489
|
entries: targets.map((rt) => ({ agent: rt.record.name, vote: null, reason: '', at: null })),
|
|
2267
2490
|
note: '',
|
|
2491
|
+
...(subject === undefined ? {} : { subject }),
|
|
2268
2492
|
};
|
|
2269
2493
|
for (const rt of targets) {
|
|
2270
|
-
|
|
2494
|
+
if (subject === undefined) {
|
|
2495
|
+
tellFromUser(rt.record.name, 'T-minus: go/no-go poll', 'The Director is polling for go or no-go. Call go_nogo with your vote and a one-sentence reason.');
|
|
2496
|
+
}
|
|
2497
|
+
else if (rt.record.position === 'simsup') {
|
|
2498
|
+
tellFromUser(rt.record.name, `Static fire: ${subject}`, `Before this ships, try to break it: ${subject}. Then call go_nogo: go if it held, no-go with what broke in one sentence (write the steps to reproduce to the Mission Log).`);
|
|
2499
|
+
}
|
|
2500
|
+
else {
|
|
2501
|
+
tellFromUser(rt.record.name, `Static fire: ${subject}`, `Before this ships, write the rollback plan for: ${subject}. Put the plan in the Mission Log with log_write, then call go_nogo: go when it can be rolled back, no-go if it cannot, with a one-sentence reason.`);
|
|
2502
|
+
}
|
|
2271
2503
|
}
|
|
2272
2504
|
publishPoll();
|
|
2273
2505
|
return pollView();
|
|
2274
2506
|
}
|
|
2507
|
+
/** The subject of a static fire, one clean line; undefined for a T-minus poll. */
|
|
2508
|
+
function staticFireSubject(req) {
|
|
2509
|
+
if (req.subject === undefined)
|
|
2510
|
+
return undefined;
|
|
2511
|
+
if (req.agents !== undefined)
|
|
2512
|
+
throw new HubError('bad_request', 'a static fire picks SIMSUP and RETRO itself', 'agents');
|
|
2513
|
+
const max = SUBJECT_MAX_CHARS - 'Static fire: '.length;
|
|
2514
|
+
const subject = typeof req.subject === 'string' ? collapseWhitespace(req.subject.replace(UNSAFE_IN_REASON, ' ')) : '';
|
|
2515
|
+
if (subject === '' || subject.length > max)
|
|
2516
|
+
throw new HubError('bad_request', `subject must be text of 1 to ${max} characters`, 'subject');
|
|
2517
|
+
return subject;
|
|
2518
|
+
}
|
|
2275
2519
|
function holdPoll() {
|
|
2276
2520
|
assertOpen();
|
|
2521
|
+
if (pollState !== null && pollState.status === 'hold')
|
|
2522
|
+
throw new HubError('conflict', 'the poll is already on hold');
|
|
2277
2523
|
if (pollState === null || pollState.status !== 'open')
|
|
2278
2524
|
throw new HubError('conflict', 'no poll is open');
|
|
2279
2525
|
pollState.status = 'hold';
|
|
@@ -2288,8 +2534,12 @@ export function createHub(io, options) {
|
|
|
2288
2534
|
if (pollState.status !== 'aborted') {
|
|
2289
2535
|
pollState.status = 'aborted';
|
|
2290
2536
|
for (const entry of pollState.entries) {
|
|
2291
|
-
if (entry.vote !== 'no-go')
|
|
2292
|
-
|
|
2537
|
+
if (entry.vote !== 'no-go') {
|
|
2538
|
+
if (pollState.subject === undefined)
|
|
2539
|
+
tellFromUser(entry.agent, 'T-minus: aborted', 'The Director aborted the poll. Stand by.');
|
|
2540
|
+
else
|
|
2541
|
+
tellFromUser(entry.agent, 'Static fire: aborted', 'The Director aborted the static fire. Stand by.');
|
|
2542
|
+
}
|
|
2293
2543
|
}
|
|
2294
2544
|
publishPoll();
|
|
2295
2545
|
}
|
|
@@ -2465,6 +2715,7 @@ export function createHub(io, options) {
|
|
|
2465
2715
|
sendFromStation,
|
|
2466
2716
|
sendFromAgent,
|
|
2467
2717
|
trip,
|
|
2718
|
+
hold,
|
|
2468
2719
|
resume,
|
|
2469
2720
|
readMessages,
|
|
2470
2721
|
rosterFor,
|