@andorra-labs/code 0.1.17 → 0.1.19
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/account-jev-savings.d.ts +4 -0
- package/dist/src/account-jev-savings.js +92 -0
- package/dist/src/acp-agent.js +2 -2
- package/dist/src/agent-execution.js +441 -53
- package/dist/src/agent-mcp.js +7 -1
- package/dist/src/agent-modifiers.js +5 -7
- package/dist/src/analytics.d.ts +19 -1
- package/dist/src/analytics.js +9 -1
- package/dist/src/andorra/entry.js +15 -6
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/andorra/hosted.d.ts +8 -0
- package/dist/src/andorra/hosted.js +22 -3
- package/dist/src/andorra/streams.d.ts +49 -0
- package/dist/src/andorra/streams.js +98 -0
- package/dist/src/antigravity-acp.d.ts +28 -0
- package/dist/src/antigravity-acp.js +150 -0
- package/dist/src/antigravity-terminal.d.ts +2 -0
- package/dist/src/antigravity-terminal.js +214 -0
- package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
- package/dist/src/app-server/adaptive-routing-settings.js +69 -0
- package/dist/src/app-server/artifact.d.ts +14 -0
- package/dist/src/app-server/artifact.js +46 -0
- package/dist/src/app-server/legal-protocol.d.ts +33 -0
- package/dist/src/app-server/legal-protocol.js +16 -0
- package/dist/src/app-server/protocol.d.ts +34 -3
- package/dist/src/app-server/protocol.js +3 -1
- package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
- package/dist/src/app-server/telemetry-protocol.js +2 -0
- package/dist/src/app-server/telemetry.d.ts +38 -0
- package/dist/src/app-server/telemetry.js +163 -0
- package/dist/src/app-server/workspace.d.ts +21 -0
- package/dist/src/app-server/workspace.js +192 -10
- package/dist/src/app-server.d.ts +82 -26
- package/dist/src/app-server.js +1573 -417
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/auth/AuthManager.d.ts +11 -2
- package/dist/src/auth/AuthManager.js +56 -13
- package/dist/src/auth/index.d.ts +5 -1
- package/dist/src/auth/index.js +8 -1
- package/dist/src/auth/lifecycle.d.ts +13 -0
- package/dist/src/auth/lifecycle.js +109 -0
- package/dist/src/auth/store.d.ts +1 -0
- package/dist/src/auth/store.js +12 -0
- package/dist/src/auth/types.d.ts +12 -0
- package/dist/src/automation-runner.js +2 -0
- package/dist/src/automation-service.js +7 -2
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/benchmark-scores.d.ts +88 -0
- package/dist/src/benchmark-scores.js +302 -0
- package/dist/src/bridge/command.js +16 -1
- package/dist/src/bridge/control.d.ts +3 -1
- package/dist/src/bridge/control.js +9 -3
- package/dist/src/bridge/engines.d.ts +2 -0
- package/dist/src/bridge/engines.js +9 -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 +3 -3
- package/dist/src/bridge/host-ops.js +14 -2
- package/dist/src/bridge/host.d.ts +2 -0
- package/dist/src/bridge/host.js +70 -16
- package/dist/src/bridge/protocol.d.ts +1 -0
- package/dist/src/bridge/protocol.js +1 -0
- package/dist/src/browser-panel-tool.d.ts +12 -0
- package/dist/src/browser-panel-tool.js +30 -3
- package/dist/src/browser-runner.js +53 -62
- package/dist/src/browser-server.js +10 -4
- package/dist/src/browser-session.d.ts +14 -0
- package/dist/src/browser-session.js +57 -12
- package/dist/src/browser-view.d.ts +40 -1
- package/dist/src/browser-view.js +163 -9
- package/dist/src/browser-window-style.d.ts +27 -0
- package/dist/src/browser-window-style.js +244 -0
- 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/claude-provider.d.ts +1 -0
- package/dist/src/claude-provider.js +77 -36
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +245 -62
- package/dist/src/codex-provider.d.ts +1 -0
- package/dist/src/codex-provider.js +44 -8
- package/dist/src/coding-tools.d.ts +1 -0
- package/dist/src/coding-tools.js +28 -7
- package/dist/src/command-screens.d.ts +1 -1
- package/dist/src/command-screens.js +2 -2
- package/dist/src/commands.d.ts +9 -2
- package/dist/src/commands.js +69 -64
- package/dist/src/completion.js +13 -7
- package/dist/src/config.d.ts +14 -3
- package/dist/src/config.js +57 -17
- package/dist/src/context-budget.d.ts +11 -2
- package/dist/src/context-budget.js +38 -4
- package/dist/src/context-compaction.d.ts +10 -8
- package/dist/src/context-compaction.js +23 -24
- package/dist/src/deadline.js +1 -1
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +16 -0
- package/dist/src/decision/DecisionManager.js +75 -2
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/applyToolMenu.js +6 -2
- package/dist/src/decision/hostedPolicy.js +6 -3
- package/dist/src/decision/optimizationPolicy.d.ts +10 -0
- package/dist/src/decision/optimizationPolicy.js +23 -3
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +4 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.js +29 -7
- package/dist/src/decision/providers/index.js +1 -1
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +3 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +80 -1
- package/dist/src/efficiency.js +119 -4
- 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/extensions.d.ts +2 -0
- package/dist/src/extensions.js +30 -20
- package/dist/src/github-app/agent-writes.d.ts +1 -1
- package/dist/src/github-app/agent-writes.js +1 -1
- package/dist/src/github-app/client.d.ts +19 -0
- package/dist/src/github-app/client.js +21 -1
- package/dist/src/github-app/event-source.d.ts +0 -5
- package/dist/src/github-app/event-source.js +1 -31
- package/dist/src/github-app/metrics.d.ts +2 -5
- package/dist/src/github-app/metrics.js +2 -14
- package/dist/src/github-app/review-loop.d.ts +5 -5
- package/dist/src/github-app/review-loop.js +1 -1
- package/dist/src/github-app/review-node.d.ts +2 -2
- package/dist/src/github-app/triggers.d.ts +3 -3
- package/dist/src/github-names.d.ts +7 -0
- package/dist/src/github-names.js +7 -0
- package/dist/src/glob-search.d.ts +1 -0
- package/dist/src/glob-search.js +3 -0
- package/dist/src/google-provider.d.ts +5 -28
- package/dist/src/google-provider.js +6 -141
- package/dist/src/graph-editor-session.d.ts +1 -0
- package/dist/src/graph-editor-session.js +2 -0
- package/dist/src/graph-health.js +3 -1
- package/dist/src/graph-preview.d.ts +2 -0
- package/dist/src/graph-preview.js +1 -0
- package/dist/src/graph-runner.js +20 -14
- package/dist/src/graph-selection.d.ts +3 -1
- package/dist/src/graph-selection.js +2 -2
- package/dist/src/graph-server.d.ts +8 -1
- package/dist/src/graph-server.js +49 -12
- package/dist/src/graph-sync.d.ts +2 -1
- package/dist/src/graph-sync.js +13 -0
- package/dist/src/graph-ui/app.js +49 -8
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graphs.d.ts +23 -1
- package/dist/src/graphs.js +58 -7
- package/dist/src/grok-provider.js +17 -14
- package/dist/src/hardened-runtime.js +39 -25
- package/dist/src/jev-savings.d.ts +4 -0
- package/dist/src/jev-savings.js +13 -0
- package/dist/src/legal/client.d.ts +25 -0
- package/dist/src/legal/client.js +47 -0
- package/dist/src/legal/command.d.ts +13 -0
- package/dist/src/legal/command.js +98 -0
- package/dist/src/legal/documents.d.ts +2 -0
- package/dist/src/legal/documents.js +14 -0
- package/dist/src/legal/gate.d.ts +13 -0
- package/dist/src/legal/gate.js +96 -0
- package/dist/src/legal/manifest.d.ts +21 -0
- package/dist/src/legal/manifest.js +23 -0
- package/dist/src/legal/receipt.d.ts +13 -0
- package/dist/src/legal/receipt.js +137 -0
- package/dist/src/legal/release.d.ts +27 -0
- package/dist/src/legal/release.js +28 -0
- package/dist/src/managed-sign-in.d.ts +0 -1
- package/dist/src/managed-sign-in.js +0 -13
- package/dist/src/membership.d.ts +27 -1
- package/dist/src/membership.js +139 -7
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.js +3 -7
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-pool.d.ts +99 -0
- package/dist/src/model-pool.js +136 -0
- package/dist/src/model-relay/local.js +5 -0
- package/dist/src/model-relay/remote.d.ts +2 -0
- package/dist/src/model-relay/remote.js +4 -0
- package/dist/src/model-tiers.d.ts +16 -1
- package/dist/src/model-tiers.js +31 -7
- package/dist/src/opencode-cli-provider.js +59 -56
- package/dist/src/opencode-provider.js +16 -13
- package/dist/src/permissions.d.ts +5 -0
- package/dist/src/permissions.js +7 -0
- package/dist/src/plan-pass.js +2 -1
- package/dist/src/pool-scores.d.ts +45 -0
- package/dist/src/pool-scores.js +40 -0
- package/dist/src/provider-connection.js +3 -17
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +116 -12
- package/dist/src/provider-request-error.d.ts +8 -0
- package/dist/src/provider-request-error.js +12 -0
- package/dist/src/provider-settings.d.ts +1 -1
- package/dist/src/provider-settings.js +36 -18
- package/dist/src/provider-turn-deadline.d.ts +39 -0
- package/dist/src/provider-turn-deadline.js +139 -0
- package/dist/src/providers.d.ts +8 -9
- package/dist/src/providers.js +211 -150
- package/dist/src/pull-request-merge.d.ts +1 -8
- package/dist/src/pull-request-merge.js +0 -4
- package/dist/src/pull-requests.d.ts +83 -57
- package/dist/src/pull-requests.js +266 -225
- package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
- package/dist/src/qa/runtime/ProcessManager.js +9 -3
- package/dist/src/react-runtime.js +245 -71
- package/dist/src/reasoning-probe-cloud.d.ts +10 -0
- package/dist/src/reasoning-probe-cloud.js +209 -0
- package/dist/src/remote/engine-pool.d.ts +3 -0
- package/dist/src/remote/engine-pool.js +88 -21
- package/dist/src/remote/recovery.d.ts +6 -0
- package/dist/src/remote/recovery.js +37 -0
- package/dist/src/run-records.d.ts +13 -3
- package/dist/src/run-records.js +59 -34
- package/dist/src/runtime.d.ts +47 -2
- package/dist/src/runtime.js +33 -7
- package/dist/src/session-summary.d.ts +8 -0
- package/dist/src/session-summary.js +34 -0
- package/dist/src/sessions.d.ts +32 -0
- package/dist/src/sessions.js +65 -3
- package/dist/src/shell.js +6 -0
- package/dist/src/side-panel.js +36 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +4 -10
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
- package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/subagent-run.js +50 -50
- package/dist/src/subscription-usage.d.ts +50 -0
- package/dist/src/subscription-usage.js +92 -0
- package/dist/src/task-checkout.d.ts +157 -0
- package/dist/src/task-checkout.js +628 -0
- package/dist/src/telemetry/access.d.ts +18 -0
- package/dist/src/telemetry/access.js +43 -0
- package/dist/src/telemetry/aggregate.d.ts +18 -2
- package/dist/src/telemetry/aggregate.js +22 -9
- package/dist/src/telemetry/capture-core.d.ts +33 -14
- package/dist/src/telemetry/capture-core.js +124 -25
- package/dist/src/telemetry/capture.d.ts +3 -2
- package/dist/src/telemetry/capture.js +21 -1
- package/dist/src/telemetry/decision-capture.js +4 -0
- package/dist/src/telemetry/emitter.d.ts +6 -7
- package/dist/src/telemetry/emitter.js +124 -29
- package/dist/src/telemetry/gate.d.ts +41 -2
- package/dist/src/telemetry/gate.js +89 -4
- package/dist/src/telemetry/home.d.ts +1 -0
- package/dist/src/telemetry/home.js +20 -0
- package/dist/src/telemetry/identity.d.ts +6 -3
- package/dist/src/telemetry/identity.js +19 -6
- package/dist/src/telemetry/lifecycle.d.ts +8 -0
- package/dist/src/telemetry/lifecycle.js +76 -0
- package/dist/src/telemetry/outbox.d.ts +13 -8
- package/dist/src/telemetry/outbox.js +68 -12
- package/dist/src/telemetry/permission-command.d.ts +38 -0
- package/dist/src/telemetry/permission-command.js +208 -0
- package/dist/src/telemetry/permission.d.ts +168 -0
- package/dist/src/telemetry/permission.js +662 -0
- package/dist/src/telemetry/record-installation.d.ts +1 -0
- package/dist/src/telemetry/record-installation.js +9 -0
- package/dist/src/telemetry/region-data.d.ts +12 -0
- package/dist/src/telemetry/region-data.js +1314 -0
- package/dist/src/telemetry/region.d.ts +34 -0
- package/dist/src/telemetry/region.js +87 -0
- package/dist/src/telemetry/run-privacy.d.ts +11 -0
- package/dist/src/telemetry/run-privacy.js +165 -0
- package/dist/src/telemetry/schema.d.ts +27 -6
- package/dist/src/telemetry/schema.js +109 -14
- package/dist/src/telemetry/state.d.ts +11 -7
- package/dist/src/telemetry/state.js +39 -6
- package/dist/src/telemetry/surface.d.ts +20 -3
- package/dist/src/telemetry/surface.js +71 -15
- package/dist/src/telemetry/uploader.d.ts +6 -11
- package/dist/src/telemetry/uploader.js +72 -46
- package/dist/src/telemetry/uploads.d.ts +5 -1
- package/dist/src/telemetry/uploads.js +25 -6
- package/dist/src/telemetry/version.d.ts +5 -0
- package/dist/src/telemetry/version.js +34 -0
- package/dist/src/telemetry/workspace.d.ts +4 -1
- package/dist/src/telemetry/workspace.js +18 -3
- package/dist/src/terminal-ui.d.ts +3 -0
- package/dist/src/terminal-ui.js +48 -6
- 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 +13 -0
- package/dist/src/thinking-level-detect.js +52 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +131 -0
- package/dist/src/timers.d.ts +3 -0
- package/dist/src/todos.d.ts +2 -1
- package/dist/src/todos.js +24 -4
- package/dist/src/tool-argument-coercion.d.ts +7 -0
- package/dist/src/tool-argument-coercion.js +49 -0
- package/dist/src/tool-catalog.d.ts +2 -2
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +67 -22
- package/dist/src/transcript.js +3 -2
- package/dist/src/types.d.ts +48 -1
- package/dist/src/update.js +4 -0
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +85 -13
- package/dist/telemetry-consent-v1 +1 -0
- package/package.json +97 -96
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { validateDecisionConfig } from '../config.js';
|
|
3
|
+
import { redactSecrets } from '../memory/redaction.js';
|
|
3
4
|
import { DecisionPolicy, validateBatch } from './DecisionPolicy.js';
|
|
4
5
|
import { createDecisionProvider } from './providers/index.js';
|
|
5
6
|
import { NoOpDecisionProvider } from './providers/NoOpDecisionProvider.js';
|
|
@@ -10,8 +11,12 @@ import { HOSTED_SKILL_LIMIT, hostedSkillLimitNotice, rankHostedSkills } from './
|
|
|
10
11
|
import { markFactGuidance } from './guidancePolicy.js';
|
|
11
12
|
import { actionablePreflightQuestion, answerOnlyTask } from './optimizationPolicy.js';
|
|
12
13
|
import { parseToolRouteEvidence } from './routeTools.js';
|
|
14
|
+
import { parseTaskKindEvidence } from './taskKind.js';
|
|
13
15
|
import { pickJevRequestPhrase } from './requestPhrases.js';
|
|
14
16
|
const FACT_TIMEOUT_MS = 2000;
|
|
17
|
+
const PULL_REQUEST_COMMENT_QUESTION = 'pull_request_comment';
|
|
18
|
+
const PULL_REQUEST_COMMENT_BYTES = 2_000;
|
|
19
|
+
const PULL_REQUEST_COMMENT_KINDS = ['noise', 'approval', 'review'];
|
|
15
20
|
const families = new Set(['filesystem-read', 'filesystem-write', 'code-search', 'codegraph', 'git', 'shell', 'memory', 'web', 'browser', 'subagents', 'artifact']);
|
|
16
21
|
export const toolFamilyQuestion = (family) => `tool_family_${family.replace(/-/g, '_')}`;
|
|
17
22
|
export function decisionRoleChoices(roles, provider) {
|
|
@@ -62,8 +67,16 @@ export class DecisionManager {
|
|
|
62
67
|
provider;
|
|
63
68
|
onEvent;
|
|
64
69
|
factGates = new Map();
|
|
70
|
+
pullRequestCommentGate = new FactServiceGate();
|
|
65
71
|
warnedSkillLimit = false;
|
|
72
|
+
/** Whether task-type routing runs when the configuration does not set a mode: the account's plan decides. */
|
|
73
|
+
taskKindOnByDefault;
|
|
74
|
+
/** 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. */
|
|
75
|
+
static taskKindUnsupported = false;
|
|
76
|
+
/** For tests: forget that a service refused the task-type call. */
|
|
77
|
+
static resetTaskKindSupport() { DecisionManager.taskKindUnsupported = false; }
|
|
66
78
|
constructor(options = {}) {
|
|
79
|
+
this.taskKindOnByDefault = options.taskKindOnByDefault === true;
|
|
67
80
|
validateDecisionConfig(options.config ?? {});
|
|
68
81
|
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
82
|
this.provider = this.config.mode === 'off' || this.config.provider === 'none' ? new NoOpDecisionProvider() : options.provider ?? createDecisionProvider(this.config);
|
|
@@ -77,6 +90,7 @@ export class DecisionManager {
|
|
|
77
90
|
get factsEnabled() { return this.resultRouting && this.style === 'facts'; }
|
|
78
91
|
get toolTrimmingEnabled() { return this.style === 'questions'; }
|
|
79
92
|
get toolMenuEnabled() { return this.active && this.config.provider === 'andorra' && this.config.features?.toolRouting !== false; }
|
|
93
|
+
get taskKindEnabled() { return this.active && this.config.provider === 'andorra' && this.config.features?.taskRouting !== false; }
|
|
80
94
|
get skillRoutingEnabled() { return this.active && this.config.provider === 'andorra' && this.config.features?.toolRouting !== false; }
|
|
81
95
|
events(identity, stage, sink = this.onEvent, applicationSink) {
|
|
82
96
|
const identitySnapshot = { ...identity, requestId: randomUUID() };
|
|
@@ -222,12 +236,71 @@ export class DecisionManager {
|
|
|
222
236
|
return evidence;
|
|
223
237
|
}, 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
238
|
}
|
|
225
|
-
|
|
239
|
+
/** What the run's first message asks for; undefined when the service is off, unreachable, slow or answers out of contract. */
|
|
240
|
+
async taskKind(request, identity, signal, sink = this.onEvent) {
|
|
241
|
+
if (!this.taskKindEnabled || signal.aborted)
|
|
242
|
+
return undefined;
|
|
243
|
+
const publish = this.events(identity, 'task_kind', sink);
|
|
244
|
+
if (DecisionManager.taskKindUnsupported) {
|
|
245
|
+
publish('decision.skipped', { reason: 'routing_protocol_unavailable' });
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
const emit = (type, data) => {
|
|
249
|
+
if (type === 'decision.fallback' && data.reason === 'decision_protocol_unsupported')
|
|
250
|
+
DecisionManager.taskKindUnsupported = true;
|
|
251
|
+
publish(type, data);
|
|
252
|
+
};
|
|
253
|
+
const evaluate = this.provider.evaluateTaskKind?.bind(this.provider);
|
|
254
|
+
if (!evaluate) {
|
|
255
|
+
emit('decision.skipped', { reason: 'routing_protocol_unavailable' });
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
const snapshot = structuredClone(request);
|
|
259
|
+
return this.settle(['task_kind'], aborted => evaluate(snapshot, aborted, this.observer(emit)), value => {
|
|
260
|
+
const evidence = parseTaskKindEvidence(value);
|
|
261
|
+
if (!evidence)
|
|
262
|
+
throw new Error('invalid_response');
|
|
263
|
+
return evidence;
|
|
264
|
+
}, 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));
|
|
265
|
+
}
|
|
266
|
+
/** Classify one reviewer's comment. An ambiguous or failed decision leaves the review wait's own signals in control. */
|
|
267
|
+
async classifyPullRequestComment(body, identity, signal, sink = this.onEvent) {
|
|
268
|
+
if (!this.resultRouting || signal.aborted || Buffer.byteLength(body, 'utf8') > PULL_REQUEST_COMMENT_BYTES)
|
|
269
|
+
return undefined;
|
|
270
|
+
const comment = redactSecrets(body).text.trim();
|
|
271
|
+
if (!comment || Buffer.byteLength(comment, 'utf8') > PULL_REQUEST_COMMENT_BYTES)
|
|
272
|
+
return undefined;
|
|
273
|
+
const publish = this.events(identity, 'pull_request_comment', sink);
|
|
274
|
+
const gate = this.pullRequestCommentGate;
|
|
275
|
+
if (!gate.acquire()) {
|
|
276
|
+
publish('decision.skipped', { reason: 'circuit_open', cause: gate.blockedReason });
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
const state = {
|
|
280
|
+
task: comment,
|
|
281
|
+
node: { id: PULL_REQUEST_COMMENT_QUESTION },
|
|
282
|
+
repository: { codeGraphAvailable: false, memoryAvailable: false },
|
|
283
|
+
capabilities: { toolFamilies: [], subagentRoles: [] },
|
|
284
|
+
run: {},
|
|
285
|
+
};
|
|
286
|
+
const batch = await this.request(state, [{ id: PULL_REQUEST_COMMENT_QUESTION, type: 'choice', choices: [...PULL_REQUEST_COMMENT_KINDS] }], signal, (type, data) => {
|
|
287
|
+
if (type === 'decision.fallback')
|
|
288
|
+
gate.failure(String(data.reason));
|
|
289
|
+
if (type === 'decision.completed')
|
|
290
|
+
gate.success();
|
|
291
|
+
publish(type, data);
|
|
292
|
+
}, Math.min(this.config.requestTimeoutMs ?? FACT_TIMEOUT_MS, FACT_TIMEOUT_MS));
|
|
293
|
+
if (!batch || signal.aborted)
|
|
294
|
+
return undefined;
|
|
295
|
+
const choice = DecisionPolicy.choice(batch, PULL_REQUEST_COMMENT_QUESTION);
|
|
296
|
+
return PULL_REQUEST_COMMENT_KINDS.find(kind => kind === choice);
|
|
297
|
+
}
|
|
298
|
+
async request(snapshot, questions, signal, emit, timeoutMs = this.config.requestTimeoutMs ?? DECISION_DEFAULTS.requestTimeoutMs) {
|
|
226
299
|
if (!questions.length)
|
|
227
300
|
return undefined;
|
|
228
301
|
snapshot = structuredClone(snapshot);
|
|
229
302
|
delete snapshot.consumers;
|
|
230
|
-
return this.settle(questions.map(q => q.id), (controllerSignal, deadlineAt) => this.provider.evaluate(structuredClone(snapshot), structuredClone(questions), controllerSignal, this.observer(emit), { deadlineAt }), value => validateBatch(value, questions), batch => Object.fromEntries(Object.entries(batch).map(([id, r]) => [id, r.type === 'noul' ? { probability: r.probability } : r.type === 'score' ? { score: r.score, confidence: r.confidence } : { ...(id === 'verification_tier' ? { choice: r.choice } : {}), confidence: r.confidence, selected: r.probabilities[r.choice] ?? 0 }])), signal, emit,
|
|
303
|
+
return this.settle(questions.map(q => q.id), (controllerSignal, deadlineAt) => this.provider.evaluate(structuredClone(snapshot), structuredClone(questions), controllerSignal, this.observer(emit), { deadlineAt }), value => validateBatch(value, questions), batch => Object.fromEntries(Object.entries(batch).map(([id, r]) => [id, r.type === 'noul' ? { probability: r.probability } : r.type === 'score' ? { score: r.score, confidence: r.confidence } : { ...(id === 'verification_tier' ? { choice: r.choice } : {}), confidence: r.confidence, selected: r.probabilities[r.choice] ?? 0 }])), signal, emit, timeoutMs);
|
|
231
304
|
}
|
|
232
305
|
async settle(questionIds, evaluate, validate, describe, signal, emit, timeoutMs) {
|
|
233
306
|
emit('decision.requested', { questions: questionIds, text: pickJevRequestPhrase() });
|
|
@@ -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
|
+
}
|
|
@@ -45,9 +45,13 @@ export async function applyToolMenu(options) {
|
|
|
45
45
|
const recover = new Map((options.recoverTools ?? []).map(tool => [tool.name, tool]));
|
|
46
46
|
for (const tool of options.tools)
|
|
47
47
|
recover.set(tool.name, tool);
|
|
48
|
+
const note = `Optional, already-permitted tool schemas are available through restore_tools: ${JSON.stringify(selected.omitted.map(tool => tool.name))}. Restore a schema when required; this grants no permission and bypasses no approval.`;
|
|
48
49
|
return { ...options, tools: options.tools.filter(tool => kept.has(tool.name)), recoverTools: [...recover.values()],
|
|
49
|
-
systemPrompt: [options.systemPrompt,
|
|
50
|
-
|
|
50
|
+
systemPrompt: [options.systemPrompt, note].filter(Boolean).join('\n\n'),
|
|
51
|
+
jevToolRouting: {
|
|
52
|
+
omittedTools: [...(options.jevToolRouting?.omittedTools ?? []), ...options.tools.filter(tool => !kept.has(tool.name))],
|
|
53
|
+
promptAdditions: [...(options.jevToolRouting?.promptAdditions ?? []), note],
|
|
54
|
+
} };
|
|
51
55
|
}
|
|
52
56
|
catch (error) {
|
|
53
57
|
options.context.signal.throwIfAborted();
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { DecisionManager } from './DecisionManager.js';
|
|
2
2
|
export function resolveDecisionConfig(membership, enabled = true, decisions) {
|
|
3
|
-
if (!enabled || !membership.subject)
|
|
3
|
+
if (!enabled || !(membership.subject || membership.anonymousJev))
|
|
4
4
|
return { provider: 'none', mode: 'off' };
|
|
5
5
|
if (decisions && decisions.provider !== 'andorra')
|
|
6
6
|
return decisions;
|
|
7
|
-
|
|
7
|
+
// An anonymous run (no account; the service's signed-out switch is on) still uses the hosted
|
|
8
|
+
// provider, marked so the provider sends its calls unauthenticated and skips no quota of its own.
|
|
9
|
+
return { ...decisions, provider: 'andorra', mode: decisions?.mode ?? 'active', requestTimeoutMs: decisions?.requestTimeoutMs ?? 15000, ...(membership.subject ? {} : { anonymous: true }) };
|
|
8
10
|
}
|
|
9
11
|
export function hostedDecisionPolicy(membership, enabled = true, decisions) {
|
|
10
12
|
return {
|
|
11
|
-
|
|
13
|
+
// Task-type routing defaults to on for subscription tiers.
|
|
14
|
+
decisionManager: new DecisionManager({ config: resolveDecisionConfig(membership, enabled, decisions), taskKindOnByDefault: ['paid', 'plus', 'ultra', 'max'].includes(membership.tier ?? '') }),
|
|
12
15
|
decisionNodeOptIn: true,
|
|
13
16
|
};
|
|
14
17
|
}
|
|
@@ -12,10 +12,20 @@ export declare function hasAdaptiveAlternative(routing: {
|
|
|
12
12
|
tiers?: Record<string, {
|
|
13
13
|
provider: string;
|
|
14
14
|
model?: string;
|
|
15
|
+
effort?: string;
|
|
15
16
|
} | undefined>;
|
|
17
|
+
strategy?: string;
|
|
18
|
+
pool?: readonly {
|
|
19
|
+
provider: string;
|
|
20
|
+
model?: string;
|
|
21
|
+
effort?: string;
|
|
22
|
+
}[];
|
|
23
|
+
candidates?: string;
|
|
24
|
+
scores?: Readonly<Record<string, unknown>>;
|
|
16
25
|
}, baseline: {
|
|
17
26
|
provider: string;
|
|
18
27
|
model: string;
|
|
28
|
+
effort?: string;
|
|
19
29
|
}, configured: readonly {
|
|
20
30
|
id: string;
|
|
21
31
|
model?: string;
|
|
@@ -19,9 +19,24 @@ export function actionablePreflightQuestion(id, facts, consumers, availability,
|
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
export function hasAdaptiveAlternative(routing, baseline, configured) {
|
|
22
|
-
|
|
22
|
+
const scores = routing.scores ?? {};
|
|
23
|
+
const pool = routing.strategy === 'pool';
|
|
24
|
+
// The thinking levels scored for a model: routing picks among them for a target that names no level itself.
|
|
25
|
+
const scoredLevels = (provider, model) => {
|
|
26
|
+
const key = provider + '/' + model;
|
|
27
|
+
const score = Object.hasOwn(scores, key) ? scores[key] : undefined;
|
|
28
|
+
const efforts = typeof score === 'object' && score !== null ? score.efforts : undefined;
|
|
29
|
+
return typeof efforts === 'object' && efforts !== null ? Object.keys(efforts) : [];
|
|
30
|
+
};
|
|
31
|
+
// With candidates all, every configured model that has a score is a pair pool routing may choose.
|
|
32
|
+
const scored = pool && routing.candidates === 'all'
|
|
33
|
+
? configured.flatMap(item => [...new Set([item.model, ...(item.models ?? [])])].flatMap((model) => model && Object.hasOwn(scores, item.id + '/' + model) ? [{ provider: item.id, model, fromScores: true }] : []))
|
|
34
|
+
: [];
|
|
35
|
+
// A tier that names no level takes one from its model's scores, as a scored pool pair does.
|
|
36
|
+
const targets = pool ? [...(routing.pool ?? []), ...scored] : Object.values(routing.tiers ?? {}).map(tier => tier && { ...tier, fromScores: true });
|
|
37
|
+
if (!routing.enabled || !targets.length)
|
|
23
38
|
return false;
|
|
24
|
-
return
|
|
39
|
+
return targets.some(target => {
|
|
25
40
|
if (!target)
|
|
26
41
|
return false;
|
|
27
42
|
const provider = configured.find(item => item.id === target.provider);
|
|
@@ -30,6 +45,11 @@ export function hasAdaptiveAlternative(routing, baseline, configured) {
|
|
|
30
45
|
return false;
|
|
31
46
|
if (target.model !== undefined && provider.models?.length && !provider.models.includes(model) && provider.model !== model)
|
|
32
47
|
return false;
|
|
33
|
-
|
|
48
|
+
if (provider.id !== baseline.provider || model !== baseline.model)
|
|
49
|
+
return true;
|
|
50
|
+
// The baseline's own model at another thinking level is an alternative as well.
|
|
51
|
+
if (target.effort !== undefined)
|
|
52
|
+
return target.effort !== baseline.effort;
|
|
53
|
+
return target.fromScores === true && scoredLevels(provider.id, model).some(level => level !== baseline.effort);
|
|
34
54
|
});
|
|
35
55
|
}
|
|
@@ -2,17 +2,20 @@ 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?;
|
|
8
|
+
private readonly anonymous;
|
|
7
9
|
constructor(dependencies?: {
|
|
8
10
|
getAccessToken: (signal?: AbortSignal) => Promise<string | undefined>;
|
|
9
11
|
apiBaseUrl: string;
|
|
10
12
|
fetch: typeof fetch;
|
|
11
|
-
} | undefined);
|
|
13
|
+
} | undefined, anonymous?: boolean);
|
|
12
14
|
evaluate(state: DecisionState, questions: DecisionQuestion[], signal?: AbortSignal, observe?: DecisionObserver, options?: DecisionRequestOptions): Promise<DecisionBatch>;
|
|
13
15
|
private evaluateBatched;
|
|
14
16
|
private evaluateOnce;
|
|
15
17
|
evaluateFact(fact: FactRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<number>;
|
|
16
18
|
evaluateToolMenu(request: ToolRouteRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<ToolRouteEvidence>;
|
|
19
|
+
evaluateTaskKind(request: TaskKindRequest, signal?: AbortSignal, observe?: DecisionObserver): Promise<TaskKindEvidence>;
|
|
17
20
|
private post;
|
|
18
21
|
}
|
|
@@ -2,6 +2,7 @@ import { normalizeAnswers } from './HttpDecisionProvider.js';
|
|
|
2
2
|
import { validateBatch } from '../DecisionPolicy.js';
|
|
3
3
|
import { clipFactText, factProbability, FACT_LIMITS } from '../facts.js';
|
|
4
4
|
import { parseToolRouteEvidence } from '../routeTools.js';
|
|
5
|
+
import { parseTaskKindEvidence } from '../taskKind.js';
|
|
5
6
|
import { abstainSkill, chunkSkills, expandSkillAnswer, HOSTED_SKILLS_PER_REQUEST, LEGACY_HOSTED_SKILLS_PER_REQUEST, mergeNoSkill } from '../hostedSkills.js';
|
|
6
7
|
const HOSTED_REQUEST_BYTES = 32_768;
|
|
7
8
|
const CLIP_MARKER = '\n…[Jev routing context clipped]…\n';
|
|
@@ -151,8 +152,10 @@ class UsageReceipts {
|
|
|
151
152
|
}
|
|
152
153
|
export class AndorraDecisionProvider {
|
|
153
154
|
dependencies;
|
|
154
|
-
|
|
155
|
+
anonymous;
|
|
156
|
+
constructor(dependencies, anonymous = false) {
|
|
155
157
|
this.dependencies = dependencies;
|
|
158
|
+
this.anonymous = anonymous;
|
|
156
159
|
}
|
|
157
160
|
async evaluate(state, questions, signal, observe, options) {
|
|
158
161
|
signal?.throwIfAborted();
|
|
@@ -254,18 +257,37 @@ export class AndorraDecisionProvider {
|
|
|
254
257
|
throw new Error('invalid_response');
|
|
255
258
|
return evidence;
|
|
256
259
|
}
|
|
260
|
+
async evaluateTaskKind(request, signal, observe) {
|
|
261
|
+
signal?.throwIfAborted();
|
|
262
|
+
const body = JSON.stringify({ taskKind: request });
|
|
263
|
+
if (Buffer.byteLength(body, 'utf8') > HOSTED_REQUEST_BYTES)
|
|
264
|
+
throw new Error('decision_input_too_large');
|
|
265
|
+
const response = await this.post(body, signal, observe);
|
|
266
|
+
const evidence = parseTaskKindEvidence(response.taskKind);
|
|
267
|
+
if (!evidence)
|
|
268
|
+
throw new Error('invalid_response');
|
|
269
|
+
return evidence;
|
|
270
|
+
}
|
|
257
271
|
async post(body, signal, observe) {
|
|
258
272
|
const auth = this.dependencies ?? await (async () => {
|
|
259
273
|
const { getAccessToken, getAuthConfiguration } = await import('../../auth/index.js');
|
|
260
274
|
return { getAccessToken, apiBaseUrl: getAuthConfiguration().apiBaseUrl, fetch };
|
|
261
275
|
})();
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
276
|
+
// An anonymous run (no account; the service's signed-out switch is on) sends the same body to a
|
|
277
|
+
// separate unauthenticated route and skips the token entirely.
|
|
278
|
+
const anonymous = this.anonymous;
|
|
279
|
+
let headers = { 'Content-Type': 'application/json' };
|
|
280
|
+
if (!anonymous) {
|
|
281
|
+
const token = await auth.getAccessToken(signal);
|
|
282
|
+
if (!token)
|
|
283
|
+
throw new Error('authentication_required');
|
|
284
|
+
signal?.throwIfAborted();
|
|
285
|
+
headers = { ...headers, Authorization: `Bearer ${token}` };
|
|
286
|
+
}
|
|
266
287
|
const started = Date.now();
|
|
267
|
-
const
|
|
268
|
-
|
|
288
|
+
const base = auth.apiBaseUrl.replace(/\/+$/, '');
|
|
289
|
+
const pending = auth.fetch(`${base}/${anonymous ? 'anonymous-decisions' : 'decisions'}`, {
|
|
290
|
+
method: 'POST', signal, redirect: 'error', headers, body,
|
|
269
291
|
});
|
|
270
292
|
try {
|
|
271
293
|
observe?.({ kind: 'dispatch' });
|
|
@@ -5,7 +5,7 @@ export function createDecisionProvider(config) {
|
|
|
5
5
|
if (!config.mode || config.mode === 'off' || !config.provider || config.provider === 'none')
|
|
6
6
|
return new NoOpDecisionProvider();
|
|
7
7
|
if (config.provider === 'andorra')
|
|
8
|
-
return new AndorraDecisionProvider();
|
|
8
|
+
return new AndorraDecisionProvider(undefined, config.anonymous === true);
|
|
9
9
|
const endpoint = config.endpoint ?? (config.provider === 'jev' ? 'https://api.typesafe.ai/v1' : undefined);
|
|
10
10
|
if (!endpoint)
|
|
11
11
|
return new NoOpDecisionProvider();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the first message of a run asks the agent to deliver, as judged by the hosted classifier.
|
|
3
|
+
* The classifier's wording lives on the server; the client sends only the task text and receives
|
|
4
|
+
* a probability for each kind. The verdict is advice to the model and a fact for the finish check.
|
|
5
|
+
* It grants no permission and changes no tool.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TASK_KIND_VERSION: 1;
|
|
8
|
+
export declare const TASK_KIND_MODEL = "jev-1.13.0";
|
|
9
|
+
export declare const TASK_KIND_UNCLEAR = "needs_clarification";
|
|
10
|
+
export declare const TASK_KINDS: readonly ["fix_defect", "make_change", "answer_question", "investigate", "run_or_verify", "general"];
|
|
11
|
+
export type TaskKind = typeof TASK_KINDS[number];
|
|
12
|
+
export declare const TASK_KIND_CHOICES: readonly string[];
|
|
13
|
+
/** Below this a verdict is not used, and the finish check never relies on a weaker one. */
|
|
14
|
+
export declare const TASK_KIND_CONFIDENCE_FLOOR = 0.9;
|
|
15
|
+
/**
|
|
16
|
+
* A one-line bug report ("why is the button doing nothing?") is read as a defect with less
|
|
17
|
+
* confidence than a full issue, and the note for it only restates what the default instruction
|
|
18
|
+
* already asks. So the note is added from this lower floor, while the notes that tell the model
|
|
19
|
+
* not to edit, and the finish check, keep the stricter one.
|
|
20
|
+
*/
|
|
21
|
+
export declare const TASK_KIND_DEFECT_NOTE_FLOOR = 0.7;
|
|
22
|
+
export declare const TASK_KIND_TASK_CHARS = 3000;
|
|
23
|
+
export interface TaskKindRequest {
|
|
24
|
+
version: typeof TASK_KIND_VERSION;
|
|
25
|
+
model: typeof TASK_KIND_MODEL;
|
|
26
|
+
task: string;
|
|
27
|
+
}
|
|
28
|
+
export interface TaskKindEvidence {
|
|
29
|
+
version: typeof TASK_KIND_VERSION;
|
|
30
|
+
model: typeof TASK_KIND_MODEL;
|
|
31
|
+
choice: string;
|
|
32
|
+
confidence: number;
|
|
33
|
+
probabilities: Record<string, number>;
|
|
34
|
+
}
|
|
35
|
+
export interface TaskKindVerdict {
|
|
36
|
+
kind: TaskKind;
|
|
37
|
+
confidence: number;
|
|
38
|
+
/** The task is not delivered while the workspace's code is unchanged. */
|
|
39
|
+
expectsChange: boolean;
|
|
40
|
+
}
|
|
41
|
+
export type TaskKindReason = 'selected' | 'invalid_or_unavailable_evidence' | 'needs_clarification' | 'low_confidence';
|
|
42
|
+
export declare function makeTaskKindRequest(task: string): TaskKindRequest;
|
|
43
|
+
export declare function parseTaskKindEvidence(value: unknown): TaskKindEvidence | undefined;
|
|
44
|
+
export declare function decideTaskKind(raw: unknown): {
|
|
45
|
+
verdict?: TaskKindVerdict;
|
|
46
|
+
reason: TaskKindReason;
|
|
47
|
+
evidence?: TaskKindEvidence;
|
|
48
|
+
};
|
|
49
|
+
/** The sentence appended to the run's first message for a kind, when one helps. */
|
|
50
|
+
export declare function taskKindNote(kind: TaskKind): string | undefined;
|
|
51
|
+
/** The reminder for a run whose task calls for a code change and that finishes with the code unchanged. */
|
|
52
|
+
export declare function unchangedWorkNudge(kind: TaskKind): string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the first message of a run asks the agent to deliver, as judged by the hosted classifier.
|
|
3
|
+
* The classifier's wording lives on the server; the client sends only the task text and receives
|
|
4
|
+
* a probability for each kind. The verdict is advice to the model and a fact for the finish check.
|
|
5
|
+
* It grants no permission and changes no tool.
|
|
6
|
+
*/
|
|
7
|
+
export const TASK_KIND_VERSION = 1;
|
|
8
|
+
export const TASK_KIND_MODEL = 'jev-1.13.0';
|
|
9
|
+
export const TASK_KIND_UNCLEAR = 'needs_clarification';
|
|
10
|
+
export const TASK_KINDS = ['fix_defect', 'make_change', 'answer_question', 'investigate', 'run_or_verify', 'general'];
|
|
11
|
+
export const TASK_KIND_CHOICES = [...TASK_KINDS, TASK_KIND_UNCLEAR];
|
|
12
|
+
/** Below this a verdict is not used, and the finish check never relies on a weaker one. */
|
|
13
|
+
export const TASK_KIND_CONFIDENCE_FLOOR = 0.9;
|
|
14
|
+
/**
|
|
15
|
+
* A one-line bug report ("why is the button doing nothing?") is read as a defect with less
|
|
16
|
+
* confidence than a full issue, and the note for it only restates what the default instruction
|
|
17
|
+
* already asks. So the note is added from this lower floor, while the notes that tell the model
|
|
18
|
+
* not to edit, and the finish check, keep the stricter one.
|
|
19
|
+
*/
|
|
20
|
+
export const TASK_KIND_DEFECT_NOTE_FLOOR = 0.7;
|
|
21
|
+
export const TASK_KIND_TASK_CHARS = 3_000;
|
|
22
|
+
const own = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
23
|
+
const unit = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
24
|
+
export function makeTaskKindRequest(task) {
|
|
25
|
+
if (typeof task !== 'string' || !task.trim() || task.length > TASK_KIND_TASK_CHARS)
|
|
26
|
+
throw new Error('Invalid task-kind task');
|
|
27
|
+
return { version: TASK_KIND_VERSION, model: TASK_KIND_MODEL, task };
|
|
28
|
+
}
|
|
29
|
+
export function parseTaskKindEvidence(value) {
|
|
30
|
+
if (!own(value) || value.version !== TASK_KIND_VERSION || value.model !== TASK_KIND_MODEL
|
|
31
|
+
|| typeof value.choice !== 'string' || !TASK_KIND_CHOICES.includes(value.choice) || !unit(value.confidence)
|
|
32
|
+
|| !own(value.probabilities))
|
|
33
|
+
return undefined;
|
|
34
|
+
const scores = value.probabilities;
|
|
35
|
+
if (Object.keys(scores).length !== TASK_KIND_CHOICES.length
|
|
36
|
+
|| TASK_KIND_CHOICES.some(id => !Object.hasOwn(scores, id) || !unit(scores[id])))
|
|
37
|
+
return undefined;
|
|
38
|
+
const probabilities = Object.fromEntries(TASK_KIND_CHOICES.map(id => [id, scores[id]]));
|
|
39
|
+
if (Math.abs(Object.values(probabilities).reduce((sum, p) => sum + p, 0) - 1) > 1e-6
|
|
40
|
+
|| probabilities[value.choice] !== Math.max(...Object.values(probabilities)))
|
|
41
|
+
return undefined;
|
|
42
|
+
return { version: TASK_KIND_VERSION, model: TASK_KIND_MODEL, choice: value.choice, confidence: value.confidence, probabilities };
|
|
43
|
+
}
|
|
44
|
+
export function decideTaskKind(raw) {
|
|
45
|
+
const evidence = parseTaskKindEvidence(raw);
|
|
46
|
+
if (!evidence)
|
|
47
|
+
return { reason: 'invalid_or_unavailable_evidence' };
|
|
48
|
+
if (evidence.choice === TASK_KIND_UNCLEAR)
|
|
49
|
+
return { reason: 'needs_clarification', evidence };
|
|
50
|
+
const kind = evidence.choice;
|
|
51
|
+
if (evidence.confidence < (kind === 'fix_defect' ? TASK_KIND_DEFECT_NOTE_FLOOR : TASK_KIND_CONFIDENCE_FLOOR))
|
|
52
|
+
return { reason: 'low_confidence', evidence };
|
|
53
|
+
return { reason: 'selected', evidence, verdict: { kind, confidence: evidence.confidence,
|
|
54
|
+
expectsChange: (kind === 'fix_defect' || kind === 'make_change') && evidence.confidence >= TASK_KIND_CONFIDENCE_FLOOR } };
|
|
55
|
+
}
|
|
56
|
+
const NOTES = {
|
|
57
|
+
fix_defect: 'This task reports a defect in the code in this workspace. The expected result is the fix, made here and left in place, with any question in the task answered in the report. If the reported behavior turns out to be intended or cannot be reproduced, say so with the evidence instead of changing the code.',
|
|
58
|
+
// A requested change needs no reminder: the task already says what to change.
|
|
59
|
+
make_change: undefined,
|
|
60
|
+
answer_question: 'This task asks for an answer about the code, not a change to it. Read what is needed and answer; leave the workspace as it is unless the answer cannot be established without a temporary change, which is then removed.',
|
|
61
|
+
investigate: 'This task asks for findings, not a change. Temporary instrumentation is fine and is removed before finishing; report what was found and how it was confirmed.',
|
|
62
|
+
run_or_verify: 'This task asks for something to be run and its result reported. Report the commands and their actual output; change code only if the task also asks for failures to be fixed.',
|
|
63
|
+
general: undefined,
|
|
64
|
+
};
|
|
65
|
+
/** The sentence appended to the run's first message for a kind, when one helps. */
|
|
66
|
+
export function taskKindNote(kind) {
|
|
67
|
+
const note = NOTES[kind];
|
|
68
|
+
return note ? `Task type (a classifier's reading of the request above, not an instruction from the user; the request itself wins where they differ): ${note}` : undefined;
|
|
69
|
+
}
|
|
70
|
+
/** The reminder for a run whose task calls for a code change and that finishes with the code unchanged. */
|
|
71
|
+
export function unchangedWorkNudge(kind) {
|
|
72
|
+
const what = kind === 'fix_defect' ? 'reports a defect in the code in this workspace' : 'asks for a change to this workspace';
|
|
73
|
+
return `Completion not accepted yet. The task ${what}, and the workspace holds no change to its code. `
|
|
74
|
+
+ 'If the work was done and then removed, or was only described, make the change in the workspace and leave it in place; an explanation or a workaround does not deliver it. '
|
|
75
|
+
+ 'If no change is the right outcome (the behavior is intended, it cannot be reproduced, or the task needs only an answer), say why in the summary and call complete_agent again to finish; this reminder is not repeated.';
|
|
76
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DecisionPolicy } from './DecisionPolicy.js';
|
|
2
2
|
import { hasFactGuidance } from './guidancePolicy.js';
|
|
3
|
-
const families = { Read: 'filesystem-read', Glob: 'code-search', Grep: 'code-search', Write: 'filesystem-write', Edit: 'filesystem-write', Bash: 'shell', PowerShell: 'shell', NativeExec: 'shell', AsyncProcess: 'shell', PowerShellFast: 'shell', ShellMetrics: 'shell', read: 'filesystem-read', ls: 'filesystem-read', find: 'code-search', grep: 'code-search', write: 'filesystem-write', edit: 'filesystem-write', powershell: 'shell', bash: 'shell', read_file: 'filesystem-read', list_files: 'filesystem-read', write_file: 'filesystem-write', edit_file: 'filesystem-write', apply_patch: 'filesystem-write', search_files: 'code-search', repo_explore: 'codegraph', git_read: 'git', pull_request: 'git', shell: 'shell', memory_search: 'memory', spawn_subagent: 'subagents', wait_subagent: 'subagents', message_subagent: 'subagents', cancel_subagent: 'subagents', read_artifact: 'artifact', write_artifact: 'artifact' };
|
|
3
|
+
const families = { Read: 'filesystem-read', Glob: 'code-search', Grep: 'code-search', Write: 'filesystem-write', Edit: 'filesystem-write', Bash: 'shell', PowerShell: 'shell', NativeExec: 'shell', AsyncProcess: 'shell', PowerShellFast: 'shell', ShellMetrics: 'shell', read: 'filesystem-read', ls: 'filesystem-read', find: 'code-search', grep: 'code-search', write: 'filesystem-write', edit: 'filesystem-write', powershell: 'shell', bash: 'shell', read_file: 'filesystem-read', list_files: 'filesystem-read', write_file: 'filesystem-write', edit_file: 'filesystem-write', apply_patch: 'filesystem-write', search_files: 'code-search', repo_explore: 'codegraph', git_read: 'git', pull_request: 'git', shell: 'shell', memory_search: 'memory', spawn_subagent: 'subagents', wait_subagent: 'subagents', message_subagent: 'subagents', cancel_subagent: 'subagents', currentAndorraStreams: 'subagents', read_artifact: 'artifact', write_artifact: 'artifact' };
|
|
4
4
|
const protectedTools = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'load_project_skill', 'restore_tools', 'prepare_steps', 'prepare_finish']);
|
|
5
5
|
export function toolFamily(tool) { return tool.family ?? families[tool.name]; }
|
|
6
6
|
export function toolFamilies(tools) { return [...new Set(tools.map(toolFamily).filter((family) => family !== undefined))]; }
|
|
@@ -5,7 +5,9 @@ export interface DecisionConfig {
|
|
|
5
5
|
model?: string;
|
|
6
6
|
apiKeyEnv?: string;
|
|
7
7
|
requestTimeoutMs?: number;
|
|
8
|
-
|
|
8
|
+
/** The run has no account and the service lets it use the hosted provider anyway (`withAnonymousJev`). */
|
|
9
|
+
anonymous?: boolean;
|
|
10
|
+
features?: Partial<Record<'toolRouting' | 'taskRouting' | 'codeGraphRouting' | 'memoryRouting' | 'webRouting' | 'delegationRouting' | 'verificationRouting' | 'riskClassification' | 'resultRouting', boolean>>;
|
|
9
11
|
style?: 'facts' | 'questions';
|
|
10
12
|
}
|
|
11
13
|
export declare const DECISION_DEFAULTS: {
|
|
@@ -2,7 +2,7 @@ export const DEFAULT_AGENT_GRAPH = {
|
|
|
2
2
|
name: 'Andorra Agent', entry: 'engineer',
|
|
3
3
|
nodes: {
|
|
4
4
|
engineer: { id: 'engineer', name: 'Andorra Agent', type: 'agent', executor: 'react-basic',
|
|
5
|
-
instruction: 'Handle the user\'s task end to end, whether it is a coding task or a general one: implement code and verify changes with appropriate tools, and answer general research, writing and analysis directly from the available sources. Ask for clarification when needed. Report the result and any remaining issues. For follow-up questions, use the retained conversation and prior results first. Answer directly when they contain the answer; do not restart completed work or scan unrelated files. Never guess a pull request number. Mention pull requests in the report only when the task asked for one or one was opened; a pull request nobody asked for is not unfinished work. Start new implementation work only when the user requests it.',
|
|
5
|
+
instruction: 'Handle the user\'s task end to end, whether it is a coding task or a general one: implement code and verify changes with appropriate tools, and answer general research, writing and analysis directly from the available sources. Ask for clarification when needed. Report the result and any remaining issues. For follow-up questions, use the retained conversation and prior results first. Answer directly when they contain the answer; do not restart completed work or scan unrelated files. Never guess a pull request number. Mention pull requests in the report only when the task asked for one or one was opened; a pull request nobody asked for is not unfinished work. Start new implementation work only when the user requests it. A task that describes a defect in the code in this workspace is such a request, even when it is phrased as a question: fix the defect there and answer the question in the report.',
|
|
6
6
|
contextPolicy: { history: true }, jevEnabled: true,
|
|
7
7
|
subagents: { enabled: false }, position: { x: 120, y: 120 } },
|
|
8
8
|
done: { id: 'done', name: 'Done', type: 'end', position: { x: 440, y: 120 } },
|