@phnx-labs/agents-cli 1.22.127 → 1.23.1
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 +108 -0
- package/README.md +15 -16
- package/dist/bootstrap.js +4 -3
- package/dist/commands/browser.js +4 -19
- package/dist/commands/cloud-transcripts.js +1 -2
- package/dist/commands/computer.d.ts +2 -6
- package/dist/commands/computer.js +12 -18
- package/dist/commands/daemon.js +70 -11
- package/dist/commands/exec.js +1 -1
- package/dist/commands/feed.js +1 -2
- package/dist/commands/focus.js +4 -1
- package/dist/commands/go.js +3 -2
- package/dist/commands/logs.js +3 -7
- package/dist/commands/menubar.js +55 -3
- package/dist/commands/projects.js +103 -40
- package/dist/commands/ps-roster.d.ts +0 -11
- package/dist/commands/ps-roster.js +3 -116
- package/dist/commands/ps.d.ts +10 -0
- package/dist/commands/ps.js +182 -1
- package/dist/commands/resume.js +1 -1
- package/dist/commands/sessions-browser.d.ts +0 -1
- package/dist/commands/sessions-browser.js +6 -23
- package/dist/commands/sessions-export.js +1 -1
- package/dist/commands/sessions-migrate.js +1 -1
- package/dist/commands/sessions-picker.d.ts +6 -32
- package/dist/commands/sessions-picker.js +81 -8
- package/dist/commands/sessions-render.js +1 -1
- package/dist/commands/sessions-resume.js +2 -2
- package/dist/commands/sessions-share.js +1 -1
- package/dist/commands/sessions-trace.js +1 -1
- package/dist/commands/sessions.d.ts +2 -176
- package/dist/commands/sessions.js +44 -1577
- package/dist/index.js +10 -11
- package/dist/lib/browser-client.d.ts +0 -21
- package/dist/lib/browser-client.js +1 -44
- package/dist/lib/computer/record.d.ts +1 -0
- package/dist/lib/computer/record.js +2 -16
- package/dist/lib/config-keys.d.ts +2 -2
- package/dist/lib/config-keys.js +8 -2
- package/dist/lib/daemon/account-state-daemon-service.d.ts +2 -2
- package/dist/lib/daemon/account-state-daemon-service.js +2 -2
- package/dist/lib/daemon/attention-notify-service.js +8 -4
- package/dist/lib/daemon/daemon.d.ts +5 -1
- package/dist/lib/daemon/daemon.js +54 -14
- package/dist/lib/daemon/diagnostics.d.ts +70 -0
- package/dist/lib/daemon/diagnostics.js +185 -0
- package/dist/lib/daemon/runner.js +3 -2
- package/dist/lib/daemon/service.d.ts +1 -1
- package/dist/lib/daemon/session-state-service.d.ts +1 -1
- package/dist/lib/daemon/session-state-service.js +2 -2
- package/dist/lib/daemon/supervisor.d.ts +8 -0
- package/dist/lib/daemon/supervisor.js +47 -6
- package/dist/lib/daemon-services.d.ts +4 -1
- package/dist/lib/daemon-services.js +36 -5
- package/dist/lib/daemon-ticks.d.ts +3 -1
- package/dist/lib/daemon-ticks.js +18 -12
- package/dist/lib/device-config.d.ts +1 -1
- package/dist/lib/device-config.js +48 -7
- package/dist/lib/feed/tool-activity.d.ts +22 -10
- package/dist/lib/feed/tool-activity.js +168 -32
- package/dist/lib/feed/tools.d.ts +55 -2
- package/dist/lib/feed/tools.js +22 -28
- package/dist/lib/feed/watch.js +12 -8
- package/dist/lib/github/open-prs.d.ts +41 -0
- package/dist/lib/github/open-prs.js +157 -0
- package/dist/lib/github/project-prs.d.ts +20 -1
- package/dist/lib/github/project-prs.js +8 -7
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/menubar/install-menubar.d.ts +23 -7
- package/dist/lib/menubar/install-menubar.js +179 -30
- package/dist/lib/menubar/resolve-version.d.ts +1 -0
- package/dist/lib/menubar/resolve-version.js +4 -2
- package/dist/lib/menubar/snapshot.d.ts +2 -0
- package/dist/lib/menubar/snapshot.js +2 -0
- package/dist/lib/menubar/update-state.d.ts +15 -0
- package/dist/lib/menubar/update-state.js +36 -0
- package/dist/lib/owner-notify.d.ts +0 -12
- package/dist/lib/owner-notify.js +1 -10
- package/dist/lib/self-heal/checks/menubar-helper.js +1 -0
- package/dist/lib/session/active.js +18 -14
- package/dist/lib/session/cloud.d.ts +0 -1
- package/dist/lib/session/cloud.js +0 -5
- package/dist/lib/session/db.d.ts +0 -64
- package/dist/lib/session/db.js +0 -116
- package/dist/lib/session/pid-registry.js +9 -6
- package/dist/lib/session/presentation.d.ts +107 -1
- package/dist/lib/session/presentation.js +543 -4
- package/dist/lib/session/remote/remote-list.d.ts +5 -36
- package/dist/lib/session/remote/remote-list.js +16 -320
- package/dist/lib/session/resume-command.d.ts +9 -0
- package/dist/lib/session/resume-command.js +107 -0
- package/dist/lib/session/selection.d.ts +102 -0
- package/dist/lib/session/selection.js +443 -0
- package/dist/lib/session/tool-index.d.ts +0 -62
- package/dist/lib/session/tool-index.js +1 -537
- package/dist/lib/sessions-client.d.ts +1 -0
- package/dist/lib/sessions-client.js +17 -1
- package/dist/lib/standalone-tools.js +2 -2
- package/dist/lib/testdata/owner-notify-api.d.ts +0 -13
- package/dist/lib/testdata/owner-notify-api.js +3 -23
- package/package.json +1 -1
- package/dist/commands/browser-sessions-picker.d.ts +0 -9
- package/dist/commands/browser-sessions-picker.js +0 -136
- package/dist/commands/computer-sessions-picker.d.ts +0 -11
- package/dist/commands/computer-sessions-picker.js +0 -90
- package/dist/commands/sessions-tail.d.ts +0 -13
- package/dist/commands/sessions-tail.js +0 -222
- package/dist/lib/browser/native-history.test-fixture.d.ts +0 -12
- package/dist/lib/browser/native-history.test-fixture.js +0 -43
- package/dist/lib/browser/paths.d.ts +0 -9
- package/dist/lib/browser/paths.js +0 -31
- package/dist/lib/browser/record.d.ts +0 -4
- package/dist/lib/browser/record.js +0 -19
- package/dist/lib/browser/sessions-list.d.ts +0 -79
- package/dist/lib/browser/sessions-list.js +0 -415
- package/dist/lib/computer/sessions-list.d.ts +0 -78
- package/dist/lib/computer/sessions-list.js +0 -372
- package/dist/lib/daemon/owner-device-delivery-service.d.ts +0 -10
- package/dist/lib/daemon/owner-device-delivery-service.js +0 -28
|
@@ -3,34 +3,12 @@ import chalk from 'chalk';
|
|
|
3
3
|
import { SSH_OPTS, controlOpts, assertValidSshTarget, shellQuote, SSH_CONN_FAILURE_CODE, REMOTE_STDOUT_MAX_BYTES, RemoteUtf8Accumulator, } from '../../ssh-exec.js';
|
|
4
4
|
import { connectionEndedNotice } from '../../hosts/reconnect.js';
|
|
5
5
|
import { sshTargetFor } from '../../devices/connect.js';
|
|
6
|
-
import { resolveExplicitTargetSet } from '../../devices/resolve-target.js';
|
|
7
6
|
import { loadDevices, isDialableDevice } from '../../devices/registry.js';
|
|
8
7
|
import { remoteShellFor, buildWindowsAgentsCommand, stripClixml } from '../../hosts/remote-cmd.js';
|
|
9
8
|
import { gatherRemoteAgentsJson } from '../../remote-agents-json.js';
|
|
10
|
-
import {
|
|
9
|
+
import { normalizeHost } from '../sync/config.js';
|
|
11
10
|
import { NO_FANOUT_ENV } from '../remote-active.js';
|
|
12
11
|
import { terminalWidth } from '../../text/width.js';
|
|
13
|
-
import { sanitizeForTerminal } from '../../redact.js';
|
|
14
|
-
import { mapBounded } from '../../concurrency.js';
|
|
15
|
-
import { TOOL_QUERY_MAX_CLAUSE_BYTES, TOOL_QUERY_MAX_CALL_ROWS, TOOL_QUERY_MAX_CLAUSES, TOOL_QUERY_MAX_RESULT_SESSIONS, TOOL_QUERY_MAX_SERIALIZED_BYTES, serializedToolSearchEnvelopeBytes, } from '../tool-index.js';
|
|
16
|
-
import { TOOL_ERROR_OUTPUT_MAX_BYTES, TOOL_INPUT_MAX_BYTES, TOOL_SUCCESS_OUTPUT_MAX_BYTES, sanitizeToolEvidenceText, } from '@phnx-labs/sessions-cli/reader';
|
|
17
|
-
const REMOTE_TOOL_TIMEOUT_MS = 60_000;
|
|
18
|
-
export { REMOTE_STDOUT_MAX_BYTES, RemoteUtf8Accumulator } from '../../ssh-exec.js';
|
|
19
|
-
export const REMOTE_TOOL_AGGREGATE_MAX_BYTES = TOOL_QUERY_MAX_SERIALIZED_BYTES;
|
|
20
|
-
export function consumeRemoteToolByteBudget(budget, bytes) {
|
|
21
|
-
if (budget.exhausted || bytes > budget.remainingBytes) {
|
|
22
|
-
budget.remainingBytes = 0;
|
|
23
|
-
budget.exhausted = true;
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
budget.remainingBytes -= bytes;
|
|
27
|
-
if (budget.remainingBytes === 0)
|
|
28
|
-
budget.exhausted = true;
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
export function consumeParsedRemoteToolSearchBudget(budget, envelope) {
|
|
32
|
-
return consumeRemoteToolByteBudget(budget, serializedToolSearchEnvelopeBytes(envelope));
|
|
33
|
-
}
|
|
34
12
|
export function remoteListCommand(forwardedArgs, os) {
|
|
35
13
|
if (remoteShellFor(os) === 'powershell') {
|
|
36
14
|
return buildWindowsAgentsCommand({
|
|
@@ -86,7 +64,7 @@ export function parseRemoteListPayload(stdout, machine, safeResolver = false) {
|
|
|
86
64
|
}
|
|
87
65
|
return { items: out, valid: true };
|
|
88
66
|
}
|
|
89
|
-
export function sshCapture(target, remoteCmd, timeoutMs,
|
|
67
|
+
export function sshCapture(target, remoteCmd, timeoutMs, options = {}) {
|
|
90
68
|
assertValidSshTarget(target);
|
|
91
69
|
return new Promise((resolve) => {
|
|
92
70
|
const args = [
|
|
@@ -100,7 +78,6 @@ export function sshCapture(target, remoteCmd, timeoutMs, aggregateBudget, option
|
|
|
100
78
|
const child = spawn('ssh', args, { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
101
79
|
const decoded = new RemoteUtf8Accumulator();
|
|
102
80
|
let stdoutBytes = 0;
|
|
103
|
-
let aggregateBudgetExceeded = false;
|
|
104
81
|
let settled = false;
|
|
105
82
|
const done = (code) => {
|
|
106
83
|
if (settled)
|
|
@@ -108,7 +85,7 @@ export function sshCapture(target, remoteCmd, timeoutMs, aggregateBudget, option
|
|
|
108
85
|
settled = true;
|
|
109
86
|
clearTimeout(timer);
|
|
110
87
|
const stdout = code === null ? decoded.current() : decoded.end();
|
|
111
|
-
resolve({ code, stdout
|
|
88
|
+
resolve({ code, stdout });
|
|
112
89
|
};
|
|
113
90
|
const timer = setTimeout(() => { child.kill('SIGKILL'); done(null); }, timeoutMs);
|
|
114
91
|
child.stdout.on('data', (d) => {
|
|
@@ -117,12 +94,6 @@ export function sshCapture(target, remoteCmd, timeoutMs, aggregateBudget, option
|
|
|
117
94
|
done(null);
|
|
118
95
|
return;
|
|
119
96
|
}
|
|
120
|
-
if (aggregateBudget && !consumeRemoteToolByteBudget(aggregateBudget, d.byteLength)) {
|
|
121
|
-
aggregateBudgetExceeded = true;
|
|
122
|
-
child.kill('SIGKILL');
|
|
123
|
-
done(null);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
97
|
stdoutBytes += d.byteLength;
|
|
127
98
|
decoded.write(d);
|
|
128
99
|
});
|
|
@@ -157,294 +128,6 @@ export async function gatherRemoteList(forwardedArgs, hosts, opts) {
|
|
|
157
128
|
],
|
|
158
129
|
};
|
|
159
130
|
}
|
|
160
|
-
export function parseRemoteToolProgramCount(stdout, machine, expectedProgram) {
|
|
161
|
-
try {
|
|
162
|
-
const parsed = JSON.parse(stdout);
|
|
163
|
-
const query = parsed.query;
|
|
164
|
-
const coverage = parsed.coverage;
|
|
165
|
-
const totals = parsed.totals;
|
|
166
|
-
const machines = parsed.machines;
|
|
167
|
-
const coverageKeys = ['indexedFiles', 'indexedCalls', 'skippedFiles', 'limitedFiles', 'remainingFiles'];
|
|
168
|
-
const totalKeys = ['occurrences', 'toolCalls', 'sessions'];
|
|
169
|
-
if (parsed.schemaVersion !== 1 || parsed.kind !== 'tool-program-count'
|
|
170
|
-
|| !query || query.program !== expectedProgram || query.semantics !== 'static-program-occurrences-v1'
|
|
171
|
-
|| !coverage || typeof coverage.complete !== 'boolean'
|
|
172
|
-
|| coverageKeys.some((key) => !Number.isSafeInteger(coverage[key]) || coverage[key] < 0)
|
|
173
|
-
|| !totals || totalKeys.some((key) => !Number.isSafeInteger(totals[key]) || totals[key] < 0)
|
|
174
|
-
|| !Array.isArray(machines) || machines.length !== 1
|
|
175
|
-
|| boundedRemoteString(parsed.generatedAt, 128) === undefined) {
|
|
176
|
-
return { items: [], valid: false };
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
valid: true,
|
|
180
|
-
items: [{
|
|
181
|
-
machine,
|
|
182
|
-
envelope: {
|
|
183
|
-
schemaVersion: 1,
|
|
184
|
-
kind: 'tool-program-count',
|
|
185
|
-
generatedAt: parsed.generatedAt,
|
|
186
|
-
query: { program: expectedProgram, semantics: 'static-program-occurrences-v1' },
|
|
187
|
-
coverage: coverage,
|
|
188
|
-
totals: totals,
|
|
189
|
-
machines: [{
|
|
190
|
-
machine,
|
|
191
|
-
coverage: coverage,
|
|
192
|
-
totals: totals,
|
|
193
|
-
}],
|
|
194
|
-
},
|
|
195
|
-
}],
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
return { items: [], valid: false };
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
export async function gatherRemoteToolProgramCounts(forwardedArgs, hosts, expectedProgram) {
|
|
203
|
-
const result = await gatherRemoteAgentsJson({
|
|
204
|
-
args: forwardedArgs,
|
|
205
|
-
noFanoutEnv: NO_FANOUT_ENV,
|
|
206
|
-
hosts,
|
|
207
|
-
timeoutMs: REMOTE_TOOL_TIMEOUT_MS,
|
|
208
|
-
parse: (stdout, machine) => parseRemoteToolProgramCount(stdout, machine, expectedProgram),
|
|
209
|
-
});
|
|
210
|
-
return {
|
|
211
|
-
envelopes: result.items,
|
|
212
|
-
deviceCount: result.deviceCount,
|
|
213
|
-
unreachable: [
|
|
214
|
-
...(result.discoveryFailed ? ['device registry'] : []),
|
|
215
|
-
...result.skipped,
|
|
216
|
-
...result.parseFailed,
|
|
217
|
-
],
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function boundedRemoteString(value, maxBytes) {
|
|
221
|
-
if (typeof value !== 'string' || Buffer.byteLength(value) > maxBytes)
|
|
222
|
-
return undefined;
|
|
223
|
-
return sanitizeToolEvidenceText(value, maxBytes);
|
|
224
|
-
}
|
|
225
|
-
function optionalRemoteString(value, maxBytes) {
|
|
226
|
-
if (value === undefined || value === null)
|
|
227
|
-
return undefined;
|
|
228
|
-
return boundedRemoteString(value, maxBytes) ?? null;
|
|
229
|
-
}
|
|
230
|
-
function parseRemoteCall(value) {
|
|
231
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
232
|
-
return undefined;
|
|
233
|
-
const call = value;
|
|
234
|
-
const id = boundedRemoteString(call.id, 512);
|
|
235
|
-
const timestamp = boundedRemoteString(call.timestamp, 128);
|
|
236
|
-
const tool = boundedRemoteString(call.tool, 512);
|
|
237
|
-
const input = boundedRemoteString(call.input, TOOL_INPUT_MAX_BYTES);
|
|
238
|
-
const sourceCallId = optionalRemoteString(call.sourceCallId, 512);
|
|
239
|
-
const output = optionalRemoteString(call.output, TOOL_SUCCESS_OUTPUT_MAX_BYTES);
|
|
240
|
-
const error = optionalRemoteString(call.error, TOOL_ERROR_OUTPUT_MAX_BYTES);
|
|
241
|
-
const errorCode = optionalRemoteString(call.errorCode, 512);
|
|
242
|
-
const parseError = optionalRemoteString(call.parseError, 1024);
|
|
243
|
-
if (call.programs !== undefined
|
|
244
|
-
&& (!Array.isArray(call.programs) || call.programs.length > 128))
|
|
245
|
-
return undefined;
|
|
246
|
-
const programs = Array.isArray(call.programs)
|
|
247
|
-
? call.programs.map((program) => boundedRemoteString(program, 512))
|
|
248
|
-
: [];
|
|
249
|
-
if (!Array.isArray(call.programOccurrences) || call.programOccurrences.length > 10_000)
|
|
250
|
-
return undefined;
|
|
251
|
-
const programOccurrences = call.programOccurrences.map((value) => {
|
|
252
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
253
|
-
return undefined;
|
|
254
|
-
const occurrence = value;
|
|
255
|
-
const program = boundedRemoteString(occurrence.program, 512);
|
|
256
|
-
if (!program || (occurrence.role !== 'wrapper' && occurrence.role !== 'effective'))
|
|
257
|
-
return undefined;
|
|
258
|
-
return { program, role: occurrence.role };
|
|
259
|
-
});
|
|
260
|
-
if (!id || !timestamp || !tool || input === undefined
|
|
261
|
-
|| !Number.isSafeInteger(call.ordinal) || call.ordinal < 0
|
|
262
|
-
|| !['ok', 'error', 'unknown'].includes(String(call.outcome))
|
|
263
|
-
|| sourceCallId === null || output === null || error === null || errorCode === null || parseError === null
|
|
264
|
-
|| programs.some((program) => program === undefined)
|
|
265
|
-
|| programOccurrences.some((occurrence) => occurrence === undefined))
|
|
266
|
-
return undefined;
|
|
267
|
-
for (const code of [call.exitCode, call.statusCode]) {
|
|
268
|
-
if (code !== undefined && (!Number.isSafeInteger(code) || code < 0))
|
|
269
|
-
return undefined;
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
id,
|
|
273
|
-
ordinal: call.ordinal,
|
|
274
|
-
sourceCallId,
|
|
275
|
-
timestamp,
|
|
276
|
-
tool,
|
|
277
|
-
programs: programs,
|
|
278
|
-
programOccurrences: programOccurrences,
|
|
279
|
-
input,
|
|
280
|
-
outcome: call.outcome,
|
|
281
|
-
exitCode: call.exitCode,
|
|
282
|
-
statusCode: call.statusCode,
|
|
283
|
-
errorCode,
|
|
284
|
-
output,
|
|
285
|
-
error,
|
|
286
|
-
parseError,
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function parseRemoteToolSession(value, machine) {
|
|
290
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
291
|
-
return undefined;
|
|
292
|
-
const session = value;
|
|
293
|
-
const id = boundedRemoteString(session.id, 512);
|
|
294
|
-
const shortId = boundedRemoteString(session.shortId, 128);
|
|
295
|
-
const agent = boundedRemoteString(session.agent, 128);
|
|
296
|
-
const timestamp = boundedRemoteString(session.timestamp, 128);
|
|
297
|
-
const project = optionalRemoteString(session.project, 4096);
|
|
298
|
-
const cwd = optionalRemoteString(session.cwd, 4096);
|
|
299
|
-
const topic = optionalRemoteString(session.topic, 4096);
|
|
300
|
-
const label = optionalRemoteString(session.label, 4096);
|
|
301
|
-
const originMachine = optionalRemoteString(session.machine, 512);
|
|
302
|
-
const dialedMachine = boundedRemoteString(machine, 512);
|
|
303
|
-
if (!id || !shortId || !agent || !timestamp || !dialedMachine || originMachine === null
|
|
304
|
-
|| project === null || cwd === null || topic === null || label === null
|
|
305
|
-
|| !Array.isArray(session.calls) || session.calls.length > TOOL_QUERY_MAX_CALL_ROWS)
|
|
306
|
-
return undefined;
|
|
307
|
-
const calls = session.calls.map(parseRemoteCall);
|
|
308
|
-
if (calls.some((call) => call === undefined))
|
|
309
|
-
return undefined;
|
|
310
|
-
return {
|
|
311
|
-
id,
|
|
312
|
-
shortId,
|
|
313
|
-
agent,
|
|
314
|
-
machine: originMachine ?? dialedMachine,
|
|
315
|
-
timestamp,
|
|
316
|
-
project,
|
|
317
|
-
cwd,
|
|
318
|
-
topic,
|
|
319
|
-
label,
|
|
320
|
-
calls: calls,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
export function parseRemoteToolSearch(stdout, machine, expectedClauses) {
|
|
324
|
-
stdout = stripClixml(stdout);
|
|
325
|
-
if (Buffer.byteLength(stdout) > REMOTE_STDOUT_MAX_BYTES)
|
|
326
|
-
return undefined;
|
|
327
|
-
try {
|
|
328
|
-
const parsed = JSON.parse(stdout);
|
|
329
|
-
const coverage = parsed?.coverage;
|
|
330
|
-
const query = parsed?.query;
|
|
331
|
-
if (parsed?.schemaVersion !== 1 || !Array.isArray(parsed.sessions)
|
|
332
|
-
|| parsed.sessions.length > TOOL_QUERY_MAX_RESULT_SESSIONS || !coverage || !query
|
|
333
|
-
|| !Array.isArray(query.clauses) || query.clauses.length > TOOL_QUERY_MAX_CLAUSES
|
|
334
|
-
|| query.clauses.some((clause) => boundedRemoteString(clause, TOOL_QUERY_MAX_CLAUSE_BYTES) === undefined))
|
|
335
|
-
return undefined;
|
|
336
|
-
let totalCalls = 0;
|
|
337
|
-
for (const sessionValue of parsed.sessions) {
|
|
338
|
-
if (!sessionValue || typeof sessionValue !== 'object' || Array.isArray(sessionValue))
|
|
339
|
-
return undefined;
|
|
340
|
-
const calls = sessionValue.calls;
|
|
341
|
-
if (!Array.isArray(calls) || calls.length > TOOL_QUERY_MAX_CALL_ROWS)
|
|
342
|
-
return undefined;
|
|
343
|
-
totalCalls += calls.length;
|
|
344
|
-
if (totalCalls > TOOL_QUERY_MAX_CALL_ROWS)
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
347
|
-
const clauses = query.clauses.map((clause) => sanitizeForTerminal(clause));
|
|
348
|
-
const expected = expectedClauses?.map((clause) => sanitizeForTerminal(clause));
|
|
349
|
-
if (expected && (clauses.length !== expected.length
|
|
350
|
-
|| clauses.some((clause, index) => clause !== expected[index])))
|
|
351
|
-
return undefined;
|
|
352
|
-
const coverageNumbers = ['indexedFiles', 'indexedCalls', 'skippedFiles', 'limitedFiles', 'remainingFiles'];
|
|
353
|
-
if (coverageNumbers.some((key) => !Number.isSafeInteger(coverage[key]) || coverage[key] < 0)
|
|
354
|
-
|| typeof coverage.complete !== 'boolean')
|
|
355
|
-
return undefined;
|
|
356
|
-
const sessions = parsed.sessions.map((session) => parseRemoteToolSession(session, machine));
|
|
357
|
-
const generatedAt = boundedRemoteString(parsed.generatedAt, 128);
|
|
358
|
-
if (!generatedAt || sessions.some((session) => session === undefined))
|
|
359
|
-
return undefined;
|
|
360
|
-
return {
|
|
361
|
-
schemaVersion: 1,
|
|
362
|
-
generatedAt,
|
|
363
|
-
query: { clauses },
|
|
364
|
-
coverage: {
|
|
365
|
-
indexedFiles: coverage.indexedFiles,
|
|
366
|
-
indexedCalls: coverage.indexedCalls,
|
|
367
|
-
skippedFiles: coverage.skippedFiles,
|
|
368
|
-
limitedFiles: coverage.limitedFiles,
|
|
369
|
-
remainingFiles: coverage.remainingFiles,
|
|
370
|
-
complete: coverage.complete,
|
|
371
|
-
},
|
|
372
|
-
sessions: sessions,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
catch {
|
|
376
|
-
return undefined;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
export async function gatherRemoteToolSearch(forwardedArgs, hosts, maxAggregateBytes = REMOTE_TOOL_AGGREGATE_MAX_BYTES, expectedClauses = []) {
|
|
380
|
-
const self = machineId();
|
|
381
|
-
const targets = [];
|
|
382
|
-
const unresolved = [];
|
|
383
|
-
if (hosts && hosts.length > 0) {
|
|
384
|
-
const resolved = await resolveExplicitTargetSet(hosts);
|
|
385
|
-
targets.push(...resolved.targets);
|
|
386
|
-
unresolved.push(...resolved.unresolved);
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
let reg;
|
|
390
|
-
try {
|
|
391
|
-
reg = await loadDevices();
|
|
392
|
-
}
|
|
393
|
-
catch {
|
|
394
|
-
return { envelopes: [], deviceCount: 0, unreachable: ['device registry'], truncated: [] };
|
|
395
|
-
}
|
|
396
|
-
for (const d of Object.values(reg)) {
|
|
397
|
-
if (!isAutomaticSessionPeer(d, self))
|
|
398
|
-
continue;
|
|
399
|
-
try {
|
|
400
|
-
targets.push({ target: sshTargetFor(d), machine: normalizeHost(d.name), name: d.name, os: d.platform });
|
|
401
|
-
}
|
|
402
|
-
catch {
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
const remainingBytes = Math.max(0, Math.min(REMOTE_TOOL_AGGREGATE_MAX_BYTES, maxAggregateBytes));
|
|
407
|
-
const aggregateBudget = {
|
|
408
|
-
remainingBytes,
|
|
409
|
-
exhausted: remainingBytes === 0,
|
|
410
|
-
};
|
|
411
|
-
const parsedBudget = {
|
|
412
|
-
remainingBytes,
|
|
413
|
-
exhausted: remainingBytes === 0,
|
|
414
|
-
};
|
|
415
|
-
const results = await mapBounded(targets, async (target) => {
|
|
416
|
-
if (aggregateBudget.exhausted)
|
|
417
|
-
return { target, truncated: target.name };
|
|
418
|
-
const capture = await sshCapture(target.target, remoteListCommand(forwardedArgs, target.os), REMOTE_TOOL_TIMEOUT_MS, aggregateBudget, { multiplex: false });
|
|
419
|
-
if (capture.aggregateBudgetExceeded)
|
|
420
|
-
return { target, truncated: target.name };
|
|
421
|
-
if (capture.code !== 0)
|
|
422
|
-
return { target, unreachable: target.name };
|
|
423
|
-
const envelope = parseRemoteToolSearch(capture.stdout, target.machine, expectedClauses);
|
|
424
|
-
if (!envelope)
|
|
425
|
-
return { target, unreachable: target.name };
|
|
426
|
-
if (!consumeParsedRemoteToolSearchBudget(parsedBudget, envelope)) {
|
|
427
|
-
return { target, truncated: target.name };
|
|
428
|
-
}
|
|
429
|
-
return { target, envelope };
|
|
430
|
-
}, { concurrency: 6 });
|
|
431
|
-
for (const result of results) {
|
|
432
|
-
if (result.unreachable) {
|
|
433
|
-
process.stderr.write(chalk.gray(` ${result.unreachable}: unreachable, incompatible, or no agents CLI — skipped\n`));
|
|
434
|
-
}
|
|
435
|
-
if (result.truncated) {
|
|
436
|
-
process.stderr.write(chalk.gray(` ${result.truncated}: fleet tool-result budget exhausted — skipped\n`));
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return {
|
|
440
|
-
envelopes: results.flatMap((result) => result.envelope
|
|
441
|
-
? [{ machine: result.target.machine, envelope: result.envelope }]
|
|
442
|
-
: []),
|
|
443
|
-
deviceCount: targets.length,
|
|
444
|
-
unreachable: [...unresolved, ...results.map((result) => result.unreachable).filter((name) => !!name)],
|
|
445
|
-
truncated: results.map((result) => result.truncated).filter((name) => !!name),
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
131
|
export async function resolvePeerTarget(machine) {
|
|
449
132
|
let reg;
|
|
450
133
|
try {
|
|
@@ -533,3 +216,16 @@ export async function runOnPeer(args, machine, opts = {}) {
|
|
|
533
216
|
});
|
|
534
217
|
});
|
|
535
218
|
}
|
|
219
|
+
export function hostToken(h) {
|
|
220
|
+
return normalizeHost(h.split('@').pop() || h);
|
|
221
|
+
}
|
|
222
|
+
export function shouldIncludeLocal(hosts, self) {
|
|
223
|
+
if (!hosts || hosts.length === 0)
|
|
224
|
+
return true;
|
|
225
|
+
return hosts.some(h => hostToken(h) === self);
|
|
226
|
+
}
|
|
227
|
+
export function remoteHostsToDial(hosts, self) {
|
|
228
|
+
if (!hosts || hosts.length === 0)
|
|
229
|
+
return undefined;
|
|
230
|
+
return hosts.filter(h => hostToken(h) !== self);
|
|
231
|
+
}
|
|
@@ -1 +1,10 @@
|
|
|
1
|
+
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
1
2
|
export declare function buildCanonicalResumeCommand(sessionId: string): string[];
|
|
3
|
+
export declare function resumeSessionInPlace(session: SessionMeta): Promise<void>;
|
|
4
|
+
export declare function buildSessionRecoveryCommand(session: Pick<SessionMeta, 'id'>, portable?: boolean): string[];
|
|
5
|
+
export declare function resumeSpawnInvocation(cmd: string[], platform?: NodeJS.Platform): {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
shell: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function buildResumeCommand(session: SessionMeta): string[] | null;
|
|
@@ -1,3 +1,110 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { AGENTS } from '../agents.js';
|
|
6
|
+
import { getAgentsInvocation } from '../daemon/daemon.js';
|
|
7
|
+
import { composeWin32CommandLine, needsWindowsShell } from '../platform/index.js';
|
|
8
|
+
import { getShimsDir } from '../state.js';
|
|
9
|
+
import { sessionAgentSupportsResume, sessionRecoveryRunArgs } from './recovery.js';
|
|
10
|
+
import { sessionOwnerDevice } from './resume-owner.js';
|
|
1
11
|
export function buildCanonicalResumeCommand(sessionId) {
|
|
2
12
|
return ['agents', 'sessions', 'resume', sessionId];
|
|
3
13
|
}
|
|
14
|
+
export async function resumeSessionInPlace(session) {
|
|
15
|
+
const owner = sessionOwnerDevice(session);
|
|
16
|
+
if (owner) {
|
|
17
|
+
console.error(chalk.red(`Session ${session.shortId} belongs to ${owner} — it cannot resume on this machine.`));
|
|
18
|
+
console.error(chalk.gray(` Resume it there: agents sessions resume ${session.id}`));
|
|
19
|
+
process.exitCode = 1;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const cwd = session.cwd && fs.existsSync(session.cwd)
|
|
23
|
+
? session.cwd
|
|
24
|
+
: process.cwd();
|
|
25
|
+
const resume = buildSessionRecoveryCommand(session);
|
|
26
|
+
console.log(chalk.gray(`Resuming: ${resume.join(' ')} (cwd: ${cwd})`));
|
|
27
|
+
await spawnResumeCommand(resume, cwd);
|
|
28
|
+
}
|
|
29
|
+
export function buildSessionRecoveryCommand(session, portable = false) {
|
|
30
|
+
const args = sessionRecoveryRunArgs(session);
|
|
31
|
+
if (portable)
|
|
32
|
+
return ['agents', ...args];
|
|
33
|
+
const invocation = getAgentsInvocation(args);
|
|
34
|
+
return [invocation.command, ...invocation.args];
|
|
35
|
+
}
|
|
36
|
+
export function resumeSpawnInvocation(cmd, platform = process.platform) {
|
|
37
|
+
const shell = needsWindowsShell(cmd[0], platform);
|
|
38
|
+
if (shell) {
|
|
39
|
+
return {
|
|
40
|
+
command: composeWin32CommandLine(cmd[0], cmd.slice(1)),
|
|
41
|
+
args: [],
|
|
42
|
+
shell: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return { command: cmd[0], args: cmd.slice(1), shell: false };
|
|
46
|
+
}
|
|
47
|
+
function spawnResumeCommand(cmd, cwd) {
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
let child;
|
|
50
|
+
try {
|
|
51
|
+
const { command, args, shell } = resumeSpawnInvocation(cmd);
|
|
52
|
+
child = spawn(command, args, {
|
|
53
|
+
cwd,
|
|
54
|
+
stdio: 'inherit',
|
|
55
|
+
shell,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
console.error(chalk.red(`Failed to launch ${cmd[0]}: ${err.message}`));
|
|
60
|
+
resolve();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
child.on('error', (err) => {
|
|
64
|
+
console.error(chalk.red(`Failed to launch ${cmd[0]}: ${err.message}`));
|
|
65
|
+
if (err.code === 'ENOENT') {
|
|
66
|
+
console.error(chalk.gray(`Make sure '${cmd[0]}' is on your PATH.`));
|
|
67
|
+
}
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
child.on('close', () => resolve());
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function resumeArgv(agent, id, launcher) {
|
|
74
|
+
switch (agent) {
|
|
75
|
+
case 'claude': return [launcher, '--resume', id];
|
|
76
|
+
case 'codex': return [launcher, 'resume', id];
|
|
77
|
+
case 'opencode': return [launcher, '--session', id];
|
|
78
|
+
case 'muse': return [launcher, 'resume', id];
|
|
79
|
+
default: return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function versionedAliasIfPresent(agent, version) {
|
|
83
|
+
const cli = AGENTS[agent]?.cliCommand ?? agent;
|
|
84
|
+
const base = path.join(getShimsDir(), `${cli}@${version}`);
|
|
85
|
+
if (process.platform === 'win32' && fs.existsSync(`${base}.cmd`))
|
|
86
|
+
return `${base}.cmd`;
|
|
87
|
+
if (fs.existsSync(base))
|
|
88
|
+
return base;
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
export function buildResumeCommand(session) {
|
|
92
|
+
if (!sessionAgentSupportsResume(session.agent))
|
|
93
|
+
return null;
|
|
94
|
+
switch (session.agent) {
|
|
95
|
+
case 'opencode':
|
|
96
|
+
return resumeArgv('opencode', session.id, 'opencode');
|
|
97
|
+
case 'claude':
|
|
98
|
+
case 'codex':
|
|
99
|
+
case 'muse': {
|
|
100
|
+
const cli = AGENTS[session.agent]?.cliCommand ?? session.agent;
|
|
101
|
+
if (session.version) {
|
|
102
|
+
const alias = versionedAliasIfPresent(session.agent, session.version);
|
|
103
|
+
return resumeArgv(session.agent, session.id, alias ?? `${cli}@${session.version}`);
|
|
104
|
+
}
|
|
105
|
+
return resumeArgv(session.agent, session.id, cli);
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { SessionAgentId, SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
import { type ActiveSession } from './active.js';
|
|
3
|
+
import { loadLocalActiveSessions } from './session-cache.js';
|
|
4
|
+
import { gatherRemoteList, runOnPeer } from './remote/remote-list.js';
|
|
5
|
+
export interface SessionFilterOptions {
|
|
6
|
+
agent?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
sessionVersion?: string;
|
|
9
|
+
project?: string;
|
|
10
|
+
all?: boolean;
|
|
11
|
+
teams?: boolean;
|
|
12
|
+
inTeam?: string;
|
|
13
|
+
routine?: boolean | string;
|
|
14
|
+
since?: string;
|
|
15
|
+
until?: string;
|
|
16
|
+
}
|
|
17
|
+
type InstalledVersionsForAgent = (agent: SessionAgentId) => string[];
|
|
18
|
+
export declare function parseInstalledAgentVersionQuery(query: string | undefined, installedVersions?: InstalledVersionsForAgent): string | undefined;
|
|
19
|
+
export declare function ticketLabel(s: Pick<SessionMeta, 'ticketId' | 'prNumber'>): string;
|
|
20
|
+
export declare function sessionMatchesQuery(s: SessionMeta, query: string): boolean;
|
|
21
|
+
export declare function mergeLocalFirst(sessions: SessionMeta[], localMachine: string): SessionMeta[];
|
|
22
|
+
export declare function serializeResolvedSessionsJson(sessions: SessionMeta[]): string;
|
|
23
|
+
interface AgentFilter {
|
|
24
|
+
agent?: SessionAgentId;
|
|
25
|
+
version?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function resolveSessionAgentName(name: string): SessionAgentId | null;
|
|
28
|
+
export declare function parseAgentFilter(agentName?: string): AgentFilter;
|
|
29
|
+
export type SessionSearchScope = {
|
|
30
|
+
agent?: string;
|
|
31
|
+
project?: string;
|
|
32
|
+
routine?: boolean | string;
|
|
33
|
+
};
|
|
34
|
+
interface SessionQueryResolution {
|
|
35
|
+
matches: SessionMeta[];
|
|
36
|
+
byId: boolean;
|
|
37
|
+
completeId: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function resolveSessionQuery(pool: SessionMeta[], query: string, options?: {
|
|
40
|
+
indexFallback?: boolean;
|
|
41
|
+
scope?: SessionSearchScope;
|
|
42
|
+
}): SessionQueryResolution;
|
|
43
|
+
export declare function filterSessionsByQuery(sessions: SessionMeta[], query: string | undefined, scope?: SessionSearchScope): SessionMeta[];
|
|
44
|
+
export declare function applyScopeFilters(sessions: SessionMeta[], scope: SessionSearchScope): SessionMeta[];
|
|
45
|
+
export declare function scopedContentIndex(sessions: SessionMeta[], query: string, scope?: SessionSearchScope): Map<string, SessionMeta>;
|
|
46
|
+
export interface FleetResolveDeps {
|
|
47
|
+
gatherRemoteList: typeof gatherRemoteList;
|
|
48
|
+
runOnPeer: typeof runOnPeer;
|
|
49
|
+
}
|
|
50
|
+
interface FleetHit {
|
|
51
|
+
machine: string;
|
|
52
|
+
session: SessionMeta;
|
|
53
|
+
}
|
|
54
|
+
export interface FleetSessionCandidate {
|
|
55
|
+
id: string;
|
|
56
|
+
hits: FleetHit[];
|
|
57
|
+
}
|
|
58
|
+
export type MetadataResolveOutcome = {
|
|
59
|
+
kind: 'resolved';
|
|
60
|
+
session: SessionMeta;
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'not-found';
|
|
63
|
+
} | {
|
|
64
|
+
kind: 'ambiguous';
|
|
65
|
+
candidates: FleetSessionCandidate[];
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'partial';
|
|
68
|
+
failedPeers: string[];
|
|
69
|
+
};
|
|
70
|
+
export declare function isDefinitiveMatch(session: SessionMeta, selector: string): boolean;
|
|
71
|
+
export declare function selectorAllowsEarlyExit(selector: string): boolean;
|
|
72
|
+
export declare function fleetCandidatesByQuery(rows: SessionMeta[], query: string, trustResolvedRows?: boolean): FleetSessionCandidate[];
|
|
73
|
+
export declare function metadataResolveForwardedArgs(selector: string, scope: Pick<SessionFilterOptions, 'agent' | 'project'>): string[];
|
|
74
|
+
export declare function isUniqueEnoughSelector(selector: string): boolean;
|
|
75
|
+
export declare function metadataResolveOutcome(localMatches: SessionMeta[], remote: {
|
|
76
|
+
sessions: SessionMeta[];
|
|
77
|
+
unreachable: string[];
|
|
78
|
+
}, selector: string): MetadataResolveOutcome;
|
|
79
|
+
export declare function isLocallyDefinitiveMatch(session: SessionMeta, self: string): boolean;
|
|
80
|
+
export declare function preferOwnerAttribution(localMatches: SessionMeta[], remoteSessions: SessionMeta[], self: string): SessionMeta[];
|
|
81
|
+
export type LiveMetadataDeps = {
|
|
82
|
+
loadActive?: typeof loadLocalActiveSessions;
|
|
83
|
+
loadFleetActive?: () => ActiveSession[];
|
|
84
|
+
};
|
|
85
|
+
export declare function computeLocalMetadataMatches(selector: string, scope: {
|
|
86
|
+
agent?: string;
|
|
87
|
+
project?: string;
|
|
88
|
+
local?: boolean;
|
|
89
|
+
hosts?: string[];
|
|
90
|
+
}, deps?: LiveMetadataDeps): Promise<SessionMeta[]>;
|
|
91
|
+
export declare function liveMetadataMatches(selector: string, scope: {
|
|
92
|
+
agent?: string;
|
|
93
|
+
project?: string;
|
|
94
|
+
}, self: string, deps?: LiveMetadataDeps): Promise<SessionMeta[]>;
|
|
95
|
+
export declare function resolveSessionMetadataValue(selector: string, scope?: {
|
|
96
|
+
agent?: string;
|
|
97
|
+
project?: string;
|
|
98
|
+
local?: boolean;
|
|
99
|
+
hosts?: string[];
|
|
100
|
+
}, deps?: Pick<FleetResolveDeps, 'gatherRemoteList'> & LiveMetadataDeps): Promise<MetadataResolveOutcome>;
|
|
101
|
+
export declare function matchesTeam(session: SessionMeta, team: string): boolean;
|
|
102
|
+
export {};
|