@juanbenjumea/pi-agy 0.5.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.
@@ -0,0 +1,131 @@
1
+ import { execFile } from "node:child_process";
2
+ import { access, readFile } from "node:fs/promises";
3
+ import * as path from "node:path";
4
+ import { promisify } from "node:util";
5
+
6
+ const execFileAsync = promisify(execFile);
7
+
8
+ interface PackageJson {
9
+ packageManager?: unknown;
10
+ scripts?: Record<string, unknown>;
11
+ }
12
+
13
+ export interface VerifyDetectionDeps {
14
+ /** Test hook — override the `just` binary availability probe. */
15
+ justAvailable?: () => Promise<boolean>;
16
+ }
17
+
18
+ /**
19
+ * Detect a local verification command for accept-edits verify-loop injection.
20
+ * The upward walk stops at the repository boundary (a directory containing
21
+ * `.git`) so a parent checkout or stray `$HOME` justfile cannot leak an
22
+ * unrelated command into a nested repo or worktree.
23
+ */
24
+ export async function detectVerifyCommand(
25
+ cwd: string,
26
+ deps: VerifyDetectionDeps = {},
27
+ ): Promise<string | null> {
28
+ let current = path.resolve(cwd);
29
+ while (true) {
30
+ const command = await detectVerifyCommandAt(current, deps);
31
+ if (command) return command;
32
+
33
+ if (await fileExists(path.join(current, ".git"))) return null;
34
+
35
+ const parent = path.dirname(current);
36
+ if (parent === current) return null;
37
+ current = parent;
38
+ }
39
+ }
40
+
41
+ async function detectVerifyCommandAt(
42
+ cwd: string,
43
+ deps: VerifyDetectionDeps,
44
+ ): Promise<string | null> {
45
+ if ((await hasJustCi(cwd)) && (await (deps.justAvailable?.() ?? justBinaryAvailable()))) {
46
+ return "just ci";
47
+ }
48
+
49
+ try {
50
+ const pkg = JSON.parse(await readFile(path.join(cwd, "package.json"), "utf8")) as PackageJson;
51
+ const scripts = pkg.scripts ?? {};
52
+ const runner = await detectPackageRunner(cwd, pkg.packageManager);
53
+ if (typeof scripts.ci === "string" && scripts.ci.trim()) return runScript(runner, "ci");
54
+ if (typeof scripts.test === "string" && scripts.test.trim()) return runScript(runner, "test");
55
+ } catch {
56
+ // no package.json or unreadable package metadata
57
+ }
58
+
59
+ return detectUvCommand(cwd);
60
+ }
61
+
62
+ async function hasJustCi(cwd: string): Promise<boolean> {
63
+ for (const filename of ["justfile", "Justfile", ".justfile"]) {
64
+ try {
65
+ const justfile = await readFile(path.join(cwd, filename), "utf8");
66
+ if (justfile.split("\n").some((line) => /^(?:alias\s+)?ci\s*(?::|:=)/.test(line))) {
67
+ return true;
68
+ }
69
+ } catch {
70
+ // try the next Justfile spelling
71
+ }
72
+ }
73
+ return false;
74
+ }
75
+
76
+ let justBinaryProbe: Promise<boolean> | undefined;
77
+
78
+ async function justBinaryAvailable(): Promise<boolean> {
79
+ justBinaryProbe ??= (async () => {
80
+ try {
81
+ await execFileAsync("just", ["--version"], { timeout: 5_000 });
82
+ return true;
83
+ } catch {
84
+ return false;
85
+ }
86
+ })();
87
+ return justBinaryProbe;
88
+ }
89
+
90
+ /** Python projects: `uv run pytest` when pyproject uses uv and references pytest. */
91
+ async function detectUvCommand(cwd: string): Promise<string | null> {
92
+ let pyproject: string;
93
+ try {
94
+ pyproject = await readFile(path.join(cwd, "pyproject.toml"), "utf8");
95
+ } catch {
96
+ return null;
97
+ }
98
+ const hasUv = (await fileExists(path.join(cwd, "uv.lock"))) || pyproject.includes("[tool.uv]");
99
+ const hasPytest = pyproject.includes("pytest");
100
+ return hasUv && hasPytest ? "uv run pytest" : null;
101
+ }
102
+
103
+ async function detectPackageRunner(cwd: string, declared: unknown): Promise<string> {
104
+ if (typeof declared === "string") {
105
+ const runner = declared.split("@", 1)[0];
106
+ if (["npm", "pnpm", "yarn", "bun"].includes(runner)) return runner;
107
+ }
108
+
109
+ for (const [filename, runner] of [
110
+ ["pnpm-lock.yaml", "pnpm"],
111
+ ["yarn.lock", "yarn"],
112
+ ["bun.lock", "bun"],
113
+ ["bun.lockb", "bun"],
114
+ ] as const) {
115
+ if (await fileExists(path.join(cwd, filename))) return runner;
116
+ }
117
+ return "npm";
118
+ }
119
+
120
+ async function fileExists(filename: string): Promise<boolean> {
121
+ try {
122
+ await access(filename);
123
+ return true;
124
+ } catch {
125
+ return false;
126
+ }
127
+ }
128
+
129
+ function runScript(runner: string, script: string): string {
130
+ return runner === "npm" && script === "test" ? "npm test" : `${runner} run ${script}`;
131
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@juanbenjumea/pi-agy",
3
+ "version": "0.5.0",
4
+ "description": "Enhanced Antigravity CLI (agy) bridge for Pi — streaming progress, conversation continuity, repo-aware verify, and diff summaries.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Juan Benjumea",
8
+ "keywords": [
9
+ "pi-package",
10
+ "pi-extension",
11
+ "pi-skill",
12
+ "agy",
13
+ "antigravity",
14
+ "gemini",
15
+ "google-ai",
16
+ "cli"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/huaxel/pi-agy"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/huaxel/pi-agy/issues"
24
+ },
25
+ "homepage": "https://github.com/huaxel/pi-agy#readme",
26
+ "scripts": {
27
+ "test": "node --import ./tests/resolve-hook.mjs --test tests/*.test.ts",
28
+ "typecheck": "tsc --noEmit --pretty false",
29
+ "pack:check": "npm pack --dry-run --json"
30
+ },
31
+ "files": [
32
+ "LICENSE",
33
+ "README.md",
34
+ "CHANGELOG.md",
35
+ "extensions/",
36
+ "skills/"
37
+ ],
38
+ "pi": {
39
+ "extensions": [
40
+ "./extensions/index.ts"
41
+ ],
42
+ "skills": [
43
+ "./skills"
44
+ ]
45
+ },
46
+ "peerDependencies": {
47
+ "@earendil-works/pi-coding-agent": "*",
48
+ "@sinclair/typebox": "*"
49
+ },
50
+ "devDependencies": {
51
+ "@sinclair/typebox": "^0.34.41",
52
+ "@types/node": "^22.0.0",
53
+ "typescript": "^5.0.0"
54
+ },
55
+ "engines": {
56
+ "node": ">=20.0.0"
57
+ }
58
+ }
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: agy-delegate
3
+ description: >
4
+ Delegate bulk implementation, scaffolding, repetitive refactors, and
5
+ exhaustive test generation to the Antigravity CLI (agy).
6
+ argument-hint: "prompt=\"...\" [model=flash-low|flash-medium|flash-high|pro-low|pro-high|sonnet|opus|gpt-oss] [mode=plan|accept-edits|sandbox]"
7
+ license: MIT
8
+ ---
9
+
10
+ # agy-delegate
11
+
12
+ Use the `agy_execute` tool to offload large scaffolding, repetitive refactors,
13
+ or exhaustive test generation via the Antigravity CLI.
14
+
15
+ ## Prerequisites
16
+
17
+ 1. Install the Antigravity CLI (a Go binary, not pipx):
18
+
19
+ ```bash
20
+ curl -fsSL https://antigravity.google/cli/install.sh | bash
21
+ ```
22
+
23
+ 2. Authenticate in a terminal (one-time):
24
+
25
+ ```bash
26
+ agy
27
+ ```
28
+
29
+ 3. Verify the CLI works:
30
+
31
+ ```bash
32
+ agy --version
33
+ agy models
34
+ ```
35
+
36
+ ## Tool usage
37
+
38
+ ```
39
+ agy_execute prompt="Refactor all snake_case variables to camelCase in src/models/"
40
+ agy_execute prompt="Generate exhaustive unit tests for src/auth/" model=flash-low
41
+ agy_execute prompt="Plan the migration to ESM" model=sonnet mode=plan digest=true
42
+ agy_execute prompt="Implement the approved plan" conversation_id=<id> mode=accept-edits
43
+ agy_execute prompt="Adversarial review the diff" model=opus effort=high mode=plan
44
+ ```
45
+
46
+ ## Modes
47
+
48
+ | Mode | Purpose |
49
+ |------|---------|
50
+ | `plan` | Exploration and planning — no edits |
51
+ | `accept-edits` (default) | Implementation — agy applies edits directly |
52
+ | `sandbox` | Preview changes without applying |
53
+
54
+ ## Rules
55
+
56
+ - **Default to `mode=plan`** for exploration; escalate to `accept-edits` only for scoped batches.
57
+ - **Always review the `git diff`** after agy runs with `accept-edits`.
58
+ - **Run `just ci`** (or the project gate) after write modes in this repo.
59
+ - **Never use agy for irreversible production changes.**
60
+ - Reuse `conversation_id` or `continue=true` for multi-step plan → implement → review.
61
+ - Use `flash-medium` by default, `flash-low` for trivial/high-volume work, and `flash-high` for difficult agentic work.
62
+ - Escalate within the Gemini quota group to `pro-low` or `pro-high` only when needed.
63
+ - Use `sonnet` for normal Claude-group coding/review; reserve `opus` for the hardest architecture or root-cause work.
64
+ - Use `gpt-oss` when an open-model alternative is specifically desired.
65
+ - Set `effort` (low/medium/high) for finer reasoning control on `sonnet`/`opus`/`gpt-oss` runs; Gemini aliases encode effort in the model id.
66
+ - For consequential work, have one family produce and the opposite family review with `mode=plan`; do not spend both groups on trivial tasks.
67
+ - Batch related work, avoid parallel calls within one shared-quota group or directory, and use `digest=true` (default) for non-write tasks.
68
+
69
+ ## Enhancements over upstream pi-agy
70
+
71
+ - **Streaming progress** — live tool steps via `stream-json` and Pi `onUpdate`.
72
+ - **Conversation continuity** — `conversation_id`, `continue`, session store under `$PI_CODING_AGENT_DIR/agy-sessions.json` (or `~/.pi/agent/agy-sessions.json` by default).
73
+ - **Repo-aware verify** — prefers `just ci` when a justfile defines `ci:`.
74
+ - **Diff summary** — accept-edits results append newly-dirty files only; pre-existing dirt is listed separately, never misattributed.
75
+ - **Per-directory lock** — serializes concurrent agy calls on the same tree across Pi processes (symlink-aware).
76
+ - **Cancellation** — abort/timeout kills the full agy process tree, and streamed records plus responses are size-bounded.