@firefunc-agent/runner 0.7.1 → 0.9.0

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.
Files changed (78) hide show
  1. package/LICENSE +7 -3
  2. package/README.md +233 -3
  3. package/dist/activity.d.ts +29 -0
  4. package/dist/activity.js +209 -0
  5. package/dist/api.d.ts +45 -1
  6. package/dist/api.js +44 -2
  7. package/dist/brief.d.ts +6 -0
  8. package/dist/brief.js +257 -0
  9. package/dist/build-info.json +4 -0
  10. package/dist/cli.js +49 -0
  11. package/dist/config.d.ts +5 -0
  12. package/dist/config.js +3 -0
  13. package/dist/daemon.js +70 -2
  14. package/dist/engines/antigravity.d.ts +2 -0
  15. package/dist/engines/antigravity.js +102 -0
  16. package/dist/engines/claude-budget.d.ts +1 -1
  17. package/dist/engines/claude-budget.js +2 -72
  18. package/dist/engines/claude.js +10 -1
  19. package/dist/engines/codex.js +10 -3
  20. package/dist/engines/copilot.d.ts +2 -0
  21. package/dist/engines/copilot.js +117 -0
  22. package/dist/engines/cursor.js +4 -0
  23. package/dist/engines/gemini.js +6 -1
  24. package/dist/engines/index.d.ts +2 -0
  25. package/dist/engines/index.js +22 -4
  26. package/dist/engines/types.d.ts +2 -1
  27. package/dist/firefunc/agents.d.ts +2 -0
  28. package/dist/firefunc/agents.js +291 -0
  29. package/dist/firefunc/args.d.ts +18 -0
  30. package/dist/firefunc/args.js +82 -0
  31. package/dist/firefunc/auth.d.ts +21 -0
  32. package/dist/firefunc/auth.js +129 -0
  33. package/dist/firefunc/catalog.d.ts +10 -0
  34. package/dist/firefunc/catalog.js +201 -0
  35. package/dist/firefunc/cli.d.ts +2 -0
  36. package/dist/firefunc/cli.js +24 -0
  37. package/dist/firefunc/client.d.ts +35 -0
  38. package/dist/firefunc/client.js +174 -0
  39. package/dist/firefunc/command.d.ts +28 -0
  40. package/dist/firefunc/command.js +35 -0
  41. package/dist/firefunc/config.d.ts +29 -0
  42. package/dist/firefunc/config.js +111 -0
  43. package/dist/firefunc/io.d.ts +25 -0
  44. package/dist/firefunc/io.js +14 -0
  45. package/dist/firefunc/main.d.ts +4 -0
  46. package/dist/firefunc/main.js +221 -0
  47. package/dist/firefunc/output.d.ts +29 -0
  48. package/dist/firefunc/output.js +128 -0
  49. package/dist/firefunc/prompt.d.ts +14 -0
  50. package/dist/firefunc/prompt.js +58 -0
  51. package/dist/firefunc/skill.d.ts +3 -0
  52. package/dist/firefunc/skill.js +80 -0
  53. package/dist/firefunc/tasks.d.ts +2 -0
  54. package/dist/firefunc/tasks.js +279 -0
  55. package/dist/firefunc/version.d.ts +2 -0
  56. package/dist/firefunc/version.js +23 -0
  57. package/dist/git-auth.d.ts +4 -1
  58. package/dist/git-auth.js +6 -2
  59. package/dist/job.js +439 -84
  60. package/dist/keep-local.d.ts +7 -0
  61. package/dist/keep-local.js +484 -0
  62. package/dist/machine-logins.d.ts +19 -0
  63. package/dist/machine-logins.js +187 -0
  64. package/dist/mcp-login.d.ts +24 -0
  65. package/dist/mcp-login.js +993 -0
  66. package/dist/mcp.d.ts +60 -0
  67. package/dist/mcp.js +582 -0
  68. package/dist/network.d.ts +20 -0
  69. package/dist/network.js +76 -0
  70. package/dist/pending.d.ts +14 -0
  71. package/dist/pending.js +56 -0
  72. package/dist/secret-scan.d.ts +19 -0
  73. package/dist/secret-scan.js +161 -0
  74. package/dist/session-stream.d.ts +1 -0
  75. package/dist/session-stream.js +11 -1
  76. package/dist/viewer.js +7 -1
  77. package/package.json +8 -5
  78. package/skill/firefunc/SKILL.md +173 -0
@@ -0,0 +1,7 @@
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 errorLine(stderr: string): string | null;
7
+ export declare function pushRefusal(stderr: string): string | null;
@@ -0,0 +1,484 @@
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 nameOf(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
+ const first = words[k];
410
+ if (!first?.bare || !/^[\w.@+/-]+$/.test(first.text))
411
+ return null;
412
+ const program = first.text.split('/').pop();
413
+ if (!program || SILENT.has(program))
414
+ return null;
415
+ if (/^python[\d.]*$|^py$/.test(program)) {
416
+ const m = words.findIndex((w, i) => i > k && w.bare && w.text === '-m');
417
+ const mod = m > 0 ? words[m + 1] : undefined;
418
+ return mod?.bare && /^[\w.]+$/.test(mod.text) ? `${program} -m ${mod.text}` : program;
419
+ }
420
+ if (!WITH_SUBCOMMAND.has(program))
421
+ return program;
422
+ const pkgRunner = program === 'npx' || program === 'pnpx' || program === 'bunx';
423
+ const sub = nextName(words, k + 1, pkgRunner ? PACKAGE : SUBCOMMAND);
424
+ if (!sub)
425
+ return program;
426
+ if (!RUNS_A_NAME.has(sub))
427
+ return `${program} ${sub}`;
428
+ const at = words.findIndex((w, i) => i > k && w.bare && w.text === sub);
429
+ const target = nextName(words, at + 1, PACKAGE);
430
+ return target ? `${program} ${sub} ${target}` : `${program} ${sub}`;
431
+ }
432
+ export const UNNAMED_COMMAND = 'a command';
433
+ export function commandName(command) {
434
+ const parts = [];
435
+ let op = '';
436
+ for (const seg of segmentsOf(command)) {
437
+ const name = nameOf(seg.words);
438
+ if (name) {
439
+ if (parts.length)
440
+ parts.push(op === '&&' || op === '||' || op === '|' ? op : ';');
441
+ parts.push(name);
442
+ if (parts.length >= 11)
443
+ break;
444
+ }
445
+ op = seg.op;
446
+ }
447
+ if (!parts.length)
448
+ return UNNAMED_COMMAND;
449
+ return parts.join(' ').replace(/ ;/g, ';');
450
+ }
451
+ const FRAME = /^\s*(?:>?\s*\d*\s*[|│]|[\^~]+\s*$)|^\s+at\s/;
452
+ 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;
453
+ const CARET = /^\s*[\^~]+\s*$/;
454
+ const PY_FRAME = /^\s*File ".*", line \d+/;
455
+ export function errorLine(stderr) {
456
+ const lines = stderr.split(/\r?\n/);
457
+ for (let i = 0; i < lines.length; i++) {
458
+ const raw = lines[i];
459
+ const line = raw.trim();
460
+ if (!line || FRAME.test(raw) || !ERRORISH.test(line))
461
+ continue;
462
+ const next = lines.slice(i + 1, i + 4).find((l) => l.trim()) ?? '';
463
+ if (CARET.test(next) || PY_FRAME.test(lines[i - 1] ?? ''))
464
+ continue;
465
+ if (/[;{]\s*$/.test(line) || (/^\s/.test(raw) && CODE_SHAPE.test(raw)))
466
+ continue;
467
+ const kept = stripCode(line).trim();
468
+ if (kept && !kept.startsWith(`[${CODE_NOTE}`))
469
+ return kept;
470
+ }
471
+ return null;
472
+ }
473
+ export function pushRefusal(stderr) {
474
+ const kept = stderr
475
+ .split(/\r?\n/)
476
+ .map((l) => l.trim())
477
+ .filter((l) => /^(?:error|fatal|hint): /.test(l) ||
478
+ /^husky - /.test(l) ||
479
+ /\[(?:remote )?rejected\]/.test(l) ||
480
+ /^remote: (?:(?:error|fatal)\b|.*\b(?:GH\d{3}|denied|declined|rejected|protected branch|cannot contain secrets)\b)/i.test(l))
481
+ .filter((l) => secretKindsIn(l).length === 0);
482
+ return kept.length ? kept.join(' ') : null;
483
+ }
484
+ //# sourceMappingURL=keep-local.js.map
@@ -0,0 +1,19 @@
1
+ export type MachineLoginState = 'logged_in' | 'expired' | 'error';
2
+ export type MachineLogin = {
3
+ server: string;
4
+ state: MachineLoginState;
5
+ via: 'runner' | 'claude_code';
6
+ serverUrl: string | null;
7
+ accountLabel: string | null;
8
+ expiresAt: string | null;
9
+ detail?: string;
10
+ };
11
+ export declare const VENDOR_MCP_URLS: Readonly<Record<string, string>>;
12
+ export declare const CATALOG_ONLY: ReadonlySet<string>;
13
+ export declare function runnerLogins(now?: number): MachineLogin[];
14
+ export type ClaudeCodeStoreReader = () => string | null;
15
+ export declare function readClaudeCodeStore(): string | null;
16
+ export declare function claudeCodeLogins(now?: number, read?: ClaudeCodeStoreReader): MachineLogin[];
17
+ export declare function machineLogins(now?: number, read?: ClaudeCodeStoreReader): MachineLogin[];
18
+ export declare function claudeCodeSignsFor(server: string, url: string, now?: number, read?: ClaudeCodeStoreReader): boolean;
19
+ export declare function claudeCodeSignInFix(server: string): string;
@@ -0,0 +1,187 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, readFileSync, readdirSync } from 'node:fs';
3
+ import { homedir, platform } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { mcpLoginPath } from './mcp.js';
6
+ import { configPath } from './config.js';
7
+ export const VENDOR_MCP_URLS = {
8
+ figma: 'https://mcp.figma.com/mcp',
9
+ jira: 'https://mcp.atlassian.com/v2/mcp',
10
+ linear: 'https://mcp.linear.app/mcp/readonly',
11
+ sentry: 'https://mcp.sentry.dev/mcp',
12
+ slack: 'https://mcp.slack.com/mcp',
13
+ };
14
+ export const CATALOG_ONLY = new Set(['figma']);
15
+ const SERVER_KEY = /^[a-z0-9]+([_-][a-z0-9]+)*$/;
16
+ const SKEW_MS = 60_000;
17
+ const normalizeUrl = (u) => u.replace(/\/+$/, '').toLowerCase();
18
+ function expiryState(expiresAt, now) {
19
+ if (expiresAt === undefined || expiresAt === null || expiresAt === '') {
20
+ return { state: 'logged_in', iso: null };
21
+ }
22
+ const ms = typeof expiresAt === 'number'
23
+ ? expiresAt
24
+ : typeof expiresAt === 'string'
25
+ ? /^\d+$/.test(expiresAt)
26
+ ? Number(expiresAt)
27
+ : Date.parse(expiresAt)
28
+ : Number.NaN;
29
+ if (!Number.isFinite(ms))
30
+ return { state: 'logged_in', iso: null };
31
+ return { state: ms <= now + SKEW_MS ? 'expired' : 'logged_in', iso: new Date(ms).toISOString() };
32
+ }
33
+ export function runnerLogins(now = Date.now()) {
34
+ const dir = join(configPath(), '..', 'mcp-logins');
35
+ let names = [];
36
+ try {
37
+ names = readdirSync(dir).filter((n) => n.endsWith('.json'));
38
+ }
39
+ catch {
40
+ return [];
41
+ }
42
+ const out = [];
43
+ for (const name of names.sort()) {
44
+ const server = name.slice(0, -'.json'.length);
45
+ if (!SERVER_KEY.test(server) || server.length > 64)
46
+ continue;
47
+ let raw;
48
+ try {
49
+ raw = JSON.parse(readFileSync(mcpLoginPath(server), 'utf8'));
50
+ }
51
+ catch {
52
+ out.push({
53
+ server,
54
+ state: 'error',
55
+ via: 'runner',
56
+ serverUrl: null,
57
+ accountLabel: null,
58
+ expiresAt: null,
59
+ detail: 'the cached login could not be read',
60
+ });
61
+ continue;
62
+ }
63
+ const r = (raw && typeof raw === 'object' ? raw : {});
64
+ if (typeof r.accessToken !== 'string' || !r.accessToken) {
65
+ out.push({
66
+ server,
67
+ state: 'error',
68
+ via: 'runner',
69
+ serverUrl: typeof r.serverUrl === 'string' ? r.serverUrl : null,
70
+ accountLabel: null,
71
+ expiresAt: null,
72
+ detail: 'the cached login holds no token',
73
+ });
74
+ continue;
75
+ }
76
+ const { state, iso } = expiryState(r.expiresAt, now);
77
+ out.push({
78
+ server,
79
+ state,
80
+ via: 'runner',
81
+ serverUrl: typeof r.serverUrl === 'string' ? r.serverUrl : null,
82
+ accountLabel: typeof r.accountLabel === 'string' ? r.accountLabel : null,
83
+ expiresAt: iso,
84
+ });
85
+ }
86
+ return out;
87
+ }
88
+ export function readClaudeCodeStore() {
89
+ if (platform() === 'darwin') {
90
+ try {
91
+ const res = spawnSync('security', ['find-generic-password', '-s', 'Claude Code-credentials', '-w'], {
92
+ encoding: 'utf8',
93
+ timeout: 5_000,
94
+ });
95
+ if (res.status === 0 && res.stdout.trim())
96
+ return res.stdout.trim();
97
+ }
98
+ catch {
99
+ }
100
+ }
101
+ const dir = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude');
102
+ const file = join(dir, '.credentials.json');
103
+ if (!existsSync(file))
104
+ return null;
105
+ try {
106
+ return readFileSync(file, 'utf8');
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ }
112
+ export function claudeCodeLogins(now = Date.now(), read = readClaudeCodeStore) {
113
+ const text = read();
114
+ if (!text)
115
+ return [];
116
+ let store;
117
+ try {
118
+ store = JSON.parse(text);
119
+ }
120
+ catch {
121
+ return [];
122
+ }
123
+ const oauth = store?.mcpOAuth;
124
+ if (!oauth || typeof oauth !== 'object')
125
+ return [];
126
+ const byUrl = new Map(Object.entries(VENDOR_MCP_URLS).map(([id, url]) => [normalizeUrl(url), id]));
127
+ const out = [];
128
+ for (const entry of Object.values(oauth)) {
129
+ if (!entry || typeof entry !== 'object')
130
+ continue;
131
+ const e = entry;
132
+ const url = typeof e.serverUrl === 'string' ? e.serverUrl : null;
133
+ const name = typeof e.serverName === 'string' ? e.serverName : null;
134
+ if (!url || !name)
135
+ continue;
136
+ const vendor = byUrl.get(normalizeUrl(url));
137
+ if (!vendor)
138
+ continue;
139
+ const hasToken = (typeof e.accessToken === 'string' && e.accessToken.length > 0) ||
140
+ (typeof e.refreshToken === 'string' && e.refreshToken.length > 0);
141
+ if (!hasToken)
142
+ continue;
143
+ if (name !== vendor) {
144
+ out.push({
145
+ server: vendor,
146
+ state: 'error',
147
+ via: 'claude_code',
148
+ serverUrl: url,
149
+ accountLabel: null,
150
+ expiresAt: null,
151
+ detail: `Claude Code holds this sign-in under the name "${name}"; a run names the server "${vendor}", and Claude Code keys the sign-in by name. Re-add it as "${vendor}".`,
152
+ });
153
+ continue;
154
+ }
155
+ const { state, iso } = expiryState(e.expiresAt, now);
156
+ const refreshable = typeof e.refreshToken === 'string' && e.refreshToken.length > 0;
157
+ out.push({
158
+ server: vendor,
159
+ state: state === 'expired' && refreshable ? 'logged_in' : state,
160
+ via: 'claude_code',
161
+ serverUrl: url,
162
+ accountLabel: null,
163
+ expiresAt: iso,
164
+ });
165
+ }
166
+ return out.sort((a, b) => a.server.localeCompare(b.server));
167
+ }
168
+ export function machineLogins(now = Date.now(), read = readClaudeCodeStore) {
169
+ const mine = runnerLogins(now);
170
+ const seen = new Set(mine.filter((l) => l.state === 'logged_in').map((l) => l.server));
171
+ const theirs = claudeCodeLogins(now, read).filter((l) => !seen.has(l.server));
172
+ return [...mine, ...theirs].sort((a, b) => a.server.localeCompare(b.server));
173
+ }
174
+ export function claudeCodeSignsFor(server, url, now = Date.now(), read = readClaudeCodeStore) {
175
+ return claudeCodeLogins(now, read).some((l) => l.server === server &&
176
+ l.state === 'logged_in' &&
177
+ l.serverUrl !== null &&
178
+ normalizeUrl(l.serverUrl) === normalizeUrl(url));
179
+ }
180
+ export function claudeCodeSignInFix(server) {
181
+ const url = VENDOR_MCP_URLS[server];
182
+ if (!url)
183
+ return `sign Claude Code in to the "${server}" server on this machine`;
184
+ return (`on this machine run \`claude mcp add --transport http ${server} ${url}\`, then inside \`claude\` run \`/mcp\` and authenticate ${server}; ` +
185
+ `the sign-in stays in Claude Code's own store and runs use it without FireFunc ever holding it`);
186
+ }
187
+ //# sourceMappingURL=machine-logins.js.map