@openchamber/web 1.18.2 → 1.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/commands-models.js +1 -1
- package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-DbUi6I9s.js} +1 -1
- package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-Jc2_hNPE.js} +1 -1
- package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-PCrYHBko.js} +1 -1
- package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CndEcZNu.js} +1 -1
- package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DEGlNjMH.js} +2 -2
- package/dist/assets/FilesView-CzUgIvUm.js +14 -0
- package/dist/assets/{GitView-OSVIn5V1.js → GitView-C-n17voy.js} +1 -1
- package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-BYcgdTOQ.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +12 -0
- package/dist/assets/OnboardingScreen-BmN0lhk4.js +1 -0
- package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-Bn7bfgUv.js} +1 -1
- package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-D1fWvrUn.js} +2 -2
- package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-CWM0iyFk.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-Cez-9xRh.js} +1 -1
- package/dist/assets/SettingsView-Bl1drwPw.js +28 -0
- package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-DL5axjDZ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-BtIJkFno.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-i3PQo6_0.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-DkcusvMa.js} +1 -1
- package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-Cc5Hd6P5.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-xPena3W2.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +1 -0
- package/dist/assets/de-u7gSnqWs.js +9 -0
- package/dist/assets/es-T9O7aAOr.js +15 -0
- package/dist/assets/fr-Oor7ewbE.js +13 -0
- package/dist/assets/index-CVNuER6G.css +1 -0
- package/dist/assets/{index-BgQEgA2a.js → index-Crz1YOFl.js} +1 -1
- package/dist/assets/index-iFY_N5aO.js +7 -0
- package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-Dudf-dWx.js} +1 -1
- package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-DS4QV1dd.js} +1 -1
- package/dist/assets/ja-DHpqbVmr.js +15 -0
- package/dist/assets/ko-CwLkS3nx.js +15 -0
- package/dist/assets/{main-LfcbGv7C.js → main-C0DyIwTb.js} +2 -2
- package/dist/assets/main-CAxX6DAN.js +915 -0
- package/dist/assets/markdownCore-DhfzuGXu.js +2 -0
- package/dist/assets/markdownImageAssets-BTNlRyjd.js +1 -0
- package/dist/assets/{miniChat-CUp_elRz.js → miniChat-CGfrxKpJ.js} +2 -2
- package/dist/assets/{mobile-CBSN7BsH.js → mobile-DEmhwNcV.js} +2 -2
- package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-C5D1OPCa.js} +2 -2
- package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
- package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-Dpbswpom.js} +2 -2
- package/dist/assets/renderMobileApp-B5HA4qbi.js +25 -0
- package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +13 -0
- package/dist/assets/scheduledTasksApi-BxgGWTL8.js +1 -0
- package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-CmanopUB.js} +1 -1
- package/dist/assets/uk-BA2kZR38.js +15 -0
- package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-sHmU5b8u.js} +137 -137
- package/dist/assets/useInlineCommentController-gt56WkxJ.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-Dihw9MtL.js} +2 -2
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-DGvnI0zx.js → web-components-BL-Ur2Tb.js} +1 -1
- package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
- package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/index.js +65 -19
- package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
- package/server/lib/agent-tool/runtime.js +90 -16
- package/server/lib/agent-tool/runtime.test.js +86 -0
- package/server/lib/browser-control/DOCUMENTATION.md +50 -0
- package/server/lib/browser-control/broker.js +154 -0
- package/server/lib/browser-control/broker.test.js +191 -0
- package/server/lib/browser-control/routes.js +48 -0
- package/server/lib/browser-control/routes.test.js +108 -0
- package/server/lib/dev-servers/parse.js +203 -0
- package/server/lib/dev-servers/parse.test.js +174 -0
- package/server/lib/dev-servers/routes.js +135 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
- package/server/lib/dev-tunnel/client.js +174 -0
- package/server/lib/dev-tunnel/runtime.js +189 -0
- package/server/lib/dev-tunnel/tunnel.test.js +282 -0
- package/server/lib/git/credentials.js +0 -33
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
- package/server/lib/openchamber-control/actions.js +33 -1
- package/server/lib/openchamber-control/screenshots.js +83 -0
- package/server/lib/openchamber-control/screenshots.test.js +84 -0
- package/server/lib/openchamber-control/service.js +141 -2
- package/server/lib/openchamber-control/service.test.js +55 -0
- package/server/lib/opencode/core-routes.js +31 -52
- package/server/lib/opencode/core-routes.test.js +37 -9
- package/server/lib/opencode/feature-routes-runtime.js +4 -0
- package/server/lib/opencode/settings-helpers.js +3 -9
- package/server/lib/projects/project-config.js +181 -2
- package/server/lib/projects/project-config.test.js +295 -0
- package/server/lib/quota/DOCUMENTATION.md +4 -2
- package/server/lib/quota/credentials/providers.js +0 -7
- package/server/lib/quota/credentials/store.js +11 -1
- package/server/lib/quota/credentials/store.test.js +9 -1
- package/server/lib/quota/providers/opencode-go.js +35 -35
- package/server/lib/quota/providers/opencode-go.test.js +52 -7
- package/server/lib/quota/routes.js +0 -2
- package/server/lib/relay/DOCUMENTATION.md +2 -0
- package/server/lib/relay/tunnel-host.js +157 -33
- package/server/lib/relay/tunnel-host.test.js +147 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
- package/server/lib/scheduled-tasks/routes.js +6 -0
- package/server/lib/scheduled-tasks/runtime.js +369 -108
- package/server/lib/scheduled-tasks/service.js +7 -1
- package/server/lib/scheduled-tasks/service.test.js +20 -0
- package/server/lib/walkthrough/index.js +0 -2
- package/server/sse-routes.test.js +3 -0
- package/dist/assets/FilesView-WkxsWHBE.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
- package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
- package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
- package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
- package/dist/assets/de-B6t6T54h.js +0 -9
- package/dist/assets/es-DH9NUKge.js +0 -15
- package/dist/assets/fr-Do4t2KmA.js +0 -13
- package/dist/assets/index-B45s9aAX.css +0 -1
- package/dist/assets/index-CNrN5qDs.js +0 -7
- package/dist/assets/ja-DJT9EM80.js +0 -15
- package/dist/assets/ko-CfWRq2p4.js +0 -15
- package/dist/assets/main-B4oBRI9u.js +0 -193
- package/dist/assets/markdownCore-A3_L34oS.js +0 -2
- package/dist/assets/pt-BR-BDEzzltP.js +0 -15
- package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
- package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
- package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
- package/dist/assets/uk-B6Q32nyk.js +0 -15
- package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
- package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
- package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
- package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
- package/server/lib/preview/proxy-runtime.js +0 -1604
- package/server/lib/preview/proxy-runtime.test.js +0 -528
- package/server/lib/quota/opencode-go-credentials.js +0 -11
- package/server/lib/quota/opencode-go-credentials.test.js +0 -32
- package/server/lib/quota/routes.test.js +0 -40
|
@@ -5,6 +5,7 @@ import { registerWalkthroughRoutes } from '../walkthrough/routes.js';
|
|
|
5
5
|
import { registerSessionGoalRoutes } from '../session-goal/routes.js';
|
|
6
6
|
import { registerGitHubRoutes } from '../github/routes.js';
|
|
7
7
|
import { registerGitRoutes } from '../git/routes.js';
|
|
8
|
+
import { registerDevServerRoutes } from '../dev-servers/routes.js';
|
|
8
9
|
import { registerMagicPromptRoutes } from '../magic-prompts/routes.js';
|
|
9
10
|
import { registerSessionFoldersRoutes } from '../session-folders/routes.js';
|
|
10
11
|
import { registerPermissionAutoAcceptRoutes } from '../permission-auto-accept/runtime.js';
|
|
@@ -110,6 +111,8 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
110
111
|
buildOpenCodeUrl,
|
|
111
112
|
getOpenCodeAuthHeaders,
|
|
112
113
|
getOpenCodePort,
|
|
114
|
+
getOwnPorts,
|
|
115
|
+
devServerScanner,
|
|
113
116
|
buildAugmentedPath,
|
|
114
117
|
projectConfigRuntime,
|
|
115
118
|
scheduledTasksRuntime,
|
|
@@ -284,6 +287,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
284
287
|
registerSessionGoalRoutes(app);
|
|
285
288
|
registerGitHubRoutes(app);
|
|
286
289
|
registerGitRoutes(app);
|
|
290
|
+
registerDevServerRoutes(app, { scanner: devServerScanner, getOwnPorts });
|
|
287
291
|
registerMagicPromptRoutes(app, {
|
|
288
292
|
fsPromises,
|
|
289
293
|
path,
|
|
@@ -362,18 +362,9 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
362
362
|
if (typeof candidate.maxLastMessageLength === 'number' && Number.isFinite(candidate.maxLastMessageLength)) {
|
|
363
363
|
result.maxLastMessageLength = Math.max(10, Math.round(candidate.maxLastMessageLength));
|
|
364
364
|
}
|
|
365
|
-
if (typeof candidate.usageAutoRefresh === 'boolean') {
|
|
366
|
-
result.usageAutoRefresh = candidate.usageAutoRefresh;
|
|
367
|
-
}
|
|
368
|
-
if (typeof candidate.usageRefreshIntervalMs === 'number' && Number.isFinite(candidate.usageRefreshIntervalMs)) {
|
|
369
|
-
result.usageRefreshIntervalMs = Math.max(30000, Math.min(300000, Math.round(candidate.usageRefreshIntervalMs)));
|
|
370
|
-
}
|
|
371
365
|
if (candidate.usageDisplayMode === 'usage' || candidate.usageDisplayMode === 'remaining') {
|
|
372
366
|
result.usageDisplayMode = candidate.usageDisplayMode;
|
|
373
367
|
}
|
|
374
|
-
if (typeof candidate.usageShowPredValues === 'boolean') {
|
|
375
|
-
result.usageShowPredValues = candidate.usageShowPredValues;
|
|
376
|
-
}
|
|
377
368
|
if (Array.isArray(candidate.usageDropdownProviders)) {
|
|
378
369
|
result.usageDropdownProviders = normalizeStringArray(candidate.usageDropdownProviders);
|
|
379
370
|
}
|
|
@@ -511,6 +502,9 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
511
502
|
if (typeof candidate.showOpenCodeUpdateNotifications === 'boolean') {
|
|
512
503
|
result.showOpenCodeUpdateNotifications = candidate.showOpenCodeUpdateNotifications;
|
|
513
504
|
}
|
|
505
|
+
if (typeof candidate.agentWebToolEnabled === 'boolean') {
|
|
506
|
+
result.agentWebToolEnabled = candidate.agentWebToolEnabled;
|
|
507
|
+
}
|
|
514
508
|
if (typeof candidate.agentControlToolEnabled === 'boolean') {
|
|
515
509
|
result.agentControlToolEnabled = candidate.agentControlToolEnabled;
|
|
516
510
|
}
|
|
@@ -254,6 +254,12 @@ const normalizeState = (value, fallback) => {
|
|
|
254
254
|
const nextRunAt = typeof source.nextRunAt === 'number' && Number.isFinite(source.nextRunAt)
|
|
255
255
|
? Math.max(0, Math.round(source.nextRunAt))
|
|
256
256
|
: undefined;
|
|
257
|
+
// Absolute ms of the schedule occurrence last claimed for dispatch. Used so
|
|
258
|
+
// two OpenChamber server instances sharing this config cannot both start a
|
|
259
|
+
// run for the same daily/weekly/cron/once slot (see issue #2710).
|
|
260
|
+
const lastScheduledFor = typeof source.lastScheduledFor === 'number' && Number.isFinite(source.lastScheduledFor)
|
|
261
|
+
? Math.max(0, Math.round(source.lastScheduledFor))
|
|
262
|
+
: undefined;
|
|
257
263
|
const lastSessionId = asNonEmptyString(source.lastSessionId);
|
|
258
264
|
const lastErrorRaw = asNonEmptyString(source.lastError);
|
|
259
265
|
const lastError = lastErrorRaw ? clampLength(lastErrorRaw, MAX_LAST_ERROR_LENGTH) : undefined;
|
|
@@ -269,6 +275,7 @@ const normalizeState = (value, fallback) => {
|
|
|
269
275
|
...(typeof lastRunAt === 'number' ? { lastRunAt } : {}),
|
|
270
276
|
...(typeof lastDurationMs === 'number' ? { lastDurationMs } : {}),
|
|
271
277
|
...(typeof nextRunAt === 'number' ? { nextRunAt } : {}),
|
|
278
|
+
...(typeof lastScheduledFor === 'number' ? { lastScheduledFor } : {}),
|
|
272
279
|
...(lastSessionId ? { lastSessionId } : {}),
|
|
273
280
|
...(lastError ? { lastError } : {}),
|
|
274
281
|
};
|
|
@@ -360,6 +367,9 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
360
367
|
});
|
|
361
368
|
|
|
362
369
|
const writeLocks = new Map();
|
|
370
|
+
const PROJECT_FILE_LOCK_WAIT_MS = 10_000;
|
|
371
|
+
const PROJECT_FILE_LOCK_STALE_MS = 60_000;
|
|
372
|
+
const PROJECT_FILE_LOCK_RETRY_MS = 20;
|
|
363
373
|
|
|
364
374
|
const sanitizeProjectID = (projectID) => {
|
|
365
375
|
const value = asNonEmptyString(projectID);
|
|
@@ -377,6 +387,104 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
377
387
|
return path.join(projectsDirPath, `${safeProjectID}.json`);
|
|
378
388
|
};
|
|
379
389
|
|
|
390
|
+
const isProcessAlive = (pid) => {
|
|
391
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
try {
|
|
395
|
+
process.kill(pid, 0);
|
|
396
|
+
return true;
|
|
397
|
+
} catch (error) {
|
|
398
|
+
// EPERM: process exists but belongs to another user — treat as alive.
|
|
399
|
+
return error?.code === 'EPERM';
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Cross-process exclusive lock for a project config file.
|
|
405
|
+
* In-process chaining alone cannot serialize Electron (port 57123) and CLI
|
|
406
|
+
* serve (port 3000) writers that share the same on-disk projects dir.
|
|
407
|
+
*/
|
|
408
|
+
const acquireProjectFileLock = async (projectID) => {
|
|
409
|
+
const configPath = resolveProjectConfigPath(projectID);
|
|
410
|
+
const lockPath = `${configPath}.lock`;
|
|
411
|
+
const startedAt = Date.now();
|
|
412
|
+
|
|
413
|
+
await fsPromises.mkdir(path.dirname(configPath), { recursive: true });
|
|
414
|
+
|
|
415
|
+
while (Date.now() - startedAt < PROJECT_FILE_LOCK_WAIT_MS) {
|
|
416
|
+
let handle;
|
|
417
|
+
try {
|
|
418
|
+
handle = await fsPromises.open(lockPath, 'wx');
|
|
419
|
+
const lockPayload = {
|
|
420
|
+
pid: process.pid,
|
|
421
|
+
at: Date.now(),
|
|
422
|
+
};
|
|
423
|
+
await handle.writeFile(JSON.stringify(lockPayload));
|
|
424
|
+
return {
|
|
425
|
+
release: async () => {
|
|
426
|
+
try {
|
|
427
|
+
await handle.close();
|
|
428
|
+
} catch {
|
|
429
|
+
}
|
|
430
|
+
// Only unlink if we still own the lock. A stale-recovery steal can
|
|
431
|
+
// replace the file; unlinking blindly would drop the new owner's lock.
|
|
432
|
+
try {
|
|
433
|
+
const raw = await fsPromises.readFile(lockPath, 'utf8');
|
|
434
|
+
const parsed = JSON.parse(raw);
|
|
435
|
+
if (Number(parsed?.pid) !== process.pid) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
await fsPromises.unlink(lockPath);
|
|
439
|
+
} catch {
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
} catch (error) {
|
|
444
|
+
if (handle) {
|
|
445
|
+
try {
|
|
446
|
+
await handle.close();
|
|
447
|
+
} catch {
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (error?.code !== 'EEXIST') {
|
|
451
|
+
throw error;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
try {
|
|
455
|
+
const raw = await fsPromises.readFile(lockPath, 'utf8');
|
|
456
|
+
const parsed = JSON.parse(raw);
|
|
457
|
+
const lockPid = Number(parsed?.pid);
|
|
458
|
+
const lockAt = Number(parsed?.at);
|
|
459
|
+
const staleByPid = Number.isInteger(lockPid) && lockPid > 0 && !isProcessAlive(lockPid);
|
|
460
|
+
const staleByAge = Number.isFinite(lockAt) && (Date.now() - lockAt) > PROJECT_FILE_LOCK_STALE_MS;
|
|
461
|
+
if (staleByPid || staleByAge || !Number.isInteger(lockPid)) {
|
|
462
|
+
await fsPromises.unlink(lockPath).catch(() => {});
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
} catch {
|
|
466
|
+
// Crash between open(wx) and writeFile (or a partial write) leaves an
|
|
467
|
+
// unparseable lock. Fall back to mtime age so recovery is not wedged.
|
|
468
|
+
try {
|
|
469
|
+
const stat = await fsPromises.stat(lockPath);
|
|
470
|
+
const mtimeMs = Number(stat?.mtimeMs);
|
|
471
|
+
if (Number.isFinite(mtimeMs) && (Date.now() - mtimeMs) > PROJECT_FILE_LOCK_STALE_MS) {
|
|
472
|
+
await fsPromises.unlink(lockPath).catch(() => {});
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
} catch {
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
await new Promise((resolve) => {
|
|
480
|
+
setTimeout(resolve, PROJECT_FILE_LOCK_RETRY_MS);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
throw new Error(`timeout acquiring project config lock for ${projectID}`);
|
|
486
|
+
};
|
|
487
|
+
|
|
380
488
|
const readRawProjectConfigFromDisk = async (projectID) => {
|
|
381
489
|
const filePath = resolveProjectConfigPath(projectID);
|
|
382
490
|
try {
|
|
@@ -443,8 +551,16 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
443
551
|
writeLocks.set(key, chained);
|
|
444
552
|
|
|
445
553
|
await previous;
|
|
554
|
+
// Acquire sits outside the mutate try — if it throws (10s lock timeout),
|
|
555
|
+
// we must still release the in-process chain or every later write for this
|
|
556
|
+
// project hangs forever on await previous.
|
|
446
557
|
try {
|
|
447
|
-
|
|
558
|
+
const fileLock = await acquireProjectFileLock(projectID);
|
|
559
|
+
try {
|
|
560
|
+
return await mutate();
|
|
561
|
+
} finally {
|
|
562
|
+
await fileLock.release();
|
|
563
|
+
}
|
|
448
564
|
} finally {
|
|
449
565
|
release();
|
|
450
566
|
const current = writeLocks.get(key);
|
|
@@ -533,10 +649,71 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
533
649
|
const current = await readProjectConfigFromDisk(projectID);
|
|
534
650
|
const taskIndex = current.scheduledTasks.findIndex((task) => task.id === normalizedTaskID);
|
|
535
651
|
if (taskIndex === -1) {
|
|
536
|
-
return { task: null, tasks: current.scheduledTasks };
|
|
652
|
+
return { task: null, tasks: current.scheduledTasks, updated: false };
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const currentTask = current.scheduledTasks[taskIndex];
|
|
656
|
+
const patchObject = statePatch && typeof statePatch === 'object' ? statePatch : {};
|
|
657
|
+
const nextTask = {
|
|
658
|
+
...currentTask,
|
|
659
|
+
state: normalizeState(
|
|
660
|
+
{
|
|
661
|
+
...currentTask.state,
|
|
662
|
+
...patchObject,
|
|
663
|
+
updatedAt: Date.now(),
|
|
664
|
+
},
|
|
665
|
+
currentTask.state,
|
|
666
|
+
),
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
const nextTasks = current.scheduledTasks.slice();
|
|
670
|
+
nextTasks[taskIndex] = nextTask;
|
|
671
|
+
|
|
672
|
+
await writeProjectConfigToDisk(projectID, {
|
|
673
|
+
version: PROJECT_CONFIG_VERSION,
|
|
674
|
+
scheduledTasks: nextTasks,
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
return {
|
|
678
|
+
task: nextTask,
|
|
679
|
+
tasks: nextTasks,
|
|
680
|
+
updated: true,
|
|
681
|
+
};
|
|
682
|
+
});
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Conditionally patch task runtime state under the project write lock.
|
|
687
|
+
* `predicate(currentTask)` is evaluated after the latest on-disk read; when
|
|
688
|
+
* it returns false the write is skipped and `{ updated: false }` is returned.
|
|
689
|
+
* Used by the scheduled-tasks runtime to claim a single schedule occurrence
|
|
690
|
+
* across concurrent OpenChamber server instances.
|
|
691
|
+
*/
|
|
692
|
+
const updateScheduledTaskStateIf = async (projectID, taskID, predicate, statePatch) => {
|
|
693
|
+
return withProjectWriteLock(projectID, async () => {
|
|
694
|
+
const normalizedTaskID = asNonEmptyString(taskID);
|
|
695
|
+
if (!normalizedTaskID) {
|
|
696
|
+
throw new Error('taskId is required');
|
|
697
|
+
}
|
|
698
|
+
if (typeof predicate !== 'function') {
|
|
699
|
+
throw new Error('predicate is required');
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const current = await readProjectConfigFromDisk(projectID);
|
|
703
|
+
const taskIndex = current.scheduledTasks.findIndex((task) => task.id === normalizedTaskID);
|
|
704
|
+
if (taskIndex === -1) {
|
|
705
|
+
return { task: null, tasks: current.scheduledTasks, updated: false };
|
|
537
706
|
}
|
|
538
707
|
|
|
539
708
|
const currentTask = current.scheduledTasks[taskIndex];
|
|
709
|
+
if (!predicate(currentTask)) {
|
|
710
|
+
return {
|
|
711
|
+
task: currentTask,
|
|
712
|
+
tasks: current.scheduledTasks,
|
|
713
|
+
updated: false,
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
|
|
540
717
|
const patchObject = statePatch && typeof statePatch === 'object' ? statePatch : {};
|
|
541
718
|
const nextTask = {
|
|
542
719
|
...currentTask,
|
|
@@ -561,6 +738,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
561
738
|
return {
|
|
562
739
|
task: nextTask,
|
|
563
740
|
tasks: nextTasks,
|
|
741
|
+
updated: true,
|
|
564
742
|
};
|
|
565
743
|
});
|
|
566
744
|
};
|
|
@@ -699,6 +877,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
699
877
|
upsertScheduledTask,
|
|
700
878
|
deleteScheduledTask,
|
|
701
879
|
updateScheduledTaskState,
|
|
880
|
+
updateScheduledTaskStateIf,
|
|
702
881
|
reconcileLoopTasks,
|
|
703
882
|
resolveProjectConfigPath,
|
|
704
883
|
};
|
|
@@ -471,4 +471,299 @@ describe('project-config loop reconciliation', () => {
|
|
|
471
471
|
await cleanup();
|
|
472
472
|
}
|
|
473
473
|
});
|
|
474
|
+
|
|
475
|
+
it('conditionally updates state only when the predicate passes (occurrence claim)', async () => {
|
|
476
|
+
const { runtime, cleanup } = await createRuntime();
|
|
477
|
+
try {
|
|
478
|
+
const created = await runtime.upsertScheduledTask('project-test', {
|
|
479
|
+
name: 'claim-me',
|
|
480
|
+
enabled: true,
|
|
481
|
+
schedule: { kind: 'daily', time: '15:00', timezone: 'UTC' },
|
|
482
|
+
execution: { prompt: 'Run once', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
const scheduledFor = Date.UTC(2026, 0, 1, 15, 0, 0);
|
|
486
|
+
const first = await runtime.updateScheduledTaskStateIf(
|
|
487
|
+
'project-test',
|
|
488
|
+
created.task.id,
|
|
489
|
+
(task) => !Number.isFinite(task.state?.lastScheduledFor),
|
|
490
|
+
{
|
|
491
|
+
lastScheduledFor: scheduledFor,
|
|
492
|
+
lastStatus: 'running',
|
|
493
|
+
nextRunAt: scheduledFor + 86_400_000,
|
|
494
|
+
},
|
|
495
|
+
);
|
|
496
|
+
expect(first.updated).toBe(true);
|
|
497
|
+
expect(first.task.state.lastScheduledFor).toBe(scheduledFor);
|
|
498
|
+
|
|
499
|
+
const second = await runtime.updateScheduledTaskStateIf(
|
|
500
|
+
'project-test',
|
|
501
|
+
created.task.id,
|
|
502
|
+
(task) => task.state?.lastScheduledFor !== scheduledFor,
|
|
503
|
+
{
|
|
504
|
+
lastScheduledFor: scheduledFor,
|
|
505
|
+
lastStatus: 'running',
|
|
506
|
+
},
|
|
507
|
+
);
|
|
508
|
+
expect(second.updated).toBe(false);
|
|
509
|
+
expect(second.task.state.lastScheduledFor).toBe(scheduledFor);
|
|
510
|
+
|
|
511
|
+
const reloaded = await runtime.listScheduledTasks('project-test');
|
|
512
|
+
expect(reloaded[0].state.lastScheduledFor).toBe(scheduledFor);
|
|
513
|
+
} finally {
|
|
514
|
+
await cleanup();
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it('serializes concurrent writes across two runtimes sharing a projects dir', async () => {
|
|
519
|
+
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'oc-project-lock-contention-'));
|
|
520
|
+
const fsPromises = await import('fs/promises');
|
|
521
|
+
try {
|
|
522
|
+
const runtimeA = createProjectConfigRuntime({
|
|
523
|
+
fsPromises,
|
|
524
|
+
path,
|
|
525
|
+
projectsDirPath: tempRoot,
|
|
526
|
+
createTaskID: () => 'shared-task',
|
|
527
|
+
});
|
|
528
|
+
const runtimeB = createProjectConfigRuntime({
|
|
529
|
+
fsPromises,
|
|
530
|
+
path,
|
|
531
|
+
projectsDirPath: tempRoot,
|
|
532
|
+
createTaskID: () => 'shared-task',
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
await runtimeA.upsertScheduledTask('project-lock', {
|
|
536
|
+
name: 'contended',
|
|
537
|
+
enabled: true,
|
|
538
|
+
schedule: { kind: 'daily', time: '15:00', timezone: 'UTC' },
|
|
539
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
await Promise.all([
|
|
543
|
+
runtimeA.updateScheduledTaskState('project-lock', 'shared-task', {
|
|
544
|
+
lastStatus: 'success',
|
|
545
|
+
lastRunAt: 100,
|
|
546
|
+
}),
|
|
547
|
+
runtimeB.updateScheduledTaskState('project-lock', 'shared-task', {
|
|
548
|
+
lastStatus: 'error',
|
|
549
|
+
lastRunAt: 200,
|
|
550
|
+
}),
|
|
551
|
+
]);
|
|
552
|
+
|
|
553
|
+
const tasks = await runtimeA.listScheduledTasks('project-lock');
|
|
554
|
+
expect(tasks).toHaveLength(1);
|
|
555
|
+
expect(['success', 'error']).toContain(tasks[0].state.lastStatus);
|
|
556
|
+
expect([100, 200]).toContain(tasks[0].state.lastRunAt);
|
|
557
|
+
|
|
558
|
+
const lockPath = `${runtimeA.resolveProjectConfigPath('project-lock')}.lock`;
|
|
559
|
+
await expect(fsPromises.access(lockPath)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
560
|
+
} finally {
|
|
561
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('recovers from a stale-by-age project config lock and cleans it up', async () => {
|
|
566
|
+
const { runtime, cleanup } = await createRuntime();
|
|
567
|
+
const fsPromises = await import('fs/promises');
|
|
568
|
+
try {
|
|
569
|
+
const projectID = 'stale-age';
|
|
570
|
+
const configPath = runtime.resolveProjectConfigPath(projectID);
|
|
571
|
+
const lockPath = `${configPath}.lock`;
|
|
572
|
+
await fsPromises.mkdir(path.dirname(configPath), { recursive: true });
|
|
573
|
+
await writeFile(lockPath, JSON.stringify({
|
|
574
|
+
pid: process.pid,
|
|
575
|
+
at: Date.now() - 120_000,
|
|
576
|
+
}));
|
|
577
|
+
|
|
578
|
+
const created = await runtime.upsertScheduledTask(projectID, {
|
|
579
|
+
name: 'after-stale',
|
|
580
|
+
enabled: true,
|
|
581
|
+
schedule: { kind: 'daily', time: '09:00', timezone: 'UTC' },
|
|
582
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
583
|
+
});
|
|
584
|
+
expect(created.created).toBe(true);
|
|
585
|
+
await expect(fsPromises.access(lockPath)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
586
|
+
} finally {
|
|
587
|
+
await cleanup();
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('recovers from a stale-by-dead-pid project config lock', async () => {
|
|
592
|
+
const { runtime, cleanup } = await createRuntime();
|
|
593
|
+
const fsPromises = await import('fs/promises');
|
|
594
|
+
try {
|
|
595
|
+
const projectID = 'stale-pid';
|
|
596
|
+
const configPath = runtime.resolveProjectConfigPath(projectID);
|
|
597
|
+
const lockPath = `${configPath}.lock`;
|
|
598
|
+
await fsPromises.mkdir(path.dirname(configPath), { recursive: true });
|
|
599
|
+
// PID unlikely to exist; kill(pid, 0) should fail with ESRCH.
|
|
600
|
+
await writeFile(lockPath, JSON.stringify({
|
|
601
|
+
pid: 2_147_483_647,
|
|
602
|
+
at: Date.now(),
|
|
603
|
+
}));
|
|
604
|
+
|
|
605
|
+
const created = await runtime.upsertScheduledTask(projectID, {
|
|
606
|
+
name: 'after-dead-pid',
|
|
607
|
+
enabled: true,
|
|
608
|
+
schedule: { kind: 'daily', time: '09:00', timezone: 'UTC' },
|
|
609
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
610
|
+
});
|
|
611
|
+
expect(created.created).toBe(true);
|
|
612
|
+
await expect(fsPromises.access(lockPath)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
613
|
+
} finally {
|
|
614
|
+
await cleanup();
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it('release does not unlink a lock stolen by another holder', async () => {
|
|
619
|
+
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'oc-project-lock-own-'));
|
|
620
|
+
const realFs = await import('fs/promises');
|
|
621
|
+
let enteredCritical;
|
|
622
|
+
const entered = new Promise((resolve) => {
|
|
623
|
+
enteredCritical = resolve;
|
|
624
|
+
});
|
|
625
|
+
let resumeCritical;
|
|
626
|
+
const hold = new Promise((resolve) => {
|
|
627
|
+
resumeCritical = resolve;
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
const fsPromises = {
|
|
631
|
+
...realFs,
|
|
632
|
+
rename: async (from, to) => {
|
|
633
|
+
if (String(from).includes('.tmp-')) {
|
|
634
|
+
enteredCritical();
|
|
635
|
+
await hold;
|
|
636
|
+
}
|
|
637
|
+
return realFs.rename(from, to);
|
|
638
|
+
},
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
try {
|
|
642
|
+
const runtime = createProjectConfigRuntime({
|
|
643
|
+
fsPromises,
|
|
644
|
+
path,
|
|
645
|
+
projectsDirPath: tempRoot,
|
|
646
|
+
createTaskID: () => 'owned-task',
|
|
647
|
+
});
|
|
648
|
+
const projectID = 'lock-own';
|
|
649
|
+
const lockPath = `${runtime.resolveProjectConfigPath(projectID)}.lock`;
|
|
650
|
+
const stolenPid = process.pid + 1;
|
|
651
|
+
|
|
652
|
+
const upsertPromise = runtime.upsertScheduledTask(projectID, {
|
|
653
|
+
name: 'ownership',
|
|
654
|
+
enabled: true,
|
|
655
|
+
schedule: { kind: 'daily', time: '10:00', timezone: 'UTC' },
|
|
656
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
await entered;
|
|
660
|
+
await realFs.writeFile(lockPath, JSON.stringify({
|
|
661
|
+
pid: stolenPid,
|
|
662
|
+
at: Date.now(),
|
|
663
|
+
}));
|
|
664
|
+
resumeCritical();
|
|
665
|
+
await upsertPromise;
|
|
666
|
+
|
|
667
|
+
const raw = await realFs.readFile(lockPath, 'utf8');
|
|
668
|
+
expect(JSON.parse(raw).pid).toBe(stolenPid);
|
|
669
|
+
} finally {
|
|
670
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
it('times out when a live lock holder never releases', async () => {
|
|
675
|
+
const { runtime, cleanup } = await createRuntime();
|
|
676
|
+
const fsPromises = await import('fs/promises');
|
|
677
|
+
try {
|
|
678
|
+
const projectID = 'lock-timeout';
|
|
679
|
+
const configPath = runtime.resolveProjectConfigPath(projectID);
|
|
680
|
+
const lockPath = `${configPath}.lock`;
|
|
681
|
+
await fsPromises.mkdir(path.dirname(configPath), { recursive: true });
|
|
682
|
+
// Current process is alive — acquire must wait then throw.
|
|
683
|
+
await writeFile(lockPath, JSON.stringify({
|
|
684
|
+
pid: process.pid,
|
|
685
|
+
at: Date.now(),
|
|
686
|
+
}));
|
|
687
|
+
|
|
688
|
+
await expect(runtime.upsertScheduledTask(projectID, {
|
|
689
|
+
name: 'blocked',
|
|
690
|
+
enabled: true,
|
|
691
|
+
schedule: { kind: 'daily', time: '11:00', timezone: 'UTC' },
|
|
692
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
693
|
+
})).rejects.toThrow(/timeout acquiring project config lock/);
|
|
694
|
+
} finally {
|
|
695
|
+
await cleanup();
|
|
696
|
+
}
|
|
697
|
+
}, 15_000);
|
|
698
|
+
|
|
699
|
+
it('releases the write chain after a lock timeout so a later write can complete', async () => {
|
|
700
|
+
const { runtime, cleanup } = await createRuntime();
|
|
701
|
+
const fsPromises = await import('fs/promises');
|
|
702
|
+
try {
|
|
703
|
+
const projectID = 'lock-timeout-recover';
|
|
704
|
+
const configPath = runtime.resolveProjectConfigPath(projectID);
|
|
705
|
+
const lockPath = `${configPath}.lock`;
|
|
706
|
+
await fsPromises.mkdir(path.dirname(configPath), { recursive: true });
|
|
707
|
+
await writeFile(lockPath, JSON.stringify({
|
|
708
|
+
pid: process.pid,
|
|
709
|
+
at: Date.now(),
|
|
710
|
+
}));
|
|
711
|
+
|
|
712
|
+
await expect(runtime.upsertScheduledTask(projectID, {
|
|
713
|
+
name: 'blocked-then-recover',
|
|
714
|
+
enabled: true,
|
|
715
|
+
schedule: { kind: 'daily', time: '11:00', timezone: 'UTC' },
|
|
716
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
717
|
+
})).rejects.toThrow(/timeout acquiring project config lock/);
|
|
718
|
+
|
|
719
|
+
// Remove the hostile lock. A wedged in-process chain would hang forever here.
|
|
720
|
+
await fsPromises.unlink(lockPath);
|
|
721
|
+
|
|
722
|
+
const created = await Promise.race([
|
|
723
|
+
runtime.upsertScheduledTask(projectID, {
|
|
724
|
+
name: 'after-timeout',
|
|
725
|
+
enabled: true,
|
|
726
|
+
schedule: { kind: 'daily', time: '12:00', timezone: 'UTC' },
|
|
727
|
+
execution: { prompt: 'Run after timeout', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
728
|
+
}),
|
|
729
|
+
new Promise((_, reject) => {
|
|
730
|
+
setTimeout(() => reject(new Error('second write hung after lock timeout')), 3_000);
|
|
731
|
+
}),
|
|
732
|
+
]);
|
|
733
|
+
|
|
734
|
+
expect(created.created).toBe(true);
|
|
735
|
+
expect(created.task.name).toBe('after-timeout');
|
|
736
|
+
const listed = await runtime.listScheduledTasks(projectID);
|
|
737
|
+
expect(listed).toHaveLength(1);
|
|
738
|
+
expect(listed[0].name).toBe('after-timeout');
|
|
739
|
+
} finally {
|
|
740
|
+
await cleanup();
|
|
741
|
+
}
|
|
742
|
+
}, 20_000);
|
|
743
|
+
|
|
744
|
+
it('recovers from an unparseable lock using mtime age', async () => {
|
|
745
|
+
const { runtime, cleanup } = await createRuntime();
|
|
746
|
+
const fsPromises = await import('fs/promises');
|
|
747
|
+
try {
|
|
748
|
+
const projectID = 'stale-unparseable';
|
|
749
|
+
const configPath = runtime.resolveProjectConfigPath(projectID);
|
|
750
|
+
const lockPath = `${configPath}.lock`;
|
|
751
|
+
await fsPromises.mkdir(path.dirname(configPath), { recursive: true });
|
|
752
|
+
// Simulate crash between open(wx) and writeFile / partial payload.
|
|
753
|
+
await writeFile(lockPath, '{not-json');
|
|
754
|
+
const staleMtime = new Date(Date.now() - 120_000);
|
|
755
|
+
await fsPromises.utimes(lockPath, staleMtime, staleMtime);
|
|
756
|
+
|
|
757
|
+
const created = await runtime.upsertScheduledTask(projectID, {
|
|
758
|
+
name: 'after-unparseable',
|
|
759
|
+
enabled: true,
|
|
760
|
+
schedule: { kind: 'daily', time: '09:00', timezone: 'UTC' },
|
|
761
|
+
execution: { prompt: 'Run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
762
|
+
});
|
|
763
|
+
expect(created.created).toBe(true);
|
|
764
|
+
await expect(fsPromises.access(lockPath)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
765
|
+
} finally {
|
|
766
|
+
await cleanup();
|
|
767
|
+
}
|
|
768
|
+
});
|
|
474
769
|
});
|
|
@@ -33,7 +33,7 @@ These provider IDs are currently dispatchable via `fetchQuotaForProvider(provide
|
|
|
33
33
|
| `minimax-cn-coding-plan` | MiniMax Coding Plan (minimaxi.com) | `providers/minimax-cn-coding-plan.js` / `providers/minimax-shared.js` | `minimax-cn-coding-plan` |
|
|
34
34
|
| `ollama-cloud` | Ollama Cloud | `providers/ollama-cloud.js` | Manual cookie stored under `~/.config/openchamber/quota/` |
|
|
35
35
|
| `wafer` | Wafer.ai | `providers/wafer.js` | `wafer`, `wafer-ai`, `wafer_ai`, `wafer.ai` |
|
|
36
|
-
| `opencode-go` | OpenCode Go | `providers/opencode-go.js` |
|
|
36
|
+
| `opencode-go` | OpenCode Go | `providers/opencode-go.js` | `opencode-go` API key from OpenCode `auth.json` |
|
|
37
37
|
| `neuralwatt` | NeuralWatt | `providers/neuralwatt.js` | `neuralwatt` (API key under `key` or `token`) |
|
|
38
38
|
| `xai` | xAI | `providers/xai.js` | `xai` OAuth entry in OpenCode `auth.json` |
|
|
39
39
|
|
|
@@ -49,7 +49,9 @@ All providers should return results via shared helpers to preserve API shape:
|
|
|
49
49
|
Provider modules must export `providerId`, `providerName`, `aliases`, `isConfigured(auth?)`, and `fetchQuota()`.
|
|
50
50
|
`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.
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
On the first OpenCode Go usage refresh after upgrading, OpenChamber deletes the obsolete `quota/opencode-go.json` credential file without reading its cookie value.
|
|
53
55
|
|
|
54
56
|
## Add a new provider (quick steps)
|
|
55
57
|
1. Choose module shape based on complexity:
|
|
@@ -3,12 +3,6 @@ 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
|
-
'opencode-go': (value) => {
|
|
7
|
-
const workspaceId = clean(value?.workspaceId);
|
|
8
|
-
let authCookie = clean(value?.authCookie);
|
|
9
|
-
if (authCookie.startsWith('auth=')) authCookie = authCookie.slice(5).trim();
|
|
10
|
-
return workspaceId && authCookie ? { workspaceId, authCookie } : null;
|
|
11
|
-
},
|
|
12
6
|
'ollama-cloud': (value) => {
|
|
13
7
|
const cookie = clean(value?.cookie);
|
|
14
8
|
return cookie ? { cookie } : null;
|
|
@@ -35,7 +29,6 @@ export const writeManagedCredential = (providerId, value) => {
|
|
|
35
29
|
export const getManagedCredentialStatus = (providerId) => {
|
|
36
30
|
const credential = readManagedCredential(providerId);
|
|
37
31
|
if (!credential) return { configured: false };
|
|
38
|
-
if (providerId === 'opencode-go') return { configured: true, workspaceId: credential.workspaceId, secretMasked: '••••••••' };
|
|
39
32
|
if (providerId === 'cursor') return { configured: true, hasRefreshToken: Boolean(credential.refreshToken), secretMasked: '••••••••' };
|
|
40
33
|
return { configured: true, secretMasked: '••••••••' };
|
|
41
34
|
};
|
|
@@ -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(['
|
|
5
|
+
const MANAGED_QUOTA_PROVIDERS = new Set(['ollama-cloud', 'cursor']);
|
|
6
6
|
|
|
7
7
|
const credentialsDirectory = () => path.join(
|
|
8
8
|
process.env.OPENCHAMBER_DATA_DIR
|
|
@@ -46,3 +46,13 @@ export const deleteQuotaCredential = (providerId) => {
|
|
|
46
46
|
if (error?.code !== 'ENOENT') throw error;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
// OpenCode Go used to store a browser auth cookie here. Its usage API now uses
|
|
51
|
+
// OpenCode's auth.json API key, so remove the obsolete secret without reading it.
|
|
52
|
+
export const deleteLegacyOpenCodeGoCredential = () => {
|
|
53
|
+
try {
|
|
54
|
+
fs.unlinkSync(path.join(credentialsDirectory(), 'opencode-go.json'));
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -2,7 +2,7 @@ import { afterAll, describe, expect, it } from 'bun:test';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { deleteQuotaCredential, readQuotaCredential, writeQuotaCredential } from './store.js';
|
|
5
|
+
import { deleteLegacyOpenCodeGoCredential, deleteQuotaCredential, readQuotaCredential, writeQuotaCredential } from './store.js';
|
|
6
6
|
|
|
7
7
|
const previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
|
|
8
8
|
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-quota-store-'));
|
|
@@ -17,6 +17,14 @@ describe('quota credential store', () => {
|
|
|
17
17
|
expect(() => writeQuotaCredential('../escape', {})).toThrow('Unsupported credential provider');
|
|
18
18
|
deleteQuotaCredential('ollama-cloud');
|
|
19
19
|
});
|
|
20
|
+
|
|
21
|
+
it('removes the obsolete OpenCode Go credential without parsing it', () => {
|
|
22
|
+
const legacyPath = path.join(temporaryDirectory, 'quota', 'opencode-go.json');
|
|
23
|
+
fs.mkdirSync(path.dirname(legacyPath), { recursive: true });
|
|
24
|
+
fs.writeFileSync(legacyPath, '{not valid json', { mode: 0o600 });
|
|
25
|
+
deleteLegacyOpenCodeGoCredential();
|
|
26
|
+
expect(fs.existsSync(legacyPath)).toBe(false);
|
|
27
|
+
});
|
|
20
28
|
});
|
|
21
29
|
|
|
22
30
|
afterAll(() => {
|