@preventive/triage 1.0.0-alpha.87 → 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.
@@ -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',
@@ -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}`))
@@ -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)