@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.
Files changed (229) hide show
  1. package/README.md +47 -13
  2. package/README.zh-CN.md +20 -10
  3. package/bin/gotry-booking-copilot.js +53 -0
  4. package/bin/gotry-bootstrap.js +111 -51
  5. package/bin/gotry-inner.js +442 -60
  6. package/bin/gotry-runtime-resolution.d.ts +27 -0
  7. package/bin/gotry-runtime-resolution.js +50 -0
  8. package/bin/gotry.js +1 -1
  9. package/cordis.gotry-patch.yml +5 -1
  10. package/dist/capabilities/agent-reach-deep.js +1 -1
  11. package/dist/capabilities/agent-reach.js +1 -1
  12. package/dist/capabilities/anything.js +1 -1
  13. package/dist/capabilities/artifacts.js +1 -1
  14. package/dist/capabilities/effect.js +1 -1
  15. package/dist/capabilities/fact-log.js +1 -1
  16. package/dist/capabilities/flyai.js +20 -6
  17. package/dist/capabilities/hbcli.js +1 -1
  18. package/dist/capabilities/incident-log.js +1 -1
  19. package/dist/capabilities/model-override.js +18 -0
  20. package/dist/capabilities/opensky.js +1 -1
  21. package/dist/capabilities/resilience.js +1 -1
  22. package/dist/capabilities/session/action-cache.js +1 -1
  23. package/dist/capabilities/session/adapters/ctrip-flight.js +1 -1
  24. package/dist/capabilities/session/adapters/meituan-local.js +1 -1
  25. package/dist/capabilities/session/benchmark.js +1 -1
  26. package/dist/capabilities/session/extension-bridge.js +19 -6
  27. package/dist/capabilities/session/extension-channel.js +3 -3
  28. package/dist/capabilities/session/extension-distribution.js +234 -0
  29. package/dist/capabilities/session/extract.js +1 -1
  30. package/dist/capabilities/session/golden-score.js +92 -0
  31. package/dist/capabilities/session/health-watch.js +1 -1
  32. package/dist/capabilities/session/read-guard.js +1 -1
  33. package/dist/capabilities/session/static-flight-golden.js +137 -0
  34. package/dist/capabilities/session/transport.js +1 -1
  35. package/dist/capabilities/session/wizard.js +21 -251
  36. package/dist/capabilities/session-consent.js +1 -1
  37. package/dist/capabilities/session-login.js +11 -5
  38. package/dist/capabilities/session-search.js +46 -4
  39. package/dist/capabilities/weather.js +168 -46
  40. package/dist/data/session-golden-20.json +25 -0
  41. package/dist/data/sf-golden-manifest.json +102 -0
  42. package/dist/data/sf-static-routes.json +91 -0
  43. package/dist/scripts/action-cache-tests.js +1 -1
  44. package/dist/scripts/agent-planning-budget-e2e.js +227 -0
  45. package/dist/scripts/agent-planning-budget-tests.js +173 -0
  46. package/dist/scripts/agent-reach-deep-tests.js +1 -1
  47. package/dist/scripts/agent-reach-tests.js +1 -1
  48. package/dist/scripts/agent-reach-wrapper-tests.js +1 -1
  49. package/dist/scripts/anything-tests.js +1 -1
  50. package/dist/scripts/async-collect.js +1 -1
  51. package/dist/scripts/benchmark-environment-bridge-e2e.js +981 -0
  52. package/dist/scripts/benchmark-environment-bridge-tests.js +2544 -0
  53. package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +335 -0
  54. package/dist/scripts/booking-copilot-availability-policy-v2-tests.js +1355 -0
  55. package/dist/scripts/booking-copilot-bin-proof-tests.js +89 -0
  56. package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +113 -0
  57. package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +356 -0
  58. package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +557 -0
  59. package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +140 -0
  60. package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +202 -0
  61. package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +102 -0
  62. package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +374 -0
  63. package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +447 -0
  64. package/dist/scripts/booking-copilot-runtime-proof-tests.js +205 -0
  65. package/dist/scripts/booking-copilot-server-proof-tests.js +317 -0
  66. package/dist/scripts/booking-copilot-startup-proof-tests.js +283 -0
  67. package/dist/scripts/booking-copilot-v2-runtime-proof-tests.js +3935 -0
  68. package/dist/scripts/booking-saga-tests.js +1 -1
  69. package/dist/scripts/booking-surface-contract-proof-tests.js +393 -0
  70. package/dist/scripts/booking-surface-v2-contract-proof-tests.js +1174 -0
  71. package/dist/scripts/bootstrap-tests.js +30 -10
  72. package/dist/scripts/build-changelog.js +1 -1
  73. package/dist/scripts/changelog-tests.js +1 -1
  74. package/dist/scripts/companion-tests.js +1 -1
  75. package/dist/scripts/diff-test.js +1 -1
  76. package/dist/scripts/dsh-runtime-closure-tests.js +225 -0
  77. package/dist/scripts/dsh-runtime-closure.js +150 -0
  78. package/dist/scripts/effect-tests.js +1 -1
  79. package/dist/scripts/engine-run.js +1 -1
  80. package/dist/scripts/engine-tests.js +1 -1
  81. package/dist/scripts/evaluation-cadence-tests.js +347 -0
  82. package/dist/scripts/evaluation-contract-tests.js +574 -0
  83. package/dist/scripts/extension-distribution-cli.js +35 -0
  84. package/dist/scripts/extension-distribution-tests.js +341 -0
  85. package/dist/scripts/extension-tests.js +128 -23
  86. package/dist/scripts/fact-gate-tests.js +1 -1
  87. package/dist/scripts/flyai-tests.js +1 -1
  88. package/dist/scripts/hbcli-e2e-tests.js +1 -1
  89. package/dist/scripts/hbcli-tests.js +1 -1
  90. package/dist/scripts/health-watch-cli.js +1 -1
  91. package/dist/scripts/i18n-tests.js +1 -1
  92. package/dist/scripts/incident-tests.js +1 -1
  93. package/dist/scripts/journey-tests.js +1 -1
  94. package/dist/scripts/ledger-tests.js +1 -1
  95. package/dist/scripts/ledger-workflow-crash.js +1 -1
  96. package/dist/scripts/memory-capture-tests.js +1 -1
  97. package/dist/scripts/memory-decay-tests.js +1 -1
  98. package/dist/scripts/memory-metrics.js +1 -1
  99. package/dist/scripts/memory-value-report.js +1 -1
  100. package/dist/scripts/model-override-e2e.js +176 -0
  101. package/dist/scripts/nightly-evidence-tests.js +1 -1
  102. package/dist/scripts/nightly-evidence.js +1 -1
  103. package/dist/scripts/nudge-digest.js +1 -1
  104. package/dist/scripts/onboarding-tests.js +21 -53
  105. package/dist/scripts/opensky-check.js +1 -1
  106. package/dist/scripts/opensky-tests.js +1 -1
  107. package/dist/scripts/pnpm-dsh-closure-proof.js +20 -0
  108. package/dist/scripts/price-drift-tests.js +1 -1
  109. package/dist/scripts/price-drift-watch.js +1 -1
  110. package/dist/scripts/probe-poi-tests.js +1 -1
  111. package/dist/scripts/product-metrics.js +1 -1
  112. package/dist/scripts/publish-preverify.js +40 -4
  113. package/dist/scripts/realtime-pricing-tests.js +1 -1
  114. package/dist/scripts/replay-async.js +1 -1
  115. package/dist/scripts/replay-real.js +1 -1
  116. package/dist/scripts/replay.js +1 -1
  117. package/dist/scripts/session-attach-diagnose.js +1 -1
  118. package/dist/scripts/session-attach-poc.js +1 -1
  119. package/dist/scripts/session-benchmark.js +1 -1
  120. package/dist/scripts/session-extract-tests.js +1 -1
  121. package/dist/scripts/session-login.js +1 -1
  122. package/dist/scripts/session-tests.js +70 -20
  123. package/dist/scripts/sf-live-benchmark.js +338 -0
  124. package/dist/scripts/sf-live-cli-tests.js +21 -0
  125. package/dist/scripts/sf-soft-score-tests.js +108 -0
  126. package/dist/scripts/sf-summary.js +93 -0
  127. package/dist/scripts/skeleton-check.js +1 -1
  128. package/dist/scripts/skeleton-integration-test.js +1 -1
  129. package/dist/scripts/skills-contract-tests.js +1 -1
  130. package/dist/scripts/smoke-session-gate-tests.js +29 -0
  131. package/dist/scripts/smoke.js +79 -33
  132. package/dist/scripts/state-cli-tests.js +1 -1
  133. package/dist/scripts/state-cli.js +1 -1
  134. package/dist/scripts/static-golden-tests.js +299 -0
  135. package/dist/scripts/time-eval-tests.js +1 -1
  136. package/dist/scripts/travel-timeline-tests.js +1 -1
  137. package/dist/scripts/unified-tests.js +1 -1
  138. package/dist/scripts/weather-tests.js +694 -44
  139. package/dist/scripts/z3-race-tests.js +1 -1
  140. package/dist/src/artifact-gate.js +1 -1
  141. package/dist/src/benchmark-agent-conformance.js +370 -0
  142. package/dist/src/benchmark-environment-bridge.js +384 -0
  143. package/dist/src/benchmark-headless-child-diagnostics.js +173 -0
  144. package/dist/src/benchmark-tool-isolation.js +124 -0
  145. package/dist/src/bookable-facts.js +1 -1
  146. package/dist/src/booking-saga.js +1 -1
  147. package/dist/src/booking-surface/availability-policy-v2.js +830 -0
  148. package/dist/src/booking-surface/canonical-schema.js +113 -0
  149. package/dist/src/booking-surface/contracts-v2.js +89 -0
  150. package/dist/src/booking-surface/contracts.js +46 -0
  151. package/dist/src/booking-surface/dsh-planner.js +453 -0
  152. package/dist/src/booking-surface/dsh-plugin.js +93 -0
  153. package/dist/src/booking-surface/error-codes.js +94 -0
  154. package/dist/src/booking-surface/index.js +15 -0
  155. package/dist/src/booking-surface/profile.js +68 -0
  156. package/dist/src/booking-surface/runtime-v2.js +1771 -0
  157. package/dist/src/booking-surface/runtime.js +351 -0
  158. package/dist/src/booking-surface/server-v2.js +334 -0
  159. package/dist/src/booking-surface/server.js +302 -0
  160. package/dist/src/booking-surface/startup.js +159 -0
  161. package/dist/src/booking-surface/validation-v2.js +319 -0
  162. package/dist/src/booking-surface/validation.js +809 -0
  163. package/dist/src/bridge.js +1 -1
  164. package/dist/src/companions.js +1 -1
  165. package/dist/src/contracts.js +1 -1
  166. package/dist/src/dsh-llm.js +1 -1
  167. package/dist/src/engine.js +1 -1
  168. package/dist/src/evaluation-cadence.js +234 -0
  169. package/dist/src/evaluation-contracts.js +906 -0
  170. package/dist/src/i18n.js +1 -1
  171. package/dist/src/index.js +50 -19
  172. package/dist/src/journey.js +1 -1
  173. package/dist/src/loop.js +1 -1
  174. package/dist/src/memory-capture.js +1 -1
  175. package/dist/src/memory-decay.js +1 -1
  176. package/dist/src/memory-utility.js +1 -1
  177. package/dist/src/mock-llm.js +1 -1
  178. package/dist/src/model.js +1 -1
  179. package/dist/src/realtime-pricing.js +1 -1
  180. package/dist/src/slot-spec.js +1 -1
  181. package/dist/src/state-ledger.js +2 -1
  182. package/dist/src/time-anchor.js +1 -1
  183. package/dist/src/tool-budget.js +136 -0
  184. package/dist/src/tool-packet.js +1 -1
  185. package/dist/src/travel-slots.js +1 -1
  186. package/dist/src/travel-timeline.js +1 -1
  187. package/dist/src/unified.js +1 -1
  188. package/dist/src/wish-pool.js +1 -1
  189. package/dist/src/z3-shared.js +1 -1
  190. package/extension/README.md +31 -7
  191. package/package.json +286 -11
  192. package/schemas/booking.surface.v1.schema.json +927 -0
  193. package/schemas/booking.surface.v2.schema.json +61 -0
  194. package/ts/capabilities/flyai.ts +16 -3
  195. package/ts/capabilities/session/extension-bridge.ts +37 -14
  196. package/ts/capabilities/session/extension-channel.ts +6 -3
  197. package/ts/capabilities/session/extension-distribution.ts +264 -0
  198. package/ts/capabilities/session/golden-score.ts +139 -0
  199. package/ts/capabilities/session/health-watch.ts +1 -1
  200. package/ts/capabilities/session/static-flight-golden.ts +209 -0
  201. package/ts/capabilities/session/wizard.ts +34 -176
  202. package/ts/capabilities/session-login.ts +15 -5
  203. package/ts/capabilities/session-search.ts +40 -3
  204. package/ts/capabilities/weather.ts +141 -52
  205. package/ts/package.json +3 -3
  206. package/ts/src/benchmark-agent-conformance.ts +448 -0
  207. package/ts/src/benchmark-environment-bridge.ts +348 -0
  208. package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
  209. package/ts/src/benchmark-tool-isolation.ts +166 -0
  210. package/ts/src/booking-surface/availability-policy-v2.ts +523 -0
  211. package/ts/src/booking-surface/canonical-schema.js +113 -0
  212. package/ts/src/booking-surface/contracts-v2.ts +118 -0
  213. package/ts/src/booking-surface/contracts.ts +380 -0
  214. package/ts/src/booking-surface/dsh-planner.ts +452 -0
  215. package/ts/src/booking-surface/dsh-plugin.js +93 -0
  216. package/ts/src/booking-surface/error-codes.ts +101 -0
  217. package/ts/src/booking-surface/index.ts +12 -0
  218. package/ts/src/booking-surface/profile.ts +42 -0
  219. package/ts/src/booking-surface/runtime-v2.ts +1466 -0
  220. package/ts/src/booking-surface/runtime.ts +483 -0
  221. package/ts/src/booking-surface/server-v2.ts +247 -0
  222. package/ts/src/booking-surface/server.ts +324 -0
  223. package/ts/src/booking-surface/startup.ts +196 -0
  224. package/ts/src/booking-surface/validation-v2.ts +205 -0
  225. package/ts/src/booking-surface/validation.ts +453 -0
  226. package/ts/src/index.ts +64 -11
  227. package/ts/src/state-ledger.ts +1 -0
  228. package/ts/src/tool-budget.ts +165 -0
  229. package/dist/scripts/wizard-bootstrap.js +0 -32
@@ -32,4 +32,4 @@ for(let round = 0; round < ROUNDS; round++){
32
32
  console.log(`Z3 RACE TESTS OK(进程内三形态并发 ×${ROUNDS}:判定与顺序基线一致,零 WASM 降级)`);
33
33
 
34
34
 
35
- //# sourceURL=/Users/bytedance/work/gotry-publish/ts/scripts/z3-race-tests.ts
35
+ //# sourceURL=ts/scripts/z3-race-tests.ts
@@ -307,4 +307,4 @@ export function gateArtifact(markdown, facts, map, opts) {
307
307
  }
308
308
 
309
309
 
310
- //# sourceURL=/Users/bytedance/work/gotry-publish/ts/src/artifact-gate.ts
310
+ //# sourceURL=ts/src/artifact-gate.ts
@@ -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