@firefunc-agent/runner 0.9.14 → 0.9.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -10
- package/dist/alive.d.ts +40 -0
- package/dist/alive.js +138 -0
- package/dist/api-fallback.d.ts +4 -2
- package/dist/api-fallback.js +26 -1
- package/dist/api.d.ts +66 -3
- package/dist/api.js +164 -3
- package/dist/brief-file.d.ts +15 -0
- package/dist/brief-file.js +36 -0
- package/dist/brief.d.ts +3 -0
- package/dist/brief.js +14 -4
- package/dist/build-caches.d.ts +7 -0
- package/dist/build-caches.js +63 -0
- package/dist/build-info.json +2 -2
- package/dist/checkpoint.d.ts +40 -0
- package/dist/checkpoint.js +98 -0
- package/dist/cli.js +184 -18
- package/dist/cloud-boot.d.ts +41 -0
- package/dist/cloud-boot.js +239 -0
- package/dist/command-activity.d.ts +23 -0
- package/dist/command-activity.js +89 -0
- package/dist/command-step.d.ts +58 -0
- package/dist/command-step.js +248 -0
- package/dist/config.d.ts +39 -0
- package/dist/config.js +23 -0
- package/dist/cut.d.ts +1 -1
- package/dist/cut.js +13 -3
- package/dist/daemon.js +364 -15
- package/dist/device-lease.d.ts +15 -0
- package/dist/device-lease.js +608 -0
- package/dist/editor/fs-server.d.ts +31 -0
- package/dist/editor/fs-server.js +159 -0
- package/dist/editor/relay-crypto.d.ts +68 -0
- package/dist/editor/relay-crypto.js +191 -0
- package/dist/editor/sessions.d.ts +50 -0
- package/dist/editor/sessions.js +279 -0
- package/dist/editor/worktree-of.d.ts +1 -0
- package/dist/editor/worktree-of.js +23 -0
- package/dist/editor/ws-client.d.ts +26 -0
- package/dist/editor/ws-client.js +227 -0
- package/dist/engine-account.d.ts +24 -0
- package/dist/engine-account.js +118 -0
- package/dist/engine-login.d.ts +12 -0
- package/dist/engine-login.js +88 -0
- package/dist/engine-models.d.ts +13 -0
- package/dist/engine-models.js +71 -0
- package/dist/engine-watch.d.ts +1 -0
- package/dist/engine-watch.js +22 -6
- package/dist/engines/antigravity.d.ts +2 -0
- package/dist/engines/antigravity.js +74 -4
- package/dist/engines/claude.js +22 -9
- package/dist/engines/codex.js +16 -2
- package/dist/engines/copilot.js +12 -0
- package/dist/engines/crush.d.ts +2 -0
- package/dist/engines/crush.js +58 -0
- package/dist/engines/cursor.js +12 -0
- package/dist/engines/gemini.js +14 -9
- package/dist/engines/index.d.ts +8 -0
- package/dist/engines/index.js +73 -1
- package/dist/engines/kilo.d.ts +2 -0
- package/dist/engines/kilo.js +63 -0
- package/dist/engines/opencode.d.ts +9 -0
- package/dist/engines/opencode.js +234 -0
- package/dist/engines/openhands.d.ts +10 -0
- package/dist/engines/openhands.js +271 -0
- package/dist/engines/pi.d.ts +10 -0
- package/dist/engines/pi.js +248 -0
- package/dist/engines/qwen.d.ts +8 -0
- package/dist/engines/qwen.js +153 -0
- package/dist/engines/sessions.d.ts +6 -0
- package/dist/engines/sessions.js +68 -0
- package/dist/engines/types.d.ts +3 -3
- package/dist/exec.d.ts +1 -0
- package/dist/exec.js +10 -4
- package/dist/firefunc/agents.d.ts +8 -1
- package/dist/firefunc/agents.js +53 -3
- package/dist/firefunc/auth.js +72 -19
- package/dist/firefunc/automations.d.ts +2 -0
- package/dist/firefunc/automations.js +290 -0
- package/dist/firefunc/cli.js +25 -0
- package/dist/firefunc/client.d.ts +5 -1
- package/dist/firefunc/client.js +12 -2
- package/dist/firefunc/config.d.ts +11 -1
- package/dist/firefunc/config.js +6 -4
- package/dist/firefunc/io.d.ts +1 -0
- package/dist/firefunc/main.js +34 -2
- package/dist/firefunc/oauth-login.d.ts +23 -0
- package/dist/firefunc/oauth-login.js +304 -0
- package/dist/firefunc/tasks.d.ts +4 -0
- package/dist/firefunc/tasks.js +89 -2
- package/dist/fleet-words.d.ts +2 -0
- package/dist/fleet-words.js +7 -0
- package/dist/git-auth.d.ts +15 -0
- package/dist/git-auth.js +39 -1
- package/dist/held.d.ts +3 -0
- package/dist/job.d.ts +26 -3
- package/dist/job.js +763 -152
- package/dist/keep-awake.d.ts +17 -0
- package/dist/keep-awake.js +90 -0
- package/dist/keep-local.d.ts +1 -1
- package/dist/keep-local.js +5 -3
- package/dist/limit.d.ts +9 -1
- package/dist/limit.js +260 -3
- package/dist/local-checks.d.ts +19 -0
- package/dist/local-checks.js +79 -0
- package/dist/locks.d.ts +18 -1
- package/dist/locks.js +249 -69
- package/dist/machine-commands.d.ts +21 -0
- package/dist/machine-commands.js +107 -0
- package/dist/machine-profile.d.ts +18 -0
- package/dist/machine-profile.js +69 -0
- package/dist/mcp-init.d.ts +2 -0
- package/dist/mcp-init.js +28 -0
- package/dist/mcp.d.ts +13 -1
- package/dist/mcp.js +48 -4
- package/dist/network.js +3 -2
- package/dist/openrouter.d.ts +15 -0
- package/dist/openrouter.js +39 -0
- package/dist/orphans.d.ts +4 -0
- package/dist/orphans.js +96 -4
- package/dist/pool.d.ts +1 -0
- package/dist/pool.js +25 -2
- package/dist/pr-title.d.ts +10 -0
- package/dist/pr-title.js +15 -0
- package/dist/recover.d.ts +3 -1
- package/dist/recover.js +27 -7
- package/dist/release-draft.d.ts +79 -0
- package/dist/release-draft.js +301 -0
- package/dist/resources.d.ts +86 -0
- package/dist/resources.js +217 -0
- package/dist/restart-idle.d.ts +23 -0
- package/dist/restart-idle.js +67 -0
- package/dist/run-attachments.d.ts +5 -0
- package/dist/run-attachments.js +14 -9
- package/dist/run-stops.d.ts +15 -0
- package/dist/run-stops.js +90 -0
- package/dist/run-temp.d.ts +12 -0
- package/dist/run-temp.js +57 -0
- package/dist/secret-scan.d.ts +5 -0
- package/dist/secret-scan.js +30 -0
- package/dist/self-upgrade.d.ts +36 -0
- package/dist/self-upgrade.js +78 -0
- package/dist/service.d.ts +7 -1
- package/dist/service.js +50 -7
- package/dist/sign-in.d.ts +42 -0
- package/dist/sign-in.js +243 -0
- package/dist/tool-call.d.ts +59 -0
- package/dist/tool-call.js +375 -0
- package/dist/transport.d.ts +26 -0
- package/dist/transport.js +118 -0
- package/dist/work-dir.d.ts +11 -0
- package/dist/work-dir.js +69 -0
- package/dist/worktree-report.d.ts +10 -0
- package/dist/worktree-report.js +17 -0
- package/dist/worktrees.d.ts +16 -1
- package/dist/worktrees.js +62 -17
- package/package.json +4 -4
- package/skill/firefunc/SKILL.md +22 -3
|
@@ -19,6 +19,11 @@ export type PreparedAttach = WrittenSkills & {
|
|
|
19
19
|
dir: string | null;
|
|
20
20
|
};
|
|
21
21
|
export declare function prepareAttachFolder(worktree: string, log: (m: string) => void): PreparedAttach;
|
|
22
|
+
export declare function prepareFireFuncFolder(worktree: string, folder: {
|
|
23
|
+
sub: string;
|
|
24
|
+
gitignore: string;
|
|
25
|
+
what: string;
|
|
26
|
+
}, log: (m: string) => void): PreparedAttach;
|
|
22
27
|
export type AttachCandidate = {
|
|
23
28
|
name: string;
|
|
24
29
|
path: string;
|
package/dist/run-attachments.js
CHANGED
|
@@ -53,12 +53,17 @@ function lstatExists(p) {
|
|
|
53
53
|
}
|
|
54
54
|
const NONE = { written: [], pathspecs: [], dir: null };
|
|
55
55
|
export function prepareAttachFolder(worktree, log) {
|
|
56
|
+
return prepareFireFuncFolder(worktree, { sub: 'attach', gitignore: GITIGNORE, what: 'pictures' }, log);
|
|
57
|
+
}
|
|
58
|
+
export function prepareFireFuncFolder(worktree, folder, log) {
|
|
59
|
+
const { sub, what } = folder;
|
|
60
|
+
const GITIGNORE = folder.gitignore;
|
|
56
61
|
let top;
|
|
57
62
|
try {
|
|
58
63
|
top = realpathSync(worktree);
|
|
59
64
|
}
|
|
60
65
|
catch (e) {
|
|
61
|
-
log(`no folder for
|
|
66
|
+
log(`no folder for ${what}: ${e.message}`);
|
|
62
67
|
return NONE;
|
|
63
68
|
}
|
|
64
69
|
const outer = join(top, '.firefunc');
|
|
@@ -67,12 +72,12 @@ export function prepareAttachFolder(worktree, log) {
|
|
|
67
72
|
mkdirSync(outer);
|
|
68
73
|
}
|
|
69
74
|
catch (e) {
|
|
70
|
-
log(`no folder for
|
|
75
|
+
log(`no folder for ${what}: ${e.message}`);
|
|
71
76
|
return NONE;
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
else if (!existsSync(outer)) {
|
|
75
|
-
log(
|
|
80
|
+
log(`no folder for ${what}: .firefunc is a link to a place that does not exist in this checkout. ` +
|
|
76
81
|
'Fix: point it at a folder inside the repository, or remove the link.');
|
|
77
82
|
return NONE;
|
|
78
83
|
}
|
|
@@ -81,15 +86,15 @@ export function prepareAttachFolder(worktree, log) {
|
|
|
81
86
|
outerReal = realpathSync(outer);
|
|
82
87
|
}
|
|
83
88
|
catch (e) {
|
|
84
|
-
log(`no folder for
|
|
89
|
+
log(`no folder for ${what}: ${e.message}`);
|
|
85
90
|
return NONE;
|
|
86
91
|
}
|
|
87
92
|
if (insideTop(top, outerReal) === null || !statSync(outerReal).isDirectory()) {
|
|
88
|
-
log(`no folder for
|
|
93
|
+
log(`no folder for ${what}: .firefunc leads to ${outerReal}, which is not a folder inside this checkout. ` +
|
|
89
94
|
'Fix: make .firefunc a folder inside the repository.');
|
|
90
95
|
return NONE;
|
|
91
96
|
}
|
|
92
|
-
const dir = join(outerReal,
|
|
97
|
+
const dir = join(outerReal, sub);
|
|
93
98
|
const rel = insideTop(top, dir);
|
|
94
99
|
const gitTop = git(top, ['rev-parse', '--show-toplevel']);
|
|
95
100
|
let isRepo = false;
|
|
@@ -119,7 +124,7 @@ export function prepareAttachFolder(worktree, log) {
|
|
|
119
124
|
}
|
|
120
125
|
if (mine)
|
|
121
126
|
return ours();
|
|
122
|
-
log(`no folder for
|
|
127
|
+
log(`no folder for ${what}: ${rel} is already in the checkout, and FireFunc never writes into the ` +
|
|
123
128
|
`repository's own files. Fix: rename or remove ${rel} in the repository.`);
|
|
124
129
|
return NONE;
|
|
125
130
|
}
|
|
@@ -131,7 +136,7 @@ export function prepareAttachFolder(worktree, log) {
|
|
|
131
136
|
`:(literal${ignoreCase ? ',icase' : ''})${rel}`,
|
|
132
137
|
]);
|
|
133
138
|
if (tracked) {
|
|
134
|
-
log(`no folder for
|
|
139
|
+
log(`no folder for ${what}: the repository tracks files under ${rel}. Fix: move them out of ${rel}.`);
|
|
135
140
|
return NONE;
|
|
136
141
|
}
|
|
137
142
|
}
|
|
@@ -140,7 +145,7 @@ export function prepareAttachFolder(worktree, log) {
|
|
|
140
145
|
writeFileSync(join(dir, '.gitignore'), GITIGNORE);
|
|
141
146
|
}
|
|
142
147
|
catch (e) {
|
|
143
|
-
log(`no folder for
|
|
148
|
+
log(`no folder for ${what}: ${e.message}`);
|
|
144
149
|
return NONE;
|
|
145
150
|
}
|
|
146
151
|
return ours();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const STOP_GRACE_MS = 3000;
|
|
2
|
+
export declare function trackRunGroup(runId: string, pgid: number): void;
|
|
3
|
+
export declare function untrackRunGroup(runId: string, pgid: number): void;
|
|
4
|
+
export declare function isStopped(runId: string): boolean;
|
|
5
|
+
export declare function forgetRun(runId: string): void;
|
|
6
|
+
export declare function readStopList(body: unknown): string[];
|
|
7
|
+
export type StopDeps = {
|
|
8
|
+
signal?: (pgid: number, sig: NodeJS.Signals) => void;
|
|
9
|
+
later?: (fn: () => void, ms: number) => void;
|
|
10
|
+
log?: (msg: string) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare function windowsStopArgs(pid: number): string[];
|
|
13
|
+
export declare function stopRun(runId: string, deps?: StopDeps): number;
|
|
14
|
+
export declare function stoppedByPersonSentence(engineName: string, at: 'engine' | 'push' | 'pr'): string;
|
|
15
|
+
export declare function resetRunStops(): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { signalGroupSparingDevices } from './orphans.js';
|
|
3
|
+
const stopped = new Set();
|
|
4
|
+
const groups = new Map();
|
|
5
|
+
export const STOP_GRACE_MS = 3_000;
|
|
6
|
+
export function trackRunGroup(runId, pgid) {
|
|
7
|
+
if (pgid <= 1)
|
|
8
|
+
return;
|
|
9
|
+
let set = groups.get(runId);
|
|
10
|
+
if (!set) {
|
|
11
|
+
set = new Set();
|
|
12
|
+
groups.set(runId, set);
|
|
13
|
+
}
|
|
14
|
+
set.add(pgid);
|
|
15
|
+
}
|
|
16
|
+
export function untrackRunGroup(runId, pgid) {
|
|
17
|
+
const set = groups.get(runId);
|
|
18
|
+
if (!set)
|
|
19
|
+
return;
|
|
20
|
+
set.delete(pgid);
|
|
21
|
+
if (set.size === 0)
|
|
22
|
+
groups.delete(runId);
|
|
23
|
+
}
|
|
24
|
+
export function isStopped(runId) {
|
|
25
|
+
return stopped.has(runId);
|
|
26
|
+
}
|
|
27
|
+
export function forgetRun(runId) {
|
|
28
|
+
stopped.delete(runId);
|
|
29
|
+
groups.delete(runId);
|
|
30
|
+
}
|
|
31
|
+
export function readStopList(body) {
|
|
32
|
+
const raw = body?.stop;
|
|
33
|
+
if (!Array.isArray(raw))
|
|
34
|
+
return [];
|
|
35
|
+
return [...new Set(raw.filter((x) => typeof x === 'string' && x.length > 0))];
|
|
36
|
+
}
|
|
37
|
+
export function windowsStopArgs(pid) {
|
|
38
|
+
return ['/pid', String(pid), '/T', '/F'];
|
|
39
|
+
}
|
|
40
|
+
const defaultSignal = (pgid, sig) => {
|
|
41
|
+
if (process.platform === 'win32') {
|
|
42
|
+
if (sig !== 'SIGTERM')
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
spawn('taskkill', windowsStopArgs(pgid), { stdio: 'ignore', windowsHide: true }).on('error', () => { });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
signalGroupSparingDevices(pgid, sig);
|
|
52
|
+
};
|
|
53
|
+
export function stopRun(runId, deps = {}) {
|
|
54
|
+
const first = !stopped.has(runId);
|
|
55
|
+
stopped.add(runId);
|
|
56
|
+
const signal = deps.signal ?? defaultSignal;
|
|
57
|
+
const later = deps.later ??
|
|
58
|
+
((fn, ms) => {
|
|
59
|
+
setTimeout(fn, ms).unref();
|
|
60
|
+
});
|
|
61
|
+
const pgids = [...(groups.get(runId) ?? [])];
|
|
62
|
+
for (const g of pgids)
|
|
63
|
+
signal(g, 'SIGTERM');
|
|
64
|
+
if (pgids.length > 0) {
|
|
65
|
+
later(() => {
|
|
66
|
+
for (const g of groups.get(runId) ?? [])
|
|
67
|
+
signal(g, 'SIGKILL');
|
|
68
|
+
}, STOP_GRACE_MS);
|
|
69
|
+
}
|
|
70
|
+
if (first) {
|
|
71
|
+
deps.log?.(`a person stopped ${runId} in FireFunc — ` +
|
|
72
|
+
(pgids.length > 0
|
|
73
|
+
? `ending its engine session now; nothing from it is pushed`
|
|
74
|
+
: `it pushes nothing, and its engine is not started`));
|
|
75
|
+
}
|
|
76
|
+
return pgids.length;
|
|
77
|
+
}
|
|
78
|
+
export function stoppedByPersonSentence(engineName, at) {
|
|
79
|
+
const rerun = 'Re-run the task when it should run again.';
|
|
80
|
+
if (at === 'push')
|
|
81
|
+
return `A person stopped this run in FireFunc before it pushed, so nothing was pushed and no pull request was opened. ${rerun}`;
|
|
82
|
+
if (at === 'pr')
|
|
83
|
+
return `A person stopped this run in FireFunc after its branch was pushed, so no pull request was opened. ${rerun}`;
|
|
84
|
+
return `A person stopped this run in FireFunc, so the runner ended the ${engineName} session; nothing was pushed. ${rerun}`;
|
|
85
|
+
}
|
|
86
|
+
export function resetRunStops() {
|
|
87
|
+
stopped.clear();
|
|
88
|
+
groups.clear();
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=run-stops.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function runTempPath(runId: string, root?: string): string;
|
|
2
|
+
export declare function tempRoot(): string;
|
|
3
|
+
export declare function makeRunTemp(runId: string, root?: string): {
|
|
4
|
+
dir: string;
|
|
5
|
+
env: {
|
|
6
|
+
TMPDIR: string;
|
|
7
|
+
TEMP: string;
|
|
8
|
+
TMP: string;
|
|
9
|
+
};
|
|
10
|
+
} | null;
|
|
11
|
+
export declare function removeRunTemp(dir: string | null): void;
|
|
12
|
+
export declare function staleRunTemps(roots: readonly string[], spare: ReadonlySet<string>, now?: number, minAgeMs?: number): string[];
|
package/dist/run-temp.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { mkdirSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { workRoot, workTempEnv } from './work-dir.js';
|
|
4
|
+
export function runTempPath(runId, root = tempRoot()) {
|
|
5
|
+
const id = runId.replace(/[^A-Za-z0-9]/g, '').slice(0, 12) || 'run';
|
|
6
|
+
return join(root, `fft-${id}`);
|
|
7
|
+
}
|
|
8
|
+
export function tempRoot() {
|
|
9
|
+
return workTempEnv().TMPDIR ?? workRoot();
|
|
10
|
+
}
|
|
11
|
+
export function makeRunTemp(runId, root) {
|
|
12
|
+
const dir = runTempPath(runId, root);
|
|
13
|
+
try {
|
|
14
|
+
mkdirSync(dir, { recursive: true });
|
|
15
|
+
return { dir, env: { TMPDIR: dir, TEMP: dir, TMP: dir } };
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function removeRunTemp(dir) {
|
|
22
|
+
if (!dir)
|
|
23
|
+
return;
|
|
24
|
+
try {
|
|
25
|
+
rmSync(dir, { recursive: true, force: true });
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function staleRunTemps(roots, spare, now = Date.now(), minAgeMs = 6 * 60 * 60_000) {
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const root of new Set(roots)) {
|
|
33
|
+
let names;
|
|
34
|
+
try {
|
|
35
|
+
names = readdirSync(root);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const n of names) {
|
|
41
|
+
if (!/^fft-[A-Za-z0-9]{1,12}$/.test(n))
|
|
42
|
+
continue;
|
|
43
|
+
const p = join(root, n);
|
|
44
|
+
if (spare.has(p))
|
|
45
|
+
continue;
|
|
46
|
+
try {
|
|
47
|
+
const st = statSync(p);
|
|
48
|
+
if (st.isDirectory() && now - st.mtimeMs >= minAgeMs)
|
|
49
|
+
out.push(p);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=run-temp.js.map
|
package/dist/secret-scan.d.ts
CHANGED
|
@@ -17,3 +17,8 @@ export declare function changeReads(from: string, branch: string, tip?: string):
|
|
|
17
17
|
export declare function uniqueHits(hits: SecretHit[]): SecretHit[];
|
|
18
18
|
export declare function hardFirst(hits: SecretHit[]): SecretHit[];
|
|
19
19
|
export declare function secretRefusal(hits: SecretHit[], branch?: string): string;
|
|
20
|
+
export declare function secretFixRead(from: string): {
|
|
21
|
+
args: string[];
|
|
22
|
+
env: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
export declare function secretFixBrief(hits: SecretHit[], from: string, committed: boolean): string;
|
package/dist/secret-scan.js
CHANGED
|
@@ -161,4 +161,34 @@ export function secretRefusal(hits, branch) {
|
|
|
161
161
|
'like a live key. Then run the task again. A value a later commit took out still counts: the push ' +
|
|
162
162
|
'would publish the commit that added it (git log -p shows which).');
|
|
163
163
|
}
|
|
164
|
+
export function secretFixRead(from) {
|
|
165
|
+
return {
|
|
166
|
+
args: [
|
|
167
|
+
'--no-replace-objects',
|
|
168
|
+
'-c',
|
|
169
|
+
'core.quotepath=off',
|
|
170
|
+
'-c',
|
|
171
|
+
'advice.graftFileDeprecated=false',
|
|
172
|
+
'diff',
|
|
173
|
+
'--cached',
|
|
174
|
+
...PATCH_FLAGS,
|
|
175
|
+
from,
|
|
176
|
+
],
|
|
177
|
+
env: { GIT_GRAFT_FILE: devNull },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export function secretFixBrief(hits, from, committed) {
|
|
181
|
+
const shown = hits
|
|
182
|
+
.slice(0, 10)
|
|
183
|
+
.map((h) => `- ${h.kind} at ${h.path}:${h.line}`)
|
|
184
|
+
.join('\n');
|
|
185
|
+
const more = hits.length > 10 ? `\n- and ${hits.length - 10} more` : '';
|
|
186
|
+
return ("Before your change is pushed, the machine's secret scan read every line it adds, and it would refuse the whole push over these lines, which look like credentials:\n" +
|
|
187
|
+
`${shown}${more}\n\n` +
|
|
188
|
+
'Rewrite each one so no credential-shaped value is written literally. In a test or a fixture, build the value when the test runs — join its parts, sign a JWT or generate a key in the test’s setup, or read it from an environment variable the test sets. A real credential is never written into the change: read it from the environment. ' +
|
|
189
|
+
(committed
|
|
190
|
+
? `A value inside a commit is pushed with that commit, so first undo your own commits with \`git reset --soft ${from}\` (your work stays, staged; the runner commits it for you). `
|
|
191
|
+
: '') +
|
|
192
|
+
'Change nothing else, run the tests these files belong to again, and end with the same summary of the task you gave before. Do not commit.');
|
|
193
|
+
}
|
|
164
194
|
//# sourceMappingURL=secret-scan.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const UPGRADE_EXIT_CODE = 75;
|
|
2
|
+
export declare const UPGRADE_INSTALL_TIMEOUT_MS: number;
|
|
3
|
+
export type UpgradeCommand = {
|
|
4
|
+
version: string;
|
|
5
|
+
requestedAt: string;
|
|
6
|
+
};
|
|
7
|
+
export type UpgradeReport = {
|
|
8
|
+
state: 'started' | 'refused' | 'failed';
|
|
9
|
+
target: string;
|
|
10
|
+
code?: string;
|
|
11
|
+
reason?: string;
|
|
12
|
+
};
|
|
13
|
+
export type SelfUpgradeDeps = {
|
|
14
|
+
held: () => number;
|
|
15
|
+
setDrain: (on: boolean) => boolean;
|
|
16
|
+
install: (spec: string) => Promise<{
|
|
17
|
+
code: number;
|
|
18
|
+
output: string;
|
|
19
|
+
}>;
|
|
20
|
+
exit: (code: number) => void;
|
|
21
|
+
log: (line: string) => void;
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
scriptPath?: string;
|
|
24
|
+
pollMs?: number;
|
|
25
|
+
settleMs?: number;
|
|
26
|
+
now?: () => number;
|
|
27
|
+
sleep?: (ms: number) => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export declare function upgradeRefusal(env: NodeJS.ProcessEnv, scriptPath: string): {
|
|
30
|
+
code: string;
|
|
31
|
+
reason: string;
|
|
32
|
+
} | null;
|
|
33
|
+
export declare function createSelfUpgrade(d: SelfUpgradeDeps): {
|
|
34
|
+
report: () => UpgradeReport | null;
|
|
35
|
+
onCommand(cmd: UpgradeCommand): void;
|
|
36
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { RUNNER_PACKAGE } from './fleet-words.js';
|
|
2
|
+
export const UPGRADE_EXIT_CODE = 75;
|
|
3
|
+
export const UPGRADE_INSTALL_TIMEOUT_MS = 10 * 60_000;
|
|
4
|
+
export function upgradeRefusal(env, scriptPath) {
|
|
5
|
+
if (/[\\/]_npx[\\/]/.test(scriptPath)) {
|
|
6
|
+
return {
|
|
7
|
+
code: 'npx_install',
|
|
8
|
+
reason: 'This runner runs from npx’s temporary cache, so there is no installed copy to upgrade. Install it with npm install -g @firefunc-agent/runner, then firefunc-runner install.',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
if (env.FIREFUNC_RUNNER_SERVICE !== '1') {
|
|
12
|
+
return {
|
|
13
|
+
code: 'not_a_service',
|
|
14
|
+
reason: 'This runner was started by hand, not as the installed service, so nothing would start the new version after it. Upgrade it where it runs (npm install -g @firefunc-agent/runner@latest), or run it as a service (firefunc-runner install).',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export function createSelfUpgrade(d) {
|
|
20
|
+
let current = null;
|
|
21
|
+
let report = null;
|
|
22
|
+
const env = d.env ?? process.env;
|
|
23
|
+
const scriptPath = d.scriptPath ?? process.argv[1] ?? '';
|
|
24
|
+
const sleep = d.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
25
|
+
const now = d.now ?? (() => Date.now());
|
|
26
|
+
async function carryOut(target) {
|
|
27
|
+
const drainedBefore = d.setDrain(true);
|
|
28
|
+
const lift = () => {
|
|
29
|
+
if (!drainedBefore)
|
|
30
|
+
d.setDrain(false);
|
|
31
|
+
};
|
|
32
|
+
d.log(`FireFunc asked this machine to upgrade to ${target} when idle — finishing the runs it holds, taking nothing new`);
|
|
33
|
+
const started = now();
|
|
34
|
+
const settle = d.settleMs ?? 70_000;
|
|
35
|
+
for (;;) {
|
|
36
|
+
if (d.held() === 0 && now() - started >= settle)
|
|
37
|
+
break;
|
|
38
|
+
await sleep(d.pollMs ?? 10_000);
|
|
39
|
+
}
|
|
40
|
+
const spec = `${RUNNER_PACKAGE}@${target}`;
|
|
41
|
+
d.log(`idle — installing ${spec}`);
|
|
42
|
+
const res = await d.install(spec).catch((err) => ({
|
|
43
|
+
code: -1,
|
|
44
|
+
output: err instanceof Error ? err.message : String(err),
|
|
45
|
+
}));
|
|
46
|
+
lift();
|
|
47
|
+
if (res.code !== 0) {
|
|
48
|
+
const tail = res.output.trim().split('\n').slice(-4).join(' ').slice(0, 400);
|
|
49
|
+
report = {
|
|
50
|
+
state: 'failed',
|
|
51
|
+
target,
|
|
52
|
+
code: 'install_failed',
|
|
53
|
+
reason: `npm install -g ${spec} failed (exit ${res.code})${tail ? `: ${tail}` : ''}. The runner keeps running its current version.`,
|
|
54
|
+
};
|
|
55
|
+
d.log(`upgrade failed — ${report.reason}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
d.log(`installed ${spec} — restarting into it`);
|
|
59
|
+
d.exit(UPGRADE_EXIT_CODE);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
report: () => report,
|
|
63
|
+
onCommand(cmd) {
|
|
64
|
+
if (current && current.target === cmd.version && current.requestedAt === cmd.requestedAt)
|
|
65
|
+
return;
|
|
66
|
+
current = { target: cmd.version, requestedAt: cmd.requestedAt };
|
|
67
|
+
const refused = upgradeRefusal(env, scriptPath);
|
|
68
|
+
if (refused) {
|
|
69
|
+
report = { state: 'refused', target: cmd.version, ...refused };
|
|
70
|
+
d.log(`cannot upgrade to ${cmd.version}: ${refused.reason}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
report = { state: 'started', target: cmd.version };
|
|
74
|
+
void carryOut(cmd.version);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=self-upgrade.js.map
|
package/dist/service.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const WINDOWS_TASK_NAME = "FireFuncRunner";
|
|
|
4
4
|
export type ServicePaths = {
|
|
5
5
|
unit: string;
|
|
6
6
|
log: string;
|
|
7
|
+
launcher?: string;
|
|
7
8
|
};
|
|
8
9
|
export declare function servicePaths(os: ServicePlatform, home?: string): ServicePaths;
|
|
9
10
|
export type UnitInput = {
|
|
@@ -15,8 +16,11 @@ export type UnitInput = {
|
|
|
15
16
|
};
|
|
16
17
|
export declare function renderLaunchdPlist(i: UnitInput): string;
|
|
17
18
|
export declare function renderSystemdUnit(i: UnitInput): string;
|
|
19
|
+
export declare function windowsServiceCommand(i: UnitInput): string;
|
|
20
|
+
export declare function renderWindowsLauncher(i: UnitInput): string;
|
|
18
21
|
export declare function renderWindowsTaskXml(i: UnitInput & {
|
|
19
22
|
userId: string;
|
|
23
|
+
launcherPath: string;
|
|
20
24
|
}): string;
|
|
21
25
|
export declare function isEphemeralInstall(scriptPath: string): boolean;
|
|
22
26
|
export declare const EPHEMERAL_INSTALL_MESSAGE: string;
|
|
@@ -29,6 +33,7 @@ export type ServiceDeps = {
|
|
|
29
33
|
os: ServicePlatform | null;
|
|
30
34
|
paths: ServicePaths;
|
|
31
35
|
unitBody: string;
|
|
36
|
+
launcherBody?: string;
|
|
32
37
|
exec: (cmd: string, args: string[]) => Promise<{
|
|
33
38
|
code: number;
|
|
34
39
|
out: string;
|
|
@@ -39,7 +44,7 @@ export type ServiceDeps = {
|
|
|
39
44
|
removeFile: (path: string) => void;
|
|
40
45
|
fileExists: (path: string) => boolean;
|
|
41
46
|
};
|
|
42
|
-
export declare function defaultServiceDeps(unitBody: string, os?: ServicePlatform | null): ServiceDeps;
|
|
47
|
+
export declare function defaultServiceDeps(unitBody: string, os?: ServicePlatform | null, launcherBody?: string): ServiceDeps;
|
|
43
48
|
export declare function installService(d: ServiceDeps): Promise<ServiceResult>;
|
|
44
49
|
export declare function uninstallService(d: ServiceDeps): Promise<ServiceResult>;
|
|
45
50
|
export declare function stopService(d: ServiceDeps): Promise<ServiceResult>;
|
|
@@ -52,4 +57,5 @@ export type ServiceStatus = {
|
|
|
52
57
|
detail?: string;
|
|
53
58
|
};
|
|
54
59
|
export declare function serviceStatus(d: ServiceDeps): Promise<ServiceStatus>;
|
|
60
|
+
export declare function serviceWords(svc: ServiceStatus, os: ServicePlatform | null, runnerRunning: boolean): string;
|
|
55
61
|
export declare function readLogTail(logPath: string, lines?: number): string;
|
package/dist/service.js
CHANGED
|
@@ -12,7 +12,11 @@ export function servicePaths(os, home = homedir()) {
|
|
|
12
12
|
return { unit: join(home, 'Library', 'LaunchAgents', `${SERVICE_LABEL}.plist`), log };
|
|
13
13
|
}
|
|
14
14
|
if (os === 'win32') {
|
|
15
|
-
return {
|
|
15
|
+
return {
|
|
16
|
+
unit: join(home, '.firefunc-runner', 'firefunc-runner-task.xml'),
|
|
17
|
+
log,
|
|
18
|
+
launcher: join(home, '.firefunc-runner', 'firefunc-runner-service.vbs'),
|
|
19
|
+
};
|
|
16
20
|
}
|
|
17
21
|
return { unit: join(home, '.config', 'systemd', 'user', 'firefunc-runner.service'), log };
|
|
18
22
|
}
|
|
@@ -83,12 +87,26 @@ StandardError=append:${i.logPath}
|
|
|
83
87
|
WantedBy=default.target
|
|
84
88
|
`;
|
|
85
89
|
}
|
|
86
|
-
export function
|
|
87
|
-
|
|
90
|
+
export function windowsServiceCommand(i) {
|
|
91
|
+
return [
|
|
88
92
|
`set "PATH=${i.pathEnv}"`,
|
|
89
93
|
`set "FIREFUNC_RUNNER_SERVICE=1"`,
|
|
94
|
+
`set "FIREFUNC_RUNNER_WINDOWLESS=1"`,
|
|
90
95
|
`"${i.nodePath}" "${i.scriptPath}" start >> "${i.logPath}" 2>&1`,
|
|
91
96
|
].join(' && ');
|
|
97
|
+
}
|
|
98
|
+
export function renderWindowsLauncher(i) {
|
|
99
|
+
const line = `cmd.exe /c "${windowsServiceCommand(i)}"`.replace(/"/g, '""');
|
|
100
|
+
return [
|
|
101
|
+
`' FireFunc runner service launcher - written by "firefunc-runner install".`,
|
|
102
|
+
`' Runs the runner with no window; its output goes to ${i.logPath.replace(/[\r\n]/g, ' ')}.`,
|
|
103
|
+
`Set shell = CreateObject("WScript.Shell")`,
|
|
104
|
+
`code = shell.Run("${line}", 0, True)`,
|
|
105
|
+
`WScript.Quit code`,
|
|
106
|
+
``,
|
|
107
|
+
].join('\r\n');
|
|
108
|
+
}
|
|
109
|
+
export function renderWindowsTaskXml(i) {
|
|
92
110
|
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
93
111
|
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
94
112
|
<RegistrationInfo>
|
|
@@ -133,8 +151,8 @@ export function renderWindowsTaskXml(i) {
|
|
|
133
151
|
</Settings>
|
|
134
152
|
<Actions Context="Author">
|
|
135
153
|
<Exec>
|
|
136
|
-
<Command>
|
|
137
|
-
<Arguments
|
|
154
|
+
<Command>wscript.exe</Command>
|
|
155
|
+
<Arguments>//B //Nologo "${xmlEscape(i.launcherPath)}"</Arguments>
|
|
138
156
|
</Exec>
|
|
139
157
|
</Actions>
|
|
140
158
|
</Task>
|
|
@@ -166,11 +184,12 @@ async function exec(cmd, args) {
|
|
|
166
184
|
return { code: typeof e.code === 'number' ? e.code : 1, out: e.stderr ?? e.message ?? '' };
|
|
167
185
|
}
|
|
168
186
|
}
|
|
169
|
-
export function defaultServiceDeps(unitBody, os = currentPlatform()) {
|
|
187
|
+
export function defaultServiceDeps(unitBody, os = currentPlatform(), launcherBody) {
|
|
170
188
|
return {
|
|
171
189
|
os,
|
|
172
190
|
paths: servicePaths(os ?? 'linux'),
|
|
173
191
|
unitBody,
|
|
192
|
+
...(launcherBody ? { launcherBody } : {}),
|
|
174
193
|
exec,
|
|
175
194
|
ensureDir: (path) => mkdirSync(path, { recursive: true }),
|
|
176
195
|
unitEncoding: os === 'win32' ? 'utf16le' : 'utf8',
|
|
@@ -206,6 +225,9 @@ export async function installService(d) {
|
|
|
206
225
|
};
|
|
207
226
|
}
|
|
208
227
|
if (d.os === 'win32') {
|
|
228
|
+
if (d.paths.launcher && d.launcherBody) {
|
|
229
|
+
d.writeFile(d.paths.launcher, d.launcherBody, 'utf16le');
|
|
230
|
+
}
|
|
209
231
|
const create = await d.exec('schtasks', [
|
|
210
232
|
'/Create',
|
|
211
233
|
'/TN',
|
|
@@ -223,7 +245,7 @@ export async function installService(d) {
|
|
|
223
245
|
: `\nNOTE: registered, but could not start it right now — it will start at your next sign-in.\n${run.out.trim()}`;
|
|
224
246
|
return {
|
|
225
247
|
ok: true,
|
|
226
|
-
message: `Installed. The runner starts when you sign in and restarts if it crashes.\n` +
|
|
248
|
+
message: `Installed. The runner starts when you sign in, runs with no window, and restarts if it crashes.\n` +
|
|
227
249
|
` task: ${WINDOWS_TASK_NAME} (Task Scheduler)\n logs: ${d.paths.log}\n\n` +
|
|
228
250
|
` firefunc-runner logs watch it work\n` +
|
|
229
251
|
` firefunc-runner stop stop it (stays stopped until you start it)\n` +
|
|
@@ -269,6 +291,8 @@ export async function uninstallService(d) {
|
|
|
269
291
|
await d.exec('systemctl', ['--user', 'daemon-reload']);
|
|
270
292
|
}
|
|
271
293
|
d.removeFile(d.paths.unit);
|
|
294
|
+
if (d.paths.launcher)
|
|
295
|
+
d.removeFile(d.paths.launcher);
|
|
272
296
|
return { ok: true, message: `Removed. ${d.paths.unit} deleted; the runner will not restart.` };
|
|
273
297
|
}
|
|
274
298
|
export async function stopService(d) {
|
|
@@ -354,6 +378,25 @@ export async function serviceStatus(d) {
|
|
|
354
378
|
const r = await d.exec('systemctl', ['--user', 'is-active', 'firefunc-runner']);
|
|
355
379
|
return { ...base, installed: true, running: r.out.trim() === 'active' };
|
|
356
380
|
}
|
|
381
|
+
export function serviceWords(svc, os, runnerRunning) {
|
|
382
|
+
if (!os) {
|
|
383
|
+
return `\nservice: not supported on this platform — keep "firefunc-runner start" running\n`;
|
|
384
|
+
}
|
|
385
|
+
if (!svc.installed) {
|
|
386
|
+
return (`\nservice: NOT INSTALLED — ${runnerRunning ? 'this runner stops' : 'the runner stops'} when you close the terminal\n` +
|
|
387
|
+
` and does not come back after a reboot.\n` +
|
|
388
|
+
` Fix: firefunc-runner install\n`);
|
|
389
|
+
}
|
|
390
|
+
const manager = os === 'win32' ? 'Task Scheduler' : os === 'darwin' ? 'launchd' : 'systemd';
|
|
391
|
+
const state = svc.running
|
|
392
|
+
? 'RUNNING'
|
|
393
|
+
: runnerRunning
|
|
394
|
+
? `installed; ${manager} reports the task as ${svc.detail === 'task not found' ? 'missing' : (svc.detail ?? 'not running')}, but the runner above is running`
|
|
395
|
+
: 'STOPPED';
|
|
396
|
+
return (`\nservice: ${svc.running ? 'installed, RUNNING' : runnerRunning ? state : `installed, ${state}`}\n` +
|
|
397
|
+
` unit: ${svc.unit}\n` +
|
|
398
|
+
(svc.running || runnerRunning ? '' : ` Start it: firefunc-runner start-service\n`));
|
|
399
|
+
}
|
|
357
400
|
export function readLogTail(logPath, lines = 80) {
|
|
358
401
|
if (!existsSync(logPath))
|
|
359
402
|
return '(no log yet — has the service been started?)';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RunnerConfig } from './config.js';
|
|
2
|
+
import { type LoginProbe } from './engine-login.js';
|
|
3
|
+
import type { EngineId } from './engines/types.js';
|
|
4
|
+
export type PlanState = 'signed_in' | 'not' | 'none' | 'unknown';
|
|
5
|
+
export type KeyState = 'found' | 'missing' | 'none';
|
|
6
|
+
export type EngineSignIn = {
|
|
7
|
+
plan: PlanState;
|
|
8
|
+
key: KeyState;
|
|
9
|
+
keySource?: string;
|
|
10
|
+
uses?: 'plan' | 'key';
|
|
11
|
+
openrouter?: 'found' | 'missing';
|
|
12
|
+
};
|
|
13
|
+
export type SignInReport = Partial<Record<EngineId, EngineSignIn>>;
|
|
14
|
+
export type SignInPref = {
|
|
15
|
+
use?: 'plan' | 'key';
|
|
16
|
+
planToKey?: boolean;
|
|
17
|
+
keyToPlan?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type SignInPrefs = Partial<Record<string, SignInPref>>;
|
|
20
|
+
export declare const ENGINE_KEY_VARS: Record<EngineId, readonly string[]>;
|
|
21
|
+
export declare function keySourceOf(engine: EngineId, cfg: Pick<RunnerConfig, 'claudeEnv' | 'claudeApiKeyFile'>, env?: NodeJS.ProcessEnv, dir?: string): string | null;
|
|
22
|
+
export declare function planStateOf(engine: EngineId, cfg: Pick<RunnerConfig, 'claudeBin' | 'codexBin' | 'claudeCodeOAuthToken'>, probe?: LoginProbe, env?: NodeJS.ProcessEnv, home?: string): PlanState;
|
|
23
|
+
export declare function signInReport(engines: readonly EngineId[], cfg: RunnerConfig, opts?: {
|
|
24
|
+
probe?: LoginProbe;
|
|
25
|
+
env?: NodeJS.ProcessEnv;
|
|
26
|
+
home?: string;
|
|
27
|
+
dir?: string;
|
|
28
|
+
}): SignInReport;
|
|
29
|
+
export declare function parseSignInPrefs(raw: unknown): SignInPrefs | null;
|
|
30
|
+
export type SignInFields = Pick<RunnerConfig, 'claudeUseApiKey' | 'claudeApiKeyFallback' | 'claudeKeyToPlan' | 'codexUseApiKey'>;
|
|
31
|
+
export declare function signInFieldsOf(cfg: RunnerConfig): SignInFields;
|
|
32
|
+
export declare function applySignInPrefs(local: SignInFields, prefs: SignInPrefs | null): SignInFields;
|
|
33
|
+
export type JobSignIn = {
|
|
34
|
+
ok: true;
|
|
35
|
+
cfg: RunnerConfig;
|
|
36
|
+
note: string | null;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
reason: string;
|
|
40
|
+
fix: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function jobSignIn(engine: EngineId, want: unknown, cfg: RunnerConfig, machine: string, report: EngineSignIn | undefined): JobSignIn;
|