@openchamber/web 1.21.1 → 1.22.1

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 (175) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-BO_2OW4E.js} +1 -1
  2. package/dist/assets/DiffView-CNnDxRmO.js +4 -0
  3. package/dist/assets/DirtyBranchSwitchDialog-jADfXQnR.js +1 -0
  4. package/dist/assets/FilesView-8wdiG2mj.js +17 -0
  5. package/dist/assets/GitView-Cv2xH-S6.js +6 -0
  6. package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-DUiIpERC.js} +1 -1
  7. package/dist/assets/LinearIssuesView-CoZ7pQN5.js +1 -0
  8. package/dist/assets/MarkdownImageGallery-DffjmciG.js +1 -0
  9. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +12 -0
  10. package/dist/assets/OnboardingScreen-CTZe6HZn.js +1 -0
  11. package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BymkP9JA.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-BvwtCxW4.js} +3 -3
  13. package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-C1qvAm7m.js} +3 -3
  14. package/dist/assets/SettingsView-xGONHFGS.js +28 -0
  15. package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-COzgfFxM.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-Dlhh_-oe.js} +6 -6
  17. package/dist/assets/ToolPartDiffPreview-b9joNtXH.js +8 -0
  18. package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-vqW3KKo5.js} +1 -1
  19. package/dist/assets/WalkthroughView-D-HFgdmM.js +4 -0
  20. package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DUnyszhW.js} +1 -1
  21. package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-CV-DwAiX.js} +1 -1
  22. package/dist/assets/{de-CEoCz3j6.js → de-Cv_4FoXm.js} +6 -5
  23. package/dist/assets/es-BIWNEbnS.js +16 -0
  24. package/dist/assets/{fr-CS7Csln9.js → fr-SD3OfMHJ.js} +6 -5
  25. package/dist/assets/index-CHUT_bDS.css +1 -0
  26. package/dist/assets/index-DDInLQDd.js +40 -0
  27. package/dist/assets/{index-CaPAjwXQ.js → index-DLiD86ge.js} +1 -1
  28. package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-TNageFjy.js} +1 -1
  29. package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-JPmZOYSp.js} +1 -1
  30. package/dist/assets/{ja-vnwqLcx6.js → ja-D7I9HofF.js} +7 -6
  31. package/dist/assets/{ko-CXuSfZv5.js → ko-BsVJM_PQ.js} +7 -6
  32. package/dist/assets/{main-D5RWr6sJ.js → main-DCB4JgVe.js} +2 -2
  33. package/dist/assets/main-De8Z5w49.js +928 -0
  34. package/dist/assets/markdownCore-BoQVG5-a.js +3 -0
  35. package/dist/assets/{miniChat-CqR3icsk.js → miniChat-BtV7N5OF.js} +2 -2
  36. package/dist/assets/{mobile-RN_UTTlB.js → mobile-DZV_sfX7.js} +2 -2
  37. package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Chmiz6hq.js} +4 -4
  38. package/dist/assets/{pl-BJxry0Mi.js → pl-XR9Bs8Be.js} +6 -5
  39. package/dist/assets/pt-BR-Due4be8g.js +16 -0
  40. package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-8tXADjfl.js} +2 -2
  41. package/dist/assets/renderMobileApp-Cji7Hma5.js +25 -0
  42. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +16 -0
  43. package/dist/assets/scheduledTasksApi-9e-UX6im.js +1 -0
  44. package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CRpCl7UT.js} +1 -1
  45. package/dist/assets/tr-DBJcAv4y.js +7 -0
  46. package/dist/assets/uk-COYh2BaN.js +16 -0
  47. package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-CCgvcQ6u.js} +178 -170
  48. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +2 -0
  49. package/dist/assets/useRootScrollLock-KzOUytpn.js +1 -0
  50. package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BxpoC5Fp.js} +2 -2
  51. package/dist/assets/vendor-zod-DVWEh-IS.js +39 -0
  52. package/dist/assets/{web-components-DOXvU-tB.js → web-components-B6QgbmTo.js} +4 -4
  53. package/dist/assets/zh-CN-Cjk6lzhc.js +16 -0
  54. package/dist/assets/{zh-TW-Dv8yyhN1.js → zh-TW-Dk0dOg03.js} +6 -5
  55. package/dist/index.html +5 -5
  56. package/dist/mini-chat.html +4 -4
  57. package/dist/mobile.html +4 -4
  58. package/package.json +2 -2
  59. package/server/index.js +35 -4
  60. package/server/lib/agent-tool/runtime.js +2 -19
  61. package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
  62. package/server/lib/dev-tunnel/runtime.js +4 -4
  63. package/server/lib/dev-tunnel/tunnel.test.js +20 -0
  64. package/server/lib/dictation/DOCUMENTATION.md +19 -6
  65. package/server/lib/dictation/local/model-catalog.js +220 -0
  66. package/server/lib/dictation/local/model-catalog.test.js +42 -0
  67. package/server/lib/dictation/local/sherpa-tts.js +41 -20
  68. package/server/lib/dictation/local/worker-process.js +2 -0
  69. package/server/lib/dictation/runtime.js +4 -0
  70. package/server/lib/dictation/service.js +27 -4
  71. package/server/lib/fs/DOCUMENTATION.md +4 -0
  72. package/server/lib/fs/routes.js +129 -0
  73. package/server/lib/fs/routes.test.js +219 -0
  74. package/server/lib/git/DOCUMENTATION.md +3 -1
  75. package/server/lib/git/routes.js +16 -0
  76. package/server/lib/git/service.js +97 -17
  77. package/server/lib/git/service.test.js +153 -0
  78. package/server/lib/linear/DOCUMENTATION.md +97 -0
  79. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
  80. package/server/lib/linear/auth.js +436 -0
  81. package/server/lib/linear/auth.test.js +242 -0
  82. package/server/lib/linear/client.js +191 -0
  83. package/server/lib/linear/index.js +61 -0
  84. package/server/lib/linear/issues.js +499 -0
  85. package/server/lib/linear/issues.test.js +512 -0
  86. package/server/lib/linear/mapping.js +188 -0
  87. package/server/lib/linear/mapping.test.js +147 -0
  88. package/server/lib/linear/oauth.js +345 -0
  89. package/server/lib/linear/oauth.test.js +166 -0
  90. package/server/lib/linear/parse.js +23 -0
  91. package/server/lib/linear/routes.js +432 -0
  92. package/server/lib/linear/routes.test.js +661 -0
  93. package/server/lib/linear/status-runtime.js +64 -0
  94. package/server/lib/linear/status-runtime.test.js +167 -0
  95. package/server/lib/linear/status.js +280 -0
  96. package/server/lib/linear/status.test.js +271 -0
  97. package/server/lib/linear/teams.js +72 -0
  98. package/server/lib/linear/teams.test.js +94 -0
  99. package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
  100. package/server/lib/mcp-reconnect/runtime.js +122 -0
  101. package/server/lib/mcp-reconnect/runtime.test.js +140 -0
  102. package/server/lib/message-queue/DOCUMENTATION.md +148 -0
  103. package/server/lib/message-queue/runtime.js +818 -0
  104. package/server/lib/message-queue/runtime.test.js +426 -0
  105. package/server/lib/openchamber-sessions/routes.js +102 -0
  106. package/server/lib/openchamber-sessions/routes.test.js +88 -0
  107. package/server/lib/opencode/DOCUMENTATION.md +5 -1
  108. package/server/lib/opencode/core-routes.js +1 -0
  109. package/server/lib/opencode/feature-routes-runtime.js +5 -0
  110. package/server/lib/opencode/managed-plugin-config.js +35 -0
  111. package/server/lib/opencode/settings-runtime.js +2 -2
  112. package/server/lib/opencode/settings-runtime.test.js +29 -0
  113. package/server/lib/opencode/shutdown-runtime.js +2 -0
  114. package/server/lib/opencode/static-routes-runtime.js +3 -3
  115. package/server/lib/projects/project-config.js +33 -5
  116. package/server/lib/projects/project-config.test.js +85 -0
  117. package/server/lib/quota/DOCUMENTATION.md +2 -1
  118. package/server/lib/quota/credentials/providers.js +4 -0
  119. package/server/lib/quota/credentials/store.js +1 -1
  120. package/server/lib/quota/credentials/store.test.js +4 -4
  121. package/server/lib/quota/providers/exe-dev.js +75 -0
  122. package/server/lib/quota/providers/exe-dev.test.js +47 -0
  123. package/server/lib/quota/providers/index.js +7 -0
  124. package/server/lib/quota/providers/opencode-go.js +1 -0
  125. package/server/lib/quota/providers/opencode-go.test.js +5 -1
  126. package/server/lib/quota/routes.js +2 -0
  127. package/server/lib/relay/DOCUMENTATION.md +1 -1
  128. package/server/lib/relay/tunnel-host.js +3 -1
  129. package/server/lib/relay/tunnel-host.test.js +9 -1
  130. package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
  131. package/server/lib/security/request-security.js +21 -6
  132. package/server/lib/security/request-security.test.js +42 -8
  133. package/server/lib/session-assist/runtime.js +1 -0
  134. package/server/lib/session-goal/create.js +3 -1
  135. package/server/lib/session-goal/runtime.js +1 -0
  136. package/server/lib/small-model/DOCUMENTATION.md +4 -0
  137. package/server/lib/small-model/call.js +8 -2
  138. package/server/lib/small-model/call.test.js +23 -0
  139. package/server/lib/small-model/index.js +2 -1
  140. package/server/lib/small-model/routes.js +2 -1
  141. package/server/lib/system-prompt/runtime.js +2 -21
  142. package/server/lib/terminal/runtime.js +30 -7
  143. package/server/lib/tts/DOCUMENTATION.md +1 -0
  144. package/server/lib/tts/language-detect.js +210 -0
  145. package/server/lib/tts/language-detect.test.js +76 -0
  146. package/server/lib/tts/routes.js +23 -1
  147. package/server/lib/tts/routes.test.js +26 -0
  148. package/server/lib/ui-auth/ui-auth.js +4 -1
  149. package/server/lib/ui-auth/ui-auth.test.js +16 -0
  150. package/server/lib/walkthrough/index.js +1 -0
  151. package/dist/assets/CommitSection-DwGiXyjf.js +0 -1
  152. package/dist/assets/DiffView-Db6bjVv1.js +0 -4
  153. package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
  154. package/dist/assets/GitView-CHzJxTi0.js +0 -6
  155. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
  156. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
  157. package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
  158. package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
  159. package/dist/assets/ToolPartDiffPreview-C7kBQNAA.js +0 -8
  160. package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
  161. package/dist/assets/es-DwyXCqaL.js +0 -15
  162. package/dist/assets/index-CUKcHnUA.css +0 -1
  163. package/dist/assets/index-DIvDEKE-.js +0 -7
  164. package/dist/assets/main-DLlfDjQ_.js +0 -926
  165. package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
  166. package/dist/assets/pt-BR-DxLmkhdv.js +0 -15
  167. package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
  168. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
  169. package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
  170. package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
  171. package/dist/assets/uk-ClgQjmlw.js +0 -15
  172. package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
  173. package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
  174. package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
  175. package/dist/assets/zh-CN-Ba6y8H-i.js +0 -15
@@ -0,0 +1,140 @@
1
+ import fs from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { afterEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ import { createMcpReconnectRuntime } from './runtime.js';
8
+
9
+ const temporaryDirectories = [];
10
+ const disposers = [];
11
+
12
+ afterEach(async () => {
13
+ await Promise.all(disposers.splice(0).map((dispose) => dispose()));
14
+ vi.useRealTimers();
15
+ await Promise.all(temporaryDirectories.splice(0).map((directory) => fs.rm(directory, { recursive: true, force: true })));
16
+ });
17
+
18
+ const materialize = async (rawConfig = '{}') => {
19
+ const dataDir = await fs.mkdtemp(path.join(os.tmpdir(), 'openchamber-mcp-reconnect-'));
20
+ temporaryDirectories.push(dataDir);
21
+ const runtime = createMcpReconnectRuntime({ fsPromises: fs, path, dataDir });
22
+ const prepared = await runtime.prepareManagedOpenCodeEnv(rawConfig);
23
+ const pluginPath = path.join(dataDir, 'mcp-reconnect', 'openchamber-mcp-reconnect-plugin.js');
24
+ const pluginModule = await import(`${pathToFileURL(pluginPath).href}?test=${Date.now()}-${Math.random()}`);
25
+ return { prepared, pluginPath, plugin: pluginModule.OpenChamberMcpReconnectPlugin };
26
+ };
27
+
28
+ /**
29
+ * A stand-in for the SDK client OpenCode hands to plugins. `statuses` is live
30
+ * state the test mutates; `connect` records when each attempt happened.
31
+ */
32
+ const createClient = (statuses, { onConnect } = {}) => {
33
+ const attempts = [];
34
+ return {
35
+ attempts,
36
+ statuses,
37
+ mcp: {
38
+ status: vi.fn(async () => ({ data: { ...statuses } })),
39
+ connect: vi.fn(async ({ path: { name } }) => {
40
+ attempts.push({ name, at: Date.now() });
41
+ onConnect?.(name);
42
+ return { data: true };
43
+ }),
44
+ },
45
+ };
46
+ };
47
+
48
+ const start = async (plugin, client) => {
49
+ const hooks = await plugin({ client });
50
+ disposers.push(hooks.dispose);
51
+ return hooks;
52
+ };
53
+
54
+ describe('managed MCP reconnect runtime', () => {
55
+ it('materializes the plugin and preserves existing plugin entries', async () => {
56
+ const { prepared, pluginPath } = await materialize('{ "plugin": ["file:///existing.js"], "model": "test/model" }');
57
+ const config = JSON.parse(prepared.OPENCODE_CONFIG_CONTENT);
58
+ expect(config.model).toBe('test/model');
59
+ expect(config.plugin).toEqual(['file:///existing.js', pathToFileURL(pluginPath).href]);
60
+ });
61
+
62
+ it('reconnects only servers in the failed state', async () => {
63
+ vi.useFakeTimers();
64
+ const { plugin } = await materialize();
65
+ const client = createClient({
66
+ broken: { status: 'failed', error: 'spawn ENOENT' },
67
+ healthy: { status: 'connected' },
68
+ off: { status: 'disabled' },
69
+ login: { status: 'needs_auth' },
70
+ registration: { status: 'needs_client_registration', error: 'no client id' },
71
+ });
72
+ await start(plugin, client);
73
+
74
+ await vi.advanceTimersByTimeAsync(1000);
75
+
76
+ expect(client.attempts.map((attempt) => attempt.name)).toEqual(['broken']);
77
+ });
78
+
79
+ it('backs off per server up to a cap while it keeps failing', async () => {
80
+ vi.useFakeTimers();
81
+ const { plugin } = await materialize();
82
+ const client = createClient({ broken: { status: 'failed', error: 'refused' } });
83
+ const started = Date.now();
84
+ await start(plugin, client);
85
+
86
+ await vi.advanceTimersByTimeAsync(92_000);
87
+
88
+ expect(client.attempts.map((attempt) => attempt.at - started)).toEqual([
89
+ 1000, 2000, 4000, 8000, 16_000, 32_000, 62_000, 92_000,
90
+ ]);
91
+ });
92
+
93
+ it('stops retrying once a server is back and starts fresh when it drops again', async () => {
94
+ vi.useFakeTimers();
95
+ const { plugin } = await materialize();
96
+ const statuses = { flaky: { status: 'failed', error: 'refused' } };
97
+ const client = createClient(statuses, {
98
+ onConnect: () => { statuses.flaky = { status: 'connected' }; },
99
+ });
100
+ const hooks = await start(plugin, client);
101
+
102
+ await vi.advanceTimersByTimeAsync(60_000);
103
+ expect(client.attempts).toHaveLength(1);
104
+
105
+ statuses.flaky = { status: 'failed', error: 'Connection closed' };
106
+ await hooks.event({ event: { type: 'mcp.tools.changed', properties: { server: 'flaky' } } });
107
+ await vi.advanceTimersByTimeAsync(1000);
108
+
109
+ expect(client.attempts).toHaveLength(2);
110
+ expect(client.attempts[1].at - client.attempts[0].at).toBeGreaterThan(30_000);
111
+ });
112
+
113
+ it('keeps going when status is temporarily unavailable', async () => {
114
+ vi.useFakeTimers();
115
+ const { plugin } = await materialize();
116
+ const client = createClient({ broken: { status: 'failed', error: 'refused' } });
117
+ client.mcp.status.mockRejectedValueOnce(new Error('ECONNREFUSED'));
118
+ await start(plugin, client);
119
+
120
+ await vi.advanceTimersByTimeAsync(1000);
121
+ expect(client.attempts).toHaveLength(0);
122
+
123
+ await vi.advanceTimersByTimeAsync(30_000);
124
+ expect(client.attempts).toHaveLength(1);
125
+ });
126
+
127
+ it('does nothing after dispose', async () => {
128
+ vi.useFakeTimers();
129
+ const { plugin } = await materialize();
130
+ const client = createClient({ broken: { status: 'failed', error: 'refused' } });
131
+ const hooks = await plugin({ client });
132
+
133
+ await hooks.dispose();
134
+ await hooks.event({ event: { type: 'mcp.tools.changed', properties: { server: 'broken' } } });
135
+ await vi.advanceTimersByTimeAsync(120_000);
136
+
137
+ expect(client.mcp.status).not.toHaveBeenCalled();
138
+ expect(client.attempts).toHaveLength(0);
139
+ });
140
+ });
@@ -0,0 +1,148 @@
1
+ # Message Queue
2
+
3
+ ## Purpose
4
+
5
+ Owns the messages a user queued while a session was busy, and sends them the
6
+ moment the session goes idle. The queue lives in the web server so a closed
7
+ tab, a locked phone, or a dropped connection no longer strands it. Structural
8
+ template: `permission-auto-accept` — the server is authoritative, the shared UI
9
+ renders a projection, and VS Code (which has no server of its own) keeps its
10
+ UI-side queue and foreground auto-send hook.
11
+
12
+ ## Files
13
+
14
+ - `runtime.js` — `createMessageQueueRuntime(...)` (state, persistence,
15
+ dispatch loop, event handling) and `registerMessageQueueRoutes(app, runtime)`.
16
+ - `runtime.test.js` — delivery, idleness gates, retries, holds, persistence,
17
+ concurrency with in-flight sends, slash commands, and project knowledge.
18
+
19
+ Wiring: created in `server/index.js` after the global event hub and the
20
+ session-knowledge runtime; routes registered in
21
+ `opencode/feature-routes-runtime.js` (before the generic OpenCode proxy) with
22
+ JSON bodies enabled in `opencode/core-routes.js`; stopped by
23
+ `opencode/shutdown-runtime.js`.
24
+
25
+ ## Item
26
+
27
+ An item is what the UI would have sent itself, captured at queue time so the
28
+ send never re-resolves mutable UI state:
29
+
30
+ ```
31
+ {
32
+ id, createdAt,
33
+ content, // raw text for display and editing
34
+ text, // text to deliver (agent mention stripped, file mentions resolved); defaults to content
35
+ agentMention?, // delivered as an `agent` part
36
+ attachments: [{ id, filename, mimeType, size, source, serverPath?, dataUrl }],
37
+ context: [ // what the composer had attached, in send order
38
+ { kind: 'context', text, metadata, instructions? }, // a draft chip or linked issue/PR; metadata is the UI's structured payload
39
+ { kind: 'instruction', text }, // derived from the text (skill instruction)
40
+ { kind: 'synthetic', text }, // handed to the composer by another surface
41
+ ],
42
+ sendConfig: { providerID, modelID, agent?, variant? } // required
43
+ }
44
+ ```
45
+
46
+ The server is a courier for `context`: it validates the shape (a kind it
47
+ knows, a `metadata` object on `context` entries) and delivers each entry as a
48
+ synthetic text part, an entry's `instructions` going out as its own part just
49
+ before it and its `metadata` riding the part verbatim so the timeline renders
50
+ the context block back. The payload inside `metadata` is the UI's contract
51
+ (`lib/messages/contextParts.ts`), parsed by the UI on the way back.
52
+
53
+ `parseQueuedItemInput` rejects anything the server could not deliver later
54
+ (no text, attachments, or context; missing model; malformed attachment or
55
+ context entry). Public snapshots and broadcasts strip the payloads —
56
+ attachment `dataUrl` (megabytes of base64) and `context` (a PR diff, say) —
57
+ so they do not ride every update; the only way to get them back is a `take`.
58
+
59
+ ## Persistence
60
+
61
+ `<data-dir>/message-queue.json` (`OPENCHAMBER_DATA_DIR` or
62
+ `~/.config/openchamber`): `{ version, revision, sessions: { [sessionId]:
63
+ { directory, items } } }`, written atomically (temp file + rename) through a
64
+ serialized write chain. A missing file is an empty queue. A malformed file is
65
+ a failure, not an empty queue: it is moved aside as
66
+ `message-queue.json.corrupt-<timestamp>` before the runtime starts empty, so
67
+ the next write cannot overwrite the user's data. A failed read leaves writes
68
+ disabled until a later load succeeds. `revision` is a global monotonic counter
69
+ bumped on every mutation; clients use it to reject stale snapshots.
70
+
71
+ In-memory only, deliberately: the in-flight item (`sendingId`), retry
72
+ backoff, abort timestamps, and holds. A restart has no in-flight sends; a
73
+ persisted "sending" flag would strand a message forever.
74
+
75
+ ## Delivery loop
76
+
77
+ 1. `start()` subscribes to the global upstream hub and loads the file; on
78
+ load and on every hub `connect` it arms every session that has items.
79
+ 2. `session.status` for a queued session: `idle` arms a short quiet timer
80
+ (500 ms, coalescing the burst around a turn boundary), `busy`/`retry`
81
+ clears it. A `message.updated` for a completed assistant reply arms as
82
+ well, so a missed idle event cannot strand the queue. `session.deleted`
83
+ drops the session's queue. An assistant `MessageAbortedError` records an
84
+ abort.
85
+ 3. `tick(sessionId)` bails when the queue is empty, an item is in flight, or
86
+ the session is held. It re-arms after a 2 s post-abort hold (the UI's
87
+ old behavior: a stop is not immediately followed by the next prompt) or
88
+ while the head item is in retry backoff.
89
+ 4. Idleness is re-verified against OpenCode before sending, because
90
+ `prompt_async` into a running turn steers into it instead of starting the
91
+ next one: `GET /session/status` must not list the session as busy/retry,
92
+ and the trailing message must not be an unfinished assistant reply (the
93
+ status map only lists busy sessions, so a missed busy event leaves no
94
+ entry while a turn still streams). A failed fetch is unknown, never idle:
95
+ the tick re-arms with backoff.
96
+ 5. The head is marked in flight (broadcast), then sent:
97
+ - text starting with `/` that names a command in OpenCode's `/command`
98
+ list (skills included) goes to `POST /session/:id/command` with the
99
+ captured model, agent, variant, and file parts;
100
+ - otherwise `POST /session/:id/prompt_async` with the parts in the same
101
+ order a UI send uses: text, files, the captured context, pending project
102
+ knowledge (`sessionKnowledgeRuntime.resolvePendingForSession`, synthetic,
103
+ recorded as delivered only after the prompt is accepted), then the agent
104
+ mention. The command path sends files and captured context as `parts`.
105
+ Success removes the item, persists, broadcasts, and marks the user
106
+ message sent for notifications. Failure keeps the item, backs off
107
+ 2 s → 60 s (doubling per consecutive failure of that item), and re-arms.
108
+ 6. The next item goes out after the next busy → idle cycle.
109
+
110
+ ## Holds
111
+
112
+ Auto-review is driven from the UI and bounces the original session through
113
+ idle between iterations; the UI tells the server to hold that session's queue
114
+ (`PUT .../hold { held: true, ttlMs? }`) while a run is going and releases it
115
+ when the run ends. A hold expires on its own (default 5 min, cap 10 min)
116
+ because the UI that asserted it may be gone; the UI re-asserts it every two
117
+ minutes while the run continues. Releasing arms a dispatch.
118
+
119
+ ## Routes (`/api/message-queue`)
120
+
121
+ Normal authenticated OpenChamber runtime routes; never on browser URL-token
122
+ allowlists.
123
+
124
+ | Route | Purpose |
125
+ |---|---|
126
+ | `GET /api/message-queue` | Full snapshot `{ revision, sessions[] }` |
127
+ | `POST .../sessions/:id/items` | Append `{ directory, item }`; returns `{ revision, session, itemId }` and arms a dispatch (the session may already be idle) |
128
+ | `DELETE .../sessions/:id/items/:itemId` | Remove; `409` while that item is in flight |
129
+ | `POST .../sessions/:id/items/:itemId/take` | Remove and return the full item (payloads included); `404`/`409` |
130
+ | `POST .../sessions/:id/take` | Remove and return every item not in flight, in order |
131
+ | `PUT .../sessions/:id/order` | `{ itemIds }` must be a complete permutation |
132
+ | `DELETE .../sessions/:id` | Clear; the in-flight item stays |
133
+ | `PUT .../sessions/:id/hold` | `{ held, ttlMs? }` |
134
+
135
+ Every mutation broadcasts `openchamber:message-queue.updated` with
136
+ `{ revision, session }` to all connected clients (SSE and WS), so several
137
+ devices on one server see one queue.
138
+
139
+ Limits: 20 items per session, 50 sessions (oldest evicted, never one with an
140
+ item in flight), 200k characters of content; attachment payloads are bounded
141
+ by the route family's 50 MB JSON limit.
142
+
143
+ ## UI ownership
144
+
145
+ `packages/ui/src/stores/messageQueueStore.ts` is the projection: see its
146
+ section in `packages/ui/src/stores/DOCUMENTATION.md`. VS Code intentionally
147
+ does not use this module; with all OpenChamber webviews closed, queued
148
+ messages there are not delivered.