@open-cr-agent/vcs-local 0.5.0 → 0.7.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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # @open-cr-agent/vcs-local
2
2
 
3
- The adapter for local Git changes (working tree, ranges and commits) of [Open-CR-Agent](https://github.com/jma49/Open-CR-Agent), the multi-agent code reviewer. Most users want [`@open-cr-agent/cli`](https://www.npmjs.com/package/@open-cr-agent/cli), which provides the `ocra` command and installs this package; see the [manual](https://ocracloud.com). All `@open-cr-agent` packages are released together at one version. Apache-2.0.
3
+ The local Git adapter (working tree, ranges, commits) of [Open-CR-Agent](https://github.com/jma49/Open-CR-Agent), the multi-agent code reviewer. Most users want [`@open-cr-agent/cli`](https://www.npmjs.com/package/@open-cr-agent/cli) (the `ocra` command) and the [manual](https://ocracloud.com). All packages share one version. Apache-2.0.
package/dist/commits.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export declare function ensureCommits(root: string, shas: readonly string[], refspecs?: readonly string[], remote?: string): Promise<void>;
2
- //# sourceMappingURL=commits.d.ts.map
package/dist/commits.js CHANGED
@@ -40,4 +40,3 @@ export async function ensureCommits(root, shas, refspecs = [], remote = "origin"
40
40
  throw new OcraError("VCS_REF_UNKNOWN", `Commits ${absent.join(", ")} are not in this repository and could not be fetched from ${remote}`);
41
41
  }
42
42
  }
43
- //# sourceMappingURL=commits.js.map
package/dist/git.d.ts CHANGED
@@ -7,7 +7,6 @@ export interface GitOptions {
7
7
  truncateAt?: number;
8
8
  timeoutMs?: number;
9
9
  }
10
- export declare const GIT_TIMEOUT_MS: number;
11
10
  export declare class GitError extends OcraError {
12
11
  readonly args: readonly string[];
13
12
  readonly exitCode: number | undefined;
@@ -17,4 +16,3 @@ export declare class GitError extends OcraError {
17
16
  export declare function git(args: readonly string[], options: GitOptions): Promise<string>;
18
17
  export declare function isShallow(root: string): Promise<boolean>;
19
18
  export declare const SHALLOW_HINT = "the clone is shallow; fetch the full history (for example actions/checkout with fetch-depth: 0)";
20
- //# sourceMappingURL=git.d.ts.map
package/dist/git.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { OcraError } from "@open-cr-agent/core";
3
+ import { errnoCode } from "@open-cr-agent/core/internal";
3
4
  // Every git call ends: a fetch can wait on the network forever, and a diff
4
5
  // of a huge repository should fail rather than hang the review.
5
- export const GIT_TIMEOUT_MS = 10 * 60_000;
6
+ const GIT_TIMEOUT_MS = 10 * 60_000;
6
7
  export class GitError extends OcraError {
7
8
  args;
8
9
  exitCode;
@@ -16,7 +17,7 @@ export class GitError extends OcraError {
16
17
  }
17
18
  }
18
19
  const MAX_OUTPUT_BYTES = 512 * 1024 * 1024;
19
- const CLOSED_PIPE = new Set(["EPIPE", "ENOTCONN", "ECONNRESET"]);
20
+ const CLOSED_PIPE = new Set(["EPIPE", "ENOTCONN", "ECONNRESET", "EOF"]);
20
21
  export function git(args, options) {
21
22
  const okExitCodes = options.okExitCodes ?? [0];
22
23
  return new Promise((resolve, reject) => {
@@ -46,10 +47,10 @@ export function git(args, options) {
46
47
  });
47
48
  // git may exit before reading stdin; its exit code already reports the
48
49
  // outcome, so a broken pipe on our side carries no information. Which
49
- // error that is depends on timing and platform (EPIPE, or ENOTCONN on
50
- // macOS when the pipe closed before the write).
50
+ // error that is depends on timing and platform (EPIPE, ENOTCONN on
51
+ // macOS when the pipe closed before the write, EOF on Windows).
51
52
  child.stdin?.on("error", (error) => {
52
- if (!CLOSED_PIPE.has(error.code ?? ""))
53
+ if (!CLOSED_PIPE.has(errnoCode(error) ?? ""))
53
54
  reject(error);
54
55
  });
55
56
  if (options.input === undefined)
@@ -68,4 +69,3 @@ export async function isShallow(root) {
68
69
  return out.trim() === "true";
69
70
  }
70
71
  export const SHALLOW_HINT = "the clone is shallow; fetch the full history (for example actions/checkout with fetch-depth: 0)";
71
- //# sourceMappingURL=git.js.map
package/dist/history.d.ts CHANGED
@@ -4,4 +4,3 @@ export type ChangedFiles = {
4
4
  reason: string;
5
5
  };
6
6
  export declare function filesChangedSince(root: string, from: string, to: string): Promise<ChangedFiles>;
7
- //# sourceMappingURL=history.d.ts.map
package/dist/history.js CHANGED
@@ -41,4 +41,3 @@ export async function filesChangedSince(root, from, to) {
41
41
  ], { cwd: root });
42
42
  return { files: out.split("\0").filter((p) => p !== "") };
43
43
  }
44
- //# sourceMappingURL=history.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { GitError } from "./git.js";
2
2
  export type { LocalGitOptions, LocalTarget } from "./local-adapter.js";
3
3
  export { localGitPlugin } from "./plugin.js";
4
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export { GitError } from "./git.js";
2
2
  export { localGitPlugin } from "./plugin.js";
3
- //# sourceMappingURL=index.js.map
@@ -1,5 +1,4 @@
1
1
  export { ensureCommits } from "./commits.js";
2
- export { type ChangedFiles, filesChangedSince } from "./history.js";
2
+ export { filesChangedSince } from "./history.js";
3
3
  export { LocalGitAdapter } from "./local-adapter.js";
4
4
  export { findRepositoryRoot } from "./plugin.js";
5
- //# sourceMappingURL=internal.d.ts.map
package/dist/internal.js CHANGED
@@ -4,4 +4,3 @@ export { ensureCommits } from "./commits.js";
4
4
  export { filesChangedSince } from "./history.js";
5
5
  export { LocalGitAdapter } from "./local-adapter.js";
6
6
  export { findRepositoryRoot } from "./plugin.js";
7
- //# sourceMappingURL=internal.js.map
@@ -15,9 +15,9 @@ export interface LocalGitOptions {
15
15
  }
16
16
  export declare const MAX_READ_BYTES: number;
17
17
  export declare class LocalGitAdapter implements VcsAdapter {
18
- private readonly options;
19
18
  readonly name = "local";
20
19
  private resolved;
20
+ private readonly options;
21
21
  constructor(options: LocalGitOptions);
22
22
  repositoryRoot(): Promise<string>;
23
23
  getChangeRequest(): Promise<ChangeRequest>;
@@ -32,4 +32,3 @@ export declare class LocalGitAdapter implements VcsAdapter {
32
32
  private target;
33
33
  private resolveTarget;
34
34
  }
35
- //# sourceMappingURL=local-adapter.d.ts.map
@@ -1,8 +1,8 @@
1
- import { cp, lstat, mkdtemp, open, readFile, readlink, realpath, rm } from "node:fs/promises";
1
+ import { cp, lstat, mkdtemp, open, readdir, readFile, readlink, realpath, rm, } from "node:fs/promises";
2
2
  import { tmpdir } from "node:os";
3
3
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import { OcraError, } from "@open-cr-agent/core";
5
- import { parseUnifiedDiff } from "@open-cr-agent/core/internal";
5
+ import { errnoCode, isNotFound, parseUnifiedDiff } from "@open-cr-agent/core/internal";
6
6
  import { GitError, git, isShallow, SHALLOW_HINT } from "./git.js";
7
7
  const WORKING_TREE = "working-tree";
8
8
  const SEARCH_RESULT_LIMIT = 100;
@@ -29,9 +29,9 @@ const DIFF_ARGS = [
29
29
  "--dst-prefix=b/",
30
30
  ];
31
31
  export class LocalGitAdapter {
32
- options;
33
32
  name = "local";
34
33
  resolved;
34
+ options;
35
35
  constructor(options) {
36
36
  this.options = options;
37
37
  }
@@ -160,7 +160,7 @@ async function workspaceDiff(root, base) {
160
160
  // timestamps to catch same-second, same-size edits ("racy git"), and a
161
161
  // fresh timestamp would make it trust stale stat data and miss them.
162
162
  await cp(resolve(root, realIndex), index, { preserveTimestamps: true }).catch((error) => {
163
- if (error.code !== "ENOENT")
163
+ if (!isNotFound(error))
164
164
  throw error;
165
165
  });
166
166
  const env = { GIT_INDEX_FILE: index, GIT_LITERAL_PATHSPECS: "1" };
@@ -194,16 +194,20 @@ function relativeInside(root, absolute) {
194
194
  return inside;
195
195
  }
196
196
  // Reads what git would store, as range and commit mode do: a symlink reads as
197
- // its target path and a path through a symlinked directory does not exist.
198
- // Following links would let a committed `notes.txt -> .env` read a file the
199
- // core access policy refuses by name.
197
+ // its target path, a path through a symlinked directory does not exist, and
198
+ // neither does another spelling of a file's name. Following links would let a
199
+ // committed `notes.txt -> .env` read a file the core access policy refuses by
200
+ // name; so would a spelling that a case-insensitive file system folds to it.
200
201
  async function readWorkingTreeFile(root, inside) {
201
202
  try {
202
203
  const parent = dirname(inside);
203
204
  const realParent = await realpath(resolve(root, parent));
204
205
  if (realParent !== resolve(await realpath(root), parent))
205
206
  return undefined;
206
- const path = join(realParent, basename(inside));
207
+ const name = basename(inside);
208
+ if (!(await isListed(realParent, name)))
209
+ return undefined;
210
+ const path = join(realParent, name);
207
211
  const stat = await lstat(path);
208
212
  if (stat.isSymbolicLink())
209
213
  return await readlink(path, "utf8");
@@ -222,12 +226,21 @@ async function readWorkingTreeFile(root, inside) {
222
226
  }
223
227
  }
224
228
  catch (error) {
225
- const code = error.code;
229
+ const code = errnoCode(error);
226
230
  if (code === "ENOENT" || code === "ENOTDIR")
227
231
  return undefined;
228
232
  throw error;
229
233
  }
230
234
  }
235
+ // Up to Unicode normalization: git on macOS reports names precomposed,
236
+ // whatever their form on disk.
237
+ async function isListed(dir, name) {
238
+ const entries = await readdir(dir);
239
+ if (entries.includes(name))
240
+ return true;
241
+ const wanted = name.normalize("NFC");
242
+ return entries.some((entry) => entry.normalize("NFC") === wanted);
243
+ }
231
244
  function request(id, title, description, baseSha, headSha) {
232
245
  return { id, title, description, baseSha, headSha };
233
246
  }
@@ -250,4 +263,3 @@ async function tryVerifyCommit(root, ref) {
250
263
  async function emptyTree(root) {
251
264
  return (await git(["hash-object", "-t", "tree", "--stdin"], { cwd: root, input: "" })).trim();
252
265
  }
253
- //# sourceMappingURL=local-adapter.js.map
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import type { OcraPlugin } from "@open-cr-agent/core";
2
2
  export declare const localGitPlugin: OcraPlugin;
3
3
  export declare function findRepositoryRoot(cwd: string): Promise<string>;
4
- //# sourceMappingURL=plugin.d.ts.map
package/dist/plugin.js CHANGED
@@ -18,4 +18,3 @@ export const localGitPlugin = {
18
18
  export async function findRepositoryRoot(cwd) {
19
19
  return (await git(["rev-parse", "--show-toplevel"], { cwd })).trim();
20
20
  }
21
- //# sourceMappingURL=plugin.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-cr-agent/vcs-local",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Local git adapter for Open-CR-Agent: working tree, ranges and commits",
5
5
  "keywords": [
6
6
  "code-review",
@@ -37,10 +37,13 @@
37
37
  "!dist/**/*.map"
38
38
  ],
39
39
  "dependencies": {
40
- "@open-cr-agent/core": "0.5.0",
40
+ "@open-cr-agent/core": "0.7.0",
41
41
  "zod": "^4.6.5"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"
45
+ },
46
+ "devDependencies": {
47
+ "@open-cr-agent/test-support": "0.0.0"
45
48
  }
46
49
  }