@openchamber/web 1.22.1 → 1.23.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 (205) hide show
  1. package/bin/cli.js +11 -1
  2. package/bin/cli.test.js +92 -0
  3. package/bin/lib/cli-startup.js +49 -0
  4. package/bin/lib/commands-startup.js +41 -6
  5. package/dist/assets/{CodeMirrorCommentWidgets-BO_2OW4E.js → CodeMirrorCommentWidgets-DbcnxAfY.js} +1 -1
  6. package/dist/assets/DiffView-Dp1tomqK.js +4 -0
  7. package/dist/assets/{DirtyBranchSwitchDialog-jADfXQnR.js → DirtyBranchSwitchDialog-DE2sKIYv.js} +1 -1
  8. package/dist/assets/FilesView-C_of2nIT.js +17 -0
  9. package/dist/assets/{GitView-Cv2xH-S6.js → GitView-CKgUkb5Z.js} +4 -4
  10. package/dist/assets/{JsonTreeView-DUiIpERC.js → JsonTreeView-Bce2ettZ.js} +1 -1
  11. package/dist/assets/{LinearIssuesView-CoZ7pQN5.js → LinearIssuesView-BZVWM2zw.js} +1 -1
  12. package/dist/assets/MarkdownImageGallery-DdROVz29.js +1 -0
  13. package/dist/assets/MarkdownRendererImpl-CenrzmMN.js +12 -0
  14. package/dist/assets/OnboardingScreen-DyqYG_NP.js +1 -0
  15. package/dist/assets/{PatchDiff-BymkP9JA.js → PatchDiff-CR3RVO5I.js} +1 -1
  16. package/dist/assets/PierreDiffViewer-KihzO94X.js +161 -0
  17. package/dist/assets/PlanView-jcQAfr2A.js +5 -0
  18. package/dist/assets/SettingsView-Buvom5A2.js +28 -0
  19. package/dist/assets/{SettingsWindow-COzgfFxM.js → SettingsWindow-CV_hzB5v.js} +1 -1
  20. package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
  21. package/dist/assets/{ToolOutputDialog-Dlhh_-oe.js → ToolOutputDialog-llKecK_Z.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-b9joNtXH.js → ToolPartDiffPreview-ZDMTdCGn.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-vqW3KKo5.js → VirtualizedFileDiff-ClvqQ4j0.js} +1 -1
  24. package/dist/assets/WalkthroughView-BgpSnSlU.js +4 -0
  25. package/dist/assets/{computeVirtualFileMetrics-DUnyszhW.js → computeVirtualFileMetrics-Nm5_wabb.js} +2 -2
  26. package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
  27. package/dist/assets/de-DTQDjaiv.js +10 -0
  28. package/dist/assets/es-SOCFd_r-.js +16 -0
  29. package/dist/assets/fr-CP6jqIzw.js +14 -0
  30. package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
  31. package/dist/assets/index-B68h5S5B.css +1 -0
  32. package/dist/assets/index-CRf2xk51.js +39 -0
  33. package/dist/assets/{index-DLiD86ge.js → index-Du9sZhDb.js} +1 -1
  34. package/dist/assets/{isDiffPlainText-TNageFjy.js → isDiffPlainText-EQERIius.js} +1 -1
  35. package/dist/assets/{isFilePlainText-JPmZOYSp.js → isFilePlainText-BCoVpkQy.js} +1 -1
  36. package/dist/assets/ja-BKfafwsD.js +16 -0
  37. package/dist/assets/ko-BA5xgCYp.js +16 -0
  38. package/dist/assets/main-BNiPEont.js +930 -0
  39. package/dist/assets/{main-DCB4JgVe.js → main-DPf32fO6.js} +2 -2
  40. package/dist/assets/markdownCore-CQ7CAuuV.js +5 -0
  41. package/dist/assets/{miniChat-BtV7N5OF.js → miniChat-CHqVTsgj.js} +2 -2
  42. package/dist/assets/{mobile-DZV_sfX7.js → mobile-BQmgHA57.js} +2 -2
  43. package/dist/assets/patchFileDiff-C4X_trug.js +13 -0
  44. package/dist/assets/pl-B215pG1Y.js +16 -0
  45. package/dist/assets/pt-BR-Bo2pnlEa.js +16 -0
  46. package/dist/assets/renderElectronMiniChatApp-BUcHPOXW.js +2 -0
  47. package/dist/assets/renderMobileApp-BvTmuRE-.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-C8GAA2kS.js +17 -0
  49. package/dist/assets/scheduledTasksApi-BAScWwt3.js +1 -0
  50. package/dist/assets/{shikiHighlight-CRpCl7UT.js → shikiHighlight-BTObuQCR.js} +1 -1
  51. package/dist/assets/surface-BvRzS58U.js +1 -0
  52. package/dist/assets/tr-CUaxHc8X.js +7 -0
  53. package/dist/assets/uk-YTJgyqAZ.js +16 -0
  54. package/dist/assets/{useAppFontEffects-CCgvcQ6u.js → useAppFontEffects-theH_IJL.js} +143 -137
  55. package/dist/assets/useGitComparison-B94I6kOI.js +1 -0
  56. package/dist/assets/useInlineCommentController-Bs3PgeA8.js +2 -0
  57. package/dist/assets/useRootScrollLock-hSYwnxZs.js +1 -0
  58. package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-language-data-BxpoC5Fp.js → vendor-codemirror-language-data-Cxgr01md.js} +2 -2
  60. package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
  61. package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
  62. package/dist/assets/{web-components-B6QgbmTo.js → web-components-CaS0ksnZ.js} +1 -1
  63. package/dist/assets/zh-CN-CZ2BxZS6.js +16 -0
  64. package/dist/assets/zh-TW-BsUrPdXz.js +16 -0
  65. package/dist/index.html +5 -43
  66. package/dist/mini-chat.html +4 -4
  67. package/dist/mobile.html +4 -4
  68. package/package.json +3 -4
  69. package/server/index.d.ts +15 -0
  70. package/server/index.js +52 -10
  71. package/server/lib/changelog/update-notes.js +82 -0
  72. package/server/lib/changelog/update-notes.test.js +59 -0
  73. package/server/lib/data-dir-migration.js +40 -0
  74. package/server/lib/data-dir-migration.test.js +59 -0
  75. package/server/lib/event-stream/runtime.test.js +12 -12
  76. package/server/lib/fs/DOCUMENTATION.md +5 -0
  77. package/server/lib/fs/routes.js +63 -21
  78. package/server/lib/fs/routes.test.js +187 -1
  79. package/server/lib/git/DOCUMENTATION.md +29 -5
  80. package/server/lib/git/routes.js +24 -4
  81. package/server/lib/git/service.js +194 -198
  82. package/server/lib/git/service.test.js +440 -25
  83. package/server/lib/inherited-env.js +16 -9
  84. package/server/lib/inherited-env.test.js +8 -9
  85. package/server/lib/message-queue/DOCUMENTATION.md +20 -7
  86. package/server/lib/message-queue/runtime.js +59 -7
  87. package/server/lib/message-queue/runtime.test.js +59 -3
  88. package/server/lib/network-defaults.js +23 -0
  89. package/server/lib/network-defaults.test.js +52 -0
  90. package/server/lib/opencode/DOCUMENTATION.md +25 -5
  91. package/server/lib/opencode/bootstrap-runtime.js +2 -0
  92. package/server/lib/opencode/config-paths.test.js +116 -0
  93. package/server/lib/opencode/feature-routes-runtime.js +4 -0
  94. package/server/lib/opencode/input-history-scope.js +14 -0
  95. package/server/lib/opencode/openchamber-routes.js +64 -4
  96. package/server/lib/opencode/openchamber-routes.test.js +128 -1
  97. package/server/lib/opencode/plugins.js +2 -2
  98. package/server/lib/opencode/providers.js +44 -2
  99. package/server/lib/opencode/providers.test.js +131 -4
  100. package/server/lib/opencode/routes.js +9 -7
  101. package/server/lib/opencode/server-startup-runtime.js +1 -1
  102. package/server/lib/opencode/settings-files.js +214 -0
  103. package/server/lib/opencode/settings-helpers.js +113 -41
  104. package/server/lib/opencode/settings-helpers.test.js +342 -0
  105. package/server/lib/opencode/settings-registry.json +747 -0
  106. package/server/lib/opencode/settings-runtime.js +139 -18
  107. package/server/lib/opencode/settings-runtime.test.js +163 -5
  108. package/server/lib/opencode/shared.js +4 -1
  109. package/server/lib/opencode/skill-routes.js +2 -1
  110. package/server/lib/opencode/snippets.js +1 -2
  111. package/server/lib/package-manager.js +3 -28
  112. package/server/lib/project-context/DOCUMENTATION.md +25 -1
  113. package/server/lib/project-context/routes.http.test.js +18 -0
  114. package/server/lib/project-context/routes.js +15 -0
  115. package/server/lib/project-context/runtime.js +248 -23
  116. package/server/lib/project-context/runtime.test.js +106 -3
  117. package/server/lib/projects/DOCUMENTATION.md +76 -0
  118. package/server/lib/projects/project-config.js +142 -9
  119. package/server/lib/projects/project-id.js +17 -0
  120. package/server/lib/projects/project-setup.js +409 -0
  121. package/server/lib/projects/project-setup.test.js +557 -0
  122. package/server/lib/projects/routes.js +59 -0
  123. package/server/lib/quota/DOCUMENTATION.md +38 -1
  124. package/server/lib/quota/index.js +1 -0
  125. package/server/lib/quota/providers/cline-pass.js +125 -0
  126. package/server/lib/quota/providers/cline-pass.test.js +103 -0
  127. package/server/lib/quota/providers/hyper.js +118 -0
  128. package/server/lib/quota/providers/hyper.test.js +126 -0
  129. package/server/lib/quota/providers/index.js +15 -0
  130. package/server/lib/quota/providers/neuralwatt.js +3 -6
  131. package/server/lib/quota/providers/neuralwatt.test.js +7 -7
  132. package/server/lib/quota/providers/ollama-cloud.js +31 -0
  133. package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
  134. package/server/lib/quota/providers/opencode-go.js +1 -1
  135. package/server/lib/quota/providers/opencode-go.test.js +26 -1
  136. package/server/lib/quota/providers/openrouter.js +119 -24
  137. package/server/lib/quota/providers/openrouter.test.js +330 -0
  138. package/server/lib/quota/utils/auth.js +1 -1
  139. package/server/lib/relay/DOCUMENTATION.md +55 -0
  140. package/server/lib/relay/cross-compat.test.js +26 -0
  141. package/server/lib/relay/downstream-scheduler.js +154 -0
  142. package/server/lib/relay/downstream-scheduler.test.js +162 -0
  143. package/server/lib/relay/e2ee.js +10 -8
  144. package/server/lib/relay/flow-control.test.js +177 -0
  145. package/server/lib/relay/host-client.js +37 -8
  146. package/server/lib/relay/host-client.test.js +9 -1
  147. package/server/lib/relay/tunnel-codec.js +9 -0
  148. package/server/lib/relay/tunnel-host.js +66 -17
  149. package/server/lib/session-assist/runtime.js +6 -10
  150. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  151. package/server/lib/session-goal/runtime.js +80 -20
  152. package/server/lib/session-goal/runtime.test.js +426 -0
  153. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  154. package/server/lib/skills-catalog/install.js +3 -2
  155. package/server/lib/small-model/DOCUMENTATION.md +3 -2
  156. package/server/lib/small-model/call.js +9 -4
  157. package/server/lib/small-model/call.test.js +29 -0
  158. package/server/lib/small-model/index.js +5 -10
  159. package/server/lib/small-model/runtime-providers.js +15 -7
  160. package/server/lib/small-model/runtime-providers.test.js +7 -1
  161. package/server/lib/terminal/DOCUMENTATION.md +14 -10
  162. package/server/lib/terminal/runtime.js +160 -24
  163. package/server/lib/terminal/runtime.test.js +571 -37
  164. package/server/lib/terminal/shells.js +17 -0
  165. package/server/lib/terminal/shells.test.js +32 -1
  166. package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
  167. package/server/lib/walkthrough/model-settings.js +8 -12
  168. package/server/lib/walkthrough/prompt.js +3 -1
  169. package/server/lib/walkthrough/routes.test.js +26 -5
  170. package/server/lib/walkthrough/sources.js +23 -2
  171. package/dist/assets/DiffView-CNnDxRmO.js +0 -4
  172. package/dist/assets/FilesView-8wdiG2mj.js +0 -17
  173. package/dist/assets/MarkdownImageGallery-DffjmciG.js +0 -1
  174. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +0 -12
  175. package/dist/assets/OnboardingScreen-CTZe6HZn.js +0 -1
  176. package/dist/assets/PierreDiffViewer-BvwtCxW4.js +0 -157
  177. package/dist/assets/PlanView-C1qvAm7m.js +0 -5
  178. package/dist/assets/SettingsView-xGONHFGS.js +0 -28
  179. package/dist/assets/WalkthroughView-D-HFgdmM.js +0 -4
  180. package/dist/assets/contextPanelEmbeddedChat-CV-DwAiX.js +0 -1
  181. package/dist/assets/de-Cv_4FoXm.js +0 -10
  182. package/dist/assets/es-BIWNEbnS.js +0 -16
  183. package/dist/assets/fr-SD3OfMHJ.js +0 -14
  184. package/dist/assets/index-CHUT_bDS.css +0 -1
  185. package/dist/assets/index-DDInLQDd.js +0 -40
  186. package/dist/assets/ja-D7I9HofF.js +0 -16
  187. package/dist/assets/ko-BsVJM_PQ.js +0 -16
  188. package/dist/assets/main-De8Z5w49.js +0 -928
  189. package/dist/assets/markdownCore-BoQVG5-a.js +0 -3
  190. package/dist/assets/patchFileDiff-Chmiz6hq.js +0 -10
  191. package/dist/assets/pl-XR9Bs8Be.js +0 -16
  192. package/dist/assets/pt-BR-Due4be8g.js +0 -16
  193. package/dist/assets/renderElectronMiniChatApp-8tXADjfl.js +0 -2
  194. package/dist/assets/renderMobileApp-Cji7Hma5.js +0 -25
  195. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +0 -16
  196. package/dist/assets/scheduledTasksApi-9e-UX6im.js +0 -1
  197. package/dist/assets/tr-DBJcAv4y.js +0 -7
  198. package/dist/assets/uk-COYh2BaN.js +0 -16
  199. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +0 -2
  200. package/dist/assets/useRootScrollLock-KzOUytpn.js +0 -1
  201. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
  202. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
  203. package/dist/assets/vendor-zod-DVWEh-IS.js +0 -39
  204. package/dist/assets/zh-CN-Cjk6lzhc.js +0 -16
  205. package/dist/assets/zh-TW-Dk0dOg03.js +0 -16
@@ -196,7 +196,7 @@ const isPathWithinRoot = (resolvedPath, rootPath, path, os) => {
196
196
  return true;
197
197
  };
198
198
 
199
- const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDirectoryPath, openchamberUserConfigRoot }) => {
199
+ const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDirectoryPath, managedRoots }) => {
200
200
  const normalized = normalizeDirectoryPath(targetPath);
201
201
  if (!normalized || typeof normalized !== 'string') {
202
202
  return { ok: false, error: 'Path is required' };
@@ -209,8 +209,12 @@ const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDi
209
209
  return { ok: true, base: resolvedBase, resolved };
210
210
  }
211
211
 
212
- if (isPathWithinRoot(resolved, openchamberUserConfigRoot, path, os)) {
213
- return { ok: true, base: path.resolve(openchamberUserConfigRoot), resolved };
212
+ // Managed roots (config root, relocated chats root) stay valid targets
213
+ // even outside the active workspace.
214
+ for (const root of managedRoots) {
215
+ if (isPathWithinRoot(resolved, root, path, os)) {
216
+ return { ok: true, base: path.resolve(root), resolved };
217
+ }
214
218
  }
215
219
 
216
220
  return { ok: false, error: 'Path is outside of active workspace' };
@@ -249,7 +253,7 @@ const resolveWorkspacePathFromWorktrees = async ({ targetPath, baseDirectory, pa
249
253
  return { ok: false, error: 'Path is outside of active workspace' };
250
254
  };
251
255
 
252
- const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProjectDirectory, path, os, normalizeDirectoryPath, openchamberUserConfigRoot }) => {
256
+ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProjectDirectory, path, os, normalizeDirectoryPath, managedRoots }) => {
253
257
  const resolvedProject = await resolveProjectDirectory(req);
254
258
  if (!resolvedProject.directory) {
255
259
  return { ok: false, error: resolvedProject.error || 'Active workspace is required' };
@@ -261,7 +265,7 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
261
265
  path,
262
266
  os,
263
267
  normalizeDirectoryPath,
264
- openchamberUserConfigRoot,
268
+ managedRoots,
265
269
  });
266
270
  if (resolved.ok || resolved.error !== 'Path is outside of active workspace') {
267
271
  return resolved;
@@ -281,7 +285,7 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
281
285
  path,
282
286
  os,
283
287
  normalizeDirectoryPath,
284
- openchamberUserConfigRoot,
288
+ managedRoots,
285
289
  });
286
290
  if (lexical.ok) {
287
291
  return lexical;
@@ -412,7 +416,7 @@ const escapeCloneSshKeyPath = (sshKeyPath) => {
412
416
  return `'${normalized.replace(/'/g, "'\\''")}'`;
413
417
  };
414
418
 
415
- const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProjectDirectory, path, os, fsPromises, normalizeDirectoryPath, openchamberUserConfigRoot }) => {
419
+ const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProjectDirectory, path, os, fsPromises, normalizeDirectoryPath, managedRoots }) => {
416
420
  if (req.query?.allowOutsideWorkspace === 'true') {
417
421
  const normalized = normalizeDirectoryPath(targetPath);
418
422
  if (!normalized || typeof normalized !== 'string') {
@@ -434,7 +438,7 @@ const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProje
434
438
  path,
435
439
  os,
436
440
  normalizeDirectoryPath,
437
- openchamberUserConfigRoot,
441
+ managedRoots,
438
442
  });
439
443
  };
440
444
 
@@ -520,7 +524,14 @@ export const registerFsRoutes = (app, dependencies) => {
520
524
  buildAugmentedPath,
521
525
  resolveGitBinaryForSpawn,
522
526
  openchamberUserConfigRoot,
527
+ managedChatsRoot,
523
528
  } = dependencies;
529
+ // Chat worktrees may live outside every project workspace; both managed
530
+ // roots stay valid filesystem targets.
531
+ const chatsRoot = typeof managedChatsRoot === 'string' && managedChatsRoot.trim()
532
+ ? path.resolve(managedChatsRoot.trim())
533
+ : path.join(openchamberUserConfigRoot, 'chats');
534
+ const managedRoots = [path.resolve(openchamberUserConfigRoot), chatsRoot];
524
535
  const realpathCache = createRealpathCache({
525
536
  realpath: fsPromises.realpath.bind(fsPromises),
526
537
  });
@@ -699,7 +710,7 @@ export const registerFsRoutes = (app, dependencies) => {
699
710
  if (!home || typeof home !== 'string' || home.length === 0) {
700
711
  return res.status(500).json({ error: 'Failed to resolve home directory' });
701
712
  }
702
- return res.json({ home });
713
+ return res.json({ home, chatsRoot });
703
714
  } catch (error) {
704
715
  console.error('Failed to resolve home directory:', error);
705
716
  return res.status(500).json({ error: (error && error.message) || 'Failed to resolve home directory' });
@@ -725,7 +736,7 @@ export const registerFsRoutes = (app, dependencies) => {
725
736
  path,
726
737
  os,
727
738
  normalizeDirectoryPath,
728
- openchamberUserConfigRoot,
739
+ managedRoots,
729
740
  });
730
741
  if (!resolved.ok) {
731
742
  return res.status(400).json({ error: resolved.error });
@@ -853,6 +864,37 @@ export const registerFsRoutes = (app, dependencies) => {
853
864
  }
854
865
  });
855
866
 
867
+ app.get('/api/fs/directory-stat', async (req, res) => {
868
+ res.setHeader('Cache-Control', 'no-store');
869
+ const paths = new URL(req.url, 'http://openchamber.local').searchParams.getAll('path');
870
+ const directoryPath = paths.length === 1 ? paths[0].trim() : '';
871
+ if (!directoryPath) {
872
+ return res.status(400).json({ error: 'Path is required' });
873
+ }
874
+
875
+ try {
876
+ // Directory discovery uses the same path policy as /api/fs/list, including
877
+ // paths outside the current workspace. stat follows symlinks without readdir.
878
+ const resolvedPath = path.resolve(normalizeDirectoryPath(directoryPath));
879
+ const stats = await fsPromises.stat(resolvedPath);
880
+ if (!stats.isDirectory()) {
881
+ return res.status(400).json({ error: 'Specified path is not a directory', reason: 'not-directory' });
882
+ }
883
+ return res.json({ isDirectory: true });
884
+ } catch (error) {
885
+ if (error.code === 'ENOENT' || error.code === 'ENOTDIR') {
886
+ return res.status(error.code === 'ENOENT' ? 404 : 400).json({
887
+ error: error.code === 'ENOENT' ? 'Directory not found' : 'Specified path is not a directory',
888
+ reason: error.code === 'ENOENT' ? 'not-found' : 'not-directory',
889
+ });
890
+ }
891
+ if (isOsPermissionError(error)) {
892
+ return sendOsPermissionDenied(res, 'Access to directory denied');
893
+ }
894
+ return res.status(500).json({ error: 'Failed to stat directory' });
895
+ }
896
+ });
897
+
856
898
  app.get('/api/fs/stat', async (req, res) => {
857
899
  const filePath = typeof req.query.path === 'string' ? req.query.path.trim() : '';
858
900
  const optional = req.query.optional === 'true';
@@ -870,7 +912,7 @@ export const registerFsRoutes = (app, dependencies) => {
870
912
  os,
871
913
  fsPromises,
872
914
  normalizeDirectoryPath,
873
- openchamberUserConfigRoot,
915
+ managedRoots,
874
916
  });
875
917
  if (!resolved.ok) {
876
918
  if (req.query?.allowOutsideWorkspace === 'true') {
@@ -920,7 +962,7 @@ export const registerFsRoutes = (app, dependencies) => {
920
962
  os,
921
963
  fsPromises,
922
964
  normalizeDirectoryPath,
923
- openchamberUserConfigRoot,
965
+ managedRoots,
924
966
  });
925
967
  if (!resolved.ok) {
926
968
  if (req.query?.allowOutsideWorkspace === 'true') {
@@ -984,7 +1026,7 @@ export const registerFsRoutes = (app, dependencies) => {
984
1026
  os,
985
1027
  fsPromises,
986
1028
  normalizeDirectoryPath,
987
- openchamberUserConfigRoot,
1029
+ managedRoots,
988
1030
  });
989
1031
  if (!resolved.ok) {
990
1032
  if (req.query?.allowOutsideWorkspace === 'true') {
@@ -1065,7 +1107,7 @@ export const registerFsRoutes = (app, dependencies) => {
1065
1107
  path,
1066
1108
  os,
1067
1109
  normalizeDirectoryPath,
1068
- openchamberUserConfigRoot,
1110
+ managedRoots,
1069
1111
  });
1070
1112
  if (!resolved.ok) {
1071
1113
  return res.status(400).json({ error: resolved.error });
@@ -1117,7 +1159,7 @@ export const registerFsRoutes = (app, dependencies) => {
1117
1159
  path,
1118
1160
  os,
1119
1161
  normalizeDirectoryPath,
1120
- openchamberUserConfigRoot,
1162
+ managedRoots,
1121
1163
  });
1122
1164
  if (!resolved.ok) {
1123
1165
  return res.status(400).json({ error: resolved.error });
@@ -1187,7 +1229,7 @@ export const registerFsRoutes = (app, dependencies) => {
1187
1229
  path,
1188
1230
  os,
1189
1231
  normalizeDirectoryPath,
1190
- openchamberUserConfigRoot,
1232
+ managedRoots,
1191
1233
  });
1192
1234
  if (!resolved.ok) {
1193
1235
  return res.status(400).json({ error: resolved.error });
@@ -1294,7 +1336,7 @@ export const registerFsRoutes = (app, dependencies) => {
1294
1336
  path,
1295
1337
  os,
1296
1338
  normalizeDirectoryPath,
1297
- openchamberUserConfigRoot,
1339
+ managedRoots,
1298
1340
  });
1299
1341
  if (!resolved.ok) {
1300
1342
  return res.status(400).json({ error: resolved.error });
@@ -1332,7 +1374,7 @@ export const registerFsRoutes = (app, dependencies) => {
1332
1374
  path,
1333
1375
  os,
1334
1376
  normalizeDirectoryPath,
1335
- openchamberUserConfigRoot,
1377
+ managedRoots,
1336
1378
  });
1337
1379
  if (!resolvedOld.ok) {
1338
1380
  return res.status(400).json({ error: resolvedOld.error });
@@ -1345,7 +1387,7 @@ export const registerFsRoutes = (app, dependencies) => {
1345
1387
  path,
1346
1388
  os,
1347
1389
  normalizeDirectoryPath,
1348
- openchamberUserConfigRoot,
1390
+ managedRoots,
1349
1391
  });
1350
1392
  if (!resolvedNew.ok) {
1351
1393
  return res.status(400).json({ error: resolvedNew.error });
@@ -1451,7 +1493,7 @@ export const registerFsRoutes = (app, dependencies) => {
1451
1493
  path,
1452
1494
  os,
1453
1495
  normalizeDirectoryPath,
1454
- openchamberUserConfigRoot,
1496
+ managedRoots,
1455
1497
  });
1456
1498
  if (!resolvedForWorkspace.ok) {
1457
1499
  console.warn(`Rejected /api/fs/exec outside workspace: ${resolvedForWorkspace.error}`);
@@ -1689,7 +1731,7 @@ export const registerFsRoutes = (app, dependencies) => {
1689
1731
  path,
1690
1732
  os,
1691
1733
  normalizeDirectoryPath,
1692
- openchamberUserConfigRoot,
1734
+ managedRoots,
1693
1735
  });
1694
1736
  if (!resolved.ok) {
1695
1737
  return res.status(400).json({ error: resolved.error });
@@ -1,5 +1,9 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import path from 'path';
3
+ import { copyFile, mkdir, mkdtemp, rm } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { execFileSync } from 'node:child_process';
6
+ import { pathToFileURL } from 'node:url';
3
7
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
8
 
5
9
  import { mintOutsideFileGrant, registerFsRoutes } from './routes.js';
@@ -1385,7 +1389,11 @@ describe('fs stat directory scope (issue 3019)', () => {
1385
1389
  path: path.posix,
1386
1390
  fsPromises: {
1387
1391
  realpath: async (targetPath) => targetPath,
1388
- stat: async () => ({ isFile: () => true, size: 12 }),
1392
+ stat: async (targetPath) => (
1393
+ targetPath === '/repo-b'
1394
+ ? { isDirectory: () => true, mtimeMs: 123 }
1395
+ : { isFile: () => true, size: 12, mtimeMs: 456 }
1396
+ ),
1389
1397
  },
1390
1398
  spawn: vi.fn(),
1391
1399
  crypto: { randomUUID: () => 'job-0' },
@@ -1428,4 +1436,182 @@ describe('fs stat directory scope (issue 3019)', () => {
1428
1436
  expect(res.statusCode).toBe(200);
1429
1437
  expect(res.body.isFile).toBe(true);
1430
1438
  });
1439
+
1440
+ });
1441
+
1442
+ describe('fs stat directory error handling', () => {
1443
+ it('loads in Node without workspace node_modules, as packaged desktop does', async () => {
1444
+ const directory = await mkdtemp(path.join(tmpdir(), 'openchamber-fs-import-'));
1445
+ try {
1446
+ await mkdir(path.join(directory, 'fs'));
1447
+ await copyFile(new URL('./routes.js', import.meta.url), path.join(directory, 'fs/routes.mjs'));
1448
+ await copyFile(new URL('../path-realpath-cache.js', import.meta.url), path.join(directory, 'path-realpath-cache.js'));
1449
+ expect(() => execFileSync('node', [
1450
+ '--input-type=module',
1451
+ '--eval',
1452
+ 'await import(process.argv[1])',
1453
+ pathToFileURL(path.join(directory, 'fs/routes.mjs')).href,
1454
+ ], { cwd: directory, stdio: 'pipe' })).not.toThrow();
1455
+ } finally {
1456
+ await rm(directory, { recursive: true, force: true });
1457
+ }
1458
+ });
1459
+
1460
+ it('returns directory-missing reasons and permission errors for directory stat', async () => {
1461
+ const { app, getRoute } = createRouteRegistry();
1462
+ const enoent = Object.assign(new Error('missing'), { code: 'ENOENT' });
1463
+ const enotdir = Object.assign(new Error('not a directory'), { code: 'ENOTDIR' });
1464
+ const eacces = Object.assign(new Error('denied'), { code: 'EACCES' });
1465
+ const stat = vi.fn(async (targetPath) => {
1466
+ if (targetPath === '/repo-b') throw enoent;
1467
+ if (targetPath === '/repo-b/file.txt/child') throw enotdir;
1468
+ if (targetPath === '/repo-b/protected') throw eacces;
1469
+ if (targetPath === '/repo-b/file.txt') return { isDirectory: () => false };
1470
+ if (targetPath === '/repo-b/failure') throw new Error('unavailable');
1471
+ return { isDirectory: () => true, mtimeMs: 1 };
1472
+ });
1473
+ const readdir = vi.fn(async () => []);
1474
+ const callStat = async (handler, { headers = {}, query }) => {
1475
+ const res = createMockResponse();
1476
+ const req = {
1477
+ url: `/api/fs/directory-stat?${new URLSearchParams(query)}`,
1478
+ query,
1479
+ get: (name) => headers[name.toLowerCase()] ?? undefined,
1480
+ };
1481
+ await handler(req, res);
1482
+ return res;
1483
+ };
1484
+ registerFsRoutes(app, {
1485
+ os: { homedir: () => '/home/user' },
1486
+ path: path.posix,
1487
+ fsPromises: {
1488
+ realpath: async (targetPath) => targetPath,
1489
+ stat,
1490
+ readdir,
1491
+ },
1492
+ spawn: vi.fn(),
1493
+ crypto: { randomUUID: () => 'job-0' },
1494
+ normalizeDirectoryPath: (p) => p,
1495
+ resolveProjectDirectory: async () => ({ directory: '/repo' }),
1496
+ buildAugmentedPath: () => '/usr/bin',
1497
+ resolveGitBinaryForSpawn: () => 'git',
1498
+ openchamberUserConfigRoot: '/home/user/.config',
1499
+ });
1500
+ const handler = getRoute('GET', '/api/fs/directory-stat');
1501
+
1502
+ const available = await callStat(handler, { query: { path: '/other-project' } });
1503
+ expect(available.statusCode).toBe(200);
1504
+ expect(available.body).toEqual({ isDirectory: true });
1505
+ expect(available.getHeader('Cache-Control')).toBe('no-store');
1506
+ expect(stat).toHaveBeenCalledTimes(1);
1507
+
1508
+ const invalid = await callStat(handler, { query: { path: ' ' } });
1509
+ expect(invalid.statusCode).toBe(400);
1510
+ expect(stat).toHaveBeenCalledTimes(1);
1511
+
1512
+ for (const query of ['path=/repo&path=/other', 'path[]=/repo', '']) {
1513
+ const malformed = createMockResponse();
1514
+ await handler({ url: `/api/fs/directory-stat?${query}` }, malformed);
1515
+ expect(malformed.statusCode).toBe(400);
1516
+ }
1517
+ expect(stat).toHaveBeenCalledTimes(1);
1518
+
1519
+ const missing = await callStat(handler, { headers: { 'x-opencode-directory': '/repo-b' }, query: { path: '/repo-b', directory: 'true' } });
1520
+ expect(missing.statusCode).toBe(404);
1521
+ expect(missing.body).toEqual({ error: 'Directory not found', reason: 'not-found' });
1522
+
1523
+ const notDir = await callStat(handler, { headers: { 'x-opencode-directory': '/repo-b' }, query: { path: '/repo-b/file.txt/child', directory: 'true' } });
1524
+ expect(notDir.statusCode).toBe(400);
1525
+ expect(notDir.body).toEqual({ error: 'Specified path is not a directory', reason: 'not-directory' });
1526
+
1527
+ const denied = await callStat(handler, { headers: { 'x-opencode-directory': '/repo-b' }, query: { path: '/repo-b/protected', directory: 'true' } });
1528
+ expect(denied.statusCode).toBe(403);
1529
+ expect(denied.body).toEqual({ error: 'Access to directory denied', reason: 'os-permission' });
1530
+
1531
+ const file = await callStat(handler, { query: { path: '/repo-b/file.txt' } });
1532
+ expect(file.statusCode).toBe(400);
1533
+ expect(file.body.reason).toBe('not-directory');
1534
+
1535
+ const failure = await callStat(handler, { query: { path: '/repo-b/failure' } });
1536
+ expect(failure.statusCode).toBe(500);
1537
+ expect(failure.body).toEqual({ error: 'Failed to stat directory' });
1538
+ expect(readdir).not.toHaveBeenCalled();
1539
+ });
1540
+ });
1541
+
1542
+ describe('fs managed chats root', () => {
1543
+ const registerWithChatsRoot = ({ managedChatsRoot, fsPromises = {} } = {}) => {
1544
+ const { app, getRoute } = createRouteRegistry();
1545
+ registerFsRoutes(app, {
1546
+ os: { homedir: () => '/home/user' },
1547
+ path: path.posix,
1548
+ fsPromises: {
1549
+ realpath: async (targetPath) => targetPath,
1550
+ mkdir: async () => undefined,
1551
+ ...fsPromises,
1552
+ },
1553
+ spawn: vi.fn(),
1554
+ crypto: { randomUUID: () => 'job-0' },
1555
+ normalizeDirectoryPath: (p) => p,
1556
+ resolveProjectDirectory: async () => ({ directory: '/repo' }),
1557
+ buildAugmentedPath: () => '/usr/bin',
1558
+ resolveGitBinaryForSpawn: () => 'git',
1559
+ openchamberUserConfigRoot: '/home/user/.config/openchamber',
1560
+ managedChatsRoot,
1561
+ });
1562
+ return {
1563
+ home: getRoute('GET', '/api/fs/home'),
1564
+ mkdir: getRoute('POST', '/api/fs/mkdir'),
1565
+ };
1566
+ };
1567
+
1568
+ it('exposes the default chats root next to the home directory', async () => {
1569
+ const { home } = registerWithChatsRoot();
1570
+
1571
+ const res = createMockResponse();
1572
+ await home(undefined, res);
1573
+
1574
+ expect(res.statusCode).toBe(200);
1575
+ expect(res.body.home).toBe('/home/user');
1576
+ expect(res.body.chatsRoot).toBe('/home/user/.config/openchamber/chats');
1577
+ });
1578
+
1579
+ it('exposes a relocated chats root when OPENCHAMBER_CHATS_DIR is configured upstream', async () => {
1580
+ const { home } = registerWithChatsRoot({ managedChatsRoot: '/srv/openchamber-chats' });
1581
+
1582
+ const res = createMockResponse();
1583
+ await home(undefined, res);
1584
+
1585
+ expect(res.statusCode).toBe(200);
1586
+ expect(res.body.chatsRoot).toBe('/srv/openchamber-chats');
1587
+ });
1588
+
1589
+ it('allows mkdir inside the relocated chats root outside the active workspace', async () => {
1590
+ const mkdirCalls = [];
1591
+ const { mkdir } = registerWithChatsRoot({
1592
+ managedChatsRoot: '/srv/openchamber-chats',
1593
+ fsPromises: {
1594
+ mkdir: async (targetPath) => {
1595
+ mkdirCalls.push(targetPath);
1596
+ },
1597
+ },
1598
+ });
1599
+
1600
+ const res = createMockResponse();
1601
+ await mkdir({ body: { path: '/srv/openchamber-chats/2026-08-25/session-a' } }, res);
1602
+
1603
+ expect(res.statusCode).toBe(200);
1604
+ expect(res.body.success).toBe(true);
1605
+ expect(mkdirCalls).toEqual(['/srv/openchamber-chats/2026-08-25/session-a']);
1606
+ });
1607
+
1608
+ it('still rejects mkdir outside the workspace and all managed roots', async () => {
1609
+ const { mkdir } = registerWithChatsRoot({ managedChatsRoot: '/srv/openchamber-chats' });
1610
+
1611
+ const res = createMockResponse();
1612
+ await mkdir({ body: { path: '/etc/passwd-holder' } }, res);
1613
+
1614
+ expect(res.statusCode).toBe(400);
1615
+ expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
1616
+ });
1431
1617
  });
@@ -25,9 +25,11 @@ The following functions are exported and used by the web server:
25
25
 
26
26
  ### Status and Diff Operations
27
27
  - `getStatus(directory)`: Get comprehensive Git status including current branch, tracking, ahead/behind, file changes, diff stats, merge/rebase state.
28
- - `getDiff(directory, { path, staged, contextLines })`: Get diff output for files or entire working tree. Untracked symbolic links are represented as link entries without following their targets.
29
- - `getRangeDiff(directory, { base, head, path, contextLines })`: Get diff between two refs. Uses three-dot `base...head` semantics, so work merged into `head` from `base` is excluded and only the branch's own changes are returned. Prefers `origin/<base>` when that remote-tracking ref exists, so a stale local base branch does not resurface already-merged commits. Exposed as `GET /api/git/range-diff` (`path` optional; omit it for the whole range).
30
- - `getRangeFiles(directory, { base, head })`: Get list of changed files between two refs.
28
+ - `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.
29
+ - `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
+ - `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
+ - 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
+ - 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.
31
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).
32
34
  - `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.
33
35
  - `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.
@@ -35,9 +37,10 @@ The following functions are exported and used by the web server:
35
37
  - `revertFile(directory, filePath, options)`: Revert a file. Default scope `all` discards staged and working-tree changes; scope `working` discards only unstaged/working-tree changes.
36
38
  - `stageFile(directory, filePath)`: Add one file path to the index.
37
39
  - `unstageFile(directory, filePath)`: Remove one file path from the index while preserving working-tree content.
38
- - `applyHunk(directory, filePath, options)`: Apply a single-hunk patch via `git apply`. `options.action` is `stage` (`git apply --cached`), `unstage` (`git apply --cached --reverse`), or `discard` (`git apply --reverse` in the working tree). The patch is written to a temp file; a `--check` runs first so a stale hunk fails with a clear "refresh and try again" error instead of a partial mutation. The patch target path must match the requested file.
40
+ - `applyHunk(directory, filePath, options)`: Apply a single-hunk patch via `git apply`. `options.action` is `stage` (`git apply --cached`), `unstage` (`git apply --cached --reverse`), or `discard` (`git apply --reverse` in the working tree). Inside the index mutation queue, the server verifies that the complete patch exactly matches one current three-context-line hunk for that file and scope, then runs `--check` before applying. Applicability alone cannot prove an unstaged change: old staged or committed hunks can reverse cleanly too. Stale, historical and multi-file patches fail with a refresh error. Temporary patch files are removed on success and failure; hunk content retains CRLF bytes.
39
41
 
40
42
  ### Branch Operations
43
+ - `getBranchBase(directory, branch)`: Read a named creation source from reflog. After a rebase, the creation source is no longer a current parent record, so return `null` and let the user choose a base. Explicit per-runtime, directory, and branch choices in the shared UI outrank detection.
41
44
  - `getBranches(directory)`: Get list of local and remote branches (filtered to active remote branches).
42
45
  - `getUnpushedBranchCounts(directory, branchNames)`: Count commits ahead of each locally known upstream for up to five supplied local branches. This reads local refs only and omits branches without an upstream.
43
46
  - `createBranch(directory, branchName, options)`: Create and checkout a new branch.
@@ -71,7 +74,8 @@ bootstrap, tracking is left unset rather than writing `branch.*.remote` /
71
74
 
72
75
  ### Log Operations
73
76
  - `getLog(directory, options)`: Get commit history with stats (supports maxCount, from, to, file filters).
74
- - `getCommitFiles(directory, commitHash)`: Get file changes for a specific commit.
77
+ - `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`.
78
+ - `getCommitDiff(directory, { hash, path, previousPath, contextLines })`: Get the same commit's patch, with optional file filtering and context depth. `previousPath` keeps a rename's old and new paths in the per-file patch. Reads committed objects only, never the working tree. Exposed as `GET /api/git/commit-diff`; an unavailable hash fails rather than returning an empty diff.
75
79
  - `getCommitFileDiff(directory, hash, filePath, isBinary)`: Get before/after content for a specific file in a commit. Returns `{ original, modified, isBinary }`. Runs `git show <hash>^:<path>` and `git show <hash>:<path>` in parallel; returns empty strings on failure (added/deleted/root-commit edge cases).
76
80
 
77
81
  ### Merge and Rebase Operations
@@ -130,8 +134,28 @@ The following functions are internal helpers used by exported functions:
130
134
 
131
135
  ### Runtime availability of range diffs
132
136
  - `GET /api/git/range-diff` is served by the OpenChamber web server, so it is available to web, desktop, and mobile clients. The shared `GitAPI.getGitRangeDiff` is therefore optional: web supplies the HTTP implementation, and VS Code does not implement it because the extension host serves Git through its own bridge rather than these routes. Features built on range diffs (currently the AI diff walkthrough) are not offered in VS Code.
137
+ - Commit comparison uses the same server boundary through optional `GitAPI.getGitCommitDiff`. Desktop Changes, mobile Changes, and the existing walkthrough surface share branch/commit comparison semantics. Mobile Changes uses the same selectors and `useGitComparison` file-list owner, with a read-only list-to-detail flow. VS Code keeps its existing modes because its Git bridge does not provide these comparison operations. The HTTP operations are available to web, Electron, hosted mobile, and Capacitor clients.
133
138
 
134
139
  ### Staged and unstaged change handling
140
+ - Desktop Changes floats a compact action capsule after each hunk's last changed row,
141
+ including single-hunk files. Whole-file controls remain in the Git panel.
142
+ `getPatchHunkAnchors` uses the canonical patch's final changed row and side, so a hunk
143
+ ending in deletions is anchored after those deletions rather than above them.
144
+ Zero-height Pierre annotation slots anchor the capsule over following context
145
+ without a separate band. At EOF the capsule lifts inside the code column;
146
+ a one-line code column has a minimum hit-target height. React controls mount only
147
+ for currently rendered slots and only after their rendered diff and anchor
148
+ identities match the current props. Comment annotations remain independent.
149
+ - The canonical three-line-context action patch stays separate from the full-file
150
+ display patch. Their bytes must be identical, or their file headers and full
151
+ blob identities must match, including when reusing a cached action patch.
152
+ Mismatch leaves actions unavailable until Retry obtains a matching pair.
153
+ Successful hunk mutations invalidate
154
+ every mounted view of that path through `sessionEvents.requestGitRefresh`.
155
+ Actions remain unavailable until the refresh succeeds. Last turn, Branch and
156
+ Commit snapshots never expose hunk mutations. Mobile uses its separate Changes
157
+ surface and VS Code does not mount these controls.
158
+ - 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.
135
159
  - `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.
136
160
  - 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.
137
161
  - The shared Git panel exposes explicit staging actions. Unstaged rows use `stageFile`, staged rows use `unstageFile`, and commits operate on the current staged index.
@@ -7,13 +7,13 @@ export function registerGitRoutes(app) {
7
7
  return gitLibraries;
8
8
  };
9
9
 
10
- const resolveDirectoryQuery = (value) => {
10
+ const resolveDirectoryQuery = (value, preserveWhitespace = false) => {
11
11
  const raw = Array.isArray(value) ? value[0] : value;
12
12
  if (typeof raw !== 'string') {
13
13
  return null;
14
14
  }
15
- const trimmed = raw.trim();
16
- return trimmed || null;
15
+ const normalized = preserveWhitespace ? raw : raw.trim();
16
+ return normalized || null;
17
17
  };
18
18
 
19
19
  const extractGitErrorText = (error) => {
@@ -417,6 +417,7 @@ export function registerGitRoutes(app) {
417
417
  const diff = await getRangeDiff(directory, {
418
418
  base,
419
419
  head,
420
+ includeWorkingTree: req.query.includeWorkingTree === 'true',
420
421
  path: pathParam,
421
422
  contextLines: Number.isFinite(context) ? context : 3,
422
423
  });
@@ -463,7 +464,7 @@ export function registerGitRoutes(app) {
463
464
  return res.status(400).json({ error: 'base and head parameters are required' });
464
465
  }
465
466
 
466
- const files = await getRangeFiles(directory, { base, head });
467
+ const files = await getRangeFiles(directory, { base, head, includeWorkingTree: req.query.includeWorkingTree === 'true' });
467
468
  res.json({ files });
468
469
  } catch (error) {
469
470
  console.error('Failed to get git range files:', error);
@@ -1300,6 +1301,25 @@ export function registerGitRoutes(app) {
1300
1301
  }
1301
1302
  });
1302
1303
 
1304
+ app.get('/api/git/commit-diff', async (req, res) => {
1305
+ const { getCommitDiff } = await getGitLibraries();
1306
+ try {
1307
+ const directory = resolveDirectoryQuery(req.query.directory);
1308
+ const hash = resolveDirectoryQuery(req.query.hash);
1309
+ if (!directory || !hash) return res.status(400).json({ error: 'directory and hash are required' });
1310
+ const context = Number(req.query.context ?? 3);
1311
+ const diff = await getCommitDiff(directory, {
1312
+ hash,
1313
+ path: resolveDirectoryQuery(req.query.path, true) ?? undefined,
1314
+ previousPath: resolveDirectoryQuery(req.query.previousPath, true) ?? undefined,
1315
+ contextLines: Number.isFinite(context) ? context : 3,
1316
+ });
1317
+ res.json({ diff });
1318
+ } catch (error) {
1319
+ res.status(500).json({ error: error.message || 'Failed to get commit diff' });
1320
+ }
1321
+ });
1322
+
1303
1323
  app.get('/api/git/commit-file-diff', async (req, res) => {
1304
1324
  const { getCommitFileDiff } = await getGitLibraries();
1305
1325
  try {