@phnx-labs/agents-cli 1.23.34 → 1.23.36

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 (41) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/commands/config.js +9 -7
  3. package/dist/commands/feed-watch.js +2 -1
  4. package/dist/commands/lead.js +65 -13
  5. package/dist/commands/projects.js +34 -2
  6. package/dist/lib/config-keys.d.ts +1 -1
  7. package/dist/lib/config-keys.js +6 -4
  8. package/dist/lib/device-config.js +9 -0
  9. package/dist/lib/github/project-prs.d.ts +7 -0
  10. package/dist/lib/github/project-prs.js +22 -0
  11. package/dist/lib/lead/act.d.ts +10 -0
  12. package/dist/lib/lead/act.js +119 -0
  13. package/dist/lib/lead/brief.d.ts +2 -0
  14. package/dist/lib/lead/brief.js +16 -5
  15. package/dist/lib/lead/client.d.ts +0 -3
  16. package/dist/lib/lead/client.js +1 -50
  17. package/dist/lib/lead/confirm.d.ts +12 -10
  18. package/dist/lib/lead/confirm.js +1 -0
  19. package/dist/lib/lead/events.d.ts +4 -2
  20. package/dist/lib/lead/events.js +5 -3
  21. package/dist/lib/lead/harness.d.ts +2 -3
  22. package/dist/lib/lead/harness.js +4 -4
  23. package/dist/lib/lead/host.d.ts +15 -8
  24. package/dist/lib/lead/host.js +63 -35
  25. package/dist/lib/lead/roster.d.ts +18 -0
  26. package/dist/lib/lead/roster.js +75 -0
  27. package/dist/lib/lead/shapes.d.ts +42 -0
  28. package/dist/lib/lead/shapes.js +202 -1
  29. package/dist/lib/lead/speak.d.ts +35 -0
  30. package/dist/lib/lead/speak.js +165 -0
  31. package/dist/lib/lead/store.d.ts +1 -0
  32. package/dist/lib/lead/tools.d.ts +11 -0
  33. package/dist/lib/lead/tools.js +98 -37
  34. package/dist/lib/lead/visibility.d.ts +1 -1
  35. package/dist/lib/lead/visibility.js +14 -4
  36. package/dist/lib/session/db.d.ts +1 -1
  37. package/dist/lib/session/db.js +10 -5
  38. package/dist/lib/session/session-cache.d.ts +1 -1
  39. package/dist/lib/session/session-cache.js +10 -8
  40. package/dist/lib/session/touched.js +1 -0
  41. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import type { ProjectDef } from '../projects.js';
2
+ import type { ConfirmAction } from './confirm.js';
2
3
  export declare const MAX_TASK_CHARS = 4000;
3
4
  export declare const MAX_NOTE_CHARS = 500;
4
5
  export declare const MAX_MEMORY_LINES = 60;
@@ -20,4 +21,45 @@ export declare function sendArgv(sessionId: string, text: string): string[];
20
21
  export declare function linearTasksArgv(def: ProjectDef, status: string, limit: number): string[];
21
22
  export declare function linearViewArgv(id: string): string[];
22
23
  export declare function linearCreateArgv(def: ProjectDef, title: string, description?: string): string[];
24
+ export declare const PR_VERBS: readonly ["merge", "comment", "ready", "rerun", "close"];
25
+ export type PrVerb = typeof PR_VERBS[number];
26
+ export declare function assertAttentionKey(key: string): string;
27
+ export declare function assertAnswerText(text: string): string;
28
+ export type AnswerValue = {
29
+ choice: string;
30
+ } | {
31
+ text: string;
32
+ };
33
+ export declare function answerArgv(key: string, value: AnswerValue): string[];
34
+ export declare function assertRepo(repo: string): string;
35
+ export declare function assertPrNumber(raw: string | number): number;
36
+ export declare function assertSha(sha: string): string;
37
+ export declare function prsListArgv(project: string, repo?: string): string[];
38
+ export declare function prReadArgv(project: string, repo: string, number: number): string[];
39
+ export declare function prFailureArgv(project: string, repo: string, sha: string): string[];
40
+ export interface PrAction {
41
+ repo: string;
42
+ number: number;
43
+ sha?: string;
44
+ body?: string;
45
+ runId?: number;
46
+ }
47
+ export declare function prArgv(project: string, verb: PrVerb, a: PrAction): string[];
48
+ export declare function assertHeldArgv(held: {
49
+ action: ConfirmAction;
50
+ project: string;
51
+ argv: string[];
52
+ linearArgv?: string[];
53
+ }): void;
54
+ export interface EditorTab {
55
+ sessionId?: string;
56
+ title?: string;
57
+ tab?: number;
58
+ }
59
+ export interface EditorContext {
60
+ front?: EditorTab;
61
+ tabs?: EditorTab[];
62
+ }
63
+ export declare function parseEditorContext(raw: string): EditorContext;
64
+ export declare function editorContextLines(ctx: EditorContext): string[];
23
65
  export declare function appendNote(memory: string, note: string): string;
@@ -1,3 +1,4 @@
1
+ import { isDeepStrictEqual } from 'node:util';
1
2
  import { isAgentId } from '../types.js';
2
3
  export const MAX_TASK_CHARS = 4_000;
3
4
  export const MAX_NOTE_CHARS = 500;
@@ -54,7 +55,10 @@ export function dispatchPrompt(id, title) {
54
55
  return `Work on ${id}: ${title}`;
55
56
  }
56
57
  export function runArgv(agent, prompt, project) {
57
- return ['run', assertAgent(agent), assertTask(prompt), '--headless', '-P', project, '--mode', 'edit'];
58
+ const task = assertTask(prompt);
59
+ if (task.startsWith('-'))
60
+ throw new LeadToolError('Refusing a task that starts with - (agents run would read it as a flag).');
61
+ return ['run', assertAgent(agent), task, '--headless', '-P', project, '--mode', 'edit'];
58
62
  }
59
63
  export function linearPickupArgv(id, agent) {
60
64
  return ['update', assertTicketId(id), '--pickup', '--delegate', assertAgent(agent)];
@@ -83,6 +87,203 @@ export function linearCreateArgv(def, title, description) {
83
87
  args.push('--description', assertTask(description));
84
88
  return args;
85
89
  }
90
+ const ATTENTION_KEY_RE = /^\w[^\s/]{0,127}\/[^\s/]{1,128}\/[^\s/]{1,128}$/;
91
+ const CHOICE_ID_RE = /^[\w.:-]{1,64}$/;
92
+ const REPO_RE = /^[\w.-]+\/[\w.-]+$/;
93
+ const SHA_RE = /^[0-9a-f]{7,40}$/i;
94
+ export const PR_VERBS = ['merge', 'comment', 'ready', 'rerun', 'close'];
95
+ export function assertAttentionKey(key) {
96
+ if (!ATTENTION_KEY_RE.test(key))
97
+ throw new LeadToolError(`'${key}' is not an attention key (expected <host>/<session>/<generation>, from the attention tool).`);
98
+ return key;
99
+ }
100
+ export function assertAnswerText(text) {
101
+ if (SEND_LINE_BREAK.test(text))
102
+ throw new LeadToolError('An answer must be one line.');
103
+ const body = assertTask(text.replace(SEND_CONTROL, ''));
104
+ if (SEND_SPECIAL_FIRST.test(body)) {
105
+ throw new LeadToolError('Refusing an answer that starts with /, ! or # (a slash command, shell escape or memory note in the session).');
106
+ }
107
+ return body;
108
+ }
109
+ export function answerArgv(key, value) {
110
+ assertAttentionKey(key);
111
+ if ('choice' in value) {
112
+ if (!CHOICE_ID_RE.test(value.choice))
113
+ throw new LeadToolError(`'${value.choice}' is not a choice id.`);
114
+ return ['feed', 'answer', key, '--choice', value.choice, '--json'];
115
+ }
116
+ return ['feed', 'answer', key, '--text', assertAnswerText(value.text), '--json'];
117
+ }
118
+ export function assertRepo(repo) {
119
+ if (!REPO_RE.test(repo))
120
+ throw new LeadToolError(`--repo expects owner/repo, got '${repo}'.`);
121
+ return repo;
122
+ }
123
+ export function assertPrNumber(raw) {
124
+ const n = typeof raw === 'number' ? raw : /^\d+$/.test(raw.trim()) ? Number(raw.trim()) : NaN;
125
+ if (!Number.isSafeInteger(n) || n <= 0)
126
+ throw new LeadToolError(`--number expects a positive integer, got '${raw}'.`);
127
+ return n;
128
+ }
129
+ export function assertSha(sha) {
130
+ if (!SHA_RE.test(sha))
131
+ throw new LeadToolError(`--sha expects a commit SHA, got '${sha}'.`);
132
+ return sha;
133
+ }
134
+ export function prsListArgv(project, repo) {
135
+ return ['projects', 'prs', 'list', project, '--json', ...(repo !== undefined ? ['--repo', assertRepo(repo)] : [])];
136
+ }
137
+ export function prReadArgv(project, repo, number) {
138
+ return ['projects', 'prs', 'list', project, '--json', '--repo', assertRepo(repo), '--number', String(assertPrNumber(number))];
139
+ }
140
+ export function prFailureArgv(project, repo, sha) {
141
+ return ['projects', 'prs', 'failure', project, '--repo', assertRepo(repo), '--sha', assertSha(sha), '--json'];
142
+ }
143
+ export function prArgv(project, verb, a) {
144
+ const base = ['projects', 'prs', verb, project, '--repo', assertRepo(a.repo)];
145
+ switch (verb) {
146
+ case 'merge':
147
+ if (a.sha === undefined)
148
+ throw new LeadToolError('A merge is pinned to the head commit; it needs its SHA.');
149
+ return [...base, '--number', String(assertPrNumber(a.number)), '--sha', assertSha(a.sha), '--json'];
150
+ case 'ready':
151
+ return [...base, '--number', String(assertPrNumber(a.number)), ...(a.sha !== undefined ? ['--sha', assertSha(a.sha)] : []), '--json'];
152
+ case 'comment':
153
+ if (a.body === undefined)
154
+ throw new LeadToolError('A comment needs --body <text>.');
155
+ return [...base, '--number', String(assertPrNumber(a.number)), '--body', assertTask(a.body), '--json'];
156
+ case 'close':
157
+ return [...base, '--number', String(assertPrNumber(a.number)), '--json'];
158
+ case 'rerun':
159
+ if (a.runId === undefined || !Number.isSafeInteger(a.runId) || a.runId <= 0)
160
+ throw new LeadToolError('A re-run needs a workflow run id.');
161
+ return [...base, '--run-id', String(a.runId), '--json'];
162
+ }
163
+ }
164
+ function prActionFromArgv(argv) {
165
+ const flag = (name) => { const i = argv.indexOf(name); return i === -1 ? undefined : argv[i + 1]; };
166
+ const runId = flag('--run-id');
167
+ const number = flag('--number');
168
+ return {
169
+ repo: flag('--repo') ?? '',
170
+ number: number === undefined ? 0 : Number(number),
171
+ sha: flag('--sha'),
172
+ body: flag('--body'),
173
+ runId: runId === undefined ? undefined : Number(runId),
174
+ };
175
+ }
176
+ export function assertHeldArgv(held) {
177
+ const { action, project, argv } = held;
178
+ let rebuilt;
179
+ switch (action) {
180
+ case 'stop':
181
+ rebuilt = ['ps', 'stop', assertSessionId(argv[2] ?? '')];
182
+ break;
183
+ case 'answer':
184
+ rebuilt = answerArgv(argv[2] ?? '', argv[3] === '--choice' ? { choice: argv[4] ?? '' } : { text: argv[4] ?? '' });
185
+ break;
186
+ case 'send':
187
+ if (!(argv[6] ?? '').startsWith(SEND_LABEL))
188
+ throw new LeadToolError('A held send has lost its [Lead] label.');
189
+ rebuilt = sendArgv(assertSessionId(argv[4] ?? ''), (argv[6] ?? '').slice(SEND_LABEL.length));
190
+ break;
191
+ case 'start':
192
+ case 'dispatch':
193
+ rebuilt = runArgv(argv[1] ?? '', argv[2] ?? '', project);
194
+ break;
195
+ case 'pr': {
196
+ const verb = argv[2];
197
+ if (!PR_VERBS.includes(verb))
198
+ throw new LeadToolError(`'${verb}' is not a PR action the Lead may hold.`);
199
+ rebuilt = prArgv(project, verb, prActionFromArgv(argv));
200
+ break;
201
+ }
202
+ }
203
+ if (!isDeepStrictEqual(argv, rebuilt))
204
+ throw new LeadToolError(`The held ${action} is not one of its fixed shapes; nothing was run.`);
205
+ const linear = held.linearArgv;
206
+ if (action === 'dispatch') {
207
+ if (!linear || !isDeepStrictEqual(linear, linearPickupArgv(linear[1] ?? '', linear[4] ?? ''))) {
208
+ throw new LeadToolError('The held dispatch has no valid ticket pickup; nothing was run.');
209
+ }
210
+ }
211
+ else if (linear !== undefined) {
212
+ throw new LeadToolError(`A held ${action} carries a ticket pickup it never has; nothing was run.`);
213
+ }
214
+ }
215
+ const MAX_CONTEXT_TABS = 60;
216
+ const MAX_CONTEXT_TITLE = 200;
217
+ const CONTEXT_SESSION_RE = /^[\w-]{1,64}$/;
218
+ function contextTab(raw, where) {
219
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
220
+ throw new LeadToolError(`--context: ${where} must be an object.`);
221
+ const out = {};
222
+ for (const [key, value] of Object.entries(raw)) {
223
+ if (key === 'sessionId') {
224
+ if (typeof value !== 'string' || !CONTEXT_SESSION_RE.test(value))
225
+ throw new LeadToolError(`--context: ${where}.sessionId must be a session id.`);
226
+ out.sessionId = value;
227
+ }
228
+ else if (key === 'title') {
229
+ if (typeof value !== 'string')
230
+ throw new LeadToolError(`--context: ${where}.title must be a string.`);
231
+ const title = value.replace(SEND_CONTROL, ' ').replace(/\s+/g, ' ').trim().slice(0, MAX_CONTEXT_TITLE);
232
+ if (title)
233
+ out.title = title;
234
+ }
235
+ else if (key === 'tab') {
236
+ if (!Number.isSafeInteger(value) || value < 1)
237
+ throw new LeadToolError(`--context: ${where}.tab must be a positive integer.`);
238
+ out.tab = value;
239
+ }
240
+ else {
241
+ throw new LeadToolError(`--context: ${where} has an unknown field '${key}' (expected sessionId, title, tab).`);
242
+ }
243
+ }
244
+ return out;
245
+ }
246
+ export function parseEditorContext(raw) {
247
+ let parsed;
248
+ try {
249
+ parsed = JSON.parse(raw);
250
+ }
251
+ catch {
252
+ throw new LeadToolError('--context expects a JSON object, e.g. {"front":{"sessionId":"…","title":"…","tab":3}}.');
253
+ }
254
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
255
+ throw new LeadToolError('--context expects a JSON object.');
256
+ const out = {};
257
+ for (const [key, value] of Object.entries(parsed)) {
258
+ if (key === 'front')
259
+ out.front = contextTab(value, 'front');
260
+ else if (key === 'tabs') {
261
+ if (!Array.isArray(value))
262
+ throw new LeadToolError('--context: tabs must be an array.');
263
+ if (value.length > MAX_CONTEXT_TABS)
264
+ throw new LeadToolError(`--context: at most ${MAX_CONTEXT_TABS} tabs.`);
265
+ out.tabs = value.map((t, i) => contextTab(t, `tabs[${i}]`));
266
+ }
267
+ else
268
+ throw new LeadToolError(`--context has an unknown field '${key}' (expected front, tabs).`);
269
+ }
270
+ return out;
271
+ }
272
+ function describeTab(t) {
273
+ return [
274
+ t.tab !== undefined ? `tab ${t.tab}` : null,
275
+ t.title ? `“${t.title}”` : null,
276
+ t.sessionId ? `(session ${t.sessionId.slice(0, 8)})` : null,
277
+ ].filter(Boolean).join(' ') || 'a tab with no session';
278
+ }
279
+ export function editorContextLines(ctx) {
280
+ const lines = [];
281
+ if (ctx.front)
282
+ lines.push(`Front tab (what "this one" means): ${describeTab(ctx.front)}`);
283
+ if (ctx.tabs?.length)
284
+ lines.push(`Open tabs: ${ctx.tabs.map(describeTab).join('; ')}`);
285
+ return lines;
286
+ }
86
287
  export function appendNote(memory, note) {
87
288
  const clean = note.replace(/\s+/g, ' ').trim();
88
289
  if (!clean)
@@ -0,0 +1,35 @@
1
+ import type { LeadEvent } from './events.js';
2
+ export declare const VOICE_MODEL = "eleven_turbo_v2_5";
3
+ export declare const VOICE_ID = "JBFqnCBsd6RMkjVDRZzb";
4
+ export declare const VOICE_KEY = "ELEVENLABS_API_KEY";
5
+ export declare class SentenceSplitter {
6
+ private buf;
7
+ push(delta: string): string[];
8
+ flush(): string[];
9
+ }
10
+ export declare function speakable(sentence: string): string | null;
11
+ export declare function playerArgv(file: string, platform?: NodeJS.Platform): string[];
12
+ export declare function voiceBundle(): string;
13
+ export interface SpeakerOptions {
14
+ apiKey: Promise<string>;
15
+ baseUrl?: string;
16
+ player?: (file: string) => string[];
17
+ onError?: (line: string) => void;
18
+ }
19
+ export declare class LeadSpeaker {
20
+ private readonly opts;
21
+ private readonly splitter;
22
+ private readonly dir;
23
+ private chain;
24
+ private clips;
25
+ private sawText;
26
+ private dead;
27
+ constructor(opts: SpeakerOptions);
28
+ static start(): LeadSpeaker | null;
29
+ onEvent(e: LeadEvent): void;
30
+ drain(): Promise<void>;
31
+ private fail;
32
+ private say;
33
+ private synthesize;
34
+ private play;
35
+ }
@@ -0,0 +1,165 @@
1
+ import * as fs from 'node:fs';
2
+ import * as os from 'node:os';
3
+ import * as path from 'node:path';
4
+ import { spawn } from 'node:child_process';
5
+ import { configKeySpec, getConfigValue } from '../device-config.js';
6
+ export const VOICE_MODEL = 'eleven_turbo_v2_5';
7
+ export const VOICE_ID = 'JBFqnCBsd6RMkjVDRZzb';
8
+ export const VOICE_KEY = 'ELEVENLABS_API_KEY';
9
+ const ELEVENLABS_URL = 'https://api.elevenlabs.io';
10
+ const SYNTH_TIMEOUT_MS = 20_000;
11
+ const PLAY_TIMEOUT_MS = 60_000;
12
+ const BOUNDARY = /[.!?…]+["”’')\]]*(?=\s)|\n+/g;
13
+ const ABBREVIATION = /(?:^|\s)(?:e\.g|i\.e|etc|vs|approx|Mr|Mrs|Ms|Dr|St|No)\.$/i;
14
+ const LIST_MARKER = /^\W*(?:\d+|[a-z])[.)]$/i;
15
+ export class SentenceSplitter {
16
+ buf = '';
17
+ push(delta) {
18
+ this.buf += delta;
19
+ const out = [];
20
+ let from = 0;
21
+ BOUNDARY.lastIndex = 0;
22
+ for (let m = BOUNDARY.exec(this.buf); m; m = BOUNDARY.exec(this.buf)) {
23
+ const end = m.index + m[0].length;
24
+ const candidate = this.buf.slice(from, end).trim();
25
+ if (!m[0].startsWith('\n') && (ABBREVIATION.test(candidate) || LIST_MARKER.test(candidate)))
26
+ continue;
27
+ if (candidate)
28
+ out.push(candidate);
29
+ from = end;
30
+ }
31
+ this.buf = this.buf.slice(from);
32
+ return out;
33
+ }
34
+ flush() {
35
+ const rest = this.buf.trim();
36
+ this.buf = '';
37
+ return rest ? [rest] : [];
38
+ }
39
+ }
40
+ export function speakable(sentence) {
41
+ const text = sentence
42
+ .replace(/https?:\/\/\S+/g, '')
43
+ .replace(/`([^`]*)`/g, '$1')
44
+ .replace(/[*_>|~]+|#+(?!\d)/g, ' ')
45
+ .replace(/^\s*[-•]\s+/, '')
46
+ .replace(/\s+/g, ' ')
47
+ .trim();
48
+ return /[\p{L}\p{N}]/u.test(text) ? text : null;
49
+ }
50
+ export function playerArgv(file, platform = process.platform) {
51
+ return platform === 'darwin' ? ['afplay', file] : ['ffplay', '-nodisp', '-autoexit', '-loglevel', 'quiet', file];
52
+ }
53
+ export function voiceBundle() {
54
+ const value = getConfigValue('lead.voice.bundle').value;
55
+ return typeof value === 'string' && value.length > 0 ? value : String(configKeySpec('lead.voice.bundle').defaultValue);
56
+ }
57
+ async function readVoiceKey(bundle) {
58
+ const [{ readAndResolveBundleEnv }, { resolveSecretsContextForRun }] = await Promise.all([
59
+ import('../secrets-client.js'),
60
+ import('../secrets-policy.js'),
61
+ ]);
62
+ const { env } = await readAndResolveBundleEnv(bundle, { caller: 'agents lead ask --speak', keys: [VOICE_KEY] }, await resolveSecretsContextForRun());
63
+ const key = env[VOICE_KEY];
64
+ if (!key)
65
+ throw new Error(`secrets bundle '${bundle}' has no ${VOICE_KEY}`);
66
+ return key;
67
+ }
68
+ export class LeadSpeaker {
69
+ opts;
70
+ splitter = new SentenceSplitter();
71
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'agents-lead-speak-'));
72
+ chain = Promise.resolve();
73
+ clips = 0;
74
+ sawText = false;
75
+ dead = false;
76
+ constructor(opts) {
77
+ this.opts = opts;
78
+ opts.apiKey.catch((err) => this.fail(err));
79
+ }
80
+ static start() {
81
+ try {
82
+ return new LeadSpeaker({ apiKey: readVoiceKey(voiceBundle()) });
83
+ }
84
+ catch (err) {
85
+ process.stderr.write(`voice: ${err instanceof Error ? err.message : String(err)}; the reply is not spoken.\n`);
86
+ return null;
87
+ }
88
+ }
89
+ onEvent(e) {
90
+ if (e.type === 'text') {
91
+ this.sawText = true;
92
+ for (const s of this.splitter.push(e.delta))
93
+ this.say(s);
94
+ }
95
+ else if (e.type === 'done') {
96
+ const rest = this.sawText ? this.splitter.flush() : [...this.splitter.push(e.text), ...this.splitter.flush()];
97
+ for (const s of rest)
98
+ this.say(s);
99
+ }
100
+ else if (e.type === 'error') {
101
+ for (const s of this.splitter.flush())
102
+ this.say(s);
103
+ }
104
+ }
105
+ async drain() {
106
+ await this.chain;
107
+ fs.rmSync(this.dir, { recursive: true, force: true });
108
+ }
109
+ fail(err) {
110
+ if (this.dead)
111
+ return;
112
+ this.dead = true;
113
+ (this.opts.onError ?? ((line) => process.stderr.write(`${line}\n`)))(`voice: ${err instanceof Error ? err.message : String(err)}; the reply is not spoken.`);
114
+ }
115
+ say(sentence) {
116
+ const text = speakable(sentence);
117
+ if (!text || this.dead)
118
+ return;
119
+ const file = path.join(this.dir, `${String(++this.clips).padStart(3, '0')}.mp3`);
120
+ const audio = this.synthesize(text, file);
121
+ audio.catch(() => { });
122
+ this.chain = this.chain.then(async () => {
123
+ if (this.dead)
124
+ return;
125
+ try {
126
+ await audio;
127
+ await this.play(file);
128
+ }
129
+ catch (err) {
130
+ this.fail(err);
131
+ }
132
+ finally {
133
+ fs.rmSync(file, { force: true });
134
+ }
135
+ });
136
+ }
137
+ async synthesize(text, file) {
138
+ const key = await this.opts.apiKey;
139
+ const url = `${this.opts.baseUrl ?? ELEVENLABS_URL}/v1/text-to-speech/${VOICE_ID}?output_format=mp3_44100_128`;
140
+ const res = await fetch(url, {
141
+ method: 'POST',
142
+ headers: { 'xi-api-key': key, 'content-type': 'application/json', accept: 'audio/mpeg' },
143
+ body: JSON.stringify({ text, model_id: VOICE_MODEL }),
144
+ signal: AbortSignal.timeout(SYNTH_TIMEOUT_MS),
145
+ });
146
+ if (!res.ok)
147
+ throw new Error(`ElevenLabs answered HTTP ${res.status}`);
148
+ fs.writeFileSync(file, Buffer.from(await res.arrayBuffer()), { mode: 0o600 });
149
+ }
150
+ play(file) {
151
+ const [command, ...args] = (this.opts.player ?? playerArgv)(file);
152
+ return new Promise((resolve, reject) => {
153
+ const child = spawn(command, args, { stdio: 'ignore' });
154
+ const timer = setTimeout(() => child.kill('SIGKILL'), PLAY_TIMEOUT_MS);
155
+ child.on('error', (err) => { clearTimeout(timer); reject(err.code === 'ENOENT' ? new Error(`${command} is not installed`) : err); });
156
+ child.on('exit', (code, signal) => {
157
+ clearTimeout(timer);
158
+ if (code === 0)
159
+ resolve();
160
+ else
161
+ reject(new Error(signal === 'SIGKILL' ? `${command} did not finish within ${PLAY_TIMEOUT_MS / 1000}s` : `${command} exited ${code}`));
162
+ });
163
+ });
164
+ }
165
+ }
@@ -8,6 +8,7 @@ export interface LeadSessionState {
8
8
  turns: number;
9
9
  briefed: boolean;
10
10
  brief: string[];
11
+ rules?: string;
11
12
  contextTokens?: number;
12
13
  contextWindow?: number;
13
14
  lastTurnAtMs?: number;
@@ -1,4 +1,5 @@
1
1
  import { type ProjectDef } from '../projects.js';
2
+ import { type AnswerValue, type PrVerb } from './shapes.js';
2
3
  import { type LeadPaths } from './paths.js';
3
4
  export * from './shapes.js';
4
5
  export interface LeadToolContext {
@@ -8,10 +9,20 @@ export interface LeadToolContext {
8
9
  }
9
10
  export declare function leadToolContext(env?: NodeJS.ProcessEnv): LeadToolContext;
10
11
  export declare function toolRoster(ctx: LeadToolContext, project?: string): Promise<string>;
12
+ export declare function toolAttention(ctx: LeadToolContext): Promise<string>;
11
13
  export declare function toolDispatch(ctx: LeadToolContext, ticket: string, agent: string): Promise<string>;
12
14
  export declare function toolStart(ctx: LeadToolContext, agent: string, task: string): Promise<string>;
13
15
  export declare function toolSend(ctx: LeadToolContext, session: string, text: string): Promise<string>;
16
+ export declare function toolAnswer(ctx: LeadToolContext, key: string, value: AnswerValue): Promise<string>;
14
17
  export declare function toolStop(ctx: LeadToolContext, session: string): Promise<string>;
18
+ export declare function toolPrsList(ctx: LeadToolContext, repo?: string): Promise<string>;
19
+ export declare function toolPrAct(ctx: LeadToolContext, verb: PrVerb, opts: {
20
+ repo: string;
21
+ number: string;
22
+ sha?: string;
23
+ body?: string;
24
+ runId?: string;
25
+ }): Promise<string>;
15
26
  export declare function toolLinearTasks(ctx: LeadToolContext, status: string, limit: number): Promise<string>;
16
27
  export declare function toolLinearView(id: string): Promise<string>;
17
28
  export declare function toolLinearCreate(ctx: LeadToolContext, title: string, description?: string): Promise<string>;