@openchamber/web 2.0.2 → 2.0.4
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/DOCUMENTATION.md +1 -1
- package/bin/lib/commands-connect-url.js +6 -5
- package/bin/lib/commands-tunnel.js +24 -5
- package/dist/assets/{CodeMirrorCommentWidgets-CmKmyb9T.js → CodeMirrorCommentWidgets-C_zL-eri.js} +1 -1
- package/dist/assets/{DiffView-8-PFpZ2p.js → DiffView-BeN2_YYF.js} +3 -3
- package/dist/assets/FilesView-CN34wm_N.js +17 -0
- package/dist/assets/{GitView-DNUSu00w.js → GitView-DLDazOo1.js} +4 -4
- package/dist/assets/{GuestAttachDialog-Cv6QzjHC.js → GuestAttachDialog-C0xe_Lyy.js} +1 -1
- package/dist/assets/{GuestSurfacePane-Bt3jB_Ye.js → GuestSurfacePane-BdaurnDr.js} +1 -1
- package/dist/assets/{JsonTreeView-BlyHTRhM.js → JsonTreeView-B1Xq-k2t.js} +1 -1
- package/dist/assets/LinearIssuesView-BryoAHow.js +1 -0
- package/dist/assets/{MarkdownImageGallery-2UXJF-5B.js → MarkdownImageGallery-DfuEoaGq.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +12 -0
- package/dist/assets/OnboardingScreen-C22bGmnP.js +1 -0
- package/dist/assets/{PatchDiff-ByvnbG5T.js → PatchDiff-0xd6UeFB.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BXieg0mH.js → PierreDiffViewer-BC950e3F.js} +3 -3
- package/dist/assets/PlanView-B7Xgihqk.js +5 -0
- package/dist/assets/PluginPane-2C71F8uF.js +3 -0
- package/dist/assets/SettingsView-m_zoFiaT.js +30 -0
- package/dist/assets/{SettingsWindow-BIz224xs.js → SettingsWindow-CofS020b.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-CXKmlps9.js → SubmoduleDiffSummary-BSA9gnIO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BsgAK8xu.js → ToolOutputDialog-DprkVKcj.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-vdPObXOf.js → ToolPartDiffPreview-Dq0go_fX.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BkFNKWS5.js → VirtualizedFileDiff-Kp8hKJdT.js} +1 -1
- package/dist/assets/WalkthroughView-DGnTzqIU.js +4 -0
- package/dist/assets/{appThemeRegistry-aHUNHoqP.js → appThemeRegistry-BdEHBA4s.js} +1 -1
- package/dist/assets/{commitAndPush-Bon9r94r.js → commitAndPush-LwtVa2Oc.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DKqr_1AQ.js → computeVirtualFileMetrics-6V1xNpO9.js} +2 -2
- package/dist/assets/de-DlgBHUAI.js +10 -0
- package/dist/assets/es-BC8G41U8.js +16 -0
- package/dist/assets/fr-I0z3vVjy.js +14 -0
- package/dist/assets/index-CgR5rJq_.js +41 -0
- package/dist/assets/{index-DpFttslC.js → index-CmNPYddV.js} +1 -1
- package/dist/assets/index-adyy_sEk.css +1 -0
- package/dist/assets/{isDiffPlainText-kzAgpIgi.js → isDiffPlainText-1bXcWCrw.js} +1 -1
- package/dist/assets/{isFilePlainText-Uj6y-jzz.js → isFilePlainText-CBAppvy1.js} +1 -1
- package/dist/assets/ja-BIElEsY8.js +16 -0
- package/dist/assets/ko-DRnnHetA.js +16 -0
- package/dist/assets/{main-CbfMxn-I.js → main-CzjTMTfW.js} +2 -2
- package/dist/assets/main-DVX34beR.js +886 -0
- package/dist/assets/markdownCore-Cxbkn5NR.js +7 -0
- package/dist/assets/{miniChat-CiAKBC10.js → miniChat-CP68IL8Q.js} +2 -2
- package/dist/assets/{mobile-CsT4sJwC.js → mobile-BrlBrNfZ.js} +2 -2
- package/dist/assets/nl-DzUV-kwp.js +16 -0
- package/dist/assets/{patchFileDiff-DeaE08W0.js → patchFileDiff-pqRSHLHI.js} +2 -2
- package/dist/assets/pl-Bb-cb7k7.js +16 -0
- package/dist/assets/pt-BR-CyIWrTcE.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-DKIilR7N.js +2 -0
- package/dist/assets/renderMobileApp-B0z6-x58.js +25 -0
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +52 -0
- package/dist/assets/{scheduledTasksApi-BZCNJ588.js → scheduledTasksApi-BuzWT445.js} +1 -1
- package/dist/assets/{shikiHighlight-BSUEa3yF.js → shikiHighlight-BWGrY5YU.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CsATFZIV.js → textMateThemeFromAppTheme-BSUFChBY.js} +1 -1
- package/dist/assets/tr-DXEDSoYO.js +7 -0
- package/dist/assets/uk-C8hN--q_.js +16 -0
- package/dist/assets/useAppFontEffects-Dsl_sLrj.js +7366 -0
- package/dist/assets/useInlineCommentController-d5vntsQ_.js +2 -0
- package/dist/assets/{useRootScrollLock-Cp1eFoM2.js → useRootScrollLock-2rd5Y6gR.js} +2 -2
- package/dist/assets/{vendor-base-ui-CsXYnR5c.js → vendor-base-ui-DnNniUWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BwwommM0.js → vendor-codemirror-language-data-B1EetJur.js} +2 -2
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
- package/dist/assets/{vendor-tanstack-react-virtual-ClYN8CzB.js → vendor-tanstack-react-virtual--0sBrLRh.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-BewVQryB.js → vendor-tanstack-virtual-core-BoA4iGMw.js} +1 -1
- package/dist/assets/{vendor-zod-BSoePkpP.js → vendor-zod-CxRSdNoV.js} +4 -4
- package/dist/assets/{web-components-D3Yjr4Zx.js → web-components-ngpHPEDU.js} +1 -1
- package/dist/assets/zh-CN-CtzXdjMZ.js +16 -0
- package/dist/assets/zh-TW-Ds0CADSz.js +16 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +5 -5
- package/server/index.js +82 -4
- package/server/lib/agent-tool/DOCUMENTATION.md +8 -1
- package/server/lib/agent-tool/runtime.js +13 -4
- package/server/lib/agent-tool/runtime.test.js +15 -0
- package/server/lib/context-obligatory/DOCUMENTATION.md +10 -7
- package/server/lib/context-obligatory/runtime.js +2 -1
- package/server/lib/context-obligatory/runtime.test.js +76 -30
- package/server/lib/dictation/DOCUMENTATION.md +4 -1
- package/server/lib/dictation/openai-compatible-session.js +7 -0
- package/server/lib/enterprise-mode.d.ts +30 -0
- package/server/lib/enterprise-mode.js +253 -0
- package/server/lib/enterprise-mode.test.js +247 -0
- package/server/lib/event-stream/translate-v2.js +6 -0
- package/server/lib/event-stream/translate-v2.test.js +6 -0
- package/server/lib/git/DOCUMENTATION.md +2 -1
- package/server/lib/git/routes.js +44 -1
- package/server/lib/git/routes.test.js +98 -1
- package/server/lib/git/service.js +146 -11
- package/server/lib/git/service.test.js +195 -0
- package/server/lib/github/routes.js +9 -19
- package/server/lib/github/routes.test.js +112 -0
- package/server/lib/guests/DOCUMENTATION.md +4 -2
- package/server/lib/guests/background.test.js +1 -1
- package/server/lib/guests/catalog.js +56 -2
- package/server/lib/guests/catalog.test.js +24 -1
- package/server/lib/guests/clone-network.test.js +52 -0
- package/server/lib/guests/clone.js +30 -4
- package/server/lib/guests/enterprise.js +68 -0
- package/server/lib/guests/enterprise.test.js +106 -0
- package/server/lib/guests/grant-scope.js +8 -2
- package/server/lib/guests/grant-scope.test.js +9 -0
- package/server/lib/guests/html-styles.js +16 -2
- package/server/lib/guests/html-styles.test.js +53 -4
- package/server/lib/guests/install.js +10 -0
- package/server/lib/guests/persist.js +1 -0
- package/server/lib/guests/routes.js +40 -5
- package/server/lib/guests/updates.js +9 -2
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/runtime.js +22 -8
- package/server/lib/notifications/trigger-runtime.test.js +45 -0
- package/server/lib/openchamber-sessions/session-metadata-store.js +27 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +18 -0
- package/server/lib/opencode/DOCUMENTATION.md +13 -9
- package/server/lib/opencode/auth-state-runtime.js +2 -2
- package/server/lib/opencode/config-paths.test.js +1 -0
- package/server/lib/opencode/env-runtime.js +26 -3
- package/server/lib/opencode/env-runtime.test.js +57 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/hmr-state-runtime.js +4 -3
- package/server/lib/opencode/lifecycle.js +10 -5
- package/server/lib/opencode/lifecycle.test.js +6 -2
- package/server/lib/opencode/managed-config-file.js +2 -1
- package/server/lib/opencode/managed-config-file.test.js +18 -0
- package/server/lib/opencode/npm-registry-config.d.ts +1 -0
- package/server/lib/opencode/npm-registry-config.js +123 -0
- package/server/lib/opencode/npm-registry-config.test.js +167 -0
- package/server/lib/opencode/npm-registry.js +5 -6
- package/server/lib/opencode/npm-registry.test.js +30 -0
- package/server/lib/opencode/openchamber-routes.js +8 -0
- package/server/lib/opencode/project-icon-routes.js +2 -2
- package/server/lib/opencode/project-icon-routes.test.js +44 -0
- package/server/lib/opencode/provider-source-route.test.js +32 -0
- package/server/lib/opencode/routes.js +17 -2
- package/server/lib/opencode/settings-helpers.js +26 -3
- package/server/lib/opencode/settings-helpers.test.js +12 -5
- package/server/lib/opencode/settings-registry.json +35 -1
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +9 -1
- package/server/lib/opencode/static-routes-runtime.test.js +58 -1
- package/server/lib/package-manager.js +4 -1
- package/server/lib/package-manager.test.js +24 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +23 -15
- package/server/lib/permission-auto-accept/modes.js +26 -0
- package/server/lib/permission-auto-accept/runtime.js +146 -40
- package/server/lib/permission-auto-accept/runtime.test.js +93 -9
- package/server/lib/quota/DOCUMENTATION.md +6 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +74 -30
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +124 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/service.js +32 -12
- package/server/lib/relay/service.test.js +30 -0
- package/server/lib/routing/DOCUMENTATION.md +150 -41
- package/server/lib/routing/classifier.js +156 -0
- package/server/lib/routing/defaults.js +27 -0
- package/server/lib/routing/jev.js +5 -17
- package/server/lib/routing/routes.http.test.js +9 -0
- package/server/lib/routing/routes.js +27 -1
- package/server/lib/routing/runtime.js +199 -33
- package/server/lib/routing/runtime.test.js +299 -15
- package/server/lib/routing/store.js +57 -0
- package/server/lib/routing/store.test.js +37 -0
- package/server/lib/session-assist/DOCUMENTATION.md +17 -7
- package/server/lib/session-assist/context.js +42 -2
- package/server/lib/session-assist/context.test.js +38 -1
- package/server/lib/session-assist/runtime.js +57 -13
- package/server/lib/session-assist/runtime.test.js +45 -0
- package/server/lib/session-goal/DOCUMENTATION.md +47 -22
- package/server/lib/session-goal/audit.js +112 -0
- package/server/lib/session-goal/audit.test.js +58 -0
- package/server/lib/session-goal/runtime.js +113 -134
- package/server/lib/session-goal/runtime.test.js +146 -13
- package/server/lib/session-lineage.js +52 -0
- package/server/lib/session-lineage.test.js +45 -0
- package/server/lib/session-work/DOCUMENTATION.md +108 -0
- package/server/lib/session-work/questions.js +126 -0
- package/server/lib/session-work/runtime.js +278 -0
- package/server/lib/session-work/runtime.test.js +255 -0
- package/server/lib/session-work/state.js +48 -0
- package/server/lib/session-work/state.test.js +34 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -7
- package/server/lib/small-model/client.js +7 -4
- package/server/lib/small-model/index.js +11 -21
- package/server/lib/small-model/index.test.js +13 -26
- package/server/lib/spaces/DOCUMENTATION.md +79 -25
- package/server/lib/spaces/gatekeeper-channel.js +63 -11
- package/server/lib/spaces/gatekeeper-channel.test.js +34 -4
- package/server/lib/spaces/gatekeeper-program.cjs +64 -13
- package/server/lib/spaces/gatekeeper-program.test.js +115 -3
- package/server/lib/spaces/host.js +58 -13
- package/server/lib/spaces/host.test.js +34 -1
- package/server/lib/spaces/idle-stop.js +98 -0
- package/server/lib/spaces/idle-stop.test.js +130 -0
- package/server/lib/spaces/journey.js +427 -17
- package/server/lib/spaces/journey.test.js +592 -5
- package/server/lib/spaces/layout.js +27 -6
- package/server/lib/spaces/manager.test.js +1 -1
- package/server/lib/spaces/places/contract-suite.js +4 -2
- package/server/lib/spaces/places/docker-live-support.js +27 -4
- package/server/lib/spaces/places/docker.js +32 -5
- package/server/lib/spaces/places/docker.test.js +38 -8
- package/server/lib/spaces/places/escape-suite.js +32 -0
- package/server/lib/spaces/places/fake-docker.js +3 -1
- package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
- package/server/lib/spaces/places/memory-place.js +3 -3
- package/server/lib/spaces/places/sessions.docker.live.test.js +4 -2
- package/server/lib/spaces/routes.js +49 -1
- package/server/lib/spaces/routes.test.js +31 -3
- package/server/lib/spaces/space-opencode.js +52 -0
- package/server/lib/spaces/space-opencode.test.js +41 -0
- package/server/lib/spaces/space-records.js +90 -2
- package/server/lib/spaces/space-records.test.js +58 -1
- package/server/lib/spaces/space-server.js +13 -1
- package/server/lib/spaces/space-server.test.js +13 -0
- package/server/lib/spaces/space-setup.js +173 -0
- package/server/lib/spaces/space-setup.test.js +174 -0
- package/server/lib/tts/DOCUMENTATION.md +3 -0
- package/server/lib/tts/base-url.js +8 -0
- package/server/lib/tts/routes.js +13 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +14 -0
- package/server/lib/tunnels/routes.test.js +26 -0
- package/server/lib/walkthrough/index.js +11 -7
- package/server/lib/walkthrough/jobs.test.js +8 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/server/lib/walkthrough/routes.js +7 -1
- package/dist/assets/FilesView-0Ie20mEk.js +0 -17
- package/dist/assets/LinearIssuesView-CSl2MUfA.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +0 -12
- package/dist/assets/OnboardingScreen-CIdXJpfc.js +0 -1
- package/dist/assets/PlanView-DEIi3Q7M.js +0 -5
- package/dist/assets/PluginPane-BEPUWVho.js +0 -3
- package/dist/assets/SettingsView-CiNh-RbW.js +0 -30
- package/dist/assets/WalkthroughView-6oE-MuDL.js +0 -4
- package/dist/assets/de-CgAJ51z7.js +0 -10
- package/dist/assets/es-zGi_ravM.js +0 -16
- package/dist/assets/fr-CPfogrWx.js +0 -14
- package/dist/assets/index-CHfphYL3.js +0 -41
- package/dist/assets/index-DvMJ3w6V.css +0 -1
- package/dist/assets/ja-DMk6wd-U.js +0 -16
- package/dist/assets/ko-BFpzJ8jc.js +0 -16
- package/dist/assets/main-anyZFMIs.js +0 -896
- package/dist/assets/markdownCore-CmM47cAE.js +0 -7
- package/dist/assets/pl-VdRPcZrB.js +0 -16
- package/dist/assets/pt-BR-BRys_lOW.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-C5677jy0.js +0 -2
- package/dist/assets/renderMobileApp-D4dBBAqQ.js +0 -25
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +0 -27
- package/dist/assets/tr-CA9ckNnm.js +0 -7
- package/dist/assets/uk-byjR-y8D.js +0 -16
- package/dist/assets/useAppFontEffects-BWQZ5DeI.js +0 -7341
- package/dist/assets/useInlineCommentController-DlFyVfBu.js +0 -2
- package/dist/assets/vendor-opencode-client-DYdsLbCM.js +0 -12
- package/dist/assets/zh-CN-DRabgxdG.js +0 -16
- package/dist/assets/zh-TW-rbY5c9UK.js +0 -16
|
@@ -59,13 +59,21 @@ export const SPACE_SERVER_PORT = 27600;
|
|
|
59
59
|
|
|
60
60
|
export const SPACE_TOKEN_DIRECTORY = `${SPACE_HOME}/.openchamber-space`;
|
|
61
61
|
export const SPACE_TOKEN_PATH = `${SPACE_TOKEN_DIRECTORY}/token`;
|
|
62
|
+
// The idle stop's setting, which the host writes at every start and whenever the user changes it,
|
|
63
|
+
// and the exit code of a server inside that stopped itself for it. The code is how the host tells
|
|
64
|
+
// an idle stop from any other: a server stopped by `docker stop` exits 143. The agent can exit
|
|
65
|
+
// with it too, and all it changes then is the line under the group.
|
|
66
|
+
export const SPACE_IDLE_STOP_PATH = `${SPACE_TOKEN_DIRECTORY}/idle-stop.json`;
|
|
67
|
+
export const SPACE_IDLE_EXIT_CODE = 75;
|
|
62
68
|
|
|
63
69
|
// The gatekeeper, the space's only way out. It sits on the space's internal network under this
|
|
64
70
|
// name and on the space's own outer network, and nothing else joins either of them.
|
|
65
71
|
export const GATEKEEPER_ALIAS = 'gatekeeper';
|
|
66
|
-
// The two listeners the space may see. They bind
|
|
67
|
-
//
|
|
68
|
-
|
|
72
|
+
// The two listeners the space may see. They bind the gatekeeper's own address on the space's
|
|
73
|
+
// network and nothing else: on a Linux Docker host every local process can reach the bridge the
|
|
74
|
+
// outer network is, and a window listening there would spend the user's key for anyone on the
|
|
75
|
+
// machine. The address is known only once the container runs, so the host writes it into this
|
|
76
|
+
// file beside the program, and the container command names the file.
|
|
69
77
|
export const GATEKEEPER_CORRIDOR_PORT = 3128;
|
|
70
78
|
export const GATEKEEPER_WINDOW_PORT = 8080;
|
|
71
79
|
// The control channel. It binds the gatekeeper's own loopback, so only an `exec` from the host
|
|
@@ -74,14 +82,22 @@ export const GATEKEEPER_WINDOW_PORT = 8080;
|
|
|
74
82
|
export const GATEKEEPER_CONTROL_HOST = '127.0.0.1';
|
|
75
83
|
export const GATEKEEPER_CONTROL_PORT = 9099;
|
|
76
84
|
|
|
77
|
-
// Where the space sends its traffic
|
|
78
|
-
// belongs to whoever writes a provider configuration, which no stage does yet.
|
|
85
|
+
// Where the space sends its traffic: the corridor, and for a grant the window under that grant's id.
|
|
79
86
|
const GATEKEEPER_CORRIDOR_URL = `http://${GATEKEEPER_ALIAS}:${GATEKEEPER_CORRIDOR_PORT}`;
|
|
87
|
+
/** The URL inside the space that reaches a grant's upstream through the window. */
|
|
88
|
+
export const spaceWindowUrl = (grantId) => `http://${GATEKEEPER_ALIAS}:${GATEKEEPER_WINDOW_PORT}/model/${grantId}`;
|
|
80
89
|
|
|
81
90
|
// The gatekeeper's program arrives over `exec` on stdin, into the container's tmpfs. It is far
|
|
82
91
|
// larger than the tools filler, and a `node -e` argument of that size was never tried on Windows.
|
|
83
92
|
export const GATEKEEPER_PROGRAM_DIRECTORY = '/tmp/openchamber-gatekeeper';
|
|
84
93
|
export const GATEKEEPER_PROGRAM_PATH = `${GATEKEEPER_PROGRAM_DIRECTORY}/gatekeeper.cjs`;
|
|
94
|
+
export const GATEKEEPER_BIND_PATH = `${GATEKEEPER_PROGRAM_DIRECTORY}/bind`;
|
|
95
|
+
|
|
96
|
+
// OpenCode's global configuration inside a space, where the host writes the provider
|
|
97
|
+
// configuration that sends model calls through the window. The agent can change it; the
|
|
98
|
+
// gatekeeper is what enforces, this only cooperates.
|
|
99
|
+
export const SPACE_OPENCODE_CONFIG_DIRECTORY = `${SPACE_HOME}/.config/opencode`;
|
|
100
|
+
export const SPACE_OPENCODE_CONFIG_PATH = `${SPACE_OPENCODE_CONFIG_DIRECTORY}/opencode.json`;
|
|
85
101
|
|
|
86
102
|
const IMAGE_PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';
|
|
87
103
|
|
|
@@ -93,6 +109,8 @@ export const IMAGE_CAT = '/bin/cat';
|
|
|
93
109
|
export const IMAGE_CHOWN = '/bin/chown';
|
|
94
110
|
export const IMAGE_CURL = '/usr/bin/curl';
|
|
95
111
|
export const IMAGE_NODE = '/usr/local/bin/node';
|
|
112
|
+
// The setup commands of a project run in bash, as the host's worktrees run them.
|
|
113
|
+
export const IMAGE_BASH = '/bin/bash';
|
|
96
114
|
const IMAGE_SLEEP = '/bin/sleep';
|
|
97
115
|
// Code in: the receiving side of a push runs as `timeout -s KILL <seconds> git receive-pack <path>`.
|
|
98
116
|
// The image's git is 2.39.5, and it has no `pkill`.
|
|
@@ -132,6 +150,9 @@ export const SPACE_ENVIRONMENT = Object.freeze({
|
|
|
132
150
|
// The server inside a space never hosts the relay passively. It has a way out now, and a
|
|
133
151
|
// space must not become the machine that paired devices land on.
|
|
134
152
|
OPENCHAMBER_RELAY_HOST: 'off',
|
|
153
|
+
// Where the server inside reads the idle stop's setting. Only a space has this variable, so the
|
|
154
|
+
// timer never runs on the host.
|
|
155
|
+
OPENCHAMBER_SPACE_IDLE_STOP_FILE: SPACE_IDLE_STOP_PATH,
|
|
135
156
|
});
|
|
136
157
|
|
|
137
158
|
// Waits for the token file, takes it as the server password, and becomes the server.
|
|
@@ -194,7 +215,7 @@ const GATEKEEPER_CONTROL_CONNECTIONS = 8;
|
|
|
194
215
|
const GATEKEEPER_SCRIPT = [
|
|
195
216
|
`while [ ! -s ${GATEKEEPER_PROGRAM_PATH} ]; do ${IMAGE_SLEEP} 0.2; done;`,
|
|
196
217
|
`exec ${IMAGE_NODE} ${GATEKEEPER_PROGRAM_PATH}`,
|
|
197
|
-
|
|
218
|
+
GATEKEEPER_BIND_PATH,
|
|
198
219
|
String(GATEKEEPER_CORRIDOR_PORT),
|
|
199
220
|
String(GATEKEEPER_WINDOW_PORT),
|
|
200
221
|
String(GATEKEEPER_CONTROL_PORT),
|
|
@@ -26,7 +26,7 @@ describe('createSpaceManager', () => {
|
|
|
26
26
|
});
|
|
27
27
|
const { memoryBytes, ...listedFields } = space;
|
|
28
28
|
expect(memoryBytes).toBeGreaterThan(0);
|
|
29
|
-
expect(await manager.listSpaces({ placeId: 'memory' })).toEqual([{ ...listedFields, state: 'running', orphans: [], damaged: false, missing: [] }]);
|
|
29
|
+
expect(await manager.listSpaces({ placeId: 'memory' })).toEqual([{ ...listedFields, state: 'running', stoppedIdle: false, gatekeeperRunning: true, orphans: [], damaged: false, missing: [] }]);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('takes the id a caller announced before the creation, and refuses one that is not a space id', async () => {
|
|
@@ -62,7 +62,8 @@ export function runPlaceContractSuite(title, { enabled = true, setup }) {
|
|
|
62
62
|
|
|
63
63
|
it('lists the space as running, with what it was created with', async () => {
|
|
64
64
|
const { id, name, project, created } = spec;
|
|
65
|
-
|
|
65
|
+
// Stage 5d-3 added `stoppedIdle` and `gatekeeperRunning` to this shape; nothing else changed.
|
|
66
|
+
expect(await listed()).toEqual({ id, name, project, created, state: 'running', stoppedIdle: false, gatekeeperRunning: true, orphans: [], damaged: false, missing: [] });
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
it('refuses to create the same space again, and leaves it alone', async () => {
|
|
@@ -139,7 +140,8 @@ export function runPlaceContractSuite(title, { enabled = true, setup }) {
|
|
|
139
140
|
|
|
140
141
|
it('stops the space and lists it as exited', async () => {
|
|
141
142
|
await place.stop(spec.id);
|
|
142
|
-
|
|
143
|
+
// Since 5d-3: a stop by the host is not an idle stop, and it takes the gatekeeper down too.
|
|
144
|
+
expect(await listed()).toMatchObject({ state: 'exited', stoppedIdle: false, gatekeeperRunning: false });
|
|
143
145
|
});
|
|
144
146
|
|
|
145
147
|
// Added in stage 4a, for the same reason as the argv: a stopped space has no server to reach.
|
|
@@ -118,13 +118,21 @@ export function createLiveDockerPlace({ toolsSource = createRegistryToolsSource(
|
|
|
118
118
|
const crypto = require('node:crypto');
|
|
119
119
|
const hash = (value) => (value === undefined ? 'none' : 'sha256:' + crypto.createHash('sha256').update(String(value)).digest('hex'));
|
|
120
120
|
require('node:http').createServer((request, response) => {
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const seen = {
|
|
122
|
+
method: request.method,
|
|
123
123
|
path: request.url,
|
|
124
124
|
authorization: hash(request.headers.authorization),
|
|
125
125
|
apiKey: hash(request.headers['x-api-key']),
|
|
126
126
|
headerNames: Object.keys(request.headers).sort(),
|
|
127
|
-
}
|
|
127
|
+
};
|
|
128
|
+
// One line per request in the container's log, so the host can read what a client it does
|
|
129
|
+
// not control, OpenCode inside a space, sent here. Hashes only, as in the answer.
|
|
130
|
+
console.log('seen ' + JSON.stringify(seen));
|
|
131
|
+
request.resume();
|
|
132
|
+
request.on('end', () => {
|
|
133
|
+
response.writeHead(200, { 'content-type': 'application/json' });
|
|
134
|
+
response.end(JSON.stringify(seen));
|
|
135
|
+
});
|
|
128
136
|
}).listen(9000, '0.0.0.0', () => console.log('upstream listening'));
|
|
129
137
|
`;
|
|
130
138
|
await docker([
|
|
@@ -136,9 +144,24 @@ require('node:http').createServer((request, response) => {
|
|
|
136
144
|
await new Promise((resolve) => { setTimeout(resolve, 250); });
|
|
137
145
|
if ((await docker(['logs', name])).stdout.includes('upstream listening')) break;
|
|
138
146
|
}
|
|
139
|
-
return {
|
|
147
|
+
return {
|
|
148
|
+
url: 'http://upstream:9000/v1',
|
|
149
|
+
/** Every request this upstream has seen so far, oldest first, from its log. */
|
|
150
|
+
seen: async () => (await docker(['logs', name])).stdout.split('\n').filter((line) => line.startsWith('seen ')).map((line) => JSON.parse(line.slice(5))),
|
|
151
|
+
stop: () => docker(['rm', '--force', name]),
|
|
152
|
+
};
|
|
140
153
|
},
|
|
141
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Runs a Node script in a helper container on the space's outer network, where the stand-in
|
|
157
|
+
* upstream sits and where, on a Linux host, the host's own processes can reach. What such a
|
|
158
|
+
* neighbour can reach on the gatekeeper is what the gatekeeper's bind address decides.
|
|
159
|
+
*/
|
|
160
|
+
probeFromOuterNetwork: (spaceId, script) => docker(
|
|
161
|
+
['run', '--rm', ...helperLabels, '--network', spaceResourceName(spaceId, ROLE_OUTER_NETWORK), SPACE_BASE_IMAGE, 'node', '-e', script],
|
|
162
|
+
{ timeoutMs: 120_000 },
|
|
163
|
+
),
|
|
164
|
+
|
|
142
165
|
/**
|
|
143
166
|
* A name of our own in the space's outer network, answered by Docker's embedded resolver with
|
|
144
167
|
* an address in that bridge's subnet — a private range, and therefore one the corridor must
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
|
|
1
3
|
import { SpaceError } from '../errors.js';
|
|
2
4
|
import { createGatekeeperChannel } from '../gatekeeper-channel.js';
|
|
3
5
|
import {
|
|
@@ -25,7 +27,7 @@ import {
|
|
|
25
27
|
requireSpaceId,
|
|
26
28
|
spaceResourceName,
|
|
27
29
|
} from '../labels.js';
|
|
28
|
-
import { SPACE_CONNECT_COMMAND, SPACE_USER, TOOLS_MOUNT_PATH } from '../layout.js';
|
|
30
|
+
import { SPACE_CONNECT_COMMAND, SPACE_IDLE_EXIT_CODE, SPACE_USER, TOOLS_MOUNT_PATH } from '../layout.js';
|
|
29
31
|
import { openCommandStream as openCommandStreamProcess } from '../run-command.js';
|
|
30
32
|
import { createSpaceServerChannel, createSpaceToken } from '../space-server.js';
|
|
31
33
|
import { CHANGE_TIMEOUT_MS, ROLLBACK_SETTLE_MS, createDockerEngine, entryLabels, entryName, isInterrupted, pause } from './docker-engine.js';
|
|
@@ -234,11 +236,18 @@ export function createDockerPlace({ runCommand, openCommandStream = openCommandS
|
|
|
234
236
|
/**
|
|
235
237
|
* Runs argv as the space user in the space or, with `target: 'gatekeeper'`, in its gatekeeper.
|
|
236
238
|
* It does not look at the container first, so it also serves containers this place just made.
|
|
239
|
+
* `maxOutputBytes`, `keepTail` and `killTree` go to `runCommand` as they are; the setup
|
|
240
|
+
* commands use them for a long command whose output is shown and whose exit code is the answer.
|
|
237
241
|
*/
|
|
238
242
|
const execInContainer = (spaceId, argv, options = {}) => run(
|
|
239
243
|
['exec', '--interactive', '--user', SPACE_USER, spaceResourceName(spaceId, execRole(options.target)), ...argv],
|
|
240
244
|
options.timeoutMs ?? EXEC_TIMEOUT_MS,
|
|
241
|
-
{
|
|
245
|
+
{
|
|
246
|
+
stdin: options.stdin ?? '',
|
|
247
|
+
...(options.maxOutputBytes === undefined ? {} : { maxOutputBytes: options.maxOutputBytes }),
|
|
248
|
+
...(options.keepTail === true ? { keepTail: true } : {}),
|
|
249
|
+
...(options.killTree === true ? { killTree: true } : {}),
|
|
250
|
+
},
|
|
242
251
|
);
|
|
243
252
|
|
|
244
253
|
const server = createSpaceServerChannel({ exec: execInContainer, wait, now: () => now().getTime() });
|
|
@@ -308,7 +317,7 @@ export function createDockerPlace({ runCommand, openCommandStream = openCommandS
|
|
|
308
317
|
await docker(['network', 'connect', outerNetwork, gatekeeperName], CHANGE_TIMEOUT_MS);
|
|
309
318
|
await requireGatekeeperVerified(id, await inspectOwnContainer(id, gatekeeperName) ?? {});
|
|
310
319
|
await docker(['start', gatekeeperName], CHANGE_TIMEOUT_MS);
|
|
311
|
-
await gatekeeper.writeProgram(id);
|
|
320
|
+
await gatekeeper.writeProgram(id, { bindAddress: await innerAddressOf(id) });
|
|
312
321
|
await gatekeeper.waitUntilReady(id);
|
|
313
322
|
// Create, verify, then start: a container that fails the check never runs.
|
|
314
323
|
await docker(buildSpaceCreateArgs({
|
|
@@ -382,13 +391,31 @@ export function createDockerPlace({ runCommand, openCommandStream = openCommandS
|
|
|
382
391
|
if (space && (!guard || (state === 'running' && guard.entry.State?.Running !== true))) {
|
|
383
392
|
missing.push(spaceResourceName(id, ROLE_GATEKEEPER));
|
|
384
393
|
}
|
|
385
|
-
|
|
394
|
+
// Since 5d-3: a space that stopped itself for the idle stop, told by its exit code, and whether
|
|
395
|
+
// its gatekeeper still runs, which the host stops when it finds one beside a stopped space.
|
|
396
|
+
const stoppedIdle = state === 'exited' && space.entry.State?.ExitCode === SPACE_IDLE_EXIT_CODE;
|
|
397
|
+
const gatekeeperRunning = guard?.entry.State?.Running === true;
|
|
398
|
+
return { id, name, project, created, state, stoppedIdle, gatekeeperRunning, orphans, damaged: missing.length > 0, missing };
|
|
386
399
|
});
|
|
387
400
|
};
|
|
388
401
|
|
|
389
402
|
// Starts that are under way in this process, by space id.
|
|
390
403
|
const starting = new Map();
|
|
391
404
|
|
|
405
|
+
/**
|
|
406
|
+
* The gatekeeper's own address on the space's inner network, read from the runtime once the
|
|
407
|
+
* container runs: that is where its corridor and window listen, and nowhere else. An engine
|
|
408
|
+
* that reports none leaves the gatekeeper unstarted, which is the safe answer.
|
|
409
|
+
*/
|
|
410
|
+
const innerAddressOf = async (spaceId) => {
|
|
411
|
+
const entry = await inspectOwnContainer(spaceId, spaceResourceName(spaceId, ROLE_GATEKEEPER));
|
|
412
|
+
const address = String(entry?.NetworkSettings?.Networks?.[spaceResourceName(spaceId, ROLE_NETWORK)]?.IPAddress ?? '');
|
|
413
|
+
if (net.isIP(address) === 0) {
|
|
414
|
+
throw new SpaceError('gatekeeper_address_unknown', `The runtime reports no address for the network filter of space ${spaceId} on the space's network, so its listeners cannot be bound.`);
|
|
415
|
+
}
|
|
416
|
+
return address;
|
|
417
|
+
};
|
|
418
|
+
|
|
392
419
|
/** The gatekeeper container of a space. It is never renamed, so there is no move to repair here. */
|
|
393
420
|
const requireGatekeeperContainer = async (spaceId) => {
|
|
394
421
|
const name = spaceResourceName(spaceId, ROLE_GATEKEEPER);
|
|
@@ -468,7 +495,7 @@ export function createDockerPlace({ runCommand, openCommandStream = openCommandS
|
|
|
468
495
|
await requireGatekeeperVerified(spaceId, container);
|
|
469
496
|
await docker(['start', name], CHANGE_TIMEOUT_MS);
|
|
470
497
|
}
|
|
471
|
-
await gatekeeper.writeProgram(spaceId);
|
|
498
|
+
await gatekeeper.writeProgram(spaceId, { bindAddress: await innerAddressOf(spaceId) });
|
|
472
499
|
await gatekeeper.waitUntilReady(spaceId);
|
|
473
500
|
};
|
|
474
501
|
|
|
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
3
3
|
import { SpaceError } from '../errors.js';
|
|
4
4
|
import { GATEKEEPER_PROGRAM } from '../gatekeeper-channel.js';
|
|
5
5
|
import { buildSpaceLabels, buildToolsLabels, hashProjectDirectory } from '../labels.js';
|
|
6
|
-
import { SPACE_CONNECT_COMMAND, SPACE_ENVIRONMENT, SPACE_SERVER_COMMAND } from '../layout.js';
|
|
6
|
+
import { SPACE_CONNECT_COMMAND, SPACE_ENVIRONMENT, SPACE_IDLE_EXIT_CODE, SPACE_SERVER_COMMAND } from '../layout.js';
|
|
7
7
|
import { createRegistryToolsSource, toolsContentKey } from '../tools.js';
|
|
8
8
|
import { SPACE_BASE_IMAGE, createDockerPlace } from './docker.js';
|
|
9
9
|
import { bridgeNetworkEntry, createFakeDocker, hardenedContainerEntry, internalNetworkEntry } from './fake-docker.js';
|
|
@@ -234,6 +234,7 @@ describe('docker place: create', () => {
|
|
|
234
234
|
'--env', 'OPENCODE_DISABLE_MODELS_FETCH=1',
|
|
235
235
|
'--env', 'OPENCODE_DISABLE_AUTOUPDATE=1',
|
|
236
236
|
'--env', 'OPENCHAMBER_RELAY_HOST=off',
|
|
237
|
+
'--env', 'OPENCHAMBER_SPACE_IDLE_STOP_FILE=/home/space/.openchamber-space/idle-stop.json',
|
|
237
238
|
SPACE_BASE_IMAGE,
|
|
238
239
|
'/bin/sh', '-c',
|
|
239
240
|
'while [ ! -s /home/space/.openchamber-space/token ]; do /bin/sleep 0.2; done; OPENCHAMBER_UI_PASSWORD="$(/bin/cat /home/space/.openchamber-space/token)"; export OPENCHAMBER_UI_PASSWORD; exec openchamber serve --foreground --api-only --host 127.0.0.1 --port 27600',
|
|
@@ -272,13 +273,21 @@ describe('docker place: create', () => {
|
|
|
272
273
|
'--env', 'HOME=/tmp',
|
|
273
274
|
SPACE_BASE_IMAGE,
|
|
274
275
|
'/bin/sh', '-c',
|
|
275
|
-
|
|
276
|
+
// The bind host is the file the host writes after the start, holding the gatekeeper's own
|
|
277
|
+
// address on the space's network, never every interface: see "Known limits" of stage 2.
|
|
278
|
+
'while [ ! -s /tmp/openchamber-gatekeeper/gatekeeper.cjs ]; do /bin/sleep 0.2; done; exec /usr/local/bin/node /tmp/openchamber-gatekeeper/gatekeeper.cjs /tmp/openchamber-gatekeeper/bind 3128 8080 9099 300000 128 64 8',
|
|
276
279
|
]);
|
|
277
280
|
expect(create).toContain('openchamber.space.role=gatekeeper');
|
|
278
281
|
expect(create).not.toContain('--mount');
|
|
279
282
|
// The program travels on stdin, so it is in no argument list, and no secret is in one either.
|
|
280
283
|
const write = fake.calls.find((call) => isExec('gatekeeper.cjs.new')(call.args));
|
|
281
284
|
expect(write.options.stdin).toBe(GATEKEEPER_PROGRAM);
|
|
285
|
+
// The address the fake engine gives the gatekeeper on the inner network, read after the start
|
|
286
|
+
// and written into the bind file before the program.
|
|
287
|
+
expect(write.args.slice(-2)).toEqual(['sh', '172.19.0.2']);
|
|
288
|
+
expect(write.args.join(' ')).toContain('> /tmp/openchamber-gatekeeper/bind.new && mv /tmp/openchamber-gatekeeper/bind.new /tmp/openchamber-gatekeeper/bind && cat > /tmp/openchamber-gatekeeper/gatekeeper.cjs.new');
|
|
289
|
+
const order = fake.calls.map((call) => describeCall(call.args));
|
|
290
|
+
expect(order.indexOf(`start ${GATEKEEPER}`)).toBeLessThan(order.indexOf('exec write program'));
|
|
282
291
|
expect(write.args[4]).toBe(GATEKEEPER);
|
|
283
292
|
});
|
|
284
293
|
|
|
@@ -383,6 +392,16 @@ describe('docker place: create', () => {
|
|
|
383
392
|
}
|
|
384
393
|
});
|
|
385
394
|
|
|
395
|
+
it('passes the output window and the tree kill of an exec to the runner, and nothing it was not given', async () => {
|
|
396
|
+
const fake = createFakeDocker();
|
|
397
|
+
const place = makePlace(fake);
|
|
398
|
+
await place.create(SPEC);
|
|
399
|
+
await place.exec(SPEC.id, ['/bin/true'], { timeoutMs: 5_000, maxOutputBytes: 1024, keepTail: true, killTree: true });
|
|
400
|
+
expect(fake.calls.at(-1).options).toEqual({ stdin: '', timeoutMs: 5_000, maxOutputBytes: 1024, keepTail: true, killTree: true });
|
|
401
|
+
await place.exec(SPEC.id, ['/bin/true']);
|
|
402
|
+
expect(fake.calls.at(-1).options).toEqual({ stdin: '', timeoutMs: 60_000 });
|
|
403
|
+
});
|
|
404
|
+
|
|
386
405
|
it('refuses when a resource with the same name exists, and touches nothing', async () => {
|
|
387
406
|
const stranger = { kind: 'volume', name: WORK, entry: { Name: WORK, Labels: null } };
|
|
388
407
|
const fake = createFakeDocker({ resources: [stranger] });
|
|
@@ -608,9 +627,9 @@ describe('docker place: list', () => {
|
|
|
608
627
|
|
|
609
628
|
const spaces = await makePlace(fake).list();
|
|
610
629
|
expect(spaces).toEqual([
|
|
611
|
-
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', orphans: [], damaged: false, missing: [] },
|
|
612
|
-
{ id: '111111111111', name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'exited', orphans: [], damaged: false, missing: [] },
|
|
613
|
-
{ id: orphanId, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'missing', orphans: [{ kind: 'volume', name: orphanVolume }], damaged: false, missing: [] },
|
|
630
|
+
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', stoppedIdle: false, gatekeeperRunning: true, orphans: [], damaged: false, missing: [] },
|
|
631
|
+
{ id: '111111111111', name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'exited', stoppedIdle: false, gatekeeperRunning: false, orphans: [], damaged: false, missing: [] },
|
|
632
|
+
{ id: orphanId, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'missing', stoppedIdle: false, gatekeeperRunning: false, orphans: [{ kind: 'volume', name: orphanVolume }], damaged: false, missing: [] },
|
|
614
633
|
]);
|
|
615
634
|
});
|
|
616
635
|
|
|
@@ -618,14 +637,14 @@ describe('docker place: list', () => {
|
|
|
618
637
|
const fake = createFakeDocker({ resources: spaceResources().filter((resource) => resource.name !== HOME && resource.kind !== 'network') });
|
|
619
638
|
|
|
620
639
|
expect(await makePlace(fake).list()).toEqual([
|
|
621
|
-
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', orphans: [], damaged: true, missing: [NETWORK, OUTER_NETWORK, HOME] },
|
|
640
|
+
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', stoppedIdle: false, gatekeeperRunning: true, orphans: [], damaged: true, missing: [NETWORK, OUTER_NETWORK, HOME] },
|
|
622
641
|
]);
|
|
623
642
|
});
|
|
624
643
|
|
|
625
644
|
it('flags a running space whose gatekeeper is gone, or does not run, as damaged and not as missing', async () => {
|
|
626
645
|
const withoutGatekeeper = createFakeDocker({ resources: spaceResources().filter((resource) => resource.name !== GATEKEEPER) });
|
|
627
646
|
expect(await makePlace(withoutGatekeeper).list()).toEqual([
|
|
628
|
-
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', orphans: [], damaged: true, missing: [GATEKEEPER] },
|
|
647
|
+
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', stoppedIdle: false, gatekeeperRunning: false, orphans: [], damaged: true, missing: [GATEKEEPER] },
|
|
629
648
|
]);
|
|
630
649
|
|
|
631
650
|
// The space runs and its way out does not. For the space that is as good as no gatekeeper.
|
|
@@ -639,6 +658,17 @@ describe('docker place: list', () => {
|
|
|
639
658
|
expect(await makePlace(bothStopped).list()).toMatchObject([{ state: 'exited', damaged: false, missing: [] }]);
|
|
640
659
|
});
|
|
641
660
|
|
|
661
|
+
it('tells a space that stopped itself for the idle stop by its exit code, and a gatekeeper left running beside it', async () => {
|
|
662
|
+
const seeds = spaceResources();
|
|
663
|
+
const space = seeds.find((resource) => resource.kind === 'container' && resource.name === `openchamber-space-${ID}-space`);
|
|
664
|
+
space.entry.State = { Running: false, Status: 'exited', ExitCode: SPACE_IDLE_EXIT_CODE };
|
|
665
|
+
expect(await makePlace(createFakeDocker({ resources: seeds })).list()).toMatchObject([{ state: 'exited', stoppedIdle: true, gatekeeperRunning: true, damaged: false, missing: [] }]);
|
|
666
|
+
|
|
667
|
+
// Stopped by `docker stop`: the server ends on SIGTERM with 143, which is no idle stop.
|
|
668
|
+
space.entry.State = { Running: false, Status: 'exited', ExitCode: 143 };
|
|
669
|
+
expect(await makePlace(createFakeDocker({ resources: seeds })).list()).toMatchObject([{ state: 'exited', stoppedIdle: false }]);
|
|
670
|
+
});
|
|
671
|
+
|
|
642
672
|
it('still lists the other spaces when a resource vanishes between the listing and the inspect', async () => {
|
|
643
673
|
const fake = createFakeDocker({ resources: [...spaceResources(), ...spaceResources({ id: '111111111111' })] });
|
|
644
674
|
const runCommand = async (file, args, options) => {
|
|
@@ -1368,7 +1398,7 @@ describe('docker place: new tools at the next start', () => {
|
|
|
1368
1398
|
expect(fake.token(CONTAINER)).toBe('seeded-token');
|
|
1369
1399
|
expect(await place.verify(ID)).toEqual([]);
|
|
1370
1400
|
expect(await place.list()).toEqual([
|
|
1371
|
-
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', orphans: [], damaged: false, missing: [] },
|
|
1401
|
+
{ id: ID, name: SPEC.name, project: SPEC.project, created: SPEC.created, state: 'running', stoppedIdle: false, gatekeeperRunning: true, orphans: [], damaged: false, missing: [] },
|
|
1372
1402
|
]);
|
|
1373
1403
|
const create = fake.calls.map((call) => call.args).find((args) => args[0] === 'create');
|
|
1374
1404
|
expect(create[create.indexOf('--memory') + 1]).toBe('4294967296');
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// spaceMetadata(spaceId) resolves, as text, everything the place's own records show about the space container
|
|
11
11
|
// gatekeeperMetadata(spaceId) the same for the gatekeeper container
|
|
12
12
|
// gatekeeperAddresses(spaceId) resolves { inner, outer }, the gatekeeper's own addresses
|
|
13
|
+
// probeFromOuterNetwork(spaceId, script) runs a Node script in a helper on the space's outer network
|
|
13
14
|
// startWindowUpstream(spaceId) a stand-in provider on the space's outer network. It answers with
|
|
14
15
|
// the sha256 of the credentials it saw, never with the credentials
|
|
15
16
|
|
|
@@ -829,6 +830,37 @@ export function runEscapeSuite(title, { enabled = true, setup }) {
|
|
|
829
830
|
expect(JSON.stringify(journal)).not.toContain(MODEL_KEY);
|
|
830
831
|
}, 120_000);
|
|
831
832
|
|
|
833
|
+
// The obligation of STAGES.md on the first real credential behind the window: on a Linux
|
|
834
|
+
// Docker host every local process can reach the outer bridge, so the corridor and the
|
|
835
|
+
// window listen on the gatekeeper's inner address only. A neighbour on the outer network
|
|
836
|
+
// stands in for such a process here; the same measurement from a Linux host itself is in
|
|
837
|
+
// the module documentation.
|
|
838
|
+
it('cannot be reached on its outer address: the corridor and the window listen on the inner network only', async () => {
|
|
839
|
+
const addresses = await host.gatekeeperAddresses(spec.id);
|
|
840
|
+
expect(addresses.outer).toMatch(/^\d+\.\d+\.\d+\.\d+$/);
|
|
841
|
+
const fromOutside = async (address, port) => (await host.probeFromOuterNetwork(spec.id, tcpProbe(address, port))).stdout.trim();
|
|
842
|
+
// Positive control: the neighbour's networking works, it reaches the stand-in upstream beside it.
|
|
843
|
+
expect(await fromOutside('upstream', 9000)).toMatch(/^connected:/);
|
|
844
|
+
for (const port of [GATEKEEPER_CORRIDOR_PORT, GATEKEEPER_WINDOW_PORT, GATEKEEPER_CONTROL_PORT]) {
|
|
845
|
+
expect(await fromOutside(addresses.outer, port), `outer address, port ${port}`).toBe('failed:ECONNREFUSED');
|
|
846
|
+
}
|
|
847
|
+
// And the space still reaches both by the gatekeeper's name, which resolves to the inner address.
|
|
848
|
+
expect(await probe(tcpProbe(GATEKEEPER_ALIAS, GATEKEEPER_CORRIDOR_PORT))).toBe(`connected:${addresses.inner}`);
|
|
849
|
+
expect(await probe(tcpProbe(GATEKEEPER_ALIAS, GATEKEEPER_WINDOW_PORT))).toBe(`connected:${addresses.inner}`);
|
|
850
|
+
}, 180_000);
|
|
851
|
+
|
|
852
|
+
it('gets no credential from the window for an opened domain, and none of its own reaches the upstream', async () => {
|
|
853
|
+
await channel().addGrant(spec.id, { id: 'open-registry', upstream: upstream.url });
|
|
854
|
+
const answer = await probe(windowProbe('/model/open-registry/-/package/left-pad', { 'x-api-key': 'sk-fake-inside', authorization: 'Bearer sk-fake-inside' }));
|
|
855
|
+
expect(answer).toMatch(/^200 /);
|
|
856
|
+
const seen = JSON.parse(answer.slice(4));
|
|
857
|
+
expect(seen.path).toBe('/v1/-/package/left-pad');
|
|
858
|
+
expect(seen.apiKey).toBe('none');
|
|
859
|
+
expect(seen.authorization).toBe('none');
|
|
860
|
+
expect(seen.headerNames.filter((name) => /key|auth|token/i.test(name))).toEqual([]);
|
|
861
|
+
expect(answer).not.toContain(MODEL_KEY);
|
|
862
|
+
}, 120_000);
|
|
863
|
+
|
|
832
864
|
it('reaches a real upstream over TLS, with no credential of anyone\'s', async () => {
|
|
833
865
|
publicAddress();
|
|
834
866
|
await channel().addGrant(spec.id, { id: 'tls', upstream: 'https://example.com/', header: 'authorization', secret: 'not-a-credential' });
|
|
@@ -96,7 +96,9 @@ export function hardenedContainerEntry({
|
|
|
96
96
|
PortBindings: {},
|
|
97
97
|
},
|
|
98
98
|
Mounts: mountList.map(volumeMountEntry),
|
|
99
|
-
|
|
99
|
+
// Like the real engine once the container runs: an address on its network. The fake gives it
|
|
100
|
+
// from the start, and the place's tests hold it to reading the address after the start.
|
|
101
|
+
NetworkSettings: { Networks: { [network]: { IPAddress: '172.19.0.2', ...(aliases.length > 0 ? { Aliases: aliases } : {}) } } },
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Grants on a real space, made through the journey on a real Docker daemon. Runs only with
|
|
2
|
+
// OPENCHAMBER_TEST_DOCKER=1. A real key goes behind the window of a space made through the
|
|
3
|
+
// journey's own routes; a stand-in provider on the space's outer network answers with the hash
|
|
4
|
+
// of the key it saw and never with the key; and the key is then looked for everywhere the host
|
|
5
|
+
// and the space keep things: the record on disk, the metadata of both containers, the space's
|
|
6
|
+
// environment, processes and files. OpenCode inside is asked for a turn against that provider,
|
|
7
|
+
// which proves that the provider configuration the host wrote sends it through the window.
|
|
8
|
+
|
|
9
|
+
import crypto from 'node:crypto';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import http from 'node:http';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
import express from 'express';
|
|
16
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
17
|
+
|
|
18
|
+
import { createGlobalMessageStreamHub } from '../../event-stream/global-hub.js';
|
|
19
|
+
import { registerOpenCodeProxy } from '../../opencode/proxy.js';
|
|
20
|
+
import { runCommand } from '../run-command.js';
|
|
21
|
+
import { createSpacesHost } from '../host.js';
|
|
22
|
+
import { SPACE_OPENCODE_CONFIG_PATH } from '../layout.js';
|
|
23
|
+
import { LIVE_DOCKER_ENABLED, createLiveDockerPlace } from './docker-live-support.js';
|
|
24
|
+
|
|
25
|
+
const CREATE_TIMEOUT_MS = 25 * 60_000;
|
|
26
|
+
const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
27
|
+
const until = async (check, timeoutMs = 10_000) => {
|
|
28
|
+
const deadline = Date.now() + timeoutMs;
|
|
29
|
+
while (!(await check()) && Date.now() < deadline) await sleep(250);
|
|
30
|
+
return check();
|
|
31
|
+
};
|
|
32
|
+
const listen = (app) => new Promise((resolve) => {
|
|
33
|
+
const server = http.createServer(app);
|
|
34
|
+
server.listen(0, '127.0.0.1', () => resolve(server));
|
|
35
|
+
});
|
|
36
|
+
const sha256 = (value) => `sha256:${crypto.createHash('sha256').update(value).digest('hex')}`;
|
|
37
|
+
const temporary = (prefix) => fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
38
|
+
|
|
39
|
+
describe.skipIf(!LIVE_DOCKER_ENABLED)('grants on a real space: docker (live)', () => {
|
|
40
|
+
// Two real keys, made here. Neither ever enters the space; the stand-in provider sees them.
|
|
41
|
+
const TYPED_KEY = `sk-ant-live-${crypto.randomBytes(24).toString('hex')}`;
|
|
42
|
+
const ENV_KEY = `sk-oai-live-${crypto.randomBytes(24).toString('hex')}`;
|
|
43
|
+
let place;
|
|
44
|
+
let dispose = async () => {};
|
|
45
|
+
let liveHost;
|
|
46
|
+
let dataDir;
|
|
47
|
+
let project;
|
|
48
|
+
let host;
|
|
49
|
+
let hub;
|
|
50
|
+
let hostOpenCode;
|
|
51
|
+
let server;
|
|
52
|
+
let spaceId;
|
|
53
|
+
let upstream = { seen: async () => [], stop: async () => {} };
|
|
54
|
+
let session = null;
|
|
55
|
+
const url = (suffix) => `http://127.0.0.1:${server.address().port}${suffix}`;
|
|
56
|
+
const inside = async (argv) => place.exec(spaceId, argv, { timeoutMs: 60_000 });
|
|
57
|
+
const shell = (script) => inside(['sh', '-c', script]);
|
|
58
|
+
const prefixed = (suffix, init) => fetch(url(`/api/spaces/${spaceId}${suffix}`), init);
|
|
59
|
+
const json = (body) => ({ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
60
|
+
const listed = async () => (await host.journey.listSpaces({ access: true })).find((space) => space.id === spaceId);
|
|
61
|
+
const recordText = () => fs.readFileSync(path.join(dataDir, 'spaces', 'records', `${spaceId}.json`), 'utf8');
|
|
62
|
+
|
|
63
|
+
beforeAll(async () => {
|
|
64
|
+
({ place, dispose, host: liveHost } = createLiveDockerPlace());
|
|
65
|
+
dataDir = temporary('openchamber-grants-live-');
|
|
66
|
+
// The registered project the space is made for: a small repository of its own.
|
|
67
|
+
project = temporary('openchamber-grants-project-');
|
|
68
|
+
const git = (...args) => runCommand('git', ['-C', project, ...args]);
|
|
69
|
+
await git('init', '-q', '.');
|
|
70
|
+
fs.writeFileSync(path.join(project, 'README.md'), 'A project for the grants live pass.\n');
|
|
71
|
+
await git('add', '.');
|
|
72
|
+
await git('-c', 'user.email=me@example.invalid', '-c', 'user.name=Me', 'commit', '-q', '-m', 'init');
|
|
73
|
+
|
|
74
|
+
host = createSpacesHost({
|
|
75
|
+
dataDir,
|
|
76
|
+
place,
|
|
77
|
+
listProjectDirectories: async () => [project],
|
|
78
|
+
hostEnvironment: { ...process.env, OPENAI_API_KEY: ENV_KEY },
|
|
79
|
+
logger: { warn: () => {} },
|
|
80
|
+
});
|
|
81
|
+
// The host's own OpenCode: nothing but an event stream that stays open.
|
|
82
|
+
const hostApp = express();
|
|
83
|
+
hostApp.get('/api/session', (_req, res) => res.json({ data: [], cursor: {} }));
|
|
84
|
+
hostApp.get('/api/event', (_req, res) => { res.setHeader('content-type', 'text/event-stream'); res.flushHeaders(); });
|
|
85
|
+
hostOpenCode = await listen(hostApp);
|
|
86
|
+
const hostPort = hostOpenCode.address().port;
|
|
87
|
+
hub = createGlobalMessageStreamHub({ buildOpenCodeUrl: (p) => `http://127.0.0.1:${hostPort}${p}`, getOpenCodeAuthHeaders: () => ({}), deltaCoalesceWindowMs: 0 });
|
|
88
|
+
const app = express();
|
|
89
|
+
app.use(host.middleware);
|
|
90
|
+
registerOpenCodeProxy(app, {
|
|
91
|
+
fs: {}, os: {}, path, OPEN_CODE_READY_GRACE_MS: 0,
|
|
92
|
+
getRuntime: () => ({ openCodePort: hostPort, isOpenCodeReady: true, openCodeNotReadySince: 0, isRestartingOpenCode: false }),
|
|
93
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
94
|
+
buildOpenCodeUrl: (p) => `http://127.0.0.1:${hostPort}${p}`,
|
|
95
|
+
ensureOpenCodeApiPrefix: () => {},
|
|
96
|
+
mergeSpaceSessionList: (payload) => host.mergeSessionList(payload),
|
|
97
|
+
spaceEventHub: hub,
|
|
98
|
+
});
|
|
99
|
+
server = await listen(app);
|
|
100
|
+
await host.startEvents(hub);
|
|
101
|
+
|
|
102
|
+
// The space, through the journey, as the create dialog will make it.
|
|
103
|
+
const answer = await host.journey.createSpace({ projectDirectory: project, name: 'Grants live', start: 'clean', network: { mode: 'allowlist', domains: [] } });
|
|
104
|
+
spaceId = answer.id;
|
|
105
|
+
expect(await until(async () => (await listed())?.state === 'running' && (await listed())?.step === null, CREATE_TIMEOUT_MS)).toBe(true);
|
|
106
|
+
upstream = await liveHost.startWindowUpstream(spaceId);
|
|
107
|
+
}, CREATE_TIMEOUT_MS);
|
|
108
|
+
|
|
109
|
+
afterAll(async () => {
|
|
110
|
+
host?.close();
|
|
111
|
+
hub?.stop();
|
|
112
|
+
for (const running of [server, hostOpenCode]) {
|
|
113
|
+
await new Promise((resolve) => { if (running) { running.closeAllConnections?.(); running.close(() => resolve()); } else resolve(); });
|
|
114
|
+
}
|
|
115
|
+
await upstream.stop();
|
|
116
|
+
await dispose();
|
|
117
|
+
for (const folder of [dataDir, project]) if (folder) fs.rmSync(folder, { recursive: true, force: true });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('gives a typed key to the gatekeeper and keeps it out of the record, the containers and the space', async () => {
|
|
121
|
+
const granted = await host.journey.grantAccess(spaceId, { kind: 'model', provider: 'anthropic', upstream: upstream.url, secret: { kind: 'typed', value: TYPED_KEY } });
|
|
122
|
+
expect(granted.grant).toMatchObject({ id: 'anthropic', header: 'x-api-key', source: { kind: 'typed' }, url: 'http://gatekeeper:8080/model/anthropic' });
|
|
123
|
+
expect(JSON.stringify(granted)).not.toContain(TYPED_KEY);
|
|
124
|
+
|
|
125
|
+
// The window carries the real key: a request from inside reaches the stand-in with its hash.
|
|
126
|
+
const through = await shell('curl -s -H "x-api-key: space-window" http://gatekeeper:8080/model/anthropic/messages');
|
|
127
|
+
expect(through.code, through.stderr).toBe(0);
|
|
128
|
+
expect(JSON.parse(through.stdout)).toMatchObject({ path: '/v1/messages', apiKey: sha256(TYPED_KEY), authorization: 'none' });
|
|
129
|
+
|
|
130
|
+
// Not on the host's disk.
|
|
131
|
+
expect(recordText()).not.toContain(TYPED_KEY);
|
|
132
|
+
expect(JSON.parse(recordText()).grants).toEqual([{ kind: 'model', id: 'anthropic', provider: 'anthropic', upstream: upstream.url, header: 'x-api-key', source: { kind: 'typed' } }]);
|
|
133
|
+
// Not in what the runtime records about either container.
|
|
134
|
+
expect(await liveHost.spaceMetadata(spaceId)).not.toContain(TYPED_KEY);
|
|
135
|
+
expect(await liveHost.gatekeeperMetadata(spaceId)).not.toContain(TYPED_KEY);
|
|
136
|
+
// Not anywhere the space can look. The space prints what it has; the host searches it.
|
|
137
|
+
const insideTheSpace = await shell(`env; ps auxeww; find /home/space /tmp /spaces/${spaceId} -type f -size -1M -exec cat {} + 2>/dev/null; true`);
|
|
138
|
+
expect(insideTheSpace.stdout.length).toBeGreaterThan(0);
|
|
139
|
+
expect(insideTheSpace.stdout).not.toContain(TYPED_KEY);
|
|
140
|
+
// What the space does have: the configuration that points OpenCode at the window.
|
|
141
|
+
const config = JSON.parse((await inside(['cat', SPACE_OPENCODE_CONFIG_PATH])).stdout);
|
|
142
|
+
expect(config.provider.anthropic.options).toEqual({ baseURL: 'http://gatekeeper:8080/model/anthropic', apiKey: 'space-window' });
|
|
143
|
+
expect((await listed())).toMatchObject({ access: 'granted', needsAccess: [], grants: [expect.objectContaining({ id: 'anthropic' })] });
|
|
144
|
+
}, 120_000);
|
|
145
|
+
|
|
146
|
+
it('sends a turn of OpenCode inside through the window, where the stand-in sees the real key', async () => {
|
|
147
|
+
const directory = (await listed()).directory;
|
|
148
|
+
const created = await prefixed('/session', json({ location: { directory }, title: 'Through the window' }));
|
|
149
|
+
expect(created.status, await created.clone().text()).toBe(200);
|
|
150
|
+
session = (await created.json()).data;
|
|
151
|
+
const model = await prefixed(`/session/${session.id}/model`, { ...json({ model: { id: 'claude-sonnet-4-5', providerID: 'anthropic' } }), headers: { 'content-type': 'application/json', 'x-opencode-directory': encodeURIComponent(directory) } });
|
|
152
|
+
expect(model.status, await model.clone().text()).toBeLessThan(300);
|
|
153
|
+
const prompt = await prefixed(`/session/${session.id}/prompt`, { ...json({ id: `msg_${crypto.randomBytes(8).toString('hex')}`, text: 'Say hello.' }), headers: { 'content-type': 'application/json', 'x-opencode-directory': encodeURIComponent(directory) } });
|
|
154
|
+
expect(prompt.status, await prompt.clone().text()).toBeLessThan(300);
|
|
155
|
+
|
|
156
|
+
// A POST: the curl of the test above was a GET with the same key, and this must be OpenCode's own request.
|
|
157
|
+
const fromOpenCode = (entry) => entry.method === 'POST' && entry.apiKey === sha256(TYPED_KEY) && entry.path.startsWith('/v1/messages');
|
|
158
|
+
expect(await until(async () => (await upstream.seen()).some(fromOpenCode), 120_000)).toBe(true);
|
|
159
|
+
expect((await upstream.seen()).find(fromOpenCode)).toMatchObject({ authorization: 'none' });
|
|
160
|
+
expect(JSON.stringify(await upstream.seen())).not.toContain(TYPED_KEY);
|
|
161
|
+
}, 180_000);
|
|
162
|
+
|
|
163
|
+
it('measures whether OpenCode inside takes a provider granted after its instance started', async () => {
|
|
164
|
+
// A second provider, from the host's environment this time, granted while the instance of
|
|
165
|
+
// the space's project is already running. Whether that instance re-reads its configuration
|
|
166
|
+
// without a restart is what this measures; the outcome is reported, not asserted, because
|
|
167
|
+
// either way the key is out of the space and the window is the only way to the provider.
|
|
168
|
+
const granted = await host.journey.grantAccess(spaceId, { kind: 'model', provider: 'openai', upstream: upstream.url, secret: { kind: 'env', name: 'OPENAI_API_KEY' } });
|
|
169
|
+
expect(granted.grant).toMatchObject({ id: 'openai', header: 'authorization', source: { kind: 'env', name: 'OPENAI_API_KEY' } });
|
|
170
|
+
expect(recordText()).not.toContain(ENV_KEY);
|
|
171
|
+
const directory = (await listed()).directory;
|
|
172
|
+
const headers = { 'content-type': 'application/json', 'x-opencode-directory': encodeURIComponent(directory) };
|
|
173
|
+
await prefixed(`/session/${session.id}/model`, { ...json({ model: { id: 'gpt-4.1', providerID: 'openai' } }), headers });
|
|
174
|
+
await prefixed(`/session/${session.id}/prompt`, { ...json({ id: `msg_${crypto.randomBytes(8).toString('hex')}`, text: 'Say hello again.' }), headers });
|
|
175
|
+
const arrived = await until(async () => (await upstream.seen()).some((seen) => seen.authorization === sha256(`Bearer ${ENV_KEY}`)), 60_000);
|
|
176
|
+
// stderr, because vitest keeps a passing test's console.log to itself.
|
|
177
|
+
process.stderr.write(`[grants live] a provider granted after the instance started ${arrived ? 'was used on the next turn without a restart' : 'was NOT used on the next turn: the instance keeps the configuration it started with'}\n`);
|
|
178
|
+
expect(JSON.stringify(await upstream.seen())).not.toContain(ENV_KEY);
|
|
179
|
+
}, 180_000);
|
|
180
|
+
|
|
181
|
+
it('says the grants again after a stop and a start: the environment key yes, the typed key no', async () => {
|
|
182
|
+
await host.journey.stopSpace(spaceId);
|
|
183
|
+
const started = await host.journey.startSpace(spaceId);
|
|
184
|
+
expect(started).toMatchObject({ state: 'running', networkRestored: true, grantsRestored: ['openai'], needsAccess: ['anthropic'] });
|
|
185
|
+
expect(await listed()).toMatchObject({ access: 'needs_access', needsAccess: ['anthropic'] });
|
|
186
|
+
// The environment key works again at once; the typed one is gone with the gatekeeper's memory.
|
|
187
|
+
const bearer = await shell('curl -s http://gatekeeper:8080/model/openai/responses');
|
|
188
|
+
expect(JSON.parse(bearer.stdout)).toMatchObject({ path: '/v1/responses', authorization: sha256(`Bearer ${ENV_KEY}`) });
|
|
189
|
+
const missing = await shell('curl -s -o /dev/null -w "%{http_code}" http://gatekeeper:8080/model/anthropic/messages');
|
|
190
|
+
expect(missing.stdout).toBe('403');
|
|
191
|
+
// Granting once more brings it back.
|
|
192
|
+
await host.journey.grantAccess(spaceId, { kind: 'model', provider: 'anthropic', upstream: upstream.url, secret: { kind: 'typed', value: TYPED_KEY } });
|
|
193
|
+
expect(await listed()).toMatchObject({ access: 'granted', needsAccess: [] });
|
|
194
|
+
expect(recordText()).not.toContain(TYPED_KEY);
|
|
195
|
+
expect(recordText()).not.toContain(ENV_KEY);
|
|
196
|
+
}, 300_000);
|
|
197
|
+
});
|