@preventive/triage 1.0.0-alpha.86 → 1.0.0-alpha.88

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 (61) hide show
  1. package/common/bundle-compare-diff.js +3 -2
  2. package/common/default-scan-models.ts +1 -0
  3. package/common/dependency-reviews.d.ts +1 -0
  4. package/common/dependency-reviews.js +3 -0
  5. package/common/github-issue-labels.d.ts +3 -1
  6. package/common/github-issue-labels.js +37 -6
  7. package/common/line-diff.d.ts +2 -1
  8. package/common/line-diff.js +12 -5
  9. package/common/managed/roles.ts +7 -0
  10. package/common/managed/routes.js +7 -6
  11. package/common/pretty-json.js +25 -0
  12. package/common/pretty-print.d.ts +1 -0
  13. package/common/pretty-print.js +5 -0
  14. package/out/activity.js +2 -2
  15. package/out/{chunk-ULI2BIWN.js → chunk-3TJCEPHF.js} +1 -1
  16. package/out/chunk-4GHLPL2P.js +1 -0
  17. package/out/chunk-5PWEAEA5.js +1 -0
  18. package/out/chunk-7KUZQB6S.js +267 -0
  19. package/out/{chunk-YU3IUQY6.js → chunk-A4HSJCXG.js} +1 -1
  20. package/out/{chunk-ZQQALNFP.js → chunk-BZJU5EEV.js} +1 -1
  21. package/out/{chunk-6CCSTJWB.js → chunk-ESXA7KID.js} +1 -1
  22. package/out/{chunk-CE2FMDK3.js → chunk-TKPNRQNN.js} +1 -1
  23. package/out/{chunk-GM6GP6TA.js → chunk-U6JONPTN.js} +2 -2
  24. package/out/chunk-VRFGZ6MV.js +1 -0
  25. package/out/{chunk-XHYX3Q34.js → chunk-XRAAYXPR.js} +1 -1
  26. package/out/chunk-ZPIUN4FW.js +55 -0
  27. package/out/client-managed-import.js +1 -1
  28. package/out/client-managed.js +28 -28
  29. package/out/compare.js +13 -13
  30. package/out/dialogs.js +38 -38
  31. package/out/graph.js +1 -1
  32. package/out/index.html +9 -9
  33. package/out/scan.js +2 -2
  34. package/out/view.css +1 -1
  35. package/out/view.js +15 -15
  36. package/package.json +2 -2
  37. package/risk/files/script.js +19 -9
  38. package/server-e2e/config.ts +3 -1
  39. package/server-managed/bundle-build-worker.js +13 -6
  40. package/server-managed/bundle-build.ts +7 -5
  41. package/server-managed/dependabot-access.ts +41 -17
  42. package/server-managed/dependabot-alerts.ts +19 -2
  43. package/server-managed/github-issues.ts +26 -14
  44. package/server-managed/github-users.ts +23 -0
  45. package/server-managed/http.ts +271 -123
  46. package/server-managed/npm-delta-worker.js +56 -8
  47. package/server-managed/npm-delta.ts +1 -1
  48. package/server-managed/npm-patch.ts +3 -1
  49. package/server-managed/pretty-format.d.ts +3 -2
  50. package/server-managed/pretty-format.js +17 -3
  51. package/server-managed/pretty-print.ts +18 -16
  52. package/server-managed/repository-browser.ts +3 -2
  53. package/server-managed/repository-risk-assess.ts +10 -0
  54. package/server-managed/stasis-dependencies.ts +14 -5
  55. package/server-managed/type-only-proof.js +22 -2
  56. package/out/chunk-2F7GGMMR.js +0 -266
  57. package/out/chunk-R7HUX4PF.js +0 -1
  58. package/out/chunk-V4U7URJF.js +0 -54
  59. package/out/chunk-WOCJFOXN.js +0 -1
  60. package/out/chunk-ZQHKSKD7.js +0 -1
  61. /package/out/{chunk-6WMQVUT2.js → chunk-WBK5ZN4K.js} +0 -0
@@ -149,12 +149,13 @@ const RENAME_LIMIT = 250
149
149
  // The files of `onlyBase` renamed to one of `onlyOther`, both by path as the
150
150
  // other bundle lays them out, within a package: `Map<base path, other path>`,
151
151
  // as @preventive/compare's compareTrees finds them, by content as git diff -M
152
- // does and where their paths say so. Whether a renamed file changed is
152
+ // does, where their paths say so, and a script or style sheet by its text as
153
+ // a build reformats it (renamesByForm). Whether a renamed file changed is
153
154
  // sameContent's to say, not this reading's. A path no UTF-8 holds is left out.
154
155
  function renamesOf(onlyBase, onlyOther, base, other, pkgOf) {
155
156
  const entries = (rows, files, side) => rows.filter(({ path }) => path !== '' && path.isWellFormed())
156
157
  .map(({ path }, at) => ({ name: path, data: treeData(files.get(path), `${side}${at}`) }))
157
- const options = { paths: 'keys', renameGroup: pkgOf, renameLimit: RENAME_LIMIT, lines: false }
158
+ const options = { paths: 'keys', renameGroup: pkgOf, renameLimit: RENAME_LIMIT, renamesByForm: true, lines: false }
158
159
  const changes = compareTrees(entries(onlyBase, base, 'a'), entries(onlyOther, other, 'b'), options)
159
160
  return new Map(changes.filter(({ status }) => status === 'renamed').map(change => [change.old.path, change.new.path]))
160
161
  }
@@ -21,6 +21,7 @@ export function defaultScanModels(provider: string | null = null) {
21
21
  'google/gemini-4-hydrogen',
22
22
  'google/gemma-4-31b-it',
23
23
  'x-ai/grok-4.7',
24
+ 'z-ai/glm-5.4',
24
25
  'z-ai/glm-5.3',
25
26
  'qwen/qwen4-max',
26
27
  'deepseek/deepseek-v4.1-flash',
@@ -1,3 +1,4 @@
1
+ export const MAX_PUBLISHED_REVIEWS: number
1
2
  export type ReviewVerdict = 'accept' | 'accept-with-nits' | 'request-changes' | 'reject'
2
3
  export interface ReviewSummary {
3
4
  coverage: 'full' | 'partial' | null
@@ -1,5 +1,8 @@
1
1
  import { npmMalwareAdvisory } from '../risk/npm/malware.js'
2
2
 
3
+ // Drafts published in one request at most (POST /api/npm/reviews/publish).
4
+ export const MAX_PUBLISHED_REVIEWS = 200
5
+
3
6
  export const REVIEW_VERDICTS = {
4
7
  accept: 'Accept',
5
8
  'accept-with-nits': 'Accept with nits (non-blocking)',
@@ -1 +1,3 @@
1
- export function newIssueLabels(isSecurity?: boolean, configured?: string): string[]
1
+ export function issueAdvisoryUrl(finding: unknown): string | null
2
+ export function issueLabelChoices(finding: unknown, configured?: string): string[][]
3
+ export function newIssueLabels(finding: unknown, configured?: string): string[]
@@ -1,11 +1,42 @@
1
- // Shared by GitHub's prefilled form and managed API issue creation.
2
- export function newIssueLabels(isSecurity = false, configured = '') {
1
+ import { isHttpUrl } from '@preventive/report'
2
+
3
+ // The link of the advisory a finding's issue is on, which the issue opens on
4
+ // in place of the finding's source (`Advisory: <url>`, ui/view/issue-draft.js);
5
+ // null for a finding on none.
6
+ export function issueAdvisoryUrl(finding) {
7
+ const url = finding?.advisory?.url
8
+ return isHttpUrl(url) ? url : null
9
+ }
10
+
11
+ // The labels a finding's new issue asks for, each a list of names of which
12
+ // it gets the first its repository has: `deepview`; `security` for a
13
+ // security finding; `dependencies`, else `deps`, for one on an advisory;
14
+ // then each of `configured` (GITHUB_NEW_ISSUE_LABELS, comma-separated).
15
+ // Names are trimmed, empty ones dropped, and a label asked for again, in any
16
+ // case, asked for once. Shared by GitHub's prefilled form and managed API
17
+ // issue creation (server-managed/github-issues.ts).
18
+ export function issueLabelChoices(finding, configured = '') {
3
19
  const seen = new Set()
4
- return ['deepview', ...(isSecurity ? ['security'] : []), ...configured.split(',')]
5
- .map(label => label.trim()).filter(label => {
6
- const key = label.toLowerCase()
7
- if (!label || seen.has(key)) return false
20
+ return [['deepview'], ...(finding?.isSecurity === true ? [['security']] : []),
21
+ ...(issueAdvisoryUrl(finding) ? [['dependencies', 'deps']] : []), ...configured.split(',').map(name => [name])]
22
+ .map(names => names.map(name => name.trim()).filter(Boolean))
23
+ .filter(names => {
24
+ const key = names.join('\0').toLowerCase()
25
+ if (names.length === 0 || seen.has(key)) return false
8
26
  seen.add(key)
9
27
  return true
10
28
  })
11
29
  }
30
+
31
+ // Every name those ask for, once, for GitHub's prefilled form, which sets
32
+ // only the labels the repository has: unable to tell which, it is handed
33
+ // both `dependencies` and `deps`.
34
+ export function newIssueLabels(finding, configured = '') {
35
+ const seen = new Set()
36
+ return issueLabelChoices(finding, configured).flat().filter(name => {
37
+ const key = name.toLowerCase()
38
+ if (seen.has(key)) return false
39
+ seen.add(key)
40
+ return true
41
+ })
42
+ }
@@ -9,6 +9,7 @@ export function indentHiddenBlocks(before: string, after: string): ChangeBlock[]
9
9
  export function markedCounts(blocks: readonly ChangeBlock[], marks: readonly ChangeBlock[] | null): { additions: number; deletions: number; renamed: number; marked: Set<number> }
10
10
  export function diffSize(before: string, after: string, ignoreWhitespace?: boolean | 'leading'): { marks: number; lines: number }
11
11
  export const isLargeDiff: (before: string, after: string) => boolean
12
- export function typeFolds(before: string, after: string, runs: { runs: [number, number][]; otherRuns: [number, number][] }): { before: string; after: string; lineOf: { a: number[]; b: number[] }; lines: { a: number; b: number } } | null
12
+ export function typeFolds(before: string, after: string, runs: { runs: [number, number][]; otherRuns: [number, number][] }): { before: string; after: string; whole: { a: string; b: string }; lineOf: { a: number[]; b: number[] }; lines: { a: number; b: number } } | false | null
13
+ export function copiesRuns(a: { text: string; runs?: [number, number][] }, b: { text: string; runs?: [number, number][] }): { runs: [number, number][]; otherRuns: [number, number][] } | null
13
14
  export function withSharedBlankLines(before: string, after: string, blankBefore: readonly number[], blankAfter: readonly number[]): { before: string; after: string }
14
15
  export function blocksHold(before: string, after: string, blocks: unknown, ignoreWhitespace?: boolean | 'leading'): boolean
@@ -90,9 +90,10 @@ export function withSharedBlankLines(before, after, blankBefore, blankAfter) {
90
90
  // A file that changed in types alone but for what runs (type-only.js
91
91
  // typeProof), its types set aside: `before` and `after` the texts of each
92
92
  // side's lines that run (`runs`, `otherRuns`, `[from, to)` each), diffed in
93
- // place of the files'; `lineOf` each of their lines' line in its file, and
94
- // `lines` the file's count, for diffRows to show where the types stand. Null
95
- // where that would hide no change or leave none to show.
93
+ // place of the files' (`whole`); `lineOf` each of their lines' line in its file, and
94
+ // `lines` the file's count, for diffRows to show where the types stand. False
95
+ // where what runs reads alike on both sides, its types alone changed; else
96
+ // null where that would hide no change.
96
97
  export function typeFolds(before, after, { runs, otherRuns }) {
97
98
  const side = (text, ranges) => {
98
99
  const lineOf = [], lines = textLines(text)
@@ -104,10 +105,16 @@ export function typeFolds(before, after, { runs, otherRuns }) {
104
105
  types: lines.filter((_, i) => !shown.has(i)).join('\n') }
105
106
  }
106
107
  const a = side(before, runs), b = side(after, otherRuns)
107
- if (a.types === b.types || a.run === b.run) return null
108
- return { before: a.text, after: b.text, lineOf: { a: a.lineOf, b: b.lineOf }, lines: { a: a.lines, b: b.lines } }
108
+ if (a.run === b.run) return false
109
+ if (a.types === b.types) return null
110
+ return { before: a.text, after: b.text, whole: { a: before, b: after }, lineOf: { a: a.lineOf, b: b.lineOf }, lines: { a: a.lines, b: b.lines } }
109
111
  }
110
112
 
113
+ const NO_RUNS = Object.freeze([])
114
+ // Two printed copies' lines that run, as typeFolds takes them, where each kept
115
+ // them or has no text; else null.
116
+ export const copiesRuns = (a, b) => ([a, b].every(copy => copy.text === '' || copy.runs) ? { runs: a.runs ?? NO_RUNS, otherRuns: b.runs ?? NO_RUNS } : null)
117
+
111
118
  // The lines `blocks` add and remove, but for those that are one of `marks`, counted apart (`renamed`, `marked`).
112
119
  export function markedCounts(blocks, marks) {
113
120
  const told = new Set((marks ?? []).map(({ a0, a1, b0, b1 }) => `${a0},${a1},${b0},${b1}`))
@@ -39,3 +39,10 @@ export function canReadRepositoryCode(session: { role: Role; publicShare?: boole
39
39
  export function canScanTeamRisk(session: { role: Role; publicShare?: boolean } | null | undefined): boolean {
40
40
  return session != null && !session.publicShare && roleAtLeast(session.role, 'manage')
41
41
  }
42
+
43
+ // Who scans one repository's risk, on its Risk tab: admins alone, as the
44
+ // server scans one repository for them alone (server-managed/http.ts
45
+ // mayReadRisk), signed in. A public link scans none.
46
+ export function canScanRepositoryRisk(session: { role: Role; publicShare?: boolean } | null | undefined): boolean {
47
+ return session != null && !session.publicShare && session.role === 'admin'
48
+ }
@@ -166,8 +166,8 @@ function parseNpmRoute(path, hash, search) {
166
166
  }
167
167
 
168
168
  // The code viewer: a directory of a repository at a commit, on its Code,
169
- // Search, Treemap, Compare, Commits, Issues, Pull requests, Agents, Pulse
170
- // or Replay tab, `/repo/<repo id>/<commit>[/<tab>…][?path=<directory>]`,
169
+ // Search, Treemap, Compare, Commits, Issues, Pull requests, Agents, Pulse,
170
+ // Replay or Risk tab, `/repo/<repo id>/<commit>[/<tab>…][?path=<directory>]`,
171
171
  // the repository's root where it names no directory. Code, the tab a bare
172
172
  // link opens, names its file by number and its lines in the fragment, as a
173
173
  // bundle's Code does: `/code/<file>#L4`. Compare names the commit compared
@@ -178,10 +178,11 @@ function parseNpmRoute(path, hash, search) {
178
178
  // branch's head, or on the revision a route held in memory names (`ref`),
179
179
  // and its route then names the commit it opened. Links from before it moved
180
180
  // name it under `/manage/code/`, and open the same.
181
- export const REPOSITORY_CODE_TABS = new Set(['code', 'search', 'treemap', 'compare', 'commits', 'issues', 'pulls', 'agents', 'pulse', 'replay'])
181
+ export const REPOSITORY_CODE_TABS = new Set(['code', 'search', 'treemap', 'compare', 'commits', 'issues', 'pulls', 'agents', 'pulse', 'replay', 'risk'])
182
182
  // The tabs reading none of the directory's files, which a directory at a
183
- // commit shows alone.
184
- export const REPOSITORY_FILELESS_TABS = new Set(['commits', 'issues', 'pulls', 'agents', 'pulse', 'replay'])
183
+ // commit shows alone: its Activity views, and its Risk, which scans the
184
+ // repository as its default branch has it.
185
+ export const REPOSITORY_FILELESS_TABS = new Set(['commits', 'issues', 'pulls', 'agents', 'pulse', 'replay', 'risk'])
185
186
  // The Activity views' sub-tabs past their first: Issues' and Pull requests'
186
187
  // closed ones (open, the first), Pulse's periods (a month, the first),
187
188
  // Replay's commits played (the last 300, the first), and one agent's
@@ -219,7 +220,7 @@ function repositoryCodePath(route) {
219
220
  }
220
221
 
221
222
  function parseRepositoryCodeRoute(url) {
222
- const match = /^\/(?:repo|manage\/code)\/([1-9]\d*)(?:\/([a-f\d]{40})(?:\/(code|search|treemap|compare|commits|history|issues|pulls|agents|pulse|replay)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u
223
+ const match = /^\/(?:repo|manage\/code)\/([1-9]\d*)(?:\/([a-f\d]{40})(?:\/(code|search|treemap|compare|commits|history|issues|pulls|agents|pulse|replay|risk)(?:\/([^/]+)(?:\/([a-z]+))?)?)?)?$/u
223
224
  .exec(url.pathname.replace(/\/$/u, ''))
224
225
  if (!match) return undefined
225
226
  const repoId = Number(match[1])
@@ -6,6 +6,31 @@ export const jsonPrinted = path => /\.json$/iu.test(path)
6
6
  // The widths prettyJSON folds to in the pretty-print toggle's layouts.
7
7
  export const JSON_LAYOUT_WIDTHS = { indented: 0, folded: 120 }
8
8
 
9
+ // A text's lines, a final newline ending the last rather than starting another.
10
+ const lineCount = text => (text === '' ? 0 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0))
11
+
12
+ // Whether folding saves enough to offer: of `indented` lines, folded to
13
+ // `folded`, more than ten, and more than a tenth.
14
+ export const foldSaves = (indented, folded) => indented - folded > Math.max(10, indented / 10)
15
+
16
+ // Whether a JSON file's own copies may offer folding: not a package.json's,
17
+ // kept short and read often, which is folded only once the toggle is.
18
+ export const offersFold = path => !/(?:^|\/)package\.json$/u.test(path)
19
+
20
+ // Whether a file's copies, `[indented, folded]`, fold enough of its lines to
21
+ // offer folding (foldSaves).
22
+ export const copiesFold = ([indented, folded]) => foldSaves(lineCount(indented), lineCount(folded))
23
+
24
+ // Whether a comparison's JSON file offers folding: where its copies fold
25
+ // enough of either side's lines (copiesFold), and of those its diff changes,
26
+ // `changed(before, after)` counting them, or null where too many to count.
27
+ // `sides` its two sides' copies, `[indented, folded]`, '' both for a side it lacks.
28
+ export function comparisonFolds(sides, changed) {
29
+ if (!sides.some(copies => copies[0] !== '' && copiesFold(copies))) return false
30
+ const [indented, folded] = [0, 1].map(layout => changed(sides[0][layout], sides[1][layout]))
31
+ return indented !== null && folded !== null && foldSaves(indented, folded)
32
+ }
33
+
9
34
  const isContainer = value => value !== null && typeof value === 'object'
10
35
 
11
36
  // `value` on one line, `{ "a": [1, 2] }`, or null where that is longer than
@@ -4,3 +4,4 @@ export const MAX_PRETTY_BYTES: number
4
4
  export function prettyExtension(path: string): string | null
5
5
  export function needsPrettyPrint(path: string, text: string, read?: () => { category: string }): boolean
6
6
  export function layoutBlankList(blank: unknown): number[] | null
7
+ export function runRangeList(runs: unknown): [number, number][] | null
@@ -34,3 +34,8 @@ export function needsPrettyPrint(path, text, read = () => npmFileReadability(pat
34
34
  // with its text (server-managed/pretty-print.ts, `{ text, blank }`): `blank`
35
35
  // where it is lines' numbers in order, else null.
36
36
  export const layoutBlankList = blank => (Array.isArray(blank) && blank.every((line, i) => Number.isSafeInteger(line) && line > (blank[i - 1] ?? -1)) ? blank : null)
37
+
38
+ // Lines `[from, to)` as the server tells them, in order, apart: a declaration
39
+ // file's copy's lines that run, or a proof's; else null.
40
+ export const runRangeList = runs => (Array.isArray(runs) && runs.every((range, i) => Array.isArray(range) && range.length === 2
41
+ && range.every(Number.isSafeInteger) && range[0] >= (runs[i - 1]?.[1] ?? 0) && range[1] > range[0]) ? runs : null)