@open-cr-agent/vcs-local 0.1.2 → 0.3.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/dist/commits.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { OcraError } from "@open-cr-agent/core";
1
2
  import { git } from "./git.js";
2
3
  const FETCH_TIMEOUT_MS = 5 * 60_000;
3
4
  // Pull request commits are often missing from a local clone (shallow CI
@@ -7,7 +8,7 @@ export async function ensureCommits(root, shas, refspecs = [], remote = "origin"
7
8
  // Anything but a commit id could be read by git fetch as an option.
8
9
  const invalid = shas.filter((sha) => !/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(sha));
9
10
  if (invalid.length > 0)
10
- throw new Error(`Not commit ids: ${invalid.join(", ")}`);
11
+ throw new OcraError("INPUT_INVALID", `Not commit ids: ${invalid.join(", ")}`);
11
12
  const missing = async () => {
12
13
  const result = [];
13
14
  for (const sha of shas) {
@@ -36,7 +37,7 @@ export async function ensureCommits(root, shas, refspecs = [], remote = "origin"
36
37
  absent = await missing();
37
38
  }
38
39
  if (absent.length > 0) {
39
- throw new Error(`Commits ${absent.join(", ")} are not in this repository and could not be fetched from ${remote}`);
40
+ throw new OcraError("VCS_REF_UNKNOWN", `Commits ${absent.join(", ")} are not in this repository and could not be fetched from ${remote}`);
40
41
  }
41
42
  }
42
43
  //# sourceMappingURL=commits.js.map
package/dist/git.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { OcraError } from "@open-cr-agent/core";
1
2
  export interface GitOptions {
2
3
  cwd: string;
3
4
  input?: string;
@@ -7,7 +8,7 @@ export interface GitOptions {
7
8
  timeoutMs?: number;
8
9
  }
9
10
  export declare const GIT_TIMEOUT_MS: number;
10
- export declare class GitError extends Error {
11
+ export declare class GitError extends OcraError {
11
12
  readonly args: readonly string[];
12
13
  readonly exitCode: number | undefined;
13
14
  readonly stderr: string;
package/dist/git.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { execFile } from "node:child_process";
2
+ import { OcraError } from "@open-cr-agent/core";
2
3
  // Every git call ends: a fetch can wait on the network forever, and a diff
3
4
  // of a huge repository should fail rather than hang the review.
4
5
  export const GIT_TIMEOUT_MS = 10 * 60_000;
5
- export class GitError extends Error {
6
+ export class GitError extends OcraError {
6
7
  args;
7
8
  exitCode;
8
9
  stderr;
9
10
  constructor(args, exitCode, stderr) {
10
- super(`git ${args.join(" ")} failed (exit ${exitCode ?? "unknown"}): ${stderr.trim()}`);
11
+ super("VCS_GIT_FAILED", `git ${args.join(" ")} failed (exit ${exitCode ?? "unknown"}): ${stderr.trim()}`);
11
12
  this.args = args;
12
13
  this.exitCode = exitCode;
13
14
  this.stderr = stderr;
15
+ this.name = "GitError";
14
16
  }
15
17
  }
16
18
  const MAX_OUTPUT_BYTES = 512 * 1024 * 1024;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- export { ensureCommits } from "./commits.js";
2
1
  export { GitError } from "./git.js";
3
- export * from "./history.js";
4
- export * from "./local-adapter.js";
5
- export * from "./plugin.js";
2
+ export type { LocalGitOptions, LocalTarget } from "./local-adapter.js";
3
+ export { localGitPlugin } from "./plugin.js";
6
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- export { ensureCommits } from "./commits.js";
2
1
  export { GitError } from "./git.js";
3
- export * from "./history.js";
4
- export * from "./local-adapter.js";
5
- export * from "./plugin.js";
2
+ export { localGitPlugin } from "./plugin.js";
6
3
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ export { ensureCommits } from "./commits.js";
2
+ export { type ChangedFiles, filesChangedSince } from "./history.js";
3
+ export { LocalGitAdapter } from "./local-adapter.js";
4
+ export { findRepositoryRoot } from "./plugin.js";
5
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1,7 @@
1
+ // "@open-cr-agent/vcs-local/internal": what the CLI uses beyond the public
2
+ // entry. Not a contract: any release may change it.
3
+ export { ensureCommits } from "./commits.js";
4
+ export { filesChangedSince } from "./history.js";
5
+ export { LocalGitAdapter } from "./local-adapter.js";
6
+ export { findRepositoryRoot } from "./plugin.js";
7
+ //# sourceMappingURL=internal.js.map
@@ -1,7 +1,8 @@
1
1
  import { cp, lstat, mkdtemp, open, 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
- import { parseUnifiedDiff, } from "@open-cr-agent/core";
4
+ import { OcraError, } from "@open-cr-agent/core";
5
+ import { parseUnifiedDiff } from "@open-cr-agent/core/internal";
5
6
  import { GitError, git, isShallow, SHALLOW_HINT } from "./git.js";
6
7
  const WORKING_TREE = "working-tree";
7
8
  const SEARCH_RESULT_LIMIT = 100;
@@ -180,7 +181,7 @@ async function mergeBase(root, from, to) {
180
181
  }
181
182
  catch (error) {
182
183
  if (error instanceof GitError && (await isShallow(root))) {
183
- throw new Error(`Cannot find where ${from.slice(0, 7)} and ${to.slice(0, 7)} diverge: ${SHALLOW_HINT}`);
184
+ throw new OcraError("VCS_GIT_FAILED", `Cannot find where ${from.slice(0, 7)} and ${to.slice(0, 7)} diverge: ${SHALLOW_HINT}`);
184
185
  }
185
186
  throw error;
186
187
  }
@@ -233,7 +234,7 @@ function request(id, title, description, baseSha, headSha) {
233
234
  async function verifyCommit(root, ref) {
234
235
  const sha = await tryVerifyCommit(root, ref);
235
236
  if (sha === undefined)
236
- throw new Error(`Unknown commit: ${ref}`);
237
+ throw new OcraError("VCS_REF_UNKNOWN", `Unknown commit: ${ref}`);
237
238
  return sha;
238
239
  }
239
240
  // --end-of-options stops a user-supplied ref such as "--output=x" from being
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-cr-agent/vcs-local",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "Local git adapter for Open-CR-Agent: working tree, ranges and commits",
5
5
  "keywords": [
6
6
  "code-review",
@@ -18,18 +18,26 @@
18
18
  "node": ">=22.19"
19
19
  },
20
20
  "type": "module",
21
+ "sideEffects": false,
21
22
  "exports": {
22
23
  ".": {
24
+ "@open-cr-agent/source": "./src/index.ts",
23
25
  "types": "./dist/index.d.ts",
24
26
  "default": "./dist/index.js"
25
- }
27
+ },
28
+ "./internal": {
29
+ "@open-cr-agent/source": "./src/internal.ts",
30
+ "types": "./dist/internal.d.ts",
31
+ "default": "./dist/internal.js"
32
+ },
33
+ "./package.json": "./package.json"
26
34
  },
27
35
  "files": [
28
36
  "dist",
29
37
  "!dist/**/*.map"
30
38
  ],
31
39
  "dependencies": {
32
- "@open-cr-agent/core": "0.1.2",
40
+ "@open-cr-agent/core": "0.3.0",
33
41
  "zod": "^4.6.5"
34
42
  },
35
43
  "publishConfig": {