@fro.bot/systematic 3.30.0 → 3.31.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/HARNESSES.md +4 -4
- package/dist/cli.d.ts +13 -9
- package/dist/cli.js +140 -31
- package/dist/{index-jvpbpj9z.js → index-a5jd8n2y.js} +2432 -1698
- package/dist/index.js +1 -1
- package/dist/lib/config-schema.d.ts +2 -0
- package/dist/lib/config.d.ts +29 -9
- package/dist/lib/search-corpus.d.ts +40 -0
- package/dist/lib/search-exclude.d.ts +84 -0
- package/dist/lib/search-external-deciduous.d.ts +9 -2
- package/dist/lib/search-external-sources.d.ts +102 -3
- package/dist/lib/search-external.d.ts +2 -1
- package/dist/lib/search-user-config.d.ts +186 -13
- package/dist/pi.js +869 -248
- package/package.json +3 -2
package/dist/pi.js
CHANGED
|
@@ -3418,24 +3418,32 @@ function listDirectoryBounded(target, limit) {
|
|
|
3418
3418
|
} catch {}
|
|
3419
3419
|
}
|
|
3420
3420
|
}
|
|
3421
|
-
function
|
|
3421
|
+
function walkToGitRoot(startDir) {
|
|
3422
3422
|
const resolved = path2.resolve(startDir);
|
|
3423
3423
|
const start = safeRealpath(resolved) ?? resolved;
|
|
3424
3424
|
let current = start;
|
|
3425
3425
|
while (true) {
|
|
3426
3426
|
try {
|
|
3427
3427
|
if (fs3.lstatSync(path2.join(current, ".git"), { throwIfNoEntry: false })) {
|
|
3428
|
-
return current;
|
|
3428
|
+
return { gitRoot: current, start };
|
|
3429
3429
|
}
|
|
3430
3430
|
} catch {
|
|
3431
|
-
return start;
|
|
3431
|
+
return { gitRoot: null, start };
|
|
3432
3432
|
}
|
|
3433
3433
|
const parent = path2.dirname(current);
|
|
3434
3434
|
if (parent === current)
|
|
3435
|
-
return start;
|
|
3435
|
+
return { gitRoot: null, start };
|
|
3436
3436
|
current = parent;
|
|
3437
3437
|
}
|
|
3438
3438
|
}
|
|
3439
|
+
function resolveSearchRoot(startDir) {
|
|
3440
|
+
const { gitRoot, start } = walkToGitRoot(startDir);
|
|
3441
|
+
return gitRoot ?? start;
|
|
3442
|
+
}
|
|
3443
|
+
function lookupSearchRoot(startDir) {
|
|
3444
|
+
const { gitRoot } = walkToGitRoot(startDir);
|
|
3445
|
+
return gitRoot === null ? { root: startDir, foundGit: false } : { root: gitRoot, foundGit: true };
|
|
3446
|
+
}
|
|
3439
3447
|
function isInside(root, candidate) {
|
|
3440
3448
|
const relative = path2.relative(root, candidate);
|
|
3441
3449
|
return relative !== "" && relative !== ".." && !relative.startsWith(`..${path2.sep}`) && !path2.isAbsolute(relative);
|
|
@@ -3456,6 +3464,21 @@ function symlinkedComponent(container, target) {
|
|
|
3456
3464
|
}
|
|
3457
3465
|
return;
|
|
3458
3466
|
}
|
|
3467
|
+
var PROJECT_ROOT_REJECTION_REASONS = {
|
|
3468
|
+
root: "a project root is a symlink",
|
|
3469
|
+
ancestor: "a project root passes through a symlink",
|
|
3470
|
+
outside: "a project root resolves outside the project root"
|
|
3471
|
+
};
|
|
3472
|
+
function rejectedProjectRoot(checkoutRoot, root) {
|
|
3473
|
+
const symlinked = symlinkedComponent(checkoutRoot, root);
|
|
3474
|
+
if (symlinked !== undefined)
|
|
3475
|
+
return symlinked;
|
|
3476
|
+
const container = probeRealpath(checkoutRoot);
|
|
3477
|
+
const directory = probeRealpath(root);
|
|
3478
|
+
if (container.kind !== "ok" || directory.kind !== "ok")
|
|
3479
|
+
return;
|
|
3480
|
+
return isInside(container.value, directory.value) ? undefined : "outside";
|
|
3481
|
+
}
|
|
3459
3482
|
function classifyEntry(spec, name, stat) {
|
|
3460
3483
|
if (stat === null || stat.isSymbolicLink())
|
|
3461
3484
|
return "ignored";
|
|
@@ -3484,6 +3507,13 @@ function listWalkedDirectory(budget, label, directory, prefix, warnings) {
|
|
|
3484
3507
|
}
|
|
3485
3508
|
return listing.names;
|
|
3486
3509
|
}
|
|
3510
|
+
function addCandidate(found, candidate) {
|
|
3511
|
+
if (found.candidates.length >= MAX_DISCOVERED_FILES) {
|
|
3512
|
+
found.truncated = true;
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
found.candidates.push(candidate);
|
|
3516
|
+
}
|
|
3487
3517
|
function discoverFiles(spec, label, directory, prefix, depth, found, warnings) {
|
|
3488
3518
|
const names = listWalkedDirectory(found.budget, label, directory, prefix, warnings);
|
|
3489
3519
|
if (names === null) {
|
|
@@ -3495,6 +3525,8 @@ function discoverFiles(spec, label, directory, prefix, depth, found, warnings) {
|
|
|
3495
3525
|
for (const name of names) {
|
|
3496
3526
|
if (found.truncated)
|
|
3497
3527
|
return;
|
|
3528
|
+
if (found.isExcluded?.(`${prefix}${name}`) === true)
|
|
3529
|
+
continue;
|
|
3498
3530
|
const absolute = path2.join(directory, name);
|
|
3499
3531
|
const stat = safeLstat(absolute);
|
|
3500
3532
|
const entryKind = classifyEntry(spec, name, stat);
|
|
@@ -3502,11 +3534,7 @@ function discoverFiles(spec, label, directory, prefix, depth, found, warnings) {
|
|
|
3502
3534
|
const child = `${prefix}${name}/`;
|
|
3503
3535
|
discoverFiles(spec, label, absolute, child, depth + 1, found, warnings);
|
|
3504
3536
|
} else if (entryKind === "file" && stat !== null) {
|
|
3505
|
-
|
|
3506
|
-
found.truncated = true;
|
|
3507
|
-
return;
|
|
3508
|
-
}
|
|
3509
|
-
found.candidates.push({
|
|
3537
|
+
addCandidate(found, {
|
|
3510
3538
|
relative: `${prefix}${name}`,
|
|
3511
3539
|
absolute,
|
|
3512
3540
|
size: stat.size
|
|
@@ -3584,7 +3612,7 @@ function parseCorpusDocument(kind, relativePath, content) {
|
|
|
3584
3612
|
};
|
|
3585
3613
|
}
|
|
3586
3614
|
function discoverSourceFiles(options, warnings) {
|
|
3587
|
-
const { directory, containedIn, walk, label, entryBudget } = options;
|
|
3615
|
+
const { directory, containedIn, walk, label, entryBudget, isExcluded } = options;
|
|
3588
3616
|
const directoryProbe = probeRealpath(directory);
|
|
3589
3617
|
const containerProbe = containedIn === undefined ? undefined : probeRealpath(containedIn);
|
|
3590
3618
|
if (containerProbe?.kind === "failed" || directoryProbe.kind === "failed") {
|
|
@@ -3611,7 +3639,8 @@ function discoverSourceFiles(options, warnings) {
|
|
|
3611
3639
|
candidates: [],
|
|
3612
3640
|
truncated: false,
|
|
3613
3641
|
rootUnreadable: false,
|
|
3614
|
-
budget: entryBudget
|
|
3642
|
+
budget: entryBudget,
|
|
3643
|
+
isExcluded
|
|
3615
3644
|
};
|
|
3616
3645
|
discoverFiles(walk, label, directoryReal, "", 0, found, warnings);
|
|
3617
3646
|
if (found.rootUnreadable) {
|
|
@@ -3745,6 +3774,183 @@ function loadCorpus(root, kind = "solution") {
|
|
|
3745
3774
|
// src/lib/search-external.ts
|
|
3746
3775
|
import path4 from "node:path";
|
|
3747
3776
|
|
|
3777
|
+
// src/lib/search-exclude.ts
|
|
3778
|
+
var MAX_EXCLUDE_PATTERNS = 64;
|
|
3779
|
+
var MAX_EXCLUDE_PATTERN_LENGTH = 256;
|
|
3780
|
+
var REASON_NOT_A_STRING = "not a string";
|
|
3781
|
+
var REASON_NOT_AN_ARRAY = "not an array";
|
|
3782
|
+
var REASON_EMPTY = "empty pattern";
|
|
3783
|
+
var REASON_TOO_LONG = `longer than ${MAX_EXCLUDE_PATTERN_LENGTH} characters`;
|
|
3784
|
+
var REASON_BACKSLASH = "backslash is not supported, use / between segments";
|
|
3785
|
+
var REASON_NEGATION = "negation with ! is not supported";
|
|
3786
|
+
var REASON_LEADING_SLASH = "starts with /, patterns are relative to the source root";
|
|
3787
|
+
var REASON_LEADING_DOT_SLASH = "starts with ./, write the path without it";
|
|
3788
|
+
var REASON_CHARACTER_CLASS = "character classes with [ ] are not supported";
|
|
3789
|
+
var REASON_EMPTY_SEGMENT = "contains an empty path segment";
|
|
3790
|
+
var REASON_DOT_SEGMENT = "contains a . path segment";
|
|
3791
|
+
var REASON_DOT_DOT_SEGMENT = "contains a .. path segment";
|
|
3792
|
+
var REASON_EMBEDDED_GLOBSTAR = "** must be a whole path segment";
|
|
3793
|
+
var GLOBSTAR = "**";
|
|
3794
|
+
function invalid(reason) {
|
|
3795
|
+
return { ok: false, reason };
|
|
3796
|
+
}
|
|
3797
|
+
var WHOLE_PATTERN_RULES = [
|
|
3798
|
+
[(pattern) => pattern.length === 0, REASON_EMPTY],
|
|
3799
|
+
[(pattern) => pattern.length > MAX_EXCLUDE_PATTERN_LENGTH, REASON_TOO_LONG],
|
|
3800
|
+
[(pattern) => pattern.includes("\\"), REASON_BACKSLASH],
|
|
3801
|
+
[(pattern) => pattern.startsWith("!"), REASON_NEGATION],
|
|
3802
|
+
[(pattern) => pattern.startsWith("/"), REASON_LEADING_SLASH],
|
|
3803
|
+
[(pattern) => pattern.startsWith("./"), REASON_LEADING_DOT_SLASH],
|
|
3804
|
+
[
|
|
3805
|
+
(pattern) => pattern.includes("[") || pattern.includes("]"),
|
|
3806
|
+
REASON_CHARACTER_CLASS
|
|
3807
|
+
]
|
|
3808
|
+
];
|
|
3809
|
+
function segmentProblem(segment) {
|
|
3810
|
+
if (segment.length === 0)
|
|
3811
|
+
return REASON_EMPTY_SEGMENT;
|
|
3812
|
+
if (segment === ".")
|
|
3813
|
+
return REASON_DOT_SEGMENT;
|
|
3814
|
+
if (segment === "..")
|
|
3815
|
+
return REASON_DOT_DOT_SEGMENT;
|
|
3816
|
+
if (segment !== GLOBSTAR && segment.includes(GLOBSTAR)) {
|
|
3817
|
+
return REASON_EMBEDDED_GLOBSTAR;
|
|
3818
|
+
}
|
|
3819
|
+
return;
|
|
3820
|
+
}
|
|
3821
|
+
function parsePattern(pattern) {
|
|
3822
|
+
if (typeof pattern !== "string")
|
|
3823
|
+
return invalid(REASON_NOT_A_STRING);
|
|
3824
|
+
for (const [applies, reason] of WHOLE_PATTERN_RULES) {
|
|
3825
|
+
if (applies(pattern))
|
|
3826
|
+
return invalid(reason);
|
|
3827
|
+
}
|
|
3828
|
+
const body = pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
3829
|
+
const segments = [];
|
|
3830
|
+
for (const segment of body.split("/")) {
|
|
3831
|
+
const problem = segmentProblem(segment);
|
|
3832
|
+
if (problem !== undefined)
|
|
3833
|
+
return invalid(problem);
|
|
3834
|
+
if (segment === GLOBSTAR && segments[segments.length - 1] === GLOBSTAR) {
|
|
3835
|
+
continue;
|
|
3836
|
+
}
|
|
3837
|
+
segments.push(segment);
|
|
3838
|
+
}
|
|
3839
|
+
return {
|
|
3840
|
+
ok: true,
|
|
3841
|
+
compiled: { segments, nameOnly: !body.includes("/") }
|
|
3842
|
+
};
|
|
3843
|
+
}
|
|
3844
|
+
function validateExcludePattern(pattern) {
|
|
3845
|
+
const parsed = parsePattern(pattern);
|
|
3846
|
+
return parsed.ok ? { ok: true } : { ok: false, reason: parsed.reason };
|
|
3847
|
+
}
|
|
3848
|
+
function validateExcludeList(value) {
|
|
3849
|
+
if (!Array.isArray(value))
|
|
3850
|
+
return { ok: false, reason: REASON_NOT_AN_ARRAY };
|
|
3851
|
+
const patterns = [];
|
|
3852
|
+
const issues = [];
|
|
3853
|
+
const inspected = Math.min(value.length, MAX_EXCLUDE_PATTERNS);
|
|
3854
|
+
for (let index = 0;index < inspected; index++) {
|
|
3855
|
+
const element = value[index];
|
|
3856
|
+
const verdict = validateExcludePattern(element);
|
|
3857
|
+
if (verdict.ok && typeof element === "string") {
|
|
3858
|
+
patterns.push(element);
|
|
3859
|
+
} else if (!verdict.ok) {
|
|
3860
|
+
issues.push({ index, reason: verdict.reason });
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
if (value.length > MAX_EXCLUDE_PATTERNS) {
|
|
3864
|
+
const dropped = value.length - MAX_EXCLUDE_PATTERNS;
|
|
3865
|
+
issues.push({
|
|
3866
|
+
index: MAX_EXCLUDE_PATTERNS,
|
|
3867
|
+
reason: `${dropped} ${dropped === 1 ? "pattern" : "patterns"} over the limit of ${MAX_EXCLUDE_PATTERNS}`
|
|
3868
|
+
});
|
|
3869
|
+
}
|
|
3870
|
+
return { ok: true, patterns, issues };
|
|
3871
|
+
}
|
|
3872
|
+
function compileExcludePattern(pattern) {
|
|
3873
|
+
const parsed = parsePattern(pattern);
|
|
3874
|
+
return parsed.ok ? parsed.compiled : undefined;
|
|
3875
|
+
}
|
|
3876
|
+
function characterLength(text, index) {
|
|
3877
|
+
const high = text.charCodeAt(index);
|
|
3878
|
+
if (high >= 55296 && high <= 56319 && index + 1 < text.length) {
|
|
3879
|
+
const low = text.charCodeAt(index + 1);
|
|
3880
|
+
if (low >= 56320 && low <= 57343)
|
|
3881
|
+
return 2;
|
|
3882
|
+
}
|
|
3883
|
+
return 1;
|
|
3884
|
+
}
|
|
3885
|
+
function matchSegment(pattern, text) {
|
|
3886
|
+
let p = 0;
|
|
3887
|
+
let t = 0;
|
|
3888
|
+
let starP = -1;
|
|
3889
|
+
let starT = 0;
|
|
3890
|
+
while (t < text.length) {
|
|
3891
|
+
const code = p < pattern.length ? pattern.charCodeAt(p) : -1;
|
|
3892
|
+
if (code === 42) {
|
|
3893
|
+
starP = p;
|
|
3894
|
+
starT = t;
|
|
3895
|
+
p++;
|
|
3896
|
+
} else if (code === 63) {
|
|
3897
|
+
p++;
|
|
3898
|
+
t += characterLength(text, t);
|
|
3899
|
+
} else if (code !== -1 && code === text.charCodeAt(t)) {
|
|
3900
|
+
p++;
|
|
3901
|
+
t++;
|
|
3902
|
+
} else if (starP !== -1) {
|
|
3903
|
+
starT += characterLength(text, starT);
|
|
3904
|
+
t = starT;
|
|
3905
|
+
p = starP + 1;
|
|
3906
|
+
} else {
|
|
3907
|
+
return false;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
while (p < pattern.length && pattern.charCodeAt(p) === 42)
|
|
3911
|
+
p++;
|
|
3912
|
+
return p === pattern.length;
|
|
3913
|
+
}
|
|
3914
|
+
function matchAnchored(pattern, path) {
|
|
3915
|
+
let reached = new Array(pattern.length + 1).fill(false);
|
|
3916
|
+
reached[0] = true;
|
|
3917
|
+
for (let j = 1;j <= pattern.length; j++) {
|
|
3918
|
+
reached[j] = pattern[j - 1] === GLOBSTAR && reached[j - 1] === true;
|
|
3919
|
+
}
|
|
3920
|
+
for (const segment of path) {
|
|
3921
|
+
const next = new Array(pattern.length + 1).fill(false);
|
|
3922
|
+
for (let j = 1;j <= pattern.length; j++) {
|
|
3923
|
+
const part = pattern[j - 1] ?? "";
|
|
3924
|
+
next[j] = part === GLOBSTAR ? next[j - 1] === true || reached[j] === true : reached[j - 1] === true && matchSegment(part, segment);
|
|
3925
|
+
}
|
|
3926
|
+
reached = next;
|
|
3927
|
+
}
|
|
3928
|
+
return reached[pattern.length] === true;
|
|
3929
|
+
}
|
|
3930
|
+
function matchesCompiled(compiled, relativePath) {
|
|
3931
|
+
if (compiled.nameOnly) {
|
|
3932
|
+
const name = relativePath.slice(relativePath.lastIndexOf("/") + 1);
|
|
3933
|
+
const part = compiled.segments[0] ?? "";
|
|
3934
|
+
return part === GLOBSTAR || matchSegment(part, name);
|
|
3935
|
+
}
|
|
3936
|
+
return matchAnchored(compiled.segments, relativePath.split("/"));
|
|
3937
|
+
}
|
|
3938
|
+
function compileExcludePatterns(patterns) {
|
|
3939
|
+
const compiled = [];
|
|
3940
|
+
for (const pattern of patterns) {
|
|
3941
|
+
const one = compileExcludePattern(pattern);
|
|
3942
|
+
if (one !== undefined)
|
|
3943
|
+
compiled.push(one);
|
|
3944
|
+
}
|
|
3945
|
+
if (compiled.length === 0)
|
|
3946
|
+
return () => false;
|
|
3947
|
+
return (relativePath) => {
|
|
3948
|
+
if (relativePath.length === 0)
|
|
3949
|
+
return false;
|
|
3950
|
+
return compiled.some((entry) => matchesCompiled(entry, relativePath));
|
|
3951
|
+
};
|
|
3952
|
+
}
|
|
3953
|
+
|
|
3748
3954
|
// src/lib/search-external-deciduous.ts
|
|
3749
3955
|
import fs4 from "node:fs";
|
|
3750
3956
|
import path3 from "node:path";
|
|
@@ -3788,9 +3994,11 @@ function probeRoot(root, containedIn) {
|
|
|
3788
3994
|
}
|
|
3789
3995
|
return { kind: "ok", real };
|
|
3790
3996
|
}
|
|
3791
|
-
function classifyJsonEntry(directory, folder, name, skips) {
|
|
3997
|
+
function classifyJsonEntry(directory, folder, name, skips, isExcluded) {
|
|
3792
3998
|
if (!name.endsWith(JSON_SUFFIX))
|
|
3793
3999
|
return;
|
|
4000
|
+
if (isExcluded(`${folder}/${name}`))
|
|
4001
|
+
return;
|
|
3794
4002
|
const absolute = path3.join(directory, name);
|
|
3795
4003
|
const entry = safeLstat(absolute);
|
|
3796
4004
|
if (entry === null)
|
|
@@ -3819,7 +4027,9 @@ function statFolder(directory) {
|
|
|
3819
4027
|
return { kind: isAbsence2(error) ? "absent" : "failed" };
|
|
3820
4028
|
}
|
|
3821
4029
|
}
|
|
3822
|
-
function scanFolder(rootReal, folder, limit, skips, budget) {
|
|
4030
|
+
function scanFolder(rootReal, folder, limit, skips, budget, isExcluded) {
|
|
4031
|
+
if (isExcluded(folder))
|
|
4032
|
+
return folderScan("excluded");
|
|
3823
4033
|
const directory = path3.join(rootReal, folder);
|
|
3824
4034
|
const probed = statFolder(directory);
|
|
3825
4035
|
if (probed.kind === "absent")
|
|
@@ -3839,7 +4049,7 @@ function scanFolder(rootReal, folder, limit, skips, budget) {
|
|
|
3839
4049
|
names.sort(compareCodeUnits);
|
|
3840
4050
|
const candidates = [];
|
|
3841
4051
|
for (const name of names) {
|
|
3842
|
-
const candidate = classifyJsonEntry(directory, folder, name, skips);
|
|
4052
|
+
const candidate = classifyJsonEntry(directory, folder, name, skips, isExcluded);
|
|
3843
4053
|
if (candidate === undefined)
|
|
3844
4054
|
continue;
|
|
3845
4055
|
if (candidates.length >= limit) {
|
|
@@ -3883,14 +4093,16 @@ function newTally() {
|
|
|
3883
4093
|
return {
|
|
3884
4094
|
files: new Map,
|
|
3885
4095
|
listed: false,
|
|
4096
|
+
excluded: false,
|
|
3886
4097
|
unreadable: false,
|
|
3887
4098
|
truncated: false
|
|
3888
4099
|
};
|
|
3889
4100
|
}
|
|
3890
|
-
function scanRoots(reals, folder, tally, otherCount, skips, budget) {
|
|
4101
|
+
function scanRoots(reals, folder, tally, otherCount, skips, budget, isExcluded) {
|
|
3891
4102
|
for (const real of reals) {
|
|
3892
|
-
const scan = scanFolder(real, folder, Math.max(MAX_DISCOVERED_FILES - otherCount - tally.files.size, 0), skips, budget);
|
|
4103
|
+
const scan = scanFolder(real, folder, Math.max(MAX_DISCOVERED_FILES - otherCount - tally.files.size, 0), skips, budget, isExcluded);
|
|
3893
4104
|
tally.listed = tally.listed || scan.status === "listed";
|
|
4105
|
+
tally.excluded = tally.excluded || scan.status === "excluded";
|
|
3894
4106
|
tally.unreadable = tally.unreadable || scan.status === "unreadable";
|
|
3895
4107
|
tally.truncated = tally.truncated || scan.truncated;
|
|
3896
4108
|
for (const candidate of scan.candidates) {
|
|
@@ -3917,8 +4129,9 @@ function gather(input, skips, warnings) {
|
|
|
3917
4129
|
const budget = newEntryBudget(limit);
|
|
3918
4130
|
const nodes = newTally();
|
|
3919
4131
|
const edges = newTally();
|
|
3920
|
-
|
|
3921
|
-
scanRoots(reals, "
|
|
4132
|
+
const isExcluded = input.isExcluded ?? (() => false);
|
|
4133
|
+
scanRoots(reals, "nodes", nodes, 0, skips, budget, isExcluded);
|
|
4134
|
+
scanRoots(reals, "edges", edges, nodes.files.size, skips, budget, isExcluded);
|
|
3922
4135
|
warnings.push(...folderWarnings(input.name, "nodes", nodes), ...folderWarnings(input.name, "edges", edges));
|
|
3923
4136
|
if (budget.exhausted) {
|
|
3924
4137
|
warnings.push(`${input.name}: entry limit of ${limit} reached; some entries were not examined`);
|
|
@@ -3931,6 +4144,8 @@ function gather(input, skips, warnings) {
|
|
|
3931
4144
|
rootsFound: reals.length,
|
|
3932
4145
|
anyNodesFolder: nodes.listed,
|
|
3933
4146
|
anyEdgesFolder: edges.listed,
|
|
4147
|
+
nodesExcluded: nodes.excluded,
|
|
4148
|
+
edgesExcluded: edges.excluded,
|
|
3934
4149
|
nodesUnreadable: nodes.unreadable,
|
|
3935
4150
|
edgesUnreadable: edges.unreadable,
|
|
3936
4151
|
truncated: nodes.truncated || edges.truncated,
|
|
@@ -4181,7 +4396,7 @@ function loadDeciduousRecords(input) {
|
|
|
4181
4396
|
return nothing("unreadable", warnings.map(cleanForWarning));
|
|
4182
4397
|
}
|
|
4183
4398
|
if (nodeless === "empty") {
|
|
4184
|
-
if (!gathered.anyNodesFolder) {
|
|
4399
|
+
if (!gathered.anyNodesFolder && !gathered.nodesExcluded) {
|
|
4185
4400
|
warnings.push(`${name}: no nodes/ folder; nothing to index`);
|
|
4186
4401
|
}
|
|
4187
4402
|
warnings.push(...skipWarnings(name, skips, input.maxFileBytes));
|
|
@@ -4200,7 +4415,7 @@ function loadDeciduousRecords(input) {
|
|
|
4200
4415
|
};
|
|
4201
4416
|
const scan = readNodes(gathered.nodes, input, reader, skips);
|
|
4202
4417
|
readEdges(gathered.edges, scan, input, reader, skips);
|
|
4203
|
-
if (!gathered.anyEdgesFolder && !gathered.edgesUnreadable) {
|
|
4418
|
+
if (!gathered.anyEdgesFolder && !gathered.edgesUnreadable && !gathered.edgesExcluded) {
|
|
4204
4419
|
warnings.push(`${name}: no edges/ folder; records carry no rationale`);
|
|
4205
4420
|
}
|
|
4206
4421
|
warnings.push(...skipWarnings(name, skips, input.maxFileBytes), ...limitWarnings(name, {
|
|
@@ -4301,17 +4516,13 @@ function finishGather(source, merge, warnings) {
|
|
|
4301
4516
|
const candidates = [...merge.candidates.values()].sort((a, b) => compareCodeUnits(a.relative, b.relative));
|
|
4302
4517
|
return { kind: "gathered", candidates, truncated: merge.truncated };
|
|
4303
4518
|
}
|
|
4304
|
-
function
|
|
4519
|
+
function projectRootWarning(source, context, root) {
|
|
4305
4520
|
if (source.origin !== "project")
|
|
4306
4521
|
return;
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
return "a project root passes through a symlink";
|
|
4312
|
-
default:
|
|
4313
|
-
return;
|
|
4314
|
-
}
|
|
4522
|
+
const rejection = rejectedProjectRoot(context.checkoutRoot, root);
|
|
4523
|
+
if (rejection === undefined)
|
|
4524
|
+
return;
|
|
4525
|
+
return rejection === "outside" ? `${source.name} resolves outside the project root; not loaded` : `${source.name}: ${PROJECT_ROOT_REJECTION_REASONS[rejection]}; source dropped`;
|
|
4315
4526
|
}
|
|
4316
4527
|
function gatherCandidates(source, context, warnings) {
|
|
4317
4528
|
const { name, origin } = source;
|
|
@@ -4327,10 +4538,11 @@ function gatherCandidates(source, context, warnings) {
|
|
|
4327
4538
|
outcome: nothing2(source, "dropped", warnings)
|
|
4328
4539
|
});
|
|
4329
4540
|
const entryBudget = newEntryBudget(context.entryLimit);
|
|
4541
|
+
const isExcluded = compileExcludePatterns(source.exclude);
|
|
4330
4542
|
for (const root of source.roots) {
|
|
4331
|
-
const
|
|
4332
|
-
if (
|
|
4333
|
-
warnings.push(
|
|
4543
|
+
const rootWarning = projectRootWarning(source, context, root);
|
|
4544
|
+
if (rootWarning !== undefined) {
|
|
4545
|
+
warnings.push(rootWarning);
|
|
4334
4546
|
return drop();
|
|
4335
4547
|
}
|
|
4336
4548
|
const discovery = discoverSourceFiles({
|
|
@@ -4338,6 +4550,7 @@ function gatherCandidates(source, context, warnings) {
|
|
|
4338
4550
|
containedIn: origin === "project" ? context.checkoutRoot : undefined,
|
|
4339
4551
|
walk: MARKDOWN_WALK,
|
|
4340
4552
|
entryBudget,
|
|
4553
|
+
isExcluded,
|
|
4341
4554
|
label: name
|
|
4342
4555
|
}, warnings);
|
|
4343
4556
|
if (discovery.state === "outside")
|
|
@@ -4398,7 +4611,8 @@ function loadDeciduousSource(source, context) {
|
|
|
4398
4611
|
containedIn: origin === "project" ? context.checkoutRoot : undefined,
|
|
4399
4612
|
remainingBytes: context.remainingBytes,
|
|
4400
4613
|
maxFileBytes: EXTERNAL_MAX_FILE_BYTES,
|
|
4401
|
-
entryLimit: context.entryLimit
|
|
4614
|
+
entryLimit: context.entryLimit,
|
|
4615
|
+
isExcluded: compileExcludePatterns(source.exclude)
|
|
4402
4616
|
});
|
|
4403
4617
|
return {
|
|
4404
4618
|
name,
|
|
@@ -10410,11 +10624,19 @@ var sourceProjectsSchema = array(string2().min(1)).optional().meta({
|
|
|
10410
10624
|
description: "User config only, and required there: at least one absolute or `~`-prefixed main repository root this source applies to. A user source that omits it or leaves it empty is dropped with a warning, so a source can never apply to every project by accident. A project config may not set it.",
|
|
10411
10625
|
examples: [["~/src/github.com/me/app"]]
|
|
10412
10626
|
});
|
|
10627
|
+
var sourceExcludeSchema = array(string2()).optional().meta({
|
|
10628
|
+
description: `Patterns for files and folders to skip under each root. A pattern with no \`/\` matches a file or folder name at any depth (\`log.md\`, \`.stryker-tmp\`), and a matched folder is skipped with everything below it. A pattern with a \`/\` is anchored at the root: \`drafts/*.md\` matches \`drafts/a.md\` but not \`notes/drafts/a.md\`. \`*\` matches any run of characters inside one name, \`?\` matches one character, and \`**\` as a whole segment matches any number of folders (\`a/**/b\`). A trailing \`/\` is ignored. Matching is case-sensitive. Negation (\`!\`), character classes (\`[ ]\`), a leading \`/\` or \`./\`, \`..\`, and backslashes are not supported. A source takes at most ${MAX_EXCLUDE_PATTERNS} patterns of at most ${MAX_EXCLUDE_PATTERN_LENGTH} characters. An invalid pattern is dropped with a warning that names its position, and the other patterns still apply. Allowed in user and project config.`,
|
|
10629
|
+
examples: [
|
|
10630
|
+
["log.md", ".stryker-tmp"],
|
|
10631
|
+
["drafts/*.md", "archive/**/old"]
|
|
10632
|
+
]
|
|
10633
|
+
});
|
|
10413
10634
|
var SearchSourceSchema = object({
|
|
10414
10635
|
name: sourceNameSchema,
|
|
10415
10636
|
format: sourceFormatSchema,
|
|
10416
10637
|
roots: sourceRootsSchema,
|
|
10417
|
-
projects: sourceProjectsSchema
|
|
10638
|
+
projects: sourceProjectsSchema,
|
|
10639
|
+
exclude: sourceExcludeSchema
|
|
10418
10640
|
}).strict().meta({
|
|
10419
10641
|
description: "One opt-in decision source: a name, a format and one or more roots.",
|
|
10420
10642
|
examples: [{ name: "team-rfcs", format: "markdown", roots: ["docs/rfcs"] }]
|
|
@@ -10497,6 +10719,9 @@ function unknownKeyWarning(trust, sourcePath) {
|
|
|
10497
10719
|
function entryWarning(sourcePath, label, reason) {
|
|
10498
10720
|
return `[systematic] search source ${label} in ${sourcePath} was dropped: ${reason}. Its valid siblings still load.`;
|
|
10499
10721
|
}
|
|
10722
|
+
function excludeWarning(sourcePath, label, issue) {
|
|
10723
|
+
return `[systematic] \`exclude[${issue.index}]\` of search source ${label} in ${sourcePath} was dropped: ${issue.reason}. The source and its other patterns still load.`;
|
|
10724
|
+
}
|
|
10500
10725
|
function isTildePath(value) {
|
|
10501
10726
|
return value === "~" || value.startsWith("~/") || value.startsWith("~\\");
|
|
10502
10727
|
}
|
|
@@ -10522,7 +10747,8 @@ var ENTRY_KEYS = new Set([
|
|
|
10522
10747
|
"name",
|
|
10523
10748
|
"format",
|
|
10524
10749
|
"roots",
|
|
10525
|
-
"projects"
|
|
10750
|
+
"projects",
|
|
10751
|
+
"exclude"
|
|
10526
10752
|
]);
|
|
10527
10753
|
function isFormat(value) {
|
|
10528
10754
|
return typeof value === "string" && SEARCH_SOURCE_FORMATS.includes(value);
|
|
@@ -10582,21 +10808,30 @@ function validateEntry(raw, index, trust) {
|
|
|
10582
10808
|
const projects = validateProjects(raw.projects, trust);
|
|
10583
10809
|
if (typeof projects === "string")
|
|
10584
10810
|
return rejectEntry(label, projects);
|
|
10811
|
+
const exclude = Object.hasOwn(raw, "exclude") ? validateExcludeList(raw.exclude) : undefined;
|
|
10812
|
+
if (exclude?.ok === false) {
|
|
10813
|
+
return rejectEntry(label, `exclude is invalid (${exclude.reason})`);
|
|
10814
|
+
}
|
|
10815
|
+
const patterns = exclude?.patterns ?? [];
|
|
10585
10816
|
return {
|
|
10586
10817
|
ok: true,
|
|
10587
10818
|
entry: {
|
|
10588
10819
|
name,
|
|
10589
10820
|
format,
|
|
10590
10821
|
roots: [...roots],
|
|
10591
|
-
...projects !== undefined && { projects: [...projects] }
|
|
10592
|
-
|
|
10822
|
+
...projects !== undefined && { projects: [...projects] },
|
|
10823
|
+
...patterns.length > 0 && { exclude: [...patterns] }
|
|
10824
|
+
},
|
|
10825
|
+
excludeIssues: exclude?.issues ?? []
|
|
10593
10826
|
};
|
|
10594
10827
|
}
|
|
10595
10828
|
function warn(state, message) {
|
|
10596
|
-
if (state.warnings.length < MAX_DETAIL_WARNINGS)
|
|
10829
|
+
if (state.warnings.length < MAX_DETAIL_WARNINGS) {
|
|
10597
10830
|
state.warnings.push(message);
|
|
10598
|
-
|
|
10599
|
-
|
|
10831
|
+
return true;
|
|
10832
|
+
}
|
|
10833
|
+
state.suppressed += 1;
|
|
10834
|
+
return false;
|
|
10600
10835
|
}
|
|
10601
10836
|
function validateSources(raw, state) {
|
|
10602
10837
|
if (!Array.isArray(raw)) {
|
|
@@ -10610,18 +10845,43 @@ function validateSources(raw, state) {
|
|
|
10610
10845
|
raw.forEach((item, index) => {
|
|
10611
10846
|
const result = validateEntry(item, index, state.trust);
|
|
10612
10847
|
if (!result.ok) {
|
|
10613
|
-
|
|
10848
|
+
dropEntry(state, index, result.label, result.reason);
|
|
10614
10849
|
return;
|
|
10615
10850
|
}
|
|
10616
10851
|
if (seen.has(result.entry.name)) {
|
|
10617
|
-
|
|
10852
|
+
dropEntry(state, index, `"${result.entry.name}"`, "the name is already used earlier in this file, so the first entry is kept");
|
|
10618
10853
|
return;
|
|
10619
10854
|
}
|
|
10620
10855
|
seen.add(result.entry.name);
|
|
10621
10856
|
kept.push(result.entry);
|
|
10857
|
+
const label = `"${result.entry.name}"`;
|
|
10858
|
+
const warnings = [];
|
|
10859
|
+
for (const issue of result.excludeIssues) {
|
|
10860
|
+
const message = excludeWarning(state.sourcePath, label, issue);
|
|
10861
|
+
if (warn(state, message))
|
|
10862
|
+
warnings.push(message);
|
|
10863
|
+
}
|
|
10864
|
+
state.entries.push({
|
|
10865
|
+
kind: "kept",
|
|
10866
|
+
index,
|
|
10867
|
+
label,
|
|
10868
|
+
entry: result.entry,
|
|
10869
|
+
warnings
|
|
10870
|
+
});
|
|
10622
10871
|
});
|
|
10623
10872
|
return kept;
|
|
10624
10873
|
}
|
|
10874
|
+
function dropEntry(state, index, label, reason) {
|
|
10875
|
+
state.dropped.push({ label, reason });
|
|
10876
|
+
const message = entryWarning(state.sourcePath, label, reason);
|
|
10877
|
+
state.entries.push({
|
|
10878
|
+
kind: "dropped",
|
|
10879
|
+
index,
|
|
10880
|
+
label,
|
|
10881
|
+
reason,
|
|
10882
|
+
warnings: warn(state, message) ? [message] : []
|
|
10883
|
+
});
|
|
10884
|
+
}
|
|
10625
10885
|
function validateAllowList(raw, state) {
|
|
10626
10886
|
if (!Array.isArray(raw)) {
|
|
10627
10887
|
state.unreadable = true;
|
|
@@ -10671,6 +10931,8 @@ function validateSearchConfig(value, trust, sourcePath) {
|
|
|
10671
10931
|
trust,
|
|
10672
10932
|
sourcePath: displaySafe(sourcePath),
|
|
10673
10933
|
warnings: [],
|
|
10934
|
+
dropped: [],
|
|
10935
|
+
entries: [],
|
|
10674
10936
|
suppressed: 0,
|
|
10675
10937
|
unreadable: false,
|
|
10676
10938
|
structural: false
|
|
@@ -10681,7 +10943,9 @@ function validateSearchConfig(value, trust, sourcePath) {
|
|
|
10681
10943
|
settings: undefined,
|
|
10682
10944
|
unreadable: true,
|
|
10683
10945
|
structural: true,
|
|
10684
|
-
warnings: state.warnings
|
|
10946
|
+
warnings: state.warnings,
|
|
10947
|
+
dropped: state.dropped,
|
|
10948
|
+
entries: state.entries
|
|
10685
10949
|
};
|
|
10686
10950
|
}
|
|
10687
10951
|
const settings = {};
|
|
@@ -10703,20 +10967,27 @@ function validateSearchConfig(value, trust, sourcePath) {
|
|
|
10703
10967
|
settings,
|
|
10704
10968
|
unreadable: state.unreadable,
|
|
10705
10969
|
structural: state.structural,
|
|
10706
|
-
warnings: state.warnings
|
|
10970
|
+
warnings: state.warnings,
|
|
10971
|
+
dropped: state.dropped,
|
|
10972
|
+
entries: state.entries
|
|
10707
10973
|
};
|
|
10708
10974
|
}
|
|
10709
10975
|
function formatSearchFileWarning(sourcePath, reason) {
|
|
10710
10976
|
return `[systematic] search settings in ${displaySafe(sourcePath)} could not be read (${reason}); the settings were ignored, search still runs and its results carry a \`config unreadable\` note.`;
|
|
10711
10977
|
}
|
|
10712
10978
|
function mergeSearchSettings(sources) {
|
|
10713
|
-
const acc = {
|
|
10979
|
+
const acc = {
|
|
10980
|
+
allow: [],
|
|
10981
|
+
byName: new Map,
|
|
10982
|
+
layers: new Map
|
|
10983
|
+
};
|
|
10714
10984
|
let unreadable = false;
|
|
10715
10985
|
for (const source of sources) {
|
|
10716
10986
|
if (source.unreadable)
|
|
10717
10987
|
unreadable = true;
|
|
10718
|
-
if (source.settings !== undefined)
|
|
10719
|
-
absorb(acc, source.settings);
|
|
10988
|
+
if (source.settings !== undefined) {
|
|
10989
|
+
absorb(acc, source.settings, source.layer);
|
|
10990
|
+
}
|
|
10720
10991
|
}
|
|
10721
10992
|
const merged = {
|
|
10722
10993
|
...acc.enabled !== undefined && { enabled: acc.enabled },
|
|
@@ -10724,23 +10995,37 @@ function mergeSearchSettings(sources) {
|
|
|
10724
10995
|
...acc.byName.size > 0 && { sources: [...acc.byName.values()] }
|
|
10725
10996
|
};
|
|
10726
10997
|
if (Object.keys(merged).length === 0) {
|
|
10727
|
-
return { settings: undefined, unreadable };
|
|
10998
|
+
return { settings: undefined, unreadable, sourceLayers: acc.layers };
|
|
10728
10999
|
}
|
|
10729
|
-
return { settings: merged, unreadable };
|
|
11000
|
+
return { settings: merged, unreadable, sourceLayers: acc.layers };
|
|
10730
11001
|
}
|
|
10731
|
-
function absorb(acc, settings) {
|
|
11002
|
+
function absorb(acc, settings, layer) {
|
|
10732
11003
|
if (settings.enabled !== undefined)
|
|
10733
11004
|
acc.enabled = settings.enabled;
|
|
10734
11005
|
for (const entry of settings.allow_project_sources ?? []) {
|
|
10735
11006
|
if (!acc.allow.includes(entry))
|
|
10736
11007
|
acc.allow.push(entry);
|
|
10737
11008
|
}
|
|
10738
|
-
for (const entry of settings.sources ?? [])
|
|
11009
|
+
for (const entry of settings.sources ?? []) {
|
|
10739
11010
|
acc.byName.set(entry.name, entry);
|
|
11011
|
+
if (layer === undefined)
|
|
11012
|
+
acc.layers.delete(entry.name);
|
|
11013
|
+
else
|
|
11014
|
+
acc.layers.set(entry.name, layer);
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
function configEntryExists(target) {
|
|
11018
|
+
try {
|
|
11019
|
+
fs6.lstatSync(target);
|
|
11020
|
+
return true;
|
|
11021
|
+
} catch (error) {
|
|
11022
|
+
const code = errorCode2(error);
|
|
11023
|
+
return code !== "ENOENT" && code !== "ENOTDIR";
|
|
11024
|
+
}
|
|
10740
11025
|
}
|
|
10741
11026
|
function selectConfigFile(dir, basename) {
|
|
10742
11027
|
const jsoncPath = path6.join(dir, `${basename}.jsonc`);
|
|
10743
|
-
if (
|
|
11028
|
+
if (configEntryExists(jsoncPath))
|
|
10744
11029
|
return jsoncPath;
|
|
10745
11030
|
return path6.join(dir, `${basename}.json`);
|
|
10746
11031
|
}
|
|
@@ -10750,6 +11035,55 @@ function resolveUserLevelConfigDirs(options) {
|
|
|
10750
11035
|
const rawCustom = options !== undefined && Object.hasOwn(options, "customConfigDir") ? options.customConfigDir?.trim() : process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
10751
11036
|
return { homeDir, userConfigDir, customConfigDir: rawCustom || undefined };
|
|
10752
11037
|
}
|
|
11038
|
+
function realpathOrResolved(dir) {
|
|
11039
|
+
const resolved = path6.resolve(dir);
|
|
11040
|
+
try {
|
|
11041
|
+
return fs6.realpathSync(resolved);
|
|
11042
|
+
} catch {
|
|
11043
|
+
return resolved;
|
|
11044
|
+
}
|
|
11045
|
+
}
|
|
11046
|
+
function selectUserLevelConfigFiles(dirs) {
|
|
11047
|
+
const files = [
|
|
11048
|
+
{
|
|
11049
|
+
layer: "user",
|
|
11050
|
+
path: selectConfigFile(dirs.userConfigDir, "systematic")
|
|
11051
|
+
},
|
|
11052
|
+
{
|
|
11053
|
+
layer: "user.local",
|
|
11054
|
+
path: selectConfigFile(dirs.userConfigDir, "systematic.local")
|
|
11055
|
+
}
|
|
11056
|
+
];
|
|
11057
|
+
const custom = dirs.customConfigDir;
|
|
11058
|
+
if (!custom)
|
|
11059
|
+
return { files, aliased: false };
|
|
11060
|
+
files.push({ layer: "custom", path: selectConfigFile(custom, "systematic") }, {
|
|
11061
|
+
layer: "custom.local",
|
|
11062
|
+
path: selectConfigFile(custom, "systematic.local")
|
|
11063
|
+
});
|
|
11064
|
+
const aliased = path6.resolve(custom) === path6.resolve(dirs.userConfigDir) || realpathOrResolved(custom) === realpathOrResolved(dirs.userConfigDir);
|
|
11065
|
+
return { files, aliased };
|
|
11066
|
+
}
|
|
11067
|
+
function selectProjectConfigFile(repoRoot) {
|
|
11068
|
+
const opencodeFile = selectConfigFile(path6.join(repoRoot, ".opencode"), "systematic");
|
|
11069
|
+
const rootFile = selectConfigFile(repoRoot, ".systematic");
|
|
11070
|
+
if (!configEntryExists(rootFile))
|
|
11071
|
+
return { path: opencodeFile };
|
|
11072
|
+
return configEntryExists(opencodeFile) ? { path: rootFile, ignoredPath: opencodeFile } : { path: rootFile };
|
|
11073
|
+
}
|
|
11074
|
+
function findStartDirProjectConfig(startDir, repoRoot, selectedProjectConfig) {
|
|
11075
|
+
if (!repoRoot.foundGit)
|
|
11076
|
+
return;
|
|
11077
|
+
if (realpathOrResolved(startDir) === repoRoot.root)
|
|
11078
|
+
return;
|
|
11079
|
+
const candidate = selectConfigFile(path6.join(startDir, ".opencode"), "systematic");
|
|
11080
|
+
if (!configEntryExists(candidate))
|
|
11081
|
+
return;
|
|
11082
|
+
return realpathOrResolved(candidate) === realpathOrResolved(selectedProjectConfig) ? undefined : candidate;
|
|
11083
|
+
}
|
|
11084
|
+
function startDirProjectWarning(startDirConfig, projectRoot, selectedProjectConfig, safe = displaySafe) {
|
|
11085
|
+
return `[systematic] project config (${safe(startDirConfig)}) is below the repository root (${safe(projectRoot)}) and is not read; project config is read from (${safe(selectedProjectConfig)}).`;
|
|
11086
|
+
}
|
|
10753
11087
|
function errorCode2(error) {
|
|
10754
11088
|
return error instanceof Error && "code" in error ? error.code : undefined;
|
|
10755
11089
|
}
|
|
@@ -10760,7 +11094,7 @@ function readTextBounded(filePath, maxBytes) {
|
|
|
10760
11094
|
case "bytes":
|
|
10761
11095
|
return { kind: "text", content: read.bytes.toString("utf-8") };
|
|
10762
11096
|
case "absent":
|
|
10763
|
-
return
|
|
11097
|
+
return absentOrDangling(filePath);
|
|
10764
11098
|
case "not-regular":
|
|
10765
11099
|
return { kind: "failed", reason: "not a regular file" };
|
|
10766
11100
|
case "too-large":
|
|
@@ -10772,12 +11106,15 @@ function readTextBounded(filePath, maxBytes) {
|
|
|
10772
11106
|
return { kind: "failed", reason: "unable to read file" };
|
|
10773
11107
|
}
|
|
10774
11108
|
}
|
|
11109
|
+
function absentOrDangling(filePath) {
|
|
11110
|
+
return configEntryExists(filePath) ? { kind: "failed", reason: "unable to read file" } : { kind: "absent" };
|
|
11111
|
+
}
|
|
10775
11112
|
function readTextWhole(filePath) {
|
|
10776
11113
|
try {
|
|
10777
11114
|
return { kind: "text", content: fs6.readFileSync(filePath, "utf-8") };
|
|
10778
11115
|
} catch (error) {
|
|
10779
11116
|
if (errorCode2(error) === "ENOENT")
|
|
10780
|
-
return
|
|
11117
|
+
return absentOrDangling(filePath);
|
|
10781
11118
|
return { kind: "failed", reason: "unable to read file" };
|
|
10782
11119
|
}
|
|
10783
11120
|
}
|
|
@@ -10804,58 +11141,111 @@ function readSearchBlock(filePath, maxBytes) {
|
|
|
10804
11141
|
searchBlock: parsed.search
|
|
10805
11142
|
};
|
|
10806
11143
|
}
|
|
11144
|
+
var NOTHING_READ = {
|
|
11145
|
+
source: undefined,
|
|
11146
|
+
warnings: [],
|
|
11147
|
+
readFailures: [],
|
|
11148
|
+
dropped: [],
|
|
11149
|
+
entries: []
|
|
11150
|
+
};
|
|
11151
|
+
function readUserLevelFile(file) {
|
|
11152
|
+
const read = readSearchBlock(file.path);
|
|
11153
|
+
if (read.kind === "absent")
|
|
11154
|
+
return NOTHING_READ;
|
|
11155
|
+
if (read.kind === "failed") {
|
|
11156
|
+
const warning = formatSearchFileWarning(file.path, read.reason);
|
|
11157
|
+
return {
|
|
11158
|
+
source: { unreadable: true },
|
|
11159
|
+
warnings: [warning],
|
|
11160
|
+
readFailures: [warning],
|
|
11161
|
+
dropped: [],
|
|
11162
|
+
entries: []
|
|
11163
|
+
};
|
|
11164
|
+
}
|
|
11165
|
+
if (!read.has)
|
|
11166
|
+
return NOTHING_READ;
|
|
11167
|
+
const validation = validateSearchConfig(read.searchBlock, "user", file.path);
|
|
11168
|
+
return {
|
|
11169
|
+
source: {
|
|
11170
|
+
settings: validation.settings,
|
|
11171
|
+
unreadable: validation.unreadable
|
|
11172
|
+
},
|
|
11173
|
+
warnings: validation.warnings,
|
|
11174
|
+
readFailures: [],
|
|
11175
|
+
dropped: validation.dropped,
|
|
11176
|
+
entries: validation.entries
|
|
11177
|
+
};
|
|
11178
|
+
}
|
|
11179
|
+
var ALIASED_TWIN = { custom: "user", "custom.local": "user.local" };
|
|
10807
11180
|
function loadUserLevelSearchSettings(options) {
|
|
10808
|
-
const
|
|
10809
|
-
const files = [
|
|
10810
|
-
selectConfigFile(dirs.userConfigDir, "systematic"),
|
|
10811
|
-
...dirs.customConfigDir ? [selectConfigFile(dirs.customConfigDir, "systematic")] : []
|
|
10812
|
-
];
|
|
11181
|
+
const selection = selectUserLevelConfigFiles(resolveUserLevelConfigDirs(options));
|
|
10813
11182
|
const warnings = [];
|
|
11183
|
+
const readFailures = [];
|
|
11184
|
+
const dropped = [];
|
|
11185
|
+
const entries = [];
|
|
10814
11186
|
const sources = [];
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
if (!read.has)
|
|
11187
|
+
const reads = new Map;
|
|
11188
|
+
for (const file of selection.files) {
|
|
11189
|
+
const twin = selection.aliased ? ALIASED_TWIN[file.layer] : undefined;
|
|
11190
|
+
const shared = twin === undefined ? undefined : reads.get(twin);
|
|
11191
|
+
const read = shared ?? readUserLevelFile(file);
|
|
11192
|
+
reads.set(file.layer, read);
|
|
11193
|
+
if (read.source)
|
|
11194
|
+
sources.push({ ...read.source, layer: file.layer });
|
|
11195
|
+
if (shared !== undefined)
|
|
10825
11196
|
continue;
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
unreadable: validation.unreadable
|
|
10831
|
-
});
|
|
11197
|
+
warnings.push(...read.warnings);
|
|
11198
|
+
readFailures.push(...read.readFailures);
|
|
11199
|
+
dropped.push(...read.dropped);
|
|
11200
|
+
entries.push(...read.entries);
|
|
10832
11201
|
}
|
|
10833
11202
|
const merged = mergeSearchSettings(sources);
|
|
10834
|
-
return {
|
|
11203
|
+
return {
|
|
11204
|
+
settings: merged.settings,
|
|
11205
|
+
unreadable: merged.unreadable,
|
|
11206
|
+
warnings,
|
|
11207
|
+
dropped,
|
|
11208
|
+
entries,
|
|
11209
|
+
sourceLayers: merged.sourceLayers,
|
|
11210
|
+
readFailures
|
|
11211
|
+
};
|
|
10835
11212
|
}
|
|
10836
11213
|
function formatProjectFileWarning(sourcePath, reason) {
|
|
10837
11214
|
return `[systematic] project search settings in ${displaySafe(sourcePath)} could not be read (${reason}); the sources it proposes were ignored.`;
|
|
10838
11215
|
}
|
|
11216
|
+
function formatShadowedProjectWarning(usedPath, ignoredPath) {
|
|
11217
|
+
return `[systematic] project config (${displaySafe(usedPath)}) takes precedence over (${displaySafe(ignoredPath)}), which is ignored; the two files are never merged.`;
|
|
11218
|
+
}
|
|
10839
11219
|
function loadProjectSearchSources(checkoutRoot) {
|
|
10840
|
-
const
|
|
11220
|
+
const selection = selectProjectConfigFile(checkoutRoot);
|
|
11221
|
+
const filePath = selection.path;
|
|
11222
|
+
const shadowed = selection.ignoredPath === undefined ? [] : [formatShadowedProjectWarning(filePath, selection.ignoredPath)];
|
|
10841
11223
|
const read = readSearchBlock(filePath, MAX_PROJECT_CONFIG_BYTES);
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
11224
|
+
const nothing = {
|
|
11225
|
+
sources: [],
|
|
11226
|
+
warnings: shadowed,
|
|
11227
|
+
unreadable: false,
|
|
11228
|
+
dropped: [],
|
|
11229
|
+
entries: []
|
|
11230
|
+
};
|
|
11231
|
+
if (read.kind === "absent")
|
|
11232
|
+
return nothing;
|
|
10845
11233
|
if (read.kind === "failed") {
|
|
10846
11234
|
return {
|
|
10847
|
-
|
|
10848
|
-
warnings: [formatProjectFileWarning(filePath, read.reason)],
|
|
11235
|
+
...nothing,
|
|
11236
|
+
warnings: [...shadowed, formatProjectFileWarning(filePath, read.reason)],
|
|
10849
11237
|
unreadable: true
|
|
10850
11238
|
};
|
|
10851
11239
|
}
|
|
10852
11240
|
if (!read.has)
|
|
10853
|
-
return
|
|
11241
|
+
return nothing;
|
|
10854
11242
|
const validation = validateSearchConfig(read.searchBlock, "project", filePath);
|
|
10855
11243
|
return {
|
|
10856
11244
|
sources: validation.structural ? [] : validation.settings?.sources ?? [],
|
|
10857
|
-
warnings: validation.warnings,
|
|
10858
|
-
unreadable: validation.structural
|
|
11245
|
+
warnings: [...shadowed, ...validation.warnings],
|
|
11246
|
+
unreadable: validation.structural,
|
|
11247
|
+
dropped: validation.dropped,
|
|
11248
|
+
entries: validation.entries
|
|
10859
11249
|
};
|
|
10860
11250
|
}
|
|
10861
11251
|
|
|
@@ -10876,22 +11266,54 @@ function capWarning(dropped) {
|
|
|
10876
11266
|
const names = `${listed.join(", ")}${more > 0 ? ` and ${more} more` : ""}`;
|
|
10877
11267
|
return `[systematic] more than ${MAX_ACTIVE_SOURCES} search sources are active for this project; these were dropped: ${names}. Remove a source or narrow its \`projects\` to bring the count down.`;
|
|
10878
11268
|
}
|
|
10879
|
-
function
|
|
10880
|
-
return declared.filter((entry) => entry.projects !== undefined && isAllowedProject(identity, entry.projects, { homeDir }))
|
|
11269
|
+
function mappedUserEntries(declared, identity, homeDir) {
|
|
11270
|
+
return declared.filter((entry) => entry.projects !== undefined && isAllowedProject(identity, entry.projects, { homeDir }));
|
|
11271
|
+
}
|
|
11272
|
+
function userSourceOf(entry, homeDir) {
|
|
11273
|
+
return {
|
|
10881
11274
|
name: entry.name,
|
|
10882
11275
|
format: entry.format,
|
|
10883
11276
|
roots: entry.roots.map((root) => expandHome2(root, homeDir)),
|
|
10884
|
-
origin: "user"
|
|
10885
|
-
|
|
11277
|
+
origin: "user",
|
|
11278
|
+
exclude: entry.exclude ?? []
|
|
11279
|
+
};
|
|
11280
|
+
}
|
|
11281
|
+
function mappedUserSources(declared, identity, homeDir) {
|
|
11282
|
+
return mappedUserEntries(declared, identity, homeDir).map((entry) => userSourceOf(entry, homeDir));
|
|
11283
|
+
}
|
|
11284
|
+
function projectSourceOf(entry, checkoutRoot) {
|
|
11285
|
+
return {
|
|
11286
|
+
name: entry.name,
|
|
11287
|
+
format: entry.format,
|
|
11288
|
+
roots: entry.roots.map((root) => path7.resolve(checkoutRoot, root)),
|
|
11289
|
+
origin: "project",
|
|
11290
|
+
exclude: entry.exclude ?? []
|
|
11291
|
+
};
|
|
11292
|
+
}
|
|
11293
|
+
function projectSourcesOf(proposals, checkoutRoot, shadowed) {
|
|
11294
|
+
return proposals.filter((entry) => !shadowed.has(entry.name)).map((entry) => projectSourceOf(entry, checkoutRoot));
|
|
11295
|
+
}
|
|
11296
|
+
function forwardedProjectWarnings(project, projectAllowed) {
|
|
11297
|
+
if (projectAllowed)
|
|
11298
|
+
return project.warnings;
|
|
11299
|
+
const aboutEntries = new Set(project.entries.flatMap((entry) => entry.warnings));
|
|
11300
|
+
return project.warnings.filter((warning) => !aboutEntries.has(warning));
|
|
11301
|
+
}
|
|
11302
|
+
function startDirWarnings(startDir, lookup, checkoutRoot) {
|
|
11303
|
+
const selected = selectProjectConfigFile(checkoutRoot).path;
|
|
11304
|
+
const ignored = findStartDirProjectConfig(startDir, lookup, selected);
|
|
11305
|
+
return ignored === undefined ? [] : [startDirProjectWarning(ignored, checkoutRoot, selected)];
|
|
10886
11306
|
}
|
|
10887
11307
|
function resolveExternalSources(input) {
|
|
10888
11308
|
const dirs = resolveUserLevelConfigDirs(input.configOptions);
|
|
10889
11309
|
const homeDir = dirs.homeDir || os3.homedir();
|
|
10890
|
-
const
|
|
11310
|
+
const lookup = lookupSearchRoot(input.startDir);
|
|
11311
|
+
const checkoutRoot = lookup.foundGit ? lookup.root : resolveSearchRoot(input.startDir);
|
|
10891
11312
|
const identity = input.identity ?? resolveProjectIdentity(checkoutRoot);
|
|
10892
11313
|
const user = loadUserLevelSearchSettings(input.configOptions);
|
|
10893
11314
|
const allow = user.settings?.allow_project_sources ?? [];
|
|
10894
11315
|
const project = loadProjectSearchSources(checkoutRoot);
|
|
11316
|
+
const projectAllowed = isAllowedProject(identity, allow, { homeDir });
|
|
10895
11317
|
const userSources = mappedUserSources(user.settings?.sources ?? [], identity, homeDir);
|
|
10896
11318
|
let projectState;
|
|
10897
11319
|
let projectSources = [];
|
|
@@ -10900,30 +11322,26 @@ function resolveExternalSources(input) {
|
|
|
10900
11322
|
projectState = { kind: "config-unreadable" };
|
|
10901
11323
|
} else if (proposals === 0) {
|
|
10902
11324
|
projectState = { kind: "none" };
|
|
10903
|
-
} else if (
|
|
11325
|
+
} else if (projectAllowed) {
|
|
10904
11326
|
projectState = { kind: "allowed", proposals };
|
|
10905
|
-
|
|
10906
|
-
projectSources = project.sources.filter((entry) => !shadowed.has(entry.name)).map((entry) => ({
|
|
10907
|
-
name: entry.name,
|
|
10908
|
-
format: entry.format,
|
|
10909
|
-
roots: entry.roots.map((root) => path7.resolve(checkoutRoot, root)),
|
|
10910
|
-
origin: "project"
|
|
10911
|
-
}));
|
|
11327
|
+
projectSources = projectSourcesOf(project.sources, checkoutRoot, new Set(userSources.map((source) => source.name)));
|
|
10912
11328
|
} else {
|
|
10913
11329
|
projectState = identity.status === "resolved" ? { kind: "not-allowed", proposals, mainRoot: identity.mainRoot } : { kind: "not-allowed", proposals };
|
|
10914
11330
|
}
|
|
10915
11331
|
const ordered = [...userSources, ...projectSources];
|
|
10916
11332
|
const sources = ordered.slice(0, MAX_ACTIVE_SOURCES);
|
|
10917
|
-
const
|
|
11333
|
+
const capped = ordered.slice(MAX_ACTIVE_SOURCES);
|
|
10918
11334
|
return {
|
|
10919
11335
|
sources,
|
|
10920
11336
|
project: projectState,
|
|
10921
11337
|
userConfigUnreadable: user.unreadable,
|
|
10922
11338
|
warnings: [
|
|
10923
|
-
...
|
|
11339
|
+
...capped.length > 0 ? [capWarning(capped)] : [],
|
|
10924
11340
|
...user.warnings,
|
|
10925
|
-
...
|
|
10926
|
-
|
|
11341
|
+
...startDirWarnings(input.startDir, lookup, checkoutRoot),
|
|
11342
|
+
...forwardedProjectWarnings(project, projectAllowed)
|
|
11343
|
+
],
|
|
11344
|
+
dropped: { user: user.dropped, project: project.dropped }
|
|
10927
11345
|
};
|
|
10928
11346
|
}
|
|
10929
11347
|
|
|
@@ -12392,11 +12810,11 @@ var permissionSchema = record(string2(), permissionRuleSchema).meta({
|
|
|
12392
12810
|
description: "Permission overrides per tool",
|
|
12393
12811
|
examples: [{ edit: "allow", bash: { curl: "allow", rm: "deny" } }]
|
|
12394
12812
|
});
|
|
12395
|
-
var MODEL_FORMAT_MESSAGE = 'must be in provider/model format (e.g., "anthropic/claude-sonnet-5")';
|
|
12813
|
+
var MODEL_FORMAT_MESSAGE = 'must be in provider/model format (e.g., "anthropic/claude-sonnet-5-5")';
|
|
12396
12814
|
var MODEL_FORMAT_REGEX = /^[^\s/]+\/\S+$/;
|
|
12397
12815
|
var modelSchema = string2().min(1).regex(MODEL_FORMAT_REGEX, MODEL_FORMAT_MESSAGE).nullable().meta({
|
|
12398
12816
|
description: "Model identifier in provider/model format, or null to inherit parent model",
|
|
12399
|
-
examples: ["anthropic/claude-sonnet-5", null]
|
|
12817
|
+
examples: ["anthropic/claude-sonnet-5-5", null]
|
|
12400
12818
|
});
|
|
12401
12819
|
var variantSchema = string2().min(1).max(128, "variant must be at most 128 characters").regex(/^\S+$/, "must be a non-empty string without whitespace").meta({
|
|
12402
12820
|
description: "Model variant identifier",
|
|
@@ -12457,7 +12875,7 @@ var OpencodeHarnessBlockSchema = object({
|
|
|
12457
12875
|
}).strict().meta({
|
|
12458
12876
|
description: "OpenCode-specific routing block. When present, model/variant here override the flat model/variant fields for OpenCode only; the flat fields remain the harness-neutral default and still apply to Pi. `variant` is bound to whichever layer supplies `model`: it is used only from that layer or a more specific one, and is dropped when a more specific layer sets (or nulls) `model` without repeating the variant. A `variant` with no `model` anywhere in the merged overlay is a config-load error raised by the routing resolver, not a parse-time error.",
|
|
12459
12877
|
examples: [
|
|
12460
|
-
{ model: "anthropic/claude-opus-5", variant: "high" },
|
|
12878
|
+
{ model: "anthropic/claude-opus-5-5", variant: "high" },
|
|
12461
12879
|
{ model: null }
|
|
12462
12880
|
]
|
|
12463
12881
|
});
|
|
@@ -12467,7 +12885,7 @@ var PiHarnessBlockSchema = object({
|
|
|
12467
12885
|
}).strict().meta({
|
|
12468
12886
|
description: "Pi-specific routing block. When present, model/thinking here override the flat model field and the legacy `pi_subagents.<name>.thinking` value for Pi only; the flat model field remains the harness-neutral default and still applies to OpenCode. Unlike OpenCode's `variant`, `thinking` is independent of `model`: it applies to whatever model the delegate ends up running, including one inherited from the parent session, so `thinking` with no `model` anywhere in the merged overlay is valid and never a config-load error.",
|
|
12469
12887
|
examples: [
|
|
12470
|
-
{ model: "anthropic/claude-opus-5", thinking: "high" },
|
|
12888
|
+
{ model: "anthropic/claude-opus-5-5", thinking: "high" },
|
|
12471
12889
|
{ model: null }
|
|
12472
12890
|
]
|
|
12473
12891
|
});
|
|
@@ -12489,13 +12907,13 @@ var AgentOverlaySchema = object({
|
|
|
12489
12907
|
description: "Per-agent configuration overlay",
|
|
12490
12908
|
examples: [
|
|
12491
12909
|
{
|
|
12492
|
-
model: "anthropic/claude-opus-5",
|
|
12910
|
+
model: "anthropic/claude-opus-5-5",
|
|
12493
12911
|
temperature: 0.1,
|
|
12494
12912
|
mode: "subagent"
|
|
12495
12913
|
},
|
|
12496
12914
|
{
|
|
12497
|
-
opencode: { model: "anthropic/claude-opus-5", variant: "high" },
|
|
12498
|
-
pi: { model: "anthropic/claude-opus-5", thinking: "high" }
|
|
12915
|
+
opencode: { model: "anthropic/claude-opus-5-5", variant: "high" },
|
|
12916
|
+
pi: { model: "anthropic/claude-opus-5-5", thinking: "high" }
|
|
12499
12917
|
}
|
|
12500
12918
|
]
|
|
12501
12919
|
});
|
|
@@ -12515,7 +12933,7 @@ var CategoryOverlaySchema = object({
|
|
|
12515
12933
|
}).strict().meta({
|
|
12516
12934
|
description: "Per-category configuration overlay (same fields as agent minus disable)",
|
|
12517
12935
|
examples: [
|
|
12518
|
-
{ model: "anthropic/claude-opus-5", temperature: 0.1 },
|
|
12936
|
+
{ model: "anthropic/claude-opus-5-5", temperature: 0.1 },
|
|
12519
12937
|
{ opencode: { variant: "high" }, pi: { thinking: "high" } }
|
|
12520
12938
|
]
|
|
12521
12939
|
});
|
|
@@ -12529,7 +12947,7 @@ var ProfileOverlaySchema = object({
|
|
|
12529
12947
|
}).strict().meta({
|
|
12530
12948
|
description: "Routing-only overlay fields permitted inside a named profile bundle entry: model, variant, temperature, top_p, and the opencode/pi harness blocks. Non-routing fields (permission, skills, mode, hidden, disable, steps, color) are rejected.",
|
|
12531
12949
|
examples: [
|
|
12532
|
-
{ model: "anthropic/claude-opus-5" },
|
|
12950
|
+
{ model: "anthropic/claude-opus-5-5" },
|
|
12533
12951
|
{ opencode: { variant: "high" }, pi: { thinking: "high" } }
|
|
12534
12952
|
]
|
|
12535
12953
|
});
|
|
@@ -12546,13 +12964,13 @@ function createProfileBundleSchema(agentNames, qualifiedAgentIds) {
|
|
|
12546
12964
|
}),
|
|
12547
12965
|
categories: record(string2(), ProfileOverlaySchema).optional().meta({
|
|
12548
12966
|
description: "Per-category routing overlays for this profile, keyed by category name, using the same routing-only field set as every profile entry.",
|
|
12549
|
-
examples: [{ review: { model: "anthropic/claude-opus-5" } }]
|
|
12967
|
+
examples: [{ review: { model: "anthropic/claude-opus-5-5" } }]
|
|
12550
12968
|
})
|
|
12551
12969
|
}).strict().meta({
|
|
12552
12970
|
description: "A named routing-only overlay bundle. Entries under agents/categories have the same shape as the top-level agents/categories overlays, restricted to routing fields.",
|
|
12553
12971
|
examples: [
|
|
12554
12972
|
{
|
|
12555
|
-
agents: { fixer: { model: "anthropic/claude-opus-5" } },
|
|
12973
|
+
agents: { fixer: { model: "anthropic/claude-opus-5-5" } },
|
|
12556
12974
|
categories: { review: { pi: { thinking: "high" } } }
|
|
12557
12975
|
}
|
|
12558
12976
|
]
|
|
@@ -12651,7 +13069,7 @@ function createSystematicConfigSchema(opts) {
|
|
|
12651
13069
|
}),
|
|
12652
13070
|
categories: record(string2(), CategoryOverlaySchema).default({}).meta({
|
|
12653
13071
|
description: "Per-category configuration overlays keyed by category name. Trust-protected fields (model, variant, skills, permission, opencode, pi) are only valid in user config or OPENCODE_CONFIG_DIR config — a project config setting them has that field ignored with a warning; other fields in the same overlay still apply.",
|
|
12654
|
-
examples: [{ review: { model: "anthropic/claude-opus-5" } }, {}]
|
|
13072
|
+
examples: [{ review: { model: "anthropic/claude-opus-5-5" } }, {}]
|
|
12655
13073
|
}),
|
|
12656
13074
|
profiles: record(string2(), createProfileBundleSchema(agentNames, qualifiedAgentIds)).default({}).meta({
|
|
12657
13075
|
description: "Named routing-only overlay bundles, selectable by name via the profile field. Valid in user config and OPENCODE_CONFIG_DIR config. A project config may always select a profile, but may only define this field when the user sets allow_project_profiles; a project-defined bundle is advisory and fills only routing the user has not set.",
|
|
@@ -12978,6 +13396,13 @@ var DEFAULT_CONFIG = {
|
|
|
12978
13396
|
skills_as_commands: true,
|
|
12979
13397
|
allow_project_profiles: false
|
|
12980
13398
|
};
|
|
13399
|
+
var LAYER_TRUST = {
|
|
13400
|
+
user: "user",
|
|
13401
|
+
"user.local": "user",
|
|
13402
|
+
project: "project",
|
|
13403
|
+
custom: "custom",
|
|
13404
|
+
"custom.local": "custom"
|
|
13405
|
+
};
|
|
12981
13406
|
var PROTECTED_OVERLAY_FIELD_PATHS = {
|
|
12982
13407
|
agents: {
|
|
12983
13408
|
model: "agents.*.model",
|
|
@@ -13080,15 +13505,36 @@ function warnDroppedNames(dropped, field, warned, removalVersion, warningSink =
|
|
|
13080
13505
|
function isErrorWithCode(error) {
|
|
13081
13506
|
return error instanceof Error && "code" in error;
|
|
13082
13507
|
}
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13508
|
+
var OVERSIZED_FILE_REASON = `file is larger than ${MAX_PROJECT_CONFIG_BYTES / (1024 * 1024)} MB`;
|
|
13509
|
+
function readConfigText(filePath, maxBytes) {
|
|
13510
|
+
if (maxBytes === undefined) {
|
|
13511
|
+
try {
|
|
13512
|
+
return fs10.readFileSync(filePath, "utf-8");
|
|
13513
|
+
} catch (error) {
|
|
13514
|
+
if (isErrorWithCode(error) && error.code === "ENOENT" && !configEntryExists(filePath)) {
|
|
13515
|
+
return null;
|
|
13516
|
+
}
|
|
13517
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file`, { cause: error });
|
|
13518
|
+
}
|
|
13091
13519
|
}
|
|
13520
|
+
const read = readBytesBounded(filePath, maxBytes);
|
|
13521
|
+
switch (read.kind) {
|
|
13522
|
+
case "bytes":
|
|
13523
|
+
return read.bytes.toString("utf-8");
|
|
13524
|
+
case "absent":
|
|
13525
|
+
if (!configEntryExists(filePath))
|
|
13526
|
+
return null;
|
|
13527
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file`);
|
|
13528
|
+
case "too-large":
|
|
13529
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file (${OVERSIZED_FILE_REASON})`);
|
|
13530
|
+
default:
|
|
13531
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file`);
|
|
13532
|
+
}
|
|
13533
|
+
}
|
|
13534
|
+
function loadJsoncFile(filePath, maxBytes) {
|
|
13535
|
+
const content = readConfigText(filePath, maxBytes);
|
|
13536
|
+
if (content === null)
|
|
13537
|
+
return null;
|
|
13092
13538
|
const errors = [];
|
|
13093
13539
|
const parsed = parseJsonc2(content, errors);
|
|
13094
13540
|
if (errors.length > 0) {
|
|
@@ -13187,9 +13633,11 @@ ${formatted.map((entry) => ` - ${entry}`).join(`
|
|
|
13187
13633
|
issues
|
|
13188
13634
|
});
|
|
13189
13635
|
}
|
|
13190
|
-
function loadConfigSource(
|
|
13636
|
+
function loadConfigSource(input) {
|
|
13637
|
+
const { filePath, layer, invalidSource, warningSink, allowProjectProfiles } = input;
|
|
13638
|
+
const trust = LAYER_TRUST[layer];
|
|
13191
13639
|
try {
|
|
13192
|
-
const rawConfig = loadJsoncFile(filePath);
|
|
13640
|
+
const rawConfig = loadJsoncFile(filePath, layer === "project" ? MAX_PROJECT_CONFIG_BYTES : undefined);
|
|
13193
13641
|
if (!rawConfig) {
|
|
13194
13642
|
return {
|
|
13195
13643
|
metadata: { kind: trust, presence: "absent" },
|
|
@@ -13208,6 +13656,7 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProj
|
|
|
13208
13656
|
metadata: { kind: trust, presence: "present" },
|
|
13209
13657
|
source: {
|
|
13210
13658
|
kind: "file",
|
|
13659
|
+
layer,
|
|
13211
13660
|
canonicalPath: resolveConfigSourcePath(filePath),
|
|
13212
13661
|
config: configWithoutSearch,
|
|
13213
13662
|
path: filePath,
|
|
@@ -13220,12 +13669,10 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProj
|
|
|
13220
13669
|
} catch (error) {
|
|
13221
13670
|
if (invalidSource === "throw")
|
|
13222
13671
|
throw error;
|
|
13672
|
+
const errorCode = classifyConfigSourceError(error);
|
|
13673
|
+
input.reportInvalid(filePath, errorCode);
|
|
13223
13674
|
return {
|
|
13224
|
-
metadata: {
|
|
13225
|
-
errorCode: classifyConfigSourceError(error),
|
|
13226
|
-
kind: trust,
|
|
13227
|
-
presence: "invalid"
|
|
13228
|
-
},
|
|
13675
|
+
metadata: { errorCode, kind: trust, presence: "invalid" },
|
|
13229
13676
|
source: null
|
|
13230
13677
|
};
|
|
13231
13678
|
}
|
|
@@ -13378,6 +13825,24 @@ function mergeArraysUnique(arr1, arr2) {
|
|
|
13378
13825
|
return Array.from(set);
|
|
13379
13826
|
}
|
|
13380
13827
|
var PROFILE_DOCS_URL = "https://fro.bot/systematic/reference/configuration#profiles";
|
|
13828
|
+
function chainOf(layers) {
|
|
13829
|
+
return [
|
|
13830
|
+
layers.user,
|
|
13831
|
+
layers.userLocal,
|
|
13832
|
+
layers.project,
|
|
13833
|
+
layers.custom,
|
|
13834
|
+
layers.customLocal
|
|
13835
|
+
].filter((source) => source !== null);
|
|
13836
|
+
}
|
|
13837
|
+
function lastDefined(sources, key) {
|
|
13838
|
+
let found;
|
|
13839
|
+
for (const source of sources) {
|
|
13840
|
+
const value = source?.config[key];
|
|
13841
|
+
if (value !== undefined)
|
|
13842
|
+
found = value;
|
|
13843
|
+
}
|
|
13844
|
+
return found;
|
|
13845
|
+
}
|
|
13381
13846
|
var NO_PROFILE_SELECTION = {
|
|
13382
13847
|
activeProfile: null,
|
|
13383
13848
|
profileSelectorSource: null,
|
|
@@ -13389,10 +13854,11 @@ function resolveProfileSelector(input) {
|
|
|
13389
13854
|
const envProfile = process.env.SYSTEMATIC_PROFILE?.trim();
|
|
13390
13855
|
if (envProfile)
|
|
13391
13856
|
return { value: envProfile, source: "environment" };
|
|
13857
|
+
const { layers } = input;
|
|
13392
13858
|
const candidates = [
|
|
13393
|
-
["custom",
|
|
13394
|
-
["project",
|
|
13395
|
-
["user",
|
|
13859
|
+
["custom", lastDefined([layers.custom, layers.customLocal], "profile")],
|
|
13860
|
+
["project", layers.project?.config.profile],
|
|
13861
|
+
["user", lastDefined([layers.user, layers.userLocal], "profile")]
|
|
13396
13862
|
];
|
|
13397
13863
|
for (const [source, value] of candidates) {
|
|
13398
13864
|
if (value !== undefined)
|
|
@@ -13401,28 +13867,24 @@ function resolveProfileSelector(input) {
|
|
|
13401
13867
|
return null;
|
|
13402
13868
|
}
|
|
13403
13869
|
function lookupProfileBundle(input, name) {
|
|
13404
|
-
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
-
|
|
13415
|
-
|
|
13416
|
-
if (input.allowProjectProfiles && input.projectSource) {
|
|
13417
|
-
const bundle = input.projectSource.config.profiles?.[name];
|
|
13418
|
-
if (bundle !== undefined) {
|
|
13419
|
-
return { bundle, definingSource: input.projectSource };
|
|
13870
|
+
const { layers } = input;
|
|
13871
|
+
const lookupOrder = [
|
|
13872
|
+
layers.customLocal,
|
|
13873
|
+
layers.custom,
|
|
13874
|
+
layers.userLocal,
|
|
13875
|
+
layers.user,
|
|
13876
|
+
input.allowProjectProfiles ? layers.project : null
|
|
13877
|
+
];
|
|
13878
|
+
for (const source of lookupOrder) {
|
|
13879
|
+
const bundle = source?.config.profiles?.[name];
|
|
13880
|
+
if (source && bundle !== undefined) {
|
|
13881
|
+
return { bundle, definingSource: source };
|
|
13420
13882
|
}
|
|
13421
13883
|
}
|
|
13422
13884
|
return;
|
|
13423
13885
|
}
|
|
13424
13886
|
function trustedDefaultProfileName(input) {
|
|
13425
|
-
const userDefault = input.
|
|
13887
|
+
const userDefault = lastDefined([input.layers.user, input.layers.userLocal], "profile");
|
|
13426
13888
|
return typeof userDefault === "string" ? userDefault : undefined;
|
|
13427
13889
|
}
|
|
13428
13890
|
function selectorSourceLabel(source) {
|
|
@@ -13475,14 +13937,26 @@ function resolveActiveProfile(input) {
|
|
|
13475
13937
|
bundleSource: null
|
|
13476
13938
|
};
|
|
13477
13939
|
}
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13940
|
+
var USER_LEVEL_SLOT = {
|
|
13941
|
+
user: "user",
|
|
13942
|
+
"user.local": "userLocal",
|
|
13943
|
+
custom: "custom",
|
|
13944
|
+
"custom.local": "customLocal"
|
|
13945
|
+
};
|
|
13946
|
+
function resolveAliasedConfigFiles(paths, includeProject) {
|
|
13947
|
+
if (!includeProject)
|
|
13948
|
+
return [];
|
|
13949
|
+
const candidates = [
|
|
13950
|
+
["custom", paths.customConfig],
|
|
13951
|
+
["custom.local", paths.customLocalConfig],
|
|
13952
|
+
["user", paths.userConfig],
|
|
13953
|
+
["user.local", paths.userLocalConfig]
|
|
13954
|
+
];
|
|
13955
|
+
const project = resolveConfigSourcePath(paths.projectConfig);
|
|
13956
|
+
return candidates.flatMap(([layer, file]) => file !== undefined && resolveConfigSourcePath(file) === project ? [{ layer, path: file }] : []);
|
|
13483
13957
|
}
|
|
13484
|
-
function createAliasStripTracker(warningSink,
|
|
13485
|
-
if (
|
|
13958
|
+
function createAliasStripTracker(warningSink, aliasedFile) {
|
|
13959
|
+
if (aliasedFile === undefined) {
|
|
13486
13960
|
return { sink: warningSink, buffered: [] };
|
|
13487
13961
|
}
|
|
13488
13962
|
const buffered = [];
|
|
@@ -13494,32 +13968,33 @@ function createAliasStripTracker(warningSink, aliasedCustomConfigPath) {
|
|
|
13494
13968
|
};
|
|
13495
13969
|
}
|
|
13496
13970
|
function isAliasNoticeEligible(input) {
|
|
13497
|
-
return input.
|
|
13971
|
+
return input.aliasedFile !== undefined && input.bufferedCount > 0;
|
|
13498
13972
|
}
|
|
13499
13973
|
function emitAliasFailureDiagnostics(input) {
|
|
13500
13974
|
if (!isAliasNoticeEligible({
|
|
13501
|
-
|
|
13975
|
+
aliasedFile: input.aliasedFile,
|
|
13502
13976
|
bufferedCount: input.buffered.length
|
|
13503
13977
|
})) {
|
|
13504
13978
|
return;
|
|
13505
13979
|
}
|
|
13506
|
-
if (input.projectLoaded && input.
|
|
13980
|
+
if (input.projectLoaded && input.aliasLoaded)
|
|
13507
13981
|
return;
|
|
13508
13982
|
for (const message of input.buffered)
|
|
13509
13983
|
input.warningSink(message);
|
|
13510
13984
|
}
|
|
13511
13985
|
function buildAliasSuccessNotice(input) {
|
|
13512
13986
|
if (!isAliasNoticeEligible({
|
|
13513
|
-
|
|
13987
|
+
aliasedFile: input.aliasedFile,
|
|
13514
13988
|
bufferedCount: input.bufferedCount
|
|
13515
|
-
}) || !(input.projectLoaded && input.
|
|
13989
|
+
}) || !(input.projectLoaded && input.aliasLoaded) || input.aliasedFile === undefined) {
|
|
13516
13990
|
return;
|
|
13517
13991
|
}
|
|
13518
|
-
const
|
|
13992
|
+
const { layer, path: aliasedPath } = input.aliasedFile;
|
|
13993
|
+
const trust = LAYER_TRUST[layer];
|
|
13519
13994
|
const projectConfigPath = input.projectConfigPath;
|
|
13520
13995
|
const warningSink = input.warningSink;
|
|
13521
13996
|
return () => {
|
|
13522
|
-
warningSink(`[systematic] project config (${sanitizeDiagnosticText(projectConfigPath)}) and
|
|
13997
|
+
warningSink(`[systematic] project config (${sanitizeDiagnosticText(projectConfigPath)}) and ${layer} config (${sanitizeDiagnosticText(aliasedPath)}) resolve to the same file; protected fields stripped from the project pass (security-overlay fields, \`profiles\`, \`allow_project_profiles\`) apply through the ${trust}-trust pass instead.`);
|
|
13523
13998
|
};
|
|
13524
13999
|
}
|
|
13525
14000
|
var REMOVED_SETTINGS_DOCS_URL = "https://fro.bot/systematic/reference/configuration#removed-settings";
|
|
@@ -13535,31 +14010,128 @@ function warnRemovedKeys(sources, warningSink) {
|
|
|
13535
14010
|
}
|
|
13536
14011
|
}
|
|
13537
14012
|
}
|
|
13538
|
-
function
|
|
13539
|
-
const
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
14013
|
+
function createInvalidFileReporter(warningSink) {
|
|
14014
|
+
const reported = new Set;
|
|
14015
|
+
return (filePath, code) => {
|
|
14016
|
+
const identity = `${resolveConfigSourcePath(filePath)}\x00${code}`;
|
|
14017
|
+
if (reported.has(identity))
|
|
14018
|
+
return;
|
|
14019
|
+
reported.add(identity);
|
|
14020
|
+
warningSink(`[systematic] config file (${sanitizeDiagnosticText(filePath)}) is invalid (${code}) and was not loaded.`);
|
|
13543
14021
|
};
|
|
13544
|
-
const allowProjectProfiles = custom.source?.config.allow_project_profiles ?? user.source?.config.allow_project_profiles ?? DEFAULT_CONFIG.allow_project_profiles;
|
|
13545
|
-
return { user, custom, allowProjectProfiles };
|
|
13546
14022
|
}
|
|
13547
|
-
function
|
|
13548
|
-
const
|
|
14023
|
+
function reassignLayer(loaded, layer) {
|
|
14024
|
+
const trust = LAYER_TRUST[layer];
|
|
14025
|
+
return {
|
|
14026
|
+
metadata: { ...loaded.metadata, kind: trust },
|
|
14027
|
+
source: loaded.source && { ...loaded.source, layer, trust }
|
|
14028
|
+
};
|
|
14029
|
+
}
|
|
14030
|
+
function loadUserLevelSources(paths, context) {
|
|
14031
|
+
const loadedByRealFile = new Map;
|
|
14032
|
+
const load = (layer, filePath) => {
|
|
14033
|
+
if (filePath === undefined) {
|
|
14034
|
+
return {
|
|
14035
|
+
metadata: { kind: LAYER_TRUST[layer], presence: "absent" },
|
|
14036
|
+
source: null
|
|
14037
|
+
};
|
|
14038
|
+
}
|
|
14039
|
+
const realFile = resolveConfigSourcePath(filePath);
|
|
14040
|
+
const shared = loadedByRealFile.get(realFile);
|
|
14041
|
+
if (shared)
|
|
14042
|
+
return reassignLayer(shared, layer);
|
|
14043
|
+
const loaded = loadConfigSource({
|
|
14044
|
+
...context,
|
|
14045
|
+
filePath,
|
|
14046
|
+
layer,
|
|
14047
|
+
allowProjectProfiles: false
|
|
14048
|
+
});
|
|
14049
|
+
loadedByRealFile.set(realFile, loaded);
|
|
14050
|
+
return loaded;
|
|
14051
|
+
};
|
|
14052
|
+
const user = load("user", paths.userConfig);
|
|
14053
|
+
const userLocal = load("user.local", paths.userLocalConfig);
|
|
14054
|
+
const custom = load("custom", paths.customConfig);
|
|
14055
|
+
const customLocal = load("custom.local", paths.customLocalConfig);
|
|
14056
|
+
const allowProjectProfiles = lastDefined([user.source, userLocal.source, custom.source, customLocal.source], "allow_project_profiles") ?? DEFAULT_CONFIG.allow_project_profiles;
|
|
14057
|
+
return { user, userLocal, custom, customLocal, allowProjectProfiles };
|
|
14058
|
+
}
|
|
14059
|
+
function emitProjectLocationWarnings(paths, warningSink) {
|
|
14060
|
+
if (paths.ignoredProjectConfig !== undefined) {
|
|
14061
|
+
warningSink(`[systematic] project config (${sanitizeDiagnosticText(paths.projectConfig)}) takes precedence over (${sanitizeDiagnosticText(paths.ignoredProjectConfig)}), which is ignored; the two files are never merged.`);
|
|
14062
|
+
}
|
|
14063
|
+
if (paths.startDirProjectConfig !== undefined) {
|
|
14064
|
+
warningSink(startDirProjectWarning(paths.startDirProjectConfig, paths.projectRoot, paths.projectConfig, sanitizeDiagnosticText));
|
|
14065
|
+
}
|
|
14066
|
+
}
|
|
14067
|
+
function buildOverlaySources(profileEntry, bundleSourceTrust, layers) {
|
|
14068
|
+
const ordered = profileEntry !== null && bundleSourceTrust === "project" ? [
|
|
14069
|
+
profileEntry,
|
|
14070
|
+
layers.user,
|
|
14071
|
+
layers.userLocal,
|
|
14072
|
+
layers.project,
|
|
14073
|
+
layers.custom,
|
|
14074
|
+
layers.customLocal
|
|
14075
|
+
] : [
|
|
14076
|
+
layers.user,
|
|
14077
|
+
profileEntry,
|
|
14078
|
+
layers.userLocal,
|
|
14079
|
+
layers.project,
|
|
14080
|
+
layers.custom,
|
|
14081
|
+
layers.customLocal
|
|
14082
|
+
];
|
|
13549
14083
|
return ordered.filter((source) => source !== null);
|
|
13550
14084
|
}
|
|
14085
|
+
function buildProfileEntry(profileSelection) {
|
|
14086
|
+
const { bundle, bundleSource, activeProfile } = profileSelection;
|
|
14087
|
+
if (!bundle || !bundleSource || typeof activeProfile !== "string")
|
|
14088
|
+
return null;
|
|
14089
|
+
return {
|
|
14090
|
+
kind: "profile-bundle",
|
|
14091
|
+
canonicalPath: bundleSource.canonicalPath,
|
|
14092
|
+
path: bundleSource.path,
|
|
14093
|
+
config: { agents: bundle.agents, categories: bundle.categories },
|
|
14094
|
+
protectedFields: [],
|
|
14095
|
+
profileName: activeProfile,
|
|
14096
|
+
bundleTrust: bundleSource.trust
|
|
14097
|
+
};
|
|
14098
|
+
}
|
|
14099
|
+
function unionDisabledList(sources, key) {
|
|
14100
|
+
return sources.reduce((merged, source) => mergeArraysUnique(merged, source.config[key]), mergeArraysUnique(DEFAULT_CONFIG[key], undefined));
|
|
14101
|
+
}
|
|
14102
|
+
function mergeBootstrap(sources) {
|
|
14103
|
+
const merged = { ...DEFAULT_CONFIG.bootstrap };
|
|
14104
|
+
for (const source of sources)
|
|
14105
|
+
Object.assign(merged, source.config.bootstrap);
|
|
14106
|
+
return merged;
|
|
14107
|
+
}
|
|
13551
14108
|
function loadConfigWithSources(projectDir, options) {
|
|
13552
14109
|
const includeProject = options?.includeProject ?? true;
|
|
13553
14110
|
const invalidSource = options?.invalidSource ?? "throw";
|
|
13554
14111
|
const paths = getConfigPaths(projectDir, options);
|
|
13555
14112
|
const warningSink = options?.warningSink ?? console.warn;
|
|
13556
|
-
const
|
|
13557
|
-
|
|
14113
|
+
const reportInvalid = createInvalidFileReporter(warningSink);
|
|
14114
|
+
if (includeProject)
|
|
14115
|
+
emitProjectLocationWarnings(paths, warningSink);
|
|
14116
|
+
const aliasedFiles = resolveAliasedConfigFiles(paths, includeProject);
|
|
14117
|
+
const aliasedFile = aliasedFiles[0];
|
|
14118
|
+
const projectStrip = createAliasStripTracker(warningSink, aliasedFile);
|
|
13558
14119
|
const boundedProjectStrip = createBoundedStripWarningSink(projectStrip.sink);
|
|
13559
|
-
const
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
14120
|
+
const userLevel = loadUserLevelSources(paths, {
|
|
14121
|
+
invalidSource,
|
|
14122
|
+
reportInvalid,
|
|
14123
|
+
warningSink
|
|
14124
|
+
});
|
|
14125
|
+
const { allowProjectProfiles } = userLevel;
|
|
14126
|
+
const aliasLoaded = aliasedFiles.some(({ layer }) => userLevel[USER_LEVEL_SLOT[layer]].source !== null);
|
|
14127
|
+
const project = includeProject ? loadConfigSource({
|
|
14128
|
+
filePath: paths.projectConfig,
|
|
14129
|
+
layer: "project",
|
|
14130
|
+
invalidSource,
|
|
14131
|
+
warningSink: boundedProjectStrip.sink,
|
|
14132
|
+
reportInvalid,
|
|
14133
|
+
allowProjectProfiles
|
|
14134
|
+
}) : {
|
|
13563
14135
|
metadata: { kind: "project", presence: "absent" },
|
|
13564
14136
|
source: null
|
|
13565
14137
|
};
|
|
@@ -13572,51 +14144,48 @@ function loadConfigWithSources(projectDir, options) {
|
|
|
13572
14144
|
projectStrip.sink(`[systematic] ${suppressedStripCount} additional project-config protected-field warning(s) in (${sanitizeDiagnosticText(paths.projectConfig)}) were suppressed.`);
|
|
13573
14145
|
}
|
|
13574
14146
|
emitAliasFailureDiagnostics({
|
|
13575
|
-
|
|
14147
|
+
aliasedFile,
|
|
13576
14148
|
buffered: projectStrip.buffered,
|
|
13577
|
-
|
|
14149
|
+
aliasLoaded,
|
|
13578
14150
|
projectLoaded: project.source !== null,
|
|
13579
14151
|
warningSink
|
|
13580
14152
|
});
|
|
13581
14153
|
const emitAliasSuccessNotice = buildAliasSuccessNotice({
|
|
13582
|
-
|
|
14154
|
+
aliasedFile,
|
|
13583
14155
|
bufferedCount: projectStrip.buffered.length,
|
|
13584
|
-
|
|
14156
|
+
aliasLoaded,
|
|
13585
14157
|
projectConfigPath: paths.projectConfig,
|
|
13586
14158
|
projectLoaded: project.source !== null,
|
|
13587
14159
|
warningSink
|
|
13588
14160
|
});
|
|
13589
|
-
const
|
|
14161
|
+
const layers = {
|
|
14162
|
+
user: userLevel.user.source,
|
|
14163
|
+
userLocal: userLevel.userLocal.source,
|
|
14164
|
+
project: projectSource,
|
|
14165
|
+
custom: userLevel.custom.source,
|
|
14166
|
+
customLocal: userLevel.customLocal.source
|
|
14167
|
+
};
|
|
14168
|
+
const sources = chainOf(layers);
|
|
13590
14169
|
warnRemovedKeys(sources, warningSink);
|
|
13591
|
-
const userConfig = userSource?.config;
|
|
13592
|
-
const projectConfig = projectSource?.config;
|
|
13593
|
-
const customConfig = customSource?.config;
|
|
13594
14170
|
const warned = new Set;
|
|
13595
|
-
const mergedSearch = mergeSearchSettings([
|
|
13596
|
-
|
|
14171
|
+
const mergedSearch = mergeSearchSettings(["user", "userLocal", "custom", "customLocal"].flatMap((slot) => {
|
|
14172
|
+
const source = layers[slot];
|
|
14173
|
+
return source?.search && isUserLevelLayer(source.layer) ? [{ ...source.search, layer: source.layer }] : [];
|
|
14174
|
+
}));
|
|
14175
|
+
assertAllProfileBundlesAreValid([
|
|
14176
|
+
layers.user,
|
|
14177
|
+
layers.userLocal,
|
|
14178
|
+
layers.custom,
|
|
14179
|
+
layers.customLocal,
|
|
14180
|
+
layers.project
|
|
14181
|
+
].map((source) => source?.config));
|
|
13597
14182
|
const profileSelection = resolveActiveProfile({
|
|
13598
|
-
|
|
13599
|
-
userSource,
|
|
13600
|
-
projectConfig,
|
|
13601
|
-
projectSource,
|
|
13602
|
-
customConfig,
|
|
13603
|
-
customSource,
|
|
14183
|
+
layers,
|
|
13604
14184
|
allowProjectProfiles,
|
|
13605
14185
|
warningSink
|
|
13606
14186
|
});
|
|
13607
|
-
const profileEntry = profileSelection
|
|
13608
|
-
|
|
13609
|
-
canonicalPath: profileSelection.bundleSource.canonicalPath,
|
|
13610
|
-
path: profileSelection.bundleSource.path,
|
|
13611
|
-
config: {
|
|
13612
|
-
agents: profileSelection.bundle.agents,
|
|
13613
|
-
categories: profileSelection.bundle.categories
|
|
13614
|
-
},
|
|
13615
|
-
protectedFields: [],
|
|
13616
|
-
profileName: profileSelection.activeProfile,
|
|
13617
|
-
bundleTrust: profileSelection.bundleSource.trust
|
|
13618
|
-
} : null;
|
|
13619
|
-
const overlaySources = buildOverlaySources(profileEntry, profileSelection.bundleSource?.trust, userSource, projectSource, customSource);
|
|
14187
|
+
const profileEntry = buildProfileEntry(profileSelection);
|
|
14188
|
+
const overlaySources = buildOverlaySources(profileEntry, profileSelection.bundleSource?.trust, layers);
|
|
13620
14189
|
const mergedOverlays = mergeOverlaySources(overlaySources);
|
|
13621
14190
|
const mergedPiSubagentsOverlays = mergePiSubagentsOverlaySources(sources);
|
|
13622
14191
|
const droppedCategories = Object.keys(mergedOverlays.categories).filter((name) => REMOVED_AGENT_CATEGORIES_SET.has(name));
|
|
@@ -13626,26 +14195,21 @@ function loadConfigWithSources(projectDir, options) {
|
|
|
13626
14195
|
...mergedOverlays,
|
|
13627
14196
|
categories: Object.fromEntries(Object.entries(mergedOverlays.categories).filter(([key]) => !droppedCategorySet.has(key)))
|
|
13628
14197
|
};
|
|
13629
|
-
const mergedDisabledAgents =
|
|
14198
|
+
const mergedDisabledAgents = unionDisabledList(sources, "disabled_agents");
|
|
13630
14199
|
assertRoutingInvariants(overlays, mergedPiSubagentsOverlays, new Set(mergedDisabledAgents), warningSink);
|
|
13631
14200
|
const result = {
|
|
13632
|
-
disabled_skills:
|
|
14201
|
+
disabled_skills: unionDisabledList(sources, "disabled_skills"),
|
|
13633
14202
|
disabled_agents: mergedDisabledAgents,
|
|
13634
|
-
disabled_commands:
|
|
13635
|
-
bootstrap:
|
|
13636
|
-
...DEFAULT_CONFIG.bootstrap,
|
|
13637
|
-
...userConfig?.bootstrap,
|
|
13638
|
-
...projectConfig?.bootstrap,
|
|
13639
|
-
...customConfig?.bootstrap
|
|
13640
|
-
},
|
|
14203
|
+
disabled_commands: unionDisabledList(sources, "disabled_commands"),
|
|
14204
|
+
bootstrap: mergeBootstrap(sources),
|
|
13641
14205
|
agents: overlayValues(overlays.agents),
|
|
13642
14206
|
categories: overlayValues(overlays.categories),
|
|
13643
14207
|
pi_subagents: {
|
|
13644
14208
|
categories: overlayValues(mergedPiSubagentsOverlays.categories),
|
|
13645
14209
|
agents: overlayValues(mergedPiSubagentsOverlays.agents)
|
|
13646
14210
|
},
|
|
13647
|
-
skills_as_commands:
|
|
13648
|
-
allow_project_profiles:
|
|
14211
|
+
skills_as_commands: lastDefined(sources, "skills_as_commands") ?? DEFAULT_CONFIG.skills_as_commands,
|
|
14212
|
+
allow_project_profiles: allowProjectProfiles,
|
|
13649
14213
|
...mergedSearch.settings && { search: mergedSearch.settings },
|
|
13650
14214
|
...mergedSearch.unreadable && { searchUnreadable: true }
|
|
13651
14215
|
};
|
|
@@ -13664,29 +14228,56 @@ function loadConfigWithSources(projectDir, options) {
|
|
|
13664
14228
|
return {
|
|
13665
14229
|
config: effectiveConfig,
|
|
13666
14230
|
metadata: buildConfigObservationMetadata({
|
|
13667
|
-
custom: custom
|
|
14231
|
+
custom: foldKindMetadata("custom", [
|
|
14232
|
+
userLevel.custom.metadata,
|
|
14233
|
+
userLevel.customLocal.metadata
|
|
14234
|
+
]),
|
|
13668
14235
|
profileSelection,
|
|
13669
14236
|
project: project.metadata,
|
|
13670
|
-
sources,
|
|
13671
|
-
user: user
|
|
14237
|
+
sources: foldSiblingSources(sources),
|
|
14238
|
+
user: foldKindMetadata("user", [
|
|
14239
|
+
userLevel.user.metadata,
|
|
14240
|
+
userLevel.userLocal.metadata
|
|
14241
|
+
])
|
|
13672
14242
|
}),
|
|
13673
14243
|
overlays,
|
|
13674
14244
|
piSubagentsOverlays: mergedPiSubagentsOverlays,
|
|
13675
14245
|
activeProfileSourcePath: profileSelection.bundleSource?.path ?? null
|
|
13676
14246
|
};
|
|
13677
14247
|
}
|
|
14248
|
+
function isUserLevelLayer(layer) {
|
|
14249
|
+
return layer !== "project";
|
|
14250
|
+
}
|
|
14251
|
+
function foldSiblingSources(sources) {
|
|
14252
|
+
const byTrust = new Map;
|
|
14253
|
+
for (const source of sources) {
|
|
14254
|
+
byTrust.set(source.trust, [...byTrust.get(source.trust) ?? [], source]);
|
|
14255
|
+
}
|
|
14256
|
+
return Array.from(byTrust.values(), (files) => ({
|
|
14257
|
+
trust: files[0]?.trust ?? "user",
|
|
14258
|
+
canonicalPaths: files.map((file) => file.canonicalPath),
|
|
14259
|
+
configs: files.map((file) => file.config),
|
|
14260
|
+
protectedFields: files.flatMap((file) => file.protectedFields)
|
|
14261
|
+
}));
|
|
14262
|
+
}
|
|
14263
|
+
function foldKindMetadata(kind, files) {
|
|
14264
|
+
const invalid = files.find((file) => file.presence === "invalid");
|
|
14265
|
+
if (invalid)
|
|
14266
|
+
return invalid;
|
|
14267
|
+
return files.some((file) => file.presence === "present") ? { kind, presence: "present" } : { kind, presence: "absent" };
|
|
14268
|
+
}
|
|
13678
14269
|
function buildConfigObservationMetadata(summary) {
|
|
13679
14270
|
const authorities = [];
|
|
13680
14271
|
const sourceConfigs = new Map;
|
|
13681
14272
|
const sourcePaths = new Map;
|
|
13682
14273
|
for (const source of summary.sources) {
|
|
13683
|
-
sourceConfigs.set(source.trust, source.
|
|
13684
|
-
sourcePaths.set(source.trust, source.
|
|
14274
|
+
sourceConfigs.set(source.trust, source.configs);
|
|
14275
|
+
sourcePaths.set(source.trust, source.canonicalPaths);
|
|
13685
14276
|
}
|
|
13686
14277
|
const firstDefinedSource = (fieldPath, candidates) => {
|
|
13687
14278
|
for (const sourceKind of candidates) {
|
|
13688
|
-
const
|
|
13689
|
-
if (config
|
|
14279
|
+
const configs = sourceConfigs.get(sourceKind);
|
|
14280
|
+
if (configs?.some((config) => hasConfigField(config, fieldPath))) {
|
|
13690
14281
|
return { fieldPath, sourceKind };
|
|
13691
14282
|
}
|
|
13692
14283
|
}
|
|
@@ -13715,19 +14306,25 @@ function buildConfigObservationMetadata(summary) {
|
|
|
13715
14306
|
}
|
|
13716
14307
|
function collectVisibleProtectedFields(sources) {
|
|
13717
14308
|
const projectSource = sources.find((source) => source.trust === "project");
|
|
13718
|
-
const
|
|
13719
|
-
const
|
|
13720
|
-
return sources.flatMap((source) =>
|
|
14309
|
+
const userLevelPaths = new Set(sources.filter((source) => source.trust !== "project").flatMap((source) => source.canonicalPaths));
|
|
14310
|
+
const projectAppliedViaUserLevel = projectSource?.canonicalPaths.some((file) => userLevelPaths.has(file)) ?? false;
|
|
14311
|
+
return sources.flatMap((source) => projectAppliedViaUserLevel && source.trust === "project" ? [] : source.protectedFields);
|
|
13721
14312
|
}
|
|
13722
14313
|
function dedupeSourceMetadata(metadata, sourcePaths) {
|
|
14314
|
+
const priority = ["custom", "user", "project"];
|
|
13723
14315
|
const seen = new Set;
|
|
13724
|
-
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
|
|
13728
|
-
seen.
|
|
13729
|
-
|
|
13730
|
-
|
|
14316
|
+
const kept = new Set;
|
|
14317
|
+
for (const kind of priority) {
|
|
14318
|
+
const files = sourcePaths.get(kind) ?? [];
|
|
14319
|
+
const presence = metadata.find((source) => source.kind === kind)?.presence;
|
|
14320
|
+
const redundant = files.length > 0 && files.every((file) => seen.has(file)) && presence !== "invalid";
|
|
14321
|
+
if (redundant)
|
|
14322
|
+
continue;
|
|
14323
|
+
for (const file of files)
|
|
14324
|
+
seen.add(file);
|
|
14325
|
+
kept.add(kind);
|
|
14326
|
+
}
|
|
14327
|
+
return metadata.filter((source) => kept.has(source.kind));
|
|
13731
14328
|
}
|
|
13732
14329
|
function hasConfigField(config, fieldPath) {
|
|
13733
14330
|
const [topLevel, nested] = fieldPath.split(".");
|
|
@@ -13786,8 +14383,8 @@ function assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle
|
|
|
13786
14383
|
}
|
|
13787
14384
|
}
|
|
13788
14385
|
}
|
|
13789
|
-
function assertAllProfileBundlesAreValid(
|
|
13790
|
-
for (const config of
|
|
14386
|
+
function assertAllProfileBundlesAreValid(configs) {
|
|
14387
|
+
for (const config of configs) {
|
|
13791
14388
|
for (const [profileName, bundle] of Object.entries(config?.profiles ?? {})) {
|
|
13792
14389
|
assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle);
|
|
13793
14390
|
}
|
|
@@ -13876,7 +14473,7 @@ function resolveOverlayEntryOrigin(previous, fragment, source) {
|
|
|
13876
14473
|
const own = routingOriginsFromOwnFields(fragment, originForSource(source));
|
|
13877
14474
|
if (!previous)
|
|
13878
14475
|
return own;
|
|
13879
|
-
const preserves = source.kind === "profile-bundle" || source.
|
|
14476
|
+
const preserves = source.kind === "profile-bundle" || source.layer === "project" || source.layer === "user";
|
|
13880
14477
|
return preserves ? { ...previous, ...own } : own;
|
|
13881
14478
|
}
|
|
13882
14479
|
function resolveOverlayEntryValue(previous, next, source) {
|
|
@@ -13885,9 +14482,9 @@ function resolveOverlayEntryValue(previous, next, source) {
|
|
|
13885
14482
|
if (source.kind === "profile-bundle") {
|
|
13886
14483
|
return mergeProfileOverlayValue(previous, next);
|
|
13887
14484
|
}
|
|
13888
|
-
if (source.
|
|
14485
|
+
if (source.layer === "project")
|
|
13889
14486
|
return preserveSecurityFields(previous, next);
|
|
13890
|
-
if (source.
|
|
14487
|
+
if (source.layer === "user")
|
|
13891
14488
|
return mergeProfileOverlayValue(previous, next);
|
|
13892
14489
|
return next;
|
|
13893
14490
|
}
|
|
@@ -13987,18 +14584,42 @@ function throwInvalidOverlay(sourcePath, keyPath) {
|
|
|
13987
14584
|
throw new Error(`Invalid Systematic config in ${sourcePath}: ${keyPath} must be an object`);
|
|
13988
14585
|
}
|
|
13989
14586
|
function getConfigPaths(projectDir, options) {
|
|
13990
|
-
const
|
|
13991
|
-
const
|
|
13992
|
-
|
|
13993
|
-
|
|
14587
|
+
const dirs = resolveUserLevelConfigDirs(options);
|
|
14588
|
+
const { homeDir, customConfigDir } = dirs;
|
|
14589
|
+
const selection = selectUserLevelConfigFiles(dirs);
|
|
14590
|
+
const fileFor = (layer) => selection.files.find((file) => file.layer === layer)?.path;
|
|
14591
|
+
const userFile = (layer) => {
|
|
14592
|
+
const file = fileFor(layer);
|
|
14593
|
+
if (file === undefined) {
|
|
14594
|
+
throw new Error(`No ${layer} config file was selected`);
|
|
14595
|
+
}
|
|
14596
|
+
return file;
|
|
14597
|
+
};
|
|
14598
|
+
const repoRoot = options?.includeProject ?? true ? lookupSearchRoot(projectDir) : undefined;
|
|
14599
|
+
const projectRoot = repoRoot?.root ?? projectDir;
|
|
14600
|
+
const project = repoRoot ? selectProjectConfigFile(projectRoot) : {
|
|
14601
|
+
path: selectConfigFile(path10.join(projectDir, ".opencode"), "systematic")
|
|
14602
|
+
};
|
|
14603
|
+
const startDirProjectConfig = repoRoot ? findStartDirProjectConfig(projectDir, repoRoot, project.path) : undefined;
|
|
14604
|
+
const ignoredProjectConfig = "ignoredPath" in project ? project.ignoredPath : undefined;
|
|
14605
|
+
const customConfig = fileFor("custom");
|
|
14606
|
+
const customLocalConfig = fileFor("custom.local");
|
|
14607
|
+
return {
|
|
14608
|
+
userConfig: userFile("user"),
|
|
14609
|
+
userLocalConfig: userFile("user.local"),
|
|
14610
|
+
projectConfig: project.path,
|
|
14611
|
+
projectRoot,
|
|
13994
14612
|
userDir: path10.join(homeDir, ".config/opencode/systematic"),
|
|
13995
|
-
projectDir: path10.join(
|
|
13996
|
-
|
|
13997
|
-
|
|
14613
|
+
projectDir: path10.join(projectRoot, ".opencode/systematic"),
|
|
14614
|
+
customAliasesUser: selection.aliased,
|
|
14615
|
+
...ignoredProjectConfig !== undefined && { ignoredProjectConfig },
|
|
14616
|
+
...startDirProjectConfig !== undefined && { startDirProjectConfig },
|
|
14617
|
+
...customConfigDir && customConfig !== undefined && customLocalConfig !== undefined && {
|
|
14618
|
+
customConfig,
|
|
14619
|
+
customLocalConfig,
|
|
13998
14620
|
customDir: path10.join(customConfigDir, "systematic")
|
|
13999
14621
|
}
|
|
14000
14622
|
};
|
|
14001
|
-
return result;
|
|
14002
14623
|
}
|
|
14003
14624
|
|
|
14004
14625
|
// src/lib/pi-delegate-session.ts
|