@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.
- package/README.md +32 -0
- package/dist/activity.d.ts +2 -0
- package/dist/activity.js +3 -0
- package/dist/alive.d.ts +8 -0
- package/dist/alive.js +29 -0
- package/dist/api.d.ts +32 -0
- package/dist/api.js +18 -2
- package/dist/ask-replace.d.ts +6 -0
- package/dist/ask-replace.js +49 -0
- package/dist/awake-timer.d.ts +8 -0
- package/dist/awake-timer.js +30 -0
- package/dist/brief.js +2 -2
- package/dist/build-info.json +2 -2
- package/dist/clean-up.d.ts +29 -0
- package/dist/clean-up.js +131 -0
- package/dist/cli.js +141 -16
- package/dist/config.d.ts +7 -0
- package/dist/cut.d.ts +2 -0
- package/dist/cut.js +20 -3
- package/dist/daemon.js +147 -6
- package/dist/disk-reclaim.d.ts +40 -0
- package/dist/disk-reclaim.js +95 -0
- package/dist/drives.d.ts +29 -0
- package/dist/drives.js +270 -0
- package/dist/engine-account.d.ts +1 -1
- package/dist/engine-account.js +12 -1
- package/dist/engines/types.d.ts +1 -1
- package/dist/exec.js +5 -6
- package/dist/firefunc/automations.js +3 -3
- package/dist/firefunc/machines.js +20 -0
- package/dist/firefunc/main.js +1 -1
- package/dist/firefunc/oauth-login.js +1 -1
- package/dist/gh-repos.d.ts +41 -0
- package/dist/gh-repos.js +68 -0
- package/dist/git-auth.d.ts +1 -0
- package/dist/git-auth.js +1 -1
- package/dist/held.d.ts +4 -2
- package/dist/held.js +19 -5
- package/dist/job.d.ts +1 -0
- package/dist/job.js +148 -33
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +63 -0
- package/dist/live-runner.d.ts +47 -0
- package/dist/live-runner.js +109 -0
- package/dist/local-tools.d.ts +31 -0
- package/dist/local-tools.js +178 -0
- package/dist/machine-logins.d.ts +4 -0
- package/dist/machine-logins.js +31 -0
- package/dist/mcp-login.d.ts +3 -0
- package/dist/mcp-login.js +34 -4
- package/dist/mcp-tools.d.ts +23 -0
- package/dist/mcp-tools.js +122 -0
- package/dist/mcp.d.ts +8 -0
- package/dist/mcp.js +37 -3
- package/dist/newer-runner.d.ts +9 -0
- package/dist/newer-runner.js +38 -0
- package/dist/pool.d.ts +1 -0
- package/dist/pool.js +1 -0
- package/dist/pr-title.d.ts +1 -0
- package/dist/pr-title.js +7 -0
- package/dist/repo-path.d.ts +15 -0
- package/dist/repo-path.js +56 -0
- package/dist/resources.d.ts +38 -0
- package/dist/resources.js +47 -1
- package/dist/restart-idle.d.ts +1 -0
- package/dist/restart-idle.js +20 -5
- package/dist/run-folders.d.ts +25 -0
- package/dist/run-folders.js +89 -0
- package/dist/update.d.ts +41 -0
- package/dist/update.js +176 -0
- package/dist/viewer.d.ts +1 -1
- package/dist/viewer.js +3 -1
- package/dist/work-dir.d.ts +30 -0
- package/dist/work-dir.js +153 -22
- package/dist/worktrees.d.ts +7 -0
- package/dist/worktrees.js +26 -5
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
export const RECLAIM_IN_USE_MS = 15 * 60_000;
|
|
4
|
+
const GB = 1024 ** 3;
|
|
5
|
+
export const gbWords = (b) => `${(b / GB).toFixed(1)} GB`;
|
|
6
|
+
function lastUsedOf(dir) {
|
|
7
|
+
let newest = 0;
|
|
8
|
+
try {
|
|
9
|
+
newest = statSync(dir).mtimeMs;
|
|
10
|
+
for (const n of readdirSync(dir)) {
|
|
11
|
+
try {
|
|
12
|
+
newest = Math.max(newest, statSync(join(dir, n)).mtimeMs);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
return newest;
|
|
22
|
+
}
|
|
23
|
+
export function reclaimables(runnerDir, now = Date.now()) {
|
|
24
|
+
const root = join(runnerDir, 'cargo-target');
|
|
25
|
+
if (!existsSync(root))
|
|
26
|
+
return [];
|
|
27
|
+
const out = [];
|
|
28
|
+
let names = [];
|
|
29
|
+
try {
|
|
30
|
+
names = readdirSync(root);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
for (const n of names) {
|
|
36
|
+
const p = join(root, n);
|
|
37
|
+
try {
|
|
38
|
+
if (!statSync(p).isDirectory())
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const lastUsed = lastUsedOf(p);
|
|
45
|
+
if (now - lastUsed < RECLAIM_IN_USE_MS)
|
|
46
|
+
continue;
|
|
47
|
+
out.push({ path: p, label: `the shared Rust build target for ${n}`, lastUsed });
|
|
48
|
+
}
|
|
49
|
+
return out.sort((a, b) => a.lastUsed - b.lastUsed);
|
|
50
|
+
}
|
|
51
|
+
let lastReport = null;
|
|
52
|
+
export function lastReclaim() {
|
|
53
|
+
return lastReport;
|
|
54
|
+
}
|
|
55
|
+
export function noteReclaim(r) {
|
|
56
|
+
lastReport = r;
|
|
57
|
+
}
|
|
58
|
+
export async function reclaimDisk(deps) {
|
|
59
|
+
const remove = deps.remove ?? ((p) => rmSync(p, { recursive: true, force: true, maxRetries: 2 }));
|
|
60
|
+
let freed = 0;
|
|
61
|
+
const removed = [];
|
|
62
|
+
try {
|
|
63
|
+
const b = await deps.cleanUp();
|
|
64
|
+
if (b > 0) {
|
|
65
|
+
freed += b;
|
|
66
|
+
deps.log(`low on disk: the clean-up freed ${gbWords(b)} (finished run folders, leftover temp)`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
}
|
|
71
|
+
for (const r of reclaimables(deps.runnerDir, deps.now?.() ?? Date.now())) {
|
|
72
|
+
if (!deps.short())
|
|
73
|
+
break;
|
|
74
|
+
const bytes = (await deps.sizeOf(r.path).catch(() => null)) ?? 0;
|
|
75
|
+
try {
|
|
76
|
+
remove(r.path);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
deps.log(`low on disk: could not remove ${r.label} (${r.path}): ${String(err)}`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
freed += bytes;
|
|
83
|
+
removed.push(r.path);
|
|
84
|
+
deps.log(`low on disk: removed ${r.label} (${r.path}), freeing ${gbWords(bytes)} — FireFunc made it, and the next build makes it again`);
|
|
85
|
+
}
|
|
86
|
+
return { freedBytes: freed, removed, stillShort: deps.short() };
|
|
87
|
+
}
|
|
88
|
+
export function stillShortWords(input) {
|
|
89
|
+
const own = input.own.filter((o) => (o.bytes ?? 0) > 0);
|
|
90
|
+
const held = own.length
|
|
91
|
+
? ` FireFunc's own folders hold ${own.map((o) => `${o.label} ${gbWords(o.bytes)}`).join(', ')}; it removed everything it could rebuild.`
|
|
92
|
+
: " FireFunc's own folders hold nothing it could remove.";
|
|
93
|
+
return `${input.machine} has ${gbWords(input.freeBytes)} free and keeps ${gbWords(input.floorBytes)} free, so it takes no new work.${held} The rest of the disk is used outside FireFunc. Fix: free space on ${input.machine}, or lower its floor (minFreeDiskGB in the runner's config).`;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=disk-reclaim.js.map
|
package/dist/drives.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type DriveReport = {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
path: string;
|
|
5
|
+
freeBytes: number;
|
|
6
|
+
totalBytes: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function dirBytes(dir: string, budgetMs?: number): Promise<number | null>;
|
|
9
|
+
export declare function parseWmicDrives(out: string): Array<{
|
|
10
|
+
id: string;
|
|
11
|
+
freeBytes: number;
|
|
12
|
+
totalBytes: number;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function parseCimDrives(out: string): Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
freeBytes: number;
|
|
17
|
+
totalBytes: number;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function parseDfMounts(out: string): Array<{
|
|
20
|
+
filesystem: string;
|
|
21
|
+
mount: string;
|
|
22
|
+
freeBytes: number;
|
|
23
|
+
totalBytes: number;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function mountOf(path: string, mounts: readonly string[]): string | null;
|
|
26
|
+
export declare function pickLinuxMounts(mounts: readonly string[], home: string, user: string, canWrite?: (p: string) => boolean): string[];
|
|
27
|
+
export declare function readDrives(os?: NodeJS.Platform): DriveReport[];
|
|
28
|
+
export declare function driveReport(now?: number, read?: () => DriveReport[]): DriveReport[];
|
|
29
|
+
export declare function rootBytes(root: string, now?: number, walk?: (dir: string) => Promise<number | null>): number | null;
|
package/dist/drives.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { accessSync, constants, readdirSync, statSync } from 'node:fs';
|
|
3
|
+
import { homedir, platform, userInfo } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { lstat, readdir } from 'node:fs/promises';
|
|
6
|
+
import { diskOf } from './resources.js';
|
|
7
|
+
import { defaultWorkRoot } from './work-dir.js';
|
|
8
|
+
const TEN_MINUTES = 10 * 60_000;
|
|
9
|
+
export async function dirBytes(dir, budgetMs = 20_000) {
|
|
10
|
+
const until = Date.now() + budgetMs;
|
|
11
|
+
let total = 0;
|
|
12
|
+
const stack = [dir];
|
|
13
|
+
while (stack.length) {
|
|
14
|
+
if (Date.now() > until)
|
|
15
|
+
return null;
|
|
16
|
+
const d = stack.pop();
|
|
17
|
+
let names;
|
|
18
|
+
try {
|
|
19
|
+
names = await readdir(d);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
for (const n of names) {
|
|
25
|
+
const p = join(d, n);
|
|
26
|
+
try {
|
|
27
|
+
const st = await lstat(p);
|
|
28
|
+
if (st.isDirectory())
|
|
29
|
+
stack.push(p);
|
|
30
|
+
else
|
|
31
|
+
total += st.size;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return total;
|
|
38
|
+
}
|
|
39
|
+
export function parseWmicDrives(out) {
|
|
40
|
+
const lines = out
|
|
41
|
+
.split(/\r?\n/)
|
|
42
|
+
.map((l) => l.trim())
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
const header = lines.shift();
|
|
45
|
+
if (!header || !/deviceid/i.test(header))
|
|
46
|
+
return [];
|
|
47
|
+
const cols = header.split(/\s+/).map((c) => c.toLowerCase());
|
|
48
|
+
const iId = cols.indexOf('deviceid');
|
|
49
|
+
const iFree = cols.indexOf('freespace');
|
|
50
|
+
const iSize = cols.indexOf('size');
|
|
51
|
+
const rows = [];
|
|
52
|
+
for (const l of lines) {
|
|
53
|
+
const f = l.split(/\s+/);
|
|
54
|
+
const id = f[iId] ?? '';
|
|
55
|
+
const free = Number(f[iFree]);
|
|
56
|
+
const size = Number(f[iSize]);
|
|
57
|
+
if (!/^[A-Za-z]:$/.test(id) || !Number.isFinite(free) || !Number.isFinite(size))
|
|
58
|
+
continue;
|
|
59
|
+
rows.push({ id: id.toUpperCase(), freeBytes: free, totalBytes: size });
|
|
60
|
+
}
|
|
61
|
+
return rows;
|
|
62
|
+
}
|
|
63
|
+
export function parseCimDrives(out) {
|
|
64
|
+
let v;
|
|
65
|
+
try {
|
|
66
|
+
v = JSON.parse(out.trim() || 'null');
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
const list = Array.isArray(v) ? v : v && typeof v === 'object' ? [v] : [];
|
|
72
|
+
const rows = [];
|
|
73
|
+
for (const d of list) {
|
|
74
|
+
const id = typeof d.DeviceID === 'string' ? d.DeviceID : '';
|
|
75
|
+
const num = (x) => typeof x === 'number' || (typeof x === 'string' && x.trim()) ? Number(x) : NaN;
|
|
76
|
+
const free = num(d.FreeSpace);
|
|
77
|
+
const size = num(d.Size);
|
|
78
|
+
if (!/^[A-Za-z]:$/.test(id) || !Number.isFinite(free) || !Number.isFinite(size))
|
|
79
|
+
continue;
|
|
80
|
+
rows.push({ id: id.toUpperCase(), freeBytes: free, totalBytes: size });
|
|
81
|
+
}
|
|
82
|
+
return rows;
|
|
83
|
+
}
|
|
84
|
+
export function parseDfMounts(out) {
|
|
85
|
+
const rows = [];
|
|
86
|
+
for (const line of out.split(/\r?\n/).slice(1)) {
|
|
87
|
+
const m = /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+(.+)$/.exec(line.trim());
|
|
88
|
+
if (!m)
|
|
89
|
+
continue;
|
|
90
|
+
rows.push({
|
|
91
|
+
filesystem: m[1],
|
|
92
|
+
totalBytes: Number(m[2]) * 1024,
|
|
93
|
+
freeBytes: Number(m[4]) * 1024,
|
|
94
|
+
mount: m[5],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return rows;
|
|
98
|
+
}
|
|
99
|
+
const writable = (p) => {
|
|
100
|
+
try {
|
|
101
|
+
accessSync(p, constants.W_OK);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
export function mountOf(path, mounts) {
|
|
109
|
+
let best = null;
|
|
110
|
+
for (const m of mounts) {
|
|
111
|
+
const prefix = m === '/' ? '/' : `${m}/`;
|
|
112
|
+
if ((path === m || path.startsWith(prefix)) && (!best || m.length > best.length))
|
|
113
|
+
best = m;
|
|
114
|
+
}
|
|
115
|
+
return best;
|
|
116
|
+
}
|
|
117
|
+
export function pickLinuxMounts(mounts, home, user, canWrite = writable) {
|
|
118
|
+
const out = new Set();
|
|
119
|
+
if (mounts.includes('/'))
|
|
120
|
+
out.add('/');
|
|
121
|
+
const h = mountOf(home, mounts);
|
|
122
|
+
if (h)
|
|
123
|
+
out.add(h);
|
|
124
|
+
const under = ['/mnt/', `/media/${user}/`, `/run/media/${user}/`];
|
|
125
|
+
for (const m of mounts) {
|
|
126
|
+
if (under.some((u) => m.startsWith(u)) && canWrite(m))
|
|
127
|
+
out.add(m);
|
|
128
|
+
}
|
|
129
|
+
return [...out];
|
|
130
|
+
}
|
|
131
|
+
function run(cmd, args) {
|
|
132
|
+
try {
|
|
133
|
+
return execFileSync(cmd, args, {
|
|
134
|
+
encoding: 'utf8',
|
|
135
|
+
timeout: 5_000,
|
|
136
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
137
|
+
windowsHide: true,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export function readDrives(os = platform()) {
|
|
145
|
+
try {
|
|
146
|
+
const home = homedir();
|
|
147
|
+
const root = defaultWorkRoot();
|
|
148
|
+
const sized = (mount, fallback) => diskOf(mount) ?? fallback ?? null;
|
|
149
|
+
if (os === 'win32') {
|
|
150
|
+
const ps = run('powershell.exe', [
|
|
151
|
+
'-NoProfile',
|
|
152
|
+
'-NonInteractive',
|
|
153
|
+
'-Command',
|
|
154
|
+
'Get-CimInstance Win32_LogicalDisk -Filter DriveType=3 | Select-Object DeviceID,FreeSpace,Size | ConvertTo-Json -Compress',
|
|
155
|
+
]);
|
|
156
|
+
let rows = ps ? parseCimDrives(ps) : [];
|
|
157
|
+
if (!rows.length) {
|
|
158
|
+
const w = run('wmic', [
|
|
159
|
+
'logicaldisk',
|
|
160
|
+
'where',
|
|
161
|
+
'drivetype=3',
|
|
162
|
+
'get',
|
|
163
|
+
'deviceid,freespace,size',
|
|
164
|
+
]);
|
|
165
|
+
rows = w ? parseWmicDrives(w) : [];
|
|
166
|
+
}
|
|
167
|
+
const homeDrive = home.slice(0, 2).toUpperCase();
|
|
168
|
+
return rows.flatMap((r) => {
|
|
169
|
+
const d = sized(`${r.id}\\`, r);
|
|
170
|
+
if (!d)
|
|
171
|
+
return [];
|
|
172
|
+
return [
|
|
173
|
+
{
|
|
174
|
+
id: r.id,
|
|
175
|
+
label: r.id,
|
|
176
|
+
path: r.id === homeDrive ? root : `${r.id}\\FireFunc`,
|
|
177
|
+
freeBytes: d.freeBytes,
|
|
178
|
+
totalBytes: d.totalBytes,
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (os === 'darwin') {
|
|
184
|
+
const out = [];
|
|
185
|
+
const boot = statSync('/').dev;
|
|
186
|
+
const d = sized('/');
|
|
187
|
+
if (d)
|
|
188
|
+
out.push({ id: '/', label: 'Macintosh HD', path: root, ...d });
|
|
189
|
+
let names = [];
|
|
190
|
+
try {
|
|
191
|
+
names = readdirSync('/Volumes');
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
names = [];
|
|
195
|
+
}
|
|
196
|
+
for (const n of names) {
|
|
197
|
+
const p = join('/Volumes', n);
|
|
198
|
+
try {
|
|
199
|
+
if (statSync(p).dev === boot || !writable(p))
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const v = sized(p);
|
|
206
|
+
if (v)
|
|
207
|
+
out.push({ id: p, label: n, path: join(p, 'FireFunc'), ...v });
|
|
208
|
+
}
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
const df = run('df', ['-kP']);
|
|
212
|
+
const rows = df ? parseDfMounts(df) : [];
|
|
213
|
+
const mounts = rows.map((r) => r.mount);
|
|
214
|
+
let user = '';
|
|
215
|
+
try {
|
|
216
|
+
user = userInfo().username;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
user = process.env.USER ?? '';
|
|
220
|
+
}
|
|
221
|
+
const homeMount = mountOf(home, mounts);
|
|
222
|
+
return pickLinuxMounts(mounts, home, user).flatMap((m) => {
|
|
223
|
+
const r = rows.find((x) => x.mount === m);
|
|
224
|
+
const d = sized(m, r);
|
|
225
|
+
if (!d)
|
|
226
|
+
return [];
|
|
227
|
+
return [
|
|
228
|
+
{
|
|
229
|
+
id: m,
|
|
230
|
+
label: m === '/' ? 'System' : (m.split('/').pop() ?? m),
|
|
231
|
+
path: m === homeMount ? root : join(m, 'FireFunc'),
|
|
232
|
+
freeBytes: d.freeBytes,
|
|
233
|
+
totalBytes: d.totalBytes,
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
let drivesAt = -Infinity;
|
|
243
|
+
let drives = [];
|
|
244
|
+
export function driveReport(now = Date.now(), read = readDrives) {
|
|
245
|
+
if (now - drivesAt >= TEN_MINUTES) {
|
|
246
|
+
drives = read();
|
|
247
|
+
drivesAt = now;
|
|
248
|
+
}
|
|
249
|
+
return drives;
|
|
250
|
+
}
|
|
251
|
+
const sizes = new Map();
|
|
252
|
+
export function rootBytes(root, now = Date.now(), walk = (d) => dirBytes(d, 20_000)) {
|
|
253
|
+
const s = sizes.get(root);
|
|
254
|
+
if (!s || (!s.walking && now - s.at >= TEN_MINUTES)) {
|
|
255
|
+
const entry = { at: now, bytes: s?.bytes ?? null, walking: true };
|
|
256
|
+
sizes.set(root, entry);
|
|
257
|
+
void walk(root)
|
|
258
|
+
.then((b) => {
|
|
259
|
+
entry.bytes = b;
|
|
260
|
+
})
|
|
261
|
+
.catch(() => {
|
|
262
|
+
entry.bytes = null;
|
|
263
|
+
})
|
|
264
|
+
.finally(() => {
|
|
265
|
+
entry.walking = false;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return sizes.get(root).bytes;
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=drives.js.map
|
package/dist/engine-account.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EngineEnding } from './declined.js';
|
|
2
2
|
import type { EngineId, UnattendedBlock } from './engines/types.js';
|
|
3
|
-
export type AccountProblem = 'not_signed_in' | 'api_key_no_credit';
|
|
3
|
+
export type AccountProblem = 'not_signed_in' | 'api_key_no_credit' | 'needs_paid_tier';
|
|
4
4
|
export declare const ACCOUNT_RETRY_FIRST_MS: number;
|
|
5
5
|
export declare const ACCOUNT_RETRY_MAX_MS: number;
|
|
6
6
|
export declare function accountProblemOf(ending: EngineEnding | undefined, opts: {
|
package/dist/engine-account.js
CHANGED
|
@@ -7,7 +7,8 @@ function noticeLine(text) {
|
|
|
7
7
|
return first && first.length <= 300 ? first : null;
|
|
8
8
|
}
|
|
9
9
|
const NO_CREDIT = /\bcredit balance is too low\b/i;
|
|
10
|
-
const SIGNED_OUT = /^(?:error:\s*)?(?:not logged in\b|login expired\b|(?:please )?run \/login\b|invalid api key\b|invalid x-api-key\b|oauth (?:access )?token (?:has )?(?:expired|been revoked)\b|failed to authenticate\b|api error: 401\b)|\bauthentication_error\b
|
|
10
|
+
const SIGNED_OUT = /^(?:error:\s*)?(?:not logged in\b|login expired\b|(?:please )?run \/login\b|invalid api key\b|invalid x-api-key\b|oauth (?:access )?token (?:has )?(?:expired|been revoked)\b|failed to authenticate\b|api error: 401\b)|\bauthentication_error\b/i;
|
|
11
|
+
const TIER = /\bineligibletiererror\b|\bnot eligible for\b|\brequires? a paid (?:plan|tier)\b|\bupgrade (?:your|to a) (?:plan|tier)\b/i;
|
|
11
12
|
export function accountProblemOf(ending, opts) {
|
|
12
13
|
let line;
|
|
13
14
|
if (ending) {
|
|
@@ -23,6 +24,8 @@ export function accountProblemOf(ending, opts) {
|
|
|
23
24
|
return null;
|
|
24
25
|
if (NO_CREDIT.test(line))
|
|
25
26
|
return 'api_key_no_credit';
|
|
27
|
+
if (TIER.test(line))
|
|
28
|
+
return 'needs_paid_tier';
|
|
26
29
|
if (SIGNED_OUT.test(line)) {
|
|
27
30
|
if (opts.billedKey && /api key|x-api-key/i.test(line))
|
|
28
31
|
return null;
|
|
@@ -40,6 +43,14 @@ export function accountBlock(code, engineName, retryInMinutes) {
|
|
|
40
43
|
detail: `${engineName} is not signed in on this machine — run \`claude\` and \`/login\` there`,
|
|
41
44
|
};
|
|
42
45
|
}
|
|
46
|
+
if (code === 'needs_paid_tier') {
|
|
47
|
+
return {
|
|
48
|
+
code,
|
|
49
|
+
reason: `${engineName}'s account on this machine is on a tier that cannot run it ("not eligible" — IneligibleTierError), so every run it started would stop the same way.`,
|
|
50
|
+
fix: `Move the account to a paid tier, or give ${engineName} an API key (for Gemini CLI: GEMINI_API_KEY from Google AI Studio). ${again}`,
|
|
51
|
+
detail: `${engineName} needs a paid tier on this machine's account`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
43
54
|
return {
|
|
44
55
|
code,
|
|
45
56
|
reason: `The Anthropic API key ${engineName} bills on this machine has no credit left ("Credit balance is too low"), so every run it started would stop the same way.`,
|
package/dist/engines/types.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type UnattendedContext = {
|
|
|
26
26
|
permissionMode: string;
|
|
27
27
|
};
|
|
28
28
|
export type UnattendedBlock = {
|
|
29
|
-
code: 'runs_as_root' | 'not_signed_in' | 'api_key_no_credit';
|
|
29
|
+
code: 'runs_as_root' | 'not_signed_in' | 'api_key_no_credit' | 'needs_paid_tier';
|
|
30
30
|
reason: string;
|
|
31
31
|
fix: string;
|
|
32
32
|
detail: string;
|
package/dist/exec.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { constants } from 'node:os';
|
|
3
3
|
import { shellSafe } from './win-shell.js';
|
|
4
|
+
import { awakeTimer } from './awake-timer.js';
|
|
4
5
|
export function signalExitCode(signal) {
|
|
5
6
|
const n = signal ? constants.signals[signal] : undefined;
|
|
6
7
|
return typeof n === 'number' ? 128 + n : 1;
|
|
@@ -104,11 +105,11 @@ export function exec(cmd, args, opts = {}) {
|
|
|
104
105
|
let timer = null;
|
|
105
106
|
let timedOut = false;
|
|
106
107
|
if (opts.timeoutMs) {
|
|
107
|
-
timer =
|
|
108
|
+
timer = awakeTimer(opts.timeoutMs, () => {
|
|
108
109
|
timedOut = true;
|
|
109
110
|
stop('SIGTERM');
|
|
110
111
|
setTimeout(() => stop('SIGKILL'), 5_000);
|
|
111
|
-
}, opts.timeoutMs);
|
|
112
|
+
}, { tickMs: Math.min(5_000, Math.max(10, Math.floor(opts.timeoutMs / 10))) });
|
|
112
113
|
}
|
|
113
114
|
child.stdout?.on('data', (d) => {
|
|
114
115
|
const s = d.toString();
|
|
@@ -117,8 +118,7 @@ export function exec(cmd, args, opts = {}) {
|
|
|
117
118
|
});
|
|
118
119
|
child.stderr?.on('data', (d) => (stderr += d.toString()));
|
|
119
120
|
child.on('error', (err) => {
|
|
120
|
-
|
|
121
|
-
clearTimeout(timer);
|
|
121
|
+
timer?.cancel();
|
|
122
122
|
if (settled)
|
|
123
123
|
return;
|
|
124
124
|
settled = true;
|
|
@@ -128,8 +128,7 @@ export function exec(cmd, args, opts = {}) {
|
|
|
128
128
|
if (settled)
|
|
129
129
|
return;
|
|
130
130
|
settled = true;
|
|
131
|
-
|
|
132
|
-
clearTimeout(timer);
|
|
131
|
+
timer?.cancel();
|
|
133
132
|
if (exitTimer)
|
|
134
133
|
clearTimeout(exitTimer);
|
|
135
134
|
resolve({
|
|
@@ -43,7 +43,7 @@ async function printRun(ctx, body) {
|
|
|
43
43
|
export const automationCommands = [
|
|
44
44
|
{
|
|
45
45
|
path: ['automations', 'list'],
|
|
46
|
-
summary: 'The
|
|
46
|
+
summary: 'The automations in this workspace (Steps and Team)',
|
|
47
47
|
usage: 'automations list [--project <id or name>]',
|
|
48
48
|
flags: { project: 'string' },
|
|
49
49
|
flagHelp: [['--project <id or name>', "only this project's automations"]],
|
|
@@ -111,7 +111,7 @@ export const automationCommands = [
|
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
113
|
path: ['automations', 'create'],
|
|
114
|
-
summary: 'Make
|
|
114
|
+
summary: 'Make an automation as a DRAFT (nothing runs until it is published)',
|
|
115
115
|
usage: 'automations create --name <name> (--spec <file.json> | --from-template <id> | --kind workflow|orchestration) [--project <id or name>]',
|
|
116
116
|
flags: {
|
|
117
117
|
name: 'string',
|
|
@@ -127,7 +127,7 @@ export const automationCommands = [
|
|
|
127
127
|
'--from-template <id>',
|
|
128
128
|
'start from a template (automations templates); it brings its agents, paused',
|
|
129
129
|
],
|
|
130
|
-
['--kind <kind>', 'an empty workflow or orchestration'],
|
|
130
|
+
['--kind <kind>', 'an empty automation: workflow (Steps) or orchestration (Team)'],
|
|
131
131
|
['--project <id or name>', 'the project it belongs to; left out: the whole workspace'],
|
|
132
132
|
],
|
|
133
133
|
async run(ctx) {
|
|
@@ -32,7 +32,27 @@ export const machineCommands = [
|
|
|
32
32
|
.map((e) => text(e.engine).replace(/_channel$/, ''))
|
|
33
33
|
.join(','),
|
|
34
34
|
},
|
|
35
|
+
{
|
|
36
|
+
head: 'RUNNER',
|
|
37
|
+
get: (m) => {
|
|
38
|
+
const r = (m.runner ?? null);
|
|
39
|
+
if (!r?.version)
|
|
40
|
+
return '-';
|
|
41
|
+
return r.behind ? `${text(r.version)} (${text(r.latest)} is out)` : text(r.version);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
35
44
|
]);
|
|
45
|
+
const behind = rows.filter((m) => (m.runner ?? null)?.update);
|
|
46
|
+
if (behind.length) {
|
|
47
|
+
ctx.io.stdout.write('\nA newer runner is out:\n');
|
|
48
|
+
for (const m of behind) {
|
|
49
|
+
const u = m.runner.update;
|
|
50
|
+
ctx.io.stdout.write(` ${text(m.name)}: ${text(u.from)} -> ${text(u.to)}\n`);
|
|
51
|
+
if (u.notes)
|
|
52
|
+
ctx.io.stdout.write(` What changed: ${text(u.notes)}\n`);
|
|
53
|
+
ctx.io.stdout.write(` ${text(u.how)}\n`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
36
56
|
},
|
|
37
57
|
},
|
|
38
58
|
{
|
package/dist/firefunc/main.js
CHANGED
|
@@ -80,7 +80,7 @@ async function register(io, meta) {
|
|
|
80
80
|
try {
|
|
81
81
|
res = await postJson(io, meta.registration_endpoint, {
|
|
82
82
|
client_name: 'FireFunc CLI',
|
|
83
|
-
client_uri: 'https://firefunc.com/
|
|
83
|
+
client_uri: 'https://firefunc.com/',
|
|
84
84
|
redirect_uris: [REDIRECT],
|
|
85
85
|
grant_types: ['authorization_code', 'refresh_token'],
|
|
86
86
|
response_types: ['code'],
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type GhReposReport = {
|
|
2
|
+
state: 'ok' | 'signed_out' | 'no_gh';
|
|
3
|
+
login: string | null;
|
|
4
|
+
checked: string[];
|
|
5
|
+
hidden: string[];
|
|
6
|
+
at: string;
|
|
7
|
+
};
|
|
8
|
+
type Run = (args: string[]) => Promise<{
|
|
9
|
+
code: number;
|
|
10
|
+
stdout: string;
|
|
11
|
+
stderr: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function checkGhRepos(repos: readonly string[], run?: Run, now?: Date): Promise<{
|
|
14
|
+
state: "no_gh";
|
|
15
|
+
login: null;
|
|
16
|
+
checked: string[];
|
|
17
|
+
hidden: never[];
|
|
18
|
+
at: string;
|
|
19
|
+
} | {
|
|
20
|
+
state: "signed_out";
|
|
21
|
+
login: null;
|
|
22
|
+
checked: string[];
|
|
23
|
+
hidden: never[];
|
|
24
|
+
at: string;
|
|
25
|
+
} | {
|
|
26
|
+
state: "ok";
|
|
27
|
+
login: string | null;
|
|
28
|
+
checked: string[];
|
|
29
|
+
hidden: string[];
|
|
30
|
+
at: string;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function ghRepoWatch(deps: {
|
|
33
|
+
run?: Run;
|
|
34
|
+
now?: () => number;
|
|
35
|
+
everyMs?: number;
|
|
36
|
+
log?: (msg: string) => void;
|
|
37
|
+
}): {
|
|
38
|
+
update(next: string[] | null): void;
|
|
39
|
+
report(): GhReposReport | null;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
package/dist/gh-repos.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { exec } from './exec.js';
|
|
2
|
+
const REPO = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
|
|
3
|
+
const defaultRun = (args) => exec('gh', args, { timeoutMs: 15_000 });
|
|
4
|
+
export async function checkGhRepos(repos, run = defaultRun, now = new Date()) {
|
|
5
|
+
const asked = [...new Set(repos.filter((r) => REPO.test(r)))].slice(0, 40);
|
|
6
|
+
const at = now.toISOString();
|
|
7
|
+
let who;
|
|
8
|
+
try {
|
|
9
|
+
who = await run(['api', 'user', '--jq', '.login']);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return { state: 'no_gh', login: null, checked: asked, hidden: [], at };
|
|
13
|
+
}
|
|
14
|
+
if (who.code !== 0) {
|
|
15
|
+
return {
|
|
16
|
+
state: 'signed_out',
|
|
17
|
+
login: null,
|
|
18
|
+
checked: asked,
|
|
19
|
+
hidden: [],
|
|
20
|
+
at,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const login = who.stdout.trim() || null;
|
|
24
|
+
const hidden = [];
|
|
25
|
+
for (const repo of asked) {
|
|
26
|
+
const r = await run(['api', `repos/${repo}`, '--jq', '.full_name']).catch(() => null);
|
|
27
|
+
if (r && r.code !== 0 && /HTTP 40[34]|Not Found/i.test(`${r.stderr}${r.stdout}`))
|
|
28
|
+
hidden.push(repo);
|
|
29
|
+
}
|
|
30
|
+
return { state: 'ok', login, checked: asked, hidden, at };
|
|
31
|
+
}
|
|
32
|
+
export function ghRepoWatch(deps) {
|
|
33
|
+
const now = deps.now ?? (() => Date.now());
|
|
34
|
+
const everyMs = deps.everyMs ?? 30 * 60_000;
|
|
35
|
+
let repos = [];
|
|
36
|
+
let last = null;
|
|
37
|
+
let askedAt = 0;
|
|
38
|
+
let busy = false;
|
|
39
|
+
const ask = async () => {
|
|
40
|
+
if (busy || repos.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
busy = true;
|
|
43
|
+
try {
|
|
44
|
+
last = await checkGhRepos(repos, deps.run, new Date(now()));
|
|
45
|
+
askedAt = now();
|
|
46
|
+
if (last.hidden.length)
|
|
47
|
+
deps.log?.(`gh (${last.login ?? 'signed in'}) cannot see ${last.hidden.join(', ')}`);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
busy = false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
update(next) {
|
|
55
|
+
if (!next)
|
|
56
|
+
return;
|
|
57
|
+
const sorted = [...new Set(next)].sort();
|
|
58
|
+
const changed = sorted.join(',') !== repos.join(',');
|
|
59
|
+
repos = sorted;
|
|
60
|
+
if (changed || now() - askedAt >= everyMs)
|
|
61
|
+
void ask();
|
|
62
|
+
},
|
|
63
|
+
report() {
|
|
64
|
+
return last;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=gh-repos.js.map
|