@firefunc-agent/runner 0.9.36 → 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 (77) hide show
  1. package/README.md +32 -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 +141 -16
  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 +147 -6
  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/machines.js +20 -0
  31. package/dist/firefunc/main.js +1 -1
  32. package/dist/firefunc/oauth-login.js +1 -1
  33. package/dist/gh-repos.d.ts +41 -0
  34. package/dist/gh-repos.js +68 -0
  35. package/dist/git-auth.d.ts +1 -0
  36. package/dist/git-auth.js +1 -1
  37. package/dist/held.d.ts +4 -2
  38. package/dist/held.js +19 -5
  39. package/dist/job.d.ts +1 -0
  40. package/dist/job.js +148 -33
  41. package/dist/keep-local.d.ts +1 -0
  42. package/dist/keep-local.js +63 -0
  43. package/dist/live-runner.d.ts +47 -0
  44. package/dist/live-runner.js +109 -0
  45. package/dist/local-tools.d.ts +31 -0
  46. package/dist/local-tools.js +178 -0
  47. package/dist/machine-logins.d.ts +4 -0
  48. package/dist/machine-logins.js +31 -0
  49. package/dist/mcp-login.d.ts +3 -0
  50. package/dist/mcp-login.js +34 -4
  51. package/dist/mcp-tools.d.ts +23 -0
  52. package/dist/mcp-tools.js +122 -0
  53. package/dist/mcp.d.ts +8 -0
  54. package/dist/mcp.js +37 -3
  55. package/dist/newer-runner.d.ts +9 -0
  56. package/dist/newer-runner.js +38 -0
  57. package/dist/pool.d.ts +1 -0
  58. package/dist/pool.js +1 -0
  59. package/dist/pr-title.d.ts +1 -0
  60. package/dist/pr-title.js +7 -0
  61. package/dist/repo-path.d.ts +15 -0
  62. package/dist/repo-path.js +56 -0
  63. package/dist/resources.d.ts +38 -0
  64. package/dist/resources.js +47 -1
  65. package/dist/restart-idle.d.ts +1 -0
  66. package/dist/restart-idle.js +20 -5
  67. package/dist/run-folders.d.ts +25 -0
  68. package/dist/run-folders.js +89 -0
  69. package/dist/update.d.ts +41 -0
  70. package/dist/update.js +176 -0
  71. package/dist/viewer.d.ts +1 -1
  72. package/dist/viewer.js +3 -1
  73. package/dist/work-dir.d.ts +30 -0
  74. package/dist/work-dir.js +153 -22
  75. package/dist/worktrees.d.ts +7 -0
  76. package/dist/worktrees.js +26 -5
  77. package/package.json +1 -1
package/dist/update.js ADDED
@@ -0,0 +1,176 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { restartWhenIdle } from './restart-idle.js';
3
+ import { shellSafe } from './win-shell.js';
4
+ import { isNewer } from './newer-runner.js';
5
+ export const RUNNER_PACKAGE = '@firefunc-agent/runner';
6
+ export function installCommand(scriptPath, spec) {
7
+ if (/[\\/]pnpm[\\/]/i.test(scriptPath))
8
+ return { cmd: 'pnpm', args: ['add', '-g', spec] };
9
+ return { cmd: 'npm', args: ['install', '-g', spec] };
10
+ }
11
+ const tail = (s) => s.trim().split('\n').slice(-4).join(' ').slice(0, 400);
12
+ export async function updateRunner(d) {
13
+ const running = d.running?.() ?? null;
14
+ const from = running ?? d.current;
15
+ if (/[\\/]_npx[\\/]/.test(d.scriptPath)) {
16
+ return {
17
+ ok: false,
18
+ from,
19
+ to: null,
20
+ message: `This runner runs from npx’s temporary cache, so there is nothing installed to update. Install it once: npm install -g ${RUNNER_PACKAGE}@latest — then: firefunc-runner install`,
21
+ };
22
+ }
23
+ const latest = await d.latest();
24
+ if (!latest) {
25
+ return {
26
+ ok: false,
27
+ from,
28
+ to: null,
29
+ message: `Not updated: npm did not answer with the newest version (is this machine online, or behind a proxy npm cannot use?). Try again, or run: npm install -g ${RUNNER_PACKAGE}@latest`,
30
+ };
31
+ }
32
+ if (!isNewer(latest, d.current)) {
33
+ if (running && isNewer(d.current, running) && (await d.service.installed())) {
34
+ let failure = null;
35
+ const idle = await restartWhenIdle({
36
+ ...d,
37
+ restart: async () => {
38
+ const stopped = await d.service.stop();
39
+ if (!stopped.ok) {
40
+ failure = stopped.message;
41
+ return { ok: false, installed: true, message: stopped.message };
42
+ }
43
+ const started = await d.service.start(d.current);
44
+ if (!started.ok)
45
+ failure = started.message;
46
+ return { ok: started.ok, installed: true, message: started.message };
47
+ },
48
+ });
49
+ if (failure)
50
+ return { ok: false, from, to: null, message: `Not restarted: ${failure}` };
51
+ if (!idle.ok)
52
+ return { ok: false, from, to: null, message: `Not restarted. ${idle.message}` };
53
+ return {
54
+ ok: true,
55
+ from,
56
+ to: d.current,
57
+ message: `Updated ${from} → ${d.current}, restarted (${d.current} was installed; ${from} was still running).`,
58
+ };
59
+ }
60
+ return { ok: true, from, to: from, message: `Already on ${from}, the newest on npm.` };
61
+ }
62
+ const spec = `${RUNNER_PACKAGE}@${latest}`;
63
+ const how = installCommand(d.scriptPath, spec);
64
+ const install = async () => {
65
+ d.log(`installing ${spec}`);
66
+ return d.run(how.cmd, how.args).catch((err) => ({
67
+ code: -1,
68
+ output: err instanceof Error ? err.message : String(err),
69
+ }));
70
+ };
71
+ const failed = (res, after) => ({
72
+ ok: false,
73
+ from,
74
+ to: null,
75
+ message: `Not updated: ${how.cmd} ${how.args.join(' ')} failed (exit ${res.code})${tail(res.output) ? `: ${tail(res.output)}` : ''}. ${after} Fix what npm says (on Windows, run PowerShell as the account that installed the runner), then run firefunc-runner update again.`,
76
+ });
77
+ const checked = async (restarted) => {
78
+ const now = (await d.installedVersion()) ?? latest;
79
+ return {
80
+ ok: true,
81
+ from,
82
+ to: now,
83
+ message: restarted
84
+ ? `Updated ${from} → ${now}, restarted.`
85
+ : `Updated ${from} → ${now}. No service is installed, so restart the runner where it runs: stop it (Ctrl-C) and run firefunc-runner start.`,
86
+ };
87
+ };
88
+ if (!(await d.service.installed())) {
89
+ const res = await install();
90
+ if (res.code !== 0)
91
+ return failed(res, `It still runs ${from}.`);
92
+ return checked(false);
93
+ }
94
+ let result = null;
95
+ const idle = await restartWhenIdle({
96
+ ...d,
97
+ restart: async () => {
98
+ const stopped = await d.service.stop();
99
+ if (!stopped.ok) {
100
+ result = {
101
+ ok: false,
102
+ from,
103
+ to: null,
104
+ message: `Not updated: the service would not stop (${stopped.message}). Nothing was installed; the runner stays drained, so run firefunc-runner resume once it is stopped and started again.`,
105
+ };
106
+ return { ok: false, installed: true, message: result.message };
107
+ }
108
+ const res = await install();
109
+ const started = await d.service.start(latest);
110
+ if (res.code !== 0) {
111
+ result = failed(res, started.ok
112
+ ? `The service runs ${from} again.`
113
+ : `The service did not start again (${started.message}): run firefunc-runner start-service.`);
114
+ return { ok: started.ok, installed: true, message: result.message };
115
+ }
116
+ if (!started.ok) {
117
+ result = {
118
+ ok: false,
119
+ from,
120
+ to: latest,
121
+ message: `Installed ${latest}, but the service did not start (${started.message}). Run: firefunc-runner start-service — then firefunc-runner resume, as it stays drained.`,
122
+ };
123
+ return { ok: false, installed: true, message: result.message };
124
+ }
125
+ return { ok: true, installed: true, message: '' };
126
+ },
127
+ });
128
+ if (result)
129
+ return result;
130
+ if (!idle.ok)
131
+ return { ok: false, from, to: null, message: `Not updated. ${idle.message}` };
132
+ const done = await checked(true);
133
+ return /drained/.test(idle.message) && /stays drained/.test(idle.message)
134
+ ? {
135
+ ...done,
136
+ message: `${done.message} It was drained before, so it stays drained: run firefunc-runner resume to take work again.`,
137
+ }
138
+ : done;
139
+ }
140
+ export function unknownWords(args, known, withValue = ['--max-wait']) {
141
+ for (let i = 0; i < args.length; i += 1) {
142
+ const a = args[i];
143
+ if (!known.includes(a))
144
+ return a;
145
+ if (withValue.includes(a))
146
+ i += 1;
147
+ }
148
+ return null;
149
+ }
150
+ export function runQuiet(cmd, args) {
151
+ return new Promise((resolve) => {
152
+ const line = shellSafe(cmd, args, process.platform === 'win32');
153
+ const child = spawn(line.cmd, line.args, { shell: line.shell, windowsHide: true });
154
+ let output = '';
155
+ const keep = (b) => {
156
+ output = (output + b.toString('utf8')).slice(-4_000);
157
+ };
158
+ child.stdout?.on('data', keep);
159
+ child.stderr?.on('data', keep);
160
+ const timer = setTimeout(() => child.kill('SIGTERM'), 10 * 60_000);
161
+ child.on('error', (err) => {
162
+ clearTimeout(timer);
163
+ resolve({ code: -1, output: err.message });
164
+ });
165
+ child.on('close', (code) => {
166
+ clearTimeout(timer);
167
+ resolve({ code: code ?? -1, output });
168
+ });
169
+ });
170
+ }
171
+ export async function installedRunnerVersion() {
172
+ const res = await runQuiet('firefunc-runner', ['--version']);
173
+ const v = res.output.trim().split('\n').pop()?.trim() ?? '';
174
+ return res.code === 0 && /^\d+\.\d+\.\d+$/.test(v) ? v : null;
175
+ }
176
+ //# sourceMappingURL=update.js.map
package/dist/viewer.d.ts CHANGED
@@ -12,5 +12,5 @@ export type SessionViewer = {
12
12
  export declare function createSessionViewer(opts: {
13
13
  port?: number;
14
14
  onListen?: (url: string) => void;
15
- onError?: (msg: string) => void;
15
+ onError?: (msg: string, port: number) => void;
16
16
  }): SessionViewer;
package/dist/viewer.js CHANGED
@@ -51,7 +51,9 @@ export function createSessionViewer(opts) {
51
51
  });
52
52
  server.on('error', (err) => {
53
53
  url = null;
54
- opts.onError?.(`session viewer could not start on :${port} (${err.message})`);
54
+ opts.onError?.(err.code === 'EADDRINUSE'
55
+ ? `EADDRINUSE: ${err.message}`
56
+ : err.message, port);
55
57
  });
56
58
  server.listen(port, '127.0.0.1', () => {
57
59
  url = `http://127.0.0.1:${port}`;
@@ -1,11 +1,41 @@
1
+ export type WorkRootSource = 'local' | 'workspace' | 'default';
2
+ export type WorkRootCheck = {
3
+ root: string;
4
+ usable: boolean;
5
+ reason?: string;
6
+ fix?: string;
7
+ };
8
+ export declare function defaultWorkRoot(): string;
1
9
  export declare function setWorkDir(dir: string | null | undefined): void;
10
+ export declare function setWorkspaceRoot(root: string | null | undefined): boolean;
11
+ export declare function workspaceRoot(): string | null;
2
12
  export declare function workDir(): string | null;
13
+ export declare function workRootSource(): WorkRootSource;
14
+ export declare function chosenWorkRoot(): string;
15
+ export declare function checkRoot(root: string, source?: WorkRootSource, fresh?: boolean): WorkRootCheck;
16
+ export declare function workRootCheck(fresh?: boolean): WorkRootCheck;
3
17
  export declare function workRoot(): string;
4
18
  export declare function workDirFailure(): string | null;
5
19
  export declare function workDirProblem(): string | null;
20
+ export declare function workRootProblem(): string | null;
21
+ export declare function runRoots(): string[];
6
22
  export declare function workRoots(): string[];
7
23
  export declare function workTempEnv(): Record<string, string>;
24
+ export declare function scratchRoot(): string;
25
+ export declare function workspaceRootFile(runnerDir: string): string;
26
+ export declare function saveWorkspaceRoot(runnerDir: string, root: string | null): void;
27
+ export declare function loadWorkspaceRoot(runnerDir: string): string | null;
8
28
  export declare function workDirWords(dir: string | undefined, disk: (dir: string) => {
9
29
  freeBytes: number;
10
30
  totalBytes: number;
11
31
  } | null, problem?: string | null): string;
32
+ export declare function workRootWords(r: {
33
+ path: string;
34
+ usable: boolean;
35
+ reason?: string;
36
+ fix?: string;
37
+ bytes: number | null;
38
+ freeBytes: number | null;
39
+ source: WorkRootSource;
40
+ }): string;
41
+ export declare function isTooBroad(root: string): boolean;
package/dist/work-dir.js CHANGED
@@ -1,33 +1,103 @@
1
- import { mkdirSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
1
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { homedir, tmpdir } from 'node:os';
3
+ import { join, parse, resolve } from 'node:path';
4
4
  let configured = null;
5
- let problem = null;
5
+ let workspace = null;
6
+ const used = new Set();
7
+ const checks = new Map();
8
+ const CHECK_TTL_MS = 30_000;
9
+ const clean = (dir) => typeof dir === 'string' && dir.trim() ? dir.trim() : null;
10
+ export function defaultWorkRoot() {
11
+ return clean(process.env.FIREFUNC_WORK_ROOT) ?? join(homedir(), 'FireFunc');
12
+ }
6
13
  export function setWorkDir(dir) {
7
- configured = typeof dir === 'string' && dir.trim() ? dir.trim() : null;
8
- problem = null;
14
+ configured = clean(dir);
15
+ }
16
+ export function setWorkspaceRoot(root) {
17
+ const next = clean(root);
18
+ const changed = next !== workspace;
19
+ workspace = next;
20
+ return changed;
21
+ }
22
+ export function workspaceRoot() {
23
+ return workspace;
9
24
  }
10
25
  export function workDir() {
11
26
  return configured;
12
27
  }
13
- export function workRoot() {
14
- if (!configured)
15
- return tmpdir();
28
+ export function workRootSource() {
29
+ return configured ? 'local' : workspace ? 'workspace' : 'default';
30
+ }
31
+ export function chosenWorkRoot() {
32
+ return configured ?? workspace ?? defaultWorkRoot();
33
+ }
34
+ function fixFor(source) {
35
+ if (source === 'local') {
36
+ return 'Connect the drive or pick a folder this user can write, with connect --work-dir <dir>.';
37
+ }
38
+ if (source === 'workspace') {
39
+ return "Connect the drive or pick a folder this user can write in the machine's settings on FireFunc.";
40
+ }
41
+ return "Connect the drive or pick a folder this user can write, with connect --work-dir <dir>, or in the machine's settings on FireFunc.";
42
+ }
43
+ function plainReason(err, root) {
44
+ const e = err;
45
+ const code = e?.code;
46
+ if (code === 'EACCES' || code === 'EPERM')
47
+ return `this user may not write to ${root}`;
48
+ if (code === 'ENOENT')
49
+ return `${root} is on a drive or folder that is not there`;
50
+ if (code === 'ENOTDIR' || code === 'EEXIST')
51
+ return `a file is in the way of the folder ${root}`;
52
+ if (code === 'EROFS')
53
+ return `${root} is on a read-only drive`;
54
+ if (code === 'ENOSPC')
55
+ return `the drive holding ${root} is full`;
56
+ return e instanceof Error ? e.message : String(err);
57
+ }
58
+ export function checkRoot(root, source = workRootSource(), fresh = false) {
59
+ const seen = checks.get(root);
60
+ if (!fresh && seen && Date.now() - seen.at < CHECK_TTL_MS)
61
+ return seen.check;
62
+ let check;
63
+ if (isTooBroad(root)) {
64
+ check = {
65
+ root,
66
+ usable: false,
67
+ reason: `${root} is a whole drive or your home folder, not a folder of its own.`,
68
+ fix: `Pick a folder inside it, such as ${join(root, 'FireFunc')}.`,
69
+ };
70
+ checks.set(root, { at: Date.now(), check });
71
+ return check;
72
+ }
16
73
  try {
17
- mkdirSync(configured, { recursive: true });
18
- problem = null;
19
- return configured;
74
+ mkdirSync(root, { recursive: true });
75
+ const probe = join(root, `.firefunc-probe-${process.pid}`);
76
+ writeFileSync(probe, 'ok');
77
+ rmSync(probe, { force: true });
78
+ check = { root, usable: true };
20
79
  }
21
80
  catch (err) {
22
- problem = err instanceof Error ? err.message : String(err);
23
- return tmpdir();
81
+ check = { root, usable: false, reason: plainReason(err, root), fix: fixFor(source) };
24
82
  }
83
+ checks.set(root, { at: Date.now(), check });
84
+ return check;
85
+ }
86
+ export function workRootCheck(fresh = false) {
87
+ return checkRoot(chosenWorkRoot(), workRootSource(), fresh);
88
+ }
89
+ export function workRoot() {
90
+ const c = workRootCheck();
91
+ if (!c.usable)
92
+ return tmpdir();
93
+ used.add(c.root);
94
+ return c.root;
25
95
  }
26
96
  export function workDirFailure() {
27
97
  if (!configured)
28
98
  return null;
29
- workRoot();
30
- return problem;
99
+ const c = workRootCheck(true);
100
+ return c.usable ? null : (c.reason ?? 'it cannot be used');
31
101
  }
32
102
  export function workDirProblem() {
33
103
  const why = workDirFailure();
@@ -35,26 +105,65 @@ export function workDirProblem() {
35
105
  ? `the work folder ${configured} cannot be made (${why}), so runs work in the OS temp folder ${tmpdir()} instead. Fix: connect the drive or pick a folder this user can write, with connect --work-dir <dir>.`
36
106
  : null;
37
107
  }
108
+ export function workRootProblem() {
109
+ const c = workRootCheck(true);
110
+ return c.usable
111
+ ? null
112
+ : `the work folder ${c.root} (${workRootSource()}) cannot be used (${c.reason}), so runs work in the OS temp folder ${tmpdir()} instead. Fix: ${c.fix}`;
113
+ }
114
+ export function runRoots() {
115
+ const roots = [chosenWorkRoot(), defaultWorkRoot(), ...used];
116
+ if (configured)
117
+ roots.push(configured);
118
+ if (workspace)
119
+ roots.push(workspace);
120
+ return [...new Set(roots)];
121
+ }
38
122
  export function workRoots() {
39
123
  const roots = [tmpdir()];
40
- if (configured)
41
- roots.push(configured, join(configured, 'tmp'));
124
+ for (const r of runRoots())
125
+ roots.push(r, join(r, '_tmp'), join(r, 'tmp'));
42
126
  return [...new Set(roots)];
43
127
  }
44
128
  export function workTempEnv() {
45
- if (!configured)
129
+ const c = workRootCheck();
130
+ if (!c.usable)
46
131
  return {};
47
- const tmp = join(configured, 'tmp');
132
+ const tmp = join(c.root, '_tmp');
48
133
  try {
49
134
  mkdirSync(tmp, { recursive: true });
135
+ mkdirSync(join(c.root, '_cache'), { recursive: true });
50
136
  }
51
137
  catch {
52
138
  return {};
53
139
  }
140
+ used.add(c.root);
54
141
  return { TMPDIR: tmp, TEMP: tmp, TMP: tmp };
55
142
  }
143
+ export function scratchRoot() {
144
+ return workTempEnv().TMPDIR ?? workRoot();
145
+ }
146
+ export function workspaceRootFile(runnerDir) {
147
+ return join(runnerDir, 'work-root.json');
148
+ }
149
+ export function saveWorkspaceRoot(runnerDir, root) {
150
+ try {
151
+ writeFileSync(workspaceRootFile(runnerDir), JSON.stringify({ workRoot: clean(root) }));
152
+ }
153
+ catch {
154
+ }
155
+ }
156
+ export function loadWorkspaceRoot(runnerDir) {
157
+ try {
158
+ const v = JSON.parse(readFileSync(workspaceRootFile(runnerDir), 'utf8'));
159
+ return typeof v.workRoot === 'string' ? clean(v.workRoot) : null;
160
+ }
161
+ catch {
162
+ return null;
163
+ }
164
+ }
56
165
  export function workDirWords(dir, disk, problem = null) {
57
- const where = dir?.trim() ? dir.trim() : tmpdir();
166
+ const where = dir?.trim() ? dir.trim() : chosenWorkRoot();
58
167
  if (dir?.trim() && problem) {
59
168
  const t = disk(tmpdir());
60
169
  const tFree = t ? `${(t.freeBytes / 1024 ** 3).toFixed(1)} GB free` : 'free space unknown';
@@ -64,6 +173,28 @@ export function workDirWords(dir, disk, problem = null) {
64
173
  const free = d ? `${(d.freeBytes / 1024 ** 3).toFixed(1)} GB free` : 'free space unknown';
65
174
  return dir?.trim()
66
175
  ? `${where} (${free}) — worktrees and the engine's temp folder`
67
- : `${where} (${free}) — the OS temp folder; set one with connect --work-dir <dir>`;
176
+ : `${where} (${free}) — the ${workRootSource() === 'workspace' ? "workspace's" : 'default'} root; set one with connect --work-dir <dir>`;
177
+ }
178
+ export function workRootWords(r) {
179
+ const by = r.source === 'local'
180
+ ? "this machine's --work-dir"
181
+ : r.source === 'workspace'
182
+ ? "the workspace's setting"
183
+ : 'the default';
184
+ if (!r.usable) {
185
+ return `${r.path} (${by}) cannot be used: ${r.reason}. Runs work in the OS temp folder instead. Fix: ${r.fix}`;
186
+ }
187
+ const gb = (b) => `${(b / 1024 ** 3).toFixed(1)} GB`;
188
+ const size = r.bytes === null ? 'size not measured' : `holds ${gb(r.bytes)}`;
189
+ const free = r.freeBytes === null ? 'free space unknown' : `${gb(r.freeBytes)} free`;
190
+ return `${r.path} (${by}) — usable, ${size}, ${free}`;
191
+ }
192
+ export function isTooBroad(root) {
193
+ const r = resolve(root);
194
+ if (r === resolve(homedir()))
195
+ return true;
196
+ if (r === parse(r).root)
197
+ return true;
198
+ return /^\\\\[^\\]+\\[^\\]+\\?$/.test(r);
68
199
  }
69
200
  //# sourceMappingURL=work-dir.js.map
@@ -4,6 +4,13 @@ export declare function isRunnerWorktree(path: string, opts?: {
4
4
  platform?: NodeJS.Platform;
5
5
  tmp?: string;
6
6
  roots?: readonly string[];
7
+ layoutRoots?: readonly string[];
8
+ hasMarker?: (path: string) => boolean;
9
+ }): boolean;
10
+ export declare function isLayoutRunFolder(path: string, opts?: {
11
+ platform?: NodeJS.Platform;
12
+ layoutRoots?: readonly string[];
13
+ hasMarker?: (path: string) => boolean;
7
14
  }): boolean;
8
15
  export type WorktreeEntry = {
9
16
  path: string;
package/dist/worktrees.js CHANGED
@@ -1,7 +1,8 @@
1
- import { rmSync } from 'node:fs';
1
+ import { existsSync, rmSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
- import { workRoots } from './work-dir.js';
4
- import { basename } from 'node:path';
3
+ import { runRoots, workRoots } from './work-dir.js';
4
+ import { basename, join } from 'node:path';
5
+ import { RESERVED_FOLDERS, RUN_MARKER } from './run-folders.js';
5
6
  import { exec } from './exec.js';
6
7
  import { isAlive, killOrphans, reviewCopiesOf } from './orphans.js';
7
8
  import { listHeld } from './held.js';
@@ -34,8 +35,28 @@ export function isRunnerWorktree(path, opts = {}) {
34
35
  .replace(/[\\/]+$/, '')
35
36
  .split(/[\\/]/)
36
37
  .pop() ?? '';
37
- return (RUNNER_WORKTREE_NAME.test(name) &&
38
- tempRoots(platform, opts.tmp ?? tmpdir(), opts.roots ?? workRoots()).has(clean.slice(0, cut)));
38
+ if (RUNNER_WORKTREE_NAME.test(name) &&
39
+ tempRoots(platform, opts.tmp ?? tmpdir(), opts.roots ?? workRoots()).has(clean.slice(0, cut))) {
40
+ return true;
41
+ }
42
+ return isLayoutRunFolder(path, opts);
43
+ }
44
+ export function isLayoutRunFolder(path, opts = {}) {
45
+ const platform = opts.platform ?? process.platform;
46
+ const parts = canonicalPathOn(path, platform).split('/');
47
+ if (parts.length < 3)
48
+ return false;
49
+ const name = parts[parts.length - 1];
50
+ const group = parts[parts.length - 2];
51
+ const parent = parts.slice(0, -2).join('/');
52
+ if (!/^[A-Za-z0-9._-]+$/.test(name) || name.startsWith('.'))
53
+ return false;
54
+ if (!group || group.startsWith('.') || RESERVED_FOLDERS.has(group.toLowerCase()))
55
+ return false;
56
+ const roots = new Set((opts.layoutRoots ?? runRoots()).map((r) => canonicalPathOn(r, platform)));
57
+ if (!roots.has(parent))
58
+ return false;
59
+ return (opts.hasMarker ?? ((p) => existsSync(join(p, RUN_MARKER))))(path);
39
60
  }
40
61
  export async function worktreesOf(checkout) {
41
62
  const r = await exec('git', ['-C', checkout, 'worktree', 'list', '--porcelain'], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firefunc-agent/runner",
3
- "version": "0.9.36",
3
+ "version": "0.9.40",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "FireFunc self-hosted runner — an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI, Copilot CLI, Antigravity) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",