@firefunc-agent/runner 0.9.14 → 0.9.35

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 (158) hide show
  1. package/README.md +184 -10
  2. package/dist/alive.d.ts +40 -0
  3. package/dist/alive.js +138 -0
  4. package/dist/api-fallback.d.ts +4 -2
  5. package/dist/api-fallback.js +26 -1
  6. package/dist/api.d.ts +66 -3
  7. package/dist/api.js +164 -3
  8. package/dist/brief-file.d.ts +15 -0
  9. package/dist/brief-file.js +36 -0
  10. package/dist/brief.d.ts +3 -0
  11. package/dist/brief.js +14 -4
  12. package/dist/build-caches.d.ts +7 -0
  13. package/dist/build-caches.js +63 -0
  14. package/dist/build-info.json +2 -2
  15. package/dist/checkpoint.d.ts +40 -0
  16. package/dist/checkpoint.js +98 -0
  17. package/dist/cli.js +184 -18
  18. package/dist/cloud-boot.d.ts +41 -0
  19. package/dist/cloud-boot.js +239 -0
  20. package/dist/command-activity.d.ts +23 -0
  21. package/dist/command-activity.js +89 -0
  22. package/dist/command-step.d.ts +58 -0
  23. package/dist/command-step.js +248 -0
  24. package/dist/config.d.ts +39 -0
  25. package/dist/config.js +23 -0
  26. package/dist/cut.d.ts +1 -1
  27. package/dist/cut.js +13 -3
  28. package/dist/daemon.js +364 -15
  29. package/dist/device-lease.d.ts +15 -0
  30. package/dist/device-lease.js +608 -0
  31. package/dist/editor/fs-server.d.ts +31 -0
  32. package/dist/editor/fs-server.js +159 -0
  33. package/dist/editor/relay-crypto.d.ts +68 -0
  34. package/dist/editor/relay-crypto.js +191 -0
  35. package/dist/editor/sessions.d.ts +50 -0
  36. package/dist/editor/sessions.js +279 -0
  37. package/dist/editor/worktree-of.d.ts +1 -0
  38. package/dist/editor/worktree-of.js +23 -0
  39. package/dist/editor/ws-client.d.ts +26 -0
  40. package/dist/editor/ws-client.js +227 -0
  41. package/dist/engine-account.d.ts +24 -0
  42. package/dist/engine-account.js +118 -0
  43. package/dist/engine-login.d.ts +12 -0
  44. package/dist/engine-login.js +88 -0
  45. package/dist/engine-models.d.ts +13 -0
  46. package/dist/engine-models.js +71 -0
  47. package/dist/engine-watch.d.ts +1 -0
  48. package/dist/engine-watch.js +22 -6
  49. package/dist/engines/antigravity.d.ts +2 -0
  50. package/dist/engines/antigravity.js +74 -4
  51. package/dist/engines/claude.js +22 -9
  52. package/dist/engines/codex.js +16 -2
  53. package/dist/engines/copilot.js +12 -0
  54. package/dist/engines/crush.d.ts +2 -0
  55. package/dist/engines/crush.js +58 -0
  56. package/dist/engines/cursor.js +12 -0
  57. package/dist/engines/gemini.js +14 -9
  58. package/dist/engines/index.d.ts +8 -0
  59. package/dist/engines/index.js +73 -1
  60. package/dist/engines/kilo.d.ts +2 -0
  61. package/dist/engines/kilo.js +63 -0
  62. package/dist/engines/opencode.d.ts +9 -0
  63. package/dist/engines/opencode.js +234 -0
  64. package/dist/engines/openhands.d.ts +10 -0
  65. package/dist/engines/openhands.js +271 -0
  66. package/dist/engines/pi.d.ts +10 -0
  67. package/dist/engines/pi.js +248 -0
  68. package/dist/engines/qwen.d.ts +8 -0
  69. package/dist/engines/qwen.js +153 -0
  70. package/dist/engines/sessions.d.ts +6 -0
  71. package/dist/engines/sessions.js +68 -0
  72. package/dist/engines/types.d.ts +3 -3
  73. package/dist/exec.d.ts +1 -0
  74. package/dist/exec.js +10 -4
  75. package/dist/firefunc/agents.d.ts +8 -1
  76. package/dist/firefunc/agents.js +53 -3
  77. package/dist/firefunc/auth.js +72 -19
  78. package/dist/firefunc/automations.d.ts +2 -0
  79. package/dist/firefunc/automations.js +290 -0
  80. package/dist/firefunc/cli.js +25 -0
  81. package/dist/firefunc/client.d.ts +5 -1
  82. package/dist/firefunc/client.js +12 -2
  83. package/dist/firefunc/config.d.ts +11 -1
  84. package/dist/firefunc/config.js +6 -4
  85. package/dist/firefunc/io.d.ts +1 -0
  86. package/dist/firefunc/main.js +34 -2
  87. package/dist/firefunc/oauth-login.d.ts +23 -0
  88. package/dist/firefunc/oauth-login.js +304 -0
  89. package/dist/firefunc/tasks.d.ts +4 -0
  90. package/dist/firefunc/tasks.js +89 -2
  91. package/dist/fleet-words.d.ts +2 -0
  92. package/dist/fleet-words.js +7 -0
  93. package/dist/git-auth.d.ts +15 -0
  94. package/dist/git-auth.js +39 -1
  95. package/dist/held.d.ts +3 -0
  96. package/dist/job.d.ts +26 -3
  97. package/dist/job.js +763 -152
  98. package/dist/keep-awake.d.ts +17 -0
  99. package/dist/keep-awake.js +90 -0
  100. package/dist/keep-local.d.ts +1 -1
  101. package/dist/keep-local.js +5 -3
  102. package/dist/limit.d.ts +9 -1
  103. package/dist/limit.js +260 -3
  104. package/dist/local-checks.d.ts +19 -0
  105. package/dist/local-checks.js +79 -0
  106. package/dist/locks.d.ts +18 -1
  107. package/dist/locks.js +249 -69
  108. package/dist/machine-commands.d.ts +21 -0
  109. package/dist/machine-commands.js +107 -0
  110. package/dist/machine-profile.d.ts +18 -0
  111. package/dist/machine-profile.js +69 -0
  112. package/dist/mcp-init.d.ts +2 -0
  113. package/dist/mcp-init.js +28 -0
  114. package/dist/mcp.d.ts +13 -1
  115. package/dist/mcp.js +48 -4
  116. package/dist/network.js +3 -2
  117. package/dist/openrouter.d.ts +15 -0
  118. package/dist/openrouter.js +39 -0
  119. package/dist/orphans.d.ts +4 -0
  120. package/dist/orphans.js +96 -4
  121. package/dist/pool.d.ts +1 -0
  122. package/dist/pool.js +25 -2
  123. package/dist/pr-title.d.ts +10 -0
  124. package/dist/pr-title.js +15 -0
  125. package/dist/recover.d.ts +3 -1
  126. package/dist/recover.js +27 -7
  127. package/dist/release-draft.d.ts +79 -0
  128. package/dist/release-draft.js +301 -0
  129. package/dist/resources.d.ts +86 -0
  130. package/dist/resources.js +217 -0
  131. package/dist/restart-idle.d.ts +23 -0
  132. package/dist/restart-idle.js +67 -0
  133. package/dist/run-attachments.d.ts +5 -0
  134. package/dist/run-attachments.js +14 -9
  135. package/dist/run-stops.d.ts +15 -0
  136. package/dist/run-stops.js +90 -0
  137. package/dist/run-temp.d.ts +12 -0
  138. package/dist/run-temp.js +57 -0
  139. package/dist/secret-scan.d.ts +5 -0
  140. package/dist/secret-scan.js +30 -0
  141. package/dist/self-upgrade.d.ts +36 -0
  142. package/dist/self-upgrade.js +78 -0
  143. package/dist/service.d.ts +7 -1
  144. package/dist/service.js +50 -7
  145. package/dist/sign-in.d.ts +42 -0
  146. package/dist/sign-in.js +243 -0
  147. package/dist/tool-call.d.ts +59 -0
  148. package/dist/tool-call.js +375 -0
  149. package/dist/transport.d.ts +26 -0
  150. package/dist/transport.js +118 -0
  151. package/dist/work-dir.d.ts +11 -0
  152. package/dist/work-dir.js +69 -0
  153. package/dist/worktree-report.d.ts +10 -0
  154. package/dist/worktree-report.js +17 -0
  155. package/dist/worktrees.d.ts +16 -1
  156. package/dist/worktrees.js +62 -17
  157. package/package.json +4 -4
  158. package/skill/firefunc/SKILL.md +22 -3
@@ -0,0 +1,304 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { createServer } from 'node:http';
3
+ import { saveCliConfig } from './config.js';
4
+ import { Refusal } from './io.js';
5
+ import { CLI_VERSION } from './version.js';
6
+ const SCOPES = [
7
+ 'agents:read',
8
+ 'agents:write',
9
+ 'tasks:read',
10
+ 'tasks:write',
11
+ 'agents:activate',
12
+ 'workspace:configure',
13
+ ];
14
+ const REDIRECT = 'http://127.0.0.1/callback';
15
+ const WAIT_MS = 10 * 60 * 1000;
16
+ const REFRESH_MARGIN_MS = 2 * 60 * 1000;
17
+ const b64url = (b) => b.toString('base64url');
18
+ async function postJson(io, url, body) {
19
+ return io.fetch(url, {
20
+ method: 'POST',
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ Accept: 'application/json',
24
+ 'User-Agent': `firefunc-cli/${CLI_VERSION}`,
25
+ },
26
+ body: JSON.stringify(body),
27
+ signal: AbortSignal.timeout(30_000),
28
+ });
29
+ }
30
+ async function postForm(io, url, form) {
31
+ return io.fetch(url, {
32
+ method: 'POST',
33
+ headers: {
34
+ 'Content-Type': 'application/x-www-form-urlencoded',
35
+ Accept: 'application/json',
36
+ 'User-Agent': `firefunc-cli/${CLI_VERSION}`,
37
+ },
38
+ body: new URLSearchParams(form).toString(),
39
+ signal: AbortSignal.timeout(30_000),
40
+ });
41
+ }
42
+ function unreachable(url, err) {
43
+ return new Refusal(`Could not reach ${url} (${err?.cause?.code ?? err?.message ?? 'no answer'}).`, 'Check your connection and the address (--api-url), then run firefunc login again.', 'unreachable');
44
+ }
45
+ async function readJson(res) {
46
+ try {
47
+ return (await res.json());
48
+ }
49
+ catch {
50
+ return undefined;
51
+ }
52
+ }
53
+ async function oauthRefusal(res, what, fix) {
54
+ const body = await readJson(res);
55
+ return new Refusal(`${what}: ${body?.error_description ?? body?.error ?? `HTTP ${res.status}`}.`, fix, body?.error ?? `http_${res.status}`);
56
+ }
57
+ export async function discover(io, apiUrl) {
58
+ const url = `${apiUrl}/.well-known/oauth-authorization-server`;
59
+ let res;
60
+ try {
61
+ res = await io.fetch(url, {
62
+ headers: { Accept: 'application/json' },
63
+ signal: AbortSignal.timeout(30_000),
64
+ });
65
+ }
66
+ catch (err) {
67
+ throw unreachable(apiUrl, err);
68
+ }
69
+ const meta = res.ok ? await readJson(res) : undefined;
70
+ if (!meta?.authorization_endpoint || !meta.token_endpoint) {
71
+ throw new Refusal(`${apiUrl} does not offer FireFunc sign-in (no OAuth metadata at ${url}).`, 'Point the CLI at the API itself (--api-url https://api.firefunc.com), or sign in with a workspace key: firefunc login --with-key.', 'no_oauth');
72
+ }
73
+ return meta;
74
+ }
75
+ async function register(io, meta) {
76
+ if (!meta.registration_endpoint) {
77
+ throw new Refusal('This server does not let the CLI register itself for sign-in.', 'Sign in with a workspace key instead: firefunc login --with-key.', 'no_registration');
78
+ }
79
+ let res;
80
+ try {
81
+ res = await postJson(io, meta.registration_endpoint, {
82
+ client_name: 'FireFunc CLI',
83
+ client_uri: 'https://firefunc.com/docs/connect/',
84
+ redirect_uris: [REDIRECT],
85
+ grant_types: ['authorization_code', 'refresh_token'],
86
+ response_types: ['code'],
87
+ token_endpoint_auth_method: 'none',
88
+ });
89
+ }
90
+ catch (err) {
91
+ throw unreachable(meta.registration_endpoint, err);
92
+ }
93
+ if (res.status !== 201 && res.status !== 200) {
94
+ throw await oauthRefusal(res, 'FireFunc did not register the CLI', 'Try again in a few minutes, or sign in with a workspace key: firefunc login --with-key.');
95
+ }
96
+ const body = await readJson(res);
97
+ if (!body?.client_id) {
98
+ throw new Refusal('FireFunc answered the registration without a client id.', 'Try again; if it keeps failing, sign in with a workspace key: firefunc login --with-key.', 'bad_registration');
99
+ }
100
+ return body.client_id;
101
+ }
102
+ async function listen(state, issuer) {
103
+ let settle;
104
+ const answer = new Promise((r) => (settle = r));
105
+ const server = createServer((req, res) => {
106
+ const url = new URL(req.url ?? '/', 'http://127.0.0.1');
107
+ if (url.pathname !== '/callback') {
108
+ res.statusCode = 404;
109
+ res.end();
110
+ return;
111
+ }
112
+ const p = url.searchParams;
113
+ const iss = p.get('iss');
114
+ let result;
115
+ if (p.get('state') !== state) {
116
+ result = {
117
+ error: 'state_mismatch',
118
+ description: 'the answer is not for this sign-in (its state differs)',
119
+ };
120
+ }
121
+ else if (iss !== null && iss.replace(/\/+$/, '').toLowerCase() !== issuer.toLowerCase()) {
122
+ result = { error: 'issuer_mismatch', description: `the answer came from ${iss}` };
123
+ }
124
+ else if (p.get('error')) {
125
+ result = {
126
+ error: p.get('error'),
127
+ description: p.get('error_description') ?? undefined,
128
+ };
129
+ }
130
+ else if (p.get('code')) {
131
+ result = { code: p.get('code') };
132
+ }
133
+ else {
134
+ result = { error: 'no_code', description: 'the browser came back without a code' };
135
+ }
136
+ const ok = 'code' in result;
137
+ res.statusCode = ok ? 200 : 400;
138
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
139
+ res.setHeader('Cache-Control', 'no-store');
140
+ const why = 'error' in result ? (result.error === 'access_denied' ? 'denied' : 'failed') : '';
141
+ res.end(callbackPage(ok, why));
142
+ settle(result);
143
+ });
144
+ await new Promise((r) => server.listen(0, '127.0.0.1', r));
145
+ return {
146
+ port: server.address().port,
147
+ answer,
148
+ close: () => server.close(),
149
+ };
150
+ }
151
+ function callbackPage(ok, why) {
152
+ const title = ok ? 'Connected' : why === 'denied' ? 'Not connected' : 'Sign-in failed';
153
+ const line = ok
154
+ ? 'The FireFunc CLI is signed in. You can close this tab and go back to your terminal.'
155
+ : why === 'denied'
156
+ ? 'You chose Deny, so nothing was connected. Close this tab; the terminal says what to do next.'
157
+ : 'The terminal says what went wrong and how to fix it. You can close this tab.';
158
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title} · FireFunc</title>
159
+ <style>:root{color-scheme:light dark;--bg:#fbfaf8;--fg:#1f1d1a;--mute:#6b665e;--line:#e7e3dc;--ok:#2f7a4b;--bad:#a23b2a}
160
+ @media (prefers-color-scheme:dark){:root{--bg:#161513;--fg:#f1eee9;--mute:#a39d93;--line:#2e2b27;--ok:#6fbf8c;--bad:#e3826f}}
161
+ body{margin:0;min-height:100vh;display:grid;place-items:center;background:var(--bg);color:var(--fg);font:15px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,sans-serif;padding:16px;box-sizing:border-box}
162
+ main{max-width:420px;border:1px solid var(--line);border-radius:12px;padding:28px 28px 24px}
163
+ h1{margin:0 0 6px;font-size:20px;font-weight:600;color:${ok ? 'var(--ok)' : 'var(--bad)'}}p{margin:0;color:var(--mute)}</style></head>
164
+ <body><main><h1>${title}</h1><p>${line}</p></main></body></html>`;
165
+ }
166
+ export async function browserLogin(io, apiUrl, existing, opts) {
167
+ const meta = await discover(io, apiUrl);
168
+ const issuer = meta.issuer.replace(/\/+$/, '');
169
+ const clientId = existing?.oauth?.clientId && existing.apiUrl === apiUrl
170
+ ? existing.oauth.clientId
171
+ : await register(io, meta);
172
+ const verifier = b64url(randomBytes(32));
173
+ const challenge = b64url(createHash('sha256').update(verifier).digest());
174
+ const state = b64url(randomBytes(16));
175
+ const cb = await listen(state, issuer);
176
+ const redirectUri = `http://127.0.0.1:${cb.port}/callback`;
177
+ const auth = new URL(meta.authorization_endpoint);
178
+ auth.search = new URLSearchParams({
179
+ response_type: 'code',
180
+ client_id: clientId,
181
+ redirect_uri: redirectUri,
182
+ code_challenge: challenge,
183
+ code_challenge_method: 'S256',
184
+ state,
185
+ scope: SCOPES.join(' '),
186
+ resource: issuer,
187
+ }).toString();
188
+ let timer;
189
+ try {
190
+ const opened = !opts.noBrowser && opts.openBrowser ? await opts.openBrowser(auth.toString()) : false;
191
+ io.stderr.write(opened
192
+ ? `Opened FireFunc in your browser. Choose the workspace and what the CLI may do, then press Allow.\nIf no tab opened, go to:\n ${auth.toString()}\n\nWaiting for the browser… (Ctrl-C to stop)\n`
193
+ : `Open this address in a browser on this computer, choose the workspace and what the CLI may do, then press Allow:\n ${auth.toString()}\n\nWaiting for the browser… (Ctrl-C to stop)\n`);
194
+ const timeout = new Promise((r) => {
195
+ timer = setTimeout(() => r({ error: 'timeout', description: 'no answer came back within 10 minutes' }), WAIT_MS);
196
+ timer.unref?.();
197
+ });
198
+ const result = await Promise.race([cb.answer, timeout]);
199
+ if (!('code' in result)) {
200
+ if (result.error === 'access_denied') {
201
+ throw new Refusal('You chose Deny in the browser, so the CLI is not signed in.', 'Run firefunc login again and press Allow, or sign in with a workspace key: firefunc login --with-key.', 'access_denied');
202
+ }
203
+ throw new Refusal(`Sign-in did not finish: ${result.description ?? result.error}.`, 'Run firefunc login again. On a machine with no browser, use a workspace key: firefunc login --with-key.', result.error);
204
+ }
205
+ let res;
206
+ try {
207
+ res = await postForm(io, meta.token_endpoint, {
208
+ grant_type: 'authorization_code',
209
+ code: result.code,
210
+ client_id: clientId,
211
+ redirect_uri: redirectUri,
212
+ code_verifier: verifier,
213
+ resource: issuer,
214
+ });
215
+ }
216
+ catch (err) {
217
+ throw unreachable(meta.token_endpoint, err);
218
+ }
219
+ if (!res.ok) {
220
+ throw await oauthRefusal(res, 'FireFunc did not issue a token', 'Run firefunc login again.');
221
+ }
222
+ const tokens = await readJson(res);
223
+ if (!tokens?.access_token || !tokens.refresh_token) {
224
+ throw new Refusal('FireFunc answered without a token.', 'Run firefunc login again.', 'bad_token');
225
+ }
226
+ const oauth = {
227
+ clientId,
228
+ accessToken: tokens.access_token,
229
+ refreshToken: tokens.refresh_token,
230
+ expiresAt: new Date(io.now() + tokens.expires_in * 1000).toISOString(),
231
+ tokenEndpoint: meta.token_endpoint,
232
+ ...(meta.revocation_endpoint ? { revocationEndpoint: meta.revocation_endpoint } : {}),
233
+ };
234
+ return {
235
+ config: {
236
+ apiUrl,
237
+ oauth,
238
+ scopes: tokens.scope.split(' ').filter(Boolean),
239
+ savedAt: new Date(io.now()).toISOString(),
240
+ },
241
+ accessToken: tokens.access_token,
242
+ };
243
+ }
244
+ finally {
245
+ if (timer)
246
+ clearTimeout(timer);
247
+ cb.close();
248
+ }
249
+ }
250
+ export async function freshAccessToken(io, cfg, opts = {}) {
251
+ const o = cfg.oauth;
252
+ if (!o)
253
+ throw new Error('no OAuth credential');
254
+ const left = new Date(o.expiresAt).getTime() - io.now();
255
+ if (!opts.force && left > REFRESH_MARGIN_MS)
256
+ return o.accessToken;
257
+ let res;
258
+ try {
259
+ res = await postForm(io, o.tokenEndpoint, {
260
+ grant_type: 'refresh_token',
261
+ refresh_token: o.refreshToken,
262
+ client_id: o.clientId,
263
+ });
264
+ }
265
+ catch (err) {
266
+ throw unreachable(o.tokenEndpoint, err);
267
+ }
268
+ if (!res.ok) {
269
+ throw await oauthRefusal(res, 'Your FireFunc sign-in has ended', 'Sign in again: firefunc login (it may have been disconnected in FireFunc → Settings → AI tools).');
270
+ }
271
+ const t = await readJson(res);
272
+ if (!t?.access_token || !t.refresh_token) {
273
+ throw new Refusal('FireFunc answered without a token.', 'Sign in again: firefunc login', 'bad_token');
274
+ }
275
+ const next = {
276
+ ...cfg,
277
+ oauth: {
278
+ ...o,
279
+ accessToken: t.access_token,
280
+ refreshToken: t.refresh_token,
281
+ expiresAt: new Date(io.now() + t.expires_in * 1000).toISOString(),
282
+ },
283
+ scopes: t.scope ? t.scope.split(' ').filter(Boolean) : cfg.scopes,
284
+ };
285
+ saveCliConfig(io, next);
286
+ Object.assign(cfg, next);
287
+ return t.access_token;
288
+ }
289
+ export async function revokeSignIn(io, o) {
290
+ if (!o.revocationEndpoint)
291
+ return false;
292
+ try {
293
+ const res = await postForm(io, o.revocationEndpoint, {
294
+ token: o.refreshToken,
295
+ token_type_hint: 'refresh_token',
296
+ client_id: o.clientId,
297
+ });
298
+ return res.ok;
299
+ }
300
+ catch {
301
+ return false;
302
+ }
303
+ }
304
+ //# sourceMappingURL=oauth-login.js.map
@@ -1,2 +1,6 @@
1
+ import { type Row } from './catalog.js';
1
2
  import { type Command } from './command.js';
3
+ export declare function outputWords(o: Row): string;
4
+ export declare function handedFromWords(v: unknown): string | null;
5
+ export declare function stalledWords(v: unknown): string | null;
2
6
  export declare const taskCommands: Command[];
@@ -16,6 +16,23 @@ const STOPS_FOR_A_PERSON = [
16
16
  'dry_run_skipped',
17
17
  ];
18
18
  const isFailure = (state) => state.endsWith('_failed');
19
+ function claimWords(r) {
20
+ if (!('machine' in r))
21
+ return '';
22
+ const machine = r.machine;
23
+ if (machine) {
24
+ const name = typeof machine.name === 'string' && machine.name ? machine.name : 'a machine';
25
+ if (r.state !== 'dispatched')
26
+ return ` ran on ${name}`;
27
+ const since = typeof r.claimedAt === 'string' ? ` since ${r.claimedAt}` : '';
28
+ return ` on ${name}${since}`;
29
+ }
30
+ const engine = typeof r.engine === 'string' ? r.engine : '';
31
+ if (r.state === 'dispatched' && engine.endsWith('_channel')) {
32
+ return ' no machine has taken it yet';
33
+ }
34
+ return '';
35
+ }
19
36
  function printTask(ctx, t) {
20
37
  const agent = t.agent;
21
38
  const project = t.project;
@@ -35,11 +52,19 @@ function printTask(ctx, t) {
35
52
  }
36
53
  else if (t.error)
37
54
  lines.push(` error: ${text(t.error)}`);
55
+ const stalled = stalledWords(t.stalled);
56
+ if (stalled) {
57
+ lines.push(...wrap(stalled, 78, ' stalled: ', ' '));
58
+ lines.push(...wrap(STALL_FIX, 78, ' fix: ', ' '));
59
+ }
38
60
  const prs = Array.isArray(t.pullRequests) ? t.pullRequests : [];
39
61
  for (const pr of prs)
40
62
  lines.push(` pull request: ${text(pr.url)} (${text(pr.state)})`);
41
63
  if (t.externalUrl)
42
64
  lines.push(` source: ${text(t.externalUrl)}`);
65
+ const from = handedFromWords(t.handedFrom);
66
+ if (from)
67
+ lines.push(...wrap(from, 78, ' handed by: ', ' '));
43
68
  const verdict = verdictWord(t.verdict);
44
69
  if (verdict)
45
70
  lines.push(` verdict: ${verdict}`);
@@ -48,7 +73,18 @@ function printTask(ctx, t) {
48
73
  lines.push(` runs: ${runs.length}`);
49
74
  for (const r of runs.slice(0, 5)) {
50
75
  const word = verdictWord(r.verdict);
51
- lines.push(` ${text(r.id)} ${text(r.state)} ${text(r.engine)}${word ? ` ${word}` : ''}${r.error ? ` ${text(r.error)}` : ''}`);
76
+ lines.push(` ${text(r.id)} ${text(r.state)} ${text(r.engine)}${word ? ` ${word}` : ''}${claimWords(r)}${r.error ? ` ${text(r.error)}` : ''}`);
77
+ }
78
+ }
79
+ const outputs = Array.isArray(t.outputs) ? t.outputs : [];
80
+ if (outputs.length) {
81
+ lines.push(` outputs: ${outputs.length}`);
82
+ for (const o of outputs) {
83
+ lines.push(...wrap(outputWords(o), 76, ' - ', ' '));
84
+ if (o.status !== 'succeeded' && typeof o.reason === 'string' && o.reason)
85
+ lines.push(...wrap(o.reason, 74, ' why: ', ' '));
86
+ if (o.status !== 'succeeded' && typeof o.fix === 'string' && o.fix)
87
+ lines.push(...wrap(o.fix, 74, ' fix: ', ' '));
52
88
  }
53
89
  }
54
90
  const findings = Array.isArray(t.findings) ? t.findings : [];
@@ -70,6 +106,50 @@ function printTask(ctx, t) {
70
106
  }
71
107
  ctx.io.stdout.write(`${lines.join('\n')}\n`);
72
108
  }
109
+ const agentWords = (a) => {
110
+ if (!a || typeof a !== 'object')
111
+ return null;
112
+ const { name, handle, id } = a;
113
+ if (typeof handle === 'string' && handle)
114
+ return `@${handle}`;
115
+ if (typeof name === 'string' && name)
116
+ return name;
117
+ return typeof id === 'string' ? id : null;
118
+ };
119
+ export function outputWords(o) {
120
+ const handed = o.handedTo;
121
+ const what = handed
122
+ ? `hand-off → ${agentWords(handed.agent) ?? 'an agent'}`
123
+ : `${text(o.tool)} · ${text(o.action)}`;
124
+ const line = typeof o.line === 'string' && o.line ? ` [${o.line}]` : '';
125
+ const task = handed && typeof handed.task === 'string' ? ` task ${handed.task}` : '';
126
+ const url = typeof o.url === 'string' && o.url ? ` ${o.url}` : '';
127
+ return `${what}${line}: ${text(o.status)}${task}${url}`;
128
+ }
129
+ export function handedFromWords(v) {
130
+ if (!v || typeof v !== 'object')
131
+ return null;
132
+ const h = v;
133
+ const pr = h.pullRequest;
134
+ const prWords = pr
135
+ ? typeof pr.url === 'string' && pr.url
136
+ ? ` with ${pr.url}`
137
+ : ` with ${String(pr.repo)}#${String(pr.number)}`
138
+ : '';
139
+ const task = typeof h.task === 'string' ? ` (task ${h.task})` : '';
140
+ return `${agentWords(h.agent) ?? 'another agent'}${task}${prWords}`;
141
+ }
142
+ const STALL_FIX = 'Stop and re-run it, or open the task.';
143
+ export function stalledWords(v) {
144
+ if (!v || typeof v !== 'object')
145
+ return null;
146
+ const st = v;
147
+ if (typeof st.silentFor !== 'string' || !st.silentFor)
148
+ return null;
149
+ const machine = typeof st.machine === 'string' && st.machine ? st.machine : 'its machine';
150
+ const since = typeof st.since === 'string' ? ` (nothing since ${st.since})` : '';
151
+ return `no activity for ${st.silentFor} on ${machine}${since}`;
152
+ }
73
153
  function heldBy(v) {
74
154
  if (!v || typeof v !== 'object')
75
155
  return null;
@@ -184,7 +264,7 @@ export const taskCommands = [
184
264
  {
185
265
  path: ['run'],
186
266
  summary: 'Start a task on an active agent (what "Run now" does)',
187
- usage: 'run <agent id or @handle> --title <title> [--body <text> | --body-file <path>] [--type <type>] [--watch]',
267
+ usage: 'run <agent id or @handle> --title <title> [--body <text> | --body-file <path>] [--type <type>] [--pr <owner/repo#n>] [--watch]',
188
268
  details: 'The agent must be active; a draft is activated by a person first. Needs tasks:write.\n' +
189
269
  `Types: ${TASK_TYPES.join(', ')} (default task).`,
190
270
  flags: {
@@ -192,6 +272,7 @@ export const taskCommands = [
192
272
  body: 'string',
193
273
  'body-file': 'string',
194
274
  type: 'string',
275
+ pr: 'string',
195
276
  watch: 'boolean',
196
277
  interval: 'string',
197
278
  timeout: 'string',
@@ -201,6 +282,10 @@ export const taskCommands = [
201
282
  ['--body <text>', 'the detail'],
202
283
  ['--body-file <path>', 'the detail from a file ("-" for stdin)'],
203
284
  ['--type <type>', `${TASK_TYPES.join(' | ')}`],
285
+ [
286
+ '--pr <owner/repo#n>',
287
+ 'the open pull request it is for: the agent continues its branch, or reviews it and posts the review there',
288
+ ],
204
289
  ['--watch', 'then watch it until it stops (see "firefunc tasks watch --help")'],
205
290
  ...watchFlagHelp,
206
291
  ],
@@ -219,6 +304,7 @@ export const taskCommands = [
219
304
  if (type !== undefined && !TASK_TYPES.includes(type)) {
220
305
  throw new UsageError(`--type must be one of ${TASK_TYPES.join(', ')}.`, ctx.command);
221
306
  }
307
+ const pr = str(ctx.args, 'pr');
222
308
  const watch = bool(ctx.args, 'watch');
223
309
  const opts = watch ? watchOpts(ctx) : undefined;
224
310
  const detail = bodyFile !== undefined
@@ -229,6 +315,7 @@ export const taskCommands = [
229
315
  title: title.trim(),
230
316
  ...(detail ? { body: detail } : {}),
231
317
  ...(type ? { type } : {}),
318
+ ...(pr?.trim() ? { pullRequest: pr.trim() } : {}),
232
319
  });
233
320
  const task = (answer?.task ?? {});
234
321
  if (watch && typeof task.id === 'string') {
@@ -0,0 +1,2 @@
1
+ export declare const RUNNER_PACKAGE = "@firefunc-agent/runner";
2
+ export declare function parseCliVersion(output: string): string | null;
@@ -0,0 +1,7 @@
1
+ export const RUNNER_PACKAGE = '@firefunc-agent/runner';
2
+ const ENGINE_VERSION = /^[0-9A-Za-z][0-9A-Za-z.+_-]{0,39}$/;
3
+ export function parseCliVersion(output) {
4
+ const m = /\b(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\b/.exec(output);
5
+ return m && ENGINE_VERSION.test(m[1]) ? m[1] : null;
6
+ }
7
+ //# sourceMappingURL=fleet-words.js.map
@@ -8,8 +8,10 @@ export declare function redact(text: string, token?: string): string;
8
8
  export declare function gitAuthEnv(token: string, repo: string): NodeJS.ProcessEnv;
9
9
  export declare function cloneRepo(repo: string, dest: string, cred: GitCredential): Promise<ExecResult>;
10
10
  export declare const pushFlags: (force: boolean) => string[];
11
+ export declare const PUSH_TIMEOUT_MS = 120000;
11
12
  export declare function pushBranch(worktree: string, branch: string, repo: string, cred: GitCredential, opts?: {
12
13
  force: boolean;
14
+ timeoutMs?: number;
13
15
  }): Promise<ExecResult>;
14
16
  export declare function openDraftPr(args: {
15
17
  repo: string;
@@ -25,3 +27,16 @@ export declare function openDraftPr(args: {
25
27
  } | {
26
28
  error: string;
27
29
  }>;
30
+ export declare function endedPullRequestForHead(args: {
31
+ repo: string;
32
+ head: string;
33
+ cred: GitCredential;
34
+ fetchImpl?: typeof fetch;
35
+ }): Promise<{
36
+ number: number;
37
+ state: 'merged' | 'closed';
38
+ } | null>;
39
+ export declare function endedPullRequestSentence(branch: string, pr: {
40
+ number: number;
41
+ state: 'merged' | 'closed';
42
+ }, base: string | null): string;
package/dist/git-auth.js CHANGED
@@ -36,9 +36,10 @@ export async function cloneRepo(repo, dest, cred) {
36
36
  return { ...res, stderr: redact(res.stderr, cred.token), stdout: redact(res.stdout, cred.token) };
37
37
  }
38
38
  export const pushFlags = (force) => (force ? ['--force-with-lease'] : []);
39
+ export const PUSH_TIMEOUT_MS = 120_000;
39
40
  export async function pushBranch(worktree, branch, repo, cred, opts = { force: true }) {
40
41
  const res = await exec('git', ['-C', worktree, 'push', ...pushFlags(opts.force), 'origin', `${branch}:${branch}`], {
41
- timeoutMs: 120_000,
42
+ timeoutMs: opts.timeoutMs ?? PUSH_TIMEOUT_MS,
42
43
  env: gitAuthEnv(cred.token, repo),
43
44
  });
44
45
  return { ...res, stderr: redact(res.stderr, cred.token), stdout: redact(res.stdout, cred.token) };
@@ -83,4 +84,41 @@ export async function openDraftPr(args) {
83
84
  }
84
85
  return { error: `github refused to open the pull request (${res.status})` };
85
86
  }
87
+ export async function endedPullRequestForHead(args) {
88
+ const { repo, head, cred } = args;
89
+ const owner = repo.split('/')[0];
90
+ if (!owner)
91
+ return null;
92
+ try {
93
+ const res = await (args.fetchImpl ?? fetch)(`https://api.github.com/repos/${repo}/pulls?head=${encodeURIComponent(`${owner}:${head}`)}&state=all&per_page=20`, {
94
+ headers: {
95
+ authorization: `Bearer ${cred.token}`,
96
+ accept: 'application/vnd.github+json',
97
+ 'x-github-api-version': '2022-11-28',
98
+ 'user-agent': 'firefunc-runner',
99
+ },
100
+ });
101
+ if (!res.ok)
102
+ return null;
103
+ const rows = (await res.json());
104
+ if (!Array.isArray(rows) || rows.length === 0)
105
+ return null;
106
+ if (rows.some((r) => r.state === 'open'))
107
+ return null;
108
+ const merged = rows.find((r) => typeof r.merged_at === 'string' && Number.isFinite(r.number));
109
+ if (merged)
110
+ return { number: Number(merged.number), state: 'merged' };
111
+ const closed = rows.find((r) => r.state === 'closed' && Number.isFinite(r.number));
112
+ return closed ? { number: Number(closed.number), state: 'closed' } : null;
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ }
118
+ export function endedPullRequestSentence(branch, pr, base) {
119
+ const target = base || 'the base branch';
120
+ return pr.state === 'merged'
121
+ ? `The pull request this run was asked to revise, #${pr.number} (branch ${branch}), was merged before the change could be pushed — continuing it would open a second pull request with the same work. Nothing was pushed. Fix: to change ${target}, start a new task.`
122
+ : `The pull request this run was asked to revise, #${pr.number} (branch ${branch}), was closed without merging before the change could be pushed. Nothing was pushed. Fix: reopen #${pr.number} and re-run this task, or start a new task to make the change afresh.`;
123
+ }
86
124
  //# sourceMappingURL=git-auth.js.map
package/dist/held.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { CutSession } from './cut.js';
1
2
  export type HeldRun = {
2
3
  runId: string;
3
4
  pid: number;
@@ -7,7 +8,9 @@ export type HeldRun = {
7
8
  scratch?: string[];
8
9
  engineGroup?: number;
9
10
  engineStartedAt?: number;
11
+ resume?: HeldResume;
10
12
  };
13
+ export type HeldResume = Omit<CutSession, 'runId' | 'worktree' | 'resetsAt' | 'cutAt' | 'keepUntil' | 'reason' | 'usage'>;
11
14
  export declare function heldDir(runnerDir: string): string;
12
15
  export declare function recordHeld(runnerDir: string, runId: string, pid?: number): void;
13
16
  export declare function updateHeld(runnerDir: string, runId: string, patch: Partial<Omit<HeldRun, 'runId' | 'pid' | 'claimedAt'>>): void;
package/dist/job.d.ts CHANGED
@@ -1,15 +1,38 @@
1
1
  import type { RunnerApi, ClaimedJob } from './api.js';
2
2
  import { type RunnerConfig } from './config.js';
3
3
  import type { SessionViewer } from './viewer.js';
4
- import type { UnattendedContext } from './engines/types.js';
4
+ import type { EngineId, UnattendedBlock, UnattendedContext } from './engines/types.js';
5
+ import { type SignInReport } from './sign-in.js';
6
+ import { type AccountProblem } from './engine-account.js';
5
7
  import { type LimitGate } from './limit.js';
8
+ import { type BranchHolder } from './worktrees.js';
6
9
  export declare function resolveRepoPath(repo: string | null | undefined, cfg: RunnerConfig): string | null;
7
10
  export declare function cloneDestination(repo: string, cfg: RunnerConfig): string | null;
8
11
  export declare function rememberRepoPath(repo: string, path: string, cfg: RunnerConfig): void;
9
12
  export declare function hasGh(cwd: string): Promise<boolean>;
10
- export declare function runJob(job: ClaimedJob, cfg: RunnerConfig, api: RunnerApi, viewer?: SessionViewer, opts?: {
13
+ export type RunJobOptions = {
11
14
  devServerPort?: number;
12
15
  limits?: LimitGate;
13
16
  now?: () => Date;
14
17
  unattended?: Partial<UnattendedContext>;
15
- }): Promise<void>;
18
+ heartbeatMs?: number;
19
+ account?: {
20
+ held: (engine: EngineId) => UnattendedBlock | null;
21
+ met: (engine: EngineId, code: AccountProblem, engineName: string) => void;
22
+ };
23
+ signIn?: () => SignInReport;
24
+ };
25
+ export declare function diskFullFailure(stderr: string, folder: string, free?: (dir: string) => number | null): {
26
+ error: string;
27
+ limit: {
28
+ kind: 'machine';
29
+ detail: string;
30
+ };
31
+ } | null;
32
+ export declare const STOPPED_HOLDER_WAIT_MS = 90000;
33
+ export declare function waitForStoppedHolder(runnerDir: string, worktree: string, holder: BranchHolder, deps?: {
34
+ sleep?: (ms: number) => Promise<void>;
35
+ waitMs?: number;
36
+ pollMs?: number;
37
+ }): Promise<BranchHolder | null>;
38
+ export declare function runJob(job: ClaimedJob, cfg: RunnerConfig, api: RunnerApi, viewer?: SessionViewer, opts?: RunJobOptions): Promise<void>;