@a2f0/agent-tool 0.1.61 → 0.1.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2f0/agent-tool",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "packageManager": "bun@1.4.4",
5
5
  "type": "module",
6
6
  "description": "Portable cross-agent review, PR workflows, and shared skills",
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
3
3
  import { loadConfig, type AgentToolConfig } from "../config";
4
4
  import { remoteBranchHead } from "../git/prContext";
5
5
  import { gitEnvironment } from "../git/environment";
6
- import { assert, clean, currentBranch, flag, git, head, mutateGit, nativeBranch, oid, option, output, repository } from "./core";
6
+ import { assert, clean, currentBranch, flag, git, head, mutateGit, mutateGitCaptured, nativeBranch, oid, option, output, repository } from "./core";
7
7
 
8
8
  export function branchErrors(name: string, config: AgentToolConfig): string[] {
9
9
  const errors: string[] = [];
@@ -75,7 +75,7 @@ export function branchCommand(args: string[]): number {
75
75
  assert(baseOid, `Remote base '${base}' does not exist.`);
76
76
  git(["fetch", "--no-tags", remote, `refs/heads/${base}`]);
77
77
  assert(git(["rev-parse", "FETCH_HEAD"]) === baseOid && remoteBranchHead(url, base) === baseOid, "Base moved while fetching; retry creation.");
78
- mutateGit(["switch", "--no-track", "-c", name, oid(baseOid)]);
78
+ mutateGitCaptured(["switch", "--no-track", "-c", name, oid(baseOid)]);
79
79
  assert(currentBranch() === name && head() === baseOid, "Checkout changed during branch creation.");
80
80
  output({ branch: name, headOid: baseOid, baseBranch: base, baseOid, remote }); return 0;
81
81
  }
@@ -12,12 +12,36 @@ export function read(command: string, args: string[], cwd = process.cwd()): stri
12
12
  }
13
13
  export function git(args: string[], cwd = process.cwd()): string { return read("git", args, cwd); }
14
14
  export function json<T>(args: string[]): T { return JSON.parse(read("gh", args)) as T; }
15
- /** Mutating Git commands deliberately retain normal hooks and their environment. */
15
+ /**
16
+ * Mutating Git commands deliberately retain normal hooks and their environment.
17
+ * This one streams Git's and its hooks' output to stderr for commands people
18
+ * watch live, such as a push and its push gate.
19
+ */
16
20
  export function mutateGit(args: string[]): void {
17
21
  const result = spawnSync("git", args, { stdio: ["inherit", 2, 2], env: process.env });
18
22
  if (result.error) throw result.error;
19
23
  assert(result.status === 0, `git ${args[0]} failed (${result.signal ?? result.status}). Inspect checkout state before retrying.`);
20
24
  }
25
+ /**
26
+ * A local Git mutation whose output nobody reads live, with the same hooks and
27
+ * environment as `mutateGit`. Its output and its hooks' are captured rather than
28
+ * inherited: a caller whose stderr pipe lost its reader (`2>&1 | jq` once jq
29
+ * quits) would otherwise kill Git with SIGPIPE part-way through a multi-step
30
+ * mutation. Stdin is closed, since a prompt could not be seen. On failure the
31
+ * error carries Git's exit status or signal and the tail of its stderr.
32
+ */
33
+ export function mutateGitCaptured(args: string[]): void {
34
+ const result = spawnSync("git", args, { stdio: ["ignore", "pipe", "pipe"], env: process.env, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
35
+ if (result.error) throw result.error;
36
+ if (result.status === 0) return;
37
+ const detail = outputTail(result.stderr || result.stdout || "");
38
+ throw new Error(`git ${args[0]} failed (${result.signal ?? result.status})${detail ? `: ${detail}` : "."} Inspect checkout state before retrying.`);
39
+ }
40
+ /** The last lines of a command's output, bounded for an error message. */
41
+ export function outputTail(text: string, lines = 20, characters = 2000): string {
42
+ const tail = text.trim().split("\n").slice(-lines).join("\n");
43
+ return tail.length > characters ? `…${tail.slice(-characters)}` : tail;
44
+ }
21
45
  export function clean(): void { assert(!git(["status", "--porcelain=v1", "--untracked-files=all"]), "Checkout has local changes; preserve them before continuing."); }
22
46
  export function head(): string { return oid(git(["rev-parse", "HEAD"])); }
23
47
  export function currentBranch(): string {
@@ -3,7 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
3
3
  import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, renameSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
4
4
  import path from "node:path";
5
5
  import { loadConfig } from "../config";
6
- import { assert, flag, git, output } from "./core";
6
+ import { assert, flag, git, mutateGitCaptured, output } from "./core";
7
7
 
8
8
  const manifestName = ".agent-tool-hooks.json";
9
9
  interface Manifest { schemaVersion: 1; files: Record<string, { hash: string; executable: boolean }> }
@@ -126,7 +126,7 @@ function install(root: string, common: string, destination: string, sources: Hoo
126
126
  const temporary = path.join(destination, `.agent-tool-manifest-${randomUUID()}`);
127
127
  writeFileSync(temporary, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600, flag: "wx" });
128
128
  renameSync(temporary, manifestFile);
129
- if (configure) assert(spawnSync("git", ["config", "--local", "core.hooksPath", destination], { stdio: "inherit" }).status === 0, "Could not configure installed hooks.");
129
+ if (configure) mutateGitCaptured(["config", "--local", "core.hooksPath", destination]);
130
130
  const after = config(["--type=path", "--get", "core.hooksPath"]);
131
131
  assert(resolveDirectory(after ? path.resolve(root, after) : path.join(common, "hooks")) === destination, "Effective hooksPath does not match installation; inspect Git configuration.");
132
132
  output({ ok: true, applied: true, destination, changes, backups });
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { loadConfig } from "../config";
5
5
  import { remoteBranchHead, resolveFreshBaseRef, resolveRepositoryGitUrl } from "../git/prContext";
6
6
  import { viewCurrentBranchPr } from "../git/currentBranchPr";
7
- import { assert, clean, currentBranch, flag, git, head, mutateGit, oid, output, read, repository } from "./core";
7
+ import { assert, clean, currentBranch, flag, git, head, mutateGitCaptured, oid, output, read, repository } from "./core";
8
8
  import { pullRequest } from "./pr";
9
9
  import { assertStrictBaseFreshness } from "../pr/baseFreshness";
10
10
  import { baseHealthCommand } from "./baseHealth";
@@ -55,15 +55,15 @@ export function repoCommand(args: string[]): number {
55
55
  const localDefault = spawnSync("git", ["rev-parse", "--verify", `refs/heads/${defaultBranch}`], { encoding: "utf8" });
56
56
  if (localDefault.status === 0) {
57
57
  assert(git(["merge-base", localDefault.stdout.trim(), defaultOid]) === localDefault.stdout.trim(), "Local default branch diverged; preserve it for inspection.");
58
- mutateGit(["switch", defaultBranch]);
59
- mutateGit(["merge", "--ff-only", defaultOid]);
60
- } else { assert(localDefault.status === 128, "Could not inspect local default branch."); mutateGit(["switch", "--no-track", "-c", defaultBranch, defaultOid]); }
58
+ mutateGitCaptured(["switch", defaultBranch]);
59
+ mutateGitCaptured(["merge", "--ff-only", defaultOid]);
60
+ } else { assert(localDefault.status === 128, "Could not inspect local default branch."); mutateGitCaptured(["switch", "--no-track", "-c", defaultBranch, defaultOid]); }
61
61
  assert(currentBranch() === defaultBranch && head() === defaultOid, "Checkout changed during default-branch update.");
62
62
  clean(); completed.push("updated-default");
63
63
  if (!keep) {
64
64
  if (feature.status === 0) {
65
65
  assert(git(["rev-parse", `refs/heads/${pr.headRefName}`]) === shipped, "Local feature branch changed before deletion.");
66
- mutateGit(["branch", "-D", "--", pr.headRefName]); completed.push("deleted-local-branch");
66
+ mutateGitCaptured(["branch", "-D", "--", pr.headRefName]); completed.push("deleted-local-branch");
67
67
  }
68
68
  const live = remoteBranchHead(url, pr.headRefName);
69
69
  assert(!live || live === shipped, "Remote feature branch changed before deletion.");