@phnx-labs/agents-cli 1.23.46 → 1.23.47
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
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.47
|
|
4
|
+
|
|
5
|
+
- **`agents accounts usage` no longer recommends a seat count from a few accounts.** With fewer than
|
|
6
|
+
75% of active accounts measured it reports `confidence: none` and names the accounts with no reading,
|
|
7
|
+
where it used to sum the one measured account and say "keep 1 of 8". Readings already in a box's
|
|
8
|
+
usage cache, local or synced from a peer, now count as history, so the table fills without waiting
|
|
9
|
+
for new status-line samples. Source: `cli/src/lib/accounting/advise.ts`, `usage-history.ts`, `usage-sync.ts`.
|
|
10
|
+
|
|
3
11
|
## 1.23.46
|
|
4
12
|
|
|
5
13
|
- **`agents accounts usage [harness]` shows how many subscription accounts you actually need.**
|
|
@@ -45,11 +45,13 @@ export interface AdviseOptions {
|
|
|
45
45
|
}
|
|
46
46
|
export declare const DEFAULT_ADVISE_WEEKS = 4;
|
|
47
47
|
export declare const DEFAULT_ADVISE_TARGET = 0.8;
|
|
48
|
+
export declare const MIN_ADVISE_COVERAGE = 0.75;
|
|
48
49
|
export declare function weekStartUtc(ms: number): number;
|
|
49
50
|
export declare function adviseAccounts(accounts: readonly AdviseAccountInput[], peaks: readonly UsagePeak[], options?: AdviseOptions): AccountsAdvice;
|
|
50
51
|
export interface CollectAdviceOptions extends AdviseOptions {
|
|
51
52
|
userAgentsDir?: string;
|
|
52
53
|
historyPath?: string;
|
|
54
|
+
cachePath?: string;
|
|
53
55
|
}
|
|
54
56
|
export declare function collectAccountsAdvice(agent: AgentId, options?: CollectAdviceOptions): AccountsAdvice & {
|
|
55
57
|
harness: AgentId;
|
|
@@ -2,9 +2,11 @@ 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;
|
|
8
10
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
9
11
|
const WEEK_MS = 7 * DAY_MS;
|
|
10
12
|
export function weekStartUtc(ms) {
|
|
@@ -86,13 +88,16 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
86
88
|
const measured = active.filter(hasReading).length;
|
|
87
89
|
const coverage = { measured, total: active.length };
|
|
88
90
|
const weeksLabel = weekStarts.map((w) => new Date(w).toISOString().slice(0, 10));
|
|
89
|
-
|
|
91
|
+
const minMeasured = Math.ceil(active.length * MIN_ADVISE_COVERAGE);
|
|
92
|
+
if (peakDemand === null || measured < minMeasured) {
|
|
93
|
+
const unmeasured = active.filter((r) => !hasReading(r)).map((r) => r.name);
|
|
94
|
+
const reason = peakDemand === null
|
|
95
|
+
? `No weekly usage recorded in the last ${weekCount} weeks yet; readings arrive as accounts run.`
|
|
96
|
+
: `Only ${measured} of ${active.length} active accounts have a weekly reading; a seat count needs ${minMeasured}. `
|
|
97
|
+
+ `No reading for ${unmeasured.join(', ')}.`;
|
|
90
98
|
return {
|
|
91
99
|
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
|
-
},
|
|
100
|
+
advice: { keep: active.length, pause: [], resume: [], add: 0, confidence: 'none', reason },
|
|
96
101
|
};
|
|
97
102
|
}
|
|
98
103
|
const limited = rows.some((r) => r.limitedWeeks > 0);
|
|
@@ -118,7 +123,9 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
118
123
|
.map((r) => r.name);
|
|
119
124
|
add = short - resume.length;
|
|
120
125
|
}
|
|
121
|
-
const
|
|
126
|
+
const weeksNeeded = Math.min(3, weekCount);
|
|
127
|
+
const thinHistory = active.filter((r) => r.peaks.filter((v) => v !== null).length < weeksNeeded).map((r) => r.name);
|
|
128
|
+
const confidence = thinHistory.length === 0 ? 'high' : 'low';
|
|
122
129
|
if (confidence === 'low') {
|
|
123
130
|
pause = [];
|
|
124
131
|
resume = [];
|
|
@@ -134,7 +141,7 @@ export function adviseAccounts(accounts, peaks, options = {}) {
|
|
|
134
141
|
if (unmeasured.length > 0)
|
|
135
142
|
parts.push(`No reading for ${unmeasured.join(', ')} (idle, or used only headless).`);
|
|
136
143
|
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 ${
|
|
144
|
+
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
145
|
}
|
|
139
146
|
return {
|
|
140
147
|
weeks: weeksLabel, rows, demand, currentDemand, peakDemand, target, coverage,
|
|
@@ -155,9 +162,12 @@ export function collectAccountsAdvice(agent, options = {}) {
|
|
|
155
162
|
}))
|
|
156
163
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
157
164
|
const local = readUsageHistory(options.historyPath ?? getUsageHistoryPath());
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
165
|
+
const cached = peaksFromCacheRows(exportClaudeUsageCacheRows(options.cachePath));
|
|
166
|
+
const peers = readFleetSharedDeviceStates(options.userAgentsDir).states.flatMap((s) => [
|
|
167
|
+
parseUsagePeaks(s.usageHistory?.peaks),
|
|
168
|
+
peaksFromCacheRows(s.usage?.rows ?? {}),
|
|
169
|
+
]);
|
|
170
|
+
return { harness: agent, ...adviseAccounts(accounts, mergeUsagePeaks(local, cached, ...peers), options) };
|
|
161
171
|
}
|
|
162
172
|
function pct(v) {
|
|
163
173
|
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.47",
|
|
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",
|