@tobi-or-not/quorum 0.4.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 +3 -1
- package/dist/bench/fingerprint.d.ts +8 -5
- package/dist/bench/fingerprint.js +28 -9
- package/dist/bench/records.d.ts +168 -0
- package/dist/bench/records.js +106 -1
- package/dist/bench/runner.d.ts +18 -0
- package/dist/bench/runner.js +30 -4
- package/dist/cli/bench.d.ts +11 -4
- package/dist/cli/bench.js +34 -17
- package/dist/cli/bin.js +2 -2
- package/dist/cli/io.d.ts +5 -0
- package/dist/cli/main.d.ts +67 -24
- package/dist/cli/main.js +288 -59
- package/dist/cli/print-config.d.ts +8 -6
- package/dist/cli/print-config.js +26 -8
- package/dist/cli/render.d.ts +9 -3
- package/dist/cli/render.js +43 -2
- 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/env.d.ts +32 -19
- package/dist/config/env.js +95 -32
- package/dist/config/from-config.js +21 -3
- package/dist/config/resolve.d.ts +13 -1
- package/dist/config/resolve.js +27 -1
- package/dist/config/schema.d.ts +152 -5
- package/dist/config/schema.js +156 -12
- package/dist/core/clock.d.ts +17 -0
- package/dist/core/clock.js +14 -0
- package/dist/core/coverage.d.ts +74 -0
- package/dist/core/coverage.js +221 -0
- package/dist/core/diff.d.ts +101 -0
- package/dist/core/diff.js +178 -35
- package/dist/core/errors.d.ts +12 -3
- package/dist/core/errors.js +21 -2
- package/dist/core/estimate.d.ts +45 -0
- package/dist/core/estimate.js +188 -0
- package/dist/core/exclude.d.ts +42 -0
- package/dist/core/exclude.js +189 -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 +83 -0
- package/dist/core/limits.js +169 -0
- package/dist/core/output.d.ts +3 -2
- package/dist/core/output.js +3 -2
- package/dist/core/parts.d.ts +146 -0
- package/dist/core/parts.js +388 -0
- package/dist/core/ports.d.ts +67 -2
- package/dist/core/ports.js +36 -1
- package/dist/core/prompts.d.ts +22 -3
- package/dist/core/prompts.js +43 -7
- package/dist/core/quorum.d.ts +26 -8
- package/dist/core/quorum.js +310 -73
- package/dist/core/retry.d.ts +36 -0
- package/dist/core/retry.js +46 -0
- package/dist/core/secrets.d.ts +98 -0
- package/dist/core/secrets.js +507 -0
- package/dist/core/stages/context.d.ts +131 -23
- package/dist/core/stages/context.js +331 -46
- package/dist/core/stages/panel.d.ts +13 -6
- package/dist/core/stages/panel.js +79 -19
- package/dist/core/stages/research.d.ts +110 -25
- package/dist/core/stages/research.js +338 -44
- package/dist/core/tokens.d.ts +31 -0
- package/dist/core/tokens.js +81 -0
- package/dist/core/types.d.ts +280 -25
- 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 +3 -1
- package/dist/providers/anthropic.js +10 -3
- package/dist/providers/claude-code.d.ts +56 -11
- package/dist/providers/claude-code.js +70 -25
- package/dist/providers/gemini.d.ts +5 -1
- package/dist/providers/gemini.js +65 -11
- package/dist/providers/http.d.ts +49 -4
- package/dist/providers/http.js +155 -14
- package/dist/providers/ollama.d.ts +4 -1
- package/dist/providers/ollama.js +13 -5
- package/dist/providers/openai-compatible.d.ts +4 -1
- package/dist/providers/openai-compatible.js +13 -5
- package/dist/providers/options.d.ts +12 -3
- package/dist/providers/options.js +30 -10
- package/dist/providers/size.d.ts +19 -15
- package/dist/providers/size.js +33 -73
- 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 +49 -1
|
@@ -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[];
|
|
@@ -0,0 +1,388 @@
|
|
|
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 { heldSpan, holds, parseHunks } from "./diff.js";
|
|
12
|
+
import { showHidden } from "./sanitize.js";
|
|
13
|
+
import { tokenBound } from "./tokens.js";
|
|
14
|
+
/** The most tokens of diff text one research request of a large change holds, when `partTokens` is not set. */
|
|
15
|
+
export const DEFAULT_PART_TOKENS = 32_768;
|
|
16
|
+
/** The least `partTokens` a configuration may state. */
|
|
17
|
+
export const MIN_PART_TOKENS = 1024;
|
|
18
|
+
/** The most file names a part's request lists. */
|
|
19
|
+
export 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 function partTokensProblem(value) {
|
|
22
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= MIN_PART_TOKENS
|
|
23
|
+
? undefined
|
|
24
|
+
: `must be a whole number of tokens from ${MIN_PART_TOKENS} to ${Number.MAX_SAFE_INTEGER}`;
|
|
25
|
+
}
|
|
26
|
+
/** The offset of each hunk's `@@` line in `text`, found in one pass over the text. */
|
|
27
|
+
function lineStarts(text, hunks) {
|
|
28
|
+
const starts = [];
|
|
29
|
+
let line = 0;
|
|
30
|
+
let offset = 0;
|
|
31
|
+
for (const { at } of hunks) {
|
|
32
|
+
while (line < at) {
|
|
33
|
+
offset = text.indexOf('\n', offset) + 1;
|
|
34
|
+
line++;
|
|
35
|
+
}
|
|
36
|
+
starts.push(offset);
|
|
37
|
+
}
|
|
38
|
+
return starts;
|
|
39
|
+
}
|
|
40
|
+
/** The text of the hunks `from` to `to` of a cut section, to the section's end when `to` is past the last hunk. */
|
|
41
|
+
function hunksText(text, starts, from, to) {
|
|
42
|
+
return text.slice(starts[from], to < starts.length
|
|
43
|
+
? starts[to] - 1
|
|
44
|
+
: undefined);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Pack the sections of a diff into parts, in the diff's order, by arithmetic over `tokenBound`. A
|
|
48
|
+
* part holds at most `cap`, the lesser of `partTokens` and `room`, the tokens a request leaves for
|
|
49
|
+
* the diff; the line feed that joins two slices counts. A section whose text fits goes whole into
|
|
50
|
+
* the open part when it fits beside what is there, else into a new one. A larger section is split
|
|
51
|
+
* between its hunks, each one counted with the section's header: a hunk extends the open slice of
|
|
52
|
+
* its section while the part stays within `cap`, else opens a slice, in the open part when it fits,
|
|
53
|
+
* else in a new part, and never joins the slice before a hunk that was set aside. A unit over `cap`,
|
|
54
|
+
* a hunk or a section with no hunk, goes alone into a part of its own when it is within `room`,
|
|
55
|
+
* else it is set aside. A hunk is never cut: a section is cut only at the lines `parseHunks` opens
|
|
56
|
+
* a hunk at, so the text outside any hunk travels with the hunk before it, or with the header when
|
|
57
|
+
* none precedes it, and every line of every section is in exactly one part, besides the header a
|
|
58
|
+
* piece repeats, or in a unit set aside. The work is linear in the size of the diff.
|
|
59
|
+
*/
|
|
60
|
+
export function packParts(sections, budget) {
|
|
61
|
+
const cap = Math.min(budget.partTokens, budget.room);
|
|
62
|
+
const parts = [];
|
|
63
|
+
const tooLarge = [];
|
|
64
|
+
const cuts = new Map();
|
|
65
|
+
let open = [];
|
|
66
|
+
let used = 0;
|
|
67
|
+
const close = () => {
|
|
68
|
+
if (open.length > 0)
|
|
69
|
+
parts.push({ slices: open, tokens: used });
|
|
70
|
+
open = [];
|
|
71
|
+
used = 0;
|
|
72
|
+
};
|
|
73
|
+
// A slice within `cap`: in the open part when it fits beside it, the line feed counted, else in a new one.
|
|
74
|
+
const place = (slice, tokens) => {
|
|
75
|
+
if (open.length > 0 && used + 1 + tokens > cap)
|
|
76
|
+
close();
|
|
77
|
+
used = open.length === 0
|
|
78
|
+
? tokens
|
|
79
|
+
: used + 1 + tokens;
|
|
80
|
+
open.push(slice);
|
|
81
|
+
};
|
|
82
|
+
// One unit over `cap`: a part of its own when it is within the room, else set aside.
|
|
83
|
+
const alone = (slice, tokens, unplaced) => {
|
|
84
|
+
if (tokens > budget.room) {
|
|
85
|
+
tooLarge.push(unplaced);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
close();
|
|
89
|
+
parts.push({
|
|
90
|
+
slices: [slice],
|
|
91
|
+
tokens,
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
for (const [section, { text }] of sections.entries()) {
|
|
95
|
+
const whole = tokenBound(text);
|
|
96
|
+
if (whole <= cap) {
|
|
97
|
+
place({ section }, whole);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const hunks = parseHunks(text);
|
|
101
|
+
if (hunks.length === 0) {
|
|
102
|
+
alone({ section }, whole, { section });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const starts = lineStarts(text, hunks);
|
|
106
|
+
cuts.set(section, { hunks, starts });
|
|
107
|
+
const header = starts[0] === 0
|
|
108
|
+
? 0
|
|
109
|
+
: tokenBound(text.slice(0, starts[0] - 1)) + 1;
|
|
110
|
+
for (let hunk = 0; hunk < hunks.length; hunk++) {
|
|
111
|
+
// A hunk's lines run to the next `@@` line, or to the section's end: text outside a hunk goes with it.
|
|
112
|
+
const units = tokenBound(hunksText(text, starts, hunk, hunk + 1));
|
|
113
|
+
const last = open.at(-1);
|
|
114
|
+
if (last?.section === section && last.to === hunk && used + 1 + units <= cap) {
|
|
115
|
+
last.to = hunk + 1;
|
|
116
|
+
used += 1 + units;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const tokens = header + units;
|
|
120
|
+
const slice = { section, from: hunk, to: hunk + 1 };
|
|
121
|
+
if (tokens <= cap)
|
|
122
|
+
place(slice, tokens);
|
|
123
|
+
else
|
|
124
|
+
alone(slice, tokens, { section, hunk });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
close();
|
|
128
|
+
return { parts, tooLarge, cuts };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The text of a slice: the section's text for a whole slice, else the section's header (the lines
|
|
132
|
+
* before its first hunk, absent when that hunk opens the section), a line feed, and the text of its
|
|
133
|
+
* hunks, which ends at the section's end when the slice holds the last hunk. A slice's hunks are read
|
|
134
|
+
* from `Packing.cuts`, the section's own reading, never by parsing a slice alone: `parseHunks` reads
|
|
135
|
+
* a final line feed as the end of the text, so a slice that ends on an empty row, which is a blank
|
|
136
|
+
* context row, parses one row short.
|
|
137
|
+
*/
|
|
138
|
+
export function sliceText(sections, packing, slice) {
|
|
139
|
+
const { text } = sections[slice.section];
|
|
140
|
+
if (slice.from === undefined || slice.to === undefined)
|
|
141
|
+
return text;
|
|
142
|
+
// A slice of a hunk range is always of a section the packing cut.
|
|
143
|
+
const { starts } = packing.cuts.get(slice.section);
|
|
144
|
+
const hunks = hunksText(text, starts, slice.from, slice.to);
|
|
145
|
+
return starts[0] === 0
|
|
146
|
+
? hunks
|
|
147
|
+
: `${text.slice(0, starts[0] - 1)}\n${hunks}`;
|
|
148
|
+
}
|
|
149
|
+
/** How far `line` is from the new-file lines `hunk` holds, as `heldSpan` gives them: 0 inside them, else the lines to the nearer end; a hunk that holds none counts its start line alone. */
|
|
150
|
+
function distance(hunk, line) {
|
|
151
|
+
const { start, end } = heldSpan(hunk) ?? { start: hunk.start, end: hunk.start };
|
|
152
|
+
return Math.max(start - line, line - end, 0);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The part of a section a voter whose room cannot hold the whole of it is shown: the section's header
|
|
156
|
+
* (the text before its first hunk, which is none for a section that starts with its first `@@` line), a
|
|
157
|
+
* line feed, and the hunks nearest the cited `line` that fit `room` tokens, as `tokenBound` counts them.
|
|
158
|
+
* `hunks` are the section's own, as `hunksOf` reads them from the whole `text`, never from a piece of it.
|
|
159
|
+
* The cited hunk is the first that holds `line`, as `locate` takes it. Then, of the hunks beside those
|
|
160
|
+
* taken, the one nearer `line` in new-file lines comes next, the earlier on a tie, so the hunks taken
|
|
161
|
+
* are always the section's own run of neighbours, in its order, and the context reads as a diff. A
|
|
162
|
+
* hunk that does not fit closes its side, the one before the run or the one after it, and the other
|
|
163
|
+
* side goes on; it stops when both sides are closed or the section's ends are reached. The hunk's
|
|
164
|
+
* count is its lines to the next `@@` line, so text outside any hunk travels with the hunk before it,
|
|
165
|
+
* and the header is always the text before the first hunk of `text`, whatever it holds.
|
|
166
|
+
*
|
|
167
|
+
* It is undefined when no hunk holds `line`, or when the header and the cited hunk alone do not fit
|
|
168
|
+
* `room`: the caller then sends the whole section, which its provider refuses as too large.
|
|
169
|
+
*/
|
|
170
|
+
export function nearestHunks(text, hunks, line, room) {
|
|
171
|
+
const cited = hunks.findIndex(hunk => holds(hunk, line));
|
|
172
|
+
if (cited === -1)
|
|
173
|
+
return undefined;
|
|
174
|
+
const starts = lineStarts(text, hunks);
|
|
175
|
+
// The header's line feed is the one before the first `@@` line, which `starts[0]` is past.
|
|
176
|
+
const header = text.slice(0, starts[0]);
|
|
177
|
+
const countOf = (hunk) => tokenBound(hunksText(text, starts, hunk, hunk + 1));
|
|
178
|
+
let used = tokenBound(header) + countOf(cited);
|
|
179
|
+
if (used > room)
|
|
180
|
+
return undefined;
|
|
181
|
+
let low = cited;
|
|
182
|
+
let high = cited;
|
|
183
|
+
let before = cited > 0;
|
|
184
|
+
let after = cited < hunks.length - 1;
|
|
185
|
+
while (before || after) {
|
|
186
|
+
const takeBefore = before && (!after || distance(hunks[low - 1], line) <= distance(hunks[high + 1], line));
|
|
187
|
+
const next = takeBefore
|
|
188
|
+
? low - 1
|
|
189
|
+
: high + 1;
|
|
190
|
+
// The line feed that joins the hunk to the run counts with it.
|
|
191
|
+
const joined = 1 + countOf(next);
|
|
192
|
+
if (used + joined > room) {
|
|
193
|
+
if (takeBefore)
|
|
194
|
+
before = false;
|
|
195
|
+
else
|
|
196
|
+
after = false;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
used += joined;
|
|
200
|
+
if (takeBefore) {
|
|
201
|
+
low = next;
|
|
202
|
+
before = low > 0;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
high = next;
|
|
206
|
+
after = high < hunks.length - 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return header + hunksText(text, starts, low, high + 1);
|
|
210
|
+
}
|
|
211
|
+
/** The text of a part: its slices joined by line feeds. */
|
|
212
|
+
export function partText(sections, packing, part) {
|
|
213
|
+
return part.slices.map(slice => sliceText(sections, packing, slice)).join('\n');
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The files a part's request names: the distinct named files of the diff, in its order, the empty
|
|
217
|
+
* name (the text no header names) left out. The list is the longest prefix of at most `LISTED_FILES`
|
|
218
|
+
* names that fits `maxTokens`, each name counted as the request shows it, through `showHidden`,
|
|
219
|
+
* with its line feed, and it stops at the first name that does not fit, so a name's length, which
|
|
220
|
+
* the author chooses, cannot take more of the window than that. `unlisted` counts the names left
|
|
221
|
+
* out. The names come back as the diff writes them: the caller shows each through `showHidden`.
|
|
222
|
+
*/
|
|
223
|
+
export function listedFiles(sections, maxTokens) {
|
|
224
|
+
const names = new Set();
|
|
225
|
+
for (const { path } of sections) {
|
|
226
|
+
if (path !== undefined && path !== '')
|
|
227
|
+
names.add(path);
|
|
228
|
+
}
|
|
229
|
+
const files = [];
|
|
230
|
+
let used = 0;
|
|
231
|
+
for (const name of names) {
|
|
232
|
+
used += tokenBound(showHidden(name)) + 1;
|
|
233
|
+
if (files.length === LISTED_FILES || used > maxTokens)
|
|
234
|
+
break;
|
|
235
|
+
files.push(name);
|
|
236
|
+
}
|
|
237
|
+
return { files, unlisted: names.size - files.length };
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The one gap of a profile whose packing set a unit aside, counting the hunks and the files they belong to,
|
|
241
|
+
* a section with no hunk counting as one hunk and a file of several sections as one file; undefined when
|
|
242
|
+
* the packing set nothing aside, or there is none. A file that `leftOut` lists as `binary` or `submodule`
|
|
243
|
+
* counts for nothing: its coverage entry is `unreviewed` with that reason, whatever became of its part, and
|
|
244
|
+
* its own gap stands, so the detail's pointer to a `too-large` range would lead nowhere. The detail names
|
|
245
|
+
* the profile's coverage, which lists the ranges, and no file.
|
|
246
|
+
*/
|
|
247
|
+
export function tooLargeGap(profile, sections, packing, leftOut) {
|
|
248
|
+
if (packing === undefined)
|
|
249
|
+
return undefined;
|
|
250
|
+
const covered = new Set(leftOut.filter(({ reason }) => reason === 'binary' || reason === 'submodule').map(({ file }) => file));
|
|
251
|
+
const hunks = packing.tooLarge.filter(({ section }) => !covered.has(sections[section].path ?? ''));
|
|
252
|
+
if (hunks.length === 0)
|
|
253
|
+
return undefined;
|
|
254
|
+
const files = new Set(hunks.map(({ section }) => sections[section].path ?? ''));
|
|
255
|
+
return {
|
|
256
|
+
profile,
|
|
257
|
+
reason: 'too-large',
|
|
258
|
+
detail: `${hunks.length} hunk(s) of ${files.size} file(s) fit in no research part of its model's window, listed as too-large in meta.profiles.${profile}.coverage`,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** The reasons `meta.leftOut` gives for a file no model read, whatever became of the part that held it, in the order that decides when a file has several. */
|
|
262
|
+
const UNREVIEWED_REASONS = [
|
|
263
|
+
'binary',
|
|
264
|
+
'submodule',
|
|
265
|
+
'secret',
|
|
266
|
+
'deleted-secret',
|
|
267
|
+
];
|
|
268
|
+
const isUnread = (piece) => piece.outcome !== 'reviewed';
|
|
269
|
+
/**
|
|
270
|
+
* The outcome of each unit, as a lookup: one per section held whole or set aside whole, else one per
|
|
271
|
+
* hunk of a split section. A part with no outcome, and a unit that no part holds and the packing
|
|
272
|
+
* does not set aside, count as a failed read, never as a reviewed one.
|
|
273
|
+
*/
|
|
274
|
+
function outcomesOfUnits(sectionCount, packing, outcomes) {
|
|
275
|
+
const whole = new Map();
|
|
276
|
+
const byHunk = new Map();
|
|
277
|
+
const record = (section, from, to, outcome) => {
|
|
278
|
+
if (from === undefined || to === undefined) {
|
|
279
|
+
whole.set(section, outcome);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const hunks = byHunk.get(section) ?? [];
|
|
283
|
+
byHunk.set(section, hunks);
|
|
284
|
+
for (let hunk = from; hunk < to; hunk++)
|
|
285
|
+
hunks[hunk] = outcome;
|
|
286
|
+
};
|
|
287
|
+
if (packing === undefined) {
|
|
288
|
+
for (let section = 0; section < sectionCount; section++)
|
|
289
|
+
record(section, undefined, undefined, outcomes[0] ?? 'research-failed');
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
for (const [index, part] of packing.parts.entries()) {
|
|
293
|
+
for (const { section, from, to } of part.slices)
|
|
294
|
+
record(section, from, to, outcomes[index] ?? 'research-failed');
|
|
295
|
+
}
|
|
296
|
+
for (const { section, hunk } of packing.tooLarge) {
|
|
297
|
+
record(section, hunk, hunk === undefined
|
|
298
|
+
? undefined
|
|
299
|
+
: hunk + 1, 'too-large');
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return (section, hunk) => (hunk === undefined
|
|
303
|
+
? whole.get(section)
|
|
304
|
+
: byHunk.get(section)?.[hunk]) ?? 'research-failed';
|
|
305
|
+
}
|
|
306
|
+
/** The ranges a piece left unread: the lines of each hunk it holds, a hunk that holds no line at its start line alone, none for a section with no hunk. */
|
|
307
|
+
function leftRanges(piece, sections, packing) {
|
|
308
|
+
const hunks = packing?.cuts.get(piece.section)?.hunks ?? parseHunks(sections[piece.section].text);
|
|
309
|
+
const left = piece.hunk === undefined
|
|
310
|
+
? hunks
|
|
311
|
+
: [hunks[piece.hunk]];
|
|
312
|
+
return left.map(hunk => ({
|
|
313
|
+
...(heldSpan(hunk) ?? { start: hunk.start, end: hunk.start }),
|
|
314
|
+
reason: piece.outcome,
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* How much of each file of the diff a profile's research reviewed, in the diff's order, once per
|
|
319
|
+
* file. `packing` is how `sections`, the ones the research read, were packed into the parts `outcomes`
|
|
320
|
+
* tells the fate of, one outcome per part; undefined is one part that holds every section whole, whose outcome is
|
|
321
|
+
* `outcomes[0]`, `'research-failed'` when there is none. In this order:
|
|
322
|
+
* 1. Each section's outcome: one when it is whole in a part, set aside whole, or in a one-part plan;
|
|
323
|
+
* else one per hunk, `too-large` for the units the packing set aside.
|
|
324
|
+
* 2. Each file's pieces, in the diff's order: a section held whole is one piece, whose ranges are
|
|
325
|
+
* all its hunks' (parsed only when a range is asked for, which a file of one section never needs),
|
|
326
|
+
* a split one a piece per hunk. A file of several sections, as a `format-patch` series has, is one
|
|
327
|
+
* file, and the sections no header names, the text before the first header and a header that
|
|
328
|
+
* names no path, are the file of the empty name.
|
|
329
|
+
* 3. Each file of `scope.files`, in its order: `excluded` with no piece when `leftOut` excludes it;
|
|
330
|
+
* `unreviewed` for `binary`, else `submodule`, else `secret`, else `deleted-secret`, when `leftOut`
|
|
331
|
+
* lists it so, whatever became of its part (a held file has no piece, and no model was sent it);
|
|
332
|
+
* `reviewed` when every piece was read; `unreviewed` with its first piece's reason when none was; else
|
|
333
|
+
* `partial`, with the range of each hunk of each piece left, each with its reason, and none for a
|
|
334
|
+
* section with no hunk.
|
|
335
|
+
* A file with no piece that nothing excludes is unreviewed, never reviewed.
|
|
336
|
+
*/
|
|
337
|
+
export function coverageOf(scope, sections, packing, outcomes) {
|
|
338
|
+
const outcomeOf = outcomesOfUnits(sections.length, packing, outcomes);
|
|
339
|
+
const pieces = new Map();
|
|
340
|
+
for (const [section, { path }] of sections.entries()) {
|
|
341
|
+
const own = pieces.get(path ?? '') ?? [];
|
|
342
|
+
pieces.set(path ?? '', own);
|
|
343
|
+
const cut = packing?.cuts.get(section);
|
|
344
|
+
if (cut === undefined) {
|
|
345
|
+
own.push({
|
|
346
|
+
outcome: outcomeOf(section),
|
|
347
|
+
section,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
cut.hunks.forEach((_, hunk) => own.push({
|
|
352
|
+
outcome: outcomeOf(section, hunk),
|
|
353
|
+
section,
|
|
354
|
+
hunk,
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const listed = (reason) => new Set(scope.leftOut.filter(entry => entry.reason === reason).map(entry => entry.file));
|
|
359
|
+
const excluded = listed('excluded');
|
|
360
|
+
// A file listed for several of the reasons is unreviewed for the first of them, in their order.
|
|
361
|
+
const unreviewed = new Map();
|
|
362
|
+
for (const reason of UNREVIEWED_REASONS) {
|
|
363
|
+
for (const file of listed(reason)) {
|
|
364
|
+
if (!unreviewed.has(file))
|
|
365
|
+
unreviewed.set(file, reason);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return scope.files.map((file) => {
|
|
369
|
+
const own = pieces.get(file) ?? [];
|
|
370
|
+
if (own.length === 0 && excluded.has(file))
|
|
371
|
+
return { file, status: 'excluded' };
|
|
372
|
+
const listedReason = unreviewed.get(file);
|
|
373
|
+
if (listedReason !== undefined)
|
|
374
|
+
return { file, status: 'unreviewed', reason: listedReason };
|
|
375
|
+
const unread = own.filter(isUnread);
|
|
376
|
+
if (own.length > 0 && unread.length === 0)
|
|
377
|
+
return { file, status: 'reviewed' };
|
|
378
|
+
if (unread.length === own.length) {
|
|
379
|
+
const reason = unread[0]?.outcome ?? 'research-failed';
|
|
380
|
+
return { file, status: 'unreviewed', reason };
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
file,
|
|
384
|
+
status: 'partial',
|
|
385
|
+
left: unread.flatMap(piece => leftRanges(piece, sections, packing)),
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
}
|
package/dist/core/ports.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface CompletionRequest {
|
|
|
14
14
|
name: string;
|
|
15
15
|
schema: JsonSchema;
|
|
16
16
|
};
|
|
17
|
+
/** The attempt's own signal: aborted with the review's, or at the attempt's deadline. */
|
|
17
18
|
signal?: AbortSignal;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -26,6 +27,34 @@ export interface CompletionResponse {
|
|
|
26
27
|
model: string;
|
|
27
28
|
usage?: Usage;
|
|
28
29
|
}
|
|
30
|
+
/** The deadline of an attempt when its provider states none: ten minutes. */
|
|
31
|
+
export declare const DEFAULT_TIMEOUT_MS = 600000;
|
|
32
|
+
/** The shortest deadline: one second. */
|
|
33
|
+
export declare const MIN_TIMEOUT_MS = 1000;
|
|
34
|
+
/** The longest deadline an option, a config or a variable sets: 24 hours. */
|
|
35
|
+
export declare const MAX_TIMEOUT_MS = 86400000;
|
|
36
|
+
/** The most retries a call is given. */
|
|
37
|
+
export declare const MAX_RETRIES = 5;
|
|
38
|
+
/**
|
|
39
|
+
* The retries a shipped adapter states when its options set none: two. A provider that states none
|
|
40
|
+
* gets no retry, since the core must not retry what may retry by itself.
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_RETRIES = 2;
|
|
43
|
+
/**
|
|
44
|
+
* The longest deadline a provider states: six times `MAX_TIMEOUT_MS`, since a provider that runs
|
|
45
|
+
* the retries itself states the deadline of its whole call, `timeoutMs` times `MAX_RETRIES + 1`.
|
|
46
|
+
*/
|
|
47
|
+
export declare const MAX_STATED_TIMEOUT_MS: number;
|
|
48
|
+
/**
|
|
49
|
+
* What is wrong with a deadline, worded with what to write, or undefined for a safe integer from
|
|
50
|
+
* `MIN_TIMEOUT_MS` to `max`. The value is never quoted: it may be anything.
|
|
51
|
+
*/
|
|
52
|
+
export declare function timeoutProblem(value: unknown, max?: number): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* What is wrong with a count of retries, worded with what to write, or undefined for a whole number
|
|
55
|
+
* from 0 to `MAX_RETRIES`. The value is never quoted: it may be anything.
|
|
56
|
+
*/
|
|
57
|
+
export declare function retriesProblem(value: unknown): string | undefined;
|
|
29
58
|
/**
|
|
30
59
|
* A model behind a port: it receives text and returns text (invariant I1). No environment value, key
|
|
31
60
|
* or credential appears in a request; keys live in adapters only. The core never trusts the reply
|
|
@@ -34,10 +63,46 @@ export interface CompletionResponse {
|
|
|
34
63
|
export interface Provider {
|
|
35
64
|
readonly id: string;
|
|
36
65
|
readonly model: string;
|
|
66
|
+
/**
|
|
67
|
+
* The deadline of one attempt, in whole milliseconds from 1000 to 518400000; `DEFAULT_TIMEOUT_MS`
|
|
68
|
+
* when unset. At it the core aborts the attempt's signal and fails the attempt as a timeout,
|
|
69
|
+
* whatever the provider does. It is read when the quorum is created, as an own data
|
|
70
|
+
* property: a getter is never run and an inherited property states nothing, so a class sets it as
|
|
71
|
+
* a field.
|
|
72
|
+
*/
|
|
73
|
+
readonly timeoutMs?: number;
|
|
74
|
+
/**
|
|
75
|
+
* How often the core retries a call that failed in passing, after its first attempt: a whole
|
|
76
|
+
* number from 0 to 5; none when unset, since a provider that retries by itself must not be
|
|
77
|
+
* retried again. The core retries only a `network`, `timeout` or `http` failure that says it may
|
|
78
|
+
* be retried, and never a call's second timeout. It is read when the quorum is created, as
|
|
79
|
+
* an own data property, as `timeoutMs` is.
|
|
80
|
+
*/
|
|
81
|
+
readonly retries?: number;
|
|
82
|
+
/**
|
|
83
|
+
* The most tokens, input and output, that one attempt of `request` may spend as the provider is billed
|
|
84
|
+
* for it, which is what the core reserves for each attempt of the request. It is called once per call,
|
|
85
|
+
* once the request is built; a result that is not a whole number of at least 1, or a throw, states
|
|
86
|
+
* nothing, and the core then reserves its own count of the request plus 512 tokens for what a server
|
|
87
|
+
* adds and 16000 for the reply, as it does when this is unset. It is read when the quorum is created,
|
|
88
|
+
* as an own data property, as `timeoutMs` is: a getter is never run and an inherited method states
|
|
89
|
+
* nothing, so a class sets it as an arrow-function field.
|
|
90
|
+
*/
|
|
91
|
+
readonly worstCase?: (request: CompletionRequest) => number;
|
|
92
|
+
/**
|
|
93
|
+
* How many more tokens of text `request` could hold and still fit the provider's window, counted as its
|
|
94
|
+
* size guard counts: negative when it does not fit, 0 when it fits exactly, so a request at a room of 0
|
|
95
|
+
* is sent and one at -1 is refused, and text added to the request lowers the room by its count. It is
|
|
96
|
+
* called once per question, synchronously; a result that is no safe integer, a promise or a throw states
|
|
97
|
+
* nothing, and the core then reviews as it does when this is unset. It is read when the quorum is
|
|
98
|
+
* created, as an own data property, as `worstCase` is: a getter is never run and an inherited method
|
|
99
|
+
* states nothing, so a class sets it as an arrow-function field.
|
|
100
|
+
*/
|
|
101
|
+
readonly room?: (request: CompletionRequest) => number;
|
|
37
102
|
/**
|
|
38
103
|
* Answer one request. It should honour `request.signal`, settling soon after the signal aborts:
|
|
39
|
-
*
|
|
40
|
-
* provider
|
|
104
|
+
* the core settles the call at its deadline or at the review's abort without waiting for the
|
|
105
|
+
* provider, and a provider that ignores the signal works on, outside the review, until it ends.
|
|
41
106
|
*/
|
|
42
107
|
complete: (request: CompletionRequest) => Promise<CompletionResponse>;
|
|
43
108
|
}
|
package/dist/core/ports.js
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
/** The deadline of an attempt when its provider states none: ten minutes. */
|
|
2
|
+
export const DEFAULT_TIMEOUT_MS = 600_000;
|
|
3
|
+
/** The shortest deadline: one second. */
|
|
4
|
+
export const MIN_TIMEOUT_MS = 1000;
|
|
5
|
+
/** The longest deadline an option, a config or a variable sets: 24 hours. */
|
|
6
|
+
export const MAX_TIMEOUT_MS = 86_400_000;
|
|
7
|
+
/** The most retries a call is given. */
|
|
8
|
+
export const MAX_RETRIES = 5;
|
|
9
|
+
/**
|
|
10
|
+
* The retries a shipped adapter states when its options set none: two. A provider that states none
|
|
11
|
+
* gets no retry, since the core must not retry what may retry by itself.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_RETRIES = 2;
|
|
14
|
+
/**
|
|
15
|
+
* The longest deadline a provider states: six times `MAX_TIMEOUT_MS`, since a provider that runs
|
|
16
|
+
* the retries itself states the deadline of its whole call, `timeoutMs` times `MAX_RETRIES + 1`.
|
|
17
|
+
*/
|
|
18
|
+
export const MAX_STATED_TIMEOUT_MS = MAX_TIMEOUT_MS * (MAX_RETRIES + 1);
|
|
19
|
+
/**
|
|
20
|
+
* What is wrong with a deadline, worded with what to write, or undefined for a safe integer from
|
|
21
|
+
* `MIN_TIMEOUT_MS` to `max`. The value is never quoted: it may be anything.
|
|
22
|
+
*/
|
|
23
|
+
export function timeoutProblem(value, max = MAX_TIMEOUT_MS) {
|
|
24
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= MIN_TIMEOUT_MS && value <= max
|
|
25
|
+
? undefined
|
|
26
|
+
: `must be a whole number of milliseconds from ${MIN_TIMEOUT_MS} to ${max}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What is wrong with a count of retries, worded with what to write, or undefined for a whole number
|
|
30
|
+
* from 0 to `MAX_RETRIES`. The value is never quoted: it may be anything.
|
|
31
|
+
*/
|
|
32
|
+
export function retriesProblem(value) {
|
|
33
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= MAX_RETRIES
|
|
34
|
+
? undefined
|
|
35
|
+
: `must be a whole number from 0 to ${MAX_RETRIES}`;
|
|
36
|
+
}
|