@tobi-or-not/quorum 0.5.0 → 0.6.0
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.
- package/README.md +2 -0
- package/dist/bench/fingerprint.d.ts +6 -5
- package/dist/bench/fingerprint.js +11 -5
- package/dist/bench/records.d.ts +100 -2
- package/dist/bench/records.js +80 -5
- package/dist/bench/runner.js +1 -1
- package/dist/cli/io.d.ts +5 -0
- package/dist/cli/main.d.ts +36 -13
- package/dist/cli/main.js +194 -44
- package/dist/cli/print-config.d.ts +5 -5
- package/dist/cli/print-config.js +10 -5
- package/dist/cli/render.d.ts +7 -1
- package/dist/cli/render.js +25 -3
- package/dist/config/claude-code.d.ts +2 -6
- package/dist/config/claude-code.js +6 -44
- package/dist/config/command.d.ts +10 -0
- package/dist/config/command.js +47 -0
- package/dist/config/from-config.js +8 -2
- package/dist/config/resolve.d.ts +4 -0
- package/dist/config/resolve.js +10 -0
- package/dist/config/schema.d.ts +13 -2
- package/dist/config/schema.js +36 -5
- package/dist/core/coverage.d.ts +38 -13
- package/dist/core/coverage.js +105 -28
- package/dist/core/diff.d.ts +77 -0
- package/dist/core/diff.js +122 -24
- package/dist/core/estimate.d.ts +45 -0
- package/dist/core/estimate.js +188 -0
- package/dist/core/flags.d.ts +14 -1
- package/dist/core/flags.js +56 -0
- package/dist/core/inputs.d.ts +38 -0
- package/dist/core/inputs.js +228 -0
- package/dist/core/limits.d.ts +5 -4
- package/dist/core/limits.js +11 -5
- package/dist/core/parts.d.ts +146 -0
- package/dist/core/parts.js +388 -0
- package/dist/core/ports.d.ts +10 -0
- package/dist/core/prompts.d.ts +22 -3
- package/dist/core/prompts.js +43 -7
- package/dist/core/quorum.d.ts +7 -5
- package/dist/core/quorum.js +164 -58
- package/dist/core/secrets.d.ts +98 -0
- package/dist/core/secrets.js +507 -0
- package/dist/core/stages/context.d.ts +16 -3
- package/dist/core/stages/context.js +44 -17
- package/dist/core/stages/panel.d.ts +8 -2
- package/dist/core/stages/panel.js +50 -9
- package/dist/core/stages/research.d.ts +107 -31
- package/dist/core/stages/research.js +290 -53
- package/dist/core/types.d.ts +217 -29
- package/dist/core/verify.d.ts +6 -0
- package/dist/core/verify.js +6 -3
- package/dist/git/run.d.ts +223 -0
- package/dist/git/run.js +608 -0
- package/dist/git/tree.d.ts +43 -0
- package/dist/git/tree.js +171 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +34 -2
- package/dist/providers/anthropic.d.ts +2 -1
- package/dist/providers/anthropic.js +4 -2
- package/dist/providers/claude-code.d.ts +5 -0
- package/dist/providers/claude-code.js +11 -1
- package/dist/providers/gemini.d.ts +2 -1
- package/dist/providers/gemini.js +4 -2
- package/dist/providers/ollama.d.ts +2 -1
- package/dist/providers/ollama.js +4 -2
- package/dist/providers/openai-compatible.d.ts +2 -1
- package/dist/providers/openai-compatible.js +4 -2
- package/dist/providers/size.d.ts +9 -1
- package/dist/providers/size.js +18 -4
- package/dist/sources/added.d.ts +49 -0
- package/dist/sources/added.js +134 -0
- package/dist/sources/diff.d.ts +13 -0
- package/dist/sources/diff.js +63 -0
- package/dist/sources/local.d.ts +41 -0
- package/dist/sources/local.js +251 -0
- package/dist/sources/paths.d.ts +45 -0
- package/dist/sources/paths.js +230 -0
- package/dist/sources/range.d.ts +21 -0
- package/dist/sources/range.js +75 -0
- package/dist/sources/read.d.ts +69 -0
- package/dist/sources/read.js +37 -0
- package/dist/sources/repository.d.ts +9 -0
- package/dist/sources/repository.js +28 -0
- package/dist/sources/skips.d.ts +49 -0
- package/dist/sources/skips.js +126 -0
- package/package.json +1 -1
- package/schema/quorum.schema.json +15 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { isRecord } from "./output.js";
|
|
2
|
+
import { SECRET_RULES } from "./secrets.js";
|
|
3
|
+
/** The kinds of source whose ids name a git repository's objects, each with the fields that hold a full commit id. */
|
|
4
|
+
const ID_FIELDS = {
|
|
5
|
+
range: ['base', 'mergeBase', 'head'],
|
|
6
|
+
local: ['head'],
|
|
7
|
+
staged: ['head'],
|
|
8
|
+
paths: ['commit'],
|
|
9
|
+
};
|
|
10
|
+
const OBJECT_FORMATS = ['sha1', 'sha256'];
|
|
11
|
+
/** A full object id of each format: 40 lowercase hexadecimal characters for sha1, 64 for sha256. */
|
|
12
|
+
const OBJECT_IDS = {
|
|
13
|
+
sha1: /^[0-9a-f]{40}$/,
|
|
14
|
+
sha256: /^[0-9a-f]{64}$/,
|
|
15
|
+
};
|
|
16
|
+
const ID_MESSAGE = 'must be a full commit id of its object format: 40 lowercase hexadecimal characters for sha1, 64 for sha256';
|
|
17
|
+
const LEFT_OUT_REASONS = new Set([
|
|
18
|
+
'excluded',
|
|
19
|
+
'binary',
|
|
20
|
+
'submodule',
|
|
21
|
+
'skipped',
|
|
22
|
+
'secret',
|
|
23
|
+
'deleted-secret',
|
|
24
|
+
]);
|
|
25
|
+
/** The reasons of a file held back as a secret, which carry the rule that held it. */
|
|
26
|
+
const HELD_REASONS = new Set(['secret', 'deleted-secret']);
|
|
27
|
+
const SECRET_RULE_SET = new Set(SECRET_RULES);
|
|
28
|
+
/** The rules a path review skips a file by: the bench's schema takes the same list. */
|
|
29
|
+
export const SKIP_RULES = [
|
|
30
|
+
'vendored',
|
|
31
|
+
'lockfile',
|
|
32
|
+
'minified',
|
|
33
|
+
'secret',
|
|
34
|
+
'binary',
|
|
35
|
+
'submodule',
|
|
36
|
+
'lfs',
|
|
37
|
+
];
|
|
38
|
+
const SKIP_RULE_SET = new Set(SKIP_RULES);
|
|
39
|
+
function isGitKind(kind) {
|
|
40
|
+
return typeof kind === 'string' && Object.hasOwn(ID_FIELDS, kind);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Every problem with a value given as a review's `source`, so an untyped caller gets issues, never a
|
|
44
|
+
* TypeError: none when it is unset, `source: must be an object`, `source.kind` when the kind is not one
|
|
45
|
+
* of the five, else `source.objectFormat`, and, once the format is known, each id field that is not a full
|
|
46
|
+
* commit id of it (a local or staged source's `head` may be null), a `paths` that is not an array of
|
|
47
|
+
* strings and a `skips` that is not a boolean. A field it does not know is no problem: `sourceOf` leaves it
|
|
48
|
+
* out of the record. No message repeats a value.
|
|
49
|
+
*/
|
|
50
|
+
export function sourceIssues(value) {
|
|
51
|
+
if (value === undefined)
|
|
52
|
+
return [];
|
|
53
|
+
if (!isRecord(value)) {
|
|
54
|
+
return [
|
|
55
|
+
{ path: 'source', message: 'must be an object' },
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
const { kind } = value;
|
|
59
|
+
if (kind === 'diff')
|
|
60
|
+
return [];
|
|
61
|
+
if (!isGitKind(kind)) {
|
|
62
|
+
return [
|
|
63
|
+
{ path: 'source.kind', message: 'must be diff, range, local, staged or paths' },
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
const issues = [];
|
|
67
|
+
const format = OBJECT_FORMATS.find(candidate => candidate === value.objectFormat);
|
|
68
|
+
if (format === undefined) {
|
|
69
|
+
issues.push({ path: 'source.objectFormat', message: 'must be sha1 or sha256' });
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const nullable = kind === 'local' || kind === 'staged';
|
|
73
|
+
for (const field of ID_FIELDS[kind]) {
|
|
74
|
+
const id = value[field];
|
|
75
|
+
if (nullable && id === null)
|
|
76
|
+
continue;
|
|
77
|
+
if (typeof id === 'string' && OBJECT_IDS[format].test(id))
|
|
78
|
+
continue;
|
|
79
|
+
issues.push({
|
|
80
|
+
path: `source.${field}`,
|
|
81
|
+
message: nullable
|
|
82
|
+
? `${ID_MESSAGE}, or null when nothing is committed`
|
|
83
|
+
: ID_MESSAGE,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (kind === 'paths') {
|
|
88
|
+
// `Array.from` reads a hole as `undefined`, so a sparse array is no array of strings.
|
|
89
|
+
if (!Array.isArray(value.paths) || !Array.from(value.paths).every(path => typeof path === 'string')) {
|
|
90
|
+
issues.push({ path: 'source.paths', message: 'must be an array of strings' });
|
|
91
|
+
}
|
|
92
|
+
if (typeof value.skips !== 'boolean')
|
|
93
|
+
issues.push({ path: 'source.skips', message: 'must be a boolean' });
|
|
94
|
+
}
|
|
95
|
+
return issues;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Every problem with a value given as a review's `leftOut`: none when it is unset, `leftOut: must be an
|
|
99
|
+
* array`, else for each entry `leftOut.<index>` when it is no object, its `file` that is not a string, its
|
|
100
|
+
* `reason` that is none of `excluded`, `binary`, `submodule`, `skipped`, `secret` and `deleted-secret`, and
|
|
101
|
+
* its `rule`: one of the seven a skipped file has, one of the nine a held file has (`secret` and
|
|
102
|
+
* `deleted-secret`), which no other reason has. A reason or a rule is a value of this release: a reader of
|
|
103
|
+
* a result takes one it does not know as a file left out, but a caller of `review` names ones it can.
|
|
104
|
+
*/
|
|
105
|
+
export function leftOutIssues(value) {
|
|
106
|
+
if (value === undefined)
|
|
107
|
+
return [];
|
|
108
|
+
if (!Array.isArray(value)) {
|
|
109
|
+
return [
|
|
110
|
+
{ path: 'leftOut', message: 'must be an array' },
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
const issues = [];
|
|
114
|
+
// `Array.from` reads a hole as `undefined`, so it is reported like any other entry that is no object.
|
|
115
|
+
for (const [index, entry] of Array.from(value).entries()) {
|
|
116
|
+
const path = `leftOut.${index}`;
|
|
117
|
+
if (!isRecord(entry)) {
|
|
118
|
+
issues.push({ path, message: 'must be an object with a file and a reason' });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (typeof entry.file !== 'string')
|
|
122
|
+
issues.push({ path: `${path}.file`, message: 'must be a string' });
|
|
123
|
+
if (!LEFT_OUT_REASONS.has(entry.reason)) {
|
|
124
|
+
issues.push({ path: `${path}.reason`, message: 'must be excluded, binary, submodule, skipped, secret or deleted-secret' });
|
|
125
|
+
}
|
|
126
|
+
else if (entry.reason === 'skipped') {
|
|
127
|
+
if (!SKIP_RULE_SET.has(entry.rule))
|
|
128
|
+
issues.push({ path: `${path}.rule`, message: 'must be vendored, lockfile, minified, secret, binary, submodule or lfs' });
|
|
129
|
+
}
|
|
130
|
+
else if (HELD_REASONS.has(entry.reason)) {
|
|
131
|
+
if (!SECRET_RULE_SET.has(entry.rule))
|
|
132
|
+
issues.push({ path: `${path}.rule`, message: `must be ${SECRET_RULES.slice(0, -1).join(', ')} or ${SECRET_RULES.at(-1)}` });
|
|
133
|
+
}
|
|
134
|
+
else if (entry.rule !== undefined) {
|
|
135
|
+
issues.push({ path: `${path}.rule`, message: 'belongs to a skipped, secret or deleted-secret file only' });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return issues;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Every problem with a value given as a review's `send`: none when it is unset, `send: must be an array`,
|
|
142
|
+
* else `send.<index>: must name a file` for each entry that is not a non-empty string, a hole included. The
|
|
143
|
+
* empty name is the text no header names, which no file of the diff is, so it is no file to send.
|
|
144
|
+
*/
|
|
145
|
+
export function sendIssues(value) {
|
|
146
|
+
if (value === undefined)
|
|
147
|
+
return [];
|
|
148
|
+
if (!Array.isArray(value)) {
|
|
149
|
+
return [
|
|
150
|
+
{ path: 'send', message: 'must be an array' },
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
// `Array.from` reads a hole as `undefined`, so it is reported like any other entry that is no name.
|
|
154
|
+
return Array.from(value).flatMap((entry, index) => typeof entry === 'string' && entry !== ''
|
|
155
|
+
? []
|
|
156
|
+
: [
|
|
157
|
+
{ path: `send.${index}`, message: 'must name a file' },
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A checked source as the review records it: a copy of its known fields, so the caller's later changes to
|
|
162
|
+
* the object, or to its `paths`, never reach the result, and `{ kind: 'diff' }` for an unset source.
|
|
163
|
+
*/
|
|
164
|
+
export function sourceOf(value) {
|
|
165
|
+
if (value === undefined)
|
|
166
|
+
return { kind: 'diff' };
|
|
167
|
+
switch (value.kind) {
|
|
168
|
+
case 'diff':
|
|
169
|
+
return { kind: 'diff' };
|
|
170
|
+
case 'range':
|
|
171
|
+
return {
|
|
172
|
+
kind: 'range',
|
|
173
|
+
base: value.base,
|
|
174
|
+
mergeBase: value.mergeBase,
|
|
175
|
+
head: value.head,
|
|
176
|
+
objectFormat: value.objectFormat,
|
|
177
|
+
};
|
|
178
|
+
case 'local':
|
|
179
|
+
case 'staged':
|
|
180
|
+
return { kind: value.kind, head: value.head, objectFormat: value.objectFormat };
|
|
181
|
+
case 'paths':
|
|
182
|
+
return {
|
|
183
|
+
kind: 'paths',
|
|
184
|
+
commit: value.commit,
|
|
185
|
+
paths: [...value.paths],
|
|
186
|
+
skips: value.skips,
|
|
187
|
+
objectFormat: value.objectFormat,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** A copy of a file left out with its known fields: `rule` only for a skipped or a held file. */
|
|
192
|
+
function copyOf(entry) {
|
|
193
|
+
switch (entry.reason) {
|
|
194
|
+
case 'skipped':
|
|
195
|
+
return { file: entry.file, reason: entry.reason, rule: entry.rule };
|
|
196
|
+
case 'secret':
|
|
197
|
+
case 'deleted-secret':
|
|
198
|
+
return { file: entry.file, reason: entry.reason, rule: entry.rule };
|
|
199
|
+
default:
|
|
200
|
+
return { file: entry.file, reason: entry.reason };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The files a review leaves out as one list: the source's first, then the diff's, each file, reason and rule
|
|
205
|
+
* once, the first kept. Every entry is a copy of its known fields, `rule` only for a skipped or a held file.
|
|
206
|
+
*/
|
|
207
|
+
export function mergeLeftOut(source, diff) {
|
|
208
|
+
const listed = new Set();
|
|
209
|
+
const merged = [];
|
|
210
|
+
for (const entry of [
|
|
211
|
+
...source,
|
|
212
|
+
...diff,
|
|
213
|
+
]) {
|
|
214
|
+
const copy = copyOf(entry);
|
|
215
|
+
const key = JSON.stringify([
|
|
216
|
+
copy.reason,
|
|
217
|
+
copy.file,
|
|
218
|
+
'rule' in copy
|
|
219
|
+
? copy.rule
|
|
220
|
+
: null,
|
|
221
|
+
]);
|
|
222
|
+
if (listed.has(key))
|
|
223
|
+
continue;
|
|
224
|
+
listed.add(key);
|
|
225
|
+
merged.push(copy);
|
|
226
|
+
}
|
|
227
|
+
return merged;
|
|
228
|
+
}
|
package/dist/core/limits.d.ts
CHANGED
|
@@ -72,11 +72,12 @@ export interface Ledger {
|
|
|
72
72
|
export declare function createLedger(cap: number): Ledger;
|
|
73
73
|
/**
|
|
74
74
|
* The gaps the limits leave in a profile, one entry per limit that stopped work, the token cap's first, or none:
|
|
75
|
-
* `research`
|
|
76
|
-
* limit counts for it. Each detail names the limit with
|
|
77
|
-
*
|
|
75
|
+
* `research` holds the outcome of each of the profile's research parts, in order, a limit's name for a part it
|
|
76
|
+
* stopped, and every vote of `verdicts` whose failure is a limit counts for it. Each detail names the limit with
|
|
77
|
+
* its setting, then what it stopped: `its research` when the research was one part, else `<n> of its <count>
|
|
78
|
+
* research parts`, then `<n> vote(s)`, joined with ` and `.
|
|
78
79
|
*/
|
|
79
|
-
export declare function limitGaps(profile: string, research:
|
|
80
|
+
export declare function limitGaps(profile: string, research: readonly string[], verdicts: readonly Verdict[], limits: {
|
|
80
81
|
readonly cap: number;
|
|
81
82
|
readonly deadlineMs: number;
|
|
82
83
|
}): IncompleteEntry[];
|
package/dist/core/limits.js
CHANGED
|
@@ -134,9 +134,10 @@ export function createLedger(cap) {
|
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* The gaps the limits leave in a profile, one entry per limit that stopped work, the token cap's first, or none:
|
|
137
|
-
* `research`
|
|
138
|
-
* limit counts for it. Each detail names the limit with
|
|
139
|
-
*
|
|
137
|
+
* `research` holds the outcome of each of the profile's research parts, in order, a limit's name for a part it
|
|
138
|
+
* stopped, and every vote of `verdicts` whose failure is a limit counts for it. Each detail names the limit with
|
|
139
|
+
* its setting, then what it stopped: `its research` when the research was one part, else `<n> of its <count>
|
|
140
|
+
* research parts`, then `<n> vote(s)`, joined with ` and `.
|
|
140
141
|
*/
|
|
141
142
|
export function limitGaps(profile, research, verdicts, limits) {
|
|
142
143
|
const failures = verdicts.flatMap(verdict => verdict.votes).map(lensVote => lensVote.failure?.kind);
|
|
@@ -146,9 +147,14 @@ export function limitGaps(profile, research, verdicts, limits) {
|
|
|
146
147
|
};
|
|
147
148
|
return LIMITS.flatMap((limit) => {
|
|
148
149
|
const votes = failures.filter(kind => kind === limit).length;
|
|
150
|
+
const parts = research.filter(outcome => outcome === limit).length;
|
|
149
151
|
const stopped = [
|
|
150
|
-
...
|
|
151
|
-
? [
|
|
152
|
+
...parts > 0
|
|
153
|
+
? [
|
|
154
|
+
research.length === 1
|
|
155
|
+
? 'its research'
|
|
156
|
+
: `${parts} of its ${research.length} research parts`,
|
|
157
|
+
]
|
|
152
158
|
: [],
|
|
153
159
|
...votes > 0
|
|
154
160
|
? [`${votes} vote(s)`]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A large change in parts. A part is the share of a diff one research request holds: the diff's
|
|
3
|
+
* sections packed in order within a budget of tokens, a section too large for a part split between
|
|
4
|
+
* its hunks, each piece with the section's header, and a hunk never cut. These are plain functions
|
|
5
|
+
* over the diff's sections: they read no provider and no profile, call nothing and keep no state, so
|
|
6
|
+
* the research stage decides what a part is sent as and what became of it. The module also picks the
|
|
7
|
+
* hunks nearest a cited line for a vote whose voter's window does not hold the section.
|
|
8
|
+
*
|
|
9
|
+
* @see ../../docs/95-reference/40-architecture.md for the module overview.
|
|
10
|
+
*/
|
|
11
|
+
import type { ReviewScope } from './coverage.ts';
|
|
12
|
+
import type { DiffSection, Hunk } from './diff.ts';
|
|
13
|
+
import type { CoverageEntry, IncompleteEntry, LeftOutFile } from './types.ts';
|
|
14
|
+
/** The most tokens of diff text one research request of a large change holds, when `partTokens` is not set. */
|
|
15
|
+
export declare const DEFAULT_PART_TOKENS = 32768;
|
|
16
|
+
/** The least `partTokens` a configuration may state. */
|
|
17
|
+
export declare const MIN_PART_TOKENS = 1024;
|
|
18
|
+
/** The most file names a part's request lists. */
|
|
19
|
+
export declare const LISTED_FILES = 100;
|
|
20
|
+
/** The problem with a `partTokens`, in words that say what to write, or undefined for a safe integer of at least 1024. */
|
|
21
|
+
export declare function partTokensProblem(value: unknown): string | undefined;
|
|
22
|
+
/** A section of the diff, or its header and the hunks `from` to `to` of it, `to` excluded. */
|
|
23
|
+
export interface Slice {
|
|
24
|
+
/** The index of the section among the diff's sections. */
|
|
25
|
+
readonly section: number;
|
|
26
|
+
/** The index of the first hunk of the slice; absent for the whole section. */
|
|
27
|
+
readonly from?: number;
|
|
28
|
+
/** The index after the last hunk of the slice; absent for the whole section. */
|
|
29
|
+
readonly to?: number;
|
|
30
|
+
}
|
|
31
|
+
/** The slices one research request holds, in the diff's order. */
|
|
32
|
+
export interface Part {
|
|
33
|
+
readonly slices: readonly Slice[];
|
|
34
|
+
/** The `tokenBound` of the part's text, the slices joined by line feeds. */
|
|
35
|
+
readonly tokens: number;
|
|
36
|
+
}
|
|
37
|
+
/** A unit of the diff no part holds: one hunk of a section, or a section that has no hunk. */
|
|
38
|
+
export interface Unplaced {
|
|
39
|
+
readonly section: number;
|
|
40
|
+
/** The index of the hunk; absent for a section with no hunk. */
|
|
41
|
+
readonly hunk?: number;
|
|
42
|
+
}
|
|
43
|
+
/** The hunks of a section split between parts, as `parseHunks` reads them, and where each one's `@@` line starts in the section's text. */
|
|
44
|
+
export interface Cut {
|
|
45
|
+
readonly hunks: readonly Hunk[];
|
|
46
|
+
/** The offset of each hunk's `@@` line in the section's text. */
|
|
47
|
+
readonly starts: readonly number[];
|
|
48
|
+
}
|
|
49
|
+
/** How a diff's sections are packed into parts. */
|
|
50
|
+
export interface Packing {
|
|
51
|
+
readonly parts: readonly Part[];
|
|
52
|
+
/** The units that fit in no part, in the diff's order. */
|
|
53
|
+
readonly tooLarge: readonly Unplaced[];
|
|
54
|
+
/** The sections split between parts, by section index. */
|
|
55
|
+
readonly cuts: ReadonlyMap<number, Cut>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Pack the sections of a diff into parts, in the diff's order, by arithmetic over `tokenBound`. A
|
|
59
|
+
* part holds at most `cap`, the lesser of `partTokens` and `room`, the tokens a request leaves for
|
|
60
|
+
* the diff; the line feed that joins two slices counts. A section whose text fits goes whole into
|
|
61
|
+
* the open part when it fits beside what is there, else into a new one. A larger section is split
|
|
62
|
+
* between its hunks, each one counted with the section's header: a hunk extends the open slice of
|
|
63
|
+
* its section while the part stays within `cap`, else opens a slice, in the open part when it fits,
|
|
64
|
+
* else in a new part, and never joins the slice before a hunk that was set aside. A unit over `cap`,
|
|
65
|
+
* a hunk or a section with no hunk, goes alone into a part of its own when it is within `room`,
|
|
66
|
+
* else it is set aside. A hunk is never cut: a section is cut only at the lines `parseHunks` opens
|
|
67
|
+
* a hunk at, so the text outside any hunk travels with the hunk before it, or with the header when
|
|
68
|
+
* none precedes it, and every line of every section is in exactly one part, besides the header a
|
|
69
|
+
* piece repeats, or in a unit set aside. The work is linear in the size of the diff.
|
|
70
|
+
*/
|
|
71
|
+
export declare function packParts(sections: readonly DiffSection[], budget: {
|
|
72
|
+
readonly partTokens: number;
|
|
73
|
+
readonly room: number;
|
|
74
|
+
}): Packing;
|
|
75
|
+
/**
|
|
76
|
+
* The text of a slice: the section's text for a whole slice, else the section's header (the lines
|
|
77
|
+
* before its first hunk, absent when that hunk opens the section), a line feed, and the text of its
|
|
78
|
+
* hunks, which ends at the section's end when the slice holds the last hunk. A slice's hunks are read
|
|
79
|
+
* from `Packing.cuts`, the section's own reading, never by parsing a slice alone: `parseHunks` reads
|
|
80
|
+
* a final line feed as the end of the text, so a slice that ends on an empty row, which is a blank
|
|
81
|
+
* context row, parses one row short.
|
|
82
|
+
*/
|
|
83
|
+
export declare function sliceText(sections: readonly DiffSection[], packing: Packing, slice: Slice): string;
|
|
84
|
+
/**
|
|
85
|
+
* The part of a section a voter whose room cannot hold the whole of it is shown: the section's header
|
|
86
|
+
* (the text before its first hunk, which is none for a section that starts with its first `@@` line), a
|
|
87
|
+
* line feed, and the hunks nearest the cited `line` that fit `room` tokens, as `tokenBound` counts them.
|
|
88
|
+
* `hunks` are the section's own, as `hunksOf` reads them from the whole `text`, never from a piece of it.
|
|
89
|
+
* The cited hunk is the first that holds `line`, as `locate` takes it. Then, of the hunks beside those
|
|
90
|
+
* taken, the one nearer `line` in new-file lines comes next, the earlier on a tie, so the hunks taken
|
|
91
|
+
* are always the section's own run of neighbours, in its order, and the context reads as a diff. A
|
|
92
|
+
* hunk that does not fit closes its side, the one before the run or the one after it, and the other
|
|
93
|
+
* side goes on; it stops when both sides are closed or the section's ends are reached. The hunk's
|
|
94
|
+
* count is its lines to the next `@@` line, so text outside any hunk travels with the hunk before it,
|
|
95
|
+
* and the header is always the text before the first hunk of `text`, whatever it holds.
|
|
96
|
+
*
|
|
97
|
+
* It is undefined when no hunk holds `line`, or when the header and the cited hunk alone do not fit
|
|
98
|
+
* `room`: the caller then sends the whole section, which its provider refuses as too large.
|
|
99
|
+
*/
|
|
100
|
+
export declare function nearestHunks(text: string, hunks: readonly Hunk[], line: number, room: number): string | undefined;
|
|
101
|
+
/** The text of a part: its slices joined by line feeds. */
|
|
102
|
+
export declare function partText(sections: readonly DiffSection[], packing: Packing, part: Part): string;
|
|
103
|
+
/**
|
|
104
|
+
* The files a part's request names: the distinct named files of the diff, in its order, the empty
|
|
105
|
+
* name (the text no header names) left out. The list is the longest prefix of at most `LISTED_FILES`
|
|
106
|
+
* names that fits `maxTokens`, each name counted as the request shows it, through `showHidden`,
|
|
107
|
+
* with its line feed, and it stops at the first name that does not fit, so a name's length, which
|
|
108
|
+
* the author chooses, cannot take more of the window than that. `unlisted` counts the names left
|
|
109
|
+
* out. The names come back as the diff writes them: the caller shows each through `showHidden`.
|
|
110
|
+
*/
|
|
111
|
+
export declare function listedFiles(sections: readonly DiffSection[], maxTokens: number): {
|
|
112
|
+
readonly files: string[];
|
|
113
|
+
readonly unlisted: number;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* The one gap of a profile whose packing set a unit aside, counting the hunks and the files they belong to,
|
|
117
|
+
* a section with no hunk counting as one hunk and a file of several sections as one file; undefined when
|
|
118
|
+
* the packing set nothing aside, or there is none. A file that `leftOut` lists as `binary` or `submodule`
|
|
119
|
+
* counts for nothing: its coverage entry is `unreviewed` with that reason, whatever became of its part, and
|
|
120
|
+
* its own gap stands, so the detail's pointer to a `too-large` range would lead nowhere. The detail names
|
|
121
|
+
* the profile's coverage, which lists the ranges, and no file.
|
|
122
|
+
*/
|
|
123
|
+
export declare function tooLargeGap(profile: string, sections: readonly DiffSection[], packing: Packing | undefined, leftOut: readonly LeftOutFile[]): IncompleteEntry | undefined;
|
|
124
|
+
/** What became of the research part that held a unit: it was read, or the reason it was not. */
|
|
125
|
+
export type PartOutcome = 'reviewed' | 'request-too-large' | 'token-cap' | 'review-deadline' | 'research-failed';
|
|
126
|
+
/**
|
|
127
|
+
* How much of each file of the diff a profile's research reviewed, in the diff's order, once per
|
|
128
|
+
* file. `packing` is how `sections`, the ones the research read, were packed into the parts `outcomes`
|
|
129
|
+
* tells the fate of, one outcome per part; undefined is one part that holds every section whole, whose outcome is
|
|
130
|
+
* `outcomes[0]`, `'research-failed'` when there is none. In this order:
|
|
131
|
+
* 1. Each section's outcome: one when it is whole in a part, set aside whole, or in a one-part plan;
|
|
132
|
+
* else one per hunk, `too-large` for the units the packing set aside.
|
|
133
|
+
* 2. Each file's pieces, in the diff's order: a section held whole is one piece, whose ranges are
|
|
134
|
+
* all its hunks' (parsed only when a range is asked for, which a file of one section never needs),
|
|
135
|
+
* a split one a piece per hunk. A file of several sections, as a `format-patch` series has, is one
|
|
136
|
+
* file, and the sections no header names, the text before the first header and a header that
|
|
137
|
+
* names no path, are the file of the empty name.
|
|
138
|
+
* 3. Each file of `scope.files`, in its order: `excluded` with no piece when `leftOut` excludes it;
|
|
139
|
+
* `unreviewed` for `binary`, else `submodule`, else `secret`, else `deleted-secret`, when `leftOut`
|
|
140
|
+
* lists it so, whatever became of its part (a held file has no piece, and no model was sent it);
|
|
141
|
+
* `reviewed` when every piece was read; `unreviewed` with its first piece's reason when none was; else
|
|
142
|
+
* `partial`, with the range of each hunk of each piece left, each with its reason, and none for a
|
|
143
|
+
* section with no hunk.
|
|
144
|
+
* A file with no piece that nothing excludes is unreviewed, never reviewed.
|
|
145
|
+
*/
|
|
146
|
+
export declare function coverageOf(scope: Pick<ReviewScope, 'files' | 'leftOut'>, sections: readonly DiffSection[], packing: Packing | undefined, outcomes: readonly PartOutcome[]): CoverageEntry[];
|