@kapybara/zerosub 1.0.0 → 1.2.1
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 +2 -0
- package/client/accounts-surface.tsx +97 -13
- package/client/add-account.tsx +51 -8
- package/client/commands.ts +2 -1
- package/client/fork-confirm.tsx +3 -1
- package/client/pills.ts +3 -2
- package/client/reset-confirm.tsx +4 -2
- package/client/switch-row.tsx +6 -1
- package/client/ui.tsx +158 -62
- package/index.server.ts +2 -0
- package/package.json +1 -1
- package/paseo-plugin.json +0 -1
- package/server/adapter.ts +17 -4
- package/server/codex.ts +1 -1
- package/server/handoff.ts +1 -1
- package/server/limits.ts +11 -10
- package/server/reopen.ts +4 -3
- package/server/routing.ts +14 -6
- package/server/service.ts +52 -4
- package/server/state.ts +2 -0
- package/shared/format.ts +1 -0
- package/shared/model.ts +2 -1
- package/shared/rpc.ts +10 -0
- package/shared/timeline.ts +4 -0
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Use several Claude and ChatGPT (Codex) subscriptions side by side in [Paseo](htt
|
|
|
8
8
|
- **Automatic failover.** When an account hits its 5-hour or weekly limit, the agent moves to the account with the most room left and carries on. New agents skip exhausted accounts.
|
|
9
9
|
- **Live usage.** Each account shows its own 5-hour and weekly usage and when they reset. Accounts in use refresh about every minute and after each turn, and a limit shows up the moment it hits.
|
|
10
10
|
- **Banked resets.** If a provider has banked limit resets on an account, you can use one from the account card or the agent's account button.
|
|
11
|
+
- **Set an account aside.** Disable an account for a while and its agents move to your other accounts, then come back when you enable it again.
|
|
11
12
|
- **Several hosts.** Each Paseo host keeps its own accounts, and the Accounts screen says which host you're looking at.
|
|
12
13
|
- **Fork to the other provider (optional).** When every Claude account is out, a stopped chat can carry on in a new ChatGPT agent, and the other way round.
|
|
13
14
|
- **Everything else stays the same.** Every account shares your settings, skills, plugins, MCP servers, `CLAUDE.md`/`AGENTS.md` and conversation history.
|
|
@@ -40,6 +41,7 @@ Then open **Accounts (ZeroSub)** in the sidebar.
|
|
|
40
41
|
- **The account button in an agent's message box**: moves that one agent.
|
|
41
42
|
- **`/account work`** in the message box, or `/account default` to follow the default again.
|
|
42
43
|
- **⌘K → "Make … the default"**.
|
|
44
|
+
- **Disable for now** (the pause button on a card): the account stays signed in but ZeroSub stops using it. Its agents move to your other accounts right away (busy ones after their turn) and come back when you press **Enable**. ChatGPT conversations already on it stay, since they can't change accounts. You can't disable the last usable account of a provider.
|
|
43
45
|
4. Leave **Automatic switching** on (in Accounts, or **Settings → Plugins → zerosub → ZeroSub preferences**) and limits take care of themselves:
|
|
44
46
|
- Only the CLIs' own limit notices trigger a switch. That covers Claude Code's "You've hit your session limit · resets 3pm" and Codex's "You’ve hit your usage limit…".
|
|
45
47
|
- A short note in the agent's timeline says what happened.
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
clearAccountLimit,
|
|
11
11
|
removeAccount,
|
|
12
12
|
renameAccount,
|
|
13
|
+
setAccountEnabled,
|
|
13
14
|
setDefaultAccount,
|
|
14
15
|
type ReopenSummary,
|
|
15
16
|
} from "../shared/rpc";
|
|
@@ -61,7 +62,15 @@ export function AccountsSurface(props: PluginSurfaceProps & { store: ZeroSubStor
|
|
|
61
62
|
Subscription accounts
|
|
62
63
|
</Text>
|
|
63
64
|
{state ? (
|
|
64
|
-
<IconButton
|
|
65
|
+
<IconButton
|
|
66
|
+
theme={theme}
|
|
67
|
+
icon="RefreshCw"
|
|
68
|
+
label="Refresh usage"
|
|
69
|
+
tooltip="Refresh usage for every account now"
|
|
70
|
+
tooltipPlacement="bottom"
|
|
71
|
+
busy={refreshing}
|
|
72
|
+
onPress={() => void refreshUsage()}
|
|
73
|
+
/>
|
|
65
74
|
) : null}
|
|
66
75
|
</View>
|
|
67
76
|
<Text style={text.muted}>
|
|
@@ -81,7 +90,14 @@ export function AccountsSurface(props: PluginSurfaceProps & { store: ZeroSubStor
|
|
|
81
90
|
}`
|
|
82
91
|
: `Could not reach the daemon: ${error}`}
|
|
83
92
|
</Text>
|
|
84
|
-
<Button
|
|
93
|
+
<Button
|
|
94
|
+
theme={theme}
|
|
95
|
+
label="Try again"
|
|
96
|
+
icon="RefreshCw"
|
|
97
|
+
tooltip="Ask this host for its accounts again"
|
|
98
|
+
tooltipAlign="start"
|
|
99
|
+
onPress={() => void store.refresh()}
|
|
100
|
+
/>
|
|
85
101
|
</Card>
|
|
86
102
|
) : null}
|
|
87
103
|
|
|
@@ -185,6 +201,8 @@ function FamilySection({
|
|
|
185
201
|
icon="Plus"
|
|
186
202
|
label={compact ? "Add" : "Add account"}
|
|
187
203
|
accessibilityLabel={`Add ${FAMILY_LABEL[family]} account`}
|
|
204
|
+
tooltip={`Sign in another ${FAMILY_LABEL[family]} account`}
|
|
205
|
+
tooltipAlign="end"
|
|
188
206
|
onPress={onAdd}
|
|
189
207
|
/>
|
|
190
208
|
</View>
|
|
@@ -222,7 +240,7 @@ function AccountCard({
|
|
|
222
240
|
}) {
|
|
223
241
|
const text = useText(theme);
|
|
224
242
|
const toast = useToast();
|
|
225
|
-
const [busy, setBusy] = useState<"default" | "remove" | "clear" | null>(null);
|
|
243
|
+
const [busy, setBusy] = useState<"default" | "remove" | "clear" | "toggle" | null>(null);
|
|
226
244
|
const [renaming, setRenaming] = useState(false);
|
|
227
245
|
const [confirmRemove, setConfirmRemove] = useState(false);
|
|
228
246
|
const [confirmReset, setConfirmReset] = useState(false);
|
|
@@ -231,10 +249,31 @@ function AccountCard({
|
|
|
231
249
|
const summary = usageSummary(account);
|
|
232
250
|
const subtitle = accountSubtitle(account);
|
|
233
251
|
const signedOut = account.status === "signed_out";
|
|
252
|
+
const disabled = account.status === "disabled";
|
|
253
|
+
const faded = disabled ? { opacity: 0.55 } : null;
|
|
234
254
|
const windows = account.usage?.windows ?? [];
|
|
235
255
|
const agents = account.agentCount === 0 ? "No agents" : `${account.agentCount} agent${account.agentCount === 1 ? "" : "s"}`;
|
|
236
256
|
const freshness = !signedOut && account.usage && windows.length > 0 ? `updated ${formatAge(account.usage.fetchedAt)}` : null;
|
|
237
257
|
|
|
258
|
+
// Sets the account aside for a while, or brings it back; its agents move off it and back.
|
|
259
|
+
const toggle = useCallback(async () => {
|
|
260
|
+
const enabling = account.status === "disabled";
|
|
261
|
+
setBusy("toggle");
|
|
262
|
+
try {
|
|
263
|
+
const result = await store.rpc(setAccountEnabled, { accountId: account.id, enabled: enabling });
|
|
264
|
+
const message = describeReopen(`${account.label} is ${enabling ? "enabled" : "disabled"}`, result);
|
|
265
|
+
const stayed =
|
|
266
|
+
result.stayed > 0
|
|
267
|
+
? ` · ${result.stayed} ChatGPT conversation${result.stayed === 1 ? " stays" : "s stay"} on it (they can't change accounts)`
|
|
268
|
+
: "";
|
|
269
|
+
toast.show(`${message}${stayed}`, { variant: "success", durationMs: 5_000 });
|
|
270
|
+
} catch (error) {
|
|
271
|
+
toast.error(describe(error));
|
|
272
|
+
} finally {
|
|
273
|
+
setBusy(null);
|
|
274
|
+
}
|
|
275
|
+
}, [account, store, toast]);
|
|
276
|
+
|
|
238
277
|
const makeDefault = useCallback(async () => {
|
|
239
278
|
setBusy("default");
|
|
240
279
|
try {
|
|
@@ -283,8 +322,10 @@ function AccountCard({
|
|
|
283
322
|
return (
|
|
284
323
|
<Card theme={theme} fill>
|
|
285
324
|
<View style={{ flexDirection: "row", alignItems: "flex-start", gap: 12 }}>
|
|
286
|
-
<
|
|
287
|
-
|
|
325
|
+
<View style={faded}>
|
|
326
|
+
<Avatar theme={theme} label={account.label} />
|
|
327
|
+
</View>
|
|
328
|
+
<View style={[{ flex: 1, minWidth: 0, gap: 3 }, faded]}>
|
|
288
329
|
<Text style={text.strong} numberOfLines={1}>
|
|
289
330
|
{account.label}
|
|
290
331
|
</Text>
|
|
@@ -300,25 +341,40 @@ function AccountCard({
|
|
|
300
341
|
theme={theme}
|
|
301
342
|
icon="CircleCheck"
|
|
302
343
|
label="Mark as available again (it has room)"
|
|
344
|
+
tooltip="Mark as available: use it again before its limit resets, e.g. after upgrading"
|
|
303
345
|
busy={busy === "clear"}
|
|
304
346
|
onPress={() => void markAvailable()}
|
|
305
347
|
/>
|
|
306
348
|
) : null}
|
|
307
|
-
{!account.isDefault &&
|
|
349
|
+
{!account.isDefault && !signedOut && !disabled ? (
|
|
308
350
|
<IconButton
|
|
309
351
|
theme={theme}
|
|
310
352
|
icon="Star"
|
|
311
353
|
label="Make default"
|
|
354
|
+
tooltip="Make default: new agents start on this account"
|
|
312
355
|
busy={busy === "default"}
|
|
313
356
|
onPress={() => void makeDefault()}
|
|
314
357
|
/>
|
|
315
358
|
) : null}
|
|
316
|
-
<IconButton
|
|
359
|
+
<IconButton
|
|
360
|
+
theme={theme}
|
|
361
|
+
icon={disabled ? "CirclePlay" : "CirclePause"}
|
|
362
|
+
label={disabled ? "Enable account" : "Disable for now (agents won't use it)"}
|
|
363
|
+
tooltip={
|
|
364
|
+
disabled
|
|
365
|
+
? "Enable: agents can use this account again"
|
|
366
|
+
: "Disable for now: agents stop using it and move to your other accounts"
|
|
367
|
+
}
|
|
368
|
+
busy={busy === "toggle"}
|
|
369
|
+
onPress={() => void toggle()}
|
|
370
|
+
/>
|
|
371
|
+
<IconButton theme={theme} icon="Pencil" label="Rename" tooltip="Rename this account" onPress={() => setRenaming(true)} />
|
|
317
372
|
{account.kind !== "main" ? (
|
|
318
373
|
<IconButton
|
|
319
374
|
theme={theme}
|
|
320
375
|
icon="Trash2"
|
|
321
376
|
label="Remove"
|
|
377
|
+
tooltip="Remove: sign it out and delete its saved login"
|
|
322
378
|
tone="danger"
|
|
323
379
|
busy={busy === "remove"}
|
|
324
380
|
onPress={() => setConfirmRemove(true)}
|
|
@@ -327,8 +383,9 @@ function AccountCard({
|
|
|
327
383
|
</View>
|
|
328
384
|
</View>
|
|
329
385
|
|
|
330
|
-
<View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 6 }}>
|
|
386
|
+
<View style={[{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 6 }, faded]}>
|
|
331
387
|
{account.isDefault ? <Badge theme={theme} label="Default" tone="accent" /> : null}
|
|
388
|
+
{disabled ? <Badge theme={theme} label="Disabled" /> : null}
|
|
332
389
|
{plan ? <Badge theme={theme} label={plan} /> : null}
|
|
333
390
|
{account.kind === "main" ? <Badge theme={theme} label="CLI login" /> : null}
|
|
334
391
|
{account.status === "limited" ? <Badge theme={theme} label="Limit reached" tone="danger" /> : null}
|
|
@@ -336,7 +393,7 @@ function AccountCard({
|
|
|
336
393
|
{resets && !signedOut ? <Badge theme={theme} label={resetBadge(resets)} tone="accent" /> : null}
|
|
337
394
|
</View>
|
|
338
395
|
|
|
339
|
-
<View style={{ gap: 10 }}>
|
|
396
|
+
<View style={[{ gap: 10 }, faded]}>
|
|
340
397
|
{signedOut ? (
|
|
341
398
|
<Text style={text.small}>Sign in again to use this account.</Text>
|
|
342
399
|
) : windows.length > 0 ? (
|
|
@@ -365,10 +422,31 @@ function AccountCard({
|
|
|
365
422
|
}}
|
|
366
423
|
>
|
|
367
424
|
<Text style={[text.small, { flexShrink: 1 }]} numberOfLines={1}>
|
|
368
|
-
{freshness ? `${agents} · ${freshness}` : agents}
|
|
425
|
+
{disabled ? "Disabled · agents won't use it" : freshness ? `${agents} · ${freshness}` : agents}
|
|
369
426
|
</Text>
|
|
370
427
|
{signedOut ? (
|
|
371
|
-
<Button
|
|
428
|
+
<Button
|
|
429
|
+
theme={theme}
|
|
430
|
+
size="small"
|
|
431
|
+
tone="primary"
|
|
432
|
+
icon="LogIn"
|
|
433
|
+
label="Sign in"
|
|
434
|
+
tooltip="Sign this account in again"
|
|
435
|
+
tooltipAlign="end"
|
|
436
|
+
onPress={onSignIn}
|
|
437
|
+
/>
|
|
438
|
+
) : disabled ? (
|
|
439
|
+
<Button
|
|
440
|
+
theme={theme}
|
|
441
|
+
size="small"
|
|
442
|
+
tone="primary"
|
|
443
|
+
icon="CirclePlay"
|
|
444
|
+
label="Enable"
|
|
445
|
+
tooltip="Use this account again; its agents move back to it"
|
|
446
|
+
tooltipAlign="end"
|
|
447
|
+
busy={busy === "toggle"}
|
|
448
|
+
onPress={() => void toggle()}
|
|
449
|
+
/>
|
|
372
450
|
) : resets ? (
|
|
373
451
|
<Button
|
|
374
452
|
theme={theme}
|
|
@@ -377,6 +455,8 @@ function AccountCard({
|
|
|
377
455
|
icon="TimerReset"
|
|
378
456
|
label="Use reset"
|
|
379
457
|
accessibilityLabel="Use a banked reset"
|
|
458
|
+
tooltip="Spend a banked reset to refill this account's limits now"
|
|
459
|
+
tooltipAlign="end"
|
|
380
460
|
disabled={!resets.usableNow}
|
|
381
461
|
onPress={() => setConfirmReset(true)}
|
|
382
462
|
/>
|
|
@@ -410,12 +490,14 @@ function AccountCard({
|
|
|
410
490
|
: "This signs the account out on this machine and deletes its saved login. New agents use the default account. Existing ChatGPT conversations on it can't move, so start new agents for them."}
|
|
411
491
|
</Text>
|
|
412
492
|
<View style={{ flexDirection: "row", gap: 8, justifyContent: "flex-end" }}>
|
|
413
|
-
<Button theme={theme} label="Cancel" onPress={() => setConfirmRemove(false)} />
|
|
493
|
+
<Button theme={theme} label="Cancel" tooltip="Keep this account" tooltipAlign="end" onPress={() => setConfirmRemove(false)} />
|
|
414
494
|
<Button
|
|
415
495
|
theme={theme}
|
|
416
496
|
tone="danger"
|
|
417
497
|
icon="Trash2"
|
|
418
498
|
label="Remove"
|
|
499
|
+
tooltip="Sign it out and delete its saved login; its agents move to the default"
|
|
500
|
+
tooltipAlign="end"
|
|
419
501
|
busy={busy === "remove"}
|
|
420
502
|
onPress={() => void remove()}
|
|
421
503
|
/>
|
|
@@ -484,11 +566,13 @@ function RenameModal({
|
|
|
484
566
|
accessibilityLabel="Account name"
|
|
485
567
|
/>
|
|
486
568
|
<View style={{ flexDirection: "row", gap: 8, justifyContent: "flex-end" }}>
|
|
487
|
-
<Button theme={theme} label="Cancel" onPress={onClose} />
|
|
569
|
+
<Button theme={theme} label="Cancel" tooltip="Keep the current name" tooltipAlign="end" onPress={onClose} />
|
|
488
570
|
<Button
|
|
489
571
|
theme={theme}
|
|
490
572
|
tone="primary"
|
|
491
573
|
label="Save"
|
|
574
|
+
tooltip="Save the new name"
|
|
575
|
+
tooltipAlign="end"
|
|
492
576
|
busy={saving}
|
|
493
577
|
disabled={!label.trim()}
|
|
494
578
|
onPress={() => void save()}
|
package/client/add-account.tsx
CHANGED
|
@@ -96,8 +96,16 @@ export function AddAccountModal({
|
|
|
96
96
|
<>
|
|
97
97
|
<Text style={text.danger}>{startError}</Text>
|
|
98
98
|
<Row>
|
|
99
|
-
<Button theme={theme} label="Close" onPress={close} />
|
|
100
|
-
<Button
|
|
99
|
+
<Button theme={theme} label="Close" tooltip="Close without adding an account" tooltipAlign="end" onPress={close} />
|
|
100
|
+
<Button
|
|
101
|
+
theme={theme}
|
|
102
|
+
tone="primary"
|
|
103
|
+
icon="RefreshCw"
|
|
104
|
+
label="Try again"
|
|
105
|
+
tooltip="Start the sign-in again"
|
|
106
|
+
tooltipAlign="end"
|
|
107
|
+
onPress={() => void begin(method)}
|
|
108
|
+
/>
|
|
101
109
|
</Row>
|
|
102
110
|
</>
|
|
103
111
|
);
|
|
@@ -131,7 +139,7 @@ export function AddAccountModal({
|
|
|
131
139
|
move an agent to it from the account button in the message box.
|
|
132
140
|
</Text>
|
|
133
141
|
<Row>
|
|
134
|
-
<Button theme={theme} tone="primary" label="Done" onPress={onClose} />
|
|
142
|
+
<Button theme={theme} tone="primary" label="Done" tooltip="Close this window" tooltipAlign="end" onPress={onClose} />
|
|
135
143
|
</Row>
|
|
136
144
|
</>
|
|
137
145
|
);
|
|
@@ -142,8 +150,16 @@ export function AddAccountModal({
|
|
|
142
150
|
{login.message ?? (login.step === "canceled" ? "Sign-in was canceled." : "Sign-in failed.")}
|
|
143
151
|
</Text>
|
|
144
152
|
<Row>
|
|
145
|
-
<Button theme={theme} label="Close" onPress={close} />
|
|
146
|
-
<Button
|
|
153
|
+
<Button theme={theme} label="Close" tooltip="Close without adding an account" tooltipAlign="end" onPress={close} />
|
|
154
|
+
<Button
|
|
155
|
+
theme={theme}
|
|
156
|
+
tone="primary"
|
|
157
|
+
icon="RefreshCw"
|
|
158
|
+
label="Try again"
|
|
159
|
+
tooltip="Start the sign-in again"
|
|
160
|
+
tooltipAlign="end"
|
|
161
|
+
onPress={() => void begin(method)}
|
|
162
|
+
/>
|
|
147
163
|
</Row>
|
|
148
164
|
</>
|
|
149
165
|
);
|
|
@@ -242,8 +258,26 @@ function SignInSteps({
|
|
|
242
258
|
: "Sign in with the account you want to add, using a browser on the host's own computer. It finishes by itself."}
|
|
243
259
|
</Text>
|
|
244
260
|
<Row start>
|
|
245
|
-
<Button
|
|
246
|
-
|
|
261
|
+
<Button
|
|
262
|
+
theme={theme}
|
|
263
|
+
tone="primary"
|
|
264
|
+
icon="ExternalLink"
|
|
265
|
+
label="Open sign-in page"
|
|
266
|
+
tooltip={`Open the ${service} sign-in page in your browser`}
|
|
267
|
+
tooltipAlign="start"
|
|
268
|
+
disabled={!link}
|
|
269
|
+
onPress={open}
|
|
270
|
+
/>
|
|
271
|
+
{link ? (
|
|
272
|
+
<Button
|
|
273
|
+
theme={theme}
|
|
274
|
+
icon="Copy"
|
|
275
|
+
label="Copy link"
|
|
276
|
+
tooltip="Copy the sign-in link, for example to open it on another device"
|
|
277
|
+
tooltipAlign="start"
|
|
278
|
+
onPress={() => void copy(link, "Link")}
|
|
279
|
+
/>
|
|
280
|
+
) : null}
|
|
247
281
|
</Row>
|
|
248
282
|
</Step>
|
|
249
283
|
|
|
@@ -253,7 +287,14 @@ function SignInSteps({
|
|
|
253
287
|
{login.userCode}
|
|
254
288
|
</Text>
|
|
255
289
|
<Row start>
|
|
256
|
-
<Button
|
|
290
|
+
<Button
|
|
291
|
+
theme={theme}
|
|
292
|
+
icon="Copy"
|
|
293
|
+
label="Copy code"
|
|
294
|
+
tooltip="Copy the code to enter on the sign-in page"
|
|
295
|
+
tooltipAlign="start"
|
|
296
|
+
onPress={() => void copy(login.userCode ?? "", "Code")}
|
|
297
|
+
/>
|
|
257
298
|
</Row>
|
|
258
299
|
<Text style={text.small}>
|
|
259
300
|
If the page says code sign-in is off, turn on device code sign-in in ChatGPT → Settings → Security (or ask
|
|
@@ -281,6 +322,8 @@ function SignInSteps({
|
|
|
281
322
|
theme={theme}
|
|
282
323
|
tone="primary"
|
|
283
324
|
label="Continue"
|
|
325
|
+
tooltip="Finish signing in with the pasted code"
|
|
326
|
+
tooltipAlign="start"
|
|
284
327
|
busy={submitting}
|
|
285
328
|
disabled={!code.trim()}
|
|
286
329
|
onPress={() => void submit()}
|
package/client/commands.ts
CHANGED
|
@@ -46,6 +46,7 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
|
|
|
46
46
|
throw new Error(`No ${FAMILY_LABEL[family]} account matches "${query}". Accounts: ${names || "none"}.`);
|
|
47
47
|
}
|
|
48
48
|
if (match.status === "signed_out") throw new Error(`${match.label} is signed out. Sign it in from Accounts first.`);
|
|
49
|
+
if (match.status === "disabled") throw new Error(`${match.label} is disabled. Enable it in Accounts first.`);
|
|
49
50
|
await store.rpc(setAgentAccount, { agentId: agent.id, accountId: match.id });
|
|
50
51
|
},
|
|
51
52
|
}),
|
|
@@ -63,7 +64,7 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
|
|
|
63
64
|
dynamic = [];
|
|
64
65
|
if (!state) return;
|
|
65
66
|
state.accounts.forEach((account, index) => {
|
|
66
|
-
if (account.isDefault || account.status === "signed_out") return;
|
|
67
|
+
if (account.isDefault || account.status === "signed_out" || account.status === "disabled") return;
|
|
67
68
|
dynamic.push(
|
|
68
69
|
client.addCommandCenterItem({
|
|
69
70
|
id: `default-${index}`,
|
package/client/fork-confirm.tsx
CHANGED
|
@@ -41,12 +41,14 @@ export function forkPopover(store: ZeroSubStore, agentId: string, from: Family,
|
|
|
41
41
|
</Text>
|
|
42
42
|
{error ? <Text style={text.danger}>{error}</Text> : null}
|
|
43
43
|
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8, justifyContent: "flex-end" }}>
|
|
44
|
-
<Button theme={theme} label="Not now" onPress={close} disabled={busy} />
|
|
44
|
+
<Button theme={theme} label="Not now" tooltip="Close without starting a new agent" tooltipAlign="end" onPress={close} disabled={busy} />
|
|
45
45
|
<Button
|
|
46
46
|
theme={theme}
|
|
47
47
|
tone="primary"
|
|
48
48
|
icon="GitFork"
|
|
49
49
|
label={`Continue on ${FAMILY_LABEL[to]}`}
|
|
50
|
+
tooltip={`Start a new ${FAMILY_LABEL[to]} agent with this conversation so far`}
|
|
51
|
+
tooltipAlign="end"
|
|
50
52
|
busy={busy}
|
|
51
53
|
onPress={() => void start()}
|
|
52
54
|
/>
|
package/client/pills.ts
CHANGED
|
@@ -161,7 +161,7 @@ function buttonFor(
|
|
|
161
161
|
const other: Family = family === "claude" ? "codex" : "claude";
|
|
162
162
|
const offerFork =
|
|
163
163
|
current.status === "limited" &&
|
|
164
|
-
accounts.every((account) => account.status === "limited" || account.status === "signed_out") &&
|
|
164
|
+
accounts.every((account) => account.status === "limited" || account.status === "signed_out" || account.status === "disabled") &&
|
|
165
165
|
state.accounts.some((account) => account.family === other && account.status === "ready");
|
|
166
166
|
if (accounts.length < 2 && !(current.status === "limited" && (offerReset || offerFork))) return null;
|
|
167
167
|
|
|
@@ -176,7 +176,7 @@ function buttonFor(
|
|
|
176
176
|
id: `account-${index}`,
|
|
177
177
|
title: account.id === current.id || movable ? menuTitle(account) : `Continue on ${account.label} (new agent)`,
|
|
178
178
|
icon: account.id === current.id ? "CircleCheck" : movable ? "Circle" : "CopyPlus",
|
|
179
|
-
disabled: account.status === "signed_out" || account.id === current.id,
|
|
179
|
+
disabled: account.status === "signed_out" || account.status === "disabled" || account.id === current.id,
|
|
180
180
|
behavior: { kind: "action", onPress: choose(account.id) },
|
|
181
181
|
}));
|
|
182
182
|
// When the agent is stuck on a limit, a way out is the most useful thing in the menu.
|
|
@@ -237,6 +237,7 @@ function buttonFor(
|
|
|
237
237
|
|
|
238
238
|
function menuTitle(account: AccountView): string {
|
|
239
239
|
if (account.status === "signed_out") return `${account.label} — signed out`;
|
|
240
|
+
if (account.status === "disabled") return `${account.label} — disabled`;
|
|
240
241
|
if (account.status === "limited") return `${account.label} — limit reached`;
|
|
241
242
|
const peak = account.usage ? peakUsage(account.usage.windows) : null;
|
|
242
243
|
return peak ? `${account.label} — ${formatPercent(peak.usedPercent)} used` : account.label;
|
package/client/reset-confirm.tsx
CHANGED
|
@@ -73,7 +73,7 @@ export function ResetConfirm({
|
|
|
73
73
|
return (
|
|
74
74
|
<View style={{ gap: 12 }}>
|
|
75
75
|
<Text style={text.body}>{account.label} has no banked resets right now.</Text>
|
|
76
|
-
<Button theme={theme} label="Close" onPress={onCancel} />
|
|
76
|
+
<Button theme={theme} label="Close" tooltip="Close this window" tooltipAlign="end" onPress={onCancel} />
|
|
77
77
|
</View>
|
|
78
78
|
);
|
|
79
79
|
}
|
|
@@ -87,12 +87,14 @@ export function ResetConfirm({
|
|
|
87
87
|
{resets.blockedReason ? <Text style={text.warning}>{resets.blockedReason}</Text> : null}
|
|
88
88
|
{error ? <Text style={text.danger}>{error}</Text> : null}
|
|
89
89
|
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8, justifyContent: "flex-end" }}>
|
|
90
|
-
<Button theme={theme} label="No, keep it" onPress={onCancel} disabled={busy} />
|
|
90
|
+
<Button theme={theme} label="No, keep it" tooltip="Keep the reset for later" tooltipAlign="end" onPress={onCancel} disabled={busy} />
|
|
91
91
|
<Button
|
|
92
92
|
theme={theme}
|
|
93
93
|
tone="primary"
|
|
94
94
|
icon="TimerReset"
|
|
95
95
|
label="Yes, use my reset"
|
|
96
|
+
tooltip="Spend one banked reset now; it can't be undone"
|
|
97
|
+
tooltipAlign="end"
|
|
96
98
|
busy={busy}
|
|
97
99
|
disabled={!resets.usableNow}
|
|
98
100
|
onPress={() => void confirm()}
|
package/client/switch-row.tsx
CHANGED
|
@@ -15,6 +15,10 @@ function cause(row: SwitchRow): string | null {
|
|
|
15
15
|
return `${from} is signed out — sign it in again from Accounts.`;
|
|
16
16
|
case "removed":
|
|
17
17
|
return `${from} was removed.`;
|
|
18
|
+
case "disabled":
|
|
19
|
+
return `${from} was disabled for now.`;
|
|
20
|
+
case "enabled":
|
|
21
|
+
return `${row.to} is enabled again.`;
|
|
18
22
|
case "default":
|
|
19
23
|
return "The default account changed.";
|
|
20
24
|
default:
|
|
@@ -59,7 +63,8 @@ export function describeRow(row: SwitchRow): string {
|
|
|
59
63
|
case "pending":
|
|
60
64
|
return `${lead}Moves to ${row.to} when its session next starts.`;
|
|
61
65
|
default: {
|
|
62
|
-
const from =
|
|
66
|
+
const from =
|
|
67
|
+
row.from && row.reason !== "limit" && row.reason !== "signed_out" && row.reason !== "disabled" ? `from ${row.from} ` : "";
|
|
63
68
|
return `${lead}Switched ${from}to ${row.to}${row.continued ? " and carried on" : ""}.`;
|
|
64
69
|
}
|
|
65
70
|
}
|
package/client/ui.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PluginHostProps } from "@getpaseo/plugin/client";
|
|
2
2
|
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
-
import { useMemo, type ReactNode } from "react";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
4
4
|
import { ActivityIndicator, Pressable, Text, View } from "react-native";
|
|
5
5
|
import { formatPercent, formatResetIn } from "../shared/format";
|
|
6
6
|
import type { UsageWindow } from "../shared/model";
|
|
@@ -9,6 +9,75 @@ type Theme = PluginHostProps["theme"];
|
|
|
9
9
|
|
|
10
10
|
export type ButtonTone = "primary" | "secondary" | "danger" | "ghost";
|
|
11
11
|
|
|
12
|
+
/** How a tooltip lines up with its control. `end` keeps a right-hand control's tip out of the next card. */
|
|
13
|
+
export type TooltipAlign = "start" | "center" | "end";
|
|
14
|
+
|
|
15
|
+
const TOOLTIP_HOVER_MS = 350;
|
|
16
|
+
const TOOLTIP_TOUCH_MS = 1_800;
|
|
17
|
+
const TOOLTIP_WIDTH = 240;
|
|
18
|
+
|
|
19
|
+
/** Hover (desktop, web) or long-press (touch) shows a short hint; pressing hides it. */
|
|
20
|
+
function useTooltip(text: string | undefined) {
|
|
21
|
+
const [visible, setVisible] = useState(false);
|
|
22
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
23
|
+
const clear = useCallback(() => {
|
|
24
|
+
if (timer.current) clearTimeout(timer.current);
|
|
25
|
+
timer.current = null;
|
|
26
|
+
}, []);
|
|
27
|
+
useEffect(() => clear, [clear]);
|
|
28
|
+
const show = useCallback(
|
|
29
|
+
(delay: number, hideAfter?: number) => {
|
|
30
|
+
clear();
|
|
31
|
+
timer.current = setTimeout(() => {
|
|
32
|
+
setVisible(true);
|
|
33
|
+
if (hideAfter) timer.current = setTimeout(() => setVisible(false), hideAfter);
|
|
34
|
+
}, delay);
|
|
35
|
+
},
|
|
36
|
+
[clear],
|
|
37
|
+
);
|
|
38
|
+
const hide = useCallback(() => {
|
|
39
|
+
clear();
|
|
40
|
+
setVisible(false);
|
|
41
|
+
}, [clear]);
|
|
42
|
+
if (!text) return { visible: false, handlers: {} };
|
|
43
|
+
return {
|
|
44
|
+
visible,
|
|
45
|
+
handlers: {
|
|
46
|
+
onHoverIn: () => show(TOOLTIP_HOVER_MS),
|
|
47
|
+
onHoverOut: hide,
|
|
48
|
+
onPressIn: hide,
|
|
49
|
+
onLongPress: () => show(0, TOOLTIP_TOUCH_MS),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function TooltipBubble({
|
|
55
|
+
theme,
|
|
56
|
+
text,
|
|
57
|
+
placement,
|
|
58
|
+
align,
|
|
59
|
+
}: {
|
|
60
|
+
theme: Theme;
|
|
61
|
+
text: string;
|
|
62
|
+
placement: "top" | "bottom";
|
|
63
|
+
align: TooltipAlign;
|
|
64
|
+
}) {
|
|
65
|
+
const vertical = placement === "top" ? { bottom: "100%" as const, marginBottom: 6 } : { top: "100%" as const, marginTop: 6 };
|
|
66
|
+
const horizontal =
|
|
67
|
+
align === "end"
|
|
68
|
+
? { right: 0, alignItems: "flex-end" as const }
|
|
69
|
+
: align === "start"
|
|
70
|
+
? { left: 0, alignItems: "flex-start" as const }
|
|
71
|
+
: { left: "50%" as const, marginLeft: -TOOLTIP_WIDTH / 2, alignItems: "center" as const };
|
|
72
|
+
return (
|
|
73
|
+
<View pointerEvents="none" style={{ position: "absolute", width: TOOLTIP_WIDTH, zIndex: 1000, ...vertical, ...horizontal }}>
|
|
74
|
+
<View style={{ paddingHorizontal: 8, paddingVertical: 5, borderRadius: 6, backgroundColor: theme.colors.foreground }}>
|
|
75
|
+
<Text style={{ color: theme.colors.surface0, fontSize: 12, lineHeight: 16 }}>{text}</Text>
|
|
76
|
+
</View>
|
|
77
|
+
</View>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
12
81
|
export function Button({
|
|
13
82
|
theme,
|
|
14
83
|
label,
|
|
@@ -19,6 +88,9 @@ export function Button({
|
|
|
19
88
|
disabled,
|
|
20
89
|
busy,
|
|
21
90
|
accessibilityLabel,
|
|
91
|
+
tooltip,
|
|
92
|
+
tooltipAlign = "center",
|
|
93
|
+
tooltipPlacement = "top",
|
|
22
94
|
}: {
|
|
23
95
|
theme: Theme;
|
|
24
96
|
label: string;
|
|
@@ -30,8 +102,13 @@ export function Button({
|
|
|
30
102
|
disabled?: boolean;
|
|
31
103
|
busy?: boolean;
|
|
32
104
|
accessibilityLabel?: string;
|
|
105
|
+
/** A short explanation shown on hover or long-press. */
|
|
106
|
+
tooltip?: string;
|
|
107
|
+
tooltipAlign?: TooltipAlign;
|
|
108
|
+
tooltipPlacement?: "top" | "bottom";
|
|
33
109
|
}) {
|
|
34
110
|
const small = size === "small";
|
|
111
|
+
const tip = useTooltip(tooltip);
|
|
35
112
|
const colors = theme.colors;
|
|
36
113
|
const palette = {
|
|
37
114
|
primary: { background: colors.accent, foreground: colors.accentForeground, border: colors.accent },
|
|
@@ -41,33 +118,38 @@ export function Button({
|
|
|
41
118
|
}[tone];
|
|
42
119
|
const inactive = disabled || busy;
|
|
43
120
|
return (
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
121
|
+
<View style={{ position: "relative", zIndex: tip.visible ? 1000 : undefined }}>
|
|
122
|
+
<Pressable
|
|
123
|
+
accessibilityRole="button"
|
|
124
|
+
accessibilityLabel={accessibilityLabel ?? label}
|
|
125
|
+
accessibilityHint={tooltip}
|
|
126
|
+
accessibilityState={{ disabled: Boolean(inactive), busy: Boolean(busy) }}
|
|
127
|
+
disabled={inactive}
|
|
128
|
+
onPress={onPress}
|
|
129
|
+
{...tip.handlers}
|
|
130
|
+
style={({ pressed }) => ({
|
|
131
|
+
flexDirection: "row",
|
|
132
|
+
alignItems: "center",
|
|
133
|
+
justifyContent: "center",
|
|
134
|
+
gap: small ? 5 : 6,
|
|
135
|
+
paddingHorizontal: small ? 10 : 12,
|
|
136
|
+
paddingVertical: small ? 5 : 8,
|
|
137
|
+
borderRadius: small ? 7 : 8,
|
|
138
|
+
borderWidth: 1,
|
|
139
|
+
borderColor: palette.border,
|
|
140
|
+
backgroundColor: palette.background,
|
|
141
|
+
opacity: inactive ? 0.55 : pressed ? 0.8 : 1,
|
|
142
|
+
})}
|
|
143
|
+
>
|
|
144
|
+
{busy ? (
|
|
145
|
+
<ActivityIndicator size="small" color={palette.foreground} />
|
|
146
|
+
) : icon ? (
|
|
147
|
+
<Icon name={icon} size={small ? 13 : 15} color={palette.foreground} />
|
|
148
|
+
) : null}
|
|
149
|
+
<Text style={{ color: palette.foreground, fontSize: small ? 12 : 13, fontWeight: "600" }}>{label}</Text>
|
|
150
|
+
</Pressable>
|
|
151
|
+
{tip.visible && tooltip ? <TooltipBubble theme={theme} text={tooltip} placement={tooltipPlacement} align={tooltipAlign} /> : null}
|
|
152
|
+
</View>
|
|
71
153
|
);
|
|
72
154
|
}
|
|
73
155
|
|
|
@@ -79,6 +161,9 @@ export function IconButton({
|
|
|
79
161
|
onPress,
|
|
80
162
|
disabled,
|
|
81
163
|
busy,
|
|
164
|
+
tooltip,
|
|
165
|
+
tooltipAlign = "end",
|
|
166
|
+
tooltipPlacement = "top",
|
|
82
167
|
}: {
|
|
83
168
|
theme: Theme;
|
|
84
169
|
icon: string;
|
|
@@ -87,44 +172,55 @@ export function IconButton({
|
|
|
87
172
|
onPress(): void;
|
|
88
173
|
disabled?: boolean;
|
|
89
174
|
busy?: boolean;
|
|
175
|
+
/** Shown on hover or long-press; an icon alone never says enough, so it falls back to `label`. */
|
|
176
|
+
tooltip?: string;
|
|
177
|
+
tooltipAlign?: TooltipAlign;
|
|
178
|
+
tooltipPlacement?: "top" | "bottom";
|
|
90
179
|
}) {
|
|
91
180
|
const colors = theme.colors;
|
|
92
181
|
const inactive = disabled || busy;
|
|
182
|
+
const hint = tooltip ?? label;
|
|
183
|
+
const tip = useTooltip(hint);
|
|
93
184
|
return (
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
185
|
+
<View style={{ position: "relative", zIndex: tip.visible ? 1000 : undefined }}>
|
|
186
|
+
<Pressable
|
|
187
|
+
accessibilityRole="button"
|
|
188
|
+
accessibilityLabel={label}
|
|
189
|
+
accessibilityHint={tooltip}
|
|
190
|
+
accessibilityState={{ disabled: Boolean(inactive), busy: Boolean(busy) }}
|
|
191
|
+
disabled={inactive}
|
|
192
|
+
onPress={onPress}
|
|
193
|
+
hitSlop={4}
|
|
194
|
+
{...tip.handlers}
|
|
195
|
+
style={(state) => {
|
|
196
|
+
const active = state.pressed || (state as { hovered?: boolean }).hovered;
|
|
197
|
+
return {
|
|
198
|
+
width: 30,
|
|
199
|
+
height: 30,
|
|
200
|
+
borderRadius: 8,
|
|
201
|
+
alignItems: "center",
|
|
202
|
+
justifyContent: "center",
|
|
203
|
+
backgroundColor: active ? colors.surface2 : "transparent",
|
|
204
|
+
opacity: inactive ? 0.45 : 1,
|
|
205
|
+
};
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
208
|
+
{({ pressed, hovered }: { pressed: boolean; hovered?: boolean }) =>
|
|
209
|
+
busy ? (
|
|
210
|
+
<ActivityIndicator size="small" color={colors.foregroundMuted} />
|
|
211
|
+
) : (
|
|
212
|
+
<Icon
|
|
213
|
+
name={icon}
|
|
214
|
+
size={15}
|
|
215
|
+
color={
|
|
216
|
+
tone === "danger" && (pressed || hovered) ? colors.statusDanger : colors.foregroundMuted
|
|
217
|
+
}
|
|
218
|
+
/>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
</Pressable>
|
|
222
|
+
{tip.visible ? <TooltipBubble theme={theme} text={hint} placement={tooltipPlacement} align={tooltipAlign} /> : null}
|
|
223
|
+
</View>
|
|
128
224
|
);
|
|
129
225
|
}
|
|
130
226
|
|
package/index.server.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
renameAccount,
|
|
13
13
|
setAgentAccount,
|
|
14
14
|
setDefaultAccount,
|
|
15
|
+
setAccountEnabled,
|
|
15
16
|
forkAgent,
|
|
16
17
|
startLogin,
|
|
17
18
|
submitLoginCode,
|
|
@@ -83,6 +84,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
83
84
|
server.handle(redeemReset, ({ accountId, agentId }, { paseo }) => service.redeem(paseo, accountId, agentId));
|
|
84
85
|
server.handle(setAgentAccount, ({ agentId, accountId }, { paseo }) => service.setAgentAccount(paseo, agentId, accountId));
|
|
85
86
|
server.handle(forkAgent, ({ agentId }, { paseo }) => service.forkAgent(paseo, agentId));
|
|
87
|
+
server.handle(setAccountEnabled, ({ accountId, enabled }, { paseo }) => service.setAccountEnabled(paseo, accountId, enabled));
|
|
86
88
|
|
|
87
89
|
return async () => {
|
|
88
90
|
stopSettings();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kapybara/zerosub",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
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/paseo-plugin.json
CHANGED
package/server/adapter.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PluginTurnOutcome } from "@getpaseo/plugin/server";
|
|
1
|
+
import type { PluginLifecycleEvents, PluginTurnOutcome } from "@getpaseo/plugin/server";
|
|
3
2
|
import type { Family, LoginMethod, LoginStep, Usage } from "../shared/model";
|
|
4
3
|
import type { RedeemOutcome } from "../shared/rpc";
|
|
5
4
|
|
|
5
|
+
/**
|
|
6
|
+
* One timeline entry. Taken from the SDK rather than `@getpaseo/protocol`: Paseo only supplies
|
|
7
|
+
* `@getpaseo/plugin` to plugins, and an npm install has no devDependencies to resolve it from.
|
|
8
|
+
*/
|
|
9
|
+
export type AgentTimelineItem = PluginLifecycleEvents["agent.turn_ended"]["timeline"][number];
|
|
10
|
+
|
|
6
11
|
/** A provider's answer to a redeem request. */
|
|
7
12
|
export interface RedeemReply {
|
|
8
13
|
outcome: RedeemOutcome;
|
|
@@ -35,6 +40,14 @@ export interface LimitHit {
|
|
|
35
40
|
message: string;
|
|
36
41
|
}
|
|
37
42
|
|
|
43
|
+
/** A finished turn, as Paseo reports it. */
|
|
44
|
+
export interface TurnEvent {
|
|
45
|
+
outcome: PluginTurnOutcome;
|
|
46
|
+
timeline: readonly AgentTimelineItem[];
|
|
47
|
+
/** Paseo's id for the turn; `null` when the turn failed before it started. */
|
|
48
|
+
turnId?: string | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
export interface LoginProgress {
|
|
39
52
|
step: LoginStep;
|
|
40
53
|
/** Link that finishes by itself when opened on the daemon machine (localhost callback), or the device-code page. */
|
|
@@ -88,9 +101,9 @@ export interface FamilyAdapter {
|
|
|
88
101
|
login(home: string | null, method: LoginMethod): Promise<LoginHandle>;
|
|
89
102
|
logout(home: string): Promise<void>;
|
|
90
103
|
/** Looks for a subscription usage-limit failure in a finished turn. */
|
|
91
|
-
detectLimit(event:
|
|
104
|
+
detectLimit(event: TurnEvent): LimitHit | null;
|
|
92
105
|
/** Looks for a turn that failed because the account's login is no longer valid. */
|
|
93
|
-
detectSignOut(event:
|
|
106
|
+
detectSignOut(event: TurnEvent): string | null;
|
|
94
107
|
}
|
|
95
108
|
|
|
96
109
|
/** The environment for a process ZeroSub spawns against `patch`. */
|
package/server/codex.ts
CHANGED
|
@@ -57,7 +57,7 @@ class AppServer {
|
|
|
57
57
|
try {
|
|
58
58
|
await server.request(
|
|
59
59
|
"initialize",
|
|
60
|
-
{ clientInfo: { name: CLIENT_NAME, title: "Paseo ZeroSub", version: "1.
|
|
60
|
+
{ clientInfo: { name: CLIENT_NAME, title: "Paseo ZeroSub", version: "1.2.1" }, capabilities: { experimentalApi: false } },
|
|
61
61
|
60_000,
|
|
62
62
|
);
|
|
63
63
|
server.send({ method: "initialized" });
|
package/server/handoff.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import type { AgentTimelineItem } from "@getpaseo/protocol/agent-types";
|
|
3
2
|
import type { PluginHookContext } from "@getpaseo/plugin/server";
|
|
3
|
+
import type { AgentTimelineItem } from "./adapter";
|
|
4
4
|
|
|
5
5
|
type PaseoApi = PluginHookContext["paseo"];
|
|
6
6
|
|
package/server/limits.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PluginTurnOutcome } from "@getpaseo/plugin/server";
|
|
3
|
-
import type { LimitHit, LimitKind } from "./adapter";
|
|
4
|
-
|
|
5
|
-
type TurnEvent = { outcome: PluginTurnOutcome; timeline: readonly AgentTimelineItem[] };
|
|
1
|
+
import type { LimitHit, LimitKind, TurnEvent } from "./adapter";
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Claude Code's exact wording for hard limits (2.1.x templates: `You've hit your ${limit}${suffix}`),
|
|
@@ -56,14 +52,17 @@ function clean(text: string): string {
|
|
|
56
52
|
/**
|
|
57
53
|
* Where a CLI-generated notice can appear in a finished turn: the failure message, error items,
|
|
58
54
|
* Paseo's `[System Error]` rows, and — for Claude, which reports limits as a synthetic reply — the
|
|
59
|
-
* final assistant messages. Ordinary replies earlier in the turn are never inspected.
|
|
55
|
+
* final assistant messages. Ordinary replies earlier in the turn are never inspected. A turn that
|
|
56
|
+
* failed before it started has only its failure: Paseo never recorded its message, so the timeline
|
|
57
|
+
* still ends with the previous turn.
|
|
60
58
|
*/
|
|
61
59
|
function notices(event: TurnEvent, includeFinalReplies: boolean): string[] {
|
|
62
60
|
const found: string[] = [];
|
|
63
61
|
if (event.outcome.kind === "failed") found.push(event.outcome.error.message);
|
|
62
|
+
const timeline = event.turnId === null ? [] : event.timeline;
|
|
64
63
|
let replies = 0;
|
|
65
|
-
for (let index =
|
|
66
|
-
const item =
|
|
64
|
+
for (let index = timeline.length - 1; index >= 0; index -= 1) {
|
|
65
|
+
const item = timeline[index];
|
|
67
66
|
if (!item) continue;
|
|
68
67
|
if (item.type === "user_message") break;
|
|
69
68
|
if (item.type === "error") found.push(item.message);
|
|
@@ -115,13 +114,15 @@ const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "
|
|
|
115
114
|
|
|
116
115
|
/**
|
|
117
116
|
* "· resets 3pm (Asia/Kolkata)", "· resets 3:30pm (America/New_York)",
|
|
118
|
-
* "· resets Sep 25, 3pm (Europe/Berlin)"
|
|
117
|
+
* "· resets Sep 25, 3pm (Europe/Berlin)" ("Sep 25 at 3pm" where the CLI's ICU is newer), or the
|
|
118
|
+
* legacy "|1790150000" epoch. A reset in the next calendar year also carries the year
|
|
119
|
+
* ("Jan 2, 2027"), which rolling the date forward already gives.
|
|
119
120
|
*/
|
|
120
121
|
export function parseClaudeReset(text: string, now: Date): string | null {
|
|
121
122
|
const epoch = text.match(/usage limit reached\|(\d{9,})/i);
|
|
122
123
|
if (epoch?.[1]) return new Date(Number(epoch[1]) * 1000).toISOString();
|
|
123
124
|
const match = text.match(
|
|
124
|
-
/resets\s+(?:([A-Za-z]{3})[a-z]*\.?\s+(\d{1,2})
|
|
125
|
+
/resets\s+(?:([A-Za-z]{3})[a-z]*\.?\s+(\d{1,2})(?:,?\s+\d{4})?,?\s+(?:at\s+)?)?(\d{1,2})(?::(\d{2}))?\s*([ap])\.?m\.?(?:\s*\(([^)]+)\))?/i,
|
|
125
126
|
);
|
|
126
127
|
if (!match) return null;
|
|
127
128
|
const [, monthName, dayText, hourText, minuteText, meridiem, zone] = match;
|
package/server/reopen.ts
CHANGED
|
@@ -22,9 +22,10 @@ export class Reopener {
|
|
|
22
22
|
return this.cli.path;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/** `timedOut`: the command was stopped before the daemon answered, so the reload may still finish. */
|
|
26
|
+
async reopen(agentId: string): Promise<{ ok: true } | { ok: false; error: string; timedOut: boolean }> {
|
|
26
27
|
const cli = await this.locate();
|
|
27
|
-
if (!cli) return { ok: false, error: "The paseo command-line tool was not found on the daemon machine." };
|
|
28
|
+
if (!cli) return { ok: false, error: "The paseo command-line tool was not found on the daemon machine.", timedOut: false };
|
|
28
29
|
return new Promise((resolve) => {
|
|
29
30
|
execFile(
|
|
30
31
|
cli,
|
|
@@ -33,7 +34,7 @@ export class Reopener {
|
|
|
33
34
|
(error, _stdout, stderr) => {
|
|
34
35
|
if (!error) return resolve({ ok: true });
|
|
35
36
|
const detail = `${stderr || error.message}`.trim().split("\n").slice(-3).join(" ");
|
|
36
|
-
resolve({ ok: false, error: explainFailure(detail) });
|
|
37
|
+
resolve({ ok: false, error: explainFailure(detail), timedOut: error.killed === true });
|
|
37
38
|
},
|
|
38
39
|
);
|
|
39
40
|
});
|
package/server/routing.ts
CHANGED
|
@@ -17,7 +17,7 @@ export function isLimited(account: StoredAccount, now: number): boolean {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function isUsable(account: StoredAccount, now: number): boolean {
|
|
20
|
-
return account.signedIn && !isLimited(account, now);
|
|
20
|
+
return account.signedIn && !account.disabled && !isLimited(account, now);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/** Lower is better. Unknown usage ranks in the middle so a known-quiet account wins over a mystery. */
|
|
@@ -76,14 +76,15 @@ export interface RouteDecision {
|
|
|
76
76
|
/** A binding to persist so the agent stays where it was routed. */
|
|
77
77
|
bind: Binding | null;
|
|
78
78
|
/** Why the preferred account was skipped, if it was. */
|
|
79
|
-
skipped: { account: StoredAccount; why: "limited" | "signed_out" } | null;
|
|
79
|
+
skipped: { account: StoredAccount; why: "limited" | "signed_out" | "disabled" } | null;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Which account a session opens on: the agent's own binding, else (for balanced new agents) the
|
|
84
84
|
* roomiest account, else the default. An exhausted or signed-out choice is swapped for the roomiest
|
|
85
85
|
* usable account when automatic switching is on — for new agents always, and for existing ones
|
|
86
|
-
* only when their conversation can move between accounts.
|
|
86
|
+
* only when their conversation can move between accounts. A disabled choice is always swapped,
|
|
87
|
+
* and the agent keeps its own binding so it returns once the account is enabled again.
|
|
87
88
|
*/
|
|
88
89
|
export function chooseAccount(state: StoredState, input: RouteInput): RouteDecision | null {
|
|
89
90
|
const accounts = accountsOf(state, input.family);
|
|
@@ -110,14 +111,21 @@ export function chooseAccount(state: StoredState, input: RouteInput): RouteDecis
|
|
|
110
111
|
if (!account) return null;
|
|
111
112
|
|
|
112
113
|
let skipped: RouteDecision["skipped"] = null;
|
|
113
|
-
const why = !account.signedIn ? "signed_out" : isLimited(account, input.now) ? "limited" : null;
|
|
114
|
+
const why = !account.signedIn ? "signed_out" : account.disabled ? "disabled" : isLimited(account, input.now) ? "limited" : null;
|
|
114
115
|
const mayMove = fresh || input.portable;
|
|
115
|
-
if (why && mayMove && (input.autoSwitch || why
|
|
116
|
+
if (why && mayMove && (input.autoSwitch || why !== "limited")) {
|
|
116
117
|
const alternative = mostAvailable(state, input.family, input.usageOf, input.now, new Set([account.id]));
|
|
117
118
|
if (alternative) {
|
|
118
119
|
skipped = { account, why };
|
|
119
120
|
account = alternative;
|
|
120
|
-
|
|
121
|
+
// A thread that can't move lives where it starts. Otherwise a disabled account keeps its
|
|
122
|
+
// agents' bindings, so they return when it's enabled again; a limit re-pins them.
|
|
123
|
+
bind =
|
|
124
|
+
!input.portable
|
|
125
|
+
? { accountId: alternative.id, source: "thread", at }
|
|
126
|
+
: why === "disabled"
|
|
127
|
+
? null
|
|
128
|
+
: { accountId: alternative.id, source: "auto", at };
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
131
|
return { account, bind, skipped };
|
package/server/service.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { readdir } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import type { AgentTimelineItem } from "@getpaseo/protocol/agent-types";
|
|
5
4
|
import type {
|
|
6
5
|
PluginHookContext,
|
|
7
6
|
PluginLifecycleEvents,
|
|
@@ -22,6 +21,7 @@ import type { RedeemResult, ReopenSummary } from "../shared/rpc";
|
|
|
22
21
|
import { SWITCH_ROW_KIND, SWITCH_ROW_VERSION, type SwitchRow } from "../shared/timeline";
|
|
23
22
|
import {
|
|
24
23
|
applyEnv,
|
|
24
|
+
type AgentTimelineItem,
|
|
25
25
|
type FamilyAdapter,
|
|
26
26
|
type Identity,
|
|
27
27
|
type LimitHit,
|
|
@@ -230,7 +230,7 @@ export class Service {
|
|
|
230
230
|
const attempted = this.usageAttemptAt.get(account.id) ?? 0;
|
|
231
231
|
const busy = now - (this.activeAt.get(account.id) ?? 0) < ACTIVE_WINDOW_MS;
|
|
232
232
|
const isDefault = defaultAccount(state, account.family)?.id === account.id;
|
|
233
|
-
const every = busy ? USAGE_BUSY_MS : isDefault ? USAGE_DEFAULT_MS : USAGE_IDLE_MS;
|
|
233
|
+
const every = account.disabled ? USAGE_IDLE_MS : busy ? USAGE_BUSY_MS : isDefault ? USAGE_DEFAULT_MS : USAGE_IDLE_MS;
|
|
234
234
|
if (account.signedIn && now - attempted > every) {
|
|
235
235
|
void this.refreshUsage(account.id).catch((error: unknown) => log(`usage refresh for ${account.label} failed`, error));
|
|
236
236
|
}
|
|
@@ -555,7 +555,7 @@ export class Service {
|
|
|
555
555
|
}
|
|
556
556
|
const next = mostAvailable(latest, family, (id) => this.usage.get(id), now, new Set([account.id]));
|
|
557
557
|
if (!next) {
|
|
558
|
-
if (problem.kind === "limit" && problem.hit.kind === "window" && this.prefs.autoRedeem) {
|
|
558
|
+
if (problem.kind === "limit" && problem.hit.kind === "window" && this.prefs.autoRedeem && !account.disabled) {
|
|
559
559
|
// Opt-in: every account is out, so spend a banked reset rather than stop.
|
|
560
560
|
const reply = await this.redeemOn(account, true);
|
|
561
561
|
if (reply.outcome === "reset") {
|
|
@@ -1049,9 +1049,20 @@ export class Service {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
return "closed";
|
|
1051
1051
|
}
|
|
1052
|
+
const before = (await this.store.read()).sessions[agentId];
|
|
1052
1053
|
const result = await this.reopener.reopen(agentId);
|
|
1053
1054
|
if (!result.ok) {
|
|
1054
1055
|
console.warn(`[ZeroSub] could not reopen ${agentId}: ${result.error}`);
|
|
1056
|
+
// Paseo asks for the new session's environment before it closes the old one, so a failed reload
|
|
1057
|
+
// has still recorded a session that never opened. One that ran out of time may yet open.
|
|
1058
|
+
if (!result.timedOut) {
|
|
1059
|
+
await this.store.update((draft) => {
|
|
1060
|
+
const recorded = draft.sessions[agentId];
|
|
1061
|
+
if (!recorded || recorded.openedAt === before?.openedAt) return;
|
|
1062
|
+
if (before) draft.sessions[agentId] = before;
|
|
1063
|
+
else delete draft.sessions[agentId];
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1055
1066
|
return "failed";
|
|
1056
1067
|
}
|
|
1057
1068
|
return "reopened";
|
|
@@ -1219,7 +1230,7 @@ export class Service {
|
|
|
1219
1230
|
email: account.email,
|
|
1220
1231
|
plan: account.plan,
|
|
1221
1232
|
organization: account.organization,
|
|
1222
|
-
status: !account.signedIn ? "signed_out" : limited ? "limited" : "ready",
|
|
1233
|
+
status: !account.signedIn ? "signed_out" : account.disabled ? "disabled" : limited ? "limited" : "ready",
|
|
1223
1234
|
isDefault: defaultAccount(state, account.family)?.id === account.id,
|
|
1224
1235
|
limitedUntil: limited ? account.limitedUntil : null,
|
|
1225
1236
|
usage: this.usage.get(account.id) ?? null,
|
|
@@ -1291,6 +1302,7 @@ export class Service {
|
|
|
1291
1302
|
const account = findAccount(await this.store.read(), accountId);
|
|
1292
1303
|
if (!account) throw new Error("That account no longer exists.");
|
|
1293
1304
|
if (!account.signedIn) throw new Error(`${account.label} is signed out. Sign it in first.`);
|
|
1305
|
+
if (account.disabled) throw new Error(`${account.label} is disabled. Enable it before making it the default.`);
|
|
1294
1306
|
if (!this.adapters[account.family].portable) await this.pinThreads(paseo, account.family);
|
|
1295
1307
|
await this.store.update((draft) => {
|
|
1296
1308
|
draft.defaults[account.family] = account.id;
|
|
@@ -1299,6 +1311,40 @@ export class Service {
|
|
|
1299
1311
|
return this.reconcile(paseo, "default");
|
|
1300
1312
|
}
|
|
1301
1313
|
|
|
1314
|
+
/**
|
|
1315
|
+
* Sets an account aside for a while, or brings it back. A disabled account stays signed in, but
|
|
1316
|
+
* nothing is routed to it: its agents move to the next account now (busy ones after their turn)
|
|
1317
|
+
* and return when it's enabled again. ChatGPT conversations can't change accounts, so the ones
|
|
1318
|
+
* already on it stay there; `stayed` counts them.
|
|
1319
|
+
*/
|
|
1320
|
+
async setAccountEnabled(paseo: PaseoApi, accountId: string, enabled: boolean): Promise<ReopenSummary & { stayed: number }> {
|
|
1321
|
+
this.attach(paseo);
|
|
1322
|
+
const state = await this.store.read();
|
|
1323
|
+
const account = findAccount(state, accountId);
|
|
1324
|
+
if (!account) throw new Error("That account no longer exists.");
|
|
1325
|
+
if (account.disabled === !enabled) return { ...emptySummary(), stayed: 0 };
|
|
1326
|
+
if (!enabled && !accountsOf(state, account.family).some((other) => other.id !== account.id && other.signedIn && !other.disabled)) {
|
|
1327
|
+
// With nothing else to route to, sessions would quietly fall back to the CLI login.
|
|
1328
|
+
throw new Error(`${account.label} is the only ${FAMILY_LABEL[account.family]} account in use. Add or enable another one first.`);
|
|
1329
|
+
}
|
|
1330
|
+
await this.store.update((draft) => {
|
|
1331
|
+
const target = findAccount(draft, accountId);
|
|
1332
|
+
if (target) target.disabled = !enabled;
|
|
1333
|
+
});
|
|
1334
|
+
console.log(`[ZeroSub] ${account.label} is ${enabled ? "enabled" : "disabled"}`);
|
|
1335
|
+
const summary = await this.reconcile(paseo, enabled ? "enabled" : "disabled");
|
|
1336
|
+
let stayed = 0;
|
|
1337
|
+
if (!enabled && !this.adapters[account.family].portable) {
|
|
1338
|
+
const families = await this.families.resolve(paseo);
|
|
1339
|
+
const latest = await this.store.read();
|
|
1340
|
+
stayed = (await listAgents(paseo, false)).agents.filter(
|
|
1341
|
+
(agent) =>
|
|
1342
|
+
families[agent.provider] === account.family && agent.hasHistory && this.targetFor(latest, agent.id, account.family) === accountId,
|
|
1343
|
+
).length;
|
|
1344
|
+
}
|
|
1345
|
+
return { ...summary, stayed };
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1302
1348
|
/**
|
|
1303
1349
|
* Pins every existing agent of a non-portable provider to the account it runs on now, before the
|
|
1304
1350
|
* default changes. Agents that haven't opened a session since ZeroSub was installed have no pin yet.
|
|
@@ -1342,6 +1388,7 @@ export class Service {
|
|
|
1342
1388
|
const target = accountId ? findAccount(state, accountId) : defaultAccount(state, family);
|
|
1343
1389
|
if (!target || target.family !== family) throw new Error("That account can't be used with this agent.");
|
|
1344
1390
|
if (!target.signedIn) throw new Error(`${target.label} is signed out. Sign it in first.`);
|
|
1391
|
+
if (accountId && target.disabled) throw new Error(`${target.label} is disabled. Enable it in Accounts first.`);
|
|
1345
1392
|
|
|
1346
1393
|
if (!adapter.portable) {
|
|
1347
1394
|
if (info.status === "running" || info.status === "initializing") {
|
|
@@ -1599,6 +1646,7 @@ function newAccount(fields: Pick<StoredAccount, "id" | "family" | "kind" | "home
|
|
|
1599
1646
|
organization: null,
|
|
1600
1647
|
identity: null,
|
|
1601
1648
|
signedIn: true,
|
|
1649
|
+
disabled: false,
|
|
1602
1650
|
limitedUntil: null,
|
|
1603
1651
|
limitKind: null,
|
|
1604
1652
|
limitedAt: null,
|
package/server/state.ts
CHANGED
|
@@ -19,6 +19,8 @@ export const StoredAccountSchema = z.object({
|
|
|
19
19
|
/** Stable identity used to spot the same account being added twice. */
|
|
20
20
|
identity: z.string().nullable().default(null),
|
|
21
21
|
signedIn: z.boolean().default(true),
|
|
22
|
+
/** Set aside by the user for a while: stays signed in, but nothing is routed to it. */
|
|
23
|
+
disabled: z.boolean().default(false),
|
|
22
24
|
limitedUntil: z.string().nullable().default(null),
|
|
23
25
|
/** What kind of limit `limitedUntil` records; only `window` limits clear from usage readings. */
|
|
24
26
|
limitKind: z.enum(["window", "budget"]).nullable().default(null),
|
package/shared/format.ts
CHANGED
|
@@ -87,6 +87,7 @@ export function formatAge(at: string, now: number = Date.now()): string {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export function usageSummary(account: AccountView, now: number = Date.now()): string | null {
|
|
90
|
+
if (account.status === "disabled") return "Disabled for now";
|
|
90
91
|
if (account.status === "limited") {
|
|
91
92
|
const reset = formatResetIn(account.limitedUntil, now);
|
|
92
93
|
return reset ? `Limit reached · resets ${reset}` : "Limit reached";
|
package/shared/model.ts
CHANGED
|
@@ -56,7 +56,8 @@ export const AccountKindSchema = z.enum([
|
|
|
56
56
|
]);
|
|
57
57
|
export type AccountKind = z.infer<typeof AccountKindSchema>;
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
/** `disabled`: the user set it aside for a while; it stays signed in but nothing is routed to it. */
|
|
60
|
+
export const AccountStatusSchema = z.enum(["ready", "signed_out", "limited", "checking", "disabled"]);
|
|
60
61
|
export type AccountStatus = z.infer<typeof AccountStatusSchema>;
|
|
61
62
|
|
|
62
63
|
export const AccountViewSchema = z.object({
|
package/shared/rpc.ts
CHANGED
|
@@ -102,6 +102,16 @@ export const setDefaultAccount = defineRpc({
|
|
|
102
102
|
output: ReopenSummarySchema,
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
+
/** Sets an account aside for a while (nothing is routed to it) or brings it back. */
|
|
106
|
+
export const setAccountEnabled = defineRpc({
|
|
107
|
+
name: "zerosub.accounts.enabled",
|
|
108
|
+
input: z.object({ accountId: z.string(), enabled: z.boolean() }),
|
|
109
|
+
output: ReopenSummarySchema.extend({
|
|
110
|
+
/** ChatGPT conversations that stay on the disabled account because they can't change accounts. */
|
|
111
|
+
stayed: z.number(),
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
|
|
105
115
|
/** Carries an agent's work on in a new agent on the other provider (Claude ↔ ChatGPT). */
|
|
106
116
|
export const forkAgent = defineRpc({
|
|
107
117
|
name: "zerosub.agents.fork",
|
package/shared/timeline.ts
CHANGED
|
@@ -19,6 +19,10 @@ export const SwitchRowSchema = z.object({
|
|
|
19
19
|
"default",
|
|
20
20
|
/** `from` was removed. */
|
|
21
21
|
"removed",
|
|
22
|
+
/** `from` was disabled for a while. */
|
|
23
|
+
"disabled",
|
|
24
|
+
/** `to` was enabled again, and this agent returns to it. */
|
|
25
|
+
"enabled",
|
|
22
26
|
/** Every account of this provider is at its limit; nothing to switch to. */
|
|
23
27
|
"exhausted",
|
|
24
28
|
]),
|