@openchamber/web 1.24.0 → 1.24.2
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.
- package/bin/cli.test.js +29 -6
- package/bin/lib/cli-http.js +5 -1
- package/bin/lib/commands-status.js +5 -0
- package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-B_vBPQYm.js} +1 -1
- package/dist/assets/DiffView-Ce0oBXXQ.js +4 -0
- package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-DtXueAWP.js} +6 -6
- package/dist/assets/GitView-k0hUF8KB.js +6 -0
- package/dist/assets/GuestAttachDialog-DIf2U85Z.js +1 -0
- package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-4AnJ04Pw.js} +1 -1
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-z_9p2GuO.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-BC-BNN-s.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-DyaBTUbH.js} +6 -6
- package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-DKU_yTb6.js} +1 -1
- package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-DpGmHRnV.js} +1 -1
- package/dist/assets/PierreDiffViewer-CgLl_tp7.js +210 -0
- package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-CrfB4qqY.js} +4 -4
- package/dist/assets/PluginPane-B5cn-jPy.js +3 -0
- package/dist/assets/SettingsView-DMKKwezx.js +29 -0
- package/dist/assets/SettingsWindow-DwbnVzOC.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-hkGcvs0E.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-DuoIOc0j.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-t1Bvq_2Y.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-BK4aU5qJ.js} +1 -1
- package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-Bk6TPNFw.js} +2 -2
- package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-DnOVbJjF.js} +1 -1
- package/dist/assets/commitAndPush-DLWNZkkY.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-BVTujWSX.js} +1 -1
- package/dist/assets/{de-CX_f-T5U.js → de-zEHaAIi3.js} +4 -4
- package/dist/assets/{es-BERmWNn_.js → es-CBDgEzgk.js} +4 -4
- package/dist/assets/{fr-BjYYE_-z.js → fr-DjiTptT_.js} +4 -4
- package/dist/assets/index-AgOdanig.css +1 -0
- package/dist/assets/index-B-2_X4DD.js +40 -0
- package/dist/assets/{index-WjufPkIV.js → index-CkA4p2IK.js} +1 -1
- package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-D3yX_vx4.js} +1 -1
- package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-CZR9TcHV.js} +1 -1
- package/dist/assets/ja-CerMgj3r.js +16 -0
- package/dist/assets/{ko-Dty1aUod.js → ko-DHYDAze5.js} +4 -4
- package/dist/assets/main-BDka4W43.js +896 -0
- package/dist/assets/main-Dl7Dyge_.js +2 -0
- package/dist/assets/markdownCore-DFmr0rUR.js +5 -0
- package/dist/assets/miniChat-CLKQPPpO.js +2 -0
- package/dist/assets/mobile--giD2Q1L.js +2 -0
- package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DRh-AQvd.js} +1 -1
- package/dist/assets/{pl-CX-_ROkr.js → pl-BTB_93bq.js} +6 -6
- package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-BwA3oyCK.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +2 -0
- package/dist/assets/renderMobileApp-pMfOuQfl.js +25 -0
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +25 -0
- package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-CeRAIUmW.js} +1 -1
- package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-BfjuB3CD.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-BP60t9SX.js} +1 -1
- package/dist/assets/tr-CcPsJoNM.js +7 -0
- package/dist/assets/{uk-CD21CXFV.js → uk-B68WibXi.js} +4 -4
- package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-DcdrFv2Z.js} +147 -147
- package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-Cq4SUjsA.js} +2 -2
- package/dist/assets/useRootScrollLock-CSdR6Wnm.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BFm1Ju2w.js} +2 -2
- package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-CgAdXWZO.js} +4 -4
- package/dist/assets/{web-components-U-hWbgJo.js → web-components-2vo9YsZc.js} +1 -1
- package/dist/assets/zh-CN-DbFHYXwP.js +16 -0
- package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-DmXAwdty.js} +4 -4
- package/dist/index.html +6 -4
- package/dist/mini-chat.html +6 -4
- package/dist/mobile.html +6 -4
- package/package.json +6 -5
- package/server/index.js +29 -7
- package/server/lib/agent-tool/DOCUMENTATION.md +17 -4
- package/server/lib/agent-tool/runtime.js +62 -15
- package/server/lib/agent-tool/runtime.test.js +88 -2
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/fs/DOCUMENTATION.md +2 -1
- package/server/lib/fs/routes.js +56 -4
- package/server/lib/fs/routes.test.js +116 -0
- package/server/lib/git/DOCUMENTATION.md +18 -5
- package/server/lib/git/routes.js +1 -1
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +325 -70
- package/server/lib/git/service.test.js +291 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +5 -3
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/catalog.js +20 -9
- package/server/lib/guests/catalog.test.js +5 -5
- package/server/lib/guests/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +10 -1
- package/server/lib/message-queue/runtime.js +21 -1
- package/server/lib/message-queue/runtime.test.js +52 -5
- package/server/lib/notifications/routes.js +5 -0
- package/server/lib/openchamber-sessions/routes.js +18 -18
- package/server/lib/openchamber-sessions/routes.test.js +49 -0
- package/server/lib/opencode/DOCUMENTATION.md +1 -1
- package/server/lib/opencode/bootstrap-runtime.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/session-runtime.js +68 -0
- package/server/lib/opencode/session-runtime.test.js +43 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-registry.json +8 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/projects/project-config.js +2 -2
- package/server/lib/realtime-proxy-terminal.test.js +150 -0
- package/server/lib/realtime-proxy.js +2 -0
- package/server/lib/routing/DOCUMENTATION.md +83 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/scheduled-tasks/runtime.js +2 -2
- package/server/lib/scheduled-tasks/runtime.test.js +14 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -2
- package/server/lib/small-model/call.js +37 -6
- package/server/lib/small-model/call.test.js +182 -0
- package/server/lib/terminal/DOCUMENTATION.md +21 -2
- package/server/lib/terminal/runtime.js +10 -3
- package/server/lib/terminal/runtime.test.js +22 -0
- package/server/lib/terminal/shutdown.js +106 -0
- package/server/lib/terminal/shutdown.test.js +84 -0
- package/server/lib/tts/service.test.js +78 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +13 -9
- package/server/lib/ui-auth/ui-auth.test.js +56 -0
- package/dist/assets/DiffView-B7YkbY-u.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
- package/dist/assets/GitView-BLhlMYEY.js +0 -6
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
- package/dist/assets/PierreDiffViewer-53Ghfnlr.js +0 -161
- package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
- package/dist/assets/index-DpzTz2UH.css +0 -1
- package/dist/assets/index-Dy8xgawx.js +0 -40
- package/dist/assets/ja-DxqeAk9N.js +0 -16
- package/dist/assets/main-BOYSXfYn.js +0 -896
- package/dist/assets/main-Bjcre_GE.js +0 -2
- package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
- package/dist/assets/miniChat-Dz_bPgMc.js +0 -2
- package/dist/assets/mobile-BbZPBJrK.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
- package/dist/assets/tr-cIQtYBpg.js +0 -7
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
- package/dist/assets/zh-CN-BWvlPHY-.js +0 -16
- /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
package/server/lib/fs/routes.js
CHANGED
|
@@ -196,6 +196,23 @@ const isPathWithinRoot = (resolvedPath, rootPath, path, os) => {
|
|
|
196
196
|
return true;
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
// A chats root may not exist until the first draft. Resolve its existing
|
|
200
|
+
// ancestor so both that first mkdir and later OpenCode sessions use disk casing.
|
|
201
|
+
const canonicalDirectoryPath = async (directory, fsPromises, path) => {
|
|
202
|
+
let ancestor = path.resolve(directory);
|
|
203
|
+
const missing = [];
|
|
204
|
+
for (;;) {
|
|
205
|
+
try {
|
|
206
|
+
return path.join(await fsPromises.realpath(ancestor), ...missing);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
const parent = path.dirname(ancestor);
|
|
209
|
+
if (error.code !== 'ENOENT' || parent === ancestor) throw error;
|
|
210
|
+
missing.unshift(path.basename(ancestor));
|
|
211
|
+
ancestor = parent;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
199
216
|
const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDirectoryPath, managedRoots }) => {
|
|
200
217
|
const normalized = normalizeDirectoryPath(targetPath);
|
|
201
218
|
if (!normalized || typeof normalized !== 'string') {
|
|
@@ -253,7 +270,7 @@ const resolveWorkspacePathFromWorktrees = async ({ targetPath, baseDirectory, pa
|
|
|
253
270
|
return { ok: false, error: 'Path is outside of active workspace' };
|
|
254
271
|
};
|
|
255
272
|
|
|
256
|
-
const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProjectDirectory, path, os, normalizeDirectoryPath, managedRoots }) => {
|
|
273
|
+
const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProjectDirectory, path, os, fsPromises, normalizeDirectoryPath, managedRoots }) => {
|
|
257
274
|
const resolvedProject = await resolveProjectDirectory(req);
|
|
258
275
|
if (!resolvedProject.directory) {
|
|
259
276
|
return { ok: false, error: resolvedProject.error || 'Active workspace is required' };
|
|
@@ -292,13 +309,30 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
|
|
|
292
309
|
}
|
|
293
310
|
}
|
|
294
311
|
|
|
295
|
-
|
|
312
|
+
// Keep legacy lexical paths valid, but also accept the canonical roots
|
|
313
|
+
// returned by /fs/home. Never infer filesystem identity from letter case.
|
|
314
|
+
let resolutionError;
|
|
315
|
+
for (const root of managedRoots) {
|
|
316
|
+
try {
|
|
317
|
+
const canonicalRoot = await canonicalDirectoryPath(root, fsPromises, path);
|
|
318
|
+
const resolvedPath = path.resolve(normalizeDirectoryPath(targetPath));
|
|
319
|
+
if (isPathWithinRoot(resolvedPath, canonicalRoot, path, os)) {
|
|
320
|
+
return { ok: true, base: canonicalRoot, resolved: resolvedPath };
|
|
321
|
+
}
|
|
322
|
+
} catch (error) {
|
|
323
|
+
resolutionError ??= error;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const worktree = await resolveWorkspacePathFromWorktrees({
|
|
296
327
|
targetPath,
|
|
297
328
|
baseDirectory: resolvedProject.directory,
|
|
298
329
|
path,
|
|
299
330
|
os,
|
|
300
331
|
normalizeDirectoryPath,
|
|
301
332
|
});
|
|
333
|
+
if (worktree.ok) return worktree;
|
|
334
|
+
if (resolutionError) throw resolutionError;
|
|
335
|
+
return worktree;
|
|
302
336
|
};
|
|
303
337
|
|
|
304
338
|
// Nested repository discovery bounds: only shallow walks are useful for the
|
|
@@ -437,6 +471,7 @@ const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProje
|
|
|
437
471
|
resolveProjectDirectory,
|
|
438
472
|
path,
|
|
439
473
|
os,
|
|
474
|
+
fsPromises,
|
|
440
475
|
normalizeDirectoryPath,
|
|
441
476
|
managedRoots,
|
|
442
477
|
});
|
|
@@ -704,13 +739,22 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
704
739
|
job.updatedAt = Date.now();
|
|
705
740
|
};
|
|
706
741
|
|
|
707
|
-
app.get('/api/fs/home', (_req, res) => {
|
|
742
|
+
app.get('/api/fs/home', async (_req, res) => {
|
|
708
743
|
try {
|
|
709
744
|
const home = os.homedir();
|
|
710
745
|
if (!home || typeof home !== 'string' || home.length === 0) {
|
|
711
746
|
return res.status(500).json({ error: 'Failed to resolve home directory' });
|
|
712
747
|
}
|
|
713
|
-
|
|
748
|
+
const [canonicalChatsRoot, canonicalLegacyChatsRoot] = await Promise.all([
|
|
749
|
+
canonicalDirectoryPath(chatsRoot, fsPromises, path),
|
|
750
|
+
canonicalDirectoryPath(path.join(home, '.config', 'openchamber', 'chats'), fsPromises, path).catch((error) => {
|
|
751
|
+
// A relocated root must remain usable if the old root is inaccessible.
|
|
752
|
+
// Omit only this optional alias; clients retain exact legacy matching.
|
|
753
|
+
console.warn('Failed to resolve legacy chats root:', error);
|
|
754
|
+
return undefined;
|
|
755
|
+
}),
|
|
756
|
+
]);
|
|
757
|
+
return res.json({ home, chatsRoot, canonicalChatsRoot, canonicalLegacyChatsRoot });
|
|
714
758
|
} catch (error) {
|
|
715
759
|
console.error('Failed to resolve home directory:', error);
|
|
716
760
|
return res.status(500).json({ error: (error && error.message) || 'Failed to resolve home directory' });
|
|
@@ -730,6 +774,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
730
774
|
return res.status(403).json({ error: 'Outside workspace directory creation requires a grant' });
|
|
731
775
|
} else {
|
|
732
776
|
const resolved = await resolveWorkspacePathFromContext({
|
|
777
|
+
fsPromises,
|
|
733
778
|
req,
|
|
734
779
|
targetPath: dirPath,
|
|
735
780
|
resolveProjectDirectory,
|
|
@@ -1153,6 +1198,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1153
1198
|
|
|
1154
1199
|
try {
|
|
1155
1200
|
const resolved = await resolveWorkspacePathFromContext({
|
|
1201
|
+
fsPromises,
|
|
1156
1202
|
req,
|
|
1157
1203
|
targetPath: filePath,
|
|
1158
1204
|
resolveProjectDirectory,
|
|
@@ -1223,6 +1269,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1223
1269
|
|
|
1224
1270
|
try {
|
|
1225
1271
|
const resolved = await resolveWorkspacePathFromContext({
|
|
1272
|
+
fsPromises,
|
|
1226
1273
|
req,
|
|
1227
1274
|
targetPath: filePath,
|
|
1228
1275
|
resolveProjectDirectory,
|
|
@@ -1330,6 +1377,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1330
1377
|
|
|
1331
1378
|
try {
|
|
1332
1379
|
const resolved = await resolveWorkspacePathFromContext({
|
|
1380
|
+
fsPromises,
|
|
1333
1381
|
req,
|
|
1334
1382
|
targetPath,
|
|
1335
1383
|
resolveProjectDirectory,
|
|
@@ -1368,6 +1416,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1368
1416
|
|
|
1369
1417
|
try {
|
|
1370
1418
|
const resolvedOld = await resolveWorkspacePathFromContext({
|
|
1419
|
+
fsPromises,
|
|
1371
1420
|
req,
|
|
1372
1421
|
targetPath: oldPath,
|
|
1373
1422
|
resolveProjectDirectory,
|
|
@@ -1381,6 +1430,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1381
1430
|
}
|
|
1382
1431
|
|
|
1383
1432
|
const resolvedNew = await resolveWorkspacePathFromContext({
|
|
1433
|
+
fsPromises,
|
|
1384
1434
|
req,
|
|
1385
1435
|
targetPath: newPath,
|
|
1386
1436
|
resolveProjectDirectory,
|
|
@@ -1487,6 +1537,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1487
1537
|
}
|
|
1488
1538
|
const resolvedCwdCandidate = path.resolve(normalizeDirectoryPath(cwd));
|
|
1489
1539
|
const resolvedForWorkspace = await resolveWorkspacePathFromContext({
|
|
1540
|
+
fsPromises,
|
|
1490
1541
|
req,
|
|
1491
1542
|
targetPath: resolvedCwdCandidate,
|
|
1492
1543
|
resolveProjectDirectory,
|
|
@@ -1726,6 +1777,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1726
1777
|
|
|
1727
1778
|
try {
|
|
1728
1779
|
const resolved = await resolveWorkspacePathFromContext({
|
|
1780
|
+
fsPromises,
|
|
1729
1781
|
req,
|
|
1730
1782
|
targetPath: rawPath,
|
|
1731
1783
|
resolveProjectDirectory,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { copyFile, mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
+
import * as nativeFs from 'node:fs/promises';
|
|
4
5
|
import { tmpdir } from 'node:os';
|
|
5
6
|
import { execFileSync } from 'node:child_process';
|
|
6
7
|
import { pathToFileURL } from 'node:url';
|
|
@@ -1586,6 +1587,40 @@ describe('fs managed chats root', () => {
|
|
|
1586
1587
|
expect(res.body.chatsRoot).toBe('/srv/openchamber-chats');
|
|
1587
1588
|
});
|
|
1588
1589
|
|
|
1590
|
+
it('fails home lookup on permission errors and retries the next request', async () => {
|
|
1591
|
+
const failure = Object.assign(new Error('permission denied'), { code: 'EACCES' });
|
|
1592
|
+
let inaccessible = true;
|
|
1593
|
+
const { home } = registerWithChatsRoot({ fsPromises: {
|
|
1594
|
+
realpath: async directory => { if (inaccessible) throw failure; return directory; },
|
|
1595
|
+
} });
|
|
1596
|
+
const failed = createMockResponse();
|
|
1597
|
+
await home(undefined, failed);
|
|
1598
|
+
expect(failed.statusCode).toBe(500);
|
|
1599
|
+
expect(failed.body).toEqual({ error: 'permission denied' });
|
|
1600
|
+
inaccessible = false;
|
|
1601
|
+
const recovered = createMockResponse();
|
|
1602
|
+
await home(undefined, recovered);
|
|
1603
|
+
expect(recovered.statusCode).toBe(200);
|
|
1604
|
+
expect(recovered.body.chatsRoot).toBe('/home/user/.config/openchamber/chats');
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
it('keeps an accessible relocated root available when legacy alias lookup fails', async () => {
|
|
1608
|
+
const { home } = registerWithChatsRoot({
|
|
1609
|
+
managedChatsRoot: '/srv/chat-alias',
|
|
1610
|
+
fsPromises: {
|
|
1611
|
+
realpath: async directory => {
|
|
1612
|
+
if (directory === '/srv/chat-alias') return '/storage/chats';
|
|
1613
|
+
throw Object.assign(new Error('legacy root is inaccessible'), { code: 'EACCES' });
|
|
1614
|
+
},
|
|
1615
|
+
},
|
|
1616
|
+
});
|
|
1617
|
+
const response = createMockResponse();
|
|
1618
|
+
await home(undefined, response);
|
|
1619
|
+
expect(response.statusCode).toBe(200);
|
|
1620
|
+
expect(response.body.canonicalChatsRoot).toBe('/storage/chats');
|
|
1621
|
+
expect(response.body.canonicalLegacyChatsRoot).toBeUndefined();
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1589
1624
|
it('allows mkdir inside the relocated chats root outside the active workspace', async () => {
|
|
1590
1625
|
const mkdirCalls = [];
|
|
1591
1626
|
const { mkdir } = registerWithChatsRoot({
|
|
@@ -1605,6 +1640,22 @@ describe('fs managed chats root', () => {
|
|
|
1605
1640
|
expect(mkdirCalls).toEqual(['/srv/openchamber-chats/2026-08-25/session-a']);
|
|
1606
1641
|
});
|
|
1607
1642
|
|
|
1643
|
+
it('accepts a canonical relocated root even when the config root cannot be resolved', async () => {
|
|
1644
|
+
const { mkdir } = registerWithChatsRoot({
|
|
1645
|
+
managedChatsRoot: '/srv/chat-alias',
|
|
1646
|
+
fsPromises: {
|
|
1647
|
+
realpath: async directory => {
|
|
1648
|
+
if (directory === '/srv/chat-alias') return '/storage/chats';
|
|
1649
|
+
throw Object.assign(new Error('permission denied'), { code: 'EACCES' });
|
|
1650
|
+
},
|
|
1651
|
+
},
|
|
1652
|
+
});
|
|
1653
|
+
const response = createMockResponse();
|
|
1654
|
+
await mkdir({ body: { path: '/storage/chats/day/session-a' } }, response);
|
|
1655
|
+
expect(response.statusCode).toBe(200);
|
|
1656
|
+
expect(response.body.path).toBe('/storage/chats/day/session-a');
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1608
1659
|
it('still rejects mkdir outside the workspace and all managed roots', async () => {
|
|
1609
1660
|
const { mkdir } = registerWithChatsRoot({ managedChatsRoot: '/srv/openchamber-chats' });
|
|
1610
1661
|
|
|
@@ -1615,3 +1666,68 @@ describe('fs managed chats root', () => {
|
|
|
1615
1666
|
expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
|
|
1616
1667
|
});
|
|
1617
1668
|
});
|
|
1669
|
+
|
|
1670
|
+
describe('canonical managed roots with real filesystem aliases', () => {
|
|
1671
|
+
const setup = async (context, { relocated = false, caseAlias = false } = {}) => {
|
|
1672
|
+
const root = await nativeFs.mkdtemp(path.join(tmpdir(), 'oc-canonical-chats-'));
|
|
1673
|
+
context.onTestFinished(() => nativeFs.rm(root, { recursive: true, force: true }));
|
|
1674
|
+
const home = path.join(root, 'Home');
|
|
1675
|
+
await nativeFs.mkdir(home);
|
|
1676
|
+
const reportedHome = path.join(root, caseAlias ? 'home' : 'home-alias');
|
|
1677
|
+
if (!caseAlias) await nativeFs.symlink(home, reportedHome, 'junction');
|
|
1678
|
+
const config = path.join(reportedHome, '.config/openchamber');
|
|
1679
|
+
const rawChats = relocated ? path.join(reportedHome, 'scratch/chats') : path.join(config, 'chats');
|
|
1680
|
+
const canonicalHome = await nativeFs.realpath(home);
|
|
1681
|
+
if (caseAlias && await nativeFs.realpath(reportedHome).catch(() => null) !== canonicalHome) {
|
|
1682
|
+
context.skip('This volume distinguishes Home from home');
|
|
1683
|
+
}
|
|
1684
|
+
const canonicalChats = path.join(canonicalHome, relocated ? 'scratch/chats' : '.config/openchamber/chats');
|
|
1685
|
+
const { app, getRoute } = createRouteRegistry();
|
|
1686
|
+
registerFsRoutes(app, {
|
|
1687
|
+
os: { homedir: () => reportedHome }, path, fsPromises: nativeFs,
|
|
1688
|
+
normalizeDirectoryPath: value => value,
|
|
1689
|
+
resolveProjectDirectory: async () => ({ directory: path.join(root, 'unrelated-project') }),
|
|
1690
|
+
openchamberUserConfigRoot: config, managedChatsRoot: rawChats,
|
|
1691
|
+
});
|
|
1692
|
+
return { getRoute, canonicalHome, canonicalChats, rawChats, reportedHome };
|
|
1693
|
+
};
|
|
1694
|
+
|
|
1695
|
+
for (const relocated of [false, true]) {
|
|
1696
|
+
it(`returns canonical paths before the ${relocated ? 'relocated' : 'default'} root exists and permits its lifecycle`, async context => {
|
|
1697
|
+
const { getRoute, canonicalHome, canonicalChats, rawChats, reportedHome } = await setup(context, { relocated });
|
|
1698
|
+
const home = createMockResponse();
|
|
1699
|
+
await getRoute('GET', '/api/fs/home')({}, home);
|
|
1700
|
+
expect(home.body).toEqual({
|
|
1701
|
+
home: reportedHome, chatsRoot: rawChats,
|
|
1702
|
+
canonicalChatsRoot: canonicalChats,
|
|
1703
|
+
canonicalLegacyChatsRoot: path.join(canonicalHome, '.config/openchamber/chats'),
|
|
1704
|
+
});
|
|
1705
|
+
await expect(nativeFs.stat(canonicalChats)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
1706
|
+
|
|
1707
|
+
const directory = path.join(home.body.canonicalChatsRoot, 'day/session-a');
|
|
1708
|
+
const created = createMockResponse();
|
|
1709
|
+
await getRoute('POST', '/api/fs/mkdir')({ body: { path: directory } }, created);
|
|
1710
|
+
expect(created.statusCode).toBe(200);
|
|
1711
|
+
expect(await nativeFs.realpath(directory)).toBe(directory);
|
|
1712
|
+
const deleted = createMockResponse();
|
|
1713
|
+
await getRoute('POST', '/api/fs/delete')({ body: { path: directory } }, deleted);
|
|
1714
|
+
expect(deleted.statusCode).toBe(200);
|
|
1715
|
+
await expect(nativeFs.stat(directory)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
1716
|
+
|
|
1717
|
+
const legacy = createMockResponse();
|
|
1718
|
+
await getRoute('POST', '/api/fs/mkdir')({ body: { path: path.join(rawChats, 'legacy-session') } }, legacy);
|
|
1719
|
+
expect(legacy.statusCode).toBe(200);
|
|
1720
|
+
expect((await nativeFs.stat(path.join(canonicalChats, 'legacy-session'))).isDirectory()).toBe(true);
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
it('reports on-disk home casing on a case-insensitive macOS volume', { skip: process.platform !== 'darwin' }, async context => {
|
|
1725
|
+
const { getRoute, canonicalChats, rawChats, reportedHome } = await setup(context, { caseAlias: true });
|
|
1726
|
+
const response = createMockResponse();
|
|
1727
|
+
await getRoute('GET', '/api/fs/home')({}, response);
|
|
1728
|
+
expect(response.body).toEqual({
|
|
1729
|
+
home: reportedHome, chatsRoot: rawChats,
|
|
1730
|
+
canonicalChatsRoot: canonicalChats, canonicalLegacyChatsRoot: canonicalChats,
|
|
1731
|
+
});
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
@@ -16,7 +16,7 @@ This module provides Git repository operations for the web server runtime, inclu
|
|
|
16
16
|
The following functions are exported and used by the web server:
|
|
17
17
|
|
|
18
18
|
### Repository Operations
|
|
19
|
-
- `isGitRepository(directory)`: Check if a directory is a Git repository.
|
|
19
|
+
- `isGitRepository(directory)`: Check if a directory is a Git repository. A repository whose root is the home directory or a filesystem root (`C:\`, `/`) answers `false` (`unsupportedRepositoryRootReason`): such a repository covers the whole disk, every status read would walk it, and it is nearly always an accidental `git init`. All Git surfaces then show the non-repository state for that directory.
|
|
20
20
|
- `getGlobalIdentity()`: Get global Git user.name, user.email, and core.sshCommand.
|
|
21
21
|
- `getCurrentIdentity(directory)`: Get local Git identity (fallback to global if not set locally).
|
|
22
22
|
- `hasLocalIdentity(directory)`: Check if local Git identity is configured.
|
|
@@ -24,10 +24,11 @@ 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. A slot is held only while the read is alive: every process the read spawns is killed after two minutes without output (one minute for the untracked-directory listing, thirty seconds for the repository probe), so a Git process that hangs, which happens on Windows, fails that read instead of holding a slot until someone kills it by hand. On Windows the listing is ended with `taskkill /T`, because the spawned `git.exe` is Git for Windows' launcher and killing it alone leaves the real `git` child walking the tree as an orphan. 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.
|
|
29
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`.
|
|
30
|
-
- 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),
|
|
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.
|
|
31
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.
|
|
32
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.
|
|
33
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.
|
|
@@ -83,6 +84,17 @@ bootstrap, tracking is left unset rather than writing `branch.*.remote` /
|
|
|
83
84
|
- `removeRemote(directory, options)`: Remove a configured remote (except `origin`).
|
|
84
85
|
- `deleteRemoteBranch(directory, options)`: Delete a remote branch.
|
|
85
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
|
+
|
|
86
98
|
### Log Operations
|
|
87
99
|
- `getLog(directory, options)`: Get commit history with stats (supports maxCount, from, to, file filters).
|
|
88
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`.
|
|
@@ -110,7 +122,7 @@ bootstrap, tracking is left unset rather than writing `branch.*.remote` /
|
|
|
110
122
|
|
|
111
123
|
The following functions are internal helpers used by exported functions:
|
|
112
124
|
- `buildSshCommand(sshKeyPath)`: Build SSH command string for git config.
|
|
113
|
-
- `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.
|
|
114
126
|
- `createGit(directory)`: Create simple-git instance with environment.
|
|
115
127
|
- `normalizeDirectoryPath(value)`: Normalize directory paths (supports ~ expansion).
|
|
116
128
|
- `cleanBranchName(branch)`: Remove refs/heads/ or refs/ prefixes.
|
|
@@ -132,7 +144,7 @@ The following functions are internal helpers used by exported functions:
|
|
|
132
144
|
- `upstreamComparison`: Optional comparison against `upstream/<current-branch>`, with `{ remote, branch, ahead, behind }`.
|
|
133
145
|
- `files`: Array of file objects with `path`, `index`, `working_dir` status codes.
|
|
134
146
|
- `isClean`: Boolean indicating if working tree is clean.
|
|
135
|
-
- `diffStats`:
|
|
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`.
|
|
136
148
|
- `mergeInProgress`: Object with `{ head, message }` if merge in progress.
|
|
137
149
|
- `rebaseInProgress`: Object with `{ headName, onto }` if rebase in progress.
|
|
138
150
|
|
|
@@ -168,6 +180,7 @@ The following functions are internal helpers used by exported functions:
|
|
|
168
180
|
surface and VS Code does not mount these controls.
|
|
169
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.
|
|
170
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.
|
|
171
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.
|
|
172
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.
|
|
173
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.
|
package/server/lib/git/routes.js
CHANGED
|
@@ -12,7 +12,7 @@ export function registerGitRoutes(app, { emitWorktreeChanged } = {}) {
|
|
|
12
12
|
|
|
13
13
|
// A path from an earlier status listing that no longer resolves is a stale
|
|
14
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]]);
|
|
15
|
+
const GIT_PATH_ERROR_STATUS = new Map([['path_not_found', 404], ['nested_repository', 422], ['untracked_directory', 422]]);
|
|
16
16
|
const sendGitPathError = (res, error) => {
|
|
17
17
|
const status = GIT_PATH_ERROR_STATUS.get(error?.code);
|
|
18
18
|
if (!status) return false;
|
|
@@ -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
|
+
});
|