@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
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { createReadStream, lstatSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { request as httpsRequest } from 'node:https';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { prepareFireFuncFolder } from './run-attachments.js';
|
|
5
|
+
export const RELEASE_FOLDER = '.firefunc/release';
|
|
6
|
+
export const RELEASE_MANIFEST = 'release.json';
|
|
7
|
+
export const MAX_RELEASE_FILES = 20;
|
|
8
|
+
export const MAX_RELEASE_FILE_BYTES = 1024 * 1024 * 1024;
|
|
9
|
+
export const MAX_RELEASE_TOTAL_BYTES = 2 * 1024 * 1024 * 1024;
|
|
10
|
+
const MAX_NOTES = 125_000;
|
|
11
|
+
const GITIGNORE = '# FireFunc: the files a release carries, never committed\n*\n';
|
|
12
|
+
const SECRET_EXTENSIONS = new Set([
|
|
13
|
+
'jks',
|
|
14
|
+
'keystore',
|
|
15
|
+
'p12',
|
|
16
|
+
'pfx',
|
|
17
|
+
'pem',
|
|
18
|
+
'key',
|
|
19
|
+
'p8',
|
|
20
|
+
'mobileprovision',
|
|
21
|
+
'provisionprofile',
|
|
22
|
+
'gpg',
|
|
23
|
+
'asc',
|
|
24
|
+
]);
|
|
25
|
+
export function releaseRule(offer) {
|
|
26
|
+
const tag = offer.tag
|
|
27
|
+
? ` (the line names ${offer.tag}; write your own when you bump the version)`
|
|
28
|
+
: '';
|
|
29
|
+
return `- This agent publishes a GitHub release. Put the files the release carries — the build (an .apk, .aab, .ipa, .zip …) and its checksums — in \`${RELEASE_FOLDER}/\`, and write \`${RELEASE_FOLDER}/${RELEASE_MANIFEST}\` as {"tag": "v1.2.0", "name": "…", "notes": "…"}${tag}. FireFunc stages them as a draft release when you finish and publishes it once the pull request merges. Never commit them, and never put a signing key, a keystore or a password there — those are never published.`;
|
|
30
|
+
}
|
|
31
|
+
export function releaseTagProblem(tag) {
|
|
32
|
+
if (typeof tag !== 'string' || !tag.trim())
|
|
33
|
+
return 'No tag was named for the release.';
|
|
34
|
+
const t = tag.trim();
|
|
35
|
+
if (t.length > 100)
|
|
36
|
+
return `The tag "${t.slice(0, 40)}…" is longer than 100 characters.`;
|
|
37
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._+\-/]*$/.test(t) ||
|
|
38
|
+
t.includes('..') ||
|
|
39
|
+
t.includes('//') ||
|
|
40
|
+
t.endsWith('.') ||
|
|
41
|
+
t.endsWith('/') ||
|
|
42
|
+
t.endsWith('.lock')) {
|
|
43
|
+
return `"${t}" is not a tag git takes: letters, digits, ".", "-", "_", "+" and "/" only, starting with a letter or a digit.`;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
export function prepareReleaseFolder(worktree, log) {
|
|
48
|
+
return prepareFireFuncFolder(worktree, { sub: 'release', gitignore: GITIGNORE, what: 'the release' }, log);
|
|
49
|
+
}
|
|
50
|
+
function readManifest(path) {
|
|
51
|
+
let text;
|
|
52
|
+
try {
|
|
53
|
+
if (!lstatSync(path).isFile())
|
|
54
|
+
return { problem: `${RELEASE_MANIFEST} is not a file.` };
|
|
55
|
+
text = readFileSync(path, 'utf8');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
let raw;
|
|
61
|
+
try {
|
|
62
|
+
raw = JSON.parse(text);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return { problem: `${RELEASE_MANIFEST} is not JSON.` };
|
|
66
|
+
}
|
|
67
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
68
|
+
return { problem: `${RELEASE_MANIFEST} is not an object such as {"tag": "v1.2.0"}.` };
|
|
69
|
+
}
|
|
70
|
+
const o = raw;
|
|
71
|
+
const str = (v, max) => typeof v === 'string' && v.trim() ? v.trim().slice(0, max) : null;
|
|
72
|
+
const tag = str(o.tag, 200);
|
|
73
|
+
if (tag && releaseTagProblem(tag))
|
|
74
|
+
return { problem: releaseTagProblem(tag) };
|
|
75
|
+
return {
|
|
76
|
+
tag,
|
|
77
|
+
name: str(o.name, 200),
|
|
78
|
+
notes: str(o.notes, MAX_NOTES),
|
|
79
|
+
prerelease: typeof o.prerelease === 'boolean' ? o.prerelease : null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function scanReleaseFolder(dir, offer = {}) {
|
|
83
|
+
const within = (v, cap) => typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.min(Math.floor(v), cap) : cap;
|
|
84
|
+
const maxFiles = within(offer.maxFiles, MAX_RELEASE_FILES);
|
|
85
|
+
const maxFileBytes = within(offer.maxFileBytes, MAX_RELEASE_FILE_BYTES);
|
|
86
|
+
const maxTotalBytes = within(offer.maxTotalBytes, MAX_RELEASE_TOTAL_BYTES);
|
|
87
|
+
const files = [];
|
|
88
|
+
const skipped = [];
|
|
89
|
+
let names;
|
|
90
|
+
try {
|
|
91
|
+
names = readdirSync(dir).sort((a, b) => a.localeCompare(b));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return { manifest: null, files, skipped };
|
|
95
|
+
}
|
|
96
|
+
const manifest = names.includes(RELEASE_MANIFEST)
|
|
97
|
+
? readManifest(join(dir, RELEASE_MANIFEST))
|
|
98
|
+
: null;
|
|
99
|
+
let total = 0;
|
|
100
|
+
for (const name of names) {
|
|
101
|
+
if (name === '.gitignore' || name === RELEASE_MANIFEST)
|
|
102
|
+
continue;
|
|
103
|
+
const path = join(dir, name);
|
|
104
|
+
let st;
|
|
105
|
+
try {
|
|
106
|
+
st = lstatSync(path);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!st.isFile()) {
|
|
112
|
+
skipped.push({
|
|
113
|
+
name,
|
|
114
|
+
why: st.isSymbolicLink() ? 'it is a link, not a file' : 'it is not a file',
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (name.length > 120 || /[\u0000-\u001f\u007f\\]/.test(name) || name.trim() !== name) {
|
|
119
|
+
skipped.push({ name, why: 'its name is not a plain file name' });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const ext = /\.([A-Za-z0-9]+)$/.exec(name)?.[1]?.toLowerCase() ?? '';
|
|
123
|
+
if (SECRET_EXTENSIONS.has(ext) ||
|
|
124
|
+
/(^|[._-])(secret|password|credentials?)([._-]|$)/i.test(name)) {
|
|
125
|
+
skipped.push({ name, why: 'a signing key or a secret is never published' });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (st.size === 0) {
|
|
129
|
+
skipped.push({ name, why: 'it is empty' });
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (st.size > maxFileBytes) {
|
|
133
|
+
skipped.push({ name, why: `it is larger than ${maxFileBytes} bytes` });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (files.length >= maxFiles) {
|
|
137
|
+
skipped.push({ name, why: `a release carries at most ${maxFiles} files` });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (total + st.size > maxTotalBytes) {
|
|
141
|
+
skipped.push({ name, why: `a release carries at most ${maxTotalBytes} bytes in all` });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
total += st.size;
|
|
145
|
+
files.push({ name, path, size: st.size });
|
|
146
|
+
}
|
|
147
|
+
return { manifest, files, skipped };
|
|
148
|
+
}
|
|
149
|
+
const httpsUpload = ({ url, token, path, size }) => new Promise((resolve, reject) => {
|
|
150
|
+
const req = httpsRequest(url, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: {
|
|
153
|
+
authorization: `Bearer ${token}`,
|
|
154
|
+
accept: 'application/vnd.github+json',
|
|
155
|
+
'x-github-api-version': '2022-11-28',
|
|
156
|
+
'content-type': 'application/octet-stream',
|
|
157
|
+
'content-length': String(size),
|
|
158
|
+
'user-agent': 'firefunc-runner',
|
|
159
|
+
},
|
|
160
|
+
timeout: 30 * 60_000,
|
|
161
|
+
}, (res) => {
|
|
162
|
+
res.resume();
|
|
163
|
+
res.on('end', () => resolve({ status: res.statusCode ?? 0 }));
|
|
164
|
+
});
|
|
165
|
+
req.on('timeout', () => req.destroy(new Error('the upload timed out')));
|
|
166
|
+
req.on('error', reject);
|
|
167
|
+
const stream = createReadStream(path);
|
|
168
|
+
stream.on('error', (e) => req.destroy(e));
|
|
169
|
+
stream.pipe(req);
|
|
170
|
+
});
|
|
171
|
+
export function assetUrl(uploadUrl, name) {
|
|
172
|
+
if (!uploadUrl)
|
|
173
|
+
return null;
|
|
174
|
+
const base = uploadUrl.replace(/\{[^}]*\}$/, '');
|
|
175
|
+
let u;
|
|
176
|
+
try {
|
|
177
|
+
u = new URL(base);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (u.protocol !== 'https:' || !/(^|\.)github\.com$/.test(u.hostname))
|
|
183
|
+
return null;
|
|
184
|
+
u.searchParams.set('name', name);
|
|
185
|
+
return u.toString();
|
|
186
|
+
}
|
|
187
|
+
export async function stageDraftRelease(opts) {
|
|
188
|
+
const { repo, offer, dir, cred, log } = opts;
|
|
189
|
+
const fetcher = opts.fetcher ?? fetch;
|
|
190
|
+
const upload = opts.upload ?? httpsUpload;
|
|
191
|
+
const api = opts.apiBase ?? 'https://api.github.com';
|
|
192
|
+
const scan = scanReleaseFolder(dir, offer);
|
|
193
|
+
for (const s of scan.skipped)
|
|
194
|
+
log(`release file ${s.name} not staged: ${s.why}`);
|
|
195
|
+
if (scan.manifest && 'problem' in scan.manifest) {
|
|
196
|
+
log(`no draft release: ${scan.manifest.problem}`);
|
|
197
|
+
return { staged: false, why: scan.manifest.problem, tag: null };
|
|
198
|
+
}
|
|
199
|
+
const manifest = scan.manifest;
|
|
200
|
+
const tag = manifest?.tag ?? (offer.tag && !releaseTagProblem(offer.tag) ? offer.tag : null);
|
|
201
|
+
if (!tag) {
|
|
202
|
+
const why = `${RELEASE_FOLDER}/${RELEASE_MANIFEST} named no tag, and the line names none`;
|
|
203
|
+
log(`no draft release: ${why}`);
|
|
204
|
+
return { staged: false, why, tag: null };
|
|
205
|
+
}
|
|
206
|
+
if (scan.files.length === 0) {
|
|
207
|
+
const why = `${RELEASE_FOLDER}/ held no file to publish`;
|
|
208
|
+
log(`no draft release for ${tag}: ${why} (the release is published without files)`);
|
|
209
|
+
return { staged: false, why, tag };
|
|
210
|
+
}
|
|
211
|
+
const headers = {
|
|
212
|
+
authorization: `Bearer ${cred.token}`,
|
|
213
|
+
accept: 'application/vnd.github+json',
|
|
214
|
+
'x-github-api-version': '2022-11-28',
|
|
215
|
+
'content-type': 'application/json',
|
|
216
|
+
'user-agent': 'firefunc-runner',
|
|
217
|
+
};
|
|
218
|
+
try {
|
|
219
|
+
let draft = null;
|
|
220
|
+
const list = await fetcher(`${api}/repos/${repo}/releases?per_page=100`, { headers });
|
|
221
|
+
if (list.ok) {
|
|
222
|
+
const rows = (await list.json());
|
|
223
|
+
draft = rows.find((r) => r.draft === true && r.tag_name === tag) ?? null;
|
|
224
|
+
}
|
|
225
|
+
if (!draft) {
|
|
226
|
+
const name = manifest?.name ?? offer.name ?? null;
|
|
227
|
+
const res = await fetcher(`${api}/repos/${repo}/releases`, {
|
|
228
|
+
method: 'POST',
|
|
229
|
+
headers,
|
|
230
|
+
body: JSON.stringify({
|
|
231
|
+
tag_name: tag,
|
|
232
|
+
...(name ? { name } : {}),
|
|
233
|
+
...(manifest?.notes ? { body: manifest.notes } : {}),
|
|
234
|
+
draft: true,
|
|
235
|
+
prerelease: manifest?.prerelease ?? offer.prerelease === true,
|
|
236
|
+
...(opts.base ? { target_commitish: opts.base } : {}),
|
|
237
|
+
}),
|
|
238
|
+
});
|
|
239
|
+
if (!res.ok) {
|
|
240
|
+
const why = `GitHub refused the draft release (${res.status})${res.status === 403 || res.status === 404 ? ' — the run’s token may not create releases in this repository' : ''}`;
|
|
241
|
+
log(`no draft release for ${tag}: ${why}`);
|
|
242
|
+
return { staged: false, why, tag };
|
|
243
|
+
}
|
|
244
|
+
draft = (await res.json());
|
|
245
|
+
}
|
|
246
|
+
const draftId = Number(draft.id);
|
|
247
|
+
if (!Number.isSafeInteger(draftId) || draftId < 1) {
|
|
248
|
+
return { staged: false, why: 'GitHub answered the draft release without an id', tag };
|
|
249
|
+
}
|
|
250
|
+
const there = new Map((draft.assets ?? []).map((a) => [a.name, a]));
|
|
251
|
+
const staged = [];
|
|
252
|
+
const skipped = [...scan.skipped];
|
|
253
|
+
for (const f of scan.files) {
|
|
254
|
+
const have = there.get(f.name);
|
|
255
|
+
if (have && have.size === f.size) {
|
|
256
|
+
staged.push({ name: f.name, size: f.size });
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (have?.id) {
|
|
260
|
+
await fetcher(`${api}/repos/${repo}/releases/assets/${have.id}`, {
|
|
261
|
+
method: 'DELETE',
|
|
262
|
+
headers,
|
|
263
|
+
}).catch(() => undefined);
|
|
264
|
+
}
|
|
265
|
+
const url = assetUrl(draft.upload_url, f.name);
|
|
266
|
+
if (!url) {
|
|
267
|
+
skipped.push({ name: f.name, why: 'GitHub gave no address to upload it to' });
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
const res = await upload({ url, token: cred.token, path: f.path, size: f.size });
|
|
272
|
+
if (res.status >= 200 && res.status < 300) {
|
|
273
|
+
staged.push({ name: f.name, size: f.size });
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
skipped.push({ name: f.name, why: `the upload answered ${res.status}` });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
skipped.push({ name: f.name, why: `it could not be uploaded (${e.name})` });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (const s of skipped.slice(scan.skipped.length)) {
|
|
284
|
+
log(`release file ${s.name} not staged: ${s.why}`);
|
|
285
|
+
}
|
|
286
|
+
log(`staged draft release ${tag} on ${repo} with ${staged.length} file(s)${staged.length ? `: ${staged.map((s) => s.name).join(', ')}` : ''}`);
|
|
287
|
+
return {
|
|
288
|
+
draftId,
|
|
289
|
+
tag,
|
|
290
|
+
url: typeof draft.html_url === 'string' ? draft.html_url : null,
|
|
291
|
+
files: staged,
|
|
292
|
+
skipped,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
const why = `GitHub could not be reached to stage the draft release (${e.name})`;
|
|
297
|
+
log(`no draft release for ${tag}: ${why}`);
|
|
298
|
+
return { staged: false, why, tag };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=release-draft.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type DeviceReport } from './device-lease.js';
|
|
2
|
+
import { type MachineProfile } from './machine-profile.js';
|
|
3
|
+
export type ResourceReading = {
|
|
4
|
+
freeBytes: number;
|
|
5
|
+
totalBytes: number | null;
|
|
6
|
+
floorBytes: number;
|
|
7
|
+
};
|
|
8
|
+
export type ResourcesReport = {
|
|
9
|
+
disk: ResourceReading | null;
|
|
10
|
+
memory: ResourceReading | null;
|
|
11
|
+
timeLimitMinutes: number;
|
|
12
|
+
devices?: DeviceReport;
|
|
13
|
+
workDir?: WorkDirReport;
|
|
14
|
+
cpus?: number;
|
|
15
|
+
load1PerCore?: number;
|
|
16
|
+
maxHeavyRuns?: number;
|
|
17
|
+
profile?: MachineProfile;
|
|
18
|
+
};
|
|
19
|
+
export declare function heavyRunBudget(setting: unknown, memBytes?: number): number;
|
|
20
|
+
export declare function processorReading(os?: NodeJS.Platform, read?: {
|
|
21
|
+
cores?: () => number;
|
|
22
|
+
load?: () => number[];
|
|
23
|
+
}): {
|
|
24
|
+
cpus: number;
|
|
25
|
+
load1PerCore: number | null;
|
|
26
|
+
};
|
|
27
|
+
export type WorkDirReport = {
|
|
28
|
+
set: boolean;
|
|
29
|
+
usable: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare const DEFAULT_MIN_FREE_DISK_GB = 5;
|
|
32
|
+
export declare const DEFAULT_MIN_FREE_MEMORY_GB = 1;
|
|
33
|
+
export declare const DEFAULT_JOB_TIMEOUT_MINUTES = 20;
|
|
34
|
+
export declare function floorBytes(gb: unknown, fallbackGb: number): number;
|
|
35
|
+
export declare function diskOf(dir: string): {
|
|
36
|
+
freeBytes: number;
|
|
37
|
+
totalBytes: number;
|
|
38
|
+
} | null;
|
|
39
|
+
export declare function leastFreeDisk(dirs: readonly string[], read?: (dir: string) => {
|
|
40
|
+
freeBytes: number;
|
|
41
|
+
totalBytes: number;
|
|
42
|
+
} | null): {
|
|
43
|
+
freeBytes: number;
|
|
44
|
+
totalBytes: number;
|
|
45
|
+
} | null;
|
|
46
|
+
export declare function macAvailableFromVmStat(out: string): number | null;
|
|
47
|
+
export declare function linuxAvailableFromMeminfo(text: string): number | null;
|
|
48
|
+
export declare function availableMemory(os?: NodeJS.Platform): number;
|
|
49
|
+
export type ResourceCfg = {
|
|
50
|
+
workDir?: string;
|
|
51
|
+
minFreeDiskGB?: number;
|
|
52
|
+
minFreeMemoryGB?: number;
|
|
53
|
+
jobTimeoutMinutes?: number;
|
|
54
|
+
repos?: Record<string, string>;
|
|
55
|
+
devices?: string[];
|
|
56
|
+
maxEmulators?: number;
|
|
57
|
+
maxHeavyRuns?: number;
|
|
58
|
+
claudeEnv?: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
export declare function hasDeviceTools(cfg: Pick<ResourceCfg, 'devices' | 'claudeEnv'>, has?: (name: string, pathVar: string) => boolean): boolean;
|
|
61
|
+
export declare function readResources(cfg: ResourceCfg, runnerDir: string, deps?: {
|
|
62
|
+
disk?: (dirs: readonly string[]) => {
|
|
63
|
+
freeBytes: number;
|
|
64
|
+
totalBytes: number;
|
|
65
|
+
} | null;
|
|
66
|
+
memory?: () => number;
|
|
67
|
+
totalMemory?: () => number;
|
|
68
|
+
workDir?: () => WorkDirReport;
|
|
69
|
+
devices?: () => DeviceReport;
|
|
70
|
+
processor?: () => {
|
|
71
|
+
cpus: number;
|
|
72
|
+
load1PerCore: number | null;
|
|
73
|
+
};
|
|
74
|
+
profile?: () => MachineProfile | null;
|
|
75
|
+
}): ResourcesReport;
|
|
76
|
+
export declare function workDirReport(): WorkDirReport;
|
|
77
|
+
export declare function shortOf(r: ResourcesReport): Array<'disk' | 'memory'>;
|
|
78
|
+
export declare function resourceWatch(deps: {
|
|
79
|
+
read: () => ResourcesReport;
|
|
80
|
+
log: (msg: string) => void;
|
|
81
|
+
everyMs?: number;
|
|
82
|
+
now?: () => number;
|
|
83
|
+
}): {
|
|
84
|
+
report: () => ResourcesReport;
|
|
85
|
+
short: () => boolean;
|
|
86
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync, statfsSync } from 'node:fs';
|
|
3
|
+
import { availableParallelism, cpus, freemem, loadavg, platform, tmpdir, totalmem } from 'node:os';
|
|
4
|
+
import { deviceReport } from './device-lease.js';
|
|
5
|
+
import { deviceLockDir } from './locks.js';
|
|
6
|
+
import { commandOnPath, runPath } from './machine-commands.js';
|
|
7
|
+
import { machineProfile } from './machine-profile.js';
|
|
8
|
+
import { workDir, workDirFailure } from './work-dir.js';
|
|
9
|
+
export function heavyRunBudget(setting, memBytes = totalmem()) {
|
|
10
|
+
if (typeof setting === 'number' && Number.isInteger(setting) && setting >= 1) {
|
|
11
|
+
return Math.min(16, setting);
|
|
12
|
+
}
|
|
13
|
+
return Math.max(1, Math.floor(memBytes / (8 * 1024 ** 3)));
|
|
14
|
+
}
|
|
15
|
+
export function processorReading(os = platform(), read = {}) {
|
|
16
|
+
let n = 0;
|
|
17
|
+
try {
|
|
18
|
+
n = read.cores ? read.cores() : availableParallelism?.() || cpus().length;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
n = 0;
|
|
22
|
+
}
|
|
23
|
+
const cores = Number.isInteger(n) && n > 0 ? n : 1;
|
|
24
|
+
if (os === 'win32')
|
|
25
|
+
return { cpus: cores, load1PerCore: null };
|
|
26
|
+
const one = (read.load ?? loadavg)()[0];
|
|
27
|
+
return {
|
|
28
|
+
cpus: cores,
|
|
29
|
+
load1PerCore: typeof one === 'number' && Number.isFinite(one) && one >= 0
|
|
30
|
+
? Math.round((one / cores) * 100) / 100
|
|
31
|
+
: null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export const DEFAULT_MIN_FREE_DISK_GB = 5;
|
|
35
|
+
export const DEFAULT_MIN_FREE_MEMORY_GB = 1;
|
|
36
|
+
export const DEFAULT_JOB_TIMEOUT_MINUTES = 20;
|
|
37
|
+
const GB = 1e9;
|
|
38
|
+
export function floorBytes(gb, fallbackGb) {
|
|
39
|
+
return typeof gb === 'number' && Number.isFinite(gb) && gb >= 0
|
|
40
|
+
? Math.round(gb * GB)
|
|
41
|
+
: fallbackGb * GB;
|
|
42
|
+
}
|
|
43
|
+
export function diskOf(dir) {
|
|
44
|
+
try {
|
|
45
|
+
if (!existsSync(dir))
|
|
46
|
+
return null;
|
|
47
|
+
const s = statfsSync(dir);
|
|
48
|
+
return { freeBytes: s.bavail * s.bsize, totalBytes: s.blocks * s.bsize };
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function leastFreeDisk(dirs, read = diskOf) {
|
|
55
|
+
let least = null;
|
|
56
|
+
for (const d of new Set(dirs)) {
|
|
57
|
+
const r = read(d);
|
|
58
|
+
if (r && (!least || r.freeBytes < least.freeBytes))
|
|
59
|
+
least = r;
|
|
60
|
+
}
|
|
61
|
+
return least;
|
|
62
|
+
}
|
|
63
|
+
export function macAvailableFromVmStat(out) {
|
|
64
|
+
const page = Number(/page size of (\d+) bytes/.exec(out)?.[1]);
|
|
65
|
+
if (!Number.isFinite(page) || page <= 0)
|
|
66
|
+
return null;
|
|
67
|
+
const pages = (name) => {
|
|
68
|
+
const m = new RegExp(`Pages ${name}:\\s+(\\d+)`).exec(out);
|
|
69
|
+
return m ? Number(m[1]) : 0;
|
|
70
|
+
};
|
|
71
|
+
const free = /Pages free:\s+\d+/.test(out) ? pages('free') : null;
|
|
72
|
+
if (free === null)
|
|
73
|
+
return null;
|
|
74
|
+
return (free + pages('inactive') + pages('speculative')) * page;
|
|
75
|
+
}
|
|
76
|
+
export function linuxAvailableFromMeminfo(text) {
|
|
77
|
+
const kb = /^MemAvailable:\s+(\d+)\s+kB/m.exec(text)?.[1];
|
|
78
|
+
return kb ? Number(kb) * 1024 : null;
|
|
79
|
+
}
|
|
80
|
+
export function availableMemory(os = platform()) {
|
|
81
|
+
try {
|
|
82
|
+
if (os === 'darwin') {
|
|
83
|
+
const out = execFileSync('vm_stat', [], { encoding: 'utf8', timeout: 2_000 });
|
|
84
|
+
const v = macAvailableFromVmStat(out);
|
|
85
|
+
if (v !== null)
|
|
86
|
+
return v;
|
|
87
|
+
}
|
|
88
|
+
else if (os === 'linux') {
|
|
89
|
+
const v = linuxAvailableFromMeminfo(readFileSync('/proc/meminfo', 'utf8'));
|
|
90
|
+
if (v !== null)
|
|
91
|
+
return v;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
}
|
|
96
|
+
return freemem();
|
|
97
|
+
}
|
|
98
|
+
export function hasDeviceTools(cfg, has = (n, p) => commandOnPath(n, p)) {
|
|
99
|
+
if (Array.isArray(cfg.devices) && cfg.devices.length > 0)
|
|
100
|
+
return true;
|
|
101
|
+
return has('adb', runPath(cfg));
|
|
102
|
+
}
|
|
103
|
+
export function readResources(cfg, runnerDir, deps = {}) {
|
|
104
|
+
const dirs = [
|
|
105
|
+
tmpdir(),
|
|
106
|
+
...(cfg.workDir ? [cfg.workDir] : []),
|
|
107
|
+
runnerDir,
|
|
108
|
+
...Object.values(cfg.repos ?? {}),
|
|
109
|
+
];
|
|
110
|
+
const disk = (deps.disk ?? ((d) => leastFreeDisk(d)))(dirs);
|
|
111
|
+
let mem = null;
|
|
112
|
+
try {
|
|
113
|
+
mem = (deps.memory ?? availableMemory)();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
mem = null;
|
|
117
|
+
}
|
|
118
|
+
const limit = typeof cfg.jobTimeoutMinutes === 'number' && cfg.jobTimeoutMinutes > 0
|
|
119
|
+
? cfg.jobTimeoutMinutes
|
|
120
|
+
: DEFAULT_JOB_TIMEOUT_MINUTES;
|
|
121
|
+
const total = (deps.totalMemory ?? totalmem)();
|
|
122
|
+
const cpu = (() => {
|
|
123
|
+
try {
|
|
124
|
+
return (deps.processor ?? (() => processorReading()))();
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
return {
|
|
131
|
+
disk: disk
|
|
132
|
+
? {
|
|
133
|
+
freeBytes: Math.max(0, Math.floor(disk.freeBytes)),
|
|
134
|
+
totalBytes: Math.floor(disk.totalBytes),
|
|
135
|
+
floorBytes: floorBytes(cfg.minFreeDiskGB, DEFAULT_MIN_FREE_DISK_GB),
|
|
136
|
+
}
|
|
137
|
+
: null,
|
|
138
|
+
memory: mem !== null && Number.isFinite(mem)
|
|
139
|
+
? {
|
|
140
|
+
freeBytes: Math.max(0, Math.floor(mem)),
|
|
141
|
+
totalBytes: total,
|
|
142
|
+
floorBytes: floorBytes(cfg.minFreeMemoryGB, DEFAULT_MIN_FREE_MEMORY_GB),
|
|
143
|
+
}
|
|
144
|
+
: null,
|
|
145
|
+
timeLimitMinutes: Math.round(limit),
|
|
146
|
+
workDir: deps.workDir ? deps.workDir() : workDirReport(),
|
|
147
|
+
devices: (() => {
|
|
148
|
+
try {
|
|
149
|
+
if (deps.devices)
|
|
150
|
+
return deps.devices();
|
|
151
|
+
return hasDeviceTools(cfg) ? deviceReport(deviceLockDir(runnerDir), cfg) : undefined;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
})(),
|
|
157
|
+
...(cpu ? { cpus: cpu.cpus } : {}),
|
|
158
|
+
...(cpu && cpu.load1PerCore !== null ? { load1PerCore: cpu.load1PerCore } : {}),
|
|
159
|
+
maxHeavyRuns: heavyRunBudget(cfg.maxHeavyRuns, total),
|
|
160
|
+
...(() => {
|
|
161
|
+
try {
|
|
162
|
+
const p = deps.profile ? deps.profile() : machineProfile(runPath(cfg));
|
|
163
|
+
return p ? { profile: p } : {};
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
})(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export function workDirReport() {
|
|
172
|
+
const set = workDir() !== null;
|
|
173
|
+
return { set, usable: !set || workDirFailure() === null };
|
|
174
|
+
}
|
|
175
|
+
export function shortOf(r) {
|
|
176
|
+
const out = [];
|
|
177
|
+
if (r.disk && r.disk.floorBytes > 0 && r.disk.freeBytes < r.disk.floorBytes)
|
|
178
|
+
out.push('disk');
|
|
179
|
+
if (r.memory && r.memory.floorBytes > 0 && r.memory.freeBytes < r.memory.floorBytes)
|
|
180
|
+
out.push('memory');
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
const gb = (b) => `${(b / GB).toFixed(1)} GB`;
|
|
184
|
+
export function resourceWatch(deps) {
|
|
185
|
+
const every = deps.everyMs ?? 15_000;
|
|
186
|
+
const now = deps.now ?? (() => Date.now());
|
|
187
|
+
let last = null;
|
|
188
|
+
let at = -Infinity;
|
|
189
|
+
let wasShort = [];
|
|
190
|
+
const report = () => {
|
|
191
|
+
if (!last || now() - at >= every) {
|
|
192
|
+
last = deps.read();
|
|
193
|
+
at = now();
|
|
194
|
+
}
|
|
195
|
+
return last;
|
|
196
|
+
};
|
|
197
|
+
const short = () => {
|
|
198
|
+
const r = report();
|
|
199
|
+
const s = shortOf(r);
|
|
200
|
+
const key = s.join(',');
|
|
201
|
+
if (key !== wasShort.join(',')) {
|
|
202
|
+
if (s.length) {
|
|
203
|
+
const words = s.map((k) => k === 'disk'
|
|
204
|
+
? `free disk ${gb(r.disk.freeBytes)} is under the ${gb(r.disk.floorBytes)} floor (minFreeDiskGB)`
|
|
205
|
+
: `available memory ${gb(r.memory.freeBytes)} is under the ${gb(r.memory.floorBytes)} floor (minFreeMemoryGB)`);
|
|
206
|
+
deps.log(`${words.join('; ')} — claiming no new work until there is room; runs already going carry on`);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
deps.log('there is room again — claiming work');
|
|
210
|
+
}
|
|
211
|
+
wasShort = s;
|
|
212
|
+
}
|
|
213
|
+
return s.length > 0;
|
|
214
|
+
};
|
|
215
|
+
return { report, short };
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type RunnerConfig } from './config.js';
|
|
2
|
+
export type RestartIdleDeps = {
|
|
3
|
+
load: () => RunnerConfig | null;
|
|
4
|
+
save: (cfg: RunnerConfig) => void;
|
|
5
|
+
held: () => string[];
|
|
6
|
+
restart: () => Promise<{
|
|
7
|
+
ok: boolean;
|
|
8
|
+
message: string;
|
|
9
|
+
installed: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
sleep: (ms: number) => Promise<void>;
|
|
12
|
+
now: () => number;
|
|
13
|
+
log: (line: string) => void;
|
|
14
|
+
settleMs?: number;
|
|
15
|
+
pollMs?: number;
|
|
16
|
+
maxWaitMs?: number | null;
|
|
17
|
+
};
|
|
18
|
+
export type RestartIdleResult = {
|
|
19
|
+
ok: boolean;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const DRAIN_SETTLE_MS = 70000;
|
|
23
|
+
export declare function restartWhenIdle(d: RestartIdleDeps): Promise<RestartIdleResult>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { drainSetting, isDraining } from './config.js';
|
|
2
|
+
export const DRAIN_SETTLE_MS = 70_000;
|
|
3
|
+
export async function restartWhenIdle(d) {
|
|
4
|
+
const cfg = d.load();
|
|
5
|
+
if (!cfg)
|
|
6
|
+
return { ok: false, message: 'Not connected. Run "firefunc-runner connect <token>".' };
|
|
7
|
+
const drainedBefore = isDraining(cfg);
|
|
8
|
+
if (!drainedBefore)
|
|
9
|
+
d.save(drainSetting(cfg, true));
|
|
10
|
+
const lift = () => {
|
|
11
|
+
if (drainedBefore)
|
|
12
|
+
return;
|
|
13
|
+
const now = d.load();
|
|
14
|
+
if (now)
|
|
15
|
+
d.save(drainSetting(now, false));
|
|
16
|
+
};
|
|
17
|
+
const settle = d.settleMs ?? DRAIN_SETTLE_MS;
|
|
18
|
+
const poll = d.pollMs ?? 10_000;
|
|
19
|
+
const started = d.now();
|
|
20
|
+
d.log('Draining: the runner finishes the runs it holds and takes nothing new; it restarts once none is left.');
|
|
21
|
+
let told = -1;
|
|
22
|
+
for (;;) {
|
|
23
|
+
const held = d.held();
|
|
24
|
+
const waited = d.now() - started;
|
|
25
|
+
if (held.length === 0 && waited >= settle)
|
|
26
|
+
break;
|
|
27
|
+
if (d.maxWaitMs != null && waited >= d.maxWaitMs) {
|
|
28
|
+
lift();
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
message: `Not restarted: ${held.length} run${held.length === 1 ? ' is' : 's are'} still running after ${Math.round(waited / 60_000)} min. ` +
|
|
32
|
+
(drainedBefore
|
|
33
|
+
? 'The runner stays drained, as it was. '
|
|
34
|
+
: 'The drain was lifted, so it takes work again. ') +
|
|
35
|
+
'Run "firefunc-runner restart --when-idle" again without --max-wait to wait for them.',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (held.length !== told) {
|
|
39
|
+
told = held.length;
|
|
40
|
+
d.log(held.length > 0
|
|
41
|
+
? `waiting for ${held.length} run${held.length === 1 ? '' : 's'} to finish: ${held.join(', ')}`
|
|
42
|
+
: 'no run held — waiting a moment for the runner to read the drain');
|
|
43
|
+
}
|
|
44
|
+
await d.sleep(poll);
|
|
45
|
+
}
|
|
46
|
+
const res = await d.restart();
|
|
47
|
+
if (!res.installed) {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
message: 'Idle: the runner holds no run, and stays drained. No service is installed, so restart it yourself — stop it with Ctrl-C where it runs and start it again with "firefunc-runner start" — then run "firefunc-runner resume" so it takes work again.',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (!res.ok) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
message: `${res.message}\nThe runner holds no run and stays drained; restart the service yourself, then run "firefunc-runner resume".`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
lift();
|
|
60
|
+
return {
|
|
61
|
+
ok: true,
|
|
62
|
+
message: drainedBefore
|
|
63
|
+
? 'Restarted while idle. It was drained before, so it stays drained: run "firefunc-runner resume" to take work again.'
|
|
64
|
+
: 'Restarted while idle, and the drain is lifted: it takes work again within a minute.',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=restart-idle.js.map
|