opencode-model-router 2.10.0 → 2.11.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/CHANGELOG.md +306 -0
- package/README.md +3 -2
- package/package.json +8 -1
- package/src/compat/background.ts +5 -0
- package/src/compat/session-lookup.ts +21 -0
- package/src/compat/v2-hooks.ts +256 -88
- package/src/compat/v2-observations.ts +1 -0
- package/src/compat/v2-vocabulary.ts +14 -0
- package/src/executor/create.ts +3 -0
- package/src/executor/git.ts +110 -26
- package/src/executor/integrate/checks.ts +29 -11
- package/src/executor/integrate/queue.ts +95 -13
- package/src/executor/ledger.ts +16 -12
- package/src/executor/lfs-restore.ts +492 -0
- package/src/executor/paths.ts +7 -2
- package/src/executor/recovery.ts +2 -1
- package/src/executor/runtime.ts +1010 -226
- package/src/executor/slots/pool.ts +120 -19
- package/src/executor/slots/provision.ts +111 -23
- package/src/executor/slots/root.ts +81 -0
- package/src/executor/types.ts +28 -2
- package/src/executor/unattended.ts +6 -1
- package/src/executor/verify-trees.ts +507 -0
- package/src/guard/enforce.ts +2 -1
- package/src/guard/fingerprint.ts +9 -0
- package/src/guard/guards.ts +7 -1
- package/src/index.ts +107 -27
- package/src/router/answer-dedup.ts +198 -0
- package/src/router/common-dir.ts +241 -0
- package/src/router/config.ts +71 -12
- package/src/router/diff-handles.ts +322 -0
- package/src/router/diff-summary.ts +318 -0
- package/src/router/git-metadata-guard.ts +144 -7
- package/src/router/git-tools.ts +930 -73
- package/src/router/role-agents.ts +100 -36
- package/src/router/run-summary.ts +253 -0
- package/src/router/run-tools.ts +145 -23
- package/src/router/sessions.ts +14 -1
- package/src/routing/classify/rules.ts +93 -14
- package/src/routing/wire/hint.ts +9 -2
- package/src/v2.ts +3 -1
- package/src/verify/exec.ts +454 -2
- package/src/verify/plan-task.ts +86 -26
- package/src/verify/runner.ts +14 -6
- package/src/verify/tree.ts +5 -1
- package/src/verify/types.ts +44 -0
- package/src/verify/wiring.ts +87 -10
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #192, QA-62C-15 (OpenCode v2 roles mode only): the git common directory of the repository holding a directory, found on
|
|
3
|
+
* disk without running git. Role agent registration denies `<git common dir>/omr-executor` with it where git cannot be
|
|
4
|
+
* asked: off Windows, where the plan executor does not run but a Windows host sharing the repository (WSL) may, and off
|
|
5
|
+
* Windows where git reports no repository although one exists (Linux git cannot read a Git for Windows worktree whose `.git`
|
|
6
|
+
* names `gitdir: D:/…`).
|
|
7
|
+
*
|
|
8
|
+
* The walk follows git's discovery order: at each level a `.git` entry, then a bare repository (git's shape,
|
|
9
|
+
* {@link bareShaped}, with a `HEAD` git accepts), then the parent directory. A `.git` directory is the git directory; a
|
|
10
|
+
* `.git` file names it on a `gitdir:` line. The common directory is what the git directory's `commondir` names, else the
|
|
11
|
+
* git directory itself. A checkout's `.git` ends the walk; a bare repository does not: its shape can be committed to a
|
|
12
|
+
* checkout (a `.git` entry cannot), so the walk goes on to the enclosing repository and every common directory found is
|
|
13
|
+
* returned (an extra deny is harmless). Pointers are read as `gitPointers` (router/git-tools.ts) reads them: `.git`,
|
|
14
|
+
* `commondir` and `HEAD` at most 4 KiB, regular files only, opened non-blocking; a `.git` that is a link and a pointer
|
|
15
|
+
* naming a network or device path are refused before any filesystem call reaches them. Off win32 a pointer naming a
|
|
16
|
+
* Windows drive path (`D:/…`, `D:\…`) is read under WSL at the drive's automount path (`<root>/<drive>/<rest>`, the root
|
|
17
|
+
* from `/etc/wsl.conf` `[automount] root`, default `/mnt/`), which must exist; a realpath naming a network or device path
|
|
18
|
+
* (`//host/…`) is refused, but a network drive Windows mounts there (`/mnt/z`) is not told apart. Anywhere else such a
|
|
19
|
+
* pointer cannot be read.
|
|
20
|
+
*
|
|
21
|
+
* Results: `none` (no repository up to the filesystem root); `resolved` with every common directory found (not
|
|
22
|
+
* canonicalized, nearest first) and, under WSL, the automount root (`drvfsRoot`: Windows drives below it compare names
|
|
23
|
+
* case-insensitively; `/` when it cannot be read); or `unresolved` with the reason: a repository was found, but a common
|
|
24
|
+
* directory cannot be read (the caller fails closed). Every OS access is a seam ({@link CommonDirDeps}). Errors never quote
|
|
25
|
+
* a pointer's text. Never throws.
|
|
26
|
+
*/
|
|
27
|
+
import { lstatSync, realpathSync } from "node:fs";
|
|
28
|
+
import { release } from "node:os";
|
|
29
|
+
import { dirname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
30
|
+
import { bareShaped } from "./git-metadata-guard";
|
|
31
|
+
import { errorMessage, isNetworkOrDevicePath, readBoundedRegularFile } from "./git-tools";
|
|
32
|
+
|
|
33
|
+
/** What {@link resolveCommonDirOnDisk} found. */
|
|
34
|
+
export type CommonDirOnDisk =
|
|
35
|
+
| { readonly kind: "none" }
|
|
36
|
+
| { readonly kind: "resolved"; readonly commons: readonly string[]; readonly drvfsRoot?: string }
|
|
37
|
+
| { readonly kind: "unresolved"; readonly reason: string };
|
|
38
|
+
|
|
39
|
+
/** What `lstat` reports of an entry, never following a link. */
|
|
40
|
+
export interface EntryStats {
|
|
41
|
+
isSymbolicLink(): boolean;
|
|
42
|
+
isDirectory(): boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Seams of {@link resolveCommonDirOnDisk} (tests); every field defaults to the real thing. */
|
|
46
|
+
export interface CommonDirDeps {
|
|
47
|
+
/** Pointer syntax (default `process.platform`): off win32 a Windows drive path is mapped under WSL. */
|
|
48
|
+
readonly platform?: NodeJS.Platform;
|
|
49
|
+
/** Whether this is WSL (default: `os.release()` names Microsoft); asked only for a drive-path pointer. */
|
|
50
|
+
readonly isWsl?: () => boolean;
|
|
51
|
+
/** The text of `/etc/wsl.conf`, undefined when missing (default: a bounded regular-file read); asked only under WSL. */
|
|
52
|
+
readonly readWslConf?: () => string | undefined;
|
|
53
|
+
/** `lstat`, undefined when the entry is missing (default `lstatSync`; ENOENT and ENOTDIR are a missing entry). */
|
|
54
|
+
readonly lstat?: (path: string) => EntryStats | undefined;
|
|
55
|
+
/** A bounded regular-file read, undefined when missing (default `readBoundedRegularFile`: non-blocking, regular files only). */
|
|
56
|
+
readonly readFile?: (path: string, max: number, label: string) => string | undefined;
|
|
57
|
+
/** `realpath` (default `realpathSync.native`): a mapped drive path must resolve. */
|
|
58
|
+
readonly realpath?: (path: string) => string;
|
|
59
|
+
/** Git's bare repository shape (default {@link bareShaped}). */
|
|
60
|
+
readonly bareShaped?: (dir: string) => boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Bound of the `.git` pointer and `commondir` files, as `gitPointers` bounds them (QA-P13-2-4). */
|
|
64
|
+
const GIT_POINTER_BYTES = 4 * 1024;
|
|
65
|
+
/** Bound of `/etc/wsl.conf`. */
|
|
66
|
+
const WSL_CONF_BYTES = 64 * 1024;
|
|
67
|
+
const WSL_CONF = "/etc/wsl.conf";
|
|
68
|
+
/** The WSL automount root when `/etc/wsl.conf` sets none. */
|
|
69
|
+
export const DEFAULT_AUTOMOUNT_ROOT = "/mnt/";
|
|
70
|
+
const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
71
|
+
/** A `HEAD` git accepts (`validate_headref`): a symbolic ref into `refs/`, or an object id (SHA-1 or SHA-256 hex). */
|
|
72
|
+
const VALID_HEAD = /^(?:ref:\s*refs\/|[0-9a-fA-F]{40})/;
|
|
73
|
+
const NONE: CommonDirOnDisk = Object.freeze({ kind: "none" });
|
|
74
|
+
|
|
75
|
+
type Seams = Required<CommonDirDeps>;
|
|
76
|
+
|
|
77
|
+
/** The code of a filesystem error, never its message (which would quote the path). */
|
|
78
|
+
function codeOf(error: unknown): string {
|
|
79
|
+
return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : "error";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** `lstatSync`, undefined for a missing entry or a file used as a directory (as `existsSync` treats them); else it throws. */
|
|
83
|
+
function lstatOrUndefined(path: string): EntryStats | undefined {
|
|
84
|
+
try {
|
|
85
|
+
return lstatSync(path);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") return undefined;
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The `[automount] root` value of a wsl.conf text, or undefined when it sets none: section and key case-insensitive, the
|
|
94
|
+
* last value wins, a trailing ` # comment` and surrounding double quotes dropped; comment lines never match.
|
|
95
|
+
*/
|
|
96
|
+
export function wslConfRoot(text: string): string | undefined {
|
|
97
|
+
let section = "";
|
|
98
|
+
let root: string | undefined;
|
|
99
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
100
|
+
const line = raw.trim();
|
|
101
|
+
const header = /^\[([^\]]*)\]/.exec(line);
|
|
102
|
+
if (header !== null) {
|
|
103
|
+
section = header[1].trim().toLowerCase();
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const entry = section === "automount" ? /^root\s*=(.*)$/i.exec(line) : null;
|
|
107
|
+
if (entry !== null) root = entry[1].replace(/\s+#.*$/, "").trim().replace(/^"(.*)"$/, "$1");
|
|
108
|
+
}
|
|
109
|
+
return root === "" ? undefined : root;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The WSL automount root: `/etc/wsl.conf`'s, else {@link DEFAULT_AUTOMOUNT_ROOT}. Throws when it is not usable. */
|
|
113
|
+
function automountRoot(seams: Seams): string {
|
|
114
|
+
const text = seams.readWslConf();
|
|
115
|
+
const root = text === undefined ? undefined : wslConfRoot(text);
|
|
116
|
+
if (root === undefined) return DEFAULT_AUTOMOUNT_ROOT;
|
|
117
|
+
if (!isAbsolute(root) || isNetworkOrDevicePath(root) || /[\x00-\x1f\x7f]/.test(root)) {
|
|
118
|
+
throw new Error(`the [automount] root of ${WSL_CONF} is not a local absolute path`);
|
|
119
|
+
}
|
|
120
|
+
return root;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A Windows drive path pointer read under WSL: `<automount root>/<drive, lower case>/<rest, / separated>`, `..` clamped at the
|
|
125
|
+
* drive root as Windows does. It must resolve, and its realpath must not name a network or device path (`//host/…`); a
|
|
126
|
+
* network drive mounted below the automount root looks local and is not detected.
|
|
127
|
+
*/
|
|
128
|
+
function underAutomount(pointer: string, label: string, seams: Seams): string {
|
|
129
|
+
if (!seams.isWsl()) throw new Error(`its ${label} names a Windows drive path, which cannot be read outside Windows or WSL`);
|
|
130
|
+
const root = automountRoot(seams);
|
|
131
|
+
const drive = win32.normalize(pointer);
|
|
132
|
+
const rest = drive.slice(3).split("\\").filter((segment) => segment !== "");
|
|
133
|
+
const mapped = [root.replace(/[\\/]+$/, ""), drive.charAt(0).toLowerCase(), ...rest].join("/");
|
|
134
|
+
let real: string;
|
|
135
|
+
try {
|
|
136
|
+
real = seams.realpath(mapped);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new Error(`its ${label} names a Windows drive path that is not found under the WSL automount root (${codeOf(error)})`);
|
|
139
|
+
}
|
|
140
|
+
if (isNetworkOrDevicePath(real)) {
|
|
141
|
+
throw new Error(`Refusing repository: its ${label} names a Windows drive path that resolves to a network or device path`);
|
|
142
|
+
}
|
|
143
|
+
return mapped;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Where `pointer` (a `.git` file's `gitdir:` or a `commondir`) leads from `base`; throws when it is refused or unreadable. */
|
|
147
|
+
function located(base: string, pointer: string, label: string, seams: Seams): string {
|
|
148
|
+
if (isNetworkOrDevicePath(pointer)) throw new Error(`Refusing repository: its ${label} points to a network or device path`);
|
|
149
|
+
if (seams.platform === "win32" || !WINDOWS_DRIVE.test(pointer)) return resolve(base, pointer);
|
|
150
|
+
return underAutomount(pointer, label, seams);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The common directory of git directory `gitdir`: what its `commondir` names, else `gitdir` itself. */
|
|
154
|
+
function commonOf(gitdir: string, seams: Seams): string {
|
|
155
|
+
const pointer = seams.readFile(join(gitdir, "commondir"), GIT_POINTER_BYTES, "commondir")?.trim() ?? "";
|
|
156
|
+
return pointer === "" ? gitdir : located(gitdir, pointer, "commondir", seams);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The common directory of the checkout whose `.git` entry `dotGit` has `stats`. */
|
|
160
|
+
function commonOfCheckout(checkout: string, dotGit: string, stats: EntryStats, seams: Seams): string {
|
|
161
|
+
if (stats.isSymbolicLink()) throw new Error("Refusing repository: its .git is a link");
|
|
162
|
+
if (stats.isDirectory()) return commonOf(dotGit, seams);
|
|
163
|
+
const match = /^gitdir:\s*(.+?)\s*$/m.exec(seams.readFile(dotGit, GIT_POINTER_BYTES, ".git") ?? "");
|
|
164
|
+
const pointer = match === null ? "" : match[1].trim();
|
|
165
|
+
if (pointer === "") throw new Error("its .git file has no gitdir: line");
|
|
166
|
+
return commonOf(located(checkout, pointer, ".git file", seams), seams);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** `dir` is a bare repository as git's discovery accepts one: git's shape, and a `HEAD` git validates (bounded read). */
|
|
170
|
+
function bareRepository(dir: string, seams: Seams): boolean {
|
|
171
|
+
return seams.bareShaped(dir) && VALID_HEAD.test(seams.readFile(join(dir, "HEAD"), GIT_POINTER_BYTES, "HEAD") ?? "");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Under WSL the automount root, `/` when it cannot be read (any path may then be on a Windows drive); else undefined. */
|
|
175
|
+
function drvfsRootOf(seams: Seams): string | undefined {
|
|
176
|
+
if (seams.platform === "win32" || !seams.isWsl()) return undefined;
|
|
177
|
+
try {
|
|
178
|
+
return automountRoot(seams);
|
|
179
|
+
} catch {
|
|
180
|
+
return "/"; // an unusable wsl.conf root: treat every path as possibly on a Windows drive (fail closed)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A path compared as a Windows drive compares names: `/` separators, case-folded. */
|
|
185
|
+
function foldedKey(path: string): string {
|
|
186
|
+
return path.replace(/\\/g, "/").toLowerCase();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** #192: `path` is the WSL automount root `root` or below it (a Windows drive, where letter case is not significant). */
|
|
190
|
+
export function onDrvfs(path: string, root: string): boolean {
|
|
191
|
+
const base = foldedKey(root).replace(/\/+$/, "");
|
|
192
|
+
const key = foldedKey(path);
|
|
193
|
+
return base === "" || key === base || key.startsWith(`${base}/`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* #192: an `external_directory` allow pattern can match a path inside `home` once letter case is ignored (a Windows drive
|
|
198
|
+
* under WSL): its static prefix (before the first glob character) and `<home>/` are prefixes of one another, compared
|
|
199
|
+
* case-insensitively. The host's own match is case-sensitive off win32, so a deny on `home` does not stop such an allow.
|
|
200
|
+
*/
|
|
201
|
+
export function reachesFolded(pattern: string, home: string): boolean {
|
|
202
|
+
const globAt = pattern.search(/[*?[\]{}]/);
|
|
203
|
+
const prefix = foldedKey(globAt === -1 ? `${pattern}/` : pattern.slice(0, globAt));
|
|
204
|
+
const inside = `${foldedKey(home).replace(/\/+$/, "")}/`;
|
|
205
|
+
return inside.startsWith(prefix) || prefix.startsWith(inside);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The git common directories of the repository holding `start` (made absolute), found on disk in git's discovery order
|
|
210
|
+
* without running git. See the module comment for the rules; never throws.
|
|
211
|
+
*/
|
|
212
|
+
export function resolveCommonDirOnDisk(start: string, deps: CommonDirDeps = {}): CommonDirOnDisk {
|
|
213
|
+
const seams: Seams = {
|
|
214
|
+
platform: deps.platform ?? process.platform,
|
|
215
|
+
isWsl: deps.isWsl ?? (() => /microsoft/i.test(release())),
|
|
216
|
+
readWslConf: deps.readWslConf ?? (() => readBoundedRegularFile(WSL_CONF, WSL_CONF_BYTES, WSL_CONF)),
|
|
217
|
+
lstat: deps.lstat ?? lstatOrUndefined,
|
|
218
|
+
readFile: deps.readFile ?? readBoundedRegularFile,
|
|
219
|
+
realpath: deps.realpath ?? ((path) => realpathSync.native(path)),
|
|
220
|
+
bareShaped: deps.bareShaped ?? bareShaped,
|
|
221
|
+
};
|
|
222
|
+
const commons: string[] = [];
|
|
223
|
+
try {
|
|
224
|
+
for (let current = resolve(start); ; current = dirname(current)) {
|
|
225
|
+
const dotGit = join(current, ".git");
|
|
226
|
+
const stats = seams.lstat(dotGit);
|
|
227
|
+
if (stats !== undefined) {
|
|
228
|
+
commons.push(commonOfCheckout(current, dotGit, stats, seams));
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
// A bare repository ends git's discovery, but its shape can be committed to a checkout: keep walking (#192).
|
|
232
|
+
if (bareRepository(current, seams)) commons.push(commonOf(current, seams));
|
|
233
|
+
if (dirname(current) === current) break;
|
|
234
|
+
}
|
|
235
|
+
} catch (error) {
|
|
236
|
+
return { kind: "unresolved", reason: errorMessage(error) };
|
|
237
|
+
}
|
|
238
|
+
if (commons.length === 0) return NONE;
|
|
239
|
+
const drvfsRoot = drvfsRootOf(seams);
|
|
240
|
+
return { kind: "resolved", commons: [...new Set(commons)], ...(drvfsRoot === undefined ? {} : { drvfsRoot }) };
|
|
241
|
+
}
|
package/src/router/config.ts
CHANGED
|
@@ -573,6 +573,20 @@ export function setConfigNoticeHost(host: RouterHost | undefined): void {
|
|
|
573
573
|
configNoticeHost = host;
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
+
/** The host the configs of this process are built for (#80); `undefined` until the v2 entry sets it, built as on v1. */
|
|
577
|
+
let configBuildHost: RouterHost | undefined;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* #80: set by the OpenCode v2 entry (src/v2.ts) before its first loadConfig(). On `v2` a `null` inside an override layer's
|
|
581
|
+
* `presets` removes the inherited key (see {@link mergeLayerData}); otherwise, as on v1, that `null` is a value, which
|
|
582
|
+
* validation refuses and the key-path drop removes with a notice. A change marks every cached config stale.
|
|
583
|
+
*/
|
|
584
|
+
export function setConfigBuildHost(host: RouterHost | undefined): void {
|
|
585
|
+
if (host === configBuildHost) return;
|
|
586
|
+
configBuildHost = host;
|
|
587
|
+
invalidateConfigCache();
|
|
588
|
+
}
|
|
589
|
+
|
|
576
590
|
/**
|
|
577
591
|
* The notices of the config last built for `dir` (default: the working
|
|
578
592
|
* directory): keys dropped from the project layer, unknown `routing` keys, and
|
|
@@ -1960,11 +1974,13 @@ function tolerantRange(
|
|
|
1960
1974
|
}
|
|
1961
1975
|
|
|
1962
1976
|
/**
|
|
1963
|
-
* Repo-independent rules for `routing.executor.slotsDir
|
|
1964
|
-
* drive root, not UNC / device, and free of `*`.
|
|
1965
|
-
*
|
|
1977
|
+
* Repo-independent rules for `routing.executor.slotsDir` on `platform`. win32: an absolute drive path
|
|
1978
|
+
* (`C:\…`), not a drive root, not UNC / device, and free of `*`. POSIX (#192): an absolute path, not `/`,
|
|
1979
|
+
* without `//`, `*`, a `.`/`..` segment or a control character. Returns the problem, or `undefined`
|
|
1980
|
+
* when valid. The repository-relative rules are {@link validateSlotsDir}.
|
|
1966
1981
|
*/
|
|
1967
|
-
export function slotsDirProblem(value: string): string | undefined {
|
|
1982
|
+
export function slotsDirProblem(value: string, platform: NodeJS.Platform): string | undefined {
|
|
1983
|
+
if (platform !== "win32") return posixSlotsDirProblem(value);
|
|
1968
1984
|
if (value.includes("*")) return "must not contain '*'";
|
|
1969
1985
|
if (/^[\\/]{2}/.test(value)) return "must not be a UNC or device path";
|
|
1970
1986
|
if (!/^[A-Za-z]:[\\/]/.test(value)) return "must be an absolute path on a drive (like C:\\.omr-slots)";
|
|
@@ -1977,6 +1993,22 @@ export function slotsDirProblem(value: string): string | undefined {
|
|
|
1977
1993
|
return undefined;
|
|
1978
1994
|
}
|
|
1979
1995
|
|
|
1996
|
+
/** #192: the stored text of a `slotsDir`: on POSIX without a trailing `/` (`/` itself is kept); win32 as written. */
|
|
1997
|
+
export function slotsDirText(value: string, platform: NodeJS.Platform): string {
|
|
1998
|
+
return platform === "win32" ? value : value.replace(/^(.+?)\/+$/, "$1");
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
/** The POSIX rules of {@link slotsDirProblem} (as the text rules of a work root, `rootTextProblem`). */
|
|
2002
|
+
function posixSlotsDirProblem(value: string): string | undefined {
|
|
2003
|
+
if (value.includes("*")) return "must not contain '*'";
|
|
2004
|
+
if (/[\u0000-\u001f\u007f]/.test(value)) return "must not contain a control character";
|
|
2005
|
+
if (!value.startsWith("/")) return "must be an absolute path (like /home/me/.omr-slots)";
|
|
2006
|
+
if (value.includes("//")) return "must not contain '//'";
|
|
2007
|
+
if (value === "/") return "must not be the filesystem root";
|
|
2008
|
+
if (value.split("/").some((s) => s === "." || s === "..")) return "must not have a '.' or '..' segment";
|
|
2009
|
+
return undefined;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
1980
2012
|
/**
|
|
1981
2013
|
* Resolve links of the longest existing prefix of `p`; the missing tail is appended unchanged.
|
|
1982
2014
|
* `realpathSync.native` (QA-4.1-4): on win32 it also resolves junctions and 8.3 short names.
|
|
@@ -2006,7 +2038,7 @@ export type SlotsDirCheck = { readonly ok: true } | { readonly ok: false; readon
|
|
|
2006
2038
|
* realpaths (junctions, 8.3 names resolved) are compared, case-insensitively on win32.
|
|
2007
2039
|
*/
|
|
2008
2040
|
export function validateSlotsDir(slotsDir: string, toplevel: string): SlotsDirCheck {
|
|
2009
|
-
const base = slotsDirProblem(slotsDir);
|
|
2041
|
+
const base = slotsDirProblem(slotsDir, process.platform);
|
|
2010
2042
|
if (base !== undefined) return { ok: false, reason: base };
|
|
2011
2043
|
const fold = (p: string): string => (process.platform === "win32" ? p.toLowerCase() : p);
|
|
2012
2044
|
const pathApi = process.platform === "win32" ? win32 : posix;
|
|
@@ -2081,11 +2113,13 @@ function sanitizeExecutor(value: unknown): TolerantBlock<ExecutorOverrides> {
|
|
|
2081
2113
|
const land = tolerantEnum(value, "land", p, EXECUTOR_LAND_MODES, d.land, issues);
|
|
2082
2114
|
if (land !== undefined) out.land = land;
|
|
2083
2115
|
|
|
2084
|
-
const
|
|
2085
|
-
if (
|
|
2086
|
-
|
|
2116
|
+
const rawSlotsDir = value.slotsDir;
|
|
2117
|
+
if (rawSlotsDir !== undefined) {
|
|
2118
|
+
// #192: on POSIX a trailing `/` is dropped before the rules and storage, so the pool and the role-agent grant see one name.
|
|
2119
|
+
const slotsDir = typeof rawSlotsDir === "string" ? slotsDirText(rawSlotsDir, process.platform) : rawSlotsDir;
|
|
2120
|
+
const problem = slotsDir === null ? undefined : typeof slotsDir !== "string" ? "must be a string or null" : slotsDirProblem(slotsDir, process.platform);
|
|
2087
2121
|
if (problem === undefined) out.slotsDir = slotsDir as string | null;
|
|
2088
|
-
else issues.push(`${p}.slotsDir ${problem} (got ${showTolerant(
|
|
2122
|
+
else issues.push(`${p}.slotsDir ${problem} (got ${showTolerant(rawSlotsDir)}); using ${d.slotsDir}`);
|
|
2089
2123
|
}
|
|
2090
2124
|
|
|
2091
2125
|
const checks = value.integrationChecks;
|
|
@@ -2538,9 +2572,12 @@ export function validateConfig(raw: unknown): RouterConfig {
|
|
|
2538
2572
|
* Recursively merge `override` onto `base`. Plain objects merge key-by-key;
|
|
2539
2573
|
* arrays and scalars are replaced wholesale (so e.g. an overridden `rules` or
|
|
2540
2574
|
* `whenToUse` list replaces rather than appends). `undefined` values in the
|
|
2541
|
-
* override are skipped so they never blow away a base value.
|
|
2575
|
+
* override are skipped so they never blow away a base value. With
|
|
2576
|
+
* `nullRemoves` (#80), a `null` in the override removes the key from the
|
|
2577
|
+
* result instead, at every depth, and one with nothing to remove leaves no
|
|
2578
|
+
* trace; an array is still replaced as a whole, `null` entries included.
|
|
2542
2579
|
*/
|
|
2543
|
-
export function deepMerge(base: unknown, override: unknown): unknown {
|
|
2580
|
+
export function deepMerge(base: unknown, override: unknown, options: { nullRemoves?: boolean } = {}): unknown {
|
|
2544
2581
|
if (!isPlainObject(base) || !isPlainObject(override)) {
|
|
2545
2582
|
return override;
|
|
2546
2583
|
}
|
|
@@ -2553,6 +2590,14 @@ export function deepMerge(base: unknown, override: unknown): unknown {
|
|
|
2553
2590
|
// already do worse, so this is tidiness rather than a boundary, but a merge
|
|
2554
2591
|
// helper should not be the thing that reparents an object.
|
|
2555
2592
|
if (key === "__proto__" || key === "constructor") continue;
|
|
2593
|
+
if (options.nullRemoves === true) {
|
|
2594
|
+
const inherited = Object.hasOwn(result, key) ? result[key] : undefined;
|
|
2595
|
+
if (value === null) delete result[key];
|
|
2596
|
+
// An object with nothing to merge into is merged into `{}`, so a `null` inside it is dropped as well.
|
|
2597
|
+
else if (isPlainObject(value)) result[key] = deepMerge(isPlainObject(inherited) ? inherited : {}, value, options);
|
|
2598
|
+
else result[key] = value;
|
|
2599
|
+
continue;
|
|
2600
|
+
}
|
|
2556
2601
|
result[key] =
|
|
2557
2602
|
key in result && isPlainObject(result[key]) && isPlainObject(value)
|
|
2558
2603
|
? deepMerge(result[key], value)
|
|
@@ -3253,9 +3298,23 @@ function boundProjectExecutor(
|
|
|
3253
3298
|
return out;
|
|
3254
3299
|
}
|
|
3255
3300
|
|
|
3301
|
+
/**
|
|
3302
|
+
* #80: `data` deep-merged onto `lower`. On OpenCode v2 ({@link setConfigBuildHost}) a `null` inside the layer's `presets` (a
|
|
3303
|
+
* preset, a tier, a tier key, at any depth) removes that key from the result, so a layer can drop what it inherits
|
|
3304
|
+
* (`"effort": null` on a bundled tier); validation and the key-path drop then judge the result like any other. Outside
|
|
3305
|
+
* `presets`, and on v1, a `null` is a value as before: several keys take `null` as a setting
|
|
3306
|
+
* (`enforcement.maxDelegationDepth`, `enforcement.verify.graderTemperature`, …), and inside `presets` no key does.
|
|
3307
|
+
*/
|
|
3308
|
+
function mergeLayerData(lower: unknown, data: Record<string, unknown>): unknown {
|
|
3309
|
+
const merged = deepMerge(lower, data);
|
|
3310
|
+
if (configBuildHost !== "v2" || !isPlainObject(merged) || !isPlainObject(data.presets)) return merged;
|
|
3311
|
+
const lowerPresets = isPlainObject(lower) ? lower.presets : undefined;
|
|
3312
|
+
return { ...merged, presets: deepMerge(isPlainObject(lowerPresets) ? lowerPresets : {}, data.presets, { nullRemoves: true }) };
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3256
3315
|
/** Merge an override while keeping project classifier budgets and executor keys within the lower layers' bounds. */
|
|
3257
3316
|
function mergeOverrideLayer(lower: unknown, layer: OverrideLayer, notices: ConfigNotice[]): unknown {
|
|
3258
|
-
const merged =
|
|
3317
|
+
const merged = mergeLayerData(lower, layer.data);
|
|
3259
3318
|
if (!layer.project || !isPlainObject(merged) || !isPlainObject(merged.routing)) return merged;
|
|
3260
3319
|
const projectRouting = layer.data.routing;
|
|
3261
3320
|
const lowerRouting = isPlainObject(lower) ? lower.routing : undefined;
|