@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.61

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 (409) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +17 -0
  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 +3 -0
  13. package/common/bundle-compare-diff.js +376 -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-metadata.d.ts +15 -0
  20. package/common/bundle-metadata.js +226 -0
  21. package/common/bundle-pkg-of.d.ts +1 -0
  22. package/common/bundle-pkg-of.js +90 -0
  23. package/common/bundle-reasons.d.ts +2 -0
  24. package/common/bundle-reasons.js +21 -0
  25. package/common/bundle-source-links.d.ts +6 -0
  26. package/common/bundle-source-links.js +216 -0
  27. package/common/bundle-sourcemap.d.ts +10 -0
  28. package/common/bundle-sourcemap.js +100 -0
  29. package/common/bundle-sources.d.ts +7 -0
  30. package/common/bundle-sources.js +333 -0
  31. package/common/bundle-stats.js +41 -0
  32. package/common/bundle-tabs.js +1 -0
  33. package/common/code-language.js +65 -0
  34. package/common/default-scan-models.ts +36 -0
  35. package/common/dependency-reviews.d.ts +18 -0
  36. package/common/dependency-reviews.js +64 -0
  37. package/common/finding-duplicates.js +58 -0
  38. package/common/finding-filters.js +274 -0
  39. package/common/finding-id.js +47 -0
  40. package/common/finding-repo.d.ts +5 -0
  41. package/common/finding-repo.js +67 -0
  42. package/common/github-issue-labels.d.ts +1 -0
  43. package/common/github-issue-labels.js +11 -0
  44. package/common/github-pr.ts +56 -0
  45. package/common/gzip.js +59 -0
  46. package/common/line-diff.d.ts +8 -0
  47. package/common/line-diff.js +57 -0
  48. package/common/linked-workspace-groups.js +63 -0
  49. package/common/managed/agent-tasks.ts +292 -0
  50. package/common/managed/comments.ts +43 -0
  51. package/common/managed/finding-detail.d.ts +5 -0
  52. package/common/managed/finding-detail.js +75 -0
  53. package/common/managed/finding-values.d.ts +2 -0
  54. package/common/managed/finding-values.js +44 -0
  55. package/common/managed/github-agents.ts +114 -0
  56. package/common/managed/github-logins.ts +49 -0
  57. package/common/managed/lite-name.d.ts +2 -0
  58. package/common/managed/lite-name.js +20 -0
  59. package/common/managed/npm-packages.d.ts +7 -0
  60. package/common/managed/npm-packages.js +51 -0
  61. package/common/managed/permissions.ts +31 -0
  62. package/common/managed/report-content.ts +72 -0
  63. package/common/managed/report-filter.ts +120 -0
  64. package/common/managed/repository-alias.ts +65 -0
  65. package/common/managed/roles.ts +35 -0
  66. package/common/managed/routes.d.ts +2 -0
  67. package/common/managed/routes.js +363 -0
  68. package/common/managed/scan-models.ts +6 -0
  69. package/common/managed/team-app.d.ts +15 -0
  70. package/common/managed/team-app.js +100 -0
  71. package/common/managed/team-filters.js +26 -0
  72. package/common/managed/triage.ts +83 -0
  73. package/common/managed/upload-seal.ts +126 -0
  74. package/common/pretty-print.d.ts +5 -0
  75. package/common/pretty-print.js +24 -0
  76. package/common/repo-commit.d.ts +4 -0
  77. package/common/repo-commit.js +30 -0
  78. package/common/revalidation-conflicts.js +48 -0
  79. package/common/revalidation-input-groups.js +56 -0
  80. package/common/save-error-reason.ts +20 -7
  81. package/common/scan-server.ts +13 -0
  82. package/common/security-links.d.ts +5 -0
  83. package/common/security-links.js +33 -0
  84. package/common/server-info.ts +46 -0
  85. package/common/utf8.d.ts +3 -0
  86. package/common/utf8.js +45 -0
  87. package/common/workspace-app.js +71 -0
  88. package/common/workspace-groups.js +176 -0
  89. package/out/activity.js +4 -0
  90. package/out/brotli-fallback.js +3 -3
  91. package/out/chunk-2XUEZHIP.js +28 -0
  92. package/out/chunk-4EMM6UCD.js +1 -0
  93. package/out/chunk-4ISO5F7Y.js +7 -0
  94. package/out/chunk-4XIH7YTX.js +1 -0
  95. package/out/chunk-6CCSTJWB.js +1 -0
  96. package/out/chunk-74AEKRES.js +10 -0
  97. package/out/chunk-7BKKYVWR.js +7 -0
  98. package/out/chunk-7C7DWL7I.js +1 -0
  99. package/out/chunk-B3FNMHOE.js +1 -0
  100. package/out/chunk-BNH52UHC.js +2 -0
  101. package/out/chunk-BRO77PQY.js +42 -0
  102. package/out/chunk-C4Z6ZBXV.js +10 -0
  103. package/out/chunk-DEVAORP2.js +1 -0
  104. package/out/chunk-E3LFSUDJ.js +9 -0
  105. package/out/chunk-G3LY2FV4.js +1 -0
  106. package/out/chunk-GO7FT4OD.js +1 -0
  107. package/out/chunk-GRGIZOTP.js +4 -0
  108. package/out/chunk-HAZKDK4M.js +4 -0
  109. package/out/chunk-HOB3YPS5.js +1 -0
  110. package/out/chunk-IYPY47MC.js +1 -0
  111. package/out/chunk-IZ6MYRYB.js +3 -0
  112. package/out/chunk-J2FWBXFV.js +1 -0
  113. package/out/chunk-JCIIBLKR.js +1 -0
  114. package/out/chunk-JFL7WLRV.js +1 -0
  115. package/out/chunk-JJK5OZG2.js +15 -0
  116. package/out/chunk-JMG5DXII.js +2 -0
  117. package/out/chunk-JOXLZXMI.js +1 -0
  118. package/out/chunk-M37X4LCF.js +14 -0
  119. package/out/chunk-M3Y6SLC4.js +1 -0
  120. package/out/chunk-NRPC74AM.js +1 -0
  121. package/out/chunk-NXATZJQ2.js +1 -0
  122. package/out/chunk-OFZYEWBH.js +244 -0
  123. package/out/chunk-OIERSXON.js +1 -0
  124. package/out/chunk-OOJM4CTU.js +1 -0
  125. package/out/chunk-PAD2JHZT.js +1 -0
  126. package/out/chunk-PNHBZGDD.js +1 -0
  127. package/out/chunk-PTFQKLKO.js +1 -0
  128. package/out/chunk-PWFUOLZK.js +17 -0
  129. package/out/chunk-PXK7EU4V.js +1 -0
  130. package/out/chunk-QCOGVL37.js +52 -0
  131. package/out/chunk-QMVOEBWC.js +13 -0
  132. package/out/chunk-QRKFPLA4.js +80 -0
  133. package/out/chunk-R3NZFXVR.js +1 -0
  134. package/out/chunk-R5O6FAW4.js +2 -0
  135. package/out/chunk-RRBIJL2B.js +1 -0
  136. package/out/chunk-SYXT3SFP.js +2 -0
  137. package/out/chunk-TOXMUOIW.js +5 -0
  138. package/out/chunk-TUII34K2.js +1 -0
  139. package/out/chunk-UCP3JRE2.js +1 -0
  140. package/out/chunk-VFWMQ3LG.js +2 -0
  141. package/out/chunk-VRX2APNA.js +9 -0
  142. package/out/chunk-W3QFV4SP.js +3 -0
  143. package/out/chunk-W6VOKW2N.js +12 -0
  144. package/out/chunk-WCPJDAYA.js +10 -0
  145. package/out/chunk-WMFDQS2L.js +11 -0
  146. package/out/chunk-WREU7JAG.js +1 -0
  147. package/out/chunk-Y5ZHFNBD.js +2 -0
  148. package/out/chunk-YF4M5OCI.js +1 -0
  149. package/out/chunk-Z667U2UJ.js +1 -0
  150. package/out/chunk-ZQHLECTI.js +1 -0
  151. package/out/chunk-ZQNEWVGG.js +1 -0
  152. package/out/client-managed-import.js +4 -0
  153. package/out/client-managed.js +34 -0
  154. package/out/client-sync.js +11 -17
  155. package/out/compare.js +40 -0
  156. package/out/dialogs.js +40 -0
  157. package/out/github-issue-authorized.html +3 -0
  158. package/out/github-issue-authorized.js +1 -0
  159. package/out/graph.js +19 -4
  160. package/out/index.html +106 -8
  161. package/out/prism.js +14 -10
  162. package/out/scan.js +2 -0
  163. package/out/stasis.svg +20 -0
  164. package/out/terminal.js +366 -39
  165. package/out/view.css +1 -1
  166. package/out/view.js +19 -144
  167. package/package.json +383 -63
  168. package/risk/actions/findings.js +161 -0
  169. package/risk/actions/resolve.js +250 -0
  170. package/risk/actions/scripts/commands.js +182 -0
  171. package/risk/actions/scripts/grade.js +113 -0
  172. package/risk/actions/scripts/packages.js +123 -0
  173. package/risk/actions/scripts/shell.js +169 -0
  174. package/risk/actions/uses.js +76 -0
  175. package/risk/actions/workflow.js +110 -0
  176. package/risk/files/characters.js +196 -0
  177. package/risk/files/hosts.js +205 -0
  178. package/risk/files/readability.js +177 -0
  179. package/risk/files/runs-code.js +615 -0
  180. package/risk/files/script.js +118 -0
  181. package/risk/files/stamps.js +47 -0
  182. package/risk/index.d.ts +272 -0
  183. package/risk/index.js +11 -0
  184. package/risk/npm/assess.js +285 -0
  185. package/risk/npm/combined.js +68 -0
  186. package/risk/npm/compare.js +257 -0
  187. package/risk/npm/dependencies.js +172 -0
  188. package/risk/npm/diff.js +79 -0
  189. package/risk/npm/downloads.js +84 -0
  190. package/risk/npm/files.js +445 -0
  191. package/risk/npm/held.js +63 -0
  192. package/risk/npm/install-scripts.js +34 -0
  193. package/risk/npm/malware.js +38 -0
  194. package/risk/npm/manifest.js +65 -0
  195. package/risk/npm/new-dependency.js +60 -0
  196. package/risk/npm/old-version.js +108 -0
  197. package/risk/npm/registry.js +390 -0
  198. package/risk/npm/release.js +85 -0
  199. package/risk/npm/score.js +59 -0
  200. package/risk/npm/specs.js +124 -0
  201. package/risk/npm/tarball.js +96 -0
  202. package/server-common/database-config.ts +16 -0
  203. package/server-common/initialize.ts +18 -0
  204. package/server-common/npm-advisories.ts +101 -0
  205. package/{server → server-common}/origin.ts +5 -5
  206. package/server-common/reap.ts +48 -0
  207. package/server-common/scan-config.ts +19 -0
  208. package/server-common/standalone.ts +29 -0
  209. package/server-common/storage-crypto.ts +182 -0
  210. package/server-common/storage-log.ts +38 -0
  211. package/server-common/vercel-blob.ts +103 -0
  212. package/server-e2e/app.ts +487 -0
  213. package/{server → server-e2e}/bus-receiver.ts +2 -1
  214. package/{server → server-e2e}/cli.js +9 -4
  215. package/{server → server-e2e}/config.ts +50 -42
  216. package/{server → server-e2e}/db-neon.ts +2 -2
  217. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  218. package/{server → server-e2e}/db-stmt.ts +2 -2
  219. package/{server → server-e2e}/db.ts +7 -7
  220. package/{server → server-e2e}/http.ts +44 -13
  221. package/{server → server-e2e}/hub.ts +40 -9
  222. package/server-e2e/index.ts +17 -0
  223. package/server-e2e/lifecycle.ts +95 -0
  224. package/{server → server-e2e}/neon-driver.ts +2 -2
  225. package/{server → server-e2e}/npm-proxy.ts +12 -145
  226. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  227. package/{server → server-e2e}/objstore/blob.ts +1 -1
  228. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  229. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  230. package/{server → server-e2e}/objstore/init.ts +19 -27
  231. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  232. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  233. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  234. package/{server → server-e2e}/objstore/rest.ts +3 -3
  235. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  236. package/{server → server-e2e}/objstore/store.ts +7 -7
  237. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  238. package/{server → server-e2e}/pubsub.ts +12 -9
  239. package/{server → server-e2e}/sign.ts +4 -4
  240. package/{server → server-e2e}/sse-server.ts +60 -33
  241. package/{server → server-e2e}/static.ts +31 -21
  242. package/{server → server-e2e}/sync-handlers.ts +64 -30
  243. package/{server → server-e2e}/ws-server.ts +20 -9
  244. package/server-managed/activity.ts +238 -0
  245. package/server-managed/agent-merges.ts +109 -0
  246. package/server-managed/app-agents.ts +23 -0
  247. package/server-managed/avatar-store.ts +13 -0
  248. package/server-managed/blob-store.ts +26 -0
  249. package/server-managed/brotli.ts +10 -0
  250. package/server-managed/bundle-advisories.ts +103 -0
  251. package/server-managed/bundle-advisory-inventory.ts +77 -0
  252. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  253. package/server-managed/bundle-build-diagnostics.js +23 -0
  254. package/server-managed/bundle-build-leases.ts +41 -0
  255. package/server-managed/bundle-build-worker.js +238 -0
  256. package/server-managed/bundle-build.ts +240 -0
  257. package/server-managed/bundle-cache.ts +199 -0
  258. package/server-managed/bundle-catalog.ts +29 -0
  259. package/server-managed/bundle-commits.ts +133 -0
  260. package/server-managed/bundle-dependency-reviews.ts +68 -0
  261. package/server-managed/bundle-store.ts +24 -0
  262. package/server-managed/bundle-summary-cache.ts +139 -0
  263. package/server-managed/bundle-validation.ts +33 -0
  264. package/server-managed/bundle.ts +119 -0
  265. package/server-managed/cache-storage.ts +20 -0
  266. package/server-managed/cli.js +21 -0
  267. package/server-managed/combined.ts +43 -0
  268. package/server-managed/comments.ts +138 -0
  269. package/server-managed/commit-coauthors.ts +105 -0
  270. package/server-managed/commit-lockfiles.ts +77 -0
  271. package/server-managed/comparison.ts +50 -0
  272. package/server-managed/config.ts +163 -0
  273. package/server-managed/content-access.ts +15 -0
  274. package/server-managed/crypto.ts +25 -0
  275. package/server-managed/db-methods.ts +1877 -0
  276. package/server-managed/db-neon.ts +388 -0
  277. package/server-managed/db-schema.ts +253 -0
  278. package/server-managed/db-table-names.ts +22 -0
  279. package/server-managed/db.ts +146 -0
  280. package/server-managed/dependabot-access.ts +61 -0
  281. package/server-managed/dependabot-alerts.ts +180 -0
  282. package/server-managed/dependency-review-comments.ts +92 -0
  283. package/server-managed/dependency-reviews.ts +363 -0
  284. package/server-managed/github-accounts.ts +59 -0
  285. package/server-managed/github-actions.ts +71 -0
  286. package/server-managed/github-app.ts +347 -0
  287. package/server-managed/github-errors.ts +70 -0
  288. package/server-managed/github-graphql.ts +42 -0
  289. package/server-managed/github-issue-links.ts +264 -0
  290. package/server-managed/github-issue-oauth.ts +30 -0
  291. package/server-managed/github-issues.ts +157 -0
  292. package/server-managed/github-link-oauth.ts +56 -0
  293. package/server-managed/github-links.ts +204 -0
  294. package/server-managed/github-metadata.ts +213 -0
  295. package/server-managed/github-oauth.ts +264 -0
  296. package/server-managed/github-pulls.ts +257 -0
  297. package/server-managed/github-requests.ts +179 -0
  298. package/server-managed/github-users.ts +30 -0
  299. package/server-managed/github-values.ts +26 -0
  300. package/server-managed/history-windows.ts +172 -0
  301. package/server-managed/http-response.ts +76 -0
  302. package/server-managed/http.ts +5796 -0
  303. package/server-managed/import-triage.ts +51 -0
  304. package/server-managed/index.ts +204 -0
  305. package/server-managed/kept-briefly.ts +37 -0
  306. package/server-managed/kept.ts +28 -0
  307. package/server-managed/link-reports.ts +149 -0
  308. package/server-managed/listed-activity.ts +39 -0
  309. package/server-managed/locked-packages.ts +152 -0
  310. package/server-managed/lockfile-scope.ts +49 -0
  311. package/server-managed/lru.ts +30 -0
  312. package/server-managed/managed-issues.ts +92 -0
  313. package/server-managed/management-catalog.ts +45 -0
  314. package/server-managed/management.ts +110 -0
  315. package/server-managed/npm-delta-worker.js +23 -0
  316. package/server-managed/npm-delta.ts +159 -0
  317. package/server-managed/npm-insights.ts +455 -0
  318. package/server-managed/npm-kept.ts +234 -0
  319. package/server-managed/npm-loads.ts +259 -0
  320. package/server-managed/npm-manifest.ts +117 -0
  321. package/server-managed/npm-packages.ts +462 -0
  322. package/server-managed/npm-patch.ts +317 -0
  323. package/server-managed/npm-provenance.ts +127 -0
  324. package/server-managed/npm-risk.ts +287 -0
  325. package/server-managed/object-storage-disk.ts +147 -0
  326. package/server-managed/object-storage-vercel.ts +71 -0
  327. package/server-managed/object-storage.ts +82 -0
  328. package/server-managed/package-entry-points.ts +79 -0
  329. package/server-managed/pretty-print.ts +425 -0
  330. package/server-managed/public-workspace.ts +242 -0
  331. package/server-managed/pull-comment-reviews.ts +161 -0
  332. package/server-managed/pull-dependencies.ts +340 -0
  333. package/server-managed/pull-dependency-reviews.ts +327 -0
  334. package/server-managed/pull-reviews.ts +202 -0
  335. package/server-managed/queue.ts +53 -0
  336. package/server-managed/release-commits.ts +85 -0
  337. package/server-managed/rename-diff-worker.js +26 -0
  338. package/server-managed/rename-diff.ts +236 -0
  339. package/server-managed/repo-path.ts +21 -0
  340. package/server-managed/report-migration.ts +32 -0
  341. package/server-managed/report-query.ts +10 -0
  342. package/server-managed/report-response.ts +16 -0
  343. package/server-managed/report-sources.ts +181 -0
  344. package/server-managed/report-store.ts +77 -0
  345. package/server-managed/repository-actions.ts +220 -0
  346. package/server-managed/repository-agents.ts +422 -0
  347. package/server-managed/repository-aliases.ts +85 -0
  348. package/server-managed/repository-browser.ts +303 -0
  349. package/server-managed/repository-changes.ts +280 -0
  350. package/server-managed/repository-code.ts +215 -0
  351. package/server-managed/repository-dependency-reviews.ts +159 -0
  352. package/server-managed/repository-discovery.ts +83 -0
  353. package/server-managed/repository-history.ts +428 -0
  354. package/server-managed/repository-issues.ts +224 -0
  355. package/server-managed/repository-policy.ts +27 -0
  356. package/server-managed/repository-pulls.ts +207 -0
  357. package/server-managed/repository-pulse.ts +477 -0
  358. package/server-managed/repository-risk-assess.ts +108 -0
  359. package/server-managed/repository-risk-audit.ts +78 -0
  360. package/server-managed/repository-risk-read.ts +170 -0
  361. package/server-managed/repository-risk.ts +483 -0
  362. package/server-managed/repository-squashes.ts +160 -0
  363. package/server-managed/repository-stamp.ts +41 -0
  364. package/server-managed/request-timing.ts +63 -0
  365. package/server-managed/reviewed-dependencies.ts +149 -0
  366. package/server-managed/revisions.ts +35 -0
  367. package/server-managed/scan-downloads.ts +87 -0
  368. package/server-managed/session.ts +132 -0
  369. package/server-managed/slugs.ts +38 -0
  370. package/server-managed/solidity-entry-points.ts +71 -0
  371. package/server-managed/sql-postgres.ts +34 -0
  372. package/server-managed/sql.ts +107 -0
  373. package/server-managed/stasis-config.ts +55 -0
  374. package/server-managed/static.ts +28 -0
  375. package/server-managed/storage-command.ts +16 -0
  376. package/server-managed/storage-db.ts +183 -0
  377. package/server-managed/storage-encryption.ts +288 -0
  378. package/server-managed/storage-maintenance.ts +259 -0
  379. package/server-managed/storage-payload.ts +121 -0
  380. package/server-managed/storage-stores.ts +91 -0
  381. package/server-managed/storage.ts +82 -0
  382. package/server-managed/team-app-summaries.ts +54 -0
  383. package/server-managed/team-app.ts +154 -0
  384. package/server-managed/team-catalog.ts +7 -0
  385. package/server-managed/team-feed.ts +180 -0
  386. package/server-managed/team-npm-scopes.ts +103 -0
  387. package/server-managed/team-reports.ts +351 -0
  388. package/server-managed/triage-response.ts +16 -0
  389. package/server-managed/type-only-proof.js +108 -0
  390. package/server-managed/type-only-worker.js +31 -0
  391. package/server-managed/type-only.ts +115 -0
  392. package/server-managed/uploads.ts +106 -0
  393. package/server-managed/upstream-cache.ts +250 -0
  394. package/server-managed/view-as.ts +58 -0
  395. package/server-managed/worker-turns.ts +76 -0
  396. package/server-managed/workspace-shares.ts +170 -0
  397. package/server.ts +70 -0
  398. package/server/index.ts +0 -480
  399. package/server/lifecycle.ts +0 -208
  400. /package/{LICENSE → LICENSE-MIT} +0 -0
  401. /package/{server → server-e2e}/auth.ts +0 -0
  402. /package/{server → server-e2e}/config.example.json +0 -0
  403. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  404. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  405. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  406. /package/{server → server-e2e}/peer.ts +0 -0
  407. /package/{server → server-e2e}/sse-session.ts +0 -0
  408. /package/{server → server-e2e}/util.ts +0 -0
  409. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,105 @@
1
+ // Who made a commit beside its author, as the Commits tab shows them
2
+ // (repository-history.ts): its co-authors, as its `Co-authored-by:` trailers
3
+ // name them, and the agents its message marks.
4
+ import { agentSignals, trailerBlock } from '../common/managed/agent-tasks.ts'
5
+ import { GITHUB_AGENTS, type GithubAgentId, emailAgent, githubAgent } from '../common/managed/github-agents.ts'
6
+ import { APP_AGENTS } from './app-agents.ts'
7
+ import { type NamedAccount, commitAccount } from './github-accounts.ts'
8
+ import { nameOf } from './github-values.ts'
9
+
10
+ export const MAX_COAUTHORS = 3
11
+ // The rules who a commit names beside its author is read by (coauthorFacts),
12
+ // and how they are kept: what was kept read by others (history pages,
13
+ // squashed pull requests) read again by these, once raised. The agents'
14
+ // accounts, addresses and names are none of them (coauthorsOf).
15
+ export const COAUTHORS_READ = 5
16
+
17
+ // One who made a commit beside its author: by name and account, as its
18
+ // author is, and the agent it is where known (common/managed/github-agents.ts),
19
+ // by its account, its commits' address or name, or the marks it leaves.
20
+ interface Coauthor { name: string | null; login: string | null; id: number | null; agent?: string }
21
+
22
+ // `Co-authored-by: <name> <address>` trailers, GitHub matching the key
23
+ // regardless of case; Cursor's agents' links, as their work carries them;
24
+ // the app agents known by the fingerprints they leave.
25
+ const COAUTHOR_TRAILER = /^co-authored-by:[ \t]*([^<\n]*?)[ \t]*<([^<>\s]+)>[ \t]*$/gimu
26
+ const CURSOR_AGENT = /https:\/\/cursor\.com\/(?:agents\?id=|background-agent\?bcId=)bc-/u
27
+ const FINGERPRINTED = APP_AGENTS.filter(agent => agent.fingerprint)
28
+
29
+ // One named as a commit's author or co-author: by name, the address its
30
+ // commit gives (where it is read), and account.
31
+ export type Maker = { name: unknown; email?: unknown; account: NamedAccount }
32
+
33
+ // Those a commit's message names in its `Co-authored-by:` trailers
34
+ // (agent-tasks.ts trailerBlock), each by name and address.
35
+ export const coauthorTrailers = (message: unknown) => typeof message === 'string'
36
+ ? [...trailerBlock(message.replaceAll('\r\n', '\n')).matchAll(COAUTHOR_TRAILER)].map(([, name, email]) => ({ name: name!, email: email! })) : []
37
+
38
+ // The agent one who made a commit is: by their account, else the address
39
+ // their commit names them by; else, GitHub naming no account for them, by
40
+ // their name.
41
+ const makerAgent = ({ name, email, account }: Maker): GithubAgentId | null => githubAgent(account.login, account.id) ?? emailAgent(email)
42
+ ?? (account.login ? null : githubAgent(null, null, typeof name === 'string' ? name : null))
43
+
44
+ // Who a commit names beside its author, as its history keeps them
45
+ // (repository-history.ts, `coauthorFacts`), its message never kept: its
46
+ // co-authors (`named`), those GitHub's GraphQL API lists past the author
47
+ // (`listed`, the addresses its `Co-authored-by:` trailers give, by the
48
+ // accounts GitHub knows them by), else its trailers (agent-tasks.ts
49
+ // trailerBlock), an account's no-reply address naming it, as many as
50
+ // MAX_NAMED, each by name, address and account; and the agents its message
51
+ // marks (`markedBy`), Claude's and Codex's as the Agents tab reads them
52
+ // (agent-tasks.ts agentSignals: their sessions' and tasks' links, Claude's
53
+ // co-author and "Generated with" lines), the app agents' by their
54
+ // fingerprints, Cursor's by its agents' links. Which of them are agents,
55
+ // and so the same as another, is told as they are answered (coauthorsOf), so
56
+ // that the agents' accounts, addresses and names change none kept.
57
+ export interface Named { name: string | null; email: string | null; login: string | null; id: number | null }
58
+ export const MAX_NAMED = 10
59
+ export function coauthorFacts(message: unknown, listed: Maker[] | null = null): { named: Named[]; markedBy: string[] } {
60
+ const text = typeof message === 'string' ? message.replaceAll('\r\n', '\n') : ''
61
+ const makers = listed ?? coauthorTrailers(text).map(({ name, email }) => ({ name, email, account: commitAccount({ email }) }))
62
+ const signals = agentSignals([text], FINGERPRINTED)
63
+ return {
64
+ named: makers.slice(0, MAX_NAMED).map(({ name, email, account }) => ({ name: nameOf(name), email: nameOf(email), login: account.login, id: account.id })),
65
+ markedBy: [...signals.claude || signals.sessions.length > 0 ? ['claude'] : [], ...signals.tasks.length > 0 || signals.codex ? ['codex'] : [],
66
+ ...CURSOR_AGENT.test(text) ? ['cursor'] : [], ...signals.agents],
67
+ }
68
+ }
69
+
70
+ // A commit as its history keeps it: its author by name, address and account,
71
+ // and who it names beside them (coauthorFacts), absent from pages kept before.
72
+ export interface CommitFacts { authorName: string | null; authorEmail?: string | null; authorLogin: string | null; authorId?: number | null; named?: Named[]
73
+ markedBy?: string[] }
74
+
75
+ // Who made a commit, past its author, as its history keeps them
76
+ // (`commit`, coauthorFacts): its co-authors, then the agents its message
77
+ // marks, each the agent it is where known, by the agents the app knows now,
78
+ // and once, the author none of them, as many as MAX_COAUTHORS: two are one by
79
+ // the first of their agent, account, address and name both name, two people
80
+ // of one name with accounts or addresses of their own two.
81
+ export function coauthorsOf({ authorName, authorEmail = null, authorLogin, authorId = null, named = [], markedBy = [] }: CommitFacts): Coauthor[] {
82
+ type Identity = { agent: string | null; login: string | null; email: string | null; name: string | null }
83
+ const identity = (agent: string | null, login: string | null, name: string | null, email: unknown = null): Identity => ({ agent, login: login?.toLowerCase() ?? null,
84
+ email: typeof email === 'string' && email.trim() ? email.trim().toLowerCase() : null, name: name?.toLowerCase() ?? null })
85
+ const same = (a: Identity, b: Identity) => a.agent && b.agent ? a.agent === b.agent : a.login && b.login ? a.login === b.login
86
+ : a.email && b.email ? a.email === b.email : a.name !== null && a.name === b.name
87
+ const author: Maker = { name: authorName, email: authorEmail, account: { login: authorLogin, id: authorId } }
88
+ const seen = [identity(makerAgent(author), authorLogin, nameOf(authorName), authorEmail)]
89
+ const coauthors: Coauthor[] = []
90
+ const add = (coauthor: Coauthor, email: unknown = null) => {
91
+ const who = identity(coauthor.agent ?? null, coauthor.login, coauthor.name, email)
92
+ if (seen.some(other => same(other, who)) || coauthors.length >= MAX_COAUTHORS || (!coauthor.login && !coauthor.name && !coauthor.agent)) return
93
+ seen.push(who)
94
+ coauthors.push(coauthor)
95
+ }
96
+ for (const { name, email, ...account } of named) {
97
+ const agent = makerAgent({ name, email, account })
98
+ // An agent known by its address where GitHub names someone else's
99
+ // account for it (Codex's), as itself, not that account.
100
+ const { login, id } = agent && account.login && githubAgent(account.login, account.id) !== agent ? { login: null, id: null } : account
101
+ add({ name, login, id, ...agent ? { agent } : {} }, email)
102
+ }
103
+ for (const agent of markedBy) if (Object.hasOwn(GITHUB_AGENTS, agent)) add({ name: GITHUB_AGENTS[agent as GithubAgentId].name, login: null, id: null, agent })
104
+ return coauthors
105
+ }
@@ -0,0 +1,77 @@
1
+ // The versions a repository's lockfiles of npm's ecosystem lock at a commit,
2
+ // as their review reads them (pull-dependency-reviews.ts): every lockfile
3
+ // there (findRepoLockfiles) a review holds to (`held`, lockfile-scope.ts),
4
+ // read as a pull request's are (pull-dependencies.ts readLockfile), but kept
5
+ // by its blob, in this instance and beyond it (`kept`), as many as
6
+ // MAX_LOCKFILES of those, each's versions (`lockfiles`), and those its reader
7
+ // refuses, of Bun's, or past MAX_LOCKFILES (`unread`), as many read at once
8
+ // as READ_AT_ONCE; and those of some of them (lockedIn), each version once by
9
+ // what its reviews are held to (lockedWith), dev only where it is wherever it
10
+ // is locked. GitHub having none of a lockfile it lists there fails the
11
+ // whole, as it would for any file.
12
+ import { createClient } from '@preventive/upstream/github.js'
13
+ import { GithubApiError, upstreamGithub } from './github-errors.ts'
14
+ import { USER_AGENT } from './github-requests.ts'
15
+ import { type LockedPackage, patchedIn } from './locked-packages.ts'
16
+ import { type Lru, lru } from './lru.ts'
17
+ import { eachOf } from './queue.ts'
18
+ import { type GithubAsked, type ListedLockfile, type LockfileStore, lockedWith, lockfileFormat, readLockfile } from './pull-dependencies.ts'
19
+
20
+ const MAX_LOCKFILES = 100
21
+ const READ_AT_ONCE = 4
22
+
23
+ export interface CommitLockfiles { lockfiles: { path: string; packages: LockedPackage[] }[]; unread: string[] }
24
+
25
+ // The lockfiles at commit `sha` its review reads, by their paths, each with
26
+ // its format (pull-dependencies.ts lockfileFormat) and its blob's id, kept by
27
+ // the commit, in this instance and beyond it (`kept`); `asked` told where
28
+ // GitHub was.
29
+ const listings: Lru<ListedLockfile[]> = lru(20_000, listed => listed.length + 1)
30
+ export async function lockfilesAt(fullName: string, token: string, sha: string, kept: LockfileStore | null, asked?: GithubAsked) {
31
+ const key = `${fullName}\0${sha}`
32
+ const known = listings.get(key)
33
+ if (known) return known
34
+ const stored = await kept?.listings.read(sha)
35
+ if (stored) { listings.set(key, stored); return stored }
36
+ if (asked) asked.github = true
37
+ const { lockfiles } = await upstreamGithub(() => createClient({ token, userAgent: USER_AGENT }).findRepoLockfiles({ repo: fullName, sha }))
38
+ const listed = lockfiles.flatMap(({ path, sha: blob }) => { const format = lockfileFormat(path); return format ? [{ path, format, sha: blob }] : [] })
39
+ listings.set(key, listed)
40
+ await kept?.listings.write(sha, listed)
41
+ return listed
42
+ }
43
+
44
+ export async function lockedAt(fullName: string, token: string, sha: string, kept: LockfileStore | null, held: (path: string) => boolean = () => true,
45
+ asked?: GithubAsked): Promise<CommitLockfiles> {
46
+ const listed = (await lockfilesAt(fullName, token, sha, kept, asked)).filter(({ path }) => held(path))
47
+ const unread = listed.slice(MAX_LOCKFILES).map(({ path }) => path)
48
+ const lockfiles: CommitLockfiles['lockfiles'] = []
49
+ const reading = listed.slice(0, MAX_LOCKFILES)
50
+ const reads = await eachOf(reading, READ_AT_ONCE, lockfile => readLockfile(fullName, token, sha, lockfile, kept, asked))
51
+ for (const [at, lockfile] of reading.entries()) {
52
+ const read = reads[at]!
53
+ if ('error' in read && read.error === 'github-not-found') throw new GithubApiError(404, 'github-not-found')
54
+ if ('error' in read) unread.push(lockfile.path)
55
+ else lockfiles.push({ path: lockfile.path, packages: read.packages })
56
+ }
57
+ return { lockfiles, unread: unread.toSorted() }
58
+ }
59
+
60
+ // The versions those of `read`'s lockfiles `held` holds to lock, each once,
61
+ // each patch's file from the repository's root (patchedIn), the first of
62
+ // them that names one there, and their paths.
63
+ export function lockedIn(read: CommitLockfiles, held: (path: string) => boolean = () => true) {
64
+ const packages = new Map<string, LockedPackage>()
65
+ const paths: string[] = []
66
+ for (const lockfile of read.lockfiles.filter(({ path }) => held(path))) {
67
+ paths.push(lockfile.path)
68
+ for (const pkg of lockfile.packages) {
69
+ const found = patchedIn(lockfile.path, { ...pkg })
70
+ const kept = packages.get(lockedWith(pkg))
71
+ if (!kept) { packages.set(lockedWith(pkg), found); continue }
72
+ if (kept.dev && !pkg.dev) delete kept.dev
73
+ if (kept.patchPath === undefined && found.patchPath !== undefined) kept.patchPath = found.patchPath
74
+ }
75
+ }
76
+ return { packages: [...packages.values()], paths }
77
+ }
@@ -0,0 +1,50 @@
1
+ // Compare's comparison of two managed bundles or two versions of an npm
2
+ // package, the one shown as a patch changes it where Review asks
3
+ // (GET /api/bundles/:id/comparison?other=, GET /api/npm/comparison):
4
+ // their files paired, at one path or renamed, with the sizes, resolutions,
5
+ // dependency versions and line counts its Overview and Code read beside them,
6
+ // as common/bundle-comparison.js prepareComparison works them out. The viewer
7
+ // of a managed bundle or a package has every comparison worked out here and
8
+ // loads none of the pairing itself. Answered as Brotli-encoded JSON, its
9
+ // `files.basePaths` (a Map) as `[path, as laid out]` pairs where the two
10
+ // sides' roots differ and none else, as the viewer reads none then. Access is
11
+ // the caller's to check.
12
+ import { Buffer } from 'node:buffer'
13
+ import { prepareComparison } from '../common/bundle-comparison.js'
14
+ import type { BundleDetails } from '../common/bundle-metadata.js'
15
+ import type { OpenedBlob } from './blob-store.ts'
16
+ import { encodeBrotli } from './brotli.ts'
17
+ import { type NpmPackageFile, type NpmVersionDocument, npmFileRows } from './npm-packages.ts'
18
+ import type { NpmPatch } from './npm-patch.ts'
19
+ import { opened } from './pretty-print.ts'
20
+
21
+ // A side with no files, as Review compares a package's first version with:
22
+ // one for each comparison, as working one out keeps its line counts on it.
23
+ export const emptySide = (): BundleDetails => ({ integrity: '(empty)', kind: 'sourcemap', size: 0, json: { version: 3, sources: [], sourcesContent: [] } })
24
+
25
+ // A version's files as the viewer reads them for a comparison (ui/view/npm-package.js
26
+ // npmPackageDetails): its texts, and those that are not text by their size and digest.
27
+ export function npmComparedSide(integrity: string, files: NpmPackageFile[]): BundleDetails & { npmBinaries: Map<string, { size: number; digest: string }> } {
28
+ const rows = npmFileRows(files)
29
+ return {
30
+ integrity, kind: 'sourcemap', size: 0,
31
+ json: { version: 3, sources: rows.map(([path]) => path), sourcesContent: rows.map(([, , text]) => text) },
32
+ npmBinaries: new Map(rows.flatMap(([path, size, text, digest]) => (text === null ? [[path, { size, digest: digest! }] as const] : []))),
33
+ }
34
+ }
35
+
36
+ // The comparison of `base` with `other`, within a reason `scope` where given, as sent.
37
+ export async function comparisonBody(base: BundleDetails, other: BundleDetails, scope = ''): Promise<OpenedBlob> {
38
+ const comparison = prepareComparison(base, other, scope)
39
+ const { files } = comparison
40
+ const json = JSON.stringify({ ...comparison, files: { ...files, basePaths: files.root ? [...files.basePaths] : [] } })
41
+ return opened(await encodeBrotli(Buffer.from(json)))
42
+ }
43
+
44
+ // A version's `files` as `patch` changes them (npm-patch.ts patchedFiles), as
45
+ // the viewer reads a version's (npm-loads.ts loadNpmPackageBody), with the
46
+ // patch, as sent: `{ name, version, private, integrity, patch, files }`.
47
+ export async function patchedVersionBody(doc: NpmVersionDocument, patch: NpmPatch, files: NpmPackageFile[]): Promise<OpenedBlob> {
48
+ const json = JSON.stringify({ name: doc.name, version: doc.version, private: doc.private, integrity: doc.dist.integrity, patch, files: npmFileRows(files) })
49
+ return opened(await encodeBrotli(Buffer.from(json)))
50
+ }
@@ -0,0 +1,163 @@
1
+ // Managed-server boot config. GitHub user authorization establishes identity;
2
+ // optional App installation credentials enable repository access. A single
3
+ // GitHub App can provide both flows, with repository grants at installation.
4
+ import { env } from 'node:process'
5
+ import { databaseUrls } from '../server-common/database-config.ts'
6
+ import { MAX_UPLOAD_BYTES } from './uploads.ts'
7
+ import { parseStorageKey } from '../server-common/storage-crypto.ts'
8
+ import { defaultCacheDir } from '@preventive/upstream/npm.js'
9
+ import { RESERVED_COOKIES } from './session.ts'
10
+ import { LOOPBACK_HOSTS } from '../server-common/origin.ts'
11
+
12
+ export interface ManagedConfig {
13
+ port: number
14
+ host: string
15
+ dbPath: string
16
+ neonUrl?: string | null
17
+ blobToken?: string | null
18
+ storageEncryptionKey?: string | null
19
+ storageEncryptionMigrate?: boolean
20
+ storageEncryptionMigrateMaxMs?: number
21
+ vercelPreview?: boolean
22
+ serverless?: boolean
23
+ // Upstream's disk cache (setCacheDir) for audits and bundle builds: its default
24
+ // location, or null for none, as on Vercel, where the database keeps listings.
25
+ upstreamCacheDir?: string | null
26
+ debug: boolean
27
+ allowShare: boolean
28
+ trustProxyEnv: string | undefined
29
+ // GitHub App user-authorization (identity) credentials — the App's client id
30
+ // + secret, used by the login flow.
31
+ githubClientId: string
32
+ githubClientSecret: string
33
+ // Preapproved GitHub identity promoted on login when it is the only user
34
+ // and its role is No access, including a login after registration.
35
+ initialAdminGithubId: number | null
36
+ // Absolute callback registered with GitHub, e.g.
37
+ // 'https://triage.example.com/api/oauth/github/callback'.
38
+ oauthCallbackUrl: string
39
+ // Whether cookies carry `Secure` (callback is https). Also gates the
40
+ // `__Host-` prefix, so loopback http dev can run with a plain cookie name.
41
+ cookieSecure: boolean
42
+ sessionCookieName: string
43
+ sessionTtlMs: number
44
+ // How long GitHub's answer on a user's access to a repository (its
45
+ // visibility, their permission) is kept for that user and repository
46
+ // (repository-browser.ts), asked again past it; 0 asks on every request
47
+ // (MANAGED_REPOSITORY_ACCESS_CACHE_MS, five minutes by default).
48
+ repositoryAccessCacheMs: number
49
+ // Optional installation credentials for the same GitHub App as login.
50
+ // Repository permissions are approved when connecting repositories.
51
+ githubAppId: string | null
52
+ githubAppPrivateKey: string | null
53
+ githubAppSlug: string | null
54
+ githubNewIssueLabels?: string
55
+ // Max accepted size (bytes) for an uploaded report on the "Manage reports"
56
+ // page, before storage compression (default 25 MiB).
57
+ maxReportBytes: number
58
+ // Max accepted size (bytes) for an uploaded bundle (sourcemap / stasis
59
+ // archive). Bundles run larger than reports, so a higher cap (default 200 MiB).
60
+ maxBundleBytes: number
61
+ // How many triage-trail events to keep per finding (managed_finding_triage_event):
62
+ // 0, the default, keeps everything — the trail is the record. An operator
63
+ // who would rather bound the store sets a positive count; older events of a
64
+ // finding are then trimmed as new ones land.
65
+ triageHistoryLimit: number
66
+ }
67
+
68
+ function fail(msg: string): never {
69
+ throw new Error(msg)
70
+ }
71
+
72
+ function requireStr(name: string): string {
73
+ const v = env[name]
74
+ if (v == null || v === '') fail(`Missing required env ${name} (managed mode).`)
75
+ return v
76
+ }
77
+
78
+ function intEnv(name: string, def: number, min: number, max: number): number {
79
+ const raw = env[name]
80
+ const n = raw == null ? def : Number(raw)
81
+ if (!Number.isSafeInteger(n) || n < min || n > max) {
82
+ fail(`Invalid ${name}: ${raw} — must be an integer in [${min}, ${max}].`)
83
+ }
84
+ return n
85
+ }
86
+
87
+ function optionalGithubId(name: string): number | null {
88
+ const raw = env[name]
89
+ if (raw == null || raw === '') return null
90
+ const id = Number(raw)
91
+ if (!/^[1-9]\d*$/u.test(raw) || !Number.isSafeInteger(id)) {
92
+ fail(`Invalid ${name}: must be a single positive numeric GitHub user ID.`)
93
+ }
94
+ return id
95
+ }
96
+
97
+ function urlOrFail(name: string, raw: string): URL {
98
+ try { return new URL(raw) } catch { fail(`${name} is not a valid URL: ${raw}`) }
99
+ }
100
+
101
+ export function loadManagedConfig({ combined = false } = {}): ManagedConfig {
102
+ const serverless = env['VERCEL'] === '1'
103
+ const neonUrl = databaseUrls({ combined }).managed
104
+ const blobToken = env['BLOB_READ_WRITE_TOKEN'] || null
105
+ const storageEncryptionKey = env['MANAGED_STORAGE_ENCRYPTION_KEY'] || null
106
+ parseStorageKey(storageEncryptionKey)
107
+ const storageEncryptionMigrate = env['MANAGED_STORAGE_ENCRYPTION_MIGRATE'] === '1'
108
+ if (storageEncryptionMigrate && !storageEncryptionKey) fail('MANAGED_STORAGE_ENCRYPTION_MIGRATE requires MANAGED_STORAGE_ENCRYPTION_KEY.')
109
+ if (serverless && !neonUrl) fail('Vercel managed mode requires DATABASE_URL or MANAGED_DATABASE_URL.')
110
+ if (neonUrl && !blobToken) fail('Managed Neon mode requires BLOB_READ_WRITE_TOKEN.')
111
+ const host = env['HOST'] ?? '127.0.0.1'
112
+ const oauthCallbackUrl = requireStr('OAUTH_CALLBACK_URL')
113
+ const callback = urlOrFail('OAUTH_CALLBACK_URL', oauthCallbackUrl)
114
+ const cookieSecure = callback.protocol === 'https:'
115
+ // A `__Host-` cookie mandates `Secure`, so any non-loopback bind must be
116
+ // HTTPS — fail fast (mirrors server-e2e's boot check). Loopback dev over
117
+ // http is allowed with a non-prefixed cookie name.
118
+ if ((serverless || !LOOPBACK_HOSTS.has(host)) && !cookieSecure) {
119
+ fail(`Vercel or non-loopback HOST=${host} requires an https OAUTH_CALLBACK_URL — the session cookie needs Secure.`)
120
+ }
121
+ const sessionCookieName = env['SESSION_COOKIE_NAME'] ?? '__Host-dvsid'
122
+ if (sessionCookieName.startsWith('__Host-') && !cookieSecure) {
123
+ fail(`SESSION_COOKIE_NAME=${sessionCookieName} uses the __Host- prefix but the callback is not https. Use a non-prefixed name for loopback http dev.`)
124
+ }
125
+ if (RESERVED_COOKIES.includes(sessionCookieName.replace(/^__Host-/u, ''))) {
126
+ fail(`SESSION_COOKIE_NAME=${sessionCookieName} is reserved for another managed cookie. Choose a different name.`)
127
+ }
128
+ return {
129
+ neonUrl, blobToken, serverless, storageEncryptionKey, storageEncryptionMigrate,
130
+ storageEncryptionMigrateMaxMs: intEnv('MANAGED_STORAGE_ENCRYPTION_MIGRATE_MAX_MS', 150_000, 1, serverless ? 240_000 : 3_600_000),
131
+ vercelPreview: env['VERCEL_ENV'] === 'preview',
132
+ upstreamCacheDir: serverless ? null : defaultCacheDir ?? null,
133
+ port: intEnv('PORT', 8765, 0, 65535),
134
+ host,
135
+ // DB_PATH belongs to e2e in a combined process. Keep the two stores apart.
136
+ dbPath: env['MANAGED_DB_PATH'] ?? (combined ? undefined : env['DB_PATH']) ?? 'server-managed/data/managed.db',
137
+ debug: env['DEBUG'] === '1' || env['DEBUG'] === 'true',
138
+ allowShare: env['DEEPVIEW_ALLOW_SHARE'] === '1',
139
+ trustProxyEnv: env['TRUST_PROXY'] ?? (serverless ? '1' : undefined),
140
+ githubClientId: requireStr('GITHUB_CLIENT_ID'),
141
+ githubClientSecret: requireStr('GITHUB_CLIENT_SECRET'),
142
+ initialAdminGithubId: optionalGithubId('MANAGED_INITIAL_ADMIN_GITHUB_ID'),
143
+ oauthCallbackUrl,
144
+ cookieSecure,
145
+ sessionCookieName,
146
+ sessionTtlMs: intEnv('SESSION_TTL_MS', 1_209_600_000, 60_000, 7_776_000_000),
147
+ repositoryAccessCacheMs: intEnv('MANAGED_REPOSITORY_ACCESS_CACHE_MS', 300_000, 0, 3_600_000),
148
+ githubAppId: env['GITHUB_APP_ID'] ?? null,
149
+ githubAppPrivateKey: normalizePem(env['GITHUB_APP_PRIVATE_KEY']),
150
+ githubAppSlug: env['GITHUB_APP_SLUG'] ?? null,
151
+ githubNewIssueLabels: env['GITHUB_NEW_ISSUE_LABELS'] ?? '',
152
+ maxReportBytes: intEnv('MAX_REPORT_BYTES', 26_214_400, 1, 104_857_600),
153
+ maxBundleBytes: intEnv('MAX_BUNDLE_BYTES', 209_715_200, 1, MAX_UPLOAD_BYTES),
154
+ triageHistoryLimit: intEnv('TRIAGE_HISTORY_LIMIT', 0, 0, 1_000_000_000),
155
+ }
156
+ }
157
+
158
+ // PEM private keys are awkward in env vars; accept a literal multi-line value or
159
+ // one with escaped newlines (`\n`). Empty/absent → null (private repos off).
160
+ function normalizePem(raw: string | undefined): string | null {
161
+ if (raw == null || raw === '') return null
162
+ return raw.includes('\\n') ? raw.replaceAll('\\n', '\n') : raw
163
+ }
@@ -0,0 +1,15 @@
1
+ import type { ManagedDb, StoredUser } from './db.ts'
2
+
3
+ export type RepoScope = { repoId: number; path: string | null }
4
+ type Content = { repoId: number | null; repoDirectory?: string }
5
+
6
+ // Read grants for each request: neither the manager role nor a cached page
7
+ // confers repository access. Bundles have repository scope; reports also have
8
+ // a directory scope. Unassigned content is only available to administrators.
9
+ export async function contentAccess(db: Pick<ManagedDb, 'listRepoScopesForUser'>, user: StoredUser) {
10
+ const scopes = user.role === 'admin' ? null : await db.listRepoScopesForUser(user.id)
11
+ const bundle = (item: Content) => scopes == null || scopes.some(scope => scope.repoId === item.repoId)
12
+ const report = (item: Content) => scopes == null || scopes.some(scope => scope.repoId === item.repoId
13
+ && (!scope.path || item.repoDirectory === scope.path || item.repoDirectory?.startsWith(scope.path + '/')))
14
+ return { scopes, bundle, report }
15
+ }
@@ -0,0 +1,25 @@
1
+ // Token helpers for the managed auth server. The raw session token lives ONLY
2
+ // in the cookie; the DB row id is its SHA-256 (see db.ts / session.ts), so a
3
+ // DB read can't reconstruct a live cookie. No HMAC pepper is needed — the
4
+ // tokens are 256-bit random, not guessable or reversible from their hash.
5
+ import { createHash, randomBytes, timingSafeEqual } from 'node:crypto'
6
+
7
+ // 256-bit URL-safe random token: the session cookie value and the OAuth CSRF
8
+ // `state` nonce.
9
+ export function randomToken(): string {
10
+ return randomBytes(32).toString('base64url')
11
+ }
12
+
13
+ // At-rest id for a session cookie token (stored as the managed_session PK).
14
+ export function hashToken(token: string): string {
15
+ return createHash('sha256').update(token, 'utf8').digest('base64url')
16
+ }
17
+
18
+ // Constant-time equality for CSRF / OAuth-state checks. A length mismatch
19
+ // short-circuits (the length of these fixed-width tokens isn't a secret).
20
+ export function safeEqual(a: string, b: string): boolean {
21
+ const ab = Buffer.from(a, 'utf8')
22
+ const bb = Buffer.from(b, 'utf8')
23
+ if (ab.length !== bb.length) return false
24
+ return timingSafeEqual(ab, bb)
25
+ }