@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveIntegrationApi } from '@openchamber/sdk';
|
|
2
2
|
|
|
3
3
|
// What a grant covered when the user approved it. `filesystem` is the
|
|
4
|
-
// declared pattern list, `network` the API origin, `service` the exec names
|
|
4
|
+
// declared pattern list, `origins` the origins the frame may reach, `network` the API origin, `service` the exec names
|
|
5
5
|
// and socket ids the dialog showed. A newer package that changes any of
|
|
6
6
|
// these has not been approved for that capability, whatever the stored
|
|
7
7
|
// grant list says, so the card asks again and the proxies refuse meanwhile.
|
|
@@ -17,6 +17,9 @@ export const guestGrantScope = (guest) => {
|
|
|
17
17
|
if (Array.isArray(guest.filesystem) && guest.filesystem.length > 0) {
|
|
18
18
|
scope.filesystem = sortedUnique(guest.filesystem);
|
|
19
19
|
}
|
|
20
|
+
if (Array.isArray(guest.origins) && guest.origins.length > 0) {
|
|
21
|
+
scope.origins = sortedUnique(guest.origins);
|
|
22
|
+
}
|
|
20
23
|
if (guest.integration) {
|
|
21
24
|
const api = resolveIntegrationApi(guest.integration);
|
|
22
25
|
if (api?.apiOrigin) {
|
|
@@ -57,7 +60,7 @@ const sameList = (a, b) => a.length === b.length && a.every((value, index) => va
|
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* The grants that still hold for the package as it is now. A scoped
|
|
60
|
-
* capability (`filesystem`, `network`, `service`) only counts when the stored
|
|
63
|
+
* capability (`filesystem`, `origins`, `network`, `service`) only counts when the stored
|
|
61
64
|
* scope equals the current one; without a stored scope it never counts.
|
|
62
65
|
* @param {string[]} granted
|
|
63
66
|
* @param {ReturnType<typeof guestGrantScope> | undefined} stored
|
|
@@ -67,6 +70,9 @@ export const effectiveGrants = (granted, stored, current) => granted.filter((cap
|
|
|
67
70
|
if (capability === 'filesystem') {
|
|
68
71
|
return Boolean(stored?.filesystem) && sameList(stored.filesystem, current.filesystem ?? []);
|
|
69
72
|
}
|
|
73
|
+
if (capability === 'origins') {
|
|
74
|
+
return Boolean(stored?.origins) && sameList(stored.origins, current.origins ?? []);
|
|
75
|
+
}
|
|
70
76
|
if (capability === 'network') {
|
|
71
77
|
return Boolean(stored?.apiOrigin)
|
|
72
78
|
&& stored.apiOrigin === current.apiOrigin
|
|
@@ -47,6 +47,15 @@ describe('effectiveGrants', () => {
|
|
|
47
47
|
expect(effectiveGrants(granted, approved, moreExec)).toEqual(['prompt', 'filesystem', 'network']);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
test('an origin added in an update is not approved until the user approves the new list', () => {
|
|
51
|
+
const approved = guestGrantScope({ origins: ['https://fonts.example.com'] });
|
|
52
|
+
expect(approved).toEqual({ origins: ['https://fonts.example.com'] });
|
|
53
|
+
expect(effectiveGrants(['origins'], approved, guestGrantScope({ origins: ['https://fonts.example.com'] }))).toEqual(['origins']);
|
|
54
|
+
const added = guestGrantScope({ origins: ['https://fonts.example.com', 'https://collect.example.net'] });
|
|
55
|
+
expect(effectiveGrants(['origins'], approved, added)).toEqual([]);
|
|
56
|
+
expect(effectiveGrants(['origins'], undefined, approved)).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
|
|
50
59
|
test('never counts a scoped grant without a recorded scope', () => {
|
|
51
60
|
expect(effectiveGrants(granted, undefined, guestGrantScope(guest))).toEqual(['prompt']);
|
|
52
61
|
});
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { GUEST_SCROLLBAR_CSS, GUEST_SCROLLBAR_SCRIPT } from '@openchamber/sdk';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// The panel iframe inherits the host's dark color scheme, and a document that
|
|
4
|
+
// does not declare one gets an opaque white canvas until its own theme loads:
|
|
5
|
+
// a white flash on every mount (issue #4017). The declaration has to precede
|
|
6
|
+
// the first paint, so it goes first: right after a leading doctype (matched
|
|
7
|
+
// only at the very start, never inside authored markup), else before all.
|
|
8
|
+
const GUEST_COLOR_SCHEME_META = '<meta name="color-scheme" content="light dark">';
|
|
9
|
+
const LEADING_DOCTYPE = /^\s*<!doctype[^>]*>/i;
|
|
10
|
+
|
|
11
|
+
const declareColorScheme = (html) => {
|
|
12
|
+
const doctype = LEADING_DOCTYPE.exec(html)?.[0] ?? '';
|
|
13
|
+
return `${doctype}${GUEST_COLOR_SCHEME_META}${html.slice(doctype.length)}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Append instead of matching tags inside untrusted comments, scripts, or templates (the one
|
|
17
|
+
* exception is the color-scheme meta, placed after a leading doctype; see above).
|
|
4
18
|
* Browsers accept the style and script after the document; its doctype and authored CSP stay intact.
|
|
5
19
|
* The script only marks scrolling elements so their scrollbars show while scrolling; an authored
|
|
6
20
|
* CSP that blocks inline scripts leaves the hover-only behavior of the stylesheet.
|
|
7
21
|
*/
|
|
8
|
-
export const injectGuestDocumentStyles = (html) => `${html}\n<style data-openchamber-guest-styles>${GUEST_SCROLLBAR_CSS}</style>\n<script data-openchamber-guest-scrollbar>${GUEST_SCROLLBAR_SCRIPT}</script>`;
|
|
22
|
+
export const injectGuestDocumentStyles = (html) => `${declareColorScheme(html)}\n<style data-openchamber-guest-styles>${GUEST_SCROLLBAR_CSS}</style>\n<script data-openchamber-guest-scrollbar>${GUEST_SCROLLBAR_SCRIPT}</script>`;
|
|
@@ -7,21 +7,50 @@ import request from 'supertest';
|
|
|
7
7
|
import { GUEST_SCROLLBAR_CSS, GUEST_SCROLLBAR_SCRIPT } from '@openchamber/sdk';
|
|
8
8
|
import { injectGuestDocumentStyles } from './html-styles.js';
|
|
9
9
|
import { registerGuestRoutes } from './routes.js';
|
|
10
|
-
import { writeExtensionStore } from './persist.js';
|
|
10
|
+
import { setCapabilityGrants, writeExtensionStore } from './persist.js';
|
|
11
11
|
|
|
12
12
|
const roots = [];
|
|
13
13
|
afterEach(async () => { await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true }))); });
|
|
14
14
|
|
|
15
|
+
describe('approved origins in the frame policy', () => {
|
|
16
|
+
test('open only once the user approved exactly the declared list', async () => {
|
|
17
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-guest-origins-')); roots.push(root);
|
|
18
|
+
const packageRoot = path.join(root, 'guest'); await fs.mkdir(packageRoot);
|
|
19
|
+
await fs.writeFile(path.join(packageRoot, 'index.html'), '<!doctype html><html><head></head><body></body></html>');
|
|
20
|
+
await fs.writeFile(path.join(packageRoot, 'package.json'), JSON.stringify({ name: 'guest', version: '1.0.0', openchamber: { apiVersion: 1, contributes: { panel: { id: 'fonts-guest', name: 'Fonts', icon: 'apps', entry: 'index.html' }, origins: ['https://fonts.example.com'] } } }));
|
|
21
|
+
const persistPath = path.join(root, 'extensions.json');
|
|
22
|
+
await writeExtensionStore(persistPath, { paths: [packageRoot], sources: { [packageRoot]: 'path' } });
|
|
23
|
+
const app = express(); registerGuestRoutes(app, { openchamberDataDir: root });
|
|
24
|
+
const policy = async () => (await request(app).get('/api/guests/fonts-guest/index.html').set('Host', 'oc.test').expect(200)).headers['content-security-policy'];
|
|
25
|
+
|
|
26
|
+
expect(await policy()).not.toContain('https://fonts.example.com');
|
|
27
|
+
await setCapabilityGrants('fonts-guest', persistPath, ['origins'], { origins: ['https://fonts.example.com'] });
|
|
28
|
+
const approved = await policy();
|
|
29
|
+
expect(approved).toContain('font-src \'self\' data: blob: https://fonts.example.com');
|
|
30
|
+
expect(approved).toContain('connect-src oc.test/api/guests/fonts-guest/ https://fonts.example.com');
|
|
31
|
+
expect(approved).not.toMatch(/script-src[^;]*fonts\.example\.com/);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
15
35
|
describe('guest document styles', () => {
|
|
16
36
|
test('preserves doctypes, CSP, and tag-like text inside authored scripts', () => {
|
|
17
37
|
const html = '<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="style-src \'self\'"><script>const text = "</head><head>";</script></head><body>Guest</body></html>';
|
|
18
38
|
const decorated = injectGuestDocumentStyles(html);
|
|
19
|
-
|
|
39
|
+
const meta = '<meta name="color-scheme" content="light dark">';
|
|
40
|
+
expect(decorated.startsWith(`<!doctype html>${meta}${html.slice('<!doctype html>'.length)}`)).toBe(true);
|
|
20
41
|
expect(decorated).toContain(GUEST_SCROLLBAR_CSS);
|
|
21
42
|
expect(decorated).toContain('data-openchamber-guest-styles');
|
|
22
43
|
expect(decorated).toContain(`<script data-openchamber-guest-scrollbar>${GUEST_SCROLLBAR_SCRIPT}</script>`);
|
|
23
44
|
});
|
|
24
45
|
|
|
46
|
+
test('declares the color scheme before any authored content', () => {
|
|
47
|
+
const meta = '<meta name="color-scheme" content="light dark">';
|
|
48
|
+
expect(injectGuestDocumentStyles('<html><body>x</body></html>').startsWith(`${meta}<html>`)).toBe(true);
|
|
49
|
+
expect(injectGuestDocumentStyles('\n<!DOCTYPE html>\n<html></html>').startsWith(`\n<!DOCTYPE html>${meta}\n<html>`)).toBe(true);
|
|
50
|
+
// A doctype-looking string later in the document is authored text, not the doctype.
|
|
51
|
+
expect(injectGuestDocumentStyles('<p>"<!doctype html>"</p>').startsWith(`${meta}<p>`)).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
25
54
|
test('serves scrollbar defaults to existing guests with or without an asset token', async () => {
|
|
26
55
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-guest-styles-')); roots.push(root);
|
|
27
56
|
const packageRoot = path.join(root, 'guest'); await fs.mkdir(packageRoot);
|
|
@@ -33,8 +62,13 @@ describe('guest document styles', () => {
|
|
|
33
62
|
await writeExtensionStore(path.join(root, 'extensions.json'), { paths: [packageRoot], sources: { [packageRoot]: 'path' } });
|
|
34
63
|
const app = express(); registerGuestRoutes(app, { openchamberDataDir: root });
|
|
35
64
|
for (const suffix of ['', '?oc_url_token=fixture-scope']) {
|
|
36
|
-
const response = await request(app).get(`/api/guests/old-guest/index.html${suffix}`).expect(200);
|
|
37
|
-
|
|
65
|
+
const response = await request(app).get(`/api/guests/old-guest/index.html${suffix}`).set('Host', 'oc.example:3000').expect(200);
|
|
66
|
+
// Sandboxed and off the network: its own package path is the one place it may connect.
|
|
67
|
+
const csp = response.headers['content-security-policy'];
|
|
68
|
+
expect(csp).toMatch(/^sandbox allow-scripts; default-src 'none';/);
|
|
69
|
+
expect(csp).toContain('connect-src oc.example:3000/api/guests/old-guest/;');
|
|
70
|
+
// Fonts and fetch from the null-origin frame are CORS requests.
|
|
71
|
+
expect(response.headers['access-control-allow-origin']).toBe('null');
|
|
38
72
|
expect(response.headers['cache-control']).toBe('no-store');
|
|
39
73
|
expect(response.text).toContain(GUEST_SCROLLBAR_CSS);
|
|
40
74
|
expect(response.text).toContain(GUEST_SCROLLBAR_SCRIPT);
|
|
@@ -42,6 +76,21 @@ describe('guest document styles', () => {
|
|
|
42
76
|
expect(response.text).toContain(suffix ? 'main.js?oc_url_token=fixture-scope' : 'src="main.js"');
|
|
43
77
|
}
|
|
44
78
|
expect((await request(app).get('/api/guests/old-guest/main.js').expect(200)).text).toBe(script);
|
|
79
|
+
// A Host that is not a plain host[:port] never reaches the policy: no connections at all.
|
|
80
|
+
// The app UI draws a package icon as a CSS mask, a CORS fetch from its own
|
|
81
|
+
// origin; the answer the server's CORS layer gave it must survive.
|
|
82
|
+
const uiApp = express();
|
|
83
|
+
uiApp.use((req, res, next) => {
|
|
84
|
+
if (req.headers.origin === 'openchamber-ui://app') res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
|
|
85
|
+
next();
|
|
86
|
+
});
|
|
87
|
+
registerGuestRoutes(uiApp, { openchamberDataDir: root });
|
|
88
|
+
const fromUi = await request(uiApp).get('/api/guests/old-guest/main.js').set('Origin', 'openchamber-ui://app').expect(200);
|
|
89
|
+
expect(fromUi.headers['access-control-allow-origin']).toBe('openchamber-ui://app');
|
|
90
|
+
const fromFrame = await request(uiApp).get('/api/guests/old-guest/main.js').set('Origin', 'null').expect(200);
|
|
91
|
+
expect(fromFrame.headers['access-control-allow-origin']).toBe('null');
|
|
92
|
+
const forged = await request(app).get('/api/guests/old-guest/index.html').set('Host', "evil.test; connect-src *").expect(200);
|
|
93
|
+
expect(forged.headers['content-security-policy']).toContain("connect-src 'none';");
|
|
45
94
|
expect(await fs.readFile(path.join(packageRoot, 'index.html'), 'utf8')).toBe(html);
|
|
46
95
|
});
|
|
47
96
|
});
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { stopGuestService } from './service.js';
|
|
14
14
|
import { cloneGitRepository, isHttpsZipUrl, isPublicHostname, parseGitInstallUrl, publicAddressesOf } from './clone.js';
|
|
15
15
|
import { isReservedBuiltInId } from './builtins.js';
|
|
16
|
+
import { enterpriseBlockedCapabilities } from './enterprise.js';
|
|
16
17
|
import { extractZipBuffer, unwrapGuestRoot } from './extract-zip.js';
|
|
17
18
|
import {
|
|
18
19
|
guestCopiesDir,
|
|
@@ -104,6 +105,11 @@ const installCopiedGuest = async ({ source, prepare, persistPath, openchamberVer
|
|
|
104
105
|
await removeDir(staging);
|
|
105
106
|
return { ok: false, code: 'reserved-id' };
|
|
106
107
|
}
|
|
108
|
+
const blocked = enterpriseBlockedCapabilities(inspected.guest, { source, gitUrl: origin?.url });
|
|
109
|
+
if (blocked.length > 0) {
|
|
110
|
+
await removeDir(staging);
|
|
111
|
+
return { ok: false, code: 'enterprise-mode', capabilities: blocked };
|
|
112
|
+
}
|
|
107
113
|
const dest = path.join(copies, inspected.guest.id);
|
|
108
114
|
const store = await readExtensionStore(persistPath);
|
|
109
115
|
// The store holds the copy's realpath (on macOS /tmp is a symlink, so
|
|
@@ -306,6 +312,10 @@ export const installGuestFromPath = async (rawPath, persistPath, { openchamberVe
|
|
|
306
312
|
if (!inspected.ok) {
|
|
307
313
|
return inspected;
|
|
308
314
|
}
|
|
315
|
+
const blocked = enterpriseBlockedCapabilities(inspected.guest, { source: 'path' });
|
|
316
|
+
if (blocked.length > 0) {
|
|
317
|
+
return { ok: false, code: 'enterprise-mode', capabilities: blocked };
|
|
318
|
+
}
|
|
309
319
|
return persistGuest(inspected.guest, root, 'path', persistPath, { replace });
|
|
310
320
|
};
|
|
311
321
|
|
|
@@ -32,6 +32,7 @@ const storeSchema = z.object({
|
|
|
32
32
|
|
|
33
33
|
const capabilityScopeSchema = z.object({
|
|
34
34
|
filesystem: z.array(z.string().min(1)).optional(),
|
|
35
|
+
origins: z.array(z.string().min(1)).optional(),
|
|
35
36
|
apiOrigin: z.string().min(1).optional(),
|
|
36
37
|
oauth: z.object({
|
|
37
38
|
authorizeUrl: z.string().min(1),
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
GUEST_GENERATE_TEXT_MAX,
|
|
14
14
|
GUEST_FILE_CONTENT_MAX,
|
|
15
15
|
GUEST_FILE_PATH_MAX,
|
|
16
|
+
guestFramePolicy,
|
|
16
17
|
isGuestRequestPath,
|
|
17
18
|
requestedGuestCapabilities,
|
|
18
19
|
resolveIntegrationAuth,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
|
|
21
22
|
import {
|
|
22
23
|
findInstalledGuest,
|
|
24
|
+
hasGuestFrame,
|
|
23
25
|
isGuestPanelId,
|
|
24
26
|
listInstalledGuests,
|
|
25
27
|
resolveGuestServedFile,
|
|
@@ -106,6 +108,11 @@ const generateBodySchema = z.object({
|
|
|
106
108
|
maxOutputTokens: z.number().int().min(1).max(GUEST_GENERATE_OUTPUT_TOKENS_MAX).optional(),
|
|
107
109
|
});
|
|
108
110
|
|
|
111
|
+
const providerHeaderSchema = z.string().trim().min(1).max(200);
|
|
112
|
+
|
|
113
|
+
// A Host header safe to echo into a CSP source: hostname or [IPv6], optional port.
|
|
114
|
+
const guestHostSchema = z.string().regex(/^(?:[A-Za-z0-9.-]+|\[[0-9A-Fa-f:.]+\])(?::\d{1,5})?$/);
|
|
115
|
+
|
|
109
116
|
const socketOverrideBodySchema = z.object({
|
|
110
117
|
id: z.string().trim().regex(/^[a-z][a-z0-9-]*$/).max(64),
|
|
111
118
|
path: z.union([
|
|
@@ -182,6 +189,10 @@ const sendInstallResult = (res, result) => {
|
|
|
182
189
|
if (result.code === 'host-too-old' && result.required) {
|
|
183
190
|
body.required = result.required;
|
|
184
191
|
}
|
|
192
|
+
if (result.code === 'enterprise-mode') {
|
|
193
|
+
body.capabilities = result.capabilities;
|
|
194
|
+
return res.status(403).json(body);
|
|
195
|
+
}
|
|
185
196
|
if (conflict && result.id) {
|
|
186
197
|
body.id = result.id;
|
|
187
198
|
}
|
|
@@ -588,7 +599,7 @@ export const registerGuestRoutes = (app, {
|
|
|
588
599
|
try {
|
|
589
600
|
const result = await runGuestStorage(persistPath, req.params.id, parsed.data, async () => {
|
|
590
601
|
const guest = await loadGuest(req.params.id);
|
|
591
|
-
if (!guest || guest.enabled === false || (
|
|
602
|
+
if (!guest || guest.enabled === false || !hasGuestFrame(guest)) throw new Error('Extension is unavailable.');
|
|
592
603
|
if (!requestedGuestCapabilities(guest).every((capability) => guest.capabilityGrants.includes(capability))) throw new Error('Extension needs approval.');
|
|
593
604
|
});
|
|
594
605
|
return res.json(result);
|
|
@@ -660,6 +671,8 @@ export const registerGuestRoutes = (app, {
|
|
|
660
671
|
return res.status(400).json({ error: 'invalid-request' });
|
|
661
672
|
}
|
|
662
673
|
const { directory } = await resolveOptionalProjectDirectory(req);
|
|
674
|
+
// The host names the composer's provider; the model stays on it.
|
|
675
|
+
const provider = providerHeaderSchema.safeParse(req.get('x-openchamber-provider'));
|
|
663
676
|
const { generateSmallModelText } = await getSmallModelService();
|
|
664
677
|
let generated;
|
|
665
678
|
try {
|
|
@@ -668,6 +681,7 @@ export const registerGuestRoutes = (app, {
|
|
|
668
681
|
system: parsed.data.system,
|
|
669
682
|
maxOutputTokens: parsed.data.maxOutputTokens,
|
|
670
683
|
directory: directory || undefined,
|
|
684
|
+
preferredProviderID: provider.success ? provider.data : undefined,
|
|
671
685
|
});
|
|
672
686
|
} catch (error) {
|
|
673
687
|
const statusCode = Number(error?.statusCode) || 500;
|
|
@@ -719,6 +733,10 @@ export const registerGuestRoutes = (app, {
|
|
|
719
733
|
// partial grant would leave the guest half-working, so both are refused.
|
|
720
734
|
const requested = requestedGuestCapabilities(guest);
|
|
721
735
|
const granted = parsed.data.granted;
|
|
736
|
+
// Enterprise mode refuses these for this package; approving cannot lift that.
|
|
737
|
+
if (guest.enterpriseBlocked?.some((capability) => granted.includes(capability))) {
|
|
738
|
+
return res.status(403).json({ error: 'enterprise-mode', capabilities: guest.enterpriseBlocked });
|
|
739
|
+
}
|
|
722
740
|
const matchesRequest = granted.length === requested.length && requested.every((capability) => granted.includes(capability));
|
|
723
741
|
if (granted.length > 0 && !matchesRequest) {
|
|
724
742
|
return res.status(400).json({ error: 'invalid-request' });
|
|
@@ -822,7 +840,7 @@ export const registerGuestRoutes = (app, {
|
|
|
822
840
|
return res.status(404).end();
|
|
823
841
|
}
|
|
824
842
|
const served = await resolveGuestServedFile(guest.packageRoot, relativePath, {
|
|
825
|
-
hasRuntime:
|
|
843
|
+
hasRuntime: hasGuestFrame(guest),
|
|
826
844
|
});
|
|
827
845
|
if (!served) {
|
|
828
846
|
return res.status(404).end();
|
|
@@ -842,10 +860,27 @@ export const registerGuestRoutes = (app, {
|
|
|
842
860
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
843
861
|
res.setHeader('Cache-Control', 'no-store');
|
|
844
862
|
// Guest files are third-party code served from the OpenChamber origin.
|
|
845
|
-
// The rail embeds them in a sandboxed iframe;
|
|
863
|
+
// The rail embeds them in a sandboxed iframe; `sandbox` makes the
|
|
846
864
|
// document sandboxed even when opened directly, so a guest page can
|
|
847
|
-
// never run with the user's session on the app origin.
|
|
848
|
-
|
|
865
|
+
// never run with the user's session on the app origin. The rest keeps
|
|
866
|
+
// it off the network (`guestFramePolicy`): its connections may reach
|
|
867
|
+
// only its own package path, named by the host the browser used, since
|
|
868
|
+
// a sandboxed document has no origin of its own to say `'self'` with.
|
|
869
|
+
const hostHeader = guestHostSchema.safeParse(req.headers.host);
|
|
870
|
+
const host = hostHeader.success ? hostHeader.data : null;
|
|
871
|
+
const connectSource = host ? `${host}/api/guests/${id}/` : null;
|
|
872
|
+
// Origins the user approved for this exact list (`effectiveGrants`) open too.
|
|
873
|
+
const origins = guest.capabilityGrants?.includes('origins') && Array.isArray(guest.origins) ? guest.origins : [];
|
|
874
|
+
res.setHeader('Content-Security-Policy', `sandbox allow-scripts; ${guestFramePolicy(connectSource, origins)}`);
|
|
875
|
+
// The sandboxed frame's origin is `null`, and fonts (always) and fetch
|
|
876
|
+
// are CORS requests: without this its own package fonts and files are
|
|
877
|
+
// refused. `null`, not `*`: only opaque-origin documents may read them.
|
|
878
|
+
// The app UI's own origin, already allowed by the server's CORS layer,
|
|
879
|
+
// keeps its answer: the rail draws a package icon as a CSS mask, which is
|
|
880
|
+
// a CORS fetch from openchamber-ui:// or the dev origin.
|
|
881
|
+
if (!res.getHeader('Access-Control-Allow-Origin')) {
|
|
882
|
+
res.setHeader('Access-Control-Allow-Origin', 'null');
|
|
883
|
+
}
|
|
849
884
|
res.send(body);
|
|
850
885
|
} catch (error) {
|
|
851
886
|
console.error('Failed to serve guest asset:', error);
|
|
@@ -6,7 +6,8 @@ import { parseManifestJson } from '@openchamber/sdk/schemas';
|
|
|
6
6
|
import { requestedGuestCapabilities } from '@openchamber/sdk';
|
|
7
7
|
|
|
8
8
|
import { inspectGuestPackage, invalidateGuestCatalog, listInstalledGuests } from './catalog.js';
|
|
9
|
-
import {
|
|
9
|
+
import { enterpriseBlockedCapabilities } from './enterprise.js';
|
|
10
|
+
import { cloneGitRepository, prepareGuestGitNetwork, runGit, runGitNetwork } from './clone.js';
|
|
10
11
|
import { unwrapGuestRoot } from './extract-zip.js';
|
|
11
12
|
import { guestCopiesDir, isCopiedGuestRoot } from './persist.js';
|
|
12
13
|
import { stopGuestService } from './service.js';
|
|
@@ -95,7 +96,7 @@ export const checkGuestUpdate = async ({ guest, origin, gitBinary, timeoutMs = C
|
|
|
95
96
|
if (!network) {
|
|
96
97
|
return { available: false, error: 'fetch-failed' };
|
|
97
98
|
}
|
|
98
|
-
const fetched = await
|
|
99
|
+
const fetched = await runGitNetwork(
|
|
99
100
|
[...network.args, 'fetch', '--depth', '1', '--', 'origin', origin.ref ?? 'HEAD'],
|
|
100
101
|
{ gitBinary, cwd, timeoutMs, env: network.env },
|
|
101
102
|
);
|
|
@@ -250,6 +251,12 @@ export const updateGuest = async ({ guest, origin, persistPath, openchamberVersi
|
|
|
250
251
|
await removeDir(staging);
|
|
251
252
|
return { ok: false, code: 'invalid-manifest' };
|
|
252
253
|
}
|
|
254
|
+
// A version that starts asking for what enterprise mode refuses from this
|
|
255
|
+
// repository stays uninstalled; the current one keeps working.
|
|
256
|
+
if (enterpriseBlockedCapabilities(inspected.guest, { source: 'git', gitUrl: origin.url }).length > 0) {
|
|
257
|
+
await removeDir(staging);
|
|
258
|
+
return { ok: false, code: 'enterprise-mode' };
|
|
259
|
+
}
|
|
253
260
|
} catch {
|
|
254
261
|
await removeDir(staging);
|
|
255
262
|
return { ok: false, code: 'clone-failed' };
|
|
@@ -7,7 +7,7 @@ This module provides notification message preparation utilities for the web serv
|
|
|
7
7
|
- `packages/web/server/lib/notifications/index.js`: public entrypoint imported by `packages/web/server/index.js`.
|
|
8
8
|
- `packages/web/server/lib/notifications/routes.js`: route registration for push, visibility, and session status/attention endpoints.
|
|
9
9
|
- `packages/web/server/lib/notifications/push-runtime.js`: push subscription persistence, VAPID initialization, and UI visibility runtime.
|
|
10
|
-
- `packages/web/server/lib/notifications/apns-runtime.js`: native iOS APNs device-token persistence + delivery. Two modes: **relay** (default — sign + POST tokens + generic text to the central Cloudflare relay `https://api.openchamber.dev/v1/push/send`, which holds the single project APNs key) and **direct** (fallback — sign ES256 JWT with Node crypto + HTTP/2, when `OPENCHAMBER_PUSH_RELAY_DISABLED=true`). Each server has an auto-generated ECDSA P-256 keypair (`getOrCreateRelayKeypair`, persisted in settings); it binds tokens on the relay (`/v1/push/register-token`) and signs every relay request, so the relay only delivers to tokens bound to that server. APNs is the native app's sole notification channel (no local notifications) and is NOT gated on UI visibility — iOS suppresses the foreground banner instead. Mobile push carries only generic text (scenario title + session name) — see `APNS.md`.
|
|
10
|
+
- `packages/web/server/lib/notifications/apns-runtime.js`: native iOS APNs device-token persistence + delivery. Two modes: **relay** (default — sign + POST tokens + generic text to the central Cloudflare relay `https://api.openchamber.dev/v1/push/send`, which holds the single project APNs key) and **direct** (fallback — sign ES256 JWT with Node crypto + HTTP/2, when `OPENCHAMBER_PUSH_RELAY_DISABLED=true`). Each server has an auto-generated ECDSA P-256 keypair (`getOrCreateRelayKeypair`, persisted in settings); it binds tokens on the relay (`/v1/push/register-token`) and signs every relay request, so the relay only delivers to tokens bound to that server. APNs is the native app's sole notification channel (no local notifications) and is NOT gated on UI visibility — iOS suppresses the foreground banner instead. Mobile push carries only generic text (scenario title + session name) — see `APNS.md`. In enterprise mode (`../enterprise-mode.js`) `fanoutPush` also drops the session name from APNs and sends web push with the scenario title, an empty body and the deep link only, since web push leaves through the browser vendor's push service. Desktop notifications and in-app toasts stay local and keep the full text.
|
|
11
11
|
- `packages/web/server/lib/notifications/emitter-runtime.js`: desktop/stdout + UI SSE notification emission runtime.
|
|
12
12
|
- `packages/web/server/lib/notifications/emit-route.js`: `POST /api/notifications/emit` for OpenCode plugins.
|
|
13
13
|
- `packages/web/server/lib/notifications/runtime.js`: trigger runtime for OpenCode event-driven notification fanout.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { unwrapOpenCodeResponse } from '../opencode/response-envelope.js';
|
|
2
2
|
import { createSessionActivityProbe } from '../opencode/session-activity.js';
|
|
3
|
+
import { isEnterpriseMode } from '../enterprise-mode.js';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
export const createNotificationTriggerRuntime = (deps) => {
|
|
@@ -77,14 +78,17 @@ export const createNotificationTriggerRuntime = (deps) => {
|
|
|
77
78
|
goal_budget: 'Goal reached its token budget',
|
|
78
79
|
};
|
|
79
80
|
|
|
81
|
+
const genericTitleOf = (payload) => APNS_TITLE_BY_TYPE[payload?.data?.type] || 'Agent update';
|
|
82
|
+
|
|
80
83
|
const toApnsGenericPayload = (payload) => {
|
|
81
84
|
const data = payload?.data && typeof payload.data === 'object' ? payload.data : {};
|
|
82
85
|
const sessionName = typeof data.sessionName === 'string' && data.sessionName.trim().length > 0
|
|
83
86
|
? data.sessionName.trim()
|
|
84
87
|
: 'Session';
|
|
85
88
|
return {
|
|
86
|
-
title:
|
|
87
|
-
|
|
89
|
+
title: genericTitleOf(payload),
|
|
90
|
+
// A session name is derived from the conversation.
|
|
91
|
+
body: isEnterpriseMode() ? '' : sessionName,
|
|
88
92
|
badge: trackPushAndCountBadge(typeof payload?.tag === 'string' ? payload.tag : undefined),
|
|
89
93
|
tag: payload?.tag,
|
|
90
94
|
// sessionId is forwarded so a tapped push can deep-link; it is an opaque id, not content.
|
|
@@ -95,6 +99,16 @@ export const createNotificationTriggerRuntime = (deps) => {
|
|
|
95
99
|
// Fan a notification out to every delivery channel: browser web-push (full templated
|
|
96
100
|
// payload) and native iOS APNs (generic model-based text). Both share the dedup tag and
|
|
97
101
|
// `requireNoSse` focus gate; a failure in one channel must not block the other.
|
|
102
|
+
// Web push leaves through the browser vendor's push service. It is
|
|
103
|
+
// encrypted, but enterprise mode keeps conversation content off every
|
|
104
|
+
// channel it does not control: the scenario title and the deep link only.
|
|
105
|
+
const toWebPushPayload = (payload) => {
|
|
106
|
+
if (!isEnterpriseMode()) return payload;
|
|
107
|
+
// Every payload built in this file carries a `data` object.
|
|
108
|
+
const { sessionName: _sessionName, ...rest } = payload.data ?? {};
|
|
109
|
+
return { ...payload, title: genericTitleOf(payload), body: '', data: rest };
|
|
110
|
+
};
|
|
111
|
+
|
|
98
112
|
const fanoutPush = (payload, options) => {
|
|
99
113
|
// Presence-aware routing: if any interactive (non-mobile) client — desktop/web/vscode — is
|
|
100
114
|
// currently visible, it already shows the in-app notification, so skip the native push to the
|
|
@@ -102,7 +116,7 @@ export const createNotificationTriggerRuntime = (deps) => {
|
|
|
102
116
|
// also skip toApnsGenericPayload, so the badge isn't incremented for an undelivered push.
|
|
103
117
|
const interactiveVisible = isAnyInteractiveClientVisible?.() === true;
|
|
104
118
|
return Promise.all([
|
|
105
|
-
Promise.resolve(sendPushToAllUiSessions?.(payload, options)).catch((error) => {
|
|
119
|
+
Promise.resolve(sendPushToAllUiSessions?.(toWebPushPayload(payload), options)).catch((error) => {
|
|
106
120
|
console.warn('[Push] web-push fanout failed:', error?.message ?? error);
|
|
107
121
|
}),
|
|
108
122
|
interactiveVisible
|
|
@@ -699,10 +713,10 @@ export const createNotificationTriggerRuntime = (deps) => {
|
|
|
699
713
|
return;
|
|
700
714
|
}
|
|
701
715
|
|
|
702
|
-
//
|
|
703
|
-
//
|
|
704
|
-
//
|
|
705
|
-
if (await (getIsSessionAutoAccepting?.(sessionId, notificationDirectory)
|
|
716
|
+
// The session (or an ancestor) answers permissions by itself. Skip the
|
|
717
|
+
// notification when this request was answered automatically; one the
|
|
718
|
+
// safety net held for the user still notifies.
|
|
719
|
+
if (await (getIsSessionAutoAccepting?.(sessionId, notificationDirectory, requestId)
|
|
706
720
|
?? isSessionAutoAccepting(sessionId, notificationDirectory))) {
|
|
707
721
|
if (requestKey) notifiedPermissionRequests.add(requestKey);
|
|
708
722
|
return;
|
|
@@ -716,7 +730,7 @@ export const createNotificationTriggerRuntime = (deps) => {
|
|
|
716
730
|
const timer = setTimeout(async () => {
|
|
717
731
|
pushPermissionDebounceTimers.delete(sessionId);
|
|
718
732
|
|
|
719
|
-
if (await (getIsSessionAutoAccepting?.(sessionId, notificationDirectory)
|
|
733
|
+
if (await (getIsSessionAutoAccepting?.(sessionId, notificationDirectory, requestId)
|
|
720
734
|
?? isSessionAutoAccepting(sessionId, notificationDirectory))) {
|
|
721
735
|
if (requestKey) notifiedPermissionRequests.add(requestKey);
|
|
722
736
|
return;
|
|
@@ -127,6 +127,51 @@ describe('ready notification while background subagents run', () => {
|
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
+
describe('push content in enterprise mode', () => {
|
|
131
|
+
const makePushRuntime = () => {
|
|
132
|
+
const sendPushToAllUiSessions = vi.fn(async () => undefined);
|
|
133
|
+
const sendApnsToAllUiSessions = vi.fn(async () => undefined);
|
|
134
|
+
const runtime = createNotificationTriggerRuntime({
|
|
135
|
+
readSettingsFromDisk: async () => ({ nativeNotificationsEnabled: true, notificationMode: 'always', notifyOnCompletion: true }),
|
|
136
|
+
prepareNotificationLastMessage: async ({ message }) => message,
|
|
137
|
+
buildTemplateVariables: async () => ({ session_name: 'Fix the billing export' }),
|
|
138
|
+
extractLastMessageText: () => 'The customer table is migrated',
|
|
139
|
+
fetchLastAssistantMessageText: async () => 'The customer table is migrated',
|
|
140
|
+
resolveNotificationTemplate: (template, variables) => template.replace('{last_message}', variables.last_message ?? ''),
|
|
141
|
+
shouldApplyResolvedTemplateMessage: () => true,
|
|
142
|
+
emitDesktopNotification: vi.fn(() => true),
|
|
143
|
+
broadcastUiNotification: vi.fn(),
|
|
144
|
+
sendPushToAllUiSessions,
|
|
145
|
+
sendApnsToAllUiSessions,
|
|
146
|
+
isAnyInteractiveClientVisible: () => false,
|
|
147
|
+
buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
|
|
148
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
149
|
+
readSessionMetadata: async () => ({}),
|
|
150
|
+
});
|
|
151
|
+
return { runtime, sendPushToAllUiSessions, sendApnsToAllUiSessions };
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
it('sends only the scenario title and the deep link, on both channels', async () => {
|
|
155
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
156
|
+
vi.stubGlobal('fetch', vi.fn(async () => Response.json({ data: {} })));
|
|
157
|
+
process.env.OPENCHAMBER_ENTERPRISE_MODE = 'true';
|
|
158
|
+
try {
|
|
159
|
+
const { runtime, sendPushToAllUiSessions, sendApnsToAllUiSessions } = makePushRuntime();
|
|
160
|
+
await runtime.maybeSendPushForTrigger(stepStarted('ses_e', 'msg_e'));
|
|
161
|
+
await runtime.maybeSendPushForTrigger(turnEnded('ses_e'));
|
|
162
|
+
|
|
163
|
+
const web = sendPushToAllUiSessions.mock.calls[0][0];
|
|
164
|
+
expect(web).toMatchObject({ title: 'Agent response is ready', body: '', data: { sessionId: 'ses_e', type: 'ready' } });
|
|
165
|
+
expect(web.data.sessionName).toBeUndefined();
|
|
166
|
+
expect(sendApnsToAllUiSessions.mock.calls[0][0]).toMatchObject({ title: 'Agent response is ready', body: '' });
|
|
167
|
+
expect(JSON.stringify([web, sendApnsToAllUiSessions.mock.calls[0][0]])).not.toMatch(/billing|customer/);
|
|
168
|
+
} finally {
|
|
169
|
+
delete process.env.OPENCHAMBER_ENTERPRISE_MODE;
|
|
170
|
+
vi.unstubAllGlobals();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
130
175
|
describe('subagent finish with subagent notifications off', () => {
|
|
131
176
|
const makeSubtaskRuntime = () => {
|
|
132
177
|
const emitDesktopNotification = vi.fn(() => true);
|
|
@@ -236,6 +236,32 @@ export const createSessionMetadataStore = ({
|
|
|
236
236
|
});
|
|
237
237
|
};
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Like `setSessionMetadata`, but the patch is decided from the record as it
|
|
241
|
+
* is when this session's turn in the write queue comes: `decide(current)`
|
|
242
|
+
* returns a merge patch, or null to leave the record alone. A writer whose
|
|
243
|
+
* change depends on the current value (open only when not closed after the
|
|
244
|
+
* request) cannot be overtaken between its read and its write this way.
|
|
245
|
+
* Resolves `{ metadata, changed }`.
|
|
246
|
+
*/
|
|
247
|
+
const updateSessionMetadata = async (sessionID, decide, { directory = '' } = {}) => {
|
|
248
|
+
const id = asNonEmptyString(sessionID);
|
|
249
|
+
if (!id) throw new Error('a session id is required to store session metadata');
|
|
250
|
+
await loadLegacy();
|
|
251
|
+
|
|
252
|
+
return runForSession(id, async () => {
|
|
253
|
+
const fromLegacy = unmigrated.has(id);
|
|
254
|
+
const current = fromLegacy ? unmigrated.get(id) : await openCode.read(id, { directory });
|
|
255
|
+
if (current === null) throw new Error(`session ${id} was not found`);
|
|
256
|
+
const patch = decide(current);
|
|
257
|
+
if (!isPlainObject(patch)) return { metadata: current, changed: false };
|
|
258
|
+
const merged = mergeMetadataPatch(current, patch);
|
|
259
|
+
await openCode.write(id, merged, { directory });
|
|
260
|
+
if (fromLegacy) await forgetLegacy(id);
|
|
261
|
+
return { metadata: merged, changed: true };
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
|
|
239
265
|
/**
|
|
240
266
|
* Pushes every legacy entry to OpenCode. A session OpenCode no longer knows
|
|
241
267
|
* has nothing to receive its metadata, so its entry is dropped. Any other
|
|
@@ -278,6 +304,7 @@ export const createSessionMetadataStore = ({
|
|
|
278
304
|
return {
|
|
279
305
|
get,
|
|
280
306
|
setSessionMetadata,
|
|
307
|
+
updateSessionMetadata,
|
|
281
308
|
migrateLegacy,
|
|
282
309
|
listUnmigrated,
|
|
283
310
|
legacyPath,
|
|
@@ -148,6 +148,24 @@ describe('createSessionMetadataStore', () => {
|
|
|
148
148
|
expect(openCode.sessions.get('ses_1')).toEqual({ keep: true });
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
+
it('decides a conditional patch against the record as it is at write time', async () => {
|
|
152
|
+
const openCode = createFakeOpenCode({ ses_1: { openchamber: { work: { state: 'open' } } } });
|
|
153
|
+
const { store } = makeStore(openCode);
|
|
154
|
+
const closeUnlessDone = (current) => (current.openchamber?.work?.state === 'done'
|
|
155
|
+
? null
|
|
156
|
+
: { openchamber: { work: { state: 'done' } } });
|
|
157
|
+
|
|
158
|
+
// Queued behind the first write, the second decision sees its result.
|
|
159
|
+
const [first, second] = await Promise.all([
|
|
160
|
+
store.updateSessionMetadata('ses_1', closeUnlessDone),
|
|
161
|
+
store.updateSessionMetadata('ses_1', closeUnlessDone),
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
expect(first).toEqual({ metadata: { openchamber: { work: { state: 'done' } } }, changed: true });
|
|
165
|
+
expect(second.changed).toBe(false);
|
|
166
|
+
expect(openCode.write).toHaveBeenCalledTimes(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
151
169
|
it('rejects a missing id or a non-object patch', async () => {
|
|
152
170
|
const { store } = makeStore(createFakeOpenCode());
|
|
153
171
|
await expect(store.setSessionMetadata('', { a: 1 })).rejects.toThrow();
|