@wix/pathgrade 0.29.0
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/bin/pathgrade.js +2 -0
- package/dist/affected/anchor.d.ts +18 -0
- package/dist/affected/anchor.js +42 -0
- package/dist/affected/config.d.ts +25 -0
- package/dist/affected/config.js +98 -0
- package/dist/affected/format.d.ts +45 -0
- package/dist/affected/format.js +87 -0
- package/dist/affected/git.d.ts +33 -0
- package/dist/affected/git.js +68 -0
- package/dist/affected/glob.d.ts +17 -0
- package/dist/affected/glob.js +25 -0
- package/dist/affected/meta.d.ts +26 -0
- package/dist/affected/meta.js +158 -0
- package/dist/affected/select.d.ts +30 -0
- package/dist/affected/select.js +101 -0
- package/dist/affected/sidecar.d.ts +32 -0
- package/dist/affected/sidecar.js +86 -0
- package/dist/affected/types.d.ts +43 -0
- package/dist/affected/types.js +7 -0
- package/dist/agents/claude/ask-user-answer-store.d.ts +28 -0
- package/dist/agents/claude/ask-user-answer-store.js +29 -0
- package/dist/agents/claude/ask-user-bridge.d.ts +56 -0
- package/dist/agents/claude/ask-user-bridge.js +162 -0
- package/dist/agents/claude/sdk-message-projector.d.ts +43 -0
- package/dist/agents/claude/sdk-message-projector.js +208 -0
- package/dist/agents/claude/sdk-options.d.ts +52 -0
- package/dist/agents/claude/sdk-options.js +79 -0
- package/dist/agents/claude.d.ts +56 -0
- package/dist/agents/claude.js +143 -0
- package/dist/agents/codex-app-server/agent.d.ts +35 -0
- package/dist/agents/codex-app-server/agent.js +388 -0
- package/dist/agents/codex-app-server/fixtures/app-server-client.d.ts +19 -0
- package/dist/agents/codex-app-server/fixtures/app-server-client.js +104 -0
- package/dist/agents/codex-app-server/fixtures/run-gate.d.ts +25 -0
- package/dist/agents/codex-app-server/fixtures/run-gate.js +48 -0
- package/dist/agents/codex-app-server/protocol/ClientRequest.d.ts +27 -0
- package/dist/agents/codex-app-server/protocol/ClientRequest.js +7 -0
- package/dist/agents/codex-app-server/protocol/DynamicToolCallParams.d.ts +9 -0
- package/dist/agents/codex-app-server/protocol/DynamicToolCallParams.js +4 -0
- package/dist/agents/codex-app-server/protocol/GrantedPermissionProfile.d.ts +6 -0
- package/dist/agents/codex-app-server/protocol/GrantedPermissionProfile.js +7 -0
- package/dist/agents/codex-app-server/protocol/McpElicitationRequestParams.d.ts +23 -0
- package/dist/agents/codex-app-server/protocol/McpElicitationRequestParams.js +8 -0
- package/dist/agents/codex-app-server/protocol/Op.d.ts +11 -0
- package/dist/agents/codex-app-server/protocol/Op.js +5 -0
- package/dist/agents/codex-app-server/protocol/PermissionsRequestApprovalParams.d.ts +10 -0
- package/dist/agents/codex-app-server/protocol/PermissionsRequestApprovalParams.js +6 -0
- package/dist/agents/codex-app-server/protocol/PermissionsRequestApprovalResponse.d.ts +15 -0
- package/dist/agents/codex-app-server/protocol/PermissionsRequestApprovalResponse.js +4 -0
- package/dist/agents/codex-app-server/protocol/SandboxMode.d.ts +1 -0
- package/dist/agents/codex-app-server/protocol/SandboxMode.js +4 -0
- package/dist/agents/codex-app-server/protocol/ServerRequest.d.ts +42 -0
- package/dist/agents/codex-app-server/protocol/ServerRequest.js +7 -0
- package/dist/agents/codex-app-server/protocol/ThreadStartParams.d.ts +45 -0
- package/dist/agents/codex-app-server/protocol/ThreadStartParams.js +10 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputAnswer.d.ts +6 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputAnswer.js +4 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputOption.d.ts +7 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputOption.js +4 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputParams.d.ts +10 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputParams.js +4 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputQuestion.d.ts +12 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputQuestion.js +4 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputResponse.d.ts +9 -0
- package/dist/agents/codex-app-server/protocol/ToolRequestUserInputResponse.js +4 -0
- package/dist/agents/codex-app-server/protocol/TurnCompletedNotification.d.ts +5 -0
- package/dist/agents/codex-app-server/protocol/TurnCompletedNotification.js +4 -0
- package/dist/agents/codex-app-server/protocol/index.d.ts +16 -0
- package/dist/agents/codex-app-server/protocol/index.js +11 -0
- package/dist/agents/codex-app-server/transport.d.ts +84 -0
- package/dist/agents/codex-app-server/transport.js +246 -0
- package/dist/agents/codex-app-server/wire-translators.d.ts +19 -0
- package/dist/agents/codex-app-server/wire-translators.js +52 -0
- package/dist/agents/codex.d.ts +7 -0
- package/dist/agents/codex.js +164 -0
- package/dist/agents/cursor.d.ts +39 -0
- package/dist/agents/cursor.js +233 -0
- package/dist/agents/registry.d.ts +17 -0
- package/dist/agents/registry.js +27 -0
- package/dist/agents/transcript-agent.d.ts +14 -0
- package/dist/agents/transcript-agent.js +59 -0
- package/dist/analytics/engine.d.ts +18 -0
- package/dist/analytics/engine.js +66 -0
- package/dist/commands/affected.d.ts +31 -0
- package/dist/commands/affected.js +150 -0
- package/dist/commands/analyze.d.ts +21 -0
- package/dist/commands/analyze.js +167 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +242 -0
- package/dist/commands/preview-reactions.d.ts +10 -0
- package/dist/commands/preview-reactions.js +88 -0
- package/dist/commands/preview.d.ts +5 -0
- package/dist/commands/preview.js +17 -0
- package/dist/commands/report.d.ts +39 -0
- package/dist/commands/report.js +108 -0
- package/dist/commands/run-args.d.ts +22 -0
- package/dist/commands/run-args.js +69 -0
- package/dist/commands/run-changed.d.ts +26 -0
- package/dist/commands/run-changed.js +138 -0
- package/dist/commands/validate.d.ts +13 -0
- package/dist/commands/validate.js +233 -0
- package/dist/core/mcp-mock.d.ts +3 -0
- package/dist/core/mcp-mock.js +23 -0
- package/dist/core/mcp-mock.types.d.ts +15 -0
- package/dist/core/mcp-mock.types.js +1 -0
- package/dist/core/skills.d.ts +15 -0
- package/dist/core/skills.js +76 -0
- package/dist/evals/discovery.d.ts +7 -0
- package/dist/evals/discovery.js +69 -0
- package/dist/mcp-mock-server.d.ts +1 -0
- package/dist/mcp-mock-server.js +116 -0
- package/dist/pathgrade.d.ts +10 -0
- package/dist/pathgrade.js +243 -0
- package/dist/plugin/index.d.ts +9 -0
- package/dist/plugin/index.js +81 -0
- package/dist/plugin/lifecycle.d.ts +45 -0
- package/dist/plugin/lifecycle.js +146 -0
- package/dist/plugin/reporter.d.ts +36 -0
- package/dist/plugin/reporter.js +275 -0
- package/dist/plugin/setup.d.ts +1 -0
- package/dist/plugin/setup.js +3 -0
- package/dist/providers/copy-filter.d.ts +18 -0
- package/dist/providers/copy-filter.js +66 -0
- package/dist/providers/credentials.d.ts +36 -0
- package/dist/providers/credentials.js +202 -0
- package/dist/providers/mcp-config.d.ts +34 -0
- package/dist/providers/mcp-config.js +55 -0
- package/dist/providers/sandbox-exec.d.ts +8 -0
- package/dist/providers/sandbox-exec.js +82 -0
- package/dist/providers/sandbox.d.ts +22 -0
- package/dist/providers/sandbox.js +158 -0
- package/dist/providers/sandboxed-claude-spawn.d.ts +24 -0
- package/dist/providers/sandboxed-claude-spawn.js +57 -0
- package/dist/providers/workspace.d.ts +15 -0
- package/dist/providers/workspace.js +73 -0
- package/dist/reporters/browser.d.ts +2 -0
- package/dist/reporters/browser.js +85 -0
- package/dist/reporters/cli.d.ts +2 -0
- package/dist/reporters/cli.js +131 -0
- package/dist/reporters/diagnostics.d.ts +46 -0
- package/dist/reporters/diagnostics.js +147 -0
- package/dist/reporters/github-comment.d.ts +67 -0
- package/dist/reporters/github-comment.js +252 -0
- package/dist/reporters/loader.d.ts +8 -0
- package/dist/reporters/loader.js +36 -0
- package/dist/reporters/results-path.d.ts +2 -0
- package/dist/reporters/results-path.js +10 -0
- package/dist/reporters/verbose-emitter.d.ts +69 -0
- package/dist/reporters/verbose-emitter.js +103 -0
- package/dist/sdk/agent-crash.d.ts +19 -0
- package/dist/sdk/agent-crash.js +20 -0
- package/dist/sdk/agent-resolution.d.ts +12 -0
- package/dist/sdk/agent-resolution.js +21 -0
- package/dist/sdk/agent-result-log.d.ts +19 -0
- package/dist/sdk/agent-result-log.js +45 -0
- package/dist/sdk/agent.d.ts +4 -0
- package/dist/sdk/agent.js +354 -0
- package/dist/sdk/ask-bus/bus.d.ts +21 -0
- package/dist/sdk/ask-bus/bus.js +129 -0
- package/dist/sdk/ask-bus/handler.d.ts +31 -0
- package/dist/sdk/ask-bus/handler.js +244 -0
- package/dist/sdk/ask-bus/parsers.d.ts +9 -0
- package/dist/sdk/ask-bus/parsers.js +30 -0
- package/dist/sdk/ask-bus/projection.d.ts +26 -0
- package/dist/sdk/ask-bus/projection.js +45 -0
- package/dist/sdk/ask-bus/types.d.ts +69 -0
- package/dist/sdk/ask-bus/types.js +1 -0
- package/dist/sdk/chat.d.ts +29 -0
- package/dist/sdk/chat.js +93 -0
- package/dist/sdk/conversation-window.d.ts +14 -0
- package/dist/sdk/conversation-window.js +38 -0
- package/dist/sdk/converse.d.ts +42 -0
- package/dist/sdk/converse.js +329 -0
- package/dist/sdk/eval-runtime.d.ts +10 -0
- package/dist/sdk/eval-runtime.js +17 -0
- package/dist/sdk/evaluate.d.ts +13 -0
- package/dist/sdk/evaluate.js +325 -0
- package/dist/sdk/index.d.ts +31 -0
- package/dist/sdk/index.js +20 -0
- package/dist/sdk/judge-pipeline.d.ts +7 -0
- package/dist/sdk/judge-pipeline.js +178 -0
- package/dist/sdk/judge-prompt-builder.d.ts +7 -0
- package/dist/sdk/judge-prompt-builder.js +76 -0
- package/dist/sdk/judge-tool-runner.d.ts +19 -0
- package/dist/sdk/judge-tool-runner.js +51 -0
- package/dist/sdk/judge-tool-session.d.ts +47 -0
- package/dist/sdk/judge-tool-session.js +213 -0
- package/dist/sdk/judge-tools.d.ts +29 -0
- package/dist/sdk/judge-tools.js +283 -0
- package/dist/sdk/managed-session.d.ts +50 -0
- package/dist/sdk/managed-session.js +110 -0
- package/dist/sdk/persona.d.ts +5 -0
- package/dist/sdk/persona.js +33 -0
- package/dist/sdk/reaction-loader.d.ts +4 -0
- package/dist/sdk/reaction-loader.js +119 -0
- package/dist/sdk/reaction-preview.d.ts +6 -0
- package/dist/sdk/reaction-preview.js +94 -0
- package/dist/sdk/run-scorer.d.ts +10 -0
- package/dist/sdk/run-scorer.js +124 -0
- package/dist/sdk/runtime-policy.d.ts +21 -0
- package/dist/sdk/runtime-policy.js +89 -0
- package/dist/sdk/scorer-utils.d.ts +6 -0
- package/dist/sdk/scorer-utils.js +39 -0
- package/dist/sdk/scorers.d.ts +64 -0
- package/dist/sdk/scorers.js +80 -0
- package/dist/sdk/snapshots.d.ts +41 -0
- package/dist/sdk/snapshots.js +148 -0
- package/dist/sdk/types.d.ts +416 -0
- package/dist/sdk/types.js +17 -0
- package/dist/sdk/visible-turn.d.ts +4 -0
- package/dist/sdk/visible-turn.js +23 -0
- package/dist/tool-events.d.ts +45 -0
- package/dist/tool-events.js +167 -0
- package/dist/types.d.ts +372 -0
- package/dist/types.js +37 -0
- package/dist/utils/cli.d.ts +55 -0
- package/dist/utils/cli.js +131 -0
- package/dist/utils/env.d.ts +8 -0
- package/dist/utils/env.js +26 -0
- package/dist/utils/llm-mocks.d.ts +43 -0
- package/dist/utils/llm-mocks.js +108 -0
- package/dist/utils/llm-providers/anthropic.d.ts +2 -0
- package/dist/utils/llm-providers/anthropic.js +132 -0
- package/dist/utils/llm-providers/cli.d.ts +20 -0
- package/dist/utils/llm-providers/cli.js +162 -0
- package/dist/utils/llm-providers/openai.d.ts +2 -0
- package/dist/utils/llm-providers/openai.js +56 -0
- package/dist/utils/llm-types.d.ts +107 -0
- package/dist/utils/llm-types.js +1 -0
- package/dist/utils/llm.d.ts +36 -0
- package/dist/utils/llm.js +209 -0
- package/dist/utils/shutdown.d.ts +15 -0
- package/dist/utils/shutdown.js +41 -0
- package/dist/utils/timeout.d.ts +8 -0
- package/dist/utils/timeout.js +32 -0
- package/dist/viewer.html +1178 -0
- package/package.json +88 -0
- package/templates/eval.ts.template +28 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { cliProvider } from './llm-providers/cli.js';
|
|
2
|
+
import { anthropicProvider } from './llm-providers/anthropic.js';
|
|
3
|
+
import { openaiProvider } from './llm-providers/openai.js';
|
|
4
|
+
export class ProviderNotSupportedError extends Error {
|
|
5
|
+
name = 'ProviderNotSupportedError';
|
|
6
|
+
adapterName;
|
|
7
|
+
constructor(adapterName) {
|
|
8
|
+
super(`Adapter '${adapterName}' does not implement callWithTools. `
|
|
9
|
+
+ 'Use an adapter that supports tool use (e.g., anthropicAdapter when '
|
|
10
|
+
+ 'ANTHROPIC_API_KEY is set) or remove tools from this judge.');
|
|
11
|
+
this.adapterName = adapterName;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// Re-export provider utilities that callsites depend on
|
|
15
|
+
export { isClaudeCliAvailable, isCodexCliAvailable, resetCliCache, extractStructuredOutput, parseCliEnvelope } from './llm-providers/cli.js';
|
|
16
|
+
function inferProviderFromModel(model) {
|
|
17
|
+
const normalized = model?.trim().toLowerCase();
|
|
18
|
+
if (!normalized)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (normalized.startsWith('claude'))
|
|
21
|
+
return 'anthropic';
|
|
22
|
+
if (normalized.startsWith('gpt-')
|
|
23
|
+
|| normalized.startsWith('chatgpt-')
|
|
24
|
+
|| normalized.startsWith('o1')
|
|
25
|
+
|| normalized.startsWith('o3')
|
|
26
|
+
|| normalized.startsWith('o4')) {
|
|
27
|
+
return 'openai';
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
export function createLLMClient(arg, legacyAgentName) {
|
|
32
|
+
const options = Array.isArray(arg)
|
|
33
|
+
? { adapters: arg, agent: legacyAgentName }
|
|
34
|
+
: arg;
|
|
35
|
+
const providers = options.adapters ?? [];
|
|
36
|
+
const agentName = options.agent;
|
|
37
|
+
const silent = options.silent === true;
|
|
38
|
+
const warnedTransitions = new Set();
|
|
39
|
+
let inputTokens = 0;
|
|
40
|
+
let outputTokens = 0;
|
|
41
|
+
let costUsd = 0;
|
|
42
|
+
let lastProvider;
|
|
43
|
+
const warnFallthrough = (from, to, reason) => {
|
|
44
|
+
if (silent)
|
|
45
|
+
return;
|
|
46
|
+
const key = `${from}→${to}`;
|
|
47
|
+
if (warnedTransitions.has(key))
|
|
48
|
+
return;
|
|
49
|
+
warnedTransitions.add(key);
|
|
50
|
+
console.warn(`pathgrade: LLM provider fallthrough: ${from} failed (${reason}), using ${to}`);
|
|
51
|
+
};
|
|
52
|
+
const accumulate = (result) => {
|
|
53
|
+
inputTokens += result.inputTokens ?? 0;
|
|
54
|
+
outputTokens += result.outputTokens ?? 0;
|
|
55
|
+
};
|
|
56
|
+
const toolCapable = providers.find((p) => typeof p.callWithTools === 'function');
|
|
57
|
+
const port = {
|
|
58
|
+
get tokenUsage() {
|
|
59
|
+
return { inputTokens, outputTokens };
|
|
60
|
+
},
|
|
61
|
+
get costUsd() {
|
|
62
|
+
return costUsd;
|
|
63
|
+
},
|
|
64
|
+
get supportsToolUse() {
|
|
65
|
+
return !!toolCapable;
|
|
66
|
+
},
|
|
67
|
+
get lastProvider() {
|
|
68
|
+
return lastProvider;
|
|
69
|
+
},
|
|
70
|
+
addTokens(input, output) {
|
|
71
|
+
inputTokens += input;
|
|
72
|
+
outputTokens += output;
|
|
73
|
+
},
|
|
74
|
+
addCost(usd) {
|
|
75
|
+
// Defensive: ignore non-finite or negative deltas. The SDK
|
|
76
|
+
// reports a non-negative finite total_cost_usd in practice;
|
|
77
|
+
// anything else is corrupt and should not poison the tracker.
|
|
78
|
+
if (!Number.isFinite(usd) || usd < 0)
|
|
79
|
+
return;
|
|
80
|
+
costUsd += usd;
|
|
81
|
+
},
|
|
82
|
+
async measure(fn) {
|
|
83
|
+
const inBefore = inputTokens;
|
|
84
|
+
const outBefore = outputTokens;
|
|
85
|
+
const costBefore = costUsd;
|
|
86
|
+
const result = await fn();
|
|
87
|
+
return {
|
|
88
|
+
result,
|
|
89
|
+
tokens: {
|
|
90
|
+
inputTokens: inputTokens - inBefore,
|
|
91
|
+
outputTokens: outputTokens - outBefore,
|
|
92
|
+
},
|
|
93
|
+
costUsd: costUsd - costBefore,
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
async call(prompt, opts = {}) {
|
|
97
|
+
const requestedProviderType = inferProviderFromModel(opts.model);
|
|
98
|
+
// Filter to providers that support the requested model
|
|
99
|
+
let candidates = opts.model
|
|
100
|
+
? providers.filter((p) => !p.supportsModel || p.supportsModel(opts.model))
|
|
101
|
+
: providers;
|
|
102
|
+
// If model explicitly targets a provider type (e.g., "gpt-4o" → openai),
|
|
103
|
+
// narrow to only providers of that type
|
|
104
|
+
const narrowed = requestedProviderType
|
|
105
|
+
? candidates.filter((p) => p.name === requestedProviderType)
|
|
106
|
+
: candidates;
|
|
107
|
+
// Try narrowed set first, then fall back to all candidates
|
|
108
|
+
const toTry = narrowed.length > 0 ? narrowed : candidates;
|
|
109
|
+
let lastError;
|
|
110
|
+
let lastFailed;
|
|
111
|
+
for (const provider of toTry) {
|
|
112
|
+
if (!await provider.isAvailable(opts.env))
|
|
113
|
+
continue;
|
|
114
|
+
try {
|
|
115
|
+
const result = await provider.call(prompt, opts);
|
|
116
|
+
if (lastFailed)
|
|
117
|
+
warnFallthrough(lastFailed.name, provider.name, lastFailed.reason);
|
|
118
|
+
accumulate(result);
|
|
119
|
+
lastProvider = provider.name;
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
lastError = error;
|
|
124
|
+
lastFailed = { name: provider.name, reason: lastError.message };
|
|
125
|
+
// Fall through to next provider
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// If narrowed set failed/was unavailable, fall back to all candidates
|
|
129
|
+
if (toTry !== candidates) {
|
|
130
|
+
for (const provider of candidates) {
|
|
131
|
+
if (toTry.includes(provider))
|
|
132
|
+
continue; // already tried
|
|
133
|
+
if (!await provider.isAvailable(opts.env))
|
|
134
|
+
continue;
|
|
135
|
+
try {
|
|
136
|
+
const result = await provider.call(prompt, opts);
|
|
137
|
+
if (lastFailed)
|
|
138
|
+
warnFallthrough(lastFailed.name, provider.name, lastFailed.reason);
|
|
139
|
+
accumulate(result);
|
|
140
|
+
lastProvider = provider.name;
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
lastError = error;
|
|
145
|
+
lastFailed = { name: provider.name, reason: lastError.message };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (lastError)
|
|
150
|
+
throw lastError;
|
|
151
|
+
if (agentName === 'claude') {
|
|
152
|
+
throw new Error('Claude CLI not found on PATH. Install with: npm install -g @anthropic-ai/claude-code');
|
|
153
|
+
}
|
|
154
|
+
if (agentName === 'codex') {
|
|
155
|
+
throw new Error('Codex CLI not found on PATH. Install with: npm install -g @openai/codex');
|
|
156
|
+
}
|
|
157
|
+
if (agentName === 'cursor') {
|
|
158
|
+
throw new Error('Cursor eval requires a judge LLM; set ANTHROPIC_API_KEY or install Claude CLI, or override the judge model.');
|
|
159
|
+
}
|
|
160
|
+
throw new Error('No LLM backend available. Install Claude CLI (claude.ai) or set ANTHROPIC_API_KEY or OPENAI_API_KEY.');
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
if (toolCapable) {
|
|
164
|
+
port.callWithTools = async (messages, opts) => {
|
|
165
|
+
if (!await toolCapable.isAvailable(opts.env)) {
|
|
166
|
+
throw new Error('Tool-use judge requires ANTHROPIC_API_KEY; the Anthropic HTTP provider is not available.');
|
|
167
|
+
}
|
|
168
|
+
const result = await toolCapable.callWithTools(messages, opts);
|
|
169
|
+
accumulate(result);
|
|
170
|
+
lastProvider = toolCapable.name;
|
|
171
|
+
return result;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return port;
|
|
175
|
+
}
|
|
176
|
+
const defaultClient = createLLMClient([cliProvider, anthropicProvider, openaiProvider]);
|
|
177
|
+
export async function callLLM(prompt, opts = {}) {
|
|
178
|
+
return defaultClient.call(prompt, opts);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create an LLM client scoped to the providers that match the given agent.
|
|
182
|
+
*
|
|
183
|
+
* - claude → CLI + Anthropic API (no OpenAI fallthrough)
|
|
184
|
+
* - codex → OpenAI API
|
|
185
|
+
*
|
|
186
|
+
* If `agentEnv` is provided, it is merged into every LLM call so that
|
|
187
|
+
* the agent's env propagates to persona/judge/summarization calls.
|
|
188
|
+
*/
|
|
189
|
+
export function createAgentLLM(agentName, agentEnv) {
|
|
190
|
+
// Tool-using judges need a provider that implements callWithTools.
|
|
191
|
+
// For claude, anthropicProvider is added as a tool-use-capable fallback
|
|
192
|
+
// alongside the CLI. The CLI still wins for plain call() when available.
|
|
193
|
+
// Cursor inherits the Claude chain by design (judge consistency across
|
|
194
|
+
// harnesses — see PRD §"LLM-backend routing"). Cursor evals therefore
|
|
195
|
+
// depend on Claude CLI or ANTHROPIC_API_KEY being available at judge time.
|
|
196
|
+
const baseAdapters = agentName === 'codex'
|
|
197
|
+
? [openaiProvider]
|
|
198
|
+
: [cliProvider, anthropicProvider];
|
|
199
|
+
const adapters = agentEnv && Object.keys(agentEnv).length > 0
|
|
200
|
+
? baseAdapters.map((a) => ({
|
|
201
|
+
...a,
|
|
202
|
+
call: (prompt, opts) => a.call(prompt, { ...opts, env: { ...agentEnv, ...opts.env } }),
|
|
203
|
+
...(a.callWithTools
|
|
204
|
+
? { callWithTools: (messages, opts) => a.callWithTools(messages, { ...opts, env: { ...agentEnv, ...opts.env } }) }
|
|
205
|
+
: {}),
|
|
206
|
+
}))
|
|
207
|
+
: baseAdapters;
|
|
208
|
+
return createLLMClient({ adapters, agent: agentName });
|
|
209
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type CleanupFn = () => Promise<void>;
|
|
2
|
+
export declare class ShutdownManager {
|
|
3
|
+
private nextId;
|
|
4
|
+
private cleanups;
|
|
5
|
+
private shuttingDown;
|
|
6
|
+
private signalHandler;
|
|
7
|
+
register(cleanup: CleanupFn): number;
|
|
8
|
+
unregister(id: number): void;
|
|
9
|
+
shutdownAll(): Promise<void>;
|
|
10
|
+
install(): void;
|
|
11
|
+
uninstall(): void;
|
|
12
|
+
}
|
|
13
|
+
/** Global singleton for the CLI process */
|
|
14
|
+
export declare const shutdown: ShutdownManager;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export class ShutdownManager {
|
|
2
|
+
nextId = 0;
|
|
3
|
+
cleanups = new Map();
|
|
4
|
+
shuttingDown = false;
|
|
5
|
+
signalHandler;
|
|
6
|
+
register(cleanup) {
|
|
7
|
+
const id = this.nextId++;
|
|
8
|
+
this.cleanups.set(id, cleanup);
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
11
|
+
unregister(id) {
|
|
12
|
+
this.cleanups.delete(id);
|
|
13
|
+
}
|
|
14
|
+
async shutdownAll() {
|
|
15
|
+
if (this.shuttingDown)
|
|
16
|
+
return;
|
|
17
|
+
this.shuttingDown = true;
|
|
18
|
+
const tasks = [...this.cleanups.values()];
|
|
19
|
+
this.cleanups.clear();
|
|
20
|
+
await Promise.allSettled(tasks.map(fn => fn()));
|
|
21
|
+
}
|
|
22
|
+
install() {
|
|
23
|
+
if (this.signalHandler)
|
|
24
|
+
return;
|
|
25
|
+
this.signalHandler = () => {
|
|
26
|
+
this.shutdownAll().finally(() => process.exit(130));
|
|
27
|
+
};
|
|
28
|
+
process.on('SIGINT', this.signalHandler);
|
|
29
|
+
process.on('SIGTERM', this.signalHandler);
|
|
30
|
+
}
|
|
31
|
+
uninstall() {
|
|
32
|
+
if (this.signalHandler) {
|
|
33
|
+
process.removeListener('SIGINT', this.signalHandler);
|
|
34
|
+
process.removeListener('SIGTERM', this.signalHandler);
|
|
35
|
+
this.signalHandler = undefined;
|
|
36
|
+
}
|
|
37
|
+
this.shuttingDown = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Global singleton for the CLI process */
|
|
41
|
+
export const shutdown = new ShutdownManager();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared timeout utilities for agent and scorer execution.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Run an async function with an AbortSignal that fires after timeoutMs.
|
|
6
|
+
* The signal is passed to `run` so it can propagate cancellation to child processes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withAbortTimeout<T>(run: (signal: AbortSignal) => Promise<T>, timeoutMs: number, label: string): Promise<T>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared timeout utilities for agent and scorer execution.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Run an async function with an AbortSignal that fires after timeoutMs.
|
|
6
|
+
* The signal is passed to `run` so it can propagate cancellation to child processes.
|
|
7
|
+
*/
|
|
8
|
+
export function withAbortTimeout(run, timeoutMs, label) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
let timedOut = false;
|
|
12
|
+
const timer = setTimeout(() => {
|
|
13
|
+
timedOut = true;
|
|
14
|
+
controller.abort();
|
|
15
|
+
}, timeoutMs);
|
|
16
|
+
run(controller.signal).then((val) => {
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
if (timedOut || controller.signal.aborted) {
|
|
19
|
+
reject(new Error(`${label} timed out after ${timeoutMs / 1000}s`));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
resolve(val);
|
|
23
|
+
}, (err) => {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
if (timedOut || controller.signal.aborted) {
|
|
26
|
+
reject(new Error(`${label} timed out after ${timeoutMs / 1000}s`));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
reject(err);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|