@preventive/triage 1.0.0-alpha.9 → 1.0.0-alpha.90

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 (448) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +16 -78
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +6 -0
  13. package/common/bundle-compare-diff.js +378 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-imports.js +20 -0
  20. package/common/bundle-metadata.d.ts +15 -0
  21. package/common/bundle-metadata.js +226 -0
  22. package/common/bundle-pkg-of.d.ts +1 -0
  23. package/common/bundle-pkg-of.js +90 -0
  24. package/common/bundle-reasons.d.ts +6 -0
  25. package/common/bundle-reasons.js +58 -0
  26. package/common/bundle-source-links.d.ts +6 -0
  27. package/common/bundle-source-links.js +216 -0
  28. package/common/bundle-sourcemap.d.ts +10 -0
  29. package/common/bundle-sourcemap.js +100 -0
  30. package/common/bundle-sources.d.ts +10 -0
  31. package/common/bundle-sources.js +374 -0
  32. package/common/bundle-stats.js +41 -0
  33. package/common/bundle-tabs.js +1 -0
  34. package/common/code-language.js +80 -0
  35. package/common/default-scan-models.ts +37 -0
  36. package/common/dependency-reviews.d.ts +19 -0
  37. package/common/dependency-reviews.js +67 -0
  38. package/common/finding-duplicates.js +63 -0
  39. package/common/finding-filters.js +313 -0
  40. package/common/finding-id.js +47 -0
  41. package/common/finding-repo.d.ts +5 -0
  42. package/common/finding-repo.js +67 -0
  43. package/common/github-issue-labels.d.ts +3 -0
  44. package/common/github-issue-labels.js +42 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +15 -0
  48. package/common/line-diff.js +188 -0
  49. package/common/linked-workspace-groups.js +63 -0
  50. package/common/managed/agent-tasks.ts +292 -0
  51. package/common/managed/comments.ts +43 -0
  52. package/common/managed/dependency-routes.js +25 -0
  53. package/common/managed/directory-packages.ts +28 -0
  54. package/common/managed/finding-detail.d.ts +5 -0
  55. package/common/managed/finding-detail.js +75 -0
  56. package/common/managed/finding-values.d.ts +2 -0
  57. package/common/managed/finding-values.js +138 -0
  58. package/common/managed/github-agents.ts +114 -0
  59. package/common/managed/github-logins.ts +49 -0
  60. package/common/managed/lite-name.d.ts +2 -0
  61. package/common/managed/lite-name.js +20 -0
  62. package/common/managed/npm-packages.d.ts +9 -0
  63. package/common/managed/npm-packages.js +63 -0
  64. package/common/managed/permissions.ts +31 -0
  65. package/common/managed/report-content.ts +72 -0
  66. package/common/managed/report-filter.ts +120 -0
  67. package/common/managed/repository-alias.ts +65 -0
  68. package/common/managed/review-view-routes.js +23 -0
  69. package/common/managed/risk-routes.js +30 -0
  70. package/common/managed/roles.ts +48 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +386 -0
  73. package/common/managed/scan-models.ts +6 -0
  74. package/common/managed/stasis-config.ts +7 -0
  75. package/common/managed/team-app.d.ts +19 -0
  76. package/common/managed/team-app.js +129 -0
  77. package/common/managed/team-filters.js +26 -0
  78. package/common/managed/triage.ts +83 -0
  79. package/common/managed/upload-seal.ts +126 -0
  80. package/common/npm-token.d.ts +2 -0
  81. package/common/npm-token.js +14 -0
  82. package/common/pretty-json.js +123 -0
  83. package/common/pretty-kinds.js +20 -0
  84. package/common/pretty-print.d.ts +7 -0
  85. package/common/pretty-print.js +41 -0
  86. package/common/pretty-sourcemap.js +70 -0
  87. package/common/repo-commit.d.ts +4 -0
  88. package/common/repo-commit.js +30 -0
  89. package/common/revalidation-conflicts.js +48 -0
  90. package/common/revalidation-input-groups.js +56 -0
  91. package/common/scan-server.ts +13 -0
  92. package/common/security-links.d.ts +5 -0
  93. package/common/security-links.js +33 -0
  94. package/common/server-info.ts +46 -0
  95. package/common/sourcemap-listing.js +78 -0
  96. package/common/sourcemap-mappings.js +136 -0
  97. package/common/sourcemap-unlist.js +85 -0
  98. package/common/stasis-files.d.ts +5 -0
  99. package/common/stasis-files.js +20 -0
  100. package/common/stasis-tgz.d.ts +6 -0
  101. package/common/stasis-tgz.js +27 -0
  102. package/common/utf8.d.ts +3 -0
  103. package/common/utf8.js +45 -0
  104. package/common/whitespace-insensitive.js +19 -0
  105. package/common/workspace-app.js +91 -0
  106. package/common/workspace-groups.js +176 -0
  107. package/out/activity.js +2 -0
  108. package/out/brotli-fallback.js +3 -3
  109. package/out/chunk-2XUEZHIP.js +28 -0
  110. package/out/chunk-3DOSBILK.js +4 -0
  111. package/out/chunk-55YIWY3H.js +5 -0
  112. package/out/chunk-5AVGKFMR.js +1 -0
  113. package/out/chunk-5PWEAEA5.js +1 -0
  114. package/out/chunk-6VOB5WXX.js +2 -0
  115. package/out/chunk-6Y6PZ2BU.js +9 -0
  116. package/out/chunk-74JZTGTO.js +11 -0
  117. package/out/chunk-7BKKYVWR.js +7 -0
  118. package/out/chunk-7C7DWL7I.js +1 -0
  119. package/out/chunk-7HP2VYIC.js +2 -0
  120. package/out/chunk-7YFJUT2P.js +1 -0
  121. package/out/chunk-A4BBBHQU.js +1 -0
  122. package/out/chunk-B64CTMVU.js +4 -0
  123. package/out/chunk-BEKYZCPX.js +14 -0
  124. package/out/chunk-BZJU5EEV.js +1 -0
  125. package/out/chunk-C4Z6ZBXV.js +10 -0
  126. package/out/chunk-CJVMNJDZ.js +3 -0
  127. package/out/chunk-CU3FPB3P.js +1 -0
  128. package/out/chunk-DEVAORP2.js +1 -0
  129. package/out/chunk-DUASGS2O.js +8 -0
  130. package/out/chunk-EEJA7JBI.js +13 -0
  131. package/out/chunk-ESXA7KID.js +1 -0
  132. package/out/chunk-FSU2PLJL.js +1 -0
  133. package/out/chunk-GO7FT4OD.js +1 -0
  134. package/out/chunk-GX5UXWT4.js +1 -0
  135. package/out/chunk-HGWFRZNC.js +267 -0
  136. package/out/chunk-IYPY47MC.js +1 -0
  137. package/out/chunk-JZAROLQT.js +40 -0
  138. package/out/chunk-K4XJHM2T.js +1 -0
  139. package/out/chunk-KP2XM324.js +6 -0
  140. package/out/chunk-LRWB6QVO.js +1 -0
  141. package/out/chunk-LVSLM7HB.js +1 -0
  142. package/out/chunk-LVW7WWV4.js +1 -0
  143. package/out/chunk-N57OWFKY.js +15 -0
  144. package/out/chunk-NRPC74AM.js +1 -0
  145. package/out/chunk-OOJM4CTU.js +1 -0
  146. package/out/chunk-PKLVXUEI.js +11 -0
  147. package/out/chunk-PLGH63UC.js +2 -0
  148. package/out/chunk-PNHBZGDD.js +1 -0
  149. package/out/chunk-PWFUOLZK.js +17 -0
  150. package/out/chunk-PXK7EU4V.js +1 -0
  151. package/out/chunk-QD3IBSF4.js +7 -0
  152. package/out/chunk-QI66YA4F.js +1 -0
  153. package/out/chunk-QRKFPLA4.js +80 -0
  154. package/out/chunk-R3NZFXVR.js +1 -0
  155. package/out/chunk-R5O6FAW4.js +2 -0
  156. package/out/chunk-RAM3GDAD.js +1 -0
  157. package/out/chunk-RPNO56H2.js +1 -0
  158. package/out/chunk-SMNFBOLO.js +10 -0
  159. package/out/chunk-SSPDMA6D.js +1 -0
  160. package/out/chunk-SZTCJVZJ.js +55 -0
  161. package/out/chunk-SZWPYLPC.js +1 -0
  162. package/out/chunk-TKPNRQNN.js +3 -0
  163. package/out/chunk-TUII34K2.js +1 -0
  164. package/out/chunk-UJP4PQJA.js +1 -0
  165. package/out/chunk-UJSJMXEG.js +1 -0
  166. package/out/chunk-UR4WYMIP.js +1 -0
  167. package/out/chunk-UTYWTUTC.js +1 -0
  168. package/out/chunk-VHEXSGGP.js +1 -0
  169. package/out/chunk-VYYUMYVW.js +9 -0
  170. package/out/chunk-WBK5ZN4K.js +3 -0
  171. package/out/chunk-WCDYSIKG.js +1 -0
  172. package/out/chunk-XM4RLC4A.js +2 -0
  173. package/out/chunk-XRAAYXPR.js +1 -0
  174. package/out/chunk-ZQHLECTI.js +1 -0
  175. package/out/client-managed-import.js +4 -0
  176. package/out/client-managed.js +35 -0
  177. package/out/client-sync.js +11 -17
  178. package/out/compare.js +26 -0
  179. package/out/dialogs.js +40 -0
  180. package/out/github-issue-authorized.html +3 -0
  181. package/out/github-issue-authorized.js +1 -0
  182. package/out/graph.js +19 -5
  183. package/out/index.html +105 -25
  184. package/out/prism.js +14 -10
  185. package/out/scan.js +2 -0
  186. package/out/stasis.svg +20 -0
  187. package/out/terminal.js +367 -39
  188. package/out/view.css +1 -1
  189. package/out/view.js +19 -148
  190. package/package.json +416 -64
  191. package/risk/actions/findings.js +161 -0
  192. package/risk/actions/resolve.js +287 -0
  193. package/risk/actions/scripts/commands.js +182 -0
  194. package/risk/actions/scripts/grade.js +113 -0
  195. package/risk/actions/scripts/packages.js +123 -0
  196. package/risk/actions/scripts/shell.js +169 -0
  197. package/risk/actions/uses.js +94 -0
  198. package/risk/actions/workflow.js +183 -0
  199. package/risk/files/characters.js +354 -0
  200. package/risk/files/hosts.js +206 -0
  201. package/risk/files/readability.js +185 -0
  202. package/risk/files/runs-code.js +568 -0
  203. package/risk/files/script.js +420 -0
  204. package/risk/files/source-map-link.js +43 -0
  205. package/risk/files/stamps.js +47 -0
  206. package/risk/index.d.ts +309 -0
  207. package/risk/index.js +12 -0
  208. package/risk/npm/assess.js +303 -0
  209. package/risk/npm/combined.js +68 -0
  210. package/risk/npm/compare.js +236 -0
  211. package/risk/npm/dependencies.js +172 -0
  212. package/risk/npm/diff.js +79 -0
  213. package/risk/npm/downloads.js +84 -0
  214. package/risk/npm/files.js +445 -0
  215. package/risk/npm/held.js +67 -0
  216. package/risk/npm/install-scripts.js +34 -0
  217. package/risk/npm/malware.js +38 -0
  218. package/risk/npm/manifest.js +65 -0
  219. package/risk/npm/new-dependency.js +60 -0
  220. package/risk/npm/old-version.js +108 -0
  221. package/risk/npm/registry.js +401 -0
  222. package/risk/npm/release.js +85 -0
  223. package/risk/npm/score.js +59 -0
  224. package/risk/npm/specs.js +124 -0
  225. package/risk/npm/tarball.js +169 -0
  226. package/server-common/database-config.ts +16 -0
  227. package/server-common/initialize.ts +18 -0
  228. package/server-common/npm-advisories.ts +101 -0
  229. package/{server → server-common}/origin.ts +5 -5
  230. package/server-common/reap.ts +48 -0
  231. package/server-common/scan-config.ts +19 -0
  232. package/server-common/standalone.ts +29 -0
  233. package/server-common/storage-crypto.ts +182 -0
  234. package/server-common/storage-log.ts +38 -0
  235. package/server-common/vercel-blob.ts +103 -0
  236. package/server-e2e/app.ts +487 -0
  237. package/{server → server-e2e}/bus-receiver.ts +2 -1
  238. package/{server → server-e2e}/cli.js +9 -4
  239. package/{server → server-e2e}/config.ts +52 -42
  240. package/{server → server-e2e}/db-neon.ts +2 -2
  241. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  242. package/{server → server-e2e}/db-stmt.ts +2 -2
  243. package/{server → server-e2e}/db.ts +7 -7
  244. package/{server → server-e2e}/http.ts +44 -13
  245. package/{server → server-e2e}/hub.ts +40 -9
  246. package/server-e2e/index.ts +17 -0
  247. package/server-e2e/lifecycle.ts +95 -0
  248. package/{server → server-e2e}/neon-driver.ts +2 -2
  249. package/{server → server-e2e}/npm-proxy.ts +12 -145
  250. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  251. package/{server → server-e2e}/objstore/blob.ts +1 -1
  252. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  253. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  254. package/{server → server-e2e}/objstore/init.ts +19 -27
  255. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  257. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  258. package/{server → server-e2e}/objstore/rest.ts +3 -3
  259. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  260. package/{server → server-e2e}/objstore/store.ts +7 -7
  261. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  262. package/{server → server-e2e}/pubsub.ts +12 -9
  263. package/{server → server-e2e}/sign.ts +4 -4
  264. package/{server → server-e2e}/sse-server.ts +3 -3
  265. package/{server → server-e2e}/static.ts +18 -17
  266. package/{server → server-e2e}/sync-handlers.ts +56 -30
  267. package/{server → server-e2e}/ws-server.ts +20 -9
  268. package/server-managed/activity.ts +269 -0
  269. package/server-managed/agent-merges.ts +109 -0
  270. package/server-managed/app-agents.ts +23 -0
  271. package/server-managed/avatar-store.ts +21 -0
  272. package/server-managed/blob-store.ts +26 -0
  273. package/server-managed/brotli.ts +10 -0
  274. package/server-managed/bundle-advisories.ts +176 -0
  275. package/server-managed/bundle-advisory-inventory.ts +85 -0
  276. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  277. package/server-managed/bundle-build-diagnostics.js +23 -0
  278. package/server-managed/bundle-build-leases.ts +41 -0
  279. package/server-managed/bundle-build-worker.js +387 -0
  280. package/server-managed/bundle-build.ts +328 -0
  281. package/server-managed/bundle-cache.ts +261 -0
  282. package/server-managed/bundle-catalog.ts +29 -0
  283. package/server-managed/bundle-commits.ts +133 -0
  284. package/server-managed/bundle-dependency-reviews.ts +91 -0
  285. package/server-managed/bundle-store.ts +24 -0
  286. package/server-managed/bundle-summary-cache.ts +139 -0
  287. package/server-managed/bundle-validation.ts +33 -0
  288. package/server-managed/bundle.ts +151 -0
  289. package/server-managed/cache-storage.ts +20 -0
  290. package/server-managed/cli.js +21 -0
  291. package/server-managed/combined.ts +43 -0
  292. package/server-managed/comments.ts +138 -0
  293. package/server-managed/commit-coauthors.ts +105 -0
  294. package/server-managed/commit-lockfiles.ts +78 -0
  295. package/server-managed/comparison.ts +51 -0
  296. package/server-managed/config.ts +163 -0
  297. package/server-managed/content-access.ts +15 -0
  298. package/server-managed/crypto.ts +25 -0
  299. package/server-managed/db-methods.ts +1950 -0
  300. package/server-managed/db-neon.ts +401 -0
  301. package/server-managed/db-schema.ts +271 -0
  302. package/server-managed/db-table-names.ts +22 -0
  303. package/server-managed/db.ts +150 -0
  304. package/server-managed/dependabot-access.ts +85 -0
  305. package/server-managed/dependabot-alerts.ts +197 -0
  306. package/server-managed/dependency-review-comments.ts +158 -0
  307. package/server-managed/dependency-reviews.ts +369 -0
  308. package/server-managed/github-accounts.ts +59 -0
  309. package/server-managed/github-actions.ts +71 -0
  310. package/server-managed/github-app.ts +347 -0
  311. package/server-managed/github-errors.ts +92 -0
  312. package/server-managed/github-graphql.ts +42 -0
  313. package/server-managed/github-issue-links.ts +264 -0
  314. package/server-managed/github-issue-oauth.ts +30 -0
  315. package/server-managed/github-issues.ts +169 -0
  316. package/server-managed/github-link-oauth.ts +56 -0
  317. package/server-managed/github-links.ts +204 -0
  318. package/server-managed/github-metadata.ts +218 -0
  319. package/server-managed/github-oauth.ts +264 -0
  320. package/server-managed/github-pulls.ts +290 -0
  321. package/server-managed/github-requests.ts +181 -0
  322. package/server-managed/github-users.ts +53 -0
  323. package/server-managed/github-values.ts +26 -0
  324. package/server-managed/history-windows.ts +172 -0
  325. package/server-managed/http-response.ts +76 -0
  326. package/server-managed/http.ts +6722 -0
  327. package/server-managed/import-triage.ts +51 -0
  328. package/server-managed/index.ts +204 -0
  329. package/server-managed/kept-briefly.ts +37 -0
  330. package/server-managed/kept.ts +28 -0
  331. package/server-managed/known-listings.ts +112 -0
  332. package/server-managed/link-reports.ts +149 -0
  333. package/server-managed/listed-activity.ts +39 -0
  334. package/server-managed/locked-packages.ts +234 -0
  335. package/server-managed/lockfile-scope.ts +58 -0
  336. package/server-managed/lru.ts +30 -0
  337. package/server-managed/managed-issues.ts +92 -0
  338. package/server-managed/management-catalog.ts +45 -0
  339. package/server-managed/management.ts +116 -0
  340. package/server-managed/npm-delta-worker.js +203 -0
  341. package/server-managed/npm-delta.ts +277 -0
  342. package/server-managed/npm-insights.ts +455 -0
  343. package/server-managed/npm-kept.ts +274 -0
  344. package/server-managed/npm-loads.ts +259 -0
  345. package/server-managed/npm-manifest.ts +117 -0
  346. package/server-managed/npm-packages.ts +477 -0
  347. package/server-managed/npm-patch-paths.ts +86 -0
  348. package/server-managed/npm-patch.ts +457 -0
  349. package/server-managed/npm-provenance.ts +127 -0
  350. package/server-managed/npm-risk.ts +310 -0
  351. package/server-managed/object-storage-disk.ts +147 -0
  352. package/server-managed/object-storage-vercel.ts +71 -0
  353. package/server-managed/object-storage.ts +82 -0
  354. package/server-managed/package-entry-points.ts +127 -0
  355. package/server-managed/pretty-copies.ts +22 -0
  356. package/server-managed/pretty-format.d.ts +4 -0
  357. package/server-managed/pretty-format.js +27 -0
  358. package/server-managed/pretty-print.ts +444 -0
  359. package/server-managed/public-workspace.ts +242 -0
  360. package/server-managed/pull-comment-reviews.ts +161 -0
  361. package/server-managed/pull-dependencies.ts +370 -0
  362. package/server-managed/pull-dependency-reviews.ts +458 -0
  363. package/server-managed/pull-reviews.ts +202 -0
  364. package/server-managed/pulse-walk.ts +164 -0
  365. package/server-managed/queue.ts +54 -0
  366. package/server-managed/release-commits.ts +85 -0
  367. package/server-managed/rename-diff-worker.js +30 -0
  368. package/server-managed/rename-diff.ts +237 -0
  369. package/server-managed/repo-path.ts +21 -0
  370. package/server-managed/report-migration.ts +32 -0
  371. package/server-managed/report-opening.ts +77 -0
  372. package/server-managed/report-query.ts +10 -0
  373. package/server-managed/report-response.ts +16 -0
  374. package/server-managed/report-sources.ts +185 -0
  375. package/server-managed/report-store.ts +77 -0
  376. package/server-managed/repository-actions.ts +220 -0
  377. package/server-managed/repository-agents.ts +422 -0
  378. package/server-managed/repository-aliases.ts +119 -0
  379. package/server-managed/repository-browser.ts +362 -0
  380. package/server-managed/repository-changes.ts +280 -0
  381. package/server-managed/repository-code.ts +222 -0
  382. package/server-managed/repository-dependency-reviews.ts +220 -0
  383. package/server-managed/repository-discovery.ts +83 -0
  384. package/server-managed/repository-history.ts +444 -0
  385. package/server-managed/repository-issues.ts +293 -0
  386. package/server-managed/repository-policy.ts +27 -0
  387. package/server-managed/repository-pulls.ts +207 -0
  388. package/server-managed/repository-pulse.ts +409 -0
  389. package/server-managed/repository-risk-assess.ts +179 -0
  390. package/server-managed/repository-risk-audit.ts +145 -0
  391. package/server-managed/repository-risk-caches.ts +56 -0
  392. package/server-managed/repository-risk-kept.ts +86 -0
  393. package/server-managed/repository-risk-read.ts +296 -0
  394. package/server-managed/repository-risk-stasis.ts +61 -0
  395. package/server-managed/repository-risk-turn.ts +97 -0
  396. package/server-managed/repository-risk.ts +528 -0
  397. package/server-managed/repository-squashes.ts +160 -0
  398. package/server-managed/repository-stamp.ts +41 -0
  399. package/server-managed/request-timing.ts +63 -0
  400. package/server-managed/reviewed-dependencies.ts +170 -0
  401. package/server-managed/revisions.ts +35 -0
  402. package/server-managed/scan-downloads.ts +121 -0
  403. package/server-managed/session.ts +132 -0
  404. package/server-managed/slugs.ts +38 -0
  405. package/server-managed/solidity-entry-points.ts +71 -0
  406. package/server-managed/sql-postgres.ts +34 -0
  407. package/server-managed/sql.ts +107 -0
  408. package/server-managed/stasis-config.ts +147 -0
  409. package/server-managed/stasis-dependencies.ts +280 -0
  410. package/server-managed/static.ts +28 -0
  411. package/server-managed/storage-command.ts +16 -0
  412. package/server-managed/storage-db.ts +183 -0
  413. package/server-managed/storage-encryption.ts +288 -0
  414. package/server-managed/storage-maintenance.ts +259 -0
  415. package/server-managed/storage-payload.ts +121 -0
  416. package/server-managed/storage-stores.ts +91 -0
  417. package/server-managed/storage.ts +82 -0
  418. package/server-managed/team-app-summaries.ts +57 -0
  419. package/server-managed/team-app.ts +162 -0
  420. package/server-managed/team-catalog.ts +7 -0
  421. package/server-managed/team-feed.ts +180 -0
  422. package/server-managed/team-icons.ts +50 -0
  423. package/server-managed/team-npm-scopes.ts +103 -0
  424. package/server-managed/team-progress.ts +77 -0
  425. package/server-managed/team-reports.ts +369 -0
  426. package/server-managed/triage-response.ts +16 -0
  427. package/server-managed/type-only-proof.js +181 -0
  428. package/server-managed/type-only-worker.js +31 -0
  429. package/server-managed/type-only.ts +135 -0
  430. package/server-managed/uploads.ts +106 -0
  431. package/server-managed/upstream-cache.ts +275 -0
  432. package/server-managed/view-as.ts +58 -0
  433. package/server-managed/worker-turns.ts +76 -0
  434. package/server-managed/workspace-shares.ts +170 -0
  435. package/server.ts +70 -0
  436. package/strip-types-loader.js +13 -10
  437. package/server/index.ts +0 -480
  438. package/server/lifecycle.ts +0 -208
  439. /package/{LICENSE → LICENSE-MIT} +0 -0
  440. /package/{server → server-e2e}/auth.ts +0 -0
  441. /package/{server → server-e2e}/config.example.json +0 -0
  442. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  443. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  444. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  445. /package/{server → server-e2e}/peer.ts +0 -0
  446. /package/{server → server-e2e}/sse-session.ts +0 -0
  447. /package/{server → server-e2e}/util.ts +0 -0
  448. /package/{server → server-e2e}/validation.ts +0 -0
package/common/gzip.js ADDED
@@ -0,0 +1,59 @@
1
+ // Gzip helpers built on the platform CompressionStream /
2
+ // DecompressionStream. Centralised so the half-dozen call sites
3
+ // (storage, triage / workspace export + import, sync-crypto) share
4
+ // one implementation of the Blob → stream → Response plumbing instead
5
+ // of hand-copying it. Bytes in / bytes out is the primitive; the text
6
+ // helpers run the bytes through `common/utf8.js` so the same
7
+ // fatal-on-invalid / BOM-preserving decode rules apply everywhere.
8
+ //
9
+ // `deflate` (raw, no gzip framing) is intentionally NOT covered here —
10
+ // `triage.js` uses it for its own at-rest blob and must stay distinct
11
+ // from the gzip-magic sniffing the bundles / import paths rely on.
12
+
13
+ import { decodeUtf8, encodeUtf8 } from './utf8.js'
14
+
15
+ export async function gzipBytes(bytes) {
16
+ const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream('gzip'))
17
+ return new Uint8Array(await new Response(stream).arrayBuffer())
18
+ }
19
+
20
+ // `maxBytes` (optional) caps the DECOMPRESSED size: gzip expands up to
21
+ // ~1032:1, so a small hostile payload can balloon to GiBs and OOM the
22
+ // process before any content validation runs. Callers decompressing
23
+ // peer-controlled bytes (sync-crypto's inbound changesets) pass a cap;
24
+ // the read then aborts with a RangeError the moment the budget is crossed,
25
+ // instead of materialising the full expansion. Uncapped callers keep
26
+ // the one-shot Response read.
27
+ export async function gunzipBytes(bytes, { maxBytes } = {}) {
28
+ const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'))
29
+ if (maxBytes == null) return new Uint8Array(await new Response(stream).arrayBuffer())
30
+ const reader = stream.getReader()
31
+ const chunks = []
32
+ let total = 0
33
+ for (;;) {
34
+ const { value, done } = await reader.read()
35
+ if (done) break
36
+ total += value.length
37
+ if (total > maxBytes) {
38
+ // Cancel so the DecompressionStream stops inflating the rest.
39
+ try { await reader.cancel() } catch {}
40
+ throw new RangeError(`gunzipBytes: decompressed size exceeds ${maxBytes}-byte cap`)
41
+ }
42
+ chunks.push(value)
43
+ }
44
+ const out = new Uint8Array(total)
45
+ let offset = 0
46
+ for (const chunk of chunks) {
47
+ out.set(chunk, offset)
48
+ offset += chunk.length
49
+ }
50
+ return out
51
+ }
52
+
53
+ export async function gzipText(text) {
54
+ return await gzipBytes(encodeUtf8(text))
55
+ }
56
+
57
+ export async function gunzipToText(bytes) {
58
+ return decodeUtf8(await gunzipBytes(bytes))
59
+ }
@@ -0,0 +1,15 @@
1
+ // Type declarations for `common/line-diff.js`, for `.ts` callers.
2
+
3
+ // Lines `a[a0..a1)` replaced by `b[b0..b1)`.
4
+ export interface ChangeBlock { a0: number; a1: number; b0: number; b1: number }
5
+
6
+ export function textLines(text: string): string[]
7
+ export function changeBlocks(before: string, after: string, ignoreWhitespace?: boolean | 'leading'): ChangeBlock[]
8
+ export function indentHiddenBlocks(before: string, after: string): ChangeBlock[]
9
+ export function markedCounts(blocks: readonly ChangeBlock[], marks: readonly ChangeBlock[] | null): { additions: number; deletions: number; renamed: number; marked: Set<number> }
10
+ export function diffSize(before: string, after: string, ignoreWhitespace?: boolean | 'leading'): { marks: number; lines: number }
11
+ export const isLargeDiff: (before: string, after: string) => boolean
12
+ export function typeFolds(before: string, after: string, runs: { runs: [number, number][]; otherRuns: [number, number][] }): { before: string; after: string; whole: { a: string; b: string }; lineOf: { a: number[]; b: number[] }; lines: { a: number; b: number } } | false | null
13
+ export function copiesRuns(a: { text: string; runs?: [number, number][] }, b: { text: string; runs?: [number, number][] }): { runs: [number, number][]; otherRuns: [number, number][] } | null
14
+ export function withSharedBlankLines(before: string, after: string, blankBefore: readonly number[], blankAfter: readonly number[]): { before: string; after: string }
15
+ export function blocksHold(before: string, after: string, blocks: unknown, ignoreWhitespace?: boolean | 'leading'): boolean
@@ -0,0 +1,188 @@
1
+ // Two texts' lines diffed as Compare draws and the server counts them (@preventive/compare's lineBlocks), and the
2
+ // check that a diff found elsewhere (server-managed/rename-diff.ts) takes one to the other.
3
+ //
4
+ // Lines are numbered the way the diff numbers them: from zero, a final
5
+ // newline ending the last line rather than starting an empty one.
6
+ import { hidesMixedWhitespace, lineBlocks } from '@preventive/compare/view.js'
7
+
8
+ export function textLines(text) {
9
+ if (text === '') return []
10
+ const lines = text.split('\n')
11
+ if (lines.at(-1) === '') lines.pop()
12
+ return lines
13
+ }
14
+
15
+ // Whether a text's last line ends in a newline. One added or dropped there is
16
+ // a change of that line, as diff has it (the viewer marks it on that line's
17
+ // row), but for diff -b, which ignores it as it does other trailing blanks.
18
+ const endsLine = text => text === '' || text.endsWith('\n')
19
+
20
+ // A line as diff -b reads it (@preventive/diff's): a run of the C locale's
21
+ // blanks as one space, and those that end it as none.
22
+ const spacing = line => line.replace(/[ \t\n\v\f\r]+$/u, '').replaceAll(/[ \t\n\v\f\r]+/gu, ' ')
23
+
24
+ // A text as `leading` reads it: a newline after its last line, as diff -b
25
+ // ignores one added or dropped there, then each line's indentation set aside;
26
+ // and a line as it reads one.
27
+ const INDENT = /(?<=^|\n)[ \t\v\f]+/gu
28
+ const unindent = text => (text === '' || text.endsWith('\n') ? text : `${text}\n`).replaceAll(INDENT, '')
29
+ const unindentLine = line => line.replace(/^[ \t\v\f]+/u, '')
30
+
31
+ // The fewest lines where that costs little to find; `ignoreWhitespace` diff -b (true), or `leading`, indentation alone.
32
+ export function changeBlocks(before, after, ignoreWhitespace = false) {
33
+ const leading = ignoreWhitespace === 'leading'
34
+ return lineBlocks(leading ? unindent(before) : before, leading ? unindent(after) : after, { horizon: 0, whitespace: ignoreWhitespace === true ? 'change' : 'none' })
35
+ }
36
+
37
+ // The blocks Compare draws with whitespace hidden: indentation set aside, but
38
+ // not where that would hide blanks of more than one kind changing.
39
+ export function indentHiddenBlocks(before, after) {
40
+ const blocks = changeBlocks(before, after, 'leading')
41
+ return hidesMixedWhitespace(before, after, blocks) ? changeBlocks(before, after) : blocks
42
+ }
43
+
44
+ // Two printed copies as Compare draws their diff, `{ before, after }`: each
45
+ // without those of its blank lines that are its layout alone (`blankBefore`,
46
+ // `blankAfter`, their numbers: @preventive/compare layoutBlankLines) that the
47
+ // other has none of there. The copies without any are diffed: a blank line
48
+ // stays between two lines that diff leaves alike, where both sides have one
49
+ // there (as many as the side with fewer), and between two lines of one change
50
+ // on its side; one beside a change, or that one side alone has, goes. A
51
+ // printer keeps one wherever the file it printed has one, so blank lines alone
52
+ // then change nothing; and each side drawn is its copy but for blank lines its
53
+ // layout alone holds, those kept drawn empty. A side with no numbers is ''.
54
+ export function withSharedBlankLines(before, after, blankBefore, blankAfter) {
55
+ if (blankBefore.length === 0 && blankAfter.length === 0) return { before, after }
56
+ const [a, b] = [[before, blankBefore], [after, blankAfter]].map(([text, blank]) => {
57
+ const gaps = [], layout = new Set(blank), lines = []
58
+ let run = 0
59
+ textLines(text).forEach((line, i) => {
60
+ if (layout.has(i)) run++
61
+ else {
62
+ lines.push(line)
63
+ gaps.push(run)
64
+ run = 0
65
+ }
66
+ })
67
+ return { lines, gaps, ends: text.endsWith('\n') }
68
+ })
69
+ const joined = (lines, ends) => (lines.length === 0 ? '' : `${lines.join('\n')}${ends ? '\n' : ''}`)
70
+ // Blank lines drawn before each line of either side without them.
71
+ const [keptA, keptB] = [a, b].map(side => side.gaps.map(() => 0))
72
+ let i = 0, j = 0
73
+ const end = { a0: a.lines.length, a1: a.lines.length, b0: b.lines.length, b1: b.lines.length }
74
+ for (const block of [...changeBlocks(joined(a.lines, a.ends), joined(b.lines, b.ends)), end]) {
75
+ // Lines alike, past the first after a change (or the start).
76
+ for (let k = i + 1, l = j + 1; k < block.a0; k++, l++) keptA[k] = keptB[l] = Math.min(a.gaps[k], b.gaps[l])
77
+ for (let k = block.a0 + 1; k < block.a1; k++) keptA[k] = a.gaps[k]
78
+ for (let k = block.b0 + 1; k < block.b1; k++) keptB[k] = b.gaps[k]
79
+ i = block.a1
80
+ j = block.b1
81
+ }
82
+ // A side as drawn, the text it came as where that is the same: kept by what keeps the drawn texts, a copy alone.
83
+ const drawn = (side, kept, text) => {
84
+ const out = joined(side.lines.map((line, k) => `${'\n'.repeat(kept[k])}${line}`), side.ends)
85
+ return out === text ? text : out
86
+ }
87
+ return { before: drawn(a, keptA, before), after: drawn(b, keptB, after) }
88
+ }
89
+
90
+ // A file that changed in types alone but for what runs (type-only.js
91
+ // typeProof), its types set aside: `before` and `after` the texts of each
92
+ // side's lines that run (`runs`, `otherRuns`, `[from, to)` each), diffed in
93
+ // place of the files' (`whole`); `lineOf` each of their lines' line in its file, and
94
+ // `lines` the file's count, for diffRows to show where the types stand. False
95
+ // where what runs reads alike on both sides, its types alone changed; else
96
+ // null where that would hide no change.
97
+ export function typeFolds(before, after, { runs, otherRuns }) {
98
+ const side = (text, ranges) => {
99
+ const lineOf = [], lines = textLines(text)
100
+ for (const [from, to] of ranges) for (let i = from; i < Math.min(to, lines.length); i++) lineOf.push(i)
101
+ const run = lineOf.map(i => lines[i]), shown = new Set(lineOf)
102
+ // A last line with no newline after it stays so where it is shown.
103
+ const open = text !== '' && !text.endsWith('\n') && lineOf.at(-1) === lines.length - 1
104
+ return { text: run.length === 0 ? '' : `${run.join('\n')}${open ? '' : '\n'}`, lineOf, lines: lines.length, run: run.join('\n'),
105
+ types: lines.filter((_, i) => !shown.has(i)).join('\n') }
106
+ }
107
+ const a = side(before, runs), b = side(after, otherRuns)
108
+ if (a.run === b.run) return false
109
+ if (a.types === b.types) return null
110
+ return { before: a.text, after: b.text, whole: { a: before, b: after }, lineOf: { a: a.lineOf, b: b.lineOf }, lines: { a: a.lines, b: b.lines } }
111
+ }
112
+
113
+ const NO_RUNS = Object.freeze([])
114
+ // Two printed copies' lines that run, as typeFolds takes them, where each kept
115
+ // them or has no text; else null.
116
+ export const copiesRuns = (a, b) => ([a, b].every(copy => copy.text === '' || copy.runs) ? { runs: a.runs ?? NO_RUNS, otherRuns: b.runs ?? NO_RUNS } : null)
117
+
118
+ // The lines `blocks` add and remove, but for those that are one of `marks`, counted apart (`renamed`, `marked`).
119
+ export function markedCounts(blocks, marks) {
120
+ const told = new Set((marks ?? []).map(({ a0, a1, b0, b1 }) => `${a0},${a1},${b0},${b1}`))
121
+ const marked = new Set()
122
+ let additions = 0, deletions = 0, renamed = 0
123
+ blocks.forEach(({ a0, a1, b0, b1 }, i) => {
124
+ if (told.has(`${a0},${a1},${b0},${b1}`) && a1 - a0 === b1 - b0) {
125
+ marked.add(i)
126
+ renamed += b1 - b0
127
+ } else {
128
+ additions += b1 - b0
129
+ deletions += a1 - a0
130
+ }
131
+ })
132
+ return { additions, deletions, renamed, marked }
133
+ }
134
+
135
+ const MARK = /[\p{L}\p{N}_$]+|\S/gu
136
+
137
+ // How much two texts' diff changes, `{ marks, lines }`: its lines removed and added, and its words and other
138
+ // characters but blanks (MARK) a block removes or adds and doesn't put back elsewhere in it, as a printer's
139
+ // semicolon changes a mark and no line. Whitespace hidden as the view hides it (mixed blanks shown).
140
+ export function diffSize(before, after, ignoreWhitespace = false) {
141
+ const a = textLines(before), b = textLines(after)
142
+ let blocks = changeBlocks(before, after, ignoreWhitespace), lines = 0, marks = 0
143
+ if (ignoreWhitespace && hidesMixedWhitespace(before, after, blocks)) blocks = changeBlocks(before, after)
144
+ for (const { a0, a1, b0, b1 } of blocks) {
145
+ const counts = new Map()
146
+ for (let i = a0; i < a1; i++) for (const [mark] of a[i].matchAll(MARK)) counts.set(mark, (counts.get(mark) ?? 0) + 1)
147
+ for (let j = b0; j < b1; j++) for (const [mark] of b[j].matchAll(MARK)) counts.set(mark, (counts.get(mark) ?? 0) - 1)
148
+ for (const count of counts.values()) marks += Math.abs(count)
149
+ lines += a1 - a0 + b1 - b0
150
+ }
151
+ return { marks, lines }
152
+ }
153
+
154
+ // Past these a diff is computed only when asked, as one of lines that share nothing takes seconds.
155
+ const LARGE_LINES = 100_000
156
+ const LARGE_CHARS = 16 * 1024 * 1024
157
+ const lineEnds = text => {
158
+ let count = 0
159
+ for (let at = text.indexOf('\n'); at !== -1; at = text.indexOf('\n', at + 1)) count++
160
+ return count
161
+ }
162
+ export const isLargeDiff = (before, after) => before.length + after.length > LARGE_CHARS || lineEnds(before) + lineEnds(after) > LARGE_LINES
163
+
164
+ // Whether `blocks` take `before`'s lines to `after`'s: each in order and apart
165
+ // from the last, within both texts, and every line between them alike on both
166
+ // sides (alike but for how much whitespace they have where `ignoreWhitespace`,
167
+ // as diff -b has them, or for their indentation where it is `leading`), the
168
+ // last line in a block where a newline was added or
169
+ // dropped after it, so that a diff drawn from them hides no change. A check on
170
+ // what changeBlocks found, or on one found apart from the texts drawn.
171
+ export function blocksHold(before, after, blocks, ignoreWhitespace = false) {
172
+ if (!Array.isArray(blocks)) return false
173
+ const a = textLines(before), b = textLines(after)
174
+ const read = ignoreWhitespace === 'leading' ? unindentLine : ignoreWhitespace ? spacing : null
175
+ const alike = read ? (x, y) => read(x) === read(y) : (x, y) => x === y
176
+ let i = 0, j = 0
177
+ for (const block of [...blocks, { a0: a.length, a1: a.length, b0: b.length, b1: b.length, last: true }]) {
178
+ const { a0, a1, b0, b1 } = block ?? {}
179
+ if (![a0, a1, b0, b1].every(Number.isInteger) || a0 < i || b0 < j || a1 < a0 || b1 < b0 || a1 > a.length || b1 > b.length) return false
180
+ // A block changes a line, and as many lines are alike before it on each side.
181
+ if ((!block.last && a1 === a0 && b1 === b0) || a0 - i !== b0 - j) return false
182
+ if (block.last && a0 > i && !ignoreWhitespace && endsLine(before) !== endsLine(after)) return false
183
+ for (; i < a0; i++, j++) if (!alike(a[i], b[j])) return false
184
+ i = a1
185
+ j = b1
186
+ }
187
+ return true
188
+ }
@@ -0,0 +1,63 @@
1
+ // Explicit links combine already-resolved workspace App rows. This is a view
2
+ // grouping, not report deduplication: each report's revalidation answer has
3
+ // already been checked in its own row, and links never create report conflicts.
4
+ //
5
+ // `visibleTabs` decides which tabs may BRIDGE two rows; `retainedTabs` (the
6
+ // same projection unless the caller says otherwise) decides which tabs the
7
+ // combined row keeps. They part when a display choice shows a row more of
8
+ // itself without meaning to re-draw the workspace's row boundaries.
9
+ export function mergeLinkedWorkspaceGroups(groups, duplicatesOf, visibleTabs, retainedTabs = visibleTabs) {
10
+ const parent = groups.map((_, i) => i)
11
+ const find = (i) => {
12
+ while (parent[i] !== i) { parent[i] = parent[parent[i]]; i = parent[i] }
13
+ return i
14
+ }
15
+ const tabs = groups.map(visibleTabs)
16
+ const byId = new Map()
17
+ for (let i = 0; i < tabs.length; i++) {
18
+ for (const f of tabs[i]) {
19
+ if (!f.id) continue
20
+ if (!byId.has(f.id)) byId.set(f.id, [])
21
+ byId.get(f.id).push(i)
22
+ }
23
+ }
24
+ for (const [id, rows] of byId) {
25
+ for (const other of duplicatesOf(id)) {
26
+ if (other === id) continue
27
+ for (const a of rows) {
28
+ for (const b of byId.get(other) ?? []) {
29
+ const left = find(a), right = find(b)
30
+ if (left !== right) parent[right] = left
31
+ }
32
+ }
33
+ }
34
+ }
35
+ const components = new Map()
36
+ for (let i = 0; i < groups.length; i++) {
37
+ const root = find(i)
38
+ if (!components.has(root)) components.set(root, [])
39
+ components.get(root).push(i)
40
+ }
41
+ if (components.size === groups.length) return groups
42
+ const key = (f) => f.id ?? String(f._id)
43
+ const merged = [...components.values()].map((indices) => {
44
+ if (indices.length === 1) return groups[indices[0]]
45
+ // Retain the tabs visible in each original row. An imported App finding
46
+ // or an unjudged source row must not disappear when linked to a pass row.
47
+ const visible = new Map()
48
+ for (const i of indices) for (const f of retainedTabs(groups[i])) if (!visible.has(key(f))) visible.set(key(f), f)
49
+ const members = new Map()
50
+ for (const i of indices) {
51
+ for (const f of groups[i]) {
52
+ if (!members.has(key(f))) members.set(key(f), visible.get(key(f)) ?? f)
53
+ }
54
+ }
55
+ const group = [...members.values()]
56
+ const first = groups[indices[0]]
57
+ group.workspaceKey = first.workspaceKey ?? key(first[0])
58
+ group.linkedTabs = [...visible.values()]
59
+ return group
60
+ })
61
+ Object.defineProperty(merged, 'ruledOutIds', { value: groups.ruledOutIds, configurable: true })
62
+ return merged
63
+ }
@@ -0,0 +1,292 @@
1
+ // Agents' sessions and their tasks, reconstructed from what each
2
+ // leaves on GitHub (the code viewer's Agents tab, repository-agents.js): a
3
+ // task is a pull request it opened, or a commit it pushed to the default
4
+ // branch without one; a session holds as many as name it, with the branches
5
+ // they are on and the issues they work on. The server reads each artifact's
6
+ // own texts, never others' comments on it (a pull request's body and its
7
+ // head and merge commits' messages, where an agent links its session; a
8
+ // commit's message; a branch's tip commit) for the marks an agent leaves
9
+ // (agentSignals), sending those alone; agentSessions then groups them:
10
+ // those naming one session, a pull request with its branch, a branch with
11
+ // the session its commits name, an issue with the pull requests closing it
12
+ // or a branch named for it. Without a session named, a branch's pull
13
+ // requests are one session, and a commit its own.
14
+ //
15
+ // The agents are Claude and Codex, and those the server knows by their GitHub
16
+ // Apps or accounts (server-managed/app-agents.ts APP_AGENTS): each told by its
17
+ // fingerprint, a line of its texts, by the account its work is authored by
18
+ // (github-agents.ts githubAgent), or by its branches' prefix, the server's to
19
+ // read, and named to the client
20
+ // by its id, name and avatar (AppAgent). Such an agent names no session:
21
+ // a pull request of its is a session alone, with its branch; Claude's or
22
+ // Codex's marks on its work show those as its tools. A pull request labelled
23
+ // for an agent (labelAgents) is that agent's too, where its own texts and
24
+ // branch name none: the mark one who ran it gives work it left unmarked.
25
+ import { githubAgent } from './github-agents.ts'
26
+
27
+ // 'claude', 'codex', or an app agent's id.
28
+ export type Agent = string
29
+
30
+ // An agent known by its GitHub App or account, as the server names it to the
31
+ // client: its id, its name, and its avatar, its mark (/api/avatar/<avatar>:
32
+ // `app-<id>` a GitHub App's, `user-<id>` a GitHub account's), where the app
33
+ // draws no mark of its own for it (Copilot's, ui/view/repository-tiles.js).
34
+ export interface AppAgent { id: string; name: string; avatar?: string }
35
+ // How the server tells one, beside the accounts its work is authored by (its
36
+ // id githubAgent's): its fingerprint, a line of an artifact's texts starting
37
+ // with it; its branches' prefix.
38
+ export interface AppAgentMarks { id: string; fingerprint?: string; prefix: string }
39
+ // An artifact's author, as GitHub names its account: its login and id.
40
+ export interface AgentAuthor { login: string; id: number }
41
+
42
+ // What an artifact's texts say of the agents that made it: the Claude Code
43
+ // sessions and Codex tasks they link, whether they carry Claude's marks,
44
+ // its co-author trailer or its "Generated with" line, and Codex's, its
45
+ // co-author trailer, and the app agents whose fingerprints they carry, or
46
+ // whose branch it is.
47
+ export interface AgentSignals { sessions: string[]; tasks: string[]; claude: boolean; codex: boolean; agents: string[] }
48
+
49
+ // Each by its author's login, and their account's numeric id (`authorId`)
50
+ // where GitHub names it.
51
+ export interface AgentPull { number: number; title: string; state: 'open' | 'merged' | 'closed'; draft: boolean; author: string | null; authorId?: number | null
52
+ // Its branch, and the owner of the fork it is in, null where it is in the
53
+ // repository itself.
54
+ createdAt: number | null; updatedAt: number | null; head: string | null; fork: string | null; additions: number; deletions: number; commits: number
55
+ closes: number[]; signals: AgentSignals }
56
+ export interface AgentIssue { number: number; title: string; state: 'open' | 'closed'; author: string | null; authorId?: number | null; createdAt: number | null; updatedAt: number | null }
57
+ export interface AgentBranch { name: string; at: number | null; author: string | null; authorId?: number | null; signals: AgentSignals }
58
+ // A commit to the default branch no pull request merged.
59
+ export interface AgentCommit { oid: string; title: string; at: number | null; author: string | null; authorId?: number | null; additions: number; deletions: number
60
+ signals: AgentSignals }
61
+
62
+ export interface AgentSession {
63
+ id: string
64
+ agents: Agent[]
65
+ // Where to open it: a Claude Code session or a Codex task.
66
+ sessions: string[]
67
+ tasks: string[]
68
+ title: string
69
+ authors: string[]
70
+ startedAt: number | null
71
+ updatedAt: number | null
72
+ state: 'open' | 'merged' | 'closed' | 'branch'
73
+ // Its tasks: the pull requests it opened, and the commits it pushed to
74
+ // the default branch, the newest first.
75
+ pulls: Pick<AgentPull, 'number' | 'title' | 'state' | 'draft'>[]
76
+ commits: Pick<AgentCommit, 'oid' | 'title'>[]
77
+ issues: Pick<AgentIssue, 'number' | 'title' | 'state'>[]
78
+ branches: string[]
79
+ // The commits its pull requests hold, and their lines and its commits'.
80
+ commitCount: number
81
+ additions: number
82
+ deletions: number
83
+ }
84
+
85
+ const SESSION = /https:\/\/claude\.ai\/code\/(session_[A-Za-z\d]{6,64})\b/gu
86
+ const CODEX_TASK = /https:\/\/chatgpt\.com\/codex\/tasks\/(task_[a-z]_[A-Za-z\d]{6,64})\b/gu
87
+ // Claude's marks on its commits and pull requests: its co-author trailer,
88
+ // its "Generated with" line, its session trailer.
89
+ const CLAUDE_MARK = /^co-authored-by: claude\b|generated with \[claude code\]|^claude-session:/imu
90
+ // Codex's: its co-author trailer, by its address, as Codex names itself
91
+ // co-author of the commits it makes as whoever ran it; a trailer of a text's
92
+ // trailers (trailerBlock), not a line before them that shows one.
93
+ const CODEX_MARK = /^co-authored-by:[ \t]*[^<\n]*<codex@openai\.com>[ \t]*$/imu
94
+ const MAX_LINKS = 8
95
+
96
+ // A message's trailers, as git reads them (`git interpret-trailers`): its
97
+ // last paragraph, past its subject's, where each of its lines is a trailer
98
+ // (`Key: value`) or goes on with one (indented), or, where it holds git's
99
+ // own `Signed-off-by:`, a quarter of them are; none where it isn't, as
100
+ // lines a description or example holds, fenced or not, are not.
101
+ const TRAILER_LINE = /^[A-Za-z\d-]+[ \t]*:/u
102
+ export function trailerBlock(text: string): string {
103
+ const paragraphs = text.replaceAll('\r\n', '\n').trim().split(/\n[ \t]*\n/u)
104
+ const block = paragraphs.length > 1 ? paragraphs.at(-1)! : ''
105
+ const lines = block.split('\n')
106
+ const trailers = lines.filter(line => TRAILER_LINE.test(line)).length
107
+ const others = lines.filter((line, at) => !TRAILER_LINE.test(line) && !(at > 0 && /^[ \t]/u.test(line))).length
108
+ return others === 0 || (lines.some(line => /^signed-off-by[ \t]*:/iu.test(line)) && trailers * 3 >= others) ? block : ''
109
+ }
110
+
111
+ // The agents of those whose ids are `ids` that `labels` name (a pull
112
+ // request's): a label an agent's id, regardless of case, alone or after
113
+ // `agent:` or `agent/` (`Codex`, `agent: claude`).
114
+ const LABEL = /^(?:agent[:/] ?)?([a-z][a-z\d-]*)$/u
115
+ export function labelAgents(labels: unknown[], ids: readonly string[]): Agent[] {
116
+ return [...new Set(labels.flatMap(label => {
117
+ const id = typeof label === 'string' ? LABEL.exec(label.trim().toLowerCase())?.[1] : undefined
118
+ return id !== undefined && ids.includes(id) ? [id] : []
119
+ }))]
120
+ }
121
+
122
+ // The sessions and tasks `texts` link, whether they carry Claude's marks and
123
+ // Codex's, and the agents of `apps` whose fingerprints start a line of them
124
+ // (not one a text quotes, as one describing it may), whose account `author`
125
+ // is (githubAgent), or whose prefix the branch `branch` is under;
126
+ // Claude, Codex or the agents of `apps` its `labels` name (labelAgents).
127
+ export function agentSignals(texts: unknown[], apps: readonly AppAgentMarks[] = [], branch: string | null = null,
128
+ author: AgentAuthor | null = null, labels: unknown[] = []): AgentSignals {
129
+ const strings = texts.filter((text): text is string => typeof text === 'string')
130
+ const found = (pattern: RegExp) => [...new Set(strings.flatMap(text => [...text.matchAll(pattern)].map(match => match[1]!)))].slice(0, MAX_LINKS)
131
+ const lines = strings.flatMap(text => text.split('\n').map(line => line.trimStart()))
132
+ const authored = author ? githubAgent(author.login, author.id) : null
133
+ const labelled = labelAgents(labels, ['claude', 'codex', ...apps.map(app => app.id)])
134
+ return { sessions: found(SESSION), tasks: found(CODEX_TASK), claude: labelled.includes('claude') || strings.some(text => CLAUDE_MARK.test(text)),
135
+ codex: labelled.includes('codex') || strings.some(text => CODEX_MARK.test(trailerBlock(text))),
136
+ agents: apps.filter(app => (app.fingerprint && lines.some(line => line.startsWith(app.fingerprint!)))
137
+ || authored === app.id || branch?.startsWith(app.prefix) || labelled.includes(app.id)).map(app => app.id) }
138
+ }
139
+
140
+ // The agent a branch's name says made it, and the issue or pull request the
141
+ // Claude GitHub App names its branch for (`claude/issue-12-…`).
142
+ export function agentBranch(name: string | null): { agent: Agent | null; issue: number | null; pull: number | null } {
143
+ const agent = name?.startsWith('claude/') ? 'claude' : name?.startsWith('codex/') ? 'codex' : null
144
+ const named = agent === 'claude' ? /^claude\/(issue|pr)-([1-9]\d{0,9})-/u.exec(name!) : null
145
+ return { agent, issue: named?.[1] === 'issue' ? Number(named[2]) : null, pull: named?.[1] === 'pr' ? Number(named[2]) : null }
146
+ }
147
+
148
+ // A pull request's branch, as GitHub names one in a fork: `owner:branch`;
149
+ // two forks' of one name, or a fork's and the repository's, are two.
150
+ const headName = (pull: AgentPull) => pull.head && pull.fork ? `${pull.fork}:${pull.head}` : pull.head
151
+
152
+ const signalAgents = (signals: AgentSignals): Agent[] => [...signals.agents, ...signals.sessions.length > 0 || signals.claude ? ['claude'] : [],
153
+ ...signals.tasks.length > 0 || signals.codex ? ['codex'] : []]
154
+ const TOOLS = new Set(['claude', 'codex'])
155
+
156
+ type Artifacts = { pulls?: AgentPull[]; commits?: AgentCommit[]; issues?: AgentIssue[]; branches?: AgentBranch[] }
157
+ type Group = { agents: Set<Agent>; keys: string[] }
158
+
159
+ // The artifacts joined (`pull:<n>`, `commit:<oid>`, `branch:<name>`,
160
+ // `session:<id>`, `task:<id>`), each set with the agents whose marks are on
161
+ // them: by the sessions and tasks they link and the branches pull requests
162
+ // are from. An app agent's join none by what they link, and a pull request
163
+ // of its its branch alone, where no pull request newer is from it, an app
164
+ // agent's or another's: one a session.
165
+ function artifactGroups({ pulls = [], commits = [], branches = [] }: Artifacts): Group[] {
166
+ const parent = new Map<string, string>()
167
+ const find = (key: string): string => {
168
+ let root = key
169
+ while (parent.has(root) && parent.get(root) !== root) root = parent.get(root)!
170
+ parent.set(key, root)
171
+ return root
172
+ }
173
+ const join = (a: string, b: string) => {
174
+ const [x, y] = [find(a), find(b)]
175
+ if (x !== y) parent.set(y, x)
176
+ }
177
+ const agentsOf = new Map<string, Set<Agent>>()
178
+ const mark = (key: string, agents: Agent[]) => { for (const agent of agents) agentsOf.set(key, new Set([...agentsOf.get(key) ?? [], agent])) }
179
+ const linked = (key: string, signals: AgentSignals) => {
180
+ find(key)
181
+ if (signals.agents.length === 0) for (const session of signals.sessions) join(key, `session:${session}`)
182
+ if (signals.agents.length === 0) for (const task of signals.tasks) join(key, `task:${task}`)
183
+ mark(key, signalAgents(signals))
184
+ }
185
+ const branchNames = new Set(branches.map(branch => branch.name))
186
+ for (const branch of branches) {
187
+ const key = `branch:${branch.name}`
188
+ linked(key, branch.signals)
189
+ const { agent } = agentBranch(branch.name)
190
+ if (agent) mark(key, [agent])
191
+ }
192
+ // The newest pull request read from each branch, by its number, as GitHub
193
+ // numbers them as they are opened: they are read as they were updated.
194
+ const newest = new Map<string, number>()
195
+ for (const pull of pulls) {
196
+ const head = headName(pull)
197
+ if (head !== null && pull.number > (newest.get(head) ?? 0)) newest.set(head, pull.number)
198
+ }
199
+ for (const pull of pulls) {
200
+ const key = `pull:${pull.number}`
201
+ linked(key, pull.signals)
202
+ const { agent, pull: named } = agentBranch(pull.head)
203
+ if (agent) mark(key, [agent])
204
+ // Its branch, an agent's or its own, read or not; a fork's its own.
205
+ const head = headName(pull)
206
+ if (pull.signals.agents.length > 0) {
207
+ if (head !== null && newest.get(head) === pull.number) join(key, `branch:${head}`)
208
+ continue
209
+ }
210
+ if (head && (agent || signalAgents(pull.signals).length > 0 || branchNames.has(head))) join(key, `branch:${head}`)
211
+ if (named) join(key, `pull:${named}`)
212
+ }
213
+ for (const commit of commits) linked(`commit:${commit.oid}`, commit.signals)
214
+
215
+ const groups = new Map<string, Group>()
216
+ for (const key of parent.keys()) {
217
+ const root = find(key)
218
+ const group = groups.get(root) ?? { agents: new Set(), keys: [] }
219
+ group.keys.push(key)
220
+ for (const agent of agentsOf.get(key) ?? []) group.agents.add(agent)
221
+ groups.set(root, group)
222
+ }
223
+ return [...groups.values()]
224
+ }
225
+
226
+ const byTime = <T>(time: (item: T) => number | null) => (a: T, b: T) => (time(a) ?? 0) - (time(b) ?? 0)
227
+
228
+ // The session a group of artifacts is, its tasks and what they touched; null
229
+ // for one no agent left marks on, or holding none read.
230
+ function sessionOf({ agents, keys }: Group, { pulls, commits, issues, branches }: {
231
+ pulls: Map<number, AgentPull>; commits: Map<string, AgentCommit>; issues: Map<number, AgentIssue>; branches: Map<string, AgentBranch> }): AgentSession | null {
232
+ if (agents.size === 0) return null
233
+ const of = (prefix: string) => keys.filter(key => key.startsWith(prefix)).map(key => key.slice(prefix.length))
234
+ const taskPulls = of('pull:').flatMap(number => pulls.get(Number(number)) ?? []).toSorted(byTime(pull => pull.createdAt))
235
+ const taskCommits = of('commit:').flatMap(oid => commits.get(oid) ?? []).toSorted(byTime(commit => commit.at))
236
+ const names = [...new Set([...of('branch:'), ...taskPulls.flatMap(pull => headName(pull) ?? [])])]
237
+ // The issues its pull requests close, and those its branches are named
238
+ // for, by a pull request's own name for its branch, a fork's too.
239
+ const issueNumbers = new Set([...taskPulls.flatMap(pull => pull.closes),
240
+ ...taskPulls.flatMap(pull => agentBranch(pull.head).issue ?? []), ...of('branch:').flatMap(name => agentBranch(name).issue ?? [])])
241
+ const taskIssues = [...issueNumbers].flatMap(number => issues.get(number) ?? []).toSorted(byTime(issue => issue.createdAt))
242
+ const taskBranches = names.flatMap(name => branches.get(name) ?? [])
243
+ const items = [...taskPulls, ...taskCommits, ...taskIssues, ...taskBranches]
244
+ if (items.length === 0) return null
245
+ const [codexTasks, sessions] = [of('task:'), of('session:')]
246
+ const started = items.flatMap(item => ('createdAt' in item ? item.createdAt : item.at) ?? [])
247
+ const updated = items.flatMap(item => ('updatedAt' in item ? item.updatedAt : item.at) ?? [])
248
+ const states = new Set(taskPulls.map(pull => pull.state))
249
+ // Its first task names it: the earliest of its pull requests and commits.
250
+ const first = [...taskPulls.map(pull => ({ at: pull.createdAt, title: pull.title })), ...taskCommits.map(commit => ({ at: commit.at, title: commit.title }))]
251
+ .toSorted(byTime(task => task.at))[0]
252
+ const landed = [...taskPulls, ...taskCommits]
253
+ return {
254
+ id: sessions[0] ?? codexTasks[0] ?? (taskPulls[0] ? `pull-${taskPulls[0].number}` : taskCommits[0]?.oid ?? names[0] ?? ''),
255
+ // An app agent's first, the one whose session it is, then the tools it
256
+ // used, Claude's or Codex's.
257
+ agents: [...[...agents].filter(agent => !TOOLS.has(agent)), ...['claude', 'codex'].filter(agent => agents.has(agent))],
258
+ sessions, tasks: codexTasks,
259
+ title: first?.title ?? taskIssues[0]?.title ?? names[0] ?? '',
260
+ authors: [...new Set(items.flatMap(item => item.author ?? []))],
261
+ startedAt: started.length > 0 ? Math.min(...started) : null,
262
+ updatedAt: updated.length > 0 ? Math.max(...updated) : null,
263
+ state: states.has('open') ? 'open' : states.has('merged') || taskCommits.length > 0 ? 'merged' : states.has('closed') ? 'closed' : 'branch',
264
+ pulls: taskPulls.map(({ number, title, state, draft }) => ({ number, title, state, draft })).toReversed(),
265
+ commits: taskCommits.map(({ oid, title }) => ({ oid, title })).toReversed(),
266
+ issues: taskIssues.map(({ number, title, state }) => ({ number, title, state })),
267
+ branches: names,
268
+ commitCount: taskPulls.reduce((sum, pull) => sum + pull.commits, 0) + taskCommits.length,
269
+ additions: landed.reduce((sum, item) => sum + item.additions, 0),
270
+ deletions: landed.reduce((sum, item) => sum + item.deletions, 0),
271
+ }
272
+ }
273
+
274
+ // The sessions `pulls`, `commits`, `issues` and `branches` make, the most
275
+ // recently updated first: each a set of them, joined by the sessions and
276
+ // tasks they link and the branches pull requests are from, with the issues
277
+ // a pull request closes or a branch is named for.
278
+ // Artifacts no agent left marks on belong to none. Where pull requests
279
+ // updated before `branchesSince` are yet to be read, a session of branches
280
+ // alone older than that waits for them: its pull request may be among them.
281
+ export function agentSessions(artifacts: Artifacts, { branchesSince = null }: { branchesSince?: number | null } = {}): AgentSession[] {
282
+ const lookups = {
283
+ pulls: new Map((artifacts.pulls ?? []).map(pull => [pull.number, pull])),
284
+ commits: new Map((artifacts.commits ?? []).map(commit => [commit.oid, commit])),
285
+ issues: new Map((artifacts.issues ?? []).map(issue => [issue.number, issue])),
286
+ branches: new Map((artifacts.branches ?? []).map(branch => [branch.name, branch])),
287
+ }
288
+ const waiting = (session: AgentSession) => branchesSince !== null && session.pulls.length === 0 && session.commits.length === 0
289
+ && (session.updatedAt ?? 0) < branchesSince
290
+ return artifactGroups(artifacts).flatMap(group => sessionOf(group, lookups) ?? []).filter(session => !waiting(session))
291
+ .toSorted(byTime(session => session.updatedAt)).toReversed()
292
+ }