paseo-plugin-account-switcher 0.8.0 → 0.9.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/OVERVIEW.md +1 -0
- package/OVERVIEW.zh-CN.md +1 -0
- package/README.md +13 -3
- package/index.server.ts +7 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/controller.ts +47 -6
- package/server/launcher-artifact.ts +1 -1
- package/server/launcher-main.ts +6 -0
- package/server/process-identity.ts +30 -0
- package/server/store.ts +1 -1
- package/server/switching.ts +35 -3
- package/shared/timeline.ts +2 -1
package/OVERVIEW.md
CHANGED
|
@@ -7,6 +7,7 @@ Limits cover every window the provider reports, such as 5-hour and weekly use, w
|
|
|
7
7
|
- Each account you add gets its own credential profile. Settings, skills, and session history stay shared with your existing CLI setup, so a profile is not a sandbox.
|
|
8
8
|
- **Enable** in Accounts points Paseo's Claude and Codex commands at the plugin's launchers, which start the official CLI under the agent's account. **Disable** restores the original commands; use it before removing the plugin.
|
|
9
9
|
- A new agent starts on its provider's default account. When the latest readings show the default has used up an account-wide limit that resets later, Codex reports that ordinary usage is not allowed, its plan lacks the Codex model chosen for the agent, or the default needs sign-in, the agent starts on the signed-in account with the largest percentage left instead. Limits of a single model and extra paid usage do not count. With every account ruled out, it stays on the default. **Always use the default** under a provider in Accounts turns this off, so the default stays binding.
|
|
10
|
+
- A tool that creates agents can name the account to start on: an agent created with `PASEO_ACCOUNT_SWITCHER_ACCOUNT` in its environment, set to an account's name or ID, starts on that account whatever its limits. It is not created when that account cannot be used, or when **Always use the default** is on and that account is not the default.
|
|
10
11
|
- `/account name` in the message field switches the chat's account, or `/account default` its provider's default: at once when the agent is idle, otherwise in the switcher for **Apply**. The Command Center offers **Make “name” the default** for each signed-in account.
|
|
11
12
|
- A line in the chat records applied switches, and why a new agent did not start on the default. These lines are best effort and do not survive a daemon restart.
|
|
12
13
|
- Signed-in accounts also appear in Paseo's Usage view, and Paseo's usage popover for an agent on a managed account shows that account.
|
package/OVERVIEW.zh-CN.md
CHANGED
|
@@ -9,6 +9,7 @@ Account Switcher 让你在 Paseo 中使用多个 Claude 和 ChatGPT/Codex 订阅
|
|
|
9
9
|
- 你添加的每个账号都有独立的凭据配置文件。设置、技能和会话历史仍与现有 CLI 配置共享,因此配置文件并不是沙箱。
|
|
10
10
|
- 在 Accounts 中选择 **Enable**,会让 Paseo 的 Claude 和 Codex 命令指向插件的启动器,启动器以智能体所选账号运行官方 CLI。**Disable** 会恢复原始命令;移除插件前请先执行它。
|
|
11
11
|
- 新智能体会使用其提供商的默认账号。如果最近读取的数据显示:默认账号已用尽某个账号级限制且重置时间尚未到来、Codex 报告不允许常规使用、其套餐不提供为该智能体选择的 Codex 模型,或默认账号需要重新登录,智能体会改用剩余百分比最多的已登录账号。单个模型的限制和额外付费用量不计入。所有账号都被排除时,仍使用默认账号。在 Accounts 中该提供商下选择 **Always use the default** 可关闭此行为,使默认账号始终生效。
|
|
12
|
+
- 创建智能体的工具可以指定起始账号:创建时在智能体环境中设置 `PASEO_ACCOUNT_SWITCHER_ACCOUNT` 为账号名称或 ID,智能体就会在该账号上启动,不受限制影响。该账号无法使用,或已选择 **Always use the default** 而该账号不是默认账号时,不会创建智能体。
|
|
12
13
|
- 在输入框中输入 `/account 名称` 可切换当前对话的账号,`/account default` 切换到提供商的默认账号:智能体空闲时立即生效,否则在切换器中通过 **Apply** 应用。命令中心(⌘K)为每个已登录账号提供 **Make “名称” the default**。
|
|
13
14
|
- 对话中会有一行记录已应用的切换,以及新智能体未使用默认账号的原因。这些记录是尽力而为的,在守护进程重启后不会保留。
|
|
14
15
|
- 已登录的账号也会显示在 Paseo 的 Usage 视图中;使用托管账号的智能体,其 Paseo 用量弹窗会显示该账号。
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
3
|
# Account Switcher for Paseo
|
|
4
4
|
|
|
@@ -94,12 +94,22 @@ A new Claude or Codex agent starts on its provider's default account. It starts
|
|
|
94
94
|
|
|
95
95
|
The replacement is the account with the largest percentage left in its tightest account-wide window; accounts without limit data come after the measured ones. Percentages do not compare the size of different plans. If every account is ruled out, the agent starts on the default, as before. Choosing an account for a chat yourself always takes precedence, and nothing changes when no default is set.
|
|
96
96
|
|
|
97
|
-
To keep the default binding, for example when one provider holds both work and personal subscriptions, choose **Always use the default** under that provider in Accounts. New agents then start on the default or not at all, as in 0.6.0. **Start on another account** is the initial choice; the control appears once a provider has a default and more than one account.
|
|
97
|
+
To keep the default binding, for example when one provider holds both work and personal subscriptions, choose **Always use the default** under that provider in Accounts. New agents then start on the default or not at all, as in 0.6.0, and a tool that names another account is refused. **Start on another account** is the initial choice; the control appears once a provider has a default and more than one account.
|
|
98
98
|
|
|
99
99
|
Limits come from the plugin's last reading, so creating an agent does not wait for a provider's limits. It does run the official sign-in check for the default, and for each further account it tries.
|
|
100
100
|
|
|
101
101
|
Before signing in again, switch agents away from that profile. To remove a managed account, clear its default and all current or pending selections first. Removal asks for confirmation. **Archived agents retain their account binding for resume**; restore and switch them before removing the account. **Current CLI** accounts cannot be removed.
|
|
102
102
|
|
|
103
|
+
### Start an agent on a chosen account
|
|
104
|
+
|
|
105
|
+
A tool that creates agents can name the account a new Claude or Codex agent starts on: set `PASEO_ACCOUNT_SWITCHER_ACCOUNT` in the agent's environment to the account's name, as shown in Accounts, or its ID. With the Paseo CLI:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
paseo run --provider codex --env PASEO_ACCOUNT_SWITCHER_ACCOUNT=Work "Review the open pull requests"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The named account is binding: the agent starts there or is not created, and the error says why. Limits do not move it to another account. A name must belong to exactly one account of the agent's provider; use the ID when two accounts share a name. Creation is refused when no such account exists, its sign-in is still in progress, the official sign-in check does not confirm it, **Always use the default** is on and the account is not the default, account switching is off for the provider, or the agent's provider is not Claude or Codex. The variable works only at creation: it reaches neither the provider CLI nor later sessions of the agent, and set in a provider's configured environment it selects nothing. The chat records the start when the account is not the default. Afterwards the agent behaves like any other: switching, and switching when a limit runs out, follow your settings.
|
|
112
|
+
|
|
103
113
|
## Switch an existing chat
|
|
104
114
|
|
|
105
115
|
1. Select the account chip beside the message field to open **Account** over the current chat.
|
|
@@ -182,7 +192,7 @@ Before disabling or removing the plugin, select **Disable** in Accounts to resto
|
|
|
182
192
|
|
|
183
193
|
## Scope
|
|
184
194
|
|
|
185
|
-
This project supports same-provider switching with subscription accounts. Switching is manual, except for the opt-in automatic switch after a turn stopped on a used-up limit. Rotating accounts to spread usage, API-key authentication, and Claude-to-Codex transfers are outside its scope. Provider authentication and limit formats can change with CLI versions; unsupported data is shown as unavailable.
|
|
195
|
+
This project supports same-provider switching with subscription accounts. Switching is manual, except for the opt-in automatic switch after a turn stopped on a used-up limit. A tool can name the account a new agent starts on; that choice is the tool's, and the plugin itself never rotates accounts. Rotating accounts to spread usage, API-key authentication, and Claude-to-Codex transfers are outside its scope. Provider authentication and limit formats can change with CLI versions; unsupported data is shown as unavailable.
|
|
186
196
|
|
|
187
197
|
Automated tests cover the implementation with synthetic accounts and provider responses. They do not establish real A → B → A switching, compaction, child-session behavior, or rewind for your accounts. Recorded checks and remaining live verification are in [verification](docs/verification.md).
|
|
188
198
|
|
package/index.server.ts
CHANGED
|
@@ -13,6 +13,8 @@ import type { AccountNote } from "./shared/timeline";
|
|
|
13
13
|
|
|
14
14
|
// Paseo hands `agent.create`'s environment to the same agent's first `agent.session_open`, which alone knows the agent ID.
|
|
15
15
|
const MODEL_ENV="PASEO_ACCOUNT_SWITCHER_MODEL";
|
|
16
|
+
// Set by whoever creates the agent (e.g. `paseo run --env PASEO_ACCOUNT_SWITCHER_ACCOUNT=Work`): the account it starts on.
|
|
17
|
+
const ACCOUNT_ENV="PASEO_ACCOUNT_SWITCHER_ACCOUNT";
|
|
16
18
|
// The prompt that resumes an agent's work on the account it was switched to.
|
|
17
19
|
const CONTINUE="Continue.";
|
|
18
20
|
const reason=(error:unknown)=>error instanceof Error?error.message:String(error);
|
|
@@ -135,8 +137,11 @@ export default function contribute(server:PluginServerContext){
|
|
|
135
137
|
});
|
|
136
138
|
const removeHook=server.before("agent.session_open",async({request},{paseo})=>{
|
|
137
139
|
await controller.ready;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
// Neither hint from the creation reaches the CLI, on this or any later session of the agent.
|
|
141
|
+
const {[MODEL_ENV]:model,[ACCOUNT_ENV]:account,...env}=request.env;
|
|
142
|
+
const creating=request.purpose==="interactive"&&request.reason==="create",requested=account?.trim()||null;
|
|
143
|
+
if(creating&&requested&&request.provider!=="claude"&&request.provider!=="codex")throw new SwitchRefusal(`Account Switcher manages only Claude Code and Codex accounts, so the ${request.provider} agent cannot start on ${requested}.`);
|
|
144
|
+
if(creating&&(request.provider==="claude"||request.provider==="codex")){await controller.ensureRuntime(paseo);const bound=await controller.switcher(paseo).bindNewAgent(request.agentId,request.provider,model||null,requested);
|
|
140
145
|
const reason=bound?.reason;
|
|
141
146
|
if(bound&&reason){
|
|
142
147
|
const started=await note(request.agentId,async()=>{const state=await controller.store.read(),to=labelOf(state,bound.accountId);return to?{kind:"started",from:labelOf(state,bound.defaultId),to,reason}:null;});
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-plugin-account-switcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "paseo-plugin-account-switcher",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.9.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@iarna/toml": "^2.2.5"
|
package/package.json
CHANGED
package/server/controller.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import { promisify } from "node:util";
|
|
2
|
+
import { promisify, stripVTControlCharacters } from "node:util";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join, dirname, resolve } from "node:path";
|
|
5
5
|
import { lstat, readFile, realpath, rm } from "node:fs/promises";
|
|
@@ -14,10 +14,21 @@ import { SwitchRefusal, SwitchService } from "./switching";
|
|
|
14
14
|
import { createUsageService, readCredentialVersion, type AccountReadOptions, type QuotaAccount } from "./usage";
|
|
15
15
|
import { renewExpiredClaudeToken } from "./usage/claude";
|
|
16
16
|
import { LoginSessions, type LoginDependencies } from "./login";
|
|
17
|
+
import { receiptProcessRuns } from "./process-identity";
|
|
17
18
|
|
|
18
19
|
const execFileAsync=promisify(execFile);
|
|
20
|
+
// Paseo sets these for its own Node processes, this plugin's included, and removes them before it starts an outside
|
|
21
|
+
// command. Inherited, ELECTRON_RUN_AS_NODE makes an Electron executable, such as a `paseo` link to the desktop app's
|
|
22
|
+
// executable left by an older install, run as plain Node, which then fails to load "agent" as a script.
|
|
23
|
+
const RUNTIME_ENV=["PASEO_NODE_ENV","PASEO_DESKTOP_MANAGED","PASEO_SUPERVISED","ELECTRON_RUN_AS_NODE","ELECTRON_NO_ATTACH_CONSOLE","ESBUILD_BINARY_PATH"];
|
|
24
|
+
// PASEO_CLI names the desktop app's bundled CLI, for the daemon the app starts and for one started from the app's terminal,
|
|
25
|
+
// which inherits it and can outlive the app. A standalone daemon finds `paseo` on PATH.
|
|
26
|
+
function paseoCli(){const env={...process.env};for(const key of RUNTIME_ENV)delete env[key];return{command:process.env.PASEO_CLI?.trim()||"paseo",env};}
|
|
19
27
|
// A revoked sign-in fails every renewal; this bounds how often it starts the CLI.
|
|
20
28
|
const RENEWAL_INTERVAL=600000;
|
|
29
|
+
// A new agent's binding is written before its CLI starts, and Paseo reports no failed creation. This covers the time until the
|
|
30
|
+
// CLI reads the binding, where each plugin hook gets 30 seconds; from then on the launcher's receipt says whether that CLI still runs.
|
|
31
|
+
const CREATION_WAIT=600000;
|
|
21
32
|
// Agent statuses that show a launch got under way, for the receipt check: the Accounts list waits for a session that is
|
|
22
33
|
// up. Failover also takes "error", which Paseo sets when a turn fails, before the plugin's turn_ended hook runs: the
|
|
23
34
|
// launcher wrote the receipt when it started the CLI, so the receipt still names the account the agent started on.
|
|
@@ -106,16 +117,36 @@ export class AccountController {
|
|
|
106
117
|
}
|
|
107
118
|
}catch{return;}
|
|
108
119
|
if(!complete)return;
|
|
120
|
+
// The list leaves agents out, those in background workspaces among them, so only Paseo's answer for the agent itself proves it is gone.
|
|
121
|
+
const now=Date.now(),gone=new Set<string>();
|
|
122
|
+
for(const binding of before.bindings){
|
|
123
|
+
if(existing.has(binding.agentId)||this.applying.has(binding.agentId)||binding.status==="switching")continue;
|
|
124
|
+
if(!binding.registrationObserved&&binding.currentAccountId===null&&!await this.creationOver(binding,now))continue;
|
|
125
|
+
const known=await paseo.agents.ref(binding.agentId).refresh().then(found=>!!found,()=>undefined);
|
|
126
|
+
if(known)existing.add(binding.agentId);else if(known===false)gone.add(binding.agentId);
|
|
127
|
+
}
|
|
109
128
|
await this.store.change(r=>{
|
|
110
129
|
r.bindings=r.bindings.filter(binding=>{
|
|
111
130
|
if(existing.has(binding.agentId)){binding.registrationObserved=true;return true;}
|
|
112
131
|
if(captured.get(binding.agentId)!==JSON.stringify(binding)||this.applying.has(binding.agentId)||binding.status==="switching")return true;
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
|
|
132
|
+
if(gone.has(binding.agentId))return false;
|
|
133
|
+
// session_open runs before native creation/registration, so a new agent's binding that has never appeared in Paseo
|
|
134
|
+
// may belong to a creation still under way. A binding from before 0.9 starts its wait here.
|
|
135
|
+
if(!binding.registrationObserved&&binding.currentAccountId===null)binding.boundAt??=new Date(now).toISOString();
|
|
136
|
+
return true;
|
|
116
137
|
});
|
|
117
138
|
});
|
|
118
139
|
}
|
|
140
|
+
/** Whether a new agent's creation can no longer use its profile: the wait is over and no CLI of its launch still runs.
|
|
141
|
+
* A profile that may be in use is not released, so anything unclear about the receipt keeps the binding. */
|
|
142
|
+
private async creationOver(binding:StoredBinding,now:number):Promise<boolean>{
|
|
143
|
+
if(!binding.boundAt||now-Date.parse(binding.boundAt)<CREATION_WAIT)return false;
|
|
144
|
+
let pid:unknown,at:unknown;
|
|
145
|
+
try{({pid,at}=JSON.parse(await readFile(join(this.store.root,"receipts",encodeURIComponent(binding.agentId)+".json"),"utf8")));}
|
|
146
|
+
catch(error){return (error as NodeJS.ErrnoException).code==="ENOENT";}
|
|
147
|
+
if(typeof pid!=="number"||!Number.isInteger(pid)||pid<=0)return false;
|
|
148
|
+
return !await receiptProcessRuns(pid,at);
|
|
149
|
+
}
|
|
119
150
|
async setDefault(provider:Provider,id:string|null){
|
|
120
151
|
await this.ready;
|
|
121
152
|
if(id===null){await this.store.change(r=>{r.defaults[provider]=null;});return;}
|
|
@@ -337,8 +368,18 @@ export class AccountController {
|
|
|
337
368
|
const listen=config.daemon?.listen;
|
|
338
369
|
if(typeof listen!=="string"||!listen)throw new SwitchRefusal("Could not identify the daemon for reload.");
|
|
339
370
|
const host=listen.replace(/^0\.0\.0\.0:/,"127.0.0.1:");
|
|
340
|
-
|
|
341
|
-
|
|
371
|
+
const cli=paseoCli();let command=cli.command;
|
|
372
|
+
const reload=(file:string)=>execFileAsync(file,["agent","reload",id,"--json","--host",host],{timeout:120_000,maxBuffer:1024*1024,env:cli.env});
|
|
373
|
+
try{
|
|
374
|
+
// A CLI that could not start reloaded nothing, so `paseo` on PATH can still try. One that ran and failed is not repeated.
|
|
375
|
+
await reload(command).catch(error=>{const code=(error as {code?:unknown}).code;if(command==="paseo"||(code!=="ENOENT"&&code!=="EACCES"))throw error;command="paseo";return reload(command);});
|
|
376
|
+
}
|
|
377
|
+
catch(error){
|
|
378
|
+
// The chat gets the refusal; the cause, which can name local paths, goes only to the plugin log.
|
|
379
|
+
const {code,signal,stderr}=error as {code?:unknown;signal?:unknown;stderr?:unknown};
|
|
380
|
+
console.error(`Native reload of agent ${id} with ${command} failed (${signal?`signal ${signal}`:`code ${code}`}): ${stripVTControlCharacters(String(stderr??"")).replace(/\s+/g," ").trim().slice(0,500)||"no output"}`);
|
|
381
|
+
throw new SwitchRefusal("The native agent reload failed. Check the agent status and try again.");
|
|
382
|
+
}
|
|
342
383
|
// Paseo 0.11 reloads into an idle session and spawns the CLI on first use; listing
|
|
343
384
|
// commands starts it so the launcher can confirm the account. Older hosts already started it.
|
|
344
385
|
const agent=paseo.agents.ref(id) as {commands?:()=>Promise<unknown>};
|