@phnx-labs/agents-cli 1.23.21 → 1.23.23
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 +115 -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 +53 -28
- package/dist/lib/daemon/attention-notify-service.js +232 -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/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
package/dist/commands/view.js
CHANGED
|
@@ -5,11 +5,10 @@ import { termLink } from '../lib/format.js';
|
|
|
5
5
|
import ora from 'ora';
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
import * as path from 'path';
|
|
8
|
-
import { AGENTS, ALL_AGENT_IDS, accountDisplayLabel, getAllCliStates, getUnmanagedCliState, getAccountInfo,
|
|
8
|
+
import { AGENTS, ALL_AGENT_IDS, accountDisplayLabel, getAllCliStates, getUnmanagedCliState, getAccountInfo, resolveAgentName, formatAgentError, agentLabel, colorAgent, } from '../lib/agents.js';
|
|
9
9
|
import { ambientClaudeToken, loginHint } from '../lib/signin-badge.js';
|
|
10
10
|
import { machineId } from '../lib/machine-id.js';
|
|
11
|
-
import {
|
|
12
|
-
import { deriveUsageStatusFromSnapshot, formatUsageSection, formatUsageSummary, formatUsageStatusBadge, getUsageInfoForIdentity, getUsageInfoByIdentity, getUsageLookupKey, usageErrorForDisplay, viewUsageSummaryOptions, } from '../lib/accounting/usage.js';
|
|
11
|
+
import { deriveUsageStatusFromSnapshot, formatUsageSection, formatUsageSummary, formatUsageStatusBadge, getUsageInfoForIdentity, getUsageInfoByIdentity, getUsageLookupKey, viewUsageSummaryOptions, } from '../lib/accounting/usage.js';
|
|
13
12
|
import { OVERVIEW_MAX_USAGE_WINDOWS } from '../lib/account-catalog.js';
|
|
14
13
|
import { isHeadedDeviceRole, selfConfiguredDeviceRole } from '../lib/device-config.js';
|
|
15
14
|
import { readManifest } from '../lib/manifest.js';
|
|
@@ -21,20 +20,20 @@ import { resolveVersionFilter, AgentSpecError } from '../lib/agent-spec/index.js
|
|
|
21
20
|
import { listCliStatus } from '../lib/cli-resources.js';
|
|
22
21
|
import { isCapable } from '../lib/capabilities.js';
|
|
23
22
|
import { discoverPlugins, pluginSupportsAgent } from '../lib/plugins/plugins.js';
|
|
24
|
-
import { getAgentsDir,
|
|
23
|
+
import { getAgentsDir, getEffectivePromptcutsPath, readMergedPromptcuts, readMeta } from '../lib/state.js';
|
|
25
24
|
import { findNativeAccountByIdentity } from '../lib/account-registry.js';
|
|
26
|
-
import { ACCOUNT_LISTING_LEGEND,
|
|
25
|
+
import { ACCOUNT_LISTING_LEGEND, loadAccountCatalog, renderAccountRows, secretsUnavailableNote } from '../lib/account-catalog.js';
|
|
27
26
|
import { addSupported } from '../lib/accounts/add.js';
|
|
28
27
|
import { readInstallation } from '../lib/installations/store.js';
|
|
29
28
|
import { isAutoUpdateEnabledForAgent } from '../lib/installations/update-policy.js';
|
|
30
29
|
import { selectUpdateStrategy } from '../lib/installations/strategies.js';
|
|
31
|
-
import { isGitRepo, getGitSyncStatus } from '../lib/git.js';
|
|
32
|
-
import { getCentralRulesFileName } from '../lib/rules/rules.js';
|
|
33
30
|
import { composeRulesFromState } from '../lib/rules/compose.js';
|
|
34
|
-
import { getConfiguredRunStrategy
|
|
31
|
+
import { getConfiguredRunStrategy } from '../lib/accounting/rotate.js';
|
|
35
32
|
import { resolveRunDefaults } from '../lib/run-defaults.js';
|
|
36
33
|
import { resolveConfiguredModel } from '../lib/models.js';
|
|
37
|
-
import {
|
|
34
|
+
import { collectAgentsJson, getHarnesses, loadResourceSyncData, resolveResourceSyncState } from '../lib/installations/inventory-json.js';
|
|
35
|
+
import { compareVersionLabels, planDuplicatePrune } from '../lib/installations/duplicate-prune.js';
|
|
36
|
+
import { profileExists, profileSummary, readProfile } from '../lib/profiles.js';
|
|
38
37
|
import { getByokUsageForHarness, hasByokProvider, renderByokBar } from '../lib/byok-usage.js';
|
|
39
38
|
import { renderHarnessDetail } from './harness.js';
|
|
40
39
|
import { confirm } from '@inquirer/prompts';
|
|
@@ -65,7 +64,7 @@ export function compareAccountOrderedVersions(a, b, globalDefault) {
|
|
|
65
64
|
if (emailOrder !== 0)
|
|
66
65
|
return emailOrder;
|
|
67
66
|
}
|
|
68
|
-
return
|
|
67
|
+
return compareVersionLabels(b.version, a.version);
|
|
69
68
|
}
|
|
70
69
|
export function joinViewColumns(cols) {
|
|
71
70
|
let end = cols.length;
|
|
@@ -73,9 +72,6 @@ export function joinViewColumns(cols) {
|
|
|
73
72
|
end--;
|
|
74
73
|
return cols.slice(0, end).join(' ');
|
|
75
74
|
}
|
|
76
|
-
function getHarnesses() {
|
|
77
|
-
return listProfiles().map(profileSummary);
|
|
78
|
-
}
|
|
79
75
|
function harnessVersionLabel(harness, globalDefault) {
|
|
80
76
|
const version = harness.hostVersion ?? globalDefault;
|
|
81
77
|
if (version) {
|
|
@@ -130,17 +126,6 @@ function formatLastActive(date) {
|
|
|
130
126
|
return chalk.gray(`${days}d ago`);
|
|
131
127
|
return chalk.gray(`${days}d ago`);
|
|
132
128
|
}
|
|
133
|
-
function compareVersions(a, b) {
|
|
134
|
-
const partsA = a.split('.').map(Number);
|
|
135
|
-
const partsB = b.split('.').map(Number);
|
|
136
|
-
for (let i = 0; i < 3; i++) {
|
|
137
|
-
if (partsA[i] > partsB[i])
|
|
138
|
-
return 1;
|
|
139
|
-
if (partsA[i] < partsB[i])
|
|
140
|
-
return -1;
|
|
141
|
-
}
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
144
129
|
function getProjectVersionFromCwd(agent) {
|
|
145
130
|
const manifestPath = path.join(process.cwd(), '.agents', 'agents.yaml');
|
|
146
131
|
if (!fs.existsSync(manifestPath)) {
|
|
@@ -919,90 +904,6 @@ async function showAgentResources(agentId, requestedVersion, filter) {
|
|
|
919
904
|
}
|
|
920
905
|
}
|
|
921
906
|
const ALL_RESOURCE_SECTIONS = ['commands', 'skills', 'mcp', 'memory', 'hooks', 'workflows', 'plugins'];
|
|
922
|
-
async function loadResourceSyncData() {
|
|
923
|
-
const userAgentsDir = getUserAgentsDir();
|
|
924
|
-
const hasGitRepo = isGitRepo(userAgentsDir);
|
|
925
|
-
return {
|
|
926
|
-
hasGitRepo,
|
|
927
|
-
commands: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'commands') : null,
|
|
928
|
-
skills: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'skills') : null,
|
|
929
|
-
hooks: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'hooks') : null,
|
|
930
|
-
memory: hasGitRepo ? await getGitSyncStatus(userAgentsDir, 'rules') : null,
|
|
931
|
-
};
|
|
932
|
-
}
|
|
933
|
-
function resolveResourceSyncState(agentId, resourceName, resourceType, syncStatus) {
|
|
934
|
-
if (!syncStatus)
|
|
935
|
-
return undefined;
|
|
936
|
-
let relativePath;
|
|
937
|
-
if (resourceType === 'commands') {
|
|
938
|
-
relativePath = `commands/${resourceName}.md`;
|
|
939
|
-
}
|
|
940
|
-
else if (resourceType === 'skills') {
|
|
941
|
-
relativePath = `skills/${resourceName}`;
|
|
942
|
-
}
|
|
943
|
-
else if (resourceType === 'hooks') {
|
|
944
|
-
relativePath = `hooks/${resourceName}`;
|
|
945
|
-
}
|
|
946
|
-
else {
|
|
947
|
-
const centralName = getCentralRulesFileName(agentId);
|
|
948
|
-
relativePath = `rules/${centralName}`;
|
|
949
|
-
}
|
|
950
|
-
const matchesPath = (f) => f === relativePath || f.startsWith(relativePath + '/');
|
|
951
|
-
if (syncStatus.new.some(matchesPath) || syncStatus.staged.some(matchesPath))
|
|
952
|
-
return 'new';
|
|
953
|
-
if (syncStatus.modified.some(matchesPath))
|
|
954
|
-
return 'modified';
|
|
955
|
-
if (syncStatus.deleted.some(matchesPath))
|
|
956
|
-
return 'deleted';
|
|
957
|
-
if (syncStatus.synced.some(matchesPath))
|
|
958
|
-
return 'synced';
|
|
959
|
-
return 'new';
|
|
960
|
-
}
|
|
961
|
-
function collectVersionResources(agentId, home, cwd, cliInstalled, sections, sync) {
|
|
962
|
-
const res = getAgentResources(agentId, { cwd, scope: 'all', cliInstalled, home });
|
|
963
|
-
const out = {};
|
|
964
|
-
const withSync = (r, type, syncStatus) => {
|
|
965
|
-
const item = { name: r.name, scope: r.scope };
|
|
966
|
-
if (r.scope !== 'project') {
|
|
967
|
-
const s = resolveResourceSyncState(agentId, r.name, type, syncStatus);
|
|
968
|
-
if (s)
|
|
969
|
-
item.syncState = s;
|
|
970
|
-
}
|
|
971
|
-
if (r.description)
|
|
972
|
-
item.description = r.description;
|
|
973
|
-
return item;
|
|
974
|
-
};
|
|
975
|
-
if (sections.has('commands'))
|
|
976
|
-
out.commands = res.commands.map((r) => withSync(r, 'commands', sync.commands));
|
|
977
|
-
if (sections.has('skills')) {
|
|
978
|
-
out.skills = res.skills.map((r) => {
|
|
979
|
-
const item = withSync(r, 'skills', sync.skills);
|
|
980
|
-
if (r.ruleCount && r.ruleCount > 0)
|
|
981
|
-
item.ruleCount = r.ruleCount;
|
|
982
|
-
return item;
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
if (sections.has('mcp')) {
|
|
986
|
-
out.mcp = res.mcp.map((r) => {
|
|
987
|
-
const item = { name: r.name, scope: r.scope };
|
|
988
|
-
if (r.scope !== 'project')
|
|
989
|
-
item.syncState = 'synced';
|
|
990
|
-
return item;
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
if (sections.has('memory'))
|
|
994
|
-
out.memory = res.memory.map((r) => withSync(r, 'memory', sync.memory));
|
|
995
|
-
if (sections.has('hooks'))
|
|
996
|
-
out.hooks = res.hooks.map((r) => withSync(r, 'hooks', sync.hooks));
|
|
997
|
-
if (sections.has('workflows'))
|
|
998
|
-
out.workflows = res.workflows.map((r) => ({ name: r.name, scope: r.scope }));
|
|
999
|
-
if (sections.has('plugins')) {
|
|
1000
|
-
out.plugins = discoverPlugins()
|
|
1001
|
-
.filter((p) => pluginSupportsAgent(p, agentId))
|
|
1002
|
-
.map((p) => ({ name: p.name }));
|
|
1003
|
-
}
|
|
1004
|
-
return out;
|
|
1005
|
-
}
|
|
1006
907
|
export function parseResourceSections(options, jsonMode) {
|
|
1007
908
|
const set = new Set();
|
|
1008
909
|
const addAll = () => ALL_RESOURCE_SECTIONS.forEach((s) => set.add(s));
|
|
@@ -1032,228 +933,6 @@ export function parseResourceSections(options, jsonMode) {
|
|
|
1032
933
|
}
|
|
1033
934
|
return set;
|
|
1034
935
|
}
|
|
1035
|
-
export async function computeAgentRunReady(agentId) {
|
|
1036
|
-
const candidates = await collectRunCandidates(agentId);
|
|
1037
|
-
if (candidates.length === 0)
|
|
1038
|
-
return undefined;
|
|
1039
|
-
const accounts = candidates.map((c) => {
|
|
1040
|
-
const readiness = readinessFromCandidate(c);
|
|
1041
|
-
const name = c.nativeAccount || c.accountLabel || c.email || c.version;
|
|
1042
|
-
return { name, ready: readiness.ready, reason: readiness.ready ? 'ready' : readiness.reason };
|
|
1043
|
-
});
|
|
1044
|
-
const readyAccount = accounts.find((a) => a.ready);
|
|
1045
|
-
let reason;
|
|
1046
|
-
if (readyAccount) {
|
|
1047
|
-
reason = `ready (${readyAccount.name})`;
|
|
1048
|
-
}
|
|
1049
|
-
else {
|
|
1050
|
-
const reasons = [...new Set(accounts.map((a) => a.reason))];
|
|
1051
|
-
reason = reasons.length === 1 ? `all ${reasons[0]}` : reasons.join(', ');
|
|
1052
|
-
}
|
|
1053
|
-
return { ready: !!readyAccount, reason, accounts };
|
|
1054
|
-
}
|
|
1055
|
-
export async function collectAgentsJson(filterAgentId, resourceSections, opts) {
|
|
1056
|
-
const agentsToShow = filterAgentId ? [filterAgentId] : ALL_AGENT_IDS;
|
|
1057
|
-
const authCache = readAuthHealthCache();
|
|
1058
|
-
const host = machineId();
|
|
1059
|
-
const wantResources = !!resourceSections && resourceSections.size > 0;
|
|
1060
|
-
const resourceSync = wantResources ? await loadResourceSyncData() : null;
|
|
1061
|
-
const cliStates = wantResources ? await getAllCliStates() : null;
|
|
1062
|
-
const infoFetches = [];
|
|
1063
|
-
for (const agentId of agentsToShow) {
|
|
1064
|
-
for (const ver of listInstalledVersions(agentId)) {
|
|
1065
|
-
const home = getVersionHomePath(agentId, ver);
|
|
1066
|
-
infoFetches.push(getAccountInfo(agentId, home).then((info) => ({ agentId, version: ver, home, info })));
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
const infoResults = await Promise.all(infoFetches);
|
|
1070
|
-
const globalReleases = new Map();
|
|
1071
|
-
await Promise.all(agentsToShow.filter(isGlobalBinaryAgent).map(async (agent) => {
|
|
1072
|
-
if (!infoResults.some((row) => row.agentId === agent))
|
|
1073
|
-
return;
|
|
1074
|
-
const release = await getLiveVersion(agent);
|
|
1075
|
-
if (release)
|
|
1076
|
-
globalReleases.set(agent, release);
|
|
1077
|
-
}));
|
|
1078
|
-
const actualRelease = (agent, label) => globalReleases.get(agent) ?? readInstallation(agent, label)?.releaseVersion ?? label;
|
|
1079
|
-
const { canonicalByUsageKey, usageByKey } = await getUsageInfoByIdentity(infoResults.map(({ agentId, home, version, info }) => ({
|
|
1080
|
-
agentId,
|
|
1081
|
-
home,
|
|
1082
|
-
cliVersion: version,
|
|
1083
|
-
info,
|
|
1084
|
-
})), { forceRefresh: opts?.forceRefresh === true });
|
|
1085
|
-
const mergeCanonical = (info) => {
|
|
1086
|
-
const key = getUsageLookupKey(info);
|
|
1087
|
-
if (!key)
|
|
1088
|
-
return info;
|
|
1089
|
-
const canon = canonicalByUsageKey.get(key);
|
|
1090
|
-
if (!canon)
|
|
1091
|
-
return info;
|
|
1092
|
-
return {
|
|
1093
|
-
...info,
|
|
1094
|
-
plan: usageByKey.get(key)?.snapshot?.plan ?? canon.plan,
|
|
1095
|
-
usageStatus: deriveUsageStatusFromSnapshot(usageByKey.get(key)?.snapshot),
|
|
1096
|
-
overageCredits: canon.overageCredits,
|
|
1097
|
-
};
|
|
1098
|
-
};
|
|
1099
|
-
const byAgent = new Map();
|
|
1100
|
-
for (const { agentId, version, home, info: rawInfo } of infoResults) {
|
|
1101
|
-
const info = mergeCanonical(rawInfo);
|
|
1102
|
-
const globalDefault = getGlobalDefault(agentId);
|
|
1103
|
-
const usageKey = getUsageLookupKey(info);
|
|
1104
|
-
const usageInfo = usageKey ? usageByKey.get(usageKey) : undefined;
|
|
1105
|
-
const snapshot = usageInfo?.snapshot ?? null;
|
|
1106
|
-
const authHealth = authCache[authCacheKey(host, agentId, version)];
|
|
1107
|
-
const entry = {
|
|
1108
|
-
version,
|
|
1109
|
-
releaseVersion: actualRelease(agentId, version),
|
|
1110
|
-
isDefault: version === globalDefault,
|
|
1111
|
-
isolated: isVersionIsolated(agentId, version),
|
|
1112
|
-
isIsolatedDefault: getIsolatedDefault(agentId) === version,
|
|
1113
|
-
signedIn: info.signedIn,
|
|
1114
|
-
launchable: isLaunchableSignedIn(info.signedIn, credentialPresence(agentId, home)),
|
|
1115
|
-
authVerdict: authHealth?.verdict ?? null,
|
|
1116
|
-
authCheckedAt: authHealth?.checkedAt ?? null,
|
|
1117
|
-
email: info.email,
|
|
1118
|
-
accountId: info.accountId,
|
|
1119
|
-
organizationType: info.organizationType ?? null,
|
|
1120
|
-
organizationName: info.organizationName ?? null,
|
|
1121
|
-
plan: info.plan,
|
|
1122
|
-
usageStatus: info.usageStatus,
|
|
1123
|
-
usageCapturedAt: snapshot?.capturedAt?.toISOString() ?? null,
|
|
1124
|
-
overageCredits: info.overageCredits,
|
|
1125
|
-
usageError: usageErrorForDisplay(usageInfo?.error),
|
|
1126
|
-
windows: snapshot
|
|
1127
|
-
? snapshot.windows.map((w) => ({
|
|
1128
|
-
key: w.key,
|
|
1129
|
-
label: w.label,
|
|
1130
|
-
usedPercent: w.usedPercent,
|
|
1131
|
-
resetsAt: w.resetsAt ? w.resetsAt.toISOString() : null,
|
|
1132
|
-
}))
|
|
1133
|
-
: [],
|
|
1134
|
-
unavailable: snapshot?.unavailable
|
|
1135
|
-
? {
|
|
1136
|
-
reason: snapshot.unavailable.reason,
|
|
1137
|
-
resetsAt: snapshot.unavailable.resetsAt?.toISOString(),
|
|
1138
|
-
}
|
|
1139
|
-
: undefined,
|
|
1140
|
-
lastActive: info.lastActive ? info.lastActive.toISOString() : null,
|
|
1141
|
-
path: getVersionDir(agentId, version),
|
|
1142
|
-
configuredModel: resolveConfiguredModel(agentId, version),
|
|
1143
|
-
};
|
|
1144
|
-
if (wantResources && resourceSync) {
|
|
1145
|
-
entry.resources = collectVersionResources(agentId, home, process.cwd(), cliStates?.[agentId]?.installed ?? false, resourceSections, resourceSync);
|
|
1146
|
-
}
|
|
1147
|
-
const existing = byAgent.get(agentId);
|
|
1148
|
-
if (existing)
|
|
1149
|
-
existing.push(entry);
|
|
1150
|
-
else
|
|
1151
|
-
byAgent.set(agentId, [entry]);
|
|
1152
|
-
}
|
|
1153
|
-
const harnesses = filterAgentId ? [] : getHarnesses();
|
|
1154
|
-
const catalog = await loadAccountCatalog();
|
|
1155
|
-
const note = secretsUnavailableNote(catalog);
|
|
1156
|
-
if (note)
|
|
1157
|
-
console.error(chalk.yellow(note));
|
|
1158
|
-
const runReadyByAgent = new Map();
|
|
1159
|
-
await Promise.all(agentsToShow.map(async (agentId) => {
|
|
1160
|
-
const runReady = await computeAgentRunReady(agentId);
|
|
1161
|
-
if (runReady)
|
|
1162
|
-
runReadyByAgent.set(agentId, runReady);
|
|
1163
|
-
}));
|
|
1164
|
-
const out = [];
|
|
1165
|
-
for (const agentId of agentsToShow) {
|
|
1166
|
-
const versions = byAgent.get(agentId) ?? [];
|
|
1167
|
-
versions.sort((a, b) => {
|
|
1168
|
-
if (a.isDefault !== b.isDefault)
|
|
1169
|
-
return a.isDefault ? -1 : 1;
|
|
1170
|
-
return compareVersions(b.version, a.version);
|
|
1171
|
-
});
|
|
1172
|
-
const accounts = accountListJson(catalog.native.filter((row) => row.agent === agentId), catalog.provider.filter((row) => row.harnesses.includes(agentId)), agentId).accounts;
|
|
1173
|
-
out.push({
|
|
1174
|
-
agent: agentId,
|
|
1175
|
-
versions,
|
|
1176
|
-
accounts,
|
|
1177
|
-
runReady: runReadyByAgent.get(agentId),
|
|
1178
|
-
harnesses: harnesses.filter((h) => h.agent === agentId),
|
|
1179
|
-
});
|
|
1180
|
-
}
|
|
1181
|
-
return out;
|
|
1182
|
-
}
|
|
1183
|
-
export function pruneGroupKey(info) {
|
|
1184
|
-
return info.accountKey ?? info.email?.toLowerCase() ?? null;
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* PURE duplicate-home detection: given every installed home for one agent, decide
|
|
1188
|
-
* which are redundant duplicates of the SAME logical account and which single home
|
|
1189
|
-
* to keep per account. Extracted from buildAgentPrunePlan so the keeper/merge rules
|
|
1190
|
-
* are unit-tested without touching disk.
|
|
1191
|
-
*
|
|
1192
|
-
* Two rules, both conservative:
|
|
1193
|
-
* - GROUPING. A home with a captured `accountKey` groups by it (account+org, so a
|
|
1194
|
-
* personal Max and a Team seat on the same email stay separate). A home with NO
|
|
1195
|
-
* accountKey folds into a same-email account ONLY when a sibling home for that
|
|
1196
|
-
* email IS identified — that email-only home is an incompletely-captured re-login
|
|
1197
|
-
* of the known account, not a distinct seat (PHNX-3887). Otherwise it groups by
|
|
1198
|
-
* its bare email and only ever collapses against another equally-bare home.
|
|
1199
|
-
* - KEEPER. Within a group the keeper is the home that best represents the account:
|
|
1200
|
-
* captured identity first, then a signed-in credential, then the newest RUNNING
|
|
1201
|
-
* release, then the highest dir label as a stable tiebreak. This is deliberately
|
|
1202
|
-
* NOT "highest dir-name semver" — in the wild that is the freshly re-logged-in
|
|
1203
|
-
* duplicate that never captured its identity or usage, and keeping it while
|
|
1204
|
-
* trashing the identified home is the exact bug this replaces.
|
|
1205
|
-
*/
|
|
1206
|
-
export function planDuplicatePrune(candidates) {
|
|
1207
|
-
const installed = candidates.filter((c) => c.hasBinary && c.email);
|
|
1208
|
-
const emailToAccountKeys = new Map();
|
|
1209
|
-
for (const c of installed) {
|
|
1210
|
-
if (!c.accountKey)
|
|
1211
|
-
continue;
|
|
1212
|
-
const email = c.email.toLowerCase();
|
|
1213
|
-
(emailToAccountKeys.get(email) ?? emailToAccountKeys.set(email, new Set()).get(email)).add(c.accountKey);
|
|
1214
|
-
}
|
|
1215
|
-
const groupKeyFor = (c) => {
|
|
1216
|
-
if (c.accountKey)
|
|
1217
|
-
return c.accountKey;
|
|
1218
|
-
const email = c.email?.toLowerCase();
|
|
1219
|
-
const keys = email ? emailToAccountKeys.get(email) : undefined;
|
|
1220
|
-
if (keys && keys.size === 1)
|
|
1221
|
-
return [...keys][0];
|
|
1222
|
-
if (keys && keys.size >= 2)
|
|
1223
|
-
return `ambiguous:${c.email.toLowerCase()}:${c.version}`;
|
|
1224
|
-
return pruneGroupKey(c);
|
|
1225
|
-
};
|
|
1226
|
-
const byAccount = new Map();
|
|
1227
|
-
for (const c of installed) {
|
|
1228
|
-
const key = groupKeyFor(c);
|
|
1229
|
-
if (!key)
|
|
1230
|
-
continue;
|
|
1231
|
-
(byAccount.get(key) ?? byAccount.set(key, []).get(key)).push(c);
|
|
1232
|
-
}
|
|
1233
|
-
const rank = (c) => [c.accountKey ? 1 : 0, c.signedIn ? 1 : 0];
|
|
1234
|
-
const better = (a, b) => {
|
|
1235
|
-
const [aa, ab] = rank(a);
|
|
1236
|
-
const [ba, bb] = rank(b);
|
|
1237
|
-
if (aa !== ba)
|
|
1238
|
-
return ba - aa;
|
|
1239
|
-
if (ab !== bb)
|
|
1240
|
-
return bb - ab;
|
|
1241
|
-
if (a.release !== b.release)
|
|
1242
|
-
return compareVersions(b.release, a.release);
|
|
1243
|
-
return compareVersions(b.version, a.version);
|
|
1244
|
-
};
|
|
1245
|
-
const out = [];
|
|
1246
|
-
for (const group of byAccount.values()) {
|
|
1247
|
-
if (group.length < 2)
|
|
1248
|
-
continue;
|
|
1249
|
-
const sorted = [...group].sort(better);
|
|
1250
|
-
const keeper = sorted[0].version;
|
|
1251
|
-
for (const dup of sorted.slice(1)) {
|
|
1252
|
-
out.push({ version: dup.version, email: dup.email, keeper });
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
return out;
|
|
1256
|
-
}
|
|
1257
936
|
async function buildAgentPrunePlan(agentId) {
|
|
1258
937
|
const dirInfos = listInstalledVersionDirs(agentId);
|
|
1259
938
|
const entries = await Promise.all(dirInfos.map(async ({ version, hasBinary }) => {
|
|
@@ -7,7 +7,7 @@ import { getConfigValue, setConfigValue } from '../lib/device-config.js';
|
|
|
7
7
|
import { writePolicySentinel, DEFAULT_THRESHOLDS, } from '../lib/watchdog/runner.js';
|
|
8
8
|
import { isWatchdogRotateEnabled, listRotateStates, setWatchdogRotateEnabled } from '../lib/watchdog/rotate.js';
|
|
9
9
|
import { loadWatchdogSessions, runWatchdogPass } from '../lib/watchdog/service.js';
|
|
10
|
-
import { readWatchdogEvents,
|
|
10
|
+
import { readWatchdogEvents, watchdogLogPath } from '../lib/watchdog/log.js';
|
|
11
11
|
import { selectWatchdogHistory } from '../lib/watchdog/history.js';
|
|
12
12
|
import { sessionHeadline } from '../lib/session/title.js';
|
|
13
13
|
function stateDir() {
|
|
@@ -332,11 +332,11 @@ export function registerWatchdogCommand(program) {
|
|
|
332
332
|
includeTicks: opts.all === true,
|
|
333
333
|
});
|
|
334
334
|
if (globals.json === true) {
|
|
335
|
-
console.log(JSON.stringify({ logPath:
|
|
335
|
+
console.log(JSON.stringify({ logPath: watchdogLogPath(), events: entries }, null, 2));
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
338
|
if (entries.length === 0) {
|
|
339
|
-
console.log(chalk.dim(`No Watchdog events found in ${
|
|
339
|
+
console.log(chalk.dim(`No Watchdog events found in ${watchdogLogPath()}`));
|
|
340
340
|
return;
|
|
341
341
|
}
|
|
342
342
|
for (const entry of entries) {
|
|
@@ -345,7 +345,7 @@ export function registerWatchdogCommand(program) {
|
|
|
345
345
|
const reason = entry.reason ? ` · ${entry.reason}` : '';
|
|
346
346
|
console.log(`${chalk.dim(when)} ${entry.kind.padEnd(8)} ${chalk.bold(session)} ${entry.agent ?? '-'} ${entry.message}${reason}`);
|
|
347
347
|
}
|
|
348
|
-
console.log(chalk.dim(`${entries.length} event${entries.length === 1 ? '' : 's'} · ${
|
|
348
|
+
console.log(chalk.dim(`${entries.length} event${entries.length === 1 ? '' : 's'} · ${watchdogLogPath()}`));
|
|
349
349
|
});
|
|
350
350
|
cmd.command('policy <sessionId> <policy>')
|
|
351
351
|
.description('Set per-session policy: off (ignore) | keep (default) | handsoff (detect + flag, never inject).')
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,10 @@ if (process.argv[2] === '__self-heal-run') {
|
|
|
46
46
|
const { runSelfHealChild } = await import('./lib/self-heal/child.js');
|
|
47
47
|
process.exit(await runSelfHealChild());
|
|
48
48
|
}
|
|
49
|
+
if (process.argv[2] === '__lead-host') {
|
|
50
|
+
const { runLeadHost } = await import('./lib/lead/client.js');
|
|
51
|
+
process.exit(await runLeadHost(process.argv[3] ?? ''));
|
|
52
|
+
}
|
|
49
53
|
if (process.argv[2] === '__daemon-run') {
|
|
50
54
|
const { runDaemon, log: daemonLog } = await import('./lib/daemon/daemon.js');
|
|
51
55
|
const crash = (kind) => (err) => {
|
|
@@ -337,7 +337,6 @@ export declare function parseClaudeModelRefusal(text: string): {
|
|
|
337
337
|
family: string;
|
|
338
338
|
} | null;
|
|
339
339
|
export declare function parseClaudeSessionLimitReset(text: string, nowMs?: number): Date | null;
|
|
340
|
-
export declare function isClaudeAuthValid(home?: string): Promise<boolean>;
|
|
341
340
|
export declare function renderBar(usedPercent: number, length: number): string;
|
|
342
341
|
export declare function getUsageColor(usedPercent: number): (text: string) => string;
|
|
343
342
|
declare function getGrokUsageInfo(options?: UsageOptions): Promise<UsageInfo>;
|
|
@@ -8,7 +8,7 @@ import { promisify } from 'util';
|
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import { decodeJwtPayload, decryptDroidAuthPayload } from '../agents.js';
|
|
10
10
|
import { walkForFiles } from '../fs-walk.js';
|
|
11
|
-
import {
|
|
11
|
+
import { getKeychainTokenSync } from '../secrets-client.js';
|
|
12
12
|
import { resolveClaudeSetupToken } from '../claude-account-token.js';
|
|
13
13
|
import { formatBackoffRemaining, noteUsageRateLimited, usageRateLimitedUntil, } from '../usage-backoff.js';
|
|
14
14
|
import { getCacheDir } from '../state.js';
|
|
@@ -18,8 +18,6 @@ import { withRefreshLease } from '../refresh-coordinator.js';
|
|
|
18
18
|
import { padToWidth } from '../session/width.js';
|
|
19
19
|
const execFileAsync = promisify(execFile);
|
|
20
20
|
const CLAUDE_USAGE_URL = 'https://api.anthropic.com/api/oauth/usage';
|
|
21
|
-
const CLAUDE_TOKEN_URL = 'https://platform.claude.com/v1/oauth/token';
|
|
22
|
-
const CLAUDE_CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e';
|
|
23
21
|
const CLAUDE_OAUTH_BETA_HEADER = 'oauth-2025-04-20';
|
|
24
22
|
const CLAUDE_REFRESH_LEEWAY_MS = 5 * 60 * 1000;
|
|
25
23
|
export function usageNoCredentialError(agent) {
|
|
@@ -126,13 +124,6 @@ export function claudeAccessTokenNeedsRefresh(expiresAt, nowMs = Date.now()) {
|
|
|
126
124
|
return false;
|
|
127
125
|
return nowMs + CLAUDE_REFRESH_LEEWAY_MS >= expiresAt;
|
|
128
126
|
}
|
|
129
|
-
const CLAUDE_SCOPES = [
|
|
130
|
-
'user:profile',
|
|
131
|
-
'user:inference',
|
|
132
|
-
'user:sessions:claude_code',
|
|
133
|
-
'user:mcp_servers',
|
|
134
|
-
'user:file_upload',
|
|
135
|
-
];
|
|
136
127
|
const CLAUDE_KEYCHAIN_SERVICE = 'Claude Code-credentials';
|
|
137
128
|
let claudeUsageCachePathOverride = null;
|
|
138
129
|
export function setClaudeUsageCachePathForTest(cachePath) {
|
|
@@ -1087,18 +1078,6 @@ function parseClaudeOauthPayload(raw) {
|
|
|
1087
1078
|
return null;
|
|
1088
1079
|
}
|
|
1089
1080
|
}
|
|
1090
|
-
const CLAUDE_OAUTH_CACHE_PREFIX = 'agents-cli.claude-oauth-cache.';
|
|
1091
|
-
function claudeOauthCacheItem(service) {
|
|
1092
|
-
const hash = createHash('sha256').update(service).digest('hex').slice(0, 16);
|
|
1093
|
-
return `${CLAUDE_OAUTH_CACHE_PREFIX}${hash}`;
|
|
1094
|
-
}
|
|
1095
|
-
function deleteCachedClaudeOauth(service) {
|
|
1096
|
-
try {
|
|
1097
|
-
deleteKeychainTokenSync(claudeOauthCacheItem(service));
|
|
1098
|
-
}
|
|
1099
|
-
catch {
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
1081
|
export function claudeHomeHasNativeOauthFile(home) {
|
|
1103
1082
|
return readClaudeNativeCredentialsFile(home) !== null;
|
|
1104
1083
|
}
|
|
@@ -1149,43 +1128,6 @@ export async function loadClaudeOauth(home, opts) {
|
|
|
1149
1128
|
}
|
|
1150
1129
|
return null;
|
|
1151
1130
|
}
|
|
1152
|
-
async function saveClaudeOauth(home, credentials) {
|
|
1153
|
-
if (process.platform !== 'darwin' && process.platform !== 'linux') {
|
|
1154
|
-
return false;
|
|
1155
|
-
}
|
|
1156
|
-
try {
|
|
1157
|
-
const service = getClaudeKeychainService(home);
|
|
1158
|
-
let existingPayload = {};
|
|
1159
|
-
try {
|
|
1160
|
-
const stdout = getKeychainTokenSync(service);
|
|
1161
|
-
existingPayload = JSON.parse(stdout.trim());
|
|
1162
|
-
}
|
|
1163
|
-
catch {
|
|
1164
|
-
}
|
|
1165
|
-
const newPayload = {
|
|
1166
|
-
...existingPayload,
|
|
1167
|
-
claudeAiOauth: {
|
|
1168
|
-
...existingPayload.claudeAiOauth,
|
|
1169
|
-
accessToken: credentials.accessToken,
|
|
1170
|
-
refreshToken: credentials.refreshToken,
|
|
1171
|
-
expiresAt: credentials.expiresAt,
|
|
1172
|
-
scopes: credentials.scopes ?? existingPayload.claudeAiOauth?.scopes,
|
|
1173
|
-
},
|
|
1174
|
-
};
|
|
1175
|
-
const payloadJson = JSON.stringify(newPayload);
|
|
1176
|
-
try {
|
|
1177
|
-
await deleteKeychainToken(service);
|
|
1178
|
-
}
|
|
1179
|
-
catch {
|
|
1180
|
-
}
|
|
1181
|
-
await setKeychainToken(service, payloadJson);
|
|
1182
|
-
deleteCachedClaudeOauth(service);
|
|
1183
|
-
return true;
|
|
1184
|
-
}
|
|
1185
|
-
catch {
|
|
1186
|
-
return false;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
1131
|
export function getClaudeKeychainService(home) {
|
|
1190
1132
|
if (!home) {
|
|
1191
1133
|
return CLAUDE_KEYCHAIN_SERVICE;
|
|
@@ -1630,59 +1572,6 @@ function isCachedUsageWindowFresh(window, capturedAt, now) {
|
|
|
1630
1572
|
}
|
|
1631
1573
|
return true;
|
|
1632
1574
|
}
|
|
1633
|
-
async function getClaudeAccessToken(oauth, home) {
|
|
1634
|
-
const accessToken = oauth.accessToken?.trim();
|
|
1635
|
-
if (!accessToken) {
|
|
1636
|
-
return null;
|
|
1637
|
-
}
|
|
1638
|
-
if (!claudeAccessTokenNeedsRefresh(oauth.expiresAt ?? null)) {
|
|
1639
|
-
return accessToken;
|
|
1640
|
-
}
|
|
1641
|
-
if (!oauth.refreshToken) {
|
|
1642
|
-
return null;
|
|
1643
|
-
}
|
|
1644
|
-
const refreshed = await refreshClaudeToken(oauth);
|
|
1645
|
-
if (!refreshed?.accessToken) {
|
|
1646
|
-
return null;
|
|
1647
|
-
}
|
|
1648
|
-
await saveClaudeOauth(home, refreshed);
|
|
1649
|
-
return refreshed.accessToken.trim();
|
|
1650
|
-
}
|
|
1651
|
-
async function refreshClaudeToken(oauth) {
|
|
1652
|
-
const response = await fetch(CLAUDE_TOKEN_URL, {
|
|
1653
|
-
method: 'POST',
|
|
1654
|
-
headers: {
|
|
1655
|
-
'Content-Type': 'application/json',
|
|
1656
|
-
},
|
|
1657
|
-
body: JSON.stringify({
|
|
1658
|
-
grant_type: 'refresh_token',
|
|
1659
|
-
refresh_token: oauth.refreshToken,
|
|
1660
|
-
client_id: CLAUDE_CLIENT_ID,
|
|
1661
|
-
scope: (oauth.scopes?.length ? oauth.scopes : CLAUDE_SCOPES).join(' '),
|
|
1662
|
-
}),
|
|
1663
|
-
signal: AbortSignal.timeout(15000),
|
|
1664
|
-
});
|
|
1665
|
-
if (!response.ok) {
|
|
1666
|
-
return null;
|
|
1667
|
-
}
|
|
1668
|
-
const data = await response.json();
|
|
1669
|
-
if (!data.access_token || !data.expires_in) {
|
|
1670
|
-
return null;
|
|
1671
|
-
}
|
|
1672
|
-
return {
|
|
1673
|
-
accessToken: data.access_token,
|
|
1674
|
-
refreshToken: data.refresh_token || oauth.refreshToken || null,
|
|
1675
|
-
expiresAt: Date.now() + data.expires_in * 1000,
|
|
1676
|
-
scopes: data.scope ? data.scope.split(/\s+/).filter(Boolean) : (oauth.scopes || CLAUDE_SCOPES),
|
|
1677
|
-
};
|
|
1678
|
-
}
|
|
1679
|
-
export async function isClaudeAuthValid(home) {
|
|
1680
|
-
const oauth = await loadClaudeOauth(home);
|
|
1681
|
-
if (!oauth)
|
|
1682
|
-
return false;
|
|
1683
|
-
const token = await getClaudeAccessToken(oauth, home);
|
|
1684
|
-
return token !== null;
|
|
1685
|
-
}
|
|
1686
1575
|
function getClaudeUserAgent(cliVersion) {
|
|
1687
1576
|
return cliVersion ? `claude-code/${cliVersion}` : 'claude-code';
|
|
1688
1577
|
}
|
package/dist/lib/accounts/add.js
CHANGED
|
@@ -505,7 +505,7 @@ async function defaultAddRunners() {
|
|
|
505
505
|
return await password({ message: `Enter the ${env} API key (stored as this account's worker credential):` });
|
|
506
506
|
}
|
|
507
507
|
catch (err) {
|
|
508
|
-
const { isPromptCancelled } = await import('
|
|
508
|
+
const { isPromptCancelled } = await import('../format.js');
|
|
509
509
|
if (isPromptCancelled(err))
|
|
510
510
|
return null;
|
|
511
511
|
throw err;
|
|
@@ -137,7 +137,7 @@ async function duplicateTrashLabels(items) {
|
|
|
137
137
|
const slotish = items.filter((i) => i.hasCredential && i.identityKey && !i.isolated);
|
|
138
138
|
if (slotish.length < 2)
|
|
139
139
|
return new Set();
|
|
140
|
-
const { planDuplicatePrune } = await import('
|
|
140
|
+
const { planDuplicatePrune } = await import('../installations/duplicate-prune.js');
|
|
141
141
|
const dups = planDuplicatePrune(slotish.map((i) => ({
|
|
142
142
|
version: i.label,
|
|
143
143
|
release: i.release,
|
|
@@ -2,7 +2,7 @@ import * as fs from 'fs';
|
|
|
2
2
|
import { simpleGit } from 'simple-git';
|
|
3
3
|
import { tryAutoPullSystemRepo, isGitRepo } from './git.js';
|
|
4
4
|
import { getSystemAgentsDir, getUserAgentsDir, getEnabledExtraRepos, getFetchCacheDir, } from './state.js';
|
|
5
|
-
import { lockFilePath, statusFilePath, markDetachedSyncComplete, SYNC_LOCK_TTL_MS, } from './auto-pull.js';
|
|
5
|
+
import { lockFilePath, statusFilePath, markDetachedSyncComplete, tryAcquireSyncLock, SYNC_LOCK_TTL_MS, } from './auto-pull.js';
|
|
6
6
|
const ENABLE_AUTO_PULL = process.env.AGENTS_AUTO_PULL === '1';
|
|
7
7
|
function ensureFetchDir() {
|
|
8
8
|
const dir = getFetchCacheDir();
|
|
@@ -16,21 +16,7 @@ function ensureFetchDir() {
|
|
|
16
16
|
}
|
|
17
17
|
function tryAcquireLock(alias) {
|
|
18
18
|
ensureFetchDir();
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const stat = fs.statSync(lock);
|
|
22
|
-
if (Date.now() - stat.mtimeMs < SYNC_LOCK_TTL_MS)
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
fs.writeFileSync(lock, String(process.pid));
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
19
|
+
return tryAcquireSyncLock(alias);
|
|
34
20
|
}
|
|
35
21
|
function touchLock(alias) {
|
|
36
22
|
const now = new Date();
|
package/dist/lib/auto-pull.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const SYNC_LOCK_TTL_MS: number;
|
|
2
2
|
export declare function lockFilePath(alias: string, fetchDir?: string): string;
|
|
3
|
+
export declare function tryAcquireSyncLock(alias: string, fetchDir?: string): boolean;
|
|
3
4
|
export declare function statusFilePath(alias: string, fetchDir?: string): string;
|
|
4
5
|
export declare function lastSyncStampPath(fetchDir?: string): string;
|
|
5
6
|
export interface FetchStatusMarker {
|