@phnx-labs/agents-cli 1.23.21 → 1.23.23
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 +115 -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 +53 -28
- package/dist/lib/daemon/attention-notify-service.js +232 -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/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,284 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
const EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
3
|
+
const folds = new Map();
|
|
4
|
+
export const PENDING_COLD_TAIL_BYTES = 64 * 1024 * 1024;
|
|
5
|
+
const MAX_READ_BYTES = 4 * 1024 * 1024;
|
|
6
|
+
const MAX_PARTIAL_BYTES = 1024 * 1024;
|
|
7
|
+
const MAX_BASH_CALLS = 256;
|
|
8
|
+
const MAX_FOLDS = 512;
|
|
9
|
+
const NOTIFICATION_RE = /<task-notification>([\s\S]*?)<\/task-notification>/g;
|
|
10
|
+
function tag(body, name) {
|
|
11
|
+
const match = new RegExp(`<${name}>([^<]*)</${name}>`).exec(body);
|
|
12
|
+
return match?.[1]?.trim() || undefined;
|
|
13
|
+
}
|
|
14
|
+
function text(value) {
|
|
15
|
+
return typeof value === 'string' && value.trim() ? value.replace(/\s+/g, ' ').trim().slice(0, 200) : undefined;
|
|
16
|
+
}
|
|
17
|
+
function epoch(value) {
|
|
18
|
+
const ms = typeof value === 'string' ? Date.parse(value) : Number.NaN;
|
|
19
|
+
return Number.isFinite(ms) ? ms : undefined;
|
|
20
|
+
}
|
|
21
|
+
function endTask(fold, id) {
|
|
22
|
+
if (!id)
|
|
23
|
+
return;
|
|
24
|
+
if (fold.tasks.delete(id))
|
|
25
|
+
return;
|
|
26
|
+
for (const [key, task] of fold.tasks) {
|
|
27
|
+
if (task.taskId === id) {
|
|
28
|
+
fold.tasks.delete(key);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function contentBlocks(record) {
|
|
34
|
+
const message = record.message;
|
|
35
|
+
return Array.isArray(message?.content) ? message.content.filter((b) => !!b && typeof b === 'object') : [];
|
|
36
|
+
}
|
|
37
|
+
function foldClaudeToolUses(fold, record) {
|
|
38
|
+
const startedAtMs = epoch(record.timestamp);
|
|
39
|
+
for (const block of contentBlocks(record)) {
|
|
40
|
+
if (block.type !== 'tool_use' || typeof block.id !== 'string')
|
|
41
|
+
continue;
|
|
42
|
+
const input = (block.input ?? {});
|
|
43
|
+
const description = text(input.description) ?? text(input.command);
|
|
44
|
+
if (block.name === 'Bash') {
|
|
45
|
+
if (input.run_in_background === true) {
|
|
46
|
+
fold.tasks.set(block.id, { kind: 'shell', toolUseId: block.id, description: description ?? 'Background command', ...(startedAtMs !== undefined ? { startedAtMs } : {}) });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
fold.bashCalls.set(block.id, { description: description ?? 'Background command', ...(startedAtMs !== undefined ? { startedAtMs } : {}) });
|
|
50
|
+
if (fold.bashCalls.size > MAX_BASH_CALLS)
|
|
51
|
+
fold.bashCalls.delete(fold.bashCalls.keys().next().value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (block.name === 'Monitor') {
|
|
55
|
+
fold.tasks.set(block.id, {
|
|
56
|
+
kind: 'monitor', toolUseId: block.id, description: description ?? 'Monitor',
|
|
57
|
+
...(startedAtMs !== undefined ? { startedAtMs } : {}),
|
|
58
|
+
...(typeof input.timeout_ms === 'number' ? { timeoutMs: input.timeout_ms } : {}),
|
|
59
|
+
...(input.persistent === true ? { persistent: true } : {}),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else if (block.name === 'TaskStop' || block.name === 'KillShell') {
|
|
63
|
+
const target = text(input.task_id) ?? text(input.shell_id);
|
|
64
|
+
if (target)
|
|
65
|
+
fold.stopCalls.set(block.id, target);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function foldClaudeToolResults(fold, record) {
|
|
70
|
+
const result = (record.toolUseResult ?? {});
|
|
71
|
+
const taskId = text(result.backgroundTaskId) ?? text(result.taskId);
|
|
72
|
+
for (const block of contentBlocks(record)) {
|
|
73
|
+
if (block.type !== 'tool_result' || typeof block.tool_use_id !== 'string')
|
|
74
|
+
continue;
|
|
75
|
+
const id = block.tool_use_id;
|
|
76
|
+
const stopTarget = fold.stopCalls.get(id);
|
|
77
|
+
if (stopTarget !== undefined) {
|
|
78
|
+
fold.stopCalls.delete(id);
|
|
79
|
+
if (block.is_error !== true)
|
|
80
|
+
endTask(fold, stopTarget);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
let task = fold.tasks.get(id);
|
|
84
|
+
if (!task && taskId && fold.bashCalls.has(id)) {
|
|
85
|
+
const call = fold.bashCalls.get(id);
|
|
86
|
+
task = { kind: 'shell', toolUseId: id, description: call.description, ...(call.startedAtMs !== undefined ? { startedAtMs: call.startedAtMs } : {}) };
|
|
87
|
+
fold.tasks.set(id, task);
|
|
88
|
+
}
|
|
89
|
+
fold.bashCalls.delete(id);
|
|
90
|
+
if (!task)
|
|
91
|
+
continue;
|
|
92
|
+
if (block.is_error === true || !taskId) {
|
|
93
|
+
fold.tasks.delete(id);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
task.taskId = taskId;
|
|
97
|
+
if (task.kind === 'monitor') {
|
|
98
|
+
if (typeof result.timeoutMs === 'number')
|
|
99
|
+
task.timeoutMs = result.timeoutMs;
|
|
100
|
+
if (result.persistent === true)
|
|
101
|
+
task.persistent = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function foldNotifications(fold, line) {
|
|
106
|
+
for (const match of line.matchAll(NOTIFICATION_RE)) {
|
|
107
|
+
const body = match[1];
|
|
108
|
+
if (!tag(body, 'status') && !body.includes('Monitor expired'))
|
|
109
|
+
continue;
|
|
110
|
+
endTask(fold, tag(body, 'tool-use-id'));
|
|
111
|
+
endTask(fold, tag(body, 'task-id'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function foldClaudeRunSettings(fold, record) {
|
|
115
|
+
if (typeof record.effort === 'string' && EFFORTS.has(record.effort))
|
|
116
|
+
fold.effort = record.effort;
|
|
117
|
+
const speed = (record.message?.usage)?.speed;
|
|
118
|
+
if (speed === 'fast')
|
|
119
|
+
fold.fast = true;
|
|
120
|
+
else if (speed === 'standard')
|
|
121
|
+
fold.fast = false;
|
|
122
|
+
}
|
|
123
|
+
function parse(line) {
|
|
124
|
+
try {
|
|
125
|
+
const value = JSON.parse(line);
|
|
126
|
+
return value && typeof value === 'object' ? value : undefined;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const PROCESS_START_RE = /"hookName":"SessionStart:(?:startup|resume)"/;
|
|
133
|
+
function isProcessBoundary(line) {
|
|
134
|
+
return line.startsWith('{"type":"cost-state"') || PROCESS_START_RE.test(line);
|
|
135
|
+
}
|
|
136
|
+
function foldClaudeLine(fold, line) {
|
|
137
|
+
if (isProcessBoundary(line)) {
|
|
138
|
+
fold.tasks.clear();
|
|
139
|
+
fold.bashCalls.clear();
|
|
140
|
+
fold.stopCalls.clear();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (line.includes('<task-notification>'))
|
|
144
|
+
foldNotifications(fold, line);
|
|
145
|
+
const isAssistant = line.includes('"type":"assistant"');
|
|
146
|
+
if (isAssistant && line.includes('"effort":"'))
|
|
147
|
+
fold.lastAssistant = line;
|
|
148
|
+
if (isAssistant && line.includes('"tool_use"') && (line.includes('"name":"Bash"') || line.includes('"name":"Monitor"') || line.includes('"name":"TaskStop"') || line.includes('"name":"KillShell"'))) {
|
|
149
|
+
const record = parse(line);
|
|
150
|
+
if (record)
|
|
151
|
+
foldClaudeToolUses(fold, record);
|
|
152
|
+
}
|
|
153
|
+
else if (!isAssistant && line.includes('"tool_result"') && (line.includes('"backgroundTaskId"') || line.includes('"taskId"') || line.includes('"is_error":true') || [...fold.stopCalls.keys()].some((id) => line.includes(id)))) {
|
|
154
|
+
const record = parse(line);
|
|
155
|
+
if (record)
|
|
156
|
+
foldClaudeToolResults(fold, record);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function foldCodexLine(fold, line) {
|
|
160
|
+
if (!line.includes('"type":"turn_context"'))
|
|
161
|
+
return;
|
|
162
|
+
const effort = parse(line)?.payload?.effort;
|
|
163
|
+
if (typeof effort === 'string' && EFFORTS.has(effort))
|
|
164
|
+
fold.effort = effort;
|
|
165
|
+
}
|
|
166
|
+
function readAppended(file, fold, onLine) {
|
|
167
|
+
let fd;
|
|
168
|
+
try {
|
|
169
|
+
fd = fs.openSync(file, 'r');
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const st = fs.fstatSync(fd);
|
|
176
|
+
let skipFirst = false;
|
|
177
|
+
if (st.ino !== fold.ino || st.size < fold.offset) {
|
|
178
|
+
fold.ino = st.ino;
|
|
179
|
+
fold.offset = Math.max(0, st.size - PENDING_COLD_TAIL_BYTES);
|
|
180
|
+
fold.partial = '';
|
|
181
|
+
fold.tasks.clear();
|
|
182
|
+
fold.bashCalls.clear();
|
|
183
|
+
fold.stopCalls.clear();
|
|
184
|
+
delete fold.lastAssistant;
|
|
185
|
+
delete fold.effort;
|
|
186
|
+
delete fold.fast;
|
|
187
|
+
skipFirst = fold.offset > 0;
|
|
188
|
+
}
|
|
189
|
+
while (fold.offset < st.size) {
|
|
190
|
+
const length = Math.min(MAX_READ_BYTES, st.size - fold.offset);
|
|
191
|
+
const buffer = Buffer.alloc(length);
|
|
192
|
+
const read = fs.readSync(fd, buffer, 0, length, fold.offset);
|
|
193
|
+
if (read <= 0)
|
|
194
|
+
break;
|
|
195
|
+
fold.offset += read;
|
|
196
|
+
const chunk = fold.partial + buffer.subarray(0, read).toString('utf8');
|
|
197
|
+
const parts = chunk.split('\n');
|
|
198
|
+
fold.partial = parts.pop() ?? '';
|
|
199
|
+
if (fold.partial.length > MAX_PARTIAL_BYTES)
|
|
200
|
+
fold.partial = '';
|
|
201
|
+
if (skipFirst) {
|
|
202
|
+
parts.shift();
|
|
203
|
+
skipFirst = false;
|
|
204
|
+
}
|
|
205
|
+
for (const part of parts)
|
|
206
|
+
if (part)
|
|
207
|
+
onLine(part);
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
fs.closeSync(fd);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function foldFor(file, agent) {
|
|
216
|
+
let fold = folds.get(file);
|
|
217
|
+
if (!fold || fold.agent !== agent) {
|
|
218
|
+
if (folds.size >= MAX_FOLDS)
|
|
219
|
+
folds.clear();
|
|
220
|
+
fold = { agent, offset: 0, partial: '', ino: -1, tasks: new Map(), bashCalls: new Map(), stopCalls: new Map() };
|
|
221
|
+
folds.set(file, fold);
|
|
222
|
+
}
|
|
223
|
+
const target = fold;
|
|
224
|
+
const ok = readAppended(file, target, agent === 'claude' ? (line) => foldClaudeLine(target, line) : (line) => foldCodexLine(target, line));
|
|
225
|
+
if (!ok) {
|
|
226
|
+
folds.delete(file);
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
if (target.lastAssistant) {
|
|
230
|
+
const record = parse(target.lastAssistant);
|
|
231
|
+
delete target.lastAssistant;
|
|
232
|
+
if (record)
|
|
233
|
+
foldClaudeRunSettings(target, record);
|
|
234
|
+
}
|
|
235
|
+
return target;
|
|
236
|
+
}
|
|
237
|
+
function items(tasks) {
|
|
238
|
+
return tasks.map((task) => ({
|
|
239
|
+
id: task.taskId ?? task.toolUseId,
|
|
240
|
+
description: task.description,
|
|
241
|
+
...(task.startedAtMs !== undefined ? { startedAtMs: task.startedAtMs } : {}),
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
export function readSessionLiveWork(row, nowMs = Date.now()) {
|
|
245
|
+
const alive = row.pidAlive === true;
|
|
246
|
+
const current = (startedAtMs) => row.processStartedAtMs === undefined || startedAtMs === undefined || startedAtMs >= row.processStartedAtMs;
|
|
247
|
+
const subagents = (alive ? row.subagents ?? [] : [])
|
|
248
|
+
.filter((agent) => agent.status === 'running' && current(agent.startedAtMs))
|
|
249
|
+
.map((agent) => ({ id: agent.id, description: agent.description, ...(agent.startedAtMs !== undefined ? { startedAtMs: agent.startedAtMs } : {}) }));
|
|
250
|
+
const agent = row.kind === 'claude' || row.kind === 'codex' ? row.kind : undefined;
|
|
251
|
+
const fold = agent && row.sessionFile ? foldFor(row.sessionFile, agent) : undefined;
|
|
252
|
+
const live = alive ? [...(fold?.tasks.values() ?? [])].filter((task) => current(task.startedAtMs)) : [];
|
|
253
|
+
const shells = items(live.filter((task) => task.kind === 'shell'));
|
|
254
|
+
const monitors = items(live.filter((task) => task.kind === 'monitor'
|
|
255
|
+
&& (task.persistent || task.timeoutMs === undefined || task.startedAtMs === undefined || task.startedAtMs + task.timeoutMs > nowMs)));
|
|
256
|
+
const out = {};
|
|
257
|
+
if (subagents.length || shells.length || monitors.length)
|
|
258
|
+
out.pending = { subagents, shells, monitors };
|
|
259
|
+
if (fold?.effort)
|
|
260
|
+
out.effort = fold.effort;
|
|
261
|
+
if (fold?.fast !== undefined)
|
|
262
|
+
out.fast = fold.fast;
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
export function enrichLiveWork(rows, nowMs = Date.now()) {
|
|
266
|
+
for (const row of rows) {
|
|
267
|
+
const work = readSessionLiveWork(row, nowMs);
|
|
268
|
+
if (work.pending)
|
|
269
|
+
row.pending = work.pending;
|
|
270
|
+
else
|
|
271
|
+
delete row.pending;
|
|
272
|
+
if (work.effort)
|
|
273
|
+
row.effort = work.effort;
|
|
274
|
+
else
|
|
275
|
+
delete row.effort;
|
|
276
|
+
if (work.fast !== undefined)
|
|
277
|
+
row.fast = work.fast;
|
|
278
|
+
else
|
|
279
|
+
delete row.fast;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
export function resetPendingWorkFolds() {
|
|
283
|
+
folds.clear();
|
|
284
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { type DeviceProfile } from '../../devices/registry.js';
|
|
2
1
|
import type { RemoteToolBin } from '../../hosts/remote-cmd.js';
|
|
3
2
|
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
4
3
|
export declare function remoteListCommand(forwardedArgs: string[], os?: string): string;
|
|
5
|
-
export declare function parseRemoteList(stdout: string, machine: string): SessionMeta[];
|
|
6
4
|
export declare function parseRemoteListPayload(stdout: string, machine: string, safeResolver?: boolean): {
|
|
7
5
|
items: SessionMeta[];
|
|
8
6
|
valid: boolean;
|
|
@@ -20,7 +18,6 @@ interface RemoteListResult {
|
|
|
20
18
|
deviceCount: number;
|
|
21
19
|
unreachable: string[];
|
|
22
20
|
}
|
|
23
|
-
export declare function isAutomaticSessionPeer(d: DeviceProfile, self: string): boolean;
|
|
24
21
|
interface GatherRemoteListOptions {
|
|
25
22
|
isDefinitive?: (session: SessionMeta, machine: string) => boolean;
|
|
26
23
|
timeoutMs?: number;
|
|
@@ -4,7 +4,7 @@ import { SSH_OPTS, controlOpts, sshExec, assertValidSshTarget, shellQuote, SSH_C
|
|
|
4
4
|
import { connectionEndedNotice } from '../../hosts/reconnect.js';
|
|
5
5
|
import { sshTargetFor } from '../../devices/connect.js';
|
|
6
6
|
import { resolveDeviceProfile } from '../../devices/resolve-profile.js';
|
|
7
|
-
import { loadDevices
|
|
7
|
+
import { loadDevices } from '../../devices/registry.js';
|
|
8
8
|
import { remoteShellFor, buildWindowsAgentsCommand, stripClixml } from '../../hosts/remote-cmd.js';
|
|
9
9
|
import { gatherRemoteAgentsJson } from '../../remote-agents-json.js';
|
|
10
10
|
import { normalizeHost } from '../sync/config.js';
|
|
@@ -22,20 +22,6 @@ export function remoteListCommand(forwardedArgs, os) {
|
|
|
22
22
|
const inner = [`${NO_FANOUT_ENV}=1`, 'agents', ...forwardedArgs].map((t, i) => i === 0 ? t : shellQuote(t)).join(' ');
|
|
23
23
|
return `bash -lc ${shellQuote(inner)}`;
|
|
24
24
|
}
|
|
25
|
-
export function parseRemoteList(stdout, machine) {
|
|
26
|
-
let parsed;
|
|
27
|
-
try {
|
|
28
|
-
parsed = JSON.parse(stripClixml(stdout));
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
if (!Array.isArray(parsed))
|
|
34
|
-
return [];
|
|
35
|
-
return parsed.flatMap((value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
36
|
-
? [{ ...value, machine, _remote: true }]
|
|
37
|
-
: []);
|
|
38
|
-
}
|
|
39
25
|
const SAFE_RESOLVER_KEYS = new Set([
|
|
40
26
|
'id', 'shortId', 'agent', 'origin', 'timestamp', 'lastActivity', 'project',
|
|
41
27
|
'version', 'harness', 'mode', 'label', 'topic', 'machine',
|
|
@@ -104,14 +90,6 @@ export function sshCapture(target, remoteCmd, timeoutMs, options = {}) {
|
|
|
104
90
|
child.on('close', (code) => done(code));
|
|
105
91
|
});
|
|
106
92
|
}
|
|
107
|
-
export function isAutomaticSessionPeer(d, self) {
|
|
108
|
-
if (!isDialableDevice(d))
|
|
109
|
-
return false;
|
|
110
|
-
if (normalizeHost(d.name) === self)
|
|
111
|
-
return false;
|
|
112
|
-
const platform = resolveDeviceProfile(d).platform;
|
|
113
|
-
return platform === 'windows' || platform === 'linux' || platform === 'macos';
|
|
114
|
-
}
|
|
115
93
|
export async function gatherRemoteList(forwardedArgs, hosts, opts) {
|
|
116
94
|
const safeResolver = forwardedArgs[0] === 'ps' && forwardedArgs[1] === 'resolve';
|
|
117
95
|
const result = await gatherRemoteAgentsJson({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ProjectDef } from '../../projects.js';
|
|
1
2
|
import { type ActiveSession } from '../active.js';
|
|
2
3
|
import { type SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
3
4
|
import { readActiveSessionsCache } from '../session-cache.js';
|
|
@@ -71,6 +72,10 @@ export interface SessionWatchRow extends Omit<ActiveSession, 'viewingIn' | 'cont
|
|
|
71
72
|
}
|
|
72
73
|
export declare function sessionWatchRowKey(scope: string, row: ActiveSession): string;
|
|
73
74
|
export declare function toSessionWatchRow(scope: string, row: ActiveSession): SessionWatchRow;
|
|
75
|
+
export declare function withCanonicalProject<T extends {
|
|
76
|
+
confirmedProject: string | null;
|
|
77
|
+
}>(row: T, defs?: ProjectDef[]): T;
|
|
78
|
+
export declare function canonicalizePeerSessionEnvelope(event: SessionWatchEnvelope): SessionWatchEnvelope;
|
|
74
79
|
export declare function toPreviousSessionWatchRow(scope: string, session: SessionMeta, accounts?: import("../../account-registry.js").NativeAccount[]): SessionWatchRow;
|
|
75
80
|
export declare class SessionWatchState {
|
|
76
81
|
readonly streamId: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SessionProjection } from '../projection.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isLeadCwd } from '../../lead/visibility.js';
|
|
3
|
+
import { canonicalProjectName, confirmedProjectForCwd, listProjectDefsCached } from '../../projects.js';
|
|
3
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
4
5
|
import * as fs from 'node:fs';
|
|
5
6
|
import * as path from 'node:path';
|
|
@@ -50,6 +51,21 @@ export function toSessionWatchRow(scope, row) {
|
|
|
50
51
|
: null,
|
|
51
52
|
};
|
|
52
53
|
}
|
|
54
|
+
export function withCanonicalProject(row, defs = listProjectDefsCached()) {
|
|
55
|
+
if (!row.confirmedProject)
|
|
56
|
+
return row;
|
|
57
|
+
const name = canonicalProjectName(row.confirmedProject, defs);
|
|
58
|
+
return name === row.confirmedProject ? row : { ...row, confirmedProject: name };
|
|
59
|
+
}
|
|
60
|
+
export function canonicalizePeerSessionEnvelope(event) {
|
|
61
|
+
if (event.type === 'reset') {
|
|
62
|
+
const defs = listProjectDefsCached();
|
|
63
|
+
return { ...event, rows: event.rows.map((row) => withCanonicalProject(row, defs)) };
|
|
64
|
+
}
|
|
65
|
+
if (event.type === 'upsert')
|
|
66
|
+
return { ...event, row: withCanonicalProject(event.row) };
|
|
67
|
+
return event;
|
|
68
|
+
}
|
|
53
69
|
function epochMs(value) {
|
|
54
70
|
const parsed = value ? Date.parse(value) : Number.NaN;
|
|
55
71
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
@@ -108,6 +124,7 @@ export function toPreviousSessionWatchRow(scope, session, accounts = listNativeA
|
|
|
108
124
|
...(session.harness ? { harness: session.harness } : {}),
|
|
109
125
|
sessionId: session.id,
|
|
110
126
|
...(session.cwd ? { cwd: session.cwd } : {}),
|
|
127
|
+
...(isLeadCwd(session.cwd) ? { lead: true } : {}),
|
|
111
128
|
...(session.project ? { project: session.project } : {}),
|
|
112
129
|
confirmedProject: confirmedProjectForCwd(session.cwd) ?? null,
|
|
113
130
|
...(session.label ? { label: session.label } : {}),
|
|
@@ -485,7 +502,7 @@ export async function watchFleetSessions(options) {
|
|
|
485
502
|
const event = JSON.parse(line);
|
|
486
503
|
if (event.version !== SESSION_WATCH_VERSION || typeof event.sequence !== 'number')
|
|
487
504
|
return false;
|
|
488
|
-
emit(event);
|
|
505
|
+
emit(canonicalizePeerSessionEnvelope(event));
|
|
489
506
|
return true;
|
|
490
507
|
}
|
|
491
508
|
catch {
|
|
@@ -38,7 +38,7 @@ interface ImmutableSessionFields {
|
|
|
38
38
|
context?: ActiveSession['context'];
|
|
39
39
|
}
|
|
40
40
|
export declare const IMMUTABLE_FIELD_KEYS: readonly ["topic", "firstUserMessage", "label", "name", "cwd", "project", "attachments", "startedAtMs", "version", "pr", "worktree", "ticket", "createdTickets", "spawnedTeam", "sessionFile", "owner", "assignedTask", "kind", "context"];
|
|
41
|
-
export declare const LIVE_STATUS_KEYS: readonly ["status", "activity", "model", "failures", "activityHistogram", "userTurns", "subagents", "preview", "tokPerSec", "awaitingReason", "question", "todos", "tail", "lastActivityMs", "lastEventMs", "hostLink", "presence", "pidAlive", "tmuxClients", "windowHeartbeatMs", "provenance", "rateLimited", "plan"];
|
|
41
|
+
export declare const LIVE_STATUS_KEYS: readonly ["status", "activity", "model", "failures", "activityHistogram", "userTurns", "subagents", "pending", "effort", "fast", "preview", "tokPerSec", "awaitingReason", "question", "todos", "tail", "lastActivityMs", "lastEventMs", "hostLink", "presence", "pidAlive", "tmuxClients", "windowHeartbeatMs", "provenance", "rateLimited", "plan"];
|
|
42
42
|
export declare const ACTIVE_SESSIONS_READER_IDLE_WINDOW_MS = 45000;
|
|
43
43
|
export declare function setActiveSessionsSnapshotPathForTest(p: string | null): string | null;
|
|
44
44
|
export declare function clearActiveSnapshotMemoryForTest(): void;
|
|
@@ -6,6 +6,7 @@ import { getCacheDir } from '../state.js';
|
|
|
6
6
|
import { artifactKind, backfillActiveRowsFromIndex, foldRecap, sessionProcessIsLocal } from './active.js';
|
|
7
7
|
import { extractArtifacts, mergeArtifacts } from '@phnx-labs/sessions-cli/reader';
|
|
8
8
|
import { enrichGlanceFiles } from './glance-files.js';
|
|
9
|
+
import { enrichLiveWork } from './pending-work.js';
|
|
9
10
|
import { readSessionSummaryAny, readSessionTimelineAny } from './db.js';
|
|
10
11
|
import { isSummarizerReady } from '../summarizer/config.js';
|
|
11
12
|
const SNAPSHOT_FILE = '.active-sessions.json';
|
|
@@ -49,6 +50,9 @@ export const LIVE_STATUS_KEYS = [
|
|
|
49
50
|
'activityHistogram',
|
|
50
51
|
'userTurns',
|
|
51
52
|
'subagents',
|
|
53
|
+
'pending',
|
|
54
|
+
'effort',
|
|
55
|
+
'fast',
|
|
52
56
|
'preview',
|
|
53
57
|
'tokPerSec',
|
|
54
58
|
'awaitingReason',
|
|
@@ -417,6 +421,7 @@ export async function loadLocalActiveSessions(opts = {}) {
|
|
|
417
421
|
for (const s of sessions)
|
|
418
422
|
applyImmutableMemo(s);
|
|
419
423
|
enrichGlanceFiles(sessions, now);
|
|
424
|
+
enrichLiveWork(sessions, now);
|
|
420
425
|
updateImmutableMemos(sessions, now);
|
|
421
426
|
const snap = writeCache('local', sessions, { capturedAt: now });
|
|
422
427
|
return { sessions, servedFromCache: false, capturedAt: snap.capturedAt };
|
|
@@ -446,11 +451,6 @@ export async function loadFleetActiveSessions(opts) {
|
|
|
446
451
|
const live = await opts.gather();
|
|
447
452
|
for (const s of live.sessions)
|
|
448
453
|
applyImmutableMemo(s);
|
|
449
|
-
updateImmutableMemos(live.sessions, now);
|
|
450
|
-
const snap = writeCache('fleet', live.sessions, {
|
|
451
|
-
capturedAt: now,
|
|
452
|
-
remoteDeviceCount: live.remoteDeviceCount,
|
|
453
|
-
});
|
|
454
454
|
let self;
|
|
455
455
|
try {
|
|
456
456
|
const { machineId } = await import('../machine-id.js');
|
|
@@ -459,6 +459,13 @@ export async function loadFleetActiveSessions(opts) {
|
|
|
459
459
|
catch {
|
|
460
460
|
self = undefined;
|
|
461
461
|
}
|
|
462
|
+
if (self !== undefined)
|
|
463
|
+
enrichLiveWork(live.sessions.filter((s) => sessionProcessIsLocal(s, self)), now);
|
|
464
|
+
updateImmutableMemos(live.sessions, now);
|
|
465
|
+
const snap = writeCache('fleet', live.sessions, {
|
|
466
|
+
capturedAt: now,
|
|
467
|
+
remoteDeviceCount: live.remoteDeviceCount,
|
|
468
|
+
});
|
|
462
469
|
if (self !== undefined) {
|
|
463
470
|
const localOnly = live.sessions.filter((s) => sessionProcessIsLocal(s, self));
|
|
464
471
|
writeCache('local', localOnly, { capturedAt: now });
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { addCustomDomain, createBucket, deployWorker, enableWorkersDev, findZoneId, putWorkerSecret, } from '../../cloudflare/provision.js';
|
|
2
|
-
import { DEFAULT_SESSIONS_BUCKET_NAME, DEFAULT_SESSIONS_DOMAIN, DEFAULT_SESSIONS_WORKER_NAME, } from '
|
|
3
|
-
import { renderSessionsWorkerScript } from './worker-template.js';
|
|
2
|
+
import { DEFAULT_SESSIONS_BUCKET_NAME, DEFAULT_SESSIONS_DOMAIN, DEFAULT_SESSIONS_WORKER_NAME, renderSessionsWorkerScript, } from '@phnx-labs/sessions-cli/backup';
|
|
4
3
|
export async function setPhoenixIdBaseSecret(apiToken, accountId, workerName, phoenixIdBase, opts = {}) {
|
|
5
4
|
const normalized = phoenixIdBase.replace(/\/+$/, '').trim();
|
|
6
5
|
if (!normalized)
|
package/dist/lib/smart-launch.js
CHANGED
|
@@ -101,8 +101,13 @@ export async function resolveDeviceAuto(agent, opts = {}) {
|
|
|
101
101
|
throw new Error(formatEmptyAutoPoolError());
|
|
102
102
|
const signals = await (opts.probe ?? probePoolSignals)(pool, agent);
|
|
103
103
|
if (!agent && !opts.probe) {
|
|
104
|
-
const { collectFleetHarnesses } = await import('
|
|
105
|
-
const
|
|
104
|
+
const { collectFleetHarnesses } = await import('./devices/harness-inventory.js');
|
|
105
|
+
const { isInteractiveTerminal } = await import('./format.js');
|
|
106
|
+
const { default: ora } = await import('ora');
|
|
107
|
+
const inventory = await collectFleetHarnesses({
|
|
108
|
+
devices: pool,
|
|
109
|
+
spinner: isInteractiveTerminal() ? (text) => ora(text).start() : undefined,
|
|
110
|
+
});
|
|
106
111
|
const byHost = new Map(inventory.map((result) => [normalizeHost(result.host), result]));
|
|
107
112
|
for (const key of pool) {
|
|
108
113
|
const result = byHost.get(key);
|
package/dist/lib/snapshot.js
CHANGED
|
@@ -38,13 +38,12 @@ export function assembleSnapshot(parts) {
|
|
|
38
38
|
}
|
|
39
39
|
export async function computeSnapshot(opts = {}) {
|
|
40
40
|
const localOnly = opts.hosts?.length ? false : opts.local !== false;
|
|
41
|
-
const [{ collectAgentsJson },
|
|
42
|
-
import('
|
|
43
|
-
import('../commands/ps-roster.js'),
|
|
41
|
+
const [{ collectAgentsJson }, { gatherActiveSessions, serializeActiveSessionsForJson }] = await Promise.all([
|
|
42
|
+
import('./installations/inventory-json.js'),
|
|
44
43
|
import('./session/active.js'),
|
|
45
44
|
]);
|
|
46
45
|
const inventoryP = collectAgentsJson(opts.agent);
|
|
47
|
-
const sessionsP =
|
|
46
|
+
const sessionsP = gatherActiveSessions({
|
|
48
47
|
local: localOnly,
|
|
49
48
|
hosts: opts.hosts,
|
|
50
49
|
});
|
package/dist/lib/ssh-exec.d.ts
CHANGED
|
@@ -42,46 +42,6 @@ interface SshExecRawStreamOptions extends SshExecOptions {
|
|
|
42
42
|
onStderr?: (chunk: Buffer) => void;
|
|
43
43
|
signal?: AbortSignal;
|
|
44
44
|
}
|
|
45
|
-
export declare const SSH_STREAM_KILL_GRACE_MS = 3000;
|
|
46
|
-
export declare const SSH_STREAM_MAX_STDERR: number;
|
|
47
|
-
export interface SshStreamResult {
|
|
48
|
-
code: number | null;
|
|
49
|
-
stderr: Buffer;
|
|
50
|
-
timedOut: boolean;
|
|
51
|
-
killed: boolean;
|
|
52
|
-
stderrTruncated: boolean;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Stream one ssh command's stdout, with the args and env a CALLER built.
|
|
56
|
-
*
|
|
57
|
-
* This exists because {@link sshExecRawStream} assembles its own ssh args, which
|
|
58
|
-
* means it cannot carry a device's canonical auth — the askpass shim for a
|
|
59
|
-
* password-auth box, `-i`/`IdentitiesOnly` for an explicit identity file, or the
|
|
60
|
-
* managed known-hosts pinning. A caller that has already built those through
|
|
61
|
-
* `buildSshInvocation` needs a way to run them, and duplicating the transport to
|
|
62
|
-
* get it would be the worse answer. So this takes `args`/`env` verbatim and adds
|
|
63
|
-
* only the lifecycle guarantees:
|
|
64
|
-
*
|
|
65
|
-
* - **SIGTERM then SIGKILL.** A timeout or abort that only sends SIGTERM leaks a
|
|
66
|
-
* child that ignores it — ssh does, mid-handshake — and the promise never
|
|
67
|
-
* settles. After {@link SSH_STREAM_KILL_GRACE_MS} the child is SIGKILLed and
|
|
68
|
-
* `killed` says so.
|
|
69
|
-
* - **Bounded stderr.** A peer that writes endlessly to stderr would otherwise
|
|
70
|
-
* grow this buffer without limit; it is capped and `stderrTruncated` says so.
|
|
71
|
-
* - **`onStdout` cannot break the caller's cleanup.** A throw from the consumer
|
|
72
|
-
* is captured and re-thrown by the awaiting caller, so a write failure ends the
|
|
73
|
-
* transfer instead of escaping as an unhandled error inside a stream event.
|
|
74
|
-
*/
|
|
75
|
-
export declare function sshStreamWithArgs(opts: {
|
|
76
|
-
args: string[];
|
|
77
|
-
env?: Record<string, string>;
|
|
78
|
-
onStdout: (chunk: Buffer) => void;
|
|
79
|
-
timeoutMs?: number;
|
|
80
|
-
killGraceMs?: number;
|
|
81
|
-
maxStderrBytes?: number;
|
|
82
|
-
signal?: AbortSignal;
|
|
83
|
-
sshBin?: string;
|
|
84
|
-
}): Promise<SshStreamResult>;
|
|
85
45
|
export declare function sshExecRawStream(target: string, remoteCmd: string, opts: SshExecRawStreamOptions): Promise<Omit<SshExecRawResult, 'stdout'>>;
|
|
86
46
|
export declare function sshReachable(target: string, timeoutMs?: number): boolean;
|
|
87
47
|
interface SshStreamOptions {
|