@phnx-labs/agents-cli 1.23.45 → 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 +55 -0
- package/README.md +28 -2
- package/dist/commands/accounts.js +58 -1
- package/dist/commands/exec.js +5 -2
- package/dist/commands/view.js +11 -6
- package/dist/lib/account-catalog.d.ts +2 -0
- package/dist/lib/account-catalog.js +5 -2
- package/dist/lib/account-registry.d.ts +2 -0
- package/dist/lib/account-registry.js +34 -0
- package/dist/lib/accounting/account-pool-collect.d.ts +2 -0
- package/dist/lib/accounting/account-pool-collect.js +10 -4
- package/dist/lib/accounting/account-pool.d.ts +1 -0
- package/dist/lib/accounting/account-pool.js +4 -1
- package/dist/lib/accounting/advise-notify.d.ts +7 -0
- package/dist/lib/accounting/advise-notify.js +37 -0
- package/dist/lib/accounting/advise.d.ts +69 -0
- package/dist/lib/accounting/advise.js +247 -0
- package/dist/lib/accounting/rotate.d.ts +1 -0
- package/dist/lib/accounting/rotate.js +8 -3
- package/dist/lib/accounting/usage-history.d.ts +29 -0
- package/dist/lib/accounting/usage-history.js +107 -0
- package/dist/lib/accounting/usage-sync.d.ts +6 -2
- package/dist/lib/accounting/usage-sync.js +19 -3
- package/dist/lib/accounting/usage.js +7 -0
- package/dist/lib/agent-spec/agents.d.ts +1 -0
- package/dist/lib/agent-spec/agents.js +10 -2
- package/dist/lib/claude-statusline.d.ts +16 -1
- package/dist/lib/claude-statusline.js +45 -7
- package/dist/lib/daemon/usage-sync-service.js +9 -0
- package/dist/lib/device-config.d.ts +1 -1
- package/dist/lib/device-config.js +2 -2
- package/dist/lib/fleet-shared-state.d.ts +5 -0
- package/dist/lib/fleet-shared-state.js +7 -0
- package/dist/lib/github/open-prs.js +2 -1
- package/dist/lib/github/project-prs.js +1 -11
- package/dist/lib/github/rest.d.ts +1 -0
- package/dist/lib/github/rest.js +1 -1
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/rush-api.js +1 -1
- package/dist/lib/session/glance-files.js +1 -1
- package/dist/lib/session/remote/watch.js +2 -2
- package/dist/lib/types.d.ts +1 -0
- package/package.json +2 -2
|
@@ -3,8 +3,9 @@ import * as os from 'os';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
5
|
import { accountDisplayLabel, readClaudeHomeConfig, } from './agent-spec/agents.js';
|
|
6
|
-
import { findNativeAccountByIdentity } from './account-registry.js';
|
|
6
|
+
import { findAccount, findNativeAccountByIdentity, listNativeAccounts, } from './account-registry.js';
|
|
7
7
|
import { atomicWriteFileSync } from './fs-atomic.js';
|
|
8
|
+
import { providerAccountUsageKey } from './accounting/account-pool.js';
|
|
8
9
|
import { mergeClaudeUsageCacheWindows } from './accounting/usage.js';
|
|
9
10
|
import { loadReminders, pickReminderForSession } from './reminders.js';
|
|
10
11
|
import { readMeta } from './state.js';
|
|
@@ -43,8 +44,44 @@ function windowFromNative(key, value) {
|
|
|
43
44
|
windowMinutes: key === 'session' ? 300 : 10_080,
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
|
-
export
|
|
47
|
-
|
|
47
|
+
export const RUN_ACCOUNT_ID_ENV = 'AGENTS_RUN_ACCOUNT_ID';
|
|
48
|
+
export function resolveStatusLineAccount(env, identity, lookups = {}) {
|
|
49
|
+
const runAccountId = env[RUN_ACCOUNT_ID_ENV]?.trim();
|
|
50
|
+
if (runAccountId) {
|
|
51
|
+
const native = (lookups.nativeAccountById ?? findNativeAccountById)(runAccountId);
|
|
52
|
+
if (!native) {
|
|
53
|
+
const provider = (lookups.providerAccount ?? findProviderAccount)(runAccountId);
|
|
54
|
+
if (provider) {
|
|
55
|
+
return {
|
|
56
|
+
usageKey: providerAccountUsageKey('claude', provider.name),
|
|
57
|
+
accountId: provider.id,
|
|
58
|
+
label: provider.name,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return { usageKey: null, accountId: null, label: 'unregistered account' };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const native = (lookups.nativeAccount ?? resolveNativeAccount)(identity);
|
|
65
|
+
return {
|
|
66
|
+
usageKey: identity?.usageKey ?? null,
|
|
67
|
+
accountId: native?.id ?? null,
|
|
68
|
+
label: formatAccountPart(identity, native),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function findNativeAccountById(id) {
|
|
72
|
+
return listNativeAccounts(readMeta()).find((account) => account.agent === 'claude' && account.id === id) ?? null;
|
|
73
|
+
}
|
|
74
|
+
function findProviderAccount(id) {
|
|
75
|
+
try {
|
|
76
|
+
const account = findAccount(id);
|
|
77
|
+
return account ? { id: account.id, name: account.name } : null;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function ingestClaudeStatusLineUsage(payload, account, versionHome) {
|
|
84
|
+
if (!account.usageKey || !payload.rate_limits)
|
|
48
85
|
return false;
|
|
49
86
|
const windows = [
|
|
50
87
|
windowFromNative('session', payload.rate_limits.five_hour),
|
|
@@ -52,7 +89,7 @@ export function ingestClaudeStatusLineUsage(payload, identity, versionHome) {
|
|
|
52
89
|
].filter((value) => value !== null);
|
|
53
90
|
if (windows.length === 0)
|
|
54
91
|
return false;
|
|
55
|
-
mergeClaudeUsageCacheWindows(
|
|
92
|
+
mergeClaudeUsageCacheWindows(account.usageKey, {
|
|
56
93
|
source: 'live',
|
|
57
94
|
sourceLabel: 'Claude response rate limits',
|
|
58
95
|
capturedAt: new Date(),
|
|
@@ -61,7 +98,7 @@ export function ingestClaudeStatusLineUsage(payload, identity, versionHome) {
|
|
|
61
98
|
});
|
|
62
99
|
recordRunAuthOutcome({
|
|
63
100
|
agent: 'claude',
|
|
64
|
-
accountId:
|
|
101
|
+
accountId: account.accountId,
|
|
65
102
|
home: versionHome ?? null,
|
|
66
103
|
outcome: { ok: true },
|
|
67
104
|
});
|
|
@@ -158,9 +195,10 @@ export async function runClaudeStatusLine() {
|
|
|
158
195
|
}
|
|
159
196
|
const versionHome = versionHomeFromEnv(process.env);
|
|
160
197
|
const identity = readClaudeIdentity(claudeHomeFromEnv(process.env));
|
|
198
|
+
const account = resolveStatusLineAccount(process.env, identity);
|
|
161
199
|
if (versionHome)
|
|
162
|
-
ingestClaudeStatusLineUsage(payload,
|
|
163
|
-
process.stdout.write(renderClaudeStatusLine(payload, undefined, versionHome ? renderDelegate(raw, versionHome) : '', resolveReminderPart(payload.session_id),
|
|
200
|
+
ingestClaudeStatusLineUsage(payload, account, versionHome);
|
|
201
|
+
process.stdout.write(renderClaudeStatusLine(payload, undefined, versionHome ? renderDelegate(raw, versionHome) : '', resolveReminderPart(payload.session_id), account.label));
|
|
164
202
|
return 0;
|
|
165
203
|
}
|
|
166
204
|
export function installClaudeStatusLine(versionHome) {
|
|
@@ -56,5 +56,14 @@ export class UsageSyncService extends BasePeriodicService {
|
|
|
56
56
|
ctx.log('INFO', `session-mirror: pruned ${foldedIn.pruned} stale mirror row(s)`);
|
|
57
57
|
for (const err of foldedIn.errors)
|
|
58
58
|
ctx.log('WARN', `session-mirror: ${err.device}: ${err.message}`);
|
|
59
|
+
try {
|
|
60
|
+
const { notifyChangedAccountsAdvice } = await import('../accounting/advise-notify.js');
|
|
61
|
+
for (const sent of await notifyChangedAccountsAdvice()) {
|
|
62
|
+
ctx.log('INFO', `accounts-advice: ${sent.title} (${sent.result})`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
ctx.log('WARN', `accounts-advice: ${err.message}`);
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
}
|
|
@@ -29,7 +29,7 @@ interface ConfigTarget {
|
|
|
29
29
|
}
|
|
30
30
|
declare const DEVICE_ROLES: readonly ["worker", "personal", "desktop"];
|
|
31
31
|
declare const AUTO_POOL_MODES: readonly ["workers", "all"];
|
|
32
|
-
export declare const MENUBAR_TABS: readonly ["home", "goals", "secrets", "linear", "github", "sessions", "inbox"];
|
|
32
|
+
export declare const MENUBAR_TABS: readonly ["home", "goals", "secrets", "linear", "github", "sessions", "inbox", "accounts"];
|
|
33
33
|
export declare const MENUBAR_RETIRED_TABS: readonly string[];
|
|
34
34
|
export declare const MENUBAR_HOME_GOALS: readonly ["company", "week", "myWeek", "myDay"];
|
|
35
35
|
export declare const MENUBAR_HOME_SECTIONS: readonly ["company", "cycle", "today", "needs", "prs", "issues", "sessions", "artifacts", "todos"];
|
|
@@ -14,10 +14,10 @@ const SSH_AUTH_METHODS = ['key', 'password'];
|
|
|
14
14
|
const DEVICE_ROLES = ['worker', 'personal', 'desktop'];
|
|
15
15
|
const AUTO_POOL_MODES = ['workers', 'all'];
|
|
16
16
|
const DEVICE_FORM_FACTORS = ['laptop', 'desktop', 'server', 'unknown'];
|
|
17
|
-
export const MENUBAR_TABS = ['home', 'goals', 'secrets', 'linear', 'github', 'sessions', 'inbox'];
|
|
17
|
+
export const MENUBAR_TABS = ['home', 'goals', 'secrets', 'linear', 'github', 'sessions', 'inbox', 'accounts'];
|
|
18
18
|
export const MENUBAR_RETIRED_TABS = ['projects'];
|
|
19
19
|
const MENUBAR_STORABLE_TABS = [...MENUBAR_TABS, ...MENUBAR_RETIRED_TABS];
|
|
20
|
-
const MENUBAR_TABS_ADDED_LATER = ['goals', 'secrets', 'linear', 'github'];
|
|
20
|
+
const MENUBAR_TABS_ADDED_LATER = ['goals', 'secrets', 'linear', 'github', 'accounts'];
|
|
21
21
|
export const MENUBAR_HOME_GOALS = ['company', 'week', 'myWeek', 'myDay'];
|
|
22
22
|
export const MENUBAR_HOME_SECTIONS = ['company', 'cycle', 'today', 'needs', 'prs', 'issues', 'sessions', 'artifacts', 'todos'];
|
|
23
23
|
export const MENUBAR_ARTIFACT_KINDS = ['image', 'html', 'markdown'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CachedUsageSnapshot } from './accounting/usage.js';
|
|
2
2
|
import type { NativeAccountRecord } from './types.js';
|
|
3
|
+
import type { UsagePeak } from './accounting/usage-history.js';
|
|
3
4
|
export declare const FLEET_SHARED_STATE_VERSION = 1;
|
|
4
5
|
export declare const FLEET_SHARED_STATE_FILE = "daemon-state.json";
|
|
5
6
|
export type SharedAuthStatus = 'ready' | 'missing' | 'invalid';
|
|
@@ -47,6 +48,9 @@ export interface FleetSharedDeviceState {
|
|
|
47
48
|
signedIn: boolean;
|
|
48
49
|
deviceToken: boolean;
|
|
49
50
|
};
|
|
51
|
+
usageHistory?: {
|
|
52
|
+
peaks: UsagePeak[];
|
|
53
|
+
};
|
|
50
54
|
receivedAt?: number;
|
|
51
55
|
}
|
|
52
56
|
interface FleetSharedStatePatch {
|
|
@@ -55,6 +59,7 @@ interface FleetSharedStatePatch {
|
|
|
55
59
|
sessions?: FleetSharedDeviceState['sessions'];
|
|
56
60
|
accounts?: FleetSharedDeviceState['accounts'];
|
|
57
61
|
ownerNotify?: FleetSharedDeviceState['ownerNotify'];
|
|
62
|
+
usageHistory?: FleetSharedDeviceState['usageHistory'];
|
|
58
63
|
receivedAt?: number;
|
|
59
64
|
}
|
|
60
65
|
interface FleetSharedStateReadResult {
|
|
@@ -44,6 +44,10 @@ export function parseFleetSharedDeviceStateEnvelope(parsed, owner) {
|
|
|
44
44
|
(!isRecord(ownerNotify) || typeof ownerNotify.signedIn !== 'boolean' || typeof ownerNotify.deviceToken !== 'boolean')) {
|
|
45
45
|
throw new Error('unrecognized owner-notify state');
|
|
46
46
|
}
|
|
47
|
+
const usageHistory = parsed.usageHistory;
|
|
48
|
+
if (usageHistory !== undefined && (!isRecord(usageHistory) || !Array.isArray(usageHistory.peaks))) {
|
|
49
|
+
throw new Error('unrecognized usage history');
|
|
50
|
+
}
|
|
47
51
|
if (parsed.receivedAt !== undefined && (typeof parsed.receivedAt !== 'number' || !Number.isFinite(parsed.receivedAt))) {
|
|
48
52
|
throw new Error('unrecognized receivedAt');
|
|
49
53
|
}
|
|
@@ -69,6 +73,7 @@ function mergeFleetState(currentRaw, device, patch) {
|
|
|
69
73
|
...(patch.sessions !== undefined ? { sessions: patch.sessions } : {}),
|
|
70
74
|
...(patch.accounts !== undefined ? { accounts: patch.accounts } : {}),
|
|
71
75
|
...(patch.ownerNotify !== undefined ? { ownerNotify: patch.ownerNotify } : {}),
|
|
76
|
+
...(patch.usageHistory !== undefined ? { usageHistory: patch.usageHistory } : {}),
|
|
72
77
|
...(patch.receivedAt !== undefined ? { receivedAt: patch.receivedAt } : {}),
|
|
73
78
|
version: FLEET_SHARED_STATE_VERSION,
|
|
74
79
|
device,
|
|
@@ -169,5 +174,7 @@ export async function storePeerFleetSharedDeviceState(state, userAgentsDir = get
|
|
|
169
174
|
patch.accounts = state.accounts;
|
|
170
175
|
if (state.ownerNotify !== undefined)
|
|
171
176
|
patch.ownerNotify = state.ownerNotify;
|
|
177
|
+
if (state.usageHistory !== undefined)
|
|
178
|
+
patch.usageHistory = state.usageHistory;
|
|
172
179
|
return updateFleetSharedDeviceStateAsync(state.device, patch, userAgentsDir);
|
|
173
180
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ghExec, canonicalizeRepo, projectRepoSlugs } from './pr-mergeable.js';
|
|
2
2
|
import { CiErrors, PR_NODE_FIELDS, enrichPr, fetchOnePr, fetchViewer, ghFailure, prFromNode, readRepoMergeAbility, } from './project-prs.js';
|
|
3
|
+
import { parseNdjson } from './rest.js';
|
|
3
4
|
const NEEDS_ME_RANK = { review: 0, failing: 1, conflicts: 2 };
|
|
4
5
|
export const SEARCH_RESULT_CAP = 1000;
|
|
5
6
|
const SEARCH_QUERY = `query($q: String!, $endCursor: String) {
|
|
@@ -14,7 +15,7 @@ async function searchOpenPrs(qualifier, gh) {
|
|
|
14
15
|
'-f', `q=is:pr is:open archived:false sort:updated-desc ${qualifier}`, '-f', `query=${SEARCH_QUERY}`,
|
|
15
16
|
'--jq', '.data.search.nodes[] | select(.number)',
|
|
16
17
|
]);
|
|
17
|
-
return out
|
|
18
|
+
return parseNdjson(out).map(prFromNode);
|
|
18
19
|
}
|
|
19
20
|
export async function listViewerOwners(viewer, gh = ghExec) {
|
|
20
21
|
const orgs = (await gh(['api', 'user/orgs', '--paginate', '--cache', '1h', '--jq', '.[].login']))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { ghExec, canonicalizeRepo, projectRepoSlugs } from './pr-mergeable.js';
|
|
4
|
-
import { isRateLimitError, rollupForSha } from './rest.js';
|
|
4
|
+
import { isRateLimitError, parseNdjson, rollupForSha } from './rest.js';
|
|
5
5
|
import { cachedViewer, fetchViewerProfile } from './viewer.js';
|
|
6
6
|
import { repoPathClaims } from '../projects.js';
|
|
7
7
|
import { getCacheDir } from '../state.js';
|
|
@@ -14,16 +14,6 @@ const PR_JQ = '{number, title, url: .html_url, isDraft: (.draft // false), ' +
|
|
|
14
14
|
'headSha: (.head.sha // ""), body: (.body // ""), ' +
|
|
15
15
|
'mergeable: .mergeable, mergeableState: .mergeable_state, ' +
|
|
16
16
|
'autoMerge: (if .auto_merge then {enabledBy: (.auto_merge.enabled_by.login // ""), method: (.auto_merge.merge_method // "")} else null end)}';
|
|
17
|
-
function parseNdjson(out) {
|
|
18
|
-
const rows = [];
|
|
19
|
-
for (const line of out.split('\n')) {
|
|
20
|
-
const t = line.trim();
|
|
21
|
-
if (!t)
|
|
22
|
-
continue;
|
|
23
|
-
rows.push(JSON.parse(t));
|
|
24
|
-
}
|
|
25
|
-
return rows;
|
|
26
|
-
}
|
|
27
17
|
export function rowToProjectPr(row) {
|
|
28
18
|
return {
|
|
29
19
|
number: Number(row.number),
|
|
@@ -8,6 +8,7 @@ interface PrHead {
|
|
|
8
8
|
number: number;
|
|
9
9
|
sha: string;
|
|
10
10
|
}
|
|
11
|
+
export declare function parseNdjson(out: string): Array<Record<string, unknown>>;
|
|
11
12
|
export declare function prHead(repo: string, number: number, gh?: GhExec): Promise<PrHead>;
|
|
12
13
|
export declare function rollupForSha(repo: string, sha: string, gh?: GhExec): Promise<RollupItem[]>;
|
|
13
14
|
export declare function pendingCheckSuites(repo: string, sha: string, gh?: GhExec): Promise<number>;
|
package/dist/lib/github/rest.js
CHANGED
package/dist/lib/rush-api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const RUSH_API_BASE = process.env.RUSH_PROXY_BASE ?? 'https://api.
|
|
1
|
+
export const RUSH_API_BASE = process.env.RUSH_PROXY_BASE ?? 'https://api.phoenix.so';
|
|
@@ -264,7 +264,7 @@ export function materializeInlineImages(events, sessionId, root = path.join(getU
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
export function enrichGlanceFiles(rows, nowMs = Date.now()) {
|
|
267
|
-
const artifacts = indexArtifactSidecars(
|
|
267
|
+
const artifacts = indexArtifactSidecars(undefined, nowMs);
|
|
268
268
|
for (const row of rows) {
|
|
269
269
|
if (!row.sessionId)
|
|
270
270
|
continue;
|
|
@@ -14,7 +14,7 @@ import { artifactKind, deriveImportantMessage, deriveSessionRecap, isReapableOrp
|
|
|
14
14
|
import { loadSessionPreviewDigest, readCachedPreviewDigest } from '../preview-digest.js';
|
|
15
15
|
import { indexArtifactSidecars, mergeArtifacts } from '@phnx-labs/sessions-cli/reader';
|
|
16
16
|
import { listNativeAccounts } from '../../account-registry.js';
|
|
17
|
-
import {
|
|
17
|
+
import { readMeta } from '../../state.js';
|
|
18
18
|
import { querySessions, readSessionSummaryAny, readSessionTimelineAny } from '../db.js';
|
|
19
19
|
import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
|
|
20
20
|
import { sessionAgentSupportsResume } from '../recovery.js';
|
|
@@ -81,7 +81,7 @@ function previousRowCard(session, request, attachments) {
|
|
|
81
81
|
attachments,
|
|
82
82
|
request,
|
|
83
83
|
});
|
|
84
|
-
const sidecars = indexArtifactSidecars(
|
|
84
|
+
const sidecars = indexArtifactSidecars().get(session.id) ?? [];
|
|
85
85
|
const artifacts = mergeArtifacts(digest?.producedArtifacts ?? [], sidecars).map((artifact) => ({ ...artifact, kind: artifactKind(artifact.path) }));
|
|
86
86
|
const todos = digest?.todos ?? session.todos;
|
|
87
87
|
const importantMessage = deriveImportantMessage({ status: 'closed', lastAgentLine: recap.lastAgentLine });
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface NativeAccountRecord {
|
|
|
30
30
|
workerCredential?: NativeAccountWorkerCredential;
|
|
31
31
|
provisioning?: AccountProvisioning;
|
|
32
32
|
createdOn?: string;
|
|
33
|
+
pausedAt?: string;
|
|
33
34
|
}
|
|
34
35
|
export type RunStrategy = 'pinned' | 'available' | 'balanced';
|
|
35
36
|
export type RunEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'auto';
|
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",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@fontsource/jetbrains-mono": "^5.3.0",
|
|
90
90
|
"@inquirer/prompts": "8.5.2",
|
|
91
91
|
"@phnx-labs/secrets-cli": "0.4.0",
|
|
92
|
-
"@phnx-labs/sessions-cli": "0.8.
|
|
92
|
+
"@phnx-labs/sessions-cli": "0.8.11",
|
|
93
93
|
"@resvg/resvg-wasm": "^2.6.2",
|
|
94
94
|
"@types/proper-lockfile": "4.1.4",
|
|
95
95
|
"@zed-industries/agent-client-protocol": "0.4.5",
|