@firefunc-agent/runner 0.9.14 → 0.9.34
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 +167 -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 +65 -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 +38 -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.js +19 -4
- package/dist/engines/claude.js +10 -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/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 +8 -1
- 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 +752 -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 +23 -2
- package/dist/network.js +3 -2
- 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 +41 -0
- package/dist/sign-in.js +239 -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 +4 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
export type KeepAwakeDeps = {
|
|
3
|
+
platform: NodeJS.Platform;
|
|
4
|
+
pid: number;
|
|
5
|
+
spawn: (cmd: string, args: string[]) => ChildProcess | null;
|
|
6
|
+
log: (line: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function windowsKeepAwakeScript(pid: number): string;
|
|
9
|
+
export declare function keepAwakeCommand(platform: NodeJS.Platform, pid: number): {
|
|
10
|
+
cmd: string;
|
|
11
|
+
args: string[];
|
|
12
|
+
} | null;
|
|
13
|
+
export declare function keepAwake(d: KeepAwakeDeps): {
|
|
14
|
+
hold: () => void;
|
|
15
|
+
release: () => void;
|
|
16
|
+
};
|
|
17
|
+
export declare function defaultKeepAwakeDeps(log: (line: string) => void): KeepAwakeDeps;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export function windowsKeepAwakeScript(pid) {
|
|
3
|
+
return ('Add-Type -Name P -Namespace W -MemberDefinition \'[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint f);\';' +
|
|
4
|
+
' [W.P]::SetThreadExecutionState([uint32]2147483649) | Out-Null;' +
|
|
5
|
+
` while (Get-Process -Id ${Math.trunc(pid)} -ErrorAction SilentlyContinue) { Start-Sleep -Seconds 30 }`);
|
|
6
|
+
}
|
|
7
|
+
export function keepAwakeCommand(platform, pid) {
|
|
8
|
+
if (platform === 'darwin')
|
|
9
|
+
return { cmd: 'caffeinate', args: ['-i', '-w', String(pid)] };
|
|
10
|
+
if (platform === 'win32') {
|
|
11
|
+
return {
|
|
12
|
+
cmd: 'powershell.exe',
|
|
13
|
+
args: [
|
|
14
|
+
'-NoProfile',
|
|
15
|
+
'-NonInteractive',
|
|
16
|
+
'-WindowStyle',
|
|
17
|
+
'Hidden',
|
|
18
|
+
'-EncodedCommand',
|
|
19
|
+
Buffer.from(windowsKeepAwakeScript(pid), 'utf16le').toString('base64'),
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (platform === 'linux') {
|
|
24
|
+
return {
|
|
25
|
+
cmd: 'systemd-inhibit',
|
|
26
|
+
args: [
|
|
27
|
+
'--what=idle:sleep',
|
|
28
|
+
'--who=firefunc-runner',
|
|
29
|
+
'--why=A FireFunc run is in progress',
|
|
30
|
+
'--mode=block',
|
|
31
|
+
'sh',
|
|
32
|
+
'-c',
|
|
33
|
+
`while kill -0 ${pid} 2>/dev/null && kill -0 $PPID 2>/dev/null; do sleep 5; done`,
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
export function keepAwake(d) {
|
|
40
|
+
let held = 0;
|
|
41
|
+
let child = null;
|
|
42
|
+
let toldMissing = false;
|
|
43
|
+
const start = () => {
|
|
44
|
+
const c = keepAwakeCommand(d.platform, d.pid);
|
|
45
|
+
if (!c)
|
|
46
|
+
return;
|
|
47
|
+
try {
|
|
48
|
+
child = d.spawn(c.cmd, c.args);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
child = null;
|
|
52
|
+
}
|
|
53
|
+
child?.on('error', () => {
|
|
54
|
+
child = null;
|
|
55
|
+
if (toldMissing)
|
|
56
|
+
return;
|
|
57
|
+
toldMissing = true;
|
|
58
|
+
d.log(`keep-awake: ${c.cmd} is not available here, so this machine may sleep during a run — keep it awake yourself, or install ${c.cmd}.`);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const stop = () => {
|
|
62
|
+
try {
|
|
63
|
+
child?.kill();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
}
|
|
67
|
+
child = null;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
hold: () => {
|
|
71
|
+
held += 1;
|
|
72
|
+
if (held === 1)
|
|
73
|
+
start();
|
|
74
|
+
},
|
|
75
|
+
release: () => {
|
|
76
|
+
held = Math.max(0, held - 1);
|
|
77
|
+
if (held === 0)
|
|
78
|
+
stop();
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function defaultKeepAwakeDeps(log) {
|
|
83
|
+
return {
|
|
84
|
+
platform: process.platform,
|
|
85
|
+
pid: process.pid,
|
|
86
|
+
spawn: (cmd, args) => spawn(cmd, args, { stdio: 'ignore', windowsHide: true }),
|
|
87
|
+
log,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=keep-awake.js.map
|
package/dist/keep-local.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare function commandName(command: string): string;
|
|
|
7
7
|
export declare function setupCommandName(command: string): string;
|
|
8
8
|
export declare function errorLine(stderr: string, sendable?: (line: string) => boolean): string | null;
|
|
9
9
|
export declare function foldHome(text: string, home: string): string;
|
|
10
|
-
export declare function lastWords(output: string): string | null;
|
|
10
|
+
export declare function lastWords(output: string, sendable?: (line: string) => boolean): string | null;
|
|
11
11
|
export declare function setupReason(stderr: string, stdout: string): string | null;
|
|
12
12
|
export declare function pushRefusal(stderr: string): string | null;
|
|
13
13
|
export declare function promisesLaterCheck(text: string): boolean;
|
package/dist/keep-local.js
CHANGED
|
@@ -629,7 +629,7 @@ export function foldHome(text, home) {
|
|
|
629
629
|
const escaped = root.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
630
630
|
return text.replace(new RegExp(`${escaped}(?![\\w-])`, 'g'), '~');
|
|
631
631
|
}
|
|
632
|
-
export function lastWords(output) {
|
|
632
|
+
export function lastWords(output, sendable = () => true) {
|
|
633
633
|
const lines = output
|
|
634
634
|
.replace(ANSI, '')
|
|
635
635
|
.split(/\r?\n/)
|
|
@@ -649,7 +649,7 @@ export function lastWords(output) {
|
|
|
649
649
|
continue;
|
|
650
650
|
if (isCodeLine(raw) || /[;{]\s*$/.test(line) || (/^\s/.test(raw) && CODE_SHAPE.test(raw)))
|
|
651
651
|
continue;
|
|
652
|
-
if (!plainWords(line))
|
|
652
|
+
if (!plainWords(line) || !sendable(line))
|
|
653
653
|
continue;
|
|
654
654
|
const kept = stripCode(line).trim();
|
|
655
655
|
if (kept && !kept.includes(`[${CODE_NOTE}`))
|
|
@@ -658,8 +658,10 @@ export function lastWords(output) {
|
|
|
658
658
|
return null;
|
|
659
659
|
}
|
|
660
660
|
export function setupReason(stderr, stdout) {
|
|
661
|
-
|
|
661
|
+
const said = (line) => plainWords(line) && !WARNING_LINE.test(line);
|
|
662
|
+
return errorLine(stderr, said) ?? lastWords(stderr, said) ?? lastWords(stdout, said);
|
|
662
663
|
}
|
|
664
|
+
const WARNING_LINE = /^\s*(?:\[?(?:warn(?:ing)?)\]?[:\s]|[\w@./-]+\s+(?:warn(?:ing)?)\b[:\s]|\S+:\s*warn(?:ing)?:)/i;
|
|
663
665
|
export function pushRefusal(stderr) {
|
|
664
666
|
const kept = stderr
|
|
665
667
|
.split(/\r?\n/)
|
package/dist/limit.d.ts
CHANGED
|
@@ -5,8 +5,16 @@ export type PlanLimit = {
|
|
|
5
5
|
said?: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function readClaudeLimit(stdout: string, now?: Date): PlanLimit | null;
|
|
8
|
+
export declare function readCodexLimit(stdout: string, now?: Date): PlanLimit | null;
|
|
9
|
+
export declare function codexResetFrom(text: string, now?: Date): string | null;
|
|
10
|
+
export declare function readGeminiLimit(stdout: string, now?: Date): PlanLimit | null;
|
|
11
|
+
export declare function geminiResetFrom(text: string, now?: Date): string | null;
|
|
12
|
+
export declare function readCopilotLimit(stdout: string, now?: Date, stderr?: string): PlanLimit | null;
|
|
13
|
+
export declare function readWordedLimit(endingError: string | null, stderr: string, now?: Date): PlanLimit | null;
|
|
14
|
+
export declare function readCursorLimit(stdout: string, now?: Date, stderr?: string): PlanLimit | null;
|
|
15
|
+
export declare function readAntigravityLimit(stdout: string, now?: Date, stderr?: string): PlanLimit | null;
|
|
8
16
|
export declare function resetFromSentence(text: string, now?: Date): string | null;
|
|
9
|
-
export declare function limitSentence(engineName: string, limit: PlanLimit, kept: boolean): string;
|
|
17
|
+
export declare function limitSentence(engineName: string, limit: PlanLimit, kept: boolean | 'session' | 'worktree'): string;
|
|
10
18
|
export type ActiveLimit = {
|
|
11
19
|
engine: string;
|
|
12
20
|
resetsAt: string | null;
|
package/dist/limit.js
CHANGED
|
@@ -75,6 +75,261 @@ export function readClaudeLimit(stdout, now = new Date()) {
|
|
|
75
75
|
return null;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
export function readCodexLimit(stdout, now = new Date()) {
|
|
79
|
+
try {
|
|
80
|
+
let failure = null;
|
|
81
|
+
for (const line of stdout.split('\n')) {
|
|
82
|
+
const t = line.trim();
|
|
83
|
+
if (!t.startsWith('{'))
|
|
84
|
+
continue;
|
|
85
|
+
if (!t.includes('"type":"turn.failed"') &&
|
|
86
|
+
!t.includes('"type":"error"') &&
|
|
87
|
+
!t.includes('"type":"turn.completed"')) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
let ev;
|
|
91
|
+
try {
|
|
92
|
+
ev = JSON.parse(t);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!isObj(ev))
|
|
98
|
+
continue;
|
|
99
|
+
if (ev.type === 'turn.completed') {
|
|
100
|
+
failure = null;
|
|
101
|
+
}
|
|
102
|
+
else if (ev.type === 'turn.failed' || ev.type === 'error') {
|
|
103
|
+
const msg = typeof ev.message === 'string'
|
|
104
|
+
? ev.message
|
|
105
|
+
: isObj(ev.error) && typeof ev.error.message === 'string'
|
|
106
|
+
? ev.error.message
|
|
107
|
+
: null;
|
|
108
|
+
if (msg && (!failure || !CODEX_LIMIT_WORDS.test(failure)))
|
|
109
|
+
failure = msg.trim();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!failure || !CODEX_LIMIT_WORDS.test(failure))
|
|
113
|
+
return null;
|
|
114
|
+
return {
|
|
115
|
+
kind: 'plan',
|
|
116
|
+
resetsAt: codexResetFrom(failure, now),
|
|
117
|
+
said: failure.slice(0, 200),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const CODEX_LIMIT_WORDS = /\bhit your usage limit\b/i;
|
|
125
|
+
export function codexResetFrom(text, now = new Date()) {
|
|
126
|
+
const rel = /\btry again in\s+((?:\d+\s*(?:days?|hours?|minutes?|mins?|seconds?|secs?)[\s,]*(?:and\s+)?)+)/i.exec(text);
|
|
127
|
+
if (rel?.[1]) {
|
|
128
|
+
let ms = 0;
|
|
129
|
+
for (const m of rel[1].matchAll(/(\d+)\s*(day|hour|min|sec)/gi)) {
|
|
130
|
+
const n = Number(m[1]);
|
|
131
|
+
const unit = m[2].toLowerCase();
|
|
132
|
+
ms +=
|
|
133
|
+
n *
|
|
134
|
+
(unit === 'day'
|
|
135
|
+
? 86_400_000
|
|
136
|
+
: unit === 'hour'
|
|
137
|
+
? 3_600_000
|
|
138
|
+
: unit === 'min'
|
|
139
|
+
? 60_000
|
|
140
|
+
: 1000);
|
|
141
|
+
}
|
|
142
|
+
return ms > 0 ? new Date(now.getTime() + ms).toISOString() : null;
|
|
143
|
+
}
|
|
144
|
+
const at = /\btry again at\s+(?:(?<mon>[A-Za-z]{3,9})\.?\s+(?<day>\d{1,2})(?:st|nd|rd|th)?,?\s+(?:\d{4},?\s+)?)?(?<time>\d{1,2}:\d{2}\s*[AaPp][Mm])/.exec(text);
|
|
145
|
+
if (!at?.groups)
|
|
146
|
+
return null;
|
|
147
|
+
const g = at.groups;
|
|
148
|
+
const sentence = g.mon && g.day ? `resets ${g.mon} ${g.day}, ${g.time}` : `resets ${g.time}`;
|
|
149
|
+
return resetFromSentence(sentence, now);
|
|
150
|
+
}
|
|
151
|
+
export function readGeminiLimit(stdout, now = new Date()) {
|
|
152
|
+
try {
|
|
153
|
+
let error = null;
|
|
154
|
+
const take = (ev) => {
|
|
155
|
+
if (!isObj(ev))
|
|
156
|
+
return;
|
|
157
|
+
if (isObj(ev.error))
|
|
158
|
+
error = ev.error;
|
|
159
|
+
else if (typeof ev.response === 'string' && ev.response.trim())
|
|
160
|
+
error = null;
|
|
161
|
+
};
|
|
162
|
+
const whole = stdout.trim();
|
|
163
|
+
let parsed = false;
|
|
164
|
+
if (whole.startsWith('{')) {
|
|
165
|
+
try {
|
|
166
|
+
take(JSON.parse(whole));
|
|
167
|
+
parsed = true;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!parsed) {
|
|
173
|
+
for (const line of stdout.split('\n')) {
|
|
174
|
+
const t = line.trim();
|
|
175
|
+
if (!t.startsWith('{') || !t.includes('"error"'))
|
|
176
|
+
continue;
|
|
177
|
+
try {
|
|
178
|
+
take(JSON.parse(t));
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const e = error;
|
|
185
|
+
if (!e)
|
|
186
|
+
return null;
|
|
187
|
+
const type = typeof e.type === 'string' ? e.type : '';
|
|
188
|
+
const message = typeof e.message === 'string' ? e.message.trim() : '';
|
|
189
|
+
if (type === 'RetryableQuotaError')
|
|
190
|
+
return null;
|
|
191
|
+
if (type !== 'TerminalQuotaError' && !GEMINI_QUOTA_WORDS.test(message))
|
|
192
|
+
return null;
|
|
193
|
+
return {
|
|
194
|
+
kind: 'plan',
|
|
195
|
+
resetsAt: geminiResetFrom(message, now),
|
|
196
|
+
...(/\bdaily\b/i.test(message) ? { window: 'daily' } : {}),
|
|
197
|
+
...(message ? { said: message.slice(0, 200) } : {}),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const GEMINI_QUOTA_WORDS = /\bexhausted your (?:[\w-]+ ){0,2}quota\b|\bQUOTA_EXHAUSTED\b/i;
|
|
205
|
+
export function geminiResetFrom(text, now = new Date()) {
|
|
206
|
+
const delay = /\bplease retry in\s+([0-9.]+)\s*(ms|s)\b/i.exec(text) ??
|
|
207
|
+
/\bretry after\s+([0-9.]+)\s*(ms|s)\b/i.exec(text);
|
|
208
|
+
if (delay?.[1]) {
|
|
209
|
+
const n = Number(delay[1]);
|
|
210
|
+
if (Number.isFinite(n) && n > 0) {
|
|
211
|
+
const ms = delay[2].toLowerCase() === 'ms' ? n : n * 1000;
|
|
212
|
+
return new Date(now.getTime() + Math.ceil(ms)).toISOString();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (/\bdaily\b/i.test(text)) {
|
|
216
|
+
const zone = 'America/Los_Angeles';
|
|
217
|
+
const today = wallParts(now.getTime(), zone);
|
|
218
|
+
const next = new Date(Date.UTC(today.y, today.mo, today.d + 1));
|
|
219
|
+
return new Date(zonedInstant(next.getUTCFullYear(), next.getUTCMonth(), next.getUTCDate(), 0, 0, zone)).toISOString();
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
export function readCopilotLimit(stdout, now = new Date(), stderr = '') {
|
|
224
|
+
try {
|
|
225
|
+
const tail = (text) => text
|
|
226
|
+
.split('\n')
|
|
227
|
+
.map((l) => l.trim())
|
|
228
|
+
.filter(Boolean)
|
|
229
|
+
.slice(-4)
|
|
230
|
+
.join('\n');
|
|
231
|
+
const ending = `${tail(stderr)}\n${tail(stdout)}`;
|
|
232
|
+
const said = COPILOT_QUOTA_WORDS.exec(ending);
|
|
233
|
+
if (!said)
|
|
234
|
+
return null;
|
|
235
|
+
const line = ending.split('\n').find((l) => COPILOT_QUOTA_WORDS.test(l)) ?? said[0];
|
|
236
|
+
void now;
|
|
237
|
+
return { kind: 'plan', resetsAt: null, said: line.slice(0, 200) };
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const COPILOT_QUOTA_WORDS = /\b402\b[^\n]{0,40}\bno quota\b|\bquota_exceeded\b|\bQuota exceeded\b/i;
|
|
244
|
+
export function readWordedLimit(endingError, stderr, now = new Date()) {
|
|
245
|
+
try {
|
|
246
|
+
const tail = stderr
|
|
247
|
+
.split('\n')
|
|
248
|
+
.map((l) => l.trim())
|
|
249
|
+
.filter(Boolean)
|
|
250
|
+
.slice(-4)
|
|
251
|
+
.join('\n');
|
|
252
|
+
const text = [endingError ?? '', tail].filter(Boolean).join('\n');
|
|
253
|
+
if (!text || !WORDED_LIMIT.test(text))
|
|
254
|
+
return null;
|
|
255
|
+
const line = text.split('\n').find((l) => WORDED_LIMIT.test(l)) ?? text;
|
|
256
|
+
return {
|
|
257
|
+
kind: 'plan',
|
|
258
|
+
resetsAt: codexResetFrom(text, now) ?? resetFromSentence(text, now),
|
|
259
|
+
said: line.slice(0, 200),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const WORDED_LIMIT = /\b(?:usage|rate|quota|credit|spend(?:ing)?) limit\b|\bhit your (?:[\w-]+ ){0,2}limit\b|\bquota (?:exceeded|exhausted)\b|\bexhausted your (?:[\w-]+ ){0,2}quota\b|\bresource[_ ]exhausted\b|\bout of (?:credits|quota)\b|\btoo many requests\b|\b429\b/i;
|
|
267
|
+
export function readCursorLimit(stdout, now = new Date(), stderr = '') {
|
|
268
|
+
let error = null;
|
|
269
|
+
let succeeded = false;
|
|
270
|
+
try {
|
|
271
|
+
for (const line of stdout.split('\n')) {
|
|
272
|
+
const t = line.trim();
|
|
273
|
+
if (!t.startsWith('{') || !t.includes('"result"'))
|
|
274
|
+
continue;
|
|
275
|
+
try {
|
|
276
|
+
const ev = JSON.parse(t);
|
|
277
|
+
if (ev.type !== 'result')
|
|
278
|
+
continue;
|
|
279
|
+
const failed = ev.is_error === true || (typeof ev.subtype === 'string' && ev.subtype !== 'success');
|
|
280
|
+
succeeded = !failed;
|
|
281
|
+
error = failed
|
|
282
|
+
? typeof ev.result === 'string'
|
|
283
|
+
? ev.result
|
|
284
|
+
: typeof ev.error === 'string'
|
|
285
|
+
? ev.error
|
|
286
|
+
: ''
|
|
287
|
+
: null;
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
error = null;
|
|
295
|
+
}
|
|
296
|
+
if (succeeded)
|
|
297
|
+
return null;
|
|
298
|
+
return readWordedLimit(error, stderr, now);
|
|
299
|
+
}
|
|
300
|
+
export function readAntigravityLimit(stdout, now = new Date(), stderr = '') {
|
|
301
|
+
let error = null;
|
|
302
|
+
let succeeded = false;
|
|
303
|
+
try {
|
|
304
|
+
for (const line of stdout.split('\n')) {
|
|
305
|
+
const t = line.trim();
|
|
306
|
+
if (!t.startsWith('{') || !t.includes('"status"'))
|
|
307
|
+
continue;
|
|
308
|
+
try {
|
|
309
|
+
const ev = JSON.parse(t);
|
|
310
|
+
if (typeof ev.status !== 'string')
|
|
311
|
+
continue;
|
|
312
|
+
succeeded = ev.status === 'SUCCESS';
|
|
313
|
+
error =
|
|
314
|
+
ev.status === 'ERROR'
|
|
315
|
+
? typeof ev.error === 'string'
|
|
316
|
+
? ev.error
|
|
317
|
+
: isObj(ev.error) && typeof ev.error.message === 'string'
|
|
318
|
+
? ev.error.message
|
|
319
|
+
: ''
|
|
320
|
+
: null;
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
error = null;
|
|
328
|
+
}
|
|
329
|
+
if (succeeded)
|
|
330
|
+
return null;
|
|
331
|
+
return readWordedLimit(error, stderr, now);
|
|
332
|
+
}
|
|
78
333
|
const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
79
334
|
function knownZone(zone) {
|
|
80
335
|
if (!zone)
|
|
@@ -163,9 +418,11 @@ export function limitSentence(engineName, limit, kept) {
|
|
|
163
418
|
return (`${engineName} was stopped by the plan's usage limit — ${when}. ` +
|
|
164
419
|
`The runner pushed nothing from this attempt and claims no new work for ${engineName} ` +
|
|
165
420
|
`until the reset. ` +
|
|
166
|
-
(kept
|
|
167
|
-
? '
|
|
168
|
-
:
|
|
421
|
+
(kept === 'worktree'
|
|
422
|
+
? 'Its work is kept on this machine: when the task runs again after the reset, a new session goes on from it instead of starting over.'
|
|
423
|
+
: kept
|
|
424
|
+
? 'When the task runs again after the reset, this machine continues the same session from where it stopped instead of starting over.'
|
|
425
|
+
: 'Run the task again after the reset.'));
|
|
169
426
|
}
|
|
170
427
|
export const UNKNOWN_RESET_WAIT_MS = 15 * 60_000;
|
|
171
428
|
export const RESET_GRACE_MS = 2 * 60_000;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type DeclaredCheck = {
|
|
2
|
+
key: string;
|
|
3
|
+
command: string;
|
|
4
|
+
};
|
|
5
|
+
export type LocalCheckRun = {
|
|
6
|
+
key: string;
|
|
7
|
+
ran: boolean;
|
|
8
|
+
ok: boolean;
|
|
9
|
+
fresh: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type LocalChecksReport = {
|
|
12
|
+
checks: LocalCheckRun[];
|
|
13
|
+
};
|
|
14
|
+
export declare function checkWords(command: string): string;
|
|
15
|
+
export declare function makeLocalChecksReader(declared: readonly DeclaredCheck[]): {
|
|
16
|
+
feed(chunk: string): void;
|
|
17
|
+
report(): LocalChecksReport | null;
|
|
18
|
+
};
|
|
19
|
+
export declare function declaredChecksOf(raw: unknown): DeclaredCheck[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { commandName } from './keep-local.js';
|
|
2
|
+
import { makeTrailStreamParser } from './trail/stream.js';
|
|
3
|
+
const EDIT_TOOLS = new Set(['Edit', 'MultiEdit', 'Write', 'NotebookEdit']);
|
|
4
|
+
export function checkWords(command) {
|
|
5
|
+
let c = command.trim().replace(/\s+/g, ' ');
|
|
6
|
+
c = c.replace(/^cd \S+ && /, '');
|
|
7
|
+
c = c.replace(/ 2>&1$/, '');
|
|
8
|
+
return c;
|
|
9
|
+
}
|
|
10
|
+
export function makeLocalChecksReader(declared) {
|
|
11
|
+
const wanted = declared
|
|
12
|
+
.map((d) => ({ key: d.key, name: commandName(d.command), words: checkWords(d.command) }))
|
|
13
|
+
.filter((d) => d.name && d.name !== 'a command');
|
|
14
|
+
const pending = new Map();
|
|
15
|
+
const last = new Map();
|
|
16
|
+
const onEvent = (ev) => {
|
|
17
|
+
if (ev.kind === 'tool_use') {
|
|
18
|
+
if (EDIT_TOOLS.has(ev.name)) {
|
|
19
|
+
for (const run of last.values())
|
|
20
|
+
run.fresh = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (ev.name !== 'Bash' || !ev.input.command || ev.input.run_in_background)
|
|
24
|
+
return;
|
|
25
|
+
const name = commandName(ev.input.command);
|
|
26
|
+
const words = checkWords(ev.input.command);
|
|
27
|
+
const hit = wanted.find((w) => w.name === name && w.words === words);
|
|
28
|
+
if (!hit)
|
|
29
|
+
return;
|
|
30
|
+
pending.set(ev.id, hit.key);
|
|
31
|
+
last.set(hit.key, { id: ev.id, ok: null, fresh: true });
|
|
32
|
+
}
|
|
33
|
+
else if (ev.kind === 'tool_result') {
|
|
34
|
+
const key = pending.get(ev.id);
|
|
35
|
+
if (!key)
|
|
36
|
+
return;
|
|
37
|
+
pending.delete(ev.id);
|
|
38
|
+
const run = last.get(key);
|
|
39
|
+
if (run && run.id === ev.id)
|
|
40
|
+
run.ok = !ev.isError;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const parse = makeTrailStreamParser(onEvent);
|
|
44
|
+
return {
|
|
45
|
+
feed(chunk) {
|
|
46
|
+
try {
|
|
47
|
+
parse(chunk);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
report() {
|
|
53
|
+
if (declared.length === 0)
|
|
54
|
+
return null;
|
|
55
|
+
return {
|
|
56
|
+
checks: declared.map((d) => {
|
|
57
|
+
const run = last.get(d.key);
|
|
58
|
+
return {
|
|
59
|
+
key: d.key,
|
|
60
|
+
ran: run !== undefined && run.ok !== null,
|
|
61
|
+
ok: run?.ok === true,
|
|
62
|
+
fresh: run?.fresh === true,
|
|
63
|
+
};
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function declaredChecksOf(raw) {
|
|
70
|
+
if (!Array.isArray(raw))
|
|
71
|
+
return [];
|
|
72
|
+
return raw.flatMap((c) => {
|
|
73
|
+
const o = c;
|
|
74
|
+
return o && typeof o.key === 'string' && typeof o.command === 'string' && o.command.trim()
|
|
75
|
+
? [{ key: o.key.slice(0, 40), command: o.command.slice(0, 200) }]
|
|
76
|
+
: [];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=local-checks.js.map
|
package/dist/locks.d.ts
CHANGED
|
@@ -4,11 +4,28 @@ export type KeyedMutex = {
|
|
|
4
4
|
export declare function createKeyedMutex(): KeyedMutex;
|
|
5
5
|
export declare function repoLockKey(repo: string): string;
|
|
6
6
|
export declare function heavyLockDir(runnerDir: string, repo: string): string;
|
|
7
|
+
export declare function heavySlotsFor(machine?: {
|
|
8
|
+
cores: number;
|
|
9
|
+
memBytes: number;
|
|
10
|
+
}): number;
|
|
11
|
+
export declare function heavySlots(setting?: number | null): number;
|
|
12
|
+
export declare function heavySlotDir(lockDir: string, i: number): string;
|
|
13
|
+
export declare function heavyQueueDir(lockDir: string): string;
|
|
14
|
+
export declare function heavyTag(runId: string): string;
|
|
15
|
+
export type HeavyWait = {
|
|
16
|
+
tag: string;
|
|
17
|
+
place: number;
|
|
18
|
+
running: number;
|
|
19
|
+
since: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function heavyWaits(runnerDir: string): HeavyWait[];
|
|
7
22
|
export type HeavyLockOptions = {
|
|
8
23
|
label?: string;
|
|
24
|
+
slots?: number;
|
|
9
25
|
pollMs?: number;
|
|
10
26
|
maxWaitMs?: number;
|
|
11
|
-
onWait?: (holder: number | null) => void;
|
|
27
|
+
onWait?: (holder: number | null, ahead: number) => void;
|
|
28
|
+
tag?: string;
|
|
12
29
|
now?: () => number;
|
|
13
30
|
sleep?: (ms: number) => Promise<void>;
|
|
14
31
|
};
|