@andorra-labs/code 0.1.16 → 0.1.17
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/dist/src/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-execution.js +11 -8
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +3 -0
- package/dist/src/agent-mcp.js +33 -1
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +19 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +89 -0
- package/dist/src/app-server/workspace.js +457 -11
- package/dist/src/app-server.d.ts +358 -32
- package/dist/src/app-server.js +2429 -509
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +347 -0
- package/dist/src/bridge/control.d.ts +68 -0
- package/dist/src/bridge/control.js +233 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +129 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +540 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/tokens.css +1 -1
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/cli.js +182 -32
- package/dist/src/coding-tools.js +15 -15
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +14 -11
- package/dist/src/commands.d.ts +14 -2
- package/dist/src/compaction-phrases.js +1 -1
- package/dist/src/completion.js +82 -5
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +202 -77
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/requestPhrases.js +0 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +349 -0
- package/dist/src/github-app/client.js +810 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-names.d.ts +8 -0
- package/dist/src/github-names.js +8 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +6 -1
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +46 -0
- package/dist/src/graph-preview.js +55 -0
- package/dist/src/graph-provider-portability.js +2 -1
- package/dist/src/graph-runner.js +64 -3
- package/dist/src/graph-server.js +3 -3
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +91 -7
- package/dist/src/graph-ui/icons.js +2 -1
- package/dist/src/graph-ui/studio.js +15 -1
- package/dist/src/graph-ui/tokens.css +1 -1
- package/dist/src/graphs.d.ts +34 -1
- package/dist/src/graphs.js +158 -14
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +10 -0
- package/dist/src/membership.js +19 -4
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +6 -0
- package/dist/src/model-metadata.js +35 -15
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +23 -2
- package/dist/src/providers.js +25 -4
- package/dist/src/pull-request-logs.d.ts +12 -1
- package/dist/src/pull-request-logs.js +14 -3
- package/dist/src/pull-requests.d.ts +327 -7
- package/dist/src/pull-requests.js +429 -51
- package/dist/src/react-runtime.js +1 -1
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +366 -89
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +7 -0
- package/dist/src/run-control.js +23 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +5 -1
- package/dist/src/runtime.js +10 -2
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +11 -1
- package/dist/src/sessions.js +17 -4
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/telemetry/emitter.d.ts +15 -0
- package/dist/src/telemetry/emitter.js +35 -1
- package/dist/src/telemetry/schema.d.ts +25 -2
- package/dist/src/telemetry/schema.js +52 -4
- package/dist/src/telemetry/surface.d.ts +2 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +7 -0
- package/dist/src/test-edit-guard.js +49 -1
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/tools.js +59 -9
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { ProviderRequestError, RetryableProviderError } from '../providers.js';
|
|
3
|
+
/** One model request's JSON payload may be this large; with its envelope it stays under the relay's 16 MiB frame. */
|
|
4
|
+
export const RELAY_PAYLOAD_LIMIT_BYTES = 12 * 1024 * 1024;
|
|
5
|
+
/** An unclaimed request is announced again this often, so a desktop that attaches later still sees it. */
|
|
6
|
+
export const RELAY_REANNOUNCE_MS = 5_000;
|
|
7
|
+
/** A claim with no progress for this long is released and the request is announced again. */
|
|
8
|
+
export const RELAY_CLAIM_SILENCE_MS = 45_000;
|
|
9
|
+
/** A request without a sign of life from a desktop for this long shows the run as awaiting-desktop. */
|
|
10
|
+
export const RELAY_AWAY_MS = 600_000;
|
|
11
|
+
/** One reasoning delta may be this large; a longer one is cut to whole characters that fit. */
|
|
12
|
+
export const RELAY_DELTA_LIMIT_BYTES = 64 * 1024;
|
|
13
|
+
export const RELAY_PAYLOAD_TOO_LARGE = 'This step\'s context is too large to send to your computer (limit 12 MiB).';
|
|
14
|
+
const CANCELLED = 'Provider request cancelled.';
|
|
15
|
+
/** The form a relayed failure's telemetry code must have. */
|
|
16
|
+
export const RELAY_FAILURE_CODE = /^[a-z0-9_]{1,64}$/;
|
|
17
|
+
function wirePayload(provider, request, sessionId) {
|
|
18
|
+
return {
|
|
19
|
+
model: request.model, messages: request.messages, tools: request.tools,
|
|
20
|
+
...(request.maxTokens === undefined ? {} : { maxTokens: request.maxTokens }),
|
|
21
|
+
...(request.mutableTail === undefined ? {} : { mutableTail: request.mutableTail }),
|
|
22
|
+
...(request.toolChoice === undefined ? {} : { toolChoice: request.toolChoice }),
|
|
23
|
+
...(request.context === undefined ? {} : { context: request.context }),
|
|
24
|
+
...(provider.reasoningEffort === undefined ? {} : { reasoningEffort: provider.reasoningEffort }),
|
|
25
|
+
...(sessionId === undefined ? {} : { sessionId }),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function readableToolCall(call) {
|
|
29
|
+
if (!call || typeof call !== 'object' || Array.isArray(call))
|
|
30
|
+
return false;
|
|
31
|
+
const value = call;
|
|
32
|
+
return typeof value.name === 'string' && typeof value.arguments === 'string' && (value.id === undefined || typeof value.id === 'string');
|
|
33
|
+
}
|
|
34
|
+
function readable(response) {
|
|
35
|
+
if (!response || typeof response !== 'object' || Array.isArray(response))
|
|
36
|
+
return false;
|
|
37
|
+
const value = response;
|
|
38
|
+
return typeof value.text === 'string' && Array.isArray(value.toolCalls) && value.toolCalls.every(readableToolCall);
|
|
39
|
+
}
|
|
40
|
+
/** `delta` cut to the whole characters that fit in RELAY_DELTA_LIMIT_BYTES. */
|
|
41
|
+
function boundedDelta(delta) {
|
|
42
|
+
if (Buffer.byteLength(delta) <= RELAY_DELTA_LIMIT_BYTES)
|
|
43
|
+
return delta;
|
|
44
|
+
return delta.slice(0, new TextEncoder().encodeInto(delta, new Uint8Array(RELAY_DELTA_LIMIT_BYTES)).read);
|
|
45
|
+
}
|
|
46
|
+
function failure(error) {
|
|
47
|
+
const message = typeof error?.message === 'string' && error.message.trim() ? error.message : 'The model request failed on your computer.';
|
|
48
|
+
const code = typeof error?.code === 'string' && RELAY_FAILURE_CODE.test(error.code) ? error.code : undefined;
|
|
49
|
+
let failed;
|
|
50
|
+
if (error?.kind === 'retryable')
|
|
51
|
+
failed = new RetryableProviderError(message);
|
|
52
|
+
else if (error?.kind === 'provider-request')
|
|
53
|
+
failed = new ProviderRequestError(message, error.contextOverflow === true);
|
|
54
|
+
else
|
|
55
|
+
return new Error(message);
|
|
56
|
+
if (code !== undefined)
|
|
57
|
+
failed.telemetryCode = code;
|
|
58
|
+
return failed;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The remote engine's half of the model relay: a relayed provider's `generate()` becomes a
|
|
62
|
+
* `model.relay.request` event that a desktop claims and answers with `model.relay.result`.
|
|
63
|
+
* A request never fails because no desktop is there; it waits, and the run shows awaiting-desktop.
|
|
64
|
+
*/
|
|
65
|
+
export class ModelRelayBroker {
|
|
66
|
+
deps;
|
|
67
|
+
pending = new Map();
|
|
68
|
+
timers;
|
|
69
|
+
constructor(deps) {
|
|
70
|
+
this.deps = deps;
|
|
71
|
+
this.timers = deps.timers ?? globalThis;
|
|
72
|
+
}
|
|
73
|
+
adapter(provider, runId, sessionId) {
|
|
74
|
+
return { generate: request => this.generate(provider, runId, request, sessionId) };
|
|
75
|
+
}
|
|
76
|
+
generate(provider, runId, request, sessionId) {
|
|
77
|
+
if (request.signal.aborted)
|
|
78
|
+
return Promise.reject(new Error(CANCELLED));
|
|
79
|
+
const payload = wirePayload(provider, request, sessionId);
|
|
80
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload));
|
|
81
|
+
if (bytes > RELAY_PAYLOAD_LIMIT_BYTES)
|
|
82
|
+
return Promise.reject(new Error(RELAY_PAYLOAD_TOO_LARGE));
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const entry = {
|
|
85
|
+
id: randomUUID(), runId, provider: provider.id, payload, bytes, request, away: false,
|
|
86
|
+
resolve: response => { this.finish(entry); resolve(response); },
|
|
87
|
+
reject: error => { this.finish(entry); reject(error); },
|
|
88
|
+
onAbort: () => {
|
|
89
|
+
if (!this.pending.has(entry.id))
|
|
90
|
+
return;
|
|
91
|
+
this.deps.emit('model.relay.cancel', { id: entry.id, runId });
|
|
92
|
+
entry.reject(new Error(CANCELLED));
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
this.pending.set(entry.id, entry);
|
|
96
|
+
request.signal.addEventListener('abort', entry.onAbort, { once: true });
|
|
97
|
+
this.touch(entry);
|
|
98
|
+
this.announce(entry);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** Takes a request for `claimant`; the payload is handed over only here, once the claim holds. */
|
|
102
|
+
claim(params) {
|
|
103
|
+
const entry = this.lookup(params.id, params.runId);
|
|
104
|
+
if (!entry || (entry.claimant !== undefined && entry.claimant !== params.claimant))
|
|
105
|
+
return { claimed: false };
|
|
106
|
+
if (entry.claimant === undefined) {
|
|
107
|
+
entry.claimant = params.claimant;
|
|
108
|
+
if (entry.announceTimer !== undefined) {
|
|
109
|
+
this.timers.clearInterval(entry.announceTimer);
|
|
110
|
+
entry.announceTimer = undefined;
|
|
111
|
+
}
|
|
112
|
+
entry.resumeBudget?.();
|
|
113
|
+
entry.resumeBudget = undefined;
|
|
114
|
+
}
|
|
115
|
+
this.touch(entry);
|
|
116
|
+
this.listen(entry);
|
|
117
|
+
return { claimed: true, payload: entry.payload };
|
|
118
|
+
}
|
|
119
|
+
progress(params) {
|
|
120
|
+
const entry = this.owned(params);
|
|
121
|
+
if (!entry)
|
|
122
|
+
return { ok: false };
|
|
123
|
+
this.touch(entry);
|
|
124
|
+
this.listen(entry);
|
|
125
|
+
const { request } = entry;
|
|
126
|
+
if (params.kind === 'request')
|
|
127
|
+
request.onRequest?.();
|
|
128
|
+
else if (params.kind === 'reasoning' && typeof params.delta === 'string')
|
|
129
|
+
request.onReasoning?.(boundedDelta(params.delta));
|
|
130
|
+
// A provider failure the desktop's adapter recovered from (a forced tool choice or streaming refused, then resent):
|
|
131
|
+
// only its telemetry code travels, in the form a relayed failure's code has.
|
|
132
|
+
else if (params.kind === 'recovered-error') {
|
|
133
|
+
if (typeof params.code === 'string' && RELAY_FAILURE_CODE.test(params.code))
|
|
134
|
+
request.onRecoveredError?.(params.code);
|
|
135
|
+
}
|
|
136
|
+
else if (params.kind === 'retry' && params.retry && typeof params.retry === 'object') {
|
|
137
|
+
// As with a local adapter, a retry listener that throws ends the call with its error.
|
|
138
|
+
Promise.resolve().then(() => request.onRetry?.(params.retry)).catch((error) => {
|
|
139
|
+
if (!this.pending.has(entry.id))
|
|
140
|
+
return;
|
|
141
|
+
this.deps.emit('model.relay.cancel', { id: entry.id, runId: entry.runId });
|
|
142
|
+
entry.reject(error instanceof Error ? error : new Error(String(error)));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return { ok: true };
|
|
146
|
+
}
|
|
147
|
+
result(params) {
|
|
148
|
+
const entry = this.owned(params);
|
|
149
|
+
if (!entry)
|
|
150
|
+
return { ok: false };
|
|
151
|
+
if (params.ok) {
|
|
152
|
+
if (readable(params.response))
|
|
153
|
+
entry.resolve(params.response);
|
|
154
|
+
else
|
|
155
|
+
entry.reject(new Error('Your computer sent a model reply this machine could not read.'));
|
|
156
|
+
}
|
|
157
|
+
else
|
|
158
|
+
entry.reject(failure(params.error));
|
|
159
|
+
return { ok: true };
|
|
160
|
+
}
|
|
161
|
+
/** Whether `runId` has a request no desktop has shown a sign of life for in RELAY_AWAY_MS. */
|
|
162
|
+
awaiting(runId) {
|
|
163
|
+
return [...this.pending.values()].some(entry => entry.runId === runId && entry.away);
|
|
164
|
+
}
|
|
165
|
+
/** Rejects every wait of `runId` as cancelled and tells the desktops to stop. */
|
|
166
|
+
endRun(runId) {
|
|
167
|
+
// The run is ending: its own final state follows, so its requests are not reported back to running.
|
|
168
|
+
for (const entry of [...this.pending.values()])
|
|
169
|
+
if (entry.runId === runId) {
|
|
170
|
+
entry.away = false;
|
|
171
|
+
entry.onAbort();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
close() {
|
|
175
|
+
for (const entry of [...this.pending.values()]) {
|
|
176
|
+
entry.away = false;
|
|
177
|
+
entry.reject(new Error(CANCELLED));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
lookup(id, runId) {
|
|
181
|
+
const entry = typeof id === 'string' ? this.pending.get(id) : undefined;
|
|
182
|
+
return entry && entry.runId === runId ? entry : undefined;
|
|
183
|
+
}
|
|
184
|
+
owned(params) {
|
|
185
|
+
const entry = this.lookup(params.id, params.runId);
|
|
186
|
+
return entry && entry.claimant !== undefined && entry.claimant === params.claimant ? entry : undefined;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Announces an unclaimed request now and every RELAY_REANNOUNCE_MS, holding the run's budgets meanwhile. The
|
|
190
|
+
* announce carries no payload, so repeating it costs little; the payload goes once, to the claim that holds.
|
|
191
|
+
*/
|
|
192
|
+
announce(entry) {
|
|
193
|
+
entry.resumeBudget ??= this.deps.suspendBudget(entry.runId);
|
|
194
|
+
const announced = { id: entry.id, runId: entry.runId, provider: entry.provider, model: entry.payload.model, bytes: entry.bytes };
|
|
195
|
+
const emit = () => this.deps.emit('model.relay.request', { ...announced });
|
|
196
|
+
emit();
|
|
197
|
+
entry.announceTimer = this.timers.setInterval(emit, RELAY_REANNOUNCE_MS);
|
|
198
|
+
entry.announceTimer.unref?.();
|
|
199
|
+
}
|
|
200
|
+
/** (Re)starts the claimant's silence clock; when it runs out the claim is released and the request announced again. */
|
|
201
|
+
listen(entry) {
|
|
202
|
+
if (entry.silenceTimer !== undefined)
|
|
203
|
+
this.timers.clearTimeout(entry.silenceTimer);
|
|
204
|
+
entry.silenceTimer = this.timers.setTimeout(() => {
|
|
205
|
+
entry.silenceTimer = undefined;
|
|
206
|
+
if (!this.pending.has(entry.id))
|
|
207
|
+
return;
|
|
208
|
+
entry.claimant = undefined;
|
|
209
|
+
this.announce(entry);
|
|
210
|
+
}, RELAY_CLAIM_SILENCE_MS);
|
|
211
|
+
entry.silenceTimer.unref?.();
|
|
212
|
+
}
|
|
213
|
+
/** A sign of life: restarts the away clock, and a returning desktop brings the run back to running. */
|
|
214
|
+
touch(entry) {
|
|
215
|
+
if (entry.awayTimer !== undefined)
|
|
216
|
+
this.timers.clearTimeout(entry.awayTimer);
|
|
217
|
+
if (entry.away && entry.claimant !== undefined) {
|
|
218
|
+
entry.away = false;
|
|
219
|
+
this.reportBack(entry.runId);
|
|
220
|
+
}
|
|
221
|
+
entry.awayTimer = this.timers.setTimeout(() => {
|
|
222
|
+
entry.awayTimer = undefined;
|
|
223
|
+
if (!this.pending.has(entry.id) || entry.away)
|
|
224
|
+
return;
|
|
225
|
+
const shown = [...this.pending.values()].some(other => other.runId === entry.runId && other.away);
|
|
226
|
+
entry.away = true;
|
|
227
|
+
if (!shown)
|
|
228
|
+
this.deps.setRunState(entry.runId, 'awaiting-desktop');
|
|
229
|
+
}, RELAY_AWAY_MS);
|
|
230
|
+
entry.awayTimer.unref?.();
|
|
231
|
+
}
|
|
232
|
+
reportBack(runId) {
|
|
233
|
+
if (![...this.pending.values()].some(other => other.runId === runId && other.away))
|
|
234
|
+
this.deps.setRunState(runId, 'running');
|
|
235
|
+
}
|
|
236
|
+
finish(entry) {
|
|
237
|
+
if (!this.pending.delete(entry.id))
|
|
238
|
+
return;
|
|
239
|
+
entry.request.signal.removeEventListener('abort', entry.onAbort);
|
|
240
|
+
if (entry.announceTimer !== undefined)
|
|
241
|
+
this.timers.clearInterval(entry.announceTimer);
|
|
242
|
+
if (entry.silenceTimer !== undefined)
|
|
243
|
+
this.timers.clearTimeout(entry.silenceTimer);
|
|
244
|
+
if (entry.awayTimer !== undefined)
|
|
245
|
+
this.timers.clearTimeout(entry.awayTimer);
|
|
246
|
+
entry.resumeBudget?.();
|
|
247
|
+
entry.resumeBudget = undefined;
|
|
248
|
+
// A request that ends while away (its node or branch was stopped) no longer keeps the run shown as awaiting-desktop.
|
|
249
|
+
if (entry.away)
|
|
250
|
+
this.reportBack(entry.runId);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** At most this many runs are remembered per machine; recording another drops the oldest. */
|
|
2
|
+
export declare const MODEL_RELAY_RUNS_LIMIT = 500;
|
|
3
|
+
/** By account subject, then by machine: the runs this computer started or resumed there, most recent last. */
|
|
4
|
+
export type ModelRelayRuns = Record<string, Record<string, string[]>>;
|
|
5
|
+
export declare function modelRelayRunsPath(home: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* The runs whose model requests this computer answers: those it started or resumed on a machine, per account, in
|
|
8
|
+
* `<home>/model-relay-runs.json`. Writes are serialized and go through a temporary file and a rename.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ModelRelayRunStore {
|
|
11
|
+
private readonly home;
|
|
12
|
+
private chain;
|
|
13
|
+
private cache;
|
|
14
|
+
/** How many times the file was read; it is read once and then kept. */
|
|
15
|
+
fileReads: number;
|
|
16
|
+
constructor(home: string);
|
|
17
|
+
/** Whether `subject` started or resumed `runId` on `env` from this computer. */
|
|
18
|
+
has(subject: string | undefined, env: string, runId: string): Promise<boolean>;
|
|
19
|
+
/** Records `runId` as started or resumed on `env` from this computer, as the most recent. */
|
|
20
|
+
record(subject: string, env: string, runId: string): Promise<void>;
|
|
21
|
+
/** Forgets every run of `env`, for every account: the machine was removed. */
|
|
22
|
+
forget(env: string): Promise<void>;
|
|
23
|
+
/** Forgets `subject`'s runs on each of `envs`: they left that account's list. */
|
|
24
|
+
forgetFor(subject: string, envs: Iterable<string>): Promise<void>;
|
|
25
|
+
/** Resolves once every write begun so far has finished. */
|
|
26
|
+
settled(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* The file's contents, read once and kept: only this process writes the file, and each write replaces the copy.
|
|
29
|
+
* A file that is missing is empty; one that cannot be read is read again next time.
|
|
30
|
+
*/
|
|
31
|
+
private read;
|
|
32
|
+
private load;
|
|
33
|
+
private change;
|
|
34
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
/** At most this many runs are remembered per machine; recording another drops the oldest. */
|
|
5
|
+
export const MODEL_RELAY_RUNS_LIMIT = 500;
|
|
6
|
+
const ENVIRONMENT_ID = /^env_[A-Za-z0-9_-]{22}$/;
|
|
7
|
+
const ACCOUNT_SUBJECT = /^[A-Za-z0-9-]{1,128}$/;
|
|
8
|
+
const MAX_RUN_ID = 128;
|
|
9
|
+
export function modelRelayRunsPath(home) {
|
|
10
|
+
return join(home, 'model-relay-runs.json');
|
|
11
|
+
}
|
|
12
|
+
function usableRun(runId) {
|
|
13
|
+
return typeof runId === 'string' && runId.length > 0 && runId.length <= MAX_RUN_ID;
|
|
14
|
+
}
|
|
15
|
+
/** The saved file, keeping only well-formed entries; a missing or unreadable file is empty. */
|
|
16
|
+
function parse(text) {
|
|
17
|
+
let value;
|
|
18
|
+
try {
|
|
19
|
+
value = JSON.parse(text);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const runs = {};
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
26
|
+
return runs;
|
|
27
|
+
for (const [subject, machines] of Object.entries(value)) {
|
|
28
|
+
if (!ACCOUNT_SUBJECT.test(subject) || !machines || typeof machines !== 'object' || Array.isArray(machines))
|
|
29
|
+
continue;
|
|
30
|
+
const kept = {};
|
|
31
|
+
for (const [env, ids] of Object.entries(machines)) {
|
|
32
|
+
if (!ENVIRONMENT_ID.test(env) || !Array.isArray(ids))
|
|
33
|
+
continue;
|
|
34
|
+
kept[env] = ids.filter(usableRun).slice(-MODEL_RELAY_RUNS_LIMIT);
|
|
35
|
+
}
|
|
36
|
+
runs[subject] = kept;
|
|
37
|
+
}
|
|
38
|
+
return runs;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The runs whose model requests this computer answers: those it started or resumed on a machine, per account, in
|
|
42
|
+
* `<home>/model-relay-runs.json`. Writes are serialized and go through a temporary file and a rename.
|
|
43
|
+
*/
|
|
44
|
+
export class ModelRelayRunStore {
|
|
45
|
+
home;
|
|
46
|
+
chain = Promise.resolve();
|
|
47
|
+
cache;
|
|
48
|
+
/** How many times the file was read; it is read once and then kept. */
|
|
49
|
+
fileReads = 0;
|
|
50
|
+
constructor(home) {
|
|
51
|
+
this.home = home;
|
|
52
|
+
}
|
|
53
|
+
/** Whether `subject` started or resumed `runId` on `env` from this computer. */
|
|
54
|
+
async has(subject, env, runId) {
|
|
55
|
+
if (subject === undefined)
|
|
56
|
+
return false;
|
|
57
|
+
const runs = await this.read();
|
|
58
|
+
return Object.hasOwn(runs, subject) && Object.hasOwn(runs[subject], env) && runs[subject][env].includes(runId);
|
|
59
|
+
}
|
|
60
|
+
/** Records `runId` as started or resumed on `env` from this computer, as the most recent. */
|
|
61
|
+
record(subject, env, runId) {
|
|
62
|
+
if (!ACCOUNT_SUBJECT.test(subject) || !ENVIRONMENT_ID.test(env) || !usableRun(runId))
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
return this.change(runs => {
|
|
65
|
+
const machines = Object.hasOwn(runs, subject) ? runs[subject] : (runs[subject] = {});
|
|
66
|
+
const list = (Object.hasOwn(machines, env) ? machines[env] : []).filter(id => id !== runId);
|
|
67
|
+
list.push(runId);
|
|
68
|
+
machines[env] = list.slice(-MODEL_RELAY_RUNS_LIMIT);
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Forgets every run of `env`, for every account: the machine was removed. */
|
|
73
|
+
forget(env) {
|
|
74
|
+
return this.change(runs => {
|
|
75
|
+
let changed = false;
|
|
76
|
+
for (const machines of Object.values(runs))
|
|
77
|
+
if (Object.hasOwn(machines, env)) {
|
|
78
|
+
delete machines[env];
|
|
79
|
+
changed = true;
|
|
80
|
+
}
|
|
81
|
+
return changed;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** Forgets `subject`'s runs on each of `envs`: they left that account's list. */
|
|
85
|
+
forgetFor(subject, envs) {
|
|
86
|
+
return this.change(runs => {
|
|
87
|
+
if (!Object.hasOwn(runs, subject))
|
|
88
|
+
return false;
|
|
89
|
+
let changed = false;
|
|
90
|
+
for (const env of envs)
|
|
91
|
+
if (Object.hasOwn(runs[subject], env)) {
|
|
92
|
+
delete runs[subject][env];
|
|
93
|
+
changed = true;
|
|
94
|
+
}
|
|
95
|
+
return changed;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Resolves once every write begun so far has finished. */
|
|
99
|
+
async settled() {
|
|
100
|
+
await this.chain.catch(() => undefined);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The file's contents, read once and kept: only this process writes the file, and each write replaces the copy.
|
|
104
|
+
* A file that is missing is empty; one that cannot be read is read again next time.
|
|
105
|
+
*/
|
|
106
|
+
async read() {
|
|
107
|
+
await this.chain.catch(() => undefined);
|
|
108
|
+
return this.load();
|
|
109
|
+
}
|
|
110
|
+
async load() {
|
|
111
|
+
if (this.cache !== undefined)
|
|
112
|
+
return this.cache;
|
|
113
|
+
this.fileReads += 1;
|
|
114
|
+
try {
|
|
115
|
+
this.cache = parse(await readFile(modelRelayRunsPath(this.home), 'utf8'));
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (error.code !== 'ENOENT')
|
|
119
|
+
return {};
|
|
120
|
+
this.cache = {};
|
|
121
|
+
}
|
|
122
|
+
return this.cache;
|
|
123
|
+
}
|
|
124
|
+
change(apply) {
|
|
125
|
+
const next = this.chain.catch(() => undefined).then(async () => {
|
|
126
|
+
const path = modelRelayRunsPath(this.home);
|
|
127
|
+
// A copy: the kept contents change only once the write has landed.
|
|
128
|
+
const runs = structuredClone(await this.load());
|
|
129
|
+
if (!apply(runs))
|
|
130
|
+
return;
|
|
131
|
+
await mkdir(dirname(path), { recursive: true });
|
|
132
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
133
|
+
try {
|
|
134
|
+
await writeFile(temporary, `${JSON.stringify(runs, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
135
|
+
await rename(temporary, path);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
this.cache = runs;
|
|
142
|
+
});
|
|
143
|
+
this.chain = next;
|
|
144
|
+
return next;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection ids a desktop engine opens for itself to answer a machine's model requests start with this. The
|
|
3
|
+
* machine's engine pool sends such a connection only `model.relay.*` events, and no replay of its runs.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MODEL_RELAY_CONNECTION_PREFIX = "relay-";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection ids a desktop engine opens for itself to answer a machine's model requests start with this. The
|
|
3
|
+
* machine's engine pool sends such a connection only `model.relay.*` events, and no replay of its runs.
|
|
4
|
+
*/
|
|
5
|
+
export const MODEL_RELAY_CONNECTION_PREFIX = 'relay-';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function addProjectEntry(path: string, options?: {
|
|
2
|
+
name?: string;
|
|
3
|
+
directory?: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function relinkProjectEntry(from: string, to: string, options?: {
|
|
6
|
+
name?: string;
|
|
7
|
+
directory?: string;
|
|
8
|
+
}): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* The id `path` answers to, storing `candidate` when it has none yet and returning whichever id is actually on the entry.
|
|
11
|
+
* Two tasks created at the same moment on a folder that has just been added would otherwise each store their own id, and
|
|
12
|
+
* the loser keeps an identity the registry never accepted, splitting the project's browser profiles for good.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ensureProjectIdentity(path: string, candidate: string, directory?: string): Promise<string | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Remembers the project id a folder answers to, so a task started after a rename or a
|
|
17
|
+
* merge belongs to the same project as the tasks that were already there.
|
|
18
|
+
* An id already on the entry wins: a second rename must not restart the project's identity.
|
|
19
|
+
*/
|
|
20
|
+
export declare function rememberProjectIdentity(path: string, id: string, directory?: string): Promise<void>;
|
|
21
|
+
export declare function removeProjectEntry(path: string, directory?: string): Promise<boolean>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { changeConfigFile, configDirectory } from './config.js';
|
|
2
|
+
// The local project registry (`projects` in config.json): the folders the sidebar lists and the identity each answers to.
|
|
3
|
+
export async function addProjectEntry(path, options = {}) {
|
|
4
|
+
const directory = options.directory ?? configDirectory();
|
|
5
|
+
const name = typeof options.name === 'string' && options.name.trim() ? options.name.trim().slice(0, 100) : undefined;
|
|
6
|
+
await changeConfigFile(directory, config => {
|
|
7
|
+
const projects = config.projects ?? [];
|
|
8
|
+
if (projects.some(project => project.path === path))
|
|
9
|
+
return config;
|
|
10
|
+
if (projects.length >= 256)
|
|
11
|
+
throw new Error('The project registry is full.');
|
|
12
|
+
return { ...config, projects: [...projects, { path, ...(name ? { name } : {}), addedAt: new Date().toISOString() }] };
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export async function relinkProjectEntry(from, to, options = {}) {
|
|
16
|
+
const directory = options.directory ?? configDirectory();
|
|
17
|
+
const name = typeof options.name === 'string' && options.name.trim() ? options.name.trim().slice(0, 100) : undefined;
|
|
18
|
+
let relinked = false;
|
|
19
|
+
await changeConfigFile(directory, config => {
|
|
20
|
+
const projects = config.projects ?? [];
|
|
21
|
+
if (!projects.some(project => project.path === from) || projects.some(project => project.path === to))
|
|
22
|
+
return config;
|
|
23
|
+
relinked = true;
|
|
24
|
+
return { ...config, projects: projects.map(project => {
|
|
25
|
+
if (project.path !== from)
|
|
26
|
+
return project;
|
|
27
|
+
const { name: _previous, ...kept } = project;
|
|
28
|
+
return { ...kept, path: to, ...(name ? { name } : {}) };
|
|
29
|
+
}) };
|
|
30
|
+
});
|
|
31
|
+
return relinked;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The id `path` answers to, storing `candidate` when it has none yet and returning whichever id is actually on the entry.
|
|
35
|
+
* Two tasks created at the same moment on a folder that has just been added would otherwise each store their own id, and
|
|
36
|
+
* the loser keeps an identity the registry never accepted, splitting the project's browser profiles for good.
|
|
37
|
+
*/
|
|
38
|
+
export async function ensureProjectIdentity(path, candidate, directory = configDirectory()) {
|
|
39
|
+
let id;
|
|
40
|
+
await changeConfigFile(directory, config => {
|
|
41
|
+
const projects = config.projects ?? [];
|
|
42
|
+
const entry = projects.find(project => project.path === path);
|
|
43
|
+
if (!entry)
|
|
44
|
+
return config;
|
|
45
|
+
if (typeof entry.id === 'string' && /^[a-f0-9]{16}$/.test(entry.id)) {
|
|
46
|
+
id = entry.id;
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
id = candidate;
|
|
50
|
+
return { ...config, projects: projects.map(project => (project === entry ? { ...project, id: candidate } : project)) };
|
|
51
|
+
});
|
|
52
|
+
return id;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Remembers the project id a folder answers to, so a task started after a rename or a
|
|
56
|
+
* merge belongs to the same project as the tasks that were already there.
|
|
57
|
+
* An id already on the entry wins: a second rename must not restart the project's identity.
|
|
58
|
+
*/
|
|
59
|
+
export async function rememberProjectIdentity(path, id, directory = configDirectory()) {
|
|
60
|
+
await changeConfigFile(directory, config => ({
|
|
61
|
+
...config,
|
|
62
|
+
projects: (config.projects ?? []).map(project => project.path === path && project.id === undefined ? { ...project, id } : project),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
export async function removeProjectEntry(path, directory = configDirectory()) {
|
|
66
|
+
let removed = false;
|
|
67
|
+
await changeConfigFile(directory, config => {
|
|
68
|
+
const projects = config.projects ?? [];
|
|
69
|
+
const kept = projects.filter(project => project.path !== path);
|
|
70
|
+
removed = kept.length !== projects.length;
|
|
71
|
+
return removed ? { ...config, projects: kept } : config;
|
|
72
|
+
});
|
|
73
|
+
return removed;
|
|
74
|
+
}
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import type { CommandScreenUI } from './command-screens.js';
|
|
2
|
-
import { type Config } from './config.js';
|
|
3
1
|
import { type ProviderConfig } from './providers.js';
|
|
4
|
-
import type { RemoteWorkspace } from './remote/types.js';
|
|
5
|
-
export declare const PEER_PROVIDER_EXPORT_CAPABILITY = "remote.providers.export";
|
|
6
2
|
export declare function normalizeExportedProvider(value: unknown): ProviderConfig | undefined;
|
|
7
3
|
export declare function normalizeExportedProviders(payload: unknown): {
|
|
8
4
|
providers: ProviderConfig[];
|
|
9
5
|
rejected: string[];
|
|
10
6
|
};
|
|
11
7
|
export declare function uniqueProviderId(taken: (id: string) => boolean, base: string): string;
|
|
12
|
-
export declare function reconcileImportedCodexAccount(incoming: ProviderConfig, existing: ProviderConfig | undefined, draft: readonly ProviderConfig[], saved: readonly ProviderConfig[]): ProviderConfig;
|
|
13
|
-
export interface PeerProviderExportResult {
|
|
14
|
-
providers: ProviderConfig[];
|
|
15
|
-
rejected: string[];
|
|
16
|
-
hostname: string;
|
|
17
|
-
}
|
|
18
|
-
export declare function fetchPeerProviderExport(workspace: RemoteWorkspace, signal?: AbortSignal): Promise<PeerProviderExportResult>;
|
|
19
|
-
export declare function importProvidersFromRemote(config: Config, ui: CommandScreenUI, signal: AbortSignal, fetch?: (workspace: RemoteWorkspace, loadSignal: AbortSignal) => Promise<PeerProviderExportResult>): Promise<Config | undefined>;
|