@firefunc-agent/runner 0.9.37 → 0.9.40

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 (70) hide show
  1. package/README.md +21 -0
  2. package/dist/activity.d.ts +2 -0
  3. package/dist/activity.js +3 -0
  4. package/dist/alive.d.ts +8 -0
  5. package/dist/alive.js +29 -0
  6. package/dist/api.d.ts +32 -0
  7. package/dist/api.js +18 -2
  8. package/dist/ask-replace.d.ts +6 -0
  9. package/dist/ask-replace.js +49 -0
  10. package/dist/awake-timer.d.ts +8 -0
  11. package/dist/awake-timer.js +30 -0
  12. package/dist/brief.js +2 -2
  13. package/dist/build-info.json +2 -2
  14. package/dist/clean-up.d.ts +29 -0
  15. package/dist/clean-up.js +131 -0
  16. package/dist/cli.js +57 -6
  17. package/dist/config.d.ts +7 -0
  18. package/dist/cut.d.ts +2 -0
  19. package/dist/cut.js +20 -3
  20. package/dist/daemon.js +115 -5
  21. package/dist/disk-reclaim.d.ts +40 -0
  22. package/dist/disk-reclaim.js +95 -0
  23. package/dist/drives.d.ts +29 -0
  24. package/dist/drives.js +270 -0
  25. package/dist/engine-account.d.ts +1 -1
  26. package/dist/engine-account.js +12 -1
  27. package/dist/engines/types.d.ts +1 -1
  28. package/dist/exec.js +5 -6
  29. package/dist/firefunc/automations.js +3 -3
  30. package/dist/firefunc/main.js +1 -1
  31. package/dist/firefunc/oauth-login.js +1 -1
  32. package/dist/gh-repos.d.ts +41 -0
  33. package/dist/gh-repos.js +68 -0
  34. package/dist/git-auth.d.ts +1 -0
  35. package/dist/git-auth.js +1 -1
  36. package/dist/held.d.ts +4 -2
  37. package/dist/held.js +19 -5
  38. package/dist/job.d.ts +1 -0
  39. package/dist/job.js +148 -33
  40. package/dist/keep-local.d.ts +1 -0
  41. package/dist/keep-local.js +63 -0
  42. package/dist/local-tools.d.ts +31 -0
  43. package/dist/local-tools.js +178 -0
  44. package/dist/machine-logins.d.ts +4 -0
  45. package/dist/machine-logins.js +31 -0
  46. package/dist/mcp-login.d.ts +3 -0
  47. package/dist/mcp-login.js +34 -4
  48. package/dist/mcp-tools.d.ts +23 -0
  49. package/dist/mcp-tools.js +122 -0
  50. package/dist/mcp.d.ts +8 -0
  51. package/dist/mcp.js +37 -3
  52. package/dist/pool.d.ts +1 -0
  53. package/dist/pool.js +1 -0
  54. package/dist/pr-title.d.ts +1 -0
  55. package/dist/pr-title.js +7 -0
  56. package/dist/repo-path.d.ts +15 -0
  57. package/dist/repo-path.js +56 -0
  58. package/dist/resources.d.ts +38 -0
  59. package/dist/resources.js +47 -1
  60. package/dist/restart-idle.d.ts +1 -0
  61. package/dist/restart-idle.js +20 -5
  62. package/dist/run-folders.d.ts +25 -0
  63. package/dist/run-folders.js +89 -0
  64. package/dist/viewer.d.ts +1 -1
  65. package/dist/viewer.js +3 -1
  66. package/dist/work-dir.d.ts +30 -0
  67. package/dist/work-dir.js +153 -22
  68. package/dist/worktrees.d.ts +7 -0
  69. package/dist/worktrees.js +26 -5
  70. package/package.json +1 -1
package/README.md CHANGED
@@ -621,6 +621,27 @@ and now says so: "[formatted text kept on the machine: read it in the run's sess
621
621
  To update: `npm install -g @firefunc-agent/runner@latest; firefunc-runner restart --when-idle`
622
622
  (PowerShell), or with `&&` in a POSIX shell.
623
623
 
624
+ ## Local tools on this machine (0.9.40)
625
+
626
+ An MCP server that lives on this machine, such as computer use, can be given to the runs of agents
627
+ granted it by name. Only you add one, here:
628
+
629
+ ```bash
630
+ firefunc-runner mcp add windows-mcp -- uvx windows-mcp serve
631
+ firefunc-runner mcp list
632
+ firefunc-runner mcp remove windows-mcp
633
+ ```
634
+
635
+ - **What leaves this machine:** only its name, on the heartbeat. The command, its arguments and any
636
+ `--env NAME=value` stay in this runner's config file (mode 0600).
637
+ - **When a run gets it:** only when its agent is granted that name in FireFunc. A granted name this
638
+ machine lacks is named in the run's brief.
639
+ - **Engine:** Claude Code runs only. The server is added to the run's `--mcp-config`, allowed whole.
640
+ - **What is recorded:** each call is a step on the run's trail by tool name, never its arguments or
641
+ its answer.
642
+
643
+ FireFunc cannot add, change or start one.
644
+
624
645
  ## Licence
625
646
 
626
647
  `@firefunc-agent/runner` is the **client** half of FireFunc, published so the machines
@@ -15,6 +15,7 @@ export declare function stepOf(ev: SessionEvent, ctx: {
15
15
  seq: number;
16
16
  now: () => Date;
17
17
  writeTools?: ReadonlySet<string>;
18
+ localServers?: ReadonlySet<string>;
18
19
  }): ActivityStep | null;
19
20
  export declare function createActivityReporter(opts: {
20
21
  worktree: string;
@@ -23,6 +24,7 @@ export declare function createActivityReporter(opts: {
23
24
  cap?: number;
24
25
  now?: () => Date;
25
26
  writeTools?: ReadonlySet<string>;
27
+ localServers?: ReadonlySet<string>;
26
28
  holdMs?: number;
27
29
  seqStart?: number;
28
30
  }): {
package/dist/activity.js CHANGED
@@ -79,6 +79,7 @@ export function stepOf(ev, ctx) {
79
79
  const action = viaFireFunc ? viaFireFunc[2] : mcp.action;
80
80
  const server = TOOL_LABELS[tool] ?? tool;
81
81
  const write = ctx.writeTools?.has(name) === true;
82
+ const local = !viaFireFunc && ctx.localServers?.has(mcp.server) === true;
82
83
  return {
83
84
  ...base,
84
85
  kind: 'tool',
@@ -88,6 +89,7 @@ export function stepOf(ev, ctx) {
88
89
  action,
89
90
  ...(viaFireFunc ? { via: 'firefunc' } : {}),
90
91
  ...(write ? { write: true } : {}),
92
+ ...(local ? { local: true } : {}),
91
93
  },
92
94
  };
93
95
  }
@@ -216,6 +218,7 @@ export function createActivityReporter(opts) {
216
218
  seq: seq + 1,
217
219
  now,
218
220
  writeTools: opts.writeTools,
221
+ localServers: opts.localServers,
219
222
  });
220
223
  if (!step || !step.label.trim())
221
224
  return;
package/dist/alive.d.ts CHANGED
@@ -7,6 +7,7 @@ export type AliveRecord = {
7
7
  startedAt: string;
8
8
  seenAt: string;
9
9
  contactAt: string | null;
10
+ drainSeenAt?: string;
10
11
  transport?: {
11
12
  failingSince: string;
12
13
  failures: number;
@@ -38,3 +39,10 @@ export declare function liveRunnerWords(live: LiveRunner, opts: {
38
39
  logPath: string;
39
40
  os?: string | null;
40
41
  }): string;
42
+ export declare function otherRunnerWarning(rec: AliveRecord | null, opts?: {
43
+ selfPid?: number;
44
+ now?: number;
45
+ os?: string | null;
46
+ alive?: (pid: number) => boolean;
47
+ }): string[] | null;
48
+ export declare function viewerPortWords(port: number, message: string, other: AliveRecord | null, os: string | null): string;
package/dist/alive.js CHANGED
@@ -27,6 +27,7 @@ export function readAlive(runnerDir) {
27
27
  startedAt: typeof rec.startedAt === 'string' ? rec.startedAt : rec.seenAt,
28
28
  seenAt: rec.seenAt,
29
29
  contactAt: typeof rec.contactAt === 'string' ? rec.contactAt : null,
30
+ ...(typeof rec.drainSeenAt === 'string' ? { drainSeenAt: rec.drainSeenAt } : {}),
30
31
  ...(rec.transport &&
31
32
  typeof rec.transport.failingSince === 'string' &&
32
33
  Number.isInteger(rec.transport.failures) &&
@@ -135,4 +136,32 @@ export function liveRunnerWords(live, opts) {
135
136
  transportWords(r, now) +
136
137
  logs);
137
138
  }
139
+ export function otherRunnerWarning(rec, opts = {}) {
140
+ const now = opts.now ?? Date.now();
141
+ const live = liveRunner(rec, now, opts.alive);
142
+ if (live.state !== 'running' || live.rec.pid === (opts.selfPid ?? process.pid))
143
+ return null;
144
+ const r = live.rec;
145
+ const how = r.service ? 'started by the background service' : 'started by hand in a terminal';
146
+ const end = opts.os === 'win32' ? `taskkill /PID ${r.pid} /T /F` : `kill ${r.pid}`;
147
+ return [
148
+ `WARNING: another runner is already running on this machine — pid ${r.pid}` +
149
+ `${r.version ? `, runner ${r.version}` : ''}, ${how}${r.user ? ` as ${r.user}` : ''}, ` +
150
+ `since ${ago(r.startedAt, now)}.`,
151
+ 'Two runners on one machine take work side by side and the second cannot open the live viewer.',
152
+ `Keep one. To keep that one, stop this one (Ctrl+C, or end the service that started it). To keep this one, end the other: ${end}`,
153
+ ];
154
+ }
155
+ export function viewerPortWords(port, message, other, os) {
156
+ if (!/EADDRINUSE|address already in use/i.test(message)) {
157
+ return `session viewer could not start on :${port} (${message}) — set "viewerPort" or pass --no-viewer`;
158
+ }
159
+ if (other) {
160
+ return (`session viewer could not start: port ${port} is held by the other runner on this machine ` +
161
+ `(pid ${other.pid}). Keep one runner, or set "viewerPort" to another port.`);
162
+ }
163
+ const find = os === 'win32' ? `netstat -ano | findstr :${port}` : `lsof -i :${port}`;
164
+ return (`session viewer could not start: another program holds port ${port}. Find it with "${find}", ` +
165
+ `or set "viewerPort" to another port (or pass --no-viewer).`);
166
+ }
138
167
  //# sourceMappingURL=alive.js.map
package/dist/api.d.ts CHANGED
@@ -11,6 +11,7 @@ export type ClaimedJob = {
11
11
  prompt: string;
12
12
  repo: string | null;
13
13
  branch: string | null;
14
+ ticketKey?: string | null;
14
15
  toolsOnly?: boolean;
15
16
  checkpoint?: {
16
17
  ref: string;
@@ -37,7 +38,14 @@ export type ClaimedJob = {
37
38
  planApproved?: boolean;
38
39
  parkStep?: ParkStep;
39
40
  baseBranch?: string | null;
41
+ prDraft?: boolean;
42
+ localTools?: string[];
40
43
  externalId: string | null;
44
+ project?: {
45
+ id: string;
46
+ slug: string | null;
47
+ name: string | null;
48
+ } | null;
41
49
  title: string | null;
42
50
  type: string;
43
51
  engine?: string | null;
@@ -165,6 +173,11 @@ export type ResultPayload = ({
165
173
  usage?: RunUsage;
166
174
  limit?: PlanLimitReport | MachineLimitReport;
167
175
  readHead?: string;
176
+ session?: {
177
+ engine: string;
178
+ id: string | null;
179
+ continued: boolean;
180
+ };
168
181
  openCommandAtEnd?: true;
169
182
  lost?: true;
170
183
  release?: ReleaseReport;
@@ -206,6 +219,12 @@ export declare class RunnerApi {
206
219
  accountLabel: string | null;
207
220
  expiresAt: string | null;
208
221
  detail?: string;
222
+ tools?: Array<{
223
+ name: string;
224
+ readOnly: boolean | null;
225
+ destructive: boolean | null;
226
+ }>;
227
+ toolsListedAt?: string;
209
228
  }>;
210
229
  heldRuns?: string[];
211
230
  lostRuns?: string[];
@@ -256,13 +275,26 @@ export declare class RunnerApi {
256
275
  config(): Promise<{
257
276
  maxParallel: number;
258
277
  requiredCommands: string[] | null;
278
+ checkRepos: string[] | null;
259
279
  signInPrefs: SignInPrefs | null;
280
+ workRoot: string | null;
281
+ cleanUpRequestedAt: string | null;
260
282
  } | null>;
261
283
  gitCredential(runId: string): Promise<{
262
284
  token: string;
263
285
  expiresAt: string;
264
286
  repo: string;
265
287
  } | null>;
288
+ gitCredentialOrRefusal(runId: string): Promise<{
289
+ token: string;
290
+ expiresAt: string;
291
+ repo: string;
292
+ } | {
293
+ refused: {
294
+ reason: string;
295
+ fix: string;
296
+ };
297
+ } | null>;
266
298
  mcpCredential(runId: string, server: string): Promise<{
267
299
  token: string;
268
300
  expiresAt?: string;
package/dist/api.js CHANGED
@@ -265,7 +265,15 @@ export class RunnerApi {
265
265
  requiredCommands: Array.isArray(body.requiredCommands)
266
266
  ? body.requiredCommands.filter((c) => typeof c === 'string')
267
267
  : null,
268
+ checkRepos: Array.isArray(body.checkRepos)
269
+ ? body.checkRepos.filter((c) => typeof c === 'string')
270
+ : null,
268
271
  signInPrefs: parseSignInPrefs(body.signInPrefs),
272
+ workRoot: typeof body.workRoot === 'string' && body.workRoot.trim() ? body.workRoot.trim() : null,
273
+ cleanUpRequestedAt: typeof body.cleanUpRequestedAt === 'string' &&
274
+ Number.isFinite(Date.parse(body.cleanUpRequestedAt))
275
+ ? body.cleanUpRequestedAt
276
+ : null,
269
277
  };
270
278
  }
271
279
  catch {
@@ -273,14 +281,22 @@ export class RunnerApi {
273
281
  }
274
282
  }
275
283
  async gitCredential(runId) {
284
+ const got = await this.gitCredentialOrRefusal(runId);
285
+ return got && 'token' in got ? got : null;
286
+ }
287
+ async gitCredentialOrRefusal(runId) {
276
288
  try {
277
289
  const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/git-credential`, {
278
290
  method: 'POST',
279
291
  headers: { ...this.headers(), 'content-type': 'application/json' },
280
292
  body: '{}',
281
293
  });
282
- if (!res.ok)
283
- return null;
294
+ if (!res.ok) {
295
+ const body = (await res.json().catch(() => null));
296
+ return typeof body?.reason === 'string' && typeof body.fix === 'string'
297
+ ? { refused: { reason: body.reason.slice(0, 400), fix: body.fix.slice(0, 400) } }
298
+ : null;
299
+ }
284
300
  const body = (await res.json());
285
301
  if (!body.ok || !body.token || !body.repo)
286
302
  return null;
@@ -0,0 +1,6 @@
1
+ import type { Readable } from 'node:stream';
2
+ export declare function askToReplace(question: string, opts?: {
3
+ input?: Readable;
4
+ isTTY?: boolean;
5
+ ttyPath?: string | null;
6
+ }): Promise<boolean>;
@@ -0,0 +1,49 @@
1
+ import { openSync, closeSync } from 'node:fs';
2
+ import { ReadStream } from 'node:tty';
3
+ import { createInterface } from 'node:readline';
4
+ export async function askToReplace(question, opts = {}) {
5
+ let input = opts.input ?? null;
6
+ let fd = null;
7
+ if (!input) {
8
+ if (opts.isTTY ?? process.stdin.isTTY)
9
+ input = process.stdin;
10
+ else {
11
+ const path = opts.ttyPath !== undefined
12
+ ? opts.ttyPath
13
+ : process.platform === 'win32' || !process.stderr.isTTY
14
+ ? null
15
+ : '/dev/tty';
16
+ if (!path)
17
+ return false;
18
+ try {
19
+ fd = openSync(path, 'r');
20
+ input = new ReadStream(fd);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ }
27
+ const rl = createInterface({ input, output: process.stderr, terminal: false });
28
+ try {
29
+ const answer = await new Promise((resolve) => {
30
+ process.stderr.write(question);
31
+ rl.once('line', resolve);
32
+ rl.once('close', () => resolve(''));
33
+ });
34
+ return /^\s*y(es)?\s*$/i.test(answer);
35
+ }
36
+ finally {
37
+ rl.close();
38
+ if (fd !== null && input && input !== process.stdin)
39
+ input.destroy();
40
+ if (fd !== null) {
41
+ try {
42
+ closeSync(fd);
43
+ }
44
+ catch {
45
+ }
46
+ }
47
+ }
48
+ }
49
+ //# sourceMappingURL=ask-replace.js.map
@@ -0,0 +1,8 @@
1
+ export type AwakeTimer = {
2
+ cancel: () => void;
3
+ awakeMs: () => number;
4
+ };
5
+ export declare function awakeTimer(limitMs: number, onLimit: () => void, opts?: {
6
+ tickMs?: number;
7
+ now?: () => number;
8
+ }): AwakeTimer;
@@ -0,0 +1,30 @@
1
+ export function awakeTimer(limitMs, onLimit, opts = {}) {
2
+ const tickMs = opts.tickMs ?? 5_000;
3
+ const now = opts.now ?? Date.now;
4
+ let last = now();
5
+ let awake = 0;
6
+ let done = false;
7
+ const tick = () => {
8
+ if (done)
9
+ return;
10
+ const t = now();
11
+ const gap = t - last;
12
+ last = t;
13
+ awake += gap > tickMs * 3 ? tickMs : Math.max(0, gap);
14
+ if (awake >= limitMs) {
15
+ done = true;
16
+ clearInterval(handle);
17
+ onLimit();
18
+ }
19
+ };
20
+ const handle = setInterval(tick, tickMs);
21
+ handle.unref?.();
22
+ return {
23
+ cancel: () => {
24
+ done = true;
25
+ clearInterval(handle);
26
+ },
27
+ awakeMs: () => awake,
28
+ };
29
+ }
30
+ //# sourceMappingURL=awake-timer.js.map
package/dist/brief.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { mkdtempSync, rmSync, existsSync } from 'node:fs';
2
- import { setWorkDir, workRoot } from './work-dir.js';
2
+ import { scratchRoot, setWorkDir } from './work-dir.js';
3
3
  import { join } from 'node:path';
4
4
  import { exec, execOut } from './exec.js';
5
5
  import { resolveRepoPath } from './job.js';
@@ -102,7 +102,7 @@ export async function runBrief(repo, cfg) {
102
102
  base = head ? head.replace('refs/remotes/origin/', '') : 'main';
103
103
  }
104
104
  setWorkDir(cfg.workDir);
105
- worktree = mkdtempSync(join(workRoot(), 'firefunc-brief-'));
105
+ worktree = mkdtempSync(join(scratchRoot(), 'firefunc-brief-'));
106
106
  const add = await exec('git', ['-C', repoPath, 'worktree', 'add', '--force', '-B', branch, worktree, `origin/${base}`], { timeoutMs: 120_000 });
107
107
  if (add.code !== 0) {
108
108
  out(`git worktree add failed: ${add.stderr.slice(0, 300)}`);
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.9.37",
3
- "builtAt": "2026-11-25T09:12:28.905Z"
2
+ "version": "0.9.40",
3
+ "builtAt": "2026-11-27T20:54:51.815Z"
4
4
  }
@@ -0,0 +1,29 @@
1
+ export type CleanUpReport = {
2
+ at: string;
3
+ freedBytes: number;
4
+ };
5
+ export declare function lastCleanUp(): CleanUpReport | null;
6
+ export type RunFolder = {
7
+ path: string;
8
+ runId: string | null;
9
+ };
10
+ export declare function runFoldersIn(roots: readonly string[]): RunFolder[];
11
+ export type SweepDeps = {
12
+ roots?: readonly string[];
13
+ spare: ReadonlySet<string>;
14
+ liveRunIds: ReadonlySet<string>;
15
+ log?: (line: string) => void;
16
+ minAgeMs?: number;
17
+ now?: number;
18
+ size?: (dir: string) => Promise<number | null>;
19
+ };
20
+ export declare function sweepWorkRoot(deps: SweepDeps): Promise<{
21
+ removed: string[];
22
+ freedBytes: number;
23
+ }>;
24
+ export declare function cleanUpNow(deps: {
25
+ runnerDir: string;
26
+ checkouts: readonly string[];
27
+ holding?: Iterable<string>;
28
+ log?: (line: string) => void;
29
+ }): Promise<CleanUpReport>;
@@ -0,0 +1,131 @@
1
+ import { existsSync, readdirSync, rmdirSync, rmSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { keptWorktrees } from './cut.js';
4
+ import { dirBytes } from './drives.js';
5
+ import { heldByLiveProcesses, liveWorktrees } from './held.js';
6
+ import { RESERVED_FOLDERS, checkoutOfWorktree, runMarkerOf, GROUP_MARKER } from './run-folders.js';
7
+ import { removeRunTemp, staleRunTemps, tempRoot } from './run-temp.js';
8
+ import { runRoots, workRoots } from './work-dir.js';
9
+ import { canonicalPath, isLayoutRunFolder, removeRunnerWorktree, sweepLeftoverWorktrees, } from './worktrees.js';
10
+ let last = null;
11
+ export function lastCleanUp() {
12
+ return last;
13
+ }
14
+ export function runFoldersIn(roots) {
15
+ const out = [];
16
+ for (const root of new Set(roots)) {
17
+ for (const group of safeList(root)) {
18
+ if (!isGroup(group))
19
+ continue;
20
+ const g = join(root, group);
21
+ for (const name of safeList(g)) {
22
+ const p = join(g, name);
23
+ if (isLayoutRunFolder(p, { layoutRoots: [root] }))
24
+ out.push({ path: p, runId: runMarkerOf(p) });
25
+ }
26
+ }
27
+ }
28
+ return out;
29
+ }
30
+ const isGroup = (name) => !!name && !name.startsWith('.') && !RESERVED_FOLDERS.has(name.toLowerCase());
31
+ function safeList(dir) {
32
+ try {
33
+ return readdirSync(dir);
34
+ }
35
+ catch {
36
+ return [];
37
+ }
38
+ }
39
+ const isDir = (p) => {
40
+ try {
41
+ return statSync(p).isDirectory();
42
+ }
43
+ catch {
44
+ return false;
45
+ }
46
+ };
47
+ export async function sweepWorkRoot(deps) {
48
+ const roots = deps.roots ?? runRoots();
49
+ const spare = new Set([...deps.spare].map(canonicalPath));
50
+ const now = deps.now ?? Date.now();
51
+ const minAge = deps.minAgeMs ?? 2 * 60_000;
52
+ const size = deps.size ?? ((d) => dirBytes(d, 5_000));
53
+ const removed = [];
54
+ let freed = 0;
55
+ for (const f of runFoldersIn(roots)) {
56
+ try {
57
+ if (spare.has(canonicalPath(f.path)))
58
+ continue;
59
+ if (f.runId && deps.liveRunIds.has(f.runId))
60
+ continue;
61
+ if (now - statSync(f.path).mtimeMs < minAge)
62
+ continue;
63
+ const bytes = await size(f.path).catch(() => null);
64
+ const checkout = checkoutOfWorktree(f.path);
65
+ deps.log?.(`removing a run folder no run holds: ${f.path}`);
66
+ if (checkout && existsSync(checkout)) {
67
+ await removeRunnerWorktree(checkout, f.path, deps.log ?? (() => { }));
68
+ }
69
+ rmSync(f.path, { recursive: true, force: true });
70
+ if (!existsSync(f.path)) {
71
+ removed.push(f.path);
72
+ freed += bytes ?? 0;
73
+ }
74
+ }
75
+ catch {
76
+ }
77
+ }
78
+ for (const root of new Set(roots)) {
79
+ for (const group of safeList(root)) {
80
+ if (!isGroup(group))
81
+ continue;
82
+ const g = join(root, group);
83
+ const left = isDir(g) ? safeList(g) : null;
84
+ if (left && left.length === 1 && left[0] === GROUP_MARKER) {
85
+ try {
86
+ rmSync(join(g, GROUP_MARKER), { force: true });
87
+ rmdirSync(g);
88
+ }
89
+ catch {
90
+ }
91
+ }
92
+ }
93
+ const tmp = join(root, '_tmp');
94
+ for (const n of safeList(tmp)) {
95
+ const p = join(tmp, n);
96
+ if (isDir(p) && safeList(p).length === 0) {
97
+ try {
98
+ rmdirSync(p);
99
+ }
100
+ catch {
101
+ }
102
+ }
103
+ }
104
+ }
105
+ return { removed, freedBytes: freed };
106
+ }
107
+ export async function cleanUpNow(deps) {
108
+ const log = deps.log ?? (() => { });
109
+ let freed = 0;
110
+ try {
111
+ const live = liveWorktrees(deps.runnerDir);
112
+ const kept = keptWorktrees(deps.runnerDir);
113
+ const liveRunIds = new Set([...heldByLiveProcesses(deps.runnerDir), ...(deps.holding ?? [])]);
114
+ const r = await sweepWorkRoot({ spare: new Set([...live, ...kept]), liveRunIds, log });
115
+ freed += r.freedBytes;
116
+ if (r.removed.length)
117
+ log(`clean-up removed ${r.removed.length} run folder(s)`);
118
+ const checkouts = deps.checkouts.filter((p) => existsSync(p));
119
+ await sweepLeftoverWorktrees(checkouts, { live, keep: kept, log });
120
+ const stale = staleRunTemps([tempRoot(), ...workRoots()], live);
121
+ for (const dir of stale) {
122
+ freed += (await dirBytes(dir, 5_000).catch(() => null)) ?? 0;
123
+ removeRunTemp(dir);
124
+ }
125
+ }
126
+ catch {
127
+ }
128
+ last = { at: new Date().toISOString(), freedBytes: freed };
129
+ return last;
130
+ }
131
+ //# sourceMappingURL=clean-up.js.map
package/dist/cli.js CHANGED
@@ -1,19 +1,24 @@
1
1
  #!/usr/bin/env node
2
+ import { checkRepoPath } from './repo-path.js';
2
3
  import { configPath, drainSetting, expandHome, isDraining, loadConfig, runnerDir, saveConfig, editorsAllowed, } from './config.js';
3
4
  import { startDaemon } from './daemon.js';
5
+ import { askToReplace } from './ask-replace.js';
4
6
  import { restartWhenIdle } from './restart-idle.js';
5
7
  import { installedRunnerVersion, runQuiet, unknownWords, updateRunner } from './update.js';
6
8
  import { endLiveRunner, startRunner, stopRunner, versionGapWords, } from './live-runner.js';
7
9
  import { heldByLiveProcesses } from './held.js';
8
10
  import { runBrief } from './brief.js';
9
11
  import { runMcpList, runMcpLogin, runMcpLogout } from './mcp-login.js';
12
+ import { localToolsListing, runMcpAdd, runMcpRemove } from './local-tools.js';
10
13
  import { RUNNER_VERSION } from './version.js';
11
14
  import { availableEngines, getAdapter } from './engines/index.js';
12
15
  import { engineBlocks, unattendedContext } from './unattended.js';
13
16
  import { engineLoginBlock } from './engine-login.js';
14
17
  import { liveRunner, liveRunnerWords, pidAlive, readAlive } from './alive.js';
15
18
  import { newerRunnerLine, readLatestRunner } from './newer-runner.js';
16
- import { setWorkDir, workDirFailure, workDirWords } from './work-dir.js';
19
+ import { loadWorkspaceRoot, setWorkDir, setWorkspaceRoot, workDirFailure, workDirWords, workRootWords, } from './work-dir.js';
20
+ import { workRootReport } from './resources.js';
21
+ import { dirBytes } from './drives.js';
17
22
  import { diskOf } from './resources.js';
18
23
  import { currentPlatform, defaultServiceDeps, EPHEMERAL_INSTALL_MESSAGE, installService, isEphemeralInstall, readLogTail, renderLaunchdPlist, renderSystemdUnit, renderWindowsLauncher, renderWindowsTaskXml, serviceStatus, serviceWords, servicePaths, startService, stopService, uninstallService, } from './service.js';
19
24
  const HELP = `firefunc-runner — run YOUR local coding agent on work FireFunc routes to you.
@@ -151,6 +156,12 @@ this one, the newest event on the issue):
151
156
  rather than left waiting for a window that never opens.
152
157
  GitHub needs no login: FireFunc mints it a read-only, one-repo, one-hour token
153
158
  per run — narrower than any machine-wide sign-in could be.
159
+ mcp add <name> [--env NAME=value] -- <command…>
160
+ An MCP server that lives on THIS machine, such as computer use
161
+ (mcp add windows-mcp -- uvx windows-mcp serve). Only you can add it,
162
+ here; FireFunc sees its name and a run gets it only when its
163
+ agent is granted that name. Claude Code runs only.
164
+ mcp remove <name> Take a local tool away.
154
165
 
155
166
  Examples:
156
167
  firefunc-runner connect ffr_xxx --repos-dir ~/code
@@ -211,6 +222,14 @@ async function main() {
211
222
  claudeEnv[e.slice(0, i)] = e.slice(i + 1);
212
223
  }
213
224
  const existing = loadConfig();
225
+ if (existing &&
226
+ existing.token !== token &&
227
+ !f.force &&
228
+ (await askToReplace(`This machine is already paired${existing.name ? ` as "${existing.name}"` : ''} with another token.\n` +
229
+ `Replacing it pairs it with the new one; it keeps its repos and engine settings.\n` +
230
+ `Replace it? [y/N] `))) {
231
+ f.force = ['true'];
232
+ }
214
233
  if (existing && existing.token !== token && !f.force) {
215
234
  process.stderr.write(`This machine is already connected to FireFunc with a different runner token.\n\n` +
216
235
  `Connecting again would REPLACE that token, so this machine would stop\n` +
@@ -280,9 +299,15 @@ async function main() {
280
299
  process.exitCode = 1;
281
300
  return;
282
301
  }
283
- cfg.repos = { ...(cfg.repos ?? {}), [name]: expandHome(localPath) };
302
+ const checked = checkRepoPath(name, localPath);
303
+ if (!checked.ok) {
304
+ process.stderr.write(`Not mapped: ${checked.reason}\nFix: ${checked.fix}\n`);
305
+ process.exitCode = 1;
306
+ return;
307
+ }
308
+ cfg.repos = { ...(cfg.repos ?? {}), [name]: checked.path };
284
309
  saveConfig(cfg);
285
- process.stdout.write(`Mapped ${name} → ${localPath}\nRestart the runner to apply: firefunc-runner start\n`);
310
+ process.stdout.write(`Mapped ${name} → ${checked.path}\nThe runner uses it from its next job; no restart needed.\n`);
286
311
  return;
287
312
  }
288
313
  if (cmd === 'brief') {
@@ -309,6 +334,18 @@ async function main() {
309
334
  const tool = positional[1];
310
335
  if (sub === 'list') {
311
336
  runMcpList();
337
+ process.stdout.write(`\n${localToolsListing(loadConfig())}`);
338
+ return;
339
+ }
340
+ if (sub === 'add') {
341
+ const at = rest.indexOf('add');
342
+ if (!runMcpAdd(rest.slice(at + 1), (t) => process.stdout.write(t), (t) => process.stderr.write(t)))
343
+ process.exitCode = 1;
344
+ return;
345
+ }
346
+ if (sub === 'remove') {
347
+ if (!runMcpRemove(tool, (t) => process.stdout.write(t), (t) => process.stderr.write(t)))
348
+ process.exitCode = 1;
312
349
  return;
313
350
  }
314
351
  if (sub === 'login' || sub === 'logout') {
@@ -325,10 +362,12 @@ async function main() {
325
362
  await runMcpLogout(tool);
326
363
  return;
327
364
  }
328
- process.stderr.write(`Usage: firefunc-runner mcp <login|list|logout> [tool]\n` +
365
+ process.stderr.write(`Usage: firefunc-runner mcp <login|list|logout|add|remove> [tool]\n` +
329
366
  ` firefunc-runner mcp login jira sign THIS machine in to Jira's MCP server\n` +
330
- ` firefunc-runner mcp list what this machine is signed in to\n` +
331
- ` firefunc-runner mcp logout jira forget that sign-in\n`);
367
+ ` firefunc-runner mcp list what this machine is signed in to, and its local tools\n` +
368
+ ` firefunc-runner mcp logout jira forget that sign-in\n` +
369
+ ` firefunc-runner mcp add windows-mcp -- uvx windows-mcp a local MCP server granted agents may use\n` +
370
+ ` firefunc-runner mcp remove windows-mcp take it away\n`);
332
371
  process.exitCode = 1;
333
372
  return;
334
373
  }
@@ -423,6 +462,10 @@ async function main() {
423
462
  load: loadConfig,
424
463
  save: saveConfig,
425
464
  held: () => heldByLiveProcesses(runnerDir()),
465
+ drainSeen: () => {
466
+ const rec = readAlive(runnerDir());
467
+ return rec && pidAlive(rec.pid) ? (rec.drainSeenAt ?? null) : null;
468
+ },
426
469
  sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
427
470
  now: () => Date.now(),
428
471
  log: (line) => process.stdout.write(`${line}\n`),
@@ -455,6 +498,10 @@ async function main() {
455
498
  load: loadConfig,
456
499
  save: saveConfig,
457
500
  held: () => heldByLiveProcesses(runnerDir()),
501
+ drainSeen: () => {
502
+ const rec = readAlive(runnerDir());
503
+ return rec && pidAlive(rec.pid) ? (rec.drainSeenAt ?? null) : null;
504
+ },
458
505
  restart: async () => {
459
506
  const installed = (await serviceStatus(deps)).installed;
460
507
  if (!installed)
@@ -482,11 +529,15 @@ async function main() {
482
529
  return;
483
530
  }
484
531
  setWorkDir(cfg.workDir);
532
+ setWorkspaceRoot(loadWorkspaceRoot(runnerDir()));
485
533
  const workDirWhy = workDirFailure();
534
+ const rootSize = await dirBytes(workRootReport({ bytes: () => null }).path, 3_000).catch(() => null);
535
+ const rootLine = workRootWords(workRootReport({ bytes: () => rootSize }));
486
536
  process.stdout.write(`Connected to ${cfg.apiUrl}\n` +
487
537
  ` name: ${cfg.name ?? '(hostname)'}\n` +
488
538
  ` reposDir: ${cfg.reposDir ?? '(none)'}\n` +
489
539
  ` workDir: ${workDirWords(cfg.workDir, diskOf, workDirWhy)}\n` +
540
+ ` workRoot: ${rootLine}\n` +
490
541
  ` repos: ${cfg.repos ? Object.keys(cfg.repos).join(', ') : '(auto by name)'}\n` +
491
542
  ` engine: ${cfg.engine ?? 'claude_code'} (default; per-project setting wins)\n` +
492
543
  ` claudeBin: ${cfg.claudeBin ?? 'claude'}\n` +