@openchamber/web 1.21.0 → 1.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
  8. package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
  9. package/dist/assets/{DiffView-D5cvbEPb.js → DiffView-Db6bjVv1.js} +3 -3
  10. package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
  11. package/dist/assets/GitView-CHzJxTi0.js +6 -0
  12. package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-CggOsLot.js} +1 -1
  13. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
  14. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
  15. package/dist/assets/{OnboardingScreen-w2VG4fWY.js → OnboardingScreen-C98d69Fp.js} +1 -1
  16. package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-DJYMUiXA.js} +1 -1
  17. package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-CY2bx_SB.js} +3 -3
  18. package/dist/assets/PlanView-PkiOY_9H.js +5 -0
  19. package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
  20. package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-oyOm2fHR.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-BP7ebDFF.js} +1 -1
  24. package/dist/assets/{WalkthroughView-D9Q4lr5x.js → WalkthroughView-MuJodAHD.js} +2 -2
  25. package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-CZ0xPeaT.js} +1 -1
  26. package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-C9abMBTb.js} +1 -1
  27. package/dist/assets/de-CEoCz3j6.js +9 -0
  28. package/dist/assets/es-DwyXCqaL.js +15 -0
  29. package/dist/assets/{fr-5qJM0nFS.js → fr-CS7Csln9.js} +5 -5
  30. package/dist/assets/index-CUKcHnUA.css +1 -0
  31. package/dist/assets/{index-Brm3X9rs.js → index-CaPAjwXQ.js} +1 -1
  32. package/dist/assets/index-DIvDEKE-.js +7 -0
  33. package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-DiLRrkJr.js} +1 -1
  35. package/dist/assets/ja-vnwqLcx6.js +15 -0
  36. package/dist/assets/ko-CXuSfZv5.js +15 -0
  37. package/dist/assets/{main-vUCh0VB0.js → main-D5RWr6sJ.js} +2 -2
  38. package/dist/assets/main-DLlfDjQ_.js +926 -0
  39. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  40. package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
  41. package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-CqR3icsk.js} +2 -2
  42. package/dist/assets/{mobile-CkX6H-IT.js → mobile-RN_UTTlB.js} +2 -2
  43. package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-CjRR5ESs.js} +3 -3
  44. package/dist/assets/pl-BJxry0Mi.js +15 -0
  45. package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
  46. package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-1wC94fQK.js} +2 -2
  47. package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
  49. package/dist/assets/{scheduledTasksApi-CAGPh_gZ.js → scheduledTasksApi-mjMDet_H.js} +1 -1
  50. package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-fGmFkxAM.js} +1 -1
  51. package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
  52. package/dist/assets/uk-ClgQjmlw.js +15 -0
  53. package/dist/assets/{useAppFontEffects-Cll4gnsh.js → useAppFontEffects-KP8_yiGW.js} +143 -141
  54. package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-HIjtuhxD.js} +2 -2
  55. package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
  56. package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
  58. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  59. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  60. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  62. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  63. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  64. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  65. package/dist/assets/{web-components-DLnGY4fs.js → web-components-DOXvU-tB.js} +1 -1
  66. package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
  67. package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +3 -3
  70. package/dist/mobile.html +3 -3
  71. package/dist/site.webmanifest +1 -1
  72. package/dist/sw.js +1 -1
  73. package/package.json +2 -2
  74. package/public/site.webmanifest +1 -1
  75. package/server/index.js +2 -2
  76. package/server/lib/cloudflare-tunnel.js +1 -1
  77. package/server/lib/fs/DOCUMENTATION.md +1 -0
  78. package/server/lib/fs/routes.js +21 -0
  79. package/server/lib/fs/routes.test.js +89 -3
  80. package/server/lib/git/DOCUMENTATION.md +4 -3
  81. package/server/lib/git/service.js +128 -6
  82. package/server/lib/git/service.test.js +191 -1
  83. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  84. package/server/lib/markdown-image-grants/routes.js +3 -1
  85. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  86. package/server/lib/openchamber-sessions/routes.js +4 -1
  87. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  88. package/server/lib/opencode/env-runtime.js +17 -1
  89. package/server/lib/opencode/env-runtime.test.js +56 -0
  90. package/server/lib/opencode/lifecycle.js +48 -9
  91. package/server/lib/opencode/lifecycle.test.js +125 -1
  92. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  93. package/server/lib/opencode/managed-process-registry.js +213 -163
  94. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  95. package/server/lib/opencode/project-directory-runtime.js +16 -11
  96. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  97. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  98. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  99. package/server/lib/opencode/routes.js +53 -5
  100. package/server/lib/opencode/settings-helpers.js +3 -0
  101. package/server/lib/opencode/settings-helpers.test.js +10 -0
  102. package/server/lib/opencode/theme-runtime.js +1 -1
  103. package/server/lib/opencode/theme-runtime.test.js +129 -0
  104. package/server/lib/quota/DOCUMENTATION.md +19 -0
  105. package/server/lib/quota/providers/copilot.js +26 -10
  106. package/server/lib/quota/providers/copilot.test.js +78 -0
  107. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  108. package/server/lib/small-model/call.js +64 -20
  109. package/server/lib/small-model/call.test.js +184 -2
  110. package/server/lib/tunnels/install-help.js +2 -2
  111. package/server/lib/tunnels/install-help.test.js +9 -0
  112. package/server/lib/walkthrough/languages.js +1 -0
  113. package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
  114. package/dist/assets/FilesView-DPU8aNPL.js +0 -17
  115. package/dist/assets/GitView-Ct6xWrVH.js +0 -6
  116. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
  117. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
  118. package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
  119. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
  120. package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
  121. package/dist/assets/de-B_LdJwEM.js +0 -9
  122. package/dist/assets/es-CubfsAYV.js +0 -15
  123. package/dist/assets/index-BW82eK5v.css +0 -1
  124. package/dist/assets/index-rlLjZUM5.js +0 -7
  125. package/dist/assets/ja-DJYIBUlH.js +0 -15
  126. package/dist/assets/ko-DcUBkB7y.js +0 -15
  127. package/dist/assets/main-DLBxKIoX.js +0 -926
  128. package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
  129. package/dist/assets/pl-rB6BLcio.js +0 -15
  130. package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
  131. package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
  132. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
  133. package/dist/assets/uk-INZlFD9A.js +0 -15
  134. package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
  135. package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
package/dist/index.html CHANGED
@@ -18,7 +18,7 @@
18
18
  <!-- Web app manifest (endpoint-first with data URL fallback) -->
19
19
  <script>
20
20
  const baseUrl = location.origin;
21
- const defaultAppName = 'OpenChamber - AI Coding Assistant';
21
+ const defaultAppName = 'OpenChamber';
22
22
  const defaultShortName = 'OpenChamber';
23
23
  const pwaNameStorageKey = 'openchamber.pwaName';
24
24
  const pwaOrientationStorageKey = 'openchamber.pwaOrientation';
@@ -509,16 +509,16 @@
509
509
  pointer-events: none;
510
510
  }
511
511
  </style>
512
- <script type="module" crossorigin src="/assets/main-vUCh0VB0.js"></script>
512
+ <script type="module" crossorigin src="/assets/main-D5RWr6sJ.js"></script>
513
513
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
514
514
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
515
515
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
516
516
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
517
517
  <link rel="modulepreload" crossorigin href="/assets/vendor-zod-BLfBSgBh.js">
518
518
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
519
- <link rel="modulepreload" crossorigin href="/assets/index-rlLjZUM5.js">
520
- <link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-CpzVNWAv.js">
521
- <link rel="stylesheet" crossorigin href="/assets/index-BW82eK5v.css">
519
+ <link rel="modulepreload" crossorigin href="/assets/index-DIvDEKE-.js">
520
+ <link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-C9abMBTb.js">
521
+ <link rel="stylesheet" crossorigin href="/assets/index-CUKcHnUA.css">
522
522
  </head>
523
523
  <body class="h-full bg-background text-foreground">
524
524
  <div id="root" class="h-full">
@@ -74,15 +74,15 @@
74
74
  }
75
75
  </style>
76
76
 
77
- <script type="module" crossorigin src="/assets/miniChat-BlzGEYgE.js"></script>
77
+ <script type="module" crossorigin src="/assets/miniChat-CqR3icsk.js"></script>
78
78
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
79
79
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
80
80
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
81
81
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
82
82
  <link rel="modulepreload" crossorigin href="/assets/vendor-zod-BLfBSgBh.js">
83
83
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
84
- <link rel="modulepreload" crossorigin href="/assets/index-rlLjZUM5.js">
85
- <link rel="stylesheet" crossorigin href="/assets/index-BW82eK5v.css">
84
+ <link rel="modulepreload" crossorigin href="/assets/index-DIvDEKE-.js">
85
+ <link rel="stylesheet" crossorigin href="/assets/index-CUKcHnUA.css">
86
86
  </head>
87
87
  <body class="h-full bg-background text-foreground">
88
88
  <div id="root" class="h-full">
package/dist/mobile.html CHANGED
@@ -63,15 +63,15 @@
63
63
  })();
64
64
  </script>
65
65
 
66
- <script type="module" crossorigin src="/assets/mobile-CkX6H-IT.js"></script>
66
+ <script type="module" crossorigin src="/assets/mobile-RN_UTTlB.js"></script>
67
67
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
68
68
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
69
69
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
70
70
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
71
71
  <link rel="modulepreload" crossorigin href="/assets/vendor-zod-BLfBSgBh.js">
72
72
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
73
- <link rel="modulepreload" crossorigin href="/assets/index-rlLjZUM5.js">
74
- <link rel="stylesheet" crossorigin href="/assets/index-BW82eK5v.css">
73
+ <link rel="modulepreload" crossorigin href="/assets/index-DIvDEKE-.js">
74
+ <link rel="stylesheet" crossorigin href="/assets/index-CUKcHnUA.css">
75
75
  </head>
76
76
  <body class="h-full bg-background text-foreground">
77
77
  <div id="root" class="h-full"></div>
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "OpenChamber - AI Coding Companion",
2
+ "name": "OpenChamber",
3
3
  "short_name": "OpenChamber",
4
4
  "description": "OpenChamber desktop companion for the OpenCode AI coding agent",
5
5
  "start_url": "/",
package/dist/sw.js CHANGED
@@ -1 +1 @@
1
- (function(){"use strict";self.addEventListener("install",t=>{t.waitUntil(self.skipWaiting())}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),self.addEventListener("push",t=>{t.waitUntil((async()=>{const i=t.data?.json()??null;if(!i||(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).some(a=>a.visibilityState==="visible"||a.focused))return;const e=i.title||"OpenChamber",s=i.body??"",l=i.icon??"/apple-touch-icon-180x180.png",o=i.badge??"/favicon-32.png";await self.registration.showNotification(e,{body:s,icon:l,badge:o,tag:i.tag,data:i.data})})())}),self.addEventListener("notificationclick",t=>{t.notification.close();const n=(t.notification.data??null)?.url??"/";t.waitUntil(self.clients.openWindow(n))})})();
1
+ (function(){"use strict";self.addEventListener("install",t=>{t.waitUntil(self.skipWaiting())}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),self.addEventListener("push",t=>{t.waitUntil((async()=>{const i=t.data?.json()??null;if(!i||(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).some(l=>l.visibilityState==="visible"||l.focused))return;const a=i.title||"OpenChamber",n=i.body??"",o=i.icon??"/apple-touch-icon-180x180.png",c=i.badge??"/favicon-32.png";await self.registration.showNotification(a,{body:n,icon:o,badge:c,tag:i.tag,data:i.data})})())}),self.addEventListener("notificationclick",t=>{t.notification.close();const s=(t.notification.data??null)?.url??"/";t.waitUntil((async()=>{const e=new URL(s,self.location.origin).href,a=await self.clients.matchAll({type:"window",includeUncontrolled:!0});for(const n of a){try{"navigate"in n&&await n.navigate(e)}catch{}if("focus"in n)return n.focus()}if(self.clients.openWindow)return self.clients.openWindow(e)})())})})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openchamber/web",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./server/index.js",
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@clack/prompts": "^1.1.0",
27
27
  "@octokit/rest": "^22.0.1",
28
- "@opencode-ai/sdk": "1.18.23",
28
+ "@opencode-ai/sdk": "1.18.25",
29
29
  "@simplewebauthn/server": "13.3.1",
30
30
  "bun-pty": "^0.4.5",
31
31
  "compression": "^1.8.1",
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "OpenChamber - AI Coding Companion",
2
+ "name": "OpenChamber",
3
3
  "short_name": "OpenChamber",
4
4
  "description": "OpenChamber desktop companion for the OpenCode AI coding agent",
5
5
  "start_url": "/",
package/server/index.js CHANGED
@@ -1162,8 +1162,8 @@ const openCodeLifecycleRuntime = createOpenCodeLifecycleRuntime({
1162
1162
  return [...new Set(directories)];
1163
1163
  },
1164
1164
  // A managed restart can move OpenCode to a NEW port (the old one may stay
1165
- // occupied by an orphaned process, e.g. killProcessOnPort is a no-op on
1166
- // Windows). Rebind the message-stream upstream readers to the current port
1165
+ // occupied if killProcessOnPort/waitForPortRelease didn't free it in time,
1166
+ // on any platform). Rebind the message-stream upstream readers to the current port
1167
1167
  // so the UI keeps receiving events instead of staying pinned to the old
1168
1168
  // process (#2638). The runtime is created later by the startup pipeline;
1169
1169
  // by the time any restart runs, it is assigned.
@@ -64,7 +64,7 @@ Install instructions for your platform:
64
64
  Windows: winget install --id Cloudflare.cloudflared
65
65
  Linux: Download from https://github.com/cloudflare/cloudflared/releases
66
66
 
67
- Or visit: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/
67
+ Or visit: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/
68
68
  `);
69
69
  }
70
70
 
@@ -25,6 +25,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
25
25
  - `GET /api/fs/list`
26
26
  - Owns exec job queue state (`execJobs`) and lifecycle/TTL pruning.
27
27
  - Enforces workspace boundary checks with active project + worktree fallback support.
28
+ - The active project directory is validated with `fs.realpath`, so when the project root is itself a symlink the workspace base no longer matches the paths the client sends. Workspace resolution therefore retries against the raw directory the client requested (`requestedDirectory` from `resolveProjectDirectory`) before falling back to worktree roots. Symlinks are still resolved afterwards, and write/exec routes keep their canonical containment check against the resolved base.
28
29
  - `createFsSearchRuntime({ fsPromises, path, spawn, resolveGitBinaryForSpawn })` from `search.js`
29
30
  - Returns `{ searchFilesystemFiles(rootPath, options) }`.
30
31
  - Supports fuzzy matching, hidden-file handling, and optional `git check-ignore` filtering.
@@ -267,6 +267,27 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
267
267
  return resolved;
268
268
  }
269
269
 
270
+ // The active project directory is validated with fs.realpath, so the base is
271
+ // canonical while the client (and the file tree) addresses files under the
272
+ // user-visible root, which may itself be a symlink. Retry against the raw
273
+ // directory the client asked for so those paths stay addressable. Symlink
274
+ // resolution still happens afterwards, and the routes that need canonical
275
+ // containment re-check it against this base.
276
+ const requestedBase = resolvedProject.requestedDirectory;
277
+ if (typeof requestedBase === 'string' && requestedBase && requestedBase !== resolvedProject.directory) {
278
+ const lexical = resolveWorkspacePath({
279
+ targetPath,
280
+ baseDirectory: requestedBase,
281
+ path,
282
+ os,
283
+ normalizeDirectoryPath,
284
+ openchamberUserConfigRoot,
285
+ });
286
+ if (lexical.ok) {
287
+ return lexical;
288
+ }
289
+ }
290
+
270
291
  return resolveWorkspacePathFromWorktrees({
271
292
  targetPath,
272
293
  baseDirectory: resolvedProject.directory,
@@ -165,7 +165,7 @@ const registerUpload = (fsPromises) => {
165
165
  return getRoute('POST', '/api/fs/upload');
166
166
  };
167
167
 
168
- const registerRead = (fsPromises) => {
168
+ const registerRead = (fsPromises, resolveProjectDirectory = async () => ({ directory: '/repo' })) => {
169
169
  const { app, getRoute } = createRouteRegistry();
170
170
  registerFsRoutes(app, {
171
171
  os: { homedir: () => '/home/user' },
@@ -177,7 +177,7 @@ const registerRead = (fsPromises) => {
177
177
  spawn: vi.fn(),
178
178
  crypto: { randomUUID: () => 'job-0' },
179
179
  normalizeDirectoryPath: (p) => p,
180
- resolveProjectDirectory: async () => ({ directory: '/repo' }),
180
+ resolveProjectDirectory,
181
181
  buildAugmentedPath: () => '/usr/bin',
182
182
  resolveGitBinaryForSpawn: () => 'git',
183
183
  openchamberUserConfigRoot: '/home/user/.config',
@@ -682,8 +682,94 @@ describe('fs read', () => {
682
682
  expect(warn).toHaveBeenCalledWith(expect.stringContaining('Read retry exhausted for /repo/file.txt'));
683
683
  warn.mockRestore();
684
684
  });
685
- });
686
685
 
686
+ it('reads files inside the workspace whose canonical path escapes through a symlinked directory', async () => {
687
+ // ~/test_folder -> /outside/shared: the requested path is lexically inside
688
+ // the workspace, the realpath is not. The read must follow the symlink
689
+ // instead of rejecting it as an outside path.
690
+ const fsPromises = {
691
+ realpath: vi.fn(async (targetPath) => {
692
+ if (targetPath === '/repo/link/file.txt') return '/outside/shared/file.txt';
693
+ return targetPath;
694
+ }),
695
+ stat: vi.fn(async () => ({ isFile: () => true, size: 5 })),
696
+ readFile: vi.fn(async () => 'hello'),
697
+ };
698
+ const handler = registerRead(fsPromises);
699
+
700
+ const res = await callRead(handler, { path: '/repo/link/file.txt' });
701
+
702
+ expect(res.statusCode).toBe(200);
703
+ expect(res.body).toBe('hello');
704
+ expect(fsPromises.readFile).toHaveBeenCalledWith('/outside/shared/file.txt', 'utf8');
705
+ });
706
+
707
+ it('rejects reads of canonical paths outside the workspace that no workspace symlink reaches', async () => {
708
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
709
+ const fsPromises = {
710
+ stat: vi.fn(async () => ({ isFile: () => true, size: 6 })),
711
+ readFile: vi.fn(async () => 'secret'),
712
+ };
713
+ const handler = registerRead(fsPromises);
714
+
715
+ const res = await callRead(handler, { path: '/outside/shared/file.txt' });
716
+
717
+ expect(res.statusCode).toBe(400);
718
+ expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
719
+ expect(fsPromises.readFile).not.toHaveBeenCalled();
720
+ warn.mockRestore();
721
+ });
722
+
723
+ it('reads files under a symlinked project root addressed via the client-sent lexical directory', async () => {
724
+ // /home/user/proj -> /real/proj: the validated base is canonical but the
725
+ // client (and the file tree) address files under the lexical root.
726
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
727
+ const fsPromises = {
728
+ realpath: vi.fn(async (targetPath) => {
729
+ if (targetPath === '/home/user/proj') return '/real/proj';
730
+ if (targetPath === '/home/user/proj/file.txt') return '/real/proj/file.txt';
731
+ return targetPath;
732
+ }),
733
+ stat: vi.fn(async () => ({ isFile: () => true, size: 4 })),
734
+ readFile: vi.fn(async () => 'data'),
735
+ };
736
+ const handler = registerRead(fsPromises, async () => ({
737
+ directory: '/real/proj',
738
+ requestedDirectory: '/home/user/proj',
739
+ }));
740
+ const res = createMockResponse();
741
+
742
+ await handler({
743
+ query: { path: '/home/user/proj/file.txt' },
744
+ get: (name) => (name === 'x-opencode-directory' ? '/home/user/proj' : undefined),
745
+ }, res);
746
+
747
+ expect(res.statusCode).toBe(200);
748
+ expect(res.body).toBe('data');
749
+ expect(fsPromises.readFile).toHaveBeenCalledWith('/real/proj/file.txt', 'utf8');
750
+ warn.mockRestore();
751
+ });
752
+
753
+ it('rejects path traversal that escapes the workspace even when it passes through a symlinked directory', async () => {
754
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
755
+ const fsPromises = {
756
+ realpath: vi.fn(async (targetPath) => {
757
+ if (targetPath === '/repo/link') return '/outside/shared';
758
+ return targetPath;
759
+ }),
760
+ stat: vi.fn(async () => ({ isFile: () => true, size: 6 })),
761
+ readFile: vi.fn(async () => 'secret'),
762
+ };
763
+ const handler = registerRead(fsPromises);
764
+
765
+ const res = await callRead(handler, { path: '/repo/sub/../../etc/passwd' });
766
+
767
+ expect(res.statusCode).toBe(400);
768
+ expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
769
+ expect(fsPromises.readFile).not.toHaveBeenCalled();
770
+ warn.mockRestore();
771
+ });
772
+ });
687
773
  describe('fs reveal', () => {
688
774
  it.each([
689
775
  ['linux', 'xdg-open', ['/repo']],
@@ -40,7 +40,7 @@ The following functions are exported and used by the web server:
40
40
  ### Branch Operations
41
41
  - `getBranches(directory)`: Get list of local and remote branches (filtered to active remote branches).
42
42
  - `createBranch(directory, branchName, options)`: Create and checkout a new branch.
43
- - `checkoutBranch(directory, branchName)`: Checkout an existing branch.
43
+ - `checkoutBranch(directory, branchName)`: Checkout an existing branch. A remote-tracking name (`origin/main`, or the `remotes/`-prefixed form) resolves to the local branch of that name, created with `--track` when it does not exist yet, because the branch selector offers remote branches as places to work rather than commits to inspect — a literal checkout of the remote ref would detach HEAD. A local branch whose own name looks like a remote ref wins over that resolution, and anything unresolvable is checked out as requested. The returned `branch` is the branch that was actually checked out, which callers should report instead of the requested name.
44
44
  - `deleteBranch(directory, branch, options)`: Delete a branch (supports force flag).
45
45
  - `renameBranch(directory, oldName, newName)`: Rename a branch and preserve upstream tracking.
46
46
  - `getRemotes(directory)`: Get list of configured remotes.
@@ -121,9 +121,10 @@ The following functions are internal helpers used by exported functions:
121
121
  - `rebaseInProgress`: Object with `{ headName, onto }` if rebase in progress.
122
122
 
123
123
  ### Branches Response
124
- - `all`: Local branches plus remote-tracking branches that still exist on their remote. A remote that fails to answer keeps its branches in the list: "we could not ask" must not be reported as "these branches are gone", because callers use this list to decide whether a base branch exists at all.
124
+ - `all`: Local branches plus every branch each reachable remote reports via `ls-remote --heads`, formatted as `remotes/<remote>/<branch>`. This is a union: local remote-tracking refs deleted on the remote are pruned, and branches that exist on the remote without a local tracking ref (never fetched) are still included, so a freshly pushed branch appears without requiring a fetch. A remote that fails to answer keeps its locally known branches in the list: "we could not ask" must not be reported as "these branches are gone", because callers use this list to decide whether a base branch exists at all.
125
125
  - `current`: Current branch name.
126
- - `branches`: Per-branch detail keyed by branch name, as reported by `git branch`.
126
+ - `branches`: Per-branch detail keyed by branch name, as reported by `git branch`. Remote-only entries in `all` — branches `ls-remote` reported that were never fetched — have **no** entry here, because `git branch` never saw them. Consumers must treat a missing detail entry as normal and read the name from `all`.
127
+ - Never-fetched remote-only branches also have no local ref, so any operation that resolves one locally has to account for that: `checkoutBranch` fetches the single branch (`git fetch <remote> <branch>`) before creating the tracking branch, and the range helpers (`getRangeDiff`, `getRangeFiles`) reject an unresolvable ref with `Ref "<ref>" is not available locally. Fetch it before comparing.` instead of surfacing git's "ambiguous argument".
127
128
  - `defaultBranches`: Each remote's default branch, keyed by remote name. Read from the local `remotes/<name>/HEAD` symbolic ref; for a remote that has none — clone writes it, a hand-added remote may not — the remote itself is asked once with `ls-remote --symref`. A remote that answers neither is absent rather than guessed, and consumers fall back to conventional branch names. Omitted entirely by runtimes that do not provide this Git metadata.
128
129
 
129
130
  ### Runtime availability of range diffs
@@ -2599,6 +2599,25 @@ export async function getUntrackedDiffs(directory, filePaths = [], { concurrency
2599
2599
  return results;
2600
2600
  }
2601
2601
 
2602
+ const refResolvesToCommit = async (git, ref) => git
2603
+ .raw(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`])
2604
+ .then((value) => Boolean(String(value || '').trim()))
2605
+ .catch(() => false);
2606
+
2607
+ /**
2608
+ * The branch list includes remote-only branches that `ls-remote` reported but
2609
+ * the repository never fetched (#2098), so a comparison can name a ref that does
2610
+ * not exist locally. Say that plainly instead of letting git's "ambiguous
2611
+ * argument" surface as an opaque failure.
2612
+ */
2613
+ async function assertRangeRefsResolve(git, refs) {
2614
+ for (const ref of refs) {
2615
+ if (!(await refResolvesToCommit(git, ref))) {
2616
+ throw new Error(`Ref "${ref}" is not available locally. Fetch it before comparing.`);
2617
+ }
2618
+ }
2619
+ }
2620
+
2602
2621
  export async function getRangeDiff(directory, { base, head, path: filePath, contextLines = 3 } = {}) {
2603
2622
  const { directoryPath, directoryGit, repoRoot, git } = await createRepositoryGitContext(directory);
2604
2623
  const baseRef = typeof base === 'string' ? base.trim() : '';
@@ -2641,6 +2660,8 @@ export async function getRangeDiff(directory, { base, head, path: filePath, cont
2641
2660
  }
2642
2661
  }
2643
2662
 
2663
+ await assertRangeRefsResolve(git, [resolvedBase, headRef]);
2664
+
2644
2665
  const args = ['diff', '--no-color'];
2645
2666
  if (typeof contextLines === 'number' && !Number.isNaN(contextLines)) {
2646
2667
  args.push(`-U${Math.max(0, contextLines)}`);
@@ -2660,7 +2681,8 @@ const BRANCH_CREATION_SOURCE_RE = /^branch: Created from (.+)$/;
2660
2681
  * Parse a branch reflog (`git reflog show --format=%gs <branch>`) and return the
2661
2682
  * ref the branch was created from, when that source is itself a named ref.
2662
2683
  *
2663
- * Returns null when the branch was created from `HEAD@{...}` or a raw commit
2684
+ * Returns null when the branch was created from `HEAD` (bare, as `git switch -c`
2685
+ * / `git checkout -b` without an explicit start point record) or a raw commit
2664
2686
  * (detached start): the original branch name is not recorded anywhere in that
2665
2687
  * case, and guessing a base from commit topology would be a heuristic, not an
2666
2688
  * answer. Callers should ask the user to pick a base instead.
@@ -2675,7 +2697,9 @@ export function parseBranchCreationSource(reflogText) {
2675
2697
  const match = lines[index].match(BRANCH_CREATION_SOURCE_RE);
2676
2698
  if (!match) continue;
2677
2699
  const source = match[1].trim();
2678
- if (!source || /^HEAD@/.test(source) || /^[0-9a-f]{7,40}$/i.test(source)) {
2700
+ // Bare `HEAD` (`git switch -c` from the current branch) and `HEAD@{...}`
2701
+ // (detached start) both lack a named source; a raw commit hash does too.
2702
+ if (!source || /^HEAD(@|$)/.test(source) || /^[0-9a-f]{7,40}$/i.test(source)) {
2679
2703
  return null;
2680
2704
  }
2681
2705
  return source;
@@ -2738,6 +2762,8 @@ export async function getRangeFiles(directory, { base, head } = {}) {
2738
2762
  // ignore
2739
2763
  }
2740
2764
 
2765
+ await assertRangeRefsResolve(git, [resolvedBase, headRef]);
2766
+
2741
2767
  // `-C` (copy detection among changed files only, so cheap) makes copies
2742
2768
  // surface as C entries instead of plain additions; rename detection is on
2743
2769
  // by default.
@@ -3744,7 +3770,7 @@ async function filterActiveRemoteBranches(git, remoteBranches) {
3744
3770
  }
3745
3771
  }));
3746
3772
 
3747
- return remoteBranches.filter(remoteBranch => {
3773
+ const activeBranches = remoteBranches.filter(remoteBranch => {
3748
3774
  const match = remoteBranch.match(/^remotes\/[^\/]+\/(.+)$/);
3749
3775
  if (!match) return false;
3750
3776
  const remoteName = remoteBranch.split('/')[1];
@@ -3752,6 +3778,25 @@ async function filterActiveRemoteBranches(git, remoteBranches) {
3752
3778
  if (unreachableRemotes.has(remoteName)) return true;
3753
3779
  return branchesByRemote.get(remoteName)?.has(branchName) ?? false;
3754
3780
  });
3781
+
3782
+ // A branch pushed to the remote that was never fetched locally has no
3783
+ // remote-tracking ref, so `git branch` never reports it — but ls-remote
3784
+ // just told us it exists. Add those so a freshly pushed branch shows up
3785
+ // without requiring a fetch first (#2098). Unreachable remotes have no
3786
+ // ls-remote data and therefore add nothing here; their local view above
3787
+ // is preserved unchanged.
3788
+ const seenBranches = new Set(activeBranches);
3789
+ for (const [remoteName, actualRemoteBranches] of branchesByRemote) {
3790
+ for (const branchName of actualRemoteBranches) {
3791
+ const qualifiedBranch = `remotes/${remoteName}/${branchName}`;
3792
+ if (!seenBranches.has(qualifiedBranch)) {
3793
+ seenBranches.add(qualifiedBranch);
3794
+ activeBranches.push(qualifiedBranch);
3795
+ }
3796
+ }
3797
+ }
3798
+
3799
+ return activeBranches;
3755
3800
  } catch (error) {
3756
3801
  console.warn('Failed to filter active remote branches, returning all:', error.message);
3757
3802
  return remoteBranches;
@@ -3770,12 +3815,81 @@ export async function createBranch(directory, branchName, options = {}) {
3770
3815
  }
3771
3816
  }
3772
3817
 
3818
+ // Deliberately not `--quiet`: simple-git resolves a quiet non-zero exit as
3819
+ // success, so the ref itself has to be echoed for the answer to mean anything.
3820
+ const gitRefExists = async (git, ref) => {
3821
+ try {
3822
+ const output = await git.raw(['show-ref', '--verify', ref]);
3823
+ return String(output).trim().length > 0;
3824
+ } catch {
3825
+ return false;
3826
+ }
3827
+ };
3828
+
3829
+ /**
3830
+ * The branch selector lists remote-tracking branches beside local ones, so
3831
+ * picking `origin/main` means "work on main", not "detach HEAD at the remote's
3832
+ * commit" — which is what a literal checkout of a remote-tracking ref does.
3833
+ * Resolve such a pick to the local branch, creating it with tracking when it
3834
+ * does not exist yet. Anything we cannot resolve is checked out as requested,
3835
+ * leaving git's own DWIM behavior intact.
3836
+ */
3837
+ const resolveBranchCheckoutTarget = async (git, branchName) => {
3838
+ const requested = String(branchName || '').trim();
3839
+ if (!requested) {
3840
+ throw new Error('Branch name is required');
3841
+ }
3842
+
3843
+ const asRequested = { branch: requested, remoteRef: null };
3844
+
3845
+ if (await gitRefExists(git, `refs/heads/${requested}`)) {
3846
+ return asRequested;
3847
+ }
3848
+
3849
+ const remoteRef = requested.replace(/^remotes\//, '');
3850
+ const remotes = await git.getRemotes();
3851
+ const remote = remotes.find((entry) => entry?.name && remoteRef.startsWith(`${entry.name}/`));
3852
+ if (!remote) {
3853
+ return asRequested;
3854
+ }
3855
+
3856
+ const localBranch = remoteRef.slice(remote.name.length + 1);
3857
+ // `origin/HEAD` names no branch of its own; it is a pointer to one.
3858
+ if (!localBranch || localBranch === 'HEAD') {
3859
+ return asRequested;
3860
+ }
3861
+
3862
+ // The branch list also carries branches that only `ls-remote` knows about
3863
+ // (#2098): they exist on the remote but were never fetched, so there is no
3864
+ // remote-tracking ref and a literal checkout fails with a pathspec error.
3865
+ // Fetch the single branch first so the tracking ref exists, then fall through
3866
+ // to the normal create-with-tracking path.
3867
+ if (!(await gitRefExists(git, `refs/remotes/${remoteRef}`))) {
3868
+ try {
3869
+ await git.fetch(remote.name, localBranch);
3870
+ } catch (error) {
3871
+ throw new Error(`Failed to fetch ${localBranch} from ${remote.name}: ${error?.message || error}`);
3872
+ }
3873
+ if (!(await gitRefExists(git, `refs/remotes/${remoteRef}`))) {
3874
+ throw new Error(`Branch ${localBranch} no longer exists on remote ${remote.name}`);
3875
+ }
3876
+ }
3877
+
3878
+ const localExists = await gitRefExists(git, `refs/heads/${localBranch}`);
3879
+ return { branch: localBranch, remoteRef: localExists ? null : remoteRef };
3880
+ };
3881
+
3773
3882
  export async function checkoutBranch(directory, branchName) {
3774
3883
  const { git } = await createRepositoryGitContext(directory);
3775
3884
 
3776
3885
  try {
3777
- await git.checkout(branchName);
3778
- return { success: true, branch: branchName };
3886
+ const target = await resolveBranchCheckoutTarget(git, branchName);
3887
+ if (target.remoteRef) {
3888
+ await git.raw(['checkout', '-b', target.branch, '--track', target.remoteRef]);
3889
+ } else {
3890
+ await git.checkout(target.branch);
3891
+ }
3892
+ return { success: true, branch: target.branch };
3779
3893
  } catch (error) {
3780
3894
  console.error('Failed to checkout branch:', error);
3781
3895
  throw error;
@@ -3895,7 +4009,15 @@ export async function getWorktrees(directory) {
3895
4009
  path: entry.worktree,
3896
4010
  }));
3897
4011
  } catch (error) {
3898
- console.warn('Failed to list worktrees, returning empty list:', error?.message || error);
4012
+ // Worktrees are an optional feature. When the caller passes a directory
4013
+ // that is not inside any git repository (for example, the managed
4014
+ // OpenCode's working directory or an unconfigured project path), git
4015
+ // exits with "fatal: not a git repository ...". Treat that as an
4016
+ // authoritative empty result so the route handler can still respond
4017
+ // 200 [] and the desktop main.log stays free of noise.
4018
+ if (!isNotGitRepositoryError(error)) {
4019
+ console.warn('Failed to list worktrees, returning empty list:', error?.message || error);
4020
+ }
3899
4021
  return [];
3900
4022
  }
3901
4023
  }