@phnx-labs/agents-cli 1.23.20 → 1.23.22
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/CHANGELOG.md +126 -0
- package/README.md +17 -0
- package/dist/bootstrap.js +5 -4
- package/dist/cli/command-registry.js +2 -0
- package/dist/commands/config.js +16 -0
- package/dist/commands/daemon.js +3 -3
- package/dist/commands/doctor.js +10 -19
- package/dist/commands/events.js +1 -14
- package/dist/commands/feed-watch.js +5 -2
- package/dist/commands/go.js +2 -2
- package/dist/commands/lead.d.ts +3 -0
- package/dist/commands/lead.js +280 -0
- package/dist/commands/projects.js +3 -2
- package/dist/commands/ps-roster.d.ts +2 -12
- package/dist/commands/ps-roster.js +5 -87
- package/dist/commands/ps.js +3 -1
- package/dist/commands/repo.js +12 -12
- package/dist/commands/resource-view.js +5 -5
- package/dist/commands/sessions-browser.js +2 -2
- package/dist/commands/sessions-watch.js +5 -2
- package/dist/commands/setup-secrets.d.ts +3 -4
- package/dist/commands/setup-secrets.js +15 -46
- package/dist/commands/setup-session-backup.js +1 -1
- package/dist/commands/ssh.d.ts +0 -4
- package/dist/commands/ssh.js +14 -81
- package/dist/commands/teams-picker.js +1 -12
- package/dist/commands/teams.js +1 -13
- package/dist/commands/view.d.ts +1 -40
- package/dist/commands/view.js +9 -330
- package/dist/commands/watchdog.js +4 -4
- package/dist/index.js +4 -0
- package/dist/lib/accounting/usage.d.ts +0 -1
- package/dist/lib/accounting/usage.js +1 -112
- package/dist/lib/accounts/add.js +1 -1
- package/dist/lib/accounts/migrate.js +1 -1
- package/dist/lib/auto-pull-worker.js +2 -16
- package/dist/lib/auto-pull.d.ts +1 -0
- package/dist/lib/auto-pull.js +27 -0
- package/dist/lib/browser-client.js +2 -11
- package/dist/lib/cloud/codex.js +3 -0
- package/dist/lib/commands.d.ts +0 -6
- package/dist/lib/commands.js +3 -116
- package/dist/lib/comms-render.d.ts +1 -7
- package/dist/lib/comms-render.js +0 -19
- package/dist/lib/computer-client.js +2 -11
- package/dist/lib/config-keys.d.ts +7 -3
- package/dist/lib/config-keys.js +15 -2
- package/dist/lib/crabbox/runtimes.d.ts +0 -14
- package/dist/lib/crabbox/runtimes.js +0 -80
- package/dist/lib/daemon/attention-notify-service.d.ts +51 -28
- package/dist/lib/daemon/attention-notify-service.js +219 -53
- package/dist/lib/daemon/daemon.js +1 -2
- package/dist/lib/daemon/feed-stream-service.js +2 -4
- package/dist/lib/device-config.d.ts +0 -5
- package/dist/lib/device-config.js +20 -27
- package/dist/lib/devices/doctor-findings.d.ts +2 -1
- package/dist/lib/devices/doctor-findings.js +12 -1
- package/dist/lib/devices/fleet.d.ts +6 -0
- package/dist/lib/devices/fleet.js +15 -0
- package/dist/lib/devices/harness-inventory.d.ts +9 -0
- package/dist/lib/devices/harness-inventory.js +66 -0
- package/dist/lib/exec.js +1 -3
- package/dist/lib/feed/attention.d.ts +16 -1
- package/dist/lib/feed/attention.js +63 -1
- package/dist/lib/feed/feed.d.ts +1 -1
- package/dist/lib/feed/feed.js +12 -2
- package/dist/lib/feed/hub.d.ts +9 -0
- package/dist/lib/feed/hub.js +27 -1
- package/dist/lib/feed/notify-schedule.d.ts +16 -0
- package/dist/lib/feed/notify-schedule.js +62 -0
- package/dist/lib/feed/ticket-priority.d.ts +4 -0
- package/dist/lib/feed/ticket-priority.js +30 -0
- package/dist/lib/feed/watch.d.ts +1 -0
- package/dist/lib/feed/watch.js +27 -3
- package/dist/lib/feed-ranking.d.ts +1 -0
- package/dist/lib/feed-ranking.js +3 -1
- package/dist/lib/format.d.ts +0 -2
- package/dist/lib/format.js +0 -8
- package/dist/lib/github/open-prs.d.ts +0 -2
- package/dist/lib/github/open-prs.js +17 -35
- package/dist/lib/github/project-prs.d.ts +5 -0
- package/dist/lib/github/project-prs.js +73 -32
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hooks/cache.d.ts +1 -0
- package/dist/lib/hooks/cache.js +12 -1
- package/dist/lib/installations/duplicate-prune.d.ts +37 -0
- package/dist/lib/installations/duplicate-prune.js +85 -0
- package/dist/lib/installations/inventory-json.d.ts +20 -0
- package/dist/lib/installations/inventory-json.js +252 -0
- package/dist/lib/installations/shims.d.ts +0 -18
- package/dist/lib/installations/shims.js +1 -257
- package/dist/lib/lead/brief.d.ts +49 -0
- package/dist/lib/lead/brief.js +173 -0
- package/dist/lib/lead/client.d.ts +21 -0
- package/dist/lib/lead/client.js +167 -0
- package/dist/lib/lead/confirm.d.ts +22 -0
- package/dist/lib/lead/confirm.js +73 -0
- package/dist/lib/lead/events.d.ts +106 -0
- package/dist/lib/lead/events.js +188 -0
- package/dist/lib/lead/harness.d.ts +29 -0
- package/dist/lib/lead/harness.js +107 -0
- package/dist/lib/lead/host.d.ts +132 -0
- package/dist/lib/lead/host.js +675 -0
- package/dist/lib/lead/paths.d.ts +22 -0
- package/dist/lib/lead/paths.js +69 -0
- package/dist/lib/lead/refs.d.ts +17 -0
- package/dist/lib/lead/refs.js +75 -0
- package/dist/lib/lead/roster.d.ts +26 -0
- package/dist/lib/lead/roster.js +121 -0
- package/dist/lib/lead/shapes.d.ts +23 -0
- package/dist/lib/lead/shapes.js +95 -0
- package/dist/lib/lead/store.d.ts +46 -0
- package/dist/lib/lead/store.js +77 -0
- package/dist/lib/lead/tools.d.ts +18 -0
- package/dist/lib/lead/tools.js +106 -0
- package/dist/lib/lead/visibility.d.ts +16 -0
- package/dist/lib/lead/visibility.js +77 -0
- package/dist/lib/mailbox.d.ts +0 -18
- package/dist/lib/mailbox.js +0 -170
- package/dist/lib/menubar/notify-desktop.d.ts +5 -0
- package/dist/lib/menubar/notify-desktop.js +24 -0
- package/dist/lib/models.js +1 -19
- package/dist/lib/permissions.d.ts +0 -6
- package/dist/lib/permissions.js +0 -140
- package/dist/lib/platform/process.d.ts +1 -0
- package/dist/lib/platform/process.js +5 -0
- package/dist/lib/probe.js +13 -1
- package/dist/lib/project-status.js +4 -3
- package/dist/lib/projects.d.ts +9 -0
- package/dist/lib/projects.js +61 -3
- package/dist/lib/scheduling/routines.d.ts +1 -13
- package/dist/lib/scheduling/routines.js +1 -37
- package/dist/lib/secrets-cli.d.ts +3 -3
- package/dist/lib/secrets-cli.js +1 -1
- package/dist/lib/secrets-client.d.ts +4 -37
- package/dist/lib/secrets-client.js +19 -265
- package/dist/lib/session/active.d.ts +18 -8
- package/dist/lib/session/active.js +94 -18
- package/dist/lib/session/db.d.ts +0 -16
- package/dist/lib/session/db.js +1 -134
- package/dist/lib/session/detached.d.ts +0 -1
- package/dist/lib/session/detached.js +0 -18
- package/dist/lib/session/pending-work.d.ts +21 -0
- package/dist/lib/session/pending-work.js +284 -0
- package/dist/lib/session/remote/remote-list.d.ts +0 -3
- package/dist/lib/session/remote/remote-list.js +1 -23
- package/dist/lib/session/remote/watch.d.ts +5 -0
- package/dist/lib/session/remote/watch.js +19 -2
- package/dist/lib/session/session-cache.d.ts +1 -1
- package/dist/lib/session/session-cache.js +12 -5
- package/dist/lib/session/sync/provision.js +1 -2
- package/dist/lib/smart-launch.js +7 -2
- package/dist/lib/snapshot.js +3 -4
- package/dist/lib/ssh-exec.d.ts +0 -40
- package/dist/lib/ssh-exec.js +0 -108
- package/dist/lib/ssh-tunnel.d.ts +0 -6
- package/dist/lib/ssh-tunnel.js +0 -42
- package/dist/lib/standalone-tools.js +12 -1
- package/dist/lib/startup/command-registry.js +1 -1
- package/dist/lib/startup/spellcheck.d.ts +0 -1
- package/dist/lib/startup/spellcheck.js +1 -20
- package/dist/lib/state.d.ts +0 -6
- package/dist/lib/state.js +1 -14
- package/dist/lib/teams/delivery.d.ts +1 -0
- package/dist/lib/teams/delivery.js +13 -0
- package/dist/lib/types.d.ts +0 -37
- package/dist/lib/types.js +0 -9
- package/dist/lib/watchdog/log.d.ts +1 -1
- package/dist/lib/watchdog/log.js +6 -4
- package/package.json +2 -1
- package/dist/lib/artifact-actions.d.ts +0 -7
- package/dist/lib/artifact-actions.js +0 -39
- package/dist/lib/session/sync/managed-config.d.ts +0 -3
- package/dist/lib/session/sync/managed-config.js +0 -3
- package/dist/lib/session/sync/worker-template.d.ts +0 -1
- package/dist/lib/session/sync/worker-template.js +0 -807
- package/dist/lib/storage/selection.d.ts +0 -8
- package/dist/lib/storage/selection.js +0 -10
- package/dist/lib/watchdog/index.d.ts +0 -3
- package/dist/lib/watchdog/index.js +0 -3
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export const ROTATE_AT_FRACTION = 0.6;
|
|
2
|
+
const LEAD_TOOL_RE = /^\s*agents\s+lead\s+tool\s+([a-z]+)/;
|
|
3
|
+
const HELD_TOOLS = new Set(['stop']);
|
|
4
|
+
export function toolLabel(command) {
|
|
5
|
+
const lead = LEAD_TOOL_RE.exec(command);
|
|
6
|
+
if (lead)
|
|
7
|
+
return lead[1];
|
|
8
|
+
const words = command.trim().split(/\s+/);
|
|
9
|
+
return words[0] || 'Bash';
|
|
10
|
+
}
|
|
11
|
+
export function isHeldCommand(command) {
|
|
12
|
+
const lead = LEAD_TOOL_RE.exec(command);
|
|
13
|
+
return lead !== null && HELD_TOOLS.has(lead[1]);
|
|
14
|
+
}
|
|
15
|
+
function round2(n) {
|
|
16
|
+
return Math.round(n * 100) / 100;
|
|
17
|
+
}
|
|
18
|
+
function mergedSeconds(spans) {
|
|
19
|
+
const sorted = [...spans].sort((a, b) => a[0] - b[0]);
|
|
20
|
+
let total = 0;
|
|
21
|
+
let curStart = -1;
|
|
22
|
+
let curEnd = -1;
|
|
23
|
+
for (const [s, e] of sorted) {
|
|
24
|
+
if (s > curEnd) {
|
|
25
|
+
if (curEnd > curStart)
|
|
26
|
+
total += curEnd - curStart;
|
|
27
|
+
curStart = s;
|
|
28
|
+
curEnd = e;
|
|
29
|
+
}
|
|
30
|
+
else if (e > curEnd) {
|
|
31
|
+
curEnd = e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (curEnd > curStart)
|
|
35
|
+
total += curEnd - curStart;
|
|
36
|
+
return total / 1000;
|
|
37
|
+
}
|
|
38
|
+
function usageTokens(u) {
|
|
39
|
+
const n = (k) => (typeof u[k] === 'number' ? u[k] : 0);
|
|
40
|
+
return n('input_tokens') + n('cache_creation_input_tokens') + n('cache_read_input_tokens') + n('output_tokens');
|
|
41
|
+
}
|
|
42
|
+
export function contextUsageFromResult(result) {
|
|
43
|
+
const usage = result.usage;
|
|
44
|
+
const modelUsage = result.modelUsage;
|
|
45
|
+
if (!usage || !modelUsage)
|
|
46
|
+
return null;
|
|
47
|
+
const windows = Object.values(modelUsage).map((m) => m.contextWindow).filter((w) => typeof w === 'number' && w > 0);
|
|
48
|
+
if (windows.length === 0)
|
|
49
|
+
return null;
|
|
50
|
+
const iterations = Array.isArray(usage.iterations) ? usage.iterations : [];
|
|
51
|
+
const last = iterations.length > 0 ? iterations[iterations.length - 1] : usage;
|
|
52
|
+
return { tokens: usageTokens(last), window: Math.max(...windows) };
|
|
53
|
+
}
|
|
54
|
+
export function shouldRotate(usage, threshold = ROTATE_AT_FRACTION) {
|
|
55
|
+
if (!usage)
|
|
56
|
+
return false;
|
|
57
|
+
return usage.tokens / usage.window >= threshold;
|
|
58
|
+
}
|
|
59
|
+
export function summarize(text, max = 80) {
|
|
60
|
+
const plain = text
|
|
61
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
62
|
+
.replace(/`([^`]*)`/g, '$1')
|
|
63
|
+
.replace(/\*\*([^*]*)\*\*/g, '$1')
|
|
64
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
65
|
+
.split('\n')
|
|
66
|
+
.map((line) => line.replace(/^\s*(?:[-*+]|\d+\.|#+)\s+/, '').trim())
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join(' ')
|
|
69
|
+
.replace(/\s+/g, ' ')
|
|
70
|
+
.trim();
|
|
71
|
+
const match = /^.*?[.!?](?=\s|$)/.exec(plain);
|
|
72
|
+
const sentence = (match ? match[0] : plain).trim();
|
|
73
|
+
if (sentence.length <= max)
|
|
74
|
+
return sentence;
|
|
75
|
+
const cut = sentence.slice(0, max - 1);
|
|
76
|
+
const space = cut.lastIndexOf(' ');
|
|
77
|
+
return `${(space > max / 2 ? cut.slice(0, space) : cut).replace(/[\s,;:]+$/, '')}…`;
|
|
78
|
+
}
|
|
79
|
+
export class LeadTurnParser {
|
|
80
|
+
status = null;
|
|
81
|
+
tools = new Map();
|
|
82
|
+
held = new Set();
|
|
83
|
+
spans = [];
|
|
84
|
+
streamedText = false;
|
|
85
|
+
feed(msg, nowMs) {
|
|
86
|
+
const out = [];
|
|
87
|
+
const type = msg.type;
|
|
88
|
+
if (type === 'system' && msg.subtype === 'init' && typeof msg.session_id === 'string') {
|
|
89
|
+
out.push({ kind: 'init', sessionId: msg.session_id });
|
|
90
|
+
}
|
|
91
|
+
else if (type === 'stream_event') {
|
|
92
|
+
this.onStreamEvent(msg.event, out);
|
|
93
|
+
}
|
|
94
|
+
else if (type === 'assistant') {
|
|
95
|
+
this.onAssistant(msg, nowMs, out);
|
|
96
|
+
}
|
|
97
|
+
else if (type === 'user') {
|
|
98
|
+
this.onUser(msg, nowMs, out);
|
|
99
|
+
}
|
|
100
|
+
else if (type === 'result') {
|
|
101
|
+
out.push({
|
|
102
|
+
kind: 'result',
|
|
103
|
+
result: {
|
|
104
|
+
text: typeof msg.result === 'string' ? msg.result : '',
|
|
105
|
+
isError: msg.is_error === true || (typeof msg.subtype === 'string' && msg.subtype !== 'success'),
|
|
106
|
+
usage: contextUsageFromResult(msg),
|
|
107
|
+
sessionId: typeof msg.session_id === 'string' ? msg.session_id : undefined,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
toolSeconds() {
|
|
114
|
+
return round2(mergedSeconds(this.spans));
|
|
115
|
+
}
|
|
116
|
+
setStatus(state, out) {
|
|
117
|
+
if (this.status === state)
|
|
118
|
+
return;
|
|
119
|
+
this.status = state;
|
|
120
|
+
out.push({ kind: 'event', event: { type: 'status', state } });
|
|
121
|
+
}
|
|
122
|
+
onStreamEvent(event, out) {
|
|
123
|
+
if (!event)
|
|
124
|
+
return;
|
|
125
|
+
if (event.type === 'message_start') {
|
|
126
|
+
this.setStatus('thinking', out);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (event.type === 'content_block_delta') {
|
|
130
|
+
const delta = event.delta;
|
|
131
|
+
if (delta?.type === 'text_delta' && typeof delta.text === 'string' && delta.text.length > 0) {
|
|
132
|
+
this.setStatus('answering', out);
|
|
133
|
+
this.streamedText = true;
|
|
134
|
+
out.push({ kind: 'event', event: { type: 'text', delta: delta.text } });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
onAssistant(msg, nowMs, out) {
|
|
139
|
+
const content = msg.message?.content;
|
|
140
|
+
if (!Array.isArray(content))
|
|
141
|
+
return;
|
|
142
|
+
for (const block of content) {
|
|
143
|
+
if (block.type === 'text' && typeof block.text === 'string' && block.text.length > 0 && !this.streamedText) {
|
|
144
|
+
this.setStatus('answering', out);
|
|
145
|
+
out.push({ kind: 'event', event: { type: 'text', delta: block.text } });
|
|
146
|
+
}
|
|
147
|
+
else if (block.type === 'tool_use' && typeof block.id === 'string') {
|
|
148
|
+
const input = (block.input ?? {});
|
|
149
|
+
const cmd = typeof input.command === 'string' ? input.command : String(block.name ?? 'tool');
|
|
150
|
+
if (block.name === 'Bash' && isHeldCommand(cmd)) {
|
|
151
|
+
this.held.add(block.id);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const label = block.name === 'Bash' ? toolLabel(cmd) : String(block.name ?? 'tool');
|
|
155
|
+
this.tools.set(block.id, { label, startMs: nowMs });
|
|
156
|
+
this.setStatus('tool', out);
|
|
157
|
+
out.push({ kind: 'event', event: { type: 'tool', id: block.id, label, cmd, state: 'run' } });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
this.streamedText = false;
|
|
161
|
+
}
|
|
162
|
+
onUser(msg, nowMs, out) {
|
|
163
|
+
const content = msg.message?.content;
|
|
164
|
+
if (!Array.isArray(content))
|
|
165
|
+
return;
|
|
166
|
+
for (const block of content) {
|
|
167
|
+
if (block.type !== 'tool_result' || typeof block.tool_use_id !== 'string')
|
|
168
|
+
continue;
|
|
169
|
+
if (this.held.has(block.tool_use_id))
|
|
170
|
+
continue;
|
|
171
|
+
const span = this.tools.get(block.tool_use_id);
|
|
172
|
+
if (!span)
|
|
173
|
+
continue;
|
|
174
|
+
this.tools.delete(block.tool_use_id);
|
|
175
|
+
this.spans.push([span.startMs, nowMs]);
|
|
176
|
+
out.push({
|
|
177
|
+
kind: 'event',
|
|
178
|
+
event: {
|
|
179
|
+
type: 'tool',
|
|
180
|
+
id: block.tool_use_id,
|
|
181
|
+
label: span.label,
|
|
182
|
+
state: block.is_error === true ? 'fail' : 'ok',
|
|
183
|
+
secs: round2((nowMs - span.startMs) / 1000),
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LeadPaths } from './paths.js';
|
|
2
|
+
export declare const LEAD_TOOL_NAMES: readonly ["roster", "dispatch", "start", "send", "stop", "linear", "remember"];
|
|
3
|
+
export type LeadToolName = typeof LEAD_TOOL_NAMES[number];
|
|
4
|
+
export declare const LEAD_ALLOWED_TOOLS: readonly string[];
|
|
5
|
+
export declare const LEAD_DENIED_TOOLS: readonly ["Edit", "Write", "MultiEdit", "NotebookEdit", "Read", "Glob", "Grep", "WebFetch", "WebSearch"];
|
|
6
|
+
export declare const LEAD_EFFORT = "low";
|
|
7
|
+
export declare const LEAD_ENV_PASSTHROUGH: readonly ["PATH", "HOME", "USER", "LOGNAME", "SHELL", "LANG", "LC_ALL", "TMPDIR", "XDG_RUNTIME_DIR", "TERM"];
|
|
8
|
+
export interface Launch {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
}
|
|
12
|
+
export type LeadSessionStart = {
|
|
13
|
+
mode: 'fresh';
|
|
14
|
+
sessionId: string;
|
|
15
|
+
} | {
|
|
16
|
+
mode: 'resume';
|
|
17
|
+
sessionId: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function leadModel(): string;
|
|
20
|
+
export declare function cliVersion(): string;
|
|
21
|
+
export declare function leadSettings(): Record<string, unknown>;
|
|
22
|
+
export declare function writeLeadSettings(paths: LeadPaths): string;
|
|
23
|
+
export declare function writeAgentsShim(paths: LeadPaths, launch?: Launch): string;
|
|
24
|
+
export declare function leadChildEnv(project: string, paths: LeadPaths, source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
25
|
+
export declare const WORKER_ENV_PASSTHROUGH: readonly ["PATH", "HOME", "USER", "LOGNAME", "SHELL", "LANG", "LC_ALL", "TMPDIR", "XDG_RUNTIME_DIR", "TERM", "SSH_AUTH_SOCK", "GH_TOKEN", "GITHUB_TOKEN", "LINEAR_API_KEY", "DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "COLORTERM", "EDITOR", "VISUAL"];
|
|
26
|
+
export declare function curatedClientEnv(source?: NodeJS.ProcessEnv): Record<string, string>;
|
|
27
|
+
export declare function workerEnv(hostEnv: NodeJS.ProcessEnv, clientEnv: Record<string, string>, leadRootDir: string): NodeJS.ProcessEnv;
|
|
28
|
+
export declare function leadRunArgs(project: string, model: string, start: LeadSessionStart, paths: LeadPaths): string[];
|
|
29
|
+
export declare function agentsCliLaunch(args: string[]): Launch;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { getCliLaunch } from '../cli-entry.js';
|
|
5
|
+
import { atomicWriteFileSync, atomicWriteJsonSync } from '../fs-atomic.js';
|
|
6
|
+
import { configKeySpec, getConfigValue } from '../device-config.js';
|
|
7
|
+
export const LEAD_TOOL_NAMES = ['roster', 'dispatch', 'start', 'send', 'stop', 'linear', 'remember'];
|
|
8
|
+
export const LEAD_ALLOWED_TOOLS = LEAD_TOOL_NAMES.map((name) => `Bash(agents lead tool ${name}:*)`);
|
|
9
|
+
export const LEAD_DENIED_TOOLS = ['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'Read', 'Glob', 'Grep', 'WebFetch', 'WebSearch'];
|
|
10
|
+
export const LEAD_EFFORT = 'low';
|
|
11
|
+
export const LEAD_ENV_PASSTHROUGH = ['PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'LANG', 'LC_ALL', 'TMPDIR', 'XDG_RUNTIME_DIR', 'TERM'];
|
|
12
|
+
const LEAD_ENV_AUTH = /^(ANTHROPIC_[A-Z_]+|CLAUDE_CODE_OAUTH_TOKEN)$/;
|
|
13
|
+
export function leadModel() {
|
|
14
|
+
const value = getConfigValue('lead.model').value;
|
|
15
|
+
return typeof value === 'string' && value.length > 0 ? value : String(configKeySpec('lead.model').defaultValue);
|
|
16
|
+
}
|
|
17
|
+
export function cliVersion() {
|
|
18
|
+
const pkg = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'package.json');
|
|
19
|
+
return JSON.parse(fs.readFileSync(pkg, 'utf-8')).version;
|
|
20
|
+
}
|
|
21
|
+
export function leadSettings() {
|
|
22
|
+
return {
|
|
23
|
+
permissions: {
|
|
24
|
+
allow: [...LEAD_ALLOWED_TOOLS],
|
|
25
|
+
deny: [...LEAD_DENIED_TOOLS],
|
|
26
|
+
defaultMode: 'dontAsk',
|
|
27
|
+
},
|
|
28
|
+
hooks: {},
|
|
29
|
+
disableAllHooks: true,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function writeLeadSettings(paths) {
|
|
33
|
+
atomicWriteJsonSync(paths.settings, leadSettings());
|
|
34
|
+
return paths.settings;
|
|
35
|
+
}
|
|
36
|
+
export function writeAgentsShim(paths, launch = getCliLaunch([])) {
|
|
37
|
+
fs.mkdirSync(paths.bin, { recursive: true, mode: 0o700 });
|
|
38
|
+
const file = path.join(paths.bin, 'agents');
|
|
39
|
+
const quote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
40
|
+
atomicWriteFileSync(file, `#!/bin/sh\nexec ${[launch.command, ...launch.args].map(quote).join(' ')} "$@"\n`);
|
|
41
|
+
fs.chmodSync(file, 0o755);
|
|
42
|
+
return file;
|
|
43
|
+
}
|
|
44
|
+
export function leadChildEnv(project, paths, source = process.env) {
|
|
45
|
+
const env = {};
|
|
46
|
+
for (const key of LEAD_ENV_PASSTHROUGH)
|
|
47
|
+
if (source[key] !== undefined)
|
|
48
|
+
env[key] = source[key];
|
|
49
|
+
for (const [key, value] of Object.entries(source))
|
|
50
|
+
if (LEAD_ENV_AUTH.test(key) && value !== undefined)
|
|
51
|
+
env[key] = value;
|
|
52
|
+
env.PATH = [paths.bin, env.PATH].filter(Boolean).join(path.delimiter);
|
|
53
|
+
env.AGENTS_LEAD_PROJECT = project;
|
|
54
|
+
env.AGENTS_NO_AUTOPULL = '1';
|
|
55
|
+
return env;
|
|
56
|
+
}
|
|
57
|
+
export const WORKER_ENV_PASSTHROUGH = [
|
|
58
|
+
...LEAD_ENV_PASSTHROUGH,
|
|
59
|
+
'SSH_AUTH_SOCK', 'GH_TOKEN', 'GITHUB_TOKEN', 'LINEAR_API_KEY', 'DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY',
|
|
60
|
+
'DBUS_SESSION_BUS_ADDRESS', 'COLORTERM', 'EDITOR', 'VISUAL',
|
|
61
|
+
];
|
|
62
|
+
export function curatedClientEnv(source = process.env) {
|
|
63
|
+
const env = {};
|
|
64
|
+
for (const key of WORKER_ENV_PASSTHROUGH) {
|
|
65
|
+
const value = source[key];
|
|
66
|
+
if (value !== undefined)
|
|
67
|
+
env[key] = value;
|
|
68
|
+
}
|
|
69
|
+
for (const [key, value] of Object.entries(source))
|
|
70
|
+
if (LEAD_ENV_AUTH.test(key) && value !== undefined)
|
|
71
|
+
env[key] = value;
|
|
72
|
+
return env;
|
|
73
|
+
}
|
|
74
|
+
export function workerEnv(hostEnv, clientEnv, leadRootDir) {
|
|
75
|
+
const env = { ...curatedClientEnv(hostEnv), ...curatedClientEnv(clientEnv) };
|
|
76
|
+
if (env.PATH) {
|
|
77
|
+
env.PATH = env.PATH.split(path.delimiter).filter((dir) => dir && !path.resolve(dir).startsWith(path.resolve(leadRootDir))).join(path.delimiter);
|
|
78
|
+
}
|
|
79
|
+
return env;
|
|
80
|
+
}
|
|
81
|
+
export function leadRunArgs(project, model, start, paths) {
|
|
82
|
+
const session = start.mode === 'fresh'
|
|
83
|
+
? ['--session-id', start.sessionId, '--name', `lead-${project}`]
|
|
84
|
+
: ['--resume', start.sessionId];
|
|
85
|
+
return [
|
|
86
|
+
'run', 'claude', '--headless', '--quiet',
|
|
87
|
+
'--cwd', paths.dir,
|
|
88
|
+
'--model', model,
|
|
89
|
+
'--effort', LEAD_EFFORT,
|
|
90
|
+
...session,
|
|
91
|
+
'--',
|
|
92
|
+
'--input-format', 'stream-json',
|
|
93
|
+
'--output-format', 'stream-json',
|
|
94
|
+
'--verbose',
|
|
95
|
+
'--include-partial-messages',
|
|
96
|
+
'--setting-sources', 'local',
|
|
97
|
+
'--settings', paths.settings,
|
|
98
|
+
'--strict-mcp-config',
|
|
99
|
+
'--tools', 'Bash',
|
|
100
|
+
'--permission-mode', 'dontAsk',
|
|
101
|
+
'--allowedTools', ...LEAD_ALLOWED_TOOLS,
|
|
102
|
+
'--disallowedTools', ...LEAD_DENIED_TOOLS,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
export function agentsCliLaunch(args) {
|
|
106
|
+
return getCliLaunch(args);
|
|
107
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type ProjectDef } from '../projects.js';
|
|
2
|
+
import { type LeadEngine, type LeadEvent } from './events.js';
|
|
3
|
+
import { type BriefPr, type BriefTicket } from './brief.js';
|
|
4
|
+
import { type LeadPaths } from './paths.js';
|
|
5
|
+
import { type Launch } from './harness.js';
|
|
6
|
+
export declare const LEAD_IDLE_EXIT_MS: number;
|
|
7
|
+
export declare const ROSTER_WAIT_MS = 4000;
|
|
8
|
+
export declare const CONFIRM_SWEEP_MS: number;
|
|
9
|
+
export declare const MEMORY_PROMPT: string;
|
|
10
|
+
export type LeadHostState = 'warm' | 'cold' | 'stopped';
|
|
11
|
+
export interface LeadStatus {
|
|
12
|
+
project: string;
|
|
13
|
+
state: LeadHostState;
|
|
14
|
+
session: string | null;
|
|
15
|
+
engine: LeadEngine | null;
|
|
16
|
+
model: string;
|
|
17
|
+
host: string;
|
|
18
|
+
brief: string[];
|
|
19
|
+
memory: string[];
|
|
20
|
+
tools: string[];
|
|
21
|
+
pid: number | null;
|
|
22
|
+
version: string | null;
|
|
23
|
+
busy: boolean;
|
|
24
|
+
queued: number;
|
|
25
|
+
turns: number;
|
|
26
|
+
contextPct: number | null;
|
|
27
|
+
lastTurnAt: string | null;
|
|
28
|
+
}
|
|
29
|
+
export type LeadRequest = {
|
|
30
|
+
op: 'ask';
|
|
31
|
+
text: string;
|
|
32
|
+
voice?: number;
|
|
33
|
+
env?: Record<string, string>;
|
|
34
|
+
} | {
|
|
35
|
+
op: 'status';
|
|
36
|
+
} | {
|
|
37
|
+
op: 'stop';
|
|
38
|
+
} | {
|
|
39
|
+
op: 'roster';
|
|
40
|
+
project?: string;
|
|
41
|
+
} | {
|
|
42
|
+
op: 'resolve';
|
|
43
|
+
session: string;
|
|
44
|
+
} | {
|
|
45
|
+
op: 'hold-stop';
|
|
46
|
+
session: string;
|
|
47
|
+
} | {
|
|
48
|
+
op: 'spawn';
|
|
49
|
+
agent: string;
|
|
50
|
+
prompt: string;
|
|
51
|
+
};
|
|
52
|
+
export interface LeadHostRecord {
|
|
53
|
+
pid: number;
|
|
54
|
+
project: string;
|
|
55
|
+
version: string;
|
|
56
|
+
model: string;
|
|
57
|
+
startedAtMs: number;
|
|
58
|
+
}
|
|
59
|
+
export interface LeadHostOptions {
|
|
60
|
+
project: string;
|
|
61
|
+
def: ProjectDef;
|
|
62
|
+
paths: LeadPaths;
|
|
63
|
+
model: string;
|
|
64
|
+
version: string;
|
|
65
|
+
harness: (args: string[]) => Launch;
|
|
66
|
+
feed: Launch | null;
|
|
67
|
+
childEnv?: NodeJS.ProcessEnv;
|
|
68
|
+
workerLaunch?: (args: string[]) => Launch;
|
|
69
|
+
fetchTickets?: (def: ProjectDef) => Promise<BriefTicket[]>;
|
|
70
|
+
fetchPrs?: (def: ProjectDef) => Promise<BriefPr[]>;
|
|
71
|
+
teamKey?: string;
|
|
72
|
+
idleExitMs?: number;
|
|
73
|
+
log?: (line: string) => void;
|
|
74
|
+
}
|
|
75
|
+
export declare function isLeadRow(row: {
|
|
76
|
+
title: string;
|
|
77
|
+
cwd?: string;
|
|
78
|
+
}): boolean;
|
|
79
|
+
export declare function readHostRecord(paths: LeadPaths): LeadHostRecord | null;
|
|
80
|
+
export declare function acquireHostLock(paths: LeadPaths): void;
|
|
81
|
+
export declare function statusFromFiles(project: string, paths: LeadPaths, model: string): LeadStatus;
|
|
82
|
+
export declare class LeadHost {
|
|
83
|
+
private readonly opts;
|
|
84
|
+
private server;
|
|
85
|
+
private child;
|
|
86
|
+
private childSessionId;
|
|
87
|
+
private childStderr;
|
|
88
|
+
private active;
|
|
89
|
+
private queue;
|
|
90
|
+
private queued;
|
|
91
|
+
private busy;
|
|
92
|
+
private stopping;
|
|
93
|
+
private readonly roster;
|
|
94
|
+
private feedChild;
|
|
95
|
+
private feedBackoffMs;
|
|
96
|
+
private timers;
|
|
97
|
+
private idleTimer;
|
|
98
|
+
private readonly ticketCache;
|
|
99
|
+
private readonly knownPrs;
|
|
100
|
+
private readonly ticketPrefixes;
|
|
101
|
+
private rotatedFrom;
|
|
102
|
+
private clientEnv;
|
|
103
|
+
private resolveClosed;
|
|
104
|
+
readonly closed: Promise<void>;
|
|
105
|
+
constructor(opts: LeadHostOptions);
|
|
106
|
+
private log;
|
|
107
|
+
start(): Promise<void>;
|
|
108
|
+
private claimSocket;
|
|
109
|
+
private armIdle;
|
|
110
|
+
private startFeed;
|
|
111
|
+
private isSelf;
|
|
112
|
+
private liveRows;
|
|
113
|
+
private projectRoster;
|
|
114
|
+
private fleetSummary;
|
|
115
|
+
private findRow;
|
|
116
|
+
private onConnection;
|
|
117
|
+
private rosterReply;
|
|
118
|
+
private resolveReply;
|
|
119
|
+
private holdStop;
|
|
120
|
+
private spawnWorker;
|
|
121
|
+
status(): LeadStatus;
|
|
122
|
+
private schedule;
|
|
123
|
+
enqueue(text: string, voice: number | undefined, emit: (e: LeadEvent) => void): Promise<void>;
|
|
124
|
+
private spawnChild;
|
|
125
|
+
private refreshRefData;
|
|
126
|
+
private gatherBrief;
|
|
127
|
+
private exchange;
|
|
128
|
+
private runTurn;
|
|
129
|
+
private rotate;
|
|
130
|
+
private stopChild;
|
|
131
|
+
shutdown(): Promise<void>;
|
|
132
|
+
}
|