@openchamber/web 1.23.2 → 1.24.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 (223) hide show
  1. package/bin/cli.test.js +7 -6
  2. package/bin/lib/cli-http.js +5 -1
  3. package/dist/assets/{CodeMirrorCommentWidgets-DdNGwbBw.js → CodeMirrorCommentWidgets-DvUH815P.js} +1 -1
  4. package/dist/assets/DiffView-DkC3xlRJ.js +4 -0
  5. package/dist/assets/FilesView-D0bM9FVB.js +13 -0
  6. package/dist/assets/GitView-Bxuv3dfP.js +6 -0
  7. package/dist/assets/GuestAttachDialog-B0u3Q5uO.js +1 -0
  8. package/dist/assets/{JsonTreeView-Chzx5Y6N.js → JsonTreeView-BBVPFM5K.js} +1 -1
  9. package/dist/assets/LinearIssuesView-UI1FcSC8.js +1 -0
  10. package/dist/assets/{MarkdownImageGallery-CugnrZ6f.js → MarkdownImageGallery-CUJxH8Le.js} +1 -1
  11. package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +12 -0
  12. package/dist/assets/{OnboardingScreen-hH9xcTjA.js → OnboardingScreen-5Gou9cGD.js} +1 -1
  13. package/dist/assets/{PatchDiff-DRgNYc9l.js → PatchDiff-C4rE5k6z.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-ZT2CKuzJ.js → PierreDiffViewer-ByRVu6ss.js} +5 -5
  15. package/dist/assets/PlanView-u2yi5XGJ.js +5 -0
  16. package/dist/assets/PluginPane-QxjsKYeO.js +3 -0
  17. package/dist/assets/SettingsView-Fo5ZqMaT.js +29 -0
  18. package/dist/assets/{SettingsWindow-DisOghhD.js → SettingsWindow-HVDVANjJ.js} +1 -1
  19. package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +1 -0
  20. package/dist/assets/ToolOutputDialog-3J6IRayW.js +15 -0
  21. package/dist/assets/{ToolPartDiffPreview-oWxWCu-4.js → ToolPartDiffPreview-DarxPjSd.js} +2 -2
  22. package/dist/assets/{VirtualizedFileDiff-CiyrAq_I.js → VirtualizedFileDiff-CZgXWHjU.js} +4 -4
  23. package/dist/assets/{WalkthroughView-CKTevaea.js → WalkthroughView-wSpED5L4.js} +2 -2
  24. package/dist/assets/appThemeRegistry-Cf8KitzT.js +1 -0
  25. package/dist/assets/commitAndPush-DZnzlhvc.js +1 -0
  26. package/dist/assets/{computeVirtualFileMetrics-SUWoTyPe.js → computeVirtualFileMetrics-VYnT_A2h.js} +1 -1
  27. package/dist/assets/de-BM_8EDD3.js +10 -0
  28. package/dist/assets/es-CxZjlqpo.js +16 -0
  29. package/dist/assets/fr-VCixCnMW.js +14 -0
  30. package/dist/assets/{index-C4jJ3Ur5.js → index-3U4CtS9b.js} +1 -1
  31. package/dist/assets/index-B9Hvzjwl.css +1 -0
  32. package/dist/assets/index-DLHQogv8.js +40 -0
  33. package/dist/assets/{isDiffPlainText-DfG0cZxr.js → isDiffPlainText-ImDG3Uhg.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CyNivOCU.js → isFilePlainText-D_YDVYDb.js} +1 -1
  35. package/dist/assets/ja-CZ5k_GyD.js +16 -0
  36. package/dist/assets/ko-7YM3A1Xh.js +16 -0
  37. package/dist/assets/{main-B8cGozKr.js → main-CycplCph.js} +2 -2
  38. package/dist/assets/main-DFYTCx5o.js +896 -0
  39. package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
  40. package/dist/assets/markdownCore-DHvqMxPn.js +5 -0
  41. package/dist/assets/{miniChat-Cay99IxR.js → miniChat-DIQKfY2V.js} +2 -2
  42. package/dist/assets/{mobile-Zfhix7nz.js → mobile-BMwz5q-m.js} +2 -2
  43. package/dist/assets/{patchFileDiff-CJ5AN9Ql.js → patchFileDiff-DDQ6Rq5e.js} +3 -3
  44. package/dist/assets/pl-BcgDO_w5.js +16 -0
  45. package/dist/assets/{pt-BR-CLosVawq.js → pt-BR-CU2u_1q5.js} +4 -4
  46. package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +2 -0
  47. package/dist/assets/renderMobileApp-D0Y8DtkA.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-DhC3REb2.js +25 -0
  49. package/dist/assets/{scheduledTasksApi-CGFV4Pap.js → scheduledTasksApi-D8pq6gQz.js} +1 -1
  50. package/dist/assets/shikiHighlight-1imXsir9.js +1 -0
  51. package/dist/assets/textMateThemeFromAppTheme-Dgqc63LZ.js +1 -0
  52. package/dist/assets/tr-DuYhOzNe.js +7 -0
  53. package/dist/assets/uk-Cuk7-uvq.js +16 -0
  54. package/dist/assets/useAppFontEffects-BItUWdo4.js +7333 -0
  55. package/dist/assets/useInlineCommentController-CkbKsm7m.js +2 -0
  56. package/dist/assets/useRootScrollLock-vmzxZjWA.js +2 -0
  57. package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-language-data-ES33GhKK.js → vendor-codemirror-language-data-BDyxuqK4.js} +2 -2
  59. package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
  60. package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
  61. package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
  62. package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
  63. package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
  64. package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
  65. package/dist/assets/{web-components-CJZwV5BE.js → web-components-D7FinaeH.js} +2 -2
  66. package/dist/assets/zh-CN-CUWoiRHd.js +16 -0
  67. package/dist/assets/zh-TW-CQ8EBSBN.js +16 -0
  68. package/dist/index.html +4 -4
  69. package/dist/mini-chat.html +4 -4
  70. package/dist/mobile.html +4 -4
  71. package/package.json +9 -6
  72. package/server/built-in-extensions/registry.json +4 -0
  73. package/server/index.d.ts +2 -0
  74. package/server/index.js +41 -10
  75. package/server/lib/changelog/update-notes.js +2 -1
  76. package/server/lib/changelog/update-notes.test.js +19 -0
  77. package/server/lib/event-stream/DOCUMENTATION.md +23 -0
  78. package/server/lib/event-stream/delta-coalescer.js +0 -0
  79. package/server/lib/event-stream/delta-coalescer.test.js +292 -0
  80. package/server/lib/event-stream/global-hub.js +53 -23
  81. package/server/lib/event-stream/global-hub.test.js +160 -0
  82. package/server/lib/event-stream/global-ws-bridge.js +1 -0
  83. package/server/lib/event-stream/index.js +4 -0
  84. package/server/lib/fs/DOCUMENTATION.md +8 -0
  85. package/server/lib/fs/git-process.test.js +77 -0
  86. package/server/lib/fs/routes.js +2 -1
  87. package/server/lib/fs/search.js +2 -1
  88. package/server/lib/git/DOCUMENTATION.md +19 -4
  89. package/server/lib/git/routes.js +16 -3
  90. package/server/lib/git/serial-refresh.js +93 -0
  91. package/server/lib/git/serial-refresh.test.js +112 -0
  92. package/server/lib/git/service.js +336 -62
  93. package/server/lib/git/service.test.js +400 -0
  94. package/server/lib/github/pr-status.js +5 -5
  95. package/server/lib/github/pr-status.test.js +1 -1
  96. package/server/lib/github/routes.js +4 -4
  97. package/server/lib/guests/DOCUMENTATION.md +68 -0
  98. package/server/lib/guests/auth-store.js +184 -0
  99. package/server/lib/guests/auth-store.test.js +112 -0
  100. package/server/lib/guests/background.test.js +83 -0
  101. package/server/lib/guests/builtins.js +34 -0
  102. package/server/lib/guests/builtins.test.js +174 -0
  103. package/server/lib/guests/catalog.js +477 -0
  104. package/server/lib/guests/catalog.test.js +390 -0
  105. package/server/lib/guests/clone.js +297 -0
  106. package/server/lib/guests/extract-zip.js +136 -0
  107. package/server/lib/guests/extract-zip.test.js +109 -0
  108. package/server/lib/guests/files.js +308 -0
  109. package/server/lib/guests/files.test.js +262 -0
  110. package/server/lib/guests/grant-scope.js +81 -0
  111. package/server/lib/guests/grant-scope.test.js +75 -0
  112. package/server/lib/guests/host-session.js +73 -0
  113. package/server/lib/guests/host-session.test.js +30 -0
  114. package/server/lib/guests/html-styles.js +6 -0
  115. package/server/lib/guests/html-styles.test.js +45 -0
  116. package/server/lib/guests/html-tokens.js +73 -0
  117. package/server/lib/guests/html-tokens.test.js +53 -0
  118. package/server/lib/guests/install.js +406 -0
  119. package/server/lib/guests/install.test.js +338 -0
  120. package/server/lib/guests/oauth.js +501 -0
  121. package/server/lib/guests/oauth.test.js +481 -0
  122. package/server/lib/guests/persist.js +336 -0
  123. package/server/lib/guests/persist.test.js +288 -0
  124. package/server/lib/guests/request.js +112 -0
  125. package/server/lib/guests/request.test.js +206 -0
  126. package/server/lib/guests/routes.js +838 -0
  127. package/server/lib/guests/service.js +538 -0
  128. package/server/lib/guests/service.test.js +277 -0
  129. package/server/lib/guests/sockets.js +129 -0
  130. package/server/lib/guests/sockets.test.js +110 -0
  131. package/server/lib/guests/ssh-install.test.js +188 -0
  132. package/server/lib/guests/storage.js +68 -0
  133. package/server/lib/guests/storage.test.js +59 -0
  134. package/server/lib/guests/updates.js +294 -0
  135. package/server/lib/guests/updates.test.js +334 -0
  136. package/server/lib/guests/upload.js +50 -0
  137. package/server/lib/guests/upload.test.js +131 -0
  138. package/server/lib/linear/DOCUMENTATION.md +1 -1
  139. package/server/lib/message-queue/DOCUMENTATION.md +6 -0
  140. package/server/lib/message-queue/runtime.js +5 -0
  141. package/server/lib/message-queue/runtime.test.js +32 -1
  142. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
  143. package/server/lib/openchamber-sessions/routes.js +44 -11
  144. package/server/lib/openchamber-sessions/routes.test.js +47 -0
  145. package/server/lib/opencode/DOCUMENTATION.md +40 -0
  146. package/server/lib/opencode/core-routes.js +39 -1
  147. package/server/lib/opencode/feature-routes-runtime.js +15 -0
  148. package/server/lib/opencode/lifecycle-process.test.js +84 -0
  149. package/server/lib/opencode/lifecycle.js +54 -67
  150. package/server/lib/opencode/settings-helpers.js +3 -0
  151. package/server/lib/opencode/settings-normalization-runtime.js +2 -0
  152. package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
  153. package/server/lib/opencode/settings-registry.json +12 -0
  154. package/server/lib/opencode/shutdown-runtime.js +3 -0
  155. package/server/lib/opencode/shutdown-runtime.test.js +24 -0
  156. package/server/lib/opencode/theme-archive.js +53 -0
  157. package/server/lib/opencode/theme-catalog.js +171 -0
  158. package/server/lib/opencode/theme-catalog.test.js +125 -0
  159. package/server/lib/opencode/theme-import.test.js +144 -0
  160. package/server/lib/opencode/theme-runtime.js +100 -28
  161. package/server/lib/opencode/theme-runtime.test.js +15 -0
  162. package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
  163. package/server/lib/permission-auto-accept/runtime.js +13 -0
  164. package/server/lib/permission-auto-accept/runtime.test.js +37 -1
  165. package/server/lib/quota/DOCUMENTATION.md +0 -1
  166. package/server/lib/quota/providers/index.js +0 -7
  167. package/server/lib/routing/DOCUMENTATION.md +81 -0
  168. package/server/lib/routing/defaults.js +98 -0
  169. package/server/lib/routing/feature-flag.js +11 -0
  170. package/server/lib/routing/history.js +34 -0
  171. package/server/lib/routing/jev.js +98 -0
  172. package/server/lib/routing/routes.http.test.js +100 -0
  173. package/server/lib/routing/routes.js +81 -0
  174. package/server/lib/routing/runtime.js +217 -0
  175. package/server/lib/routing/runtime.test.js +188 -0
  176. package/server/lib/routing/store.js +249 -0
  177. package/server/lib/routing/store.test.js +96 -0
  178. package/server/lib/security/request-security.js +9 -5
  179. package/server/lib/security/request-security.test.js +37 -0
  180. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  181. package/server/lib/terminal/runtime.js +17 -2
  182. package/server/lib/terminal/runtime.test.js +45 -0
  183. package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
  184. package/server/lib/ui-auth/session-cookie.js +51 -0
  185. package/server/lib/ui-auth/session-cookie.test.js +46 -0
  186. package/server/lib/ui-auth/ui-auth.js +56 -17
  187. package/server/lib/ui-auth/ui-auth.test.js +96 -0
  188. package/dist/assets/DiffView-GYriC0Wk.js +0 -4
  189. package/dist/assets/DirtyBranchSwitchDialog-Bv0C99hc.js +0 -1
  190. package/dist/assets/FilesView-2Lin13wx.js +0 -13
  191. package/dist/assets/GitView-9wKba3UO.js +0 -6
  192. package/dist/assets/LinearIssuesView-DXS9QJiR.js +0 -1
  193. package/dist/assets/MarkdownRendererImpl-CaMyct2Q.js +0 -12
  194. package/dist/assets/PlanView-DiTBm2BD.js +0 -5
  195. package/dist/assets/SettingsView-CN8VeM99.js +0 -28
  196. package/dist/assets/ToolOutputDialog-BqiKydxR.js +0 -15
  197. package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
  198. package/dist/assets/de-DQWC94VK.js +0 -10
  199. package/dist/assets/es-DixFUD3m.js +0 -16
  200. package/dist/assets/fr-D6u8tvfA.js +0 -14
  201. package/dist/assets/index-BvpFzhLs.js +0 -40
  202. package/dist/assets/index-n5p3SnES.css +0 -1
  203. package/dist/assets/ja-4u4pCorB.js +0 -16
  204. package/dist/assets/ko-C27-LW_b.js +0 -16
  205. package/dist/assets/main-tEA-fFPg.js +0 -930
  206. package/dist/assets/markdownCore-kyGrWGsn.js +0 -5
  207. package/dist/assets/pl-FtCjsNdW.js +0 -16
  208. package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
  209. package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +0 -2
  210. package/dist/assets/renderMobileApp-C4X_KUH8.js +0 -25
  211. package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +0 -41
  212. package/dist/assets/shikiHighlight-DdKWYWrV.js +0 -1
  213. package/dist/assets/tr-D2j6wUez.js +0 -7
  214. package/dist/assets/uk-C6IzmwM_.js +0 -16
  215. package/dist/assets/useAppFontEffects-DgCHy6Mr.js +0 -7282
  216. package/dist/assets/useGitComparison-BIaI0WZI.js +0 -1
  217. package/dist/assets/useInlineCommentController-2wcCtpM3.js +0 -2
  218. package/dist/assets/useRootScrollLock-CbWA03xR.js +0 -1
  219. package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
  220. package/dist/assets/zh-CN-Wl6tIDz1.js +0 -16
  221. package/dist/assets/zh-TW-hgphoWSN.js +0 -16
  222. package/server/lib/quota/providers/crof.js +0 -96
  223. package/server/lib/quota/providers/crof.test.js +0 -98
@@ -0,0 +1,77 @@
1
+ import { spawn } from 'node:child_process';
2
+ import crypto from 'node:crypto';
3
+ import fs from 'node:fs/promises';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { describe, expect, it } from 'vitest';
7
+ import { createFsSearchRuntime } from './search.js';
8
+ import { registerFsRoutes } from './routes.js';
9
+
10
+ // Use real OS pipes. A mocked data event cannot reproduce a full stderr pipe.
11
+ const noisyGit = `
12
+ const fs = require('node:fs');
13
+ const chunk = Buffer.alloc(65536, 'x');
14
+ for (let i = 0; i < 32; i++) fs.writeSync(2, chunk);
15
+ fs.writeSync(1, 'ignored.txt\\n');
16
+ `;
17
+
18
+ describe('filesystem Git process ownership', () => {
19
+ for (const operation of ['search', 'list']) {
20
+ it(`${operation} completes repeated checks with more diagnostics than an OS pipe can hold`, async () => {
21
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-git-pipes-'));
22
+ const children = [];
23
+ const exits = [];
24
+ const launch = (binary, args, options) => {
25
+ expect(binary).toBe('git');
26
+ expect(args).toContain('check-ignore');
27
+ expect(args).toContain('ignored.txt');
28
+ const child = spawn(process.execPath, ['-e', noisyGit], options);
29
+ children.push(child);
30
+ exits.push(new Promise((resolve) => child.once('close', (code) => resolve(code))));
31
+ return child;
32
+ };
33
+ let deadline;
34
+ try {
35
+ await fs.writeFile(path.join(root, 'ignored.txt'), 'ignored');
36
+ await fs.writeFile(path.join(root, 'visible.txt'), 'visible');
37
+ const dependencies = { fsPromises: fs, path, spawn: launch, resolveGitBinaryForSpawn: () => 'git' };
38
+ const search = createFsSearchRuntime(dependencies);
39
+ const routes = new Map();
40
+ registerFsRoutes({
41
+ get(route, handler) { routes.set(route, handler); }, post() {}, put() {}, delete() {},
42
+ }, {
43
+ ...dependencies, os, crypto, normalizeDirectoryPath: (value) => value,
44
+ resolveProjectDirectory: async () => ({ directory: root }),
45
+ buildAugmentedPath: () => process.env.PATH,
46
+ openchamberUserConfigRoot: root,
47
+ gitCheckIgnoreTimeoutMs: 10_000,
48
+ });
49
+ const work = Array.from({ length: 12 }, async () => {
50
+ if (operation === 'search') {
51
+ const files = await search.searchFilesystemFiles(root, { query: '', limit: 10, respectGitignore: true });
52
+ expect(files.map((file) => file.name)).toEqual(['visible.txt']);
53
+ } else {
54
+ const response = { status() { return this; }, json(value) { this.body = value; } };
55
+ await routes.get('/api/fs/list')({ query: { path: root, respectGitignore: 'true' } }, response);
56
+ expect(response.body.entries.map((entry) => entry.name)).toEqual(['visible.txt']);
57
+ }
58
+ });
59
+ await Promise.race([
60
+ Promise.all(work),
61
+ new Promise((_, reject) => { deadline = setTimeout(() => reject(new Error('Git blocked on unread diagnostics')), 5000); }),
62
+ ]);
63
+ expect(children).toHaveLength(12);
64
+ expect(await Promise.all(exits)).toEqual(Array(12).fill(0));
65
+ for (const child of children) expect(child.exitCode).toBe(0);
66
+ } finally {
67
+ clearTimeout(deadline);
68
+ for (const child of children) {
69
+ child.stderr?.resume();
70
+ if (child.exitCode === null && child.signalCode === null) child.kill('SIGKILL');
71
+ }
72
+ await Promise.all(exits);
73
+ await fs.rm(root, { recursive: true, force: true });
74
+ }
75
+ }, 15_000);
76
+ }
77
+ });
@@ -1619,7 +1619,8 @@ export const registerFsRoutes = (app, dependencies) => {
1619
1619
  const child = spawn(resolveGitBinaryForSpawn(), ['check-ignore', '--', ...pathsToCheck], {
1620
1620
  cwd: resolvedPath,
1621
1621
  windowsHide: true,
1622
- stdio: ['ignore', 'pipe', 'pipe'],
1622
+ // Diagnostics are unused here. An unread pipe can block Git forever.
1623
+ stdio: ['ignore', 'pipe', 'ignore'],
1623
1624
  });
1624
1625
 
1625
1626
  let stdout = '';
@@ -127,7 +127,8 @@ export const createFsSearchRuntime = ({ fsPromises, path, spawn, resolveGitBinar
127
127
  const child = spawn(resolveGitBinaryForSpawn(), ['check-ignore', '--', ...pathsToCheck], {
128
128
  cwd: dir,
129
129
  windowsHide: true,
130
- stdio: ['ignore', 'pipe', 'pipe'],
130
+ // Diagnostics are unused here. An unread pipe can block Git forever.
131
+ stdio: ['ignore', 'pipe', 'ignore'],
131
132
  });
132
133
 
133
134
  let stdout = '';
@@ -24,13 +24,16 @@ The following functions are exported and used by the web server:
24
24
  - `getRemoteUrl(directory, remoteName)`: Get URL for a specific remote.
25
25
 
26
26
  ### Status and Diff Operations
27
- - `getStatus(directory)`: Get comprehensive Git status including current branch, tracking, ahead/behind, file changes, diff stats, merge/rebase state.
27
+ - `getStatus(directory, { mode })`: Get comprehensive Git status including current branch, tracking, ahead/behind, file changes, diff stats, merge/rebase state. `mode: 'light'` skips the diff stats. One read runs per directory at a time and at most four run across directories (`serial-refresh.js`): a call made while a read is running waits for one follow-up read that starts after the call, so no caller gets a snapshot older than its request, and every caller that arrives during one read shares that single follow-up at the widest mode any of them asked for. Clients refresh after every completed agent tool call and from several surfaces at once; on a large repository (a status read is a dozen Git processes walking the working tree) this bound is what keeps identical `git status` processes from piling up side by side. Untracked files are listed with `-unormal` and each new directory is then expanded to its files with a bounded `ls-files` listing (`UNTRACKED_DIRECTORY_EXPANSION_LIMIT`, 1000): up to that many files the result equals `-uall`; beyond it the directory stays one `dir/` entry, because `-uall` would walk a forgotten build or dependency directory in full on every read. A nested repository stays a `dir/` entry as before.
28
+ - `getTrackingBranch(directory)`: Upstream of the checked-out branch as `remote/branch` (the same value as `status.tracking`, including an upstream whose remote ref is gone), or `null` when HEAD is detached or unborn or no upstream is configured. Reads refs and config only. Callers that need just the tracking name (GitHub PR status polling, PR creation) use this instead of `getStatus`.
28
29
  - `getDiff(directory, { path, staged, contextLines })`: Get diff output for files or entire working tree with full Git blob identities. Untracked symbolic links are represented as link entries without following their targets.
30
+ - `getPathDiff(directory, { path, staged, contextLines })`: `getDiff` for one path, returning `{ diff, submodule }`. `submodule` is `null` for ordinary paths. For a gitlink it is `{ headCommit, indexCommit, worktreeCommit, hasTrackedChanges, hasUntrackedFiles, hasConflict }`, because a submodule that only gained untracked files shows as modified in status while its patch is empty. `worktreeCommit` is `null` when the submodule is not checked out. An unmerged gitlink has no single index commit, so it reports `hasConflict: true` with `indexCommit: null`. Exposed as `GET /api/git/diff`.
31
+ - Paths come from an earlier status listing and can stop resolving. Per-path operations reject with `error.code`: `path_not_found` when the path is absent from the working tree, index, and HEAD (for example, a file removed after the listing), `nested_repository` when the path is a directory holding its own `.git` that is not a submodule (status lists it as `dir/`), and `untracked_directory` when the path is a directory status kept as one `dir/` entry because it holds more untracked files than the expansion bound. `GET /api/git/diff` and `GET /api/git/file-diff` answer these with 404, 422 and 422 and a `{ error, code }` body instead of 500. Entry existence is read from `ls-files --stage` and `ls-tree` modes, not `cat-file -e`: a gitlink's commit is not in the parent's object store, and simple-git reports that silent exit 1 as success.
29
32
  - `getRangeDiff(directory, { base, head, path, contextLines, includeWorkingTree })`: Compare the merge base of the exact selected refs with `head`. With `includeWorkingTree: true`, compare with the checked-out branch's current files instead, including committed, staged, unstaged, and untracked work in one net diff. This mode rejects a head that is not the checked-out branch. Exposed as `GET /api/git/range-diff`; omit `path` for the whole comparison.
30
33
  - `getRangeFiles(directory, { base, head, includeWorkingTree })`: List changed paths using the same comparison as `getRangeDiff`. A successful empty list means the final files match the merge base, even if staging and working-tree changes cancel each other out.
31
34
  - Both range operations honor refs literally. A local `main` is never replaced with `origin/main`, and an unavailable ref fails rather than choosing a different remote. The UI picker sends qualified refs to distinguish local and remote branches with matching display names.
32
35
  - Working-tree comparisons use the real index read-only. When untracked paths exist, a temporary copy of the index receives intent-to-add entries so Git computes additions, deletions, recreations, and renames together. Current contents come from the working tree, symlinks remain links, ignored files stay excluded, and temporary files are removed on success or failure.
33
- - `getFileDiff(directory, { path, staged })`: Get original and modified file contents for a single file (handles images as data URLs and symbolic links as their link-target text).
36
+ - `getFileDiff(directory, { path, staged })`: Get original and modified file contents for a single file (handles images as data URLs and symbolic links as their link-target text). For a submodule, both sides are Git's `Subproject commit <sha>` text (HEAD against the worktree checkout, or against the index when `staged`) and the result carries the same `submodule` state as `getPathDiff`; other paths return no `submodule`, which the route sends as `null`.
34
37
  - `listUntrackedPaths(directory)`: List individual untracked file paths honoring ignore rules. Much cheaper than `getStatus` when that is all a caller needs. Deliberately not `--directory`: collapsed directory entries end in a slash and are rejected by the per-file diff helpers, so a caller would silently lose every file inside a new directory.
35
38
  - `getUntrackedDiffs(directory, filePaths, { concurrency, contextLines })`: Diffs for untracked files against an empty tree. Resolves the repository context once instead of per file (`getDiff` re-resolves every call, costing an extra `rev-parse` each time) and bounds how many diff processes run at once. Returns one entry per input path in order; unreadable paths yield `''` rather than failing the batch.
36
39
  - `collectDiffs(directory, files)`: Collect diff output for multiple files.
@@ -81,6 +84,17 @@ bootstrap, tracking is left unset rather than writing `branch.*.remote` /
81
84
  - `removeRemote(directory, options)`: Remove a configured remote (except `origin`).
82
85
  - `deleteRemoteBranch(directory, options)`: Delete a remote branch.
83
86
 
87
+ `push` leaves an unspecified destination to Git, including `branch.<name>.pushRemote`
88
+ and `remote.pushDefault`. Its missing-upstream fallback uses that same destination;
89
+ an explicit remote overrides configuration. `pushed` contains only refs changed by
90
+ the operation, derived from Git's porcelain flags, including first publication,
91
+ fast-forward and forced updates. Each entry's `remote` is the destination remote
92
+ name, not a ref. A successful no-op returns an empty array; rejected pushes throw.
93
+ Commit & Push and Sync share the same fetch/pull/push flow in web, Electron and
94
+ mobile, and never infer publication from an upstream `ahead` count. Fetch follows
95
+ the selected upstream while push routing remains independent. VS Code does not
96
+ mount these Git panels and keeps its separate extension-host Git implementation.
97
+
84
98
  ### Log Operations
85
99
  - `getLog(directory, options)`: Get commit history with stats (supports maxCount, from, to, file filters).
86
100
  - `getCommitFiles(directory, commitHash)`: Get file changes for a specific commit relative to its first parent, or the empty tree for a root commit. NUL-delimited paths preserve whitespace; renamed files return their destination in `path` and source in `previousPath`.
@@ -108,7 +122,7 @@ bootstrap, tracking is left unset rather than writing `branch.*.remote` /
108
122
 
109
123
  The following functions are internal helpers used by exported functions:
110
124
  - `buildSshCommand(sshKeyPath)`: Build SSH command string for git config.
111
- - `buildGitEnv()`: Build Git environment with SSH_AUTH_SOCK resolution.
125
+ - `buildGitEnv()`: Build Git environment with SSH_AUTH_SOCK resolution and `GIT_TERMINAL_PROMPT=0` (unless the server was started with it set): the server has no terminal a user could answer, so a Git command that would ask for a username or password fails instead of waiting forever on a console nobody sees. Credential helpers, including GUI ones, still run before Git would prompt.
112
126
  - `createGit(directory)`: Create simple-git instance with environment.
113
127
  - `normalizeDirectoryPath(value)`: Normalize directory paths (supports ~ expansion).
114
128
  - `cleanBranchName(branch)`: Remove refs/heads/ or refs/ prefixes.
@@ -130,7 +144,7 @@ The following functions are internal helpers used by exported functions:
130
144
  - `upstreamComparison`: Optional comparison against `upstream/<current-branch>`, with `{ remote, branch, ahead, behind }`.
131
145
  - `files`: Array of file objects with `path`, `index`, `working_dir` status codes.
132
146
  - `isClean`: Boolean indicating if working tree is clean.
133
- - `diffStats`: Object mapping file paths to `{ insertions, deletions }`.
147
+ - `diffStats`: Scope-aware per-file line stats, `{ staged, working }`. `staged` is HEAD → index (`git diff --cached --numstat`), `working` is index → working tree (`git diff --numstat`). A partially staged file appears in both maps with its own scope's counts; the two are never summed together. Untracked and working-tree-added files are counted into `working`; files added to the index are counted into `staged`.
134
148
  - `mergeInProgress`: Object with `{ head, message }` if merge in progress.
135
149
  - `rebaseInProgress`: Object with `{ headName, onto }` if rebase in progress.
136
150
 
@@ -166,6 +180,7 @@ The following functions are internal helpers used by exported functions:
166
180
  surface and VS Code does not mount these controls.
167
181
  - Untracked patches from `getDiff` and `getUntrackedDiffs` use `git diff --no-index` with separate stdout, stderr, and process exit status. Exit codes 0 and 1 return stdout only, so line-ending warnings never become patch text or request failures. Other exits and process failures reject the single-file request; the batch keeps an empty entry for the failed path and preserves the other results.
168
182
  - `status.files` exposes both `index` and `working_dir` codes. Shared UI uses these as separate scopes: staged rows are derived from non-empty `index` statuses, while unstaged rows are derived from `working_dir` statuses and untracked files.
183
+ - `status.diffStats` follows the same scopes (`staged`, `working`), so a staged row shows HEAD → index counts and an unstaged row shows index → working-tree counts. A file with edits in both scopes reports each part in its own row instead of one combined total.
169
184
  - A file with both staged and unstaged changes can appear in both UI sections. Staged rows request diffs with `staged: true`; unstaged rows request normal working-tree diffs.
170
185
  - The shared Git panel exposes explicit staging actions. Unstaged rows use `stageFile`, staged rows use `unstageFile`, and commits operate on the current staged index.
171
186
  - `stageFiles` remains supported for callers that need to stage a selected unstaged subset as part of commit. In that mode the server temporarily unstages unrelated index entries, stages `stageFiles`, commits from the index, then restores temporarily unstaged entries.
@@ -10,6 +10,16 @@ export function registerGitRoutes(app, { emitWorktreeChanged } = {}) {
10
10
  return gitLibraries;
11
11
  };
12
12
 
13
+ // A path from an earlier status listing that no longer resolves is a stale
14
+ // row or a nested repository, not a server fault.
15
+ const GIT_PATH_ERROR_STATUS = new Map([['path_not_found', 404], ['nested_repository', 422], ['untracked_directory', 422]]);
16
+ const sendGitPathError = (res, error) => {
17
+ const status = GIT_PATH_ERROR_STATUS.get(error?.code);
18
+ if (!status) return false;
19
+ res.status(status).json({ error: error.message, code: error.code });
20
+ return true;
21
+ };
22
+
13
23
  const resolveDirectoryQuery = (value, preserveWhitespace = false) => {
14
24
  const raw = Array.isArray(value) ? value[0] : value;
15
25
  if (typeof raw !== 'string') {
@@ -345,7 +355,7 @@ export function registerGitRoutes(app, { emitWorktreeChanged } = {}) {
345
355
  });
346
356
 
347
357
  app.get('/api/git/diff', async (req, res) => {
348
- const { getDiff } = await getGitLibraries();
358
+ const { getPathDiff } = await getGitLibraries();
349
359
  try {
350
360
  const directory = req.query.directory;
351
361
  if (!directory) {
@@ -360,14 +370,15 @@ export function registerGitRoutes(app, { emitWorktreeChanged } = {}) {
360
370
  const staged = req.query.staged === 'true';
361
371
  const context = req.query.context ? parseInt(String(req.query.context), 10) : undefined;
362
372
 
363
- const diff = await getDiff(directory, {
373
+ const { diff, submodule } = await getPathDiff(directory, {
364
374
  path,
365
375
  staged,
366
376
  contextLines: Number.isFinite(context) ? context : 3,
367
377
  });
368
378
 
369
- res.json({ diff });
379
+ res.json({ diff, submodule });
370
380
  } catch (error) {
381
+ if (sendGitPathError(res, error)) return;
371
382
  console.error('Failed to get git diff:', error);
372
383
  res.status(500).json({ error: error.message || 'Failed to get git diff' });
373
384
  }
@@ -398,8 +409,10 @@ export function registerGitRoutes(app, { emitWorktreeChanged } = {}) {
398
409
  modified: result.modified,
399
410
  path: result.path,
400
411
  isBinary: Boolean(result.isBinary),
412
+ submodule: result.submodule ?? null,
401
413
  });
402
414
  } catch (error) {
415
+ if (sendGitPathError(res, error)) return;
403
416
  console.error('Failed to get git file diff:', error);
404
417
  res.status(500).json({ error: error.message || 'Failed to get git file diff' });
405
418
  }
@@ -0,0 +1,93 @@
1
+ // Runs one refresh per key at a time and bounds how many keys refresh at once.
2
+ //
3
+ // A request that arrives while a refresh for its key is running does not join
4
+ // that run: the run may have read the working tree before the change the
5
+ // caller just made. Instead the request waits for one follow-up run that starts
6
+ // after the current one finishes, so every caller receives a result at least as
7
+ // fresh as its own arrival. All requests that arrive during one run share the
8
+ // same follow-up, which caps the work per key at "one running, one pending"
9
+ // no matter how many callers ask.
10
+
11
+ export function createSerialRefresh({ maxConcurrent = Number.POSITIVE_INFINITY } = {}) {
12
+ const runs = new Map();
13
+ let running = 0;
14
+ const waiting = [];
15
+
16
+ const acquire = () => new Promise((resolve) => {
17
+ if (running < maxConcurrent) {
18
+ running += 1;
19
+ resolve();
20
+ return;
21
+ }
22
+ waiting.push(resolve);
23
+ });
24
+
25
+ const release = () => {
26
+ const next = waiting.shift();
27
+ if (next) {
28
+ next();
29
+ return;
30
+ }
31
+ running -= 1;
32
+ };
33
+
34
+ const start = (key, requests, execute, deferred) => {
35
+ const run = { follower: null };
36
+ runs.set(key, run);
37
+ const promise = (async () => {
38
+ await acquire();
39
+ try {
40
+ return await execute(requests);
41
+ } finally {
42
+ release();
43
+ }
44
+ })();
45
+ if (deferred) {
46
+ promise.then(deferred.resolve, deferred.reject);
47
+ }
48
+ promise
49
+ .catch(() => undefined)
50
+ .then(() => {
51
+ if (runs.get(key) !== run) return;
52
+ if (run.follower) {
53
+ const follower = run.follower;
54
+ start(key, follower.requests, follower.execute, follower);
55
+ return;
56
+ }
57
+ runs.delete(key);
58
+ });
59
+ return promise;
60
+ };
61
+
62
+ return {
63
+ /**
64
+ * @template TRequest, TResult
65
+ * @param {string} key
66
+ * @param {TRequest} request
67
+ * @param {(requests: TRequest[]) => Promise<TResult>} execute receives every
68
+ * request the run answers, so it can widen the work to satisfy all of them
69
+ * @returns {Promise<TResult>}
70
+ */
71
+ run(key, request, execute) {
72
+ const current = runs.get(key);
73
+ if (!current) {
74
+ return start(key, [request], execute);
75
+ }
76
+ if (!current.follower) {
77
+ let resolve;
78
+ let reject;
79
+ const promise = new Promise((res, rej) => {
80
+ resolve = res;
81
+ reject = rej;
82
+ });
83
+ current.follower = { requests: [], execute, promise, resolve, reject };
84
+ }
85
+ current.follower.requests.push(request);
86
+ return current.follower.promise;
87
+ },
88
+ /** Keys with a running or pending refresh. Exposed for tests. */
89
+ get activeKeys() {
90
+ return Array.from(runs.keys());
91
+ },
92
+ };
93
+ }
@@ -0,0 +1,112 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createSerialRefresh } from './serial-refresh.js';
3
+
4
+ const createGate = () => {
5
+ let release;
6
+ const opened = new Promise((resolve) => {
7
+ release = resolve;
8
+ });
9
+ return { opened, release };
10
+ };
11
+
12
+ const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
13
+
14
+ describe('createSerialRefresh', () => {
15
+ it('runs one refresh per key and answers later callers with one follow-up run', async () => {
16
+ const refresh = createSerialRefresh();
17
+ const gates = [createGate(), createGate()];
18
+ const executions = [];
19
+ const execute = async (requests) => {
20
+ const index = executions.length;
21
+ executions.push(requests);
22
+ await gates[index].opened;
23
+ return `run-${index}`;
24
+ };
25
+
26
+ const first = refresh.run('repo', 'a', execute);
27
+ await flush();
28
+ const second = refresh.run('repo', 'b', execute);
29
+ const third = refresh.run('repo', 'c', execute);
30
+ await flush();
31
+
32
+ expect(executions).toEqual([['a']]);
33
+
34
+ gates[0].release();
35
+ await expect(first).resolves.toBe('run-0');
36
+ await flush();
37
+ expect(executions).toEqual([['a'], ['b', 'c']]);
38
+
39
+ gates[1].release();
40
+ await expect(second).resolves.toBe('run-1');
41
+ await expect(third).resolves.toBe('run-1');
42
+ await flush();
43
+ expect(refresh.activeKeys).toEqual([]);
44
+ });
45
+
46
+ it('never serves a caller from a run that started before it asked', async () => {
47
+ const refresh = createSerialRefresh();
48
+ const gate = createGate();
49
+ let reads = 0;
50
+ const execute = async () => {
51
+ reads += 1;
52
+ const value = reads;
53
+ if (value === 1) await gate.opened;
54
+ return value;
55
+ };
56
+
57
+ const early = refresh.run('repo', null, execute);
58
+ await flush();
59
+ const late = refresh.run('repo', null, execute);
60
+ gate.release();
61
+
62
+ await expect(early).resolves.toBe(1);
63
+ await expect(late).resolves.toBe(2);
64
+ });
65
+
66
+ it('keeps keys independent and bounds how many run at once', async () => {
67
+ const refresh = createSerialRefresh({ maxConcurrent: 2 });
68
+ const gates = new Map();
69
+ const started = [];
70
+ const execute = (key) => async () => {
71
+ started.push(key);
72
+ const gate = createGate();
73
+ gates.set(key, gate);
74
+ await gate.opened;
75
+ return key;
76
+ };
77
+
78
+ const runs = ['a', 'b', 'c'].map((key) => refresh.run(key, null, execute(key)));
79
+ await flush();
80
+ expect(started).toEqual(['a', 'b']);
81
+
82
+ gates.get('a').release();
83
+ await flush();
84
+ expect(started).toEqual(['a', 'b', 'c']);
85
+
86
+ gates.get('b').release();
87
+ gates.get('c').release();
88
+ await expect(Promise.all(runs)).resolves.toEqual(['a', 'b', 'c']);
89
+ });
90
+
91
+ it('propagates a failed run to its callers and still runs the follow-up', async () => {
92
+ const refresh = createSerialRefresh();
93
+ const gate = createGate();
94
+ let calls = 0;
95
+ const execute = async () => {
96
+ calls += 1;
97
+ if (calls === 1) {
98
+ await gate.opened;
99
+ throw new Error('first failed');
100
+ }
101
+ return 'ok';
102
+ };
103
+
104
+ const first = refresh.run('repo', null, execute);
105
+ await flush();
106
+ const second = refresh.run('repo', null, execute);
107
+ gate.release();
108
+
109
+ await expect(first).rejects.toThrow('first failed');
110
+ await expect(second).resolves.toBe('ok');
111
+ });
112
+ });