@openchamber/web 1.18.4 → 1.19.0

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 (207) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
  3. package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-D9cV-qR9.js} +1 -1
  4. package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-B9NCadU7.js} +1 -1
  5. package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
  6. package/dist/assets/{DiffView-DZIoOnV7.js → DiffView-BWNq-0ov.js} +2 -2
  7. package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
  8. package/dist/assets/{GitView-DBFrDDBv.js → GitView-DsWXqWx3.js} +3 -3
  9. package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-h4dHASlq.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
  12. package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
  13. package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-jPKTJje5.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
  15. package/dist/assets/PlanView-UvuxIl9-.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
  17. package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
  18. package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
  19. package/dist/assets/{ToolOutputDialog-Za6V4VMJ.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-BL-9ixyC.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
  22. package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-Bxun3k66.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
  25. package/dist/assets/de-DbV6CLxv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-CVDlyzZ4.js +15 -0
  28. package/dist/assets/fr-Czc-p0g-.js +13 -0
  29. package/dist/assets/index-1OhiMDBz.css +1 -0
  30. package/dist/assets/index-BSvmTvZl.js +1 -0
  31. package/dist/assets/index-DzriVon2.js +7 -0
  32. package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-DwHKxDYc.js} +1 -1
  33. package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-Dwq6ILxo.js} +1 -1
  34. package/dist/assets/ja-dwc9NM_S.js +15 -0
  35. package/dist/assets/ko-Ds1DZ8FX.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-BF51IOVF.js +921 -0
  38. package/dist/assets/{main-D7UcL3VQ.js → main-D7UPARut.js} +2 -2
  39. package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
  40. package/dist/assets/{miniChat-O_GVoEbc.js → miniChat-BISXSGOo.js} +2 -2
  41. package/dist/assets/mobile-BnYxVuvw.js +2 -0
  42. package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BEDPDypx.js} +2 -2
  43. package/dist/assets/pl-CLiTO7i-.js +15 -0
  44. package/dist/assets/pt-BR-GIimJgpK.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
  46. package/dist/assets/{renderMobileApp-toj9cXoh.js → renderMobileApp-BiMbzPq9.js} +7 -7
  47. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
  48. package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
  49. package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DXYW46vW.js} +1 -1
  50. package/dist/assets/uk-DLfgD1ki.js +15 -0
  51. package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-CbzHzFop.js} +139 -142
  52. package/dist/assets/{useInlineCommentController-CYPvYJDt.js → useInlineCommentController-CegKdDXi.js} +2 -2
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
  85. package/dist/assets/{web-components-GMc3oR3i.js → web-components-DCLjCO9n.js} +1 -1
  86. package/dist/assets/zh-CN-DkeP5awK.js +15 -0
  87. package/dist/assets/zh-TW-BocaFm3d.js +15 -0
  88. package/dist/index.html +4 -4
  89. package/dist/mini-chat.html +3 -3
  90. package/dist/mobile.html +3 -3
  91. package/package.json +1 -1
  92. package/server/index.js +116 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +56 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +85 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +427 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/fs/DOCUMENTATION.md +3 -0
  111. package/server/lib/fs/routes.js +149 -32
  112. package/server/lib/fs/routes.test.js +225 -0
  113. package/server/lib/git/DOCUMENTATION.md +8 -0
  114. package/server/lib/git/service.js +121 -67
  115. package/server/lib/git/service.test.js +129 -0
  116. package/server/lib/github/DOCUMENTATION.md +14 -3
  117. package/server/lib/github/pr-status.js +188 -83
  118. package/server/lib/github/pr-status.test.js +182 -0
  119. package/server/lib/github/routes.js +36 -30
  120. package/server/lib/notifications/template-runtime.js +2 -3
  121. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  122. package/server/lib/openchamber-control/actions.js +78 -0
  123. package/server/lib/openchamber-control/service.js +7 -0
  124. package/server/lib/openchamber-sessions/routes.js +14 -0
  125. package/server/lib/opencode/DOCUMENTATION.md +6 -4
  126. package/server/lib/opencode/claude-cli-auth.js +60 -0
  127. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  128. package/server/lib/opencode/feature-routes-runtime.js +11 -0
  129. package/server/lib/opencode/plugins.js +12 -3
  130. package/server/lib/opencode/plugins.test.js +18 -0
  131. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  132. package/server/lib/opencode/proxy.js +116 -6
  133. package/server/lib/opencode/proxy.test.js +158 -1
  134. package/server/lib/opencode/routes.js +4 -1
  135. package/server/lib/opencode/settings-helpers.js +11 -0
  136. package/server/lib/opencode/settings-helpers.test.js +35 -0
  137. package/server/lib/opencode/settings-runtime.js +51 -0
  138. package/server/lib/opencode/shared.js +120 -16
  139. package/server/lib/opencode/shared.test.js +185 -1
  140. package/server/lib/project-context/DOCUMENTATION.md +158 -0
  141. package/server/lib/project-context/routes.http.test.js +264 -0
  142. package/server/lib/project-context/routes.js +237 -0
  143. package/server/lib/project-context/runtime.js +667 -0
  144. package/server/lib/project-context/runtime.test.js +498 -0
  145. package/server/lib/quota/DOCUMENTATION.md +16 -1
  146. package/server/lib/quota/providers/claude/auth.js +113 -0
  147. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  148. package/server/lib/quota/providers/claude/index.js +151 -0
  149. package/server/lib/quota/providers/claude/index.test.js +147 -0
  150. package/server/lib/quota/providers/claude/transforms.js +127 -0
  151. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  152. package/server/lib/quota/providers/command-code.js +90 -0
  153. package/server/lib/quota/providers/command-code.test.js +72 -0
  154. package/server/lib/quota/providers/index.js +22 -2
  155. package/server/lib/quota/providers/index.test.js +10 -1
  156. package/server/lib/quota/utils/formatters.js +2 -1
  157. package/server/lib/scheduled-tasks/runtime.js +21 -2
  158. package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
  159. package/server/lib/session-knowledge/routes.js +107 -0
  160. package/server/lib/session-knowledge/runtime.js +331 -0
  161. package/server/lib/session-knowledge/runtime.test.js +275 -0
  162. package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
  163. package/server/lib/skills-catalog/curated-sources.js +1 -1
  164. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  165. package/server/lib/small-model/index.js +8 -0
  166. package/server/lib/small-model/index.test.js +31 -1
  167. package/server/lib/small-model/routes.js +3 -1
  168. package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
  169. package/dist/assets/FilesView-BKL6YlKG.js +0 -14
  170. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
  171. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
  172. package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
  173. package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
  174. package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
  175. package/dist/assets/SettingsView-5RmswFZe.js +0 -28
  176. package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
  177. package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
  178. package/dist/assets/de-u7gSnqWs.js +0 -9
  179. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  180. package/dist/assets/es-T9O7aAOr.js +0 -15
  181. package/dist/assets/fr-Oor7ewbE.js +0 -13
  182. package/dist/assets/index-BzIpNlNE.css +0 -1
  183. package/dist/assets/index-C0yNhuZw.js +0 -1
  184. package/dist/assets/index-DRpChWux.js +0 -7
  185. package/dist/assets/ja-DHpqbVmr.js +0 -15
  186. package/dist/assets/ko-CwLkS3nx.js +0 -15
  187. package/dist/assets/main-DPMd2iKS.js +0 -915
  188. package/dist/assets/markdownCore-DDrHVneM.js +0 -2
  189. package/dist/assets/mobile-Br4TtAqc.js +0 -2
  190. package/dist/assets/pl-CcZILN8q.js +0 -15
  191. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  192. package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
  193. package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
  194. package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
  195. package/dist/assets/uk-BA2kZR38.js +0 -15
  196. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  197. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  198. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  199. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  200. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  201. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  202. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  203. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  204. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  205. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  206. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  207. package/server/lib/quota/providers/claude.js +0 -107
@@ -0,0 +1,90 @@
1
+ import { readAuthFile } from '../../opencode/auth.js';
2
+ import { asObject, buildResult, getAuthEntry, normalizeAuthEntry, toNumber, toUsageWindow } from '../utils/index.js';
3
+
4
+ export const providerId = 'command-code';
5
+ export const providerName = 'Command Code';
6
+ export const aliases = ['command-code'];
7
+
8
+ const API_BASE_URL = 'https://api.commandcode.ai';
9
+
10
+ const getApiKey = (auth = readAuthFile()) => {
11
+ const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
12
+ const stored = entry?.key ?? entry?.access ?? entry?.token;
13
+ return (typeof stored === 'string' ? stored.trim() : '') || process.env.COMMAND_CODE_API_KEY?.trim() || null;
14
+ };
15
+
16
+ const requestJson = async (path, apiKey, fetchImpl) => {
17
+ const response = await fetchImpl(`${API_BASE_URL}${path}`, {
18
+ headers: {
19
+ Accept: 'application/json',
20
+ Authorization: `Bearer ${apiKey}`,
21
+ 'User-Agent': 'OpenChamber quota provider',
22
+ },
23
+ signal: AbortSignal.timeout(15_000),
24
+ });
25
+ if (response.status === 401 || response.status === 403) throw new Error('Command Code authentication failed');
26
+ if (!response.ok) throw new Error(`Command Code usage API returned HTTP ${response.status}`);
27
+ return response.json().catch(() => null);
28
+ };
29
+
30
+ const formatCredits = (value) => String(Math.round((value + Number.EPSILON) * 100) / 100);
31
+
32
+ const toBalanceWindow = (value) => toUsageWindow({
33
+ usedPercent: null,
34
+ windowSeconds: null,
35
+ resetAt: null,
36
+ valueLabel: formatCredits(value),
37
+ });
38
+
39
+ export const parseCommandCodeCredits = (payload) => {
40
+ const root = asObject(payload);
41
+ const credits = asObject(root?.credits);
42
+ const limits = asObject(root?.windowLimits);
43
+ const windows = {};
44
+
45
+ for (const [label, field] of [['monthly_credits', 'monthlyCredits'], ['purchased_credits', 'purchasedCredits'], ['free_credits', 'freeCredits']]) {
46
+ const value = toNumber(credits?.[field]);
47
+ if (value !== null) windows[label] = toBalanceWindow(value);
48
+ }
49
+
50
+ for (const [label, field, windowSeconds] of [['5h', 'fiveHour', 5 * 60 * 60], ['weekly', 'weekly', 7 * 24 * 60 * 60]]) {
51
+ const limit = asObject(limits?.[field]);
52
+ const used = toNumber(limit?.used);
53
+ const cap = toNumber(limit?.cap);
54
+ if (used === null || cap === null || cap <= 0) continue;
55
+ const resetAt = toNumber(limit?.resetAt);
56
+ windows[label] = toUsageWindow({
57
+ usedPercent: Math.min(100, Math.max(0, used / cap * 100)),
58
+ windowSeconds,
59
+ resetAt: resetAt === null ? null : resetAt < 1_000_000_000_000 ? resetAt * 1000 : resetAt,
60
+ valueLabel: `${formatCredits(used)} / ${formatCredits(cap)}`,
61
+ });
62
+ }
63
+
64
+ return windows;
65
+ };
66
+
67
+ export const fetchCommandCodeUsage = async (apiKey, fetchImpl = fetch) => {
68
+ const identity = asObject(await requestJson('/alpha/whoami', apiKey, fetchImpl));
69
+ const org = asObject(identity?.org);
70
+ const orgId = typeof org?.id === 'string' ? org.id.trim() : '';
71
+ const creditsPath = orgId
72
+ ? `/alpha/billing/credits?orgId=${encodeURIComponent(orgId)}`
73
+ : '/alpha/billing/credits';
74
+ const credits = await requestJson(creditsPath, apiKey, fetchImpl);
75
+ const windows = parseCommandCodeCredits(credits);
76
+ if (Object.keys(windows).length === 0) throw new Error('Command Code usage data could not be parsed');
77
+ return windows;
78
+ };
79
+
80
+ export const isConfigured = () => Boolean(getApiKey());
81
+
82
+ export const fetchQuota = async (auth = readAuthFile()) => {
83
+ const apiKey = getApiKey(auth);
84
+ if (!apiKey) return buildResult({ providerId, providerName, ok: false, configured: false, error: 'Not configured' });
85
+ try {
86
+ return buildResult({ providerId, providerName, ok: true, configured: true, usage: { windows: await fetchCommandCodeUsage(apiKey) } });
87
+ } catch (error) {
88
+ return buildResult({ providerId, providerName, ok: false, configured: true, error: error instanceof Error ? error.message : 'Request failed' });
89
+ }
90
+ };
@@ -0,0 +1,72 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import { fetchCommandCodeUsage, fetchQuota, parseCommandCodeCredits } from './command-code.js';
4
+
5
+ const creditsPayload = {
6
+ credits: { monthlyCredits: 120, purchasedCredits: 30, freeCredits: 5 },
7
+ windowLimits: {
8
+ fiveHour: { used: 25, cap: 100, resetAt: 1_776_000_000 },
9
+ weekly: { used: 70, cap: 200, resetAt: 1_776_604_800 },
10
+ },
11
+ };
12
+
13
+ describe('Command Code quota provider', () => {
14
+ it('parses balances and rate-limit windows', () => {
15
+ const windows = parseCommandCodeCredits(creditsPayload);
16
+ expect(windows.monthly_credits).toMatchObject({ usedPercent: null, valueLabel: '120' });
17
+ expect(windows.purchased_credits).toMatchObject({ usedPercent: null, valueLabel: '30' });
18
+ expect(windows.free_credits).toMatchObject({ usedPercent: null, valueLabel: '5' });
19
+ expect(windows['5h']).toMatchObject({ usedPercent: 25, valueLabel: '25 / 100', resetAt: 1_776_000_000_000 });
20
+ expect(windows.weekly.usedPercent).toBe(35);
21
+ });
22
+
23
+ it('formats fractional credit values for display', () => {
24
+ const windows = parseCommandCodeCredits({
25
+ credits: { monthlyCredits: 69.7947070034 },
26
+ windowLimits: { fiveHour: { used: 0.2052929966, cap: 14 } },
27
+ });
28
+ expect(windows.monthly_credits.valueLabel).toBe('69.79');
29
+ expect(windows['5h'].valueLabel).toBe('0.21 / 14');
30
+ });
31
+
32
+ it('resolves the organization before fetching credits', async () => {
33
+ const requests = [];
34
+ const windows = await fetchCommandCodeUsage('secret', async (url, options) => {
35
+ requests.push({ url, options });
36
+ return new Response(JSON.stringify(url.endsWith('/alpha/whoami') ? { org: { id: 'org/a' } } : creditsPayload));
37
+ });
38
+ expect(requests.map(({ url }) => url)).toEqual([
39
+ 'https://api.commandcode.ai/alpha/whoami',
40
+ 'https://api.commandcode.ai/alpha/billing/credits?orgId=org%2Fa',
41
+ ]);
42
+ expect(requests[0].options.headers.Authorization).toBe('Bearer secret');
43
+ expect(windows['5h'].usedPercent).toBe(25);
44
+ });
45
+
46
+ it('fetches account-scoped credits without orgId for personal accounts', async () => {
47
+ const urls = [];
48
+ await fetchCommandCodeUsage('secret', async (url) => {
49
+ urls.push(url);
50
+ return new Response(JSON.stringify(url.endsWith('/alpha/whoami') ? { user: { id: 'user-1' }, org: null } : creditsPayload));
51
+ });
52
+ expect(urls).toEqual([
53
+ 'https://api.commandcode.ai/alpha/whoami',
54
+ 'https://api.commandcode.ai/alpha/billing/credits',
55
+ ]);
56
+ });
57
+
58
+ it('does not expose credentials in authentication errors', async () => {
59
+ await expect(fetchCommandCodeUsage('secret', async () => new Response('', { status: 401 }))).rejects.toThrow('authentication failed');
60
+ });
61
+
62
+ it('reads OAuth access credentials from the OpenCode auth file', async () => {
63
+ const fetchMock = vi.fn()
64
+ .mockResolvedValueOnce(new Response(JSON.stringify({ org: { id: 'org-1' } })))
65
+ .mockResolvedValueOnce(new Response(JSON.stringify(creditsPayload)));
66
+ vi.stubGlobal('fetch', fetchMock);
67
+ const result = await fetchQuota({ 'command-code': { type: 'oauth', access: 'test-token' } });
68
+ expect(result).toMatchObject({ providerId: 'command-code', ok: true, configured: true });
69
+ expect(fetchMock.mock.calls[0][1].headers.Authorization).toBe('Bearer test-token');
70
+ vi.unstubAllGlobals();
71
+ });
72
+ });
@@ -7,8 +7,9 @@
7
7
 
8
8
  import { buildResult } from '../utils/index.js';
9
9
 
10
- import * as claude from './claude.js';
10
+ import * as claude from './claude/index.js';
11
11
  import * as codex from './codex.js';
12
+ import * as commandCode from './command-code.js';
12
13
  import * as copilot from './copilot.js';
13
14
  import * as crof from './crof.js';
14
15
  import * as cursor from './cursor.js';
@@ -29,6 +30,12 @@ import * as opencodeGo from './opencode-go.js';
29
30
  import * as xai from './xai.js';
30
31
 
31
32
  const registry = {
33
+ 'command-code': {
34
+ providerId: commandCode.providerId,
35
+ providerName: commandCode.providerName,
36
+ isConfigured: commandCode.isConfigured,
37
+ fetchQuota: commandCode.fetchQuota
38
+ },
32
39
  claude: {
33
40
  providerId: claude.providerId,
34
41
  providerName: claude.providerName,
@@ -151,6 +158,8 @@ const registry = {
151
158
  }
152
159
  };
153
160
 
161
+ const pendingFetches = new Map();
162
+
154
163
  export const listConfiguredQuotaProviders = () => {
155
164
  const configured = [];
156
165
 
@@ -167,7 +176,7 @@ export const listConfiguredQuotaProviders = () => {
167
176
  return configured;
168
177
  };
169
178
 
170
- export const fetchQuotaForProvider = async (providerId) => {
179
+ const fetchQuotaForProviderUncoalesced = async (providerId) => {
171
180
  const provider = registry[providerId];
172
181
 
173
182
  if (!provider) {
@@ -193,6 +202,17 @@ export const fetchQuotaForProvider = async (providerId) => {
193
202
  }
194
203
  };
195
204
 
205
+ export const fetchQuotaForProvider = (providerId) => {
206
+ const existing = pendingFetches.get(providerId);
207
+ if (existing) return existing;
208
+
209
+ const pending = fetchQuotaForProviderUncoalesced(providerId).finally(() => {
210
+ if (pendingFetches.get(providerId) === pending) pendingFetches.delete(providerId);
211
+ });
212
+ pendingFetches.set(providerId, pending);
213
+ return pending;
214
+ };
215
+
196
216
  export const fetchClaudeQuota = claude.fetchQuota;
197
217
  export const fetchOpenaiQuota = openai.fetchQuota;
198
218
  export const fetchGoogleQuota = google.fetchGoogleQuota;
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
3
  import * as google from './google/index.js';
4
- import { listConfiguredQuotaProviders } from './index.js';
4
+ import { fetchQuotaForProvider, listConfiguredQuotaProviders } from './index.js';
5
5
 
6
6
  describe('quota provider registry', () => {
7
7
  it('exposes google provider configuration helpers through the provider module', () => {
@@ -14,4 +14,13 @@ describe('quota provider registry', () => {
14
14
  it('can list configured providers without missing provider exports', () => {
15
15
  expect(() => listConfiguredQuotaProviders()).not.toThrow();
16
16
  });
17
+
18
+ it('coalesces concurrent refreshes by provider ID', async () => {
19
+ const first = fetchQuotaForProvider('unsupported-test-provider');
20
+ const second = fetchQuotaForProvider('unsupported-test-provider');
21
+
22
+ expect(first).toBe(second);
23
+ await first;
24
+ expect(fetchQuotaForProvider('unsupported-test-provider')).not.toBe(first);
25
+ });
17
26
  });
@@ -53,13 +53,14 @@ export const toUsageWindow = ({ usedPercent, windowSeconds, resetAt, valueLabel
53
53
  };
54
54
  };
55
55
 
56
- export const buildResult = ({ providerId, providerName, ok, configured, usage, error }) => ({
56
+ export const buildResult = ({ providerId, providerName, ok, configured, usage, error, planLabel }) => ({
57
57
  providerId,
58
58
  providerName,
59
59
  ok,
60
60
  configured,
61
61
  usage: usage ?? null,
62
62
  ...(error ? { error } : {}),
63
+ ...(planLabel ? { planLabel } : {}),
63
64
  fetchedAt: Date.now()
64
65
  });
65
66
 
@@ -254,6 +254,7 @@ export const createScheduledTasksRuntime = (deps) => {
254
254
  waitForOpenCodeReady,
255
255
  emitTaskRunEvent,
256
256
  setSessionAutoAccept,
257
+ sessionKnowledgeRuntime = null,
257
258
  logger = console,
258
259
  maxGlobalConcurrency = DEFAULT_GLOBAL_CONCURRENCY,
259
260
  maxProjectConcurrency = DEFAULT_PROJECT_CONCURRENCY,
@@ -451,7 +452,7 @@ export const createScheduledTasksRuntime = (deps) => {
451
452
  return projectRunning < maxProjectConcurrency;
452
453
  };
453
454
 
454
- const buildPromptAsyncPayload = (task, projectPath) => ({
455
+ const buildPromptAsyncPayload = (task, projectPath, knowledgeText = '') => ({
455
456
  model: {
456
457
  providerID: task.execution.providerID,
457
458
  modelID: task.execution.modelID,
@@ -459,6 +460,10 @@ export const createScheduledTasksRuntime = (deps) => {
459
460
  ...(task.execution.agent ? { agent: task.execution.agent } : {}),
460
461
  ...(task.execution.variant ? { variant: task.execution.variant } : {}),
461
462
  parts: [
463
+ // Standing project context first, so the prompt reads against it. A
464
+ // scheduled run has no UI to attach this, which is why it is asked for
465
+ // here rather than assembled by whoever is sending.
466
+ ...(knowledgeText ? [{ type: 'text', text: knowledgeText, synthetic: true }] : []),
462
467
  {
463
468
  type: 'text',
464
469
  text: expandSnippets(task.execution.prompt, projectPath),
@@ -470,6 +475,13 @@ export const createScheduledTasksRuntime = (deps) => {
470
475
  });
471
476
 
472
477
  const runPromptAsync = async ({ baseUrl, authHeaders, sessionID, projectPath, task }) => {
478
+ // Never allowed to fail the run: a task that executes without its
479
+ // background is a lesser loss than a task that does not execute.
480
+ const knowledge = sessionKnowledgeRuntime
481
+ ? await sessionKnowledgeRuntime.resolvePendingForSession(sessionID, projectPath)
482
+ .catch(() => ({ text: '', signature: '' }))
483
+ : { text: '', signature: '' };
484
+
473
485
  const promptUrl = new URL(`${baseUrl}/session/${encodeURIComponent(sessionID)}/prompt_async`);
474
486
  promptUrl.searchParams.set('directory', projectPath);
475
487
  const response = await fetch(promptUrl.toString(), {
@@ -479,13 +491,20 @@ export const createScheduledTasksRuntime = (deps) => {
479
491
  'content-type': 'application/json',
480
492
  accept: 'application/json',
481
493
  },
482
- body: JSON.stringify(buildPromptAsyncPayload(task, projectPath)),
494
+ body: JSON.stringify(buildPromptAsyncPayload(task, projectPath, knowledge.text)),
483
495
  });
484
496
 
485
497
  if (!response.ok) {
486
498
  const body = await response.text().catch(() => '');
487
499
  throw new Error(`prompt_async failed (${response.status})${body ? `: ${body}` : ''}`);
488
500
  }
501
+
502
+ // Recorded only after the prompt is accepted, so a failed dispatch carries
503
+ // the context again on the next run.
504
+ if (knowledge.text && sessionKnowledgeRuntime) {
505
+ await sessionKnowledgeRuntime.recordDelivered(sessionID, projectPath, knowledge.signature)
506
+ .catch(() => undefined);
507
+ }
489
508
  };
490
509
 
491
510
  const resolveScheduledCommand = async ({ client, projectPath, task }) => {
@@ -0,0 +1,87 @@
1
+ # Session Knowledge
2
+
3
+ What a session must be told about the project — that session's pinned notes and
4
+ plans, and the index of what the agent has remembered — and whether it has been
5
+ told yet.
6
+
7
+ ## Why it is here and not in the UI
8
+
9
+ The client used to own this: it assembled the text, decided when to send it, and
10
+ remembered what it had sent in a module-scoped map. Two consequences followed.
11
+
12
+ A session started without a UI got nothing at all. Scheduled tasks and sessions
13
+ the agent dispatches build their prompts on the server and never touch the
14
+ browser, so pinned context and the memory index simply did not exist for them.
15
+
16
+ And a tab's memory of what it sent survives compaction, while the conversation
17
+ does not. After a summary the agent no longer holds the block, but the tab goes
18
+ on believing it does and never sends it again.
19
+
20
+ ## The contract
21
+
22
+ `session.metadata.openchamber.project_context_pins` owns the note and plan ids
23
+ attached to that session. Pins never come from project-wide note or plan state.
24
+ A new-session draft passes its pins into this metadata when its first message
25
+ creates the session.
26
+
27
+ `session.metadata.openchamber.knowledge_context_delivered` holds the signature
28
+ of what the session is carrying. It lives with the session, so it survives the
29
+ tab closing and is visible to every sender, including the ones with no tab.
30
+
31
+ The signature covers content revisions, not just identity: editing a pinned note
32
+ must re-send it, not merely renaming one.
33
+
34
+ ## Three moments, two deliveries
35
+
36
+ | Moment | Delivery |
37
+ |---|---|
38
+ | A message from the UI | synthetic part on that message |
39
+ | A scheduled task, a session the agent dispatched | synthetic part on that prompt |
40
+ | After compaction | its own `prompt_async`, alongside the pinned messages |
41
+
42
+ The first two attach to an outgoing message because there is one. Compaction has
43
+ none, which is why it re-sends on its own — and it travels with
44
+ `context-obligatory`'s pinned messages in a single turn, since two synthetic
45
+ messages back to back read as the agent being interrupted twice.
46
+
47
+ ## Failure behaviour
48
+
49
+ Nothing here may fail a send. A message without its background costs the agent
50
+ some context; a failed send costs the user their message. Every caller treats an
51
+ error as "no block this time".
52
+
53
+ A source that will not load never blanks the rest: an unreadable memory store
54
+ still delivers the pinned notes. A memory scope that failed to load is left out
55
+ rather than indexed as empty, which would teach the agent to store again what it
56
+ already has.
57
+
58
+ Delivery is recorded only after the send is accepted. Recording it when the text
59
+ is handed over would leave a failed send believing the agent had context it never
60
+ received.
61
+
62
+ ## Entries that read as instructions
63
+
64
+ Memory is the one place where text from outside can settle permanently. The
65
+ agent reads a page, decides a line is worth keeping, saves it — and from then on
66
+ it rides into every session in every project. An injection anywhere else lives
67
+ for one conversation.
68
+
69
+ `agent-memory/threat-patterns` scans on write and again on every read, so an
70
+ entry written before a pattern existed, or edited on disk since, is judged now.
71
+ A match never deletes: the entry is stored, flagged, kept out of what sessions
72
+ are told, and shown in the panel with a warning. Silently dropping it would hide
73
+ the attempt from the only person able to judge it.
74
+
75
+ Patterns, not a model — this runs on every index build. That buys the blunt
76
+ cases only, which is the honest expectation.
77
+
78
+ ## Shipping dark
79
+
80
+ Agent memory is complete but unreleased. `OPENCHAMBER_MEMORY_ENABLE` decides
81
+ whether it exists in a given process at all: unset, there is no tool, no routes,
82
+ no session index, no settings row and no panel tab — absent rather than switched
83
+ off, which would invite turning on something never announced. The setting itself
84
+ also defaults to off, so setting the variable does not enable memory by itself.
85
+
86
+ Pinned notes and plans are unaffected by the memory switch and remain scoped to
87
+ the session that pinned them.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * What a session still owes in project knowledge, and the record that it was
3
+ * delivered.
4
+ *
5
+ * Two calls rather than one, because only the sender knows whether the message
6
+ * carrying the block actually went out. Handing over the text and recording it
7
+ * as delivered in the same request would leave a failed send believing the
8
+ * agent has context it never received.
9
+ *
10
+ * The body parser is attached per route: there is no global one, because the
11
+ * generic OpenCode proxy needs an unread request stream.
12
+ */
13
+
14
+ import express from 'express';
15
+
16
+ const parseJsonBody = express.json({ limit: '1mb' });
17
+
18
+ const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
19
+
20
+ const asNonEmptyString = (value) => (
21
+ typeof value === 'string' && value.trim().length > 0 ? value.trim() : ''
22
+ );
23
+
24
+ export const registerSessionKnowledgeRoutes = (app, dependencies) => {
25
+ const { sessionKnowledgeRuntime } = dependencies;
26
+
27
+ /**
28
+ * Answers with the text to attach and the signature to report back once it
29
+ * has gone. An empty text means the session is already carrying it.
30
+ */
31
+ app.get('/api/session-knowledge', async (req, res) => {
32
+ const directory = asNonEmptyString(req.query.directory);
33
+ const sessionId = asNonEmptyString(req.query.sessionId);
34
+ if (!directory) {
35
+ return res.status(400).json({ error: 'directory is required' });
36
+ }
37
+
38
+ try {
39
+ const pending = sessionId
40
+ ? await sessionKnowledgeRuntime.resolvePendingForSession(sessionId, directory)
41
+ // A session that does not exist yet — a draft about to be created —
42
+ // has been told nothing, so everything is still owed.
43
+ : await sessionKnowledgeRuntime.resolvePending(directory, '');
44
+ return res.json(pending);
45
+ } catch (error) {
46
+ // Never fails the caller's send: a message without its background is far
47
+ // better than no message at all.
48
+ return res.json({ text: '', signature: '', unavailable: true, reason: error?.message ?? 'unknown' });
49
+ }
50
+ });
51
+
52
+ /** Counts and names for the work status panel; assembles no text. */
53
+ app.get('/api/session-knowledge/summary', async (req, res) => {
54
+ const directory = asNonEmptyString(req.query.directory);
55
+ if (!directory) {
56
+ return res.json({ notes: [], plans: [], memory: { global: 0, project: 0 } });
57
+ }
58
+ const sessionId = asNonEmptyString(req.query.sessionId);
59
+ try {
60
+ return res.json(sessionId
61
+ ? await sessionKnowledgeRuntime.collectSummaryForSession(sessionId, directory)
62
+ : await sessionKnowledgeRuntime.collectSummary(directory));
63
+ } catch {
64
+ // A panel that cannot read this shows nothing rather than an error.
65
+ return res.json({ notes: [], plans: [], memory: { global: 0, project: 0 } });
66
+ }
67
+ });
68
+
69
+ app.post('/api/session-knowledge/pin', parseJsonBody, async (req, res) => {
70
+ const body = req.body;
71
+ if (!isRecord(body)) return res.status(400).json({ error: 'Body must be an object' });
72
+ const sessionId = asNonEmptyString(body.sessionId);
73
+ const directory = asNonEmptyString(body.directory);
74
+ const id = asNonEmptyString(body.id);
75
+ const kind = body.kind === 'note' || body.kind === 'plan' ? body.kind : '';
76
+ if (!sessionId || !directory || !id || !kind || typeof body.pinned !== 'boolean') {
77
+ return res.status(400).json({ error: 'sessionId, directory, kind, id and pinned are required' });
78
+ }
79
+ try {
80
+ return res.json({ pins: await sessionKnowledgeRuntime.setPin(sessionId, directory, kind, id, body.pinned) });
81
+ } catch (error) {
82
+ return res.status(500).json({ error: error?.message ?? 'Unable to update pin' });
83
+ }
84
+ });
85
+
86
+ app.post('/api/session-knowledge/delivered', parseJsonBody, async (req, res) => {
87
+ const body = req.body;
88
+ if (!isRecord(body)) {
89
+ return res.status(400).json({ error: 'Body must be an object' });
90
+ }
91
+ const sessionId = asNonEmptyString(body.sessionId);
92
+ const directory = asNonEmptyString(body.directory);
93
+ const signature = asNonEmptyString(body.signature);
94
+ if (!sessionId || !directory || !signature) {
95
+ return res.status(400).json({ error: 'sessionId, directory and signature are required' });
96
+ }
97
+
98
+ try {
99
+ await sessionKnowledgeRuntime.recordDelivered(sessionId, directory, signature);
100
+ return res.json({ recorded: true });
101
+ } catch (error) {
102
+ // The message is already sent; failing here only means the block may be
103
+ // sent once more, which is far better than reporting the send as failed.
104
+ return res.json({ recorded: false, reason: error?.message ?? 'unknown' });
105
+ }
106
+ });
107
+ };