@phnx-labs/agents-cli 1.23.21 → 1.23.22

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 (176) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +17 -0
  3. package/dist/bootstrap.js +5 -4
  4. package/dist/cli/command-registry.js +2 -0
  5. package/dist/commands/config.js +16 -0
  6. package/dist/commands/daemon.js +3 -3
  7. package/dist/commands/doctor.js +10 -19
  8. package/dist/commands/events.js +1 -14
  9. package/dist/commands/feed-watch.js +5 -2
  10. package/dist/commands/go.js +2 -2
  11. package/dist/commands/lead.d.ts +3 -0
  12. package/dist/commands/lead.js +280 -0
  13. package/dist/commands/projects.js +3 -2
  14. package/dist/commands/ps-roster.d.ts +2 -12
  15. package/dist/commands/ps-roster.js +5 -87
  16. package/dist/commands/ps.js +3 -1
  17. package/dist/commands/repo.js +12 -12
  18. package/dist/commands/resource-view.js +5 -5
  19. package/dist/commands/sessions-browser.js +2 -2
  20. package/dist/commands/sessions-watch.js +5 -2
  21. package/dist/commands/setup-secrets.d.ts +3 -4
  22. package/dist/commands/setup-secrets.js +15 -46
  23. package/dist/commands/setup-session-backup.js +1 -1
  24. package/dist/commands/ssh.d.ts +0 -4
  25. package/dist/commands/ssh.js +14 -81
  26. package/dist/commands/teams-picker.js +1 -12
  27. package/dist/commands/teams.js +1 -13
  28. package/dist/commands/view.d.ts +1 -40
  29. package/dist/commands/view.js +9 -330
  30. package/dist/commands/watchdog.js +4 -4
  31. package/dist/index.js +4 -0
  32. package/dist/lib/accounting/usage.d.ts +0 -1
  33. package/dist/lib/accounting/usage.js +1 -112
  34. package/dist/lib/accounts/add.js +1 -1
  35. package/dist/lib/accounts/migrate.js +1 -1
  36. package/dist/lib/auto-pull-worker.js +2 -16
  37. package/dist/lib/auto-pull.d.ts +1 -0
  38. package/dist/lib/auto-pull.js +27 -0
  39. package/dist/lib/browser-client.js +2 -11
  40. package/dist/lib/cloud/codex.js +3 -0
  41. package/dist/lib/commands.d.ts +0 -6
  42. package/dist/lib/commands.js +3 -116
  43. package/dist/lib/comms-render.d.ts +1 -7
  44. package/dist/lib/comms-render.js +0 -19
  45. package/dist/lib/computer-client.js +2 -11
  46. package/dist/lib/config-keys.d.ts +7 -3
  47. package/dist/lib/config-keys.js +15 -2
  48. package/dist/lib/crabbox/runtimes.d.ts +0 -14
  49. package/dist/lib/crabbox/runtimes.js +0 -80
  50. package/dist/lib/daemon/attention-notify-service.d.ts +51 -28
  51. package/dist/lib/daemon/attention-notify-service.js +219 -53
  52. package/dist/lib/daemon/daemon.js +1 -2
  53. package/dist/lib/daemon/feed-stream-service.js +2 -4
  54. package/dist/lib/device-config.d.ts +0 -5
  55. package/dist/lib/device-config.js +20 -27
  56. package/dist/lib/devices/doctor-findings.d.ts +2 -1
  57. package/dist/lib/devices/doctor-findings.js +12 -1
  58. package/dist/lib/devices/fleet.d.ts +6 -0
  59. package/dist/lib/devices/fleet.js +15 -0
  60. package/dist/lib/devices/harness-inventory.d.ts +9 -0
  61. package/dist/lib/devices/harness-inventory.js +66 -0
  62. package/dist/lib/exec.js +1 -3
  63. package/dist/lib/feed/attention.d.ts +16 -1
  64. package/dist/lib/feed/attention.js +63 -1
  65. package/dist/lib/feed/feed.d.ts +1 -1
  66. package/dist/lib/feed/feed.js +12 -2
  67. package/dist/lib/feed/hub.d.ts +9 -0
  68. package/dist/lib/feed/hub.js +27 -1
  69. package/dist/lib/feed/notify-schedule.d.ts +16 -0
  70. package/dist/lib/feed/notify-schedule.js +62 -0
  71. package/dist/lib/feed/ticket-priority.d.ts +4 -0
  72. package/dist/lib/feed/ticket-priority.js +30 -0
  73. package/dist/lib/feed/watch.d.ts +1 -0
  74. package/dist/lib/feed/watch.js +27 -3
  75. package/dist/lib/feed-ranking.d.ts +1 -0
  76. package/dist/lib/feed-ranking.js +3 -1
  77. package/dist/lib/format.d.ts +0 -2
  78. package/dist/lib/format.js +0 -8
  79. package/dist/lib/helper-versions.js +1 -1
  80. package/dist/lib/hooks/cache.d.ts +1 -0
  81. package/dist/lib/hooks/cache.js +12 -1
  82. package/dist/lib/installations/duplicate-prune.d.ts +37 -0
  83. package/dist/lib/installations/duplicate-prune.js +85 -0
  84. package/dist/lib/installations/inventory-json.d.ts +20 -0
  85. package/dist/lib/installations/inventory-json.js +252 -0
  86. package/dist/lib/installations/shims.d.ts +0 -18
  87. package/dist/lib/installations/shims.js +1 -257
  88. package/dist/lib/lead/brief.d.ts +49 -0
  89. package/dist/lib/lead/brief.js +173 -0
  90. package/dist/lib/lead/client.d.ts +21 -0
  91. package/dist/lib/lead/client.js +167 -0
  92. package/dist/lib/lead/confirm.d.ts +22 -0
  93. package/dist/lib/lead/confirm.js +73 -0
  94. package/dist/lib/lead/events.d.ts +106 -0
  95. package/dist/lib/lead/events.js +188 -0
  96. package/dist/lib/lead/harness.d.ts +29 -0
  97. package/dist/lib/lead/harness.js +107 -0
  98. package/dist/lib/lead/host.d.ts +132 -0
  99. package/dist/lib/lead/host.js +675 -0
  100. package/dist/lib/lead/paths.d.ts +22 -0
  101. package/dist/lib/lead/paths.js +69 -0
  102. package/dist/lib/lead/refs.d.ts +17 -0
  103. package/dist/lib/lead/refs.js +75 -0
  104. package/dist/lib/lead/roster.d.ts +26 -0
  105. package/dist/lib/lead/roster.js +121 -0
  106. package/dist/lib/lead/shapes.d.ts +23 -0
  107. package/dist/lib/lead/shapes.js +95 -0
  108. package/dist/lib/lead/store.d.ts +46 -0
  109. package/dist/lib/lead/store.js +77 -0
  110. package/dist/lib/lead/tools.d.ts +18 -0
  111. package/dist/lib/lead/tools.js +106 -0
  112. package/dist/lib/lead/visibility.d.ts +16 -0
  113. package/dist/lib/lead/visibility.js +77 -0
  114. package/dist/lib/mailbox.d.ts +0 -18
  115. package/dist/lib/mailbox.js +0 -170
  116. package/dist/lib/menubar/notify-desktop.d.ts +5 -0
  117. package/dist/lib/menubar/notify-desktop.js +24 -0
  118. package/dist/lib/models.js +1 -19
  119. package/dist/lib/permissions.d.ts +0 -6
  120. package/dist/lib/permissions.js +0 -140
  121. package/dist/lib/platform/process.d.ts +1 -0
  122. package/dist/lib/platform/process.js +5 -0
  123. package/dist/lib/probe.js +13 -1
  124. package/dist/lib/project-status.js +4 -3
  125. package/dist/lib/projects.d.ts +9 -0
  126. package/dist/lib/projects.js +61 -3
  127. package/dist/lib/scheduling/routines.d.ts +1 -13
  128. package/dist/lib/scheduling/routines.js +1 -37
  129. package/dist/lib/secrets-cli.d.ts +3 -3
  130. package/dist/lib/secrets-cli.js +1 -1
  131. package/dist/lib/secrets-client.d.ts +4 -37
  132. package/dist/lib/secrets-client.js +19 -265
  133. package/dist/lib/session/active.d.ts +18 -8
  134. package/dist/lib/session/active.js +94 -18
  135. package/dist/lib/session/db.d.ts +0 -16
  136. package/dist/lib/session/db.js +1 -134
  137. package/dist/lib/session/detached.d.ts +0 -1
  138. package/dist/lib/session/detached.js +0 -18
  139. package/dist/lib/session/pending-work.d.ts +21 -0
  140. package/dist/lib/session/pending-work.js +284 -0
  141. package/dist/lib/session/remote/remote-list.d.ts +0 -3
  142. package/dist/lib/session/remote/remote-list.js +1 -23
  143. package/dist/lib/session/remote/watch.d.ts +5 -0
  144. package/dist/lib/session/remote/watch.js +19 -2
  145. package/dist/lib/session/session-cache.d.ts +1 -1
  146. package/dist/lib/session/session-cache.js +12 -5
  147. package/dist/lib/session/sync/provision.js +1 -2
  148. package/dist/lib/smart-launch.js +7 -2
  149. package/dist/lib/snapshot.js +3 -4
  150. package/dist/lib/ssh-exec.d.ts +0 -40
  151. package/dist/lib/ssh-exec.js +0 -108
  152. package/dist/lib/ssh-tunnel.d.ts +0 -6
  153. package/dist/lib/ssh-tunnel.js +0 -42
  154. package/dist/lib/standalone-tools.js +12 -1
  155. package/dist/lib/startup/command-registry.js +1 -1
  156. package/dist/lib/startup/spellcheck.d.ts +0 -1
  157. package/dist/lib/startup/spellcheck.js +1 -20
  158. package/dist/lib/state.d.ts +0 -6
  159. package/dist/lib/state.js +1 -14
  160. package/dist/lib/teams/delivery.d.ts +1 -0
  161. package/dist/lib/teams/delivery.js +13 -0
  162. package/dist/lib/types.d.ts +0 -37
  163. package/dist/lib/types.js +0 -9
  164. package/dist/lib/watchdog/log.d.ts +1 -1
  165. package/dist/lib/watchdog/log.js +6 -4
  166. package/package.json +2 -1
  167. package/dist/lib/artifact-actions.d.ts +0 -7
  168. package/dist/lib/artifact-actions.js +0 -39
  169. package/dist/lib/session/sync/managed-config.d.ts +0 -3
  170. package/dist/lib/session/sync/managed-config.js +0 -3
  171. package/dist/lib/session/sync/worker-template.d.ts +0 -1
  172. package/dist/lib/session/sync/worker-template.js +0 -807
  173. package/dist/lib/storage/selection.d.ts +0 -8
  174. package/dist/lib/storage/selection.js +0 -10
  175. package/dist/lib/watchdog/index.d.ts +0 -3
  176. package/dist/lib/watchdog/index.js +0 -3
@@ -93,17 +93,9 @@ export function parseCommaSeparatedList(value) {
93
93
  .map((item) => item.trim())
94
94
  .filter(Boolean);
95
95
  }
96
- export function visibleWidth(s) {
97
- // eslint-disable-next-line no-control-regex
98
- return s.replace(/\x1b\[[0-9;]*m/g, '').length;
99
- }
100
96
  export function padRight(s, width) {
101
97
  return s.length >= width ? s : s + ' '.repeat(width - s.length);
102
98
  }
103
- export function padVisible(s, width) {
104
- const w = visibleWidth(s);
105
- return w >= width ? s : s + ' '.repeat(width - w);
106
- }
107
99
  export function isJsonMode(opts) {
108
100
  // Piped output stays human-readable unless the caller explicitly requests JSON.
109
101
  return Boolean(opts.json);
@@ -1,5 +1,5 @@
1
1
  export const HELPER_RELEASES = {
2
- menubar: { tagPrefix: 'menubar', floor: '1.18.1' },
2
+ menubar: { tagPrefix: 'menubar', floor: '1.19.0' },
3
3
  };
4
4
  export function helperTag(helper, version) {
5
5
  const release = HELPER_RELEASES[helper];
@@ -1,6 +1,7 @@
1
1
  import type { HookCache, HookCacheConfig, HookMatches } from '../types.js';
2
2
  export declare function parseCacheConfig(raw: HookCache | undefined): HookCacheConfig | null;
3
3
  export declare function parseDuration(d: number | string | undefined): number | null;
4
+ export declare function parseSince(raw: string): Date;
4
5
  export declare function isValidHookShimName(name: string): boolean;
5
6
  export declare function getHookShimPath(name: string): string;
6
7
  export interface HookShimPaths {
@@ -34,13 +34,15 @@ export function parseDuration(d) {
34
34
  return null;
35
35
  if (typeof d === 'number')
36
36
  return Number.isFinite(d) && d > 0 ? Math.floor(d) : null;
37
- const m = d.trim().match(/^(\d+)\s*(s|sec|secs|m|min|mins|h|hr|hrs|d|day|days)?$/i);
37
+ const m = d.trim().match(/^(\d+)\s*(s|sec|secs|m|min|mins|h|hr|hrs|d|day|days|w|wk|wks|week|weeks)?$/i);
38
38
  if (!m)
39
39
  return null;
40
40
  const value = parseInt(m[1], 10);
41
41
  if (!Number.isFinite(value) || value <= 0)
42
42
  return null;
43
43
  const unit = (m[2] || 's').toLowerCase();
44
+ if (unit.startsWith('w'))
45
+ return value * 604800;
44
46
  if (unit.startsWith('d'))
45
47
  return value * 86400;
46
48
  if (unit.startsWith('h'))
@@ -49,6 +51,15 @@ export function parseDuration(d) {
49
51
  return value * 60;
50
52
  return value;
51
53
  }
54
+ export function parseSince(raw) {
55
+ const seconds = parseDuration(raw);
56
+ if (seconds != null)
57
+ return new Date(Date.now() - seconds * 1000);
58
+ const ms = Date.parse(raw);
59
+ if (Number.isNaN(ms))
60
+ throw new Error(`Invalid --since value: ${raw} (use e.g. 2h, 7d, 1w, or an ISO date)`);
61
+ return new Date(ms);
62
+ }
52
63
  // Shim names become path segments; validation is the traversal boundary.
53
64
  export function isValidHookShimName(name) {
54
65
  return (!!name &&
@@ -0,0 +1,37 @@
1
+ import type { AccountInfo } from '../agents.js';
2
+ export declare function compareVersionLabels(a: string, b: string): number;
3
+ export declare function pruneGroupKey(info: Pick<AccountInfo, 'accountKey' | 'email'>): string | null;
4
+ export interface PruneCandidate {
5
+ version: string;
6
+ release: string;
7
+ email: string | null;
8
+ accountKey: string | null;
9
+ signedIn: boolean;
10
+ hasBinary: boolean;
11
+ }
12
+ export interface DuplicatePruneEntry {
13
+ version: string;
14
+ email: string;
15
+ keeper: string;
16
+ }
17
+ /**
18
+ * PURE duplicate-home detection: given every installed home for one agent, decide
19
+ * which are redundant duplicates of the SAME logical account and which single home
20
+ * to keep per account. Extracted from buildAgentPrunePlan so the keeper/merge rules
21
+ * are unit-tested without touching disk.
22
+ *
23
+ * Two rules, both conservative:
24
+ * - GROUPING. A home with a captured `accountKey` groups by it (account+org, so a
25
+ * personal Max and a Team seat on the same email stay separate). A home with NO
26
+ * accountKey folds into a same-email account ONLY when a sibling home for that
27
+ * email IS identified — that email-only home is an incompletely-captured re-login
28
+ * of the known account, not a distinct seat (PHNX-3887). Otherwise it groups by
29
+ * its bare email and only ever collapses against another equally-bare home.
30
+ * - KEEPER. Within a group the keeper is the home that best represents the account:
31
+ * captured identity first, then a signed-in credential, then the newest RUNNING
32
+ * release, then the highest dir label as a stable tiebreak. This is deliberately
33
+ * NOT "highest dir-name semver" — in the wild that is the freshly re-logged-in
34
+ * duplicate that never captured its identity or usage, and keeping it while
35
+ * trashing the identified home is the exact bug this replaces.
36
+ */
37
+ export declare function planDuplicatePrune(candidates: PruneCandidate[]): DuplicatePruneEntry[];
@@ -0,0 +1,85 @@
1
+ export function compareVersionLabels(a, b) {
2
+ const partsA = a.split('.').map(Number);
3
+ const partsB = b.split('.').map(Number);
4
+ for (let i = 0; i < 3; i++) {
5
+ if (partsA[i] > partsB[i])
6
+ return 1;
7
+ if (partsA[i] < partsB[i])
8
+ return -1;
9
+ }
10
+ return 0;
11
+ }
12
+ export function pruneGroupKey(info) {
13
+ return info.accountKey ?? info.email?.toLowerCase() ?? null;
14
+ }
15
+ /**
16
+ * PURE duplicate-home detection: given every installed home for one agent, decide
17
+ * which are redundant duplicates of the SAME logical account and which single home
18
+ * to keep per account. Extracted from buildAgentPrunePlan so the keeper/merge rules
19
+ * are unit-tested without touching disk.
20
+ *
21
+ * Two rules, both conservative:
22
+ * - GROUPING. A home with a captured `accountKey` groups by it (account+org, so a
23
+ * personal Max and a Team seat on the same email stay separate). A home with NO
24
+ * accountKey folds into a same-email account ONLY when a sibling home for that
25
+ * email IS identified — that email-only home is an incompletely-captured re-login
26
+ * of the known account, not a distinct seat (PHNX-3887). Otherwise it groups by
27
+ * its bare email and only ever collapses against another equally-bare home.
28
+ * - KEEPER. Within a group the keeper is the home that best represents the account:
29
+ * captured identity first, then a signed-in credential, then the newest RUNNING
30
+ * release, then the highest dir label as a stable tiebreak. This is deliberately
31
+ * NOT "highest dir-name semver" — in the wild that is the freshly re-logged-in
32
+ * duplicate that never captured its identity or usage, and keeping it while
33
+ * trashing the identified home is the exact bug this replaces.
34
+ */
35
+ export function planDuplicatePrune(candidates) {
36
+ const installed = candidates.filter((c) => c.hasBinary && c.email);
37
+ const emailToAccountKeys = new Map();
38
+ for (const c of installed) {
39
+ if (!c.accountKey)
40
+ continue;
41
+ const email = c.email.toLowerCase();
42
+ (emailToAccountKeys.get(email) ?? emailToAccountKeys.set(email, new Set()).get(email)).add(c.accountKey);
43
+ }
44
+ const groupKeyFor = (c) => {
45
+ if (c.accountKey)
46
+ return c.accountKey;
47
+ const email = c.email?.toLowerCase();
48
+ const keys = email ? emailToAccountKeys.get(email) : undefined;
49
+ if (keys && keys.size === 1)
50
+ return [...keys][0];
51
+ if (keys && keys.size >= 2)
52
+ return `ambiguous:${c.email.toLowerCase()}:${c.version}`;
53
+ return pruneGroupKey(c);
54
+ };
55
+ const byAccount = new Map();
56
+ for (const c of installed) {
57
+ const key = groupKeyFor(c);
58
+ if (!key)
59
+ continue;
60
+ (byAccount.get(key) ?? byAccount.set(key, []).get(key)).push(c);
61
+ }
62
+ const rank = (c) => [c.accountKey ? 1 : 0, c.signedIn ? 1 : 0];
63
+ const better = (a, b) => {
64
+ const [aa, ab] = rank(a);
65
+ const [ba, bb] = rank(b);
66
+ if (aa !== ba)
67
+ return ba - aa;
68
+ if (ab !== bb)
69
+ return bb - ab;
70
+ if (a.release !== b.release)
71
+ return compareVersionLabels(b.release, a.release);
72
+ return compareVersionLabels(b.version, a.version);
73
+ };
74
+ const out = [];
75
+ for (const group of byAccount.values()) {
76
+ if (group.length < 2)
77
+ continue;
78
+ const sorted = [...group].sort(better);
79
+ const keeper = sorted[0].version;
80
+ for (const dup of sorted.slice(1)) {
81
+ out.push({ version: dup.version, email: dup.email, keeper });
82
+ }
83
+ }
84
+ return out;
85
+ }
@@ -0,0 +1,20 @@
1
+ import { getGitSyncStatus } from '../git.js';
2
+ import { type ProfileSummary } from '../profiles.js';
3
+ import type { AgentId } from '../types.js';
4
+ import type { ResourceSection, SyncState, ViewJsonAgent, ViewJsonRunReady } from '../view-types.js';
5
+ export declare function getHarnesses(): ProfileSummary[];
6
+ export type ResourceSyncType = 'commands' | 'skills' | 'hooks' | 'memory';
7
+ interface ResourceSyncData {
8
+ hasGitRepo: boolean;
9
+ commands: Awaited<ReturnType<typeof getGitSyncStatus>>;
10
+ skills: Awaited<ReturnType<typeof getGitSyncStatus>>;
11
+ hooks: Awaited<ReturnType<typeof getGitSyncStatus>>;
12
+ memory: Awaited<ReturnType<typeof getGitSyncStatus>>;
13
+ }
14
+ export declare function loadResourceSyncData(): Promise<ResourceSyncData>;
15
+ export declare function resolveResourceSyncState(agentId: AgentId, resourceName: string, resourceType: ResourceSyncType, syncStatus: Awaited<ReturnType<typeof getGitSyncStatus>>): SyncState | undefined;
16
+ export declare function computeAgentRunReady(agentId: AgentId): Promise<ViewJsonRunReady | undefined>;
17
+ export declare function collectAgentsJson(filterAgentId?: AgentId, resourceSections?: Set<ResourceSection>, opts?: {
18
+ forceRefresh?: boolean;
19
+ }): Promise<ViewJsonAgent[]>;
20
+ export {};
@@ -0,0 +1,252 @@
1
+ import { accountListJson, loadAccountCatalog, secretsUnavailableNote } from '../account-catalog.js';
2
+ import { collectRunCandidates, isLaunchableSignedIn, readinessFromCandidate } from '../accounting/rotate.js';
3
+ import { deriveUsageStatusFromSnapshot, getUsageInfoByIdentity, getUsageLookupKey, usageErrorForDisplay } from '../accounting/usage.js';
4
+ import { ALL_AGENT_IDS, credentialPresence, getAccountInfo, getAllCliStates } from '../agents.js';
5
+ import { authCacheKey, readAuthHealthCache } from '../auth-health.js';
6
+ import { getGitSyncStatus, isGitRepo } from '../git.js';
7
+ import { machineId } from '../machine-id.js';
8
+ import { resolveConfiguredModel } from '../models.js';
9
+ import { discoverPlugins, pluginSupportsAgent } from '../plugins/plugins.js';
10
+ import { listProfiles, profileSummary } from '../profiles.js';
11
+ import { getAgentResources } from '../resources.js';
12
+ import { getCentralRulesFileName } from '../rules/rules.js';
13
+ import { compareVersionLabels } from './duplicate-prune.js';
14
+ import { getUserAgentsDir } from '../state.js';
15
+ import { readInstallation } from './store.js';
16
+ import { getGlobalDefault, getIsolatedDefault, getLiveVersion, getVersionDir, getVersionHomePath, isGlobalBinaryAgent, isVersionIsolated, listInstalledVersions } from './versions.js';
17
+ import chalk from 'chalk';
18
+ export function getHarnesses() {
19
+ return listProfiles().map(profileSummary);
20
+ }
21
+ export async function loadResourceSyncData() {
22
+ const userAgentsDir = getUserAgentsDir();
23
+ const hasGitRepo = isGitRepo(userAgentsDir);
24
+ return {
25
+ hasGitRepo,
26
+ commands: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'commands') : null,
27
+ skills: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'skills') : null,
28
+ hooks: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'hooks') : null,
29
+ memory: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'rules') : null,
30
+ };
31
+ }
32
+ export function resolveResourceSyncState(agentId, resourceName, resourceType, syncStatus) {
33
+ if (!syncStatus)
34
+ return undefined;
35
+ let relativePath;
36
+ if (resourceType === 'commands') {
37
+ relativePath = `commands/${resourceName}.md`;
38
+ }
39
+ else if (resourceType === 'skills') {
40
+ relativePath = `skills/${resourceName}`;
41
+ }
42
+ else if (resourceType === 'hooks') {
43
+ relativePath = `hooks/${resourceName}`;
44
+ }
45
+ else {
46
+ const centralName = getCentralRulesFileName(agentId);
47
+ relativePath = `rules/${centralName}`;
48
+ }
49
+ const matchesPath = (f) => f === relativePath || f.startsWith(relativePath + '/');
50
+ if (syncStatus.new.some(matchesPath) || syncStatus.staged.some(matchesPath))
51
+ return 'new';
52
+ if (syncStatus.modified.some(matchesPath))
53
+ return 'modified';
54
+ if (syncStatus.deleted.some(matchesPath))
55
+ return 'deleted';
56
+ if (syncStatus.synced.some(matchesPath))
57
+ return 'synced';
58
+ return 'new';
59
+ }
60
+ function collectVersionResources(agentId, home, cwd, cliInstalled, sections, sync) {
61
+ const res = getAgentResources(agentId, { cwd, scope: 'all', cliInstalled, home });
62
+ const out = {};
63
+ const withSync = (r, type, syncStatus) => {
64
+ const item = { name: r.name, scope: r.scope };
65
+ if (r.scope !== 'project') {
66
+ const s = resolveResourceSyncState(agentId, r.name, type, syncStatus);
67
+ if (s)
68
+ item.syncState = s;
69
+ }
70
+ if (r.description)
71
+ item.description = r.description;
72
+ return item;
73
+ };
74
+ if (sections.has('commands'))
75
+ out.commands = res.commands.map((r) => withSync(r, 'commands', sync.commands));
76
+ if (sections.has('skills')) {
77
+ out.skills = res.skills.map((r) => {
78
+ const item = withSync(r, 'skills', sync.skills);
79
+ if (r.ruleCount && r.ruleCount > 0)
80
+ item.ruleCount = r.ruleCount;
81
+ return item;
82
+ });
83
+ }
84
+ if (sections.has('mcp')) {
85
+ out.mcp = res.mcp.map((r) => {
86
+ const item = { name: r.name, scope: r.scope };
87
+ if (r.scope !== 'project')
88
+ item.syncState = 'synced';
89
+ return item;
90
+ });
91
+ }
92
+ if (sections.has('memory'))
93
+ out.memory = res.memory.map((r) => withSync(r, 'memory', sync.memory));
94
+ if (sections.has('hooks'))
95
+ out.hooks = res.hooks.map((r) => withSync(r, 'hooks', sync.hooks));
96
+ if (sections.has('workflows'))
97
+ out.workflows = res.workflows.map((r) => ({ name: r.name, scope: r.scope }));
98
+ if (sections.has('plugins')) {
99
+ out.plugins = discoverPlugins()
100
+ .filter((p) => pluginSupportsAgent(p, agentId))
101
+ .map((p) => ({ name: p.name }));
102
+ }
103
+ return out;
104
+ }
105
+ export async function computeAgentRunReady(agentId) {
106
+ const candidates = await collectRunCandidates(agentId);
107
+ if (candidates.length === 0)
108
+ return undefined;
109
+ const accounts = candidates.map((c) => {
110
+ const readiness = readinessFromCandidate(c);
111
+ const name = c.nativeAccount || c.accountLabel || c.email || c.version;
112
+ return { name, ready: readiness.ready, reason: readiness.ready ? 'ready' : readiness.reason };
113
+ });
114
+ const readyAccount = accounts.find((a) => a.ready);
115
+ let reason;
116
+ if (readyAccount) {
117
+ reason = `ready (${readyAccount.name})`;
118
+ }
119
+ else {
120
+ const reasons = [...new Set(accounts.map((a) => a.reason))];
121
+ reason = reasons.length === 1 ? `all ${reasons[0]}` : reasons.join(', ');
122
+ }
123
+ return { ready: !!readyAccount, reason, accounts };
124
+ }
125
+ export async function collectAgentsJson(filterAgentId, resourceSections, opts) {
126
+ const agentsToShow = filterAgentId ? [filterAgentId] : ALL_AGENT_IDS;
127
+ const authCache = readAuthHealthCache();
128
+ const host = machineId();
129
+ const wantResources = !!resourceSections && resourceSections.size > 0;
130
+ const resourceSync = wantResources ? await loadResourceSyncData() : null;
131
+ const cliStates = wantResources ? await getAllCliStates() : null;
132
+ const infoFetches = [];
133
+ for (const agentId of agentsToShow) {
134
+ for (const ver of listInstalledVersions(agentId)) {
135
+ const home = getVersionHomePath(agentId, ver);
136
+ infoFetches.push(getAccountInfo(agentId, home).then((info) => ({ agentId, version: ver, home, info })));
137
+ }
138
+ }
139
+ const infoResults = await Promise.all(infoFetches);
140
+ const globalReleases = new Map();
141
+ await Promise.all(agentsToShow.filter(isGlobalBinaryAgent).map(async (agent) => {
142
+ if (!infoResults.some((row) => row.agentId === agent))
143
+ return;
144
+ const release = await getLiveVersion(agent);
145
+ if (release)
146
+ globalReleases.set(agent, release);
147
+ }));
148
+ const actualRelease = (agent, label) => globalReleases.get(agent) ?? readInstallation(agent, label)?.releaseVersion ?? label;
149
+ const { canonicalByUsageKey, usageByKey } = await getUsageInfoByIdentity(infoResults.map(({ agentId, home, version, info }) => ({
150
+ agentId,
151
+ home,
152
+ cliVersion: version,
153
+ info,
154
+ })), { forceRefresh: opts?.forceRefresh === true });
155
+ const mergeCanonical = (info) => {
156
+ const key = getUsageLookupKey(info);
157
+ if (!key)
158
+ return info;
159
+ const canon = canonicalByUsageKey.get(key);
160
+ if (!canon)
161
+ return info;
162
+ return {
163
+ ...info,
164
+ plan: usageByKey.get(key)?.snapshot?.plan ?? canon.plan,
165
+ usageStatus: deriveUsageStatusFromSnapshot(usageByKey.get(key)?.snapshot),
166
+ overageCredits: canon.overageCredits,
167
+ };
168
+ };
169
+ const byAgent = new Map();
170
+ for (const { agentId, version, home, info: rawInfo } of infoResults) {
171
+ const info = mergeCanonical(rawInfo);
172
+ const globalDefault = getGlobalDefault(agentId);
173
+ const usageKey = getUsageLookupKey(info);
174
+ const usageInfo = usageKey ? usageByKey.get(usageKey) : undefined;
175
+ const snapshot = usageInfo?.snapshot ?? null;
176
+ const authHealth = authCache[authCacheKey(host, agentId, version)];
177
+ const entry = {
178
+ version,
179
+ releaseVersion: actualRelease(agentId, version),
180
+ isDefault: version === globalDefault,
181
+ isolated: isVersionIsolated(agentId, version),
182
+ isIsolatedDefault: getIsolatedDefault(agentId) === version,
183
+ signedIn: info.signedIn,
184
+ launchable: isLaunchableSignedIn(info.signedIn, credentialPresence(agentId, home)),
185
+ authVerdict: authHealth?.verdict ?? null,
186
+ authCheckedAt: authHealth?.checkedAt ?? null,
187
+ email: info.email,
188
+ accountId: info.accountId,
189
+ organizationType: info.organizationType ?? null,
190
+ organizationName: info.organizationName ?? null,
191
+ plan: info.plan,
192
+ usageStatus: info.usageStatus,
193
+ usageCapturedAt: snapshot?.capturedAt?.toISOString() ?? null,
194
+ overageCredits: info.overageCredits,
195
+ usageError: usageErrorForDisplay(usageInfo?.error),
196
+ windows: snapshot
197
+ ? snapshot.windows.map((w) => ({
198
+ key: w.key,
199
+ label: w.label,
200
+ usedPercent: w.usedPercent,
201
+ resetsAt: w.resetsAt ? w.resetsAt.toISOString() : null,
202
+ }))
203
+ : [],
204
+ unavailable: snapshot?.unavailable
205
+ ? {
206
+ reason: snapshot.unavailable.reason,
207
+ resetsAt: snapshot.unavailable.resetsAt?.toISOString(),
208
+ }
209
+ : undefined,
210
+ lastActive: info.lastActive ? info.lastActive.toISOString() : null,
211
+ path: getVersionDir(agentId, version),
212
+ configuredModel: resolveConfiguredModel(agentId, version),
213
+ };
214
+ if (wantResources && resourceSync) {
215
+ entry.resources = collectVersionResources(agentId, home, process.cwd(), cliStates?.[agentId]?.installed ?? false, resourceSections, resourceSync);
216
+ }
217
+ const existing = byAgent.get(agentId);
218
+ if (existing)
219
+ existing.push(entry);
220
+ else
221
+ byAgent.set(agentId, [entry]);
222
+ }
223
+ const harnesses = filterAgentId ? [] : getHarnesses();
224
+ const catalog = await loadAccountCatalog();
225
+ const note = secretsUnavailableNote(catalog);
226
+ if (note)
227
+ console.error(chalk.yellow(note));
228
+ const runReadyByAgent = new Map();
229
+ await Promise.all(agentsToShow.map(async (agentId) => {
230
+ const runReady = await computeAgentRunReady(agentId);
231
+ if (runReady)
232
+ runReadyByAgent.set(agentId, runReady);
233
+ }));
234
+ const out = [];
235
+ for (const agentId of agentsToShow) {
236
+ const versions = byAgent.get(agentId) ?? [];
237
+ versions.sort((a, b) => {
238
+ if (a.isDefault !== b.isDefault)
239
+ return a.isDefault ? -1 : 1;
240
+ return compareVersionLabels(b.version, a.version);
241
+ });
242
+ const accounts = accountListJson(catalog.native.filter((row) => row.agent === agentId), catalog.provider.filter((row) => row.harnesses.includes(agentId)), agentId).accounts;
243
+ out.push({
244
+ agent: agentId,
245
+ versions,
246
+ accounts,
247
+ runReady: runReadyByAgent.get(agentId),
248
+ harnesses: harnesses.filter((h) => h.agent === agentId),
249
+ });
250
+ }
251
+ return out;
252
+ }
@@ -3,12 +3,6 @@ import { getShimsDir } from '../state.js';
3
3
  export { getShimsDir };
4
4
  export declare function recordLaunchLease(agent: AgentId, label: string, pid: number): () => void;
5
5
  export declare function hasLiveLaunchLease(agent: AgentId, label: string): boolean;
6
- export type ConflictStrategy = 'keep-dest' | 'overwrite' | 'ask-per-file';
7
- export interface ConflictInfo {
8
- agent: AgentId;
9
- version: string;
10
- conflicts: string[];
11
- }
12
6
  export declare const SHIM_SCHEMA_VERSION = 33;
13
7
  export declare function generateShimScript(agent: AgentId): string;
14
8
  export declare function shimTargetsFor(platform: NodeJS.Platform): {
@@ -124,15 +118,3 @@ export declare class IsolationBoundaryError extends Error {
124
118
  export declare function isIsolationProtected(agent: AgentId): boolean;
125
119
  export declare function assertIsolationBoundary(agent: AgentId, operation: string): void;
126
120
  export declare function listAgentsWithNonIsolatedInstalledVersions(): AgentId[];
127
- export interface ResourceDiff {
128
- commands: string[];
129
- skills: string[];
130
- hooks: string[];
131
- memory: {
132
- file: string;
133
- currentLines: number;
134
- targetLines: number;
135
- }[];
136
- mcp: string[];
137
- }
138
- export declare function hasResourceDiff(diff: ResourceDiff): boolean;