lastlight 0.16.0 → 0.16.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 (385) hide show
  1. package/README.md +71 -692
  2. package/dist/cli-config.js.map +1 -0
  3. package/dist/cli-format.js.map +1 -0
  4. package/dist/{cli/cli-server.d.ts → cli-server.d.ts} +39 -1
  5. package/dist/{cli/cli-server.js → cli-server.js} +105 -5
  6. package/dist/cli-server.js.map +1 -0
  7. package/dist/cli-timeline.js.map +1 -0
  8. package/dist/{cli/cli.js → cli.js} +9 -7
  9. package/dist/cli.js.map +1 -0
  10. package/dist/{cli/fork-cli.d.ts → fork-cli.d.ts} +3 -3
  11. package/dist/{cli/fork-cli.js → fork-cli.js} +28 -27
  12. package/dist/fork-cli.js.map +1 -0
  13. package/dist/{cli/oauth-cli.js → oauth-cli.js} +1 -1
  14. package/dist/oauth-cli.js.map +1 -0
  15. package/dist/{cli/setup.js → setup.js} +10 -4
  16. package/dist/setup.js.map +1 -0
  17. package/dist/{cli/skills-install.d.ts → skills-install.d.ts} +6 -0
  18. package/dist/{cli/skills-install.js → skills-install.js} +6 -2
  19. package/dist/skills-install.js.map +1 -0
  20. package/package.json +20 -65
  21. package/plugins/lastlight/.claude-plugin/plugin.json +1 -1
  22. package/agent-context/rules.md +0 -80
  23. package/agent-context/security.md +0 -69
  24. package/agent-context/soul.md +0 -21
  25. package/config/default.yaml +0 -119
  26. package/deploy/.env.production.example +0 -100
  27. package/deploy/entrypoint.sh +0 -82
  28. package/deploy/native/README.md +0 -160
  29. package/deploy/native/install.sh +0 -110
  30. package/deploy/native/lastlight.env.example +0 -95
  31. package/deploy/native/lastlight.service +0 -50
  32. package/deploy/sandbox-entrypoint.sh +0 -93
  33. package/dist/admin/auth.d.ts +0 -51
  34. package/dist/admin/auth.js +0 -121
  35. package/dist/admin/auth.js.map +0 -1
  36. package/dist/admin/chat-session-reader.d.ts +0 -39
  37. package/dist/admin/chat-session-reader.js +0 -84
  38. package/dist/admin/chat-session-reader.js.map +0 -1
  39. package/dist/admin/docker.d.ts +0 -61
  40. package/dist/admin/docker.js +0 -187
  41. package/dist/admin/docker.js.map +0 -1
  42. package/dist/admin/index.d.ts +0 -9
  43. package/dist/admin/index.js +0 -59
  44. package/dist/admin/index.js.map +0 -1
  45. package/dist/admin/routes.d.ts +0 -81
  46. package/dist/admin/routes.js +0 -1381
  47. package/dist/admin/routes.js.map +0 -1
  48. package/dist/admin/sessions.d.ts +0 -89
  49. package/dist/admin/sessions.js +0 -204
  50. package/dist/admin/sessions.js.map +0 -1
  51. package/dist/admin/tail.d.ts +0 -12
  52. package/dist/admin/tail.js +0 -145
  53. package/dist/admin/tail.js.map +0 -1
  54. package/dist/admin/version.d.ts +0 -22
  55. package/dist/admin/version.js +0 -92
  56. package/dist/admin/version.js.map +0 -1
  57. package/dist/cli/cli-config.js.map +0 -1
  58. package/dist/cli/cli-format.js.map +0 -1
  59. package/dist/cli/cli-server.js.map +0 -1
  60. package/dist/cli/cli-timeline.js.map +0 -1
  61. package/dist/cli/cli.js.map +0 -1
  62. package/dist/cli/fork-cli.js.map +0 -1
  63. package/dist/cli/oauth-cli.js.map +0 -1
  64. package/dist/cli/setup.js.map +0 -1
  65. package/dist/cli/skills-install.js.map +0 -1
  66. package/dist/config/config-resolve.d.ts +0 -28
  67. package/dist/config/config-resolve.js +0 -47
  68. package/dist/config/config-resolve.js.map +0 -1
  69. package/dist/config/config.d.ts +0 -157
  70. package/dist/config/config.js +0 -581
  71. package/dist/config/config.js.map +0 -1
  72. package/dist/config/core-pin.d.ts +0 -16
  73. package/dist/config/core-pin.js +0 -85
  74. package/dist/config/core-pin.js.map +0 -1
  75. package/dist/config/overlay-assets.d.ts +0 -20
  76. package/dist/config/overlay-assets.js +0 -114
  77. package/dist/config/overlay-assets.js.map +0 -1
  78. package/dist/config/overlay-bootstrap.d.ts +0 -44
  79. package/dist/config/overlay-bootstrap.js +0 -304
  80. package/dist/config/overlay-bootstrap.js.map +0 -1
  81. package/dist/connectors/github-webhook.d.ts +0 -45
  82. package/dist/connectors/github-webhook.js +0 -321
  83. package/dist/connectors/github-webhook.js.map +0 -1
  84. package/dist/connectors/index.d.ts +0 -18
  85. package/dist/connectors/index.js +0 -41
  86. package/dist/connectors/index.js.map +0 -1
  87. package/dist/connectors/messaging/base.d.ts +0 -42
  88. package/dist/connectors/messaging/base.js +0 -139
  89. package/dist/connectors/messaging/base.js.map +0 -1
  90. package/dist/connectors/messaging/delivery.d.ts +0 -14
  91. package/dist/connectors/messaging/delivery.js +0 -38
  92. package/dist/connectors/messaging/delivery.js.map +0 -1
  93. package/dist/connectors/messaging/index.d.ts +0 -4
  94. package/dist/connectors/messaging/index.js +0 -4
  95. package/dist/connectors/messaging/index.js.map +0 -1
  96. package/dist/connectors/messaging/session-manager.d.ts +0 -53
  97. package/dist/connectors/messaging/session-manager.js +0 -255
  98. package/dist/connectors/messaging/session-manager.js.map +0 -1
  99. package/dist/connectors/messaging/types.d.ts +0 -58
  100. package/dist/connectors/messaging/types.js +0 -7
  101. package/dist/connectors/messaging/types.js.map +0 -1
  102. package/dist/connectors/slack/connector.d.ts +0 -142
  103. package/dist/connectors/slack/connector.js +0 -494
  104. package/dist/connectors/slack/connector.js.map +0 -1
  105. package/dist/connectors/slack/index.d.ts +0 -2
  106. package/dist/connectors/slack/index.js +0 -3
  107. package/dist/connectors/slack/index.js.map +0 -1
  108. package/dist/connectors/slack/mrkdwn.d.ts +0 -19
  109. package/dist/connectors/slack/mrkdwn.js +0 -240
  110. package/dist/connectors/slack/mrkdwn.js.map +0 -1
  111. package/dist/connectors/types.d.ts +0 -61
  112. package/dist/connectors/types.js +0 -2
  113. package/dist/connectors/types.js.map +0 -1
  114. package/dist/cron/fanout.d.ts +0 -33
  115. package/dist/cron/fanout.js +0 -55
  116. package/dist/cron/fanout.js.map +0 -1
  117. package/dist/cron/jobs.d.ts +0 -18
  118. package/dist/cron/jobs.js +0 -37
  119. package/dist/cron/jobs.js.map +0 -1
  120. package/dist/cron/scheduler.d.ts +0 -45
  121. package/dist/cron/scheduler.js +0 -105
  122. package/dist/cron/scheduler.js.map +0 -1
  123. package/dist/engine/agent-executor.d.ts +0 -34
  124. package/dist/engine/agent-executor.js +0 -246
  125. package/dist/engine/agent-executor.js.map +0 -1
  126. package/dist/engine/chat/chat-runner.d.ts +0 -132
  127. package/dist/engine/chat/chat-runner.js +0 -424
  128. package/dist/engine/chat/chat-runner.js.map +0 -1
  129. package/dist/engine/chat/chat-skills.d.ts +0 -45
  130. package/dist/engine/chat/chat-skills.js +0 -184
  131. package/dist/engine/chat/chat-skills.js.map +0 -1
  132. package/dist/engine/chat/chat.d.ts +0 -54
  133. package/dist/engine/chat/chat.js +0 -316
  134. package/dist/engine/chat/chat.js.map +0 -1
  135. package/dist/engine/chat/message-batcher.d.ts +0 -32
  136. package/dist/engine/chat/message-batcher.js +0 -109
  137. package/dist/engine/chat/message-batcher.js.map +0 -1
  138. package/dist/engine/dispatcher.d.ts +0 -73
  139. package/dist/engine/dispatcher.js +0 -663
  140. package/dist/engine/dispatcher.js.map +0 -1
  141. package/dist/engine/event-shim.d.ts +0 -117
  142. package/dist/engine/event-shim.js +0 -435
  143. package/dist/engine/event-shim.js.map +0 -1
  144. package/dist/engine/executors/orchestrator.d.ts +0 -81
  145. package/dist/engine/executors/orchestrator.js +0 -365
  146. package/dist/engine/executors/orchestrator.js.map +0 -1
  147. package/dist/engine/executors/shared.d.ts +0 -189
  148. package/dist/engine/executors/shared.js +0 -616
  149. package/dist/engine/executors/shared.js.map +0 -1
  150. package/dist/engine/github/git-auth.d.ts +0 -62
  151. package/dist/engine/github/git-auth.js +0 -161
  152. package/dist/engine/github/git-auth.js.map +0 -1
  153. package/dist/engine/github/github-app-client.d.ts +0 -23
  154. package/dist/engine/github/github-app-client.js +0 -33
  155. package/dist/engine/github/github-app-client.js.map +0 -1
  156. package/dist/engine/github/github-tools.d.ts +0 -18
  157. package/dist/engine/github/github-tools.js +0 -263
  158. package/dist/engine/github/github-tools.js.map +0 -1
  159. package/dist/engine/github/github.d.ts +0 -1193
  160. package/dist/engine/github/github.js +0 -357
  161. package/dist/engine/github/github.js.map +0 -1
  162. package/dist/engine/github/profiles.d.ts +0 -279
  163. package/dist/engine/github/profiles.js +0 -42
  164. package/dist/engine/github/profiles.js.map +0 -1
  165. package/dist/engine/github/review-poster.d.ts +0 -98
  166. package/dist/engine/github/review-poster.js +0 -177
  167. package/dist/engine/github/review-poster.js.map +0 -1
  168. package/dist/engine/llm.d.ts +0 -79
  169. package/dist/engine/llm.js +0 -269
  170. package/dist/engine/llm.js.map +0 -1
  171. package/dist/engine/oauth.d.ts +0 -43
  172. package/dist/engine/oauth.js +0 -103
  173. package/dist/engine/oauth.js.map +0 -1
  174. package/dist/engine/router.d.ts +0 -29
  175. package/dist/engine/router.js +0 -680
  176. package/dist/engine/router.js.map +0 -1
  177. package/dist/engine/screen/classifier.d.ts +0 -93
  178. package/dist/engine/screen/classifier.js +0 -215
  179. package/dist/engine/screen/classifier.js.map +0 -1
  180. package/dist/engine/screen/screen.d.ts +0 -41
  181. package/dist/engine/screen/screen.js +0 -93
  182. package/dist/engine/screen/screen.js.map +0 -1
  183. package/dist/evals-api.d.ts +0 -24
  184. package/dist/evals-api.js +0 -22
  185. package/dist/evals-api.js.map +0 -1
  186. package/dist/index.d.ts +0 -1
  187. package/dist/index.js +0 -940
  188. package/dist/index.js.map +0 -1
  189. package/dist/managed-repos.d.ts +0 -30
  190. package/dist/managed-repos.js +0 -72
  191. package/dist/managed-repos.js.map +0 -1
  192. package/dist/notify/blocks.d.ts +0 -23
  193. package/dist/notify/blocks.js +0 -118
  194. package/dist/notify/blocks.js.map +0 -1
  195. package/dist/notify/index.d.ts +0 -17
  196. package/dist/notify/index.js +0 -7
  197. package/dist/notify/index.js.map +0 -1
  198. package/dist/notify/model.d.ts +0 -57
  199. package/dist/notify/model.js +0 -89
  200. package/dist/notify/model.js.map +0 -1
  201. package/dist/notify/notifier.d.ts +0 -18
  202. package/dist/notify/notifier.js +0 -100
  203. package/dist/notify/notifier.js.map +0 -1
  204. package/dist/notify/render.d.ts +0 -21
  205. package/dist/notify/render.js +0 -59
  206. package/dist/notify/render.js.map +0 -1
  207. package/dist/notify/transports/github.d.ts +0 -26
  208. package/dist/notify/transports/github.js +0 -27
  209. package/dist/notify/transports/github.js.map +0 -1
  210. package/dist/notify/transports/slack.d.ts +0 -27
  211. package/dist/notify/transports/slack.js +0 -37
  212. package/dist/notify/transports/slack.js.map +0 -1
  213. package/dist/notify/types.d.ts +0 -119
  214. package/dist/notify/types.js +0 -16
  215. package/dist/notify/types.js.map +0 -1
  216. package/dist/providers.d.ts +0 -125
  217. package/dist/providers.js +0 -279
  218. package/dist/providers.js.map +0 -1
  219. package/dist/sandbox/docker.d.ts +0 -180
  220. package/dist/sandbox/docker.js +0 -517
  221. package/dist/sandbox/docker.js.map +0 -1
  222. package/dist/sandbox/egress-allowlist.d.ts +0 -74
  223. package/dist/sandbox/egress-allowlist.js +0 -164
  224. package/dist/sandbox/egress-allowlist.js.map +0 -1
  225. package/dist/sandbox/egress-firewall-config.d.ts +0 -127
  226. package/dist/sandbox/egress-firewall-config.js +0 -434
  227. package/dist/sandbox/egress-firewall-config.js.map +0 -1
  228. package/dist/sandbox/images.d.ts +0 -23
  229. package/dist/sandbox/images.js +0 -55
  230. package/dist/sandbox/images.js.map +0 -1
  231. package/dist/sandbox/index.d.ts +0 -112
  232. package/dist/sandbox/index.js +0 -332
  233. package/dist/sandbox/index.js.map +0 -1
  234. package/dist/sandbox/sandbox.d.ts +0 -214
  235. package/dist/sandbox/sandbox.js +0 -453
  236. package/dist/sandbox/sandbox.js.map +0 -1
  237. package/dist/sandbox/smol.d.ts +0 -162
  238. package/dist/sandbox/smol.js +0 -485
  239. package/dist/sandbox/smol.js.map +0 -1
  240. package/dist/session-log.d.ts +0 -63
  241. package/dist/session-log.js +0 -290
  242. package/dist/session-log.js.map +0 -1
  243. package/dist/state/approval-store.d.ts +0 -88
  244. package/dist/state/approval-store.js +0 -149
  245. package/dist/state/approval-store.js.map +0 -1
  246. package/dist/state/build-assets.d.ts +0 -50
  247. package/dist/state/build-assets.js +0 -154
  248. package/dist/state/build-assets.js.map +0 -1
  249. package/dist/state/db.d.ts +0 -81
  250. package/dist/state/db.js +0 -155
  251. package/dist/state/db.js.map +0 -1
  252. package/dist/state/execution-store.d.ts +0 -257
  253. package/dist/state/execution-store.js +0 -527
  254. package/dist/state/execution-store.js.map +0 -1
  255. package/dist/state/migrate.d.ts +0 -15
  256. package/dist/state/migrate.js +0 -175
  257. package/dist/state/migrate.js.map +0 -1
  258. package/dist/state/workflow-run-store.d.ts +0 -216
  259. package/dist/state/workflow-run-store.js +0 -403
  260. package/dist/state/workflow-run-store.js.map +0 -1
  261. package/dist/telemetry/index.d.ts +0 -38
  262. package/dist/telemetry/index.js +0 -253
  263. package/dist/telemetry/index.js.map +0 -1
  264. package/dist/telemetry/pi-events.d.ts +0 -12
  265. package/dist/telemetry/pi-events.js +0 -134
  266. package/dist/telemetry/pi-events.js.map +0 -1
  267. package/dist/workflows/dag.d.ts +0 -37
  268. package/dist/workflows/dag.js +0 -118
  269. package/dist/workflows/dag.js.map +0 -1
  270. package/dist/workflows/loader.d.ts +0 -53
  271. package/dist/workflows/loader.js +0 -421
  272. package/dist/workflows/loader.js.map +0 -1
  273. package/dist/workflows/loop-eval.d.ts +0 -28
  274. package/dist/workflows/loop-eval.js +0 -74
  275. package/dist/workflows/loop-eval.js.map +0 -1
  276. package/dist/workflows/phase-executor.d.ts +0 -222
  277. package/dist/workflows/phase-executor.js +0 -1153
  278. package/dist/workflows/phase-executor.js.map +0 -1
  279. package/dist/workflows/phase-ref.d.ts +0 -50
  280. package/dist/workflows/phase-ref.js +0 -91
  281. package/dist/workflows/phase-ref.js.map +0 -1
  282. package/dist/workflows/resume.d.ts +0 -58
  283. package/dist/workflows/resume.js +0 -313
  284. package/dist/workflows/resume.js.map +0 -1
  285. package/dist/workflows/runner.d.ts +0 -63
  286. package/dist/workflows/runner.js +0 -381
  287. package/dist/workflows/runner.js.map +0 -1
  288. package/dist/workflows/schema.d.ts +0 -344
  289. package/dist/workflows/schema.js +0 -460
  290. package/dist/workflows/schema.js.map +0 -1
  291. package/dist/workflows/simple.d.ts +0 -90
  292. package/dist/workflows/simple.js +0 -393
  293. package/dist/workflows/simple.js.map +0 -1
  294. package/dist/workflows/target-policy.d.ts +0 -74
  295. package/dist/workflows/target-policy.js +0 -80
  296. package/dist/workflows/target-policy.js.map +0 -1
  297. package/dist/workflows/templates.d.ts +0 -88
  298. package/dist/workflows/templates.js +0 -127
  299. package/dist/workflows/templates.js.map +0 -1
  300. package/dist/workflows/triggers.d.ts +0 -21
  301. package/dist/workflows/triggers.js +0 -45
  302. package/dist/workflows/triggers.js.map +0 -1
  303. package/dist/workflows/verdict.d.ts +0 -19
  304. package/dist/workflows/verdict.js +0 -30
  305. package/dist/workflows/verdict.js.map +0 -1
  306. package/dist/worktree/manager.d.ts +0 -43
  307. package/dist/worktree/manager.js +0 -127
  308. package/dist/worktree/manager.js.map +0 -1
  309. package/docker-compose.yml +0 -274
  310. package/sandbox.Dockerfile +0 -68
  311. package/skills/README.md +0 -42
  312. package/skills/browser-qa/SKILL.md +0 -208
  313. package/skills/browser-qa/scripts/agent-browser.mjs +0 -531
  314. package/skills/building/SKILL.md +0 -95
  315. package/skills/chat/SKILL.md +0 -36
  316. package/skills/code-review/SKILL.md +0 -82
  317. package/skills/debug-production/SKILL.md +0 -108
  318. package/skills/demo/SKILL.md +0 -228
  319. package/skills/demo/scripts/compose-demo.sh +0 -243
  320. package/skills/issue-answer/SKILL.md +0 -91
  321. package/skills/issue-comment/SKILL.md +0 -49
  322. package/skills/issue-triage/SKILL.md +0 -149
  323. package/skills/issue-triage/references/AGENT-BRIEF.md +0 -65
  324. package/skills/pr-comment/SKILL.md +0 -64
  325. package/skills/pr-review/SKILL.md +0 -148
  326. package/skills/pr-review/references/findings-schema.md +0 -89
  327. package/skills/qa-test/SKILL.md +0 -97
  328. package/skills/repo-health/SKILL.md +0 -67
  329. package/skills/security-feedback/SKILL.md +0 -173
  330. package/skills/security-feedback/references/templates.md +0 -77
  331. package/skills/security-review/SKILL.md +0 -215
  332. package/skills/security-review/references/issue-format.md +0 -302
  333. package/skills/verify/SKILL.md +0 -118
  334. package/workflows/answer.yaml +0 -44
  335. package/workflows/build.yaml +0 -129
  336. package/workflows/cron-health.yaml +0 -6
  337. package/workflows/cron-review.yaml +0 -8
  338. package/workflows/cron-security.yaml +0 -6
  339. package/workflows/cron-triage.yaml +0 -8
  340. package/workflows/demo.yaml +0 -62
  341. package/workflows/examples/bash-smoke.yaml +0 -41
  342. package/workflows/examples/parallel-review.yaml +0 -36
  343. package/workflows/examples/tdd-loop.yaml +0 -17
  344. package/workflows/explore.yaml +0 -80
  345. package/workflows/issue-comment.yaml +0 -15
  346. package/workflows/issue-triage.yaml +0 -22
  347. package/workflows/pr-comment.yaml +0 -16
  348. package/workflows/pr-fix.yaml +0 -17
  349. package/workflows/pr-review.yaml +0 -50
  350. package/workflows/prompts/answer.md +0 -68
  351. package/workflows/prompts/architect.md +0 -44
  352. package/workflows/prompts/classifier.md +0 -60
  353. package/workflows/prompts/classify-adds-info.md +0 -17
  354. package/workflows/prompts/demo.md +0 -125
  355. package/workflows/prompts/executor.md +0 -42
  356. package/workflows/prompts/explore-ask.md +0 -99
  357. package/workflows/prompts/explore-publish.md +0 -31
  358. package/workflows/prompts/explore-read.md +0 -120
  359. package/workflows/prompts/explore-synthesize.md +0 -88
  360. package/workflows/prompts/fix.md +0 -18
  361. package/workflows/prompts/guardrails.md +0 -96
  362. package/workflows/prompts/pr-fix.md +0 -26
  363. package/workflows/prompts/pr.md +0 -39
  364. package/workflows/prompts/qa-browser.md +0 -95
  365. package/workflows/prompts/qa-synth.md +0 -44
  366. package/workflows/prompts/qa-test.md +0 -60
  367. package/workflows/prompts/re-reviewer.md +0 -33
  368. package/workflows/prompts/reviewer.md +0 -60
  369. package/workflows/prompts/verify-browser.md +0 -93
  370. package/workflows/prompts/verify-synth.md +0 -44
  371. package/workflows/prompts/verify.md +0 -63
  372. package/workflows/qa-test.yaml +0 -94
  373. package/workflows/repo-health.yaml +0 -15
  374. package/workflows/security-feedback.yaml +0 -25
  375. package/workflows/security-review.yaml +0 -37
  376. package/workflows/verify.yaml +0 -93
  377. /package/dist/{cli/cli-config.d.ts → cli-config.d.ts} +0 -0
  378. /package/dist/{cli/cli-config.js → cli-config.js} +0 -0
  379. /package/dist/{cli/cli-format.d.ts → cli-format.d.ts} +0 -0
  380. /package/dist/{cli/cli-format.js → cli-format.js} +0 -0
  381. /package/dist/{cli/cli-timeline.d.ts → cli-timeline.d.ts} +0 -0
  382. /package/dist/{cli/cli-timeline.js → cli-timeline.js} +0 -0
  383. /package/dist/{cli/cli.d.ts → cli.d.ts} +0 -0
  384. /package/dist/{cli/oauth-cli.d.ts → oauth-cli.d.ts} +0 -0
  385. /package/dist/{cli/setup.d.ts → setup.d.ts} +0 -0
@@ -1,403 +0,0 @@
1
- /**
2
- * Aggregate root for a workflow run's lifecycle. Owns the `workflow_runs`
3
- * table (including the `phase_history` JSON column) and the named, atomic
4
- * transitions a run moves through: create → pause-for-approval →
5
- * resume/finish, plus gate resolution and the socratic reply append.
6
- *
7
- * Carved out of the old `StateDb` god-class (issue #97). The deepening: every
8
- * multi-step mutation that previously lived as an un-guarded read-modify-write
9
- * chain in `index.ts` / `admin/routes.ts` / `phase-executor.ts` is now a
10
- * single named operation wrapped in ONE `better-sqlite3` transaction — a throw
11
- * partway through rolls the whole thing back, so a run can never be left
12
- * marked `running` with its gate unresolved (the hazard the issue calls out).
13
- *
14
- * Constructed with an injected {@link ApprovalStore}: an approval has no life
15
- * independent of its run, so the cross-table ops call the approval store's
16
- * single-table writes from inside this store's transaction. Both stores MUST
17
- * be built from the same `Database` — better-sqlite3 transactions are
18
- * per-connection.
19
- *
20
- * The long-running re-dispatch (`dispatchWorkflow`, which spawns a Docker
21
- * sandbox for minutes) is deliberately NOT part of any transaction here —
22
- * better-sqlite3 transactions are synchronous. The atomic boundary is the DB
23
- * mutations only; the caller dispatches after the transaction commits.
24
- */
25
- export class WorkflowRunStore {
26
- db;
27
- approvals;
28
- constructor(db, deps) {
29
- this.db = db;
30
- this.approvals = deps.approvals;
31
- }
32
- // ── Plain single-mutation operations ───────────────────────────
33
- /** Create a new workflow run record */
34
- createRun(run) {
35
- const now = new Date().toISOString();
36
- this.db.prepare(`
37
- INSERT INTO workflow_runs (id, workflow_name, trigger_id, repo, issue_number, current_phase, phase_history, status, context, scratch, started_at, updated_at)
38
- VALUES (?, ?, ?, ?, ?, ?, '[]', ?, ?, ?, ?, ?)
39
- `).run(run.id, run.workflowName, run.triggerId, run.repo ?? null, run.issueNumber ?? null, run.currentPhase, run.status, run.context ? JSON.stringify(run.context) : null, run.scratch ? JSON.stringify(run.scratch) : null, run.startedAt, now);
40
- }
41
- /**
42
- * Top-level merge of `patch` into the workflow run's scratch state.
43
- * Loop iterations can append to `scratch.socratic.qa` without clobbering
44
- * other keys.
45
- *
46
- * Throws if `patch` is not JSON-serializable (e.g. it contains a BigInt) —
47
- * which is exactly how the atomic ops prove their rollback: a poison patch
48
- * makes `JSON.stringify` throw mid-transaction.
49
- */
50
- mergeScratch(id, patch) {
51
- const now = new Date().toISOString();
52
- const row = this.db
53
- .prepare(`SELECT scratch FROM workflow_runs WHERE id = ?`)
54
- .get(id);
55
- if (!row)
56
- return;
57
- const current = row.scratch ? JSON.parse(row.scratch) : {};
58
- const merged = { ...current, ...patch };
59
- // Stringify BEFORE the UPDATE so a non-serializable patch throws without
60
- // having mutated the row — keeps the op all-or-nothing even outside a txn.
61
- const serialized = JSON.stringify(merged);
62
- this.db
63
- .prepare(`UPDATE workflow_runs SET scratch = ?, updated_at = ? WHERE id = ?`)
64
- .run(serialized, now, id);
65
- }
66
- /**
67
- * Update the current phase and append to phase history. This is the single
68
- * seam through which all phase-history writes flow (issue #97 defers the
69
- * full `phase_history`/`executions` reconciliation to a follow-up, but
70
- * routes every write through here so that future change touches one method
71
- * instead of ~10 call sites).
72
- */
73
- appendPhase(id, phase, entry) {
74
- const now = new Date().toISOString();
75
- const row = this.db.prepare(`SELECT phase_history FROM workflow_runs WHERE id = ?`).get(id);
76
- if (!row)
77
- return;
78
- const history = JSON.parse(row.phase_history);
79
- history.push(entry);
80
- this.db.prepare(`
81
- UPDATE workflow_runs SET current_phase = ?, phase_history = ?, updated_at = ? WHERE id = ?
82
- `).run(phase, JSON.stringify(history), now, id);
83
- }
84
- /** Get a single workflow run by ID */
85
- getRun(id) {
86
- const row = this.db.prepare(`SELECT * FROM workflow_runs WHERE id = ?`).get(id);
87
- return row ? this.deserialize(row) : null;
88
- }
89
- /** Find the most recent active (running or paused) workflow run for a trigger */
90
- getByTrigger(triggerId) {
91
- const row = this.db.prepare(`
92
- SELECT * FROM workflow_runs
93
- WHERE trigger_id = ? AND status IN ('running', 'paused')
94
- ORDER BY started_at DESC
95
- LIMIT 1
96
- `).get(triggerId);
97
- return row ? this.deserialize(row) : null;
98
- }
99
- /**
100
- * True if any run of `workflowName` exists for this trigger, in ANY status.
101
- * Unlike `getByTrigger` (active runs only), this also sees a build that has
102
- * already succeeded/failed/cancelled — the signal the router uses to gate
103
- * reporter-driven re-triage to the pre-build window.
104
- */
105
- hasRunForTrigger(triggerId, workflowName) {
106
- const row = this.db.prepare(`
107
- SELECT 1 FROM workflow_runs
108
- WHERE trigger_id = ? AND workflow_name = ?
109
- LIMIT 1
110
- `).get(triggerId, workflowName);
111
- return !!row;
112
- }
113
- /** List all active (running or paused) workflow runs */
114
- listActive() {
115
- const rows = this.db.prepare(`
116
- SELECT * FROM workflow_runs WHERE status IN ('running', 'paused') ORDER BY started_at DESC
117
- `).all();
118
- return rows.map((r) => this.deserialize(r));
119
- }
120
- /** List recent workflow runs, ordered by start time descending */
121
- listRecent(limit = 20) {
122
- const rows = this.db.prepare(`
123
- SELECT * FROM workflow_runs ORDER BY started_at DESC LIMIT ?
124
- `).all(limit);
125
- return rows.map((r) => this.deserialize(r));
126
- }
127
- /**
128
- * List workflow runs with pagination + filters. Returns the page slice
129
- * AND the post-filter total so the dashboard knows how many remain.
130
- *
131
- * - sinceIso filters `started_at >= sinceIso` (used for the header date range).
132
- * - workflowName filters by exact `workflow_name`.
133
- * - statuses filters to one of the workflow statuses (`running`, `paused`,
134
- * `succeeded`, `failed`, `cancelled`). Used for the dashboard's "live"
135
- * filter, which maps to ['running','paused'].
136
- */
137
- list(opts = {}) {
138
- const limit = opts.limit ?? 20;
139
- const offset = opts.offset ?? 0;
140
- const where = [];
141
- const params = [];
142
- if (opts.sinceIso) {
143
- where.push("started_at >= ?");
144
- params.push(opts.sinceIso);
145
- }
146
- if (opts.workflowName) {
147
- where.push("workflow_name = ?");
148
- params.push(opts.workflowName);
149
- }
150
- if (opts.statuses && opts.statuses.length > 0) {
151
- where.push(`status IN (${opts.statuses.map(() => "?").join(",")})`);
152
- params.push(...opts.statuses);
153
- }
154
- const whereClause = where.length > 0 ? `WHERE ${where.join(" AND ")}` : "";
155
- const total = this.db
156
- .prepare(`SELECT COUNT(*) as c FROM workflow_runs ${whereClause}`)
157
- .get(...params).c;
158
- // Explicit column list — the heavy JSON blobs (`context`, `scratch`)
159
- // can each be many MB on long-running build runs and
160
- // the dashboard list view doesn't read them. Returning them turned a
161
- // 20-row page into a 14MB payload. The single-row endpoint
162
- // (`getRun`) still uses `SELECT *` so the detail panel keeps
163
- // the full row when the user picks one.
164
- const rows = this.db
165
- .prepare(`SELECT
166
- id, workflow_name, trigger_id, repo, issue_number,
167
- current_phase, phase_history, status,
168
- restart_count, started_at, updated_at, finished_at
169
- FROM workflow_runs
170
- ${whereClause}
171
- ORDER BY started_at DESC
172
- LIMIT ? OFFSET ?`)
173
- .all(...params, limit, offset);
174
- return {
175
- runs: rows.map((r) => this.deserialize(r)),
176
- total,
177
- };
178
- }
179
- /** Distinct workflow_name values, sorted alphabetically. */
180
- distinctNames() {
181
- const rows = this.db
182
- .prepare(`SELECT DISTINCT workflow_name FROM workflow_runs ORDER BY workflow_name ASC`)
183
- .all();
184
- return rows.map((r) => r.workflow_name);
185
- }
186
- /**
187
- * Mark a workflow run as finished. Plain status flip when called with just
188
- * `{ error }`; when a `terminalMarker` is supplied (the runner's
189
- * `on_success.set_phase`), the phase-history append and the status flip
190
- * happen in ONE transaction so the dashboard never sees the terminal phase
191
- * without the finished status, or vice versa.
192
- */
193
- finishRun(id, status, opts = {}) {
194
- const apply = () => {
195
- if (opts.terminalMarker) {
196
- this.appendPhase(id, opts.terminalMarker.phase, {
197
- phase: opts.terminalMarker.phase,
198
- timestamp: new Date().toISOString(),
199
- success: true,
200
- summary: opts.terminalMarker.summary,
201
- });
202
- }
203
- this.flipFinished(id, status, opts.error);
204
- };
205
- if (opts.terminalMarker) {
206
- this.db.transaction(apply)();
207
- }
208
- else {
209
- apply();
210
- }
211
- }
212
- flipFinished(id, status, error) {
213
- const now = new Date().toISOString();
214
- this.db.prepare(`
215
- UPDATE workflow_runs SET status = ?, finished_at = ?, updated_at = ?, context = CASE
216
- WHEN ? IS NOT NULL THEN json_patch(COALESCE(context, '{}'), json_object('error', ?))
217
- ELSE context
218
- END WHERE id = ?
219
- `).run(status, now, now, error ?? null, error ?? null, id);
220
- }
221
- /** Cancel a workflow run */
222
- cancelRun(id) {
223
- const now = new Date().toISOString();
224
- this.db.prepare(`
225
- UPDATE workflow_runs SET status = 'cancelled', updated_at = ?, finished_at = ? WHERE id = ?
226
- `).run(now, now, id);
227
- }
228
- /** Pause a workflow run (waiting for approval) */
229
- setPaused(id) {
230
- const now = new Date().toISOString();
231
- this.db.prepare(`
232
- UPDATE workflow_runs SET status = 'paused', updated_at = ? WHERE id = ?
233
- `).run(now, id);
234
- }
235
- /** Resume a paused workflow run (set back to running) */
236
- setRunning(id) {
237
- const now = new Date().toISOString();
238
- this.db.prepare(`
239
- UPDATE workflow_runs SET status = 'running', updated_at = ? WHERE id = ?
240
- `).run(now, id);
241
- }
242
- /**
243
- * Restart a FAILED run so it can be retried from the phase that failed.
244
- * Unlike {@link setRunning} this also clears the terminal markers a failure
245
- * left behind — `finished_at` and the `context.error` string `flipFinished`
246
- * wrote — so the row reads live again rather than "failed at …". The taskId,
247
- * branch, scratch and phase_history are all preserved, so the ledger-driven
248
- * re-dispatch (`resumeSimpleRun`) resumes from the failed phase with the same
249
- * context.
250
- *
251
- * Guarded by `WHERE status = 'failed'` and returns the changed-row count so
252
- * the caller can make retry a compare-and-set: a second concurrent retry
253
- * click sees 0 rows changed and does NOT dispatch again.
254
- */
255
- restartRun(id) {
256
- const now = new Date().toISOString();
257
- const info = this.db.prepare(`
258
- UPDATE workflow_runs
259
- SET status = 'running',
260
- finished_at = NULL,
261
- updated_at = ?,
262
- restart_count = COALESCE(restart_count, 0) + 1,
263
- context = json_remove(COALESCE(context, '{}'), '$.error')
264
- WHERE id = ? AND status = 'failed'
265
- `).run(now, id);
266
- return info.changes;
267
- }
268
- /**
269
- * Increment the restart counter and return the new value. Used by
270
- * `resumeOrphanedWorkflows` to enforce a retry budget so a run that
271
- * crashes the host (agent OOM, etc.) eventually self-terminates instead
272
- * of being re-dispatched on every boot.
273
- */
274
- incrementRestartCount(id) {
275
- const now = new Date().toISOString();
276
- this.db.prepare(`
277
- UPDATE workflow_runs
278
- SET restart_count = COALESCE(restart_count, 0) + 1, updated_at = ?
279
- WHERE id = ?
280
- `).run(now, id);
281
- const row = this.db.prepare(`SELECT restart_count FROM workflow_runs WHERE id = ?`)
282
- .get(id);
283
- return row?.restart_count ?? 0;
284
- }
285
- deserialize(row) {
286
- return {
287
- id: row.id,
288
- workflowName: row.workflow_name,
289
- triggerId: row.trigger_id,
290
- repo: row.repo,
291
- issueNumber: row.issue_number,
292
- currentPhase: row.current_phase,
293
- phaseHistory: JSON.parse(row.phase_history),
294
- status: row.status,
295
- context: row.context ? JSON.parse(row.context) : undefined,
296
- scratch: row.scratch ? JSON.parse(row.scratch) : undefined,
297
- restartCount: typeof row.restart_count === "number" ? row.restart_count : 0,
298
- startedAt: row.started_at,
299
- updatedAt: row.updated_at,
300
- finishedAt: row.finished_at,
301
- };
302
- }
303
- // ── Named atomic lifecycle operations ──────────────────────────
304
- //
305
- // Each wraps ONE better-sqlite3 transaction. The long-running re-dispatch
306
- // (`dispatchWorkflow`) stays OUT of these — the caller dispatches after the
307
- // transaction commits.
308
- /**
309
- * Resolve a socratic reply gate and resume the run, atomically: the reply
310
- * gate flips `pending → approved` (recording the reply text), the caller's
311
- * scratch patch merges in, and the run goes back to `running` — all in one
312
- * transaction. A throw anywhere rolls the whole thing back, so the run can
313
- * never be left `running` with its gate unresolved or its reply lost (the
314
- * hazard issue #97 calls out).
315
- *
316
- * The reply-gate resolve is guarded by `kind = 'reply' AND status = 'pending'`
317
- * (see {@link ApprovalStore.resolveReplyGate}); if it changes zero rows —
318
- * because a racing reply already resolved the gate — this throws and the
319
- * transaction aborts, which is the double-reply concurrency guard.
320
- *
321
- * The caller (`index.ts`) computes the explore-domain `scratch.socratic.qa`
322
- * patch and passes it in; the generic store stays ignorant of that shape.
323
- */
324
- /**
325
- * Pause a run for an approval gate, atomically: create the pending approval,
326
- * optionally merge a scratch patch (loops persist their iteration state
327
- * here), append the `waiting_approval` phase marker, and flip the run to
328
- * `paused` — all in one transaction. Covers the standard post-phase gate,
329
- * the reviewer-loop gate, and the interactive generic-loop gate.
330
- *
331
- * The marker is appended BEFORE the approval insert so that an insert
332
- * failure provably rolls back the phase-history write (the injected
333
- * ApprovalStore participates in the same transaction); ordering is invisible
334
- * outside the transaction.
335
- */
336
- pauseForApproval(runId, approval, marker, scratchPatch) {
337
- this.db.transaction(() => {
338
- this.appendPhase(runId, marker.phase, {
339
- phase: marker.phase,
340
- timestamp: new Date().toISOString(),
341
- success: true,
342
- summary: marker.summary,
343
- });
344
- if (scratchPatch)
345
- this.mergeScratch(runId, scratchPatch);
346
- this.approvals.create(approval);
347
- this.setPaused(runId);
348
- })();
349
- }
350
- /**
351
- * Approve a gate and resume its run, atomically. Reads the approval to find
352
- * its run, records the `approved` response, and flips the run back to
353
- * `running` in one transaction; returns the run so the caller can dispatch.
354
- * Used by the GitHub/Slack path (`index.ts`), which validates the dispatch
355
- * target BEFORE calling this so the flip to `running` is always followed by a
356
- * dispatch. The dashboard path does NOT use this — it can't prove a dispatch
357
- * will follow before responding, so it records the approval and lets
358
- * `resumeWorkflow` flip the run only as part of an actual dispatch.
359
- */
360
- resolveGateAndResume(approvalId, responder) {
361
- return this.db.transaction(() => {
362
- const approval = this.approvals.getById(approvalId);
363
- if (!approval)
364
- throw new Error(`approval ${approvalId} not found`);
365
- const changed = this.approvals.respond(approvalId, "approved", responder);
366
- if (changed !== 1) {
367
- throw new Error(`approval ${approvalId} is not pending (already resolved?)`);
368
- }
369
- this.setRunning(approval.workflowRunId);
370
- return this.getRun(approval.workflowRunId);
371
- })();
372
- }
373
- /**
374
- * Reject a gate and fail its run, atomically: record the `rejected` response
375
- * (with reason) and flip the run to `failed` in one transaction. Returns the
376
- * run (or null if the approval's run was already gone).
377
- */
378
- resolveGateAndFail(approvalId, responder, reason) {
379
- return this.db.transaction(() => {
380
- const approval = this.approvals.getById(approvalId);
381
- if (!approval)
382
- throw new Error(`approval ${approvalId} not found`);
383
- const changed = this.approvals.respond(approvalId, "rejected", responder, reason);
384
- if (changed !== 1) {
385
- throw new Error(`approval ${approvalId} is not pending (already resolved?)`);
386
- }
387
- this.flipFinished(approval.workflowRunId, "failed", `Rejected: ${reason || "no reason given"}`);
388
- return this.getRun(approval.workflowRunId);
389
- })();
390
- }
391
- resolveReplyGateAndResume(runId, approvalId, replyText, responder, scratchPatch) {
392
- return this.db.transaction(() => {
393
- const changed = this.approvals.resolveReplyGate(approvalId, replyText, responder);
394
- if (changed !== 1) {
395
- throw new Error(`reply gate ${approvalId} is not pending (already resolved?)`);
396
- }
397
- this.mergeScratch(runId, scratchPatch);
398
- this.setRunning(runId);
399
- return this.getRun(runId);
400
- })();
401
- }
402
- }
403
- //# sourceMappingURL=workflow-run-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workflow-run-store.js","sourceRoot":"","sources":["../../src/state/workflow-run-store.ts"],"names":[],"mappings":"AA6CA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,gBAAgB;IACnB,EAAE,CAAoB;IACtB,SAAS,CAAgB;IAEjC,YAAY,EAAqB,EAAE,IAAkC;QACnE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IAClC,CAAC;IAED,kEAAkE;IAElE,uCAAuC;IACvC,SAAS,CAAC,GAAoD;QAC5D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC;;;KAGf,CAAC,CAAC,GAAG,CACJ,GAAG,CAAC,EAAE,EACN,GAAG,CAAC,YAAY,EAChB,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,IAAI,IAAI,IAAI,EAChB,GAAG,CAAC,WAAW,IAAI,IAAI,EACvB,GAAG,CAAC,YAAY,EAChB,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAChD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAChD,GAAG,CAAC,SAAS,EACb,GAAG,CACJ,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAU,EAAE,KAA8B;QACrD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE;aAChB,OAAO,CAAC,gDAAgD,CAAC;aACzD,GAAG,C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,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,qCAAqC,CAAC,CAAC;YACjF,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YACvC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF"}
@@ -1,38 +0,0 @@
1
- import { type Span } from "@opentelemetry/api";
2
- import type { OtelConfig } from "../config/config.js";
3
- export type TelemetryPrimitive = string | number | boolean;
4
- export type TelemetryAttributes = Record<string, unknown>;
5
- export declare const OTEL_SANDBOX_ENV_ALLOWLIST: readonly ["OTEL_SERVICE_NAME", "OTEL_RESOURCE_ATTRIBUTES", "OTEL_TRACES_EXPORTER", "OTEL_METRICS_EXPORTER", "OTEL_LOGS_EXPORTER", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "OTEL_EXPORTER_OTLP_PROTOCOL", "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL", "OTEL_EXPORTER_OTLP_HEADERS", "OTEL_EXPORTER_OTLP_TRACES_HEADERS", "OTEL_EXPORTER_OTLP_METRICS_HEADERS", "OTEL_EXPORTER_OTLP_LOGS_HEADERS", "OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT", "OTEL_ATTRIBUTE_COUNT_LIMIT", "OTEL_BSP_MAX_QUEUE_SIZE", "OTEL_BSP_SCHEDULE_DELAY", "OTEL_METRIC_EXPORT_INTERVAL"];
6
- export declare function isTelemetryEnabled(): boolean;
7
- export declare function telemetryIncludesContent(): boolean;
8
- export declare function safeSpanAttributes(attrs?: TelemetryAttributes): Record<string, TelemetryPrimitive>;
9
- export declare function safeMetricAttributes(attrs?: TelemetryAttributes): Record<string, TelemetryPrimitive>;
10
- export declare function initTelemetry(config: OtelConfig, opts?: {
11
- packageVersion?: string;
12
- }): Promise<void>;
13
- export declare function shutdownTelemetry(): Promise<void>;
14
- export declare function withSpan<T>(name: string, attrs: TelemetryAttributes, fn: (span: Span | undefined) => Promise<T> | T): Promise<T>;
15
- export declare function recordExecutionMetrics(surface: "workflow" | "phase" | "agent" | "chat", attrs?: TelemetryAttributes): void;
16
- export declare function recordWorkflowRunStart(attrs?: TelemetryAttributes): void;
17
- export declare function recordWorkflowRunEnd(attrs?: TelemetryAttributes): void;
18
- export declare function recordError(surface: string, error: unknown, attrs?: TelemetryAttributes): void;
19
- /**
20
- * OTEL env for the **docker** backend, where pi-coding-agent runs *inside*
21
- * the container. The sandbox is pointed at the in-network collector by its
22
- * static IP — it never learns the real backend endpoint or its auth
23
- * headers (those stay host-side on the collector). Reached directly by IP
24
- * on `sandbox-egress`, so it traverses neither the SNI firewall nor DNS,
25
- * and works identically in strict and unrestricted-egress phases.
26
- */
27
- export declare function getDockerSandboxOtelEnv(env?: NodeJS.ProcessEnv): Record<string, string>;
28
- /**
29
- * OTEL env for the **in-process** backends (gondolin / none), where
30
- * pi-coding-agent runs in the harness process rather than a container —
31
- * its own telemetry already inherits the harness SDK. This forwards the
32
- * host's OTEL_* config into the sandbox shell env for child processes the
33
- * agent spawns. There is no in-network collector reachable from a gondolin
34
- * VM, so the real endpoint/headers are forwarded directly; unsafe values
35
- * (newline / single-quote, which would break downstream shell quoting) are
36
- * dropped with a warning rather than forwarded.
37
- */
38
- export declare function getOtelEnvForSandbox(env?: NodeJS.ProcessEnv): Record<string, string>;