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
|
@@ -12,14 +12,15 @@
|
|
|
12
12
|
* unresolvable entry) — fail closed;
|
|
13
13
|
* - resolves (links and junctions followed, case and 8.3 short names as on disk) to a path with a `.git` segment, or into the git
|
|
14
14
|
* directory or common directory of the session directory's repository (also when it is not named `.git`: a bare repository's
|
|
15
|
-
* linked worktree, `--separate-git-dir`), the checkout's own files excepted when such a directory holds the checkout
|
|
15
|
+
* linked worktree, `--separate-git-dir`), the checkout's own files excepted when such a directory holds the checkout; or (#161)
|
|
16
|
+
* into the bare repository the session directory itself is in, the files of its linked worktrees inside it excepted.
|
|
16
17
|
* Each file is resolved in two readings, and refused when either hits: as written (links resolved before any `..` after them, as
|
|
17
18
|
* the kernel does on POSIX) and as the host resolves it (`path.resolve`: `..` collapsed as text first). A patch whose targets
|
|
18
19
|
* cannot be read is refused too (fail closed). Never throws.
|
|
19
20
|
*/
|
|
20
|
-
import { lstatSync, realpathSync } from "node:fs";
|
|
21
|
-
import { posix, win32 } from "node:path";
|
|
22
|
-
import { gitPointers, nearestRepository } from "./git-tools";
|
|
21
|
+
import { existsSync, lstatSync, readdirSync, readlinkSync, realpathSync, statSync } from "node:fs";
|
|
22
|
+
import { dirname, join, posix, resolve, win32 } from "node:path";
|
|
23
|
+
import { gitPointers, isNetworkOrDevicePath, nearestRepository, readBoundedRegularFile } from "./git-tools";
|
|
23
24
|
import { WRITE_CLASS, writeTargetTexts } from "./tool-paths";
|
|
24
25
|
import { canonicalAuthorityPath, insideWorkRoot } from "../routing/roles/work-root";
|
|
25
26
|
import { displaySafe, namesGitMetadata } from "../routing/roles/read-set";
|
|
@@ -30,6 +31,12 @@ export interface SessionGitDirectories {
|
|
|
30
31
|
readonly directories: readonly string[];
|
|
31
32
|
/** The checkout (repository top) holding the session directory; undefined outside a repository. */
|
|
32
33
|
readonly checkout: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* #161: the linked worktrees inside a bare repository among `directories` (the session directory's own, when it is in one); each
|
|
36
|
+
* exempts its own files as `checkout` does. Called only once a target lands in a git directory the checkout does not exempt it
|
|
37
|
+
* from. Absent when there is no such repository.
|
|
38
|
+
*/
|
|
39
|
+
readonly worktrees?: () => readonly string[];
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
/** Seams of {@link gitMetadataWriteRefusal} (tests). */
|
|
@@ -83,7 +90,7 @@ const NO_GIT_DIRECTORIES: SessionGitDirectories = Object.freeze({ directories: [
|
|
|
83
90
|
* from its `.git` pointers without running git ({@link gitPointers}: bounded, never followed onto a network or device path). No
|
|
84
91
|
* directories when there is no repository or a pointer is refused or unreadable: the `.git` segment checks still apply.
|
|
85
92
|
*/
|
|
86
|
-
function
|
|
93
|
+
function checkoutGitDirectories(directory: string): SessionGitDirectories {
|
|
87
94
|
try {
|
|
88
95
|
const checkout = nearestRepository(directory);
|
|
89
96
|
if (checkout === undefined) return NO_GIT_DIRECTORIES;
|
|
@@ -103,16 +110,146 @@ function sessionGitDirectories(directory: string): SessionGitDirectories {
|
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
|
|
113
|
+
/** Bound of the `gitdir` file of a linked worktree's admin directory (as git-tools bounds `.git` and `commondir`). */
|
|
114
|
+
const GITDIR_FILE_BYTES = 4 * 1024;
|
|
115
|
+
/** #161: at most this many entries of a bare repository's `worktrees/` are read; the files of any other worktree stay refused. */
|
|
116
|
+
const MAX_BARE_WORKTREES = 256;
|
|
117
|
+
/** #161: git's own directories in a git directory: a worktree in one of them is never exempt. */
|
|
118
|
+
const GIT_OWN_DIRECTORIES = [
|
|
119
|
+
"hooks", "info", "logs", "objects", "refs", "worktrees", "modules", "lfs", "rr-cache", "remotes", "branches", "reftable",
|
|
120
|
+
] as const;
|
|
121
|
+
|
|
122
|
+
/** Two canonical paths name the same directory (win32 case folding). */
|
|
123
|
+
function sameDirectory(a: string, b: string): boolean {
|
|
124
|
+
return insideWorkRoot(a, b) && insideWorkRoot(b, a);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** What `path` itself is, never following a link: a plain file or directory, a link (symlink or junction), or undefined. */
|
|
128
|
+
function entryKind(path: string): "file" | "directory" | "link" | undefined {
|
|
129
|
+
try {
|
|
130
|
+
const stats = lstatSync(path);
|
|
131
|
+
return stats.isSymbolicLink() ? "link" : stats.isFile() ? "file" : stats.isDirectory() ? "directory" : undefined;
|
|
132
|
+
} catch {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* #161: `path` is a directory, or a link to a local one (git accepts a bare repository whose `objects` or `refs` is a link): the
|
|
139
|
+
* link's text is never followed when it names a network or device path, nor is a target that resolves to one.
|
|
140
|
+
*/
|
|
141
|
+
function directoryOrLocalLink(path: string): boolean {
|
|
142
|
+
const kind = entryKind(path);
|
|
143
|
+
if (kind !== "link") return kind === "directory";
|
|
144
|
+
try {
|
|
145
|
+
if (isNetworkOrDevicePath(readlinkSync(path))) return false;
|
|
146
|
+
const target = realpathSync.native(path);
|
|
147
|
+
return !isNetworkOrDevicePath(target) && statSync(target).isDirectory();
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* #161: `dir` has git's bare repository shape, as git's own discovery checks it: a `HEAD` regular file, and `objects` and `refs`
|
|
155
|
+
* directories, each also a link to a local directory ({@link directoryOrLocalLink}). Also used by the on-disk common-directory
|
|
156
|
+
* lookup of role agent registration (router/common-dir.ts, #192).
|
|
157
|
+
*/
|
|
158
|
+
export function bareShaped(dir: string): boolean {
|
|
159
|
+
return entryKind(join(dir, "HEAD")) === "file" && directoryOrLocalLink(join(dir, "objects")) && directoryOrLocalLink(join(dir, "refs"));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** `text` as the first `gitdir:` line of a `.git` file names it, or undefined. */
|
|
163
|
+
function gitdirLine(text: string | undefined): string | undefined {
|
|
164
|
+
return /^gitdir:\s*(.+?)\s*$/m.exec(text ?? "")?.[1];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* #161: the linked worktrees of the bare repository `bare` (canonical) that lie inside it, each confirmed both ways: the `gitdir`
|
|
169
|
+
* file of its admin directory `worktrees/<name>` names `<worktree>/.git`, that `.git` file names the same admin directory back,
|
|
170
|
+
* and the admin directory's `commondir` names `bare`. `worktrees`, each `worktrees/<name>` and every file read must be a plain
|
|
171
|
+
* directory or regular file (no link is followed, so none reaches a network path); each file is read bounded (4 KiB) and a pointer
|
|
172
|
+
* naming a network or device path is never followed. A worktree that is `bare` itself, holds its admin directory or lies in one of
|
|
173
|
+
* git's own directories is never one. Canonical; an entry that cannot be read is skipped (its files stay refused). Never throws.
|
|
174
|
+
*/
|
|
175
|
+
function worktreesInside(bare: string): string[] {
|
|
176
|
+
const read = (path: string): string | undefined =>
|
|
177
|
+
(entryKind(path) === "file" ? readBoundedRegularFile(path, GITDIR_FILE_BYTES, "worktree pointer")?.trim() : undefined);
|
|
178
|
+
let names: string[];
|
|
179
|
+
try {
|
|
180
|
+
if (entryKind(join(bare, "worktrees")) !== "directory") return [];
|
|
181
|
+
names = readdirSync(join(bare, "worktrees"));
|
|
182
|
+
} catch {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
const found: string[] = [];
|
|
186
|
+
for (const name of names.slice(0, MAX_BARE_WORKTREES)) {
|
|
187
|
+
try {
|
|
188
|
+
const admin = join(bare, "worktrees", name);
|
|
189
|
+
if (entryKind(admin) !== "directory") continue;
|
|
190
|
+
const named = read(join(admin, "gitdir"));
|
|
191
|
+
if (named === undefined || named === "" || isNetworkOrDevicePath(named)) continue;
|
|
192
|
+
const candidate = dirname(resolve(admin, named));
|
|
193
|
+
if (!insideWorkRoot(candidate, bare)) continue; // nothing outside the repository is touched
|
|
194
|
+
const worktree = realpathSync.native(candidate);
|
|
195
|
+
if (!insideWorkRoot(worktree, bare) || insideWorkRoot(bare, worktree) || insideWorkRoot(admin, worktree)) continue;
|
|
196
|
+
if (GIT_OWN_DIRECTORIES.some((own) => insideWorkRoot(worktree, join(bare, own)))) continue;
|
|
197
|
+
const back = gitdirLine(read(join(worktree, ".git")));
|
|
198
|
+
if (back === undefined || isNetworkOrDevicePath(back) || !sameDirectory(resolve(worktree, back), admin)) continue;
|
|
199
|
+
const common = read(join(admin, "commondir"));
|
|
200
|
+
if (common === undefined || common === "" || isNetworkOrDevicePath(common) || !sameDirectory(resolve(admin, common), bare)) continue;
|
|
201
|
+
found.push(worktree);
|
|
202
|
+
} catch {
|
|
203
|
+
// unreadable: not exempt
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return found;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* #161: the bare repository the session directory is in — `directory` itself or its nearest ancestor with git's bare shape
|
|
211
|
+
* ({@link bareShaped}) when no checkout (a directory holding `.git`) comes first, as git's own discovery finds the repository —
|
|
212
|
+
* canonical. Undefined otherwise, and when it cannot be read (the checkout's directories and the `.git` segment checks still
|
|
213
|
+
* apply). Spawns nothing; never throws.
|
|
214
|
+
*/
|
|
215
|
+
function bareRepositoryOf(directory: string): string | undefined {
|
|
216
|
+
try {
|
|
217
|
+
for (let current = directory; ; current = dirname(current)) {
|
|
218
|
+
if (existsSync(join(current, ".git"))) return undefined; // a checkout: its git directories come from its pointers
|
|
219
|
+
if (bareShaped(current)) return realpathSync.native(current);
|
|
220
|
+
if (dirname(current) === current) return undefined;
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The git directories of the session directory's repository ({@link checkoutGitDirectories}) and (#161) the bare repository the
|
|
229
|
+
* session directory itself is in ({@link bareRepositoryOf}: OpenCode opened at `proj.git`, which holds its worktrees), which no
|
|
230
|
+
* `.git` pointer names; its linked worktrees ({@link worktreesInside}) are read only once a target lands in it. Never throws.
|
|
231
|
+
*/
|
|
232
|
+
function sessionGitDirectories(directory: string): SessionGitDirectories {
|
|
233
|
+
const found = checkoutGitDirectories(directory);
|
|
234
|
+
const bare = bareRepositoryOf(directory);
|
|
235
|
+
if (bare === undefined) return found;
|
|
236
|
+
const directories = found.directories.some((dir) => sameDirectory(dir, bare)) ? found.directories : [...found.directories, bare];
|
|
237
|
+
let worktrees: readonly string[] | undefined;
|
|
238
|
+
return { directories, checkout: found.checkout, worktrees: () => (worktrees ??= worktreesInside(bare)) };
|
|
239
|
+
}
|
|
240
|
+
|
|
106
241
|
/**
|
|
107
242
|
* `target` (canonical) lies in one of the session repository's git directories. A git directory that holds the checkout itself
|
|
108
243
|
* (a bare repository with its worktree inside it, or a malformed pointer naming the checkout) exempts only the checkout's own
|
|
109
|
-
* files; a git directory inside the checkout exempts nothing.
|
|
244
|
+
* files; a git directory inside the checkout exempts nothing. #161: so does a linked worktree a bare repository holds (read only
|
|
245
|
+
* when the checkout does not exempt the target).
|
|
110
246
|
*/
|
|
111
247
|
function insideGitDirectory(target: string, git: SessionGitDirectories): boolean {
|
|
112
248
|
const top = git.checkout;
|
|
113
249
|
return git.directories.some((dir) => {
|
|
114
250
|
if (!insideWorkRoot(target, dir)) return false;
|
|
115
|
-
|
|
251
|
+
if (top !== undefined && insideWorkRoot(top, dir) && insideWorkRoot(target, top)) return false;
|
|
252
|
+
return !(git.worktrees?.() ?? []).some((worktree) => insideWorkRoot(worktree, dir) && insideWorkRoot(target, worktree));
|
|
116
253
|
});
|
|
117
254
|
}
|
|
118
255
|
|