@discovery-tree/runner 0.0.0-stage → 0.1.1
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/README.md +263 -2
- package/dist/cli.js +2639 -0
- package/package.json +27 -4
package/README.md
CHANGED
|
@@ -1,3 +1,264 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dt-runner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`dt-runner` lets Discovery Tree run agent sessions on **your own computer** with the
|
|
4
|
+
**Claude Code CLI you already have installed and signed in**. The work happens in git worktrees
|
|
5
|
+
of your own clones, the branch is pushed with your own git credentials, and the conversation
|
|
6
|
+
shows up in Discovery Tree like any other agent run: transcript, messages, interrupt and pull
|
|
7
|
+
request included.
|
|
8
|
+
|
|
9
|
+
## Your Claude subscription, your credentials
|
|
10
|
+
|
|
11
|
+
- The runner drives the official `claude` CLI as a subprocess. Claude Code uses whatever sign-in
|
|
12
|
+
you set up for it (for example your Claude Pro/Max subscription), so the runs use your
|
|
13
|
+
subscription's usage.
|
|
14
|
+
- **Discovery Tree never sees your Claude credentials.** The runner never reads Claude's
|
|
15
|
+
credential files and never sends them anywhere. It checks whether Claude Code is signed in
|
|
16
|
+
only by asking `claude auth status`.
|
|
17
|
+
- **Do not set `ANTHROPIC_API_KEY`** in the runner's environment unless you mean to: Claude Code
|
|
18
|
+
then bills that API key instead of your subscription. `dt-runner doctor` and `dt-runner start`
|
|
19
|
+
warn when it is set.
|
|
20
|
+
- Discovery Tree hands the runner no GitHub token either. Clones, fetches and pushes use your
|
|
21
|
+
normal git setup (credential helper, SSH agent, `gh auth setup-git`, …).
|
|
22
|
+
|
|
23
|
+
## Install and run
|
|
24
|
+
|
|
25
|
+
You need Node.js 22 or newer, git, and [Claude Code](https://docs.claude.com/en/docs/claude-code)
|
|
26
|
+
signed in (run `claude` once and sign in).
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx @discovery-tree/runner login # pair this computer with your Discovery Tree account
|
|
30
|
+
npx @discovery-tree/runner doctor # check node, git and Claude Code
|
|
31
|
+
npx @discovery-tree/runner start # wait for sessions and run them (Ctrl+C to stop)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or install it once: `npm install -g @discovery-tree/runner`, then `dt-runner login` and
|
|
35
|
+
`dt-runner start`.
|
|
36
|
+
|
|
37
|
+
`login` prints a short code and opens the approval page in your browser (use `--no-browser` on
|
|
38
|
+
a headless machine and open the printed link yourself). The page does not carry the code: type
|
|
39
|
+
the code shown in your terminal while signed in to Discovery Tree, and only ever approve a code
|
|
40
|
+
you see on your own screen. Once it is approved the runner prints the account it was paired
|
|
41
|
+
with and asks **"Is this your Discovery Tree account?"**; the runner token is saved only if you
|
|
42
|
+
answer yes. If you answer no, nothing is saved; remove the runner in Discovery Tree under
|
|
43
|
+
**Account settings → Local runners**. `--yes` skips the question (for scripts). Without a
|
|
44
|
+
terminal to ask (stdin is not a TTY) the token is saved and the account is printed in a
|
|
45
|
+
banner. Check it.
|
|
46
|
+
|
|
47
|
+
| Command | What it does |
|
|
48
|
+
| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
49
|
+
| `dt-runner login [--server <url>] [--name <name>] [--yes]` | Pair with Discovery Tree (device code), then confirm the account. |
|
|
50
|
+
| `dt-runner start [--max-sessions N] [--repos-dir <dir>] [--json] [--verbose]` | Run the daemon (one per configuration; a second `start` refuses to run). |
|
|
51
|
+
| `dt-runner status` | Show the configuration and check the server (see below). |
|
|
52
|
+
| `dt-runner doctor` | Check Node.js, git, Claude Code and its sign-in; warn about `ANTHROPIC_API_KEY`. |
|
|
53
|
+
| `dt-runner logout` | Delete the saved config (and token). Remove the runner in Discovery Tree to revoke it. |
|
|
54
|
+
|
|
55
|
+
The runner only makes outbound HTTPS requests to the Discovery Tree server: a heartbeat every
|
|
56
|
+
15 seconds, a long poll for commands, and posts of session events. Nothing listens on a port.
|
|
57
|
+
If the server limits the command polls (HTTP 429) the runner waits a few seconds, with jitter,
|
|
58
|
+
and polls again; if it refuses a batch of session events as too large (HTTP 413) the runner
|
|
59
|
+
logs it, drops that batch and carries on.
|
|
60
|
+
|
|
61
|
+
Only one `dt-runner start` runs per configuration: it holds a lock file (`daemon.pid` in the
|
|
62
|
+
state folder). Two daemons sharing one runner token would each report only their own sessions,
|
|
63
|
+
and the server would fail the other one's as lost. A lock left by a runner that is no longer
|
|
64
|
+
running is taken over. `dt-runner status` sends one heartbeat (listing the sessions saved on
|
|
65
|
+
disk) to check the token, but only when no daemon is running; while one is, it leaves the
|
|
66
|
+
reporting to the daemon.
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
The config file is `$XDG_CONFIG_HOME/discovery-tree/runner.json` (usually
|
|
71
|
+
`~/.config/discovery-tree/runner.json`; `%APPDATA%\discovery-tree\runner.json` on Windows),
|
|
72
|
+
readable only by you (mode 0600) because it holds the runner token. `login` writes `server`,
|
|
73
|
+
`runnerId`, `token` and `name`; add any of these to change the defaults:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"maxSessions": 2,
|
|
78
|
+
"reposDir": "/path/to/clone/cache",
|
|
79
|
+
"worktreesDir": "/path/to/worktrees",
|
|
80
|
+
"permissionMode": "acceptEdits",
|
|
81
|
+
"extraAllowedTools": ["Bash(docker compose *)"],
|
|
82
|
+
"extraDisallowedTools": ["Read(~/work/secrets/**)"],
|
|
83
|
+
"gitProtocol": "https",
|
|
84
|
+
"idleTimeoutMinutes": 15
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
| Option | Default | Meaning |
|
|
89
|
+
| ---------------------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
90
|
+
| `maxSessions` | `2` | Sessions with a running Claude Code at once (1 to 64). Further starts are refused as busy and retried by the server. `--max-sessions` overrides it. |
|
|
91
|
+
| `reposDir` | `$XDG_DATA_HOME/discovery-tree/runner/repos` | Clone cache. `--repos-dir` overrides it. |
|
|
92
|
+
| `worktreesDir` | `$XDG_DATA_HOME/discovery-tree/runner/worktrees` | One worktree per session. |
|
|
93
|
+
| `permissionMode` | `acceptEdits` | Claude Code `--permission-mode`. See below. |
|
|
94
|
+
| `allowedTools` | a development allow-list | Replaces the default `--allowedTools` list. |
|
|
95
|
+
| `extraAllowedTools` | `[]` | Added to the allow-list. |
|
|
96
|
+
| `disallowedTools` | credential locations (see below) | Replaces the default `--disallowedTools` deny list. Deny rules win over the allow-list. |
|
|
97
|
+
| `extraDisallowedTools` | `[]` | Added to the deny list. |
|
|
98
|
+
| `loadProjectSettings` | `false` | `true` lets Claude Code load the repository's own `.claude/settings.json` / `settings.local.json` (hooks, permissions). See below. |
|
|
99
|
+
| `gitProtocol` | `https` | `ssh` clones `git@github.com:owner/repo.git` instead. The cached clone's `origin` URL is rewritten to match on every session start (see below). |
|
|
100
|
+
| `idleTimeoutMinutes` | `15` | An idle Claude Code process is ended after this long; the next message resumes it. |
|
|
101
|
+
|
|
102
|
+
Environment variables: `DT_SERVER_URL` (server), `DT_RUNNER_TOKEN` (token; overrides the file),
|
|
103
|
+
`DT_RUNNER_CLAUDE_BIN` (the `claude` binary to run).
|
|
104
|
+
|
|
105
|
+
### Permissions and safety
|
|
106
|
+
|
|
107
|
+
**With the default settings, the agent can run arbitrary code on your computer as you.** The
|
|
108
|
+
runner runs an AI agent with your user's access. Nobody is at the keyboard to answer Claude
|
|
109
|
+
Code's permission prompts, so anything that would prompt is denied and the agent reports that it
|
|
110
|
+
could not do it. What it may do without asking:
|
|
111
|
+
|
|
112
|
+
- **`permissionMode: "acceptEdits"`** (default): file edits inside the worktree are allowed.
|
|
113
|
+
- **The allow-list** (`DEFAULT_ALLOWED_TOOLS` in `src/config.ts`): the file tools (`Read`,
|
|
114
|
+
`Edit`, `Write`, `Glob`, `Grep`, …) and the commands an agent needs to build and test a
|
|
115
|
+
change, in Claude Code's `Bash(<prefix> *)` syntax: `git status/diff/log/add/commit …`,
|
|
116
|
+
`npm`, `npx`, `pnpm`, `yarn`, `node`, `tsc`, `python`, `pip`, `pytest`, `make`, `cargo`, `go`,
|
|
117
|
+
`ls`, `cat`, `grep`, … **`npm`, `npx`, `pnpm`, `yarn`, `node`, `python`, `pip`, `make`,
|
|
118
|
+
`cargo` and `go` run code**, from the repository (package scripts, build files, tests) or
|
|
119
|
+
written by the agent, so this list amounts to arbitrary code execution as you. It keeps the
|
|
120
|
+
agent from stalling on every command; it is not a sandbox.
|
|
121
|
+
Left off on purpose: `WebFetch` and `WebSearch` (the easiest way for a manipulated agent to
|
|
122
|
+
send data out), `find` (`-exec`), `sed`, `cp`, `mv` (they can write anywhere; the Edit and
|
|
123
|
+
Write tools cover changes in the worktree) and `git push` (the runner pushes).
|
|
124
|
+
- **The deny list** (`--disallowedTools`, which wins over the allow-list): the agent's file
|
|
125
|
+
tools may not read or edit `~/.ssh`, `~/.aws`, `~/.config/gcloud`, `~/.azure`, `~/.gnupg`,
|
|
126
|
+
`~/.netrc`, `~/.git-credentials`, `~/.config/gh`, `~/.docker/config.json`, `~/.kube`,
|
|
127
|
+
`~/.npmrc`, `~/.pypirc`, the runner's own config (its token), and Claude Code's credentials
|
|
128
|
+
(`~/.claude/.credentials.json`, `~/.claude.json`); nothing under `~/.claude` may be edited.
|
|
129
|
+
Claude Code applies these `Read` rules to the shell commands it knows read files (`cat`,
|
|
130
|
+
`head`, …) too. This closes the obvious paths only: code run through the allow-list
|
|
131
|
+
(`node -e …`, a package script) can still read anything you can.
|
|
132
|
+
- **Repository settings are not loaded.** The runner starts Claude Code with
|
|
133
|
+
`--setting-sources user`, so a cloned repository's `.claude/settings.json` and
|
|
134
|
+
`.claude/settings.local.json` (hooks that run shell commands, permission rules, environment
|
|
135
|
+
variables) are ignored; your own `~/.claude/settings.json` still applies. The repository's
|
|
136
|
+
`CLAUDE.md` files **are** still read (`--setting-sources` does not control them) and go into
|
|
137
|
+
the agent's context. Set `"loadProjectSettings": true` to load the repository's settings too,
|
|
138
|
+
only for repositories you trust.
|
|
139
|
+
- **`permissionMode: "bypassPermissions"`** lets Claude Code run **anything** without asking.
|
|
140
|
+
Only use it on a disposable machine or container; the runner prints a loud warning at start.
|
|
141
|
+
|
|
142
|
+
**Where instructions to the agent come from (prompt injection).** Anything the agent reads can
|
|
143
|
+
try to steer it:
|
|
144
|
+
|
|
145
|
+
- **The task text.** Anyone who can edit the tree can edit a task before you start a run on it.
|
|
146
|
+
(Once a run is going, only you, its owner, can send it messages.) Read the task before you
|
|
147
|
+
start the run.
|
|
148
|
+
- **The repository.** Its `CLAUDE.md` files (loaded automatically), code, comments, issues
|
|
149
|
+
quoted in files, test fixtures; and, if you set `loadProjectSettings`, its `.claude/`
|
|
150
|
+
settings and hooks.
|
|
151
|
+
- **The web**, if you add `WebFetch` or `WebSearch` to the allow-list.
|
|
152
|
+
|
|
153
|
+
For repositories or task authors you do not fully trust, **run the runner in a container or a
|
|
154
|
+
VM, or as a separate OS user** that has none of your credentials beyond what it needs to push
|
|
155
|
+
(for example a fine-grained GitHub token for those repositories). Then "arbitrary code as the
|
|
156
|
+
runner's user" is a small blast radius.
|
|
157
|
+
|
|
158
|
+
Customise in the config file: `allowedTools` / `disallowedTools` replace the defaults,
|
|
159
|
+
`extraAllowedTools` / `extraDisallowedTools` add to them. Rules use Claude Code's permission
|
|
160
|
+
syntax: `Bash(docker compose *)` (a command prefix), `Read(~/path/**)` (relative to your home
|
|
161
|
+
directory), `Read(//abs/path/**)` (an absolute path). `Edit(path)` rules cover all of the
|
|
162
|
+
editing tools; Claude Code ignores `Write(path)` rules.
|
|
163
|
+
|
|
164
|
+
The runner only clones from `https://github.com/<owner>/<repo>`: Discovery Tree cannot point it
|
|
165
|
+
at another host. It passes Claude Code only a model name that looks like one (`sonnet`,
|
|
166
|
+
`opus[1m]`, `claude-opus-5-5`, …) and refuses the session otherwise.
|
|
167
|
+
|
|
168
|
+
## Repositories, worktrees and branches
|
|
169
|
+
|
|
170
|
+
For a session on `https://github.com/owner/repo`:
|
|
171
|
+
|
|
172
|
+
1. The runner keeps a clone at `<reposDir>/owner/repo` (`git clone --no-checkout` the first time,
|
|
173
|
+
`git fetch --prune origin` afterwards). Nothing is ever edited in it.
|
|
174
|
+
2. It creates `<worktreesDir>/<sessionId>` with `git worktree add -B <workBranch> … origin/<base>`
|
|
175
|
+
(the repository's default branch unless the run names one).
|
|
176
|
+
On every session start the cached clone's `origin` URL is set to the `gitProtocol` form
|
|
177
|
+
(`https://github.com/owner/repo.git` or `git@github.com:owner/repo.git`), so an `origin`
|
|
178
|
+
you changed by hand in the cache is changed back. To reach GitHub through a host alias, a
|
|
179
|
+
proxy or a mirror, use git's own rewriting instead (`git config --global
|
|
180
|
+
url."git@my-alias:".insteadOf "git@github.com:"`), which git applies after the runner sets
|
|
181
|
+
the URL.
|
|
182
|
+
3. Claude Code runs in that worktree. It is told to commit its work on that branch and not to push
|
|
183
|
+
or switch branches.
|
|
184
|
+
4. At the end of every turn the runner commits anything left uncommitted
|
|
185
|
+
(`git add -A && git commit`, only if the worktree is dirty) and runs
|
|
186
|
+
`git push -u origin HEAD:<workBranch>` when the branch has commits on top of its base. Discovery
|
|
187
|
+
Tree opens the pull request from that branch.
|
|
188
|
+
5. When Discovery Tree closes the session, the worktree is removed (`git worktree remove --force`).
|
|
189
|
+
The branch stays, locally and on the remote.
|
|
190
|
+
|
|
191
|
+
A session without a repository runs in an empty scratch directory.
|
|
192
|
+
|
|
193
|
+
State lives under `$XDG_STATE_HOME/discovery-tree/runner` (usually `~/.local/state/…`): one folder
|
|
194
|
+
per session with its record (worktree, branch, Claude Code session id) and an outbox of events not
|
|
195
|
+
yet delivered. If the runner stops — Ctrl+C, a reboot, a crash — `dt-runner start` picks the
|
|
196
|
+
sessions up again: undelivered events are sent, a turn that was cut short is reported as ended,
|
|
197
|
+
and the next message resumes the same Claude Code conversation (`claude --resume`) in the same
|
|
198
|
+
worktree.
|
|
199
|
+
|
|
200
|
+
## Troubleshooting
|
|
201
|
+
|
|
202
|
+
- **`dt-runner doctor` says Claude Code is not signed in** — run `claude` in a terminal and sign in,
|
|
203
|
+
then try again.
|
|
204
|
+
- **Turns fail with "Claude Code exited …"** — run `dt-runner start --verbose`. Check that
|
|
205
|
+
`claude -p "say ok"` works in a terminal as the same user.
|
|
206
|
+
- **Pushing the work branch failed** — the turn fails with the git error and says where the work
|
|
207
|
+
is kept (the local branch in the runner's clone, which closing the session does not delete).
|
|
208
|
+
Check that `git push` works for that repository from a terminal (credentials, SSH key, branch protection).
|
|
209
|
+
The runner disables interactive git prompts, so a credential helper must be able to answer
|
|
210
|
+
without asking. With an SSH-only setup, set `"gitProtocol": "ssh"`.
|
|
211
|
+
- **"Discovery Tree refused this runner's token"** — the runner was removed or its token revoked.
|
|
212
|
+
Run `dt-runner login` again.
|
|
213
|
+
- **"Discovery Tree needs a newer dt-runner"** — run `npx @discovery-tree/runner@latest start`.
|
|
214
|
+
- **The runner is busy** — it is already running `maxSessions` sessions; the server retries later.
|
|
215
|
+
Raise `maxSessions` if your machine can take more.
|
|
216
|
+
- **Start over** — `dt-runner logout`, delete the state and data folders shown by
|
|
217
|
+
`dt-runner status`, then `dt-runner login`.
|
|
218
|
+
|
|
219
|
+
## Development
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pnpm --filter @discovery-tree/runner test # vitest: mapper fixtures, fake-claude integration, fake server
|
|
223
|
+
pnpm --filter @discovery-tree/runner lint
|
|
224
|
+
pnpm --filter @discovery-tree/runner typecheck
|
|
225
|
+
pnpm --filter @discovery-tree/runner build # → dist/cli.js (single file, no runtime dependencies)
|
|
226
|
+
node packages/runner/dist/cli.js --help
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
The protocol is defined in `packages/contracts/src/agent-runner.ts`. `test/fixtures` holds real
|
|
230
|
+
Claude Code 2.1.296 `stream-json` output; `test/fake-claude.mjs` is a scripted stand-in for the CLI
|
|
231
|
+
used by the integration tests.
|
|
232
|
+
|
|
233
|
+
## Releasing
|
|
234
|
+
|
|
235
|
+
`@discovery-tree/runner` is published to npm by the **Publish dt-runner** GitHub Actions
|
|
236
|
+
workflow (`.github/workflows/publish-runner.yml`), never from a laptop.
|
|
237
|
+
|
|
238
|
+
1. Bump `version` in `packages/runner/package.json` in a pull request and merge it to `main`.
|
|
239
|
+
2. Actions → **Publish dt-runner** → **Run workflow** on `main`. It refuses a version that is
|
|
240
|
+
already on npm, runs lint, typecheck, tests and the build, then publishes publicly.
|
|
241
|
+
|
|
242
|
+
The workflow runs in the `npm-publish` environment; add required reviewers there to gate
|
|
243
|
+
releases.
|
|
244
|
+
|
|
245
|
+
**First publish (one time).** npm can only link a trusted publisher to a package that exists,
|
|
246
|
+
so the first release uses a token:
|
|
247
|
+
|
|
248
|
+
1. On npmjs.com create a granular access token with read and write access to the
|
|
249
|
+
`@discovery-tree` scope (packages and scopes), and allow it to bypass 2FA.
|
|
250
|
+
2. Save it as the `NPM_TOKEN` secret of the `npm-publish` environment (repository Settings →
|
|
251
|
+
Environments).
|
|
252
|
+
3. Run the workflow.
|
|
253
|
+
4. On npmjs.com, open the package → Settings → Trusted publishing → GitHub Actions:
|
|
254
|
+
organization `OrganismAI`, repository `discovery-tree`, workflow `publish-runner.yml`,
|
|
255
|
+
environment `npm-publish`. Also allow direct publishing with `npm publish`: configurations
|
|
256
|
+
created after Sep 3, 2026 allow only `npm stage publish` unless you do.
|
|
257
|
+
5. Within 2 days, validate it: delete the `NPM_TOKEN` secret (so the run can only use OIDC),
|
|
258
|
+
bump the version, merge, and run the workflow. npm expires a new trusted publisher
|
|
259
|
+
configuration that has not published within 2 days; if that happens, delete it and add it
|
|
260
|
+
again.
|
|
261
|
+
6. Once that run has published, revoke the token on npmjs.com and set the package's
|
|
262
|
+
"Publishing access" to require 2FA and disallow tokens.
|
|
263
|
+
|
|
264
|
+
The repository is private, so npm does not attach provenance to the package.
|