@phnx-labs/agents-cli 1.22.125 → 1.22.127
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 +24 -0
- package/dist/index.js +2 -1
- package/dist/lib/accounting/usage-ingest.js +2 -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 +2 -0
- package/dist/lib/session/active.js +37 -8
- package/dist/lib/stdout.d.ts +1 -0
- package/dist/lib/stdout.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.22.127
|
|
4
|
+
|
|
5
|
+
- **A peer's fleet-state reply now arrives whole over ssh.** `agents __usage-ingest --reply`
|
|
6
|
+
and `agents __usage-export` exited before stdout drained, so a reply larger than one pipe
|
|
7
|
+
buffer was cut at 65,536 bytes and the dialing box logged "malformed JSON payload" for every
|
|
8
|
+
peer. That left peer state stale, which blocked worker owner-notify tokens from minting. Both
|
|
9
|
+
verbs now wait for stdout to flush before exiting. Source: `cli/src/lib/stdout.ts`.
|
|
10
|
+
|
|
11
|
+
## 1.22.126
|
|
12
|
+
|
|
13
|
+
- **Liveness checks no longer spawn one `ps` per session (PHNX-4225).** Every PID-reuse check
|
|
14
|
+
ran a synchronous `ps -o lstart= -p <pid>` per live session, and several daemon services
|
|
15
|
+
(session state, the feed's tool activity, the recordings settler) repeat that scan. On a busy
|
|
16
|
+
laptop with ~100 live sessions those spawns blocked the event loop past the 5–10 s service
|
|
17
|
+
deadlines, so the supervisor kept restarting the daemon. Start times now come from one
|
|
18
|
+
`ps -A -o pid=,lstart=` per 30 s (35 ms for 2,050 processes on that laptop), with a single
|
|
19
|
+
per-pid read only for a process that started after the snapshot.
|
|
20
|
+
Source: `cli/src/lib/session/active.ts`.
|
|
21
|
+
|
|
22
|
+
- **A worker that keeps rejecting its owner-notify token is no longer re-minted every exchange.**
|
|
23
|
+
After a worker reports three pushed device tokens unusable in a row, the minting box waits six
|
|
24
|
+
hours before the next attempt and says so in its skip reason; the count resets once the worker
|
|
25
|
+
reports a working token. Source: `cli/src/lib/owner-notify-tokens.ts`.
|
|
26
|
+
|
|
3
27
|
## 1.22.125
|
|
4
28
|
|
|
5
29
|
- **`agents ps focus <id>` jumps to the VSCodium tab that holds the session.** It used to
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,8 @@ if (process.argv[2] === '__usage-ingest') {
|
|
|
34
34
|
}
|
|
35
35
|
if (process.argv[2] === '__usage-export') {
|
|
36
36
|
const { exportClaudeUsageCacheRows } = await import('./lib/accounting/usage.js');
|
|
37
|
-
|
|
37
|
+
const { writeStdoutFlushed } = await import('./lib/stdout.js');
|
|
38
|
+
await writeStdoutFlushed(JSON.stringify({ v: 1, rows: exportClaudeUsageCacheRows() }));
|
|
38
39
|
process.exit(0);
|
|
39
40
|
}
|
|
40
41
|
if (process.argv[2] === '__harness-update-run') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { REMOTE_STDOUT_MAX_BYTES, RemoteUtf8Accumulator } from '../ssh-exec.js';
|
|
3
|
+
import { writeStdoutFlushed } from '../stdout.js';
|
|
3
4
|
import { ingestPeerClaudeUsageRows } from './usage.js';
|
|
4
5
|
import { applyPeerFleetState, buildFleetStatePayload, formatFleetStateReply, parseFleetStateExchangeInput, publishOwnFleetState, } from './usage-sync.js';
|
|
5
6
|
export class UsageIngestInputTooLargeError extends Error {
|
|
@@ -98,6 +99,6 @@ export async function runUsageIngest(argv = process.argv.slice(3)) {
|
|
|
98
99
|
errors.push(...published.errors);
|
|
99
100
|
for (const message of published.errors)
|
|
100
101
|
process.stderr.write(`[agents] __usage-ingest: ${message}\n`);
|
|
101
|
-
|
|
102
|
+
await writeStdoutFlushed(formatFleetStateReply(buildFleetStatePayload({ errors })));
|
|
102
103
|
return 0;
|
|
103
104
|
}
|
|
@@ -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
|
}
|
|
@@ -171,6 +171,8 @@ export declare function resolveNamesToSessionIds(sessionNames: string[], deps: {
|
|
|
171
171
|
id: string;
|
|
172
172
|
}>;
|
|
173
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;
|
|
174
176
|
export declare function isPidAlive(pid: number, startedAtMs?: number): boolean;
|
|
175
177
|
export declare function pickClaudeSessionFileAcrossRoots(projectRoots: string[], cwd: string, sessionId?: string): string | undefined;
|
|
176
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)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeStdoutFlushed(text: string): Promise<void>;
|
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.127",
|
|
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",
|