@firefunc-agent/runner 0.7.1 → 0.9.3
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/LICENSE +7 -3
- package/README.md +296 -4
- package/dist/activity.d.ts +32 -0
- package/dist/activity.js +295 -0
- package/dist/api.d.ts +69 -1
- package/dist/api.js +114 -3
- package/dist/brief.d.ts +11 -0
- package/dist/brief.js +278 -0
- package/dist/build-info.json +4 -0
- package/dist/cli.js +59 -2
- package/dist/config.d.ts +7 -0
- package/dist/config.js +3 -0
- package/dist/cut.d.ts +45 -0
- package/dist/cut.js +105 -0
- package/dist/daemon.d.ts +16 -0
- package/dist/daemon.js +196 -7
- package/dist/declined.d.ts +11 -0
- package/dist/declined.js +27 -0
- package/dist/engines/antigravity.d.ts +2 -0
- package/dist/engines/antigravity.js +102 -0
- package/dist/engines/claude-budget.d.ts +1 -1
- package/dist/engines/claude-budget.js +2 -72
- package/dist/engines/claude.js +139 -2
- package/dist/engines/codex.js +10 -3
- package/dist/engines/copilot.d.ts +2 -0
- package/dist/engines/copilot.js +117 -0
- package/dist/engines/cursor.js +4 -0
- package/dist/engines/gemini.js +6 -1
- package/dist/engines/index.d.ts +2 -0
- package/dist/engines/index.js +22 -4
- package/dist/engines/types.d.ts +12 -1
- package/dist/exec.d.ts +3 -0
- package/dist/exec.js +48 -5
- package/dist/firefunc/agents.d.ts +2 -0
- package/dist/firefunc/agents.js +343 -0
- package/dist/firefunc/args.d.ts +18 -0
- package/dist/firefunc/args.js +82 -0
- package/dist/firefunc/auth.d.ts +21 -0
- package/dist/firefunc/auth.js +129 -0
- package/dist/firefunc/catalog.d.ts +10 -0
- package/dist/firefunc/catalog.js +201 -0
- package/dist/firefunc/cli.d.ts +2 -0
- package/dist/firefunc/cli.js +24 -0
- package/dist/firefunc/client.d.ts +36 -0
- package/dist/firefunc/client.js +177 -0
- package/dist/firefunc/command.d.ts +28 -0
- package/dist/firefunc/command.js +35 -0
- package/dist/firefunc/config.d.ts +29 -0
- package/dist/firefunc/config.js +111 -0
- package/dist/firefunc/configure.d.ts +6 -0
- package/dist/firefunc/configure.js +409 -0
- package/dist/firefunc/io.d.ts +25 -0
- package/dist/firefunc/io.js +14 -0
- package/dist/firefunc/main.d.ts +4 -0
- package/dist/firefunc/main.js +259 -0
- package/dist/firefunc/output.d.ts +29 -0
- package/dist/firefunc/output.js +131 -0
- package/dist/firefunc/prompt.d.ts +14 -0
- package/dist/firefunc/prompt.js +58 -0
- package/dist/firefunc/skill.d.ts +3 -0
- package/dist/firefunc/skill.js +80 -0
- package/dist/firefunc/tasks.d.ts +2 -0
- package/dist/firefunc/tasks.js +279 -0
- package/dist/firefunc/version.d.ts +2 -0
- package/dist/firefunc/version.js +8 -0
- package/dist/git-auth.d.ts +4 -1
- package/dist/git-auth.js +6 -2
- package/dist/held.d.ts +18 -0
- package/dist/held.js +95 -0
- package/dist/job.d.ts +3 -0
- package/dist/job.js +818 -102
- package/dist/keep-local.d.ts +12 -0
- package/dist/keep-local.js +651 -0
- package/dist/limit.d.ts +30 -0
- package/dist/limit.js +258 -0
- package/dist/locks.d.ts +14 -0
- package/dist/locks.js +164 -0
- package/dist/machine-logins.d.ts +19 -0
- package/dist/machine-logins.js +187 -0
- package/dist/mcp-login.d.ts +24 -0
- package/dist/mcp-login.js +993 -0
- package/dist/mcp-proxy.d.ts +21 -0
- package/dist/mcp-proxy.js +180 -0
- package/dist/mcp.d.ts +62 -0
- package/dist/mcp.js +611 -0
- package/dist/network.d.ts +20 -0
- package/dist/network.js +76 -0
- package/dist/orphans.d.ts +40 -0
- package/dist/orphans.js +235 -0
- package/dist/pending.d.ts +14 -0
- package/dist/pending.js +56 -0
- package/dist/pool.d.ts +7 -0
- package/dist/pool.js +57 -9
- package/dist/pr-title.d.ts +11 -0
- package/dist/pr-title.js +63 -0
- package/dist/recover.d.ts +10 -0
- package/dist/recover.js +104 -0
- package/dist/secret-scan.d.ts +19 -0
- package/dist/secret-scan.js +161 -0
- package/dist/session-stream.d.ts +9 -1
- package/dist/session-stream.js +20 -2
- package/dist/skills.d.ts +11 -0
- package/dist/skills.js +164 -0
- package/dist/stopped.d.ts +3 -0
- package/dist/stopped.js +10 -0
- package/dist/usage.d.ts +49 -0
- package/dist/usage.js +389 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +17 -0
- package/dist/viewer.js +7 -1
- package/dist/worktrees.d.ts +15 -0
- package/dist/worktrees.js +96 -0
- package/package.json +8 -5
- package/skill/firefunc/SKILL.md +222 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const CODE_NOTE = "code kept on the machine";
|
|
2
|
+
export declare function codeNote(ref: string | null): string;
|
|
3
|
+
export declare function stripCode(text: string): string;
|
|
4
|
+
export declare const UNNAMED_COMMAND = "a command";
|
|
5
|
+
export declare function commandName(command: string): string;
|
|
6
|
+
export declare function setupCommandName(command: string): string;
|
|
7
|
+
export declare function errorLine(stderr: string, sendable?: (line: string) => boolean): string | null;
|
|
8
|
+
export declare function foldHome(text: string, home: string): string;
|
|
9
|
+
export declare function lastWords(output: string): string | null;
|
|
10
|
+
export declare function setupReason(stderr: string, stdout: string): string | null;
|
|
11
|
+
export declare function pushRefusal(stderr: string): string | null;
|
|
12
|
+
export declare function promisesLaterCheck(text: string): boolean;
|
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
import { secretKindsIn } from './secret-scan.js';
|
|
2
|
+
export const CODE_NOTE = 'code kept on the machine';
|
|
3
|
+
export function codeNote(ref) {
|
|
4
|
+
return ref ? `[${CODE_NOTE} — see ${ref}]` : `[${CODE_NOTE}]`;
|
|
5
|
+
}
|
|
6
|
+
const EXTENSIONS = 'tsx?|jsx?|mjs|cjs|py|rb|go|rs|java|kts?|swift|c|h|cc|cpp|hpp|cs|php|sql|json|ya?ml|toml|md|css|scss|less|html?|vue|svelte|sh|bash|zsh|tf|hcl|graphql|gql|prisma|ex|exs|scala|dart|lua|pl|proto|xml|gradle|ini|env|lock|conf|cfg';
|
|
7
|
+
const PATH_REF = new RegExp(`((?:[\\w@.-]+/)*[\\w@-][\\w@.-]*\\.(?:${EXTENSIONS}))(?![\\w])(?:(?::|#L)(\\d+))?`, 'i');
|
|
8
|
+
const CODE_REF = /^(\d+):\d+:(\S+)$/;
|
|
9
|
+
const COMMENT_REF = new RegExp(`^\\s*(?://|#|--|/\\*|<!--|;)\\s*${PATH_REF.source}`, 'i');
|
|
10
|
+
function refOf(m, pathAt = 1, lineAt = 2) {
|
|
11
|
+
if (!m?.[pathAt])
|
|
12
|
+
return null;
|
|
13
|
+
const ref = m[lineAt] ? `${m[pathAt]}:${m[lineAt]}` : m[pathAt];
|
|
14
|
+
return ref.length > 120 ? null : ref;
|
|
15
|
+
}
|
|
16
|
+
function blockRef(info, body, before) {
|
|
17
|
+
const cursor = CODE_REF.exec(info.trim());
|
|
18
|
+
if (cursor)
|
|
19
|
+
return refOf(cursor, 2, 1);
|
|
20
|
+
const fromInfo = refOf(PATH_REF.exec(info));
|
|
21
|
+
if (fromInfo)
|
|
22
|
+
return fromInfo;
|
|
23
|
+
const first = body.find((l) => l.trim()) ?? '';
|
|
24
|
+
const fromComment = refOf(COMMENT_REF.exec(first));
|
|
25
|
+
if (fromComment)
|
|
26
|
+
return fromComment;
|
|
27
|
+
const plus = body.find((l) => /^\+\+\+ /.test(l));
|
|
28
|
+
if (plus) {
|
|
29
|
+
const path = plus.slice(4).trim().replace(/^b\//, '');
|
|
30
|
+
const hunk = body.map((l) => /^@@ -\d+(?:,\d+)? \+(\d+)/.exec(l)).find(Boolean);
|
|
31
|
+
if (path && path !== '/dev/null' && path.length <= 120) {
|
|
32
|
+
return hunk ? `${path}:${hunk[1]}` : path;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const above = PATH_REF.exec(before);
|
|
36
|
+
return above?.[2] ? refOf(above) : null;
|
|
37
|
+
}
|
|
38
|
+
const FENCE_OPEN = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
39
|
+
const LIST_ITEM = /^\s*(?:[-*+]|\d{1,9}[.)])\s/;
|
|
40
|
+
const INDENTED = /^(?: {4}|\t)/;
|
|
41
|
+
const CODE_SHAPE = /[{};]\s*$|[=!<>]=|=>|->|::|\w\([^)]*\)\s*[;:{]?\s*$|^\s*[\w.[\]]+\s*=\s*\S|^\s*(?:def|class|function|const|let|var|import|export|func|fn|impl|struct|package|#include)\s+\S|^\s*(?:SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER)\s|^\s*(?:@@|\$ |>>> )/m;
|
|
42
|
+
const STATEMENT = /[;{}]\s*$|^\s*[}\])]+[;,)]*\s*$|^\s*(?:import|export|const|let|var|def|class|function|func|fn|package|#include)\b.*[=({:;]/;
|
|
43
|
+
const INDENTED_CODE = /^\s+(?:return|raise|throw|yield|await|if|elif|else|for|while|try|except|catch|finally|with)\b/;
|
|
44
|
+
function isCodeLine(line) {
|
|
45
|
+
if (!line.trim() || LIST_ITEM.test(line))
|
|
46
|
+
return false;
|
|
47
|
+
return (STATEMENT.test(line) ||
|
|
48
|
+
(/^\s/.test(line) && (CODE_SHAPE.test(line) || INDENTED_CODE.test(line))));
|
|
49
|
+
}
|
|
50
|
+
const DIFF_HEAD = /^(?:diff --git |index [0-9a-f]{7,}\.\.[0-9a-f]{7,}|--- (?:a\/|\/dev\/null)|\+\+\+ (?:b\/|\/dev\/null)|@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@)/;
|
|
51
|
+
const DIFF_BODY = /^(?:[-+ \\]|@@ |diff --git |index |new file mode|deleted file mode|similarity index|rename (?:from|to) |old mode|new mode|Binary files )/;
|
|
52
|
+
const INLINE_STATEMENT = /[;{}]|=>|(?<![=!<>])=(?![=>])|^\s*(?:return|throw|raise|const|let|var|def|import|from|export|function|class|if|for|while)\s/;
|
|
53
|
+
function inlineSpan(whole, inner) {
|
|
54
|
+
const named = /^[\w@./-]+(?::\d+)?$/.test(inner.trim());
|
|
55
|
+
const code = inner.includes('\n') ||
|
|
56
|
+
inner.length > 60 ||
|
|
57
|
+
(/\s/.test(inner.trim()) && INLINE_STATEMENT.test(inner));
|
|
58
|
+
return code && !named ? codeNote(null) : whole;
|
|
59
|
+
}
|
|
60
|
+
export function stripCode(text) {
|
|
61
|
+
if (!text)
|
|
62
|
+
return text;
|
|
63
|
+
const lines = text
|
|
64
|
+
.replace(/\r\n?/g, '\n')
|
|
65
|
+
.replace(/<pre\b[^>]*>[\s\S]*?(?:<\/pre>|$)/gi, () => codeNote(null))
|
|
66
|
+
.split('\n');
|
|
67
|
+
const fenced = [];
|
|
68
|
+
let before = '';
|
|
69
|
+
for (let i = 0; i < lines.length; i++) {
|
|
70
|
+
const line = lines[i];
|
|
71
|
+
const open = FENCE_OPEN.exec(line);
|
|
72
|
+
if (!open || (open[2].startsWith('`') && open[3].includes('`'))) {
|
|
73
|
+
fenced.push(line);
|
|
74
|
+
if (line.trim())
|
|
75
|
+
before = line;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const [, indent, marker] = open;
|
|
79
|
+
const close = new RegExp(`^ {0,3}${marker[0] === '`' ? '`' : '~'}{${marker.length},}\\s*$`);
|
|
80
|
+
let j = i + 1;
|
|
81
|
+
while (j < lines.length && !close.test(lines[j]))
|
|
82
|
+
j++;
|
|
83
|
+
before = `${indent}${codeNote(blockRef(open[3], lines.slice(i + 1, j), before))}`;
|
|
84
|
+
fenced.push(before);
|
|
85
|
+
i = j;
|
|
86
|
+
}
|
|
87
|
+
const out = [];
|
|
88
|
+
let lastWords = '';
|
|
89
|
+
const keep = (l) => {
|
|
90
|
+
out.push(l);
|
|
91
|
+
if (l.trim())
|
|
92
|
+
lastWords = l;
|
|
93
|
+
};
|
|
94
|
+
for (let i = 0; i < fenced.length; i++) {
|
|
95
|
+
const line = fenced[i];
|
|
96
|
+
const prev = out.length ? out[out.length - 1] : '';
|
|
97
|
+
if (DIFF_HEAD.test(line)) {
|
|
98
|
+
let end = i + 1;
|
|
99
|
+
for (; end < fenced.length; end++) {
|
|
100
|
+
const l = fenced[end];
|
|
101
|
+
if (DIFF_BODY.test(l))
|
|
102
|
+
continue;
|
|
103
|
+
if (!l.trim() && /^(?:\+|@@ |diff --git |-(?! ))/.test(fenced[end + 1] ?? ''))
|
|
104
|
+
continue;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
const block = fenced.slice(i, end);
|
|
108
|
+
if (block.length >= 2 && block.some((l) => /^(?:@@ |\+\+\+ |diff --git )/.test(l))) {
|
|
109
|
+
keep(codeNote(blockRef('', block, lastWords)));
|
|
110
|
+
i = end - 1;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (INDENTED.test(line) && line.trim() && !LIST_ITEM.test(line)) {
|
|
115
|
+
let end = i;
|
|
116
|
+
while (end < fenced.length && (INDENTED.test(fenced[end]) || !fenced[end].trim()))
|
|
117
|
+
end++;
|
|
118
|
+
while (end > i && !fenced[end - 1].trim())
|
|
119
|
+
end--;
|
|
120
|
+
const block = fenced.slice(i, end);
|
|
121
|
+
const inList = LIST_ITEM.test(lastWords) || /^\s/.test(lastWords);
|
|
122
|
+
if ((prev.trim() || inList) && !CODE_SHAPE.test(block.join('\n')))
|
|
123
|
+
block.forEach(keep);
|
|
124
|
+
else
|
|
125
|
+
keep(codeNote(blockRef('', block, lastWords)));
|
|
126
|
+
i = end - 1;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (isCodeLine(line)) {
|
|
130
|
+
let end = i;
|
|
131
|
+
while (end < fenced.length && isCodeLine(fenced[end]))
|
|
132
|
+
end++;
|
|
133
|
+
const block = fenced.slice(i, end);
|
|
134
|
+
if (block.length >= 2 && block.some((l) => STATEMENT.test(l))) {
|
|
135
|
+
keep(codeNote(blockRef('', block, lastWords)));
|
|
136
|
+
i = end - 1;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
keep(line);
|
|
141
|
+
}
|
|
142
|
+
return (out
|
|
143
|
+
.join('\n')
|
|
144
|
+
.replace(/`{3,}[\s\S]*?(?:`{3,}|$)/g, () => codeNote(null))
|
|
145
|
+
.replace(/(?<!`)(`{1,2})(?!`)([\s\S]+?)(?<!`)\1(?!`)/g, (whole, _ticks, inner) => inlineSpan(whole, inner))
|
|
146
|
+
.replace(/<code>([\s\S]*?)<\/code>/gi, (whole, inner) => inlineSpan(whole, inner)));
|
|
147
|
+
}
|
|
148
|
+
function segmentsOf(command) {
|
|
149
|
+
const segs = [];
|
|
150
|
+
let words = [];
|
|
151
|
+
let text = '';
|
|
152
|
+
let raw = '';
|
|
153
|
+
let bare = true;
|
|
154
|
+
let started = false;
|
|
155
|
+
const endWord = () => {
|
|
156
|
+
if (started)
|
|
157
|
+
words.push({ text, raw, bare });
|
|
158
|
+
text = '';
|
|
159
|
+
raw = '';
|
|
160
|
+
bare = true;
|
|
161
|
+
started = false;
|
|
162
|
+
};
|
|
163
|
+
const endSegment = (op) => {
|
|
164
|
+
endWord();
|
|
165
|
+
if (words.length)
|
|
166
|
+
segs.push({ words, op });
|
|
167
|
+
else if (op !== ';' && op && segs.length)
|
|
168
|
+
segs[segs.length - 1].op = op;
|
|
169
|
+
words = [];
|
|
170
|
+
};
|
|
171
|
+
const s = command;
|
|
172
|
+
let i = 0;
|
|
173
|
+
while (i < s.length) {
|
|
174
|
+
const c = s[i];
|
|
175
|
+
const next = s[i + 1];
|
|
176
|
+
if (c === '\\' && next === '\n') {
|
|
177
|
+
endWord();
|
|
178
|
+
i += 2;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (c === '\\') {
|
|
182
|
+
text += next ?? '';
|
|
183
|
+
raw += c + (next ?? '');
|
|
184
|
+
bare = false;
|
|
185
|
+
started = true;
|
|
186
|
+
i += 2;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (c === "'" || c === '"' || c === '`') {
|
|
190
|
+
let j = i + 1;
|
|
191
|
+
while (j < s.length && s[j] !== c)
|
|
192
|
+
j += s[j] === '\\' && c !== "'" ? 2 : 1;
|
|
193
|
+
text += s.slice(i + 1, j);
|
|
194
|
+
raw += s.slice(i, j + 1);
|
|
195
|
+
bare = false;
|
|
196
|
+
started = true;
|
|
197
|
+
i = j + 1;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (c === '$' && next === '(') {
|
|
201
|
+
let depth = 0;
|
|
202
|
+
let j = i + 1;
|
|
203
|
+
for (; j < s.length; j++) {
|
|
204
|
+
if (s[j] === '(')
|
|
205
|
+
depth++;
|
|
206
|
+
else if (s[j] === ')' && --depth === 0)
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
raw += s.slice(i, j + 1);
|
|
210
|
+
bare = false;
|
|
211
|
+
started = true;
|
|
212
|
+
i = j + 1;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (c === '<' && next === '<' && s[i + 2] !== '<') {
|
|
216
|
+
endWord();
|
|
217
|
+
const m = /^<<-?\s*(['"]?)([\w.-]+)\1/.exec(s.slice(i));
|
|
218
|
+
const eol = s.indexOf('\n', i);
|
|
219
|
+
if (!m || eol < 0)
|
|
220
|
+
break;
|
|
221
|
+
const lines = s.slice(eol + 1).split('\n');
|
|
222
|
+
const closeAt = lines.findIndex((l) => l.trim() === m[2]);
|
|
223
|
+
if (closeAt < 0)
|
|
224
|
+
break;
|
|
225
|
+
endSegment(';');
|
|
226
|
+
i = eol + 1 + lines.slice(0, closeAt + 1).join('\n').length;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (c === ' ' || c === '\t') {
|
|
230
|
+
endWord();
|
|
231
|
+
i++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (c === '\n' || c === ';' || c === '(' || c === ')') {
|
|
235
|
+
endSegment(';');
|
|
236
|
+
i++;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if ((c === '&' && next === '&') || (c === '|' && next === '|')) {
|
|
240
|
+
endSegment(c + next);
|
|
241
|
+
i += 2;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (c === '|') {
|
|
245
|
+
endSegment('|');
|
|
246
|
+
i += next === '&' ? 2 : 1;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (c === '&' && s[i - 1] !== '>' && next !== '>') {
|
|
250
|
+
endSegment(';');
|
|
251
|
+
i++;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
text += c;
|
|
255
|
+
raw += c;
|
|
256
|
+
started = true;
|
|
257
|
+
i++;
|
|
258
|
+
}
|
|
259
|
+
endSegment('');
|
|
260
|
+
return segs;
|
|
261
|
+
}
|
|
262
|
+
const WRAPPERS = new Set([
|
|
263
|
+
'sudo',
|
|
264
|
+
'env',
|
|
265
|
+
'time',
|
|
266
|
+
'nice',
|
|
267
|
+
'nohup',
|
|
268
|
+
'command',
|
|
269
|
+
'exec',
|
|
270
|
+
'builtin',
|
|
271
|
+
'timeout',
|
|
272
|
+
'xargs',
|
|
273
|
+
'stdbuf',
|
|
274
|
+
'if',
|
|
275
|
+
'then',
|
|
276
|
+
'else',
|
|
277
|
+
'elif',
|
|
278
|
+
'while',
|
|
279
|
+
'until',
|
|
280
|
+
'do',
|
|
281
|
+
'!',
|
|
282
|
+
'{',
|
|
283
|
+
]);
|
|
284
|
+
const SILENT = new Set([
|
|
285
|
+
'cd',
|
|
286
|
+
'pushd',
|
|
287
|
+
'popd',
|
|
288
|
+
'export',
|
|
289
|
+
'set',
|
|
290
|
+
'unset',
|
|
291
|
+
'source',
|
|
292
|
+
'.',
|
|
293
|
+
'true',
|
|
294
|
+
':',
|
|
295
|
+
'for',
|
|
296
|
+
'case',
|
|
297
|
+
'select',
|
|
298
|
+
'done',
|
|
299
|
+
'fi',
|
|
300
|
+
'esac',
|
|
301
|
+
'}',
|
|
302
|
+
'local',
|
|
303
|
+
]);
|
|
304
|
+
const WITH_SUBCOMMAND = new Set([
|
|
305
|
+
'git',
|
|
306
|
+
'npm',
|
|
307
|
+
'pnpm',
|
|
308
|
+
'yarn',
|
|
309
|
+
'bun',
|
|
310
|
+
'npx',
|
|
311
|
+
'pnpx',
|
|
312
|
+
'bunx',
|
|
313
|
+
'deno',
|
|
314
|
+
'cargo',
|
|
315
|
+
'go',
|
|
316
|
+
'rustup',
|
|
317
|
+
'docker',
|
|
318
|
+
'docker-compose',
|
|
319
|
+
'podman',
|
|
320
|
+
'kubectl',
|
|
321
|
+
'helm',
|
|
322
|
+
'gh',
|
|
323
|
+
'glab',
|
|
324
|
+
'make',
|
|
325
|
+
'just',
|
|
326
|
+
'turbo',
|
|
327
|
+
'nx',
|
|
328
|
+
'poetry',
|
|
329
|
+
'pip',
|
|
330
|
+
'pip3',
|
|
331
|
+
'uv',
|
|
332
|
+
'pipenv',
|
|
333
|
+
'conda',
|
|
334
|
+
'dotnet',
|
|
335
|
+
'mvn',
|
|
336
|
+
'gradle',
|
|
337
|
+
'gradlew',
|
|
338
|
+
'terraform',
|
|
339
|
+
'tofu',
|
|
340
|
+
'aws',
|
|
341
|
+
'gcloud',
|
|
342
|
+
'az',
|
|
343
|
+
'bundle',
|
|
344
|
+
'rake',
|
|
345
|
+
'rails',
|
|
346
|
+
'mix',
|
|
347
|
+
'composer',
|
|
348
|
+
'brew',
|
|
349
|
+
'swift',
|
|
350
|
+
'flutter',
|
|
351
|
+
'dart',
|
|
352
|
+
'vitest',
|
|
353
|
+
'prisma',
|
|
354
|
+
'drizzle-kit',
|
|
355
|
+
'firefunc-runner',
|
|
356
|
+
]);
|
|
357
|
+
const RUNS_A_NAME = new Set(['run', 'run-script', 'exec', 'x', 'dlx']);
|
|
358
|
+
const VALUE_FLAGS = new Set([
|
|
359
|
+
'-C',
|
|
360
|
+
'-c',
|
|
361
|
+
'--filter',
|
|
362
|
+
'-F',
|
|
363
|
+
'--prefix',
|
|
364
|
+
'--dir',
|
|
365
|
+
'--workspace',
|
|
366
|
+
'--cwd',
|
|
367
|
+
'--manifest-path',
|
|
368
|
+
'-f',
|
|
369
|
+
'--file',
|
|
370
|
+
'--project',
|
|
371
|
+
'--profile',
|
|
372
|
+
'--region',
|
|
373
|
+
'-n',
|
|
374
|
+
'--namespace',
|
|
375
|
+
'--context',
|
|
376
|
+
'-p',
|
|
377
|
+
'--package',
|
|
378
|
+
]);
|
|
379
|
+
const SUBCOMMAND = /^[A-Za-z][\w:.-]*$/;
|
|
380
|
+
const PACKAGE = /^@?[A-Za-z][\w:.-]*(?:\/[\w.-]+)?(?:@[\w.^~-]+)?$/;
|
|
381
|
+
function nextName(words, k, shape) {
|
|
382
|
+
for (let i = k; i < words.length; i++) {
|
|
383
|
+
const w = words[i];
|
|
384
|
+
if (w.bare && w.text.startsWith('-')) {
|
|
385
|
+
if (VALUE_FLAGS.has(w.text))
|
|
386
|
+
i++;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
return w.bare && shape.test(w.text) ? w.text : null;
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
function programAt(words) {
|
|
394
|
+
let k = 0;
|
|
395
|
+
let wrapped = false;
|
|
396
|
+
while (k < words.length) {
|
|
397
|
+
const w = words[k];
|
|
398
|
+
if (/^[A-Za-z_]\w*=/.test(w.raw))
|
|
399
|
+
k++;
|
|
400
|
+
else if (w.bare && WRAPPERS.has(w.text)) {
|
|
401
|
+
k++;
|
|
402
|
+
wrapped = true;
|
|
403
|
+
}
|
|
404
|
+
else if (wrapped && w.bare && (w.text.startsWith('-') || /^\d+[smhd]?$/.test(w.text)))
|
|
405
|
+
k++;
|
|
406
|
+
else
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
return k;
|
|
410
|
+
}
|
|
411
|
+
function nameOf(words) {
|
|
412
|
+
const k = programAt(words);
|
|
413
|
+
const first = words[k];
|
|
414
|
+
if (!first?.bare || !/^[\w.@+/-]+$/.test(first.text))
|
|
415
|
+
return null;
|
|
416
|
+
const program = first.text.split('/').pop();
|
|
417
|
+
if (!program || SILENT.has(program))
|
|
418
|
+
return null;
|
|
419
|
+
if (/^python[\d.]*$|^py$/.test(program)) {
|
|
420
|
+
const m = words.findIndex((w, i) => i > k && w.bare && w.text === '-m');
|
|
421
|
+
const mod = m > 0 ? words[m + 1] : undefined;
|
|
422
|
+
return mod?.bare && /^[\w.]+$/.test(mod.text) ? `${program} -m ${mod.text}` : program;
|
|
423
|
+
}
|
|
424
|
+
if (!WITH_SUBCOMMAND.has(program))
|
|
425
|
+
return program;
|
|
426
|
+
const pkgRunner = program === 'npx' || program === 'pnpx' || program === 'bunx';
|
|
427
|
+
const sub = nextName(words, k + 1, pkgRunner ? PACKAGE : SUBCOMMAND);
|
|
428
|
+
if (!sub)
|
|
429
|
+
return program;
|
|
430
|
+
if (!RUNS_A_NAME.has(sub))
|
|
431
|
+
return `${program} ${sub}`;
|
|
432
|
+
const at = words.findIndex((w, i) => i > k && w.bare && w.text === sub);
|
|
433
|
+
const target = nextName(words, at + 1, PACKAGE);
|
|
434
|
+
return target ? `${program} ${sub} ${target}` : `${program} ${sub}`;
|
|
435
|
+
}
|
|
436
|
+
export const UNNAMED_COMMAND = 'a command';
|
|
437
|
+
export function commandName(command) {
|
|
438
|
+
return namesOf(command, nameOf);
|
|
439
|
+
}
|
|
440
|
+
const INTERPRETER = /^(?:sh|bash|zsh|dash|ksh|fish|pwsh|powershell|node|tsx|ts-node|ruby|perl|php|python[\d.]*|py)$/;
|
|
441
|
+
const SHELL = /^(?:sh|bash|zsh|dash|ksh|fish|pwsh|powershell)$/;
|
|
442
|
+
const SCRIPT_NAME = /^[\w@+-][\w.@+-]*\.[A-Za-z0-9]{1,6}$/;
|
|
443
|
+
function scriptOf(words, at, shell) {
|
|
444
|
+
for (let i = at + 1; i < words.length; i++) {
|
|
445
|
+
const w = words[i];
|
|
446
|
+
if (w.bare && w.text.startsWith('-')) {
|
|
447
|
+
const body = shell
|
|
448
|
+
? /^-[a-z]*c[a-z]*$|^-(?:Command|command)$/.test(w.text)
|
|
449
|
+
: /^-(?:[cepr]|-eval|-print)$/.test(w.text);
|
|
450
|
+
if (body)
|
|
451
|
+
return null;
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const file = w.text.split('/').pop() ?? '';
|
|
455
|
+
return SCRIPT_NAME.test(file) && !carriesCredential(file) ? file : null;
|
|
456
|
+
}
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
export function setupCommandName(command) {
|
|
460
|
+
return namesOf(command, (words) => {
|
|
461
|
+
const name = nameOf(words);
|
|
462
|
+
if (!name || !INTERPRETER.test(name))
|
|
463
|
+
return name;
|
|
464
|
+
const script = scriptOf(words, programAt(words), SHELL.test(name));
|
|
465
|
+
return script ? `${name} ${script}` : name;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
function namesOf(command, nameFor) {
|
|
469
|
+
const parts = [];
|
|
470
|
+
let op = '';
|
|
471
|
+
for (const seg of segmentsOf(command)) {
|
|
472
|
+
const name = nameFor(seg.words);
|
|
473
|
+
if (name) {
|
|
474
|
+
if (parts.length)
|
|
475
|
+
parts.push(op === '&&' || op === '||' || op === '|' ? op : ';');
|
|
476
|
+
parts.push(name);
|
|
477
|
+
if (parts.length >= 11)
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
op = seg.op;
|
|
481
|
+
}
|
|
482
|
+
if (!parts.length)
|
|
483
|
+
return UNNAMED_COMMAND;
|
|
484
|
+
return parts.join(' ').replace(/ ;/g, ';');
|
|
485
|
+
}
|
|
486
|
+
const FRAME = /^\s*(?:>?\s*\d*\s*[|│]|[\^~]+\s*$)|^\s+at\s/;
|
|
487
|
+
const ERRORISH = /\b(?:error|fatal|failed|failure|denied|refused|not found|no such|unauthori[sz]ed|forbidden|timed out|cannot|can't|could not|unable|invalid|missing|ENOENT|EACCES|ECONNREFUSED|ETIMEDOUT)\b|\w(?:Error|Exception)\b/i;
|
|
488
|
+
const CARET = /^\s*[\^~]+\s*$/;
|
|
489
|
+
const PY_FRAME = /^\s*File ".*", line \d+/;
|
|
490
|
+
const SHELL_TRACE = /^\s*\+/;
|
|
491
|
+
function traceLines(lines) {
|
|
492
|
+
const traced = lines.map(() => false);
|
|
493
|
+
let open = null;
|
|
494
|
+
for (let i = 0; i < lines.length; i++) {
|
|
495
|
+
const line = lines[i];
|
|
496
|
+
if (!open && !SHELL_TRACE.test(line))
|
|
497
|
+
continue;
|
|
498
|
+
traced[i] = true;
|
|
499
|
+
for (let c = 0; c < line.length; c++) {
|
|
500
|
+
const ch = line[c];
|
|
501
|
+
if (open === 'sq') {
|
|
502
|
+
if (ch === "'")
|
|
503
|
+
open = null;
|
|
504
|
+
}
|
|
505
|
+
else if (open === 'ansi') {
|
|
506
|
+
if (ch === '\\')
|
|
507
|
+
c++;
|
|
508
|
+
else if (ch === "'")
|
|
509
|
+
open = null;
|
|
510
|
+
}
|
|
511
|
+
else if (ch === '\\')
|
|
512
|
+
c++;
|
|
513
|
+
else if (ch === '$' && line[c + 1] === "'") {
|
|
514
|
+
open = 'ansi';
|
|
515
|
+
c++;
|
|
516
|
+
}
|
|
517
|
+
else if (ch === "'")
|
|
518
|
+
open = 'sq';
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return traced;
|
|
522
|
+
}
|
|
523
|
+
export function errorLine(stderr, sendable = () => true) {
|
|
524
|
+
const lines = stderr.split(/\r?\n/);
|
|
525
|
+
const traced = traceLines(lines);
|
|
526
|
+
for (let i = 0; i < lines.length; i++) {
|
|
527
|
+
const raw = lines[i];
|
|
528
|
+
const line = raw.trim();
|
|
529
|
+
if (!line || FRAME.test(raw) || traced[i] || !ERRORISH.test(line))
|
|
530
|
+
continue;
|
|
531
|
+
const next = lines.slice(i + 1, i + 4).find((l) => l.trim()) ?? '';
|
|
532
|
+
if (CARET.test(next) || PY_FRAME.test(lines[i - 1] ?? ''))
|
|
533
|
+
continue;
|
|
534
|
+
if (/[;{]\s*$/.test(line) || (/^\s/.test(raw) && CODE_SHAPE.test(raw)))
|
|
535
|
+
continue;
|
|
536
|
+
if (carriesCredential(line) || !sendable(line))
|
|
537
|
+
continue;
|
|
538
|
+
const kept = stripCode(line).trim();
|
|
539
|
+
if (kept && !kept.startsWith(`[${CODE_NOTE}`))
|
|
540
|
+
return kept;
|
|
541
|
+
}
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
const ANSI = /\u001b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
545
|
+
const CREDENTIAL_FLAG = /(?:^|\s)(?:-u\s*\S*:\S|--user(?:=|\s+)\S*:\S|-p\s*\S|-b\s+\S|--[\w-]*(?:pass(?:word|wd|phrase)?|token|secret|api-?key|access-?key|auth\w*|cred\w*|cookie)(?:=|\s+)\S)|(?:^|\s)(?:-H|--header)(?:=|\s*)['"]?\s*[\w-]*(?:token|key|auth\w*|cookie|secret)[\w-]*\s*:/i;
|
|
546
|
+
const SECRET_URL = /\b(?:hooks\.slack\.com\/(?:services|workflows|triggers)\/|discord(?:app)?\.com\/api\/webhooks\/|[\w.-]*\.webhook\.office\.com\/|outlook\.office(?:365)?\.com\/webhook|hooks\.zapier\.com\/hooks\/|api\.telegram\.org\/bot)|[?&#;](?:[\w-]*(?:token|key|secret|sig|signature|password|passwd|pwd|auth|code|credential|session)[\w-]*|X-Amz-[\w-]+|X-Goog-[\w-]+|sv|se|sp|sr|st)=[^&\s]/i;
|
|
547
|
+
const ENV_ASSIGNMENT = /(?:^|[\s;'"(])[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*=[^\s=]/;
|
|
548
|
+
function carriesCredential(line) {
|
|
549
|
+
return (secretKindsIn(line).length > 0 ||
|
|
550
|
+
/[a-z][a-z0-9+.-]*:\/\/[^\s/@:]*:[^\s/@]+@/i.test(line) ||
|
|
551
|
+
/(?:^|[\s'"(])[^\s:@/'"(]+:[^\s@/]+@[\w-]+\.[\w.-]/.test(line) ||
|
|
552
|
+
/\b[\w.-]*(?:password|passwd|passphrase|secret|token|api[_-]?key|access[_-]?key|private[_-]?key|credentials?)[\w.-]*["']?\s*[:=]\s*\S/i.test(line) ||
|
|
553
|
+
/(?:\b|_)pass["']?\s*[:=]\s*\S/i.test(line) ||
|
|
554
|
+
/\bbearer\s+[A-Za-z0-9._~+/=-]{8,}|\bauthorization\b\s*[:=]|\bcookie\b\s*[:=]/i.test(line) ||
|
|
555
|
+
CREDENTIAL_FLAG.test(line) ||
|
|
556
|
+
SECRET_URL.test(line) ||
|
|
557
|
+
ENV_ASSIGNMENT.test(line));
|
|
558
|
+
}
|
|
559
|
+
const SECRET_WORD = /\b(?:password|passwd|passphrase|secrets?|tokens?|api[\s_-]?keys?|credentials?|private[\s_-]?keys?|bearer|cookies?)\b/i;
|
|
560
|
+
function opaqueRun(line) {
|
|
561
|
+
for (const run of line.match(/[A-Za-z0-9_+/=-]{16,}/g) ?? []) {
|
|
562
|
+
const digit = /\d/.test(run);
|
|
563
|
+
const lower = /[a-z]/.test(run);
|
|
564
|
+
const upper = /[A-Z]/.test(run);
|
|
565
|
+
if (run.includes('/')) {
|
|
566
|
+
if (run.length >= 30 && digit && lower && upper)
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
else if ((digit && (lower || upper)) || (run.length >= 32 && lower && upper))
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
function plainWords(line) {
|
|
575
|
+
if (SHELL_TRACE.test(line) || carriesCredential(line))
|
|
576
|
+
return false;
|
|
577
|
+
if (/:\/\/|\bwww\./i.test(line) || /[=@`]/.test(line))
|
|
578
|
+
return false;
|
|
579
|
+
if (/(?:^|[\s([{"'])--?[A-Za-z]/.test(line))
|
|
580
|
+
return false;
|
|
581
|
+
return !SECRET_WORD.test(line) && !opaqueRun(line);
|
|
582
|
+
}
|
|
583
|
+
export function foldHome(text, home) {
|
|
584
|
+
const root = home.replace(/[\\/]+$/, '');
|
|
585
|
+
if (root.length < 2)
|
|
586
|
+
return text;
|
|
587
|
+
const escaped = root.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
588
|
+
return text.replace(new RegExp(`${escaped}(?![\\w-])`, 'g'), '~');
|
|
589
|
+
}
|
|
590
|
+
export function lastWords(output) {
|
|
591
|
+
const lines = output
|
|
592
|
+
.replace(ANSI, '')
|
|
593
|
+
.split(/\r?\n/)
|
|
594
|
+
.map((l) => l.split('\r').pop() ?? '');
|
|
595
|
+
const traced = traceLines(lines);
|
|
596
|
+
let looked = 0;
|
|
597
|
+
let below = '';
|
|
598
|
+
for (let i = lines.length - 1; i >= 0 && looked < 20; i--) {
|
|
599
|
+
const raw = lines[i];
|
|
600
|
+
const line = raw.trim();
|
|
601
|
+
if (!line)
|
|
602
|
+
continue;
|
|
603
|
+
looked++;
|
|
604
|
+
const under = below;
|
|
605
|
+
below = raw;
|
|
606
|
+
if (traced[i] || FRAME.test(raw) || CARET.test(under) || PY_FRAME.test(lines[i - 1] ?? ''))
|
|
607
|
+
continue;
|
|
608
|
+
if (isCodeLine(raw) || /[;{]\s*$/.test(line) || (/^\s/.test(raw) && CODE_SHAPE.test(raw)))
|
|
609
|
+
continue;
|
|
610
|
+
if (!plainWords(line))
|
|
611
|
+
continue;
|
|
612
|
+
const kept = stripCode(line).trim();
|
|
613
|
+
if (kept && !kept.includes(`[${CODE_NOTE}`))
|
|
614
|
+
return kept;
|
|
615
|
+
}
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
export function setupReason(stderr, stdout) {
|
|
619
|
+
return errorLine(stderr, plainWords) ?? lastWords(stderr) ?? lastWords(stdout);
|
|
620
|
+
}
|
|
621
|
+
export function pushRefusal(stderr) {
|
|
622
|
+
const kept = stderr
|
|
623
|
+
.split(/\r?\n/)
|
|
624
|
+
.map((l) => l.trim())
|
|
625
|
+
.filter((l) => /^(?:error|fatal|hint): /.test(l) ||
|
|
626
|
+
/^husky - /.test(l) ||
|
|
627
|
+
/\[(?:remote )?rejected\]/.test(l) ||
|
|
628
|
+
/^remote: (?:(?:error|fatal)\b|.*\b(?:GH\d{3}|denied|declined|rejected|protected branch|cannot contain secrets)\b)/i.test(l))
|
|
629
|
+
.filter((l) => secretKindsIn(l).length === 0);
|
|
630
|
+
return kept.length ? kept.join(' ') : null;
|
|
631
|
+
}
|
|
632
|
+
const WAITING_OPENER = /^(?:(?:i['’]m|i am|now|currently|still)\s+)*(?:still\s+)?waiting\s+(?:on|for|until)\b/i;
|
|
633
|
+
const LATER_CHECK = /\bi(?:['’]ll| will| am going to|['’]m going to)\s+(?:(?:then|now|come back and|go back and)\s+)?(?:check|look(?: at)?|report(?: back)?|post|update|share|confirm|verify|follow up|circle back|let you know|write(?: the)?|review|re-?run)\b/i;
|
|
634
|
+
const ON_SOMETHING_RUNNING = /\b(?:when|once|after|as soon as|until)\s+(?:it|they|this|that|those|the\s[\w .'/-]{1,60}?|my\s[\w .'/-]{1,60}?)\s+(?:finish(?:es|ed)?|complete[sd]?|(?:is|are)\s+done|come[s]?\s+back|return[s]?|report[s]?|land[s]?|pass(?:es)?|fail[s]?)\b|\b(?:is|are)\s+still\s+running\b|\bin the background\b/i;
|
|
635
|
+
const STILL_RUNNING = /^(?:the|my|our)\s[\w .'/-]{1,60}?\s(?:is|are)\s+still\s+running\b/i;
|
|
636
|
+
const NEGATED = /\b(?:not needed|no need|is not|are not|isn['’]t|aren['’]t|never)\b/i;
|
|
637
|
+
export function promisesLaterCheck(text) {
|
|
638
|
+
const sentences = text
|
|
639
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
640
|
+
.split(/(?<=[.!?…])\s+|\n+/)
|
|
641
|
+
.map((s) => s.replace(/^[\s>*_#-]+/, '').trim())
|
|
642
|
+
.filter(Boolean);
|
|
643
|
+
for (const s of sentences.slice(-2)) {
|
|
644
|
+
if ((WAITING_OPENER.test(s) || STILL_RUNNING.test(s)) && !NEGATED.test(s))
|
|
645
|
+
return true;
|
|
646
|
+
if (LATER_CHECK.test(s) && ON_SOMETHING_RUNNING.test(s))
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
//# sourceMappingURL=keep-local.js.map
|
package/dist/limit.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type PlanLimit = {
|
|
2
|
+
kind: 'plan';
|
|
3
|
+
resetsAt: string | null;
|
|
4
|
+
window?: string;
|
|
5
|
+
said?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function readClaudeLimit(stdout: string, now?: Date): PlanLimit | null;
|
|
8
|
+
export declare function resetFromSentence(text: string, now?: Date): string | null;
|
|
9
|
+
export declare function limitSentence(engineName: string, limit: PlanLimit, kept: boolean): string;
|
|
10
|
+
export type ActiveLimit = {
|
|
11
|
+
engine: string;
|
|
12
|
+
resetsAt: string | null;
|
|
13
|
+
window?: string;
|
|
14
|
+
until: string;
|
|
15
|
+
since: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const UNKNOWN_RESET_WAIT_MS: number;
|
|
18
|
+
export declare const RESET_GRACE_MS: number;
|
|
19
|
+
export declare class LimitGate {
|
|
20
|
+
private readonly file;
|
|
21
|
+
private readonly now;
|
|
22
|
+
private limits;
|
|
23
|
+
constructor(file: string | null, now?: () => number);
|
|
24
|
+
static fileIn(runnerDir: string): string;
|
|
25
|
+
set(engine: string, limit: PlanLimit): ActiveLimit;
|
|
26
|
+
isLimited(engine: string): ActiveLimit | null;
|
|
27
|
+
active(): ActiveLimit[];
|
|
28
|
+
private prune;
|
|
29
|
+
private save;
|
|
30
|
+
}
|