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
@@ -2,7 +2,22 @@ const MODELS_URL = 'https://api.anthropic.com/v1/models?limit=1';
2
2
  const OPENAI_MODELS_URL = 'https://api.openai.com/v1/models';
3
3
  const OPENAI_ME_URL = 'https://api.openai.com/v1/me';
4
4
  const GITHUB_USER_URL = 'https://api.github.com/user';
5
+ /**
6
+ * Describes the key that asks, for free: whether it works, what it has spent (`usage`, BTN-860) and what is left of its
7
+ * own limit (BTN-847).
8
+ */
9
+ export const OPENROUTER_KEY_URL = 'https://openrouter.ai/api/v1/key';
5
10
  const API_VERSION = '2023-06-01';
11
+ const LIMIT_RESETS = ['daily', 'weekly', 'monthly'];
12
+ /** The key's own limit from the `data` of `GET /api/v1/key`; null — the key has none, or the answer does not tell it. */
13
+ export function openRouterLimit(data) {
14
+ if (typeof data !== 'object' || data === null)
15
+ return null;
16
+ const { limit, limit_remaining: remaining, limit_reset: reset } = data;
17
+ if (typeof limit !== 'number' || !Number.isFinite(limit) || typeof remaining !== 'number' || !Number.isFinite(remaining))
18
+ return null;
19
+ return { remaining, limit, reset: LIMIT_RESETS.find((each) => each === reset) ?? null };
20
+ }
6
21
  /** Asks Anthropic whether it takes the key: the models list costs no tokens. 401 and 403 are a refused key. */
7
22
  export function checkApiKey(key, timeoutMs, fetchImpl = fetch) {
8
23
  return askModels(MODELS_URL, { 'x-api-key': key, 'anthropic-version': API_VERSION }, timeoutMs, fetchImpl, 'anthropic-organization-id');
@@ -19,6 +34,17 @@ export async function checkOpenAiKey(key, timeoutMs, fetchImpl = fetch) {
19
34
  const me = await askModels(OPENAI_ME_URL, headers, timeoutMs, fetchImpl, 'openai-organization');
20
35
  return me.state === 'ok' && me.organization !== undefined ? me : verdict;
21
36
  }
37
+ /**
38
+ * Whether OpenRouter takes an OpenCode account's key (BTN-843): `/api/v1/key` describes the key for free, its own limit
39
+ * too (BTN-847). OpenRouter has no organization header.
40
+ */
41
+ export async function checkOpenRouterKey(key, timeoutMs, fetchImpl = fetch) {
42
+ return askModels(OPENROUTER_KEY_URL, { authorization: `Bearer ${key}` }, timeoutMs, fetchImpl, undefined, async (response) => {
43
+ const body = await response.json();
44
+ const limit = openRouterLimit(typeof body === 'object' && body !== null ? body.data : null);
45
+ return limit === null ? {} : { limit };
46
+ });
47
+ }
22
48
  /**
23
49
  * Whether GitHub takes a Copilot account's token (BTN-215): `/user` answers any valid token for free. Whether it may make
24
50
  * Copilot requests is not asked — only a session shows that.
@@ -26,7 +52,9 @@ export async function checkOpenAiKey(key, timeoutMs, fetchImpl = fetch) {
26
52
  export function checkGitHubToken(key, timeoutMs, fetchImpl = fetch) {
27
53
  return askModels(GITHUB_USER_URL, { authorization: `Bearer ${key}`, accept: 'application/vnd.github+json', 'user-agent': 'even-keel' }, timeoutMs, fetchImpl);
28
54
  }
29
- async function askModels(url, headers, timeoutMs, fetchImpl, organizationHeader) {
55
+ async function askModels(url, headers, timeoutMs, fetchImpl, organizationHeader,
56
+ /** What a working key's answer tells besides; without it the body is dropped unread, and an unreadable one tells nothing. */
57
+ describe) {
30
58
  let response;
31
59
  try {
32
60
  response = await fetchImpl(url, { headers, signal: AbortSignal.timeout(timeoutMs) });
@@ -34,10 +62,12 @@ async function askModels(url, headers, timeoutMs, fetchImpl, organizationHeader)
34
62
  catch (error) {
35
63
  return { state: 'unknown', reason: error instanceof Error ? error.message : String(error) };
36
64
  }
37
- await response.body?.cancel();
65
+ const told = response.ok && describe !== undefined ? await describe(response).catch(() => ({})) : {};
66
+ if (!(response.ok && describe !== undefined))
67
+ await response.body?.cancel();
38
68
  if (response.ok) {
39
69
  const organization = organizationHeader === undefined ? '' : (response.headers.get(organizationHeader)?.trim() ?? '');
40
- return organization === '' ? { state: 'ok' } : { state: 'ok', organization };
70
+ return organization === '' ? { state: 'ok', ...told } : { state: 'ok', organization, ...told };
41
71
  }
42
72
  if (response.status === 401 || response.status === 403)
43
73
  return { state: 'rejected' };
@@ -47,6 +77,7 @@ async function askModels(url, headers, timeoutMs, fetchImpl, organizationHeader)
47
77
  export class KeyChecks {
48
78
  intervalMs;
49
79
  checked = new Map();
80
+ limits = new Map();
50
81
  constructor(intervalMs) {
51
82
  this.intervalMs = intervalMs;
52
83
  }
@@ -54,14 +85,36 @@ export class KeyChecks {
54
85
  const last = this.checked.get(key);
55
86
  return last === undefined || now.getTime() - last.at >= this.intervalMs;
56
87
  }
88
+ /** True when the verdict or the key's limit changed. */
57
89
  note(key, verdict, now) {
58
- const rejected = verdict.state === 'unknown' ? (this.checked.get(key)?.rejected ?? false) : verdict.state === 'rejected';
90
+ const before = this.rejected(key);
91
+ const rejected = verdict.state === 'unknown' ? before : verdict.state === 'rejected';
59
92
  this.checked.set(key, { at: now.getTime(), rejected });
93
+ const limitChanged = verdict.state !== 'unknown' && this.noteLimit(key, verdict.state === 'ok' ? (verdict.limit ?? null) : null, now);
94
+ return rejected !== before || limitChanged;
95
+ }
96
+ /**
97
+ * A key's limit read between two checks, by a read of its spend (`readOpenRouterKey`); null — the key has none. The
98
+ * next check stays where it was. True when the limit changed.
99
+ */
100
+ noteLimit(key, limit, now) {
101
+ const before = this.limits.get(key);
102
+ const changed = limit === null ? before !== undefined :
103
+ before === undefined || before.remaining !== limit.remaining || before.limit !== limit.limit || before.reset !== limit.reset;
104
+ if (limit === null)
105
+ this.limits.delete(key);
106
+ else
107
+ this.limits.set(key, { ...limit, at: now.toISOString() });
108
+ return changed;
60
109
  }
61
110
  rejected(key) {
62
111
  return this.checked.get(key)?.rejected ?? false;
63
112
  }
113
+ limit(key) {
114
+ return this.limits.get(key) ?? null;
115
+ }
64
116
  forget(key) {
65
117
  this.checked.delete(key);
118
+ this.limits.delete(key);
66
119
  }
67
120
  }
@@ -0,0 +1,41 @@
1
+ /** Tells the account's credits bought and used, only to a management key: the key a session runs on gets 403. */
2
+ const OPENROUTER_CREDITS_URL = 'https://openrouter.ai/api/v1/credits';
3
+ /** The account's balance, `total_credits` less `total_usage`; 401 and 403 are a key that is no management key. */
4
+ export async function readOpenRouterBalance(key, timeoutMs, fetchImpl = fetch) {
5
+ let response;
6
+ try {
7
+ response = await fetchImpl(OPENROUTER_CREDITS_URL, { headers: { authorization: `Bearer ${key}` }, signal: AbortSignal.timeout(timeoutMs) });
8
+ }
9
+ catch (error) {
10
+ return { state: 'unknown', reason: error instanceof Error ? error.message : String(error) };
11
+ }
12
+ if (!response.ok) {
13
+ await response.body?.cancel();
14
+ if (response.status === 401 || response.status === 403)
15
+ return { state: 'rejected' };
16
+ return { state: 'unknown', reason: `HTTP ${response.status}` };
17
+ }
18
+ const body = await response.json().catch(() => null);
19
+ const data = typeof body === 'object' && body !== null ? body.data : null;
20
+ const { total_credits: credits, total_usage: usage } = typeof data === 'object' && data !== null ? data : {};
21
+ if (typeof credits !== 'number' || !Number.isFinite(credits) || typeof usage !== 'number' || !Number.isFinite(usage)) {
22
+ return { state: 'unknown', reason: 'no credits in the answer' };
23
+ }
24
+ return { state: 'ok', usd: Math.round((credits - usage) * 1e6) / 1e6 };
25
+ }
26
+ /**
27
+ * The management key of each OpenRouter account, kept out of the account's folder that its sessions read (BTN-868).
28
+ * Keyed by the account folder's key; table `management_keys` (step 37, `docs/storage.md`).
29
+ */
30
+ export async function loadManagementKeys(db) {
31
+ const { rows } = await db.query('select account, key from management_keys order by account');
32
+ return new Map(rows.map((row) => [row.account, row.key]));
33
+ }
34
+ /** Starts its write at the call: see `Writes`. */
35
+ export async function saveManagementKey(db, account, key, at) {
36
+ await db.query(`insert into management_keys (account, key, saved_at) values ($1, $2, $3)
37
+ on conflict (account) do update set key = excluded.key, saved_at = excluded.saved_at`, [account, key, at.toISOString()]);
38
+ }
39
+ export async function forgetManagementKey(db, account) {
40
+ await db.query('delete from management_keys where account = $1', [account]);
41
+ }
@@ -39,9 +39,17 @@ export function parseAuthStatus(text) {
39
39
  export function isApiKey(status) {
40
40
  return status?.authMethod === 'api_key' || status?.authMethod === 'api_key_helper';
41
41
  }
42
- /** An API account has no e-mail: its folder key stands in for it wherever an account is told apart by e-mail. */
42
+ /** A cloud account (BTN-822): the CLI says `third_party` for a folder whose `settings.json` turns a cloud on. */
43
+ export function isCloud(status) {
44
+ return status?.authMethod === 'third_party';
45
+ }
46
+ /** A key or a cloud pays per token: no plan limits, no claude.ai sign-in to renew or sign out of. */
47
+ export function paysPerToken(status) {
48
+ return isApiKey(status) || isCloud(status);
49
+ }
50
+ /** An API or cloud account has no e-mail: its folder key stands in for it wherever an account is told apart by e-mail. */
43
51
  export function withIdentity(status, key) {
44
- return status.loggedIn && status.email === null && isApiKey(status) ? { ...status, email: key } : status;
52
+ return status.loggedIn && status.email === null && paysPerToken(status) ? { ...status, email: key } : status;
45
53
  }
46
54
  export function cleanOutput(raw) {
47
55
  return stripAnsi(raw).replace(/\r\n?/g, '\n');
@@ -177,13 +185,19 @@ export function launchBlock(view, key = view.active) {
177
185
  return freeHeld(view.accounts, key);
178
186
  }
179
187
  /**
180
- * The keys of the Codex accounts on the free plan past the first in the folders' order: OpenAI's terms forbid several
181
- * free accounts to get round the limits, so only the first of them works (BTN-176).
188
+ * Free ChatGPT folders past the first identity in folder order. That identity may have one folder per agent.
182
189
  */
183
190
  export function extraFree(accounts) {
184
- return freeCodex(accounts)
185
- .slice(1)
186
- .map((entry) => entry.key);
191
+ const [first, ...rest] = freeChatGpt(accounts);
192
+ if (first === undefined)
193
+ return [];
194
+ const agents = new Set([first.agent]);
195
+ return rest.filter(entry => {
196
+ if (!sameEmail(first.status, entry.status) || agents.has(entry.agent))
197
+ return true;
198
+ agents.add(entry.agent);
199
+ return false;
200
+ }).map(entry => entry.key);
187
201
  }
188
202
  /**
189
203
  * Whether an account of the agent just added takes the shared pool's entry for it: it does while that entry names no
@@ -203,30 +217,39 @@ export function missingNotice(agent) {
203
217
  return notice(agent === CODEX ? 'login.codexMissing' : 'login.claudeMissing', {});
204
218
  }
205
219
  /**
206
- * Why a Codex sign-in on the free plan is not added: another account already holds the one free plan, or the sign-in
207
- * is that very account again.
220
+ * Why a free ChatGPT sign-in is not added. The same identity in another agent shares its allowance.
208
221
  */
209
222
  export function secondFreeProblem(accounts, agent, status) {
210
- if (agent !== CODEX || !isFree(status))
223
+ if (!isFree(agent, status))
211
224
  return undefined;
212
- const first = freeCodex(accounts)[0];
225
+ const free = freeChatGpt(accounts);
226
+ const first = free[0];
213
227
  if (first === undefined)
214
228
  return undefined;
215
229
  const account = first.status?.email ?? first.key;
216
- const same = status.email !== null && first.status?.email?.toLowerCase() === status.email.toLowerCase();
230
+ const same = sameEmail(first.status, status);
231
+ if (same && !free.some(entry => entry.agent === agent && sameEmail(entry.status, status)))
232
+ return undefined;
217
233
  return notice(same ? 'account.sameFree' : 'account.secondFree', { account });
218
234
  }
219
235
  function freeHeld(accounts, key) {
220
- const [first, ...rest] = freeCodex(accounts);
221
- if (first === undefined || !rest.some((entry) => entry.key === key))
236
+ const first = freeChatGpt(accounts)[0];
237
+ if (first === undefined || !extraFree(accounts).includes(key))
222
238
  return undefined;
223
239
  return notice('account.extraFree', { account: first.status?.email ?? first.key });
224
240
  }
225
- function freeCodex(accounts) {
226
- return accounts.filter((entry) => entry.agent === CODEX && isFree(entry.status));
241
+ function freeChatGpt(accounts) {
242
+ return accounts.filter((entry) => isFree(entry.agent, entry.status));
243
+ }
244
+ function isFree(agent, status) {
245
+ if (status?.loggedIn !== true)
246
+ return false;
247
+ if (agent === CODEX)
248
+ return status.subscriptionType === FREE_PLAN && !isApiKey(status);
249
+ return agent === OPENCODE && status.authMethod === 'oauth' && status.chatgptPlan === FREE_PLAN;
227
250
  }
228
- function isFree(status) {
229
- return status?.loggedIn === true && status.subscriptionType === FREE_PLAN;
251
+ function sameEmail(left, right) {
252
+ return !!left.email && !!right.email && left.email.toLowerCase() === right.email.toLowerCase();
230
253
  }
231
254
  function stringOf(value) {
232
255
  return typeof value === 'string' && value !== '' ? value : null;
@@ -1,14 +1,19 @@
1
1
  import { CODEX } from '../codex/name.js';
2
2
  import { COPILOT } from '../copilot/name.js';
3
+ import { keyVendor } from '../opencode/home.js';
3
4
  import { OPENCODE } from '../opencode/name.js';
4
5
  const CLAUDE_API = 'https://api.anthropic.com';
5
6
  const OPENAI_API = 'https://api.openai.com';
6
7
  const OPENCODE_API = 'https://opencode.ai';
7
8
  const GITHUB_API = 'https://api.github.com';
8
- /** The API the agent's sign-in renews its tokens against: account calls wait until it answers (EKR-15). */
9
- export function providerUrl(agent) {
9
+ const OPENROUTER_API = 'https://openrouter.ai';
10
+ /**
11
+ * The API the agent's sign-in renews its tokens against: account calls wait until it answers (EKR-15). An OpenCode
12
+ * folder on an OpenRouter key, `key`, talks only to OpenRouter (BTN-843).
13
+ */
14
+ export function providerUrl(agent, key = null) {
10
15
  if (agent === OPENCODE)
11
- return OPENCODE_API;
16
+ return key !== null && keyVendor(key) === 'openrouter' ? OPENROUTER_API : OPENCODE_API;
12
17
  if (agent === COPILOT)
13
18
  return GITHUB_API;
14
19
  return agent === CODEX ? OPENAI_API : CLAUDE_API;
@@ -1,17 +1,26 @@
1
- import { checkCredit, checkOpenAiCredit } from './credit.js';
2
- import { checkApiKey, checkGitHubToken, checkOpenAiKey } from './keycheck.js';
1
+ import { checkCredit, checkOpenAiCredit, checkOpenRouterCredit } from './credit.js';
2
+ import { checkApiKey, checkGitHubToken, checkOpenAiKey, checkOpenRouterKey } from './keycheck.js';
3
3
  export const KEY_CHECK_MS = 60 * 60_000;
4
4
  export const KEY_CHECK_TIMEOUT_MS = 15_000;
5
5
  export const CREDIT_CHECK_MS = 5 * 60_000;
6
+ /** The OpenRouter key's `usage` is read before a turn too: a short wait, a missed read only moves the growth on (BTN-860). */
7
+ export const KEY_SPEND_TIMEOUT_MS = 5_000;
8
+ /** How long after the last turn a growth of `usage` still goes to its session, and how often the key is read meanwhile. */
9
+ export const KEY_SPEND_TAIL_MS = 10 * 60_000;
10
+ export const KEY_SPEND_POLL_MS = 60_000;
6
11
  /**
7
12
  * The key and credit checks by whose key it is (`keyProvider`). GitHub has no way to ask about a token's AI credits: a
8
13
  * Copilot account waits out spent credit by its monthly allowance instead (`Agent.keyUsage`, BTN-341).
9
14
  */
10
- export const KEY_CHECKS = { anthropic: checkApiKey, openai: checkOpenAiKey, github: checkGitHubToken };
15
+ export const KEY_CHECKS = { anthropic: checkApiKey, openai: checkOpenAiKey, openrouter: checkOpenRouterKey, github: checkGitHubToken };
11
16
  export const CREDIT_CHECKS = {
12
17
  anthropic: checkCredit,
13
18
  openai: checkOpenAiCredit,
19
+ openrouter: checkOpenRouterCredit,
14
20
  github: async () => ({ state: 'unknown', reason: 'GitHub does not tell the AI credits of a token' }),
15
21
  };
22
+ /** The check turn of a new cloud account: the CLI gives up resolving AWS credentials after 60 s itself. */
23
+ export const CLOUD_CHECK_TIMEOUT_MS = 120_000;
24
+ export const CLOUD_CHECK_PROMPT = 'This is a connection check. Reply with the single word OK and use no tools.';
16
25
  export const APP_POLL_MS = 5_000;
17
26
  export const LOGIN_TIMEOUT_MS = 10 * 60_000;
@@ -0,0 +1,92 @@
1
+ import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { pathsOf, samePath } from '../paths.js';
5
+ import { SETTINGS_GUARD_MARK as MARK, stripSettingsGuard } from './settingsGuardStrip.js';
6
+ export { stripSettingsGuard };
7
+ function object(value) {
8
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
9
+ }
10
+ export function withSettingsGuard(settings, config) {
11
+ const clean = stripSettingsGuard(settings);
12
+ const hooks = object(clean.hooks);
13
+ const script = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? '../../dist/src/account/settingsHook.js' : './settingsHook.js', import.meta.url));
14
+ const data = Buffer.from(JSON.stringify(config)).toString('base64url');
15
+ return { ...clean, hooks: { ...hooks, PreToolUse: [
16
+ ...(Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : []),
17
+ { matcher: 'Edit|Write|MultiEdit', hooks: [{ type: 'command', command: process.execPath,
18
+ args: [script, MARK, data], timeout: 5, onFailure: 'continue' }] },
19
+ ] } };
20
+ }
21
+ export function removeSettingsGuard(dir) {
22
+ const file = join(dir, 'settings.json');
23
+ try {
24
+ const settings = JSON.parse(readFileSync(file, 'utf8'));
25
+ const clean = stripSettingsGuard(settings);
26
+ if (clean !== settings)
27
+ writeFileSync(file, JSON.stringify(clean, null, 2));
28
+ }
29
+ catch (error) {
30
+ if (error.code === 'ENOENT')
31
+ return;
32
+ throw error;
33
+ }
34
+ }
35
+ /** Uninstall keeps account folders and user hooks; only managed Claude folders are visited. */
36
+ export function removeAccountSettingsGuards(accountsDir, globalDir) {
37
+ let entries;
38
+ try {
39
+ entries = readdirSync(accountsDir, { withFileTypes: true });
40
+ }
41
+ catch (error) {
42
+ if (error.code === 'ENOENT')
43
+ return;
44
+ throw error;
45
+ }
46
+ for (const entry of entries) {
47
+ const dir = join(accountsDir, entry.name);
48
+ if (!entry.isDirectory() || samePath(dir, globalDir))
49
+ continue;
50
+ try {
51
+ removeSettingsGuard(dir);
52
+ }
53
+ catch (error) {
54
+ console.warn(`account settings guard: could not remove hook from ${dir}: ${String(error)}`);
55
+ }
56
+ }
57
+ }
58
+ /** No HTTP call for ordinary edits. The service confirms that a candidate belongs to a listed Claude account. */
59
+ export async function guardSettingsEdit(input, config, ask = async () => {
60
+ const response = await fetch(`${config.url}/api/state`, { signal: AbortSignal.timeout(1500), redirect: 'error' });
61
+ return response.ok ? response.json() : null;
62
+ }, platform = process.platform) {
63
+ try {
64
+ const event = object(input);
65
+ if (!['Edit', 'Write', 'MultiEdit'].includes(String(event.tool_name)))
66
+ return null;
67
+ const tool = object(event.tool_input);
68
+ const paths = pathsOf(platform);
69
+ const targets = [tool.file_path, ...(Array.isArray(tool.edits) ? tool.edits.map((edit) => object(edit).file_path) : [])]
70
+ .filter((path) => typeof path === 'string' && path !== '')
71
+ .map((path) => paths.resolve(typeof event.cwd === 'string' ? event.cwd : process.cwd(), path))
72
+ .filter((path) => platform === 'linux' ? paths.basename(path) === 'settings.json' : paths.basename(path).toLowerCase() === 'settings.json')
73
+ .filter((path) => samePath(paths.dirname(paths.dirname(path)), config.accountsDir, platform)
74
+ && !samePath(paths.dirname(path), config.globalDir, platform)
75
+ && samePath(path, paths.join(paths.dirname(path), 'settings.json'), platform));
76
+ if (targets.length === 0)
77
+ return null;
78
+ const accounts = object(object(await ask()).account).accounts;
79
+ if (!Array.isArray(accounts))
80
+ return null;
81
+ const managed = accounts.some((value) => {
82
+ const account = object(value);
83
+ return account.agent === 'claude' && account.global === false && typeof account.key === 'string'
84
+ && paths.basename(account.key) === account.key
85
+ && targets.some((path) => samePath(path, paths.join(config.accountsDir, account.key, 'settings.json'), platform));
86
+ });
87
+ return managed ? 'Even Keel manages this account folder’s settings.json. Edit shared settings in ~/.claude/settings.json; Even Keel transfers them to all Claude accounts before launch. For account-only settings, use Accounts in Even Keel: resolve a settings change with “Keep for this account only”.' : null;
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
@@ -0,0 +1,36 @@
1
+ export const SETTINGS_GUARD_MARK = '--even-keel-account-settings';
2
+ function object(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
4
+ }
5
+ /** Removes only Even Keel's command, even when somebody put it beside a user's command in one group. */
6
+ export function stripSettingsGuard(settings) {
7
+ const hooks = { ...object(settings.hooks) };
8
+ let changed = false;
9
+ for (const [event, groups] of Object.entries(hooks)) {
10
+ if (!Array.isArray(groups))
11
+ continue;
12
+ const kept = groups.flatMap((group) => {
13
+ const entry = object(group);
14
+ if (!Array.isArray(entry.hooks))
15
+ return [group];
16
+ const commands = entry.hooks.filter((hook) => {
17
+ const command = object(hook).command;
18
+ const args = object(hook).args;
19
+ return !(typeof command === 'string' && command.includes(` ${SETTINGS_GUARD_MARK} `))
20
+ && !(Array.isArray(args) && args.includes(SETTINGS_GUARD_MARK));
21
+ });
22
+ if (commands.length === entry.hooks.length)
23
+ return [group];
24
+ changed = true;
25
+ return commands.length === 0 ? [] : [{ ...entry, hooks: commands }];
26
+ });
27
+ if (kept.length > 0 || groups.length === 0)
28
+ hooks[event] = kept;
29
+ else
30
+ delete hooks[event];
31
+ }
32
+ if (!changed)
33
+ return settings;
34
+ const { hooks: _, ...rest } = settings;
35
+ return Object.keys(hooks).length === 0 ? rest : { ...rest, hooks };
36
+ }
@@ -0,0 +1,15 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { guardSettingsEdit } from './settingsGuard.js';
3
+ try {
4
+ const index = process.argv.indexOf('--even-keel-account-settings');
5
+ const config = JSON.parse(Buffer.from(process.argv[index + 1], 'base64url').toString('utf8'));
6
+ const reason = await guardSettingsEdit(JSON.parse(readFileSync(0, 'utf8')), config);
7
+ if (reason !== null) {
8
+ process.stdout.write(JSON.stringify({ hookSpecificOutput: {
9
+ hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: reason,
10
+ } }));
11
+ }
12
+ }
13
+ catch {
14
+ // An unavailable service or malformed hook input must not hold an unrelated edit.
15
+ }
@@ -0,0 +1,190 @@
1
+ import { readFileSync, statSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { fail } from '../notice/notice.js';
4
+ import { isCloudVariable } from './cloud.js';
5
+ import { API_KEY_VARIABLE, mergeSettings } from './share.js';
6
+ import { stripSettingsGuard } from './settingsGuard.js';
7
+ export const EDIT_CHOICES = ['share', 'own', 'discard'];
8
+ /**
9
+ * Keys the CLI writes into `settings.json` with no one asking for a setting: `claude install` and the update channel's
10
+ * switch. Read in the 2.1.319 binary; the startup migrations of `model` and `env` were seen there too, but a person
11
+ * writes those keys as well, so they stay watched (`docs/unverified/accounts.md`).
12
+ */
13
+ const SILENT_KEYS = new Set(['autoUpdatesChannel', 'minimumVersion']);
14
+ /** The folder owns these whatever the global settings say (`mergeSettings`), so a change of them is no edit. */
15
+ const FOLDER_KEYS = new Set(['apiKeyHelper']);
16
+ function isOwnVariable(name) {
17
+ return name === API_KEY_VARIABLE || isCloudVariable(name);
18
+ }
19
+ function sharedEnv(value) {
20
+ return Object.fromEntries(Object.entries(objectOf(value)).filter(([name]) => !isOwnVariable(name)));
21
+ }
22
+ function ownVariables(value) {
23
+ return Object.fromEntries(Object.entries(objectOf(value)).filter(([name]) => isOwnVariable(name)));
24
+ }
25
+ function comparable(key, value) {
26
+ if (value === undefined)
27
+ return undefined;
28
+ if (key === 'hooks') {
29
+ const hooks = Object.fromEntries(Object.entries(objectOf(value)).filter(([, groups]) => !Array.isArray(groups) || groups.length > 0));
30
+ return Object.keys(hooks).length === 0 ? undefined : JSON.stringify(hooks);
31
+ }
32
+ return JSON.stringify(key === 'env' ? sharedEnv(value) : value);
33
+ }
34
+ /** The top-level keys of the folder's file whose value moved away from what the last transfer wrote there. */
35
+ export function editedKeys(folder, written) {
36
+ folder = stripSettingsGuard(folder);
37
+ written = stripSettingsGuard(written);
38
+ const keys = new Set([...Object.keys(folder), ...Object.keys(written)]);
39
+ return [...keys].filter((key) => !SILENT_KEYS.has(key) && !FOLDER_KEYS.has(key) && comparable(key, folder[key]) !== comparable(key, written[key])).sort();
40
+ }
41
+ /** The transfer of `settings.json` with the account's layer on top and the folder's own edits kept (`docs/accounts.md`). */
42
+ export function planSettings(global, folder, record, discard = new Set()) {
43
+ const file = mergeSettings(global, folder);
44
+ for (const [key, value] of Object.entries(record?.own ?? {})) {
45
+ if (value === null)
46
+ delete file[key];
47
+ else
48
+ file[key] = key === 'env' ? { ...objectOf(value), ...ownVariables(folder?.env) } : value;
49
+ }
50
+ const written = { ...file };
51
+ // An edit the transfer would write anyway — made shared, kept as the account's own — is resolved.
52
+ const edits = record === undefined || folder === undefined ? [] : editedKeys(folder, record.written)
53
+ .filter((key) => !discard.has(key) && comparable(key, folder[key]) !== comparable(key, file[key]));
54
+ for (const key of edits) {
55
+ setOrDelete(file, key, folder?.[key]);
56
+ setOrDelete(written, key, record?.written[key]);
57
+ }
58
+ return { file, written, edits };
59
+ }
60
+ /**
61
+ * The records of every account folder, held in memory and written behind (`save`): the transfer is synchronous. Reads
62
+ * the folder's file on each `edits`, so the page shows an edit as soon as it is made, not at the next launch.
63
+ */
64
+ export class AccountSettings {
65
+ records;
66
+ globalDir;
67
+ save;
68
+ discards = new Map();
69
+ seen = new Map();
70
+ version = 0;
71
+ constructor(records, globalDir, save) {
72
+ this.records = records;
73
+ this.globalDir = globalDir;
74
+ this.save = save;
75
+ }
76
+ /** The `settings.json` part of `shareConfig` for the folder: remembers what it wrote and uses up a discard. */
77
+ planner(account) {
78
+ return (global, folder) => {
79
+ const discard = this.discards.get(account) ?? new Set();
80
+ const record = this.records.get(account);
81
+ const plan = planSettings(global, folder, record, discard);
82
+ this.discards.delete(account);
83
+ const next = { written: plan.written, own: record?.own ?? {} };
84
+ if (record === undefined || JSON.stringify(record) !== JSON.stringify(next))
85
+ this.keep(account, next);
86
+ return plan.file;
87
+ };
88
+ }
89
+ /** The keys changed in the folder since the last transfer; none before the first one. */
90
+ edits(home) {
91
+ const record = this.records.get(home.key);
92
+ if (record === undefined)
93
+ return [];
94
+ const file = join(home.dir, 'settings.json');
95
+ let stamp;
96
+ try {
97
+ const stat = statSync(file);
98
+ stamp = `${this.version}:${stat.mtimeMs}:${stat.size}`;
99
+ }
100
+ catch {
101
+ return [];
102
+ }
103
+ const cached = this.seen.get(home.key);
104
+ if (cached?.stamp === stamp)
105
+ return cached.edits;
106
+ const folder = readJson(file);
107
+ const discard = this.discards.get(home.key);
108
+ const edits = folder === undefined ? [] : editedKeys(folder, record.written).filter((key) => discard?.has(key) !== true);
109
+ this.seen.set(home.key, { stamp, edits });
110
+ return edits;
111
+ }
112
+ /** The keys of the account's own layer. */
113
+ own(account) {
114
+ return Object.keys(this.records.get(account)?.own ?? {}).sort();
115
+ }
116
+ /** Takes effect at the next transfer into the folder, which the caller starts. */
117
+ resolve(home, key, choice) {
118
+ const record = this.records.get(home.key);
119
+ if (record === undefined || !this.edits(home).includes(key))
120
+ throw fail('account.settingsNoEdit', { account: home.key, key });
121
+ const value = stripSettingsGuard(readJson(join(home.dir, 'settings.json')) ?? {})[key];
122
+ if (choice === 'discard') {
123
+ this.discards.set(home.key, new Set([...(this.discards.get(home.key) ?? []), key]));
124
+ this.version++;
125
+ return;
126
+ }
127
+ if (choice === 'own') {
128
+ this.keep(home.key, { ...record, own: { ...record.own, [key]: value === undefined ? null : key === 'env' ? sharedEnv(value) : value } });
129
+ return;
130
+ }
131
+ const file = join(this.globalDir, 'settings.json');
132
+ const global = readJson(file) ?? {};
133
+ setOrDelete(global, key, key === 'env' && value !== undefined ? { ...sharedEnv(value), ...ownVariables(global.env) } : value);
134
+ writeFileSync(file, JSON.stringify(global, null, 2));
135
+ this.version++;
136
+ }
137
+ /** Takes effect at the next transfer into the folder, which the caller starts. */
138
+ dropOwn(home, key) {
139
+ const record = this.records.get(home.key);
140
+ if (record === undefined || !(key in record.own))
141
+ throw fail('account.settingsNoOwn', { account: home.key, key });
142
+ const { [key]: _, ...own } = record.own;
143
+ this.keep(home.key, { ...record, own });
144
+ }
145
+ forget(account) {
146
+ this.discards.delete(account);
147
+ this.seen.delete(account);
148
+ if (!this.records.delete(account))
149
+ return;
150
+ this.version++;
151
+ this.save(account, null);
152
+ }
153
+ keep(account, record) {
154
+ this.records.set(account, record);
155
+ this.version++;
156
+ this.save(account, record);
157
+ }
158
+ }
159
+ /** Table `account_settings` (`docs/storage.md`). */
160
+ export async function loadAccountSettings(db) {
161
+ const { rows } = await db.query('select account, written, own from account_settings order by account');
162
+ return new Map(rows.map((row) => [row.account, { written: objectOf(JSON.parse(row.written)), own: objectOf(JSON.parse(row.own)) }]));
163
+ }
164
+ /** Starts its write at the call: see `Writes`. */
165
+ export async function saveAccountSettings(db, account, record, at) {
166
+ if (record === null) {
167
+ await db.query('delete from account_settings where account = $1', [account]);
168
+ return;
169
+ }
170
+ await db.query(`insert into account_settings (account, written, own, saved_at) values ($1, $2, $3, $4)
171
+ on conflict (account) do update set written = excluded.written, own = excluded.own, saved_at = excluded.saved_at`, [account, JSON.stringify(record.written), JSON.stringify(record.own), at.toISOString()]);
172
+ }
173
+ function setOrDelete(target, key, value) {
174
+ if (value === undefined)
175
+ delete target[key];
176
+ else
177
+ target[key] = value;
178
+ }
179
+ function readJson(file) {
180
+ try {
181
+ const value = JSON.parse(readFileSync(file, 'utf8'));
182
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
183
+ }
184
+ catch {
185
+ return undefined;
186
+ }
187
+ }
188
+ function objectOf(value) {
189
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
190
+ }
@@ -0,0 +1,7 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ import { loadEnv } from '../locations.js';
4
+ import { accountsRoot } from './homes.js';
5
+ import { removeAccountSettingsGuards } from './settingsGuard.js';
6
+ loadEnv();
7
+ removeAccountSettingsGuards(accountsRoot(process.env), process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude'));