@firefunc-agent/runner 0.9.35 → 0.9.37
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.
- package/README.md +50 -0
- package/dist/api.d.ts +1 -1
- package/dist/brief-file.d.ts +1 -0
- package/dist/brief-file.js +6 -0
- package/dist/build-info.json +2 -2
- package/dist/cli.js +84 -10
- package/dist/daemon.js +35 -5
- package/dist/engine-login.js +4 -2
- package/dist/engine-models.js +4 -2
- package/dist/engines/index.js +4 -2
- package/dist/exec.js +5 -2
- package/dist/firefunc/automations.js +22 -0
- package/dist/firefunc/catalog.js +8 -1
- package/dist/firefunc/machines.d.ts +2 -0
- package/dist/firefunc/machines.js +85 -0
- package/dist/firefunc/main.js +9 -0
- package/dist/firefunc/tasks.js +2 -0
- package/dist/firefunc/webhooks.d.ts +2 -0
- package/dist/firefunc/webhooks.js +78 -0
- package/dist/job.js +17 -4
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +6 -1
- package/dist/live-runner.d.ts +47 -0
- package/dist/live-runner.js +109 -0
- package/dist/mcp-login.d.ts +1 -0
- package/dist/mcp-login.js +42 -5
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +35 -3
- package/dist/newer-runner.d.ts +9 -0
- package/dist/newer-runner.js +38 -0
- package/dist/pool.d.ts +2 -0
- package/dist/pool.js +12 -1
- package/dist/update.d.ts +41 -0
- package/dist/update.js +176 -0
- package/dist/win-shell.d.ts +14 -0
- package/dist/win-shell.js +51 -0
- package/package.json +1 -1
package/dist/update.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type RestartIdleDeps } from './restart-idle.js';
|
|
2
|
+
export declare const RUNNER_PACKAGE = "@firefunc-agent/runner";
|
|
3
|
+
export type UpdateDeps = Omit<RestartIdleDeps, 'restart'> & {
|
|
4
|
+
current: string;
|
|
5
|
+
running?: () => string | null;
|
|
6
|
+
latest: () => Promise<string | null>;
|
|
7
|
+
scriptPath: string;
|
|
8
|
+
service: {
|
|
9
|
+
installed: () => Promise<boolean>;
|
|
10
|
+
stop: () => Promise<{
|
|
11
|
+
ok: boolean;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
start: (want: string) => Promise<{
|
|
15
|
+
ok: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
run: (cmd: string, args: string[]) => Promise<{
|
|
20
|
+
code: number;
|
|
21
|
+
output: string;
|
|
22
|
+
}>;
|
|
23
|
+
installedVersion: () => Promise<string | null>;
|
|
24
|
+
};
|
|
25
|
+
export type UpdateResult = {
|
|
26
|
+
ok: boolean;
|
|
27
|
+
message: string;
|
|
28
|
+
from: string;
|
|
29
|
+
to: string | null;
|
|
30
|
+
};
|
|
31
|
+
export declare function installCommand(scriptPath: string, spec: string): {
|
|
32
|
+
cmd: string;
|
|
33
|
+
args: string[];
|
|
34
|
+
};
|
|
35
|
+
export declare function updateRunner(d: UpdateDeps): Promise<UpdateResult>;
|
|
36
|
+
export declare function unknownWords(args: readonly string[], known: readonly string[], withValue?: readonly string[]): string | null;
|
|
37
|
+
export declare function runQuiet(cmd: string, args: string[]): Promise<{
|
|
38
|
+
code: number;
|
|
39
|
+
output: string;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function installedRunnerVersion(): Promise<string | null>;
|
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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function msvcQuote(arg: string): string;
|
|
2
|
+
export declare function windowsShellArg(arg: string, batch?: boolean): string;
|
|
3
|
+
export declare function windowsShellCommandName(cmd: string): string;
|
|
4
|
+
export type WhichDeps = {
|
|
5
|
+
exists: (p: string) => boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function resolveWindowsCommand(cmd: string, env?: NodeJS.ProcessEnv, deps?: WhichDeps): string | null;
|
|
8
|
+
export declare function isBatchFile(path: string): boolean;
|
|
9
|
+
export declare function windowsShellLine(cmd: string, args: readonly string[], env?: NodeJS.ProcessEnv, deps?: WhichDeps): string;
|
|
10
|
+
export declare function shellSafe(cmd: string, args: readonly string[], shell: boolean | undefined, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): {
|
|
11
|
+
cmd: string;
|
|
12
|
+
args: string[];
|
|
13
|
+
shell: boolean;
|
|
14
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { win32 } from 'node:path';
|
|
3
|
+
const { delimiter, extname, isAbsolute, join, normalize } = win32;
|
|
4
|
+
const META = /([()\][%!^"`<>&|;, *?])/g;
|
|
5
|
+
export function msvcQuote(arg) {
|
|
6
|
+
let out = '"';
|
|
7
|
+
let slashes = 0;
|
|
8
|
+
for (const ch of arg) {
|
|
9
|
+
if (ch === '\\') {
|
|
10
|
+
slashes += 1;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
out += ch === '"' ? `${'\\'.repeat(slashes * 2 + 1)}"` : `${'\\'.repeat(slashes)}${ch}`;
|
|
14
|
+
slashes = 0;
|
|
15
|
+
}
|
|
16
|
+
return `${out}${'\\'.repeat(slashes * 2)}"`;
|
|
17
|
+
}
|
|
18
|
+
export function windowsShellArg(arg, batch = false) {
|
|
19
|
+
const once = msvcQuote(arg).replace(META, '^$1');
|
|
20
|
+
return batch ? once.replace(META, '^$1') : once;
|
|
21
|
+
}
|
|
22
|
+
export function windowsShellCommandName(cmd) {
|
|
23
|
+
return normalize(cmd).replace(META, '^$1');
|
|
24
|
+
}
|
|
25
|
+
export function resolveWindowsCommand(cmd, env = process.env, deps = { exists: existsSync }) {
|
|
26
|
+
const exts = (env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean);
|
|
27
|
+
const candidates = (base) => extname(base) && deps.exists(base) ? [base] : exts.map((e) => `${base}${e}`);
|
|
28
|
+
const hasDir = isAbsolute(cmd) || /[\\/]/.test(cmd);
|
|
29
|
+
const dirs = hasDir ? [''] : (env.PATH ?? env.Path ?? '').split(delimiter).filter(Boolean);
|
|
30
|
+
for (const dir of dirs) {
|
|
31
|
+
const base = dir ? join(dir, cmd) : cmd;
|
|
32
|
+
for (const c of candidates(base))
|
|
33
|
+
if (deps.exists(c))
|
|
34
|
+
return c;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export function isBatchFile(path) {
|
|
39
|
+
return /\.(cmd|bat)$/i.test(path);
|
|
40
|
+
}
|
|
41
|
+
export function windowsShellLine(cmd, args, env = process.env, deps) {
|
|
42
|
+
const resolved = resolveWindowsCommand(cmd, env, deps) ?? cmd;
|
|
43
|
+
const batch = isBatchFile(resolved);
|
|
44
|
+
return [windowsShellCommandName(resolved), ...args.map((a) => windowsShellArg(a, batch))].join(' ');
|
|
45
|
+
}
|
|
46
|
+
export function shellSafe(cmd, args, shell, env = process.env, platform = process.platform) {
|
|
47
|
+
if (!shell || platform !== 'win32' || args.length === 0)
|
|
48
|
+
return { cmd, args: [...args], shell: !!shell };
|
|
49
|
+
return { cmd: windowsShellLine(cmd, args, env), args: [], shell: true };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=win-shell.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firefunc-agent/runner",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.37",
|
|
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.",
|