@andorra-labs/code 0.1.16 → 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/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-execution.js +108 -19
- 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/errors.js +3 -0
- 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 +30 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +108 -0
- package/dist/src/app-server/workspace.js +608 -11
- package/dist/src/app-server.d.ts +390 -33
- package/dist/src/app-server.js +3033 -565
- 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/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 +359 -0
- package/dist/src/bridge/control.d.ts +70 -0
- package/dist/src/bridge/control.js +238 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- 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 +9 -0
- package/dist/src/bridge/host-ops.js +139 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +543 -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/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/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +191 -35
- package/dist/src/codex-provider.js +1 -1
- package/dist/src/coding-tools.js +24 -17
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +14 -11
- package/dist/src/commands.d.ts +15 -3
- package/dist/src/commands.js +2 -1
- package/dist/src/compaction-phrases.js +1 -1
- package/dist/src/completion.js +89 -8
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +205 -78
- package/dist/src/context-budget.js +15 -2
- package/dist/src/deadline.js +13 -1
- 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/checks.js +1 -1
- 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/requestPhrases.js +0 -1
- 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/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 +368 -0
- package/dist/src/github-app/client.js +830 -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 +15 -0
- package/dist/src/github-names.js +15 -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 +48 -0
- package/dist/src/graph-preview.js +56 -0
- package/dist/src/graph-provider-portability.js +2 -1
- package/dist/src/graph-runner.js +65 -4
- package/dist/src/graph-server.js +7 -5
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +121 -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 +40 -1
- package/dist/src/graphs.js +164 -15
- package/dist/src/hardened-runtime.js +32 -21
- 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-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- 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/model-tiers.d.ts +3 -0
- package/dist/src/model-tiers.js +3 -3
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.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 +28 -2
- package/dist/src/providers.js +59 -12
- 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 +338 -8
- package/dist/src/pull-requests.js +482 -53
- package/dist/src/react-runtime.js +99 -16
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +367 -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 +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 +34 -2
- package/dist/src/runtime.js +18 -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 +35 -1
- package/dist/src/sessions.js +70 -4
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- 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 +3 -3
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/task-checkout.d.ts +141 -0
- package/dist/src/task-checkout.js +558 -0
- 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 +37 -0
- package/dist/src/test-edit-guard.js +216 -3
- 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 +3 -0
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +59 -9
- package/dist/src/transcript.js +1 -1
- package/dist/src/types.d.ts +34 -0
- 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
package/dist/src/config.js
CHANGED
|
@@ -7,6 +7,7 @@ import { isIP } from 'node:net';
|
|
|
7
7
|
import { cleanModelName, fallbackProviderId } from './andorra/entry.js';
|
|
8
8
|
import { readHostedState } from './andorra/state.js';
|
|
9
9
|
import { isModelParameters } from './providers.js';
|
|
10
|
+
import { validateThinkingLevels } from './thinking-levels.js';
|
|
10
11
|
import { assertProviderCredentials, assertRequestTimeout, assertStreamIdleTimeout, MAX_CODEX_ACCOUNT_KEY_LENGTH, MAX_PROVIDER_NAME_LENGTH, PROVIDER_TYPES, REASONING_EFFORTS } from './providers.js';
|
|
11
12
|
import { GOOGLE_BASE_URL } from './google-provider.js';
|
|
12
13
|
import { GROK_BASE_URL } from './grok-provider.js';
|
|
@@ -43,6 +44,164 @@ export function isProjectExtensionOverride(entry) {
|
|
|
43
44
|
return false;
|
|
44
45
|
return true;
|
|
45
46
|
}
|
|
47
|
+
/** At most this many machines are allowed per account; allowing another drops the oldest. */
|
|
48
|
+
export const MODEL_RELAY_ALLOWED_LIMIT = 64;
|
|
49
|
+
const MODEL_RELAY_ACCOUNT_LIMIT = 64;
|
|
50
|
+
const ENVIRONMENT_ID = /^env_[A-Za-z0-9_-]{22}$/;
|
|
51
|
+
const ACCOUNT_SUBJECT = /^[A-Za-z0-9-]{1,128}$/;
|
|
52
|
+
/** The machines `subject` allowed to use this computer's models, from a saved `environments.modelRelay`. */
|
|
53
|
+
export function modelRelayAllowedFor(environments, subject) {
|
|
54
|
+
const saved = environments?.modelRelay;
|
|
55
|
+
if (subject === undefined || !saved || Array.isArray(saved) || !Object.hasOwn(saved, subject))
|
|
56
|
+
return [];
|
|
57
|
+
return [...saved[subject]];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* `map` with `subject`'s list set to `list` and moved to the end: the object's key order is the order in which the
|
|
61
|
+
* accounts' lists were last written. Past 64 accounts, the least recently written are dropped, so the file always
|
|
62
|
+
* validates. (Account subjects are Cognito ids, never integer-like keys, so the order holds.)
|
|
63
|
+
*/
|
|
64
|
+
export function withModelRelayEntry(map, subject, list) {
|
|
65
|
+
const others = Object.entries(map).filter(([key]) => key !== subject);
|
|
66
|
+
return Object.fromEntries([...others.slice(Math.max(0, others.length - (MODEL_RELAY_ACCOUNT_LIMIT - 1))), [subject, list.slice(-MODEL_RELAY_ALLOWED_LIMIT)]]);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The Andorra GitHub App, per user. `app.enabled: false` turns its events off on this installation (every PR
|
|
70
|
+
* is polled through gh, as without the App). `app.agentWrites` says who the agent's replies, resolves and PR
|
|
71
|
+
* comments post as on a PR the App covers: `bot` (the default) for the App's bot, `me` for the person's own gh
|
|
72
|
+
* account. `app.triggers: false` stops a mention of the App's bot on a task's PR from waking the task on this
|
|
73
|
+
* installation (the per-machine opt-out; on by default). `app.reviews: false` refuses switching the Andorra review loop
|
|
74
|
+
* on here (on by default); `app.reviewNewPullRequests: true` switches it on for each PR a task opens (off by default).
|
|
75
|
+
* Other keys under `github.app` belong to later versions and are kept as written.
|
|
76
|
+
*/
|
|
77
|
+
export const GITHUB_AGENT_WRITES = ['bot', 'me'];
|
|
78
|
+
export function validateGitHubConfig(value) {
|
|
79
|
+
const c = value;
|
|
80
|
+
if (!c || typeof c !== 'object' || Array.isArray(c))
|
|
81
|
+
throw new Error('Invalid github configuration');
|
|
82
|
+
if (c.app !== undefined && (!c.app || typeof c.app !== 'object' || Array.isArray(c.app)))
|
|
83
|
+
throw new Error('Invalid github.app configuration');
|
|
84
|
+
if (c.app?.enabled !== undefined && typeof c.app.enabled !== 'boolean')
|
|
85
|
+
throw new Error('github.app.enabled must be a boolean');
|
|
86
|
+
if (c.app?.agentWrites !== undefined && !GITHUB_AGENT_WRITES.includes(c.app.agentWrites))
|
|
87
|
+
throw new Error('github.app.agentWrites must be bot or me');
|
|
88
|
+
if (c.app?.triggers !== undefined && typeof c.app.triggers !== 'boolean')
|
|
89
|
+
throw new Error('github.app.triggers must be a boolean');
|
|
90
|
+
if (c.app?.reviews !== undefined && typeof c.app.reviews !== 'boolean')
|
|
91
|
+
throw new Error('github.app.reviews must be a boolean');
|
|
92
|
+
if (c.app?.reviewNewPullRequests !== undefined && typeof c.app.reviewNewPullRequests !== 'boolean')
|
|
93
|
+
throw new Error('github.app.reviewNewPullRequests must be a boolean');
|
|
94
|
+
return c;
|
|
95
|
+
}
|
|
96
|
+
/** Who the agent's PR writes post as: `me` only when the config says so; anything else, or no config, is `bot`. */
|
|
97
|
+
function agentWritesOf(config) {
|
|
98
|
+
const github = typeof config === 'object' && config !== null ? config.github : undefined;
|
|
99
|
+
const app = typeof github === 'object' && github !== null ? github.app : undefined;
|
|
100
|
+
return typeof app === 'object' && app !== null && app.agentWrites === 'me' ? 'me' : 'bot';
|
|
101
|
+
}
|
|
102
|
+
export function githubAgentWrites(config) {
|
|
103
|
+
return agentWritesOf(config);
|
|
104
|
+
}
|
|
105
|
+
/** The same, read from `config.json` for each write and each Auto-fix prompt, without validation or keyring; unreadable reads as `bot`. */
|
|
106
|
+
export async function readGitHubAgentWrites(directory) {
|
|
107
|
+
let value;
|
|
108
|
+
try {
|
|
109
|
+
value = JSON.parse(await readFile(join(directory, 'config.json'), 'utf8'));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return 'bot';
|
|
113
|
+
}
|
|
114
|
+
return agentWritesOf(value);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The one rule for whether the GitHub App's events may run here: not switched off by `ANDORRA_GITHUB_APP=off`,
|
|
118
|
+
* nor by `github.app.enabled: false` in the config (parsed, or read raw from `config.json`).
|
|
119
|
+
*/
|
|
120
|
+
function githubAppEventsAllowed(config, env) {
|
|
121
|
+
if (env.ANDORRA_GITHUB_APP?.trim().toLowerCase() === 'off')
|
|
122
|
+
return false;
|
|
123
|
+
const github = typeof config === 'object' && config !== null ? config.github : undefined;
|
|
124
|
+
const app = typeof github === 'object' && github !== null ? github.app : undefined;
|
|
125
|
+
return !(typeof app === 'object' && app !== null && app.enabled === false);
|
|
126
|
+
}
|
|
127
|
+
/** Whether the GitHub App's events may run here: not switched off in config, nor by `ANDORRA_GITHUB_APP=off`. */
|
|
128
|
+
export function githubAppEventsEnabled(config, env = process.env) {
|
|
129
|
+
return githubAppEventsAllowed(config, env);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The same, read cheaply for a check that runs every minute: only `github.app.enabled` is taken from
|
|
133
|
+
* `config.json`, with no validation, no provider keys and no keyring. A missing or unreadable file reads as on,
|
|
134
|
+
* as `loadConfig`'s default config would.
|
|
135
|
+
*/
|
|
136
|
+
export async function readGitHubAppEventsEnabled(directory, env = process.env) {
|
|
137
|
+
if (!githubAppEventsAllowed(undefined, env))
|
|
138
|
+
return false;
|
|
139
|
+
let value;
|
|
140
|
+
try {
|
|
141
|
+
value = JSON.parse(await readFile(join(directory, 'config.json'), 'utf8'));
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return githubAppEventsAllowed(value, env);
|
|
147
|
+
}
|
|
148
|
+
/** A mention of the bot may wake a task here: only `github.app.triggers: false` says no. */
|
|
149
|
+
function triggersOf(config) {
|
|
150
|
+
const github = typeof config === 'object' && config !== null ? config.github : undefined;
|
|
151
|
+
const app = typeof github === 'object' && github !== null ? github.app : undefined;
|
|
152
|
+
return !(typeof app === 'object' && app !== null && app.triggers === false);
|
|
153
|
+
}
|
|
154
|
+
export function githubAppTriggersEnabled(config) {
|
|
155
|
+
return triggersOf(config);
|
|
156
|
+
}
|
|
157
|
+
/** The same, read from `config.json` for each mention, without validation or keyring; a missing or unreadable file reads as on. */
|
|
158
|
+
export async function readGitHubAppTriggersEnabled(directory) {
|
|
159
|
+
let value;
|
|
160
|
+
try {
|
|
161
|
+
value = JSON.parse(await readFile(join(directory, 'config.json'), 'utf8'));
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return triggersOf(value);
|
|
167
|
+
}
|
|
168
|
+
/** One boolean key under `github.app`, or undefined when the config does not set it. */
|
|
169
|
+
function githubAppFlag(config, key) {
|
|
170
|
+
const github = typeof config === 'object' && config !== null ? config.github : undefined;
|
|
171
|
+
const app = typeof github === 'object' && github !== null ? github.app : undefined;
|
|
172
|
+
const value = typeof app === 'object' && app !== null ? app[key] : undefined;
|
|
173
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
174
|
+
}
|
|
175
|
+
/** The Andorra review loop may be switched on here: only `github.app.reviews: false` says no. */
|
|
176
|
+
export function githubAppReviewsEnabled(config) {
|
|
177
|
+
return githubAppFlag(config, 'reviews') !== false;
|
|
178
|
+
}
|
|
179
|
+
/** The same, read from `config.json` without validation or keyring; a missing or unreadable file reads as on. */
|
|
180
|
+
export async function readGitHubAppReviewsEnabled(directory) {
|
|
181
|
+
let value;
|
|
182
|
+
try {
|
|
183
|
+
value = JSON.parse(await readFile(join(directory, 'config.json'), 'utf8'));
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
return githubAppFlag(value, 'reviews') !== false;
|
|
189
|
+
}
|
|
190
|
+
/** A PR a task opens starts with the review loop on: only `github.app.reviewNewPullRequests: true` says so. */
|
|
191
|
+
export function githubAppReviewNewPullRequests(config) {
|
|
192
|
+
return githubAppFlag(config, 'reviewNewPullRequests') === true;
|
|
193
|
+
}
|
|
194
|
+
/** The same, read from `config.json`; a missing or unreadable file reads as off. */
|
|
195
|
+
export async function readGitHubAppReviewNewPullRequests(directory) {
|
|
196
|
+
let value;
|
|
197
|
+
try {
|
|
198
|
+
value = JSON.parse(await readFile(join(directory, 'config.json'), 'utf8'));
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
return githubAppFlag(value, 'reviewNewPullRequests') === true;
|
|
204
|
+
}
|
|
46
205
|
export const MAX_CAPSOLVER_API_KEY_LENGTH = 256;
|
|
47
206
|
export function validateBrowserConfig(value) {
|
|
48
207
|
const c = value;
|
|
@@ -235,6 +394,8 @@ export function validateConfig(value) {
|
|
|
235
394
|
validateBrowserConfig(c.browser);
|
|
236
395
|
if (c.webSearch !== undefined)
|
|
237
396
|
validateWebSearchConfig(c.webSearch);
|
|
397
|
+
if (c.github !== undefined)
|
|
398
|
+
validateGitHubConfig(c.github);
|
|
238
399
|
if (c.extensions !== undefined) {
|
|
239
400
|
if (!c.extensions || typeof c.extensions !== 'object' || Array.isArray(c.extensions))
|
|
240
401
|
throw new Error('Invalid extensions configuration');
|
|
@@ -256,8 +417,10 @@ export function validateConfig(value) {
|
|
|
256
417
|
|| Object.entries(c.projectExtensions).some(([key, entry]) => !/^[a-f0-9]{64}$/.test(key) || !isProjectExtensionOverride(entry)))) {
|
|
257
418
|
throw new Error('Invalid projectExtensions configuration');
|
|
258
419
|
}
|
|
259
|
-
if (c.
|
|
260
|
-
|
|
420
|
+
if (c.bridge !== undefined)
|
|
421
|
+
validateBridgeConfig(c.bridge);
|
|
422
|
+
if (c.environments !== undefined)
|
|
423
|
+
validateEnvironmentsConfig(c.environments);
|
|
261
424
|
if (c.projects !== undefined)
|
|
262
425
|
validateProjectsConfig(c.projects);
|
|
263
426
|
if (c.externalSubagent !== undefined && !c.providers.some(p => p?.id === c.externalSubagent.provider)) {
|
|
@@ -271,6 +434,9 @@ export function validateConfig(value) {
|
|
|
271
434
|
const ids = new Set();
|
|
272
435
|
let andorraSeen = false;
|
|
273
436
|
for (const p of c.providers) {
|
|
437
|
+
// A relayed provider lives only in the run that a desktop started with it: never in a config file.
|
|
438
|
+
if (p && typeof p === 'object' && p.type === 'relayed')
|
|
439
|
+
throw new Error('Relayed providers cannot be saved.');
|
|
274
440
|
if (p && typeof p === 'object' && p.type === 'andorra')
|
|
275
441
|
normaliseAndorraEntry(p);
|
|
276
442
|
if (!p || typeof p.id !== 'string' || !/^[\w-]+$/.test(p.id) || ids.has(p.id)
|
|
@@ -294,6 +460,9 @@ export function validateConfig(value) {
|
|
|
294
460
|
throw new Error(`The active model must be one of provider ${p.id}'s configured models`);
|
|
295
461
|
}
|
|
296
462
|
}
|
|
463
|
+
if (p.textOnlyModels !== undefined && (!Array.isArray(p.textOnlyModels) || p.textOnlyModels.some((model) => typeof model !== 'string' || !model.trim() || model.length > 500))) {
|
|
464
|
+
throw new Error('Provider textOnlyModels must be a list of nonempty model ids');
|
|
465
|
+
}
|
|
297
466
|
if (p.modelContextWindows !== undefined) {
|
|
298
467
|
if (!p.modelContextWindows || typeof p.modelContextWindows !== 'object' || Array.isArray(p.modelContextWindows)) {
|
|
299
468
|
throw new Error('Provider modelContextWindows must map model ids to positive integer context windows');
|
|
@@ -319,6 +488,7 @@ export function validateConfig(value) {
|
|
|
319
488
|
if (p.reasoningEffort !== undefined && (!['openai-compatible', 'opencode-go', 'anthropic'].includes(p.type) || !REASONING_EFFORTS.includes(p.reasoningEffort))) {
|
|
320
489
|
throw new Error('Invalid reasoningEffort: use an OpenAI-compatible, OpenCode Go or Anthropic provider and none, minimal, low, medium, high, xhigh, or max');
|
|
321
490
|
}
|
|
491
|
+
validateThinkingLevels(p.thinkingLevels, p.type);
|
|
322
492
|
assertRequestTimeout(p);
|
|
323
493
|
assertStreamIdleTimeout(p);
|
|
324
494
|
assertProviderCredentials(p);
|
|
@@ -785,9 +955,6 @@ export function resolveCodeIntelConfig(config) {
|
|
|
785
955
|
validateCodeIntelConfig(codeIntel);
|
|
786
956
|
return codeIntel;
|
|
787
957
|
}
|
|
788
|
-
const BASE64URL_32 = /^[A-Za-z0-9_-]{43}$/;
|
|
789
|
-
const HEX_16 = /^[a-f0-9]{16}$/;
|
|
790
|
-
const HEX_32 = /^[a-f0-9]{32}$/;
|
|
791
958
|
const HEX_12 = /^[a-f0-9]{12}$/;
|
|
792
959
|
const ISO_DATE = /^\d{4}-\d{2}-\d{2}T/;
|
|
793
960
|
function isDisplayLabel(value) {
|
|
@@ -796,80 +963,40 @@ function isDisplayLabel(value) {
|
|
|
796
963
|
function isIsoDate(value) {
|
|
797
964
|
return typeof value === 'string' && ISO_DATE.test(value) && !Number.isNaN(Date.parse(value));
|
|
798
965
|
}
|
|
799
|
-
function
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if (h.transport !== undefined && h.transport !== 'https' && h.transport !== 'http')
|
|
815
|
-
throw new Error('remote.hosting.transport must be https or http');
|
|
816
|
-
if (h.invitation !== undefined && h.invitation !== null) {
|
|
817
|
-
const i = h.invitation;
|
|
818
|
-
if (!i || typeof i !== 'object' || Array.isArray(i) || !BASE64URL_32.test(i.token) || !isIsoDate(i.createdAt) || !isIsoDate(i.expiresAt)
|
|
819
|
-
|| (i.redeemedAt !== undefined && !isIsoDate(i.redeemedAt))
|
|
820
|
-
|| (i.grant !== undefined && i.grant !== 'browse' && i.grant !== 'full'))
|
|
821
|
-
throw new Error('Invalid remote invitation');
|
|
822
|
-
}
|
|
823
|
-
if (h.devices !== undefined) {
|
|
824
|
-
if (!Array.isArray(h.devices) || h.devices.length > 32)
|
|
825
|
-
throw new Error('remote.hosting.devices must be an array of at most 32 devices');
|
|
826
|
-
const ids = new Set();
|
|
827
|
-
for (const device of h.devices) {
|
|
828
|
-
if (!device || typeof device !== 'object' || Array.isArray(device) || !HEX_16.test(device.id) || ids.has(device.id)
|
|
829
|
-
|| !BASE64URL_32.test(device.token) || !isIsoDate(device.addedAt)
|
|
830
|
-
|| (device.label !== undefined && !isDisplayLabel(device.label))
|
|
831
|
-
|| (device.lastSeenAt !== undefined && !isIsoDate(device.lastSeenAt))
|
|
832
|
-
|| (device.grant !== undefined && device.grant !== 'browse' && device.grant !== 'full'))
|
|
833
|
-
throw new Error('Invalid paired remote device');
|
|
834
|
-
ids.add(device.id);
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
if (h.shares !== undefined) {
|
|
838
|
-
if (!Array.isArray(h.shares) || h.shares.length > 64)
|
|
839
|
-
throw new Error('remote.hosting.shares must be an array of at most 64 shares');
|
|
840
|
-
const ids = new Set();
|
|
841
|
-
for (const share of h.shares) {
|
|
842
|
-
if (!share || typeof share !== 'object' || Array.isArray(share) || !HEX_12.test(share.id) || ids.has(share.id)
|
|
843
|
-
|| typeof share.path !== 'string' || !share.path.trim() || share.path.includes('\0')
|
|
844
|
-
|| (share.label !== undefined && !isDisplayLabel(share.label)))
|
|
845
|
-
throw new Error('Invalid remote share');
|
|
846
|
-
ids.add(share.id);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
966
|
+
export function validateBridgeConfig(bridge) {
|
|
967
|
+
const b = bridge;
|
|
968
|
+
if (!b || typeof b !== 'object' || Array.isArray(b))
|
|
969
|
+
throw new Error('Invalid bridge configuration');
|
|
970
|
+
if (b.folders === undefined)
|
|
971
|
+
return;
|
|
972
|
+
if (!Array.isArray(b.folders) || b.folders.length > 64)
|
|
973
|
+
throw new Error('bridge.folders must be an array of at most 64 folders');
|
|
974
|
+
const ids = new Set();
|
|
975
|
+
for (const folder of b.folders) {
|
|
976
|
+
if (!folder || typeof folder !== 'object' || Array.isArray(folder) || typeof folder.id !== 'string' || !HEX_12.test(folder.id) || ids.has(folder.id)
|
|
977
|
+
|| typeof folder.path !== 'string' || !folder.path.trim() || folder.path.includes('\0')
|
|
978
|
+
|| (folder.label !== undefined && !isDisplayLabel(folder.label)))
|
|
979
|
+
throw new Error('Invalid bridge folder');
|
|
980
|
+
ids.add(folder.id);
|
|
849
981
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|| (workspace.transport === 'https'
|
|
863
|
-
? (typeof workspace.certPem !== 'string' || !workspace.certPem.includes('BEGIN CERTIFICATE'))
|
|
864
|
-
: (workspace.certPem !== undefined && typeof workspace.certPem !== 'string'))
|
|
865
|
-
|| !BASE64URL_32.test(workspace.token) || !isIsoDate(workspace.addedAt)
|
|
866
|
-
|| (workspace.hostname !== undefined && (typeof workspace.hostname !== 'string' || !workspace.hostname.trim() || workspace.hostname.length > 128 || /[\0\r\n]/.test(workspace.hostname)))
|
|
867
|
-
|| (workspace.platform !== undefined && (typeof workspace.platform !== 'string' || !workspace.platform.trim() || workspace.platform.length > 64 || /[\0\r\n]/.test(workspace.platform)))
|
|
868
|
-
|| (workspace.version !== undefined && (typeof workspace.version !== 'string' || !workspace.version.trim() || workspace.version.length > 64 || /[\0\r\n]/.test(workspace.version))))
|
|
869
|
-
throw new Error('Invalid paired remote workspace');
|
|
870
|
-
ids.add(workspace.id);
|
|
871
|
-
}
|
|
982
|
+
}
|
|
983
|
+
export function validateEnvironmentsConfig(environments) {
|
|
984
|
+
const e = environments;
|
|
985
|
+
if (!e || typeof e !== 'object' || Array.isArray(e) || Object.keys(e).some(key => key !== 'modelRelay'))
|
|
986
|
+
throw new Error('Invalid environments configuration');
|
|
987
|
+
if (e.modelRelay === undefined)
|
|
988
|
+
return;
|
|
989
|
+
// The earlier list shape is read as nothing allowed; it is still a valid file.
|
|
990
|
+
if (Array.isArray(e.modelRelay)) {
|
|
991
|
+
if (e.modelRelay.length > MODEL_RELAY_ALLOWED_LIMIT || e.modelRelay.some(id => typeof id !== 'string'))
|
|
992
|
+
throw new Error('environments.modelRelay must map accounts to at most 64 environment ids');
|
|
993
|
+
return;
|
|
872
994
|
}
|
|
995
|
+
const byAccount = e.modelRelay;
|
|
996
|
+
if (!byAccount || typeof byAccount !== 'object' || Object.keys(byAccount).length > MODEL_RELAY_ACCOUNT_LIMIT
|
|
997
|
+
|| Object.entries(byAccount).some(([subject, ids]) => !ACCOUNT_SUBJECT.test(subject) || !Array.isArray(ids) || ids.length > MODEL_RELAY_ALLOWED_LIMIT
|
|
998
|
+
|| ids.some(id => typeof id !== 'string' || !ENVIRONMENT_ID.test(id))))
|
|
999
|
+
throw new Error('environments.modelRelay must map accounts to at most 64 environment ids');
|
|
873
1000
|
}
|
|
874
1001
|
export function validateProjectsConfig(projects) {
|
|
875
1002
|
if (!Array.isArray(projects) || projects.length > 256)
|
|
@@ -918,6 +1045,6 @@ export function validateDecisionConfig(value) {
|
|
|
918
1045
|
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash || (url.protocol === 'http:' && !privateHttpHost(url.hostname)))
|
|
919
1046
|
throw new Error('decisions.endpoint requires HTTPS or private HTTP without credentials, query or fragment');
|
|
920
1047
|
}
|
|
921
|
-
if (c.features !== undefined && (!c.features || typeof c.features !== 'object' || Array.isArray(c.features) || Object.entries(c.features).some(([key, v]) => !['toolRouting', 'codeGraphRouting', 'memoryRouting', 'webRouting', 'delegationRouting', 'verificationRouting', 'riskClassification', 'resultRouting'].includes(key) || typeof v !== 'boolean')))
|
|
1048
|
+
if (c.features !== undefined && (!c.features || typeof c.features !== 'object' || Array.isArray(c.features) || Object.entries(c.features).some(([key, v]) => !['toolRouting', 'taskRouting', 'codeGraphRouting', 'memoryRouting', 'webRouting', 'delegationRouting', 'verificationRouting', 'riskClassification', 'resultRouting'].includes(key) || typeof v !== 'boolean')))
|
|
922
1049
|
throw new Error('Invalid decisions.features');
|
|
923
1050
|
}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { getAutoCompactThreshold } from '../vendor/zcode/source/compact/policy.js';
|
|
2
2
|
import { estimateMessageTokens } from '../vendor/zcode/source/compact/manual.js';
|
|
3
3
|
import { MICROCOMPACT_CLEARED_TOOL_RESULT_MESSAGE, maybeLocalMicrocompactMessages } from '../vendor/zcode/source/compact/microcompact.js';
|
|
4
|
+
/**
|
|
5
|
+
* A turn holding Andorra's router's `reasoning_details` goes back with its thinking inside them and its readable
|
|
6
|
+
* reasoning as a blank, so the readable copy is not counted a second time.
|
|
7
|
+
*/
|
|
8
|
+
function countedReasoning(message) {
|
|
9
|
+
return message.providerContinuation?.reasoningDetails?.length ? undefined : message.reasoningContent;
|
|
10
|
+
}
|
|
4
11
|
export function serializeContext(messages) {
|
|
5
|
-
return JSON.stringify(messages, (key, value)
|
|
12
|
+
return JSON.stringify(messages, function (key, value) {
|
|
13
|
+
if (key === 'images' && Array.isArray(value))
|
|
14
|
+
return value.map(image => ({ mimeType: image.mimeType, nativeImage: true }));
|
|
15
|
+
if (key === 'reasoningContent' && this !== null && typeof this === 'object' && countedReasoning(this) === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
return value;
|
|
18
|
+
});
|
|
6
19
|
}
|
|
7
20
|
export function pruneHistoricalImages(messages, keepToolTurns = 5) {
|
|
8
21
|
const turns = messages.filter(message => message.role === 'assistant' && message.toolCalls?.length);
|
|
@@ -45,7 +58,7 @@ export function dropRejectedImages(messages) {
|
|
|
45
58
|
return images;
|
|
46
59
|
}
|
|
47
60
|
export function estimateContextTokens(messages, toolChars) {
|
|
48
|
-
const contentTokens = estimateMessageTokens(messages.map(message => ({ role: message.role, content: message.content + (message
|
|
61
|
+
const contentTokens = estimateMessageTokens(messages.map(message => ({ role: message.role, content: message.content + (countedReasoning(message) ?? '') + (message.providerContinuation ? JSON.stringify(message.providerContinuation) : ''), toolCalls: message.toolCalls?.map(call => { let input; try {
|
|
49
62
|
input = JSON.parse(call.arguments);
|
|
50
63
|
}
|
|
51
64
|
catch {
|
package/dist/src/deadline.js
CHANGED
|
@@ -84,8 +84,20 @@ export function createRuntimeBudget(callerSignal, wallTimeMs, control) {
|
|
|
84
84
|
resume = undefined;
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
|
|
87
|
+
const unsubscribePause = control.onChange(changed);
|
|
88
88
|
changed(control.isPaused);
|
|
89
|
+
let resumeHold;
|
|
90
|
+
const held = (holding) => {
|
|
91
|
+
if (holding)
|
|
92
|
+
resumeHold ??= budget.suspend();
|
|
93
|
+
else {
|
|
94
|
+
resumeHold?.();
|
|
95
|
+
resumeHold = undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const unsubscribeHold = control.onBudgetHold(held);
|
|
99
|
+
held(control.budgetsHeld);
|
|
100
|
+
unsubscribe = () => { unsubscribePause(); unsubscribeHold(); };
|
|
89
101
|
}
|
|
90
102
|
return budget;
|
|
91
103
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DecisionBatch, DecisionQuestion, DecisionState } from './types.js';
|
|
2
2
|
import type { FactRequest } from './facts.js';
|
|
3
3
|
import type { ToolRouteEvidence, ToolRouteRequest } from './routeTools.js';
|
|
4
|
+
import type { TaskKindEvidence, TaskKindRequest } from './taskKind.js';
|
|
4
5
|
export type DecisionObservation = {
|
|
5
6
|
kind: 'dispatch';
|
|
6
7
|
} | {
|
|
@@ -19,5 +20,6 @@ export type DecisionRequestOptions = {
|
|
|
19
20
|
export interface DecisionProvider {
|
|
20
21
|
evaluate(state: DecisionState, questions: DecisionQuestion[], signal?: AbortSignal, observe?: DecisionObserver, options?: DecisionRequestOptions): Promise<DecisionBatch>;
|
|
21
22
|
evaluateToolMenu?(request: ToolRouteRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<ToolRouteEvidence>;
|
|
23
|
+
evaluateTaskKind?(request: TaskKindRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<TaskKindEvidence>;
|
|
22
24
|
evaluateFact?(fact: FactRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<number>;
|
|
23
25
|
}
|
|
@@ -4,6 +4,7 @@ import type { DecisionProvider } from './DecisionEngine.js';
|
|
|
4
4
|
import { type AgentDecisionState, type DecisionBatch, type DecisionConfig, type DecisionIdentity, type DecisionQuestion, type DecisionRouting } from './types.js';
|
|
5
5
|
import { type FactRequest } from './facts.js';
|
|
6
6
|
import { type ToolRouteEvidence, type ToolRouteRequest } from './routeTools.js';
|
|
7
|
+
import { type TaskKindEvidence, type TaskKindRequest } from './taskKind.js';
|
|
7
8
|
export declare const toolFamilyQuestion: (family: string) => string;
|
|
8
9
|
export declare function decisionRoleChoices(roles: string[], provider: DecisionConfig['provider']): string[];
|
|
9
10
|
export declare function preflightQuestions(config: DecisionConfig, roles: string[], capabilities?: AgentDecisionState['capabilities']): DecisionQuestion[];
|
|
@@ -14,10 +15,17 @@ export declare class DecisionManager {
|
|
|
14
15
|
private readonly onEvent?;
|
|
15
16
|
private readonly factGates;
|
|
16
17
|
private warnedSkillLimit;
|
|
18
|
+
/** Whether task-type routing runs when the configuration does not set a mode: the account's plan decides. */
|
|
19
|
+
readonly taskKindOnByDefault: boolean;
|
|
20
|
+
/** Set once the hosted service has answered that it does not know the task-type call, so a process asks an old service only once. */
|
|
21
|
+
private static taskKindUnsupported;
|
|
22
|
+
/** For tests: forget that a service refused the task-type call. */
|
|
23
|
+
static resetTaskKindSupport(): void;
|
|
17
24
|
constructor(options?: {
|
|
18
25
|
config?: DecisionConfig;
|
|
19
26
|
provider?: DecisionProvider;
|
|
20
27
|
onEvent?: EventSink;
|
|
28
|
+
taskKindOnByDefault?: boolean;
|
|
21
29
|
});
|
|
22
30
|
get enabled(): boolean;
|
|
23
31
|
get active(): boolean;
|
|
@@ -27,6 +35,7 @@ export declare class DecisionManager {
|
|
|
27
35
|
get factsEnabled(): boolean;
|
|
28
36
|
get toolTrimmingEnabled(): boolean;
|
|
29
37
|
get toolMenuEnabled(): boolean;
|
|
38
|
+
get taskKindEnabled(): boolean;
|
|
30
39
|
get skillRoutingEnabled(): boolean;
|
|
31
40
|
private events;
|
|
32
41
|
observe(state: AgentDecisionState, identity: DecisionIdentity, baseline: {
|
|
@@ -41,6 +50,8 @@ export declare class DecisionManager {
|
|
|
41
50
|
fact(request: FactRequest, identity: DecisionIdentity, signal: AbortSignal, sink?: EventSink | undefined): Promise<number | undefined>;
|
|
42
51
|
private observer;
|
|
43
52
|
toolMenu(request: ToolRouteRequest, identity: DecisionIdentity, signal: AbortSignal, sink?: EventSink | undefined): Promise<ToolRouteEvidence | undefined>;
|
|
53
|
+
/** What the run's first message asks for; undefined when the service is off, unreachable, slow or answers out of contract. */
|
|
54
|
+
taskKind(request: TaskKindRequest, identity: DecisionIdentity, signal: AbortSignal, sink?: EventSink | undefined): Promise<TaskKindEvidence | undefined>;
|
|
44
55
|
private request;
|
|
45
56
|
private settle;
|
|
46
57
|
}
|
|
@@ -10,6 +10,7 @@ import { HOSTED_SKILL_LIMIT, hostedSkillLimitNotice, rankHostedSkills } from './
|
|
|
10
10
|
import { markFactGuidance } from './guidancePolicy.js';
|
|
11
11
|
import { actionablePreflightQuestion, answerOnlyTask } from './optimizationPolicy.js';
|
|
12
12
|
import { parseToolRouteEvidence } from './routeTools.js';
|
|
13
|
+
import { parseTaskKindEvidence } from './taskKind.js';
|
|
13
14
|
import { pickJevRequestPhrase } from './requestPhrases.js';
|
|
14
15
|
const FACT_TIMEOUT_MS = 2000;
|
|
15
16
|
const families = new Set(['filesystem-read', 'filesystem-write', 'code-search', 'codegraph', 'git', 'shell', 'memory', 'web', 'browser', 'subagents', 'artifact']);
|
|
@@ -63,7 +64,14 @@ export class DecisionManager {
|
|
|
63
64
|
onEvent;
|
|
64
65
|
factGates = new Map();
|
|
65
66
|
warnedSkillLimit = false;
|
|
67
|
+
/** Whether task-type routing runs when the configuration does not set a mode: the account's plan decides. */
|
|
68
|
+
taskKindOnByDefault;
|
|
69
|
+
/** Set once the hosted service has answered that it does not know the task-type call, so a process asks an old service only once. */
|
|
70
|
+
static taskKindUnsupported = false;
|
|
71
|
+
/** For tests: forget that a service refused the task-type call. */
|
|
72
|
+
static resetTaskKindSupport() { DecisionManager.taskKindUnsupported = false; }
|
|
66
73
|
constructor(options = {}) {
|
|
74
|
+
this.taskKindOnByDefault = options.taskKindOnByDefault === true;
|
|
67
75
|
validateDecisionConfig(options.config ?? {});
|
|
68
76
|
this.config = structuredClone({ ...options.config, mode: options.config?.mode ?? DECISION_DEFAULTS.mode, provider: options.config?.provider ?? DECISION_DEFAULTS.provider, requestTimeoutMs: options.config?.requestTimeoutMs ?? DECISION_DEFAULTS.requestTimeoutMs });
|
|
69
77
|
this.provider = this.config.mode === 'off' || this.config.provider === 'none' ? new NoOpDecisionProvider() : options.provider ?? createDecisionProvider(this.config);
|
|
@@ -77,6 +85,7 @@ export class DecisionManager {
|
|
|
77
85
|
get factsEnabled() { return this.resultRouting && this.style === 'facts'; }
|
|
78
86
|
get toolTrimmingEnabled() { return this.style === 'questions'; }
|
|
79
87
|
get toolMenuEnabled() { return this.active && this.config.provider === 'andorra' && this.config.features?.toolRouting !== false; }
|
|
88
|
+
get taskKindEnabled() { return this.active && this.config.provider === 'andorra' && this.config.features?.taskRouting !== false; }
|
|
80
89
|
get skillRoutingEnabled() { return this.active && this.config.provider === 'andorra' && this.config.features?.toolRouting !== false; }
|
|
81
90
|
events(identity, stage, sink = this.onEvent, applicationSink) {
|
|
82
91
|
const identitySnapshot = { ...identity, requestId: randomUUID() };
|
|
@@ -222,6 +231,33 @@ export class DecisionManager {
|
|
|
222
231
|
return evidence;
|
|
223
232
|
}, evidence => ({ tool_menu: { confidence: evidence.confidence, selected: evidence.probabilities[evidence.choice], version: evidence.version } }), signal, emit, Math.min(this.config.requestTimeoutMs ?? FACT_TIMEOUT_MS, FACT_TIMEOUT_MS));
|
|
224
233
|
}
|
|
234
|
+
/** What the run's first message asks for; undefined when the service is off, unreachable, slow or answers out of contract. */
|
|
235
|
+
async taskKind(request, identity, signal, sink = this.onEvent) {
|
|
236
|
+
if (!this.taskKindEnabled || signal.aborted)
|
|
237
|
+
return undefined;
|
|
238
|
+
const publish = this.events(identity, 'task_kind', sink);
|
|
239
|
+
if (DecisionManager.taskKindUnsupported) {
|
|
240
|
+
publish('decision.skipped', { reason: 'routing_protocol_unavailable' });
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
const emit = (type, data) => {
|
|
244
|
+
if (type === 'decision.fallback' && data.reason === 'decision_protocol_unsupported')
|
|
245
|
+
DecisionManager.taskKindUnsupported = true;
|
|
246
|
+
publish(type, data);
|
|
247
|
+
};
|
|
248
|
+
const evaluate = this.provider.evaluateTaskKind?.bind(this.provider);
|
|
249
|
+
if (!evaluate) {
|
|
250
|
+
emit('decision.skipped', { reason: 'routing_protocol_unavailable' });
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const snapshot = structuredClone(request);
|
|
254
|
+
return this.settle(['task_kind'], aborted => evaluate(snapshot, aborted, this.observer(emit)), value => {
|
|
255
|
+
const evidence = parseTaskKindEvidence(value);
|
|
256
|
+
if (!evidence)
|
|
257
|
+
throw new Error('invalid_response');
|
|
258
|
+
return evidence;
|
|
259
|
+
}, evidence => ({ task_kind: { choice: evidence.choice, confidence: evidence.confidence, selected: evidence.probabilities[evidence.choice], version: evidence.version } }), signal, emit, Math.min(this.config.requestTimeoutMs ?? FACT_TIMEOUT_MS, FACT_TIMEOUT_MS));
|
|
260
|
+
}
|
|
225
261
|
async request(snapshot, questions, signal, emit) {
|
|
226
262
|
if (!questions.length)
|
|
227
263
|
return undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HardenedRunOptions } from '../react-runtime.js';
|
|
2
|
+
/**
|
|
3
|
+
* Asks the hosted classifier what the run's first message calls for and records the verdict on the
|
|
4
|
+
* run. Only the agent whose answer ends a run is asked, and only for a first message: a follow-up
|
|
5
|
+
* is read against the conversation, which the classifier does not see. In `shadow` mode the answer
|
|
6
|
+
* is recorded and nothing changes; any failure leaves the run exactly as it was.
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyTaskKind(options: HardenedRunOptions): Promise<HardenedRunOptions>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { clipFactText } from './facts.js';
|
|
3
|
+
import { TASK_KIND_TASK_CHARS, decideTaskKind, makeTaskKindRequest, taskKindNote } from './taskKind.js';
|
|
4
|
+
/**
|
|
5
|
+
* Asks the hosted classifier what the run's first message calls for and records the verdict on the
|
|
6
|
+
* run. Only the agent whose answer ends a run is asked, and only for a first message: a follow-up
|
|
7
|
+
* is read against the conversation, which the classifier does not see. In `shadow` mode the answer
|
|
8
|
+
* is recorded and nothing changes; any failure leaves the run exactly as it was.
|
|
9
|
+
*/
|
|
10
|
+
export async function applyTaskKind(options) {
|
|
11
|
+
const manager = options.decisionManager;
|
|
12
|
+
// An explicit mode wins. Without one, a Paid account classifies and every other plan does not.
|
|
13
|
+
const mode = options.efficiency?.taskKindRouting?.mode ?? (manager?.taskKindOnByDefault ? 'on' : 'off');
|
|
14
|
+
if (mode === 'off' || !manager?.taskKindEnabled)
|
|
15
|
+
return options;
|
|
16
|
+
if (options.subagentId || !options.finalAnswerOutcomes?.length || options.canonicalTask !== undefined)
|
|
17
|
+
return options;
|
|
18
|
+
if (options.history?.length || options.resumeMessages?.length || options.previousConversation?.messages?.length
|
|
19
|
+
|| Object.keys(options.predecessorOutputs ?? {}).length)
|
|
20
|
+
return options;
|
|
21
|
+
const task = clipFactText(options.decisionTask ?? options.task, TASK_KIND_TASK_CHARS);
|
|
22
|
+
if (!task.trim())
|
|
23
|
+
return options;
|
|
24
|
+
const pause = options.context.runControl?.signal;
|
|
25
|
+
const signal = pause ? AbortSignal.any([options.context.signal, pause]) : options.context.signal;
|
|
26
|
+
const identity = { runId: options.runId ?? randomUUID(), nodeId: options.nodeId ?? 'engineer', invocationId: randomUUID() };
|
|
27
|
+
const emit = async (data) => {
|
|
28
|
+
try {
|
|
29
|
+
await options.onEvent?.({ type: 'efficiency.task_kind', time: new Date().toISOString(), data: { ...identity, mode, ...data } });
|
|
30
|
+
}
|
|
31
|
+
catch { }
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const request = makeTaskKindRequest(task);
|
|
35
|
+
const decided = decideTaskKind(await manager.taskKind(request, identity, signal, options.onEvent));
|
|
36
|
+
options.context.signal.throwIfAborted();
|
|
37
|
+
if (pause?.aborted)
|
|
38
|
+
return options;
|
|
39
|
+
const verdict = decided.verdict;
|
|
40
|
+
const note = verdict ? taskKindNote(verdict.kind) : undefined;
|
|
41
|
+
void emit({ reason: mode === 'shadow' && verdict ? 'shadow' : decided.reason, kind: decided.evidence?.choice, confidence: decided.evidence?.confidence,
|
|
42
|
+
noted: mode === 'on' && !!note, expectsChange: verdict?.expectsChange ?? false,
|
|
43
|
+
requestHash: createHash('sha256').update(JSON.stringify({ taskKind: request })).digest('hex'), requestChars: JSON.stringify({ taskKind: request }).length });
|
|
44
|
+
if (mode !== 'on' || !verdict)
|
|
45
|
+
return options;
|
|
46
|
+
return { ...options, taskKind: { ...verdict, ...(note ? { note } : {}) } };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
options.context.signal.throwIfAborted();
|
|
50
|
+
await emit({ reason: pause?.aborted ? 'paused' : 'routing_unavailable' });
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -197,7 +197,7 @@ export function replayableTestRun(line) {
|
|
|
197
197
|
const source = line.trim().replace(/^cd\s+"?\$\(pwd\)"?\s*&&\s*/, '');
|
|
198
198
|
if (!source || MUTATING_FLAG.test(source) || source.includes('<<'))
|
|
199
199
|
return undefined;
|
|
200
|
-
const masked = source.replace(/'[^']*'/g, quoted => `'${'_'.repeat(quoted.length - 2)}'`).replace(/"
|
|
200
|
+
const masked = source.replace(/'[^']*'/g, quoted => `'${'_'.repeat(quoted.length - 2)}'`).replace(/"[^"$`]*"/g, quoted => `"${'_'.repeat(quoted.length - 2)}"`);
|
|
201
201
|
let cut = -1;
|
|
202
202
|
for (let index = 0; index < masked.length; index++) {
|
|
203
203
|
if (masked[index] !== '|')
|
|
@@ -8,7 +8,8 @@ export function resolveDecisionConfig(membership, enabled = true, decisions) {
|
|
|
8
8
|
}
|
|
9
9
|
export function hostedDecisionPolicy(membership, enabled = true, decisions) {
|
|
10
10
|
return {
|
|
11
|
-
|
|
11
|
+
// Task-type routing costs one hosted decision per run: on by default where decisions are not capped.
|
|
12
|
+
decisionManager: new DecisionManager({ config: resolveDecisionConfig(membership, enabled, decisions), taskKindOnByDefault: membership.tier === 'paid' }),
|
|
12
13
|
decisionNodeOptIn: true,
|
|
13
14
|
};
|
|
14
15
|
}
|
|
@@ -2,6 +2,7 @@ import type { DecisionProvider, DecisionObserver, DecisionRequestOptions } from
|
|
|
2
2
|
import type { DecisionBatch, DecisionQuestion, DecisionState } from '../types.js';
|
|
3
3
|
import { type FactRequest } from '../facts.js';
|
|
4
4
|
import { type ToolRouteRequest, type ToolRouteEvidence } from '../routeTools.js';
|
|
5
|
+
import { type TaskKindEvidence, type TaskKindRequest } from '../taskKind.js';
|
|
5
6
|
export declare class AndorraDecisionProvider implements DecisionProvider {
|
|
6
7
|
private readonly dependencies?;
|
|
7
8
|
constructor(dependencies?: {
|
|
@@ -14,5 +15,6 @@ export declare class AndorraDecisionProvider implements DecisionProvider {
|
|
|
14
15
|
private evaluateOnce;
|
|
15
16
|
evaluateFact(fact: FactRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<number>;
|
|
16
17
|
evaluateToolMenu(request: ToolRouteRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<ToolRouteEvidence>;
|
|
18
|
+
evaluateTaskKind(request: TaskKindRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<TaskKindEvidence>;
|
|
17
19
|
private post;
|
|
18
20
|
}
|