@andorra-labs/code 0.1.17 → 0.1.18
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/agent-execution.js +97 -11
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/app-server/protocol.d.ts +13 -2
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server/workspace.d.ts +19 -0
- package/dist/src/app-server/workspace.js +155 -4
- package/dist/src/app-server.d.ts +32 -1
- package/dist/src/app-server.js +622 -74
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/bridge/command.js +12 -0
- package/dist/src/bridge/control.d.ts +3 -1
- package/dist/src/bridge/control.js +7 -2
- package/dist/src/bridge/github.d.ts +108 -0
- package/dist/src/bridge/github.js +378 -0
- package/dist/src/bridge/host-ops.d.ts +1 -1
- package/dist/src/bridge/host-ops.js +11 -1
- package/dist/src/bridge/host.js +7 -4
- package/dist/src/bug-report-attachments.d.ts +48 -0
- package/dist/src/bug-report-attachments.js +327 -0
- package/dist/src/bug-report.d.ts +23 -3
- package/dist/src/bug-report.js +72 -9
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +10 -4
- package/dist/src/codex-provider.js +1 -1
- package/dist/src/coding-tools.js +9 -2
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +2 -1
- package/dist/src/completion.js +8 -4
- package/dist/src/config.js +3 -1
- package/dist/src/context-budget.js +15 -2
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +11 -0
- package/dist/src/decision/DecisionManager.js +36 -0
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/hostedPolicy.js +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.js +12 -0
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/types.d.ts +1 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +5 -0
- package/dist/src/efficiency.js +5 -1
- package/dist/src/effort-routing.d.ts +27 -0
- package/dist/src/effort-routing.js +34 -0
- package/dist/src/evidence.d.ts +110 -0
- package/dist/src/evidence.js +195 -0
- package/dist/src/github-app/client.d.ts +19 -0
- package/dist/src/github-app/client.js +21 -1
- package/dist/src/github-names.d.ts +7 -0
- package/dist/src/github-names.js +7 -0
- package/dist/src/graph-preview.d.ts +2 -0
- package/dist/src/graph-preview.js +1 -0
- package/dist/src/graph-runner.js +1 -1
- package/dist/src/graph-server.js +4 -2
- package/dist/src/graph-ui/app.js +30 -0
- package/dist/src/graphs.d.ts +6 -0
- package/dist/src/graphs.js +7 -2
- package/dist/src/hardened-runtime.js +32 -21
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-tiers.d.ts +3 -0
- package/dist/src/model-tiers.js +3 -3
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +74 -0
- package/dist/src/providers.d.ts +5 -0
- package/dist/src/providers.js +34 -8
- package/dist/src/pull-requests.d.ts +11 -1
- package/dist/src/pull-requests.js +53 -2
- package/dist/src/react-runtime.js +98 -15
- package/dist/src/remote/engine-pool.js +5 -5
- package/dist/src/runtime.d.ts +29 -1
- package/dist/src/runtime.js +8 -0
- package/dist/src/sessions.d.ts +24 -0
- package/dist/src/sessions.js +55 -2
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/provenance.json +1 -1
- package/dist/src/task-checkout.d.ts +141 -0
- package/dist/src/task-checkout.js +558 -0
- package/dist/src/test-edit-guard.d.ts +30 -0
- package/dist/src/test-edit-guard.js +167 -2
- package/dist/src/thinking-level-detect.d.ts +11 -0
- package/dist/src/thinking-level-detect.js +47 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +124 -0
- package/dist/src/timers.d.ts +1 -0
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/transcript.js +1 -1
- package/dist/src/types.d.ts +34 -0
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ const GIT_TIMEOUT_MS = 5_000;
|
|
|
22
22
|
const HASH_FILE_LIMIT = 8 * 1024 * 1024;
|
|
23
23
|
const BASELINE_DIRTY_LIMIT = 2_000;
|
|
24
24
|
const MAX_NAMED_FILES = 12;
|
|
25
|
+
const UNTRACKED_LIMIT = 200;
|
|
25
26
|
/** True for a path that holds tests, fixtures or expected output: a tests/test/testing directory, test_*.py, *_test.*, *.test.*, *.spec.*, conftest.py. */
|
|
26
27
|
export function isTestPath(name) {
|
|
27
28
|
const normalized = name.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
@@ -53,6 +54,19 @@ export function testEditNudge(edits, restoreFrom) {
|
|
|
53
54
|
+ `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. `
|
|
54
55
|
+ 'If the task does require these edits, call complete_agent again to finish; this reminder is not repeated for the same files.';
|
|
55
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The reminder for a run that changed code through the file tools and finishes with none of it left:
|
|
59
|
+
* a fix that was applied, checked and then taken out again (to compare against the original, or to
|
|
60
|
+
* leave the workspace as it was found) is not delivered.
|
|
61
|
+
*/
|
|
62
|
+
export function undoneWorkNudge(files) {
|
|
63
|
+
const named = files.slice(0, MAX_NAMED_FILES).join(', ');
|
|
64
|
+
const more = files.length > MAX_NAMED_FILES ? `, and ${files.length - MAX_NAMED_FILES} more` : '';
|
|
65
|
+
const one = files.length === 1;
|
|
66
|
+
return `Completion not accepted yet. This run changed ${named}${more} and then restored ${one ? 'it' : 'them'}: the workspace now holds no change to its code. `
|
|
67
|
+
+ 'If a change you made fixes a defect the task describes, apply it again and leave it in place. A fix that was verified and then removed is not delivered, and comparing against the original code is no reason to drop it. '
|
|
68
|
+
+ 'If the changes were only instrumentation, or the task needs only an answer, call complete_agent again to finish; this reminder is not repeated.';
|
|
69
|
+
}
|
|
56
70
|
function git(cwd, args, signal) {
|
|
57
71
|
return new Promise((resolve, reject) => {
|
|
58
72
|
execFile('git', ['-c', 'core.quotepath=off', ...args], {
|
|
@@ -99,6 +113,8 @@ export class TestEditGuard {
|
|
|
99
113
|
nudged = new Set();
|
|
100
114
|
created = new Set();
|
|
101
115
|
toolEdits = new Map();
|
|
116
|
+
sourceEdits = new Set();
|
|
117
|
+
undoneAsked = false;
|
|
102
118
|
restoreFrom;
|
|
103
119
|
startedAt = Date.now();
|
|
104
120
|
stopper = new AbortController();
|
|
@@ -164,7 +180,8 @@ export class TestEditGuard {
|
|
|
164
180
|
}
|
|
165
181
|
this.captured = true;
|
|
166
182
|
this.restoreFrom = head.slice(0, 12);
|
|
167
|
-
return { kind: 'git', root: path.resolve(root), prefix, head, dirty, unknown
|
|
183
|
+
return { kind: 'git', root: path.resolve(root), prefix, head, dirty, unknown,
|
|
184
|
+
...(local.length <= BASELINE_DIRTY_LIMIT ? { dirtyNames: new Set(local) } : {}) };
|
|
168
185
|
}
|
|
169
186
|
/**
|
|
170
187
|
* Reports, before it runs, a tool that may change files: target is the file a file tool changes,
|
|
@@ -210,8 +227,73 @@ export class TestEditGuard {
|
|
|
210
227
|
this.created.add(relative);
|
|
211
228
|
return;
|
|
212
229
|
}
|
|
213
|
-
if (
|
|
230
|
+
if (this.created.has(relative))
|
|
231
|
+
return;
|
|
232
|
+
if (isTestPath(relative))
|
|
214
233
|
this.toolEdits.set(relative, 'modified');
|
|
234
|
+
else if (this.namesItself(target, relative))
|
|
235
|
+
this.sourceEdits.add(relative);
|
|
236
|
+
}
|
|
237
|
+
/** False for a link to another file: the edit changed that file, which is reported under its own path. */
|
|
238
|
+
namesItself(target, relative) {
|
|
239
|
+
try {
|
|
240
|
+
return this.workspaceRelative(realpathSync(target)) === relative;
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The files outside test locations that existed before the run and were changed through Write or
|
|
248
|
+
* Edit, when the workspace's tracked code is now identical to the commit the run started from: the
|
|
249
|
+
* run undid everything it changed. Raised once. Nothing is reported without Git, when any tracked
|
|
250
|
+
* file outside test locations still differs (the work is there, perhaps in another file), when an
|
|
251
|
+
* edited file is not tracked (its contents cannot be compared) or already differed from the commit
|
|
252
|
+
* when the run started (returning it to the commit may be the fix), or on a Git failure, so a
|
|
253
|
+
* doubt never holds a run back.
|
|
254
|
+
*/
|
|
255
|
+
async undone(signal) {
|
|
256
|
+
if (this.undoneAsked || !this.sourceEdits.size)
|
|
257
|
+
return [];
|
|
258
|
+
const baseline = await (this.baseline ?? Promise.resolve({ kind: 'none' }));
|
|
259
|
+
if (baseline.kind !== 'git')
|
|
260
|
+
return [];
|
|
261
|
+
let changed;
|
|
262
|
+
try {
|
|
263
|
+
changed = (await git(this.workspace, ['diff', '--name-only', '-z', '--no-renames', '--relative', baseline.head, '--', '.'], signal)).split('\0').filter(Boolean);
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
if (changed.some(name => !isTestPath(name)))
|
|
269
|
+
return [];
|
|
270
|
+
// The comparison above covers tracked files only. A file Git does not track may still hold the
|
|
271
|
+
// run's change, so one among the edited files leaves the question open and nothing is reported.
|
|
272
|
+
const edited = [...this.sourceEdits];
|
|
273
|
+
if (edited.length > 200)
|
|
274
|
+
return [];
|
|
275
|
+
// "Identical to the commit" means "restored" only for a file that matched the commit when the run
|
|
276
|
+
// started. One that already differed may have been fixed by returning it to the commit, and one
|
|
277
|
+
// changed before the starting state was recorded has an unknown start.
|
|
278
|
+
if (!baseline.dirtyNames || this.racedUnknown || edited.some(name => baseline.dirtyNames.has(name) || this.racedPaths.has(name)))
|
|
279
|
+
return [];
|
|
280
|
+
let tracked;
|
|
281
|
+
try {
|
|
282
|
+
tracked = new Set((await git(this.workspace, ['ls-files', '-z', '--', ...edited], signal)).split('\0').filter(Boolean));
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
return [];
|
|
286
|
+
}
|
|
287
|
+
if (edited.some(name => !tracked.has(name)))
|
|
288
|
+
return [];
|
|
289
|
+
// Work delivered in a new file the run wrote, which Git does not list until it is added. An edit
|
|
290
|
+
// that replaces a file gives it a new creation time, so a file first seen as existing is not new.
|
|
291
|
+
for (const name of this.created) {
|
|
292
|
+
if (!isTestPath(name) && !this.sourceEdits.has(name) && await contentHash(path.join(this.workspace, name)) !== null)
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
this.undoneAsked = true;
|
|
296
|
+
return edited.sort((a, b) => a.localeCompare(b));
|
|
215
297
|
}
|
|
216
298
|
/**
|
|
217
299
|
* The modified test files whose change only adds new tests: no line of the starting commit's file was
|
|
@@ -291,6 +373,89 @@ export class TestEditGuard {
|
|
|
291
373
|
: unknown?.has(name) ? { path: name, state, startUnknown: true } : { path: name, state })
|
|
292
374
|
.sort((a, b) => a.path.localeCompare(b.path));
|
|
293
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* True, once, when the run finishes with the workspace's tracked code identical to the commit it
|
|
378
|
+
* started from, no edited file outside Git's view and no surviving new source file written through
|
|
379
|
+
* the file tools: nothing a task that calls for a change could have delivered. False without Git,
|
|
380
|
+
* on a Git failure, when the workspace's code already differed from the commit at the start, and
|
|
381
|
+
* after undone() or this has already raised the matter, so the agent is asked about it a single time.
|
|
382
|
+
* With testsCount, a change to a test file is work too: a request to write tests is delivered by them,
|
|
383
|
+
* while a defect is not fixed by a test alone.
|
|
384
|
+
*/
|
|
385
|
+
async unchanged(signal, testsCount = false) {
|
|
386
|
+
const counts = (name) => testsCount || !isTestPath(name);
|
|
387
|
+
if (this.undoneAsked)
|
|
388
|
+
return false;
|
|
389
|
+
const baseline = await (this.baseline ?? Promise.resolve({ kind: 'none' }));
|
|
390
|
+
if (baseline.kind !== 'git')
|
|
391
|
+
return false;
|
|
392
|
+
// "Identical to the commit" means "nothing was delivered" only when the workspace's code matched
|
|
393
|
+
// the commit at the start: with source already changed then, returning it to the commit may be
|
|
394
|
+
// the fix. The same doubt holds when a tool changed files before the starting state was recorded.
|
|
395
|
+
if (!baseline.dirtyNames || this.racedUnknown || this.racedPaths.size
|
|
396
|
+
|| [...baseline.dirtyNames].some(counts))
|
|
397
|
+
return false;
|
|
398
|
+
let changed;
|
|
399
|
+
try {
|
|
400
|
+
changed = (await git(this.workspace, ['diff', '--name-only', '--no-renames', '--relative', baseline.head, '--', '.'], signal)).split(/\r?\n/).filter(Boolean);
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
if (changed.some(counts))
|
|
406
|
+
return false;
|
|
407
|
+
// Git's comparison covers tracked files. Work may sit in an edited file Git does not track, or in a
|
|
408
|
+
// new file the run wrote that still exists.
|
|
409
|
+
const edited = [...this.sourceEdits];
|
|
410
|
+
if (edited.length > 200)
|
|
411
|
+
return false;
|
|
412
|
+
if (edited.length) {
|
|
413
|
+
let tracked;
|
|
414
|
+
try {
|
|
415
|
+
tracked = new Set((await git(this.workspace, ['ls-files', '--', ...edited], signal)).split(/\r?\n/).filter(Boolean));
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
if (edited.some(name => !tracked.has(name)))
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
for (const name of this.created) {
|
|
424
|
+
if (counts(name) && !this.sourceEdits.has(name) && await contentHash(path.join(this.workspace, name)) !== null)
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
// A shell command or subagent can write a new file without reporting it. Git lists such files as
|
|
428
|
+
// untracked; one written since the run started is the run's work, an older one was already there.
|
|
429
|
+
// An untracked directory may hold either, and too long a list is not examined: both abstain.
|
|
430
|
+
if (this.opaque) {
|
|
431
|
+
let untracked;
|
|
432
|
+
try {
|
|
433
|
+
untracked = statusPaths(await git(this.workspace, ['status', '--porcelain=v1', '-z', '--untracked-files=normal', '--', '.'], signal)
|
|
434
|
+
.then(output => output.split('\0').filter(entry => entry.startsWith('?? ')).join('\0')));
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
if (untracked.length > UNTRACKED_LIMIT)
|
|
440
|
+
return false;
|
|
441
|
+
for (const listed of untracked) {
|
|
442
|
+
const name = listed.startsWith(baseline.prefix) ? listed.slice(baseline.prefix.length) : listed;
|
|
443
|
+
if (!counts(name.replace(/\/$/, '')))
|
|
444
|
+
continue;
|
|
445
|
+
if (name.endsWith('/'))
|
|
446
|
+
return false;
|
|
447
|
+
try {
|
|
448
|
+
if ((await stat(path.join(this.workspace, name))).mtimeMs >= this.startedAt)
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
this.undoneAsked = true;
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
294
459
|
/**
|
|
295
460
|
* Returns the changed pre-existing test files when at least one of them has not been reported yet,
|
|
296
461
|
* and marks them reported; returns nothing otherwise, so each set of files is raised once.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ProviderConfig, type ReasoningEffort } from './providers.js';
|
|
2
|
+
import type { ModelAdapter } from './types.js';
|
|
3
|
+
/** The smallest output allowance at which an Anthropic request still thinks: a 1024-token budget plus 1024 to answer. */
|
|
4
|
+
export declare const ANTHROPIC_PROBE_MAX_TOKENS = 2048;
|
|
5
|
+
/** One minimal request at a level, answered with the HTTP status the provider gave it. Throws when there was none. */
|
|
6
|
+
export declare function probeLevel(adapter: ModelAdapter, model: string, signal: AbortSignal, maxTokens?: number): Promise<number>;
|
|
7
|
+
/**
|
|
8
|
+
* The thinking levels a provider's model accepts: from the built-in catalog for a catalogued Anthropic model, else by
|
|
9
|
+
* asking the provider once per level. Undefined when the provider type takes no level or the answer was inconclusive.
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectProviderLevels(provider: ProviderConfig, model: string, signal: AbortSignal, adapterFor?: (snapshot: ProviderConfig) => ModelAdapter): Promise<ReasoningEffort[] | undefined>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { anthropicCatalogLevels } from './provider-engine.js';
|
|
2
|
+
import { createAdapter, ProviderRequestError, supportsReasoningEffort } from './providers.js';
|
|
3
|
+
import { detectLevels } from './thinking-levels.js';
|
|
4
|
+
/** The smallest output allowance at which an Anthropic request still thinks: a 1024-token budget plus 1024 to answer. */
|
|
5
|
+
export const ANTHROPIC_PROBE_MAX_TOKENS = 2048;
|
|
6
|
+
/** One minimal request at a level, answered with the HTTP status the provider gave it. Throws when there was none. */
|
|
7
|
+
export async function probeLevel(adapter, model, signal, maxTokens = 16) {
|
|
8
|
+
// A retryable failure (rate limit, server error, timeout) says nothing about the level, and waiting through the
|
|
9
|
+
// adapter's retries would stall the probe: the first retry ends it.
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const bounded = AbortSignal.any([signal, controller.signal]);
|
|
12
|
+
let retried = false;
|
|
13
|
+
try {
|
|
14
|
+
await adapter.generate({ model, messages: [{ role: 'user', content: 'Reply with OK.' }], tools: [], signal: bounded, maxTokens,
|
|
15
|
+
onRetry: () => { retried = true; controller.abort(); } });
|
|
16
|
+
return 200;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
signal.throwIfAborted();
|
|
20
|
+
if (retried)
|
|
21
|
+
return 503;
|
|
22
|
+
if (!(error instanceof ProviderRequestError))
|
|
23
|
+
throw error;
|
|
24
|
+
// A refusal the adapter does not retry carries its status; one it would retry carries it in its telemetry code.
|
|
25
|
+
const direct = error.status;
|
|
26
|
+
const status = typeof direct === 'number' ? direct : Number(/^http_(\d{3})$/.exec(error.telemetryCode ?? '')?.[1]);
|
|
27
|
+
if (!Number.isInteger(status))
|
|
28
|
+
throw error;
|
|
29
|
+
return status;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The thinking levels a provider's model accepts: from the built-in catalog for a catalogued Anthropic model, else by
|
|
34
|
+
* asking the provider once per level. Undefined when the provider type takes no level or the answer was inconclusive.
|
|
35
|
+
*/
|
|
36
|
+
export async function detectProviderLevels(provider, model, signal, adapterFor = snapshot => createAdapter(snapshot)) {
|
|
37
|
+
if (!supportsReasoningEffort(provider.type) || provider.type === 'relayed')
|
|
38
|
+
return undefined;
|
|
39
|
+
const catalog = provider.type === 'anthropic' ? anthropicCatalogLevels(model) : undefined;
|
|
40
|
+
return detectLevels((effort, probeSignal) => {
|
|
41
|
+
const snapshot = { ...provider, model, reasoningEffort: effort };
|
|
42
|
+
delete snapshot.thinkingLevels;
|
|
43
|
+
// An Anthropic request with a small output allowance has thinking turned off whatever level was asked for (the
|
|
44
|
+
// budget must leave 1024 tokens), so the probe would test nothing: give it room for the smallest budget.
|
|
45
|
+
return probeLevel(adapterFor(snapshot), model, probeSignal, provider.type === 'anthropic' ? ANTHROPIC_PROBE_MAX_TOKENS : 16);
|
|
46
|
+
}, signal, catalog);
|
|
47
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ProviderConfig, type ReasoningEffort } from './providers.js';
|
|
2
|
+
/** The thinking levels one model accepts and the ones the user switched off, as saved on its provider. */
|
|
3
|
+
export interface ModelThinkingLevels {
|
|
4
|
+
supported?: ReasoningEffort[];
|
|
5
|
+
disabled?: ReasoningEffort[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The levels a model may run at, lowest first: the ones it accepts minus the ones switched off. A model nobody has
|
|
9
|
+
* detected yet counts as accepting every level, which is what the engine sent before levels were tracked.
|
|
10
|
+
*/
|
|
11
|
+
export declare function enabledLevels(provider: Pick<ProviderConfig, 'type' | 'thinkingLevels'> | undefined, model: string): ReasoningEffort[];
|
|
12
|
+
/**
|
|
13
|
+
* The levels Auto may pick for a model. For a detected model these are its enabled levels. For one nobody has
|
|
14
|
+
* detected, Auto stays inside the widely accepted levels, so that it never sends a level the provider would refuse
|
|
15
|
+
* and fail the run; a level the user sets by hand is still sent as written.
|
|
16
|
+
*/
|
|
17
|
+
export declare function autoLevels(provider: Pick<ProviderConfig, 'type' | 'thinkingLevels'> | undefined, model: string): ReasoningEffort[];
|
|
18
|
+
/** The wanted level when it is enabled, else the closest enabled one, the higher of two equally close. */
|
|
19
|
+
export declare function nearestEnabled(levels: readonly ReasoningEffort[], wanted: ReasoningEffort): ReasoningEffort | undefined;
|
|
20
|
+
export declare function validateThinkingLevels(value: unknown, providerType: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Which levels a model accepts. A catalogued model answers from the catalog. Any other is asked once per level with
|
|
23
|
+
* `send`, which returns the HTTP status of one minimal request at that level; a 2xx keeps the level. Returns undefined,
|
|
24
|
+
* so that nothing is saved, when the server could not be reached or refused for a reason unrelated to the level.
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectLevels(send: (effort: ReasoningEffort, signal: AbortSignal) => Promise<number>, signal: AbortSignal, catalog?: readonly ReasoningEffort[]): Promise<ReasoningEffort[] | undefined>;
|
|
27
|
+
/** The provider with a model's detected levels saved. The user's switched-off levels are kept where still accepted. */
|
|
28
|
+
export declare function withDetectedLevels<T extends Pick<ProviderConfig, 'thinkingLevels'>>(provider: T, model: string, supported: readonly ReasoningEffort[]): T;
|
|
29
|
+
/** The provider with a model's switched-off levels replaced. Throws when that would leave no level enabled. */
|
|
30
|
+
export declare function withDisabledLevels<T extends Pick<ProviderConfig, 'thinkingLevels'>>(provider: T, model: string, disabled: readonly ReasoningEffort[]): T;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { REASONING_EFFORTS, supportsReasoningEffort } from './providers.js';
|
|
2
|
+
// Read at call time, not at load: this module and the provider module can be loaded in either order.
|
|
3
|
+
const position = (level) => REASONING_EFFORTS.indexOf(level);
|
|
4
|
+
const isLevel = (value) => typeof value === 'string' && REASONING_EFFORTS.includes(value);
|
|
5
|
+
const ordered = (levels) => REASONING_EFFORTS.filter(level => new Set(levels).has(level));
|
|
6
|
+
/**
|
|
7
|
+
* The levels a model may run at, lowest first: the ones it accepts minus the ones switched off. A model nobody has
|
|
8
|
+
* detected yet counts as accepting every level, which is what the engine sent before levels were tracked.
|
|
9
|
+
*/
|
|
10
|
+
export function enabledLevels(provider, model) {
|
|
11
|
+
if (!provider || !supportsReasoningEffort(provider.type))
|
|
12
|
+
return [];
|
|
13
|
+
const entry = provider.thinkingLevels?.[model];
|
|
14
|
+
const disabled = new Set(entry?.disabled ?? []);
|
|
15
|
+
return ordered(entry?.supported ?? REASONING_EFFORTS).filter(level => !disabled.has(level));
|
|
16
|
+
}
|
|
17
|
+
/** The levels nearly every provider that takes a level accepts. */
|
|
18
|
+
const WIDELY_ACCEPTED = ['low', 'medium', 'high'];
|
|
19
|
+
/**
|
|
20
|
+
* The levels Auto may pick for a model. For a detected model these are its enabled levels. For one nobody has
|
|
21
|
+
* detected, Auto stays inside the widely accepted levels, so that it never sends a level the provider would refuse
|
|
22
|
+
* and fail the run; a level the user sets by hand is still sent as written.
|
|
23
|
+
*/
|
|
24
|
+
export function autoLevels(provider, model) {
|
|
25
|
+
const enabled = enabledLevels(provider, model);
|
|
26
|
+
return provider?.thinkingLevels?.[model]?.supported === undefined ? enabled.filter(level => WIDELY_ACCEPTED.includes(level)) : enabled;
|
|
27
|
+
}
|
|
28
|
+
/** The wanted level when it is enabled, else the closest enabled one, the higher of two equally close. */
|
|
29
|
+
export function nearestEnabled(levels, wanted) {
|
|
30
|
+
if (levels.includes(wanted))
|
|
31
|
+
return wanted;
|
|
32
|
+
const at = position(wanted);
|
|
33
|
+
let best;
|
|
34
|
+
let distance = Infinity;
|
|
35
|
+
for (const level of levels) {
|
|
36
|
+
const gap = Math.abs(position(level) - at);
|
|
37
|
+
if (gap < distance || (gap === distance && position(level) > at)) {
|
|
38
|
+
best = level;
|
|
39
|
+
distance = gap;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return best;
|
|
43
|
+
}
|
|
44
|
+
export function validateThinkingLevels(value, providerType) {
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return;
|
|
47
|
+
const fail = () => { throw new Error('Invalid thinkingLevels: a map of model ids to { supported, disabled } lists of none, minimal, low, medium, high, xhigh or max, with at least one thinking level left enabled'); };
|
|
48
|
+
if (!supportsReasoningEffort(providerType))
|
|
49
|
+
throw new Error('thinkingLevels belongs to a provider that accepts a thinking level');
|
|
50
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
51
|
+
fail();
|
|
52
|
+
for (const [model, entry] of Object.entries(value)) {
|
|
53
|
+
if (!model.trim() || model.length > 500 || typeof entry !== 'object' || entry === null || Array.isArray(entry))
|
|
54
|
+
fail();
|
|
55
|
+
const { supported, disabled, ...rest } = entry;
|
|
56
|
+
if (Object.keys(rest).length)
|
|
57
|
+
fail();
|
|
58
|
+
for (const list of [supported, disabled]) {
|
|
59
|
+
if (list === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
if (!Array.isArray(list) || list.some(level => !isLevel(level)) || new Set(list).size !== list.length)
|
|
62
|
+
fail();
|
|
63
|
+
}
|
|
64
|
+
const off = new Set(disabled ?? []);
|
|
65
|
+
if (!(supported ?? REASONING_EFFORTS).some(level => !off.has(level))
|
|
66
|
+
&& (supported?.length ?? 1) > 0)
|
|
67
|
+
fail();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** HTTP answers that say nothing about the level asked for: the request never reached a decision on it. */
|
|
71
|
+
const INCONCLUSIVE = new Set([401, 403, 404, 408, 429]);
|
|
72
|
+
/**
|
|
73
|
+
* Which levels a model accepts. A catalogued model answers from the catalog. Any other is asked once per level with
|
|
74
|
+
* `send`, which returns the HTTP status of one minimal request at that level; a 2xx keeps the level. Returns undefined,
|
|
75
|
+
* so that nothing is saved, when the server could not be reached or refused for a reason unrelated to the level.
|
|
76
|
+
*/
|
|
77
|
+
export async function detectLevels(send, signal, catalog) {
|
|
78
|
+
if (catalog)
|
|
79
|
+
return ordered(catalog);
|
|
80
|
+
const accepted = [];
|
|
81
|
+
for (const level of REASONING_EFFORTS) {
|
|
82
|
+
signal.throwIfAborted();
|
|
83
|
+
let status;
|
|
84
|
+
try {
|
|
85
|
+
status = await send(level, signal);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
signal.throwIfAborted();
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
if (INCONCLUSIVE.has(status) || status >= 500)
|
|
92
|
+
return undefined;
|
|
93
|
+
if (status >= 200 && status < 300)
|
|
94
|
+
accepted.push(level);
|
|
95
|
+
}
|
|
96
|
+
return accepted;
|
|
97
|
+
}
|
|
98
|
+
/** The provider with a model's detected levels saved. The user's switched-off levels are kept where still accepted. */
|
|
99
|
+
export function withDetectedLevels(provider, model, supported) {
|
|
100
|
+
const levels = ordered(supported);
|
|
101
|
+
const kept = (provider.thinkingLevels?.[model]?.disabled ?? []).filter(level => levels.includes(level));
|
|
102
|
+
const disabled = kept.length >= levels.length ? [] : ordered(kept);
|
|
103
|
+
return { ...provider, thinkingLevels: { ...provider.thinkingLevels, [model]: { supported: levels, ...(disabled.length ? { disabled } : {}) } } };
|
|
104
|
+
}
|
|
105
|
+
/** The provider with a model's switched-off levels replaced. Throws when that would leave no level enabled. */
|
|
106
|
+
export function withDisabledLevels(provider, model, disabled) {
|
|
107
|
+
const entry = provider.thinkingLevels?.[model];
|
|
108
|
+
const supported = entry?.supported ?? [...REASONING_EFFORTS];
|
|
109
|
+
const off = ordered(disabled.filter(level => supported.includes(level)));
|
|
110
|
+
if (supported.length > 0 && off.length >= supported.length)
|
|
111
|
+
throw new Error('At least one thinking level must stay enabled');
|
|
112
|
+
const next = { ...(entry?.supported ? { supported: entry.supported } : {}), ...(off.length ? { disabled: off } : {}) };
|
|
113
|
+
const all = { ...provider.thinkingLevels };
|
|
114
|
+
if (Object.keys(next).length)
|
|
115
|
+
all[model] = next;
|
|
116
|
+
else
|
|
117
|
+
delete all[model];
|
|
118
|
+
const result = { ...provider };
|
|
119
|
+
if (Object.keys(all).length)
|
|
120
|
+
result.thinkingLevels = all;
|
|
121
|
+
else
|
|
122
|
+
delete result.thinkingLevels;
|
|
123
|
+
return result;
|
|
124
|
+
}
|
package/dist/src/timers.d.ts
CHANGED
package/dist/src/tool-catalog.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toolFamily } from './decision/toolFamilies.js';
|
|
2
2
|
import { canonicalToolName } from './tool-names.js';
|
|
3
3
|
import { identifierTokens } from './context-selection.js';
|
|
4
|
-
const PROTECTED = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'submit_bug_report', 'load_project_skill', 'restore_tools', 'prepare_steps', 'update_widget', 'Skill', 'read_skill_resource', 'expand_tool_output', 'read_artifact', 'write_artifact']);
|
|
4
|
+
const PROTECTED = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'submit_bug_report', 'list_bug_report_sessions', 'load_project_skill', 'restore_tools', 'prepare_steps', 'update_widget', 'Skill', 'read_skill_resource', 'expand_tool_output', 'read_artifact', 'write_artifact']);
|
|
5
5
|
const GIT_WORDS = /\b(git|commit|branch|rebase|merge|stash|diff|blame|checkout|pull request|pr\b|push|history|log)\b/i;
|
|
6
6
|
const MEMORY_WORDS = /\b(remember|recall|memory|previous(ly)?|last time|earlier|convention|decision history)\b/i;
|
|
7
7
|
const WEB_WORDS = /\b(docs?|documentation|https?:\/\/|url|website|web|online|latest version|api reference|changelog|npm package|look up|search the)\b/i;
|
package/dist/src/transcript.js
CHANGED
|
@@ -104,7 +104,7 @@ export function formatEvent(event) {
|
|
|
104
104
|
if (event.type === 'decision.fallback' && data.reason !== 'low_confidence') {
|
|
105
105
|
const reasons = {
|
|
106
106
|
authentication_required: 'Sign in required', decision_daily_limit_reached: 'Daily quota reached',
|
|
107
|
-
decision_window_limit_reached: '
|
|
107
|
+
decision_window_limit_reached: 'Jev limit reached',
|
|
108
108
|
decision_service_unavailable: 'Service unavailable', invalid_response: 'Invalid response',
|
|
109
109
|
decision_protocol_unsupported: 'Request not accepted by the service',
|
|
110
110
|
decision_input_too_large: 'Context exceeds hosted size limits; evaluation skipped locally',
|
package/dist/src/types.d.ts
CHANGED
|
@@ -3,6 +3,18 @@ export interface ToolCall {
|
|
|
3
3
|
name: string;
|
|
4
4
|
arguments: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* One entry of the `reasoning_details` Andorra's router adds to an answer from a model it serves through Anthropic's
|
|
8
|
+
* Messages API: a block of Claude's answer (signed thinking, redacted thinking, a text length or a tool call's place),
|
|
9
|
+
* sealed for the router to rebuild the turn from. The client keeps it as received and sends it back unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export interface RouterReasoningDetail {
|
|
12
|
+
type: 'reasoning.encrypted';
|
|
13
|
+
format: 'anthropic-messages-v1';
|
|
14
|
+
index: number;
|
|
15
|
+
data: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
6
18
|
export interface ProviderContinuation {
|
|
7
19
|
api: string;
|
|
8
20
|
provider: string;
|
|
@@ -13,6 +25,8 @@ export interface ProviderContinuation {
|
|
|
13
25
|
thinkingSignature?: string;
|
|
14
26
|
redacted?: boolean;
|
|
15
27
|
}[];
|
|
28
|
+
/** Andorra's router only: the answer's `reasoning_details`, sent back on the same assistant message. */
|
|
29
|
+
reasoningDetails?: RouterReasoningDetail[];
|
|
16
30
|
}
|
|
17
31
|
export interface ToolImage {
|
|
18
32
|
mimeType: 'image/png' | 'image/jpeg';
|
|
@@ -50,6 +64,11 @@ export interface ModelResponse {
|
|
|
50
64
|
stopReason?: string;
|
|
51
65
|
reasoningContent?: string;
|
|
52
66
|
providerContinuation?: ProviderContinuation;
|
|
67
|
+
/**
|
|
68
|
+
* Messages an adapter added at the end of the request this answer replies to, which the run keeps in its history right
|
|
69
|
+
* before the answer: Claude's thinking comes back from Andorra's router only while its earlier conversation is unchanged.
|
|
70
|
+
*/
|
|
71
|
+
requestTail?: Message[];
|
|
53
72
|
}
|
|
54
73
|
export interface ModelRequestContext {
|
|
55
74
|
runId?: string;
|
|
@@ -112,6 +131,8 @@ export interface ToolRuntimeState {
|
|
|
112
131
|
fileReads: Map<string, ToolFileReadState>;
|
|
113
132
|
}
|
|
114
133
|
export interface ToolContext {
|
|
134
|
+
/** The project a task is filed under, when it works elsewhere (its own worktree); `workspace` is where it works. */
|
|
135
|
+
project?: string;
|
|
115
136
|
automationDirectory?: string;
|
|
116
137
|
browserSessionOwner?: object;
|
|
117
138
|
browserToolBatch?: object;
|
|
@@ -139,6 +160,18 @@ export interface ToolContext {
|
|
|
139
160
|
onApprovalEvent?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
140
161
|
onBrowserEvent?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
141
162
|
onCommandOutput?: (chunk: string) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Records a shell command the agent runs, for the turn's evidence: called before it starts (the runtime reads the
|
|
165
|
+
* revision it runs against), and the returned function when it ends.
|
|
166
|
+
*/
|
|
167
|
+
observeCommand?: (start: {
|
|
168
|
+
command: string;
|
|
169
|
+
directory: string;
|
|
170
|
+
signal?: AbortSignal;
|
|
171
|
+
}) => Promise<(end: {
|
|
172
|
+
exitCode?: number;
|
|
173
|
+
output: string;
|
|
174
|
+
}) => void>;
|
|
142
175
|
onFilePathAuthorized?: (canonicalTarget: string) => void | Promise<void>;
|
|
143
176
|
toolState?: ToolRuntimeState;
|
|
144
177
|
timers?: import('./timers.js').TimerRegistry;
|
|
@@ -146,6 +179,7 @@ export interface ToolContext {
|
|
|
146
179
|
wakeOrigin?: import('./timers.js').WakeOrigin;
|
|
147
180
|
wakesArmed?: string[];
|
|
148
181
|
sessionScope?: string;
|
|
182
|
+
sessionId?: string;
|
|
149
183
|
pullRequests?: import('./pull-requests.js').PullRequestControl;
|
|
150
184
|
fileChanges?: import('./session-changes.js').FileChangeRecorder;
|
|
151
185
|
}
|