@phnx-labs/agents-cli 1.22.124 → 1.22.126
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 +29 -0
- package/dist/commands/focus.js +6 -1
- package/dist/commands/go.d.ts +5 -0
- package/dist/commands/go.js +42 -1
- package/dist/lib/owner-notify-tokens.d.ts +2 -0
- package/dist/lib/owner-notify-tokens.js +17 -1
- package/dist/lib/session/active.d.ts +3 -0
- package/dist/lib/session/active.js +38 -8
- package/dist/lib/terminal/backends/vscodium-agent.d.ts +4 -1
- package/dist/lib/terminal/backends/vscodium-agent.js +14 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.22.126
|
|
4
|
+
|
|
5
|
+
- **Liveness checks no longer spawn one `ps` per session (PHNX-4225).** Every PID-reuse check
|
|
6
|
+
ran a synchronous `ps -o lstart= -p <pid>` per live session, and several daemon services
|
|
7
|
+
(session state, the feed's tool activity, the recordings settler) repeat that scan. On a busy
|
|
8
|
+
laptop with ~100 live sessions those spawns blocked the event loop past the 5–10 s service
|
|
9
|
+
deadlines, so the supervisor kept restarting the daemon. Start times now come from one
|
|
10
|
+
`ps -A -o pid=,lstart=` per 30 s (35 ms for 2,050 processes on that laptop), with a single
|
|
11
|
+
per-pid read only for a process that started after the snapshot.
|
|
12
|
+
Source: `cli/src/lib/session/active.ts`.
|
|
13
|
+
|
|
14
|
+
- **A worker that keeps rejecting its owner-notify token is no longer re-minted every exchange.**
|
|
15
|
+
After a worker reports three pushed device tokens unusable in a row, the minting box waits six
|
|
16
|
+
hours before the next attempt and says so in its skip reason; the count resets once the worker
|
|
17
|
+
reports a working token. Source: `cli/src/lib/owner-notify-tokens.ts`.
|
|
18
|
+
|
|
19
|
+
## 1.22.125
|
|
20
|
+
|
|
21
|
+
- **`agents ps focus <id>` jumps to the VSCodium tab that holds the session.** It used to
|
|
22
|
+
stop at "no attach rail (not tmux/Ghostty)" for a session in an editor tab, or, without
|
|
23
|
+
`--attach-only`, start a duplicate copy of a running session in a new terminal. A session
|
|
24
|
+
running on another device through a local tab tried a tmux pane on that device instead.
|
|
25
|
+
Focus now finds the tab on this machine (by session id, or by the tab a `--device` run
|
|
26
|
+
was launched from), brings its window to the front and selects it. The same applies to
|
|
27
|
+
`agents://session/<id>` links, which focus a local tab before sweeping the fleet when the
|
|
28
|
+
id (at least the 8-character short id) names exactly one live tab here, even if the link
|
|
29
|
+
names another host. `agents sessions --active --json` rows from an editor tab carry
|
|
30
|
+
`workspaceDir`, the window's folder.
|
|
31
|
+
|
|
3
32
|
## 1.22.124
|
|
4
33
|
|
|
5
34
|
- **The one-time `humans.yaml` upload now carries your channels and quiet hours (PHNX-4267).**
|
package/dist/commands/focus.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { confirm } from '@inquirer/prompts';
|
|
4
|
-
import { gatherLiveTargets, pickLiveTarget, pickLiveTargets, jumpTo, probeAttachRail, refuseFallback } from './go.js';
|
|
4
|
+
import { gatherLiveTargets, pickLiveTarget, pickLiveTargets, jumpTo, focusEditorTabOf, focusLocalEditorTab, probeAttachRail, refuseFallback } from './go.js';
|
|
5
5
|
import { sessionProcessIsLocal, sessionProcessHost, shortIdFromName } from '../lib/session/active.js';
|
|
6
6
|
import { isAgentTmuxAlias } from '@phnx-labs/sessions-cli/reader';
|
|
7
7
|
import { attachLocalLiveSelector } from '../lib/session/local-tmux-attach.js';
|
|
@@ -179,6 +179,9 @@ export async function focusAction(id, opts) {
|
|
|
179
179
|
if (await attachLocalLiveSelector(textSelector, hosts)) {
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
|
+
if (textSelector && looksLikeIdSelector(textSelector) && await focusLocalEditorTab(textSelector)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
182
185
|
if (idLookup && hosts.length === 0 && looksLikeIdSelector(textSelector)) {
|
|
183
186
|
const self = machineId();
|
|
184
187
|
const localMatch = dedupeSessionsByLogicalId(await resolveIndexedSessionById(textSelector), self);
|
|
@@ -382,6 +385,8 @@ export async function focusResolvedSession(meta, liveById, self, fallback, attac
|
|
|
382
385
|
await jumpTo(active, self, fallback, meta.id);
|
|
383
386
|
return;
|
|
384
387
|
}
|
|
388
|
+
if (active && await focusEditorTabOf(active, self))
|
|
389
|
+
return;
|
|
385
390
|
if (attachOnly) {
|
|
386
391
|
console.log(chalk.yellow(`${meta.shortId} has no living process or pane to attach.`));
|
|
387
392
|
process.exitCode = 1;
|
package/dist/commands/go.d.ts
CHANGED
|
@@ -37,4 +37,9 @@ export type AttachRailLiveness = {
|
|
|
37
37
|
};
|
|
38
38
|
export declare function probeAttachRail(s: ActiveSession, self: string): Promise<AttachRailLiveness>;
|
|
39
39
|
export declare function refuseFallback(s: ActiveSession, remote: string | undefined, fallbackId?: string): Promise<void>;
|
|
40
|
+
export declare const EDITOR_TAB_SELECTOR_MIN = 8;
|
|
41
|
+
export declare function matchEditorTab(s: ActiveSession, self: string, tabs: ActiveSession[], nowMs?: number): ActiveSession | undefined;
|
|
42
|
+
export declare function editorTabsForSelector(selector: string, tabs: ActiveSession[], nowMs?: number): ActiveSession[];
|
|
43
|
+
export declare function focusEditorTabOf(s: ActiveSession, self: string): Promise<boolean>;
|
|
44
|
+
export declare function focusLocalEditorTab(selector: string): Promise<boolean>;
|
|
40
45
|
export declare function jumpTo(s: ActiveSession, self: string, fallback?: UnreachableFallback, fallbackId?: string): Promise<void>;
|
package/dist/commands/go.js
CHANGED
|
@@ -2,7 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { execFile } from 'child_process';
|
|
4
4
|
import { promisify } from 'util';
|
|
5
|
-
import { getActiveSessions, findSessionFileForKind, sessionProcessIsLocal, sessionProcessHost } from '../lib/session/active.js';
|
|
5
|
+
import { getActiveSessions, findSessionFileForKind, listTerminalsActive, sessionProcessIsLocal, sessionProcessHost } from '../lib/session/active.js';
|
|
6
6
|
import { isSessionIdShape } from '../lib/session/pid-registry.js';
|
|
7
7
|
import { gatherRemoteActive } from '../lib/session/remote-active.js';
|
|
8
8
|
import { discoverSessions } from '../lib/session/discover.js';
|
|
@@ -20,6 +20,10 @@ import { sshExec, sshStream, assertValidSshTarget, shellQuote, SSH_CONN_FAILURE_
|
|
|
20
20
|
import { connectionEndedNotice } from '../lib/hosts/reconnect.js';
|
|
21
21
|
import { enumerateGhosttyTabs, assignGhosttyTabs } from '../lib/session/ghostty-tabs.js';
|
|
22
22
|
import { addressabilityRecoveryHint } from '../lib/terminal/resolve.js';
|
|
23
|
+
import { editorVariantForHost, focusTabSpecs } from '../lib/terminal/backends/vscodium-agent.js';
|
|
24
|
+
import { runLocal } from '../lib/terminal/transport.js';
|
|
25
|
+
import { sessionHeadline } from '../lib/session/title.js';
|
|
26
|
+
import { HOST_HEARTBEAT_STALE_MS } from '../lib/session/host-link.js';
|
|
23
27
|
const execFileAsync = promisify(execFile);
|
|
24
28
|
export function filterLivePool(sessions, opts = {}) {
|
|
25
29
|
let out = sessions;
|
|
@@ -220,7 +224,44 @@ export async function refuseFallback(s, remote, fallbackId) {
|
|
|
220
224
|
chalk.gray(`\n${addressabilityRecoveryHint(s, fallbackId)}`));
|
|
221
225
|
process.exitCode = 1;
|
|
222
226
|
}
|
|
227
|
+
export const EDITOR_TAB_SELECTOR_MIN = 8;
|
|
228
|
+
function isFocusableEditorTab(t, nowMs) {
|
|
229
|
+
const windowLive = t.windowHeartbeatMs !== undefined && nowMs - t.windowHeartbeatMs < HOST_HEARTBEAT_STALE_MS;
|
|
230
|
+
return !!(editorVariantForHost(t.host) && t.terminalId && t.workspaceDir && t.pidAlive && windowLive);
|
|
231
|
+
}
|
|
232
|
+
export function matchEditorTab(s, self, tabs, nowMs = Date.now()) {
|
|
233
|
+
const originTab = s.originTerminal?.device === self ? s.originTerminal.terminalId : undefined;
|
|
234
|
+
return tabs.find((t) => isFocusableEditorTab(t, nowMs) &&
|
|
235
|
+
((s.sessionId && t.sessionId === s.sessionId) || (originTab && t.terminalId === originTab)));
|
|
236
|
+
}
|
|
237
|
+
export function editorTabsForSelector(selector, tabs, nowMs = Date.now()) {
|
|
238
|
+
if (selector.length < EDITOR_TAB_SELECTOR_MIN)
|
|
239
|
+
return [];
|
|
240
|
+
return tabs.filter((t) => isFocusableEditorTab(t, nowMs) && t.sessionId?.startsWith(selector));
|
|
241
|
+
}
|
|
242
|
+
async function focusEditorTab(tab) {
|
|
243
|
+
const variant = editorVariantForHost(tab.host);
|
|
244
|
+
for (const spec of focusTabSpecs(variant, tab.workspaceDir, tab.terminalId)) {
|
|
245
|
+
const result = await runLocal(spec, 10_000);
|
|
246
|
+
if (!result.ok) {
|
|
247
|
+
console.error(chalk.yellow(`Could not focus ${variant.label} tab ${tab.terminalId}: ${result.error}. Trying the other rails.`));
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
console.log(chalk.gray(`Sent ${shortId(tab)} → ${sessionHeadline(tab) || tab.terminalId} (${path.basename(tab.workspaceDir)}) to ${variant.label}.`));
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
export async function focusEditorTabOf(s, self) {
|
|
255
|
+
const tab = matchEditorTab(s, self, await listTerminalsActive());
|
|
256
|
+
return tab ? focusEditorTab(tab) : false;
|
|
257
|
+
}
|
|
258
|
+
export async function focusLocalEditorTab(selector) {
|
|
259
|
+
const matches = editorTabsForSelector(selector, await listTerminalsActive());
|
|
260
|
+
return matches.length === 1 ? focusEditorTab(matches[0]) : false;
|
|
261
|
+
}
|
|
223
262
|
export async function jumpTo(s, self, fallback = refuseFallback, fallbackId) {
|
|
263
|
+
if (await focusEditorTabOf(s, self))
|
|
264
|
+
return;
|
|
224
265
|
const remote = sessionProcessHost(s, self);
|
|
225
266
|
const mux = s.provenance?.mux;
|
|
226
267
|
if (remote) {
|
|
@@ -38,6 +38,8 @@ interface OwnerNotifySyncDeps {
|
|
|
38
38
|
sshTarget?: (device: DeviceProfile) => string;
|
|
39
39
|
now?: () => number;
|
|
40
40
|
}
|
|
41
|
+
export declare const OWNER_NOTIFY_REJECT_BACKOFF_AFTER = 3;
|
|
42
|
+
export declare const OWNER_NOTIFY_REJECT_BACKOFF_MS: number;
|
|
41
43
|
export declare function syncOwnerNotifyTokens(deps?: OwnerNotifySyncDeps): Promise<OwnerNotifySyncResult>;
|
|
42
44
|
export declare function revokeMintedOwnerNotifyTokens(cacheDir?: string): Promise<{
|
|
43
45
|
revoked: string[];
|
|
@@ -31,6 +31,8 @@ export function electOwnerNotifyMinter(signedInHeaded) {
|
|
|
31
31
|
function memoPath(root) {
|
|
32
32
|
return path.join(root, 'owner-notify-minted.json');
|
|
33
33
|
}
|
|
34
|
+
export const OWNER_NOTIFY_REJECT_BACKOFF_AFTER = 3;
|
|
35
|
+
export const OWNER_NOTIFY_REJECT_BACKOFF_MS = 6 * 60 * 60 * 1000;
|
|
34
36
|
function readMemo(root) {
|
|
35
37
|
try {
|
|
36
38
|
const parsed = JSON.parse(fs.readFileSync(memoPath(root), 'utf-8'));
|
|
@@ -134,6 +136,10 @@ export async function syncOwnerNotifyTokens(deps = {}) {
|
|
|
134
136
|
continue;
|
|
135
137
|
}
|
|
136
138
|
if (peerState.deviceToken) {
|
|
139
|
+
if (memo[name]?.rejected) {
|
|
140
|
+
memo[name] = { ...memo[name], rejected: 0 };
|
|
141
|
+
writeMemo(cacheDir, memo);
|
|
142
|
+
}
|
|
137
143
|
result.skipped.push({ device: worker.name, reason: 'token present' });
|
|
138
144
|
continue;
|
|
139
145
|
}
|
|
@@ -146,6 +152,16 @@ export async function syncOwnerNotifyTokens(deps = {}) {
|
|
|
146
152
|
result.skipped.push({ device: worker.name, reason: 'waiting for the worker to report the pushed token' });
|
|
147
153
|
continue;
|
|
148
154
|
}
|
|
155
|
+
const rejectedSoFar = held?.rejected ?? 0;
|
|
156
|
+
if (rejectedSoFar >= OWNER_NOTIFY_REJECT_BACKOFF_AFTER && held?.pushedAt !== undefined
|
|
157
|
+
&& now - held.pushedAt < OWNER_NOTIFY_REJECT_BACKOFF_MS) {
|
|
158
|
+
result.skipped.push({
|
|
159
|
+
device: worker.name,
|
|
160
|
+
reason: `worker rejected ${rejectedSoFar} pushed tokens in a row; next attempt after ${new Date(held.pushedAt + OWNER_NOTIFY_REJECT_BACKOFF_MS).toISOString()}`,
|
|
161
|
+
});
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const rejected = holdsLive && held.pushedAt !== undefined ? rejectedSoFar + 1 : rejectedSoFar;
|
|
149
165
|
if (onServer && !(holdsLive && held.pushedAt === undefined)) {
|
|
150
166
|
await revokeApiToken(onServer.id);
|
|
151
167
|
onServer = undefined;
|
|
@@ -159,7 +175,7 @@ export async function syncOwnerNotifyTokens(deps = {}) {
|
|
|
159
175
|
await revokeApiToken(minted.id);
|
|
160
176
|
throw err;
|
|
161
177
|
}
|
|
162
|
-
memo[name] = { id: minted.id };
|
|
178
|
+
memo[name] = { id: minted.id, rejected };
|
|
163
179
|
writeMemo(cacheDir, memo);
|
|
164
180
|
result.minted.push(worker.name);
|
|
165
181
|
}
|
|
@@ -134,6 +134,7 @@ export interface ActiveSession {
|
|
|
134
134
|
cloudTaskId?: string;
|
|
135
135
|
cloudStatus?: string;
|
|
136
136
|
windowId?: string;
|
|
137
|
+
workspaceDir?: string;
|
|
137
138
|
tty?: string;
|
|
138
139
|
ghosttyTab?: number;
|
|
139
140
|
tmuxTarget?: string;
|
|
@@ -170,6 +171,8 @@ export declare function resolveNamesToSessionIds(sessionNames: string[], deps: {
|
|
|
170
171
|
id: string;
|
|
171
172
|
}>;
|
|
172
173
|
}): Map<string, string>;
|
|
174
|
+
export declare const PROCESS_START_CACHE_TTL_MS = 30000;
|
|
175
|
+
export declare function processStartMs(pid: number, now?: number): number | null;
|
|
173
176
|
export declare function isPidAlive(pid: number, startedAtMs?: number): boolean;
|
|
174
177
|
export declare function pickClaudeSessionFileAcrossRoots(projectRoots: string[], cwd: string, sessionId?: string): string | undefined;
|
|
175
178
|
export declare function pickSessionFile(projectDir: string, sessionId?: string): string | undefined;
|
|
@@ -284,22 +284,51 @@ export function resolveNamesToSessionIds(sessionNames, deps) {
|
|
|
284
284
|
return out;
|
|
285
285
|
}
|
|
286
286
|
const PID_REUSE_TOLERANCE_MS = 60_000;
|
|
287
|
-
|
|
287
|
+
export const PROCESS_START_CACHE_TTL_MS = 30_000;
|
|
288
|
+
const processStartCache = new Map();
|
|
289
|
+
let processStartTableAt = Number.NEGATIVE_INFINITY;
|
|
290
|
+
function parseStartMs(text) {
|
|
291
|
+
const ms = text ? Date.parse(text) : NaN;
|
|
292
|
+
return Number.isFinite(ms) ? ms : null;
|
|
293
|
+
}
|
|
294
|
+
function readProcessStartTable(now) {
|
|
295
|
+
processStartCache.clear();
|
|
296
|
+
processStartTableAt = now;
|
|
297
|
+
try {
|
|
298
|
+
const out = execFileSync('ps', ['-A', '-o', 'pid=,lstart='], {
|
|
299
|
+
encoding: 'utf-8',
|
|
300
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
301
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
302
|
+
});
|
|
303
|
+
for (const line of out.split('\n')) {
|
|
304
|
+
const m = line.trim().match(/^(\d+)\s+(.+)$/);
|
|
305
|
+
if (m)
|
|
306
|
+
processStartCache.set(Number(m[1]), parseStartMs(m[2].trim()));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
processStartCache.clear();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
export function processStartMs(pid, now = Date.now()) {
|
|
288
314
|
if (process.platform === 'win32')
|
|
289
315
|
return null;
|
|
316
|
+
if (now - processStartTableAt >= PROCESS_START_CACHE_TTL_MS)
|
|
317
|
+
readProcessStartTable(now);
|
|
318
|
+
if (processStartCache.has(pid))
|
|
319
|
+
return processStartCache.get(pid);
|
|
320
|
+
let ms = null;
|
|
290
321
|
try {
|
|
291
|
-
|
|
322
|
+
ms = parseStartMs(execFileSync('ps', ['-o', 'lstart=', '-p', String(pid)], {
|
|
292
323
|
encoding: 'utf-8',
|
|
293
324
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
294
|
-
}).trim();
|
|
295
|
-
if (!out)
|
|
296
|
-
return null;
|
|
297
|
-
const ms = Date.parse(out);
|
|
298
|
-
return Number.isFinite(ms) ? ms : null;
|
|
325
|
+
}).trim());
|
|
299
326
|
}
|
|
300
327
|
catch {
|
|
301
|
-
|
|
328
|
+
ms = null;
|
|
302
329
|
}
|
|
330
|
+
processStartCache.set(pid, ms);
|
|
331
|
+
return ms;
|
|
303
332
|
}
|
|
304
333
|
export function isPidAlive(pid, startedAtMs) {
|
|
305
334
|
if (!pid || pid < 1)
|
|
@@ -715,6 +744,7 @@ export async function listTerminalsActive() {
|
|
|
715
744
|
startedAtMs: pidEntry?.startedAtMs ?? t.startedAtMs,
|
|
716
745
|
lastActivityMs: sessionFileTimes(sessionFile).mtimeMs,
|
|
717
746
|
windowId: t.windowId,
|
|
747
|
+
workspaceDir: t.cwd ?? undefined,
|
|
718
748
|
windowHeartbeatMs: t.windowHeartbeatMs,
|
|
719
749
|
owner: resolveOwner(pidEntry?.actor, resolvedId),
|
|
720
750
|
}, state, sessionFile, pidAlive)];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TerminalBackend, SplitDirection } from '../types.js';
|
|
1
|
+
import type { TerminalBackend, LaunchSpec, SplitDirection } from '../types.js';
|
|
2
2
|
export interface EditorVariant {
|
|
3
3
|
cli: string;
|
|
4
4
|
scheme: string;
|
|
@@ -11,5 +11,8 @@ export declare function spawnUri(scheme: string, cwd: string, command: string[],
|
|
|
11
11
|
sessionId?: string;
|
|
12
12
|
title?: string;
|
|
13
13
|
}): string;
|
|
14
|
+
export declare function editorVariantForHost(host: string | undefined): EditorVariant | undefined;
|
|
15
|
+
export declare function focusUri(scheme: string, terminalId: string): string;
|
|
16
|
+
export declare function focusTabSpecs(variant: EditorVariant, folder: string, terminalId: string): LaunchSpec[];
|
|
14
17
|
export declare function makeVscodiumAgentBackend(variant: EditorVariant): TerminalBackend;
|
|
15
18
|
export declare const vscodiumAgentBackend: TerminalBackend;
|
|
@@ -29,6 +29,20 @@ export function spawnUri(scheme, cwd, command, direction, meta) {
|
|
|
29
29
|
const p = Buffer.from(JSON.stringify(payload), 'utf8').toString('base64url');
|
|
30
30
|
return `${scheme}://${EXTENSION_AUTHORITY}/spawn?p=${p}`;
|
|
31
31
|
}
|
|
32
|
+
export function editorVariantForHost(host) {
|
|
33
|
+
return host ? EDITOR_VARIANTS.find((v) => v.cli === host) : undefined;
|
|
34
|
+
}
|
|
35
|
+
export function focusUri(scheme, terminalId) {
|
|
36
|
+
return `${scheme}://${EXTENSION_AUTHORITY}/focus?terminalId=${encodeURIComponent(terminalId)}`;
|
|
37
|
+
}
|
|
38
|
+
export function focusTabSpecs(variant, folder, terminalId) {
|
|
39
|
+
const bundled = `${variant.app}/Contents/Resources/app/bin/${variant.cli}`;
|
|
40
|
+
const cli = appExists(bundled) ? bundled : variant.cli;
|
|
41
|
+
return [
|
|
42
|
+
{ argv: [cli, folder] },
|
|
43
|
+
{ argv: [cli, '--open-url', focusUri(variant.scheme, terminalId)] },
|
|
44
|
+
];
|
|
45
|
+
}
|
|
32
46
|
export function makeVscodiumAgentBackend(variant) {
|
|
33
47
|
return {
|
|
34
48
|
id: 'vscodium-agent',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phnx-labs/agents-cli",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.126",
|
|
4
4
|
"description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|