@openchamber/web 1.21.1 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-BO_2OW4E.js} +1 -1
- package/dist/assets/DiffView-CNnDxRmO.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-jADfXQnR.js +1 -0
- package/dist/assets/FilesView-8wdiG2mj.js +17 -0
- package/dist/assets/GitView-Cv2xH-S6.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-DUiIpERC.js} +1 -1
- package/dist/assets/LinearIssuesView-CoZ7pQN5.js +1 -0
- package/dist/assets/MarkdownImageGallery-DffjmciG.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +12 -0
- package/dist/assets/OnboardingScreen-CTZe6HZn.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BymkP9JA.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-BvwtCxW4.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-C1qvAm7m.js} +3 -3
- package/dist/assets/SettingsView-xGONHFGS.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-COzgfFxM.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-Dlhh_-oe.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-b9joNtXH.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-vqW3KKo5.js} +1 -1
- package/dist/assets/WalkthroughView-D-HFgdmM.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DUnyszhW.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-CV-DwAiX.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-Cv_4FoXm.js} +6 -5
- package/dist/assets/es-BIWNEbnS.js +16 -0
- package/dist/assets/{fr-CS7Csln9.js → fr-SD3OfMHJ.js} +6 -5
- package/dist/assets/index-CHUT_bDS.css +1 -0
- package/dist/assets/index-DDInLQDd.js +40 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-DLiD86ge.js} +1 -1
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-TNageFjy.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-JPmZOYSp.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-D7I9HofF.js} +7 -6
- package/dist/assets/{ko-CXuSfZv5.js → ko-BsVJM_PQ.js} +7 -6
- package/dist/assets/{main-D5RWr6sJ.js → main-DCB4JgVe.js} +2 -2
- package/dist/assets/main-De8Z5w49.js +928 -0
- package/dist/assets/markdownCore-BoQVG5-a.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-BtV7N5OF.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-DZV_sfX7.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Chmiz6hq.js} +4 -4
- package/dist/assets/{pl-BJxry0Mi.js → pl-XR9Bs8Be.js} +6 -5
- package/dist/assets/pt-BR-Due4be8g.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-8tXADjfl.js} +2 -2
- package/dist/assets/renderMobileApp-Cji7Hma5.js +25 -0
- package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +16 -0
- package/dist/assets/scheduledTasksApi-9e-UX6im.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CRpCl7UT.js} +1 -1
- package/dist/assets/tr-DBJcAv4y.js +7 -0
- package/dist/assets/uk-COYh2BaN.js +16 -0
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-CCgvcQ6u.js} +178 -170
- package/dist/assets/useInlineCommentController-BkfXnjNZ.js +2 -0
- package/dist/assets/useRootScrollLock-KzOUytpn.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BxpoC5Fp.js} +2 -2
- package/dist/assets/vendor-zod-DVWEh-IS.js +39 -0
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-B6QgbmTo.js} +4 -4
- package/dist/assets/zh-CN-Cjk6lzhc.js +16 -0
- package/dist/assets/{zh-TW-Dv8yyhN1.js → zh-TW-Dk0dOg03.js} +6 -5
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +35 -4
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -0
- package/server/lib/git/service.js +97 -17
- package/server/lib/git/service.test.js +153 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +148 -0
- package/server/lib/message-queue/runtime.js +818 -0
- package/server/lib/message-queue/runtime.test.js +426 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +5 -1
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/quota/DOCUMENTATION.md +2 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/opencode-go.js +1 -0
- package/server/lib/quota/providers/opencode-go.test.js +5 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +1 -0
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +1 -0
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +8 -2
- package/server/lib/small-model/call.test.js +23 -0
- package/server/lib/small-model/index.js +2 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/runtime.js +30 -7
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/index.js +1 -0
- package/dist/assets/CommitSection-DwGiXyjf.js +0 -1
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/ToolPartDiffPreview-C7kBQNAA.js +0 -8
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/es-DwyXCqaL.js +0 -15
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/pt-BR-DxLmkhdv.js +0 -15
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/uk-ClgQjmlw.js +0 -15
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-Ba6y8H-i.js +0 -15
|
@@ -34,6 +34,8 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
34
34
|
- `packages/web/server/lib/opencode/startup-performance.js`: opt-in startup phase diagnostics with fixed labels and numeric metadata allowlists.
|
|
35
35
|
- `packages/web/server/lib/agent-tool/runtime.js`: managed OpenCode custom-tool materialization, environment injection, loopback authentication, and fixed CLI action dispatch.
|
|
36
36
|
- `packages/web/server/lib/system-prompt/runtime.js`: opt-in managed OpenCode system-prompt optimizer materialization and plugin injection.
|
|
37
|
+
- `packages/web/server/lib/mcp-reconnect/runtime.js`: always-on managed OpenCode plugin that reconnects MCP servers OpenCode marked `failed`, with per-server backoff.
|
|
38
|
+
- `packages/web/server/lib/opencode/managed-plugin-config.js`: the one `OPENCODE_CONFIG_CONTENT` merge every managed plugin (agent tools, system prompt optimizer, MCP reconnect) appends itself through.
|
|
37
39
|
- `packages/web/server/lib/opencode/server-utils-runtime.js`: shared server runtime utilities for OpenCode proxy wiring, OpenCode port/readiness helpers, and snapshot fetchers.
|
|
38
40
|
- `packages/web/server/lib/opencode/openchamber-routes.js`: OpenChamber update and models metadata route registration.
|
|
39
41
|
- `packages/web/server/lib/opencode/pwa-manifest-routes.js`: PWA manifest route registration with recent-session shortcut resolution and short-lived caching.
|
|
@@ -130,7 +132,8 @@ The runtime maintains active-session count incrementally from idempotent activit
|
|
|
130
132
|
- `killProcessOnPort(port)`
|
|
131
133
|
|
|
132
134
|
Managed OpenCode launch also merges the environment returned by the agent-tool
|
|
133
|
-
runtime
|
|
135
|
+
runtime, the opt-in system prompt optimizer, and the always-on MCP reconnect
|
|
136
|
+
plugin, each appending its `file://` entry to the previous one's config. PATH and `OPENCODE_SERVER_PASSWORD` remain lifecycle-owned and cannot
|
|
134
137
|
be replaced by injected values. External OpenCode processes receive no
|
|
135
138
|
OpenChamber tool injection. Managed launch env strips AppImage `ARGV0` before
|
|
136
139
|
spawn so zsh-backed OpenCode tools do not rewrite child argv[0] to the AppImage
|
|
@@ -208,6 +211,7 @@ Managed health failures are classified as `timeout`, `connection_refused`, `conn
|
|
|
208
211
|
- `writeSettingsToDisk(settings)`
|
|
209
212
|
- `persistSettings(changes)`
|
|
210
213
|
- Persistent permission auto-accept policy is stored under `permissionAutoAccept`; execution ownership lives in `lib/permission-auto-accept/`.
|
|
214
|
+
- Queued follow-up messages live in `<data-dir>/message-queue.json`, not in settings; execution ownership lives in `lib/message-queue/`.
|
|
211
215
|
- Shared sidebar preferences are stored as validated top-level fields: `sidebarProjectDisplayMode`, `sidebarSessionGroupingMode`, `sidebarProjectSortOrder`, and `sidebarShowRecentSection`. Device-local picker selection and sticky-header state do not enter `settings.json`.
|
|
212
216
|
|
|
213
217
|
## Public exports (settings-helpers.js)
|
|
@@ -1065,6 +1065,7 @@ export const registerCommonRequestMiddleware = (app, dependencies) => {
|
|
|
1065
1065
|
req.path.startsWith('/api/push') ||
|
|
1066
1066
|
req.path.startsWith('/api/notifications') ||
|
|
1067
1067
|
req.path.startsWith('/api/permission-auto-accept') ||
|
|
1068
|
+
req.path.startsWith('/api/message-queue') ||
|
|
1068
1069
|
req.path.startsWith('/api/provider') ||
|
|
1069
1070
|
req.path.startsWith('/api/session-folders') ||
|
|
1070
1071
|
req.path.startsWith('/api/small-model') ||
|
|
@@ -4,6 +4,7 @@ import { registerSmallModelRoutes } from '../small-model/routes.js';
|
|
|
4
4
|
import { registerWalkthroughRoutes } from '../walkthrough/routes.js';
|
|
5
5
|
import { registerSessionGoalRoutes } from '../session-goal/routes.js';
|
|
6
6
|
import { registerGitHubRoutes } from '../github/routes.js';
|
|
7
|
+
import { registerLinearRoutes } from '../linear/routes.js';
|
|
7
8
|
import { registerGitRoutes } from '../git/routes.js';
|
|
8
9
|
import { registerDevServerRoutes } from '../dev-servers/routes.js';
|
|
9
10
|
import { registerMagicPromptRoutes } from '../magic-prompts/routes.js';
|
|
@@ -12,6 +13,7 @@ import { registerProjectContextRoutes } from '../project-context/routes.js';
|
|
|
12
13
|
import { registerAgentMemoryRoutes } from '../agent-memory/routes.js';
|
|
13
14
|
import { registerSessionKnowledgeRoutes } from '../session-knowledge/routes.js';
|
|
14
15
|
import { registerPermissionAutoAcceptRoutes } from '../permission-auto-accept/runtime.js';
|
|
16
|
+
import { registerMessageQueueRoutes } from '../message-queue/runtime.js';
|
|
15
17
|
import { registerConfigEntityRoutes } from './config-entity-routes.js';
|
|
16
18
|
import { registerSettingsUtilityRoutes } from './core-routes.js';
|
|
17
19
|
import { registerProjectIconRoutes } from './project-icon-routes.js';
|
|
@@ -131,6 +133,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
131
133
|
writeSseEvent,
|
|
132
134
|
emitSessionCreatedEvent,
|
|
133
135
|
permissionAutoAcceptRuntime,
|
|
136
|
+
messageQueueRuntime,
|
|
134
137
|
} = routeDependencies;
|
|
135
138
|
|
|
136
139
|
registerSettingsUtilityRoutes(app, {
|
|
@@ -140,6 +143,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
140
143
|
});
|
|
141
144
|
|
|
142
145
|
registerPermissionAutoAcceptRoutes(app, permissionAutoAcceptRuntime);
|
|
146
|
+
registerMessageQueueRoutes(app, messageQueueRuntime);
|
|
143
147
|
|
|
144
148
|
registerOpenCodeRoutes(app, {
|
|
145
149
|
crypto,
|
|
@@ -300,6 +304,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
300
304
|
registerWalkthroughRoutes(app, { getWalkthroughService });
|
|
301
305
|
registerSessionGoalRoutes(app);
|
|
302
306
|
registerGitHubRoutes(app);
|
|
307
|
+
registerLinearRoutes(app);
|
|
303
308
|
registerGitRoutes(app);
|
|
304
309
|
registerDevServerRoutes(app, { scanner: devServerScanner, getOwnPorts });
|
|
305
310
|
registerMagicPromptRoutes(app, {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parse as parseJsonc } from 'jsonc-parser';
|
|
2
|
+
|
|
3
|
+
const isJsonObject = (value) => value !== null && value !== undefined && Object.getPrototypeOf(value) === Object.prototype;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Append a managed OpenChamber plugin to the `plugin` list of an
|
|
7
|
+
* `OPENCODE_CONFIG_CONTENT` value.
|
|
8
|
+
*
|
|
9
|
+
* Existing entries are preserved; an earlier entry for the same URL is dropped
|
|
10
|
+
* so a restart never registers the same plugin twice. Every managed plugin
|
|
11
|
+
* (agent tools, system prompt optimizer, MCP reconnect) goes through this one
|
|
12
|
+
* merge so they compose in any order.
|
|
13
|
+
*
|
|
14
|
+
* @param {string | undefined} rawConfig the current `OPENCODE_CONFIG_CONTENT`, JSONC or unset
|
|
15
|
+
* @param {string} pluginUrl `file://` URL of the materialized plugin
|
|
16
|
+
* @param {string} purpose short noun phrase for the error message, e.g. "managed tool"
|
|
17
|
+
* @returns {string} the merged config as JSON
|
|
18
|
+
*/
|
|
19
|
+
export const appendManagedPlugin = (rawConfig, pluginUrl, purpose) => {
|
|
20
|
+
const errors = [];
|
|
21
|
+
const text = (rawConfig ?? '').trim();
|
|
22
|
+
const parsed = text ? parseJsonc(text, errors, { allowTrailingComma: true }) : {};
|
|
23
|
+
if (errors.length > 0 || !isJsonObject(parsed)) {
|
|
24
|
+
throw new Error(`OPENCODE_CONFIG_CONTENT must contain a valid JSON object before OpenChamber can inject its ${purpose}`);
|
|
25
|
+
}
|
|
26
|
+
if (parsed.plugin !== undefined && !Array.isArray(parsed.plugin)) {
|
|
27
|
+
throw new Error(`OPENCODE_CONFIG_CONTENT plugin must be an array before OpenChamber can inject its ${purpose}`);
|
|
28
|
+
}
|
|
29
|
+
const configured = Array.isArray(parsed.plugin) ? parsed.plugin : [];
|
|
30
|
+
parsed.plugin = [
|
|
31
|
+
...configured.filter((value) => value !== pluginUrl && (!Array.isArray(value) || value[0] !== pluginUrl)),
|
|
32
|
+
pluginUrl,
|
|
33
|
+
];
|
|
34
|
+
return JSON.stringify(parsed);
|
|
35
|
+
};
|
|
@@ -692,8 +692,8 @@ export const createSettingsRuntime = (deps) => {
|
|
|
692
692
|
return { settings, changed: false };
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
-
const defaultLight = '
|
|
696
|
-
const defaultDark = '
|
|
695
|
+
const defaultLight = 'openchamber-light';
|
|
696
|
+
const defaultDark = 'openchamber-dark';
|
|
697
697
|
|
|
698
698
|
let nextLightThemeId = hasLight ? settings.lightThemeId : undefined;
|
|
699
699
|
let nextDarkThemeId = hasDark ? settings.darkThemeId : undefined;
|
|
@@ -39,6 +39,35 @@ const createRuntime = async () => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
describe('settings runtime', () => {
|
|
42
|
+
it('uses OpenChamber themes when a new install has no theme preferences', async () => {
|
|
43
|
+
const { runtime, cleanup } = await createRuntime();
|
|
44
|
+
try {
|
|
45
|
+
await expect(runtime.readSettingsFromDiskMigrated()).resolves.toMatchObject({
|
|
46
|
+
lightThemeId: 'openchamber-light',
|
|
47
|
+
darkThemeId: 'openchamber-dark',
|
|
48
|
+
});
|
|
49
|
+
} finally {
|
|
50
|
+
await cleanup();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('preserves existing theme preferences during theme migration', async () => {
|
|
55
|
+
const { runtime, settingsFilePath, cleanup } = await createRuntime();
|
|
56
|
+
try {
|
|
57
|
+
await fsPromises.writeFile(settingsFilePath, JSON.stringify({
|
|
58
|
+
lightThemeId: 'flexoki-light',
|
|
59
|
+
darkThemeId: 'flexoki-dark',
|
|
60
|
+
}), 'utf8');
|
|
61
|
+
|
|
62
|
+
await expect(runtime.readSettingsFromDiskMigrated()).resolves.toMatchObject({
|
|
63
|
+
lightThemeId: 'flexoki-light',
|
|
64
|
+
darkThemeId: 'flexoki-dark',
|
|
65
|
+
});
|
|
66
|
+
} finally {
|
|
67
|
+
await cleanup();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
42
71
|
it('round-trips shared sidebar preferences through settings.json', async () => {
|
|
43
72
|
const { runtime, settingsFilePath, cleanup } = await createRuntime();
|
|
44
73
|
const preferences = {
|
|
@@ -11,6 +11,7 @@ export const createGracefulShutdownRuntime = (dependencies) => {
|
|
|
11
11
|
sessionAssistRuntime,
|
|
12
12
|
sessionGoalRuntime,
|
|
13
13
|
contextObligatoryRuntime,
|
|
14
|
+
messageQueueRuntime,
|
|
14
15
|
scheduledTasksRuntime,
|
|
15
16
|
getHealthCheckInterval,
|
|
16
17
|
clearHealthCheckInterval,
|
|
@@ -47,6 +48,7 @@ export const createGracefulShutdownRuntime = (dependencies) => {
|
|
|
47
48
|
sessionAssistRuntime?.stop?.();
|
|
48
49
|
sessionGoalRuntime?.stop?.();
|
|
49
50
|
contextObligatoryRuntime?.stop?.();
|
|
51
|
+
messageQueueRuntime?.stop?.();
|
|
50
52
|
scheduledTasksRuntime?.stop?.();
|
|
51
53
|
|
|
52
54
|
const healthCheckInterval = getHealthCheckInterval();
|
|
@@ -47,20 +47,20 @@ export const createStaticRoutesRuntime = (dependencies) => {
|
|
|
47
47
|
normalizePwaOrientation,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
app.get(/^(?!\/api|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
50
|
+
app.get(/^(?!\/api|\/linear|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
51
51
|
res.sendFile(path.join(distPath, 'index.html'));
|
|
52
52
|
});
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
console.warn(`Warning: ${distPath} not found, static files will not be served`);
|
|
57
|
-
app.get(/^(?!\/api|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
57
|
+
app.get(/^(?!\/api|\/linear|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (_req, res) => {
|
|
58
58
|
res.status(404).send('Static files not found. Please build the application first.');
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const registerApiOnlyFallbackRoutes = (app) => {
|
|
63
|
-
app.get(/^(?!\/api|\/auth|\/health|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (req, res) => {
|
|
63
|
+
app.get(/^(?!\/api|\/auth|\/health|\/linear|.*\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|map)).*$/, (req, res) => {
|
|
64
64
|
const command = 'openchamber connect-url --help';
|
|
65
65
|
res.status(200).format({
|
|
66
66
|
html: () => {
|
|
@@ -499,11 +499,20 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
499
499
|
}
|
|
500
500
|
};
|
|
501
501
|
|
|
502
|
+
// Normalized tasks for reading, plus the raw on-disk record of each one for
|
|
503
|
+
// writing back. Normalization only keeps the fields THIS build knows, so a
|
|
504
|
+
// write that re-serialized normalized tasks would strip every field added
|
|
505
|
+
// by a newer build (or a newer UI) the moment an older server touched the
|
|
506
|
+
// file — a goal or auto-accept setting silently lost after a task ran.
|
|
507
|
+
// Writers therefore persist untouched tasks from `rawTasksByID` verbatim and
|
|
508
|
+
// only serialize a normalized task where the task itself was deliberately
|
|
509
|
+
// replaced.
|
|
502
510
|
const readProjectConfigFromDisk = async (projectID) => {
|
|
503
511
|
const parsed = await readRawProjectConfigFromDisk(projectID);
|
|
504
512
|
const tasksRaw = Array.isArray(parsed.scheduledTasks) ? parsed.scheduledTasks : [];
|
|
505
513
|
const now = Date.now();
|
|
506
514
|
const scheduledTasks = [];
|
|
515
|
+
const rawTasksByID = new Map();
|
|
507
516
|
for (const task of tasksRaw) {
|
|
508
517
|
try {
|
|
509
518
|
const normalized = normalizeTaskForStorage(task, {
|
|
@@ -514,15 +523,31 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
514
523
|
refreshUpdatedAt: false,
|
|
515
524
|
});
|
|
516
525
|
scheduledTasks.push(normalized);
|
|
526
|
+
rawTasksByID.set(normalized.id, task);
|
|
517
527
|
} catch {
|
|
518
528
|
}
|
|
519
529
|
}
|
|
520
530
|
return {
|
|
521
531
|
version: PROJECT_CONFIG_VERSION,
|
|
522
532
|
scheduledTasks,
|
|
533
|
+
rawTasksByID,
|
|
523
534
|
};
|
|
524
535
|
};
|
|
525
536
|
|
|
537
|
+
// The list to write: tasks this write replaced go out normalized; every
|
|
538
|
+
// other task goes out exactly as stored, fields unknown to this build
|
|
539
|
+
// included. A state-only update counts as untouched — only its `state` is
|
|
540
|
+
// swapped onto the stored record. Callers keep working with (and returning)
|
|
541
|
+
// the normalized tasks; only the bytes on disk differ.
|
|
542
|
+
const toStoredTasks = (config, tasks, { replacedIDs = new Set(), stateUpdatedID = null } = {}) => (
|
|
543
|
+
tasks.map((task) => {
|
|
544
|
+
if (replacedIDs.has(task.id)) return task;
|
|
545
|
+
const stored = config.rawTasksByID.get(task.id);
|
|
546
|
+
if (!stored) return task;
|
|
547
|
+
return task.id === stateUpdatedID ? { ...stored, state: task.state } : stored;
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
|
|
526
551
|
const writeProjectConfigToDisk = async (projectID, config) => {
|
|
527
552
|
const filePath = resolveProjectConfigPath(projectID);
|
|
528
553
|
const parentDirectory = path.dirname(filePath);
|
|
@@ -607,7 +632,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
607
632
|
|
|
608
633
|
const nextConfig = {
|
|
609
634
|
version: PROJECT_CONFIG_VERSION,
|
|
610
|
-
scheduledTasks: nextTasks,
|
|
635
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { replacedIDs: new Set([normalizedTask.id]) }),
|
|
611
636
|
};
|
|
612
637
|
await writeProjectConfigToDisk(projectID, nextConfig);
|
|
613
638
|
|
|
@@ -633,7 +658,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
633
658
|
if (deleted) {
|
|
634
659
|
await writeProjectConfigToDisk(projectID, {
|
|
635
660
|
version: PROJECT_CONFIG_VERSION,
|
|
636
|
-
scheduledTasks: nextTasks,
|
|
661
|
+
scheduledTasks: toStoredTasks(current, nextTasks),
|
|
637
662
|
});
|
|
638
663
|
}
|
|
639
664
|
|
|
@@ -676,7 +701,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
676
701
|
|
|
677
702
|
await writeProjectConfigToDisk(projectID, {
|
|
678
703
|
version: PROJECT_CONFIG_VERSION,
|
|
679
|
-
scheduledTasks: nextTasks,
|
|
704
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { stateUpdatedID: nextTask.id }),
|
|
680
705
|
});
|
|
681
706
|
|
|
682
707
|
return {
|
|
@@ -737,7 +762,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
737
762
|
|
|
738
763
|
await writeProjectConfigToDisk(projectID, {
|
|
739
764
|
version: PROJECT_CONFIG_VERSION,
|
|
740
|
-
scheduledTasks: nextTasks,
|
|
765
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { stateUpdatedID: nextTask.id }),
|
|
741
766
|
});
|
|
742
767
|
|
|
743
768
|
return {
|
|
@@ -797,6 +822,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
797
822
|
|
|
798
823
|
const consumedLoopPaths = new Set();
|
|
799
824
|
const nextTasks = [];
|
|
825
|
+
const replacedIDs = new Set();
|
|
800
826
|
for (const task of tasks) {
|
|
801
827
|
if (task.loopFile && !activeLoopFilePaths.has(task.loopFile)) {
|
|
802
828
|
// The driving loop file was removed (or renamed) — unschedule.
|
|
@@ -828,6 +854,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
828
854
|
},
|
|
829
855
|
);
|
|
830
856
|
nextTasks.push(adopted);
|
|
857
|
+
replacedIDs.add(adopted.id);
|
|
831
858
|
pendingLoops.delete(loop.definition.name);
|
|
832
859
|
if (task.loopFile) {
|
|
833
860
|
consumedLoopPaths.add(task.loopFile);
|
|
@@ -863,6 +890,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
863
890
|
},
|
|
864
891
|
);
|
|
865
892
|
nextTasks.push(created);
|
|
893
|
+
replacedIDs.add(created.id);
|
|
866
894
|
} catch (error) {
|
|
867
895
|
console.warn(`[scheduled-tasks] skipped loop ${loop.filePath}:`, error?.message ?? error);
|
|
868
896
|
}
|
|
@@ -870,7 +898,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
870
898
|
|
|
871
899
|
await writeProjectConfigToDisk(projectID, {
|
|
872
900
|
version: PROJECT_CONFIG_VERSION,
|
|
873
|
-
scheduledTasks: nextTasks,
|
|
901
|
+
scheduledTasks: toStoredTasks(current, nextTasks, { replacedIDs }),
|
|
874
902
|
});
|
|
875
903
|
|
|
876
904
|
return nextTasks;
|
|
@@ -14,6 +14,7 @@ const createRuntime = async () => {
|
|
|
14
14
|
});
|
|
15
15
|
return {
|
|
16
16
|
runtime,
|
|
17
|
+
tempRoot,
|
|
17
18
|
cleanup: async () => {
|
|
18
19
|
await rm(tempRoot, { recursive: true, force: true });
|
|
19
20
|
},
|
|
@@ -472,6 +473,90 @@ describe('project-config loop reconciliation', () => {
|
|
|
472
473
|
}
|
|
473
474
|
});
|
|
474
475
|
|
|
476
|
+
describe('fields this build does not know', () => {
|
|
477
|
+
// Simulates a config written by a newer build (or a newer UI): the task
|
|
478
|
+
// carries execution and state fields normalization here has never heard of.
|
|
479
|
+
const seedForeignTask = async (runtime, tempRoot) => {
|
|
480
|
+
const created = await runtime.upsertScheduledTask('project-test', {
|
|
481
|
+
name: 'Nightly digest',
|
|
482
|
+
enabled: true,
|
|
483
|
+
schedule: { kind: 'daily', time: '09:30', timezone: 'UTC' },
|
|
484
|
+
execution: { prompt: 'Summarize', providerID: 'openai', modelID: 'gpt-4.1', goalEnabled: true },
|
|
485
|
+
});
|
|
486
|
+
const filePath = path.join(tempRoot, 'project-test.json');
|
|
487
|
+
const stored = JSON.parse(await readFile(filePath, 'utf8'));
|
|
488
|
+
stored.scheduledTasks[0].execution.futureExecutionField = 'keep me';
|
|
489
|
+
stored.scheduledTasks[0].state.futureStateField = 42;
|
|
490
|
+
stored.scheduledTasks[0].futureTopLevelField = true;
|
|
491
|
+
await writeFile(filePath, JSON.stringify(stored, null, 2), 'utf8');
|
|
492
|
+
return { id: created.task.id, filePath };
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const readStoredTask = async (filePath, id) => {
|
|
496
|
+
const stored = JSON.parse(await readFile(filePath, 'utf8'));
|
|
497
|
+
return stored.scheduledTasks.find((task) => task.id === id);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
it('survive a state update after a run, and the claim update', async () => {
|
|
501
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
502
|
+
try {
|
|
503
|
+
const { id, filePath } = await seedForeignTask(runtime, tempRoot);
|
|
504
|
+
|
|
505
|
+
await runtime.updateScheduledTaskState('project-test', id, { lastStatus: 'success', lastRunAt: 1000 });
|
|
506
|
+
let stored = await readStoredTask(filePath, id);
|
|
507
|
+
expect(stored.execution.futureExecutionField).toBe('keep me');
|
|
508
|
+
expect(stored.execution.goalEnabled).toBe(true);
|
|
509
|
+
expect(stored.futureTopLevelField).toBe(true);
|
|
510
|
+
expect(stored.state.lastStatus).toBe('success');
|
|
511
|
+
|
|
512
|
+
await runtime.updateScheduledTaskStateIf('project-test', id, () => true, { lastScheduledFor: 5000 });
|
|
513
|
+
stored = await readStoredTask(filePath, id);
|
|
514
|
+
expect(stored.execution.futureExecutionField).toBe('keep me');
|
|
515
|
+
expect(stored.state.lastScheduledFor).toBe(5000);
|
|
516
|
+
} finally {
|
|
517
|
+
await cleanup();
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('survive writes that replace or delete a different task, and a loop sync', async () => {
|
|
522
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
523
|
+
try {
|
|
524
|
+
const { id, filePath } = await seedForeignTask(runtime, tempRoot);
|
|
525
|
+
|
|
526
|
+
const other = await runtime.upsertScheduledTask('project-test', {
|
|
527
|
+
id: 'other-task',
|
|
528
|
+
name: 'Other',
|
|
529
|
+
enabled: true,
|
|
530
|
+
schedule: { kind: 'daily', time: '10:00', timezone: 'UTC' },
|
|
531
|
+
execution: { prompt: 'Other', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
532
|
+
});
|
|
533
|
+
expect((await readStoredTask(filePath, id)).execution.futureExecutionField).toBe('keep me');
|
|
534
|
+
|
|
535
|
+
await runtime.deleteScheduledTask('project-test', other.task.id);
|
|
536
|
+
expect((await readStoredTask(filePath, id)).execution.futureExecutionField).toBe('keep me');
|
|
537
|
+
|
|
538
|
+
await runtime.reconcileLoopTasks('project-test', []);
|
|
539
|
+
expect((await readStoredTask(filePath, id)).execution.futureExecutionField).toBe('keep me');
|
|
540
|
+
} finally {
|
|
541
|
+
await cleanup();
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('are dropped only when the task itself is deliberately saved', async () => {
|
|
546
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
547
|
+
try {
|
|
548
|
+
const { id, filePath } = await seedForeignTask(runtime, tempRoot);
|
|
549
|
+
const [task] = await runtime.listScheduledTasks('project-test');
|
|
550
|
+
await runtime.upsertScheduledTask('project-test', { ...task, name: 'Renamed' });
|
|
551
|
+
const stored = await readStoredTask(filePath, id);
|
|
552
|
+
expect(stored.name).toBe('Renamed');
|
|
553
|
+
expect(stored.execution.futureExecutionField).toBeUndefined();
|
|
554
|
+
} finally {
|
|
555
|
+
await cleanup();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
|
|
475
560
|
it('conditionally updates state only when the predicate passes (occurrence claim)', async () => {
|
|
476
561
|
const { runtime, cleanup } = await createRuntime();
|
|
477
562
|
try {
|
|
@@ -23,6 +23,7 @@ These provider IDs are currently dispatchable via `fetchQuotaForProvider(provide
|
|
|
23
23
|
| `cursor` | Cursor | `providers/cursor.js` | Environment/token files, OpenChamber-managed credentials, or explicit one-time Cursor import |
|
|
24
24
|
| `crof` | CrofAI | `providers/crof.js` | `crof` (API key under `key` or `token`) |
|
|
25
25
|
| `deepseek` | DeepSeek | `providers/deepseek.js` | `deepseek` (API key under `key` or `token`) |
|
|
26
|
+
| `exe-dev` | exe.dev | `providers/exe-dev.js` | Usage API token stored under `~/.config/openchamber/quota/` |
|
|
26
27
|
| `google` | Google | `providers/google/index.js` | `google`, `google.oauth`, Antigravity accounts file |
|
|
27
28
|
| `github-copilot` | GitHub Copilot | `providers/copilot.js` | `github-copilot`, `copilot` |
|
|
28
29
|
| `github-copilot-addon` | GitHub Copilot Add-on | `providers/copilot.js` | `github-copilot`, `copilot` |
|
|
@@ -51,7 +52,7 @@ All providers should return results via shared helpers to preserve API shape:
|
|
|
51
52
|
Provider modules must export `providerId`, `providerName`, `aliases`, `isConfigured(auth?)`, and `fetchQuota()`.
|
|
52
53
|
`fetchQuota()` should return a quota result with `usage.windows` keyed by window name (for example `5h`, `7d`, `daily`) and optional provider-specific `usage.models` data.
|
|
53
54
|
|
|
54
|
-
Ollama Cloud and Cursor credentials are explicitly managed through Settings. OpenCode Go usage uses `GET https://opencode.ai/zen/go/v1/usage` with the `opencode-go` API key from OpenCode `auth.json` as a bearer token. The server validates managed credentials before atomic `0600` writes and never returns secrets through its API. OpenChamber never scans browser cookie stores or automatically reads Cursor storage; Cursor import is an explicit one-time user action and never modifies Cursor's database.
|
|
55
|
+
exe.dev, Ollama Cloud, and Cursor credentials are explicitly managed through Settings. exe.dev usage uses a separately generated HTTPS API token restricted to `billing credits usage` and aggregates every `exe-*` model provider into one monthly credit window. Generate the token with `ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`. OpenCode Go usage uses `GET https://opencode.ai/zen/go/v1/usage` with the `opencode-go` API key from OpenCode `auth.json` as a bearer token and the stable `x-opencode-session: openchamber-usage` workload id. The server validates managed credentials before atomic `0600` writes and never returns secrets through its API. OpenChamber never scans browser cookie stores or automatically reads Cursor storage; Cursor import is an explicit one-time user action and never modifies Cursor's database.
|
|
55
56
|
|
|
56
57
|
Command Code usage resolves account scope through `GET /alpha/whoami`, then reads server-backed credit balances and five-hour/weekly limits from `GET /alpha/billing/credits?orgId=...`. Personal accounts return `org: null` and use `/alpha/billing/credits` without an `orgId`; organization accounts include their organization id. Web/Electron and VS Code read the standard `command-code` OpenCode auth entry (including OAuth `access`) or `COMMAND_CODE_API_KEY`; credentials remain in the owning runtime and are never returned to shared UI.
|
|
57
58
|
|
|
@@ -3,6 +3,10 @@ import { deleteQuotaCredential, readQuotaCredential, writeQuotaCredential } from
|
|
|
3
3
|
const clean = (value) => typeof value === 'string' && !/[\r\n]/.test(value) ? value.trim() : '';
|
|
4
4
|
|
|
5
5
|
export const normalizers = {
|
|
6
|
+
'exe-dev': (value) => {
|
|
7
|
+
const usageToken = clean(value?.usageToken);
|
|
8
|
+
return usageToken ? { usageToken } : null;
|
|
9
|
+
},
|
|
6
10
|
'ollama-cloud': (value) => {
|
|
7
11
|
const cookie = clean(value?.cookie);
|
|
8
12
|
return cookie ? { cookie } : null;
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
const MANAGED_QUOTA_PROVIDERS = new Set(['ollama-cloud', 'cursor']);
|
|
5
|
+
const MANAGED_QUOTA_PROVIDERS = new Set(['exe-dev', 'ollama-cloud', 'cursor']);
|
|
6
6
|
|
|
7
7
|
const credentialsDirectory = () => path.join(
|
|
8
8
|
process.env.OPENCHAMBER_DATA_DIR
|
|
@@ -10,12 +10,12 @@ process.env.OPENCHAMBER_DATA_DIR = temporaryDirectory;
|
|
|
10
10
|
|
|
11
11
|
describe('quota credential store', () => {
|
|
12
12
|
it('uses owner-only permissions and rejects arbitrary provider paths', () => {
|
|
13
|
-
writeQuotaCredential('
|
|
13
|
+
writeQuotaCredential('exe-dev', { usageToken: 'secret' });
|
|
14
14
|
expect(fs.statSync(path.join(temporaryDirectory, 'quota')).mode & 0o777).toBe(0o700);
|
|
15
|
-
expect(fs.statSync(path.join(temporaryDirectory, 'quota', '
|
|
16
|
-
expect(readQuotaCredential('
|
|
15
|
+
expect(fs.statSync(path.join(temporaryDirectory, 'quota', 'exe-dev.json')).mode & 0o777).toBe(0o600);
|
|
16
|
+
expect(readQuotaCredential('exe-dev', (value) => value)).toEqual({ usageToken: 'secret' });
|
|
17
17
|
expect(() => writeQuotaCredential('../escape', {})).toThrow('Unsupported credential provider');
|
|
18
|
-
deleteQuotaCredential('
|
|
18
|
+
deleteQuotaCredential('exe-dev');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('removes the obsolete OpenCode Go credential without parsing it', () => {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readManagedCredential } from '../credentials/providers.js';
|
|
2
|
+
import { asObject, buildResult, formatMoney, toNumber, toTimestamp, toUsageWindow } from '../utils/index.js';
|
|
3
|
+
|
|
4
|
+
export const providerId = 'exe-dev';
|
|
5
|
+
export const providerName = 'exe.dev';
|
|
6
|
+
export const aliases = ['exe-dev'];
|
|
7
|
+
const EXEC_URL = 'https://exe.dev/exec';
|
|
8
|
+
const USAGE_COMMAND = 'billing credits usage --group=day --json';
|
|
9
|
+
|
|
10
|
+
export const parseExeDevUsage = (payload) => {
|
|
11
|
+
const data = asObject(payload);
|
|
12
|
+
if (!data) return null;
|
|
13
|
+
|
|
14
|
+
const totalCost = toNumber(data.total_cost_usd);
|
|
15
|
+
const monthlyAllowance = toNumber(data.monthly_allowance_usd);
|
|
16
|
+
const resetAt = toTimestamp(data.period_end);
|
|
17
|
+
if (totalCost === null || monthlyAllowance === null || monthlyAllowance < 0 || resetAt === null) return null;
|
|
18
|
+
|
|
19
|
+
const usedPercent = monthlyAllowance > 0
|
|
20
|
+
? Math.min(100, Math.max(0, (totalCost / monthlyAllowance) * 100))
|
|
21
|
+
: null;
|
|
22
|
+
const spent = formatMoney(totalCost);
|
|
23
|
+
const allowance = formatMoney(monthlyAllowance);
|
|
24
|
+
if (spent === null || allowance === null) return null;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
monthly: toUsageWindow({
|
|
28
|
+
usedPercent,
|
|
29
|
+
windowSeconds: null,
|
|
30
|
+
resetAt,
|
|
31
|
+
valueLabel: `$${spent} / $${allowance}`,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const fetchExeDevUsage = async (credential, fetchImpl = fetch) => {
|
|
37
|
+
const response = await fetchImpl(EXEC_URL, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {
|
|
40
|
+
Accept: 'application/json',
|
|
41
|
+
Authorization: `Bearer ${credential.usageToken}`,
|
|
42
|
+
'Content-Type': 'text/plain',
|
|
43
|
+
'User-Agent': 'OpenChamber quota provider',
|
|
44
|
+
},
|
|
45
|
+
body: USAGE_COMMAND,
|
|
46
|
+
signal: AbortSignal.timeout(15_000),
|
|
47
|
+
});
|
|
48
|
+
if (response.status === 401 || response.status === 403) throw new Error('exe.dev authentication failed');
|
|
49
|
+
if (!response.ok) throw new Error(`exe.dev usage API returned HTTP ${response.status}`);
|
|
50
|
+
const windows = parseExeDevUsage(await response.json().catch(() => null));
|
|
51
|
+
if (!windows) throw new Error('exe.dev usage data could not be parsed');
|
|
52
|
+
return windows;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const isConfigured = () => Boolean(readManagedCredential(providerId));
|
|
56
|
+
|
|
57
|
+
export const fetchQuota = async () => {
|
|
58
|
+
const credential = readManagedCredential(providerId);
|
|
59
|
+
if (!credential) {
|
|
60
|
+
return buildResult({ providerId, providerName, ok: false, configured: false, error: 'Not configured' });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const windows = await fetchExeDevUsage(credential);
|
|
65
|
+
return buildResult({ providerId, providerName, ok: true, configured: true, usage: { windows } });
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return buildResult({
|
|
68
|
+
providerId,
|
|
69
|
+
providerName,
|
|
70
|
+
ok: false,
|
|
71
|
+
configured: true,
|
|
72
|
+
error: error instanceof Error ? error.message : 'Request failed',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { fetchExeDevUsage, parseExeDevUsage } from './exe-dev.js';
|
|
3
|
+
|
|
4
|
+
const payload = {
|
|
5
|
+
allowance_spend_usd: 0.11,
|
|
6
|
+
extra_spend_usd: 0,
|
|
7
|
+
group: 'day',
|
|
8
|
+
month: '2026-09',
|
|
9
|
+
monthly_allowance_usd: 20,
|
|
10
|
+
period_end: '2026-10-01T00:00:00Z',
|
|
11
|
+
period_start: '2026-09-01T00:00:00Z',
|
|
12
|
+
total_cost_usd: 0.11,
|
|
13
|
+
total_requests: 17,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('exe.dev quota provider', () => {
|
|
17
|
+
it('parses monthly credit usage', () => {
|
|
18
|
+
const windows = parseExeDevUsage(payload);
|
|
19
|
+
expect(windows?.monthly.usedPercent).toBeCloseTo(0.55);
|
|
20
|
+
expect(windows?.monthly.valueLabel).toBe('$0.11 / $20.00');
|
|
21
|
+
expect(windows?.monthly.resetAt).toBe(Date.parse('2026-10-01T00:00:00Z'));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('sends the scoped billing command without exposing the token elsewhere', async () => {
|
|
25
|
+
const requests = [];
|
|
26
|
+
const windows = await fetchExeDevUsage({ usageToken: 'test-token' }, async (url, init) => {
|
|
27
|
+
requests.push({ url, init });
|
|
28
|
+
return Response.json(payload);
|
|
29
|
+
});
|
|
30
|
+
expect(windows.monthly.valueLabel).toBe('$0.11 / $20.00');
|
|
31
|
+
expect(requests).toHaveLength(1);
|
|
32
|
+
expect(requests[0].url).toBe('https://exe.dev/exec');
|
|
33
|
+
expect(requests[0].init.method).toBe('POST');
|
|
34
|
+
expect(requests[0].init.body).toBe('billing credits usage --group=day --json');
|
|
35
|
+
expect(requests[0].init.headers.Authorization).toBe('Bearer test-token');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('rejects malformed successful responses', async () => {
|
|
39
|
+
await expect(fetchExeDevUsage({ usageToken: 'test-token' }, async () => Response.json({})))
|
|
40
|
+
.rejects.toThrow('could not be parsed');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('reports authentication failure without including the token', async () => {
|
|
44
|
+
await expect(fetchExeDevUsage({ usageToken: 'test-token' }, async () => new Response('', { status: 401 })))
|
|
45
|
+
.rejects.toThrow('exe.dev authentication failed');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -13,6 +13,7 @@ import * as copilot from './copilot.js';
|
|
|
13
13
|
import * as crof from './crof.js';
|
|
14
14
|
import * as cursor from './cursor.js';
|
|
15
15
|
import * as deepseek from './deepseek.js';
|
|
16
|
+
import * as exeDev from './exe-dev.js';
|
|
16
17
|
import * as google from './google/index.js';
|
|
17
18
|
import * as kimi from './kimi.js';
|
|
18
19
|
import * as nanogpt from './nanogpt.js';
|
|
@@ -59,6 +60,12 @@ const registry = {
|
|
|
59
60
|
isConfigured: deepseek.isConfigured,
|
|
60
61
|
fetchQuota: deepseek.fetchQuota
|
|
61
62
|
},
|
|
63
|
+
'exe-dev': {
|
|
64
|
+
providerId: exeDev.providerId,
|
|
65
|
+
providerName: exeDev.providerName,
|
|
66
|
+
isConfigured: exeDev.isConfigured,
|
|
67
|
+
fetchQuota: exeDev.fetchQuota
|
|
68
|
+
},
|
|
62
69
|
google: {
|
|
63
70
|
providerId: google.providerId,
|
|
64
71
|
providerName: google.providerName,
|
|
@@ -37,6 +37,7 @@ export const fetchOpenCodeGoUsage = async (apiKey, fetchImpl = fetch) => {
|
|
|
37
37
|
headers: {
|
|
38
38
|
Accept: 'application/json',
|
|
39
39
|
Authorization: `Bearer ${apiKey}`,
|
|
40
|
+
'x-opencode-session': 'openchamber-usage',
|
|
40
41
|
'User-Agent': 'OpenChamber quota provider',
|
|
41
42
|
},
|
|
42
43
|
signal: AbortSignal.timeout(15_000),
|
|
@@ -43,7 +43,11 @@ describe('OpenCode Go quota provider', () => {
|
|
|
43
43
|
return new Response(JSON.stringify({ usage: { rolling: { percent: 25, resetsAt: '2026-08-12T12:00:00.000Z' } } }));
|
|
44
44
|
});
|
|
45
45
|
expect(request.url).toBe('https://opencode.ai/zen/go/v1/usage');
|
|
46
|
-
expect(request.options.headers).toMatchObject({
|
|
46
|
+
expect(request.options.headers).toMatchObject({
|
|
47
|
+
Accept: 'application/json',
|
|
48
|
+
Authorization: 'Bearer secret',
|
|
49
|
+
'x-opencode-session': 'openchamber-usage',
|
|
50
|
+
});
|
|
47
51
|
expect(request.options.headers.Cookie).toBeUndefined();
|
|
48
52
|
expect(usage['5h'].usedPercent).toBe(25);
|
|
49
53
|
});
|