@aiworker/web 1.22.2 → 1.23.0
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/cli.js +7 -0
- package/dist/assets/{CodeMirrorCommentWidgets-CSICpWQD.js → CodeMirrorCommentWidgets-B1Gizi3a.js} +1 -1
- package/dist/assets/DiffView-DXjVsEOw.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-C22HdWj4.js → DirtyBranchSwitchDialog-aig6zJjg.js} +1 -1
- package/dist/assets/FilesView-CJdG0-wk.js +17 -0
- package/dist/assets/{GitView-VQQkYuUw.js → GitView-BXsS3jG6.js} +4 -4
- package/dist/assets/{JsonTreeView-6lrhwD3q.js → JsonTreeView-D_hpXBnF.js} +1 -1
- package/dist/assets/{LinearIssuesView-Ba6Q9569.js → LinearIssuesView-BoUiLQG1.js} +1 -1
- package/dist/assets/MarkdownImageGallery-B_B_a9KS.js +1 -0
- package/dist/assets/MarkdownRendererImpl-xgyyLiBM.js +12 -0
- package/dist/assets/OnboardingScreen-DIp84OWt.js +1 -0
- package/dist/assets/{PatchDiff-BzcZPlOq.js → PatchDiff-8p6nLJaU.js} +1 -1
- package/dist/assets/PierreDiffViewer-DjC8nTk9.js +161 -0
- package/dist/assets/{PlanView-DyDt_nZ_.js → PlanView-CJTmOF6I.js} +2 -2
- package/dist/assets/SettingsView-DD-JqIJx.js +28 -0
- package/dist/assets/{SettingsWindow-DDQYaKWQ.js → SettingsWindow-Cpb4hM6q.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-iYF8Y2bz.js → ToolOutputDialog-DfaKZXNU.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-CdjbOVMM.js → ToolPartDiffPreview-DtZLzrSK.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-fFFm2QgH.js → VirtualizedFileDiff-C8i9HpTB.js} +1 -1
- package/dist/assets/WalkthroughView-DeKMvZlL.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CzgLum_K.js → computeVirtualFileMetrics-BBI7ZwrC.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BdA6bdky.js +1 -0
- package/dist/assets/de-DCrsQ5zS.js +10 -0
- package/dist/assets/es-Dwv4YfH6.js +16 -0
- package/dist/assets/fr-BCWg4Cnx.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/index-B68h5S5B.css +1 -0
- package/dist/assets/index-DVwMarHI.js +39 -0
- package/dist/assets/{index-Bl3LSbjn.js → index-jXSK5RrB.js} +1 -1
- package/dist/assets/{isDiffPlainText-Dx-dB_8l.js → isDiffPlainText-B_x_rVon.js} +1 -1
- package/dist/assets/{isFilePlainText-CWFPwmnU.js → isFilePlainText-DW_xMer1.js} +1 -1
- package/dist/assets/ja-Bruw3RYC.js +16 -0
- package/dist/assets/ko-idhXGF8j.js +16 -0
- package/dist/assets/main-BkyaQhJX.js +930 -0
- package/dist/assets/{main-DnBAoktx.js → main-CzdPuL0s.js} +2 -2
- package/dist/assets/markdownCore-Cn4Tyejo.js +5 -0
- package/dist/assets/{miniChat-BKyvLseN.js → miniChat-CCkqKOLp.js} +2 -2
- package/dist/assets/{mobile-DKjeFgMN.js → mobile-mvxTo055.js} +2 -2
- package/dist/assets/patchFileDiff-Csk4iNUi.js +13 -0
- package/dist/assets/pl-CGZWUqZJ.js +16 -0
- package/dist/assets/pt-BR-B8V7u7tA.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +2 -0
- package/dist/assets/renderMobileApp-B48CsP4r.js +25 -0
- package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +17 -0
- package/dist/assets/scheduledTasksApi-BW0Etzwz.js +1 -0
- package/dist/assets/{shikiHighlight-TEQCmzW8.js → shikiHighlight-CRl0SUC9.js} +1 -1
- package/dist/assets/surface-oMvhsog3.js +1 -0
- package/dist/assets/tr-BK_KiO2V.js +7 -0
- package/dist/assets/uk-CG74xV8N.js +16 -0
- package/dist/assets/{useAppFontEffects-D7sNpuL2.js → useAppFontEffects-CPKeOpUo.js} +160 -157
- package/dist/assets/useGitComparison-DH220WmO.js +1 -0
- package/dist/assets/useInlineCommentController-BiWz4AVb.js +2 -0
- package/dist/assets/useRootScrollLock-BS4-kr7P.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Dp3KMRQG.js → vendor-codemirror-language-data-Bg4AEeCr.js} +2 -2
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-_mNEMjFY.js → web-components-z7hfnS8n.js} +1 -1
- package/dist/assets/zh-CN-T4AXofZI.js +16 -0
- package/dist/assets/zh-TW-Dte40sxp.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -3
- package/server/index.d.ts +15 -0
- package/server/index.js +45 -9
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/event-stream/runtime.test.js +12 -12
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +31 -0
- package/server/lib/fs/routes.test.js +110 -1
- package/server/lib/git/DOCUMENTATION.md +29 -5
- package/server/lib/git/routes.js +24 -4
- package/server/lib/git/service.js +184 -198
- package/server/lib/git/service.test.js +422 -25
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/message-queue/DOCUMENTATION.md +4 -1
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/opencode/DOCUMENTATION.md +17 -1
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +128 -1
- package/server/lib/opencode/routes.js +5 -3
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +85 -41
- package/server/lib/opencode/settings-helpers.test.js +166 -1
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +139 -18
- package/server/lib/opencode/settings-runtime.test.js +163 -5
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +142 -9
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +31 -1
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +1 -1
- package/server/lib/quota/providers/opencode-go.test.js +26 -1
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/relay/DOCUMENTATION.md +55 -0
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +37 -8
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +66 -17
- package/server/lib/session-assist/runtime.js +6 -10
- package/server/lib/session-goal/runtime.js +4 -9
- package/server/lib/small-model/DOCUMENTATION.md +3 -2
- package/server/lib/small-model/call.js +9 -4
- package/server/lib/small-model/call.test.js +29 -0
- package/server/lib/small-model/index.js +5 -10
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/terminal/DOCUMENTATION.md +4 -4
- package/server/lib/terminal/runtime.js +11 -6
- package/server/lib/terminal/runtime.test.js +20 -13
- package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/sources.js +23 -2
- package/dist/assets/DiffView-hDBKesA_.js +0 -4
- package/dist/assets/FilesView-CdWzeOp9.js +0 -17
- package/dist/assets/MarkdownImageGallery-Czv_mhvS.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +0 -12
- package/dist/assets/OnboardingScreen-ChxQoAkx.js +0 -1
- package/dist/assets/PierreDiffViewer-BchBtZlp.js +0 -157
- package/dist/assets/SettingsView-BKf5xBsP.js +0 -28
- package/dist/assets/WalkthroughView-DOeCsMju.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-C0ZLAepL.js +0 -1
- package/dist/assets/de-B5JaA3SA.js +0 -10
- package/dist/assets/es-EPIH88ii.js +0 -16
- package/dist/assets/fr-CAMfxUdZ.js +0 -14
- package/dist/assets/index-DF5kMP-i.js +0 -39
- package/dist/assets/index-Dl3xbAB_.css +0 -1
- package/dist/assets/ja-CifOE1VN.js +0 -16
- package/dist/assets/ko-BBDyAyYQ.js +0 -16
- package/dist/assets/main-MhSaOZoB.js +0 -930
- package/dist/assets/markdownCore-BrBwOOMn.js +0 -3
- package/dist/assets/patchFileDiff-o8ms1me8.js +0 -10
- package/dist/assets/pl-DgEHYfFM.js +0 -16
- package/dist/assets/pt-BR-DuWHojUw.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-CDgBwwCS.js +0 -2
- package/dist/assets/renderMobileApp-DJIKIK1r.js +0 -25
- package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +0 -17
- package/dist/assets/scheduledTasksApi-D8yamh1b.js +0 -1
- package/dist/assets/tr-D5m2yIWL.js +0 -7
- package/dist/assets/uk-D_q60oog.js +0 -16
- package/dist/assets/useInlineCommentController-Brz_cLcQ.js +0 -2
- package/dist/assets/useRootScrollLock-lXEnWlaU.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-zod-CK21ihK-.js +0 -39
- package/dist/assets/zh-CN-D8QvsVeg.js +0 -16
- package/dist/assets/zh-TW-B9t7rQQO.js +0 -16
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
2
|
+
import {
|
|
3
|
+
buildPreferencesFields,
|
|
4
|
+
flattenPreferences,
|
|
5
|
+
instancePartOf,
|
|
6
|
+
legacySettingsDocumentOf,
|
|
7
|
+
profilePartOf,
|
|
8
|
+
isDeviceSettingsKey,
|
|
9
|
+
isProfileSettingsKey,
|
|
10
|
+
normalizeSettingsSurface,
|
|
11
|
+
parsePreferencesDocument,
|
|
12
|
+
preferencesFilePathFor,
|
|
13
|
+
seedPreferencesFrom,
|
|
14
|
+
serializePreferencesDocument,
|
|
15
|
+
} from './settings-files.js';
|
|
2
16
|
|
|
3
17
|
const DEFAULT_NOTIFICATION_TEMPLATES = {
|
|
4
18
|
completion: { title: '{agent_name} is ready', message: '{model_name} completed the task' },
|
|
@@ -48,6 +62,13 @@ export const createSettingsRuntime = (deps) => {
|
|
|
48
62
|
|
|
49
63
|
let persistSettingsLock = Promise.resolve();
|
|
50
64
|
|
|
65
|
+
const PREFERENCES_FILE_PATH = preferencesFilePathFor(SETTINGS_FILE_PATH, path);
|
|
66
|
+
// True while preferences.json exists but cannot be read. Profile writes are
|
|
67
|
+
// refused meanwhile so a corrupt file is never overwritten with a seed or a
|
|
68
|
+
// partial document; clients keep the values they hold.
|
|
69
|
+
let preferencesUnavailable = false;
|
|
70
|
+
let preferencesFailureLogged = false;
|
|
71
|
+
|
|
51
72
|
// Orphan recovery is a one-shot best-effort scan: when orphans can't be
|
|
52
73
|
// matched on first pass they stay on disk and every subsequent settings
|
|
53
74
|
// read would re-scan them. In-process (Electron) this runs in the main
|
|
@@ -472,7 +493,7 @@ export const createSettingsRuntime = (deps) => {
|
|
|
472
493
|
}
|
|
473
494
|
};
|
|
474
495
|
|
|
475
|
-
const
|
|
496
|
+
const readInstanceSettingsFromDisk = async () => {
|
|
476
497
|
try {
|
|
477
498
|
const raw = await fsPromises.readFile(SETTINGS_FILE_PATH, 'utf8');
|
|
478
499
|
const parsed = JSON.parse(raw);
|
|
@@ -489,6 +510,67 @@ export const createSettingsRuntime = (deps) => {
|
|
|
489
510
|
}
|
|
490
511
|
};
|
|
491
512
|
|
|
513
|
+
/**
|
|
514
|
+
* `{ status: 'missing' }` when the file does not exist, `{ status: 'ok',
|
|
515
|
+
* fields }` when it parsed, `{ status: 'failed' }` for anything else. Only
|
|
516
|
+
* "missing" may be seeded; "failed" must leave the file alone.
|
|
517
|
+
*/
|
|
518
|
+
const readPreferenceFields = async () => {
|
|
519
|
+
let raw;
|
|
520
|
+
try {
|
|
521
|
+
raw = await fsPromises.readFile(PREFERENCES_FILE_PATH, 'utf8');
|
|
522
|
+
} catch (error) {
|
|
523
|
+
if (error && typeof error === 'object' && error.code === 'ENOENT') {
|
|
524
|
+
return { status: 'missing' };
|
|
525
|
+
}
|
|
526
|
+
if (!preferencesFailureLogged) {
|
|
527
|
+
preferencesFailureLogged = true;
|
|
528
|
+
console.warn('Failed to read preferences file:', error);
|
|
529
|
+
}
|
|
530
|
+
return { status: 'failed' };
|
|
531
|
+
}
|
|
532
|
+
const parsed = parsePreferencesDocument(raw);
|
|
533
|
+
if (!parsed.ok) {
|
|
534
|
+
if (!preferencesFailureLogged) {
|
|
535
|
+
preferencesFailureLogged = true;
|
|
536
|
+
console.warn(`Preferences file is unreadable (${parsed.reason}); profile writes are paused until it is fixed or removed.`);
|
|
537
|
+
}
|
|
538
|
+
return { status: 'failed' };
|
|
539
|
+
}
|
|
540
|
+
preferencesFailureLogged = false;
|
|
541
|
+
return { status: 'ok', fields: parsed.fields };
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
const writePreferencesToDisk = async (fields) => {
|
|
545
|
+
await writeJsonFileAtomic(PREFERENCES_FILE_PATH, serializePreferencesDocument(fields));
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// The merged document every consumer sees: instance facts from settings.json
|
|
549
|
+
// plus the profile from preferences.json. On the first read of an install
|
|
550
|
+
// that predates the split, the profile keys still sitting in settings.json
|
|
551
|
+
// seed preferences.json. settings.json keeps a copy of the profile's base
|
|
552
|
+
// values on every write too, so an older build (which reads only that file)
|
|
553
|
+
// still finds everything where it used to be.
|
|
554
|
+
const readSettingsFromDisk = async ({ surface = null } = {}) => {
|
|
555
|
+
const instance = await readInstanceSettingsFromDisk();
|
|
556
|
+
const preferences = await readPreferenceFields();
|
|
557
|
+
if (preferences.status === 'failed') {
|
|
558
|
+
preferencesUnavailable = true;
|
|
559
|
+
return instance;
|
|
560
|
+
}
|
|
561
|
+
preferencesUnavailable = false;
|
|
562
|
+
if (preferences.status === 'missing') {
|
|
563
|
+
const seeded = seedPreferencesFrom(instance, Date.now());
|
|
564
|
+
try {
|
|
565
|
+
await writePreferencesToDisk(seeded);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
console.warn('Failed to seed preferences file:', error);
|
|
568
|
+
}
|
|
569
|
+
return instance;
|
|
570
|
+
}
|
|
571
|
+
return { ...instance, ...flattenPreferences(preferences.fields, normalizeSettingsSurface(surface)) };
|
|
572
|
+
};
|
|
573
|
+
|
|
492
574
|
// Strict variant for callers that REGENERATE persisted identity when a key is
|
|
493
575
|
// absent (relay signing/encryption keys). The lenient reader above maps every
|
|
494
576
|
// failure — corrupt JSON, EACCES, transient I/O — to `{}`, which such callers
|
|
@@ -558,7 +640,7 @@ export const createSettingsRuntime = (deps) => {
|
|
|
558
640
|
try {
|
|
559
641
|
const entries = await fsPromises.readdir(directory, { withFileTypes: true });
|
|
560
642
|
const cleanupTasks = entries
|
|
561
|
-
.filter((entry) => entry.isFile() && entry.name.startsWith('settings.json.tmp-'))
|
|
643
|
+
.filter((entry) => entry.isFile() && (entry.name.startsWith('settings.json.tmp-') || entry.name.startsWith('preferences.json.tmp-')))
|
|
562
644
|
.map((entry) => fsPromises.rm(path.join(directory, entry.name), { force: true }).catch(() => {}));
|
|
563
645
|
await Promise.all(cleanupTasks);
|
|
564
646
|
} catch {
|
|
@@ -566,27 +648,54 @@ export const createSettingsRuntime = (deps) => {
|
|
|
566
648
|
}
|
|
567
649
|
};
|
|
568
650
|
|
|
569
|
-
const
|
|
570
|
-
const
|
|
571
|
-
await fsPromises.mkdir(
|
|
572
|
-
if (process.platform !== 'win32') await fsPromises.chmod(
|
|
573
|
-
// Atomic write: Electron main and ssh-manager read
|
|
651
|
+
const writeJsonFileAtomic = async (filePath, text) => {
|
|
652
|
+
const directory = path.dirname(filePath);
|
|
653
|
+
await fsPromises.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
654
|
+
if (process.platform !== 'win32') await fsPromises.chmod(directory, 0o700);
|
|
655
|
+
// Atomic write: Electron main and ssh-manager read these files via plain
|
|
574
656
|
// readFile + JSON.parse and silently coerce parse errors to {}. A
|
|
575
657
|
// partial read during a non-atomic writeFile would make their next
|
|
576
|
-
// read-modify-write wipe the
|
|
577
|
-
const tmp = `${
|
|
658
|
+
// read-modify-write wipe the file.
|
|
659
|
+
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
578
660
|
try {
|
|
579
|
-
await fsPromises.writeFile(tmp,
|
|
661
|
+
await fsPromises.writeFile(tmp, text, { encoding: 'utf8', mode: 0o600 });
|
|
580
662
|
if (process.platform !== 'win32') await fsPromises.chmod(tmp, 0o600);
|
|
581
|
-
await replaceFile(tmp,
|
|
582
|
-
if (process.platform !== 'win32') await fsPromises.chmod(
|
|
663
|
+
await replaceFile(tmp, filePath);
|
|
664
|
+
if (process.platform !== 'win32') await fsPromises.chmod(filePath, 0o600);
|
|
583
665
|
} catch (error) {
|
|
584
666
|
await fsPromises.rm(tmp, { force: true }).catch(() => {});
|
|
585
|
-
console.warn(
|
|
667
|
+
console.warn(`Failed to write ${path.basename(filePath)}:`, error);
|
|
586
668
|
throw error;
|
|
587
669
|
}
|
|
588
670
|
};
|
|
589
671
|
|
|
672
|
+
/**
|
|
673
|
+
* Persist a merged document: profile keys go to preferences.json (stamped
|
|
674
|
+
* when their value changed), everything else to settings.json. While
|
|
675
|
+
* preferences.json is unreadable its part is skipped rather than replaced.
|
|
676
|
+
*/
|
|
677
|
+
const writeSettingsToDisk = async (settings, { surface = null, changedKeys = null } = {}) => {
|
|
678
|
+
const current = preferencesUnavailable ? { status: 'failed' } : await readPreferenceFields();
|
|
679
|
+
if (current.status === 'failed') {
|
|
680
|
+
// The profile part is not saved; settings.json keeps whatever legacy
|
|
681
|
+
// profile copy it already holds rather than losing it too.
|
|
682
|
+
preferencesUnavailable = true;
|
|
683
|
+
const onDisk = await readInstanceSettingsFromDisk();
|
|
684
|
+
await writeJsonFileAtomic(SETTINGS_FILE_PATH, JSON.stringify({
|
|
685
|
+
...instancePartOf(settings),
|
|
686
|
+
...profilePartOf(onDisk),
|
|
687
|
+
}, null, 2));
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const previousFields = current.status === 'ok' ? current.fields : {};
|
|
691
|
+
const nextFields = buildPreferencesFields(previousFields, settings, Date.now(), {
|
|
692
|
+
surface: normalizeSettingsSurface(surface),
|
|
693
|
+
changedKeys,
|
|
694
|
+
});
|
|
695
|
+
await writeJsonFileAtomic(SETTINGS_FILE_PATH, JSON.stringify(legacySettingsDocumentOf(settings, nextFields), null, 2));
|
|
696
|
+
await writePreferencesToDisk(nextFields);
|
|
697
|
+
};
|
|
698
|
+
|
|
590
699
|
const validateProjectEntries = async (projects) => {
|
|
591
700
|
if (!Array.isArray(projects)) {
|
|
592
701
|
return [];
|
|
@@ -872,7 +981,7 @@ export const createSettingsRuntime = (deps) => {
|
|
|
872
981
|
|
|
873
982
|
let hasCleanedOrphanedTempFiles = false;
|
|
874
983
|
|
|
875
|
-
const readSettingsFromDiskMigrated = async () => {
|
|
984
|
+
const readSettingsFromDiskMigrated = async ({ surface = null } = {}) => {
|
|
876
985
|
if (!hasCleanedOrphanedTempFiles) {
|
|
877
986
|
hasCleanedOrphanedTempFiles = true;
|
|
878
987
|
await cleanupOrphanedSettingsTempFiles(path.dirname(SETTINGS_FILE_PATH));
|
|
@@ -889,16 +998,28 @@ export const createSettingsRuntime = (deps) => {
|
|
|
889
998
|
if (migration1.changed || migration2.changed || migration3.changed || migration4.changed || migration5.changed || migration6.changed || migration7.changed || migration8.changed) {
|
|
890
999
|
await writeSettingsToDisk(migration8.settings);
|
|
891
1000
|
}
|
|
892
|
-
|
|
1001
|
+
// Migrations run on the base view; a surface asks for its own resolution
|
|
1002
|
+
// of the per-surface keys on top of the migrated files.
|
|
1003
|
+
return normalizeSettingsSurface(surface) ? readSettingsFromDisk({ surface }) : migration8.settings;
|
|
893
1004
|
};
|
|
894
1005
|
|
|
895
|
-
const persistSettings = async (changes) => {
|
|
1006
|
+
const persistSettings = async (changes, { surface = null } = {}) => {
|
|
896
1007
|
persistSettingsLock = persistSettingsLock.then(async () => {
|
|
897
1008
|
// Log field names only — changes can carry credentials (UI password,
|
|
898
1009
|
// client tokens, tunnel tokens) that must never reach the log file.
|
|
899
1010
|
console.log('[persistSettings] Updating fields:', Object.keys(changes || {}).join(', ') || '(none)');
|
|
900
|
-
const current = await readSettingsFromDisk();
|
|
1011
|
+
const current = await readSettingsFromDisk({ surface });
|
|
901
1012
|
const sanitized = sanitizeSettingsUpdate(changes);
|
|
1013
|
+
for (const key of Object.keys(sanitized)) {
|
|
1014
|
+
// Device state belongs to the install in front of the user, never to
|
|
1015
|
+
// the instance; a client that still sends it is simply ignored.
|
|
1016
|
+
if (isDeviceSettingsKey(key)) {
|
|
1017
|
+
delete sanitized[key];
|
|
1018
|
+
} else if (preferencesUnavailable && isProfileSettingsKey(key)) {
|
|
1019
|
+
console.warn(`[persistSettings] Dropping ${key}: preferences file is unreadable`);
|
|
1020
|
+
delete sanitized[key];
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
902
1023
|
let next = mergePersistedSettings(current, sanitized);
|
|
903
1024
|
|
|
904
1025
|
const normalizedState = normalizeSettingsPaths(next);
|
|
@@ -962,7 +1083,7 @@ export const createSettingsRuntime = (deps) => {
|
|
|
962
1083
|
}
|
|
963
1084
|
}
|
|
964
1085
|
|
|
965
|
-
await writeSettingsToDisk(next);
|
|
1086
|
+
await writeSettingsToDisk(next, { surface, changedKeys: Object.keys(sanitized) });
|
|
966
1087
|
return formatSettingsResponse(next);
|
|
967
1088
|
});
|
|
968
1089
|
|
|
@@ -6,7 +6,7 @@ import path from 'path';
|
|
|
6
6
|
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
7
7
|
import { createSettingsRuntime } from './settings-runtime.js';
|
|
8
8
|
|
|
9
|
-
const createRuntime = async () => {
|
|
9
|
+
const createRuntime = async ({ mergePersistedSettings = (_current, changes) => changes } = {}) => {
|
|
10
10
|
const tempRoot = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'oc-settings-runtime-'));
|
|
11
11
|
const settingsFilePath = path.join(tempRoot, 'settings.json');
|
|
12
12
|
const runtime = createSettingsRuntime({
|
|
@@ -16,7 +16,7 @@ const createRuntime = async () => {
|
|
|
16
16
|
SETTINGS_FILE_PATH: settingsFilePath,
|
|
17
17
|
sanitizeProjects: (projects) => Array.isArray(projects) ? projects : [],
|
|
18
18
|
sanitizeSettingsUpdate: (settings) => settings,
|
|
19
|
-
mergePersistedSettings
|
|
19
|
+
mergePersistedSettings,
|
|
20
20
|
normalizeSettingsPaths: (settings) => ({ settings, changed: false }),
|
|
21
21
|
normalizeStringArray: (values) => Array.isArray(values) ? values.filter((value) => typeof value === 'string') : [],
|
|
22
22
|
formatSettingsResponse: (settings) => settings,
|
|
@@ -68,8 +68,8 @@ describe('settings runtime', () => {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
it('round-trips shared sidebar preferences through
|
|
72
|
-
const { runtime, settingsFilePath, cleanup } = await createRuntime();
|
|
71
|
+
it('round-trips shared sidebar preferences through preferences.json', async () => {
|
|
72
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
73
73
|
const preferences = {
|
|
74
74
|
sidebarProjectDisplayMode: 'single',
|
|
75
75
|
sidebarSessionGroupingMode: 'flat',
|
|
@@ -80,7 +80,10 @@ describe('settings runtime', () => {
|
|
|
80
80
|
await runtime.persistSettings(preferences);
|
|
81
81
|
|
|
82
82
|
await expect(runtime.readSettingsFromDisk()).resolves.toEqual(preferences);
|
|
83
|
-
|
|
83
|
+
// Profile keys live in preferences.json; settings.json keeps a legacy copy for older builds.
|
|
84
|
+
expect(JSON.parse(await fsPromises.readFile(settingsFilePath, 'utf8'))).toEqual(preferences);
|
|
85
|
+
const stored = JSON.parse(await fsPromises.readFile(path.join(tempRoot, 'preferences.json'), 'utf8'));
|
|
86
|
+
expect(Object.fromEntries(Object.entries(stored.fields).map(([key, entry]) => [key, entry.value]))).toEqual(preferences);
|
|
84
87
|
} finally {
|
|
85
88
|
await cleanup();
|
|
86
89
|
}
|
|
@@ -248,3 +251,158 @@ describe('settings runtime', () => {
|
|
|
248
251
|
}
|
|
249
252
|
});
|
|
250
253
|
});
|
|
254
|
+
|
|
255
|
+
describe('settings runtime: preferences.json split', () => {
|
|
256
|
+
const readJson = async (filePath) => JSON.parse(await fsPromises.readFile(filePath, 'utf8'));
|
|
257
|
+
|
|
258
|
+
it('seeds preferences.json from the profile keys of an existing settings.json and leaves that file intact', async () => {
|
|
259
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
260
|
+
try {
|
|
261
|
+
const legacy = { projects: [], fontSize: 110, themeId: 'openchamber-dark', desktopLanAccessEnabled: true };
|
|
262
|
+
await fsPromises.writeFile(settingsFilePath, JSON.stringify(legacy));
|
|
263
|
+
|
|
264
|
+
const merged = await runtime.readSettingsFromDisk();
|
|
265
|
+
expect(merged).toMatchObject(legacy);
|
|
266
|
+
|
|
267
|
+
const preferences = await readJson(path.join(tempRoot, 'preferences.json'));
|
|
268
|
+
expect(preferences.version).toBe(1);
|
|
269
|
+
expect(Object.keys(preferences.fields).sort()).toEqual(['fontSize', 'themeId']);
|
|
270
|
+
expect(preferences.fields.fontSize.value).toBe(110);
|
|
271
|
+
expect(typeof preferences.fields.fontSize.updatedAt).toBe('number');
|
|
272
|
+
expect(await readJson(settingsFilePath)).toEqual(legacy);
|
|
273
|
+
} finally {
|
|
274
|
+
await cleanup();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('routes profile keys to preferences.json, keeps a legacy copy of them in settings.json, and drops device keys', async () => {
|
|
279
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
280
|
+
try {
|
|
281
|
+
await runtime.persistSettings({ fontSize: 120, desktopLanAccessEnabled: true, mobileKeyboardMode: 'native' });
|
|
282
|
+
|
|
283
|
+
const settings = await readJson(settingsFilePath);
|
|
284
|
+
expect(settings.desktopLanAccessEnabled).toBe(true);
|
|
285
|
+
// Older builds read only settings.json: the profile's base values stay there as a copy.
|
|
286
|
+
expect(settings.fontSize).toBe(120);
|
|
287
|
+
expect(settings).not.toHaveProperty('mobileKeyboardMode');
|
|
288
|
+
|
|
289
|
+
const preferences = await readJson(path.join(tempRoot, 'preferences.json'));
|
|
290
|
+
expect(preferences.fields.fontSize.value).toBe(120);
|
|
291
|
+
expect(preferences.fields).not.toHaveProperty('mobileKeyboardMode');
|
|
292
|
+
expect(preferences.fields).not.toHaveProperty('desktopLanAccessEnabled');
|
|
293
|
+
|
|
294
|
+
expect(await runtime.readSettingsFromDisk()).toMatchObject({ fontSize: 120, desktopLanAccessEnabled: true });
|
|
295
|
+
} finally {
|
|
296
|
+
await cleanup();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('keeps the timestamp of an unchanged profile key and restamps a changed one', async () => {
|
|
301
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
302
|
+
try {
|
|
303
|
+
const preferencesPath = path.join(tempRoot, 'preferences.json');
|
|
304
|
+
await runtime.persistSettings({ fontSize: 100, padding: 100 });
|
|
305
|
+
const first = await readJson(preferencesPath);
|
|
306
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
307
|
+
await runtime.persistSettings({ fontSize: 100, padding: 120 });
|
|
308
|
+
const second = await readJson(preferencesPath);
|
|
309
|
+
|
|
310
|
+
expect(second.fields.fontSize.updatedAt).toBe(first.fields.fontSize.updatedAt);
|
|
311
|
+
expect(second.fields.padding.updatedAt).toBeGreaterThan(first.fields.padding.updatedAt);
|
|
312
|
+
expect(second.fields.padding.value).toBe(120);
|
|
313
|
+
} finally {
|
|
314
|
+
await cleanup();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('treats an unreadable preferences.json as failure: no seed, no overwrite, profile writes refused, instance still served', async () => {
|
|
319
|
+
const { runtime, settingsFilePath, tempRoot, cleanup } = await createRuntime();
|
|
320
|
+
try {
|
|
321
|
+
const preferencesPath = path.join(tempRoot, 'preferences.json');
|
|
322
|
+
await fsPromises.writeFile(settingsFilePath, JSON.stringify({ desktopLanAccessEnabled: true }));
|
|
323
|
+
await fsPromises.writeFile(preferencesPath, '{ not json');
|
|
324
|
+
|
|
325
|
+
expect(await runtime.readSettingsFromDisk()).toEqual({ desktopLanAccessEnabled: true });
|
|
326
|
+
|
|
327
|
+
await runtime.persistSettings({ fontSize: 130, desktopKeepAwakeEnabled: true });
|
|
328
|
+
|
|
329
|
+
expect(await fsPromises.readFile(preferencesPath, 'utf8')).toBe('{ not json');
|
|
330
|
+
const settings = await readJson(settingsFilePath);
|
|
331
|
+
expect(settings.desktopKeepAwakeEnabled).toBe(true);
|
|
332
|
+
// The refused profile write must not land in the legacy copy either.
|
|
333
|
+
expect(settings).not.toHaveProperty('fontSize');
|
|
334
|
+
} finally {
|
|
335
|
+
await cleanup();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe('settings runtime: per-surface profile keys', () => {
|
|
341
|
+
const readJson = async (filePath) => JSON.parse(await fsPromises.readFile(filePath, 'utf8'));
|
|
342
|
+
// These sequences persist several times; the default stub replaces the
|
|
343
|
+
// document with the changes, the real merge keeps the current document.
|
|
344
|
+
const createMergingRuntime = () => createRuntime({ mergePersistedSettings: (current, changes) => ({ ...current, ...changes }) });
|
|
345
|
+
|
|
346
|
+
it('stores a per-surface key under the writing surface and leaves the base alone', async () => {
|
|
347
|
+
const { runtime, tempRoot, cleanup } = await createMergingRuntime();
|
|
348
|
+
try {
|
|
349
|
+
await runtime.persistSettings({ fontSize: 100 }); // base (no surface): migrations and legacy callers
|
|
350
|
+
await runtime.persistSettings({ fontSize: 130, showReasoningTraces: false }, { surface: 'mobile' });
|
|
351
|
+
|
|
352
|
+
const stored = await readJson(path.join(tempRoot, 'preferences.json'));
|
|
353
|
+
expect(stored.fields.fontSize.value).toBe(100);
|
|
354
|
+
expect(stored.fields.fontSize.surfaces.mobile.value).toBe(130);
|
|
355
|
+
// Not per-surface: written to the base regardless of the surface.
|
|
356
|
+
expect(stored.fields.showReasoningTraces.value).toBe(false);
|
|
357
|
+
expect(stored.fields.showReasoningTraces.surfaces).toBeUndefined();
|
|
358
|
+
|
|
359
|
+
expect((await runtime.readSettingsFromDisk({ surface: 'mobile' })).fontSize).toBe(130);
|
|
360
|
+
expect((await runtime.readSettingsFromDisk({ surface: 'desktop' })).fontSize).toBe(100);
|
|
361
|
+
expect((await runtime.readSettingsFromDisk()).fontSize).toBe(100);
|
|
362
|
+
expect((await runtime.readSettingsFromDiskMigrated({ surface: 'mobile' })).fontSize).toBe(130);
|
|
363
|
+
} finally {
|
|
364
|
+
await cleanup();
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('a per-surface key set only from one surface has no base and stays absent elsewhere', async () => {
|
|
369
|
+
const { runtime, tempRoot, cleanup } = await createMergingRuntime();
|
|
370
|
+
try {
|
|
371
|
+
await runtime.persistSettings({ stickyUserHeader: false }, { surface: 'mobile' });
|
|
372
|
+
const stored = await readJson(path.join(tempRoot, 'preferences.json'));
|
|
373
|
+
expect(stored.fields.stickyUserHeader).not.toHaveProperty('value');
|
|
374
|
+
expect(stored.fields.stickyUserHeader.surfaces.mobile.value).toBe(false);
|
|
375
|
+
expect((await runtime.readSettingsFromDisk({ surface: 'desktop' })).stickyUserHeader).toBeUndefined();
|
|
376
|
+
expect((await runtime.readSettingsFromDisk({ surface: 'mobile' })).stickyUserHeader).toBe(false);
|
|
377
|
+
} finally {
|
|
378
|
+
await cleanup();
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('a surface write of an unrelated key does not copy the resolved per-surface view into the file', async () => {
|
|
383
|
+
const { runtime, tempRoot, cleanup } = await createMergingRuntime();
|
|
384
|
+
try {
|
|
385
|
+
await runtime.persistSettings({ fontSize: 100 });
|
|
386
|
+
await runtime.persistSettings({ fontSize: 130 }, { surface: 'mobile' });
|
|
387
|
+
await runtime.persistSettings({ showReasoningTraces: true }, { surface: 'mobile' });
|
|
388
|
+
const stored = await readJson(path.join(tempRoot, 'preferences.json'));
|
|
389
|
+
expect(stored.fields.fontSize.value).toBe(100);
|
|
390
|
+
expect(stored.fields.fontSize.surfaces.mobile.value).toBe(130);
|
|
391
|
+
expect(stored.fields.fontSize.surfaces.desktop).toBeUndefined();
|
|
392
|
+
} finally {
|
|
393
|
+
await cleanup();
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('ignores an unknown surface header value and writes the base', async () => {
|
|
398
|
+
const { runtime, tempRoot, cleanup } = await createMergingRuntime();
|
|
399
|
+
try {
|
|
400
|
+
await runtime.persistSettings({ fontSize: 90 }, { surface: 'toaster' });
|
|
401
|
+
const stored = await readJson(path.join(tempRoot, 'preferences.json'));
|
|
402
|
+
expect(stored.fields.fontSize.value).toBe(90);
|
|
403
|
+
expect(stored.fields.fontSize.surfaces).toBeUndefined();
|
|
404
|
+
} finally {
|
|
405
|
+
await cleanup();
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
@@ -9,9 +9,10 @@ The managed Chats root (`~/.config/openchamber/chats`) is also one context owner
|
|
|
9
9
|
|
|
10
10
|
| Path | Owner | Contents |
|
|
11
11
|
|---|---|---|
|
|
12
|
-
| `<projectsDir>/<projectId>.json` |
|
|
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
|
+
| `<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 |
|
|
15
16
|
|
|
16
17
|
The split is the point. Both files were previously one, written by the client
|
|
17
18
|
with a whole-file read-modify-write. Adding a server writer to that file would
|
|
@@ -58,6 +59,27 @@ denormalized into the manifest so listing plans costs one read rather than one
|
|
|
58
59
|
read per plan; `readPlan` returns the title parsed from the file, which wins if
|
|
59
60
|
the two ever disagree.
|
|
60
61
|
|
|
62
|
+
## Shared plans
|
|
63
|
+
|
|
64
|
+
Every `.md` file in the repository plans folder is a plan too: `.aiworker/plans`
|
|
65
|
+
by default, or the `plansDir` the team config (`<repo>/.aiworker/project.json`,
|
|
66
|
+
see `packages/web/server/lib/projects`) names instead of it (the custom folder
|
|
67
|
+
replaces the default outright; moving files between the two is the user's job). `readContext` appends them after the personal ones,
|
|
68
|
+
each marked `source: "shared"` (personal ones get `source: "personal"`), and
|
|
69
|
+
reports the folder as `sharedPlansDir`. A shared plan is addressed as
|
|
70
|
+
`shared:<file>` when no manifest entry claims it; its title is parsed from the
|
|
71
|
+
file on every list, and `readPlan` / `updatePlan` / `deletePlan` work on the
|
|
72
|
+
file directly (an update writes the raw document verbatim, so a plan another
|
|
73
|
+
tool wrote keeps its shape). `setPlanPinned` is `404` for such a plan.
|
|
74
|
+
|
|
75
|
+
A plan the user moves there keeps its id: `sharePlan` moves the markdown into
|
|
76
|
+
the folder and keeps the manifest entry with `shared: true` (the flag says
|
|
77
|
+
which folder holds the file), so a session that attached the plan still finds
|
|
78
|
+
it, and the file is listed under that id instead of `shared:<file>`.
|
|
79
|
+
`unsharePlan` moves it back and clears the flag; a plan that only ever lived
|
|
80
|
+
in the team's folder gets a manifest entry (and an id) on the way in. A name
|
|
81
|
+
collision gets a numeric suffix. Sharing is refused only when the checkout cannot be located.
|
|
82
|
+
|
|
61
83
|
## Routes
|
|
62
84
|
|
|
63
85
|
| Method | Route | Notes |
|
|
@@ -72,6 +94,8 @@ the two ever disagree.
|
|
|
72
94
|
| POST | `/api/project-context/:projectId/plans` | `201`; takes `{title, body}`, never a path |
|
|
73
95
|
| PUT | `/api/project-context/:projectId/plans/:planId` | takes the whole `{raw}` document; `404` when the link or its markdown is gone |
|
|
74
96
|
| DELETE | `/api/project-context/:projectId/plans/:planId` | `404` when unknown |
|
|
97
|
+
| POST | `/api/project-context/:projectId/plans/:planId/share` | moves the plan into the shared folder; `400` without one, `404` when unknown |
|
|
98
|
+
| POST | `/api/project-context/:projectId/plans/:planId/unshare` | moves a `shared:` plan back; `404` when unknown |
|
|
75
99
|
|
|
76
100
|
**Body parsing is attached per route.** This server has no global JSON parser:
|
|
77
101
|
`core-routes` parses only an allowlist of `/api` path prefixes so the generic
|
|
@@ -57,6 +57,8 @@ const createApp = (overrides = {}) => {
|
|
|
57
57
|
context: emptyContext,
|
|
58
58
|
}),
|
|
59
59
|
deletePlan: async () => ({ deleted: true, context: emptyContext }),
|
|
60
|
+
sharePlan: async (_projectId, planId) => (planId === 'p1' ? { plan: { id: 'shared:a.md', file: 'a.md', title: 'A', createdAt: 1, pinned: false, source: 'shared' }, context: emptyContext } : null),
|
|
61
|
+
unsharePlan: async (_projectId, planId) => (planId === 'shared:a.md' ? { plan: { id: 'p2', file: 'a.md', title: 'A', createdAt: 1, pinned: false, source: 'personal' }, context: emptyContext } : null),
|
|
60
62
|
...overrides,
|
|
61
63
|
};
|
|
62
64
|
|
|
@@ -212,6 +214,22 @@ describe('project context routes over HTTP', () => {
|
|
|
212
214
|
.expect(400);
|
|
213
215
|
});
|
|
214
216
|
|
|
217
|
+
it('shares and unshares a plan, and answers 404 for an unknown one', async () => {
|
|
218
|
+
const { app } = createApp();
|
|
219
|
+
const shared = await request(app).post('/api/project-context/proj/plans/p1/share');
|
|
220
|
+
expect(shared.status).toBe(200);
|
|
221
|
+
expect(shared.body.plan.id).toBe('shared:a.md');
|
|
222
|
+
const back = await request(app).post('/api/project-context/proj/plans/shared%3Aa.md/unshare');
|
|
223
|
+
expect(back.status).toBe(200);
|
|
224
|
+
expect(back.body.plan.source).toBe('personal');
|
|
225
|
+
expect((await request(app).post('/api/project-context/proj/plans/nope/share')).status).toBe(404);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('answers 400 when sharing without a shared plans folder', async () => {
|
|
229
|
+
const { app } = createApp({ sharePlan: async () => { throw new Error('shared plans folder is required'); } });
|
|
230
|
+
expect((await request(app).post('/api/project-context/proj/plans/p1/share')).status).toBe(400);
|
|
231
|
+
});
|
|
232
|
+
|
|
215
233
|
it('returns 404 for an unknown plan', async () => {
|
|
216
234
|
const { app } = createApp();
|
|
217
235
|
await request(app).get(`${BASE}/plans/nope`).expect(404);
|
|
@@ -220,6 +220,21 @@ export const registerProjectContextRoutes = (app, dependencies) => {
|
|
|
220
220
|
}
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
+
// Moving a plan between the user's folder and the team's shared folder.
|
|
224
|
+
for (const [suffix, method] of [['share', 'sharePlan'], ['unshare', 'unsharePlan']]) {
|
|
225
|
+
app.post(`/api/project-context/:projectId/plans/:planId/${suffix}`, async (req, res) => {
|
|
226
|
+
try {
|
|
227
|
+
const result = await projectContextRuntime[method](req.params.projectId, req.params.planId);
|
|
228
|
+
if (!result) {
|
|
229
|
+
return res.status(404).json({ error: 'Plan not found' });
|
|
230
|
+
}
|
|
231
|
+
return res.json(result);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
return respondWithError(res, error, `Failed to ${suffix} plan`);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
223
238
|
app.delete('/api/project-context/:projectId/plans/:planId', async (req, res) => {
|
|
224
239
|
try {
|
|
225
240
|
const { deleted, context } = await projectContextRuntime.deletePlan(
|