@openchamber/web 1.24.1 → 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 +22 -0
- package/bin/lib/commands-status.js +5 -0
- package/dist/assets/{CodeMirrorCommentWidgets-DvUH815P.js → CodeMirrorCommentWidgets-B_vBPQYm.js} +1 -1
- package/dist/assets/DiffView-Ce0oBXXQ.js +4 -0
- package/dist/assets/{FilesView-D0bM9FVB.js → FilesView-DtXueAWP.js} +5 -5
- package/dist/assets/{GitView-Bxuv3dfP.js → GitView-k0hUF8KB.js} +4 -4
- package/dist/assets/{GuestAttachDialog-B0u3Q5uO.js → GuestAttachDialog-DIf2U85Z.js} +1 -1
- package/dist/assets/{JsonTreeView-BBVPFM5K.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-UI1FcSC8.js → LinearIssuesView-z_9p2GuO.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-CUJxH8Le.js → MarkdownImageGallery-BC-BNN-s.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-D5BZOg8X.js → MarkdownRendererImpl-DyaBTUbH.js} +6 -6
- package/dist/assets/{OnboardingScreen-5Gou9cGD.js → OnboardingScreen-DKU_yTb6.js} +1 -1
- package/dist/assets/{PatchDiff-C4rE5k6z.js → PatchDiff-DpGmHRnV.js} +1 -1
- package/dist/assets/PierreDiffViewer-CgLl_tp7.js +210 -0
- package/dist/assets/{PlanView-u2yi5XGJ.js → PlanView-CrfB4qqY.js} +4 -4
- package/dist/assets/{PluginPane-QxjsKYeO.js → PluginPane-B5cn-jPy.js} +1 -1
- package/dist/assets/{SettingsView-Fo5ZqMaT.js → SettingsView-DMKKwezx.js} +12 -12
- package/dist/assets/{SettingsWindow-HVDVANjJ.js → SettingsWindow-DwbnVzOC.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-D3hzkybB.js → SubmoduleDiffSummary-hkGcvs0E.js} +1 -1
- package/dist/assets/{ToolOutputDialog-3J6IRayW.js → ToolOutputDialog-DuoIOc0j.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-DarxPjSd.js → ToolPartDiffPreview-t1Bvq_2Y.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CZgXWHjU.js → VirtualizedFileDiff-BK4aU5qJ.js} +4 -4
- package/dist/assets/{WalkthroughView-wSpED5L4.js → WalkthroughView-Bk6TPNFw.js} +2 -2
- package/dist/assets/{appThemeRegistry-Cf8KitzT.js → appThemeRegistry-DnOVbJjF.js} +1 -1
- package/dist/assets/{commitAndPush-DZnzlhvc.js → commitAndPush-DLWNZkkY.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-VYnT_A2h.js → computeVirtualFileMetrics-BVTujWSX.js} +1 -1
- package/dist/assets/{de-BM_8EDD3.js → de-zEHaAIi3.js} +4 -4
- package/dist/assets/{es-CxZjlqpo.js → es-CBDgEzgk.js} +3 -3
- package/dist/assets/{fr-VCixCnMW.js → fr-DjiTptT_.js} +4 -4
- package/dist/assets/{index-B9Hvzjwl.css → index-AgOdanig.css} +1 -1
- package/dist/assets/index-B-2_X4DD.js +40 -0
- package/dist/assets/{index-3U4CtS9b.js → index-CkA4p2IK.js} +1 -1
- package/dist/assets/{isDiffPlainText-ImDG3Uhg.js → isDiffPlainText-D3yX_vx4.js} +1 -1
- package/dist/assets/{isFilePlainText-D_YDVYDb.js → isFilePlainText-CZR9TcHV.js} +1 -1
- package/dist/assets/{ja-CZ5k_GyD.js → ja-CerMgj3r.js} +4 -4
- package/dist/assets/{ko-7YM3A1Xh.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-DHvqMxPn.js → markdownCore-DFmr0rUR.js} +4 -4
- package/dist/assets/miniChat-CLKQPPpO.js +2 -0
- package/dist/assets/mobile--giD2Q1L.js +2 -0
- package/dist/assets/{patchFileDiff-DDQ6Rq5e.js → patchFileDiff-DRh-AQvd.js} +3 -3
- package/dist/assets/{pl-BcgDO_w5.js → pl-BTB_93bq.js} +4 -4
- package/dist/assets/{pt-BR-CU2u_1q5.js → pt-BR-BwA3oyCK.js} +3 -3
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +2 -0
- package/dist/assets/{renderMobileApp-D0Y8DtkA.js → renderMobileApp-pMfOuQfl.js} +7 -7
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +25 -0
- package/dist/assets/{scheduledTasksApi-D8pq6gQz.js → scheduledTasksApi-CeRAIUmW.js} +1 -1
- package/dist/assets/{shikiHighlight-1imXsir9.js → shikiHighlight-BfjuB3CD.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Dgqc63LZ.js → textMateThemeFromAppTheme-BP60t9SX.js} +1 -1
- package/dist/assets/{tr-DuYhOzNe.js → tr-CcPsJoNM.js} +3 -3
- package/dist/assets/{uk-Cuk7-uvq.js → uk-B68WibXi.js} +3 -3
- package/dist/assets/{useAppFontEffects-BItUWdo4.js → useAppFontEffects-DcdrFv2Z.js} +144 -144
- package/dist/assets/{useInlineCommentController-CkbKsm7m.js → useInlineCommentController-Cq4SUjsA.js} +2 -2
- package/dist/assets/{useRootScrollLock-vmzxZjWA.js → useRootScrollLock-CSdR6Wnm.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-BDyxuqK4.js → vendor-codemirror-language-data-BFm1Ju2w.js} +2 -2
- package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
- package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-CgAdXWZO.js} +4 -4
- package/dist/assets/{web-components-D7FinaeH.js → web-components-2vo9YsZc.js} +1 -1
- package/dist/assets/{zh-CN-CUWoiRHd.js → zh-CN-DbFHYXwP.js} +3 -3
- package/dist/assets/{zh-TW-CQ8EBSBN.js → zh-TW-DmXAwdty.js} +3 -3
- package/dist/index.html +6 -4
- package/dist/mini-chat.html +6 -4
- package/dist/mobile.html +6 -4
- package/package.json +4 -4
- package/server/index.js +3 -0
- 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/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 +2 -2
- package/server/lib/git/service.js +94 -9
- package/server/lib/git/service.test.js +18 -0
- package/server/lib/message-queue/DOCUMENTATION.md +4 -1
- package/server/lib/message-queue/runtime.js +16 -1
- package/server/lib/message-queue/runtime.test.js +21 -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/session-runtime.js +68 -0
- package/server/lib/opencode/session-runtime.test.js +43 -0
- 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 +5 -3
- package/server/lib/scheduled-tasks/runtime.js +2 -2
- package/server/lib/scheduled-tasks/runtime.test.js +14 -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/dist/assets/DiffView-DkC3xlRJ.js +0 -4
- package/dist/assets/PierreDiffViewer-ByRVu6ss.js +0 -161
- package/dist/assets/index-DLHQogv8.js +0 -40
- package/dist/assets/main-CycplCph.js +0 -2
- package/dist/assets/main-DFYTCx5o.js +0 -896
- package/dist/assets/miniChat-DIQKfY2V.js +0 -2
- package/dist/assets/mobile-BMwz5q-m.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +0 -2
- package/dist/assets/runtimeEndpointReset-DhC3REb2.js +0 -25
- /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
|
@@ -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,7 +24,7 @@ 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, { mode })`: Get comprehensive Git status including current branch, tracking, ahead/behind, file changes, diff stats, merge/rebase state. `mode: 'light'` skips the diff stats. One read runs per directory at a time and at most four run across directories (`serial-refresh.js`): a call made while a read is running waits for one follow-up read that starts after the call, so no caller gets a snapshot older than its request, and every caller that arrives during one read shares that single follow-up at the widest mode any of them asked for. Clients refresh after every completed agent tool call and from several surfaces at once; on a large repository (a status read is a dozen Git processes walking the working tree) this bound is what keeps identical `git status` processes from piling up side by side. Untracked files are listed with `-unormal` and each new directory is then expanded to its files with a bounded `ls-files` listing (`UNTRACKED_DIRECTORY_EXPANSION_LIMIT`, 1000): up to that many files the result equals `-uall`; beyond it the directory stays one `dir/` entry, because `-uall` would walk a forgotten build or dependency directory in full on every read. A nested repository stays a `dir/` entry as before.
|
|
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
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`.
|
|
29
29
|
- `getDiff(directory, { path, staged, contextLines })`: Get diff output for files or entire working tree with full Git blob identities. Untracked symbolic links are represented as link entries without following their targets.
|
|
30
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`.
|
|
@@ -359,9 +359,13 @@ const buildGitEnv = async () => {
|
|
|
359
359
|
return env;
|
|
360
360
|
};
|
|
361
361
|
|
|
362
|
-
const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafeCredentialHelper = false } = {}) => {
|
|
362
|
+
const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafeCredentialHelper = false, stallTimeoutMs = 0 } = {}) => {
|
|
363
363
|
const env = await buildGitEnv();
|
|
364
364
|
const spawnOptions = { windowsHide: true };
|
|
365
|
+
// simple-git's block timeout kills the process once it has produced no
|
|
366
|
+
// output for this long. Opt-in per caller: a background read must never hold
|
|
367
|
+
// a limiter slot forever, while a silent long push or fetch must not be cut.
|
|
368
|
+
const timeout = stallTimeoutMs > 0 ? { block: stallTimeoutMs } : undefined;
|
|
365
369
|
const binary = getGitBinary();
|
|
366
370
|
const hasCustomBinary = typeof binary === 'string' && binary.trim() && binary !== 'git' && binary !== 'git.exe';
|
|
367
371
|
const unsafe = hasCustomBinary || allowUnsafeSshCommand || allowUnsafeCredentialHelper
|
|
@@ -386,6 +390,7 @@ const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafe
|
|
|
386
390
|
spawnOptions,
|
|
387
391
|
binary,
|
|
388
392
|
unsafe,
|
|
393
|
+
...(timeout ? { timeout } : {}),
|
|
389
394
|
});
|
|
390
395
|
};
|
|
391
396
|
|
|
@@ -491,14 +496,14 @@ const resolveGitRepositoryRoot = async (directoryPath, git) => {
|
|
|
491
496
|
: path.resolve(directoryPath, normalizedTopLevel);
|
|
492
497
|
};
|
|
493
498
|
|
|
494
|
-
const createRepositoryGitContext = async (directory) => {
|
|
499
|
+
const createRepositoryGitContext = async (directory, gitOptions = {}) => {
|
|
495
500
|
const directoryPath = normalizeDirectoryPath(directory);
|
|
496
501
|
if (typeof directoryPath !== 'string' || !directoryPath.trim()) {
|
|
497
502
|
throw new Error('Git directory is required');
|
|
498
503
|
}
|
|
499
|
-
const directoryGit = await createGit(directoryPath);
|
|
504
|
+
const directoryGit = await createGit(directoryPath, gitOptions);
|
|
500
505
|
const repoRoot = await resolveGitRepositoryRoot(directoryPath, directoryGit);
|
|
501
|
-
const git = path.resolve(directoryPath) === repoRoot ? directoryGit : await createGit(repoRoot);
|
|
506
|
+
const git = path.resolve(directoryPath) === repoRoot ? directoryGit : await createGit(repoRoot, gitOptions);
|
|
502
507
|
return { directoryPath, directoryGit, repoRoot, git };
|
|
503
508
|
};
|
|
504
509
|
|
|
@@ -1014,13 +1019,16 @@ const isMissingDirectoryError = (error) => {
|
|
|
1014
1019
|
return /directory that does not exist|does not exist|no such file or directory/i.test(text);
|
|
1015
1020
|
};
|
|
1016
1021
|
|
|
1017
|
-
const runGitCommand = async (cwd, args) => {
|
|
1022
|
+
const runGitCommand = async (cwd, args, { timeoutMs = 0 } = {}) => {
|
|
1018
1023
|
try {
|
|
1019
1024
|
const { stdout, stderr } = await execFileAsync(getGitBinary(), args, {
|
|
1020
1025
|
cwd,
|
|
1021
1026
|
env: await buildGitEnv(),
|
|
1022
1027
|
windowsHide: true,
|
|
1023
1028
|
maxBuffer: 20 * 1024 * 1024,
|
|
1029
|
+
// Only short probes pass a timeout; commands that legitimately run long
|
|
1030
|
+
// (a fetch into a temporary clone) keep the default of none.
|
|
1031
|
+
...(timeoutMs > 0 ? { timeout: timeoutMs, killSignal: 'SIGKILL' } : {}),
|
|
1024
1032
|
});
|
|
1025
1033
|
return {
|
|
1026
1034
|
success: true,
|
|
@@ -2147,14 +2155,45 @@ const applyUpstreamConfiguration = async (args) => {
|
|
|
2147
2155
|
);
|
|
2148
2156
|
};
|
|
2149
2157
|
|
|
2158
|
+
/**
|
|
2159
|
+
* A repository whose root is the user's home directory or a filesystem root
|
|
2160
|
+
* (`C:\`, `/`) covers the whole disk. Every status read walks Program Files
|
|
2161
|
+
* or the entire home tree, which is minutes of Git work per refresh and, on
|
|
2162
|
+
* Windows, the process pile-ups users report. Such a repository is nearly
|
|
2163
|
+
* always an accidental `git init` in the wrong place, so OpenChamber treats
|
|
2164
|
+
* it as no repository at all. Returns the reason or null for a normal root.
|
|
2165
|
+
*/
|
|
2166
|
+
export const unsupportedRepositoryRootReason = (repoRoot, home = os.homedir()) => {
|
|
2167
|
+
if (typeof repoRoot !== 'string' || !repoRoot.trim()) return null;
|
|
2168
|
+
const resolved = path.resolve(repoRoot.trim());
|
|
2169
|
+
if (path.resolve(path.parse(resolved).root) === resolved) return 'filesystem-root';
|
|
2170
|
+
if (typeof home === 'string' && home.trim() && path.resolve(home.trim()) === resolved) return 'home';
|
|
2171
|
+
return null;
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
const warnedUnsupportedRoots = new Set();
|
|
2175
|
+
|
|
2150
2176
|
export async function isGitRepository(directory) {
|
|
2151
2177
|
const directoryPath = normalizeDirectoryPath(directory);
|
|
2152
2178
|
if (!directoryPath || !fs.existsSync(directoryPath)) {
|
|
2153
2179
|
return false;
|
|
2154
2180
|
}
|
|
2155
2181
|
|
|
2156
|
-
const result = await runGitCommand(directoryPath, ['rev-parse', '--git-dir']);
|
|
2157
|
-
|
|
2182
|
+
const result = await runGitCommand(directoryPath, ['rev-parse', '--git-dir'], { timeoutMs: GIT_PROBE_TIMEOUT_MS });
|
|
2183
|
+
if (!result.success) return false;
|
|
2184
|
+
|
|
2185
|
+
// `--show-toplevel` has no answer inside a bare repository or a .git
|
|
2186
|
+
// directory; those keep the previous answer rather than being rejected.
|
|
2187
|
+
const topLevel = await runGitCommand(directoryPath, ['rev-parse', '--show-toplevel'], { timeoutMs: GIT_PROBE_TIMEOUT_MS });
|
|
2188
|
+
if (!topLevel.success) return true;
|
|
2189
|
+
const repoRoot = topLevel.stdout.trim();
|
|
2190
|
+
const reason = unsupportedRepositoryRootReason(repoRoot);
|
|
2191
|
+
if (!reason) return true;
|
|
2192
|
+
if (!warnedUnsupportedRoots.has(repoRoot)) {
|
|
2193
|
+
warnedUnsupportedRoots.add(repoRoot);
|
|
2194
|
+
console.warn(`[git] Ignoring repository rooted at ${repoRoot} (${reason}): Git features are disabled for ${directoryPath}`);
|
|
2195
|
+
}
|
|
2196
|
+
return false;
|
|
2158
2197
|
}
|
|
2159
2198
|
|
|
2160
2199
|
export async function getGlobalIdentity() {
|
|
@@ -2282,7 +2321,38 @@ export async function setLocalIdentity(directory, profile) {
|
|
|
2282
2321
|
// .gitignore.
|
|
2283
2322
|
const UNTRACKED_DIRECTORY_EXPANSION_LIMIT = 1000;
|
|
2284
2323
|
|
|
2324
|
+
// A status read holds one of MAX_CONCURRENT_STATUS_READS slots until it
|
|
2325
|
+
// finishes. Git never gets a terminal here, but a process can still hang on
|
|
2326
|
+
// Windows (a locked index, a stuck filesystem monitor, an unreachable network
|
|
2327
|
+
// drive), and a hung process would hold its slot forever: four of them and no
|
|
2328
|
+
// status read runs again until someone kills them by hand. Every process the
|
|
2329
|
+
// read spawns is therefore killed when it stops producing output for this long,
|
|
2330
|
+
// and the read fails instead of wedging the limiter. Two minutes is far above
|
|
2331
|
+
// what a healthy read spends silent, even on a very large tree.
|
|
2332
|
+
const GIT_STATUS_STALL_TIMEOUT_MS = 120_000;
|
|
2333
|
+
const GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS = 60_000;
|
|
2334
|
+
const GIT_PROBE_TIMEOUT_MS = 30_000;
|
|
2335
|
+
|
|
2285
2336
|
// Untracked files under `dirPath` (repository-relative, trailing slash), read
|
|
2337
|
+
// Git for Windows runs commands through a launcher: the `git.exe` we spawn is a
|
|
2338
|
+
// wrapper whose child is the real `git`. Killing only the wrapper leaves that
|
|
2339
|
+
// child alive, still walking the tree on its own (a repository rooted at a
|
|
2340
|
+
// drive root sends it through Program Files), and it shows up in Task Manager
|
|
2341
|
+
// as a stuck pair until someone ends it by hand. Windows has no process groups
|
|
2342
|
+
// to signal, so the tree is ended through taskkill.
|
|
2343
|
+
const killProcessTree = (child) => {
|
|
2344
|
+
if (!child.pid) return;
|
|
2345
|
+
if (process.platform === 'win32') {
|
|
2346
|
+
try {
|
|
2347
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' }).on('error', () => {});
|
|
2348
|
+
} catch {
|
|
2349
|
+
child.kill('SIGKILL');
|
|
2350
|
+
}
|
|
2351
|
+
return;
|
|
2352
|
+
}
|
|
2353
|
+
child.kill('SIGKILL');
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2286
2356
|
// from a streamed `ls-files` that is stopped once the bound is exceeded so a
|
|
2287
2357
|
// huge directory is never listed in full. `paths` is complete when
|
|
2288
2358
|
// `truncated` is false.
|
|
@@ -2299,16 +2369,29 @@ const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
|
|
|
2299
2369
|
let pending = '';
|
|
2300
2370
|
let truncated = false;
|
|
2301
2371
|
let settled = false;
|
|
2372
|
+
let stallTimer = null;
|
|
2302
2373
|
const finish = (error) => {
|
|
2303
2374
|
if (settled) return;
|
|
2304
2375
|
settled = true;
|
|
2376
|
+
if (stallTimer) clearTimeout(stallTimer);
|
|
2305
2377
|
if (error) {
|
|
2306
2378
|
reject(error);
|
|
2307
2379
|
return;
|
|
2308
2380
|
}
|
|
2309
2381
|
resolve({ paths, truncated });
|
|
2310
2382
|
};
|
|
2383
|
+
// A listing that goes silent is killed rather than left holding the
|
|
2384
|
+
// status read (and its limiter slot) open.
|
|
2385
|
+
const armStallTimer = () => {
|
|
2386
|
+
if (stallTimer) clearTimeout(stallTimer);
|
|
2387
|
+
stallTimer = setTimeout(() => {
|
|
2388
|
+
killProcessTree(child);
|
|
2389
|
+
finish(new Error(`git ls-files produced no output for ${GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS}ms in ${dirPath}`));
|
|
2390
|
+
}, GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS);
|
|
2391
|
+
};
|
|
2392
|
+
armStallTimer();
|
|
2311
2393
|
child.stdout.on('data', (chunk) => {
|
|
2394
|
+
armStallTimer();
|
|
2312
2395
|
if (truncated) return;
|
|
2313
2396
|
pending += chunk.toString('utf8');
|
|
2314
2397
|
const records = pending.split('\0');
|
|
@@ -2318,7 +2401,7 @@ const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
|
|
|
2318
2401
|
paths.push(record);
|
|
2319
2402
|
if (paths.length > limit) {
|
|
2320
2403
|
truncated = true;
|
|
2321
|
-
child
|
|
2404
|
+
killProcessTree(child);
|
|
2322
2405
|
finish();
|
|
2323
2406
|
return;
|
|
2324
2407
|
}
|
|
@@ -2426,7 +2509,9 @@ async function readStatus(normalizedDirectory, lightMode) {
|
|
|
2426
2509
|
throw new Error('fatal: not a git repository (or any of the parent directories): .git');
|
|
2427
2510
|
}
|
|
2428
2511
|
|
|
2429
|
-
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory
|
|
2512
|
+
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory, {
|
|
2513
|
+
stallTimeoutMs: GIT_STATUS_STALL_TIMEOUT_MS,
|
|
2514
|
+
});
|
|
2430
2515
|
|
|
2431
2516
|
// `-unormal` lists a directory with no tracked files as one `dir/` entry
|
|
2432
2517
|
// and stops walking it at its first file. `-uall` would walk every file
|
|
@@ -8,6 +8,7 @@ import { loadSourceSections, parseSource, sourceKey } from '../walkthrough/sourc
|
|
|
8
8
|
import { registerGitRoutes } from './routes.js';
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
+
unsupportedRepositoryRootReason,
|
|
11
12
|
checkoutBranch,
|
|
12
13
|
checkoutCommit,
|
|
13
14
|
cherryPick,
|
|
@@ -131,6 +132,23 @@ async function createTempRepo() {
|
|
|
131
132
|
// resolveBaseRefForLog
|
|
132
133
|
// ---------------------------------------------------------------------------
|
|
133
134
|
|
|
135
|
+
describe('unsupportedRepositoryRootReason', () => {
|
|
136
|
+
it('rejects a repository rooted at a filesystem root or the home directory', () => {
|
|
137
|
+
const home = path.join(os.tmpdir(), 'unsupported-root-home');
|
|
138
|
+
expect(unsupportedRepositoryRootReason('/', home)).toBe('filesystem-root');
|
|
139
|
+
expect(unsupportedRepositoryRootReason(path.parse(process.cwd()).root, home)).toBe('filesystem-root');
|
|
140
|
+
expect(unsupportedRepositoryRootReason(home, home)).toBe('home');
|
|
141
|
+
expect(unsupportedRepositoryRootReason(`${home}${path.sep}`, home)).toBe('home');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('accepts an ordinary project root, including one directly under home', () => {
|
|
145
|
+
const home = path.join(os.tmpdir(), 'unsupported-root-home');
|
|
146
|
+
expect(unsupportedRepositoryRootReason(path.join(home, 'project'), home)).toBeNull();
|
|
147
|
+
expect(unsupportedRepositoryRootReason(path.join(os.tmpdir(), 'repo'), home)).toBeNull();
|
|
148
|
+
expect(unsupportedRepositoryRootReason('', home)).toBeNull();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
134
152
|
describe('resolveBaseRefForLog', () => {
|
|
135
153
|
it('returns the local ref unchanged when it exists, even if origin also exists', async () => {
|
|
136
154
|
const checkRef = async (ref) => ref === 'main' || ref === 'refs/remotes/origin/main';
|
|
@@ -104,7 +104,10 @@ persisted "sending" flag would strand a message forever.
|
|
|
104
104
|
next one: `GET /session/status` must not list the session as busy/retry,
|
|
105
105
|
and the trailing message must not be an unfinished assistant reply (the
|
|
106
106
|
status map only lists busy sessions, so a missed busy event leaves no
|
|
107
|
-
entry while a turn still streams).
|
|
107
|
+
entry while a turn still streams). An unfinished reply created before this
|
|
108
|
+
runtime started does not block: its run died with the previous server and
|
|
109
|
+
will never complete, so a restored queue would wait on it forever. A reply
|
|
110
|
+
with no `created` time still blocks. A failed fetch is unknown, never idle:
|
|
108
111
|
the tick re-arms with backoff.
|
|
109
112
|
5. The head is marked in flight (broadcast), then sent:
|
|
110
113
|
- text starting with `/` that names a command in OpenCode's `/command`
|
|
@@ -230,6 +230,13 @@ export function createMessageQueueRuntime({
|
|
|
230
230
|
let writePromise = Promise.resolve();
|
|
231
231
|
let stopped = false;
|
|
232
232
|
|
|
233
|
+
// An unfinished assistant message older than this marker is a run that died
|
|
234
|
+
// with the previous server, not a streaming turn: no completion event will
|
|
235
|
+
// ever arrive for it, so treating it as live strands restored queue items
|
|
236
|
+
// forever. A run that outlived the restart (external OpenCode) is still
|
|
237
|
+
// caught by the live status check, which runs first.
|
|
238
|
+
const runtimeStartedAt = now();
|
|
239
|
+
|
|
233
240
|
/** In-memory only — a restart has no in-flight sends. */
|
|
234
241
|
const sending = new Map(); // sessionId → itemId
|
|
235
242
|
const timers = new Map(); // sessionId → timeout
|
|
@@ -396,7 +403,15 @@ export function createMessageQueueRuntime({
|
|
|
396
403
|
}).catch(() => null));
|
|
397
404
|
if (!messages) return null;
|
|
398
405
|
const last = asRecord(asRecord(messages[messages.length - 1])?.info);
|
|
399
|
-
|
|
406
|
+
const lastTime = asRecord(last?.time);
|
|
407
|
+
if (last?.role === 'assistant' && asCount(lastTime?.completed) === null) {
|
|
408
|
+
const created = asCount(lastTime?.created);
|
|
409
|
+
if (created === null || created >= runtimeStartedAt) return false;
|
|
410
|
+
// Unfinished tail from before this runtime started: its run died with
|
|
411
|
+
// the previous server, so it must not block delivery. (A missing
|
|
412
|
+
// created timestamp stays conservative and blocks, as before.)
|
|
413
|
+
console.log(`[message-queue] ignoring pre-boot unfinished tail for ${sessionId}`);
|
|
414
|
+
}
|
|
400
415
|
return true;
|
|
401
416
|
};
|
|
402
417
|
|
|
@@ -58,7 +58,7 @@ const createOpenCode = () => {
|
|
|
58
58
|
return { state, fetchImpl };
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), knowledge = null, retryDelayMs, resolvePromptBody } = {}) => {
|
|
61
|
+
const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), knowledge = null, retryDelayMs, resolvePromptBody, now } = {}) => {
|
|
62
62
|
let eventHandler = () => {};
|
|
63
63
|
let statusHandler = () => {};
|
|
64
64
|
const broadcasts = [];
|
|
@@ -80,6 +80,7 @@ const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), k
|
|
|
80
80
|
};
|
|
81
81
|
if (retryDelayMs) options.retryDelayMs = retryDelayMs;
|
|
82
82
|
if (resolvePromptBody) options.resolvePromptBody = resolvePromptBody;
|
|
83
|
+
if (now) options.now = now;
|
|
83
84
|
const runtime = createMessageQueueRuntime(options);
|
|
84
85
|
return {
|
|
85
86
|
runtime,
|
|
@@ -206,9 +207,10 @@ describe('message queue runtime', () => {
|
|
|
206
207
|
});
|
|
207
208
|
|
|
208
209
|
it('does not send into a running turn even when the status event says idle', async () => {
|
|
209
|
-
const { runtime, openCode, emit } = createRuntime();
|
|
210
|
+
const { runtime, openCode, emit } = createRuntime({ now: () => 10_000 });
|
|
210
211
|
runtime.start();
|
|
211
|
-
|
|
212
|
+
// Live unfinished turn: created after this runtime started.
|
|
213
|
+
openCode.state.tail = [{ info: { role: 'assistant', time: { created: 10_001 } } }];
|
|
212
214
|
await runtime.enqueue(SESSION, DIRECTORY, item());
|
|
213
215
|
emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
|
|
214
216
|
await settle();
|
|
@@ -216,12 +218,26 @@ describe('message queue runtime', () => {
|
|
|
216
218
|
|
|
217
219
|
// The reply completes: that alone drains the queue (a missed idle event
|
|
218
220
|
// must not strand it).
|
|
219
|
-
openCode.state.tail = [{ info: { role: 'assistant', time: { created:
|
|
220
|
-
emit({ type: 'message.updated', properties: { info: { role: 'assistant', sessionID: SESSION, time: { created:
|
|
221
|
+
openCode.state.tail = [{ info: { role: 'assistant', time: { created: 10_001, completed: 10_002 } } }];
|
|
222
|
+
emit({ type: 'message.updated', properties: { info: { role: 'assistant', sessionID: SESSION, time: { created: 10_001, completed: 10_002 } } } });
|
|
221
223
|
await settle();
|
|
222
224
|
expect(openCode.state.sent).toHaveLength(1);
|
|
223
225
|
});
|
|
224
226
|
|
|
227
|
+
it('delivers past an unfinished tail that predates this runtime (dead pre-restart run)', async () => {
|
|
228
|
+
const { runtime, openCode, emit } = createRuntime({ now: () => 10_000 });
|
|
229
|
+
runtime.start();
|
|
230
|
+
// Assistant reply interrupted by a server restart: unfinished, but older
|
|
231
|
+
// than this runtime — no completion event will ever arrive for it, so it
|
|
232
|
+
// must not block a restored queue forever.
|
|
233
|
+
openCode.state.tail = [{ info: { role: 'assistant', time: { created: 1 } } }];
|
|
234
|
+
await runtime.enqueue(SESSION, DIRECTORY, item());
|
|
235
|
+
emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
|
|
236
|
+
await settle();
|
|
237
|
+
expect(openCode.state.sent).toHaveLength(1);
|
|
238
|
+
expect(openCode.state.sent[0].path).toBe(`/session/${SESSION}/prompt_async`);
|
|
239
|
+
});
|
|
240
|
+
|
|
225
241
|
it('treats an unreachable OpenCode as unknown, not idle', async () => {
|
|
226
242
|
const { runtime, openCode, emit } = createRuntime({ retryDelayMs: () => 10 });
|
|
227
243
|
runtime.start();
|
|
@@ -44,6 +44,7 @@ export const registerNotificationRoutes = (app, dependencies) => {
|
|
|
44
44
|
writeSseEvent,
|
|
45
45
|
getSessionActivitySnapshot,
|
|
46
46
|
getSessionStateSnapshot,
|
|
47
|
+
getPendingBlockingRequestsSnapshot,
|
|
47
48
|
getSessionAttentionSnapshot,
|
|
48
49
|
getSessionState,
|
|
49
50
|
getSessionAttentionState,
|
|
@@ -295,11 +296,15 @@ export const registerNotificationRoutes = (app, dependencies) => {
|
|
|
295
296
|
});
|
|
296
297
|
});
|
|
297
298
|
|
|
299
|
+
// Cross-project seed for clients that do not initialize every directory:
|
|
300
|
+
// live status per session plus the permission and question requests still
|
|
301
|
+
// waiting for an answer. Both come from the server's single upstream stream.
|
|
298
302
|
app.get('/api/sessions/status', async (_req, res) => {
|
|
299
303
|
await ensureSessionWatcher();
|
|
300
304
|
const snapshot = getSessionStateSnapshot();
|
|
301
305
|
res.json({
|
|
302
306
|
sessions: snapshot,
|
|
307
|
+
pending: typeof getPendingBlockingRequestsSnapshot === 'function' ? getPendingBlockingRequestsSnapshot() : {},
|
|
303
308
|
serverTime: Date.now(),
|
|
304
309
|
});
|
|
305
310
|
});
|
|
@@ -422,6 +422,10 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
422
422
|
emitSessionCreatedEvent,
|
|
423
423
|
createSessionGoal: createSessionGoalOverride,
|
|
424
424
|
sessionKnowledgeRuntime = null,
|
|
425
|
+
// Auto routing. Prompts dispatched here go straight to OpenCode, not
|
|
426
|
+
// through the proxy that rewrites the Auto sentinel, so the same hook runs
|
|
427
|
+
// on the body before it is sent. Null when routing is not wired in.
|
|
428
|
+
resolvePromptBody = null,
|
|
425
429
|
} = dependencies;
|
|
426
430
|
|
|
427
431
|
// Last user message of an existing session, as a selection to reuse. Returns
|
|
@@ -596,25 +600,21 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
596
600
|
? await sessionKnowledgeRuntime.resolvePendingForSession(sessionID, directory)
|
|
597
601
|
.catch(() => ({ text: '', signature: '' }))
|
|
598
602
|
: { text: '', signature: '' };
|
|
603
|
+
const payload = {
|
|
604
|
+
model,
|
|
605
|
+
...(agent ? { agent } : {}),
|
|
606
|
+
...(variant ? { variant } : {}),
|
|
607
|
+
parts: [
|
|
608
|
+
...(knowledge.text ? [{ type: 'text', text: knowledge.text, synthetic: true }] : []),
|
|
609
|
+
{ type: 'text', text: expandedPrompt },
|
|
610
|
+
...(goalInput.enabled
|
|
611
|
+
? [{ type: 'text', text: buildGoalIntroText(goalInput.tokenBudget), synthetic: true }]
|
|
612
|
+
: []),
|
|
613
|
+
],
|
|
614
|
+
};
|
|
615
|
+
await resolvePromptBody?.(payload, { sessionId: sessionID, directory });
|
|
599
616
|
try {
|
|
600
|
-
await runPromptAsync({
|
|
601
|
-
baseUrl,
|
|
602
|
-
authHeaders,
|
|
603
|
-
sessionID,
|
|
604
|
-
directory,
|
|
605
|
-
payload: {
|
|
606
|
-
model,
|
|
607
|
-
...(agent ? { agent } : {}),
|
|
608
|
-
...(variant ? { variant } : {}),
|
|
609
|
-
parts: [
|
|
610
|
-
...(knowledge.text ? [{ type: 'text', text: knowledge.text, synthetic: true }] : []),
|
|
611
|
-
{ type: 'text', text: expandedPrompt },
|
|
612
|
-
...(goalInput.enabled
|
|
613
|
-
? [{ type: 'text', text: buildGoalIntroText(goalInput.tokenBudget), synthetic: true }]
|
|
614
|
-
: []),
|
|
615
|
-
],
|
|
616
|
-
},
|
|
617
|
-
});
|
|
617
|
+
await runPromptAsync({ baseUrl, authHeaders, sessionID, directory, payload });
|
|
618
618
|
} catch (error) {
|
|
619
619
|
throw markGoalPartial(error);
|
|
620
620
|
}
|
|
@@ -361,6 +361,55 @@ describe('openchamber session routes', () => {
|
|
|
361
361
|
}
|
|
362
362
|
});
|
|
363
363
|
|
|
364
|
+
it('lets the routing hook replace an Auto default before the prompt leaves', async () => {
|
|
365
|
+
const originalFetch = globalThis.fetch;
|
|
366
|
+
const fetchMock = vi.fn(async (url) => {
|
|
367
|
+
const text = String(url);
|
|
368
|
+
if (text.includes('/prompt_async')) {
|
|
369
|
+
return { ok: true, text: async () => '' };
|
|
370
|
+
}
|
|
371
|
+
if (text.includes('/config/providers')) {
|
|
372
|
+
return { ok: true, json: async () => ({ providers: [{ id: 'openai', models: { 'gpt-5.5': { id: 'gpt-5.5' } } }] }) };
|
|
373
|
+
}
|
|
374
|
+
if (text.includes('/agent')) {
|
|
375
|
+
return { ok: true, json: async () => [{ name: 'build', mode: 'primary' }] };
|
|
376
|
+
}
|
|
377
|
+
if (text.includes('/config')) {
|
|
378
|
+
return { ok: true, json: async () => ({}) };
|
|
379
|
+
}
|
|
380
|
+
return { ok: true, json: async () => ({ id: 'ses_123' }) };
|
|
381
|
+
});
|
|
382
|
+
globalThis.fetch = fetchMock;
|
|
383
|
+
const seen = [];
|
|
384
|
+
const resolvePromptBody = vi.fn(async (body, target) => {
|
|
385
|
+
seen.push({ model: body.model, target });
|
|
386
|
+
body.model = { providerID: 'openai', modelID: 'gpt-5.5' };
|
|
387
|
+
});
|
|
388
|
+
const { app } = createApp({
|
|
389
|
+
readSettingsFromDiskMigrated: async () => ({
|
|
390
|
+
defaultModel: 'openchamber/auto',
|
|
391
|
+
defaultAgent: 'build',
|
|
392
|
+
projects: [{ id: 'proj_1', path: '/repo/app' }],
|
|
393
|
+
}),
|
|
394
|
+
resolvePromptBody,
|
|
395
|
+
});
|
|
396
|
+
try {
|
|
397
|
+
await request(app)
|
|
398
|
+
.post('/api/openchamber/sessions')
|
|
399
|
+
.send({ directory: '/repo/app', prompt: 'Run this' })
|
|
400
|
+
.expect(200);
|
|
401
|
+
|
|
402
|
+
expect(seen).toEqual([{
|
|
403
|
+
model: { providerID: 'openchamber', modelID: 'auto' },
|
|
404
|
+
target: { sessionId: 'ses_123', directory: '/repo/app' },
|
|
405
|
+
}]);
|
|
406
|
+
const promptCall = fetchMock.mock.calls.find(([url]) => String(url).includes('/prompt_async'));
|
|
407
|
+
expect(JSON.parse(promptCall?.[1]?.body).model).toEqual({ providerID: 'openai', modelID: 'gpt-5.5' });
|
|
408
|
+
} finally {
|
|
409
|
+
globalThis.fetch = originalFetch;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
364
413
|
it.each([
|
|
365
414
|
['', { projectId: 'proj_1' }],
|
|
366
415
|
['', { directory: '/repo/app', worktree: { name: 'side-task' } }],
|
|
@@ -32,7 +32,7 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
32
32
|
- `packages/web/server/lib/opencode/tunnel-wiring-runtime.js`: tunnel service/routes composition runtime and active-port wiring for main server startup.
|
|
33
33
|
- `packages/web/server/lib/opencode/startup-pipeline-runtime.js`: server startup tail orchestration runtime for terminal/proxy/static/start-listen flow.
|
|
34
34
|
- `packages/web/server/lib/opencode/startup-performance.js`: opt-in startup phase diagnostics with fixed labels and numeric metadata allowlists.
|
|
35
|
-
- `packages/web/server/lib/agent-tool/runtime.js`: managed OpenCode custom-tool materialization, environment injection,
|
|
35
|
+
- `packages/web/server/lib/agent-tool/runtime.js`: managed OpenCode custom-tool materialization, environment injection, same-machine authentication (loopback, or the bound address for a concrete bind), and fixed CLI action dispatch.
|
|
36
36
|
- `packages/web/server/lib/system-prompt/runtime.js`: opt-in managed OpenCode system-prompt optimizer materialization and plugin injection.
|
|
37
37
|
- `packages/web/server/lib/opencode/managed-plugin-config.js`: the one `OPENCODE_CONFIG_CONTENT` merge every managed plugin (agent tools, system prompt optimizer) appends itself through.
|
|
38
38
|
- `packages/web/server/lib/opencode/server-utils-runtime.js`: shared server runtime utilities for OpenCode proxy wiring, OpenCode port/readiness helpers, and snapshot fetchers.
|
|
@@ -131,6 +131,7 @@ export const createBootstrapRuntime = (dependencies) => {
|
|
|
131
131
|
writeSseEvent,
|
|
132
132
|
getSessionActivitySnapshot: sessionRuntime.getSessionActivitySnapshot,
|
|
133
133
|
getSessionStateSnapshot: sessionRuntime.getSessionStateSnapshot,
|
|
134
|
+
getPendingBlockingRequestsSnapshot: sessionRuntime.getPendingBlockingRequestsSnapshot,
|
|
134
135
|
getSessionAttentionSnapshot: sessionRuntime.getSessionAttentionSnapshot,
|
|
135
136
|
getSessionState: sessionRuntime.getSessionState,
|
|
136
137
|
getSessionAttentionState: sessionRuntime.getSessionAttentionState,
|