@firefunc-agent/runner 0.7.0 → 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.
- package/LICENSE +7 -3
- package/README.md +233 -3
- package/dist/activity.d.ts +29 -0
- package/dist/activity.js +209 -0
- package/dist/api.d.ts +45 -1
- package/dist/api.js +44 -2
- package/dist/brief.d.ts +6 -0
- package/dist/brief.js +257 -0
- package/dist/build-info.json +4 -0
- package/dist/cli.js +49 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +3 -0
- package/dist/daemon.js +70 -2
- 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 +10 -1
- 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 +2 -1
- package/dist/firefunc/agents.d.ts +2 -0
- package/dist/firefunc/agents.js +291 -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 +35 -0
- package/dist/firefunc/client.js +174 -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/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 +221 -0
- package/dist/firefunc/output.d.ts +29 -0
- package/dist/firefunc/output.js +128 -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 +23 -0
- package/dist/git-auth.d.ts +4 -1
- package/dist/git-auth.js +6 -2
- package/dist/job.js +476 -83
- package/dist/keep-local.d.ts +7 -0
- package/dist/keep-local.js +484 -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.d.ts +60 -0
- package/dist/mcp.js +582 -0
- package/dist/network.d.ts +20 -0
- package/dist/network.js +76 -0
- package/dist/pending.d.ts +14 -0
- package/dist/pending.js +56 -0
- package/dist/secret-scan.d.ts +19 -0
- package/dist/secret-scan.js +161 -0
- package/dist/session-stream.d.ts +1 -0
- package/dist/session-stream.js +11 -1
- package/dist/viewer.js +11 -1
- package/package.json +7 -4
- package/skill/firefunc/SKILL.md +173 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { str, UsageError } from './args.js';
|
|
2
|
+
import { pick, listIn, resolveProject, resolveProjectId } from './catalog.js';
|
|
3
|
+
import { enc, readInputFile, readSpec } from './command.js';
|
|
4
|
+
import { Refusal } from './io.js';
|
|
5
|
+
import { describe, printJson, table, text } from './output.js';
|
|
6
|
+
const agentLine = (a) => `${text(pick('name')(a))}${(a.handle ?? a.mentionHandle) ? ` (@${String(a.handle ?? a.mentionHandle)})` : ''}`;
|
|
7
|
+
function composerOf(body) {
|
|
8
|
+
const u = body.composerUrl ?? body.agent?.composerUrl;
|
|
9
|
+
return typeof u === 'string' ? u : undefined;
|
|
10
|
+
}
|
|
11
|
+
const SPEC_FIELDS = "The spec is the composer's own agent body, as JSON (firefunc connections list --json\n" +
|
|
12
|
+
'shows the values each tool takes):\n' +
|
|
13
|
+
' projectId the project; --project sets it by id or name. Left out: the\n' +
|
|
14
|
+
" workspace's default project. It cannot change after create.\n" +
|
|
15
|
+
' templateSlug start from a template (firefunc templates list); --template sets it,\n' +
|
|
16
|
+
' and every other field overrides the template\n' +
|
|
17
|
+
' name, workType, trigger\n' +
|
|
18
|
+
' required unless a template gives them. workType: bug | feature |\n' +
|
|
19
|
+
' task | chore | story | refactor\n' +
|
|
20
|
+
' trigger { source, event, filters, query, after } — what wakes it. source is\n' +
|
|
21
|
+
' a tool\'s "source" (connections list), or manual (by hand, a schedule\n' +
|
|
22
|
+
' or a join), webhook, or "*" for any tool; event is one it sends\n' +
|
|
23
|
+
' instruction what it does each run (up to 4000 characters; activation needs one)\n' +
|
|
24
|
+
' mentionHandle the @handle it answers to (2-32 lower-case letters, digits, hyphens)\n' +
|
|
25
|
+
' worksIn { repo: "owner/repo", base } — a repository the project lists — or\n' +
|
|
26
|
+
' { repo: null } for an agent that works through its tools, no PR\n' +
|
|
27
|
+
' delivers "pull_request" (the default) | "review"\n' +
|
|
28
|
+
' tool_grants { <tool or MCP server slug>: { read, write } } — only tools the\n' +
|
|
29
|
+
" project has bound. Left out: the template's, or GitHub read+write\n" +
|
|
30
|
+
' deliverables [{ id, action: "tool.action", params, gate, position }]\n' +
|
|
31
|
+
' guardrails left out: Preview (dry_run_mode true, auto_merge false)\n' +
|
|
32
|
+
' caps { runs_per_day, max_in_flight } — left out: { runs_per_day: 5 }\n' +
|
|
33
|
+
' description, schedule, skills (installed slugs), engine, engine_firmness\n' +
|
|
34
|
+
"The API checks it the way the composer's Save does and refuses what it would refuse,\n" +
|
|
35
|
+
'with the reason and the fix; a default it had to leave out comes back in "warnings".\n' +
|
|
36
|
+
'"status" is not part of a spec: an agent is created as a draft, and activating it is\n' +
|
|
37
|
+
'its own step.';
|
|
38
|
+
function refuseStatus(spec) {
|
|
39
|
+
if ('status' in spec) {
|
|
40
|
+
throw new Refusal('A spec cannot set "status": agents are made and edited as drafts, and switching one on is its own step.', 'Remove "status" from the spec. A person activates the draft in the composer, or run "firefunc agents activate <agent>" with a key granted agents:activate (pause/resume likewise).', 'status_not_settable');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function specFromFlags(ctx, forCreate) {
|
|
44
|
+
const specPath = str(ctx.args, 'spec');
|
|
45
|
+
const spec = specPath ? await readSpec(ctx.io, specPath) : {};
|
|
46
|
+
refuseStatus(spec);
|
|
47
|
+
const instruction = str(ctx.args, 'instruction');
|
|
48
|
+
const instructionFile = str(ctx.args, 'instruction-file');
|
|
49
|
+
if (instruction !== undefined && instructionFile !== undefined) {
|
|
50
|
+
throw new UsageError('Pass --instruction or --instruction-file, not both.', ctx.command);
|
|
51
|
+
}
|
|
52
|
+
const body = { ...spec };
|
|
53
|
+
const name = str(ctx.args, 'name');
|
|
54
|
+
const handle = str(ctx.args, 'handle');
|
|
55
|
+
if (name !== undefined)
|
|
56
|
+
body.name = name;
|
|
57
|
+
if (handle !== undefined)
|
|
58
|
+
body.mentionHandle = handle.replace(/^@/, '');
|
|
59
|
+
if (instruction !== undefined)
|
|
60
|
+
body.instruction = instruction;
|
|
61
|
+
if (instructionFile !== undefined) {
|
|
62
|
+
body.instruction = (await readInputFile(ctx.io, instructionFile, 'instruction-file')).trim();
|
|
63
|
+
}
|
|
64
|
+
let project;
|
|
65
|
+
if (forCreate) {
|
|
66
|
+
const template = str(ctx.args, 'template');
|
|
67
|
+
if (template !== undefined)
|
|
68
|
+
body.templateSlug = template;
|
|
69
|
+
const ref = str(ctx.args, 'project');
|
|
70
|
+
if (ref !== undefined) {
|
|
71
|
+
project = await resolveProject(ctx, ref);
|
|
72
|
+
body.projectId = project.id;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (!Object.keys(body).length) {
|
|
76
|
+
throw new UsageError('Nothing to change. Pass --spec <file.json> with the fields to change, or --name / --handle / --instruction.', ctx.command);
|
|
77
|
+
}
|
|
78
|
+
return { body, project };
|
|
79
|
+
}
|
|
80
|
+
const isLive = (status) => status === 'active' || status === 'paused';
|
|
81
|
+
const saidList = (v) => Array.isArray(v)
|
|
82
|
+
? v.filter((x) => x && typeof x.reason === 'string' && x.reason)
|
|
83
|
+
: [];
|
|
84
|
+
const saidLine = (x) => ` - ${String(x.reason)}${typeof x.fix === 'string' && x.fix ? ` Fix: ${x.fix}` : ''}`;
|
|
85
|
+
function activationLines(body, opts) {
|
|
86
|
+
const r = (body.agent?.activation ?? {});
|
|
87
|
+
const missing = saidList(r.missing);
|
|
88
|
+
const notes = [...saidList(body.warnings), ...saidList(r.notes)];
|
|
89
|
+
const lines = [];
|
|
90
|
+
if (opts.gate) {
|
|
91
|
+
if (missing.length)
|
|
92
|
+
lines.push('', 'Before it can be activated:', ...missing.map(saidLine));
|
|
93
|
+
else if (r.ready === true)
|
|
94
|
+
lines.push('', 'Nothing is missing for it to be activated.');
|
|
95
|
+
}
|
|
96
|
+
if (typeof r.machinesOnline === 'number') {
|
|
97
|
+
lines.push(`Machines online for this workspace now: ${r.machinesOnline}`);
|
|
98
|
+
}
|
|
99
|
+
if (notes.length)
|
|
100
|
+
lines.push('', 'Worth knowing:', ...notes.map(saidLine));
|
|
101
|
+
return lines;
|
|
102
|
+
}
|
|
103
|
+
function printDraft(ctx, body, verb, named) {
|
|
104
|
+
const a = body.agent ?? {};
|
|
105
|
+
const status = typeof a.status === 'string' ? a.status : undefined;
|
|
106
|
+
const projectId = typeof a.projectId === 'string' ? a.projectId : undefined;
|
|
107
|
+
const projectName = named?.project && named.project.id === projectId ? named.project.name : undefined;
|
|
108
|
+
const project = projectName
|
|
109
|
+
? `${projectName} (${projectId})`
|
|
110
|
+
: projectId && named?.defaulted
|
|
111
|
+
? `${projectId} (the workspace's default project)`
|
|
112
|
+
: text(projectId);
|
|
113
|
+
const url = composerOf(body);
|
|
114
|
+
const lines = [
|
|
115
|
+
`${verb} ${status === 'draft' ? 'the draft agent' : 'agent'} ${agentLine(a)}`,
|
|
116
|
+
` id: ${text(a.id)}`,
|
|
117
|
+
` project: ${project}`,
|
|
118
|
+
` status: ${text(status)}`,
|
|
119
|
+
...activationLines(body, { gate: !isLive(status) }),
|
|
120
|
+
'',
|
|
121
|
+
];
|
|
122
|
+
if (status === 'draft')
|
|
123
|
+
lines.push('It takes no work until a person activates it.');
|
|
124
|
+
if (url)
|
|
125
|
+
lines.push('Review it in the composer:', ` ${url}`);
|
|
126
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
127
|
+
}
|
|
128
|
+
const specFlags = {
|
|
129
|
+
name: 'string',
|
|
130
|
+
handle: 'string',
|
|
131
|
+
instruction: 'string',
|
|
132
|
+
'instruction-file': 'string',
|
|
133
|
+
spec: 'string',
|
|
134
|
+
};
|
|
135
|
+
const specFlagHelp = [
|
|
136
|
+
['--name <name>', 'what the agent is called'],
|
|
137
|
+
['--handle <handle>', 'the @handle it answers to'],
|
|
138
|
+
['--instruction <text>', 'its standing instruction'],
|
|
139
|
+
['--instruction-file <path>', 'the instruction from a file ("-" for stdin)'],
|
|
140
|
+
['--spec <file.json>', 'the whole agent as JSON ("-" for stdin); flags win over it'],
|
|
141
|
+
];
|
|
142
|
+
function lifecycle(action) {
|
|
143
|
+
const needs = action === 'activate' ? 'agents:activate' : 'agents:write';
|
|
144
|
+
return {
|
|
145
|
+
path: ['agents', action],
|
|
146
|
+
summary: action === 'activate'
|
|
147
|
+
? 'Switch a draft on (a key granted agents:activate only)'
|
|
148
|
+
: action === 'pause'
|
|
149
|
+
? 'Stop an agent taking new work'
|
|
150
|
+
: 'Let a paused agent take work again',
|
|
151
|
+
usage: `agents ${action} <id or @handle>`,
|
|
152
|
+
details: action === 'activate'
|
|
153
|
+
? "Activating is a person's decision. It needs a key made with the agents:activate\n" +
|
|
154
|
+
'scope; without it the API refuses and says so, and the person activates the draft\n' +
|
|
155
|
+
'in the composer instead.'
|
|
156
|
+
: action === 'pause'
|
|
157
|
+
? `Needs ${needs}. A draft is not running, so pausing one changes nothing.`
|
|
158
|
+
: `Needs ${needs}. Only an agent that was switched on before can be resumed; a draft\n` +
|
|
159
|
+
'is activated instead (by a person, or with a key granted agents:activate).',
|
|
160
|
+
positional: { min: 1, max: 1 },
|
|
161
|
+
async run(ctx) {
|
|
162
|
+
const ref = ctx.args.positional[0];
|
|
163
|
+
const body = await ctx.api().post(`/api/v1/agents/${enc(ref)}/${action}`);
|
|
164
|
+
if (ctx.json)
|
|
165
|
+
return printJson(ctx.io, body);
|
|
166
|
+
const a = body?.agent ?? {};
|
|
167
|
+
const url = composerOf(body ?? {});
|
|
168
|
+
const target = action === 'pause' ? 'paused' : 'active';
|
|
169
|
+
const lines = [
|
|
170
|
+
typeof a.status !== 'string'
|
|
171
|
+
? `The API accepted "${action}" for ${ref}.`
|
|
172
|
+
: a.status === target
|
|
173
|
+
? `${agentLine(a)} is ${a.status}.`
|
|
174
|
+
: `${agentLine(a)} is ${a.status}; "${action}" changed nothing.`,
|
|
175
|
+
];
|
|
176
|
+
if (url)
|
|
177
|
+
lines.push(` ${url}`);
|
|
178
|
+
if (a.status === 'active')
|
|
179
|
+
lines.push(...activationLines(body ?? {}, { gate: false }));
|
|
180
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export const agentCommands = [
|
|
185
|
+
{
|
|
186
|
+
path: ['agents', 'list'],
|
|
187
|
+
summary: 'The agents in this workspace',
|
|
188
|
+
usage: 'agents list [--project <id or name>] [--status active|paused|draft]',
|
|
189
|
+
flags: { project: 'string', status: 'string' },
|
|
190
|
+
flagHelp: [
|
|
191
|
+
['--project <id or name>', "only this project's agents"],
|
|
192
|
+
['--status <status>', 'active, paused or draft'],
|
|
193
|
+
],
|
|
194
|
+
async run(ctx) {
|
|
195
|
+
const project = str(ctx.args, 'project');
|
|
196
|
+
const body = await ctx.api().get('/api/v1/agents', {
|
|
197
|
+
project: project ? await resolveProjectId(ctx, project) : undefined,
|
|
198
|
+
status: str(ctx.args, 'status'),
|
|
199
|
+
});
|
|
200
|
+
if (ctx.json)
|
|
201
|
+
return printJson(ctx.io, body);
|
|
202
|
+
const rows = listIn(body, 'agents');
|
|
203
|
+
if (!rows.length) {
|
|
204
|
+
ctx.io.stdout.write('No agents match.\n');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
table(ctx.io, rows, [
|
|
208
|
+
{ head: 'ID', get: pick('id') },
|
|
209
|
+
{
|
|
210
|
+
head: 'HANDLE',
|
|
211
|
+
get: (r) => pick('handle', 'mentionHandle')(r)
|
|
212
|
+
? `@${String(pick('handle', 'mentionHandle')(r))}`
|
|
213
|
+
: undefined,
|
|
214
|
+
},
|
|
215
|
+
{ head: 'STATUS', get: pick('status') },
|
|
216
|
+
{ head: 'NAME', get: pick('name'), max: 40 },
|
|
217
|
+
{ head: 'PROJECT ID', get: pick('projectId'), max: 36 },
|
|
218
|
+
]);
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
path: ['agents', 'get'],
|
|
223
|
+
summary: 'One agent, every field',
|
|
224
|
+
usage: 'agents get <id or @handle>',
|
|
225
|
+
positional: { min: 1, max: 1 },
|
|
226
|
+
async run(ctx) {
|
|
227
|
+
const ref = ctx.args.positional[0];
|
|
228
|
+
const body = await ctx.api().get(`/api/v1/agents/${enc(ref)}`);
|
|
229
|
+
if (ctx.json)
|
|
230
|
+
return printJson(ctx.io, body);
|
|
231
|
+
describe(ctx.io, body.agent ?? {}, { skip: ['composerUrl', 'activation'] });
|
|
232
|
+
const extra = activationLines(body, { gate: !isLive(body.agent?.status) });
|
|
233
|
+
if (extra.length)
|
|
234
|
+
ctx.io.stdout.write(`${extra.join('\n')}\n`);
|
|
235
|
+
const url = composerOf(body);
|
|
236
|
+
if (url)
|
|
237
|
+
ctx.io.stdout.write(`\nIn the composer: ${url}\n`);
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
path: ['agents', 'create'],
|
|
242
|
+
summary: 'Create an agent as a DRAFT and get the composer link',
|
|
243
|
+
usage: 'agents create [--project <id or name>] [--template <slug>] [--name <name>] [--handle <handle>]\n' +
|
|
244
|
+
' [--instruction <text> | --instruction-file <path>] [--spec <file.json>]',
|
|
245
|
+
details: 'Creates a DRAFT: it takes no work until a person opens the composer link and\n' +
|
|
246
|
+
'activates it (or "firefunc agents activate", with a key granted agents:activate).\n' +
|
|
247
|
+
'Needs agents:write.\n\n' +
|
|
248
|
+
SPEC_FIELDS,
|
|
249
|
+
flags: { ...specFlags, project: 'string', template: 'string' },
|
|
250
|
+
flagHelp: [
|
|
251
|
+
['--project <id or name>', "the project it lives in (default: the workspace's default)"],
|
|
252
|
+
['--template <slug>', 'start from a template (firefunc templates list)'],
|
|
253
|
+
...specFlagHelp,
|
|
254
|
+
],
|
|
255
|
+
async run(ctx) {
|
|
256
|
+
const { body: spec, project } = await specFromFlags(ctx, true);
|
|
257
|
+
const body = await ctx.api().post('/api/v1/agents', spec);
|
|
258
|
+
if (ctx.json)
|
|
259
|
+
return printJson(ctx.io, body);
|
|
260
|
+
printDraft(ctx, body, 'Created', { project, defaulted: spec.projectId === undefined });
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
path: ['agents', 'update'],
|
|
265
|
+
summary: 'Change an agent (only the fields you pass)',
|
|
266
|
+
usage: 'agents update <id or @handle> [--spec <file.json>] [--name …] [--handle …] [--instruction …]',
|
|
267
|
+
details: 'Sends only what you pass; everything else stays as it is. An agent cannot move to\n' +
|
|
268
|
+
'another project (create a new one there instead), so an update takes no projectId,\n' +
|
|
269
|
+
'and no templateSlug. tool_grants, deliverables, skills and caps are replaced whole,\n' +
|
|
270
|
+
'as in the composer; guardrails are merged (keys you leave out are kept).\n' +
|
|
271
|
+
'A draft needs agents:write. An agent that is active or paused needs agents:activate\n' +
|
|
272
|
+
'too, because the edit reaches its runs; without it the API refuses and names the\n' +
|
|
273
|
+
'composer link where a person can make the change.\n\n' +
|
|
274
|
+
SPEC_FIELDS,
|
|
275
|
+
flags: specFlags,
|
|
276
|
+
flagHelp: specFlagHelp,
|
|
277
|
+
positional: { min: 1, max: 1 },
|
|
278
|
+
async run(ctx) {
|
|
279
|
+
const ref = ctx.args.positional[0];
|
|
280
|
+
const { body: spec } = await specFromFlags(ctx, false);
|
|
281
|
+
const body = await ctx.api().patch(`/api/v1/agents/${enc(ref)}`, spec);
|
|
282
|
+
if (ctx.json)
|
|
283
|
+
return printJson(ctx.io, body);
|
|
284
|
+
printDraft(ctx, body, 'Updated');
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
lifecycle('activate'),
|
|
288
|
+
lifecycle('pause'),
|
|
289
|
+
lifecycle('resume'),
|
|
290
|
+
];
|
|
291
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type FlagKind = 'string' | 'boolean';
|
|
2
|
+
export type FlagSpec = Record<string, FlagKind>;
|
|
3
|
+
export type ParsedArgs = {
|
|
4
|
+
positional: string[];
|
|
5
|
+
flags: Record<string, string | boolean>;
|
|
6
|
+
};
|
|
7
|
+
export declare class UsageError extends Error {
|
|
8
|
+
readonly helpFor?: string | undefined;
|
|
9
|
+
constructor(message: string, helpFor?: string | undefined);
|
|
10
|
+
}
|
|
11
|
+
export declare const GLOBAL_FLAGS: FlagSpec;
|
|
12
|
+
export declare function parseArgs(argv: readonly string[], spec: FlagSpec, command: string): ParsedArgs;
|
|
13
|
+
export declare function str(p: ParsedArgs, name: string): string | undefined;
|
|
14
|
+
export declare function bool(p: ParsedArgs, name: string): boolean;
|
|
15
|
+
export declare function positiveNumber(p: ParsedArgs, name: string, command: string, opts?: {
|
|
16
|
+
min?: number;
|
|
17
|
+
max?: number;
|
|
18
|
+
}): number | undefined;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export class UsageError extends Error {
|
|
2
|
+
helpFor;
|
|
3
|
+
constructor(message, helpFor) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.helpFor = helpFor;
|
|
6
|
+
this.name = 'UsageError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export const GLOBAL_FLAGS = {
|
|
10
|
+
json: 'boolean',
|
|
11
|
+
help: 'boolean',
|
|
12
|
+
'api-url': 'string',
|
|
13
|
+
};
|
|
14
|
+
export function parseArgs(argv, spec, command) {
|
|
15
|
+
const all = { ...GLOBAL_FLAGS, ...spec };
|
|
16
|
+
const positional = [];
|
|
17
|
+
const flags = {};
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
if (a === '--') {
|
|
21
|
+
positional.push(...argv.slice(i + 1));
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
if (a === '-h') {
|
|
25
|
+
flags.help = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!a.startsWith('--') || a === '--') {
|
|
29
|
+
positional.push(a);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const eq = a.indexOf('=');
|
|
33
|
+
const name = eq > 0 ? a.slice(2, eq) : a.slice(2);
|
|
34
|
+
const kind = all[name];
|
|
35
|
+
if (!kind) {
|
|
36
|
+
throw new UsageError(`Unknown option --${name} for "${command}".`, command);
|
|
37
|
+
}
|
|
38
|
+
if (kind === 'boolean') {
|
|
39
|
+
if (eq > 0) {
|
|
40
|
+
const v = a.slice(eq + 1).toLowerCase();
|
|
41
|
+
if (v !== 'true' && v !== 'false') {
|
|
42
|
+
throw new UsageError(`--${name} takes no value (or =true / =false).`, command);
|
|
43
|
+
}
|
|
44
|
+
flags[name] = v === 'true';
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
flags[name] = true;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (eq > 0) {
|
|
52
|
+
flags[name] = a.slice(eq + 1);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const next = argv[i + 1];
|
|
56
|
+
if (next === undefined || next.startsWith('--')) {
|
|
57
|
+
throw new UsageError(`--${name} needs a value${next ? ` (for a value that starts with "--", write --${name}=…)` : ''}.`, command);
|
|
58
|
+
}
|
|
59
|
+
flags[name] = next;
|
|
60
|
+
i++;
|
|
61
|
+
}
|
|
62
|
+
return { positional, flags };
|
|
63
|
+
}
|
|
64
|
+
export function str(p, name) {
|
|
65
|
+
const v = p.flags[name];
|
|
66
|
+
return typeof v === 'string' ? v : undefined;
|
|
67
|
+
}
|
|
68
|
+
export function bool(p, name) {
|
|
69
|
+
return p.flags[name] === true;
|
|
70
|
+
}
|
|
71
|
+
export function positiveNumber(p, name, command, opts = {}) {
|
|
72
|
+
const raw = str(p, name);
|
|
73
|
+
if (raw === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
const n = Number(raw);
|
|
76
|
+
const min = opts.min ?? 1;
|
|
77
|
+
if (!Number.isFinite(n) || n < min || (opts.max !== undefined && n > opts.max)) {
|
|
78
|
+
throw new UsageError(`--${name} must be a number${opts.max !== undefined ? ` from ${min} to ${opts.max}` : ` of at least ${min}`}.`, command);
|
|
79
|
+
}
|
|
80
|
+
return n;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Command } from './command.js';
|
|
2
|
+
export type Me = {
|
|
3
|
+
workspace?: {
|
|
4
|
+
id?: string;
|
|
5
|
+
name?: string | null;
|
|
6
|
+
slug?: string | null;
|
|
7
|
+
};
|
|
8
|
+
key?: {
|
|
9
|
+
id?: string;
|
|
10
|
+
name?: string | null;
|
|
11
|
+
scopes?: string[];
|
|
12
|
+
};
|
|
13
|
+
grant?: {
|
|
14
|
+
grantId?: string;
|
|
15
|
+
userId?: string;
|
|
16
|
+
scopes?: string[];
|
|
17
|
+
};
|
|
18
|
+
[k: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
export declare const scopesOf: (me: Me) => string[];
|
|
21
|
+
export declare const authCommands: Command[];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { str } from './args.js';
|
|
2
|
+
import { ApiClient } from './client.js';
|
|
3
|
+
import { API_KEY_SHAPE, configFile, loadCliConfig, removeCliConfig, resolveApiUrl, saveCliConfig, } from './config.js';
|
|
4
|
+
import { Refusal } from './io.js';
|
|
5
|
+
import { printJson } from './output.js';
|
|
6
|
+
export const scopesOf = (me) => {
|
|
7
|
+
for (const v of [me.key?.scopes, me.grant?.scopes])
|
|
8
|
+
if (Array.isArray(v))
|
|
9
|
+
return v;
|
|
10
|
+
return [];
|
|
11
|
+
};
|
|
12
|
+
const keyIdOf = (me) => me.key?.id;
|
|
13
|
+
const ACTIVATE_NOTE = 'This key cannot activate agents (no agents:activate scope): agents it creates stay drafts until a person activates them in FireFunc.';
|
|
14
|
+
function printIdentity(ctx, me, apiUrl, source) {
|
|
15
|
+
const scopes = scopesOf(me);
|
|
16
|
+
const ws = me.workspace;
|
|
17
|
+
const lines = [
|
|
18
|
+
`Workspace: ${ws?.name ?? '(unnamed)'}${ws?.id ? ` (${ws.id})` : ''}`,
|
|
19
|
+
`Key: ${me.key?.name ? `"${me.key.name}" ` : ''}${keyIdOf(me) ? `(${keyIdOf(me)}) ` : ''}— ${source}`,
|
|
20
|
+
`Scopes: ${scopes.length ? scopes.join(', ') : 'none'}`,
|
|
21
|
+
`API: ${apiUrl}`,
|
|
22
|
+
];
|
|
23
|
+
if (!scopes.includes('agents:activate'))
|
|
24
|
+
lines.push('', ACTIVATE_NOTE);
|
|
25
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
26
|
+
}
|
|
27
|
+
const login = {
|
|
28
|
+
path: ['login'],
|
|
29
|
+
summary: 'Sign in with a workspace API key (asked for without echo)',
|
|
30
|
+
usage: 'login [--key <ffk_…>] [--api-url <url>]',
|
|
31
|
+
details: 'Make a key in FireFunc → Settings → API keys, then run "firefunc login" and paste it at the\n' +
|
|
32
|
+
'prompt — nothing you type is shown. Piped in (printf %s "$KEY" | firefunc login) or in\n' +
|
|
33
|
+
'FIREFUNC_API_KEY works too. The key is checked against the API before it is saved to\n' +
|
|
34
|
+
'~/.firefunc/config.json (readable only by you). It is never printed, and it is sent\n' +
|
|
35
|
+
'only to the address it was checked against (--api-url here names another).\n\n' +
|
|
36
|
+
'Which key to make: agents:read to look (templates, projects, connections, skills,\n' +
|
|
37
|
+
'agents), agents:write to create and edit drafts, tasks:write to start runs. Add\n' +
|
|
38
|
+
'agents:activate only if you mean this key to switch agents on without a person.',
|
|
39
|
+
flags: { key: 'string' },
|
|
40
|
+
flagHelp: [
|
|
41
|
+
['--key <ffk_…>', 'the key itself — it lands in your shell history; prefer the prompt'],
|
|
42
|
+
],
|
|
43
|
+
async run(ctx) {
|
|
44
|
+
const { io } = ctx;
|
|
45
|
+
let existing = null;
|
|
46
|
+
try {
|
|
47
|
+
existing = loadCliConfig(io, { warnLoose: false });
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
if (!(err instanceof Refusal && err.code === 'config_unreadable'))
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
const apiUrl = resolveApiUrl(str(ctx.args, 'api-url'), io, existing);
|
|
54
|
+
let key = str(ctx.args, 'key')?.trim();
|
|
55
|
+
if (key !== undefined && !ctx.json && io.stdinIsTty) {
|
|
56
|
+
io.stderr.write('Note: a key passed with --key is now in your shell history. The prompt keeps it out.\n');
|
|
57
|
+
}
|
|
58
|
+
key ??= io.env.FIREFUNC_API_KEY?.trim() || undefined;
|
|
59
|
+
if (key === undefined) {
|
|
60
|
+
key = io.stdinIsTty
|
|
61
|
+
? await io.readSecret('Workspace API key (ffk_…, from Settings → API keys): ')
|
|
62
|
+
: (await io.readStdin()).trim();
|
|
63
|
+
}
|
|
64
|
+
if (!key) {
|
|
65
|
+
throw new Refusal('No key was given.', 'Make one in FireFunc → Settings → API keys, then paste it at the "firefunc login" prompt.', 'no_key');
|
|
66
|
+
}
|
|
67
|
+
if (!API_KEY_SHAPE.test(key)) {
|
|
68
|
+
throw new Refusal('That is not a FireFunc workspace API key (they look like ffk_<workspace>_<secret>).', 'Copy the key FireFunc showed when it was made (Settings → API keys); a lost key cannot be shown again — make a new one.', 'bad_key');
|
|
69
|
+
}
|
|
70
|
+
const me = await new ApiClient(apiUrl, key, io.fetch).get('/api/v1/me');
|
|
71
|
+
const file = saveCliConfig(io, {
|
|
72
|
+
apiUrl,
|
|
73
|
+
key,
|
|
74
|
+
workspace: me.workspace?.id
|
|
75
|
+
? { id: me.workspace.id, name: me.workspace.name ?? null }
|
|
76
|
+
: undefined,
|
|
77
|
+
keyId: keyIdOf(me),
|
|
78
|
+
keyName: me.key?.name ?? undefined,
|
|
79
|
+
scopes: scopesOf(me),
|
|
80
|
+
savedAt: new Date(io.now()).toISOString(),
|
|
81
|
+
});
|
|
82
|
+
if (ctx.json) {
|
|
83
|
+
printJson(io, { ...me, apiUrl, savedTo: file });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
io.stdout.write(`Signed in. The key is saved to ${file} (readable only by you).\n\n`);
|
|
87
|
+
printIdentity(ctx, me, apiUrl, 'saved by firefunc login');
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const logout = {
|
|
91
|
+
path: ['logout'],
|
|
92
|
+
summary: 'Forget the key saved on this machine',
|
|
93
|
+
usage: 'logout',
|
|
94
|
+
details: 'Removes ~/.firefunc/config.json. The key itself keeps working until it is revoked in\n' +
|
|
95
|
+
'FireFunc → Settings → API keys — this command cannot revoke it.',
|
|
96
|
+
async run(ctx) {
|
|
97
|
+
const { io } = ctx;
|
|
98
|
+
const file = configFile(io);
|
|
99
|
+
const removed = removeCliConfig(io);
|
|
100
|
+
const envStillSet = Boolean(io.env.FIREFUNC_API_KEY?.trim());
|
|
101
|
+
if (ctx.json) {
|
|
102
|
+
printJson(io, { removed, file, envKeyStillSet: envStillSet });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
io.stdout.write(removed
|
|
106
|
+
? `Forgot the key saved in ${file}.\nThe key still works until it is revoked in FireFunc → Settings → API keys.\n`
|
|
107
|
+
: `No key was saved on this machine (${file}).\n`);
|
|
108
|
+
if (envStillSet) {
|
|
109
|
+
io.stdout.write('FIREFUNC_API_KEY is still set in this shell, and commands will keep using it.\n');
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const whoami = {
|
|
114
|
+
path: ['whoami'],
|
|
115
|
+
summary: 'Which workspace and key this machine is using, and its scopes',
|
|
116
|
+
usage: 'whoami',
|
|
117
|
+
async run(ctx) {
|
|
118
|
+
const { io } = ctx;
|
|
119
|
+
const creds = ctx.credentials();
|
|
120
|
+
const me = await ctx.api().get('/api/v1/me');
|
|
121
|
+
if (ctx.json) {
|
|
122
|
+
printJson(io, { ...me, apiUrl: creds.apiUrl, keySource: creds.keySource });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
printIdentity(ctx, me, creds.apiUrl, creds.keySource === 'env' ? 'from FIREFUNC_API_KEY' : 'saved by firefunc login');
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
export const authCommands = [login, logout, whoami];
|
|
129
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Command, Ctx } from './command.js';
|
|
2
|
+
export type Row = Record<string, unknown>;
|
|
3
|
+
export declare const pick: (...keys: string[]) => (row: Row) => unknown;
|
|
4
|
+
export declare function listIn(body: unknown, key: string): Row[];
|
|
5
|
+
export declare function resolveProject(ctx: Ctx, ref: string): Promise<{
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function resolveProjectId(ctx: Ctx, ref: string): Promise<string>;
|
|
10
|
+
export declare const catalogCommands: Command[];
|