@phnx-labs/agents-cli 1.23.1 → 1.23.3
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 +23 -0
- package/dist/lib/feed/tool-activity.d.ts +4 -2
- package/dist/lib/feed/tool-activity.js +142 -28
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/menubar/install-menubar.d.ts +1 -1
- package/dist/lib/menubar/install-menubar.js +24 -13
- package/package.json +1 -1
- package/dist/lib/linear-autoclose.d.ts +0 -5
- package/dist/lib/linear-autoclose.js +0 -3
- package/dist/lib/template.d.ts +0 -5
- package/dist/lib/template.js +0 -36
- package/dist/lib/version-duplicates.d.ts +0 -14
- package/dist/lib/version-duplicates.js +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.3
|
|
4
|
+
|
|
5
|
+
- **The daemon stops crash-looping on tool-row linking (PHNX-4225).** Every feed
|
|
6
|
+
reprojection linked each browser and computer row to its agent session with one
|
|
7
|
+
synchronous lookup per row, and rebuilt the launch-id index from every activity log
|
|
8
|
+
on the daemon's event loop. On a busy machine that held the loop for up to 21 s per
|
|
9
|
+
pass, so attention-notify missed its 10 s deadline and the daemon restarted about
|
|
10
|
+
every 20 s. Linking is now incremental and yields:
|
|
11
|
+
- A found session is reused for 60 to 120 s, with staggered expiry.
|
|
12
|
+
- A session-id miss is retried after 10 s.
|
|
13
|
+
- The launch-id index is rebuilt at most once a minute by an async scan that only
|
|
14
|
+
re-reads logs that changed, so a new launch id links within 60 s.
|
|
15
|
+
|
|
16
|
+
Measured on the affected machine: the longest event-loop stall per pass dropped from
|
|
17
|
+
587 ms to 62 ms cold and 1 ms warm, with identical links.
|
|
18
|
+
Source: `cli/src/lib/feed/tool-activity.ts`.
|
|
19
|
+
|
|
20
|
+
## 1.23.2
|
|
21
|
+
|
|
22
|
+
- **AGI Menu 1.15.21: Restart AGI Menu, and Quit no longer turns it off (PHNX-4325).** Settings → AGI Menu has a Restart button and the right-click menu has Restart AGI Menu (⌘R); both run `agents menubar restart`. Quit AGI Menu only quits, and the app returns at the next login. The new Turn off AGI Menu… asks first, then runs `agents menubar disable` as Quit used to. Settings → Tabs names the agents-cli version an unavailable tab needs. Several failing CLI calls finishing at once no longer crash the app. Source: `cli/src/lib/helper-versions.ts`.
|
|
23
|
+
|
|
24
|
+
- **Re-registering AGI Menu's login item no longer leaves the menu stopped.** `launchctl bootout` returns before launchd finishes removing the job, so the immediate `bootstrap` failed with `5: Input/output error` and the menu stayed down until the next login. Every setup, enable and startup repair that rewrites the plist took this path, including the one-time `KeepAlive` rewrite in 1.23.1. The CLI now waits for the old job to leave (up to 5 seconds), retries a refused bootstrap twice, and prints an error naming `agents menubar setup` if registration still fails. Source: `cli/src/lib/menubar/install-menubar.ts`.
|
|
25
|
+
|
|
3
26
|
## 1.23.1
|
|
4
27
|
|
|
5
28
|
- **`agents ps preview <id>` shows the rich session card (PHNX-4227).** It is the
|
|
@@ -9,12 +9,14 @@ export declare class ToolNotInstalledError extends Error {
|
|
|
9
9
|
export declare function readToolJson(tool: StandaloneTool, argv: string[]): Promise<unknown[]>;
|
|
10
10
|
export declare function readStandaloneBrowserRows(): Promise<BrowserSessionRow[]>;
|
|
11
11
|
export declare function readStandaloneComputerRows(): Promise<ComputerRunRow[]>;
|
|
12
|
-
|
|
12
|
+
export declare const TOOL_LINK_TTL_MS = 60000;
|
|
13
|
+
export declare const TOOL_LINK_MISS_TTL_MS = 10000;
|
|
14
|
+
export declare function _resetToolLinkCacheForTest(): void;
|
|
13
15
|
export declare function linkToolSessions<T extends {
|
|
14
16
|
sessionId?: string;
|
|
15
17
|
launchId?: string;
|
|
16
18
|
linkedSession?: SessionMeta;
|
|
17
|
-
}>(rows: T[]): T[]
|
|
19
|
+
}>(rows: T[], nowMs?: number): Promise<T[]>;
|
|
18
20
|
export interface ToolDiff {
|
|
19
21
|
upserts: ToolRow[];
|
|
20
22
|
removes: string[];
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
import { getBrowserRuntimeDir, getCacheDir } from '../state.js';
|
|
4
|
+
import { getActivityDir, getBrowserRuntimeDir, getCacheDir } from '../state.js';
|
|
5
5
|
import { getEventsDir } from './events.js';
|
|
6
|
-
import { readRecentActivity } from './activity.js';
|
|
7
6
|
import { span, spanSync } from '../daemon/diagnostics.js';
|
|
8
7
|
import { invocation as browserInvocation, resolveBrowserBin } from '../browser-client.js';
|
|
9
8
|
import { invocation as computerInvocation, resolveComputerBin } from '../computer-client.js';
|
|
@@ -89,40 +88,155 @@ export async function readStandaloneComputerRows() {
|
|
|
89
88
|
return row;
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
export const TOOL_LINK_TTL_MS = 60_000;
|
|
92
|
+
export const TOOL_LINK_MISS_TTL_MS = 10_000;
|
|
93
|
+
const LINK_YIELD_EVERY = 64;
|
|
94
|
+
const ACTIVITY_LAUNCH_TAIL_BYTES = 64 * 1024;
|
|
95
|
+
const linkCache = { metas: new Map(), launches: new Map(), indexBuiltAt: -Infinity, activity: new Map() };
|
|
96
|
+
export function _resetToolLinkCacheForTest() {
|
|
97
|
+
linkCache.metas.clear();
|
|
98
|
+
linkCache.launches = new Map();
|
|
99
|
+
linkCache.activity.clear();
|
|
100
|
+
linkCache.indexBuiltAt = -Infinity;
|
|
94
101
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
const yieldToLoop = () => new Promise((resolve) => setImmediate(resolve));
|
|
103
|
+
function expiryJitterMs(id) {
|
|
104
|
+
let hash = 0;
|
|
105
|
+
for (let i = 0; i < id.length; i++)
|
|
106
|
+
hash = (hash * 31 + id.charCodeAt(i)) >>> 0;
|
|
107
|
+
return hash % TOOL_LINK_TTL_MS;
|
|
108
|
+
}
|
|
109
|
+
function keepEarliest(into, launchId, sessionId, atMs) {
|
|
110
|
+
const prior = into.get(launchId);
|
|
111
|
+
if (!prior || atMs < prior.atMs)
|
|
112
|
+
into.set(launchId, { sessionId, atMs });
|
|
113
|
+
}
|
|
114
|
+
async function readLaunchPairs(file) {
|
|
115
|
+
const handle = await fs.promises.open(file, 'r');
|
|
116
|
+
try {
|
|
117
|
+
const { size } = await handle.stat();
|
|
118
|
+
const start = Math.max(0, size - ACTIVITY_LAUNCH_TAIL_BYTES);
|
|
119
|
+
const buf = Buffer.alloc(size - start);
|
|
120
|
+
await handle.read(buf, 0, buf.length, start);
|
|
121
|
+
const pairs = new Map();
|
|
122
|
+
for (const line of buf.toString('utf8').split('\n')) {
|
|
123
|
+
if (!line.includes('"launchId"'))
|
|
124
|
+
continue;
|
|
125
|
+
let event;
|
|
126
|
+
try {
|
|
127
|
+
event = JSON.parse(line);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (typeof event.launchId !== 'string' || !event.launchId || typeof event.sessionId !== 'string' || !event.sessionId)
|
|
133
|
+
continue;
|
|
134
|
+
if (!event.event || typeof event.ts !== 'string')
|
|
135
|
+
continue;
|
|
136
|
+
const atMs = Date.parse(event.ts);
|
|
137
|
+
if (Number.isFinite(atMs))
|
|
138
|
+
keepEarliest(pairs, event.launchId, event.sessionId, atMs);
|
|
139
|
+
}
|
|
140
|
+
return pairs;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
await handle.close();
|
|
100
144
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
}
|
|
146
|
+
async function refreshLaunchIndex(nowMs) {
|
|
147
|
+
const dir = getActivityDir();
|
|
148
|
+
let names;
|
|
149
|
+
try {
|
|
150
|
+
names = (await fs.promises.readdir(dir)).filter((name) => name.endsWith('.jsonl'));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (error.code !== 'ENOENT')
|
|
154
|
+
throw error;
|
|
155
|
+
names = [];
|
|
156
|
+
}
|
|
157
|
+
const present = new Set(names);
|
|
158
|
+
for (const name of linkCache.activity.keys())
|
|
159
|
+
if (!present.has(name))
|
|
160
|
+
linkCache.activity.delete(name);
|
|
161
|
+
for (const name of names) {
|
|
162
|
+
const file = path.join(dir, name);
|
|
163
|
+
let stat;
|
|
164
|
+
try {
|
|
165
|
+
stat = await fs.promises.stat(file);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
linkCache.activity.delete(name);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const stamp = `${stat.size}:${stat.mtimeMs}`;
|
|
172
|
+
if (linkCache.activity.get(name)?.stamp === stamp)
|
|
173
|
+
continue;
|
|
174
|
+
let pairs;
|
|
175
|
+
try {
|
|
176
|
+
pairs = await readLaunchPairs(file);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (error.code !== 'ENOENT')
|
|
180
|
+
throw error;
|
|
181
|
+
linkCache.activity.delete(name);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
linkCache.activity.set(name, { stamp, pairs });
|
|
104
185
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
186
|
+
const earliest = new Map();
|
|
187
|
+
for (const { pairs } of linkCache.activity.values()) {
|
|
188
|
+
for (const [launchId, { sessionId, atMs }] of pairs)
|
|
189
|
+
keepEarliest(earliest, launchId, sessionId, atMs);
|
|
108
190
|
}
|
|
109
|
-
|
|
191
|
+
const next = new Map();
|
|
192
|
+
for (const [launchId, { sessionId }] of earliest)
|
|
193
|
+
next.set(launchId, sessionId);
|
|
194
|
+
spanSync('feed.tools.launch-index.local', () => {
|
|
195
|
+
for (const [launchId, record] of loadHookSessionIndex().byLaunchId) {
|
|
196
|
+
if (record.session_id)
|
|
197
|
+
next.set(launchId, record.session_id);
|
|
198
|
+
}
|
|
199
|
+
for (const entry of listPidSessionEntries()) {
|
|
200
|
+
if (entry.launchId && entry.sessionId)
|
|
201
|
+
next.set(entry.launchId, entry.sessionId);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
linkCache.launches = next;
|
|
205
|
+
linkCache.indexBuiltAt = nowMs;
|
|
110
206
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return spanSync('feed.tools.link-sessions', () => linkToolSessionsNow(rows), () => ({ rows: rows.length }));
|
|
207
|
+
export function linkToolSessions(rows, nowMs = Date.now()) {
|
|
208
|
+
return span('feed.tools.link-sessions', () => linkToolSessionsNow(rows, nowMs), () => ({ rows: rows.length }));
|
|
114
209
|
}
|
|
115
|
-
function linkToolSessionsNow(rows) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
210
|
+
async function linkToolSessionsNow(rows, nowMs) {
|
|
211
|
+
for (const [id, entry] of linkCache.metas)
|
|
212
|
+
if (entry.expiresAt <= nowMs)
|
|
213
|
+
linkCache.metas.delete(id);
|
|
214
|
+
if (rows.some((row) => row.launchId) && nowMs - linkCache.indexBuiltAt >= TOOL_LINK_TTL_MS) {
|
|
215
|
+
linkCache.refreshing ??= span('feed.tools.launch-index', () => refreshLaunchIndex(nowMs))
|
|
216
|
+
.finally(() => { linkCache.refreshing = undefined; });
|
|
217
|
+
await linkCache.refreshing;
|
|
218
|
+
}
|
|
219
|
+
let lookups = 0;
|
|
220
|
+
const sessionFor = async (id) => {
|
|
221
|
+
const hit = linkCache.metas.get(id);
|
|
222
|
+
if (hit)
|
|
223
|
+
return hit.meta;
|
|
224
|
+
if (++lookups % LINK_YIELD_EVERY === 0)
|
|
225
|
+
await yieldToLoop();
|
|
226
|
+
const meta = getSessionById(id);
|
|
227
|
+
linkCache.metas.set(id, { meta, expiresAt: nowMs + (meta ? TOOL_LINK_TTL_MS + expiryJitterMs(id) : TOOL_LINK_MISS_TTL_MS) });
|
|
228
|
+
return meta;
|
|
229
|
+
};
|
|
230
|
+
const out = [];
|
|
231
|
+
for (const row of rows) {
|
|
232
|
+
let linked = row.sessionId ? await sessionFor(row.sessionId) : null;
|
|
119
233
|
if (!linked && row.launchId) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
linked = sessionId ? getSessionById(sessionId) : null;
|
|
234
|
+
const sessionId = linkCache.launches.get(row.launchId);
|
|
235
|
+
linked = sessionId ? await sessionFor(sessionId) : null;
|
|
123
236
|
}
|
|
124
|
-
|
|
125
|
-
}
|
|
237
|
+
out.push(linked ? { ...row, linkedSession: linked } : row);
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
126
240
|
}
|
|
127
241
|
export async function collectToolRows(scope, sources = {}) {
|
|
128
242
|
const incomplete = new Set();
|
|
@@ -25,7 +25,7 @@ export declare function ensureMenubarAppInstalled(opts?: {
|
|
|
25
25
|
export declare function generateServicePlist(execPath: string): string;
|
|
26
26
|
export declare function restartMenubarLaunchAgent(uid: number, plist: string, exec?: (cmd: string, args: readonly string[], opts: {
|
|
27
27
|
stdio: ['ignore', 'ignore', 'ignore'];
|
|
28
|
-
}) => Buffer): void;
|
|
28
|
+
}) => Buffer, sleep?: (ms: number) => void): void;
|
|
29
29
|
export declare function restartMenubarHelperAfterSwap(uid: number, ownProcesses: readonly MenubarProcess[], exec?: (cmd: string, args: readonly string[], opts: {
|
|
30
30
|
stdio: ['ignore', 'ignore', 'ignore'];
|
|
31
31
|
}) => Buffer, kill?: (pid: number) => void): void;
|
|
@@ -22,6 +22,7 @@ export function serviceLabel() {
|
|
|
22
22
|
return namespacedServiceLabel(SERVICE_LABEL_BASE);
|
|
23
23
|
}
|
|
24
24
|
const MENUBAR_THROTTLE_SECONDS = 30;
|
|
25
|
+
const MENUBAR_BOOTOUT_WAIT_TRIES = 50;
|
|
25
26
|
function onDarwin() {
|
|
26
27
|
return process.platform === 'darwin';
|
|
27
28
|
}
|
|
@@ -232,7 +233,7 @@ ${envXml}
|
|
|
232
233
|
</dict>
|
|
233
234
|
</plist>`;
|
|
234
235
|
}
|
|
235
|
-
export function restartMenubarLaunchAgent(uid, plist, exec = execFileSync) {
|
|
236
|
+
export function restartMenubarLaunchAgent(uid, plist, exec = execFileSync, sleep = sleepSync) {
|
|
236
237
|
const reg = serviceManagerRegistrationAllowed();
|
|
237
238
|
if (!reg.allowed) {
|
|
238
239
|
process.stderr.write(`[agents] ${reg.reason}\n`);
|
|
@@ -240,18 +241,28 @@ export function restartMenubarLaunchAgent(uid, plist, exec = execFileSync) {
|
|
|
240
241
|
}
|
|
241
242
|
const serviceTarget = `gui/${uid}/${serviceLabel()}`;
|
|
242
243
|
const opts = { stdio: ['ignore', 'ignore', 'ignore'] };
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
244
|
+
const succeeds = (args) => {
|
|
245
|
+
try {
|
|
246
|
+
exec('launchctl', args, opts);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
succeeds(['bootout', serviceTarget]);
|
|
254
|
+
for (let i = 0; i < MENUBAR_BOOTOUT_WAIT_TRIES && succeeds(['print', serviceTarget]); i++)
|
|
255
|
+
sleep(100);
|
|
256
|
+
let bootstrapped = false;
|
|
257
|
+
for (let attempt = 0; attempt < 3 && !bootstrapped; attempt++) {
|
|
258
|
+
if (attempt > 0)
|
|
259
|
+
sleep(500);
|
|
260
|
+
bootstrapped = succeeds(['bootstrap', `gui/${uid}`, plist]);
|
|
261
|
+
}
|
|
262
|
+
if (!bootstrapped) {
|
|
263
|
+
process.stderr.write(`[agents] AGI Menu login item could not be registered (launchctl bootstrap gui/${uid} ${plist} failed 3 times); run \`agents menubar setup\`\n`);
|
|
264
|
+
}
|
|
265
|
+
succeeds(['kickstart', serviceTarget]);
|
|
255
266
|
}
|
|
256
267
|
export function restartMenubarHelperAfterSwap(uid, ownProcesses, exec = execFileSync, kill = endProcess) {
|
|
257
268
|
const reg = serviceManagerRegistrationAllowed();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phnx-labs/agents-cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.3",
|
|
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",
|
package/dist/lib/template.d.ts
DELETED
package/dist/lib/template.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export function resolveTemplate(tmpl, artifact, preflight) {
|
|
2
|
-
let result = tmpl;
|
|
3
|
-
result = result.replace(/\{\{artifact\.(\w+)\}\}/g, (_, key) => {
|
|
4
|
-
return artifact[key] ?? '';
|
|
5
|
-
});
|
|
6
|
-
result = result.replace(/\{\{preflight\.(\w+)\}\}/g, (_, key) => {
|
|
7
|
-
const val = preflight[key];
|
|
8
|
-
if (val === undefined || val === null) {
|
|
9
|
-
return '';
|
|
10
|
-
}
|
|
11
|
-
if (typeof val === 'string') {
|
|
12
|
-
return val;
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(val)) {
|
|
15
|
-
return val.join(',');
|
|
16
|
-
}
|
|
17
|
-
return '';
|
|
18
|
-
});
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
export function extractTemplateVariables(tmpl) {
|
|
22
|
-
const artifact = [];
|
|
23
|
-
const preflight = [];
|
|
24
|
-
const re = /\{\{(\w+)\.(\w+)\}\}/g;
|
|
25
|
-
let match;
|
|
26
|
-
while ((match = re.exec(tmpl)) !== null) {
|
|
27
|
-
const [, prefix, key] = match;
|
|
28
|
-
if (prefix === 'artifact' && !artifact.includes(key)) {
|
|
29
|
-
artifact.push(key);
|
|
30
|
-
}
|
|
31
|
-
else if (prefix === 'preflight' && !preflight.includes(key)) {
|
|
32
|
-
preflight.push(key);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return { artifact, preflight };
|
|
36
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type AccountInfo } from './agents.js';
|
|
2
|
-
import type { AgentId } from './types.js';
|
|
3
|
-
export interface VersionAccountEntry {
|
|
4
|
-
version: string;
|
|
5
|
-
info: AccountInfo;
|
|
6
|
-
}
|
|
7
|
-
interface NewerDuplicateVersion {
|
|
8
|
-
version: string;
|
|
9
|
-
email: string | null;
|
|
10
|
-
plan: string | null;
|
|
11
|
-
}
|
|
12
|
-
export declare function findNewerDuplicateVersions(entries: VersionAccountEntry[], selectedVersion: string): NewerDuplicateVersion[];
|
|
13
|
-
export declare function formatNewerDuplicateNotice(agentId: AgentId, selectedVersion: string, duplicates: NewerDuplicateVersion[], selectedLabel?: string): string;
|
|
14
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { agentLabel } from './agents.js';
|
|
3
|
-
import { compareVersions } from './installations/versions.js';
|
|
4
|
-
import { getUsageLookupKey } from './accounting/usage.js';
|
|
5
|
-
function duplicateIdentity(info) {
|
|
6
|
-
if (!info)
|
|
7
|
-
return null;
|
|
8
|
-
const usageKey = getUsageLookupKey(info);
|
|
9
|
-
if (usageKey)
|
|
10
|
-
return usageKey;
|
|
11
|
-
return info.email ? `email:${info.email.toLowerCase()}` : null;
|
|
12
|
-
}
|
|
13
|
-
export function findNewerDuplicateVersions(entries, selectedVersion) {
|
|
14
|
-
const selected = entries.find((entry) => entry.version === selectedVersion);
|
|
15
|
-
const selectedIdentity = duplicateIdentity(selected?.info);
|
|
16
|
-
if (!selectedIdentity)
|
|
17
|
-
return [];
|
|
18
|
-
return entries
|
|
19
|
-
.filter((entry) => entry.version !== selectedVersion &&
|
|
20
|
-
compareVersions(entry.version, selectedVersion) > 0 &&
|
|
21
|
-
duplicateIdentity(entry.info) === selectedIdentity)
|
|
22
|
-
.sort((a, b) => compareVersions(b.version, a.version))
|
|
23
|
-
.map((entry) => ({
|
|
24
|
-
version: entry.version,
|
|
25
|
-
email: entry.info.email,
|
|
26
|
-
plan: entry.info.plan,
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
export function formatNewerDuplicateNotice(agentId, selectedVersion, duplicates, selectedLabel = '') {
|
|
30
|
-
if (duplicates.length === 0)
|
|
31
|
-
return '';
|
|
32
|
-
const versionLabel = selectedLabel
|
|
33
|
-
? `${selectedLabel} ${agentLabel(agentId)}@${selectedVersion}`
|
|
34
|
-
: `${agentLabel(agentId)}@${selectedVersion}`;
|
|
35
|
-
const plural = duplicates.length === 1 ? 'duplicate' : 'duplicates';
|
|
36
|
-
const maxVersion = Math.max(...duplicates.map((duplicate) => duplicate.version.length));
|
|
37
|
-
const maxEmail = Math.max(0, ...duplicates.map((duplicate) => duplicate.email?.length ?? 0));
|
|
38
|
-
const lines = [
|
|
39
|
-
`Found ${duplicates.length} newer ${plural} for ${versionLabel}:`,
|
|
40
|
-
];
|
|
41
|
-
for (const duplicate of duplicates) {
|
|
42
|
-
const parts = [` ${duplicate.version.padEnd(maxVersion)}`];
|
|
43
|
-
if (maxEmail > 0) {
|
|
44
|
-
parts.push(duplicate.email ? chalk.cyan(duplicate.email.padEnd(maxEmail)) : ''.padEnd(maxEmail));
|
|
45
|
-
}
|
|
46
|
-
if (duplicate.plan) {
|
|
47
|
-
parts.push(duplicate.plan);
|
|
48
|
-
}
|
|
49
|
-
lines.push(parts.join(' '));
|
|
50
|
-
}
|
|
51
|
-
lines.push('');
|
|
52
|
-
lines.push(`Run: agents use ${agentId}@${duplicates[0].version}`);
|
|
53
|
-
return lines.join('\n');
|
|
54
|
-
}
|