@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
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import request from 'supertest';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { registerProjectContextRoutes } from './routes.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* End-to-end route tests over real HTTP.
|
|
9
|
+
*
|
|
10
|
+
* An earlier unit test invoked the handlers directly. That covered status-code
|
|
11
|
+
* mapping but could not see middleware, and the blind spot shipped a real bug:
|
|
12
|
+
* the
|
|
13
|
+
* server has no global JSON parser — `core-routes` parses only an allowlist of
|
|
14
|
+
* path prefixes so the OpenCode proxy keeps an unread stream — so every write
|
|
15
|
+
* here arrived with `req.body` undefined and was rejected as malformed.
|
|
16
|
+
*
|
|
17
|
+
* These tests mount the routes on a bare express app, exactly as production
|
|
18
|
+
* does, so a missing body parser fails the suite instead of the user.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const emptyContext = { version: 2, notes: [], todos: [], plans: [] };
|
|
22
|
+
|
|
23
|
+
const createApp = (overrides = {}) => {
|
|
24
|
+
const received = {};
|
|
25
|
+
const runtime = {
|
|
26
|
+
readContext: async () => emptyContext,
|
|
27
|
+
saveTodos: async (_projectId, todos) => {
|
|
28
|
+
received.todos = todos;
|
|
29
|
+
return { ...emptyContext, todos };
|
|
30
|
+
},
|
|
31
|
+
createNote: async (_projectId, value) => {
|
|
32
|
+
received.note = value;
|
|
33
|
+
return {
|
|
34
|
+
note: { id: 'n1', body: value.body, createdAt: 1, updatedAt: 1, source: value.source ?? 'manual', pinned: false },
|
|
35
|
+
context: emptyContext,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
updateNote: async (_projectId, _noteId, patch) => {
|
|
39
|
+
received.notePatch = patch;
|
|
40
|
+
return {
|
|
41
|
+
note: { id: 'n1', body: 'x', createdAt: 1, updatedAt: 2, source: 'manual', pinned: patch.pinned === true },
|
|
42
|
+
context: emptyContext,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
deleteNote: async () => ({ deleted: true, context: emptyContext }),
|
|
46
|
+
readPlan: async () => null,
|
|
47
|
+
createPlan: async (_projectId, value) => {
|
|
48
|
+
received.plan = value;
|
|
49
|
+
return { plan: { id: 'p1', file: 'a.md', title: value.title, createdAt: 1, pinned: false }, context: emptyContext };
|
|
50
|
+
},
|
|
51
|
+
updatePlan: async (_projectId, _planId, value) => {
|
|
52
|
+
received.planRaw = value;
|
|
53
|
+
return { plan: { id: 'p1', file: 'a.md', title: 'A', createdAt: 1, pinned: false }, context: emptyContext, title: 'A', body: 'x', raw: value.raw };
|
|
54
|
+
},
|
|
55
|
+
setPlanPinned: async (_projectId, _planId, pinned) => ({
|
|
56
|
+
plan: { id: 'p1', file: 'a.md', title: 'A', createdAt: 1, pinned },
|
|
57
|
+
context: emptyContext,
|
|
58
|
+
}),
|
|
59
|
+
deletePlan: async () => ({ deleted: true, context: emptyContext }),
|
|
60
|
+
...overrides,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const app = express();
|
|
64
|
+
// Deliberately NO app.use(express.json()): production does not have one on
|
|
65
|
+
// this path, so adding it here would hide the very defect these tests exist
|
|
66
|
+
// to catch.
|
|
67
|
+
registerProjectContextRoutes(app, { projectContextRuntime: runtime });
|
|
68
|
+
return { app, received };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const BASE = '/api/project-context/path_dGVzdA';
|
|
72
|
+
|
|
73
|
+
describe('project context routes over HTTP', () => {
|
|
74
|
+
it('reads the context', async () => {
|
|
75
|
+
const { app } = createApp();
|
|
76
|
+
const res = await request(app).get(BASE).expect(200);
|
|
77
|
+
expect(res.body).toEqual(emptyContext);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('accepts a todos write with a JSON body', async () => {
|
|
81
|
+
const { app, received } = createApp();
|
|
82
|
+
|
|
83
|
+
await request(app)
|
|
84
|
+
.put(`${BASE}/todos`)
|
|
85
|
+
.send({ todos: [{ id: 't1', text: 'one' }] })
|
|
86
|
+
.expect(200);
|
|
87
|
+
|
|
88
|
+
expect(received.todos).toEqual([{ id: 't1', text: 'one' }]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('accepts a note create with a JSON body', async () => {
|
|
92
|
+
const { app, received } = createApp();
|
|
93
|
+
|
|
94
|
+
const res = await request(app)
|
|
95
|
+
.post(`${BASE}/notes`)
|
|
96
|
+
.send({ body: 'hello', source: 'selection', origin: { sessionId: 'ses_1' } })
|
|
97
|
+
.expect(201);
|
|
98
|
+
|
|
99
|
+
expect(received.note.body).toBe('hello');
|
|
100
|
+
expect(received.note.source).toBe('selection');
|
|
101
|
+
expect(res.body.note.id).toBe('n1');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('accepts a note pin patch with a JSON body', async () => {
|
|
105
|
+
const { app, received } = createApp();
|
|
106
|
+
|
|
107
|
+
const res = await request(app)
|
|
108
|
+
.patch(`${BASE}/notes/n1`)
|
|
109
|
+
.send({ pinned: true })
|
|
110
|
+
.expect(200);
|
|
111
|
+
|
|
112
|
+
expect(received.notePatch).toEqual({ pinned: true });
|
|
113
|
+
expect(res.body.note.pinned).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('accepts a note body patch with a JSON body', async () => {
|
|
117
|
+
const { app, received } = createApp();
|
|
118
|
+
|
|
119
|
+
await request(app)
|
|
120
|
+
.patch(`${BASE}/notes/n1`)
|
|
121
|
+
.send({ body: 'edited' })
|
|
122
|
+
.expect(200);
|
|
123
|
+
|
|
124
|
+
expect(received.notePatch).toEqual({ body: 'edited' });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('accepts a plan pin patch with a JSON body', async () => {
|
|
128
|
+
const { app } = createApp();
|
|
129
|
+
|
|
130
|
+
const res = await request(app)
|
|
131
|
+
.patch(`${BASE}/plans/p1`)
|
|
132
|
+
.send({ pinned: true })
|
|
133
|
+
.expect(200);
|
|
134
|
+
|
|
135
|
+
expect(res.body.plan.pinned).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('accepts a plan create with a JSON body', async () => {
|
|
139
|
+
const { app, received } = createApp();
|
|
140
|
+
|
|
141
|
+
await request(app)
|
|
142
|
+
.post(`${BASE}/plans`)
|
|
143
|
+
.send({ title: 'A', body: 'text' })
|
|
144
|
+
.expect(201);
|
|
145
|
+
|
|
146
|
+
expect(received.plan).toEqual({ title: 'A', body: 'text' });
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('accepts a plan save with a JSON body', async () => {
|
|
150
|
+
const { app, received } = createApp();
|
|
151
|
+
|
|
152
|
+
await request(app)
|
|
153
|
+
.put(`${BASE}/plans/p1`)
|
|
154
|
+
.send({ raw: '# A\n\nx' })
|
|
155
|
+
.expect(200);
|
|
156
|
+
|
|
157
|
+
expect(received.planRaw).toEqual({ raw: '# A\n\nx' });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('deletes a note', async () => {
|
|
161
|
+
const { app } = createApp();
|
|
162
|
+
await request(app).delete(`${BASE}/notes/n1`).expect(200);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('deletes a plan', async () => {
|
|
166
|
+
const { app } = createApp();
|
|
167
|
+
await request(app).delete(`${BASE}/plans/p1`).expect(200);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('still rejects a genuinely malformed body', async () => {
|
|
171
|
+
const { app } = createApp();
|
|
172
|
+
|
|
173
|
+
await request(app)
|
|
174
|
+
.post(`${BASE}/notes`)
|
|
175
|
+
.send({ notBody: 'nope' })
|
|
176
|
+
.expect(400);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('rejects malformed todo shapes', async () => {
|
|
180
|
+
const { app } = createApp();
|
|
181
|
+
|
|
182
|
+
await request(app)
|
|
183
|
+
.put(`${BASE}/todos`)
|
|
184
|
+
.send({ todos: [{ id: 1, text: 'bad id type' }] })
|
|
185
|
+
.expect(400);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('rejects an unknown note source', async () => {
|
|
189
|
+
const { app } = createApp();
|
|
190
|
+
|
|
191
|
+
await request(app)
|
|
192
|
+
.post(`${BASE}/notes`)
|
|
193
|
+
.send({ body: 'hello', source: 'somewhere-else' })
|
|
194
|
+
.expect(400);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('rejects a plan pin patch without a boolean', async () => {
|
|
198
|
+
const { app } = createApp();
|
|
199
|
+
|
|
200
|
+
await request(app)
|
|
201
|
+
.patch(`${BASE}/plans/p1`)
|
|
202
|
+
.send({ pinned: 'yes' })
|
|
203
|
+
.expect(400);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('rejects a plan save without raw content', async () => {
|
|
207
|
+
const { app } = createApp();
|
|
208
|
+
|
|
209
|
+
await request(app)
|
|
210
|
+
.put(`${BASE}/plans/p1`)
|
|
211
|
+
.send({ body: 'wrong field' })
|
|
212
|
+
.expect(400);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('returns 404 for an unknown plan', async () => {
|
|
216
|
+
const { app } = createApp();
|
|
217
|
+
await request(app).get(`${BASE}/plans/nope`).expect(404);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('returns 404 when patching a note that does not exist', async () => {
|
|
221
|
+
const { app } = createApp({ updateNote: async () => null });
|
|
222
|
+
|
|
223
|
+
await request(app).patch(`${BASE}/notes/nope`).send({ body: 'x' }).expect(404);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('returns 404 when deleting a note that does not exist', async () => {
|
|
227
|
+
const { app } = createApp({ deleteNote: async () => ({ deleted: false, context: emptyContext }) });
|
|
228
|
+
|
|
229
|
+
await request(app).delete(`${BASE}/notes/nope`).expect(404);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('returns 404 when deleting a plan that does not exist', async () => {
|
|
233
|
+
const { app } = createApp({ deletePlan: async () => ({ deleted: false, context: emptyContext }) });
|
|
234
|
+
|
|
235
|
+
await request(app).delete(`${BASE}/plans/nope`).expect(404);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('returns 404 when saving a plan whose markdown is gone', async () => {
|
|
239
|
+
const { app } = createApp({ updatePlan: async () => null });
|
|
240
|
+
|
|
241
|
+
await request(app).put(`${BASE}/plans/p1`).send({ raw: '# B' }).expect(404);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('surfaces malformed stored context as a server error, not empty data', async () => {
|
|
245
|
+
const { app } = createApp({
|
|
246
|
+
readContext: async () => {
|
|
247
|
+
throw new Error('Stored project context is malformed');
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const res = await request(app).get(BASE).expect(500);
|
|
252
|
+
expect(res.body).toEqual({ error: 'Stored project context is malformed' });
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('rejects a traversal projectId as a client error', async () => {
|
|
256
|
+
const { app } = createApp({
|
|
257
|
+
readContext: async () => {
|
|
258
|
+
throw new Error('projectId contains unsupported characters');
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
await request(app).get('/api/project-context/..%2Fescape').expect(400);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenChamber project context routes: notes, todos, and plan files.
|
|
3
|
+
*
|
|
4
|
+
* These replace the shared UI's direct `/api/fs/*` access to
|
|
5
|
+
* `~/.config/openchamber/projects/*`. The client no longer resolves the home
|
|
6
|
+
* directory or composes storage paths, and plan markdown is addressed by id
|
|
7
|
+
* rather than by an absolute path supplied by the caller.
|
|
8
|
+
*
|
|
9
|
+
* Body parsing is attached per route. There is no global JSON parser: the
|
|
10
|
+
* generic OpenCode proxy needs an unread request stream, so `core-routes`
|
|
11
|
+
* parses only an explicit allowlist of path prefixes and leaves every other
|
|
12
|
+
* `/api` request untouched. A route that forgets this sees `req.body` as
|
|
13
|
+
* undefined and rejects every write as a malformed body.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import express from 'express';
|
|
17
|
+
|
|
18
|
+
const parseJsonBody = express.json({ limit: '1mb' });
|
|
19
|
+
|
|
20
|
+
const isObjectRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
21
|
+
|
|
22
|
+
const isValidationError = (error) => {
|
|
23
|
+
const message = error instanceof Error ? error.message : '';
|
|
24
|
+
return message.includes('is required') || message.includes('unsupported characters');
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const respondWithError = (res, error, fallbackMessage) => {
|
|
28
|
+
const message = error instanceof Error ? error.message : fallbackMessage;
|
|
29
|
+
if (isValidationError(error)) {
|
|
30
|
+
return res.status(400).json({ error: message });
|
|
31
|
+
}
|
|
32
|
+
return res.status(500).json({ error: message || fallbackMessage });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const isValidNoteSource = (value) => value === 'manual' || value === 'selection' || value === 'agent';
|
|
36
|
+
|
|
37
|
+
const hasValidTodosShape = (value) => (
|
|
38
|
+
Array.isArray(value)
|
|
39
|
+
&& value.every((todo) => (
|
|
40
|
+
isObjectRecord(todo)
|
|
41
|
+
&& typeof todo.id === 'string'
|
|
42
|
+
&& typeof todo.text === 'string'
|
|
43
|
+
&& (todo.completed === undefined || typeof todo.completed === 'boolean')
|
|
44
|
+
&& (todo.createdAt === undefined || (typeof todo.createdAt === 'number' && Number.isFinite(todo.createdAt)))
|
|
45
|
+
))
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const registerProjectContextRoutes = (app, dependencies) => {
|
|
49
|
+
const { projectContextRuntime } = dependencies;
|
|
50
|
+
|
|
51
|
+
app.get('/api/project-context/:projectId', async (req, res) => {
|
|
52
|
+
try {
|
|
53
|
+
return res.json(await projectContextRuntime.readContext(req.params.projectId));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return respondWithError(res, error, 'Failed to read project context');
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
app.put('/api/project-context/:projectId/todos', parseJsonBody, async (req, res) => {
|
|
60
|
+
const body = req.body;
|
|
61
|
+
if (!isObjectRecord(body)) {
|
|
62
|
+
return res.status(400).json({ error: 'Body must be an object' });
|
|
63
|
+
}
|
|
64
|
+
if (!hasValidTodosShape(body.todos)) {
|
|
65
|
+
return res.status(400).json({ error: 'todos must be an array of todo items' });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
return res.json(await projectContextRuntime.saveTodos(req.params.projectId, body.todos));
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return respondWithError(res, error, 'Failed to save project todos');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
app.post('/api/project-context/:projectId/notes', parseJsonBody, async (req, res) => {
|
|
76
|
+
const body = req.body;
|
|
77
|
+
if (!isObjectRecord(body)) {
|
|
78
|
+
return res.status(400).json({ error: 'Body must be an object' });
|
|
79
|
+
}
|
|
80
|
+
if (typeof body.body !== 'string') {
|
|
81
|
+
return res.status(400).json({ error: 'body must be a string' });
|
|
82
|
+
}
|
|
83
|
+
if (body.source !== undefined && !isValidNoteSource(body.source)) {
|
|
84
|
+
return res.status(400).json({ error: 'source must be manual, selection, or agent' });
|
|
85
|
+
}
|
|
86
|
+
if (body.origin !== undefined && !isObjectRecord(body.origin)) {
|
|
87
|
+
return res.status(400).json({ error: 'origin must be an object' });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const { note, context } = await projectContextRuntime.createNote(req.params.projectId, {
|
|
92
|
+
body: body.body,
|
|
93
|
+
source: body.source,
|
|
94
|
+
origin: body.origin,
|
|
95
|
+
});
|
|
96
|
+
return res.status(201).json({ note, context });
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return respondWithError(res, error, 'Failed to create note');
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
app.patch('/api/project-context/:projectId/notes/:noteId', parseJsonBody, async (req, res) => {
|
|
103
|
+
const body = req.body;
|
|
104
|
+
if (!isObjectRecord(body)) {
|
|
105
|
+
return res.status(400).json({ error: 'Body must be an object' });
|
|
106
|
+
}
|
|
107
|
+
if (body.body !== undefined && typeof body.body !== 'string') {
|
|
108
|
+
return res.status(400).json({ error: 'body must be a string' });
|
|
109
|
+
}
|
|
110
|
+
if (body.pinned !== undefined && typeof body.pinned !== 'boolean') {
|
|
111
|
+
return res.status(400).json({ error: 'pinned must be a boolean' });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const result = await projectContextRuntime.updateNote(req.params.projectId, req.params.noteId, {
|
|
116
|
+
...(body.body !== undefined ? { body: body.body } : {}),
|
|
117
|
+
...(body.pinned !== undefined ? { pinned: body.pinned } : {}),
|
|
118
|
+
});
|
|
119
|
+
if (!result) {
|
|
120
|
+
return res.status(404).json({ error: 'Note not found' });
|
|
121
|
+
}
|
|
122
|
+
return res.json(result);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return respondWithError(res, error, 'Failed to save note');
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
app.delete('/api/project-context/:projectId/notes/:noteId', async (req, res) => {
|
|
129
|
+
try {
|
|
130
|
+
const { deleted, context } = await projectContextRuntime.deleteNote(
|
|
131
|
+
req.params.projectId,
|
|
132
|
+
req.params.noteId,
|
|
133
|
+
);
|
|
134
|
+
if (!deleted) {
|
|
135
|
+
return res.status(404).json({ error: 'Note not found' });
|
|
136
|
+
}
|
|
137
|
+
return res.json(context);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return respondWithError(res, error, 'Failed to delete note');
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
app.patch('/api/project-context/:projectId/plans/:planId', parseJsonBody, async (req, res) => {
|
|
144
|
+
const body = req.body;
|
|
145
|
+
if (!isObjectRecord(body) || typeof body.pinned !== 'boolean') {
|
|
146
|
+
return res.status(400).json({ error: 'pinned must be a boolean' });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const result = await projectContextRuntime.setPlanPinned(
|
|
151
|
+
req.params.projectId,
|
|
152
|
+
req.params.planId,
|
|
153
|
+
body.pinned,
|
|
154
|
+
);
|
|
155
|
+
if (!result) {
|
|
156
|
+
return res.status(404).json({ error: 'Plan not found' });
|
|
157
|
+
}
|
|
158
|
+
return res.json(result);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
return respondWithError(res, error, 'Failed to update plan');
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
app.get('/api/project-context/:projectId/plans/:planId', async (req, res) => {
|
|
165
|
+
try {
|
|
166
|
+
const plan = await projectContextRuntime.readPlan(req.params.projectId, req.params.planId);
|
|
167
|
+
if (!plan) {
|
|
168
|
+
return res.status(404).json({ error: 'Plan not found' });
|
|
169
|
+
}
|
|
170
|
+
return res.json(plan);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return respondWithError(res, error, 'Failed to read plan');
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
app.put('/api/project-context/:projectId/plans/:planId', parseJsonBody, async (req, res) => {
|
|
177
|
+
const body = req.body;
|
|
178
|
+
if (!isObjectRecord(body)) {
|
|
179
|
+
return res.status(400).json({ error: 'Body must be an object' });
|
|
180
|
+
}
|
|
181
|
+
if (typeof body.raw !== 'string') {
|
|
182
|
+
return res.status(400).json({ error: 'raw must be a string' });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const result = await projectContextRuntime.updatePlan(
|
|
187
|
+
req.params.projectId,
|
|
188
|
+
req.params.planId,
|
|
189
|
+
{ raw: body.raw },
|
|
190
|
+
);
|
|
191
|
+
if (!result) {
|
|
192
|
+
return res.status(404).json({ error: 'Plan not found' });
|
|
193
|
+
}
|
|
194
|
+
return res.json(result);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return respondWithError(res, error, 'Failed to save plan');
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
app.post('/api/project-context/:projectId/plans', parseJsonBody, async (req, res) => {
|
|
201
|
+
const body = req.body;
|
|
202
|
+
if (!isObjectRecord(body)) {
|
|
203
|
+
return res.status(400).json({ error: 'Body must be an object' });
|
|
204
|
+
}
|
|
205
|
+
if (typeof body.body !== 'string') {
|
|
206
|
+
return res.status(400).json({ error: 'body must be a string' });
|
|
207
|
+
}
|
|
208
|
+
if (body.title !== undefined && typeof body.title !== 'string') {
|
|
209
|
+
return res.status(400).json({ error: 'title must be a string' });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
const { plan, context } = await projectContextRuntime.createPlan(req.params.projectId, {
|
|
214
|
+
title: body.title ?? '',
|
|
215
|
+
body: body.body,
|
|
216
|
+
});
|
|
217
|
+
return res.status(201).json({ plan, context });
|
|
218
|
+
} catch (error) {
|
|
219
|
+
return respondWithError(res, error, 'Failed to create plan');
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
app.delete('/api/project-context/:projectId/plans/:planId', async (req, res) => {
|
|
224
|
+
try {
|
|
225
|
+
const { deleted, context } = await projectContextRuntime.deletePlan(
|
|
226
|
+
req.params.projectId,
|
|
227
|
+
req.params.planId,
|
|
228
|
+
);
|
|
229
|
+
if (!deleted) {
|
|
230
|
+
return res.status(404).json({ error: 'Plan not found' });
|
|
231
|
+
}
|
|
232
|
+
return res.json(context);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
return respondWithError(res, error, 'Failed to delete plan');
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|