@openchamber/web 1.23.0 → 1.23.2
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-DbcnxAfY.js → CodeMirrorCommentWidgets-DdNGwbBw.js} +1 -1
- package/dist/assets/DiffView-GYriC0Wk.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-DE2sKIYv.js → DirtyBranchSwitchDialog-Bv0C99hc.js} +1 -1
- package/dist/assets/FilesView-2Lin13wx.js +13 -0
- package/dist/assets/{GitView-CKgUkb5Z.js → GitView-9wKba3UO.js} +4 -4
- package/dist/assets/{JsonTreeView-Bce2ettZ.js → JsonTreeView-Chzx5Y6N.js} +1 -1
- package/dist/assets/{LinearIssuesView-BZVWM2zw.js → LinearIssuesView-DXS9QJiR.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-DdROVz29.js → MarkdownImageGallery-CugnrZ6f.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CenrzmMN.js → MarkdownRendererImpl-CaMyct2Q.js} +4 -4
- package/dist/assets/{OnboardingScreen-DyqYG_NP.js → OnboardingScreen-hH9xcTjA.js} +1 -1
- package/dist/assets/{PatchDiff-CR3RVO5I.js → PatchDiff-DRgNYc9l.js} +1 -1
- package/dist/assets/{PierreDiffViewer-KihzO94X.js → PierreDiffViewer-ZT2CKuzJ.js} +1 -1
- package/dist/assets/PlanView-DiTBm2BD.js +5 -0
- package/dist/assets/SettingsView-CN8VeM99.js +28 -0
- package/dist/assets/{SettingsWindow-CV_hzB5v.js → SettingsWindow-DisOghhD.js} +1 -1
- package/dist/assets/{ToolOutputDialog-llKecK_Z.js → ToolOutputDialog-BqiKydxR.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-ZDMTdCGn.js → ToolPartDiffPreview-oWxWCu-4.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-ClvqQ4j0.js → VirtualizedFileDiff-CiyrAq_I.js} +4 -4
- package/dist/assets/WalkthroughView-CKTevaea.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-Nm5_wabb.js → computeVirtualFileMetrics-SUWoTyPe.js} +2 -2
- package/dist/assets/de-DQWC94VK.js +10 -0
- package/dist/assets/es-DixFUD3m.js +16 -0
- package/dist/assets/{fr-CP6jqIzw.js → fr-D6u8tvfA.js} +4 -4
- package/dist/assets/index-BvpFzhLs.js +40 -0
- package/dist/assets/{index-Du9sZhDb.js → index-C4jJ3Ur5.js} +1 -1
- package/dist/assets/index-n5p3SnES.css +1 -0
- package/dist/assets/{isDiffPlainText-EQERIius.js → isDiffPlainText-DfG0cZxr.js} +1 -1
- package/dist/assets/{isFilePlainText-BCoVpkQy.js → isFilePlainText-CyNivOCU.js} +1 -1
- package/dist/assets/ja-4u4pCorB.js +16 -0
- package/dist/assets/ko-C27-LW_b.js +16 -0
- package/dist/assets/{main-DPf32fO6.js → main-B8cGozKr.js} +2 -2
- package/dist/assets/main-tEA-fFPg.js +930 -0
- package/dist/assets/markdownCore-kyGrWGsn.js +5 -0
- package/dist/assets/{miniChat-CHqVTsgj.js → miniChat-Cay99IxR.js} +2 -2
- package/dist/assets/{mobile-BQmgHA57.js → mobile-Zfhix7nz.js} +2 -2
- package/dist/assets/patchFileDiff-CJ5AN9Ql.js +13 -0
- package/dist/assets/{pl-B215pG1Y.js → pl-FtCjsNdW.js} +4 -4
- package/dist/assets/pt-BR-CLosVawq.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +2 -0
- package/dist/assets/renderMobileApp-C4X_KUH8.js +25 -0
- package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +41 -0
- package/dist/assets/scheduledTasksApi-CGFV4Pap.js +1 -0
- package/dist/assets/{shikiHighlight-BTObuQCR.js → shikiHighlight-DdKWYWrV.js} +1 -1
- package/dist/assets/surface-B6n7wJtt.js +1 -0
- package/dist/assets/tr-D2j6wUez.js +7 -0
- package/dist/assets/uk-C6IzmwM_.js +16 -0
- package/dist/assets/{useAppFontEffects-theH_IJL.js → useAppFontEffects-DgCHy6Mr.js} +134 -136
- package/dist/assets/useGitComparison-BIaI0WZI.js +1 -0
- package/dist/assets/{useInlineCommentController-Bs3PgeA8.js → useInlineCommentController-2wcCtpM3.js} +2 -2
- package/dist/assets/{useRootScrollLock-hSYwnxZs.js → useRootScrollLock-CbWA03xR.js} +1 -1
- package/dist/assets/{vendor-base-ui-DdV8vhHn.js → vendor-base-ui-BY_5qla_.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Cxgr01md.js → vendor-codemirror-language-data-ES33GhKK.js} +2 -2
- package/dist/assets/{vendor-remixicon-react-Dil0zKKT.js → vendor-remixicon-react-BDmGmFCA.js} +1 -1
- package/dist/assets/{vendor-zod-BPAANqvH.js → vendor-zod-B6551dwG.js} +2 -2
- package/dist/assets/{web-components-CaS0ksnZ.js → web-components-CJZwV5BE.js} +1 -1
- package/dist/assets/zh-CN-Wl6tIDz1.js +16 -0
- package/dist/assets/zh-TW-hgphoWSN.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +3 -13
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/agent-memory/runtime.test.js +22 -0
- package/server/lib/event-stream/DOCUMENTATION.md +3 -0
- package/server/lib/event-stream/global-hub.js +29 -4
- package/server/lib/event-stream/global-hub.test.js +22 -0
- package/server/lib/event-stream/global-ws-bridge.js +15 -18
- package/server/lib/event-stream/protocol.js +21 -7
- package/server/lib/event-stream/runtime.js +9 -6
- package/server/lib/event-stream/runtime.test.js +60 -0
- package/server/lib/git/DOCUMENTATION.md +10 -1
- package/server/lib/git/routes.js +21 -8
- package/server/lib/git/routes.test.js +78 -0
- package/server/lib/git/service.js +159 -4
- package/server/lib/git/service.test.js +74 -0
- package/server/lib/github/DOCUMENTATION.md +5 -0
- package/server/lib/github/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +7 -0
- package/server/lib/message-queue/runtime.js +13 -0
- package/server/lib/message-queue/runtime.test.js +31 -1
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/emitter-runtime.js +4 -3
- package/server/lib/opencode/DOCUMENTATION.md +32 -4
- package/server/lib/opencode/env-runtime.js +5 -1
- package/server/lib/opencode/env-runtime.test.js +72 -0
- package/server/lib/opencode/feature-routes-runtime.js +15 -1
- package/server/lib/opencode/lifecycle.js +4 -3
- package/server/lib/opencode/lifecycle.test.js +29 -0
- package/server/lib/opencode/managed-plugin-config.js +1 -1
- package/server/lib/opencode/openchamber-routes.js +72 -14
- package/server/lib/opencode/openchamber-routes.test.js +71 -3
- package/server/lib/opencode/proxy.js +33 -0
- package/server/lib/opencode/settings-helpers.js +8 -0
- package/server/lib/opencode/settings-helpers.test.js +24 -2
- package/server/lib/opencode/settings-registry.json +6 -0
- package/server/lib/opencode/settings-runtime.js +36 -9
- package/server/lib/opencode/settings-runtime.test.js +158 -2
- package/server/lib/project-context/DOCUMENTATION.md +13 -3
- package/server/lib/project-context/runtime.js +8 -2
- package/server/lib/project-context/runtime.test.js +54 -0
- package/server/lib/projects/DOCUMENTATION.md +2 -1
- package/server/lib/projects/project-config.js +38 -9
- package/server/lib/projects/project-config.test.js +97 -0
- package/server/lib/projects/project-id.js +26 -0
- package/server/lib/relay/DOCUMENTATION.md +20 -0
- package/server/lib/relay/host-client.js +7 -0
- package/server/lib/relay/host-client.test.js +14 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
- package/server/lib/scheduled-tasks/runtime.js +12 -2
- package/server/lib/scheduled-tasks/runtime.test.js +53 -0
- package/server/lib/session-assist/DOCUMENTATION.md +131 -66
- package/server/lib/session-assist/context.js +127 -0
- package/server/lib/session-assist/context.test.js +132 -0
- package/server/lib/session-assist/prompt.js +54 -0
- package/server/lib/session-assist/runtime.js +111 -257
- package/server/lib/session-assist/runtime.test.js +203 -0
- package/server/lib/walkthrough/DOCUMENTATION.md +15 -5
- package/server/lib/walkthrough/pr-source.test.js +21 -0
- package/server/lib/walkthrough/pull-request.js +7 -4
- package/server/lib/walkthrough/pull-request.test.js +16 -0
- package/server/lib/walkthrough/routes.js +19 -0
- package/server/lib/walkthrough/routes.test.js +26 -0
- package/server/lib/walkthrough/sources.js +13 -2
- package/server/opencode-worktree-readiness.test.js +130 -0
- package/dist/assets/DiffView-Dp1tomqK.js +0 -4
- package/dist/assets/FilesView-C_of2nIT.js +0 -17
- package/dist/assets/PlanView-jcQAfr2A.js +0 -5
- package/dist/assets/SettingsView-Buvom5A2.js +0 -28
- package/dist/assets/WalkthroughView-BgpSnSlU.js +0 -4
- package/dist/assets/de-DTQDjaiv.js +0 -10
- package/dist/assets/es-SOCFd_r-.js +0 -16
- package/dist/assets/index-B68h5S5B.css +0 -1
- package/dist/assets/index-CRf2xk51.js +0 -39
- package/dist/assets/ja-BKfafwsD.js +0 -16
- package/dist/assets/ko-BA5xgCYp.js +0 -16
- package/dist/assets/main-BNiPEont.js +0 -930
- package/dist/assets/markdownCore-CQ7CAuuV.js +0 -5
- package/dist/assets/patchFileDiff-C4X_trug.js +0 -13
- package/dist/assets/pt-BR-Bo2pnlEa.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-BUcHPOXW.js +0 -2
- package/dist/assets/renderMobileApp-BvTmuRE-.js +0 -25
- package/dist/assets/runtimeEndpointReset-C8GAA2kS.js +0 -17
- package/dist/assets/scheduledTasksApi-BAScWwt3.js +0 -1
- package/dist/assets/surface-BvRzS58U.js +0 -1
- package/dist/assets/tr-CUaxHc8X.js +0 -7
- package/dist/assets/uk-YTJgyqAZ.js +0 -16
- package/dist/assets/useGitComparison-B94I6kOI.js +0 -1
- package/dist/assets/zh-CN-CZ2BxZS6.js +0 -16
- package/dist/assets/zh-TW-BsUrPdXz.js +0 -16
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
- package/server/lib/mcp-reconnect/runtime.js +0 -122
- package/server/lib/mcp-reconnect/runtime.test.js +0 -140
|
@@ -136,6 +136,9 @@
|
|
|
136
136
|
"autoDeleteAfterDays": {
|
|
137
137
|
"scope": "instance"
|
|
138
138
|
},
|
|
139
|
+
"sessionRetentionOnlyArchived": {
|
|
140
|
+
"scope": "instance"
|
|
141
|
+
},
|
|
139
142
|
"sessionRetentionAction": {
|
|
140
143
|
"scope": "instance"
|
|
141
144
|
},
|
|
@@ -214,6 +217,9 @@
|
|
|
214
217
|
"sidebarShowRecentSection": {
|
|
215
218
|
"scope": "profile"
|
|
216
219
|
},
|
|
220
|
+
"workStatusSectionOrder": {
|
|
221
|
+
"scope": "profile"
|
|
222
|
+
},
|
|
217
223
|
"workStatusPanelEnabled": {
|
|
218
224
|
"scope": "profile"
|
|
219
225
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
1
|
+
import { createProjectIdFromPath, projectConfigFileStemOf } from '../projects/project-id.js';
|
|
2
2
|
import {
|
|
3
3
|
buildPreferencesFields,
|
|
4
4
|
flattenPreferences,
|
|
@@ -288,10 +288,10 @@ export const createSettingsRuntime = (deps) => {
|
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
const oldConfigPath = path.join(PROJECTS_ROOT_DIR, `${oldId}.json`);
|
|
292
|
-
const newConfigPath = path.join(PROJECTS_ROOT_DIR, `${newId}.json`);
|
|
293
|
-
const oldStorageDir = path.join(PROJECTS_ROOT_DIR, oldId);
|
|
294
|
-
const newStorageDir = path.join(PROJECTS_ROOT_DIR, newId);
|
|
291
|
+
const oldConfigPath = path.join(PROJECTS_ROOT_DIR, `${projectConfigFileStemOf(oldId)}.json`);
|
|
292
|
+
const newConfigPath = path.join(PROJECTS_ROOT_DIR, `${projectConfigFileStemOf(newId)}.json`);
|
|
293
|
+
const oldStorageDir = path.join(PROJECTS_ROOT_DIR, projectConfigFileStemOf(oldId));
|
|
294
|
+
const newStorageDir = path.join(PROJECTS_ROOT_DIR, projectConfigFileStemOf(newId));
|
|
295
295
|
|
|
296
296
|
const [oldConfig, newConfig] = await Promise.all([
|
|
297
297
|
readJsonFile(oldConfigPath),
|
|
@@ -308,6 +308,28 @@ export const createSettingsRuntime = (deps) => {
|
|
|
308
308
|
await fsPromises.rm(oldConfigPath, { force: true });
|
|
309
309
|
};
|
|
310
310
|
|
|
311
|
+
/**
|
|
312
|
+
* A build before the bounded folder name created `<projectId>/` for an id
|
|
313
|
+
* the filesystem still accepted (201 to 255 characters; longer ids never
|
|
314
|
+
* got a folder). Only the bounded folder is read now, so that folder's
|
|
315
|
+
* notes, plans, and memory are moved over once. A raw name the filesystem
|
|
316
|
+
* cannot hold (ENAMETOOLONG) means no such folder ever existed.
|
|
317
|
+
*/
|
|
318
|
+
const migrateRawIdStorageFolder = async (projectId) => {
|
|
319
|
+
const stem = projectConfigFileStemOf(projectId);
|
|
320
|
+
if (stem === projectId) return;
|
|
321
|
+
const rawStorageDir = path.join(PROJECTS_ROOT_DIR, projectId);
|
|
322
|
+
try {
|
|
323
|
+
await fsPromises.stat(rawStorageDir);
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (error?.code === 'ENOENT' || error?.code === 'ENAMETOOLONG') return;
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
const boundedStorageDir = path.join(PROJECTS_ROOT_DIR, stem);
|
|
329
|
+
await mergeProjectContextFiles(rawStorageDir, boundedStorageDir);
|
|
330
|
+
await moveDirectoryContents(rawStorageDir, boundedStorageDir);
|
|
331
|
+
};
|
|
332
|
+
|
|
311
333
|
const migrateSettingsToDeterministicProjectIds = async (current) => {
|
|
312
334
|
const settings = current && typeof current === 'object' ? current : {};
|
|
313
335
|
const projects = sanitizeProjects(settings.projects) || [];
|
|
@@ -328,6 +350,7 @@ export const createSettingsRuntime = (deps) => {
|
|
|
328
350
|
await migrateProjectScopedStorage({ oldId: project.id, newId: nextId, projectPath: project.path });
|
|
329
351
|
await migrateProjectIconFiles({ oldId: project.id, newId: nextId });
|
|
330
352
|
}
|
|
353
|
+
await migrateRawIdStorageFolder(nextId);
|
|
331
354
|
nextProjects.push({ ...project, id: nextId });
|
|
332
355
|
}
|
|
333
356
|
|
|
@@ -468,19 +491,23 @@ export const createSettingsRuntime = (deps) => {
|
|
|
468
491
|
for (const [projectId, orphansForProject] of matches.entries()) {
|
|
469
492
|
const project = canonicalProjects.find((p) => p.id === projectId);
|
|
470
493
|
if (!project) continue;
|
|
471
|
-
const
|
|
494
|
+
const targetStem = projectConfigFileStemOf(project.id);
|
|
495
|
+
const targetPath = path.join(PROJECTS_ROOT_DIR, `${targetStem}.json`);
|
|
496
|
+
const targetStorageDir = path.join(PROJECTS_ROOT_DIR, targetStem);
|
|
472
497
|
|
|
473
498
|
for (const orphan of orphansForProject) {
|
|
474
499
|
const targetExisting = (await readJsonFile(targetPath)) || {};
|
|
500
|
+
// An orphan is named by the file found on disk, so its folder is the raw name.
|
|
501
|
+
const orphanStorageDir = path.join(PROJECTS_ROOT_DIR, orphan.orphanId);
|
|
475
502
|
const merged = mergeProjectConfigData({
|
|
476
503
|
oldConfig: orphan.content,
|
|
477
504
|
newConfig: targetExisting,
|
|
478
|
-
oldStorageDir:
|
|
479
|
-
newStorageDir:
|
|
505
|
+
oldStorageDir: orphanStorageDir,
|
|
506
|
+
newStorageDir: targetStorageDir,
|
|
480
507
|
projectPath: project.path,
|
|
481
508
|
});
|
|
482
509
|
await writeJsonFile(targetPath, merged);
|
|
483
|
-
await moveDirectoryContents(
|
|
510
|
+
await moveDirectoryContents(orphanStorageDir, targetStorageDir);
|
|
484
511
|
await fsPromises.rm(orphan.filePath, { force: true });
|
|
485
512
|
orphansConsumed.add(orphan.orphanId);
|
|
486
513
|
console.log(`[projects] Recovered orphan ${orphan.orphanId} -> ${project.id} (${project.path})`);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import fsPromises from 'fs/promises';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
6
|
+
import { createProjectIdFromPath, projectConfigFileStemOf } from '../projects/project-id.js';
|
|
7
7
|
import { createSettingsRuntime } from './settings-runtime.js';
|
|
8
8
|
|
|
9
9
|
const createRuntime = async ({ mergePersistedSettings = (_current, changes) => changes } = {}) => {
|
|
@@ -39,6 +39,20 @@ const createRuntime = async ({ mergePersistedSettings = (_current, changes) => c
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
describe('settings runtime', () => {
|
|
42
|
+
it('round-trips both archived-only retention states through instance settings', async () => {
|
|
43
|
+
const { runtime, settingsFilePath, cleanup } = await createRuntime();
|
|
44
|
+
try {
|
|
45
|
+
for (const sessionRetentionOnlyArchived of [true, false]) {
|
|
46
|
+
const settings = { sessionRetentionOnlyArchived, sessionRetentionAction: 'delete', autoDeleteAfterDays: 30 };
|
|
47
|
+
await runtime.persistSettings(settings);
|
|
48
|
+
expect(await runtime.readSettingsFromDisk()).toEqual(settings);
|
|
49
|
+
expect(JSON.parse(await fsPromises.readFile(settingsFilePath, 'utf8'))).toEqual(settings);
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
await cleanup();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
42
56
|
it('uses OpenChamber themes when a new install has no theme preferences', async () => {
|
|
43
57
|
const { runtime, cleanup } = await createRuntime();
|
|
44
58
|
try {
|
|
@@ -145,6 +159,52 @@ describe('settings runtime', () => {
|
|
|
145
159
|
}
|
|
146
160
|
});
|
|
147
161
|
|
|
162
|
+
it('migrates a legacy id into the bounded file of a project whose path is too long for a file name', async () => {
|
|
163
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
164
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
165
|
+
try {
|
|
166
|
+
const projectPath = path.join(tempRoot, 'a'.repeat(160));
|
|
167
|
+
const oldProjectId = 'legacy-project-id';
|
|
168
|
+
const newProjectId = createProjectIdFromPath(projectPath);
|
|
169
|
+
expect(newProjectId.length).toBeGreaterThan(200);
|
|
170
|
+
const projectsRoot = path.join(path.dirname(settingsFilePath), 'projects');
|
|
171
|
+
const boundedPath = path.join(projectsRoot, `${projectConfigFileStemOf(newProjectId)}.json`);
|
|
172
|
+
expect(path.basename(boundedPath).startsWith('path_sha256_')).toBe(true);
|
|
173
|
+
|
|
174
|
+
await fsPromises.mkdir(projectPath, { recursive: true });
|
|
175
|
+
await fsPromises.mkdir(projectsRoot, { recursive: true });
|
|
176
|
+
await fsPromises.writeFile(
|
|
177
|
+
settingsFilePath,
|
|
178
|
+
JSON.stringify({
|
|
179
|
+
projects: [{ id: oldProjectId, path: projectPath, addedAt: 1, lastOpenedAt: 1 }],
|
|
180
|
+
activeProjectId: oldProjectId,
|
|
181
|
+
}, null, 2),
|
|
182
|
+
'utf8',
|
|
183
|
+
);
|
|
184
|
+
await fsPromises.writeFile(
|
|
185
|
+
path.join(projectsRoot, `${oldProjectId}.json`),
|
|
186
|
+
JSON.stringify({ 'setup-worktree': ['bun install'] }, null, 2),
|
|
187
|
+
'utf8',
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const settings = await runtime.readSettingsFromDiskMigrated();
|
|
191
|
+
|
|
192
|
+
expect(settings.projects[0].id).toBe(newProjectId);
|
|
193
|
+
const migratedConfig = JSON.parse(await fsPromises.readFile(boundedPath, 'utf8'));
|
|
194
|
+
expect(migratedConfig['setup-worktree']).toEqual(['bun install']);
|
|
195
|
+
await expect(fsPromises.readFile(path.join(projectsRoot, `${oldProjectId}.json`), 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
|
|
196
|
+
|
|
197
|
+
// A second pass sees the bounded file beside the settings; it is the
|
|
198
|
+
// project's own file, not a stray from the random-id era.
|
|
199
|
+
await runtime.readSettingsFromDiskMigrated();
|
|
200
|
+
expect(JSON.parse(await fsPromises.readFile(boundedPath, 'utf8'))['setup-worktree']).toEqual(['bun install']);
|
|
201
|
+
expect(warn.mock.calls.some((call) => String(call[0]).includes('orphan'))).toBe(false);
|
|
202
|
+
} finally {
|
|
203
|
+
warn.mockRestore();
|
|
204
|
+
await cleanup();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
148
208
|
it.skipIf(process.platform !== 'win32')('falls back when Windows blocks atomic settings replacement', async () => {
|
|
149
209
|
const tempRoot = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'oc-settings-runtime-'));
|
|
150
210
|
const settingsFilePath = path.join(tempRoot, 'settings.json');
|
|
@@ -184,6 +244,102 @@ describe('settings runtime', () => {
|
|
|
184
244
|
}
|
|
185
245
|
});
|
|
186
246
|
|
|
247
|
+
it('moves project storage into the bounded folder when the canonical id is too long for a folder name', async () => {
|
|
248
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
249
|
+
try {
|
|
250
|
+
const projectPath = path.join(tempRoot, `${'segment-'.repeat(18)}`, 'demo-repo');
|
|
251
|
+
const oldProjectId = 'legacy-project-id';
|
|
252
|
+
const newProjectId = createProjectIdFromPath(projectPath);
|
|
253
|
+
const stem = projectConfigFileStemOf(newProjectId);
|
|
254
|
+
expect(newProjectId.length).toBeGreaterThan(240);
|
|
255
|
+
expect(stem).not.toBe(newProjectId);
|
|
256
|
+
const projectsRoot = path.join(path.dirname(settingsFilePath), 'projects');
|
|
257
|
+
const oldStorageDir = path.join(projectsRoot, oldProjectId);
|
|
258
|
+
const newStorageDir = path.join(projectsRoot, stem);
|
|
259
|
+
|
|
260
|
+
await fsPromises.mkdir(projectPath, { recursive: true });
|
|
261
|
+
await fsPromises.mkdir(path.join(oldStorageDir, 'plans'), { recursive: true });
|
|
262
|
+
await fsPromises.writeFile(path.join(oldStorageDir, 'context.json'), JSON.stringify({ version: 2, notes: [], todos: [{ id: 't1', text: 'keep', completed: false, createdAt: 1 }], plans: [] }), 'utf8');
|
|
263
|
+
await fsPromises.writeFile(path.join(oldStorageDir, 'plans', 'inside.md'), '# Inside\n', 'utf8');
|
|
264
|
+
await fsPromises.writeFile(path.join(oldStorageDir, 'memory.json'), JSON.stringify({ version: 1, entries: [] }), 'utf8');
|
|
265
|
+
await fsPromises.writeFile(
|
|
266
|
+
settingsFilePath,
|
|
267
|
+
JSON.stringify({
|
|
268
|
+
projects: [{ id: oldProjectId, path: projectPath, addedAt: 1, lastOpenedAt: 1 }],
|
|
269
|
+
activeProjectId: oldProjectId,
|
|
270
|
+
}, null, 2),
|
|
271
|
+
'utf8',
|
|
272
|
+
);
|
|
273
|
+
await fsPromises.writeFile(
|
|
274
|
+
path.join(projectsRoot, `${oldProjectId}.json`),
|
|
275
|
+
JSON.stringify({ projectPlanFiles: [{ id: 'inside', path: path.join(oldStorageDir, 'plans', 'inside.md') }] }, null, 2),
|
|
276
|
+
'utf8',
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const settings = await runtime.readSettingsFromDiskMigrated();
|
|
280
|
+
|
|
281
|
+
expect(settings.projects.map((project) => project.id)).toEqual([newProjectId]);
|
|
282
|
+
const migratedConfig = JSON.parse(await fsPromises.readFile(path.join(projectsRoot, `${stem}.json`), 'utf8'));
|
|
283
|
+
expect(migratedConfig.projectPlanFiles).toEqual([{ id: 'inside', path: path.join(newStorageDir, 'plans', 'inside.md') }]);
|
|
284
|
+
expect(JSON.parse(await fsPromises.readFile(path.join(newStorageDir, 'context.json'), 'utf8')).todos).toHaveLength(1);
|
|
285
|
+
await fsPromises.access(path.join(newStorageDir, 'plans', 'inside.md'));
|
|
286
|
+
await fsPromises.access(path.join(newStorageDir, 'memory.json'));
|
|
287
|
+
expect((await fsPromises.readdir(projectsRoot)).sort()).toEqual([stem, `${stem}.json`]);
|
|
288
|
+
} finally {
|
|
289
|
+
await cleanup();
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('moves a folder an older build created under a raw id that still fit a folder name into the bounded folder', async () => {
|
|
294
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
295
|
+
try {
|
|
296
|
+
// Long enough for the bounded name, short enough that an older build
|
|
297
|
+
// could still have created `<id>/` on this filesystem. The temp root
|
|
298
|
+
// differs per OS (a few characters on Linux runners, dozens on macOS),
|
|
299
|
+
// so pad to a fixed path length instead of a fixed segment.
|
|
300
|
+
const projectPathLength = 170;
|
|
301
|
+
const segment = 'x'.repeat(Math.max(1, projectPathLength - path.join(tempRoot, 'demo-repo').length - 1));
|
|
302
|
+
const projectPath = path.join(tempRoot, segment, 'demo-repo');
|
|
303
|
+
const projectId = createProjectIdFromPath(projectPath);
|
|
304
|
+
const stem = projectConfigFileStemOf(projectId);
|
|
305
|
+
expect(projectId.length).toBeGreaterThan(200);
|
|
306
|
+
expect(projectId.length).toBeLessThanOrEqual(255);
|
|
307
|
+
expect(stem).not.toBe(projectId);
|
|
308
|
+
const projectsRoot = path.join(path.dirname(settingsFilePath), 'projects');
|
|
309
|
+
const rawStorageDir = path.join(projectsRoot, projectId);
|
|
310
|
+
const boundedStorageDir = path.join(projectsRoot, stem);
|
|
311
|
+
|
|
312
|
+
await fsPromises.mkdir(projectPath, { recursive: true });
|
|
313
|
+
await fsPromises.mkdir(path.join(rawStorageDir, 'plans'), { recursive: true });
|
|
314
|
+
await fsPromises.writeFile(path.join(rawStorageDir, 'context.json'), JSON.stringify({ version: 2, notes: [{ id: 'n1', body: 'old note', createdAt: 1, updatedAt: 1 }], todos: [], plans: [] }), 'utf8');
|
|
315
|
+
await fsPromises.writeFile(path.join(rawStorageDir, 'plans', 'old.md'), '# Old\n', 'utf8');
|
|
316
|
+
await fsPromises.writeFile(path.join(rawStorageDir, 'memory.json'), JSON.stringify({ version: 1, entries: [{ id: 'm1', title: 'Old memory', body: 'x', type: 'fact', createdAt: 1, updatedAt: 1 }] }), 'utf8');
|
|
317
|
+
// The bounded folder already holds newer context: both sides survive.
|
|
318
|
+
await fsPromises.mkdir(boundedStorageDir, { recursive: true });
|
|
319
|
+
await fsPromises.writeFile(path.join(boundedStorageDir, 'context.json'), JSON.stringify({ version: 2, notes: [{ id: 'n2', body: 'new note', createdAt: 2, updatedAt: 2 }], todos: [], plans: [] }), 'utf8');
|
|
320
|
+
await fsPromises.writeFile(
|
|
321
|
+
settingsFilePath,
|
|
322
|
+
JSON.stringify({ projects: [{ id: projectId, path: projectPath, addedAt: 1, lastOpenedAt: 1 }], activeProjectId: projectId }, null, 2),
|
|
323
|
+
'utf8',
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
const settings = await runtime.readSettingsFromDiskMigrated();
|
|
327
|
+
|
|
328
|
+
expect(settings.projects.map((project) => project.id)).toEqual([projectId]);
|
|
329
|
+
const context = JSON.parse(await fsPromises.readFile(path.join(boundedStorageDir, 'context.json'), 'utf8'));
|
|
330
|
+
expect(context.notes.map((note) => note.id).sort()).toEqual(['n1', 'n2']);
|
|
331
|
+
await fsPromises.access(path.join(boundedStorageDir, 'plans', 'old.md'));
|
|
332
|
+
expect(JSON.parse(await fsPromises.readFile(path.join(boundedStorageDir, 'memory.json'), 'utf8')).entries).toHaveLength(1);
|
|
333
|
+
await expect(fsPromises.access(rawStorageDir)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
334
|
+
|
|
335
|
+
// A second startup finds nothing left to move.
|
|
336
|
+
await runtime.readSettingsFromDiskMigrated();
|
|
337
|
+
expect(JSON.parse(await fsPromises.readFile(path.join(boundedStorageDir, 'context.json'), 'utf8')).notes).toHaveLength(2);
|
|
338
|
+
} finally {
|
|
339
|
+
await cleanup();
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
187
343
|
it('cleans up orphaned settings.json.tmp files during startup migration', async () => {
|
|
188
344
|
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
189
345
|
try {
|
|
@@ -12,8 +12,18 @@ The managed Chats root (`~/.config/openchamber/chats`) is also one context owner
|
|
|
12
12
|
| `<projectsDir>/<projectId>.json` | `packages/web/server/lib/projects` (`project-setup.js` for the client-owned keys behind `/api/projects/:projectId/config`; `project-config.js` for `version` / `scheduledTasks`), one write lock for both | worktree setup, draft starters, project actions, scheduled tasks |
|
|
13
13
|
| `<projectsDir>/<projectId>/context.json` | **this module, exclusively** | notes, todos, plan manifest |
|
|
14
14
|
| `<projectsDir>/<projectId>/plans/*.md` | **this module, exclusively** | plan bodies |
|
|
15
|
+
| `<projectsDir>/<projectId>/memory.json` | `packages/web/server/lib/agent-memory` | what the agent chose to remember about the project |
|
|
15
16
|
| `<repo>/<plansDir>/*.md` | this module (read, edit, delete, move) when the team config names a `plansDir`; the folder is the team's, any tool may write there | shared plan bodies |
|
|
16
17
|
|
|
18
|
+
`<projectId>` in these paths is the bounded stem `projectConfigFileStemOf`
|
|
19
|
+
(`packages/web/server/lib/projects/project-id.js`) gives the id: the id itself
|
|
20
|
+
up to 200 characters, `path_sha256_<digest>` beyond that, so a deeply nested
|
|
21
|
+
checkout gets a folder the filesystem accepts. The folder, the config file,
|
|
22
|
+
and the memory file all share that one stem; nothing here composes a path from
|
|
23
|
+
the raw id. The legacy-migration read below looks at the bounded config file
|
|
24
|
+
for the same reason: a read of `<raw id>.json` would fail with ENAMETOOLONG
|
|
25
|
+
and turn an empty project into an error.
|
|
26
|
+
|
|
17
27
|
The split is the point. Both files were previously one, written by the client
|
|
18
28
|
with a whole-file read-modify-write. Adding a server writer to that file would
|
|
19
29
|
have made unrelated features (project actions, draft starters) clobber notes
|
|
@@ -147,9 +157,9 @@ and I/O failures are `500`.
|
|
|
147
157
|
## Legacy migration
|
|
148
158
|
|
|
149
159
|
`projectNotes`, `projectTodos`, and `projectPlanFiles` originally lived in
|
|
150
|
-
`<projectId>.json
|
|
151
|
-
are moved out and deleted from the
|
|
152
|
-
preserved untouched.
|
|
160
|
+
`<projectId>.json` (the bounded name, see Ownership). On the first read with
|
|
161
|
+
no `context.json`, those three keys are moved out and deleted from the
|
|
162
|
+
client-owned file; every other key is preserved untouched.
|
|
153
163
|
|
|
154
164
|
Plan links carried absolute paths. Migration converts each to a base name. A
|
|
155
165
|
file already in the plans directory is used in place; one referenced from
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* directory never invalidates a reference.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { projectConfigFileStemOf } from '../projects/project-id.js';
|
|
16
|
+
|
|
15
17
|
const PROJECT_CONTEXT_VERSION = 2;
|
|
16
18
|
const PROJECT_NOTE_BODY_MAX_LENGTH = 3000;
|
|
17
19
|
const PROJECT_NOTE_MAX_ITEMS = 200;
|
|
@@ -221,10 +223,14 @@ export const createProjectContextRuntime = (deps) => {
|
|
|
221
223
|
return value;
|
|
222
224
|
};
|
|
223
225
|
|
|
224
|
-
|
|
226
|
+
// The folder and the client-owned config file share one bounded stem
|
|
227
|
+
// (`projectConfigFileStemOf`): an id too long for a file name would
|
|
228
|
+
// otherwise fail every read with ENAMETOOLONG instead of reading as empty.
|
|
229
|
+
const storageStemFor = (projectId) => projectConfigFileStemOf(sanitizeProjectId(projectId));
|
|
230
|
+
const storageDirFor = (projectId) => path.join(projectsDirPath, storageStemFor(projectId));
|
|
225
231
|
const contextPathFor = (projectId) => path.join(storageDirFor(projectId), 'context.json');
|
|
226
232
|
const plansDirFor = (projectId) => path.join(storageDirFor(projectId), 'plans');
|
|
227
|
-
const legacyConfigPathFor = (projectId) => path.join(projectsDirPath, `${
|
|
233
|
+
const legacyConfigPathFor = (projectId) => path.join(projectsDirPath, `${storageStemFor(projectId)}.json`);
|
|
228
234
|
|
|
229
235
|
const readJson = async (filePath) => {
|
|
230
236
|
let raw;
|
|
@@ -3,6 +3,7 @@ import fsPromises from 'node:fs/promises';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
|
+
import { createProjectIdFromPath, projectConfigFileStemOf } from '../projects/project-id.js';
|
|
6
7
|
import { createProjectContextRuntime, parsePlanMarkdown } from './runtime.js';
|
|
7
8
|
|
|
8
9
|
const PROJECT_ID = 'path_dGVzdA';
|
|
@@ -200,6 +201,59 @@ describe('legacy migration', () => {
|
|
|
200
201
|
});
|
|
201
202
|
});
|
|
202
203
|
|
|
204
|
+
describe('long project ids', () => {
|
|
205
|
+
// A checkout nested deep enough that its `path_<base64url>` id is longer
|
|
206
|
+
// than a file or folder name may be; the storage lands under the bounded
|
|
207
|
+
// stem instead of failing with ENAMETOOLONG.
|
|
208
|
+
const longProjectId = createProjectIdFromPath(`/private/tmp/claude-501/${'segment-'.repeat(18)}/scratchpad/evidence/demo-repo`);
|
|
209
|
+
const stem = projectConfigFileStemOf(longProjectId);
|
|
210
|
+
|
|
211
|
+
test('the id maps to a bounded folder name', () => {
|
|
212
|
+
expect(longProjectId.length).toBeGreaterThan(240);
|
|
213
|
+
expect(stem.startsWith('path_sha256_')).toBe(true);
|
|
214
|
+
expect(stem.length).toBeLessThan(100);
|
|
215
|
+
expect(runtime.contextPathFor(longProjectId)).toBe(path.join(projectsDirPath, stem, 'context.json'));
|
|
216
|
+
expect(runtime.plansDirFor(longProjectId)).toBe(path.join(projectsDirPath, stem, 'plans'));
|
|
217
|
+
// A short id keeps naming its folder itself.
|
|
218
|
+
expect(runtime.contextPathFor(PROJECT_ID)).toBe(contextPath());
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('a missing context reads as empty instead of failing on the legacy config lookup', async () => {
|
|
222
|
+
expect(await runtime.readContext(longProjectId)).toEqual({ version: 2, notes: [], todos: [], plans: [], sharedPlansDir: null });
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('context and plans round-trip through the bounded folder', async () => {
|
|
226
|
+
await runtime.saveTodos(longProjectId, [{ id: 't1', text: 'do it', completed: false, createdAt: 1 }]);
|
|
227
|
+
const { note } = await runtime.createNote(longProjectId, { body: 'kept' });
|
|
228
|
+
const { plan } = await runtime.createPlan(longProjectId, { title: 'Deep plan', body: 'step one' });
|
|
229
|
+
|
|
230
|
+
const context = await runtime.readContext(longProjectId);
|
|
231
|
+
expect(context.todos).toEqual([{ id: 't1', text: 'do it', completed: false, createdAt: 1 }]);
|
|
232
|
+
expect(context.notes.map((entry) => entry.id)).toEqual([note.id]);
|
|
233
|
+
expect(context.plans.map((entry) => entry.id)).toEqual([plan.id]);
|
|
234
|
+
expect((await runtime.readPlan(longProjectId, plan.id)).body).toBe('step one');
|
|
235
|
+
|
|
236
|
+
expect((await readJson(path.join(projectsDirPath, stem, 'context.json'))).todos).toHaveLength(1);
|
|
237
|
+
await fsPromises.access(path.join(projectsDirPath, stem, 'plans', plan.file));
|
|
238
|
+
expect(await fsPromises.readdir(projectsDirPath)).toEqual([stem]);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('legacy keys are migrated out of the bounded config file', async () => {
|
|
242
|
+
const boundedConfigPath = path.join(projectsDirPath, `${stem}.json`);
|
|
243
|
+
await writeJson(boundedConfigPath, {
|
|
244
|
+
'setup-worktree': ['bun install'],
|
|
245
|
+
projectNotes: 'legacy notes',
|
|
246
|
+
projectTodos: [{ id: 't1', text: 'legacy todo', completed: true, createdAt: 5 }],
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const context = await runtime.readContext(longProjectId);
|
|
250
|
+
expect(context.notes.map((entry) => entry.body)).toEqual(['legacy notes']);
|
|
251
|
+
expect(context.todos).toEqual([{ id: 't1', text: 'legacy todo', completed: true, createdAt: 5 }]);
|
|
252
|
+
expect(await readJson(boundedConfigPath)).toEqual({ 'setup-worktree': ['bun install'] });
|
|
253
|
+
expect((await readJson(path.join(projectsDirPath, stem, 'context.json'))).notes[0].body).toBe('legacy notes');
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
203
257
|
describe('todos', () => {
|
|
204
258
|
test('round-trips through disk', async () => {
|
|
205
259
|
await runtime.saveTodos(PROJECT_ID, [{ id: 't1', text: 'do it', completed: false, createdAt: 1 }]);
|
|
@@ -63,7 +63,7 @@ UI (`packages/ui/src/lib/sharedTrustConfirmation.ts`).
|
|
|
63
63
|
|
|
64
64
|
## Modules
|
|
65
65
|
|
|
66
|
-
- `project-id.js` — `createProjectIdFromPath` / `projectPathFromId`: the path-derived id (`path_<base64url>`) that names the file, and the checkout path back from it. The shared UI derives the same id (`packages/ui/src/lib/projectId.ts`); both sides must agree.
|
|
66
|
+
- `project-id.js` — `createProjectIdFromPath` / `projectPathFromId`: the path-derived id (`path_<base64url>`) that names the file, and the checkout path back from it. The shared UI derives the same id (`packages/ui/src/lib/projectId.ts`); both sides must agree. `projectConfigFileStemOf`: the stem that names the file and the sibling folder for an id, see the file name invariant below.
|
|
67
67
|
- `project-config.js` — `createProjectConfigRuntime`: raw read, atomic write, the cross-process file lock (Electron and a CLI `serve` can share one projects dir), scheduled-task normalization, and the project-setup read/update.
|
|
68
68
|
- `project-setup.js` — sanitizers, the shared-file parser (`parseSharedProjectConfig`, `normalizePlansDir`), the merge (`mergeProjectSetup`), and the personal view for the setup keys. Mirrored in the VS Code extension host (`packages/vscode/src/project-setup.ts`), which owns the same file when the webview has no OpenChamber server; keep the two in sync.
|
|
69
69
|
- `routes.js` — the setup routes. `/api/projects` is on the JSON-body allowlist in `opencode/core-routes.js`.
|
|
@@ -72,5 +72,6 @@ UI (`packages/ui/src/lib/sharedTrustConfirmation.ts`).
|
|
|
72
72
|
|
|
73
73
|
- **Every write is a locked read-modify-write of the whole document.** Keys the writer does not own, and keys from newer builds, come back out unchanged. A setup update and a scheduled-task update never clobber each other.
|
|
74
74
|
- **A wrongly shaped key is a 400, not a silent drop.** `projectSetupPatchToStored` throws; the file is untouched. Values inside a well-shaped key are sanitized (trimmed, capped, deduplicated) rather than rejected.
|
|
75
|
+
- **The file name is bounded, and so is the folder beside it.** The file is `<projectId>.json` and the per-project folder is `<projectId>/` while the id is at most 200 characters. A `path_<base64url>` id grows with the checkout path, so a deeply nested project (a path of roughly 150 characters or more) would otherwise get a name beyond the 255-byte limit and every write, lock, and temp file would fail with ENAMETOOLONG. Such an id is stored as `path_sha256_<hex digest of the id>.json` instead, with the folder `path_sha256_<digest>/` beside it (`projectConfigFileStemOf`; every composer of either path goes through it: `project-config.js`, `project-context/runtime.js`, `agent-memory/runtime.js`, and the id migration and orphan recovery in `opencode/settings-runtime.js`). The digest keeps the `path_` prefix so orphan recovery skips it. A file an older build managed to write under the long name is still read when the bounded file is missing and is moved to the bounded name by the next write; a malformed one is a read failure, not an empty project. A folder an older build created under the raw id (possible only for ids of 201 to 255 characters; longer names never got one) is moved into the bounded folder once at startup, by the project id migration in `opencode/settings-runtime.js`, with `context.json` merged by entry identity when both exist. The VS Code extension host mirrors both the naming rule and the legacy read-then-move for the file (`bridge-project-setup-runtime.ts`), because a VS Code-only user has no server to do it; it never touches the folder.
|
|
75
76
|
- **The client never composes the path.** `packages/ui/src/lib/openchamberConfig.ts` speaks only HTTP; the same code serves web, desktop, VS Code, and the phone, including a phone on a remote instance.
|
|
76
77
|
- **`OPENCHAMBER_DATA_DIR` moves this directory too.** Every OpenChamber folder hangs off the one root; a custom root gets `projects/`, `themes/`, and `speech-models/` copied in from `~/.config/openchamber` once at startup (copied, not moved: a second instance beside the default one must not strip it) (`lib/data-dir-migration.js`). A scratch server started with its own data dir therefore never touches the real project configs.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DateTime, IANAZone } from 'luxon';
|
|
2
2
|
import parser from 'cron-parser';
|
|
3
3
|
|
|
4
|
-
import { projectPathFromId } from './project-id.js';
|
|
4
|
+
import { projectConfigFileStemOf, projectPathFromId } from './project-id.js';
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_PLANS_DIR,
|
|
7
7
|
EMPTY_SHARED_PROJECT_CONFIG,
|
|
@@ -399,6 +399,15 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
399
399
|
|
|
400
400
|
const resolveProjectConfigPath = (projectID) => {
|
|
401
401
|
const safeProjectID = sanitizeProjectID(projectID);
|
|
402
|
+
return path.join(projectsDirPath, `${projectConfigFileStemOf(safeProjectID)}.json`);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// Where a build before the bounded file name stored an id too long for one
|
|
406
|
+
// (on a filesystem that still accepted it), or null when the id's own name
|
|
407
|
+
// is the current one. Read as a fallback, moved on the next write.
|
|
408
|
+
const resolveLegacyProjectConfigPath = (projectID) => {
|
|
409
|
+
const safeProjectID = sanitizeProjectID(projectID);
|
|
410
|
+
if (projectConfigFileStemOf(safeProjectID) === safeProjectID) return null;
|
|
402
411
|
return path.join(projectsDirPath, `${safeProjectID}.json`);
|
|
403
412
|
};
|
|
404
413
|
|
|
@@ -500,18 +509,31 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
500
509
|
throw new Error(`timeout acquiring project config lock for ${projectID}`);
|
|
501
510
|
};
|
|
502
511
|
|
|
503
|
-
|
|
504
|
-
|
|
512
|
+
// The parsed document, or null when there is no file (one of
|
|
513
|
+
// `missingCodes`). Malformed JSON still throws; it is a broken file, not
|
|
514
|
+
// an empty one.
|
|
515
|
+
const readJsonDocumentIfPresent = async (filePath, missingCodes) => {
|
|
516
|
+
let raw;
|
|
505
517
|
try {
|
|
506
|
-
|
|
507
|
-
const parsed = JSON.parse(raw);
|
|
508
|
-
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
518
|
+
raw = await fsPromises.readFile(filePath, 'utf8');
|
|
509
519
|
} catch (error) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
520
|
+
const code = error && typeof error === 'object' ? error.code : null;
|
|
521
|
+
if (missingCodes.includes(code)) return null;
|
|
513
522
|
throw error;
|
|
514
523
|
}
|
|
524
|
+
const parsed = JSON.parse(raw);
|
|
525
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// The legacy name of a long id may exceed what the filesystem can hold;
|
|
529
|
+
// ENAMETOOLONG there means "no such file". On the bounded path it would
|
|
530
|
+
// mean the projects dir itself is unusable, so it stays an error.
|
|
531
|
+
const readRawProjectConfigFromDisk = async (projectID) => {
|
|
532
|
+
const current = await readJsonDocumentIfPresent(resolveProjectConfigPath(projectID), ['ENOENT']);
|
|
533
|
+
if (current) return current;
|
|
534
|
+
const legacyPath = resolveLegacyProjectConfigPath(projectID);
|
|
535
|
+
const legacy = legacyPath ? await readJsonDocumentIfPresent(legacyPath, ['ENOENT', 'ENAMETOOLONG']) : null;
|
|
536
|
+
return legacy ?? {};
|
|
515
537
|
};
|
|
516
538
|
|
|
517
539
|
// Normalized tasks for reading, plus the raw on-disk record of each one for
|
|
@@ -578,6 +600,13 @@ export const createProjectConfigRuntime = (deps) => {
|
|
|
578
600
|
await fsPromises.rm(temporaryPath, { force: true }).catch(() => {});
|
|
579
601
|
throw error;
|
|
580
602
|
}
|
|
603
|
+
// Every write goes through a read of the whole document, so the legacy
|
|
604
|
+
// file's content is now in the current one; drop it so a later read (or an
|
|
605
|
+
// older build) cannot see two copies drifting apart.
|
|
606
|
+
const legacyPath = resolveLegacyProjectConfigPath(projectID);
|
|
607
|
+
if (legacyPath) {
|
|
608
|
+
await fsPromises.rm(legacyPath, { force: true }).catch(() => {});
|
|
609
|
+
}
|
|
581
610
|
};
|
|
582
611
|
|
|
583
612
|
const writeProjectConfigToDisk = async (projectID, config) => {
|
|
@@ -3,6 +3,7 @@ import os from 'os';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { mkdtemp, rm, readFile, writeFile } from 'fs/promises';
|
|
5
5
|
import { createProjectConfigRuntime } from './project-config.js';
|
|
6
|
+
import { createProjectIdFromPath } from './project-id.js';
|
|
6
7
|
|
|
7
8
|
const createRuntime = async () => {
|
|
8
9
|
const tempRoot = await mkdtemp(path.join(os.tmpdir(), 'oc-scheduled-project-config-'));
|
|
@@ -175,6 +176,102 @@ describe('project-config runtime', () => {
|
|
|
175
176
|
});
|
|
176
177
|
});
|
|
177
178
|
|
|
179
|
+
describe('project-config file naming', () => {
|
|
180
|
+
const nightly = {
|
|
181
|
+
name: 'nightly',
|
|
182
|
+
enabled: true,
|
|
183
|
+
schedule: { kind: 'daily', time: '09:00', timezone: 'UTC' },
|
|
184
|
+
execution: { prompt: 'run', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
it('names the file by the id while the id fits a file name', async () => {
|
|
188
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
189
|
+
try {
|
|
190
|
+
const projectID = createProjectIdFromPath('/Users/someone/projects/demo');
|
|
191
|
+
expect(runtime.resolveProjectConfigPath(projectID)).toBe(path.join(tempRoot, `${projectID}.json`));
|
|
192
|
+
} finally {
|
|
193
|
+
await cleanup();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('stores a project whose path is too long for a file name under a bounded name', async () => {
|
|
198
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
199
|
+
try {
|
|
200
|
+
// ~190 characters, like a scratchpad checkout nested under a worktree;
|
|
201
|
+
// the base64url id is longer than the 255-byte file name limit allows.
|
|
202
|
+
const projectPath = `/private/tmp/claude-501/${'segment-'.repeat(18)}/scratchpad/evidence/demo-repo`;
|
|
203
|
+
expect(projectPath.length).toBeGreaterThan(180);
|
|
204
|
+
const projectID = createProjectIdFromPath(projectPath);
|
|
205
|
+
expect(projectID.length).toBeGreaterThan(240);
|
|
206
|
+
|
|
207
|
+
const filePath = runtime.resolveProjectConfigPath(projectID);
|
|
208
|
+
const fileName = path.basename(filePath);
|
|
209
|
+
expect(path.dirname(filePath)).toBe(tempRoot);
|
|
210
|
+
expect(fileName.startsWith('path_sha256_')).toBe(true);
|
|
211
|
+
expect(fileName.length).toBeLessThan(100);
|
|
212
|
+
// The same id always maps to the same file.
|
|
213
|
+
expect(runtime.resolveProjectConfigPath(projectID)).toBe(filePath);
|
|
214
|
+
|
|
215
|
+
// The whole write path (lock file, temp file, rename) works on a real filesystem.
|
|
216
|
+
const created = await runtime.upsertScheduledTask(projectID, nightly);
|
|
217
|
+
expect(created.created).toBe(true);
|
|
218
|
+
const setup = await runtime.updateProjectSetup(projectID, { setupWorktree: ['bun install'] });
|
|
219
|
+
expect(setup.setupWorktree).toEqual(['bun install']);
|
|
220
|
+
|
|
221
|
+
const raw = JSON.parse(await readFile(filePath, 'utf8'));
|
|
222
|
+
expect(raw.scheduledTasks).toHaveLength(1);
|
|
223
|
+
expect(raw['setup-worktree']).toEqual(['bun install']);
|
|
224
|
+
expect(await runtime.listScheduledTasks(projectID)).toHaveLength(1);
|
|
225
|
+
expect((await runtime.readProjectSetup(projectID)).setupWorktree).toEqual(['bun install']);
|
|
226
|
+
} finally {
|
|
227
|
+
await cleanup();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('reads a long id from its pre-bound file name and moves it on the next write', async () => {
|
|
232
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
233
|
+
try {
|
|
234
|
+
// Long enough for the bounded name, short enough that an older build
|
|
235
|
+
// could still have written `<id>.json` on this filesystem.
|
|
236
|
+
const projectID = `path_${'a'.repeat(200)}`;
|
|
237
|
+
const legacyPath = path.join(tempRoot, `${projectID}.json`);
|
|
238
|
+
const currentPath = runtime.resolveProjectConfigPath(projectID);
|
|
239
|
+
expect(currentPath).not.toBe(legacyPath);
|
|
240
|
+
await writeFile(legacyPath, JSON.stringify({
|
|
241
|
+
version: 1,
|
|
242
|
+
scheduledTasks: [{ id: 'task-legacy', ...nightly, state: { createdAt: 1, updatedAt: 2, lastStatus: 'idle' } }],
|
|
243
|
+
projectNotes: 'keep me',
|
|
244
|
+
}), 'utf8');
|
|
245
|
+
|
|
246
|
+
const tasks = await runtime.listScheduledTasks(projectID);
|
|
247
|
+
expect(tasks.map((task) => task.id)).toEqual(['task-legacy']);
|
|
248
|
+
|
|
249
|
+
await runtime.upsertScheduledTask(projectID, { ...nightly, name: 'weekly digest' });
|
|
250
|
+
|
|
251
|
+
const raw = JSON.parse(await readFile(currentPath, 'utf8'));
|
|
252
|
+
expect(raw.scheduledTasks.map((task) => task.id)).toEqual(['task-legacy', 'task-fixed-id']);
|
|
253
|
+
expect(raw.projectNotes).toBe('keep me');
|
|
254
|
+
await expect(readFile(legacyPath, 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
|
|
255
|
+
expect((await runtime.listScheduledTasks(projectID)).map((task) => task.name)).toEqual(['nightly', 'weekly digest']);
|
|
256
|
+
} finally {
|
|
257
|
+
await cleanup();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('treats a malformed pre-bound file as a failure, not as an empty project', async () => {
|
|
262
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
263
|
+
try {
|
|
264
|
+
const projectID = `path_${'b'.repeat(200)}`;
|
|
265
|
+
await writeFile(path.join(tempRoot, `${projectID}.json`), '{ not json', 'utf8');
|
|
266
|
+
await expect(runtime.listScheduledTasks(projectID)).rejects.toThrow();
|
|
267
|
+
await expect(runtime.upsertScheduledTask(projectID, nightly)).rejects.toThrow();
|
|
268
|
+
await expect(readFile(runtime.resolveProjectConfigPath(projectID), 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
|
|
269
|
+
} finally {
|
|
270
|
+
await cleanup();
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
178
275
|
describe('project-config loop reconciliation', () => {
|
|
179
276
|
const loop = (name, overrides = {}) => ({
|
|
180
277
|
scope: 'project',
|