@firefunc-agent/runner 0.7.1 → 0.9.3

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 (114) hide show
  1. package/LICENSE +7 -3
  2. package/README.md +296 -4
  3. package/dist/activity.d.ts +32 -0
  4. package/dist/activity.js +295 -0
  5. package/dist/api.d.ts +69 -1
  6. package/dist/api.js +114 -3
  7. package/dist/brief.d.ts +11 -0
  8. package/dist/brief.js +278 -0
  9. package/dist/build-info.json +4 -0
  10. package/dist/cli.js +59 -2
  11. package/dist/config.d.ts +7 -0
  12. package/dist/config.js +3 -0
  13. package/dist/cut.d.ts +45 -0
  14. package/dist/cut.js +105 -0
  15. package/dist/daemon.d.ts +16 -0
  16. package/dist/daemon.js +196 -7
  17. package/dist/declined.d.ts +11 -0
  18. package/dist/declined.js +27 -0
  19. package/dist/engines/antigravity.d.ts +2 -0
  20. package/dist/engines/antigravity.js +102 -0
  21. package/dist/engines/claude-budget.d.ts +1 -1
  22. package/dist/engines/claude-budget.js +2 -72
  23. package/dist/engines/claude.js +139 -2
  24. package/dist/engines/codex.js +10 -3
  25. package/dist/engines/copilot.d.ts +2 -0
  26. package/dist/engines/copilot.js +117 -0
  27. package/dist/engines/cursor.js +4 -0
  28. package/dist/engines/gemini.js +6 -1
  29. package/dist/engines/index.d.ts +2 -0
  30. package/dist/engines/index.js +22 -4
  31. package/dist/engines/types.d.ts +12 -1
  32. package/dist/exec.d.ts +3 -0
  33. package/dist/exec.js +48 -5
  34. package/dist/firefunc/agents.d.ts +2 -0
  35. package/dist/firefunc/agents.js +343 -0
  36. package/dist/firefunc/args.d.ts +18 -0
  37. package/dist/firefunc/args.js +82 -0
  38. package/dist/firefunc/auth.d.ts +21 -0
  39. package/dist/firefunc/auth.js +129 -0
  40. package/dist/firefunc/catalog.d.ts +10 -0
  41. package/dist/firefunc/catalog.js +201 -0
  42. package/dist/firefunc/cli.d.ts +2 -0
  43. package/dist/firefunc/cli.js +24 -0
  44. package/dist/firefunc/client.d.ts +36 -0
  45. package/dist/firefunc/client.js +177 -0
  46. package/dist/firefunc/command.d.ts +28 -0
  47. package/dist/firefunc/command.js +35 -0
  48. package/dist/firefunc/config.d.ts +29 -0
  49. package/dist/firefunc/config.js +111 -0
  50. package/dist/firefunc/configure.d.ts +6 -0
  51. package/dist/firefunc/configure.js +409 -0
  52. package/dist/firefunc/io.d.ts +25 -0
  53. package/dist/firefunc/io.js +14 -0
  54. package/dist/firefunc/main.d.ts +4 -0
  55. package/dist/firefunc/main.js +259 -0
  56. package/dist/firefunc/output.d.ts +29 -0
  57. package/dist/firefunc/output.js +131 -0
  58. package/dist/firefunc/prompt.d.ts +14 -0
  59. package/dist/firefunc/prompt.js +58 -0
  60. package/dist/firefunc/skill.d.ts +3 -0
  61. package/dist/firefunc/skill.js +80 -0
  62. package/dist/firefunc/tasks.d.ts +2 -0
  63. package/dist/firefunc/tasks.js +279 -0
  64. package/dist/firefunc/version.d.ts +2 -0
  65. package/dist/firefunc/version.js +8 -0
  66. package/dist/git-auth.d.ts +4 -1
  67. package/dist/git-auth.js +6 -2
  68. package/dist/held.d.ts +18 -0
  69. package/dist/held.js +95 -0
  70. package/dist/job.d.ts +3 -0
  71. package/dist/job.js +818 -102
  72. package/dist/keep-local.d.ts +12 -0
  73. package/dist/keep-local.js +651 -0
  74. package/dist/limit.d.ts +30 -0
  75. package/dist/limit.js +258 -0
  76. package/dist/locks.d.ts +14 -0
  77. package/dist/locks.js +164 -0
  78. package/dist/machine-logins.d.ts +19 -0
  79. package/dist/machine-logins.js +187 -0
  80. package/dist/mcp-login.d.ts +24 -0
  81. package/dist/mcp-login.js +993 -0
  82. package/dist/mcp-proxy.d.ts +21 -0
  83. package/dist/mcp-proxy.js +180 -0
  84. package/dist/mcp.d.ts +62 -0
  85. package/dist/mcp.js +611 -0
  86. package/dist/network.d.ts +20 -0
  87. package/dist/network.js +76 -0
  88. package/dist/orphans.d.ts +40 -0
  89. package/dist/orphans.js +235 -0
  90. package/dist/pending.d.ts +14 -0
  91. package/dist/pending.js +56 -0
  92. package/dist/pool.d.ts +7 -0
  93. package/dist/pool.js +57 -9
  94. package/dist/pr-title.d.ts +11 -0
  95. package/dist/pr-title.js +63 -0
  96. package/dist/recover.d.ts +10 -0
  97. package/dist/recover.js +104 -0
  98. package/dist/secret-scan.d.ts +19 -0
  99. package/dist/secret-scan.js +161 -0
  100. package/dist/session-stream.d.ts +9 -1
  101. package/dist/session-stream.js +20 -2
  102. package/dist/skills.d.ts +11 -0
  103. package/dist/skills.js +164 -0
  104. package/dist/stopped.d.ts +3 -0
  105. package/dist/stopped.js +10 -0
  106. package/dist/usage.d.ts +49 -0
  107. package/dist/usage.js +389 -0
  108. package/dist/version.d.ts +1 -0
  109. package/dist/version.js +17 -0
  110. package/dist/viewer.js +7 -1
  111. package/dist/worktrees.d.ts +15 -0
  112. package/dist/worktrees.js +96 -0
  113. package/package.json +8 -5
  114. package/skill/firefunc/SKILL.md +222 -0
package/dist/usage.js ADDED
@@ -0,0 +1,389 @@
1
+ const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
2
+ const count = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : undefined;
3
+ const plus = (a, b) => a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);
4
+ function tidy(o) {
5
+ for (const k of Object.keys(o))
6
+ if (o[k] === undefined)
7
+ delete o[k];
8
+ return o;
9
+ }
10
+ function modelLine(raw) {
11
+ if (!isObj(raw))
12
+ return null;
13
+ const input = count(raw.inputTokens);
14
+ const output = count(raw.outputTokens);
15
+ if (input === undefined || output === undefined)
16
+ return null;
17
+ const basis = raw.costBasis === undefined || raw.costBasis === 'list'
18
+ ? 'list'
19
+ : raw.costBasis === 'managed'
20
+ ? 'managed'
21
+ : 'unknown';
22
+ return {
23
+ line: tidy({
24
+ input_tokens: input,
25
+ output_tokens: output,
26
+ cache_creation_input_tokens: count(raw.cacheCreationInputTokens),
27
+ cache_read_input_tokens: count(raw.cacheReadInputTokens),
28
+ thinking_tokens: count(raw.thinkingTokens),
29
+ cost_usd: count(raw.costUSD),
30
+ }),
31
+ basis,
32
+ provider: raw.provider,
33
+ };
34
+ }
35
+ function runBasis(bases) {
36
+ if (bases.includes('unknown'))
37
+ return 'unknown';
38
+ const managed = bases.filter((b) => b === 'managed').length;
39
+ if (managed === 0)
40
+ return 'list';
41
+ return managed === bases.length ? 'managed' : 'mixed';
42
+ }
43
+ function reportCounts(ev) {
44
+ const out = [ev.total_cost_usd];
45
+ if (isObj(ev.usage)) {
46
+ const u = ev.usage;
47
+ out.push(u.input_tokens, u.output_tokens, u.cache_creation_input_tokens, u.cache_read_input_tokens);
48
+ }
49
+ if (isObj(ev.modelUsage)) {
50
+ for (const m of Object.values(ev.modelUsage)) {
51
+ if (!isObj(m))
52
+ continue;
53
+ out.push(m.inputTokens, m.outputTokens, m.cacheCreationInputTokens, m.cacheReadInputTokens, m.costUSD);
54
+ }
55
+ }
56
+ return out.filter((v) => typeof v === 'number');
57
+ }
58
+ function isZeroedCrash(ev) {
59
+ return ev.subtype === 'error_during_execution' && reportCounts(ev).every((v) => v === 0);
60
+ }
61
+ function sumModels(models) {
62
+ let acc = { input_tokens: 0, output_tokens: 0 };
63
+ for (const m of models)
64
+ acc = addModel(acc, m);
65
+ return acc;
66
+ }
67
+ function addModel(a, b) {
68
+ return tidy({
69
+ input_tokens: a.input_tokens + b.input_tokens,
70
+ output_tokens: a.output_tokens + b.output_tokens,
71
+ cache_creation_input_tokens: plus(a.cache_creation_input_tokens, b.cache_creation_input_tokens),
72
+ cache_read_input_tokens: plus(a.cache_read_input_tokens, b.cache_read_input_tokens),
73
+ thinking_tokens: plus(a.thinking_tokens, b.thinking_tokens),
74
+ cost_usd: plus(a.cost_usd, b.cost_usd),
75
+ });
76
+ }
77
+ export function readClaudeUsage(stdout) {
78
+ try {
79
+ let result = null;
80
+ const stretches = [];
81
+ let crashedAfter = false;
82
+ let floor = false;
83
+ let overage = false;
84
+ let apiKeySource;
85
+ let version;
86
+ const first = {
87
+ five_hour: undefined,
88
+ seven_day: undefined,
89
+ };
90
+ const last = { ...first };
91
+ for (const line of stdout.split('\n')) {
92
+ const t = line.trim();
93
+ if (!t.startsWith('{'))
94
+ continue;
95
+ if (!t.includes('"result"') && !t.includes('rate_limit_event') && !t.includes('"init"'))
96
+ continue;
97
+ let ev;
98
+ try {
99
+ ev = JSON.parse(t);
100
+ }
101
+ catch {
102
+ continue;
103
+ }
104
+ if (!isObj(ev))
105
+ continue;
106
+ if (ev.type === 'result') {
107
+ if (isZeroedCrash(ev)) {
108
+ crashedAfter = true;
109
+ }
110
+ else {
111
+ result = ev;
112
+ stretches.push(ev);
113
+ crashedAfter = false;
114
+ }
115
+ }
116
+ else if (ev.type === 'system' && ev.subtype === 'init') {
117
+ apiKeySource = ev.apiKeySource;
118
+ version = ev.claude_code_version;
119
+ }
120
+ else if (ev.type === 'rate_limit_event' && isObj(ev.rate_limit_info)) {
121
+ const info = ev.rate_limit_info;
122
+ if (info.isUsingOverage === true || info.overageInUse === true)
123
+ overage = true;
124
+ const kind = info.rateLimitType ?? info.rate_limit_type;
125
+ const u = count(info.utilization);
126
+ if ((kind === 'five_hour' || kind === 'seven_day') && u !== undefined && u <= 1) {
127
+ const pct = Math.round(u * 1000) / 10;
128
+ if (first[kind] === undefined)
129
+ first[kind] = pct;
130
+ last[kind] = pct;
131
+ }
132
+ }
133
+ }
134
+ if (!result)
135
+ return null;
136
+ const lines = [];
137
+ if (isObj(result.modelUsage)) {
138
+ for (const [id, raw] of Object.entries(result.modelUsage)) {
139
+ const m = modelLine(raw);
140
+ if (m)
141
+ lines.push([id, m]);
142
+ }
143
+ }
144
+ const basis = lines.length > 0 ? runBasis(lines.map(([, m]) => m.basis)) : 'list';
145
+ const priced = basis === 'list' || basis === 'managed';
146
+ const models = {};
147
+ for (const [id, m] of lines) {
148
+ const keep = m.basis === 'list' || (m.basis === 'managed' && basis === 'managed');
149
+ models[id] = keep ? m.line : tidy({ ...m.line, cost_usd: undefined });
150
+ }
151
+ const perModel = Object.values(models);
152
+ let totals;
153
+ const s = sumModels(perModel);
154
+ if (perModel.length > 0) {
155
+ totals = tidy({
156
+ input_tokens: s.input_tokens,
157
+ output_tokens: s.output_tokens,
158
+ cache_creation_input_tokens: s.cache_creation_input_tokens,
159
+ cache_read_input_tokens: s.cache_read_input_tokens,
160
+ thinking_tokens: s.thinking_tokens,
161
+ });
162
+ }
163
+ else {
164
+ let loop = null;
165
+ let unreadStretch = false;
166
+ for (const r of stretches) {
167
+ const u = isObj(r.usage) ? r.usage : null;
168
+ const input = count(u?.input_tokens);
169
+ const output = count(u?.output_tokens);
170
+ if (input === undefined || output === undefined) {
171
+ unreadStretch = true;
172
+ continue;
173
+ }
174
+ const details = isObj(u?.output_tokens_details) ? u.output_tokens_details : null;
175
+ const line = tidy({
176
+ input_tokens: input,
177
+ output_tokens: output,
178
+ cache_creation_input_tokens: count(u?.cache_creation_input_tokens),
179
+ cache_read_input_tokens: count(u?.cache_read_input_tokens),
180
+ thinking_tokens: count(details?.thinking_tokens),
181
+ });
182
+ loop = loop ? addModel(loop, line) : line;
183
+ }
184
+ if (!loop)
185
+ return null;
186
+ if (unreadStretch)
187
+ floor = true;
188
+ totals = tidy({
189
+ input_tokens: loop.input_tokens,
190
+ output_tokens: loop.output_tokens,
191
+ cache_creation_input_tokens: loop.cache_creation_input_tokens,
192
+ cache_read_input_tokens: loop.cache_read_input_tokens,
193
+ thinking_tokens: loop.thinking_tokens,
194
+ });
195
+ }
196
+ const stretchSum = (k) => stretches.reduce((acc, r) => plus(acc, count(r[k])), undefined);
197
+ const limits = tidy({
198
+ five_hour_pct_before: first.five_hour,
199
+ five_hour_pct_after: last.five_hour,
200
+ weekly_pct_before: first.seven_day,
201
+ weekly_pct_after: last.seven_day,
202
+ });
203
+ const firstParty = lines.length > 0 && lines.every(([, m]) => m.provider === 'firstParty');
204
+ return tidy({
205
+ ...totals,
206
+ total_cost_usd: priced ? (count(result.total_cost_usd) ?? s.cost_usd) : undefined,
207
+ cost_basis: priced && basis === 'managed' ? 'managed' : undefined,
208
+ num_turns: stretchSum('num_turns'),
209
+ duration_ms: stretchSum('duration_ms'),
210
+ duration_api_ms: count(result.duration_api_ms),
211
+ models: perModel.length > 0 ? models : undefined,
212
+ auth: apiKeySource === 'none'
213
+ ? firstParty
214
+ ? 'subscription'
215
+ : undefined
216
+ : typeof apiKeySource === 'string' && apiKeySource
217
+ ? 'api_key'
218
+ : undefined,
219
+ overage: overage ? true : undefined,
220
+ engine_version: typeof version === 'string' && version ? version : undefined,
221
+ sessions: 1,
222
+ incomplete: crashedAfter || floor ? true : undefined,
223
+ limits: Object.keys(limits).length > 0
224
+ ? { ...limits, source: 'rate_limit_event' }
225
+ : undefined,
226
+ });
227
+ }
228
+ catch {
229
+ return null;
230
+ }
231
+ }
232
+ export function combineUsage(sessions) {
233
+ const read = sessions.filter((s) => s !== null);
234
+ if (read.length === 0)
235
+ return null;
236
+ if (read.length === 1 && sessions.length === 1)
237
+ return read[0];
238
+ const models = {};
239
+ for (const s of read) {
240
+ for (const [id, m] of Object.entries(s.models ?? {})) {
241
+ models[id] = models[id] ? addModel(models[id], m) : m;
242
+ }
243
+ }
244
+ const withLimits = read.filter((s) => s.limits);
245
+ const firstL = withLimits[0]?.limits;
246
+ const lastL = withLimits[withLimits.length - 1]?.limits;
247
+ const limits = tidy({
248
+ five_hour_pct_before: firstL?.five_hour_pct_before,
249
+ five_hour_pct_after: lastL?.five_hour_pct_after,
250
+ weekly_pct_before: firstL?.weekly_pct_before,
251
+ weekly_pct_after: lastL?.weekly_pct_after,
252
+ });
253
+ const sum = (k) => read.reduce((acc, s) => plus(acc, s[k]), undefined);
254
+ const latest = read[read.length - 1];
255
+ const priced = read.every((s) => s.total_cost_usd !== undefined) &&
256
+ read.every((s) => s.cost_basis === latest.cost_basis);
257
+ return tidy({
258
+ input_tokens: sum('input_tokens') ?? 0,
259
+ output_tokens: sum('output_tokens') ?? 0,
260
+ cache_creation_input_tokens: sum('cache_creation_input_tokens'),
261
+ cache_read_input_tokens: sum('cache_read_input_tokens'),
262
+ thinking_tokens: sum('thinking_tokens'),
263
+ total_cost_usd: priced ? sum('total_cost_usd') : undefined,
264
+ cost_basis: priced ? latest.cost_basis : undefined,
265
+ num_turns: sum('num_turns'),
266
+ duration_ms: sum('duration_ms'),
267
+ duration_api_ms: sum('duration_api_ms'),
268
+ models: Object.keys(models).length > 0 ? models : undefined,
269
+ auth: latest.auth,
270
+ overage: read.some((s) => s.overage) ? true : undefined,
271
+ engine_version: latest.engine_version,
272
+ sessions: read.length,
273
+ incomplete: read.length < sessions.length || read.some((s) => s.incomplete) ? true : undefined,
274
+ limits: Object.keys(limits).length > 0
275
+ ? { ...limits, source: 'rate_limit_event' }
276
+ : undefined,
277
+ });
278
+ }
279
+ export function carriesEarlierSpend(u) {
280
+ if (!u.models || !u.engine_version)
281
+ return false;
282
+ const m = /^(\d+)\.(\d+)\.(\d+)/.exec(u.engine_version);
283
+ if (!m)
284
+ return false;
285
+ const [maj, min, pat] = [Number(m[1]), Number(m[2]), Number(m[3])];
286
+ return maj > 2 || (maj === 2 && (min > 1 || (min === 1 && pat >= 277)));
287
+ }
288
+ export function continueUsage(prev, next) {
289
+ if (!next)
290
+ return prev ? { ...prev, incomplete: true } : null;
291
+ if (!prev)
292
+ return { ...next, incomplete: true };
293
+ if (!carriesEarlierSpend(next))
294
+ return combineUsage([prev, next]);
295
+ const limits = tidy({
296
+ five_hour_pct_before: prev.limits?.five_hour_pct_before ?? next.limits?.five_hour_pct_before,
297
+ five_hour_pct_after: next.limits?.five_hour_pct_after ?? prev.limits?.five_hour_pct_after,
298
+ weekly_pct_before: prev.limits?.weekly_pct_before ?? next.limits?.weekly_pct_before,
299
+ weekly_pct_after: next.limits?.weekly_pct_after ?? prev.limits?.weekly_pct_after,
300
+ });
301
+ return tidy({
302
+ ...next,
303
+ num_turns: plus(prev.num_turns, next.num_turns),
304
+ duration_ms: plus(prev.duration_ms, next.duration_ms),
305
+ overage: prev.overage || next.overage ? true : undefined,
306
+ sessions: prev.sessions ?? 1,
307
+ incomplete: prev.incomplete || next.incomplete ? true : undefined,
308
+ limits: Object.keys(limits).length > 0
309
+ ? { ...limits, source: 'rate_limit_event' }
310
+ : undefined,
311
+ });
312
+ }
313
+ export function usageSince(next, baseline) {
314
+ if (!next || !carriesEarlierSpend(next))
315
+ return next;
316
+ if (!baseline)
317
+ return null;
318
+ const minus = (a, b) => a === undefined ? undefined : Math.max(0, a - (b ?? 0));
319
+ const models = {};
320
+ for (const [id, m] of Object.entries(next.models ?? {})) {
321
+ const was = baseline.models?.[id];
322
+ models[id] = tidy({
323
+ input_tokens: minus(m.input_tokens, was?.input_tokens) ?? 0,
324
+ output_tokens: minus(m.output_tokens, was?.output_tokens) ?? 0,
325
+ cache_creation_input_tokens: minus(m.cache_creation_input_tokens, was?.cache_creation_input_tokens),
326
+ cache_read_input_tokens: minus(m.cache_read_input_tokens, was?.cache_read_input_tokens),
327
+ thinking_tokens: minus(m.thinking_tokens, was?.thinking_tokens),
328
+ cost_usd: minus(m.cost_usd, was?.cost_usd),
329
+ });
330
+ }
331
+ const s = sumModels(Object.values(models));
332
+ return tidy({
333
+ ...next,
334
+ input_tokens: s.input_tokens,
335
+ output_tokens: s.output_tokens,
336
+ cache_creation_input_tokens: s.cache_creation_input_tokens,
337
+ cache_read_input_tokens: s.cache_read_input_tokens,
338
+ thinking_tokens: s.thinking_tokens,
339
+ total_cost_usd: next.total_cost_usd !== undefined && baseline.total_cost_usd !== undefined
340
+ ? Math.max(0, next.total_cost_usd - baseline.total_cost_usd)
341
+ : undefined,
342
+ duration_api_ms: minus(next.duration_api_ms, baseline.duration_api_ms),
343
+ models,
344
+ });
345
+ }
346
+ export function attemptUsage(sessions, cut) {
347
+ const groups = [];
348
+ for (const s of sessions) {
349
+ const own = cut && s.session === cut.session ? usageSince(s.usage, cut.baseline) : s.usage;
350
+ if (s.continued && groups.length > 0) {
351
+ groups[groups.length - 1] = continueUsage(groups[groups.length - 1] ?? null, own);
352
+ }
353
+ else {
354
+ groups.push(own);
355
+ }
356
+ }
357
+ return combineUsage(groups);
358
+ }
359
+ const n = (v) => Math.round(v).toLocaleString('en-US');
360
+ const secs = (ms) => {
361
+ const s = Math.round(ms / 1000);
362
+ return s >= 60 ? `${Math.floor(s / 60)}m${String(s % 60).padStart(2, '0')}s` : `${s}s`;
363
+ };
364
+ export function describeUsage(u) {
365
+ const total = u.input_tokens + u.output_tokens + (u.cache_creation_input_tokens ?? 0);
366
+ const parts = [
367
+ `${u.incomplete ? 'at least ' : ''}${n(total)} tokens (${n(u.input_tokens)} in · ${n(u.output_tokens)} out` +
368
+ `${u.cache_creation_input_tokens !== undefined ? ` · ${n(u.cache_creation_input_tokens)} cache written` : ''})` +
369
+ `${u.cache_read_input_tokens !== undefined ? ` + ${n(u.cache_read_input_tokens)} cache read` : ''}`,
370
+ ];
371
+ if (u.num_turns !== undefined)
372
+ parts.push(`${n(u.num_turns)} turns`);
373
+ if (u.duration_ms !== undefined)
374
+ parts.push(secs(u.duration_ms));
375
+ if (u.total_cost_usd !== undefined) {
376
+ const rate = u.cost_basis === 'managed' ? "at your organization's configured rates" : 'at API list prices';
377
+ const why = u.overage
378
+ ? " (the plan's extra usage was drawn on, so part of it may have been billed)"
379
+ : u.auth === 'subscription'
380
+ ? ' (a subscription run is not billed per token)'
381
+ : '';
382
+ parts.push(`≈$${u.total_cost_usd.toFixed(2)} ${rate}${why}`);
383
+ }
384
+ else if (u.overage) {
385
+ parts.push("the plan's extra usage was drawn on, so part of it may have been billed");
386
+ }
387
+ return parts.join(' · ');
388
+ }
389
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ export declare const RUNNER_VERSION: string;
@@ -0,0 +1,17 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ export const RUNNER_VERSION = (() => {
5
+ const here = dirname(fileURLToPath(import.meta.url));
6
+ for (const file of [join(here, 'build-info.json'), join(here, '..', 'package.json')]) {
7
+ try {
8
+ const v = JSON.parse(readFileSync(file, 'utf8')).version;
9
+ if (v)
10
+ return v;
11
+ }
12
+ catch {
13
+ }
14
+ }
15
+ return '0.0.0';
16
+ })();
17
+ //# sourceMappingURL=version.js.map
package/dist/viewer.js CHANGED
@@ -134,9 +134,15 @@ const SHELL_CSS = `
134
134
  .ln.sys{color:var(--dim)} .cur{display:inline-block;width:8px;height:15px;background:var(--accent);
135
135
  animation:b 1s steps(2) infinite;vertical-align:-2px}@keyframes b{50%{opacity:0}}
136
136
  a{color:var(--accent)}`;
137
+ const FAVICON = `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 50 50" fill="none">' +
138
+ '<style>.a{stroke:#211A12}.b{stroke:#9A5F3E}.c{fill:#9A5F3E}' +
139
+ '@media (prefers-color-scheme:dark){.a,.b{stroke:#F4F4F8}.c{fill:#F4F4F8}}</style>' +
140
+ '<path class="a" d="M6.71 12.25A16.615 16.615 0 0 0 6.71 35.75" stroke-width="4.8"/>' +
141
+ '<path class="b" d="M41.29 12.25A16.615 16.615 0 0 1 41.29 35.75" stroke-width="4.8"/>' +
142
+ '<circle class="c" cx="24" cy="24" r="5.4"/></svg>')}`;
137
143
  function page(title, inner, script = '') {
138
144
  return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
139
- <title>${esc(title)}</title><style>${SHELL_CSS}</style></head><body>${inner}<script>${script}</script></body></html>`;
145
+ <title>${esc(title)}</title><link rel="icon" href="${FAVICON}"><style>${SHELL_CSS}</style></head><body>${inner}<script>${script}</script></body></html>`;
140
146
  }
141
147
  function sessionHtml(runId, title) {
142
148
  const inner = `<div class="win"><div class="bar"><span class="dot r"></span><span class="dot y"></span><span class="dot g"></span>
@@ -0,0 +1,15 @@
1
+ export declare function canonicalPath(path: string): string;
2
+ export declare function isRunnerWorktree(path: string): boolean;
3
+ export type WorktreeEntry = {
4
+ path: string;
5
+ branch?: string;
6
+ head?: string;
7
+ };
8
+ export declare function worktreesOf(checkout: string): Promise<WorktreeEntry[]>;
9
+ export declare function staleHolder(stderr: string): string | null;
10
+ export declare function removeRunnerWorktree(checkout: string, path: string, log: (line: string) => void): Promise<void>;
11
+ export declare function sweepLeftoverWorktrees(checkouts: string[], opts: {
12
+ live: Set<string>;
13
+ keep: Set<string>;
14
+ log: (line: string) => void;
15
+ }): Promise<number>;
@@ -0,0 +1,96 @@
1
+ import { rmSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { basename, dirname } from 'node:path';
4
+ import { exec } from './exec.js';
5
+ import { killOrphans, reviewCopiesOf } from './orphans.js';
6
+ const RUNNER_WORKTREE_NAME = /^firefunc-[A-Za-z0-9]{6}$/;
7
+ function tempRoots() {
8
+ const t = tmpdir().replace(/\/+$/, '');
9
+ const out = new Set([t]);
10
+ if (t.startsWith('/private/'))
11
+ out.add(t.slice('/private'.length));
12
+ else if (t.startsWith('/var/'))
13
+ out.add(`/private${t}`);
14
+ out.add('/tmp');
15
+ out.add('/private/tmp');
16
+ return out;
17
+ }
18
+ export function canonicalPath(path) {
19
+ const clean = path.replace(/\/+$/, '');
20
+ return /^\/private\/(?:var|tmp)(?:\/|$)/.test(clean) ? clean.slice('/private'.length) : clean;
21
+ }
22
+ export function isRunnerWorktree(path) {
23
+ const clean = path.replace(/\/+$/, '');
24
+ return RUNNER_WORKTREE_NAME.test(basename(clean)) && tempRoots().has(dirname(clean));
25
+ }
26
+ export async function worktreesOf(checkout) {
27
+ const r = await exec('git', ['-C', checkout, 'worktree', 'list', '--porcelain'], {
28
+ timeoutMs: 30_000,
29
+ }).catch(() => null);
30
+ if (!r || r.code !== 0)
31
+ return [];
32
+ const out = [];
33
+ let cur = null;
34
+ for (const line of r.stdout.split('\n')) {
35
+ if (line.startsWith('worktree ')) {
36
+ cur = { path: line.slice('worktree '.length) };
37
+ out.push(cur);
38
+ }
39
+ else if (cur && line.startsWith('branch ')) {
40
+ cur.branch = line.slice('branch '.length).replace(/^refs\/heads\//, '');
41
+ }
42
+ else if (cur && line.startsWith('HEAD ')) {
43
+ cur.head = line.slice('HEAD '.length);
44
+ }
45
+ }
46
+ return out;
47
+ }
48
+ export function staleHolder(stderr) {
49
+ const m = /(?:already checked out at|used by worktree at|already used by worktree at)\s+'([^']+)'/.exec(stderr);
50
+ const path = m?.[1];
51
+ return path && isRunnerWorktree(path) ? path : null;
52
+ }
53
+ export async function removeRunnerWorktree(checkout, path, log) {
54
+ const copies = reviewCopiesOf(path);
55
+ await killOrphans({ roots: [path, ...copies], reviewCopiesOf: basename(path) }, { log }).catch(() => { });
56
+ const removed = await exec('git', ['-C', checkout, 'worktree', 'remove', '--force', path], {
57
+ timeoutMs: 120_000,
58
+ }).catch(() => null);
59
+ if (!removed || removed.code !== 0) {
60
+ try {
61
+ rmSync(path, { recursive: true, force: true });
62
+ }
63
+ catch {
64
+ }
65
+ await exec('git', ['-C', checkout, 'worktree', 'prune'], { timeoutMs: 60_000 }).catch(() => { });
66
+ }
67
+ for (const c of copies) {
68
+ try {
69
+ rmSync(c, { recursive: true, force: true });
70
+ }
71
+ catch {
72
+ }
73
+ }
74
+ }
75
+ export async function sweepLeftoverWorktrees(checkouts, opts) {
76
+ let removed = 0;
77
+ const spare = new Set([...opts.live, ...opts.keep].map(canonicalPath));
78
+ for (const checkout of new Set(checkouts)) {
79
+ try {
80
+ await exec('git', ['-C', checkout, 'worktree', 'prune'], { timeoutMs: 60_000 }).catch(() => { });
81
+ for (const wt of await worktreesOf(checkout)) {
82
+ if (!isRunnerWorktree(wt.path))
83
+ continue;
84
+ if (spare.has(canonicalPath(wt.path)))
85
+ continue;
86
+ opts.log(`removing a worktree a stopped runner left in ${checkout}: ${wt.path}${wt.branch ? ` (${wt.branch})` : ''}`);
87
+ await removeRunnerWorktree(checkout, wt.path, opts.log);
88
+ removed += 1;
89
+ }
90
+ }
91
+ catch {
92
+ }
93
+ }
94
+ return removed;
95
+ }
96
+ //# sourceMappingURL=worktrees.js.map
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@firefunc-agent/runner",
3
- "version": "0.7.1",
3
+ "version": "0.9.3",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "FireFunc self-hosted runner \u2014 an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",
6
+ "description": "FireFunc self-hosted runner — an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",
7
7
  "keywords": [
8
8
  "firefunc",
9
9
  "runner",
@@ -17,11 +17,13 @@
17
17
  ],
18
18
  "license": "SEE LICENSE IN LICENSE",
19
19
  "bin": {
20
- "firefunc-runner": "./dist/cli.js"
20
+ "firefunc-runner": "./dist/cli.js",
21
+ "firefunc": "./dist/firefunc/cli.js"
21
22
  },
22
23
  "files": [
23
24
  "dist",
24
25
  "!dist/**/*.map",
26
+ "skill",
25
27
  "README.md",
26
28
  "LICENSE"
27
29
  ],
@@ -33,9 +35,10 @@
33
35
  },
34
36
  "scripts": {
35
37
  "dev": "tsx src/cli.ts",
38
+ "firefunc": "tsx src/firefunc/cli.ts",
36
39
  "start": "tsx src/cli.ts start",
37
- "build": "npm run clean && tsc -p .",
38
- "prepack": "npm run build && node -e \"const{existsSync}=require('fs');if(!existsSync('dist/cli.js')){console.error('dist/cli.js is missing \u2014 refusing to pack a package with no code in it');process.exit(1)}\"",
40
+ "build": "npm run clean && tsc -p . && node scripts/stamp-build.mjs",
41
+ "prepack": "npm run build && node -e \"const{existsSync}=require('fs');for(const f of ['dist/cli.js','dist/firefunc/cli.js','skill/firefunc/SKILL.md']){if(!existsSync(f)){console.error(f+' is missing — refusing to pack a package without it');process.exit(1)}}\"",
39
42
  "lint": "echo '[runner] lint TBD'",
40
43
  "typecheck": "tsc -p . --noEmit",
41
44
  "test": "vitest run --passWithNoTests",