@phnx-labs/agents-cli 1.23.46 → 1.23.48
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 +14 -0
- package/dist/lib/accounting/advise.d.ts +10 -0
- package/dist/lib/accounting/advise.js +26 -14
- package/dist/lib/accounting/usage-history.d.ts +5 -0
- package/dist/lib/accounting/usage-history.js +10 -0
- package/dist/lib/accounting/usage-sync.js +3 -2
- package/dist/lib/helper-versions.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.48
|
|
4
|
+
|
|
5
|
+
- **`agents accounts usage --json` reports the rules it applied.** A new `thresholds` object carries the target share, the coverage needed before a seat count (`minCoverage`, `minMeasured`), the weeks each account needs before accounts are named (`weeksNeeded`) and the limit percent, so the AGI Menu Accounts tab can show why it recommends what it does. Source: `cli/src/lib/accounting/advise.ts`.
|
|
6
|
+
|
|
7
|
+
- **AGI Menu 1.21.0: the Accounts tab draws its answer.** The `menubar` helper floor rises to 1.21.0. The tab shows a verdict card with a confidence chip, weekly demand against the seats you would keep, a heat strip of weekly peaks per account, and the rules behind the advice with your numbers. You can filter by harness, 4/8/12 weeks and a 70/80/90% target, and Pause/Resume now works, with an inline confirm. Source: `cli/src/lib/helper-versions.ts`.
|
|
8
|
+
|
|
9
|
+
## 1.23.47
|
|
10
|
+
|
|
11
|
+
- **`agents accounts usage` no longer recommends a seat count from a few accounts.** With fewer than
|
|
12
|
+
75% of active accounts measured it reports `confidence: none` and names the accounts with no reading,
|
|
13
|
+
where it used to sum the one measured account and say "keep 1 of 8". Readings already in a box's
|
|
14
|
+
usage cache, local or synced from a peer, now count as history, so the table fills without waiting
|
|
15
|
+
for new status-line samples. Source: `cli/src/lib/accounting/advise.ts`, `usage-history.ts`, `usage-sync.ts`.
|
|
16
|
+
|
|
3
17
|
## 1.23.46
|
|
4
18
|
|
|
5
19
|
- **`agents accounts usage [harness]` shows how many subscription accounts you actually need.**
|
|
@@ -29,6 +29,13 @@ export interface AccountsAdvice {
|
|
|
29
29
|
measured: number;
|
|
30
30
|
total: number;
|
|
31
31
|
};
|
|
32
|
+
thresholds: {
|
|
33
|
+
target: number;
|
|
34
|
+
minCoverage: number;
|
|
35
|
+
minMeasured: number;
|
|
36
|
+
weeksNeeded: number;
|
|
37
|
+
limitPercent: number;
|
|
38
|
+
};
|
|
32
39
|
advice: {
|
|
33
40
|
keep: number;
|
|
34
41
|
pause: string[];
|
|
@@ -45,11 +52,14 @@ export interface AdviseOptions {
|
|
|
45
52
|
}
|
|
46
53
|
export declare const DEFAULT_ADVISE_WEEKS = 4;
|
|
47
54
|
export declare const DEFAULT_ADVISE_TARGET = 0.8;
|
|
55
|
+
export declare const MIN_ADVISE_COVERAGE = 0.75;
|
|
56
|
+
export declare const LIMIT_PERCENT = 100;
|
|
48
57
|
export declare function weekStartUtc(ms: number): number;
|
|
49
58
|
export declare function adviseAccounts(accounts: readonly AdviseAccountInput[], peaks: readonly UsagePeak[], options?: AdviseOptions): AccountsAdvice;
|
|
50
59
|
export interface CollectAdviceOptions extends AdviseOptions {
|
|
51
60
|
userAgentsDir?: string;
|
|
52
61
|
historyPath?: string;
|
|
62
|
+
cachePath?: string;
|
|
53
63
|
}
|
|
54
64
|
export declare function collectAccountsAdvice(agent: AgentId, options?: CollectAdviceOptions): AccountsAdvice & {
|
|
55
65
|
harness: AgentId;
|
|
@@ -2,9 +2,12 @@ import { listNativeAccounts } from '../account-registry.js';
|
|
|
2
2
|
import { usageKeyForNativeIdentity } from '../agents.js';
|
|
3
3
|
import { readFleetSharedDeviceStates } from '../fleet-shared-state.js';
|
|
4
4
|
import { readMeta } from '../state.js';
|
|
5
|
-
import {
|
|
5
|
+
import { exportClaudeUsageCacheRows } from './usage.js';
|
|
6
|
+
import { getUsageHistoryPath, mergeUsagePeaks, parseUsagePeaks, peaksFromCacheRows, readUsageHistory, } from './usage-history.js';
|
|
6
7
|
export const DEFAULT_ADVISE_WEEKS = 4;
|
|
7
8
|
export const DEFAULT_ADVISE_TARGET = 0.8;
|
|
9
|
+
export const MIN_ADVISE_COVERAGE = 0.75;
|
|
10
|
+
export const LIMIT_PERCENT = 100;
|
|
8
11
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
9
12
|
const WEEK_MS = 7 * DAY_MS;
|
|
10
13
|
export function weekStartUtc(ms) {
|
|
@@ -39,7 +42,7 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
39
42
|
let pace = null;
|
|
40
43
|
let limitedWeeks = 0;
|
|
41
44
|
for (const p of byKey.get(account.usageKey) ?? []) {
|
|
42
|
-
if (p.peak >=
|
|
45
|
+
if (p.peak >= LIMIT_PERCENT)
|
|
43
46
|
limitedWeeks += 1;
|
|
44
47
|
if (Date.parse(p.resetsAt) > now.getTime()) {
|
|
45
48
|
thisWeek = Math.max(thisWeek ?? 0, p.peak);
|
|
@@ -86,13 +89,18 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
86
89
|
const measured = active.filter(hasReading).length;
|
|
87
90
|
const coverage = { measured, total: active.length };
|
|
88
91
|
const weeksLabel = weekStarts.map((w) => new Date(w).toISOString().slice(0, 10));
|
|
89
|
-
|
|
92
|
+
const minMeasured = Math.ceil(active.length * MIN_ADVISE_COVERAGE);
|
|
93
|
+
const weeksNeeded = Math.min(3, weekCount);
|
|
94
|
+
const thresholds = { target, minCoverage: MIN_ADVISE_COVERAGE, minMeasured, weeksNeeded, limitPercent: LIMIT_PERCENT };
|
|
95
|
+
if (peakDemand === null || measured < minMeasured) {
|
|
96
|
+
const unmeasured = active.filter((r) => !hasReading(r)).map((r) => r.name);
|
|
97
|
+
const reason = peakDemand === null
|
|
98
|
+
? `No weekly usage recorded in the last ${weekCount} weeks yet; readings arrive as accounts run.`
|
|
99
|
+
: `Only ${measured} of ${active.length} active accounts have a weekly reading; a seat count needs ${minMeasured}. `
|
|
100
|
+
+ `No reading for ${unmeasured.join(', ')}.`;
|
|
90
101
|
return {
|
|
91
|
-
weeks: weeksLabel, rows, demand, currentDemand, peakDemand, target, coverage,
|
|
92
|
-
advice: {
|
|
93
|
-
keep: active.length, pause: [], resume: [], add: 0, confidence: 'none',
|
|
94
|
-
reason: `No weekly usage recorded in the last ${weekCount} weeks yet; readings arrive as accounts run.`,
|
|
95
|
-
},
|
|
102
|
+
weeks: weeksLabel, rows, demand, currentDemand, peakDemand, target, coverage, thresholds,
|
|
103
|
+
advice: { keep: active.length, pause: [], resume: [], add: 0, confidence: 'none', reason },
|
|
96
104
|
};
|
|
97
105
|
}
|
|
98
106
|
const limited = rows.some((r) => r.limitedWeeks > 0);
|
|
@@ -118,7 +126,8 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
118
126
|
.map((r) => r.name);
|
|
119
127
|
add = short - resume.length;
|
|
120
128
|
}
|
|
121
|
-
const
|
|
129
|
+
const thinHistory = active.filter((r) => r.peaks.filter((v) => v !== null).length < weeksNeeded).map((r) => r.name);
|
|
130
|
+
const confidence = thinHistory.length === 0 ? 'high' : 'low';
|
|
122
131
|
if (confidence === 'low') {
|
|
123
132
|
pause = [];
|
|
124
133
|
resume = [];
|
|
@@ -134,10 +143,10 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
134
143
|
if (unmeasured.length > 0)
|
|
135
144
|
parts.push(`No reading for ${unmeasured.join(', ')} (idle, or used only headless).`);
|
|
136
145
|
if (confidence === 'low' && need !== active.length) {
|
|
137
|
-
parts.push(`Accounts to ${need < active.length ? 'pause' : 'resume'} are named once every active account has readings in ${
|
|
146
|
+
parts.push(`Accounts to ${need < active.length ? 'pause' : 'resume'} are named once every active account has readings in ${weeksNeeded} of the last ${weekCount} weeks.`);
|
|
138
147
|
}
|
|
139
148
|
return {
|
|
140
|
-
weeks: weeksLabel, rows, demand, currentDemand, peakDemand, target, coverage,
|
|
149
|
+
weeks: weeksLabel, rows, demand, currentDemand, peakDemand, target, coverage, thresholds,
|
|
141
150
|
advice: { keep: need, pause, resume, add, confidence, reason: parts.join(' ') },
|
|
142
151
|
};
|
|
143
152
|
}
|
|
@@ -155,9 +164,12 @@ export function collectAccountsAdvice(agent, options = {}) {
|
|
|
155
164
|
}))
|
|
156
165
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
157
166
|
const local = readUsageHistory(options.historyPath ?? getUsageHistoryPath());
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
const cached = peaksFromCacheRows(exportClaudeUsageCacheRows(options.cachePath));
|
|
168
|
+
const peers = readFleetSharedDeviceStates(options.userAgentsDir).states.flatMap((s) => [
|
|
169
|
+
parseUsagePeaks(s.usageHistory?.peaks),
|
|
170
|
+
peaksFromCacheRows(s.usage?.rows ?? {}),
|
|
171
|
+
]);
|
|
172
|
+
return { harness: agent, ...adviseAccounts(accounts, mergeUsagePeaks(local, cached, ...peers), options) };
|
|
161
173
|
}
|
|
162
174
|
function pct(v) {
|
|
163
175
|
return v === null ? '—' : `${v}%`;
|
|
@@ -20,5 +20,10 @@ export declare function readUsageHistory(historyPath?: string): UsagePeak[];
|
|
|
20
20
|
export declare function mergeUsagePeaks(...sets: ReadonlyArray<readonly UsagePeak[]>): UsagePeak[];
|
|
21
21
|
export declare function pruneUsagePeaks(peaks: readonly UsagePeak[], now: Date, days?: number): UsagePeak[];
|
|
22
22
|
export declare function peaksFromWindows(usageKey: string, windows: readonly UsageWindowSample[], seenAt: Date): UsagePeak[];
|
|
23
|
+
export interface UsageCacheRowLike {
|
|
24
|
+
capturedAt: string | null;
|
|
25
|
+
windows: readonly UsageWindowSample[];
|
|
26
|
+
}
|
|
27
|
+
export declare function peaksFromCacheRows(rows: Readonly<Record<string, UsageCacheRowLike>>): UsagePeak[];
|
|
23
28
|
export declare function recordUsagePeaks(usageKey: string, windows: readonly UsageWindowSample[], seenAt?: Date, historyPath?: string): number;
|
|
24
29
|
export declare function usagePeaksForPublish(now?: Date, historyPath?: string): UsagePeak[];
|
|
@@ -80,6 +80,16 @@ export function peaksFromWindows(usageKey, windows, seenAt) {
|
|
|
80
80
|
}
|
|
81
81
|
return out;
|
|
82
82
|
}
|
|
83
|
+
export function peaksFromCacheRows(rows) {
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const [usageKey, row] of Object.entries(rows)) {
|
|
86
|
+
const seenAt = row.capturedAt ? new Date(row.capturedAt) : null;
|
|
87
|
+
if (!seenAt || !Number.isFinite(seenAt.getTime()))
|
|
88
|
+
continue;
|
|
89
|
+
out.push(...peaksFromWindows(usageKey, row.windows, seenAt));
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
83
93
|
export function recordUsagePeaks(usageKey, windows, seenAt = new Date(), historyPath = getUsageHistoryPath()) {
|
|
84
94
|
const incoming = peaksFromWindows(usageKey, windows, seenAt);
|
|
85
95
|
if (incoming.length === 0)
|
|
@@ -26,7 +26,7 @@ import { getUserAgentsDir } from '../state.js';
|
|
|
26
26
|
import { machineId, normalizeHost } from '../session/sync/config.js';
|
|
27
27
|
import { resolveDeviceProfile } from '../devices/resolve-profile.js';
|
|
28
28
|
import { exportClaudeUsageCacheRows, ingestPeerClaudeUsageRows, } from './usage.js';
|
|
29
|
-
import { getUsageHistoryPath, usageHistoryPathFor, usagePeaksForPublish } from './usage-history.js';
|
|
29
|
+
import { getUsageHistoryPath, mergeUsagePeaks, peaksFromCacheRows, pruneUsagePeaks, USAGE_HISTORY_PUBLISH_DAYS, usageHistoryPathFor, usagePeaksForPublish, } from './usage-history.js';
|
|
30
30
|
export const USAGE_SYNC_INTERVAL_MS = 15 * 60_000;
|
|
31
31
|
export const USAGE_PUBLISH_HEARTBEAT_MS = 10 * 60_000;
|
|
32
32
|
export const USAGE_EXCHANGE_PEER_TIMEOUT_MS = 20_000;
|
|
@@ -95,7 +95,8 @@ export async function publishUsageSnapshotToSharedStore(options = {}) {
|
|
|
95
95
|
async function publishOwnUsageHistory(options) {
|
|
96
96
|
try {
|
|
97
97
|
const historyPath = options.cachePath ? usageHistoryPathFor(options.cachePath) : getUsageHistoryPath();
|
|
98
|
-
const
|
|
98
|
+
const now = new Date();
|
|
99
|
+
const peaks = mergeUsagePeaks(usagePeaksForPublish(now, historyPath), pruneUsagePeaks(peaksFromCacheRows(exportClaudeUsageCacheRows(options.cachePath)), now, USAGE_HISTORY_PUBLISH_DAYS));
|
|
99
100
|
await updateFleetSharedDeviceStateAsync(options.device ?? machineId(), { usageHistory: { peaks } }, options.userAgentsDir ?? getUserAgentsDir());
|
|
100
101
|
return { count: peaks.length, error: null };
|
|
101
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phnx-labs/agents-cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.48",
|
|
4
4
|
"description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|