agengo 0.0.0-stage → 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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /node_modules
2
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ ### Fixed
6
+ - **Claude Code could not write files.** Worktrees used to live under `.git/agent-flow/worktrees`, and Claude Code refuses to write to any path containing `.git/`. Worktrees now live in `~/.cache/agengo/worktrees/…`; override with `AGENGO_WORKTREES` or `XDG_CACHE_HOME`.
7
+ - **The Claude Builder was denied permissions in `-p` mode.** The Builder now runs with `--permission-mode acceptEdits --allowedTools Bash`, and the Reviewer with `--allowedTools Bash`.
8
+ - **Worktrees and temporary branches were never removed.** Each step's worktree is removed when the step finishes. On delivery, agengo removes all of the run's worktrees and temporary refs (`af-work/*`, `refs/agent-flow/builds/*`).
9
+ - **`commit` handoff sent unverified builds to the Reviewer.** The task's `setup` and `verify` now run on the Builder's commit before review, as in `worktree` handoff.
10
+
11
+ ### Changed
12
+ - **English is now the project's single source language.** All CLI output (labels, notices, recommendations, errors) is in English, with labels such as `[PROGRESS]`, `[DECISION]`, `[DELIVERED]`, `[INBOX]` and `[METRICS]`. The terms are defined in [docs/glossary.md](docs/glossary.md). The main README and user guide are in English, and the Vietnamese versions moved to [README.vi.md](README.vi.md) and [docs/vi/](docs/vi/huong-dan.md). Notices recorded by older versions keep their original text.
13
+ - `quality.python_duplicates` accepts `off` | `warn` | `block`, and **defaults to `warn`**: duplicates produce a warning in the delivery notice instead of blocking. The old `true`/`false` mean `block`/`off`. In `block` mode the gate runs at every integration, so the Builder of the task that adds a duplicate has to fix it.
14
+ - Function fingerprints normalize parameter and local variable names, so copies with renamed variables are found. Functions that only store attributes (`self.x = x`) are ignored.
15
+ - Agent incidents (crash, timeout, reply that breaks the contract), dependency errors and failed final checks now raise a `decision` request with a `Y-xx` code, instead of an `incident` notice nobody could answer.
16
+ - `status`, `inbox` and notices print the exact `agengo respond …` command. `inbox --json` and `status --json` include `command` / `respond_command`.
17
+ - When `af/<run>` is changed outside agengo, the error message includes the `git update-ref` command that restores it.
18
+
19
+ ### Added
20
+ - **Distribution.** Prebuilt binaries for Linux and macOS (x64 and arm64) on GitHub Releases, an npm package (`npm install -g agengo`, `npx agengo`), a shell installer, and the `agengo` crate on crates.io. Releases are built by [cargo-dist](https://github.com/axodotdev/cargo-dist) when a `v*` tag is pushed.
21
+ - MIT license.
22
+ - **Per-attempt token usage and cost.** For Claude Code, agengo reads `usage`, `total_cost_usd` and `modelUsage`. Custom adapters can report a provider-neutral `usage` object, following [specs/usage.schema.json](specs/usage.schema.json). `status --json` shows each attempt's usage; `metrics` totals it per role, per task and per run. The new `attempt_usage` table is added to existing databases without a migration. Recording costs about 1 ms per attempt.
23
+ - `agengo clean <run>`.
24
+ - Brand assets in [assets/](assets/): logo (light and dark), favicon, workflow diagrams, social preview image and a demo screenshot from a real run.
25
+ - System tests for commit handoff, review findings across rounds, choice B (plan amendment), incident requests, `clean`, `metrics`, token usage, both duplicate gate modes, and one real Claude Code run when `AGENGO_CLAUDE_E2E=1` is set.
26
+ - Typed `Settings` for run configuration, and typed errors `DependencyMissing`, `VerifyFailed` and `DuplicatesFound` instead of matching error text.
27
+ - Full documentation: user guide, glossary, adapter protocol, storage and security limits. GitHub Actions CI on Linux and macOS.
28
+
29
+ ### Upgrading from 0.2.x
30
+ - Existing runs can still be resumed. Worktrees of old runs under `.git/agent-flow/worktrees` are removed when the run is delivered, or by `agengo clean <run>`.
31
+ - Plans that relied on the duplicate gate blocking by default must now set `quality.python_duplicates: block`.
32
+ - Scripts that parsed the Vietnamese CLI output must switch to the English labels, or better, to `status --json` and `inbox --json`.
33
+
34
+ ## 0.2.0
35
+ - First reviewed version.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nguyentan510
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,208 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="assets/logo-dark.svg">
5
+ <img src="assets/logo.svg" alt="agengo" height="96">
6
+ </picture>
7
+
8
+ **Run AI coding agents like Claude Code on your own machine, under control. Each task is built, verified, independently reviewed and integrated in its own Git worktree, and the result is handed over only when every check passes.**
9
+
10
+ [![Rust 1.90+](https://img.shields.io/badge/rust-1.90%2B-orange?logo=rust)](https://www.rust-lang.org)
11
+ [![CI](https://github.com/nguyentan510/agengo/actions/workflows/ci.yml/badge.svg)](https://github.com/nguyentan510/agengo/actions/workflows/ci.yml)
12
+ [![Platform: Linux · macOS](https://img.shields.io/badge/platform-Linux%20%C2%B7%20macOS-blue)](#requirements)
13
+ [![Claude Code](https://img.shields.io/badge/agent-Claude%20Code-d97757)](https://claude.com/claude-code)
14
+ [![Version 0.3.0](https://img.shields.io/badge/version-0.3.0-green)](CHANGELOG.md)
15
+
16
+ [Features](#features) · [How it works](#how-it-works) · [Quick start](#quick-start) · [Docs](docs/README.md) · [FAQ](#faq) · [Tiếng Việt](README.vi.md)
17
+
18
+ </div>
19
+
20
+ ---
21
+
22
+ **agengo** is an open-source command-line tool, written in Rust, for running **AI coding agents** under control. You write a plan made of small tasks. For each task, agengo:
23
+
24
+ 1. dispatches a **Builder** agent,
25
+ 2. runs *your* verification commands,
26
+ 3. has an independent **Reviewer** check the exact commit against the acceptance criteria,
27
+ 4. merges the result into a dedicated Git branch.
28
+
29
+ You end up with a verified `af/<run-id>` branch that is ready to inspect and merge. Your `main` branch is never touched.
30
+
31
+ > Use it when you want Claude Code, or any other coding agent, to work on **several tasks at once** while keeping **clear file scopes, mandatory tests, independent review, and a human in the loop** for the decisions that matter.
32
+
33
+ ## Why agengo?
34
+
35
+ Running an agent directly on your repository is fast but hard to control. It may edit unrelated files, report "done" while tests are still red, or leave your working branch in a mess. agengo adds a verified orchestration layer around the agent:
36
+
37
+ | Running an agent directly | Running it through agengo |
38
+ |---|---|
39
+ | The agent may edit any file | Each task may only change the paths listed in its `owns` scope; anything else is rejected |
40
+ | "Done" means the agent says so | "Done" means your `verify` commands pass in a clean worktree |
41
+ | The agent reviews its own work | A separate Reviewer must attest the exact commit SHA it was given |
42
+ | Work happens on your current branch | Every attempt gets its own worktree; results merge into `af/<run-id>` |
43
+ | An interruption loses track of progress | State lives in SQLite; `resume` continues where it stopped, even after Ctrl‑C |
44
+ | Questions get lost in chat | A decision inbox lists each `Y-xx` request together with the command that answers it |
45
+
46
+ ## Features
47
+
48
+ - 🤖 **Multi-agent workflow:** Builder → verification → Reviewer → integration → final checks. Claude Code works out of the box; any other agent can plug in through a [JSON adapter](#adapter-protocol).
49
+ - 🌳 **Git worktree isolation:** every build, review and integration attempt runs in its own worktree, and worktrees are cleaned up automatically.
50
+ - ⚡ **Safe parallelism:** `--jobs N` runs independent tasks concurrently; tasks with overlapping file scopes are serialized, and `depends` ordering is enforced.
51
+ - ✅ **Mandatory verification:** each task's `verify` commands, `integration_verify` after every merge, and `final_verify` before hand-off.
52
+ - 🔍 **Tracked review findings:** findings (`F-01`, …) are tied to acceptance criteria and followed across fix rounds. An optional whole-branch review is available.
53
+ - 🧑‍⚖️ **Human in the loop:** approve plans before they run, choose between options A and B, amend the plan as a new revision, and pause or resume individual tasks.
54
+ - 🧬 **Quality gates:** tree-sitter–based detection of duplicated Python functions (`off`/`warn`/`block`), plus any lint or test commands you add.
55
+ - 💾 **Crash-safe:** transactional SQLite state, a per-run lock, and timeouts and output limits for agent processes.
56
+ - 📊 **Cost transparency:** `status --json` records every attempt's request, result, duration, tokens and cost; `agengo metrics` totals tokens and cost per role and per task, for Claude Code or any adapter that reports [`usage`](#token-and-cost-usage).
57
+
58
+ ## How it works
59
+
60
+ <picture>
61
+ <source media="(prefers-color-scheme: dark)" srcset="assets/workflow.en-dark.svg">
62
+ <img src="assets/workflow.en.svg" alt="agengo workflow: plan, build, verify, review, integrate, deliver, with a decision inbox for people">
63
+ </picture>
64
+
65
+ Tasks move through `pending → building → ready_review → reviewing → passed → integrated`. When a task gets stuck — the review limit is reached, the agent crashes, or a prerequisite is missing — it becomes `blocked` and agengo asks you through a `Y-xx` request. Independent tasks keep running.
66
+
67
+ ## Requirements
68
+
69
+ - Linux or macOS. Windows is not supported natively; use WSL.
70
+ - Node.js 14.18+ for the npm package, or Rust/Cargo 1.90+ and a C compiler to build from source. Prebuilt binaries need neither.
71
+ - Git 2.31+ with `user.name` and `user.email` configured.
72
+ - Either [Claude Code](https://claude.com/claude-code) on `PATH` and logged in, or your own adapter passed with `--agent <executable>`.
73
+
74
+ ## Installation
75
+
76
+ Prebuilt binaries are available for Linux and macOS (x64 and arm64).
77
+
78
+ ```bash
79
+ npm install -g agengo # or try it without installing: npx agengo --help
80
+ ```
81
+
82
+ ```bash
83
+ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/nguyentan510/agengo/releases/latest/download/agengo-installer.sh | sh
84
+ ```
85
+
86
+ ```bash
87
+ cargo install agengo --locked # builds from source
88
+ ```
89
+
90
+ Binaries and checksums for each version are on the [Releases](https://github.com/nguyentan510/agengo/releases) page.
91
+
92
+ ## Quick start
93
+
94
+ ```yaml
95
+ # plan.yaml
96
+ schema_version: 1
97
+ goal: Add a greeting helper
98
+ tasks:
99
+ - id: greet
100
+ goal: Add greet(name) to src/greet.py returning "Hello, <name>!".
101
+ owns: [src/greet.py, tests/test_greet.py]
102
+ acceptance: ["greet('An') returns 'Hello, An!'"]
103
+ verify: [["python3", "-m", "pytest", "-q", "tests/test_greet.py"]]
104
+ final_verify: [["python3", "-m", "pytest", "-q"]]
105
+ ```
106
+
107
+ ```bash
108
+ agengo plan --file plan.yaml --brief # validate the plan without calling an agent
109
+ agengo run plan.yaml --id demo # build → review → integrate → deliver
110
+ agengo status demo # progress
111
+ agengo inbox demo # pending requests, each with the command that answers it
112
+ git log --oneline main..af/demo # inspect the result before merging
113
+ ```
114
+
115
+ <img src="assets/demo-terminal.png" alt="Real agengo output after a Claude Code run: delivered branch, per-role tokens and cost, and the merge graph" width="100%">
116
+
117
+ No plan yet? Let the agent draft one: `agengo plan --goal "Add a login API" --format yaml > plan.yaml`.
118
+
119
+ Exit codes: `0` delivered · `2` waiting for your answer (then run `resume`) · `1` error · `130` interrupted (run `resume`).
120
+
121
+ ## Plan format
122
+
123
+ A plan is YAML or JSON, validated against [specs/plan.schema.json](specs/plan.schema.json). agengo rejects unknown fields, dependency cycles and paths outside the repository.
124
+
125
+ | Field | Required | Meaning |
126
+ |---|---|---|
127
+ | `goal` | ✔ | Overall goal of the run |
128
+ | `tasks[].id` | ✔ | 1–64 characters from `A-Z a-z 0-9 _ -`, unique |
129
+ | `tasks[].goal` / `title` | goal ✔ | Instructions for the agent / short title for humans |
130
+ | `tasks[].owns` | ✔ | Files or directories the Builder may change. Tasks with overlapping scopes never run in parallel |
131
+ | `tasks[].acceptance` | ✔ | Acceptance criteria, as strings or `{id, text}` |
132
+ | `tasks[].verify` | ✔ | argv commands run on the candidate before review and again at integration |
133
+ | `tasks[].depends` | | Tasks that must be integrated first |
134
+ | `tasks[].setup`, `setup` | | Commands that prepare each worktree, e.g. `[["npm","ci"]]` |
135
+ | `integration_verify` | | Commands run after every merge |
136
+ | `final_verify` | ✔ | Commands run on the final branch before delivery |
137
+ | `quality` | | `python_duplicates: off \| warn \| block`, `ignore_paths`, extra `checks`, `review: true` for a whole-branch review |
138
+
139
+ Commands are argv arrays and never go through a shell. Use `["sh", "-c", "..."]` if you need shell syntax.
140
+
141
+ ## Commands
142
+
143
+ | Command | Purpose |
144
+ |---|---|
145
+ | `plan --file F` / `--goal G` / `--from F` | Validate a plan, or have the agent draft one |
146
+ | `run PLAN [--id ID] [--jobs N] [--base REV]` | Start a run (`--review-limit`, `--gate-limit`, `--timeout`, `--builder-handoff worktree\|commit`, `--agent`, `--await-approval`) |
147
+ | `resume ID` / `resume ID --task T` / `pause ID --task T` | Continue a run, unpause a task, pause a task |
148
+ | `status ID [--json]` · `inbox ID [--json]` · `metrics ID [--json]` | Progress, pending requests, timing, tokens and cost |
149
+ | `respond ID Y-xx --choice A\|B\|approve\|reject --note N [--plan F]` | Answer a request |
150
+ | `resolve ID TASK --note N` · `amend ID PLAN --note N` | Reopen a blocked task · approve a new plan revision |
151
+ | `clean ID` | Remove the run's worktrees (and its temporary refs once delivered) |
152
+
153
+ ## Adapter protocol
154
+
155
+ With `--agent <exe>`, agengo runs the executable once per assignment, inside the assigned worktree:
156
+
157
+ - **Input:** a request JSON on **stdin**, following [specs/request.schema.json](specs/request.schema.json). It includes `role`, `task`, `head`, `base`, `context` with acceptance criteria and open findings, `decisions` and `relationships`.
158
+ - **Output:** one result JSON on **stdout**, following [specs/outcome.schema.json](specs/outcome.schema.json):
159
+
160
+ ```json
161
+ {"status": "done", "head": "<sha>", "summary": "…", "blocker": null,
162
+ "findings": [], "finding_resolutions": [], "resolved_conflicts": []}
163
+ ```
164
+
165
+ ### Token and cost usage
166
+
167
+ An adapter may add an optional top-level `usage` object, following [specs/usage.schema.json](specs/usage.schema.json): `input_tokens` (uncached input), `output_tokens`, `cache_read_tokens`, `cache_write_tokens`, `cost_usd` and `model`. Malformed fields are dropped and never fail an attempt. agengo does not price tokens itself. For Claude Code, usage and `total_cost_usd` are read automatically. Mappings for the Anthropic, OpenAI, Gemini and Ollama APIs are in the [user guide](docs/guide.md#token-and-cost-usage-optional).
168
+
169
+ The Builder returns `done` (commit handoff) or `ready` (worktree handoff). The Reviewer returns `pass` or `changes_requested`. Any role may return `blocked` with a `blocker` (`action`, `decision` or `information`). A non-zero exit, output that is not JSON, or a timeout becomes a `Y-xx` decision. A complete reference adapter lives in [tests/support/mod.rs](tests/support/mod.rs).
170
+
171
+ ## FAQ
172
+
173
+ **Does agengo merge into `main` or push to a remote?**
174
+ No. It only creates and updates the local branch `af/<run-id>` and never pushes. Merging is your decision.
175
+
176
+ **Can I use an agent other than Claude Code?**
177
+ Yes. Any executable that speaks the [JSON adapter protocol](#adapter-protocol) works.
178
+
179
+ **What happens if the agent hangs or crashes?**
180
+ Each attempt has a timeout (`--timeout`, 900 s by default). Failures turn into `Y-xx` requests. Answer with `agengo respond`, then run `agengo resume`.
181
+
182
+ **Where is data stored?**
183
+ State is kept in `.git/agent-flow/state.sqlite3`. Temporary worktrees live under `~/.cache/agengo/worktrees` (override with `AGENGO_WORKTREES`) and are removed after delivery or by `agengo clean <run>`.
184
+
185
+ **Is it a sandbox?**
186
+ No. agengo checks file scope, commit SHAs, the index and branches after every attempt, but agents can run Bash. For untrusted code or agents, run agengo inside a container or VM.
187
+
188
+ **What does it cost?**
189
+ agengo itself is free. You pay for the agent you use, such as Claude Code. Every task needs at least one build attempt and one review attempt, and on small tasks the review can cost nearly as much as the build. `agengo metrics` reports real tokens and cost per role and per task. Recording them adds about 1 ms per attempt and makes no extra API calls.
190
+
191
+ ## Documentation
192
+
193
+ - [User guide](docs/guide.md): full reference.
194
+ - [Glossary](docs/glossary.md): canonical terms and CLI output labels.
195
+ - [Documentation index](docs/README.md).
196
+ - [CHANGELOG](CHANGELOG.md).
197
+ - [specs/](specs/): JSON Schemas and role prompts.
198
+
199
+ ## Development
200
+
201
+ ```bash
202
+ cargo test --locked # unit + system tests with a simulated agent
203
+ AGENGO_CLAUDE_E2E=1 cargo test --locked --test system # plus one real Claude Code run (uses API credits)
204
+ ```
205
+
206
+ ---
207
+
208
+ <sub>Keywords: AI coding agent orchestrator · Claude Code automation · multi-agent software development · git worktree · automated code review · human-in-the-loop · Rust CLI</sub>
@@ -0,0 +1,348 @@
1
+ const {
2
+ createWriteStream,
3
+ existsSync,
4
+ mkdirSync,
5
+ mkdtemp,
6
+ rmSync,
7
+ } = require("fs");
8
+ const { join, sep } = require("path");
9
+ const { spawnSync } = require("child_process");
10
+ const { tmpdir } = require("os");
11
+
12
+ const https = require("node:https");
13
+ const http = require("node:http");
14
+
15
+ const tmpDir = tmpdir();
16
+
17
+ const error = (msg) => {
18
+ console.error(msg);
19
+ process.exit(1);
20
+ };
21
+
22
+ function getProxyForUrl(urlString) {
23
+ const url = new URL(urlString);
24
+ const isHttps = url.protocol === "https:";
25
+
26
+ const noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
27
+ if (noProxy === "*") return null;
28
+ if (noProxy) {
29
+ const hostname = url.hostname.toLowerCase();
30
+ const noProxyList = noProxy.split(",").map((s) => s.trim().toLowerCase());
31
+ for (const entry of noProxyList) {
32
+ if (hostname === entry || hostname.endsWith("." + entry)) {
33
+ return null;
34
+ }
35
+ }
36
+ }
37
+
38
+ const proxyEnv = isHttps
39
+ ? process.env.HTTPS_PROXY || process.env.https_proxy
40
+ : process.env.HTTP_PROXY || process.env.http_proxy;
41
+
42
+ if (!proxyEnv) return null;
43
+
44
+ const proxyUrl = new URL(proxyEnv);
45
+
46
+ let auth = null;
47
+ if (proxyUrl.username || proxyUrl.password) {
48
+ auth = `${proxyUrl.username}:${proxyUrl.password}`;
49
+ }
50
+
51
+ return {
52
+ hostname: proxyUrl.hostname,
53
+ port: proxyUrl.port || (proxyUrl.protocol === "https:" ? 443 : 80),
54
+ auth: auth,
55
+ };
56
+ }
57
+
58
+ function connectThroughProxy(proxy, target) {
59
+ return new Promise((resolve, reject) => {
60
+ const headers = {};
61
+ if (proxy.auth) {
62
+ headers["Proxy-Authorization"] =
63
+ "Basic " + Buffer.from(proxy.auth).toString("base64");
64
+ }
65
+
66
+ const connectReq = http.request({
67
+ hostname: proxy.hostname,
68
+ port: proxy.port,
69
+ method: "CONNECT",
70
+ path: `${target.hostname}:${target.port || 443}`,
71
+ headers,
72
+ });
73
+ connectReq.on("connect", (res, socket) => {
74
+ if (res.statusCode === 200) {
75
+ resolve(socket);
76
+ } else {
77
+ reject(new Error(`Proxy CONNECT failed with status ${res.statusCode}`));
78
+ }
79
+ });
80
+ connectReq.on("error", reject);
81
+ connectReq.end();
82
+ });
83
+ }
84
+
85
+ function download(urlString, maxRedirects) {
86
+ if (maxRedirects === undefined) maxRedirects = 5;
87
+ return new Promise((resolve, reject) => {
88
+ if (maxRedirects < 0) {
89
+ return reject(new Error("Too many redirects"));
90
+ }
91
+
92
+ const parsed = new URL(urlString);
93
+ const isHttps = parsed.protocol === "https:";
94
+ const mod = isHttps ? https : http;
95
+ const proxy = getProxyForUrl(urlString);
96
+
97
+ const doRequest = (extraOptions) => {
98
+ const options = Object.assign(
99
+ {
100
+ hostname: parsed.hostname,
101
+ port: parsed.port || (isHttps ? 443 : 80),
102
+ path: parsed.pathname + parsed.search,
103
+ method: "GET",
104
+ headers: { "User-Agent": "cargo-dist-npm-installer" },
105
+ },
106
+ extraOptions || {},
107
+ );
108
+
109
+ if (proxy && !isHttps) {
110
+ // HTTP through HTTP proxy: request the full URL via the proxy
111
+ options.hostname = proxy.hostname;
112
+ options.port = proxy.port;
113
+ options.path = urlString;
114
+ if (proxy.auth) {
115
+ options.headers["Proxy-Authorization"] =
116
+ "Basic " + Buffer.from(proxy.auth).toString("base64");
117
+ }
118
+ }
119
+
120
+ const req = mod.request(options, (res) => {
121
+ if (
122
+ res.statusCode >= 300 &&
123
+ res.statusCode < 400 &&
124
+ res.headers.location
125
+ ) {
126
+ res.resume();
127
+ const nextUrl = new URL(res.headers.location, urlString).toString();
128
+ return download(nextUrl, maxRedirects - 1).then(resolve, reject);
129
+ }
130
+ if (res.statusCode < 200 || res.statusCode >= 300) {
131
+ res.resume();
132
+ return reject(new Error(`HTTP ${res.statusCode} from ${urlString}`));
133
+ }
134
+ resolve(res);
135
+ });
136
+ req.on("error", reject);
137
+ req.end();
138
+ };
139
+
140
+ if (proxy && isHttps) {
141
+ connectThroughProxy(proxy, parsed).then(
142
+ (socket) => doRequest({ socket, agent: false }),
143
+ reject,
144
+ );
145
+ } else {
146
+ doRequest();
147
+ }
148
+ });
149
+ }
150
+
151
+ class Package {
152
+ constructor(platform, name, url, filename, zipExt, binaries) {
153
+ let errors = [];
154
+ if (typeof url !== "string") {
155
+ errors.push("url must be a string");
156
+ } else {
157
+ try {
158
+ new URL(url);
159
+ } catch (e) {
160
+ errors.push(e);
161
+ }
162
+ }
163
+ if (name && typeof name !== "string") {
164
+ errors.push("package name must be a string");
165
+ }
166
+ if (!name) {
167
+ errors.push("You must specify the name of your package");
168
+ }
169
+ if (binaries && typeof binaries !== "object") {
170
+ errors.push("binaries must be a string => string map");
171
+ }
172
+ if (!binaries) {
173
+ errors.push("You must specify the binaries in the package");
174
+ }
175
+
176
+ if (errors.length > 0) {
177
+ let errorMsg =
178
+ "One or more of the parameters you passed to the Binary constructor are invalid:\n";
179
+ errors.forEach((error) => {
180
+ errorMsg += error;
181
+ });
182
+ errorMsg +=
183
+ '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})';
184
+ error(errorMsg);
185
+ }
186
+
187
+ this.platform = platform;
188
+ this.url = url;
189
+ this.name = name;
190
+ this.filename = filename;
191
+ this.zipExt = zipExt;
192
+ this.installDirectory = join(__dirname, "node_modules", ".bin_real");
193
+ this.binaries = binaries;
194
+
195
+ if (!existsSync(this.installDirectory)) {
196
+ mkdirSync(this.installDirectory, { recursive: true });
197
+ }
198
+ }
199
+
200
+ exists() {
201
+ for (const binaryName in this.binaries) {
202
+ const binRelPath = this.binaries[binaryName];
203
+ const binPath = join(this.installDirectory, binRelPath);
204
+ if (!existsSync(binPath)) {
205
+ return false;
206
+ }
207
+ }
208
+ return true;
209
+ }
210
+
211
+ install(suppressLogs = false) {
212
+ if (this.exists()) {
213
+ if (!suppressLogs) {
214
+ console.error(
215
+ `${this.name} is already installed, skipping installation.`,
216
+ );
217
+ }
218
+ return Promise.resolve();
219
+ }
220
+
221
+ try {
222
+ rmSync(this.installDirectory, { recursive: true, force: true });
223
+ } catch {
224
+ // ignore - directory may not exist
225
+ }
226
+
227
+ mkdirSync(this.installDirectory, { recursive: true });
228
+
229
+ if (!suppressLogs) {
230
+ console.error(`Downloading release from ${this.url}`);
231
+ }
232
+
233
+ return download(this.url)
234
+ .then((res) => {
235
+ return new Promise((resolve, reject) => {
236
+ mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
237
+ if (err) return reject(err);
238
+ let tempFile = join(directory, this.filename);
239
+ const sink = res.pipe(createWriteStream(tempFile));
240
+ sink.on("error", (err) => reject(err));
241
+ sink.on("close", () => {
242
+ if (/\.tar\.*/.test(this.zipExt)) {
243
+ const result = spawnSync("tar", [
244
+ "xf",
245
+ tempFile,
246
+ // The tarballs are stored with a leading directory
247
+ // component; we strip one component in the
248
+ // shell installers too.
249
+ "--strip-components",
250
+ "1",
251
+ "-C",
252
+ this.installDirectory,
253
+ ]);
254
+ if (result.status == 0) {
255
+ resolve();
256
+ } else if (result.error) {
257
+ reject(result.error);
258
+ } else {
259
+ reject(
260
+ new Error(
261
+ `An error occurred untarring the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
262
+ ),
263
+ );
264
+ }
265
+ } else if (this.zipExt == ".zip") {
266
+ let result;
267
+ if (this.platform.artifactName.includes("windows")) {
268
+ // Windows does not have "unzip" by default on many installations, instead
269
+ // we use Expand-Archive from powershell
270
+ result = spawnSync("powershell.exe", [
271
+ "-NoProfile",
272
+ "-NonInteractive",
273
+ "-Command",
274
+ `& {
275
+ param([string]$LiteralPath, [string]$DestinationPath)
276
+ Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force
277
+ }`,
278
+ tempFile,
279
+ this.installDirectory,
280
+ ]);
281
+ } else {
282
+ result = spawnSync("unzip", [
283
+ "-q",
284
+ tempFile,
285
+ "-d",
286
+ this.installDirectory,
287
+ ]);
288
+ }
289
+
290
+ if (result.status == 0) {
291
+ resolve();
292
+ } else if (result.error) {
293
+ reject(result.error);
294
+ } else {
295
+ reject(
296
+ new Error(
297
+ `An error occurred unzipping the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
298
+ ),
299
+ );
300
+ }
301
+ } else {
302
+ reject(
303
+ new Error(`Unrecognized file extension: ${this.zipExt}`),
304
+ );
305
+ }
306
+ });
307
+ });
308
+ });
309
+ })
310
+ .then(() => {
311
+ if (!suppressLogs) {
312
+ console.error(`${this.name} has been installed!`);
313
+ }
314
+ })
315
+ .catch((e) => {
316
+ error(`Error fetching release: ${e.message}`);
317
+ });
318
+ }
319
+
320
+ run(binaryName) {
321
+ const promise = !this.exists() ? this.install(true) : Promise.resolve();
322
+
323
+ promise
324
+ .then(() => {
325
+ const [, , ...args] = process.argv;
326
+
327
+ const options = { cwd: process.cwd(), stdio: "inherit" };
328
+
329
+ const binRelPath = this.binaries[binaryName];
330
+ if (!binRelPath) {
331
+ error(`${binaryName} is not a known binary in ${this.name}`);
332
+ }
333
+ const binPath = join(this.installDirectory, binRelPath);
334
+ const result = spawnSync(binPath, args, options);
335
+
336
+ if (result.error) {
337
+ error(result.error);
338
+ }
339
+
340
+ process.exit(result.status);
341
+ })
342
+ .catch((e) => {
343
+ error(e.message);
344
+ });
345
+ }
346
+ }
347
+
348
+ module.exports.Package = Package;
package/binary.js ADDED
@@ -0,0 +1,124 @@
1
+ const { Package } = require("./binary-install");
2
+ const os = require("os");
3
+ const libc = require("detect-libc");
4
+
5
+ const error = (msg) => {
6
+ console.error(msg);
7
+ process.exit(1);
8
+ };
9
+
10
+ const {
11
+ name,
12
+ artifactDownloadUrls,
13
+ supportedPlatforms,
14
+ glibcMinimum,
15
+ } = require("./package.json");
16
+
17
+ // FIXME: implement NPM installer handling of fallback download URLs
18
+ const artifactDownloadUrl = artifactDownloadUrls[0];
19
+ const builderGlibcMajorVersion = glibcMinimum.major;
20
+ const builderGlibcMinorVersion = glibcMinimum.series;
21
+
22
+ const getPlatform = () => {
23
+ const rawOsType = os.type();
24
+ const rawArchitecture = os.arch();
25
+
26
+ // We want to use rust-style target triples as the canonical key
27
+ // for a platform, so translate the "os" library's concepts into rust ones
28
+ let osType = "";
29
+ switch (rawOsType) {
30
+ case "Windows_NT":
31
+ osType = "pc-windows-msvc";
32
+ break;
33
+ case "Darwin":
34
+ osType = "apple-darwin";
35
+ break;
36
+ case "Linux":
37
+ osType = "unknown-linux-gnu";
38
+ break;
39
+ }
40
+
41
+ let arch = "";
42
+ switch (rawArchitecture) {
43
+ case "x64":
44
+ arch = "x86_64";
45
+ break;
46
+ case "arm64":
47
+ arch = "aarch64";
48
+ break;
49
+ }
50
+
51
+ if (rawOsType === "Linux") {
52
+ if (libc.familySync() == "musl") {
53
+ osType = "unknown-linux-musl-dynamic";
54
+ } else if (libc.isNonGlibcLinuxSync()) {
55
+ console.warn(
56
+ "Your libc is neither glibc nor musl; trying static musl binary instead",
57
+ );
58
+ osType = "unknown-linux-musl-static";
59
+ } else {
60
+ let libcVersion = libc.versionSync();
61
+ let splitLibcVersion = libcVersion.split(".");
62
+ let libcMajorVersion = splitLibcVersion[0];
63
+ let libcMinorVersion = splitLibcVersion[1];
64
+ if (
65
+ libcMajorVersion != builderGlibcMajorVersion ||
66
+ libcMinorVersion < builderGlibcMinorVersion
67
+ ) {
68
+ // We can't run the glibc binaries, but we can run the static musl ones
69
+ // if they exist
70
+ console.warn(
71
+ "Your glibc isn't compatible; trying static musl binary instead",
72
+ );
73
+ osType = "unknown-linux-musl-static";
74
+ }
75
+ }
76
+ }
77
+
78
+ // Assume the above succeeded and build a target triple to look things up with.
79
+ // If any of it failed, this lookup will fail and we'll handle it like normal.
80
+ let targetTriple = `${arch}-${osType}`;
81
+ let platform = supportedPlatforms[targetTriple];
82
+
83
+ if (!platform) {
84
+ error(
85
+ `Platform with type "${rawOsType}" and architecture "${rawArchitecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${Object.keys(
86
+ supportedPlatforms,
87
+ ).join(",")}`,
88
+ );
89
+ }
90
+
91
+ return platform;
92
+ };
93
+
94
+ const getPackage = () => {
95
+ const platform = getPlatform();
96
+ const url = `${artifactDownloadUrl}/${platform.artifactName}`;
97
+ let filename = platform.artifactName;
98
+ let ext = platform.zipExt;
99
+ let binary = new Package(platform, name, url, filename, ext, platform.bins);
100
+
101
+ return binary;
102
+ };
103
+
104
+ const install = (suppressLogs) => {
105
+ if (!artifactDownloadUrl || artifactDownloadUrl.length === 0) {
106
+ console.warn("in demo mode, not installing binaries");
107
+ return;
108
+ }
109
+ const pkg = getPackage();
110
+
111
+ return pkg.install(suppressLogs);
112
+ };
113
+
114
+ const run = (binaryName) => {
115
+ const pkg = getPackage();
116
+
117
+ pkg.run(binaryName);
118
+ };
119
+
120
+ module.exports = {
121
+ install,
122
+ run,
123
+ getPackage,
124
+ };
package/install.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { install } = require("./binary");
4
+ install(false);
@@ -0,0 +1,52 @@
1
+ {
2
+ "lockfileVersion": 3,
3
+ "name": "agengo",
4
+ "packages": {
5
+ "": {
6
+ "bin": {
7
+ "agengo": "run-agengo.js"
8
+ },
9
+ "dependencies": {
10
+ "detect-libc": "^2.1.2"
11
+ },
12
+ "devDependencies": {
13
+ "prettier": "^3.9.10"
14
+ },
15
+ "engines": {
16
+ "node": ">=14.18",
17
+ "npm": ">=6"
18
+ },
19
+ "hasInstallScript": true,
20
+ "license": "MIT",
21
+ "name": "agengo",
22
+ "version": "0.3.0"
23
+ },
24
+ "node_modules/detect-libc": {
25
+ "engines": {
26
+ "node": ">=8"
27
+ },
28
+ "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
29
+ "license": "Apache-2.0",
30
+ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
31
+ "version": "2.1.2"
32
+ },
33
+ "node_modules/prettier": {
34
+ "bin": {
35
+ "prettier": "bin/prettier.cjs"
36
+ },
37
+ "dev": true,
38
+ "engines": {
39
+ "node": ">=14"
40
+ },
41
+ "funding": {
42
+ "url": "https://github.com/prettier/prettier?sponsor=1"
43
+ },
44
+ "integrity": "sha512-skGHTH1Yb9QvaTC4hWnRTzEYtCpApF0UMBPz+t/0ZPzP8ihefo/btKd+QA7pUE0fEwA1SbS/NmhyEcstdXOIdA==",
45
+ "license": "MIT",
46
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.10.tgz",
47
+ "version": "3.9.10"
48
+ }
49
+ },
50
+ "requires": true,
51
+ "version": "0.3.0"
52
+ }
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
+ "artifactDownloadUrls": [
3
+ "https://github.com/nguyentan510/agengo/releases/download/v0.3.0"
4
+ ],
5
+ "bin": {
6
+ "agengo": "run-agengo.js"
7
+ },
8
+ "dependencies": {
9
+ "detect-libc": "^2.1.2"
10
+ },
11
+ "description": "Orchestrate AI coding agents (Claude Code) to build, verify, review and integrate tasks in isolated Git worktrees",
12
+ "devDependencies": {
13
+ "prettier": "^3.9.10"
14
+ },
15
+ "engines": {
16
+ "node": ">=14.18",
17
+ "npm": ">=6"
18
+ },
19
+ "glibcMinimum": {
20
+ "major": 2,
21
+ "series": 35
22
+ },
23
+ "homepage": "https://github.com/nguyentan510/agengo",
24
+ "keywords": [
25
+ "command-line-utilities",
26
+ "development-tools",
27
+ "ai-agent",
28
+ "claude-code",
29
+ "git-worktree",
30
+ "code-review",
31
+ "orchestration"
32
+ ],
33
+ "license": "MIT",
2
34
  "name": "agengo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
35
+ "preferUnplugged": true,
36
+ "repository": "https://github.com/nguyentan510/agengo",
37
+ "scripts": {
38
+ "fmt": "prettier --write **/*.js",
39
+ "fmt:check": "prettier --check **/*.js",
40
+ "postinstall": "node ./install.js"
41
+ },
42
+ "supportedPlatforms": {
43
+ "aarch64-apple-darwin": {
44
+ "artifactName": "agengo-aarch64-apple-darwin.tar.xz",
45
+ "bins": {
46
+ "agengo": "agengo"
47
+ },
48
+ "zipExt": ".tar.xz"
49
+ },
50
+ "aarch64-unknown-linux-gnu": {
51
+ "artifactName": "agengo-aarch64-unknown-linux-gnu.tar.xz",
52
+ "bins": {
53
+ "agengo": "agengo"
54
+ },
55
+ "zipExt": ".tar.xz"
56
+ },
57
+ "x86_64-apple-darwin": {
58
+ "artifactName": "agengo-x86_64-apple-darwin.tar.xz",
59
+ "bins": {
60
+ "agengo": "agengo"
61
+ },
62
+ "zipExt": ".tar.xz"
63
+ },
64
+ "x86_64-unknown-linux-gnu": {
65
+ "artifactName": "agengo-x86_64-unknown-linux-gnu.tar.xz",
66
+ "bins": {
67
+ "agengo": "agengo"
68
+ },
69
+ "zipExt": ".tar.xz"
70
+ }
71
+ },
72
+ "version": "0.3.0",
73
+ "volta": {
74
+ "node": "18.14.1",
75
+ "npm": "9.5.0"
76
+ }
6
77
  }
package/run-agengo.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { run } = require("./binary");
4
+ run("agengo");