@openchamber/web 2.0.2 → 2.0.4

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 (257) hide show
  1. package/bin/lib/DOCUMENTATION.md +1 -1
  2. package/bin/lib/commands-connect-url.js +6 -5
  3. package/bin/lib/commands-tunnel.js +24 -5
  4. package/dist/assets/{CodeMirrorCommentWidgets-CmKmyb9T.js → CodeMirrorCommentWidgets-C_zL-eri.js} +1 -1
  5. package/dist/assets/{DiffView-8-PFpZ2p.js → DiffView-BeN2_YYF.js} +3 -3
  6. package/dist/assets/FilesView-CN34wm_N.js +17 -0
  7. package/dist/assets/{GitView-DNUSu00w.js → GitView-DLDazOo1.js} +4 -4
  8. package/dist/assets/{GuestAttachDialog-Cv6QzjHC.js → GuestAttachDialog-C0xe_Lyy.js} +1 -1
  9. package/dist/assets/{GuestSurfacePane-Bt3jB_Ye.js → GuestSurfacePane-BdaurnDr.js} +1 -1
  10. package/dist/assets/{JsonTreeView-BlyHTRhM.js → JsonTreeView-B1Xq-k2t.js} +1 -1
  11. package/dist/assets/LinearIssuesView-BryoAHow.js +1 -0
  12. package/dist/assets/{MarkdownImageGallery-2UXJF-5B.js → MarkdownImageGallery-DfuEoaGq.js} +1 -1
  13. package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +12 -0
  14. package/dist/assets/OnboardingScreen-C22bGmnP.js +1 -0
  15. package/dist/assets/{PatchDiff-ByvnbG5T.js → PatchDiff-0xd6UeFB.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-BXieg0mH.js → PierreDiffViewer-BC950e3F.js} +3 -3
  17. package/dist/assets/PlanView-B7Xgihqk.js +5 -0
  18. package/dist/assets/PluginPane-2C71F8uF.js +3 -0
  19. package/dist/assets/SettingsView-m_zoFiaT.js +30 -0
  20. package/dist/assets/{SettingsWindow-BIz224xs.js → SettingsWindow-CofS020b.js} +1 -1
  21. package/dist/assets/{SubmoduleDiffSummary-CXKmlps9.js → SubmoduleDiffSummary-BSA9gnIO.js} +1 -1
  22. package/dist/assets/{ToolOutputDialog-BsgAK8xu.js → ToolOutputDialog-DprkVKcj.js} +7 -7
  23. package/dist/assets/{ToolPartDiffPreview-vdPObXOf.js → ToolPartDiffPreview-Dq0go_fX.js} +2 -2
  24. package/dist/assets/{VirtualizedFileDiff-BkFNKWS5.js → VirtualizedFileDiff-Kp8hKJdT.js} +1 -1
  25. package/dist/assets/WalkthroughView-DGnTzqIU.js +4 -0
  26. package/dist/assets/{appThemeRegistry-aHUNHoqP.js → appThemeRegistry-BdEHBA4s.js} +1 -1
  27. package/dist/assets/{commitAndPush-Bon9r94r.js → commitAndPush-LwtVa2Oc.js} +1 -1
  28. package/dist/assets/{computeVirtualFileMetrics-DKqr_1AQ.js → computeVirtualFileMetrics-6V1xNpO9.js} +2 -2
  29. package/dist/assets/de-DlgBHUAI.js +10 -0
  30. package/dist/assets/es-BC8G41U8.js +16 -0
  31. package/dist/assets/fr-I0z3vVjy.js +14 -0
  32. package/dist/assets/index-CgR5rJq_.js +41 -0
  33. package/dist/assets/{index-DpFttslC.js → index-CmNPYddV.js} +1 -1
  34. package/dist/assets/index-adyy_sEk.css +1 -0
  35. package/dist/assets/{isDiffPlainText-kzAgpIgi.js → isDiffPlainText-1bXcWCrw.js} +1 -1
  36. package/dist/assets/{isFilePlainText-Uj6y-jzz.js → isFilePlainText-CBAppvy1.js} +1 -1
  37. package/dist/assets/ja-BIElEsY8.js +16 -0
  38. package/dist/assets/ko-DRnnHetA.js +16 -0
  39. package/dist/assets/{main-CbfMxn-I.js → main-CzjTMTfW.js} +2 -2
  40. package/dist/assets/main-DVX34beR.js +886 -0
  41. package/dist/assets/markdownCore-Cxbkn5NR.js +7 -0
  42. package/dist/assets/{miniChat-CiAKBC10.js → miniChat-CP68IL8Q.js} +2 -2
  43. package/dist/assets/{mobile-CsT4sJwC.js → mobile-BrlBrNfZ.js} +2 -2
  44. package/dist/assets/nl-DzUV-kwp.js +16 -0
  45. package/dist/assets/{patchFileDiff-DeaE08W0.js → patchFileDiff-pqRSHLHI.js} +2 -2
  46. package/dist/assets/pl-Bb-cb7k7.js +16 -0
  47. package/dist/assets/pt-BR-CyIWrTcE.js +16 -0
  48. package/dist/assets/renderElectronMiniChatApp-DKIilR7N.js +2 -0
  49. package/dist/assets/renderMobileApp-B0z6-x58.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +52 -0
  51. package/dist/assets/{scheduledTasksApi-BZCNJ588.js → scheduledTasksApi-BuzWT445.js} +1 -1
  52. package/dist/assets/{shikiHighlight-BSUEa3yF.js → shikiHighlight-BWGrY5YU.js} +1 -1
  53. package/dist/assets/{textMateThemeFromAppTheme-CsATFZIV.js → textMateThemeFromAppTheme-BSUFChBY.js} +1 -1
  54. package/dist/assets/tr-DXEDSoYO.js +7 -0
  55. package/dist/assets/uk-C8hN--q_.js +16 -0
  56. package/dist/assets/useAppFontEffects-Dsl_sLrj.js +7366 -0
  57. package/dist/assets/useInlineCommentController-d5vntsQ_.js +2 -0
  58. package/dist/assets/{useRootScrollLock-Cp1eFoM2.js → useRootScrollLock-2rd5Y6gR.js} +2 -2
  59. package/dist/assets/{vendor-base-ui-CsXYnR5c.js → vendor-base-ui-DnNniUWp.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-language-data-BwwommM0.js → vendor-codemirror-language-data-B1EetJur.js} +2 -2
  61. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
  62. package/dist/assets/{vendor-tanstack-react-virtual-ClYN8CzB.js → vendor-tanstack-react-virtual--0sBrLRh.js} +1 -1
  63. package/dist/assets/{vendor-tanstack-virtual-core-BewVQryB.js → vendor-tanstack-virtual-core-BoA4iGMw.js} +1 -1
  64. package/dist/assets/{vendor-zod-BSoePkpP.js → vendor-zod-CxRSdNoV.js} +4 -4
  65. package/dist/assets/{web-components-D3Yjr4Zx.js → web-components-ngpHPEDU.js} +1 -1
  66. package/dist/assets/zh-CN-CtzXdjMZ.js +16 -0
  67. package/dist/assets/zh-TW-Ds0CADSz.js +16 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +5 -5
  70. package/dist/mobile.html +5 -5
  71. package/package.json +5 -5
  72. package/server/index.js +82 -4
  73. package/server/lib/agent-tool/DOCUMENTATION.md +8 -1
  74. package/server/lib/agent-tool/runtime.js +13 -4
  75. package/server/lib/agent-tool/runtime.test.js +15 -0
  76. package/server/lib/context-obligatory/DOCUMENTATION.md +10 -7
  77. package/server/lib/context-obligatory/runtime.js +2 -1
  78. package/server/lib/context-obligatory/runtime.test.js +76 -30
  79. package/server/lib/dictation/DOCUMENTATION.md +4 -1
  80. package/server/lib/dictation/openai-compatible-session.js +7 -0
  81. package/server/lib/enterprise-mode.d.ts +30 -0
  82. package/server/lib/enterprise-mode.js +253 -0
  83. package/server/lib/enterprise-mode.test.js +247 -0
  84. package/server/lib/event-stream/translate-v2.js +6 -0
  85. package/server/lib/event-stream/translate-v2.test.js +6 -0
  86. package/server/lib/git/DOCUMENTATION.md +2 -1
  87. package/server/lib/git/routes.js +44 -1
  88. package/server/lib/git/routes.test.js +98 -1
  89. package/server/lib/git/service.js +146 -11
  90. package/server/lib/git/service.test.js +195 -0
  91. package/server/lib/github/routes.js +9 -19
  92. package/server/lib/github/routes.test.js +112 -0
  93. package/server/lib/guests/DOCUMENTATION.md +4 -2
  94. package/server/lib/guests/background.test.js +1 -1
  95. package/server/lib/guests/catalog.js +56 -2
  96. package/server/lib/guests/catalog.test.js +24 -1
  97. package/server/lib/guests/clone-network.test.js +52 -0
  98. package/server/lib/guests/clone.js +30 -4
  99. package/server/lib/guests/enterprise.js +68 -0
  100. package/server/lib/guests/enterprise.test.js +106 -0
  101. package/server/lib/guests/grant-scope.js +8 -2
  102. package/server/lib/guests/grant-scope.test.js +9 -0
  103. package/server/lib/guests/html-styles.js +16 -2
  104. package/server/lib/guests/html-styles.test.js +53 -4
  105. package/server/lib/guests/install.js +10 -0
  106. package/server/lib/guests/persist.js +1 -0
  107. package/server/lib/guests/routes.js +40 -5
  108. package/server/lib/guests/updates.js +9 -2
  109. package/server/lib/notifications/DOCUMENTATION.md +1 -1
  110. package/server/lib/notifications/runtime.js +22 -8
  111. package/server/lib/notifications/trigger-runtime.test.js +45 -0
  112. package/server/lib/openchamber-sessions/session-metadata-store.js +27 -0
  113. package/server/lib/openchamber-sessions/session-metadata-store.test.js +18 -0
  114. package/server/lib/opencode/DOCUMENTATION.md +13 -9
  115. package/server/lib/opencode/auth-state-runtime.js +2 -2
  116. package/server/lib/opencode/config-paths.test.js +1 -0
  117. package/server/lib/opencode/env-runtime.js +26 -3
  118. package/server/lib/opencode/env-runtime.test.js +57 -0
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  120. package/server/lib/opencode/hmr-state-runtime.js +4 -3
  121. package/server/lib/opencode/lifecycle.js +10 -5
  122. package/server/lib/opencode/lifecycle.test.js +6 -2
  123. package/server/lib/opencode/managed-config-file.js +2 -1
  124. package/server/lib/opencode/managed-config-file.test.js +18 -0
  125. package/server/lib/opencode/npm-registry-config.d.ts +1 -0
  126. package/server/lib/opencode/npm-registry-config.js +123 -0
  127. package/server/lib/opencode/npm-registry-config.test.js +167 -0
  128. package/server/lib/opencode/npm-registry.js +5 -6
  129. package/server/lib/opencode/npm-registry.test.js +30 -0
  130. package/server/lib/opencode/openchamber-routes.js +8 -0
  131. package/server/lib/opencode/project-icon-routes.js +2 -2
  132. package/server/lib/opencode/project-icon-routes.test.js +44 -0
  133. package/server/lib/opencode/provider-source-route.test.js +32 -0
  134. package/server/lib/opencode/routes.js +17 -2
  135. package/server/lib/opencode/settings-helpers.js +26 -3
  136. package/server/lib/opencode/settings-helpers.test.js +12 -5
  137. package/server/lib/opencode/settings-registry.json +35 -1
  138. package/server/lib/opencode/settings-runtime.js +1 -0
  139. package/server/lib/opencode/shutdown-runtime.js +2 -0
  140. package/server/lib/opencode/static-routes-runtime.js +9 -1
  141. package/server/lib/opencode/static-routes-runtime.test.js +58 -1
  142. package/server/lib/package-manager.js +4 -1
  143. package/server/lib/package-manager.test.js +24 -0
  144. package/server/lib/permission-auto-accept/DOCUMENTATION.md +23 -15
  145. package/server/lib/permission-auto-accept/modes.js +26 -0
  146. package/server/lib/permission-auto-accept/runtime.js +146 -40
  147. package/server/lib/permission-auto-accept/runtime.test.js +93 -9
  148. package/server/lib/quota/DOCUMENTATION.md +6 -0
  149. package/server/lib/quota/providers/zhipuai-coding-plan.js +74 -30
  150. package/server/lib/quota/providers/zhipuai-coding-plan.test.js +124 -0
  151. package/server/lib/relay/DOCUMENTATION.md +1 -1
  152. package/server/lib/relay/service.js +32 -12
  153. package/server/lib/relay/service.test.js +30 -0
  154. package/server/lib/routing/DOCUMENTATION.md +150 -41
  155. package/server/lib/routing/classifier.js +156 -0
  156. package/server/lib/routing/defaults.js +27 -0
  157. package/server/lib/routing/jev.js +5 -17
  158. package/server/lib/routing/routes.http.test.js +9 -0
  159. package/server/lib/routing/routes.js +27 -1
  160. package/server/lib/routing/runtime.js +199 -33
  161. package/server/lib/routing/runtime.test.js +299 -15
  162. package/server/lib/routing/store.js +57 -0
  163. package/server/lib/routing/store.test.js +37 -0
  164. package/server/lib/session-assist/DOCUMENTATION.md +17 -7
  165. package/server/lib/session-assist/context.js +42 -2
  166. package/server/lib/session-assist/context.test.js +38 -1
  167. package/server/lib/session-assist/runtime.js +57 -13
  168. package/server/lib/session-assist/runtime.test.js +45 -0
  169. package/server/lib/session-goal/DOCUMENTATION.md +47 -22
  170. package/server/lib/session-goal/audit.js +112 -0
  171. package/server/lib/session-goal/audit.test.js +58 -0
  172. package/server/lib/session-goal/runtime.js +113 -134
  173. package/server/lib/session-goal/runtime.test.js +146 -13
  174. package/server/lib/session-lineage.js +52 -0
  175. package/server/lib/session-lineage.test.js +45 -0
  176. package/server/lib/session-work/DOCUMENTATION.md +108 -0
  177. package/server/lib/session-work/questions.js +126 -0
  178. package/server/lib/session-work/runtime.js +278 -0
  179. package/server/lib/session-work/runtime.test.js +255 -0
  180. package/server/lib/session-work/state.js +48 -0
  181. package/server/lib/session-work/state.test.js +34 -0
  182. package/server/lib/small-model/DOCUMENTATION.md +14 -7
  183. package/server/lib/small-model/client.js +7 -4
  184. package/server/lib/small-model/index.js +11 -21
  185. package/server/lib/small-model/index.test.js +13 -26
  186. package/server/lib/spaces/DOCUMENTATION.md +79 -25
  187. package/server/lib/spaces/gatekeeper-channel.js +63 -11
  188. package/server/lib/spaces/gatekeeper-channel.test.js +34 -4
  189. package/server/lib/spaces/gatekeeper-program.cjs +64 -13
  190. package/server/lib/spaces/gatekeeper-program.test.js +115 -3
  191. package/server/lib/spaces/host.js +58 -13
  192. package/server/lib/spaces/host.test.js +34 -1
  193. package/server/lib/spaces/idle-stop.js +98 -0
  194. package/server/lib/spaces/idle-stop.test.js +130 -0
  195. package/server/lib/spaces/journey.js +427 -17
  196. package/server/lib/spaces/journey.test.js +592 -5
  197. package/server/lib/spaces/layout.js +27 -6
  198. package/server/lib/spaces/manager.test.js +1 -1
  199. package/server/lib/spaces/places/contract-suite.js +4 -2
  200. package/server/lib/spaces/places/docker-live-support.js +27 -4
  201. package/server/lib/spaces/places/docker.js +32 -5
  202. package/server/lib/spaces/places/docker.test.js +38 -8
  203. package/server/lib/spaces/places/escape-suite.js +32 -0
  204. package/server/lib/spaces/places/fake-docker.js +3 -1
  205. package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
  206. package/server/lib/spaces/places/memory-place.js +3 -3
  207. package/server/lib/spaces/places/sessions.docker.live.test.js +4 -2
  208. package/server/lib/spaces/routes.js +49 -1
  209. package/server/lib/spaces/routes.test.js +31 -3
  210. package/server/lib/spaces/space-opencode.js +52 -0
  211. package/server/lib/spaces/space-opencode.test.js +41 -0
  212. package/server/lib/spaces/space-records.js +90 -2
  213. package/server/lib/spaces/space-records.test.js +58 -1
  214. package/server/lib/spaces/space-server.js +13 -1
  215. package/server/lib/spaces/space-server.test.js +13 -0
  216. package/server/lib/spaces/space-setup.js +173 -0
  217. package/server/lib/spaces/space-setup.test.js +174 -0
  218. package/server/lib/tts/DOCUMENTATION.md +3 -0
  219. package/server/lib/tts/base-url.js +8 -0
  220. package/server/lib/tts/routes.js +13 -1
  221. package/server/lib/tts/routes.test.js +26 -0
  222. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  223. package/server/lib/tunnels/routes.js +14 -0
  224. package/server/lib/tunnels/routes.test.js +26 -0
  225. package/server/lib/walkthrough/index.js +11 -7
  226. package/server/lib/walkthrough/jobs.test.js +8 -0
  227. package/server/lib/walkthrough/languages.js +1 -0
  228. package/server/lib/walkthrough/routes.js +7 -1
  229. package/dist/assets/FilesView-0Ie20mEk.js +0 -17
  230. package/dist/assets/LinearIssuesView-CSl2MUfA.js +0 -1
  231. package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +0 -12
  232. package/dist/assets/OnboardingScreen-CIdXJpfc.js +0 -1
  233. package/dist/assets/PlanView-DEIi3Q7M.js +0 -5
  234. package/dist/assets/PluginPane-BEPUWVho.js +0 -3
  235. package/dist/assets/SettingsView-CiNh-RbW.js +0 -30
  236. package/dist/assets/WalkthroughView-6oE-MuDL.js +0 -4
  237. package/dist/assets/de-CgAJ51z7.js +0 -10
  238. package/dist/assets/es-zGi_ravM.js +0 -16
  239. package/dist/assets/fr-CPfogrWx.js +0 -14
  240. package/dist/assets/index-CHfphYL3.js +0 -41
  241. package/dist/assets/index-DvMJ3w6V.css +0 -1
  242. package/dist/assets/ja-DMk6wd-U.js +0 -16
  243. package/dist/assets/ko-BFpzJ8jc.js +0 -16
  244. package/dist/assets/main-anyZFMIs.js +0 -896
  245. package/dist/assets/markdownCore-CmM47cAE.js +0 -7
  246. package/dist/assets/pl-VdRPcZrB.js +0 -16
  247. package/dist/assets/pt-BR-BRys_lOW.js +0 -16
  248. package/dist/assets/renderElectronMiniChatApp-C5677jy0.js +0 -2
  249. package/dist/assets/renderMobileApp-D4dBBAqQ.js +0 -25
  250. package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +0 -27
  251. package/dist/assets/tr-CA9ckNnm.js +0 -7
  252. package/dist/assets/uk-byjR-y8D.js +0 -16
  253. package/dist/assets/useAppFontEffects-BWQZ5DeI.js +0 -7341
  254. package/dist/assets/useInlineCommentController-DlFyVfBu.js +0 -2
  255. package/dist/assets/vendor-opencode-client-DYdsLbCM.js +0 -12
  256. package/dist/assets/zh-CN-DRabgxdG.js +0 -16
  257. package/dist/assets/zh-TW-rbY5c9UK.js +0 -16
@@ -0,0 +1,255 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import { mergeMetadataPatch } from '../openchamber-sessions/session-metadata-store.js';
3
+ import { decideAssist, decideOpen } from './questions.js';
4
+ import { createSessionWorkRuntime } from './runtime.js';
5
+ import { createSessionLineage } from '../session-lineage.js';
6
+
7
+ const ENDPOINT = { url: 'https://jev.test', model: 'jev', headers: {} };
8
+
9
+ // v2 serves a session's messages newest first.
10
+ const settledPair = [
11
+ { id: 'msg_a1', type: 'assistant', content: [{ type: 'text', text: 'Here is how it works.' }], finish: 'stop', time: { completed: 2 } },
12
+ { id: 'msg_u1', type: 'user', text: 'How does the sidebar work?', time: { created: 1 } },
13
+ ];
14
+ const answeredTurn = [
15
+ { id: 'msg_idle', type: 'idle', outcome: 'succeeded' },
16
+ { id: 'msg_a2', type: 'assistant', content: [{ type: 'text', text: 'Done, try it.' }], finish: 'stop', time: { completed: 4 } },
17
+ { id: 'msg_u2', type: 'user', text: 'Implement it', time: { created: 3 } },
18
+ ...settledPair,
19
+ ];
20
+
21
+ const stubOpenCode = ({ session = {}, records = answeredTurn } = {}) => {
22
+ const fetchMock = vi.fn(async (input) => {
23
+ const url = new URL(String(input));
24
+ let body;
25
+ if (url.pathname === '/api/session/ses_1') body = { data: { id: 'ses_1', ...session } };
26
+ else if (url.pathname === '/api/session/ses_1/message') body = { data: records, cursor: {} };
27
+ else throw new Error(`unexpected ${url.pathname}`);
28
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
29
+ });
30
+ vi.stubGlobal('fetch', fetchMock);
31
+ return fetchMock;
32
+ };
33
+
34
+ const makeRuntime = ({ metadata = {}, answers = {}, askError = null, settings = {}, endpoint = ENDPOINT, lineage = null } = {}) => {
35
+ const records = new Map([['ses_1', metadata]]);
36
+ const updateMetadata = vi.fn(async (id, decide) => {
37
+ const current = records.get(id) ?? {};
38
+ const patch = decide(current);
39
+ if (!patch) return { metadata: current, changed: false };
40
+ const merged = mergeMetadataPatch(current, patch);
41
+ records.set(id, merged);
42
+ return { metadata: merged, changed: true };
43
+ });
44
+ const jev = { ask: vi.fn(async () => { if (askError) throw askError; return { answers, ms: 5 }; }) };
45
+ let time = 100;
46
+ const runtime = createSessionWorkRuntime({
47
+ buildOpenCodeUrl: (fetchPath) => `http://opencode.test${fetchPath}`,
48
+ getOpenCodeAuthHeaders: () => ({}),
49
+ getSettings: () => ({ enabled: true, autoOpen: true, ...settings }),
50
+ classifierEndpoint: async () => endpoint,
51
+ jev,
52
+ readMetadata: async (id) => records.get(id) ?? {},
53
+ updateMetadata,
54
+ chatRoots: ['/home/me/.config/openchamber/chats'],
55
+ lineage,
56
+ now: () => time++,
57
+ });
58
+ return { runtime, jev, updateMetadata, records };
59
+ };
60
+
61
+ const sent = (id = 'msg_new', text = 'Now fix the header') => ({
62
+ type: 'message.updated',
63
+ properties: { sessionID: 'ses_1', info: { id, role: 'user', text, time: { created: 50 } } },
64
+ });
65
+
66
+ const settle = async (check) => {
67
+ for (let i = 0; i < 50 && !check(); i += 1) await new Promise((resolve) => setTimeout(resolve, 5));
68
+ };
69
+
70
+ afterEach(() => {
71
+ vi.unstubAllGlobals();
72
+ vi.restoreAllMocks();
73
+ });
74
+
75
+ describe('session work decisions', () => {
76
+ it('opens when either measured question passes its threshold', () => {
77
+ expect(decideOpen({ change: { noul: 0.86 } })).toBe(true);
78
+ expect(decideOpen({ change: { noul: 0.84 }, toward_change: { noul: 0.91 } })).toBe(true);
79
+ expect(decideOpen({ change: { noul: 0.84 }, toward_change: { noul: 0.89 } })).toBe(false);
80
+ expect(decideOpen({})).toBe(false);
81
+ });
82
+
83
+ it('keeps an assist field Jev did not answer, and drops only a clear no', () => {
84
+ expect(decideAssist({})).toEqual({ recap: true, suggestion: true });
85
+ expect(decideAssist({ recap: { noul: 0.2 }, next_step: { noul: 0.1 } })).toEqual({ recap: false, suggestion: false });
86
+ expect(decideAssist({ recap: { noul: 0.6 }, next_step: { noul: 0.7 } })).toEqual({ recap: true, suggestion: true });
87
+ });
88
+ });
89
+
90
+ describe('session work runtime: a message was sent', () => {
91
+ it('asks Jev on the new message with the settled turns as history, and opens the session', async () => {
92
+ stubOpenCode({ records: [{ id: 'msg_new', type: 'user', text: 'Now fix the header' }, ...settledPair] });
93
+ const { runtime, jev, records } = makeRuntime({ answers: { change: { noul: 0.95 }, toward_change: { noul: 0.9 } } });
94
+
95
+ runtime.processPayload(sent());
96
+ await settle(() => records.get('ses_1').openchamber);
97
+
98
+ const [request] = jev.ask.mock.calls[0];
99
+ expect(request.state.request).toBe('Now fix the header');
100
+ expect(request.state.history.map((entry) => entry.role)).toEqual(['user', 'assistant']);
101
+ expect(Object.keys(request.questions)).toEqual(['change', 'toward_change']);
102
+ expect(records.get('ses_1')).toMatchObject({ openchamber: { work: { state: 'open', openedBy: 'jev' } } });
103
+ });
104
+
105
+ it('does not ask again for a session already in work, or for the same message twice', async () => {
106
+ stubOpenCode();
107
+ const open = makeRuntime({ metadata: { openchamber: { work: { state: 'open' } } } });
108
+ open.runtime.processPayload(sent());
109
+ await new Promise((resolve) => setTimeout(resolve, 30));
110
+ expect(open.jev.ask).not.toHaveBeenCalled();
111
+
112
+ const fresh = makeRuntime({ answers: { change: { noul: 0.1 } } });
113
+ fresh.runtime.processPayload(sent('msg_x'));
114
+ fresh.runtime.processPayload(sent('msg_x'));
115
+ await settle(() => fresh.jev.ask.mock.calls.length > 0);
116
+ await new Promise((resolve) => setTimeout(resolve, 20));
117
+ expect(fresh.jev.ask).toHaveBeenCalledTimes(1);
118
+ expect(fresh.updateMetadata).not.toHaveBeenCalled();
119
+ });
120
+
121
+ it('skips a known subsession without reading it, and learns one it had to read', async () => {
122
+ const lineage = createSessionLineage();
123
+ lineage.remember('ses_1', 'ses_parent');
124
+ const fetchMock = stubOpenCode();
125
+ const known = makeRuntime({ lineage, answers: { change: { noul: 1 } } });
126
+ known.runtime.processPayload(sent());
127
+ expect(await known.runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: true, suggestion: true } })).toBeNull();
128
+ await new Promise((resolve) => setTimeout(resolve, 20));
129
+ expect(fetchMock).not.toHaveBeenCalled();
130
+ expect(known.jev.ask).not.toHaveBeenCalled();
131
+ vi.unstubAllGlobals();
132
+
133
+ const learning = createSessionLineage();
134
+ stubOpenCode({ session: { parentID: 'ses_parent' } });
135
+ const unknown = makeRuntime({ lineage: learning });
136
+ await unknown.runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: true, suggestion: true } });
137
+ expect(learning.isChild('ses_1')).toBe(true);
138
+ });
139
+
140
+ it('asks nothing with auto-open off, without Jev, or in a child, review, or chat session', async () => {
141
+ for (const setup of [
142
+ { runtime: { settings: { autoOpen: false } } },
143
+ { runtime: { endpoint: null } },
144
+ { session: { parentID: 'ses_parent' } },
145
+ { session: { metadata: { openchamber: { kind: 'review', originalSessionID: 'ses_0' } } } },
146
+ { session: { location: { directory: '/home/me/.config/openchamber/chats/2026-09-27/hello' } } },
147
+ ]) {
148
+ stubOpenCode({ session: setup.session });
149
+ const { runtime, jev } = makeRuntime({ answers: { change: { noul: 1 } }, ...setup.runtime });
150
+ runtime.processPayload(sent());
151
+ await new Promise((resolve) => setTimeout(resolve, 30));
152
+ expect(jev.ask).not.toHaveBeenCalled();
153
+ vi.unstubAllGlobals();
154
+ }
155
+ });
156
+ });
157
+
158
+ describe('session work runtime: a turn ended', () => {
159
+ it('asks the open questions and the assist questions in one call, and opens on the answer', async () => {
160
+ stubOpenCode();
161
+ const { runtime, jev, records } = makeRuntime({
162
+ answers: { change: { noul: 0.97 }, recap: { noul: 0.9 }, next_step: { noul: 0.1 } },
163
+ });
164
+
165
+ const gate = await runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: true, suggestion: true } });
166
+
167
+ expect(jev.ask).toHaveBeenCalledTimes(1);
168
+ expect(Object.keys(jev.ask.mock.calls[0][0].questions).sort()).toEqual(['change', 'next_step', 'recap', 'toward_change']);
169
+ expect(jev.ask.mock.calls[0][0].state).toMatchObject({ request: 'Implement it', answer: 'Done, try it.' });
170
+ expect(gate).toEqual({ recap: true, suggestion: false });
171
+ expect(records.get('ses_1')).toMatchObject({ openchamber: { work: { state: 'open' } } });
172
+ });
173
+
174
+ it('asks only whether the work looks done in a session already in work, and a new turn retires the hint', async () => {
175
+ stubOpenCode();
176
+ const { runtime, jev, records, updateMetadata } = makeRuntime({
177
+ metadata: { openchamber: { work: { state: 'open', openedAt: 1 } } },
178
+ answers: { wrap_up: { noul: 0.93 } },
179
+ });
180
+
181
+ const gate = await runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: false, suggestion: false } });
182
+
183
+ expect(Object.keys(jev.ask.mock.calls[0][0].questions)).toEqual(['wrap_up']);
184
+ expect(gate).toBeNull();
185
+ expect(records.get('ses_1').openchamber.work.suggestDoneAt).toBeTypeOf('number');
186
+
187
+ const busy = { type: 'session.status', properties: { sessionID: 'ses_1', status: { type: 'busy' } } };
188
+ runtime.processPayload(busy);
189
+ runtime.processPayload(busy);
190
+ await settle(() => records.get('ses_1').openchamber.work.suggestDoneAt === undefined);
191
+ expect(records.get('ses_1').openchamber.work).not.toHaveProperty('suggestDoneAt');
192
+ // One write for the hint, one to retire it: the second busy found nothing to retire.
193
+ expect(updateMetadata).toHaveBeenCalledTimes(2);
194
+ });
195
+
196
+ it('drops a late done answer once the next turn started', async () => {
197
+ stubOpenCode();
198
+ const { runtime, jev, records } = makeRuntime({
199
+ metadata: { openchamber: { work: { state: 'open', openedAt: 1 } } },
200
+ });
201
+ let answer;
202
+ jev.ask.mockImplementation(() => new Promise((resolve) => { answer = resolve; }));
203
+
204
+ const busy = { type: 'session.status', properties: { sessionID: 'ses_1', status: { type: 'busy' } } };
205
+ // The ordinary lifecycle, several turns in a row: every turn starts with a
206
+ // busy, ends, gets checked, and the user moves on before Jev answers.
207
+ for (let turn = 0; turn < 3; turn += 1) {
208
+ answer = undefined;
209
+ runtime.processPayload(busy);
210
+ const pending = runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: false, suggestion: false } });
211
+ await settle(() => answer !== undefined);
212
+ runtime.processPayload(busy);
213
+ answer({ answers: { wrap_up: { noul: 0.99 } }, ms: 5 });
214
+ await pending;
215
+ expect(records.get('ses_1').openchamber.work).not.toHaveProperty('suggestDoneAt');
216
+ }
217
+
218
+ // A check nobody overtook still writes its hint.
219
+ answer = undefined;
220
+ const current = runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: false, suggestion: false } });
221
+ await settle(() => answer !== undefined);
222
+ answer({ answers: { wrap_up: { noul: 0.99 } }, ms: 5 });
223
+ await current;
224
+ expect(records.get('ses_1').openchamber.work.suggestDoneAt).toBeTypeOf('number');
225
+ });
226
+
227
+ it('never closes: a closing turn in a session in work only hints', async () => {
228
+ stubOpenCode();
229
+ const { runtime, records } = makeRuntime({
230
+ metadata: { openchamber: { work: { state: 'open', openedAt: 1 } } },
231
+ answers: { wrap_up: { noul: 0.99 }, change: { noul: 0 } },
232
+ });
233
+ await runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: false, suggestion: false } });
234
+ expect(records.get('ses_1').openchamber.work.state).toBe('open');
235
+ });
236
+
237
+ it('answers unknown on a Jev failure and changes nothing', async () => {
238
+ stubOpenCode();
239
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
240
+ const { runtime, updateMetadata } = makeRuntime({ askError: new Error('Jev timed out after 4000ms') });
241
+
242
+ const gate = await runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: true, suggestion: true } });
243
+
244
+ expect(gate).toBeNull();
245
+ expect(updateMetadata).not.toHaveBeenCalled();
246
+ });
247
+
248
+ it('makes no call when the feature and both assist fields are off', async () => {
249
+ const fetchMock = stubOpenCode();
250
+ const { runtime, jev } = makeRuntime({ settings: { enabled: false } });
251
+ expect(await runtime.evaluateTurnEnd({ sessionId: 'ses_1', directory: '/repo', assist: { recap: false, suggestion: false } })).toBeNull();
252
+ expect(jev.ask).not.toHaveBeenCalled();
253
+ expect(fetchMock).not.toHaveBeenCalled();
254
+ });
255
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `metadata.openchamber.work`: whether a session is in work and what Jev
3
+ * currently suggests about it. Every function returns a JSON merge patch for
4
+ * the session metadata store, or null when nothing changes, so the store can
5
+ * decide against the record as it is at write time.
6
+ *
7
+ * The rule the patches keep: Jev only ever opens, the user alone closes. Jev
8
+ * may reopen a session the user closed, but only for a request sent after the
9
+ * user closed it.
10
+ */
11
+ import { z } from 'zod';
12
+
13
+ const workSchema = z.object({
14
+ state: z.enum(['open', 'done']),
15
+ openedAt: z.number().optional(),
16
+ openedBy: z.enum(['jev', 'user']).optional(),
17
+ doneAt: z.number().optional(),
18
+ suggestDoneAt: z.number().optional(),
19
+ });
20
+
21
+ const metadataSchema = z.object({ openchamber: z.object({ work: workSchema }) });
22
+
23
+ /** The session's work record, or null when it has none (or a malformed one). */
24
+ export const readWork = (metadata) => metadataSchema.safeParse(metadata).data?.openchamber.work ?? null;
25
+
26
+ const patchOf = (work) => ({ openchamber: { work } });
27
+
28
+ /** Jev saw a request that starts work, sent at `requestAt`. */
29
+ export const openByJevPatch = (metadata, { requestAt, now }) => {
30
+ const work = readWork(metadata);
31
+ if (work?.state === 'open') return null;
32
+ // Closed after this request was sent: the user's decision stands.
33
+ if (work?.state === 'done' && Number.isFinite(requestAt) && (work.doneAt ?? 0) >= requestAt) return null;
34
+ return patchOf({ state: 'open', openedAt: now, openedBy: 'jev', doneAt: null, suggestDoneAt: null });
35
+ };
36
+
37
+ /** The turn that just ended looks like the end of the work. */
38
+ export const suggestDonePatch = (metadata, { now }) => {
39
+ if (readWork(metadata)?.state !== 'open') return null;
40
+ return patchOf({ suggestDoneAt: now });
41
+ };
42
+
43
+ /** A new turn started: whatever Jev concluded about the last one no longer holds. */
44
+ export const clearSuggestionPatch = (metadata) => {
45
+ const work = readWork(metadata);
46
+ if (!work || work.suggestDoneAt === undefined) return null;
47
+ return patchOf({ suggestDoneAt: null });
48
+ };
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { clearSuggestionPatch, openByJevPatch, readWork, suggestDonePatch } from './state.js';
3
+
4
+ const withWork = (work) => ({ openchamber: { goal: { id: 'g' }, work } });
5
+
6
+ describe('session work state', () => {
7
+ it('reads a work record, and a missing or malformed one as none', () => {
8
+ expect(readWork(withWork({ state: 'open', openedAt: 1 }))).toMatchObject({ state: 'open' });
9
+ expect(readWork({})).toBeNull();
10
+ expect(readWork(withWork({ state: 'maybe' }))).toBeNull();
11
+ });
12
+
13
+ it('opens a session that is not in work and records that Jev did it', () => {
14
+ expect(openByJevPatch({}, { requestAt: 5, now: 10 })).toEqual({
15
+ openchamber: { work: { state: 'open', openedAt: 10, openedBy: 'jev', doneAt: null, suggestDoneAt: null } },
16
+ });
17
+ expect(openByJevPatch(withWork({ state: 'open', openedAt: 1 }), { requestAt: 5, now: 10 })).toBeNull();
18
+ });
19
+
20
+ it('reopens a closed session only for a request sent after the user closed it', () => {
21
+ const closedAt7 = withWork({ state: 'done', doneAt: 7 });
22
+ expect(openByJevPatch(closedAt7, { requestAt: 5, now: 10 })).toBeNull();
23
+ expect(openByJevPatch(closedAt7, { requestAt: 7, now: 10 })).toBeNull();
24
+ expect(openByJevPatch(closedAt7, { requestAt: 8, now: 10 })).toMatchObject({ openchamber: { work: { state: 'open' } } });
25
+ });
26
+
27
+ it('hints done only on a session in work, and retires the hint once', () => {
28
+ expect(suggestDonePatch(withWork({ state: 'open' }), { now: 3 })).toEqual({ openchamber: { work: { suggestDoneAt: 3 } } });
29
+ expect(suggestDonePatch(withWork({ state: 'done' }), { now: 3 })).toBeNull();
30
+ expect(suggestDonePatch({}, { now: 3 })).toBeNull();
31
+ expect(clearSuggestionPatch(withWork({ state: 'open', suggestDoneAt: 3 }))).toEqual({ openchamber: { work: { suggestDoneAt: null } } });
32
+ expect(clearSuggestionPatch(withWork({ state: 'open' }))).toBeNull();
33
+ });
34
+ });
@@ -41,10 +41,11 @@ login `generateSmallModelText` throws `404`. What happens next is per feature:
41
41
  model with the session as context and does not touch its history. Verified
42
42
  on OpenCode 2.0.2: the reply comes back and the message count stays at zero.
43
43
  - Session renaming, the session goal and the walkthrough do NOT fall back —
44
- feeding a whole session into a model to write a title or audit a goal is the
44
+ feeding a whole session into a model to write a title or check a goal is the
45
45
  wrong cost. Their entry points read `available` from `GET /api/small-model`
46
46
  (`packages/ui/src/stores/useSmallModelStore.ts`) and show a disabled control
47
- with the reason; the walkthrough uses its own readiness (`no-model`).
47
+ with the reason; the walkthrough uses its own readiness (`no-model`). A goal
48
+ is also allowed when Jev checks it instead (`../session-goal`).
48
49
  - Session assist is server-side and simply does nothing when
49
50
  `describeSmallModel` answers null.
50
51
  - Notes summarization and spoken summaries keep the original text and silence
@@ -58,7 +59,9 @@ Four things are decided here, in order:
58
59
  2. OpenChamber's settings override (Settings → Sessions → Small Model): when
59
60
  `smallModelUseDefault` is `false`, `smallModelOverride` wins —
60
61
  `source: 'settings'`.
61
- 3. The small model of the session's provider (`preferredProviderID`) —
62
+ 3. The small model of the caller's provider (`preferredProviderID`: the
63
+ session's, or the composer's for commit messages, PR descriptions, spoken
64
+ summaries, the diff walkthrough and extensions) —
62
65
  `source: 'session-provider-small'` — found by `pickSmallModelInProvider`:
63
66
  the newest enabled, active, text-in text-out model of the first family in
64
67
  `SMALL_MODEL_FAMILY_PRIORITY` (`gpt-luna`, `gemini-flash-lite`,
@@ -75,12 +78,16 @@ Four things are decided here, in order:
75
78
  and finds none then takes the session's own model — `source:
76
79
  'session-model'`: costlier than a small model elsewhere, but never another
77
80
  provider's subscription.
78
- 4. The small model of any provider OpenCode can call, same family order,
79
- newest first — `source: 'small'`. Where callers without a session (commit
80
- messages, spoken summaries) usually land.
81
- 5. Otherwise `GET /api/model/default` — `source: 'default'`. This is
81
+ 4. Otherwise `GET /api/model/default` — `source: 'default'`. This is
82
82
  OpenCode's default chat model, not a small one; it is the last resort.
83
83
 
84
+ There is deliberately no step that takes a small model from whichever other
85
+ provider is connected. Until 2026-09 one existed (`source: 'small'`, after
86
+ step 3); it sent diffs and replies to a provider the user never chose for
87
+ them, and the walkthrough and extensions reached it without even passing
88
+ their provider. Content goes only to the provider the user works with, the
89
+ model they picked, or the default they configured.
90
+
84
91
  Claude Code (`claude-code`, from the opencode-claude plugin) is a provider
85
92
  like any other: its generate path runs a clean one-shot turn with no tools and
86
93
  no session, so `claude-code/haiku` (family `claude-haiku`) is picked in the
@@ -104,10 +104,13 @@ export async function getDefaultModelInfo(client) {
104
104
  }
105
105
 
106
106
  /**
107
- * The model entry for a `provider/model` reference. `modelID` and `id` are
108
- * both accepted because OpenCode reports the same model under both.
107
+ * The model entry for a `provider/model` reference. `id` is the catalog key a
108
+ * reference holds; `modelID` is the provider API name, shared by derived
109
+ * entries (`gpt-6-luna` and `gpt-6-luna-fast`), so an exact `id` match wins.
109
110
  */
110
111
  export function findModelInfo(models, providerID, modelID) {
111
- return models.find((model) => model?.providerID === providerID
112
- && (model.id === modelID || model.modelID === modelID)) ?? null;
112
+ const ofProvider = models.filter((model) => model?.providerID === providerID);
113
+ return ofProvider.find((model) => model.id === modelID)
114
+ ?? ofProvider.find((model) => model.modelID === modelID)
115
+ ?? null;
113
116
  }
@@ -144,14 +144,6 @@ export const familyOf = (model) => {
144
144
  */
145
145
  export const pickSmallModelInProvider = (models, providerID) => pickSmallModel(models, (model) => model.providerID === providerID);
146
146
 
147
- /**
148
- * The small model across every provider OpenCode can call: same family
149
- * order, newest release first within a family. What v1 did after the
150
- * session provider came up empty; for callers without a session (commit
151
- * messages, spoken summaries) it is the first place to look.
152
- */
153
- export const pickSmallModelAnywhere = (models) => pickSmallModel(models, () => true);
154
-
155
147
  const pickSmallModel = (models, accept) => {
156
148
  const candidates = models
157
149
  .filter((model) => model && accept(model)
@@ -172,15 +164,17 @@ const pickSmallModel = (models, accept) => {
172
164
  *
173
165
  * 1. An explicit request model.
174
166
  * 2. OpenChamber's settings override (Settings → Sessions → Small Model).
175
- * 3. The small model of the session's provider (family scan above) —
176
- * `session-provider-small`. A caller that must not leave that provider
177
- * then falls back to the session's own model (`session-model`): costlier
178
- * than a small model elsewhere, but never someone else's subscription.
179
- * 4. The small model of any provider OpenCode can call, newest first —
180
- * `small`.
181
- * 5. `GET /api/model/default`: OpenCode's default model — `default`. This is
167
+ * 3. The small model of the caller's provider — the session's, or the one
168
+ * in the composer (family scan above) — `session-provider-small`. A caller
169
+ * that must not leave that provider then takes its own model
170
+ * (`session-model`): costlier, but never someone else's subscription.
171
+ * 4. `GET /api/model/default`: OpenCode's default model — `default`. This is
182
172
  * the chat default, not a small model; OpenCode's own small-model chain is
183
- * not reachable over HTTP, which is why steps 3 and 4 live here.
173
+ * not reachable over HTTP, which is why step 3 lives here.
174
+ *
175
+ * There is no step that picks a small model from whichever other provider
176
+ * happens to be connected: the content (diffs, replies, session text) goes
177
+ * only where the user sent their own work or configured on purpose.
184
178
  */
185
179
  const resolveSmallModel = async ({ client, directory, model, preferredProviderID, preferredModelID, restrictToPreferredProvider }) => {
186
180
  const explicit = parseModelRef(model);
@@ -189,18 +183,14 @@ const resolveSmallModel = async ({ client, directory, model, preferredProviderID
189
183
  const fromSettings = parseModelRef(readSmallModelSettingsOverride());
190
184
  if (fromSettings) return { ...fromSettings, source: 'settings' };
191
185
 
192
- const models = await listModelInfos(client, directory);
193
186
  if (preferredProviderID) {
194
- const small = pickSmallModelInProvider(models, preferredProviderID);
187
+ const small = pickSmallModelInProvider(await listModelInfos(client, directory), preferredProviderID);
195
188
  if (small) return { ...small, source: 'session-provider-small' };
196
189
  }
197
190
  if (restrictToPreferredProvider && preferredProviderID && preferredModelID) {
198
191
  return { providerID: preferredProviderID, modelID: preferredModelID, source: 'session-model' };
199
192
  }
200
193
 
201
- const anywhere = pickSmallModelAnywhere(models);
202
- if (anywhere) return { ...anywhere, source: 'small' };
203
-
204
194
  const fallback = await getDefaultModelInfo(client);
205
195
  if (!fallback) return null;
206
196
  return { providerID: fallback.providerID, modelID: fallback.id, source: 'default' };
@@ -166,9 +166,8 @@ describe('generateSmallModelText', () => {
166
166
  it('sends the prompt to /api/generate on the resolved model', async () => {
167
167
  const result = await generateSmallModelText({ prompt: 'summarize this', directory: '/proj' });
168
168
 
169
- // The fixture's only model is a haiku: the family scan finds it before
170
- // OpenCode's default is even asked.
171
- expect(result).toMatchObject({ text: 'generated', providerID: 'anthropic', modelID: 'claude-haiku-4-5', source: 'small' });
169
+ // No provider to stay on and no Settings pick: OpenCode's default.
170
+ expect(result).toMatchObject({ text: 'generated', providerID: 'anthropic', modelID: 'claude-haiku-4-5', source: 'default' });
172
171
  expect(lastGenerate().body).toEqual({
173
172
  prompt: 'summarize this',
174
173
  model: { id: 'claude-haiku-4-5', providerID: 'anthropic' },
@@ -236,38 +235,26 @@ describe('generateSmallModelText', () => {
236
235
  expect(lastGenerate().body.model).toEqual({ id: 'claude-haiku-5', providerID: 'anthropic' });
237
236
  });
238
237
 
239
- it('without a session, takes the newest small model of any provider before the default', async () => {
240
- state.models = [
241
- MODEL({ id: 'claude-sonnet-5', modelID: 'claude-sonnet-5', family: 'claude-sonnet' }),
242
- MODEL({ id: 'claude-haiku-5', modelID: 'claude-haiku-5', family: 'claude-haiku', time: { released: 9 } }),
243
- MODEL({ id: 'gemini-3.5-flash', modelID: 'gemini-3.5-flash', providerID: 'google', family: 'gemini-flash', time: { released: 1 } }),
244
- MODEL({ id: 'gemini-3.6-flash', modelID: 'gemini-3.6-flash', providerID: 'google', family: 'gemini-flash', time: { released: 2 } }),
245
- ];
246
- state.defaultModel = state.models[0];
247
-
248
- const result = await generateSmallModelText({ prompt: 'hi', directory: '/proj' });
249
-
250
- // gemini-flash outranks claude-haiku in the family list, so the newest
251
- // gemini-flash wins even though haiku was released later.
252
- expect(result).toMatchObject({ providerID: 'google', modelID: 'gemini-3.6-flash', source: 'small' });
253
- });
254
-
255
- it('with a session but no restriction, still prefers the session provider, then any provider', async () => {
238
+ it('never takes a small model from another connected provider', async () => {
256
239
  state.models = [
257
240
  MODEL({ id: 'claude-sonnet-5', modelID: 'claude-sonnet-5', family: 'claude-sonnet' }),
258
241
  MODEL({ id: 'gemini-3.6-flash', modelID: 'gemini-3.6-flash', providerID: 'google', family: 'gemini-flash' }),
259
242
  ];
260
243
  state.defaultModel = state.models[0];
261
244
 
262
- const result = await generateSmallModelText({
245
+ // Anthropic has no small family here; the caller allows leaving it, yet
246
+ // the connected Google flash is not someone's pick for this content.
247
+ const withProvider = await generateSmallModelText({
263
248
  prompt: 'hi',
264
249
  directory: '/proj',
265
250
  preferredProviderID: 'anthropic',
266
251
  preferredModelID: 'claude-sonnet-5',
267
252
  });
253
+ expect(withProvider).toMatchObject({ providerID: 'anthropic', modelID: 'claude-sonnet-5', source: 'default' });
268
254
 
269
- // Anthropic has no small family here, and the caller allows switching.
270
- expect(result).toMatchObject({ providerID: 'google', modelID: 'gemini-3.6-flash', source: 'small' });
255
+ const withoutProvider = await generateSmallModelText({ prompt: 'hi', directory: '/proj' });
256
+ expect(withoutProvider).toMatchObject({ providerID: 'anthropic', modelID: 'claude-sonnet-5', source: 'default' });
257
+ expect(state.requests.some((entry) => entry.body?.model?.providerID === 'google')).toBe(false);
271
258
  });
272
259
 
273
260
  it('reads the family from the model id when the catalog has none (custom provider)', async () => {
@@ -291,9 +278,9 @@ describe('generateSmallModelText', () => {
291
278
  it('picks Claude Code haiku as the small model like any other provider', async () => {
292
279
  state.models = [MODEL({ id: 'haiku', modelID: 'haiku', providerID: 'claude-code', family: 'claude-haiku' })];
293
280
 
294
- const result = await generateSmallModelText({ prompt: 'hi', directory: '/proj' });
281
+ const result = await generateSmallModelText({ prompt: 'hi', directory: '/proj', preferredProviderID: 'claude-code' });
295
282
 
296
- expect(result).toMatchObject({ providerID: 'claude-code', modelID: 'haiku', source: 'small' });
283
+ expect(result).toMatchObject({ providerID: 'claude-code', modelID: 'haiku', source: 'session-provider-small' });
297
284
  });
298
285
 
299
286
  it('ignores a disabled small model and falls back to the session model', async () => {
@@ -425,7 +412,7 @@ describe('describeSmallModel', () => {
425
412
  expect(described).toMatchObject({
426
413
  providerID: 'anthropic',
427
414
  modelID: 'claude-haiku-4-5',
428
- source: 'small',
415
+ source: 'default',
429
416
  inputCharBudget: 16_000,
430
417
  contextTokens: 8_000,
431
418
  contextKnown: true,