even-keel 0.2.4 → 0.3.0-rc.2

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 (477) hide show
  1. package/.claude-plugin/marketplace.json +16 -4
  2. package/.env.example +2 -2
  3. package/CHANGELOG.md +23 -0
  4. package/README.md +10 -8
  5. package/dist/src/account/aws.js +76 -0
  6. package/dist/src/account/azure.js +36 -0
  7. package/dist/src/account/cloud-errors.js +72 -0
  8. package/dist/src/account/cloud.js +335 -0
  9. package/dist/src/account/credit.js +49 -7
  10. package/dist/src/account/gcloud.js +71 -0
  11. package/dist/src/account/header-levels.js +3 -2
  12. package/dist/src/account/homes.js +49 -5
  13. package/dist/src/account/keycheck.js +57 -4
  14. package/dist/src/account/management.js +41 -0
  15. package/dist/src/account/model.js +41 -18
  16. package/dist/src/account/network.js +8 -3
  17. package/dist/src/account/service-defaults.js +12 -3
  18. package/dist/src/account/settingsGuard.js +92 -0
  19. package/dist/src/account/settingsGuardStrip.js +36 -0
  20. package/dist/src/account/settingsHook.js +15 -0
  21. package/dist/src/account/settingsLayer.js +190 -0
  22. package/dist/src/account/settingsUninstall.js +7 -0
  23. package/dist/src/account/share.js +23 -6
  24. package/dist/src/account/spend.js +155 -0
  25. package/dist/src/account/watcher.js +189 -24
  26. package/dist/src/agent/adapters.js +13 -2
  27. package/dist/src/agent/env.js +22 -7
  28. package/dist/src/agent/model-slots.js +32 -0
  29. package/dist/src/agent/process.js +32 -6
  30. package/dist/src/agent/projectRules.js +3 -2
  31. package/dist/src/agent/providers.js +18 -1
  32. package/dist/src/agent/scripted.js +319 -0
  33. package/dist/src/agent/windows.js +35 -3
  34. package/dist/src/badge/action.js +41 -0
  35. package/dist/src/badge/check.js +60 -0
  36. package/dist/src/badge/collect.js +174 -0
  37. package/dist/src/badge/dates.js +29 -0
  38. package/dist/src/badge/drawing.js +3 -0
  39. package/dist/src/badge/fonts.generated.js +11 -0
  40. package/dist/src/badge/model.js +9 -0
  41. package/dist/src/badge/privacy.js +151 -0
  42. package/dist/src/badge/push.js +117 -0
  43. package/dist/src/badge/render.js +490 -0
  44. package/dist/src/badge/settings.js +43 -0
  45. package/dist/src/badge/stats.js +31 -0
  46. package/dist/src/badge/status.js +57 -0
  47. package/dist/src/badge/text.js +52 -0
  48. package/dist/src/badge/theme.js +54 -0
  49. package/dist/src/badge/translate.js +162 -0
  50. package/dist/src/builtin/adapter.js +40 -0
  51. package/dist/src/builtin/control.js +179 -0
  52. package/dist/src/builtin/editor.js +117 -0
  53. package/dist/src/builtin/export-store.js +67 -0
  54. package/dist/src/builtin/export.js +202 -0
  55. package/dist/src/builtin/exporting.js +25 -0
  56. package/dist/src/builtin/files.js +155 -0
  57. package/dist/src/builtin/links.js +25 -0
  58. package/dist/src/builtin/model.js +59 -0
  59. package/dist/src/builtin/routes.js +108 -0
  60. package/dist/src/builtin/source.js +240 -0
  61. package/dist/src/builtin/store.js +520 -0
  62. package/dist/src/builtin/switch.js +77 -0
  63. package/dist/src/chain/answers.js +27 -0
  64. package/dist/src/chain/archive.js +0 -1
  65. package/dist/src/chain/dispatcher.js +105 -12
  66. package/dist/src/chain/fence.js +30 -0
  67. package/dist/src/chain/handover.js +27 -9
  68. package/dist/src/chain/launches.js +4 -4
  69. package/dist/src/chain/limitNotice.js +1 -1
  70. package/dist/src/chain/lists.js +42 -6
  71. package/dist/src/chain/log.js +3 -1
  72. package/dist/src/chain/maincheck.js +116 -10
  73. package/dist/src/chain/mainci.js +26 -7
  74. package/dist/src/chain/mainfix.js +12 -1
  75. package/dist/src/chain/milestone-sequence.js +40 -0
  76. package/dist/src/chain/milestones.js +3 -2
  77. package/dist/src/chain/order.js +20 -5
  78. package/dist/src/chain/overage.js +7 -2
  79. package/dist/src/chain/places.js +1 -1
  80. package/dist/src/chain/prompts.js +64 -6
  81. package/dist/src/chain/relay.js +35 -14
  82. package/dist/src/chain/reviews.js +8 -4
  83. package/dist/src/chain/rules.js +40 -11
  84. package/dist/src/chain/snapshots.js +2 -0
  85. package/dist/src/chain/start.js +21 -1
  86. package/dist/src/chain/store.js +16 -6
  87. package/dist/src/chain/unchanged.js +68 -5
  88. package/dist/src/ci/adapters.js +3 -1
  89. package/dist/src/ci/forgejo-profile.js +3 -24
  90. package/dist/src/ci/forgejo.js +2 -1
  91. package/dist/src/ci/github.js +10 -2
  92. package/dist/src/ci/gitlab.js +10 -3
  93. package/dist/src/ci/http.js +4 -0
  94. package/dist/src/ci/model.js +79 -6
  95. package/dist/src/ci/report.js +6 -3
  96. package/dist/src/ci/shared.js +9 -0
  97. package/dist/src/ci/verdict.js +18 -7
  98. package/dist/src/ci/watcher.js +95 -23
  99. package/dist/src/ci/wiring.js +15 -0
  100. package/dist/src/claude/adapter.js +34 -8
  101. package/dist/src/claude/cli.js +32 -8
  102. package/dist/src/claude/instructions.js +42 -7
  103. package/dist/src/claude/oauth.js +67 -0
  104. package/dist/src/claude/sdk/host.js +9 -4
  105. package/dist/src/claude/tree.js +45 -14
  106. package/dist/src/cli-check/run.js +3 -3
  107. package/dist/src/cli-check/support.js +4 -4
  108. package/dist/src/cli.js +54 -17
  109. package/dist/src/codex/adapter.js +2 -0
  110. package/dist/src/codex/cli.js +34 -18
  111. package/dist/src/codex/protection.js +17 -11
  112. package/dist/src/codex/rollout.js +9 -2
  113. package/dist/src/codex/turns.js +6 -3
  114. package/dist/src/codex/window.js +14 -0
  115. package/dist/src/config-form.js +63 -7
  116. package/dist/src/config-store.js +29 -7
  117. package/dist/src/config.js +45 -15
  118. package/dist/src/copilot/adapter.js +2 -0
  119. package/dist/src/copilot/cli.js +8 -11
  120. package/dist/src/copilot/home.js +1 -1
  121. package/dist/src/copilot/transcript.js +1 -2
  122. package/dist/src/demo/agent.js +97 -0
  123. package/dist/src/demo/model.js +6 -0
  124. package/dist/src/demo/scenario.js +139 -0
  125. package/dist/src/demo/service.js +161 -0
  126. package/dist/src/diagnostics/stop.js +16 -0
  127. package/dist/src/env-file.js +4 -0
  128. package/dist/src/error-reason.js +10 -0
  129. package/dist/src/event-log/log.js +97 -0
  130. package/dist/src/event-log/model.js +1 -0
  131. package/dist/src/event-log/page-events.js +71 -0
  132. package/dist/src/event-log/watch.js +236 -0
  133. package/dist/src/events.js +57 -1
  134. package/dist/src/forgejo/adapter.js +49 -0
  135. package/dist/src/forgejo/api.js +95 -0
  136. package/dist/src/forgejo/editor.js +196 -0
  137. package/dist/src/forgejo/model.js +90 -0
  138. package/dist/src/forgejo/profile.js +24 -0
  139. package/dist/src/forgejo/source.js +292 -0
  140. package/dist/src/forgejo/trust.js +45 -0
  141. package/dist/src/git/branches.js +88 -0
  142. package/dist/src/git/clone-progress.js +168 -0
  143. package/dist/src/git/remote-run.js +162 -0
  144. package/dist/src/git/run.js +6 -2
  145. package/dist/src/git/setup.js +4 -5
  146. package/dist/src/git/slot.js +9 -7
  147. package/dist/src/git/worktree.js +13 -10
  148. package/dist/src/github/adapter.js +1 -0
  149. package/dist/src/github/editor.js +214 -0
  150. package/dist/src/github/edits.js +31 -0
  151. package/dist/src/github/model.js +10 -4
  152. package/dist/src/github/source.js +66 -15
  153. package/dist/src/gitlab/adapter.js +1 -0
  154. package/dist/src/gitlab/api.js +4 -2
  155. package/dist/src/gitlab/editor.js +248 -0
  156. package/dist/src/gitlab/model.js +43 -4
  157. package/dist/src/gitlab/source.js +113 -22
  158. package/dist/src/guard.js +26 -10
  159. package/dist/src/hotkeys.js +51 -0
  160. package/dist/src/huly/adapter.js +1 -0
  161. package/dist/src/huly/collab.js +15 -0
  162. package/dist/src/huly/editor.js +241 -0
  163. package/dist/src/huly/marks.js +48 -0
  164. package/dist/src/huly/model.js +22 -5
  165. package/dist/src/huly/source.js +111 -48
  166. package/dist/src/intake/github.js +10 -0
  167. package/dist/src/intake/intake.js +41 -1
  168. package/dist/src/intake/model.js +8 -3
  169. package/dist/src/jira/adapter.js +1 -0
  170. package/dist/src/jira/api.js +28 -7
  171. package/dist/src/jira/editor.js +243 -0
  172. package/dist/src/jira/model.js +19 -5
  173. package/dist/src/jira/source.js +41 -9
  174. package/dist/src/jobs/model.js +1 -0
  175. package/dist/src/jobs/runner.js +236 -0
  176. package/dist/src/limits/chatgpt.js +11 -0
  177. package/dist/src/limits/copilot.js +51 -18
  178. package/dist/src/limits/model.js +62 -8
  179. package/dist/src/limits/overage-session.js +2 -2
  180. package/dist/src/limits/overage.js +8 -5
  181. package/dist/src/limits/reset.js +7 -0
  182. package/dist/src/limits/usage.js +60 -5
  183. package/dist/src/linear/adapter.js +1 -0
  184. package/dist/src/linear/editor.js +220 -0
  185. package/dist/src/linear/estimate.js +32 -0
  186. package/dist/src/linear/model.js +24 -3
  187. package/dist/src/linear/source.js +74 -21
  188. package/dist/src/main.js +53 -23
  189. package/dist/src/notice/en-advice.js +28 -0
  190. package/dist/src/notice/en-review.js +29 -0
  191. package/dist/src/notice/en-startup.js +21 -0
  192. package/dist/src/notice/en-values.js +47 -0
  193. package/dist/src/notice/en.js +265 -96
  194. package/dist/src/notice/kinds.js +26 -0
  195. package/dist/src/notice/notice.js +49 -6
  196. package/dist/src/npm-access.js +58 -0
  197. package/dist/src/opencode/adapter.js +4 -2
  198. package/dist/src/opencode/cli.js +34 -25
  199. package/dist/src/opencode/go.js +51 -0
  200. package/dist/src/opencode/home.js +41 -8
  201. package/dist/src/opencode/transcript.js +5 -5
  202. package/dist/src/opencode/usage.js +10 -4
  203. package/dist/src/opencode/window.js +54 -0
  204. package/dist/src/packages/check.js +11 -5
  205. package/dist/src/packages/gateway.js +76 -6
  206. package/dist/src/packages/launch.js +6 -3
  207. package/dist/src/packages/model.js +61 -2
  208. package/dist/src/packages/npm.js +55 -6
  209. package/dist/src/packages/plugins.js +23 -2
  210. package/dist/src/packages/service.js +104 -17
  211. package/dist/src/packages/settings.js +13 -0
  212. package/dist/src/packages/store.js +1 -1
  213. package/dist/src/paths.js +32 -0
  214. package/dist/src/profiles/control.js +1 -0
  215. package/dist/src/profiles/model.js +2 -2
  216. package/dist/src/profiles/oauth-error.js +1 -9
  217. package/dist/src/profiles/oauth-response.js +2 -0
  218. package/dist/src/profiles/service.js +46 -4
  219. package/dist/src/profiles/store.js +10 -5
  220. package/dist/src/projects/add.js +25 -2
  221. package/dist/src/projects/branch-control.js +86 -0
  222. package/dist/src/projects/branch-move.js +39 -0
  223. package/dist/src/projects/branch.js +13 -0
  224. package/dist/src/projects/check.js +80 -36
  225. package/dist/src/projects/creation.js +166 -0
  226. package/dist/src/projects/git-found.js +62 -0
  227. package/dist/src/projects/git-mode.js +116 -0
  228. package/dist/src/projects/own-folder.js +8 -0
  229. package/dist/src/projects/place.js +235 -0
  230. package/dist/src/projects/remote-branches.js +24 -0
  231. package/dist/src/projects/target-read.js +95 -0
  232. package/dist/src/projects/target.js +56 -0
  233. package/dist/src/review/events.js +1 -1
  234. package/dist/src/review/note.js +58 -0
  235. package/dist/src/review/open.js +3 -3
  236. package/dist/src/review/wiring.js +25 -3
  237. package/dist/src/secrets/catalog.js +4 -1
  238. package/dist/src/server-control.js +1 -0
  239. package/dist/src/server-guard.js +4 -0
  240. package/dist/src/server-request.js +88 -10
  241. package/dist/src/server-response.js +143 -0
  242. package/dist/src/server-security.js +16 -0
  243. package/dist/src/server.js +105 -117
  244. package/dist/src/service/account-packages.js +116 -0
  245. package/dist/src/service/accounts.js +109 -81
  246. package/dist/src/service/badge-private.js +62 -0
  247. package/dist/src/service/badge.js +203 -0
  248. package/dist/src/service/chain-prompts.js +87 -0
  249. package/dist/src/service/chain.js +120 -190
  250. package/dist/src/service/cleanup.js +114 -0
  251. package/dist/src/service/cli-check.js +1 -1
  252. package/dist/src/service/closing.js +57 -0
  253. package/dist/src/service/demo.js +46 -0
  254. package/dist/src/service/hosting.js +239 -18
  255. package/dist/src/service/install-check.js +78 -0
  256. package/dist/src/service/lifecycle.js +4 -7
  257. package/dist/src/service/stats.js +3 -3
  258. package/dist/src/service/trackers.js +27 -1
  259. package/dist/src/service/vocabulary.js +17 -0
  260. package/dist/src/service.js +215 -19
  261. package/dist/src/sessions/agents.js +10 -2
  262. package/dist/src/sessions/approvals.js +1 -1
  263. package/dist/src/sessions/ask.js +32 -6
  264. package/dist/src/sessions/boot.js +7 -0
  265. package/dist/src/sessions/chat.js +16 -4
  266. package/dist/src/sessions/commandPrompt.js +13 -6
  267. package/dist/src/sessions/history.js +2 -0
  268. package/dist/src/sessions/keepwarm.js +1 -1
  269. package/dist/src/sessions/launch.js +21 -25
  270. package/dist/src/sessions/lingering.js +30 -7
  271. package/dist/src/sessions/mail.js +7 -6
  272. package/dist/src/sessions/mailRelay.js +2 -2
  273. package/dist/src/sessions/mailbox.js +1 -1
  274. package/dist/src/sessions/monitor.js +47 -3
  275. package/dist/src/sessions/note.js +44 -19
  276. package/dist/src/sessions/permission.js +32 -10
  277. package/dist/src/sessions/protection.js +38 -14
  278. package/dist/src/sessions/rare.js +130 -0
  279. package/dist/src/sessions/runs-store.js +20 -0
  280. package/dist/src/sessions/runs.js +140 -0
  281. package/dist/src/sessions/tail.js +4 -0
  282. package/dist/src/sessions/transcript.js +64 -8
  283. package/dist/src/settings/defaults.js +1 -0
  284. package/dist/src/settings/registry.js +86 -24
  285. package/dist/src/settings/store.js +14 -5
  286. package/dist/src/setup.js +5 -0
  287. package/dist/src/shown-work.js +22 -0
  288. package/dist/src/state/settings.js +1 -0
  289. package/dist/src/stats/base-sql.js +7 -1
  290. package/dist/src/stats/checkpoint.js +8 -5
  291. package/dist/src/stats/model.js +1 -1
  292. package/dist/src/stats/reader.js +50 -25
  293. package/dist/src/stats/rules-reader.js +6 -2
  294. package/dist/src/stats/steps-reader.js +5 -0
  295. package/dist/src/stats/tally-schema.js +1 -1
  296. package/dist/src/storage/backup-model.js +3 -0
  297. package/dist/src/storage/backup-schedule.js +197 -0
  298. package/dist/src/storage/backup-worker.js +9 -0
  299. package/dist/src/storage/backup.js +141 -0
  300. package/dist/src/storage/browser-hotkeys.js +25 -0
  301. package/dist/src/storage/context-windows.js +39 -0
  302. package/dist/src/storage/copy.js +44 -13
  303. package/dist/src/storage/database.js +343 -4
  304. package/dist/src/storage/left-folders.js +16 -0
  305. package/dist/src/storage/migrations.js +98 -1
  306. package/dist/src/storage/owner.js +12 -7
  307. package/dist/src/storage/schema.js +1 -1
  308. package/dist/src/storage/startup.js +25 -0
  309. package/dist/src/storage/state-files.js +1 -1
  310. package/dist/src/storage/vacuum.js +29 -0
  311. package/dist/src/taskmcp/args.js +146 -0
  312. package/dist/src/taskmcp/calls.js +741 -0
  313. package/dist/src/taskmcp/downloads.js +87 -0
  314. package/dist/src/taskmcp/files.js +58 -0
  315. package/dist/src/taskmcp/retries.js +57 -0
  316. package/dist/src/taskmcp/server.js +81 -0
  317. package/dist/src/taskmcp/tools.js +128 -0
  318. package/dist/src/taskmcp/vocabulary.js +75 -0
  319. package/dist/src/tools/panel.js +41 -8
  320. package/dist/src/tools/sessionSettings.js +2 -1
  321. package/dist/src/tools/settings.js +16 -3
  322. package/dist/src/tracker/adapters.js +3 -1
  323. package/dist/src/tracker/card.js +16 -12
  324. package/dist/src/tracker/close.js +57 -0
  325. package/dist/src/tracker/closer.js +18 -15
  326. package/dist/src/tracker/closes.js +6 -0
  327. package/dist/src/tracker/control.js +32 -13
  328. package/dist/src/tracker/diagnostics.js +5 -2
  329. package/dist/src/tracker/editor.js +108 -0
  330. package/dist/src/tracker/export-target.js +30 -0
  331. package/dist/src/tracker/export.js +168 -0
  332. package/dist/src/tracker/health.js +5 -0
  333. package/dist/src/tracker/link.js +127 -24
  334. package/dist/src/tracker/markers.js +7 -0
  335. package/dist/src/tracker/model.js +0 -12
  336. package/dist/src/tracker/parents.js +8 -0
  337. package/dist/src/tracker/questions.js +24 -3
  338. package/dist/src/tracker/readers.js +19 -3
  339. package/dist/src/tracker/source.js +5 -0
  340. package/dist/src/tracker/start.js +61 -6
  341. package/dist/src/tracker/templates.js +102 -0
  342. package/dist/src/tracker/trackers.js +20 -10
  343. package/dist/src/updates/runner.js +1 -1
  344. package/dist/src/updates/settle.js +11 -3
  345. package/dist/src/updates/updater.js +4 -4
  346. package/dist/tally/src/builtin-tasks.js +45 -0
  347. package/dist/tally/src/catalogue.js +70 -0
  348. package/dist/tally/src/classify.js +1 -0
  349. package/dist/tally/src/collect.js +33 -10
  350. package/dist/tally/src/copilot.js +1 -0
  351. package/dist/tally/src/db-classify.js +46 -0
  352. package/dist/tally/src/db.js +66 -60
  353. package/dist/tally/src/migrations/10-rework-label.sql +73 -0
  354. package/dist/tally/src/migrations/11-catalogue-prices.sql +53 -0
  355. package/dist/tally/src/migrations/12-key-spends.sql +30 -0
  356. package/dist/tally/src/migrations/13-normal-spans.sql +110 -0
  357. package/dist/tally/src/migrations/14-model-families.sql +25 -0
  358. package/dist/tally/src/migrations/15-task-moves.sql +32 -0
  359. package/dist/tally/src/migrations.js +1 -1
  360. package/dist/tally/src/opencode.js +1 -0
  361. package/dist/tally/src/parse.js +3 -0
  362. package/dist/tally/src/rollout.js +2 -1
  363. package/dist/tally/src/rule-hook-size.js +2 -1
  364. package/dist/tally/src/rule-hook.js +3 -0
  365. package/dist/tally/src/task-moves.js +32 -0
  366. package/dist/web/assets/BadgeDialog-Dx2EERWr.js +1 -0
  367. package/dist/web/assets/BadgeDialog-W0giN4k2.css +1 -0
  368. package/dist/web/assets/DescriptionEditor-BL_6314d.js +216 -0
  369. package/dist/web/assets/ProjectPackages-D-Hqs0sG.js +1 -0
  370. package/dist/web/assets/Select-B5xZpiCG.js +1 -0
  371. package/dist/web/assets/Select-CYemy5Na.css +1 -0
  372. package/dist/web/assets/TaskCard-B9EJ_Qa2.js +2 -0
  373. package/dist/web/assets/TaskCard-BV2lQojC.css +1 -0
  374. package/dist/web/assets/TranscriptWindow-BN6jSpev.css +1 -0
  375. package/dist/web/assets/TranscriptWindow-E8DxggYC.js +4 -0
  376. package/dist/web/assets/accountParts-c2gPSGKK.js +3 -0
  377. package/dist/web/assets/accountParts-tFRVownp.css +1 -0
  378. package/dist/web/assets/blocks-B03KxlgQ.js +12 -0
  379. package/dist/web/assets/blocks-Dx3DACiG.css +1 -0
  380. package/dist/web/assets/cardDrafts-Cb5dNpJ3.js +12 -0
  381. package/dist/web/assets/cardDrafts-izWnctoh.css +1 -0
  382. package/dist/web/assets/cardSide-63fNWHHv.css +1 -0
  383. package/dist/web/assets/cardSide-CIGvmTwG.js +2 -0
  384. package/dist/web/assets/description-C-o9LBbp.css +1 -0
  385. package/dist/web/assets/feedLine-Buzox_AA.js +1 -0
  386. package/dist/web/assets/feedLine-CBjZXWwX.css +1 -0
  387. package/dist/web/assets/hooks-DdmIE6gF.js +1 -0
  388. package/dist/web/assets/index-CkYiatZt.css +1 -0
  389. package/dist/web/assets/index-DELgEMlH.js +25 -0
  390. package/dist/web/assets/lib-B8qNeB0X.css +1 -0
  391. package/dist/web/assets/lib-C1i2rKJZ.js +18 -0
  392. package/dist/web/assets/overview-B7iEgjQD.css +1 -0
  393. package/dist/web/assets/overview-D9PUjFeR.js +7 -0
  394. package/dist/web/assets/packageGroups-B34vA6-0.js +1 -0
  395. package/dist/web/assets/packages-Dld4uH9X.css +1 -0
  396. package/dist/web/assets/react-dom-vGPErQYp.js +1 -0
  397. package/dist/web/assets/rules-BVB-I2tg.js +1 -0
  398. package/dist/web/assets/rules-Bgil4ZBp.css +1 -0
  399. package/dist/web/assets/secret-CmK85pY6.js +1 -0
  400. package/dist/web/assets/secret-DldsC74x.css +1 -0
  401. package/dist/web/assets/useFileDrop-eZtIxL1H.js +1 -0
  402. package/dist/web/assets/useHeightGlide-BmtdsmN0.css +1 -0
  403. package/dist/web/assets/useHeightGlide-DQvvOoIL.js +3 -0
  404. package/dist/web/assets/useRowFocus-CwOoEmzD.js +1 -0
  405. package/dist/web/index.html +30 -9
  406. package/dist/web/theme.js +6 -0
  407. package/even-keel.config.example.json +5 -4
  408. package/package.json +21 -5
  409. package/plugins/agent-bridge/.claude-plugin/plugin.json +16 -0
  410. package/plugins/{checkpoint → agent-bridge}/README.md +20 -6
  411. package/plugins/agent-bridge/hooks/addressban.mjs +64 -0
  412. package/plugins/{checkpoint → agent-bridge}/hooks/checkpoint-mark.mjs +4 -3
  413. package/plugins/{checkpoint → agent-bridge}/hooks/evenkeel.mjs +28 -11
  414. package/plugins/agent-bridge/hooks/git-ban.mjs +31 -0
  415. package/plugins/agent-bridge/hooks/gitban.mjs +83 -0
  416. package/plugins/agent-bridge/hooks/handoff.mjs +20 -0
  417. package/plugins/{checkpoint → agent-bridge}/hooks/hooks.json +10 -0
  418. package/plugins/{checkpoint → agent-bridge}/hooks/mailbox.mjs +6 -3
  419. package/plugins/{checkpoint → agent-bridge}/hooks/nudges.mjs +11 -7
  420. package/plugins/{checkpoint/opencode/checkpoint.mjs → agent-bridge/opencode/agent-bridge.mjs} +15 -9
  421. package/plugins/forgejo/.claude-plugin/plugin.json +7 -0
  422. package/plugins/forgejo/.mcp.json +13 -0
  423. package/plugins/forgejo/README.md +23 -0
  424. package/plugins/forgejo/skills/task/SKILL.md +55 -0
  425. package/plugins/github/.claude-plugin/plugin.json +1 -1
  426. package/plugins/github/README.md +1 -1
  427. package/plugins/github/skills/task/SKILL.md +2 -2
  428. package/plugins/gitlab/.claude-plugin/plugin.json +1 -1
  429. package/plugins/gitlab/skills/task/SKILL.md +2 -2
  430. package/plugins/huly/.claude-plugin/plugin.json +1 -1
  431. package/plugins/huly/skills/task/SKILL.md +4 -4
  432. package/plugins/jira/.claude-plugin/plugin.json +1 -1
  433. package/plugins/jira/skills/task/SKILL.md +3 -3
  434. package/plugins/linear/.claude-plugin/plugin.json +1 -1
  435. package/plugins/linear/README.md +1 -1
  436. package/plugins/linear/skills/task/SKILL.md +3 -3
  437. package/plugins/tally/.claude-plugin/plugin.json +1 -1
  438. package/plugins/tally/skills/session-audit/SKILL.md +5 -5
  439. package/plugins/tasks/.claude-plugin/plugin.json +9 -0
  440. package/plugins/tasks/.mcp.json +8 -0
  441. package/plugins/tasks/README.md +42 -0
  442. package/plugins/tasks/hooks/calibration-context.mjs +45 -0
  443. package/plugins/tasks/hooks/calibration.mjs +92 -0
  444. package/plugins/tasks/hooks/check-service.mjs +15 -0
  445. package/plugins/tasks/hooks/hooks.json +28 -0
  446. package/plugins/tasks/hooks/service-check.mjs +34 -0
  447. package/plugins/tasks/hooks/show-calibration.mjs +19 -0
  448. package/plugins/tasks/opencode/tasks.mjs +28 -0
  449. package/plugins/tasks/skills/split/SKILL.md +29 -0
  450. package/plugins/tasks/skills/task/SKILL.md +61 -0
  451. package/service/EvenKeelTray.cs +4 -20
  452. package/service/install.sh +25 -2
  453. package/service/uninstall.ps1 +16 -0
  454. package/service/uninstall.sh +10 -0
  455. package/tally/tally.config.json +2 -0
  456. package/dist/web/assets/Loader-CRe-GCoI.js +0 -31
  457. package/dist/web/assets/Loader-DJJTBsaF.css +0 -1
  458. package/dist/web/assets/TaskCard-Br2QIllc.css +0 -1
  459. package/dist/web/assets/TaskCard-C2xeaHWD.js +0 -2
  460. package/dist/web/assets/TranscriptWindow-B9zsSmIg.css +0 -1
  461. package/dist/web/assets/TranscriptWindow-COL_WTrF.js +0 -4
  462. package/dist/web/assets/feedLine-D0lnFyBZ.js +0 -1
  463. package/dist/web/assets/index-DQje9Nfo.js +0 -25
  464. package/dist/web/assets/index-mDBlgk2Y.css +0 -1
  465. package/dist/web/assets/media-BlW-XXN0.js +0 -1
  466. package/dist/web/assets/media-DR8nAbPy.css +0 -1
  467. package/dist/web/assets/useModels-1oIk0mDX.css +0 -1
  468. package/dist/web/assets/useModels-DRW63oka.js +0 -15
  469. package/plugins/checkpoint/.claude-plugin/plugin.json +0 -9
  470. package/plugins/checkpoint/hooks/handoff.mjs +0 -9
  471. /package/plugins/{checkpoint → agent-bridge}/hooks/context-checkpoint.mjs +0 -0
  472. /package/plugins/{checkpoint → agent-bridge}/hooks/merge-check.mjs +0 -0
  473. /package/plugins/{checkpoint → agent-bridge}/hooks/merges.mjs +0 -0
  474. /package/plugins/{checkpoint → agent-bridge}/hooks/permission.mjs +0 -0
  475. /package/plugins/{checkpoint → agent-bridge}/hooks/schema-hint.mjs +0 -0
  476. /package/plugins/{checkpoint → agent-bridge}/hooks/standard-gate.mjs +0 -0
  477. /package/plugins/{checkpoint → agent-bridge}/hooks/standards.mjs +0 -0
@@ -0,0 +1,25 @@
1
+ import { hotkeyBindingsOf } from '../hotkeys.js';
2
+ /**
3
+ * The page's hotkeys of each browser that changed one (BTN-880), by the id it keeps in its `localStorage`; table
4
+ * `browser_hotkeys` (step 38, `docs/storage.md`). A browser without a row keeps the defaults. A row that no longer
5
+ * reads (an action gone) is left out.
6
+ */
7
+ export async function loadBrowserHotkeys(db) {
8
+ const { rows } = await db.query('select browser, bindings from browser_hotkeys order by browser');
9
+ const layouts = {};
10
+ for (const row of rows) {
11
+ const bindings = hotkeyBindingsOf(JSON.parse(row.bindings));
12
+ if (bindings !== null)
13
+ layouts[row.browser] = bindings;
14
+ }
15
+ return layouts;
16
+ }
17
+ /** Starts its write at the call: see `Writes`. An empty layout is the defaults again: the row goes. */
18
+ export async function saveBrowserHotkeys(db, browser, bindings, at) {
19
+ if (Object.keys(bindings).length === 0) {
20
+ await db.query('delete from browser_hotkeys where browser = $1', [browser]);
21
+ return;
22
+ }
23
+ await db.query(`insert into browser_hotkeys (browser, bindings, saved_at) values ($1, $2, $3)
24
+ on conflict (browser) do update set bindings = excluded.bindings, saved_at = excluded.saved_at`, [browser, JSON.stringify(bindings), at.toISOString()]);
25
+ }
@@ -0,0 +1,39 @@
1
+ /** The newest answers kept; an older one only costs one more question of the agent. */
2
+ export const CONTEXT_WINDOWS_KEPT = 200;
3
+ /**
4
+ * The sessions whose last window is kept, here and in the monitor's memory. Above what the page shows (936
5
+ * sessions on 2026-11-09): fewer, and every start writes the shown ones that fell out again.
6
+ */
7
+ export const SESSION_WINDOWS_KEPT = 2000;
8
+ /**
9
+ * The context windows the agents named (BTN-946), kept through a restart; tables `context_windows` and
10
+ * `session_windows` (step 44, `docs/storage.md`).
11
+ */
12
+ export async function loadContextWindows(db) {
13
+ const { rows } = await db.query('select account, model, settings, stamp, window_size, measured_at from context_windows order by measured_at, account, model');
14
+ return rows.map((row) => ({ account: row.account, model: row.model, settings: row.settings, stamp: row.stamp, window: row.window_size, measuredAt: Number(row.measured_at) }));
15
+ }
16
+ /** Starts its write at the call: see `Writes`. */
17
+ export async function saveContextWindow(db, window) {
18
+ await db.query(`insert into context_windows (account, model, settings, stamp, window_size, measured_at) values ($1, $2, $3, $4, $5, $6)
19
+ on conflict (account, model, settings) do update set stamp = excluded.stamp, window_size = excluded.window_size, measured_at = excluded.measured_at`, [window.account, window.model, window.settings, window.stamp, window.window, window.measuredAt]);
20
+ await db.query('delete from context_windows where ctid in (select ctid from context_windows order by measured_at desc offset $1)', [CONTEXT_WINDOWS_KEPT]);
21
+ }
22
+ /** The last window of each session, oldest first. */
23
+ export async function loadSessionWindows(db) {
24
+ const { rows } = await db.query('select session_id, window_size from session_windows order by seen_at, session_id');
25
+ return rows.map((row) => [row.session_id, row.window_size]);
26
+ }
27
+ /**
28
+ * One poll's new and changed windows, a session once, in two statements however many they are: a write per
29
+ * session with its own trim kept the database busy for a quarter of the time (BTN-951). Starts its write at
30
+ * the call: see `Writes`.
31
+ */
32
+ export async function saveSessionWindows(db, windows, at) {
33
+ if (windows.length === 0)
34
+ return;
35
+ await db.query(`insert into session_windows (session_id, window_size, seen_at)
36
+ select session_id, window_size, $2 from json_to_recordset($1::json) as fresh(session_id text, window_size integer)
37
+ on conflict (session_id) do update set window_size = excluded.window_size`, [JSON.stringify(windows.map(([sessionId, window]) => ({ session_id: sessionId, window_size: window }))), at]);
38
+ await db.query('delete from session_windows where session_id in (select session_id from session_windows order by seen_at desc, session_id desc offset $1)', [SESSION_WINDOWS_KEPT]);
39
+ }
@@ -1,15 +1,51 @@
1
- import { existsSync, readdirSync } from 'node:fs';
1
+ import { cpSync, existsSync, readdirSync } from 'node:fs';
2
2
  import { insertList, inTransaction, openDatabase, refuseNewer, SQLITE_VERSIONS, STEPS } from './database.js';
3
- import { dataDirOf } from './owner.js';
3
+ import { dataDirOf, filesDirOf } from './owner.js';
4
+ /** The tables a copy carries over: every table but the version. */
5
+ export async function tablesOf(db) {
6
+ const { rows } = await db.query("select tablename as name from pg_tables where schemaname = 'public' and tablename <> 'schema_version' order by tablename");
7
+ return rows.map(({ name }) => name);
8
+ }
9
+ const tableRows = (name) => `(select coalesce(json_agg(r), '[]'::json) from "${name}" r)`;
4
10
  /** Every row of every table but the version, in one statement: a consistent snapshot while the service writes. */
5
11
  export async function rowsOf(db) {
6
- const { rows: tables } = await db.query("select tablename as name from pg_tables where schemaname = 'public' and tablename <> 'schema_version' order by tablename");
12
+ const tables = await tablesOf(db);
7
13
  if (tables.length === 0)
8
14
  return {};
9
- const parts = tables.map(({ name }) => `'${name}', (select coalesce(json_agg(r), '[]'::json) from "${name}" r)`);
15
+ const parts = tables.map((name) => `'${name}', ${tableRows(name)}`);
10
16
  const { rows } = await db.query(`select json_build_object(${parts.join(', ')}) as rows`);
11
17
  return rows[0].rows;
12
18
  }
19
+ /**
20
+ * The rows of `rowsOf` as JSON text, never parsed here: read a table a statement inside one transaction, which keeps
21
+ * the service's writes out until the last table is read, so the snapshot stays consistent while the event loop runs
22
+ * between the statements. For the automatic backup (`src/storage/backup.ts`), whose thread parses it.
23
+ */
24
+ export async function rowsTextOf(db) {
25
+ return inTransaction(db, async (tx) => {
26
+ const parts = [];
27
+ for (const name of await tablesOf(tx)) {
28
+ const { rows } = await tx.query(`select ${tableRows(name)}::text as rows`);
29
+ parts.push(`${JSON.stringify(name)}:${rows[0].rows}`);
30
+ }
31
+ return `{${parts.join(',')}}`;
32
+ });
33
+ }
34
+ /**
35
+ * Writes the rows into a new database in `dataDir` of the schema `steps` bring it to, then the attachments' bytes
36
+ * `files` (the source's folder) into `filesDir`, without half-written uploads.
37
+ */
38
+ export async function writeRows(rows, dir, files, steps = STEPS) {
39
+ const copy = await openDatabase(dataDirOf(dir), steps);
40
+ try {
41
+ await insertRows(copy, rows);
42
+ }
43
+ finally {
44
+ await copy.close();
45
+ }
46
+ if (files !== undefined && existsSync(files))
47
+ cpSync(files, filesDirOf(dir), { recursive: true, filter: (path) => !/\.tmp$/.test(path) });
48
+ }
13
49
  /** Inserts the rows into the tables of the same names and moves the counters of the id columns past them. */
14
50
  export async function insertRows(db, rows) {
15
51
  await inTransaction(db, async (tx) => {
@@ -24,18 +60,13 @@ export async function insertRows(db, rows) {
24
60
  /**
25
61
  * A copy of the database into the new folder `dir`, laid out as the database folder of the state folder: to restore it,
26
62
  * stop the service and put it in place of `state/even-keel`. The source is of this code's version (`checkVersion`).
63
+ * `files` — the source's folder of attachments' bytes, copied after the rows: a record is written after its file, so
64
+ * every record of the copy finds its bytes.
27
65
  */
28
- export async function backupDatabase(source, dir) {
66
+ export async function backupDatabase(source, dir, files) {
29
67
  if (existsSync(dir) && readdirSync(dir).length > 0)
30
68
  throw new Error(`storage: ${dir} exists; give a new folder`);
31
- const rows = await rowsOf(source);
32
- const copy = await openDatabase(dataDirOf(dir));
33
- try {
34
- await insertRows(copy, rows);
35
- }
36
- finally {
37
- await copy.close();
38
- }
69
+ await writeRows(await rowsOf(source), dir, files);
39
70
  }
40
71
  /**
41
72
  * The rows of the `node:sqlite` file of versions 1 and 2 (BTN-147), read whole; its tables are those of step 3. The
@@ -19,7 +19,8 @@ export const SQLITE_VERSIONS = 2;
19
19
  * organization each API account's key pays through, `key_organizations` (BTN-418); step 21 puts the Agent SDK of
20
20
  * Claude on the checked CLI (BTN-610); step 22 the `reason` of a chat message that came back (BTN-558); step 23 copies a project's own chain rules into each
21
21
  * of its feeds (BTN-553); step 24 the profiles' status moves (BTN-554); step 25 each account's last known limits,
22
- * `account_limits` (BTN-631); step 26 the tasks the merge closer closed, `merge_closes` (BTN-689). A foreign key between tables is deferred, so that a copy inserts the
22
+ * `account_limits` (BTN-631); step 26 the tasks the merge closer closed, `merge_closes` (BTN-689); step 29 the event
23
+ * log, `event_log` (BTN-350); step 30 the built-in tracker, `builtin_*` (BTN-767); step 32 its attachments, `builtin_files` (BTN-773); step 43 the worktree folders a cleanup left held, `left_folders` (BTN-925); step 49 the copy of a built-in project's tasks into another tracker, `tracker_exports` and `tracker_export_tasks` (BTN-1073); step 50 the copied project's old key, `tracker_exports.source_key` (BTN-1076). A foreign key between tables is deferred, so that a copy inserts the
23
24
  * tables in any order (`insertRows`).
24
25
  */
25
26
  export const STEPS = [
@@ -313,6 +314,327 @@ export const STEPS = [
313
314
  delete from setting_values where key = 'trustClaude';
314
315
  delete from setting_definitions where key = 'trustClaude';
315
316
  `,
317
+ // No label keeps a task out by itself any more (BTN-758): `Manual` and `Вручную` did whatever the lists said. Every
318
+ // list of excluded labels an existing database keeps — Even Keel's, a profile's, a project's, a feed's — gets the two
319
+ // it lacks, and Even Keel's is written where it had none, so the same tasks stay out; a fresh one keeps `["Manual"]`.
320
+ `
321
+ create function pg_temp.with_manual(list jsonb) returns jsonb language sql immutable as $$
322
+ select list || coalesce((
323
+ select jsonb_agg(name order by n)
324
+ from unnest(array['Manual', 'Вручную']) with ordinality as m(name, n)
325
+ where not exists (select 1 from jsonb_array_elements_text(list) as e(have) where lower(trim(have)) = lower(name))
326
+ ), '[]'::jsonb)
327
+ $$;
328
+ update setting_values
329
+ set value = pg_temp.with_manual(value::jsonb)::text
330
+ where key = 'chain.excludedLabels' and jsonb_typeof(value::jsonb) = 'array';
331
+ insert into setting_definitions (key, kind, spec, default_value, scopes)
332
+ select 'chain.excludedLabels', 'list', '{}', '[]', 'global,project,profile'
333
+ where current_setting('even_keel.migration_from', true)::integer > 0
334
+ on conflict (key) do nothing;
335
+ insert into setting_values (key, project_id, qualifier, value, updated_at, updated_by)
336
+ select 'chain.excludedLabels', null, '', '["Manual", "Вручную"]', to_char(now() at time zone 'utc', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'), 'service'
337
+ where current_setting('even_keel.migration_from', true)::integer > 0
338
+ and not exists (select 1 from setting_values where key = 'chain.excludedLabels' and project_id is null and qualifier = '');
339
+ update tracker_profiles
340
+ set rules = jsonb_set(rules::jsonb, '{excludedLabels}', pg_temp.with_manual(rules::jsonb -> 'excludedLabels'))::text
341
+ where jsonb_typeof(rules::jsonb -> 'excludedLabels') = 'array';
342
+ update projects p
343
+ set feeds = (
344
+ select jsonb_agg(case when jsonb_typeof(f #> '{chain,excludedLabels}') = 'array'
345
+ then jsonb_set(f, '{chain,excludedLabels}', pg_temp.with_manual(f #> '{chain,excludedLabels}'))
346
+ else f end order by n)::text
347
+ from jsonb_array_elements(p.feeds::jsonb) with ordinality as e(f, n)
348
+ )
349
+ where exists (select 1 from jsonb_array_elements(p.feeds::jsonb) as e(f) where jsonb_typeof(f #> '{chain,excludedLabels}') = 'array');
350
+ drop function pg_temp.with_manual(jsonb);
351
+ `,
352
+ // The event log the page shows (BTN-350): what came while nobody looked, the newest `EVENT_LOG_LIMIT` entries.
353
+ `
354
+ create table event_log (
355
+ id integer primary key,
356
+ at text not null,
357
+ level text not null,
358
+ notice text not null,
359
+ place text
360
+ );
361
+ `,
362
+ // The built-in tracker (BTN-767): its tasks, each project's counter of numbers, labels and milestones per project, the
363
+ // labels of a task, the links between tasks of any of its projects, and the comments. `description_rev` grows only
364
+ // when the description changes, `version` on every change of the task.
365
+ `
366
+ create table builtin_counters (
367
+ project_id text primary key,
368
+ last integer not null
369
+ );
370
+ create table builtin_milestones (
371
+ id text primary key,
372
+ project_id text not null,
373
+ name text not null,
374
+ date bigint
375
+ );
376
+ create unique index builtin_milestones_name on builtin_milestones (project_id, lower(name));
377
+ create table builtin_labels (
378
+ id text primary key,
379
+ project_id text not null,
380
+ name text not null,
381
+ color integer not null
382
+ );
383
+ create unique index builtin_labels_name on builtin_labels (project_id, lower(name));
384
+ create table builtin_tasks (
385
+ id text primary key,
386
+ project_id text not null,
387
+ number integer not null,
388
+ title text not null,
389
+ description text not null,
390
+ description_rev integer not null,
391
+ status text not null,
392
+ priority text not null,
393
+ milestone_id text references builtin_milestones (id) on delete set null deferrable initially deferred,
394
+ parent_id text references builtin_tasks (id) on delete set null deferrable initially deferred,
395
+ version integer not null,
396
+ created_at text not null,
397
+ updated_at text not null,
398
+ unique (project_id, number)
399
+ );
400
+ create table builtin_task_labels (
401
+ task_id text not null references builtin_tasks (id) on delete cascade deferrable initially deferred,
402
+ label_id text not null references builtin_labels (id) on delete cascade deferrable initially deferred,
403
+ primary key (task_id, label_id)
404
+ );
405
+ create table builtin_relations (
406
+ from_id text not null references builtin_tasks (id) on delete cascade deferrable initially deferred,
407
+ to_id text not null references builtin_tasks (id) on delete cascade deferrable initially deferred,
408
+ kind text not null check (kind in ('blocks', 'relates')),
409
+ primary key (from_id, to_id, kind)
410
+ );
411
+ create table builtin_comments (
412
+ id integer generated by default as identity primary key,
413
+ task_id text not null references builtin_tasks (id) on delete cascade deferrable initially deferred,
414
+ author text not null check (author in ('person', 'agent', 'service')),
415
+ body text not null,
416
+ at text not null
417
+ );
418
+ create index builtin_comments_task on builtin_comments (task_id, id);
419
+ `,
420
+ // The model of the session an agent's comment came from (BTN-774), `<Provider> | <model>`; `null` for the rest.
421
+ `
422
+ alter table builtin_comments add column model text;
423
+ `,
424
+ // The attachments of the built-in tracker's tasks (BTN-773): a record per file of a task; the bytes are
425
+ // `files/<sha256>` next to `pgdata/`, one copy for the same bytes. `type` is what the browser declared, shown only.
426
+ `
427
+ create table builtin_files (
428
+ id text primary key,
429
+ task_id text not null references builtin_tasks (id) on delete cascade deferrable initially deferred,
430
+ name text not null,
431
+ type text not null,
432
+ size bigint not null,
433
+ sha256 text not null,
434
+ at text not null,
435
+ unique (task_id, sha256)
436
+ );
437
+ create index builtin_files_sha on builtin_files (sha256);
438
+ `,
439
+ // Aggregate views may hide a project; recording and chain operation stay unchanged (BTN-206).
440
+ `
441
+ insert into setting_definitions (key, kind, spec, default_value, scopes, qualifier)
442
+ select 'testProject', 'boolean', '{}'::jsonb, 'false'::jsonb, 'project', null
443
+ where exists (select 1 from projects)
444
+ on conflict (key) do nothing;
445
+ `,
446
+ // The keys of the reported `rare:` diagnostics and their open pairs (BTN-814), so a restart repeats no line.
447
+ `
448
+ create table rare_events (
449
+ entry text not null,
450
+ event text not null,
451
+ session_id text not null,
452
+ seen_at text not null,
453
+ waiting text,
454
+ primary key (entry, event, session_id)
455
+ );
456
+ create index rare_events_seen on rare_events (seen_at);
457
+ `,
458
+ // A session's real spend on a key that tells it, an OpenRouter key's `usage` (BTN-860); Tally takes the rows.
459
+ `
460
+ create table key_spends (
461
+ session_id text primary key,
462
+ account text not null,
463
+ usd double precision not null,
464
+ shared boolean not null,
465
+ reads integer not null,
466
+ first_at text not null,
467
+ last_at text not null
468
+ );
469
+ `,
470
+ // A turned-off tracker profile (BTN-830): the service reaches nothing of its host until it is turned on again.
471
+ `
472
+ alter table tracker_profiles add column disabled boolean not null default false;
473
+ `,
474
+ // The management key of an OpenRouter account (BTN-868), read only for the balance and kept out of its sessions.
475
+ `
476
+ create table management_keys (
477
+ account text primary key,
478
+ key text not null,
479
+ saved_at text not null
480
+ );
481
+ `,
482
+ // The page's hotkeys of each browser (BTN-880), under the id the browser keeps in its localStorage.
483
+ `
484
+ create table browser_hotkeys (
485
+ browser text primary key,
486
+ bindings text not null,
487
+ saved_at text not null
488
+ );
489
+ `,
490
+ // Progress of tasks_create batches, saved before the next task is created (BTN-896).
491
+ `
492
+ create table task_retries (
493
+ position bigint generated by default as identity primary key,
494
+ project_id text not null,
495
+ retry_key text not null,
496
+ ids text not null,
497
+ unique (project_id, retry_key)
498
+ );
499
+ `,
500
+ // The position of a tasks_create batch being created and the marker its task gets in the tracker (BTN-905).
501
+ `
502
+ alter table task_retries add column started text;
503
+ `,
504
+ // What the last transfer wrote into each Claude account folder's settings.json and the account's own layer (BTN-901).
505
+ `
506
+ create table account_settings (
507
+ account text primary key,
508
+ written text not null,
509
+ own text not null,
510
+ saved_at text not null
511
+ );
512
+ `,
513
+ // The estimate of a built-in task in minutes of the agent's work (BTN-911); null — none.
514
+ `
515
+ alter table builtin_tasks add column estimate integer;
516
+ `,
517
+ // The worktree folders a cleanup after Done left held, tried again after a restart (BTN-925).
518
+ `
519
+ create table left_folders (
520
+ path text primary key,
521
+ project_id text not null,
522
+ task text not null,
523
+ repo text not null,
524
+ until bigint not null
525
+ );
526
+ `,
527
+ // The context windows the agents named, kept through a restart: per account, model and launch settings, and per session (BTN-946).
528
+ `
529
+ create table context_windows (
530
+ account text not null,
531
+ model text not null,
532
+ settings text,
533
+ stamp text not null,
534
+ window_size integer,
535
+ measured_at bigint not null,
536
+ unique nulls not distinct (account, model, settings)
537
+ );
538
+ create table session_windows (
539
+ session_id text primary key,
540
+ window_size integer not null,
541
+ seen_at bigint not null
542
+ );
543
+ `,
544
+ `
545
+ create table badge_translations (
546
+ tracker text not null,
547
+ task text not null,
548
+ title_hash text not null,
549
+ attempted_at bigint not null,
550
+ title_en text,
551
+ primary key (tracker, task, title_hash)
552
+ );
553
+ create table badge_translation_spend (
554
+ message_id text primary key,
555
+ message text not null
556
+ );
557
+ `,
558
+ // `Manual` is no longer the default excluded label (BTN-971): an existing database that kept no shared list relied on
559
+ // it and gets `["Manual"]` written, so the same tasks stay out; a list it keeps is left alone, a fresh one gets nothing.
560
+ `
561
+ insert into setting_definitions (key, kind, spec, default_value, scopes)
562
+ select 'chain.excludedLabels', 'list', '{}', '[]', 'global,project,profile'
563
+ where current_setting('even_keel.migration_from', true)::integer > 0
564
+ on conflict (key) do nothing;
565
+ insert into setting_values (key, project_id, qualifier, value, updated_at, updated_by)
566
+ select 'chain.excludedLabels', null, '', '["Manual"]', to_char(now() at time zone 'utc', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'), 'service'
567
+ where current_setting('even_keel.migration_from', true)::integer > 0
568
+ and not exists (select 1 from setting_values where key = 'chain.excludedLabels' and project_id is null and qualifier = '');
569
+ `,
570
+ // What each task's sessions run on is Even Keel's record, not a tracker label (BTN-983). The `modelLabels` setting
571
+ // goes; a project it was on for is marked, and the service moves the run labels of its open tasks into runs once.
572
+ `
573
+ create table task_runs (
574
+ project_id text not null,
575
+ task text not null,
576
+ provider text,
577
+ model text,
578
+ effort text,
579
+ primary key (project_id, task)
580
+ );
581
+ create table run_label_imports (
582
+ project_id text primary key
583
+ );
584
+ insert into run_label_imports (project_id)
585
+ select p.id from projects p
586
+ where coalesce(
587
+ (select v.value from setting_values v where v.key = 'modelLabels' and v.project_id = p.id),
588
+ (select v.value from setting_values v where v.key = 'modelLabels' and v.project_id is null),
589
+ 'false') = 'true';
590
+ delete from setting_values where key = 'modelLabels';
591
+ delete from setting_definitions where key = 'modelLabels';
592
+ `,
593
+ // An OpenCode model is kept by the provider its account signs in to (BTN-984): `models` of `opencode` goes to the
594
+ // slot `opencode/<provider>` its prefix names, a prefix OpenCode's providers do not have to its own models.
595
+ `
596
+ update setting_values
597
+ set qualifier = 'opencode/' || case
598
+ when position('/' in (value::jsonb #>> '{}')) > 0
599
+ and split_part(value::jsonb #>> '{}', '/', 1) in ('openai', 'anthropic', 'openrouter', 'github-copilot', 'opencode-go', 'opencode')
600
+ then split_part(value::jsonb #>> '{}', '/', 1)
601
+ else 'opencode'
602
+ end
603
+ where key = 'models' and qualifier = 'opencode' and jsonb_typeof(value::jsonb) = 'string';
604
+ `,
605
+ // The copy of a built-in project's tasks into another tracker (BTN-1073): its target, and each task's new key and
606
+ // the stage it reached, so that a repeat goes on and a finished copy creates nothing again.
607
+ `
608
+ create table tracker_exports (
609
+ project_id text primary key,
610
+ profile text not null,
611
+ place text not null,
612
+ key text not null,
613
+ started_at text not null,
614
+ finished_at text
615
+ );
616
+ create table tracker_export_tasks (
617
+ project_id text not null,
618
+ task_id text not null,
619
+ number integer not null,
620
+ new_key text,
621
+ url text,
622
+ stage text not null check (stage in ('pending', 'created', 'linked', 'attached', 'journaled', 'marked')),
623
+ marker text,
624
+ done integer not null default 0,
625
+ at text not null,
626
+ primary key (project_id, task_id)
627
+ );
628
+ `,
629
+ // The project's key on the built-in tracker at the copy's start (BTN-1076): the switch gives the project the target's
630
+ // key, and Tally links the old ids `<source_key>-<number>` to the new ones by it. A copy of a project still on the
631
+ // built-in tracker takes its key now; one already switched has lost it.
632
+ `
633
+ alter table tracker_exports add column source_key text;
634
+ update tracker_exports e set source_key = p.key from projects p
635
+ where p.id = e.project_id
636
+ and exists (select 1 from setting_values v where v.key = 'tracker' and v.project_id = p.id and v.qualifier = '' and v.value = '"builtin"');
637
+ `,
316
638
  ];
317
639
  /** The version this code reads and writes. */
318
640
  export const DATABASE_VERSION = SQLITE_VERSIONS + STEPS.length;
@@ -333,13 +655,14 @@ export async function databaseVersion(db) {
333
655
  /**
334
656
  * Opens the database in `dataDir` (in memory without one, for tests) and brings it to the current schema; a database a
335
657
  * newer Even Keel wrote is refused before anything is written. One process holds the folder: `src/storage/owner.ts`.
658
+ * `before` runs when an existing database is about to take new steps, on its schema `from` (the backup's copy, BTN-1083).
336
659
  */
337
- export async function openDatabase(dataDir, steps = STEPS) {
660
+ export async function openDatabase(dataDir, steps = STEPS, before) {
338
661
  if (dataDir !== undefined)
339
662
  mkdirSync(dataDir, { recursive: true });
340
663
  const db = await PGlite.create(dataDir === undefined ? {} : { dataDir });
341
664
  try {
342
- await migrateDatabase(db, dataDir ?? 'memory', steps);
665
+ await migrateDatabase(db, dataDir ?? 'memory', steps, before);
343
666
  return db;
344
667
  }
345
668
  catch (error) {
@@ -347,10 +670,12 @@ export async function openDatabase(dataDir, steps = STEPS) {
347
670
  throw error;
348
671
  }
349
672
  }
350
- async function migrateDatabase(db, where, steps) {
673
+ async function migrateDatabase(db, where, steps, before) {
351
674
  const known = SQLITE_VERSIONS + steps.length;
352
675
  const from = await databaseVersion(db);
353
676
  refuseNewer(where, from, known);
677
+ if (before !== undefined && from > SQLITE_VERSIONS && from < known)
678
+ await before(db, from);
354
679
  for (let version = Math.max(from, SQLITE_VERSIONS); version < known; version++) {
355
680
  await db.transaction(async (tx) => {
356
681
  await tx.query("select set_config('even_keel.migration_from', $1, true)", [String(from)]);
@@ -380,6 +705,20 @@ export async function insertList(db, table, rows) {
380
705
  return;
381
706
  await db.query(`insert into "${table}" select * from json_populate_recordset(null::"${table}", $1)`, [JSON.stringify(rows)]);
382
707
  }
708
+ /**
709
+ * Makes the table hold exactly `rows`, in one statement, touching only what differs: a row whose `values` changed
710
+ * is updated, a key that is gone deleted, a new one inserted. A delete and an insert of the whole table left every
711
+ * row dead at every save (BTN-952). `keys` are the primary key's columns, `values` the rest.
712
+ */
713
+ export async function replaceRows(db, table, keys, values, rows) {
714
+ const list = (columns, of) => columns.map((column) => `${of}."${column}"`).join(', ');
715
+ const assigned = values.map((column) => `"${column}" = excluded."${column}"`).join(', ');
716
+ await db.query(`with fresh as (select * from json_populate_recordset(null::"${table}", $1)),
717
+ gone as (delete from "${table}" old where not exists (select 1 from fresh where (${list(keys, 'fresh')}) = (${list(keys, 'old')})))
718
+ insert into "${table}" as kept select * from fresh
719
+ on conflict (${keys.map((key) => `"${key}"`).join(', ')}) do update set ${assigned}
720
+ where (${list(values, 'kept')}) is distinct from (${list(values, 'excluded')})`, [JSON.stringify(rows)]);
721
+ }
383
722
  /** Runs `body` in one transaction: all of its writes or none. A call inside another one joins it. */
384
723
  export function inTransaction(db, body) {
385
724
  return 'transaction' in db ? db.transaction(body) : body(db);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The worktree folders a cleanup after Done left while a process still held them (BTN-870), kept through a restart
3
+ * (BTN-925); table `left_folders` (step 43, `docs/storage.md`). `until` is the end of the wait counted from the Done.
4
+ */
5
+ export async function loadLeftFolders(db) {
6
+ const { rows } = await db.query('select path, project_id, task, repo, until from left_folders order by path');
7
+ return rows.map((row) => ({ project: row.project_id, task: row.task, repo: row.repo, path: row.path, until: Number(row.until) }));
8
+ }
9
+ /** Starts its write at the call: see `Writes`. */
10
+ export async function saveLeftFolder(db, folder) {
11
+ await db.query(`insert into left_folders (path, project_id, task, repo, until) values ($1, $2, $3, $4, $5)
12
+ on conflict (path) do update set project_id = excluded.project_id, task = excluded.task, repo = excluded.repo, until = excluded.until`, [folder.path, folder.project, folder.task, folder.repo, folder.until]);
13
+ }
14
+ export async function dropLeftFolder(db, path) {
15
+ await db.query('delete from left_folders where path = $1', [path]);
16
+ }