opencode-model-router 1.14.0 → 2.0.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.
@@ -24,7 +24,8 @@ import { isCheckable } from "./dod";
24
24
  import { runDeterministic } from "./deterministic";
25
25
  import { runChecker } from "./checker";
26
26
  import type { ArtefactView, CheckerDeps } from "./checker";
27
- import { resolveBaseDir } from "./paths";
27
+ import { isAbsolute } from "node:path";
28
+ import { isWithinDir, resolveBaseDir } from "./paths";
28
29
 
29
30
  /** The concrete, inspectable result of a delegation (artefact contract §3.3). */
30
31
  export interface Artefact {
@@ -62,6 +63,12 @@ export interface GateDeps {
62
63
  */
63
64
  require?: "never" | "whenDoDPresent" | "always";
64
65
  strictUnverifiable?: boolean;
66
+ /**
67
+ * Canonicalizes a path for the outside-the-base check: one directory can be spelled several
68
+ * ways (a Windows 8.3 short name, a symlink such as macOS /var -> /private/var), and a lexical
69
+ * comparison would call the producer's own files "outside". Absent means lexical comparison.
70
+ */
71
+ canonicalPath?: (path: string) => string;
65
72
  }
66
73
 
67
74
  export interface GateResult {
@@ -187,6 +194,14 @@ export async function accept(
187
194
 
188
195
  let verdict: Verdict;
189
196
  if (dod.kind === "deterministic") {
197
+ const canonical = deps.canonicalPath ?? ((path: string) => path);
198
+ const canonicalBase = canonical(effectiveBaseDir);
199
+ if (artefact.changedFiles.length > 0 && artefact.changedFiles.every(
200
+ ({ path }) => isAbsolute(path) && !isWithinDir(canonical(path), canonicalBase),
201
+ )) {
202
+ const reason = `the producer changed files only outside ${effectiveBaseDir} (e.g. ${artefact.changedFiles[0].path}); checks run there cannot see them. Add "cwd: <dir>" to the [acceptance] block to verify where the work landed.`;
203
+ return gateResult({ pass: false, outcome: "unverifiable", method: "none", reasons: [reason], caveats: [reason] }, dodSource, deps.strictUnverifiable);
204
+ }
190
205
  verdict = await runDeterministic(dod, {
191
206
  ...deps.deterministic,
192
207
  cwd: effectiveBaseDir,
@@ -5,7 +5,15 @@
5
5
  // resolve relative paths against an effective base dir instead of the router's
6
6
  // own cwd.
7
7
 
8
- import { isAbsolute, join } from "node:path";
8
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
9
+
10
+ /** Lexical containment only: no filesystem or symlink resolution. */
11
+ export function isWithinDir(path: string, dir: string): boolean {
12
+ const key = (p: string) => process.platform === "win32" ? resolve(p).toLowerCase() : resolve(p);
13
+ const delta = relative(key(dir), key(path));
14
+ // Only a leading `..` SEGMENT leaves the dir: a child named `..cache` stays inside.
15
+ return delta !== ".." && !delta.startsWith(`..${sep}`) && !isAbsolute(delta);
16
+ }
9
17
 
10
18
  /**
11
19
  * Resolve the effective base directory for a delegation's verification.