@openchamber/web 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
- package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
- package/dist/assets/FilesView-B_NJFLBH.js +17 -0
- package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
- package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
- package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
- package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
- package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
- package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
- package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
- package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
- package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
- package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
- package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
- package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
- package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
- package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
- package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
- package/dist/assets/de-D4hpTCNY.js +10 -0
- package/dist/assets/es-Bw9m3H62.js +16 -0
- package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
- package/dist/assets/fr-Bhll42P0.js +14 -0
- package/dist/assets/index-Btd2mmYT.js +42 -0
- package/dist/assets/index-C-7hQnEc.css +1 -0
- package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
- package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
- package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
- package/dist/assets/ja-CsHoT43d.js +16 -0
- package/dist/assets/ko-BBNdtFa4.js +16 -0
- package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
- package/dist/assets/main-kYkr_urz.js +1000 -0
- package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
- package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
- package/dist/assets/mobile-CviaXnnU.js +2 -0
- package/dist/assets/nl-DszyktfH.js +16 -0
- package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
- package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
- package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
- package/dist/assets/pl-Bk9_mUXc.js +16 -0
- package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
- package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
- package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
- package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
- package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
- package/dist/assets/space-close-C1tL-_0t.js +1 -0
- package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
- package/dist/assets/tr-C_13w7CX.js +7 -0
- package/dist/assets/uk-BZTsG-q_.js +16 -0
- package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
- package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
- package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
- package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
- package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
- package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
- package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
- package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
- package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
- package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
- package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
- package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
- package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +4 -4
- package/server/index.js +58 -1
- package/server/lib/browser-control/DOCUMENTATION.md +8 -1
- package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
- package/server/lib/dev-tunnel/runtime.js +94 -38
- package/server/lib/dev-tunnel/tunnel.test.js +16 -2
- package/server/lib/dictation/DOCUMENTATION.md +23 -10
- package/server/lib/dictation/audio.js +28 -0
- package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
- package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
- package/server/lib/dictation/local/worker-client.js +28 -10
- package/server/lib/dictation/local/worker-process.js +25 -1
- package/server/lib/dictation/stream-manager.js +160 -53
- package/server/lib/dictation/stream-manager.test.js +108 -7
- package/server/lib/enterprise-mode.d.ts +2 -0
- package/server/lib/enterprise-mode.js +84 -9
- package/server/lib/enterprise-mode.test.js +115 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -2
- package/server/lib/fs/routes.js +28 -1
- package/server/lib/fs/routes.test.js +31 -5
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +61 -2
- package/server/lib/git/service.test.js +141 -0
- package/server/lib/github/DOCUMENTATION.md +18 -0
- package/server/lib/github/checks-summary.js +76 -0
- package/server/lib/github/pr-summaries.js +282 -0
- package/server/lib/github/pr-summaries.test.js +209 -0
- package/server/lib/github/routes.js +42 -77
- package/server/lib/github/routes.test.js +77 -0
- package/server/lib/inherited-env.js +51 -0
- package/server/lib/inherited-env.test.js +59 -0
- package/server/lib/message-search/DOCUMENTATION.md +83 -0
- package/server/lib/message-search/indexer.js +336 -0
- package/server/lib/message-search/indexer.test.js +341 -0
- package/server/lib/message-search/routes.js +92 -0
- package/server/lib/message-search/runtime.js +234 -0
- package/server/lib/message-search/runtime.test.js +108 -0
- package/server/lib/message-search/sqlite.js +74 -0
- package/server/lib/message-search/store.js +289 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
- package/server/lib/openchamber-control/actions.js +1 -1
- package/server/lib/openchamber-control/service.js +21 -2
- package/server/lib/openchamber-control/service.test.js +50 -0
- package/server/lib/openchamber-sessions/routes.js +15 -0
- package/server/lib/openchamber-sessions/routes.test.js +31 -0
- package/server/lib/opencode/DOCUMENTATION.md +43 -38
- package/server/lib/opencode/auth.d.ts +24 -0
- package/server/lib/opencode/auth.js +130 -66
- package/server/lib/opencode/auth.test.js +114 -70
- package/server/lib/opencode/compatibility.js +4 -3
- package/server/lib/opencode/compatibility.test.js +10 -10
- package/server/lib/opencode/feature-routes-runtime.js +3 -0
- package/server/lib/opencode/lifecycle.js +21 -12
- package/server/lib/opencode/lifecycle.test.js +38 -5
- package/server/lib/opencode/provider-source-route.test.js +55 -2
- package/server/lib/opencode/routes.js +17 -4
- package/server/lib/opencode/settings-helpers.js +6 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +16 -0
- package/server/lib/opencode/settings-runtime.js +9 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/v1-migration-topup.js +13 -3
- package/server/lib/opencode/v2-install.test.js +13 -13
- package/server/lib/quota/DOCUMENTATION.md +11 -5
- package/server/lib/quota/providers/claude/auth.js +19 -6
- package/server/lib/quota/providers/claude/auth.test.js +22 -9
- package/server/lib/quota/providers/claude/index.js +3 -3
- package/server/lib/quota/providers/claude/index.test.js +3 -2
- package/server/lib/quota/providers/cline-pass.js +4 -4
- package/server/lib/quota/providers/codex.js +3 -4
- package/server/lib/quota/providers/codex.test.js +1 -1
- package/server/lib/quota/providers/copilot.js +4 -5
- package/server/lib/quota/providers/copilot.test.js +1 -1
- package/server/lib/quota/providers/deepseek.js +3 -4
- package/server/lib/quota/providers/deepseek.test.js +1 -1
- package/server/lib/quota/providers/google/auth.js +1 -3
- package/server/lib/quota/providers/google/index.js +3 -2
- package/server/lib/quota/providers/hyper.js +4 -4
- package/server/lib/quota/providers/index.js +9 -2
- package/server/lib/quota/providers/index.test.js +5 -3
- package/server/lib/quota/providers/kimi.js +16 -11
- package/server/lib/quota/providers/kimi.test.js +81 -38
- package/server/lib/quota/providers/minimax-shared.js +3 -4
- package/server/lib/quota/providers/nanogpt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.test.js +1 -1
- package/server/lib/quota/providers/openai.js +2 -8
- package/server/lib/quota/providers/opencode-go.js +5 -5
- package/server/lib/quota/providers/opencode-go.test.js +1 -1
- package/server/lib/quota/providers/openrouter.js +30 -6
- package/server/lib/quota/providers/openrouter.test.js +122 -1
- package/server/lib/quota/providers/wafer.js +3 -4
- package/server/lib/quota/providers/xai.js +12 -12
- package/server/lib/quota/providers/zai.js +3 -4
- package/server/lib/quota/providers/zai.test.js +1 -1
- package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
- package/server/lib/quota/routes.js +1 -1
- package/server/lib/routing/DOCUMENTATION.md +4 -0
- package/server/lib/routing/runtime.js +45 -4
- package/server/lib/routing/runtime.test.js +35 -6
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
- package/server/lib/scheduled-tasks/chats-scope.js +50 -0
- package/server/lib/scheduled-tasks/runtime.js +57 -23
- package/server/lib/scheduled-tasks/runtime.test.js +103 -1
- package/server/lib/scheduled-tasks/service.js +37 -29
- package/server/lib/scheduled-tasks/service.test.js +39 -0
- package/server/lib/spaces/DOCUMENTATION.md +54 -9
- package/server/lib/spaces/host.js +24 -3
- package/server/lib/spaces/journey.js +111 -11
- package/server/lib/spaces/journey.test.js +189 -8
- package/server/lib/spaces/places/docker-disk.js +151 -0
- package/server/lib/spaces/places/docker-disk.test.js +167 -0
- package/server/lib/spaces/places/docker-tools.js +11 -1
- package/server/lib/spaces/places/docker.js +4 -2
- package/server/lib/spaces/places/fake-docker.js +36 -2
- package/server/lib/spaces/routes.js +21 -4
- package/server/lib/spaces/routes.test.js +6 -2
- package/server/lib/spaces/space-archive.js +275 -0
- package/server/lib/spaces/space-archive.test.js +194 -0
- package/server/lib/spaces/space-opencode.js +139 -6
- package/server/lib/spaces/space-opencode.test.js +82 -1
- package/server/lib/spaces/space-records.js +3 -0
- package/server/lib/spaces/space-setup.js +10 -5
- package/server/lib/spaces/space-setup.test.js +8 -2
- package/server/lib/terminal/DOCUMENTATION.md +1 -0
- package/server/lib/terminal/runtime.js +6 -1
- package/server/lib/terminal/runtime.test.js +19 -0
- package/server/lib/tts/routes.js +2 -2
- package/server/lib/tts/service.js +8 -8
- package/dist/assets/FilesView-CN34wm_N.js +0 -17
- package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
- package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
- package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
- package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
- package/dist/assets/SettingsWindow-CofS020b.js +0 -1
- package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
- package/dist/assets/de-DlgBHUAI.js +0 -10
- package/dist/assets/es-BC8G41U8.js +0 -16
- package/dist/assets/fr-I0z3vVjy.js +0 -14
- package/dist/assets/index-CgR5rJq_.js +0 -41
- package/dist/assets/index-adyy_sEk.css +0 -1
- package/dist/assets/ja-BIElEsY8.js +0 -16
- package/dist/assets/ko-DRnnHetA.js +0 -16
- package/dist/assets/main-DVX34beR.js +0 -886
- package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
- package/dist/assets/mobile-BrlBrNfZ.js +0 -2
- package/dist/assets/nl-DzUV-kwp.js +0 -16
- package/dist/assets/pl-Bb-cb7k7.js +0 -16
- package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
- package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
- package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
- package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
- package/dist/assets/tr-DXEDSoYO.js +0 -7
- package/dist/assets/uk-C8hN--q_.js +0 -16
- package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
- package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
- package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
- package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
- package/server/lib/opencode/credential-db.js +0 -144
- package/server/lib/opencode/credential-db.test.js +0 -104
|
@@ -58,6 +58,20 @@ function silentChunkBase64(samples = 1600) {
|
|
|
58
58
|
return Buffer.from(new Int16Array(samples).buffer).toString('base64');
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** Loud samples, then `gap` samples at `gapAmplitude` (silent by default), then loud again. */
|
|
62
|
+
function speechWithGapBase64({ before, gap, after, gapAmplitude = 0 }) {
|
|
63
|
+
const arr = new Int16Array(before + gap + after);
|
|
64
|
+
const fill = (start, count, amplitude) => {
|
|
65
|
+
for (let i = start; i < start + count; i += 1) {
|
|
66
|
+
arr[i] = i % 2 === 0 ? amplitude : -amplitude;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
fill(0, before, 8000);
|
|
70
|
+
fill(before, gap, gapAmplitude);
|
|
71
|
+
fill(before + gap, after, 8000);
|
|
72
|
+
return Buffer.from(arr.buffer).toString('base64');
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
function createManager(session) {
|
|
62
76
|
const messages = [];
|
|
63
77
|
const manager = new DictationStreamManager({
|
|
@@ -167,15 +181,11 @@ describe('DictationStreamManager', () => {
|
|
|
167
181
|
});
|
|
168
182
|
|
|
169
183
|
it('emits partials as segment transcripts arrive', async () => {
|
|
170
|
-
let segment = 0;
|
|
171
184
|
const session = new FakeSttSession({
|
|
172
|
-
transcriptBySegment: () => {
|
|
173
|
-
segment += 1;
|
|
174
|
-
return segment === 1 ? 'first part' : 'second part';
|
|
175
|
-
},
|
|
185
|
+
transcriptBySegment: (segmentId) => `part ${segmentId.slice('seg-'.length)}`,
|
|
176
186
|
});
|
|
177
187
|
const { manager, messages } = createManager(session);
|
|
178
|
-
// Force a hard-cap split
|
|
188
|
+
// Force a hard-cap split inside each ~0.1s chunk so several segments form.
|
|
179
189
|
manager.segmentMaxSeconds = 0.05;
|
|
180
190
|
|
|
181
191
|
await manager.handleStart('d1', FORMAT, {});
|
|
@@ -186,8 +196,9 @@ describe('DictationStreamManager', () => {
|
|
|
186
196
|
|
|
187
197
|
await waitFor(() => messages.some((m) => m.type === 'final'));
|
|
188
198
|
|
|
199
|
+
// Two cap cuts plus the tail committed on finish.
|
|
189
200
|
const final = messages.find((m) => m.type === 'final');
|
|
190
|
-
expect(final.payload.text).toBe('
|
|
201
|
+
expect(final.payload.text).toBe('part 0 part 1 part 2');
|
|
191
202
|
const partials = messages.filter((m) => m.type === 'partial');
|
|
192
203
|
expect(partials.length).toBeGreaterThan(0);
|
|
193
204
|
});
|
|
@@ -238,6 +249,96 @@ describe('DictationStreamManager', () => {
|
|
|
238
249
|
expect(session.commits).toBe(1);
|
|
239
250
|
});
|
|
240
251
|
|
|
252
|
+
it('cuts inside a pause, not at the chunk boundary', async () => {
|
|
253
|
+
const session = new FakeSttSession();
|
|
254
|
+
const { manager } = createManager(session);
|
|
255
|
+
manager.segmentMinSeconds = 1;
|
|
256
|
+
|
|
257
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
258
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
|
|
259
|
+
// 300 ms speech, 400 ms gap, 300 ms speech: the cut belongs in the gap.
|
|
260
|
+
manager.handleChunk({
|
|
261
|
+
dictationId: 'd1',
|
|
262
|
+
seq: 1,
|
|
263
|
+
audioBase64: speechWithGapBase64({ before: 4800, gap: 6400, after: 4800 }),
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
expect(session.commits).toBe(1);
|
|
267
|
+
const cutBytes = session.appended[1].length;
|
|
268
|
+
expect(cutBytes).toBeGreaterThan(4800 * 2);
|
|
269
|
+
expect(cutBytes).toBeLessThan((4800 + 6400) * 2);
|
|
270
|
+
// The rest of the chunk opens the next segment.
|
|
271
|
+
expect(session.appended[2].length).toBe(16000 * 2 - cutBytes);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('finds a pause that straddles two chunks', async () => {
|
|
275
|
+
const session = new FakeSttSession();
|
|
276
|
+
const { manager } = createManager(session);
|
|
277
|
+
manager.segmentMinSeconds = 1;
|
|
278
|
+
|
|
279
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
280
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
|
|
281
|
+
// 100 ms of quiet at the end of one chunk, 250 ms at the start of the next:
|
|
282
|
+
// neither alone is a pause, together they are, and the middle of the
|
|
283
|
+
// 350 ms run is 50 ms into the second chunk.
|
|
284
|
+
manager.handleChunk({
|
|
285
|
+
dictationId: 'd1',
|
|
286
|
+
seq: 1,
|
|
287
|
+
audioBase64: speechWithGapBase64({ before: 14400, gap: 1600, after: 0 }),
|
|
288
|
+
});
|
|
289
|
+
expect(session.commits).toBe(0);
|
|
290
|
+
manager.handleChunk({
|
|
291
|
+
dictationId: 'd1',
|
|
292
|
+
seq: 2,
|
|
293
|
+
audioBase64: speechWithGapBase64({ before: 0, gap: 4000, after: 12000 }),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
expect(session.commits).toBe(1);
|
|
297
|
+
expect(session.appended[2].length).toBe(800 * 2);
|
|
298
|
+
expect(session.appended[3].length).toBe((16000 - 800) * 2);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('forgets a silent first second so noisy pauses still count', async () => {
|
|
302
|
+
const session = new FakeSttSession();
|
|
303
|
+
const { manager } = createManager(session);
|
|
304
|
+
manager.segmentMinSeconds = 12;
|
|
305
|
+
|
|
306
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
307
|
+
// A gated mic opens with digital zeros; every later pause carries room noise.
|
|
308
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: silentChunkBase64(16000) });
|
|
309
|
+
for (let seq = 1; seq <= 12; seq += 1) {
|
|
310
|
+
manager.handleChunk({
|
|
311
|
+
dictationId: 'd1',
|
|
312
|
+
seq,
|
|
313
|
+
audioBase64: speechWithGapBase64({ before: 4800, gap: 6400, after: 4800, gapAmplitude: 400 }),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
expect(session.commits).toBe(1);
|
|
318
|
+
const cutBytes = session.appended[12].length;
|
|
319
|
+
expect(cutBytes).toBeGreaterThan(4800 * 2);
|
|
320
|
+
expect(cutBytes).toBeLessThan((4800 + 6400) * 2);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('cuts at the quietest frame when the hard cap hits pauseless speech', async () => {
|
|
324
|
+
const session = new FakeSttSession();
|
|
325
|
+
const { manager } = createManager(session);
|
|
326
|
+
manager.segmentMinSeconds = 60;
|
|
327
|
+
manager.segmentMaxSeconds = 2;
|
|
328
|
+
|
|
329
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
330
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
|
|
331
|
+
// A 50 ms dip 600 ms in: too short to be a pause, but the best place to cut.
|
|
332
|
+
manager.handleChunk({
|
|
333
|
+
dictationId: 'd1',
|
|
334
|
+
seq: 1,
|
|
335
|
+
audioBase64: speechWithGapBase64({ before: 9600, gap: 800, after: 5600, gapAmplitude: 2000 }),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
expect(session.commits).toBe(1);
|
|
339
|
+
expect(session.appended[1].length).toBe((9600 + 400) * 2);
|
|
340
|
+
});
|
|
341
|
+
|
|
241
342
|
it('clears a silence-only segment at the hard cap instead of committing it', async () => {
|
|
242
343
|
const session = new FakeSttSession();
|
|
243
344
|
const { manager } = createManager(session);
|
|
@@ -28,3 +28,5 @@ export const NETWORK_ACCESS_BLOCKED_ERROR: string;
|
|
|
28
28
|
export function publicEnterprisePolicy(options?: EnterprisePolicyOptions): PublicEnterprisePolicy;
|
|
29
29
|
export function isProviderConnectRequest(method: string, requestPath: string): boolean;
|
|
30
30
|
export const ENTERPRISE_MODE_ERROR: string;
|
|
31
|
+
export function isCredentialListRequest(method: string, requestPath: string): boolean;
|
|
32
|
+
export const CREDENTIAL_LIST_ERROR: string;
|
|
@@ -32,6 +32,8 @@ import { z } from 'zod';
|
|
|
32
32
|
* signing in, adding a key or creating a custom provider through this
|
|
33
33
|
* server is refused (`opencode/routes.js`). OpenCode's `provider.use`
|
|
34
34
|
* policy is the real lock; this closes the way in through the app.
|
|
35
|
+
* Signing in to a remote MCP server from the OpenCode config uses the same
|
|
36
|
+
* routes and stays allowed.
|
|
35
37
|
* - Jev classification is off, unless the administrator pinned their own
|
|
36
38
|
* endpoint (`routing/runtime.js`).
|
|
37
39
|
* - External tunnels are refused: their provider sees plain text (`tunnels`).
|
|
@@ -238,16 +240,89 @@ export const publicEnterprisePolicy = (options) => {
|
|
|
238
240
|
return { enterpriseMode, source, organization, policyError, networkAccessBlocked: enterpriseMode && !allowNetworkAccess };
|
|
239
241
|
};
|
|
240
242
|
|
|
241
|
-
// OpenCode
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
const
|
|
243
|
+
// OpenCode registers every remote MCP server with OAuth as an integration
|
|
244
|
+
// whose id is `mcp_` plus 16 hex digits of a hash of its name and URL
|
|
245
|
+
// (`packages/core/src/mcp/index.ts` upstream). Signing in to one reaches a
|
|
246
|
+
// tool server from the OpenCode config, not a model provider.
|
|
247
|
+
const MCP_INTEGRATION_ID = /^mcp_[0-9a-f]{16}$/;
|
|
248
|
+
const ATTEMPT_ID = /^[A-Za-z0-9_-]+$/;
|
|
247
249
|
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
/**
|
|
251
|
+
* The path segments as OpenCode 2.0.18 to 2.0.20 route them. Bun's URL parsing turns
|
|
252
|
+
* `\` into `/`; OpenCode's router (`effect/unstable/http` FindMyWay:
|
|
253
|
+
* case-insensitive, duplicate and trailing slashes ignored, `safeDecodeURI`)
|
|
254
|
+
* ends the path at `?`, `#` or `;` and decodes percent escapes. So `/API//integration\%6Fpenai/connect/key;x` reaches the same
|
|
255
|
+
* handler as `/api/integration/openai/connect/key`. Null when a segment cannot
|
|
256
|
+
* be decoded or is a dot segment: such a path is refused. Recheck this list
|
|
257
|
+
* when OpenCode changes its router.
|
|
258
|
+
*/
|
|
259
|
+
const routeSegments = (requestPath) => {
|
|
260
|
+
const pathOnly = String(requestPath).split(/[?#;]/, 1)[0];
|
|
261
|
+
const segments = [];
|
|
262
|
+
for (const raw of pathOnly.split(/[\\/]/)) {
|
|
263
|
+
if (!raw) continue;
|
|
264
|
+
let segment;
|
|
265
|
+
try {
|
|
266
|
+
segment = decodeURIComponent(raw);
|
|
267
|
+
} catch {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
if (segment === '.' || segment === '..') return null;
|
|
271
|
+
segments.push(segment);
|
|
272
|
+
}
|
|
273
|
+
return segments;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// POST `connect/oauth` starts an MCP sign-in, `connect/oauth/:attempt/complete`
|
|
277
|
+
// finishes it with a pasted code.
|
|
278
|
+
const isMcpSignIn = (integrationId, rest) => (
|
|
279
|
+
MCP_INTEGRATION_ID.test(integrationId)
|
|
280
|
+
&& rest[0]?.toLowerCase() === 'oauth'
|
|
281
|
+
&& (rest.length === 1 || (rest.length === 3 && ATTEMPT_ID.test(rest[1]) && rest[2].toLowerCase() === 'complete'))
|
|
251
282
|
);
|
|
252
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Whether a request to OpenCode would add a way to reach a model provider:
|
|
286
|
+
* every POST under `/api/integration/:id/connect` (key, oauth start and
|
|
287
|
+
* complete, command), storing a key with `POST /api/credential`, and adding a
|
|
288
|
+
* well-known integration. Signing in to a
|
|
289
|
+
* remote MCP server goes through the same routes and stays allowed. Reads,
|
|
290
|
+
* cancelling an attempt and removing or switching an existing account stay
|
|
291
|
+
* allowed too: they only narrow access. A path that cannot be read safely
|
|
292
|
+
* counts as a connect.
|
|
293
|
+
*/
|
|
294
|
+
export const isProviderConnectRequest = (method, requestPath) => {
|
|
295
|
+
if (String(method).toUpperCase() !== 'POST') return false;
|
|
296
|
+
const segments = routeSegments(requestPath);
|
|
297
|
+
if (segments === null) return true;
|
|
298
|
+
const [api, group, ...tail] = segments.map((segment) => segment.toLowerCase());
|
|
299
|
+
if (api !== 'api') return false;
|
|
300
|
+
// `POST /api/credential` stores a new key (OpenCode 2.0.20);
|
|
301
|
+
// `/api/credential/:id/activate` only switches between existing ones.
|
|
302
|
+
if (group === 'credential') return tail.length === 0;
|
|
303
|
+
if (group === 'experimental') return tail[0] === 'integration' && tail[1] === 'wellknown';
|
|
304
|
+
if (group !== 'integration' || tail[1] !== 'connect') return false;
|
|
305
|
+
return !isMcpSignIn(segments[2], segments.slice(4));
|
|
306
|
+
};
|
|
307
|
+
|
|
253
308
|
export const ENTERPRISE_MODE_ERROR = 'Not available in enterprise mode: this server keeps conversations with the model providers configured in OpenCode.';
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Whether a request asks OpenCode for every stored credential. Since 2.0.20
|
|
312
|
+
* `GET /api/credential` answers with the secrets themselves. This server and
|
|
313
|
+
* the VS Code extension host read it for themselves (`opencode/auth.js`); no
|
|
314
|
+
* client gets it, in or out of enterprise mode, because anyone signed in to
|
|
315
|
+
* the UI (over a tunnel or a paired phone too) would otherwise read every key.
|
|
316
|
+
* It lives here because it needs the same reading of an OpenCode path as the
|
|
317
|
+
* provider-connect check. A path under `/api` that cannot be read safely
|
|
318
|
+
* counts as a read; anything else never reaches OpenCode and is left alone.
|
|
319
|
+
*/
|
|
320
|
+
export const isCredentialListRequest = (method, requestPath) => {
|
|
321
|
+
const upper = String(method).toUpperCase();
|
|
322
|
+
if (upper !== 'GET' && upper !== 'HEAD') return false;
|
|
323
|
+
const segments = routeSegments(requestPath);
|
|
324
|
+
if (segments === null) return /^[\\/]*api(?:[\\/?#;]|$)/i.test(String(requestPath));
|
|
325
|
+
return segments.length === 2 && segments[0].toLowerCase() === 'api' && segments[1].toLowerCase() === 'credential';
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export const CREDENTIAL_LIST_ERROR = 'OpenChamber does not hand stored provider keys to clients.';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
isCredentialListRequest,
|
|
4
5
|
isEnterpriseMode,
|
|
5
6
|
isNetworkAccessBlocked,
|
|
6
7
|
isProviderConnectRequest,
|
|
@@ -230,18 +231,132 @@ describe('enterprise policy', () => {
|
|
|
230
231
|
'/api/integration/anthropic/connect/oauth/att_1/complete',
|
|
231
232
|
'/api/integration/github-copilot/connect/command',
|
|
232
233
|
'/api/experimental/integration/wellknown',
|
|
234
|
+
'/api/integration/openai/connect',
|
|
235
|
+
'/api/integration/openai/connect/key/',
|
|
236
|
+
'/api/credential',
|
|
237
|
+
'/api/credential/',
|
|
238
|
+
'/API//credential;x',
|
|
233
239
|
])('refuses POST %s', (requestPath) => {
|
|
234
240
|
expect(isProviderConnectRequest('POST', requestPath)).toBe(true);
|
|
235
241
|
});
|
|
236
242
|
|
|
243
|
+
// OpenCode routes all of these to the provider connect handlers.
|
|
244
|
+
it.each([
|
|
245
|
+
'/API/integration/openai/connect/key',
|
|
246
|
+
'/api/Integration/openai/Connect/Key',
|
|
247
|
+
'/api//integration/openai/connect/key',
|
|
248
|
+
'/api/integration//openai/connect/key',
|
|
249
|
+
'/api/integration/openai/%63onnect/key',
|
|
250
|
+
'/api/%65xperimental/integration/wellknown',
|
|
251
|
+
'/api/integration/%6Dcp_0123456789abcdef/connect/key',
|
|
252
|
+
'/api/integration\\openai\\connect\\key',
|
|
253
|
+
'/api/integration/openai\\connect/key',
|
|
254
|
+
'/api/Experimental/integration\\wellknown',
|
|
255
|
+
'/api/experimental/integration/wellknown;x',
|
|
256
|
+
'/api/integration/openai/connect/key;x',
|
|
257
|
+
])('refuses POST %s written another way', (requestPath) => {
|
|
258
|
+
expect(isProviderConnectRequest('POST', requestPath)).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it.each([
|
|
262
|
+
'/api/integration/openai/connect/../connect/key',
|
|
263
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth/../../../openai/connect/key',
|
|
264
|
+
'/api/integration/openai/connect/%E0%A4%A',
|
|
265
|
+
])('refuses POST %s, which cannot be read safely', (requestPath) => {
|
|
266
|
+
expect(isProviderConnectRequest('POST', requestPath)).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it.each([
|
|
270
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth',
|
|
271
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth?location=%2Fp',
|
|
272
|
+
'/api/integration/mcp_0123456789abcdef/connect/OAuth/',
|
|
273
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth/att_1/complete',
|
|
274
|
+
'/api/integration\\mcp_0123456789abcdef\\connect\\oauth',
|
|
275
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth;/../../../openai/connect/key',
|
|
276
|
+
])('lets POST %s sign in to an MCP server', (requestPath) => {
|
|
277
|
+
expect(isProviderConnectRequest('POST', requestPath)).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it.each([
|
|
281
|
+
'/api/integration/mcp_0123456789abcdef/connect/key',
|
|
282
|
+
'/api/integration/mcp_0123456789abcdef/connect/command',
|
|
283
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth/att_1/complete/extra',
|
|
284
|
+
'/api/integration/mcp_0123456789abcdef/connect/oauth/att%2F1/complete',
|
|
285
|
+
'/api/integration/MCP_0123456789ABCDEF/connect/oauth',
|
|
286
|
+
'/api/integration/mcp_evil/connect/oauth',
|
|
287
|
+
'/api/integration/mcp_0123456789abcdef%2F..%2Fopenai/connect/oauth',
|
|
288
|
+
])('refuses POST %s, which is not an MCP sign-in', (requestPath) => {
|
|
289
|
+
expect(isProviderConnectRequest('POST', requestPath)).toBe(true);
|
|
290
|
+
});
|
|
291
|
+
|
|
237
292
|
it.each([
|
|
238
293
|
['GET', '/api/integration/anthropic/connect/oauth/att_1'],
|
|
239
294
|
['DELETE', '/api/integration/anthropic/connect/oauth/att_1'],
|
|
240
295
|
['GET', '/api/integration'],
|
|
241
296
|
['POST', '/api/session'],
|
|
297
|
+
['POST', '/api/integration/openai/connectors'],
|
|
298
|
+
['POST', '/health'],
|
|
242
299
|
['DELETE', '/api/credential/cred_1'],
|
|
300
|
+
['POST', '/api/credential/cred_1/activate'],
|
|
301
|
+
['PATCH', '/api/credential/cred_1'],
|
|
302
|
+
['GET', '/api/credential'],
|
|
243
303
|
])('leaves %s %s alone', (method, requestPath) => {
|
|
244
304
|
expect(isProviderConnectRequest(method, requestPath)).toBe(false);
|
|
245
305
|
});
|
|
246
306
|
});
|
|
307
|
+
|
|
308
|
+
describe('credential list requests', () => {
|
|
309
|
+
// OpenCode routes all of these to the handler that returns every key.
|
|
310
|
+
it.each([
|
|
311
|
+
['GET', '/api/credential'],
|
|
312
|
+
['GET', '/api/credential/'],
|
|
313
|
+
['GET', '/api/credential?directory=%2Fp'],
|
|
314
|
+
['HEAD', '/api/credential'],
|
|
315
|
+
['get', '/API/Credential'],
|
|
316
|
+
['GET', '//api//credential'],
|
|
317
|
+
['GET', '/api\\credential'],
|
|
318
|
+
['GET', '/api/%63redential'],
|
|
319
|
+
['GET', '/api/credential;x'],
|
|
320
|
+
])('refuses %s %s', (method, requestPath) => {
|
|
321
|
+
expect(isCredentialListRequest(method, requestPath)).toBe(true);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it.each([
|
|
325
|
+
'/api/x/../credential',
|
|
326
|
+
'/api/%E0%A4%A',
|
|
327
|
+
'/API/%zz',
|
|
328
|
+
])('refuses GET %s, which cannot be read safely', (requestPath) => {
|
|
329
|
+
expect(isCredentialListRequest('GET', requestPath)).toBe(true);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it.each([
|
|
333
|
+
'/assets/a%zz.js',
|
|
334
|
+
'/docs/../index.html',
|
|
335
|
+
'/apikeys/%zz',
|
|
336
|
+
])('leaves GET %s alone, which never reaches OpenCode', (requestPath) => {
|
|
337
|
+
expect(isCredentialListRequest('GET', requestPath)).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// OpenCode 2.0.20 matches before decoding a separator: these reach its web
|
|
341
|
+
// app page (200 HTML), 404 or 405, never the credential handler.
|
|
342
|
+
it.each([
|
|
343
|
+
'/api%2fcredential',
|
|
344
|
+
'/api%2Fcredential',
|
|
345
|
+
'/api%5ccredential',
|
|
346
|
+
])('leaves GET %s alone, which OpenCode does not route to the list', (requestPath) => {
|
|
347
|
+
expect(isCredentialListRequest('GET', requestPath)).toBe(false);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it.each([
|
|
351
|
+
['POST', '/api/credential'],
|
|
352
|
+
['PATCH', '/api/credential/cred_1'],
|
|
353
|
+
['DELETE', '/api/credential/cred_1'],
|
|
354
|
+
['POST', '/api/credential/cred_1/activate'],
|
|
355
|
+
['GET', '/api/credentials'],
|
|
356
|
+
['GET', '/api/integration'],
|
|
357
|
+
['GET', '/credential'],
|
|
358
|
+
])('leaves %s %s alone', (method, requestPath) => {
|
|
359
|
+
expect(isCredentialListRequest(method, requestPath)).toBe(false);
|
|
360
|
+
});
|
|
361
|
+
});
|
|
247
362
|
});
|
|
@@ -27,8 +27,9 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
27
27
|
- `GET /api/fs/list`
|
|
28
28
|
- `GET /api/fs/git-dirs` — shallow nested git repository discovery for the
|
|
29
29
|
Git tab (depth- and visit-capped readdir walk; `.git` directory, file, or
|
|
30
|
-
symlink marks a repository boundary; junk directories
|
|
31
|
-
|
|
30
|
+
symlink marks a repository boundary; junk directories are skipped;
|
|
31
|
+
symlinked directories are followed, each real directory walked once,
|
|
32
|
+
and repositories are reported under the link path)
|
|
32
33
|
- Owns exec job queue state (`execJobs`) and lifecycle/TTL pruning.
|
|
33
34
|
- Enforces workspace boundary checks with active project + worktree fallback support.
|
|
34
35
|
- 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.
|
package/server/lib/fs/routes.js
CHANGED
|
@@ -345,8 +345,14 @@ const GIT_DIRS_SKIP_LIST = new Set(['node_modules', 'dist', 'build', '.venv', 't
|
|
|
345
345
|
// containing a `.git` entry — a directory, a worktree pointer file, or a
|
|
346
346
|
// symlink). A repository boundary stops descent: nested repos inside repos
|
|
347
347
|
// are not reported. The root itself, when it is a repo, yields no results.
|
|
348
|
+
// Symlinked directories are followed, the way the file tree follows them: a
|
|
349
|
+
// parent folder of links to repositories kept elsewhere is a common way to
|
|
350
|
+
// group them into one project. Each real directory is walked once, so a link
|
|
351
|
+
// loop or two links to one repository cannot repeat it, and repositories are
|
|
352
|
+
// reported under the path the link gives them inside the project.
|
|
348
353
|
const findGitDirectories = async ({ rootPath, fsPromises, path: pathModule, maxDepth, maxDirs }) => {
|
|
349
354
|
const results = [];
|
|
355
|
+
const walkedRealPaths = new Set();
|
|
350
356
|
let visited = 0;
|
|
351
357
|
|
|
352
358
|
const walk = async (dir, depth) => {
|
|
@@ -354,6 +360,20 @@ const findGitDirectories = async ({ rootPath, fsPromises, path: pathModule, maxD
|
|
|
354
360
|
return;
|
|
355
361
|
}
|
|
356
362
|
|
|
363
|
+
let realPath;
|
|
364
|
+
try {
|
|
365
|
+
realPath = await fsPromises.realpath(dir);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
if (dir === rootPath) {
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (walkedRealPaths.has(realPath)) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
walkedRealPaths.add(realPath);
|
|
376
|
+
|
|
357
377
|
let dirents;
|
|
358
378
|
try {
|
|
359
379
|
dirents = await fsPromises.readdir(dir, { withFileTypes: true });
|
|
@@ -374,7 +394,7 @@ const findGitDirectories = async ({ rootPath, fsPromises, path: pathModule, maxD
|
|
|
374
394
|
isRepoBoundary = true;
|
|
375
395
|
continue;
|
|
376
396
|
}
|
|
377
|
-
if (!dirent.isDirectory()
|
|
397
|
+
if (!dirent.isDirectory() && !dirent.isSymbolicLink()) {
|
|
378
398
|
continue;
|
|
379
399
|
}
|
|
380
400
|
if (GIT_DIRS_SKIP_LIST.has(dirent.name)) {
|
|
@@ -383,6 +403,13 @@ const findGitDirectories = async ({ rootPath, fsPromises, path: pathModule, maxD
|
|
|
383
403
|
if (depth >= maxDepth) {
|
|
384
404
|
continue;
|
|
385
405
|
}
|
|
406
|
+
if (dirent.isSymbolicLink()) {
|
|
407
|
+
// A link to a file, or a dangling one, is not a place to look.
|
|
408
|
+
const target = await fsPromises.stat(pathModule.join(dir, dirent.name)).catch(() => null);
|
|
409
|
+
if (!target?.isDirectory()) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
386
413
|
subdirectories.push(dirent.name);
|
|
387
414
|
}
|
|
388
415
|
|
|
@@ -1254,14 +1254,14 @@ describe('fs git-dirs', () => {
|
|
|
1254
1254
|
});
|
|
1255
1255
|
|
|
1256
1256
|
// tree maps directory path -> [[name, type], ...]
|
|
1257
|
-
const registerGitDirs = (tree, { stat, readdir: readdirOverride } = {}) => {
|
|
1257
|
+
const registerGitDirs = (tree, { stat, readdir: readdirOverride, realpath } = {}) => {
|
|
1258
1258
|
const { app, getRoute } = createRouteRegistry();
|
|
1259
1259
|
const readdir = readdirOverride ?? vi.fn(async (dirPath) => (tree[dirPath] ?? []).map(([name, type]) => createDirent(name, type)));
|
|
1260
1260
|
registerFsRoutes(app, {
|
|
1261
1261
|
os: { homedir: () => '/home/user' },
|
|
1262
1262
|
path: path.posix,
|
|
1263
1263
|
fsPromises: {
|
|
1264
|
-
realpath: async (targetPath) => targetPath,
|
|
1264
|
+
realpath: realpath ?? (async (targetPath) => targetPath),
|
|
1265
1265
|
stat: stat ?? vi.fn(async (targetPath) => ({ isDirectory: () => Boolean(tree[targetPath]) })),
|
|
1266
1266
|
readdir,
|
|
1267
1267
|
},
|
|
@@ -1369,16 +1369,42 @@ describe('fs git-dirs', () => {
|
|
|
1369
1369
|
expect(readdir).not.toHaveBeenCalledWith('/workspace/node_modules', { withFileTypes: true });
|
|
1370
1370
|
});
|
|
1371
1371
|
|
|
1372
|
-
it('
|
|
1372
|
+
it('follows symlinked directories and reports repositories under the link path', async () => {
|
|
1373
|
+
// /workspace groups repositories kept elsewhere through links.
|
|
1374
|
+
const links = { '/workspace/api': '/src/api', '/workspace/web': '/src/web' };
|
|
1373
1375
|
const { handler } = registerGitDirs({
|
|
1374
|
-
'/workspace': [['
|
|
1376
|
+
'/workspace': [['api', 'symlink'], ['web', 'symlink'], ['notes.md', 'symlink']],
|
|
1377
|
+
'/workspace/api': [['.git', 'dir']],
|
|
1378
|
+
'/workspace/web': [['.git', 'file']],
|
|
1379
|
+
}, {
|
|
1380
|
+
realpath: async (targetPath) => links[targetPath] ?? targetPath,
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1384
|
+
|
|
1385
|
+
expect(res.statusCode).toBe(200);
|
|
1386
|
+
expect(res.body.repositories).toEqual([
|
|
1387
|
+
{ path: '/workspace/api', name: 'api' },
|
|
1388
|
+
{ path: '/workspace/web', name: 'web' },
|
|
1389
|
+
]);
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1392
|
+
it('walks each real directory once, so a link loop or a second link to a repository does not repeat it', async () => {
|
|
1393
|
+
const links = { '/workspace/loop': '/workspace', '/workspace/again': '/workspace/real' };
|
|
1394
|
+
const { handler, readdir } = registerGitDirs({
|
|
1395
|
+
'/workspace': [['again', 'symlink'], ['loop', 'symlink'], ['real', 'dir']],
|
|
1375
1396
|
'/workspace/real': [['.git', 'dir']],
|
|
1397
|
+
'/workspace/again': [['.git', 'dir']],
|
|
1398
|
+
'/workspace/loop': [['again', 'symlink'], ['loop', 'symlink'], ['real', 'dir']],
|
|
1399
|
+
}, {
|
|
1400
|
+
realpath: async (targetPath) => links[targetPath] ?? targetPath,
|
|
1376
1401
|
});
|
|
1377
1402
|
|
|
1378
1403
|
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1379
1404
|
|
|
1380
1405
|
expect(res.statusCode).toBe(200);
|
|
1381
|
-
expect(res.body.repositories).toEqual([{ path: '/workspace/
|
|
1406
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/again', name: 'again' }]);
|
|
1407
|
+
expect(readdir).toHaveBeenCalledTimes(2);
|
|
1382
1408
|
});
|
|
1383
1409
|
|
|
1384
1410
|
it('returns repositories in deterministic order', async () => {
|
|
@@ -123,7 +123,7 @@ mount these Git panels and keeps its separate extension-host Git implementation.
|
|
|
123
123
|
|
|
124
124
|
The following functions are internal helpers used by exported functions:
|
|
125
125
|
- `buildSshCommand(sshKeyPath)`: Build SSH command string for git config.
|
|
126
|
-
- `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.
|
|
126
|
+
- `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. Inside a Linux AppImage it also drops what the AppImage launcher added to `PATH`, `LD_LIBRARY_PATH`, `GSETTINGS_SCHEMA_DIR` and `XDG_DATA_DIRS` (`stripAppImageLauncherEnv`, #4177), so hooks run with the user's values.
|
|
127
127
|
- `createGit(directory)`: Create simple-git instance with environment.
|
|
128
128
|
- `normalizeDirectoryPath(value)`: Normalize directory paths (supports ~ expansion).
|
|
129
129
|
- `cleanBranchName(branch)`: Remove refs/heads/ or refs/ prefixes.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import simpleGit from 'simple-git';
|
|
2
2
|
import { createSerialRefresh } from './serial-refresh.js';
|
|
3
|
+
import { stripAppImageLauncherEnv } from '../inherited-env.js';
|
|
3
4
|
import fs from 'fs';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import os from 'os';
|
|
@@ -343,7 +344,9 @@ const resolveSshAuthSock = async () => {
|
|
|
343
344
|
};
|
|
344
345
|
|
|
345
346
|
const buildGitEnv = async () => {
|
|
346
|
-
|
|
347
|
+
// Git runs the user's hooks, so they must not see what the AppImage launcher
|
|
348
|
+
// added to LD_LIBRARY_PATH and friends (#4177).
|
|
349
|
+
const env = stripAppImageLauncherEnv({ ...process.env });
|
|
347
350
|
if (!env.SSH_AUTH_SOCK || !env.SSH_AUTH_SOCK.trim()) {
|
|
348
351
|
const resolved = await resolveSshAuthSock();
|
|
349
352
|
if (resolved) {
|
|
@@ -4920,6 +4923,62 @@ async function attachGitWorktreeToCandidate(context, candidate, input = {}) {
|
|
|
4920
4923
|
};
|
|
4921
4924
|
}
|
|
4922
4925
|
|
|
4926
|
+
const isAncestorRef = async (cwd, ancestor, descendant) => {
|
|
4927
|
+
const result = await runGitCommand(cwd, ['merge-base', '--is-ancestor', ancestor, descendant]);
|
|
4928
|
+
return result.success;
|
|
4929
|
+
};
|
|
4930
|
+
|
|
4931
|
+
/**
|
|
4932
|
+
* The upstream of a local branch whose commits are all published, or null.
|
|
4933
|
+
*
|
|
4934
|
+
* Only the standard remote-tracking layout qualifies
|
|
4935
|
+
* (`refs/remotes/<remote>/<branch>`), because that is the ref
|
|
4936
|
+
* `fetchRemoteBranchRef` refreshes.
|
|
4937
|
+
*/
|
|
4938
|
+
const resolvePublishedLocalBranchUpstream = async (primaryWorktree, startRef) => {
|
|
4939
|
+
const branch = String(startRef || '').trim().replace(/^refs\/heads\//, '');
|
|
4940
|
+
if (!branch || branch === 'HEAD') return null;
|
|
4941
|
+
const localRef = `refs/heads/${branch}`;
|
|
4942
|
+
const refs = await runGitCommand(primaryWorktree, [
|
|
4943
|
+
'for-each-ref',
|
|
4944
|
+
'--format=%(refname)%00%(upstream)%00%(upstream:remotename)%00%(upstream:remoteref)',
|
|
4945
|
+
localRef,
|
|
4946
|
+
]);
|
|
4947
|
+
if (!refs.success) return null;
|
|
4948
|
+
const line = refs.stdout.split('\n').find((entry) => entry.startsWith(`${localRef}\0`));
|
|
4949
|
+
if (!line) return null;
|
|
4950
|
+
const [, trackingRef, remote, remoteRef] = line.split('\0');
|
|
4951
|
+
const remoteBranch = String(remoteRef || '').replace(/^refs\/heads\//, '');
|
|
4952
|
+
if (!remote || !remoteBranch || trackingRef !== `refs/remotes/${remote}/${remoteBranch}`) return null;
|
|
4953
|
+
if (!(await isAncestorRef(primaryWorktree, localRef, trackingRef))) return null;
|
|
4954
|
+
return { remote, branch: remoteBranch, localRef, trackingRef };
|
|
4955
|
+
};
|
|
4956
|
+
|
|
4957
|
+
/**
|
|
4958
|
+
* A local base branch with nothing unpublished starts the worktree from its
|
|
4959
|
+
* freshly fetched upstream, so the worktree includes what was pushed since
|
|
4960
|
+
* the last pull. The local branch itself is never moved. A branch with
|
|
4961
|
+
* unpublished commits, or an upstream that no longer contains the local
|
|
4962
|
+
* commits after the fetch (a force-push), keeps the local ref; a failed fetch
|
|
4963
|
+
* keeps it too and says so.
|
|
4964
|
+
*/
|
|
4965
|
+
const preparePublishedLocalBranchSource = async (context, input, startRef) => {
|
|
4966
|
+
const upstream = await resolvePublishedLocalBranchUpstream(context.primaryWorktree, startRef);
|
|
4967
|
+
if (!upstream) return { input, sourceFetchFailed: false };
|
|
4968
|
+
try {
|
|
4969
|
+
await fetchRemoteBranchRef(context.primaryWorktree, upstream.remote, upstream.branch);
|
|
4970
|
+
} catch {
|
|
4971
|
+
return { input, sourceFetchFailed: true };
|
|
4972
|
+
}
|
|
4973
|
+
if (!(await isAncestorRef(context.primaryWorktree, upstream.localRef, upstream.trackingRef))) {
|
|
4974
|
+
return { input, sourceFetchFailed: false };
|
|
4975
|
+
}
|
|
4976
|
+
return {
|
|
4977
|
+
input: { ...input, startRef: `remotes/${upstream.remote}/${upstream.branch}` },
|
|
4978
|
+
sourceFetchFailed: false,
|
|
4979
|
+
};
|
|
4980
|
+
};
|
|
4981
|
+
|
|
4923
4982
|
const prepareWorktreeCreateSource = async (context, input = {}) => {
|
|
4924
4983
|
if (input?.mode === 'existing') {
|
|
4925
4984
|
return { input, sourceFetchFailed: false };
|
|
@@ -4928,7 +4987,7 @@ const prepareWorktreeCreateSource = async (context, input = {}) => {
|
|
|
4928
4987
|
const startRef = normalizeStartRef(input?.startRef);
|
|
4929
4988
|
const remoteStartRef = await resolveRemoteBranchRef(context.primaryWorktree, startRef);
|
|
4930
4989
|
if (!remoteStartRef) {
|
|
4931
|
-
return
|
|
4990
|
+
return preparePublishedLocalBranchSource(context, input, startRef);
|
|
4932
4991
|
}
|
|
4933
4992
|
|
|
4934
4993
|
const status = await getStatus(context.primaryWorktree, { mode: 'light' }).catch(() => null);
|