@openchamber/web 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-zm3C1FvM.js → CodeMirrorCommentWidgets-CmKmyb9T.js} +1 -1
- package/dist/assets/{DiffView-DNExNi1z.js → DiffView-8-PFpZ2p.js} +1 -1
- package/dist/assets/{FilesView-DUCLmHBi.js → FilesView-0Ie20mEk.js} +9 -9
- package/dist/assets/{GitView-Bz9z6gZA.js → GitView-DNUSu00w.js} +1 -1
- package/dist/assets/{GuestAttachDialog-UGp4KDlK.js → GuestAttachDialog-Cv6QzjHC.js} +1 -1
- package/dist/assets/{GuestSurfacePane-B3pdB_2u.js → GuestSurfacePane-Bt3jB_Ye.js} +1 -1
- package/dist/assets/{JsonTreeView-7lVecnZl.js → JsonTreeView-BlyHTRhM.js} +1 -1
- package/dist/assets/{LinearIssuesView-CTGRS9Vq.js → LinearIssuesView-CSl2MUfA.js} +1 -1
- package/dist/assets/MarkdownImageGallery-2UXJF-5B.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +12 -0
- package/dist/assets/{OnboardingScreen-CBx6cXPP.js → OnboardingScreen-CIdXJpfc.js} +1 -1
- package/dist/assets/{PatchDiff-D7VVpR_l.js → PatchDiff-ByvnbG5T.js} +1 -1
- package/dist/assets/{PierreDiffViewer-Gbfks1pk.js → PierreDiffViewer-BXieg0mH.js} +1 -1
- package/dist/assets/{PlanView-CPSK0x97.js → PlanView-DEIi3Q7M.js} +3 -3
- package/dist/assets/PluginPane-BEPUWVho.js +3 -0
- package/dist/assets/{SettingsView-Dql7z6Ww.js → SettingsView-CiNh-RbW.js} +16 -16
- package/dist/assets/{SettingsWindow-D6oi-UmV.js → SettingsWindow-BIz224xs.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-BXA0FAWj.js → SubmoduleDiffSummary-CXKmlps9.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BQJsSbDm.js → ToolOutputDialog-BsgAK8xu.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-FY9w0TVT.js → ToolPartDiffPreview-vdPObXOf.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-B9YhAya5.js → VirtualizedFileDiff-BkFNKWS5.js} +1 -1
- package/dist/assets/{WalkthroughView-CmFgOUFN.js → WalkthroughView-6oE-MuDL.js} +2 -2
- package/dist/assets/{appThemeRegistry-BebxalUt.js → appThemeRegistry-aHUNHoqP.js} +1 -1
- package/dist/assets/{commitAndPush-Wfxng_IK.js → commitAndPush-Bon9r94r.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-BCOqgixN.js → computeVirtualFileMetrics-DKqr_1AQ.js} +1 -1
- package/dist/assets/de-CgAJ51z7.js +10 -0
- package/dist/assets/es-zGi_ravM.js +16 -0
- package/dist/assets/fr-CPfogrWx.js +14 -0
- package/dist/assets/index-CHfphYL3.js +41 -0
- package/dist/assets/{index-3TiDNtfN.js → index-DpFttslC.js} +1 -1
- package/dist/assets/index-DvMJ3w6V.css +1 -0
- package/dist/assets/{isDiffPlainText-DnDYQmWK.js → isDiffPlainText-kzAgpIgi.js} +1 -1
- package/dist/assets/{isFilePlainText-BA_AHX7d.js → isFilePlainText-Uj6y-jzz.js} +1 -1
- package/dist/assets/ja-DMk6wd-U.js +16 -0
- package/dist/assets/ko-BFpzJ8jc.js +16 -0
- package/dist/assets/{main-DtUmJp9B.js → main-CbfMxn-I.js} +2 -2
- package/dist/assets/main-anyZFMIs.js +896 -0
- package/dist/assets/{markdownCore-BSnlUXBf.js → markdownCore-CmM47cAE.js} +5 -5
- package/dist/assets/{miniChat-BYfLUnDK.js → miniChat-CiAKBC10.js} +2 -2
- package/dist/assets/{mobile-DH3hI6gd.js → mobile-CsT4sJwC.js} +2 -2
- package/dist/assets/{patchFileDiff--L7lt_GZ.js → patchFileDiff-DeaE08W0.js} +1 -1
- package/dist/assets/{pl-BkI_xHqz.js → pl-VdRPcZrB.js} +5 -5
- package/dist/assets/pt-BR-BRys_lOW.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-C7kpNW_-.js → renderElectronMiniChatApp-C5677jy0.js} +2 -2
- package/dist/assets/{renderMobileApp-i0nq7Dwy.js → renderMobileApp-D4dBBAqQ.js} +7 -7
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +27 -0
- package/dist/assets/{scheduledTasksApi-Cy7uZCaI.js → scheduledTasksApi-BZCNJ588.js} +1 -1
- package/dist/assets/{shikiHighlight-D4vxipfr.js → shikiHighlight-BSUEa3yF.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-BYAHtJwQ.js → textMateThemeFromAppTheme-CsATFZIV.js} +1 -1
- package/dist/assets/tr-CA9ckNnm.js +7 -0
- package/dist/assets/uk-byjR-y8D.js +16 -0
- package/dist/assets/{useAppFontEffects-DHZ9-L30.js → useAppFontEffects-BWQZ5DeI.js} +153 -150
- package/dist/assets/{useInlineCommentController-CvpOMK-R.js → useInlineCommentController-DlFyVfBu.js} +1 -1
- package/dist/assets/{useRootScrollLock-DzNFi-fn.js → useRootScrollLock-Cp1eFoM2.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-j3fhlwUM.js → vendor-codemirror-language-data-BwwommM0.js} +2 -2
- package/dist/assets/{web-components-BvHNFSEG.js → web-components-D3Yjr4Zx.js} +1 -1
- package/dist/assets/zh-CN-DRabgxdG.js +16 -0
- package/dist/assets/zh-TW-rbY5c9UK.js +16 -0
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/index.js +64 -0
- package/server/lib/event-stream/global-hub.js +23 -1
- package/server/lib/event-stream/global-hub.test.js +35 -0
- package/server/lib/event-stream/global-ws-bridge.js +3 -1
- package/server/lib/event-stream/upstream-reader.js +3 -2
- package/server/lib/opencode/DOCUMENTATION.md +6 -2
- package/server/lib/opencode/bootstrap-runtime.js +2 -1
- package/server/lib/opencode/config-entity-v2.test.js +27 -0
- package/server/lib/opencode/config-paths.test.js +12 -0
- package/server/lib/opencode/core-routes.js +17 -4
- package/server/lib/opencode/core-routes.test.js +26 -0
- package/server/lib/opencode/mcp.js +7 -2
- package/server/lib/opencode/project-directory-runtime.js +8 -0
- package/server/lib/opencode/project-directory-runtime.test.js +13 -0
- package/server/lib/opencode/proxy.js +38 -2
- package/server/lib/opencode/routes.js +18 -0
- package/server/lib/opencode/server-utils-runtime.js +5 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +3 -0
- package/server/lib/opencode/shared.js +17 -2
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/watcher.js +3 -1
- package/server/lib/realtime-proxy.js +5 -1
- package/server/lib/realtime-proxy.test.js +29 -0
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +11 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -10
- package/server/lib/small-model/index.js +27 -32
- package/server/lib/small-model/index.test.js +28 -16
- package/server/lib/spaces/DOCUMENTATION.md +381 -20
- package/server/lib/spaces/code-in-bait.js +145 -6
- package/server/lib/spaces/code-in.js +10 -150
- package/server/lib/spaces/code-in.test.js +7 -83
- package/server/lib/spaces/code-out.js +1819 -0
- package/server/lib/spaces/code-out.test.js +3945 -0
- package/server/lib/spaces/code-transfer.js +173 -0
- package/server/lib/spaces/command-stream.test.js +181 -0
- package/server/lib/spaces/dispatcher.js +670 -0
- package/server/lib/spaces/dispatcher.test.js +582 -0
- package/server/lib/spaces/gatekeeper-channel.js +2 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +9 -3
- package/server/lib/spaces/gatekeeper-program.cjs +4 -1
- package/server/lib/spaces/gatekeeper-program.test.js +3 -0
- package/server/lib/spaces/hardening.js +20 -4
- package/server/lib/spaces/hardening.test.js +18 -3
- package/server/lib/spaces/host-git.js +7 -4
- package/server/lib/spaces/host-git.test.js +6 -2
- package/server/lib/spaces/host.js +304 -0
- package/server/lib/spaces/host.test.js +273 -0
- package/server/lib/spaces/journey.js +393 -0
- package/server/lib/spaces/journey.test.js +384 -0
- package/server/lib/spaces/layout.js +26 -2
- package/server/lib/spaces/manager.js +4 -3
- package/server/lib/spaces/manager.test.js +6 -0
- package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
- package/server/lib/spaces/places/contract-suite.js +36 -0
- package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
- package/server/lib/spaces/places/docker.js +15 -3
- package/server/lib/spaces/places/docker.test.js +33 -2
- package/server/lib/spaces/places/escape-suite.js +86 -14
- package/server/lib/spaces/places/memory-place.js +24 -1
- package/server/lib/spaces/places/registry.js +1 -1
- package/server/lib/spaces/places/server.docker.live.test.js +69 -33
- package/server/lib/spaces/places/sessions.docker.live.test.js +220 -0
- package/server/lib/spaces/routes.js +207 -0
- package/server/lib/spaces/routes.test.js +211 -0
- package/server/lib/spaces/run-command.js +261 -8
- package/server/lib/spaces/run-command.test.js +193 -3
- package/server/lib/spaces/space-events.js +153 -0
- package/server/lib/spaces/space-events.test.js +160 -0
- package/server/lib/spaces/space-records.js +98 -0
- package/server/lib/spaces/space-records.test.js +73 -0
- package/server/lib/spaces/space-sessions.js +210 -0
- package/server/lib/spaces/space-sessions.test.js +161 -0
- package/server/lib/spaces/websocket.js +329 -0
- package/server/lib/spaces/websocket.test.js +345 -0
- package/server/lib/ui-auth/ui-auth.js +8 -2
- package/server/lib/ui-auth/ui-auth.test.js +29 -0
- package/server/opencode-proxy.test.js +113 -0
- package/dist/assets/MarkdownImageGallery-DQk5adUs.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +0 -12
- package/dist/assets/PluginPane-BIGsUx69.js +0 -3
- package/dist/assets/de-CMA45TC-.js +0 -10
- package/dist/assets/es-DPL4fBtl.js +0 -16
- package/dist/assets/fr-OHBKBseP.js +0 -14
- package/dist/assets/index-BLUZa5u0.js +0 -41
- package/dist/assets/index-Cm2rrq69.css +0 -1
- package/dist/assets/ja-DvX4WSRf.js +0 -16
- package/dist/assets/ko-BUcLd8YZ.js +0 -16
- package/dist/assets/main-B_jri4i-.js +0 -896
- package/dist/assets/pt-BR-7wFtQlV9.js +0 -16
- package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +0 -27
- package/dist/assets/tr-TsD-AqEH.js +0 -7
- package/dist/assets/uk-B-qspCmD.js +0 -16
- package/dist/assets/zh-CN-DYuPJV5i.js +0 -16
- package/dist/assets/zh-TW-BX_2D_lV.js +0 -16
package/dist/index.html
CHANGED
|
@@ -515,17 +515,17 @@
|
|
|
515
515
|
pointer-events: none;
|
|
516
516
|
}
|
|
517
517
|
</style>
|
|
518
|
-
<script type="module" crossorigin src="/assets/main-
|
|
518
|
+
<script type="module" crossorigin src="/assets/main-CbfMxn-I.js"></script>
|
|
519
519
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
520
520
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zod-BSoePkpP.js">
|
|
521
521
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
522
522
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
|
|
523
523
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
|
|
524
524
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-client-DYdsLbCM.js">
|
|
525
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
525
|
+
<link rel="modulepreload" crossorigin href="/assets/index-CHfphYL3.js">
|
|
526
526
|
<link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-CirXEPJq.js">
|
|
527
527
|
<link rel="modulepreload" crossorigin href="/assets/vendor-katex-CHD9BdDO.js">
|
|
528
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
528
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DvMJ3w6V.css">
|
|
529
529
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-Cp579UoJ.css">
|
|
530
530
|
</head>
|
|
531
531
|
<body class="h-full bg-background text-foreground">
|
package/dist/mini-chat.html
CHANGED
|
@@ -74,16 +74,16 @@
|
|
|
74
74
|
}
|
|
75
75
|
</style>
|
|
76
76
|
|
|
77
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
77
|
+
<script type="module" crossorigin src="/assets/miniChat-CiAKBC10.js"></script>
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zod-BSoePkpP.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
|
|
82
82
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
|
|
83
83
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-client-DYdsLbCM.js">
|
|
84
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
84
|
+
<link rel="modulepreload" crossorigin href="/assets/index-CHfphYL3.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="/assets/vendor-katex-CHD9BdDO.js">
|
|
86
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
86
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DvMJ3w6V.css">
|
|
87
87
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-Cp579UoJ.css">
|
|
88
88
|
</head>
|
|
89
89
|
<body class="h-full bg-background text-foreground">
|
package/dist/mobile.html
CHANGED
|
@@ -63,16 +63,16 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-CsT4sJwC.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zod-BSoePkpP.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
|
|
70
70
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-client-DYdsLbCM.js">
|
|
73
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
73
|
+
<link rel="modulepreload" crossorigin href="/assets/index-CHfphYL3.js">
|
|
74
74
|
<link rel="modulepreload" crossorigin href="/assets/vendor-katex-CHD9BdDO.js">
|
|
75
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
75
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DvMJ3w6V.css">
|
|
76
76
|
<link rel="stylesheet" crossorigin href="/assets/vendor-katex-Cp579UoJ.css">
|
|
77
77
|
</head>
|
|
78
78
|
<body class="h-full bg-background text-foreground">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openchamber/web",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./server/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@clack/prompts": "^1.1.0",
|
|
28
28
|
"@octokit/rest": "^22.0.1",
|
|
29
|
-
"@openchamber/sdk": "2.0.
|
|
29
|
+
"@openchamber/sdk": "2.0.2",
|
|
30
30
|
"@opencode/client": "2.0.16",
|
|
31
31
|
"@opencode/schema": "2.0.16",
|
|
32
32
|
"@simplewebauthn/server": "13.3.3",
|
package/server/index.js
CHANGED
|
@@ -112,6 +112,8 @@ import { createAgentMemoryRuntime } from './lib/agent-memory/runtime.js';
|
|
|
112
112
|
import { createAgentMemoryActions } from './lib/agent-memory/actions.js';
|
|
113
113
|
import { createMemoryProjectResolver } from './lib/agent-memory/project-resolution.js';
|
|
114
114
|
import { isAgentMemoryFeatureAvailable } from './lib/agent-memory/feature-flag.js';
|
|
115
|
+
import { createSpacesHost } from './lib/spaces/host.js';
|
|
116
|
+
import { createSwitchController, registerSpaceRoutes } from './lib/spaces/routes.js';
|
|
115
117
|
import { resolvePrimaryWorktreeRoot } from './lib/git/service.js';
|
|
116
118
|
import { createRemoteClientAuthRuntime } from './lib/client-auth/remote-clients.js';
|
|
117
119
|
import { createClientPairingRuntime } from './lib/client-auth/pairing.js';
|
|
@@ -387,6 +389,8 @@ const projectDirectoryRuntime = createProjectDirectoryRuntime({
|
|
|
387
389
|
normalizeDirectoryPath,
|
|
388
390
|
getReadSettingsFromDiskMigrated: () => readSettingsFromDiskMigrated,
|
|
389
391
|
sanitizeProjects,
|
|
392
|
+
// A space's directory never runs on the host, whatever route carries it.
|
|
393
|
+
refuseDirectory: (candidate) => spacesHost?.refuseDirectory(candidate) ?? null,
|
|
390
394
|
});
|
|
391
395
|
|
|
392
396
|
const resolveDirectoryCandidate = (...args) => projectDirectoryRuntime.resolveDirectoryCandidate(...args);
|
|
@@ -630,6 +634,9 @@ let openCodeNotReadySince = 0;
|
|
|
630
634
|
let isExternalOpenCode = false;
|
|
631
635
|
let exitOnShutdown = true;
|
|
632
636
|
let uiAuthController = null;
|
|
637
|
+
// The isolated-spaces host: the place, the manager and the dispatcher. Null while the feature's
|
|
638
|
+
// switch is off, and then nothing of the feature runs, see docs/isolated-spaces/DESIGN.md.
|
|
639
|
+
let spacesHost = null;
|
|
633
640
|
let activeTunnelController = null;
|
|
634
641
|
let globalWatcherStartPromise = null;
|
|
635
642
|
const tunnelProviderRegistry = createTunnelProviderRegistry([
|
|
@@ -1106,6 +1113,10 @@ const serverUtilsRuntime = createServerUtilsRuntime({
|
|
|
1106
1113
|
// down, while the proxy is registered later still.
|
|
1107
1114
|
getArchivedSessions: () => openChamberSessionService.archiveStore.getAll(),
|
|
1108
1115
|
getStoredSessionMetadata: () => sessionMetadataStore.listUnmigrated(),
|
|
1116
|
+
// Isolated spaces: with the switch on, the session list carries every space's sessions and
|
|
1117
|
+
// the global SSE stream their events. Called, not captured: the host is made in `main`.
|
|
1118
|
+
getMergeSpaceSessionList: () => (spacesHost ? (payload) => spacesHost.mergeSessionList(payload) : null),
|
|
1119
|
+
getSpaceEventHub: () => (spacesHost ? globalMessageStreamHub : null),
|
|
1109
1120
|
fs,
|
|
1110
1121
|
os,
|
|
1111
1122
|
path,
|
|
@@ -1686,6 +1697,7 @@ const gracefulShutdownRuntime = createGracefulShutdownRuntime({
|
|
|
1686
1697
|
getDictationRuntime: () => dictationRuntime,
|
|
1687
1698
|
getRelayService: () => relayServiceInstance,
|
|
1688
1699
|
getRelayReconcileTimer: () => relayReconcileTimer,
|
|
1700
|
+
getSpacesHost: () => spacesHost,
|
|
1689
1701
|
});
|
|
1690
1702
|
|
|
1691
1703
|
const gracefulShutdown = (...args) => gracefulShutdownRuntime.gracefulShutdown(...args);
|
|
@@ -1862,6 +1874,31 @@ async function main(options = {}) {
|
|
|
1862
1874
|
// but do not hold server listen or managed OpenCode startup on `say -v "?"`.
|
|
1863
1875
|
const sayTTSCapability = detectSayTtsCapability(process);
|
|
1864
1876
|
|
|
1877
|
+
// The isolated-spaces switch, read here at start and changed live through its route below.
|
|
1878
|
+
// While it is off the feature has no place, no manager, no route and runs no `docker`.
|
|
1879
|
+
const buildSpacesHost = () => createSpacesHost({
|
|
1880
|
+
dataDir: OPENCHAMBER_DATA_DIR,
|
|
1881
|
+
dockerPath: searchPathFor('docker', buildAugmentedPath()) ?? 'docker',
|
|
1882
|
+
gitPath: searchPathFor('git', buildAugmentedPath()) ?? 'git',
|
|
1883
|
+
// git starts `docker exec` itself when code moves in or out, so its PATH must find docker.
|
|
1884
|
+
hostEnvironment: { ...process.env, PATH: buildAugmentedPath() },
|
|
1885
|
+
// So the session list can say which registered project each space was made for.
|
|
1886
|
+
listProjectDirectories: async () => {
|
|
1887
|
+
const settings = await readSettingsFromDiskMigrated();
|
|
1888
|
+
return sanitizeProjects(settings?.projects || []).map((project) => project.path);
|
|
1889
|
+
},
|
|
1890
|
+
});
|
|
1891
|
+
const startupSettings = await readSettingsFromDiskMigrated().catch(() => null);
|
|
1892
|
+
if (startupSettings?.isolatedSpacesEnabled === true) {
|
|
1893
|
+
try {
|
|
1894
|
+
spacesHost = buildSpacesHost();
|
|
1895
|
+
} catch (error) {
|
|
1896
|
+
// The feature is absent then, and the rest of the server starts as with the switch off.
|
|
1897
|
+
console.error(`[spaces] isolated spaces are unavailable this start: ${error?.code ?? ''} ${error?.message ?? error}`.trim());
|
|
1898
|
+
spacesHost = null;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1865
1902
|
const app = express();
|
|
1866
1903
|
const serverStartedAt = new Date().toISOString();
|
|
1867
1904
|
const packagedClientOrigins = new Set([
|
|
@@ -2029,8 +2066,35 @@ async function main(options = {}) {
|
|
|
2029
2066
|
setAutoAcceptSession,
|
|
2030
2067
|
agentToolRuntime,
|
|
2031
2068
|
desktopUpdater,
|
|
2069
|
+
skipBodyParsing: (req) => spacesHost?.skipsBodyParsing(req) === true,
|
|
2032
2070
|
});
|
|
2033
2071
|
uiAuthController = bootstrapResult.uiAuthController;
|
|
2072
|
+
// After the API auth gate, before every route that reads a directory, before the OpenCode proxy.
|
|
2073
|
+
// The slot is mounted once and reads the host at call time, so the switch can turn the feature
|
|
2074
|
+
// on and off live: with no host it passes every request on and no upgrade is taken.
|
|
2075
|
+
app.use((req, res, next) => (spacesHost ? spacesHost.middleware(req, res, next) : next()));
|
|
2076
|
+
server.on('upgrade', (...args) => { spacesHost?.upgradeHandler(...args); });
|
|
2077
|
+
const startSpacesHost = (host) => {
|
|
2078
|
+
host.prepareUpgrades({ uiAuthController, isRequestOriginAllowed });
|
|
2079
|
+
// Every space's events join the host's hub, and the host asks each space for its live status.
|
|
2080
|
+
void host.startEvents(globalMessageStreamHub).catch((error) => {
|
|
2081
|
+
console.warn(`[spaces] could not follow the spaces: ${error?.message ?? error}`);
|
|
2082
|
+
});
|
|
2083
|
+
};
|
|
2084
|
+
if (spacesHost) startSpacesHost(spacesHost);
|
|
2085
|
+
const spacesSwitch = createSwitchController({
|
|
2086
|
+
getHost: () => spacesHost,
|
|
2087
|
+
setHost: (host) => { spacesHost = host; },
|
|
2088
|
+
buildHost: buildSpacesHost,
|
|
2089
|
+
startHost: startSpacesHost,
|
|
2090
|
+
persist: (enabled) => persistSettings({ isolatedSpacesEnabled: enabled }),
|
|
2091
|
+
});
|
|
2092
|
+
registerSpaceRoutes(app, {
|
|
2093
|
+
getJourney: () => spacesHost?.journey ?? null,
|
|
2094
|
+
getPlaces: () => spacesHost?.places() ?? [],
|
|
2095
|
+
readSwitch: spacesSwitch.readSwitch,
|
|
2096
|
+
setSwitch: spacesSwitch.setSwitch,
|
|
2097
|
+
});
|
|
2034
2098
|
realtimeProxyRuntime = attachRealtimeProxy({
|
|
2035
2099
|
app,
|
|
2036
2100
|
server,
|
|
@@ -24,6 +24,8 @@ export function createGlobalMessageStreamHub({
|
|
|
24
24
|
throw new RangeError('Replay limits must be nonnegative safe integers');
|
|
25
25
|
}
|
|
26
26
|
const eventSubscribers = new Set();
|
|
27
|
+
// The event subscribers that also take the events of isolated spaces.
|
|
28
|
+
const spaceSubscribers = new Set();
|
|
27
29
|
const statusSubscribers = new Set();
|
|
28
30
|
const replay = [];
|
|
29
31
|
let replayBytes = 0;
|
|
@@ -69,6 +71,10 @@ export function createGlobalMessageStreamHub({
|
|
|
69
71
|
const eventId = typeof envelope?.eventId === 'string' && envelope.eventId.length > 0
|
|
70
72
|
? envelope.eventId
|
|
71
73
|
: `${replayIdPrefix}${String(++replaySequence).padStart(12, '0')}`;
|
|
74
|
+
// An event of an isolated space carries the space's id; subscribers see it only when they
|
|
75
|
+
// asked for space events, because a consumer that acts on the host's OpenCode by
|
|
76
|
+
// directory must never act on a space's directory.
|
|
77
|
+
const spaceId = typeof envelope?.spaceId === 'string' && envelope.spaceId.length > 0 ? envelope.spaceId : null;
|
|
72
78
|
let serializedFrame;
|
|
73
79
|
let translated;
|
|
74
80
|
return {
|
|
@@ -76,6 +82,7 @@ export function createGlobalMessageStreamHub({
|
|
|
76
82
|
payload,
|
|
77
83
|
directory,
|
|
78
84
|
eventId,
|
|
85
|
+
spaceId,
|
|
79
86
|
serialize() {
|
|
80
87
|
serializedFrame ??= serializeMessageStreamWsEvent(payload, { directory, eventId });
|
|
81
88
|
return serializedFrame;
|
|
@@ -112,6 +119,7 @@ export function createGlobalMessageStreamHub({
|
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
for (const subscriber of Array.from(eventSubscribers)) {
|
|
122
|
+
if (normalized.spaceId !== null && !spaceSubscribers.has(subscriber)) continue;
|
|
115
123
|
notifySubscriber('event', subscriber, normalized);
|
|
116
124
|
}
|
|
117
125
|
};
|
|
@@ -191,12 +199,26 @@ export function createGlobalMessageStreamHub({
|
|
|
191
199
|
hasConnected() {
|
|
192
200
|
return everConnected;
|
|
193
201
|
},
|
|
194
|
-
|
|
202
|
+
/**
|
|
203
|
+
* `spaces: true` also delivers the events of isolated spaces, which carry `spaceId`.
|
|
204
|
+
* Without it a subscriber sees the host's events only, as every consumer did before spaces.
|
|
205
|
+
*/
|
|
206
|
+
subscribeEvent(subscriber, { spaces = false } = {}) {
|
|
195
207
|
eventSubscribers.add(subscriber);
|
|
208
|
+
if (spaces) spaceSubscribers.add(subscriber);
|
|
196
209
|
return () => {
|
|
197
210
|
eventSubscribers.delete(subscriber);
|
|
211
|
+
spaceSubscribers.delete(subscriber);
|
|
198
212
|
};
|
|
199
213
|
},
|
|
214
|
+
/**
|
|
215
|
+
* One event of an isolated space, from that space's own connection, entered here as if it
|
|
216
|
+
* had arrived upstream: numbered, coalesced, replayed and fanned out with the host's, so
|
|
217
|
+
* a client keeps one cursor for everything. `directory` is the space's, `spaceId` marks it.
|
|
218
|
+
*/
|
|
219
|
+
injectEvent({ payload, directory, spaceId }) {
|
|
220
|
+
coalescer.push({ envelope: { directory, spaceId }, payload });
|
|
221
|
+
},
|
|
200
222
|
subscribeStatus(subscriber) {
|
|
201
223
|
statusSubscribers.add(subscriber);
|
|
202
224
|
return () => {
|
|
@@ -321,3 +321,38 @@ describe('createGlobalMessageStreamHub', () => {
|
|
|
321
321
|
}
|
|
322
322
|
});
|
|
323
323
|
});
|
|
324
|
+
|
|
325
|
+
describe('events of isolated spaces in the global hub', () => {
|
|
326
|
+
const makeHub = () => createGlobalMessageStreamHub({
|
|
327
|
+
buildOpenCodeUrl: path => `http://127.0.0.1:4096${path}`,
|
|
328
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
329
|
+
deltaCoalesceWindowMs: 0,
|
|
330
|
+
fetchImpl: async () => createSseResponse({ blocks: [] }),
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('delivers an injected space event to subscribers that asked for spaces only, numbered and replayable like the host\'s', () => {
|
|
334
|
+
const hub = makeHub();
|
|
335
|
+
const plain = [];
|
|
336
|
+
const withSpaces = [];
|
|
337
|
+
hub.subscribeEvent(event => plain.push(event));
|
|
338
|
+
hub.subscribeEvent(event => withSpaces.push(event), { spaces: true });
|
|
339
|
+
hub.injectEvent({ payload: { type: 'session.execution.started', data: { sessionID: 's1' } }, directory: '/spaces/a1b2c3d4e5f6/repo', spaceId: 'a1b2c3d4e5f6' });
|
|
340
|
+
expect(plain).toHaveLength(0);
|
|
341
|
+
expect(withSpaces).toHaveLength(1);
|
|
342
|
+
expect(withSpaces[0]).toMatchObject({ spaceId: 'a1b2c3d4e5f6', directory: '/spaces/a1b2c3d4e5f6/repo' });
|
|
343
|
+
expect(withSpaces[0].eventId).toMatch(/^oc-/);
|
|
344
|
+
expect(withSpaces[0].translated()).toEqual([expect.objectContaining({ type: 'session.status' })]);
|
|
345
|
+
expect(JSON.parse(withSpaces[0].serialize())).toMatchObject({ type: 'event', directory: '/spaces/a1b2c3d4e5f6/repo', payload: { type: 'session.execution.started' } });
|
|
346
|
+
hub.injectEvent({ payload: { type: 'session.execution.succeeded', data: { sessionID: 's1' } }, directory: '/spaces/a1b2c3d4e5f6/repo', spaceId: 'a1b2c3d4e5f6' });
|
|
347
|
+
expect(hub.replayAfter(withSpaces[0].eventId).map(entry => entry.eventId)).toEqual([withSpaces[1].eventId]);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('marks a host event with no space, so every subscriber sees it', () => {
|
|
351
|
+
const hub = makeHub();
|
|
352
|
+
const seen = [];
|
|
353
|
+
hub.subscribeEvent(event => seen.push(event.spaceId));
|
|
354
|
+
hub.subscribeEvent(event => seen.push(event.spaceId), { spaces: true });
|
|
355
|
+
hub.injectEvent({ payload: { type: 'session.execution.started', data: { sessionID: 's1' } }, directory: '/home/me', spaceId: null });
|
|
356
|
+
expect(seen).toEqual([null, null]);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
@@ -86,6 +86,8 @@ export function createGlobalMessageStreamWsBridge({
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
// Browser clients take the events of isolated spaces too: each frame carries its directory,
|
|
90
|
+
// and a space's directory is one more project directory to the UI.
|
|
89
91
|
const unsubscribeEvent = globalHub.subscribeEvent((event) => {
|
|
90
92
|
const { payload } = event;
|
|
91
93
|
for (const socket of Array.from(clients)) {
|
|
@@ -111,7 +113,7 @@ export function createGlobalMessageStreamWsBridge({
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
});
|
|
114
|
-
});
|
|
116
|
+
}, { spaces: true });
|
|
115
117
|
|
|
116
118
|
const unsubscribeStatus = globalHub.subscribeStatus((status) => {
|
|
117
119
|
if (status.type === 'connect') {
|
|
@@ -144,7 +144,7 @@ export function createUpstreamSseReader({
|
|
|
144
144
|
response,
|
|
145
145
|
});
|
|
146
146
|
await cancelResponseBody(response);
|
|
147
|
-
await waitForReconnectDelay(reconnectDelayMs, signal);
|
|
147
|
+
await waitForReconnectDelay(resolveTimeoutMs(reconnectDelayMs, DEFAULT_UPSTREAM_RECONNECT_DELAY_MS), signal);
|
|
148
148
|
continue;
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -219,7 +219,8 @@ export function createUpstreamSseReader({
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
if (!stopped && !signal?.aborted) {
|
|
222
|
-
|
|
222
|
+
// A function is read before every wait, so a caller can back off between attempts.
|
|
223
|
+
await waitForReconnectDelay(resolveTimeoutMs(reconnectDelayMs, DEFAULT_UPSTREAM_RECONNECT_DELAY_MS), signal);
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
})().finally(() => {
|
|
@@ -458,7 +458,7 @@ ConPTY or Console Window Host behavior.
|
|
|
458
458
|
- `readCustomThemesFromDisk()`
|
|
459
459
|
|
|
460
460
|
## Public exports (project-directory-runtime.js)
|
|
461
|
-
- `createProjectDirectoryRuntime(dependencies)`: creates runtime for request/project directory candidate normalization and validation.
|
|
461
|
+
- `createProjectDirectoryRuntime(dependencies)`: creates runtime for request/project directory candidate normalization and validation. `dependencies.refuseDirectory(candidate)` answers the reason a resolved directory may not be used on this host, or null; `validateDirectoryPath` asks it before it looks at the disk, so a refused directory is never touched and never falls back to another one. The isolated-spaces host refuses `/spaces/...` through it while its switch is on.
|
|
462
462
|
- Returned API:
|
|
463
463
|
- `resolveDirectoryCandidate(value)`
|
|
464
464
|
- `validateDirectoryPath(candidate)`
|
|
@@ -732,6 +732,7 @@ headers }` or v1 `{ npm, options }`. The stored entry is always a
|
|
|
732
732
|
- conditional JSON body parser behavior for `/api/*` vs non-API requests
|
|
733
733
|
- URL-encoded parser setup
|
|
734
734
|
- request logging middleware
|
|
735
|
+
- `dependencies.skipBodyParsing(req)` names a request both parsers leave alone, so its body reaches its route untouched; the isolated-spaces dispatcher uses it for `/api/spaces/<id>/...`, which it streams into a space
|
|
735
736
|
|
|
736
737
|
## Public exports (cli-options.js)
|
|
737
738
|
- `parseServeCliOptions(options)`: parses serve CLI flags and environment-derived defaults:
|
|
@@ -911,7 +912,10 @@ The VS Code extension owns its separate Git and proxy implementation.
|
|
|
911
912
|
|
|
912
913
|
The behavior `GET /api/behavior/agents-md` response includes `path`, the effective
|
|
913
914
|
server-side filename, whether or not the file exists. Settings displays this
|
|
914
|
-
path without deriving a directory from the browser environment.
|
|
915
|
+
path without deriving a directory from the browser environment. A `PUT` may send
|
|
916
|
+
`expectedContent` (the content the editor loaded, `null` for no file); when the
|
|
917
|
+
file on disk no longer matches, the write is refused with `409` and code
|
|
918
|
+
`AGENTS_MD_CONFLICT` instead of overwriting an edit made elsewhere.
|
|
915
919
|
|
|
916
920
|
## Managed OpenCode config layer (managed-config-file.js)
|
|
917
921
|
|
|
@@ -67,6 +67,7 @@ export const createBootstrapRuntime = (dependencies) => {
|
|
|
67
67
|
agentToolRuntime,
|
|
68
68
|
pluginNotificationEmitter,
|
|
69
69
|
desktopUpdater,
|
|
70
|
+
skipBodyParsing,
|
|
70
71
|
} = options;
|
|
71
72
|
|
|
72
73
|
const uiAuthController = createUiAuth({
|
|
@@ -93,7 +94,7 @@ export const createBootstrapRuntime = (dependencies) => {
|
|
|
93
94
|
uiAuthController,
|
|
94
95
|
});
|
|
95
96
|
|
|
96
|
-
registerCommonRequestMiddleware(app, { express, verboseRequestLogs });
|
|
97
|
+
registerCommonRequestMiddleware(app, { express, verboseRequestLogs, skipBodyParsing });
|
|
97
98
|
|
|
98
99
|
registerAgentToolRoutes(app, { express, agentToolRuntime });
|
|
99
100
|
|
|
@@ -261,6 +261,33 @@ describe('entity modules speak OpenCode 2 shapes', () => {
|
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
|
|
264
|
+
it('lists servers from a global opencode.jsonc next to opencode.json and edits them in place', () => {
|
|
265
|
+
const configDir = path.join(process.env.XDG_CONFIG_HOME, 'opencode');
|
|
266
|
+
const jsonPath = path.join(configDir, 'opencode.json');
|
|
267
|
+
const jsoncPath = path.join(configDir, 'opencode.jsonc');
|
|
268
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
269
|
+
fs.writeFileSync(jsonPath, JSON.stringify({ autoupdate: true }, null, 2), 'utf8');
|
|
270
|
+
fs.writeFileSync(jsoncPath, [
|
|
271
|
+
'{',
|
|
272
|
+
' // servers live only in the jsonc file',
|
|
273
|
+
' "mcp": { "servers": { "docs": { "type": "remote", "url": "https://docs.example.com/mcp" } } }',
|
|
274
|
+
'}',
|
|
275
|
+
].join('\n'), 'utf8');
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
expect(listMcpConfigs(projectDir).map((entry) => entry.name)).toContain('docs');
|
|
279
|
+
expect(getMcpConfig('docs', projectDir)).toEqual(expect.objectContaining({ scope: 'user' }));
|
|
280
|
+
|
|
281
|
+
updateMcpConfig('docs', { disabled: true }, projectDir);
|
|
282
|
+
|
|
283
|
+
expect(getMcpConfig('docs', projectDir)).toEqual(expect.objectContaining({ disabled: true }));
|
|
284
|
+
expect(readJson(jsonPath)).toEqual({ autoupdate: true });
|
|
285
|
+
} finally {
|
|
286
|
+
fs.rmSync(jsonPath, { force: true });
|
|
287
|
+
fs.rmSync(jsoncPath, { force: true });
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
264
291
|
it('reads a v1 mcp entry and rewrites it under mcp.servers in the same file', () => {
|
|
265
292
|
const configPath = write('opencode.json', JSON.stringify({
|
|
266
293
|
mcp: {
|
|
@@ -111,6 +111,18 @@ describe('OpenCode global config paths', () => {
|
|
|
111
111
|
expect(response.json).toHaveBeenLastCalledWith({
|
|
112
112
|
content: 'Global behavior', exists: true, path: path.join(process.env.XDG_CONFIG_HOME, 'opencode', 'AGENTS.md'),
|
|
113
113
|
});
|
|
114
|
+
|
|
115
|
+
// A write based on an outdated copy is refused and leaves the file alone.
|
|
116
|
+
await handlers.get('PUT /api/behavior/agents-md')({
|
|
117
|
+
body: { content: 'Stale draft', expectedContent: 'Older behavior' },
|
|
118
|
+
}, response);
|
|
119
|
+
expect(response.status).toHaveBeenLastCalledWith(409);
|
|
120
|
+
expect(fs.readFileSync(path.join(process.env.XDG_CONFIG_HOME, 'opencode', 'AGENTS.md'), 'utf8')).toBe('Global behavior');
|
|
121
|
+
|
|
122
|
+
await handlers.get('PUT /api/behavior/agents-md')({
|
|
123
|
+
body: { content: 'Current draft', expectedContent: 'Global behavior' },
|
|
124
|
+
}, response);
|
|
125
|
+
expect(fs.readFileSync(path.join(process.env.XDG_CONFIG_HOME, 'opencode', 'AGENTS.md'), 'utf8')).toBe('Current draft');
|
|
114
126
|
fs.rmSync(root, { recursive: true, force: true });
|
|
115
127
|
});
|
|
116
128
|
});
|
|
@@ -1075,10 +1075,15 @@ export const registerSettingsUtilityRoutes = (app, dependencies) => {
|
|
|
1075
1075
|
};
|
|
1076
1076
|
|
|
1077
1077
|
export const registerCommonRequestMiddleware = (app, dependencies) => {
|
|
1078
|
-
|
|
1078
|
+
// `skipBodyParsing(req)` names a request whose body must reach its route untouched: a
|
|
1079
|
+
// request the isolated-spaces dispatcher streams into a space, where a parsed body would
|
|
1080
|
+
// otherwise be consumed here and lost.
|
|
1081
|
+
const { express, verboseRequestLogs = false, skipBodyParsing = () => false } = dependencies;
|
|
1079
1082
|
|
|
1080
1083
|
app.use((req, res, next) => {
|
|
1081
|
-
if (req
|
|
1084
|
+
if (skipBodyParsing(req)) {
|
|
1085
|
+
next();
|
|
1086
|
+
} else if (req.path === '/api/config/themes' || req.path.startsWith('/api/config/themes/')) {
|
|
1082
1087
|
express.json({ limit: '1mb' })(req, res, next);
|
|
1083
1088
|
} else if (req.path.startsWith('/api/behavior')) {
|
|
1084
1089
|
const contentLength = parseInt(req.headers['content-length'] || '0', 10);
|
|
@@ -1115,7 +1120,8 @@ export const registerCommonRequestMiddleware = (app, dependencies) => {
|
|
|
1115
1120
|
req.path.startsWith('/api/text') ||
|
|
1116
1121
|
req.path.startsWith('/api/voice') ||
|
|
1117
1122
|
req.path.startsWith('/api/tts') ||
|
|
1118
|
-
req.path.startsWith('/api/openchamber/tunnel')
|
|
1123
|
+
req.path.startsWith('/api/openchamber/tunnel') ||
|
|
1124
|
+
req.path.startsWith('/api/openchamber/spaces')
|
|
1119
1125
|
) {
|
|
1120
1126
|
express.json({ limit: '50mb' })(req, res, next);
|
|
1121
1127
|
} else if (req.path.startsWith('/api')) {
|
|
@@ -1125,7 +1131,14 @@ export const registerCommonRequestMiddleware = (app, dependencies) => {
|
|
|
1125
1131
|
}
|
|
1126
1132
|
});
|
|
1127
1133
|
|
|
1128
|
-
|
|
1134
|
+
const urlencoded = express.urlencoded({ extended: true, limit: '50mb' });
|
|
1135
|
+
app.use((req, res, next) => {
|
|
1136
|
+
if (skipBodyParsing(req)) {
|
|
1137
|
+
next();
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
urlencoded(req, res, next);
|
|
1141
|
+
});
|
|
1129
1142
|
|
|
1130
1143
|
app.use((req, _res, next) => {
|
|
1131
1144
|
if (verboseRequestLogs) {
|
|
@@ -127,6 +127,32 @@ describe('core-routes', () => {
|
|
|
127
127
|
expect(response.body).toEqual({ body: { content: 'Snippet body' } });
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
+
it('leaves the body of a request alone when told to, for both parsers', async () => {
|
|
131
|
+
const app = express();
|
|
132
|
+
registerCommonRequestMiddleware(app, { express, skipBodyParsing: (req) => req.path.startsWith('/api/spaces/') });
|
|
133
|
+
const raw = (req, res) => {
|
|
134
|
+
// A body a parser read is complete already, and its stream ends no second time.
|
|
135
|
+
if (req.complete) {
|
|
136
|
+
res.json({ body: req.body ?? null, raw: '' });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const chunks = [];
|
|
140
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
141
|
+
req.on('end', () => res.json({ body: req.body ?? null, raw: Buffer.concat(chunks).toString('utf8') }));
|
|
142
|
+
};
|
|
143
|
+
app.post('/api/spaces/abc/form', raw);
|
|
144
|
+
app.post('/api/spaces/abc/config/snippets/x', raw);
|
|
145
|
+
app.post('/api/other/form', raw);
|
|
146
|
+
|
|
147
|
+
const kept = await request(app).post('/api/spaces/abc/form').type('form').send('a=1&b=2').expect(200);
|
|
148
|
+
expect(kept.body).toEqual({ body: null, raw: 'a=1&b=2' });
|
|
149
|
+
const keptJson = await request(app).post('/api/spaces/abc/config/snippets/x').send({ content: 'x' }).expect(200);
|
|
150
|
+
expect(keptJson.body).toEqual({ body: null, raw: '{"content":"x"}' });
|
|
151
|
+
// Elsewhere the parsers still run, and a parsed body leaves nothing to read.
|
|
152
|
+
const parsed = await request(app).post('/api/other/form').type('form').send('a=1&b=2').expect(200);
|
|
153
|
+
expect(parsed.body).toEqual({ body: { a: '1', b: '2' }, raw: '' });
|
|
154
|
+
});
|
|
155
|
+
|
|
130
156
|
it('should parse JSON bodies for the web search config route', async () => {
|
|
131
157
|
const app = express();
|
|
132
158
|
registerCommonRequestMiddleware(app, { express });
|
|
@@ -48,9 +48,14 @@ function ensureProjectMcpConfigPath(workingDirectory) {
|
|
|
48
48
|
return path.join(configDir, 'opencode.json');
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/** Same precedence as `getJsonEntrySource`: custom > project > user. */
|
|
51
|
+
/** Same precedence as `getJsonEntrySource`: custom > project > user override > user. */
|
|
52
52
|
function readMcpEntriesAcrossLayers(layers) {
|
|
53
|
-
return readLayeredMcpEntries([
|
|
53
|
+
return readLayeredMcpEntries([
|
|
54
|
+
layers?.userConfig,
|
|
55
|
+
layers?.userOverrideConfig,
|
|
56
|
+
layers?.projectConfig,
|
|
57
|
+
layers?.customConfig,
|
|
58
|
+
]);
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
function listMcpConfigs(workingDirectory) {
|
|
@@ -16,6 +16,10 @@ export const createProjectDirectoryRuntime = (dependencies) => {
|
|
|
16
16
|
readSettingsFromDiskMigrated,
|
|
17
17
|
getReadSettingsFromDiskMigrated,
|
|
18
18
|
sanitizeProjects,
|
|
19
|
+
// `refuseDirectory(candidate)` answers the reason a directory may not be used on this host,
|
|
20
|
+
// or null. It runs before the path is looked at, so a refused directory is never touched and
|
|
21
|
+
// never falls back to another one. The isolated-spaces host refuses `/spaces/...` with it.
|
|
22
|
+
refuseDirectory = () => null,
|
|
19
23
|
} = dependencies;
|
|
20
24
|
const realpathCache = createRealpathCache({
|
|
21
25
|
realpath: fsPromises.realpath.bind(fsPromises),
|
|
@@ -38,6 +42,10 @@ export const createProjectDirectoryRuntime = (dependencies) => {
|
|
|
38
42
|
if (!resolved) {
|
|
39
43
|
return { ok: false, error: 'Directory parameter is required' };
|
|
40
44
|
}
|
|
45
|
+
const refusal = refuseDirectory(resolved);
|
|
46
|
+
if (typeof refusal === 'string' && refusal.length > 0) {
|
|
47
|
+
return { ok: false, error: refusal };
|
|
48
|
+
}
|
|
41
49
|
try {
|
|
42
50
|
const stats = await fsPromises.stat(resolved);
|
|
43
51
|
if (!stats.isDirectory()) {
|
|
@@ -42,6 +42,19 @@ describe('project directory runtime', () => {
|
|
|
42
42
|
expect(result).toEqual({ ok: true, directory: '/real/path/to/project', requestedDirectory: '/symlink/path/to/project' });
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
it('refuses a directory the host says no to, before it looks at the disk', async () => {
|
|
46
|
+
let statCalls = 0;
|
|
47
|
+
const runtime = createTestRuntime({
|
|
48
|
+
fsPromises: { stat: async () => { statCalls += 1; return { isDirectory: () => true }; }, realpath: async (p) => p },
|
|
49
|
+
refuseDirectory: (candidate) => (candidate.startsWith('/spaces/') ? 'A directory under /spaces/ belongs to an isolated space' : null),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(await runtime.validateDirectoryPath('/spaces/a1b2c3d4e5f6/repo')).toEqual({ ok: false, error: 'A directory under /spaces/ belongs to an isolated space' });
|
|
53
|
+
expect(statCalls).toBe(0);
|
|
54
|
+
expect(await runtime.validateDirectoryPath('/home/user/project')).toMatchObject({ ok: true });
|
|
55
|
+
expect(statCalls).toBe(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
45
58
|
it('returns error when candidate is empty', async () => {
|
|
46
59
|
const runtime = createTestRuntime();
|
|
47
60
|
const result = await runtime.validateDirectoryPath('');
|