@agentchatham/cli 2.28.0 → 2.30.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/CLAUDE.md CHANGED
@@ -19,10 +19,15 @@ boot paths: up <inv> [agent_id] → bindOrRegister (registration.ts) → bo
19
19
  agentchatham <dir> → ensureIdentity (SDK) → bootAgent
20
20
  cli package: src/cli/index.ts — barrel (parseCliArgs + CliArgs/Command + run* handlers)
21
21
  src/cli/args.ts — arg parsing
22
- src/cli/commands.ts — subcommand handlers (register/list/update/remove/info)
22
+ src/cli/commands.ts — ALL subcommand handlers (register/list/update/remove/info,
23
+ setup-github/github-token/git-credential). One file: a
24
+ handler is `run<Command>`, and nothing else lives here
23
25
  register: src/registration.ts — bindOrRegister: idempotent register-or-bind for `up` (by agent_id)
24
26
  src/identity.ts — findAgentDir: locate an agent dir by its `-<agent_id>` suffix
25
27
  src/bootstrap.ts — runBootstrap stub for `-b` (image scripts; later phase)
28
+ github: src/github/setup.ts — the GitHub integration; see "GitHub integration" below
29
+ host tools: pluginSetup.ts:run() — the ONE child-process runner (git, claude, openclaw).
30
+ Exported for github/setup.ts; do not re-spawn by hand
26
31
  storage: src/agentConfig.ts — per-agent cli.json (read/writeAgentConfig: harness+mode); NO cli dep,
27
32
  so registration.ts reuses it without depending on cli/
28
33
  slash-cmds: src/commands/ — agent in-chat slash-commands (distinct from cli/commands.ts)
@@ -47,6 +52,43 @@ infra: src/lifecycle.ts — shutdown choreography
47
52
  - WS loop: `monitorProvider` owns connect/reconnect. Never call `connectClient` directly.
48
53
  - Identity CRUD: `registerIdentity`, `loadIdentity` from SDK.
49
54
 
55
+ ## GitHub integration
56
+
57
+ Agents never hold a long-lived GitHub credential. Every git operation mints a
58
+ fresh, usually single-repo, ~1h installation token from the backend, which holds
59
+ the org's GitHub App installation (agent_chatham `docs/plans/integrations.md`
60
+ §3.2). Nothing is written to disk, ever.
61
+
62
+ **The mint is the SDK's**, per §7 of that plan. Do not re-implement it here, and
63
+ do not reach for `fetch` in this repo. The SDK exposes two doors and this repo
64
+ uses the unusual one:
65
+
66
+ - `githubTokenFromIdentity(dirName, {repositories})` — what these commands call.
67
+ REST, authenticating from `identity.json`, because the credential helper is a
68
+ fresh process per git operation with no live socket — and must not touch the
69
+ wrapping key / OS keyring for the same reason.
70
+ - `githubToken(client, …)` — the socket path, and what the SDK's `github_token`
71
+ MCP tool calls. That is how a *harness* gets a token for `gh`; the CLI has no
72
+ client in these code paths.
73
+
74
+ What remains here is genuinely CLI and lives in two places: `src/github/setup.ts`
75
+ (the `git config` writes and the managed-boot hook), and `cli/commands.ts` — the
76
+ three handlers plus git's credential protocol, private to the one handler that
77
+ speaks it.
78
+
79
+ Rules:
80
+
81
+ - **The helper's stdout is the wire.** Anything printed there is parsed by git as
82
+ credential data, so failures log to stderr and exit 1 — never stdout.
83
+ - **Silence is a valid answer.** A non-github.com host gets no output at all, so
84
+ git falls through to the user's own helpers. `store`/`erase` are no-ops.
85
+ - **Scope is opt-in.** `setup-github` writes repo-local config by default; only
86
+ a managed VM, which is the agent's own host, gets `--global`.
87
+ - **Boot does not reconfigure.** `maybeSetupGithub` asks git whether the helper
88
+ is already set and returns if it is: `up` runs on every VM start, and the git
89
+ config it writes is host state, not per-run state. Reconfiguring is explicit
90
+ (`agentchatham setup-github --global`).
91
+
50
92
  ## Adding a new provider
51
93
 
52
94
  1. Add name to the `Harness` union in `src/provider.ts` (and `VALID_HARNESSES`)
package/README.md CHANGED
@@ -53,8 +53,35 @@ The process runs in the foreground, streaming logs to stdout/stderr. `Ctrl-C` (o
53
53
  | `agentchatham update <dirName> <key>:<value>…` | Update agent config (e.g. `harness:claude`, `mode:cli`). |
54
54
  | `agentchatham rm <dirName>` | Remove an agent. |
55
55
  | `agentchatham ls` | List all registered agents. |
56
+ | `agentchatham setup-github [<dirName>] [--global]` | Wire git to the org's GitHub integration (see below). Defaults to the current repo. |
57
+ | `agentchatham github-token [<dirName>] [--repo <name>]…` | Mint a short-lived GitHub token and print it. `--repo` narrows it; repeatable. |
58
+ | `agentchatham git-credential [<dirName>] <action>` | Git credential helper. Invoked by git, not by you. |
56
59
  | `agentchatham help` | Print usage. |
57
60
 
61
+ Where `<dirName>` is optional it resolves the same way `agentchatham` with no arguments does: the `AGENT_CHATHAM_AGENT` binding, else the single registered agent.
62
+
63
+ ### GitHub
64
+
65
+ The agent never holds a GitHub credential. `setup-github` points git's credential helper at the CLI, and from then on every `clone`/`fetch`/`push` against `github.com` mints a fresh, single-repo, ~1h installation token for that one operation — nothing is written to disk:
66
+
67
+ ```bash
68
+ # Once per repo (or --global on a machine that is the agent's own):
69
+ agentchatham setup-github
70
+
71
+ git clone https://github.com/acme/widget.git # just works; no PAT, no ssh key
72
+ ```
73
+
74
+ It also sets `user.name` / `user.email` to the agent's identity, so its commits are attributed to the agent.
75
+
76
+ `gh` and raw API calls don't read git credential helpers, so mint explicitly for those:
77
+
78
+ ```bash
79
+ export GH_TOKEN=$(agentchatham github-token)
80
+ gh pr create --fill
81
+ ```
82
+
83
+ Both require an org admin to have connected GitHub on the Integrations page; until then they exit 1 saying so. Managed VMs run `setup-github --global` themselves on first boot.
84
+
58
85
  ### Options (for `up` and `register`)
59
86
 
60
87
  | Flag | Env | Description |