@evermore.work/server 2026.509.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1045) hide show
  1. package/dist/adapters/builtin-adapter-types.d.ts +5 -0
  2. package/dist/adapters/builtin-adapter-types.d.ts.map +1 -0
  3. package/dist/adapters/builtin-adapter-types.js +17 -0
  4. package/dist/adapters/builtin-adapter-types.js.map +1 -0
  5. package/dist/adapters/codex-models.d.ts +5 -0
  6. package/dist/adapters/codex-models.d.ts.map +1 -0
  7. package/dist/adapters/codex-models.js +105 -0
  8. package/dist/adapters/codex-models.js.map +1 -0
  9. package/dist/adapters/cursor-models.d.ts +13 -0
  10. package/dist/adapters/cursor-models.d.ts.map +1 -0
  11. package/dist/adapters/cursor-models.js +148 -0
  12. package/dist/adapters/cursor-models.js.map +1 -0
  13. package/dist/adapters/http/execute.d.ts +3 -0
  14. package/dist/adapters/http/execute.d.ts.map +1 -0
  15. package/dist/adapters/http/execute.js +51 -0
  16. package/dist/adapters/http/execute.js.map +1 -0
  17. package/dist/adapters/http/execute.test.d.ts +2 -0
  18. package/dist/adapters/http/execute.test.d.ts.map +1 -0
  19. package/dist/adapters/http/execute.test.js +40 -0
  20. package/dist/adapters/http/execute.test.js.map +1 -0
  21. package/dist/adapters/http/index.d.ts +3 -0
  22. package/dist/adapters/http/index.d.ts.map +1 -0
  23. package/dist/adapters/http/index.js +20 -0
  24. package/dist/adapters/http/index.js.map +1 -0
  25. package/dist/adapters/http/test.d.ts +3 -0
  26. package/dist/adapters/http/test.d.ts.map +1 -0
  27. package/dist/adapters/http/test.js +106 -0
  28. package/dist/adapters/http/test.js.map +1 -0
  29. package/dist/adapters/index.d.ts +4 -0
  30. package/dist/adapters/index.d.ts.map +1 -0
  31. package/dist/adapters/index.js +3 -0
  32. package/dist/adapters/index.js.map +1 -0
  33. package/dist/adapters/plugin-loader.d.ts +28 -0
  34. package/dist/adapters/plugin-loader.d.ts.map +1 -0
  35. package/dist/adapters/plugin-loader.js +196 -0
  36. package/dist/adapters/plugin-loader.js.map +1 -0
  37. package/dist/adapters/process/execute.d.ts +3 -0
  38. package/dist/adapters/process/execute.d.ts.map +1 -0
  39. package/dist/adapters/process/execute.js +70 -0
  40. package/dist/adapters/process/execute.js.map +1 -0
  41. package/dist/adapters/process/index.d.ts +3 -0
  42. package/dist/adapters/process/index.d.ts.map +1 -0
  43. package/dist/adapters/process/index.js +23 -0
  44. package/dist/adapters/process/index.js.map +1 -0
  45. package/dist/adapters/process/test.d.ts +3 -0
  46. package/dist/adapters/process/test.d.ts.map +1 -0
  47. package/dist/adapters/process/test.js +77 -0
  48. package/dist/adapters/process/test.js.map +1 -0
  49. package/dist/adapters/registry.d.ts +69 -0
  50. package/dist/adapters/registry.d.ts.map +1 -0
  51. package/dist/adapters/registry.js +566 -0
  52. package/dist/adapters/registry.js.map +1 -0
  53. package/dist/adapters/types.d.ts +2 -0
  54. package/dist/adapters/types.d.ts.map +1 -0
  55. package/dist/adapters/types.js +2 -0
  56. package/dist/adapters/types.js.map +1 -0
  57. package/dist/adapters/utils.d.ts +43 -0
  58. package/dist/adapters/utils.d.ts.map +1 -0
  59. package/dist/adapters/utils.js +52 -0
  60. package/dist/adapters/utils.js.map +1 -0
  61. package/dist/agent-auth-jwt.d.ts +14 -0
  62. package/dist/agent-auth-jwt.d.ts.map +1 -0
  63. package/dist/agent-auth-jwt.js +117 -0
  64. package/dist/agent-auth-jwt.js.map +1 -0
  65. package/dist/app.d.ts +43 -0
  66. package/dist/app.d.ts.map +1 -0
  67. package/dist/app.js +373 -0
  68. package/dist/app.js.map +1 -0
  69. package/dist/attachment-types.d.ts +23 -0
  70. package/dist/attachment-types.d.ts.map +1 -0
  71. package/dist/attachment-types.js +91 -0
  72. package/dist/attachment-types.js.map +1 -0
  73. package/dist/auth/better-auth.d.ts +33 -0
  74. package/dist/auth/better-auth.d.ts.map +1 -0
  75. package/dist/auth/better-auth.js +133 -0
  76. package/dist/auth/better-auth.js.map +1 -0
  77. package/dist/board-claim.d.ts +23 -0
  78. package/dist/board-claim.d.ts.map +1 -0
  79. package/dist/board-claim.js +115 -0
  80. package/dist/board-claim.js.map +1 -0
  81. package/dist/config-file.d.ts +3 -0
  82. package/dist/config-file.d.ts.map +1 -0
  83. package/dist/config-file.js +16 -0
  84. package/dist/config-file.js.map +1 -0
  85. package/dist/config.d.ts +44 -0
  86. package/dist/config.d.ts.map +1 -0
  87. package/dist/config.js +226 -0
  88. package/dist/config.js.map +1 -0
  89. package/dist/dev-runner-worktree.d.ts +15 -0
  90. package/dist/dev-runner-worktree.d.ts.map +1 -0
  91. package/dist/dev-runner-worktree.js +68 -0
  92. package/dist/dev-runner-worktree.js.map +1 -0
  93. package/dist/dev-server-status.d.ts +27 -0
  94. package/dist/dev-server-status.d.ts.map +1 -0
  95. package/dist/dev-server-status.js +74 -0
  96. package/dist/dev-server-status.js.map +1 -0
  97. package/dist/dev-watch-ignore.d.ts +2 -0
  98. package/dist/dev-watch-ignore.d.ts.map +1 -0
  99. package/dist/dev-watch-ignore.js +36 -0
  100. package/dist/dev-watch-ignore.js.map +1 -0
  101. package/dist/errors.d.ts +12 -0
  102. package/dist/errors.d.ts.map +1 -0
  103. package/dist/errors.js +28 -0
  104. package/dist/errors.js.map +1 -0
  105. package/dist/home-paths.d.ts +17 -0
  106. package/dist/home-paths.d.ts.map +1 -0
  107. package/dist/home-paths.js +75 -0
  108. package/dist/home-paths.js.map +1 -0
  109. package/dist/index.d.ts +10 -0
  110. package/dist/index.d.ts.map +1 -0
  111. package/dist/index.js +753 -0
  112. package/dist/index.js.map +1 -0
  113. package/dist/lib/join-request-dedupe.d.ts +11 -0
  114. package/dist/lib/join-request-dedupe.d.ts.map +1 -0
  115. package/dist/lib/join-request-dedupe.js +49 -0
  116. package/dist/lib/join-request-dedupe.js.map +1 -0
  117. package/dist/log-redaction.d.ts +11 -0
  118. package/dist/log-redaction.d.ts.map +1 -0
  119. package/dist/log-redaction.js +122 -0
  120. package/dist/log-redaction.js.map +1 -0
  121. package/dist/middleware/auth.d.ts +12 -0
  122. package/dist/middleware/auth.d.ts.map +1 -0
  123. package/dist/middleware/auth.js +302 -0
  124. package/dist/middleware/auth.js.map +1 -0
  125. package/dist/middleware/board-mutation-guard.d.ts +3 -0
  126. package/dist/middleware/board-mutation-guard.d.ts.map +1 -0
  127. package/dist/middleware/board-mutation-guard.js +67 -0
  128. package/dist/middleware/board-mutation-guard.js.map +1 -0
  129. package/dist/middleware/error-handler.d.ts +17 -0
  130. package/dist/middleware/error-handler.d.ts.map +1 -0
  131. package/dist/middleware/error-handler.js +45 -0
  132. package/dist/middleware/error-handler.js.map +1 -0
  133. package/dist/middleware/http-log-policy.d.ts +2 -0
  134. package/dist/middleware/http-log-policy.d.ts.map +1 -0
  135. package/dist/middleware/http-log-policy.js +52 -0
  136. package/dist/middleware/http-log-policy.js.map +1 -0
  137. package/dist/middleware/index.d.ts +4 -0
  138. package/dist/middleware/index.d.ts.map +1 -0
  139. package/dist/middleware/index.js +4 -0
  140. package/dist/middleware/index.js.map +1 -0
  141. package/dist/middleware/logger.d.ts +4 -0
  142. package/dist/middleware/logger.d.ts.map +1 -0
  143. package/dist/middleware/logger.js +92 -0
  144. package/dist/middleware/logger.js.map +1 -0
  145. package/dist/middleware/private-hostname-guard.d.ts +11 -0
  146. package/dist/middleware/private-hostname-guard.d.ts.map +1 -0
  147. package/dist/middleware/private-hostname-guard.js +78 -0
  148. package/dist/middleware/private-hostname-guard.js.map +1 -0
  149. package/dist/middleware/validate.d.ts +4 -0
  150. package/dist/middleware/validate.d.ts.map +1 -0
  151. package/dist/middleware/validate.js +7 -0
  152. package/dist/middleware/validate.js.map +1 -0
  153. package/dist/onboarding-assets/ceo/AGENTS.md +59 -0
  154. package/dist/onboarding-assets/ceo/HEARTBEAT.md +85 -0
  155. package/dist/onboarding-assets/ceo/SOUL.md +33 -0
  156. package/dist/onboarding-assets/ceo/TOOLS.md +3 -0
  157. package/dist/onboarding-assets/default/AGENTS.md +17 -0
  158. package/dist/paths.d.ts +3 -0
  159. package/dist/paths.d.ts.map +1 -0
  160. package/dist/paths.js +31 -0
  161. package/dist/paths.js.map +1 -0
  162. package/dist/realtime/live-events-ws.d.ts +28 -0
  163. package/dist/realtime/live-events-ws.d.ts.map +1 -0
  164. package/dist/realtime/live-events-ws.js +187 -0
  165. package/dist/realtime/live-events-ws.js.map +1 -0
  166. package/dist/redaction.d.ts +5 -0
  167. package/dist/redaction.d.ts.map +1 -0
  168. package/dist/redaction.js +98 -0
  169. package/dist/redaction.js.map +1 -0
  170. package/dist/routes/access.d.ts +82 -0
  171. package/dist/routes/access.d.ts.map +1 -0
  172. package/dist/routes/access.js +3411 -0
  173. package/dist/routes/access.js.map +1 -0
  174. package/dist/routes/activity.d.ts +3 -0
  175. package/dist/routes/activity.d.ts.map +1 -0
  176. package/dist/routes/activity.js +90 -0
  177. package/dist/routes/activity.js.map +1 -0
  178. package/dist/routes/adapters.d.ts +16 -0
  179. package/dist/routes/adapters.d.ts.map +1 -0
  180. package/dist/routes/adapters.js +527 -0
  181. package/dist/routes/adapters.js.map +1 -0
  182. package/dist/routes/agents.d.ts +6 -0
  183. package/dist/routes/agents.d.ts.map +1 -0
  184. package/dist/routes/agents.js +2753 -0
  185. package/dist/routes/agents.js.map +1 -0
  186. package/dist/routes/approvals.d.ts +6 -0
  187. package/dist/routes/approvals.d.ts.map +1 -0
  188. package/dist/routes/approvals.js +300 -0
  189. package/dist/routes/approvals.js.map +1 -0
  190. package/dist/routes/assets.d.ts +4 -0
  191. package/dist/routes/assets.d.ts.map +1 -0
  192. package/dist/routes/assets.js +309 -0
  193. package/dist/routes/assets.js.map +1 -0
  194. package/dist/routes/auth.d.ts +3 -0
  195. package/dist/routes/auth.d.ts.map +1 -0
  196. package/dist/routes/auth.js +82 -0
  197. package/dist/routes/auth.js.map +1 -0
  198. package/dist/routes/authz.d.ts +19 -0
  199. package/dist/routes/authz.d.ts.map +1 -0
  200. package/dist/routes/authz.js +75 -0
  201. package/dist/routes/authz.js.map +1 -0
  202. package/dist/routes/companies.d.ts +4 -0
  203. package/dist/routes/companies.d.ts.map +1 -0
  204. package/dist/routes/companies.js +359 -0
  205. package/dist/routes/companies.js.map +1 -0
  206. package/dist/routes/company-skills.d.ts +3 -0
  207. package/dist/routes/company-skills.d.ts.map +1 -0
  208. package/dist/routes/company-skills.js +258 -0
  209. package/dist/routes/company-skills.js.map +1 -0
  210. package/dist/routes/costs.d.ts +11 -0
  211. package/dist/routes/costs.d.ts.map +1 -0
  212. package/dist/routes/costs.js +285 -0
  213. package/dist/routes/costs.js.map +1 -0
  214. package/dist/routes/dashboard.d.ts +3 -0
  215. package/dist/routes/dashboard.d.ts.map +1 -0
  216. package/dist/routes/dashboard.js +15 -0
  217. package/dist/routes/dashboard.js.map +1 -0
  218. package/dist/routes/environment-selection.d.ts +13 -0
  219. package/dist/routes/environment-selection.d.ts.map +1 -0
  220. package/dist/routes/environment-selection.js +30 -0
  221. package/dist/routes/environment-selection.js.map +1 -0
  222. package/dist/routes/environments.d.ts +6 -0
  223. package/dist/routes/environments.d.ts.map +1 -0
  224. package/dist/routes/environments.js +401 -0
  225. package/dist/routes/environments.js.map +1 -0
  226. package/dist/routes/execution-workspaces.d.ts +3 -0
  227. package/dist/routes/execution-workspaces.d.ts.map +1 -0
  228. package/dist/routes/execution-workspaces.js +536 -0
  229. package/dist/routes/execution-workspaces.js.map +1 -0
  230. package/dist/routes/goals.d.ts +3 -0
  231. package/dist/routes/goals.d.ts.map +1 -0
  232. package/dist/routes/goals.js +101 -0
  233. package/dist/routes/goals.js.map +1 -0
  234. package/dist/routes/health.d.ts +9 -0
  235. package/dist/routes/health.d.ts.map +1 -0
  236. package/dist/routes/health.js +114 -0
  237. package/dist/routes/health.js.map +1 -0
  238. package/dist/routes/inbox-dismissals.d.ts +3 -0
  239. package/dist/routes/inbox-dismissals.d.ts.map +1 -0
  240. package/dist/routes/inbox-dismissals.js +58 -0
  241. package/dist/routes/inbox-dismissals.js.map +1 -0
  242. package/dist/routes/index.d.ts +22 -0
  243. package/dist/routes/index.d.ts.map +1 -0
  244. package/dist/routes/index.js +22 -0
  245. package/dist/routes/index.js.map +1 -0
  246. package/dist/routes/instance-database-backups.d.ts +15 -0
  247. package/dist/routes/instance-database-backups.d.ts.map +1 -0
  248. package/dist/routes/instance-database-backups.js +12 -0
  249. package/dist/routes/instance-database-backups.js.map +1 -0
  250. package/dist/routes/instance-settings.d.ts +3 -0
  251. package/dist/routes/instance-settings.d.ts.map +1 -0
  252. package/dist/routes/instance-settings.js +110 -0
  253. package/dist/routes/instance-settings.js.map +1 -0
  254. package/dist/routes/issue-tree-control.d.ts +3 -0
  255. package/dist/routes/issue-tree-control.d.ts.map +1 -0
  256. package/dist/routes/issue-tree-control.js +363 -0
  257. package/dist/routes/issue-tree-control.js.map +1 -0
  258. package/dist/routes/issues-checkout-wakeup.d.ts +9 -0
  259. package/dist/routes/issues-checkout-wakeup.d.ts.map +1 -0
  260. package/dist/routes/issues-checkout-wakeup.js +12 -0
  261. package/dist/routes/issues-checkout-wakeup.js.map +1 -0
  262. package/dist/routes/issues.d.ts +23 -0
  263. package/dist/routes/issues.d.ts.map +1 -0
  264. package/dist/routes/issues.js +3886 -0
  265. package/dist/routes/issues.js.map +1 -0
  266. package/dist/routes/llms.d.ts +3 -0
  267. package/dist/routes/llms.d.ts.map +1 -0
  268. package/dist/routes/llms.js +80 -0
  269. package/dist/routes/llms.js.map +1 -0
  270. package/dist/routes/org-chart-svg.d.ts +25 -0
  271. package/dist/routes/org-chart-svg.d.ts.map +1 -0
  272. package/dist/routes/org-chart-svg.js +656 -0
  273. package/dist/routes/org-chart-svg.js.map +1 -0
  274. package/dist/routes/plugin-ui-static.d.ts +69 -0
  275. package/dist/routes/plugin-ui-static.d.ts.map +1 -0
  276. package/dist/routes/plugin-ui-static.js +411 -0
  277. package/dist/routes/plugin-ui-static.js.map +1 -0
  278. package/dist/routes/plugins.d.ts +121 -0
  279. package/dist/routes/plugins.d.ts.map +1 -0
  280. package/dist/routes/plugins.js +2192 -0
  281. package/dist/routes/plugins.js.map +1 -0
  282. package/dist/routes/projects.d.ts +3 -0
  283. package/dist/routes/projects.d.ts.map +1 -0
  284. package/dist/routes/projects.js +566 -0
  285. package/dist/routes/projects.js.map +1 -0
  286. package/dist/routes/routines.d.ts +6 -0
  287. package/dist/routes/routines.d.ts.map +1 -0
  288. package/dist/routes/routines.js +417 -0
  289. package/dist/routes/routines.js.map +1 -0
  290. package/dist/routes/secrets.d.ts +3 -0
  291. package/dist/routes/secrets.d.ts.map +1 -0
  292. package/dist/routes/secrets.js +128 -0
  293. package/dist/routes/secrets.js.map +1 -0
  294. package/dist/routes/sidebar-badges.d.ts +3 -0
  295. package/dist/routes/sidebar-badges.d.ts.map +1 -0
  296. package/dist/routes/sidebar-badges.js +68 -0
  297. package/dist/routes/sidebar-badges.js.map +1 -0
  298. package/dist/routes/sidebar-preferences.d.ts +3 -0
  299. package/dist/routes/sidebar-preferences.d.ts.map +1 -0
  300. package/dist/routes/sidebar-preferences.js +63 -0
  301. package/dist/routes/sidebar-preferences.js.map +1 -0
  302. package/dist/routes/user-profiles.d.ts +3 -0
  303. package/dist/routes/user-profiles.d.ts.map +1 -0
  304. package/dist/routes/user-profiles.js +337 -0
  305. package/dist/routes/user-profiles.js.map +1 -0
  306. package/dist/routes/workspace-command-authz.d.ts +14 -0
  307. package/dist/routes/workspace-command-authz.d.ts.map +1 -0
  308. package/dist/routes/workspace-command-authz.js +83 -0
  309. package/dist/routes/workspace-command-authz.js.map +1 -0
  310. package/dist/routes/workspace-runtime-service-authz.d.ts +12 -0
  311. package/dist/routes/workspace-runtime-service-authz.d.ts.map +1 -0
  312. package/dist/routes/workspace-runtime-service-authz.js +96 -0
  313. package/dist/routes/workspace-runtime-service-authz.js.map +1 -0
  314. package/dist/runtime-api.d.ts +19 -0
  315. package/dist/runtime-api.d.ts.map +1 -0
  316. package/dist/runtime-api.js +137 -0
  317. package/dist/runtime-api.js.map +1 -0
  318. package/dist/secrets/external-stub-providers.d.ts +5 -0
  319. package/dist/secrets/external-stub-providers.d.ts.map +1 -0
  320. package/dist/secrets/external-stub-providers.js +21 -0
  321. package/dist/secrets/external-stub-providers.js.map +1 -0
  322. package/dist/secrets/local-encrypted-provider.d.ts +3 -0
  323. package/dist/secrets/local-encrypted-provider.d.ts.map +1 -0
  324. package/dist/secrets/local-encrypted-provider.js +116 -0
  325. package/dist/secrets/local-encrypted-provider.js.map +1 -0
  326. package/dist/secrets/provider-registry.d.ts +5 -0
  327. package/dist/secrets/provider-registry.d.ts.map +1 -0
  328. package/dist/secrets/provider-registry.js +20 -0
  329. package/dist/secrets/provider-registry.js.map +1 -0
  330. package/dist/secrets/types.d.ts +21 -0
  331. package/dist/secrets/types.d.ts.map +1 -0
  332. package/dist/secrets/types.js +2 -0
  333. package/dist/secrets/types.js.map +1 -0
  334. package/dist/services/access.d.ts +171 -0
  335. package/dist/services/access.d.ts.map +1 -0
  336. package/dist/services/access.js +522 -0
  337. package/dist/services/access.js.map +1 -0
  338. package/dist/services/activity-log.d.ts +19 -0
  339. package/dist/services/activity-log.d.ts.map +1 -0
  340. package/dist/services/activity-log.js +99 -0
  341. package/dist/services/activity-log.js.map +1 -0
  342. package/dist/services/activity.d.ts +462 -0
  343. package/dist/services/activity.d.ts.map +1 -0
  344. package/dist/services/activity.js +443 -0
  345. package/dist/services/activity.js.map +1 -0
  346. package/dist/services/adapter-plugin-store.d.ts +36 -0
  347. package/dist/services/adapter-plugin-store.d.ts.map +1 -0
  348. package/dist/services/adapter-plugin-store.js +154 -0
  349. package/dist/services/adapter-plugin-store.js.map +1 -0
  350. package/dist/services/agent-instructions.d.ts +91 -0
  351. package/dist/services/agent-instructions.d.ts.map +1 -0
  352. package/dist/services/agent-instructions.js +580 -0
  353. package/dist/services/agent-instructions.js.map +1 -0
  354. package/dist/services/agent-permissions.d.ts +6 -0
  355. package/dist/services/agent-permissions.d.ts.map +1 -0
  356. package/dist/services/agent-permissions.js +18 -0
  357. package/dist/services/agent-permissions.js.map +1 -0
  358. package/dist/services/agent-start-lock.d.ts +2 -0
  359. package/dist/services/agent-start-lock.d.ts.map +1 -0
  360. package/dist/services/agent-start-lock.js +43 -0
  361. package/dist/services/agent-start-lock.js.map +1 -0
  362. package/dist/services/agents.d.ts +2253 -0
  363. package/dist/services/agents.d.ts.map +1 -0
  364. package/dist/services/agents.js +609 -0
  365. package/dist/services/agents.js.map +1 -0
  366. package/dist/services/approvals.d.ts +546 -0
  367. package/dist/services/approvals.d.ts.map +1 -0
  368. package/dist/services/approvals.js +212 -0
  369. package/dist/services/approvals.js.map +1 -0
  370. package/dist/services/assets.d.ts +33 -0
  371. package/dist/services/assets.d.ts.map +1 -0
  372. package/dist/services/assets.js +17 -0
  373. package/dist/services/assets.js.map +1 -0
  374. package/dist/services/board-auth.d.ts +239 -0
  375. package/dist/services/board-auth.d.ts.map +1 -0
  376. package/dist/services/board-auth.js +300 -0
  377. package/dist/services/board-auth.js.map +1 -0
  378. package/dist/services/budgets.d.ts +38 -0
  379. package/dist/services/budgets.d.ts.map +1 -0
  380. package/dist/services/budgets.js +784 -0
  381. package/dist/services/budgets.js.map +1 -0
  382. package/dist/services/companies.d.ts +154 -0
  383. package/dist/services/companies.d.ts.map +1 -0
  384. package/dist/services/companies.js +267 -0
  385. package/dist/services/companies.js.map +1 -0
  386. package/dist/services/company-export-readme.d.ts +17 -0
  387. package/dist/services/company-export-readme.d.ts.map +1 -0
  388. package/dist/services/company-export-readme.js +148 -0
  389. package/dist/services/company-export-readme.js.map +1 -0
  390. package/dist/services/company-member-roles.d.ts +9 -0
  391. package/dist/services/company-member-roles.d.ts.map +1 -0
  392. package/dist/services/company-member-roles.js +46 -0
  393. package/dist/services/company-member-roles.js.map +1 -0
  394. package/dist/services/company-portability.d.ts +24 -0
  395. package/dist/services/company-portability.d.ts.map +1 -0
  396. package/dist/services/company-portability.js +4076 -0
  397. package/dist/services/company-portability.js.map +1 -0
  398. package/dist/services/company-search-rate-limit.d.ts +22 -0
  399. package/dist/services/company-search-rate-limit.d.ts.map +1 -0
  400. package/dist/services/company-search-rate-limit.js +38 -0
  401. package/dist/services/company-search-rate-limit.js.map +1 -0
  402. package/dist/services/company-search.d.ts +8 -0
  403. package/dist/services/company-search.d.ts.map +1 -0
  404. package/dist/services/company-search.js +626 -0
  405. package/dist/services/company-search.js.map +1 -0
  406. package/dist/services/company-skills.d.ts +77 -0
  407. package/dist/services/company-skills.d.ts.map +1 -0
  408. package/dist/services/company-skills.js +2120 -0
  409. package/dist/services/company-skills.js.map +1 -0
  410. package/dist/services/costs.d.ts +127 -0
  411. package/dist/services/costs.d.ts.map +1 -0
  412. package/dist/services/costs.js +409 -0
  413. package/dist/services/costs.js.map +1 -0
  414. package/dist/services/cron.d.ts +80 -0
  415. package/dist/services/cron.d.ts.map +1 -0
  416. package/dist/services/cron.js +300 -0
  417. package/dist/services/cron.js.map +1 -0
  418. package/dist/services/dashboard.d.ts +34 -0
  419. package/dist/services/dashboard.d.ts.map +1 -0
  420. package/dist/services/dashboard.js +142 -0
  421. package/dist/services/dashboard.js.map +1 -0
  422. package/dist/services/default-agent-instructions.d.ts +9 -0
  423. package/dist/services/default-agent-instructions.d.ts.map +1 -0
  424. package/dist/services/default-agent-instructions.js +20 -0
  425. package/dist/services/default-agent-instructions.js.map +1 -0
  426. package/dist/services/documents.d.ts +199 -0
  427. package/dist/services/documents.d.ts.map +1 -0
  428. package/dist/services/documents.js +411 -0
  429. package/dist/services/documents.js.map +1 -0
  430. package/dist/services/environment-config.d.ts +43 -0
  431. package/dist/services/environment-config.d.ts.map +1 -0
  432. package/dist/services/environment-config.js +388 -0
  433. package/dist/services/environment-config.js.map +1 -0
  434. package/dist/services/environment-execution-target.d.ts +21 -0
  435. package/dist/services/environment-execution-target.d.ts.map +1 -0
  436. package/dist/services/environment-execution-target.js +119 -0
  437. package/dist/services/environment-execution-target.js.map +1 -0
  438. package/dist/services/environment-probe.d.ts +9 -0
  439. package/dist/services/environment-probe.d.ts.map +1 -0
  440. package/dist/services/environment-probe.js +106 -0
  441. package/dist/services/environment-probe.js.map +1 -0
  442. package/dist/services/environment-run-orchestrator.d.ts +124 -0
  443. package/dist/services/environment-run-orchestrator.d.ts.map +1 -0
  444. package/dist/services/environment-run-orchestrator.js +392 -0
  445. package/dist/services/environment-run-orchestrator.js.map +1 -0
  446. package/dist/services/environment-runtime.d.ts +90 -0
  447. package/dist/services/environment-runtime.d.ts.map +1 -0
  448. package/dist/services/environment-runtime.js +934 -0
  449. package/dist/services/environment-runtime.js.map +1 -0
  450. package/dist/services/environments.d.ts +36 -0
  451. package/dist/services/environments.d.ts.map +1 -0
  452. package/dist/services/environments.js +260 -0
  453. package/dist/services/environments.js.map +1 -0
  454. package/dist/services/execution-workspace-policy.d.ts +30 -0
  455. package/dist/services/execution-workspace-policy.d.ts.map +1 -0
  456. package/dist/services/execution-workspace-policy.js +195 -0
  457. package/dist/services/execution-workspace-policy.js.map +1 -0
  458. package/dist/services/execution-workspaces.d.ts +30 -0
  459. package/dist/services/execution-workspaces.d.ts.map +1 -0
  460. package/dist/services/execution-workspaces.js +635 -0
  461. package/dist/services/execution-workspaces.js.map +1 -0
  462. package/dist/services/feedback-redaction.d.ts +23 -0
  463. package/dist/services/feedback-redaction.d.ts.map +1 -0
  464. package/dist/services/feedback-redaction.js +150 -0
  465. package/dist/services/feedback-redaction.js.map +1 -0
  466. package/dist/services/feedback-share-client.d.ts +9 -0
  467. package/dist/services/feedback-share-client.d.ts.map +1 -0
  468. package/dist/services/feedback-share-client.js +46 -0
  469. package/dist/services/feedback-share-client.js.map +1 -0
  470. package/dist/services/feedback.d.ts +93 -0
  471. package/dist/services/feedback.d.ts.map +1 -0
  472. package/dist/services/feedback.js +1717 -0
  473. package/dist/services/feedback.js.map +1 -0
  474. package/dist/services/finance.d.ts +93 -0
  475. package/dist/services/finance.d.ts.map +1 -0
  476. package/dist/services/finance.js +120 -0
  477. package/dist/services/finance.js.map +1 -0
  478. package/dist/services/github-fetch.d.ts +4 -0
  479. package/dist/services/github-fetch.d.ts.map +1 -0
  480. package/dist/services/github-fetch.js +23 -0
  481. package/dist/services/github-fetch.js.map +1 -0
  482. package/dist/services/goals.d.ts +433 -0
  483. package/dist/services/goals.d.ts.map +1 -0
  484. package/dist/services/goals.js +54 -0
  485. package/dist/services/goals.js.map +1 -0
  486. package/dist/services/heartbeat-run-summary.d.ts +7 -0
  487. package/dist/services/heartbeat-run-summary.d.ts.map +1 -0
  488. package/dist/services/heartbeat-run-summary.js +84 -0
  489. package/dist/services/heartbeat-run-summary.js.map +1 -0
  490. package/dist/services/heartbeat-stop-metadata.d.ts +28 -0
  491. package/dist/services/heartbeat-stop-metadata.d.ts.map +1 -0
  492. package/dist/services/heartbeat-stop-metadata.js +86 -0
  493. package/dist/services/heartbeat-stop-metadata.js.map +1 -0
  494. package/dist/services/heartbeat-stop-metadata.test.d.ts +2 -0
  495. package/dist/services/heartbeat-stop-metadata.test.d.ts.map +1 -0
  496. package/dist/services/heartbeat-stop-metadata.test.js +93 -0
  497. package/dist/services/heartbeat-stop-metadata.test.js.map +1 -0
  498. package/dist/services/heartbeat.d.ts +1484 -0
  499. package/dist/services/heartbeat.d.ts.map +1 -0
  500. package/dist/services/heartbeat.js +7557 -0
  501. package/dist/services/heartbeat.js.map +1 -0
  502. package/dist/services/hire-hook.d.ts +14 -0
  503. package/dist/services/hire-hook.d.ts.map +1 -0
  504. package/dist/services/hire-hook.js +85 -0
  505. package/dist/services/hire-hook.js.map +1 -0
  506. package/dist/services/inbox-dismissals.d.ts +22 -0
  507. package/dist/services/inbox-dismissals.d.ts.map +1 -0
  508. package/dist/services/inbox-dismissals.js +33 -0
  509. package/dist/services/inbox-dismissals.js.map +1 -0
  510. package/dist/services/index.d.ts +44 -0
  511. package/dist/services/index.d.ts.map +1 -0
  512. package/dist/services/index.js +44 -0
  513. package/dist/services/index.js.map +1 -0
  514. package/dist/services/instance-settings.d.ts +11 -0
  515. package/dist/services/instance-settings.d.ts.map +1 -0
  516. package/dist/services/instance-settings.js +138 -0
  517. package/dist/services/instance-settings.js.map +1 -0
  518. package/dist/services/invite-grants.d.ts +15 -0
  519. package/dist/services/invite-grants.d.ts.map +1 -0
  520. package/dist/services/invite-grants.js +50 -0
  521. package/dist/services/invite-grants.js.map +1 -0
  522. package/dist/services/issue-approvals.d.ts +56 -0
  523. package/dist/services/issue-approvals.d.ts.map +1 -0
  524. package/dist/services/issue-approvals.js +153 -0
  525. package/dist/services/issue-approvals.js.map +1 -0
  526. package/dist/services/issue-assignment-wakeup.d.ts +29 -0
  527. package/dist/services/issue-assignment-wakeup.d.ts.map +1 -0
  528. package/dist/services/issue-assignment-wakeup.js +22 -0
  529. package/dist/services/issue-assignment-wakeup.js.map +1 -0
  530. package/dist/services/issue-continuation-summary.d.ts +66 -0
  531. package/dist/services/issue-continuation-summary.d.ts.map +1 -0
  532. package/dist/services/issue-continuation-summary.js +212 -0
  533. package/dist/services/issue-continuation-summary.js.map +1 -0
  534. package/dist/services/issue-execution-policy.d.ts +93 -0
  535. package/dist/services/issue-execution-policy.d.ts.map +1 -0
  536. package/dist/services/issue-execution-policy.js +838 -0
  537. package/dist/services/issue-execution-policy.js.map +1 -0
  538. package/dist/services/issue-goal-fallback.d.ts +18 -0
  539. package/dist/services/issue-goal-fallback.d.ts.map +1 -0
  540. package/dist/services/issue-goal-fallback.js +33 -0
  541. package/dist/services/issue-goal-fallback.js.map +1 -0
  542. package/dist/services/issue-liveness.d.ts +3 -0
  543. package/dist/services/issue-liveness.d.ts.map +1 -0
  544. package/dist/services/issue-liveness.js +2 -0
  545. package/dist/services/issue-liveness.js.map +1 -0
  546. package/dist/services/issue-references.d.ts +21 -0
  547. package/dist/services/issue-references.d.ts.map +1 -0
  548. package/dist/services/issue-references.js +318 -0
  549. package/dist/services/issue-references.js.map +1 -0
  550. package/dist/services/issue-thread-interactions.d.ts +76 -0
  551. package/dist/services/issue-thread-interactions.d.ts.map +1 -0
  552. package/dist/services/issue-thread-interactions.js +923 -0
  553. package/dist/services/issue-thread-interactions.js.map +1 -0
  554. package/dist/services/issue-thread-interactions.test.d.ts +2 -0
  555. package/dist/services/issue-thread-interactions.test.d.ts.map +1 -0
  556. package/dist/services/issue-thread-interactions.test.js +195 -0
  557. package/dist/services/issue-thread-interactions.test.js.map +1 -0
  558. package/dist/services/issue-tree-control.d.ts +89 -0
  559. package/dist/services/issue-tree-control.d.ts.map +1 -0
  560. package/dist/services/issue-tree-control.js +933 -0
  561. package/dist/services/issue-tree-control.js.map +1 -0
  562. package/dist/services/issues.d.ts +710 -0
  563. package/dist/services/issues.d.ts.map +1 -0
  564. package/dist/services/issues.js +3199 -0
  565. package/dist/services/issues.js.map +1 -0
  566. package/dist/services/json-schema-secret-refs.d.ts +5 -0
  567. package/dist/services/json-schema-secret-refs.d.ts.map +1 -0
  568. package/dist/services/json-schema-secret-refs.js +67 -0
  569. package/dist/services/json-schema-secret-refs.js.map +1 -0
  570. package/dist/services/live-events.d.ts +17 -0
  571. package/dist/services/live-events.d.ts.map +1 -0
  572. package/dist/services/live-events.js +33 -0
  573. package/dist/services/live-events.js.map +1 -0
  574. package/dist/services/local-service-supervisor.d.ts +56 -0
  575. package/dist/services/local-service-supervisor.d.ts.map +1 -0
  576. package/dist/services/local-service-supervisor.js +284 -0
  577. package/dist/services/local-service-supervisor.js.map +1 -0
  578. package/dist/services/plugin-capability-validator.d.ts +108 -0
  579. package/dist/services/plugin-capability-validator.d.ts.map +1 -0
  580. package/dist/services/plugin-capability-validator.js +313 -0
  581. package/dist/services/plugin-capability-validator.js.map +1 -0
  582. package/dist/services/plugin-config-validator.d.ts +26 -0
  583. package/dist/services/plugin-config-validator.d.ts.map +1 -0
  584. package/dist/services/plugin-config-validator.js +41 -0
  585. package/dist/services/plugin-config-validator.js.map +1 -0
  586. package/dist/services/plugin-database.d.ts +49 -0
  587. package/dist/services/plugin-database.d.ts.map +1 -0
  588. package/dist/services/plugin-database.js +440 -0
  589. package/dist/services/plugin-database.js.map +1 -0
  590. package/dist/services/plugin-dev-watcher.d.ts +30 -0
  591. package/dist/services/plugin-dev-watcher.d.ts.map +1 -0
  592. package/dist/services/plugin-dev-watcher.js +241 -0
  593. package/dist/services/plugin-dev-watcher.js.map +1 -0
  594. package/dist/services/plugin-environment-driver.d.ts +124 -0
  595. package/dist/services/plugin-environment-driver.d.ts.map +1 -0
  596. package/dist/services/plugin-environment-driver.js +224 -0
  597. package/dist/services/plugin-environment-driver.js.map +1 -0
  598. package/dist/services/plugin-event-bus.d.ts +149 -0
  599. package/dist/services/plugin-event-bus.d.ts.map +1 -0
  600. package/dist/services/plugin-event-bus.js +258 -0
  601. package/dist/services/plugin-event-bus.js.map +1 -0
  602. package/dist/services/plugin-host-service-cleanup.d.ts +14 -0
  603. package/dist/services/plugin-host-service-cleanup.d.ts.map +1 -0
  604. package/dist/services/plugin-host-service-cleanup.js +37 -0
  605. package/dist/services/plugin-host-service-cleanup.js.map +1 -0
  606. package/dist/services/plugin-host-services.d.ts +17 -0
  607. package/dist/services/plugin-host-services.d.ts.map +1 -0
  608. package/dist/services/plugin-host-services.js +1861 -0
  609. package/dist/services/plugin-host-services.js.map +1 -0
  610. package/dist/services/plugin-job-coordinator.d.ts +81 -0
  611. package/dist/services/plugin-job-coordinator.d.ts.map +1 -0
  612. package/dist/services/plugin-job-coordinator.js +172 -0
  613. package/dist/services/plugin-job-coordinator.js.map +1 -0
  614. package/dist/services/plugin-job-scheduler.d.ts +163 -0
  615. package/dist/services/plugin-job-scheduler.d.ts.map +1 -0
  616. package/dist/services/plugin-job-scheduler.js +454 -0
  617. package/dist/services/plugin-job-scheduler.js.map +1 -0
  618. package/dist/services/plugin-job-store.d.ts +208 -0
  619. package/dist/services/plugin-job-store.d.ts.map +1 -0
  620. package/dist/services/plugin-job-store.js +350 -0
  621. package/dist/services/plugin-job-store.js.map +1 -0
  622. package/dist/services/plugin-lifecycle.d.ts +203 -0
  623. package/dist/services/plugin-lifecycle.d.ts.map +1 -0
  624. package/dist/services/plugin-lifecycle.js +476 -0
  625. package/dist/services/plugin-lifecycle.js.map +1 -0
  626. package/dist/services/plugin-loader.d.ts +445 -0
  627. package/dist/services/plugin-loader.d.ts.map +1 -0
  628. package/dist/services/plugin-loader.js +1273 -0
  629. package/dist/services/plugin-loader.js.map +1 -0
  630. package/dist/services/plugin-local-folders.d.ts +48 -0
  631. package/dist/services/plugin-local-folders.d.ts.map +1 -0
  632. package/dist/services/plugin-local-folders.js +461 -0
  633. package/dist/services/plugin-local-folders.js.map +1 -0
  634. package/dist/services/plugin-log-retention.d.ts +20 -0
  635. package/dist/services/plugin-log-retention.d.ts.map +1 -0
  636. package/dist/services/plugin-log-retention.js +63 -0
  637. package/dist/services/plugin-log-retention.js.map +1 -0
  638. package/dist/services/plugin-managed-agents.d.ts +15 -0
  639. package/dist/services/plugin-managed-agents.d.ts.map +1 -0
  640. package/dist/services/plugin-managed-agents.js +414 -0
  641. package/dist/services/plugin-managed-agents.js.map +1 -0
  642. package/dist/services/plugin-managed-routines.d.ts +41 -0
  643. package/dist/services/plugin-managed-routines.d.ts.map +1 -0
  644. package/dist/services/plugin-managed-routines.js +416 -0
  645. package/dist/services/plugin-managed-routines.js.map +1 -0
  646. package/dist/services/plugin-manifest-validator.d.ts +79 -0
  647. package/dist/services/plugin-manifest-validator.d.ts.map +1 -0
  648. package/dist/services/plugin-manifest-validator.js +84 -0
  649. package/dist/services/plugin-manifest-validator.js.map +1 -0
  650. package/dist/services/plugin-registry.d.ts +2550 -0
  651. package/dist/services/plugin-registry.d.ts.map +1 -0
  652. package/dist/services/plugin-registry.js +581 -0
  653. package/dist/services/plugin-registry.js.map +1 -0
  654. package/dist/services/plugin-runtime-sandbox.d.ts +40 -0
  655. package/dist/services/plugin-runtime-sandbox.d.ts.map +1 -0
  656. package/dist/services/plugin-runtime-sandbox.js +154 -0
  657. package/dist/services/plugin-runtime-sandbox.js.map +1 -0
  658. package/dist/services/plugin-secrets-handler.d.ts +81 -0
  659. package/dist/services/plugin-secrets-handler.d.ts.map +1 -0
  660. package/dist/services/plugin-secrets-handler.js +231 -0
  661. package/dist/services/plugin-secrets-handler.js.map +1 -0
  662. package/dist/services/plugin-state-store.d.ts +92 -0
  663. package/dist/services/plugin-state-store.d.ts.map +1 -0
  664. package/dist/services/plugin-state-store.js +190 -0
  665. package/dist/services/plugin-state-store.js.map +1 -0
  666. package/dist/services/plugin-stream-bus.d.ts +29 -0
  667. package/dist/services/plugin-stream-bus.d.ts.map +1 -0
  668. package/dist/services/plugin-stream-bus.js +48 -0
  669. package/dist/services/plugin-stream-bus.js.map +1 -0
  670. package/dist/services/plugin-tool-dispatcher.d.ts +180 -0
  671. package/dist/services/plugin-tool-dispatcher.d.ts.map +1 -0
  672. package/dist/services/plugin-tool-dispatcher.js +224 -0
  673. package/dist/services/plugin-tool-dispatcher.js.map +1 -0
  674. package/dist/services/plugin-tool-registry.d.ts +192 -0
  675. package/dist/services/plugin-tool-registry.d.ts.map +1 -0
  676. package/dist/services/plugin-tool-registry.js +224 -0
  677. package/dist/services/plugin-tool-registry.js.map +1 -0
  678. package/dist/services/plugin-worker-manager.d.ts +262 -0
  679. package/dist/services/plugin-worker-manager.d.ts.map +1 -0
  680. package/dist/services/plugin-worker-manager.js +836 -0
  681. package/dist/services/plugin-worker-manager.js.map +1 -0
  682. package/dist/services/productivity-review.d.ts +83 -0
  683. package/dist/services/productivity-review.d.ts.map +1 -0
  684. package/dist/services/productivity-review.js +652 -0
  685. package/dist/services/productivity-review.js.map +1 -0
  686. package/dist/services/project-workspace-runtime-config.d.ts +4 -0
  687. package/dist/services/project-workspace-runtime-config.d.ts.map +1 -0
  688. package/dist/services/project-workspace-runtime-config.js +54 -0
  689. package/dist/services/project-workspace-runtime-config.js.map +1 -0
  690. package/dist/services/projects.d.ts +99 -0
  691. package/dist/services/projects.d.ts.map +1 -0
  692. package/dist/services/projects.js +879 -0
  693. package/dist/services/projects.js.map +1 -0
  694. package/dist/services/quota-windows.d.ts +9 -0
  695. package/dist/services/quota-windows.d.ts.map +1 -0
  696. package/dist/services/quota-windows.js +56 -0
  697. package/dist/services/quota-windows.js.map +1 -0
  698. package/dist/services/recovery/index.d.ts +10 -0
  699. package/dist/services/recovery/index.d.ts.map +1 -0
  700. package/dist/services/recovery/index.js +6 -0
  701. package/dist/services/recovery/index.js.map +1 -0
  702. package/dist/services/recovery/issue-graph-liveness.d.ts +85 -0
  703. package/dist/services/recovery/issue-graph-liveness.d.ts.map +1 -0
  704. package/dist/services/recovery/issue-graph-liveness.js +343 -0
  705. package/dist/services/recovery/issue-graph-liveness.js.map +1 -0
  706. package/dist/services/recovery/model-profile-hint.d.ts +8 -0
  707. package/dist/services/recovery/model-profile-hint.d.ts.map +1 -0
  708. package/dist/services/recovery/model-profile-hint.js +11 -0
  709. package/dist/services/recovery/model-profile-hint.js.map +1 -0
  710. package/dist/services/recovery/origins.d.ts +36 -0
  711. package/dist/services/recovery/origins.d.ts.map +1 -0
  712. package/dist/services/recovery/origins.js +45 -0
  713. package/dist/services/recovery/origins.js.map +1 -0
  714. package/dist/services/recovery/pause-hold-guard.d.ts +6 -0
  715. package/dist/services/recovery/pause-hold-guard.d.ts.map +1 -0
  716. package/dist/services/recovery/pause-hold-guard.js +6 -0
  717. package/dist/services/recovery/pause-hold-guard.js.map +1 -0
  718. package/dist/services/recovery/run-liveness-continuations.d.ts +50 -0
  719. package/dist/services/recovery/run-liveness-continuations.d.ts.map +1 -0
  720. package/dist/services/recovery/run-liveness-continuations.js +117 -0
  721. package/dist/services/recovery/run-liveness-continuations.js.map +1 -0
  722. package/dist/services/recovery/service.d.ts +195 -0
  723. package/dist/services/recovery/service.d.ts.map +1 -0
  724. package/dist/services/recovery/service.js +2210 -0
  725. package/dist/services/recovery/service.js.map +1 -0
  726. package/dist/services/recovery/successful-run-handoff.d.ts +87 -0
  727. package/dist/services/recovery/successful-run-handoff.d.ts.map +1 -0
  728. package/dist/services/recovery/successful-run-handoff.js +297 -0
  729. package/dist/services/recovery/successful-run-handoff.js.map +1 -0
  730. package/dist/services/recovery/successful-run-handoff.test.d.ts +2 -0
  731. package/dist/services/recovery/successful-run-handoff.test.d.ts.map +1 -0
  732. package/dist/services/recovery/successful-run-handoff.test.js +267 -0
  733. package/dist/services/recovery/successful-run-handoff.test.js.map +1 -0
  734. package/dist/services/routines.d.ts +166 -0
  735. package/dist/services/routines.d.ts.map +1 -0
  736. package/dist/services/routines.js +1937 -0
  737. package/dist/services/routines.js.map +1 -0
  738. package/dist/services/run-continuations.d.ts +3 -0
  739. package/dist/services/run-continuations.d.ts.map +1 -0
  740. package/dist/services/run-continuations.js +2 -0
  741. package/dist/services/run-continuations.js.map +1 -0
  742. package/dist/services/run-liveness.d.ts +46 -0
  743. package/dist/services/run-liveness.d.ts.map +1 -0
  744. package/dist/services/run-liveness.js +275 -0
  745. package/dist/services/run-liveness.js.map +1 -0
  746. package/dist/services/run-log-store.d.ts +34 -0
  747. package/dist/services/run-log-store.d.ts.map +1 -0
  748. package/dist/services/run-log-store.js +111 -0
  749. package/dist/services/run-log-store.js.map +1 -0
  750. package/dist/services/sandbox-provider-runtime.d.ts +132 -0
  751. package/dist/services/sandbox-provider-runtime.d.ts.map +1 -0
  752. package/dist/services/sandbox-provider-runtime.js +216 -0
  753. package/dist/services/sandbox-provider-runtime.js.map +1 -0
  754. package/dist/services/secrets.d.ts +515 -0
  755. package/dist/services/secrets.d.ts.map +1 -0
  756. package/dist/services/secrets.js +290 -0
  757. package/dist/services/secrets.js.map +1 -0
  758. package/dist/services/sidebar-badges.d.ts +14 -0
  759. package/dist/services/sidebar-badges.d.ts.map +1 -0
  760. package/dist/services/sidebar-badges.js +48 -0
  761. package/dist/services/sidebar-badges.js.map +1 -0
  762. package/dist/services/sidebar-preferences.d.ts +9 -0
  763. package/dist/services/sidebar-preferences.d.ts.map +1 -0
  764. package/dist/services/sidebar-preferences.js +82 -0
  765. package/dist/services/sidebar-preferences.js.map +1 -0
  766. package/dist/services/work-products.d.ts +14 -0
  767. package/dist/services/work-products.d.ts.map +1 -0
  768. package/dist/services/work-products.js +100 -0
  769. package/dist/services/work-products.js.map +1 -0
  770. package/dist/services/workspace-operation-log-store.d.ts +33 -0
  771. package/dist/services/workspace-operation-log-store.d.ts.map +1 -0
  772. package/dist/services/workspace-operation-log-store.js +110 -0
  773. package/dist/services/workspace-operation-log-store.js.map +1 -0
  774. package/dist/services/workspace-operations.d.ts +44 -0
  775. package/dist/services/workspace-operations.d.ts.map +1 -0
  776. package/dist/services/workspace-operations.js +211 -0
  777. package/dist/services/workspace-operations.js.map +1 -0
  778. package/dist/services/workspace-realization.d.ts +33 -0
  779. package/dist/services/workspace-realization.d.ts.map +1 -0
  780. package/dist/services/workspace-realization.js +221 -0
  781. package/dist/services/workspace-realization.js.map +1 -0
  782. package/dist/services/workspace-runtime-read-model.d.ts +92 -0
  783. package/dist/services/workspace-runtime-read-model.d.ts.map +1 -0
  784. package/dist/services/workspace-runtime-read-model.js +67 -0
  785. package/dist/services/workspace-runtime-read-model.js.map +1 -0
  786. package/dist/services/workspace-runtime.d.ts +238 -0
  787. package/dist/services/workspace-runtime.d.ts.map +1 -0
  788. package/dist/services/workspace-runtime.js +2388 -0
  789. package/dist/services/workspace-runtime.js.map +1 -0
  790. package/dist/startup-banner.d.ts +32 -0
  791. package/dist/startup-banner.d.ts.map +1 -0
  792. package/dist/startup-banner.js +118 -0
  793. package/dist/startup-banner.js.map +1 -0
  794. package/dist/storage/index.d.ts +6 -0
  795. package/dist/storage/index.d.ts.map +1 -0
  796. package/dist/storage/index.js +29 -0
  797. package/dist/storage/index.js.map +1 -0
  798. package/dist/storage/local-disk-provider.d.ts +3 -0
  799. package/dist/storage/local-disk-provider.d.ts.map +1 -0
  800. package/dist/storage/local-disk-provider.js +79 -0
  801. package/dist/storage/local-disk-provider.js.map +1 -0
  802. package/dist/storage/provider-registry.d.ts +4 -0
  803. package/dist/storage/provider-registry.d.ts.map +1 -0
  804. package/dist/storage/provider-registry.js +15 -0
  805. package/dist/storage/provider-registry.js.map +1 -0
  806. package/dist/storage/s3-provider.d.ts +11 -0
  807. package/dist/storage/s3-provider.d.ts.map +1 -0
  808. package/dist/storage/s3-provider.js +123 -0
  809. package/dist/storage/s3-provider.js.map +1 -0
  810. package/dist/storage/service.d.ts +3 -0
  811. package/dist/storage/service.d.ts.map +1 -0
  812. package/dist/storage/service.js +120 -0
  813. package/dist/storage/service.js.map +1 -0
  814. package/dist/storage/types.d.ts +55 -0
  815. package/dist/storage/types.d.ts.map +1 -0
  816. package/dist/storage/types.js +2 -0
  817. package/dist/storage/types.js.map +1 -0
  818. package/dist/telemetry.d.ts +6 -0
  819. package/dist/telemetry.d.ts.map +1 -0
  820. package/dist/telemetry.js +20 -0
  821. package/dist/telemetry.js.map +1 -0
  822. package/dist/ui-branding.d.ts +13 -0
  823. package/dist/ui-branding.d.ts.map +1 -0
  824. package/dist/ui-branding.js +187 -0
  825. package/dist/ui-branding.js.map +1 -0
  826. package/dist/version.d.ts +2 -0
  827. package/dist/version.d.ts.map +1 -0
  828. package/dist/version.js +5 -0
  829. package/dist/version.js.map +1 -0
  830. package/dist/vite-html-renderer.d.ts +18 -0
  831. package/dist/vite-html-renderer.d.ts.map +1 -0
  832. package/dist/vite-html-renderer.js +61 -0
  833. package/dist/vite-html-renderer.js.map +1 -0
  834. package/dist/worktree-config.d.ts +19 -0
  835. package/dist/worktree-config.d.ts.map +1 -0
  836. package/dist/worktree-config.js +368 -0
  837. package/dist/worktree-config.js.map +1 -0
  838. package/package.json +90 -0
  839. package/skills/diagnose-why-work-stopped/SKILL.md +161 -0
  840. package/skills/evermore/SKILL.md +366 -0
  841. package/skills/evermore/references/api-reference.md +899 -0
  842. package/skills/evermore/references/company-skills.md +193 -0
  843. package/skills/evermore/references/issue-workspaces.md +80 -0
  844. package/skills/evermore/references/routines.md +187 -0
  845. package/skills/evermore/references/workflows.md +141 -0
  846. package/skills/evermore-converting-plans-to-tasks/SKILL.md +42 -0
  847. package/skills/evermore-create-agent/SKILL.md +163 -0
  848. package/skills/evermore-create-agent/references/agent-instruction-templates.md +123 -0
  849. package/skills/evermore-create-agent/references/agents/coder.md +64 -0
  850. package/skills/evermore-create-agent/references/agents/qa.md +88 -0
  851. package/skills/evermore-create-agent/references/agents/securityengineer.md +135 -0
  852. package/skills/evermore-create-agent/references/agents/uxdesigner.md +115 -0
  853. package/skills/evermore-create-agent/references/api-reference.md +110 -0
  854. package/skills/evermore-create-agent/references/baseline-role-guide.md +168 -0
  855. package/skills/evermore-create-agent/references/draft-review-checklist.md +95 -0
  856. package/skills/evermore-create-plugin/SKILL.md +101 -0
  857. package/skills/evermore-dev/SKILL.md +267 -0
  858. package/skills/para-memory-files/SKILL.md +104 -0
  859. package/skills/para-memory-files/references/schemas.md +35 -0
  860. package/skills/terminal-bench-loop/SKILL.md +236 -0
  861. package/ui-dist/android-chrome-192x192.png +0 -0
  862. package/ui-dist/android-chrome-512x512.png +0 -0
  863. package/ui-dist/apple-touch-icon.png +0 -0
  864. package/ui-dist/assets/_basePickBy-Ds9oHp1_.js +1 -0
  865. package/ui-dist/assets/_baseUniq-CHYwQyJ_.js +1 -0
  866. package/ui-dist/assets/apl-B4CMkyY2.js +1 -0
  867. package/ui-dist/assets/arc-CiUKtBzk.js +1 -0
  868. package/ui-dist/assets/architectureDiagram-VXUJARFQ-CAW2b6pT.js +36 -0
  869. package/ui-dist/assets/asciiarmor-Df11BRmG.js +1 -0
  870. package/ui-dist/assets/asn1-EdZsLKOL.js +1 -0
  871. package/ui-dist/assets/asterisk-B-8jnY81.js +1 -0
  872. package/ui-dist/assets/blockDiagram-VD42YOAC-1Rk6YCcn.js +122 -0
  873. package/ui-dist/assets/brainfuck-C4LP7Hcl.js +1 -0
  874. package/ui-dist/assets/c4Diagram-YG6GDRKO-DF5RJtyZ.js +10 -0
  875. package/ui-dist/assets/channel-D7SqxhNi.js +1 -0
  876. package/ui-dist/assets/chunk-4BX2VUAB-BSZDJAxk.js +1 -0
  877. package/ui-dist/assets/chunk-55IACEB6-DgVOW-V3.js +1 -0
  878. package/ui-dist/assets/chunk-B4BG7PRW-C1sGAq6t.js +165 -0
  879. package/ui-dist/assets/chunk-DI55MBZ5-DZyfq3VK.js +220 -0
  880. package/ui-dist/assets/chunk-FMBD7UC4-D6K9nYXi.js +15 -0
  881. package/ui-dist/assets/chunk-QN33PNHL-BJ0Ni2l9.js +1 -0
  882. package/ui-dist/assets/chunk-QZHKN3VN-Cwjr0vxG.js +1 -0
  883. package/ui-dist/assets/chunk-TZMSLE5B-C2RGCkyV.js +1 -0
  884. package/ui-dist/assets/classDiagram-2ON5EDUG-Cx1PlXXb.js +1 -0
  885. package/ui-dist/assets/classDiagram-v2-WZHVMYZB-Cx1PlXXb.js +1 -0
  886. package/ui-dist/assets/clike-B9uivgTg.js +1 -0
  887. package/ui-dist/assets/clojure-BMjYHr_A.js +1 -0
  888. package/ui-dist/assets/clone-5ZE-SRxk.js +1 -0
  889. package/ui-dist/assets/cmake-BQqOBYOt.js +1 -0
  890. package/ui-dist/assets/cobol-CWcv1MsR.js +1 -0
  891. package/ui-dist/assets/coffeescript-S37ZYGWr.js +1 -0
  892. package/ui-dist/assets/commonlisp-DBKNyK5s.js +1 -0
  893. package/ui-dist/assets/cose-bilkent-S5V4N54A-CW0Mh3DC.js +1 -0
  894. package/ui-dist/assets/crystal-SjHAIU92.js +1 -0
  895. package/ui-dist/assets/css-BnMrqG3P.js +1 -0
  896. package/ui-dist/assets/cypher-C_CwsFkJ.js +1 -0
  897. package/ui-dist/assets/cytoscape.esm-jbPEKk2Y.js +321 -0
  898. package/ui-dist/assets/d-pRatUO7H.js +1 -0
  899. package/ui-dist/assets/dagre-6UL2VRFP-BXDbyGyw.js +4 -0
  900. package/ui-dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  901. package/ui-dist/assets/diagram-PSM6KHXK-BHW-b3P9.js +24 -0
  902. package/ui-dist/assets/diagram-QEK2KX5R-vjGsaMmX.js +43 -0
  903. package/ui-dist/assets/diagram-S2PKOQOG-BHVhRqBj.js +24 -0
  904. package/ui-dist/assets/diff-DbItnlRl.js +1 -0
  905. package/ui-dist/assets/dockerfile-BKs6k2Af.js +1 -0
  906. package/ui-dist/assets/dtd-DF_7sFjM.js +1 -0
  907. package/ui-dist/assets/dylan-DwRh75JA.js +1 -0
  908. package/ui-dist/assets/ebnf-CDyGwa7X.js +1 -0
  909. package/ui-dist/assets/ecl-Cabwm37j.js +1 -0
  910. package/ui-dist/assets/eiffel-CnydiIhH.js +1 -0
  911. package/ui-dist/assets/elm-vLlmbW-K.js +1 -0
  912. package/ui-dist/assets/erDiagram-Q2GNP2WA-DwsdEDB2.js +60 -0
  913. package/ui-dist/assets/erlang-BNw1qcRV.js +1 -0
  914. package/ui-dist/assets/factor-kuTfRLto.js +1 -0
  915. package/ui-dist/assets/fcl-Kvtd6kyn.js +1 -0
  916. package/ui-dist/assets/flowDiagram-NV44I4VS-Bv7drkZu.js +162 -0
  917. package/ui-dist/assets/forth-Ffai-XNe.js +1 -0
  918. package/ui-dist/assets/fortran-DYz_wnZ1.js +1 -0
  919. package/ui-dist/assets/ganttDiagram-JELNMOA3-DyYAGyjV.js +267 -0
  920. package/ui-dist/assets/gas-Bneqetm1.js +1 -0
  921. package/ui-dist/assets/gherkin-heZmZLOM.js +1 -0
  922. package/ui-dist/assets/gitGraphDiagram-V2S2FVAM-DmKJJ2X0.js +65 -0
  923. package/ui-dist/assets/graph-BI12oqz9.js +1 -0
  924. package/ui-dist/assets/groovy-D9Dt4D0W.js +1 -0
  925. package/ui-dist/assets/haskell-Cw1EW3IL.js +1 -0
  926. package/ui-dist/assets/haxe-H-WmDvRZ.js +1 -0
  927. package/ui-dist/assets/http-DBlCnlav.js +1 -0
  928. package/ui-dist/assets/idl-BEugSyMb.js +1 -0
  929. package/ui-dist/assets/index-B1YmgKZD.js +1 -0
  930. package/ui-dist/assets/index-B5EG1mbW.js +1 -0
  931. package/ui-dist/assets/index-B63DPkk7.js +2 -0
  932. package/ui-dist/assets/index-BAalUM2u.js +1 -0
  933. package/ui-dist/assets/index-BCyQqUEQ.js +1 -0
  934. package/ui-dist/assets/index-BSRsyahM.js +1 -0
  935. package/ui-dist/assets/index-B_Iu4zUd.js +1 -0
  936. package/ui-dist/assets/index-C-BdZUIH.js +1 -0
  937. package/ui-dist/assets/index-CGgUnSQj.js +6 -0
  938. package/ui-dist/assets/index-COTIEysQ.js +1 -0
  939. package/ui-dist/assets/index-ChSqseHR.js +1 -0
  940. package/ui-dist/assets/index-Ckf1hADU.js +534 -0
  941. package/ui-dist/assets/index-D4M1TSCO.js +3 -0
  942. package/ui-dist/assets/index-DCTk2CN-.js +7 -0
  943. package/ui-dist/assets/index-DI-wyUUr.js +1 -0
  944. package/ui-dist/assets/index-DNtLqZ-D.js +1 -0
  945. package/ui-dist/assets/index-DSRR_614.css +1 -0
  946. package/ui-dist/assets/index-DarmgkJv.js +1 -0
  947. package/ui-dist/assets/index-DdcxF71a.js +1 -0
  948. package/ui-dist/assets/index-DfwWaMga.js +1 -0
  949. package/ui-dist/assets/index-SzUviW57.js +13 -0
  950. package/ui-dist/assets/index-VjZhELb6.js +1 -0
  951. package/ui-dist/assets/index-mEcmy8wG.js +1 -0
  952. package/ui-dist/assets/index-q7ldlDv6.js +1 -0
  953. package/ui-dist/assets/infoDiagram-HS3SLOUP-CqAxMRbC.js +2 -0
  954. package/ui-dist/assets/init-Gi6I4Gst.js +1 -0
  955. package/ui-dist/assets/javascript-iXu5QeM3.js +1 -0
  956. package/ui-dist/assets/journeyDiagram-XKPGCS4Q-DUJiudtY.js +139 -0
  957. package/ui-dist/assets/julia-DuME0IfC.js +1 -0
  958. package/ui-dist/assets/kanban-definition-3W4ZIXB7-CiRgJ4X2.js +89 -0
  959. package/ui-dist/assets/katex-B95LWT_Q.js +261 -0
  960. package/ui-dist/assets/layout-DJ8V2pqt.js +1 -0
  961. package/ui-dist/assets/linear-BwnNUuyZ.js +1 -0
  962. package/ui-dist/assets/livescript-BwQOo05w.js +1 -0
  963. package/ui-dist/assets/lua-BgMRiT3U.js +1 -0
  964. package/ui-dist/assets/mathematica-DTrFuWx2.js +1 -0
  965. package/ui-dist/assets/mbox-CNhZ1qSd.js +1 -0
  966. package/ui-dist/assets/mermaid.core-DLCiCWj4.js +250 -0
  967. package/ui-dist/assets/mindmap-definition-VGOIOE7T-epIiGA01.js +68 -0
  968. package/ui-dist/assets/mirc-CjQqDB4T.js +1 -0
  969. package/ui-dist/assets/mllike-CXdrOF99.js +1 -0
  970. package/ui-dist/assets/modelica-Dc1JOy9r.js +1 -0
  971. package/ui-dist/assets/mscgen-BA5vi2Kp.js +1 -0
  972. package/ui-dist/assets/mumps-BT43cFF4.js +1 -0
  973. package/ui-dist/assets/nginx-DdIZxoE0.js +1 -0
  974. package/ui-dist/assets/nsis-LdVXkNf5.js +1 -0
  975. package/ui-dist/assets/ntriples-BfvgReVJ.js +1 -0
  976. package/ui-dist/assets/octave-Ck1zUtKM.js +1 -0
  977. package/ui-dist/assets/ordinal-Cboi1Yqb.js +1 -0
  978. package/ui-dist/assets/oz-BzwKVEFT.js +1 -0
  979. package/ui-dist/assets/pascal--L3eBynH.js +1 -0
  980. package/ui-dist/assets/perl-CdXCOZ3F.js +1 -0
  981. package/ui-dist/assets/pieDiagram-ADFJNKIX-CHx4pJ9Y.js +30 -0
  982. package/ui-dist/assets/pig-CevX1Tat.js +1 -0
  983. package/ui-dist/assets/powershell-CFHJl5sT.js +1 -0
  984. package/ui-dist/assets/properties-C78fOPTZ.js +1 -0
  985. package/ui-dist/assets/protobuf-ChK-085T.js +1 -0
  986. package/ui-dist/assets/pug-DeIclll2.js +1 -0
  987. package/ui-dist/assets/puppet-DMA9R1ak.js +1 -0
  988. package/ui-dist/assets/python-BuPzkPfP.js +1 -0
  989. package/ui-dist/assets/q-pXgVlZs6.js +1 -0
  990. package/ui-dist/assets/quadrantDiagram-AYHSOK5B-D0tXmGxE.js +7 -0
  991. package/ui-dist/assets/r-B6wPVr8A.js +1 -0
  992. package/ui-dist/assets/requirementDiagram-UZGBJVZJ-BgFc9Xc4.js +64 -0
  993. package/ui-dist/assets/rpm-CTu-6PCP.js +1 -0
  994. package/ui-dist/assets/ruby-B2Rjki9n.js +1 -0
  995. package/ui-dist/assets/sankeyDiagram-TZEHDZUN-DqntX5wV.js +10 -0
  996. package/ui-dist/assets/sas-B4kiWyti.js +1 -0
  997. package/ui-dist/assets/scheme-C41bIUwD.js +1 -0
  998. package/ui-dist/assets/sequenceDiagram-WL72ISMW-BfIJeGAT.js +145 -0
  999. package/ui-dist/assets/shell-CjFT_Tl9.js +1 -0
  1000. package/ui-dist/assets/sieve-C3Gn_uJK.js +1 -0
  1001. package/ui-dist/assets/simple-mode-GW_nhZxv.js +1 -0
  1002. package/ui-dist/assets/smalltalk-CnHTOXQT.js +1 -0
  1003. package/ui-dist/assets/solr-DehyRSwq.js +1 -0
  1004. package/ui-dist/assets/sparql-DkYu6x3z.js +1 -0
  1005. package/ui-dist/assets/spreadsheet-BCZA_wO0.js +1 -0
  1006. package/ui-dist/assets/sql-D0XecflT.js +1 -0
  1007. package/ui-dist/assets/stateDiagram-FKZM4ZOC-CBlsmcoW.js +1 -0
  1008. package/ui-dist/assets/stateDiagram-v2-4FDKWEC3-DJtH2tCS.js +1 -0
  1009. package/ui-dist/assets/stex-C3f8Ysf7.js +1 -0
  1010. package/ui-dist/assets/stylus-B533Al4x.js +1 -0
  1011. package/ui-dist/assets/swift-BzpIVaGY.js +1 -0
  1012. package/ui-dist/assets/tcl-DVfN8rqt.js +1 -0
  1013. package/ui-dist/assets/textile-CnDTJFAw.js +1 -0
  1014. package/ui-dist/assets/tiddlywiki-DO-Gjzrf.js +1 -0
  1015. package/ui-dist/assets/tiki-DGYXhP31.js +1 -0
  1016. package/ui-dist/assets/timeline-definition-IT6M3QCI-C2XyT4Lo.js +61 -0
  1017. package/ui-dist/assets/toml-Bm5Em-hy.js +1 -0
  1018. package/ui-dist/assets/treemap-GDKQZRPO-DvTrxs0e.js +154 -0
  1019. package/ui-dist/assets/troff-wAsdV37c.js +1 -0
  1020. package/ui-dist/assets/ttcn-CfJYG6tj.js +1 -0
  1021. package/ui-dist/assets/ttcn-cfg-B9xdYoR4.js +1 -0
  1022. package/ui-dist/assets/turtle-B1tBg_DP.js +1 -0
  1023. package/ui-dist/assets/vb-CmGdzxic.js +1 -0
  1024. package/ui-dist/assets/vbscript-BuJXcnF6.js +1 -0
  1025. package/ui-dist/assets/velocity-D8B20fx6.js +1 -0
  1026. package/ui-dist/assets/verilog-C6RDOZhf.js +1 -0
  1027. package/ui-dist/assets/vhdl-lSbBsy5d.js +1 -0
  1028. package/ui-dist/assets/webidl-ZXfAyPTL.js +1 -0
  1029. package/ui-dist/assets/xquery-DzFWVndE.js +1 -0
  1030. package/ui-dist/assets/xychartDiagram-PRI3JC2R-pTizTbG0.js +7 -0
  1031. package/ui-dist/assets/yacas-BJ4BC0dw.js +1 -0
  1032. package/ui-dist/assets/z80-Hz9HOZM7.js +1 -0
  1033. package/ui-dist/brands/opencode-logo-dark-square.svg +18 -0
  1034. package/ui-dist/brands/opencode-logo-light-square.svg +18 -0
  1035. package/ui-dist/favicon-16x16.png +0 -0
  1036. package/ui-dist/favicon-32x32.png +0 -0
  1037. package/ui-dist/favicon.ico +0 -0
  1038. package/ui-dist/favicon.svg +9 -0
  1039. package/ui-dist/index.html +49 -0
  1040. package/ui-dist/site.webmanifest +30 -0
  1041. package/ui-dist/sw.js +42 -0
  1042. package/ui-dist/worktree-favicon-16x16.png +0 -0
  1043. package/ui-dist/worktree-favicon-32x32.png +0 -0
  1044. package/ui-dist/worktree-favicon.ico +0 -0
  1045. package/ui-dist/worktree-favicon.svg +9 -0
@@ -0,0 +1,2192 @@
1
+ /**
2
+ * @fileoverview Plugin management REST API routes
3
+ *
4
+ * This module provides Express routes for managing the complete plugin lifecycle:
5
+ * - Listing and filtering plugins by status
6
+ * - Installing plugins from npm or local paths
7
+ * - Uninstalling plugins (soft delete or hard purge)
8
+ * - Enabling/disabling plugins
9
+ * - Running health diagnostics
10
+ * - Upgrading plugins
11
+ * - Retrieving UI slot contributions for frontend rendering
12
+ * - Discovering and executing plugin-contributed agent tools
13
+ *
14
+ * All routes require board-level authentication, and sensitive instance-wide
15
+ * mutations such as install/upgrade require instance-admin privileges.
16
+ *
17
+ * @module server/routes/plugins
18
+ * @see doc/plugins/PLUGIN_SPEC.md for the full plugin specification
19
+ */
20
+ import { existsSync } from "node:fs";
21
+ import path from "node:path";
22
+ import { randomUUID } from "node:crypto";
23
+ import { fileURLToPath } from "node:url";
24
+ import { Router } from "express";
25
+ import { and, desc, eq, gte } from "drizzle-orm";
26
+ import { agents, companies, heartbeatRuns, pluginLogs, pluginWebhookDeliveries, projects, } from "@evermore.work/db";
27
+ import { PLUGIN_STATUSES, } from "@evermore.work/shared";
28
+ import { pluginRegistryService } from "../services/plugin-registry.js";
29
+ import { pluginLifecycleManager } from "../services/plugin-lifecycle.js";
30
+ import { getPluginUiContributionMetadata } from "../services/plugin-loader.js";
31
+ import { logActivity } from "../services/activity-log.js";
32
+ import { publishGlobalLiveEvent } from "../services/live-events.js";
33
+ import { issueService } from "../services/issues.js";
34
+ import { JsonRpcCallError, PLUGIN_RPC_ERROR_CODES } from "@evermore.work/plugin-sdk";
35
+ import { assertAuthenticated, assertBoard, assertBoardOrgAccess, assertCompanyAccess, assertInstanceAdmin, getActorInfo, } from "./authz.js";
36
+ import { validateInstanceConfig } from "../services/plugin-config-validator.js";
37
+ import { findLocalFolderDeclaration, getStoredLocalFolders, inspectPluginLocalFolder, requireLocalFolderDeclaration, setStoredLocalFolder, } from "../services/plugin-local-folders.js";
38
+ import { badRequest, forbidden, notFound, unauthorized, unprocessable } from "../errors.js";
39
+ /** UUID v4 regex used for plugin ID route resolution. */
40
+ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
41
+ const PLUGIN_API_BODY_LIMIT_BYTES = 1_000_000;
42
+ const PLUGIN_SCOPED_API_RESPONSE_HEADER_ALLOWLIST = new Set([
43
+ "cache-control",
44
+ "etag",
45
+ "last-modified",
46
+ "x-request-id",
47
+ ]);
48
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
49
+ const REPO_ROOT = path.resolve(__dirname, "../../..");
50
+ const BUNDLED_PLUGIN_EXAMPLES = [
51
+ {
52
+ packageName: "@evermore.work/plugin-hello-world-example",
53
+ pluginKey: "evermore.hello-world-example",
54
+ displayName: "Hello World Widget (Example)",
55
+ description: "Reference UI plugin that adds a simple Hello World widget to the Evermore dashboard.",
56
+ localPath: "packages/plugins/examples/plugin-hello-world-example",
57
+ tag: "example",
58
+ },
59
+ {
60
+ packageName: "@evermore.work/plugin-file-browser-example",
61
+ pluginKey: "evermore-file-browser-example",
62
+ displayName: "File Browser (Example)",
63
+ description: "Example plugin that adds a Files link in project navigation plus a project detail file browser.",
64
+ localPath: "packages/plugins/examples/plugin-file-browser-example",
65
+ tag: "example",
66
+ },
67
+ {
68
+ packageName: "@evermore.work/plugin-kitchen-sink-example",
69
+ pluginKey: "evermore-kitchen-sink-example",
70
+ displayName: "Kitchen Sink (Example)",
71
+ description: "Reference plugin that demonstrates the current Evermore plugin API surface, bridge flows, UI extension surfaces, jobs, webhooks, tools, streams, and trusted local workspace/process demos.",
72
+ localPath: "packages/plugins/examples/plugin-kitchen-sink-example",
73
+ tag: "example",
74
+ },
75
+ {
76
+ packageName: "@evermore.work/plugin-orchestration-smoke-example",
77
+ pluginKey: "evermore.plugin-orchestration-smoke-example",
78
+ displayName: "Orchestration Smoke (Example)",
79
+ description: "Acceptance fixture for scoped plugin routes, restricted database namespaces, issue orchestration, documents, wakeups, summaries, and UI status surfaces.",
80
+ localPath: "packages/plugins/examples/plugin-orchestration-smoke-example",
81
+ tag: "example",
82
+ },
83
+ ];
84
+ function listBundledPluginExamples() {
85
+ return BUNDLED_PLUGIN_EXAMPLES.flatMap((plugin) => {
86
+ const absoluteLocalPath = path.resolve(REPO_ROOT, plugin.localPath);
87
+ if (!existsSync(absoluteLocalPath))
88
+ return [];
89
+ return [{ ...plugin, localPath: absoluteLocalPath }];
90
+ });
91
+ }
92
+ /**
93
+ * Resolve a plugin by either database ID or plugin key.
94
+ *
95
+ * Lookup order:
96
+ * - UUID-like IDs: getById first, then getByKey.
97
+ * - Scoped package keys (e.g. "@scope/name"): getByKey only, never getById.
98
+ * - Other non-UUID IDs: try getById first (test/memory registries may allow this),
99
+ * then fallback to getByKey. Any UUID parse error from getById is ignored.
100
+ *
101
+ * @param registry - The plugin registry service instance
102
+ * @param pluginId - Either a database UUID or plugin key (manifest id)
103
+ * @returns Plugin record or null if not found
104
+ */
105
+ async function resolvePlugin(registry, pluginId) {
106
+ const isUuid = UUID_REGEX.test(pluginId);
107
+ const isScopedPackageKey = pluginId.startsWith("@") || pluginId.includes("/");
108
+ // Scoped package IDs are valid plugin keys but invalid UUIDs.
109
+ // Skip getById() entirely to avoid Postgres uuid parse errors.
110
+ if (isScopedPackageKey && !isUuid) {
111
+ return registry.getByKey(pluginId);
112
+ }
113
+ try {
114
+ const byId = await registry.getById(pluginId);
115
+ if (byId)
116
+ return byId;
117
+ }
118
+ catch (error) {
119
+ const maybeCode = typeof error === "object" && error !== null && "code" in error
120
+ ? error.code
121
+ : undefined;
122
+ // Ignore invalid UUID cast errors and continue with key lookup.
123
+ if (maybeCode !== "22P02") {
124
+ throw error;
125
+ }
126
+ }
127
+ return registry.getByKey(pluginId);
128
+ }
129
+ /**
130
+ * Create Express router for plugin management API.
131
+ *
132
+ * Routes provided:
133
+ *
134
+ * | Method | Path | Description |
135
+ * |--------|------|-------------|
136
+ * | GET | /plugins | List all plugins (optional ?status= filter) |
137
+ * | GET | /plugins/ui-contributions | Get UI slots from ready plugins |
138
+ * | GET | /plugins/:pluginId | Get single plugin by ID or key |
139
+ * | POST | /plugins/install | Install from npm or local path |
140
+ * | DELETE | /plugins/:pluginId | Uninstall (optional ?purge=true) |
141
+ * | POST | /plugins/:pluginId/enable | Enable a plugin |
142
+ * | POST | /plugins/:pluginId/disable | Disable a plugin |
143
+ * | GET | /plugins/:pluginId/health | Run health diagnostics |
144
+ * | POST | /plugins/:pluginId/upgrade | Upgrade to newer version |
145
+ * | GET | /plugins/:pluginId/jobs | List jobs for a plugin |
146
+ * | GET | /plugins/:pluginId/jobs/:jobId/runs | List runs for a job |
147
+ * | POST | /plugins/:pluginId/jobs/:jobId/trigger | Manually trigger a job |
148
+ * | POST | /plugins/:pluginId/webhooks/:endpointKey | Receive inbound webhook |
149
+ * | GET | /plugins/tools | List all available plugin tools |
150
+ * | GET | /plugins/tools?pluginId=... | List tools for a specific plugin |
151
+ * | POST | /plugins/tools/execute | Execute a plugin tool |
152
+ * | GET | /plugins/:pluginId/config | Get current plugin config |
153
+ * | POST | /plugins/:pluginId/config | Save (upsert) plugin config |
154
+ * | POST | /plugins/:pluginId/config/test | Test config via validateConfig RPC |
155
+ * | POST | /plugins/:pluginId/bridge/data | Proxy getData to plugin worker |
156
+ * | POST | /plugins/:pluginId/bridge/action | Proxy performAction to plugin worker |
157
+ * | POST | /plugins/:pluginId/data/:key | Proxy getData to plugin worker (key in URL) |
158
+ * | POST | /plugins/:pluginId/actions/:key | Proxy performAction to plugin worker (key in URL) |
159
+ * | GET | /plugins/:pluginId/bridge/stream/:channel | SSE stream from worker to UI |
160
+ * | GET | /plugins/:pluginId/dashboard | Aggregated health dashboard data |
161
+ *
162
+ * **Route Ordering Note:** Static routes (like /ui-contributions, /tools) must be
163
+ * registered before parameterized routes (like /:pluginId) to prevent Express from
164
+ * matching them as a plugin ID.
165
+ *
166
+ * @param db - Database connection instance
167
+ * @param jobDeps - Optional job scheduling dependencies
168
+ * @param webhookDeps - Optional webhook ingestion dependencies
169
+ * @param toolDeps - Optional tool dispatcher dependencies
170
+ * @param bridgeDeps - Optional bridge proxy dependencies for getData/performAction
171
+ * @returns Express router with plugin routes mounted
172
+ */
173
+ export function pluginRoutes(db, loader, jobDeps, webhookDeps, toolDeps, bridgeDeps) {
174
+ const router = Router();
175
+ const registry = pluginRegistryService(db);
176
+ const lifecycle = pluginLifecycleManager(db, {
177
+ loader,
178
+ workerManager: bridgeDeps?.workerManager ?? webhookDeps?.workerManager,
179
+ });
180
+ const issuesSvc = issueService(db);
181
+ function matchScopedApiRoute(route, method, requestPath) {
182
+ if (route.method !== method)
183
+ return null;
184
+ const normalize = (value) => value.replace(/\/+$/, "") || "/";
185
+ const routeSegments = normalize(route.path).split("/").filter(Boolean);
186
+ const requestSegments = normalize(requestPath).split("/").filter(Boolean);
187
+ if (routeSegments.length !== requestSegments.length)
188
+ return null;
189
+ const params = {};
190
+ for (let i = 0; i < routeSegments.length; i += 1) {
191
+ const routeSegment = routeSegments[i];
192
+ const requestSegment = requestSegments[i];
193
+ if (routeSegment.startsWith(":")) {
194
+ params[routeSegment.slice(1)] = decodeURIComponent(requestSegment);
195
+ continue;
196
+ }
197
+ if (routeSegment !== requestSegment)
198
+ return null;
199
+ }
200
+ return params;
201
+ }
202
+ function sanitizePluginRequestHeaders(req) {
203
+ const safeHeaderNames = new Set([
204
+ "accept",
205
+ "content-type",
206
+ "user-agent",
207
+ "x-evermore-run-id",
208
+ "x-request-id",
209
+ ]);
210
+ const headers = {};
211
+ for (const [name, value] of Object.entries(req.headers)) {
212
+ const lower = name.toLowerCase();
213
+ if (!safeHeaderNames.has(lower))
214
+ continue;
215
+ if (Array.isArray(value)) {
216
+ headers[lower] = value.join(", ");
217
+ }
218
+ else if (typeof value === "string") {
219
+ headers[lower] = value;
220
+ }
221
+ }
222
+ return headers;
223
+ }
224
+ function applyPluginScopedApiResponseHeaders(res, headers) {
225
+ for (const [name, value] of Object.entries(headers ?? {})) {
226
+ const lower = name.toLowerCase();
227
+ if (!PLUGIN_SCOPED_API_RESPONSE_HEADER_ALLOWLIST.has(lower))
228
+ continue;
229
+ res.setHeader(lower, value);
230
+ }
231
+ }
232
+ function normalizeQuery(query) {
233
+ const normalized = {};
234
+ for (const [key, value] of Object.entries(query)) {
235
+ if (typeof value === "string") {
236
+ normalized[key] = value;
237
+ }
238
+ else if (Array.isArray(value)) {
239
+ normalized[key] = value.map((entry) => String(entry));
240
+ }
241
+ }
242
+ return normalized;
243
+ }
244
+ async function resolveScopedApiCompanyId(route, params, req) {
245
+ const resolution = route.companyResolution;
246
+ if (!resolution) {
247
+ if (req.actor.type === "agent" && req.actor.companyId)
248
+ return req.actor.companyId;
249
+ return null;
250
+ }
251
+ if (resolution.from === "body") {
252
+ const body = req.body;
253
+ const companyId = body?.[resolution.key ?? ""];
254
+ return typeof companyId === "string" ? companyId : null;
255
+ }
256
+ if (resolution.from === "query") {
257
+ const value = req.query[resolution.key ?? ""];
258
+ return typeof value === "string" ? value : null;
259
+ }
260
+ const issueId = params[resolution.param ?? ""];
261
+ if (!issueId)
262
+ return null;
263
+ const issue = await issuesSvc.getById(issueId);
264
+ return issue?.companyId ?? null;
265
+ }
266
+ function assertScopedApiAuth(req, route) {
267
+ if (route.auth === "board") {
268
+ assertBoard(req);
269
+ return;
270
+ }
271
+ if (route.auth === "agent") {
272
+ assertAuthenticated(req);
273
+ if (req.actor.type !== "agent")
274
+ throw forbidden("Agent access required");
275
+ return;
276
+ }
277
+ if (route.auth === "webhook") {
278
+ throw unprocessable("Webhook-scoped plugin API routes require a signature verifier and are not enabled");
279
+ }
280
+ assertAuthenticated(req);
281
+ if (req.actor.type !== "board" && req.actor.type !== "agent") {
282
+ throw forbidden("Board or agent access required");
283
+ }
284
+ }
285
+ async function enforceScopedApiCheckout(req, route, params, companyId) {
286
+ const policy = route.checkoutPolicy ?? "none";
287
+ if (policy === "none" || req.actor.type !== "agent")
288
+ return;
289
+ const issueId = params.issueId;
290
+ if (!issueId) {
291
+ throw unprocessable("Checkout-protected plugin API routes require an issueId route parameter");
292
+ }
293
+ const issue = await issuesSvc.getById(issueId);
294
+ if (!issue || issue.companyId !== companyId) {
295
+ throw notFound("Issue not found");
296
+ }
297
+ if (policy === "required-for-agent-in-progress") {
298
+ if (issue.status !== "in_progress" || issue.assigneeAgentId !== req.actor.agentId)
299
+ return;
300
+ }
301
+ const runId = req.actor.runId?.trim();
302
+ if (!runId) {
303
+ throw unauthorized("Agent run id required");
304
+ }
305
+ if (!req.actor.agentId) {
306
+ throw forbidden("Agent authentication required");
307
+ }
308
+ await issuesSvc.assertCheckoutOwner(issueId, req.actor.agentId, runId);
309
+ }
310
+ async function resolvePluginAuditCompanyIds(req) {
311
+ if (typeof db.select === "function") {
312
+ const rows = await db
313
+ .select({ id: companies.id })
314
+ .from(companies);
315
+ return rows.map((row) => row.id);
316
+ }
317
+ if (req.actor.type === "agent" && req.actor.companyId) {
318
+ return [req.actor.companyId];
319
+ }
320
+ if (req.actor.type === "board") {
321
+ return req.actor.companyIds ?? [];
322
+ }
323
+ return [];
324
+ }
325
+ async function logPluginMutationActivity(req, action, entityId, details) {
326
+ const companyIds = await resolvePluginAuditCompanyIds(req);
327
+ if (companyIds.length === 0)
328
+ return;
329
+ const actor = getActorInfo(req);
330
+ await Promise.all(companyIds.map((companyId) => logActivity(db, {
331
+ companyId,
332
+ actorType: actor.actorType,
333
+ actorId: actor.actorId,
334
+ agentId: actor.agentId,
335
+ runId: actor.runId,
336
+ action,
337
+ entityType: "plugin",
338
+ entityId,
339
+ details,
340
+ })));
341
+ }
342
+ function assertPluginBridgeScope(req, companyId) {
343
+ if (companyId === undefined || companyId === null) {
344
+ assertInstanceAdmin(req);
345
+ return undefined;
346
+ }
347
+ if (typeof companyId !== "string" || companyId.trim().length === 0) {
348
+ throw badRequest('"companyId" must be a non-empty string when provided');
349
+ }
350
+ assertCompanyAccess(req, companyId);
351
+ return companyId;
352
+ }
353
+ async function validateToolRunContextScope(runContext) {
354
+ const [agent] = await db
355
+ .select({ companyId: agents.companyId })
356
+ .from(agents)
357
+ .where(eq(agents.id, runContext.agentId))
358
+ .limit(1);
359
+ if (!agent || agent.companyId !== runContext.companyId) {
360
+ return '"runContext.agentId" does not belong to "runContext.companyId"';
361
+ }
362
+ const [run] = await db
363
+ .select({ companyId: heartbeatRuns.companyId, agentId: heartbeatRuns.agentId })
364
+ .from(heartbeatRuns)
365
+ .where(eq(heartbeatRuns.id, runContext.runId))
366
+ .limit(1);
367
+ if (!run || run.companyId !== runContext.companyId) {
368
+ return '"runContext.runId" does not belong to "runContext.companyId"';
369
+ }
370
+ if (run.agentId !== runContext.agentId) {
371
+ return '"runContext.runId" does not belong to "runContext.agentId"';
372
+ }
373
+ const [project] = await db
374
+ .select({ companyId: projects.companyId })
375
+ .from(projects)
376
+ .where(eq(projects.id, runContext.projectId))
377
+ .limit(1);
378
+ if (!project || project.companyId !== runContext.companyId) {
379
+ return '"runContext.projectId" does not belong to "runContext.companyId"';
380
+ }
381
+ return null;
382
+ }
383
+ /**
384
+ * GET /api/plugins
385
+ *
386
+ * List all installed plugins, optionally filtered by lifecycle status.
387
+ *
388
+ * Query params:
389
+ * - `status` (optional): Filter by lifecycle status. Must be one of the
390
+ * values in `PLUGIN_STATUSES` (`installed`, `ready`, `error`,
391
+ * `upgrade_pending`, `uninstalled`). Returns HTTP 400 if the value is
392
+ * not a recognised status string.
393
+ *
394
+ * Response: `PluginRecord[]`
395
+ */
396
+ router.get("/plugins", async (req, res) => {
397
+ assertBoardOrgAccess(req);
398
+ const rawStatus = req.query.status;
399
+ if (rawStatus !== undefined) {
400
+ if (typeof rawStatus !== "string" || !PLUGIN_STATUSES.includes(rawStatus)) {
401
+ res.status(400).json({
402
+ error: `Invalid status '${String(rawStatus)}'. Must be one of: ${PLUGIN_STATUSES.join(", ")}`,
403
+ });
404
+ return;
405
+ }
406
+ }
407
+ const status = rawStatus;
408
+ const plugins = status
409
+ ? await registry.listByStatus(status)
410
+ : await registry.listInstalled();
411
+ res.json(plugins);
412
+ });
413
+ /**
414
+ * GET /api/plugins/examples
415
+ *
416
+ * Return first-party example plugins bundled in this repo, if present.
417
+ * These can be installed through the normal local-path install flow.
418
+ */
419
+ router.get("/plugins/examples", async (req, res) => {
420
+ assertBoardOrgAccess(req);
421
+ res.json(listBundledPluginExamples());
422
+ });
423
+ // IMPORTANT: Static routes must come before parameterized routes
424
+ // to avoid Express matching "ui-contributions" as a :pluginId
425
+ /**
426
+ * GET /api/plugins/ui-contributions
427
+ *
428
+ * Return UI contributions from all plugins in 'ready' state.
429
+ * Used by the frontend to discover plugin UI slots and launcher metadata.
430
+ *
431
+ * The response is normalized for the frontend slot host:
432
+ * - Only includes plugins with at least one declared UI slot or launcher
433
+ * - Excludes plugins with null/missing manifestJson (defensive)
434
+ * - Slots are extracted from manifest.ui.slots
435
+ * - Launchers are aggregated from legacy manifest.launchers and manifest.ui.launchers
436
+ *
437
+ * Example response:
438
+ * ```json
439
+ * [
440
+ * {
441
+ * "pluginId": "plg_123",
442
+ * "pluginKey": "evermore.claude-usage",
443
+ * "displayName": "Claude Usage",
444
+ * "version": "1.0.0",
445
+ * "uiEntryFile": "index.js",
446
+ * "slots": [],
447
+ * "launchers": [
448
+ * {
449
+ * "id": "claude-usage-toolbar",
450
+ * "displayName": "Claude Usage",
451
+ * "placementZone": "toolbarButton",
452
+ * "action": { "type": "openModal", "target": "ClaudeUsageView" },
453
+ * "render": { "environment": "hostOverlay", "bounds": "wide" }
454
+ * }
455
+ * ]
456
+ * }
457
+ * ]
458
+ * ```
459
+ *
460
+ * Response: PluginUiContribution[]
461
+ */
462
+ router.get("/plugins/ui-contributions", async (req, res) => {
463
+ assertBoardOrgAccess(req);
464
+ const plugins = await registry.listByStatus("ready");
465
+ const contributions = plugins
466
+ .map((plugin) => {
467
+ // Safety check: manifestJson should always exist for ready plugins, but guard against null
468
+ const manifest = plugin.manifestJson;
469
+ if (!manifest)
470
+ return null;
471
+ const uiMetadata = getPluginUiContributionMetadata(manifest);
472
+ if (!uiMetadata)
473
+ return null;
474
+ return {
475
+ pluginId: plugin.id,
476
+ pluginKey: plugin.pluginKey,
477
+ displayName: manifest.displayName,
478
+ version: plugin.version,
479
+ updatedAt: plugin.updatedAt.toISOString(),
480
+ uiEntryFile: uiMetadata.uiEntryFile,
481
+ slots: uiMetadata.slots,
482
+ launchers: uiMetadata.launchers,
483
+ };
484
+ })
485
+ .filter((item) => item !== null);
486
+ res.json(contributions);
487
+ });
488
+ // ===========================================================================
489
+ // Tool discovery and execution routes
490
+ // ===========================================================================
491
+ /**
492
+ * GET /api/plugins/tools
493
+ *
494
+ * List all available plugin-contributed tools in an agent-friendly format.
495
+ *
496
+ * Query params:
497
+ * - `pluginId` (optional): Filter to tools from a specific plugin
498
+ *
499
+ * Response: `AgentToolDescriptor[]`
500
+ * Errors: 501 if tool dispatcher is not configured
501
+ */
502
+ router.get("/plugins/tools", async (req, res) => {
503
+ assertBoardOrgAccess(req);
504
+ if (!toolDeps) {
505
+ res.status(501).json({ error: "Plugin tool dispatch is not enabled" });
506
+ return;
507
+ }
508
+ const pluginId = req.query.pluginId;
509
+ const filter = pluginId ? { pluginId } : undefined;
510
+ const tools = toolDeps.toolDispatcher.listToolsForAgent(filter);
511
+ res.json(tools);
512
+ });
513
+ /**
514
+ * POST /api/plugins/tools/execute
515
+ *
516
+ * Execute a plugin-contributed tool by its namespaced name.
517
+ *
518
+ * This is the primary endpoint used by the agent service to invoke
519
+ * plugin tools during an agent run.
520
+ *
521
+ * Request body:
522
+ * - `tool`: Fully namespaced tool name (e.g., "acme.linear:search-issues")
523
+ * - `parameters`: Parameters matching the tool's declared JSON Schema
524
+ * - `runContext`: Agent run context with agentId, runId, companyId, projectId
525
+ *
526
+ * Response: `ToolExecutionResult`
527
+ * Errors:
528
+ * - 400 if request validation fails
529
+ * - 404 if tool is not found
530
+ * - 501 if tool dispatcher is not configured
531
+ * - 502 if the plugin worker is unavailable or the RPC call fails
532
+ */
533
+ router.post("/plugins/tools/execute", async (req, res) => {
534
+ assertBoardOrgAccess(req);
535
+ if (!toolDeps) {
536
+ res.status(501).json({ error: "Plugin tool dispatch is not enabled" });
537
+ return;
538
+ }
539
+ const body = req.body;
540
+ if (!body) {
541
+ res.status(400).json({ error: "Request body is required" });
542
+ return;
543
+ }
544
+ const { tool, parameters, runContext } = body;
545
+ // Validate required fields
546
+ if (!tool || typeof tool !== "string") {
547
+ res.status(400).json({ error: '"tool" is required and must be a string' });
548
+ return;
549
+ }
550
+ if (!runContext || typeof runContext !== "object") {
551
+ res.status(400).json({ error: '"runContext" is required and must be an object' });
552
+ return;
553
+ }
554
+ if (!runContext.agentId || !runContext.runId || !runContext.companyId || !runContext.projectId) {
555
+ res.status(400).json({
556
+ error: '"runContext" must include agentId, runId, companyId, and projectId',
557
+ });
558
+ return;
559
+ }
560
+ assertCompanyAccess(req, runContext.companyId);
561
+ const scopeError = await validateToolRunContextScope(runContext);
562
+ if (scopeError) {
563
+ res.status(403).json({ error: scopeError });
564
+ return;
565
+ }
566
+ // Verify the tool exists
567
+ const registeredTool = toolDeps.toolDispatcher.getTool(tool);
568
+ if (!registeredTool) {
569
+ res.status(404).json({ error: `Tool "${tool}" not found` });
570
+ return;
571
+ }
572
+ try {
573
+ const result = await toolDeps.toolDispatcher.executeTool(tool, parameters ?? {}, runContext);
574
+ res.json(result);
575
+ }
576
+ catch (err) {
577
+ const message = err instanceof Error ? err.message : String(err);
578
+ // Distinguish between "worker not running" (502) and other errors (500)
579
+ if (message.includes("not running") || message.includes("worker")) {
580
+ res.status(502).json({ error: message });
581
+ }
582
+ else {
583
+ res.status(500).json({ error: message });
584
+ }
585
+ }
586
+ });
587
+ /**
588
+ * POST /api/plugins/install
589
+ *
590
+ * Install a plugin from npm or a local filesystem path.
591
+ *
592
+ * Instance-wide plugin installation is restricted to instance admins because
593
+ * the install flow fetches and inspects package contents on the host.
594
+ *
595
+ * Request body:
596
+ * - packageName: npm package name or local path (required)
597
+ * - version: Target version for npm packages (optional)
598
+ * - isLocalPath: Set true if packageName is a local path
599
+ *
600
+ * The installer:
601
+ * 1. Downloads from npm or loads from local path
602
+ * 2. Validates the manifest (schema + capability consistency)
603
+ * 3. Registers in the database
604
+ * 4. Transitions to `ready` state if no new capability approval is needed
605
+ *
606
+ * Response: `PluginRecord`
607
+ *
608
+ * Errors:
609
+ * - `400` — validation failure or install error (package not found, bad manifest, etc.)
610
+ * - `500` — installation succeeded but manifest is missing (indicates a loader bug)
611
+ */
612
+ router.post("/plugins/install", async (req, res) => {
613
+ assertInstanceAdmin(req);
614
+ const { packageName, version, isLocalPath } = req.body;
615
+ // Input validation
616
+ if (!packageName || typeof packageName !== "string") {
617
+ res.status(400).json({ error: "packageName is required and must be a string" });
618
+ return;
619
+ }
620
+ if (version !== undefined && typeof version !== "string") {
621
+ res.status(400).json({ error: "version must be a string if provided" });
622
+ return;
623
+ }
624
+ if (isLocalPath !== undefined && typeof isLocalPath !== "boolean") {
625
+ res.status(400).json({ error: "isLocalPath must be a boolean if provided" });
626
+ return;
627
+ }
628
+ // Validate package name format
629
+ const trimmedPackage = packageName.trim();
630
+ if (trimmedPackage.length === 0) {
631
+ res.status(400).json({ error: "packageName cannot be empty" });
632
+ return;
633
+ }
634
+ // Basic security check for package name (prevent injection)
635
+ if (!isLocalPath && /[<>:"|?*]/.test(trimmedPackage)) {
636
+ res.status(400).json({ error: "packageName contains invalid characters" });
637
+ return;
638
+ }
639
+ try {
640
+ const installOptions = isLocalPath
641
+ ? { localPath: trimmedPackage }
642
+ : { packageName: trimmedPackage, version: version?.trim() };
643
+ const discovered = await loader.installPlugin(installOptions);
644
+ if (!discovered.manifest) {
645
+ res.status(500).json({ error: "Plugin installed but manifest is missing" });
646
+ return;
647
+ }
648
+ // Transition to ready state
649
+ const existingPlugin = await registry.getByKey(discovered.manifest.id);
650
+ if (existingPlugin) {
651
+ await lifecycle.load(existingPlugin.id);
652
+ const updated = await registry.getById(existingPlugin.id);
653
+ await logPluginMutationActivity(req, "plugin.installed", existingPlugin.id, {
654
+ pluginId: existingPlugin.id,
655
+ pluginKey: existingPlugin.pluginKey,
656
+ packageName: updated?.packageName ?? existingPlugin.packageName,
657
+ version: updated?.version ?? existingPlugin.version,
658
+ source: isLocalPath ? "local_path" : "npm",
659
+ });
660
+ publishGlobalLiveEvent({ type: "plugin.ui.updated", payload: { pluginId: existingPlugin.id, action: "installed" } });
661
+ res.json(updated);
662
+ }
663
+ else {
664
+ // This shouldn't happen since installPlugin already registers in the DB
665
+ res.status(500).json({ error: "Plugin installed but not found in registry" });
666
+ }
667
+ }
668
+ catch (err) {
669
+ const message = err instanceof Error ? err.message : String(err);
670
+ res.status(400).json({ error: message });
671
+ }
672
+ });
673
+ /**
674
+ * Map a worker RPC error to a bridge-level error code.
675
+ *
676
+ * JsonRpcCallError carries numeric codes from the plugin RPC error code space.
677
+ * This helper maps them to the string error codes defined in PluginBridgeErrorCode.
678
+ *
679
+ * @see PLUGIN_SPEC.md §19.7 — Error Propagation Through The Bridge
680
+ */
681
+ function mapRpcErrorToBridgeError(err) {
682
+ if (err instanceof JsonRpcCallError) {
683
+ switch (err.code) {
684
+ case PLUGIN_RPC_ERROR_CODES.WORKER_UNAVAILABLE:
685
+ return {
686
+ code: "WORKER_UNAVAILABLE",
687
+ message: err.message,
688
+ details: err.data,
689
+ };
690
+ case PLUGIN_RPC_ERROR_CODES.CAPABILITY_DENIED:
691
+ return {
692
+ code: "CAPABILITY_DENIED",
693
+ message: err.message,
694
+ details: err.data,
695
+ };
696
+ case PLUGIN_RPC_ERROR_CODES.TIMEOUT:
697
+ return {
698
+ code: "TIMEOUT",
699
+ message: err.message,
700
+ details: err.data,
701
+ };
702
+ case PLUGIN_RPC_ERROR_CODES.WORKER_ERROR:
703
+ return {
704
+ code: "WORKER_ERROR",
705
+ message: err.message,
706
+ details: err.data,
707
+ };
708
+ default:
709
+ return {
710
+ code: "UNKNOWN",
711
+ message: err.message,
712
+ details: err.data,
713
+ };
714
+ }
715
+ }
716
+ const message = err instanceof Error ? err.message : String(err);
717
+ // Worker not running — surface as WORKER_UNAVAILABLE
718
+ if (message.includes("not running") || message.includes("not registered")) {
719
+ return {
720
+ code: "WORKER_UNAVAILABLE",
721
+ message,
722
+ };
723
+ }
724
+ return {
725
+ code: "UNKNOWN",
726
+ message,
727
+ };
728
+ }
729
+ /**
730
+ * POST /api/plugins/:pluginId/bridge/data
731
+ *
732
+ * Proxy a `getData` call from the plugin UI to the plugin worker.
733
+ *
734
+ * This is the server-side half of the `usePluginData(key, params)` bridge hook.
735
+ * The frontend sends a POST with the data key and optional params; the host
736
+ * forwards the call to the worker via the `getData` RPC method and returns
737
+ * the result.
738
+ *
739
+ * Request body:
740
+ * - `key`: Plugin-defined data key (e.g. `"sync-health"`)
741
+ * - `params`: Optional query parameters forwarded to the worker handler
742
+ *
743
+ * Response: The raw result from the worker's `getData` handler
744
+ *
745
+ * Error response body follows the `PluginBridgeError` shape:
746
+ * `{ code: PluginBridgeErrorCode, message: string, details?: unknown }`
747
+ *
748
+ * Errors:
749
+ * - 400 if request validation fails
750
+ * - 404 if plugin not found
751
+ * - 501 if bridge deps are not configured
752
+ * - 502 if the worker is unavailable or returns an error
753
+ *
754
+ * @see PLUGIN_SPEC.md §13.8 — `getData`
755
+ * @see PLUGIN_SPEC.md §19.7 — Error Propagation Through The Bridge
756
+ */
757
+ router.post("/plugins/:pluginId/bridge/data", async (req, res) => {
758
+ assertBoardOrgAccess(req);
759
+ if (!bridgeDeps) {
760
+ res.status(501).json({ error: "Plugin bridge is not enabled" });
761
+ return;
762
+ }
763
+ const { pluginId } = req.params;
764
+ // Resolve plugin
765
+ const plugin = await resolvePlugin(registry, pluginId);
766
+ if (!plugin) {
767
+ res.status(404).json({ error: "Plugin not found" });
768
+ return;
769
+ }
770
+ // Validate plugin is in ready state
771
+ if (plugin.status !== "ready") {
772
+ const bridgeError = {
773
+ code: "WORKER_UNAVAILABLE",
774
+ message: `Plugin is not ready (current status: ${plugin.status})`,
775
+ };
776
+ res.status(502).json(bridgeError);
777
+ return;
778
+ }
779
+ // Validate request body
780
+ const body = req.body;
781
+ if (!body || !body.key || typeof body.key !== "string") {
782
+ res.status(400).json({ error: '"key" is required and must be a string' });
783
+ return;
784
+ }
785
+ assertPluginBridgeScope(req, body.companyId);
786
+ try {
787
+ const result = await bridgeDeps.workerManager.call(plugin.id, "getData", {
788
+ key: body.key,
789
+ params: body.params ?? {},
790
+ renderEnvironment: body.renderEnvironment ?? null,
791
+ });
792
+ res.json({ data: result });
793
+ }
794
+ catch (err) {
795
+ const bridgeError = mapRpcErrorToBridgeError(err);
796
+ res.status(502).json(bridgeError);
797
+ }
798
+ });
799
+ /**
800
+ * POST /api/plugins/:pluginId/bridge/action
801
+ *
802
+ * Proxy a `performAction` call from the plugin UI to the plugin worker.
803
+ *
804
+ * This is the server-side half of the `usePluginAction(key)` bridge hook.
805
+ * The frontend sends a POST with the action key and optional params; the host
806
+ * forwards the call to the worker via the `performAction` RPC method and
807
+ * returns the result.
808
+ *
809
+ * Request body:
810
+ * - `key`: Plugin-defined action key (e.g. `"resync"`)
811
+ * - `params`: Optional parameters forwarded to the worker handler
812
+ *
813
+ * Response: The raw result from the worker's `performAction` handler
814
+ *
815
+ * Error response body follows the `PluginBridgeError` shape:
816
+ * `{ code: PluginBridgeErrorCode, message: string, details?: unknown }`
817
+ *
818
+ * Errors:
819
+ * - 400 if request validation fails
820
+ * - 404 if plugin not found
821
+ * - 501 if bridge deps are not configured
822
+ * - 502 if the worker is unavailable or returns an error
823
+ *
824
+ * @see PLUGIN_SPEC.md §13.9 — `performAction`
825
+ * @see PLUGIN_SPEC.md §19.7 — Error Propagation Through The Bridge
826
+ */
827
+ router.post("/plugins/:pluginId/bridge/action", async (req, res) => {
828
+ assertBoardOrgAccess(req);
829
+ if (!bridgeDeps) {
830
+ res.status(501).json({ error: "Plugin bridge is not enabled" });
831
+ return;
832
+ }
833
+ const { pluginId } = req.params;
834
+ // Resolve plugin
835
+ const plugin = await resolvePlugin(registry, pluginId);
836
+ if (!plugin) {
837
+ res.status(404).json({ error: "Plugin not found" });
838
+ return;
839
+ }
840
+ // Validate plugin is in ready state
841
+ if (plugin.status !== "ready") {
842
+ const bridgeError = {
843
+ code: "WORKER_UNAVAILABLE",
844
+ message: `Plugin is not ready (current status: ${plugin.status})`,
845
+ };
846
+ res.status(502).json(bridgeError);
847
+ return;
848
+ }
849
+ // Validate request body
850
+ const body = req.body;
851
+ if (!body || !body.key || typeof body.key !== "string") {
852
+ res.status(400).json({ error: '"key" is required and must be a string' });
853
+ return;
854
+ }
855
+ assertPluginBridgeScope(req, body.companyId);
856
+ try {
857
+ const result = await bridgeDeps.workerManager.call(plugin.id, "performAction", {
858
+ key: body.key,
859
+ params: body.params ?? {},
860
+ renderEnvironment: body.renderEnvironment ?? null,
861
+ });
862
+ res.json({ data: result });
863
+ }
864
+ catch (err) {
865
+ const bridgeError = mapRpcErrorToBridgeError(err);
866
+ res.status(502).json(bridgeError);
867
+ }
868
+ });
869
+ // ===========================================================================
870
+ // URL-keyed bridge routes (key as path parameter)
871
+ // ===========================================================================
872
+ /**
873
+ * POST /api/plugins/:pluginId/data/:key
874
+ *
875
+ * Proxy a `getData` call from the plugin UI to the plugin worker, with the
876
+ * data key specified as a URL path parameter instead of in the request body.
877
+ *
878
+ * This is a REST-friendly alternative to `POST /plugins/:pluginId/bridge/data`.
879
+ * The frontend bridge hooks use this endpoint for cleaner URLs.
880
+ *
881
+ * Request body (optional):
882
+ * - `params`: Optional query parameters forwarded to the worker handler
883
+ *
884
+ * Response: The raw result from the worker's `getData` handler wrapped as `{ data: T }`
885
+ *
886
+ * Error response body follows the `PluginBridgeError` shape:
887
+ * `{ code: PluginBridgeErrorCode, message: string, details?: unknown }`
888
+ *
889
+ * Errors:
890
+ * - 404 if plugin not found
891
+ * - 501 if bridge deps are not configured
892
+ * - 502 if the worker is unavailable or returns an error
893
+ *
894
+ * @see PLUGIN_SPEC.md §13.8 — `getData`
895
+ * @see PLUGIN_SPEC.md §19.7 — Error Propagation Through The Bridge
896
+ */
897
+ router.post("/plugins/:pluginId/data/:key", async (req, res) => {
898
+ assertBoardOrgAccess(req);
899
+ if (!bridgeDeps) {
900
+ res.status(501).json({ error: "Plugin bridge is not enabled" });
901
+ return;
902
+ }
903
+ const { pluginId, key } = req.params;
904
+ // Resolve plugin
905
+ const plugin = await resolvePlugin(registry, pluginId);
906
+ if (!plugin) {
907
+ res.status(404).json({ error: "Plugin not found" });
908
+ return;
909
+ }
910
+ // Validate plugin is in ready state
911
+ if (plugin.status !== "ready") {
912
+ const bridgeError = {
913
+ code: "WORKER_UNAVAILABLE",
914
+ message: `Plugin is not ready (current status: ${plugin.status})`,
915
+ };
916
+ res.status(502).json(bridgeError);
917
+ return;
918
+ }
919
+ const body = req.body;
920
+ assertPluginBridgeScope(req, body?.companyId);
921
+ try {
922
+ const result = await bridgeDeps.workerManager.call(plugin.id, "getData", {
923
+ key,
924
+ params: body?.params ?? {},
925
+ renderEnvironment: body?.renderEnvironment ?? null,
926
+ });
927
+ res.json({ data: result });
928
+ }
929
+ catch (err) {
930
+ const bridgeError = mapRpcErrorToBridgeError(err);
931
+ res.status(502).json(bridgeError);
932
+ }
933
+ });
934
+ /**
935
+ * POST /api/plugins/:pluginId/actions/:key
936
+ *
937
+ * Proxy a `performAction` call from the plugin UI to the plugin worker, with
938
+ * the action key specified as a URL path parameter instead of in the request body.
939
+ *
940
+ * This is a REST-friendly alternative to `POST /plugins/:pluginId/bridge/action`.
941
+ * The frontend bridge hooks use this endpoint for cleaner URLs.
942
+ *
943
+ * Request body (optional):
944
+ * - `params`: Optional parameters forwarded to the worker handler
945
+ *
946
+ * Response: The raw result from the worker's `performAction` handler wrapped as `{ data: T }`
947
+ *
948
+ * Error response body follows the `PluginBridgeError` shape:
949
+ * `{ code: PluginBridgeErrorCode, message: string, details?: unknown }`
950
+ *
951
+ * Errors:
952
+ * - 404 if plugin not found
953
+ * - 501 if bridge deps are not configured
954
+ * - 502 if the worker is unavailable or returns an error
955
+ *
956
+ * @see PLUGIN_SPEC.md §13.9 — `performAction`
957
+ * @see PLUGIN_SPEC.md §19.7 — Error Propagation Through The Bridge
958
+ */
959
+ router.post("/plugins/:pluginId/actions/:key", async (req, res) => {
960
+ assertBoardOrgAccess(req);
961
+ if (!bridgeDeps) {
962
+ res.status(501).json({ error: "Plugin bridge is not enabled" });
963
+ return;
964
+ }
965
+ const { pluginId, key } = req.params;
966
+ // Resolve plugin
967
+ const plugin = await resolvePlugin(registry, pluginId);
968
+ if (!plugin) {
969
+ res.status(404).json({ error: "Plugin not found" });
970
+ return;
971
+ }
972
+ // Validate plugin is in ready state
973
+ if (plugin.status !== "ready") {
974
+ const bridgeError = {
975
+ code: "WORKER_UNAVAILABLE",
976
+ message: `Plugin is not ready (current status: ${plugin.status})`,
977
+ };
978
+ res.status(502).json(bridgeError);
979
+ return;
980
+ }
981
+ const body = req.body;
982
+ assertPluginBridgeScope(req, body?.companyId);
983
+ try {
984
+ const result = await bridgeDeps.workerManager.call(plugin.id, "performAction", {
985
+ key,
986
+ params: body?.params ?? {},
987
+ renderEnvironment: body?.renderEnvironment ?? null,
988
+ });
989
+ res.json({ data: result });
990
+ }
991
+ catch (err) {
992
+ const bridgeError = mapRpcErrorToBridgeError(err);
993
+ res.status(502).json(bridgeError);
994
+ }
995
+ });
996
+ // ===========================================================================
997
+ // SSE stream bridge route
998
+ // ===========================================================================
999
+ /**
1000
+ * GET /api/plugins/:pluginId/bridge/stream/:channel
1001
+ *
1002
+ * Server-Sent Events endpoint for real-time streaming from plugin worker to UI.
1003
+ *
1004
+ * The worker pushes events via `ctx.streams.emit(channel, event)` which arrive
1005
+ * as JSON-RPC notifications to the host, get published on the PluginStreamBus,
1006
+ * and are fanned out to all connected SSE clients matching (pluginId, channel,
1007
+ * companyId).
1008
+ *
1009
+ * Query parameters:
1010
+ * - `companyId` (required): Scope events to a specific company
1011
+ *
1012
+ * SSE event types:
1013
+ * - `message`: A data event from the worker (default)
1014
+ * - `open`: The worker opened the stream channel
1015
+ * - `close`: The worker closed the stream channel — client should disconnect
1016
+ *
1017
+ * Errors:
1018
+ * - 400 if companyId is missing
1019
+ * - 404 if plugin not found
1020
+ * - 501 if bridge deps or stream bus are not configured
1021
+ */
1022
+ router.get("/plugins/:pluginId/bridge/stream/:channel", async (req, res) => {
1023
+ assertBoardOrgAccess(req);
1024
+ if (!bridgeDeps?.streamBus) {
1025
+ res.status(501).json({ error: "Plugin stream bridge is not enabled" });
1026
+ return;
1027
+ }
1028
+ const { pluginId, channel } = req.params;
1029
+ const companyId = req.query.companyId;
1030
+ if (!companyId) {
1031
+ res.status(400).json({ error: '"companyId" query parameter is required' });
1032
+ return;
1033
+ }
1034
+ const plugin = await resolvePlugin(registry, pluginId);
1035
+ if (!plugin) {
1036
+ res.status(404).json({ error: "Plugin not found" });
1037
+ return;
1038
+ }
1039
+ assertCompanyAccess(req, companyId);
1040
+ // Set SSE headers
1041
+ res.writeHead(200, {
1042
+ "Content-Type": "text/event-stream",
1043
+ "Cache-Control": "no-cache",
1044
+ "Connection": "keep-alive",
1045
+ "X-Accel-Buffering": "no",
1046
+ });
1047
+ res.flushHeaders();
1048
+ // Send initial comment to establish the connection
1049
+ res.write(":ok\n\n");
1050
+ let unsubscribed = false;
1051
+ const safeUnsubscribe = () => {
1052
+ if (!unsubscribed) {
1053
+ unsubscribed = true;
1054
+ unsubscribe();
1055
+ }
1056
+ };
1057
+ const unsubscribe = bridgeDeps.streamBus.subscribe(plugin.id, channel, companyId, (event, eventType) => {
1058
+ if (unsubscribed || !res.writable)
1059
+ return;
1060
+ try {
1061
+ if (eventType !== "message") {
1062
+ res.write(`event: ${eventType}\n`);
1063
+ }
1064
+ res.write(`data: ${JSON.stringify(event)}\n\n`);
1065
+ }
1066
+ catch {
1067
+ // Connection closed or write error — stop delivering
1068
+ safeUnsubscribe();
1069
+ }
1070
+ });
1071
+ req.on("close", safeUnsubscribe);
1072
+ res.on("error", safeUnsubscribe);
1073
+ });
1074
+ router.use("/plugins/:pluginId/api", async (req, res) => {
1075
+ if (!bridgeDeps) {
1076
+ res.status(501).json({ error: "Plugin scoped API routes are not enabled" });
1077
+ return;
1078
+ }
1079
+ const { pluginId } = req.params;
1080
+ const plugin = await resolvePlugin(registry, pluginId);
1081
+ if (!plugin) {
1082
+ res.status(404).json({ error: "Plugin not found" });
1083
+ return;
1084
+ }
1085
+ if (plugin.status !== "ready") {
1086
+ res.status(503).json({ error: `Plugin is not ready (current status: ${plugin.status})` });
1087
+ return;
1088
+ }
1089
+ const isWorkerRunning = typeof bridgeDeps.workerManager.isRunning === "function"
1090
+ ? bridgeDeps.workerManager.isRunning(plugin.id)
1091
+ : true;
1092
+ if (!isWorkerRunning) {
1093
+ res.status(503).json({ error: "Plugin worker is not running" });
1094
+ return;
1095
+ }
1096
+ if (!plugin.manifestJson.capabilities.includes("api.routes.register")) {
1097
+ res.status(404).json({ error: "Plugin does not expose scoped API routes" });
1098
+ return;
1099
+ }
1100
+ const requestPath = req.path || "/";
1101
+ const routes = plugin.manifestJson.apiRoutes ?? [];
1102
+ const match = routes
1103
+ .map((route) => ({ route, params: matchScopedApiRoute(route, req.method, requestPath) }))
1104
+ .find((candidate) => candidate.params !== null);
1105
+ if (!match || !match.params) {
1106
+ res.status(404).json({ error: "Plugin API route not found" });
1107
+ return;
1108
+ }
1109
+ try {
1110
+ assertScopedApiAuth(req, match.route);
1111
+ const companyId = await resolveScopedApiCompanyId(match.route, match.params, req);
1112
+ if (!companyId) {
1113
+ res.status(400).json({ error: "Unable to resolve company for plugin API route" });
1114
+ return;
1115
+ }
1116
+ assertCompanyAccess(req, companyId);
1117
+ await enforceScopedApiCheckout(req, match.route, match.params, companyId);
1118
+ if (req.method !== "GET" && req.headers["content-type"] && !req.is("application/json")) {
1119
+ res.status(415).json({ error: "Plugin API routes accept JSON requests only" });
1120
+ return;
1121
+ }
1122
+ const requestBody = req.body ?? null;
1123
+ const bodySize = Buffer.byteLength(JSON.stringify(requestBody));
1124
+ if (bodySize > PLUGIN_API_BODY_LIMIT_BYTES) {
1125
+ res.status(413).json({ error: "Plugin API request body is too large" });
1126
+ return;
1127
+ }
1128
+ const actor = getActorInfo(req);
1129
+ const input = {
1130
+ routeKey: match.route.routeKey,
1131
+ method: req.method,
1132
+ path: requestPath,
1133
+ params: match.params,
1134
+ query: normalizeQuery(req.query),
1135
+ body: requestBody,
1136
+ actor: {
1137
+ actorType: actor.actorType,
1138
+ actorId: actor.actorId,
1139
+ agentId: actor.agentId,
1140
+ userId: actor.actorType === "user" ? actor.actorId : null,
1141
+ runId: actor.runId,
1142
+ },
1143
+ companyId,
1144
+ headers: sanitizePluginRequestHeaders(req),
1145
+ };
1146
+ const result = await bridgeDeps.workerManager.call(plugin.id, "handleApiRequest", input);
1147
+ const status = Number.isInteger(result.status) && Number(result.status) >= 200 && Number(result.status) <= 599
1148
+ ? Number(result.status)
1149
+ : 200;
1150
+ applyPluginScopedApiResponseHeaders(res, result.headers);
1151
+ if (status === 204) {
1152
+ res.status(status).end();
1153
+ }
1154
+ else {
1155
+ res.status(status).json(result.body ?? null);
1156
+ }
1157
+ }
1158
+ catch (err) {
1159
+ const status = typeof err.status === "number"
1160
+ ? err.status
1161
+ : err instanceof JsonRpcCallError && err.code === PLUGIN_RPC_ERROR_CODES.CAPABILITY_DENIED
1162
+ ? 403
1163
+ : err instanceof JsonRpcCallError && err.code === PLUGIN_RPC_ERROR_CODES.METHOD_NOT_IMPLEMENTED
1164
+ ? 501
1165
+ : err instanceof JsonRpcCallError
1166
+ ? 502
1167
+ : 500;
1168
+ res.status(status).json({
1169
+ error: err instanceof Error ? err.message : String(err),
1170
+ });
1171
+ }
1172
+ });
1173
+ /**
1174
+ * GET /api/plugins/:pluginId
1175
+ *
1176
+ * Get detailed information about a single plugin.
1177
+ *
1178
+ * The :pluginId parameter accepts either:
1179
+ * - Database UUID (e.g., "abc123-def456")
1180
+ * - Plugin key (e.g., "acme.linear")
1181
+ *
1182
+ * Response: PluginRecord
1183
+ * Errors: 404 if plugin not found
1184
+ */
1185
+ router.get("/plugins/:pluginId", async (req, res) => {
1186
+ assertBoardOrgAccess(req);
1187
+ const { pluginId } = req.params;
1188
+ const plugin = await resolvePlugin(registry, pluginId);
1189
+ if (!plugin) {
1190
+ res.status(404).json({ error: "Plugin not found" });
1191
+ return;
1192
+ }
1193
+ // Enrich with worker capabilities when available
1194
+ const worker = bridgeDeps?.workerManager.getWorker(plugin.id);
1195
+ const supportsConfigTest = worker
1196
+ ? worker.supportedMethods.includes("validateConfig")
1197
+ : false;
1198
+ res.json({ ...plugin, supportsConfigTest });
1199
+ });
1200
+ /**
1201
+ * DELETE /api/plugins/:pluginId
1202
+ *
1203
+ * Uninstall a plugin.
1204
+ *
1205
+ * Query params:
1206
+ * - purge: If "true", permanently delete all plugin data (hard delete)
1207
+ * Otherwise, soft-delete with 30-day data retention
1208
+ *
1209
+ * Response: PluginRecord (the deleted record)
1210
+ * Errors: 404 if plugin not found, 400 for lifecycle errors
1211
+ */
1212
+ router.delete("/plugins/:pluginId", async (req, res) => {
1213
+ assertInstanceAdmin(req);
1214
+ const { pluginId } = req.params;
1215
+ const purge = req.query.purge === "true";
1216
+ const plugin = await resolvePlugin(registry, pluginId);
1217
+ if (!plugin) {
1218
+ res.status(404).json({ error: "Plugin not found" });
1219
+ return;
1220
+ }
1221
+ try {
1222
+ const result = await lifecycle.unload(plugin.id, purge);
1223
+ await logPluginMutationActivity(req, "plugin.uninstalled", plugin.id, {
1224
+ pluginId: plugin.id,
1225
+ pluginKey: plugin.pluginKey,
1226
+ purge,
1227
+ });
1228
+ publishGlobalLiveEvent({ type: "plugin.ui.updated", payload: { pluginId: plugin.id, action: "uninstalled" } });
1229
+ res.json(result);
1230
+ }
1231
+ catch (err) {
1232
+ const message = err instanceof Error ? err.message : String(err);
1233
+ res.status(400).json({ error: message });
1234
+ }
1235
+ });
1236
+ /**
1237
+ * POST /api/plugins/:pluginId/enable
1238
+ *
1239
+ * Enable a plugin that is currently disabled or in error state.
1240
+ *
1241
+ * Transitions the plugin to 'ready' state after loading and validation.
1242
+ *
1243
+ * Response: PluginRecord
1244
+ * Errors: 404 if plugin not found, 400 for lifecycle errors
1245
+ */
1246
+ router.post("/plugins/:pluginId/enable", async (req, res) => {
1247
+ assertInstanceAdmin(req);
1248
+ const { pluginId } = req.params;
1249
+ const plugin = await resolvePlugin(registry, pluginId);
1250
+ if (!plugin) {
1251
+ res.status(404).json({ error: "Plugin not found" });
1252
+ return;
1253
+ }
1254
+ try {
1255
+ const result = await lifecycle.enable(plugin.id);
1256
+ await logPluginMutationActivity(req, "plugin.enabled", plugin.id, {
1257
+ pluginId: plugin.id,
1258
+ pluginKey: plugin.pluginKey,
1259
+ version: result?.version ?? plugin.version,
1260
+ });
1261
+ publishGlobalLiveEvent({ type: "plugin.ui.updated", payload: { pluginId: plugin.id, action: "enabled" } });
1262
+ res.json(result);
1263
+ }
1264
+ catch (err) {
1265
+ const message = err instanceof Error ? err.message : String(err);
1266
+ res.status(400).json({ error: message });
1267
+ }
1268
+ });
1269
+ /**
1270
+ * POST /api/plugins/:pluginId/disable
1271
+ *
1272
+ * Disable a running plugin.
1273
+ *
1274
+ * Request body (optional):
1275
+ * - reason: Human-readable reason for disabling
1276
+ *
1277
+ * The plugin transitions to 'installed' state and stops processing events.
1278
+ *
1279
+ * Response: PluginRecord
1280
+ * Errors: 404 if plugin not found, 400 for lifecycle errors
1281
+ */
1282
+ router.post("/plugins/:pluginId/disable", async (req, res) => {
1283
+ assertInstanceAdmin(req);
1284
+ const { pluginId } = req.params;
1285
+ const body = req.body;
1286
+ const reason = body?.reason;
1287
+ const plugin = await resolvePlugin(registry, pluginId);
1288
+ if (!plugin) {
1289
+ res.status(404).json({ error: "Plugin not found" });
1290
+ return;
1291
+ }
1292
+ try {
1293
+ const result = await lifecycle.disable(plugin.id, reason);
1294
+ await logPluginMutationActivity(req, "plugin.disabled", plugin.id, {
1295
+ pluginId: plugin.id,
1296
+ pluginKey: plugin.pluginKey,
1297
+ reason: reason ?? null,
1298
+ });
1299
+ publishGlobalLiveEvent({ type: "plugin.ui.updated", payload: { pluginId: plugin.id, action: "disabled" } });
1300
+ res.json(result);
1301
+ }
1302
+ catch (err) {
1303
+ const message = err instanceof Error ? err.message : String(err);
1304
+ res.status(400).json({ error: message });
1305
+ }
1306
+ });
1307
+ /**
1308
+ * GET /api/plugins/:pluginId/health
1309
+ *
1310
+ * Run health diagnostics on a plugin.
1311
+ *
1312
+ * Performs the following checks:
1313
+ * 1. Registry: Plugin is registered in the database
1314
+ * 2. Manifest: Manifest is valid and parseable
1315
+ * 3. Status: Plugin is in 'ready' state
1316
+ * 4. Error state: Plugin has no unhandled errors
1317
+ *
1318
+ * Response: PluginHealthCheckResult
1319
+ * Errors: 404 if plugin not found
1320
+ */
1321
+ router.get("/plugins/:pluginId/health", async (req, res) => {
1322
+ assertBoardOrgAccess(req);
1323
+ const { pluginId } = req.params;
1324
+ const plugin = await resolvePlugin(registry, pluginId);
1325
+ if (!plugin) {
1326
+ res.status(404).json({ error: "Plugin not found" });
1327
+ return;
1328
+ }
1329
+ const checks = [];
1330
+ // Check 1: Plugin is registered
1331
+ checks.push({
1332
+ name: "registry",
1333
+ passed: true,
1334
+ message: "Plugin found in registry",
1335
+ });
1336
+ // Check 2: Manifest is valid
1337
+ const hasValidManifest = Boolean(plugin.manifestJson?.id);
1338
+ checks.push({
1339
+ name: "manifest",
1340
+ passed: hasValidManifest,
1341
+ message: hasValidManifest ? "Manifest is valid" : "Manifest is invalid or missing",
1342
+ });
1343
+ // Check 3: Plugin status
1344
+ const isHealthy = plugin.status === "ready";
1345
+ checks.push({
1346
+ name: "status",
1347
+ passed: isHealthy,
1348
+ message: `Current status: ${plugin.status}`,
1349
+ });
1350
+ // Check 4: No last error
1351
+ const hasNoError = !plugin.lastError;
1352
+ if (!hasNoError) {
1353
+ checks.push({
1354
+ name: "error_state",
1355
+ passed: false,
1356
+ message: plugin.lastError ?? undefined,
1357
+ });
1358
+ }
1359
+ const result = {
1360
+ pluginId: plugin.id,
1361
+ status: plugin.status,
1362
+ healthy: isHealthy && hasValidManifest && hasNoError,
1363
+ checks,
1364
+ lastError: plugin.lastError ?? undefined,
1365
+ };
1366
+ res.json(result);
1367
+ });
1368
+ /**
1369
+ * GET /api/plugins/:pluginId/logs
1370
+ *
1371
+ * Query recent log entries for a plugin.
1372
+ *
1373
+ * Query params:
1374
+ * - limit: Maximum number of entries (default 25, max 500)
1375
+ * - level: Filter by log level (info, warn, error, debug)
1376
+ * - since: ISO timestamp to filter logs newer than this time
1377
+ *
1378
+ * Response: Array of log entries, newest first.
1379
+ */
1380
+ router.get("/plugins/:pluginId/logs", async (req, res) => {
1381
+ assertBoardOrgAccess(req);
1382
+ const { pluginId } = req.params;
1383
+ const plugin = await resolvePlugin(registry, pluginId);
1384
+ if (!plugin) {
1385
+ res.status(404).json({ error: "Plugin not found" });
1386
+ return;
1387
+ }
1388
+ const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 25, 1), 500);
1389
+ const level = req.query.level;
1390
+ const since = req.query.since;
1391
+ const conditions = [eq(pluginLogs.pluginId, plugin.id)];
1392
+ if (level) {
1393
+ conditions.push(eq(pluginLogs.level, level));
1394
+ }
1395
+ if (since) {
1396
+ const sinceDate = new Date(since);
1397
+ if (!isNaN(sinceDate.getTime())) {
1398
+ conditions.push(gte(pluginLogs.createdAt, sinceDate));
1399
+ }
1400
+ }
1401
+ const rows = await db
1402
+ .select()
1403
+ .from(pluginLogs)
1404
+ .where(and(...conditions))
1405
+ .orderBy(desc(pluginLogs.createdAt))
1406
+ .limit(limit);
1407
+ res.json(rows);
1408
+ });
1409
+ /**
1410
+ * POST /api/plugins/:pluginId/upgrade
1411
+ *
1412
+ * Upgrade a plugin to a newer version.
1413
+ *
1414
+ * Upgrades are restricted to instance admins because they fetch and inspect
1415
+ * new package contents on the host before activation.
1416
+ *
1417
+ * Request body (optional):
1418
+ * - version: Target version (defaults to latest)
1419
+ *
1420
+ * If the upgrade adds new capabilities, the plugin transitions to
1421
+ * 'upgrade_pending' state for board approval. Otherwise, it goes
1422
+ * directly to 'ready'.
1423
+ *
1424
+ * Response: PluginRecord
1425
+ * Errors: 404 if plugin not found, 400 for lifecycle errors
1426
+ */
1427
+ router.post("/plugins/:pluginId/upgrade", async (req, res) => {
1428
+ assertInstanceAdmin(req);
1429
+ const { pluginId } = req.params;
1430
+ const body = req.body;
1431
+ const version = body?.version;
1432
+ const plugin = await resolvePlugin(registry, pluginId);
1433
+ if (!plugin) {
1434
+ res.status(404).json({ error: "Plugin not found" });
1435
+ return;
1436
+ }
1437
+ try {
1438
+ // Upgrade the plugin - this would typically:
1439
+ // 1. Download the new version
1440
+ // 2. Compare capabilities
1441
+ // 3. If new capabilities, mark as upgrade_pending
1442
+ // 4. Otherwise, transition to ready
1443
+ const result = await lifecycle.upgrade(plugin.id, version);
1444
+ await logPluginMutationActivity(req, "plugin.upgraded", plugin.id, {
1445
+ pluginId: plugin.id,
1446
+ pluginKey: plugin.pluginKey,
1447
+ previousVersion: plugin.version,
1448
+ version: result?.version ?? plugin.version,
1449
+ targetVersion: version ?? null,
1450
+ });
1451
+ publishGlobalLiveEvent({ type: "plugin.ui.updated", payload: { pluginId: plugin.id, action: "upgraded" } });
1452
+ res.json(result);
1453
+ }
1454
+ catch (err) {
1455
+ const message = err instanceof Error ? err.message : String(err);
1456
+ res.status(400).json({ error: message });
1457
+ }
1458
+ });
1459
+ // ===========================================================================
1460
+ // Plugin configuration routes
1461
+ // ===========================================================================
1462
+ /**
1463
+ * GET /api/plugins/:pluginId/config
1464
+ *
1465
+ * Retrieve the current instance configuration for a plugin.
1466
+ *
1467
+ * Returns the `PluginConfig` record if one exists, or `null` if the plugin
1468
+ * has not yet been configured.
1469
+ *
1470
+ * Response: `PluginConfig | null`
1471
+ * Errors: 404 if plugin not found
1472
+ */
1473
+ router.get("/plugins/:pluginId/config", async (req, res) => {
1474
+ assertBoardOrgAccess(req);
1475
+ const { pluginId } = req.params;
1476
+ const plugin = await resolvePlugin(registry, pluginId);
1477
+ if (!plugin) {
1478
+ res.status(404).json({ error: "Plugin not found" });
1479
+ return;
1480
+ }
1481
+ const config = await registry.getConfig(plugin.id);
1482
+ res.json(config);
1483
+ });
1484
+ /**
1485
+ * POST /api/plugins/:pluginId/config
1486
+ *
1487
+ * Save (create or replace) the instance configuration for a plugin.
1488
+ *
1489
+ * The caller provides the full `configJson` object. The server persists it
1490
+ * via `registry.upsertConfig()`.
1491
+ *
1492
+ * Request body:
1493
+ * - `configJson`: Configuration values matching the plugin's `instanceConfigSchema`
1494
+ *
1495
+ * Response: `PluginConfig`
1496
+ * Errors:
1497
+ * - 400 if request validation fails
1498
+ * - 404 if plugin not found
1499
+ */
1500
+ router.post("/plugins/:pluginId/config", async (req, res) => {
1501
+ assertInstanceAdmin(req);
1502
+ const { pluginId } = req.params;
1503
+ const plugin = await resolvePlugin(registry, pluginId);
1504
+ if (!plugin) {
1505
+ res.status(404).json({ error: "Plugin not found" });
1506
+ return;
1507
+ }
1508
+ const body = req.body;
1509
+ if (!body?.configJson || typeof body.configJson !== "object") {
1510
+ res.status(400).json({ error: '"configJson" is required and must be an object' });
1511
+ return;
1512
+ }
1513
+ // Strip devUiUrl unless the caller is an instance admin. devUiUrl activates
1514
+ // a dev-proxy in the static file route that could be abused for SSRF if any
1515
+ // board-level user were allowed to set it.
1516
+ if ("devUiUrl" in body.configJson &&
1517
+ !(req.actor.type === "board" && req.actor.isInstanceAdmin)) {
1518
+ delete body.configJson.devUiUrl;
1519
+ }
1520
+ // Validate configJson against the plugin's instanceConfigSchema (if declared).
1521
+ // This ensures CLI/API callers get the same validation the UI performs client-side.
1522
+ const schema = plugin.manifestJson?.instanceConfigSchema;
1523
+ if (schema && Object.keys(schema).length > 0) {
1524
+ const validation = validateInstanceConfig(body.configJson, schema);
1525
+ if (!validation.valid) {
1526
+ res.status(400).json({
1527
+ error: "Configuration does not match the plugin's instanceConfigSchema",
1528
+ fieldErrors: validation.errors,
1529
+ });
1530
+ return;
1531
+ }
1532
+ }
1533
+ try {
1534
+ const result = await registry.upsertConfig(plugin.id, {
1535
+ configJson: body.configJson,
1536
+ });
1537
+ await logPluginMutationActivity(req, "plugin.config.updated", plugin.id, {
1538
+ pluginId: plugin.id,
1539
+ pluginKey: plugin.pluginKey,
1540
+ configKeyCount: Object.keys(body.configJson).length,
1541
+ });
1542
+ // Notify the running worker about the config change (PLUGIN_SPEC §25.4.4).
1543
+ // If the worker implements onConfigChanged, send the new config via RPC.
1544
+ // If it doesn't (METHOD_NOT_IMPLEMENTED), restart the worker so it picks
1545
+ // up the new config on re-initialize. If no worker is running, skip.
1546
+ if (bridgeDeps?.workerManager.isRunning(plugin.id)) {
1547
+ try {
1548
+ await bridgeDeps.workerManager.call(plugin.id, "configChanged", { config: body.configJson });
1549
+ }
1550
+ catch (rpcErr) {
1551
+ if (rpcErr instanceof JsonRpcCallError &&
1552
+ rpcErr.code === PLUGIN_RPC_ERROR_CODES.METHOD_NOT_IMPLEMENTED) {
1553
+ // Worker doesn't handle live config — restart it.
1554
+ try {
1555
+ await lifecycle.restartWorker(plugin.id);
1556
+ }
1557
+ catch {
1558
+ // Restart failure is non-fatal for the config save response.
1559
+ }
1560
+ }
1561
+ // Other RPC errors (timeout, unavailable) are non-fatal — config is
1562
+ // already persisted and will take effect on next worker restart.
1563
+ }
1564
+ }
1565
+ res.json(result);
1566
+ }
1567
+ catch (err) {
1568
+ const message = err instanceof Error ? err.message : String(err);
1569
+ res.status(400).json({ error: message });
1570
+ }
1571
+ });
1572
+ /**
1573
+ * POST /api/plugins/:pluginId/config/test
1574
+ *
1575
+ * Test a plugin configuration without persisting it by calling the plugin
1576
+ * worker's `validateConfig` RPC method.
1577
+ *
1578
+ * Only works when the plugin's worker implements `onValidateConfig`.
1579
+ * If the worker does not implement the method, returns
1580
+ * `{ valid: false, supported: false, message: "..." }` with HTTP 200.
1581
+ *
1582
+ * Request body:
1583
+ * - `configJson`: Configuration values to validate
1584
+ *
1585
+ * Response: `{ valid: boolean; message?: string; supported?: boolean }`
1586
+ * Errors:
1587
+ * - 400 if request validation fails
1588
+ * - 404 if plugin not found
1589
+ * - 501 if bridge deps (worker manager) are not configured
1590
+ * - 502 if the worker is unavailable
1591
+ */
1592
+ router.post("/plugins/:pluginId/config/test", async (req, res) => {
1593
+ assertBoardOrgAccess(req);
1594
+ if (!bridgeDeps) {
1595
+ res.status(501).json({ error: "Plugin bridge is not enabled" });
1596
+ return;
1597
+ }
1598
+ const { pluginId } = req.params;
1599
+ const plugin = await resolvePlugin(registry, pluginId);
1600
+ if (!plugin) {
1601
+ res.status(404).json({ error: "Plugin not found" });
1602
+ return;
1603
+ }
1604
+ if (plugin.status !== "ready") {
1605
+ res.status(400).json({
1606
+ error: `Plugin is not ready (current status: ${plugin.status})`,
1607
+ });
1608
+ return;
1609
+ }
1610
+ const body = req.body;
1611
+ if (!body?.configJson || typeof body.configJson !== "object") {
1612
+ res.status(400).json({ error: '"configJson" is required and must be an object' });
1613
+ return;
1614
+ }
1615
+ // Fast schema-level rejection before hitting the worker RPC.
1616
+ const schema = plugin.manifestJson?.instanceConfigSchema;
1617
+ if (schema && Object.keys(schema).length > 0) {
1618
+ const validation = validateInstanceConfig(body.configJson, schema);
1619
+ if (!validation.valid) {
1620
+ res.status(400).json({
1621
+ error: "Configuration does not match the plugin's instanceConfigSchema",
1622
+ fieldErrors: validation.errors,
1623
+ });
1624
+ return;
1625
+ }
1626
+ }
1627
+ try {
1628
+ const result = await bridgeDeps.workerManager.call(plugin.id, "validateConfig", { config: body.configJson });
1629
+ // The worker returns PluginConfigValidationResult { ok, warnings?, errors? }
1630
+ // Map to the frontend-expected shape { valid, message? }
1631
+ if (result.ok) {
1632
+ const warningText = result.warnings?.length
1633
+ ? `Warnings: ${result.warnings.join("; ")}`
1634
+ : undefined;
1635
+ res.json({ valid: true, message: warningText });
1636
+ }
1637
+ else {
1638
+ const errorText = result.errors?.length
1639
+ ? result.errors.join("; ")
1640
+ : "Configuration validation failed.";
1641
+ res.json({ valid: false, message: errorText });
1642
+ }
1643
+ }
1644
+ catch (err) {
1645
+ // If the worker does not implement validateConfig, return a structured response
1646
+ if (err instanceof JsonRpcCallError &&
1647
+ err.code === PLUGIN_RPC_ERROR_CODES.METHOD_NOT_IMPLEMENTED) {
1648
+ res.json({
1649
+ valid: false,
1650
+ supported: false,
1651
+ message: "This plugin does not support configuration testing.",
1652
+ });
1653
+ return;
1654
+ }
1655
+ // Worker unavailable or other RPC errors
1656
+ const bridgeError = mapRpcErrorToBridgeError(err);
1657
+ res.status(502).json(bridgeError);
1658
+ }
1659
+ });
1660
+ // ===========================================================================
1661
+ // Job scheduling routes
1662
+ // ===========================================================================
1663
+ /**
1664
+ * GET /api/plugins/:pluginId/jobs
1665
+ *
1666
+ * List all scheduled jobs for a plugin.
1667
+ *
1668
+ * Query params:
1669
+ * - `status` (optional): Filter by job status (`active`, `paused`, `failed`)
1670
+ *
1671
+ * Response: PluginJobRecord[]
1672
+ * Errors: 404 if plugin not found
1673
+ */
1674
+ router.get("/plugins/:pluginId/jobs", async (req, res) => {
1675
+ assertBoardOrgAccess(req);
1676
+ if (!jobDeps) {
1677
+ res.status(501).json({ error: "Job scheduling is not enabled" });
1678
+ return;
1679
+ }
1680
+ const { pluginId } = req.params;
1681
+ const plugin = await resolvePlugin(registry, pluginId);
1682
+ if (!plugin) {
1683
+ res.status(404).json({ error: "Plugin not found" });
1684
+ return;
1685
+ }
1686
+ const rawStatus = req.query.status;
1687
+ const validStatuses = ["active", "paused", "failed"];
1688
+ if (rawStatus !== undefined && !validStatuses.includes(rawStatus)) {
1689
+ res.status(400).json({
1690
+ error: `Invalid status '${rawStatus}'. Must be one of: ${validStatuses.join(", ")}`,
1691
+ });
1692
+ return;
1693
+ }
1694
+ try {
1695
+ const jobs = await jobDeps.jobStore.listJobs(plugin.id, rawStatus);
1696
+ res.json(jobs);
1697
+ }
1698
+ catch (err) {
1699
+ const message = err instanceof Error ? err.message : String(err);
1700
+ res.status(500).json({ error: message });
1701
+ }
1702
+ });
1703
+ /**
1704
+ * GET /api/plugins/:pluginId/jobs/:jobId/runs
1705
+ *
1706
+ * List execution history for a specific job.
1707
+ *
1708
+ * Query params:
1709
+ * - `limit` (optional): Maximum number of runs to return (default: 50)
1710
+ *
1711
+ * Response: PluginJobRunRecord[]
1712
+ * Errors: 404 if plugin not found
1713
+ */
1714
+ router.get("/plugins/:pluginId/jobs/:jobId/runs", async (req, res) => {
1715
+ assertBoardOrgAccess(req);
1716
+ if (!jobDeps) {
1717
+ res.status(501).json({ error: "Job scheduling is not enabled" });
1718
+ return;
1719
+ }
1720
+ const { pluginId, jobId } = req.params;
1721
+ const plugin = await resolvePlugin(registry, pluginId);
1722
+ if (!plugin) {
1723
+ res.status(404).json({ error: "Plugin not found" });
1724
+ return;
1725
+ }
1726
+ const job = await jobDeps.jobStore.getJobByIdForPlugin(plugin.id, jobId);
1727
+ if (!job) {
1728
+ res.status(404).json({ error: "Job not found" });
1729
+ return;
1730
+ }
1731
+ const limit = req.query.limit ? parseInt(req.query.limit, 10) : 25;
1732
+ if (isNaN(limit) || limit < 1 || limit > 500) {
1733
+ res.status(400).json({ error: "limit must be a number between 1 and 500" });
1734
+ return;
1735
+ }
1736
+ try {
1737
+ const runs = await jobDeps.jobStore.listRunsByJob(jobId, limit);
1738
+ res.json(runs);
1739
+ }
1740
+ catch (err) {
1741
+ const message = err instanceof Error ? err.message : String(err);
1742
+ res.status(500).json({ error: message });
1743
+ }
1744
+ });
1745
+ /**
1746
+ * POST /api/plugins/:pluginId/jobs/:jobId/trigger
1747
+ *
1748
+ * Manually trigger a job execution outside its cron schedule.
1749
+ *
1750
+ * Creates a run with `trigger: "manual"` and dispatches immediately.
1751
+ * The response returns before the job completes (non-blocking).
1752
+ *
1753
+ * Response: `{ runId: string, jobId: string }`
1754
+ * Errors:
1755
+ * - 404 if plugin not found
1756
+ * - 400 if job not found, not active, already running, or worker unavailable
1757
+ */
1758
+ router.post("/plugins/:pluginId/jobs/:jobId/trigger", async (req, res) => {
1759
+ assertInstanceAdmin(req);
1760
+ if (!jobDeps) {
1761
+ res.status(501).json({ error: "Job scheduling is not enabled" });
1762
+ return;
1763
+ }
1764
+ const { pluginId, jobId } = req.params;
1765
+ const plugin = await resolvePlugin(registry, pluginId);
1766
+ if (!plugin) {
1767
+ res.status(404).json({ error: "Plugin not found" });
1768
+ return;
1769
+ }
1770
+ const job = await jobDeps.jobStore.getJobByIdForPlugin(plugin.id, jobId);
1771
+ if (!job) {
1772
+ res.status(404).json({ error: "Job not found" });
1773
+ return;
1774
+ }
1775
+ try {
1776
+ const result = await jobDeps.scheduler.triggerJob(jobId, "manual");
1777
+ res.json(result);
1778
+ }
1779
+ catch (err) {
1780
+ const message = err instanceof Error ? err.message : String(err);
1781
+ res.status(400).json({ error: message });
1782
+ }
1783
+ });
1784
+ // ===========================================================================
1785
+ // Webhook ingestion route
1786
+ // ===========================================================================
1787
+ /**
1788
+ * POST /api/plugins/:pluginId/webhooks/:endpointKey
1789
+ *
1790
+ * Receive an inbound webhook delivery for a plugin.
1791
+ *
1792
+ * This route is called by external systems (e.g. GitHub, Linear, Stripe) to
1793
+ * deliver webhook payloads to a plugin. The host validates that:
1794
+ * 1. The plugin exists and is in 'ready' state
1795
+ * 2. The plugin declares the `webhooks.receive` capability
1796
+ * 3. The `endpointKey` matches a declared webhook in the manifest
1797
+ *
1798
+ * The delivery is recorded in the `plugin_webhook_deliveries` table and
1799
+ * dispatched to the worker via the `handleWebhook` RPC method.
1800
+ *
1801
+ * **Note:** This route does NOT require board authentication — webhook
1802
+ * endpoints must be publicly accessible for external callers. Signature
1803
+ * verification is the plugin's responsibility.
1804
+ *
1805
+ * Response: `{ deliveryId: string, status: string }`
1806
+ * Errors:
1807
+ * - 404 if plugin not found or endpointKey not declared
1808
+ * - 400 if plugin is not in ready state or lacks webhooks.receive capability
1809
+ * - 502 if the worker is unavailable or the RPC call fails
1810
+ */
1811
+ router.post("/plugins/:pluginId/webhooks/:endpointKey", async (req, res) => {
1812
+ if (!webhookDeps) {
1813
+ res.status(501).json({ error: "Webhook ingestion is not enabled" });
1814
+ return;
1815
+ }
1816
+ const { pluginId, endpointKey } = req.params;
1817
+ // Step 1: Resolve the plugin
1818
+ const plugin = await resolvePlugin(registry, pluginId);
1819
+ if (!plugin) {
1820
+ res.status(404).json({ error: "Plugin not found" });
1821
+ return;
1822
+ }
1823
+ // Step 2: Validate the plugin is in 'ready' state
1824
+ if (plugin.status !== "ready") {
1825
+ res.status(400).json({
1826
+ error: `Plugin is not ready (current status: ${plugin.status})`,
1827
+ });
1828
+ return;
1829
+ }
1830
+ // Step 3: Validate the plugin has webhooks.receive capability
1831
+ const manifest = plugin.manifestJson;
1832
+ if (!manifest) {
1833
+ res.status(400).json({ error: "Plugin manifest is missing" });
1834
+ return;
1835
+ }
1836
+ const capabilities = manifest.capabilities ?? [];
1837
+ if (!capabilities.includes("webhooks.receive")) {
1838
+ res.status(400).json({
1839
+ error: "Plugin does not have the webhooks.receive capability",
1840
+ });
1841
+ return;
1842
+ }
1843
+ // Step 4: Validate the endpointKey exists in the manifest's webhook declarations
1844
+ const declaredWebhooks = manifest.webhooks ?? [];
1845
+ const webhookDecl = declaredWebhooks.find((w) => w.endpointKey === endpointKey);
1846
+ if (!webhookDecl) {
1847
+ res.status(404).json({
1848
+ error: `Webhook endpoint '${endpointKey}' is not declared by this plugin`,
1849
+ });
1850
+ return;
1851
+ }
1852
+ // Step 5: Extract request data
1853
+ const requestId = randomUUID();
1854
+ const rawHeaders = {};
1855
+ for (const [key, value] of Object.entries(req.headers)) {
1856
+ if (typeof value === "string") {
1857
+ rawHeaders[key] = value;
1858
+ }
1859
+ else if (Array.isArray(value)) {
1860
+ rawHeaders[key] = value.join(", ");
1861
+ }
1862
+ }
1863
+ // Use the raw buffer stashed by the express.json() `verify` callback.
1864
+ // This preserves the exact bytes the provider signed, whereas
1865
+ // JSON.stringify(req.body) would re-serialize and break HMAC verification.
1866
+ const stashedRaw = req.rawBody;
1867
+ const rawBody = stashedRaw ? stashedRaw.toString("utf-8") : "";
1868
+ const parsedBody = req.body;
1869
+ const payload = req.body ?? {};
1870
+ // Step 6: Record the delivery in the database
1871
+ const startedAt = new Date();
1872
+ const [delivery] = await db
1873
+ .insert(pluginWebhookDeliveries)
1874
+ .values({
1875
+ pluginId: plugin.id,
1876
+ webhookKey: endpointKey,
1877
+ status: "pending",
1878
+ payload,
1879
+ headers: rawHeaders,
1880
+ startedAt,
1881
+ })
1882
+ .returning({ id: pluginWebhookDeliveries.id });
1883
+ // Step 7: Dispatch to the worker via handleWebhook RPC
1884
+ try {
1885
+ await webhookDeps.workerManager.call(plugin.id, "handleWebhook", {
1886
+ endpointKey,
1887
+ headers: req.headers,
1888
+ rawBody,
1889
+ parsedBody,
1890
+ requestId,
1891
+ });
1892
+ // Step 8: Update delivery record to success
1893
+ const finishedAt = new Date();
1894
+ const durationMs = finishedAt.getTime() - startedAt.getTime();
1895
+ await db
1896
+ .update(pluginWebhookDeliveries)
1897
+ .set({
1898
+ status: "success",
1899
+ durationMs,
1900
+ finishedAt,
1901
+ })
1902
+ .where(eq(pluginWebhookDeliveries.id, delivery.id));
1903
+ res.status(200).json({
1904
+ deliveryId: delivery.id,
1905
+ status: "success",
1906
+ });
1907
+ }
1908
+ catch (err) {
1909
+ // Step 8 (error): Update delivery record to failed
1910
+ const finishedAt = new Date();
1911
+ const durationMs = finishedAt.getTime() - startedAt.getTime();
1912
+ const errorMessage = err instanceof Error ? err.message : String(err);
1913
+ await db
1914
+ .update(pluginWebhookDeliveries)
1915
+ .set({
1916
+ status: "failed",
1917
+ durationMs,
1918
+ error: errorMessage,
1919
+ finishedAt,
1920
+ })
1921
+ .where(eq(pluginWebhookDeliveries.id, delivery.id));
1922
+ res.status(502).json({
1923
+ deliveryId: delivery.id,
1924
+ status: "failed",
1925
+ error: errorMessage,
1926
+ });
1927
+ }
1928
+ });
1929
+ // ===========================================================================
1930
+ // Company-scoped trusted local folders
1931
+ // ===========================================================================
1932
+ router.get("/plugins/:pluginId/companies/:companyId/local-folders", async (req, res) => {
1933
+ assertBoardOrgAccess(req);
1934
+ const { pluginId, companyId } = req.params;
1935
+ assertCompanyAccess(req, companyId);
1936
+ const plugin = await resolvePlugin(registry, pluginId);
1937
+ if (!plugin) {
1938
+ res.status(404).json({ error: "Plugin not found" });
1939
+ return;
1940
+ }
1941
+ const settings = await registry.getCompanySettings(plugin.id, companyId);
1942
+ const storedFolders = getStoredLocalFolders(settings?.settingsJson);
1943
+ const declarations = plugin.manifestJson.localFolders ?? [];
1944
+ const folderKeys = declarations.map((declaration) => declaration.folderKey);
1945
+ const statuses = await Promise.all(folderKeys.map((folderKey) => inspectPluginLocalFolder({
1946
+ folderKey,
1947
+ declaration: findLocalFolderDeclaration(declarations, folderKey),
1948
+ storedConfig: storedFolders[folderKey] ?? null,
1949
+ })));
1950
+ res.json({
1951
+ pluginId: plugin.id,
1952
+ companyId,
1953
+ declarations,
1954
+ folders: statuses,
1955
+ });
1956
+ });
1957
+ router.get("/plugins/:pluginId/companies/:companyId/local-folders/:folderKey/status", async (req, res) => {
1958
+ assertBoardOrgAccess(req);
1959
+ const { pluginId, companyId, folderKey } = req.params;
1960
+ assertCompanyAccess(req, companyId);
1961
+ const plugin = await resolvePlugin(registry, pluginId);
1962
+ if (!plugin) {
1963
+ res.status(404).json({ error: "Plugin not found" });
1964
+ return;
1965
+ }
1966
+ const settings = await registry.getCompanySettings(plugin.id, companyId);
1967
+ const storedFolders = getStoredLocalFolders(settings?.settingsJson);
1968
+ const declarations = plugin.manifestJson.localFolders ?? [];
1969
+ const declaration = requireLocalFolderDeclaration(declarations, folderKey);
1970
+ const status = await inspectPluginLocalFolder({
1971
+ folderKey,
1972
+ declaration,
1973
+ storedConfig: storedFolders[folderKey] ?? null,
1974
+ });
1975
+ res.json(status);
1976
+ });
1977
+ router.post("/plugins/:pluginId/companies/:companyId/local-folders/:folderKey/validate", async (req, res) => {
1978
+ assertBoardOrgAccess(req);
1979
+ const { pluginId, companyId, folderKey } = req.params;
1980
+ assertCompanyAccess(req, companyId);
1981
+ const plugin = await resolvePlugin(registry, pluginId);
1982
+ if (!plugin) {
1983
+ res.status(404).json({ error: "Plugin not found" });
1984
+ return;
1985
+ }
1986
+ const body = req.body;
1987
+ if (typeof body?.path !== "string" || body.path.trim().length === 0) {
1988
+ res.status(400).json({ error: '"path" is required and must be a non-empty string' });
1989
+ return;
1990
+ }
1991
+ const declaration = requireLocalFolderDeclaration(plugin.manifestJson.localFolders ?? [], folderKey);
1992
+ const status = await inspectPluginLocalFolder({
1993
+ folderKey,
1994
+ declaration,
1995
+ overrideConfig: {
1996
+ path: body.path,
1997
+ },
1998
+ });
1999
+ res.json(status);
2000
+ });
2001
+ router.put("/plugins/:pluginId/companies/:companyId/local-folders/:folderKey", async (req, res) => {
2002
+ assertBoardOrgAccess(req);
2003
+ const { pluginId, companyId, folderKey } = req.params;
2004
+ assertCompanyAccess(req, companyId);
2005
+ const plugin = await resolvePlugin(registry, pluginId);
2006
+ if (!plugin) {
2007
+ res.status(404).json({ error: "Plugin not found" });
2008
+ return;
2009
+ }
2010
+ const body = req.body;
2011
+ if (typeof body?.path !== "string" || body.path.trim().length === 0) {
2012
+ res.status(400).json({ error: '"path" is required and must be a non-empty string' });
2013
+ return;
2014
+ }
2015
+ const existing = await registry.getCompanySettings(plugin.id, companyId);
2016
+ const declaration = requireLocalFolderDeclaration(plugin.manifestJson.localFolders ?? [], folderKey);
2017
+ const status = await inspectPluginLocalFolder({
2018
+ folderKey,
2019
+ declaration,
2020
+ storedConfig: getStoredLocalFolders(existing?.settingsJson)[folderKey] ?? null,
2021
+ overrideConfig: {
2022
+ path: body.path,
2023
+ },
2024
+ });
2025
+ const nextSettings = setStoredLocalFolder(existing?.settingsJson, folderKey, {
2026
+ path: body.path,
2027
+ access: status.access,
2028
+ requiredDirectories: status.requiredDirectories,
2029
+ requiredFiles: status.requiredFiles,
2030
+ });
2031
+ await registry.upsertCompanySettings(plugin.id, companyId, {
2032
+ enabled: existing?.enabled ?? true,
2033
+ settingsJson: nextSettings,
2034
+ lastError: status.healthy ? null : status.problems.map((item) => item.message).join("; "),
2035
+ });
2036
+ await logPluginMutationActivity(req, "plugin.local_folder.configured", plugin.id, {
2037
+ pluginId: plugin.id,
2038
+ pluginKey: plugin.pluginKey,
2039
+ companyId,
2040
+ folderKey,
2041
+ healthy: status.healthy,
2042
+ });
2043
+ res.json(status);
2044
+ });
2045
+ // ===========================================================================
2046
+ // Plugin health dashboard — aggregated diagnostics for the settings page
2047
+ // ===========================================================================
2048
+ /**
2049
+ * GET /api/plugins/:pluginId/dashboard
2050
+ *
2051
+ * Aggregated health dashboard data for a plugin's settings page.
2052
+ *
2053
+ * Returns worker diagnostics (status, uptime, crash history), recent job
2054
+ * runs, recent webhook deliveries, and the current health check result —
2055
+ * all in a single response to avoid multiple round-trips.
2056
+ *
2057
+ * Response: PluginDashboardData
2058
+ * Errors: 404 if plugin not found
2059
+ */
2060
+ router.get("/plugins/:pluginId/dashboard", async (req, res) => {
2061
+ assertBoardOrgAccess(req);
2062
+ const { pluginId } = req.params;
2063
+ const plugin = await resolvePlugin(registry, pluginId);
2064
+ if (!plugin) {
2065
+ res.status(404).json({ error: "Plugin not found" });
2066
+ return;
2067
+ }
2068
+ // --- Worker diagnostics ---
2069
+ let worker = null;
2070
+ // Try bridgeDeps first (primary source for worker manager), fallback to webhookDeps
2071
+ const wm = bridgeDeps?.workerManager ?? webhookDeps?.workerManager ?? null;
2072
+ if (wm) {
2073
+ const handle = wm.getWorker(plugin.id);
2074
+ if (handle) {
2075
+ const diag = handle.diagnostics();
2076
+ worker = {
2077
+ status: diag.status,
2078
+ pid: diag.pid,
2079
+ uptime: diag.uptime,
2080
+ consecutiveCrashes: diag.consecutiveCrashes,
2081
+ totalCrashes: diag.totalCrashes,
2082
+ pendingRequests: diag.pendingRequests,
2083
+ lastCrashAt: diag.lastCrashAt,
2084
+ nextRestartAt: diag.nextRestartAt,
2085
+ };
2086
+ }
2087
+ }
2088
+ // --- Recent job runs (last 10, newest first) ---
2089
+ let recentJobRuns = [];
2090
+ if (jobDeps) {
2091
+ try {
2092
+ const runs = await jobDeps.jobStore.listRunsByPlugin(plugin.id, undefined, 10);
2093
+ // Also fetch job definitions so we can include jobKey
2094
+ const jobs = await jobDeps.jobStore.listJobs(plugin.id);
2095
+ const jobKeyMap = new Map(jobs.map((j) => [j.id, j.jobKey]));
2096
+ recentJobRuns = runs
2097
+ .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
2098
+ .map((r) => ({
2099
+ id: r.id,
2100
+ jobId: r.jobId,
2101
+ jobKey: jobKeyMap.get(r.jobId) ?? undefined,
2102
+ trigger: r.trigger,
2103
+ status: r.status,
2104
+ durationMs: r.durationMs,
2105
+ error: r.error,
2106
+ startedAt: r.startedAt ? new Date(r.startedAt).toISOString() : null,
2107
+ finishedAt: r.finishedAt ? new Date(r.finishedAt).toISOString() : null,
2108
+ createdAt: new Date(r.createdAt).toISOString(),
2109
+ }));
2110
+ }
2111
+ catch {
2112
+ // Job data unavailable — leave empty
2113
+ }
2114
+ }
2115
+ // --- Recent webhook deliveries (last 10, newest first) ---
2116
+ let recentWebhookDeliveries = [];
2117
+ try {
2118
+ const deliveries = await db
2119
+ .select({
2120
+ id: pluginWebhookDeliveries.id,
2121
+ webhookKey: pluginWebhookDeliveries.webhookKey,
2122
+ status: pluginWebhookDeliveries.status,
2123
+ durationMs: pluginWebhookDeliveries.durationMs,
2124
+ error: pluginWebhookDeliveries.error,
2125
+ startedAt: pluginWebhookDeliveries.startedAt,
2126
+ finishedAt: pluginWebhookDeliveries.finishedAt,
2127
+ createdAt: pluginWebhookDeliveries.createdAt,
2128
+ })
2129
+ .from(pluginWebhookDeliveries)
2130
+ .where(eq(pluginWebhookDeliveries.pluginId, plugin.id))
2131
+ .orderBy(desc(pluginWebhookDeliveries.createdAt))
2132
+ .limit(10);
2133
+ recentWebhookDeliveries = deliveries.map((d) => ({
2134
+ id: d.id,
2135
+ webhookKey: d.webhookKey,
2136
+ status: d.status,
2137
+ durationMs: d.durationMs,
2138
+ error: d.error,
2139
+ startedAt: d.startedAt ? d.startedAt.toISOString() : null,
2140
+ finishedAt: d.finishedAt ? d.finishedAt.toISOString() : null,
2141
+ createdAt: d.createdAt.toISOString(),
2142
+ }));
2143
+ }
2144
+ catch {
2145
+ // Webhook data unavailable — leave empty
2146
+ }
2147
+ // --- Health check (same logic as GET /health) ---
2148
+ const checks = [];
2149
+ checks.push({
2150
+ name: "registry",
2151
+ passed: true,
2152
+ message: "Plugin found in registry",
2153
+ });
2154
+ const hasValidManifest = Boolean(plugin.manifestJson?.id);
2155
+ checks.push({
2156
+ name: "manifest",
2157
+ passed: hasValidManifest,
2158
+ message: hasValidManifest ? "Manifest is valid" : "Manifest is invalid or missing",
2159
+ });
2160
+ const isHealthy = plugin.status === "ready";
2161
+ checks.push({
2162
+ name: "status",
2163
+ passed: isHealthy,
2164
+ message: `Current status: ${plugin.status}`,
2165
+ });
2166
+ const hasNoError = !plugin.lastError;
2167
+ if (!hasNoError) {
2168
+ checks.push({
2169
+ name: "error_state",
2170
+ passed: false,
2171
+ message: plugin.lastError ?? undefined,
2172
+ });
2173
+ }
2174
+ const health = {
2175
+ pluginId: plugin.id,
2176
+ status: plugin.status,
2177
+ healthy: isHealthy && hasValidManifest && hasNoError,
2178
+ checks,
2179
+ lastError: plugin.lastError ?? undefined,
2180
+ };
2181
+ res.json({
2182
+ pluginId: plugin.id,
2183
+ worker,
2184
+ recentJobRuns,
2185
+ recentWebhookDeliveries,
2186
+ health,
2187
+ checkedAt: new Date().toISOString(),
2188
+ });
2189
+ });
2190
+ return router;
2191
+ }
2192
+ //# sourceMappingURL=plugins.js.map