@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,14 @@
1
+ export class Refusal extends Error {
2
+ fix;
3
+ code;
4
+ constructor(message, fix, code) {
5
+ super(message);
6
+ this.fix = fix;
7
+ this.code = code;
8
+ this.name = 'Refusal';
9
+ }
10
+ }
11
+ const SECRET_SHAPE = /(?<![A-Za-z0-9])ff[a-z0-9]{0,4}_[A-Za-z0-9_-]{8,}/g;
12
+ export const looksLikeSecret = (s) => new RegExp(`^${SECRET_SHAPE.source}`).test(s);
13
+ export const hideSecrets = (s) => s.replace(SECRET_SHAPE, '[a key, not shown]');
14
+ //# sourceMappingURL=io.js.map
@@ -0,0 +1,4 @@
1
+ import type { Command } from './command.js';
2
+ import { type Io } from './io.js';
3
+ export declare const COMMANDS: Command[];
4
+ export declare function runFirefunc(argv: readonly string[], io: Io): Promise<number>;
@@ -0,0 +1,221 @@
1
+ import { GLOBAL_FLAGS, parseArgs, str, UsageError } from './args.js';
2
+ import { agentCommands } from './agents.js';
3
+ import { authCommands } from './auth.js';
4
+ import { catalogCommands } from './catalog.js';
5
+ import { ApiClient } from './client.js';
6
+ import { DEFAULT_API_URL, resolveCredentials } from './config.js';
7
+ import { hideSecrets, looksLikeSecret } from './io.js';
8
+ import { printError } from './output.js';
9
+ import { PromptCancelled } from './prompt.js';
10
+ import { skillCommands } from './skill.js';
11
+ import { taskCommands } from './tasks.js';
12
+ import { CLI_VERSION } from './version.js';
13
+ export const COMMANDS = [
14
+ ...authCommands,
15
+ ...catalogCommands,
16
+ ...agentCommands,
17
+ ...taskCommands,
18
+ ...skillCommands,
19
+ ];
20
+ const GROUPS = ['templates', 'projects', 'connections', 'skills', 'agents', 'tasks', 'skill'];
21
+ const SECTIONS = [
22
+ ['Sign in', ['login', 'logout', 'whoami']],
23
+ [
24
+ 'Look before you create',
25
+ ['templates list', 'projects list', 'connections list', 'skills list'],
26
+ ],
27
+ [
28
+ 'Agents',
29
+ [
30
+ 'agents list',
31
+ 'agents get',
32
+ 'agents create',
33
+ 'agents update',
34
+ 'agents activate',
35
+ 'agents pause',
36
+ 'agents resume',
37
+ ],
38
+ ],
39
+ ['Tasks', ['run', 'tasks list', 'tasks get', 'tasks watch', 'tasks states']],
40
+ ['Claude Code', ['skill install', 'skill show']],
41
+ ];
42
+ const COMMON_OPTIONS = [
43
+ ['--json', "print the API's answer as JSON (refusals as JSON on stderr)"],
44
+ [
45
+ '--api-url <url>',
46
+ `the API (default ${DEFAULT_API_URL}; env FIREFUNC_API_URL); a saved key goes only to the address it was saved with`,
47
+ ],
48
+ ['-h, --help', 'this help'],
49
+ ];
50
+ const byPath = (words) => COMMANDS.find((c) => c.path.join(' ') === words);
51
+ function topHelp() {
52
+ const w = Math.max(...COMMANDS.map((c) => c.path.join(' ').length)) + 2;
53
+ const out = [
54
+ `firefunc ${CLI_VERSION} — set up and run FireFunc agents from a terminal, a script or Claude Code.`,
55
+ '',
56
+ 'Usage: firefunc <command> [options] firefunc <command> --help for its options',
57
+ '',
58
+ ];
59
+ for (const [title, paths] of SECTIONS) {
60
+ out.push(`${title}:`);
61
+ for (const p of paths)
62
+ out.push(` ${p.padEnd(w)}${byPath(p)?.summary ?? ''}`);
63
+ out.push('');
64
+ }
65
+ out.push('Agents are created as DRAFTS: each comes back with a link that opens it in the composer,', 'and a person activates it there. A key granted agents:activate may activate one here.', '', 'Every command takes --json for scripts and agents. Exit codes: 0 done; 1 refused or', 'failed (the reason and the fix on stderr); 2 the command line was wrong.', '', 'Environment:', ' FIREFUNC_API_KEY a workspace key to use instead of the one "login" saved', ` FIREFUNC_API_URL the API address (default ${DEFAULT_API_URL})`, ' FIREFUNC_CONFIG_DIR where "login" keeps the key (default ~/.firefunc)', '', 'Start: make a key in FireFunc → Settings → API keys, then: firefunc login', '');
66
+ return out.join('\n');
67
+ }
68
+ function groupHelp(group) {
69
+ const cmds = COMMANDS.filter((c) => c.path[0] === group);
70
+ const w = Math.max(...cmds.map((c) => c.path.join(' ').length)) + 2;
71
+ return [
72
+ `Usage: firefunc ${group} <command> [options]`,
73
+ '',
74
+ ...cmds.map((c) => ` ${c.path.join(' ').padEnd(w)}${c.summary}`),
75
+ '',
76
+ `firefunc ${group} <command> --help for its options.`,
77
+ '',
78
+ ].join('\n');
79
+ }
80
+ function commandHelp(c) {
81
+ const opts = [...(c.flagHelp ?? []), ...COMMON_OPTIONS];
82
+ const w = Math.max(...opts.map(([f]) => f.length)) + 2;
83
+ return [
84
+ `Usage: firefunc ${c.usage}`,
85
+ '',
86
+ c.summary + '.',
87
+ ...(c.details ? ['', c.details] : []),
88
+ '',
89
+ 'Options:',
90
+ ...opts.map(([f, d]) => ` ${f.padEnd(w)}${d}`),
91
+ '',
92
+ ].join('\n');
93
+ }
94
+ function commandWords(argv) {
95
+ const words = [];
96
+ for (let i = 0; i < argv.length; i++) {
97
+ const a = argv[i];
98
+ if (a === '--')
99
+ break;
100
+ if (a.startsWith('-')) {
101
+ const name = a.replace(/^--?/, '').split('=')[0];
102
+ const global = name === 'h' || name in GLOBAL_FLAGS;
103
+ if (words.length && !global)
104
+ break;
105
+ if (!a.includes('=') && GLOBAL_FLAGS[name] === 'string')
106
+ i++;
107
+ continue;
108
+ }
109
+ words.push({ word: a, index: i });
110
+ if (words.length === 2)
111
+ break;
112
+ }
113
+ return words;
114
+ }
115
+ const shown = (args) => args
116
+ .filter((a) => a !== undefined)
117
+ .map(hideSecrets)
118
+ .join(' ');
119
+ export async function runFirefunc(argv, io) {
120
+ const json = argv.includes('--json');
121
+ try {
122
+ const words = commandWords(argv);
123
+ const wantsHelp = argv.includes('--help') || argv.includes('-h');
124
+ if (!words.length) {
125
+ if (argv.includes('--version') || argv.includes('-v')) {
126
+ io.stdout.write(`${CLI_VERSION}\n`);
127
+ return 0;
128
+ }
129
+ if (!argv.length || wantsHelp) {
130
+ io.stdout.write(topHelp());
131
+ return 0;
132
+ }
133
+ throw new UsageError(`Say which command: ${shown(argv)} is not one.`);
134
+ }
135
+ if (words[0].word === 'help') {
136
+ const rest = argv.filter((a) => !a.startsWith('-')).slice(1);
137
+ const c = byPath(rest.slice(0, 2).join(' ')) ?? byPath(rest[0] ?? '');
138
+ if (c)
139
+ io.stdout.write(commandHelp(c));
140
+ else if (rest[0] && GROUPS.includes(rest[0]))
141
+ io.stdout.write(groupHelp(rest[0]));
142
+ else if (!rest.length)
143
+ io.stdout.write(topHelp());
144
+ else
145
+ throw new UsageError(`No command "${shown(rest)}".`);
146
+ return 0;
147
+ }
148
+ const [first, second] = words;
149
+ let command = second ? byPath(`${first.word} ${second.word}`) : undefined;
150
+ let used = command ? [first.index, second.index] : [];
151
+ if (!command) {
152
+ command = byPath(first.word);
153
+ used = command ? [first.index] : [];
154
+ }
155
+ if (!command && GROUPS.includes(first.word)) {
156
+ const sub = second?.word;
157
+ const list = byPath(`${first.word} list`);
158
+ if (sub === undefined && wantsHelp) {
159
+ io.stdout.write(groupHelp(first.word));
160
+ return 0;
161
+ }
162
+ if (sub === undefined && list) {
163
+ command = list;
164
+ used = [first.index];
165
+ }
166
+ else {
167
+ throw new UsageError(sub === undefined
168
+ ? `Say what to do with "${first.word}".`
169
+ : `Unknown command "${shown([first.word, sub])}".`, `firefunc ${first.word}`);
170
+ }
171
+ }
172
+ if (!command)
173
+ throw new UsageError(`Unknown command "${shown([first.word])}".`);
174
+ const name = `firefunc ${command.path.join(' ')}`;
175
+ const rest = argv.filter((_, i) => !used.includes(i));
176
+ const args = parseArgs(rest, command.flags ?? {}, name);
177
+ if (args.flags.help) {
178
+ io.stdout.write(commandHelp(command));
179
+ return 0;
180
+ }
181
+ const pos = command.positional ?? { min: 0, max: 0 };
182
+ if (args.positional.length < pos.min) {
183
+ throw new UsageError(`Missing an argument. Usage: firefunc ${command.usage.split('\n')[0]}`, name);
184
+ }
185
+ if (args.positional.length > pos.max) {
186
+ throw new UsageError(`Unexpected argument${args.positional.length - pos.max > 1 ? 's' : ''}: ${shown(args.positional.slice(pos.max))}.` +
187
+ (args.positional.some(looksLikeSecret)
188
+ ? ' A key is never taken as an argument: run "firefunc login" and paste it at the prompt.'
189
+ : ''), name);
190
+ }
191
+ let creds;
192
+ let client;
193
+ const ctx = {
194
+ io,
195
+ args,
196
+ json: args.flags.json === true,
197
+ command: name,
198
+ credentials() {
199
+ creds ??= resolveCredentials(str(args, 'api-url'), io);
200
+ return creds;
201
+ },
202
+ api() {
203
+ if (!client) {
204
+ const c = ctx.credentials();
205
+ client = new ApiClient(c.apiUrl, c.key, io.fetch);
206
+ }
207
+ return client;
208
+ },
209
+ };
210
+ const code = await command.run(ctx);
211
+ return typeof code === 'number' ? code : 0;
212
+ }
213
+ catch (err) {
214
+ if (err instanceof PromptCancelled) {
215
+ io.stderr.write('Cancelled; nothing was saved.\n');
216
+ return 1;
217
+ }
218
+ return printError(io, err, json);
219
+ }
220
+ }
221
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,29 @@
1
+ import { type Io } from './io.js';
2
+ export declare function quietWhenReaderLeaves(stdout: NodeJS.EventEmitter, stderr: NodeJS.EventEmitter, exit: (code: number) => void): void;
3
+ export declare function printJson(io: Io, value: unknown): void;
4
+ export declare const dash = "\u2014";
5
+ export declare function text(v: unknown): string;
6
+ export type Column<T> = {
7
+ head: string;
8
+ get: (row: T) => unknown;
9
+ max?: number;
10
+ };
11
+ export declare function table<T>(io: Io, rows: readonly T[], columns: Column<T>[]): void;
12
+ export declare function describe(io: Io, record: Record<string, unknown>, opts?: {
13
+ skip?: string[];
14
+ }): void;
15
+ export type ErrorReport = {
16
+ status?: number;
17
+ code: string;
18
+ message: string;
19
+ fix?: string;
20
+ requestId?: string;
21
+ issues?: string[];
22
+ details?: Record<string, unknown>;
23
+ };
24
+ export declare function reportOf(err: unknown): {
25
+ report: ErrorReport;
26
+ exit: number;
27
+ fixIsListed?: boolean;
28
+ };
29
+ export declare function printError(io: Io, err: unknown, json: boolean): number;
@@ -0,0 +1,128 @@
1
+ import { ApiRefusal, ApiUnreachable } from './client.js';
2
+ import { UsageError } from './args.js';
3
+ import { Refusal } from './io.js';
4
+ export function quietWhenReaderLeaves(stdout, stderr, exit) {
5
+ const epipe = (err) => err?.code === 'EPIPE';
6
+ stdout.on('error', (err) => {
7
+ if (!epipe(err))
8
+ throw err;
9
+ exit(0);
10
+ });
11
+ stderr.on('error', (err) => {
12
+ if (!epipe(err))
13
+ throw err;
14
+ });
15
+ }
16
+ export function printJson(io, value) {
17
+ io.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
18
+ }
19
+ export const dash = '—';
20
+ export function text(v) {
21
+ if (v === null || v === undefined || v === '')
22
+ return dash;
23
+ if (typeof v === 'string')
24
+ return v;
25
+ if (typeof v === 'number' || typeof v === 'boolean')
26
+ return String(v);
27
+ if (Array.isArray(v))
28
+ return v.length ? v.map(text).join(', ') : dash;
29
+ return JSON.stringify(v);
30
+ }
31
+ function clip(s, max) {
32
+ const one = s.replace(/\s+/g, ' ').trim();
33
+ return one.length > max ? `${one.slice(0, max - 1)}…` : one;
34
+ }
35
+ export function table(io, rows, columns) {
36
+ const cells = rows.map((r) => columns.map((c) => clip(text(c.get(r)), c.max ?? 60)));
37
+ const widths = columns.map((c, i) => Math.max(c.head.length, ...cells.map((row) => row[i].length)));
38
+ const line = (vals) => vals
39
+ .map((v, i) => (i === vals.length - 1 ? v : v.padEnd(widths[i])))
40
+ .join(' ')
41
+ .trimEnd();
42
+ io.stdout.write(`${line(columns.map((c) => c.head))}\n`);
43
+ for (const row of cells)
44
+ io.stdout.write(`${line(row)}\n`);
45
+ }
46
+ export function describe(io, record, opts = {}) {
47
+ const entries = Object.entries(record).filter(([k]) => !opts.skip?.includes(k));
48
+ const flat = entries.filter(([, v]) => v === null || typeof v !== 'object');
49
+ const nested = entries.filter(([, v]) => v !== null && typeof v === 'object');
50
+ const w = Math.max(0, ...flat.map(([k]) => k.length)) + 1;
51
+ for (const [k, v] of flat)
52
+ io.stdout.write(`${`${k}:`.padEnd(w)} ${text(v)}\n`);
53
+ for (const [k, v] of nested) {
54
+ const empty = Array.isArray(v) ? v.length === 0 : Object.keys(v).length === 0;
55
+ if (empty) {
56
+ io.stdout.write(`${k}: ${Array.isArray(v) ? '[]' : '{}'}\n`);
57
+ continue;
58
+ }
59
+ const body = JSON.stringify(v, null, 2)
60
+ .split('\n')
61
+ .map((l) => ` ${l}`)
62
+ .join('\n');
63
+ io.stdout.write(`${k}:\n${body}\n`);
64
+ }
65
+ }
66
+ export function reportOf(err) {
67
+ if (err instanceof UsageError) {
68
+ return {
69
+ report: {
70
+ code: 'usage',
71
+ message: err.message,
72
+ fix: `Run "${err.helpFor ?? 'firefunc'} --help" for how to call it.`,
73
+ },
74
+ exit: 2,
75
+ };
76
+ }
77
+ if (err instanceof ApiRefusal) {
78
+ return {
79
+ report: {
80
+ status: err.status,
81
+ code: err.code,
82
+ message: err.message,
83
+ ...(err.fix ? { fix: err.fix } : {}),
84
+ ...(err.requestId ? { requestId: err.requestId } : {}),
85
+ ...(err.issues.length ? { issues: err.issues } : {}),
86
+ ...(err.details ? { details: err.details } : {}),
87
+ },
88
+ exit: 1,
89
+ fixIsListed: err.fixIsListed,
90
+ };
91
+ }
92
+ if (err instanceof ApiUnreachable) {
93
+ return {
94
+ report: {
95
+ code: 'unreachable',
96
+ message: err.message,
97
+ fix: 'Check your connection and the address (--api-url, FIREFUNC_API_URL). A create or a run whose answer was lost may still have happened: list before trying again.',
98
+ },
99
+ exit: 1,
100
+ };
101
+ }
102
+ if (err instanceof Refusal) {
103
+ return {
104
+ report: { code: err.code, message: err.message, ...(err.fix ? { fix: err.fix } : {}) },
105
+ exit: 1,
106
+ };
107
+ }
108
+ const message = err instanceof Error ? err.message : String(err);
109
+ return { report: { code: 'failed', message }, exit: 1 };
110
+ }
111
+ export function printError(io, err, json) {
112
+ const { report, exit, fixIsListed } = reportOf(err);
113
+ if (json) {
114
+ io.stderr.write(`${JSON.stringify({ error: report })}\n`);
115
+ return exit;
116
+ }
117
+ const status = report.status ? ` (${report.status}${report.code ? ` ${report.code}` : ''})` : '';
118
+ const lines = [`firefunc: ${report.message}${status}`];
119
+ for (const i of report.issues ?? [])
120
+ lines.push(` - ${i}`);
121
+ if (report.fix && !fixIsListed)
122
+ lines.push(` Fix: ${report.fix}`);
123
+ if (report.requestId)
124
+ lines.push(` (request ${report.requestId})`);
125
+ io.stderr.write(`${lines.join('\n')}\n`);
126
+ return exit;
127
+ }
128
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1,14 @@
1
+ export type TtyIn = NodeJS.EventEmitter & {
2
+ isTTY?: boolean;
3
+ setRawMode?(mode: boolean): unknown;
4
+ setEncoding?(enc: BufferEncoding): unknown;
5
+ resume(): unknown;
6
+ pause(): unknown;
7
+ };
8
+ export declare class PromptCancelled extends Error {
9
+ constructor();
10
+ }
11
+ export declare function readHidden(prompt: string, input: TtyIn, output: {
12
+ write(s: string): unknown;
13
+ }): Promise<string>;
14
+ export declare function readAll(input: AsyncIterable<unknown>): Promise<string>;
@@ -0,0 +1,58 @@
1
+ export class PromptCancelled extends Error {
2
+ constructor() {
3
+ super('Cancelled.');
4
+ this.name = 'PromptCancelled';
5
+ }
6
+ }
7
+ export function readHidden(prompt, input, output) {
8
+ output.write(prompt);
9
+ return new Promise((resolve, reject) => {
10
+ let buf = '';
11
+ let inEscape = false;
12
+ const wasRaw = Boolean(input.isRaw);
13
+ input.setRawMode?.(true);
14
+ input.setEncoding?.('utf8');
15
+ input.resume();
16
+ const done = (err) => {
17
+ input.removeListener('data', onData);
18
+ input.setRawMode?.(wasRaw);
19
+ input.pause();
20
+ output.write('\n');
21
+ if (err)
22
+ reject(err);
23
+ else
24
+ resolve(buf.trim());
25
+ };
26
+ const onData = (chunk) => {
27
+ for (const ch of String(chunk)) {
28
+ if (inEscape) {
29
+ if (/[A-Za-z~]/.test(ch))
30
+ inEscape = false;
31
+ continue;
32
+ }
33
+ if (ch === '\r' || ch === '\n' || ch === '\u0004')
34
+ return done();
35
+ if (ch === '\u0003')
36
+ return done(new PromptCancelled());
37
+ if (ch === '\u007f' || ch === '\b') {
38
+ buf = buf.slice(0, -1);
39
+ continue;
40
+ }
41
+ if (ch === '\u001b') {
42
+ inEscape = true;
43
+ continue;
44
+ }
45
+ if (ch >= ' ')
46
+ buf += ch;
47
+ }
48
+ };
49
+ input.on('data', onData);
50
+ });
51
+ }
52
+ export async function readAll(input) {
53
+ let out = '';
54
+ for await (const chunk of input)
55
+ out += typeof chunk === 'string' ? chunk : String(chunk);
56
+ return out;
57
+ }
58
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1,3 @@
1
+ import type { Command } from './command.js';
2
+ export declare function skillSource(): string;
3
+ export declare const skillCommands: Command[];
@@ -0,0 +1,80 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { isAbsolute, join, resolve } from 'node:path';
3
+ import { bool, str } from './args.js';
4
+ import { Refusal } from './io.js';
5
+ import { printJson } from './output.js';
6
+ import { packageRoot } from './version.js';
7
+ export function skillSource() {
8
+ return join(packageRoot(), 'skill', 'firefunc', 'SKILL.md');
9
+ }
10
+ function readSkill() {
11
+ try {
12
+ return readFileSync(skillSource(), 'utf8');
13
+ }
14
+ catch {
15
+ throw new Refusal(`The skill file is missing from this install (${skillSource()}).`, 'Reinstall the package: npm install -g @firefunc-agent/runner', 'skill_missing');
16
+ }
17
+ }
18
+ function expand(io, p) {
19
+ if (p === '~')
20
+ return io.home;
21
+ if (p.startsWith('~/') || p.startsWith('~\\'))
22
+ return join(io.home, p.slice(2));
23
+ return isAbsolute(p) ? p : resolve(io.cwd, p);
24
+ }
25
+ export const skillCommands = [
26
+ {
27
+ path: ['skill', 'install'],
28
+ summary: 'Teach Claude Code to use this CLI (writes the FireFunc SKILL.md)',
29
+ usage: 'skill install [--dir <skills folder>] [--force]',
30
+ details: 'Writes <dir>/firefunc/SKILL.md. The default folder is ~/.claude/skills, where Claude\n' +
31
+ 'Code reads personal skills; for one repository, pass --dir .claude/skills there.\n' +
32
+ 'A SKILL.md that differs from this version (edited, or another version) is not\n' +
33
+ 'replaced without --force.',
34
+ flags: { dir: 'string', force: 'boolean' },
35
+ flagHelp: [
36
+ ['--dir <folder>', 'the skills folder (default ~/.claude/skills)'],
37
+ ['--force', 'replace a different SKILL.md that is already there'],
38
+ ],
39
+ async run(ctx) {
40
+ const { io } = ctx;
41
+ const content = readSkill();
42
+ const dir = expand(io, str(ctx.args, 'dir') ?? '~/.claude/skills');
43
+ const target = join(dir, 'firefunc', 'SKILL.md');
44
+ let outcome = 'installed';
45
+ if (existsSync(target)) {
46
+ const current = readFileSync(target, 'utf8');
47
+ if (current === content)
48
+ outcome = 'unchanged';
49
+ else if (!bool(ctx.args, 'force')) {
50
+ throw new Refusal(`${target} already exists and differs from this version's skill.`, `Look at it first; to replace it: firefunc skill install${str(ctx.args, 'dir') ? ` --dir ${str(ctx.args, 'dir')}` : ''} --force`, 'skill_exists');
51
+ }
52
+ else
53
+ outcome = 'updated';
54
+ }
55
+ if (outcome !== 'unchanged') {
56
+ mkdirSync(join(dir, 'firefunc'), { recursive: true });
57
+ writeFileSync(target, content);
58
+ }
59
+ if (ctx.json)
60
+ return printJson(io, { path: target, outcome });
61
+ io.stdout.write(outcome === 'unchanged'
62
+ ? `The FireFunc skill at ${target} is already this version.\n`
63
+ : `${outcome === 'updated' ? 'Updated' : 'Installed'} the FireFunc skill at ${target}.\n` +
64
+ 'Claude Code finds it there (a session already open may need restarting).\n' +
65
+ 'Sign in first if you have not: firefunc login\n');
66
+ },
67
+ },
68
+ {
69
+ path: ['skill', 'show'],
70
+ summary: 'Print the skill (what Claude Code is told)',
71
+ usage: 'skill show',
72
+ async run(ctx) {
73
+ const content = readSkill();
74
+ if (ctx.json)
75
+ return printJson(ctx.io, { path: skillSource(), content });
76
+ ctx.io.stdout.write(content);
77
+ },
78
+ },
79
+ ];
80
+ //# sourceMappingURL=skill.js.map
@@ -0,0 +1,2 @@
1
+ import { type Command } from './command.js';
2
+ export declare const taskCommands: Command[];