@andorra-labs/code 0.1.15 → 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-definitions.js +29 -6
- package/dist/src/agent-execution.js +15 -10
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +4 -1
- package/dist/src/agent-mcp.js +46 -10
- 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 +22 -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 +465 -32
- package/dist/src/app-server.js +3308 -517
- package/dist/src/auth/deployment.js +2 -2
- 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-runner.js +1 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +28 -17
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/claude-provider.js +3 -1
- package/dist/src/cli.js +202 -38
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/coding-tools.js +15 -15
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +19 -14
- package/dist/src/commands.d.ts +14 -1
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- 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/context-compaction.js +2 -1
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +22 -0
- 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-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -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 +13 -4
- 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 +34 -11
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +88 -10
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +11 -9
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +201 -40
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +3 -1
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +26 -5
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +28 -20
- package/dist/src/graphs.d.ts +34 -1
- package/dist/src/graphs.js +162 -17
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +30 -1
- package/dist/src/membership.js +48 -8
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +7 -1
- package/dist/src/model-metadata.js +39 -17
- 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/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.js +3 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +40 -2
- package/dist/src/providers.js +93 -23
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +87 -0
- package/dist/src/pull-request-logs.js +183 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +369 -8
- package/dist/src/pull-requests.js +524 -55
- package/dist/src/react-runtime.js +38 -5
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +379 -90
- 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 +17 -0
- package/dist/src/run-control.js +47 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +9 -1
- package/dist/src/runtime.js +24 -4
- 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/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +17 -0
- package/dist/src/telemetry/emitter.js +76 -5
- package/dist/src/telemetry/schema.d.ts +47 -2
- package/dist/src/telemetry/schema.js +120 -5
- package/dist/src/telemetry/surface.d.ts +3 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/telemetry/uploader.d.ts +6 -1
- package/dist/src/telemetry/uploader.js +22 -3
- 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/dist/src/transcript.js +8 -2
- package/dist/src/types.d.ts +7 -0
- package/dist/src/usage-analytics.js +18 -10
- 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
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import { join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
2
4
|
import { TEST_RUN_MARKER } from '../andorra/hosted.js';
|
|
3
5
|
import { AUTH_DEPLOYMENT } from '../auth/deployment.js';
|
|
4
6
|
import { enqueue, pruneGeneration, pruneOld, readSpool, rewriteSpool, spoolNames, sweepOutbox, withSpoolLock, withSpoolLockWait, } from './outbox.js';
|
|
@@ -9,13 +11,30 @@ import { uploadSignal } from './uploads.js';
|
|
|
9
11
|
* no endpoint unless the test names one, so a test that starts an engine against a throwaway home can never
|
|
10
12
|
* report to the production service as a new installation. Nothing a user's own tools set (Node's test-runner
|
|
11
13
|
* variables among them) switches reporting off.
|
|
14
|
+
*
|
|
15
|
+
* `ANDORRA_TELEMETRY_URL` names another endpoint for development only: it is read in a test run and in a build
|
|
16
|
+
* that runs from a source checkout, and an installed release ignores it and posts to the stamped endpoint.
|
|
12
17
|
*/
|
|
13
|
-
export function telemetryEndpoint(env = process.env) {
|
|
14
|
-
|
|
18
|
+
export function telemetryEndpoint(env = process.env, sourceCheckout = runsFromSourceCheckout()) {
|
|
19
|
+
const override = env[TEST_RUN_MARKER] || sourceCheckout ? env.ANDORRA_TELEMETRY_URL : undefined;
|
|
20
|
+
if (env[TEST_RUN_MARKER] && !override)
|
|
15
21
|
return undefined;
|
|
16
|
-
const configured =
|
|
22
|
+
const configured = override || AUTH_DEPLOYMENT.telemetryBaseUrl;
|
|
17
23
|
return configured ? configured.replace(/\/+$/, '') : undefined;
|
|
18
24
|
}
|
|
25
|
+
let sourceCheckout;
|
|
26
|
+
/** Whether this build sits in a git working tree (a `.git` entry beside package.json), which a published package never has. */
|
|
27
|
+
export function runsFromSourceCheckout() {
|
|
28
|
+
if (sourceCheckout === undefined) {
|
|
29
|
+
try {
|
|
30
|
+
sourceCheckout = existsSync(fileURLToPath(new URL('../../../.git', import.meta.url)));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
sourceCheckout = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return sourceCheckout;
|
|
37
|
+
}
|
|
19
38
|
const REQUEST_TIMEOUT_MS = 5_000;
|
|
20
39
|
async function post(endpoint, event, dependencies) {
|
|
21
40
|
let body;
|
|
@@ -229,6 +229,7 @@ export declare class TerminalUI extends EventEmitter {
|
|
|
229
229
|
conversationPrompt?: boolean;
|
|
230
230
|
history?: boolean;
|
|
231
231
|
secret?: boolean;
|
|
232
|
+
yieldToQuestions?: boolean;
|
|
232
233
|
}): Promise<string>;
|
|
233
234
|
chooseQuestion(prompt: string, items: TerminalChoice[], options?: {
|
|
234
235
|
kind?: 'question' | 'approval';
|
package/dist/src/terminal-ui.js
CHANGED
|
@@ -85,7 +85,7 @@ const submittedCommand = (value) => {
|
|
|
85
85
|
};
|
|
86
86
|
const workingCommandHint = (command) => `${command} doesn't run while a task is working. Run ${command} once this task has finished.`
|
|
87
87
|
+ (command === '/graph' ? ' Switching graphs clears the previous graph progress and starts fresh.' : '');
|
|
88
|
-
const liveRunCommands = ['/model', '/browser', '/attach', '/yolo', '/permissions', '/jev', '/help', '/status', '/usage', '/tools', '/exit', '/quit'];
|
|
88
|
+
const liveRunCommands = ['/model', '/providers', '/browser', '/attach', '/compact', '/yolo', '/permissions', '/jev', '/help', '/status', '/usage', '/tools', '/exit', '/quit'];
|
|
89
89
|
const paint = (text, color = GRAY) => typeof color === 'number'
|
|
90
90
|
? `\x1b[38;5;${color}m${text}\x1b[0m`
|
|
91
91
|
: `\x1b[${color}m${text}\x1b[0m`;
|
|
@@ -696,6 +696,13 @@ export class TerminalUI extends EventEmitter {
|
|
|
696
696
|
if (this.closed)
|
|
697
697
|
return Promise.reject(new Error('Terminal is closed'));
|
|
698
698
|
this.yieldScreen();
|
|
699
|
+
// A prompt that yields gives way to the run's question: the caller sees an AbortError and closes its screen.
|
|
700
|
+
if (this.pending && !options.yieldToQuestions) {
|
|
701
|
+
const held = this.pending;
|
|
702
|
+
if (!held.yieldToQuestions)
|
|
703
|
+
return Promise.reject(new Error('A terminal question is already active'));
|
|
704
|
+
held.abort?.();
|
|
705
|
+
}
|
|
699
706
|
if (this.pending)
|
|
700
707
|
return Promise.reject(new Error('A terminal question is already active'));
|
|
701
708
|
if (this.modal)
|
|
@@ -718,7 +725,7 @@ export class TerminalUI extends EventEmitter {
|
|
|
718
725
|
if (!regular)
|
|
719
726
|
this.print(label);
|
|
720
727
|
return new Promise((resolve, reject) => {
|
|
721
|
-
const pending = { kind: options.kind ?? 'question', resolve, reject, signal: options.signal, label: oneLine(label), title: options.title ? oneLine(options.title).trim() : undefined, regular, cancelOnEscape: options.cancelOnEscape, conversationPrompt: options.conversationPrompt === true, secret: options.secret, history: regular && options.history !== false && !options.secret };
|
|
728
|
+
const pending = { kind: options.kind ?? 'question', resolve, reject, signal: options.signal, label: oneLine(label), title: options.title ? oneLine(options.title).trim() : undefined, regular, cancelOnEscape: options.cancelOnEscape, conversationPrompt: options.conversationPrompt === true, secret: options.secret, history: regular && options.history !== false && !options.secret, yieldToQuestions: options.yieldToQuestions === true };
|
|
722
729
|
pending.abort = () => { if (this.pending !== pending)
|
|
723
730
|
return; this.finishQuestion(); reject(new DOMException('Question aborted', 'AbortError')); this.scheduleRender(); };
|
|
724
731
|
this.pending = pending;
|
|
@@ -731,7 +738,7 @@ export class TerminalUI extends EventEmitter {
|
|
|
731
738
|
if (!items.length || items.some(item => !item.id))
|
|
732
739
|
throw new Error('Question choices require nonempty IDs');
|
|
733
740
|
this.yieldScreen();
|
|
734
|
-
if (this.
|
|
741
|
+
if (this.modal || (this.pending && !this.pending.yieldToQuestions))
|
|
735
742
|
throw new Error('A terminal question or screen is already active');
|
|
736
743
|
const displayedPrompt = prompt === 'Choose an answer' ? this.dashboardNotices.at(-1) ?? prompt : prompt;
|
|
737
744
|
if (options.printPrompt !== false)
|
|
@@ -65,6 +65,13 @@ export declare class TestEditGuard {
|
|
|
65
65
|
* a file born after the run started was made by the run (through the shell, say) and is its own to change.
|
|
66
66
|
*/
|
|
67
67
|
noteToolMutation(target: string, existed: boolean, bornAtMs?: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* The modified test files whose change only adds new tests: no line of the starting commit's file was
|
|
70
|
+
* removed or replaced, and nothing added switches a test off or defines again a name the file already
|
|
71
|
+
* had. Appending a regression test to an existing test file is ordinary work, not a rewrite of the
|
|
72
|
+
* tests that constrain the fix. Any doubt (a Git failure, a file that is not test code) keeps the file flagged.
|
|
73
|
+
*/
|
|
74
|
+
private onlyAddsTests;
|
|
68
75
|
private current;
|
|
69
76
|
/**
|
|
70
77
|
* Returns the changed pre-existing test files when at least one of them has not been reported yet,
|
|
@@ -10,6 +10,14 @@ function within(root, target) {
|
|
|
10
10
|
const TEST_DIRECTORY = /(?:^|\/)(?:tests?|testing|__tests__|__snapshots__|baseline_images|testdata|test_data)\//i;
|
|
11
11
|
const TEST_FILE = /(?:^|\/)(?:test_[^/]*\.py|conftest\.py|[^/]+_test\.[^/]+|[^/]+\.(?:test|spec)\.[^/]+)$/i;
|
|
12
12
|
const ASKS_FOR_TEST_CHANGES = /\b(?:add|adds|adding|update|updates|updating|fix|fixes|fixing|change|changes|changing|modify|modifying|rewrite|rewriting|adjust|adjusting|extend|extending|refactor|refactoring|delete|deleting|remove|removing|rename|renaming|migrate|migrating|port|porting|regenerate|regenerating|write|writing)\b[^.!?\n]{0,60}\b(?:tests?|specs?|test suite|fixtures?|snapshots?|baselines?|conftest)\b/i;
|
|
13
|
+
/** Test source files, where an added line is a new test rather than new expected output. */
|
|
14
|
+
const ADDITIVE_TEST_CODE = /\.(?:py|[cm]?[jt]sx?|go|rs|java|kt|rb|php|cs|c|cc|cpp|h|hpp|swift|scala)$/i;
|
|
15
|
+
const FIXTURE_LOCATION = /(?:^|\/)(?:conftest\.py$|(?:__snapshots__|baseline_images|testdata|test_data|fixtures?)\/)/i;
|
|
16
|
+
/** An added line that can switch an existing test off, or narrow the run to some tests. */
|
|
17
|
+
const DISABLES_TESTS = /skip|xfail|expectedFailure|\bx(?:it|test|describe)\b|\.(?:only|todo|fixme)\b|\bf(?:it|describe)\b|collect_ignore|pytestmark|\bignore\b|\bdisabled?\b|\bpending\b/i;
|
|
18
|
+
/** A named definition; one that repeats a name already in the file replaces the earlier one in most languages. */
|
|
19
|
+
const DECLARATION = /^\s*(?:export\s+)?(?:public\s+|private\s+|protected\s+|static\s+|async\s+)*(?:def|class|func|function|fn|fun|void|module)\s+([A-Za-z_$][\w$]*)/;
|
|
20
|
+
const ADDITIVE_FILE_LIMIT = 40;
|
|
13
21
|
const GIT_TIMEOUT_MS = 5_000;
|
|
14
22
|
const HASH_FILE_LIMIT = 8 * 1024 * 1024;
|
|
15
23
|
const BASELINE_DIRTY_LIMIT = 2_000;
|
|
@@ -42,7 +50,7 @@ export function testEditNudge(edits, restoreFrom) {
|
|
|
42
50
|
: 'undo those edits';
|
|
43
51
|
return `Completion not accepted yet. ${edits.length === 1 ? 'This test file' : 'These test files'} existed before this run and ${edits.length === 1 ? 'was' : 'were'} changed during it: ${named}${more}. `
|
|
44
52
|
+ 'An existing test that fails after your change is a constraint on the fix, not something to rewrite to fit it. '
|
|
45
|
-
+ `Unless the task explicitly asks for these tests to change, ${restore} and change the code until the original tests pass.${keep} Adding new test files is fine. `
|
|
53
|
+
+ `Unless the task explicitly asks for these tests to change, ${restore} and change the code until the original tests pass.${keep} Adding new test files is fine, and so is adding new tests to an existing file without changing what it already holds. `
|
|
46
54
|
+ 'If the task does require these edits, call complete_agent again to finish; this reminder is not repeated for the same files.';
|
|
47
55
|
}
|
|
48
56
|
function git(cwd, args, signal) {
|
|
@@ -205,6 +213,44 @@ export class TestEditGuard {
|
|
|
205
213
|
if (!this.created.has(relative) && isTestPath(relative))
|
|
206
214
|
this.toolEdits.set(relative, 'modified');
|
|
207
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* The modified test files whose change only adds new tests: no line of the starting commit's file was
|
|
218
|
+
* removed or replaced, and nothing added switches a test off or defines again a name the file already
|
|
219
|
+
* had. Appending a regression test to an existing test file is ordinary work, not a rewrite of the
|
|
220
|
+
* tests that constrain the fix. Any doubt (a Git failure, a file that is not test code) keeps the file flagged.
|
|
221
|
+
*/
|
|
222
|
+
async onlyAddsTests(baseline, names, signal) {
|
|
223
|
+
const candidates = names.filter(name => ADDITIVE_TEST_CODE.test(name) && !FIXTURE_LOCATION.test(name)
|
|
224
|
+
&& !baseline.dirty.has(name) && !baseline.unknown.has(name)).slice(0, ADDITIVE_FILE_LIMIT);
|
|
225
|
+
if (!candidates.length)
|
|
226
|
+
return [];
|
|
227
|
+
const additive = [];
|
|
228
|
+
try {
|
|
229
|
+
const counts = (await git(this.workspace, ['diff', '--numstat', '-z', '--no-renames', '--relative', baseline.head, '--', ...candidates], signal)).split('\0');
|
|
230
|
+
for (const entry of counts) {
|
|
231
|
+
const match = /^(\d+)\t0\t(.+)$/s.exec(entry);
|
|
232
|
+
if (!match || match[1] === '0' || !candidates.includes(match[2]))
|
|
233
|
+
continue;
|
|
234
|
+
const name = match[2];
|
|
235
|
+
const patch = await git(this.workspace, ['diff', '-U0', '--no-color', '--no-ext-diff', '--no-renames', '--relative', baseline.head, '--', name], signal);
|
|
236
|
+
const added = patch.split(/\r?\n/).filter(line => line.startsWith('+') && !line.startsWith('+++')).map(line => line.slice(1));
|
|
237
|
+
if (!added.length || added.some(line => DISABLES_TESTS.test(line)))
|
|
238
|
+
continue;
|
|
239
|
+
const declared = added.map(line => DECLARATION.exec(line)?.[1]).filter((item) => !!item);
|
|
240
|
+
if (declared.length) {
|
|
241
|
+
const before = await git(this.workspace, ['show', `${baseline.head}:${baseline.prefix}${name}`], signal);
|
|
242
|
+
const existing = new Set([...before.matchAll(new RegExp(DECLARATION.source, 'gm'))].map(found => found[1]));
|
|
243
|
+
if (declared.some(item => existing.has(item)) || new Set(declared).size !== declared.length)
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
additive.push(name);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return additive;
|
|
251
|
+
}
|
|
252
|
+
return additive;
|
|
253
|
+
}
|
|
208
254
|
async current(signal) {
|
|
209
255
|
const baseline = await (this.baseline ?? Promise.resolve({ kind: 'none' }));
|
|
210
256
|
const edits = new Map();
|
|
@@ -216,6 +262,8 @@ export class TestEditGuard {
|
|
|
216
262
|
continue;
|
|
217
263
|
edits.set(name, status.startsWith('D') ? 'deleted' : 'modified');
|
|
218
264
|
}
|
|
265
|
+
for (const name of await this.onlyAddsTests(baseline, [...edits].filter(([, state]) => state === 'modified').map(([name]) => name), signal))
|
|
266
|
+
edits.delete(name);
|
|
219
267
|
for (const [name, before] of baseline.dirty) {
|
|
220
268
|
const now = await contentHash(path.join(baseline.root, baseline.prefix, name));
|
|
221
269
|
if (now === before)
|
package/dist/src/timers.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface WakeCarry {
|
|
|
10
10
|
reasoningEffort?: string;
|
|
11
11
|
overrideAllNodes?: boolean;
|
|
12
12
|
panelBrowserRelay?: boolean;
|
|
13
|
+
/** The session's run used a desktop's providers: a wake cannot start it here, only a resume from that desktop can. */
|
|
14
|
+
relayed?: boolean;
|
|
13
15
|
input?: Record<string, unknown>;
|
|
14
16
|
state?: Record<string, unknown>;
|
|
15
17
|
}
|
package/dist/src/tools.js
CHANGED
|
@@ -17,7 +17,8 @@ import { READ_IMAGE_FILE_LIMIT } from './read-image.js';
|
|
|
17
17
|
import { decodeLegacyText, sniffDocument } from './read-document.js';
|
|
18
18
|
import { READ_DOCUMENT_FILE_LIMIT } from './read-document-tool.js';
|
|
19
19
|
import { clipText } from './text.js';
|
|
20
|
-
import { pullRequestSettings } from './pull-requests.js';
|
|
20
|
+
import { pullRequestSettings, REVIEW_BUMP_COMMENT, REVIEW_INSTRUCTION_BYTES, REVIEW_ROUNDS_DEFAULT, REVIEW_ROUNDS_MAX, reviewLoopActive, reviewLoopSettings } from './pull-requests.js';
|
|
21
|
+
import { agentWriteFromArgs } from './github-app/agent-writes.js';
|
|
21
22
|
import { approveOperation } from './capabilities.js';
|
|
22
23
|
import { HARNESS_HOME_OFF_LIMITS, assertCommandAvoidsHarnessHome, guardsHarnessHome, insideHarnessHome } from './harness-home.js';
|
|
23
24
|
const OUTPUT_LIMIT = 32_768;
|
|
@@ -599,13 +600,44 @@ function qaPermissionTool(tool) {
|
|
|
599
600
|
} };
|
|
600
601
|
}
|
|
601
602
|
const AWAIT_REVIEW_DEFAULT_MINUTES = 360;
|
|
603
|
+
const REVIEW_PHASE_TEXT = { waiting: 'waiting to review', reviewing: 'reviewing', posting: 'posting a review', fixing: 'waiting for your fixes', ended: 'ended' };
|
|
604
|
+
/** The Andorra review loop in the tool's status: on with its round and phase, or off with how the last loop ended. */
|
|
605
|
+
function describeReview(pr) {
|
|
606
|
+
const review = pr.review;
|
|
607
|
+
if (review === undefined)
|
|
608
|
+
return 'Andorra review off';
|
|
609
|
+
if (reviewLoopActive(pr))
|
|
610
|
+
return `Andorra review on (${review.round} of ${review.rounds} reviews posted, ${REVIEW_PHASE_TEXT[review.phase]})`;
|
|
611
|
+
if (review.ended === undefined)
|
|
612
|
+
return `Andorra review off (${review.rounds} rounds when on)`;
|
|
613
|
+
return `Andorra review off (the last loop ended ${review.ended.reason} after ${review.round} of ${review.rounds} reviews${review.ended.detail === undefined ? '' : `: ${review.ended.detail}`})`;
|
|
614
|
+
}
|
|
615
|
+
/** What an Andorra review loop's end means for the agent waiting on it. */
|
|
616
|
+
const REVIEW_END_TEXT = {
|
|
617
|
+
'signed-off': 'Its last review found no P1 or P2 findings.',
|
|
618
|
+
'rounds-used': 'Its last round still found something, and those findings are left for the user: do not fix them unless the user asks.',
|
|
619
|
+
'review-only': 'This task cannot push to the pull request\'s head repository, so the review\'s findings are left for the user.',
|
|
620
|
+
'no-new-commits': 'The turn that took its findings ended without a new commit.',
|
|
621
|
+
'switched-off': 'Andorra review was switched off.',
|
|
622
|
+
};
|
|
623
|
+
function reviewLoopEndAnswer(ended) {
|
|
624
|
+
const why = REVIEW_END_TEXT[ended.reason] ?? (ended.detail === undefined ? '' : ended.detail);
|
|
625
|
+
const next = ended.pullRequest.autoFix
|
|
626
|
+
? 'Auto-fix is still on: call await_review again to wait for other reviewers, or finish and report.'
|
|
627
|
+
: 'There is no review left to wait for; finish your work and report.';
|
|
628
|
+
return `The Andorra review loop ended: ${ended.reason}.${why ? ` ${why}` : ''} ${next}`;
|
|
629
|
+
}
|
|
602
630
|
function reviewWaitAnswer(ended, minutes, signal) {
|
|
603
631
|
switch (ended.kind) {
|
|
632
|
+
// The loop's wake text already says to call await_review once the round is pushed and answered.
|
|
633
|
+
case 'review': return ended.prompt;
|
|
634
|
+
case 'review-ended': return reviewLoopEndAnswer(ended);
|
|
604
635
|
case 'comments': return `${ended.prompt}
|
|
605
636
|
|
|
606
637
|
When this round is pushed and its threads are answered, call pull_request with action await_review again to wait for the next review.`;
|
|
638
|
+
case 'approved': return `Codex signed off on ${ended.pullRequest.url}${ended.headSha === undefined ? '' : ` at ${ended.headSha.slice(0, 10)}`}: it reviewed that commit and found nothing (its thumbs-up on the pull request, or a review with no findings), and no new review comment is waiting. Treat this as an approval of that commit. There is no review left to wait for; finish your work and report, and merge only if the user asked you to. Call await_review again only after you push another commit.`;
|
|
607
639
|
case 'finished': return `${ended.pullRequest.url} is ${ended.pullRequest.state}, so Auto-fix is off and there is no review left to wait for. Finish your work and report.`;
|
|
608
|
-
case 'off': return `Auto-fix is off for ${ended.pullRequest.url}, so no review will be waited for. Finish your work and report; switch Auto-fix on only if the user asks.`;
|
|
640
|
+
case 'off': return `Auto-fix is off for ${ended.pullRequest.url} and no Andorra review loop is running, so no review will be waited for. Finish your work and report; switch Auto-fix or Andorra review on only if the user asks.`;
|
|
609
641
|
case 'none': return 'No pull request is tracked for this session, so there is no review to wait for.';
|
|
610
642
|
case 'timeout': return `No new review arrived in ${minutes} minute${minutes === 1 ? '' : 's'}. Call await_review again to keep waiting, or finish and report.`;
|
|
611
643
|
case 'steered': return 'The user sent you a message while you were waiting for a review. Read and answer it; call await_review again afterwards if the review loop should continue.';
|
|
@@ -751,20 +783,27 @@ export function createTools() {
|
|
|
751
783
|
context.wakesArmed?.push(timer.id);
|
|
752
784
|
return `Timer ${timer.id.slice(0, 8)} armed: your prompt will be delivered in ${args.seconds} second${args.seconds === 1 ? '' : 's'}, at ${new Date(timer.fireAt).toISOString()}. It fires once.`;
|
|
753
785
|
}),
|
|
754
|
-
{ ...tool('pull_request',
|
|
755
|
-
action: { type: 'string', enum: ['status', 'attach', 'update', 'await_review', 'dismiss'], description: 'status shows the tracked PR; attach starts tracking url; update changes settings; await_review waits for the next review round; dismiss stops tracking' },
|
|
786
|
+
{ ...tool('pull_request', `Show or change the pull request this session tracks in the desktop Plan card. A PR you open with \`gh pr create\` is attached automatically; use attach for one opened another way. update changes its settings when the user asks: mergeWhenReady enables GitHub auto-merge (gh pr merge --auto), draft converts to a draft or marks it ready, autoFix wakes you with a prompt when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments and switches itself off once the PR is merged or closed. review switches on Andorra review: the Andorra Code bot reviews the PR up to reviewRounds times (1 to ${REVIEW_ROUNDS_MAX}, default ${REVIEW_ROUNDS_DEFAULT}) and you are woken to fix its findings between reviews; reviewInstruction tells the reviewer what to focus on, reviewModel picks its provider/model (default: this task's), and review false switches it off. It needs a paid Andorra plan and a pull request the Andorra Code GitHub App covers; the result says why when it cannot be switched on. await_review keeps you in this run while Auto-fix or Andorra review is on: it waits, without using the model, until new review comments arrive (and returns them), Andorra review posts its next round (and returns it) or ends, Codex signs off on the head commit (its thumbs-up on the pull request, which is its approval), the PR is merged or closed, the user messages you, or timeoutMinutes pass. Use it to own the review loop: fix a round, push, resolve the threads you fixed, then call await_review again, until the PR is merged or closed. Never wait for a review with sleep, a shell loop or set_timer. Where Codex reviews the repository but shows no sign of having picked up the head commit after 30 seconds (no eyes reaction, no review, no comment), the wait posts "@codex review" on the PR once for that commit, as the gh account that reads the PR; do not post that comment yourself. reply answers a review thread (threadId, body), resolve resolves one (resolved false reopens it), and comment posts on the PR's conversation (body); they act only on the tracked PR. Where the Andorra Code GitHub App covers the PR they post as its bot, otherwise as the gh account that reads the PR; the result says who posted and why. dismiss stops tracking an open PR, and only when the user asks you to: never dismiss as cleanup after a merge, because a merged or closed PR stays on the task as its record and dismiss refuses one. Only change a setting the user asked you to change.`, {
|
|
787
|
+
action: { type: 'string', enum: ['status', 'attach', 'update', 'await_review', 'reply', 'resolve', 'comment', 'dismiss'], description: 'status shows the tracked PR; attach starts tracking url; update changes settings; await_review waits for the next review round; reply, resolve and comment write on the tracked PR; dismiss stops tracking an open PR when the user asks (refused once it is merged or closed)' },
|
|
788
|
+
threadId: property('The review thread\'s id, PRRT_…, from gh\'s reviewThreads query (reply and resolve only)'),
|
|
789
|
+
body: property('The text to post (reply and comment only)'),
|
|
790
|
+
resolved: { type: 'boolean', description: 'resolve only: false reopens a resolved thread (default true)' },
|
|
756
791
|
url: property('The GitHub pull request URL (attach only)'),
|
|
757
792
|
autoFix: { type: 'boolean', description: 'Wake this session when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments, until the PR is merged or closed' },
|
|
758
793
|
mergeWhenReady: { type: 'boolean', description: 'GitHub auto-merge once checks and reviews pass' },
|
|
759
794
|
draft: { type: 'boolean', description: 'true converts to a draft, false marks it ready for review' },
|
|
795
|
+
review: { type: 'boolean', description: 'Andorra review: true has the Andorra Code bot review the PR in rounds and wakes you to fix its findings between them; false stops it' },
|
|
796
|
+
reviewRounds: { type: 'integer', minimum: 1, maximum: REVIEW_ROUNDS_MAX, description: `How many reviews Andorra review posts at most (1 to ${REVIEW_ROUNDS_MAX}, default ${REVIEW_ROUNDS_DEFAULT})` },
|
|
797
|
+
reviewInstruction: property(`What Andorra review's reviewer should focus on, for example "focus on security" (at most ${REVIEW_INSTRUCTION_BYTES} bytes; empty clears it)`),
|
|
798
|
+
reviewModel: property('The reviewer\'s provider/model, for example anthropic/claude-sonnet-4-5 (empty: this task\'s model)'),
|
|
760
799
|
timeoutMinutes: { type: 'integer', minimum: 1, maximum: 1440, description: `How long await_review waits for a review before returning (1 to 1440, default ${AWAIT_REVIEW_DEFAULT_MINUTES})` },
|
|
761
800
|
}, ['action'], async (args, context) => {
|
|
762
801
|
const control = context.pullRequests;
|
|
763
802
|
if (!control)
|
|
764
803
|
throw new Error('pull_request is unavailable here; no session tracks a pull request for this run.');
|
|
765
|
-
const settings = pullRequestSettings(args);
|
|
804
|
+
const settings = { ...pullRequestSettings(args), ...reviewLoopSettings(args) };
|
|
766
805
|
const approve = () => approveOperation(context, 'pull_request', { ...args, warning: 'Changes the pull request on GitHub, or what Andorra does on its own when the PR changes.' });
|
|
767
|
-
const describe = (pr) => `${pr.url} (${pr.state})${pr.title ? ` "${pr.title}"` : ''}: autoFix ${pr.autoFix ? 'on' : 'off'}, mergeWhenReady ${pr.mergeWhenReady ? 'on' : 'off'}`;
|
|
806
|
+
const describe = (pr) => `${pr.url} (${pr.state})${pr.title ? ` "${pr.title}"` : ''}: autoFix ${pr.autoFix ? 'on' : 'off'}, mergeWhenReady ${pr.mergeWhenReady ? 'on' : 'off'}, ${describeReview(pr)}`;
|
|
768
807
|
switch (args.action) {
|
|
769
808
|
case 'status': {
|
|
770
809
|
const pr = await control.status();
|
|
@@ -778,7 +817,7 @@ export function createTools() {
|
|
|
778
817
|
}
|
|
779
818
|
case 'update': {
|
|
780
819
|
if (!Object.keys(settings).length)
|
|
781
|
-
throw new Error('update needs at least one of autoFix, mergeWhenReady, draft');
|
|
820
|
+
throw new Error('update needs at least one of autoFix, mergeWhenReady, draft, review, reviewRounds, reviewInstruction, reviewModel');
|
|
782
821
|
await approve();
|
|
783
822
|
return `Updated ${describe(await control.update(settings, context.wakeOrigin))}`;
|
|
784
823
|
}
|
|
@@ -789,14 +828,25 @@ export function createTools() {
|
|
|
789
828
|
if (typeof minutes !== 'number' || !Number.isSafeInteger(minutes) || minutes < 1 || minutes > 1_440)
|
|
790
829
|
throw new Error('timeoutMinutes must be an integer from 1 to 1440');
|
|
791
830
|
const awaitReview = control.awaitReview.bind(control);
|
|
792
|
-
const
|
|
831
|
+
const approveBump = (detail) => approveOperation(context, 'pull_request', { ...args, body: REVIEW_BUMP_COMMENT, warning: `Changes the pull request on GitHub. ${detail}` });
|
|
832
|
+
const wait = () => awaitReview(context.signal, minutes * 60_000, context.wakeOrigin, { approveBump });
|
|
793
833
|
const ended = await (context.waitOutside ? context.waitOutside(wait) : wait());
|
|
794
834
|
return reviewWaitAnswer(ended, minutes, context.signal);
|
|
795
835
|
}
|
|
836
|
+
case 'reply':
|
|
837
|
+
case 'resolve':
|
|
838
|
+
case 'comment': {
|
|
839
|
+
const write = agentWriteFromArgs(args);
|
|
840
|
+
if (!control.write)
|
|
841
|
+
throw new Error(`${args.action} is unavailable here; this surface cannot write on the pull request.`);
|
|
842
|
+
// Asked by the write once it knows the route and the write passes that route's checks (the bot's 16 KiB), before
|
|
843
|
+
// anything is sent; `detail` says who it posts as.
|
|
844
|
+
return control.write(write, { signal: context.signal, approve: detail => approveOperation(context, 'pull_request', { ...args, warning: `Changes the pull request on GitHub. ${detail}` }) });
|
|
845
|
+
}
|
|
796
846
|
case 'dismiss':
|
|
797
847
|
await control.dismiss();
|
|
798
848
|
return 'The pull request is no longer tracked for this session.';
|
|
799
|
-
default: throw new Error('action must be status, attach, update, await_review, or dismiss');
|
|
849
|
+
default: throw new Error('action must be status, attach, update, await_review, reply, resolve, comment, or dismiss');
|
|
800
850
|
}
|
|
801
851
|
}), family: 'git', executionMode: 'sequential' },
|
|
802
852
|
...createCodingTools({ safePath, read, readImage, readDocument, readLegacyText, atomicWrite, authorize, files, fileLimit: FILE_LIMIT }),
|
package/dist/src/transcript.js
CHANGED
|
@@ -6,6 +6,8 @@ import { HEADING_PREFIX, renderMarkdown } from './markdown.js';
|
|
|
6
6
|
import { formatDuration } from './duration.js';
|
|
7
7
|
import { toolCallStamp } from './tool-call-clock.js';
|
|
8
8
|
import { canonicalCodingToolName } from './tool-names.js';
|
|
9
|
+
import { jevRequestPhrase } from './decision/requestPhrases.js';
|
|
10
|
+
import { compactionText } from './compaction-phrases.js';
|
|
9
11
|
const clean = (value) => stripVTControlCharacters(String(value ?? '')).replace(/\r\n?/g, '\n').replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, '');
|
|
10
12
|
const line = (value) => clipText(clean(value).replace(/\s+/g, ' ').trim(), 240);
|
|
11
13
|
export function formatDurationSuffix(data) {
|
|
@@ -94,7 +96,7 @@ export function formatEvent(event) {
|
|
|
94
96
|
const data = event.data;
|
|
95
97
|
if (data.provider === 'andorra' || data.provider === 'jev') {
|
|
96
98
|
if (event.type === 'decision.requested')
|
|
97
|
-
return { text:
|
|
99
|
+
return { text: `• [Jev] ${jevRequestPhrase(data.text)}` };
|
|
98
100
|
if (event.type === 'decision.skills_truncated')
|
|
99
101
|
return typeof data.text === 'string' && data.text ? { text: ` ⚠ ${data.text}` } : undefined;
|
|
100
102
|
if (event.type === 'decision.completed')
|
|
@@ -115,7 +117,11 @@ export function formatEvent(event) {
|
|
|
115
117
|
const identity = [data.nodeName, typeof data.copy === 'number' && Number(data.copies ?? 2) > 1 ? `copy ${data.copy}${data.copies ? `/${data.copies}` : ''}` : '', data.subagentId].filter(Boolean).map(line).join(' - ');
|
|
116
118
|
const actor = identity ? `[${identity}] ` : '';
|
|
117
119
|
if (event.type === 'agent.context.compaction.started')
|
|
118
|
-
return { text:
|
|
120
|
+
return { text: compactionText(data.text) };
|
|
121
|
+
if (event.type === 'agent.context.compacted' && data.reason === 'requested')
|
|
122
|
+
return { text: data.removedExchanges === 0 ? 'Nothing to compact yet: the run has no earlier exchanges to summarize. Continuing.' : `Compacted ${line(data.removedExchanges)} earlier exchange${data.removedExchanges === 1 ? '' : 's'} into a summary. Continuing.` };
|
|
123
|
+
if (event.type === 'agent.context.compaction.deferred' && data.requested === true)
|
|
124
|
+
return { text: `The context summary could not be written (${line(data.reason)}), so the run continues with its full history.` };
|
|
119
125
|
if (event.type === 'agent.context.compaction.retry')
|
|
120
126
|
return { text: `Context summary incomplete (${line(data.reason)}); retrying ${line(data.nextAttempt)}/3.` };
|
|
121
127
|
if (event.type === 'agent.model.retry' && data.quiet === true)
|
package/dist/src/types.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export interface ModelRetry {
|
|
|
67
67
|
unparsedReply?: string;
|
|
68
68
|
/** The system error code behind a connection that could not be made (`ECONNREFUSED`, `EAI_AGAIN`), for the record only: `reason` stays the plain sentence. */
|
|
69
69
|
cause?: string;
|
|
70
|
+
/** The telemetry error code of the failure being retried (`http_429`, `provider_timeout`, `ECONNRESET`); record-only, never shown. */
|
|
71
|
+
code?: string;
|
|
70
72
|
}
|
|
71
73
|
export interface GenerateRequest {
|
|
72
74
|
model: string;
|
|
@@ -79,6 +81,11 @@ export interface GenerateRequest {
|
|
|
79
81
|
context?: ModelRequestContext;
|
|
80
82
|
estimateInputTokens?: () => number;
|
|
81
83
|
onRetry?: (retry: ModelRetry) => void | Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* A failed request the provider recovered from without a visible retry (a 400 answered by sending again
|
|
86
|
+
* without a forced tool choice or without streaming). Record-only: its telemetry code, never shown.
|
|
87
|
+
*/
|
|
88
|
+
onRecoveredError?: (code: string) => void;
|
|
82
89
|
onRequest?: () => void;
|
|
83
90
|
onReasoning?: (delta: string) => void;
|
|
84
91
|
onText?: (delta: string) => void;
|
|
@@ -6,21 +6,29 @@ import { providerLabel } from './providers.js';
|
|
|
6
6
|
const nonnegative = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
7
7
|
const finiteNonnegative = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
8
8
|
const asObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
9
|
-
const dateOf = (time) => {
|
|
9
|
+
const dateOf = (time, width = 10) => {
|
|
10
10
|
if (typeof time !== 'string')
|
|
11
11
|
return undefined;
|
|
12
12
|
const instant = new Date(time);
|
|
13
|
-
return Number.isFinite(instant.getTime()) ? instant.toISOString().slice(0,
|
|
13
|
+
return Number.isFinite(instant.getTime()) ? instant.toISOString().slice(0, width) : undefined;
|
|
14
14
|
};
|
|
15
15
|
const keyOf = (providerId, model) => JSON.stringify([providerId, model]);
|
|
16
16
|
const emptyModel = (providerId, provider, model) => ({ providerId, provider, model, inputTokens: 0, outputTokens: 0, cacheRead: 0, savedInputEstimate: 0, savedOutputEstimate: 0, bypassedTurns: 0 });
|
|
17
17
|
const emptyDay = (date) => ({ date, inputTokens: 0, outputTokens: 0, cacheRead: 0, savedInputEstimate: 0, savedOutputEstimate: 0, bypassedTurns: 0, models: [] });
|
|
18
18
|
export function createUsageCollector(windowDays, now = new Date(), resolveProvider = provider => provider) {
|
|
19
|
-
if (![7, 30, 365].includes(windowDays))
|
|
20
|
-
throw new Error('windowDays must be 7, 30, or 365');
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
19
|
+
if (![1, 7, 30, 365].includes(windowDays))
|
|
20
|
+
throw new Error('windowDays must be 1, 7, 30, or 365');
|
|
21
|
+
// A one-day window is the rolling last 24 hours, bucketed by UTC hour ("2026-10-29T12"); longer windows bucket by UTC date.
|
|
22
|
+
const hourly = windowDays === 1;
|
|
23
|
+
const step = hourly ? 3600000 : 86400000;
|
|
24
|
+
const buckets = hourly ? 24 : windowDays;
|
|
25
|
+
const width = hourly ? 13 : 10;
|
|
26
|
+
const start = hourly
|
|
27
|
+
? Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours())
|
|
28
|
+
: Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
29
|
+
const bucketOf = (time) => dateOf(time, width);
|
|
30
|
+
const cutoff = new Date(start - (buckets - 1) * step).toISOString().slice(0, width);
|
|
31
|
+
const today = new Date(start).toISOString().slice(0, width);
|
|
24
32
|
const days = new Map();
|
|
25
33
|
const models = new Map();
|
|
26
34
|
const baselines = new Map();
|
|
@@ -51,7 +59,7 @@ export function createUsageCollector(windowDays, now = new Date(), resolveProvid
|
|
|
51
59
|
const item = asObject(record);
|
|
52
60
|
if (!item)
|
|
53
61
|
return;
|
|
54
|
-
const date =
|
|
62
|
+
const date = bucketOf(item.time);
|
|
55
63
|
if (!date || date > today)
|
|
56
64
|
return;
|
|
57
65
|
if (item.type === 'model.response') {
|
|
@@ -130,8 +138,8 @@ export function createUsageCollector(windowDays, now = new Date(), resolveProvid
|
|
|
130
138
|
};
|
|
131
139
|
const finish = (filesScanned = 0, incomplete = false) => {
|
|
132
140
|
const orderedDays = [];
|
|
133
|
-
for (let i = 0; i <
|
|
134
|
-
const date = new Date(
|
|
141
|
+
for (let i = 0; i < buckets; i++) {
|
|
142
|
+
const date = new Date(start - (buckets - i - 1) * step).toISOString().slice(0, width);
|
|
135
143
|
const day = days.get(date);
|
|
136
144
|
orderedDays.push({ ...(day?.row ?? emptyDay(date)), models: [...(day?.models.values() ?? [])].sort((a, b) => b.inputTokens + b.outputTokens - a.inputTokens - a.outputTokens) });
|
|
137
145
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andorra-labs/code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Terminal-first coding agent with a ReAct graph runtime",
|
|
5
5
|
"homepage": "https://andorracode.com",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"typebox": "1.3.27",
|
|
81
81
|
"yaml": "2.9.0"
|
|
82
82
|
},
|
|
83
|
+
"overrides": {
|
|
84
|
+
"@npmcli/package-json": {
|
|
85
|
+
"glob": "14.0.6"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
83
88
|
"lavamoat": {
|
|
84
89
|
"allowScripts": {
|
|
85
90
|
"@google/genai#2.21.0": false,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export interface RemoteTlsIdentity {
|
|
3
|
-
keyPem: string;
|
|
4
|
-
certPem: string;
|
|
5
|
-
fingerprint: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function certificateFingerprint(certPem: string): string;
|
|
8
|
-
export { pemFromDer } from './pem.js';
|
|
9
|
-
export declare function ensureRemoteTlsIdentity(tlsDirectory: string, options?: {
|
|
10
|
-
rotate?: boolean;
|
|
11
|
-
}): Promise<RemoteTlsIdentity>;
|
package/dist/src/remote/cert.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { createHash, createPrivateKey, createPublicKey, randomBytes, X509Certificate as NodeX509Certificate, webcrypto } from 'node:crypto';
|
|
2
|
-
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import 'reflect-metadata';
|
|
5
|
-
import * as x509 from '@peculiar/x509';
|
|
6
|
-
import { acquireSaveLock, SaveLockBusyError } from '../save-lock.js';
|
|
7
|
-
import { toPem } from './pem.js';
|
|
8
|
-
x509.cryptoProvider.set(webcrypto);
|
|
9
|
-
const CERTIFICATE_LIFETIME_MS = 10 * 365 * 24 * 60 * 60 * 1000;
|
|
10
|
-
export function certificateFingerprint(certPem) {
|
|
11
|
-
const der = new NodeX509Certificate(certPem).raw;
|
|
12
|
-
return createHash('sha256').update(der).digest('base64url');
|
|
13
|
-
}
|
|
14
|
-
export { pemFromDer } from './pem.js';
|
|
15
|
-
function storedPairUsable(certPem, keyPem) {
|
|
16
|
-
try {
|
|
17
|
-
const cert = new NodeX509Certificate(certPem);
|
|
18
|
-
const publicKeyPem = cert.publicKey.export({ type: 'spki', format: 'pem' });
|
|
19
|
-
const storedPublicKeyPem = createPublicKey(createPrivateKey(keyPem)).export({ type: 'spki', format: 'pem' });
|
|
20
|
-
return Date.parse(cert.validTo) >= Date.now() && publicKeyPem === storedPublicKeyPem;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async function loadStablePair(tlsDirectory) {
|
|
27
|
-
try {
|
|
28
|
-
const [certPem, keyPem] = await Promise.all([
|
|
29
|
-
readFile(join(tlsDirectory, 'cert.pem'), 'utf8'),
|
|
30
|
-
readFile(join(tlsDirectory, 'key.pem'), 'utf8'),
|
|
31
|
-
]);
|
|
32
|
-
if (!storedPairUsable(certPem, keyPem))
|
|
33
|
-
return null;
|
|
34
|
-
return { certPem, keyPem, fingerprint: certificateFingerprint(certPem) };
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export async function ensureRemoteTlsIdentity(tlsDirectory, options = {}) {
|
|
41
|
-
await mkdir(tlsDirectory, { recursive: true });
|
|
42
|
-
let release;
|
|
43
|
-
for (let attempt = 0; release === undefined; attempt += 1) {
|
|
44
|
-
try {
|
|
45
|
-
release = await acquireSaveLock(tlsDirectory);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (!(error instanceof SaveLockBusyError))
|
|
49
|
-
throw error;
|
|
50
|
-
if (attempt >= 200) {
|
|
51
|
-
const published = await loadStablePair(tlsDirectory);
|
|
52
|
-
if (published)
|
|
53
|
-
return published;
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
await new Promise(resolve => setTimeout(resolve, 25));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
if (!options.rotate) {
|
|
61
|
-
const existing = await loadStablePair(tlsDirectory);
|
|
62
|
-
if (existing)
|
|
63
|
-
return existing;
|
|
64
|
-
}
|
|
65
|
-
const keys = await webcrypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
|
|
66
|
-
const now = Date.now();
|
|
67
|
-
const certificate = await x509.X509CertificateGenerator.createSelfSigned({
|
|
68
|
-
serialNumber: randomBytes(8).toString('hex'),
|
|
69
|
-
name: 'CN=andorra-remote',
|
|
70
|
-
notBefore: new Date(now - 60_000),
|
|
71
|
-
notAfter: new Date(now + CERTIFICATE_LIFETIME_MS),
|
|
72
|
-
keys,
|
|
73
|
-
}, webcrypto);
|
|
74
|
-
const keyPem = toPem('PRIVATE KEY', new Uint8Array(await webcrypto.subtle.exportKey('pkcs8', keys.privateKey)));
|
|
75
|
-
const certPem = certificate.toString('pem');
|
|
76
|
-
const stagedKey = join(tlsDirectory, `key-${randomBytes(6).toString('hex')}.tmp`);
|
|
77
|
-
const stagedCert = join(tlsDirectory, `cert-${randomBytes(6).toString('hex')}.tmp`);
|
|
78
|
-
await writeFile(stagedKey, keyPem, { mode: 0o600 });
|
|
79
|
-
await writeFile(stagedCert, certPem, { mode: 0o600 });
|
|
80
|
-
await rename(stagedKey, join(tlsDirectory, 'key.pem'));
|
|
81
|
-
await rename(stagedCert, join(tlsDirectory, 'cert.pem'));
|
|
82
|
-
return { keyPem, certPem, fingerprint: certificateFingerprint(certPem) };
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
await release();
|
|
86
|
-
}
|
|
87
|
-
}
|