@openchamber/web 1.19.0 → 1.21.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 (182) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C2BopIs3.js} +1 -1
  2. package/dist/assets/CommitSection-HJeMUAWb.js +1 -0
  3. package/dist/assets/DiffView-D5cvbEPb.js +4 -0
  4. package/dist/assets/FilesView-DPU8aNPL.js +17 -0
  5. package/dist/assets/GitView-Ct6xWrVH.js +6 -0
  6. package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-osju7J70.js} +1 -1
  7. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +1 -0
  8. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +12 -0
  9. package/dist/assets/OnboardingScreen-w2VG4fWY.js +1 -0
  10. package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-Dan3mADn.js} +1 -1
  11. package/dist/assets/PierreDiffViewer-CGoI2v0q.js +157 -0
  12. package/dist/assets/PlanView-Dgg-WTEc.js +4 -0
  13. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +1 -0
  14. package/dist/assets/SettingsView-D9yRuFZw.js +28 -0
  15. package/dist/assets/SettingsWindow-DXF-MTHG.js +1 -0
  16. package/dist/assets/ToolOutputDialog-DrCa1JRk.js +15 -0
  17. package/dist/assets/ToolPartDiffPreview-B_tfvlNF.js +8 -0
  18. package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-CN_BctrR.js} +4 -4
  19. package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
  20. package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
  21. package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-D9Q4lr5x.js} +2 -2
  22. package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-Gi1d5eU1.js} +1 -1
  23. package/dist/assets/contextPanelEmbeddedChat-CpzVNWAv.js +1 -0
  24. package/dist/assets/de-B_LdJwEM.js +9 -0
  25. package/dist/assets/es-CubfsAYV.js +15 -0
  26. package/dist/assets/fr-5qJM0nFS.js +13 -0
  27. package/dist/assets/index-BW82eK5v.css +1 -0
  28. package/dist/assets/index-Brm3X9rs.js +1 -0
  29. package/dist/assets/index-rlLjZUM5.js +7 -0
  30. package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-pH9kAJQH.js} +1 -1
  31. package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-CVKy_dgB.js} +1 -1
  32. package/dist/assets/ja-DJYIBUlH.js +15 -0
  33. package/dist/assets/ko-DcUBkB7y.js +15 -0
  34. package/dist/assets/main-DLBxKIoX.js +926 -0
  35. package/dist/assets/main-vUCh0VB0.js +2 -0
  36. package/dist/assets/markdownCore-DG6GHLF4.js +3 -0
  37. package/dist/assets/miniChat-BlzGEYgE.js +2 -0
  38. package/dist/assets/mobile-CkX6H-IT.js +2 -0
  39. package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BCTsE43U.js} +3 -3
  40. package/dist/assets/pl-rB6BLcio.js +15 -0
  41. package/dist/assets/pt-BR-DcwtlO-o.js +15 -0
  42. package/dist/assets/renderElectronMiniChatApp-CJYe_KOL.js +2 -0
  43. package/dist/assets/renderMobileApp-hQJTnr8B.js +25 -0
  44. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +15 -0
  45. package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +1 -0
  46. package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-BgTPSITe.js} +1 -1
  47. package/dist/assets/uk-INZlFD9A.js +15 -0
  48. package/dist/assets/useAppFontEffects-Cll4gnsh.js +7268 -0
  49. package/dist/assets/useInlineCommentController-DFFv0hae.js +2 -0
  50. package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-_6j2xOWl.js} +1 -1
  51. package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-DkQX2EBa.js} +2 -2
  52. package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
  53. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
  54. package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
  55. package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
  56. package/dist/assets/{web-components-DCLjCO9n.js → web-components-DLnGY4fs.js} +4 -4
  57. package/dist/assets/zh-CN-Dzda8xa1.js +15 -0
  58. package/dist/assets/zh-TW-Cwn3rNYZ.js +15 -0
  59. package/dist/index.html +6 -5
  60. package/dist/mini-chat.html +5 -4
  61. package/dist/mobile.html +5 -4
  62. package/package.json +5 -7
  63. package/server/index.js +44 -0
  64. package/server/lib/agent-memory/project-resolution.js +10 -1
  65. package/server/lib/agent-memory/project-resolution.test.js +9 -0
  66. package/server/lib/agent-memory/runtime.js +7 -2
  67. package/server/lib/client-auth/pairing.js +8 -7
  68. package/server/lib/client-auth/pairing.test.js +5 -1
  69. package/server/lib/client-auth/remote-clients.js +9 -1
  70. package/server/lib/client-auth/remote-clients.test.js +17 -0
  71. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  72. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  73. package/server/lib/dictation/local/worker-process.js +2 -2
  74. package/server/lib/dictation/openai-compatible-session.js +3 -2
  75. package/server/lib/dictation/stream-manager.js +77 -34
  76. package/server/lib/dictation/stream-manager.test.js +60 -2
  77. package/server/lib/fs/routes.test.js +76 -0
  78. package/server/lib/git/routes.js +43 -0
  79. package/server/lib/git/service.js +85 -5
  80. package/server/lib/git/service.test.js +93 -0
  81. package/server/lib/github/pr-status.js +10 -1
  82. package/server/lib/opencode/DOCUMENTATION.md +6 -2
  83. package/server/lib/opencode/feature-routes-runtime.js +5 -9
  84. package/server/lib/opencode/lifecycle.js +202 -26
  85. package/server/lib/opencode/lifecycle.test.js +179 -1
  86. package/server/lib/opencode/providers.js +9 -4
  87. package/server/lib/opencode/providers.test.js +27 -0
  88. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  89. package/server/lib/opencode/session-runtime.js +39 -2
  90. package/server/lib/opencode/session-runtime.test.js +74 -0
  91. package/server/lib/opencode/settings-helpers.js +15 -0
  92. package/server/lib/opencode/settings-helpers.test.js +22 -0
  93. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  94. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  95. package/server/lib/opencode/settings-runtime.js +32 -10
  96. package/server/lib/opencode/settings-runtime.test.js +85 -0
  97. package/server/lib/opencode/skill-routes.js +29 -73
  98. package/server/lib/opencode/skill-routes.test.js +2 -5
  99. package/server/lib/project-context/DOCUMENTATION.md +2 -0
  100. package/server/lib/project-context/runtime.js +7 -2
  101. package/server/lib/projects/project-config.js +7 -2
  102. package/server/lib/quota/DOCUMENTATION.md +1 -1
  103. package/server/lib/quota/providers/claude/index.js +2 -2
  104. package/server/lib/quota/providers/index.js +1 -7
  105. package/server/lib/quota/providers/zai.js +26 -6
  106. package/server/lib/quota/providers/zai.test.js +33 -0
  107. package/server/lib/relay/DOCUMENTATION.md +1 -1
  108. package/server/lib/relay/service.js +34 -2
  109. package/server/lib/relay/service.test.js +69 -0
  110. package/server/lib/session-goal/runtime.js +2 -1
  111. package/server/lib/session-goal/runtime.test.js +4 -2
  112. package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
  113. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  114. package/server/lib/skills-catalog/cache.js +120 -1
  115. package/server/lib/skills-catalog/cache.test.js +77 -0
  116. package/server/lib/skills-catalog/curated-sources.js +21 -5
  117. package/server/lib/skills-catalog/curated-sources.test.js +4 -4
  118. package/server/lib/skills-catalog/disk-cache.js +52 -0
  119. package/server/lib/skills-catalog/github-meta.js +139 -0
  120. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  121. package/server/lib/skills-catalog/source.js +0 -5
  122. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  123. package/server/lib/small-model/call.js +46 -12
  124. package/server/lib/small-model/call.test.js +79 -0
  125. package/server/lib/small-model/index.js +51 -8
  126. package/server/lib/small-model/index.test.js +73 -3
  127. package/server/lib/small-model/routes.js +1 -1
  128. package/server/lib/small-model/runtime-providers.js +156 -0
  129. package/server/lib/small-model/runtime-providers.test.js +112 -0
  130. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  131. package/server/lib/terminal/runtime.js +29 -1
  132. package/server/lib/terminal/runtime.test.js +26 -0
  133. package/server/lib/ui-auth/ui-auth.js +2 -2
  134. package/server/lib/ui-auth/ui-auth.test.js +2 -2
  135. package/dist/assets/CommitSection-D9cV-qR9.js +0 -1
  136. package/dist/assets/DiagramEditor-B9NCadU7.js +0 -1
  137. package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
  138. package/dist/assets/DiffView-BWNq-0ov.js +0 -4
  139. package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
  140. package/dist/assets/GitView-DsWXqWx3.js +0 -6
  141. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +0 -1
  142. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
  143. package/dist/assets/OnboardingScreen-CDjgzxEe.js +0 -1
  144. package/dist/assets/PierreDiffViewer-D_Gt4A_6.js +0 -136
  145. package/dist/assets/PlanView-UvuxIl9-.js +0 -4
  146. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
  147. package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
  148. package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
  149. package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
  150. package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
  151. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +0 -1
  152. package/dist/assets/de-DbV6CLxv.js +0 -9
  153. package/dist/assets/es-CVDlyzZ4.js +0 -15
  154. package/dist/assets/fr-Czc-p0g-.js +0 -13
  155. package/dist/assets/index-1OhiMDBz.css +0 -1
  156. package/dist/assets/index-BSvmTvZl.js +0 -1
  157. package/dist/assets/index-DzriVon2.js +0 -7
  158. package/dist/assets/ja-dwc9NM_S.js +0 -15
  159. package/dist/assets/ko-Ds1DZ8FX.js +0 -15
  160. package/dist/assets/main-BF51IOVF.js +0 -921
  161. package/dist/assets/main-D7UPARut.js +0 -2
  162. package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
  163. package/dist/assets/miniChat-BISXSGOo.js +0 -2
  164. package/dist/assets/mobile-BnYxVuvw.js +0 -2
  165. package/dist/assets/pl-CLiTO7i-.js +0 -15
  166. package/dist/assets/pt-BR-GIimJgpK.js +0 -15
  167. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
  168. package/dist/assets/renderMobileApp-BiMbzPq9.js +0 -25
  169. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
  170. package/dist/assets/scheduledTasksApi-01zzfzqH.js +0 -1
  171. package/dist/assets/uk-DLfgD1ki.js +0 -15
  172. package/dist/assets/useAppFontEffects-CbzHzFop.js +0 -7271
  173. package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
  174. package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
  175. package/dist/assets/zh-CN-DkeP5awK.js +0 -15
  176. package/dist/assets/zh-TW-BocaFm3d.js +0 -15
  177. package/server/lib/quota/providers/command-code.js +0 -90
  178. package/server/lib/quota/providers/command-code.test.js +0 -72
  179. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  180. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  181. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  182. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -1,6 +1,58 @@
1
- const DEFAULT_TTL_MS = 30 * 60 * 1000;
1
+ import { readDiskCache, writeDiskCache } from './disk-cache.js';
2
+
3
+ const DEFAULT_TTL_MS = 3 * 60 * 60 * 1000;
4
+ const DISK_CACHE_FILE = 'skills-catalog-cache.json';
5
+ const MAX_CONCURRENT_SCANS = 2;
2
6
 
3
7
  const cache = new Map();
8
+ const inFlight = new Map();
9
+
10
+ let diskLoaded = false;
11
+ let diskWriteTimer = null;
12
+
13
+ const loadDiskEntries = () => {
14
+ if (diskLoaded) {
15
+ return;
16
+ }
17
+ diskLoaded = true;
18
+ const persisted = readDiskCache(DISK_CACHE_FILE);
19
+ if (!persisted) {
20
+ return;
21
+ }
22
+ const now = Date.now();
23
+ for (const [key, entry] of Object.entries(persisted)) {
24
+ if (
25
+ entry
26
+ && typeof entry === 'object'
27
+ && typeof entry.expiresAt === 'number'
28
+ && entry.expiresAt > now
29
+ && entry.value
30
+ && typeof entry.value === 'object'
31
+ ) {
32
+ cache.set(key, entry);
33
+ }
34
+ }
35
+ };
36
+
37
+ const scheduleDiskWrite = () => {
38
+ if (diskWriteTimer) {
39
+ return;
40
+ }
41
+ diskWriteTimer = setTimeout(() => {
42
+ diskWriteTimer = null;
43
+ const now = Date.now();
44
+ const persisted = {};
45
+ for (const [key, entry] of cache.entries()) {
46
+ if (entry.expiresAt > now) {
47
+ persisted[key] = entry;
48
+ }
49
+ }
50
+ writeDiskCache(DISK_CACHE_FILE, persisted);
51
+ }, 1000);
52
+ if (typeof diskWriteTimer.unref === 'function') {
53
+ diskWriteTimer.unref();
54
+ }
55
+ };
4
56
 
5
57
  export function getCacheKey({ normalizedRepo, subpath, identityId }) {
6
58
  const safeRepo = String(normalizedRepo || '').trim();
@@ -10,6 +62,7 @@ export function getCacheKey({ normalizedRepo, subpath, identityId }) {
10
62
  }
11
63
 
12
64
  export function getCachedScan(key) {
65
+ loadDiskEntries();
13
66
  const entry = cache.get(key);
14
67
  if (!entry) return null;
15
68
  if (Date.now() >= entry.expiresAt) {
@@ -22,4 +75,70 @@ export function getCachedScan(key) {
22
75
  export function setCachedScan(key, value, ttlMs = DEFAULT_TTL_MS) {
23
76
  const ttl = Number.isFinite(ttlMs) ? ttlMs : DEFAULT_TTL_MS;
24
77
  cache.set(key, { expiresAt: Date.now() + ttl, value });
78
+ scheduleDiskWrite();
79
+ }
80
+
81
+ export function clearCache() {
82
+ cache.clear();
83
+ inFlight.clear();
84
+ }
85
+
86
+ // ─── Concurrency-limited scan orchestration ───
87
+
88
+ let activeScans = 0;
89
+ const scanQueue = [];
90
+
91
+ const acquireScanSlot = () => new Promise((resolve) => {
92
+ scanQueue.push(resolve);
93
+ pumpScanQueue();
94
+ });
95
+
96
+ const releaseScanSlot = () => {
97
+ activeScans -= 1;
98
+ pumpScanQueue();
99
+ };
100
+
101
+ const pumpScanQueue = () => {
102
+ while (activeScans < MAX_CONCURRENT_SCANS && scanQueue.length > 0) {
103
+ const resolve = scanQueue.shift();
104
+ activeScans += 1;
105
+ resolve();
106
+ }
107
+ };
108
+
109
+ /**
110
+ * Run `loader` for a scan cache key with deduplication and a global
111
+ * concurrency limit. Concurrent callers for the same key share one loader
112
+ * run; at most MAX_CONCURRENT_SCANS loaders run at once. Only successful
113
+ * (`ok: true`) results are cached.
114
+ */
115
+ export async function scanWithCache(key, loader, { refresh = false } = {}) {
116
+ if (!refresh) {
117
+ const cached = getCachedScan(key);
118
+ if (cached) {
119
+ return cached;
120
+ }
121
+ }
122
+
123
+ const existing = inFlight.get(key);
124
+ if (existing) {
125
+ return existing;
126
+ }
127
+
128
+ const run = (async () => {
129
+ await acquireScanSlot();
130
+ try {
131
+ const result = await loader();
132
+ if (result && result.ok) {
133
+ setCachedScan(key, result);
134
+ }
135
+ return result;
136
+ } finally {
137
+ releaseScanSlot();
138
+ inFlight.delete(key);
139
+ }
140
+ })();
141
+
142
+ inFlight.set(key, run);
143
+ return run;
25
144
  }
@@ -0,0 +1,77 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import fs from 'fs';
3
+ import os from 'os';
4
+ import path from 'path';
5
+ import { clearCache, scanWithCache, setCachedScan, getCachedScan } from './cache.js';
6
+
7
+ let tempDataDir;
8
+
9
+ beforeEach(() => {
10
+ tempDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'skills-cache-test-'));
11
+ process.env.OPENCHAMBER_DATA_DIR = tempDataDir;
12
+ });
13
+
14
+ afterEach(() => {
15
+ delete process.env.OPENCHAMBER_DATA_DIR;
16
+ clearCache();
17
+ vi.restoreAllMocks();
18
+ fs.rmSync(tempDataDir, { recursive: true, force: true });
19
+ });
20
+
21
+ const flushDiskWrites = async () => new Promise((resolve) => setTimeout(resolve, 1200));
22
+
23
+ describe('scanWithCache', () => {
24
+ it('deduplicates concurrent loaders for the same key', async () => {
25
+ const loader = vi.fn(async () => {
26
+ await new Promise((resolve) => setTimeout(resolve, 20));
27
+ return { ok: true, items: [] };
28
+ });
29
+
30
+ const [a, b] = await Promise.all([
31
+ scanWithCache('k', loader),
32
+ scanWithCache('k', loader),
33
+ ]);
34
+
35
+ expect(loader).toHaveBeenCalledTimes(1);
36
+ expect(a).toEqual(b);
37
+ });
38
+
39
+ it('limits concurrent scans across different keys', async () => {
40
+ let running = 0;
41
+ let peak = 0;
42
+ const loader = async () => {
43
+ running += 1;
44
+ peak = Math.max(peak, running);
45
+ await new Promise((resolve) => setTimeout(resolve, 20));
46
+ running -= 1;
47
+ return { ok: true, items: [] };
48
+ };
49
+
50
+ await Promise.all(Array.from({ length: 6 }, (_, i) => scanWithCache(`key-${i}`, loader)));
51
+
52
+ expect(peak).toBeLessThanOrEqual(2);
53
+ });
54
+
55
+ it('does not cache failed scans', async () => {
56
+ await scanWithCache('bad', async () => ({ ok: false, error: { kind: 'networkError', message: 'x' } }));
57
+
58
+ expect(getCachedScan('bad')).toBeNull();
59
+ });
60
+
61
+ it('refresh bypasses the cache', async () => {
62
+ setCachedScan('fresh', { ok: true, items: ['cached'] });
63
+
64
+ const result = await scanWithCache('fresh', async () => ({ ok: true, items: ['reloaded'] }), { refresh: true });
65
+
66
+ expect(result.items).toEqual(['reloaded']);
67
+ expect(getCachedScan('fresh').items).toEqual(['reloaded']);
68
+ });
69
+
70
+ it('persists successful scans to disk for later processes', async () => {
71
+ await scanWithCache('persisted', async () => ({ ok: true, items: [{ skillName: 'x' }] }));
72
+ await flushDiskWrites();
73
+
74
+ const onDisk = JSON.parse(fs.readFileSync(path.join(tempDataDir, 'skills-catalog-cache.json'), 'utf8'));
75
+ expect(onDisk.persisted.value.items).toEqual([{ skillName: 'x' }]);
76
+ });
77
+ });
@@ -8,11 +8,27 @@ const CURATED_SKILLS_SOURCES = [
8
8
  sourceType: 'github',
9
9
  },
10
10
  {
11
- id: 'clawdhub',
12
- label: 'ClawHub',
13
- description: 'Community skill registry with vector search',
14
- source: 'clawdhub:registry',
15
- sourceType: 'clawdhub',
11
+ id: 'openai',
12
+ label: 'OpenAI',
13
+ description: "OpenAI's curated skills",
14
+ source: 'openai/skills',
15
+ defaultSubpath: 'skills/.curated',
16
+ sourceType: 'github',
17
+ },
18
+ {
19
+ id: 'cursor',
20
+ label: 'Cursor',
21
+ description: "Cursor's plugin skills",
22
+ source: 'cursor/plugins',
23
+ defaultSubpath: 'pstack/skills',
24
+ sourceType: 'github',
25
+ },
26
+ {
27
+ id: 'mattpocock',
28
+ label: 'Matt Pocock',
29
+ description: 'Matt Pocock skills collection',
30
+ source: 'mattpocock/skills',
31
+ sourceType: 'github',
16
32
  },
17
33
  ];
18
34
 
@@ -2,9 +2,9 @@ import { describe, expect, it } from 'vitest';
2
2
  import { getCuratedSkillsSources } from './curated-sources.js';
3
3
 
4
4
  describe('getCuratedSkillsSources', () => {
5
- it('labels the ClawHub curated source as ClawHub', () => {
6
- const clawhub = getCuratedSkillsSources().find((source) => source.id === 'clawdhub');
7
- expect(clawhub).toBeDefined();
8
- expect(clawhub.label).toBe('ClawHub');
5
+ it('includes the Anthropic curated source', () => {
6
+ const anthropic = getCuratedSkillsSources().find((source) => source.id === 'anthropic');
7
+ expect(anthropic).toBeDefined();
8
+ expect(anthropic.label).toBe('Anthropic');
9
9
  });
10
10
  });
@@ -0,0 +1,52 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+
5
+ const resolveDataDir = () => (process.env.OPENCHAMBER_DATA_DIR
6
+ ? path.resolve(process.env.OPENCHAMBER_DATA_DIR)
7
+ : path.join(os.homedir(), '.config', 'openchamber'));
8
+
9
+ const readJsonFile = (filePath) => {
10
+ try {
11
+ const raw = fs.readFileSync(filePath, 'utf8');
12
+ const parsed = JSON.parse(raw);
13
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
14
+ } catch {
15
+ return null;
16
+ }
17
+ };
18
+
19
+ /**
20
+ * Read a persisted cache object from the OpenChamber data directory.
21
+ * Returns null when the file is missing, unreadable, or malformed.
22
+ */
23
+ export const readDiskCache = (fileName) => {
24
+ try {
25
+ return readJsonFile(path.join(resolveDataDir(), fileName));
26
+ } catch {
27
+ return null;
28
+ }
29
+ };
30
+
31
+ /**
32
+ * Persist a cache object to the OpenChamber data directory with an atomic
33
+ * temp-file rename. Failures are ignored: the in-memory cache stays
34
+ * authoritative and the next successful write retries persistence.
35
+ */
36
+ export const writeDiskCache = (fileName, data) => {
37
+ const filePath = path.join(resolveDataDir(), fileName);
38
+ const tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
39
+ try {
40
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
41
+ fs.writeFileSync(tempPath, JSON.stringify(data), { encoding: 'utf8', mode: 0o600 });
42
+ fs.renameSync(tempPath, filePath);
43
+ return true;
44
+ } catch {
45
+ try {
46
+ fs.unlinkSync(tempPath);
47
+ } catch {
48
+ // ignore
49
+ }
50
+ return false;
51
+ }
52
+ };
@@ -0,0 +1,139 @@
1
+ import { readDiskCache, writeDiskCache } from './disk-cache.js';
2
+
3
+ const GITHUB_API_BASE = 'https://api.github.com';
4
+ const CACHE_TTL_MS = 3 * 60 * 60 * 1000;
5
+ const FAILURE_CACHE_TTL_MS = 5 * 60 * 1000;
6
+ // Keep well under the catalog route's client request deadline so optional
7
+ // metadata enrichment can never abort catalog loading.
8
+ const FETCH_TIMEOUT_MS = 1500;
9
+ const DISK_CACHE_FILE = 'skills-github-meta.json';
10
+
11
+ const metaCache = new Map();
12
+ const inFlight = new Map();
13
+
14
+ let diskLoaded = false;
15
+ let diskWriteTimer = null;
16
+
17
+ const loadDiskEntries = () => {
18
+ if (diskLoaded) {
19
+ return;
20
+ }
21
+ diskLoaded = true;
22
+ const persisted = readDiskCache(DISK_CACHE_FILE);
23
+ if (!persisted) {
24
+ return;
25
+ }
26
+ const now = Date.now();
27
+ for (const [repo, entry] of Object.entries(persisted)) {
28
+ if (
29
+ entry
30
+ && typeof entry === 'object'
31
+ && typeof entry.expiresAt === 'number'
32
+ && entry.expiresAt > now
33
+ && entry.value
34
+ && typeof entry.value === 'object'
35
+ ) {
36
+ metaCache.set(repo, entry);
37
+ }
38
+ }
39
+ };
40
+
41
+ const scheduleDiskWrite = () => {
42
+ if (diskWriteTimer) {
43
+ return;
44
+ }
45
+ diskWriteTimer = setTimeout(() => {
46
+ diskWriteTimer = null;
47
+ const now = Date.now();
48
+ const persisted = {};
49
+ for (const [repo, entry] of metaCache.entries()) {
50
+ if (entry.expiresAt > now) {
51
+ persisted[repo] = entry;
52
+ }
53
+ }
54
+ writeDiskCache(DISK_CACHE_FILE, persisted);
55
+ }, 1000);
56
+ if (typeof diskWriteTimer.unref === 'function') {
57
+ diskWriteTimer.unref();
58
+ }
59
+ };
60
+
61
+ const parseMeta = (payload) => {
62
+ if (!payload || typeof payload !== 'object') {
63
+ return null;
64
+ }
65
+ const pushedAt = payload.pushed_at;
66
+ return {
67
+ stars: Number.isFinite(payload.stargazers_count) ? payload.stargazers_count : null,
68
+ repoUpdatedAt: typeof pushedAt === 'string' && pushedAt ? pushedAt : null,
69
+ };
70
+ };
71
+
72
+ const fetchRepoMeta = async (normalizedRepo) => {
73
+ loadDiskEntries();
74
+ const cached = metaCache.get(normalizedRepo);
75
+ if (cached && Date.now() < cached.expiresAt) {
76
+ return cached.value;
77
+ }
78
+
79
+ const existing = inFlight.get(normalizedRepo);
80
+ if (existing) {
81
+ return existing;
82
+ }
83
+
84
+ const run = (async () => {
85
+ try {
86
+ const response = await fetch(`${GITHUB_API_BASE}/repos/${normalizedRepo}`, {
87
+ headers: { Accept: 'application/vnd.github+json' },
88
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
89
+ });
90
+ if (!response.ok) {
91
+ // Cache failures briefly so repeated catalog loads do not re-hit a
92
+ // rate-limited or failing API for the same repository.
93
+ metaCache.set(normalizedRepo, {
94
+ expiresAt: Date.now() + FAILURE_CACHE_TTL_MS,
95
+ value: { stars: null, repoUpdatedAt: null },
96
+ });
97
+ scheduleDiskWrite();
98
+ return null;
99
+ }
100
+
101
+ const value = parseMeta(await response.json());
102
+ if (value) {
103
+ metaCache.set(normalizedRepo, { expiresAt: Date.now() + CACHE_TTL_MS, value });
104
+ scheduleDiskWrite();
105
+ }
106
+ return value;
107
+ } catch {
108
+ metaCache.set(normalizedRepo, {
109
+ expiresAt: Date.now() + FAILURE_CACHE_TTL_MS,
110
+ value: { stars: null, repoUpdatedAt: null },
111
+ });
112
+ scheduleDiskWrite();
113
+ return null;
114
+ } finally {
115
+ inFlight.delete(normalizedRepo);
116
+ }
117
+ })();
118
+
119
+ inFlight.set(normalizedRepo, run);
120
+ return run;
121
+ };
122
+
123
+ /**
124
+ * Fetch GitHub repository metadata (stars, last push) for a list of
125
+ * `owner/repo` strings. Best-effort: failed lookups resolve to null and
126
+ * never block the catalog response.
127
+ */
128
+ export async function fetchGitHubRepoMetas(normalizedRepos) {
129
+ const unique = [...new Set(normalizedRepos.filter(Boolean))];
130
+ const entries = await Promise.all(unique.map(async (repo) => [repo, await fetchRepoMeta(repo)]));
131
+ return Object.fromEntries(entries);
132
+ }
133
+
134
+ /** For tests only: clear the in-memory repository metadata cache. */
135
+ export function clearGitHubMetaCache() {
136
+ metaCache.clear();
137
+ inFlight.clear();
138
+ diskLoaded = true;
139
+ }
@@ -0,0 +1,71 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import fs from 'fs';
3
+ import os from 'os';
4
+ import path from 'path';
5
+ import { clearGitHubMetaCache, fetchGitHubRepoMetas } from './github-meta.js';
6
+
7
+ const originalFetch = globalThis.fetch;
8
+
9
+ let tempDataDir;
10
+
11
+ beforeEach(() => {
12
+ tempDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'github-meta-test-'));
13
+ process.env.OPENCHAMBER_DATA_DIR = tempDataDir;
14
+ });
15
+
16
+ afterEach(() => {
17
+ delete process.env.OPENCHAMBER_DATA_DIR;
18
+ globalThis.fetch = originalFetch;
19
+ clearGitHubMetaCache();
20
+ vi.restoreAllMocks();
21
+ fs.rmSync(tempDataDir, { recursive: true, force: true });
22
+ });
23
+
24
+ describe('fetchGitHubRepoMetas', () => {
25
+ it('returns stars and pushed_at from the GitHub API', async () => {
26
+ const fetchMock = vi.fn(async () => new Response(
27
+ JSON.stringify({ stargazers_count: 42, pushed_at: '2026-08-01T00:00:00Z' }),
28
+ { status: 200 },
29
+ ));
30
+ globalThis.fetch = fetchMock;
31
+
32
+ const metas = await fetchGitHubRepoMetas(['anthropics/skills']);
33
+
34
+ expect(metas).toEqual({
35
+ 'anthropics/skills': { stars: 42, repoUpdatedAt: '2026-08-01T00:00:00Z' },
36
+ });
37
+ expect(fetchMock).toHaveBeenCalledTimes(1);
38
+ });
39
+
40
+ it('resolves failed lookups to null without throwing', async () => {
41
+ globalThis.fetch = vi.fn(async () => new Response('rate limited', { status: 403 }));
42
+
43
+ const metas = await fetchGitHubRepoMetas(['anthropics/skills']);
44
+
45
+ expect(metas).toEqual({ 'anthropics/skills': null });
46
+ });
47
+
48
+ it('caches failed lookups briefly to avoid repeat hits', async () => {
49
+ const fetchMock = vi.fn(async () => new Response('rate limited', { status: 403 }));
50
+ globalThis.fetch = fetchMock;
51
+
52
+ await fetchGitHubRepoMetas(['anthropics/skills']);
53
+ const second = await fetchGitHubRepoMetas(['anthropics/skills']);
54
+
55
+ expect(fetchMock).toHaveBeenCalledTimes(1);
56
+ expect(second).toEqual({ 'anthropics/skills': { stars: null, repoUpdatedAt: null } });
57
+ });
58
+
59
+ it('deduplicates repositories', async () => {
60
+ const fetchMock = vi.fn(async () => new Response(
61
+ JSON.stringify({ stargazers_count: 1, pushed_at: null }),
62
+ { status: 200 },
63
+ ));
64
+ globalThis.fetch = fetchMock;
65
+
66
+ const metas = await fetchGitHubRepoMetas(['a/b', 'a/b', null]);
67
+
68
+ expect(fetchMock).toHaveBeenCalledTimes(1);
69
+ expect(metas['a/b']).toEqual({ stars: 1, repoUpdatedAt: null });
70
+ });
71
+ });
@@ -1,5 +1,4 @@
1
1
  const GITHUB_HOST = 'github.com';
2
- const CLAWDHUB_SOURCE_PREFIX = 'clawdhub:';
3
2
 
4
3
 
5
4
  function normalizeGitOwnerRepo(owner, repo) {
@@ -86,7 +85,3 @@ export function parseSkillRepoSource(input, options = {}) {
86
85
 
87
86
  return { ok: false, error: { kind: 'invalidSource', message: 'Unsupported repository source format' } };
88
87
  }
89
-
90
- export function isClawdHubSource(input) {
91
- return typeof input === 'string' && input.trim().toLowerCase().startsWith(CLAWDHUB_SOURCE_PREFIX);
92
- }
@@ -15,6 +15,15 @@ other runtime API.
15
15
  ## Files
16
16
 
17
17
  - `index.js` — orchestration: `generateSmallModelText()` / `describeSmallModel()`.
18
+ - `runtime-providers.js` — provider state that exists only inside the running
19
+ OpenCode process. A plugin registers its provider from the `config` hook and
20
+ supplies the credential from its `auth` loader, so neither reaches
21
+ `opencode.json` nor `auth.json`; `GET /provider` is the only place they
22
+ become visible. The module caches one snapshot (30s TTL, shared in-flight
23
+ request) and answers `null` — never an empty provider list — when OpenCode is
24
+ unreachable, so a momentary outage cannot retract providers. It is wired once
25
+ from `server/index.js` and reset on OpenCode restart, which reloads plugins
26
+ and can move their ports and keys.
18
27
  - `resolve.js` — model selection, mirroring OpenCode's `getSmallModel` chain:
19
28
  0. OpenChamber's own settings override (Settings → Sessions → Small Model):
20
29
  when `smallModelUseDefault` is `false`, `smallModelOverride`
@@ -100,9 +109,17 @@ other runtime API.
100
109
  - Everything else: OpenAI-compatible `/chat/completions` against the
101
110
  provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
102
111
  in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
103
- endpoint, or (3) the provider's `api` field from the models.dev catalog.
104
- Configured API keys honor OpenCode's `{env:NAME}` and `{file:path}`
105
- substitutions; file contents and resolved credentials remain server-side.
112
+ endpoint, (3) the endpoint OpenCode resolved at runtime, or (4) the
113
+ provider's `api` field from the models.dev catalog. The credential follows
114
+ the same shape: config `options.apiKey`, then the runtime credential, then
115
+ the auth.json entry. Configured API keys honor OpenCode's `{env:NAME}` and
116
+ `{file:path}` substitutions; file contents and resolved credentials remain
117
+ server-side.
118
+ - The runtime credential is refused for providers listed in
119
+ `OWN_CREDENTIAL_HANDLING`. Their branches need the stored entry rather than
120
+ a bearer token: the clearest case is the ChatGPT-plan `openai` login, whose
121
+ runtime `options.apiKey` is an OAuth access token that `api.openai.com`
122
+ answers with 401.
106
123
  - `[small-model:diagnostic]` logs record provider/model, input character
107
124
  counts, output budget, thinking toggle, HTTP/finish status, and
108
125
  content/reasoning lengths without logging prompts, response text, or
@@ -110,11 +127,59 @@ other runtime API.
110
127
  `[session-goal:diagnostic]` structural verdict metadata.
111
128
  - `catalog.js` — models.dev catalog via the shared in-process cache
112
129
  (`../opencode/models-metadata.js`, also serving
113
- `/api/openchamber/models-metadata`).
130
+ `/api/openchamber/models-metadata`).
114
131
  - `routes.js` — `GET /api/small-model` (resolution preview) and
115
132
  `POST /api/small-model/generate` (`{ prompt, system?, maxOutputTokens?,
116
133
  model?, directory? }` → `{ text, providerID, modelID, source }`).
117
134
 
135
+ ## Which providers the pickers may offer
136
+
137
+ `listAuthenticatedProviders()` answers one question for the Small Model and
138
+ Changes Walkthrough pickers alike: which providers can this module actually
139
+ call. One rule decides it, applied the same way to every provider — **a
140
+ credential we are allowed to use, and an endpoint to send it to.** The
141
+ auth.json scan as before, plus the credential and endpoint OpenCode resolved
142
+ for a plugin provider.
143
+
144
+ **opencode zen is excluded without a real login.** When the user has no zen
145
+ credential, OpenCode substitutes the sentinel `options.apiKey = "public"` and
146
+ trims its catalog to the free models. Those run on OpenCode's own subsidised
147
+ infrastructure and are meant to be reached through OpenCode, so the sentinel is
148
+ never accepted as a credential — see `ZEN_ANONYMOUS_API_KEY`.
149
+
150
+ ### Why there is no capability probe
151
+
152
+ A plugin may implement its whole integration inside `options.fetch` —
153
+ rewriting the path, signing the request, translating the payload — and OpenCode
154
+ cannot serialise a function. Such a provider advertises an ordinary base URL
155
+ that answers nothing we know how to ask, and no reported field distinguishes it
156
+ from a plain one.
157
+
158
+ Asking the endpoint (`GET /models`) does identify that case correctly. It was
159
+ measured against all 166 providers carrying an `api` URL in the models.dev
160
+ catalog, and it also denies six of them — `cloudflare-workers-ai`,
161
+ `infomaniak`, `iflowcn`, `inference`, `kuae-cloud-coding-plan`,
162
+ `thinkingmachines` — which work fine and simply have no `/models` route. At a
163
+ 3.6% false-negative rate on providers known to work, the probe removes more
164
+ working models from the picker than broken ones, and a provider that silently
165
+ vanishes explains nothing while one that fails on use says why.
166
+
167
+ So availability stops at credential and endpoint, and the protocol verdict is
168
+ left to the call. A provider whose protocol lives in a plugin's `fetch` stays
169
+ selectable and fails when used — which is what it did before this resolution
170
+ existed.
171
+
172
+ Claude Code is refused unconditionally. A plugin can publish an
173
+ OpenAI-compatible endpoint for it, but that endpoint is a façade over the
174
+ Claude Agent SDK, which spawns the Claude Code CLI per request and spends the
175
+ user's Claude subscription rate limit. Paying that for a session title or a
176
+ summary is the wrong trade, so an available endpoint does not lift the
177
+ refusal — the cost is the reason, not the transport.
178
+
179
+ The result is served as `authenticatedProviders` on `GET /api/small-model`.
180
+ The field name predates the runtime resolution; it now means "callable", which
181
+ is a superset of "has an auth.json entry".
182
+
118
183
  ## Registration
119
184
 
120
185
  Mounted lazily from `feature-routes-runtime.js` (same pattern as quota): the
@@ -125,9 +190,12 @@ module is imported on first request, not at server startup.
125
190
  - OpenCode's free models (`opencode/big-pickle`, `*-free`) work without a
126
191
  token only through OpenCode's own server — direct calls are rejected, and
127
192
  piggybacking on their subsidized infra is out of bounds by design. Every
128
- resolution step therefore requires a usable auth entry for the provider:
193
+ resolution step therefore requires a credential we are allowed to use:
129
194
  a session on an unauthenticated `opencode` provider falls through to the
130
- global scan (or a clean 404 on a vanilla setup with no logins).
195
+ global scan (or a clean 404 on a vanilla setup with no logins). The runtime
196
+ snapshot does not weaken this — OpenCode reports the sentinel
197
+ `apiKey: "public"` for that state, and this module refuses to read it as a
198
+ credential.
131
199
 
132
200
  - Anthropic OAuth (Claude Pro/Max) entries are not supported — OpenCode itself
133
201
  keeps those outside `auth.json` in this generation; only `type: api` keys