@danceiny/gotry 0.0.1-rc.16 → 0.0.1-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -13
- package/README.zh-CN.md +20 -10
- package/bin/gotry-booking-copilot.js +53 -0
- package/bin/gotry-bootstrap.js +111 -51
- package/bin/gotry-inner.js +442 -60
- package/bin/gotry-runtime-resolution.d.ts +27 -0
- package/bin/gotry-runtime-resolution.js +50 -0
- package/bin/gotry.js +1 -1
- package/cordis.gotry-patch.yml +5 -1
- package/dist/capabilities/agent-reach-deep.js +1 -1
- package/dist/capabilities/agent-reach.js +1 -1
- package/dist/capabilities/anything.js +1 -1
- package/dist/capabilities/artifacts.js +1 -1
- package/dist/capabilities/effect.js +1 -1
- package/dist/capabilities/fact-log.js +1 -1
- package/dist/capabilities/flyai.js +20 -6
- package/dist/capabilities/hbcli.js +1 -1
- package/dist/capabilities/incident-log.js +1 -1
- package/dist/capabilities/model-override.js +18 -0
- package/dist/capabilities/opensky.js +1 -1
- package/dist/capabilities/resilience.js +1 -1
- package/dist/capabilities/session/action-cache.js +1 -1
- package/dist/capabilities/session/adapters/ctrip-flight.js +1 -1
- package/dist/capabilities/session/adapters/meituan-local.js +1 -1
- package/dist/capabilities/session/benchmark.js +1 -1
- package/dist/capabilities/session/extension-bridge.js +19 -6
- package/dist/capabilities/session/extension-channel.js +3 -3
- package/dist/capabilities/session/extension-distribution.js +234 -0
- package/dist/capabilities/session/extract.js +1 -1
- package/dist/capabilities/session/golden-score.js +92 -0
- package/dist/capabilities/session/health-watch.js +1 -1
- package/dist/capabilities/session/read-guard.js +1 -1
- package/dist/capabilities/session/static-flight-golden.js +137 -0
- package/dist/capabilities/session/transport.js +1 -1
- package/dist/capabilities/session/wizard.js +21 -251
- package/dist/capabilities/session-consent.js +1 -1
- package/dist/capabilities/session-login.js +11 -5
- package/dist/capabilities/session-search.js +46 -4
- package/dist/capabilities/weather.js +168 -46
- package/dist/data/session-golden-20.json +25 -0
- package/dist/data/sf-golden-manifest.json +102 -0
- package/dist/data/sf-static-routes.json +91 -0
- package/dist/scripts/action-cache-tests.js +1 -1
- package/dist/scripts/agent-planning-budget-e2e.js +227 -0
- package/dist/scripts/agent-planning-budget-tests.js +173 -0
- package/dist/scripts/agent-reach-deep-tests.js +1 -1
- package/dist/scripts/agent-reach-tests.js +1 -1
- package/dist/scripts/agent-reach-wrapper-tests.js +1 -1
- package/dist/scripts/anything-tests.js +1 -1
- package/dist/scripts/async-collect.js +1 -1
- package/dist/scripts/benchmark-environment-bridge-e2e.js +981 -0
- package/dist/scripts/benchmark-environment-bridge-tests.js +2544 -0
- package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +335 -0
- package/dist/scripts/booking-copilot-availability-policy-v2-tests.js +1355 -0
- package/dist/scripts/booking-copilot-bin-proof-tests.js +89 -0
- package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +113 -0
- package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +356 -0
- package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +557 -0
- package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +140 -0
- package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +202 -0
- package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +102 -0
- package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +374 -0
- package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +447 -0
- package/dist/scripts/booking-copilot-runtime-proof-tests.js +205 -0
- package/dist/scripts/booking-copilot-server-proof-tests.js +317 -0
- package/dist/scripts/booking-copilot-startup-proof-tests.js +283 -0
- package/dist/scripts/booking-copilot-v2-runtime-proof-tests.js +3935 -0
- package/dist/scripts/booking-saga-tests.js +1 -1
- package/dist/scripts/booking-surface-contract-proof-tests.js +393 -0
- package/dist/scripts/booking-surface-v2-contract-proof-tests.js +1174 -0
- package/dist/scripts/bootstrap-tests.js +30 -10
- package/dist/scripts/build-changelog.js +1 -1
- package/dist/scripts/changelog-tests.js +1 -1
- package/dist/scripts/companion-tests.js +1 -1
- package/dist/scripts/diff-test.js +1 -1
- package/dist/scripts/dsh-runtime-closure-tests.js +225 -0
- package/dist/scripts/dsh-runtime-closure.js +150 -0
- package/dist/scripts/effect-tests.js +1 -1
- package/dist/scripts/engine-run.js +1 -1
- package/dist/scripts/engine-tests.js +1 -1
- package/dist/scripts/evaluation-cadence-tests.js +347 -0
- package/dist/scripts/evaluation-contract-tests.js +574 -0
- package/dist/scripts/extension-distribution-cli.js +35 -0
- package/dist/scripts/extension-distribution-tests.js +341 -0
- package/dist/scripts/extension-tests.js +128 -23
- package/dist/scripts/fact-gate-tests.js +1 -1
- package/dist/scripts/flyai-tests.js +1 -1
- package/dist/scripts/hbcli-e2e-tests.js +1 -1
- package/dist/scripts/hbcli-tests.js +1 -1
- package/dist/scripts/health-watch-cli.js +1 -1
- package/dist/scripts/i18n-tests.js +1 -1
- package/dist/scripts/incident-tests.js +1 -1
- package/dist/scripts/journey-tests.js +1 -1
- package/dist/scripts/ledger-tests.js +1 -1
- package/dist/scripts/ledger-workflow-crash.js +1 -1
- package/dist/scripts/memory-capture-tests.js +1 -1
- package/dist/scripts/memory-decay-tests.js +1 -1
- package/dist/scripts/memory-metrics.js +1 -1
- package/dist/scripts/memory-value-report.js +1 -1
- package/dist/scripts/model-override-e2e.js +176 -0
- package/dist/scripts/nightly-evidence-tests.js +1 -1
- package/dist/scripts/nightly-evidence.js +1 -1
- package/dist/scripts/nudge-digest.js +1 -1
- package/dist/scripts/onboarding-tests.js +21 -53
- package/dist/scripts/opensky-check.js +1 -1
- package/dist/scripts/opensky-tests.js +1 -1
- package/dist/scripts/pnpm-dsh-closure-proof.js +20 -0
- package/dist/scripts/price-drift-tests.js +1 -1
- package/dist/scripts/price-drift-watch.js +1 -1
- package/dist/scripts/probe-poi-tests.js +1 -1
- package/dist/scripts/product-metrics.js +1 -1
- package/dist/scripts/publish-preverify.js +40 -4
- package/dist/scripts/realtime-pricing-tests.js +1 -1
- package/dist/scripts/replay-async.js +1 -1
- package/dist/scripts/replay-real.js +1 -1
- package/dist/scripts/replay.js +1 -1
- package/dist/scripts/session-attach-diagnose.js +1 -1
- package/dist/scripts/session-attach-poc.js +1 -1
- package/dist/scripts/session-benchmark.js +1 -1
- package/dist/scripts/session-extract-tests.js +1 -1
- package/dist/scripts/session-login.js +1 -1
- package/dist/scripts/session-tests.js +70 -20
- package/dist/scripts/sf-live-benchmark.js +338 -0
- package/dist/scripts/sf-live-cli-tests.js +21 -0
- package/dist/scripts/sf-soft-score-tests.js +108 -0
- package/dist/scripts/sf-summary.js +93 -0
- package/dist/scripts/skeleton-check.js +1 -1
- package/dist/scripts/skeleton-integration-test.js +1 -1
- package/dist/scripts/skills-contract-tests.js +1 -1
- package/dist/scripts/smoke-session-gate-tests.js +29 -0
- package/dist/scripts/smoke.js +79 -33
- package/dist/scripts/state-cli-tests.js +1 -1
- package/dist/scripts/state-cli.js +1 -1
- package/dist/scripts/static-golden-tests.js +299 -0
- package/dist/scripts/time-eval-tests.js +1 -1
- package/dist/scripts/travel-timeline-tests.js +1 -1
- package/dist/scripts/unified-tests.js +1 -1
- package/dist/scripts/weather-tests.js +694 -44
- package/dist/scripts/z3-race-tests.js +1 -1
- package/dist/src/artifact-gate.js +1 -1
- package/dist/src/benchmark-agent-conformance.js +370 -0
- package/dist/src/benchmark-environment-bridge.js +384 -0
- package/dist/src/benchmark-headless-child-diagnostics.js +173 -0
- package/dist/src/benchmark-tool-isolation.js +124 -0
- package/dist/src/bookable-facts.js +1 -1
- package/dist/src/booking-saga.js +1 -1
- package/dist/src/booking-surface/availability-policy-v2.js +830 -0
- package/dist/src/booking-surface/canonical-schema.js +113 -0
- package/dist/src/booking-surface/contracts-v2.js +89 -0
- package/dist/src/booking-surface/contracts.js +46 -0
- package/dist/src/booking-surface/dsh-planner.js +453 -0
- package/dist/src/booking-surface/dsh-plugin.js +93 -0
- package/dist/src/booking-surface/error-codes.js +94 -0
- package/dist/src/booking-surface/index.js +15 -0
- package/dist/src/booking-surface/profile.js +68 -0
- package/dist/src/booking-surface/runtime-v2.js +1771 -0
- package/dist/src/booking-surface/runtime.js +351 -0
- package/dist/src/booking-surface/server-v2.js +334 -0
- package/dist/src/booking-surface/server.js +302 -0
- package/dist/src/booking-surface/startup.js +159 -0
- package/dist/src/booking-surface/validation-v2.js +319 -0
- package/dist/src/booking-surface/validation.js +809 -0
- package/dist/src/bridge.js +1 -1
- package/dist/src/companions.js +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/dsh-llm.js +1 -1
- package/dist/src/engine.js +1 -1
- package/dist/src/evaluation-cadence.js +234 -0
- package/dist/src/evaluation-contracts.js +906 -0
- package/dist/src/i18n.js +1 -1
- package/dist/src/index.js +50 -19
- package/dist/src/journey.js +1 -1
- package/dist/src/loop.js +1 -1
- package/dist/src/memory-capture.js +1 -1
- package/dist/src/memory-decay.js +1 -1
- package/dist/src/memory-utility.js +1 -1
- package/dist/src/mock-llm.js +1 -1
- package/dist/src/model.js +1 -1
- package/dist/src/realtime-pricing.js +1 -1
- package/dist/src/slot-spec.js +1 -1
- package/dist/src/state-ledger.js +2 -1
- package/dist/src/time-anchor.js +1 -1
- package/dist/src/tool-budget.js +136 -0
- package/dist/src/tool-packet.js +1 -1
- package/dist/src/travel-slots.js +1 -1
- package/dist/src/travel-timeline.js +1 -1
- package/dist/src/unified.js +1 -1
- package/dist/src/wish-pool.js +1 -1
- package/dist/src/z3-shared.js +1 -1
- package/extension/README.md +31 -7
- package/package.json +286 -11
- package/schemas/booking.surface.v1.schema.json +927 -0
- package/schemas/booking.surface.v2.schema.json +61 -0
- package/ts/capabilities/flyai.ts +16 -3
- package/ts/capabilities/session/extension-bridge.ts +37 -14
- package/ts/capabilities/session/extension-channel.ts +6 -3
- package/ts/capabilities/session/extension-distribution.ts +264 -0
- package/ts/capabilities/session/golden-score.ts +139 -0
- package/ts/capabilities/session/health-watch.ts +1 -1
- package/ts/capabilities/session/static-flight-golden.ts +209 -0
- package/ts/capabilities/session/wizard.ts +34 -176
- package/ts/capabilities/session-login.ts +15 -5
- package/ts/capabilities/session-search.ts +40 -3
- package/ts/capabilities/weather.ts +141 -52
- package/ts/package.json +3 -3
- package/ts/src/benchmark-agent-conformance.ts +448 -0
- package/ts/src/benchmark-environment-bridge.ts +348 -0
- package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
- package/ts/src/benchmark-tool-isolation.ts +166 -0
- package/ts/src/booking-surface/availability-policy-v2.ts +523 -0
- package/ts/src/booking-surface/canonical-schema.js +113 -0
- package/ts/src/booking-surface/contracts-v2.ts +118 -0
- package/ts/src/booking-surface/contracts.ts +380 -0
- package/ts/src/booking-surface/dsh-planner.ts +452 -0
- package/ts/src/booking-surface/dsh-plugin.js +93 -0
- package/ts/src/booking-surface/error-codes.ts +101 -0
- package/ts/src/booking-surface/index.ts +12 -0
- package/ts/src/booking-surface/profile.ts +42 -0
- package/ts/src/booking-surface/runtime-v2.ts +1466 -0
- package/ts/src/booking-surface/runtime.ts +483 -0
- package/ts/src/booking-surface/server-v2.ts +247 -0
- package/ts/src/booking-surface/server.ts +324 -0
- package/ts/src/booking-surface/startup.ts +196 -0
- package/ts/src/booking-surface/validation-v2.ts +205 -0
- package/ts/src/booking-surface/validation.ts +453 -0
- package/ts/src/index.ts +64 -11
- package/ts/src/state-ledger.ts +1 -0
- package/ts/src/tool-budget.ts +165 -0
- package/dist/scripts/wizard-bootstrap.js +0 -32
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import { classifyBenchmarkTurnEnd, createBenchmarkDiagnosticArbiter, emitBenchmarkChildDiagnostic } from './benchmark-headless-child-diagnostics.js';
|
|
3
|
+
export const MAX_CONFORMANCE_RETRIES = 1;
|
|
4
|
+
export const BENCHMARK_BRIDGE_CALL_REQUIRED = 'BENCHMARK_BRIDGE_CALL_REQUIRED';
|
|
5
|
+
export const BENCHMARK_BRIDGE_CALL_FAILED = 'BENCHMARK_BRIDGE_CALL_FAILED';
|
|
6
|
+
export const BENCHMARK_BRIDGE_TIMED_OUT = 'BENCHMARK_BRIDGE_TIMED_OUT';
|
|
7
|
+
export const BENCHMARK_BRIDGE_RUNNER_FAILED = 'BENCHMARK_BRIDGE_RUNNER_FAILED';
|
|
8
|
+
export const BENCHMARK_BRIDGE_SPAWN_FAILED = 'BENCHMARK_BRIDGE_SPAWN_FAILED';
|
|
9
|
+
export const BENCHMARK_BRIDGE_OUTPUT_TRUNCATED = 'BENCHMARK_BRIDGE_OUTPUT_TRUNCATED';
|
|
10
|
+
export const BENCHMARK_TERMINAL_INVALID = 'BENCHMARK_TERMINAL_INVALID';
|
|
11
|
+
export const BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED = 'BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED';
|
|
12
|
+
export const BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE = 'BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE';
|
|
13
|
+
const IDENTIFIER = /^[A-Za-z][A-Za-z0-9_.-]*$/;
|
|
14
|
+
const MAX_TERMINAL_BYTES = 1024 * 1024;
|
|
15
|
+
function plainObject(value) {
|
|
16
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
export function validateTerminalOutputConfig(value) {
|
|
19
|
+
if (!plainObject(value)) return false;
|
|
20
|
+
const keys = Object.keys(value).sort();
|
|
21
|
+
return JSON.stringify(keys) === JSON.stringify([
|
|
22
|
+
'max_bytes',
|
|
23
|
+
'tag'
|
|
24
|
+
]) && typeof value.tag === 'string' && IDENTIFIER.test(value.tag) && typeof value.max_bytes === 'number' && Number.isInteger(value.max_bytes) && value.max_bytes >= 1 && value.max_bytes <= MAX_TERMINAL_BYTES;
|
|
25
|
+
}
|
|
26
|
+
function invalidTerminal() {
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
error: 'invalid_terminal_output'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function parseBenchmarkTerminal(raw, config) {
|
|
33
|
+
if (!validateTerminalOutputConfig(config)) return invalidTerminal();
|
|
34
|
+
if (Buffer.byteLength(raw, 'utf8') > config.max_bytes) return invalidTerminal();
|
|
35
|
+
const trimmed = raw.trim();
|
|
36
|
+
const opening = `<${config.tag}>`;
|
|
37
|
+
const closing = `</${config.tag}>`;
|
|
38
|
+
if (!trimmed.startsWith(opening) || !trimmed.endsWith(closing)) return invalidTerminal();
|
|
39
|
+
if (trimmed.indexOf(opening) !== trimmed.lastIndexOf(opening) || trimmed.indexOf(closing) !== trimmed.lastIndexOf(closing)) return invalidTerminal();
|
|
40
|
+
const body = trimmed.slice(opening.length, -closing.length);
|
|
41
|
+
if (body.length === 0 || body.includes('```')) return invalidTerminal();
|
|
42
|
+
try {
|
|
43
|
+
const value = JSON.parse(body);
|
|
44
|
+
return plainObject(value) ? {
|
|
45
|
+
ok: true,
|
|
46
|
+
value
|
|
47
|
+
} : invalidTerminal();
|
|
48
|
+
} catch {
|
|
49
|
+
return invalidTerminal();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export const validateTerminalOutput = parseBenchmarkTerminal;
|
|
53
|
+
function eventData(event) {
|
|
54
|
+
if (!plainObject(event) || typeof event.type !== 'string' || !plainObject(event.data)) return undefined;
|
|
55
|
+
return {
|
|
56
|
+
type: event.type,
|
|
57
|
+
data: event.data
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function eventTurn(data) {
|
|
61
|
+
return typeof data.turn === 'number' && Number.isInteger(data.turn) ? data.turn : undefined;
|
|
62
|
+
}
|
|
63
|
+
function parseToolArguments(value) {
|
|
64
|
+
if (plainObject(value)) return value;
|
|
65
|
+
if (typeof value !== 'string') return undefined;
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(value);
|
|
68
|
+
return plainObject(parsed) ? parsed : undefined;
|
|
69
|
+
} catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function assistantText(data) {
|
|
74
|
+
if (!plainObject(data.message) || !Array.isArray(data.message.content)) return undefined;
|
|
75
|
+
const text = data.message.content.filter((block)=>plainObject(block) && block.type === 'text' && typeof block.text === 'string').map((block)=>String(block.text)).join('');
|
|
76
|
+
return {
|
|
77
|
+
text,
|
|
78
|
+
interrupted: data.interrupted === true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function bridgeResultStatus(data, callId) {
|
|
82
|
+
if (!plainObject(data.message) || !plainObject(data.message.source)) return undefined;
|
|
83
|
+
if (data.message.source.callId !== callId || !Array.isArray(data.message.content)) return undefined;
|
|
84
|
+
const block = data.message.content.find((candidate)=>plainObject(candidate) && candidate.type === 'tool-result' && candidate.toolCallId === callId);
|
|
85
|
+
if (!plainObject(block) || block.isError === true || !Array.isArray(block.content)) return undefined;
|
|
86
|
+
const text = block.content.filter((candidate)=>plainObject(candidate) && candidate.type === 'text' && typeof candidate.text === 'string').map((candidate)=>String(candidate.text)).join('');
|
|
87
|
+
try {
|
|
88
|
+
const parsed = JSON.parse(text);
|
|
89
|
+
if (!plainObject(parsed)) return undefined;
|
|
90
|
+
if (parsed.ok === true) return {
|
|
91
|
+
ok: true
|
|
92
|
+
};
|
|
93
|
+
if (parsed.ok === false && typeof parsed.error === 'string') {
|
|
94
|
+
const code = parsed.error === 'timed_out' ? BENCHMARK_BRIDGE_TIMED_OUT : parsed.error === 'runner_failed' ? BENCHMARK_BRIDGE_RUNNER_FAILED : parsed.error === 'spawn_failed' ? BENCHMARK_BRIDGE_SPAWN_FAILED : parsed.error === 'output_truncated' ? BENCHMARK_BRIDGE_OUTPUT_TRUNCATED : BENCHMARK_BRIDGE_CALL_FAILED;
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
code
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
} catch {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function benchmarkChildFailureForConformanceCode(code) {
|
|
106
|
+
if (code === BENCHMARK_BRIDGE_TIMED_OUT) return 'child_bridge_timed_out';
|
|
107
|
+
if (code === BENCHMARK_BRIDGE_RUNNER_FAILED) return 'child_bridge_runner_failed';
|
|
108
|
+
if (code === BENCHMARK_BRIDGE_SPAWN_FAILED) return 'child_bridge_spawn_failed';
|
|
109
|
+
if (code === BENCHMARK_BRIDGE_OUTPUT_TRUNCATED) return 'child_bridge_output_truncated';
|
|
110
|
+
if (code === BENCHMARK_BRIDGE_CALL_FAILED) return 'child_bridge_failure';
|
|
111
|
+
return 'child_conformance_failure';
|
|
112
|
+
}
|
|
113
|
+
function newTurn(turn) {
|
|
114
|
+
return {
|
|
115
|
+
turn,
|
|
116
|
+
validCallIds: new Set(),
|
|
117
|
+
retryCount: 0,
|
|
118
|
+
retryMode: 'none',
|
|
119
|
+
bridgeCallFailed: false,
|
|
120
|
+
retryRedispatchAttempted: false
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export function createBenchmarkAgentConformance(projection) {
|
|
124
|
+
let state;
|
|
125
|
+
const controller = {
|
|
126
|
+
get retryMode () {
|
|
127
|
+
return state?.retryMode ?? 'none';
|
|
128
|
+
},
|
|
129
|
+
get retryCount () {
|
|
130
|
+
return state?.retryCount ?? 0;
|
|
131
|
+
},
|
|
132
|
+
observe (rawEvent) {
|
|
133
|
+
const event = eventData(rawEvent);
|
|
134
|
+
if (!event) return;
|
|
135
|
+
const turn = eventTurn(event.data);
|
|
136
|
+
if (event.type === 'turn/start' && turn !== undefined) {
|
|
137
|
+
state = newTurn(turn);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (event.type === 'turn/end') {
|
|
141
|
+
if (state && turn === state.turn) state = undefined;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!state || turn !== state.turn) return;
|
|
145
|
+
if (event.type === 'tool/call') {
|
|
146
|
+
if (event.data.name !== projection.toolName) return;
|
|
147
|
+
if (state.retryMode === 'terminal') {
|
|
148
|
+
state.retryRedispatchAttempted = true;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (typeof event.data.callId !== 'string') return;
|
|
152
|
+
const args = parseToolArguments(event.data.arguments);
|
|
153
|
+
const query = args && plainObject(args.query) ? args.query : undefined;
|
|
154
|
+
if (query?.action === 'call' && typeof query.tool === 'string' && projection.allowedTools.includes(query.tool)) {
|
|
155
|
+
state.validCallIds.add(event.data.callId);
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (event.type === 'tool/result') {
|
|
160
|
+
if (!plainObject(event.data.message) || !plainObject(event.data.message.source)) return;
|
|
161
|
+
const callId = event.data.message.source.callId;
|
|
162
|
+
if (typeof callId !== 'string' || !state.validCallIds.has(callId)) return;
|
|
163
|
+
const resultStatus = bridgeResultStatus(event.data, callId);
|
|
164
|
+
if (resultStatus?.ok === true) {
|
|
165
|
+
state.successfulResultStep = typeof event.data.step === 'number' ? event.data.step : state.successfulResultStep;
|
|
166
|
+
} else {
|
|
167
|
+
state.bridgeCallFailed = true;
|
|
168
|
+
state.bridgeFailureCode = resultStatus?.code ?? BENCHMARK_BRIDGE_CALL_FAILED;
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (event.type === 'assistant/message') {
|
|
173
|
+
const assistant = assistantText(event.data);
|
|
174
|
+
if (!assistant || typeof event.data.step !== 'number') return;
|
|
175
|
+
state.lastAssistant = {
|
|
176
|
+
step: event.data.step,
|
|
177
|
+
...assistant
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
stopping (turn) {
|
|
182
|
+
if (!state || state.turn !== turn) {
|
|
183
|
+
return {
|
|
184
|
+
kind: 'reject',
|
|
185
|
+
code: BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (state.retryRedispatchAttempted) {
|
|
189
|
+
return {
|
|
190
|
+
kind: 'reject',
|
|
191
|
+
code: BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (state.successfulResultStep === undefined) {
|
|
195
|
+
if (state.bridgeCallFailed) {
|
|
196
|
+
return {
|
|
197
|
+
kind: 'reject',
|
|
198
|
+
code: state.bridgeFailureCode ?? BENCHMARK_BRIDGE_CALL_FAILED
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (state.retryCount >= MAX_CONFORMANCE_RETRIES) {
|
|
202
|
+
return {
|
|
203
|
+
kind: 'reject',
|
|
204
|
+
code: BENCHMARK_BRIDGE_CALL_REQUIRED
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
state.retryCount += 1;
|
|
208
|
+
state.retryMode = 'call';
|
|
209
|
+
return {
|
|
210
|
+
kind: 'steer',
|
|
211
|
+
mode: 'call'
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const terminal = state.lastAssistant;
|
|
215
|
+
const terminalIsValid = terminal !== undefined && !terminal.interrupted && terminal.step > state.successfulResultStep && parseBenchmarkTerminal(terminal.text, projection.terminal).ok;
|
|
216
|
+
if (terminalIsValid) return {
|
|
217
|
+
kind: 'accept'
|
|
218
|
+
};
|
|
219
|
+
if (state.retryCount >= MAX_CONFORMANCE_RETRIES) {
|
|
220
|
+
return {
|
|
221
|
+
kind: 'reject',
|
|
222
|
+
code: BENCHMARK_TERMINAL_INVALID
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
state.retryCount += 1;
|
|
226
|
+
state.retryMode = 'terminal';
|
|
227
|
+
return {
|
|
228
|
+
kind: 'steer',
|
|
229
|
+
mode: 'terminal'
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
guardBridgeExecution () {
|
|
233
|
+
return state?.retryMode === 'terminal' ? BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED : undefined;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return controller;
|
|
237
|
+
}
|
|
238
|
+
function requireDisposer(value, capability) {
|
|
239
|
+
if (typeof value !== 'function') throw new Error(`benchmark conformance ${capability} disposer unavailable`);
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
function correctionMessage(mode, projection) {
|
|
243
|
+
const text = mode === 'call' ? `BENCHMARK_CONFORMANCE_CALL: Execute exactly one native ${projection.toolName} action:"call" now. Describing an intended CLI, shell, or Python command does not execute it.` : `BENCHMARK_CONFORMANCE_TERMINAL: Reuse the existing successful tool result. Do not call any tool. Reply only <${projection.terminal.tag}>{"result":"..."}</${projection.terminal.tag}> with one JSON object.`;
|
|
244
|
+
return createUserMessage({
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: 'text',
|
|
248
|
+
text
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
source: {
|
|
252
|
+
kind: 'plugin',
|
|
253
|
+
plugin: 'gotry-benchmark-agent-conformance'
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function systemSection(projection) {
|
|
258
|
+
const allowed = projection.allowedTools.join(', ');
|
|
259
|
+
return {
|
|
260
|
+
name: 'benchmark:agent-conformance',
|
|
261
|
+
text: [
|
|
262
|
+
'Benchmark execution contract:',
|
|
263
|
+
`- Translate every task instruction to use a CLI, shell, Python, or agent_env.cli into the native tool ${projection.toolName}; do not merely describe the intended command.`,
|
|
264
|
+
`- Call it with exactly {"query":{"action":"call","tool":"<one of: ${allowed}>","arguments":{...}}}.`,
|
|
265
|
+
'- action:"tools" is discovery only and does not satisfy the required environment call.',
|
|
266
|
+
`- After a successful tool result, reply only <${projection.terminal.tag}>{...one JSON object...}</${projection.terminal.tag}> with no prose or code fence.`,
|
|
267
|
+
'- If a terminal-format correction arrives, reuse the existing result and do not call the tool again.'
|
|
268
|
+
].join('\n')
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export function installBenchmarkAgentConformance(ctx, projection, diagnosticWriter = emitBenchmarkChildDiagnostic) {
|
|
272
|
+
const bus = ctx;
|
|
273
|
+
if (typeof bus.on !== 'function') throw new Error('benchmark conformance event bus unavailable');
|
|
274
|
+
const byAgent = new WeakMap();
|
|
275
|
+
const bySession = new WeakMap();
|
|
276
|
+
const sessionKeys = new WeakMap();
|
|
277
|
+
let sessionOrdinal = 0;
|
|
278
|
+
const diagnostics = createBenchmarkDiagnosticArbiter(diagnosticWriter);
|
|
279
|
+
bus.on('agent/created', (payload)=>{
|
|
280
|
+
const agent = payload.agent;
|
|
281
|
+
if (!agent || typeof agent !== 'object' || !agent.session) {
|
|
282
|
+
throw new Error('benchmark conformance created agent unavailable');
|
|
283
|
+
}
|
|
284
|
+
if (typeof agent.steer !== 'function') throw new Error('benchmark conformance steering unavailable');
|
|
285
|
+
if (typeof agent.ctx?.tools?.guard !== 'function') throw new Error('benchmark conformance scoped guard unavailable');
|
|
286
|
+
if (typeof agent.ctx.effect !== 'function') throw new Error('benchmark conformance scoped effect unavailable');
|
|
287
|
+
if (typeof agent.ctx.on !== 'function') throw new Error('benchmark conformance scoped event bus unavailable');
|
|
288
|
+
const controller = createBenchmarkAgentConformance(projection);
|
|
289
|
+
byAgent.set(agent, controller);
|
|
290
|
+
bySession.set(agent.session, controller);
|
|
291
|
+
sessionKeys.set(agent.session, `session-${++sessionOrdinal}`);
|
|
292
|
+
try {
|
|
293
|
+
requireDisposer(agent.ctx.effect.call(agent.ctx, function*() {
|
|
294
|
+
yield requireDisposer(agent.ctx.tools.guard((execution)=>{
|
|
295
|
+
if (execution.name !== projection.toolName) return undefined;
|
|
296
|
+
return controller.guardBridgeExecution();
|
|
297
|
+
}), 'scoped guard');
|
|
298
|
+
yield requireDisposer(agent.ctx.on.call(agent.ctx, 'system-prompt/assemble', async (_assembly, _context, next)=>{
|
|
299
|
+
if (typeof next !== 'function') throw new Error('benchmark conformance assembly continuation unavailable');
|
|
300
|
+
const result = await next();
|
|
301
|
+
if (!plainObject(result)) throw new Error('benchmark conformance assembly result unavailable');
|
|
302
|
+
const sections = Array.isArray(result.sections) ? result.sections : [];
|
|
303
|
+
return {
|
|
304
|
+
...result,
|
|
305
|
+
sections: [
|
|
306
|
+
...sections,
|
|
307
|
+
systemSection(projection)
|
|
308
|
+
]
|
|
309
|
+
};
|
|
310
|
+
}, {
|
|
311
|
+
prepend: true
|
|
312
|
+
}), 'scoped assembly listener');
|
|
313
|
+
}, 'benchmark-agent-conformance'), 'scoped effect');
|
|
314
|
+
} catch (error) {
|
|
315
|
+
byAgent.delete(agent);
|
|
316
|
+
bySession.delete(agent.session);
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
bus.on('session/event', (session, event)=>{
|
|
321
|
+
bySession.get(session)?.observe(event);
|
|
322
|
+
if (typeof event === 'object' && event !== null && event.type === 'turn/end') {
|
|
323
|
+
const key = sessionKeys.get(session);
|
|
324
|
+
if (key !== undefined) {
|
|
325
|
+
diagnostics.offer(key, classifyBenchmarkTurnEnd(event.data?.reason));
|
|
326
|
+
diagnostics.flush(key);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
bus.on('session/disposed', (session)=>{
|
|
331
|
+
const key = sessionKeys.get(session);
|
|
332
|
+
if (key !== undefined) diagnostics.flush(key);
|
|
333
|
+
sessionKeys.delete(session);
|
|
334
|
+
bySession.delete(session);
|
|
335
|
+
});
|
|
336
|
+
bus.on('agent/disposed', (payload)=>{
|
|
337
|
+
const agent = payload.agent;
|
|
338
|
+
if (!agent || typeof agent !== 'object') return;
|
|
339
|
+
byAgent.delete(agent);
|
|
340
|
+
if (agent.session) bySession.delete(agent.session);
|
|
341
|
+
});
|
|
342
|
+
bus.on('agent/turn-stopping', (payload)=>{
|
|
343
|
+
const agent = payload.agent;
|
|
344
|
+
const session = agent?.session ?? payload.session;
|
|
345
|
+
const key = session && typeof session === 'object' ? sessionKeys.get(session) : undefined;
|
|
346
|
+
if (!agent || typeof agent !== 'object' || typeof payload.turn !== 'number') {
|
|
347
|
+
if (key !== undefined) diagnostics.offer(key, 'child_conformance_failure');
|
|
348
|
+
else diagnosticWriter('child_conformance_failure');
|
|
349
|
+
throw new Error(BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE);
|
|
350
|
+
}
|
|
351
|
+
const controller = byAgent.get(agent);
|
|
352
|
+
if (!controller) {
|
|
353
|
+
if (key !== undefined) diagnostics.offer(key, 'child_conformance_failure');
|
|
354
|
+
else diagnosticWriter('child_conformance_failure');
|
|
355
|
+
throw new Error(BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE);
|
|
356
|
+
}
|
|
357
|
+
const decision = controller.stopping(payload.turn);
|
|
358
|
+
if (decision.kind === 'reject') {
|
|
359
|
+
if (key !== undefined) diagnostics.offer(key, benchmarkChildFailureForConformanceCode(decision.code));
|
|
360
|
+
else diagnosticWriter(benchmarkChildFailureForConformanceCode(decision.code));
|
|
361
|
+
throw new Error(decision.code);
|
|
362
|
+
}
|
|
363
|
+
if (decision.kind === 'steer') agent.steer(correctionMessage(decision.mode, projection));
|
|
364
|
+
}, {
|
|
365
|
+
prepend: true
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
//# sourceURL=ts/src/benchmark-agent-conformance.ts
|