@danceiny/gotry 0.0.1-rc.15 → 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 (238) hide show
  1. package/README.md +51 -13
  2. package/README.zh-CN.md +26 -12
  3. package/bin/gotry-booking-copilot.js +53 -0
  4. package/bin/gotry-bootstrap.js +357 -8
  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 +15 -1
  10. package/data/airline-airports.json +39 -0
  11. package/dist/capabilities/agent-reach-deep.js +1 -1
  12. package/dist/capabilities/agent-reach.js +1 -1
  13. package/dist/capabilities/anything.js +1 -1
  14. package/dist/capabilities/artifacts.js +1 -1
  15. package/dist/capabilities/effect.js +293 -0
  16. package/dist/capabilities/fact-log.js +41 -0
  17. package/dist/capabilities/flyai.js +20 -6
  18. package/dist/capabilities/hbcli.js +43 -1
  19. package/dist/capabilities/incident-log.js +1 -1
  20. package/dist/capabilities/model-override.js +18 -0
  21. package/dist/capabilities/opensky.js +1 -1
  22. package/dist/capabilities/resilience.js +90 -0
  23. package/dist/capabilities/session/action-cache.js +1 -1
  24. package/dist/capabilities/session/adapters/ctrip-flight.js +1 -1
  25. package/dist/capabilities/session/adapters/meituan-local.js +1 -1
  26. package/dist/capabilities/session/benchmark.js +2 -1
  27. package/dist/capabilities/session/extension-bridge.js +358 -0
  28. package/dist/capabilities/session/extension-channel.js +93 -0
  29. package/dist/capabilities/session/extension-distribution.js +234 -0
  30. package/dist/capabilities/session/extract.js +1 -1
  31. package/dist/capabilities/session/golden-score.js +92 -0
  32. package/dist/capabilities/session/health-watch.js +216 -0
  33. package/dist/capabilities/session/read-guard.js +1 -1
  34. package/dist/capabilities/session/static-flight-golden.js +137 -0
  35. package/dist/capabilities/session/transport.js +1 -1
  36. package/dist/capabilities/session/wizard.js +147 -0
  37. package/dist/capabilities/session-consent.js +1 -1
  38. package/dist/capabilities/session-login.js +83 -1
  39. package/dist/capabilities/session-search.js +111 -2
  40. package/dist/capabilities/weather.js +168 -46
  41. package/dist/data/session-golden-20.json +25 -0
  42. package/dist/data/sf-golden-manifest.json +102 -0
  43. package/dist/data/sf-static-routes.json +91 -0
  44. package/dist/scripts/action-cache-tests.js +1 -1
  45. package/dist/scripts/agent-planning-budget-e2e.js +227 -0
  46. package/dist/scripts/agent-planning-budget-tests.js +173 -0
  47. package/dist/scripts/agent-reach-deep-tests.js +1 -1
  48. package/dist/scripts/agent-reach-tests.js +1 -1
  49. package/dist/scripts/agent-reach-wrapper-tests.js +1 -1
  50. package/dist/scripts/anything-tests.js +1 -1
  51. package/dist/scripts/async-collect.js +1 -1
  52. package/dist/scripts/benchmark-environment-bridge-e2e.js +981 -0
  53. package/dist/scripts/benchmark-environment-bridge-tests.js +2544 -0
  54. package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +335 -0
  55. package/dist/scripts/booking-copilot-availability-policy-v2-tests.js +1355 -0
  56. package/dist/scripts/booking-copilot-bin-proof-tests.js +89 -0
  57. package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +113 -0
  58. package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +356 -0
  59. package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +557 -0
  60. package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +140 -0
  61. package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +202 -0
  62. package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +102 -0
  63. package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +374 -0
  64. package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +447 -0
  65. package/dist/scripts/booking-copilot-runtime-proof-tests.js +205 -0
  66. package/dist/scripts/booking-copilot-server-proof-tests.js +317 -0
  67. package/dist/scripts/booking-copilot-startup-proof-tests.js +283 -0
  68. package/dist/scripts/booking-copilot-v2-runtime-proof-tests.js +3935 -0
  69. package/dist/scripts/booking-saga-tests.js +1 -1
  70. package/dist/scripts/booking-surface-contract-proof-tests.js +393 -0
  71. package/dist/scripts/booking-surface-v2-contract-proof-tests.js +1174 -0
  72. package/dist/scripts/bootstrap-tests.js +59 -3
  73. package/dist/scripts/build-changelog.js +279 -0
  74. package/dist/scripts/changelog-tests.js +165 -0
  75. package/dist/scripts/companion-tests.js +1 -1
  76. package/dist/scripts/diff-test.js +1 -1
  77. package/dist/scripts/dsh-runtime-closure-tests.js +225 -0
  78. package/dist/scripts/dsh-runtime-closure.js +150 -0
  79. package/dist/scripts/effect-tests.js +474 -0
  80. package/dist/scripts/engine-run.js +1 -1
  81. package/dist/scripts/engine-tests.js +1 -1
  82. package/dist/scripts/evaluation-cadence-tests.js +347 -0
  83. package/dist/scripts/evaluation-contract-tests.js +574 -0
  84. package/dist/scripts/extension-distribution-cli.js +35 -0
  85. package/dist/scripts/extension-distribution-tests.js +341 -0
  86. package/dist/scripts/extension-tests.js +573 -0
  87. package/dist/scripts/fact-gate-tests.js +318 -0
  88. package/dist/scripts/flyai-tests.js +1 -1
  89. package/dist/scripts/hbcli-e2e-tests.js +180 -0
  90. package/dist/scripts/hbcli-tests.js +1 -1
  91. package/dist/scripts/health-watch-cli.js +51 -0
  92. package/dist/scripts/i18n-tests.js +1 -1
  93. package/dist/scripts/incident-tests.js +1 -1
  94. package/dist/scripts/journey-tests.js +1 -1
  95. package/dist/scripts/ledger-tests.js +1 -1
  96. package/dist/scripts/ledger-workflow-crash.js +1 -1
  97. package/dist/scripts/memory-capture-tests.js +1 -1
  98. package/dist/scripts/memory-decay-tests.js +1 -1
  99. package/dist/scripts/memory-metrics.js +1 -1
  100. package/dist/scripts/memory-value-report.js +1 -1
  101. package/dist/scripts/model-override-e2e.js +176 -0
  102. package/dist/scripts/nightly-evidence-tests.js +67 -4
  103. package/dist/scripts/nightly-evidence.js +59 -3
  104. package/dist/scripts/nudge-digest.js +1 -1
  105. package/dist/scripts/onboarding-tests.js +186 -0
  106. package/dist/scripts/opensky-check.js +1 -1
  107. package/dist/scripts/opensky-tests.js +1 -1
  108. package/dist/scripts/pnpm-dsh-closure-proof.js +20 -0
  109. package/dist/scripts/price-drift-tests.js +441 -0
  110. package/dist/scripts/price-drift-watch.js +491 -0
  111. package/dist/scripts/probe-poi-tests.js +1 -1
  112. package/dist/scripts/product-metrics.js +1 -1
  113. package/dist/scripts/publish-preverify.js +40 -4
  114. package/dist/scripts/realtime-pricing-tests.js +1 -1
  115. package/dist/scripts/replay-async.js +1 -1
  116. package/dist/scripts/replay-real.js +1 -1
  117. package/dist/scripts/replay.js +1 -1
  118. package/dist/scripts/session-attach-diagnose.js +1 -1
  119. package/dist/scripts/session-attach-poc.js +1 -1
  120. package/dist/scripts/session-benchmark.js +1 -1
  121. package/dist/scripts/session-extract-tests.js +1 -1
  122. package/dist/scripts/session-login.js +1 -1
  123. package/dist/scripts/session-tests.js +70 -20
  124. package/dist/scripts/sf-live-benchmark.js +338 -0
  125. package/dist/scripts/sf-live-cli-tests.js +21 -0
  126. package/dist/scripts/sf-soft-score-tests.js +108 -0
  127. package/dist/scripts/sf-summary.js +93 -0
  128. package/dist/scripts/skeleton-check.js +1 -1
  129. package/dist/scripts/skeleton-integration-test.js +1 -1
  130. package/dist/scripts/skills-contract-tests.js +1 -1
  131. package/dist/scripts/smoke-session-gate-tests.js +29 -0
  132. package/dist/scripts/smoke.js +154 -33
  133. package/dist/scripts/state-cli-tests.js +1 -1
  134. package/dist/scripts/state-cli.js +1 -1
  135. package/dist/scripts/static-golden-tests.js +299 -0
  136. package/dist/scripts/time-eval-tests.js +1 -1
  137. package/dist/scripts/travel-timeline-tests.js +1 -1
  138. package/dist/scripts/unified-tests.js +1 -1
  139. package/dist/scripts/weather-tests.js +694 -44
  140. package/dist/scripts/z3-race-tests.js +1 -1
  141. package/dist/src/artifact-gate.js +310 -0
  142. package/dist/src/benchmark-agent-conformance.js +370 -0
  143. package/dist/src/benchmark-environment-bridge.js +384 -0
  144. package/dist/src/benchmark-headless-child-diagnostics.js +173 -0
  145. package/dist/src/benchmark-tool-isolation.js +124 -0
  146. package/dist/src/bookable-facts.js +349 -0
  147. package/dist/src/booking-saga.js +1 -1
  148. package/dist/src/booking-surface/availability-policy-v2.js +830 -0
  149. package/dist/src/booking-surface/canonical-schema.js +113 -0
  150. package/dist/src/booking-surface/contracts-v2.js +89 -0
  151. package/dist/src/booking-surface/contracts.js +46 -0
  152. package/dist/src/booking-surface/dsh-planner.js +453 -0
  153. package/dist/src/booking-surface/dsh-plugin.js +93 -0
  154. package/dist/src/booking-surface/error-codes.js +94 -0
  155. package/dist/src/booking-surface/index.js +15 -0
  156. package/dist/src/booking-surface/profile.js +68 -0
  157. package/dist/src/booking-surface/runtime-v2.js +1771 -0
  158. package/dist/src/booking-surface/runtime.js +351 -0
  159. package/dist/src/booking-surface/server-v2.js +334 -0
  160. package/dist/src/booking-surface/server.js +302 -0
  161. package/dist/src/booking-surface/startup.js +159 -0
  162. package/dist/src/booking-surface/validation-v2.js +319 -0
  163. package/dist/src/booking-surface/validation.js +809 -0
  164. package/dist/src/bridge.js +1 -1
  165. package/dist/src/companions.js +1 -1
  166. package/dist/src/contracts.js +1 -1
  167. package/dist/src/dsh-llm.js +1 -1
  168. package/dist/src/engine.js +1 -1
  169. package/dist/src/evaluation-cadence.js +234 -0
  170. package/dist/src/evaluation-contracts.js +906 -0
  171. package/dist/src/i18n.js +1 -1
  172. package/dist/src/index.js +234 -60
  173. package/dist/src/journey.js +1 -1
  174. package/dist/src/loop.js +1 -1
  175. package/dist/src/memory-capture.js +1 -1
  176. package/dist/src/memory-decay.js +1 -1
  177. package/dist/src/memory-utility.js +1 -1
  178. package/dist/src/mock-llm.js +1 -1
  179. package/dist/src/model.js +1 -1
  180. package/dist/src/realtime-pricing.js +14 -7
  181. package/dist/src/slot-spec.js +1 -1
  182. package/dist/src/state-ledger.js +2 -1
  183. package/dist/src/time-anchor.js +1 -1
  184. package/dist/src/tool-budget.js +136 -0
  185. package/dist/src/tool-packet.js +1 -1
  186. package/dist/src/travel-slots.js +1 -1
  187. package/dist/src/travel-timeline.js +1 -1
  188. package/dist/src/unified.js +1 -1
  189. package/dist/src/wish-pool.js +1 -1
  190. package/dist/src/z3-shared.js +1 -1
  191. package/extension/README.md +50 -0
  192. package/extension/background.js +160 -0
  193. package/extension/content-bridge.js +41 -0
  194. package/extension/content-main.js +62 -0
  195. package/extension/manifest.json +32 -0
  196. package/package.json +291 -12
  197. package/schemas/booking.surface.v1.schema.json +927 -0
  198. package/schemas/booking.surface.v2.schema.json +61 -0
  199. package/ts/capabilities/fact-log.ts +54 -0
  200. package/ts/capabilities/flyai.ts +16 -3
  201. package/ts/capabilities/hbcli.ts +46 -0
  202. package/ts/capabilities/session/benchmark.ts +4 -1
  203. package/ts/capabilities/session/extension-bridge.ts +377 -0
  204. package/ts/capabilities/session/extension-channel.ts +95 -0
  205. package/ts/capabilities/session/extension-distribution.ts +264 -0
  206. package/ts/capabilities/session/golden-score.ts +139 -0
  207. package/ts/capabilities/session/health-watch.ts +257 -0
  208. package/ts/capabilities/session/static-flight-golden.ts +209 -0
  209. package/ts/capabilities/session/wizard.ts +140 -0
  210. package/ts/capabilities/session-login.ts +63 -2
  211. package/ts/capabilities/session-search.ts +105 -3
  212. package/ts/capabilities/weather.ts +141 -52
  213. package/ts/package.json +3 -3
  214. package/ts/src/artifact-gate.ts +365 -0
  215. package/ts/src/benchmark-agent-conformance.ts +448 -0
  216. package/ts/src/benchmark-environment-bridge.ts +348 -0
  217. package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
  218. package/ts/src/benchmark-tool-isolation.ts +166 -0
  219. package/ts/src/bookable-facts.ts +557 -0
  220. package/ts/src/booking-surface/availability-policy-v2.ts +523 -0
  221. package/ts/src/booking-surface/canonical-schema.js +113 -0
  222. package/ts/src/booking-surface/contracts-v2.ts +118 -0
  223. package/ts/src/booking-surface/contracts.ts +380 -0
  224. package/ts/src/booking-surface/dsh-planner.ts +452 -0
  225. package/ts/src/booking-surface/dsh-plugin.js +93 -0
  226. package/ts/src/booking-surface/error-codes.ts +101 -0
  227. package/ts/src/booking-surface/index.ts +12 -0
  228. package/ts/src/booking-surface/profile.ts +42 -0
  229. package/ts/src/booking-surface/runtime-v2.ts +1466 -0
  230. package/ts/src/booking-surface/runtime.ts +483 -0
  231. package/ts/src/booking-surface/server-v2.ts +247 -0
  232. package/ts/src/booking-surface/server.ts +324 -0
  233. package/ts/src/booking-surface/startup.ts +196 -0
  234. package/ts/src/booking-surface/validation-v2.ts +205 -0
  235. package/ts/src/booking-surface/validation.ts +453 -0
  236. package/ts/src/index.ts +161 -14
  237. package/ts/src/state-ledger.ts +1 -0
  238. package/ts/src/tool-budget.ts +165 -0
@@ -0,0 +1,136 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ export const TOOL_BUDGET_SOFT_CALL = 16;
3
+ export const TOOL_BUDGET_HARD_CALL = 18;
4
+ export const TOOL_BUDGET_EXHAUSTED = 'TOOL_BUDGET_EXHAUSTED';
5
+ export function toolBudgetDecision(callNumber) {
6
+ if (callNumber > TOOL_BUDGET_HARD_CALL) {
7
+ return {
8
+ kind: 'deny',
9
+ reason: `${TOOL_BUDGET_EXHAUSTED}: maximum ${TOOL_BUDGET_HARD_CALL} real tool dispatches per agent turn reached; provide a final answer using existing results`
10
+ };
11
+ }
12
+ return {
13
+ kind: 'allow',
14
+ softSignal: callNumber === TOOL_BUDGET_SOFT_CALL,
15
+ exhaustsBudget: callNumber === TOOL_BUDGET_HARD_CALL
16
+ };
17
+ }
18
+ export function createToolBudgetState() {
19
+ let calls = 0;
20
+ return {
21
+ nextCall () {
22
+ calls += 1;
23
+ return {
24
+ ...toolBudgetDecision(calls),
25
+ callNumber: calls
26
+ };
27
+ }
28
+ };
29
+ }
30
+ function convergenceContext(code, text) {
31
+ return {
32
+ id: randomUUID(),
33
+ role: 'user',
34
+ content: [
35
+ {
36
+ type: 'text',
37
+ text: `${code}: ${text}`
38
+ }
39
+ ],
40
+ source: {
41
+ kind: 'plugin',
42
+ plugin: 'gotry-tool-budget'
43
+ }
44
+ };
45
+ }
46
+ function exhaustionResult(reason) {
47
+ return {
48
+ isError: true,
49
+ error: {
50
+ message: reason,
51
+ info: {
52
+ name: 'ToolBudgetError',
53
+ code: TOOL_BUDGET_EXHAUSTED
54
+ }
55
+ },
56
+ content: [
57
+ {
58
+ type: 'text',
59
+ text: reason
60
+ }
61
+ ],
62
+ additionalContexts: [
63
+ convergenceContext(TOOL_BUDGET_EXHAUSTED, 'No more tool dispatches are permitted in this turn. Produce the final answer from existing results.')
64
+ ]
65
+ };
66
+ }
67
+ export function installToolBudget(ctx) {
68
+ if (typeof ctx.on !== 'function') return;
69
+ const budgetByAgent = new Map();
70
+ const softExecutions = new Map();
71
+ const pendingFinalOnly = new Map();
72
+ const finalOnlyDisposers = new Map();
73
+ const clearAgent = (agentId)=>{
74
+ budgetByAgent.delete(agentId);
75
+ for (const [token, owner] of softExecutions){
76
+ if (owner === agentId) softExecutions.delete(token);
77
+ }
78
+ pendingFinalOnly.delete(agentId);
79
+ finalOnlyDisposers.get(agentId)?.();
80
+ finalOnlyDisposers.delete(agentId);
81
+ };
82
+ const enterFinalOnly = (agent)=>{
83
+ const agentId = String(agent.id);
84
+ if (finalOnlyDisposers.has(agentId)) return;
85
+ const globalTools = ctx.tools;
86
+ const scopedTools = agent.ctx?.tools;
87
+ if (typeof globalTools.schemas !== 'function' || typeof scopedTools?.restrict !== 'function') return;
88
+ const inheritedNames = globalTools.schemas().map((schema)=>schema.name).filter((name)=>name !== 'run_code');
89
+ if (inheritedNames.length === 0) return;
90
+ finalOnlyDisposers.set(agentId, scopedTools.restrict({
91
+ deny: inheritedNames
92
+ }));
93
+ };
94
+ ctx.on('session/event', (subject, event)=>{
95
+ const agentId = String(subject.id);
96
+ if (event.type === 'turn/start' || event.type === 'turn/end') {
97
+ clearAgent(agentId);
98
+ return;
99
+ }
100
+ if (event.type === 'step/end') {
101
+ const agent = pendingFinalOnly.get(agentId);
102
+ if (agent) {
103
+ pendingFinalOnly.delete(agentId);
104
+ enterFinalOnly(agent);
105
+ }
106
+ }
107
+ });
108
+ ctx.on('session/disposed', (subject)=>clearAgent(String(subject.id)));
109
+ ctx.on('tools/execute', (exec, next)=>{
110
+ if (!exec.agent) return next();
111
+ const agentId = String(exec.agent.id);
112
+ const state = budgetByAgent.get(agentId) ?? createToolBudgetState();
113
+ budgetByAgent.set(agentId, state);
114
+ const decision = state.nextCall();
115
+ if (decision.kind === 'deny') {
116
+ pendingFinalOnly.set(agentId, exec.agent);
117
+ return Promise.resolve(exhaustionResult(decision.reason));
118
+ }
119
+ if (decision.softSignal) softExecutions.set(exec.token, agentId);
120
+ if (decision.exhaustsBudget) pendingFinalOnly.set(agentId, exec.agent);
121
+ return next();
122
+ });
123
+ ctx.on('tools/post-execute', (exec, _result, next)=>{
124
+ if (!softExecutions.delete(exec.token)) return next();
125
+ return next().then((decision)=>({
126
+ ...decision,
127
+ additionalContexts: [
128
+ ...decision.additionalContexts ?? [],
129
+ convergenceContext('TOOL_BUDGET_SOFT', 'Tool call 16 reached. Converge now and produce the final answer from gathered evidence.')
130
+ ]
131
+ }));
132
+ });
133
+ }
134
+
135
+
136
+ //# sourceURL=ts/src/tool-budget.ts
@@ -9,4 +9,4 @@ export function interpretArgs(args, stringKey) {
9
9
  }
10
10
 
11
11
 
12
- //# sourceURL=/Users/bytedance/work/gotry/ts/src/tool-packet.ts
12
+ //# sourceURL=ts/src/tool-packet.ts
@@ -141,4 +141,4 @@ export function scoreExtraction(expected, actual) {
141
141
  }
142
142
 
143
143
 
144
- //# sourceURL=/Users/bytedance/work/gotry/ts/src/travel-slots.ts
144
+ //# sourceURL=ts/src/travel-slots.ts
@@ -75,4 +75,4 @@ export function timelineGapsForVerified(timeline, verifiedWishes) {
75
75
  export { ymd };
76
76
 
77
77
 
78
- //# sourceURL=/Users/bytedance/work/gotry/ts/src/travel-timeline.ts
78
+ //# sourceURL=ts/src/travel-timeline.ts
@@ -588,4 +588,4 @@ function renderCandidateMarkdown(req, verdicts, recommended) {
588
588
  export { minToHhmm };
589
589
 
590
590
 
591
- //# sourceURL=/Users/bytedance/work/gotry/ts/src/unified.ts
591
+ //# sourceURL=ts/src/unified.ts
@@ -24,4 +24,4 @@ export function pickNudgeWish(pool, ctx) {
24
24
  }
25
25
 
26
26
 
27
- //# sourceURL=/Users/bytedance/work/gotry/ts/src/wish-pool.ts
27
+ //# sourceURL=ts/src/wish-pool.ts
@@ -15,4 +15,4 @@ export async function withZ3(label, session) {
15
15
  }
16
16
 
17
17
 
18
- //# sourceURL=/Users/bytedance/work/gotry/ts/src/z3-shared.ts
18
+ //# sourceURL=ts/src/z3-shared.ts
@@ -0,0 +1,50 @@
1
+ # GoTry Session Bridge(浏览器扩展)
2
+
3
+ 一次性安装的会话检索数据面(issue #21 传输层方案 C,2026-08-29 founder 定案):在你**自己的** Chrome 登录态里,只读嗅探携程机票检索回包([会话:ctrip-flight]。gotry 不再需要逐连接弹 Chrome 权限框,也不需要开 `chrome://inspect` 远程调试。
4
+
5
+ ## 它做什么 / 不做什么
6
+
7
+ - ✅ 检索:你(或 agent)发起会话检索时,后台标签页打开携程机票列表页,被动嗅探页面自己发出的 `batchSearch` 响应,文本回传给本机的 gotry。收尾自动关闭自己开的标签。
8
+ - ✅ 登录检查:只读登录票据 cookie 的**名字**(cticket/uid/uname/passport),判断「是否已登录」这个布尔事实。
9
+ - ✅ 登录引导:把登录入口页**置前台**打开,登录由你在携程官网完成。
10
+ - ❌ **不读取、不存储、不回传任何 cookie 值,不接触密码/验证码**;
11
+ - ❌ 不向任何站点发起请求(检索请求由站点页面自己发出,扩展只听不写);
12
+ - ❌ 不动你已打开的任何标签页(只创建/关闭自己的检索标签;登录标签留给你)。
13
+
14
+ ## 安装(每台浏览器一次)
15
+
16
+ ### 方式一(推荐):Chrome 应用商店一键安装
17
+
18
+ 打开商店页点「添加至 Chrome」即可,零开发者模式、零手动加载,**自动更新**:
19
+
20
+ **https://chromewebstore.google.com/detail/gotry-session-bridge/oeajpiccmonococjcegddlooeeohlbgd**
21
+
22
+ 商店版经 Google 审核上架(2026-09-02),版本跟随商店发版节奏。
23
+
24
+ ### 方式二:GitHub Releases 本地加载(免审核,版本更新更快)
25
+
26
+ 不经商店审核,版本化 tarball + SHA256 校验,与 npm 发版节奏解耦,更新比商店快:
27
+
28
+ ```bash
29
+ npx gotry setup --extension-from=github # 自动下载校验并落位 ~/.gotry/extension
30
+ ```
31
+
32
+ (或手动:从 [github.com/Danceiny/gotry/releases](https://github.com/Danceiny/gotry/releases) 标签 `ext-*` 下载 `gotry-session-bridge.tar.gz` 解压到任意固定位置。)
33
+
34
+ 然后在 Chrome 地址栏打开 `chrome://extensions` → 右上角开启「开发者模式」→ 点「加载已解压的扩展程序」选择该目录。
35
+
36
+ ### 方式三:npm 包内副本本地加载(离线确定性)
37
+
38
+ ```bash
39
+ npx gotry setup # 把包内扩展落位到 ~/.gotry/extension
40
+ ```
41
+
42
+ 再按方式二的 `chrome://extensions` 三步加载该目录。
43
+
44
+ 装好即生效,无任何系统弹窗。卸载/随时可停:扩展卡片上的开关即是总闸(仍受 gotry 授权闸 `sessionAccess` 双重控制)。
45
+
46
+ ## 自检
47
+
48
+ - 商店版扩展 ID 固定为 `oeajpiccmonococjcegddlooeeohlbgd`(商店用自己的签名 key,与 unpacked 版 ID 不同,二者都是同一扩展,本机 gotry 桥双通道同信);
49
+ - 本地加载(unpacked)版扩展 ID 应为固定的 `olpgkofjhhiiiahdkkbcninhjmegghfe`(manifest 带 `key`,跨机器稳定)——若不一致,说明 manifest 被改动过,不要加载;
50
+ - gotry 侧运行 `npx gotry` 后发起一次会话检索,扩展图标应出现(无需点击);桥状态可看 `curl http://127.0.0.1:8791/status`(仅本机回环)。
@@ -0,0 +1,160 @@
1
+ /**
2
+ * GoTry Session Bridge — MV3 Service Worker(RFC user-session-data-rfc.md §2.2 通道 C,2026-08-29 定案为 PRIMARY 传输)。
3
+ *
4
+ * 职责(与 Node 侧 session/extension-bridge.ts 配对,零构建纯 JS):
5
+ * - 长轮询取活:POST /jobs(桥最多 hold 20s;每次响应/失败都重置 SW 30s 生命周期,任务秒级触达);
6
+ * 断线每 5s 重试,chrome.alarms(30s)兜底唤醒防 SW 悬挂。
7
+ * - 三种 job:
8
+ * search → 后台标签打开 job.url(仅 flights.ctrip.com 白名单),等 content hook 嗅探回包,收尾关自己的标签;
9
+ * open-login → 置前台打开登录入口页(登录页纪律 #34),标签留给用户,绝不代关;
10
+ * cookie-names → chrome.cookies 只读票据 cookie **名字**(值即取即弃,永不离开扩展——红线)。
11
+ * - 物理只读(ReadGuard 扩展车道形态):本 SW 绝不向站点发任何请求——检索请求由站点自己的
12
+ * 页面代码发出,我们只「导航 + 被动转发 NETWORK_HINTS 命中响应」;写不是被禁止的行为,是不存在的原语。
13
+ */
14
+
15
+ 'use strict'
16
+
17
+ const BRIDGE_PORTS = [8791, 8792, 8793, 8794, 8795]
18
+ const RETRY_MS = 5_000
19
+
20
+ /** 站点注册表(与 Node 侧 LOGIN_TARGETS/LOGIN_COOKIE_NAMES 对账,防漂移测试守住) */
21
+ const SITES = {
22
+ 'ctrip-flight': {
23
+ domain: 'ctrip.com',
24
+ ticketNames: ['cticket', 'uid', 'uname', 'passport'],
25
+ },
26
+ }
27
+
28
+ let activePort = null
29
+ let polling = false
30
+
31
+ function sleep(ms) {
32
+ return new Promise((resolve) => setTimeout(resolve, ms))
33
+ }
34
+
35
+ async function detectPort() {
36
+ for (const p of BRIDGE_PORTS) {
37
+ try {
38
+ const r = await fetch(`http://127.0.0.1:${p}/health`, { headers: { 'x-gotry-bridge': 'v1' } })
39
+ if (r.ok) return p
40
+ } catch { /* 无人监听,试下一个端口 */ }
41
+ }
42
+ return null
43
+ }
44
+
45
+ async function postResult(jobId, result) {
46
+ if (activePort == null || !jobId) return
47
+ try {
48
+ await fetch(`http://127.0.0.1:${activePort}/results/${encodeURIComponent(jobId)}`, {
49
+ method: 'POST',
50
+ headers: { 'content-type': 'application/json', 'x-gotry-bridge': 'v1' },
51
+ body: JSON.stringify(result),
52
+ })
53
+ } catch { /* 桥可能已退场;Node 侧超时兜底 */ }
54
+ }
55
+
56
+ /** 只读票据 cookie 名单(只上报名;chrome.cookies 的值就地丢弃,不进任何结果对象) */
57
+ async function ticketNames(site) {
58
+ const conf = SITES[site]
59
+ if (!conf) return []
60
+ const cookies = await chrome.cookies.getAll({ domain: conf.domain }).catch(() => [])
61
+ return (Array.isArray(cookies) ? cookies : [])
62
+ .map((c) => c.name)
63
+ .filter((n) => conf.ticketNames.includes(n))
64
+ }
65
+
66
+ /** 后台标签等嗅探回包;超时带回页标题(供 Node 侧 CHALLENGE_RE 判定),收尾关自己的标签 */
67
+ function waitSniff(tabId, timeoutMs) {
68
+ return new Promise((resolve) => {
69
+ let settled = false
70
+ let title = ''
71
+ const handler = (msg, sender) => {
72
+ if (!sender || !sender.tab || sender.tab.id !== tabId) return
73
+ if (msg && msg.type === 'gotry-page') { title = String(msg.title ?? title); return }
74
+ if (msg && msg.type === 'gotry-sniff' && !settled) {
75
+ settled = true
76
+ clearTimeout(timer)
77
+ chrome.runtime.onMessage.removeListener(handler)
78
+ resolve({ ok: true, kind: 'search', body: String(msg.body ?? ''), title })
79
+ }
80
+ }
81
+ const timer = setTimeout(() => {
82
+ if (settled) return
83
+ settled = true
84
+ chrome.runtime.onMessage.removeListener(handler)
85
+ resolve({ ok: false, kind: 'search', timeout: true, title })
86
+ }, Math.max(Number(timeoutMs) || 30_000, 5_000))
87
+ chrome.runtime.onMessage.addListener(handler)
88
+ })
89
+ }
90
+
91
+ async function handleJob(job) {
92
+ const jobId = job && job.jobId
93
+ if (typeof jobId !== 'string' || !jobId) return
94
+ const site = String((job && job.site) || '')
95
+ const conf = SITES[site]
96
+ try {
97
+ if (!conf) {
98
+ await postResult(jobId, { ok: false, error: `unknown site ${site}` })
99
+ return
100
+ }
101
+ if (job.kind === 'cookie-names') {
102
+ await postResult(jobId, { ok: true, kind: 'cookie-names', names: await ticketNames(site) })
103
+ return
104
+ }
105
+ if (job.kind === 'open-login') {
106
+ if (typeof job.url !== 'string' || !job.url.startsWith('https://')) {
107
+ await postResult(jobId, { ok: false, error: 'open-login 需要 https job.url' })
108
+ return
109
+ }
110
+ const tab = await chrome.tabs.create({ url: job.url, active: true })
111
+ await postResult(jobId, { ok: true, kind: 'open-login', opened: true, tabId: tab.id })
112
+ return
113
+ }
114
+ if (job.kind === 'search') {
115
+ if (typeof job.url !== 'string' || !job.url.startsWith('https://flights.ctrip.com/')) {
116
+ await postResult(jobId, { ok: false, error: `search 只允许 flights.ctrip.com 域(收到 ${String(job.url).slice(0, 80)})` })
117
+ return
118
+ }
119
+ const tab = await chrome.tabs.create({ url: job.url, active: false })
120
+ const result = await waitSniff(tab.id, job.timeoutMs)
121
+ await chrome.tabs.remove(tab.id).catch(() => { /* 用户先关了,无妨 */ })
122
+ await postResult(jobId, result)
123
+ return
124
+ }
125
+ await postResult(jobId, { ok: false, error: `unknown job kind ${String(job.kind)}` })
126
+ } catch (e) {
127
+ await postResult(jobId, { ok: false, error: String(e && e.message ? e.message : e).slice(0, 200) })
128
+ }
129
+ }
130
+
131
+ async function loop() {
132
+ if (polling) return
133
+ polling = true
134
+ try {
135
+ for (;;) {
136
+ if (activePort == null) activePort = await detectPort()
137
+ if (activePort == null) { await sleep(RETRY_MS); continue }
138
+ try {
139
+ const r = await fetch(`http://127.0.0.1:${activePort}/jobs`, {
140
+ method: 'POST',
141
+ headers: { 'content-type': 'application/json', 'x-gotry-bridge': 'v1' },
142
+ body: JSON.stringify({
143
+ extensionVersion: chrome.runtime.getManifest().version,
144
+ capabilities: Object.keys(SITES),
145
+ }),
146
+ })
147
+ const data = await r.json().catch(() => ({ job: null }))
148
+ if (data && data.job) await handleJob(data.job)
149
+ } catch { activePort = null; await sleep(RETRY_MS) }
150
+ }
151
+ } finally {
152
+ polling = false
153
+ }
154
+ }
155
+
156
+ // SW 冷启动 + 闹钟兜底双保险;loop() 幂等
157
+ if (chrome.runtime.onStartup) chrome.runtime.onStartup.addListener(() => { void loop() })
158
+ chrome.alarms.create('gotry-bridge-poll', { periodInMinutes: 0.5 })
159
+ chrome.alarms.onAlarm.addListener((a) => { if (a.name === 'gotry-bridge-poll') void loop() })
160
+ void loop()
@@ -0,0 +1,41 @@
1
+ /**
2
+ * GoTry Session Bridge — ISOLATED-world 桥(manifest 默认 world,document_start)。
3
+ *
4
+ * MAIN world(content-main.js)拿不到 chrome API;本脚本监听页面里的
5
+ * gotry-ctrip-sniff 自定义事件,把响应文本经 chrome.runtime.sendMessage 转发给
6
+ * Service Worker(onMessage 按 sender.tab.id 归属到对应 search job)。
7
+ *
8
+ * 附带页标题快报(gotry-page):SW 在嗅探超时/挑战判定(CHALLENGE_RE)时用它。
9
+ */
10
+ ;(function () {
11
+ if (window.__gotrySniffBridge) return
12
+ window.__gotrySniffBridge = true
13
+
14
+ window.addEventListener('gotry-ctrip-sniff', function (ev) {
15
+ try {
16
+ var d = (ev && ev.detail) || {}
17
+ if (!d.body) return
18
+ chrome.runtime.sendMessage({
19
+ type: 'gotry-sniff',
20
+ url: d.url,
21
+ body: d.body,
22
+ title: document.title || '',
23
+ }).catch(function () { /* SW 重启中,下一条嗅探再投 */ })
24
+ } catch { /* 不抛 */ }
25
+ })
26
+
27
+ function sendPage() {
28
+ try {
29
+ chrome.runtime.sendMessage({
30
+ type: 'gotry-page',
31
+ title: document.title || '',
32
+ url: location.href,
33
+ }).catch(function () { /* SW 侧无等待者,常态丢弃 */ })
34
+ } catch { /* 环境异常不抛 */ }
35
+ }
36
+ if (document.readyState === 'loading') {
37
+ window.addEventListener('DOMContentLoaded', sendPage, { once: true })
38
+ } else {
39
+ sendPage()
40
+ }
41
+ })()
@@ -0,0 +1,62 @@
1
+ /**
2
+ * GoTry Session Bridge — MAIN-world 网络嗅探(manifest world:"MAIN",document_start)。
3
+ *
4
+ * MAIN world 没有 chrome.runtime,只负责:hook 站点自己的 fetch/XHR,把命中
5
+ * NETWORK_HINTS(batchSearch)的响应文本以 CustomEvent 派发到页面里;
6
+ * ISOLATED 侧的 content-bridge.js 监听事件并经 chrome.runtime 转发给 Service Worker。
7
+ *
8
+ * 只读被动转发:不修改请求、不重放、不伪造(§2.3 反模式红线)——响应由站点自己的
9
+ * 代码发出,我们只听。
10
+ */
11
+ ;(function () {
12
+ if (window.__gotrySniffInstalled) return
13
+ window.__gotrySniffInstalled = true
14
+
15
+ /** 与 Node 侧 adapters/ctrip-flight.ts NETWORK_HINTS 对账(run-all §38 防漂移断言) */
16
+ var HINT_RE = /search\/api\/search\/batchSearch/
17
+
18
+ function dispatch(url, body) {
19
+ try {
20
+ window.dispatchEvent(new CustomEvent('gotry-ctrip-sniff', { detail: { url: String(url), body: String(body) } }))
21
+ } catch { /* 页面环境异常不抛 */ }
22
+ }
23
+
24
+ var origFetch = window.fetch
25
+ if (typeof origFetch === 'function') {
26
+ window.fetch = function (input, init) {
27
+ return origFetch.apply(this, arguments).then(function (res) {
28
+ try {
29
+ var url = ''
30
+ if (typeof input === 'string') url = input
31
+ else if (input && typeof input.url === 'string') url = input.url
32
+ if (HINT_RE.test(url)) {
33
+ var clone = res.clone()
34
+ clone.text().then(function (t) { dispatch(url, t) }).catch(function () { /* 流不可读则跳过 */ })
35
+ }
36
+ } catch { /* 嗅探失败不影响站点自身 */ }
37
+ return res
38
+ })
39
+ }
40
+ }
41
+
42
+ var origOpen = XMLHttpRequest.prototype.open
43
+ var origSend = XMLHttpRequest.prototype.send
44
+ XMLHttpRequest.prototype.open = function (method, url) {
45
+ this.__gotryUrl = typeof url === 'string' ? url : String(url ?? '')
46
+ return origOpen.apply(this, arguments)
47
+ }
48
+ XMLHttpRequest.prototype.send = function () {
49
+ var xhr = this
50
+ xhr.addEventListener('load', function () {
51
+ try {
52
+ if (!xhr.__gotryUrl || !HINT_RE.test(xhr.__gotryUrl)) return
53
+ var body = ''
54
+ if (xhr.responseType === '' || xhr.responseType === 'text') body = xhr.responseText
55
+ else if (xhr.responseType === 'json') body = JSON.stringify(xhr.response)
56
+ else return
57
+ if (body) dispatch(xhr.__gotryUrl, body)
58
+ } catch { /* 嗅探失败不影响站点 */ }
59
+ })
60
+ return origSend.apply(this, arguments)
61
+ }
62
+ })()
@@ -0,0 +1,32 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "GoTry Session Bridge",
4
+ "version": "0.1.0",
5
+ "description": "GoTry 会话检索桥(issue #21):在你自己的登录态里只读嗅探检索回包与登录票据 cookie 名;零凭证经手,登录在官网由你完成,检索只读不写。gotry 侧不再需要开启 Remote Debugging,也没有任何系统级权限弹窗。",
6
+ "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnuzBX8rT8+RZKEUip5VRA0cY056pExy9PNdN9YCiuY3dgglRbcIBhjuFJoR6EX3/MaUv82vJVyItRVrowXLTwDk4WZof0vwFgKL0zBK304PC46pUaAKTSu1PgXeL1+j5KTAGz/9a9+RnPdbj7jND5rM/MOmBHNPVPpp1NlwxRGIgF9OxHSOfXORcH4Iyte1aJSFUJbFtNS/DaE5D+KjyupPLyIqVN/dCiKnNsTCEHQB9ngeli665PFp76hkccHQQZ4sVuMLS4zBPcazUsp1kcnW+xsQoUATkODTCY+Pzk3zUVF1QOESTjRCVnbNi8tkO43RMRs2q63gX/3inFivcEwIDAQAB",
7
+ "permissions": ["cookies", "alarms"],
8
+ "host_permissions": [
9
+ "http://127.0.0.1:8791/*",
10
+ "http://127.0.0.1:8792/*",
11
+ "http://127.0.0.1:8793/*",
12
+ "http://127.0.0.1:8794/*",
13
+ "http://127.0.0.1:8795/*",
14
+ "https://*.ctrip.com/*"
15
+ ],
16
+ "background": {
17
+ "service_worker": "background.js"
18
+ },
19
+ "content_scripts": [
20
+ {
21
+ "matches": ["https://flights.ctrip.com/*"],
22
+ "js": ["content-main.js"],
23
+ "run_at": "document_start",
24
+ "world": "MAIN"
25
+ },
26
+ {
27
+ "matches": ["https://flights.ctrip.com/*"],
28
+ "js": ["content-bridge.js"],
29
+ "run_at": "document_start"
30
+ }
31
+ ]
32
+ }