@loicngr/kobo 1.6.14 → 1.7.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.
Files changed (200) hide show
  1. package/README.md +4 -3
  2. package/dist/mcp-server/kobo-tasks-server.js +51 -0
  3. package/dist/server/db/migrations.js +40 -0
  4. package/dist/server/db/schema.js +7 -5
  5. package/dist/server/index.js +12 -11
  6. package/dist/server/routes/workspaces.js +207 -26
  7. package/dist/server/services/agent/engines/claude-code/capabilities.js +1 -1
  8. package/dist/server/services/agent/engines/claude-code/engine.js +237 -132
  9. package/dist/server/services/agent/engines/claude-code/event-mapper.js +234 -0
  10. package/dist/server/services/agent/engines/claude-code/options-builder.js +68 -0
  11. package/dist/server/services/agent/engines/claude-code/precompact-hook.js +27 -0
  12. package/dist/server/services/agent/engines/types.js +1 -0
  13. package/dist/server/services/agent/orchestrator.js +536 -94
  14. package/dist/server/services/agent/session-controller.js +14 -43
  15. package/dist/server/services/auto-loop-service.js +17 -6
  16. package/dist/server/services/content-migration-service.js +24 -94
  17. package/dist/server/services/usage/poller.js +4 -1
  18. package/dist/server/services/wakeup-service.js +8 -9
  19. package/dist/server/services/workspace-service.js +40 -36
  20. package/dist/server/utils/git-ops.js +67 -5
  21. package/package.json +2 -1
  22. package/src/client/dist/spa/assets/ActivityFeed-CIJPN8TH.js +7 -0
  23. package/src/client/dist/spa/assets/ActivityFeed-LXnbg3ff.css +1 -0
  24. package/src/client/dist/spa/assets/ClosePopup-DzB3mDtj.js +1 -0
  25. package/src/client/dist/spa/assets/CreatePage-BE3xfQsC.css +1 -0
  26. package/src/client/dist/spa/assets/CreatePage-U6TtJzNe.js +2 -0
  27. package/src/client/dist/spa/assets/DiffViewer-D1Sdu307.css +1 -0
  28. package/src/client/dist/spa/assets/DiffViewer-Di85TBIi.js +7 -0
  29. package/src/client/dist/spa/assets/HealthPage-B7aWFxAZ.js +1 -0
  30. package/src/client/dist/spa/assets/{MainLayout-C3TUaYvQ.js → MainLayout-BHBrz4c9.js} +17 -17
  31. package/src/client/dist/spa/assets/MainLayout-Dba6SdpU.css +1 -0
  32. package/src/client/dist/spa/assets/QCheckbox-CcY7ZSk9.js +1 -0
  33. package/src/client/dist/spa/assets/QChip-BhT0W2Dg.js +1 -0
  34. package/src/client/dist/spa/assets/QExpansionItem-VS4b4eY6.js +1 -0
  35. package/src/client/dist/spa/assets/QInput-D4WJro4e.js +1 -0
  36. package/src/client/dist/spa/assets/QMenu-CchbRXbp.js +1 -0
  37. package/src/client/dist/spa/assets/{QPage-yqdKDG7-.js → QPage-Cu7zkfc6.js} +1 -1
  38. package/src/client/dist/spa/assets/QRadio-DaZhdLCg.js +1 -0
  39. package/src/client/dist/spa/assets/QResizeObserver-Cf79V-VZ.js +1 -0
  40. package/src/client/dist/spa/assets/QScrollArea-DrVTDLU0.js +1 -0
  41. package/src/client/dist/spa/assets/QTabPanels-HXz-evuj.js +1 -0
  42. package/src/client/dist/spa/assets/QToggle-CGpiJLDJ.js +1 -0
  43. package/src/client/dist/spa/assets/QTooltip-DjJYMTkN.js +1 -0
  44. package/src/client/dist/spa/assets/SearchPage-CVm-sqxH.js +1 -0
  45. package/src/client/dist/spa/assets/SettingsPage-ayDKGo9H.js +1 -0
  46. package/src/client/dist/spa/assets/SettingsPage-wTBCvK6t.css +1 -0
  47. package/src/client/dist/spa/assets/WorkspacePage-DQxGe62K.css +1 -0
  48. package/src/client/dist/spa/assets/WorkspacePage-xaVy8s5i.js +4 -0
  49. package/src/client/dist/spa/assets/build-path-tree-CdY1A6aP.js +1 -0
  50. package/src/client/dist/spa/assets/{cssMode-wNaxOrgG.js → cssMode-BVNBMOxh.js} +1 -1
  51. package/src/client/dist/spa/assets/documents-D6A3wRry.js +1 -0
  52. package/src/client/dist/spa/assets/{editor.api-CcDntllS.js → editor.api-D6Vfp5yv.js} +1 -1
  53. package/src/client/dist/spa/assets/{editor.main-Chu4hc0J.js → editor.main-CTCYF6V4.js} +3 -3
  54. package/src/client/dist/spa/assets/{expand-template-CcQus77v.js → expand-template-vHV2iwXf.js} +1 -1
  55. package/src/client/dist/spa/assets/{formatters-CX2gvLFv.js → formatters-ejxELb0M.js} +1 -1
  56. package/src/client/dist/spa/assets/{freemarker2-CO_b202E.js → freemarker2-nmzwPmzi.js} +1 -1
  57. package/src/client/dist/spa/assets/{handlebars-CJnTWNLs.js → handlebars-CI9lR7Ef.js} +1 -1
  58. package/src/client/dist/spa/assets/{html-DeArYseI.js → html-BQ21REnv.js} +1 -1
  59. package/src/client/dist/spa/assets/{htmlMode-BnNgEgdx.js → htmlMode-io5J5Qr1.js} +1 -1
  60. package/src/client/dist/spa/assets/i18n-Do8Kn8n0.js +1 -0
  61. package/src/client/dist/spa/assets/index-C_e7KOYh.js +2 -0
  62. package/src/client/dist/spa/assets/{javascript-C0pxfNu4.js → javascript--u9PDBCv.js} +1 -1
  63. package/src/client/dist/spa/assets/{jsonMode-ety87201.js → jsonMode-DBG5llk4.js} +1 -1
  64. package/src/client/dist/spa/assets/{kobo-commands-Cpl4IFon.js → kobo-commands-DiUm1Y34.js} +1 -1
  65. package/src/client/dist/spa/assets/{liquid-kanevKvC.js → liquid-DxAS4nYF.js} +1 -1
  66. package/src/client/dist/spa/assets/marked.esm-DuOsJx63.js +60 -0
  67. package/src/client/dist/spa/assets/{mdx-DkmtbRD7.js → mdx-BNXTiODW.js} +1 -1
  68. package/src/client/dist/spa/assets/models-DNYEhFF7.js +1 -0
  69. package/src/client/dist/spa/assets/{monaco.contribution-DsZsua59.js → monaco.contribution-CT3LAK0J.js} +2 -2
  70. package/src/client/dist/spa/assets/{python-DrxH1xl7.js → python-DztNww13.js} +1 -1
  71. package/src/client/dist/spa/assets/{razor-CU4khv8N.js → razor-Cyr82NZF.js} +1 -1
  72. package/src/client/dist/spa/assets/settings-Dbx1_ksA.js +1 -0
  73. package/src/client/dist/spa/assets/symbols-BVRrMH2r.js +1 -0
  74. package/src/client/dist/spa/assets/touch-Co9pfjUU.js +1 -0
  75. package/src/client/dist/spa/assets/{tsMode-CQ5yxoz_.js → tsMode-CbQVgsIP.js} +1 -1
  76. package/src/client/dist/spa/assets/{typescript-CSwKmP7l.js → typescript-UHOe4d1S.js} +1 -1
  77. package/src/client/dist/spa/assets/use-checkbox-DzHmcu7s.js +1 -0
  78. package/src/client/dist/spa/assets/use-id-CDuXkR0Z.js +1 -0
  79. package/src/client/dist/spa/assets/use-panel-Br8QNRMk.js +1 -0
  80. package/src/client/dist/spa/assets/{xml-9bnWANPJ.js → xml-DC88eFpV.js} +1 -1
  81. package/src/client/dist/spa/assets/{yaml-sUtDJGxo.js → yaml-DSTsIRJr.js} +1 -1
  82. package/src/client/dist/spa/index.html +11 -10
  83. package/src/mcp-server/kobo-tasks-server.ts +60 -1
  84. package/dist/server/services/agent/engines/claude-code/args-builder.js +0 -57
  85. package/dist/server/services/agent/engines/claude-code/mcp-config.js +0 -23
  86. package/dist/server/services/agent/engines/claude-code/stream-parser.js +0 -386
  87. package/src/client/dist/spa/assets/ActivityFeed-Be0QQryJ.css +0 -1
  88. package/src/client/dist/spa/assets/ActivityFeed-BtIOkIy6.js +0 -8
  89. package/src/client/dist/spa/assets/ClosePopup-DkLittac.js +0 -1
  90. package/src/client/dist/spa/assets/CreatePage-D6Q3nxkX.js +0 -2
  91. package/src/client/dist/spa/assets/CreatePage-DJbZH8wp.css +0 -1
  92. package/src/client/dist/spa/assets/DiffViewer-1s165rFm.css +0 -1
  93. package/src/client/dist/spa/assets/DiffViewer-D5u9p7il.js +0 -2
  94. package/src/client/dist/spa/assets/HealthPage-Cr7aAUy6.js +0 -1
  95. package/src/client/dist/spa/assets/MainLayout-CBnSwSfy.css +0 -1
  96. package/src/client/dist/spa/assets/QChip-bl3YRhax.js +0 -1
  97. package/src/client/dist/spa/assets/QExpansionItem-CWw6ZujM.js +0 -1
  98. package/src/client/dist/spa/assets/QScrollArea-DpCqRRE0.js +0 -1
  99. package/src/client/dist/spa/assets/QSeparator-DNSiXYrN.js +0 -1
  100. package/src/client/dist/spa/assets/QSlideTransition-BQxI8l5r.js +0 -1
  101. package/src/client/dist/spa/assets/QTabPanels-C4bZGqml.js +0 -1
  102. package/src/client/dist/spa/assets/QTooltip-BIDjo2hJ.js +0 -1
  103. package/src/client/dist/spa/assets/SearchPage-CavRaij6.js +0 -1
  104. package/src/client/dist/spa/assets/SettingsPage-B8DhSZw7.css +0 -1
  105. package/src/client/dist/spa/assets/SettingsPage-C13T1l_t.js +0 -1
  106. package/src/client/dist/spa/assets/TouchPan-vsl78kxF.js +0 -1
  107. package/src/client/dist/spa/assets/WorkspacePage-BEqEuPrb.js +0 -4
  108. package/src/client/dist/spa/assets/WorkspacePage-k2pgeRoy.css +0 -1
  109. package/src/client/dist/spa/assets/build-path-tree-BeAS10oa.js +0 -1
  110. package/src/client/dist/spa/assets/documents-Cw05r3zs.js +0 -60
  111. package/src/client/dist/spa/assets/i18n-CuT4b7ns.js +0 -1
  112. package/src/client/dist/spa/assets/index-CZA4BFN5.js +0 -2
  113. package/src/client/dist/spa/assets/models-CPFeBEQS.js +0 -1
  114. package/src/client/dist/spa/assets/private.use-form-Dlb0iQZh.js +0 -1
  115. package/src/client/dist/spa/assets/scroll-CYWyxBdv.js +0 -1
  116. package/src/client/dist/spa/assets/settings-CAILUJXO.js +0 -1
  117. package/src/client/dist/spa/assets/stats-C3n1k51k.js +0 -1
  118. package/src/client/dist/spa/assets/symbols-DCYodwb2.js +0 -1
  119. package/src/client/dist/spa/assets/touch-Bj_Fr4kC.js +0 -1
  120. package/src/client/dist/spa/assets/use-checkbox-B_o-iLG2.js +0 -1
  121. package/src/client/dist/spa/assets/use-id-C93QQwrt.js +0 -1
  122. /package/src/client/dist/spa/assets/{QBadge-DqtcDv8D.js → QBadge-fsQ2AokU.js} +0 -0
  123. /package/src/client/dist/spa/assets/{QItemLabel-Codqjisk.js → QItemLabel-DWwenW2S.js} +0 -0
  124. /package/src/client/dist/spa/assets/{QItemSection-CiY_LK5Y.js → QItemSection-KFAnxzMK.js} +0 -0
  125. /package/src/client/dist/spa/assets/{QList-Bl9824vi.js → QList-NmIE6Rd9.js} +0 -0
  126. /package/src/client/dist/spa/assets/{QSpace-BNr0AftG.js → QSpace-COlmM_4F.js} +0 -0
  127. /package/src/client/dist/spa/assets/{QSpinnerDots-DEiRooBD.js → QSpinnerDots-DwtnRN2r.js} +0 -0
  128. /package/src/client/dist/spa/assets/{_plugin-vue_export-helper-r4mAJOHR.js → _plugin-vue_export-helper-B8bB5DBd.js} +0 -0
  129. /package/src/client/dist/spa/assets/{abap-Bgec7Keq.js → abap-DzK-OTGh.js} +0 -0
  130. /package/src/client/dist/spa/assets/{apex-VBlPwEoQ.js → apex-Bj60_dRt.js} +0 -0
  131. /package/src/client/dist/spa/assets/{azcli-DKqrEFBx.js → azcli-B6NwaBAZ.js} +0 -0
  132. /package/src/client/dist/spa/assets/{bat-DdgQWy_0.js → bat-bf7wXV68.js} +0 -0
  133. /package/src/client/dist/spa/assets/{bicep-CRMM43EB.js → bicep-C_bg8UgA.js} +0 -0
  134. /package/src/client/dist/spa/assets/{cameligo-UatALtML.js → cameligo-CTWw4D4B.js} +0 -0
  135. /package/src/client/dist/spa/assets/{clojure-D8JU08RA.js → clojure-CgdPoH0r.js} +0 -0
  136. /package/src/client/dist/spa/assets/{coffee-C56wu358.js → coffee-gHQfdA5M.js} +0 -0
  137. /package/src/client/dist/spa/assets/{cpp-CyZLvhJG.js → cpp-BM4Jj4aW.js} +0 -0
  138. /package/src/client/dist/spa/assets/{csharp-BJl3ixva.js → csharp-D8-bh4Cd.js} +0 -0
  139. /package/src/client/dist/spa/assets/{csp-CxEKxmO-.js → csp-CXBxRx0n.js} +0 -0
  140. /package/src/client/dist/spa/assets/{css-B0t_muXd.js → css-DKjIxrmY.js} +0 -0
  141. /package/src/client/dist/spa/assets/{cypher-D1hqiMFD.js → cypher-C5e5inIh.js} +0 -0
  142. /package/src/client/dist/spa/assets/{dart-Bz550Pyv.js → dart-BhRHHm4x.js} +0 -0
  143. /package/src/client/dist/spa/assets/{dockerfile-CIXgVAuA.js → dockerfile-DW5REF8E.js} +0 -0
  144. /package/src/client/dist/spa/assets/{ecl-D9qbvZoA.js → ecl-Bw4Hg3n_.js} +0 -0
  145. /package/src/client/dist/spa/assets/{elixir-b2M38fAy.js → elixir-DHmoBvpZ.js} +0 -0
  146. /package/src/client/dist/spa/assets/{flow9-Dq1UYMkt.js → flow9-BsFExz3v.js} +0 -0
  147. /package/src/client/dist/spa/assets/{fsharp-CFNadkg7.js → fsharp-BaeLhgfq.js} +0 -0
  148. /package/src/client/dist/spa/assets/{go-dSur1iB2.js → go-Bd-NFKIC.js} +0 -0
  149. /package/src/client/dist/spa/assets/{graphql-qyhAo11d.js → graphql-DZVerJfy.js} +0 -0
  150. /package/src/client/dist/spa/assets/{hcl-DFzjMyzm.js → hcl-CAVzrZfH.js} +0 -0
  151. /package/src/client/dist/spa/assets/{ini-TdzA8TIl.js → ini-CyXdX58t.js} +0 -0
  152. /package/src/client/dist/spa/assets/{is-DUKatk8N.js → is-BbsvEMaT.js} +0 -0
  153. /package/src/client/dist/spa/assets/{java-CSGA9pkE.js → java-B5pNgvhy.js} +0 -0
  154. /package/src/client/dist/spa/assets/{julia-9izz5OsY.js → julia-XRhmV3AN.js} +0 -0
  155. /package/src/client/dist/spa/assets/{kotlin-DuPK7AtF.js → kotlin-DOd3J5vr.js} +0 -0
  156. /package/src/client/dist/spa/assets/{less-B8d93iCg.js → less-veZSnyw6.js} +0 -0
  157. /package/src/client/dist/spa/assets/{lexon-DWtEIyu7.js → lexon-QWGkuK0H.js} +0 -0
  158. /package/src/client/dist/spa/assets/{lua-Ciq0OGgt.js → lua-CYGpjuO5.js} +0 -0
  159. /package/src/client/dist/spa/assets/{m3-Cki6JWj_.js → m3-yNnrZkdc.js} +0 -0
  160. /package/src/client/dist/spa/assets/{markdown-Cu47xwU0.js → markdown-BCSWEPSX.js} +0 -0
  161. /package/src/client/dist/spa/assets/{mips-BM8ui995.js → mips-OpYmcC30.js} +0 -0
  162. /package/src/client/dist/spa/assets/{msdax-DqLio0_c.js → msdax-2oxoTO9Z.js} +0 -0
  163. /package/src/client/dist/spa/assets/{mysql-v1wbjJOq.js → mysql-5KlC-K_9.js} +0 -0
  164. /package/src/client/dist/spa/assets/{objective-c-CQl3PGSB.js → objective-c-CcDCgtLx.js} +0 -0
  165. /package/src/client/dist/spa/assets/{pascal-D4iW0ZtD.js → pascal-BZGsbaEV.js} +0 -0
  166. /package/src/client/dist/spa/assets/{pascaligo-BdC9CZdj.js → pascaligo-DtD5qU3G.js} +0 -0
  167. /package/src/client/dist/spa/assets/{perl-BL10m4XD.js → perl-C1jNNS3E.js} +0 -0
  168. /package/src/client/dist/spa/assets/{pgsql-Be_oqVo3.js → pgsql-CT0fhiZa.js} +0 -0
  169. /package/src/client/dist/spa/assets/{php-BtvXSFRI.js → php-D6DrXoPM.js} +0 -0
  170. /package/src/client/dist/spa/assets/{pla-B2vUy15C.js → pla-b3-HN2pF.js} +0 -0
  171. /package/src/client/dist/spa/assets/{postiats-CbmTTfXr.js → postiats-Bin2ApVS.js} +0 -0
  172. /package/src/client/dist/spa/assets/{powerquery-DszLhJGx.js → powerquery-7ASnn-ZG.js} +0 -0
  173. /package/src/client/dist/spa/assets/{powershell-B0dYktF6.js → powershell-t4p7sU1H.js} +0 -0
  174. /package/src/client/dist/spa/assets/{protobuf-CZvaj1VX.js → protobuf-BUGeWa_j.js} +0 -0
  175. /package/src/client/dist/spa/assets/{pug-CPDx1B3S.js → pug-BuKcgC9s.js} +0 -0
  176. /package/src/client/dist/spa/assets/{qsharp-CDP9TFLl.js → qsharp-DSMtI_O7.js} +0 -0
  177. /package/src/client/dist/spa/assets/{r-8DbbFX2l.js → r-DMlFgn7A.js} +0 -0
  178. /package/src/client/dist/spa/assets/{redis-DRWj9MtJ.js → redis-cXItkC5u.js} +0 -0
  179. /package/src/client/dist/spa/assets/{redshift-C6cElE_5.js → redshift-BZVbW7HE.js} +0 -0
  180. /package/src/client/dist/spa/assets/{restructuredtext-W9pS9n3m.js → restructuredtext-BzjxwS8h.js} +0 -0
  181. /package/src/client/dist/spa/assets/{ruby-BKnzWnk-.js → ruby-C5nyLV4l.js} +0 -0
  182. /package/src/client/dist/spa/assets/{rust-YPCclWwe.js → rust-BcmMsHdf.js} +0 -0
  183. /package/src/client/dist/spa/assets/{sb-BgM4DTFb.js → sb-Dnb1iy6B.js} +0 -0
  184. /package/src/client/dist/spa/assets/{scala-fz1OPLMl.js → scala-anMIFYpA.js} +0 -0
  185. /package/src/client/dist/spa/assets/{scheme-8Uz1RIbu.js → scheme-BItQTe08.js} +0 -0
  186. /package/src/client/dist/spa/assets/{scss-Djo3IYXr.js → scss-BOv51BJ5.js} +0 -0
  187. /package/src/client/dist/spa/assets/{shell-CINF5Tx_.js → shell-BsRYRTNN.js} +0 -0
  188. /package/src/client/dist/spa/assets/{solidity-GgiNEuUm.js → solidity-BtuLgGDx.js} +0 -0
  189. /package/src/client/dist/spa/assets/{sophia-Culj97P9.js → sophia-B0Vkc5MF.js} +0 -0
  190. /package/src/client/dist/spa/assets/{sparql-C2ZlpxOY.js → sparql-B7lvkZQM.js} +0 -0
  191. /package/src/client/dist/spa/assets/{sql-BEf5Pg7Y.js → sql-DvP5MpA3.js} +0 -0
  192. /package/src/client/dist/spa/assets/{st-CT6UUoeH.js → st-GVUeyB3U.js} +0 -0
  193. /package/src/client/dist/spa/assets/{swift-B5g0xTG3.js → swift-DSPIoCjm.js} +0 -0
  194. /package/src/client/dist/spa/assets/{systemverilog-CEgQz9DR.js → systemverilog-Icj2-k23.js} +0 -0
  195. /package/src/client/dist/spa/assets/{tcl-D0qL2L0I.js → tcl-Cd8KQcm-.js} +0 -0
  196. /package/src/client/dist/spa/assets/{twig-BFUAVf1E.js → twig-CBHmt8z3.js} +0 -0
  197. /package/src/client/dist/spa/assets/{typespec-CjVVcNKm.js → typespec-Ckc037mq.js} +0 -0
  198. /package/src/client/dist/spa/assets/{vb-CZJr-DQz.js → vb-B97GW9Wb.js} +0 -0
  199. /package/src/client/dist/spa/assets/{vue-i18n-BJlZEYnA.js → vue-i18n-eUDnMrPl.js} +0 -0
  200. /package/src/client/dist/spa/assets/{wgsl-ivoXUo2e.js → wgsl-DIKmb3YH.js} +0 -0
@@ -1,11 +1,13 @@
1
- import { getWorkspace, listTasks } from '../workspace-service.js';
2
1
  export class SessionController {
3
2
  workspaceId;
4
3
  agentSessionId;
5
4
  engine;
6
5
  onEvent;
7
- engineProcess;
6
+ _engineProcess;
8
7
  _status = 'running';
8
+ get engineProcess() {
9
+ return this._engineProcess;
10
+ }
9
11
  constructor(workspaceId, agentSessionId, engine, onEvent) {
10
12
  this.workspaceId = workspaceId;
11
13
  this.agentSessionId = agentSessionId;
@@ -13,67 +15,36 @@ export class SessionController {
13
15
  this.onEvent = onEvent;
14
16
  }
15
17
  async start(options) {
16
- if (this.engineProcess)
18
+ if (this._engineProcess)
17
19
  throw new Error('SessionController already started');
18
- this.engineProcess = await this.engine.start(options, (ev) => this.handle(ev));
20
+ this._engineProcess = await this.engine.start(options, (ev) => this.handle(ev));
19
21
  this._status = 'running';
20
22
  }
21
23
  sendMessage(content) {
22
- if (!this.engineProcess)
24
+ if (!this._engineProcess)
23
25
  throw new Error('SessionController not started');
24
- this.engineProcess.sendMessage(content);
26
+ this._engineProcess.sendMessage(content);
25
27
  }
26
28
  interrupt() {
27
- if (!this.engineProcess)
29
+ if (!this._engineProcess)
28
30
  throw new Error('SessionController not started');
29
- this.engineProcess.interrupt();
31
+ this._engineProcess.interrupt();
30
32
  }
31
33
  async stop() {
32
34
  this._status = 'stopping';
33
- if (this.engineProcess)
34
- await this.engineProcess.stop();
35
+ if (this._engineProcess)
36
+ await this._engineProcess.stop();
35
37
  }
36
38
  get status() {
37
39
  return this._status;
38
40
  }
39
41
  get pid() {
40
- return this.engineProcess?.pid;
42
+ return this._engineProcess?.pid;
41
43
  }
42
44
  get engineSessionId() {
43
- return this.engineProcess?.engineSessionId;
45
+ return this._engineProcess?.engineSessionId;
44
46
  }
45
47
  handle(ev) {
46
- if (ev.kind === 'session:compacted') {
47
- try {
48
- this.injectPostCompactReminder();
49
- }
50
- catch (err) {
51
- console.error('[session-controller] post-compact reminder failed:', err);
52
- }
53
- }
54
48
  this.onEvent(ev);
55
49
  }
56
- injectPostCompactReminder() {
57
- if (!this.engineProcess)
58
- return;
59
- const ws = getWorkspace(this.workspaceId);
60
- const tasks = listTasks(this.workspaceId);
61
- const criteria = tasks.filter((t) => t.isAcceptanceCriterion);
62
- const todos = tasks.filter((t) => !t.isAcceptanceCriterion);
63
- if (criteria.length === 0 && todos.length === 0)
64
- return;
65
- let reminder = `\n--- Context reminder after compaction ---\n`;
66
- reminder += `Task: ${ws?.name ?? this.workspaceId}\n`;
67
- if (todos.length > 0) {
68
- reminder += `\nTasks:\n${todos.map((t) => `- [${t.status === 'done' ? 'x' : ' '}] ${t.title}`).join('\n')}\n`;
69
- }
70
- if (criteria.length > 0) {
71
- reminder += `\nAcceptance criteria:\n${criteria
72
- .map((t) => `- [${t.status === 'done' ? 'x' : ' '}] ${t.title}`)
73
- .join('\n')}\n`;
74
- reminder += `\nWhen you complete a criterion, tell me which one so I can mark it as done.\n`;
75
- }
76
- reminder += `--- End of reminder ---\n`;
77
- this.engineProcess.sendMessage(reminder);
78
- }
79
50
  }
@@ -10,7 +10,7 @@ const NO_PROGRESS_STALL_THRESHOLD = 3;
10
10
  function getRow(workspaceId) {
11
11
  const db = getDb();
12
12
  const row = db
13
- .prepare(`SELECT id, project_path, working_branch, worktree_path, model, permission_mode, reasoning_effort,
13
+ .prepare(`SELECT id, project_path, working_branch, worktree_path, model, permission_mode, agent_permission_mode, reasoning_effort,
14
14
  status, auto_loop, auto_loop_ready, no_progress_streak, archived_at
15
15
  FROM workspaces WHERE id = ?`)
16
16
  .get(workspaceId);
@@ -97,6 +97,10 @@ export function onSessionEnded(workspaceId, reason, tasksDoneDelta) {
97
97
  // timer), let that timer own the next spawn so the backoff delay is respected.
98
98
  if (row.status === 'quota')
99
99
  return;
100
+ // Don't spawn a competing session while paused on canUseTool — the user
101
+ // will resume the deferred turn explicitly.
102
+ if (row.status === 'awaiting-user')
103
+ return;
100
104
  if (reason === 'error' || reason === 'killed') {
101
105
  disable(workspaceId, 'error');
102
106
  return;
@@ -219,6 +223,9 @@ function spawnNextIteration(workspaceId, opts = {}) {
219
223
  const row = getRow(workspaceId);
220
224
  if (!row)
221
225
  return;
226
+ // Same guard as onSessionEnded — never race a deferred-resume start.
227
+ if (row.status === 'awaiting-user')
228
+ return;
222
229
  const task = pickNextTask(workspaceId);
223
230
  if (!task) {
224
231
  disable(workspaceId, 'completed');
@@ -246,10 +253,14 @@ function spawnNextIteration(workspaceId, opts = {}) {
246
253
  .replaceAll('{isAcceptanceCriterion}', String(task.isAcceptanceCriterion))
247
254
  .replaceAll('{overrideBlock}', overrideBlock);
248
255
  const worktreePath = row.worktree_path ?? path.join(row.project_path, '.worktrees', row.working_branch);
249
- // Auto-loop iterations always run in auto-accept mode. Plan mode blocks MCP
250
- // tools (kobo__mark_task_done, etc.) and Edit/Write/Bash everything the
251
- // iteration needs so honoring a 'plan' setting here would deadlock the loop.
252
- const permissionMode = 'auto-accept';
256
+ // Plan mode would deadlock the loop (blocks MCP + edits) — promote to bypass.
257
+ // Other modes (bypass/strict/interactive) are honored.
258
+ const stored = (row.agent_permission_mode ?? 'bypass');
259
+ const agentPermissionMode = stored === 'plan' ? 'bypass' : stored;
260
+ if (stored === 'plan') {
261
+ console.warn(`[auto-loop-service] Promoting plan → bypass for workspace ${workspaceId} — auto-loop cannot run in plan mode`);
262
+ emitEphemeral(workspaceId, 'autoloop:permission-overridden', { from: 'plan', to: 'bypass' });
263
+ }
253
264
  // Pre-check: if the worktree directory is gone (user `rm -rf`-ed it),
254
265
  // fail loudly rather than letting startAgent throw a deep engine error.
255
266
  if (!fs.existsSync(worktreePath)) {
@@ -263,7 +274,7 @@ function spawnNextIteration(workspaceId, opts = {}) {
263
274
  let agentSessionId;
264
275
  try {
265
276
  const agent = orchestrator.startAgent(workspaceId, worktreePath, prompt, row.model, false, // resume=false — fresh context for each iteration
266
- permissionMode, undefined, row.reasoning_effort);
277
+ agentPermissionMode, undefined, row.reasoning_effort);
267
278
  agentSessionId = agent.agentSessionId;
268
279
  }
269
280
  catch (err) {
@@ -1,7 +1,3 @@
1
- import { nanoid } from 'nanoid';
2
- import { createParserState, parseClaudeLine } from './agent/engines/claude-code/stream-parser.js';
3
- import { createPreMigrationBackup } from './db-backup-service.js';
4
- import { broadcastAll } from './websocket-service.js';
5
1
  const internal = { state: 'idle', total: 0, processed: 0 };
6
2
  let isRunning = false;
7
3
  function snapshot() {
@@ -41,105 +37,39 @@ function snapshot() {
41
37
  export function getContentMigrationStatus() {
42
38
  return snapshot();
43
39
  }
44
- export async function runContentMigrationIfNeeded(db, dbPath) {
40
+ /**
41
+ * Legacy ws_events content migration.
42
+ *
43
+ * Historical context: earlier versions of Kōbō persisted Claude Code stdout as
44
+ * `agent:output` / `agent:stderr` / `agent:status` rows. The migration to the
45
+ * unified `agent:event` shape was completed in v10. As of the Claude Agent SDK
46
+ * cutover, the stream-parser used to reconstruct AgentEvents from those legacy
47
+ * rows has been removed.
48
+ *
49
+ * All production databases have been migrated. This function is now a no-op
50
+ * kept for API compatibility — it always reports `idle`. Should any rare,
51
+ * unmigrated row remain, it is left untouched in `ws_events` (and ignored by
52
+ * the new replay path which only reads `agent:event`).
53
+ */
54
+ export async function runContentMigrationIfNeeded(_db, _dbPath) {
45
55
  if (isRunning)
46
56
  return;
47
57
  isRunning = true;
48
58
  try {
49
- const row = db
50
- .prepare("SELECT COUNT(*) AS c FROM ws_events WHERE type IN ('agent:output', 'agent:stderr', 'agent:status')")
51
- .get();
52
- if (row.c === 0) {
53
- internal.state = 'idle';
54
- isRunning = false;
55
- return;
56
- }
57
- internal.state = 'backing-up';
58
- internal.startedAt = new Date().toISOString();
59
- broadcastStatus();
60
- const backup = await createPreMigrationBackup(db, dbPath, 'v10');
61
- internal.backupPath = backup.created ?? undefined;
62
- internal.state = 'running';
63
- internal.total = row.c;
64
- internal.processed = 0;
65
- broadcastStatus();
66
- await processLoop(db);
67
- internal.state = 'done';
68
- internal.finishedAt = new Date().toISOString();
69
- broadcastStatus();
70
- }
71
- catch (err) {
72
- internal.state = 'error';
73
- internal.errorMessage = err instanceof Error ? err.message : String(err);
74
- broadcastStatus();
75
- throw err;
59
+ internal.state = 'idle';
76
60
  }
77
61
  finally {
78
62
  isRunning = false;
79
63
  }
80
64
  }
81
- function broadcastStatus() {
82
- // Content-migration events are global (no workspace context) — use broadcastAll so every
83
- // connected WS client receives them regardless of their workspace subscriptions.
84
- broadcastAll(internal.state === 'error' ? 'migration:error' : 'migration:progress', getContentMigrationStatus());
85
- }
86
- async function processLoop(db) {
87
- const batchSize = 500;
88
- const selectStmt = db.prepare("SELECT id, workspace_id, type, payload, session_id, created_at FROM ws_events WHERE type IN ('agent:output', 'agent:stderr', 'agent:status') ORDER BY created_at ASC LIMIT ?");
89
- const insertStmt = db.prepare('INSERT INTO ws_events (id, workspace_id, type, payload, session_id, created_at) VALUES (?, ?, ?, ?, ?, ?)');
90
- const deleteStmt = db.prepare('DELETE FROM ws_events WHERE id = ?');
91
- while (true) {
92
- const rows = selectStmt.all(batchSize);
93
- if (rows.length === 0)
94
- break;
95
- db.transaction(() => {
96
- for (const r of rows) {
97
- const events = convertRow(r.type, r.payload, { workspaceId: r.workspace_id });
98
- for (const ev of events) {
99
- insertStmt.run(nanoid(), r.workspace_id, 'agent:event', JSON.stringify(ev), r.session_id, r.created_at);
100
- }
101
- deleteStmt.run(r.id);
102
- }
103
- })();
104
- internal.processed += rows.length;
105
- broadcastStatus();
106
- // Yield to the event loop
107
- await new Promise((resolve) => setImmediate(resolve));
108
- }
109
- }
110
- export function convertRow(type, payload, context) {
111
- if (type === 'agent:status')
112
- return []; // redundant — re-derivable from session events
113
- if (type === 'agent:stderr') {
114
- // Drop: the new engine only logs non-quota stderr via console.warn and
115
- // does not persist it. Converting legacy stderr rows to error events
116
- // would surface every historical Claude CLI warning ("no stdin data in
117
- // 3s…", debug lines) as a UI-blocking banner. Quota-bearing stderr is
118
- // handled live by the engine's backoff path, not via replay.
119
- return [];
120
- }
121
- if (type === 'agent:output') {
122
- try {
123
- const parsed = JSON.parse(payload);
124
- // The legacy payload may be either the raw Claude NDJSON already-parsed object,
125
- // or a wrapper { type: 'raw', content: '...' } for non-JSON output. Handle both.
126
- if (parsed && typeof parsed === 'object' && parsed.type === 'raw') {
127
- return [{ kind: 'message:raw', content: String(parsed.content ?? '') }];
128
- }
129
- const state = createParserState();
130
- const { events } = parseClaudeLine(JSON.stringify(parsed), state);
131
- return events;
132
- }
133
- catch {
134
- // Log enough to debug (first 200 chars of the bad payload + the owning
135
- // workspace id when the caller passed one). We intentionally do not log
136
- // the full payload to keep the console readable on noisy migrations.
137
- const preview = payload.length > 200 ? `${payload.slice(0, 200)}…` : payload;
138
- const ctx = context?.workspaceId ? ` (workspace=${context.workspaceId})` : '';
139
- console.warn(`[content-migration] Could not parse agent:output payload${ctx}, falling back to message:raw. Preview: ${preview}`);
140
- return [{ kind: 'message:raw', content: payload }];
141
- }
142
- }
65
+ /**
66
+ * Convert a legacy ws_events row into AgentEvents.
67
+ *
68
+ * The stream-parser has been removed; this function now skips every legacy
69
+ * type and returns an empty array. It is preserved as an export for API
70
+ * compatibility with old call sites and tests.
71
+ */
72
+ export function convertRow(_type, _payload, _context) {
143
73
  return [];
144
74
  }
145
75
  /** Test-only. */
@@ -1,7 +1,10 @@
1
1
  import { broadcastAll } from '../websocket-service.js';
2
2
  import { upsertUsageSnapshot } from './db.js';
3
3
  import { createClaudeCodeProvider } from './providers/claude-code.js';
4
- export const POLL_INTERVAL_MS = 60_000;
4
+ // 5 minutes the Anthropic `five_hour` / `seven_day` buckets are slow-moving
5
+ // so a tighter cadence just burns rate limit (429s) without surfacing fresher
6
+ // data to the UI. The user can still trigger a manual refresh via `refreshNow`.
7
+ export const POLL_INTERVAL_MS = 5 * 60_000;
5
8
  const DEFAULT_PROVIDERS = [createClaudeCodeProvider()];
6
9
  let providers = DEFAULT_PROVIDERS;
7
10
  let intervalHandle = null;
@@ -18,7 +18,7 @@ function rowToPending(row) {
18
18
  return { targetAt: row.target_at, reason: row.reason ?? undefined };
19
19
  }
20
20
  /** Schedule a wakeup for the given workspace. Replaces any existing pending wakeup. */
21
- export function schedule(workspaceId, delaySeconds, prompt, reason) {
21
+ export function schedule(workspaceId, delaySeconds, prompt, reason, agentSessionId) {
22
22
  try {
23
23
  const clampedSeconds = clamp(Math.floor(delaySeconds), MIN_DELAY_SECONDS, MAX_DELAY_SECONDS);
24
24
  const effectivePrompt = prompt === AUTONOMOUS_LOOP_SENTINEL ? AUTONOMOUS_LOOP_FALLBACK_PROMPT : prompt;
@@ -28,8 +28,8 @@ export function schedule(workspaceId, delaySeconds, prompt, reason) {
28
28
  clearTimeout(existing);
29
29
  const db = getDb();
30
30
  db.prepare(`INSERT OR REPLACE INTO pending_wakeups
31
- (workspace_id, target_at, prompt, reason, created_at)
32
- VALUES (?, ?, ?, ?, ?)`).run(workspaceId, targetAtIso, effectivePrompt, reason ?? null, new Date().toISOString());
31
+ (workspace_id, target_at, prompt, reason, created_at, agent_session_id)
32
+ VALUES (?, ?, ?, ?, ?, ?)`).run(workspaceId, targetAtIso, effectivePrompt, reason ?? null, new Date().toISOString(), agentSessionId ?? null);
33
33
  const timeout = setTimeout(() => fire(workspaceId), clampedSeconds * 1000);
34
34
  timeout.unref?.();
35
35
  timers.set(workspaceId, timeout);
@@ -125,7 +125,7 @@ function fire(workspaceId) {
125
125
  return;
126
126
  }
127
127
  const wsRow = db
128
- .prepare(`SELECT project_path, working_branch, worktree_path, model, permission_mode, reasoning_effort
128
+ .prepare(`SELECT project_path, working_branch, worktree_path, model, agent_permission_mode, reasoning_effort
129
129
  FROM workspaces WHERE id = ?`)
130
130
  .get(workspaceId);
131
131
  if (!wsRow) {
@@ -133,12 +133,11 @@ function fire(workspaceId) {
133
133
  return;
134
134
  }
135
135
  const worktreePath = wsRow.worktree_path ?? path.join(wsRow.project_path, '.worktrees', wsRow.working_branch);
136
- // Defensive: narrow `permission_mode` against the two known values rather
137
- // than trusting the DB column shape. Any unexpected value falls back to
138
- // the safer 'auto-accept'.
139
- const permissionMode = wsRow.permission_mode === 'plan' ? 'plan' : 'auto-accept';
136
+ // Narrow against the four known values; unknowns → 'bypass'.
137
+ const stored = wsRow.agent_permission_mode;
138
+ const agentPermissionMode = stored === 'plan' || stored === 'strict' || stored === 'interactive' ? stored : 'bypass';
140
139
  try {
141
- orchestrator.startAgent(workspaceId, worktreePath, row.prompt, wsRow.model, true, permissionMode, undefined, wsRow.reasoning_effort);
140
+ orchestrator.startAgent(workspaceId, worktreePath, row.prompt, wsRow.model, true, agentPermissionMode, row.agent_session_id ?? undefined, wsRow.reasoning_effort);
142
141
  emitEphemeral(workspaceId, 'wakeup:fired', {});
143
142
  }
144
143
  catch (err) {
@@ -6,9 +6,10 @@ import * as wakeupService from './wakeup-service.js';
6
6
  /** Allowed status transitions per current status. Enforced by updateWorkspaceStatus. */
7
7
  const VALID_TRANSITIONS = {
8
8
  created: ['extracting', 'brainstorming', 'idle', 'error'],
9
- extracting: ['extracting', 'brainstorming', 'idle', 'error'],
10
- brainstorming: ['executing', 'completed', 'idle', 'error'],
11
- executing: ['completed', 'idle', 'error', 'quota'],
9
+ extracting: ['extracting', 'brainstorming', 'idle', 'error', 'awaiting-user'],
10
+ brainstorming: ['executing', 'completed', 'idle', 'error', 'awaiting-user'],
11
+ executing: ['completed', 'idle', 'error', 'quota', 'awaiting-user'],
12
+ 'awaiting-user': ['executing', 'brainstorming', 'extracting', 'idle', 'error', 'completed', 'quota'],
12
13
  completed: ['idle', 'executing'],
13
14
  idle: ['executing', 'brainstorming', 'extracting', 'error'],
14
15
  error: ['idle', 'executing', 'brainstorming', 'extracting'],
@@ -19,6 +20,17 @@ const VALID_TRANSITIONS = {
19
20
  // is untyped, so we intentionally do not narrow here — validation against
20
21
  // `listEngines()` is expected to happen at workspace creation (see the
21
22
  // routes/engines handler) and when resolving an engine at agent-start time.
23
+ /**
24
+ * Coerce a raw `agent_permission_mode` cell into the typed union.
25
+ * Falls back to `bypass` for unknown / null values — guarantees callers
26
+ * always get a valid SDK-mappable mode regardless of legacy or corrupted rows.
27
+ */
28
+ function coerceAgentPermissionMode(raw) {
29
+ if (raw === 'plan' || raw === 'bypass' || raw === 'strict' || raw === 'interactive') {
30
+ return raw;
31
+ }
32
+ return 'bypass';
33
+ }
22
34
  function mapWorkspace(row) {
23
35
  return {
24
36
  id: row.id,
@@ -32,7 +44,7 @@ function mapWorkspace(row) {
32
44
  sentryUrl: row.sentry_url,
33
45
  model: row.model,
34
46
  reasoningEffort: row.reasoning_effort ?? 'auto',
35
- permissionMode: (row.permission_mode ?? 'auto-accept'),
47
+ agentPermissionMode: coerceAgentPermissionMode(row.agent_permission_mode),
36
48
  devServerStatus: row.dev_server_status,
37
49
  hasUnread: row.has_unread === 1,
38
50
  archivedAt: row.archived_at,
@@ -42,7 +54,6 @@ function mapWorkspace(row) {
42
54
  autoLoop: row.auto_loop === 1,
43
55
  autoLoopReady: row.auto_loop_ready === 1,
44
56
  noProgressStreak: row.no_progress_streak ?? 0,
45
- permissionProfile: (row.permission_profile ?? 'bypass'),
46
57
  worktreePath: row.worktree_path ?? '',
47
58
  worktreeOwned: row.worktree_owned === 1,
48
59
  createdAt: row.created_at,
@@ -82,13 +93,18 @@ export function createWorkspace(data) {
82
93
  const id = nanoid();
83
94
  const computedWorktreePath = data.worktreePath ?? `${data.projectPath}/.worktrees/${data.workingBranch}`;
84
95
  const owned = data.worktreeOwned ?? true;
96
+ // Mirror the unified mode into the legacy columns so older readers (in-flight
97
+ // requests during deploy, external scripts) still see a sane value.
98
+ const unifiedMode = data.agentPermissionMode ?? 'bypass';
99
+ const legacyMode = unifiedMode === 'plan' ? 'plan' : 'auto-accept';
100
+ const legacyProfile = unifiedMode === 'plan' ? 'bypass' : unifiedMode;
85
101
  db.prepare(`
86
102
  INSERT INTO workspaces (
87
103
  id, name, project_path, source_branch, working_branch, status,
88
104
  notion_url, notion_page_id, sentry_url, worktree_path, worktree_owned,
89
- model, reasoning_effort, permission_mode, engine, created_at, updated_at
90
- ) VALUES (?, ?, ?, ?, ?, 'created', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
91
- `).run(id, data.name, data.projectPath, data.sourceBranch, data.workingBranch, data.notionUrl ?? null, data.notionPageId ?? null, data.sentryUrl ?? null, computedWorktreePath, owned ? 1 : 0, data.model ?? 'claude-opus-4-7', data.reasoningEffort ?? 'auto', data.permissionMode ?? 'auto-accept', data.engine ?? 'claude-code', now, now);
105
+ model, reasoning_effort, permission_mode, permission_profile, agent_permission_mode, engine, created_at, updated_at
106
+ ) VALUES (?, ?, ?, ?, ?, 'created', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
107
+ `).run(id, data.name, data.projectPath, data.sourceBranch, data.workingBranch, data.notionUrl ?? null, data.notionPageId ?? null, data.sentryUrl ?? null, computedWorktreePath, owned ? 1 : 0, data.model ?? 'claude-opus-4-7', data.reasoningEffort ?? 'auto', legacyMode, legacyProfile, unifiedMode, data.engine ?? 'claude-code', now, now);
92
108
  return getWorkspace(id);
93
109
  }
94
110
  /** Fetch a single workspace by ID, or null if not found. */
@@ -212,13 +228,21 @@ export function updateWorktreePath(id, newPath) {
212
228
  }
213
229
  return getWorkspace(id);
214
230
  }
215
- /** Update the agent's permission mode (auto-accept vs plan/read-only). */
216
- export function updateWorkspacePermissionMode(id, permissionMode) {
231
+ /**
232
+ * Update the agent's unified permission mode (plan | bypass | strict | interactive).
233
+ *
234
+ * Also writes the legacy `permission_mode` and `permission_profile` columns to
235
+ * keep them coherent with the new value — they remain readable by legacy code
236
+ * paths during deploy. The unified column is the source of truth.
237
+ */
238
+ export function updateAgentPermissionMode(id, mode) {
217
239
  const db = getDb();
218
240
  const now = new Date().toISOString();
241
+ const legacyMode = mode === 'plan' ? 'plan' : 'auto-accept';
242
+ const legacyProfile = mode === 'plan' ? 'bypass' : mode;
219
243
  const result = db
220
- .prepare('UPDATE workspaces SET permission_mode = ?, updated_at = ? WHERE id = ?')
221
- .run(permissionMode, now, id);
244
+ .prepare('UPDATE workspaces SET agent_permission_mode = ?, permission_mode = ?, permission_profile = ?, updated_at = ? WHERE id = ?')
245
+ .run(mode, legacyMode, legacyProfile, now, id);
222
246
  if (result.changes === 0) {
223
247
  throw new Error(`Workspace '${id}' not found`);
224
248
  }
@@ -249,6 +273,10 @@ export function deleteWorkspace(id) {
249
273
  // churn. The Map has no FK to clean up for it automatically.
250
274
  orchestrator.forgetRateLimitInfo(id);
251
275
  orchestrator.forgetTasksDoneSnapshot(id);
276
+ orchestrator.forgetResumeFailed(id);
277
+ orchestrator.forgetPendingQueue(id);
278
+ orchestrator.forgetPreAwaitStatus(id);
279
+ orchestrator.forgetSessionId(id);
252
280
  autoLoopService.forgetAutoLoopState(id);
253
281
  const db = getDb();
254
282
  db.prepare('DELETE FROM workspaces WHERE id = ?').run(id);
@@ -373,30 +401,6 @@ export function setAutoLoopReady(id, ready) {
373
401
  db.prepare('UPDATE workspaces SET auto_loop_ready = ? WHERE id = ?').run(ready ? 1 : 0, id);
374
402
  return getWorkspace(id);
375
403
  }
376
- /**
377
- * Set the permission profile for a workspace.
378
- *
379
- * - `bypass` (default): Kōbō passes `--dangerously-skip-permissions` — no
380
- * prompts, but the CLI hard-denies writes under `.claude/**` and
381
- * `.github/workflows/**` regardless of the project's settings.json.
382
- * - `strict`: Kōbō passes `--permission-mode acceptEdits` — the CLI respects
383
- * the project's `.claude/settings.json` allow/deny lists. Enables writes
384
- * under `.claude/**` / `.github/workflows/**` when the user has explicitly
385
- * allowed them, at the cost of potential prompts on un-allow-listed Bash
386
- * or MCP calls.
387
- *
388
- * Takes effect on the next session spawn — running sessions keep whichever
389
- * flag they were started with.
390
- */
391
- export function setPermissionProfile(id, profile) {
392
- const workspace = getWorkspace(id);
393
- if (!workspace)
394
- throw new Error(`Workspace '${id}' not found`);
395
- const db = getDb();
396
- const now = new Date().toISOString();
397
- db.prepare('UPDATE workspaces SET permission_profile = ?, updated_at = ? WHERE id = ?').run(profile, now, id);
398
- return getWorkspace(id);
399
- }
400
404
  /** Remove a workspace from favorites. Idempotent: safe to call on a non-favorite, though `updated_at` still refreshes. */
401
405
  export function unsetFavorite(id) {
402
406
  const db = getDb();
@@ -1,5 +1,5 @@
1
1
  import { execFile as execFileCb, execFileSync } from 'node:child_process';
2
- import { existsSync, readFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, rmSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { promisify } from 'node:util';
5
5
  const execFileAsync = promisify(execFileCb);
@@ -410,7 +410,7 @@ export function moveWorktree(projectPath, oldPath, newPath) {
410
410
  git(projectPath, ['worktree', 'move', oldPath, newPath]);
411
411
  }
412
412
  /** List files changed between base and HEAD (committed), plus working tree changes. */
413
- export function getChangedFiles(repoPath, base) {
413
+ export function getChangedFiles(repoPath, base, includeUntracked = false) {
414
414
  const ref = resolveBase(repoPath, base);
415
415
  const files = [];
416
416
  const seen = new Set();
@@ -443,9 +443,14 @@ export function getChangedFiles(repoPath, base) {
443
443
  catch {
444
444
  // No commits yet
445
445
  }
446
- // Working tree changes (uncommitted)
446
+ // Working tree changes (uncommitted). Default to `-uno` to skip pure
447
+ // untracked files: they have never been `git add`-ed and won't ship in
448
+ // the next commit/PR, so showing them in the diff viewer is misleading.
449
+ // When `includeUntracked` is true (user opt-in via the diff viewer toggle)
450
+ // we use `-uall` and surface them with status='added'.
447
451
  try {
448
- const output = git(repoPath, ['status', '--porcelain', '-uall']);
452
+ const flag = includeUntracked ? '-uall' : '-uno';
453
+ const output = git(repoPath, ['status', '--porcelain', flag]);
449
454
  for (const line of output.split('\n')) {
450
455
  if (!line)
451
456
  continue;
@@ -456,7 +461,7 @@ export function getChangedFiles(repoPath, base) {
456
461
  const y = line[1];
457
462
  let status = 'modified';
458
463
  if (x === '?' && y === '?')
459
- status = 'added';
464
+ status = 'untracked';
460
465
  else if (x === 'A' || y === 'A')
461
466
  status = 'added';
462
467
  else if (x === 'D' || y === 'D')
@@ -523,6 +528,63 @@ export function getFileAtRef(repoPath, ref, filePath) {
523
528
  return null;
524
529
  }
525
530
  }
531
+ /**
532
+ * Reset a single file in the worktree to a sensible baseline. Cascade:
533
+ * 1. `origin/<branchName>` if the remote ref AND the file exist there
534
+ * (typical: branch is pushed, user wants to undo all local changes).
535
+ * 2. `HEAD` if the file exists at the last local commit (typical: branch
536
+ * not yet pushed, or file was added in commits that aren't on remote
537
+ * yet — discards just the uncommitted edits, keeps the commits).
538
+ * 3. **Delete** the file from disk when it's untracked (not on remote AND
539
+ * not in HEAD): there's nothing to "rollback to", so the only sensible
540
+ * undo is to remove the local-only file. Caller MUST surface this to
541
+ * the user with an explicit confirmation message — the action is
542
+ * permanent.
543
+ *
544
+ * Throws on filesystem errors (permission denied, etc.). Returns the
545
+ * target that was actually used so the caller can surface the right
546
+ * feedback in the UI.
547
+ */
548
+ export function rollbackFile(repoPath, branchName, filePath, remote = 'origin') {
549
+ const remoteRef = `${remote}/${branchName}`;
550
+ let remoteRefExists = false;
551
+ try {
552
+ git(repoPath, ['rev-parse', '--verify', remoteRef]);
553
+ remoteRefExists = true;
554
+ }
555
+ catch {
556
+ // Branch never pushed — fall through to HEAD.
557
+ }
558
+ if (remoteRefExists) {
559
+ try {
560
+ git(repoPath, ['cat-file', '-e', `${remoteRef}:${filePath}`]);
561
+ git(repoPath, ['checkout', remoteRef, '--', filePath]);
562
+ return 'remote';
563
+ }
564
+ catch {
565
+ // File doesn't exist at origin/<branch> (added locally) — fall through.
566
+ }
567
+ }
568
+ try {
569
+ git(repoPath, ['cat-file', '-e', `HEAD:${filePath}`]);
570
+ git(repoPath, ['checkout', 'HEAD', '--', filePath]);
571
+ return 'head';
572
+ }
573
+ catch {
574
+ // File is untracked OR has already been rolled back — delete it from
575
+ // disk if still present. Idempotent: if the file is already gone (race
576
+ // with a previous rollback, stale UI list, manual rm), we still return
577
+ // 'deleted' since the end state matches the user's intent. `rmSync`
578
+ // over `git clean -f` keeps the action narrow to one file.
579
+ const absPath = join(repoPath, filePath);
580
+ if (existsSync(absPath)) {
581
+ rmSync(absPath, { force: true });
582
+ }
583
+ return 'deleted';
584
+ }
585
+ }
586
+ /** @deprecated kept for backwards-compat with older imports — use `rollbackFile`. */
587
+ export const rollbackFileToRemote = rollbackFile;
526
588
  /** Get the current content of a file in the worktree. Returns null if the file doesn't exist. */
527
589
  export function getFileContent(repoPath, filePath) {
528
590
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loicngr/kobo",
3
- "version": "1.6.14",
3
+ "version": "1.7.0",
4
4
  "description": "Kōbō — multi-workspace agent manager for Claude Code. Orchestrates isolated git worktrees with dev servers, Notion integration, and MCP tools.",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-or-later",
@@ -66,6 +66,7 @@
66
66
  "prepublishOnly": "npm run build"
67
67
  },
68
68
  "dependencies": {
69
+ "@anthropic-ai/claude-agent-sdk": "^0.2.126",
69
70
  "@hono/node-server": "^1.19.13",
70
71
  "@modelcontextprotocol/sdk": "^1.29.0",
71
72
  "better-sqlite3": "^12.8.0",