@phnx-labs/agents-cli 1.23.23 → 1.23.25

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/commands/exec.js +1 -1
  3. package/dist/commands/fork.js +9 -0
  4. package/dist/commands/go.js +2 -1
  5. package/dist/commands/ps.js +2 -2
  6. package/dist/commands/run-device-picker.js +2 -1
  7. package/dist/commands/ssh.js +5 -3
  8. package/dist/lib/devices/health-report.js +2 -0
  9. package/dist/lib/devices/health.d.ts +5 -1
  10. package/dist/lib/devices/health.js +17 -3
  11. package/dist/lib/devices/pool.d.ts +5 -0
  12. package/dist/lib/devices/pool.js +26 -13
  13. package/dist/lib/devices/worker-pick.d.ts +2 -1
  14. package/dist/lib/devices/worker-pick.js +6 -4
  15. package/dist/lib/exec.d.ts +1 -0
  16. package/dist/lib/exec.js +4 -3
  17. package/dist/lib/hosts/option.d.ts +2 -1
  18. package/dist/lib/hosts/option.js +9 -1
  19. package/dist/lib/hosts/passthrough.js +2 -4
  20. package/dist/lib/hosts/routing-flag.d.ts +2 -0
  21. package/dist/lib/hosts/routing-flag.js +8 -1
  22. package/dist/lib/session/active.d.ts +7 -0
  23. package/dist/lib/session/active.js +49 -41
  24. package/dist/lib/session/db.d.ts +8 -2
  25. package/dist/lib/session/db.js +32 -28
  26. package/dist/lib/session/discover.d.ts +7 -2
  27. package/dist/lib/session/discover.js +61 -39
  28. package/dist/lib/session/migrate-targets.js +2 -1
  29. package/dist/lib/session/presentation.js +2 -0
  30. package/dist/lib/session/title.d.ts +14 -0
  31. package/dist/lib/session/title.js +32 -0
  32. package/dist/lib/smart-launch.js +8 -5
  33. package/dist/lib/teams/agents.js +2 -1
  34. package/dist/lib/teams/api.js +5 -4
  35. package/dist/lib/teams/placement-probe.js +1 -0
  36. package/dist/lib/teams/scheduler.d.ts +3 -2
  37. package/dist/lib/teams/scheduler.js +9 -6
  38. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
+ import { cleanFirstUserMessage, cleanGeneratedSessionLabel } from '@phnx-labs/sessions-cli/reader';
2
3
  export const SESSION_TITLE_PROMPT_MARKER = 'Generate a concise session headline';
3
4
  export const SESSION_TITLE_MAX_CHARS = 60;
4
5
  export const SESSION_TITLE_MAX_WORDS = 8;
@@ -70,6 +71,37 @@ export function sanitizeGeneratedTitle(raw) {
70
71
  export function sessionHeadline(row) {
71
72
  return row.label || row.generatedTitle || row.topic || undefined;
72
73
  }
74
+ function nonEmpty(s) {
75
+ return s?.trim() || undefined;
76
+ }
77
+ export function resolveSessionName(n) {
78
+ const liveName = n.live && n.live.source !== 'derived' ? nonEmpty(n.live.name) : undefined;
79
+ return (n.live?.source === 'user' ? liveName : undefined)
80
+ ?? nonEmpty(n.customTitle)
81
+ ?? liveName
82
+ ?? nonEmpty(n.indexed)
83
+ ?? nonEmpty(n.launchName)
84
+ ?? cleanGeneratedSessionLabel(n.aiTitle ?? undefined);
85
+ }
86
+ export const STARTED_AS_MAX_CHARS = 280;
87
+ const COMMAND_RE = /<command-name>\s*(\/[^<\s]+)\s*<\/command-name>[\s\S]*?(?:<command-args>([\s\S]*?)<\/command-args>|$)/;
88
+ export function startedAsFromUserTurn(text) {
89
+ const command = COMMAND_RE.exec(text);
90
+ let prompt;
91
+ if (command) {
92
+ const args = command[2]?.trim();
93
+ if (!args)
94
+ return undefined;
95
+ prompt = command[1] === '/goal' ? args : `${command[1]} ${args}`;
96
+ }
97
+ else {
98
+ prompt = cleanFirstUserMessage(text);
99
+ }
100
+ const flat = prompt?.replace(/\s+/g, ' ').trim();
101
+ if (!flat)
102
+ return undefined;
103
+ return flat.length > STARTED_AS_MAX_CHARS ? `${flat.slice(0, STARTED_AS_MAX_CHARS - 1).trimEnd()}…` : flat;
104
+ }
73
105
  export async function resolveSessionTitleAgent() {
74
106
  const { listInstalledVersions } = await import('../installations/store.js');
75
107
  for (const agent of SESSION_TITLE_AGENTS) {
@@ -1,6 +1,7 @@
1
1
  import { queryAffinityRollup } from './session/db.js';
2
2
  import { localMachineId } from './session/origin-machine.js';
3
3
  import { loadDevicesSync } from './devices/registry.js';
4
+ import { blocksPlacement } from './devices/health.js';
4
5
  import { autoLaunchPreferredSet, describeAutoPool, filterAutoPool, isAutoPoolMember } from './devices/pool.js';
5
6
  import { normalizeHost } from './machine-id.js';
6
7
  import { probePoolSignals } from './teams/placement-probe.js';
@@ -56,7 +57,7 @@ export function formatNoHealthyDeviceError(pool, signals, agent) {
56
57
  const excluded = pool.map((key) => {
57
58
  const signal = signals.get(key);
58
59
  let reason;
59
- if (signal?.reachable === true && signal.headroom !== 'loaded' && signal.installed === undefined) {
60
+ if (signal?.reachable === true && !blocksPlacement(signal.headroom) && signal.installed === undefined) {
60
61
  if (signal.timedOut)
61
62
  timedOutCount++;
62
63
  reason = signal.timedOut ? 'readiness probe timed out' : 'readiness probe did not answer';
@@ -64,9 +65,11 @@ export function formatNoHealthyDeviceError(pool, signals, agent) {
64
65
  else if (signal?.reachable === true) {
65
66
  reason = signal.headroom === 'loaded'
66
67
  ? 'overloaded'
67
- : signal.installed !== true || signal.signedIn !== true
68
- ? `no ready harness account${signal.reason ? ` (${signal.reason})` : ''}`
69
- : 'ineligible';
68
+ : signal.headroom === 'disk-low'
69
+ ? 'disk low'
70
+ : signal.installed !== true || signal.signedIn !== true
71
+ ? `no ready harness account${signal.reason ? ` (${signal.reason})` : ''}`
72
+ : 'ineligible';
70
73
  }
71
74
  else if (signal?.timedOut) {
72
75
  timedOutCount++;
@@ -119,7 +122,7 @@ export async function resolveDeviceAuto(agent, opts = {}) {
119
122
  }
120
123
  const eligiblePool = pool.filter((key) => {
121
124
  const signal = signals.get(key);
122
- if (signal?.reachable !== true || signal.headroom === 'loaded')
125
+ if (signal?.reachable !== true || blocksPlacement(signal.headroom))
123
126
  return false;
124
127
  if (!agent)
125
128
  return opts.probe ? true : signal.installed === true && signal.signedIn === true;
@@ -29,7 +29,7 @@ import { atomicWriteJsonSync } from '../fs-atomic.js';
29
29
  import { resolvePlacement, classifyExclusions, isTransientPlacementBlock, NoViableDeviceError, } from './scheduler.js';
30
30
  import { probePoolSignals } from './placement-probe.js';
31
31
  import { readMaxConcurrentCaps } from '../device-config.js';
32
- import { filterAutoPool, listWorkerDevices } from '../devices/pool.js';
32
+ import { autoLaunchPreferredSet, filterAutoPool, listWorkerDevices } from '../devices/pool.js';
33
33
  import { redactSecrets, sanitizeForTerminal } from '../redact.js';
34
34
  import chalk from 'chalk';
35
35
  let lastMemoryWarnAt = 0;
@@ -1640,6 +1640,7 @@ export class AgentManager {
1640
1640
  const placeOpts = {
1641
1641
  maxConcurrent,
1642
1642
  signals,
1643
+ preferred: autoLaunchPreferredSet(pool, { roster: pool }),
1643
1644
  defaultDevices: pool,
1644
1645
  agentLabel: this.placementAgentLabel(agent),
1645
1646
  };
@@ -1,7 +1,8 @@
1
1
  import { AgentStatus, resolveMode } from './agents.js';
2
2
  import { getDelta } from './summarizer.js';
3
3
  import { debug } from './debug.js';
4
- import { buildClaudeLabelMap } from '../session/discover.js';
4
+ import { readClaudeLiveNames } from '../session/discover.js';
5
+ import { resolveSessionName } from '../session/title.js';
5
6
  import { resolveTeammateDelivery } from './delivery.js';
6
7
  import { hasUncommittedChanges } from './worktree.js';
7
8
  function truncateBashCommand(cmd, maxLen = 120) {
@@ -205,8 +206,8 @@ export async function handleStatus(manager, taskName, filter, since, parentSessi
205
206
  }
206
207
  }
207
208
  let maxTimestamp = since || new Date(0).toISOString();
208
- const claudeLabels = allAgents.some((agent) => agent.agentType === 'claude')
209
- ? buildClaudeLabelMap()
209
+ const claudeLiveNames = allAgents.some((agent) => agent.agentType === 'claude')
210
+ ? readClaudeLiveNames()
210
211
  : new Map();
211
212
  for (const agent of agents) {
212
213
  await agent.readNewEvents();
@@ -234,7 +235,7 @@ export async function handleStatus(manager, taskName, filter, since, parentSessi
234
235
  version: agent.version,
235
236
  remote_session_id: agent.remoteSessionId,
236
237
  session_label: agent.remoteSessionId
237
- ? claudeLabels.get(agent.remoteSessionId) ?? null
238
+ ? resolveSessionName({ live: claudeLiveNames.get(agent.remoteSessionId) }) ?? null
238
239
  : null,
239
240
  name: agent.name,
240
241
  after: agent.after,
@@ -83,6 +83,7 @@ export function mergePlacementSignal(stats, readiness) {
83
83
  headroom: stats ? headroom(stats) : undefined,
84
84
  loadPercent: stats?.loadPercent,
85
85
  memPercent: stats?.memPercent,
86
+ memFreeBytes: stats?.memFreeBytes,
86
87
  installed: readiness?.installed,
87
88
  signedIn: readiness?.signedIn,
88
89
  pickerEligible: readiness?.pickerEligible,
@@ -1,10 +1,11 @@
1
- import type { Headroom } from '../devices/health.js';
1
+ import { type Headroom } from '../devices/health.js';
2
2
  export interface DevicePlacementSignal {
3
3
  reachable?: boolean;
4
4
  timedOut?: boolean;
5
5
  headroom?: Headroom;
6
6
  loadPercent?: number;
7
7
  memPercent?: number;
8
+ memFreeBytes?: number;
8
9
  installed?: boolean;
9
10
  signedIn?: boolean;
10
11
  pickerEligible?: boolean;
@@ -20,7 +21,7 @@ interface PlacementOptions {
20
21
  agentLabel?: string;
21
22
  preferred?: ReadonlySet<string>;
22
23
  }
23
- type ExclusionReason = 'unreachable' | 'probe-timed-out' | 'overloaded' | 'capped' | 'not-installed';
24
+ type ExclusionReason = 'unreachable' | 'probe-timed-out' | 'overloaded' | 'disk-low' | 'capped' | 'not-installed';
24
25
  interface ExcludedDevice {
25
26
  device: string;
26
27
  reason: ExclusionReason;
@@ -1,4 +1,5 @@
1
- import { machineId } from '../machine-id.js';
1
+ import { machineId, normalizeHost } from '../machine-id.js';
2
+ import { blocksPlacement, memPressurePercent } from '../devices/health.js';
2
3
  export class NoViableDeviceError extends Error {
3
4
  excluded;
4
5
  agentLabel;
@@ -32,7 +33,9 @@ export function formatNoViableMessage(excluded, agentLabel) {
32
33
  ? " Add a device to the pool, raise a cap, or wait for the pool to free up / come back online ('agents devices ping')."
33
34
  : allCapped
34
35
  ? " Raise a cap with 'agents devices config <name> agents.max-concurrent N' or add a device to the pool."
35
- : ' Add a device to the pool, raise a cap, or bring an overloaded box under load.';
36
+ : excluded.some((e) => e.reason === 'disk-low')
37
+ ? ' Free disk on a disk-low box (agents need at least 20G free), or add a device to the pool.'
38
+ : ' Add a device to the pool, raise a cap, or bring an overloaded box under load.';
36
39
  const reasons = allCapped
37
40
  ? excluded.map((e) => `${e.device} (${e.detail})`).join(', ')
38
41
  : perDevice;
@@ -97,7 +100,7 @@ export function pickLeastLoaded(devices, roster, maxConcurrent) {
97
100
  function loadCost(s) {
98
101
  if (!s)
99
102
  return undefined;
100
- const vals = [s.loadPercent, s.memPercent].filter((v) => typeof v === 'number');
103
+ const vals = [s.loadPercent, memPressurePercent(s)].filter((v) => typeof v === 'number');
101
104
  return vals.length ? Math.max(...vals) : undefined;
102
105
  }
103
106
  function headroomTier(h) {
@@ -124,8 +127,8 @@ export function classifyExclusions(devices, roster, opts) {
124
127
  excluded.push({ device: d, reason: 'not-installed' });
125
128
  continue;
126
129
  }
127
- if (s?.headroom === 'loaded') {
128
- excluded.push({ device: d, reason: 'overloaded' });
130
+ if (blocksPlacement(s?.headroom)) {
131
+ excluded.push({ device: d, reason: s?.headroom === 'disk-low' ? 'disk-low' : 'overloaded' });
129
132
  continue;
130
133
  }
131
134
  const cap = caps[d];
@@ -169,7 +172,7 @@ export function pickBestDevice(devices, roster, opts) {
169
172
  return signedIn;
170
173
  const preferred = opts?.preferred;
171
174
  if (preferred && preferred.size > 0) {
172
- const pref = (preferred.has(a) ? 0 : 1) - (preferred.has(b) ? 0 : 1);
175
+ const pref = (preferred.has(normalizeHost(a)) ? 0 : 1) - (preferred.has(normalizeHost(b)) ? 0 : 1);
173
176
  if (pref !== 0)
174
177
  return pref;
175
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.23",
3
+ "version": "1.23.25",
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",
@@ -89,7 +89,7 @@
89
89
  "@fontsource/jetbrains-mono": "^5.3.0",
90
90
  "@inquirer/prompts": "8.5.2",
91
91
  "@phnx-labs/secrets-cli": "0.4.0",
92
- "@phnx-labs/sessions-cli": "0.8.4",
92
+ "@phnx-labs/sessions-cli": "0.8.6",
93
93
  "@resvg/resvg-wasm": "^2.6.2",
94
94
  "@types/proper-lockfile": "4.1.4",
95
95
  "@zed-industries/agent-client-protocol": "0.4.5",