@tobi-or-not/quorum 0.1.0 → 0.3.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/LICENSE +202 -0
- package/README.md +5 -0
- package/dist/bench/fingerprint.d.ts +36 -0
- package/dist/bench/fingerprint.js +79 -0
- package/dist/bench/records.d.ts +62 -0
- package/dist/bench/records.js +161 -0
- package/dist/bench/report.d.ts +110 -0
- package/dist/bench/report.js +332 -0
- package/dist/bench/run-dir.d.ts +101 -0
- package/dist/bench/run-dir.js +379 -0
- package/dist/bench/runner.d.ts +80 -0
- package/dist/bench/runner.js +160 -0
- package/dist/bench/score.d.ts +30 -0
- package/dist/bench/score.js +38 -0
- package/dist/bench/stats.d.ts +51 -0
- package/dist/bench/stats.js +83 -0
- package/dist/bench/suite.d.ts +87 -0
- package/dist/bench/suite.js +286 -0
- package/dist/cli/bench.d.ts +32 -0
- package/dist/cli/bench.js +463 -0
- package/dist/cli/bin.js +9 -1
- package/dist/cli/io.d.ts +45 -0
- package/dist/cli/io.js +45 -0
- package/dist/cli/main.d.ts +7 -37
- package/dist/cli/main.js +47 -60
- package/dist/cli/print-config.js +38 -9
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +37 -16
- package/dist/config/claude-code.js +42 -11
- package/dist/config/env.js +135 -32
- package/dist/config/from-config.js +43 -9
- package/dist/config/load.d.ts +43 -0
- package/dist/config/load.js +205 -46
- package/dist/config/profiles.js +87 -20
- package/dist/config/resolve.js +194 -47
- package/dist/config/schema.js +98 -23
- package/dist/core/diff.d.ts +10 -0
- package/dist/core/diff.js +90 -17
- package/dist/core/errors.js +14 -5
- package/dist/core/flags.js +30 -6
- package/dist/core/output.js +49 -13
- package/dist/core/policy.js +6 -2
- package/dist/core/profile.js +42 -15
- package/dist/core/prompts.d.ts +3 -1
- package/dist/core/prompts.js +28 -8
- package/dist/core/quorum.js +128 -33
- package/dist/core/sanitize.d.ts +16 -1
- package/dist/core/sanitize.js +31 -5
- package/dist/core/stages/context.js +30 -5
- package/dist/core/stages/panel.js +55 -9
- package/dist/core/stages/research.js +13 -3
- package/dist/core/verify.js +6 -2
- package/dist/index.js +5 -1
- package/dist/providers/anthropic.js +28 -5
- package/dist/providers/build.js +57 -16
- package/dist/providers/claude-code.js +206 -51
- package/dist/providers/gemini.js +61 -14
- package/dist/providers/http.js +32 -9
- package/dist/providers/messages.js +14 -2
- package/dist/providers/ollama.js +31 -8
- package/dist/providers/openai-compatible.js +51 -15
- package/dist/providers/options.js +120 -40
- package/dist/providers/presets.js +143 -16
- package/dist/providers/reply.js +15 -5
- package/dist/providers/size.js +11 -3
- package/package.json +6 -5
package/dist/config/load.js
CHANGED
|
@@ -7,7 +7,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
9
|
import { constants } from 'node:fs';
|
|
10
|
-
import { open } from 'node:fs/promises';
|
|
10
|
+
import { lstat, open } from 'node:fs/promises';
|
|
11
11
|
import { dirname, extname, isAbsolute, resolve } from 'node:path';
|
|
12
12
|
import { pathToFileURL } from 'node:url';
|
|
13
13
|
import { isMap, isPair, isScalar, isSeq, LineCounter, parseDocument } from 'yaml';
|
|
@@ -26,26 +26,75 @@ const MAX_DEPTH = 64;
|
|
|
26
26
|
/** How many values a config may hold: more would be a walk and a schema check of unbounded work, and issues of unbounded number. */
|
|
27
27
|
const MAX_VALUES = 10_000;
|
|
28
28
|
/** The format of each extension a config may have, read from the map alone, never from an object's prototype. */
|
|
29
|
-
const FORMATS = new Map([
|
|
29
|
+
const FORMATS = new Map([
|
|
30
|
+
['.yaml', 'yaml'],
|
|
31
|
+
['.yml', 'yaml'],
|
|
32
|
+
['.json', 'json'],
|
|
33
|
+
['.mts', 'code'],
|
|
34
|
+
['.mjs', 'code'],
|
|
35
|
+
['.ts', 'code'],
|
|
36
|
+
['.js', 'code'],
|
|
37
|
+
]);
|
|
30
38
|
/** A name a message may give what a config threw: a class name, never text the config could have written a secret into. */
|
|
31
39
|
const ERROR_NAME = /^[A-Z][A-Za-z]{0,63}$/;
|
|
32
40
|
const STAGES = ['research', 'vote'];
|
|
33
41
|
function fail(path, message) {
|
|
34
|
-
throw new ConfigError([
|
|
42
|
+
throw new ConfigError([
|
|
43
|
+
{ path, message },
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
/** What an open that failed means, by its code: the runtime's own message is never kept. */
|
|
47
|
+
function openProblem(error, noFollow) {
|
|
48
|
+
const code = error.code;
|
|
49
|
+
if (code === 'ENOENT' || code === 'ENOTDIR')
|
|
50
|
+
return 'does not exist';
|
|
51
|
+
if (code === 'EISDIR')
|
|
52
|
+
return 'is not a file';
|
|
53
|
+
return code === 'ELOOP' && noFollow
|
|
54
|
+
? 'is a symbolic link'
|
|
55
|
+
: 'cannot be read';
|
|
56
|
+
}
|
|
57
|
+
/** The problem a path has before an open that must not follow a link: it is one, or it is missing or unreadable; undefined when it is not a link. */
|
|
58
|
+
async function linkProblem(absolute) {
|
|
59
|
+
try {
|
|
60
|
+
return (await lstat(absolute)).isSymbolicLink()
|
|
61
|
+
? 'is a symbolic link'
|
|
62
|
+
: undefined;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const code = error.code;
|
|
66
|
+
return code === 'ENOENT' || code === 'ENOTDIR'
|
|
67
|
+
? 'does not exist'
|
|
68
|
+
: 'cannot be read';
|
|
69
|
+
}
|
|
35
70
|
}
|
|
36
71
|
/**
|
|
37
72
|
* The bytes of a regular file of at most `limit` bytes. The file is opened without blocking, so a FIFO
|
|
38
73
|
* is refused instead of waiting for a writer, and at most one byte past the limit is read, however large
|
|
39
|
-
* the file is or grows. The runtime's own message is never kept.
|
|
74
|
+
* the file is or grows. The runtime's own message is never kept. A symbolic link is followed, unless
|
|
75
|
+
* `options.noFollow` is set: then a link is `is a symbolic link`, refused by an `lstat` before the open,
|
|
76
|
+
* and the open itself refuses one with `O_NOFOLLOW` where the platform has it, which closes the race
|
|
77
|
+
* between the two on Linux and macOS (without it, on Windows, a link swapped in after the `lstat` is
|
|
78
|
+
* followed).
|
|
40
79
|
*/
|
|
41
|
-
async function readBounded(absolute, limit, size) {
|
|
80
|
+
export async function readBounded(absolute, limit, size, options = {}) {
|
|
81
|
+
const noFollow = options.noFollow === true;
|
|
82
|
+
if (noFollow) {
|
|
83
|
+
const linked = await linkProblem(absolute);
|
|
84
|
+
if (linked !== undefined)
|
|
85
|
+
return { problem: linked };
|
|
86
|
+
}
|
|
87
|
+
const flags = noFollow && typeof constants.O_NOFOLLOW === 'number'
|
|
88
|
+
? constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW
|
|
89
|
+
: constants.O_RDONLY | constants.O_NONBLOCK;
|
|
42
90
|
let handle;
|
|
43
91
|
try {
|
|
44
|
-
handle = await open(absolute,
|
|
92
|
+
handle = await open(absolute, flags);
|
|
45
93
|
}
|
|
46
94
|
catch (error) {
|
|
47
|
-
|
|
48
|
-
|
|
95
|
+
return {
|
|
96
|
+
problem: openProblem(error, noFollow),
|
|
97
|
+
};
|
|
49
98
|
}
|
|
50
99
|
try {
|
|
51
100
|
const stats = await handle.stat();
|
|
@@ -56,7 +105,11 @@ async function readBounded(absolute, limit, size) {
|
|
|
56
105
|
for (let read = -1; read !== 0 && length < buffer.length; length += read) {
|
|
57
106
|
read = (await handle.read(buffer, length, buffer.length - length, length)).bytesRead;
|
|
58
107
|
}
|
|
59
|
-
return length > limit
|
|
108
|
+
return length > limit
|
|
109
|
+
? { problem: `is over ${size}`, counted: limit }
|
|
110
|
+
: {
|
|
111
|
+
value: buffer.subarray(0, length),
|
|
112
|
+
};
|
|
60
113
|
}
|
|
61
114
|
catch {
|
|
62
115
|
return { problem: 'cannot be read' };
|
|
@@ -66,9 +119,11 @@ async function readBounded(absolute, limit, size) {
|
|
|
66
119
|
}
|
|
67
120
|
}
|
|
68
121
|
/** The UTF-8 text of `bytes`, a leading byte-order mark dropped (the decoder's default). */
|
|
69
|
-
function decode(bytes) {
|
|
122
|
+
export function decode(bytes) {
|
|
70
123
|
try {
|
|
71
|
-
return {
|
|
124
|
+
return {
|
|
125
|
+
value: new TextDecoder('utf-8', { fatal: true }).decode(bytes),
|
|
126
|
+
};
|
|
72
127
|
}
|
|
73
128
|
catch {
|
|
74
129
|
return { problem: 'is not UTF-8 text' };
|
|
@@ -77,7 +132,9 @@ function decode(bytes) {
|
|
|
77
132
|
/** The UTF-8 text of a regular file of at most `limit` bytes. */
|
|
78
133
|
async function readText(absolute, limit, size) {
|
|
79
134
|
const bytes = await readBounded(absolute, limit, size);
|
|
80
|
-
return 'problem' in bytes
|
|
135
|
+
return 'problem' in bytes
|
|
136
|
+
? bytes
|
|
137
|
+
: decode(bytes.value);
|
|
81
138
|
}
|
|
82
139
|
/** Where `offset` sits in the text, as a line and a column. */
|
|
83
140
|
function position(lines, offset) {
|
|
@@ -100,7 +157,9 @@ function yamlProblem(error, lines) {
|
|
|
100
157
|
* `MAX_DEPTH` keys deep: `dataIssues` refuses that data whatever the walk finds there.
|
|
101
158
|
*/
|
|
102
159
|
function repeatedKeyAt(doc) {
|
|
103
|
-
const stack = [
|
|
160
|
+
const stack = [
|
|
161
|
+
{ node: doc.contents, depth: 0 },
|
|
162
|
+
];
|
|
104
163
|
for (let entry = stack.pop(); entry !== undefined; entry = stack.pop()) {
|
|
105
164
|
const { node, depth } = entry;
|
|
106
165
|
if (depth > MAX_DEPTH)
|
|
@@ -112,9 +171,14 @@ function repeatedKeyAt(doc) {
|
|
|
112
171
|
if (isMap(node)) {
|
|
113
172
|
const seen = new Set();
|
|
114
173
|
for (const { key } of node.items) {
|
|
115
|
-
const value = isScalar(key)
|
|
116
|
-
|
|
117
|
-
|
|
174
|
+
const value = isScalar(key)
|
|
175
|
+
? key.value
|
|
176
|
+
: key;
|
|
177
|
+
if (seen.has(value)) {
|
|
178
|
+
return (isScalar(key)
|
|
179
|
+
? key.range?.[0]
|
|
180
|
+
: undefined) ?? 0;
|
|
181
|
+
}
|
|
118
182
|
seen.add(value);
|
|
119
183
|
}
|
|
120
184
|
}
|
|
@@ -130,22 +194,42 @@ function repeatedKeyAt(doc) {
|
|
|
130
194
|
* are not resolved; any error, any warning (an unknown tag is only a warning to the parser), a key that
|
|
131
195
|
* repeats one of its mapping and any alias refuse the file; no problem carries source text.
|
|
132
196
|
*/
|
|
133
|
-
function parseYaml(text) {
|
|
197
|
+
export function parseYaml(text) {
|
|
134
198
|
const lines = new LineCounter();
|
|
135
199
|
try {
|
|
136
|
-
const doc = parseDocument(text, {
|
|
200
|
+
const doc = parseDocument(text, {
|
|
201
|
+
schema: 'core',
|
|
202
|
+
version: '1.2',
|
|
203
|
+
merge: false,
|
|
204
|
+
resolveKnownTags: false,
|
|
205
|
+
uniqueKeys: false,
|
|
206
|
+
stringKeys: true,
|
|
207
|
+
prettyErrors: false,
|
|
208
|
+
logLevel: 'error',
|
|
209
|
+
strict: true,
|
|
210
|
+
lineCounter: lines,
|
|
211
|
+
});
|
|
137
212
|
const first = doc.errors[0] ?? doc.warnings[0];
|
|
138
|
-
if (first !== undefined)
|
|
139
|
-
return {
|
|
213
|
+
if (first !== undefined) {
|
|
214
|
+
return {
|
|
215
|
+
problem: yamlProblem(first, lines),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
140
218
|
const repeated = repeatedKeyAt(doc);
|
|
141
219
|
if (repeated !== undefined)
|
|
142
220
|
return { problem: `is not valid YAML at ${position(lines, repeated)} (DUPLICATE_KEY)` };
|
|
143
221
|
const value = doc.toJS({ maxAliasCount: 0 });
|
|
144
|
-
return value === null
|
|
222
|
+
return value === null
|
|
223
|
+
? { problem: 'is empty' }
|
|
224
|
+
: { value };
|
|
145
225
|
}
|
|
146
226
|
catch (error) {
|
|
147
227
|
// An alias throws a ReferenceError once aliases are disabled; deep nesting can throw a RangeError.
|
|
148
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
problem: error instanceof ReferenceError
|
|
230
|
+
? 'uses an alias, which quorum does not read'
|
|
231
|
+
: 'is not valid YAML',
|
|
232
|
+
};
|
|
149
233
|
}
|
|
150
234
|
}
|
|
151
235
|
/**
|
|
@@ -165,19 +249,27 @@ function parseJson(text) {
|
|
|
165
249
|
}
|
|
166
250
|
const lines = new LineCounter();
|
|
167
251
|
try {
|
|
168
|
-
const doc = parseDocument(text, {
|
|
252
|
+
const doc = parseDocument(text, {
|
|
253
|
+
schema: 'json',
|
|
254
|
+
uniqueKeys: false,
|
|
255
|
+
prettyErrors: false,
|
|
256
|
+
logLevel: 'error',
|
|
257
|
+
lineCounter: lines,
|
|
258
|
+
});
|
|
169
259
|
const first = doc.errors[0];
|
|
170
260
|
if (first !== undefined)
|
|
171
261
|
return { problem: `is not valid JSON at ${position(lines, first.pos[0])} (${first.code})` };
|
|
172
262
|
const repeated = repeatedKeyAt(doc);
|
|
173
|
-
return repeated === undefined
|
|
263
|
+
return repeated === undefined
|
|
264
|
+
? { value }
|
|
265
|
+
: { problem: `has a duplicate key at ${position(lines, repeated)}` };
|
|
174
266
|
}
|
|
175
267
|
catch {
|
|
176
268
|
return { problem: 'is not valid JSON' };
|
|
177
269
|
}
|
|
178
270
|
}
|
|
179
271
|
/** Whether `value` is an object of data: an object whose prototype is `Object.prototype` or none, never a class instance. */
|
|
180
|
-
function isPlainObject(value) {
|
|
272
|
+
export function isPlainObject(value) {
|
|
181
273
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
182
274
|
return false;
|
|
183
275
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -194,28 +286,57 @@ function isPlainObject(value) {
|
|
|
194
286
|
* `MAX_VALUES` it stops and the config has that one issue, at the file: the schema never sees more data
|
|
195
287
|
* than that, and an object that refers to itself ends the walk instead of repeating it.
|
|
196
288
|
*/
|
|
197
|
-
function dataIssues(value, file) {
|
|
289
|
+
export function dataIssues(value, file) {
|
|
198
290
|
const budget = { left: MAX_VALUES };
|
|
199
291
|
const issues = valueIssues(value, [], file, 0, budget);
|
|
200
|
-
return budget.left < 0
|
|
292
|
+
return budget.left < 0
|
|
293
|
+
? [
|
|
294
|
+
{ path: file ?? 'config', message: `holds more than ${MAX_VALUES} values` },
|
|
295
|
+
]
|
|
296
|
+
: issues;
|
|
201
297
|
}
|
|
202
298
|
function valueIssues(value, segments, file, depth, budget) {
|
|
203
299
|
if (--budget.left < 0)
|
|
204
300
|
return [];
|
|
205
|
-
if (depth > MAX_DEPTH)
|
|
206
|
-
return [
|
|
301
|
+
if (depth > MAX_DEPTH) {
|
|
302
|
+
return [
|
|
303
|
+
{
|
|
304
|
+
path: configPath(segments, file),
|
|
305
|
+
message: `is nested more than ${MAX_DEPTH} keys deep`,
|
|
306
|
+
},
|
|
307
|
+
];
|
|
308
|
+
}
|
|
207
309
|
if (value === null || value === undefined || typeof value === 'string' || typeof value === 'boolean')
|
|
208
310
|
return [];
|
|
209
|
-
if (typeof value === 'number')
|
|
210
|
-
return Number.isFinite(value)
|
|
311
|
+
if (typeof value === 'number') {
|
|
312
|
+
return Number.isFinite(value)
|
|
313
|
+
? []
|
|
314
|
+
: [
|
|
315
|
+
{
|
|
316
|
+
path: configPath(segments, file),
|
|
317
|
+
message: 'must be a finite number',
|
|
318
|
+
},
|
|
319
|
+
];
|
|
320
|
+
}
|
|
211
321
|
if (isProvider(value))
|
|
212
322
|
return [];
|
|
213
323
|
if (Array.isArray(value))
|
|
214
324
|
return value.flatMap((item, index) => valueIssues(item, [...segments, index], file, depth + 1, budget));
|
|
215
|
-
if (!isPlainObject(value))
|
|
216
|
-
return [
|
|
325
|
+
if (!isPlainObject(value)) {
|
|
326
|
+
return [
|
|
327
|
+
{
|
|
328
|
+
path: configPath(segments, file),
|
|
329
|
+
message: 'must be plain data: an object, an array, a string, a finite number, true, false or null',
|
|
330
|
+
},
|
|
331
|
+
];
|
|
332
|
+
}
|
|
217
333
|
return Object.keys(value).flatMap(key => key === '__proto__'
|
|
218
|
-
? [
|
|
334
|
+
? [
|
|
335
|
+
{
|
|
336
|
+
path: configPath([...segments, key], file),
|
|
337
|
+
message: 'is not allowed as a key: it can replace the prototype of an object',
|
|
338
|
+
},
|
|
339
|
+
]
|
|
219
340
|
: valueIssues(value[key], [...segments, key], file, depth + 1, budget));
|
|
220
341
|
}
|
|
221
342
|
/** The name a message gives what a config threw. Reading it can run the config's code too, so nothing it throws gets out. */
|
|
@@ -224,7 +345,9 @@ function thrownName(error) {
|
|
|
224
345
|
if (typeof error !== 'object' || error === null)
|
|
225
346
|
return 'a value that is not an error';
|
|
226
347
|
const { name } = error;
|
|
227
|
-
return typeof name === 'string' && ERROR_NAME.test(name)
|
|
348
|
+
return typeof name === 'string' && ERROR_NAME.test(name)
|
|
349
|
+
? name
|
|
350
|
+
: 'an error';
|
|
228
351
|
}
|
|
229
352
|
catch {
|
|
230
353
|
return 'an error';
|
|
@@ -260,7 +383,13 @@ function nameProviders(config) {
|
|
|
260
383
|
const providers = config.providers;
|
|
261
384
|
if (typeof providers !== 'object' || providers === null)
|
|
262
385
|
return config;
|
|
263
|
-
return {
|
|
386
|
+
return {
|
|
387
|
+
...config,
|
|
388
|
+
providers: Object.fromEntries(Object.entries(providers).map(([name, entry]) => [
|
|
389
|
+
name,
|
|
390
|
+
nameSnapshot(name, entry),
|
|
391
|
+
])),
|
|
392
|
+
};
|
|
264
393
|
}
|
|
265
394
|
/**
|
|
266
395
|
* The plain object a config's code hands over, checked by `schema`: `read` returns it, then it must be a
|
|
@@ -279,9 +408,19 @@ export function checkCodeValue(schema, read, words) {
|
|
|
279
408
|
let checked;
|
|
280
409
|
try {
|
|
281
410
|
const value = read();
|
|
282
|
-
const issues = isPlainObject(value)
|
|
283
|
-
|
|
284
|
-
|
|
411
|
+
const issues = isPlainObject(value)
|
|
412
|
+
? dataIssues(value, words.file)
|
|
413
|
+
: [
|
|
414
|
+
{ path: at, message: words.notAnObject },
|
|
415
|
+
];
|
|
416
|
+
const result = issues.length > 0
|
|
417
|
+
? { issues }
|
|
418
|
+
: checkConfig(schema, value, words.file);
|
|
419
|
+
checked = 'issues' in result
|
|
420
|
+
? result
|
|
421
|
+
: {
|
|
422
|
+
config: nameProviders(result.config),
|
|
423
|
+
};
|
|
285
424
|
}
|
|
286
425
|
catch (error) {
|
|
287
426
|
fail(at, `${words.threw} (${thrownName(error)})`);
|
|
@@ -345,15 +484,29 @@ async function readPromptFiles(config, directory, path) {
|
|
|
345
484
|
const prompt = prompts[stage];
|
|
346
485
|
if (typeof prompt !== 'object')
|
|
347
486
|
continue;
|
|
348
|
-
const at = configPath([
|
|
487
|
+
const at = configPath([
|
|
488
|
+
'profiles',
|
|
489
|
+
id,
|
|
490
|
+
'prompts',
|
|
491
|
+
stage,
|
|
492
|
+
'file',
|
|
493
|
+
], path);
|
|
349
494
|
const absolute = resolve(directory, prompt.file);
|
|
350
495
|
let text = reads.get(absolute);
|
|
351
496
|
if (text === undefined) {
|
|
352
497
|
const bytes = await readBounded(absolute, PROMPT_LIMIT, '64 KiB');
|
|
353
|
-
total += 'problem' in bytes
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
498
|
+
total += 'problem' in bytes
|
|
499
|
+
? bytes.counted ?? 0
|
|
500
|
+
: bytes.value.length;
|
|
501
|
+
if (total > PROMPT_TOTAL_LIMIT) {
|
|
502
|
+
throw new ConfigError([
|
|
503
|
+
...issues,
|
|
504
|
+
{ path: at, message: 'takes the prompt files over 1 MiB in total' },
|
|
505
|
+
]);
|
|
506
|
+
}
|
|
507
|
+
text = 'problem' in bytes
|
|
508
|
+
? bytes
|
|
509
|
+
: decode(bytes.value);
|
|
357
510
|
reads.set(absolute, text);
|
|
358
511
|
}
|
|
359
512
|
if ('problem' in text)
|
|
@@ -388,7 +541,11 @@ export async function readConfigFile(path, options = {}) {
|
|
|
388
541
|
const text = await readText(source, CONFIG_LIMIT, '1 MiB');
|
|
389
542
|
if ('problem' in text)
|
|
390
543
|
fail(path, text.problem);
|
|
391
|
-
const config = format === 'code'
|
|
544
|
+
const config = format === 'code'
|
|
545
|
+
? await loadCode(source, path)
|
|
546
|
+
: checkData(format === 'yaml'
|
|
547
|
+
? parseYaml(text.value)
|
|
548
|
+
: parseJson(text.value), path);
|
|
392
549
|
return { config: await readPromptFiles(config, dirname(source), path), source };
|
|
393
550
|
}
|
|
394
551
|
/**
|
|
@@ -411,7 +568,9 @@ export async function loadConfig(options = {}) {
|
|
|
411
568
|
if (named !== undefined && !isAbsolute(named))
|
|
412
569
|
fail('QUORUM_CONFIG', 'must be an absolute path');
|
|
413
570
|
const path = options.configPath ?? named;
|
|
414
|
-
const loaded = path === undefined
|
|
571
|
+
const loaded = path === undefined
|
|
572
|
+
? undefined
|
|
573
|
+
: await readConfigFile(path, { cwd: options.cwd });
|
|
415
574
|
const config = resolveConfig(loaded?.config ?? {}, { env, selection: options.selection });
|
|
416
575
|
return { config, source: loaded?.source, warnings: config.warnings };
|
|
417
576
|
}
|
package/dist/config/profiles.js
CHANGED
|
@@ -4,31 +4,53 @@ import { profileIssues } from "../core/profile.js";
|
|
|
4
4
|
import { securityProfile } from "../profiles/security.js";
|
|
5
5
|
import { unknownName } from "./schema.js";
|
|
6
6
|
/** The built-in profiles a config can run or extend, by id. */
|
|
7
|
-
const BUILT_IN = new Map([
|
|
7
|
+
const BUILT_IN = new Map([
|
|
8
|
+
[securityProfile.id, securityProfile],
|
|
9
|
+
]);
|
|
8
10
|
const NEEDS_BASE = 'is required: the profile extends no built-in profile';
|
|
9
11
|
const LEVELS = ['high', 'medium', 'low'];
|
|
10
12
|
/** A field a record holds itself: a prototype, a polluted one included, fills none. */
|
|
11
13
|
export function own(record, key) {
|
|
12
|
-
return record !== undefined && Object.hasOwn(record, key)
|
|
14
|
+
return record !== undefined && Object.hasOwn(record, key)
|
|
15
|
+
? record[key]
|
|
16
|
+
: undefined;
|
|
13
17
|
}
|
|
14
18
|
/** A rule as a new frozen value: the config's own objects stay out of a frozen profile. */
|
|
15
19
|
function copyRule(rule) {
|
|
16
|
-
return typeof rule === 'object'
|
|
20
|
+
return typeof rule === 'object'
|
|
21
|
+
? Object.freeze({ ...rule })
|
|
22
|
+
: rule;
|
|
17
23
|
}
|
|
18
24
|
/** The base's policy, else the default one, with the levels the entry sets (not `undefined`) over it. */
|
|
19
25
|
function policyOf(base, entry) {
|
|
20
26
|
const set = Object.fromEntries(LEVELS.flatMap((level) => {
|
|
21
27
|
const rule = own(entry, level);
|
|
22
|
-
return rule === undefined
|
|
28
|
+
return rule === undefined
|
|
29
|
+
? []
|
|
30
|
+
: [
|
|
31
|
+
[level, rule],
|
|
32
|
+
];
|
|
23
33
|
}));
|
|
24
|
-
const merged = {
|
|
25
|
-
|
|
34
|
+
const merged = {
|
|
35
|
+
...base?.policy ?? defaultPolicy,
|
|
36
|
+
...set,
|
|
37
|
+
};
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
high: copyRule(merged.high),
|
|
40
|
+
medium: copyRule(merged.medium),
|
|
41
|
+
low: copyRule(merged.low),
|
|
42
|
+
});
|
|
26
43
|
}
|
|
27
44
|
/** The lenses of the entry, else of the base: the fields the check reads, each read once, whatever the lens holds besides. */
|
|
28
45
|
function lensesOf(entry, base) {
|
|
29
46
|
// `profileIssues` refuses a lens whose id or question is not a string, so the casts hide nothing.
|
|
30
|
-
if (entry !== undefined)
|
|
31
|
-
return entry.map(lens => ({
|
|
47
|
+
if (entry !== undefined) {
|
|
48
|
+
return entry.map(lens => ({
|
|
49
|
+
id: own(lens, 'id'),
|
|
50
|
+
question: own(lens, 'question'),
|
|
51
|
+
provider: own(lens, 'provider'),
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
32
54
|
return base?.lenses.map(({ id, question }) => ({ id, question, provider: undefined }));
|
|
33
55
|
}
|
|
34
56
|
/** What one profile of the config resolves to, or every issue that keeps it from running. */
|
|
@@ -40,8 +62,17 @@ function resolveEntry(id, entry, { roles, providers, known }) {
|
|
|
40
62
|
const vote = own(entryPrompts, 'vote') ?? base?.prompts.vote;
|
|
41
63
|
const lenses = lensesOf(own(entry, 'lenses'), base);
|
|
42
64
|
if (research === undefined || vote === undefined || lenses === undefined) {
|
|
43
|
-
const needed = [
|
|
44
|
-
|
|
65
|
+
const needed = [
|
|
66
|
+
[research, 'prompts', 'research'],
|
|
67
|
+
[vote, 'prompts', 'vote'],
|
|
68
|
+
[lenses, 'lenses'],
|
|
69
|
+
];
|
|
70
|
+
return {
|
|
71
|
+
issues: needed.filter(([value]) => value === undefined).map(([, ...segments]) => ({
|
|
72
|
+
path: at(...segments),
|
|
73
|
+
message: NEEDS_BASE,
|
|
74
|
+
})),
|
|
75
|
+
};
|
|
45
76
|
}
|
|
46
77
|
const profile = Object.freeze({
|
|
47
78
|
id,
|
|
@@ -54,9 +85,18 @@ function resolveEntry(id, entry, { roles, providers, known }) {
|
|
|
54
85
|
const issues = profileIssues(profile, id).map(issue => ({ path: `${at()}${issue.path.slice(id.length)}`, message: issue.message }));
|
|
55
86
|
const entryRoles = own(entry, 'roles');
|
|
56
87
|
const references = [
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
88
|
+
{
|
|
89
|
+
path: at('roles', 'research'),
|
|
90
|
+
name: own(entryRoles, 'research'),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
path: at('roles', 'voter'),
|
|
94
|
+
name: own(entryRoles, 'voter'),
|
|
95
|
+
},
|
|
96
|
+
...lenses.map((lens, index) => ({
|
|
97
|
+
path: at('lenses', index, 'provider'),
|
|
98
|
+
name: lens.provider,
|
|
99
|
+
})),
|
|
60
100
|
];
|
|
61
101
|
for (const { path, name } of references) {
|
|
62
102
|
if (name !== undefined && !known.has(name))
|
|
@@ -87,11 +127,33 @@ function resolveEntry(id, entry, { roles, providers, known }) {
|
|
|
87
127
|
*/
|
|
88
128
|
export function resolveProfiles(inputs) {
|
|
89
129
|
const configured = new Map(Object.entries(inputs.profiles ?? {}));
|
|
90
|
-
const selected = inputs.selection?.ids ?? (inputs.profiles === undefined
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
130
|
+
const selected = inputs.selection?.ids ?? (inputs.profiles === undefined
|
|
131
|
+
? [securityProfile.id]
|
|
132
|
+
: [
|
|
133
|
+
...configured.keys(),
|
|
134
|
+
]);
|
|
135
|
+
const bindings = {
|
|
136
|
+
roles: inputs.roles,
|
|
137
|
+
providers: inputs.providers,
|
|
138
|
+
known: new Set(inputs.providers),
|
|
139
|
+
};
|
|
140
|
+
const defined = [
|
|
141
|
+
...configured.keys(),
|
|
142
|
+
...[
|
|
143
|
+
...BUILT_IN.keys(),
|
|
144
|
+
].filter(id => !configured.has(id)),
|
|
145
|
+
];
|
|
146
|
+
const issues = selected.length > 0
|
|
147
|
+
? []
|
|
148
|
+
: [
|
|
149
|
+
inputs.selection === undefined
|
|
150
|
+
? { path: 'profiles', message: 'must hold at least one profile, or be left out' }
|
|
151
|
+
: { path: inputs.selection.path, message: 'must name at least one profile' },
|
|
152
|
+
];
|
|
153
|
+
const resolutions = new Map([...configured].map(([id, entry]) => [
|
|
154
|
+
id,
|
|
155
|
+
resolveEntry(id, entry, bindings),
|
|
156
|
+
]));
|
|
95
157
|
for (const id of selected) {
|
|
96
158
|
if (resolutions.has(id))
|
|
97
159
|
continue;
|
|
@@ -100,6 +162,11 @@ export function resolveProfiles(inputs) {
|
|
|
100
162
|
else
|
|
101
163
|
issues.push(unknownName(inputs.selection?.path ?? 'profiles', 'profile', id, defined));
|
|
102
164
|
}
|
|
103
|
-
issues.push(...[
|
|
104
|
-
|
|
165
|
+
issues.push(...[
|
|
166
|
+
...resolutions.values(),
|
|
167
|
+
].flatMap(resolution => resolution.issues));
|
|
168
|
+
return {
|
|
169
|
+
profiles: selected.flatMap(id => resolutions.get(id)?.resolved ?? []),
|
|
170
|
+
issues,
|
|
171
|
+
};
|
|
105
172
|
}
|