paseo-plugin-account-switcher 0.10.2 → 0.11.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 CHANGED
@@ -110,6 +110,15 @@ paseo run --provider codex --env PASEO_ACCOUNT_SWITCHER_ACCOUNT=Work "Review the
110
110
 
111
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
112
 
113
+ On Paseo 0.16 and later, name the account when importing a provider session into Paseo for the first time:
114
+
115
+ ```sh
116
+ paseo import <session-id> --provider claude --label 'account-switcher.account=Work'
117
+ ```
118
+
119
+ The named account must be signed in and allowed by the provider's account switching settings. Paseo refuses the import if the plugin cannot select it. The label applies to the first import. Restoring an archived Paseo agent keeps its existing account.
120
+
121
+
113
122
  ## Switch an existing chat
114
123
 
115
124
  1. Select the account chip beside the message field to open **Account** over the current chat.
package/index.server.ts CHANGED
@@ -15,6 +15,7 @@ import type { AccountNote } from "./shared/timeline";
15
15
  const MODEL_ENV="PASEO_ACCOUNT_SWITCHER_MODEL";
16
16
  // Set by whoever creates the agent (e.g. `paseo run --env PASEO_ACCOUNT_SWITCHER_ACCOUNT=Work`): the account it starts on.
17
17
  const ACCOUNT_ENV="PASEO_ACCOUNT_SWITCHER_ACCOUNT";
18
+ const IMPORT_ACCOUNT_LABEL="account-switcher.account";
18
19
  // The prompt that resumes an agent's work on the account it was switched to.
19
20
  const CONTINUE="Continue.";
20
21
  const reason=(error:unknown)=>error instanceof Error?error.message:String(error);
@@ -139,9 +140,17 @@ export default function contribute(server:PluginServerContext){
139
140
  await controller.ready;
140
141
  // Neither hint from the creation reaches the CLI, on this or any later session of the agent.
141
142
  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);
143
+ const creating=request.purpose==="interactive"&&request.reason==="create";
144
+ const importing=request.purpose==="interactive"&&request.reason==="import";
145
+ // Newer daemons include labels in session-open requests; the pinned 0.11 SDK does not declare them.
146
+ const labelled=request as typeof request&{labels?:Readonly<Record<string,string>>};
147
+ const importAccount=importing?labelled.labels?.[IMPORT_ACCOUNT_LABEL]:undefined;
148
+ if(importAccount!==undefined&&!importAccount.trim())throw new SwitchRefusal("Name an account in the account-switcher.account import label.");
149
+ const requested=(importing?importAccount:account)?.trim()||null;
150
+ const selecting=creating||importAccount!==undefined;
151
+ if(selecting&&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}.`);
152
+ if(selecting&&(request.provider==="claude"||request.provider==="codex")){await controller.ensureRuntime(paseo);const bound=await controller.switcher(paseo).bindNewAgent(request.agentId,request.provider,model||null,requested);
153
+ if(importing&&requested&&!bound)throw new SwitchRefusal("This imported session already has an account binding. Switch it from the composer.");
145
154
  const reason=bound?.reason;
146
155
  if(bound&&reason){
147
156
  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;});
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "paseo-plugin-account-switcher",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "paseo-plugin-account-switcher",
9
- "version": "0.10.2",
9
+ "version": "0.11.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@iarna/toml": "^2.2.5"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-plugin-account-switcher",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "dutchakdev",
@@ -40,16 +40,16 @@
40
40
  "@getpaseo/client": "0.11.4",
41
41
  "@getpaseo/plugin": "0.11.4",
42
42
  "@getpaseo/protocol": "0.11.4",
43
- "@tanstack/react-query": "^5.90.11",
43
+ "@tanstack/react-query": "^5.107.1",
44
44
  "@types/node": "^22.0.0",
45
45
  "@types/react": "~19.2.0",
46
46
  "esbuild": "^0.28.2",
47
47
  "react": "19.1.0",
48
48
  "react-native": "0.81.5",
49
- "semver": "^7.8.5",
49
+ "semver": "^7.8.6",
50
50
  "typescript": "^7.0.2",
51
- "vite": "^8.3.5",
52
- "vitest": "^5.0.5",
51
+ "vite": "^8.3.6",
52
+ "vitest": "^5.1.0",
53
53
  "zod": "^4.4.3"
54
54
  },
55
55
  "repository": {
@@ -13,7 +13,7 @@ import { installIntegration, restoreIntegration, writeLaunchers, prepareRuntime,
13
13
  import { SwitchRefusal, SwitchService } from "./switching";
14
14
  import { createUsageService, readCredentialVersion, usageChecksEnabled, type AccountReadOptions, type QuotaAccount } from "./usage";
15
15
  import { renewExpiredClaudeToken } from "./usage/claude";
16
- import { LoginSessions, type LoginDependencies } from "./login";
16
+ import { LoginRefusal, LoginSessions, type LoginDependencies } from "./login";
17
17
  import { receiptProcessRuns } from "./process-identity";
18
18
 
19
19
  const execFileAsync=promisify(execFile);
@@ -251,7 +251,7 @@ export class AccountController {
251
251
  if(account.loginToken)throw new Error("Sign-in is already open. Continue or cancel the current attempt.");
252
252
  if(account.source!=="managed")throw new Error("Add a separate account for isolated sign-in.");
253
253
  return await this.logins.start(account,registry,this.store.root,token,mode,async()=>{
254
- await this.store.change(state=>{const current=accountFrom(state,id);if(current.loginToken)throw new Error("Sign-in is already open. Continue or cancel the current attempt.");if(state.bindings.some(b=>b.currentAccountId===id||b.launchAccountId===id||b.currentAccountId===null&&b.pendingAccountId===id))throw new Error("Switch agents away from this account before signing in again.");current.loginToken=token;current.login={sessionId:token,mode:account.provider==="claude"?"browser":mode};});
254
+ await this.store.change(state=>{const current=accountFrom(state,id);if(current.loginToken)throw new LoginRefusal("Sign-in is already open. Continue or cancel the current attempt.");if(state.bindings.some(b=>b.currentAccountId===id||b.launchAccountId===id||b.currentAccountId===null&&b.pendingAccountId===id))throw new LoginRefusal("Switch agents away from this account before signing in again.");current.loginToken=token;current.login={sessionId:token,mode:account.provider==="claude"?"browser":mode};});
255
255
  this.usage.invalidate(id);
256
256
  await this.checks.get(id)?.catch(()=>{});
257
257
  });
@@ -13,8 +13,30 @@ const providers = ["claude", "codex"] as const;
13
13
  const COMMAND_DRIFT = "Provider commands changed outside the plugin. Enable integration again to apply accounts.";
14
14
  export const NO_PROVIDER_CLI = "Provider CLI not found. Install Claude Code or Codex, or configure its command in Paseo.";
15
15
  export const launcherPath = (root: string, provider: Provider): string => join(root, "bin", `${provider}-launcher`);
16
+ /** The launcher bundle that every provider's launcher runs. */
17
+ export const launcherScriptPath = (root: string): string => join(root, "bin", "launcher.js");
18
+
19
+ const shellQuote = (value: string): string => `'${value.replace(/'/g, `'\\''`)}'`;
20
+
21
+ /**
22
+ * A provider's launcher: a shell script that runs the bundle with the Node that runs this plugin, and names the
23
+ * provider. The bundle used to be the launcher itself, behind `#!/usr/bin/env node`, which takes the first `node` on the
24
+ * agent's PATH; a project that pins an old Node through mise, asdf or nvm put that one first, and it could not parse the
25
+ * bundle (#58). Under the desktop app the plugin's Node is Paseo's Electron, which acts as Node only with
26
+ * ELECTRON_RUN_AS_NODE; the launcher drops the variable again before it starts the provider CLI.
27
+ */
28
+ export function launcherWrapper(node: string, script: string, provider: Provider, electron: boolean): string {
29
+ const lines = ["#!/bin/sh", `# Account Switcher ${provider} launcher, written by the plugin at every start. Do not edit.`];
30
+ if (electron) lines.push("ELECTRON_RUN_AS_NODE=1; ACCOUNT_SWITCHER_ELECTRON=1; export ELECTRON_RUN_AS_NODE ACCOUNT_SWITCHER_ELECTRON");
31
+ lines.push(`exec ${shellQuote(node)} ${shellQuote(script)} ${provider} "$@"`);
32
+ return `${lines.join("\n")}\n`;
33
+ }
34
+
16
35
  export async function writeLaunchers(store: AccountStore): Promise<void> {
17
- for (const provider of providers) await atomicWrite(launcherPath(store.root, provider), LAUNCHER_SOURCE, 0o700);
36
+ const script = launcherScriptPath(store.root);
37
+ await atomicWrite(script, LAUNCHER_SOURCE, 0o600);
38
+ const electron = typeof process.versions.electron === "string";
39
+ for (const provider of providers) await atomicWrite(launcherPath(store.root, provider), launcherWrapper(process.execPath, script, provider, electron), 0o700);
18
40
  }
19
41
 
20
42
  function commandArray(value: unknown): string[] | null {
@@ -90,7 +112,8 @@ async function discoverCommands(paseo: PaseoApi, store: AccountStore) {
90
112
 
91
113
  async function discoverRuntime(paseo: PaseoApi, store: AccountStore) {
92
114
  const { config } = await paseo.config.get(); const registry = await store.read();
93
- const wrappers = providers.map(provider => launcherPath(store.root, provider));
115
+ // The shared bundle counts as a launcher too: `node bin/launcher.js codex` saved as the original command would recurse.
116
+ const wrappers = [...providers.map(provider => launcherPath(store.root, provider)), launcherScriptPath(store.root)];
94
117
  const commands = { ...registry.commands }, originals = { ...registry.originalCommands }, sourceHomes = { ...registry.sourceHomes };
95
118
  const sourceEnvironment: typeof registry.sourceEnvironment = { claude: {}, codex: {} };
96
119
  const available = { claude: false, codex: false };