@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.
Files changed (114) hide show
  1. package/LICENSE +7 -3
  2. package/README.md +296 -4
  3. package/dist/activity.d.ts +32 -0
  4. package/dist/activity.js +295 -0
  5. package/dist/api.d.ts +69 -1
  6. package/dist/api.js +114 -3
  7. package/dist/brief.d.ts +11 -0
  8. package/dist/brief.js +278 -0
  9. package/dist/build-info.json +4 -0
  10. package/dist/cli.js +59 -2
  11. package/dist/config.d.ts +7 -0
  12. package/dist/config.js +3 -0
  13. package/dist/cut.d.ts +45 -0
  14. package/dist/cut.js +105 -0
  15. package/dist/daemon.d.ts +16 -0
  16. package/dist/daemon.js +196 -7
  17. package/dist/declined.d.ts +11 -0
  18. package/dist/declined.js +27 -0
  19. package/dist/engines/antigravity.d.ts +2 -0
  20. package/dist/engines/antigravity.js +102 -0
  21. package/dist/engines/claude-budget.d.ts +1 -1
  22. package/dist/engines/claude-budget.js +2 -72
  23. package/dist/engines/claude.js +139 -2
  24. package/dist/engines/codex.js +10 -3
  25. package/dist/engines/copilot.d.ts +2 -0
  26. package/dist/engines/copilot.js +117 -0
  27. package/dist/engines/cursor.js +4 -0
  28. package/dist/engines/gemini.js +6 -1
  29. package/dist/engines/index.d.ts +2 -0
  30. package/dist/engines/index.js +22 -4
  31. package/dist/engines/types.d.ts +12 -1
  32. package/dist/exec.d.ts +3 -0
  33. package/dist/exec.js +48 -5
  34. package/dist/firefunc/agents.d.ts +2 -0
  35. package/dist/firefunc/agents.js +343 -0
  36. package/dist/firefunc/args.d.ts +18 -0
  37. package/dist/firefunc/args.js +82 -0
  38. package/dist/firefunc/auth.d.ts +21 -0
  39. package/dist/firefunc/auth.js +129 -0
  40. package/dist/firefunc/catalog.d.ts +10 -0
  41. package/dist/firefunc/catalog.js +201 -0
  42. package/dist/firefunc/cli.d.ts +2 -0
  43. package/dist/firefunc/cli.js +24 -0
  44. package/dist/firefunc/client.d.ts +36 -0
  45. package/dist/firefunc/client.js +177 -0
  46. package/dist/firefunc/command.d.ts +28 -0
  47. package/dist/firefunc/command.js +35 -0
  48. package/dist/firefunc/config.d.ts +29 -0
  49. package/dist/firefunc/config.js +111 -0
  50. package/dist/firefunc/configure.d.ts +6 -0
  51. package/dist/firefunc/configure.js +409 -0
  52. package/dist/firefunc/io.d.ts +25 -0
  53. package/dist/firefunc/io.js +14 -0
  54. package/dist/firefunc/main.d.ts +4 -0
  55. package/dist/firefunc/main.js +259 -0
  56. package/dist/firefunc/output.d.ts +29 -0
  57. package/dist/firefunc/output.js +131 -0
  58. package/dist/firefunc/prompt.d.ts +14 -0
  59. package/dist/firefunc/prompt.js +58 -0
  60. package/dist/firefunc/skill.d.ts +3 -0
  61. package/dist/firefunc/skill.js +80 -0
  62. package/dist/firefunc/tasks.d.ts +2 -0
  63. package/dist/firefunc/tasks.js +279 -0
  64. package/dist/firefunc/version.d.ts +2 -0
  65. package/dist/firefunc/version.js +8 -0
  66. package/dist/git-auth.d.ts +4 -1
  67. package/dist/git-auth.js +6 -2
  68. package/dist/held.d.ts +18 -0
  69. package/dist/held.js +95 -0
  70. package/dist/job.d.ts +3 -0
  71. package/dist/job.js +818 -102
  72. package/dist/keep-local.d.ts +12 -0
  73. package/dist/keep-local.js +651 -0
  74. package/dist/limit.d.ts +30 -0
  75. package/dist/limit.js +258 -0
  76. package/dist/locks.d.ts +14 -0
  77. package/dist/locks.js +164 -0
  78. package/dist/machine-logins.d.ts +19 -0
  79. package/dist/machine-logins.js +187 -0
  80. package/dist/mcp-login.d.ts +24 -0
  81. package/dist/mcp-login.js +993 -0
  82. package/dist/mcp-proxy.d.ts +21 -0
  83. package/dist/mcp-proxy.js +180 -0
  84. package/dist/mcp.d.ts +62 -0
  85. package/dist/mcp.js +611 -0
  86. package/dist/network.d.ts +20 -0
  87. package/dist/network.js +76 -0
  88. package/dist/orphans.d.ts +40 -0
  89. package/dist/orphans.js +235 -0
  90. package/dist/pending.d.ts +14 -0
  91. package/dist/pending.js +56 -0
  92. package/dist/pool.d.ts +7 -0
  93. package/dist/pool.js +57 -9
  94. package/dist/pr-title.d.ts +11 -0
  95. package/dist/pr-title.js +63 -0
  96. package/dist/recover.d.ts +10 -0
  97. package/dist/recover.js +104 -0
  98. package/dist/secret-scan.d.ts +19 -0
  99. package/dist/secret-scan.js +161 -0
  100. package/dist/session-stream.d.ts +9 -1
  101. package/dist/session-stream.js +20 -2
  102. package/dist/skills.d.ts +11 -0
  103. package/dist/skills.js +164 -0
  104. package/dist/stopped.d.ts +3 -0
  105. package/dist/stopped.js +10 -0
  106. package/dist/usage.d.ts +49 -0
  107. package/dist/usage.js +389 -0
  108. package/dist/version.d.ts +1 -0
  109. package/dist/version.js +17 -0
  110. package/dist/viewer.js +7 -1
  111. package/dist/worktrees.d.ts +15 -0
  112. package/dist/worktrees.js +96 -0
  113. package/package.json +8 -5
  114. package/skill/firefunc/SKILL.md +222 -0
@@ -0,0 +1,104 @@
1
+ import { existsSync, rmSync } from 'node:fs';
2
+ import { basename } from 'node:path';
3
+ import { keptWorktrees } from './cut.js';
4
+ import { heldByGoneProcesses, releaseHeld } from './held.js';
5
+ import { isNetworkError, withNetworkRetry } from './network.js';
6
+ import { killOrphans, reviewCopiesOf } from './orphans.js';
7
+ import { listPendingResults, savePendingResult } from './pending.js';
8
+ import { canonicalPath, removeRunnerWorktree } from './worktrees.js';
9
+ export function lostSentence(machine) {
10
+ return (`The attempt did not finish: the runner on ${machine} stopped while it was running — ` +
11
+ 'the runner process was restarted, stopped or crashed — and the process that took over ' +
12
+ 'does not hold it, so nothing more will be reported for it. What it left running on the ' +
13
+ 'machine was stopped and its worktree removed. Re-run the task.');
14
+ }
15
+ async function clearUp(rec, keep, log) {
16
+ const roots = [rec.worktree, ...(rec.scratch ?? [])].filter((p) => !!p);
17
+ const kept = rec.worktree ? keep.has(canonicalPath(rec.worktree)) : false;
18
+ const copies = rec.worktree ? reviewCopiesOf(rec.worktree) : [];
19
+ await killOrphans({
20
+ roots: [...roots, ...copies],
21
+ ...(rec.worktree ? { reviewCopiesOf: basename(rec.worktree) } : {}),
22
+ ...(rec.engineGroup
23
+ ? {
24
+ groups: [
25
+ {
26
+ pgid: rec.engineGroup,
27
+ startedAt: rec.engineStartedAt ?? 0,
28
+ leaderExited: false,
29
+ },
30
+ ],
31
+ }
32
+ : {}),
33
+ }, { log });
34
+ if (rec.worktree && !kept) {
35
+ if (rec.repoPath && existsSync(rec.repoPath)) {
36
+ await removeRunnerWorktree(rec.repoPath, rec.worktree, log);
37
+ }
38
+ else {
39
+ rmSync(rec.worktree, { recursive: true, force: true });
40
+ }
41
+ }
42
+ for (const p of rec.scratch ?? []) {
43
+ try {
44
+ rmSync(p, { recursive: true, force: true });
45
+ }
46
+ catch {
47
+ }
48
+ }
49
+ }
50
+ export async function recoverPreviousProcess(deps) {
51
+ const lost = [];
52
+ let gone;
53
+ try {
54
+ gone = heldByGoneProcesses(deps.runnerDir);
55
+ }
56
+ catch {
57
+ return lost;
58
+ }
59
+ if (gone.length === 0)
60
+ return lost;
61
+ const pending = new Set(listPendingResults(deps.runnerDir).map((p) => p.runId));
62
+ const keep = new Set([...keptWorktrees(deps.runnerDir)].map(canonicalPath));
63
+ deps.log(`${gone.length} run(s) were held by a runner process that is no longer running — stopping what they left and reporting them`);
64
+ let offline = false;
65
+ for (const rec of gone) {
66
+ try {
67
+ await clearUp(rec, keep, deps.log);
68
+ if (!pending.has(rec.runId)) {
69
+ const payload = {
70
+ status: 'failed',
71
+ error: lostSentence(deps.machine),
72
+ lost: true,
73
+ };
74
+ try {
75
+ if (offline)
76
+ throw new Error('fetch failed: FireFunc was unreachable a moment ago');
77
+ await withNetworkRetry(() => deps.api.result(rec.runId, payload), {
78
+ label: `lost run ${rec.runId}`,
79
+ maxWaitMs: deps.maxWaitMs ?? 2 * 60_000,
80
+ probe: () => deps.api.probe(),
81
+ log: deps.log,
82
+ });
83
+ deps.log(`reported run ${rec.runId} as lost with the previous runner process`);
84
+ }
85
+ catch (err) {
86
+ if (isNetworkError(err)) {
87
+ offline = true;
88
+ savePendingResult(deps.runnerDir, rec.runId, payload);
89
+ deps.log(`FireFunc is unreachable — kept the lost report for ${rec.runId}; it is delivered when the network is back`);
90
+ }
91
+ else {
92
+ deps.log(`FireFunc did not take the lost report for ${rec.runId}: ${err.message}`);
93
+ }
94
+ }
95
+ lost.push(rec.runId);
96
+ }
97
+ }
98
+ finally {
99
+ releaseHeld(deps.runnerDir, rec.runId);
100
+ }
101
+ }
102
+ return lost;
103
+ }
104
+ //# sourceMappingURL=recover.js.map
@@ -0,0 +1,19 @@
1
+ export type SecretKind = 'aws_access_key_id' | 'aws_secret_access_key' | 'github_token' | 'slack_token' | 'google_api_key' | 'stripe_secret_key' | 'private_key_block' | 'jwt' | 'generic_assignment';
2
+ export type SecretHit = {
3
+ path: string;
4
+ kind: SecretKind;
5
+ line: number;
6
+ };
7
+ export declare const SOFT_KINDS: ReadonlySet<SecretKind>;
8
+ export declare function refusesPush(hit: SecretHit): boolean;
9
+ export declare const FULL_SHA: RegExp;
10
+ export declare function secretKindsIn(line: string): SecretKind[];
11
+ export declare function scanAddedLines(diff: string): SecretHit[];
12
+ export declare function changeReads(from: string, branch: string, tip?: string): {
13
+ whole: string[];
14
+ commits: string[];
15
+ env: Record<string, string>;
16
+ };
17
+ export declare function uniqueHits(hits: SecretHit[]): SecretHit[];
18
+ export declare function hardFirst(hits: SecretHit[]): SecretHit[];
19
+ export declare function secretRefusal(hits: SecretHit[], branch?: string): string;
@@ -0,0 +1,161 @@
1
+ import { devNull } from 'node:os';
2
+ export const SOFT_KINDS = new Set(['generic_assignment']);
3
+ export function refusesPush(hit) {
4
+ return !SOFT_KINDS.has(hit.kind);
5
+ }
6
+ export const FULL_SHA = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
7
+ const PATTERNS = [
8
+ { kind: 'aws_access_key_id', re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/ },
9
+ {
10
+ kind: 'aws_secret_access_key',
11
+ re: /\baws_secret_access_key\b\s*[:=]\s*['"]?[A-Za-z0-9/+]{40}['"]?/i,
12
+ },
13
+ { kind: 'github_token', re: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36}\b/ },
14
+ { kind: 'github_token', re: /\bgithub_pat_[A-Za-z0-9_]{82}\b/ },
15
+ { kind: 'slack_token', re: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/ },
16
+ { kind: 'google_api_key', re: /\bAIza[0-9A-Za-z\-_]{35}\b/ },
17
+ { kind: 'stripe_secret_key', re: /\bsk_(?:live|test)_[0-9a-zA-Z]{16,}\b/ },
18
+ { kind: 'private_key_block', re: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/ },
19
+ { kind: 'jwt', re: /\bey[A-Za-z0-9_-]{10,}\.ey[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/ },
20
+ {
21
+ kind: 'generic_assignment',
22
+ re: /\b(?:secret|passwd|password|api[_-]?key|access[_-]?token|private[_-]?key)\b\s*[:=]\s*['"][^'"\n]{12,}['"]/i,
23
+ },
24
+ ];
25
+ const DOCUMENTED_EXAMPLES = ['AKIAIOSFODNN7EXAMPLE', 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'];
26
+ export function secretKindsIn(line) {
27
+ const found = [];
28
+ for (const { kind, re } of PATTERNS) {
29
+ if (found.includes(kind))
30
+ continue;
31
+ const all = new RegExp(re.source, `${re.flags}g`);
32
+ for (const m of line.matchAll(all)) {
33
+ if (DOCUMENTED_EXAMPLES.some((ex) => m[0].includes(ex)))
34
+ continue;
35
+ found.push(kind);
36
+ break;
37
+ }
38
+ }
39
+ return found;
40
+ }
41
+ function pathOf(header) {
42
+ let p = header.replace(/\t.*$/, '').trim();
43
+ if (p === '/dev/null')
44
+ return null;
45
+ if (p.startsWith('"') && p.endsWith('"')) {
46
+ p = p
47
+ .slice(1, -1)
48
+ .replace(/\\([\\"tn])/g, (_, c) => (c === 't' ? '\t' : c === 'n' ? '\n' : c));
49
+ }
50
+ return p.replace(/^b\//, '') || null;
51
+ }
52
+ export function scanAddedLines(diff) {
53
+ const hits = [];
54
+ let path = null;
55
+ let newLine = 0;
56
+ let oldLeft = 0;
57
+ let newLeft = 0;
58
+ for (const raw of diff.split('\n')) {
59
+ const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
60
+ if (oldLeft > 0 || newLeft > 0) {
61
+ const c = line[0];
62
+ if (c === '+') {
63
+ if (path)
64
+ for (const kind of secretKindsIn(line.slice(1)))
65
+ hits.push({ path, kind, line: newLine });
66
+ newLine++;
67
+ newLeft--;
68
+ continue;
69
+ }
70
+ if (c === '-') {
71
+ oldLeft--;
72
+ continue;
73
+ }
74
+ if (c === ' ') {
75
+ newLine++;
76
+ newLeft--;
77
+ oldLeft--;
78
+ continue;
79
+ }
80
+ if (c === '\\')
81
+ continue;
82
+ oldLeft = 0;
83
+ newLeft = 0;
84
+ }
85
+ if (line.startsWith('diff --git ')) {
86
+ path = null;
87
+ continue;
88
+ }
89
+ if (line.startsWith('+++ ')) {
90
+ path = pathOf(line.slice(4));
91
+ continue;
92
+ }
93
+ const hunk = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(line);
94
+ if (hunk) {
95
+ oldLeft = hunk[1] === undefined ? 1 : Number(hunk[1]);
96
+ newLine = Number(hunk[2]);
97
+ newLeft = hunk[3] === undefined ? 1 : Number(hunk[3]);
98
+ }
99
+ }
100
+ return hits;
101
+ }
102
+ const PATCH_FLAGS = [
103
+ '--no-color',
104
+ '--no-ext-diff',
105
+ '--no-textconv',
106
+ '--text',
107
+ '--src-prefix=a/',
108
+ '--dst-prefix=b/',
109
+ '-U0',
110
+ ];
111
+ export function changeReads(from, branch, tip) {
112
+ const pushed = tip ?? `refs/heads/${branch}`;
113
+ const base = [
114
+ '--no-replace-objects',
115
+ '-c',
116
+ 'core.quotepath=off',
117
+ '-c',
118
+ 'advice.graftFileDeprecated=false',
119
+ ];
120
+ return {
121
+ whole: [...base, 'diff', ...PATCH_FLAGS, `${from}...${pushed}`],
122
+ commits: [
123
+ ...base,
124
+ 'log',
125
+ '--no-show-signature',
126
+ '--format=',
127
+ '-p',
128
+ ...PATCH_FLAGS,
129
+ `${from}..${pushed}`,
130
+ ],
131
+ env: { GIT_GRAFT_FILE: devNull },
132
+ };
133
+ }
134
+ export function uniqueHits(hits) {
135
+ const seen = new Set();
136
+ return hits.filter((h) => {
137
+ const key = `${h.path}\u0000${h.kind}\u0000${h.line}`;
138
+ if (seen.has(key))
139
+ return false;
140
+ seen.add(key);
141
+ return true;
142
+ });
143
+ }
144
+ export function hardFirst(hits) {
145
+ return [...hits.filter(refusesPush), ...hits.filter((h) => !refusesPush(h))];
146
+ }
147
+ export function secretRefusal(hits, branch) {
148
+ const shown = hits
149
+ .slice(0, 5)
150
+ .map((h) => `${h.kind} at ${h.path}:${h.line}`)
151
+ .join(', ');
152
+ const more = hits.length > 5 ? ` and ${hits.length - 5} more` : '';
153
+ const where = branch ? `on the local branch ${branch} of the checkout` : 'in the checkout';
154
+ return (`Refusing to push: the change adds what looks like a secret — ${shown}${more}. ` +
155
+ `Nothing was pushed: the commit stays ${where} on the machine. ` +
156
+ 'If the value is a real credential, rotate it and tell the agent where the code should read it from ' +
157
+ '(an environment variable or your secret store); if it is a placeholder, ask for one that does not look ' +
158
+ 'like a live key. Then run the task again. A value a later commit took out still counts: the push ' +
159
+ 'would publish the commit that added it (git log -p shows which).');
160
+ }
161
+ //# sourceMappingURL=secret-scan.js.map
@@ -5,8 +5,16 @@ export type SessionEvent = {
5
5
  kind: 'tool';
6
6
  name: string;
7
7
  arg?: string;
8
+ path?: string;
9
+ id?: string;
8
10
  } | {
9
11
  kind: 'result';
10
12
  text: string;
13
+ } | {
14
+ kind: 'tool_result';
15
+ id: string;
16
+ isError: boolean;
11
17
  };
12
- export declare function makeStreamJsonParser(onEvent: (ev: SessionEvent) => void): (chunk: string) => void;
18
+ export declare function makeStreamJsonParser(onEvent: (ev: SessionEvent) => void, opts?: {
19
+ toolResults?: boolean;
20
+ }): (chunk: string) => void;
@@ -1,4 +1,4 @@
1
- export function makeStreamJsonParser(onEvent) {
1
+ export function makeStreamJsonParser(onEvent, opts = {}) {
2
2
  let buf = '';
3
3
  return (chunk) => {
4
4
  buf += chunk;
@@ -24,12 +24,30 @@ export function makeStreamJsonParser(onEvent) {
24
24
  else if (c.type === 'tool_use' && c.name) {
25
25
  const inp = c.input ?? {};
26
26
  const arg = (inp.file_path ??
27
+ inp.notebook_path ??
27
28
  inp.command ??
28
29
  inp.pattern ??
29
30
  inp.path ??
30
31
  inp.url ??
32
+ inp.skill ??
33
+ inp.query ??
34
+ inp.description ??
31
35
  '');
32
- onEvent(arg ? { kind: 'tool', name: c.name, arg } : { kind: 'tool', name: c.name });
36
+ const path = typeof inp.path === 'string' && inp.path !== arg ? inp.path : '';
37
+ onEvent({
38
+ kind: 'tool',
39
+ name: c.name,
40
+ ...(arg ? { arg } : {}),
41
+ ...(path ? { path } : {}),
42
+ ...(opts.toolResults && typeof c.id === 'string' ? { id: c.id } : {}),
43
+ });
44
+ }
45
+ }
46
+ }
47
+ else if (opts.toolResults && ev.type === 'user' && Array.isArray(ev.message?.content)) {
48
+ for (const c of ev.message.content) {
49
+ if (c?.type === 'tool_result' && typeof c.tool_use_id === 'string') {
50
+ onEvent({ kind: 'tool_result', id: c.tool_use_id, isError: c.is_error === true });
33
51
  }
34
52
  }
35
53
  }
@@ -0,0 +1,11 @@
1
+ export interface SkillToWrite {
2
+ slug: string;
3
+ content: string;
4
+ }
5
+ export interface WrittenSkills {
6
+ written: string[];
7
+ pathspecs: string[];
8
+ ignoreCase?: boolean;
9
+ }
10
+ export declare function writtenSkillPaths(staged: readonly string[], w: WrittenSkills): string[];
11
+ export declare function writeSkills(worktree: string, skills: readonly SkillToWrite[] | null | undefined, log: (m: string) => void): WrittenSkills;
package/dist/skills.js ADDED
@@ -0,0 +1,164 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { existsSync, lstatSync, mkdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
3
+ import { isAbsolute, join, relative, sep } from 'node:path';
4
+ const NONE = { written: [], pathspecs: [] };
5
+ const SKILL_GITIGNORE = '# FireFunc: a skill written for one run, never committed\n*\n';
6
+ export function writtenSkillPaths(staged, w) {
7
+ const fold = (p) => (w.ignoreCase ? p.toLowerCase() : p);
8
+ const mine = w.written.map(fold);
9
+ return staged.filter((l) => {
10
+ const f = fold(l);
11
+ return mine.some((p) => f === p || f.startsWith(`${p}/`));
12
+ });
13
+ }
14
+ function git(cwd, args) {
15
+ try {
16
+ return execFileSync('git', ['-C', cwd, ...args], {
17
+ encoding: 'utf8',
18
+ stdio: ['ignore', 'pipe', 'ignore'],
19
+ }).trim();
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ }
25
+ function insideTop(top, real) {
26
+ const rel = relative(top, real);
27
+ if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel))
28
+ return null;
29
+ return rel.split(sep).join('/');
30
+ }
31
+ export function writeSkills(worktree, skills, log) {
32
+ const seen = new Set();
33
+ const wanted = [];
34
+ for (const s of skills ?? []) {
35
+ if (!s || typeof s.slug !== 'string' || typeof s.content !== 'string')
36
+ continue;
37
+ const slug = s.slug.replace(/[^a-z0-9-]/gi, '-').toLowerCase();
38
+ if (!slug || seen.has(slug))
39
+ continue;
40
+ seen.add(slug);
41
+ wanted.push({ slug, content: s.content });
42
+ }
43
+ if (wanted.length === 0)
44
+ return NONE;
45
+ let top;
46
+ try {
47
+ top = realpathSync(worktree);
48
+ }
49
+ catch (e) {
50
+ log(`could not write skills: ${e.message}`);
51
+ return NONE;
52
+ }
53
+ let dir = top;
54
+ for (const part of ['.claude', 'skills']) {
55
+ const next = join(dir, part);
56
+ const shown = relative(top, next).split(sep).join('/') || part;
57
+ if (!lstatExists(next)) {
58
+ try {
59
+ mkdirSync(next);
60
+ }
61
+ catch (e) {
62
+ log(`could not write skills: ${e.message}`);
63
+ return NONE;
64
+ }
65
+ }
66
+ else if (!existsSync(next)) {
67
+ log(`skills not written: ${shown} is a link to a place that does not exist in this checkout. ` +
68
+ `Fix: point it at a folder inside the repository, or remove the link.`);
69
+ return NONE;
70
+ }
71
+ let real;
72
+ try {
73
+ real = realpathSync(next);
74
+ }
75
+ catch (e) {
76
+ log(`could not write skills: ${e.message}`);
77
+ return NONE;
78
+ }
79
+ if (insideTop(top, real) === null) {
80
+ log(`skills not written: ${shown} leads to ${real}, which is not a folder inside this checkout; ` +
81
+ `FireFunc writes only inside the worktree. ` +
82
+ `Fix: point ${shown} at a folder inside the repository.`);
83
+ return NONE;
84
+ }
85
+ if (!statSync(real).isDirectory()) {
86
+ log(`skills not written: ${shown} is a file, not a folder. ` +
87
+ `Fix: make ${shown} a folder (or a link to one inside the repository).`);
88
+ return NONE;
89
+ }
90
+ dir = real;
91
+ }
92
+ const skillsRel = insideTop(top, dir);
93
+ const gitTop = git(top, ['rev-parse', '--show-toplevel']);
94
+ let isRepo = false;
95
+ if (gitTop) {
96
+ try {
97
+ isRepo = realpathSync(gitTop) === top;
98
+ }
99
+ catch {
100
+ isRepo = false;
101
+ }
102
+ }
103
+ const ignoreCase = isRepo && git(top, ['config', '--bool', 'core.ignorecase']) === 'true';
104
+ const fold = (x) => (ignoreCase ? x.toLowerCase() : x);
105
+ const tracked = isRepo
106
+ ? (git(top, ['ls-files', '-z', '--', `:(literal${ignoreCase ? ',icase' : ''})${skillsRel}`]) ??
107
+ '')
108
+ .split('\0')
109
+ .filter(Boolean)
110
+ .map(fold)
111
+ : [];
112
+ const written = [];
113
+ for (const s of wanted) {
114
+ const p = `${skillsRel}/${s.slug}`;
115
+ const folded = fold(p);
116
+ if (tracked.some((t) => t === folded || t.startsWith(`${folded}/`))) {
117
+ log(`skill ${s.slug} not written: the repository tracks its own ${p}, and FireFunc never ` +
118
+ `overwrites a repository's files — this run sees the repository's version. ` +
119
+ `Fix: rename one of the two skills.`);
120
+ continue;
121
+ }
122
+ const slugDir = join(dir, s.slug);
123
+ try {
124
+ if (lstatExists(slugDir)) {
125
+ log(`skill ${s.slug} not written: ${p} is already in the checkout (possibly under another ` +
126
+ `case), and FireFunc never writes into the repository's own files — this run sees ` +
127
+ `what is there. Fix: rename the skill, or remove ${p} from the repository.`);
128
+ continue;
129
+ }
130
+ mkdirSync(slugDir);
131
+ writeFileSync(join(slugDir, 'SKILL.md'), s.content);
132
+ written.push(p);
133
+ try {
134
+ writeFileSync(join(slugDir, '.gitignore'), SKILL_GITIGNORE);
135
+ }
136
+ catch (e) {
137
+ log(`could not keep skill ${s.slug} out of git status: ${e.message}`);
138
+ }
139
+ }
140
+ catch (e) {
141
+ log(`could not write skill ${s.slug}: ${e.message}`);
142
+ }
143
+ }
144
+ if (written.length === 0)
145
+ return NONE;
146
+ const where = skillsRel === '.claude/skills' ? '.claude/skills' : `.claude/skills (${skillsRel})`;
147
+ log(`wrote ${written.length} skill(s) into ${where}: ` +
148
+ written.map((p) => p.slice(skillsRel.length + 1)).join(', '));
149
+ return {
150
+ written,
151
+ pathspecs: written.map((p) => `:(exclude,literal${ignoreCase ? ',icase' : ''})${p}`),
152
+ ...(ignoreCase ? { ignoreCase } : {}),
153
+ };
154
+ }
155
+ function lstatExists(p) {
156
+ try {
157
+ lstatSync(p);
158
+ return true;
159
+ }
160
+ catch {
161
+ return false;
162
+ }
163
+ }
164
+ //# sourceMappingURL=skills.js.map
@@ -0,0 +1,3 @@
1
+ export type EndingSignal = 'SIGTERM' | 'SIGKILL';
2
+ export declare function endedBySignal(code: number): EndingSignal | null;
3
+ export declare function stoppedSentence(engineName: string, code: number, signal: EndingSignal, sessionLog: string | null): string;
@@ -0,0 +1,10 @@
1
+ export function endedBySignal(code) {
2
+ return code === 143 ? 'SIGTERM' : code === 137 ? 'SIGKILL' : null;
3
+ }
4
+ export function stoppedSentence(engineName, code, signal, sessionLog) {
5
+ return (`${engineName} was ended by a signal (${signal}, exit ${code}) before it finished — by a person, ` +
6
+ 'the operating system or a time limit on the machine, not by the agent. The runner pushed ' +
7
+ `nothing and opened no pull request. Its output stayed on the machine${sessionLog ? ` — the session log is logs/${sessionLog} in the runner’s folder` : ''}. ` +
8
+ 'Re-run the task to start a new attempt.');
9
+ }
10
+ //# sourceMappingURL=stopped.js.map
@@ -0,0 +1,49 @@
1
+ export type ModelUsage = {
2
+ input_tokens: number;
3
+ output_tokens: number;
4
+ cache_creation_input_tokens?: number;
5
+ cache_read_input_tokens?: number;
6
+ thinking_tokens?: number;
7
+ cost_usd?: number;
8
+ };
9
+ export type UsageLimits = {
10
+ five_hour_pct_before?: number;
11
+ five_hour_pct_after?: number;
12
+ weekly_pct_before?: number;
13
+ weekly_pct_after?: number;
14
+ source: 'rate_limit_event';
15
+ };
16
+ export type RunUsage = {
17
+ input_tokens: number;
18
+ output_tokens: number;
19
+ cache_creation_input_tokens?: number;
20
+ cache_read_input_tokens?: number;
21
+ thinking_tokens?: number;
22
+ total_cost_usd?: number;
23
+ num_turns?: number;
24
+ duration_ms?: number;
25
+ duration_api_ms?: number;
26
+ models?: Record<string, ModelUsage>;
27
+ cost_basis?: 'list' | 'managed';
28
+ auth?: 'subscription' | 'api_key';
29
+ overage?: boolean;
30
+ engine_version?: string;
31
+ sessions?: number;
32
+ incomplete?: boolean;
33
+ limits?: UsageLimits;
34
+ };
35
+ export declare function readClaudeUsage(stdout: string): RunUsage | null;
36
+ export declare function combineUsage(sessions: Array<RunUsage | null>): RunUsage | null;
37
+ export declare function carriesEarlierSpend(u: RunUsage): boolean;
38
+ export declare function continueUsage(prev: RunUsage | null, next: RunUsage | null): RunUsage | null;
39
+ export declare function usageSince(next: RunUsage | null, baseline: RunUsage | undefined): RunUsage | null;
40
+ export type AttemptSession = {
41
+ usage: RunUsage | null;
42
+ session: string | null;
43
+ continued: boolean;
44
+ };
45
+ export declare function attemptUsage(sessions: AttemptSession[], cut?: {
46
+ session: string;
47
+ baseline?: RunUsage;
48
+ }): RunUsage | null;
49
+ export declare function describeUsage(u: RunUsage): string;