@tiptask/runner 0.0.0-stage → 0.8.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.
Files changed (3) hide show
  1. package/README.md +401 -2
  2. package/dist/cli.js +1652 -0
  3. package/package.json +57 -4
package/README.md CHANGED
@@ -1,3 +1,402 @@
1
- # Temporary Holding Version
1
+ # @tiptask/runner
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
+ TipTask is a self-hosted issue tracker. An AI
4
+ agent in it is a project member: it has a role, permissions, and its own issues.
5
+
6
+ This package runs such agents on your own machine — one, or several at once.
7
+
8
+ - Polls your instance for the agent's queued runs. Runs each one with a coding agent CLI.
9
+ Reports the result.
10
+ - Has presets for Claude Code, Codex, opencode, Antigravity CLI, GitHub Copilot CLI,
11
+ Pi, and Oh My Pi (`omp`). Each preset sets the unattended flags and the session resume.
12
+ - Runs your own `command` instead, if you prefer. The command takes the task on stdin.
13
+ - Answers the agent's chat. Sends the text and the tool calls while the CLI prints them.
14
+ - Sends the messages and the tool calls of a queued run to the issue while the run works.
15
+ - Receives the tasks on a port instead of polling, for an agent whose Connection is
16
+ Endpoint. See [Receiving tasks on a port](#receiving-tasks-on-a-port).
17
+
18
+ ## Quick start
19
+
20
+ **1. Get the agent's key.** In your project, go to Settings, AI agents. Create an agent
21
+ of kind External. The key appears one time only, at creation.
22
+
23
+ **2. Enable MCP** for the project, in Settings, MCP Server. MCP is off by default. The
24
+ agent reads the issue and writes its result through it.
25
+
26
+ **3. Start the runner** in the folder the coding agent should work in:
27
+
28
+ ```bash
29
+ npx -y @tiptask/runner
30
+ ```
31
+
32
+ Without a `tiptask-runner.json` there, the runner asks for the instance URL, the key, the
33
+ coding agent and the working folder. It checks that the URL is the TipTask API, and takes
34
+ `<url>/api` when the API is there. It marks the coding agents that are installed. Then
35
+ it writes `tiptask-runner.json`, writes `.mcp.json` for Claude Code, Pi and Oh My Pi, and
36
+ starts. Run `npx -y @tiptask/runner init` to answer the questions again.
37
+
38
+ The project shows the agent as online in a few seconds. Delegate an issue to the agent,
39
+ or mention it in a comment. The task then starts in your terminal.
40
+
41
+ `tiptask-runner.json` holds the key. Keep it out of git.
42
+
43
+ ### The same setup by hand
44
+
45
+ A runner that a service manager starts has no terminal to ask in, so write the two files
46
+ yourself.
47
+
48
+ **Give the coding agent the address of the MCP server.** Claude Code, Oh My Pi, and Pi
49
+ (through `pi-mcp-adapter`) read `.mcp.json` from the folder they run in. For the other
50
+ CLIs, see [Coding agent setup](https://gitlab.tma.com.vn/young-turtles/tiptask/-/blob/develop/docs/runner.md).
51
+
52
+ ```json
53
+ {
54
+ "mcpServers": {
55
+ "tiptask": {
56
+ "type": "http",
57
+ "url": "http://localhost:3000/mcp",
58
+ "headers": { "Authorization": "Bearer ${TIPTASK_API_KEY}" }
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ The runner sets `TIPTASK_API_KEY` for the command that it starts. The key thus stays in
65
+ one file.
66
+
67
+ **Write `tiptask-runner.json`** in the same folder:
68
+
69
+ ```json
70
+ {
71
+ "url": "http://localhost:3000",
72
+ "apiKey": "the key you just copied",
73
+ "agent": "claude"
74
+ }
75
+ ```
76
+
77
+ ## Which coding agent
78
+
79
+ `agent` names a CLI that the runner knows. The runner then builds the command itself: the
80
+ flags for an unattended run, and the session resume. Every preset keeps a chat session.
81
+
82
+ | Agent | Runs |
83
+ | ------------- | ------------------ |
84
+ | `claude` | Claude Code |
85
+ | `codex` | Codex CLI |
86
+ | `opencode` | opencode |
87
+ | `antigravity` | Antigravity CLI |
88
+ | `copilot` | GitHub Copilot CLI |
89
+ | `pi` | Pi |
90
+ | `omp` | Oh My Pi |
91
+
92
+ Each preset needs the CLI's own MCP config.
93
+ [Coding agent setup](https://gitlab.tma.com.vn/young-turtles/tiptask/-/blob/develop/docs/runner.md) holds
94
+ that file, and the notes for each CLI.
95
+
96
+ `--agent` on the command line has priority over the file, except over an `agents` entry
97
+ that names its own. The runner appends the arguments after `--` to the ones from the
98
+ preset:
99
+
100
+ ```bash
101
+ npx -y @tiptask/runner --agent claude -- --model opus
102
+ ```
103
+
104
+ Write the same arguments in the file if a service manager starts the runner:
105
+
106
+ ```json
107
+ {
108
+ "url": "http://localhost:3000",
109
+ "apiKey": "the key you copied on creation",
110
+ "agent": "claude",
111
+ "cwd": "/Users/me/work/my-repo",
112
+ "args": ["--model", "opus"]
113
+ }
114
+ ```
115
+
116
+ Your arguments come after the preset's own. A repeated flag thus replaces its value.
117
+
118
+ `command` replaces the preset with your own shell command. The command receives the task
119
+ on stdin. The runner keeps no session for it, because it does not know how to resume one.
120
+
121
+ ## Several agents on one runner
122
+
123
+ One key is one agent. One runner can serve several agents. It polls for each key
124
+ separately, and every agent uses the `agent`, `cwd` and `args` from the file.
125
+
126
+ ```json
127
+ {
128
+ "url": "http://localhost:3000",
129
+ "agent": "claude",
130
+ "cwd": "/Users/me/work/my-repo",
131
+ "apiKeys": ["the first agent's key", "the second agent's key"]
132
+ }
133
+ ```
134
+
135
+ The runner gives each command its own `TIPTASK_API_KEY`, so one MCP config in that
136
+ folder works for all agents.
137
+
138
+ Use `agents` instead of `apiKeys` when an agent needs its own settings. Each entry sets
139
+ its own `apiKey`. The other fields that an entry sets replace the shared ones, and the
140
+ entry inherits the rest. `name` is the agent's label in the log. Without it, the log
141
+ numbers the agents `#1`, `#2` in the order of the file.
142
+
143
+ ```json
144
+ {
145
+ "url": "http://localhost:3000",
146
+ "agent": "claude",
147
+ "cwd": "/Users/me/work/my-repo",
148
+ "agents": [
149
+ { "apiKey": "the first agent's key", "name": "planner" },
150
+ {
151
+ "apiKey": "the second agent's key",
152
+ "cwd": "/Users/me/work/other-repo",
153
+ "args": ["--model", "opus"]
154
+ }
155
+ ]
156
+ }
157
+ ```
158
+
159
+ `concurrency` counts per agent and per feed. A runner with three agents at
160
+ `concurrency: 2` can run six queued runs and six chat answers at once, each in its own
161
+ CLI process.
162
+
163
+ If the instance refuses the key of an agent, that agent stops. The other agents continue.
164
+
165
+ ## Receiving tasks on a port
166
+
167
+ By default the runner polls the instance for tasks. With `listen`, the instance sends each
168
+ task to the runner when the task is created. The runner then does not poll.
169
+
170
+ Use `listen` for a runner on a server that the instance can reach. On a laptop behind a
171
+ router, use polling. Polling needs no setup. The chat is as fast with polling, because a
172
+ chat claim waits on the server until a message comes.
173
+
174
+ **1.** In the agent's settings, open Connection and select Endpoint. Enter the public
175
+ HTTPS address of the runner's port (see [Reaching the port](#reaching-the-port)), and
176
+ save. Copy the signing secret.
177
+
178
+ **2.** Add `listen` and `signingSecret` to `tiptask-runner.json`:
179
+
180
+ ```json
181
+ {
182
+ "url": "https://plan.example.com",
183
+ "apiKey": "the agent's key",
184
+ "agent": "claude",
185
+ "listen": 4000,
186
+ "signingSecret": "whsec_…"
187
+ }
188
+ ```
189
+
190
+ **3.** Start the runner. It logs `listening on port 4000`. In the agent's settings, click
191
+ Send test. The result must be `200`.
192
+
193
+ The runner answers each task immediately. Then it runs the task as it runs a polled task,
194
+ with the same command, heartbeats and result. The rules for a request:
195
+
196
+ - The runner accepts only a `POST` request signed with the secret of one of its agents.
197
+ - It refuses a request whose signature time is more than five minutes from its clock.
198
+ - If the instance sends a task again while the task runs, the runner does not start it a
199
+ second time.
200
+
201
+ Several agents can use one port. The runner identifies the agent by the secret, so each
202
+ agent needs its own `signingSecret`. Put the agents in `agents`:
203
+
204
+ ```json
205
+ {
206
+ "url": "https://plan.example.com",
207
+ "agent": "claude",
208
+ "listen": 4000,
209
+ "agents": [
210
+ { "apiKey": "the first agent's key", "signingSecret": "whsec_first…" },
211
+ { "apiKey": "the second agent's key", "signingSecret": "whsec_second…" }
212
+ ]
213
+ }
214
+ ```
215
+
216
+ In the same file, the runner polls for each agent that has no `listen`.
217
+
218
+ ### Reaching the port
219
+
220
+ The runner serves plain HTTP. In production, the instance requires HTTPS. Put a tunnel or a
221
+ reverse proxy in front of the port:
222
+
223
+ - **Reverse proxy** on a server with a domain. Caddy gets the certificate automatically:
224
+
225
+ ```
226
+ runner.example.com {
227
+ reverse_proxy localhost:4000
228
+ }
229
+ ```
230
+
231
+ - **Cloudflare Tunnel.** `cloudflared tunnel --url http://localhost:4000` prints a
232
+ `trycloudflare.com` address. The address changes each time the tunnel starts, and then
233
+ you must change the agent's URL too. A named tunnel on your own domain keeps the same
234
+ address.
235
+ - **ngrok.** `ngrok http 4000`. A static domain in your ngrok account keeps the same
236
+ address.
237
+ - **Tailscale Funnel.** `tailscale funnel 4000` publishes the port at the machine's
238
+ `ts.net` address.
239
+
240
+ On a private network without a tunnel, add the runner's host to `SSRF_ALLOWED_HOSTS` on
241
+ the instance. That host must also use HTTPS. When `NODE_ENV` on the instance is not
242
+ `production` or `test`, the instance also accepts `http://` and private addresses, for
243
+ example `http://localhost:4000`.
244
+
245
+ ## Settings
246
+
247
+ The runner reads `./tiptask-runner.json`. Without it, and without `TIPTASK_URL` or
248
+ `TIPTASK_API_KEY`, the runner asks the setup questions in a terminal and stops with an
249
+ example file elsewhere. For a different file, give the path as an argument or in
250
+ `TIPTASK_RUNNER_CONFIG`:
251
+
252
+ ```bash
253
+ npx -y @tiptask/runner /path/to/config.json
254
+ ```
255
+
256
+ The environment variables have priority over the file. The command-line options have
257
+ priority over both. An `agents` entry has priority over all three, for the fields it sets.
258
+
259
+ | Field | Environment variable | Default | What it does |
260
+ | ---------------- | --------------------------- | ------------------ | ---------------------------------------------------------------------- |
261
+ | `url` | `TIPTASK_URL` | required | Your TipTask instance |
262
+ | `apiKey` | `TIPTASK_API_KEY` | required | The external agent's key. Replaced by `apiKeys` or `agents` |
263
+ | `apiKeys` | | — | Several keys, all with these settings. Not with `agents` |
264
+ | `agents` | | — | Several agents, each with its own key and settings. Not with `apiKeys` |
265
+ | `agent` | `TIPTASK_AGENT` | — | The coding agent to run |
266
+ | `args` | | `[]` | Arguments added after the preset's |
267
+ | `command` | `TIPTASK_COMMAND` | — | Your own command, instead of `agent` |
268
+ | `cwd` | `TIPTASK_CWD` | where you start it | Working directory for the command |
269
+ | `env` | | `{}` | Extra variables for the command |
270
+ | `concurrency` | `TIPTASK_CONCURRENCY` | `1` | Tasks at once, per agent. Queued runs and chat answers count apart |
271
+ | `pollIntervalMs` | `TIPTASK_POLL_INTERVAL_MS` | `3000` | Wait after an empty queue. Minimum 1000 |
272
+ | `timeoutMs` | `TIPTASK_TIMEOUT_MS` | `1800000` | Time before the runner stops a task |
273
+ | `outputFormat` | `TIPTASK_OUTPUT_FORMAT` | the preset's | How the runner reads the output. See [The output](#the-output) |
274
+ | `listen` | `TIPTASK_LISTEN` | — | Port that receives the tasks. The runner does not poll for the agent |
275
+ | `signingSecret` | `TIPTASK_SIGNING_SECRET` | — | The agent's signing secret. Required with `listen` |
276
+
277
+ Set `agent` or `command`. With the environment you need no file at all:
278
+
279
+ ```bash
280
+ export TIPTASK_API_KEY=…
281
+ npx -y @tiptask/runner --agent claude
282
+ ```
283
+
284
+ ## What the coding agent receives
285
+
286
+ ### The task text
287
+
288
+ The server writes the task text. The text states what occurred, what to do, and to post
289
+ the result as a comment on the issue. Your own `command` receives the text on **stdin**. A
290
+ preset gives it to its CLI in the way that CLI accepts it: on stdin for `claude`, `codex`
291
+ and `pi`, as an argument for `antigravity`, `copilot`, `opencode` and `omp`.
292
+
293
+ The agent reads all other data through the MCP server at `$TIPTASK_URL/mcp`. The agent
294
+ sends `$TIPTASK_API_KEY` as a bearer token, and acts as its own user with its role.
295
+
296
+ ### The environment
297
+
298
+ Every run holds these variables:
299
+
300
+ | Variable | What it holds |
301
+ | ------------------------ | --------------------------------------------------------------------------- |
302
+ | `TIPTASK_URL` | the instance that sent the task |
303
+ | `TIPTASK_API_KEY` | the agent's key, for the API and the MCP server |
304
+ | `TIPTASK_TRIGGER` | `mention`, `delegation`, `field`, `schedule`, `manual`, `status`, or `chat` |
305
+ | `TIPTASK_SYSTEM_PROMPT` | the context of the run, for a command that takes a system prompt |
306
+ | `TIPTASK_TIMEOUT_MS` | the task timeout in milliseconds |
307
+
308
+ A command can read `TIPTASK_TIMEOUT_MS` to set its own timeout. The value is the
309
+ `timeoutMs` of that agent, and it replaces a value from the environment or from `env`.
310
+ The time starts when the command starts.
311
+
312
+ A queued run adds three more:
313
+
314
+ | Variable | What it holds |
315
+ | ------------------- | --------------------------------------------------------------- |
316
+ | `TIPTASK_RUN_ID` | the run's id |
317
+ | `TIPTASK_ISSUE` | the issue key, for example `MKT-42`. Empty if there is no issue |
318
+ | `TIPTASK_ISSUE_ID` | the numeric id of the issue. Empty if there is no issue |
319
+
320
+ A chat message adds three others in their place, and `TIPTASK_TRIGGER` is `chat`:
321
+
322
+ | Variable | What it holds |
323
+ | --------------------- | ----------------------------------------------------------------- |
324
+ | `TIPTASK_THREAD_ID` | the conversation's id |
325
+ | `TIPTASK_MESSAGE_ID` | the id of the message to answer |
326
+ | `TIPTASK_SESSION_ID` | the coding agent's session to resume. Empty for the first message |
327
+
328
+ The task text of a chat message includes the conversation, unless a session holds it. See
329
+ [Sessions](#sessions).
330
+
331
+ ## The output
332
+
333
+ Exit code `0` is a success. Any other code is a failure, and the end of stderr becomes the
334
+ error.
335
+
336
+ `outputFormat` tells the runner how to read stdout:
337
+
338
+ - `text` — all of stdout is the answer.
339
+ - `claude-stream-json`, `codex-jsonl`, `opencode-json`, `antigravity-stream-json`,
340
+ `copilot-json`, `pi-json` — the event stream of that CLI. `pi` and `omp` both use
341
+ `pi-json`. The runner reads the text and the tool calls from it.
342
+
343
+ A preset sets `outputFormat` for you. Set it yourself only with your own `command`. If the
344
+ output does not agree with the format, the runner uses the output as plain text.
345
+
346
+ A queued run reports one answer as its output. With an event stream format, the answer is
347
+ the text that the agent wrote after its last tool call.
348
+
349
+ ### Run transcripts
350
+
351
+ While a queued run works, the runner sends the agent's messages and tool calls to the
352
+ instance. The issue shows them as the run's transcript.
353
+
354
+ - The tool calls need an event stream format. With `text`, the transcript holds only the
355
+ output.
356
+ - With `codex-jsonl`, the run shows an **Open in Codex** link. The link opens the session
357
+ only where that session is: in the Codex app of the viewer, or on a connected host. The
358
+ link does not copy the session.
359
+ - The instance keeps up to 2,000 events or 1 MB for each attempt, and marks a transcript
360
+ that it cut. The cut does not change the result of the run.
361
+ - If the last upload fails with a network or server error, the runner tries it one more
362
+ time. Then it reports the result of the command, even with an incomplete transcript.
363
+ Any other refusal fails the run.
364
+
365
+ ## Chat
366
+
367
+ The runner streams the answer to the chat while the command runs. It sends the tool calls
368
+ with the answer.
369
+
370
+ ### Sessions
371
+
372
+ Each conversation resumes one session of the coding agent, which keeps its full context.
373
+ Without a session the server sends the last 20 messages of the conversation as plain text.
374
+
375
+ - The chat header shows the session id. Run `claude --resume <id>` in the runner's working
376
+ directory to open the same session in your terminal.
377
+ - Your own `command` keeps no session. Each chat message then includes the conversation.
378
+ - A session stays on the machine that started it. If you delete its files or move the
379
+ runner, the answers fail. Start a new chat then.
380
+
381
+ ## Requirements
382
+
383
+ - **Node 20 or later.**
384
+ - **An TipTask instance 1.7.0 or later.**
385
+ - **An external agent in your project.** The runner authenticates with its API key.
386
+ - **The coding agent, installed and signed in on the same machine.** The runner starts the
387
+ CLI as you, but it cannot sign in for you.
388
+
389
+ macOS and Linux need nothing else. The runner starts a preset directly, so its arguments
390
+ need no quotes. Your own `command` goes to `sh -c`, so write it as POSIX shell.
391
+
392
+ Windows needs WSL2, because `cmd.exe` and PowerShell have no `sh`:
393
+
394
+ ```powershell
395
+ wsl --install # installs Ubuntu, then reboot
396
+ ```
397
+
398
+ Do everything else in WSL: Node, the coding agent, the config file, and the runner.
399
+
400
+ - Keep the working directory in the WSL file system (`~/work/repo`), not under
401
+ `/mnt/c/...`. Access between the two file systems is slow.
402
+ - An instance on the Windows host is available at `http://localhost:3000`.