@commonlyai/cli 0.1.217 → 0.1.218
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/package.json +1 -1
- package/src/commands/agent.js +76 -48
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -502,6 +502,81 @@ export const bootstrapAgentRecordFromEnv = async ({
|
|
|
502
502
|
};
|
|
503
503
|
};
|
|
504
504
|
|
|
505
|
+
/**
|
|
506
|
+
* `commonly agent list`. Without --pod it reads the admin installs route, which
|
|
507
|
+
* only a global admin can call. With --pod it reads the member-gated pod roster,
|
|
508
|
+
* so a pod member lists its own seats. Returns the exit code, never exits itself.
|
|
509
|
+
* Any throw becomes one Failed line and exit 1.
|
|
510
|
+
*/
|
|
511
|
+
export const runAgentList = async (opts = {}, deps = {}) => {
|
|
512
|
+
const { error = console.error } = deps;
|
|
513
|
+
try {
|
|
514
|
+
return await listAgents(opts, deps);
|
|
515
|
+
} catch (err) {
|
|
516
|
+
error(`Failed: ${err.message}`);
|
|
517
|
+
return 1;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
const listAgents = async (opts, deps) => {
|
|
522
|
+
const {
|
|
523
|
+
clientFactory = createClient,
|
|
524
|
+
tokenFor = getToken,
|
|
525
|
+
instanceUrlFor = resolveInstanceUrl,
|
|
526
|
+
log = console.log,
|
|
527
|
+
error = console.error,
|
|
528
|
+
} = deps;
|
|
529
|
+
const col = (s, w) => String(s ?? '').padEnd(w).slice(0, w);
|
|
530
|
+
|
|
531
|
+
if (opts.local) {
|
|
532
|
+
const agents = listLocalAgents();
|
|
533
|
+
if (agents.length === 0) {
|
|
534
|
+
log('No agents attached locally. Run: commonly agent attach <adapter> --pod <podId> --name <n>');
|
|
535
|
+
return 0;
|
|
536
|
+
}
|
|
537
|
+
log(`${col('NAME', 20)} ${col('ADAPTER', 10)} ${col('POD', 26)} LAST TURN`);
|
|
538
|
+
log('─'.repeat(80));
|
|
539
|
+
agents.forEach((a) => {
|
|
540
|
+
const lastTurn = a.lastTurn ? new Date(a.lastTurn).toLocaleString() : 'never';
|
|
541
|
+
log(`${col(a.name, 20)} ${col(a.adapter, 10)} ${col(a.podId, 26)} ${lastTurn}`);
|
|
542
|
+
});
|
|
543
|
+
return 0;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const token = tokenFor(opts.instance);
|
|
547
|
+
if (!token) { error('Not logged in. Run: commonly login'); return 1; }
|
|
548
|
+
|
|
549
|
+
const client = clientFactory({ instance: instanceUrlFor(opts.instance), token });
|
|
550
|
+
|
|
551
|
+
try {
|
|
552
|
+
const rows = opts.pod
|
|
553
|
+
? (await client.get(`/api/registry/pods/${encodeURIComponent(opts.pod)}/agents`)).agents || []
|
|
554
|
+
: (await client.get('/api/registry/admin/installations')).installations || [];
|
|
555
|
+
|
|
556
|
+
if (rows.length === 0) {
|
|
557
|
+
log('No agents installed.');
|
|
558
|
+
return 0;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
log(`${col('NAME', 16)} ${col('INSTANCE', 10)} ${col('RUNTIME', 14)} ${col('HOST', 6)} ${col('STATUS', 10)} LAST SEEN`);
|
|
562
|
+
log('─'.repeat(80));
|
|
563
|
+
rows.forEach((inst) => {
|
|
564
|
+
// The pod roster names the agent `name`; the admin route uses `agentName`.
|
|
565
|
+
const displayName = opts.pod ? (inst.name || inst.agentName) : inst.agentName;
|
|
566
|
+
const runtimeType = inst.config?.runtime?.runtimeType || inst.runtime?.runtimeType || inst.runtimeType || '?';
|
|
567
|
+
const host = inst.config?.runtime?.host || inst.runtime?.host || '';
|
|
568
|
+
const seen = inst.lastActiveAt || inst.usage?.lastUsedAt || inst.connection?.lastSeenAt;
|
|
569
|
+
const lastSeen = seen ? new Date(seen).toLocaleString() : 'never';
|
|
570
|
+
log(`${col(displayName, 16)} ${col(inst.instanceId, 10)} ${col(runtimeType, 14)} ${col(host, 6)} ${col(inst.status, 10)} ${lastSeen}`);
|
|
571
|
+
});
|
|
572
|
+
return 0;
|
|
573
|
+
} catch (err) {
|
|
574
|
+
error(`Failed: ${err.message}`);
|
|
575
|
+
if (err.status === 403 && !opts.pod) error('Listing every install needs a global admin. Pass --pod <podId> to list one pod you belong to.');
|
|
576
|
+
return 1;
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
|
|
505
580
|
/**
|
|
506
581
|
* Enumerate every agent attached on this laptop — i.e. every file in
|
|
507
582
|
* ~/.commonly/tokens/*.json. Cross-references the session store for a
|
|
@@ -4325,54 +4400,7 @@ The two modes answer different questions:
|
|
|
4325
4400
|
|
|
4326
4401
|
Use --local to find the name you'd pass to 'agent run' or 'agent detach'.
|
|
4327
4402
|
`)
|
|
4328
|
-
.action(async (opts) => {
|
|
4329
|
-
if (opts.local) {
|
|
4330
|
-
const agents = listLocalAgents();
|
|
4331
|
-
if (agents.length === 0) {
|
|
4332
|
-
console.log('No agents attached locally. Run: commonly agent attach <adapter> --pod <podId> --name <n>');
|
|
4333
|
-
return;
|
|
4334
|
-
}
|
|
4335
|
-
const col = (s, w) => String(s ?? '').padEnd(w).slice(0, w);
|
|
4336
|
-
console.log(`${col('NAME', 20)} ${col('ADAPTER', 10)} ${col('POD', 26)} LAST TURN`);
|
|
4337
|
-
console.log('─'.repeat(80));
|
|
4338
|
-
agents.forEach((a) => {
|
|
4339
|
-
const lastTurn = a.lastTurn ? new Date(a.lastTurn).toLocaleString() : 'never';
|
|
4340
|
-
console.log(`${col(a.name, 20)} ${col(a.adapter, 10)} ${col(a.podId, 26)} ${lastTurn}`);
|
|
4341
|
-
});
|
|
4342
|
-
return;
|
|
4343
|
-
}
|
|
4344
|
-
|
|
4345
|
-
const token = getToken(opts.instance);
|
|
4346
|
-
if (!token) { console.error('Not logged in. Run: commonly login'); process.exit(1); }
|
|
4347
|
-
|
|
4348
|
-
const client = createClient({ instance: resolveInstanceUrl(opts.instance), token });
|
|
4349
|
-
|
|
4350
|
-
try {
|
|
4351
|
-
const params = opts.pod ? { podId: opts.pod } : {};
|
|
4352
|
-
const data = await client.get('/api/registry/admin/installations', params);
|
|
4353
|
-
const installations = data.installations || data || [];
|
|
4354
|
-
|
|
4355
|
-
if (installations.length === 0) {
|
|
4356
|
-
console.log('No agents installed.');
|
|
4357
|
-
return;
|
|
4358
|
-
}
|
|
4359
|
-
|
|
4360
|
-
const col = (s, w) => String(s ?? '').padEnd(w).slice(0, w);
|
|
4361
|
-
console.log(`${col('NAME', 16)} ${col('INSTANCE', 10)} ${col('RUNTIME', 14)} ${col('HOST', 6)} ${col('STATUS', 10)} LAST SEEN`);
|
|
4362
|
-
console.log('─'.repeat(80));
|
|
4363
|
-
installations.forEach((inst) => {
|
|
4364
|
-
const runtimeType = inst.config?.runtime?.runtimeType || inst.runtimeType || '?';
|
|
4365
|
-
const host = inst.config?.runtime?.host || '';
|
|
4366
|
-
const lastSeen = inst.usage?.lastUsedAt
|
|
4367
|
-
? new Date(inst.usage.lastUsedAt).toLocaleString()
|
|
4368
|
-
: 'never';
|
|
4369
|
-
console.log(`${col(inst.agentName, 16)} ${col(inst.instanceId, 10)} ${col(runtimeType, 14)} ${col(host, 6)} ${col(inst.status, 10)} ${lastSeen}`);
|
|
4370
|
-
});
|
|
4371
|
-
} catch (err) {
|
|
4372
|
-
console.error(`Failed: ${err.message}`);
|
|
4373
|
-
process.exit(1);
|
|
4374
|
-
}
|
|
4375
|
-
});
|
|
4403
|
+
.action(async (opts) => { process.exit(await runAgentList(opts)); });
|
|
4376
4404
|
|
|
4377
4405
|
// ── logs ──────────────────────────────────────────────────────────────────
|
|
4378
4406
|
// Without --pod, the seat's local daemon log is read. With --pod, the owner
|