@phnx-labs/agents-cli 1.23.20 → 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.
- package/CHANGELOG.md +126 -0
- package/README.md +17 -0
- package/dist/bootstrap.js +5 -4
- package/dist/cli/command-registry.js +2 -0
- package/dist/commands/config.js +16 -0
- package/dist/commands/daemon.js +3 -3
- package/dist/commands/doctor.js +10 -19
- package/dist/commands/events.js +1 -14
- package/dist/commands/feed-watch.js +5 -2
- package/dist/commands/go.js +2 -2
- package/dist/commands/lead.d.ts +3 -0
- package/dist/commands/lead.js +280 -0
- package/dist/commands/projects.js +3 -2
- package/dist/commands/ps-roster.d.ts +2 -12
- package/dist/commands/ps-roster.js +5 -87
- package/dist/commands/ps.js +3 -1
- package/dist/commands/repo.js +12 -12
- package/dist/commands/resource-view.js +5 -5
- package/dist/commands/sessions-browser.js +2 -2
- package/dist/commands/sessions-watch.js +5 -2
- package/dist/commands/setup-secrets.d.ts +3 -4
- package/dist/commands/setup-secrets.js +15 -46
- package/dist/commands/setup-session-backup.js +1 -1
- package/dist/commands/ssh.d.ts +0 -4
- package/dist/commands/ssh.js +14 -81
- package/dist/commands/teams-picker.js +1 -12
- package/dist/commands/teams.js +1 -13
- package/dist/commands/view.d.ts +1 -40
- package/dist/commands/view.js +9 -330
- package/dist/commands/watchdog.js +4 -4
- package/dist/index.js +4 -0
- package/dist/lib/accounting/usage.d.ts +0 -1
- package/dist/lib/accounting/usage.js +1 -112
- package/dist/lib/accounts/add.js +1 -1
- package/dist/lib/accounts/migrate.js +1 -1
- package/dist/lib/auto-pull-worker.js +2 -16
- package/dist/lib/auto-pull.d.ts +1 -0
- package/dist/lib/auto-pull.js +27 -0
- package/dist/lib/browser-client.js +2 -11
- package/dist/lib/cloud/codex.js +3 -0
- package/dist/lib/commands.d.ts +0 -6
- package/dist/lib/commands.js +3 -116
- package/dist/lib/comms-render.d.ts +1 -7
- package/dist/lib/comms-render.js +0 -19
- package/dist/lib/computer-client.js +2 -11
- package/dist/lib/config-keys.d.ts +7 -3
- package/dist/lib/config-keys.js +15 -2
- package/dist/lib/crabbox/runtimes.d.ts +0 -14
- package/dist/lib/crabbox/runtimes.js +0 -80
- package/dist/lib/daemon/attention-notify-service.d.ts +51 -28
- package/dist/lib/daemon/attention-notify-service.js +219 -53
- package/dist/lib/daemon/daemon.js +1 -2
- package/dist/lib/daemon/feed-stream-service.js +2 -4
- package/dist/lib/device-config.d.ts +0 -5
- package/dist/lib/device-config.js +20 -27
- package/dist/lib/devices/doctor-findings.d.ts +2 -1
- package/dist/lib/devices/doctor-findings.js +12 -1
- package/dist/lib/devices/fleet.d.ts +6 -0
- package/dist/lib/devices/fleet.js +15 -0
- package/dist/lib/devices/harness-inventory.d.ts +9 -0
- package/dist/lib/devices/harness-inventory.js +66 -0
- package/dist/lib/exec.js +1 -3
- package/dist/lib/feed/attention.d.ts +16 -1
- package/dist/lib/feed/attention.js +63 -1
- package/dist/lib/feed/feed.d.ts +1 -1
- package/dist/lib/feed/feed.js +12 -2
- package/dist/lib/feed/hub.d.ts +9 -0
- package/dist/lib/feed/hub.js +27 -1
- package/dist/lib/feed/notify-schedule.d.ts +16 -0
- package/dist/lib/feed/notify-schedule.js +62 -0
- package/dist/lib/feed/ticket-priority.d.ts +4 -0
- package/dist/lib/feed/ticket-priority.js +30 -0
- package/dist/lib/feed/watch.d.ts +1 -0
- package/dist/lib/feed/watch.js +27 -3
- package/dist/lib/feed-ranking.d.ts +1 -0
- package/dist/lib/feed-ranking.js +3 -1
- package/dist/lib/format.d.ts +0 -2
- package/dist/lib/format.js +0 -8
- package/dist/lib/github/open-prs.d.ts +0 -2
- package/dist/lib/github/open-prs.js +17 -35
- package/dist/lib/github/project-prs.d.ts +5 -0
- package/dist/lib/github/project-prs.js +73 -32
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hooks/cache.d.ts +1 -0
- package/dist/lib/hooks/cache.js +12 -1
- package/dist/lib/installations/duplicate-prune.d.ts +37 -0
- package/dist/lib/installations/duplicate-prune.js +85 -0
- package/dist/lib/installations/inventory-json.d.ts +20 -0
- package/dist/lib/installations/inventory-json.js +252 -0
- package/dist/lib/installations/shims.d.ts +0 -18
- package/dist/lib/installations/shims.js +1 -257
- package/dist/lib/lead/brief.d.ts +49 -0
- package/dist/lib/lead/brief.js +173 -0
- package/dist/lib/lead/client.d.ts +21 -0
- package/dist/lib/lead/client.js +167 -0
- package/dist/lib/lead/confirm.d.ts +22 -0
- package/dist/lib/lead/confirm.js +73 -0
- package/dist/lib/lead/events.d.ts +106 -0
- package/dist/lib/lead/events.js +188 -0
- package/dist/lib/lead/harness.d.ts +29 -0
- package/dist/lib/lead/harness.js +107 -0
- package/dist/lib/lead/host.d.ts +132 -0
- package/dist/lib/lead/host.js +675 -0
- package/dist/lib/lead/paths.d.ts +22 -0
- package/dist/lib/lead/paths.js +69 -0
- package/dist/lib/lead/refs.d.ts +17 -0
- package/dist/lib/lead/refs.js +75 -0
- package/dist/lib/lead/roster.d.ts +26 -0
- package/dist/lib/lead/roster.js +121 -0
- package/dist/lib/lead/shapes.d.ts +23 -0
- package/dist/lib/lead/shapes.js +95 -0
- package/dist/lib/lead/store.d.ts +46 -0
- package/dist/lib/lead/store.js +77 -0
- package/dist/lib/lead/tools.d.ts +18 -0
- package/dist/lib/lead/tools.js +106 -0
- package/dist/lib/lead/visibility.d.ts +16 -0
- package/dist/lib/lead/visibility.js +77 -0
- package/dist/lib/mailbox.d.ts +0 -18
- package/dist/lib/mailbox.js +0 -170
- package/dist/lib/menubar/notify-desktop.d.ts +5 -0
- package/dist/lib/menubar/notify-desktop.js +24 -0
- package/dist/lib/models.js +1 -19
- package/dist/lib/permissions.d.ts +0 -6
- package/dist/lib/permissions.js +0 -140
- package/dist/lib/platform/process.d.ts +1 -0
- package/dist/lib/platform/process.js +5 -0
- package/dist/lib/probe.js +13 -1
- package/dist/lib/project-status.js +4 -3
- package/dist/lib/projects.d.ts +9 -0
- package/dist/lib/projects.js +61 -3
- package/dist/lib/scheduling/routines.d.ts +1 -13
- package/dist/lib/scheduling/routines.js +1 -37
- package/dist/lib/secrets-cli.d.ts +3 -3
- package/dist/lib/secrets-cli.js +1 -1
- package/dist/lib/secrets-client.d.ts +4 -37
- package/dist/lib/secrets-client.js +19 -265
- package/dist/lib/session/active.d.ts +18 -8
- package/dist/lib/session/active.js +94 -18
- package/dist/lib/session/db.d.ts +0 -16
- package/dist/lib/session/db.js +1 -134
- package/dist/lib/session/detached.d.ts +0 -1
- package/dist/lib/session/detached.js +0 -18
- package/dist/lib/session/pending-work.d.ts +21 -0
- package/dist/lib/session/pending-work.js +284 -0
- package/dist/lib/session/remote/remote-list.d.ts +0 -3
- package/dist/lib/session/remote/remote-list.js +1 -23
- package/dist/lib/session/remote/watch.d.ts +5 -0
- package/dist/lib/session/remote/watch.js +19 -2
- package/dist/lib/session/session-cache.d.ts +1 -1
- package/dist/lib/session/session-cache.js +12 -5
- package/dist/lib/session/sync/provision.js +1 -2
- package/dist/lib/smart-launch.js +7 -2
- package/dist/lib/snapshot.js +3 -4
- package/dist/lib/ssh-exec.d.ts +0 -40
- package/dist/lib/ssh-exec.js +0 -108
- package/dist/lib/ssh-tunnel.d.ts +0 -6
- package/dist/lib/ssh-tunnel.js +0 -42
- package/dist/lib/standalone-tools.js +12 -1
- package/dist/lib/startup/command-registry.js +1 -1
- package/dist/lib/startup/spellcheck.d.ts +0 -1
- package/dist/lib/startup/spellcheck.js +1 -20
- package/dist/lib/state.d.ts +0 -6
- package/dist/lib/state.js +1 -14
- package/dist/lib/teams/delivery.d.ts +1 -0
- package/dist/lib/teams/delivery.js +13 -0
- package/dist/lib/types.d.ts +0 -37
- package/dist/lib/types.js +0 -9
- package/dist/lib/watchdog/log.d.ts +1 -1
- package/dist/lib/watchdog/log.js +6 -4
- package/package.json +2 -1
- package/dist/lib/artifact-actions.d.ts +0 -7
- package/dist/lib/artifact-actions.js +0 -39
- package/dist/lib/session/sync/managed-config.d.ts +0 -3
- package/dist/lib/session/sync/managed-config.js +0 -3
- package/dist/lib/session/sync/worker-template.d.ts +0 -1
- package/dist/lib/session/sync/worker-template.js +0 -807
- package/dist/lib/storage/selection.d.ts +0 -8
- package/dist/lib/storage/selection.js +0 -10
- package/dist/lib/watchdog/index.d.ts +0 -3
- package/dist/lib/watchdog/index.js +0 -3
|
@@ -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;
|
|
@@ -2,7 +2,7 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import { confirm
|
|
5
|
+
import { confirm } from '@inquirer/prompts';
|
|
6
6
|
import { IS_WINDOWS, prependToWindowsUserPath } from '../platform/index.js';
|
|
7
7
|
import { getShimsDir, getVersionsDir, getBackupsDir, getHistoryDir, ensureAgentsDir } from '../state.js';
|
|
8
8
|
export { getShimsDir };
|
|
@@ -83,86 +83,6 @@ export function hasLiveLaunchLease(agent, label) {
|
|
|
83
83
|
}
|
|
84
84
|
return live;
|
|
85
85
|
}
|
|
86
|
-
function detectConflicts(src, dest, prefix = '') {
|
|
87
|
-
const conflicts = [];
|
|
88
|
-
if (!fs.existsSync(src) || !fs.existsSync(dest)) {
|
|
89
|
-
return conflicts;
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
const destStat = fs.lstatSync(dest);
|
|
93
|
-
if (destStat.isSymbolicLink()) {
|
|
94
|
-
return conflicts;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
return conflicts;
|
|
99
|
-
}
|
|
100
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
101
|
-
for (const entry of entries) {
|
|
102
|
-
if (shouldIgnore(entry.name)) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
const srcPath = path.join(src, entry.name);
|
|
106
|
-
const destPath = path.join(dest, entry.name);
|
|
107
|
-
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
108
|
-
try {
|
|
109
|
-
const entryDestStat = fs.lstatSync(destPath);
|
|
110
|
-
if (entryDestStat.isSymbolicLink()) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (entry.isDirectory()) {
|
|
114
|
-
conflicts.push(...detectConflicts(srcPath, destPath, relativePath));
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
conflicts.push(relativePath);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return conflicts;
|
|
124
|
-
}
|
|
125
|
-
async function promptConflictStrategy(conflictInfos) {
|
|
126
|
-
const totalConflicts = conflictInfos.reduce((sum, info) => sum + info.conflicts.length, 0);
|
|
127
|
-
if (totalConflicts === 0) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
console.log('\nFile conflicts detected:');
|
|
131
|
-
for (const info of conflictInfos) {
|
|
132
|
-
const agentConfig = AGENTS[info.agent];
|
|
133
|
-
const configDir = agentConfig.configDir;
|
|
134
|
-
console.log(` ${info.conflicts.length} file(s) conflict between:`);
|
|
135
|
-
console.log(` ~/${configDir}/ (your config)`);
|
|
136
|
-
console.log(` ${agentConfig.name}@${info.version} (managed version)`);
|
|
137
|
-
}
|
|
138
|
-
console.log();
|
|
139
|
-
const firstInfo = conflictInfos[0];
|
|
140
|
-
const firstAgent = AGENTS[firstInfo.agent];
|
|
141
|
-
const versionLabel = conflictInfos.length === 1
|
|
142
|
-
? `${firstAgent.name}@${firstInfo.version}`
|
|
143
|
-
: 'version';
|
|
144
|
-
const strategy = await select({
|
|
145
|
-
message: 'Which files should be kept?',
|
|
146
|
-
choices: [
|
|
147
|
-
{
|
|
148
|
-
value: 'keep-dest',
|
|
149
|
-
name: `Keep ${versionLabel} files (recommended)`,
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
value: 'overwrite',
|
|
153
|
-
name: conflictInfos.length === 1
|
|
154
|
-
? `Keep ~/${firstAgent.configDir}/ files`
|
|
155
|
-
: 'Keep my config files',
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
value: 'ask-per-file',
|
|
159
|
-
name: `Decide per file (${totalConflicts} file${totalConflicts === 1 ? '' : 's'})`,
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
default: 'keep-dest',
|
|
163
|
-
});
|
|
164
|
-
return strategy;
|
|
165
|
-
}
|
|
166
86
|
export const SHIM_SCHEMA_VERSION = 33;
|
|
167
87
|
const SHIM_VERSION_MARKER = 'agents-shim-version:';
|
|
168
88
|
function shellQuote(value) {
|
|
@@ -1030,31 +950,6 @@ function getVersionConfigPath(agent, version) {
|
|
|
1030
950
|
const configDirName = path.relative(os.homedir(), agentConfig.configDir);
|
|
1031
951
|
return path.join(versionsDir, agent, version, 'home', configDirName);
|
|
1032
952
|
}
|
|
1033
|
-
function detectMigrationConflicts(agent, version) {
|
|
1034
|
-
const configPath = getAgentConfigPath(agent);
|
|
1035
|
-
const versionConfigPath = getVersionConfigPath(agent, version);
|
|
1036
|
-
try {
|
|
1037
|
-
const stat = fs.lstatSync(configPath);
|
|
1038
|
-
if (stat.isSymbolicLink()) {
|
|
1039
|
-
return null;
|
|
1040
|
-
}
|
|
1041
|
-
else if (stat.isDirectory()) {
|
|
1042
|
-
const conflicts = detectConflicts(configPath, versionConfigPath);
|
|
1043
|
-
return {
|
|
1044
|
-
agent,
|
|
1045
|
-
version,
|
|
1046
|
-
conflicts,
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
return null;
|
|
1050
|
-
}
|
|
1051
|
-
catch (err) {
|
|
1052
|
-
if (err.code === 'ENOENT') {
|
|
1053
|
-
return null;
|
|
1054
|
-
}
|
|
1055
|
-
return null;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
953
|
export function readAuthFileIdentity(agent, configDir) {
|
|
1059
954
|
return readAuthAccountIdentity(agent, configDir);
|
|
1060
955
|
}
|
|
@@ -1984,154 +1879,3 @@ export function listAgentsWithNonIsolatedInstalledVersions() {
|
|
|
1984
1879
|
.some((entry) => entry.isDirectory() && !isInstalledVersionIsolated(agent, entry.name));
|
|
1985
1880
|
});
|
|
1986
1881
|
}
|
|
1987
|
-
function ensureAllShims() {
|
|
1988
|
-
const versionsDir = getVersionsDir();
|
|
1989
|
-
if (!fs.existsSync(versionsDir)) {
|
|
1990
|
-
return;
|
|
1991
|
-
}
|
|
1992
|
-
const entries = fs.readdirSync(versionsDir, { withFileTypes: true });
|
|
1993
|
-
for (const entry of entries) {
|
|
1994
|
-
if (entry.isDirectory() && AGENTS[entry.name]) {
|
|
1995
|
-
const agent = entry.name;
|
|
1996
|
-
const agentVersionsDir = path.join(versionsDir, agent);
|
|
1997
|
-
const versions = fs.readdirSync(agentVersionsDir, { withFileTypes: true })
|
|
1998
|
-
.filter((e) => e.isDirectory() && !isInstalledVersionIsolated(agent, e.name));
|
|
1999
|
-
if (versions.length > 0 && !shimExists(agent)) {
|
|
2000
|
-
createShim(agent);
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
function compareVersionResources(agent, currentVersion, targetVersion) {
|
|
2006
|
-
const agentConfig = AGENTS[agent];
|
|
2007
|
-
const currentPath = getVersionConfigPath(agent, currentVersion);
|
|
2008
|
-
const targetPath = getVersionConfigPath(agent, targetVersion);
|
|
2009
|
-
const diff = {
|
|
2010
|
-
commands: [],
|
|
2011
|
-
skills: [],
|
|
2012
|
-
hooks: [],
|
|
2013
|
-
memory: [],
|
|
2014
|
-
mcp: [],
|
|
2015
|
-
};
|
|
2016
|
-
const listDir = (dir) => {
|
|
2017
|
-
if (!fs.existsSync(dir))
|
|
2018
|
-
return [];
|
|
2019
|
-
try {
|
|
2020
|
-
return fs.readdirSync(dir).filter(f => !f.startsWith('.'));
|
|
2021
|
-
}
|
|
2022
|
-
catch {
|
|
2023
|
-
return [];
|
|
2024
|
-
}
|
|
2025
|
-
};
|
|
2026
|
-
const countLines = (filePath) => {
|
|
2027
|
-
if (!fs.existsSync(filePath))
|
|
2028
|
-
return 0;
|
|
2029
|
-
try {
|
|
2030
|
-
return fs.readFileSync(filePath, 'utf-8').split('\n').length;
|
|
2031
|
-
}
|
|
2032
|
-
catch {
|
|
2033
|
-
return 0;
|
|
2034
|
-
}
|
|
2035
|
-
};
|
|
2036
|
-
const currentCommands = listDir(path.join(currentPath, agentConfig.commandsSubdir));
|
|
2037
|
-
const targetCommands = new Set(listDir(path.join(targetPath, agentConfig.commandsSubdir)));
|
|
2038
|
-
diff.commands = currentCommands.filter(c => !targetCommands.has(c)).map(c => c.replace(/\.(md|toml)$/, ''));
|
|
2039
|
-
const currentSkills = listDir(path.join(currentPath, 'skills'));
|
|
2040
|
-
const targetSkills = new Set(listDir(path.join(targetPath, 'skills')));
|
|
2041
|
-
diff.skills = currentSkills.filter(s => !targetSkills.has(s));
|
|
2042
|
-
const currentHooks = listDir(path.join(currentPath, 'hooks'));
|
|
2043
|
-
const targetHooks = new Set(listDir(path.join(targetPath, 'hooks')));
|
|
2044
|
-
diff.hooks = currentHooks.filter(h => !targetHooks.has(h));
|
|
2045
|
-
const memoryFile = agentConfig.instructionsFile;
|
|
2046
|
-
const currentMemoryPath = path.join(currentPath, memoryFile);
|
|
2047
|
-
const targetMemoryPath = path.join(targetPath, memoryFile);
|
|
2048
|
-
const currentLines = countLines(currentMemoryPath);
|
|
2049
|
-
const targetLines = countLines(targetMemoryPath);
|
|
2050
|
-
if (currentLines > 0 && currentLines !== targetLines) {
|
|
2051
|
-
diff.memory.push({ file: memoryFile, currentLines, targetLines });
|
|
2052
|
-
}
|
|
2053
|
-
const readMcpServers = (configPath) => {
|
|
2054
|
-
const settingsPath = path.join(configPath, 'settings.json');
|
|
2055
|
-
if (!fs.existsSync(settingsPath))
|
|
2056
|
-
return [];
|
|
2057
|
-
try {
|
|
2058
|
-
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
2059
|
-
return Object.keys(settings.mcpServers || {});
|
|
2060
|
-
}
|
|
2061
|
-
catch {
|
|
2062
|
-
return [];
|
|
2063
|
-
}
|
|
2064
|
-
};
|
|
2065
|
-
const currentMcp = readMcpServers(currentPath);
|
|
2066
|
-
const targetMcp = new Set(readMcpServers(targetPath));
|
|
2067
|
-
diff.mcp = currentMcp.filter(m => !targetMcp.has(m));
|
|
2068
|
-
return diff;
|
|
2069
|
-
}
|
|
2070
|
-
export function hasResourceDiff(diff) {
|
|
2071
|
-
return (diff.commands.length > 0 ||
|
|
2072
|
-
diff.skills.length > 0 ||
|
|
2073
|
-
diff.hooks.length > 0 ||
|
|
2074
|
-
diff.memory.length > 0 ||
|
|
2075
|
-
diff.mcp.length > 0);
|
|
2076
|
-
}
|
|
2077
|
-
function copyResourcesToVersion(agent, fromVersion, toVersion, diff) {
|
|
2078
|
-
const agentConfig = AGENTS[agent];
|
|
2079
|
-
const fromPath = getVersionConfigPath(agent, fromVersion);
|
|
2080
|
-
const toPath = getVersionConfigPath(agent, toVersion);
|
|
2081
|
-
const copyItem = (srcDir, destDir, name) => {
|
|
2082
|
-
const srcPath = path.join(srcDir, name);
|
|
2083
|
-
const destPath = path.join(destDir, name);
|
|
2084
|
-
if (!fs.existsSync(srcPath))
|
|
2085
|
-
return;
|
|
2086
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
2087
|
-
const stat = fs.statSync(srcPath);
|
|
2088
|
-
if (stat.isDirectory()) {
|
|
2089
|
-
copyDirContents(srcPath, destPath);
|
|
2090
|
-
}
|
|
2091
|
-
else {
|
|
2092
|
-
fs.copyFileSync(srcPath, destPath);
|
|
2093
|
-
}
|
|
2094
|
-
};
|
|
2095
|
-
const commandsSubdir = agentConfig.commandsSubdir;
|
|
2096
|
-
const ext = agentConfig.format === 'toml' ? '.toml' : '.md';
|
|
2097
|
-
for (const cmd of diff.commands) {
|
|
2098
|
-
copyItem(path.join(fromPath, commandsSubdir), path.join(toPath, commandsSubdir), `${cmd}${ext}`);
|
|
2099
|
-
}
|
|
2100
|
-
for (const skill of diff.skills) {
|
|
2101
|
-
copyItem(path.join(fromPath, 'skills'), path.join(toPath, 'skills'), skill);
|
|
2102
|
-
}
|
|
2103
|
-
for (const hook of diff.hooks) {
|
|
2104
|
-
copyItem(path.join(fromPath, 'hooks'), path.join(toPath, 'hooks'), hook);
|
|
2105
|
-
}
|
|
2106
|
-
for (const mem of diff.memory) {
|
|
2107
|
-
const srcPath = path.join(fromPath, mem.file);
|
|
2108
|
-
const destPath = path.join(toPath, mem.file);
|
|
2109
|
-
if (fs.existsSync(srcPath)) {
|
|
2110
|
-
fs.copyFileSync(srcPath, destPath);
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
if (diff.mcp.length > 0) {
|
|
2114
|
-
const fromSettingsPath = path.join(fromPath, 'settings.json');
|
|
2115
|
-
const toSettingsPath = path.join(toPath, 'settings.json');
|
|
2116
|
-
if (fs.existsSync(fromSettingsPath)) {
|
|
2117
|
-
try {
|
|
2118
|
-
const fromSettings = JSON.parse(fs.readFileSync(fromSettingsPath, 'utf-8'));
|
|
2119
|
-
let toSettings = {};
|
|
2120
|
-
if (fs.existsSync(toSettingsPath)) {
|
|
2121
|
-
toSettings = JSON.parse(fs.readFileSync(toSettingsPath, 'utf-8'));
|
|
2122
|
-
}
|
|
2123
|
-
if (!toSettings.mcpServers) {
|
|
2124
|
-
toSettings.mcpServers = {};
|
|
2125
|
-
}
|
|
2126
|
-
for (const serverName of diff.mcp) {
|
|
2127
|
-
if (fromSettings.mcpServers?.[serverName]) {
|
|
2128
|
-
toSettings.mcpServers[serverName] = fromSettings.mcpServers[serverName];
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
fs.writeFileSync(toSettingsPath, JSON.stringify(toSettings, null, 2));
|
|
2132
|
-
}
|
|
2133
|
-
catch {
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ProjectDef } from '../projects.js';
|
|
2
|
+
import { type RosterSnapshot } from './roster.js';
|
|
3
|
+
export declare const BRIEF_FETCH_TIMEOUT_MS = 8000;
|
|
4
|
+
export interface BriefTicket {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
state?: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BriefPr {
|
|
11
|
+
number: number;
|
|
12
|
+
title: string;
|
|
13
|
+
url: string;
|
|
14
|
+
draft: boolean;
|
|
15
|
+
open: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface BriefInputs {
|
|
18
|
+
project: string;
|
|
19
|
+
def: ProjectDef;
|
|
20
|
+
agentsDigest: string | null;
|
|
21
|
+
roster: RosterSnapshot;
|
|
22
|
+
fleet: string;
|
|
23
|
+
tickets: BriefTicket[] | {
|
|
24
|
+
error: string;
|
|
25
|
+
};
|
|
26
|
+
prs: BriefPr[] | {
|
|
27
|
+
error: string;
|
|
28
|
+
};
|
|
29
|
+
memory: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const LEAD_RULES: string[];
|
|
32
|
+
export declare function agentsMdDigest(root: string | undefined): string | null;
|
|
33
|
+
export declare function fetchOpenTickets(def: ProjectDef, cwd: string | undefined): Promise<BriefTicket[]>;
|
|
34
|
+
export declare function fetchRecentPrs(repo: string | undefined, cwd: string | undefined): Promise<BriefPr[]>;
|
|
35
|
+
export declare function linearTeamKey(home: string): string | undefined;
|
|
36
|
+
export declare function quoteNotes(memory: string): string;
|
|
37
|
+
export declare function projectRepo(def: ProjectDef): string | undefined;
|
|
38
|
+
export declare function buildBrief(inputs: BriefInputs): string;
|
|
39
|
+
export declare function briefSummary(inputs: BriefInputs): string[];
|
|
40
|
+
export declare function fleetLine(rows: Array<{
|
|
41
|
+
status: string;
|
|
42
|
+
host: string;
|
|
43
|
+
}>, selfExcluded: number): string;
|
|
44
|
+
export declare function composeTurnMessage(opts: {
|
|
45
|
+
brief?: string;
|
|
46
|
+
delta: string[];
|
|
47
|
+
text: string;
|
|
48
|
+
voiceSecs?: number;
|
|
49
|
+
}): string;
|