@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80

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 (442) 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 +377 -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 +66 -0
  35. package/common/default-scan-models.ts +36 -0
  36. package/common/dependency-reviews.d.ts +18 -0
  37. package/common/dependency-reviews.js +64 -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 +1 -0
  44. package/common/github-issue-labels.js +11 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +14 -0
  48. package/common/line-diff.js +181 -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 +41 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +385 -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/pretty-json.js +98 -0
  81. package/common/pretty-kinds.js +20 -0
  82. package/common/pretty-print.d.ts +6 -0
  83. package/common/pretty-print.js +36 -0
  84. package/common/pretty-sourcemap.js +70 -0
  85. package/common/repo-commit.d.ts +4 -0
  86. package/common/repo-commit.js +30 -0
  87. package/common/revalidation-conflicts.js +48 -0
  88. package/common/revalidation-input-groups.js +56 -0
  89. package/common/save-error-reason.ts +20 -7
  90. package/common/scan-server.ts +13 -0
  91. package/common/security-links.d.ts +5 -0
  92. package/common/security-links.js +33 -0
  93. package/common/server-info.ts +46 -0
  94. package/common/sourcemap-listing.js +78 -0
  95. package/common/sourcemap-mappings.js +136 -0
  96. package/common/sourcemap-unlist.js +85 -0
  97. package/common/stasis-files.d.ts +5 -0
  98. package/common/stasis-files.js +20 -0
  99. package/common/stasis-tgz.d.ts +6 -0
  100. package/common/stasis-tgz.js +27 -0
  101. package/common/utf8.d.ts +3 -0
  102. package/common/utf8.js +45 -0
  103. package/common/whitespace-insensitive.js +19 -0
  104. package/common/workspace-app.js +91 -0
  105. package/common/workspace-groups.js +176 -0
  106. package/out/activity.js +2 -0
  107. package/out/brotli-fallback.js +3 -3
  108. package/out/chunk-2XUEZHIP.js +28 -0
  109. package/out/chunk-55YIWY3H.js +5 -0
  110. package/out/chunk-5AVGKFMR.js +1 -0
  111. package/out/chunk-5CJKUV53.js +1 -0
  112. package/out/chunk-5EAVJAD2.js +3 -0
  113. package/out/chunk-5M2X3QPK.js +6 -0
  114. package/out/chunk-5QWPKTCE.js +40 -0
  115. package/out/chunk-6CCSTJWB.js +1 -0
  116. package/out/chunk-6VOB5WXX.js +2 -0
  117. package/out/chunk-6Y6PZ2BU.js +9 -0
  118. package/out/chunk-74JZTGTO.js +11 -0
  119. package/out/chunk-7BKKYVWR.js +7 -0
  120. package/out/chunk-7C7DWL7I.js +1 -0
  121. package/out/chunk-7HP2VYIC.js +2 -0
  122. package/out/chunk-7YFJUT2P.js +1 -0
  123. package/out/chunk-7YO4QV5P.js +1 -0
  124. package/out/chunk-A4BBBHQU.js +1 -0
  125. package/out/chunk-B64CTMVU.js +4 -0
  126. package/out/chunk-BEKYZCPX.js +14 -0
  127. package/out/chunk-C4Z6ZBXV.js +10 -0
  128. package/out/chunk-CU3FPB3P.js +1 -0
  129. package/out/chunk-DEVAORP2.js +1 -0
  130. package/out/chunk-DUASGS2O.js +8 -0
  131. package/out/chunk-DUS5ARE2.js +53 -0
  132. package/out/chunk-EEJA7JBI.js +13 -0
  133. package/out/chunk-FSU2PLJL.js +1 -0
  134. package/out/chunk-GBMAXAYK.js +3 -0
  135. package/out/chunk-GO7FT4OD.js +1 -0
  136. package/out/chunk-GX5UXWT4.js +1 -0
  137. package/out/chunk-ITUKKCCK.js +10 -0
  138. package/out/chunk-IYPY47MC.js +1 -0
  139. package/out/chunk-JXBRWLMA.js +4 -0
  140. package/out/chunk-K4XJHM2T.js +1 -0
  141. package/out/chunk-LBD3M3J6.js +1 -0
  142. package/out/chunk-LVSLM7HB.js +1 -0
  143. package/out/chunk-LVW7WWV4.js +1 -0
  144. package/out/chunk-MV66NL3G.js +3 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OOJM4CTU.js +1 -0
  148. package/out/chunk-OWSEQOL5.js +1 -0
  149. package/out/chunk-PKLVXUEI.js +11 -0
  150. package/out/chunk-PLGH63UC.js +2 -0
  151. package/out/chunk-PNHBZGDD.js +1 -0
  152. package/out/chunk-PTFYDJUP.js +1 -0
  153. package/out/chunk-PWFUOLZK.js +17 -0
  154. package/out/chunk-PXK7EU4V.js +1 -0
  155. package/out/chunk-QD3IBSF4.js +7 -0
  156. package/out/chunk-QI66YA4F.js +1 -0
  157. package/out/chunk-QRKFPLA4.js +80 -0
  158. package/out/chunk-R3NZFXVR.js +1 -0
  159. package/out/chunk-R5O6FAW4.js +2 -0
  160. package/out/chunk-RPNO56H2.js +1 -0
  161. package/out/chunk-SSPDMA6D.js +1 -0
  162. package/out/chunk-SZWPYLPC.js +1 -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-VHEXSGGP.js +1 -0
  168. package/out/chunk-VYYUMYVW.js +9 -0
  169. package/out/chunk-VZPPX6MV.js +1 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-XM4RLC4A.js +2 -0
  172. package/out/chunk-YKCRCNYZ.js +266 -0
  173. package/out/chunk-ZQHLECTI.js +1 -0
  174. package/out/client-managed-import.js +4 -0
  175. package/out/client-managed.js +37 -0
  176. package/out/client-sync.js +11 -17
  177. package/out/compare.js +26 -0
  178. package/out/dialogs.js +40 -0
  179. package/out/github-issue-authorized.html +3 -0
  180. package/out/github-issue-authorized.js +1 -0
  181. package/out/graph.js +19 -4
  182. package/out/index.html +104 -24
  183. package/out/prism.js +14 -10
  184. package/out/scan.js +2 -0
  185. package/out/stasis.svg +20 -0
  186. package/out/terminal.js +367 -39
  187. package/out/view.css +1 -1
  188. package/out/view.js +19 -147
  189. package/package.json +409 -64
  190. package/risk/actions/findings.js +161 -0
  191. package/risk/actions/resolve.js +287 -0
  192. package/risk/actions/scripts/commands.js +182 -0
  193. package/risk/actions/scripts/grade.js +113 -0
  194. package/risk/actions/scripts/packages.js +123 -0
  195. package/risk/actions/scripts/shell.js +169 -0
  196. package/risk/actions/uses.js +94 -0
  197. package/risk/actions/workflow.js +183 -0
  198. package/risk/files/characters.js +341 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +563 -0
  202. package/risk/files/script.js +402 -0
  203. package/risk/files/source-map-link.js +43 -0
  204. package/risk/files/stamps.js +47 -0
  205. package/risk/index.d.ts +294 -0
  206. package/risk/index.js +12 -0
  207. package/risk/npm/assess.js +285 -0
  208. package/risk/npm/combined.js +68 -0
  209. package/risk/npm/compare.js +236 -0
  210. package/risk/npm/dependencies.js +172 -0
  211. package/risk/npm/diff.js +79 -0
  212. package/risk/npm/downloads.js +84 -0
  213. package/risk/npm/files.js +445 -0
  214. package/risk/npm/held.js +67 -0
  215. package/risk/npm/install-scripts.js +34 -0
  216. package/risk/npm/malware.js +38 -0
  217. package/risk/npm/manifest.js +65 -0
  218. package/risk/npm/new-dependency.js +60 -0
  219. package/risk/npm/old-version.js +108 -0
  220. package/risk/npm/registry.js +393 -0
  221. package/risk/npm/release.js +85 -0
  222. package/risk/npm/score.js +59 -0
  223. package/risk/npm/specs.js +124 -0
  224. package/risk/npm/tarball.js +169 -0
  225. package/server-common/database-config.ts +16 -0
  226. package/server-common/initialize.ts +18 -0
  227. package/server-common/npm-advisories.ts +101 -0
  228. package/{server → server-common}/origin.ts +5 -5
  229. package/server-common/reap.ts +48 -0
  230. package/server-common/scan-config.ts +19 -0
  231. package/server-common/standalone.ts +29 -0
  232. package/server-common/storage-crypto.ts +182 -0
  233. package/server-common/storage-log.ts +38 -0
  234. package/server-common/vercel-blob.ts +103 -0
  235. package/server-e2e/app.ts +487 -0
  236. package/{server → server-e2e}/bus-receiver.ts +2 -1
  237. package/{server → server-e2e}/cli.js +9 -4
  238. package/{server → server-e2e}/config.ts +50 -42
  239. package/{server → server-e2e}/db-neon.ts +2 -2
  240. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  241. package/{server → server-e2e}/db-stmt.ts +2 -2
  242. package/{server → server-e2e}/db.ts +7 -7
  243. package/{server → server-e2e}/http.ts +44 -13
  244. package/{server → server-e2e}/hub.ts +40 -9
  245. package/server-e2e/index.ts +17 -0
  246. package/server-e2e/lifecycle.ts +95 -0
  247. package/{server → server-e2e}/neon-driver.ts +2 -2
  248. package/{server → server-e2e}/npm-proxy.ts +12 -145
  249. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  250. package/{server → server-e2e}/objstore/blob.ts +1 -1
  251. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  252. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  253. package/{server → server-e2e}/objstore/init.ts +19 -27
  254. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  255. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  257. package/{server → server-e2e}/objstore/rest.ts +3 -3
  258. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  259. package/{server → server-e2e}/objstore/store.ts +7 -7
  260. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  261. package/{server → server-e2e}/pubsub.ts +12 -9
  262. package/{server → server-e2e}/sign.ts +4 -4
  263. package/{server → server-e2e}/sse-server.ts +60 -33
  264. package/{server → server-e2e}/static.ts +18 -17
  265. package/{server → server-e2e}/sync-handlers.ts +64 -30
  266. package/{server → server-e2e}/ws-server.ts +20 -9
  267. package/server-managed/activity.ts +247 -0
  268. package/server-managed/agent-merges.ts +109 -0
  269. package/server-managed/app-agents.ts +23 -0
  270. package/server-managed/avatar-store.ts +13 -0
  271. package/server-managed/blob-store.ts +26 -0
  272. package/server-managed/brotli.ts +10 -0
  273. package/server-managed/bundle-advisories.ts +79 -0
  274. package/server-managed/bundle-advisory-inventory.ts +85 -0
  275. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  276. package/server-managed/bundle-build-diagnostics.js +23 -0
  277. package/server-managed/bundle-build-leases.ts +41 -0
  278. package/server-managed/bundle-build-worker.js +380 -0
  279. package/server-managed/bundle-build.ts +326 -0
  280. package/server-managed/bundle-cache.ts +261 -0
  281. package/server-managed/bundle-catalog.ts +29 -0
  282. package/server-managed/bundle-commits.ts +133 -0
  283. package/server-managed/bundle-dependency-reviews.ts +91 -0
  284. package/server-managed/bundle-store.ts +24 -0
  285. package/server-managed/bundle-summary-cache.ts +139 -0
  286. package/server-managed/bundle-validation.ts +33 -0
  287. package/server-managed/bundle.ts +151 -0
  288. package/server-managed/cache-storage.ts +20 -0
  289. package/server-managed/cli.js +21 -0
  290. package/server-managed/combined.ts +43 -0
  291. package/server-managed/comments.ts +138 -0
  292. package/server-managed/commit-coauthors.ts +105 -0
  293. package/server-managed/commit-lockfiles.ts +78 -0
  294. package/server-managed/comparison.ts +51 -0
  295. package/server-managed/config.ts +163 -0
  296. package/server-managed/content-access.ts +15 -0
  297. package/server-managed/crypto.ts +25 -0
  298. package/server-managed/db-methods.ts +1914 -0
  299. package/server-managed/db-neon.ts +398 -0
  300. package/server-managed/db-schema.ts +263 -0
  301. package/server-managed/db-table-names.ts +22 -0
  302. package/server-managed/db.ts +149 -0
  303. package/server-managed/dependabot-access.ts +61 -0
  304. package/server-managed/dependabot-alerts.ts +180 -0
  305. package/server-managed/dependency-review-comments.ts +143 -0
  306. package/server-managed/dependency-reviews.ts +369 -0
  307. package/server-managed/github-accounts.ts +59 -0
  308. package/server-managed/github-actions.ts +71 -0
  309. package/server-managed/github-app.ts +347 -0
  310. package/server-managed/github-errors.ts +92 -0
  311. package/server-managed/github-graphql.ts +42 -0
  312. package/server-managed/github-issue-links.ts +264 -0
  313. package/server-managed/github-issue-oauth.ts +30 -0
  314. package/server-managed/github-issues.ts +157 -0
  315. package/server-managed/github-link-oauth.ts +56 -0
  316. package/server-managed/github-links.ts +204 -0
  317. package/server-managed/github-metadata.ts +213 -0
  318. package/server-managed/github-oauth.ts +264 -0
  319. package/server-managed/github-pulls.ts +257 -0
  320. package/server-managed/github-requests.ts +181 -0
  321. package/server-managed/github-users.ts +30 -0
  322. package/server-managed/github-values.ts +26 -0
  323. package/server-managed/history-windows.ts +172 -0
  324. package/server-managed/http-response.ts +76 -0
  325. package/server-managed/http.ts +6324 -0
  326. package/server-managed/import-triage.ts +51 -0
  327. package/server-managed/index.ts +204 -0
  328. package/server-managed/kept-briefly.ts +37 -0
  329. package/server-managed/kept.ts +28 -0
  330. package/server-managed/link-reports.ts +149 -0
  331. package/server-managed/listed-activity.ts +39 -0
  332. package/server-managed/locked-packages.ts +234 -0
  333. package/server-managed/lockfile-scope.ts +58 -0
  334. package/server-managed/lru.ts +30 -0
  335. package/server-managed/managed-issues.ts +92 -0
  336. package/server-managed/management-catalog.ts +45 -0
  337. package/server-managed/management.ts +116 -0
  338. package/server-managed/npm-delta-worker.js +142 -0
  339. package/server-managed/npm-delta.ts +277 -0
  340. package/server-managed/npm-insights.ts +455 -0
  341. package/server-managed/npm-kept.ts +265 -0
  342. package/server-managed/npm-loads.ts +259 -0
  343. package/server-managed/npm-manifest.ts +117 -0
  344. package/server-managed/npm-packages.ts +469 -0
  345. package/server-managed/npm-patch-paths.ts +86 -0
  346. package/server-managed/npm-patch.ts +455 -0
  347. package/server-managed/npm-provenance.ts +127 -0
  348. package/server-managed/npm-risk.ts +287 -0
  349. package/server-managed/object-storage-disk.ts +147 -0
  350. package/server-managed/object-storage-vercel.ts +71 -0
  351. package/server-managed/object-storage.ts +82 -0
  352. package/server-managed/package-entry-points.ts +127 -0
  353. package/server-managed/pretty-copies.ts +22 -0
  354. package/server-managed/pretty-format.d.ts +3 -0
  355. package/server-managed/pretty-format.js +13 -0
  356. package/server-managed/pretty-print.ts +442 -0
  357. package/server-managed/public-workspace.ts +243 -0
  358. package/server-managed/pull-comment-reviews.ts +161 -0
  359. package/server-managed/pull-dependencies.ts +370 -0
  360. package/server-managed/pull-dependency-reviews.ts +407 -0
  361. package/server-managed/pull-reviews.ts +202 -0
  362. package/server-managed/queue.ts +54 -0
  363. package/server-managed/release-commits.ts +85 -0
  364. package/server-managed/rename-diff-worker.js +30 -0
  365. package/server-managed/rename-diff.ts +237 -0
  366. package/server-managed/repo-path.ts +21 -0
  367. package/server-managed/report-migration.ts +32 -0
  368. package/server-managed/report-opening.ts +77 -0
  369. package/server-managed/report-query.ts +10 -0
  370. package/server-managed/report-response.ts +16 -0
  371. package/server-managed/report-sources.ts +185 -0
  372. package/server-managed/report-store.ts +77 -0
  373. package/server-managed/repository-actions.ts +220 -0
  374. package/server-managed/repository-agents.ts +422 -0
  375. package/server-managed/repository-aliases.ts +119 -0
  376. package/server-managed/repository-browser.ts +361 -0
  377. package/server-managed/repository-changes.ts +280 -0
  378. package/server-managed/repository-code.ts +222 -0
  379. package/server-managed/repository-dependency-reviews.ts +182 -0
  380. package/server-managed/repository-discovery.ts +83 -0
  381. package/server-managed/repository-history.ts +428 -0
  382. package/server-managed/repository-issues.ts +293 -0
  383. package/server-managed/repository-policy.ts +27 -0
  384. package/server-managed/repository-pulls.ts +207 -0
  385. package/server-managed/repository-pulse.ts +477 -0
  386. package/server-managed/repository-risk-assess.ts +108 -0
  387. package/server-managed/repository-risk-audit.ts +78 -0
  388. package/server-managed/repository-risk-caches.ts +37 -0
  389. package/server-managed/repository-risk-read.ts +260 -0
  390. package/server-managed/repository-risk-stasis.ts +61 -0
  391. package/server-managed/repository-risk-turn.ts +97 -0
  392. package/server-managed/repository-risk.ts +516 -0
  393. package/server-managed/repository-squashes.ts +160 -0
  394. package/server-managed/repository-stamp.ts +41 -0
  395. package/server-managed/request-timing.ts +63 -0
  396. package/server-managed/reviewed-dependencies.ts +170 -0
  397. package/server-managed/revisions.ts +35 -0
  398. package/server-managed/scan-downloads.ts +121 -0
  399. package/server-managed/session.ts +132 -0
  400. package/server-managed/slugs.ts +38 -0
  401. package/server-managed/solidity-entry-points.ts +71 -0
  402. package/server-managed/sql-postgres.ts +34 -0
  403. package/server-managed/sql.ts +107 -0
  404. package/server-managed/stasis-config.ts +147 -0
  405. package/server-managed/stasis-dependencies.ts +221 -0
  406. package/server-managed/static.ts +28 -0
  407. package/server-managed/storage-command.ts +16 -0
  408. package/server-managed/storage-db.ts +183 -0
  409. package/server-managed/storage-encryption.ts +288 -0
  410. package/server-managed/storage-maintenance.ts +259 -0
  411. package/server-managed/storage-payload.ts +121 -0
  412. package/server-managed/storage-stores.ts +91 -0
  413. package/server-managed/storage.ts +82 -0
  414. package/server-managed/team-app-summaries.ts +56 -0
  415. package/server-managed/team-app.ts +156 -0
  416. package/server-managed/team-catalog.ts +7 -0
  417. package/server-managed/team-feed.ts +180 -0
  418. package/server-managed/team-npm-scopes.ts +103 -0
  419. package/server-managed/team-reports.ts +368 -0
  420. package/server-managed/triage-response.ts +16 -0
  421. package/server-managed/type-only-proof.js +161 -0
  422. package/server-managed/type-only-worker.js +31 -0
  423. package/server-managed/type-only.ts +135 -0
  424. package/server-managed/uploads.ts +106 -0
  425. package/server-managed/upstream-cache.ts +256 -0
  426. package/server-managed/view-as.ts +58 -0
  427. package/server-managed/worker-turns.ts +76 -0
  428. package/server-managed/workspace-shares.ts +170 -0
  429. package/server.ts +70 -0
  430. package/strip-types-loader.js +13 -10
  431. package/server/index.ts +0 -480
  432. package/server/lifecycle.ts +0 -208
  433. /package/{LICENSE → LICENSE-MIT} +0 -0
  434. /package/{server → server-e2e}/auth.ts +0 -0
  435. /package/{server → server-e2e}/config.example.json +0 -0
  436. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  437. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  438. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  439. /package/{server → server-e2e}/peer.ts +0 -0
  440. /package/{server → server-e2e}/sse-session.ts +0 -0
  441. /package/{server → server-e2e}/util.ts +0 -0
  442. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,181 @@
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'; `lineOf` each of their lines' line in its file, and
94
+ // `lines` the file's count, for diffRows to show where the types stand. Null
95
+ // where that would hide no change or leave none to show.
96
+ export function typeFolds(before, after, { runs, otherRuns }) {
97
+ const side = (text, ranges) => {
98
+ const lineOf = [], lines = textLines(text)
99
+ for (const [from, to] of ranges) for (let i = from; i < Math.min(to, lines.length); i++) lineOf.push(i)
100
+ const run = lineOf.map(i => lines[i]), shown = new Set(lineOf)
101
+ // A last line with no newline after it stays so where it is shown.
102
+ const open = text !== '' && !text.endsWith('\n') && lineOf.at(-1) === lines.length - 1
103
+ return { text: run.length === 0 ? '' : `${run.join('\n')}${open ? '' : '\n'}`, lineOf, lines: lines.length, run: run.join('\n'),
104
+ types: lines.filter((_, i) => !shown.has(i)).join('\n') }
105
+ }
106
+ const a = side(before, runs), b = side(after, otherRuns)
107
+ if (a.types === b.types || a.run === b.run) return null
108
+ return { before: a.text, after: b.text, lineOf: { a: a.lineOf, b: b.lineOf }, lines: { a: a.lines, b: b.lines } }
109
+ }
110
+
111
+ // The lines `blocks` add and remove, but for those that are one of `marks`, counted apart (`renamed`, `marked`).
112
+ export function markedCounts(blocks, marks) {
113
+ const told = new Set((marks ?? []).map(({ a0, a1, b0, b1 }) => `${a0},${a1},${b0},${b1}`))
114
+ const marked = new Set()
115
+ let additions = 0, deletions = 0, renamed = 0
116
+ blocks.forEach(({ a0, a1, b0, b1 }, i) => {
117
+ if (told.has(`${a0},${a1},${b0},${b1}`) && a1 - a0 === b1 - b0) {
118
+ marked.add(i)
119
+ renamed += b1 - b0
120
+ } else {
121
+ additions += b1 - b0
122
+ deletions += a1 - a0
123
+ }
124
+ })
125
+ return { additions, deletions, renamed, marked }
126
+ }
127
+
128
+ const MARK = /[\p{L}\p{N}_$]+|\S/gu
129
+
130
+ // How much two texts' diff changes, `{ marks, lines }`: its lines removed and added, and its words and other
131
+ // characters but blanks (MARK) a block removes or adds and doesn't put back elsewhere in it, as a printer's
132
+ // semicolon changes a mark and no line. Whitespace hidden as the view hides it (mixed blanks shown).
133
+ export function diffSize(before, after, ignoreWhitespace = false) {
134
+ const a = textLines(before), b = textLines(after)
135
+ let blocks = changeBlocks(before, after, ignoreWhitespace), lines = 0, marks = 0
136
+ if (ignoreWhitespace && hidesMixedWhitespace(before, after, blocks)) blocks = changeBlocks(before, after)
137
+ for (const { a0, a1, b0, b1 } of blocks) {
138
+ const counts = new Map()
139
+ for (let i = a0; i < a1; i++) for (const [mark] of a[i].matchAll(MARK)) counts.set(mark, (counts.get(mark) ?? 0) + 1)
140
+ for (let j = b0; j < b1; j++) for (const [mark] of b[j].matchAll(MARK)) counts.set(mark, (counts.get(mark) ?? 0) - 1)
141
+ for (const count of counts.values()) marks += Math.abs(count)
142
+ lines += a1 - a0 + b1 - b0
143
+ }
144
+ return { marks, lines }
145
+ }
146
+
147
+ // Past these a diff is computed only when asked, as one of lines that share nothing takes seconds.
148
+ const LARGE_LINES = 100_000
149
+ const LARGE_CHARS = 16 * 1024 * 1024
150
+ const lineEnds = text => {
151
+ let count = 0
152
+ for (let at = text.indexOf('\n'); at !== -1; at = text.indexOf('\n', at + 1)) count++
153
+ return count
154
+ }
155
+ export const isLargeDiff = (before, after) => before.length + after.length > LARGE_CHARS || lineEnds(before) + lineEnds(after) > LARGE_LINES
156
+
157
+ // Whether `blocks` take `before`'s lines to `after`'s: each in order and apart
158
+ // from the last, within both texts, and every line between them alike on both
159
+ // sides (alike but for how much whitespace they have where `ignoreWhitespace`,
160
+ // as diff -b has them, or for their indentation where it is `leading`), the
161
+ // last line in a block where a newline was added or
162
+ // dropped after it, so that a diff drawn from them hides no change. A check on
163
+ // what changeBlocks found, or on one found apart from the texts drawn.
164
+ export function blocksHold(before, after, blocks, ignoreWhitespace = false) {
165
+ if (!Array.isArray(blocks)) return false
166
+ const a = textLines(before), b = textLines(after)
167
+ const read = ignoreWhitespace === 'leading' ? unindentLine : ignoreWhitespace ? spacing : null
168
+ const alike = read ? (x, y) => read(x) === read(y) : (x, y) => x === y
169
+ let i = 0, j = 0
170
+ for (const block of [...blocks, { a0: a.length, a1: a.length, b0: b.length, b1: b.length, last: true }]) {
171
+ const { a0, a1, b0, b1 } = block ?? {}
172
+ if (![a0, a1, b0, b1].every(Number.isInteger) || a0 < i || b0 < j || a1 < a0 || b1 < b0 || a1 > a.length || b1 > b.length) return false
173
+ // A block changes a line, and as many lines are alike before it on each side.
174
+ if ((!block.last && a1 === a0 && b1 === b0) || a0 - i !== b0 - j) return false
175
+ if (block.last && a0 > i && !ignoreWhitespace && endsLine(before) !== endsLine(after)) return false
176
+ for (; i < a0; i++, j++) if (!alike(a[i], b[j])) return false
177
+ i = a1
178
+ j = b1
179
+ }
180
+ return true
181
+ }
@@ -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
+ }
@@ -0,0 +1,43 @@
1
+ // Managed comments are independent records, shared by reports containing the
2
+ // same finding. Imported and legacy comments may lack attribution or dates.
3
+ export interface ManagedComment {
4
+ id: string
5
+ findingId: string
6
+ body: string
7
+ authorId: string | null
8
+ authorLogin: string | null
9
+ // The name its author chose to show (managed_user.name), as it is now: null
10
+ // for one with none, one no longer a user, and to a public link's readers.
11
+ authorName: string | null
12
+ createdAt: number | null
13
+ updatedAt: number | null
14
+ version: number
15
+ }
16
+
17
+ export const MAX_COMMENT_TEXT = 10_000
18
+
19
+ // Who a comment shows as by: its author's name, else their login; null for
20
+ // one with neither, as an imported or legacy one is.
21
+ export function commentAuthorName(comment: { authorName?: string | null; authorLogin?: string | null }): string | null {
22
+ return comment.authorName?.trim() || comment.authorLogin || null
23
+ }
24
+
25
+ // Callers also enforce write access to the report containing the finding.
26
+ // Admins can remove comments with no linked user, but cannot claim authorship.
27
+ export function canDeleteComment(comment: Pick<ManagedComment, 'authorId'>, actor: { id: string; role: string } | null | undefined): boolean {
28
+ return actor != null && (comment.authorId === actor.id || (comment.authorId == null && actor.role === 'admin'))
29
+ }
30
+
31
+ export function compareManagedComments(a: ManagedComment, b: ManagedComment): number {
32
+ if (a.createdAt == null && b.createdAt != null) return -1
33
+ if (a.createdAt != null && b.createdAt == null) return 1
34
+ const byDate = (a.createdAt ?? 0) - (b.createdAt ?? 0)
35
+ if (byDate !== 0) return byDate
36
+ if (a.id === b.id) return 0
37
+ return a.id < b.id ? -1 : 1
38
+ }
39
+
40
+ export function parseCommentBody(value: unknown): string | null {
41
+ if (typeof value !== 'string' || value.length > MAX_COMMENT_TEXT) return null
42
+ return value.trim() || null
43
+ }
@@ -0,0 +1,25 @@
1
+ // A team's Dependencies: its sub-tabs, `/team/<slug>/dependencies[/<tab>]`, and a pull request's
2
+ // versions reviewed together, `/team/<slug>/dependencies/review/<repo id>/<number>` (`pullReview`).
3
+ export const DEPENDENCY_TABS = new Set(['pulls', 'versions', 'branch', 'reviews'])
4
+ const isPullReview = pull => [pull?.repoId, pull?.number].every(id => Number.isSafeInteger(id) && id > 0)
5
+
6
+ export function dependencyFields(route) {
7
+ if (route.view !== 'workspace-dependencies') return {}
8
+ if (isPullReview(route.pullReview)) return { pullReview: { repoId: route.pullReview.repoId, number: route.pullReview.number } }
9
+ return route.dependencyTab == null ? {} : { dependencyTab: route.dependencyTab }
10
+ }
11
+
12
+ export function dependenciesPath(slug, route) {
13
+ const { dependencyTab: tab = 'pulls', pullReview } = dependencyFields(route)
14
+ if (!DEPENDENCY_TABS.has(tab)) return null
15
+ if (pullReview) return `/team/${slug}/dependencies/review/${pullReview.repoId}/${pullReview.number}`
16
+ return `/team/${slug}/dependencies${tab === 'pulls' ? '' : `/${tab}`}`
17
+ }
18
+
19
+ // Undefined where `path` is none of these.
20
+ export function parseDependenciesRoute(path) {
21
+ const match = /^\/team\/([A-Za-z0-9_-]+)\/dependencies\/(?:([a-z]+)|review\/([1-9]\d{0,14})\/([1-9]\d{0,14}))$/u.exec(path)
22
+ if (!match) return undefined
23
+ if (match[3]) return { view: 'workspace-dependencies', teamSlug: match[1], pullReview: { repoId: Number(match[3]), number: Number(match[4]) } }
24
+ return DEPENDENCY_TABS.has(match[2]) ? { view: 'workspace-dependencies', teamSlug: match[1], dependencyTab: match[2] } : null
25
+ }
@@ -0,0 +1,28 @@
1
+ // A package installed from a directory: Stasis records one an ecosystem's
2
+ // `:directory` (`npm:directory`, a `file:` dependency pnpm and yarn copy into
3
+ // node_modules), naming the directory it was copied from (`directory`). It is
4
+ // the repository's own code, wherever that directory is, in the repository
5
+ // or outside it, not any registry's package of its name: never reviewed as a
6
+ // dependency, here or by the host's reviewed dependencies, nor audited. No
7
+ // archive was installed, so its record carries no integrity.
8
+ interface Recorded { ecosystem?: unknown; integrity?: unknown; directory?: unknown; name?: unknown; version?: unknown }
9
+
10
+ export const isDirectoryEcosystem = (ecosystem: unknown): ecosystem is string => typeof ecosystem === 'string' && ecosystem.endsWith(':directory')
11
+
12
+ // Whether `info`, recorded as installed from a directory, isn't as Stasis
13
+ // records one: with an integrity, or naming no directory.
14
+ export const malformedDirectoryPackage = (info: Recorded) => isDirectoryEcosystem(info.ecosystem)
15
+ && (info.integrity !== undefined || typeof info.directory !== 'string' || info.directory === '')
16
+
17
+ export const MALFORMED_DIRECTORY_PACKAGE = 'Recorded as installed from a directory, but with an integrity or naming no directory.'
18
+
19
+ // Whether `info` is a package installed from a directory, the repository's
20
+ // own code; one recorded so that is malformed throws.
21
+ export function isDirectoryPackage(info: Recorded | null | undefined): boolean {
22
+ if (!info || !isDirectoryEcosystem(info.ecosystem)) return false
23
+ if (malformedDirectoryPackage(info)) {
24
+ throw Object.assign(new Error(`${String(info.name ?? 'A package')}@${String(info.version ?? '?')} (${info.ecosystem}): ${MALFORMED_DIRECTORY_PACKAGE}`),
25
+ { code: 'directory-package-malformed' })
26
+ }
27
+ return true
28
+ }
@@ -0,0 +1,5 @@
1
+ export const FINDING_DETAIL_FIELDS: readonly string[]
2
+ export function liteReportData(data: unknown, options?: { fold?: boolean; shown?: ReadonlySet<string> | null }): unknown
3
+ export function liteWorkspace<T extends { filename: string; data: unknown }>(reports: readonly T[], links: readonly (readonly string[])[], view?: import('./team-app.js').ManagedTeamView): {
4
+ reports: T[]; folded: false | 'rows' | 'app'; lens: { drop: boolean; detail: boolean; upstream: boolean } | null
5
+ }