@openchamber/web 1.18.4 → 1.19.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/README.md +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
- package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-D9cV-qR9.js} +1 -1
- package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-B9NCadU7.js} +1 -1
- package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
- package/dist/assets/{DiffView-DZIoOnV7.js → DiffView-BWNq-0ov.js} +2 -2
- package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
- package/dist/assets/{GitView-DBFrDDBv.js → GitView-DsWXqWx3.js} +3 -3
- package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-h4dHASlq.js} +1 -1
- package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
- package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
- package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-jPKTJje5.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
- package/dist/assets/PlanView-UvuxIl9-.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
- package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
- package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
- package/dist/assets/{ToolOutputDialog-Za6V4VMJ.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BL-9ixyC.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
- package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-Bxun3k66.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
- package/dist/assets/de-DbV6CLxv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-CVDlyzZ4.js +15 -0
- package/dist/assets/fr-Czc-p0g-.js +13 -0
- package/dist/assets/index-1OhiMDBz.css +1 -0
- package/dist/assets/index-BSvmTvZl.js +1 -0
- package/dist/assets/index-DzriVon2.js +7 -0
- package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-DwHKxDYc.js} +1 -1
- package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-Dwq6ILxo.js} +1 -1
- package/dist/assets/ja-dwc9NM_S.js +15 -0
- package/dist/assets/ko-Ds1DZ8FX.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-BF51IOVF.js +921 -0
- package/dist/assets/{main-D7UcL3VQ.js → main-D7UPARut.js} +2 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
- package/dist/assets/{miniChat-O_GVoEbc.js → miniChat-BISXSGOo.js} +2 -2
- package/dist/assets/mobile-BnYxVuvw.js +2 -0
- package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BEDPDypx.js} +2 -2
- package/dist/assets/pl-CLiTO7i-.js +15 -0
- package/dist/assets/pt-BR-GIimJgpK.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
- package/dist/assets/{renderMobileApp-toj9cXoh.js → renderMobileApp-BiMbzPq9.js} +7 -7
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
- package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
- package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DXYW46vW.js} +1 -1
- package/dist/assets/uk-DLfgD1ki.js +15 -0
- package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-CbzHzFop.js} +139 -142
- package/dist/assets/{useInlineCommentController-CYPvYJDt.js → useInlineCommentController-CegKdDXi.js} +2 -2
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
- package/dist/assets/{web-components-GMc3oR3i.js → web-components-DCLjCO9n.js} +1 -1
- package/dist/assets/zh-CN-DkeP5awK.js +15 -0
- package/dist/assets/zh-TW-BocaFm3d.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 +1 -1
- package/server/index.js +116 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +56 -0
- package/server/lib/agent-memory/project-resolution.test.js +85 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +427 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +225 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/service.js +121 -67
- package/server/lib/git/service.test.js +129 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -4
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +11 -0
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/settings-helpers.js +11 -0
- package/server/lib/opencode/settings-helpers.test.js +35 -0
- package/server/lib/opencode/settings-runtime.js +51 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/project-context/DOCUMENTATION.md +158 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +667 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/quota/DOCUMENTATION.md +16 -1
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +72 -0
- package/server/lib/quota/providers/index.js +22 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
- package/server/lib/skills-catalog/curated-sources.js +1 -1
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/small-model/index.js +8 -0
- package/server/lib/small-model/index.test.js +31 -1
- package/server/lib/small-model/routes.js +3 -1
- package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
- package/dist/assets/FilesView-BKL6YlKG.js +0 -14
- package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
- package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
- package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
- package/dist/assets/SettingsView-5RmswFZe.js +0 -28
- package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
- package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-BzIpNlNE.css +0 -1
- package/dist/assets/index-C0yNhuZw.js +0 -1
- package/dist/assets/index-DRpChWux.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-DPMd2iKS.js +0 -915
- package/dist/assets/markdownCore-DDrHVneM.js +0 -2
- package/dist/assets/mobile-Br4TtAqc.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
- package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
- package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import yaml from 'yaml';
|
|
5
|
-
import { parse as parseJsonc } from 'jsonc-parser';
|
|
5
|
+
import { parse as parseJsonc, printParseErrorCode } from 'jsonc-parser';
|
|
6
6
|
|
|
7
7
|
// ============== PATH CONSTANTS ==============
|
|
8
8
|
|
|
@@ -168,6 +168,42 @@ function getPrimaryUserConfigPath(userPaths) {
|
|
|
168
168
|
return CONFIG_FILE;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
const INVALID_JSONC = 'INVALID_JSONC';
|
|
172
|
+
|
|
173
|
+
function isInvalidJsoncError(error) {
|
|
174
|
+
return Boolean(error && typeof error === 'object' && error.code === INVALID_JSONC);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function formatJsoncParseError(filePath, errors) {
|
|
178
|
+
const first = Array.isArray(errors) && errors.length > 0 ? errors[0] : null;
|
|
179
|
+
const location = first && Number.isFinite(first.offset)
|
|
180
|
+
? ` (${printParseErrorCode(first.error)} at offset ${first.offset})`
|
|
181
|
+
: '';
|
|
182
|
+
return `OpenCode configuration at ${filePath} contains invalid JSONC and cannot be loaded safely${location}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function isCommentOnlyParse(parsed, errors) {
|
|
186
|
+
// Comment-only / whitespace-only files parse to undefined with nothing but
|
|
187
|
+
// ValueExpected. Any other error means real content we failed to understand
|
|
188
|
+
// (YAML, plain text, a stray leading token), which must not read as empty.
|
|
189
|
+
return parsed === undefined
|
|
190
|
+
&& errors.every((entry) => printParseErrorCode(entry.error) === 'ValueExpected');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function parseConfigObject(content, filePath) {
|
|
194
|
+
const errors = [];
|
|
195
|
+
const parsed = parseJsonc(content, errors, { allowTrailingComma: true });
|
|
196
|
+
if (isCommentOnlyParse(parsed, errors)) {
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
if (errors.length > 0 || !parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
200
|
+
const error = new Error(formatJsoncParseError(filePath, errors));
|
|
201
|
+
error.code = INVALID_JSONC;
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
return parsed;
|
|
205
|
+
}
|
|
206
|
+
|
|
171
207
|
function readConfigFile(filePath) {
|
|
172
208
|
if (!filePath || !fs.existsSync(filePath)) {
|
|
173
209
|
return {};
|
|
@@ -178,8 +214,13 @@ function readConfigFile(filePath) {
|
|
|
178
214
|
if (!normalized) {
|
|
179
215
|
return {};
|
|
180
216
|
}
|
|
181
|
-
|
|
217
|
+
// Refuse partial jsonc-parser trees. Ignoring errors previously let mutations
|
|
218
|
+
// rewrite a truncated object (often only `$schema`) over the full config.
|
|
219
|
+
return parseConfigObject(normalized, filePath);
|
|
182
220
|
} catch (error) {
|
|
221
|
+
if (isInvalidJsoncError(error)) {
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
183
224
|
console.error(`Failed to read config file: ${filePath}`, error);
|
|
184
225
|
throw new Error('Failed to read OpenCode configuration');
|
|
185
226
|
}
|
|
@@ -209,20 +250,47 @@ function mergeConfigs(base, override) {
|
|
|
209
250
|
return result;
|
|
210
251
|
}
|
|
211
252
|
|
|
253
|
+
function readConfigLayer(filePath) {
|
|
254
|
+
try {
|
|
255
|
+
return { config: readConfigFile(filePath), error: null };
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (isInvalidJsoncError(error)) {
|
|
258
|
+
console.error(error.message);
|
|
259
|
+
return { config: {}, error };
|
|
260
|
+
}
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
212
265
|
function readConfigLayers(workingDirectory) {
|
|
213
266
|
const { userPaths, projectPath, customPath } = getConfigPaths(workingDirectory);
|
|
214
267
|
const userPath = getPrimaryUserConfigPath(userPaths);
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const mergedConfig = mergeConfigs(
|
|
268
|
+
const userLayer = readConfigLayer(userPath);
|
|
269
|
+
const projectLayer = readConfigLayer(projectPath);
|
|
270
|
+
const customLayer = readConfigLayer(customPath);
|
|
271
|
+
const mergedConfig = mergeConfigs(
|
|
272
|
+
mergeConfigs(userLayer.config, projectLayer.config),
|
|
273
|
+
customLayer.config,
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const layerErrors = [];
|
|
277
|
+
if (userLayer.error) {
|
|
278
|
+
layerErrors.push({ path: userPath, code: userLayer.error.code, message: userLayer.error.message });
|
|
279
|
+
}
|
|
280
|
+
if (projectLayer.error && projectPath) {
|
|
281
|
+
layerErrors.push({ path: projectPath, code: projectLayer.error.code, message: projectLayer.error.message });
|
|
282
|
+
}
|
|
283
|
+
if (customLayer.error && customPath) {
|
|
284
|
+
layerErrors.push({ path: customPath, code: customLayer.error.code, message: customLayer.error.message });
|
|
285
|
+
}
|
|
219
286
|
|
|
220
287
|
return {
|
|
221
|
-
userConfig,
|
|
222
|
-
projectConfig,
|
|
223
|
-
customConfig,
|
|
288
|
+
userConfig: userLayer.config,
|
|
289
|
+
projectConfig: projectLayer.config,
|
|
290
|
+
customConfig: customLayer.config,
|
|
224
291
|
mergedConfig,
|
|
225
|
-
paths: { userPath, projectPath, customPath }
|
|
292
|
+
paths: { userPath, projectPath, customPath },
|
|
293
|
+
layerErrors,
|
|
226
294
|
};
|
|
227
295
|
}
|
|
228
296
|
|
|
@@ -246,6 +314,12 @@ function getConfigForPath(layers, targetPath) {
|
|
|
246
314
|
function writeConfig(config, filePath = CONFIG_FILE) {
|
|
247
315
|
try {
|
|
248
316
|
if (fs.existsSync(filePath)) {
|
|
317
|
+
// Defense in depth: never overwrite a file we cannot fully parse.
|
|
318
|
+
const existing = fs.readFileSync(filePath, 'utf8').trim();
|
|
319
|
+
if (existing) {
|
|
320
|
+
parseConfigObject(existing, filePath);
|
|
321
|
+
}
|
|
322
|
+
|
|
249
323
|
const backupFile = `${filePath}.openchamber.backup`;
|
|
250
324
|
fs.copyFileSync(filePath, backupFile);
|
|
251
325
|
console.log(`Created config backup: ${backupFile}`);
|
|
@@ -255,23 +329,49 @@ function writeConfig(config, filePath = CONFIG_FILE) {
|
|
|
255
329
|
fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf8');
|
|
256
330
|
console.log(`Successfully wrote config file: ${filePath}`);
|
|
257
331
|
} catch (error) {
|
|
332
|
+
if (isInvalidJsoncError(error)) {
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
258
335
|
console.error(`Failed to write config file: ${filePath}`, error);
|
|
259
336
|
throw new Error('Failed to write OpenCode configuration');
|
|
260
337
|
}
|
|
261
338
|
}
|
|
262
339
|
|
|
340
|
+
function getLayerError(layers, filePath) {
|
|
341
|
+
if (!filePath || !Array.isArray(layers?.layerErrors)) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
return layers.layerErrors.find((entry) => entry.path === filePath) || null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function throwIfLayerError(layers, filePath) {
|
|
348
|
+
const failed = getLayerError(layers, filePath);
|
|
349
|
+
if (!failed) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const error = new Error(failed.message);
|
|
353
|
+
error.code = failed.code;
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
356
|
+
|
|
263
357
|
function getJsonEntrySource(layers, sectionKey, entryName) {
|
|
264
358
|
const { userConfig, projectConfig, customConfig, paths } = layers;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
359
|
+
if (paths.customPath) {
|
|
360
|
+
throwIfLayerError(layers, paths.customPath);
|
|
361
|
+
const customSection = customConfig?.[sectionKey]?.[entryName];
|
|
362
|
+
if (customSection !== undefined) {
|
|
363
|
+
return { section: customSection, config: customConfig, path: paths.customPath, exists: true };
|
|
364
|
+
}
|
|
268
365
|
}
|
|
269
366
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
367
|
+
if (paths.projectPath && !getLayerError(layers, paths.projectPath)) {
|
|
368
|
+
const projectSection = projectConfig?.[sectionKey]?.[entryName];
|
|
369
|
+
if (projectSection !== undefined) {
|
|
370
|
+
return { section: projectSection, config: projectConfig, path: paths.projectPath, exists: true };
|
|
371
|
+
}
|
|
273
372
|
}
|
|
274
373
|
|
|
374
|
+
throwIfLayerError(layers, paths.userPath);
|
|
275
375
|
const userSection = userConfig?.[sectionKey]?.[entryName];
|
|
276
376
|
if (userSection !== undefined) {
|
|
277
377
|
return { section: userSection, config: userConfig, path: paths.userPath, exists: true };
|
|
@@ -283,11 +383,14 @@ function getJsonEntrySource(layers, sectionKey, entryName) {
|
|
|
283
383
|
function getJsonWriteTarget(layers, preferredScope) {
|
|
284
384
|
const { userConfig, projectConfig, customConfig, paths } = layers;
|
|
285
385
|
if (paths.customPath) {
|
|
386
|
+
throwIfLayerError(layers, paths.customPath);
|
|
286
387
|
return { config: customConfig, path: paths.customPath };
|
|
287
388
|
}
|
|
288
389
|
if (preferredScope === AGENT_SCOPE.PROJECT && paths.projectPath) {
|
|
390
|
+
throwIfLayerError(layers, paths.projectPath);
|
|
289
391
|
return { config: projectConfig, path: paths.projectPath };
|
|
290
392
|
}
|
|
393
|
+
throwIfLayerError(layers, paths.userPath);
|
|
291
394
|
return { config: userConfig, path: paths.userPath };
|
|
292
395
|
}
|
|
293
396
|
|
|
@@ -547,6 +650,7 @@ export {
|
|
|
547
650
|
parseMdFile,
|
|
548
651
|
writeMdFile,
|
|
549
652
|
readConfigFile,
|
|
653
|
+
readConfigLayer,
|
|
550
654
|
isPlainObject,
|
|
551
655
|
readConfigLayers,
|
|
552
656
|
readConfig,
|
|
@@ -3,8 +3,9 @@ import fs from 'fs';
|
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
|
-
import { parseMdFile, writeMdFile } from './shared.js';
|
|
6
|
+
import { parseMdFile, writeMdFile, readConfigFile, readConfigLayers, writeConfig } from './shared.js';
|
|
7
7
|
import { updateAgent } from './agents.js';
|
|
8
|
+
import { updateMcpConfig } from './mcp.js';
|
|
8
9
|
|
|
9
10
|
const FIXTURE_DIR = path.join(os.tmpdir(), `openchamber-shared-test-${process.pid}`);
|
|
10
11
|
|
|
@@ -200,3 +201,186 @@ describe('updateAgent frontmatter preservation', () => {
|
|
|
200
201
|
expect(parsed.body).toBe('Body of strateg.');
|
|
201
202
|
});
|
|
202
203
|
});
|
|
204
|
+
|
|
205
|
+
describe('readConfigFile / writeConfig JSONC safety (issue #2923)', () => {
|
|
206
|
+
beforeEach(() => {
|
|
207
|
+
fs.rmSync(FIXTURE_DIR, { recursive: true, force: true });
|
|
208
|
+
fs.mkdirSync(FIXTURE_DIR, { recursive: true });
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
afterEach(() => {
|
|
212
|
+
fs.rmSync(FIXTURE_DIR, { recursive: true, force: true });
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const VALID_CONFIG = [
|
|
216
|
+
'{',
|
|
217
|
+
' "$schema": "https://opencode.ai/config.json",',
|
|
218
|
+
' // keep me',
|
|
219
|
+
' "plugin": ["opencode-see-image"],',
|
|
220
|
+
' "mcp": {',
|
|
221
|
+
' "openproject": {',
|
|
222
|
+
' "type": "remote",',
|
|
223
|
+
' "url": "https://openproject.example.com/mcp",',
|
|
224
|
+
' "enabled": true,',
|
|
225
|
+
' }',
|
|
226
|
+
' },',
|
|
227
|
+
' "provider": {',
|
|
228
|
+
' "ollama-cloud": {',
|
|
229
|
+
' "npm": "@ai-sdk/openai-compatible",',
|
|
230
|
+
' "name": "Ollama Cloud"',
|
|
231
|
+
' }',
|
|
232
|
+
' }',
|
|
233
|
+
'}',
|
|
234
|
+
'',
|
|
235
|
+
].join('\n');
|
|
236
|
+
|
|
237
|
+
// JSON5-style unquoted keys after $schema — jsonc-parser returns a partial
|
|
238
|
+
// tree of only `{ $schema }` when errors are ignored.
|
|
239
|
+
const PARTIAL_PARSE_CONFIG = [
|
|
240
|
+
'{',
|
|
241
|
+
' "$schema": "https://opencode.ai/config.json",',
|
|
242
|
+
' plugin: ["opencode-see-image"],',
|
|
243
|
+
' mcp: {',
|
|
244
|
+
' openproject: {',
|
|
245
|
+
' type: "remote",',
|
|
246
|
+
' url: "https://openproject.example.com/mcp",',
|
|
247
|
+
' enabled: true',
|
|
248
|
+
' }',
|
|
249
|
+
' },',
|
|
250
|
+
' provider: {',
|
|
251
|
+
' "ollama-cloud": {',
|
|
252
|
+
' npm: "@ai-sdk/openai-compatible",',
|
|
253
|
+
' name: "Ollama Cloud"',
|
|
254
|
+
' }',
|
|
255
|
+
' }',
|
|
256
|
+
'}',
|
|
257
|
+
'',
|
|
258
|
+
].join('\n');
|
|
259
|
+
|
|
260
|
+
it('parses valid JSONC with comments and trailing commas without dropping keys', () => {
|
|
261
|
+
const file = writeFixture('opencode.jsonc', VALID_CONFIG);
|
|
262
|
+
expect(readConfigFile(file)).toEqual({
|
|
263
|
+
$schema: 'https://opencode.ai/config.json',
|
|
264
|
+
plugin: ['opencode-see-image'],
|
|
265
|
+
mcp: {
|
|
266
|
+
openproject: {
|
|
267
|
+
type: 'remote',
|
|
268
|
+
url: 'https://openproject.example.com/mcp',
|
|
269
|
+
enabled: true,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
provider: {
|
|
273
|
+
'ollama-cloud': {
|
|
274
|
+
npm: '@ai-sdk/openai-compatible',
|
|
275
|
+
name: 'Ollama Cloud',
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('returns an empty object for a missing or whitespace-only file', () => {
|
|
282
|
+
expect(readConfigFile(path.join(FIXTURE_DIR, 'missing.jsonc'))).toEqual({});
|
|
283
|
+
const empty = writeFixture('empty.jsonc', ' \n');
|
|
284
|
+
expect(readConfigFile(empty)).toEqual({});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('throws INVALID_JSONC on partial-parse JSONC instead of returning a $schema-only stub', () => {
|
|
288
|
+
const file = writeFixture('opencode.jsonc', PARTIAL_PARSE_CONFIG);
|
|
289
|
+
expect(() => readConfigFile(file)).toThrow(/cannot be loaded safely/);
|
|
290
|
+
try {
|
|
291
|
+
readConfigFile(file);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
expect(error.code).toBe('INVALID_JSONC');
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('throws INVALID_JSONC for a non-object JSONC root', () => {
|
|
298
|
+
const file = writeFixture('array.jsonc', '["plugin"]\n');
|
|
299
|
+
expect(() => readConfigFile(file)).toThrow(/cannot be loaded safely/);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('refuses to overwrite an unparseable config file', () => {
|
|
303
|
+
const file = writeFixture('opencode.jsonc', PARTIAL_PARSE_CONFIG);
|
|
304
|
+
expect(() => writeConfig({ $schema: 'https://opencode.ai/config.json' }, file)).toThrow(
|
|
305
|
+
/cannot be loaded safely/,
|
|
306
|
+
);
|
|
307
|
+
expect(fs.readFileSync(file, 'utf8')).toBe(PARTIAL_PARSE_CONFIG);
|
|
308
|
+
expect(fs.existsSync(`${file}.openchamber.backup`)).toBe(false);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('preserves a valid config across MCP updates', () => {
|
|
312
|
+
const file = writeFixture('opencode.jsonc', VALID_CONFIG);
|
|
313
|
+
const config = readConfigFile(file);
|
|
314
|
+
config.mcp.openproject.enabled = false;
|
|
315
|
+
writeConfig(config, file);
|
|
316
|
+
|
|
317
|
+
const rewritten = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
318
|
+
expect(rewritten.plugin).toEqual(['opencode-see-image']);
|
|
319
|
+
expect(rewritten.provider['ollama-cloud'].name).toBe('Ollama Cloud');
|
|
320
|
+
expect(rewritten.mcp.openproject.enabled).toBe(false);
|
|
321
|
+
expect(fs.readFileSync(`${file}.openchamber.backup`, 'utf8')).toBe(VALID_CONFIG);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('does not wipe an unparseable user config during MCP mutation attempts', () => {
|
|
325
|
+
const file = writeFixture('opencode.jsonc', PARTIAL_PARSE_CONFIG);
|
|
326
|
+
const previousOpenCodeConfig = process.env.OPENCODE_CONFIG;
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
process.env.OPENCODE_CONFIG = file;
|
|
330
|
+
expect(() => updateMcpConfig('openproject', { enabled: true })).toThrow(
|
|
331
|
+
/cannot be loaded safely/,
|
|
332
|
+
);
|
|
333
|
+
expect(fs.readFileSync(file, 'utf8')).toBe(PARTIAL_PARSE_CONFIG);
|
|
334
|
+
expect(fs.existsSync(`${file}.openchamber.backup`)).toBe(false);
|
|
335
|
+
} finally {
|
|
336
|
+
if (previousOpenCodeConfig === undefined) delete process.env.OPENCODE_CONFIG;
|
|
337
|
+
else process.env.OPENCODE_CONFIG = previousOpenCodeConfig;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('returns an empty object for a comment-only config file', () => {
|
|
342
|
+
const file = writeFixture('comments.jsonc', '// placeholder\n/* still empty */\n');
|
|
343
|
+
expect(readConfigFile(file)).toEqual({});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('throws INVALID_JSONC for content that yields no JSON value at all', () => {
|
|
347
|
+
const yamlish = writeFixture('yamlish.jsonc', 'mcp:\n openproject:\n type: remote\n');
|
|
348
|
+
expect(() => readConfigFile(yamlish)).toThrow(/cannot be loaded safely/);
|
|
349
|
+
expect(() => writeConfig({ $schema: 'https://opencode.ai/config.json' }, yamlish)).toThrow(
|
|
350
|
+
/cannot be loaded safely/,
|
|
351
|
+
);
|
|
352
|
+
expect(fs.readFileSync(yamlish, 'utf8')).toBe('mcp:\n openproject:\n type: remote\n');
|
|
353
|
+
expect(fs.existsSync(`${yamlish}.openchamber.backup`)).toBe(false);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('keeps a valid custom layer readable when a project layer is unparseable', () => {
|
|
357
|
+
const custom = writeFixture('custom.jsonc', VALID_CONFIG);
|
|
358
|
+
const projectDir = path.join(FIXTURE_DIR, 'project');
|
|
359
|
+
const projectFile = writeFixture(path.join('project', '.opencode', 'opencode.jsonc'), PARTIAL_PARSE_CONFIG);
|
|
360
|
+
const previousOpenCodeConfig = process.env.OPENCODE_CONFIG;
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
process.env.OPENCODE_CONFIG = custom;
|
|
364
|
+
const layers = readConfigLayers(projectDir);
|
|
365
|
+
expect(layers.customConfig.plugin).toEqual(['opencode-see-image']);
|
|
366
|
+
expect(layers.projectConfig).toEqual({});
|
|
367
|
+
expect(layers.mergedConfig.plugin).toEqual(['opencode-see-image']);
|
|
368
|
+
expect(layers.layerErrors).toEqual([
|
|
369
|
+
expect.objectContaining({
|
|
370
|
+
path: projectFile,
|
|
371
|
+
code: 'INVALID_JSONC',
|
|
372
|
+
}),
|
|
373
|
+
]);
|
|
374
|
+
|
|
375
|
+
updateMcpConfig('openproject', { enabled: false }, projectDir);
|
|
376
|
+
const rewritten = JSON.parse(fs.readFileSync(custom, 'utf8'));
|
|
377
|
+
expect(rewritten.plugin).toEqual(['opencode-see-image']);
|
|
378
|
+
expect(rewritten.mcp.openproject.enabled).toBe(false);
|
|
379
|
+
expect(fs.readFileSync(projectFile, 'utf8')).toBe(PARTIAL_PARSE_CONFIG);
|
|
380
|
+
expect(fs.existsSync(`${projectFile}.openchamber.backup`)).toBe(false);
|
|
381
|
+
} finally {
|
|
382
|
+
if (previousOpenCodeConfig === undefined) delete process.env.OPENCODE_CONFIG;
|
|
383
|
+
else process.env.OPENCODE_CONFIG = previousOpenCodeConfig;
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
|
|
3
|
+
Server-owned storage for the Project Notes surface: free-form notes, todos, and
|
|
4
|
+
plan markdown files.
|
|
5
|
+
|
|
6
|
+
## Ownership
|
|
7
|
+
|
|
8
|
+
| Path | Owner | Contents |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| `<projectsDir>/<projectId>.json` | shared UI (`packages/ui/src/lib/openchamberConfig.ts`), plus server-owned `version` / `scheduledTasks` | worktree setup, draft starters, project actions |
|
|
11
|
+
| `<projectsDir>/<projectId>/context.json` | **this module, exclusively** | notes, todos, plan manifest |
|
|
12
|
+
| `<projectsDir>/<projectId>/plans/*.md` | **this module, exclusively** | plan bodies |
|
|
13
|
+
|
|
14
|
+
The split is the point. Both files were previously one, written by the client
|
|
15
|
+
with a whole-file read-modify-write. Adding a server writer to that file would
|
|
16
|
+
have made unrelated features (project actions, draft starters) clobber notes
|
|
17
|
+
across processes, with no lock able to span both sides. Separate files remove
|
|
18
|
+
the shared resource instead of trying to coordinate access to it.
|
|
19
|
+
|
|
20
|
+
Nothing outside this module may write `context.json` or the `plans` directory.
|
|
21
|
+
|
|
22
|
+
## Storage format
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"version": 2,
|
|
27
|
+
"notes": [{
|
|
28
|
+
"id": "", "body": "", "createdAt": 0, "updatedAt": 0,
|
|
29
|
+
"source": "manual | selection | agent",
|
|
30
|
+
"origin": { "sessionId": "", "messageId": "" }
|
|
31
|
+
}],
|
|
32
|
+
"todos": [{ "id": "", "text": "", "completed": false, "createdAt": 0 }],
|
|
33
|
+
"plans": [{ "id": "", "file": "1700000000-title.md", "title": "", "createdAt": 0 }]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Notes are entries, not one blob. Version 1 stored a single string; it converts
|
|
38
|
+
to a single `manual` note on read (an empty string converts to no notes at
|
|
39
|
+
all). The conversion lives in the read path rather than a separate migration
|
|
40
|
+
pass so that every reader — including one racing a writer — sees one shape.
|
|
41
|
+
Legacy `pinned` fields may remain in existing files but are ignored; attachment
|
|
42
|
+
ownership lives in each session's metadata.
|
|
43
|
+
|
|
44
|
+
`source` records where a note came from, and `origin` links it back to the
|
|
45
|
+
message it was distilled from, so a note taken off a chat selection can be
|
|
46
|
+
traced to its conversation.
|
|
47
|
+
|
|
48
|
+
Notes and todos are written through separate routes. That split is what stops a
|
|
49
|
+
todo toggle from persisting half-typed notes alongside it, and stops an
|
|
50
|
+
agent-authored note from clobbering a concurrent todo change.
|
|
51
|
+
|
|
52
|
+
Plan links store a **base name**, never a path. The file always lives in
|
|
53
|
+
`<projectId>/plans/`, so moving the project storage directory cannot invalidate
|
|
54
|
+
a reference and a caller can never address a file outside it. `title` is
|
|
55
|
+
denormalized into the manifest so listing plans costs one read rather than one
|
|
56
|
+
read per plan; `readPlan` returns the title parsed from the file, which wins if
|
|
57
|
+
the two ever disagree.
|
|
58
|
+
|
|
59
|
+
## Routes
|
|
60
|
+
|
|
61
|
+
| Method | Route | Notes |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| GET | `/api/project-context/:projectId` | full context; missing file is `200` empty |
|
|
64
|
+
| PUT | `/api/project-context/:projectId/todos` | replaces the whole list; returns committed context |
|
|
65
|
+
| POST | `/api/project-context/:projectId/notes` | `201`; takes `{body, source?, origin?}` |
|
|
66
|
+
| PATCH | `/api/project-context/:projectId/notes/:noteId` | patches `body`; legacy `pinned` input is ignored by session knowledge; `404` when unknown |
|
|
67
|
+
| DELETE | `/api/project-context/:projectId/notes/:noteId` | `404` when unknown |
|
|
68
|
+
| PATCH | `/api/project-context/:projectId/plans/:planId` | legacy project pin state only; session attachment uses session knowledge; `404` when unknown |
|
|
69
|
+
| GET | `/api/project-context/:projectId/plans/:planId` | `404` when the link or its markdown is gone |
|
|
70
|
+
| POST | `/api/project-context/:projectId/plans` | `201`; takes `{title, body}`, never a path |
|
|
71
|
+
| PUT | `/api/project-context/:projectId/plans/:planId` | takes the whole `{raw}` document; `404` when the link or its markdown is gone |
|
|
72
|
+
| DELETE | `/api/project-context/:projectId/plans/:planId` | `404` when unknown |
|
|
73
|
+
|
|
74
|
+
**Body parsing is attached per route.** This server has no global JSON parser:
|
|
75
|
+
`core-routes` parses only an allowlist of `/api` path prefixes so the generic
|
|
76
|
+
OpenCode proxy keeps an unread request stream, and every other `/api` request
|
|
77
|
+
passes through untouched. A write route that forgets `express.json()` therefore
|
|
78
|
+
sees `req.body` as `undefined` and rejects every request as a malformed body —
|
|
79
|
+
which is exactly how this shipped once. `routes.http.test.js` mounts the routes
|
|
80
|
+
on a bare express app so that failure mode fails the suite instead of the user.
|
|
81
|
+
|
|
82
|
+
`projectId` is validated against `/^[a-zA-Z0-9._:-]+$/`, which rejects
|
|
83
|
+
separators and traversal. Validation failures are `400`; malformed stored data
|
|
84
|
+
and I/O failures are `500`.
|
|
85
|
+
|
|
86
|
+
## Invariants
|
|
87
|
+
|
|
88
|
+
- **Missing is not malformed.** A missing `context.json` is authoritative empty
|
|
89
|
+
data. Unparseable JSON is a failure that propagates as `500`, so the client
|
|
90
|
+
preserves what it already has instead of rendering an empty panel over intact
|
|
91
|
+
data on disk.
|
|
92
|
+
- **Writes are serialized per project** through an in-process lock, and land via
|
|
93
|
+
write-to-temp + rename so a crash cannot leave a half-written file.
|
|
94
|
+
- **`readContext` never takes the lock.** Every mutator calls it while already
|
|
95
|
+
holding the lock, so locking there would deadlock. The legacy migration it can
|
|
96
|
+
trigger is safe unlocked: both writes are atomic renames of identical content.
|
|
97
|
+
- **Plan create writes markdown before the manifest entry**; delete removes the
|
|
98
|
+
manifest entry before the file. Either partial failure leaves an unreferenced
|
|
99
|
+
markdown file, which is inert. The reverse order would leave a manifest entry
|
|
100
|
+
that renders as a plan and fails to open.
|
|
101
|
+
- **Plan update takes the raw document, not title + body.** The editor owns
|
|
102
|
+
the file verbatim; reassembling it from parsed parts would rewrite the
|
|
103
|
+
heading and reformat what the user typed. The manifest title is re-derived
|
|
104
|
+
from the saved content, and the file name never changes with the title — it
|
|
105
|
+
is the stable identity behind the link.
|
|
106
|
+
- **Plan update refuses to recreate a deleted file.** If the markdown vanished
|
|
107
|
+
underneath an open editor the link is already dead; writing would resurrect
|
|
108
|
+
content the user believes was discarded, so it returns `404` instead.
|
|
109
|
+
- **A note patch touches only the fields it names.** Pinning sends `pinned`
|
|
110
|
+
alone, so it cannot roll back an edit that landed between the two requests,
|
|
111
|
+
and editing does not reset a pin. Editing bumps `updatedAt`; pinning does not,
|
|
112
|
+
because a pin is not a change to what the note says.
|
|
113
|
+
- **A note body can be clamped but never blanked.** An empty body is rejected
|
|
114
|
+
rather than stored, since a note with nothing in it is indistinguishable from
|
|
115
|
+
a delete the user did not ask for.
|
|
116
|
+
- **Notes are capped at 200 per project.** Past that, creation fails loudly
|
|
117
|
+
instead of silently evicting the oldest entry.
|
|
118
|
+
- **Per-entry sanitization never fails the whole read.** A malformed todo or
|
|
119
|
+
plan link is dropped; the rest of the context still loads.
|
|
120
|
+
|
|
121
|
+
## Legacy migration
|
|
122
|
+
|
|
123
|
+
`projectNotes`, `projectTodos`, and `projectPlanFiles` originally lived in
|
|
124
|
+
`<projectId>.json`. On the first read with no `context.json`, those three keys
|
|
125
|
+
are moved out and deleted from the client-owned file; every other key is
|
|
126
|
+
preserved untouched.
|
|
127
|
+
|
|
128
|
+
Plan links carried absolute paths. Migration converts each to a base name. A
|
|
129
|
+
file already in the plans directory is used in place; one referenced from
|
|
130
|
+
elsewhere — a stale path left by an earlier project id — is copied in rather
|
|
131
|
+
than dropped. A link whose markdown cannot be found at all is discarded, since
|
|
132
|
+
it could not have been opened either way.
|
|
133
|
+
|
|
134
|
+
The legacy keys are removed only after `context.json` is durably written, so any
|
|
135
|
+
failure simply leaves the migration to run again on the next read. Repeat and
|
|
136
|
+
concurrent reads converge on identical content.
|
|
137
|
+
|
|
138
|
+
## Cross-module contract
|
|
139
|
+
|
|
140
|
+
`packages/web/server/lib/opencode/settings-runtime.js` merges project storage
|
|
141
|
+
when a project id changes. Its `mergeProjectContextFiles` step must run before
|
|
142
|
+
`moveDirectoryContents`, because that mover only renames into a free
|
|
143
|
+
destination and would otherwise discard the old `context.json` whenever the
|
|
144
|
+
destination already had one.
|
|
145
|
+
|
|
146
|
+
`mergeProjectContextFiles` merges every list by identity and deliberately does
|
|
147
|
+
not convert a version 1 string note: this module owns that conversion, and
|
|
148
|
+
doing it in two places would mean two definitions of the same migration.
|
|
149
|
+
|
|
150
|
+
`mergeProjectConfigData` still merges the legacy `projectNotes` /
|
|
151
|
+
`projectTodos` / `projectPlanFiles` keys. That is deliberate: a project whose
|
|
152
|
+
context has not been migrated yet keeps its data in `<projectId>.json`, and the
|
|
153
|
+
migration picks it up from the merged destination afterwards.
|
|
154
|
+
|
|
155
|
+
## Tests
|
|
156
|
+
|
|
157
|
+
- `runtime.test.js` — storage, sanitization, migration, locking, plan lifecycle.
|
|
158
|
+
- `routes.test.js` — status-code mapping, payload validation, failure surfacing.
|