@openchamber/web 1.18.2 → 1.18.3

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.
Files changed (136) hide show
  1. package/bin/lib/commands-models.js +1 -1
  2. package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-DbUi6I9s.js} +1 -1
  3. package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-Jc2_hNPE.js} +1 -1
  4. package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-PCrYHBko.js} +1 -1
  5. package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CndEcZNu.js} +1 -1
  6. package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DEGlNjMH.js} +2 -2
  7. package/dist/assets/FilesView-CzUgIvUm.js +14 -0
  8. package/dist/assets/{GitView-OSVIn5V1.js → GitView-C-n17voy.js} +1 -1
  9. package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-BYcgdTOQ.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +12 -0
  12. package/dist/assets/OnboardingScreen-BmN0lhk4.js +1 -0
  13. package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-Bn7bfgUv.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-D1fWvrUn.js} +2 -2
  15. package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-CWM0iyFk.js} +3 -3
  16. package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-Cez-9xRh.js} +1 -1
  17. package/dist/assets/SettingsView-Bl1drwPw.js +28 -0
  18. package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-DL5axjDZ.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-BtIJkFno.js} +7 -7
  20. package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-i3PQo6_0.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-DkcusvMa.js} +1 -1
  22. package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-Cc5Hd6P5.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-xPena3W2.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +1 -0
  25. package/dist/assets/de-u7gSnqWs.js +9 -0
  26. package/dist/assets/es-T9O7aAOr.js +15 -0
  27. package/dist/assets/fr-Oor7ewbE.js +13 -0
  28. package/dist/assets/index-CVNuER6G.css +1 -0
  29. package/dist/assets/{index-BgQEgA2a.js → index-Crz1YOFl.js} +1 -1
  30. package/dist/assets/index-iFY_N5aO.js +7 -0
  31. package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-Dudf-dWx.js} +1 -1
  32. package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-DS4QV1dd.js} +1 -1
  33. package/dist/assets/ja-DHpqbVmr.js +15 -0
  34. package/dist/assets/ko-CwLkS3nx.js +15 -0
  35. package/dist/assets/{main-LfcbGv7C.js → main-C0DyIwTb.js} +2 -2
  36. package/dist/assets/main-CAxX6DAN.js +915 -0
  37. package/dist/assets/markdownCore-DhfzuGXu.js +2 -0
  38. package/dist/assets/markdownImageAssets-BTNlRyjd.js +1 -0
  39. package/dist/assets/{miniChat-CUp_elRz.js → miniChat-CGfrxKpJ.js} +2 -2
  40. package/dist/assets/{mobile-CBSN7BsH.js → mobile-DEmhwNcV.js} +2 -2
  41. package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-C5D1OPCa.js} +2 -2
  42. package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
  43. package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
  44. package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-Dpbswpom.js} +2 -2
  45. package/dist/assets/renderMobileApp-B5HA4qbi.js +25 -0
  46. package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +13 -0
  47. package/dist/assets/scheduledTasksApi-BxgGWTL8.js +1 -0
  48. package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-CmanopUB.js} +1 -1
  49. package/dist/assets/uk-BA2kZR38.js +15 -0
  50. package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-sHmU5b8u.js} +137 -137
  51. package/dist/assets/useInlineCommentController-gt56WkxJ.js +2 -0
  52. package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-Dihw9MtL.js} +2 -2
  53. package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
  54. package/dist/assets/{web-components-DGvnI0zx.js → web-components-BL-Ur2Tb.js} +1 -1
  55. package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
  56. package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
  57. package/dist/index.html +4 -4
  58. package/dist/mini-chat.html +3 -3
  59. package/dist/mobile.html +3 -3
  60. package/package.json +2 -2
  61. package/server/index.js +65 -19
  62. package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
  63. package/server/lib/agent-tool/runtime.js +90 -16
  64. package/server/lib/agent-tool/runtime.test.js +86 -0
  65. package/server/lib/browser-control/DOCUMENTATION.md +50 -0
  66. package/server/lib/browser-control/broker.js +154 -0
  67. package/server/lib/browser-control/broker.test.js +191 -0
  68. package/server/lib/browser-control/routes.js +48 -0
  69. package/server/lib/browser-control/routes.test.js +108 -0
  70. package/server/lib/dev-servers/parse.js +203 -0
  71. package/server/lib/dev-servers/parse.test.js +174 -0
  72. package/server/lib/dev-servers/routes.js +135 -0
  73. package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
  74. package/server/lib/dev-tunnel/client.js +174 -0
  75. package/server/lib/dev-tunnel/runtime.js +189 -0
  76. package/server/lib/dev-tunnel/tunnel.test.js +282 -0
  77. package/server/lib/git/credentials.js +0 -33
  78. package/server/lib/github/DOCUMENTATION.md +1 -1
  79. package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
  80. package/server/lib/openchamber-control/actions.js +33 -1
  81. package/server/lib/openchamber-control/screenshots.js +83 -0
  82. package/server/lib/openchamber-control/screenshots.test.js +84 -0
  83. package/server/lib/openchamber-control/service.js +141 -2
  84. package/server/lib/openchamber-control/service.test.js +55 -0
  85. package/server/lib/opencode/core-routes.js +31 -52
  86. package/server/lib/opencode/core-routes.test.js +37 -9
  87. package/server/lib/opencode/feature-routes-runtime.js +4 -0
  88. package/server/lib/opencode/settings-helpers.js +3 -9
  89. package/server/lib/projects/project-config.js +181 -2
  90. package/server/lib/projects/project-config.test.js +295 -0
  91. package/server/lib/quota/DOCUMENTATION.md +4 -2
  92. package/server/lib/quota/credentials/providers.js +0 -7
  93. package/server/lib/quota/credentials/store.js +11 -1
  94. package/server/lib/quota/credentials/store.test.js +9 -1
  95. package/server/lib/quota/providers/opencode-go.js +35 -35
  96. package/server/lib/quota/providers/opencode-go.test.js +52 -7
  97. package/server/lib/quota/routes.js +0 -2
  98. package/server/lib/relay/DOCUMENTATION.md +2 -0
  99. package/server/lib/relay/tunnel-host.js +157 -33
  100. package/server/lib/relay/tunnel-host.test.js +147 -0
  101. package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
  102. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
  103. package/server/lib/scheduled-tasks/routes.js +6 -0
  104. package/server/lib/scheduled-tasks/runtime.js +369 -108
  105. package/server/lib/scheduled-tasks/service.js +7 -1
  106. package/server/lib/scheduled-tasks/service.test.js +20 -0
  107. package/server/lib/walkthrough/index.js +0 -2
  108. package/server/sse-routes.test.js +3 -0
  109. package/dist/assets/FilesView-WkxsWHBE.js +0 -14
  110. package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
  111. package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
  112. package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
  113. package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
  114. package/dist/assets/de-B6t6T54h.js +0 -9
  115. package/dist/assets/es-DH9NUKge.js +0 -15
  116. package/dist/assets/fr-Do4t2KmA.js +0 -13
  117. package/dist/assets/index-B45s9aAX.css +0 -1
  118. package/dist/assets/index-CNrN5qDs.js +0 -7
  119. package/dist/assets/ja-DJT9EM80.js +0 -15
  120. package/dist/assets/ko-CfWRq2p4.js +0 -15
  121. package/dist/assets/main-B4oBRI9u.js +0 -193
  122. package/dist/assets/markdownCore-A3_L34oS.js +0 -2
  123. package/dist/assets/pt-BR-BDEzzltP.js +0 -15
  124. package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
  125. package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
  126. package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
  127. package/dist/assets/uk-B6Q32nyk.js +0 -15
  128. package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
  129. package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
  130. package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
  131. package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
  132. package/server/lib/preview/proxy-runtime.js +0 -1604
  133. package/server/lib/preview/proxy-runtime.test.js +0 -528
  134. package/server/lib/quota/opencode-go-credentials.js +0 -11
  135. package/server/lib/quota/opencode-go-credentials.test.js +0 -32
  136. package/server/lib/quota/routes.test.js +0 -40
package/dist/index.html CHANGED
@@ -509,15 +509,15 @@
509
509
  pointer-events: none;
510
510
  }
511
511
  </style>
512
- <script type="module" crossorigin src="/assets/main-LfcbGv7C.js"></script>
512
+ <script type="module" crossorigin src="/assets/main-C0DyIwTb.js"></script>
513
513
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
514
514
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
515
515
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
516
516
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
517
517
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
518
- <link rel="modulepreload" crossorigin href="/assets/index-CNrN5qDs.js">
519
- <link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-5VGWIT_J.js">
520
- <link rel="stylesheet" crossorigin href="/assets/index-B45s9aAX.css">
518
+ <link rel="modulepreload" crossorigin href="/assets/index-iFY_N5aO.js">
519
+ <link rel="modulepreload" crossorigin href="/assets/contextPanelEmbeddedChat-tQekJUAF.js">
520
+ <link rel="stylesheet" crossorigin href="/assets/index-CVNuER6G.css">
521
521
  </head>
522
522
  <body class="h-full bg-background text-foreground">
523
523
  <div id="root" class="h-full">
@@ -74,14 +74,14 @@
74
74
  }
75
75
  </style>
76
76
 
77
- <script type="module" crossorigin src="/assets/miniChat-CUp_elRz.js"></script>
77
+ <script type="module" crossorigin src="/assets/miniChat-CGfrxKpJ.js"></script>
78
78
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
79
79
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
80
80
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
81
81
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
82
82
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
83
- <link rel="modulepreload" crossorigin href="/assets/index-CNrN5qDs.js">
84
- <link rel="stylesheet" crossorigin href="/assets/index-B45s9aAX.css">
83
+ <link rel="modulepreload" crossorigin href="/assets/index-iFY_N5aO.js">
84
+ <link rel="stylesheet" crossorigin href="/assets/index-CVNuER6G.css">
85
85
  </head>
86
86
  <body class="h-full bg-background text-foreground">
87
87
  <div id="root" class="h-full">
package/dist/mobile.html CHANGED
@@ -63,14 +63,14 @@
63
63
  })();
64
64
  </script>
65
65
 
66
- <script type="module" crossorigin src="/assets/mobile-CBSN7BsH.js"></script>
66
+ <script type="module" crossorigin src="/assets/mobile-DEmhwNcV.js"></script>
67
67
  <link rel="modulepreload" crossorigin href="/assets/vendor-vite-runtime-DD1OZmLC.js">
68
68
  <link rel="modulepreload" crossorigin href="/assets/vendor-opencode-sdk-BJ73u-bH.js">
69
69
  <link rel="modulepreload" crossorigin href="/assets/vendor-scheduler-7OC5HNn7.js">
70
70
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BUCujlKS.js">
71
71
  <link rel="modulepreload" crossorigin href="/assets/vendor-zustand-BAGL70zf.js">
72
- <link rel="modulepreload" crossorigin href="/assets/index-CNrN5qDs.js">
73
- <link rel="stylesheet" crossorigin href="/assets/index-B45s9aAX.css">
72
+ <link rel="modulepreload" crossorigin href="/assets/index-iFY_N5aO.js">
73
+ <link rel="stylesheet" crossorigin href="/assets/index-CVNuER6G.css">
74
74
  </head>
75
75
  <body class="h-full bg-background text-foreground">
76
76
  <div id="root" class="h-full"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openchamber/web",
3
- "version": "1.18.2",
3
+ "version": "1.18.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./server/index.js",
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@clack/prompts": "^1.1.0",
27
27
  "@octokit/rest": "^22.0.1",
28
- "@opencode-ai/sdk": "1.18.16",
28
+ "@opencode-ai/sdk": "1.18.18",
29
29
  "@simplewebauthn/server": "13.3.1",
30
30
  "adm-zip": "^0.6.0",
31
31
  "bun-pty": "^0.4.5",
package/server/index.js CHANGED
@@ -92,16 +92,18 @@ import { createGracefulShutdownRuntime } from './lib/opencode/shutdown-runtime.j
92
92
  import { createProjectConfigRuntime } from './lib/projects/project-config.js';
93
93
  import { createRemoteClientAuthRuntime } from './lib/client-auth/remote-clients.js';
94
94
  import { createClientPairingRuntime } from './lib/client-auth/pairing.js';
95
- import { createPreviewProxyRuntime } from './lib/preview/proxy-runtime.js';
96
95
  import { attachRealtimeProxy } from './lib/realtime-proxy.js';
97
96
  import { createRelayService } from './lib/relay/service.js';
98
97
  import { createRelayHostLock } from './lib/relay/host-lock.js';
99
98
  import { createAgentToolRuntime } from './lib/agent-tool/runtime.js';
99
+ import { createBrowserControlBroker } from './lib/browser-control/broker.js';
100
+ import { createDevServerScanner } from './lib/dev-servers/routes.js';
101
+ import { createDevTunnelRuntime } from './lib/dev-tunnel/runtime.js';
102
+ import { registerBrowserControlRoutes } from './lib/browser-control/routes.js';
100
103
  import { createSystemPromptRuntime } from './lib/system-prompt/runtime.js';
101
104
  import { createOpenChamberSessionService } from './lib/openchamber-sessions/routes.js';
102
105
  import { createScheduledTaskService } from './lib/scheduled-tasks/service.js';
103
106
  import { createOpenChamberControlService } from './lib/openchamber-control/service.js';
104
- import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
105
107
  import webPush from 'web-push';
106
108
 
107
109
  const __filename = fileURLToPath(import.meta.url);
@@ -1094,9 +1096,13 @@ const openCodeLifecycleRuntime = createOpenCodeLifecycleRuntime({
1094
1096
  },
1095
1097
  getManagedOpenCodeEnv: async () => {
1096
1098
  const settings = await readSettingsFromDiskMigrated().catch(() => null);
1097
- const managedEnv = settings?.agentControlToolEnabled === false
1098
- ? {}
1099
- : await (agentToolRuntime?.prepareManagedOpenCodeEnv() || {});
1099
+ // Each capability is its own tool and its own switch; the plugin is only
1100
+ // injected while at least one of them is on.
1101
+ const includeControl = settings?.agentControlToolEnabled !== false;
1102
+ const includeWeb = settings?.agentWebToolEnabled !== false;
1103
+ const managedEnv = includeControl || includeWeb
1104
+ ? await (agentToolRuntime?.prepareManagedOpenCodeEnv({ includeControl, includeWeb }) || {})
1105
+ : {};
1100
1106
  if (settings?.optimizeSystemPrompt !== true) return managedEnv;
1101
1107
 
1102
1108
  const configContent = managedEnv.OPENCODE_CONFIG_CONTENT ?? process.env.OPENCODE_CONFIG_CONTENT;
@@ -1188,6 +1194,37 @@ const openChamberSessionService = createOpenChamberSessionService({
1188
1194
  waitForOpenCodeReady,
1189
1195
  emitSessionCreatedEvent,
1190
1196
  });
1197
+ // Browser actions are published to whichever OpenChamber clients are connected;
1198
+ // the one owning the browser panel answers. `emitRequest` returns the number of
1199
+ // clients reached so the broker can fail fast when nobody is listening.
1200
+ const browserControlBroker = createBrowserControlBroker({
1201
+ createId: () => `browser-${crypto.randomUUID()}`,
1202
+ emitRequest: (request) => {
1203
+ // Opening a page only needs a panel to open it in; everything else needs a
1204
+ // client that can actually drive one. Counting the right clients is what
1205
+ // lets the broker say "not here" instead of timing out.
1206
+ const needsBrowserView = request.action !== 'browser.open';
1207
+ let delivered = 0;
1208
+ for (const client of uiOpenChamberEventClients) {
1209
+ if (needsBrowserView && client.openchamberBrowserCapable !== true) continue;
1210
+ try {
1211
+ writeSseEvent(client, {
1212
+ type: 'openchamber:browser-control-request',
1213
+ properties: {
1214
+ requestId: request.requestId,
1215
+ action: request.action,
1216
+ parameters: request.parameters,
1217
+ },
1218
+ });
1219
+ delivered += 1;
1220
+ } catch {
1221
+ uiOpenChamberEventClients.delete(client);
1222
+ }
1223
+ }
1224
+ return delivered;
1225
+ },
1226
+ });
1227
+
1191
1228
  const openChamberControlService = createOpenChamberControlService({
1192
1229
  readSettingsFromDiskMigrated,
1193
1230
  sanitizeProjects,
@@ -1196,6 +1233,7 @@ const openChamberControlService = createOpenChamberControlService({
1196
1233
  waitForOpenCodeReady,
1197
1234
  sessionService: openChamberSessionService,
1198
1235
  scheduledTaskService,
1236
+ browserControl: browserControlBroker,
1199
1237
  });
1200
1238
 
1201
1239
  const ensureGlobalWatcherStarted = async () => {
@@ -1653,6 +1691,24 @@ async function main(options = {}) {
1653
1691
  relayServiceInstance = relayService;
1654
1692
  relayService.registerRoutes(app);
1655
1693
 
1694
+ registerBrowserControlRoutes(app, { express, broker: browserControlBroker });
1695
+
1696
+ // One scanner backs both discovery and the tunnel allowlist, so a port the
1697
+ // user can see is exactly a port the tunnel will dial.
1698
+ const devServerScanner = createDevServerScanner({ spawn, platform: process.platform });
1699
+ const listDevServers = () => devServerScanner.discover({
1700
+ ownPorts: [port, openCodePort].filter((value) => Number.isInteger(value) && value > 0),
1701
+ });
1702
+
1703
+ createDevTunnelRuntime({
1704
+ server,
1705
+ discoverDevServers: listDevServers,
1706
+ uiAuthController,
1707
+ isRequestOriginAllowed,
1708
+ rejectWebSocketUpgrade,
1709
+ logger: console,
1710
+ });
1711
+
1656
1712
  await featureRoutesRuntime.registerRoutes(app, {
1657
1713
  crypto,
1658
1714
  fs,
@@ -1682,6 +1738,10 @@ async function main(options = {}) {
1682
1738
  buildOpenCodeUrl,
1683
1739
  getOpenCodeAuthHeaders,
1684
1740
  getOpenCodePort: () => openCodePort,
1741
+ // Dev-server discovery must not offer OpenChamber's own listeners back to
1742
+ // the user as something to preview.
1743
+ getOwnPorts: () => [port, openCodePort].filter((value) => Number.isInteger(value) && value > 0),
1744
+ devServerScanner,
1685
1745
  buildAugmentedPath,
1686
1746
  projectConfigRuntime,
1687
1747
  scheduledTasksRuntime,
@@ -1695,20 +1755,6 @@ async function main(options = {}) {
1695
1755
  permissionAutoAcceptRuntime,
1696
1756
  });
1697
1757
 
1698
- const previewProxyRuntime = createPreviewProxyRuntime({
1699
- crypto,
1700
- URL,
1701
- createProxyMiddleware,
1702
- responseInterceptor,
1703
- });
1704
- previewProxyRuntime.attach(app, {
1705
- server,
1706
- express,
1707
- uiAuthController,
1708
- isRequestOriginAllowed,
1709
- rejectWebSocketUpgrade,
1710
- });
1711
-
1712
1758
  const startupPipelineResult = await startupPipelineRuntime.run({
1713
1759
  app,
1714
1760
  server,
@@ -2,12 +2,27 @@
2
2
 
3
3
  ## Purpose
4
4
 
5
- This module exposes OpenChamber orchestration to agents as one typed OpenCode
6
- custom tool named `openchamber`. It is injected only when OpenChamber launches
7
- and owns the OpenCode process, and only while the persisted
8
- `agentControlToolEnabled` setting is not `false` (default on; toggled in
9
- Settings → General → OpenCode CLI and applied on the next managed OpenCode
10
- restart).
5
+ This module exposes OpenChamber to agents as typed OpenCode custom tools. There
6
+ are two, because controlling sessions and driving a page are separate intents
7
+ the user can want independently:
8
+
9
+ - `openchamber` — projects, sessions, worktrees, and scheduled tasks. Enabled
10
+ while the persisted `agentControlToolEnabled` setting is not `false`.
11
+ - `openchamber_web` — looking at and interacting with the page in OpenChamber's
12
+ browser panel. Enabled while `agentWebToolEnabled` is not `false`.
13
+
14
+ Both default to on, are toggled in Settings → General → OpenCode CLI, and apply
15
+ on the next managed OpenCode restart. Each tool carries only its own actions and
16
+ only the parameters those actions use, so turning one off removes its inputs
17
+ from the schema rather than leaving them visible. The plugin is injected only
18
+ when OpenChamber launches and owns the OpenCode process, and not at all when
19
+ both settings are `false`.
20
+
21
+ - The plugin accepts the action's inputs either inside `parameters` or beside
22
+ `action`, because models produce both shapes; an explicit `parameters` object
23
+ wins on a conflict. Rejecting the flattened shape turned a call that plainly
24
+ carried a `url` into "url is required", which reads as a broken tool rather
25
+ than a malformed call.
11
26
 
12
27
  ## Runtime flow
13
28
 
@@ -3,15 +3,29 @@ import { pathToFileURL } from 'node:url';
3
3
  import {
4
4
  OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS,
5
5
  OPENCHAMBER_AGENT_TOOL_ACTIONS,
6
+ OPENCHAMBER_WEB_ACTION_DEFINITIONS,
7
+ OPENCHAMBER_WEB_ACTIONS,
6
8
  } from '../openchamber-control/actions.js';
7
9
 
8
10
  const TOOL_SCHEMA_VERSION = 1;
9
- const ACTIONS = new Set(OPENCHAMBER_AGENT_TOOL_ACTIONS);
11
+ // Everything either managed tool may ask for; the agent allowlist stays
12
+ // narrower than the full control surface.
13
+ const ACTIONS = new Set([...OPENCHAMBER_AGENT_TOOL_ACTIONS, ...OPENCHAMBER_WEB_ACTIONS]);
10
14
  const AGENT_TOOL_ACTION_TITLES = Object.fromEntries(
11
- OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS.map(({ action, title }) => [action, title]),
15
+ [...OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS, ...OPENCHAMBER_WEB_ACTION_DEFINITIONS]
16
+ .map(({ action, title }) => [action, title]),
12
17
  );
13
18
 
14
- const PLUGIN_PARAMETER_PROPERTIES = {
19
+ /**
20
+ * Each tool carries only the inputs its own actions take.
21
+ *
22
+ * A shared parameter object would leave a disabled capability's inputs visible
23
+ * in the other tool's schema, which is both misleading and paid for in context
24
+ * on every call.
25
+ */
26
+ const WEB_PARAMETER_NAMES = ['url', 'selector', 'text', 'value', 'submit', 'direction', 'viewport', 'label'];
27
+
28
+ const ALL_PARAMETER_PROPERTIES = {
15
29
  projectId: { type: 'string', description: 'Configured project ID; do not combine with directory' },
16
30
  directory: { type: 'string', description: 'Absolute checkout or session directory; defaults to the current session directory' },
17
31
  sessionId: { type: 'string' },
@@ -44,8 +58,29 @@ const PLUGIN_PARAMETER_PROPERTIES = {
44
58
  cron: { type: 'string', description: 'Cron expression' },
45
59
  timezone: { type: 'string', description: 'IANA timezone' },
46
60
  disabled: { type: 'boolean', description: 'true disables and false enables; required for schedule.toggle' },
61
+ url: { type: 'string', description: 'http(s) URL for browser.open' },
62
+ selector: { type: 'string', description: 'CSS selector from a browser.snapshot result' },
63
+ text: { type: 'string', description: 'Visible label to match when no selector is given' },
64
+ value: { type: 'string', description: 'Text to type for browser.type' },
65
+ submit: { type: 'boolean', description: 'Press Enter after typing' },
66
+ direction: { type: 'string', enum: ['up', 'down', 'top', 'bottom'], description: 'Scroll direction for browser.scroll' },
67
+ viewport: { type: 'string', enum: ['mobile', 'tablet', 'desktop', 'fill'], description: 'Page layout size; snapshots report which one is in effect' },
68
+ label: { type: 'string', description: 'Short name for a browser.capture image, such as before-fix' },
47
69
  };
48
70
 
71
+ const pickParameters = (names) => Object.fromEntries(
72
+ Object.entries(ALL_PARAMETER_PROPERTIES).filter(([name]) => names.includes(name)),
73
+ );
74
+
75
+ const CONTROL_PARAMETER_PROPERTIES = pickParameters(
76
+ Object.keys(ALL_PARAMETER_PROPERTIES).filter((name) => !WEB_PARAMETER_NAMES.includes(name)),
77
+ );
78
+ const WEB_PARAMETER_PROPERTIES = pickParameters(WEB_PARAMETER_NAMES);
79
+
80
+ const CONTROL_TOOL_DESCRIPTION = "Control OpenChamber projects, sessions, and scheduled tasks on the user's behalf. Sessions and scheduled tasks you create are for the user to follow and interact with; never use this tool to delegate parts of your own current task. Use one action per call. Scope with projectId or directory; omit both to use the current session directory. Session dispatches return immediately by default and you receive no notification when a dispatched session finishes, so never promise to report back on it; the user follows it in OpenChamber; a dispatched session needs no follow-up from you. If the user later asks how it went, use session.messages (add wait to block until it is idle, lastAssistant for just the final answer) — session.send always sends a NEW prompt and never just waits. Set wait only when the user asks or the next step requires the completed result. Session and worktree deletion are unavailable.";
81
+
82
+ const WEB_TOOL_DESCRIPTION = "Look at and interact with a web page in OpenChamber's browser panel, so you can check your own work rather than describing what you expect. Use one action per call. Open a page, snapshot it to read its text and its interactive elements, then click, type or scroll using the selectors the snapshot returned; snapshots also report any errors the page logged. Pass a selector to browser.snapshot to read one part of a long page. browser.inspect returns computed styles when the question is how something renders. Set viewport to check a layout at mobile, tablet or desktop size. The page runs with the user's real logins, so treat what you see as their live session.";
83
+
49
84
  const asNonEmptyString = (value) => {
50
85
  if (typeof value !== 'string') return null;
51
86
  const trimmed = value.trim();
@@ -68,23 +103,33 @@ const isLoopbackAddress = (value) => {
68
103
  || address === '::ffff:127.0.0.1';
69
104
  };
70
105
 
71
- const createPluginSource = () => String.raw`
72
- export const OpenChamberPlugin = async () => ({
73
- tool: {
74
- openchamber: {
75
- description: "Control OpenChamber projects, sessions, and scheduled tasks on the user's behalf. Sessions and scheduled tasks you create are for the user to follow and interact with; never use this tool to delegate parts of your own current task. Use one action per call. Scope with projectId or directory; omit both to use the current session directory. Session dispatches return immediately by default and you receive no notification when a dispatched session finishes, so never promise to report back on it; the user follows it in OpenChamber; a dispatched session needs no follow-up from you. If the user later asks how it went, use session.messages (add wait to block until it is idle, lastAssistant for just the final answer) — session.send always sends a NEW prompt and never just waits. Set wait only when the user asks or the next step requires the completed result. Session and worktree deletion are unavailable.",
106
+ /**
107
+ * One template, one entry per enabled capability.
108
+ *
109
+ * Both tools speak to the same callback with the same envelope; only the action
110
+ * set, the inputs and the description differ. Generating them from one template
111
+ * keeps the transport, metadata and failure handling identical, which is what
112
+ * the caller depends on.
113
+ */
114
+ const createToolEntry = ({ name, description, actions, definitions, parameters }) => String.raw` ${name}: {
115
+ description: ${JSON.stringify(description)},
76
116
  args: {
77
- action: { type: "string", enum: ${JSON.stringify(OPENCHAMBER_AGENT_TOOL_ACTIONS)}, oneOf: ${JSON.stringify(OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS.map(({ action, description }) => ({ const: action, description })))}, description: "OpenChamber action to perform" },
78
- parameters: { type: "object", properties: ${JSON.stringify(PLUGIN_PARAMETER_PROPERTIES)}, additionalProperties: false, description: "Inputs for the action; use an empty object when none are needed" },
117
+ action: { type: "string", enum: ${JSON.stringify(actions)}, oneOf: ${JSON.stringify(definitions.map((entry) => ({ const: entry.action, description: entry.description })))}, description: "OpenChamber action to perform" },
118
+ parameters: { type: "object", properties: ${JSON.stringify(parameters)}, additionalProperties: false, description: "Inputs for the action; use an empty object when none are needed" },
79
119
  },
80
120
  async execute(input, context) {
81
- const args = { ...(input.parameters ?? {}), action: input.action }
121
+ // Models routinely put the inputs next to the action instead of inside
122
+ // the parameters object, and dropping them there produced a
123
+ // "url is required" error for a call that plainly carried a url. Both
124
+ // shapes are accepted; an explicit parameters object wins on a conflict.
125
+ const { action: requestedAction, parameters, ...flattened } = input ?? {}
126
+ const args = { ...flattened, ...(parameters ?? {}), action: requestedAction }
82
127
  const actionTitles = ${JSON.stringify(AGENT_TOOL_ACTION_TITLES)}
83
128
  const title = Object.hasOwn(actionTitles, args.action) ? actionTitles[args.action] : args.action
84
129
  context.metadata({
85
130
  title,
86
131
  metadata: {
87
- openchamber: {
132
+ ${name}: {
88
133
  schemaVersion: ${TOOL_SCHEMA_VERSION},
89
134
  action: args.action,
90
135
  description: title,
@@ -119,7 +164,7 @@ export const OpenChamberPlugin = async () => ({
119
164
  context.metadata({
120
165
  title,
121
166
  metadata: {
122
- openchamber: {
167
+ ${name}: {
123
168
  schemaVersion: ${TOOL_SCHEMA_VERSION},
124
169
  action: args.action,
125
170
  description: title,
@@ -135,9 +180,35 @@ export const OpenChamberPlugin = async () => ({
135
180
  }
136
181
  },
137
182
  },
138
- },
183
+ `;
184
+
185
+ const createPluginSource = ({ includeControl, includeWeb }) => {
186
+ const entries = [];
187
+ if (includeControl) {
188
+ entries.push(createToolEntry({
189
+ name: 'openchamber',
190
+ description: CONTROL_TOOL_DESCRIPTION,
191
+ actions: OPENCHAMBER_AGENT_TOOL_ACTIONS,
192
+ definitions: OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS,
193
+ parameters: CONTROL_PARAMETER_PROPERTIES,
194
+ }));
195
+ }
196
+ if (includeWeb) {
197
+ entries.push(createToolEntry({
198
+ name: 'openchamber_web',
199
+ description: WEB_TOOL_DESCRIPTION,
200
+ actions: OPENCHAMBER_WEB_ACTIONS,
201
+ definitions: OPENCHAMBER_WEB_ACTION_DEFINITIONS,
202
+ parameters: WEB_PARAMETER_PROPERTIES,
203
+ }));
204
+ }
205
+
206
+ return `export const OpenChamberPlugin = async () => ({
207
+ tool: {
208
+ ${entries.join('')} },
139
209
  })
140
210
  `;
211
+ };
141
212
 
142
213
  const mergePluginConfig = (rawConfig, pluginUrl) => {
143
214
  const errors = [];
@@ -170,13 +241,16 @@ export const createAgentToolRuntime = (dependencies) => {
170
241
  const pluginPath = path.join(pluginDirectory, 'openchamber-plugin.js');
171
242
  let activeToken = null;
172
243
 
173
- const prepareManagedOpenCodeEnv = async () => {
244
+ const prepareManagedOpenCodeEnv = async ({ includeControl = true, includeWeb = true } = {}) => {
174
245
  const port = getActivePort();
175
246
  if (!Number.isInteger(port) || port <= 0) {
176
247
  throw new Error('OpenChamber listener port is unavailable for managed tool injection');
177
248
  }
249
+ if (!includeControl && !includeWeb) {
250
+ throw new Error('At least one OpenChamber managed tool must be enabled to inject the plugin');
251
+ }
178
252
  await fsPromises.mkdir(pluginDirectory, { recursive: true });
179
- await fsPromises.writeFile(pluginPath, createPluginSource(), { mode: 0o600 });
253
+ await fsPromises.writeFile(pluginPath, createPluginSource({ includeControl, includeWeb }), { mode: 0o600 });
180
254
  activeToken = crypto.randomBytes(32).toString('base64url');
181
255
  const pluginUrl = pathToFileURL(pluginPath).href;
182
256
  return {
@@ -114,6 +114,92 @@ describe('managed agent tool runtime', () => {
114
114
  expect(source).not.toContain(preparedEnv.OPENCHAMBER_AGENT_TOOL_TOKEN);
115
115
  });
116
116
 
117
+ it('emits both tools, each carrying only its own actions and inputs', async () => {
118
+ const { runtime, dataDir } = await createRuntime();
119
+ await runtime.prepareManagedOpenCodeEnv();
120
+ const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
121
+ const pluginModule = await import(`${pathToFileURL(pluginPath).href}?both=${Date.now()}`);
122
+ const { tool } = await pluginModule.OpenChamberPlugin();
123
+
124
+ const controlActions = tool.openchamber.args.action.enum;
125
+ const webActions = tool.openchamber_web.args.action.enum;
126
+ expect(webActions).toContain('browser.open');
127
+ expect(controlActions).not.toContain('browser.open');
128
+ expect(webActions).not.toContain('session.create');
129
+
130
+ // Turning one tool off has to remove its inputs too, not just its actions.
131
+ expect(Object.keys(tool.openchamber_web.args.parameters.properties)).toContain('url');
132
+ expect(Object.keys(tool.openchamber.args.parameters.properties)).not.toContain('url');
133
+ expect(Object.keys(tool.openchamber.args.parameters.properties)).toContain('sessionId');
134
+ });
135
+
136
+ it('accepts inputs passed beside the action, not only inside parameters', async () => {
137
+ const { runtime, dataDir } = await createRuntime();
138
+ const prepared = await runtime.prepareManagedOpenCodeEnv();
139
+ const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
140
+ const pluginModule = await import(`${pathToFileURL(pluginPath).href}?flat=${Date.now()}`);
141
+ const { tool } = await pluginModule.OpenChamberPlugin();
142
+
143
+ const sent = [];
144
+ const originalFetch = globalThis.fetch;
145
+ const originalUrl = process.env.OPENCHAMBER_AGENT_TOOL_URL;
146
+ const originalToken = process.env.OPENCHAMBER_AGENT_TOOL_TOKEN;
147
+ process.env.OPENCHAMBER_AGENT_TOOL_URL = prepared.OPENCHAMBER_AGENT_TOOL_URL;
148
+ process.env.OPENCHAMBER_AGENT_TOOL_TOKEN = prepared.OPENCHAMBER_AGENT_TOOL_TOKEN;
149
+ globalThis.fetch = async (_endpoint, init) => {
150
+ sent.push(JSON.parse(init.body));
151
+ return new Response(JSON.stringify({ schemaVersion: 1, ok: true, action: 'browser.open', data: {} }));
152
+ };
153
+ const context = { directory: '/work/project', abort: new AbortController().signal, metadata: () => {} };
154
+
155
+ try {
156
+ // The shape a model actually produced: url and viewport next to action.
157
+ await tool.openchamber_web.execute(
158
+ { action: 'browser.open', url: 'https://example.test', viewport: 'mobile' },
159
+ context,
160
+ );
161
+ // The documented shape must keep working, and win when both are present.
162
+ await tool.openchamber_web.execute(
163
+ { action: 'browser.open', url: 'https://ignored.test', parameters: { url: 'https://example.test/nested' } },
164
+ context,
165
+ );
166
+ // Both tools come from one template, so session control accepts it too.
167
+ await tool.openchamber.execute(
168
+ { action: 'session.messages', sessionId: 'ses_1', limit: 3 },
169
+ context,
170
+ );
171
+ } finally {
172
+ globalThis.fetch = originalFetch;
173
+ process.env.OPENCHAMBER_AGENT_TOOL_URL = originalUrl;
174
+ process.env.OPENCHAMBER_AGENT_TOOL_TOKEN = originalToken;
175
+ }
176
+
177
+ expect(sent[0].input).toEqual({ action: 'browser.open', url: 'https://example.test', viewport: 'mobile' });
178
+ expect(sent[1].input.url).toBe('https://example.test/nested');
179
+ expect(sent[2].input).toEqual({ action: 'session.messages', sessionId: 'ses_1', limit: 3 });
180
+ });
181
+
182
+ it('omits a tool the user turned off', async () => {
183
+ const { runtime, dataDir } = await createRuntime();
184
+ await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: true });
185
+ const pluginPath = path.join(dataDir, 'agent-tool', 'openchamber-plugin.js');
186
+ const pluginModule = await import(`${pathToFileURL(pluginPath).href}?web=${Date.now()}`);
187
+ const { tool } = await pluginModule.OpenChamberPlugin();
188
+
189
+ expect(Object.keys(tool)).toEqual(['openchamber_web']);
190
+ });
191
+
192
+ it('refuses to inject a plugin with no tools in it', async () => {
193
+ const { runtime } = await createRuntime();
194
+ let failed = false;
195
+ try {
196
+ await runtime.prepareManagedOpenCodeEnv({ includeControl: false, includeWeb: false });
197
+ } catch {
198
+ failed = true;
199
+ }
200
+ expect(failed).toBe(true);
201
+ });
202
+
117
203
  it('executes actions through the shared control service', async () => {
118
204
  const executeAction = vi.fn(async () => ({ projects: [] }));
119
205
  const { runtime } = await createRuntime({ executeAction });
@@ -0,0 +1,50 @@
1
+ # Browser Control Broker
2
+
3
+ ## Purpose
4
+
5
+ This module carries agent browser actions from the server to the client that
6
+ owns the in-app browser view, and the result back. The browser lives in a
7
+ renderer, not in the server process, so the server can never act on a page
8
+ itself; it can only ask and wait.
9
+
10
+ ## Boundaries
11
+
12
+ - `broker.js` owns request lifetime: it publishes one action through the
13
+ injected `emitRequest`, holds the pending request, and settles it on a client
14
+ result, a timeout, or an abort signal. It knows nothing about transports.
15
+ - `routes.js` is the result callback (`POST /api/browser-control/result`). It
16
+ validates the envelope and hands the outcome to the broker.
17
+ - `../../index.js` supplies `emitRequest`, which writes the request to the
18
+ OpenChamber SSE clients and returns how many were reached.
19
+ - `../openchamber-control/service.js` is the only caller. It maps the
20
+ `browser.*` actions of the `openchamber_web` tool onto `broker.request()` and
21
+ owns their parameter validation.
22
+ - The client half is `packages/ui/src/lib/browser/controlClient.ts`, which
23
+ registers the mounted browser pane as the one responder.
24
+
25
+ ## Invariants
26
+
27
+ - Capability belongs to the connection, not to configuration. A client declares
28
+ it can drive a page by opening its event stream with `browser=1`, which only
29
+ a Chromium host does; the flag lives and dies with that connection, so there
30
+ is no setting to enable and no restart to remember.
31
+ - `emitRequest` counts only clients that can serve the action. `browser.open`
32
+ needs any client, because opening a tab is what creates a view; every other
33
+ action needs a declared-capable one.
34
+ - Exactly one client performs a request. The broadcast reaches everyone who
35
+ could serve it, so a client claims the request over
36
+ `POST /api/browser-control/claim` and acts only if granted; the first claim
37
+ wins and every other client does nothing. Deciding by whose result arrives
38
+ first would be too late, because by then each of them has already clicked.
39
+ A claim for a settled request is refused for the same reason.
40
+ - Nobody listening is answered immediately with a 503 describing the
41
+ environment, never by blocking for the full timeout. A blocked wait followed
42
+ by a timeout cannot be told apart from a page that hung.
43
+ - A client that accepted a request and then disappeared still times out.
44
+ Assuming success would report a page interaction that never happened.
45
+ - A result for an unknown request id is accepted with `matched: false`, not an
46
+ error: a client answering after the timeout has behaved correctly.
47
+ - The result route parses its own body. This server has no global body parser,
48
+ and a missing one silently turns every answer into an agent-visible timeout.
49
+ - Request payload limits are sized for a page snapshot (visible text plus every
50
+ interactive element), not for a control message.