@openchamber/web 1.24.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/commands-connect-url.js +3 -8
- package/bin/lib/commands-tunnel.js +3 -0
- package/dist/assets/{CodeMirrorCommentWidgets-B_vBPQYm.js → CodeMirrorCommentWidgets-zm3C1FvM.js} +1 -1
- package/dist/assets/DiffView-DNExNi1z.js +4 -0
- package/dist/assets/FilesView-DUCLmHBi.js +17 -0
- package/dist/assets/{GitView-k0hUF8KB.js → GitView-Bz9z6gZA.js} +4 -4
- package/dist/assets/{GuestAttachDialog-DIf2U85Z.js → GuestAttachDialog-UGp4KDlK.js} +1 -1
- package/dist/assets/GuestSurfacePane-B3pdB_2u.js +1 -0
- package/dist/assets/{JsonTreeView-4AnJ04Pw.js → JsonTreeView-7lVecnZl.js} +1 -1
- package/dist/assets/LinearIssuesView-CTGRS9Vq.js +1 -0
- package/dist/assets/MarkdownImageGallery-DQk5adUs.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +12 -0
- package/dist/assets/OnboardingScreen-CBx6cXPP.js +1 -0
- package/dist/assets/{PatchDiff-DpGmHRnV.js → PatchDiff-D7VVpR_l.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CgLl_tp7.js → PierreDiffViewer-Gbfks1pk.js} +3 -3
- package/dist/assets/PlanView-CPSK0x97.js +5 -0
- package/dist/assets/PluginPane-BIGsUx69.js +3 -0
- package/dist/assets/SettingsView-Dql7z6Ww.js +30 -0
- package/dist/assets/SettingsWindow-D6oi-UmV.js +1 -0
- package/dist/assets/SubmoduleDiffSummary-BXA0FAWj.js +1 -0
- package/dist/assets/ToolOutputDialog-BQJsSbDm.js +15 -0
- package/dist/assets/ToolPartDiffPreview-FY9w0TVT.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BK4aU5qJ.js → VirtualizedFileDiff-B9YhAya5.js} +4 -4
- package/dist/assets/{WalkthroughView-Bk6TPNFw.js → WalkthroughView-CmFgOUFN.js} +2 -2
- package/dist/assets/appThemeRegistry-BebxalUt.js +1 -0
- package/dist/assets/changesTree-CePHbFcj.js +1 -0
- package/dist/assets/commitAndPush-Wfxng_IK.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-BVTujWSX.js → computeVirtualFileMetrics-BCOqgixN.js} +2 -2
- package/dist/assets/de-CMA45TC-.js +10 -0
- package/dist/assets/es-DPL4fBtl.js +16 -0
- package/dist/assets/fr-OHBKBseP.js +14 -0
- package/dist/assets/index-3TiDNtfN.js +1 -0
- package/dist/assets/index-BLUZa5u0.js +41 -0
- package/dist/assets/index-Cm2rrq69.css +1 -0
- package/dist/assets/{isDiffPlainText-D3yX_vx4.js → isDiffPlainText-DnDYQmWK.js} +1 -1
- package/dist/assets/{isFilePlainText-CZR9TcHV.js → isFilePlainText-BA_AHX7d.js} +1 -1
- package/dist/assets/ja-DvX4WSRf.js +16 -0
- package/dist/assets/ko-BUcLd8YZ.js +16 -0
- package/dist/assets/main-B_jri4i-.js +896 -0
- package/dist/assets/main-DtUmJp9B.js +2 -0
- package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
- package/dist/assets/markdownCore-BSnlUXBf.js +7 -0
- package/dist/assets/miniChat-BYfLUnDK.js +2 -0
- package/dist/assets/mobile-DH3hI6gd.js +2 -0
- package/dist/assets/patchFileDiff--L7lt_GZ.js +13 -0
- package/dist/assets/pl-BkI_xHqz.js +16 -0
- package/dist/assets/pt-BR-7wFtQlV9.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-C7kpNW_-.js +2 -0
- package/dist/assets/renderMobileApp-i0nq7Dwy.js +25 -0
- package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +27 -0
- package/dist/assets/scheduledTasksApi-Cy7uZCaI.js +1 -0
- package/dist/assets/{shikiHighlight-BfjuB3CD.js → shikiHighlight-D4vxipfr.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-BP60t9SX.js → textMateThemeFromAppTheme-BYAHtJwQ.js} +1 -1
- package/dist/assets/tr-TsD-AqEH.js +7 -0
- package/dist/assets/uk-B-qspCmD.js +16 -0
- package/dist/assets/useAppFontEffects-DHZ9-L30.js +7338 -0
- package/dist/assets/useInlineCommentController-CvpOMK-R.js +2 -0
- package/dist/assets/useRootScrollLock-DzNFi-fn.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BFm1Ju2w.js → vendor-codemirror-language-data-j3fhlwUM.js} +2 -2
- package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
- package/dist/assets/vendor-opencode-client-DYdsLbCM.js +12 -0
- package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
- package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
- package/dist/assets/{web-components-2vo9YsZc.js → web-components-BvHNFSEG.js} +2 -2
- package/dist/assets/zh-CN-DYuPJV5i.js +16 -0
- package/dist/assets/zh-TW-BX_2D_lV.js +16 -0
- package/dist/index.html +13 -7
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +6 -5
- package/server/index.d.ts +1 -0
- package/server/index.js +264 -91
- package/server/lib/agent-tool/DOCUMENTATION.md +38 -16
- package/server/lib/agent-tool/runtime.js +167 -58
- package/server/lib/agent-tool/runtime.test.js +170 -87
- package/server/lib/browser-control/DOCUMENTATION.md +51 -4
- package/server/lib/browser-control/provider.js +217 -0
- package/server/lib/browser-control/provider.test.js +251 -0
- package/server/lib/context-obligatory/runtime.js +61 -50
- package/server/lib/context-obligatory/runtime.test.js +62 -162
- package/server/lib/event-stream/DOCUMENTATION.md +12 -1
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +68 -57
- package/server/lib/event-stream/directory-ws-bridge.js +1 -1
- package/server/lib/event-stream/global-hub.js +10 -1
- package/server/lib/event-stream/global-hub.test.js +27 -26
- package/server/lib/event-stream/index.js +6 -0
- package/server/lib/event-stream/protocol.js +26 -19
- package/server/lib/event-stream/protocol.test.js +18 -7
- package/server/lib/event-stream/rebind.test.js +5 -5
- package/server/lib/event-stream/runtime.test.js +17 -15
- package/server/lib/event-stream/translate-v2.js +313 -0
- package/server/lib/event-stream/translate-v2.test.js +209 -0
- package/server/lib/event-stream/upstream-reader.test.js +16 -16
- package/server/lib/fs/DOCUMENTATION.md +4 -2
- package/server/lib/fs/byte-range.js +35 -0
- package/server/lib/fs/byte-range.test.js +31 -0
- package/server/lib/fs/routes.js +47 -42
- package/server/lib/fs/routes.test.js +123 -18
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +34 -0
- package/server/lib/git/service.test.js +8 -0
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/github/pr-status.js +22 -2
- package/server/lib/github/pr-status.test.js +27 -14
- package/server/lib/guests/DOCUMENTATION.md +16 -2
- package/server/lib/guests/catalog.js +31 -1
- package/server/lib/guests/catalog.test.js +55 -0
- package/server/lib/guests/html-styles.js +5 -3
- package/server/lib/guests/html-styles.test.js +3 -1
- package/server/lib/guests/routes.js +21 -4
- package/server/lib/guests/service.js +197 -14
- package/server/lib/guests/service.test.js +201 -1
- package/server/lib/guests/surface.js +676 -0
- package/server/lib/guests/surface.test.js +536 -0
- package/server/lib/markdown-image-grants/routes.js +18 -5
- package/server/lib/markdown-image-grants/routes.test.js +9 -6
- package/server/lib/message-queue/DOCUMENTATION.md +33 -22
- package/server/lib/message-queue/runtime.js +155 -100
- package/server/lib/message-queue/runtime.test.js +168 -82
- package/server/lib/notifications/DOCUMENTATION.md +38 -0
- package/server/lib/notifications/control-stream.http.test.js +68 -0
- package/server/lib/notifications/emit-route.js +118 -0
- package/server/lib/notifications/emit-route.test.js +112 -0
- package/server/lib/notifications/emitter-runtime.js +15 -0
- package/server/lib/notifications/emitter-runtime.test.js +32 -0
- package/server/lib/notifications/push-runtime.js +5 -1
- package/server/lib/notifications/push-runtime.test.js +2 -2
- package/server/lib/notifications/routes.js +1 -1
- package/server/lib/notifications/runtime.js +115 -26
- package/server/lib/notifications/template-runtime.js +13 -15
- package/server/lib/notifications/template-runtime.test.js +16 -9
- package/server/lib/notifications/trigger-runtime.test.js +187 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
- package/server/lib/openchamber-control/actions.js +19 -4
- package/server/lib/openchamber-control/error.js +1 -1
- package/server/lib/openchamber-control/file-open.js +59 -0
- package/server/lib/openchamber-control/file-open.test.js +57 -0
- package/server/lib/openchamber-control/routes.test.js +12 -0
- package/server/lib/openchamber-control/service.js +125 -49
- package/server/lib/openchamber-control/service.test.js +115 -44
- package/server/lib/openchamber-sessions/archive-store.js +224 -0
- package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
- package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
- package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
- package/server/lib/openchamber-sessions/opencode-client.js +22 -0
- package/server/lib/openchamber-sessions/routes.js +409 -328
- package/server/lib/openchamber-sessions/routes.test.js +795 -740
- package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
- package/server/lib/opencode/DOCUMENTATION.md +458 -29
- package/server/lib/opencode/agents.js +233 -327
- package/server/lib/opencode/auth.js +41 -44
- package/server/lib/opencode/auth.test.js +92 -0
- package/server/lib/opencode/bootstrap-runtime.js +12 -0
- package/server/lib/opencode/cli-upgrade.d.ts +4 -0
- package/server/lib/opencode/cli-upgrade.js +18 -0
- package/server/lib/opencode/cli-upgrade.test.js +36 -0
- package/server/lib/opencode/commands.js +164 -145
- package/server/lib/opencode/compatibility.d.ts +16 -0
- package/server/lib/opencode/compatibility.js +91 -0
- package/server/lib/opencode/compatibility.test.js +70 -0
- package/server/lib/opencode/config-entity-routes.js +58 -29
- package/server/lib/opencode/config-entity-v2.test.js +290 -0
- package/server/lib/opencode/config-mutation-response.js +17 -7
- package/server/lib/opencode/config-mutation-response.test.js +4 -7
- package/server/lib/opencode/config-paths.test.js +2 -2
- package/server/lib/opencode/config-v2.d.ts +185 -0
- package/server/lib/opencode/config-v2.js +843 -0
- package/server/lib/opencode/config-v2.test.js +483 -0
- package/server/lib/opencode/core-routes.js +3 -0
- package/server/lib/opencode/core-routes.test.js +15 -0
- package/server/lib/opencode/credential-db.js +144 -0
- package/server/lib/opencode/credential-db.test.js +104 -0
- package/server/lib/opencode/env-runtime.js +47 -15
- package/server/lib/opencode/env-runtime.test.js +45 -0
- package/server/lib/opencode/feature-routes-runtime.js +16 -5
- package/server/lib/opencode/lifecycle-process.test.js +7 -4
- package/server/lib/opencode/lifecycle.js +113 -30
- package/server/lib/opencode/lifecycle.test.js +107 -8
- package/server/lib/opencode/login-shell-env.js +27 -0
- package/server/lib/opencode/managed-config-file.js +131 -0
- package/server/lib/opencode/managed-config-file.test.js +168 -0
- package/server/lib/opencode/managed-plugin-config.js +33 -13
- package/server/lib/opencode/mcp.js +43 -149
- package/server/lib/opencode/network-runtime.js +6 -7
- package/server/lib/opencode/openchamber-routes.js +29 -11
- package/server/lib/opencode/openchamber-routes.test.js +18 -1
- package/server/lib/opencode/plugin-routes.js +3 -3
- package/server/lib/opencode/plugin-routes.test.js +6 -24
- package/server/lib/opencode/plugins.js +91 -40
- package/server/lib/opencode/plugins.test.js +28 -15
- package/server/lib/opencode/provider-source-route.test.js +59 -0
- package/server/lib/opencode/providers.js +66 -83
- package/server/lib/opencode/providers.test.js +190 -59
- package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
- package/server/lib/opencode/proxy.js +179 -129
- package/server/lib/opencode/pwa-manifest-routes.js +4 -2
- package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
- package/server/lib/opencode/response-envelope.js +14 -0
- package/server/lib/opencode/response-envelope.test.js +23 -0
- package/server/lib/opencode/routes-upgrade.test.js +73 -116
- package/server/lib/opencode/routes.js +138 -428
- package/server/lib/opencode/server-utils-runtime.js +10 -4
- package/server/lib/opencode/session-activity.js +78 -0
- package/server/lib/opencode/session-runtime.js +21 -10
- package/server/lib/opencode/session-runtime.test.js +9 -9
- package/server/lib/opencode/settings-helpers.js +15 -8
- package/server/lib/opencode/settings-helpers.test.js +7 -12
- package/server/lib/opencode/settings-registry.json +20 -8
- package/server/lib/opencode/settings-runtime.js +19 -1
- package/server/lib/opencode/settings-runtime.test.js +31 -2
- package/server/lib/opencode/shared.js +86 -24
- package/server/lib/opencode/shared.test.js +87 -5
- package/server/lib/opencode/shutdown-runtime.js +54 -7
- package/server/lib/opencode/shutdown-runtime.test.js +224 -30
- package/server/lib/opencode/skill-routes.js +51 -36
- package/server/lib/opencode/skill-routes.test.js +121 -1
- package/server/lib/opencode/skills.js +7 -5
- package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
- package/server/lib/opencode/upgrade-capability.js +0 -14
- package/server/lib/opencode/upgrade-capability.test.js +1 -1
- package/server/lib/opencode/v1-migration-topup.js +294 -0
- package/server/lib/opencode/v1-migration-topup.test.js +274 -0
- package/server/lib/opencode/v2-install.d.ts +9 -0
- package/server/lib/opencode/v2-install.js +159 -0
- package/server/lib/opencode/v2-install.test.js +133 -0
- package/server/lib/opencode/watcher.js +10 -3
- package/server/lib/opencode/watcher.test.js +17 -21
- package/server/lib/opencode/websearch-config.js +78 -0
- package/server/lib/permission-auto-accept/runtime.js +38 -22
- package/server/lib/permission-auto-accept/runtime.test.js +39 -17
- package/server/lib/quota/DOCUMENTATION.md +4 -0
- package/server/lib/quota/providers/kimi.js +1 -1
- package/server/lib/quota/providers/xai.js +4 -4
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +7 -0
- package/server/lib/routing/DOCUMENTATION.md +52 -21
- package/server/lib/routing/defaults.js +23 -6
- package/server/lib/routing/jev.js +17 -7
- package/server/lib/routing/routes.http.test.js +68 -33
- package/server/lib/routing/routes.js +65 -22
- package/server/lib/routing/runtime.js +145 -48
- package/server/lib/routing/runtime.test.js +79 -55
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
- package/server/lib/scheduled-tasks/runtime.js +81 -74
- package/server/lib/scheduled-tasks/runtime.test.js +53 -1
- package/server/lib/session-assist/DOCUMENTATION.md +25 -8
- package/server/lib/session-assist/context.js +122 -46
- package/server/lib/session-assist/context.test.js +117 -49
- package/server/lib/session-assist/runtime.js +71 -24
- package/server/lib/session-assist/runtime.test.js +153 -173
- package/server/lib/session-goal/DOCUMENTATION.md +34 -15
- package/server/lib/session-goal/create.js +9 -12
- package/server/lib/session-goal/create.test.js +27 -28
- package/server/lib/session-goal/runtime.js +164 -77
- package/server/lib/session-goal/runtime.test.js +271 -519
- package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
- package/server/lib/session-knowledge/runtime.js +59 -41
- package/server/lib/session-knowledge/runtime.test.js +90 -20
- package/server/lib/small-model/DOCUMENTATION.md +154 -208
- package/server/lib/small-model/client.js +113 -0
- package/server/lib/small-model/index.js +296 -158
- package/server/lib/small-model/index.test.js +423 -256
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/spaces/DOCUMENTATION.md +807 -0
- package/server/lib/spaces/code-in-bait.js +185 -0
- package/server/lib/spaces/code-in.js +641 -0
- package/server/lib/spaces/code-in.test.js +1048 -0
- package/server/lib/spaces/errors.js +8 -0
- package/server/lib/spaces/exec-http.js +94 -0
- package/server/lib/spaces/gatekeeper-channel.js +202 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
- package/server/lib/spaces/gatekeeper-program.cjs +914 -0
- package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
- package/server/lib/spaces/hardening.js +457 -0
- package/server/lib/spaces/hardening.test.js +368 -0
- package/server/lib/spaces/host-git.js +127 -0
- package/server/lib/spaces/host-git.test.js +137 -0
- package/server/lib/spaces/labels.js +234 -0
- package/server/lib/spaces/labels.test.js +219 -0
- package/server/lib/spaces/layout.js +184 -0
- package/server/lib/spaces/layout.test.js +30 -0
- package/server/lib/spaces/manager.js +82 -0
- package/server/lib/spaces/manager.test.js +114 -0
- package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
- package/server/lib/spaces/places/contract-suite.js +156 -0
- package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
- package/server/lib/spaces/places/contract.test.js +6 -0
- package/server/lib/spaces/places/docker-engine.js +126 -0
- package/server/lib/spaces/places/docker-live-support.js +202 -0
- package/server/lib/spaces/places/docker-tools.js +186 -0
- package/server/lib/spaces/places/docker.js +587 -0
- package/server/lib/spaces/places/docker.test.js +1610 -0
- package/server/lib/spaces/places/escape-suite.js +1018 -0
- package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
- package/server/lib/spaces/places/fake-docker.js +375 -0
- package/server/lib/spaces/places/memory-place.js +103 -0
- package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
- package/server/lib/spaces/places/registry.js +43 -0
- package/server/lib/spaces/places/registry.test.js +50 -0
- package/server/lib/spaces/places/server.docker.live.test.js +225 -0
- package/server/lib/spaces/run-command.js +261 -0
- package/server/lib/spaces/run-command.test.js +396 -0
- package/server/lib/spaces/space-server.js +190 -0
- package/server/lib/spaces/space-server.test.js +335 -0
- package/server/lib/spaces/tools-filler.js +82 -0
- package/server/lib/spaces/tools-filler.test.js +148 -0
- package/server/lib/spaces/tools-pack.js +49 -0
- package/server/lib/spaces/tools-pack.test.js +57 -0
- package/server/lib/spaces/tools.js +137 -0
- package/server/lib/spaces/tools.test.js +153 -0
- package/server/lib/tts/openai-sdk.js +11 -0
- package/server/lib/tts/service.js +7 -5
- package/server/lib/tts/stt.js +3 -2
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +7 -0
- package/server/lib/tunnels/routes.test.js +55 -0
- package/server/lib/ui-auth/ui-auth.js +38 -2
- package/server/lib/ui-auth/ui-auth.test.js +42 -0
- package/server/lib/ui-auth/ui-passkeys.js +12 -10
- package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
- package/server/lib/walkthrough/pull-request.js +61 -8
- package/server/lib/walkthrough/pull-request.test.js +54 -1
- package/server/lib/walkthrough/routes.js +20 -0
- package/server/lib/walkthrough/routes.test.js +19 -0
- package/server/opencode-proxy.test.js +190 -166
- package/server/opencode-worktree-readiness.test.js +5 -4
- package/dist/assets/DiffView-Ce0oBXXQ.js +0 -4
- package/dist/assets/FilesView-DtXueAWP.js +0 -13
- package/dist/assets/LinearIssuesView-z_9p2GuO.js +0 -1
- package/dist/assets/MarkdownImageGallery-BC-BNN-s.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DyaBTUbH.js +0 -12
- package/dist/assets/OnboardingScreen-DKU_yTb6.js +0 -1
- package/dist/assets/PlanView-CrfB4qqY.js +0 -5
- package/dist/assets/PluginPane-B5cn-jPy.js +0 -3
- package/dist/assets/SettingsView-DMKKwezx.js +0 -29
- package/dist/assets/SettingsWindow-DwbnVzOC.js +0 -1
- package/dist/assets/SubmoduleDiffSummary-hkGcvs0E.js +0 -1
- package/dist/assets/ToolOutputDialog-DuoIOc0j.js +0 -15
- package/dist/assets/ToolPartDiffPreview-t1Bvq_2Y.js +0 -8
- package/dist/assets/appThemeRegistry-DnOVbJjF.js +0 -1
- package/dist/assets/commitAndPush-DLWNZkkY.js +0 -1
- package/dist/assets/de-zEHaAIi3.js +0 -10
- package/dist/assets/es-CBDgEzgk.js +0 -16
- package/dist/assets/fr-DjiTptT_.js +0 -14
- package/dist/assets/index-AgOdanig.css +0 -1
- package/dist/assets/index-B-2_X4DD.js +0 -40
- package/dist/assets/index-CkA4p2IK.js +0 -1
- package/dist/assets/ja-CerMgj3r.js +0 -16
- package/dist/assets/ko-DHYDAze5.js +0 -16
- package/dist/assets/main-BDka4W43.js +0 -896
- package/dist/assets/main-Dl7Dyge_.js +0 -2
- package/dist/assets/markdownCore-DFmr0rUR.js +0 -5
- package/dist/assets/miniChat-CLKQPPpO.js +0 -2
- package/dist/assets/mobile--giD2Q1L.js +0 -2
- package/dist/assets/patchFileDiff-DRh-AQvd.js +0 -13
- package/dist/assets/pl-BTB_93bq.js +0 -16
- package/dist/assets/pt-BR-BwA3oyCK.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +0 -2
- package/dist/assets/renderMobileApp-pMfOuQfl.js +0 -25
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +0 -25
- package/dist/assets/scheduledTasksApi-CeRAIUmW.js +0 -1
- package/dist/assets/tr-CcPsJoNM.js +0 -7
- package/dist/assets/uk-B68WibXi.js +0 -16
- package/dist/assets/useAppFontEffects-DcdrFv2Z.js +0 -7333
- package/dist/assets/useInlineCommentController-Cq4SUjsA.js +0 -2
- package/dist/assets/useRootScrollLock-CSdR6Wnm.js +0 -2
- package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
- package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
- package/dist/assets/vendor-zod-CgAdXWZO.js +0 -39
- package/dist/assets/zh-CN-DbFHYXwP.js +0 -16
- package/dist/assets/zh-TW-DmXAwdty.js +0 -16
- package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
- package/server/lib/routing/feature-flag.js +0 -11
- package/server/lib/small-model/call.js +0 -851
- package/server/lib/small-model/call.test.js +0 -1292
- package/server/lib/small-model/catalog.js +0 -13
- package/server/lib/small-model/resolve.js +0 -131
- package/server/lib/small-model/resolve.test.js +0 -197
- package/server/lib/small-model/runtime-providers.js +0 -164
- package/server/lib/small-model/runtime-providers.test.js +0 -118
- package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
- package/server/lib/system-prompt/runtime.js +0 -49
- package/server/lib/system-prompt/runtime.test.js +0 -76
- package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
createWorktree as createWorktreeDefault,
|
|
4
|
+
getWorktreeBootstrapStatus as getWorktreeBootstrapStatusDefault,
|
|
5
|
+
resolvePrimaryWorktreeRoot,
|
|
6
|
+
} from '../git/index.js';
|
|
4
7
|
import { expandSnippets } from '../opencode/snippets.js';
|
|
5
|
-
import {
|
|
8
|
+
import { AUTO_MODEL_REF, isAutoModel } from '../routing/defaults.js';
|
|
9
|
+
import { parseScheduledCommandPrompt } from '../scheduled-tasks/runtime.js';
|
|
6
10
|
import { buildGoalIntroText, createSessionGoal } from '../session-goal/create.js';
|
|
7
11
|
import { OpenChamberControlError, asControlError } from '../openchamber-control/error.js';
|
|
12
|
+
import { readObjective, writeObjective } from '../session-goal/objectives.js';
|
|
13
|
+
import { createArchiveStore } from './archive-store.js';
|
|
14
|
+
import { applyForkInheritance } from './fork-inheritance.js';
|
|
15
|
+
import { createOpenCodeClient as defaultCreateOpenCodeClient } from './opencode-client.js';
|
|
16
|
+
import { createSessionMetadataStore, createOpenCodeSessionMetadata } from './session-metadata-store.js';
|
|
8
17
|
|
|
9
18
|
const asNonEmptyString = (value) => {
|
|
10
19
|
if (typeof value !== 'string') return null;
|
|
@@ -12,6 +21,8 @@ const asNonEmptyString = (value) => {
|
|
|
12
21
|
return trimmed.length > 0 ? trimmed : null;
|
|
13
22
|
};
|
|
14
23
|
|
|
24
|
+
const asList = (value) => (Array.isArray(value) ? value : []);
|
|
25
|
+
|
|
15
26
|
const splitModel = (value) => {
|
|
16
27
|
const model = asNonEmptyString(value);
|
|
17
28
|
if (!model) return null;
|
|
@@ -59,29 +70,33 @@ const resolveGoalInput = (payload, prompt) => {
|
|
|
59
70
|
|
|
60
71
|
const isPrimaryAgentMode = (mode) => !mode || mode === 'primary' || mode === 'all';
|
|
61
72
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
// OpenCode 2.x serves one flat model catalogue instead of models nested under
|
|
74
|
+
// providers: every entry already names its provider.
|
|
75
|
+
const hasCatalogModel = (models, providerID, modelID) => models.some(
|
|
76
|
+
(model) => model?.providerID === providerID && model?.modelID === modelID,
|
|
77
|
+
);
|
|
67
78
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
79
|
+
const findCatalogModel = (models, providerID, modelID) => models.find(
|
|
80
|
+
(model) => model?.providerID === providerID && model?.modelID === modelID,
|
|
81
|
+
) || null;
|
|
72
82
|
|
|
73
|
-
const resolveVariant = (
|
|
83
|
+
const resolveVariant = (models, providerID, modelID, variant) => {
|
|
74
84
|
const normalized = asNonEmptyString(variant);
|
|
75
85
|
if (!normalized) return undefined;
|
|
76
|
-
const
|
|
77
|
-
|
|
86
|
+
const model = findCatalogModel(models, providerID, modelID);
|
|
87
|
+
// A model the catalog does not know yet (cold or unreachable) keeps the
|
|
88
|
+
// user's saved variant instead of losing it to a discovery gap.
|
|
78
89
|
if (!model) return normalized;
|
|
79
|
-
return model
|
|
80
|
-
? normalized
|
|
81
|
-
: undefined;
|
|
90
|
+
return asList(model.variants).some((entry) => entry?.id === normalized) ? normalized : undefined;
|
|
82
91
|
};
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
// Config `model` is either "providerID/modelID" or the expanded object form.
|
|
94
|
+
const parseConfigModel = (value) => {
|
|
95
|
+
if (typeof value === 'string') return splitModel(value);
|
|
96
|
+
const providerID = asNonEmptyString(value?.providerID);
|
|
97
|
+
const modelID = asNonEmptyString(value?.model);
|
|
98
|
+
return providerID && modelID ? { providerID, modelID } : null;
|
|
99
|
+
};
|
|
85
100
|
|
|
86
101
|
const resolveProjectDefaults = (settings, directory, projectId) => {
|
|
87
102
|
const projects = Array.isArray(settings?.projects) ? settings.projects : [];
|
|
@@ -95,181 +110,161 @@ const resolveProjectDefaults = (settings, directory, projectId) => {
|
|
|
95
110
|
};
|
|
96
111
|
};
|
|
97
112
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const fetchJson = async (url, authHeaders, fallback, directory) => {
|
|
106
|
-
const response = await fetch(url.toString(), {
|
|
107
|
-
headers: { ...authHeaders, ...buildDirectoryHeaders(directory), accept: 'application/json' },
|
|
108
|
-
});
|
|
109
|
-
if (!response.ok) return fallback;
|
|
110
|
-
return response.json().catch(() => fallback);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const fetchSelectionInputs = async ({ buildOpenCodeUrl, authHeaders, directory, readSettingsFromDiskMigrated }) => {
|
|
113
|
+
/** `x-opencode-directory` is how v2 scopes a request; there is no query param. */
|
|
114
|
+
/**
|
|
115
|
+
* Everything the default model/agent resolution needs, from one directory-scoped
|
|
116
|
+
* client. A failed lookup answers empty on purpose: an empty catalogue means
|
|
117
|
+
* "unknown", and callers must never turn that into a rejection.
|
|
118
|
+
*/
|
|
119
|
+
const fetchSelectionInputs = async ({ client, readSettingsFromDiskMigrated }) => {
|
|
114
120
|
const settings = await readSettingsFromDiskMigrated();
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const [providersBody, agentsBody, configBody] = await Promise.all([
|
|
123
|
-
fetchJson(providersUrl, authHeaders, { providers: [] }, directory),
|
|
124
|
-
fetchJson(agentsUrl, authHeaders, [], directory),
|
|
125
|
-
fetchJson(configUrl, authHeaders, {}, directory),
|
|
121
|
+
const [models, agents, configEntries] = await Promise.all([
|
|
122
|
+
client.model.list().then((response) => asList(response?.data)).catch(() => []),
|
|
123
|
+
// v2 agents carry `id` (`build`, what prompts and sessions refer to) and a
|
|
124
|
+
// display `name` (`Build`); every lookup here is by id.
|
|
125
|
+
client.agent.list().then((response) => asList(response?.data)).catch(() => []),
|
|
126
|
+
client.config.get().then((response) => asList(response)).catch(() => []),
|
|
126
127
|
]);
|
|
127
128
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
// Config entries arrive lowest priority first, so the last definition wins.
|
|
130
|
+
let opencodeDefaultAgent = null;
|
|
131
|
+
let opencodeDefaultModel = null;
|
|
132
|
+
for (const entry of configEntries) {
|
|
133
|
+
const info = entry?.info;
|
|
134
|
+
if (!info) continue;
|
|
135
|
+
const agent = asNonEmptyString(info.default_agent);
|
|
136
|
+
if (agent) opencodeDefaultAgent = agent;
|
|
137
|
+
const model = parseConfigModel(info.model);
|
|
138
|
+
if (model) opencodeDefaultModel = model;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return { settings, models, agents, opencodeDefaultAgent, opencodeDefaultModel };
|
|
135
142
|
};
|
|
136
143
|
|
|
137
|
-
const resolveDefaultSelection = ({ agents,
|
|
144
|
+
const resolveDefaultSelection = ({ agents, models, settings, projectDefaults, opencodeDefaultAgent, opencodeDefaultModel }) => {
|
|
138
145
|
const primaryAgents = agents.filter((agent) => isPrimaryAgentMode(agent?.mode) && agent?.hidden !== true);
|
|
139
146
|
let resolvedAgent = null;
|
|
140
147
|
const projectDefaultAgent = asNonEmptyString(projectDefaults?.defaultAgent);
|
|
141
148
|
const settingsDefaultAgent = asNonEmptyString(settings?.defaultAgent);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
// The project's default agent wins over the global one. v1 stored the agent's
|
|
150
|
+
// display name; v2 agents are addressed by id (`build` vs `Build`), so a
|
|
151
|
+
// setting saved before the upgrade still resolves.
|
|
152
|
+
const findAgentBySetting = (wantedName) => {
|
|
153
|
+
const wanted = wantedName.toLowerCase();
|
|
154
|
+
return agents.find((agent) => agent?.id === wantedName)
|
|
155
|
+
|| agents.find((agent) => typeof agent?.name === 'string' && agent.name.toLowerCase() === wanted)
|
|
156
|
+
|| agents.find((agent) => typeof agent?.id === 'string' && agent.id.toLowerCase() === wanted)
|
|
157
|
+
|| null;
|
|
158
|
+
};
|
|
159
|
+
if (projectDefaultAgent) resolvedAgent = findAgentBySetting(projectDefaultAgent);
|
|
160
|
+
if (!resolvedAgent && settingsDefaultAgent) resolvedAgent = findAgentBySetting(settingsDefaultAgent);
|
|
148
161
|
if (!resolvedAgent && opencodeDefaultAgent) {
|
|
149
|
-
const candidate = agents.find((agent) => agent?.
|
|
162
|
+
const candidate = agents.find((agent) => agent?.id === opencodeDefaultAgent) || null;
|
|
150
163
|
if (candidate && isPrimaryAgentMode(candidate.mode) && candidate.hidden !== true) {
|
|
151
164
|
resolvedAgent = candidate;
|
|
152
165
|
}
|
|
153
166
|
}
|
|
154
167
|
if (!resolvedAgent) {
|
|
155
|
-
resolvedAgent = primaryAgents.find((agent) => agent?.
|
|
168
|
+
resolvedAgent = primaryAgents.find((agent) => agent?.id === 'build') || primaryAgents[0] || agents[0] || null;
|
|
156
169
|
}
|
|
157
170
|
|
|
158
171
|
let model = null;
|
|
159
172
|
let variant;
|
|
160
173
|
const projectDefaultModel = parseConfigModel(projectDefaults?.defaultModel);
|
|
161
174
|
const settingsDefaultModel = parseConfigModel(settings?.defaultModel);
|
|
175
|
+
// A saved choice is honoured even when the catalog has not listed it yet: a
|
|
176
|
+
// discovery gap must not silently move the user onto another model.
|
|
162
177
|
if (projectDefaultModel) {
|
|
163
178
|
model = projectDefaultModel;
|
|
164
|
-
variant = resolveVariant(
|
|
179
|
+
variant = resolveVariant(models, model.providerID, model.modelID, projectDefaults?.defaultVariant);
|
|
165
180
|
}
|
|
166
181
|
if (!model && settingsDefaultModel) {
|
|
167
182
|
model = settingsDefaultModel;
|
|
168
|
-
variant = resolveVariant(
|
|
183
|
+
variant = resolveVariant(models, model.providerID, model.modelID, settings?.defaultVariant);
|
|
169
184
|
}
|
|
170
185
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
// An agent's model is a v2 `ModelRef`: `id` is the model id, not a composite.
|
|
187
|
+
const agentModel = resolvedAgent?.model;
|
|
188
|
+
if (!model && asNonEmptyString(agentModel?.providerID) && asNonEmptyString(agentModel?.id)) {
|
|
189
|
+
model = { providerID: agentModel.providerID, modelID: agentModel.id };
|
|
190
|
+
variant = resolveVariant(models, model.providerID, model.modelID, agentModel.variant);
|
|
174
191
|
}
|
|
175
192
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
model = opencodeModel;
|
|
193
|
+
if (!model && opencodeDefaultModel) {
|
|
194
|
+
model = opencodeDefaultModel;
|
|
179
195
|
}
|
|
180
196
|
|
|
181
|
-
if (!model &&
|
|
197
|
+
if (!model && hasCatalogModel(models, FALLBACK_PROVIDER_ID, FALLBACK_MODEL_ID)) {
|
|
182
198
|
model = { providerID: FALLBACK_PROVIDER_ID, modelID: FALLBACK_MODEL_ID };
|
|
183
199
|
}
|
|
184
200
|
|
|
185
201
|
if (!model) {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
model = { providerID: provider.id, modelID: firstModel.id };
|
|
202
|
+
const first = models[0];
|
|
203
|
+
if (asNonEmptyString(first?.providerID) && asNonEmptyString(first?.modelID)) {
|
|
204
|
+
model = { providerID: first.providerID, modelID: first.modelID };
|
|
190
205
|
}
|
|
191
206
|
}
|
|
192
207
|
|
|
193
208
|
return {
|
|
194
|
-
agent: resolvedAgent?.
|
|
209
|
+
agent: resolvedAgent?.id,
|
|
195
210
|
model,
|
|
196
211
|
variant,
|
|
197
212
|
};
|
|
198
213
|
};
|
|
199
214
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
body: JSON.stringify(payload),
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
if (!response.ok) {
|
|
215
|
-
const body = await response.text().catch(() => '');
|
|
216
|
-
throw new Error(`prompt_async failed (${response.status})${body ? `: ${body}` : ''}`);
|
|
215
|
+
/**
|
|
216
|
+
* v2 selects model and agent per session, not per prompt: the choice is
|
|
217
|
+
* switched once and then persists, so every dispatch sets it explicitly rather
|
|
218
|
+
* than passing it alongside the prompt.
|
|
219
|
+
*/
|
|
220
|
+
const applySessionSelection = async ({ client, sessionID, model, agent, variant }) => {
|
|
221
|
+
if (model) {
|
|
222
|
+
await client.session.switchModel({
|
|
223
|
+
sessionID,
|
|
224
|
+
model: { id: model.modelID, providerID: model.providerID, ...(variant ? { variant } : {}) },
|
|
225
|
+
});
|
|
217
226
|
}
|
|
227
|
+
if (agent) await client.session.switchAgent({ sessionID, agent });
|
|
218
228
|
};
|
|
219
229
|
|
|
220
|
-
const createSession = async ({
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
method: 'POST',
|
|
225
|
-
headers: {
|
|
226
|
-
...authHeaders,
|
|
227
|
-
...buildDirectoryHeaders(directory),
|
|
228
|
-
'content-type': 'application/json',
|
|
229
|
-
accept: 'application/json',
|
|
230
|
-
},
|
|
231
|
-
body: JSON.stringify({ directory, ...(title ? { title } : {}) }),
|
|
230
|
+
const createSession = async ({ client, directory, title }) => {
|
|
231
|
+
const session = await client.session.create({
|
|
232
|
+
location: { directory },
|
|
233
|
+
...(title ? { title } : {}),
|
|
232
234
|
});
|
|
233
|
-
|
|
234
|
-
if (!
|
|
235
|
-
const body = await response.text().catch(() => '');
|
|
236
|
-
throw new Error(`session create failed (${response.status})${body ? `: ${body}` : ''}`);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const body = await response.json().catch(() => null);
|
|
240
|
-
const sessionID = body?.id || body?.data?.id;
|
|
241
|
-
if (!sessionID) {
|
|
242
|
-
throw new Error('failed to create session');
|
|
243
|
-
}
|
|
235
|
+
const sessionID = asNonEmptyString(session?.id);
|
|
236
|
+
if (!sessionID) throw new Error('failed to create session');
|
|
244
237
|
return sessionID;
|
|
245
238
|
};
|
|
246
239
|
|
|
247
|
-
const forkSession = async ({ client, sessionID,
|
|
248
|
-
const
|
|
240
|
+
const forkSession = async ({ client, sessionID, messageID }) => {
|
|
241
|
+
const session = await client.session.fork({
|
|
249
242
|
sessionID,
|
|
250
|
-
|
|
251
|
-
|
|
243
|
+
// OpenCode 2.0.8 replaced the SessionForkBoundary object with an optional
|
|
244
|
+
// `before` message id. Omitting it carries the whole session over, which is
|
|
245
|
+
// what the old `{ type: 'through' }` boundary meant.
|
|
246
|
+
...(messageID ? { before: messageID } : {}),
|
|
252
247
|
});
|
|
253
|
-
|
|
254
|
-
if (!session?.id) {
|
|
255
|
-
throw new Error('failed to fork session');
|
|
256
|
-
}
|
|
248
|
+
if (!asNonEmptyString(session?.id)) throw new Error('failed to fork session');
|
|
257
249
|
return session;
|
|
258
250
|
};
|
|
259
251
|
|
|
260
|
-
const
|
|
261
|
-
|
|
252
|
+
const listMessages = async ({ client, sessionID, limit }) => {
|
|
253
|
+
const response = await client.message.list({ sessionID, limit, order: 'desc' });
|
|
254
|
+
return asList(response?.data);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const latestCompletedAssistantMessageID = async ({ client, sessionID }) => {
|
|
258
|
+
let messages;
|
|
262
259
|
try {
|
|
263
|
-
|
|
260
|
+
messages = await listMessages({ client, sessionID, limit: 100 });
|
|
264
261
|
} catch {
|
|
265
262
|
return null;
|
|
266
263
|
}
|
|
267
|
-
const messages = Array.isArray(response?.data) ? response.data : [];
|
|
268
264
|
let latest = null;
|
|
269
265
|
for (const message of messages) {
|
|
270
|
-
|
|
271
|
-
if (
|
|
272
|
-
if (!latest || (info.time.created || 0) >= (latest.time?.created || 0)) latest = info;
|
|
266
|
+
if (message?.type !== 'assistant' || !Number.isFinite(message?.time?.completed)) continue;
|
|
267
|
+
if (!latest || (message.time.created || 0) >= (latest.time?.created || 0)) latest = message;
|
|
273
268
|
}
|
|
274
269
|
return asNonEmptyString(latest?.id);
|
|
275
270
|
};
|
|
@@ -277,14 +272,12 @@ const latestCompletedAssistantMessageID = async ({ client, sessionID, directory
|
|
|
277
272
|
/**
|
|
278
273
|
* Upper bound on one archive batch.
|
|
279
274
|
*
|
|
280
|
-
* The batch is
|
|
281
|
-
*
|
|
282
|
-
* more sessions than this send several batches and keep their own partial
|
|
283
|
-
* results.
|
|
275
|
+
* The batch is a bounded amount of work on one request, and callers with more
|
|
276
|
+
* sessions than this send several batches and keep their own partial results.
|
|
284
277
|
*/
|
|
285
278
|
const MAX_ARCHIVE_BATCH = 500;
|
|
286
279
|
|
|
287
|
-
const
|
|
280
|
+
const parseIdBatch = (payload) => {
|
|
288
281
|
const rawIds = payload?.ids;
|
|
289
282
|
if (!Array.isArray(rawIds) || rawIds.length === 0) {
|
|
290
283
|
return { ok: false, error: 'ids must be a non-empty array of session ids' };
|
|
@@ -299,13 +292,19 @@ const parseArchiveRequest = (payload) => {
|
|
|
299
292
|
if (!id) return { ok: false, error: 'ids must contain non-empty session ids' };
|
|
300
293
|
ids.push(id);
|
|
301
294
|
}
|
|
295
|
+
return { ok: true, ids };
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const parseArchiveRequest = (payload) => {
|
|
299
|
+
const parsed = parseIdBatch(payload);
|
|
300
|
+
if (!parsed.ok) return parsed;
|
|
302
301
|
|
|
303
302
|
const archivedAt = payload?.archivedAt;
|
|
304
303
|
if (archivedAt !== undefined && (!Number.isSafeInteger(archivedAt) || archivedAt <= 0)) {
|
|
305
304
|
return { ok: false, error: 'archivedAt must be a positive integer timestamp' };
|
|
306
305
|
}
|
|
307
306
|
|
|
308
|
-
return { ok: true, ids, archivedAt: archivedAt ?? Date.now() };
|
|
307
|
+
return { ok: true, ids: parsed.ids, archivedAt: archivedAt ?? Date.now() };
|
|
309
308
|
};
|
|
310
309
|
|
|
311
310
|
const resolveRequestedDirectory = async ({ payload, readSettingsFromDiskMigrated, sanitizeProjects, validateDirectoryPath }) => {
|
|
@@ -336,9 +335,6 @@ const resolveRequestedDirectory = async ({ payload, readSettingsFromDiskMigrated
|
|
|
336
335
|
return { ok: true, directory: validated.directory, ...(project ? { projectId: project.id } : {}) };
|
|
337
336
|
};
|
|
338
337
|
|
|
339
|
-
const PROMPT_LANDED_TIMEOUT_MS = 5_000;
|
|
340
|
-
const PROMPT_LANDED_POLL_MS = 150;
|
|
341
|
-
|
|
342
338
|
// createWorktree returns while the worktree is still being populated in the
|
|
343
339
|
// background (git reset --hard after a --no-checkout add). Dispatching a
|
|
344
340
|
// prompt into a half-populated directory makes opencode's run die with
|
|
@@ -348,54 +344,6 @@ const PROMPT_LANDED_POLL_MS = 150;
|
|
|
348
344
|
const WORKTREE_BOOTSTRAP_TIMEOUT_MS = 60_000;
|
|
349
345
|
const WORKTREE_BOOTSTRAP_POLL_MS = 150;
|
|
350
346
|
|
|
351
|
-
const waitForWorktreeBootstrapReady = async ({ directory }) => {
|
|
352
|
-
const deadline = Date.now() + WORKTREE_BOOTSTRAP_TIMEOUT_MS;
|
|
353
|
-
for (;;) {
|
|
354
|
-
const status = await getWorktreeBootstrapStatus(directory);
|
|
355
|
-
if (status?.status === 'failed') {
|
|
356
|
-
throw new OpenChamberControlError(`Worktree bootstrap failed: ${status.error || 'unknown error'}`, 500);
|
|
357
|
-
}
|
|
358
|
-
const phase = status?.phase;
|
|
359
|
-
if (status?.status === 'ready' || phase === 'git-ready' || phase === 'setup-ready') return;
|
|
360
|
-
if (Date.now() >= deadline) {
|
|
361
|
-
throw new OpenChamberControlError('Timed out waiting for the worktree bootstrap', 500);
|
|
362
|
-
}
|
|
363
|
-
await new Promise((resolve) => setTimeout(resolve, WORKTREE_BOOTSTRAP_POLL_MS));
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
const latestUserMessageID = async ({ client, sessionID, directory }) => {
|
|
368
|
-
let response;
|
|
369
|
-
try {
|
|
370
|
-
response = await client.session.messages({ sessionID, directory, limit: 100 });
|
|
371
|
-
} catch {
|
|
372
|
-
return { ok: false, messageID: null };
|
|
373
|
-
}
|
|
374
|
-
const messages = Array.isArray(response?.data) ? response.data : [];
|
|
375
|
-
let latest = null;
|
|
376
|
-
for (const message of messages) {
|
|
377
|
-
const info = message?.info;
|
|
378
|
-
if (info?.role !== 'user') continue;
|
|
379
|
-
if (!latest || (info.time?.created || 0) >= (latest.time?.created || 0)) latest = info;
|
|
380
|
-
}
|
|
381
|
-
return { ok: true, messageID: asNonEmptyString(latest?.id) };
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
// `prompt_async` answers 204 as soon as OpenCode forks the run, and every later
|
|
385
|
-
// failure is reported only on the session event stream. Confirm the prompt was
|
|
386
|
-
// actually recorded so `promptDispatched` never claims a dispatch that vanished.
|
|
387
|
-
const waitForPromptLanded = async ({ client, sessionID, directory, baselineUserMessageID }) => {
|
|
388
|
-
const deadline = Date.now() + PROMPT_LANDED_TIMEOUT_MS;
|
|
389
|
-
for (;;) {
|
|
390
|
-
const latest = await latestUserMessageID({ client, sessionID, directory });
|
|
391
|
-
// A failed lookup is not authoritative evidence that the prompt was lost.
|
|
392
|
-
if (!latest.ok) return true;
|
|
393
|
-
if (latest.messageID && latest.messageID !== baselineUserMessageID) return true;
|
|
394
|
-
if (Date.now() >= deadline) return false;
|
|
395
|
-
await new Promise((resolve) => setTimeout(resolve, PROMPT_LANDED_POLL_MS));
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
|
|
399
347
|
const resolveWorktreeInput = (payload) => {
|
|
400
348
|
if (!payload?.worktree || typeof payload.worktree !== 'object') return null;
|
|
401
349
|
const name = asNonEmptyString(payload.worktree.name);
|
|
@@ -420,54 +368,95 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
420
368
|
getOpenCodeAuthHeaders,
|
|
421
369
|
waitForOpenCodeReady,
|
|
422
370
|
emitSessionCreatedEvent,
|
|
371
|
+
broadcastGlobalUiEvent,
|
|
423
372
|
createSessionGoal: createSessionGoalOverride,
|
|
424
373
|
sessionKnowledgeRuntime = null,
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
374
|
+
dataDir = null,
|
|
375
|
+
archiveStore: injectedArchiveStore = null,
|
|
376
|
+
sessionMetadataStore: injectedSessionMetadataStore = null,
|
|
377
|
+
// Injected by the server so every metadata write takes the same path:
|
|
378
|
+
// store, broadcast, and tell the goal loop. Falls back to store+broadcast
|
|
379
|
+
// when it is absent, which is what module tests use.
|
|
380
|
+
persistSessionMetadata = null,
|
|
381
|
+
createOpenCodeClient = defaultCreateOpenCodeClient,
|
|
382
|
+
createWorktree = createWorktreeDefault,
|
|
383
|
+
getWorktreeBootstrapStatus = getWorktreeBootstrapStatusDefault,
|
|
384
|
+
// Auto routing. Sessions dispatched here talk to OpenCode through the SDK,
|
|
385
|
+
// not through the proxy that intercepts the Auto sentinel, so a default of
|
|
386
|
+
// `openchamber/auto` (Session Defaults) is resolved here before the
|
|
387
|
+
// session is switched onto it. Null when routing is not wired in.
|
|
388
|
+
resolveAutoSelection = null,
|
|
429
389
|
} = dependencies;
|
|
430
390
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
391
|
+
if ((!injectedArchiveStore || !injectedSessionMetadataStore) && !dataDir) {
|
|
392
|
+
throw new Error('openchamber session routes need either both stores or a dataDir');
|
|
393
|
+
}
|
|
394
|
+
const archiveStore = injectedArchiveStore || createArchiveStore({ dataDir });
|
|
395
|
+
const sessionMetadataStore = injectedSessionMetadataStore || createSessionMetadataStore({
|
|
396
|
+
dataDir,
|
|
397
|
+
openCode: createOpenCodeSessionMetadata({
|
|
398
|
+
buildOpenCodeUrl,
|
|
399
|
+
getOpenCodeAuthHeaders,
|
|
400
|
+
createOpenCodeClient,
|
|
401
|
+
}),
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
const openCodeBaseUrl = () => buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
405
|
+
const clientFor = (directory) => createOpenCodeClient({
|
|
406
|
+
baseUrl: openCodeBaseUrl(),
|
|
407
|
+
headers: getOpenCodeAuthHeaders(),
|
|
408
|
+
directory,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const waitForWorktreeBootstrapReady = async ({ directory }) => {
|
|
412
|
+
const deadline = Date.now() + WORKTREE_BOOTSTRAP_TIMEOUT_MS;
|
|
413
|
+
for (;;) {
|
|
414
|
+
const status = await getWorktreeBootstrapStatus(directory);
|
|
415
|
+
if (status?.status === 'failed') {
|
|
416
|
+
throw new OpenChamberControlError(`Worktree bootstrap failed: ${status.error || 'unknown error'}`, 500);
|
|
448
417
|
}
|
|
418
|
+
const phase = status?.phase;
|
|
419
|
+
if (status?.status === 'ready' || phase === 'git-ready' || phase === 'setup-ready') return;
|
|
420
|
+
if (Date.now() >= deadline) {
|
|
421
|
+
throw new OpenChamberControlError('Timed out waiting for the worktree bootstrap', 500);
|
|
422
|
+
}
|
|
423
|
+
await new Promise((resolve) => setTimeout(resolve, WORKTREE_BOOTSTRAP_POLL_MS));
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The selection an existing session already runs on. v2 keeps it on the
|
|
429
|
+
* session record, so there is no need to walk the message history for it.
|
|
430
|
+
*/
|
|
431
|
+
const fetchSessionSelection = async ({ client, sessionID }) => {
|
|
432
|
+
try {
|
|
433
|
+
const session = await client.session.get({ sessionID });
|
|
434
|
+
const providerID = asNonEmptyString(session?.model?.providerID);
|
|
435
|
+
const modelID = asNonEmptyString(session?.model?.id);
|
|
436
|
+
return {
|
|
437
|
+
model: providerID && modelID ? { providerID, modelID } : null,
|
|
438
|
+
agent: asNonEmptyString(session?.agent),
|
|
439
|
+
variant: asNonEmptyString(session?.model?.variant),
|
|
440
|
+
};
|
|
449
441
|
} catch {
|
|
442
|
+
return null;
|
|
450
443
|
}
|
|
451
|
-
return null;
|
|
452
444
|
};
|
|
453
445
|
|
|
454
|
-
//
|
|
455
|
-
//
|
|
456
|
-
//
|
|
446
|
+
// An unknown agent or model makes the run fail after the prompt is accepted,
|
|
447
|
+
// leaving a session with no answer. Reject them before any session, worktree,
|
|
448
|
+
// or goal side effect happens.
|
|
457
449
|
const validateRequestedSelection = async ({ directory, requestedModel, requestedAgent, requestedVariant }) => {
|
|
458
450
|
if (!requestedModel && !requestedAgent && !requestedVariant) return;
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
buildOpenCodeUrl,
|
|
462
|
-
authHeaders,
|
|
463
|
-
directory,
|
|
451
|
+
const { models, agents } = await fetchSelectionInputs({
|
|
452
|
+
client: clientFor(directory),
|
|
464
453
|
readSettingsFromDiskMigrated,
|
|
465
454
|
});
|
|
466
455
|
|
|
467
456
|
// An empty list means the lookup failed or returned nothing authoritative;
|
|
468
457
|
// it must not turn a valid selection into a rejection.
|
|
469
458
|
if (requestedAgent && agents.length > 0) {
|
|
470
|
-
const agent = agents.find((entry) => entry?.
|
|
459
|
+
const agent = agents.find((entry) => entry?.id === requestedAgent) || null;
|
|
471
460
|
if (!agent) {
|
|
472
461
|
throw new OpenChamberControlError(`Unknown agent '${requestedAgent}' for ${directory}`, 400);
|
|
473
462
|
}
|
|
@@ -476,15 +465,15 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
476
465
|
}
|
|
477
466
|
}
|
|
478
467
|
|
|
479
|
-
if (requestedModel &&
|
|
480
|
-
if (!
|
|
468
|
+
if (requestedModel && models.length > 0) {
|
|
469
|
+
if (!hasCatalogModel(models, requestedModel.providerID, requestedModel.modelID)) {
|
|
481
470
|
throw new OpenChamberControlError(
|
|
482
471
|
`Unknown model '${requestedModel.providerID}/${requestedModel.modelID}' for ${directory}`,
|
|
483
472
|
400,
|
|
484
473
|
);
|
|
485
474
|
}
|
|
486
475
|
if (requestedVariant
|
|
487
|
-
&& !resolveVariant(
|
|
476
|
+
&& !resolveVariant(models, requestedModel.providerID, requestedModel.modelID, requestedVariant)) {
|
|
488
477
|
throw new OpenChamberControlError(
|
|
489
478
|
`Unknown variant '${requestedVariant}' for model '${requestedModel.providerID}/${requestedModel.modelID}'`,
|
|
490
479
|
400,
|
|
@@ -511,7 +500,7 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
511
500
|
let agent = requestedAgent;
|
|
512
501
|
let variant = requestedVariant;
|
|
513
502
|
if (reuseSessionSelection && (!model || !agent)) {
|
|
514
|
-
const previous = await
|
|
503
|
+
const previous = await fetchSessionSelection({ client, sessionID });
|
|
515
504
|
if (previous) {
|
|
516
505
|
if (!model && previous.model) {
|
|
517
506
|
model = previous.model;
|
|
@@ -521,12 +510,7 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
521
510
|
}
|
|
522
511
|
}
|
|
523
512
|
if (!model || !agent) {
|
|
524
|
-
const inputs = await fetchSelectionInputs({
|
|
525
|
-
buildOpenCodeUrl,
|
|
526
|
-
authHeaders,
|
|
527
|
-
directory,
|
|
528
|
-
readSettingsFromDiskMigrated,
|
|
529
|
-
});
|
|
513
|
+
const inputs = await fetchSelectionInputs({ client, readSettingsFromDiskMigrated });
|
|
530
514
|
const defaults = resolveDefaultSelection({
|
|
531
515
|
...inputs,
|
|
532
516
|
projectDefaults: resolveProjectDefaults(inputs.settings, directory, projectId),
|
|
@@ -544,31 +528,53 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
544
528
|
}
|
|
545
529
|
|
|
546
530
|
const expandedPrompt = expandSnippets(prompt, directory);
|
|
531
|
+
if (isAutoModel(model)) {
|
|
532
|
+
// The sentinel must never reach OpenCode: neither the goal record nor the
|
|
533
|
+
// session switch below may carry it.
|
|
534
|
+
if (!resolveAutoSelection) {
|
|
535
|
+
throw new OpenChamberControlError('Auto routing is not available on this server. Choose a model.', 400);
|
|
536
|
+
}
|
|
537
|
+
const routed = await resolveAutoSelection({
|
|
538
|
+
sessionId: sessionID,
|
|
539
|
+
directory,
|
|
540
|
+
model: AUTO_MODEL_REF,
|
|
541
|
+
agent: agent ?? null,
|
|
542
|
+
requestText: expandedPrompt,
|
|
543
|
+
});
|
|
544
|
+
model = { providerID: routed.model.providerID, modelID: routed.model.id };
|
|
545
|
+
variant = routed.model.variant ?? undefined;
|
|
546
|
+
agent = routed.agent || agent;
|
|
547
|
+
}
|
|
547
548
|
const parsedCommand = parseScheduledCommandPrompt(prompt);
|
|
548
549
|
let resolvedCommand = null;
|
|
549
550
|
if (parsedCommand) {
|
|
550
551
|
try {
|
|
551
|
-
const response = await client.command.list(
|
|
552
|
-
const commands =
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
const response = await client.command.list();
|
|
553
|
+
const commands = asList(response?.data);
|
|
554
|
+
if (commands.some((candidate) => candidate?.name === parsedCommand.command)) {
|
|
555
|
+
resolvedCommand = parsedCommand;
|
|
556
|
+
}
|
|
555
557
|
} catch {
|
|
556
558
|
}
|
|
557
559
|
}
|
|
558
560
|
if (goalInput.enabled) {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
: null;
|
|
561
|
+
// v2 no longer publishes a command's template, so a slash command's goal
|
|
562
|
+
// objective is the prompt the user typed rather than the expanded body.
|
|
562
563
|
await (createSessionGoalOverride || createSessionGoal)({
|
|
563
564
|
baseUrl,
|
|
564
565
|
authHeaders,
|
|
565
566
|
sessionID,
|
|
566
567
|
directory,
|
|
567
|
-
objective:
|
|
568
|
+
objective: expandedPrompt,
|
|
568
569
|
tokenBudget: goalInput.tokenBudget,
|
|
569
570
|
providerID: model.providerID,
|
|
570
571
|
modelID: model.modelID,
|
|
571
572
|
onWarning: (message, error) => console.warn(`[OpenChamberSessions] ${message}:`, error?.message || error),
|
|
573
|
+
// v2 has no session-metadata route, so the goal record goes to
|
|
574
|
+
// OpenChamber's own store — the same one the proxy overlays back.
|
|
575
|
+
persistSessionGoal: async (goalSessionID, goalDirectory, goal) => {
|
|
576
|
+
await writeMetadata(goalSessionID, { openchamber: { goal } }, goalDirectory);
|
|
577
|
+
},
|
|
572
578
|
});
|
|
573
579
|
}
|
|
574
580
|
|
|
@@ -577,66 +583,75 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
577
583
|
return error;
|
|
578
584
|
};
|
|
579
585
|
|
|
586
|
+
try {
|
|
587
|
+
await applySessionSelection({ client, sessionID, model, agent, variant });
|
|
588
|
+
} catch (error) {
|
|
589
|
+
throw markGoalPartial(error);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// A session the agent dispatched has no UI to attach the project's
|
|
593
|
+
// standing context, so it is asked for here. Never fails the dispatch:
|
|
594
|
+
// a session that runs without its background beats one that never runs.
|
|
595
|
+
const knowledge = sessionKnowledgeRuntime
|
|
596
|
+
? await sessionKnowledgeRuntime.resolvePendingForSession(sessionID, directory)
|
|
597
|
+
.catch(() => ({ text: '', signature: '' }))
|
|
598
|
+
: { text: '', signature: '' };
|
|
599
|
+
// After the send is accepted, so a rejected dispatch carries it again.
|
|
600
|
+
const recordKnowledge = async () => {
|
|
601
|
+
if (knowledge.text && sessionKnowledgeRuntime) {
|
|
602
|
+
await sessionKnowledgeRuntime.recordDelivered(sessionID, directory, knowledge.signature)
|
|
603
|
+
.catch(() => undefined);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
|
|
580
607
|
if (resolvedCommand) {
|
|
581
608
|
try {
|
|
609
|
+
// The command route takes no extra parts, so the context goes in
|
|
610
|
+
// first as a synthetic message that does not start execution.
|
|
611
|
+
if (knowledge.text) {
|
|
612
|
+
await client.session.synthetic({ sessionID, text: knowledge.text, resume: false });
|
|
613
|
+
}
|
|
582
614
|
await client.session.command({
|
|
583
615
|
sessionID,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
...(agent ? { agent } : {}),
|
|
588
|
-
model: `${model.providerID}/${model.modelID}`,
|
|
589
|
-
...(variant ? { variant } : {}),
|
|
616
|
+
// OpenCode 2.0.8 renamed the command body field `command` to `name`.
|
|
617
|
+
name: resolvedCommand.command,
|
|
618
|
+
text: resolvedCommand.arguments || '',
|
|
590
619
|
});
|
|
591
620
|
} catch (error) {
|
|
592
621
|
throw markGoalPartial(error);
|
|
593
622
|
}
|
|
623
|
+
await recordKnowledge();
|
|
594
624
|
} else {
|
|
595
|
-
|
|
596
|
-
// A session the agent dispatched has no UI to attach the project's
|
|
597
|
-
// standing context, so it is asked for here. Never fails the dispatch:
|
|
598
|
-
// a session that runs without its background beats one that never runs.
|
|
599
|
-
const knowledge = sessionKnowledgeRuntime
|
|
600
|
-
? await sessionKnowledgeRuntime.resolvePendingForSession(sessionID, directory)
|
|
601
|
-
.catch(() => ({ text: '', signature: '' }))
|
|
602
|
-
: { text: '', signature: '' };
|
|
603
|
-
const payload = {
|
|
604
|
-
model,
|
|
605
|
-
...(agent ? { agent } : {}),
|
|
606
|
-
...(variant ? { variant } : {}),
|
|
607
|
-
parts: [
|
|
608
|
-
...(knowledge.text ? [{ type: 'text', text: knowledge.text, synthetic: true }] : []),
|
|
609
|
-
{ type: 'text', text: expandedPrompt },
|
|
610
|
-
...(goalInput.enabled
|
|
611
|
-
? [{ type: 'text', text: buildGoalIntroText(goalInput.tokenBudget), synthetic: true }]
|
|
612
|
-
: []),
|
|
613
|
-
],
|
|
614
|
-
};
|
|
615
|
-
await resolvePromptBody?.(payload, { sessionId: sessionID, directory });
|
|
625
|
+
let landedMessageID = null;
|
|
616
626
|
try {
|
|
617
|
-
|
|
627
|
+
if (knowledge.text) {
|
|
628
|
+
await client.session.synthetic({ sessionID, text: knowledge.text, resume: false });
|
|
629
|
+
}
|
|
630
|
+
const sent = await client.session.prompt({ sessionID, text: expandedPrompt });
|
|
631
|
+
landedMessageID = asNonEmptyString(sent?.id);
|
|
632
|
+
if (goalInput.enabled) {
|
|
633
|
+
// Goal mode's reminder refers to "the user message above", so it is
|
|
634
|
+
// admitted after the prompt; v2 has no way to append to one message.
|
|
635
|
+
await client.session.synthetic({
|
|
636
|
+
sessionID,
|
|
637
|
+
text: buildGoalIntroText(goalInput.tokenBudget),
|
|
638
|
+
resume: false,
|
|
639
|
+
});
|
|
640
|
+
}
|
|
618
641
|
} catch (error) {
|
|
619
642
|
throw markGoalPartial(error);
|
|
620
643
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
const landed = await waitForPromptLanded({
|
|
627
|
-
client,
|
|
628
|
-
sessionID,
|
|
629
|
-
directory,
|
|
630
|
-
baselineUserMessageID: baseline.messageID,
|
|
631
|
-
});
|
|
632
|
-
if (!landed) {
|
|
644
|
+
await recordKnowledge();
|
|
645
|
+
if (!landedMessageID) {
|
|
646
|
+
// v2 answers a prompt with the inbox item it recorded. No item id means
|
|
647
|
+
// nothing is queued, so the dispatch must not be claimed as done.
|
|
633
648
|
return {
|
|
634
649
|
model,
|
|
635
650
|
agent,
|
|
636
651
|
variant,
|
|
637
652
|
promptDispatched: false,
|
|
638
653
|
dispatchedAsCommand: false,
|
|
639
|
-
promptError: 'OpenCode accepted the prompt but
|
|
654
|
+
promptError: 'OpenCode accepted the prompt but returned no queued message',
|
|
640
655
|
};
|
|
641
656
|
}
|
|
642
657
|
}
|
|
@@ -644,20 +659,63 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
644
659
|
return { model, agent, variant, promptDispatched: true, dispatchedAsCommand: Boolean(resolvedCommand) };
|
|
645
660
|
};
|
|
646
661
|
|
|
662
|
+
const broadcastMetadata = (sessionID, metadata) => {
|
|
663
|
+
broadcastGlobalUiEvent?.({
|
|
664
|
+
type: 'openchamber:session-metadata',
|
|
665
|
+
properties: { sessionID, metadata },
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Merge-patch a session's OpenChamber metadata on its OpenCode record: the
|
|
671
|
+
* per-session state of goal mode, session assist, obligatory context and
|
|
672
|
+
* pinned notes. The broadcast carries the full merged object, because a
|
|
673
|
+
* client that missed an earlier patch must not have to reconstruct it.
|
|
674
|
+
*/
|
|
675
|
+
const writeMetadata = async (sessionID, patch, directory = '') => {
|
|
676
|
+
if (typeof persistSessionMetadata === 'function') {
|
|
677
|
+
return persistSessionMetadata(sessionID, patch, { directory });
|
|
678
|
+
}
|
|
679
|
+
const metadata = await sessionMetadataStore.setSessionMetadata(sessionID, patch, { directory });
|
|
680
|
+
broadcastMetadata(sessionID, metadata);
|
|
681
|
+
return metadata;
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
const setMetadata = async (sessionID, payload = {}) => {
|
|
685
|
+
const id = asNonEmptyString(sessionID);
|
|
686
|
+
if (!id) throw new OpenChamberControlError('a session id is required', 400);
|
|
687
|
+
const patch = payload?.patch;
|
|
688
|
+
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
|
|
689
|
+
throw new OpenChamberControlError('patch must be an object', 400);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
return { metadata: await writeMetadata(id, patch, asNonEmptyString(payload?.directory) || '') };
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
const getMetadata = async (sessionID, directory = '') => {
|
|
696
|
+
const id = asNonEmptyString(sessionID);
|
|
697
|
+
if (!id) throw new OpenChamberControlError('a session id is required', 400);
|
|
698
|
+
return { metadata: await sessionMetadataStore.get(id, { directory }) };
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const broadcastArchived = (sessionID, archivedAt) => {
|
|
702
|
+
broadcastGlobalUiEvent?.({
|
|
703
|
+
type: 'openchamber:session-archived',
|
|
704
|
+
properties: { sessionID, archivedAt },
|
|
705
|
+
});
|
|
706
|
+
};
|
|
707
|
+
|
|
647
708
|
/**
|
|
648
709
|
* Archive a batch of sessions in one request.
|
|
649
710
|
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
711
|
+
* OpenCode 2.x has no route that sets `time.archived`, so the state is
|
|
712
|
+
* OpenChamber's own: a JSON file beside the OpenCode instance, folded back
|
|
713
|
+
* onto the session records the proxy serves. Batching matters for the same
|
|
714
|
+
* reason it did before — the UI archives every session linked to a worktree
|
|
715
|
+
* before removing it, and doing that one request at a time is what made
|
|
716
|
+
* removing a busy worktree take tens of seconds.
|
|
655
717
|
*
|
|
656
|
-
*
|
|
657
|
-
* single OpenCode instance, and a fan-out of concurrent writes would trade a
|
|
658
|
-
* UI stall for server event-loop starvation. One failed session never stops
|
|
659
|
-
* the batch — it is reported in `failedIds` while the rest still archive, so
|
|
660
|
-
* callers keep the partial-failure behaviour they already show.
|
|
718
|
+
* No directory is needed: archive state is keyed by session id per data dir.
|
|
661
719
|
*/
|
|
662
720
|
const archive = async (payload = {}) => {
|
|
663
721
|
const parsed = parseArchiveRequest(payload);
|
|
@@ -665,41 +723,21 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
665
723
|
throw new OpenChamberControlError(parsed.error, 400);
|
|
666
724
|
}
|
|
667
725
|
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
validateDirectoryPath,
|
|
673
|
-
});
|
|
674
|
-
if (!resolvedDirectory.ok) {
|
|
675
|
-
throw new OpenChamberControlError(resolvedDirectory.error, resolvedDirectory.status || 400);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
if (typeof waitForOpenCodeReady === 'function') await waitForOpenCodeReady(10_000, 250);
|
|
679
|
-
|
|
680
|
-
const directory = resolvedDirectory.directory;
|
|
681
|
-
const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
682
|
-
const client = createOpencodeClient({ baseUrl, headers: getOpenCodeAuthHeaders() });
|
|
726
|
+
const { archived, failedIds } = await archiveStore.archive(parsed.ids, parsed.archivedAt);
|
|
727
|
+
for (const entry of archived) broadcastArchived(entry.id, entry.archivedAt);
|
|
728
|
+
return { archived, failedIds };
|
|
729
|
+
};
|
|
683
730
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
sessionID,
|
|
690
|
-
directory,
|
|
691
|
-
time: { archived: parsed.archivedAt },
|
|
692
|
-
});
|
|
693
|
-
const session = response?.data;
|
|
694
|
-
if (session?.id) archived.push(session);
|
|
695
|
-
else failedIds.push(sessionID);
|
|
696
|
-
} catch (error) {
|
|
697
|
-
console.warn('[OpenChamberSessions] failed to archive session', sessionID, error);
|
|
698
|
-
failedIds.push(sessionID);
|
|
699
|
-
}
|
|
731
|
+
/** Clears the archive flag for a batch. Mirrors `archive`. */
|
|
732
|
+
const unarchive = async (payload = {}) => {
|
|
733
|
+
const parsed = parseIdBatch(payload);
|
|
734
|
+
if (!parsed.ok) {
|
|
735
|
+
throw new OpenChamberControlError(parsed.error, 400);
|
|
700
736
|
}
|
|
701
737
|
|
|
702
|
-
|
|
738
|
+
const { restored, failedIds } = await archiveStore.unarchive(parsed.ids);
|
|
739
|
+
for (const entry of restored) broadcastArchived(entry.id, null);
|
|
740
|
+
return { restored, failedIds };
|
|
703
741
|
};
|
|
704
742
|
|
|
705
743
|
const create = async (payload = {}) => {
|
|
@@ -747,13 +785,11 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
747
785
|
await waitForWorktreeBootstrapReady({ directory: sessionDirectory });
|
|
748
786
|
}
|
|
749
787
|
|
|
750
|
-
const baseUrl =
|
|
788
|
+
const baseUrl = openCodeBaseUrl();
|
|
751
789
|
const authHeaders = getOpenCodeAuthHeaders();
|
|
752
|
-
const client =
|
|
790
|
+
const client = clientFor(sessionDirectory);
|
|
753
791
|
const sessionID = await createSession({
|
|
754
792
|
client,
|
|
755
|
-
baseUrl,
|
|
756
|
-
authHeaders,
|
|
757
793
|
directory: sessionDirectory,
|
|
758
794
|
...(title ? { title } : {}),
|
|
759
795
|
});
|
|
@@ -845,23 +881,30 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
845
881
|
requestedVariant: asNonEmptyString(payload.variant),
|
|
846
882
|
});
|
|
847
883
|
|
|
848
|
-
const baseUrl =
|
|
884
|
+
const baseUrl = openCodeBaseUrl();
|
|
849
885
|
const authHeaders = getOpenCodeAuthHeaders();
|
|
850
|
-
const client =
|
|
886
|
+
const client = clientFor(directory);
|
|
851
887
|
if (action === 'fork') {
|
|
852
888
|
targetSession = await forkSession({
|
|
853
889
|
client,
|
|
854
890
|
sessionID: sourceSessionID,
|
|
855
|
-
directory,
|
|
856
891
|
messageID: asNonEmptyString(payload.messageId) || undefined,
|
|
857
892
|
});
|
|
858
893
|
targetSessionID = targetSession.id;
|
|
894
|
+
// Before the prompt goes out, so a goal armed by this dispatch writes
|
|
895
|
+
// over the copied objective rather than the other way round.
|
|
896
|
+
await applyForkInheritance({
|
|
897
|
+
sourceSessionID,
|
|
898
|
+
fork: targetSession,
|
|
899
|
+
readObjective,
|
|
900
|
+
writeObjective,
|
|
901
|
+
writeMetadata: (sessionID, patch) => writeMetadata(sessionID, patch, directory),
|
|
902
|
+
});
|
|
859
903
|
}
|
|
860
904
|
|
|
861
905
|
const baselineAssistantMessageId = await latestCompletedAssistantMessageID({
|
|
862
906
|
client,
|
|
863
907
|
sessionID: targetSessionID,
|
|
864
|
-
directory,
|
|
865
908
|
});
|
|
866
909
|
|
|
867
910
|
const dispatch = await dispatchPrompt({
|
|
@@ -939,6 +982,11 @@ export const createOpenChamberSessionService = (dependencies) => {
|
|
|
939
982
|
return {
|
|
940
983
|
create,
|
|
941
984
|
archive,
|
|
985
|
+
unarchive,
|
|
986
|
+
archiveStore,
|
|
987
|
+
sessionMetadataStore,
|
|
988
|
+
setMetadata,
|
|
989
|
+
getMetadata,
|
|
942
990
|
send: (sessionID, payload) => runExisting('send', sessionID, payload),
|
|
943
991
|
fork: (sessionID, payload) => runExisting('fork', sessionID, payload),
|
|
944
992
|
};
|
|
@@ -978,6 +1026,39 @@ export const registerOpenChamberSessionRoutes = (app, dependencies) => {
|
|
|
978
1026
|
}
|
|
979
1027
|
});
|
|
980
1028
|
|
|
1029
|
+
app.get('/api/openchamber/sessions/:sessionId/metadata', async (req, res) => {
|
|
1030
|
+
try {
|
|
1031
|
+
return res.json(await service.getMetadata(
|
|
1032
|
+
req.params.sessionId,
|
|
1033
|
+
asNonEmptyString(req.query?.directory) || '',
|
|
1034
|
+
));
|
|
1035
|
+
} catch (error) {
|
|
1036
|
+
console.error('[OpenChamberSessions] failed to read session metadata:', error);
|
|
1037
|
+
return sendServiceError(res, error, 'Failed to read session metadata');
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
app.post('/api/openchamber/sessions/:sessionId/metadata', express.json({ limit: '1mb' }), async (req, res) => {
|
|
1042
|
+
try {
|
|
1043
|
+
return res.json(await service.setMetadata(
|
|
1044
|
+
req.params.sessionId,
|
|
1045
|
+
req.body && typeof req.body === 'object' ? req.body : {},
|
|
1046
|
+
));
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
console.error('[OpenChamberSessions] failed to store session metadata:', error);
|
|
1049
|
+
return sendServiceError(res, error, 'Failed to store session metadata');
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
|
|
1053
|
+
app.post('/api/openchamber/sessions/unarchive', express.json({ limit: '1mb' }), async (req, res) => {
|
|
1054
|
+
try {
|
|
1055
|
+
return res.json(await service.unarchive(req.body && typeof req.body === 'object' ? req.body : {}));
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
console.error('[OpenChamberSessions] failed to unarchive sessions:', error);
|
|
1058
|
+
return sendServiceError(res, error, 'Failed to unarchive sessions');
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
|
|
981
1062
|
app.post(
|
|
982
1063
|
'/api/openchamber/sessions/:sessionId/send',
|
|
983
1064
|
express.json({ limit: '1mb' }),
|