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

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-563V5VVT.js +266 -0
  111. package/out/chunk-5AVGKFMR.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-5UJHJWFU.js +4 -0
  116. package/out/chunk-6CCSTJWB.js +1 -0
  117. package/out/chunk-6VOB5WXX.js +2 -0
  118. package/out/chunk-6WMQVUT2.js +3 -0
  119. package/out/chunk-6Y6PZ2BU.js +9 -0
  120. package/out/chunk-74JZTGTO.js +11 -0
  121. package/out/chunk-7BKKYVWR.js +7 -0
  122. package/out/chunk-7C7DWL7I.js +1 -0
  123. package/out/chunk-7HP2VYIC.js +2 -0
  124. package/out/chunk-7YFJUT2P.js +1 -0
  125. package/out/chunk-7YO4QV5P.js +1 -0
  126. package/out/chunk-A4BBBHQU.js +1 -0
  127. package/out/chunk-B64CTMVU.js +4 -0
  128. package/out/chunk-BEKYZCPX.js +14 -0
  129. package/out/chunk-C4Z6ZBXV.js +10 -0
  130. package/out/chunk-CU3FPB3P.js +1 -0
  131. package/out/chunk-DEVAORP2.js +1 -0
  132. package/out/chunk-DOYTKRIR.js +53 -0
  133. package/out/chunk-DUASGS2O.js +8 -0
  134. package/out/chunk-EEJA7JBI.js +13 -0
  135. package/out/chunk-FSU2PLJL.js +1 -0
  136. package/out/chunk-GO7FT4OD.js +1 -0
  137. package/out/chunk-GX5UXWT4.js +1 -0
  138. package/out/chunk-H4FEC57K.js +1 -0
  139. package/out/chunk-ITUKKCCK.js +10 -0
  140. package/out/chunk-IYPY47MC.js +1 -0
  141. package/out/chunk-K4XJHM2T.js +1 -0
  142. package/out/chunk-LBD3M3J6.js +1 -0
  143. package/out/chunk-LVSLM7HB.js +1 -0
  144. package/out/chunk-LVW7WWV4.js +1 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OAWQNDAO.js +3 -0
  148. package/out/chunk-OOJM4CTU.js +1 -0
  149. package/out/chunk-PEE47ANR.js +1 -0
  150. package/out/chunk-PKLVXUEI.js +11 -0
  151. package/out/chunk-PLGH63UC.js +2 -0
  152. package/out/chunk-PNHBZGDD.js +1 -0
  153. package/out/chunk-PTFYDJUP.js +1 -0
  154. package/out/chunk-PWFUOLZK.js +17 -0
  155. package/out/chunk-PXK7EU4V.js +1 -0
  156. package/out/chunk-QD3IBSF4.js +7 -0
  157. package/out/chunk-QI66YA4F.js +1 -0
  158. package/out/chunk-QRKFPLA4.js +80 -0
  159. package/out/chunk-R3NZFXVR.js +1 -0
  160. package/out/chunk-R5O6FAW4.js +2 -0
  161. package/out/chunk-RPNO56H2.js +1 -0
  162. package/out/chunk-SSPDMA6D.js +1 -0
  163. package/out/chunk-SZWPYLPC.js +1 -0
  164. package/out/chunk-TUII34K2.js +1 -0
  165. package/out/chunk-UJP4PQJA.js +1 -0
  166. package/out/chunk-UJSJMXEG.js +1 -0
  167. package/out/chunk-UR4WYMIP.js +1 -0
  168. package/out/chunk-VHEXSGGP.js +1 -0
  169. package/out/chunk-VYYUMYVW.js +9 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-WFBVS4QI.js +1 -0
  172. package/out/chunk-XM4RLC4A.js +2 -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 +354 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +568 -0
  202. package/risk/files/script.js +410 -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 +269 -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 +1915 -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 +158 -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 +6327 -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,83 @@
1
+ // Per-finding triage annotations on a managed server — shared by the server
2
+ // (which stores one row per finding id, validates the wire shape, and decides
3
+ // per report which ids a viewer may read or write) and the managed client
4
+ // (which mirrors entries into its local triage map). Keyed by finding id
5
+ // alone, like that map: reports mostly repeat one another (a re-scan of the
6
+ // same code carries the same finding ids), and a finding's triage is shared by
7
+ // every report that carries it. A wire entry carries the four server-persisted
8
+ // fields below, or is null for a cleared entry (the server's tombstone); the
9
+ // client's `ignoredReports` deliberately does NOT ride this wire — the
10
+ // per-report ignore is a client-local concept keyed by report name.
11
+ export type TriageBucket = 'inprogress' | 'fixed' | 'invalid' | 'deleted' | 'ignored'
12
+
13
+ const TRIAGE_BUCKETS: readonly TriageBucket[] = ['inprogress', 'fixed', 'invalid', 'deleted', 'ignored']
14
+
15
+ // One finding's server-side triage entry (also the write shape — writes
16
+ // replace the whole entry). Absent fields are unset; `flagged` is tri-state:
17
+ // absent = never set, `true` = flagged, `false` = an explicit un-flag
18
+ // tombstone that must round-trip (see client/state.ts TriageEntry).
19
+ export type TriageEntryPatch = {
20
+ color?: string
21
+ triage?: TriageBucket
22
+ // Legacy triage history/migration only. New comments use separate records;
23
+ // the managed triage write endpoint rejects this field.
24
+ comment?: string
25
+ fix?: string
26
+ flagged?: boolean
27
+ }
28
+
29
+ // Length caps enforced at the write endpoint so one entry can't balloon a row.
30
+ export const MAX_TRIAGE_TEXT = 10_000
31
+ export const MAX_TRIAGE_COLOR = 50
32
+
33
+ // Caps on one write request as a whole — shared with the client, which batches
34
+ // within them: entries per request, the finding-id length (real ids are 36-char
35
+ // uuids), and the JSON body (the server's small default is too small for entry
36
+ // batches, which carry free text).
37
+ export const MAX_TRIAGE_ENTRIES = 200
38
+ export const MAX_FINDING_ID = 100
39
+ export const MAX_TRIAGE_BODY_BYTES = 262_144
40
+
41
+ // The most trail events one history read returns (newest first). Retention is
42
+ // the server's: everything is kept unless its TRIAGE_HISTORY_LIMIT says
43
+ // otherwise.
44
+ export const MAX_TRIAGE_HISTORY = 200
45
+
46
+ export function isTriageBucket(x: unknown): x is TriageBucket {
47
+ return typeof x === 'string' && (TRIAGE_BUCKETS as readonly string[]).includes(x)
48
+ }
49
+
50
+ // Coerce one wire entry (a request-body value) into a clean patch. `null`
51
+ // means "clear the entry"; a malformed value (wrong type, unknown bucket,
52
+ // over-cap string, non-boolean flagged) is 'invalid' so the endpoint 400s
53
+ // rather than store garbage. Null/empty-string fields count as absent (an
54
+ // absent field is cleared anyway under whole-entry replace); unknown keys are
55
+ // ignored.
56
+ export function parseTriageEntryPatch(x: unknown): TriageEntryPatch | null | 'invalid' {
57
+ if (x === null) return null
58
+ if (typeof x !== 'object' || Array.isArray(x)) return 'invalid'
59
+ const o = x as Record<string, unknown>
60
+ const out: TriageEntryPatch = {}
61
+ const color = o['color']
62
+ if (color != null) {
63
+ if (typeof color !== 'string' || color.length > MAX_TRIAGE_COLOR) return 'invalid'
64
+ if (color !== '') out.color = color
65
+ }
66
+ const triage = o['triage']
67
+ if (triage != null) {
68
+ if (!isTriageBucket(triage)) return 'invalid'
69
+ out.triage = triage
70
+ }
71
+ for (const key of ['comment', 'fix'] as const) {
72
+ const v = o[key]
73
+ if (v == null) continue
74
+ if (typeof v !== 'string' || v.length > MAX_TRIAGE_TEXT) return 'invalid'
75
+ if (v !== '') out[key] = v
76
+ }
77
+ const flagged = o['flagged']
78
+ if (flagged != null) {
79
+ if (typeof flagged !== 'boolean') return 'invalid'
80
+ out.flagged = flagged
81
+ }
82
+ return out
83
+ }
@@ -0,0 +1,126 @@
1
+ // Managed uploads cross TLS-terminating proxies (Cloudflare, corporate
2
+ // gateways) that would otherwise read report and bundle bytes in plaintext.
3
+ // The server sends each session an X25519 public key; the browser seals every
4
+ // upload to it with a fresh ephemeral key (X25519 → HKDF-SHA-256 →
5
+ // AES-256-GCM), so the content key itself never crosses the proxy. Text is
6
+ // gzipped before sealing; binary content is sealed as is.
7
+ //
8
+ // Sealed body: version(1) | flags(1) | ephemeral public key(32), then the
9
+ // payload in 1 MiB segments, each sealed under nonce = big-endian segment
10
+ // index with the last byte marking the final segment. The header is the HKDF
11
+ // salt, so altering it changes the key. Segments bound browser memory for
12
+ // large bundles, and their nonces reject reordered, truncated or extended
13
+ // bodies. Every upload derives its own key, so counter nonces never repeat.
14
+
15
+ import { gunzipBytes } from '../gzip.js'
16
+ import { encodeUtf8 } from '../utf8.js'
17
+
18
+ // Set (to the format version) on a request whose body is sealed.
19
+ export const UPLOAD_SEAL_HEADER = 'x-upload-encryption'
20
+ const VERSION = 1
21
+ const FLAG_GZIP = 1
22
+ const CURVE = { name: 'X25519' }
23
+ const HEADER_BYTES = 2 + 32
24
+ const TAG_BYTES = 16
25
+ const SEGMENT_BYTES = 1024 * 1024
26
+ const SNIFF_BYTES = 64 * 1024
27
+ const KEY_INFO = 'deepview-managed-upload.v1.content-key'
28
+
29
+ // The largest sealed body for `maxBytes` of content. Deflate can grow
30
+ // incompressible text slightly (its worst case is about 0.03%).
31
+ export function maxSealedBytes(maxBytes: number): number {
32
+ const payload = maxBytes + Math.ceil(maxBytes / 1024) + 64
33
+ return HEADER_BYTES + payload + TAG_BYTES * (Math.floor(payload / SEGMENT_BYTES) + 1)
34
+ }
35
+
36
+ function nonce(index: number, final: boolean): Uint8Array<ArrayBuffer> {
37
+ const iv = new Uint8Array(12)
38
+ new DataView(iv.buffer).setUint32(7, index)
39
+ iv[11] = final ? 1 : 0
40
+ return iv
41
+ }
42
+
43
+ async function contentKey(secret: ArrayBuffer, header: Uint8Array<ArrayBuffer>, usage: KeyUsage): Promise<CryptoKey> {
44
+ const ikm = await crypto.subtle.importKey('raw', secret, 'HKDF', false, ['deriveKey'])
45
+ return await crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-256', salt: header, info: encodeUtf8(KEY_INFO) },
46
+ ikm, { name: 'AES-GCM', length: 256 }, false, [usage])
47
+ }
48
+
49
+ // Archives and other binary content would only grow under gzip. A NUL byte or
50
+ // invalid UTF-8 in the first 64 KiB marks content as binary.
51
+ async function isText(blob: Blob): Promise<boolean> {
52
+ const head = new Uint8Array(await blob.slice(0, SNIFF_BYTES).arrayBuffer())
53
+ if (head.includes(0)) return false
54
+ try { new TextDecoder('utf-8', { fatal: true }).decode(head, { stream: true }); return true }
55
+ catch { return false }
56
+ }
57
+
58
+ // Seal `blob` to the server's raw public key. Reads the input as a stream;
59
+ // sealed segments are kept as Blobs, which browsers may page to disk. An abort
60
+ // stops reading at the next chunk.
61
+ export async function sealUpload(blob: Blob, publicKey: Uint8Array<ArrayBuffer>, signal?: AbortSignal): Promise<Blob> {
62
+ const gzip = await isText(blob)
63
+ const [server, ephemeral] = await Promise.all([
64
+ crypto.subtle.importKey('raw', publicKey, CURVE, false, []),
65
+ crypto.subtle.generateKey(CURVE, false, ['deriveBits']) as Promise<CryptoKeyPair>,
66
+ ])
67
+ const header = new Uint8Array(HEADER_BYTES)
68
+ header[0] = VERSION
69
+ header[1] = gzip ? FLAG_GZIP : 0
70
+ header.set(new Uint8Array(await crypto.subtle.exportKey('raw', ephemeral.publicKey)), 2)
71
+ const key = await contentKey(await crypto.subtle.deriveBits({ name: 'X25519', public: server }, ephemeral.privateKey, 256), header, 'encrypt')
72
+ const parts = [new Blob([header])], segment = new Uint8Array(SEGMENT_BYTES)
73
+ let filled = 0, index = 0
74
+ const seal = async (final: boolean) => {
75
+ parts.push(new Blob([await crypto.subtle.encrypt({ name: 'AES-GCM', iv: nonce(index++, final) }, key, segment.subarray(0, filled))]))
76
+ filled = 0
77
+ }
78
+ const stream: ReadableStream<Uint8Array> = gzip ? blob.stream().pipeThrough(new CompressionStream('gzip')) : blob.stream()
79
+ const reader = stream.getReader()
80
+ try {
81
+ for (let read = await reader.read(); !read.done; read = await reader.read()) {
82
+ signal?.throwIfAborted()
83
+ for (let offset = 0; offset < read.value.length;) {
84
+ // A full segment is final only if the input ends with it.
85
+ if (filled === SEGMENT_BYTES) await seal(false)
86
+ const length = Math.min(SEGMENT_BYTES - filled, read.value.length - offset)
87
+ segment.set(read.value.subarray(offset, offset + length), filled)
88
+ filled += length
89
+ offset += length
90
+ }
91
+ }
92
+ } catch (err) {
93
+ await reader.cancel(err).catch(() => {})
94
+ throw err
95
+ }
96
+ await seal(true)
97
+ return new Blob(parts)
98
+ }
99
+
100
+ // Open a sealed body with the session's private JWK. Throws 'too-large' when
101
+ // the content exceeds `maxBytes`, else 'bad-upload' for any invalid body.
102
+ export async function openUpload(sealed: Uint8Array<ArrayBuffer>, privateKey: JsonWebKey, maxBytes: number): Promise<Uint8Array<ArrayBuffer>> {
103
+ // Every segment but the last is full, so the layout follows from the length.
104
+ const rest = sealed.length - HEADER_BYTES
105
+ const count = Math.ceil(rest / (SEGMENT_BYTES + TAG_BYTES))
106
+ const last = rest - (count - 1) * (SEGMENT_BYTES + TAG_BYTES)
107
+ if (rest < TAG_BYTES || last < TAG_BYTES || sealed[0] !== VERSION || (sealed[1]! & ~FLAG_GZIP) !== 0) throw new Error('bad-upload')
108
+ const gzip = sealed[1] === FLAG_GZIP, plain = new Uint8Array(rest - count * TAG_BYTES)
109
+ if (!gzip && plain.length > maxBytes) throw new Error('too-large')
110
+ try {
111
+ const header = sealed.slice(0, HEADER_BYTES)
112
+ const [key, peer] = await Promise.all([
113
+ crypto.subtle.importKey('jwk', privateKey, CURVE, false, ['deriveBits']),
114
+ crypto.subtle.importKey('raw', header.slice(2), CURVE, false, []),
115
+ ])
116
+ const content = await contentKey(await crypto.subtle.deriveBits({ name: 'X25519', public: peer }, key, 256), header, 'decrypt')
117
+ for (let index = 0; index < count; index++) {
118
+ const start = HEADER_BYTES + index * (SEGMENT_BYTES + TAG_BYTES)
119
+ const segment = sealed.subarray(start, Math.min(start + SEGMENT_BYTES + TAG_BYTES, sealed.length))
120
+ plain.set(new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce(index, index === count - 1) }, content, segment)), index * SEGMENT_BYTES)
121
+ }
122
+ } catch (err) { throw new Error('bad-upload', { cause: err }) }
123
+ if (!gzip) return plain
124
+ try { return await gunzipBytes(plain, { maxBytes }) }
125
+ catch (err) { throw new Error(err instanceof RangeError ? 'too-large' : 'bad-upload', { cause: err }) }
126
+ }
@@ -0,0 +1,98 @@
1
+ // JSON pretty-printed for reading, by the viewer (ui/view/pretty-source.js).
2
+
3
+ // Whether a path is JSON, which the viewer formats rather than the server.
4
+ export const jsonPrinted = path => /\.json$/iu.test(path)
5
+
6
+ // The widths prettyJSON folds to in the pretty-print toggle's layouts.
7
+ export const JSON_LAYOUT_WIDTHS = { indented: 0, folded: 120 }
8
+
9
+ const isContainer = value => value !== null && typeof value === 'object'
10
+
11
+ // `value` on one line, `{ "a": [1, 2] }`, or null where that is longer than
12
+ // `room`: given up on as soon as it is, as a long one is tried at every level.
13
+ function oneLine(value, room) {
14
+ if (!isContainer(value)) {
15
+ if (typeof value === 'string' && value.length + 2 > room) return null
16
+ const text = JSON.stringify(value)
17
+ return text.length <= room ? text : null
18
+ }
19
+ const array = Array.isArray(value), keys = array ? null : Object.keys(value)
20
+ const count = array ? value.length : keys.length
21
+ if (count === 0) return array ? '[]' : '{}'
22
+ let text = array ? '[' : '{ '
23
+ for (let i = 0; i < count && text.length <= room; i++) {
24
+ if (i > 0) text += ', '
25
+ if (!array) text += `${JSON.stringify(keys[i])}: `
26
+ const part = oneLine(array ? value[i] : value[keys[i]], room - text.length - (array ? 1 : 2))
27
+ if (part === null) return null
28
+ text += part
29
+ }
30
+ text += array ? ']' : ' }'
31
+ return text.length <= room ? text : null
32
+ }
33
+
34
+ // `data`, a value JSON.parse returned, laid out as `JSON.stringify(data,
35
+ // undefined, 2)` does, but for each object or array whose one-line form fits
36
+ // its line within `width`, kept on it, and an array of strings alone that
37
+ // doesn't, as many to a line as fit. Throws past `limit` characters, which
38
+ // deep nesting can run to from a short text.
39
+ export function prettyJSON(data, { width = 120, limit = Infinity } = {}) {
40
+ const lines = []
41
+ let length = -1 // no line end before the first line
42
+ const push = line => {
43
+ if ((length += line.length + 1) > limit) throw new RangeError(`The copy would run past ${limit.toLocaleString('en')} characters.`)
44
+ lines.push(line)
45
+ }
46
+ const write = (value, indent, head, tail) => {
47
+ const line = oneLine(value, width - indent.length - head.length - tail.length)
48
+ if (line !== null || !isContainer(value)) {
49
+ push(`${indent}${head}${line ?? JSON.stringify(value)}${tail}`)
50
+ return
51
+ }
52
+ const array = Array.isArray(value), keys = array ? null : Object.keys(value)
53
+ const count = array ? value.length : keys.length
54
+ push(`${indent}${head}${array ? '[' : '{'}`)
55
+ if (array && value.every(item => typeof item === 'string')) {
56
+ const room = width - indent.length - 2
57
+ let row = ''
58
+ for (const [i, item] of value.entries()) {
59
+ const part = `${JSON.stringify(item)}${i < count - 1 ? ',' : ''}`
60
+ if (row && row.length + 1 + part.length > room) {
61
+ push(`${indent} ${row}`)
62
+ row = ''
63
+ }
64
+ row = row ? `${row} ${part}` : part
65
+ }
66
+ push(`${indent} ${row}`)
67
+ } else {
68
+ for (let i = 0; i < count; i++) {
69
+ write(array ? value[i] : value[keys[i]], `${indent} `, array ? '' : `${JSON.stringify(keys[i])}: `, i < count - 1 ? ',' : '')
70
+ }
71
+ }
72
+ push(`${indent}${array ? ']' : '}'}${tail}`)
73
+ }
74
+ write(data, '', '', '')
75
+ return lines.join('\n')
76
+ }
77
+
78
+ // The most characters a text's copy (prettyJsonText, and a source map's
79
+ // listing: sourcemap-listing.js) runs to: four times the largest file
80
+ // formatted, far past what a file not nested hundreds deep needs.
81
+ export const COPY_LIMIT = 16 * 1024 * 1024
82
+
83
+ // A JSON text without the blanks between its tokens.
84
+ const blankless = text => text.replaceAll(/("(?:[^"\\]+|\\.)*")|[\t\n\r ]+/gu, '$1')
85
+
86
+ // A JSON text pretty-printed (prettyJSON, `width` 0 for JSON.stringify's
87
+ // layout), keeping whether it ends in a line end, or null where it isn't JSON.
88
+ // Throws where the copy would read otherwise than the text: a key given
89
+ // twice, an escape or a number respelled.
90
+ export function prettyJsonText(text, { width } = {}) {
91
+ let value
92
+ try { value = JSON.parse(text) } catch { return null }
93
+ if (!text.isWellFormed()) throw new Error('Its text has lone surrogates.')
94
+ const copy = `${prettyJSON(value, { width, limit: COPY_LIMIT })}${text.endsWith('\n') ? '\n' : ''}`
95
+ if (JSON.stringify(JSON.parse(copy)) !== JSON.stringify(value)) throw new Error('The copy reads as another value.')
96
+ if (blankless(text) !== blankless(copy)) throw new Error('The copy would change more than its layout: a key given twice, or an escape, a number or the order of keys written otherwise.')
97
+ return copy
98
+ }
@@ -0,0 +1,20 @@
1
+ // The files the viewer prints itself by their path (ui/view/pretty-source.js), as the server counts them too
2
+ // (npm-delta-worker.js): JSON in the toggle's layout, source maps listed, whose listings' diff is drawn only where
3
+ // it reads back to the new map (`refusal`: why not).
4
+ import { isSourceMap } from '../risk/files/source-map-link.js'
5
+ import { JSON_LAYOUT_WIDTHS, jsonPrinted, prettyJsonText } from './pretty-json.js'
6
+ import { printableSize } from './pretty-print.js'
7
+ import { listSourcemap, sourcemapDiffRebuilds, sourcemapPrinted } from './pretty-sourcemap.js'
8
+
9
+ const parses = text => {
10
+ try { JSON.parse(text); return true } catch { return false }
11
+ }
12
+ const KINDS = [
13
+ { printed: jsonPrinted, printable: parses, layouts: true, copy: (text, layout) => prettyJsonText(text, { width: JSON_LAYOUT_WIDTHS[layout] }) },
14
+ { printed: sourcemapPrinted, printable: isSourceMap, layouts: false, copy: text => listSourcemap(text),
15
+ refusal: (drawn, [before, after], [listed, listing]) => sourcemapDiffRebuilds(drawn, { text: before, listing: listed }, { text: after, listing }) },
16
+ ]
17
+
18
+ export const viewerKind = path => KINDS.find(kind => kind.printed(path)) ?? null
19
+ // Whether a file of `kind` can be printed: no larger than formatted, and read as one.
20
+ export const viewerPrintable = (kind, text) => printableSize(text) && kind.printable(text)
@@ -0,0 +1,6 @@
1
+ // Type declarations for `common/pretty-print.js`, for `.ts` callers.
2
+
3
+ export const MAX_PRETTY_BYTES: number
4
+ export function prettyExtension(path: string): string | null
5
+ export function needsPrettyPrint(path: string, text: string, read?: () => { category: string }): boolean
6
+ export function layoutBlankList(blank: unknown): number[] | null
@@ -0,0 +1,36 @@
1
+ // Minified files pretty-printed by the server (server-managed/pretty-print.ts)
2
+ // for the viewer (ui/view/pretty-source.js).
3
+ import { npmFileReadability } from '../risk/files/readability.js'
4
+ import { utf8ByteLength } from './utf8.js'
5
+
6
+ // The extensions formatted, each parsed as the language it names; JSON the
7
+ // viewer formats itself (pretty-json.js).
8
+ const PRETTY_EXTENSIONS = new Set(['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx', 'css'])
9
+
10
+ // The largest file formatted, in UTF-8 bytes: formatting holds a syntax tree
11
+ // a hundred times the file's size.
12
+ export const MAX_PRETTY_BYTES = 4 * 1024 * 1024
13
+
14
+ // Whether a text is no larger than formatted (MAX_PRETTY_BYTES): its UTF-8
15
+ // counted only where its length leaves it in doubt, each of its UTF-16 units
16
+ // one to three bytes.
17
+ export const printableSize = text => text.length * 3 <= MAX_PRETTY_BYTES || (text.length <= MAX_PRETTY_BYTES && utf8ByteLength(text) <= MAX_PRETTY_BYTES)
18
+
19
+ // The extension a path is formatted as, or null for one that isn't.
20
+ export function prettyExtension(path) {
21
+ const extension = /\.([a-z]+)$/iu.exec(path)?.[1]?.toLowerCase()
22
+ return PRETTY_EXTENSIONS.has(extension) ? extension : null
23
+ }
24
+
25
+ // Whether a file's text is pretty-printed: in a language formatted, no larger
26
+ // than formatted, and minified, as risk reads it, `read` reading that where
27
+ // the reader keeps it.
28
+ export function needsPrettyPrint(path, text, read = () => npmFileReadability(path, text)) {
29
+ return prettyExtension(path) !== null && printableSize(text) && read().category === 'minified'
30
+ }
31
+
32
+ // The numbers of a copy's blank lines that are its layout alone
33
+ // (@preventive/compare layoutBlankLines), as the server keeps and sends them
34
+ // with its text (server-managed/pretty-print.ts, `{ text, blank }`): `blank`
35
+ // where it is lines' numbers in order, else null.
36
+ export const layoutBlankList = blank => (Array.isArray(blank) && blank.every((line, i) => Number.isSafeInteger(line) && line > (blank[i - 1] ?? -1)) ? blank : null)
@@ -0,0 +1,70 @@
1
+ // A source map listed for the pretty-print toggle (ui/view/pretty-source.js):
2
+ // its values alone, laid out a value to a row (sourcemap-listing.js), so that
3
+ // a diff of two maps' listings reads as the changes between them. A listing
4
+ // reads back (sourcemap-unlist.js) to the very text it lists, and Compare
5
+ // draws a diff of two only where what it draws, the old map's listing and the
6
+ // changes it shows, reads back to the new map (sourcemapDiffRebuilds). A map
7
+ // that can't be listed, or a diff of two that doesn't read back, is shown as
8
+ // published.
9
+ import { UNSEEN } from '../risk/files/characters.js'
10
+ import { SOURCE_MAP } from '../risk/files/readability.js'
11
+ import { blocksHold } from './line-diff.js'
12
+ import { sourcemapListing } from './sourcemap-listing.js'
13
+ import { unlistSourcemap } from './sourcemap-unlist.js'
14
+
15
+ export { unlistSourcemap }
16
+
17
+ // Whether a path is a source map's, which the viewer lists rather than
18
+ // formats, where its text is one (risk/files/source-map-link.js isSourceMap).
19
+ export const sourcemapPrinted = path => SOURCE_MAP.test(path)
20
+
21
+ // What JSON.parse reads past after a value: a line end, mostly.
22
+ const BLANKS = /^[\t\n\r ]*$/u
23
+
24
+ // A source map's text listed. Throws, saying why, for a text that isn't a
25
+ // JSON object written as JSON.stringify writes it, but for blanks after it
26
+ // (spaced, keys repeated, a number or an escape spelled otherwise: a listing
27
+ // wouldn't read back to it), an index map, or a listing too long. Asserted of
28
+ // every listing before it is shown, as no map should fail them: that it reads
29
+ // back to the very text it lists, and that no row of it holds a character
30
+ // that shows as another or none.
31
+ export function listSourcemap(text) {
32
+ let value
33
+ try {
34
+ value = JSON.parse(text)
35
+ } catch {
36
+ throw new Error("Its text isn't JSON.")
37
+ }
38
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) throw new Error("Its JSON isn't an object.")
39
+ const json = JSON.stringify(value), trailing = text.slice(json.length)
40
+ if (!text.startsWith(json) || !BLANKS.test(trailing)) throw new Error("Its text isn't written as JSON.stringify writes its JSON, so its listing wouldn't read back to it.")
41
+ if (Object.hasOwn(value, 'sections')) throw new Error("It is an index map, whose sections aren't listed.")
42
+ const listing = sourcemapListing(value, trailing)
43
+ if (unlistSourcemap(listing) !== text) throw new Error("Its listing doesn't read back to its text.")
44
+ if (UNSEEN.test(listing)) throw new Error('Its listing would show a character as another or none.')
45
+ return listing
46
+ }
47
+
48
+ const joined = lines => (lines.length === 0 ? '' : `${lines.join('\n')}\n`)
49
+
50
+ // Whether a diff drawn of two maps' listings shows every change between the
51
+ // maps: null where it does, else why not. `a` and `b` are the lines drawn of
52
+ // the old side and the new, `blocks` the changes drawn between them (each
53
+ // `a[a0..a1)` replaced by `b[b0..b1)`); `before` and `after` each side's map,
54
+ // `{ text, listing }`, its listing as listSourcemap made it (which reads back
55
+ // to the text), both '' where that side has none. The old side drawn must be
56
+ // the old map's listing; the changes drawn must take it to the new side drawn
57
+ // (line-diff.js blocksHold); that must be the new map's listing; and it must
58
+ // read back to the new map's very text.
59
+ export function sourcemapDiffRebuilds({ a, b, blocks }, before, after) {
60
+ const drawn = joined(b)
61
+ if (joined(a) !== before.listing) return "the old side drawn isn't the old map's listing."
62
+ if (!blocksHold(before.listing, drawn, blocks)) return "the changes drawn don't take the old map's listing to the new side drawn."
63
+ if (drawn !== after.listing) return "the new side drawn isn't the new map's listing."
64
+ if (after.text === '') return null
65
+ try {
66
+ return unlistSourcemap(drawn) === after.text ? null : 'the new side drawn reads back to another map than the new one.'
67
+ } catch (err) {
68
+ return err.message
69
+ }
70
+ }
@@ -0,0 +1,4 @@
1
+ export function asCommit(value: unknown): string
2
+ export function repoCommit(repo: unknown): string
3
+ export function sameRepoSlug(a: unknown, b: unknown): boolean
4
+ export function reportCommit(data: unknown, github: unknown): string
@@ -0,0 +1,30 @@
1
+ import { reportRepoGithub } from '@preventive/report'
2
+
3
+ // A git commit hash as a report writes one, short or full, either case:
4
+ // the rule @preventive/report's parsers read `auditedCommit` with.
5
+ // Empty for anything else, so a link falls back to HEAD.
6
+ export function asCommit(value) {
7
+ const commit = typeof value === 'string' ? value.trim() : ''
8
+ return /^[0-9a-f]{7,64}$/iu.test(commit) ? commit : ''
9
+ }
10
+
11
+ // The revision a `repo` declaration names beside its `github`, as a
12
+ // deepview report's header does: `"repo": { "github", "directory",
13
+ // "commit" }`. Older reports carry no `commit`, some no `repo` at all.
14
+ export function repoCommit(repo) {
15
+ return asCommit(repo?.commit)
16
+ }
17
+
18
+ // GitHub repository names ignore case, and the slug a report writes need
19
+ // not match the case GitHub reports for the same repository.
20
+ export function sameRepoSlug(a, b) {
21
+ return typeof a === 'string' && typeof b === 'string' && a !== '' && a.toLowerCase() === b.toLowerCase()
22
+ }
23
+
24
+ // The commit a report read its repository at, stamped on its findings
25
+ // as `_repoCommit`, but only while `github` (the repo its links resolve
26
+ // against) is the one the report names: it says nothing about a repo
27
+ // typed in later or assigned in its place.
28
+ export function reportCommit(data, github) {
29
+ return sameRepoSlug(github, reportRepoGithub(data)) ? repoCommit(data?.repo) : ''
30
+ }
@@ -0,0 +1,48 @@
1
+ import { REVALIDATE_KINDS, revalidateKindOf } from '@preventive/report'
2
+
3
+ // Keep only the pass's fields, before gap-filling changes the survivor.
4
+ // In particular, a verdict borrowed from report B must never be attributed
5
+ // to an unstamped copy from report A when report C later contradicts it.
6
+ function fieldsOf(finding) {
7
+ return Object.fromEntries(Object.entries(finding).filter(([key, value]) =>
8
+ key.startsWith('revalidate') && value != null))
9
+ }
10
+
11
+ export function recordRevalidationCopies(survivor, duplicate, reportName) {
12
+ const fields = fieldsOf(duplicate)
13
+ if (!survivor._revalidationCopies) {
14
+ const own = fieldsOf(survivor)
15
+ if (Object.keys(own).length === 0 && Object.keys(fields).length === 0) return []
16
+ survivor._revalidationCopies = Object.keys(own).length > 0
17
+ ? [{ reportName: survivor._reportName ?? '', fields: own }]
18
+ : []
19
+ }
20
+ if (Object.keys(fields).length > 0) survivor._revalidationCopies.push({ reportName, fields })
21
+ return survivor._revalidationCopies
22
+ }
23
+
24
+ // Same comparisons as mergeDuplicateFields: missing values are gaps, stamps
25
+ // are normalized, and prose ignores surrounding whitespace. Group agreeing
26
+ // reports together, retaining every distinct answer rather than just a pair.
27
+ export function revalidationDifferences(copies) {
28
+ const byField = new Map()
29
+ const knownKinds = new Set(REVALIDATE_KINDS)
30
+ for (const { reportName, fields } of copies) {
31
+ for (const [key, value] of Object.entries(fields)) {
32
+ if (value == null) continue
33
+ const normalized = key === 'revalidate'
34
+ ? revalidateKindOf(fields) || String(value).trim().toLowerCase()
35
+ : String(value).trim()
36
+ if (key === 'revalidate' && !normalized) continue
37
+ if (key === 'revalidate' && !knownKinds.has(normalized)) continue
38
+ if (!byField.has(key)) byField.set(key, new Map())
39
+ const variants = byField.get(key)
40
+ if (!variants.has(normalized)) variants.set(normalized, new Set())
41
+ variants.get(normalized).add(reportName)
42
+ }
43
+ }
44
+ return [...byField].filter(([, variants]) => variants.size > 1).map(([field, variants]) => ({
45
+ field,
46
+ variants: [...variants].map(([value, reports]) => ({ value, reports: [...reports] })),
47
+ }))
48
+ }
@@ -0,0 +1,56 @@
1
+ // Recover source-level row boundaries before hiding the App layer. App
2
+ // deduplication alone does not make the underlying code findings equivalent.
3
+ // Only split when every source ID is accounted for and every referenced input
4
+ // exists in this row. Missing input lists are empty, not missing evidence for
5
+ // an otherwise complete partition. Original findings and rows stay untouched.
6
+ export function splitRevalidationInputs(group, appFindings = null) {
7
+ const app = appFindings ?? group.filter((f) => f.isApp)
8
+ const source = group.filter((f) => !f.isApp)
9
+ if (app.length === 0 || source.length === 0) return [group]
10
+ // A surviving App finding means this is not a pure non-App projection;
11
+ // never move it into a source-only partition.
12
+ if (appFindings && group.some((f) => f.isApp)) return [group]
13
+ if (source.some((f) => typeof f.id !== 'string' || !f.id)) return [group]
14
+
15
+ const sourceIds = new Set(source.map((f) => f.id))
16
+ const inputsByApp = new Map()
17
+ const covered = new Set()
18
+ for (const f of app) {
19
+ const inputs = f.revalidateInputs === undefined ? [] : f.revalidateInputs
20
+ if (!Array.isArray(inputs)) return [group]
21
+ for (const id of inputs) {
22
+ if (!sourceIds.has(id)) return [group]
23
+ covered.add(id)
24
+ }
25
+ inputsByApp.set(f, inputs)
26
+ }
27
+ if (covered.size !== sourceIds.size) return [group]
28
+
29
+ const parent = new Map([...sourceIds].map((id) => [id, id]))
30
+ const find = (id) => {
31
+ let root = id
32
+ while (parent.get(root) !== root) root = parent.get(root)
33
+ while (parent.get(id) !== root) {
34
+ const next = parent.get(id)
35
+ parent.set(id, root)
36
+ id = next
37
+ }
38
+ return root
39
+ }
40
+ for (const inputs of inputsByApp.values()) {
41
+ if (inputs.length === 0) continue
42
+ const root = find(inputs[0])
43
+ for (const id of inputs) parent.set(find(id), root)
44
+ }
45
+
46
+ const components = new Map()
47
+ for (const f of group) {
48
+ const inputs = inputsByApp.get(f)
49
+ // Keep an App finding with its inputs until the caller projects the lens.
50
+ // App findings without inputs stand alone; hiding them then drops the row.
51
+ const key = inputs ? inputs.length > 0 ? find(inputs[0]) : f : find(f.id)
52
+ if (!components.has(key)) components.set(key, [])
53
+ components.get(key).push(f)
54
+ }
55
+ return components.size === 1 ? [group] : [...components.values()]
56
+ }
@@ -15,8 +15,11 @@
15
15
  // `session.error` until `dismissError()`.
16
16
  // `busy` — per-socket inflight cap dropped the save
17
17
  // (transport backpressure). Recoverable; the
18
- // client clears `pending` and re-arms
19
- // `pendingSave` for the next natural trigger.
18
+ // client clears `pending`, re-arms `pendingSave`,
19
+ // and schedules a short timed retry — without the
20
+ // timer an idle client (no further edit /
21
+ // broadcast / reconnect) would strand its last
22
+ // edit unsynced indefinitely.
20
23
  // `stale-base` — concurrent commit advanced the head past the
21
24
  // client's claimed base. The server emits the
22
25
  // typed frame AFTER a `workspace-state` catch-up
@@ -25,11 +28,21 @@
25
28
  // and this frame's handler then early-returns
26
29
  // on the missing pending. So `stale-base` is
27
30
  // NOT in the recoverable set: in the happy path
28
- // the recoverable branch is unreachable; in the
29
- // pathological case where wire order flipped,
30
- // we'd rather mark the session errored (visible
31
- // via UI + recoverable via `dismissError()`)
32
- // than silently swallow a state divergence.
31
+ // the recoverable branch is unreachable. When
32
+ // `pending` DOES survive to this frame — the
33
+ // catch-up was empty (chain gone: wiped /
34
+ // migrated DB) or didn't apply (chain rebuilt
35
+ // past the client's base) — the client answers
36
+ // with ONE full-state-push reset per recovery
37
+ // cycle (re-anchor at base=null; safe because
38
+ // the server's null-safe head CAS rejects a
39
+ // base=null root against any non-empty chain;
40
+ // see `staleResetAttempted` in triage-sync.ts).
41
+ // A repeat within the cycle marks the session
42
+ // errored (visible via UI + recoverable via
43
+ // `dismissError()`) rather than looping
44
+ // full-state saves against a relay that keeps
45
+ // rejecting them.
33
46
 
34
47
  export type SaveErrorReason = 'too-large' | 'busy' | 'stale-base'
35
48
 
@@ -0,0 +1,13 @@
1
+ export const DEFAULT_SCAN_SERVER = 'http://127.0.0.1:3123/'
2
+
3
+ // Discovery is optional: malformed scan configuration must never prevent
4
+ // opening local data or recognizing the server's sync protocol.
5
+ export function normalizeScanServer(value: unknown): string | null {
6
+ if (typeof value !== 'string' || !value.trim()) return null
7
+ try {
8
+ const url = new URL(value)
9
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) return null
10
+ url.pathname = url.pathname.replace(/\/+$/u, '') + '/'
11
+ return url.href
12
+ } catch { return null }
13
+ }
@@ -0,0 +1,5 @@
1
+ export function securityLinks(links?: Iterable<readonly string[]>): {
2
+ add(ids: readonly string[]): void
3
+ linkedIds(id: string): Iterable<string>
4
+ }
5
+ export function revalidationLinks(findings: Iterable<unknown>): string[][]