even-keel 0.0.2 → 0.2.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 (537) hide show
  1. package/.claude-plugin/marketplace.json +52 -0
  2. package/.env.example +66 -0
  3. package/CHANGELOG.md +315 -0
  4. package/LICENSE +21 -0
  5. package/README.md +199 -3
  6. package/dist/src/account/apps.js +100 -0
  7. package/dist/src/account/credit.js +117 -0
  8. package/dist/src/account/current.js +13 -0
  9. package/dist/src/account/daemon.js +65 -0
  10. package/dist/src/account/globals.js +25 -0
  11. package/dist/src/account/header-levels.js +22 -0
  12. package/dist/src/account/homes.js +332 -0
  13. package/dist/src/account/keychain.js +134 -0
  14. package/dist/src/account/keycheck.js +67 -0
  15. package/dist/src/account/ledger.js +92 -0
  16. package/dist/src/account/model.js +234 -0
  17. package/dist/src/account/network.js +51 -0
  18. package/dist/src/account/organizations.js +17 -0
  19. package/dist/src/account/service-defaults.js +17 -0
  20. package/dist/src/account/share.js +275 -0
  21. package/dist/src/account/transport.js +29 -0
  22. package/dist/src/account/vscode.js +84 -0
  23. package/dist/src/account/watcher.js +451 -0
  24. package/dist/src/agent/adapters.js +10 -0
  25. package/dist/src/agent/cli-state.js +1 -0
  26. package/dist/src/agent/contract.js +7 -0
  27. package/dist/src/agent/copies.js +38 -0
  28. package/dist/src/agent/copy.js +42 -0
  29. package/dist/src/agent/download.js +39 -0
  30. package/dist/src/agent/env.js +23 -0
  31. package/dist/src/agent/models.js +90 -0
  32. package/dist/src/agent/npm.js +55 -0
  33. package/dist/src/agent/oneturn.js +48 -0
  34. package/dist/src/agent/pinned.js +79 -0
  35. package/dist/src/agent/process.js +76 -0
  36. package/dist/src/agent/projectRules.js +54 -0
  37. package/dist/src/agent/providers.js +39 -0
  38. package/dist/src/agent/versions.js +89 -0
  39. package/dist/src/agent/windows.js +39 -0
  40. package/dist/src/ansi.js +6 -0
  41. package/dist/src/autostart.js +80 -0
  42. package/dist/src/chain/answers.js +26 -0
  43. package/dist/src/chain/archive.js +25 -0
  44. package/dist/src/chain/carry.js +97 -0
  45. package/dist/src/chain/cleanup.js +134 -0
  46. package/dist/src/chain/dispatcher.js +800 -0
  47. package/dist/src/chain/fix.js +55 -0
  48. package/dist/src/chain/forward.js +195 -0
  49. package/dist/src/chain/handover.js +350 -0
  50. package/dist/src/chain/launches.js +193 -0
  51. package/dist/src/chain/limitNotice.js +30 -0
  52. package/dist/src/chain/lists.js +174 -0
  53. package/dist/src/chain/log.js +23 -0
  54. package/dist/src/chain/maincheck.js +449 -0
  55. package/dist/src/chain/mainci.js +116 -0
  56. package/dist/src/chain/mainfix.js +180 -0
  57. package/dist/src/chain/mainwait.js +73 -0
  58. package/dist/src/chain/milestones.js +67 -0
  59. package/dist/src/chain/model.js +6 -0
  60. package/dist/src/chain/moves.js +100 -0
  61. package/dist/src/chain/order.js +266 -0
  62. package/dist/src/chain/overage.js +44 -0
  63. package/dist/src/chain/pauses.js +81 -0
  64. package/dist/src/chain/places.js +42 -0
  65. package/dist/src/chain/prompts.js +199 -0
  66. package/dist/src/chain/relay.js +153 -0
  67. package/dist/src/chain/restartGuard.js +17 -0
  68. package/dist/src/chain/reviews.js +316 -0
  69. package/dist/src/chain/rules.js +59 -0
  70. package/dist/src/chain/shelved.js +33 -0
  71. package/dist/src/chain/skippedown.js +20 -0
  72. package/dist/src/chain/snapshots.js +37 -0
  73. package/dist/src/chain/start.js +52 -0
  74. package/dist/src/chain/store.js +146 -0
  75. package/dist/src/chain/unchanged.js +71 -0
  76. package/dist/src/changelog/diff.js +118 -0
  77. package/dist/src/changelog/draft.js +59 -0
  78. package/dist/src/changelog/drafts.js +121 -0
  79. package/dist/src/changelog/file.js +146 -0
  80. package/dist/src/changelog/store.js +75 -0
  81. package/dist/src/ci/adapters.js +65 -0
  82. package/dist/src/ci/forgejo-profile.js +86 -0
  83. package/dist/src/ci/forgejo.js +62 -0
  84. package/dist/src/ci/github.js +53 -0
  85. package/dist/src/ci/gitlab.js +62 -0
  86. package/dist/src/ci/host.js +14 -0
  87. package/dist/src/ci/http.js +71 -0
  88. package/dist/src/ci/model.js +41 -0
  89. package/dist/src/ci/protection-audit.js +49 -0
  90. package/dist/src/ci/protection-model.js +1 -0
  91. package/dist/src/ci/protection.js +75 -0
  92. package/dist/src/ci/remote.js +105 -0
  93. package/dist/src/ci/report.js +114 -0
  94. package/dist/src/ci/shared.js +74 -0
  95. package/dist/src/ci/verdict.js +61 -0
  96. package/dist/src/ci/watcher.js +188 -0
  97. package/dist/src/ci/watches.js +116 -0
  98. package/dist/src/ci/wiring.js +26 -0
  99. package/dist/src/claude/adapter.js +174 -0
  100. package/dist/src/claude/calls.js +88 -0
  101. package/dist/src/claude/cli.js +451 -0
  102. package/dist/src/claude/context.js +33 -0
  103. package/dist/src/claude/instructions.js +12 -0
  104. package/dist/src/claude/leftovers.js +32 -0
  105. package/dist/src/claude/name.js +2 -0
  106. package/dist/src/claude/release.js +69 -0
  107. package/dist/src/claude/sdk/executor.js +214 -0
  108. package/dist/src/claude/sdk/host.js +422 -0
  109. package/dist/src/claude/sdk/pipe.js +134 -0
  110. package/dist/src/claude/sdk/registry.js +88 -0
  111. package/dist/src/claude/sdk/release.js +26 -0
  112. package/dist/src/claude/sdk/types.js +1 -0
  113. package/dist/src/claude/tree.js +103 -0
  114. package/dist/src/claude/trust.js +12 -0
  115. package/dist/src/cli-args.js +36 -0
  116. package/dist/src/cli-check/lease.js +35 -0
  117. package/dist/src/cli-check/run.js +381 -0
  118. package/dist/src/cli-check/scheduler.js +134 -0
  119. package/dist/src/cli-check/support.js +105 -0
  120. package/dist/src/cli.js +196 -0
  121. package/dist/src/codex/adapter.js +112 -0
  122. package/dist/src/codex/appserver.js +68 -0
  123. package/dist/src/codex/cli.js +360 -0
  124. package/dist/src/codex/mcp.js +8 -0
  125. package/dist/src/codex/name.js +2 -0
  126. package/dist/src/codex/plugins.js +137 -0
  127. package/dist/src/codex/process.js +81 -0
  128. package/dist/src/codex/protection.js +32 -0
  129. package/dist/src/codex/release.js +33 -0
  130. package/dist/src/codex/rollout.js +478 -0
  131. package/dist/src/codex/rolloutImages.js +49 -0
  132. package/dist/src/codex/rules.js +141 -0
  133. package/dist/src/codex/tail.js +53 -0
  134. package/dist/src/codex/turns.js +140 -0
  135. package/dist/src/codex/usage.js +88 -0
  136. package/dist/src/codex/version.js +2 -0
  137. package/dist/src/config-form.js +359 -0
  138. package/dist/src/config-store.js +184 -0
  139. package/dist/src/config.js +524 -0
  140. package/dist/src/copilot/adapter.js +121 -0
  141. package/dist/src/copilot/cli.js +298 -0
  142. package/dist/src/copilot/errors.js +50 -0
  143. package/dist/src/copilot/home.js +84 -0
  144. package/dist/src/copilot/machine.js +41 -0
  145. package/dist/src/copilot/name.js +2 -0
  146. package/dist/src/copilot/release.js +30 -0
  147. package/dist/src/copilot/tail.js +57 -0
  148. package/dist/src/copilot/transcript.js +385 -0
  149. package/dist/src/diagnostics/start-watch.js +77 -0
  150. package/dist/src/env-file.js +91 -0
  151. package/dist/src/events.js +150 -0
  152. package/dist/src/git/changelog.js +38 -0
  153. package/dist/src/git/changes.js +10 -0
  154. package/dist/src/git/merged.js +36 -0
  155. package/dist/src/git/run.js +25 -0
  156. package/dist/src/git/setup.js +100 -0
  157. package/dist/src/git/slot.js +99 -0
  158. package/dist/src/git/sync.js +72 -0
  159. package/dist/src/git/types.js +1 -0
  160. package/dist/src/git/work.js +119 -0
  161. package/dist/src/git/worktree.js +216 -0
  162. package/dist/src/github/adapter.js +30 -0
  163. package/dist/src/github/model.js +104 -0
  164. package/dist/src/github/profile.js +50 -0
  165. package/dist/src/github/source.js +438 -0
  166. package/dist/src/github/trust.js +25 -0
  167. package/dist/src/github/uploads.js +36 -0
  168. package/dist/src/gitlab/adapter.js +51 -0
  169. package/dist/src/gitlab/api.js +71 -0
  170. package/dist/src/gitlab/batch.js +114 -0
  171. package/dist/src/gitlab/hierarchy.js +59 -0
  172. package/dist/src/gitlab/model.js +56 -0
  173. package/dist/src/gitlab/profile.js +25 -0
  174. package/dist/src/gitlab/source.js +246 -0
  175. package/dist/src/gitlab/uploads.js +65 -0
  176. package/dist/src/guard.js +141 -0
  177. package/dist/src/huly/adapter.js +34 -0
  178. package/dist/src/huly/client.js +158 -0
  179. package/dist/src/huly/credentials.js +27 -0
  180. package/dist/src/huly/ids.js +16 -0
  181. package/dist/src/huly/labels.js +32 -0
  182. package/dist/src/huly/model.js +191 -0
  183. package/dist/src/huly/profile.js +73 -0
  184. package/dist/src/huly/quiet.js +17 -0
  185. package/dist/src/huly/source.js +327 -0
  186. package/dist/src/intake/github.js +73 -0
  187. package/dist/src/intake/intake.js +113 -0
  188. package/dist/src/intake/model.js +72 -0
  189. package/dist/src/jira/adapter.js +35 -0
  190. package/dist/src/jira/adf.js +253 -0
  191. package/dist/src/jira/api.js +96 -0
  192. package/dist/src/jira/mcp.js +134 -0
  193. package/dist/src/jira/model.js +111 -0
  194. package/dist/src/jira/profile.js +17 -0
  195. package/dist/src/jira/source.js +320 -0
  196. package/dist/src/jsonc.js +15 -0
  197. package/dist/src/language.js +4 -0
  198. package/dist/src/limits/chatgpt.js +144 -0
  199. package/dist/src/limits/copilot.js +117 -0
  200. package/dist/src/limits/model.js +183 -0
  201. package/dist/src/limits/overage-session.js +9 -0
  202. package/dist/src/limits/overage.js +74 -0
  203. package/dist/src/limits/recovery.js +23 -0
  204. package/dist/src/limits/reset.js +81 -0
  205. package/dist/src/limits/retry.js +45 -0
  206. package/dist/src/limits/saved.js +17 -0
  207. package/dist/src/limits/spending.js +15 -0
  208. package/dist/src/limits/usage.js +53 -0
  209. package/dist/src/limits/watcher.js +269 -0
  210. package/dist/src/linear/adapter.js +50 -0
  211. package/dist/src/linear/model.js +89 -0
  212. package/dist/src/linear/profile.js +45 -0
  213. package/dist/src/linear/source.js +423 -0
  214. package/dist/src/locations.js +53 -0
  215. package/dist/src/main.js +76 -0
  216. package/dist/src/notice/en.js +489 -0
  217. package/dist/src/notice/notice.js +93 -0
  218. package/dist/src/opencode/adapter.js +121 -0
  219. package/dist/src/opencode/cli.js +433 -0
  220. package/dist/src/opencode/db.js +103 -0
  221. package/dist/src/opencode/home.js +85 -0
  222. package/dist/src/opencode/log.js +87 -0
  223. package/dist/src/opencode/models.js +51 -0
  224. package/dist/src/opencode/name.js +2 -0
  225. package/dist/src/opencode/protection-plugin.js +27 -0
  226. package/dist/src/opencode/release.js +29 -0
  227. package/dist/src/opencode/support.js +14 -0
  228. package/dist/src/opencode/tail.js +42 -0
  229. package/dist/src/opencode/transcript.js +331 -0
  230. package/dist/src/opencode/usage.js +41 -0
  231. package/dist/src/packages/check.js +146 -0
  232. package/dist/src/packages/gateway.js +496 -0
  233. package/dist/src/packages/keys.js +78 -0
  234. package/dist/src/packages/launch.js +99 -0
  235. package/dist/src/packages/model.js +61 -0
  236. package/dist/src/packages/npm.js +115 -0
  237. package/dist/src/packages/plugins.js +162 -0
  238. package/dist/src/packages/service.js +615 -0
  239. package/dist/src/packages/settings.js +25 -0
  240. package/dist/src/packages/skills.js +132 -0
  241. package/dist/src/packages/store.js +39 -0
  242. package/dist/src/packages/version.js +26 -0
  243. package/dist/src/patch.js +1 -0
  244. package/dist/src/paths.js +83 -0
  245. package/dist/src/profiles/control.js +32 -0
  246. package/dist/src/profiles/mcp.js +29 -0
  247. package/dist/src/profiles/model.js +97 -0
  248. package/dist/src/profiles/oauth-error.js +21 -0
  249. package/dist/src/profiles/oauth-protocol.js +106 -0
  250. package/dist/src/profiles/oauth-response.js +12 -0
  251. package/dist/src/profiles/oauth.js +228 -0
  252. package/dist/src/profiles/request.js +20 -0
  253. package/dist/src/profiles/routes.js +31 -0
  254. package/dist/src/profiles/rules.js +54 -0
  255. package/dist/src/profiles/service.js +471 -0
  256. package/dist/src/profiles/store.js +125 -0
  257. package/dist/src/projects/add.js +11 -0
  258. package/dist/src/projects/check.js +174 -0
  259. package/dist/src/projects/colors.js +16 -0
  260. package/dist/src/projects/folder.js +30 -0
  261. package/dist/src/projects/remotes.js +109 -0
  262. package/dist/src/projects/removal.js +14 -0
  263. package/dist/src/projects/standards.js +31 -0
  264. package/dist/src/review/events.js +27 -0
  265. package/dist/src/review/feedback.js +64 -0
  266. package/dist/src/review/forgejo.js +110 -0
  267. package/dist/src/review/github.js +69 -0
  268. package/dist/src/review/gitlab.js +118 -0
  269. package/dist/src/review/model.js +25 -0
  270. package/dist/src/review/open.js +141 -0
  271. package/dist/src/review/refusals.js +20 -0
  272. package/dist/src/review/wiring.js +93 -0
  273. package/dist/src/secrets/catalog.js +34 -0
  274. package/dist/src/secrets/service.js +168 -0
  275. package/dist/src/server-guard.js +51 -0
  276. package/dist/src/server-request.js +360 -0
  277. package/dist/src/server.js +576 -0
  278. package/dist/src/service/accounts.js +584 -0
  279. package/dist/src/service/chain.js +642 -0
  280. package/dist/src/service/cli-check.js +58 -0
  281. package/dist/src/service/hosting.js +508 -0
  282. package/dist/src/service/lifecycle.js +59 -0
  283. package/dist/src/service/stats.js +72 -0
  284. package/dist/src/service/trackers.js +239 -0
  285. package/dist/src/service.js +699 -0
  286. package/dist/src/sessions/activity.js +32 -0
  287. package/dist/src/sessions/agents.js +217 -0
  288. package/dist/src/sessions/approvals.js +105 -0
  289. package/dist/src/sessions/ask.js +234 -0
  290. package/dist/src/sessions/cache.js +14 -0
  291. package/dist/src/sessions/chat.js +60 -0
  292. package/dist/src/sessions/commandPrompt.js +31 -0
  293. package/dist/src/sessions/commands.js +29 -0
  294. package/dist/src/sessions/entry.js +104 -0
  295. package/dist/src/sessions/history.js +88 -0
  296. package/dist/src/sessions/holds.js +63 -0
  297. package/dist/src/sessions/inbox.js +101 -0
  298. package/dist/src/sessions/keepwarm.js +110 -0
  299. package/dist/src/sessions/launch.js +32 -0
  300. package/dist/src/sessions/lines.js +90 -0
  301. package/dist/src/sessions/lingering.js +26 -0
  302. package/dist/src/sessions/mail.js +36 -0
  303. package/dist/src/sessions/mailRelay.js +88 -0
  304. package/dist/src/sessions/mailbox.js +136 -0
  305. package/dist/src/sessions/model-prompts.js +16 -0
  306. package/dist/src/sessions/monitor.js +215 -0
  307. package/dist/src/sessions/note.js +30 -0
  308. package/dist/src/sessions/occupants.js +15 -0
  309. package/dist/src/sessions/owners.js +59 -0
  310. package/dist/src/sessions/paths.js +24 -0
  311. package/dist/src/sessions/permission.js +58 -0
  312. package/dist/src/sessions/place.js +37 -0
  313. package/dist/src/sessions/prompt.js +16 -0
  314. package/dist/src/sessions/protection.js +88 -0
  315. package/dist/src/sessions/remote.js +41 -0
  316. package/dist/src/sessions/setup.js +57 -0
  317. package/dist/src/sessions/share.js +6 -0
  318. package/dist/src/sessions/shareFile.js +32 -0
  319. package/dist/src/sessions/silence.js +25 -0
  320. package/dist/src/sessions/tail.js +79 -0
  321. package/dist/src/sessions/title.js +67 -0
  322. package/dist/src/sessions/transcript.js +477 -0
  323. package/dist/src/sessions/transient.js +4 -0
  324. package/dist/src/sessions/watch.js +78 -0
  325. package/dist/src/settings/changes.js +15 -0
  326. package/dist/src/settings/defaults.js +25 -0
  327. package/dist/src/settings/file.js +197 -0
  328. package/dist/src/settings/import.js +93 -0
  329. package/dist/src/settings/registry.js +422 -0
  330. package/dist/src/settings/resolve.js +80 -0
  331. package/dist/src/settings/store.js +102 -0
  332. package/dist/src/setup.js +7 -0
  333. package/dist/src/state.js +1 -0
  334. package/dist/src/stats/base-sql.js +58 -0
  335. package/dist/src/stats/break-labels.js +53 -0
  336. package/dist/src/stats/calibration.js +43 -0
  337. package/dist/src/stats/checkpoint.js +66 -0
  338. package/dist/src/stats/connect.js +49 -0
  339. package/dist/src/stats/diff.js +88 -0
  340. package/dist/src/stats/mode.js +25 -0
  341. package/dist/src/stats/model.js +108 -0
  342. package/dist/src/stats/reader.js +563 -0
  343. package/dist/src/stats/rule-imports.js +106 -0
  344. package/dist/src/stats/rules-reader.js +257 -0
  345. package/dist/src/stats/rules.js +324 -0
  346. package/dist/src/stats/steps-reader.js +108 -0
  347. package/dist/src/stats/steps.js +159 -0
  348. package/dist/src/stats/tally-schema.js +13 -0
  349. package/dist/src/stats/tally.js +139 -0
  350. package/dist/src/stats/task-checkpoint.js +9 -0
  351. package/dist/src/storage/atomic.js +41 -0
  352. package/dist/src/storage/claim.js +139 -0
  353. package/dist/src/storage/copy.js +69 -0
  354. package/dist/src/storage/database.js +405 -0
  355. package/dist/src/storage/json-folder.js +47 -0
  356. package/dist/src/storage/memory.js +15 -0
  357. package/dist/src/storage/migrations.js +373 -0
  358. package/dist/src/storage/owner.js +114 -0
  359. package/dist/src/storage/package-settings.js +33 -0
  360. package/dist/src/storage/projects.js +23 -0
  361. package/dist/src/storage/schema.js +21 -0
  362. package/dist/src/storage/service-state.js +9 -0
  363. package/dist/src/storage/state-files.js +222 -0
  364. package/dist/src/tools/model.js +1 -0
  365. package/dist/src/tools/panel.js +197 -0
  366. package/dist/src/tools/received.js +114 -0
  367. package/dist/src/tools/sessionSettings.js +15 -0
  368. package/dist/src/tools/settings.js +109 -0
  369. package/dist/src/tracker/adapters.js +28 -0
  370. package/dist/src/tracker/card.js +32 -0
  371. package/dist/src/tracker/closer.js +76 -0
  372. package/dist/src/tracker/closes.js +45 -0
  373. package/dist/src/tracker/comments.js +24 -0
  374. package/dist/src/tracker/control.js +138 -0
  375. package/dist/src/tracker/diagnostics.js +38 -0
  376. package/dist/src/tracker/health.js +1 -0
  377. package/dist/src/tracker/labels.js +25 -0
  378. package/dist/src/tracker/link.js +125 -0
  379. package/dist/src/tracker/model.js +82 -0
  380. package/dist/src/tracker/move-check.js +14 -0
  381. package/dist/src/tracker/mover.js +67 -0
  382. package/dist/src/tracker/parents.js +32 -0
  383. package/dist/src/tracker/poller.js +60 -0
  384. package/dist/src/tracker/questions.js +127 -0
  385. package/dist/src/tracker/readers.js +95 -0
  386. package/dist/src/tracker/source.js +66 -0
  387. package/dist/src/tracker/start.js +256 -0
  388. package/dist/src/tracker/statuses.js +22 -0
  389. package/dist/src/tracker/trackers.js +148 -0
  390. package/dist/src/tracker/vocabulary.js +33 -0
  391. package/dist/src/updates/checkout.js +16 -0
  392. package/dist/src/updates/control.js +139 -0
  393. package/dist/src/updates/launch.js +40 -0
  394. package/dist/src/updates/model.js +105 -0
  395. package/dist/src/updates/prefix.js +19 -0
  396. package/dist/src/updates/release.js +100 -0
  397. package/dist/src/updates/run.js +64 -0
  398. package/dist/src/updates/runner.js +183 -0
  399. package/dist/src/updates/settle.js +18 -0
  400. package/dist/src/updates/steps.js +63 -0
  401. package/dist/src/updates/updater.js +205 -0
  402. package/dist/src/updates/watcher.js +86 -0
  403. package/dist/tally/src/classify.js +144 -0
  404. package/dist/tally/src/closed-tasks.js +25 -0
  405. package/dist/tally/src/collect-worker.js +17 -0
  406. package/dist/tally/src/collect.js +212 -0
  407. package/dist/tally/src/compact.js +33 -0
  408. package/dist/tally/src/config.js +150 -0
  409. package/dist/tally/src/copilot-turns.js +101 -0
  410. package/dist/tally/src/copilot.js +173 -0
  411. package/dist/tally/src/db.js +562 -0
  412. package/dist/tally/src/handoffs.js +126 -0
  413. package/dist/tally/src/host-worker.js +18 -0
  414. package/dist/tally/src/huly-profiles.js +38 -0
  415. package/dist/tally/src/huly.js +123 -0
  416. package/dist/tally/src/limits.js +21 -0
  417. package/dist/tally/src/load.js +89 -0
  418. package/dist/tally/src/local.js +47 -0
  419. package/dist/tally/src/main.js +39 -0
  420. package/dist/tally/src/migrations/2-false-rule-deletions.sql +41 -0
  421. package/dist/tally/src/migrations/3-gpt-family.sql +20 -0
  422. package/dist/tally/src/migrations/4-compactions.sql +49 -0
  423. package/dist/tally/src/migrations/5-milestones.sql +25 -0
  424. package/dist/tally/src/migrations/6-task-sources.sql +6 -0
  425. package/dist/tally/src/migrations/7-task-followups.sql +28 -0
  426. package/dist/tally/src/migrations/8-handoff-headings.sql +12 -0
  427. package/dist/tally/src/migrations/9-codex-stray-counts.sql +15 -0
  428. package/dist/tally/src/migrations.js +80 -0
  429. package/dist/tally/src/opencode-turns.js +79 -0
  430. package/dist/tally/src/opencode.js +115 -0
  431. package/dist/tally/src/parse.js +192 -0
  432. package/dist/tally/src/prompt.js +19 -0
  433. package/dist/tally/src/rollout-turns.js +181 -0
  434. package/dist/tally/src/rollout.js +159 -0
  435. package/dist/tally/src/rule-changes.js +39 -0
  436. package/dist/tally/src/rule-history.js +88 -0
  437. package/dist/tally/src/rule-hook-size.js +23 -0
  438. package/dist/tally/src/rule-hook.js +177 -0
  439. package/dist/tally/src/rule-imports.js +76 -0
  440. package/dist/tally/src/rule-parse.js +178 -0
  441. package/dist/tally/src/rule-repair.js +27 -0
  442. package/dist/tally/src/rule-scan.js +179 -0
  443. package/dist/tally/src/rule-steps.js +144 -0
  444. package/dist/tally/src/rules.js +230 -0
  445. package/dist/tally/src/scan.js +59 -0
  446. package/dist/tally/src/schema.sql +702 -0
  447. package/dist/tally/src/signs.js +179 -0
  448. package/dist/tally/src/step-runs.js +274 -0
  449. package/dist/tally/src/steps.js +140 -0
  450. package/dist/tally/src/stream.js +73 -0
  451. package/dist/tally/src/task.js +16 -0
  452. package/dist/tally/src/turns.js +114 -0
  453. package/dist/web/apple-touch-icon.png +0 -0
  454. package/dist/web/assets/Loader-BoP9PE7x.js +31 -0
  455. package/dist/web/assets/Loader-DJJTBsaF.css +1 -0
  456. package/dist/web/assets/TaskCard-Br2QIllc.css +1 -0
  457. package/dist/web/assets/TaskCard-DNn-Qm8d.js +2 -0
  458. package/dist/web/assets/TranscriptWindow-2afYjYo9.css +1 -0
  459. package/dist/web/assets/TranscriptWindow-CFE2kEuL.js +4 -0
  460. package/dist/web/assets/feedLine-C_AM4QQT.js +1 -0
  461. package/dist/web/assets/index-BY7ediF2.js +25 -0
  462. package/dist/web/assets/index-Di7tEbPf.css +1 -0
  463. package/dist/web/assets/media-DR8nAbPy.css +1 -0
  464. package/dist/web/assets/media-DfHUEnGn.js +1 -0
  465. package/dist/web/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  466. package/dist/web/assets/useModels-1oIk0mDX.css +1 -0
  467. package/dist/web/assets/useModels-BmTGsRQz.js +15 -0
  468. package/dist/web/favicon.svg +1 -0
  469. package/dist/web/icon-192.png +0 -0
  470. package/dist/web/icon-512.png +0 -0
  471. package/dist/web/icon-maskable-512.png +0 -0
  472. package/dist/web/index.html +25 -0
  473. package/dist/web/manifest.webmanifest +16 -0
  474. package/dist/web/stats-preview.png +0 -0
  475. package/even-keel.config.example.json +59 -0
  476. package/package.json +118 -7
  477. package/plugins/checkpoint/.claude-plugin/plugin.json +9 -0
  478. package/plugins/checkpoint/README.md +85 -0
  479. package/plugins/checkpoint/hooks/checkpoint-mark.mjs +26 -0
  480. package/plugins/checkpoint/hooks/context-checkpoint.mjs +28 -0
  481. package/plugins/checkpoint/hooks/evenkeel.mjs +117 -0
  482. package/plugins/checkpoint/hooks/handoff.mjs +9 -0
  483. package/plugins/checkpoint/hooks/hooks.json +120 -0
  484. package/plugins/checkpoint/hooks/mailbox.mjs +36 -0
  485. package/plugins/checkpoint/hooks/merge-check.mjs +28 -0
  486. package/plugins/checkpoint/hooks/merges.mjs +103 -0
  487. package/plugins/checkpoint/hooks/nudges.mjs +78 -0
  488. package/plugins/checkpoint/hooks/permission.mjs +49 -0
  489. package/plugins/checkpoint/hooks/schema-hint.mjs +53 -0
  490. package/plugins/checkpoint/hooks/standard-gate.mjs +51 -0
  491. package/plugins/checkpoint/hooks/standards.mjs +258 -0
  492. package/plugins/checkpoint/opencode/checkpoint.mjs +85 -0
  493. package/plugins/github/.claude-plugin/plugin.json +9 -0
  494. package/plugins/github/.mcp.json +12 -0
  495. package/plugins/github/README.md +73 -0
  496. package/plugins/github/skills/task/SKILL.md +62 -0
  497. package/plugins/gitlab/.claude-plugin/plugin.json +7 -0
  498. package/plugins/gitlab/.mcp.json +13 -0
  499. package/plugins/gitlab/README.md +29 -0
  500. package/plugins/gitlab/skills/task/SKILL.md +55 -0
  501. package/plugins/huly/.claude-plugin/plugin.json +9 -0
  502. package/plugins/huly/.mcp.json +11 -0
  503. package/plugins/huly/README.md +60 -0
  504. package/plugins/huly/hooks/calibration-context.mjs +44 -0
  505. package/plugins/huly/hooks/calibration.mjs +80 -0
  506. package/plugins/huly/hooks/check-marks.mjs +23 -0
  507. package/plugins/huly/hooks/hooks.json +26 -0
  508. package/plugins/huly/hooks/marks.mjs +58 -0
  509. package/plugins/huly/hooks/show-calibration.mjs +19 -0
  510. package/plugins/huly/opencode/huly.mjs +31 -0
  511. package/plugins/huly/skills/setup/SKILL.md +51 -0
  512. package/plugins/huly/skills/split/SKILL.md +53 -0
  513. package/plugins/huly/skills/task/SKILL.md +81 -0
  514. package/plugins/jira/.claude-plugin/plugin.json +7 -0
  515. package/plugins/jira/.mcp.json +11 -0
  516. package/plugins/jira/README.md +39 -0
  517. package/plugins/jira/skills/task/SKILL.md +63 -0
  518. package/plugins/linear/.claude-plugin/plugin.json +9 -0
  519. package/plugins/linear/.mcp.json +11 -0
  520. package/plugins/linear/README.md +71 -0
  521. package/plugins/linear/skills/task/SKILL.md +62 -0
  522. package/plugins/tally/.claude-plugin/plugin.json +9 -0
  523. package/plugins/tally/README.md +42 -0
  524. package/plugins/tally/bin/locate.mjs +48 -0
  525. package/plugins/tally/bin/sql.mjs +21 -0
  526. package/plugins/tally/skills/session-audit/SKILL.md +333 -0
  527. package/service/EvenKeelHost.cs +133 -0
  528. package/service/EvenKeelService.cs +271 -0
  529. package/service/EvenKeelTray.cs +258 -0
  530. package/service/install.ps1 +95 -0
  531. package/service/install.sh +143 -0
  532. package/service/uninstall.ps1 +19 -0
  533. package/service/uninstall.sh +37 -0
  534. package/statusline/statusline.mjs +46 -0
  535. package/tally/bin/rule-hook.mjs +26 -0
  536. package/tally/bin/sql.mjs +166 -0
  537. package/tally/tally.config.json +59 -0
@@ -0,0 +1,111 @@
1
+ import { sameName } from '../chain/rules.js';
2
+ import { adfToMarkdown } from './adf.js';
3
+ /** The fields a task of the chain needs; the card adds the description and the files. */
4
+ export const TASK_FIELDS = ['summary', 'status', 'priority', 'labels', 'fixVersions', 'parent', 'issuelinks', 'subtasks', 'issuetype'];
5
+ export const CARD_FIELDS = [...TASK_FIELDS, 'description', 'attachment'];
6
+ /** The link type the chain orders by; it is found by this name, so a site that renamed it has no blockers (`jira.blocksType`). */
7
+ export const BLOCKS = 'Blocks';
8
+ const RELATES = 'Relates';
9
+ /**
10
+ * A status by its category: `new` is ready, `indeterminate` in progress, `done` done. Jira has no category of its own
11
+ * for a backlog: Jira Software's backlog column is a `new` status named Backlog, so a `new` status of that name is the
12
+ * backlog and stays out of the chain by default.
13
+ */
14
+ export function jiraStatus(status) {
15
+ switch (status.statusCategory.key) {
16
+ case 'new':
17
+ return { name: status.name, category: sameName(status.untranslatedName ?? status.name, 'Backlog') ? 'UnStarted' : 'ToDo' };
18
+ case 'indeterminate':
19
+ return { name: status.name, category: 'Active' };
20
+ case 'done':
21
+ return { name: status.name, category: 'Won' };
22
+ default:
23
+ return { name: status.name, category: 'UnStarted' };
24
+ }
25
+ }
26
+ const BUILT_IN = { highest: 'urgent', high: 'high', medium: 'medium', low: 'low', lowest: 'low' };
27
+ const LEVELS = ['urgent', 'high', 'medium', 'low'];
28
+ /** The built-in priorities by name; a site's own scheme by the priority's place in `order`, highest first. */
29
+ export function jiraPriority(priority, order) {
30
+ if (priority == null)
31
+ return 'none';
32
+ const named = BUILT_IN[priority.name.trim().toLowerCase()];
33
+ if (named !== undefined)
34
+ return named;
35
+ const at = order.findIndex((name) => sameName(name, priority.name));
36
+ if (at < 0)
37
+ return 'none';
38
+ return order.length === 1 ? 'medium' : LEVELS[Math.round((at * (LEVELS.length - 1)) / (order.length - 1))];
39
+ }
40
+ /** The site's priority for a level: the built-in one of its name, else the first whose place gives the level. */
41
+ export function priorityFor(level, priorities) {
42
+ if (level === 'none')
43
+ return undefined;
44
+ const order = priorities.map((each) => each.name);
45
+ const named = priorities.find((each) => sameName(each.name, level === 'urgent' ? 'Highest' : level));
46
+ return named ?? priorities.find((each) => jiraPriority(each, order) === level);
47
+ }
48
+ /** The earliest version by release date; one without a date goes after the dated ones. */
49
+ export function earliestVersion(versions) {
50
+ const dated = (version) => (version.releaseDate ? Date.parse(version.releaseDate) : Number.POSITIVE_INFINITY);
51
+ return [...(versions ?? [])].sort((a, b) => dated(a) - dated(b))[0] ?? null;
52
+ }
53
+ export function milestoneOf(version) {
54
+ return version === null ? null : { label: version.name, targetDate: version.releaseDate ? Date.parse(version.releaseDate) : null };
55
+ }
56
+ const isBlocks = (link) => sameName(link.type.name, BLOCKS);
57
+ /** `children` — how many issues have this one as their parent; Jira lists only sub-tasks on the issue itself. */
58
+ export function toTrackerTask(issue, order, children = issue.fields.subtasks?.length ?? 0) {
59
+ const fields = issue.fields;
60
+ return {
61
+ id: issue.key,
62
+ title: fields.summary,
63
+ status: jiraStatus(fields.status),
64
+ blockedBy: (fields.issuelinks ?? []).flatMap((link) => (isBlocks(link) && link.inwardIssue !== undefined ? [link.inwardIssue.key] : [])),
65
+ parent: fields.parent?.key ?? null,
66
+ subtasks: children,
67
+ milestone: milestoneOf(earliestVersion(fields.fixVersions)),
68
+ priority: jiraPriority(fields.priority, order),
69
+ labels: fields.labels ?? [],
70
+ estimate: 0,
71
+ };
72
+ }
73
+ /** An issue that may have children other than its sub-tasks: an epic, or a level above it. */
74
+ export const hasChildIssues = (issue) => (issue.fields.issuetype?.hierarchyLevel ?? 0) > 0;
75
+ /** The service's route to a file of the task's card, as `cardOf` makes it. */
76
+ const fileRoute = (task, file) => `/api/tasks/${encodeURIComponent(task)}/files/${encodeURIComponent(file)}`;
77
+ /**
78
+ * A media node names its file by the media id, not by the attachment's: its `alt` is the file name, and the attachment
79
+ * of that name is taken for it.
80
+ */
81
+ export function mediaLinks(task, attachments) {
82
+ return ({ alt }) => {
83
+ const found = attachments.find((each) => each.filename === alt);
84
+ return found === undefined ? null : { url: fileRoute(task, found.id), image: (found.mimeType ?? '').startsWith('image/') };
85
+ };
86
+ }
87
+ export function toCard(issue, comments, order) {
88
+ const fields = issue.fields;
89
+ const task = toTrackerTask(issue, order);
90
+ const refOf = (ref) => ({ id: ref.key, title: ref.fields.summary, status: jiraStatus(ref.fields.status) });
91
+ const links = fields.issuelinks ?? [];
92
+ const media = mediaLinks(issue.key, fields.attachment ?? []);
93
+ const attachments = (fields.attachment ?? []).map((each) => ({ file: each.id, name: each.filename, type: each.mimeType ?? '', size: each.size ?? 0, url: null }));
94
+ return {
95
+ id: issue.key,
96
+ title: fields.summary,
97
+ description: adfToMarkdown(fields.description, media),
98
+ status: task.status,
99
+ priority: task.priority,
100
+ labels: task.labels,
101
+ milestone: task.milestone,
102
+ parent: fields.parent == null ? null : refOf(fields.parent),
103
+ blockedBy: links.flatMap((link) => (isBlocks(link) && link.inwardIssue !== undefined ? [refOf(link.inwardIssue)] : [])),
104
+ blocks: links.flatMap((link) => (isBlocks(link) && link.outwardIssue !== undefined ? [refOf(link.outwardIssue)] : [])),
105
+ related: links.flatMap((link) => (sameName(link.type.name, RELATES) ? [link.inwardIssue ?? link.outwardIssue].filter((ref) => ref !== undefined).map(refOf) : [])),
106
+ comments: [...comments]
107
+ .sort((a, b) => Date.parse(a.created) - Date.parse(b.created))
108
+ .map((comment) => ({ author: comment.author?.displayName ?? null, at: Date.parse(comment.created), text: adfToMarkdown(comment.body, media) })),
109
+ attachments,
110
+ };
111
+ }
@@ -0,0 +1,17 @@
1
+ import { JiraApi, JIRA_MCP_TOKEN, siteUrl } from './api.js';
2
+ import { checkJiraMcp } from './mcp.js';
3
+ /** The most a `projects` answer lists. */
4
+ const LIMIT = 50;
5
+ /** The profile is named by the site: one account may sign in to several. */
6
+ export async function jiraAccount(values, timeoutMs, fetchImpl = fetch) {
7
+ const { user } = await JiraApi.open(values, timeoutMs, fetchImpl);
8
+ if (values[JIRA_MCP_TOKEN])
9
+ await checkJiraMcp(values, timeoutMs, fetchImpl);
10
+ const host = new URL(siteUrl(values)).hostname.replace(/\.atlassian\.net$/, '');
11
+ return { login: user.emailAddress || user.displayName, name: `Jira · ${host}`, expiresAt: null, user: { id: user.accountId, name: user.displayName || user.accountId } };
12
+ }
13
+ export async function jiraProjects(values, query, timeoutMs, fetchImpl = fetch) {
14
+ const { api } = await JiraApi.open(values, timeoutMs, fetchImpl);
15
+ const { values: projects } = await api.rest(`/project/search?maxResults=${LIMIT}&query=${encodeURIComponent(query.trim())}`);
16
+ return projects.map((project) => ({ key: project.key, name: project.name }));
17
+ }
@@ -0,0 +1,320 @@
1
+ import { sameName } from '../chain/rules.js';
2
+ import { changedLabels } from '../tracker/labels.js';
3
+ import { fail } from '../notice/notice.js';
4
+ import { commentsAfterId } from '../tracker/comments.js';
5
+ import { parseTaskId, uniqueStatuses } from '../tracker/model.js';
6
+ import { TrackerNotFound } from '../tracker/source.js';
7
+ import { adfToMarkdown, markdownToAdf } from './adf.js';
8
+ import { JiraApi } from './api.js';
9
+ import { BLOCKS, CARD_FIELDS, earliestVersion, hasChildIssues, jiraStatus, priorityFor, TASK_FIELDS, toCard, toTrackerTask, } from './model.js';
10
+ const PAGE = 100;
11
+ /** Keys per `parent in (…)` query: a long JQL is refused. */
12
+ const PARENTS_CHUNK = 50;
13
+ export async function connectJira(settings, timeoutMs, fetchImpl = fetch, log = console.log) {
14
+ const { api } = await JiraApi.open(settings.values, timeoutMs, fetchImpl);
15
+ const { issueLinkTypes } = await api.rest('/issueLinkType');
16
+ if (!issueLinkTypes.some((type) => sameName(type.name, BLOCKS)))
17
+ throw fail('jira.blocksType', { types: issueLinkTypes.map((type) => type.name).join(', ') });
18
+ let priorities = null;
19
+ const prioritiesOf = () => {
20
+ priorities ??= api.rest(`/priority/search?maxResults=${PAGE}`).then((page) => page.values).catch((error) => {
21
+ priorities = null;
22
+ throw error;
23
+ });
24
+ return priorities;
25
+ };
26
+ const order = async () => (await prioritiesOf()).map((each) => each.name);
27
+ const keyOf = (project) => {
28
+ const place = Object.hasOwn(settings.projects, project) ? settings.projects[project] : undefined;
29
+ if (place === undefined)
30
+ throw new Error(`jira: project ${project} is not on this profile`);
31
+ return place.key;
32
+ };
33
+ const issuePath = (id) => {
34
+ if (parseTaskId(id) === null)
35
+ throw new Error(`jira: ${id} is not a task id`);
36
+ return `/issue/${id}`;
37
+ };
38
+ async function search(jql, fields = TASK_FIELDS) {
39
+ const issues = [];
40
+ let nextPageToken;
41
+ do {
42
+ const page = await api.rest('/search/jql', 'POST', { jql, fields, maxResults: PAGE, ...(nextPageToken === undefined ? {} : { nextPageToken }) });
43
+ issues.push(...page.issues);
44
+ nextPageToken = page.nextPageToken;
45
+ } while (nextPageToken !== undefined);
46
+ return issues;
47
+ }
48
+ /** Jira lists only sub-tasks on an issue: the children of an epic are the issues with it as their `parent`. */
49
+ async function converted(issues, catalogs) {
50
+ const names = await order();
51
+ await resolveStatuses(issues, catalogs);
52
+ const epics = issues.filter(hasChildIssues).map((issue) => issue.key);
53
+ const children = new Map();
54
+ for (let at = 0; at < epics.length; at += PARENTS_CHUNK) {
55
+ for (const child of await search(`parent in (${epics.slice(at, at + PARENTS_CHUNK).join(', ')})`, ['parent'])) {
56
+ const parent = child.fields.parent?.key;
57
+ if (parent !== undefined)
58
+ children.set(parent, (children.get(parent) ?? 0) + 1);
59
+ }
60
+ }
61
+ return issues.map((issue) => toTrackerTask(issue, names, hasChildIssues(issue) ? (children.get(issue.key) ?? 0) : undefined));
62
+ }
63
+ async function statusesOf(key) {
64
+ const types = await api.rest(`/project/${encodeURIComponent(key)}/statuses`);
65
+ return [...new Map(types.flatMap((type) => type.statuses).map((status) => [status.id, status])).values()];
66
+ }
67
+ /** Issue responses omit untranslatedName; keep the display name and resolve the original by status id. */
68
+ async function resolveStatuses(refs, catalogs = new Map()) {
69
+ for (const ref of refs) {
70
+ const status = ref.fields.status;
71
+ if (status.untranslatedName != null)
72
+ continue;
73
+ const key = parseTaskId(ref.key).project;
74
+ let catalog = catalogs.get(key);
75
+ if (catalog === undefined) {
76
+ catalog = statusesOf(key);
77
+ catalogs.set(key, catalog);
78
+ }
79
+ const original = (await catalog).find((each) => each.id === status.id);
80
+ status.untranslatedName = original?.untranslatedName ?? original?.name;
81
+ }
82
+ }
83
+ const versionsOf = (key) => api.rest(`/project/${encodeURIComponent(key)}/versions`);
84
+ const openVersions = (versions) => versions.filter((version) => version.released !== true && version.archived !== true);
85
+ const issueOf = (id, fields) => api.rest(`${issuePath(id)}?fields=${fields.join(',')}`);
86
+ const transitionsOf = async (id) => (await api.rest(`${issuePath(id)}/transitions`)).transitions;
87
+ const transition = (id, to) => api.rest(`${issuePath(id)}/transitions`, 'POST', { transition: { id: to.id } });
88
+ const setVersions = (id, versions) => api.rest(issuePath(id), 'PUT', { fields: { fixVersions: versions.map((version) => ({ id: version })) } });
89
+ async function commentsOf(id, newestFirst = false, limit = Number.POSITIVE_INFINITY) {
90
+ const comments = [];
91
+ for (let startAt = 0; comments.length < limit;) {
92
+ const page = await api.rest(`${issuePath(id)}/comment?orderBy=${newestFirst ? '-created' : 'created'}&startAt=${startAt}&maxResults=${Math.min(PAGE, limit)}`);
93
+ comments.push(...page.comments);
94
+ startAt += page.comments.length;
95
+ if (page.comments.length === 0 || startAt >= page.total)
96
+ break;
97
+ }
98
+ return comments;
99
+ }
100
+ /**
101
+ * Through the workflow's first transition from one of `from` into `to`; `null` — the issue is in none of `from`, or, with
102
+ * `wanted` null, its workflow has no such transition.
103
+ */
104
+ async function move(id, from, to, wanted) {
105
+ const { fields } = await issueOf(id, ['status']);
106
+ const catalogs = new Map();
107
+ await resolveStatuses([{ key: id, fields }], catalogs);
108
+ if (!from.includes(jiraStatus(fields.status).category))
109
+ return null;
110
+ const transitions = await transitionsOf(id);
111
+ await resolveStatuses(transitions.map((each) => ({ key: id, fields: { summary: '', status: each.to } })), catalogs);
112
+ const found = transitions.find((each) => jiraStatus(each.to).category === to);
113
+ if (found === undefined && wanted === null)
114
+ return null;
115
+ if (found === undefined)
116
+ throw new Error(`jira: ${id} has no transition from ${fields.status.name} to a ${wanted} status`);
117
+ await transition(id, found);
118
+ return jiraStatus(found.to);
119
+ }
120
+ const ready = (id) => move(id, ['UnStarted'], 'ToDo', 'ready');
121
+ return {
122
+ async chainTasks(project, open) {
123
+ const key = keyOf(project);
124
+ const statuses = await statusesOf(key);
125
+ const where = (wanted) => statuses.filter((status) => open(jiraStatus(status)) === wanted).map((status) => status.id);
126
+ const opened = where(true);
127
+ const issues = opened.length === 0 ? [] : await search(`project = "${key}" AND status in (${opened.join(', ')}) ORDER BY key`);
128
+ const versions = [...new Set(issues.flatMap((issue) => (issue.fields.fixVersions ?? []).map((version) => version.id)))];
129
+ const closed = where(false);
130
+ const others = versions.length === 0 || closed.length === 0 ? [] : await search(`project = "${key}" AND status in (${closed.join(', ')}) AND fixVersion in (${versions.join(', ')}) ORDER BY key`);
131
+ return { tasks: await converted([...issues, ...others], new Map([[key, Promise.resolve(statuses)]])), statuses: [...new Set(statuses.map((status) => status.name))] };
132
+ },
133
+ async tasks(ids) {
134
+ const keys = [...new Set(ids.filter((id) => parseTaskId(id) !== null))];
135
+ const issues = [];
136
+ for (let at = 0; at < keys.length; at += PAGE) {
137
+ // An id Jira does not have is left out of `issues`, not a failure of the call (live: `issueErrors` stayed empty).
138
+ const page = await api.rest('/issue/bulkfetch', 'POST', { issueIdsOrKeys: keys.slice(at, at + PAGE), fields: TASK_FIELDS });
139
+ issues.push(...page.issues);
140
+ }
141
+ return converted(issues);
142
+ },
143
+ async brief(id) {
144
+ const { fields } = await issueOf(id, ['summary', 'description']);
145
+ return { title: fields.summary, description: adfToMarkdown(fields.description) };
146
+ },
147
+ async complete(id, name) {
148
+ const { fields } = await issueOf(id, ['status']);
149
+ if (jiraStatus(fields.status).category === 'Won')
150
+ return false;
151
+ const to = (await transitionsOf(id)).find((each) => each.to.statusCategory.key === 'done' && (name === undefined || sameName(each.to.name, name)));
152
+ if (to === undefined && name !== undefined)
153
+ throw new Error(`jira: ${id} has no transition from ${fields.status.name} to "${name}" of the Done category`);
154
+ if (to === undefined) {
155
+ log(`jira: ${id} is not closed: its workflow has no transition from ${fields.status.name} to a status of the Done category`);
156
+ return false;
157
+ }
158
+ await transition(id, to);
159
+ return true;
160
+ },
161
+ async moveTo(id, name) {
162
+ const { fields } = await issueOf(id, ['status']);
163
+ const catalogs = new Map();
164
+ await resolveStatuses([{ key: id, fields }], catalogs);
165
+ if (sameName(fields.status.name, name))
166
+ return jiraStatus(fields.status);
167
+ const to = (await transitionsOf(id)).find((each) => sameName(each.to.name, name));
168
+ if (to === undefined) {
169
+ log(`jira: ${id} stays in ${fields.status.name}: its workflow has no transition from it to "${name}"`);
170
+ return null;
171
+ }
172
+ await resolveStatuses([{ key: id, fields: { summary: '', status: to.to } }], catalogs);
173
+ await transition(id, to);
174
+ return jiraStatus(to.to);
175
+ },
176
+ async statuses() {
177
+ return uniqueStatuses((await api.rest('/status')).map(jiraStatus));
178
+ },
179
+ async children(id) {
180
+ issuePath(id);
181
+ return converted(await search(`parent = ${id} ORDER BY key`));
182
+ },
183
+ async card(id) {
184
+ const [issue, comments] = await Promise.all([issueOf(id, CARD_FIELDS), commentsOf(id)]);
185
+ const links = issue.fields.issuelinks ?? [];
186
+ await resolveStatuses([issue, ...[issue.fields.parent, ...links.flatMap((link) => [link.inwardIssue, link.outwardIssue])].filter((ref) => ref != null)]);
187
+ return toCard(issue, comments, await order());
188
+ },
189
+ async file(id, file) {
190
+ if (!/^\d+$/.test(file))
191
+ return null;
192
+ const { fields } = await issueOf(id, ['attachment']);
193
+ const attachment = (fields.attachment ?? []).find((each) => each.id === file);
194
+ if (attachment === undefined)
195
+ return null;
196
+ let response;
197
+ try {
198
+ response = await api.request(`/rest/api/3/attachment/content/${file}?redirect=false`);
199
+ }
200
+ catch (error) {
201
+ if (error instanceof TrackerNotFound)
202
+ return null;
203
+ throw error;
204
+ }
205
+ if (response.body === null)
206
+ return null;
207
+ return { type: attachment.mimeType ?? response.headers.get('content-type') ?? '', size: attachment.size ?? null, body: response.body };
208
+ },
209
+ ready,
210
+ // A board's backlog is often a view, not a status: without one only the required label goes.
211
+ unready: (id) => move(id, ['ToDo', 'Active'], 'UnStarted', null),
212
+ async relabel(id, change) {
213
+ const issue = await issueOf(id, ['labels']);
214
+ const labels = changedLabels(issue.fields.labels ?? [], change);
215
+ await api.rest(issuePath(id), 'PUT', { fields: { labels } });
216
+ return (await issueOf(id, ['labels'])).fields.labels ?? [];
217
+ },
218
+ async comment(id, body) {
219
+ return (await api.rest(`${issuePath(id)}/comment`, 'POST', { body: markdownToAdf(body) })).id;
220
+ },
221
+ async commentsAfter(id, after) {
222
+ const comments = await commentsOf(id);
223
+ const later = commentsAfterId(comments, after);
224
+ const hasMedia = later.some((comment) => JSON.stringify(comment.body ?? {}).includes('"media'));
225
+ const attachments = hasMedia ? ((await issueOf(id, ['attachment'])).fields.attachment ?? []) : [];
226
+ // A session gets a comment's files downloaded, so its text names them and links nowhere.
227
+ return later.map((comment) => {
228
+ const files = new Map();
229
+ const body = adfToMarkdown(comment.body, ({ alt }) => {
230
+ const found = attachments.find((each) => each.filename === alt);
231
+ if (found !== undefined)
232
+ files.set(found.id, found.filename);
233
+ return null;
234
+ });
235
+ return { id: comment.id, body, files: [...files].map(([file, name]) => ({ name, file })) };
236
+ });
237
+ },
238
+ // A new issue goes in at the workflow's first status; one that starts in the backlog is moved to the first ready one.
239
+ async create(task) {
240
+ const key = keyOf(task.project);
241
+ const { issueTypes, values } = await api.rest(`/issue/createmeta/${encodeURIComponent(key)}/issuetypes`);
242
+ const types = (issueTypes ?? values ?? []).filter((type) => type.subtask !== true && type.hierarchyLevel === 0);
243
+ const type = types.find((each) => sameName(each.untranslatedName ?? each.name, 'Task')) ?? types[0];
244
+ if (type === undefined)
245
+ throw new Error(`jira: project ${key} has no issue type to create a task with`);
246
+ const priority = priorityFor(task.priority, await prioritiesOf());
247
+ const like = task.milestoneOf !== null && parseTaskId(task.milestoneOf)?.project === key ? earliestVersion((await issueOf(task.milestoneOf, ['fixVersions'])).fields.fixVersions) : null;
248
+ const fields = {
249
+ project: { key },
250
+ issuetype: { id: type.id },
251
+ summary: task.title,
252
+ description: markdownToAdf(task.description),
253
+ ...(priority === undefined ? {} : { priority: { id: priority.id } }),
254
+ ...(like === null ? {} : { fixVersions: [{ id: like.id }] }),
255
+ };
256
+ const created = await api.rest('/issue', 'POST', { fields });
257
+ await ready(created.key);
258
+ return created.key;
259
+ },
260
+ // A version belongs to a project: a task of another project is left alone.
261
+ async setMilestone(id, milestoneOf) {
262
+ if (parseTaskId(id)?.project !== parseTaskId(milestoneOf)?.project)
263
+ return false;
264
+ if ((await issueOf(id, ['fixVersions'])).fields.fixVersions?.length)
265
+ return false;
266
+ const version = earliestVersion((await issueOf(milestoneOf, ['fixVersions'])).fields.fixVersions);
267
+ if (version === null)
268
+ return false;
269
+ await setVersions(id, [version.id]);
270
+ return true;
271
+ },
272
+ async milestones(id) {
273
+ const own = earliestVersion((await issueOf(id, ['fixVersions'])).fields.fixVersions);
274
+ const choices = openVersions(await versionsOf(parseTaskId(id).project));
275
+ if (own !== null && !choices.some((each) => each.id === own.id))
276
+ choices.push(own);
277
+ return {
278
+ current: own?.id ?? null,
279
+ choices: choices.map((version) => ({ id: version.id, label: version.name, targetDate: version.releaseDate ? Date.parse(version.releaseDate) : null })),
280
+ };
281
+ },
282
+ // Jira lets an issue be in several versions; a pick on the card leaves it in the one picked.
283
+ async moveMilestone(id, milestone) {
284
+ if (milestone !== null && !/^\d+$/.test(milestone))
285
+ throw new Error('jira: invalid version id');
286
+ await setVersions(id, milestone === null ? [] : [milestone]);
287
+ },
288
+ async milestoneTasks(project, milestone) {
289
+ const key = keyOf(project);
290
+ const version = (await versionsOf(key)).find((each) => each.name === milestone);
291
+ if (version === undefined)
292
+ return [];
293
+ const tasks = await converted(await search(`project = "${key}" AND fixVersion = ${version.id} ORDER BY key`));
294
+ const result = [];
295
+ for (const task of tasks) {
296
+ const [last] = await commentsOf(task.id, true, 1);
297
+ result.push({ ...task, lastComment: last === undefined ? null : adfToMarkdown(last.body) });
298
+ }
299
+ return result;
300
+ },
301
+ async vocabulary(project) {
302
+ const key = keyOf(project);
303
+ const statuses = await statusesOf(key);
304
+ const labels = [];
305
+ for (let startAt = 0;;) {
306
+ const page = await api.rest(`/label?startAt=${startAt}&maxResults=1000`);
307
+ labels.push(...page.values);
308
+ startAt += page.values.length;
309
+ if (page.isLast !== false || page.values.length === 0)
310
+ break;
311
+ }
312
+ return {
313
+ statuses: [...new Map(statuses.map((status) => [status.name, jiraStatus(status)])).values()],
314
+ labels,
315
+ milestones: openVersions(await versionsOf(key)).map((version) => version.name),
316
+ };
317
+ },
318
+ close: async () => { },
319
+ };
320
+ }
@@ -0,0 +1,15 @@
1
+ /** JSON with comments and trailing commas, as OpenCode reads its config and Copilot writes its own; `undefined` when it is not even that or not an object. */
2
+ export function parseJsonc(text) {
3
+ const bare = text.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_match, string) => string ?? '').replace(/,(\s*[}\]])/g, '$1');
4
+ try {
5
+ const value = JSON.parse(bare);
6
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
7
+ }
8
+ catch {
9
+ return undefined;
10
+ }
11
+ }
12
+ /** The `//` comment lines a file opens with, kept when the file is written back. */
13
+ export function leadingComments(text) {
14
+ return /^(?:[ \t]*\/\/[^\n]*\n)*/.exec(text.replace(/\r\n/g, '\n'))?.[0] ?? '';
15
+ }
@@ -0,0 +1,4 @@
1
+ export const LANGUAGES = ['en', 'ru'];
2
+ export function isLanguage(value) {
3
+ return typeof value === 'string' && LANGUAGES.includes(value);
4
+ }
@@ -0,0 +1,144 @@
1
+ import { notice } from '../notice/notice.js';
2
+ import { chatGptCredits } from './overage.js';
3
+ /** What Codex's `/status` asks: the windows of the ChatGPT subscription, shared by every client signed in to it. */
4
+ export const CHATGPT_USAGE_URL = 'https://chatgpt.com/backend-api/wham/usage';
5
+ const AUTH_CLAIM = 'https://api.openai.com/auth';
6
+ const FIVE_HOURS = 300;
7
+ const WEEK = 10080;
8
+ const MONTH = 43200;
9
+ const POLL_MS = 5 * 60_000;
10
+ const polls = new Map();
11
+ /**
12
+ * The windows of ChatGPT's usage answer (BTN-341): `rate_limit.primary_window`/`secondary_window`, each with the share
13
+ * used, its length and its reset in seconds — the five-hour, the weekly and the free plan's 30-day window by their length,
14
+ * as Codex's rollouts (`limitsOfRollout`). `undefined` — the answer holds no window.
15
+ */
16
+ export function chatGptLimits(body, at) {
17
+ const limit = isRecord(body) ? body.rate_limit : undefined;
18
+ const overage = chatGptCredits(isRecord(body) ? body.credits : undefined, at);
19
+ const windows = isRecord(limit) ? [limit.primary_window, limit.secondary_window].filter(isRecord) : [];
20
+ if (windows.length === 0 && overage === undefined)
21
+ return undefined;
22
+ const of = (minutes) => {
23
+ const found = windows.find((window) => window.limit_window_seconds === minutes * 60);
24
+ return found === undefined ? null : windowOf(found, at);
25
+ };
26
+ const monthly = windows.some((window) => window.limit_window_seconds === MONTH * 60);
27
+ const flags = isRecord(limit) && (typeof limit.allowed === 'boolean' || typeof limit.limit_reached === 'boolean') ? limit : undefined;
28
+ const open = flags === undefined ? undefined : flags.allowed === true && flags.limit_reached === false;
29
+ return {
30
+ fiveHour: of(FIVE_HOURS),
31
+ sevenDay: of(WEEK),
32
+ ...(monthly ? { month: of(MONTH) } : {}),
33
+ updatedAt: at,
34
+ source: 'api',
35
+ ...(overage !== undefined && { overage }),
36
+ ...(open !== undefined && { open }),
37
+ };
38
+ }
39
+ /** The ChatGPT account an access token is for, by its claim; `null` — not a token that says. */
40
+ export function chatGptAccountOf(token) {
41
+ const auth = claimsOf(token)?.[AUTH_CLAIM];
42
+ const id = isRecord(auth) ? auth.chatgpt_account_id : undefined;
43
+ return typeof id === 'string' && id !== '' ? id : null;
44
+ }
45
+ /** The ChatGPT account a Codex folder's `auth.json` is signed in to; `null` — an API key or no sign-in. */
46
+ export function chatGptAccountIn(codexAuth) {
47
+ try {
48
+ const value = JSON.parse(codexAuth ?? '');
49
+ const tokens = isRecord(value) ? value.tokens : undefined;
50
+ if (!isRecord(tokens))
51
+ return null;
52
+ const { account_id: id, access_token: access } = tokens;
53
+ if (typeof id === 'string' && id !== '')
54
+ return id;
55
+ return typeof access === 'string' ? chatGptAccountOf(access) : null;
56
+ }
57
+ catch {
58
+ return null;
59
+ }
60
+ }
61
+ /** The ChatGPT access token in Codex's `auth.json`; API keys and incomplete sign-ins have none. */
62
+ export function chatGptSignInIn(codexAuth) {
63
+ try {
64
+ const value = JSON.parse(codexAuth ?? '');
65
+ if (!isRecord(value) || value.auth_mode === 'apikey')
66
+ return undefined;
67
+ const tokens = value.tokens;
68
+ if (!isRecord(tokens) || typeof tokens.access_token !== 'string' || tokens.access_token === '')
69
+ return undefined;
70
+ const exp = claimsOf(tokens.access_token)?.exp;
71
+ const expiresAt = typeof exp === 'number' && Number.isFinite(exp) && exp > 0 ? exp * 1000 : null;
72
+ return { token: tokens.access_token, accountId: chatGptAccountIn(codexAuth), expiresAt };
73
+ }
74
+ catch {
75
+ return undefined;
76
+ }
77
+ }
78
+ /** Shares a five-minute poll, including an in-flight call, across Codex and OpenCode folders on one ChatGPT account. */
79
+ export async function pollChatGpt(signIn, at, timeoutMs, fetchImpl = fetch) {
80
+ const now = Date.parse(at);
81
+ for (const [key, poll] of polls)
82
+ if (poll.until <= now)
83
+ polls.delete(key);
84
+ const account = signIn.accountId ?? chatGptAccountOf(signIn.token);
85
+ const key = account === null ? `token:${signIn.token}` : chatGptPool(account);
86
+ const held = polls.get(key);
87
+ if (held !== undefined) {
88
+ const answer = await held.answer;
89
+ if (!held.refused || held.token === signIn.token)
90
+ return answer;
91
+ if (polls.get(key) !== held)
92
+ return pollChatGpt(signIn, at, timeoutMs, fetchImpl);
93
+ }
94
+ const poll = { until: now + POLL_MS, token: signIn.token, refused: false, answer: askChatGpt(signIn, at, timeoutMs, fetchImpl) };
95
+ polls.set(key, poll);
96
+ const answer = await poll.answer;
97
+ // A refused token belongs to one folder; another client's valid sign-in may still read the same pool.
98
+ poll.refused = answer.kind === 'missing';
99
+ return answer;
100
+ }
101
+ /**
102
+ * Asks ChatGPT for the subscription's windows without renewing the sign-in. Expiry and refusal have separate reasons;
103
+ * the owning client decides whether to renew. Any other failure throws, for the watcher to retry.
104
+ */
105
+ export async function askChatGpt(signIn, at, timeoutMs, fetchImpl = fetch) {
106
+ if (signIn.expiresAt !== null && signIn.expiresAt <= Date.parse(at))
107
+ return { kind: 'missing', reason: notice('usage.chatGptExpired', {}) };
108
+ const accountId = signIn.accountId ?? chatGptAccountOf(signIn.token);
109
+ const headers = { Authorization: `Bearer ${signIn.token}`, Accept: 'application/json' };
110
+ if (accountId !== null)
111
+ headers['ChatGPT-Account-Id'] = accountId;
112
+ const response = await fetchImpl(CHATGPT_USAGE_URL, { headers, signal: AbortSignal.timeout(timeoutMs) });
113
+ if (response.status === 401 || response.status === 403)
114
+ return { kind: 'missing', reason: notice('usage.chatGptRevoked', {}) };
115
+ if (!response.ok)
116
+ throw new Error(`ChatGPT usage answered ${response.status}`);
117
+ const limits = chatGptLimits(await response.json().catch(() => undefined), at);
118
+ if (limits === undefined)
119
+ return { kind: 'unknown', reason: notice('usage.chatGptUnread', {}) };
120
+ return { kind: 'limits', limits: accountId === null ? limits : { ...limits, pool: chatGptPool(accountId) } };
121
+ }
122
+ /** The pool of a ChatGPT account: a Codex and an OpenCode folder signed in to it share its limits. */
123
+ export function chatGptPool(accountId) {
124
+ return `chatgpt:${accountId}`;
125
+ }
126
+ function windowOf(raw, at) {
127
+ const { used_percent: used, reset_at: resetAt, reset_after_seconds: after } = raw;
128
+ if (typeof used !== 'number' || !Number.isFinite(used))
129
+ return null;
130
+ const reset = typeof resetAt === 'number' && resetAt > 0 ? resetAt * 1000 : typeof after === 'number' ? Date.parse(at) + after * 1000 : NaN;
131
+ return Number.isFinite(reset) ? { usedPercentage: used, resetsAt: new Date(reset).toISOString() } : null;
132
+ }
133
+ function isRecord(value) {
134
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
135
+ }
136
+ function claimsOf(token) {
137
+ try {
138
+ const claims = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString('utf8'));
139
+ return isRecord(claims) ? claims : undefined;
140
+ }
141
+ catch {
142
+ return undefined;
143
+ }
144
+ }