@fro.bot/systematic 3.30.1 → 3.31.1
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 +5 -5
- package/dist/cli.d.ts +13 -9
- package/dist/cli.js +140 -31
- package/dist/{index-10dym2d9.js → index-8rz6cepj.js} +2593 -1864
- 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 +45 -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 +193 -13
- package/dist/pi.js +876 -258
- package/package.json +1 -1
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,24 @@ 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 projectRootRejectionWarning(sourceName, rejection) {
|
|
3473
|
+
return rejection === "outside" ? `${sourceName} resolves outside the project root; not loaded` : `${sourceName}: ${PROJECT_ROOT_REJECTION_REASONS[rejection]}; source dropped`;
|
|
3474
|
+
}
|
|
3475
|
+
function rejectedProjectRoot(checkoutRoot, root) {
|
|
3476
|
+
const symlinked = symlinkedComponent(checkoutRoot, root);
|
|
3477
|
+
if (symlinked !== undefined)
|
|
3478
|
+
return symlinked;
|
|
3479
|
+
const container = probeRealpath(checkoutRoot);
|
|
3480
|
+
const directory = probeRealpath(root);
|
|
3481
|
+
if (container.kind !== "ok" || directory.kind !== "ok")
|
|
3482
|
+
return;
|
|
3483
|
+
return isInside(container.value, directory.value) ? undefined : "outside";
|
|
3484
|
+
}
|
|
3459
3485
|
function classifyEntry(spec, name, stat) {
|
|
3460
3486
|
if (stat === null || stat.isSymbolicLink())
|
|
3461
3487
|
return "ignored";
|
|
@@ -3484,6 +3510,13 @@ function listWalkedDirectory(budget, label, directory, prefix, warnings) {
|
|
|
3484
3510
|
}
|
|
3485
3511
|
return listing.names;
|
|
3486
3512
|
}
|
|
3513
|
+
function addCandidate(found, candidate) {
|
|
3514
|
+
if (found.candidates.length >= MAX_DISCOVERED_FILES) {
|
|
3515
|
+
found.truncated = true;
|
|
3516
|
+
return;
|
|
3517
|
+
}
|
|
3518
|
+
found.candidates.push(candidate);
|
|
3519
|
+
}
|
|
3487
3520
|
function discoverFiles(spec, label, directory, prefix, depth, found, warnings) {
|
|
3488
3521
|
const names = listWalkedDirectory(found.budget, label, directory, prefix, warnings);
|
|
3489
3522
|
if (names === null) {
|
|
@@ -3495,6 +3528,8 @@ function discoverFiles(spec, label, directory, prefix, depth, found, warnings) {
|
|
|
3495
3528
|
for (const name of names) {
|
|
3496
3529
|
if (found.truncated)
|
|
3497
3530
|
return;
|
|
3531
|
+
if (found.isExcluded?.(`${prefix}${name}`) === true)
|
|
3532
|
+
continue;
|
|
3498
3533
|
const absolute = path2.join(directory, name);
|
|
3499
3534
|
const stat = safeLstat(absolute);
|
|
3500
3535
|
const entryKind = classifyEntry(spec, name, stat);
|
|
@@ -3502,11 +3537,7 @@ function discoverFiles(spec, label, directory, prefix, depth, found, warnings) {
|
|
|
3502
3537
|
const child = `${prefix}${name}/`;
|
|
3503
3538
|
discoverFiles(spec, label, absolute, child, depth + 1, found, warnings);
|
|
3504
3539
|
} else if (entryKind === "file" && stat !== null) {
|
|
3505
|
-
|
|
3506
|
-
found.truncated = true;
|
|
3507
|
-
return;
|
|
3508
|
-
}
|
|
3509
|
-
found.candidates.push({
|
|
3540
|
+
addCandidate(found, {
|
|
3510
3541
|
relative: `${prefix}${name}`,
|
|
3511
3542
|
absolute,
|
|
3512
3543
|
size: stat.size
|
|
@@ -3584,7 +3615,7 @@ function parseCorpusDocument(kind, relativePath, content) {
|
|
|
3584
3615
|
};
|
|
3585
3616
|
}
|
|
3586
3617
|
function discoverSourceFiles(options, warnings) {
|
|
3587
|
-
const { directory, containedIn, walk, label, entryBudget } = options;
|
|
3618
|
+
const { directory, containedIn, walk, label, entryBudget, isExcluded } = options;
|
|
3588
3619
|
const directoryProbe = probeRealpath(directory);
|
|
3589
3620
|
const containerProbe = containedIn === undefined ? undefined : probeRealpath(containedIn);
|
|
3590
3621
|
if (containerProbe?.kind === "failed" || directoryProbe.kind === "failed") {
|
|
@@ -3611,7 +3642,8 @@ function discoverSourceFiles(options, warnings) {
|
|
|
3611
3642
|
candidates: [],
|
|
3612
3643
|
truncated: false,
|
|
3613
3644
|
rootUnreadable: false,
|
|
3614
|
-
budget: entryBudget
|
|
3645
|
+
budget: entryBudget,
|
|
3646
|
+
isExcluded
|
|
3615
3647
|
};
|
|
3616
3648
|
discoverFiles(walk, label, directoryReal, "", 0, found, warnings);
|
|
3617
3649
|
if (found.rootUnreadable) {
|
|
@@ -3745,6 +3777,183 @@ function loadCorpus(root, kind = "solution") {
|
|
|
3745
3777
|
// src/lib/search-external.ts
|
|
3746
3778
|
import path4 from "node:path";
|
|
3747
3779
|
|
|
3780
|
+
// src/lib/search-exclude.ts
|
|
3781
|
+
var MAX_EXCLUDE_PATTERNS = 64;
|
|
3782
|
+
var MAX_EXCLUDE_PATTERN_LENGTH = 256;
|
|
3783
|
+
var REASON_NOT_A_STRING = "not a string";
|
|
3784
|
+
var REASON_NOT_AN_ARRAY = "not an array";
|
|
3785
|
+
var REASON_EMPTY = "empty pattern";
|
|
3786
|
+
var REASON_TOO_LONG = `longer than ${MAX_EXCLUDE_PATTERN_LENGTH} characters`;
|
|
3787
|
+
var REASON_BACKSLASH = "backslash is not supported, use / between segments";
|
|
3788
|
+
var REASON_NEGATION = "negation with ! is not supported";
|
|
3789
|
+
var REASON_LEADING_SLASH = "starts with /, patterns are relative to the source root";
|
|
3790
|
+
var REASON_LEADING_DOT_SLASH = "starts with ./, write the path without it";
|
|
3791
|
+
var REASON_CHARACTER_CLASS = "character classes with [ ] are not supported";
|
|
3792
|
+
var REASON_EMPTY_SEGMENT = "contains an empty path segment";
|
|
3793
|
+
var REASON_DOT_SEGMENT = "contains a . path segment";
|
|
3794
|
+
var REASON_DOT_DOT_SEGMENT = "contains a .. path segment";
|
|
3795
|
+
var REASON_EMBEDDED_GLOBSTAR = "** must be a whole path segment";
|
|
3796
|
+
var GLOBSTAR = "**";
|
|
3797
|
+
function invalid(reason) {
|
|
3798
|
+
return { ok: false, reason };
|
|
3799
|
+
}
|
|
3800
|
+
var WHOLE_PATTERN_RULES = [
|
|
3801
|
+
[(pattern) => pattern.length === 0, REASON_EMPTY],
|
|
3802
|
+
[(pattern) => pattern.length > MAX_EXCLUDE_PATTERN_LENGTH, REASON_TOO_LONG],
|
|
3803
|
+
[(pattern) => pattern.includes("\\"), REASON_BACKSLASH],
|
|
3804
|
+
[(pattern) => pattern.startsWith("!"), REASON_NEGATION],
|
|
3805
|
+
[(pattern) => pattern.startsWith("/"), REASON_LEADING_SLASH],
|
|
3806
|
+
[(pattern) => pattern.startsWith("./"), REASON_LEADING_DOT_SLASH],
|
|
3807
|
+
[
|
|
3808
|
+
(pattern) => pattern.includes("[") || pattern.includes("]"),
|
|
3809
|
+
REASON_CHARACTER_CLASS
|
|
3810
|
+
]
|
|
3811
|
+
];
|
|
3812
|
+
function segmentProblem(segment) {
|
|
3813
|
+
if (segment.length === 0)
|
|
3814
|
+
return REASON_EMPTY_SEGMENT;
|
|
3815
|
+
if (segment === ".")
|
|
3816
|
+
return REASON_DOT_SEGMENT;
|
|
3817
|
+
if (segment === "..")
|
|
3818
|
+
return REASON_DOT_DOT_SEGMENT;
|
|
3819
|
+
if (segment !== GLOBSTAR && segment.includes(GLOBSTAR)) {
|
|
3820
|
+
return REASON_EMBEDDED_GLOBSTAR;
|
|
3821
|
+
}
|
|
3822
|
+
return;
|
|
3823
|
+
}
|
|
3824
|
+
function parsePattern(pattern) {
|
|
3825
|
+
if (typeof pattern !== "string")
|
|
3826
|
+
return invalid(REASON_NOT_A_STRING);
|
|
3827
|
+
for (const [applies, reason] of WHOLE_PATTERN_RULES) {
|
|
3828
|
+
if (applies(pattern))
|
|
3829
|
+
return invalid(reason);
|
|
3830
|
+
}
|
|
3831
|
+
const body = pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
3832
|
+
const segments = [];
|
|
3833
|
+
for (const segment of body.split("/")) {
|
|
3834
|
+
const problem = segmentProblem(segment);
|
|
3835
|
+
if (problem !== undefined)
|
|
3836
|
+
return invalid(problem);
|
|
3837
|
+
if (segment === GLOBSTAR && segments[segments.length - 1] === GLOBSTAR) {
|
|
3838
|
+
continue;
|
|
3839
|
+
}
|
|
3840
|
+
segments.push(segment);
|
|
3841
|
+
}
|
|
3842
|
+
return {
|
|
3843
|
+
ok: true,
|
|
3844
|
+
compiled: { segments, nameOnly: !body.includes("/") }
|
|
3845
|
+
};
|
|
3846
|
+
}
|
|
3847
|
+
function validateExcludePattern(pattern) {
|
|
3848
|
+
const parsed = parsePattern(pattern);
|
|
3849
|
+
return parsed.ok ? { ok: true } : { ok: false, reason: parsed.reason };
|
|
3850
|
+
}
|
|
3851
|
+
function validateExcludeList(value) {
|
|
3852
|
+
if (!Array.isArray(value))
|
|
3853
|
+
return { ok: false, reason: REASON_NOT_AN_ARRAY };
|
|
3854
|
+
const patterns = [];
|
|
3855
|
+
const issues = [];
|
|
3856
|
+
const inspected = Math.min(value.length, MAX_EXCLUDE_PATTERNS);
|
|
3857
|
+
for (let index = 0;index < inspected; index++) {
|
|
3858
|
+
const element = value[index];
|
|
3859
|
+
const verdict = validateExcludePattern(element);
|
|
3860
|
+
if (verdict.ok && typeof element === "string") {
|
|
3861
|
+
patterns.push(element);
|
|
3862
|
+
} else if (!verdict.ok) {
|
|
3863
|
+
issues.push({ index, reason: verdict.reason });
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
if (value.length > MAX_EXCLUDE_PATTERNS) {
|
|
3867
|
+
const dropped = value.length - MAX_EXCLUDE_PATTERNS;
|
|
3868
|
+
issues.push({
|
|
3869
|
+
index: MAX_EXCLUDE_PATTERNS,
|
|
3870
|
+
reason: `${dropped} ${dropped === 1 ? "pattern" : "patterns"} over the limit of ${MAX_EXCLUDE_PATTERNS}`
|
|
3871
|
+
});
|
|
3872
|
+
}
|
|
3873
|
+
return { ok: true, patterns, issues };
|
|
3874
|
+
}
|
|
3875
|
+
function compileExcludePattern(pattern) {
|
|
3876
|
+
const parsed = parsePattern(pattern);
|
|
3877
|
+
return parsed.ok ? parsed.compiled : undefined;
|
|
3878
|
+
}
|
|
3879
|
+
function characterLength(text, index) {
|
|
3880
|
+
const high = text.charCodeAt(index);
|
|
3881
|
+
if (high >= 55296 && high <= 56319 && index + 1 < text.length) {
|
|
3882
|
+
const low = text.charCodeAt(index + 1);
|
|
3883
|
+
if (low >= 56320 && low <= 57343)
|
|
3884
|
+
return 2;
|
|
3885
|
+
}
|
|
3886
|
+
return 1;
|
|
3887
|
+
}
|
|
3888
|
+
function matchSegment(pattern, text) {
|
|
3889
|
+
let p = 0;
|
|
3890
|
+
let t = 0;
|
|
3891
|
+
let starP = -1;
|
|
3892
|
+
let starT = 0;
|
|
3893
|
+
while (t < text.length) {
|
|
3894
|
+
const code = p < pattern.length ? pattern.charCodeAt(p) : -1;
|
|
3895
|
+
if (code === 42) {
|
|
3896
|
+
starP = p;
|
|
3897
|
+
starT = t;
|
|
3898
|
+
p++;
|
|
3899
|
+
} else if (code === 63) {
|
|
3900
|
+
p++;
|
|
3901
|
+
t += characterLength(text, t);
|
|
3902
|
+
} else if (code !== -1 && code === text.charCodeAt(t)) {
|
|
3903
|
+
p++;
|
|
3904
|
+
t++;
|
|
3905
|
+
} else if (starP !== -1) {
|
|
3906
|
+
starT += characterLength(text, starT);
|
|
3907
|
+
t = starT;
|
|
3908
|
+
p = starP + 1;
|
|
3909
|
+
} else {
|
|
3910
|
+
return false;
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
while (p < pattern.length && pattern.charCodeAt(p) === 42)
|
|
3914
|
+
p++;
|
|
3915
|
+
return p === pattern.length;
|
|
3916
|
+
}
|
|
3917
|
+
function matchAnchored(pattern, path) {
|
|
3918
|
+
let reached = new Array(pattern.length + 1).fill(false);
|
|
3919
|
+
reached[0] = true;
|
|
3920
|
+
for (let j = 1;j <= pattern.length; j++) {
|
|
3921
|
+
reached[j] = pattern[j - 1] === GLOBSTAR && reached[j - 1] === true;
|
|
3922
|
+
}
|
|
3923
|
+
for (const segment of path) {
|
|
3924
|
+
const next = new Array(pattern.length + 1).fill(false);
|
|
3925
|
+
for (let j = 1;j <= pattern.length; j++) {
|
|
3926
|
+
const part = pattern[j - 1] ?? "";
|
|
3927
|
+
next[j] = part === GLOBSTAR ? next[j - 1] === true || reached[j] === true : reached[j - 1] === true && matchSegment(part, segment);
|
|
3928
|
+
}
|
|
3929
|
+
reached = next;
|
|
3930
|
+
}
|
|
3931
|
+
return reached[pattern.length] === true;
|
|
3932
|
+
}
|
|
3933
|
+
function matchesCompiled(compiled, relativePath) {
|
|
3934
|
+
if (compiled.nameOnly) {
|
|
3935
|
+
const name = relativePath.slice(relativePath.lastIndexOf("/") + 1);
|
|
3936
|
+
const part = compiled.segments[0] ?? "";
|
|
3937
|
+
return part === GLOBSTAR || matchSegment(part, name);
|
|
3938
|
+
}
|
|
3939
|
+
return matchAnchored(compiled.segments, relativePath.split("/"));
|
|
3940
|
+
}
|
|
3941
|
+
function compileExcludePatterns(patterns) {
|
|
3942
|
+
const compiled = [];
|
|
3943
|
+
for (const pattern of patterns) {
|
|
3944
|
+
const one = compileExcludePattern(pattern);
|
|
3945
|
+
if (one !== undefined)
|
|
3946
|
+
compiled.push(one);
|
|
3947
|
+
}
|
|
3948
|
+
if (compiled.length === 0)
|
|
3949
|
+
return () => false;
|
|
3950
|
+
return (relativePath) => {
|
|
3951
|
+
if (relativePath.length === 0)
|
|
3952
|
+
return false;
|
|
3953
|
+
return compiled.some((entry) => matchesCompiled(entry, relativePath));
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3748
3957
|
// src/lib/search-external-deciduous.ts
|
|
3749
3958
|
import fs4 from "node:fs";
|
|
3750
3959
|
import path3 from "node:path";
|
|
@@ -3788,9 +3997,11 @@ function probeRoot(root, containedIn) {
|
|
|
3788
3997
|
}
|
|
3789
3998
|
return { kind: "ok", real };
|
|
3790
3999
|
}
|
|
3791
|
-
function classifyJsonEntry(directory, folder, name, skips) {
|
|
4000
|
+
function classifyJsonEntry(directory, folder, name, skips, isExcluded) {
|
|
3792
4001
|
if (!name.endsWith(JSON_SUFFIX))
|
|
3793
4002
|
return;
|
|
4003
|
+
if (isExcluded(`${folder}/${name}`))
|
|
4004
|
+
return;
|
|
3794
4005
|
const absolute = path3.join(directory, name);
|
|
3795
4006
|
const entry = safeLstat(absolute);
|
|
3796
4007
|
if (entry === null)
|
|
@@ -3819,7 +4030,9 @@ function statFolder(directory) {
|
|
|
3819
4030
|
return { kind: isAbsence2(error) ? "absent" : "failed" };
|
|
3820
4031
|
}
|
|
3821
4032
|
}
|
|
3822
|
-
function scanFolder(rootReal, folder, limit, skips, budget) {
|
|
4033
|
+
function scanFolder(rootReal, folder, limit, skips, budget, isExcluded) {
|
|
4034
|
+
if (isExcluded(folder))
|
|
4035
|
+
return folderScan("excluded");
|
|
3823
4036
|
const directory = path3.join(rootReal, folder);
|
|
3824
4037
|
const probed = statFolder(directory);
|
|
3825
4038
|
if (probed.kind === "absent")
|
|
@@ -3839,7 +4052,7 @@ function scanFolder(rootReal, folder, limit, skips, budget) {
|
|
|
3839
4052
|
names.sort(compareCodeUnits);
|
|
3840
4053
|
const candidates = [];
|
|
3841
4054
|
for (const name of names) {
|
|
3842
|
-
const candidate = classifyJsonEntry(directory, folder, name, skips);
|
|
4055
|
+
const candidate = classifyJsonEntry(directory, folder, name, skips, isExcluded);
|
|
3843
4056
|
if (candidate === undefined)
|
|
3844
4057
|
continue;
|
|
3845
4058
|
if (candidates.length >= limit) {
|
|
@@ -3854,18 +4067,14 @@ function probeRoots(input, warnings) {
|
|
|
3854
4067
|
const reals = [];
|
|
3855
4068
|
let unreadable = false;
|
|
3856
4069
|
for (const root of input.roots) {
|
|
3857
|
-
const
|
|
3858
|
-
if (
|
|
3859
|
-
warnings.push(
|
|
3860
|
-
return { kind: "dropped" };
|
|
3861
|
-
}
|
|
3862
|
-
if (symlinked === "ancestor") {
|
|
3863
|
-
warnings.push(`${name}: a project root passes through a symlink; source dropped`);
|
|
4070
|
+
const rejection = containedIn === undefined ? undefined : rejectedProjectRoot(containedIn, root);
|
|
4071
|
+
if (rejection !== undefined) {
|
|
4072
|
+
warnings.push(projectRootRejectionWarning(name, rejection));
|
|
3864
4073
|
return { kind: "dropped" };
|
|
3865
4074
|
}
|
|
3866
4075
|
const probe = probeRoot(root, containedIn);
|
|
3867
4076
|
if (probe.kind === "outside") {
|
|
3868
|
-
warnings.push(
|
|
4077
|
+
warnings.push(projectRootRejectionWarning(name, "outside"));
|
|
3869
4078
|
return { kind: "dropped" };
|
|
3870
4079
|
}
|
|
3871
4080
|
if (probe.kind === "unreadable") {
|
|
@@ -3883,14 +4092,16 @@ function newTally() {
|
|
|
3883
4092
|
return {
|
|
3884
4093
|
files: new Map,
|
|
3885
4094
|
listed: false,
|
|
4095
|
+
excluded: false,
|
|
3886
4096
|
unreadable: false,
|
|
3887
4097
|
truncated: false
|
|
3888
4098
|
};
|
|
3889
4099
|
}
|
|
3890
|
-
function scanRoots(reals, folder, tally, otherCount, skips, budget) {
|
|
4100
|
+
function scanRoots(reals, folder, tally, otherCount, skips, budget, isExcluded) {
|
|
3891
4101
|
for (const real of reals) {
|
|
3892
|
-
const scan = scanFolder(real, folder, Math.max(MAX_DISCOVERED_FILES - otherCount - tally.files.size, 0), skips, budget);
|
|
4102
|
+
const scan = scanFolder(real, folder, Math.max(MAX_DISCOVERED_FILES - otherCount - tally.files.size, 0), skips, budget, isExcluded);
|
|
3893
4103
|
tally.listed = tally.listed || scan.status === "listed";
|
|
4104
|
+
tally.excluded = tally.excluded || scan.status === "excluded";
|
|
3894
4105
|
tally.unreadable = tally.unreadable || scan.status === "unreadable";
|
|
3895
4106
|
tally.truncated = tally.truncated || scan.truncated;
|
|
3896
4107
|
for (const candidate of scan.candidates) {
|
|
@@ -3917,8 +4128,9 @@ function gather(input, skips, warnings) {
|
|
|
3917
4128
|
const budget = newEntryBudget(limit);
|
|
3918
4129
|
const nodes = newTally();
|
|
3919
4130
|
const edges = newTally();
|
|
3920
|
-
|
|
3921
|
-
scanRoots(reals, "
|
|
4131
|
+
const isExcluded = input.isExcluded ?? (() => false);
|
|
4132
|
+
scanRoots(reals, "nodes", nodes, 0, skips, budget, isExcluded);
|
|
4133
|
+
scanRoots(reals, "edges", edges, nodes.files.size, skips, budget, isExcluded);
|
|
3922
4134
|
warnings.push(...folderWarnings(input.name, "nodes", nodes), ...folderWarnings(input.name, "edges", edges));
|
|
3923
4135
|
if (budget.exhausted) {
|
|
3924
4136
|
warnings.push(`${input.name}: entry limit of ${limit} reached; some entries were not examined`);
|
|
@@ -3931,6 +4143,8 @@ function gather(input, skips, warnings) {
|
|
|
3931
4143
|
rootsFound: reals.length,
|
|
3932
4144
|
anyNodesFolder: nodes.listed,
|
|
3933
4145
|
anyEdgesFolder: edges.listed,
|
|
4146
|
+
nodesExcluded: nodes.excluded,
|
|
4147
|
+
edgesExcluded: edges.excluded,
|
|
3934
4148
|
nodesUnreadable: nodes.unreadable,
|
|
3935
4149
|
edgesUnreadable: edges.unreadable,
|
|
3936
4150
|
truncated: nodes.truncated || edges.truncated,
|
|
@@ -4181,7 +4395,7 @@ function loadDeciduousRecords(input) {
|
|
|
4181
4395
|
return nothing("unreadable", warnings.map(cleanForWarning));
|
|
4182
4396
|
}
|
|
4183
4397
|
if (nodeless === "empty") {
|
|
4184
|
-
if (!gathered.anyNodesFolder) {
|
|
4398
|
+
if (!gathered.anyNodesFolder && !gathered.nodesExcluded) {
|
|
4185
4399
|
warnings.push(`${name}: no nodes/ folder; nothing to index`);
|
|
4186
4400
|
}
|
|
4187
4401
|
warnings.push(...skipWarnings(name, skips, input.maxFileBytes));
|
|
@@ -4200,7 +4414,7 @@ function loadDeciduousRecords(input) {
|
|
|
4200
4414
|
};
|
|
4201
4415
|
const scan = readNodes(gathered.nodes, input, reader, skips);
|
|
4202
4416
|
readEdges(gathered.edges, scan, input, reader, skips);
|
|
4203
|
-
if (!gathered.anyEdgesFolder && !gathered.edgesUnreadable) {
|
|
4417
|
+
if (!gathered.anyEdgesFolder && !gathered.edgesUnreadable && !gathered.edgesExcluded) {
|
|
4204
4418
|
warnings.push(`${name}: no edges/ folder; records carry no rationale`);
|
|
4205
4419
|
}
|
|
4206
4420
|
warnings.push(...skipWarnings(name, skips, input.maxFileBytes), ...limitWarnings(name, {
|
|
@@ -4301,17 +4515,11 @@ function finishGather(source, merge, warnings) {
|
|
|
4301
4515
|
const candidates = [...merge.candidates.values()].sort((a, b) => compareCodeUnits(a.relative, b.relative));
|
|
4302
4516
|
return { kind: "gathered", candidates, truncated: merge.truncated };
|
|
4303
4517
|
}
|
|
4304
|
-
function
|
|
4518
|
+
function projectRootWarning(source, context, root) {
|
|
4305
4519
|
if (source.origin !== "project")
|
|
4306
4520
|
return;
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
return "a project root is a symlink";
|
|
4310
|
-
case "ancestor":
|
|
4311
|
-
return "a project root passes through a symlink";
|
|
4312
|
-
default:
|
|
4313
|
-
return;
|
|
4314
|
-
}
|
|
4521
|
+
const rejection = rejectedProjectRoot(context.checkoutRoot, root);
|
|
4522
|
+
return rejection === undefined ? undefined : projectRootRejectionWarning(source.name, rejection);
|
|
4315
4523
|
}
|
|
4316
4524
|
function gatherCandidates(source, context, warnings) {
|
|
4317
4525
|
const { name, origin } = source;
|
|
@@ -4327,10 +4535,11 @@ function gatherCandidates(source, context, warnings) {
|
|
|
4327
4535
|
outcome: nothing2(source, "dropped", warnings)
|
|
4328
4536
|
});
|
|
4329
4537
|
const entryBudget = newEntryBudget(context.entryLimit);
|
|
4538
|
+
const isExcluded = compileExcludePatterns(source.exclude);
|
|
4330
4539
|
for (const root of source.roots) {
|
|
4331
|
-
const
|
|
4332
|
-
if (
|
|
4333
|
-
warnings.push(
|
|
4540
|
+
const rootWarning = projectRootWarning(source, context, root);
|
|
4541
|
+
if (rootWarning !== undefined) {
|
|
4542
|
+
warnings.push(rootWarning);
|
|
4334
4543
|
return drop();
|
|
4335
4544
|
}
|
|
4336
4545
|
const discovery = discoverSourceFiles({
|
|
@@ -4338,6 +4547,7 @@ function gatherCandidates(source, context, warnings) {
|
|
|
4338
4547
|
containedIn: origin === "project" ? context.checkoutRoot : undefined,
|
|
4339
4548
|
walk: MARKDOWN_WALK,
|
|
4340
4549
|
entryBudget,
|
|
4550
|
+
isExcluded,
|
|
4341
4551
|
label: name
|
|
4342
4552
|
}, warnings);
|
|
4343
4553
|
if (discovery.state === "outside")
|
|
@@ -4398,7 +4608,8 @@ function loadDeciduousSource(source, context) {
|
|
|
4398
4608
|
containedIn: origin === "project" ? context.checkoutRoot : undefined,
|
|
4399
4609
|
remainingBytes: context.remainingBytes,
|
|
4400
4610
|
maxFileBytes: EXTERNAL_MAX_FILE_BYTES,
|
|
4401
|
-
entryLimit: context.entryLimit
|
|
4611
|
+
entryLimit: context.entryLimit,
|
|
4612
|
+
isExcluded: compileExcludePatterns(source.exclude)
|
|
4402
4613
|
});
|
|
4403
4614
|
return {
|
|
4404
4615
|
name,
|
|
@@ -10410,11 +10621,19 @@ var sourceProjectsSchema = array(string2().min(1)).optional().meta({
|
|
|
10410
10621
|
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
10622
|
examples: [["~/src/github.com/me/app"]]
|
|
10412
10623
|
});
|
|
10624
|
+
var sourceExcludeSchema = array(string2()).optional().meta({
|
|
10625
|
+
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.`,
|
|
10626
|
+
examples: [
|
|
10627
|
+
["log.md", ".stryker-tmp"],
|
|
10628
|
+
["drafts/*.md", "archive/**/old"]
|
|
10629
|
+
]
|
|
10630
|
+
});
|
|
10413
10631
|
var SearchSourceSchema = object({
|
|
10414
10632
|
name: sourceNameSchema,
|
|
10415
10633
|
format: sourceFormatSchema,
|
|
10416
10634
|
roots: sourceRootsSchema,
|
|
10417
|
-
projects: sourceProjectsSchema
|
|
10635
|
+
projects: sourceProjectsSchema,
|
|
10636
|
+
exclude: sourceExcludeSchema
|
|
10418
10637
|
}).strict().meta({
|
|
10419
10638
|
description: "One opt-in decision source: a name, a format and one or more roots.",
|
|
10420
10639
|
examples: [{ name: "team-rfcs", format: "markdown", roots: ["docs/rfcs"] }]
|
|
@@ -10497,6 +10716,9 @@ function unknownKeyWarning(trust, sourcePath) {
|
|
|
10497
10716
|
function entryWarning(sourcePath, label, reason) {
|
|
10498
10717
|
return `[systematic] search source ${label} in ${sourcePath} was dropped: ${reason}. Its valid siblings still load.`;
|
|
10499
10718
|
}
|
|
10719
|
+
function excludeWarning(sourcePath, label, issue) {
|
|
10720
|
+
return `[systematic] \`exclude[${issue.index}]\` of search source ${label} in ${sourcePath} was dropped: ${issue.reason}. The source and its other patterns still load.`;
|
|
10721
|
+
}
|
|
10500
10722
|
function isTildePath(value) {
|
|
10501
10723
|
return value === "~" || value.startsWith("~/") || value.startsWith("~\\");
|
|
10502
10724
|
}
|
|
@@ -10522,7 +10744,8 @@ var ENTRY_KEYS = new Set([
|
|
|
10522
10744
|
"name",
|
|
10523
10745
|
"format",
|
|
10524
10746
|
"roots",
|
|
10525
|
-
"projects"
|
|
10747
|
+
"projects",
|
|
10748
|
+
"exclude"
|
|
10526
10749
|
]);
|
|
10527
10750
|
function isFormat(value) {
|
|
10528
10751
|
return typeof value === "string" && SEARCH_SOURCE_FORMATS.includes(value);
|
|
@@ -10582,21 +10805,30 @@ function validateEntry(raw, index, trust) {
|
|
|
10582
10805
|
const projects = validateProjects(raw.projects, trust);
|
|
10583
10806
|
if (typeof projects === "string")
|
|
10584
10807
|
return rejectEntry(label, projects);
|
|
10808
|
+
const exclude = Object.hasOwn(raw, "exclude") ? validateExcludeList(raw.exclude) : undefined;
|
|
10809
|
+
if (exclude?.ok === false) {
|
|
10810
|
+
return rejectEntry(label, `exclude is invalid (${exclude.reason})`);
|
|
10811
|
+
}
|
|
10812
|
+
const patterns = exclude?.patterns ?? [];
|
|
10585
10813
|
return {
|
|
10586
10814
|
ok: true,
|
|
10587
10815
|
entry: {
|
|
10588
10816
|
name,
|
|
10589
10817
|
format,
|
|
10590
10818
|
roots: [...roots],
|
|
10591
|
-
...projects !== undefined && { projects: [...projects] }
|
|
10592
|
-
|
|
10819
|
+
...projects !== undefined && { projects: [...projects] },
|
|
10820
|
+
...patterns.length > 0 && { exclude: [...patterns] }
|
|
10821
|
+
},
|
|
10822
|
+
excludeIssues: exclude?.issues ?? []
|
|
10593
10823
|
};
|
|
10594
10824
|
}
|
|
10595
10825
|
function warn(state, message) {
|
|
10596
|
-
if (state.warnings.length < MAX_DETAIL_WARNINGS)
|
|
10826
|
+
if (state.warnings.length < MAX_DETAIL_WARNINGS) {
|
|
10597
10827
|
state.warnings.push(message);
|
|
10598
|
-
|
|
10599
|
-
|
|
10828
|
+
return true;
|
|
10829
|
+
}
|
|
10830
|
+
state.suppressed += 1;
|
|
10831
|
+
return false;
|
|
10600
10832
|
}
|
|
10601
10833
|
function validateSources(raw, state) {
|
|
10602
10834
|
if (!Array.isArray(raw)) {
|
|
@@ -10610,18 +10842,43 @@ function validateSources(raw, state) {
|
|
|
10610
10842
|
raw.forEach((item, index) => {
|
|
10611
10843
|
const result = validateEntry(item, index, state.trust);
|
|
10612
10844
|
if (!result.ok) {
|
|
10613
|
-
|
|
10845
|
+
dropEntry(state, index, result.label, result.reason);
|
|
10614
10846
|
return;
|
|
10615
10847
|
}
|
|
10616
10848
|
if (seen.has(result.entry.name)) {
|
|
10617
|
-
|
|
10849
|
+
dropEntry(state, index, `"${result.entry.name}"`, "the name is already used earlier in this file, so the first entry is kept");
|
|
10618
10850
|
return;
|
|
10619
10851
|
}
|
|
10620
10852
|
seen.add(result.entry.name);
|
|
10621
10853
|
kept.push(result.entry);
|
|
10854
|
+
const label = `"${result.entry.name}"`;
|
|
10855
|
+
const warnings = [];
|
|
10856
|
+
for (const issue of result.excludeIssues) {
|
|
10857
|
+
const message = excludeWarning(state.sourcePath, label, issue);
|
|
10858
|
+
if (warn(state, message))
|
|
10859
|
+
warnings.push(message);
|
|
10860
|
+
}
|
|
10861
|
+
state.entries.push({
|
|
10862
|
+
kind: "kept",
|
|
10863
|
+
index,
|
|
10864
|
+
label,
|
|
10865
|
+
entry: result.entry,
|
|
10866
|
+
warnings
|
|
10867
|
+
});
|
|
10622
10868
|
});
|
|
10623
10869
|
return kept;
|
|
10624
10870
|
}
|
|
10871
|
+
function dropEntry(state, index, label, reason) {
|
|
10872
|
+
state.dropped.push({ label, reason });
|
|
10873
|
+
const message = entryWarning(state.sourcePath, label, reason);
|
|
10874
|
+
state.entries.push({
|
|
10875
|
+
kind: "dropped",
|
|
10876
|
+
index,
|
|
10877
|
+
label,
|
|
10878
|
+
reason,
|
|
10879
|
+
warnings: warn(state, message) ? [message] : []
|
|
10880
|
+
});
|
|
10881
|
+
}
|
|
10625
10882
|
function validateAllowList(raw, state) {
|
|
10626
10883
|
if (!Array.isArray(raw)) {
|
|
10627
10884
|
state.unreadable = true;
|
|
@@ -10671,6 +10928,8 @@ function validateSearchConfig(value, trust, sourcePath) {
|
|
|
10671
10928
|
trust,
|
|
10672
10929
|
sourcePath: displaySafe(sourcePath),
|
|
10673
10930
|
warnings: [],
|
|
10931
|
+
dropped: [],
|
|
10932
|
+
entries: [],
|
|
10674
10933
|
suppressed: 0,
|
|
10675
10934
|
unreadable: false,
|
|
10676
10935
|
structural: false
|
|
@@ -10681,7 +10940,9 @@ function validateSearchConfig(value, trust, sourcePath) {
|
|
|
10681
10940
|
settings: undefined,
|
|
10682
10941
|
unreadable: true,
|
|
10683
10942
|
structural: true,
|
|
10684
|
-
warnings: state.warnings
|
|
10943
|
+
warnings: state.warnings,
|
|
10944
|
+
dropped: state.dropped,
|
|
10945
|
+
entries: state.entries
|
|
10685
10946
|
};
|
|
10686
10947
|
}
|
|
10687
10948
|
const settings = {};
|
|
@@ -10703,20 +10964,31 @@ function validateSearchConfig(value, trust, sourcePath) {
|
|
|
10703
10964
|
settings,
|
|
10704
10965
|
unreadable: state.unreadable,
|
|
10705
10966
|
structural: state.structural,
|
|
10706
|
-
warnings: state.warnings
|
|
10967
|
+
warnings: state.warnings,
|
|
10968
|
+
dropped: state.dropped,
|
|
10969
|
+
entries: state.entries
|
|
10707
10970
|
};
|
|
10708
10971
|
}
|
|
10972
|
+
function withoutEntryWarnings(validation) {
|
|
10973
|
+
const aboutEntries = new Set(validation.entries.flatMap((entry) => entry.warnings));
|
|
10974
|
+
return validation.warnings.filter((warning) => !aboutEntries.has(warning));
|
|
10975
|
+
}
|
|
10709
10976
|
function formatSearchFileWarning(sourcePath, reason) {
|
|
10710
10977
|
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
10978
|
}
|
|
10712
10979
|
function mergeSearchSettings(sources) {
|
|
10713
|
-
const acc = {
|
|
10980
|
+
const acc = {
|
|
10981
|
+
allow: [],
|
|
10982
|
+
byName: new Map,
|
|
10983
|
+
layers: new Map
|
|
10984
|
+
};
|
|
10714
10985
|
let unreadable = false;
|
|
10715
10986
|
for (const source of sources) {
|
|
10716
10987
|
if (source.unreadable)
|
|
10717
10988
|
unreadable = true;
|
|
10718
|
-
if (source.settings !== undefined)
|
|
10719
|
-
absorb(acc, source.settings);
|
|
10989
|
+
if (source.settings !== undefined) {
|
|
10990
|
+
absorb(acc, source.settings, source.layer);
|
|
10991
|
+
}
|
|
10720
10992
|
}
|
|
10721
10993
|
const merged = {
|
|
10722
10994
|
...acc.enabled !== undefined && { enabled: acc.enabled },
|
|
@@ -10724,23 +10996,37 @@ function mergeSearchSettings(sources) {
|
|
|
10724
10996
|
...acc.byName.size > 0 && { sources: [...acc.byName.values()] }
|
|
10725
10997
|
};
|
|
10726
10998
|
if (Object.keys(merged).length === 0) {
|
|
10727
|
-
return { settings: undefined, unreadable };
|
|
10999
|
+
return { settings: undefined, unreadable, sourceLayers: acc.layers };
|
|
10728
11000
|
}
|
|
10729
|
-
return { settings: merged, unreadable };
|
|
11001
|
+
return { settings: merged, unreadable, sourceLayers: acc.layers };
|
|
10730
11002
|
}
|
|
10731
|
-
function absorb(acc, settings) {
|
|
11003
|
+
function absorb(acc, settings, layer) {
|
|
10732
11004
|
if (settings.enabled !== undefined)
|
|
10733
11005
|
acc.enabled = settings.enabled;
|
|
10734
11006
|
for (const entry of settings.allow_project_sources ?? []) {
|
|
10735
11007
|
if (!acc.allow.includes(entry))
|
|
10736
11008
|
acc.allow.push(entry);
|
|
10737
11009
|
}
|
|
10738
|
-
for (const entry of settings.sources ?? [])
|
|
11010
|
+
for (const entry of settings.sources ?? []) {
|
|
10739
11011
|
acc.byName.set(entry.name, entry);
|
|
11012
|
+
if (layer === undefined)
|
|
11013
|
+
acc.layers.delete(entry.name);
|
|
11014
|
+
else
|
|
11015
|
+
acc.layers.set(entry.name, layer);
|
|
11016
|
+
}
|
|
11017
|
+
}
|
|
11018
|
+
function configEntryExists(target) {
|
|
11019
|
+
try {
|
|
11020
|
+
fs6.lstatSync(target);
|
|
11021
|
+
return true;
|
|
11022
|
+
} catch (error) {
|
|
11023
|
+
const code = errorCode2(error);
|
|
11024
|
+
return code !== "ENOENT" && code !== "ENOTDIR";
|
|
11025
|
+
}
|
|
10740
11026
|
}
|
|
10741
11027
|
function selectConfigFile(dir, basename) {
|
|
10742
11028
|
const jsoncPath = path6.join(dir, `${basename}.jsonc`);
|
|
10743
|
-
if (
|
|
11029
|
+
if (configEntryExists(jsoncPath))
|
|
10744
11030
|
return jsoncPath;
|
|
10745
11031
|
return path6.join(dir, `${basename}.json`);
|
|
10746
11032
|
}
|
|
@@ -10750,6 +11036,55 @@ function resolveUserLevelConfigDirs(options) {
|
|
|
10750
11036
|
const rawCustom = options !== undefined && Object.hasOwn(options, "customConfigDir") ? options.customConfigDir?.trim() : process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
10751
11037
|
return { homeDir, userConfigDir, customConfigDir: rawCustom || undefined };
|
|
10752
11038
|
}
|
|
11039
|
+
function realpathOrResolved(dir) {
|
|
11040
|
+
const resolved = path6.resolve(dir);
|
|
11041
|
+
try {
|
|
11042
|
+
return fs6.realpathSync(resolved);
|
|
11043
|
+
} catch {
|
|
11044
|
+
return resolved;
|
|
11045
|
+
}
|
|
11046
|
+
}
|
|
11047
|
+
function selectUserLevelConfigFiles(dirs) {
|
|
11048
|
+
const files = [
|
|
11049
|
+
{
|
|
11050
|
+
layer: "user",
|
|
11051
|
+
path: selectConfigFile(dirs.userConfigDir, "systematic")
|
|
11052
|
+
},
|
|
11053
|
+
{
|
|
11054
|
+
layer: "user.local",
|
|
11055
|
+
path: selectConfigFile(dirs.userConfigDir, "systematic.local")
|
|
11056
|
+
}
|
|
11057
|
+
];
|
|
11058
|
+
const custom = dirs.customConfigDir;
|
|
11059
|
+
if (!custom)
|
|
11060
|
+
return { files, aliased: false };
|
|
11061
|
+
files.push({ layer: "custom", path: selectConfigFile(custom, "systematic") }, {
|
|
11062
|
+
layer: "custom.local",
|
|
11063
|
+
path: selectConfigFile(custom, "systematic.local")
|
|
11064
|
+
});
|
|
11065
|
+
const aliased = path6.resolve(custom) === path6.resolve(dirs.userConfigDir) || realpathOrResolved(custom) === realpathOrResolved(dirs.userConfigDir);
|
|
11066
|
+
return { files, aliased };
|
|
11067
|
+
}
|
|
11068
|
+
function selectProjectConfigFile(repoRoot) {
|
|
11069
|
+
const opencodeFile = selectConfigFile(path6.join(repoRoot, ".opencode"), "systematic");
|
|
11070
|
+
const rootFile = selectConfigFile(repoRoot, ".systematic");
|
|
11071
|
+
if (!configEntryExists(rootFile))
|
|
11072
|
+
return { path: opencodeFile };
|
|
11073
|
+
return configEntryExists(opencodeFile) ? { path: rootFile, ignoredPath: opencodeFile } : { path: rootFile };
|
|
11074
|
+
}
|
|
11075
|
+
function findStartDirProjectConfig(startDir, repoRoot, selectedProjectConfig) {
|
|
11076
|
+
if (!repoRoot.foundGit)
|
|
11077
|
+
return;
|
|
11078
|
+
if (realpathOrResolved(startDir) === repoRoot.root)
|
|
11079
|
+
return;
|
|
11080
|
+
const candidate = selectConfigFile(path6.join(startDir, ".opencode"), "systematic");
|
|
11081
|
+
if (!configEntryExists(candidate))
|
|
11082
|
+
return;
|
|
11083
|
+
return realpathOrResolved(candidate) === realpathOrResolved(selectedProjectConfig) ? undefined : candidate;
|
|
11084
|
+
}
|
|
11085
|
+
function startDirProjectWarning(startDirConfig, projectRoot, selectedProjectConfig, safe = displaySafe) {
|
|
11086
|
+
return `[systematic] project config (${safe(startDirConfig)}) is below the repository root (${safe(projectRoot)}) and is not read; project config is read from (${safe(selectedProjectConfig)}).`;
|
|
11087
|
+
}
|
|
10753
11088
|
function errorCode2(error) {
|
|
10754
11089
|
return error instanceof Error && "code" in error ? error.code : undefined;
|
|
10755
11090
|
}
|
|
@@ -10760,7 +11095,7 @@ function readTextBounded(filePath, maxBytes) {
|
|
|
10760
11095
|
case "bytes":
|
|
10761
11096
|
return { kind: "text", content: read.bytes.toString("utf-8") };
|
|
10762
11097
|
case "absent":
|
|
10763
|
-
return
|
|
11098
|
+
return absentOrDangling(filePath);
|
|
10764
11099
|
case "not-regular":
|
|
10765
11100
|
return { kind: "failed", reason: "not a regular file" };
|
|
10766
11101
|
case "too-large":
|
|
@@ -10772,17 +11107,12 @@ function readTextBounded(filePath, maxBytes) {
|
|
|
10772
11107
|
return { kind: "failed", reason: "unable to read file" };
|
|
10773
11108
|
}
|
|
10774
11109
|
}
|
|
10775
|
-
function
|
|
10776
|
-
|
|
10777
|
-
return { kind: "text", content: fs6.readFileSync(filePath, "utf-8") };
|
|
10778
|
-
} catch (error) {
|
|
10779
|
-
if (errorCode2(error) === "ENOENT")
|
|
10780
|
-
return { kind: "absent" };
|
|
10781
|
-
return { kind: "failed", reason: "unable to read file" };
|
|
10782
|
-
}
|
|
11110
|
+
function absentOrDangling(filePath) {
|
|
11111
|
+
return configEntryExists(filePath) ? { kind: "failed", reason: "unable to read file" } : { kind: "absent" };
|
|
10783
11112
|
}
|
|
11113
|
+
var USER_LEVEL_FILE_MAX_BYTES = Number.POSITIVE_INFINITY;
|
|
10784
11114
|
function readSearchBlock(filePath, maxBytes) {
|
|
10785
|
-
const text =
|
|
11115
|
+
const text = readTextBounded(filePath, maxBytes ?? USER_LEVEL_FILE_MAX_BYTES);
|
|
10786
11116
|
if (text.kind !== "text")
|
|
10787
11117
|
return text;
|
|
10788
11118
|
const content = text.content;
|
|
@@ -10804,58 +11134,111 @@ function readSearchBlock(filePath, maxBytes) {
|
|
|
10804
11134
|
searchBlock: parsed.search
|
|
10805
11135
|
};
|
|
10806
11136
|
}
|
|
11137
|
+
var NOTHING_READ = {
|
|
11138
|
+
source: undefined,
|
|
11139
|
+
warnings: [],
|
|
11140
|
+
readFailures: [],
|
|
11141
|
+
dropped: [],
|
|
11142
|
+
entries: []
|
|
11143
|
+
};
|
|
11144
|
+
function readUserLevelFile(file) {
|
|
11145
|
+
const read = readSearchBlock(file.path);
|
|
11146
|
+
if (read.kind === "absent")
|
|
11147
|
+
return NOTHING_READ;
|
|
11148
|
+
if (read.kind === "failed") {
|
|
11149
|
+
const warning = formatSearchFileWarning(file.path, read.reason);
|
|
11150
|
+
return {
|
|
11151
|
+
source: { unreadable: true },
|
|
11152
|
+
warnings: [warning],
|
|
11153
|
+
readFailures: [warning],
|
|
11154
|
+
dropped: [],
|
|
11155
|
+
entries: []
|
|
11156
|
+
};
|
|
11157
|
+
}
|
|
11158
|
+
if (!read.has)
|
|
11159
|
+
return NOTHING_READ;
|
|
11160
|
+
const validation = validateSearchConfig(read.searchBlock, "user", file.path);
|
|
11161
|
+
return {
|
|
11162
|
+
source: {
|
|
11163
|
+
settings: validation.settings,
|
|
11164
|
+
unreadable: validation.unreadable
|
|
11165
|
+
},
|
|
11166
|
+
warnings: validation.warnings,
|
|
11167
|
+
readFailures: [],
|
|
11168
|
+
dropped: validation.dropped,
|
|
11169
|
+
entries: validation.entries
|
|
11170
|
+
};
|
|
11171
|
+
}
|
|
11172
|
+
var ALIASED_TWIN = { custom: "user", "custom.local": "user.local" };
|
|
10807
11173
|
function loadUserLevelSearchSettings(options) {
|
|
10808
|
-
const
|
|
10809
|
-
const files = [
|
|
10810
|
-
selectConfigFile(dirs.userConfigDir, "systematic"),
|
|
10811
|
-
...dirs.customConfigDir ? [selectConfigFile(dirs.customConfigDir, "systematic")] : []
|
|
10812
|
-
];
|
|
11174
|
+
const selection = selectUserLevelConfigFiles(resolveUserLevelConfigDirs(options));
|
|
10813
11175
|
const warnings = [];
|
|
11176
|
+
const readFailures = [];
|
|
11177
|
+
const dropped = [];
|
|
11178
|
+
const entries = [];
|
|
10814
11179
|
const sources = [];
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
11180
|
+
const reads = new Map;
|
|
11181
|
+
for (const file of selection.files) {
|
|
11182
|
+
const twin = selection.aliased ? ALIASED_TWIN[file.layer] : undefined;
|
|
11183
|
+
const shared = twin === undefined ? undefined : reads.get(twin);
|
|
11184
|
+
const read = shared ?? readUserLevelFile(file);
|
|
11185
|
+
reads.set(file.layer, read);
|
|
11186
|
+
if (read.source)
|
|
11187
|
+
sources.push({ ...read.source, layer: file.layer });
|
|
11188
|
+
if (shared !== undefined)
|
|
10822
11189
|
continue;
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
warnings.push(...validation.warnings);
|
|
10828
|
-
sources.push({
|
|
10829
|
-
settings: validation.settings,
|
|
10830
|
-
unreadable: validation.unreadable
|
|
10831
|
-
});
|
|
11190
|
+
warnings.push(...read.warnings);
|
|
11191
|
+
readFailures.push(...read.readFailures);
|
|
11192
|
+
dropped.push(...read.dropped);
|
|
11193
|
+
entries.push(...read.entries);
|
|
10832
11194
|
}
|
|
10833
11195
|
const merged = mergeSearchSettings(sources);
|
|
10834
|
-
return {
|
|
11196
|
+
return {
|
|
11197
|
+
settings: merged.settings,
|
|
11198
|
+
unreadable: merged.unreadable,
|
|
11199
|
+
warnings,
|
|
11200
|
+
dropped,
|
|
11201
|
+
entries,
|
|
11202
|
+
sourceLayers: merged.sourceLayers,
|
|
11203
|
+
readFailures
|
|
11204
|
+
};
|
|
10835
11205
|
}
|
|
10836
11206
|
function formatProjectFileWarning(sourcePath, reason) {
|
|
10837
11207
|
return `[systematic] project search settings in ${displaySafe(sourcePath)} could not be read (${reason}); the sources it proposes were ignored.`;
|
|
10838
11208
|
}
|
|
11209
|
+
function formatShadowedProjectWarning(usedPath, ignoredPath) {
|
|
11210
|
+
return `[systematic] project config (${displaySafe(usedPath)}) takes precedence over (${displaySafe(ignoredPath)}), which is ignored; the two files are never merged.`;
|
|
11211
|
+
}
|
|
10839
11212
|
function loadProjectSearchSources(checkoutRoot) {
|
|
10840
|
-
const
|
|
11213
|
+
const selection = selectProjectConfigFile(checkoutRoot);
|
|
11214
|
+
const filePath = selection.path;
|
|
11215
|
+
const shadowed = selection.ignoredPath === undefined ? [] : [formatShadowedProjectWarning(filePath, selection.ignoredPath)];
|
|
10841
11216
|
const read = readSearchBlock(filePath, MAX_PROJECT_CONFIG_BYTES);
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
11217
|
+
const nothing = {
|
|
11218
|
+
sources: [],
|
|
11219
|
+
warnings: shadowed,
|
|
11220
|
+
unreadable: false,
|
|
11221
|
+
dropped: [],
|
|
11222
|
+
entries: []
|
|
11223
|
+
};
|
|
11224
|
+
if (read.kind === "absent")
|
|
11225
|
+
return nothing;
|
|
10845
11226
|
if (read.kind === "failed") {
|
|
10846
11227
|
return {
|
|
10847
|
-
|
|
10848
|
-
warnings: [formatProjectFileWarning(filePath, read.reason)],
|
|
11228
|
+
...nothing,
|
|
11229
|
+
warnings: [...shadowed, formatProjectFileWarning(filePath, read.reason)],
|
|
10849
11230
|
unreadable: true
|
|
10850
11231
|
};
|
|
10851
11232
|
}
|
|
10852
11233
|
if (!read.has)
|
|
10853
|
-
return
|
|
11234
|
+
return nothing;
|
|
10854
11235
|
const validation = validateSearchConfig(read.searchBlock, "project", filePath);
|
|
10855
11236
|
return {
|
|
10856
11237
|
sources: validation.structural ? [] : validation.settings?.sources ?? [],
|
|
10857
|
-
warnings: validation.warnings,
|
|
10858
|
-
unreadable: validation.structural
|
|
11238
|
+
warnings: [...shadowed, ...validation.warnings],
|
|
11239
|
+
unreadable: validation.structural,
|
|
11240
|
+
dropped: validation.dropped,
|
|
11241
|
+
entries: validation.entries
|
|
10859
11242
|
};
|
|
10860
11243
|
}
|
|
10861
11244
|
|
|
@@ -10876,22 +11259,51 @@ function capWarning(dropped) {
|
|
|
10876
11259
|
const names = `${listed.join(", ")}${more > 0 ? ` and ${more} more` : ""}`;
|
|
10877
11260
|
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
11261
|
}
|
|
10879
|
-
function
|
|
10880
|
-
return declared.filter((entry) => entry.projects !== undefined && isAllowedProject(identity, entry.projects, { homeDir }))
|
|
11262
|
+
function mappedUserEntries(declared, identity, homeDir) {
|
|
11263
|
+
return declared.filter((entry) => entry.projects !== undefined && isAllowedProject(identity, entry.projects, { homeDir }));
|
|
11264
|
+
}
|
|
11265
|
+
function userSourceOf(entry, homeDir) {
|
|
11266
|
+
return {
|
|
10881
11267
|
name: entry.name,
|
|
10882
11268
|
format: entry.format,
|
|
10883
11269
|
roots: entry.roots.map((root) => expandHome2(root, homeDir)),
|
|
10884
|
-
origin: "user"
|
|
10885
|
-
|
|
11270
|
+
origin: "user",
|
|
11271
|
+
exclude: entry.exclude ?? []
|
|
11272
|
+
};
|
|
11273
|
+
}
|
|
11274
|
+
function mappedUserSources(declared, identity, homeDir) {
|
|
11275
|
+
return mappedUserEntries(declared, identity, homeDir).map((entry) => userSourceOf(entry, homeDir));
|
|
11276
|
+
}
|
|
11277
|
+
function projectSourceOf(entry, checkoutRoot) {
|
|
11278
|
+
return {
|
|
11279
|
+
name: entry.name,
|
|
11280
|
+
format: entry.format,
|
|
11281
|
+
roots: entry.roots.map((root) => path7.resolve(checkoutRoot, root)),
|
|
11282
|
+
origin: "project",
|
|
11283
|
+
exclude: entry.exclude ?? []
|
|
11284
|
+
};
|
|
11285
|
+
}
|
|
11286
|
+
function projectSourcesOf(proposals, checkoutRoot, shadowed) {
|
|
11287
|
+
return proposals.filter((entry) => !shadowed.has(entry.name)).map((entry) => projectSourceOf(entry, checkoutRoot));
|
|
11288
|
+
}
|
|
11289
|
+
function forwardedProjectWarnings(project, projectAllowed) {
|
|
11290
|
+
return projectAllowed ? project.warnings : withoutEntryWarnings(project);
|
|
11291
|
+
}
|
|
11292
|
+
function startDirWarnings(startDir, lookup, checkoutRoot) {
|
|
11293
|
+
const selected = selectProjectConfigFile(checkoutRoot).path;
|
|
11294
|
+
const ignored = findStartDirProjectConfig(startDir, lookup, selected);
|
|
11295
|
+
return ignored === undefined ? [] : [startDirProjectWarning(ignored, checkoutRoot, selected)];
|
|
10886
11296
|
}
|
|
10887
11297
|
function resolveExternalSources(input) {
|
|
10888
11298
|
const dirs = resolveUserLevelConfigDirs(input.configOptions);
|
|
10889
11299
|
const homeDir = dirs.homeDir || os3.homedir();
|
|
10890
|
-
const
|
|
11300
|
+
const lookup = lookupSearchRoot(input.startDir);
|
|
11301
|
+
const checkoutRoot = lookup.foundGit ? lookup.root : resolveSearchRoot(input.startDir);
|
|
10891
11302
|
const identity = input.identity ?? resolveProjectIdentity(checkoutRoot);
|
|
10892
11303
|
const user = loadUserLevelSearchSettings(input.configOptions);
|
|
10893
11304
|
const allow = user.settings?.allow_project_sources ?? [];
|
|
10894
11305
|
const project = loadProjectSearchSources(checkoutRoot);
|
|
11306
|
+
const projectAllowed = isAllowedProject(identity, allow, { homeDir });
|
|
10895
11307
|
const userSources = mappedUserSources(user.settings?.sources ?? [], identity, homeDir);
|
|
10896
11308
|
let projectState;
|
|
10897
11309
|
let projectSources = [];
|
|
@@ -10900,30 +11312,26 @@ function resolveExternalSources(input) {
|
|
|
10900
11312
|
projectState = { kind: "config-unreadable" };
|
|
10901
11313
|
} else if (proposals === 0) {
|
|
10902
11314
|
projectState = { kind: "none" };
|
|
10903
|
-
} else if (
|
|
11315
|
+
} else if (projectAllowed) {
|
|
10904
11316
|
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
|
-
}));
|
|
11317
|
+
projectSources = projectSourcesOf(project.sources, checkoutRoot, new Set(userSources.map((source) => source.name)));
|
|
10912
11318
|
} else {
|
|
10913
11319
|
projectState = identity.status === "resolved" ? { kind: "not-allowed", proposals, mainRoot: identity.mainRoot } : { kind: "not-allowed", proposals };
|
|
10914
11320
|
}
|
|
10915
11321
|
const ordered = [...userSources, ...projectSources];
|
|
10916
11322
|
const sources = ordered.slice(0, MAX_ACTIVE_SOURCES);
|
|
10917
|
-
const
|
|
11323
|
+
const capped = ordered.slice(MAX_ACTIVE_SOURCES);
|
|
10918
11324
|
return {
|
|
10919
11325
|
sources,
|
|
10920
11326
|
project: projectState,
|
|
10921
11327
|
userConfigUnreadable: user.unreadable,
|
|
10922
11328
|
warnings: [
|
|
10923
|
-
...
|
|
11329
|
+
...capped.length > 0 ? [capWarning(capped)] : [],
|
|
10924
11330
|
...user.warnings,
|
|
10925
|
-
...
|
|
10926
|
-
|
|
11331
|
+
...startDirWarnings(input.startDir, lookup, checkoutRoot),
|
|
11332
|
+
...forwardedProjectWarnings(project, projectAllowed)
|
|
11333
|
+
],
|
|
11334
|
+
dropped: { user: user.dropped, project: project.dropped }
|
|
10927
11335
|
};
|
|
10928
11336
|
}
|
|
10929
11337
|
|
|
@@ -12192,6 +12600,7 @@ ${skillUsage}${ruleSection}${profileSection}
|
|
|
12192
12600
|
|
|
12193
12601
|
// src/lib/config.ts
|
|
12194
12602
|
import fs10 from "node:fs";
|
|
12603
|
+
import os5 from "node:os";
|
|
12195
12604
|
import path10 from "node:path";
|
|
12196
12605
|
import {
|
|
12197
12606
|
parse as parseJsonc2,
|
|
@@ -12978,6 +13387,13 @@ var DEFAULT_CONFIG = {
|
|
|
12978
13387
|
skills_as_commands: true,
|
|
12979
13388
|
allow_project_profiles: false
|
|
12980
13389
|
};
|
|
13390
|
+
var LAYER_TRUST = {
|
|
13391
|
+
user: "user",
|
|
13392
|
+
"user.local": "user",
|
|
13393
|
+
project: "project",
|
|
13394
|
+
custom: "custom",
|
|
13395
|
+
"custom.local": "custom"
|
|
13396
|
+
};
|
|
12981
13397
|
var PROTECTED_OVERLAY_FIELD_PATHS = {
|
|
12982
13398
|
agents: {
|
|
12983
13399
|
model: "agents.*.model",
|
|
@@ -13077,18 +13493,29 @@ function warnDroppedNames(dropped, field, warned, removalVersion, warningSink =
|
|
|
13077
13493
|
warningSink(`[systematic] "${displayName}" in \`${field}\` is no longer a bundled name and will be ignored.${removalNote} Remove it from your config to silence this warning. See ${MIGRATION_DOCS_URL} for migration guidance.`);
|
|
13078
13494
|
}
|
|
13079
13495
|
}
|
|
13080
|
-
|
|
13081
|
-
|
|
13082
|
-
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13496
|
+
var OVERSIZED_FILE_REASON = `file is larger than ${MAX_PROJECT_CONFIG_BYTES / (1024 * 1024)} MB`;
|
|
13497
|
+
var USER_LEVEL_CONFIG_MAX_BYTES = Number.POSITIVE_INFINITY;
|
|
13498
|
+
function readConfigText(filePath, maxBytes) {
|
|
13499
|
+
const read = readBytesBounded(filePath, maxBytes);
|
|
13500
|
+
switch (read.kind) {
|
|
13501
|
+
case "bytes":
|
|
13502
|
+
return read.bytes.toString("utf-8");
|
|
13503
|
+
case "absent":
|
|
13504
|
+
if (!configEntryExists(filePath))
|
|
13505
|
+
return null;
|
|
13506
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file`);
|
|
13507
|
+
case "too-large":
|
|
13508
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file (${OVERSIZED_FILE_REASON})`);
|
|
13509
|
+
case "not-regular":
|
|
13510
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file (not a regular file)`);
|
|
13511
|
+
default:
|
|
13512
|
+
throw new Error(`Invalid Systematic config in ${filePath}: unable to read file`);
|
|
13091
13513
|
}
|
|
13514
|
+
}
|
|
13515
|
+
function loadJsoncFile(filePath, maxBytes) {
|
|
13516
|
+
const content = readConfigText(filePath, maxBytes);
|
|
13517
|
+
if (content === null)
|
|
13518
|
+
return null;
|
|
13092
13519
|
const errors = [];
|
|
13093
13520
|
const parsed = parseJsonc2(content, errors);
|
|
13094
13521
|
if (errors.length > 0) {
|
|
@@ -13187,9 +13614,18 @@ ${formatted.map((entry) => ` - ${entry}`).join(`
|
|
|
13187
13614
|
issues
|
|
13188
13615
|
});
|
|
13189
13616
|
}
|
|
13190
|
-
function loadConfigSource(
|
|
13617
|
+
function loadConfigSource(input) {
|
|
13618
|
+
const {
|
|
13619
|
+
filePath,
|
|
13620
|
+
layer,
|
|
13621
|
+
invalidSource,
|
|
13622
|
+
warningSink,
|
|
13623
|
+
allowProjectProfiles,
|
|
13624
|
+
projectAllowed
|
|
13625
|
+
} = input;
|
|
13626
|
+
const trust = LAYER_TRUST[layer];
|
|
13191
13627
|
try {
|
|
13192
|
-
const rawConfig = loadJsoncFile(filePath);
|
|
13628
|
+
const rawConfig = loadJsoncFile(filePath, layer === "project" ? MAX_PROJECT_CONFIG_BYTES : USER_LEVEL_CONFIG_MAX_BYTES);
|
|
13193
13629
|
if (!rawConfig) {
|
|
13194
13630
|
return {
|
|
13195
13631
|
metadata: { kind: trust, presence: "absent" },
|
|
@@ -13199,7 +13635,7 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProj
|
|
|
13199
13635
|
const protectedFields = collectProjectProtectedFields(rawConfig, trust, allowProjectProfiles);
|
|
13200
13636
|
const topLevelStripped = trust === "project" ? stripProjectProtectedFields(rawConfig, allowProjectProfiles) : rawConfig;
|
|
13201
13637
|
const config = trust === "project" ? stripProjectSecurityOverlayFields(topLevelStripped, filePath, warningSink) : topLevelStripped;
|
|
13202
|
-
const { config: configWithoutSearch, search } = splitSearchBlock(config, filePath, trust, warningSink);
|
|
13638
|
+
const { config: configWithoutSearch, search } = splitSearchBlock(config, filePath, trust, warningSink, projectAllowed);
|
|
13203
13639
|
const result = SystematicConfigSchema.safeParse(configWithoutSearch);
|
|
13204
13640
|
if (!result.success) {
|
|
13205
13641
|
throwTopLevelConfigSchemaError(filePath, trust, result.error.issues, configWithoutSearch);
|
|
@@ -13208,6 +13644,7 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProj
|
|
|
13208
13644
|
metadata: { kind: trust, presence: "present" },
|
|
13209
13645
|
source: {
|
|
13210
13646
|
kind: "file",
|
|
13647
|
+
layer,
|
|
13211
13648
|
canonicalPath: resolveConfigSourcePath(filePath),
|
|
13212
13649
|
config: configWithoutSearch,
|
|
13213
13650
|
path: filePath,
|
|
@@ -13220,22 +13657,22 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProj
|
|
|
13220
13657
|
} catch (error) {
|
|
13221
13658
|
if (invalidSource === "throw")
|
|
13222
13659
|
throw error;
|
|
13660
|
+
const errorCode = classifyConfigSourceError(error);
|
|
13661
|
+
input.reportInvalid(filePath, errorCode);
|
|
13223
13662
|
return {
|
|
13224
|
-
metadata: {
|
|
13225
|
-
errorCode: classifyConfigSourceError(error),
|
|
13226
|
-
kind: trust,
|
|
13227
|
-
presence: "invalid"
|
|
13228
|
-
},
|
|
13663
|
+
metadata: { errorCode, kind: trust, presence: "invalid" },
|
|
13229
13664
|
source: null
|
|
13230
13665
|
};
|
|
13231
13666
|
}
|
|
13232
13667
|
}
|
|
13233
|
-
function splitSearchBlock(config, filePath, trust, warningSink) {
|
|
13668
|
+
function splitSearchBlock(config, filePath, trust, warningSink, projectAllowed) {
|
|
13234
13669
|
if (!Object.hasOwn(config, "search"))
|
|
13235
13670
|
return { config, search: undefined };
|
|
13236
13671
|
const { search: rawSearch, ...rest } = config;
|
|
13237
13672
|
const validation = validateSearchConfig(rawSearch, trust === "project" ? "project" : "user", filePath);
|
|
13238
|
-
|
|
13673
|
+
const hideEntryWarnings = trust === "project" && validation.entries.some((entry) => entry.warnings.length > 0) && !projectAllowed();
|
|
13674
|
+
const warnings = hideEntryWarnings ? withoutEntryWarnings(validation) : validation.warnings;
|
|
13675
|
+
for (const message of warnings)
|
|
13239
13676
|
warningSink(message);
|
|
13240
13677
|
return {
|
|
13241
13678
|
config: rest,
|
|
@@ -13378,6 +13815,24 @@ function mergeArraysUnique(arr1, arr2) {
|
|
|
13378
13815
|
return Array.from(set);
|
|
13379
13816
|
}
|
|
13380
13817
|
var PROFILE_DOCS_URL = "https://fro.bot/systematic/reference/configuration#profiles";
|
|
13818
|
+
function chainOf(layers) {
|
|
13819
|
+
return [
|
|
13820
|
+
layers.user,
|
|
13821
|
+
layers.userLocal,
|
|
13822
|
+
layers.project,
|
|
13823
|
+
layers.custom,
|
|
13824
|
+
layers.customLocal
|
|
13825
|
+
].filter((source) => source !== null);
|
|
13826
|
+
}
|
|
13827
|
+
function lastDefined(sources, key) {
|
|
13828
|
+
let found;
|
|
13829
|
+
for (const source of sources) {
|
|
13830
|
+
const value = source?.config[key];
|
|
13831
|
+
if (value !== undefined)
|
|
13832
|
+
found = value;
|
|
13833
|
+
}
|
|
13834
|
+
return found;
|
|
13835
|
+
}
|
|
13381
13836
|
var NO_PROFILE_SELECTION = {
|
|
13382
13837
|
activeProfile: null,
|
|
13383
13838
|
profileSelectorSource: null,
|
|
@@ -13389,10 +13844,11 @@ function resolveProfileSelector(input) {
|
|
|
13389
13844
|
const envProfile = process.env.SYSTEMATIC_PROFILE?.trim();
|
|
13390
13845
|
if (envProfile)
|
|
13391
13846
|
return { value: envProfile, source: "environment" };
|
|
13847
|
+
const { layers } = input;
|
|
13392
13848
|
const candidates = [
|
|
13393
|
-
["custom",
|
|
13394
|
-
["project",
|
|
13395
|
-
["user",
|
|
13849
|
+
["custom", lastDefined([layers.custom, layers.customLocal], "profile")],
|
|
13850
|
+
["project", layers.project?.config.profile],
|
|
13851
|
+
["user", lastDefined([layers.user, layers.userLocal], "profile")]
|
|
13396
13852
|
];
|
|
13397
13853
|
for (const [source, value] of candidates) {
|
|
13398
13854
|
if (value !== undefined)
|
|
@@ -13401,28 +13857,24 @@ function resolveProfileSelector(input) {
|
|
|
13401
13857
|
return null;
|
|
13402
13858
|
}
|
|
13403
13859
|
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 };
|
|
13860
|
+
const { layers } = input;
|
|
13861
|
+
const lookupOrder = [
|
|
13862
|
+
layers.customLocal,
|
|
13863
|
+
layers.custom,
|
|
13864
|
+
layers.userLocal,
|
|
13865
|
+
layers.user,
|
|
13866
|
+
input.allowProjectProfiles ? layers.project : null
|
|
13867
|
+
];
|
|
13868
|
+
for (const source of lookupOrder) {
|
|
13869
|
+
const bundle = source?.config.profiles?.[name];
|
|
13870
|
+
if (source && bundle !== undefined) {
|
|
13871
|
+
return { bundle, definingSource: source };
|
|
13420
13872
|
}
|
|
13421
13873
|
}
|
|
13422
13874
|
return;
|
|
13423
13875
|
}
|
|
13424
13876
|
function trustedDefaultProfileName(input) {
|
|
13425
|
-
const userDefault = input.
|
|
13877
|
+
const userDefault = lastDefined([input.layers.user, input.layers.userLocal], "profile");
|
|
13426
13878
|
return typeof userDefault === "string" ? userDefault : undefined;
|
|
13427
13879
|
}
|
|
13428
13880
|
function selectorSourceLabel(source) {
|
|
@@ -13475,14 +13927,26 @@ function resolveActiveProfile(input) {
|
|
|
13475
13927
|
bundleSource: null
|
|
13476
13928
|
};
|
|
13477
13929
|
}
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13930
|
+
var USER_LEVEL_SLOT = {
|
|
13931
|
+
user: "user",
|
|
13932
|
+
"user.local": "userLocal",
|
|
13933
|
+
custom: "custom",
|
|
13934
|
+
"custom.local": "customLocal"
|
|
13935
|
+
};
|
|
13936
|
+
function resolveAliasedConfigFiles(paths, includeProject) {
|
|
13937
|
+
if (!includeProject)
|
|
13938
|
+
return [];
|
|
13939
|
+
const candidates = [
|
|
13940
|
+
["custom", paths.customConfig],
|
|
13941
|
+
["custom.local", paths.customLocalConfig],
|
|
13942
|
+
["user", paths.userConfig],
|
|
13943
|
+
["user.local", paths.userLocalConfig]
|
|
13944
|
+
];
|
|
13945
|
+
const project = resolveConfigSourcePath(paths.projectConfig);
|
|
13946
|
+
return candidates.flatMap(([layer, file]) => file !== undefined && resolveConfigSourcePath(file) === project ? [{ layer, path: file }] : []);
|
|
13483
13947
|
}
|
|
13484
|
-
function createAliasStripTracker(warningSink,
|
|
13485
|
-
if (
|
|
13948
|
+
function createAliasStripTracker(warningSink, aliasedFile) {
|
|
13949
|
+
if (aliasedFile === undefined) {
|
|
13486
13950
|
return { sink: warningSink, buffered: [] };
|
|
13487
13951
|
}
|
|
13488
13952
|
const buffered = [];
|
|
@@ -13494,32 +13958,33 @@ function createAliasStripTracker(warningSink, aliasedCustomConfigPath) {
|
|
|
13494
13958
|
};
|
|
13495
13959
|
}
|
|
13496
13960
|
function isAliasNoticeEligible(input) {
|
|
13497
|
-
return input.
|
|
13961
|
+
return input.aliasedFile !== undefined && input.bufferedCount > 0;
|
|
13498
13962
|
}
|
|
13499
13963
|
function emitAliasFailureDiagnostics(input) {
|
|
13500
13964
|
if (!isAliasNoticeEligible({
|
|
13501
|
-
|
|
13965
|
+
aliasedFile: input.aliasedFile,
|
|
13502
13966
|
bufferedCount: input.buffered.length
|
|
13503
13967
|
})) {
|
|
13504
13968
|
return;
|
|
13505
13969
|
}
|
|
13506
|
-
if (input.projectLoaded && input.
|
|
13970
|
+
if (input.projectLoaded && input.aliasLoaded)
|
|
13507
13971
|
return;
|
|
13508
13972
|
for (const message of input.buffered)
|
|
13509
13973
|
input.warningSink(message);
|
|
13510
13974
|
}
|
|
13511
13975
|
function buildAliasSuccessNotice(input) {
|
|
13512
13976
|
if (!isAliasNoticeEligible({
|
|
13513
|
-
|
|
13977
|
+
aliasedFile: input.aliasedFile,
|
|
13514
13978
|
bufferedCount: input.bufferedCount
|
|
13515
|
-
}) || !(input.projectLoaded && input.
|
|
13979
|
+
}) || !(input.projectLoaded && input.aliasLoaded) || input.aliasedFile === undefined) {
|
|
13516
13980
|
return;
|
|
13517
13981
|
}
|
|
13518
|
-
const
|
|
13982
|
+
const { layer, path: aliasedPath } = input.aliasedFile;
|
|
13983
|
+
const trust = LAYER_TRUST[layer];
|
|
13519
13984
|
const projectConfigPath = input.projectConfigPath;
|
|
13520
13985
|
const warningSink = input.warningSink;
|
|
13521
13986
|
return () => {
|
|
13522
|
-
warningSink(`[systematic] project config (${sanitizeDiagnosticText(projectConfigPath)}) and
|
|
13987
|
+
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
13988
|
};
|
|
13524
13989
|
}
|
|
13525
13990
|
var REMOVED_SETTINGS_DOCS_URL = "https://fro.bot/systematic/reference/configuration#removed-settings";
|
|
@@ -13535,31 +14000,133 @@ function warnRemovedKeys(sources, warningSink) {
|
|
|
13535
14000
|
}
|
|
13536
14001
|
}
|
|
13537
14002
|
}
|
|
13538
|
-
function
|
|
13539
|
-
const
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
14003
|
+
function createInvalidFileReporter(warningSink) {
|
|
14004
|
+
const reported = new Set;
|
|
14005
|
+
return (filePath, code) => {
|
|
14006
|
+
const identity = `${resolveConfigSourcePath(filePath)}\x00${code}`;
|
|
14007
|
+
if (reported.has(identity))
|
|
14008
|
+
return;
|
|
14009
|
+
reported.add(identity);
|
|
14010
|
+
warningSink(`[systematic] config file (${sanitizeDiagnosticText(filePath)}) is invalid (${code}) and was not loaded.`);
|
|
13543
14011
|
};
|
|
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
14012
|
}
|
|
13547
|
-
function
|
|
13548
|
-
const
|
|
14013
|
+
function reassignLayer(loaded, layer) {
|
|
14014
|
+
const trust = LAYER_TRUST[layer];
|
|
14015
|
+
return {
|
|
14016
|
+
metadata: { ...loaded.metadata, kind: trust },
|
|
14017
|
+
source: loaded.source && { ...loaded.source, layer, trust }
|
|
14018
|
+
};
|
|
14019
|
+
}
|
|
14020
|
+
function loadUserLevelSources(paths, context) {
|
|
14021
|
+
const loadedByRealFile = new Map;
|
|
14022
|
+
const load = (layer, filePath) => {
|
|
14023
|
+
if (filePath === undefined) {
|
|
14024
|
+
return {
|
|
14025
|
+
metadata: { kind: LAYER_TRUST[layer], presence: "absent" },
|
|
14026
|
+
source: null
|
|
14027
|
+
};
|
|
14028
|
+
}
|
|
14029
|
+
const realFile = resolveConfigSourcePath(filePath);
|
|
14030
|
+
const shared = loadedByRealFile.get(realFile);
|
|
14031
|
+
if (shared)
|
|
14032
|
+
return reassignLayer(shared, layer);
|
|
14033
|
+
const loaded = loadConfigSource({
|
|
14034
|
+
...context,
|
|
14035
|
+
filePath,
|
|
14036
|
+
layer,
|
|
14037
|
+
allowProjectProfiles: false,
|
|
14038
|
+
projectAllowed: () => false
|
|
14039
|
+
});
|
|
14040
|
+
loadedByRealFile.set(realFile, loaded);
|
|
14041
|
+
return loaded;
|
|
14042
|
+
};
|
|
14043
|
+
const user = load("user", paths.userConfig);
|
|
14044
|
+
const userLocal = load("user.local", paths.userLocalConfig);
|
|
14045
|
+
const custom = load("custom", paths.customConfig);
|
|
14046
|
+
const customLocal = load("custom.local", paths.customLocalConfig);
|
|
14047
|
+
const allowProjectProfiles = lastDefined([user.source, userLocal.source, custom.source, customLocal.source], "allow_project_profiles") ?? DEFAULT_CONFIG.allow_project_profiles;
|
|
14048
|
+
return { user, userLocal, custom, customLocal, allowProjectProfiles };
|
|
14049
|
+
}
|
|
14050
|
+
function emitProjectLocationWarnings(paths, warningSink) {
|
|
14051
|
+
if (paths.ignoredProjectConfig !== undefined) {
|
|
14052
|
+
warningSink(`[systematic] project config (${sanitizeDiagnosticText(paths.projectConfig)}) takes precedence over (${sanitizeDiagnosticText(paths.ignoredProjectConfig)}), which is ignored; the two files are never merged.`);
|
|
14053
|
+
}
|
|
14054
|
+
if (paths.startDirProjectConfig !== undefined) {
|
|
14055
|
+
warningSink(startDirProjectWarning(paths.startDirProjectConfig, paths.projectRoot, paths.projectConfig, sanitizeDiagnosticText));
|
|
14056
|
+
}
|
|
14057
|
+
}
|
|
14058
|
+
function buildOverlaySources(profileEntry, bundleSourceTrust, layers) {
|
|
14059
|
+
const ordered = profileEntry !== null && bundleSourceTrust === "project" ? [
|
|
14060
|
+
profileEntry,
|
|
14061
|
+
layers.user,
|
|
14062
|
+
layers.userLocal,
|
|
14063
|
+
layers.project,
|
|
14064
|
+
layers.custom,
|
|
14065
|
+
layers.customLocal
|
|
14066
|
+
] : [
|
|
14067
|
+
layers.user,
|
|
14068
|
+
profileEntry,
|
|
14069
|
+
layers.userLocal,
|
|
14070
|
+
layers.project,
|
|
14071
|
+
layers.custom,
|
|
14072
|
+
layers.customLocal
|
|
14073
|
+
];
|
|
13549
14074
|
return ordered.filter((source) => source !== null);
|
|
13550
14075
|
}
|
|
14076
|
+
function buildProfileEntry(profileSelection) {
|
|
14077
|
+
const { bundle, bundleSource, activeProfile } = profileSelection;
|
|
14078
|
+
if (!bundle || !bundleSource || typeof activeProfile !== "string")
|
|
14079
|
+
return null;
|
|
14080
|
+
return {
|
|
14081
|
+
kind: "profile-bundle",
|
|
14082
|
+
canonicalPath: bundleSource.canonicalPath,
|
|
14083
|
+
path: bundleSource.path,
|
|
14084
|
+
config: { agents: bundle.agents, categories: bundle.categories },
|
|
14085
|
+
protectedFields: [],
|
|
14086
|
+
profileName: activeProfile,
|
|
14087
|
+
bundleTrust: bundleSource.trust
|
|
14088
|
+
};
|
|
14089
|
+
}
|
|
14090
|
+
function unionDisabledList(sources, key) {
|
|
14091
|
+
return sources.reduce((merged, source) => mergeArraysUnique(merged, source.config[key]), mergeArraysUnique(DEFAULT_CONFIG[key], undefined));
|
|
14092
|
+
}
|
|
14093
|
+
function mergeBootstrap(sources) {
|
|
14094
|
+
const merged = { ...DEFAULT_CONFIG.bootstrap };
|
|
14095
|
+
for (const source of sources)
|
|
14096
|
+
Object.assign(merged, source.config.bootstrap);
|
|
14097
|
+
return merged;
|
|
14098
|
+
}
|
|
13551
14099
|
function loadConfigWithSources(projectDir, options) {
|
|
13552
14100
|
const includeProject = options?.includeProject ?? true;
|
|
13553
14101
|
const invalidSource = options?.invalidSource ?? "throw";
|
|
13554
14102
|
const paths = getConfigPaths(projectDir, options);
|
|
13555
14103
|
const warningSink = options?.warningSink ?? console.warn;
|
|
13556
|
-
const
|
|
13557
|
-
|
|
14104
|
+
const reportInvalid = createInvalidFileReporter(warningSink);
|
|
14105
|
+
if (includeProject)
|
|
14106
|
+
emitProjectLocationWarnings(paths, warningSink);
|
|
14107
|
+
const aliasedFiles = resolveAliasedConfigFiles(paths, includeProject);
|
|
14108
|
+
const aliasedFile = aliasedFiles[0];
|
|
14109
|
+
const projectStrip = createAliasStripTracker(warningSink, aliasedFile);
|
|
13558
14110
|
const boundedProjectStrip = createBoundedStripWarningSink(projectStrip.sink);
|
|
13559
|
-
const
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
14111
|
+
const userLevel = loadUserLevelSources(paths, {
|
|
14112
|
+
invalidSource,
|
|
14113
|
+
reportInvalid,
|
|
14114
|
+
warningSink
|
|
14115
|
+
});
|
|
14116
|
+
const { allowProjectProfiles } = userLevel;
|
|
14117
|
+
const mergedSearch = mergeUserLevelSearch(userLevel);
|
|
14118
|
+
const homeDir = resolveUserLevelConfigDirs(options).homeDir || os5.homedir();
|
|
14119
|
+
const projectAllowed = () => isAllowedProject(resolveProjectIdentity(paths.projectRoot), mergedSearch.settings?.allow_project_sources ?? [], { homeDir });
|
|
14120
|
+
const aliasLoaded = aliasedFiles.some(({ layer }) => userLevel[USER_LEVEL_SLOT[layer]].source !== null);
|
|
14121
|
+
const project = includeProject ? loadConfigSource({
|
|
14122
|
+
filePath: paths.projectConfig,
|
|
14123
|
+
layer: "project",
|
|
14124
|
+
invalidSource,
|
|
14125
|
+
warningSink: boundedProjectStrip.sink,
|
|
14126
|
+
reportInvalid,
|
|
14127
|
+
allowProjectProfiles,
|
|
14128
|
+
projectAllowed
|
|
14129
|
+
}) : {
|
|
13563
14130
|
metadata: { kind: "project", presence: "absent" },
|
|
13564
14131
|
source: null
|
|
13565
14132
|
};
|
|
@@ -13572,51 +14139,44 @@ function loadConfigWithSources(projectDir, options) {
|
|
|
13572
14139
|
projectStrip.sink(`[systematic] ${suppressedStripCount} additional project-config protected-field warning(s) in (${sanitizeDiagnosticText(paths.projectConfig)}) were suppressed.`);
|
|
13573
14140
|
}
|
|
13574
14141
|
emitAliasFailureDiagnostics({
|
|
13575
|
-
|
|
14142
|
+
aliasedFile,
|
|
13576
14143
|
buffered: projectStrip.buffered,
|
|
13577
|
-
|
|
14144
|
+
aliasLoaded,
|
|
13578
14145
|
projectLoaded: project.source !== null,
|
|
13579
14146
|
warningSink
|
|
13580
14147
|
});
|
|
13581
14148
|
const emitAliasSuccessNotice = buildAliasSuccessNotice({
|
|
13582
|
-
|
|
14149
|
+
aliasedFile,
|
|
13583
14150
|
bufferedCount: projectStrip.buffered.length,
|
|
13584
|
-
|
|
14151
|
+
aliasLoaded,
|
|
13585
14152
|
projectConfigPath: paths.projectConfig,
|
|
13586
14153
|
projectLoaded: project.source !== null,
|
|
13587
14154
|
warningSink
|
|
13588
14155
|
});
|
|
13589
|
-
const
|
|
14156
|
+
const layers = {
|
|
14157
|
+
user: userLevel.user.source,
|
|
14158
|
+
userLocal: userLevel.userLocal.source,
|
|
14159
|
+
project: projectSource,
|
|
14160
|
+
custom: userLevel.custom.source,
|
|
14161
|
+
customLocal: userLevel.customLocal.source
|
|
14162
|
+
};
|
|
14163
|
+
const sources = chainOf(layers);
|
|
13590
14164
|
warnRemovedKeys(sources, warningSink);
|
|
13591
|
-
const userConfig = userSource?.config;
|
|
13592
|
-
const projectConfig = projectSource?.config;
|
|
13593
|
-
const customConfig = customSource?.config;
|
|
13594
14165
|
const warned = new Set;
|
|
13595
|
-
|
|
13596
|
-
|
|
14166
|
+
assertAllProfileBundlesAreValid([
|
|
14167
|
+
layers.user,
|
|
14168
|
+
layers.userLocal,
|
|
14169
|
+
layers.custom,
|
|
14170
|
+
layers.customLocal,
|
|
14171
|
+
layers.project
|
|
14172
|
+
].map((source) => source?.config));
|
|
13597
14173
|
const profileSelection = resolveActiveProfile({
|
|
13598
|
-
|
|
13599
|
-
userSource,
|
|
13600
|
-
projectConfig,
|
|
13601
|
-
projectSource,
|
|
13602
|
-
customConfig,
|
|
13603
|
-
customSource,
|
|
14174
|
+
layers,
|
|
13604
14175
|
allowProjectProfiles,
|
|
13605
14176
|
warningSink
|
|
13606
14177
|
});
|
|
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);
|
|
14178
|
+
const profileEntry = buildProfileEntry(profileSelection);
|
|
14179
|
+
const overlaySources = buildOverlaySources(profileEntry, profileSelection.bundleSource?.trust, layers);
|
|
13620
14180
|
const mergedOverlays = mergeOverlaySources(overlaySources);
|
|
13621
14181
|
const mergedPiSubagentsOverlays = mergePiSubagentsOverlaySources(sources);
|
|
13622
14182
|
const droppedCategories = Object.keys(mergedOverlays.categories).filter((name) => REMOVED_AGENT_CATEGORIES_SET.has(name));
|
|
@@ -13626,26 +14186,21 @@ function loadConfigWithSources(projectDir, options) {
|
|
|
13626
14186
|
...mergedOverlays,
|
|
13627
14187
|
categories: Object.fromEntries(Object.entries(mergedOverlays.categories).filter(([key]) => !droppedCategorySet.has(key)))
|
|
13628
14188
|
};
|
|
13629
|
-
const mergedDisabledAgents =
|
|
14189
|
+
const mergedDisabledAgents = unionDisabledList(sources, "disabled_agents");
|
|
13630
14190
|
assertRoutingInvariants(overlays, mergedPiSubagentsOverlays, new Set(mergedDisabledAgents), warningSink);
|
|
13631
14191
|
const result = {
|
|
13632
|
-
disabled_skills:
|
|
14192
|
+
disabled_skills: unionDisabledList(sources, "disabled_skills"),
|
|
13633
14193
|
disabled_agents: mergedDisabledAgents,
|
|
13634
|
-
disabled_commands:
|
|
13635
|
-
bootstrap:
|
|
13636
|
-
...DEFAULT_CONFIG.bootstrap,
|
|
13637
|
-
...userConfig?.bootstrap,
|
|
13638
|
-
...projectConfig?.bootstrap,
|
|
13639
|
-
...customConfig?.bootstrap
|
|
13640
|
-
},
|
|
14194
|
+
disabled_commands: unionDisabledList(sources, "disabled_commands"),
|
|
14195
|
+
bootstrap: mergeBootstrap(sources),
|
|
13641
14196
|
agents: overlayValues(overlays.agents),
|
|
13642
14197
|
categories: overlayValues(overlays.categories),
|
|
13643
14198
|
pi_subagents: {
|
|
13644
14199
|
categories: overlayValues(mergedPiSubagentsOverlays.categories),
|
|
13645
14200
|
agents: overlayValues(mergedPiSubagentsOverlays.agents)
|
|
13646
14201
|
},
|
|
13647
|
-
skills_as_commands:
|
|
13648
|
-
allow_project_profiles:
|
|
14202
|
+
skills_as_commands: lastDefined(sources, "skills_as_commands") ?? DEFAULT_CONFIG.skills_as_commands,
|
|
14203
|
+
allow_project_profiles: allowProjectProfiles,
|
|
13649
14204
|
...mergedSearch.settings && { search: mergedSearch.settings },
|
|
13650
14205
|
...mergedSearch.unreadable && { searchUnreadable: true }
|
|
13651
14206
|
};
|
|
@@ -13664,29 +14219,62 @@ function loadConfigWithSources(projectDir, options) {
|
|
|
13664
14219
|
return {
|
|
13665
14220
|
config: effectiveConfig,
|
|
13666
14221
|
metadata: buildConfigObservationMetadata({
|
|
13667
|
-
custom: custom
|
|
14222
|
+
custom: foldKindMetadata("custom", [
|
|
14223
|
+
userLevel.custom.metadata,
|
|
14224
|
+
userLevel.customLocal.metadata
|
|
14225
|
+
]),
|
|
13668
14226
|
profileSelection,
|
|
13669
14227
|
project: project.metadata,
|
|
13670
|
-
sources,
|
|
13671
|
-
user: user
|
|
14228
|
+
sources: foldSiblingSources(sources),
|
|
14229
|
+
user: foldKindMetadata("user", [
|
|
14230
|
+
userLevel.user.metadata,
|
|
14231
|
+
userLevel.userLocal.metadata
|
|
14232
|
+
])
|
|
13672
14233
|
}),
|
|
13673
14234
|
overlays,
|
|
13674
14235
|
piSubagentsOverlays: mergedPiSubagentsOverlays,
|
|
13675
14236
|
activeProfileSourcePath: profileSelection.bundleSource?.path ?? null
|
|
13676
14237
|
};
|
|
13677
14238
|
}
|
|
14239
|
+
function mergeUserLevelSearch(userLevel) {
|
|
14240
|
+
return mergeSearchSettings(["user", "userLocal", "custom", "customLocal"].flatMap((slot) => {
|
|
14241
|
+
const source = userLevel[slot].source;
|
|
14242
|
+
return source?.search && isUserLevelLayer(source.layer) ? [{ ...source.search, layer: source.layer }] : [];
|
|
14243
|
+
}));
|
|
14244
|
+
}
|
|
14245
|
+
function isUserLevelLayer(layer) {
|
|
14246
|
+
return layer !== "project";
|
|
14247
|
+
}
|
|
14248
|
+
function foldSiblingSources(sources) {
|
|
14249
|
+
const byTrust = new Map;
|
|
14250
|
+
for (const source of sources) {
|
|
14251
|
+
byTrust.set(source.trust, [...byTrust.get(source.trust) ?? [], source]);
|
|
14252
|
+
}
|
|
14253
|
+
return Array.from(byTrust.values(), (files) => ({
|
|
14254
|
+
trust: files[0]?.trust ?? "user",
|
|
14255
|
+
canonicalPaths: files.map((file) => file.canonicalPath),
|
|
14256
|
+
configs: files.map((file) => file.config),
|
|
14257
|
+
protectedFields: files.flatMap((file) => file.protectedFields)
|
|
14258
|
+
}));
|
|
14259
|
+
}
|
|
14260
|
+
function foldKindMetadata(kind, files) {
|
|
14261
|
+
const invalid = files.find((file) => file.presence === "invalid");
|
|
14262
|
+
if (invalid)
|
|
14263
|
+
return invalid;
|
|
14264
|
+
return files.some((file) => file.presence === "present") ? { kind, presence: "present" } : { kind, presence: "absent" };
|
|
14265
|
+
}
|
|
13678
14266
|
function buildConfigObservationMetadata(summary) {
|
|
13679
14267
|
const authorities = [];
|
|
13680
14268
|
const sourceConfigs = new Map;
|
|
13681
14269
|
const sourcePaths = new Map;
|
|
13682
14270
|
for (const source of summary.sources) {
|
|
13683
|
-
sourceConfigs.set(source.trust, source.
|
|
13684
|
-
sourcePaths.set(source.trust, source.
|
|
14271
|
+
sourceConfigs.set(source.trust, source.configs);
|
|
14272
|
+
sourcePaths.set(source.trust, source.canonicalPaths);
|
|
13685
14273
|
}
|
|
13686
14274
|
const firstDefinedSource = (fieldPath, candidates) => {
|
|
13687
14275
|
for (const sourceKind of candidates) {
|
|
13688
|
-
const
|
|
13689
|
-
if (config
|
|
14276
|
+
const configs = sourceConfigs.get(sourceKind);
|
|
14277
|
+
if (configs?.some((config) => hasConfigField(config, fieldPath))) {
|
|
13690
14278
|
return { fieldPath, sourceKind };
|
|
13691
14279
|
}
|
|
13692
14280
|
}
|
|
@@ -13715,19 +14303,25 @@ function buildConfigObservationMetadata(summary) {
|
|
|
13715
14303
|
}
|
|
13716
14304
|
function collectVisibleProtectedFields(sources) {
|
|
13717
14305
|
const projectSource = sources.find((source) => source.trust === "project");
|
|
13718
|
-
const
|
|
13719
|
-
const
|
|
13720
|
-
return sources.flatMap((source) =>
|
|
14306
|
+
const userLevelPaths = new Set(sources.filter((source) => source.trust !== "project").flatMap((source) => source.canonicalPaths));
|
|
14307
|
+
const projectAppliedViaUserLevel = projectSource?.canonicalPaths.some((file) => userLevelPaths.has(file)) ?? false;
|
|
14308
|
+
return sources.flatMap((source) => projectAppliedViaUserLevel && source.trust === "project" ? [] : source.protectedFields);
|
|
13721
14309
|
}
|
|
13722
14310
|
function dedupeSourceMetadata(metadata, sourcePaths) {
|
|
14311
|
+
const priority = ["custom", "user", "project"];
|
|
13723
14312
|
const seen = new Set;
|
|
13724
|
-
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
|
|
13728
|
-
seen.
|
|
13729
|
-
|
|
13730
|
-
|
|
14313
|
+
const kept = new Set;
|
|
14314
|
+
for (const kind of priority) {
|
|
14315
|
+
const files = sourcePaths.get(kind) ?? [];
|
|
14316
|
+
const presence = metadata.find((source) => source.kind === kind)?.presence;
|
|
14317
|
+
const redundant = files.length > 0 && files.every((file) => seen.has(file)) && presence !== "invalid";
|
|
14318
|
+
if (redundant)
|
|
14319
|
+
continue;
|
|
14320
|
+
for (const file of files)
|
|
14321
|
+
seen.add(file);
|
|
14322
|
+
kept.add(kind);
|
|
14323
|
+
}
|
|
14324
|
+
return metadata.filter((source) => kept.has(source.kind));
|
|
13731
14325
|
}
|
|
13732
14326
|
function hasConfigField(config, fieldPath) {
|
|
13733
14327
|
const [topLevel, nested] = fieldPath.split(".");
|
|
@@ -13786,8 +14380,8 @@ function assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle
|
|
|
13786
14380
|
}
|
|
13787
14381
|
}
|
|
13788
14382
|
}
|
|
13789
|
-
function assertAllProfileBundlesAreValid(
|
|
13790
|
-
for (const config of
|
|
14383
|
+
function assertAllProfileBundlesAreValid(configs) {
|
|
14384
|
+
for (const config of configs) {
|
|
13791
14385
|
for (const [profileName, bundle] of Object.entries(config?.profiles ?? {})) {
|
|
13792
14386
|
assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle);
|
|
13793
14387
|
}
|
|
@@ -13876,7 +14470,7 @@ function resolveOverlayEntryOrigin(previous, fragment, source) {
|
|
|
13876
14470
|
const own = routingOriginsFromOwnFields(fragment, originForSource(source));
|
|
13877
14471
|
if (!previous)
|
|
13878
14472
|
return own;
|
|
13879
|
-
const preserves = source.kind === "profile-bundle" || source.
|
|
14473
|
+
const preserves = source.kind === "profile-bundle" || source.layer === "project" || source.layer === "user";
|
|
13880
14474
|
return preserves ? { ...previous, ...own } : own;
|
|
13881
14475
|
}
|
|
13882
14476
|
function resolveOverlayEntryValue(previous, next, source) {
|
|
@@ -13885,9 +14479,9 @@ function resolveOverlayEntryValue(previous, next, source) {
|
|
|
13885
14479
|
if (source.kind === "profile-bundle") {
|
|
13886
14480
|
return mergeProfileOverlayValue(previous, next);
|
|
13887
14481
|
}
|
|
13888
|
-
if (source.
|
|
14482
|
+
if (source.layer === "project")
|
|
13889
14483
|
return preserveSecurityFields(previous, next);
|
|
13890
|
-
if (source.
|
|
14484
|
+
if (source.layer === "user")
|
|
13891
14485
|
return mergeProfileOverlayValue(previous, next);
|
|
13892
14486
|
return next;
|
|
13893
14487
|
}
|
|
@@ -13987,18 +14581,42 @@ function throwInvalidOverlay(sourcePath, keyPath) {
|
|
|
13987
14581
|
throw new Error(`Invalid Systematic config in ${sourcePath}: ${keyPath} must be an object`);
|
|
13988
14582
|
}
|
|
13989
14583
|
function getConfigPaths(projectDir, options) {
|
|
13990
|
-
const
|
|
13991
|
-
const
|
|
13992
|
-
|
|
13993
|
-
|
|
14584
|
+
const dirs = resolveUserLevelConfigDirs(options);
|
|
14585
|
+
const { homeDir, customConfigDir } = dirs;
|
|
14586
|
+
const selection = selectUserLevelConfigFiles(dirs);
|
|
14587
|
+
const fileFor = (layer) => selection.files.find((file) => file.layer === layer)?.path;
|
|
14588
|
+
const userFile = (layer) => {
|
|
14589
|
+
const file = fileFor(layer);
|
|
14590
|
+
if (file === undefined) {
|
|
14591
|
+
throw new Error(`No ${layer} config file was selected`);
|
|
14592
|
+
}
|
|
14593
|
+
return file;
|
|
14594
|
+
};
|
|
14595
|
+
const repoRoot = options?.includeProject ?? true ? lookupSearchRoot(projectDir) : undefined;
|
|
14596
|
+
const projectRoot = repoRoot?.root ?? projectDir;
|
|
14597
|
+
const project = repoRoot ? selectProjectConfigFile(projectRoot) : {
|
|
14598
|
+
path: selectConfigFile(path10.join(projectDir, ".opencode"), "systematic")
|
|
14599
|
+
};
|
|
14600
|
+
const startDirProjectConfig = repoRoot ? findStartDirProjectConfig(projectDir, repoRoot, project.path) : undefined;
|
|
14601
|
+
const ignoredProjectConfig = "ignoredPath" in project ? project.ignoredPath : undefined;
|
|
14602
|
+
const customConfig = fileFor("custom");
|
|
14603
|
+
const customLocalConfig = fileFor("custom.local");
|
|
14604
|
+
return {
|
|
14605
|
+
userConfig: userFile("user"),
|
|
14606
|
+
userLocalConfig: userFile("user.local"),
|
|
14607
|
+
projectConfig: project.path,
|
|
14608
|
+
projectRoot,
|
|
13994
14609
|
userDir: path10.join(homeDir, ".config/opencode/systematic"),
|
|
13995
|
-
projectDir: path10.join(
|
|
13996
|
-
|
|
13997
|
-
|
|
14610
|
+
projectDir: path10.join(projectRoot, ".opencode/systematic"),
|
|
14611
|
+
customAliasesUser: selection.aliased,
|
|
14612
|
+
...ignoredProjectConfig !== undefined && { ignoredProjectConfig },
|
|
14613
|
+
...startDirProjectConfig !== undefined && { startDirProjectConfig },
|
|
14614
|
+
...customConfigDir && customConfig !== undefined && customLocalConfig !== undefined && {
|
|
14615
|
+
customConfig,
|
|
14616
|
+
customLocalConfig,
|
|
13998
14617
|
customDir: path10.join(customConfigDir, "systematic")
|
|
13999
14618
|
}
|
|
14000
14619
|
};
|
|
14001
|
-
return result;
|
|
14002
14620
|
}
|
|
14003
14621
|
|
|
14004
14622
|
// src/lib/pi-delegate-session.ts
|