@tobi-or-not/quorum 0.1.0 → 0.2.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 +4 -0
- package/dist/cli/bin.js +9 -1
- package/dist/cli/main.js +49 -12
- package/dist/cli/print-config.js +38 -9
- package/dist/cli/render.js +18 -6
- 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.js +163 -37
- 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.js +65 -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.js +20 -5
- package/dist/core/quorum.js +128 -33
- package/dist/core/sanitize.js +3 -1
- 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 +5 -4
package/dist/config/load.js
CHANGED
|
@@ -26,12 +26,22 @@ 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
|
+
]);
|
|
35
45
|
}
|
|
36
46
|
/**
|
|
37
47
|
* The bytes of a regular file of at most `limit` bytes. The file is opened without blocking, so a FIFO
|
|
@@ -45,7 +55,13 @@ async function readBounded(absolute, limit, size) {
|
|
|
45
55
|
}
|
|
46
56
|
catch (error) {
|
|
47
57
|
const code = error.code;
|
|
48
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
problem: code === 'ENOENT' || code === 'ENOTDIR'
|
|
60
|
+
? 'does not exist'
|
|
61
|
+
: code === 'EISDIR'
|
|
62
|
+
? 'is not a file'
|
|
63
|
+
: 'cannot be read',
|
|
64
|
+
};
|
|
49
65
|
}
|
|
50
66
|
try {
|
|
51
67
|
const stats = await handle.stat();
|
|
@@ -56,7 +72,11 @@ async function readBounded(absolute, limit, size) {
|
|
|
56
72
|
for (let read = -1; read !== 0 && length < buffer.length; length += read) {
|
|
57
73
|
read = (await handle.read(buffer, length, buffer.length - length, length)).bytesRead;
|
|
58
74
|
}
|
|
59
|
-
return length > limit
|
|
75
|
+
return length > limit
|
|
76
|
+
? { problem: `is over ${size}`, counted: limit }
|
|
77
|
+
: {
|
|
78
|
+
value: buffer.subarray(0, length),
|
|
79
|
+
};
|
|
60
80
|
}
|
|
61
81
|
catch {
|
|
62
82
|
return { problem: 'cannot be read' };
|
|
@@ -68,7 +88,9 @@ async function readBounded(absolute, limit, size) {
|
|
|
68
88
|
/** The UTF-8 text of `bytes`, a leading byte-order mark dropped (the decoder's default). */
|
|
69
89
|
function decode(bytes) {
|
|
70
90
|
try {
|
|
71
|
-
return {
|
|
91
|
+
return {
|
|
92
|
+
value: new TextDecoder('utf-8', { fatal: true }).decode(bytes),
|
|
93
|
+
};
|
|
72
94
|
}
|
|
73
95
|
catch {
|
|
74
96
|
return { problem: 'is not UTF-8 text' };
|
|
@@ -77,7 +99,9 @@ function decode(bytes) {
|
|
|
77
99
|
/** The UTF-8 text of a regular file of at most `limit` bytes. */
|
|
78
100
|
async function readText(absolute, limit, size) {
|
|
79
101
|
const bytes = await readBounded(absolute, limit, size);
|
|
80
|
-
return 'problem' in bytes
|
|
102
|
+
return 'problem' in bytes
|
|
103
|
+
? bytes
|
|
104
|
+
: decode(bytes.value);
|
|
81
105
|
}
|
|
82
106
|
/** Where `offset` sits in the text, as a line and a column. */
|
|
83
107
|
function position(lines, offset) {
|
|
@@ -100,7 +124,9 @@ function yamlProblem(error, lines) {
|
|
|
100
124
|
* `MAX_DEPTH` keys deep: `dataIssues` refuses that data whatever the walk finds there.
|
|
101
125
|
*/
|
|
102
126
|
function repeatedKeyAt(doc) {
|
|
103
|
-
const stack = [
|
|
127
|
+
const stack = [
|
|
128
|
+
{ node: doc.contents, depth: 0 },
|
|
129
|
+
];
|
|
104
130
|
for (let entry = stack.pop(); entry !== undefined; entry = stack.pop()) {
|
|
105
131
|
const { node, depth } = entry;
|
|
106
132
|
if (depth > MAX_DEPTH)
|
|
@@ -112,9 +138,14 @@ function repeatedKeyAt(doc) {
|
|
|
112
138
|
if (isMap(node)) {
|
|
113
139
|
const seen = new Set();
|
|
114
140
|
for (const { key } of node.items) {
|
|
115
|
-
const value = isScalar(key)
|
|
116
|
-
|
|
117
|
-
|
|
141
|
+
const value = isScalar(key)
|
|
142
|
+
? key.value
|
|
143
|
+
: key;
|
|
144
|
+
if (seen.has(value)) {
|
|
145
|
+
return (isScalar(key)
|
|
146
|
+
? key.range?.[0]
|
|
147
|
+
: undefined) ?? 0;
|
|
148
|
+
}
|
|
118
149
|
seen.add(value);
|
|
119
150
|
}
|
|
120
151
|
}
|
|
@@ -133,19 +164,39 @@ function repeatedKeyAt(doc) {
|
|
|
133
164
|
function parseYaml(text) {
|
|
134
165
|
const lines = new LineCounter();
|
|
135
166
|
try {
|
|
136
|
-
const doc = parseDocument(text, {
|
|
167
|
+
const doc = parseDocument(text, {
|
|
168
|
+
schema: 'core',
|
|
169
|
+
version: '1.2',
|
|
170
|
+
merge: false,
|
|
171
|
+
resolveKnownTags: false,
|
|
172
|
+
uniqueKeys: false,
|
|
173
|
+
stringKeys: true,
|
|
174
|
+
prettyErrors: false,
|
|
175
|
+
logLevel: 'error',
|
|
176
|
+
strict: true,
|
|
177
|
+
lineCounter: lines,
|
|
178
|
+
});
|
|
137
179
|
const first = doc.errors[0] ?? doc.warnings[0];
|
|
138
|
-
if (first !== undefined)
|
|
139
|
-
return {
|
|
180
|
+
if (first !== undefined) {
|
|
181
|
+
return {
|
|
182
|
+
problem: yamlProblem(first, lines),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
140
185
|
const repeated = repeatedKeyAt(doc);
|
|
141
186
|
if (repeated !== undefined)
|
|
142
187
|
return { problem: `is not valid YAML at ${position(lines, repeated)} (DUPLICATE_KEY)` };
|
|
143
188
|
const value = doc.toJS({ maxAliasCount: 0 });
|
|
144
|
-
return value === null
|
|
189
|
+
return value === null
|
|
190
|
+
? { problem: 'is empty' }
|
|
191
|
+
: { value };
|
|
145
192
|
}
|
|
146
193
|
catch (error) {
|
|
147
194
|
// An alias throws a ReferenceError once aliases are disabled; deep nesting can throw a RangeError.
|
|
148
|
-
return {
|
|
195
|
+
return {
|
|
196
|
+
problem: error instanceof ReferenceError
|
|
197
|
+
? 'uses an alias, which quorum does not read'
|
|
198
|
+
: 'is not valid YAML',
|
|
199
|
+
};
|
|
149
200
|
}
|
|
150
201
|
}
|
|
151
202
|
/**
|
|
@@ -165,12 +216,20 @@ function parseJson(text) {
|
|
|
165
216
|
}
|
|
166
217
|
const lines = new LineCounter();
|
|
167
218
|
try {
|
|
168
|
-
const doc = parseDocument(text, {
|
|
219
|
+
const doc = parseDocument(text, {
|
|
220
|
+
schema: 'json',
|
|
221
|
+
uniqueKeys: false,
|
|
222
|
+
prettyErrors: false,
|
|
223
|
+
logLevel: 'error',
|
|
224
|
+
lineCounter: lines,
|
|
225
|
+
});
|
|
169
226
|
const first = doc.errors[0];
|
|
170
227
|
if (first !== undefined)
|
|
171
228
|
return { problem: `is not valid JSON at ${position(lines, first.pos[0])} (${first.code})` };
|
|
172
229
|
const repeated = repeatedKeyAt(doc);
|
|
173
|
-
return repeated === undefined
|
|
230
|
+
return repeated === undefined
|
|
231
|
+
? { value }
|
|
232
|
+
: { problem: `has a duplicate key at ${position(lines, repeated)}` };
|
|
174
233
|
}
|
|
175
234
|
catch {
|
|
176
235
|
return { problem: 'is not valid JSON' };
|
|
@@ -197,25 +256,54 @@ function isPlainObject(value) {
|
|
|
197
256
|
function dataIssues(value, file) {
|
|
198
257
|
const budget = { left: MAX_VALUES };
|
|
199
258
|
const issues = valueIssues(value, [], file, 0, budget);
|
|
200
|
-
return budget.left < 0
|
|
259
|
+
return budget.left < 0
|
|
260
|
+
? [
|
|
261
|
+
{ path: file ?? 'config', message: `holds more than ${MAX_VALUES} values` },
|
|
262
|
+
]
|
|
263
|
+
: issues;
|
|
201
264
|
}
|
|
202
265
|
function valueIssues(value, segments, file, depth, budget) {
|
|
203
266
|
if (--budget.left < 0)
|
|
204
267
|
return [];
|
|
205
|
-
if (depth > MAX_DEPTH)
|
|
206
|
-
return [
|
|
268
|
+
if (depth > MAX_DEPTH) {
|
|
269
|
+
return [
|
|
270
|
+
{
|
|
271
|
+
path: configPath(segments, file),
|
|
272
|
+
message: `is nested more than ${MAX_DEPTH} keys deep`,
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
}
|
|
207
276
|
if (value === null || value === undefined || typeof value === 'string' || typeof value === 'boolean')
|
|
208
277
|
return [];
|
|
209
|
-
if (typeof value === 'number')
|
|
210
|
-
return Number.isFinite(value)
|
|
278
|
+
if (typeof value === 'number') {
|
|
279
|
+
return Number.isFinite(value)
|
|
280
|
+
? []
|
|
281
|
+
: [
|
|
282
|
+
{
|
|
283
|
+
path: configPath(segments, file),
|
|
284
|
+
message: 'must be a finite number',
|
|
285
|
+
},
|
|
286
|
+
];
|
|
287
|
+
}
|
|
211
288
|
if (isProvider(value))
|
|
212
289
|
return [];
|
|
213
290
|
if (Array.isArray(value))
|
|
214
291
|
return value.flatMap((item, index) => valueIssues(item, [...segments, index], file, depth + 1, budget));
|
|
215
|
-
if (!isPlainObject(value))
|
|
216
|
-
return [
|
|
292
|
+
if (!isPlainObject(value)) {
|
|
293
|
+
return [
|
|
294
|
+
{
|
|
295
|
+
path: configPath(segments, file),
|
|
296
|
+
message: 'must be plain data: an object, an array, a string, a finite number, true, false or null',
|
|
297
|
+
},
|
|
298
|
+
];
|
|
299
|
+
}
|
|
217
300
|
return Object.keys(value).flatMap(key => key === '__proto__'
|
|
218
|
-
? [
|
|
301
|
+
? [
|
|
302
|
+
{
|
|
303
|
+
path: configPath([...segments, key], file),
|
|
304
|
+
message: 'is not allowed as a key: it can replace the prototype of an object',
|
|
305
|
+
},
|
|
306
|
+
]
|
|
219
307
|
: valueIssues(value[key], [...segments, key], file, depth + 1, budget));
|
|
220
308
|
}
|
|
221
309
|
/** 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 +312,9 @@ function thrownName(error) {
|
|
|
224
312
|
if (typeof error !== 'object' || error === null)
|
|
225
313
|
return 'a value that is not an error';
|
|
226
314
|
const { name } = error;
|
|
227
|
-
return typeof name === 'string' && ERROR_NAME.test(name)
|
|
315
|
+
return typeof name === 'string' && ERROR_NAME.test(name)
|
|
316
|
+
? name
|
|
317
|
+
: 'an error';
|
|
228
318
|
}
|
|
229
319
|
catch {
|
|
230
320
|
return 'an error';
|
|
@@ -260,7 +350,13 @@ function nameProviders(config) {
|
|
|
260
350
|
const providers = config.providers;
|
|
261
351
|
if (typeof providers !== 'object' || providers === null)
|
|
262
352
|
return config;
|
|
263
|
-
return {
|
|
353
|
+
return {
|
|
354
|
+
...config,
|
|
355
|
+
providers: Object.fromEntries(Object.entries(providers).map(([name, entry]) => [
|
|
356
|
+
name,
|
|
357
|
+
nameSnapshot(name, entry),
|
|
358
|
+
])),
|
|
359
|
+
};
|
|
264
360
|
}
|
|
265
361
|
/**
|
|
266
362
|
* The plain object a config's code hands over, checked by `schema`: `read` returns it, then it must be a
|
|
@@ -279,9 +375,19 @@ export function checkCodeValue(schema, read, words) {
|
|
|
279
375
|
let checked;
|
|
280
376
|
try {
|
|
281
377
|
const value = read();
|
|
282
|
-
const issues = isPlainObject(value)
|
|
283
|
-
|
|
284
|
-
|
|
378
|
+
const issues = isPlainObject(value)
|
|
379
|
+
? dataIssues(value, words.file)
|
|
380
|
+
: [
|
|
381
|
+
{ path: at, message: words.notAnObject },
|
|
382
|
+
];
|
|
383
|
+
const result = issues.length > 0
|
|
384
|
+
? { issues }
|
|
385
|
+
: checkConfig(schema, value, words.file);
|
|
386
|
+
checked = 'issues' in result
|
|
387
|
+
? result
|
|
388
|
+
: {
|
|
389
|
+
config: nameProviders(result.config),
|
|
390
|
+
};
|
|
285
391
|
}
|
|
286
392
|
catch (error) {
|
|
287
393
|
fail(at, `${words.threw} (${thrownName(error)})`);
|
|
@@ -345,15 +451,29 @@ async function readPromptFiles(config, directory, path) {
|
|
|
345
451
|
const prompt = prompts[stage];
|
|
346
452
|
if (typeof prompt !== 'object')
|
|
347
453
|
continue;
|
|
348
|
-
const at = configPath([
|
|
454
|
+
const at = configPath([
|
|
455
|
+
'profiles',
|
|
456
|
+
id,
|
|
457
|
+
'prompts',
|
|
458
|
+
stage,
|
|
459
|
+
'file',
|
|
460
|
+
], path);
|
|
349
461
|
const absolute = resolve(directory, prompt.file);
|
|
350
462
|
let text = reads.get(absolute);
|
|
351
463
|
if (text === undefined) {
|
|
352
464
|
const bytes = await readBounded(absolute, PROMPT_LIMIT, '64 KiB');
|
|
353
|
-
total += 'problem' in bytes
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
465
|
+
total += 'problem' in bytes
|
|
466
|
+
? bytes.counted ?? 0
|
|
467
|
+
: bytes.value.length;
|
|
468
|
+
if (total > PROMPT_TOTAL_LIMIT) {
|
|
469
|
+
throw new ConfigError([
|
|
470
|
+
...issues,
|
|
471
|
+
{ path: at, message: 'takes the prompt files over 1 MiB in total' },
|
|
472
|
+
]);
|
|
473
|
+
}
|
|
474
|
+
text = 'problem' in bytes
|
|
475
|
+
? bytes
|
|
476
|
+
: decode(bytes.value);
|
|
357
477
|
reads.set(absolute, text);
|
|
358
478
|
}
|
|
359
479
|
if ('problem' in text)
|
|
@@ -388,7 +508,11 @@ export async function readConfigFile(path, options = {}) {
|
|
|
388
508
|
const text = await readText(source, CONFIG_LIMIT, '1 MiB');
|
|
389
509
|
if ('problem' in text)
|
|
390
510
|
fail(path, text.problem);
|
|
391
|
-
const config = format === 'code'
|
|
511
|
+
const config = format === 'code'
|
|
512
|
+
? await loadCode(source, path)
|
|
513
|
+
: checkData(format === 'yaml'
|
|
514
|
+
? parseYaml(text.value)
|
|
515
|
+
: parseJson(text.value), path);
|
|
392
516
|
return { config: await readPromptFiles(config, dirname(source), path), source };
|
|
393
517
|
}
|
|
394
518
|
/**
|
|
@@ -411,7 +535,9 @@ export async function loadConfig(options = {}) {
|
|
|
411
535
|
if (named !== undefined && !isAbsolute(named))
|
|
412
536
|
fail('QUORUM_CONFIG', 'must be an absolute path');
|
|
413
537
|
const path = options.configPath ?? named;
|
|
414
|
-
const loaded = path === undefined
|
|
538
|
+
const loaded = path === undefined
|
|
539
|
+
? undefined
|
|
540
|
+
: await readConfigFile(path, { cwd: options.cwd });
|
|
415
541
|
const config = resolveConfig(loaded?.config ?? {}, { env, selection: options.selection });
|
|
416
542
|
return { config, source: loaded?.source, warnings: config.warnings };
|
|
417
543
|
}
|
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
|
}
|