@openchamber/web 2.3.2 → 2.3.3

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.
Files changed (213) hide show
  1. package/dist/assets/{AboutDialog-MZbHWRua.js → AboutDialog-Ctk2zvrv.js} +1 -1
  2. package/dist/assets/{ArchiveView-CkeSWPcI.js → ArchiveView-sbNreasJ.js} +1 -1
  3. package/dist/assets/{CommandPalette-CtKzNzwW.js → CommandPalette-BICwnwAZ.js} +2 -2
  4. package/dist/assets/{DiffView-DaXjHTAq.js → DiffView-B5yeuxv8.js} +1 -1
  5. package/dist/assets/{FilesView-DMNYEydF.js → FilesView-ni2zfAwL.js} +7 -7
  6. package/dist/assets/{GitView-HXttTpUw.js → GitView-C0QgeC9O.js} +3 -3
  7. package/dist/assets/{GuestSurfacePane-KzguENQG.js → GuestSurfacePane-D1gLktSj.js} +1 -1
  8. package/dist/assets/{HelpDialog-9YZGhBgT.js → HelpDialog-CxC6qTaS.js} +1 -1
  9. package/dist/assets/{InProgressOperationBanner-DzGIwGH2.js → InProgressOperationBanner-JFV70YFh.js} +1 -1
  10. package/dist/assets/{JsonTreeView-D9rP8jM8.js → JsonTreeView-RsbV4Usa.js} +1 -1
  11. package/dist/assets/MarkdownRendererImpl-CZK5DoOX.js +1 -0
  12. package/dist/assets/{MemoryDebugPanel-Ct0h3RWh.js → MemoryDebugPanel-caUWOKiz.js} +1 -1
  13. package/dist/assets/{OnboardingScreen-B5Zzb1Mp.js → OnboardingScreen-BDT-J2JP.js} +1 -1
  14. package/dist/assets/{OpenCodeStatusDialog-CXBWWRh8.js → OpenCodeStatusDialog-Cxa2yqOB.js} +1 -1
  15. package/dist/assets/{PatchDiff-DhDAQ5em.js → PatchDiff-C1pnbAsJ.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-DPa08AmN.js → PierreDiffViewer-D0zX2Msu.js} +1 -1
  17. package/dist/assets/PlanView-BxRCMuGe.js +5 -0
  18. package/dist/assets/{ProjectActionsDialog-DATu0aBc.js → ProjectActionsDialog-D660By4K.js} +1 -1
  19. package/dist/assets/{RunOverview-D6xy_vME.js → RunOverview-C1uTMnQS.js} +2 -2
  20. package/dist/assets/{ScheduledTasksDialog-BWXVnfrf.js → ScheduledTasksDialog-S-gAgo7Z.js} +5 -5
  21. package/dist/assets/SettingsView-CVpfbdob.js +30 -0
  22. package/dist/assets/{SettingsWindow-Cx6TrtY0.js → SettingsWindow-Dd1hHvgh.js} +1 -1
  23. package/dist/assets/SourceBoardView-DbGWAxtS.js +1 -0
  24. package/dist/assets/SpaceAccessDialog-muTSsEJ9.js +1 -0
  25. package/dist/assets/{SpaceApplyDialog-BtuwtlaG.js → SpaceApplyDialog-Dsf6MNGm.js} +1 -1
  26. package/dist/assets/{SpaceRow-MXqvd-dr.js → SpaceRow-7Z6ebRtm.js} +1 -1
  27. package/dist/assets/{SpaceSetupOutput-Uo5LS7Jy.js → SpaceSetupOutput-BytPfCOC.js} +1 -1
  28. package/dist/assets/{SpacesView-DvoOh4sM.js → SpacesView-CYCrlp0D.js} +1 -1
  29. package/dist/assets/{SubmoduleDiffSummary-CyMwDeoP.js → SubmoduleDiffSummary-VrNUbIqF.js} +1 -1
  30. package/dist/assets/{ToolOutputDialog-BaUZIVzc.js → ToolOutputDialog-DHORjBND.js} +7 -7
  31. package/dist/assets/{ToolPartDiffPreview-DmMwdcF4.js → ToolPartDiffPreview-BLAXe7C5.js} +1 -1
  32. package/dist/assets/{UsageStatsView-D7WrDBTC.js → UsageStatsView-BxtYEAa0.js} +1 -1
  33. package/dist/assets/{Virtualizer-CnU8pYMb.js → Virtualizer-Bl4Cf-H-.js} +1 -1
  34. package/dist/assets/{WalkthroughView-r0Ho9F4Z.js → WalkthroughView-B2BJJ4u5.js} +2 -2
  35. package/dist/assets/{WorktreesView-C-t7uxq1.js → WorktreesView-Dv0AO9dF.js} +1 -1
  36. package/dist/assets/{appThemeRegistry-BUY7Ge9i.js → appThemeRegistry-xm_W0svA.js} +1 -1
  37. package/dist/assets/{ar-HauNhDvN.js → ar-Cj8UF12m.js} +4 -4
  38. package/dist/assets/{computeVirtualFileMetrics-CUof18z3.js → computeVirtualFileMetrics-Cx05cmWI.js} +2 -2
  39. package/dist/assets/{de-fEoJ_Yyp.js → de-fSQ1ho01.js} +4 -4
  40. package/dist/assets/{decorate-BkTSGAlD.js → decorate-jpF7GA6t.js} +2 -2
  41. package/dist/assets/{es-CKNTBsZW.js → es-DrdzhSlK.js} +5 -5
  42. package/dist/assets/{fileContentPoller-BJWgy1fX.js → fileContentPoller-C0f20jNG.js} +3 -3
  43. package/dist/assets/{flexokiTheme-BArobfXV.js → flexokiTheme-DKNCYSqL.js} +1 -1
  44. package/dist/assets/{fr-C23655Pi.js → fr-Cmz6Da4q.js} +4 -4
  45. package/dist/assets/{he-CphXS_Fv.js → he-COJRUNy4.js} +4 -4
  46. package/dist/assets/{index-B27cSA9V.js → index-C8Mw8uvl.js} +1 -1
  47. package/dist/assets/{initializeSharedPreferences-CucsmDMw.js → initializeSharedPreferences-U9-v9mfq.js} +1 -1
  48. package/dist/assets/{isDiffPlainText-DSCjvV0m.js → isDiffPlainText-DW43IghW.js} +1 -1
  49. package/dist/assets/{isFilePlainText-C7g4UPox.js → isFilePlainText-Duq5CiuG.js} +1 -1
  50. package/dist/assets/{ja-BmsU2iQe.js → ja-Ce0NvDHZ.js} +4 -4
  51. package/dist/assets/katex-BZNCT55U.css +1 -0
  52. package/dist/assets/katex.min-EZjpSwGK.js +65 -0
  53. package/dist/assets/{ko-CxISpkje.js → ko-BGFcCLLq.js} +4 -4
  54. package/dist/assets/main-BUetg9hg.js +1048 -0
  55. package/dist/assets/{main-CGPiw9fS.js → main-Be_jmIlF.js} +2 -2
  56. package/dist/assets/markdownCore-BkTeS4gA.js +10 -0
  57. package/dist/assets/{miniChat-DVEKVYKe.js → miniChat-g1RgiLLS.js} +2 -2
  58. package/dist/assets/{mobile-Q_FVBe4I.js → mobile-DBli3U-T.js} +2 -2
  59. package/dist/assets/{moveWorkspacePath-CyZJ-2aD.js → moveWorkspacePath-CnYc96Xo.js} +1 -1
  60. package/dist/assets/{nl-jnTBQ_gU.js → nl-Cu1nxo5t.js} +4 -4
  61. package/dist/assets/{parseDiffFromFile-OHXXXyzL.js → parseDiffFromFile-DEjkjYod.js} +3 -3
  62. package/dist/assets/{patchFileDiff-BZrb6h2u.js → patchFileDiff-D__42sau.js} +5 -5
  63. package/dist/assets/{pierreDiffTint-DHf2xvyt.js → pierreDiffTint-3oatL635.js} +4 -4
  64. package/dist/assets/pl-4LdEMgWI.js +20 -0
  65. package/dist/assets/{pt-BR-BfpsFrHv.js → pt-BR-2UbEBNgC.js} +5 -5
  66. package/dist/assets/{relocateRestoredSession-DInneXVI.js → relocateRestoredSession-pkxyd_lV.js} +1 -1
  67. package/dist/assets/renderElectronMiniChatApp-D0tKJFBB.js +2 -0
  68. package/dist/assets/renderMobileApp-D6bOYHuP.js +25 -0
  69. package/dist/assets/{restartOpenCode-DwBaMPJK.js → restartOpenCode-FYqjpaWc.js} +1 -1
  70. package/dist/assets/runtimeEndpointReset-6CNNzem4.js +74 -0
  71. package/dist/assets/{scheduledTasksApi-ClJplEhR.js → scheduledTasksApi-BbnQ4W-W.js} +1 -1
  72. package/dist/assets/{selectionMarkdown-BuveYuup.js → selectionMarkdown-D8QAxC44.js} +1 -1
  73. package/dist/assets/sessionOwnership-BBuf0UCB.js +1 -0
  74. package/dist/assets/{shikiHighlight-DJAESrna.js → shikiHighlight-CweIj1cL.js} +1 -1
  75. package/dist/assets/{space-apply-DWFLwXbI.js → space-apply-CEi013sa.js} +1 -1
  76. package/dist/assets/{space-close-BYDbwdWc.js → space-close-BuStkLrZ.js} +1 -1
  77. package/dist/assets/{spaceNetwork-DHrhfbKM.js → spaceNetwork-tH2d5Mgs.js} +1 -1
  78. package/dist/assets/{textMateThemeFromAppTheme-DcAZmUlv.js → textMateThemeFromAppTheme-DLJBL6al.js} +1 -1
  79. package/dist/assets/tr-Bg0Qt-mG.js +11 -0
  80. package/dist/assets/{uk-C82aEtvs.js → uk-vcnOugr0.js} +5 -5
  81. package/dist/assets/useAppFontEffects-Cs6k0JKv.js +773 -0
  82. package/dist/assets/{useCallableModelProviders-BU_455MN.js → useCallableModelProviders-BsGEzsl2.js} +1 -1
  83. package/dist/assets/{useInlineCommentController-AuUrVz9U.js → useInlineCommentController-CVYaPzfO.js} +2 -2
  84. package/dist/assets/{useRootScrollLock-Cpk7NmBa.js → useRootScrollLock-Dov-44ov.js} +2 -2
  85. package/dist/assets/{vendor-codemirror-language-data-BYGweLoh.js → vendor-codemirror-language-data-DBekkZIx.js} +2 -2
  86. package/dist/assets/vendor-tanstack-react-virtual-Dozz-7fb.js +1 -0
  87. package/dist/assets/vendor-tanstack-virtual-core-DKBj55Em.js +1 -0
  88. package/dist/assets/{vendor-yaml-3778uTud.js → vendor-yaml-CE-D_49-.js} +1 -1
  89. package/dist/assets/{zh-CN-DEq7j9I5.js → zh-CN-C3UhwFsk.js} +5 -5
  90. package/dist/assets/{zh-TW-DgCN99T-.js → zh-TW-D0CmmMvp.js} +5 -5
  91. package/dist/index.html +3 -3
  92. package/dist/mini-chat.html +3 -3
  93. package/dist/mobile.html +3 -3
  94. package/package.json +5 -5
  95. package/server/index.js +13 -1
  96. package/server/lib/agent-memory/actions.js +22 -9
  97. package/server/lib/agent-memory/actions.test.js +57 -0
  98. package/server/lib/agent-memory/runtime.js +8 -5
  99. package/server/lib/agent-tool/DOCUMENTATION.md +17 -1
  100. package/server/lib/agent-tool/runtime.js +41 -7
  101. package/server/lib/agent-tool/runtime.test.js +11 -0
  102. package/server/lib/git/DOCUMENTATION.md +17 -5
  103. package/server/lib/git/lfs-discovery.js +7 -4
  104. package/server/lib/git/lfs-discovery.test.js +60 -0
  105. package/server/lib/git/network-operations.js +9 -3
  106. package/server/lib/git/network-operations.test.js +31 -2
  107. package/server/lib/git/service.js +72 -12
  108. package/server/lib/git/service.test.js +65 -0
  109. package/server/lib/github/DOCUMENTATION.md +1 -0
  110. package/server/lib/github/reference-search.js +49 -18
  111. package/server/lib/github/reference-search.test.js +28 -6
  112. package/server/lib/github/routes.js +87 -1
  113. package/server/lib/github/routes.mutations.test.js +38 -0
  114. package/server/lib/github/routes.test.js +1 -0
  115. package/server/lib/gitlab/DOCUMENTATION.md +4 -0
  116. package/server/lib/gitlab/client.js +23 -0
  117. package/server/lib/gitlab/client.test.js +28 -1
  118. package/server/lib/gitlab/mappers.js +9 -0
  119. package/server/lib/gitlab/resources.js +153 -4
  120. package/server/lib/gitlab/resources.test.js +107 -0
  121. package/server/lib/gitlab/routes.js +120 -1
  122. package/server/lib/gitlab/routes.test.js +59 -0
  123. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  124. package/server/lib/markdown-image-grants/routes.js +14 -2
  125. package/server/lib/markdown-image-grants/routes.test.js +23 -0
  126. package/server/lib/notifications/APNS.md +24 -23
  127. package/server/lib/notifications/DOCUMENTATION.md +2 -2
  128. package/server/lib/notifications/apns-runtime.js +8 -5
  129. package/server/lib/notifications/apns-runtime.test.js +26 -0
  130. package/server/lib/notifications/message.js +5 -3
  131. package/server/lib/notifications/message.test.js +9 -0
  132. package/server/lib/notifications/runtime.js +44 -9
  133. package/server/lib/notifications/trigger-runtime.test.js +84 -0
  134. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
  135. package/server/lib/openchamber-control/actions.js +18 -2
  136. package/server/lib/openchamber-control/project-knowledge.js +17 -3
  137. package/server/lib/openchamber-control/project-knowledge.test.js +14 -0
  138. package/server/lib/openchamber-control/render-page.js +58 -0
  139. package/server/lib/openchamber-control/service.js +9 -0
  140. package/server/lib/openchamber-control/service.test.js +43 -0
  141. package/server/lib/openchamber-sessions/routes.js +1 -0
  142. package/server/lib/openchamber-sessions/worktree-move.js +26 -10
  143. package/server/lib/openchamber-sessions/worktree-move.test.js +36 -0
  144. package/server/lib/opencode/DOCUMENTATION.md +1 -1
  145. package/server/lib/opencode/managed-config-file.js +3 -2
  146. package/server/lib/opencode/managed-config-file.test.js +20 -6
  147. package/server/lib/opencode/settings-helpers.js +3 -0
  148. package/server/lib/opencode/settings-helpers.test.js +1 -1
  149. package/server/lib/opencode/settings-registry.json +3 -0
  150. package/server/lib/opencode/settings-runtime.js +1 -0
  151. package/server/lib/project-context/DOCUMENTATION.md +25 -1
  152. package/server/lib/project-context/plan-progress.js +69 -0
  153. package/server/lib/project-context/plan-progress.test.js +58 -0
  154. package/server/lib/project-context/routes.http.test.js +22 -0
  155. package/server/lib/project-context/routes.js +20 -0
  156. package/server/lib/project-context/runtime.js +132 -18
  157. package/server/lib/project-context/runtime.test.js +58 -0
  158. package/server/lib/provider-read-cache/index.js +7 -1
  159. package/server/lib/provider-read-cache/index.test.js +12 -0
  160. package/server/lib/relay/DOCUMENTATION.md +17 -1
  161. package/server/lib/session-knowledge/DOCUMENTATION.md +17 -0
  162. package/server/lib/session-knowledge/runtime.js +29 -6
  163. package/server/lib/session-knowledge/runtime.test.js +26 -1
  164. package/server/lib/source-control/audit-storage.js +1 -0
  165. package/server/lib/source-control/mutation-storage.js +3 -0
  166. package/server/lib/spaces/DOCUMENTATION.md +14 -9
  167. package/server/lib/spaces/code-out.js +13 -4
  168. package/server/lib/spaces/code-out.test.js +5 -3
  169. package/server/lib/spaces/dispatcher.js +12 -5
  170. package/server/lib/spaces/dispatcher.test.js +19 -1
  171. package/server/lib/spaces/gatekeeper-channel.js +8 -7
  172. package/server/lib/spaces/gatekeeper-channel.test.js +10 -0
  173. package/server/lib/spaces/gatekeeper-program.cjs +38 -3
  174. package/server/lib/spaces/gatekeeper-program.test.js +20 -0
  175. package/server/lib/spaces/hardening.js +14 -1
  176. package/server/lib/spaces/hardening.test.js +5 -0
  177. package/server/lib/spaces/host-providers.js +165 -0
  178. package/server/lib/spaces/host-providers.test.js +100 -0
  179. package/server/lib/spaces/host.js +16 -4
  180. package/server/lib/spaces/journey.js +87 -17
  181. package/server/lib/spaces/journey.test.js +90 -2
  182. package/server/lib/spaces/layout.js +15 -5
  183. package/server/lib/spaces/places/docker-live-support.js +2 -0
  184. package/server/lib/spaces/places/docker.test.js +2 -0
  185. package/server/lib/spaces/places/fake-docker.js +3 -0
  186. package/server/lib/spaces/places/grants.docker.live.test.js +71 -7
  187. package/server/lib/spaces/routes.js +9 -0
  188. package/server/lib/spaces/routes.test.js +4 -2
  189. package/server/lib/spaces/space-opencode.js +31 -14
  190. package/server/lib/spaces/space-opencode.test.js +15 -2
  191. package/server/lib/spaces/space-records.js +8 -0
  192. package/server/lib/spaces/space-records.test.js +7 -3
  193. package/server/lib/spaces/websocket.test.js +13 -1
  194. package/server/lib/ui-auth/ui-auth.js +28 -3
  195. package/server/lib/ui-auth/ui-auth.test.js +31 -0
  196. package/dist/assets/MarkdownRendererImpl-B2LsA09C.js +0 -1
  197. package/dist/assets/PlanView-Dt5EN_JK.js +0 -5
  198. package/dist/assets/SettingsView-BolP_tuu.js +0 -30
  199. package/dist/assets/SourceBoardView-yca1qvgB.js +0 -1
  200. package/dist/assets/SpaceAccessDialog-CZ-u75py.js +0 -1
  201. package/dist/assets/katex-rNcbfUj4.css +0 -1
  202. package/dist/assets/katex.min-DQ8qF6NR.js +0 -65
  203. package/dist/assets/main-CVHM3_8W.js +0 -1048
  204. package/dist/assets/markdownCore-D5ZOJXeO.js +0 -9
  205. package/dist/assets/pl-Bj-Hy0X5.js +0 -20
  206. package/dist/assets/renderElectronMiniChatApp-B_5BeSF6.js +0 -2
  207. package/dist/assets/renderMobileApp-DGEXUTk-.js +0 -25
  208. package/dist/assets/runtimeEndpointReset-CIpvn8QG.js +0 -59
  209. package/dist/assets/sessionOwnership-BZoGed9N.js +0 -1
  210. package/dist/assets/tr-qMRMBQ8r.js +0 -11
  211. package/dist/assets/useAppFontEffects-Bih1DxXi.js +0 -745
  212. package/dist/assets/vendor-tanstack-react-virtual-CvuLsk7D.js +0 -1
  213. package/dist/assets/vendor-tanstack-virtual-core-DPaNcJcT.js +0 -1
@@ -117,15 +117,19 @@ export const createSessionWorktreeMover = (dependencies) => {
117
117
  await dropStash(source, stash);
118
118
  };
119
119
 
120
- const removeCreatedWorktree = (root, worktree) => removeWorktree(root, {
120
+ // A branch that existed before the move stays; only one the move made goes with the worktree.
121
+ const removeCreatedWorktree = (root, worktree, deleteLocalBranch) => removeWorktree(root, {
121
122
  directory: worktree.path,
122
- deleteLocalBranch: true,
123
+ deleteLocalBranch,
123
124
  }, { bootstrapStore }).catch((error) => {
124
125
  warn(`Failed to remove worktree ${worktree.path} after a failed session move:`, error);
125
126
  });
126
127
 
127
128
  /**
128
- * @param {{ sessionId: string, directory: string, name: string, branchName?: string, startRef?: string }} input
129
+ * `existingBranch` checks out a branch that already exists, local or remote
130
+ * (`origin/feature`), instead of making a new one from `startRef`.
131
+ *
132
+ * @param {{ sessionId: string, directory: string, name: string, branchName?: string, startRef?: string, existingBranch?: string }} input
129
133
  */
130
134
  const move = async (input) => {
131
135
  const sessionId = asNonEmptyString(input?.sessionId);
@@ -134,13 +138,25 @@ export const createSessionWorktreeMover = (dependencies) => {
134
138
  if (!source) throw new OpenChamberControlError('The session has no directory to move from', 400);
135
139
  const name = asNonEmptyString(input?.name);
136
140
  if (!name) throw new OpenChamberControlError('worktree is required: a short folder name for the task', 400);
137
-
138
- const { root } = await resolvePrimaryWorktreeRoot(source);
139
- const startRef = asNonEmptyString(input?.startRef) || await resolveDefaultStartRef(root);
141
+ const existingBranch = asNonEmptyString(input?.existingBranch);
140
142
  const branchName = asNonEmptyString(input?.branchName);
143
+ if (existingBranch && (branchName || asNonEmptyString(input?.startRef))) {
144
+ throw new OpenChamberControlError('existingBranch checks out that branch as it is; do not combine it with branch or startRef', 400);
145
+ }
141
146
 
142
- const worktreeInput = { mode: 'new', name, startRef };
143
- if (branchName) worktreeInput.branchName = branchName;
147
+ const { root } = await resolvePrimaryWorktreeRoot(source);
148
+ let startRef = null;
149
+ let worktreeInput;
150
+ let ownsBranch = true;
151
+ if (existingBranch) {
152
+ ownsBranch = !(await getBranches(root, { remote: 'local' })).all.includes(existingBranch);
153
+ // A remote branch gets a local branch that tracks it; a local one keeps its own tracking.
154
+ worktreeInput = { mode: 'existing', name, existingBranch, setUpstream: true };
155
+ } else {
156
+ startRef = asNonEmptyString(input?.startRef) || await resolveDefaultStartRef(root);
157
+ worktreeInput = { mode: 'new', name, startRef };
158
+ if (branchName) worktreeInput.branchName = branchName;
159
+ }
144
160
 
145
161
  let worktree;
146
162
  try {
@@ -158,7 +174,7 @@ export const createSessionWorktreeMover = (dependencies) => {
158
174
  stash = await carryChanges({ source, destination: worktree.path, sessionId, name });
159
175
  await moveSession(sessionId, worktree.path);
160
176
  } catch (error) {
161
- await removeCreatedWorktree(root, worktree);
177
+ await removeCreatedWorktree(root, worktree, ownsBranch);
162
178
  const failure = asControlError(error, 'Failed to move the session into the worktree');
163
179
  const pending = stash ?? failure.stash ?? null;
164
180
  if (pending) {
@@ -184,7 +200,7 @@ export const createSessionWorktreeMover = (dependencies) => {
184
200
  sessionId,
185
201
  directory: worktree.path,
186
202
  previousDirectory: source,
187
- worktree: { name: worktree.name, branch: worktree.branch, path: worktree.path, startRef },
203
+ worktree: { name: worktree.name, branch: worktree.branch, path: worktree.path, ...(existingBranch ? { existingBranch } : { startRef }) },
188
204
  changesMoved: stash !== null,
189
205
  };
190
206
  };
@@ -90,6 +90,42 @@ describe('moving a session into a new worktree', () => {
90
90
  expect(calls.map(([step]) => step)).toEqual(['createWorktree', 'hydrateCheckout', 'waitForWorktreeReady', 'stashPush', 'moveSession']);
91
91
  });
92
92
 
93
+ it('checks out a branch that already exists, and keeps it when the move fails', async () => {
94
+ const { mover, calls } = createMover({ moveFails: true });
95
+
96
+ await expect(mover.move({ sessionId: 'ses_1', directory: SOURCE, name: 'feature', existingBranch: 'feature' })).rejects.toThrow('session not found');
97
+
98
+ expect(calls[0]).toEqual(['createWorktree', ROOT, { mode: 'existing', name: 'feature', existingBranch: 'feature', setUpstream: true }]);
99
+ expect(calls).toContainEqual(['removeWorktree', ROOT, { directory: WORKTREE.path, deleteLocalBranch: false }]);
100
+ });
101
+
102
+ it('checks out a remote branch and removes the local branch it made when the move fails', async () => {
103
+ const { mover, calls } = createMover({ moveFails: true });
104
+
105
+ await expect(mover.move({ sessionId: 'ses_1', directory: SOURCE, name: 'review', existingBranch: 'origin/review' })).rejects.toThrow('session not found');
106
+
107
+ expect(calls[0]).toEqual(['createWorktree', ROOT, { mode: 'existing', name: 'review', existingBranch: 'origin/review', setUpstream: true }]);
108
+ expect(calls).toContainEqual(['removeWorktree', ROOT, { directory: WORKTREE.path, deleteLocalBranch: true }]);
109
+ });
110
+
111
+ it('reports the branch it checked out', async () => {
112
+ const { mover } = createMover({ changes: false });
113
+
114
+ const result = await mover.move({ sessionId: 'ses_1', directory: SOURCE, name: 'feature', existingBranch: 'feature' });
115
+
116
+ expect(result.worktree).toEqual({ ...WORKTREE, existingBranch: 'feature' });
117
+ });
118
+
119
+ it('refuses an existing branch combined with a new branch or a start ref', async () => {
120
+ const { mover, calls } = createMover();
121
+
122
+ await expect(mover.move({ sessionId: 'ses_1', directory: SOURCE, name: 'feature', existingBranch: 'feature', startRef: 'main' }))
123
+ .rejects.toMatchObject({ statusCode: 400 });
124
+ await expect(mover.move({ sessionId: 'ses_1', directory: SOURCE, name: 'feature', existingBranch: 'feature', branchName: 'other' }))
125
+ .rejects.toMatchObject({ statusCode: 400 });
126
+ expect(calls).toEqual([]);
127
+ });
128
+
93
129
  it('removes the worktree and puts the changes back when they do not apply there', async () => {
94
130
  const { mover, calls, stashes } = createMover({ applyFails: true });
95
131
 
@@ -1005,7 +1005,7 @@ under a running child.
1005
1005
  a tool switched on later then reaches a process that can already call back.
1006
1006
  - `persistSettings` rewrites the file (temp + rename) whenever
1007
1007
  `agentControlToolEnabled`, `agentWebToolEnabled`, `agentMemoryToolEnabled`,
1008
- `agentKnowledgeToolEnabled`, `agentNotifyToolEnabled` or `agentToolsCodeMode` changes. Plugin directories are written before the
1008
+ `agentKnowledgeToolEnabled`, `agentNotifyToolEnabled`, `agentRenderToolEnabled` or `agentToolsCodeMode` changes. Plugin directories are written before the
1009
1009
  file names them, and a disabled plugin is removed from the list. OpenCode
1010
1010
  reloads within a couple of seconds; no restart is involved.
1011
1011
  - Fallback: when the user's own environment already sets `OPENCODE_CONFIG`,
@@ -83,14 +83,15 @@ export const createManagedConfigRuntime = ({
83
83
  const includeMemory = isAgentMemoryAvailable() && settings?.agentMemoryToolEnabled === true;
84
84
  const includeKnowledge = settings?.agentKnowledgeToolEnabled !== false;
85
85
  const includeNotify = settings?.agentNotifyToolEnabled === true;
86
+ const includeRender = settings?.agentRenderToolEnabled !== false;
86
87
  const codeMode = settings?.agentToolsCodeMode === true;
87
88
  // Read into the control tool's description, so the rewrite that follows a
88
89
  // toggle changes what the agent is told without a restart.
89
90
  const worktreeMoveWithoutAsking = settings?.agentWorktreeMoveWithoutAsking === true;
90
91
 
91
92
  const directories = [];
92
- if (agentToolRuntime && (includeControl || includeWeb || includeMemory || includeKnowledge || includeNotify)) {
93
- directories.push(await agentToolRuntime.materializePlugin({ includeControl, includeWeb, includeMemory, includeKnowledge, includeNotify, codeMode, worktreeMoveWithoutAsking }));
93
+ if (agentToolRuntime && (includeControl || includeWeb || includeMemory || includeKnowledge || includeNotify || includeRender)) {
94
+ directories.push(await agentToolRuntime.materializePlugin({ includeControl, includeWeb, includeMemory, includeKnowledge, includeNotify, includeRender, codeMode, worktreeMoveWithoutAsking }));
94
95
  }
95
96
  return directories;
96
97
  };
@@ -68,7 +68,7 @@ describe('managed OpenCode config file', () => {
68
68
 
69
69
  it('keeps the callback token in the child env while every tool is off', async () => {
70
70
  const { runtime, agentToolRuntime, readConfigFile } = await createHarness({
71
- settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentMemoryToolEnabled: false, agentKnowledgeToolEnabled: false },
71
+ settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentMemoryToolEnabled: false, agentKnowledgeToolEnabled: false, agentRenderToolEnabled: false },
72
72
  });
73
73
 
74
74
  const childEnv = await runtime.buildManagedChildEnv();
@@ -85,7 +85,7 @@ describe('managed OpenCode config file', () => {
85
85
  });
86
86
  await runtime.buildManagedChildEnv();
87
87
 
88
- current.settings = { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false };
88
+ current.settings = { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false, agentRenderToolEnabled: false };
89
89
  expect(await runtime.refreshManagedConfigFile()).toEqual({ updated: true });
90
90
 
91
91
  const { plugins } = await readConfigFile();
@@ -95,11 +95,11 @@ describe('managed OpenCode config file', () => {
95
95
 
96
96
  it('turns a tool back on without a restart', async () => {
97
97
  const { runtime, current, agentToolRuntime, readConfigFile } = await createHarness({
98
- settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false },
98
+ settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false, agentRenderToolEnabled: false },
99
99
  });
100
100
  await runtime.buildManagedChildEnv();
101
101
 
102
- current.settings = { agentControlToolEnabled: false, agentWebToolEnabled: true, agentKnowledgeToolEnabled: false };
102
+ current.settings = { agentControlToolEnabled: false, agentWebToolEnabled: true, agentKnowledgeToolEnabled: false, agentRenderToolEnabled: false };
103
103
  await runtime.refreshManagedConfigFile();
104
104
 
105
105
  expect((await readConfigFile()).plugins).toHaveLength(2);
@@ -109,6 +109,7 @@ describe('managed OpenCode config file', () => {
109
109
  includeMemory: false,
110
110
  includeKnowledge: false,
111
111
  includeNotify: false,
112
+ includeRender: false,
112
113
  codeMode: false,
113
114
  worktreeMoveWithoutAsking: false,
114
115
  });
@@ -125,9 +126,20 @@ describe('managed OpenCode config file', () => {
125
126
  expect(agentToolRuntime.materializePlugin).toHaveBeenLastCalledWith(expect.objectContaining({ includeKnowledge: false }));
126
127
  });
127
128
 
129
+ it('injects the render tool by default and leaves it out once switched off', async () => {
130
+ const { runtime, current, agentToolRuntime } = await createHarness({ settings: {} });
131
+
132
+ await runtime.buildManagedChildEnv();
133
+ expect(agentToolRuntime.materializePlugin).toHaveBeenLastCalledWith(expect.objectContaining({ includeRender: true }));
134
+
135
+ current.settings = { agentRenderToolEnabled: false };
136
+ await runtime.refreshManagedConfigFile();
137
+ expect(agentToolRuntime.materializePlugin).toHaveBeenLastCalledWith(expect.objectContaining({ includeRender: false }));
138
+ });
139
+
128
140
  it('injects the notify tool only when it is switched on', async () => {
129
141
  const { runtime, agentToolRuntime } = await createHarness({
130
- settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false, agentNotifyToolEnabled: true },
142
+ settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false, agentRenderToolEnabled: false, agentNotifyToolEnabled: true },
131
143
  });
132
144
 
133
145
  await runtime.buildManagedChildEnv();
@@ -138,6 +150,7 @@ describe('managed OpenCode config file', () => {
138
150
  includeMemory: false,
139
151
  includeKnowledge: false,
140
152
  includeNotify: true,
153
+ includeRender: false,
141
154
  codeMode: false,
142
155
  worktreeMoveWithoutAsking: false,
143
156
  });
@@ -156,6 +169,7 @@ describe('managed OpenCode config file', () => {
156
169
  includeMemory: false,
157
170
  includeKnowledge: true,
158
171
  includeNotify: false,
172
+ includeRender: true,
159
173
  codeMode: true,
160
174
  worktreeMoveWithoutAsking: false,
161
175
  });
@@ -204,7 +218,7 @@ describe('managed OpenCode config file', () => {
204
218
 
205
219
  it('ignores the memory tool while the feature is unavailable', async () => {
206
220
  const { runtime, agentToolRuntime, readConfigFile } = await createHarness({
207
- settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false, agentMemoryToolEnabled: true },
221
+ settings: { agentControlToolEnabled: false, agentWebToolEnabled: false, agentKnowledgeToolEnabled: false, agentRenderToolEnabled: false, agentMemoryToolEnabled: true },
208
222
  memoryAvailable: false,
209
223
  });
210
224
 
@@ -739,6 +739,9 @@ export const createSettingsHelpers = (dependencies) => {
739
739
  if (typeof candidate.agentNotifyToolEnabled === 'boolean') {
740
740
  result.agentNotifyToolEnabled = candidate.agentNotifyToolEnabled;
741
741
  }
742
+ if (candidate.agentRenderToolEnabled === true || candidate.agentRenderToolEnabled === false) {
743
+ result.agentRenderToolEnabled = candidate.agentRenderToolEnabled;
744
+ }
742
745
  if (typeof candidate.agentToolsCodeMode === 'boolean') {
743
746
  result.agentToolsCodeMode = candidate.agentToolsCodeMode;
744
747
  }
@@ -836,7 +836,7 @@ describe('settings registry gate', () => {
836
836
  desktopLanAccessEnabled: true, desktopKeepAwakeEnabled: true, desktopMinimizeToTrayEnabled: true, desktopMacMenuBarEnabled: true, desktopLinuxNativeFrame: true, sidebarShowChatsSection: false, sidebarShowWorkSection: false, sidebarShowPinnedSection: true, sidebarDetailedZoneRows: true,
837
837
  desktopUiPassword: 'secret', githubClientId: 'client', githubScopes: 'repo', gitlabClientId: 'gitlab-client', skillCatalogs: [{ id: 'c', label: 'C', source: 'https://x' }],
838
838
  defaultGitIdentityId: 'global', permissionAutoAccept: { sessions: { s: true }, revision: 1 }, permissionDefaultMode: 'safety', messageSearchEnabled: true, messageSearchReasoningEnabled: true,
839
- agentControlToolEnabled: true, agentWebToolEnabled: true, browserProvider: 'builtin', agentMemoryToolEnabled: true, agentKnowledgeToolEnabled: true, agentNotifyToolEnabled: true, agentToolsCodeMode: true, agentWorktreeMoveWithoutAsking: true, isolatedSpacesEnabled: true, isolatedSpacesIdleStop: { enabled: true, hours: 4 }, isolatedSpacesSshHost: 'me@box.local:2222', openCodeUpdateToastDismissedVersion: '1.0.0',
839
+ agentControlToolEnabled: true, agentWebToolEnabled: true, browserProvider: 'builtin', agentMemoryToolEnabled: true, agentKnowledgeToolEnabled: true, agentNotifyToolEnabled: true, agentRenderToolEnabled: true, agentToolsCodeMode: true, agentWorktreeMoveWithoutAsking: true, isolatedSpacesEnabled: true, isolatedSpacesIdleStop: { enabled: true, hours: 4 }, isolatedSpacesSshHost: 'me@box.local:2222', openCodeUpdateToastDismissedVersion: '1.0.0',
840
840
  autoDeleteEnabled: true, autoDeleteAfterDays: 30, sessionRetentionOnlyArchived: false, sessionRetentionAction: 'archive', mergedWorktreeCleanupEnabled: true, terminalShell: 'zsh', terminalLoginShells: ['zsh'],
841
841
  openInAppId: 'vscode', dictationEnabled: true, sttProvider: 'local', sttServerUrl: 'http://localhost:8001/v1', sttModel: 'm', sttLocalModel: 'm', sttLanguage: 'en',
842
842
  tunnelProvider: 'cloudflare', tunnelMode: 'quick', tunnelBootstrapTtlMs: 600000, tunnelSessionTtlMs: 86400000, managedLocalTunnelConfigPath: '/tmp/x',
@@ -162,6 +162,9 @@
162
162
  "agentNotifyToolEnabled": {
163
163
  "scope": "instance"
164
164
  },
165
+ "agentRenderToolEnabled": {
166
+ "scope": "instance"
167
+ },
165
168
  "agentToolsCodeMode": {
166
169
  "scope": "instance"
167
170
  },
@@ -47,6 +47,7 @@ const MANAGED_PLUGIN_SETTINGS_KEYS = new Set([
47
47
  'agentMemoryToolEnabled',
48
48
  'agentKnowledgeToolEnabled',
49
49
  'agentNotifyToolEnabled',
50
+ 'agentRenderToolEnabled',
50
51
  'agentToolsCodeMode',
51
52
  'agentWorktreeMoveWithoutAsking',
52
53
  ]);
@@ -43,7 +43,8 @@ Nothing outside this module may write `context.json` or the `plans` directory.
43
43
  "origin": { "sessionId": "", "messageId": "" }
44
44
  }],
45
45
  "todos": [{ "id": "", "text": "", "completed": false, "createdAt": 0 }],
46
- "plans": [{ "id": "", "file": "1700000000-title.md", "title": "", "createdAt": 0 }]
46
+ "plans": [{ "id": "", "file": "1700000000-title.md", "title": "", "createdAt": 0 }],
47
+ "planSessions": { "<planId>": { "sessionId": "", "linkedAt": 0 } }
47
48
  }
48
49
  ```
49
50
 
@@ -69,6 +70,28 @@ denormalized into the manifest so listing plans costs one read rather than one
69
70
  read per plan; `readPlan` returns the title parsed from the file, which wins if
70
71
  the two ever disagree.
71
72
 
73
+ ## Plan progress
74
+
75
+ A plan's progress is its `## Steps` checklist: the knowledge tool tells agents
76
+ to open every plan with one and to tick a step when it is done, and
77
+ `plan-progress.js` counts ticked and total items in that section only (later
78
+ checklists are detail). There is no separate status field to drift from the
79
+ file. Listed plans carry `progress: { done, total }`; a plan without the
80
+ section, or whose file cannot be read, carries none, and one unreadable plan
81
+ never fails the list. `knowledge.save` answers a plan saved without the
82
+ section with a `warning`, so the agent adds it in the same turn.
83
+
84
+ Agents tick steps with their own file tools, which announce nothing, so the
85
+ Plans tab re-reads the list while it is on screen. Listing therefore costs one
86
+ `stat` per plan: a file is read and parsed again only when its modification
87
+ time or size changed. Clients receive the counts, never the text.
88
+
89
+ `planSessions` records the session a plan was last sent to with Implement or
90
+ Improve (`PUT .../plans/:planId/session`), so its card leads there. It is a map
91
+ beside the manifest because a plan that only lives in the team's folder has no
92
+ link to carry it. Deleting a plan drops its entry; a `shared:` plan made
93
+ personal takes its entry to the new id.
94
+
72
95
  ## Shared plans
73
96
 
74
97
  Every `.md` file in the repository plans folder is a plan too: `.openchamber/plans`
@@ -109,6 +132,7 @@ collision gets a numeric suffix. Sharing is refused only when the checkout canno
109
132
  | DELETE | `/api/project-context/:projectId/plans/:planId` | `404` when unknown |
110
133
  | POST | `/api/project-context/:projectId/plans/:planId/share` | moves the plan into the shared folder; `400` without one, `404` when unknown |
111
134
  | POST | `/api/project-context/:projectId/plans/:planId/unshare` | moves a `shared:` plan back; `404` when unknown |
135
+ | PUT | `/api/project-context/:projectId/plans/:planId/session` | takes `{sessionId}`, the session the plan was just sent to; replaces the previous one; `404` when unknown |
112
136
 
113
137
  **Body parsing is attached per route.** This server has no global JSON parser:
114
138
  `core-routes` parses only an allowlist of `/api` path prefixes so the generic
@@ -0,0 +1,69 @@
1
+ /**
2
+ * How far a plan has got, read from its `## Steps` checklist.
3
+ *
4
+ * Plans carry their progress in the markdown itself: the knowledge tool tells
5
+ * agents to open a plan with a `## Steps` checklist and to tick a step when it
6
+ * is done. That checklist is the only record, so there is no status field to
7
+ * drift from it. Only the `## Steps` section counts: checklists further down
8
+ * (test lists, acceptance criteria) are detail, not progress.
9
+ */
10
+
11
+ const STEPS_HEADING = /^##\s+steps\s*$/i;
12
+ const SECTION_END = /^#{1,2}\s/;
13
+ const CHECKLIST_ITEM = /^\s*[-*+]\s+\[([ xX])\]\s/;
14
+
15
+ /** `{ done, total }` for a plan with a `## Steps` checklist, null otherwise. */
16
+ export const parsePlanProgress = (raw) => {
17
+ const lines = raw.replace(/\r\n?/g, '\n').split('\n');
18
+ const start = lines.findIndex((line) => STEPS_HEADING.test(line));
19
+ if (start === -1) return null;
20
+ let done = 0;
21
+ let total = 0;
22
+ for (const line of lines.slice(start + 1)) {
23
+ if (SECTION_END.test(line)) break;
24
+ const item = line.match(CHECKLIST_ITEM);
25
+ if (!item) continue;
26
+ total += 1;
27
+ if (item[1] !== ' ') done += 1;
28
+ }
29
+ return total === 0 ? null : { done, total };
30
+ };
31
+
32
+ /**
33
+ * Plan files read for the list, remembered by modification time and size.
34
+ *
35
+ * The Plans tab re-reads the list while it is open, and agents tick steps with
36
+ * their own file tools, so no write event announces it. Listing therefore
37
+ * costs one `stat` per plan, and a file is read and parsed again only when it
38
+ * changed since the last listing.
39
+ */
40
+ export const createPlanSummaryCache = ({ fsPromises, parseTitle }) => {
41
+ const entries = new Map();
42
+
43
+ /**
44
+ * `{ title, progress, mtimeMs }`, or null when the file is gone. Other read
45
+ * errors propagate; the caller decides whether one plan may fail the list.
46
+ */
47
+ const summaryOf = async (filePath) => {
48
+ let stat;
49
+ try {
50
+ stat = await fsPromises.stat(filePath);
51
+ } catch (error) {
52
+ if (error && error.code === 'ENOENT') {
53
+ entries.delete(filePath);
54
+ return null;
55
+ }
56
+ throw error;
57
+ }
58
+ const cached = entries.get(filePath);
59
+ if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
60
+ return cached.summary;
61
+ }
62
+ const raw = await fsPromises.readFile(filePath, 'utf8');
63
+ const summary = { title: parseTitle(raw), progress: parsePlanProgress(raw), mtimeMs: stat.mtimeMs };
64
+ entries.set(filePath, { mtimeMs: stat.mtimeMs, size: stat.size, summary });
65
+ return summary;
66
+ };
67
+
68
+ return { summaryOf };
69
+ };
@@ -0,0 +1,58 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import fsPromises from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+
6
+ import { createPlanSummaryCache, parsePlanProgress } from './plan-progress.js';
7
+
8
+ describe('parsePlanProgress', () => {
9
+ test('counts the ticked and open steps of the ## Steps checklist', () => {
10
+ expect(parsePlanProgress('# Plan\n\n## Steps\n- [x] one\n- [X] two\n- [ ] three\n')).toEqual({ done: 2, total: 3 });
11
+ });
12
+
13
+ test('stops at the next section, so later checklists are not progress', () => {
14
+ const raw = '# Plan\n\n## Steps\n- [x] one\n- [ ] two\n\n## Testing\n- [ ] unit\n- [ ] manual\n';
15
+ expect(parsePlanProgress(raw)).toEqual({ done: 1, total: 2 });
16
+ });
17
+
18
+ test('keeps nested headings inside the section', () => {
19
+ const raw = '## Steps\n- [x] one\n### Notes on one\ntext\n- [ ] two\n';
20
+ expect(parsePlanProgress(raw)).toEqual({ done: 1, total: 2 });
21
+ });
22
+
23
+ test('a plan without the section or without items has no progress', () => {
24
+ expect(parsePlanProgress('# Plan\n\n- [x] loose item\n')).toBeNull();
25
+ expect(parsePlanProgress('# Plan\n\n## Steps\n\nWrite them later.\n')).toBeNull();
26
+ expect(parsePlanProgress('')).toBeNull();
27
+ });
28
+
29
+ test('reads CRLF files and other list markers', () => {
30
+ expect(parsePlanProgress('## steps\r\n* [x] one\r\n+ [ ] two\r\n')).toEqual({ done: 1, total: 2 });
31
+ });
32
+ });
33
+
34
+ describe('createPlanSummaryCache', () => {
35
+ test('re-reads a file only after it changed, and forgets one that is gone', async () => {
36
+ const dir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'oc-plan-progress-'));
37
+ try {
38
+ const file = path.join(dir, 'plan.md');
39
+ await fsPromises.writeFile(file, '# Plan\n\n## Steps\n- [ ] one\n- [ ] two\n');
40
+ let reads = 0;
41
+ const counting = { stat: fsPromises.stat, readFile: (...args) => { reads += 1; return fsPromises.readFile(...args); } };
42
+ const cache = createPlanSummaryCache({ fsPromises: counting, parseTitle: () => 'Plan' });
43
+
44
+ expect((await cache.summaryOf(file)).progress).toEqual({ done: 0, total: 2 });
45
+ await cache.summaryOf(file);
46
+ expect(reads).toBe(1);
47
+
48
+ await fsPromises.writeFile(file, '# Plan\n\n## Steps\n- [x] one\n- [ ] two\n- [ ] three\n');
49
+ expect((await cache.summaryOf(file)).progress).toEqual({ done: 1, total: 3 });
50
+ expect(reads).toBe(2);
51
+
52
+ await fsPromises.rm(file);
53
+ expect(await cache.summaryOf(file)).toBeNull();
54
+ } finally {
55
+ await fsPromises.rm(dir, { recursive: true, force: true });
56
+ }
57
+ });
58
+ });
@@ -330,3 +330,25 @@ describe('project context routes over HTTP', () => {
330
330
  await request(app).get('/api/project-context/..%2Fescape').expect(400);
331
331
  });
332
332
  });
333
+
334
+ describe('plan session route', () => {
335
+ it('reads the session id from a JSON body and answers with the plan', async () => {
336
+ const seen = [];
337
+ const { app } = createApp({
338
+ setPlanSession: async (_projectId, planId, value) => {
339
+ seen.push({ planId, ...value });
340
+ return { plan: { id: planId, file: 'a.md', title: 'A', createdAt: 1, pinned: false, session: { sessionId: value.sessionId, linkedAt: 1 } }, context: emptyContext };
341
+ },
342
+ });
343
+
344
+ const res = await request(app).put(`${BASE}/plans/p1/session`).send({ sessionId: 'ses_1' }).expect(200);
345
+ expect(seen).toEqual([{ planId: 'p1', sessionId: 'ses_1' }]);
346
+ expect(res.body.plan.session.sessionId).toBe('ses_1');
347
+ });
348
+
349
+ it('rejects a body without a session id and reports an unknown plan as 404', async () => {
350
+ const { app } = createApp({ setPlanSession: async () => null });
351
+ await request(app).put(`${BASE}/plans/p1/session`).send({}).expect(400);
352
+ await request(app).put(`${BASE}/plans/nope/session`).send({ sessionId: 'ses_1' }).expect(404);
353
+ });
354
+ });
@@ -19,6 +19,7 @@ import { z } from 'zod';
19
19
 
20
20
  const parseJsonBody = express.json({ limit: '1mb' });
21
21
  const todoTextInput = z.string();
22
+ const sessionIdInput = z.string();
22
23
  const optionalTextInput = z.string().optional();
23
24
  const optionalCompletedInput = z.boolean().optional();
24
25
 
@@ -272,6 +273,25 @@ export const registerProjectContextRoutes = (app, dependencies) => {
272
273
  }
273
274
  });
274
275
 
276
+ // The session a plan was just sent to with Implement or Improve.
277
+ app.put('/api/project-context/:projectId/plans/:planId/session', parseJsonBody, async (req, res) => {
278
+ const sessionId = sessionIdInput.safeParse(isObjectRecord(req.body) ? req.body.sessionId : undefined);
279
+ if (!sessionId.success) {
280
+ return res.status(400).json({ error: 'sessionId must be a string' });
281
+ }
282
+ try {
283
+ const result = await projectContextRuntime.setPlanSession(req.params.projectId, req.params.planId, {
284
+ sessionId: sessionId.data,
285
+ });
286
+ if (!result?.plan) {
287
+ return res.status(404).json({ error: 'Plan not found' });
288
+ }
289
+ return res.json(result);
290
+ } catch (error) {
291
+ return respondWithError(res, error, 'Failed to link plan to session');
292
+ }
293
+ });
294
+
275
295
  // Moving a plan between the user's folder and the team's shared folder.
276
296
  for (const [suffix, method] of [['share', 'sharePlan'], ['unshare', 'unsharePlan']]) {
277
297
  app.post(`/api/project-context/:projectId/plans/:planId/${suffix}`, async (req, res) => {