@openchamber/web 1.18.4 → 1.20.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-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-BPECg1jS.js} +1 -1
- package/dist/assets/DiagramView-D0YNMix8.js +1 -0
- package/dist/assets/DiffView-BHWaMYCC.js +4 -0
- package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
- package/dist/assets/{GitView-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
- package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
- package/dist/assets/PlanView-Czu1KMJa.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
- package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
- package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
- package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
- package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/index-BiEgzzkg.js +1 -0
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-BbV-39jl.js} +1 -1
- package/dist/assets/ja-DQLQJL2J.js +15 -0
- package/dist/assets/ko-BeElEB4Y.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-Dpzo18z7.js +2 -0
- package/dist/assets/main-WMjtYzJs.js +921 -0
- package/dist/assets/markdownCore--tDmyI_v.js +2 -0
- package/dist/assets/miniChat-ldEghBLB.js +2 -0
- package/dist/assets/mobile-Dk-VGreF.js +2 -0
- package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
- package/dist/assets/pl-CLHt2_vV.js +15 -0
- package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
- package/dist/assets/renderMobileApp-CDfHS5rr.js +25 -0
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
- package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.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-vch3tJ4c.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-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-GMc3oR3i.js → web-components-pcwCTWjC.js} +4 -4
- package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
- package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
- package/dist/index.html +5 -4
- package/dist/mini-chat.html +4 -3
- package/dist/mobile.html +4 -3
- package/package.json +3 -5
- package/server/index.js +152 -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 +65 -0
- package/server/lib/agent-memory/project-resolution.test.js +94 -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 +432 -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/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +301 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +206 -72
- package/server/lib/git/service.test.js +222 -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 +12 -6
- 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 +16 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -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/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +26 -0
- package/server/lib/opencode/settings-helpers.test.js +57 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +83 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +160 -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 +672 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +17 -2
- 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 +85 -0
- package/server/lib/quota/providers/index.js +30 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- 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 +89 -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 +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +57 -6
- package/server/lib/small-model/index.test.js +102 -2
- package/server/lib/small-model/routes.js +4 -2
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
- package/dist/assets/DiffView-DZIoOnV7.js +0 -4
- 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/ToolOutputDialog-Za6V4VMJ.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
- 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-D7UcL3VQ.js +0 -2
- package/dist/assets/main-DPMd2iKS.js +0 -915
- package/dist/assets/markdownCore-DDrHVneM.js +0 -2
- package/dist/assets/miniChat-O_GVoEbc.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/renderMobileApp-toj9cXoh.js +0 -25
- 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/useInlineCommentController-CYPvYJDt.js +0 -2
- 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
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
|
|
3
|
+
Server-owned storage for the Project Notes surface: free-form notes, todos, and
|
|
4
|
+
plan markdown files.
|
|
5
|
+
|
|
6
|
+
The managed Chats root (`~/.config/openchamber/chats`) is also one context owner. Every dated per-session directory beneath it resolves to that root, so Notes, Todo, Plans, pinned knowledge, and project memory are shared across ordinary chats without registering Chats as a user project.
|
|
7
|
+
|
|
8
|
+
## Ownership
|
|
9
|
+
|
|
10
|
+
| Path | Owner | Contents |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| `<projectsDir>/<projectId>.json` | shared UI (`packages/ui/src/lib/openchamberConfig.ts`), plus server-owned `version` / `scheduledTasks` | worktree setup, draft starters, project actions |
|
|
13
|
+
| `<projectsDir>/<projectId>/context.json` | **this module, exclusively** | notes, todos, plan manifest |
|
|
14
|
+
| `<projectsDir>/<projectId>/plans/*.md` | **this module, exclusively** | plan bodies |
|
|
15
|
+
|
|
16
|
+
The split is the point. Both files were previously one, written by the client
|
|
17
|
+
with a whole-file read-modify-write. Adding a server writer to that file would
|
|
18
|
+
have made unrelated features (project actions, draft starters) clobber notes
|
|
19
|
+
across processes, with no lock able to span both sides. Separate files remove
|
|
20
|
+
the shared resource instead of trying to coordinate access to it.
|
|
21
|
+
|
|
22
|
+
Nothing outside this module may write `context.json` or the `plans` directory.
|
|
23
|
+
|
|
24
|
+
## Storage format
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"version": 2,
|
|
29
|
+
"notes": [{
|
|
30
|
+
"id": "", "body": "", "createdAt": 0, "updatedAt": 0,
|
|
31
|
+
"source": "manual | selection | agent",
|
|
32
|
+
"origin": { "sessionId": "", "messageId": "" }
|
|
33
|
+
}],
|
|
34
|
+
"todos": [{ "id": "", "text": "", "completed": false, "createdAt": 0 }],
|
|
35
|
+
"plans": [{ "id": "", "file": "1700000000-title.md", "title": "", "createdAt": 0 }]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Notes are entries, not one blob. Version 1 stored a single string; it converts
|
|
40
|
+
to a single `manual` note on read (an empty string converts to no notes at
|
|
41
|
+
all). The conversion lives in the read path rather than a separate migration
|
|
42
|
+
pass so that every reader — including one racing a writer — sees one shape.
|
|
43
|
+
Legacy `pinned` fields may remain in existing files but are ignored; attachment
|
|
44
|
+
ownership lives in each session's metadata.
|
|
45
|
+
|
|
46
|
+
`source` records where a note came from, and `origin` links it back to the
|
|
47
|
+
message it was distilled from, so a note taken off a chat selection can be
|
|
48
|
+
traced to its conversation.
|
|
49
|
+
|
|
50
|
+
Notes and todos are written through separate routes. That split is what stops a
|
|
51
|
+
todo toggle from persisting half-typed notes alongside it, and stops an
|
|
52
|
+
agent-authored note from clobbering a concurrent todo change.
|
|
53
|
+
|
|
54
|
+
Plan links store a **base name**, never a path. The file always lives in
|
|
55
|
+
`<projectId>/plans/`, so moving the project storage directory cannot invalidate
|
|
56
|
+
a reference and a caller can never address a file outside it. `title` is
|
|
57
|
+
denormalized into the manifest so listing plans costs one read rather than one
|
|
58
|
+
read per plan; `readPlan` returns the title parsed from the file, which wins if
|
|
59
|
+
the two ever disagree.
|
|
60
|
+
|
|
61
|
+
## Routes
|
|
62
|
+
|
|
63
|
+
| Method | Route | Notes |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| GET | `/api/project-context/:projectId` | full context; missing file is `200` empty |
|
|
66
|
+
| PUT | `/api/project-context/:projectId/todos` | replaces the whole list; returns committed context |
|
|
67
|
+
| POST | `/api/project-context/:projectId/notes` | `201`; takes `{body, source?, origin?}` |
|
|
68
|
+
| PATCH | `/api/project-context/:projectId/notes/:noteId` | patches `body`; legacy `pinned` input is ignored by session knowledge; `404` when unknown |
|
|
69
|
+
| DELETE | `/api/project-context/:projectId/notes/:noteId` | `404` when unknown |
|
|
70
|
+
| PATCH | `/api/project-context/:projectId/plans/:planId` | legacy project pin state only; session attachment uses session knowledge; `404` when unknown |
|
|
71
|
+
| GET | `/api/project-context/:projectId/plans/:planId` | `404` when the link or its markdown is gone |
|
|
72
|
+
| POST | `/api/project-context/:projectId/plans` | `201`; takes `{title, body}`, never a path |
|
|
73
|
+
| PUT | `/api/project-context/:projectId/plans/:planId` | takes the whole `{raw}` document; `404` when the link or its markdown is gone |
|
|
74
|
+
| DELETE | `/api/project-context/:projectId/plans/:planId` | `404` when unknown |
|
|
75
|
+
|
|
76
|
+
**Body parsing is attached per route.** This server has no global JSON parser:
|
|
77
|
+
`core-routes` parses only an allowlist of `/api` path prefixes so the generic
|
|
78
|
+
OpenCode proxy keeps an unread request stream, and every other `/api` request
|
|
79
|
+
passes through untouched. A write route that forgets `express.json()` therefore
|
|
80
|
+
sees `req.body` as `undefined` and rejects every request as a malformed body —
|
|
81
|
+
which is exactly how this shipped once. `routes.http.test.js` mounts the routes
|
|
82
|
+
on a bare express app so that failure mode fails the suite instead of the user.
|
|
83
|
+
|
|
84
|
+
`projectId` is validated against `/^[a-zA-Z0-9._:-]+$/`, which rejects
|
|
85
|
+
separators and traversal. Validation failures are `400`; malformed stored data
|
|
86
|
+
and I/O failures are `500`.
|
|
87
|
+
|
|
88
|
+
## Invariants
|
|
89
|
+
|
|
90
|
+
- **Missing is not malformed.** A missing `context.json` is authoritative empty
|
|
91
|
+
data. Unparseable JSON is a failure that propagates as `500`, so the client
|
|
92
|
+
preserves what it already has instead of rendering an empty panel over intact
|
|
93
|
+
data on disk.
|
|
94
|
+
- **Writes are serialized per project** through an in-process lock, and land via
|
|
95
|
+
write-to-temp + rename so a crash cannot leave a half-written file.
|
|
96
|
+
- **`readContext` never takes the lock.** Every mutator calls it while already
|
|
97
|
+
holding the lock, so locking there would deadlock. The legacy migration it can
|
|
98
|
+
trigger is safe unlocked: both writes are atomic renames of identical content.
|
|
99
|
+
- **Plan create writes markdown before the manifest entry**; delete removes the
|
|
100
|
+
manifest entry before the file. Either partial failure leaves an unreferenced
|
|
101
|
+
markdown file, which is inert. The reverse order would leave a manifest entry
|
|
102
|
+
that renders as a plan and fails to open.
|
|
103
|
+
- **Plan update takes the raw document, not title + body.** The editor owns
|
|
104
|
+
the file verbatim; reassembling it from parsed parts would rewrite the
|
|
105
|
+
heading and reformat what the user typed. The manifest title is re-derived
|
|
106
|
+
from the saved content, and the file name never changes with the title — it
|
|
107
|
+
is the stable identity behind the link.
|
|
108
|
+
- **Plan update refuses to recreate a deleted file.** If the markdown vanished
|
|
109
|
+
underneath an open editor the link is already dead; writing would resurrect
|
|
110
|
+
content the user believes was discarded, so it returns `404` instead.
|
|
111
|
+
- **A note patch touches only the fields it names.** Pinning sends `pinned`
|
|
112
|
+
alone, so it cannot roll back an edit that landed between the two requests,
|
|
113
|
+
and editing does not reset a pin. Editing bumps `updatedAt`; pinning does not,
|
|
114
|
+
because a pin is not a change to what the note says.
|
|
115
|
+
- **A note body can be clamped but never blanked.** An empty body is rejected
|
|
116
|
+
rather than stored, since a note with nothing in it is indistinguishable from
|
|
117
|
+
a delete the user did not ask for.
|
|
118
|
+
- **Notes are capped at 200 per project.** Past that, creation fails loudly
|
|
119
|
+
instead of silently evicting the oldest entry.
|
|
120
|
+
- **Per-entry sanitization never fails the whole read.** A malformed todo or
|
|
121
|
+
plan link is dropped; the rest of the context still loads.
|
|
122
|
+
|
|
123
|
+
## Legacy migration
|
|
124
|
+
|
|
125
|
+
`projectNotes`, `projectTodos`, and `projectPlanFiles` originally lived in
|
|
126
|
+
`<projectId>.json`. On the first read with no `context.json`, those three keys
|
|
127
|
+
are moved out and deleted from the client-owned file; every other key is
|
|
128
|
+
preserved untouched.
|
|
129
|
+
|
|
130
|
+
Plan links carried absolute paths. Migration converts each to a base name. A
|
|
131
|
+
file already in the plans directory is used in place; one referenced from
|
|
132
|
+
elsewhere — a stale path left by an earlier project id — is copied in rather
|
|
133
|
+
than dropped. A link whose markdown cannot be found at all is discarded, since
|
|
134
|
+
it could not have been opened either way.
|
|
135
|
+
|
|
136
|
+
The legacy keys are removed only after `context.json` is durably written, so any
|
|
137
|
+
failure simply leaves the migration to run again on the next read. Repeat and
|
|
138
|
+
concurrent reads converge on identical content.
|
|
139
|
+
|
|
140
|
+
## Cross-module contract
|
|
141
|
+
|
|
142
|
+
`packages/web/server/lib/opencode/settings-runtime.js` merges project storage
|
|
143
|
+
when a project id changes. Its `mergeProjectContextFiles` step must run before
|
|
144
|
+
`moveDirectoryContents`, because that mover only renames into a free
|
|
145
|
+
destination and would otherwise discard the old `context.json` whenever the
|
|
146
|
+
destination already had one.
|
|
147
|
+
|
|
148
|
+
`mergeProjectContextFiles` merges every list by identity and deliberately does
|
|
149
|
+
not convert a version 1 string note: this module owns that conversion, and
|
|
150
|
+
doing it in two places would mean two definitions of the same migration.
|
|
151
|
+
|
|
152
|
+
`mergeProjectConfigData` still merges the legacy `projectNotes` /
|
|
153
|
+
`projectTodos` / `projectPlanFiles` keys. That is deliberate: a project whose
|
|
154
|
+
context has not been migrated yet keeps its data in `<projectId>.json`, and the
|
|
155
|
+
migration picks it up from the merged destination afterwards.
|
|
156
|
+
|
|
157
|
+
## Tests
|
|
158
|
+
|
|
159
|
+
- `runtime.test.js` — storage, sanitization, migration, locking, plan lifecycle.
|
|
160
|
+
- `routes.test.js` — status-code mapping, payload validation, failure surfacing.
|
|
@@ -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
|
+
};
|