@openchamber/web 1.18.3 → 1.19.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/README.md +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-DbUi6I9s.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
- package/dist/assets/{CommitSection-Jc2_hNPE.js → CommitSection-D9cV-qR9.js} +1 -1
- package/dist/assets/{DiagramEditor-PCrYHBko.js → DiagramEditor-B9NCadU7.js} +1 -1
- package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
- package/dist/assets/{DiffView-DEGlNjMH.js → DiffView-BWNq-0ov.js} +2 -2
- package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
- package/dist/assets/{GitView-C-n17voy.js → GitView-DsWXqWx3.js} +3 -3
- package/dist/assets/{JsonTreeView-BYcgdTOQ.js → JsonTreeView-h4dHASlq.js} +1 -1
- package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
- package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
- package/dist/assets/{PatchDiff-Bn7bfgUv.js → PatchDiff-jPKTJje5.js} +1 -1
- package/dist/assets/{PierreDiffViewer-D1fWvrUn.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
- package/dist/assets/PlanView-UvuxIl9-.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
- package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
- package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
- package/dist/assets/{ToolOutputDialog-BtIJkFno.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-i3PQo6_0.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DkcusvMa.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
- package/dist/assets/{WalkthroughView-Cc5Hd6P5.js → WalkthroughView-Bxun3k66.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-xPena3W2.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
- package/dist/assets/de-DbV6CLxv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-CVDlyzZ4.js +15 -0
- package/dist/assets/fr-Czc-p0g-.js +13 -0
- package/dist/assets/index-1OhiMDBz.css +1 -0
- package/dist/assets/index-BSvmTvZl.js +1 -0
- package/dist/assets/index-DzriVon2.js +7 -0
- package/dist/assets/{isDiffPlainText-Dudf-dWx.js → isDiffPlainText-DwHKxDYc.js} +1 -1
- package/dist/assets/{isFilePlainText-DS4QV1dd.js → isFilePlainText-Dwq6ILxo.js} +1 -1
- package/dist/assets/ja-dwc9NM_S.js +15 -0
- package/dist/assets/ko-Ds1DZ8FX.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-BF51IOVF.js +921 -0
- package/dist/assets/{main-C0DyIwTb.js → main-D7UPARut.js} +2 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
- package/dist/assets/{miniChat-CGfrxKpJ.js → miniChat-BISXSGOo.js} +2 -2
- package/dist/assets/mobile-BnYxVuvw.js +2 -0
- package/dist/assets/{patchFileDiff-C5D1OPCa.js → patchFileDiff-BEDPDypx.js} +2 -2
- package/dist/assets/pl-CLiTO7i-.js +15 -0
- package/dist/assets/pt-BR-GIimJgpK.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
- package/dist/assets/{renderMobileApp-B5HA4qbi.js → renderMobileApp-BiMbzPq9.js} +7 -7
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
- package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
- package/dist/assets/{shikiHighlight-CmanopUB.js → shikiHighlight-DXYW46vW.js} +1 -1
- package/dist/assets/uk-DLfgD1ki.js +15 -0
- package/dist/assets/{useAppFontEffects-sHmU5b8u.js → useAppFontEffects-CbzHzFop.js} +139 -142
- package/dist/assets/{useInlineCommentController-gt56WkxJ.js → useInlineCommentController-CegKdDXi.js} +2 -2
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-Dihw9MtL.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
- package/dist/assets/{web-components-BL-Ur2Tb.js → web-components-DCLjCO9n.js} +1 -1
- package/dist/assets/zh-CN-DkeP5awK.js +15 -0
- package/dist/assets/zh-TW-BocaFm3d.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +116 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +56 -0
- package/server/lib/agent-memory/project-resolution.test.js +85 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +427 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- package/server/lib/dev-tunnel/client.js +20 -1
- package/server/lib/dev-tunnel/tunnel.test.js +9 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +225 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/service.js +121 -67
- package/server/lib/git/service.test.js +129 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
- package/server/lib/markdown-image-grants/routes.js +340 -0
- package/server/lib/markdown-image-grants/routes.test.js +221 -0
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -4
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +22 -0
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/server-startup-runtime.js +22 -1
- package/server/lib/opencode/server-startup-runtime.test.js +44 -0
- package/server/lib/opencode/settings-helpers.js +11 -0
- package/server/lib/opencode/settings-helpers.test.js +35 -0
- package/server/lib/opencode/settings-runtime.js +51 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/project-context/DOCUMENTATION.md +158 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +667 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/quota/DOCUMENTATION.md +16 -1
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +72 -0
- package/server/lib/quota/providers/index.js +22 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
- package/server/lib/skills-catalog/curated-sources.js +1 -1
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/small-model/index.js +8 -0
- package/server/lib/small-model/index.test.js +31 -1
- package/server/lib/small-model/routes.js +3 -1
- package/dist/assets/DiagramView-CndEcZNu.js +0 -1
- package/dist/assets/FilesView-CzUgIvUm.js +0 -14
- package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +0 -12
- package/dist/assets/OnboardingScreen-BmN0lhk4.js +0 -1
- package/dist/assets/PlanView-CWM0iyFk.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-Cez-9xRh.js +0 -1
- package/dist/assets/SettingsView-Bl1drwPw.js +0 -28
- package/dist/assets/SettingsWindow-DL5axjDZ.js +0 -1
- package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-CVNuER6G.css +0 -1
- package/dist/assets/index-Crz1YOFl.js +0 -1
- package/dist/assets/index-iFY_N5aO.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-CAxX6DAN.js +0 -915
- package/dist/assets/markdownCore-DhfzuGXu.js +0 -2
- package/dist/assets/markdownImageAssets-BTNlRyjd.js +0 -1
- package/dist/assets/mobile-DEmhwNcV.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-Dpbswpom.js +0 -2
- package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +0 -13
- package/dist/assets/scheduledTasksApi-BxgGWTL8.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
|
@@ -181,7 +181,7 @@ describe('managed agent tool runtime', () => {
|
|
|
181
181
|
|
|
182
182
|
it('omits a tool the user turned off', async () => {
|
|
183
183
|
const { runtime, dataDir } = await createRuntime();
|
|
184
|
-
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: true });
|
|
184
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: true, includeMemory: false });
|
|
185
185
|
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
186
186
|
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?web=${Date.now()}`);
|
|
187
187
|
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
@@ -189,17 +189,100 @@ describe('managed agent tool runtime', () => {
|
|
|
189
189
|
expect(Object.keys(tool)).toEqual(['openchamber_web']);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
it('exposes memory as its own tool carrying only its own inputs', async () => {
|
|
193
|
+
const { runtime, dataDir } = await createRuntime();
|
|
194
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: true, includeWeb: false, includeMemory: true });
|
|
195
|
+
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
196
|
+
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?memory=${Date.now()}`);
|
|
197
|
+
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
198
|
+
|
|
199
|
+
expect(Object.keys(tool)).toEqual(['openchamber', 'openchamber_memory']);
|
|
200
|
+
expect(Object.keys(tool.openchamber_memory.args.parameters.properties).sort())
|
|
201
|
+
.toEqual(['body', 'memoryId', 'scope', 'title', 'type']);
|
|
202
|
+
// Memory inputs must not leak into the control tool's schema, which the
|
|
203
|
+
// model pays for on every unrelated call.
|
|
204
|
+
expect(Object.keys(tool.openchamber.args.parameters.properties)).not.toContain('memoryId');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('omits memory entirely when the user turns it off', async () => {
|
|
208
|
+
const { runtime, dataDir } = await createRuntime();
|
|
209
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: true, includeWeb: false, includeMemory: false });
|
|
210
|
+
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
211
|
+
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?nomemory=${Date.now()}`);
|
|
212
|
+
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
213
|
+
|
|
214
|
+
expect(Object.keys(tool)).toEqual(['openchamber']);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('injects the plugin when memory is the only tool left on', async () => {
|
|
218
|
+
const { runtime, dataDir } = await createRuntime();
|
|
219
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false, includeMemory: true });
|
|
220
|
+
const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
|
|
221
|
+
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?onlymemory=${Date.now()}`);
|
|
222
|
+
const { tool } = await pluginModule.OpenChamberPlugin();
|
|
223
|
+
|
|
224
|
+
expect(Object.keys(tool)).toEqual(['openchamber_memory']);
|
|
225
|
+
});
|
|
226
|
+
|
|
192
227
|
it('refuses to inject a plugin with no tools in it', async () => {
|
|
193
228
|
const { runtime } = await createRuntime();
|
|
194
229
|
let failed = false;
|
|
195
230
|
try {
|
|
196
|
-
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false });
|
|
231
|
+
await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false, includeMemory: false });
|
|
197
232
|
} catch {
|
|
198
233
|
failed = true;
|
|
199
234
|
}
|
|
200
235
|
expect(failed).toBe(true);
|
|
201
236
|
});
|
|
202
237
|
|
|
238
|
+
it('accepts the bare action a tool name already qualifies', async () => {
|
|
239
|
+
// Observed: the model called `read` on openchamber_memory, having taken the
|
|
240
|
+
// tool's own name for the namespace.
|
|
241
|
+
const executeAction = vi.fn(async () => ({ memory: {} }));
|
|
242
|
+
const { runtime } = await createRuntime({ executeAction });
|
|
243
|
+
|
|
244
|
+
const result = await runtime.execute({
|
|
245
|
+
input: { action: 'read', title: 'Uses bun' },
|
|
246
|
+
contextDirectory: '/work/project',
|
|
247
|
+
tool: 'openchamber_memory',
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
expect(result.ok).toBe(true);
|
|
251
|
+
expect(result.action).toBe('memory.read');
|
|
252
|
+
expect(executeAction).toHaveBeenCalledWith(
|
|
253
|
+
'memory.read',
|
|
254
|
+
{ action: 'memory.read', title: 'Uses bun' },
|
|
255
|
+
'/work/project',
|
|
256
|
+
{},
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('tells an unresolvable action what the calling tool can do', async () => {
|
|
261
|
+
const { runtime } = await createRuntime();
|
|
262
|
+
|
|
263
|
+
const result = await runtime.execute({
|
|
264
|
+
input: { action: 'get' },
|
|
265
|
+
tool: 'openchamber_memory',
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(result.ok).toBe(false);
|
|
269
|
+
expect(result.error.message).toContain('memory.read');
|
|
270
|
+
expect(result.error.message).not.toContain('browser.open');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('does not let one tool reach another tool\'s actions', async () => {
|
|
274
|
+
const executeAction = vi.fn(async () => ({}));
|
|
275
|
+
const { runtime } = await createRuntime({ executeAction });
|
|
276
|
+
|
|
277
|
+
const result = await runtime.execute({
|
|
278
|
+
input: { action: 'open', url: 'https://example.test' },
|
|
279
|
+
tool: 'openchamber_memory',
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
expect(result.ok).toBe(false);
|
|
283
|
+
expect(executeAction).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
|
|
203
286
|
it('executes actions through the shared control service', async () => {
|
|
204
287
|
const executeAction = vi.fn(async () => ({ projects: [] }));
|
|
205
288
|
const { runtime } = await createRuntime({ executeAction });
|
|
@@ -33,6 +33,7 @@ const buildContextPrompt = (entries) => {
|
|
|
33
33
|
export const createContextObligatoryRuntime = ({
|
|
34
34
|
buildOpenCodeUrl,
|
|
35
35
|
getOpenCodeAuthHeaders,
|
|
36
|
+
sessionKnowledgeRuntime = null,
|
|
36
37
|
}) => {
|
|
37
38
|
const inflight = new Set();
|
|
38
39
|
let stopped = false;
|
|
@@ -59,7 +60,26 @@ export const createContextObligatoryRuntime = ({
|
|
|
59
60
|
const session = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}`, { directory });
|
|
60
61
|
if (session?.parentID) return;
|
|
61
62
|
const state = readContextState(session);
|
|
62
|
-
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Project knowledge rides along with the pinned messages. Compaction takes
|
|
66
|
+
* both away, and both are restored for the same reason, so they travel as
|
|
67
|
+
* one message: two synthetic turns back to back would read as the agent
|
|
68
|
+
* being interrupted twice.
|
|
69
|
+
*/
|
|
70
|
+
const knowledge = sessionKnowledgeRuntime
|
|
71
|
+
? await sessionKnowledgeRuntime
|
|
72
|
+
.resolvePending(
|
|
73
|
+
directory,
|
|
74
|
+
// Compaction removed the previously delivered block, so its stored
|
|
75
|
+
// signature is no longer evidence that the session still carries it.
|
|
76
|
+
'',
|
|
77
|
+
sessionKnowledgeRuntime.readPins(session),
|
|
78
|
+
)
|
|
79
|
+
.catch(() => ({ text: '', signature: '' }))
|
|
80
|
+
: { text: '', signature: '' };
|
|
81
|
+
|
|
82
|
+
if (state.messages.length === 0 && !knowledge.text) return;
|
|
63
83
|
|
|
64
84
|
const recent = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}/message`, {
|
|
65
85
|
directory,
|
|
@@ -86,7 +106,7 @@ export const createContextObligatoryRuntime = ({
|
|
|
86
106
|
.filter((result) => result.status === 'fulfilled' && result.value.text)
|
|
87
107
|
.map((result) => result.value)
|
|
88
108
|
.sort((left, right) => left.pinned.createdAt - right.pinned.createdAt);
|
|
89
|
-
if (entries.length === 0) return;
|
|
109
|
+
if (entries.length === 0 && !knowledge.text) return;
|
|
90
110
|
|
|
91
111
|
const executionInfo = recent.toReversed().find((message) =>
|
|
92
112
|
message?.info?.role === 'assistant' && message.info.summary !== true)?.info;
|
|
@@ -100,7 +120,13 @@ export const createContextObligatoryRuntime = ({
|
|
|
100
120
|
body: {
|
|
101
121
|
model: { providerID, modelID },
|
|
102
122
|
...(typeof agent === 'string' && agent ? { agent } : {}),
|
|
103
|
-
parts: [{
|
|
123
|
+
parts: [{
|
|
124
|
+
type: 'text',
|
|
125
|
+
text: [knowledge.text, entries.length > 0 ? buildContextPrompt(entries) : '']
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join('\n\n---\n\n'),
|
|
128
|
+
synthetic: true,
|
|
129
|
+
}],
|
|
104
130
|
},
|
|
105
131
|
});
|
|
106
132
|
|
|
@@ -115,6 +141,11 @@ export const createContextObligatoryRuntime = ({
|
|
|
115
141
|
openchamber: {
|
|
116
142
|
...freshState.openchamber,
|
|
117
143
|
context_obligatory_last_compaction_message_id: summary.id,
|
|
144
|
+
// Recorded together with the cursor: the session now carries this
|
|
145
|
+
// knowledge again, so the next send must not repeat it.
|
|
146
|
+
...(knowledge.signature
|
|
147
|
+
? { [sessionKnowledgeRuntime.metadataKey]: knowledge.signature }
|
|
148
|
+
: {}),
|
|
118
149
|
},
|
|
119
150
|
},
|
|
120
151
|
},
|
|
@@ -63,6 +63,120 @@ describe('context obligatory runtime', () => {
|
|
|
63
63
|
runtime.stop();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
|
|
67
|
+
it('restores project knowledge after compaction even with nothing pinned', async () => {
|
|
68
|
+
// Pinned messages are already in the conversation until compaction removes
|
|
69
|
+
// them; project knowledge was never there at all, so a session with no
|
|
70
|
+
// pinned messages still has something to get back.
|
|
71
|
+
const requests = [];
|
|
72
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init = {}) => {
|
|
73
|
+
const url = new URL(typeof input === 'string' ? input : input.url);
|
|
74
|
+
requests.push({ path: url.pathname, method: init.method ?? 'GET', body: init.body });
|
|
75
|
+
if (url.pathname === '/session/ses_1' && init.method === 'PATCH') return json({});
|
|
76
|
+
if (url.pathname === '/session/ses_1') return json({
|
|
77
|
+
id: 'ses_1',
|
|
78
|
+
metadata: { openchamber: { knowledge_context_delivered: 'sig-before-compaction' } },
|
|
79
|
+
});
|
|
80
|
+
if (url.pathname === '/session/ses_1/message') return json([
|
|
81
|
+
{ info: { id: 'msg_agent', role: 'assistant', providerID: 'provider', modelID: 'model', agent: 'build' } },
|
|
82
|
+
{ info: { id: 'msg_summary', role: 'assistant', summary: true, time: { completed: 30 } } },
|
|
83
|
+
]);
|
|
84
|
+
if (url.pathname === '/session/ses_1/prompt_async') return json({});
|
|
85
|
+
throw new Error(`Unexpected ${url.pathname}`);
|
|
86
|
+
}));
|
|
87
|
+
const resolvePending = vi.fn(async () => ({
|
|
88
|
+
text: '## Pinned notes\n\n- Remember this.',
|
|
89
|
+
signature: 'sig-1',
|
|
90
|
+
}));
|
|
91
|
+
const runtime = createContextObligatoryRuntime({
|
|
92
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
93
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
94
|
+
sessionKnowledgeRuntime: {
|
|
95
|
+
metadataKey: 'knowledge_context_delivered',
|
|
96
|
+
readPins: () => ({ notes: ['n1'], plans: [] }),
|
|
97
|
+
resolvePending,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await runtime.processPayload({
|
|
102
|
+
type: 'session.compacted',
|
|
103
|
+
properties: { sessionID: 'ses_1', directory: '/work/project' },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(resolvePending).toHaveBeenCalledWith(
|
|
107
|
+
'/work/project',
|
|
108
|
+
'',
|
|
109
|
+
{ notes: ['n1'], plans: [] },
|
|
110
|
+
);
|
|
111
|
+
const prompt = requests.find((request) => request.path.endsWith('/prompt_async'));
|
|
112
|
+
expect(JSON.parse(prompt.body).parts[0].text).toContain('Remember this.');
|
|
113
|
+
const patch = requests.find((request) => request.method === 'PATCH');
|
|
114
|
+
// Recorded with the cursor, so the next ordinary send does not repeat it.
|
|
115
|
+
expect(JSON.parse(patch.body).metadata.openchamber.knowledge_context_delivered).toBe('sig-1');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('sends pinned messages and project knowledge as one message', async () => {
|
|
119
|
+
const requests = [];
|
|
120
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init = {}) => {
|
|
121
|
+
const url = new URL(typeof input === 'string' ? input : input.url);
|
|
122
|
+
requests.push({ path: url.pathname, method: init.method ?? 'GET', body: init.body });
|
|
123
|
+
if (url.pathname === '/session/ses_1' && init.method === 'PATCH') return json({});
|
|
124
|
+
if (url.pathname === '/session/ses_1') return json({
|
|
125
|
+
id: 'ses_1',
|
|
126
|
+
metadata: { openchamber: { context_obligatory_messages: [{ id: 'msg_1', createdAt: 10, role: 'user' }] } },
|
|
127
|
+
});
|
|
128
|
+
if (url.pathname === '/session/ses_1/message') return json([
|
|
129
|
+
{ info: { id: 'msg_agent', role: 'assistant', providerID: 'provider', modelID: 'model', agent: 'build' } },
|
|
130
|
+
{ info: { id: 'msg_summary', role: 'assistant', summary: true, time: { completed: 30 } } },
|
|
131
|
+
]);
|
|
132
|
+
if (url.pathname === '/session/ses_1/message/msg_1') return json({ parts: [{ type: 'text', text: 'Pinned message' }] });
|
|
133
|
+
if (url.pathname === '/session/ses_1/prompt_async') return json({});
|
|
134
|
+
throw new Error(`Unexpected ${url.pathname}`);
|
|
135
|
+
}));
|
|
136
|
+
const runtime = createContextObligatoryRuntime({
|
|
137
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
138
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
139
|
+
sessionKnowledgeRuntime: {
|
|
140
|
+
metadataKey: 'knowledge_context_delivered',
|
|
141
|
+
readPins: () => ({ notes: ['n1'], plans: [] }),
|
|
142
|
+
resolvePending: async () => ({ text: 'Pinned notes block', signature: 'sig-1' }),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await runtime.processPayload({ type: 'session.compacted', properties: { sessionID: 'ses_1' } });
|
|
147
|
+
|
|
148
|
+
// One turn, not two: back-to-back synthetic messages read as the agent
|
|
149
|
+
// being interrupted twice.
|
|
150
|
+
const prompts = requests.filter((request) => request.path.endsWith('/prompt_async'));
|
|
151
|
+
expect(prompts).toHaveLength(1);
|
|
152
|
+
const text = JSON.parse(prompts[0].body).parts[0].text;
|
|
153
|
+
expect(text).toContain('Pinned notes block');
|
|
154
|
+
expect(text).toContain('Pinned message');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('does nothing when the session already carries the knowledge and has no pins', async () => {
|
|
158
|
+
const requests = [];
|
|
159
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init = {}) => {
|
|
160
|
+
const url = new URL(typeof input === 'string' ? input : input.url);
|
|
161
|
+
requests.push({ path: url.pathname, method: init.method ?? 'GET' });
|
|
162
|
+
if (url.pathname === '/session/ses_1') return json({ id: 'ses_1', metadata: {} });
|
|
163
|
+
throw new Error(`Unexpected ${url.pathname}`);
|
|
164
|
+
}));
|
|
165
|
+
const runtime = createContextObligatoryRuntime({
|
|
166
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
167
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
168
|
+
sessionKnowledgeRuntime: {
|
|
169
|
+
metadataKey: 'knowledge_context_delivered',
|
|
170
|
+
readPins: () => ({ notes: [], plans: [] }),
|
|
171
|
+
resolvePending: async () => ({ text: '', signature: 'sig-1' }),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await runtime.processPayload({ type: 'session.compacted', properties: { sessionID: 'ses_1' } });
|
|
176
|
+
|
|
177
|
+
expect(requests.some((request) => request.path.endsWith('/prompt_async'))).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
|
|
66
180
|
it('ignores ordinary idle events without making requests', async () => {
|
|
67
181
|
const fetchImpl = vi.fn();
|
|
68
182
|
vi.stubGlobal('fetch', fetchImpl);
|
|
@@ -27,6 +27,14 @@ const HANDSHAKE_TIMEOUT_MS = 15_000;
|
|
|
27
27
|
|
|
28
28
|
const toWebSocketUrl = (baseUrl, port) => {
|
|
29
29
|
const parsed = new URL('/api/dev-tunnel', baseUrl);
|
|
30
|
+
// WHATWG URL silently ignores a protocol assignment that crosses from a
|
|
31
|
+
// non-special scheme (custom app protocols, relay-virtual URLs) to `ws:`.
|
|
32
|
+
// Without this check the stale scheme survives into `new WebSocket(...)`,
|
|
33
|
+
// which then throws inside the connection handler and takes the whole
|
|
34
|
+
// process down; rejecting here fails the open() call cleanly instead.
|
|
35
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
36
|
+
throw new Error(`The remote base URL must be http(s); got "${parsed.protocol}"`);
|
|
37
|
+
}
|
|
30
38
|
parsed.protocol = parsed.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
31
39
|
parsed.searchParams.set('port', String(port));
|
|
32
40
|
return parsed.toString();
|
|
@@ -76,7 +84,18 @@ export const createDevTunnelClient = ({
|
|
|
76
84
|
socket.setNoDelay(true);
|
|
77
85
|
sockets.add(socket);
|
|
78
86
|
|
|
79
|
-
|
|
87
|
+
// A synchronous throw here would be an uncaught exception in the
|
|
88
|
+
// connection handler and crash the process; one bad connection must
|
|
89
|
+
// fail alone.
|
|
90
|
+
let upstream;
|
|
91
|
+
try {
|
|
92
|
+
upstream = new WebSocket(target, { headers, perMessageDeflate: false });
|
|
93
|
+
} catch (error) {
|
|
94
|
+
logger.warn?.(`[dev-tunnel] failed to dial upstream for port ${remotePort}: ${error?.message || error}`);
|
|
95
|
+
sockets.delete(socket);
|
|
96
|
+
try { socket.destroy(); } catch { /* already gone */ }
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
80
99
|
upstream.binaryType = 'nodebuffer';
|
|
81
100
|
let pendingWrites = [];
|
|
82
101
|
let pendingBytes = 0;
|
|
@@ -195,6 +195,15 @@ describe('dev tunnel end to end', () => {
|
|
|
195
195
|
expect(client.list()).toEqual([]);
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
+
test('rejects a non-http(s) base URL instead of crashing on first connection', async () => {
|
|
199
|
+
// A non-special scheme survives the `ws:` protocol assignment (WHATWG URL
|
|
200
|
+
// ignores it), so `new WebSocket(...)` used to throw inside the connection
|
|
201
|
+
// handler and take the whole process down.
|
|
202
|
+
const client = createDevTunnelClient({ logger: { warn: () => {} } });
|
|
203
|
+
await expect(client.open({ baseUrl: 'openchamber-ui://index', port: 5173 })).rejects.toThrow('must be http(s)');
|
|
204
|
+
expect(client.list()).toEqual([]);
|
|
205
|
+
});
|
|
206
|
+
|
|
198
207
|
// Not covered here: recovery after a request the dev server kills mid-flight.
|
|
199
208
|
// The behaviour is real (each connection tears down independently), but the
|
|
200
209
|
// abandoned socket makes this harness's teardown unreliable, and a flaky test
|
|
@@ -16,6 +16,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
16
16
|
- `GET /api/fs/raw`
|
|
17
17
|
- `GET /api/fs/serve/:path(*)`
|
|
18
18
|
- `POST /api/fs/write`
|
|
19
|
+
- `POST /api/fs/upload`
|
|
19
20
|
- `POST /api/fs/delete`
|
|
20
21
|
- `POST /api/fs/rename`
|
|
21
22
|
- `POST /api/fs/reveal`
|
|
@@ -35,5 +36,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
35
36
|
## Notes for contributors
|
|
36
37
|
- Keep filesystem policy (workspace root checks, error mapping, exec timeout behavior) inside this module, not in the composition root.
|
|
37
38
|
- Filesystem `EPERM`/`EACCES` failures use the stable `reason: "os-permission"` response marker. Policy denials such as workspace-boundary or missing-grant failures must not use that marker because a native folder picker cannot remediate them.
|
|
39
|
+
- Read-only routes authorize the requested path against the workspace before resolving symlinks. A symlink reached through the workspace may therefore target a file outside it, while a directly requested outside path still requires an exact-path grant. Write routes keep canonical-target boundary checks.
|
|
38
40
|
- If adding new `/api/fs/*` endpoints, add them in `routes.js` and extend this document.
|
|
39
41
|
- `GET /api/fs/list` may resolve symlinks with `realpath` to read directory contents, but the response `path` and each entry `path` must stay in the caller's requested path space (`path.join(requestedPath, name)`). Returning real paths breaks file-tree expansion for directories reached through workspace symlinks.
|
|
42
|
+
- `POST /api/fs/upload` accepts one `application/octet-stream` body with `path` and optional `overwrite=true` query parameters. The body streams into a same-directory temp file with a 100 MiB default cap configurable through `OPENCHAMBER_FS_UPLOAD_MAX_BYTES`; failed and oversized uploads clean up that temp file. New files commit through an atomic no-replace link, existing files return `409` unless overwrite is explicit, directory targets are rejected, and the destination parent resolves before writing so uploads cannot escape through workspace symlinks.
|
package/server/lib/fs/routes.js
CHANGED
|
@@ -108,6 +108,12 @@ const createGitCheckIgnoreTimeoutMs = () => {
|
|
|
108
108
|
return 2500;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
const createUploadMaxBytes = () => {
|
|
112
|
+
const raw = Number(process.env.OPENCHAMBER_FS_UPLOAD_MAX_BYTES);
|
|
113
|
+
if (Number.isFinite(raw) && raw > 0) return Math.floor(raw);
|
|
114
|
+
return 100 * 1024 * 1024;
|
|
115
|
+
};
|
|
116
|
+
|
|
111
117
|
const FILE_MIME_MAP = Object.freeze({
|
|
112
118
|
'.html': 'text/html',
|
|
113
119
|
'.htm': 'text/html',
|
|
@@ -140,6 +146,27 @@ const FILE_MIME_MAP = Object.freeze({
|
|
|
140
146
|
|
|
141
147
|
const MAX_SERVE_BYTES = 100 * 1024 * 1024;
|
|
142
148
|
|
|
149
|
+
const streamUploadBody = async (req, handle, maxBytes) => {
|
|
150
|
+
let received = 0;
|
|
151
|
+
for await (const chunk of req) {
|
|
152
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
153
|
+
received += buffer.length;
|
|
154
|
+
if (received > maxBytes) {
|
|
155
|
+
req.resume?.();
|
|
156
|
+
throw Object.assign(new Error('Upload exceeds the maximum allowed size'), { uploadTooLarge: true });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let offset = 0;
|
|
160
|
+
while (offset < buffer.length) {
|
|
161
|
+
const { bytesWritten } = await handle.write(buffer, offset, buffer.length - offset, null);
|
|
162
|
+
if (!Number.isFinite(bytesWritten) || bytesWritten <= 0) {
|
|
163
|
+
throw new Error('Failed to write upload');
|
|
164
|
+
}
|
|
165
|
+
offset += bytesWritten;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
143
170
|
// Only deterministic, side-effect-free git plumbing path queries are cacheable.
|
|
144
171
|
// Anything outside this allowlist (including any non-git command) runs normally
|
|
145
172
|
// — we never cache arbitrary exec.
|
|
@@ -758,14 +785,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
758
785
|
return res.status(400).json({ error: resolved.error });
|
|
759
786
|
}
|
|
760
787
|
|
|
761
|
-
const
|
|
762
|
-
fsPromises.realpath(resolved.resolved),
|
|
763
|
-
fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
|
|
764
|
-
]);
|
|
765
|
-
|
|
766
|
-
if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
|
|
767
|
-
return res.status(403).json({ error: 'Access to file denied' });
|
|
768
|
-
}
|
|
788
|
+
const canonicalPath = await fsPromises.realpath(resolved.resolved);
|
|
769
789
|
|
|
770
790
|
const stats = await fsPromises.stat(canonicalPath);
|
|
771
791
|
if (!stats.isFile()) {
|
|
@@ -815,14 +835,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
815
835
|
return res.status(400).json({ error: resolved.error });
|
|
816
836
|
}
|
|
817
837
|
|
|
818
|
-
const
|
|
819
|
-
fsPromises.realpath(resolved.resolved),
|
|
820
|
-
fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
|
|
821
|
-
]);
|
|
822
|
-
|
|
823
|
-
if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
|
|
824
|
-
return res.status(403).json({ error: 'Access to file denied' });
|
|
825
|
-
}
|
|
838
|
+
const canonicalPath = await fsPromises.realpath(resolved.resolved);
|
|
826
839
|
|
|
827
840
|
const stats = await fsPromises.stat(canonicalPath);
|
|
828
841
|
if (!stats.isFile()) {
|
|
@@ -886,14 +899,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
886
899
|
return res.status(400).json({ error: resolved.error });
|
|
887
900
|
}
|
|
888
901
|
|
|
889
|
-
const
|
|
890
|
-
fsPromises.realpath(resolved.resolved),
|
|
891
|
-
fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
|
|
892
|
-
]);
|
|
893
|
-
|
|
894
|
-
if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
|
|
895
|
-
return res.status(403).json({ error: 'Access to file denied' });
|
|
896
|
-
}
|
|
902
|
+
const canonicalPath = await fsPromises.realpath(resolved.resolved);
|
|
897
903
|
|
|
898
904
|
const stats = await fsPromises.stat(canonicalPath);
|
|
899
905
|
if (!stats.isFile()) {
|
|
@@ -971,14 +977,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
971
977
|
return res.status(400).json({ error: resolved.error });
|
|
972
978
|
}
|
|
973
979
|
|
|
974
|
-
const
|
|
975
|
-
fsPromises.realpath(resolved.resolved),
|
|
976
|
-
fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base)),
|
|
977
|
-
]);
|
|
978
|
-
|
|
979
|
-
if (!isPathWithinRoot(canonicalPath, canonicalBase, path, os)) {
|
|
980
|
-
return res.status(403).json({ error: 'Access to file denied' });
|
|
981
|
-
}
|
|
980
|
+
const canonicalPath = await fsPromises.realpath(resolved.resolved);
|
|
982
981
|
|
|
983
982
|
const stats = await fsPromises.stat(canonicalPath);
|
|
984
983
|
if (!stats.isFile()) {
|
|
@@ -1069,6 +1068,124 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1069
1068
|
}
|
|
1070
1069
|
});
|
|
1071
1070
|
|
|
1071
|
+
app.post('/api/fs/upload', async (req, res) => {
|
|
1072
|
+
const filePath = typeof req.query?.path === 'string' ? req.query.path.trim() : '';
|
|
1073
|
+
const overwrite = req.query?.overwrite === 'true';
|
|
1074
|
+
if (!filePath) {
|
|
1075
|
+
return res.status(400).json({ error: 'Path is required' });
|
|
1076
|
+
}
|
|
1077
|
+
if (!String(req.headers?.['content-type'] || '').toLowerCase().startsWith('application/octet-stream')) {
|
|
1078
|
+
return res.status(415).json({ error: 'Content-Type must be application/octet-stream' });
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const maxUploadBytes = createUploadMaxBytes();
|
|
1082
|
+
const declaredSize = Number(req.headers?.['content-length']);
|
|
1083
|
+
if (Number.isFinite(declaredSize) && declaredSize > maxUploadBytes) {
|
|
1084
|
+
req.resume?.();
|
|
1085
|
+
return res.status(413).json({ error: `File exceeds maximum size of ${maxUploadBytes} bytes` });
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
try {
|
|
1089
|
+
const resolved = await resolveWorkspacePathFromContext({
|
|
1090
|
+
req,
|
|
1091
|
+
targetPath: filePath,
|
|
1092
|
+
resolveProjectDirectory,
|
|
1093
|
+
path,
|
|
1094
|
+
os,
|
|
1095
|
+
normalizeDirectoryPath,
|
|
1096
|
+
openchamberUserConfigRoot,
|
|
1097
|
+
});
|
|
1098
|
+
if (!resolved.ok) {
|
|
1099
|
+
return res.status(400).json({ error: resolved.error });
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
const canonicalBase = await fsPromises.realpath(resolved.base).catch(() => path.resolve(resolved.base));
|
|
1103
|
+
const requestedParent = path.dirname(resolved.resolved);
|
|
1104
|
+
const canonicalParent = await fsPromises.realpath(requestedParent);
|
|
1105
|
+
if (!isPathWithinRoot(canonicalParent, canonicalBase, path, os)) {
|
|
1106
|
+
return res.status(403).json({ error: 'Access denied' });
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
const existingPath = await fsPromises.realpath(resolved.resolved).catch((error) => {
|
|
1110
|
+
if (error && typeof error === 'object' && error.code === 'ENOENT') {
|
|
1111
|
+
return null;
|
|
1112
|
+
}
|
|
1113
|
+
throw error;
|
|
1114
|
+
});
|
|
1115
|
+
const writePath = existingPath || path.join(canonicalParent, path.basename(resolved.resolved));
|
|
1116
|
+
if (!isPathWithinRoot(writePath, canonicalBase, path, os)) {
|
|
1117
|
+
return res.status(403).json({ error: 'Access denied' });
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
if (existingPath) {
|
|
1121
|
+
const stats = await fsPromises.stat(existingPath);
|
|
1122
|
+
if (stats.isDirectory()) {
|
|
1123
|
+
return res.status(400).json({ error: 'Specified path is a directory' });
|
|
1124
|
+
}
|
|
1125
|
+
if (!overwrite) {
|
|
1126
|
+
req.resume?.();
|
|
1127
|
+
return res.status(409).json({ error: 'File already exists', reason: 'already-exists' });
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
const tmp = `${writePath}.upload-${crypto.randomUUID()}`;
|
|
1132
|
+
let tempExists = false;
|
|
1133
|
+
try {
|
|
1134
|
+
const handle = await fsPromises.open(tmp, 'wx');
|
|
1135
|
+
tempExists = true;
|
|
1136
|
+
let streamError = null;
|
|
1137
|
+
try {
|
|
1138
|
+
await streamUploadBody(req, handle, maxUploadBytes);
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
streamError = error;
|
|
1141
|
+
}
|
|
1142
|
+
try {
|
|
1143
|
+
await handle.close();
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
if (!streamError) throw error;
|
|
1146
|
+
}
|
|
1147
|
+
if (streamError) throw streamError;
|
|
1148
|
+
|
|
1149
|
+
if (overwrite) {
|
|
1150
|
+
await fsPromises.rename(tmp, writePath);
|
|
1151
|
+
} else {
|
|
1152
|
+
// A same-directory hard link commits without replacing a target that
|
|
1153
|
+
// appeared after the existence check. The temp file is already fully
|
|
1154
|
+
// flushed, so readers never observe a partial upload.
|
|
1155
|
+
await fsPromises.link(tmp, writePath);
|
|
1156
|
+
await fsPromises.unlink(tmp).catch(() => {});
|
|
1157
|
+
}
|
|
1158
|
+
tempExists = false;
|
|
1159
|
+
} catch (error) {
|
|
1160
|
+
if (tempExists) {
|
|
1161
|
+
await fsPromises.unlink(tmp).catch(() => {});
|
|
1162
|
+
}
|
|
1163
|
+
throw error;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
return res.json({ success: true, path: resolved.resolved });
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
const err = error;
|
|
1169
|
+
if (err && typeof err === 'object' && err.code === 'EEXIST') {
|
|
1170
|
+
return res.status(409).json({ error: 'File already exists', reason: 'already-exists' });
|
|
1171
|
+
}
|
|
1172
|
+
if (err && typeof err === 'object' && err.code === 'ENOENT') {
|
|
1173
|
+
return res.status(404).json({ error: 'Destination directory not found', reason: 'not-found' });
|
|
1174
|
+
}
|
|
1175
|
+
if (err && typeof err === 'object' && err.uploadTooLarge) {
|
|
1176
|
+
return res.status(413).json({ error: `File exceeds maximum size of ${maxUploadBytes} bytes` });
|
|
1177
|
+
}
|
|
1178
|
+
if (err && typeof err === 'object' && (err.code === 'EISDIR' || err.code === 'ENOTDIR')) {
|
|
1179
|
+
return res.status(400).json({ error: 'Specified path is a directory' });
|
|
1180
|
+
}
|
|
1181
|
+
if (isOsPermissionError(err)) {
|
|
1182
|
+
return sendOsPermissionDenied(res, 'Access denied');
|
|
1183
|
+
}
|
|
1184
|
+
console.error('Failed to upload file:', error);
|
|
1185
|
+
return res.status(500).json({ error: (error && error.message) || 'Failed to upload file' });
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1072
1189
|
app.post('/api/fs/delete', async (req, res) => {
|
|
1073
1190
|
const { path: targetPath } = req.body || {};
|
|
1074
1191
|
if (!targetPath || typeof targetPath !== 'string') {
|