@danceiny/gotry 0.0.1-rc.16 → 0.0.1-rc.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +161 -116
  2. package/README.zh-CN.md +173 -144
  3. package/bin/gotry-booking-copilot.js +53 -0
  4. package/bin/gotry-bootstrap.js +113 -66
  5. package/bin/gotry-inner.js +436 -70
  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 +45 -39
  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
@@ -0,0 +1,165 @@
1
+ /** Per-agent, per-turn guard for model-driven tool loops. */
2
+
3
+ import { randomUUID } from 'node:crypto'
4
+ import type { Context } from '@deepseek-ai/cordis'
5
+ import type { Agent } from '@deepseek-ai/dsh-agent'
6
+ import type { ToolExecutionResult, ToolExecutionToken } from '@deepseek-ai/dsh-tools'
7
+
8
+ export const TOOL_BUDGET_SOFT_CALL = 16
9
+ export const TOOL_BUDGET_HARD_CALL = 18
10
+ export const TOOL_BUDGET_EXHAUSTED = 'TOOL_BUDGET_EXHAUSTED'
11
+
12
+ export type ToolBudgetDecision =
13
+ | { kind: 'allow'; softSignal: boolean; exhaustsBudget: boolean }
14
+ | { kind: 'deny'; reason: string }
15
+
16
+ export function toolBudgetDecision(callNumber: number): ToolBudgetDecision {
17
+ if (callNumber > TOOL_BUDGET_HARD_CALL) {
18
+ return {
19
+ kind: 'deny',
20
+ reason: `${TOOL_BUDGET_EXHAUSTED}: maximum ${TOOL_BUDGET_HARD_CALL} real tool dispatches per agent turn reached; provide a final answer using existing results`,
21
+ }
22
+ }
23
+ return {
24
+ kind: 'allow',
25
+ softSignal: callNumber === TOOL_BUDGET_SOFT_CALL,
26
+ exhaustsBudget: callNumber === TOOL_BUDGET_HARD_CALL,
27
+ }
28
+ }
29
+
30
+ export function createToolBudgetState(): {
31
+ nextCall(): ToolBudgetDecision & { callNumber: number }
32
+ } {
33
+ let calls = 0
34
+ return {
35
+ nextCall() {
36
+ calls += 1
37
+ return { ...toolBudgetDecision(calls), callNumber: calls }
38
+ },
39
+ }
40
+ }
41
+
42
+ function convergenceContext(code: 'TOOL_BUDGET_SOFT' | typeof TOOL_BUDGET_EXHAUSTED, text: string) {
43
+ return {
44
+ id: randomUUID(),
45
+ role: 'user' as const,
46
+ content: [{ type: 'text' as const, text: `${code}: ${text}` }],
47
+ source: { kind: 'plugin' as const, plugin: 'gotry-tool-budget' },
48
+ }
49
+ }
50
+
51
+ function exhaustionResult(reason: string): ToolExecutionResult {
52
+ return {
53
+ isError: true,
54
+ error: {
55
+ message: reason,
56
+ info: { name: 'ToolBudgetError', code: TOOL_BUDGET_EXHAUSTED },
57
+ },
58
+ content: [{ type: 'text', text: reason }],
59
+ additionalContexts: [convergenceContext(
60
+ TOOL_BUDGET_EXHAUSTED,
61
+ 'No more tool dispatches are permitted in this turn. Produce the final answer from existing results.',
62
+ ) as never],
63
+ }
64
+ }
65
+
66
+ type RestrictableTools = {
67
+ schemas?: () => Array<{ name: string }>
68
+ restrict?: (filter: { deny: string[] }) => () => void
69
+ }
70
+
71
+ /**
72
+ * Install the runtime boundary, kept separate from the GoTry tool catalog so
73
+ * the actual Cordis waterfalls can be exercised without booting every tool.
74
+ */
75
+ export function installToolBudget(ctx: Context): void {
76
+ // Some offline contract tests intentionally provide a registration-only
77
+ // Context slice. They do not drive an agent loop, so there is no budget hook
78
+ // to install and no reason to require an event bus.
79
+ if (typeof (ctx as unknown as { on?: unknown }).on !== 'function') return
80
+
81
+ const budgetByAgent = new Map<string, ReturnType<typeof createToolBudgetState>>()
82
+ const softExecutions = new Map<ToolExecutionToken, string>()
83
+ const pendingFinalOnly = new Map<string, Agent>()
84
+ const finalOnlyDisposers = new Map<string, () => void>()
85
+
86
+ const clearAgent = (agentId: string) => {
87
+ budgetByAgent.delete(agentId)
88
+ for (const [token, owner] of softExecutions) {
89
+ if (owner === agentId) softExecutions.delete(token)
90
+ }
91
+ pendingFinalOnly.delete(agentId)
92
+ finalOnlyDisposers.get(agentId)?.()
93
+ finalOnlyDisposers.delete(agentId)
94
+ }
95
+
96
+ const enterFinalOnly = (agent: Agent) => {
97
+ const agentId = String(agent.id)
98
+ if (finalOnlyDisposers.has(agentId)) return
99
+ const globalTools = ctx.tools as unknown as RestrictableTools
100
+ const scopedTools = agent.ctx?.tools as unknown as RestrictableTools | undefined
101
+ if (typeof globalTools.schemas !== 'function' || typeof scopedTools?.restrict !== 'function') return
102
+
103
+ // GoTry's model-facing tools are inherited globals. Removing their schemas
104
+ // makes the next native-mode request text-only; the execution wrapper below
105
+ // still denies any already-prepared same-step call beyond the hard limit.
106
+ const inheritedNames = globalTools.schemas()
107
+ .map(schema => schema.name)
108
+ .filter(name => name !== 'run_code')
109
+ if (inheritedNames.length === 0) return
110
+ finalOnlyDisposers.set(agentId, scopedTools.restrict({ deny: inheritedNames }))
111
+ }
112
+
113
+ ctx.on('session/event', (subject, event) => {
114
+ const agentId = String(subject.id)
115
+ if (event.type === 'turn/start' || event.type === 'turn/end') {
116
+ clearAgent(agentId)
117
+ return
118
+ }
119
+ // The live registry re-checks a tool name before starting every call in
120
+ // one assistant response. Restricting immediately on call 18 would turn an
121
+ // already-prepared call 19 into an opaque "unknown tool" before the
122
+ // execute waterfall can return TOOL_BUDGET_EXHAUSTED. step/end is the
123
+ // exact boundary after that batch settles and before the next prompt is
124
+ // assembled, so current-step refusals stay structured while the next
125
+ // native request is text-only.
126
+ if (event.type === 'step/end') {
127
+ const agent = pendingFinalOnly.get(agentId)
128
+ if (agent) {
129
+ pendingFinalOnly.delete(agentId)
130
+ enterFinalOnly(agent)
131
+ }
132
+ }
133
+ })
134
+ ctx.on('session/disposed', subject => clearAgent(String(subject.id)))
135
+
136
+ ctx.on('tools/execute', (exec, next) => {
137
+ // Programmatic/direct calls are not part of a model planner turn.
138
+ if (!exec.agent) return next()
139
+ const agentId = String(exec.agent.id)
140
+ const state = budgetByAgent.get(agentId) ?? createToolBudgetState()
141
+ budgetByAgent.set(agentId, state)
142
+ const decision = state.nextCall()
143
+ if (decision.kind === 'deny') {
144
+ pendingFinalOnly.set(agentId, exec.agent)
145
+ return Promise.resolve(exhaustionResult(decision.reason))
146
+ }
147
+ if (decision.softSignal) softExecutions.set(exec.token, agentId)
148
+ if (decision.exhaustsBudget) pendingFinalOnly.set(agentId, exec.agent)
149
+ return next()
150
+ })
151
+
152
+ ctx.on('tools/post-execute', (exec, _result, next) => {
153
+ if (!softExecutions.delete(exec.token)) return next()
154
+ return next().then(decision => ({
155
+ ...decision,
156
+ additionalContexts: [
157
+ ...(decision.additionalContexts ?? []),
158
+ convergenceContext(
159
+ 'TOOL_BUDGET_SOFT',
160
+ 'Tool call 16 reached. Converge now and produce the final answer from gathered evidence.',
161
+ ) as never,
162
+ ],
163
+ }))
164
+ })
165
+ }
@@ -1,32 +0,0 @@
1
- import process from 'node:process';
2
- import { runOnboardingWizard } from '../capabilities/session/wizard.js';
3
- function parseArgs(argv) {
4
- const args = {};
5
- for(let i = 0; i < argv.length; i += 1){
6
- const cur = argv[i];
7
- if (cur === '--extension-dir') args.extensionDir = argv[++i];
8
- else if (cur === '--source-dir') args.sourceDir = argv[++i];
9
- }
10
- return args;
11
- }
12
- async function main() {
13
- const args = parseArgs(process.argv.slice(2));
14
- const result = await runOnboardingWizard({
15
- dryRun: false,
16
- ...args.extensionDir ? {
17
- extensionDir: args.extensionDir
18
- } : {},
19
- ...args.sourceDir ? {
20
- sourceDir: args.sourceDir
21
- } : {}
22
- });
23
- process.stdout.write(JSON.stringify(result) + '\n');
24
- process.exit(0);
25
- }
26
- main().catch((e)=>{
27
- process.stderr.write(`[wizard-bootstrap] error: ${e instanceof Error ? e.message : String(e)}\n`);
28
- process.exit(2);
29
- });
30
-
31
-
32
- //# sourceURL=/Users/bytedance/work/gotry-publish/ts/scripts/wizard-bootstrap.ts