@kapybara/zerosub 1.5.0 → 1.5.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 -1
- package/package.json +1 -1
- package/server/codex.ts +1 -1
- package/server/continuations.ts +62 -2
- package/server/handoff.ts +10 -1
- package/server/service.ts +2 -0
- package/server/state.ts +2 -0
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ Turn on **Spread new agents across accounts** to select an account from its usag
|
|
|
63
63
|
- A tab you return to gets the instructions and progress since it was last used, and checks the current files and Git diff before going on. Very long instructions are shortened, keeping the first one since the tab was last used (the original request, for a new tab), the latest ones and a note of how many were left out.
|
|
64
64
|
- You can type in any of a task's tabs and switch from any of them. The tab you used last is where the task continues: automatic switches and resets only move that tab, and another tab that hits a limit says in its timeline where the task went.
|
|
65
65
|
- A tab is reused while it is in the same workspace with the same account and permission mode; otherwise ZeroSub starts a new one. While one of the task's tabs is working or asking for permission, a switch you pick is refused until it stops, and an automatic switch leaves the task where it is and says so in its timeline.
|
|
66
|
+
- A sub-agent (one another agent started) keeps its parent: its new tab goes under the same agent, or under the tab where that agent's own task now continues. Like the first tab, it's archived with the parent and sends no notifications of its own. Paseo doesn't tell the parent when the new tab finishes, though: it only reports to an agent on agents it started or prompted itself.
|
|
66
67
|
- ZeroSub never sends a hand-off twice. If a lost connection leaves one unconfirmed, the switch stops and names the tab to check. Continuation agents from earlier versions are picked up on the first switch. New Codex agents simply start on the chosen account.
|
|
67
68
|
|
|
68
69
|
### Banked resets
|
|
@@ -88,7 +89,7 @@ ZeroSub tries these in order, and a timeline note says which one happened:
|
|
|
88
89
|
|
|
89
90
|
1. **Use a banked reset**, if you turned on **Use banked resets when every account is out**.
|
|
90
91
|
2. **Fork the chat to the other provider**, if you turned on **When every account is out, fork the chat to the other provider** (off by default). A stopped Claude chat continues in a new ChatGPT agent, or the other way round:
|
|
91
|
-
- The new agent opens in the same workspace with the conversation so far and goes straight back to work. If that conversation began as a hand-off itself, only the start and end of the earlier one are quoted. It uses the other provider's default model and its account with the most room left.
|
|
92
|
+
- The new agent opens in the same workspace (under the same parent, for a sub-agent) with the conversation so far and goes straight back to work. If that conversation began as a hand-off itself, only the start and end of the earlier one are quoted. It uses the other provider's default model and its account with the most room left.
|
|
92
93
|
- Its permission mode matches the original's level. Bypass becomes Full Access, and Accept File Edits becomes Default Permissions. Codex has no read-only or ask-first mode, so a Claude agent in Plan Mode or Always Ask isn't forked. ZeroSub never gives a fork more freedom than you gave the original.
|
|
93
94
|
- The original agent stays as it was, and prompting it again while its provider is still out points to the same fork rather than starting another.
|
|
94
95
|
- With the option off, a stopped agent's account button offers **Continue on ChatGPT (new agent)…** (or Claude) instead, with a confirmation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kapybara/zerosub",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.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/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.5.
|
|
73
|
+
{ clientInfo: { name: CLIENT_NAME, title: "Paseo ZeroSub", version: "1.5.1" }, capabilities: { experimentalApi: false } },
|
|
74
74
|
60_000,
|
|
75
75
|
);
|
|
76
76
|
server.send({ method: "initialized" });
|
package/server/continuations.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import type { PluginHookContext } from "@getpaseo/plugin/server";
|
|
3
3
|
import { sameAccountIdentity } from "./account-identity";
|
|
4
4
|
import type { AgentTimelineItem } from "./adapter";
|
|
5
|
-
import { buildTranscript, CONTINUED_FROM_LABEL, continueInNewAgent, keepEnds, type Continuation } from "./handoff";
|
|
5
|
+
import { buildTranscript, CONTINUED_FROM_LABEL, continueInNewAgent, keepEnds, PARENT_LABEL, type Continuation } from "./handoff";
|
|
6
6
|
import { Mutex } from "./json-file";
|
|
7
7
|
import { isUsable } from "./routing";
|
|
8
8
|
import { findAccount, MAIN_ACCOUNT_ID, StateStore, type ContinuationChain, type StoredAccount, type StoredState } from "./state";
|
|
@@ -89,6 +89,8 @@ interface Destination {
|
|
|
89
89
|
/** The existing tab, when there is one. */
|
|
90
90
|
agent?: Agent;
|
|
91
91
|
entry?: Member;
|
|
92
|
+
/** A new tab's parent agent, if it's created as a sub-agent. */
|
|
93
|
+
parent?: string;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
/** What the destination hasn't seen yet, and the timeline marks to record once it has. */
|
|
@@ -126,6 +128,40 @@ export class CodexContinuations {
|
|
|
126
128
|
return current.id === agentId ? null : { agentId: current.id, title: current.agent?.title ?? "Codex task" };
|
|
127
129
|
}
|
|
128
130
|
|
|
131
|
+
/**
|
|
132
|
+
* The agent to create a continuation of `agentId` under, so a sub-agent's continuation is still
|
|
133
|
+
* a sub-agent of the agent that started it: that parent, or where the parent's own task carries
|
|
134
|
+
* on if ZeroSub has continued it too (in another ChatGPT tab, or on the other provider). None for
|
|
135
|
+
* an agent without a parent, or when the parent is archived or gone. A failed lookup means none
|
|
136
|
+
* too: the hand-off goes ahead without a parent rather than not at all.
|
|
137
|
+
*/
|
|
138
|
+
async parentFor(paseo: PaseoApi, agentId: string): Promise<string | undefined> {
|
|
139
|
+
try {
|
|
140
|
+
let parentId = (await snapshot(paseo, agentId))?.labels?.[PARENT_LABEL]?.trim();
|
|
141
|
+
let live: Agent[] | undefined;
|
|
142
|
+
// A continuation on the other provider has only its label to go by, as when an earlier fork is reused.
|
|
143
|
+
const forkOf = async (id: string) => {
|
|
144
|
+
const agent = await snapshot(paseo, id);
|
|
145
|
+
if (!agent) return undefined;
|
|
146
|
+
live ??= await liveAgents(paseo);
|
|
147
|
+
return live.find((other) => other.labels?.[CONTINUED_FROM_LABEL] === id && other.provider !== agent.provider && !other.archivedAt)?.id;
|
|
148
|
+
};
|
|
149
|
+
// Each step goes to where that agent's task went next. A loop in the records ends the walk.
|
|
150
|
+
const seen = new Set([agentId]);
|
|
151
|
+
while (parentId && !seen.has(parentId)) {
|
|
152
|
+
seen.add(parentId);
|
|
153
|
+
const next = (await this.continuesElsewhere(paseo, parentId))?.agentId ?? (await forkOf(parentId));
|
|
154
|
+
if (!next) break;
|
|
155
|
+
parentId = next;
|
|
156
|
+
}
|
|
157
|
+
const parent = parentId && parentId !== agentId ? await snapshot(paseo, parentId) : undefined;
|
|
158
|
+
return parent && !parent.archivedAt ? parent.id : undefined;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error(`[ZeroSub] couldn't look up the parent of ${agentId}; continuing it without one`, error instanceof Error ? error.message : error);
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
129
165
|
continue(paseo: PaseoApi, sourceAgentId: string, target: StoredAccount, why: string, source: Source): Promise<Continuation> {
|
|
130
166
|
const key = `${sourceAgentId}:${target.id}`;
|
|
131
167
|
const existing = this.inFlight.get(key);
|
|
@@ -157,6 +193,8 @@ export class CodexContinuations {
|
|
|
157
193
|
const gathered = await gatherUpdates(paseo, state, chain, snapshots, sourceAgent, destination);
|
|
158
194
|
const prompt = composePrompt(chain, destination, gathered, why, Boolean(reserved));
|
|
159
195
|
const messageId = reserved?.messageId ?? `${MESSAGE_PREFIX}${randomUUID()}`;
|
|
196
|
+
// A retried creation has to repeat its first request exactly, parent included.
|
|
197
|
+
if (!destination.agent) destination.parent = reserved ? reserved.parent : await this.parentFor(paseo, sourceAgent.id);
|
|
160
198
|
await this.confirmUnchanged(paseo, sourceAgent, destination, account);
|
|
161
199
|
await this.reserve(root, sourceAgent.id, destination, gathered, account, messageId, source);
|
|
162
200
|
return this.deliver(paseo, root, sourceAgent, destination, account, prompt, messageId, why);
|
|
@@ -265,6 +303,7 @@ export class CodexContinuations {
|
|
|
265
303
|
seen: gathered.seen,
|
|
266
304
|
stage: destination.agent ? "sending" : "creating",
|
|
267
305
|
...(gathered.fallback ? { replaceHistory: gathered.obsolete } : {}),
|
|
306
|
+
...(destination.parent ? { parent: destination.parent } : {}),
|
|
268
307
|
};
|
|
269
308
|
if (!destination.agent) draft.bindings[targetId] = { accountId: account.id, source: source === "user" ? "user" : "thread", at: new Date().toISOString() };
|
|
270
309
|
});
|
|
@@ -286,7 +325,15 @@ export class CodexContinuations {
|
|
|
286
325
|
if (destination.agent) {
|
|
287
326
|
result = { agentId: targetId, title: destination.agent.title ?? "Codex task" };
|
|
288
327
|
} else {
|
|
289
|
-
result = await continueInNewAgent({
|
|
328
|
+
result = await continueInNewAgent({
|
|
329
|
+
paseo,
|
|
330
|
+
sourceAgentId: sourceAgent.id,
|
|
331
|
+
why,
|
|
332
|
+
agentId: targetId,
|
|
333
|
+
deferPrompt: true,
|
|
334
|
+
parentId: destination.parent,
|
|
335
|
+
bind: async () => {},
|
|
336
|
+
});
|
|
290
337
|
// Creation can take time. A user may have started another turn or disabled the account.
|
|
291
338
|
const created = await waitForCreated(paseo, targetId);
|
|
292
339
|
const sourceNow = await snapshot(paseo, sourceAgent.id);
|
|
@@ -354,6 +401,19 @@ async function adoptDescendants(paseo: PaseoApi, original: Agent, ancestors: Age
|
|
|
354
401
|
}
|
|
355
402
|
}
|
|
356
403
|
|
|
404
|
+
/** Every agent that isn't archived, as far as MAX_PAGES pages go. */
|
|
405
|
+
async function liveAgents(paseo: PaseoApi): Promise<Agent[]> {
|
|
406
|
+
const agents: Agent[] = [];
|
|
407
|
+
let cursor: string | undefined;
|
|
408
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
409
|
+
const result = await paseo.agents.list({ page: { limit: 200, ...(cursor ? { cursor } : {}) } });
|
|
410
|
+
agents.push(...result.entries.map(({ agent }) => agent));
|
|
411
|
+
if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) break;
|
|
412
|
+
cursor = result.pageInfo.nextCursor;
|
|
413
|
+
}
|
|
414
|
+
return agents;
|
|
415
|
+
}
|
|
416
|
+
|
|
357
417
|
function newer(left: string | null | undefined, right: string | null | undefined): boolean {
|
|
358
418
|
return left ? !right || Date.parse(left) > Date.parse(right) : false;
|
|
359
419
|
}
|
package/server/handoff.ts
CHANGED
|
@@ -6,6 +6,8 @@ type PaseoApi = PluginHookContext["paseo"];
|
|
|
6
6
|
|
|
7
7
|
/** Label on a continuation agent naming the agent it carries on from. */
|
|
8
8
|
export const CONTINUED_FROM_LABEL = "zerosub.continued-from";
|
|
9
|
+
/** Paseo's label naming the agent a sub-agent was created by (`PARENT_AGENT_ID_LABEL`). */
|
|
10
|
+
export const PARENT_LABEL = "paseo.parent-agent-id";
|
|
9
11
|
|
|
10
12
|
const MAX_TRANSCRIPT = 40_000;
|
|
11
13
|
const MAX_FIRST_MESSAGE = 6_000;
|
|
@@ -170,6 +172,13 @@ export async function continueInNewAgent(options: {
|
|
|
170
172
|
agentId?: string;
|
|
171
173
|
/** Create the pre-bound tab first; the caller delivers its handoff separately. */
|
|
172
174
|
deferPrompt?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Make the new agent a sub-agent of this one, as the source was of its parent. This sets Paseo's
|
|
177
|
+
* parent label rather than `parent`: on a create, `parent` would also turn the first prompt into
|
|
178
|
+
* a message from the parent agent, move an agent made outside a workspace into the parent's, and
|
|
179
|
+
* fail outright once the parent has been closed.
|
|
180
|
+
*/
|
|
181
|
+
parentId?: string;
|
|
173
182
|
}): Promise<Continuation> {
|
|
174
183
|
const { paseo, sourceAgentId } = options;
|
|
175
184
|
const refreshed = await paseo.agents.ref(sourceAgentId).refresh();
|
|
@@ -211,7 +220,7 @@ export async function continueInNewAgent(options: {
|
|
|
211
220
|
config,
|
|
212
221
|
title,
|
|
213
222
|
...(!options.deferPrompt ? { prompt: continuationPrompt(buildTranscript(timeline ?? []), options.why, options.previous) } : {}),
|
|
214
|
-
labels: { [CONTINUED_FROM_LABEL]: sourceAgentId },
|
|
223
|
+
labels: { [CONTINUED_FROM_LABEL]: sourceAgentId, ...(options.parentId ? { [PARENT_LABEL]: options.parentId } : {}) },
|
|
215
224
|
};
|
|
216
225
|
if (source.workspaceId) await paseo.workspaces.ref(source.workspaceId).agents.create(request);
|
|
217
226
|
else await paseo.agents.create({ ...request, cwd: source.cwd });
|
package/server/service.ts
CHANGED
|
@@ -1069,6 +1069,7 @@ export class Service {
|
|
|
1069
1069
|
why: source === "auto" ? `every ${FAMILY_LABEL[family]} account reached its usage limit` : `the work was moved to ${name}`,
|
|
1070
1070
|
previous: PROVIDER_NAME[family],
|
|
1071
1071
|
target: { provider, label: name, modeId },
|
|
1072
|
+
parentId: await this.continuations.parentFor(paseo, agentId),
|
|
1072
1073
|
bind: async (newAgentId) => {
|
|
1073
1074
|
await this.store.update((draft) => {
|
|
1074
1075
|
draft.bindings[newAgentId] = {
|
|
@@ -1141,6 +1142,7 @@ export class Service {
|
|
|
1141
1142
|
sourceAgentId: agentId,
|
|
1142
1143
|
timeline,
|
|
1143
1144
|
why,
|
|
1145
|
+
parentId: await this.continuations.parentFor(paseo, agentId),
|
|
1144
1146
|
bind: async (newAgentId) => {
|
|
1145
1147
|
await this.store.update((draft) => {
|
|
1146
1148
|
draft.bindings[newAgentId] = {
|
package/server/state.ts
CHANGED
|
@@ -77,6 +77,8 @@ export const ContinuationChainSchema = z.object({
|
|
|
77
77
|
seen: z.record(z.string(), TimelineMarkSchema),
|
|
78
78
|
stage: z.enum(["creating", "sending"]).default("sending"),
|
|
79
79
|
replaceHistory: z.array(z.string()).optional(),
|
|
80
|
+
/** The agent a new tab is created under. A retried creation must repeat its first request. */
|
|
81
|
+
parent: z.string().optional(),
|
|
80
82
|
}).optional(),
|
|
81
83
|
});
|
|
82
84
|
export type ContinuationChain = z.infer<typeof ContinuationChainSchema>;
|