@kapybara/zerosub 1.2.2 → 1.3.0
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/README.md +3 -1
- package/client/accounts-surface.tsx +7 -0
- package/client/settings-screen.tsx +7 -0
- package/package.json +1 -1
- package/server/codex.ts +1 -1
- package/server/service.ts +73 -2
- package/server/state.ts +2 -1
- package/shared/preferences.ts +7 -0
package/README.md
CHANGED
|
@@ -37,7 +37,9 @@ Then open **Accounts (ZeroSub)** in the sidebar.
|
|
|
37
37
|
- In a browser on the host's own computer, the page finishes by itself.
|
|
38
38
|
- Anywhere else, choose **Use a code instead**. For Claude, paste the code shown after sign-in. For ChatGPT, type the code shown in Paseo on the page. Phones, and hosts without a desktop (servers, containers, daemons started over SSH), start with the code.
|
|
39
39
|
3. Choose which account agents use:
|
|
40
|
-
- **Make default**: new agents, and agents that follow the default, use it.
|
|
40
|
+
- **Make default**: new agents, and agents that follow the default, use it. Open Claude agents switch right away, busy ones after their turn.
|
|
41
|
+
- To leave open agents where they are, turn off **Move open agents when the default changes** (in Accounts, or **Settings → Plugins → zerosub → ZeroSub preferences**). Each open agent that follows the default then stays pinned to the account it's using, even after it reopens, unless that account is signed out, disabled or at its limit. New agents, and agents that aren't open at the time, use the new default.
|
|
42
|
+
- A kept agent still switches when its account hits a limit. To move it to the new default, choose **Follow default** from its account button, or type `/account default`.
|
|
41
43
|
- **The account button in an agent's message box**: moves that one agent.
|
|
42
44
|
- **`/account work`** in the message box, or `/account default` to follow the default again.
|
|
43
45
|
- **⌘K → "Make … the default"**.
|
|
@@ -639,6 +639,13 @@ function AutomationSettings({ theme }: { theme: Theme }) {
|
|
|
639
639
|
disabled={settings.saving}
|
|
640
640
|
onValueChange={(balanceNewAgents) => save({ balanceNewAgents })}
|
|
641
641
|
/>
|
|
642
|
+
<SettingsSwitch
|
|
643
|
+
label="Move open agents when the default changes"
|
|
644
|
+
hint="Off: open agents stay on the account they're using, even after they reopen. New agents, and agents that aren't open at the time, use the new default."
|
|
645
|
+
value={settings.values.moveAgentsOnDefaultChange}
|
|
646
|
+
disabled={settings.saving}
|
|
647
|
+
onValueChange={(moveAgentsOnDefaultChange) => save({ moveAgentsOnDefaultChange })}
|
|
648
|
+
/>
|
|
642
649
|
<SettingsSwitch
|
|
643
650
|
label="Use banked resets when every account is out"
|
|
644
651
|
hint="Spends one of the account's banked resets instead of stopping. Resets are scarce, so this is off unless you turn it on."
|
|
@@ -42,6 +42,13 @@ export function PreferencesScreen({ theme, host, onOpenAccounts }: PluginSurface
|
|
|
42
42
|
actionLabel="Open accounts"
|
|
43
43
|
onPress={onOpenAccounts}
|
|
44
44
|
/>
|
|
45
|
+
<SettingsSwitch
|
|
46
|
+
label="Move open agents when the default changes"
|
|
47
|
+
hint="Off: open agents stay on the account they're using, even after they reopen. New agents, and agents that aren't open at the time, use the new default."
|
|
48
|
+
value={settings.values.moveAgentsOnDefaultChange}
|
|
49
|
+
disabled={settings.saving}
|
|
50
|
+
onValueChange={(moveAgentsOnDefaultChange) => save({ moveAgentsOnDefaultChange })}
|
|
51
|
+
/>
|
|
45
52
|
</SettingsCard>
|
|
46
53
|
</SettingsSection>
|
|
47
54
|
<SettingsSection title="Automatic switching">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kapybara/zerosub",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "ZeroSub: use several Claude and ChatGPT (Codex) subscriptions side by side in Paseo. Add accounts in-app, pick one per agent, and switch automatically when an account hits its limit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paseo",
|
package/server/codex.ts
CHANGED
|
@@ -70,7 +70,7 @@ class AppServer {
|
|
|
70
70
|
try {
|
|
71
71
|
await server.request(
|
|
72
72
|
"initialize",
|
|
73
|
-
{ clientInfo: { name: CLIENT_NAME, title: "Paseo ZeroSub", version: "1.
|
|
73
|
+
{ clientInfo: { name: CLIENT_NAME, title: "Paseo ZeroSub", version: "1.3.0" }, capabilities: { experimentalApi: false } },
|
|
74
74
|
60_000,
|
|
75
75
|
);
|
|
76
76
|
server.send({ method: "initialized" });
|
package/server/service.ts
CHANGED
|
@@ -40,7 +40,7 @@ import { homesDir } from "./paths";
|
|
|
40
40
|
import { Reopener } from "./reopen";
|
|
41
41
|
import { SwitchGuard } from "./switch-guard";
|
|
42
42
|
import { loadReadings, mergeUsage, saveReadings, showLimit } from "./usage";
|
|
43
|
-
import { chooseAccount, isLimited, mostAvailable } from "./routing";
|
|
43
|
+
import { chooseAccount, isLimited, isUsable, mostAvailable } from "./routing";
|
|
44
44
|
import {
|
|
45
45
|
MAIN_ACCOUNT_ID,
|
|
46
46
|
StateStore,
|
|
@@ -79,11 +79,14 @@ const PRUNE_MS = 10 * 60_000;
|
|
|
79
79
|
/** After a reset, limit notices from turns that were already running are stale. */
|
|
80
80
|
const RESET_GRACE_MS = 5 * 60_000;
|
|
81
81
|
const AGENT_LIST_MS = 3_000;
|
|
82
|
+
/** How long a default change waits for sessions already being routed to record their account. */
|
|
83
|
+
const ROUTING_WAIT_MS = 5_000;
|
|
82
84
|
|
|
83
85
|
const DEFAULT_PREFERENCES: Preferences = {
|
|
84
86
|
autoSwitch: true,
|
|
85
87
|
autoContinue: true,
|
|
86
88
|
continuePrompt: DEFAULT_CONTINUE_PROMPT,
|
|
89
|
+
moveAgentsOnDefaultChange: true,
|
|
87
90
|
balanceNewAgents: false,
|
|
88
91
|
showComposerPill: true,
|
|
89
92
|
autoRedeem: false,
|
|
@@ -140,6 +143,8 @@ export class Service {
|
|
|
140
143
|
private readonly deferred = new Map<string, SwitchRow | null>();
|
|
141
144
|
/** Agents in the middle of a failover, so nothing else moves them at the same time. */
|
|
142
145
|
private readonly switching = new Set<string>();
|
|
146
|
+
/** Interactive sessions being routed right now, and their agents. Where each opens isn't recorded yet. */
|
|
147
|
+
private readonly routing = new Map<Promise<unknown>, string>();
|
|
143
148
|
/** One failover at a time per exhausted account. */
|
|
144
149
|
private readonly failoverLocks = new Map<string, Mutex>();
|
|
145
150
|
private readonly switchGuard = new SwitchGuard();
|
|
@@ -339,6 +344,20 @@ export class Service {
|
|
|
339
344
|
async onSessionOpen(
|
|
340
345
|
request: PluginSessionOpenRequest,
|
|
341
346
|
context: PluginHookContext,
|
|
347
|
+
): Promise<PluginSessionOpenRequest | undefined> {
|
|
348
|
+
const routed = this.route(request, context);
|
|
349
|
+
if (request.purpose !== "interactive") return routed;
|
|
350
|
+
this.routing.set(routed, request.agentId);
|
|
351
|
+
try {
|
|
352
|
+
return await routed;
|
|
353
|
+
} finally {
|
|
354
|
+
this.routing.delete(routed);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private async route(
|
|
359
|
+
request: PluginSessionOpenRequest,
|
|
360
|
+
context: PluginHookContext,
|
|
342
361
|
): Promise<PluginSessionOpenRequest | undefined> {
|
|
343
362
|
this.attach(context.paseo);
|
|
344
363
|
const family = (await this.families.resolve(context.paseo))[request.provider];
|
|
@@ -1303,10 +1322,18 @@ export class Service {
|
|
|
1303
1322
|
if (!account) throw new Error("That account no longer exists.");
|
|
1304
1323
|
if (!account.signedIn) throw new Error(`${account.label} is signed out. Sign it in first.`);
|
|
1305
1324
|
if (account.disabled) throw new Error(`${account.label} is disabled. Enable it before making it the default.`);
|
|
1306
|
-
|
|
1325
|
+
const portable = this.adapters[account.family].portable;
|
|
1326
|
+
if (!portable) await this.pinThreads(paseo, account.family);
|
|
1307
1327
|
await this.store.update((draft) => {
|
|
1308
1328
|
draft.defaults[account.family] = account.id;
|
|
1309
1329
|
});
|
|
1330
|
+
if (portable && !this.prefs.moveAgentsOnDefaultChange) {
|
|
1331
|
+
// The new default is for what comes next: open agents stay on the account they run on.
|
|
1332
|
+
const { kept, moving } = await this.keepOpenAgents(paseo, account.family, account.id);
|
|
1333
|
+
console.log(`[ZeroSub] ${account.label} is the default now; ${kept} open agent(s) stay on their account`);
|
|
1334
|
+
// Agents that can't stay where they are move as they would with the switch on; nothing else does.
|
|
1335
|
+
return moving.length > 0 ? this.reconcile(paseo, "default", moving) : emptySummary();
|
|
1336
|
+
}
|
|
1310
1337
|
// Conversations that can't move (Codex threads) are pinned, so this only moves portable ones.
|
|
1311
1338
|
return this.reconcile(paseo, "default");
|
|
1312
1339
|
}
|
|
@@ -1366,6 +1393,50 @@ export class Service {
|
|
|
1366
1393
|
});
|
|
1367
1394
|
}
|
|
1368
1395
|
|
|
1396
|
+
/**
|
|
1397
|
+
* Pins each open agent that follows the default to the account it runs on, so the new default
|
|
1398
|
+
* doesn't move it, now or when it next opens. Runs once the new default is in place, so an agent
|
|
1399
|
+
* that opened under the old one just before is kept too, even if its session was still being
|
|
1400
|
+
* routed. Agents already on the new default keep following it. An account that's gone, signed
|
|
1401
|
+
* out, disabled or at its limit is no place to keep work, so those agents come back in `moving`.
|
|
1402
|
+
*/
|
|
1403
|
+
private async keepOpenAgents(
|
|
1404
|
+
paseo: PaseoApi,
|
|
1405
|
+
family: Family,
|
|
1406
|
+
newDefault: string,
|
|
1407
|
+
): Promise<{ kept: number; moving: string[] }> {
|
|
1408
|
+
// A session being routed may have gone by the old default: let it record where it opens first.
|
|
1409
|
+
if (this.routing.size > 0) await withTimeout(Promise.allSettled(this.routing.keys()), ROUTING_WAIT_MS);
|
|
1410
|
+
const families = await this.families.resolve(paseo);
|
|
1411
|
+
const open = (await listAgents(paseo, false)).agents.filter(
|
|
1412
|
+
(agent) => families[agent.provider] === family && !agent.archived && isLive(agent.status),
|
|
1413
|
+
);
|
|
1414
|
+
let kept = 0;
|
|
1415
|
+
const moving: string[] = [];
|
|
1416
|
+
if (open.length === 0) return { kept, moving };
|
|
1417
|
+
const now = Date.now();
|
|
1418
|
+
const at = new Date(now).toISOString();
|
|
1419
|
+
await this.store.update((draft) => {
|
|
1420
|
+
// Where these open isn't recorded yet, and a session routed now goes by the new default.
|
|
1421
|
+
const routing = new Set(this.routing.values());
|
|
1422
|
+
for (const agent of open) {
|
|
1423
|
+
if (routing.has(agent.id)) continue;
|
|
1424
|
+
// An agent with an account of its own never followed the default.
|
|
1425
|
+
if (findAccount(draft, draft.bindings[agent.id]?.accountId)?.family === family) continue;
|
|
1426
|
+
// Still starting, and not routed yet: it will be, by the new default.
|
|
1427
|
+
if (agent.status === "initializing" && !draft.sessions[agent.id]) continue;
|
|
1428
|
+
const current = findAccount(draft, this.runningOn(draft, agent.id, family));
|
|
1429
|
+
if (!current || current.family !== family || !isUsable(current, now)) moving.push(agent.id);
|
|
1430
|
+
else if (current.id !== newDefault) {
|
|
1431
|
+
// "auto", like a limit switch, so the account button still offers "Follow default".
|
|
1432
|
+
draft.bindings[agent.id] = { accountId: current.id, source: "auto", at };
|
|
1433
|
+
kept += 1;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
return { kept, moving };
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1369
1440
|
async clearLimit(accountId: string): Promise<void> {
|
|
1370
1441
|
const state = await this.store.update((draft) => {
|
|
1371
1442
|
const account = findAccount(draft, accountId);
|
package/server/state.ts
CHANGED
|
@@ -33,7 +33,8 @@ export type StoredAccount = z.infer<typeof StoredAccountSchema>;
|
|
|
33
33
|
export const BindingSchema = z.object({
|
|
34
34
|
accountId: z.string(),
|
|
35
35
|
/**
|
|
36
|
-
* `user`: chosen in the UI. `auto`: moved after a limit
|
|
36
|
+
* `user`: chosen in the UI. `auto`: moved after a limit, or kept on its account when the default
|
|
37
|
+
* changed. `balance`: spread at creation.
|
|
37
38
|
* `thread`: a conversation that can't change accounts, pinned where it started.
|
|
38
39
|
*/
|
|
39
40
|
source: z.enum(["user", "auto", "balance", "thread"]),
|
package/shared/preferences.ts
CHANGED
|
@@ -15,6 +15,13 @@ export const preferences = defineSettings({
|
|
|
15
15
|
/** After an automatic switch, send a follow-up so the interrupted turn keeps going. */
|
|
16
16
|
autoContinue: z.boolean().default(true),
|
|
17
17
|
continuePrompt: z.string().trim().min(1).max(500).default(DEFAULT_CONTINUE_PROMPT),
|
|
18
|
+
/**
|
|
19
|
+
* When the default account changes, open agents that follow it move to the new one. Off, each
|
|
20
|
+
* stays pinned to the account it runs on (so it stays there when it next opens too), unless that
|
|
21
|
+
* account can't be used right now, and the new default is for new agents and ones that aren't
|
|
22
|
+
* open at the time. Codex threads never move either way.
|
|
23
|
+
*/
|
|
24
|
+
moveAgentsOnDefaultChange: z.boolean().default(true),
|
|
18
25
|
/** New agents start on the account with the most headroom instead of the default. */
|
|
19
26
|
balanceNewAgents: z.boolean().default(false),
|
|
20
27
|
/** When every account of a provider is at its limit, spend a banked reset instead of stopping. */
|