looply-cli 0.5.9 → 0.5.10

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.
Files changed (47) hide show
  1. package/dist/account-failover.d.ts +30 -0
  2. package/dist/account-failover.d.ts.map +1 -0
  3. package/dist/account-failover.js +32 -0
  4. package/dist/account-failover.js.map +1 -0
  5. package/dist/daemon-cmd.d.ts.map +1 -1
  6. package/dist/daemon-cmd.js +29 -1
  7. package/dist/daemon-cmd.js.map +1 -1
  8. package/dist/daemon.d.ts +10 -1
  9. package/dist/daemon.d.ts.map +1 -1
  10. package/dist/daemon.js +31 -5
  11. package/dist/daemon.js.map +1 -1
  12. package/dist/model-transport.d.ts +13 -0
  13. package/dist/model-transport.d.ts.map +1 -1
  14. package/dist/model-transport.js +70 -9
  15. package/dist/model-transport.js.map +1 -1
  16. package/dist/provider-accounts-cmd.d.ts +58 -0
  17. package/dist/provider-accounts-cmd.d.ts.map +1 -0
  18. package/dist/provider-accounts-cmd.js +247 -0
  19. package/dist/provider-accounts-cmd.js.map +1 -0
  20. package/dist/provider-accounts.d.ts +157 -0
  21. package/dist/provider-accounts.d.ts.map +1 -0
  22. package/dist/provider-accounts.js +423 -0
  23. package/dist/provider-accounts.js.map +1 -0
  24. package/dist/provider-cmd.d.ts +3 -0
  25. package/dist/provider-cmd.d.ts.map +1 -1
  26. package/dist/provider-cmd.js +25 -0
  27. package/dist/provider-cmd.js.map +1 -1
  28. package/dist/provider-limit.d.ts +6 -0
  29. package/dist/provider-limit.d.ts.map +1 -1
  30. package/dist/provider-limit.js +12 -0
  31. package/dist/provider-limit.js.map +1 -1
  32. package/dist/provider-state.d.ts +3 -0
  33. package/dist/provider-state.d.ts.map +1 -1
  34. package/dist/provider-state.js +4 -1
  35. package/dist/provider-state.js.map +1 -1
  36. package/dist/run-cmd.d.ts.map +1 -1
  37. package/dist/run-cmd.js +41 -5
  38. package/dist/run-cmd.js.map +1 -1
  39. package/dist/server-client.d.ts +19 -2
  40. package/dist/server-client.d.ts.map +1 -1
  41. package/dist/server-client.js +16 -1
  42. package/dist/server-client.js.map +1 -1
  43. package/dist/spend-ledger.d.ts +7 -0
  44. package/dist/spend-ledger.d.ts.map +1 -1
  45. package/dist/spend-ledger.js +1 -0
  46. package/dist/spend-ledger.js.map +1 -1
  47. package/package.json +2 -2
@@ -0,0 +1,157 @@
1
+ import { type AccountNotReadyReason, type AccountPlan, type AccountPolicy, type AccountProvider, type AccountReport, type AccountRole } from '@looply/core';
2
+ /**
3
+ * SEVERAL NAMED AI ACCOUNTS ON ONE MACHINE.
4
+ *
5
+ * Each account is a provider login in its OWN profile directory, made by the
6
+ * provider's own login flow (`looply provider login --name <n>`). Looply stores
7
+ * the directory's PATH, never what is in it — the rule `provider-state.ts`
8
+ * established for the single profile, kept for many.
9
+ *
10
+ * ~/.looply/provider-profile the account named `default` (the legacy profile)
11
+ * ~/.looply/provider-profiles/<name> every other account
12
+ * ~/.looply/provider-accounts.json which accounts exist (name, provider, label)
13
+ * ~/.looply/provider-accounts-state.json resting until, readiness, plan — shared by every daemon here
14
+ * ~/.looply/provider-accounts-remote.json what the accounts' owners set, as last pulled
15
+ *
16
+ * ⚠️ MACHINE STATE, NOT PROJECT STATE: resolved from the daemon's home, never
17
+ * from `.looply/config.yaml`, which sits in a worktree the model may edit.
18
+ *
19
+ * ⚠️ WHAT CROSSES TO THE SERVER: the name, a label, the provider kind, the
20
+ * auth method and plan name, readiness, resting until, token usage. Never an
21
+ * email, an organisation id or a credential.
22
+ */
23
+ export declare const ACCOUNTS_FILE = "provider-accounts.json";
24
+ export declare const ACCOUNTS_STATE_FILE = "provider-accounts-state.json";
25
+ export declare const ACCOUNTS_REMOTE_FILE = "provider-accounts-remote.json";
26
+ export declare const PROFILES_DIR = "provider-profiles";
27
+ export interface AccountEntry {
28
+ name: string;
29
+ provider: AccountProvider;
30
+ label: string;
31
+ /** The provider's profile directory: `CLAUDE_CONFIG_DIR` for claude, `CODEX_HOME` for codex. */
32
+ profileDir: string;
33
+ }
34
+ export interface AccountState {
35
+ restingUntil?: number;
36
+ restingBecause?: string;
37
+ ready?: boolean;
38
+ reason?: AccountNotReadyReason | null;
39
+ authMethod?: string | null;
40
+ plan?: AccountPlan | null;
41
+ checkedAt?: number;
42
+ }
43
+ /** Where an account's provider profile lives. `default` is the legacy single profile. */
44
+ export declare function accountProfileDir(name: string, home?: string): string;
45
+ /**
46
+ * Every account on this machine. The legacy profile is always the claude
47
+ * account `default`, so a machine nobody configured behaves exactly as before.
48
+ */
49
+ export declare function readAccounts(home?: string): AccountEntry[];
50
+ /** Add (or relabel) a named account. Its profile directory is made; nothing is put in it. */
51
+ export declare function addAccount(input: {
52
+ name: string;
53
+ provider: AccountProvider;
54
+ label?: string;
55
+ }, home?: string): AccountEntry;
56
+ /** Forget a named account. Its profile directory (and the login in it) is left where it is. */
57
+ export declare function removeAccount(name: string, home?: string): boolean;
58
+ export declare function readAccountStates(home?: string): Record<string, AccountState>;
59
+ /** The account answered with a usage limit: it rests until `until`. Read by every daemon here. */
60
+ export declare function markAccountResting(name: string, until: number, because: string, home?: string): void;
61
+ /** What a readiness check found, kept so a call need not ask every account every time. */
62
+ export declare function recordAccountReadiness(name: string, r: {
63
+ ready: boolean;
64
+ reason: AccountNotReadyReason | null;
65
+ authMethod?: string | null;
66
+ plan?: AccountPlan | null;
67
+ }, now: number, home?: string): void;
68
+ export interface RemoteAccountPolicies {
69
+ policies: AccountPolicy[];
70
+ updatedAt: string | null;
71
+ fetchedAt: string;
72
+ }
73
+ export declare function readAccountPolicies(home?: string): AccountPolicy[];
74
+ /** Pull this machine's account policies (`GET /v1/machine/accounts`) into the cache. */
75
+ export declare function makeAccountPoliciesPull(deps: {
76
+ fetch: () => Promise<unknown>;
77
+ log: (line: string) => void;
78
+ home?: string;
79
+ now?: () => number;
80
+ }): () => Promise<'updated' | 'unchanged' | 'failed'>;
81
+ /** Tokens (input + output) each account used in the last 24 hours and 7 days. */
82
+ export declare function accountUsage(home?: string, now?: number): Map<string, {
83
+ dayTokens: number;
84
+ weekTokens: number;
85
+ }>;
86
+ export interface AccountCallInput {
87
+ role: AccountRole;
88
+ projectId: string | null;
89
+ requesterRef: string | null;
90
+ provider?: AccountProvider;
91
+ now: number;
92
+ /** Accounts already found unusable during this call (e.g. not logged in). */
93
+ skip?: readonly string[];
94
+ }
95
+ export type AccountChoice = {
96
+ kind: 'account';
97
+ entry: AccountEntry;
98
+ resting: boolean;
99
+ } | {
100
+ kind: 'none';
101
+ because: string;
102
+ };
103
+ /**
104
+ * Which account one model call uses.
105
+ *
106
+ * - the first usable account by priority;
107
+ * - else, when the only thing in the way is that accounts are RESTING, the one
108
+ * that rests the shortest: its call meets the limit again and the run waits
109
+ * it out (`provider-limit.ts`), exactly as with one account;
110
+ * - else, when every account is simply not logged in, the first by priority, so
111
+ * the launch says "log in" in the words it always did;
112
+ * - else no account, with every reason: the owners' settings allow none for this work.
113
+ */
114
+ export declare function chooseAccountForCall(input: AccountCallInput, home?: string): AccountChoice;
115
+ /** Whether any account other than `except` could take a call of this kind right now. */
116
+ export declare function anotherAccountUsable(input: AccountCallInput & {
117
+ except: string;
118
+ }, home?: string): string | null;
119
+ /**
120
+ * Every account, as the heartbeat reports it. Readiness is what was last
121
+ * checked (`refreshAccountReadiness`); nothing here starts a process.
122
+ */
123
+ export declare function accountReports(home?: string, now?: number): AccountReport[];
124
+ export type AccountAuth = {
125
+ ok: true;
126
+ authMethod: string | null;
127
+ plan: AccountPlan | null;
128
+ } | {
129
+ ok: false;
130
+ reason: AccountNotReadyReason;
131
+ because: string;
132
+ };
133
+ export declare function planOf(x: unknown): AccountPlan | null;
134
+ export interface CodexDeps {
135
+ run?: (exe: string, argv: readonly string[], env: Record<string, string>) => {
136
+ status: number;
137
+ out: string;
138
+ };
139
+ executable?: string | null;
140
+ }
141
+ /** `codex` on PATH, or null. Codex is installed by its owner; Looply does not install it. */
142
+ export declare function codexExecutable(env?: NodeJS.ProcessEnv): string | null;
143
+ /**
144
+ * Is a codex account logged in? `codex login status` in its own `CODEX_HOME`
145
+ * answers with exit 0 when it is, and names "API key" or "ChatGPT".
146
+ *
147
+ * ⚠️ NEVER RUN END TO END ON THIS PROJECT'S MACHINES: the codex preset is
148
+ * declared but no Looply run has used it yet. Readiness is what this checks.
149
+ */
150
+ export declare function checkCodexAuth(profileDir: string, deps?: CodexDeps): AccountAuth;
151
+ /** Who asked for the work a run is bound to (`requestedBy.ref` on its goal), or null. */
152
+ export declare function requesterRefOf(goal: {
153
+ requestedBy?: {
154
+ ref?: unknown;
155
+ } | null;
156
+ } | undefined | null): string | null;
157
+ //# sourceMappingURL=provider-accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-accounts.d.ts","sourceRoot":"","sources":["../src/provider-accounts.ts"],"names":[],"mappings":"AAIA,OAAO,EASL,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,aAAa,2BAA2B,CAAC;AACtD,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAClE,eAAO,MAAM,oBAAoB,kCAAkC,CAAC;AACpE,eAAO,MAAM,YAAY,sBAAsB,CAAC;AAKhD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,eAAe,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,gGAAgG;IAChG,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,GAA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,EAAE;QAAE,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAGjH"}
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROFILES_DIR = exports.ACCOUNTS_REMOTE_FILE = exports.ACCOUNTS_STATE_FILE = exports.ACCOUNTS_FILE = void 0;
4
+ exports.accountProfileDir = accountProfileDir;
5
+ exports.readAccounts = readAccounts;
6
+ exports.addAccount = addAccount;
7
+ exports.removeAccount = removeAccount;
8
+ exports.readAccountStates = readAccountStates;
9
+ exports.markAccountResting = markAccountResting;
10
+ exports.recordAccountReadiness = recordAccountReadiness;
11
+ exports.readAccountPolicies = readAccountPolicies;
12
+ exports.makeAccountPoliciesPull = makeAccountPoliciesPull;
13
+ exports.accountUsage = accountUsage;
14
+ exports.chooseAccountForCall = chooseAccountForCall;
15
+ exports.anotherAccountUsable = anotherAccountUsable;
16
+ exports.accountReports = accountReports;
17
+ exports.planOf = planOf;
18
+ exports.codexExecutable = codexExecutable;
19
+ exports.checkCodexAuth = checkCodexAuth;
20
+ exports.requesterRefOf = requesterRefOf;
21
+ const node_child_process_1 = require("node:child_process");
22
+ const node_fs_1 = require("node:fs");
23
+ const node_os_1 = require("node:os");
24
+ const node_path_1 = require("node:path");
25
+ const core_1 = require("@looply/core");
26
+ const spend_ledger_1 = require("./spend-ledger");
27
+ const server_client_1 = require("./server-client");
28
+ /**
29
+ * SEVERAL NAMED AI ACCOUNTS ON ONE MACHINE.
30
+ *
31
+ * Each account is a provider login in its OWN profile directory, made by the
32
+ * provider's own login flow (`looply provider login --name <n>`). Looply stores
33
+ * the directory's PATH, never what is in it — the rule `provider-state.ts`
34
+ * established for the single profile, kept for many.
35
+ *
36
+ * ~/.looply/provider-profile the account named `default` (the legacy profile)
37
+ * ~/.looply/provider-profiles/<name> every other account
38
+ * ~/.looply/provider-accounts.json which accounts exist (name, provider, label)
39
+ * ~/.looply/provider-accounts-state.json resting until, readiness, plan — shared by every daemon here
40
+ * ~/.looply/provider-accounts-remote.json what the accounts' owners set, as last pulled
41
+ *
42
+ * ⚠️ MACHINE STATE, NOT PROJECT STATE: resolved from the daemon's home, never
43
+ * from `.looply/config.yaml`, which sits in a worktree the model may edit.
44
+ *
45
+ * ⚠️ WHAT CROSSES TO THE SERVER: the name, a label, the provider kind, the
46
+ * auth method and plan name, readiness, resting until, token usage. Never an
47
+ * email, an organisation id or a credential.
48
+ */
49
+ exports.ACCOUNTS_FILE = 'provider-accounts.json';
50
+ exports.ACCOUNTS_STATE_FILE = 'provider-accounts-state.json';
51
+ exports.ACCOUNTS_REMOTE_FILE = 'provider-accounts-remote.json';
52
+ exports.PROFILES_DIR = 'provider-profiles';
53
+ const DAY_MS = 24 * 60 * 60 * 1000;
54
+ const WEEK_MS = 7 * DAY_MS;
55
+ const looplyHome = (home) => (0, node_path_1.join)(home, '.looply');
56
+ /** Where an account's provider profile lives. `default` is the legacy single profile. */
57
+ function accountProfileDir(name, home = (0, node_os_1.homedir)()) {
58
+ return name === core_1.DEFAULT_ACCOUNT_NAME
59
+ ? (0, node_path_1.join)(looplyHome(home), 'provider-profile')
60
+ : (0, node_path_1.join)(looplyHome(home), exports.PROFILES_DIR, name);
61
+ }
62
+ /** Atomic: a reader never sees half a file, and many daemons may write the same file. */
63
+ function writeJson(file, value) {
64
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(file), { recursive: true });
65
+ const tmp = `${file}.${process.pid}.${Math.floor(Math.random() * 1e9).toString(36)}.tmp`;
66
+ (0, node_fs_1.writeFileSync)(tmp, JSON.stringify(value, null, 2) + '\n', 'utf8');
67
+ try {
68
+ (0, node_fs_1.renameSync)(tmp, file);
69
+ }
70
+ catch (e) {
71
+ try {
72
+ (0, node_fs_1.unlinkSync)(tmp);
73
+ }
74
+ catch {
75
+ /* already gone */
76
+ }
77
+ throw e;
78
+ }
79
+ }
80
+ function readJson(file) {
81
+ try {
82
+ return JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
83
+ }
84
+ catch {
85
+ return null;
86
+ }
87
+ }
88
+ function readStored(home) {
89
+ const raw = readJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_FILE));
90
+ if (raw === null || !Array.isArray(raw.accounts))
91
+ return [];
92
+ return raw.accounts.filter((a) => typeof a === 'object' &&
93
+ a !== null &&
94
+ (0, core_1.isAccountName)(a.name) &&
95
+ (a.provider === 'claude' || a.provider === 'codex'));
96
+ }
97
+ /**
98
+ * Every account on this machine. The legacy profile is always the claude
99
+ * account `default`, so a machine nobody configured behaves exactly as before.
100
+ */
101
+ function readAccounts(home = (0, node_os_1.homedir)()) {
102
+ const stored = readStored(home).filter((a) => a.name !== core_1.DEFAULT_ACCOUNT_NAME);
103
+ const defaultLabel = readStored(home).find((a) => a.name === core_1.DEFAULT_ACCOUNT_NAME)?.label;
104
+ return [
105
+ {
106
+ name: core_1.DEFAULT_ACCOUNT_NAME,
107
+ provider: 'claude',
108
+ label: defaultLabel ?? 'default',
109
+ profileDir: accountProfileDir(core_1.DEFAULT_ACCOUNT_NAME, home),
110
+ },
111
+ ...stored.map((a) => ({
112
+ name: a.name,
113
+ provider: a.provider,
114
+ label: typeof a.label === 'string' && a.label.trim() !== '' ? a.label.slice(0, 60) : a.name,
115
+ profileDir: accountProfileDir(a.name, home),
116
+ })),
117
+ ];
118
+ }
119
+ /** Add (or relabel) a named account. Its profile directory is made; nothing is put in it. */
120
+ function addAccount(input, home = (0, node_os_1.homedir)()) {
121
+ if (!(0, core_1.isAccountName)(input.name)) {
122
+ throw new Error(`"${input.name}" is not an account name: use 1-32 lowercase letters, digits and dashes, starting with a letter or digit`);
123
+ }
124
+ if (input.name === core_1.DEFAULT_ACCOUNT_NAME && input.provider !== 'claude') {
125
+ throw new Error('the account named "default" is the machine\'s Claude Code profile; pick another name for a codex account');
126
+ }
127
+ const stored = readStored(home).filter((a) => a.name !== input.name);
128
+ const before = readStored(home).find((a) => a.name === input.name);
129
+ if (before !== undefined && before.provider !== input.provider) {
130
+ throw new Error(`the account "${input.name}" is a ${before.provider} account; remove it first or pick another name`);
131
+ }
132
+ stored.push({
133
+ name: input.name,
134
+ provider: input.provider,
135
+ ...(input.label !== undefined ? { label: input.label.slice(0, 60) } : before?.label ? { label: before.label } : {}),
136
+ addedAt: before?.addedAt ?? new Date().toISOString(),
137
+ });
138
+ writeJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_FILE), { accounts: stored });
139
+ const dir = accountProfileDir(input.name, home);
140
+ (0, node_fs_1.mkdirSync)(dir, { recursive: true });
141
+ return readAccounts(home).find((a) => a.name === input.name);
142
+ }
143
+ /** Forget a named account. Its profile directory (and the login in it) is left where it is. */
144
+ function removeAccount(name, home = (0, node_os_1.homedir)()) {
145
+ if (name === core_1.DEFAULT_ACCOUNT_NAME)
146
+ throw new Error('the "default" account is the machine\'s own profile and cannot be removed');
147
+ const stored = readStored(home);
148
+ const kept = stored.filter((a) => a.name !== name);
149
+ if (kept.length === stored.length)
150
+ return false;
151
+ writeJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_FILE), { accounts: kept });
152
+ return true;
153
+ }
154
+ // ── state shared by every daemon on the machine ──
155
+ function readAccountStates(home = (0, node_os_1.homedir)()) {
156
+ const raw = readJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_STATE_FILE));
157
+ if (raw === null || typeof raw.accounts !== 'object' || raw.accounts === null)
158
+ return {};
159
+ return raw.accounts;
160
+ }
161
+ function updateState(home, name, patch) {
162
+ const all = readAccountStates(home);
163
+ all[name] = { ...(all[name] ?? {}), ...patch };
164
+ try {
165
+ writeJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_STATE_FILE), { accounts: all });
166
+ }
167
+ catch {
168
+ /* a state write that fails costs one retry later, never the call */
169
+ }
170
+ }
171
+ /** The account answered with a usage limit: it rests until `until`. Read by every daemon here. */
172
+ function markAccountResting(name, until, because, home = (0, node_os_1.homedir)()) {
173
+ updateState(home, name, { restingUntil: until, restingBecause: because.slice(0, 300) });
174
+ }
175
+ /** What a readiness check found, kept so a call need not ask every account every time. */
176
+ function recordAccountReadiness(name, r, now, home = (0, node_os_1.homedir)()) {
177
+ updateState(home, name, {
178
+ ready: r.ready,
179
+ reason: r.reason,
180
+ ...(r.authMethod !== undefined ? { authMethod: r.authMethod } : {}),
181
+ ...(r.plan !== undefined ? { plan: r.plan } : {}),
182
+ checkedAt: now,
183
+ });
184
+ }
185
+ function readAccountPolicies(home = (0, node_os_1.homedir)()) {
186
+ const raw = readJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_REMOTE_FILE));
187
+ if (raw === null || !Array.isArray(raw.policies))
188
+ return [];
189
+ return raw.policies.map(core_1.accountPolicyOf).filter((p) => p !== null);
190
+ }
191
+ /** Pull this machine's account policies (`GET /v1/machine/accounts`) into the cache. */
192
+ function makeAccountPoliciesPull(deps) {
193
+ const home = deps.home ?? (0, node_os_1.homedir)();
194
+ const now = deps.now ?? (() => Date.now());
195
+ let reported = false;
196
+ return async () => {
197
+ let body;
198
+ try {
199
+ body = await deps.fetch();
200
+ }
201
+ catch (e) {
202
+ // An older server (404), no network, or a revoked token: keep what was last pulled.
203
+ if (!(e instanceof server_client_1.ServerError && (e.isOffline || e.isAuth || e.status === 404)) && !reported) {
204
+ reported = true;
205
+ deps.log(`accounts: could not refresh the AI account settings — ${e.message}`);
206
+ }
207
+ return 'failed';
208
+ }
209
+ const b = body;
210
+ if (b === null || typeof b !== 'object' || !Array.isArray(b.policies))
211
+ return 'failed';
212
+ reported = false;
213
+ const policies = b.policies.map(core_1.accountPolicyOf).filter((p) => p !== null);
214
+ const before = readAccountPolicies(home);
215
+ if (JSON.stringify(before) === JSON.stringify(policies))
216
+ return 'unchanged';
217
+ writeJson((0, node_path_1.join)(looplyHome(home), exports.ACCOUNTS_REMOTE_FILE), {
218
+ policies,
219
+ updatedAt: typeof b.updatedAt === 'string' ? b.updatedAt : null,
220
+ fetchedAt: new Date(now()).toISOString(),
221
+ });
222
+ deps.log(`accounts: AI account settings updated (${policies.length} with settings)`);
223
+ return 'updated';
224
+ };
225
+ }
226
+ // ── usage, from the machine's spend ledger ──
227
+ /** Tokens (input + output) each account used in the last 24 hours and 7 days. */
228
+ function accountUsage(home = (0, node_os_1.homedir)(), now = Date.now()) {
229
+ const out = new Map();
230
+ const read = (0, spend_ledger_1.readSpend)(home);
231
+ if (!read.ok)
232
+ return out;
233
+ for (const r of read.records) {
234
+ const name = r.account;
235
+ if (typeof name !== 'string')
236
+ continue;
237
+ const at = Date.parse(r.at);
238
+ if (!Number.isFinite(at) || at > now || now - at > WEEK_MS)
239
+ continue;
240
+ const tokens = (r.inputTokens ?? 0) + (r.outputTokens ?? 0);
241
+ const u = out.get(name) ?? { dayTokens: 0, weekTokens: 0 };
242
+ u.weekTokens += tokens;
243
+ if (now - at <= DAY_MS)
244
+ u.dayTokens += tokens;
245
+ out.set(name, u);
246
+ }
247
+ return out;
248
+ }
249
+ // ── choosing ──
250
+ function candidatesFor(home, now, provider) {
251
+ const entries = readAccounts(home).filter((a) => a.provider === provider);
252
+ const states = readAccountStates(home);
253
+ const policies = new Map(readAccountPolicies(home).map((p) => [p.name, p]));
254
+ const needUsage = [...policies.values()].some((p) => p.dailyTokenCap !== null || p.weeklyTokenCap !== null);
255
+ const usage = needUsage ? accountUsage(home, now) : new Map();
256
+ const candidates = entries.map((e) => {
257
+ const s = states[e.name] ?? {};
258
+ return {
259
+ name: e.name,
260
+ provider: e.provider,
261
+ // Never checked yet: assumed ready; the launch checks it and records the answer.
262
+ ready: s.ready !== false,
263
+ personal: (0, core_1.isPersonalAccount)(s.authMethod ?? null, s.plan ?? null),
264
+ restingUntil: typeof s.restingUntil === 'number' ? s.restingUntil : null,
265
+ usage: usage.get(e.name) ?? { dayTokens: 0, weekTokens: 0 },
266
+ policy: policies.get(e.name) ?? null,
267
+ };
268
+ });
269
+ return { entries, candidates };
270
+ }
271
+ /**
272
+ * Which account one model call uses.
273
+ *
274
+ * - the first usable account by priority;
275
+ * - else, when the only thing in the way is that accounts are RESTING, the one
276
+ * that rests the shortest: its call meets the limit again and the run waits
277
+ * it out (`provider-limit.ts`), exactly as with one account;
278
+ * - else, when every account is simply not logged in, the first by priority, so
279
+ * the launch says "log in" in the words it always did;
280
+ * - else no account, with every reason: the owners' settings allow none for this work.
281
+ */
282
+ function chooseAccountForCall(input, home = (0, node_os_1.homedir)()) {
283
+ const provider = input.provider ?? 'claude';
284
+ const { entries, candidates } = candidatesFor(home, input.now, provider);
285
+ const skip = new Set(input.skip ?? []);
286
+ const live = candidates.filter((c) => !skip.has(c.name));
287
+ const ctx = { provider, role: input.role, projectId: input.projectId, requesterRef: input.requesterRef, now: input.now };
288
+ const { usable, refused } = (0, core_1.chooseAccounts)(live, ctx);
289
+ const entryOf = (name) => entries.find((e) => e.name === name);
290
+ if (usable.length > 0)
291
+ return { kind: 'account', entry: entryOf(usable[0]), resting: false };
292
+ // Would it be usable but for resting? Ask again as if every rest were over.
293
+ const awake = (0, core_1.chooseAccounts)(live.map((c) => ({ ...c, restingUntil: null })), ctx).usable;
294
+ if (awake.length > 0) {
295
+ const soonest = live
296
+ .filter((c) => awake.includes(c.name))
297
+ .sort((a, b) => (a.restingUntil ?? 0) - (b.restingUntil ?? 0))[0];
298
+ return { kind: 'account', entry: entryOf(soonest.name), resting: true };
299
+ }
300
+ const asIfReady = (0, core_1.chooseAccounts)(live.map((c) => ({ ...c, ready: true, restingUntil: null })), ctx).usable;
301
+ if (asIfReady.length > 0)
302
+ return { kind: 'account', entry: entryOf(asIfReady[0]), resting: false };
303
+ if (live.length === 0)
304
+ return { kind: 'none', because: `no ${provider} account on this machine is left to try` };
305
+ return {
306
+ kind: 'none',
307
+ because: `no AI account on this machine is allowed for this work: ` + refused.map((r) => `${r.name} — ${r.why}`).join('; '),
308
+ };
309
+ }
310
+ /** Whether any account other than `except` could take a call of this kind right now. */
311
+ function anotherAccountUsable(input, home = (0, node_os_1.homedir)()) {
312
+ const provider = input.provider ?? 'claude';
313
+ const { candidates } = candidatesFor(home, input.now, provider);
314
+ const ctx = { provider, role: input.role, projectId: input.projectId, requesterRef: input.requesterRef, now: input.now };
315
+ const { usable } = (0, core_1.chooseAccounts)(candidates.filter((c) => c.name !== input.except && !(input.skip ?? []).includes(c.name)), ctx);
316
+ return usable[0] ?? null;
317
+ }
318
+ // ── what the heartbeat says ──
319
+ /** The heartbeat runs every few seconds in every daemon; the ledger is read at most once a minute per process. */
320
+ const USAGE_CACHE_MS = 60_000;
321
+ let usageCache = null;
322
+ function cachedUsage(home, now) {
323
+ if (usageCache !== null && usageCache.home === home && now - usageCache.at >= 0 && now - usageCache.at < USAGE_CACHE_MS) {
324
+ return usageCache.value;
325
+ }
326
+ usageCache = { home, at: now, value: accountUsage(home, now) };
327
+ return usageCache.value;
328
+ }
329
+ /**
330
+ * Every account, as the heartbeat reports it. Readiness is what was last
331
+ * checked (`refreshAccountReadiness`); nothing here starts a process.
332
+ */
333
+ function accountReports(home = (0, node_os_1.homedir)(), now = Date.now()) {
334
+ const states = readAccountStates(home);
335
+ const policies = new Map(readAccountPolicies(home).map((p) => [p.name, p]));
336
+ const usage = cachedUsage(home, now);
337
+ return readAccounts(home).map((e) => {
338
+ const s = states[e.name] ?? {};
339
+ const plan = s.plan ?? null;
340
+ const authMethod = s.authMethod ?? null;
341
+ const personal = (0, core_1.isPersonalAccount)(authMethod, plan);
342
+ const policy = policies.get(e.name);
343
+ const resting = typeof s.restingUntil === 'number' && s.restingUntil > now;
344
+ const ready = s.ready !== false && s.checkedAt !== undefined;
345
+ return {
346
+ name: e.name,
347
+ provider: e.provider,
348
+ label: e.label,
349
+ authMethod,
350
+ plan,
351
+ personal,
352
+ ready,
353
+ reason: ready ? null : s.checkedAt === undefined ? 'unknown' : (s.reason ?? 'unknown'),
354
+ restingUntil: resting ? new Date(s.restingUntil).toISOString() : null,
355
+ restingBecause: resting ? (s.restingBecause ?? null) : null,
356
+ usage: usage.get(e.name) ?? { dayTokens: 0, weekTokens: 0 },
357
+ policyRefused: policy !== undefined ? (0, core_1.policyProblemFor)(policy, { personal }) : null,
358
+ };
359
+ });
360
+ }
361
+ function planOf(x) {
362
+ if (typeof x !== 'string')
363
+ return null;
364
+ const v = x.toLowerCase();
365
+ return core_1.ACCOUNT_PLANS.includes(v) ? v : null;
366
+ }
367
+ /** `codex` on PATH, or null. Codex is installed by its owner; Looply does not install it. */
368
+ function codexExecutable(env = process.env) {
369
+ const names = process.platform === 'win32' ? ['codex.cmd', 'codex.exe', 'codex'] : ['codex'];
370
+ for (const dir of (env['PATH'] ?? env['Path'] ?? '').split(node_path_1.delimiter)) {
371
+ if (dir === '')
372
+ continue;
373
+ for (const n of names) {
374
+ const p = (0, node_path_1.join)(dir, n);
375
+ if ((0, node_fs_1.existsSync)(p))
376
+ return p;
377
+ }
378
+ }
379
+ return null;
380
+ }
381
+ /**
382
+ * Is a codex account logged in? `codex login status` in its own `CODEX_HOME`
383
+ * answers with exit 0 when it is, and names "API key" or "ChatGPT".
384
+ *
385
+ * ⚠️ NEVER RUN END TO END ON THIS PROJECT'S MACHINES: the codex preset is
386
+ * declared but no Looply run has used it yet. Readiness is what this checks.
387
+ */
388
+ function checkCodexAuth(profileDir, deps = {}) {
389
+ const exe = deps.executable !== undefined ? deps.executable : codexExecutable();
390
+ if (exe === null)
391
+ return { ok: false, reason: 'not_installed', because: 'codex is not installed on this machine' };
392
+ (0, node_fs_1.mkdirSync)(profileDir, { recursive: true });
393
+ const env = { ...process.env, CODEX_HOME: profileDir };
394
+ const run = deps.run ??
395
+ ((e, argv, en) => {
396
+ try {
397
+ const out = (0, node_child_process_1.execFileSync)(e, [...argv], {
398
+ encoding: 'utf8',
399
+ timeout: 20_000,
400
+ env: en,
401
+ stdio: ['ignore', 'pipe', 'pipe'],
402
+ windowsHide: true,
403
+ shell: process.platform === 'win32' && e.toLowerCase().endsWith('.cmd'),
404
+ });
405
+ return { status: 0, out };
406
+ }
407
+ catch (err) {
408
+ const x = err;
409
+ return { status: typeof x.status === 'number' ? x.status : 1, out: `${x.stdout ?? ''}${x.stderr ?? ''}` };
410
+ }
411
+ });
412
+ const r = run(exe, ['login', 'status'], env);
413
+ if (r.status !== 0)
414
+ return { ok: false, reason: 'not_logged_in', because: 'this codex account is not logged in' };
415
+ const method = /api key/i.test(r.out) ? 'api_key' : /chatgpt/i.test(r.out) ? 'chatgpt' : null;
416
+ return { ok: true, authMethod: method, plan: null };
417
+ }
418
+ /** Who asked for the work a run is bound to (`requestedBy.ref` on its goal), or null. */
419
+ function requesterRefOf(goal) {
420
+ const ref = goal?.requestedBy?.ref;
421
+ return typeof ref === 'string' && ref !== '' ? ref : null;
422
+ }
423
+ //# sourceMappingURL=provider-accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-accounts.js","sourceRoot":"","sources":["../src/provider-accounts.ts"],"names":[],"mappings":";;;AA0EA,8CAIC;AAkDD,oCAiBC;AAGD,gCAyBC;AAGD,sCAOC;AAID,8CAIC;AAaD,gDAEC;AAGD,wDAaC;AAUD,kDAIC;AAGD,0DAmCC;AAKD,oCAgBC;AAmDD,oDAgCC;AAGD,oDASC;AAmBD,wCA2BC;AAQD,wBAIC;AAQD,0CAUC;AASD,wCA2BC;AAGD,wCAGC;AA5fD,2DAAkD;AAClD,qCAAqG;AACrG,qCAAkC;AAClC,yCAAqD;AACrD,uCAesB;AACtB,iDAA2C;AAC3C,mDAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEU,QAAA,aAAa,GAAG,wBAAwB,CAAC;AACzC,QAAA,mBAAmB,GAAG,8BAA8B,CAAC;AACrD,QAAA,oBAAoB,GAAG,+BAA+B,CAAC;AACvD,QAAA,YAAY,GAAG,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,OAAO,GAA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C5D,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { type ProviderDiscovery } from './provider-discovery';
2
2
  import { type ProviderReadiness } from './provider-ready';
3
3
  import { type ProviderAuthState } from './provider-state';
4
+ import { type AccountsCmdDeps } from './provider-accounts-cmd';
4
5
  /**
5
6
  * `looply provider` — IS CLAUDE CODE READY ON THIS MACHINE, AND IF NOT, FIX IT.
6
7
  *
@@ -40,6 +41,8 @@ export interface ProviderDeps {
40
41
  login(executable: string): Promise<number>;
41
42
  out(line: string): void;
42
43
  err(line: string): void;
44
+ /** Several named AI accounts on this machine (`provider-accounts-cmd.ts`). */
45
+ accounts?: AccountsCmdDeps;
43
46
  }
44
47
  export declare function readinessOf(deps: Pick<ProviderDeps, 'discover' | 'checkAuth' | 'version'>): ProviderReadiness;
45
48
  /** The exact command a person types to log Looply's profile in, in their own shell. */
@@ -1 +1 @@
1
- {"version":3,"file":"provider-cmd.d.ts","sourceRoot":"","sources":["../src/provider-cmd.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkC,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAuC,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAyC,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGjG;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,cAAc,QAKf,CAAC;AAEb,wFAAwF;AACxF,eAAO,MAAM,eAAe,8CAA8C,CAAC;AAC3E,sFAAsF;AACtF,eAAO,MAAM,cAAc,8CAAkB,CAAC;AAK9C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,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