@firefunc-agent/runner 0.9.0 → 0.9.4

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 (66) hide show
  1. package/README.md +90 -28
  2. package/dist/activity.d.ts +4 -1
  3. package/dist/activity.js +94 -8
  4. package/dist/api.d.ts +24 -0
  5. package/dist/api.js +74 -5
  6. package/dist/brief.d.ts +5 -0
  7. package/dist/brief.js +21 -0
  8. package/dist/build-info.json +2 -2
  9. package/dist/cli.js +10 -2
  10. package/dist/config.d.ts +2 -0
  11. package/dist/cut.d.ts +45 -0
  12. package/dist/cut.js +105 -0
  13. package/dist/daemon.d.ts +16 -0
  14. package/dist/daemon.js +156 -35
  15. package/dist/declined.d.ts +11 -0
  16. package/dist/declined.js +27 -0
  17. package/dist/engines/claude.js +129 -1
  18. package/dist/engines/types.d.ts +10 -0
  19. package/dist/exec.d.ts +3 -0
  20. package/dist/exec.js +48 -5
  21. package/dist/firefunc/agents.js +59 -7
  22. package/dist/firefunc/client.d.ts +1 -0
  23. package/dist/firefunc/client.js +3 -0
  24. package/dist/firefunc/configure.d.ts +6 -0
  25. package/dist/firefunc/configure.js +409 -0
  26. package/dist/firefunc/main.js +45 -7
  27. package/dist/firefunc/output.d.ts +1 -0
  28. package/dist/firefunc/output.js +24 -1
  29. package/dist/firefunc/tasks.js +32 -4
  30. package/dist/firefunc/version.js +2 -17
  31. package/dist/held.d.ts +18 -0
  32. package/dist/held.js +95 -0
  33. package/dist/job.d.ts +3 -0
  34. package/dist/job.js +437 -76
  35. package/dist/keep-local.d.ts +6 -1
  36. package/dist/keep-local.js +171 -4
  37. package/dist/limit.d.ts +30 -0
  38. package/dist/limit.js +258 -0
  39. package/dist/locks.d.ts +14 -0
  40. package/dist/locks.js +164 -0
  41. package/dist/mcp-proxy.d.ts +21 -0
  42. package/dist/mcp-proxy.js +180 -0
  43. package/dist/mcp.d.ts +2 -0
  44. package/dist/mcp.js +31 -2
  45. package/dist/orphans.d.ts +40 -0
  46. package/dist/orphans.js +235 -0
  47. package/dist/pool.d.ts +7 -0
  48. package/dist/pool.js +57 -9
  49. package/dist/pr-title.d.ts +11 -0
  50. package/dist/pr-title.js +63 -0
  51. package/dist/recover.d.ts +10 -0
  52. package/dist/recover.js +104 -0
  53. package/dist/session-stream.d.ts +8 -1
  54. package/dist/session-stream.js +9 -1
  55. package/dist/skills.d.ts +11 -0
  56. package/dist/skills.js +164 -0
  57. package/dist/stopped.d.ts +3 -0
  58. package/dist/stopped.js +10 -0
  59. package/dist/usage.d.ts +49 -0
  60. package/dist/usage.js +389 -0
  61. package/dist/version.d.ts +1 -0
  62. package/dist/version.js +17 -0
  63. package/dist/worktrees.d.ts +15 -0
  64. package/dist/worktrees.js +96 -0
  65. package/package.json +1 -1
  66. package/skill/firefunc/SKILL.md +63 -8
package/dist/exec.d.ts CHANGED
@@ -4,6 +4,7 @@ export type ExecResult = {
4
4
  stdout: string;
5
5
  stderr: string;
6
6
  };
7
+ export declare function signalExitCode(signal: NodeJS.Signals | null): number;
7
8
  export declare function spawnBackground(cmd: string, opts?: {
8
9
  cwd?: string;
9
10
  env?: NodeJS.ProcessEnv;
@@ -16,5 +17,7 @@ export declare function exec(cmd: string, args: string[], opts?: {
16
17
  input?: string;
17
18
  shell?: boolean;
18
19
  onStdout?: (chunk: string) => void;
20
+ ownGroup?: boolean;
21
+ onSpawn?: (pid: number) => void;
19
22
  }): Promise<ExecResult>;
20
23
  export declare function execOut(cmd: string, args: string[], cwd?: string): Promise<string>;
package/dist/exec.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { constants } from 'node:os';
3
+ export function signalExitCode(signal) {
4
+ const n = signal ? constants.signals[signal] : undefined;
5
+ return typeof n === 'number' ? 128 + n : 1;
6
+ }
2
7
  function mergeEnv(extra) {
3
8
  const env = { ...process.env, ...extra };
4
9
  for (const k of Object.keys(env))
@@ -46,12 +51,40 @@ export async function killProcessTree(child) {
46
51
  }
47
52
  export function exec(cmd, args, opts = {}) {
48
53
  return new Promise((resolve, reject) => {
54
+ const grouped = opts.ownGroup === true && process.platform !== 'win32';
49
55
  const child = spawn(cmd, args, {
50
56
  cwd: opts.cwd,
51
57
  env: mergeEnv(opts.env),
52
58
  stdio: [opts.input != null ? 'pipe' : 'ignore', 'pipe', 'pipe'],
53
59
  shell: opts.shell,
60
+ detached: grouped,
61
+ });
62
+ if (child.pid)
63
+ opts.onSpawn?.(child.pid);
64
+ let exited = false;
65
+ let settled = false;
66
+ let exitTimer = null;
67
+ child.on('exit', (code, signal) => {
68
+ exited = true;
69
+ exitTimer = setTimeout(() => {
70
+ child.stdout?.destroy();
71
+ child.stderr?.destroy();
72
+ finish(code, signal);
73
+ }, EXIT_GRACE_MS);
54
74
  });
75
+ const stop = (sig) => {
76
+ if (exited)
77
+ return;
78
+ if (grouped && child.pid) {
79
+ try {
80
+ process.kill(-child.pid, sig);
81
+ return;
82
+ }
83
+ catch {
84
+ }
85
+ }
86
+ child.kill(sig);
87
+ };
55
88
  if (opts.input != null) {
56
89
  child.stdin?.on('error', () => { });
57
90
  child.stdin?.write(opts.input);
@@ -64,8 +97,8 @@ export function exec(cmd, args, opts = {}) {
64
97
  if (opts.timeoutMs) {
65
98
  timer = setTimeout(() => {
66
99
  timedOut = true;
67
- child.kill('SIGTERM');
68
- setTimeout(() => child.kill('SIGKILL'), 5_000);
100
+ stop('SIGTERM');
101
+ setTimeout(() => stop('SIGKILL'), 5_000);
69
102
  }, opts.timeoutMs);
70
103
  }
71
104
  child.stdout?.on('data', (d) => {
@@ -77,19 +110,29 @@ export function exec(cmd, args, opts = {}) {
77
110
  child.on('error', (err) => {
78
111
  if (timer)
79
112
  clearTimeout(timer);
113
+ if (settled)
114
+ return;
115
+ settled = true;
80
116
  reject(err);
81
117
  });
82
- child.on('close', (code) => {
118
+ const finish = (code, signal) => {
119
+ if (settled)
120
+ return;
121
+ settled = true;
83
122
  if (timer)
84
123
  clearTimeout(timer);
124
+ if (exitTimer)
125
+ clearTimeout(exitTimer);
85
126
  resolve({
86
- code: timedOut ? 124 : (code ?? 1),
127
+ code: timedOut ? 124 : (code ?? signalExitCode(signal)),
87
128
  stdout,
88
129
  stderr: timedOut ? `${stderr}\n[firefunc-runner] timed out` : stderr,
89
130
  });
90
- });
131
+ };
132
+ child.on('close', finish);
91
133
  });
92
134
  }
135
+ const EXIT_GRACE_MS = 3_000;
93
136
  export async function execOut(cmd, args, cwd) {
94
137
  const r = await exec(cmd, args, { cwd });
95
138
  return r.code === 0 ? r.stdout.trim() : '';
@@ -8,15 +8,61 @@ function composerOf(body) {
8
8
  const u = body.composerUrl ?? body.agent?.composerUrl;
9
9
  return typeof u === 'string' ? u : undefined;
10
10
  }
11
+ const ANATOMY_ROWS = [
12
+ ['purpose', 'Purpose'],
13
+ ['startsWhen', 'Starts when'],
14
+ ['worksIn', 'Works in'],
15
+ ['reads', 'Reads'],
16
+ ['writes', 'Writes'],
17
+ ['skills', 'Skills'],
18
+ ['delivers', 'Delivers'],
19
+ ['handsOffTo', 'Hands off to'],
20
+ ['guardrails', 'Guardrails'],
21
+ ['runsOn', 'Runs on'],
22
+ ];
23
+ const ANATOMY_SOURCE_WORDS = {
24
+ template: 'from template',
25
+ edited: 'edited here',
26
+ default: 'default',
27
+ rule: 'from the project’s rules',
28
+ declared: 'declared by another agent',
29
+ evidence: 'from evidence',
30
+ suggested: 'suggested',
31
+ unset: 'not set',
32
+ derived: 'read from how it is built',
33
+ };
34
+ function anatomyLines(anatomy) {
35
+ if (!anatomy || typeof anatomy !== 'object')
36
+ return [];
37
+ const a = anatomy;
38
+ const rows = ANATOMY_ROWS.flatMap(([key, label]) => {
39
+ const f = a[key];
40
+ if (!f || typeof f.words !== 'string')
41
+ return [];
42
+ const tag = typeof f.source === 'string' && ANATOMY_SOURCE_WORDS[f.source]
43
+ ? ` (${ANATOMY_SOURCE_WORDS[f.source]})`
44
+ : '';
45
+ return [` ${label}: ${f.words}${tag}`];
46
+ });
47
+ if (!rows.length)
48
+ return [];
49
+ const said = (k, label) => {
50
+ const w = a[k]?.words;
51
+ return typeof w === 'string' && w ? [` ${label}: ${w}`] : [];
52
+ };
53
+ return ['', 'What it is:', ...rows, ...said('person', 'A person'), ...said('provenance', 'From')];
54
+ }
11
55
  const SPEC_FIELDS = "The spec is the composer's own agent body, as JSON (firefunc connections list --json\n" +
12
56
  'shows the values each tool takes):\n' +
13
57
  ' 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" +
58
+ " workspace's default project — except with a template, which needs\n" +
59
+ " it: a template's copy lives in the project you name. It cannot\n" +
60
+ ' change after create.\n' +
15
61
  ' templateSlug start from a template (firefunc templates list); --template sets it,\n' +
16
62
  ' 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' +
63
+ ' name, trigger required unless a template gives them\n' +
64
+ ' workType optional, default task: bug | feature | task | chore | story |\n' +
65
+ ' refactor — story makes the agent take a whole story\n' +
20
66
  ' trigger { source, event, filters, query, after } — what wakes it. source is\n' +
21
67
  ' a tool\'s "source" (connections list), or manual (by hand, a schedule\n' +
22
68
  ' or a join), webhook, or "*" for any tool; event is one it sends\n' +
@@ -228,7 +274,10 @@ export const agentCommands = [
228
274
  const body = await ctx.api().get(`/api/v1/agents/${enc(ref)}`);
229
275
  if (ctx.json)
230
276
  return printJson(ctx.io, body);
231
- describe(ctx.io, body.agent ?? {}, { skip: ['composerUrl', 'activation'] });
277
+ describe(ctx.io, body.agent ?? {}, { skip: ['composerUrl', 'activation', 'anatomy'] });
278
+ const what = anatomyLines(body.agent?.anatomy);
279
+ if (what.length)
280
+ ctx.io.stdout.write(`${what.join('\n')}\n`);
232
281
  const extra = activationLines(body, { gate: !isLive(body.agent?.status) });
233
282
  if (extra.length)
234
283
  ctx.io.stdout.write(`${extra.join('\n')}\n`);
@@ -248,8 +297,11 @@ export const agentCommands = [
248
297
  SPEC_FIELDS,
249
298
  flags: { ...specFlags, project: 'string', template: 'string' },
250
299
  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)'],
300
+ [
301
+ '--project <id or name>',
302
+ "the project it lives in (required with --template; otherwise the workspace's default)",
303
+ ],
304
+ ['--template <slug>', 'start from a template (firefunc templates list); needs --project'],
253
305
  ...specFlagHelp,
254
306
  ],
255
307
  async run(ctx) {
@@ -27,6 +27,7 @@ export declare class ApiClient {
27
27
  get<T>(path: string, query?: Query): Promise<T>;
28
28
  post<T>(path: string, body?: unknown): Promise<T>;
29
29
  patch<T>(path: string, body: unknown): Promise<T>;
30
+ put<T>(path: string, body: unknown): Promise<T>;
30
31
  request<T>(method: string, path: string, opts?: {
31
32
  query?: Query;
32
33
  body?: unknown;
@@ -55,6 +55,9 @@ export class ApiClient {
55
55
  patch(path, body) {
56
56
  return this.request('PATCH', path, { body });
57
57
  }
58
+ put(path, body) {
59
+ return this.request('PUT', path, { body });
60
+ }
58
61
  async request(method, path, opts = {}) {
59
62
  const url = new URL(`${this.baseUrl}${path}`);
60
63
  for (const [k, v] of Object.entries(opts.query ?? {})) {
@@ -0,0 +1,6 @@
1
+ import { type Command } from './command.js';
2
+ export declare function frontmatterOf(md: string): {
3
+ fields: Record<string, string>;
4
+ hasFrontmatter: boolean;
5
+ };
6
+ export declare const configureCommands: Command[];
@@ -0,0 +1,409 @@
1
+ import { str, UsageError } from './args.js';
2
+ import { listIn, pick, resolveProject } from './catalog.js';
3
+ import { enc, readInputFile } from './command.js';
4
+ import { Refusal } from './io.js';
5
+ import { printJson, table, text } from './output.js';
6
+ function parseJsonFile(raw, path, want) {
7
+ try {
8
+ return JSON.parse(raw);
9
+ }
10
+ catch (err) {
11
+ throw new Refusal(`--file ${path} is not valid JSON (${err.message}).`, `Write ${want} as JSON.`, 'bad_file');
12
+ }
13
+ }
14
+ function requireFile(ctx) {
15
+ const path = str(ctx.args, 'file');
16
+ if (path === undefined) {
17
+ throw new UsageError('Pass --file <path> ("-" for stdin).', ctx.command);
18
+ }
19
+ return path;
20
+ }
21
+ export function frontmatterOf(md) {
22
+ const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(md);
23
+ if (!m)
24
+ return { fields: {}, hasFrontmatter: false };
25
+ const fields = {};
26
+ for (const line of m[1].split(/\r?\n/)) {
27
+ const kv = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
28
+ if (!kv)
29
+ continue;
30
+ fields[kv[1]] = kv[2].trim().replace(/^(['"])(.*)\1$/, '$2');
31
+ }
32
+ return { fields, hasFrontmatter: true };
33
+ }
34
+ const slugOf = (name) => name
35
+ .toLowerCase()
36
+ .replace(/[^a-z0-9]+/g, '-')
37
+ .replace(/^-+|-+$/g, '')
38
+ .slice(0, 64);
39
+ const looksLikeJson = (path, raw) => path.toLowerCase().endsWith('.json') || raw.trimStart().startsWith('{');
40
+ async function skillFromFile(ctx, path, forCreate) {
41
+ const raw = await readInputFile(ctx.io, path, 'file');
42
+ const name = str(ctx.args, 'name');
43
+ const description = str(ctx.args, 'description');
44
+ const slug = str(ctx.args, 'slug');
45
+ let body;
46
+ if (looksLikeJson(path, raw)) {
47
+ const parsed = parseJsonFile(raw, path, 'the skill');
48
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
49
+ throw new Refusal(`--file ${path} must hold one JSON object.`, 'Write the skill as { "slug", "name", "description", "content" }, or pass a SKILL.md.', 'bad_file');
50
+ }
51
+ body = { ...parsed };
52
+ }
53
+ else {
54
+ const { fields, hasFrontmatter } = frontmatterOf(raw);
55
+ const n = name ?? fields.name;
56
+ const d = description ?? fields.description;
57
+ if (!n && (forCreate || !hasFrontmatter)) {
58
+ throw new Refusal(`--file ${path} is a SKILL.md with no name in its frontmatter.`, 'Add "name:" to its frontmatter, or pass --name.', 'skill_needs_name');
59
+ }
60
+ body = {
61
+ ...(n ? { name: n } : {}),
62
+ ...(d !== undefined || forCreate ? { description: d ?? '' } : {}),
63
+ content: hasFrontmatter
64
+ ? raw
65
+ : `---\nname: ${n}\ndescription: ${d ?? ''}\n---\n\n${raw.trim()}\n`,
66
+ };
67
+ }
68
+ if (name !== undefined)
69
+ body.name = name;
70
+ if (description !== undefined)
71
+ body.description = description;
72
+ if (forCreate) {
73
+ if (slug !== undefined)
74
+ body.slug = slug;
75
+ if (body.slug === undefined && typeof body.name === 'string')
76
+ body.slug = slugOf(body.name);
77
+ }
78
+ else {
79
+ delete body.slug;
80
+ }
81
+ return body;
82
+ }
83
+ const skillName = (s) => `“${text(s.name)}” (${text(s.slug)})`;
84
+ const INSTRUCTION_LABELS = {
85
+ agent: 'Agent instructions',
86
+ gather: 'What to gather before starting',
87
+ pr_title: 'Pull request titles',
88
+ pr_body: 'Pull request descriptions',
89
+ commit: 'Commit messages',
90
+ };
91
+ function printInstructions(ctx, body, verb) {
92
+ const project = (body.project ?? {});
93
+ const instructions = (body.instructions ?? {});
94
+ const set = Object.entries(instructions).filter(([, v]) => typeof v === 'string' && v);
95
+ const lines = [
96
+ `${verb ? `${verb} the` : 'The'} standing instructions of ${text(project.name)} (${text(project.id)}).`,
97
+ ];
98
+ if (!set.length) {
99
+ lines.push('None are set: runs in this project read the workspace’s instructions and the agent’s own.');
100
+ }
101
+ for (const [k, v] of set) {
102
+ lines.push('', `${INSTRUCTION_LABELS[k] ?? k} (${k}):`);
103
+ for (const l of String(v).split('\n'))
104
+ lines.push(` ${l}`);
105
+ }
106
+ if (verb) {
107
+ lines.push('', 'Every run in the project reads them, after the workspace’s instructions and before the agent’s own.');
108
+ }
109
+ ctx.io.stdout.write(`${lines.join('\n')}\n`);
110
+ }
111
+ const KIND_LABELS = {
112
+ jira: 'Jira project keys',
113
+ linear: 'Linear teams / projects',
114
+ sentry: 'Sentry projects',
115
+ slack: 'Slack channels',
116
+ figma: 'Figma files',
117
+ };
118
+ function printSources(ctx, body, verb) {
119
+ const project = (body.project ?? {});
120
+ const sources = (body.sources ?? {});
121
+ const bound = Array.isArray(body.claimedThroughBinding)
122
+ ? body.claimedThroughBinding.map(String)
123
+ : [];
124
+ const w = Math.max(...Object.values(KIND_LABELS).map((l) => l.length)) + 2;
125
+ const lines = [
126
+ `${verb ? `${verb}. ` : ''}What ${text(project.name)} (${text(project.id)}) claims — work with these keys is routed to it:`,
127
+ ];
128
+ for (const [k, label] of Object.entries(KIND_LABELS)) {
129
+ const keys = Array.isArray(sources[k]) ? sources[k].map(String) : [];
130
+ lines.push(` ${label.padEnd(w)}${keys.length ? keys.join(', ') : '—'}${bound.includes(k) ? ' (through its bound account; changed there)' : ''}`);
131
+ }
132
+ ctx.io.stdout.write(`${lines.join('\n')}\n`);
133
+ }
134
+ function printRepos(ctx, body, verb) {
135
+ const project = (body.project ?? {});
136
+ const repos = Array.isArray(body.repos) ? body.repos.map(String) : [];
137
+ const lines = [
138
+ `${verb ? `${verb}. ` : ''}${text(project.name)} (${text(project.id)}) lists ${repos.length ? repos.join(', ') : 'no repository'}.`,
139
+ ` primary: ${text(body.primaryRepo)}`,
140
+ ` updatedAt: ${text(body.updatedAt)} (send it as expectedUpdatedAt to refuse a write over a newer change)`,
141
+ ];
142
+ const av = body.available;
143
+ if (av) {
144
+ lines.push('');
145
+ if (av.supported === false) {
146
+ lines.push('This API cannot list the repositories the project’s GitHub account can see.');
147
+ }
148
+ else if (av.connected === false) {
149
+ lines.push('The project has no GitHub account, so no repository can be added to it.');
150
+ }
151
+ else {
152
+ const seen = (av.repos ?? []).map(String);
153
+ lines.push(`Its GitHub account can see ${seen.length} ${seen.length === 1 ? 'repository' : 'repositories'}${av.complete === false ? ' (an account did not answer, so the list may be short)' : ''} — only these can be added:`, ...seen.map((r) => ` ${r}`));
154
+ }
155
+ }
156
+ ctx.io.stdout.write(`${lines.join('\n')}\n`);
157
+ }
158
+ const NEEDS_CONFIGURE = 'Needs a key granted workspace:configure (off unless ticked in Settings → API keys).';
159
+ function projectCommand(kind, action, spec) {
160
+ return {
161
+ path: ['projects', kind, action],
162
+ summary: spec.summary,
163
+ usage: `projects ${kind} ${action} <project id or name>${action === 'set' ? ' --file <file.json>' : ''}`,
164
+ details: spec.details,
165
+ positional: { min: 1, max: 1 },
166
+ ...(action === 'set'
167
+ ? {
168
+ flags: { file: 'string' },
169
+ flagHelp: [['--file <path>', `${spec.want} as JSON ("-" for stdin)`]],
170
+ }
171
+ : {}),
172
+ async run(ctx) {
173
+ const project = await resolveProject(ctx, ctx.args.positional[0]);
174
+ const url = `/api/v1/projects/${enc(project.id)}/${kind}`;
175
+ let body;
176
+ if (action === 'get') {
177
+ body = await ctx.api().get(url);
178
+ }
179
+ else {
180
+ const path = requireFile(ctx);
181
+ const raw = await readInputFile(ctx.io, path, 'file');
182
+ const parsed = parseJsonFile(raw, path, spec.want);
183
+ const send = spec.body
184
+ ? spec.body(parsed, path)
185
+ : (() => {
186
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
187
+ throw new Refusal(`--file ${path} must hold one JSON object.`, `Write ${spec.want} as one JSON object.`, 'bad_file');
188
+ }
189
+ return parsed;
190
+ })();
191
+ body = await ctx.api().put(url, send);
192
+ }
193
+ if (ctx.json)
194
+ return printJson(ctx.io, body);
195
+ spec.print(ctx, body ?? {}, action === 'set' ? spec.verb : undefined);
196
+ },
197
+ };
198
+ }
199
+ export const configureCommands = [
200
+ {
201
+ path: ['skills', 'directory'],
202
+ summary: "FireFunc's curated skills, and which are installed here",
203
+ usage: 'skills directory',
204
+ details: 'Install one with: firefunc skills install <slug> (a key granted workspace:configure).\n' +
205
+ "Each entry's SKILL.md: add --json.",
206
+ async run(ctx) {
207
+ const body = await ctx.api().get('/api/v1/skills/directory');
208
+ if (ctx.json)
209
+ return printJson(ctx.io, body);
210
+ const rows = listIn(body, 'entries');
211
+ if (!rows.length) {
212
+ ctx.io.stdout.write('The directory is empty.\n');
213
+ return;
214
+ }
215
+ table(ctx.io, rows, [
216
+ { head: 'SLUG', get: pick('slug') },
217
+ { head: 'CATEGORY', get: pick('category') },
218
+ { head: 'INSTALLED', get: (r) => (r.installed === true ? 'yes' : 'no') },
219
+ { head: 'NAME', get: pick('name'), max: 40 },
220
+ { head: 'DESCRIPTION', get: pick('description'), max: 70 },
221
+ ]);
222
+ },
223
+ },
224
+ {
225
+ path: ['skills', 'install'],
226
+ summary: 'Install a skill from the directory, so agents may carry it',
227
+ usage: 'skills install <slug>',
228
+ details: `${NEEDS_CONFIGURE}\n` +
229
+ 'A skill goes into every run of every agent that carries it. Installing one that is\n' +
230
+ 'already installed changes nothing. An agent carries it once its "skills" list names\n' +
231
+ 'the slug (firefunc agents update <agent> --spec …).',
232
+ positional: { min: 1, max: 1 },
233
+ async run(ctx) {
234
+ const slug = ctx.args.positional[0];
235
+ const body = await ctx
236
+ .api()
237
+ .post('/api/v1/skills/install', { slug });
238
+ if (ctx.json)
239
+ return printJson(ctx.io, body);
240
+ const s = body?.skill ?? { slug };
241
+ ctx.io.stdout.write(body?.installed === false
242
+ ? `${skillName(s)} was already installed; nothing changed.\n`
243
+ : `Installed ${skillName(s)}. An agent carries it once its skills list names "${text(s.slug)}".\n`);
244
+ },
245
+ },
246
+ {
247
+ path: ['skills', 'create'],
248
+ summary: "Write a skill of the workspace's own from a SKILL.md or JSON",
249
+ usage: 'skills create --file <SKILL.md | skill.json> [--slug <slug>] [--name <name>] [--description <text>]',
250
+ details: `${NEEDS_CONFIGURE}\n` +
251
+ 'From a SKILL.md: the whole file is the content, and its frontmatter gives the name and\n' +
252
+ 'the description (the flags win). A file without frontmatter gets it from --name and\n' +
253
+ '--description. From JSON: { "slug", "name", "description", "content" }.\n' +
254
+ 'The slug is --slug, else the name made into one (lower-case, hyphens) — it is how an\n' +
255
+ 'agent names the skill. A slug already installed is refused: change that one with\n' +
256
+ '"firefunc skills update".',
257
+ flags: { file: 'string', slug: 'string', name: 'string', description: 'string' },
258
+ flagHelp: [
259
+ ['--file <path>', 'a SKILL.md or a JSON skill ("-" for stdin)'],
260
+ ['--slug <slug>', 'how agents name it (2-64 lower-case letters, digits, hyphens)'],
261
+ ['--name <name>', 'what people call it'],
262
+ ['--description <text>', 'the one line the engine reads to decide when it applies'],
263
+ ],
264
+ async run(ctx) {
265
+ const send = await skillFromFile(ctx, requireFile(ctx), true);
266
+ const body = await ctx.api().post('/api/v1/skills', send);
267
+ if (ctx.json)
268
+ return printJson(ctx.io, body);
269
+ const s = body?.skill ?? {};
270
+ ctx.io.stdout.write(`Wrote the skill ${skillName(s)} (id ${text(s.id)}). An agent carries it once its skills list names "${text(s.slug)}".\n`);
271
+ },
272
+ },
273
+ {
274
+ path: ['skills', 'update'],
275
+ summary: 'Change an installed skill (name, description or content)',
276
+ usage: 'skills update <slug or id> [--file <SKILL.md | changes.json>] [--name <name>] [--description <text>]',
277
+ details: `${NEEDS_CONFIGURE}\n` +
278
+ 'Sends only what you pass. From a SKILL.md, the content is the whole file and its\n' +
279
+ 'frontmatter name and description go with it; from JSON, the fields in it. Every agent\n' +
280
+ 'that carries the skill gets the change in its next run.',
281
+ flags: { file: 'string', name: 'string', description: 'string' },
282
+ flagHelp: [
283
+ ['--file <path>', 'a SKILL.md or JSON with the fields to change ("-" for stdin)'],
284
+ ['--name <name>', 'a new name'],
285
+ ['--description <text>', 'a new one-line description'],
286
+ ],
287
+ positional: { min: 1, max: 1 },
288
+ async run(ctx) {
289
+ const ref = ctx.args.positional[0];
290
+ const path = str(ctx.args, 'file');
291
+ const send = path ? await skillFromFile(ctx, path, false) : {};
292
+ const name = str(ctx.args, 'name');
293
+ const description = str(ctx.args, 'description');
294
+ if (name !== undefined)
295
+ send.name = name;
296
+ if (description !== undefined)
297
+ send.description = description;
298
+ if (!Object.keys(send).length) {
299
+ throw new UsageError('Nothing to change. Pass --file <SKILL.md | changes.json>, --name or --description.', ctx.command);
300
+ }
301
+ const body = await ctx.api().patch(`/api/v1/skills/${enc(ref)}`, send);
302
+ if (ctx.json)
303
+ return printJson(ctx.io, body);
304
+ ctx.io.stdout.write(`Changed the skill ${skillName(body?.skill ?? { slug: ref })}. Every agent that carries it gets the change in its next run.\n`);
305
+ },
306
+ },
307
+ projectCommand('instructions', 'get', {
308
+ summary: "A project's standing instructions",
309
+ details: 'What every run in the project is told, after the workspace’s instructions and before\n' +
310
+ 'the agent’s own. Needs agents:read.',
311
+ want: 'the instructions',
312
+ print: printInstructions,
313
+ verb: 'Saved',
314
+ }),
315
+ projectCommand('instructions', 'set', {
316
+ summary: "Replace a project's standing instructions",
317
+ details: `${NEEDS_CONFIGURE}\n` +
318
+ 'Replaced WHOLE: a field left out (or null, or blank) is cleared — start from\n' +
319
+ '"firefunc projects instructions get <project> --json" and change what you mean to.\n' +
320
+ 'The file is { "agent", "gather", "pr_title", "pr_body", "commit" } (each up to 4000\n' +
321
+ 'characters), or the answer of "instructions get --json", whose "instructions" is used.',
322
+ want: 'the instructions',
323
+ body: (parsed, path) => {
324
+ const obj = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
325
+ if (!obj) {
326
+ throw new Refusal(`--file ${path} must hold one JSON object.`, 'Write the instructions as { "agent", "gather", "pr_title", "pr_body", "commit" }.', 'bad_file');
327
+ }
328
+ const inner = obj.instructions;
329
+ return inner && typeof inner === 'object' && !Array.isArray(inner) ? inner : obj;
330
+ },
331
+ print: printInstructions,
332
+ verb: 'Saved',
333
+ }),
334
+ projectCommand('sources', 'get', {
335
+ summary: 'What work a project claims (Jira, Linear, Sentry, Slack, Figma keys)',
336
+ details: 'Work whose key is listed here is routed to this project. Slack and Figma claims marked\n' +
337
+ '"through its bound account" are changed on that account in FireFunc. Needs agents:read.',
338
+ want: 'the sources',
339
+ print: printSources,
340
+ verb: 'Saved',
341
+ }),
342
+ projectCommand('sources', 'set', {
343
+ summary: 'Set what work a project claims',
344
+ details: `${NEEDS_CONFIGURE}\n` +
345
+ 'Merged kind by kind: a kind left out is kept, an empty list clears it. The file is\n' +
346
+ '{ "jira": [...], "linear": [...], "sentry": [...] } — Linear keys are a team key\n' +
347
+ '("ENG") or "<TEAM>/<Linear project id>". "slack" and "figma" only remove a leftover\n' +
348
+ 'claim. A key another project claims is refused with the project to take it from.\n' +
349
+ 'The answer of "sources get --json" round-trips (its "sources" is used).',
350
+ want: 'the sources',
351
+ body: (parsed, path) => {
352
+ const obj = parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
353
+ if (!obj) {
354
+ throw new Refusal(`--file ${path} must hold one JSON object.`, 'Write the sources as { "jira": [...], "linear": [...], "sentry": [...] }.', 'bad_file');
355
+ }
356
+ const inner = obj.sources;
357
+ if (!inner || typeof inner !== 'object' || Array.isArray(inner))
358
+ return obj;
359
+ const send = { ...inner };
360
+ if (Array.isArray(obj.claimedThroughBinding)) {
361
+ for (const k of obj.claimedThroughBinding)
362
+ delete send[String(k)];
363
+ }
364
+ return send;
365
+ },
366
+ print: printSources,
367
+ verb: 'Saved',
368
+ }),
369
+ projectCommand('repos', 'get', {
370
+ summary: "A project's repositories, and the ones its GitHub account can see",
371
+ details: 'The repositories its agents may work in and its GitHub work is routed by, its primary\n' +
372
+ 'one, the updatedAt to send back as expectedUpdatedAt, and the repositories the\n' +
373
+ 'project’s GitHub account can see (only those can be added). Needs agents:read.',
374
+ want: 'the repositories',
375
+ print: printRepos,
376
+ verb: 'Saved',
377
+ }),
378
+ projectCommand('repos', 'set', {
379
+ summary: "Replace a project's repositories",
380
+ details: `${NEEDS_CONFIGURE}\n` +
381
+ 'Replaced WHOLE, with the primary repository: the file is\n' +
382
+ '{ "repos": ["owner/name", ...], "primaryRepo": "owner/name", "expectedUpdatedAt": "…" }\n' +
383
+ '(or just the list, as a JSON array). primaryRepo left out is cleared. A repository\n' +
384
+ 'belongs to one project only, and one the project does not list yet must be one its\n' +
385
+ 'GitHub account can see ("repos get"). The answer of "repos get --json" round-trips:\n' +
386
+ 'its updatedAt is sent as expectedUpdatedAt, so a change made since is not overwritten.',
387
+ want: 'the repositories',
388
+ body: (parsed, path) => {
389
+ if (Array.isArray(parsed))
390
+ return { repos: parsed };
391
+ const obj = parsed && typeof parsed === 'object' ? parsed : null;
392
+ if (!obj) {
393
+ throw new Refusal(`--file ${path} must hold a JSON object or a list of repositories.`, 'Write { "repos": ["owner/name"], "primaryRepo": "owner/name" }, or ["owner/name"].', 'bad_file');
394
+ }
395
+ const send = {};
396
+ if (obj.repos !== undefined)
397
+ send.repos = obj.repos;
398
+ if (obj.primaryRepo !== undefined)
399
+ send.primaryRepo = obj.primaryRepo;
400
+ const expected = obj.expectedUpdatedAt ?? obj.updatedAt;
401
+ if (expected !== undefined)
402
+ send.expectedUpdatedAt = expected;
403
+ return send;
404
+ },
405
+ print: printRepos,
406
+ verb: 'Saved',
407
+ }),
408
+ ];
409
+ //# sourceMappingURL=configure.js.map