@phnx-labs/agents-cli 1.22.124 → 1.22.125

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.22.125
4
+
5
+ - **`agents ps focus <id>` jumps to the VSCodium tab that holds the session.** It used to
6
+ stop at "no attach rail (not tmux/Ghostty)" for a session in an editor tab, or, without
7
+ `--attach-only`, start a duplicate copy of a running session in a new terminal. A session
8
+ running on another device through a local tab tried a tmux pane on that device instead.
9
+ Focus now finds the tab on this machine (by session id, or by the tab a `--device` run
10
+ was launched from), brings its window to the front and selects it. The same applies to
11
+ `agents://session/<id>` links, which focus a local tab before sweeping the fleet when the
12
+ id (at least the 8-character short id) names exactly one live tab here, even if the link
13
+ names another host. `agents sessions --active --json` rows from an editor tab carry
14
+ `workspaceDir`, the window's folder.
15
+
3
16
  ## 1.22.124
4
17
 
5
18
  - **The one-time `humans.yaml` upload now carries your channels and quiet hours (PHNX-4267).**
@@ -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;
@@ -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>;
@@ -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) {
@@ -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;
@@ -715,6 +715,7 @@ export async function listTerminalsActive() {
715
715
  startedAtMs: pidEntry?.startedAtMs ?? t.startedAtMs,
716
716
  lastActivityMs: sessionFileTimes(sessionFile).mtimeMs,
717
717
  windowId: t.windowId,
718
+ workspaceDir: t.cwd ?? undefined,
718
719
  windowHeartbeatMs: t.windowHeartbeatMs,
719
720
  owner: resolveOwner(pidEntry?.actor, resolvedId),
720
721
  }, 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.124",
3
+ "version": "1.22.125",
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",