claude-account-sync 0.4.0 → 0.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 CHANGED
@@ -7,6 +7,8 @@ Run Claude Code with several accounts — personal subscription, work OAuth, API
7
7
  The `clp` command (also available as `ccprofiles`) fixes that:
8
8
 
9
9
  - 🔎 **Adopt** your existing `.claude*` directories into a declarative manifest — zero manual config
10
+ - 🎛️ **Set up profiles the easy way** — a guided web form to create, edit, and delete profiles: launcher, env, links, MCP, and provider — no hand-editing config files
11
+ - 🌐 **Custom LLM providers per profile** — point a profile at z.ai (GLM), mimo, OpenRouter, or any Anthropic-compatible endpoint with a preset picker; base URL + token + model mappings managed for you, token kept in the keychain
10
12
  - 🧩 **Manage MCP servers** across profiles: drift matrix, add/remove everywhere at once, sync one profile's set to others
11
13
  - 🔐 **Secrets out of your rc files** — macOS Keychain / libsecret / encrypted file, with `clp secrets migrate` to clean up existing plaintext keys
12
14
  - 🖥️ **Replicate to another machine over LAN** — PIN pairing, end-to-end encrypted, no cloud, works macOS ↔ Windows ↔ Linux ↔ WSL
@@ -64,6 +66,47 @@ clp create work --from oauth # dir + launcher fn + copied MCP set
64
66
  cl-work # launches claude with CLAUDE_CONFIG_DIR=~/.claude-work
65
67
  ```
66
68
 
69
+ `clp apply` writes a launcher function per profile into your shell startup file — `.zshrc`/`.bashrc` on macOS/Linux, your **PowerShell profile** on Windows. After applying, reload the shell (or open a new terminal) and the `cl-*` commands are available directly.
70
+
71
+ ### Using the launchers on Windows (PowerShell)
72
+
73
+ On Windows the launchers are **PowerShell functions**, written to the PowerShell 7 profile:
74
+
75
+ ```
76
+ %USERPROFILE%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
77
+ ```
78
+
79
+ After `clp apply`, reload with `. $PROFILE` (or open a new tab), then run `cl-work` directly. Three things to get right:
80
+
81
+ - **Use PowerShell 7 (`pwsh`), not Windows PowerShell 5.1.** clp writes to the `Documents\PowerShell\` profile (PS7). The old built-in "Windows PowerShell" (5.1, `powershell.exe`) reads a *different* file (`Documents\WindowsPowerShell\`) and won't see the functions. Install PS7 with `winget install --id Microsoft.PowerShell` and make it your default: Windows Terminal → Settings → Startup → Default profile → **PowerShell**. Check with `$PSVersionTable.PSVersion` (want 7.x). *(CMD and Git Bash can't use these — they're PowerShell functions.)*
82
+ - **Allow the profile to run.** If reloading errors with "running scripts is disabled," run once: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
83
+ - **Watch for OneDrive-redirected Documents.** If your Documents folder syncs to OneDrive, PowerShell's real `$PROFILE` may live under OneDrive. Compare `$PROFILE` in your shell against the path above — if they differ, that's why the launcher isn't found.
84
+
85
+ ### Point a profile at a custom LLM provider
86
+
87
+ Run a profile against z.ai (GLM), mimo, OpenRouter, or any Anthropic-compatible
88
+ endpoint — Claude Code reads the provider config from that profile's `settings.json`,
89
+ and `clp` manages it for you. The easiest path is the **web dashboard**: open a profile
90
+ → **Edit → Provider**, pick a preset (or *Custom*), fill in the base URL, choose a
91
+ keychain secret for the auth token, and optionally map the opus/sonnet/haiku model
92
+ names. You can also **copy provider settings from another profile** in one click.
93
+
94
+ Already configured a provider by hand in `settings.json`? `clp adopt` imports it, and
95
+ `clp secrets migrate` moves the plaintext token into your keychain (the manifest then
96
+ references it as `secret://…`, resolved at apply time):
97
+
98
+ ```bash
99
+ clp adopt --yes # imports each profile's settings.json env, incl. provider config
100
+ clp secrets migrate # moves ANTHROPIC_AUTH_TOKEN / API_KEY into the keychain
101
+ clp doctor # flags any provider token still sitting in plaintext
102
+ ```
103
+
104
+ Under the hood this is a generic per-profile env map written into `settings.json`
105
+ (`ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_DEFAULT_*_MODEL`, …), so
106
+ anything Claude Code supports works — the form just gives the common keys friendly
107
+ labels and a preset for the base URL. It travels with sync and bundles like everything
108
+ else, token included (via the encrypted secrets channel).
109
+
67
110
  ### Replicate to a second machine
68
111
 
69
112
  ```bash
@@ -90,13 +133,19 @@ Two things intentionally don't travel:
90
133
  clp ui # opens http://127.0.0.1:<port>/?t=<token> in your browser
91
134
  ```
92
135
 
93
- A local panel to manage profiles, MCP servers (interactive drift matrix), secrets (add / reveal / delete / migrate), sync, and doctor — everything the CLI does. It's **localhost-only** and guarded by a per-launch session token plus an Origin check, so nothing off your machine (and no website in your browser) can reach the API. Pass `--no-open` to just print the URL, or `--port <n>` to pin the port.
136
+ A local panel to manage everything the CLI does and the easiest way to set profiles up:
137
+
138
+ - **Profiles** — create, edit, and delete profiles from a form: launcher function, environment variables, links, MCP toggles, and a **guided Provider section** (preset picker for z.ai / mimo / OpenRouter / Anthropic-default / Custom, labeled base-URL / token / model fields, copy-from-another-profile, and an *Advanced* raw editor for any other `settings.json` env var). Deleting a profile is manifest-only — the `~/.claude-*` directory stays on disk.
139
+ - **Shell RC** — preview the managed block in your `.zshrc`/`.bashrc` vs. what the manifest renders, with a one-click update.
140
+ - **MCP servers** (interactive drift matrix), **Secrets** (add / reveal / delete / migrate, plus attach a secret to a profile as an env var), **Sync**, and **Doctor**.
141
+
142
+ It's **localhost-only** and guarded by a per-launch session token plus an Origin check, so nothing off your machine (and no website in your browser) can reach the API. Pass `--no-open` to just print the URL, or `--port <n>` to pin the port.
94
143
 
95
144
  ## How it works
96
145
 
97
146
  Three layers of state:
98
147
 
99
- 1. **Live state** — your actual `.claude*` dirs and shell rc files. Claude Code owns these; the tool edits only the keys it manages (`mcpServers`, its marked rc block, its links).
148
+ 1. **Live state** — your actual `.claude*` dirs and shell rc files. Claude Code owns these; the tool edits only the keys it manages (`mcpServers` and the `env` block in `settings.json`, its marked rc block, its links).
100
149
  2. **Manifest** — `~/.ccprofiles/manifest.yaml`, a platform-neutral declaration (paths templated as `{home}`, secrets referenced as `secret://name`). Versioned with local git commits; safe to share.
101
150
  3. **Secrets store** — per-machine keychain: macOS Keychain, Linux `secret-tool` (libsecret), or an AES-256-GCM encrypted file as fallback (native Windows and headless Linux — set `CCPROFILES_PASSPHRASE` in your environment for it). Values never appear in the manifest, bundles, or rc files; launcher functions resolve them at run time by calling the CLI.
102
151
 
@@ -112,7 +161,7 @@ Pairing performs an X25519 ECDH key exchange authenticated by the 6-digit PIN sh
112
161
 
113
162
  | Area | Commands |
114
163
  |---|---|
115
- | Profiles | `list` · `create <name> [--from p]` · `adopt [--yes]` · `doctor` |
164
+ | Profiles | `list` · `create <name> [--from p]` · `adopt [--yes]` · `doctor` (create/edit/delete + provider config: use `clp ui`) |
116
165
  | MCP | `mcp list` · `mcp add/rm <name> [--profile p\|--all]` · `mcp sync --from p --to p1,p2\|--all` |
117
166
  | Secrets | `secrets set/get/list/rm` · `secrets migrate` |
118
167
  | Manifest | `status` · `apply` · `snapshot` |
@@ -129,7 +178,8 @@ All mutating commands support `--dry-run`. Every mutation backs up the files it
129
178
  | `error: no manifest yet` | Run `clp adopt --yes` first — it builds the manifest from your existing profiles |
130
179
  | `zsh: command not found: clp` | Not linked/installed — see Install; if just linked, run `rehash` |
131
180
  | ``cannot reach <host> — is `ccprofiles serve` running?`` | Start `clp serve` on the other device; check you're on the same network and the port matches |
132
- | `encrypted-file backend requires a passphrase` | Set `CCPROFILES_PASSPHRASE` (Windows / Linux without libsecret) |
181
+ | `encrypted-file backend requires a passphrase` | On Windows, secrets use DPAPI automatically (needs PowerShell); otherwise set `CCPROFILES_PASSPHRASE` (headless Linux without libsecret) |
182
+ | `cl-*` launcher not found on Windows | Use PowerShell 7 (`pwsh`), not Windows PowerShell 5.1; reload with `. $PROFILE`; if scripts are blocked run `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`. Confirm `$PROFILE` matches `Documents\PowerShell\Microsoft.PowerShell_profile.ps1` (OneDrive can redirect it) |
133
183
  | Profile shows account `-` after sync | Expected — run `/login` inside that profile once; OAuth sessions don't sync |
134
184
  | Something went wrong after `apply` | Restore from `~/.ccprofiles/backups/<latest>/` |
135
185
 
@@ -137,7 +187,6 @@ All mutating commands support `--dry-run`. Every mutation backs up the files it
137
187
 
138
188
  - mDNS auto-discovery for `clp devices`
139
189
  - Pair devices from the dashboard (currently CLI-only)
140
- - Windows Credential Manager (DPAPI) secrets backend
141
190
  - Interactive prompts (`secrets set` without echoing, `adopt` confirmation)
142
191
 
143
192
  ## Development
@@ -150,10 +199,6 @@ npm test # vitest — unit + e2e (incl. an in-process two-machine sync te
150
199
  npm run build # builds core + cli + the dashboard, bundled into the CLI
151
200
  ```
152
201
 
153
- ## Related projects
154
-
155
- Not to be confused with [samhvw8/claude-code-profile](https://github.com/samhvw8/claude-code-profile) (the `ccp` command) — a great tool for a **different** job: a central hub of reusable skills/agents/hooks/commands, with profiles for different *workflows*. It explicitly does **not** handle MCP servers, secrets, LAN sync, or multiple *accounts* — which are exactly this tool's focus. The two are complementary; this one deliberately uses the `clp` / `ccprofiles` commands to avoid clashing with its `ccp`.
156
-
157
202
  ## License
158
203
 
159
204
  MIT
package/dist/context.js CHANGED
@@ -11,7 +11,17 @@ import { registerBundleCommands } from './commands/bundle.js';
11
11
  import { registerUiCommand } from './ui/command.js';
12
12
  export function makeContext(env = process.env) {
13
13
  const testHome = env.CCPROFILES_TEST_HOME;
14
- const platform = detectPlatform(testHome ? { home: testHome, shell: env.SHELL } : {});
14
+ // CCPROFILES_FORCE_OS is a test-only seam for simulating other platforms' secrets-backend
15
+ // selection from a single dev machine — never set this outside tests. It intentionally
16
+ // accepts any sentinel string (not just OsKind): detectPlatform/defaultBackend only ever
17
+ // compare it against 'darwin'/'linux'/'win32' at runtime, so a value like 'none' safely
18
+ // flows through as a deterministic "none of the above" platform for tests. Gated behind
19
+ // CCPROFILES_TEST_HOME (the existing test-only signal) so it can never affect production.
20
+ const forcedOs = testHome ? env.CCPROFILES_FORCE_OS : undefined;
21
+ const platform = detectPlatform({
22
+ ...(testHome ? { home: testHome, shell: env.SHELL } : {}),
23
+ ...(forcedOs ? { osKind: forcedOs } : {}),
24
+ });
15
25
  const manifestRoot = env.CCPROFILES_HOME ?? join(platform.home, '.ccprofiles');
16
26
  return {
17
27
  home: platform.home,
package/dist/ui/api.js CHANGED
@@ -304,7 +304,13 @@ export function buildRoutes(ctx) {
304
304
  });
305
305
  // ── secrets ─────────────────────────────────────────────────────────────────
306
306
  add('GET', /^\/api\/secrets$/, async (_m, _req, res) => {
307
- const store = await secretsStore(ctx);
307
+ let store;
308
+ try {
309
+ store = await secretsStore(ctx);
310
+ }
311
+ catch (e) {
312
+ return sendJson(res, 200, { names: [], backend: 'unavailable', error: e.message });
313
+ }
308
314
  sendJson(res, 200, { names: await store.list(), backend: store.backendName });
309
315
  });
310
316
  add('GET', /^\/api\/secrets\/([^/]+)$/, async (mtch, _req, res) => {
@@ -138,6 +138,6 @@ Error generating stack: `+l.message+`
138
138
  *
139
139
  * This source code is licensed under the ISC license.
140
140
  * See the LICENSE file in the root directory of this source tree.
141
- */const Aa=un("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),dr=wp,za=kp,jn=g.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Cp,{children:[u.jsx(Np,{className:"fixed inset-0 z-50 bg-black/70 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),u.jsxs(jp,{ref:r,className:ve("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 border bg-background p-6 shadow-lg rounded-lg",e),...n,children:[t,u.jsxs(Op,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100",children:[u.jsx(Aa,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));jn.displayName="DialogContent";function fr({className:e,...t}){return u.jsx("div",{className:ve("flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function pr({className:e,...t}){return u.jsx("div",{className:ve("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}const Pn=g.forwardRef(({className:e,...t},n)=>u.jsx(_p,{ref:n,className:ve("text-lg font-semibold leading-none tracking-tight",e),...t}));Pn.displayName="DialogTitle";const ye=g.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,ref:r,className:ve("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),...n}));ye.displayName="Input";var _0="Label",Lp=g.forwardRef((e,t)=>u.jsx(Ke.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Lp.displayName=_0;var T0=Lp;const Pe=g.forwardRef(({className:e,...t},n)=>u.jsx(T0,{ref:n,className:ve("text-sm font-medium leading-none",e),...t}));Pe.displayName="Label";const Oi="secret://",Mi=[{id:"zai",label:"z.ai (GLM)",baseUrl:"https://api.z.ai/api/anthropic",tokenVar:"ANTHROPIC_AUTH_TOKEN"},{id:"mimo",label:"mimo",baseUrl:"https://token-plan-sgp.xiaomimimo.com/anthropic",tokenVar:"ANTHROPIC_AUTH_TOKEN"},{id:"openrouter",label:"OpenRouter",baseUrl:"https://openrouter.ai/api",tokenVar:"ANTHROPIC_AUTH_TOKEN"}],xn={opus:"ANTHROPIC_DEFAULT_OPUS_MODEL",sonnet:"ANTHROPIC_DEFAULT_SONNET_MODEL",haiku:"ANTHROPIC_DEFAULT_HAIKU_MODEL"},R0=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN","ANTHROPIC_API_KEY",xn.opus,xn.sonnet,xn.haiku,"API_TIMEOUT_MS"];function Ip(){return{baseUrl:"",tokenVar:"ANTHROPIC_AUTH_TOKEN",token:{secret:!0,value:""},models:{opus:"",sonnet:"",haiku:""},timeoutMs:""}}function Li(e){const t={};for(const[l,s]of Object.entries(e))R0.includes(l)||(t[l]=s);const n=e.ANTHROPIC_API_KEY!==void 0&&e.ANTHROPIC_AUTH_TOKEN===void 0?"ANTHROPIC_API_KEY":"ANTHROPIC_AUTH_TOKEN",r=n==="ANTHROPIC_AUTH_TOKEN"?"ANTHROPIC_API_KEY":"ANTHROPIC_AUTH_TOKEN";e[r]!==void 0&&(t[r]=e[r]);const o=e[n]??"";return{form:{baseUrl:e.ANTHROPIC_BASE_URL??"",tokenVar:n,token:o.startsWith(Oi)?{secret:!0,value:o.slice(Oi.length)}:{secret:o==="",value:o},models:{opus:e[xn.opus]??"",sonnet:e[xn.sonnet]??"",haiku:e[xn.haiku]??""},timeoutMs:e.API_TIMEOUT_MS??""},advanced:t}}function O0(e,t){const n={...t};e.baseUrl.trim()&&(n.ANTHROPIC_BASE_URL=e.baseUrl.trim()),e.token.value.trim()&&(n[e.tokenVar]=e.token.secret?Oi+e.token.value.trim():e.token.value.trim());for(const r of["opus","sonnet","haiku"])e.models[r].trim()&&(n[xn[r]]=e.models[r].trim());return e.timeoutMs.trim()&&(n.API_TIMEOUT_MS=e.timeoutMs.trim()),n}function jc(e){var t;return e?((t=Mi.find(n=>n.baseUrl===e))==null?void 0:t.id)??"custom":"anthropic"}function M0(e,t){return{...Ip(),baseUrl:t.baseUrl,tokenVar:t.tokenVar,token:e.token}}function L0(e){return{...Li(e).form,token:{secret:!0,value:""}}}function Uo({children:e}){return u.jsx("div",{className:"text-[11px] text-muted-foreground font-mono",children:e})}function I0({form:e,onChange:t,secretNames:n,copySources:r}){const[o,l]=g.useState(()=>jc(e.baseUrl)),s=i=>{if(i.startsWith("copy:")){const a=r.find(c=>c.name===i.slice(5));if(a){const c=L0(a.env);l(jc(c.baseUrl)),t(c)}return}if(l(i),i==="anthropic")t(Ip());else{const a=Mi.find(c=>c.id===i);a&&t(M0(e,a))}};return u.jsxs("div",{className:"space-y-3",children:[u.jsxs("select",{className:"w-full border rounded-md h-9 px-2 bg-background text-sm",value:o,onChange:i=>s(i.target.value),children:[u.jsx("option",{value:"anthropic",children:"Anthropic (default)"}),Mi.map(i=>u.jsx("option",{value:i.id,children:i.label},i.id)),u.jsx("option",{value:"custom",children:"Custom…"}),r.length>0&&u.jsx("option",{disabled:!0,children:"── copy from ──"}),r.map(i=>u.jsxs("option",{value:`copy:${i.name}`,children:["copy from ",i.name]},i.name))]}),o==="anthropic"?u.jsx("p",{className:"text-xs text-muted-foreground",children:"Uses Anthropic's API with this profile's normal auth — no provider overrides."}):u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsx(ye,{className:"font-mono text-xs",value:e.baseUrl,placeholder:"https://provider.example.com/anthropic",onChange:i=>t({...e,baseUrl:i.target.value})}),u.jsx(Uo,{children:"ANTHROPIC_BASE_URL"})]}),u.jsxs("div",{className:"space-y-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[e.token.secret?u.jsxs("select",{className:"flex-1 border rounded-md h-9 px-2 bg-background text-sm",value:e.token.value,onChange:i=>t({...e,token:{secret:!0,value:i.target.value}}),children:[u.jsx("option",{value:"",children:"— pick secret (token) —"}),n.map(i=>u.jsx("option",{value:i,children:i},i))]}):u.jsx(ye,{className:"flex-1 font-mono text-xs",type:"password",value:e.token.value,placeholder:"auth token",onChange:i=>t({...e,token:{secret:!1,value:i.target.value}})}),u.jsxs("label",{className:"flex items-center gap-1 text-xs text-muted-foreground whitespace-nowrap",children:[u.jsx("input",{type:"checkbox",checked:e.token.secret,onChange:i=>t({...e,token:{secret:i.target.checked,value:""}})}),"secret"]}),o==="custom"&&u.jsxs("select",{className:"border rounded-md h-9 px-2 bg-background text-xs",value:e.tokenVar,onChange:i=>t({...e,tokenVar:i.target.value}),children:[u.jsx("option",{value:"ANTHROPIC_AUTH_TOKEN",children:"AUTH_TOKEN"}),u.jsx("option",{value:"ANTHROPIC_API_KEY",children:"API_KEY"})]})]}),u.jsx(Uo,{children:e.tokenVar})]}),u.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(i=>u.jsxs("div",{className:"space-y-1",children:[u.jsx(ye,{className:"font-mono text-xs",value:e.models[i],placeholder:`${i} model`,onChange:a=>t({...e,models:{...e.models,[i]:a.target.value}})}),u.jsxs(Uo,{children:["ANTHROPIC_DEFAULT_",i.toUpperCase(),"_MODEL"]})]},i))}),u.jsxs("div",{className:"space-y-1",children:[u.jsx(ye,{className:"font-mono text-xs w-40",value:e.timeoutMs,placeholder:"timeout ms (optional)",onChange:i=>t({...e,timeoutMs:i.target.value})}),u.jsx(Uo,{children:"API_TIMEOUT_MS"})]})]})]})}const Ii="secret://";function Pc(e){return Object.entries(e).map(([t,n])=>n.startsWith(Ii)?{key:t,value:n.slice(Ii.length),secret:!0}:{key:t,value:n,secret:!1})}function bc(e){const t={};for(const n of e)n.key.trim()&&(t[n.key.trim()]=n.secret?Ii+n.value:n.value);return t}function _c({rows:e,onChange:t,secretNames:n,keyPlaceholder:r}){const o=(l,s)=>t(e.map((i,a)=>a===l?{...i,...s}:i));return u.jsxs(u.Fragment,{children:[e.map((l,s)=>u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ye,{className:"w-56 font-mono text-xs",value:l.key,onChange:i=>o(s,{key:i.target.value}),placeholder:r}),l.secret?u.jsxs("select",{className:"flex-1 border rounded-md h-9 px-2 bg-background text-sm",value:l.value,onChange:i=>o(s,{value:i.target.value}),children:[u.jsx("option",{value:"",children:"— pick secret —"}),n.map(i=>u.jsx("option",{value:i,children:i},i))]}):u.jsx(ye,{className:"flex-1 font-mono text-xs",value:l.value,onChange:i=>o(s,{value:i.target.value})}),u.jsxs("label",{className:"flex items-center gap-1 text-xs text-muted-foreground whitespace-nowrap",children:[u.jsx("input",{type:"checkbox",checked:l.secret,onChange:i=>o(s,{secret:i.target.checked,value:""})}),"secret"]}),u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>t(e.filter((i,a)=>a!==s)),children:u.jsx(Aa,{className:"h-4 w-4"})})]},s)),u.jsx(K,{size:"sm",variant:"secondary",onClick:()=>t([...e,{key:"",value:"",secret:!1}]),children:"Add env var"})]})}function A0({profile:e,profiles:t,servers:n,secretNames:r,onClose:o,onSaved:l}){const[s,i]=g.useState(e.launcher??""),[a,c]=g.useState(Pc(e.env)),p=Object.keys(e.settingsEnv).length?e.settingsEnv:e.liveSettingsEnv,[h,v]=g.useState(()=>Li(p).form),[f,w]=g.useState(()=>Pc(Li(p).advanced)),[x,C]=g.useState(Object.entries(e.links).map(([E,N])=>({key:E,value:N}))),[m,d]=g.useState(e.mcpNames),[y,k]=g.useState(!1),j=(E,N)=>C(x.map((L,O)=>O===E?{...L,...N}:L)),S=async()=>{for(const E of[...a,...f])if(E.secret&&!E.value){$.error(`pick a secret for ${E.key||"env var"}`);return}k(!0);try{const E={};for(const N of x)N.key.trim()&&(E[N.key.trim()]=N.value);await Q.patchProfile(e.name,{env:bc(a),settingsEnv:O0(h,bc(f)),links:E,launcher:s.trim()||null});for(const N of m.filter(L=>!e.mcpNames.includes(L)))await Q.addMcp({name:N,targets:[e.name]});for(const N of e.mcpNames.filter(L=>!m.includes(L)))await Q.rmMcp(N,[e.name]);$.success(`Saved ${e.name}`),l()}catch(E){$.error(E.message)}finally{k(!1)}};return u.jsx(dr,{open:!0,onOpenChange:E=>{E||o()},children:u.jsxs(jn,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[u.jsx(fr,{children:u.jsxs(Pn,{children:["Edit ",e.name]})}),u.jsxs("div",{className:"space-y-5",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Launcher function"}),u.jsx(ye,{value:s,onChange:E=>i(E.target.value),placeholder:"cl-work (empty = no launcher)"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Launcher env (exported by the shell function)"}),u.jsx(_c,{rows:a,onChange:c,secretNames:r,keyPlaceholder:"ANTHROPIC_API_KEY"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Provider"}),u.jsx("p",{className:"text-xs text-muted-foreground",children:"Where this profile's Claude Code sends requests — written into settings.json. Secret tokens resolve from the keychain on apply."}),u.jsx(I0,{form:h,onChange:v,secretNames:r,copySources:t.filter(E=>E.name!==e.name).map(E=>({name:E.name,env:Object.keys(E.settingsEnv).length?E.settingsEnv:E.liveSettingsEnv})).filter(E=>E.env.ANTHROPIC_BASE_URL)}),u.jsxs("details",{className:"pt-1",children:[u.jsxs("summary",{className:"text-xs text-muted-foreground cursor-pointer select-none",children:["Advanced — other settings.json env vars (",f.length,")"]}),u.jsx("div",{className:"space-y-1.5 pt-2",children:u.jsx(_c,{rows:f,onChange:w,secretNames:r,keyPlaceholder:"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"})})]})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Links"}),x.map((E,N)=>u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ye,{className:"w-56 font-mono text-xs",value:E.key,onChange:L=>j(N,{key:L.target.value}),placeholder:"skills"}),u.jsx(ye,{className:"flex-1 font-mono text-xs",value:E.value,onChange:L=>j(N,{value:L.target.value}),placeholder:"hub or a path"}),u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>C(x.filter((L,O)=>O!==N)),children:u.jsx(Aa,{className:"h-4 w-4"})})]},N)),u.jsx(K,{size:"sm",variant:"secondary",onClick:()=>C([...x,{key:"",value:""}]),children:"Add link"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"MCP servers"}),u.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[n.map(E=>u.jsxs("label",{className:"flex items-center gap-2 text-sm font-mono",children:[u.jsx("input",{type:"checkbox",checked:m.includes(E),onChange:N=>d(N.target.checked?[...m,E]:m.filter(L=>L!==E))}),E]},E)),n.length===0&&u.jsx("div",{className:"text-sm text-muted-foreground",children:"No servers in manifest."})]})]})]}),u.jsxs(pr,{children:[u.jsx(K,{variant:"secondary",onClick:o,children:"Cancel"}),u.jsx(K,{disabled:y,onClick:S,children:y?"Saving…":"Save & apply"})]})]})})}function z0(e){var n;const t=(n=e.settingsEnv)==null?void 0:n.ANTHROPIC_BASE_URL;if(!t)return"—";try{return new URL(t).host}catch{return t}}function D0(){const[e,t]=g.useState([]),[n,r]=g.useState([]),[o,l]=g.useState([]),[s,i]=g.useState(""),[a,c]=g.useState(""),[p,h]=g.useState(!1),[v,f]=g.useState(null),[w,x]=g.useState(null),C=async()=>{try{t(await Q.profiles())}catch(d){$.error(d.message)}try{r((await Q.mcp()).servers)}catch{r([])}try{l((await Q.secrets()).names)}catch{l([])}};g.useEffect(()=>{C()},[]);const m=async d=>{try{await Q.deleteProfile(d.name),$.success(`Removed ${d.name} from manifest`),x(null),C()}catch(y){$.error(y.message)}};return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h1",{className:"text-xl font-semibold",children:"Profiles"}),u.jsxs(dr,{open:p,onOpenChange:h,children:[u.jsx(za,{asChild:!0,children:u.jsx(K,{children:"Create profile"})}),u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsx(Pn,{children:"New profile"})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Name"}),u.jsx(ye,{value:s,onChange:d=>i(d.target.value),placeholder:"work"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Copy MCP / links from (optional)"}),u.jsxs("select",{className:"w-full border rounded-md h-9 px-2 bg-background text-sm",value:a,onChange:d=>c(d.target.value),children:[u.jsx("option",{value:"",children:"— none —"}),e.map(d=>u.jsx("option",{value:d.name,children:d.name},d.name))]})]})]}),u.jsx(pr,{children:u.jsx(K,{onClick:async()=>{try{await Q.createProfile(s,a||void 0),$.success(`Created ${s}`),h(!1),i(""),c(""),C()}catch(d){$.error(d.message)}},children:"Create"})})]})]})]}),u.jsxs(ep,{children:[u.jsx(tp,{children:u.jsxs(_i,{children:[u.jsx(St,{children:"Name"}),u.jsx(St,{children:"Auth"}),u.jsx(St,{children:"Account"}),u.jsx(St,{children:"MCP"}),u.jsx(St,{children:"Launcher"}),u.jsx(St,{children:"Provider"}),u.jsx(St,{children:"Env"}),u.jsx(St,{className:"w-32"})]})}),u.jsx(np,{children:e.map(d=>u.jsxs(_i,{children:[u.jsxs(kt,{className:"font-medium",children:[d.name,!d.adopted&&u.jsx("span",{className:"text-muted-foreground",title:"not in manifest — adopt to manage",children:" *"})]}),u.jsx(kt,{children:d.auth}),u.jsx(kt,{className:"text-muted-foreground",children:d.account??"—"}),u.jsx(kt,{children:d.mcp}),u.jsx(kt,{className:"font-mono text-xs",children:d.launcher??"—"}),u.jsx(kt,{className:"font-mono text-xs text-muted-foreground",children:z0(d)}),u.jsx(kt,{className:"font-mono text-xs text-muted-foreground",children:Object.keys(d.env).length||"—"}),u.jsx(kt,{children:u.jsxs("div",{className:"flex gap-1 justify-end",children:[u.jsx("span",{title:d.adopted?void 0:"Adopt first",children:u.jsx(K,{size:"sm",variant:"ghost",disabled:!d.adopted,onClick:()=>f(d),children:"Edit"})}),u.jsx("span",{title:d.adopted?void 0:"Adopt first",children:u.jsx(K,{size:"sm",variant:"ghost",disabled:!d.adopted,onClick:()=>x(d),children:"Delete"})})]})})]},d.name))})]}),v&&u.jsx(A0,{profile:v,profiles:e,servers:n,secretNames:o,onClose:()=>f(null),onSaved:()=>{f(null),C()}}),w&&u.jsx(dr,{open:!0,onOpenChange:d=>{d||x(null)},children:u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsxs(Pn,{children:['Delete profile "',w.name,'"?']})}),u.jsxs("p",{className:"text-sm text-muted-foreground",children:["Removes it from the manifest and drops its launcher from your shell rc on apply. The directory ",u.jsx("span",{className:"font-mono",children:w.dir})," stays on disk — re-adopt to manage it again."]}),u.jsxs(pr,{children:[u.jsx(K,{variant:"secondary",onClick:()=>x(null),children:"Cancel"}),u.jsx(K,{variant:"destructive",onClick:()=>m(w),children:"Delete"})]})]})})]})}function F0(e){const t=g.useRef({value:e,previous:e});return g.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function $0(e){const[t,n]=g.useState(void 0);return Nn(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const l=o[0];let s,i;if("borderBoxSize"in l){const a=l.borderBoxSize,c=Array.isArray(a)?a[0]:a;s=c.inlineSize,i=c.blockSize}else s=e.offsetWidth,i=e.offsetHeight;n({width:s,height:i})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Yl="Switch",[U0]=rp(Yl),[B0,Da]=U0(Yl);function H0(e){const{__scopeSwitch:t,checked:n,children:r,defaultChecked:o,disabled:l,form:s,name:i,onCheckedChange:a,required:c,value:p="on",internal_do_not_use_render:h}=e,[v,f]=op({prop:n,defaultProp:o??!1,onChange:a,caller:Yl}),[w,x]=g.useState(null),[C,m]=g.useState(null),d=g.useRef(!1),y=w?!!s||!!w.closest("form"):!0,k={checked:v,setChecked:f,disabled:l,control:w,setControl:x,name:i,form:s,value:p,hasConsumerStoppedPropagationRef:d,required:c,defaultChecked:o,isFormControl:y,bubbleInput:C,setBubbleInput:m};return u.jsx(B0,{scope:t,...k,children:V0(h)?h(k):r})}var Ap="SwitchTrigger",zp=g.forwardRef(({__scopeSwitch:e,onClick:t,...n},r)=>{const{value:o,disabled:l,checked:s,required:i,setControl:a,setChecked:c,hasConsumerStoppedPropagationRef:p,isFormControl:h,bubbleInput:v}=Da(Ap,e),f=Lt(r,a);return u.jsx(Ke.button,{type:"button",role:"switch","aria-checked":s,"aria-required":i,"data-state":Hp(s),"data-disabled":l?"":void 0,disabled:l,value:o,...n,ref:f,onClick:bt(t,w=>{c(x=>!x),v&&h&&(p.current=w.isPropagationStopped(),p.current||w.stopPropagation())})})});zp.displayName=Ap;var Dp=g.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:l,required:s,disabled:i,value:a,onCheckedChange:c,form:p,...h}=e;return u.jsx(H0,{__scopeSwitch:n,checked:o,defaultChecked:l,disabled:i,required:s,onCheckedChange:c,name:r,form:p,value:a,internal_do_not_use_render:({isFormControl:v})=>u.jsxs(u.Fragment,{children:[u.jsx(zp,{...h,ref:t,__scopeSwitch:n}),v&&u.jsx(Bp,{__scopeSwitch:n})]})})});Dp.displayName=Yl;var Fp="SwitchThumb",$p=g.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Da(Fp,n);return u.jsx(Ke.span,{"data-state":Hp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$p.displayName=Fp;var Up="SwitchBubbleInput",Bp=g.forwardRef(({__scopeSwitch:e,...t},n)=>{const{control:r,hasConsumerStoppedPropagationRef:o,checked:l,defaultChecked:s,required:i,disabled:a,name:c,value:p,form:h,bubbleInput:v,setBubbleInput:f}=Da(Up,e),w=Lt(n,f),x=F0(l),C=$0(r);g.useEffect(()=>{const d=v;if(!d)return;const y=window.HTMLInputElement.prototype,j=Object.getOwnPropertyDescriptor(y,"checked").set,S=!o.current;if(x!==l&&j){const E=new Event("click",{bubbles:S});j.call(d,l),d.dispatchEvent(E)}},[v,x,l,o]);const m=g.useRef(l);return u.jsx(Ke.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??m.current,required:i,disabled:a,name:c,value:p,form:h,...t,tabIndex:-1,ref:w,style:{...t.style,...C,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Bp.displayName=Up;function V0(e){return typeof e=="function"}function Hp(e){return e?"checked":"unchecked"}const Fa=g.forwardRef(({className:e,...t},n)=>u.jsx(Dp,{className:ve("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx($p,{className:"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})}));Fa.displayName="Switch";function W0(){const[e,t]=g.useState(null),[n,r]=g.useState(!1),[o,l]=g.useState({name:"",command:"npx",args:""}),[s,i]=g.useState(""),a=async()=>{try{t(await Q.mcp())}catch(p){$.error(p.message)}};if(g.useEffect(()=>{a()},[]),!e)return null;const c=async(p,h,v)=>{try{v?await Q.addMcp({name:p,targets:[h]}):await Q.rmMcp(p,[h]),await a()}catch(f){$.error(f.message)}};return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[u.jsx("h1",{className:"text-xl font-semibold",children:"MCP servers"}),u.jsxs("div",{className:"flex gap-2 items-center",children:[u.jsxs("select",{className:"border rounded-md h-9 px-2 bg-background text-sm",value:s,onChange:p=>i(p.target.value),children:[u.jsx("option",{value:"",children:"sync from…"}),e.profiles.map(p=>u.jsx("option",{value:p.name,children:p.name},p.name))]}),u.jsx(K,{variant:"secondary",disabled:!s,onClick:async()=>{try{await Q.syncMcp(s,"all"),$.success(`Synced from ${s}`),await a()}catch(p){$.error(p.message)}},children:"Sync → all"}),u.jsxs(dr,{open:n,onOpenChange:r,children:[u.jsx(za,{asChild:!0,children:u.jsx(K,{children:"Add server"})}),u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsx(Pn,{children:"Add MCP server"})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Name"}),u.jsx(ye,{value:o.name,onChange:p=>l({...o,name:p.target.value}),placeholder:"shadcn"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Command"}),u.jsx(ye,{value:o.command,onChange:p=>l({...o,command:p.target.value})})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Args (comma-separated)"}),u.jsx(ye,{value:o.args,onChange:p=>l({...o,args:p.target.value}),placeholder:"-y,@playwright/mcp@latest"})]})]}),u.jsx(pr,{children:u.jsx(K,{onClick:async()=>{try{await Q.addMcp({name:o.name,command:o.command,args:o.args?o.args.split(","):[],targets:"all"}),$.success(`Added ${o.name}`),r(!1),l({name:"",command:"npx",args:""}),await a()}catch(p){$.error(p.message)}},children:"Add to all"})})]})]})]})]}),u.jsx("div",{className:"overflow-x-auto border rounded-lg",children:u.jsxs("table",{className:"text-sm border-collapse w-full",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b",children:[u.jsx("th",{className:"text-left p-3 font-medium",children:"Server"}),e.profiles.map(p=>u.jsx("th",{className:"p-3 text-center font-medium",children:p.name},p.name))]})}),u.jsxs("tbody",{children:[e.servers.map(p=>u.jsxs("tr",{className:"border-b last:border-0",children:[u.jsx("td",{className:"p-3 font-mono",children:p}),e.profiles.map(h=>u.jsx("td",{className:"p-3 text-center",children:u.jsx(Fa,{checked:h.has.includes(p),onCheckedChange:v=>c(p,h.name,v)})},h.name))]},p)),e.servers.length===0&&u.jsx("tr",{children:u.jsx("td",{className:"p-3 text-muted-foreground",colSpan:e.profiles.length+1,children:"No MCP servers yet."})})]})]})})]})}const K0=qf("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ai({className:e,variant:t,...n}){return u.jsx("div",{className:ve(K0({variant:t}),e),...n})}const Ls="secret://";function Q0(){const[e,t]=g.useState([]),[n,r]=g.useState(""),[o,l]=g.useState([]),[s,i]=g.useState({}),[a,c]=g.useState(!1),[p,h]=g.useState({name:"",value:""}),[v,f]=g.useState(null),[w,x]=g.useState({profile:"",envKey:"ANTHROPIC_API_KEY"}),C=async()=>{try{const S=await Q.secrets();t(S.names),r(S.backend)}catch(S){$.error(S.message)}try{l(await Q.profiles())}catch{l([])}};g.useEffect(()=>{C()},[]);const m=S=>o.flatMap(E=>[...Object.entries(E.env).filter(([,N])=>N===Ls+S).map(([N])=>({profile:E.name,envKey:N,map:"env"})),...Object.entries(E.settingsEnv).filter(([,N])=>N===Ls+S).map(([N])=>({profile:E.name,envKey:N,map:"settingsEnv"}))]),d=async S=>{if(s[S]!==void 0){const E={...s};delete E[S],i(E);return}try{const E=await Q.revealSecret(S);i({...s,[S]:E.value})}catch(E){$.error(E.message)}},y=async()=>{if(!v||!w.profile||!w.envKey.trim())return;const S=o.find(E=>E.name===w.profile);if(S)try{await Q.patchProfile(S.name,{env:{...S.env,[w.envKey.trim()]:Ls+v}}),$.success(`Attached ${v} to ${S.name} as ${w.envKey.trim()}`),f(null),x({profile:"",envKey:"ANTHROPIC_API_KEY"}),C()}catch(E){$.error(E.message)}},k=async(S,E)=>{const N=o.find(O=>O.name===E.profile);if(!N)return;const L=E.map==="env"?{env:(()=>{const O={...N.env};return delete O[E.envKey],O})()}:{settingsEnv:(()=>{const O={...N.settingsEnv};return delete O[E.envKey],O})()};try{await Q.patchProfile(N.name,L),$.success(`Detached ${S} from ${E.profile}`),C()}catch(O){$.error(O.message)}},j=o.filter(S=>S.adopted);return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("h1",{className:"text-xl font-semibold flex items-center gap-2",children:["Secrets ",u.jsx(Ai,{variant:"secondary",children:n})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(K,{variant:"secondary",onClick:async()=>{try{const S=await Q.migrate();$.success(S.migrated.length?`Migrated ${S.migrated.join(", ")}`:"No plaintext keys found"),C()}catch(S){$.error(S.message)}},children:"Migrate plaintext keys"}),u.jsxs(dr,{open:a,onOpenChange:c,children:[u.jsx(za,{asChild:!0,children:u.jsx(K,{children:"Add secret"})}),u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsx(Pn,{children:"Add secret"})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Name"}),u.jsx(ye,{value:p.name,onChange:S=>h({...p,name:S.target.value}),placeholder:"anthropic-api-key"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Value"}),u.jsx(ye,{type:"password",value:p.value,onChange:S=>h({...p,value:S.target.value})})]})]}),u.jsx(pr,{children:u.jsx(K,{onClick:async()=>{try{await Q.setSecret(p.name,p.value),$.success(`Stored ${p.name}`),c(!1),h({name:"",value:""}),C()}catch(S){$.error(S.message)}},children:"Save"})})]})]})]})]}),u.jsxs("div",{className:"divide-y border rounded-lg",children:[e.map(S=>{const E=m(S);return u.jsxs("div",{className:"flex items-center justify-between p-3 gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("div",{className:"font-mono text-sm",children:[S,s[S]!==void 0&&u.jsx("span",{className:"ml-3 text-muted-foreground",children:s[S]})]}),E.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:E.map(N=>u.jsxs(Ai,{variant:"secondary",className:"font-mono text-[11px] gap-1",children:[N.profile," · ",N.envKey,N.map==="settingsEnv"&&u.jsx("span",{className:"text-muted-foreground",children:" (settings)"}),u.jsx("button",{className:"ml-0.5 hover:text-foreground",title:"Detach",onClick:()=>k(S,N),children:"×"})]},`${N.profile}-${N.map}-${N.envKey}`))})]}),u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>f(S),children:"Attach"}),u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>d(S),children:s[S]!==void 0?"Hide":"Reveal"}),u.jsx(K,{size:"sm",variant:"ghost",onClick:async()=>{try{await Q.rmSecret(S),$.success(`Removed ${S}`),C()}catch(N){$.error(N.message)}},children:"Delete"})]})]},S)}),e.length===0&&u.jsx("div",{className:"p-3 text-sm text-muted-foreground",children:"No secrets yet."})]}),v&&u.jsx(dr,{open:!0,onOpenChange:S=>{S||f(null)},children:u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsxs(Pn,{children:["Attach ",v," to a profile"]})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Profile"}),u.jsxs("select",{className:"w-full border rounded-md h-9 px-2 bg-background text-sm",value:w.profile,onChange:S=>x({...w,profile:S.target.value}),children:[u.jsx("option",{value:"",children:"— pick profile —"}),j.map(S=>u.jsx("option",{value:S.name,children:S.name},S.name))]})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Env var name"}),u.jsx(ye,{className:"font-mono",value:w.envKey,onChange:S=>x({...w,envKey:S.target.value})})]}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["The launcher will export it as ",u.jsxs("span",{className:"font-mono",children:[w.envKey||"VAR",'="$(ccprofiles secrets get ',v,')"']})," — the value never lands in your rc file."]})]}),u.jsxs(pr,{children:[u.jsx(K,{variant:"secondary",onClick:()=>f(null),children:"Cancel"}),u.jsx(K,{disabled:!w.profile||!w.envKey.trim(),onClick:y,children:"Attach"})]})]})})]})}function Tc({title:e,lines:t,otherLines:n,tint:r}){return u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"text-sm font-medium mb-1.5",children:e}),u.jsx("pre",{className:"border rounded-lg p-3 text-xs font-mono overflow-x-auto whitespace-pre",children:t.map((o,l)=>u.jsx("div",{className:ve("px-1 -mx-1 rounded-sm",!n.has(o)&&o.trim()!==""&&r),children:o||" "},l))})]})}function Y0(){const[e,t]=g.useState(null),[n,r]=g.useState(!1),[o,l]=g.useState(null),s=async()=>{try{t(await Q.rc()),l(null)}catch(c){l(c.message),$.error(c.message)}};if(g.useEffect(()=>{s()},[]),o)return u.jsx("div",{className:"text-sm text-muted-foreground",children:"No manifest yet — adopt your profiles first."});if(!e)return u.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading…"});const i=(e.current??"").split(`
141
+ */const Aa=un("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),dr=wp,za=kp,jn=g.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Cp,{children:[u.jsx(Np,{className:"fixed inset-0 z-50 bg-black/70 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),u.jsxs(jp,{ref:r,className:ve("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 border bg-background p-6 shadow-lg rounded-lg",e),...n,children:[t,u.jsxs(Op,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100",children:[u.jsx(Aa,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));jn.displayName="DialogContent";function fr({className:e,...t}){return u.jsx("div",{className:ve("flex flex-col space-y-1.5 text-center sm:text-left",e),...t})}function pr({className:e,...t}){return u.jsx("div",{className:ve("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}const Pn=g.forwardRef(({className:e,...t},n)=>u.jsx(_p,{ref:n,className:ve("text-lg font-semibold leading-none tracking-tight",e),...t}));Pn.displayName="DialogTitle";const ye=g.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,ref:r,className:ve("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),...n}));ye.displayName="Input";var _0="Label",Lp=g.forwardRef((e,t)=>u.jsx(Ke.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Lp.displayName=_0;var T0=Lp;const Pe=g.forwardRef(({className:e,...t},n)=>u.jsx(T0,{ref:n,className:ve("text-sm font-medium leading-none",e),...t}));Pe.displayName="Label";const Oi="secret://",Mi=[{id:"zai",label:"z.ai (GLM)",baseUrl:"https://api.z.ai/api/anthropic",tokenVar:"ANTHROPIC_AUTH_TOKEN"},{id:"mimo",label:"mimo",baseUrl:"https://token-plan-sgp.xiaomimimo.com/anthropic",tokenVar:"ANTHROPIC_AUTH_TOKEN"},{id:"openrouter",label:"OpenRouter",baseUrl:"https://openrouter.ai/api",tokenVar:"ANTHROPIC_AUTH_TOKEN"}],xn={opus:"ANTHROPIC_DEFAULT_OPUS_MODEL",sonnet:"ANTHROPIC_DEFAULT_SONNET_MODEL",haiku:"ANTHROPIC_DEFAULT_HAIKU_MODEL"},R0=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN","ANTHROPIC_API_KEY",xn.opus,xn.sonnet,xn.haiku,"API_TIMEOUT_MS"];function Ip(){return{baseUrl:"",tokenVar:"ANTHROPIC_AUTH_TOKEN",token:{secret:!0,value:""},models:{opus:"",sonnet:"",haiku:""},timeoutMs:""}}function Li(e){const t={};for(const[l,s]of Object.entries(e))R0.includes(l)||(t[l]=s);const n=e.ANTHROPIC_API_KEY!==void 0&&e.ANTHROPIC_AUTH_TOKEN===void 0?"ANTHROPIC_API_KEY":"ANTHROPIC_AUTH_TOKEN",r=n==="ANTHROPIC_AUTH_TOKEN"?"ANTHROPIC_API_KEY":"ANTHROPIC_AUTH_TOKEN";e[r]!==void 0&&(t[r]=e[r]);const o=e[n]??"";return{form:{baseUrl:e.ANTHROPIC_BASE_URL??"",tokenVar:n,token:o.startsWith(Oi)?{secret:!0,value:o.slice(Oi.length)}:{secret:o==="",value:o},models:{opus:e[xn.opus]??"",sonnet:e[xn.sonnet]??"",haiku:e[xn.haiku]??""},timeoutMs:e.API_TIMEOUT_MS??""},advanced:t}}function O0(e,t){const n={...t};e.baseUrl.trim()&&(n.ANTHROPIC_BASE_URL=e.baseUrl.trim()),e.token.value.trim()&&(n[e.tokenVar]=e.token.secret?Oi+e.token.value.trim():e.token.value.trim());for(const r of["opus","sonnet","haiku"])e.models[r].trim()&&(n[xn[r]]=e.models[r].trim());return e.timeoutMs.trim()&&(n.API_TIMEOUT_MS=e.timeoutMs.trim()),n}function jc(e){var t;return e?((t=Mi.find(n=>n.baseUrl===e))==null?void 0:t.id)??"custom":"anthropic"}function M0(e,t){return{...Ip(),baseUrl:t.baseUrl,tokenVar:t.tokenVar,token:e.token}}function L0(e){return{...Li(e).form,token:{secret:!0,value:""}}}function Uo({children:e}){return u.jsx("div",{className:"text-[11px] text-muted-foreground font-mono",children:e})}function I0({form:e,onChange:t,secretNames:n,copySources:r}){const[o,l]=g.useState(()=>jc(e.baseUrl)),s=i=>{if(i.startsWith("copy:")){const a=r.find(c=>c.name===i.slice(5));if(a){const c=L0(a.env);l(jc(c.baseUrl)),t(c)}return}if(l(i),i==="anthropic")t(Ip());else{const a=Mi.find(c=>c.id===i);a&&t(M0(e,a))}};return u.jsxs("div",{className:"space-y-3",children:[u.jsxs("select",{className:"w-full border rounded-md h-9 px-2 bg-background text-sm",value:o,onChange:i=>s(i.target.value),children:[u.jsx("option",{value:"anthropic",children:"Anthropic (default)"}),Mi.map(i=>u.jsx("option",{value:i.id,children:i.label},i.id)),u.jsx("option",{value:"custom",children:"Custom…"}),r.length>0&&u.jsx("option",{disabled:!0,children:"── copy from ──"}),r.map(i=>u.jsxs("option",{value:`copy:${i.name}`,children:["copy from ",i.name]},i.name))]}),o==="anthropic"?u.jsx("p",{className:"text-xs text-muted-foreground",children:"Uses Anthropic's API with this profile's normal auth — no provider overrides."}):u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsx(ye,{className:"font-mono text-xs",value:e.baseUrl,placeholder:"https://provider.example.com/anthropic",onChange:i=>t({...e,baseUrl:i.target.value})}),u.jsx(Uo,{children:"ANTHROPIC_BASE_URL"})]}),u.jsxs("div",{className:"space-y-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[e.token.secret?u.jsxs("select",{className:"flex-1 border rounded-md h-9 px-2 bg-background text-sm",value:e.token.value,onChange:i=>t({...e,token:{secret:!0,value:i.target.value}}),children:[u.jsx("option",{value:"",children:"— pick secret (token) —"}),n.map(i=>u.jsx("option",{value:i,children:i},i))]}):u.jsx(ye,{className:"flex-1 font-mono text-xs",type:"password",value:e.token.value,placeholder:"auth token",onChange:i=>t({...e,token:{secret:!1,value:i.target.value}})}),u.jsxs("label",{className:"flex items-center gap-1 text-xs text-muted-foreground whitespace-nowrap",children:[u.jsx("input",{type:"checkbox",checked:e.token.secret,onChange:i=>t({...e,token:{secret:i.target.checked,value:""}})}),"secret"]}),o==="custom"&&u.jsxs("select",{className:"border rounded-md h-9 px-2 bg-background text-xs",value:e.tokenVar,onChange:i=>t({...e,tokenVar:i.target.value}),children:[u.jsx("option",{value:"ANTHROPIC_AUTH_TOKEN",children:"AUTH_TOKEN"}),u.jsx("option",{value:"ANTHROPIC_API_KEY",children:"API_KEY"})]})]}),u.jsx(Uo,{children:e.tokenVar})]}),u.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(i=>u.jsxs("div",{className:"space-y-1",children:[u.jsx(ye,{className:"font-mono text-xs",value:e.models[i],placeholder:`${i} model`,onChange:a=>t({...e,models:{...e.models,[i]:a.target.value}})}),u.jsxs(Uo,{children:["ANTHROPIC_DEFAULT_",i.toUpperCase(),"_MODEL"]})]},i))}),u.jsxs("div",{className:"space-y-1",children:[u.jsx(ye,{className:"font-mono text-xs w-40",value:e.timeoutMs,placeholder:"timeout ms (optional)",onChange:i=>t({...e,timeoutMs:i.target.value})}),u.jsx(Uo,{children:"API_TIMEOUT_MS"})]})]})]})}const Ii="secret://";function Pc(e){return Object.entries(e).map(([t,n])=>n.startsWith(Ii)?{key:t,value:n.slice(Ii.length),secret:!0}:{key:t,value:n,secret:!1})}function bc(e){const t={};for(const n of e)n.key.trim()&&(t[n.key.trim()]=n.secret?Ii+n.value:n.value);return t}function _c({rows:e,onChange:t,secretNames:n,keyPlaceholder:r}){const o=(l,s)=>t(e.map((i,a)=>a===l?{...i,...s}:i));return u.jsxs(u.Fragment,{children:[e.map((l,s)=>u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ye,{className:"w-56 font-mono text-xs",value:l.key,onChange:i=>o(s,{key:i.target.value}),placeholder:r}),l.secret?u.jsxs("select",{className:"flex-1 border rounded-md h-9 px-2 bg-background text-sm",value:l.value,onChange:i=>o(s,{value:i.target.value}),children:[u.jsx("option",{value:"",children:"— pick secret —"}),n.map(i=>u.jsx("option",{value:i,children:i},i))]}):u.jsx(ye,{className:"flex-1 font-mono text-xs",value:l.value,onChange:i=>o(s,{value:i.target.value})}),u.jsxs("label",{className:"flex items-center gap-1 text-xs text-muted-foreground whitespace-nowrap",children:[u.jsx("input",{type:"checkbox",checked:l.secret,onChange:i=>o(s,{secret:i.target.checked,value:""})}),"secret"]}),u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>t(e.filter((i,a)=>a!==s)),children:u.jsx(Aa,{className:"h-4 w-4"})})]},s)),u.jsx(K,{size:"sm",variant:"secondary",onClick:()=>t([...e,{key:"",value:"",secret:!1}]),children:"Add env var"})]})}function A0({profile:e,profiles:t,servers:n,secretNames:r,onClose:o,onSaved:l}){const[s,i]=g.useState(e.launcher??""),[a,c]=g.useState(Pc(e.env)),p=Object.keys(e.settingsEnv).length?e.settingsEnv:e.liveSettingsEnv,[h,v]=g.useState(()=>Li(p).form),[f,w]=g.useState(()=>Pc(Li(p).advanced)),[x,C]=g.useState(Object.entries(e.links).map(([E,N])=>({key:E,value:N}))),[m,d]=g.useState(e.mcpNames),[y,k]=g.useState(!1),j=(E,N)=>C(x.map((L,O)=>O===E?{...L,...N}:L)),S=async()=>{for(const E of[...a,...f])if(E.secret&&!E.value){$.error(`pick a secret for ${E.key||"env var"}`);return}k(!0);try{const E={};for(const N of x)N.key.trim()&&(E[N.key.trim()]=N.value);await Q.patchProfile(e.name,{env:bc(a),settingsEnv:O0(h,bc(f)),links:E,launcher:s.trim()||null});for(const N of m.filter(L=>!e.mcpNames.includes(L)))await Q.addMcp({name:N,targets:[e.name]});for(const N of e.mcpNames.filter(L=>!m.includes(L)))await Q.rmMcp(N,[e.name]);$.success(`Saved ${e.name}`),l()}catch(E){$.error(E.message)}finally{k(!1)}};return u.jsx(dr,{open:!0,onOpenChange:E=>{E||o()},children:u.jsxs(jn,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[u.jsx(fr,{children:u.jsxs(Pn,{children:["Edit ",e.name]})}),u.jsxs("div",{className:"space-y-5",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Launcher function"}),u.jsx(ye,{value:s,onChange:E=>i(E.target.value),placeholder:"cl-work (empty = no launcher)"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Launcher env (exported by the shell function)"}),u.jsx(_c,{rows:a,onChange:c,secretNames:r,keyPlaceholder:"ANTHROPIC_API_KEY"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Provider"}),u.jsx("p",{className:"text-xs text-muted-foreground",children:"Where this profile's Claude Code sends requests — written into settings.json. Secret tokens resolve from the keychain on apply."}),u.jsx(I0,{form:h,onChange:v,secretNames:r,copySources:t.filter(E=>E.name!==e.name).map(E=>({name:E.name,env:Object.keys(E.settingsEnv).length?E.settingsEnv:E.liveSettingsEnv})).filter(E=>E.env.ANTHROPIC_BASE_URL)}),u.jsxs("details",{className:"pt-1",children:[u.jsxs("summary",{className:"text-xs text-muted-foreground cursor-pointer select-none",children:["Advanced — other settings.json env vars (",f.length,")"]}),u.jsx("div",{className:"space-y-1.5 pt-2",children:u.jsx(_c,{rows:f,onChange:w,secretNames:r,keyPlaceholder:"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"})})]})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Links"}),x.map((E,N)=>u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ye,{className:"w-56 font-mono text-xs",value:E.key,onChange:L=>j(N,{key:L.target.value}),placeholder:"skills"}),u.jsx(ye,{className:"flex-1 font-mono text-xs",value:E.value,onChange:L=>j(N,{value:L.target.value}),placeholder:"hub or a path"}),u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>C(x.filter((L,O)=>O!==N)),children:u.jsx(Aa,{className:"h-4 w-4"})})]},N)),u.jsx(K,{size:"sm",variant:"secondary",onClick:()=>C([...x,{key:"",value:""}]),children:"Add link"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"MCP servers"}),u.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[n.map(E=>u.jsxs("label",{className:"flex items-center gap-2 text-sm font-mono",children:[u.jsx("input",{type:"checkbox",checked:m.includes(E),onChange:N=>d(N.target.checked?[...m,E]:m.filter(L=>L!==E))}),E]},E)),n.length===0&&u.jsx("div",{className:"text-sm text-muted-foreground",children:"No servers in manifest."})]})]})]}),u.jsxs(pr,{children:[u.jsx(K,{variant:"secondary",onClick:o,children:"Cancel"}),u.jsx(K,{disabled:y,onClick:S,children:y?"Saving…":"Save & apply"})]})]})})}function z0(e){var n;const t=(n=e.settingsEnv)==null?void 0:n.ANTHROPIC_BASE_URL;if(!t)return"—";try{return new URL(t).host}catch{return t}}function D0(){const[e,t]=g.useState([]),[n,r]=g.useState([]),[o,l]=g.useState([]),[s,i]=g.useState(""),[a,c]=g.useState(""),[p,h]=g.useState(!1),[v,f]=g.useState(null),[w,x]=g.useState(null),C=async()=>{try{t(await Q.profiles())}catch(d){$.error(d.message)}try{r((await Q.mcp()).servers)}catch{r([])}try{l((await Q.secrets()).names)}catch{l([])}};g.useEffect(()=>{C()},[]);const m=async d=>{try{await Q.deleteProfile(d.name),$.success(`Removed ${d.name} from manifest`),x(null),C()}catch(y){$.error(y.message)}};return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h1",{className:"text-xl font-semibold",children:"Profiles"}),u.jsxs(dr,{open:p,onOpenChange:h,children:[u.jsx(za,{asChild:!0,children:u.jsx(K,{children:"Create profile"})}),u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsx(Pn,{children:"New profile"})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Name"}),u.jsx(ye,{value:s,onChange:d=>i(d.target.value),placeholder:"work"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Copy MCP / links from (optional)"}),u.jsxs("select",{className:"w-full border rounded-md h-9 px-2 bg-background text-sm",value:a,onChange:d=>c(d.target.value),children:[u.jsx("option",{value:"",children:"— none —"}),e.map(d=>u.jsx("option",{value:d.name,children:d.name},d.name))]})]})]}),u.jsx(pr,{children:u.jsx(K,{onClick:async()=>{try{await Q.createProfile(s,a||void 0),$.success(`Created ${s}`),h(!1),i(""),c(""),C()}catch(d){$.error(d.message)}},children:"Create"})})]})]})]}),u.jsxs(ep,{children:[u.jsx(tp,{children:u.jsxs(_i,{children:[u.jsx(St,{children:"Name"}),u.jsx(St,{children:"Auth"}),u.jsx(St,{children:"Account"}),u.jsx(St,{children:"MCP"}),u.jsx(St,{children:"Launcher"}),u.jsx(St,{children:"Provider"}),u.jsx(St,{children:"Env"}),u.jsx(St,{className:"w-32"})]})}),u.jsx(np,{children:e.map(d=>u.jsxs(_i,{children:[u.jsxs(kt,{className:"font-medium",children:[d.name,!d.adopted&&u.jsx("span",{className:"text-muted-foreground",title:"not in manifest — adopt to manage",children:" *"})]}),u.jsx(kt,{children:d.auth}),u.jsx(kt,{className:"text-muted-foreground",children:d.account??"—"}),u.jsx(kt,{children:d.mcp}),u.jsx(kt,{className:"font-mono text-xs",children:d.launcher??"—"}),u.jsx(kt,{className:"font-mono text-xs text-muted-foreground",children:z0(d)}),u.jsx(kt,{className:"font-mono text-xs text-muted-foreground",children:Object.keys(d.env).length||"—"}),u.jsx(kt,{children:u.jsxs("div",{className:"flex gap-1 justify-end",children:[u.jsx("span",{title:d.adopted?void 0:"Adopt first",children:u.jsx(K,{size:"sm",variant:"ghost",disabled:!d.adopted,onClick:()=>f(d),children:"Edit"})}),u.jsx("span",{title:d.adopted?void 0:"Adopt first",children:u.jsx(K,{size:"sm",variant:"ghost",disabled:!d.adopted,onClick:()=>x(d),children:"Delete"})})]})})]},d.name))})]}),v&&u.jsx(A0,{profile:v,profiles:e,servers:n,secretNames:o,onClose:()=>f(null),onSaved:()=>{f(null),C()}}),w&&u.jsx(dr,{open:!0,onOpenChange:d=>{d||x(null)},children:u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsxs(Pn,{children:['Delete profile "',w.name,'"?']})}),u.jsxs("p",{className:"text-sm text-muted-foreground",children:["Removes it from the manifest and drops its launcher from your shell rc on apply. The directory ",u.jsx("span",{className:"font-mono",children:w.dir})," stays on disk — re-adopt to manage it again."]}),u.jsxs(pr,{children:[u.jsx(K,{variant:"secondary",onClick:()=>x(null),children:"Cancel"}),u.jsx(K,{variant:"destructive",onClick:()=>m(w),children:"Delete"})]})]})})]})}function F0(e){const t=g.useRef({value:e,previous:e});return g.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function $0(e){const[t,n]=g.useState(void 0);return Nn(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const l=o[0];let s,i;if("borderBoxSize"in l){const a=l.borderBoxSize,c=Array.isArray(a)?a[0]:a;s=c.inlineSize,i=c.blockSize}else s=e.offsetWidth,i=e.offsetHeight;n({width:s,height:i})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Yl="Switch",[U0]=rp(Yl),[B0,Da]=U0(Yl);function H0(e){const{__scopeSwitch:t,checked:n,children:r,defaultChecked:o,disabled:l,form:s,name:i,onCheckedChange:a,required:c,value:p="on",internal_do_not_use_render:h}=e,[v,f]=op({prop:n,defaultProp:o??!1,onChange:a,caller:Yl}),[w,x]=g.useState(null),[C,m]=g.useState(null),d=g.useRef(!1),y=w?!!s||!!w.closest("form"):!0,k={checked:v,setChecked:f,disabled:l,control:w,setControl:x,name:i,form:s,value:p,hasConsumerStoppedPropagationRef:d,required:c,defaultChecked:o,isFormControl:y,bubbleInput:C,setBubbleInput:m};return u.jsx(B0,{scope:t,...k,children:V0(h)?h(k):r})}var Ap="SwitchTrigger",zp=g.forwardRef(({__scopeSwitch:e,onClick:t,...n},r)=>{const{value:o,disabled:l,checked:s,required:i,setControl:a,setChecked:c,hasConsumerStoppedPropagationRef:p,isFormControl:h,bubbleInput:v}=Da(Ap,e),f=Lt(r,a);return u.jsx(Ke.button,{type:"button",role:"switch","aria-checked":s,"aria-required":i,"data-state":Hp(s),"data-disabled":l?"":void 0,disabled:l,value:o,...n,ref:f,onClick:bt(t,w=>{c(x=>!x),v&&h&&(p.current=w.isPropagationStopped(),p.current||w.stopPropagation())})})});zp.displayName=Ap;var Dp=g.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:l,required:s,disabled:i,value:a,onCheckedChange:c,form:p,...h}=e;return u.jsx(H0,{__scopeSwitch:n,checked:o,defaultChecked:l,disabled:i,required:s,onCheckedChange:c,name:r,form:p,value:a,internal_do_not_use_render:({isFormControl:v})=>u.jsxs(u.Fragment,{children:[u.jsx(zp,{...h,ref:t,__scopeSwitch:n}),v&&u.jsx(Bp,{__scopeSwitch:n})]})})});Dp.displayName=Yl;var Fp="SwitchThumb",$p=g.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=Da(Fp,n);return u.jsx(Ke.span,{"data-state":Hp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});$p.displayName=Fp;var Up="SwitchBubbleInput",Bp=g.forwardRef(({__scopeSwitch:e,...t},n)=>{const{control:r,hasConsumerStoppedPropagationRef:o,checked:l,defaultChecked:s,required:i,disabled:a,name:c,value:p,form:h,bubbleInput:v,setBubbleInput:f}=Da(Up,e),w=Lt(n,f),x=F0(l),C=$0(r);g.useEffect(()=>{const d=v;if(!d)return;const y=window.HTMLInputElement.prototype,j=Object.getOwnPropertyDescriptor(y,"checked").set,S=!o.current;if(x!==l&&j){const E=new Event("click",{bubbles:S});j.call(d,l),d.dispatchEvent(E)}},[v,x,l,o]);const m=g.useRef(l);return u.jsx(Ke.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??m.current,required:i,disabled:a,name:c,value:p,form:h,...t,tabIndex:-1,ref:w,style:{...t.style,...C,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Bp.displayName=Up;function V0(e){return typeof e=="function"}function Hp(e){return e?"checked":"unchecked"}const Fa=g.forwardRef(({className:e,...t},n)=>u.jsx(Dp,{className:ve("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx($p,{className:"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})}));Fa.displayName="Switch";function W0(){const[e,t]=g.useState(null),[n,r]=g.useState(!1),[o,l]=g.useState({name:"",command:"npx",args:""}),[s,i]=g.useState(""),a=async()=>{try{t(await Q.mcp())}catch(p){$.error(p.message)}};if(g.useEffect(()=>{a()},[]),!e)return null;const c=async(p,h,v)=>{try{v?await Q.addMcp({name:p,targets:[h]}):await Q.rmMcp(p,[h]),await a()}catch(f){$.error(f.message)}};return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[u.jsx("h1",{className:"text-xl font-semibold",children:"MCP servers"}),u.jsxs("div",{className:"flex gap-2 items-center",children:[u.jsxs("select",{className:"border rounded-md h-9 px-2 bg-background text-sm",value:s,onChange:p=>i(p.target.value),children:[u.jsx("option",{value:"",children:"sync from…"}),e.profiles.map(p=>u.jsx("option",{value:p.name,children:p.name},p.name))]}),u.jsx(K,{variant:"secondary",disabled:!s,onClick:async()=>{try{await Q.syncMcp(s,"all"),$.success(`Synced from ${s}`),await a()}catch(p){$.error(p.message)}},children:"Sync → all"}),u.jsxs(dr,{open:n,onOpenChange:r,children:[u.jsx(za,{asChild:!0,children:u.jsx(K,{children:"Add server"})}),u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsx(Pn,{children:"Add MCP server"})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Name"}),u.jsx(ye,{value:o.name,onChange:p=>l({...o,name:p.target.value}),placeholder:"shadcn"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Command"}),u.jsx(ye,{value:o.command,onChange:p=>l({...o,command:p.target.value})})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Args (comma-separated)"}),u.jsx(ye,{value:o.args,onChange:p=>l({...o,args:p.target.value}),placeholder:"-y,@playwright/mcp@latest"})]})]}),u.jsx(pr,{children:u.jsx(K,{onClick:async()=>{try{await Q.addMcp({name:o.name,command:o.command,args:o.args?o.args.split(","):[],targets:"all"}),$.success(`Added ${o.name}`),r(!1),l({name:"",command:"npx",args:""}),await a()}catch(p){$.error(p.message)}},children:"Add to all"})})]})]})]})]}),u.jsx("div",{className:"overflow-x-auto border rounded-lg",children:u.jsxs("table",{className:"text-sm border-collapse w-full",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b",children:[u.jsx("th",{className:"text-left p-3 font-medium",children:"Server"}),e.profiles.map(p=>u.jsx("th",{className:"p-3 text-center font-medium",children:p.name},p.name))]})}),u.jsxs("tbody",{children:[e.servers.map(p=>u.jsxs("tr",{className:"border-b last:border-0",children:[u.jsx("td",{className:"p-3 font-mono",children:p}),e.profiles.map(h=>u.jsx("td",{className:"p-3 text-center",children:u.jsx(Fa,{checked:h.has.includes(p),onCheckedChange:v=>c(p,h.name,v)})},h.name))]},p)),e.servers.length===0&&u.jsx("tr",{children:u.jsx("td",{className:"p-3 text-muted-foreground",colSpan:e.profiles.length+1,children:"No MCP servers yet."})})]})]})})]})}const K0=qf("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ai({className:e,variant:t,...n}){return u.jsx("div",{className:ve(K0({variant:t}),e),...n})}const Ls="secret://";function Q0(){const[e,t]=g.useState([]),[n,r]=g.useState(""),[o,l]=g.useState([]),[s,i]=g.useState({}),[a,c]=g.useState(!1),[p,h]=g.useState({name:"",value:""}),[v,f]=g.useState(null),[w,x]=g.useState({profile:"",envKey:"ANTHROPIC_API_KEY"}),C=async()=>{try{const S=await Q.secrets();t(S.names),r(S.backend)}catch(S){$.error(S.message)}try{l(await Q.profiles())}catch{l([])}};g.useEffect(()=>{C()},[]);const m=S=>o.flatMap(E=>[...Object.entries(E.env).filter(([,N])=>N===Ls+S).map(([N])=>({profile:E.name,envKey:N,map:"env"})),...Object.entries(E.settingsEnv).filter(([,N])=>N===Ls+S).map(([N])=>({profile:E.name,envKey:N,map:"settingsEnv"}))]),d=async S=>{if(s[S]!==void 0){const E={...s};delete E[S],i(E);return}try{const E=await Q.revealSecret(S);i({...s,[S]:E.value})}catch(E){$.error(E.message)}},y=async()=>{if(!v||!w.profile||!w.envKey.trim())return;const S=o.find(E=>E.name===w.profile);if(S)try{await Q.patchProfile(S.name,{env:{...S.env,[w.envKey.trim()]:Ls+v}}),$.success(`Attached ${v} to ${S.name} as ${w.envKey.trim()}`),f(null),x({profile:"",envKey:"ANTHROPIC_API_KEY"}),C()}catch(E){$.error(E.message)}},k=async(S,E)=>{const N=o.find(O=>O.name===E.profile);if(!N)return;const L=E.map==="env"?{env:(()=>{const O={...N.env};return delete O[E.envKey],O})()}:{settingsEnv:(()=>{const O={...N.settingsEnv};return delete O[E.envKey],O})()};try{await Q.patchProfile(N.name,L),$.success(`Detached ${S} from ${E.profile}`),C()}catch(O){$.error(O.message)}},j=o.filter(S=>S.adopted);return u.jsxs("div",{className:"space-y-4",children:[u.jsx("div",{className:"flex items-center justify-between",children:u.jsxs("h1",{className:"text-xl font-semibold flex items-center gap-2",children:["Secrets ",u.jsx(Ai,{variant:"secondary",children:n})]})}),n==="unavailable"?u.jsxs("div",{className:"border rounded-lg p-4 text-sm space-y-1",children:[u.jsx("div",{className:"font-medium",children:"Secrets backend not configured"}),u.jsxs("p",{className:"text-muted-foreground",children:["On Windows this uses DPAPI automatically (needs PowerShell). Otherwise set",u.jsx("span",{className:"font-mono",children:" CCPROFILES_PASSPHRASE"})," in your environment to enable the encrypted-file backend, then reopen this page."]})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"flex items-center justify-end",children:u.jsxs("div",{className:"flex gap-2",children:[u.jsx(K,{variant:"secondary",onClick:async()=>{try{const S=await Q.migrate();$.success(S.migrated.length?`Migrated ${S.migrated.join(", ")}`:"No plaintext keys found"),C()}catch(S){$.error(S.message)}},children:"Migrate plaintext keys"}),u.jsxs(dr,{open:a,onOpenChange:c,children:[u.jsx(za,{asChild:!0,children:u.jsx(K,{children:"Add secret"})}),u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsx(Pn,{children:"Add secret"})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Name"}),u.jsx(ye,{value:p.name,onChange:S=>h({...p,name:S.target.value}),placeholder:"anthropic-api-key"})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Value"}),u.jsx(ye,{type:"password",value:p.value,onChange:S=>h({...p,value:S.target.value})})]})]}),u.jsx(pr,{children:u.jsx(K,{onClick:async()=>{try{await Q.setSecret(p.name,p.value),$.success(`Stored ${p.name}`),c(!1),h({name:"",value:""}),C()}catch(S){$.error(S.message)}},children:"Save"})})]})]})]})}),u.jsxs("div",{className:"divide-y border rounded-lg",children:[e.map(S=>{const E=m(S);return u.jsxs("div",{className:"flex items-center justify-between p-3 gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("div",{className:"font-mono text-sm",children:[S,s[S]!==void 0&&u.jsx("span",{className:"ml-3 text-muted-foreground",children:s[S]})]}),E.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:E.map(N=>u.jsxs(Ai,{variant:"secondary",className:"font-mono text-[11px] gap-1",children:[N.profile," · ",N.envKey,N.map==="settingsEnv"&&u.jsx("span",{className:"text-muted-foreground",children:" (settings)"}),u.jsx("button",{className:"ml-0.5 hover:text-foreground",title:"Detach",onClick:()=>k(S,N),children:"×"})]},`${N.profile}-${N.map}-${N.envKey}`))})]}),u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>f(S),children:"Attach"}),u.jsx(K,{size:"sm",variant:"ghost",onClick:()=>d(S),children:s[S]!==void 0?"Hide":"Reveal"}),u.jsx(K,{size:"sm",variant:"ghost",onClick:async()=>{try{await Q.rmSecret(S),$.success(`Removed ${S}`),C()}catch(N){$.error(N.message)}},children:"Delete"})]})]},S)}),e.length===0&&u.jsx("div",{className:"p-3 text-sm text-muted-foreground",children:"No secrets yet."})]})]}),v&&u.jsx(dr,{open:!0,onOpenChange:S=>{S||f(null)},children:u.jsxs(jn,{children:[u.jsx(fr,{children:u.jsxs(Pn,{children:["Attach ",v," to a profile"]})}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Profile"}),u.jsxs("select",{className:"w-full border rounded-md h-9 px-2 bg-background text-sm",value:w.profile,onChange:S=>x({...w,profile:S.target.value}),children:[u.jsx("option",{value:"",children:"— pick profile —"}),j.map(S=>u.jsx("option",{value:S.name,children:S.name},S.name))]})]}),u.jsxs("div",{className:"space-y-1.5",children:[u.jsx(Pe,{children:"Env var name"}),u.jsx(ye,{className:"font-mono",value:w.envKey,onChange:S=>x({...w,envKey:S.target.value})})]}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["The launcher will export it as ",u.jsxs("span",{className:"font-mono",children:[w.envKey||"VAR",'="$(ccprofiles secrets get ',v,')"']})," — the value never lands in your rc file."]})]}),u.jsxs(pr,{children:[u.jsx(K,{variant:"secondary",onClick:()=>f(null),children:"Cancel"}),u.jsx(K,{disabled:!w.profile||!w.envKey.trim(),onClick:y,children:"Attach"})]})]})})]})}function Tc({title:e,lines:t,otherLines:n,tint:r}){return u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"text-sm font-medium mb-1.5",children:e}),u.jsx("pre",{className:"border rounded-lg p-3 text-xs font-mono overflow-x-auto whitespace-pre",children:t.map((o,l)=>u.jsx("div",{className:ve("px-1 -mx-1 rounded-sm",!n.has(o)&&o.trim()!==""&&r),children:o||" "},l))})]})}function Y0(){const[e,t]=g.useState(null),[n,r]=g.useState(!1),[o,l]=g.useState(null),s=async()=>{try{t(await Q.rc()),l(null)}catch(c){l(c.message),$.error(c.message)}};if(g.useEffect(()=>{s()},[]),o)return u.jsx("div",{className:"text-sm text-muted-foreground",children:"No manifest yet — adopt your profiles first."});if(!e)return u.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading…"});const i=(e.current??"").split(`
142
142
  `),a=e.rendered.split(`
143
143
  `);return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("h1",{className:"text-xl font-semibold flex items-center gap-2",children:["Shell RC",u.jsx(Ai,{variant:e.inSync?"secondary":"default",children:e.inSync?"in sync":"out of sync"})]}),u.jsxs(K,{disabled:e.inSync||n,onClick:async()=>{r(!0);try{const c=await Q.updateRc();$.success(c.backupDir?`Updated — backup in ${c.backupDir}`:"Updated"),s()}catch(c){$.error(c.message)}finally{r(!1)}},children:["Update ",e.rcFile.split("/").pop()]})]}),u.jsx("div",{className:"text-sm text-muted-foreground font-mono",children:e.rcFile}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Only the managed block (between the ccprofiles markers) is ever rewritten. Everything else in the file is untouched."}),u.jsxs("div",{className:"flex gap-4",children:[u.jsx(Tc,{title:"Currently in file",lines:e.current===null?["(no managed block yet)"]:i,otherLines:new Set(a),tint:"bg-red-500/10"}),u.jsx(Tc,{title:"From manifest",lines:a,otherLines:new Set(i),tint:"bg-green-500/10"})]})]})}function G0(){const[e,t]=g.useState([]),[n,r]=g.useState(!1),o=async()=>{try{t(await Q.devices())}catch(l){$.error(l.message)}};return g.useEffect(()=>{o()},[]),u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h1",{className:"text-xl font-semibold",children:"Sync"}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(Fa,{id:"ws",checked:n,onCheckedChange:r}),u.jsx(Pe,{htmlFor:"ws",children:"with secrets"})]})]}),e.length===0?u.jsxs(nn,{className:"p-6 text-sm text-muted-foreground",children:["No paired devices. Pair one from the CLI: ",u.jsx("code",{className:"font-mono text-foreground",children:"clp pair <host> --port <p> --pin <pin>"})]}):e.map(l=>u.jsxs(nn,{className:"p-4 flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx("div",{className:"font-medium",children:l.name}),u.jsxs("div",{className:"text-xs text-muted-foreground",children:[l.host,":",l.port]})]}),u.jsx(K,{onClick:async()=>{try{const s=await Q.sync(l.name,n);$.success(`Pulled ${s.performed.length} change(s)${s.secrets.length?`, secrets: ${s.secrets.join(", ")}`:""}`)}catch(s){$.error(s.message)}},children:"Pull"})]},l.name))]})}function X0(){const[e,t]=g.useState(null),n=async()=>{try{t((await Q.doctor()).problems)}catch(r){$.error(r.message)}};return g.useEffect(()=>{n()},[]),u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h1",{className:"text-xl font-semibold",children:"Doctor"}),u.jsx(K,{variant:"secondary",onClick:n,children:"Re-run"})]}),e===null?null:e.length===0?u.jsx(nn,{className:"p-6 text-green-500 font-medium",children:"No problems found ✓"}):u.jsx("div",{className:"space-y-2",children:e.map((r,o)=>u.jsx(nn,{className:"p-4 text-sm",children:r},o))})]})}const Z0=[["status","Status",C0],["profiles","Profiles",b0],["mcp","MCP",k0],["secrets","Secrets",E0],["rc","Shell RC",P0],["sync","Sync",N0],["doctor","Doctor",j0]];function J0(){const[e,t]=g.useState("status");return u.jsxs("div",{className:"flex h-screen",children:[u.jsxs("aside",{className:"w-52 border-r p-3 space-y-1 shrink-0",children:[u.jsx("div",{className:"px-2 pb-4 pt-1 text-lg font-semibold tracking-tight",children:"ccprofiles"}),Z0.map(([n,r,o])=>u.jsxs("button",{onClick:()=>t(n),className:ve("w-full flex items-center gap-2.5 text-left px-3 py-2 rounded-md text-sm transition-colors",e===n?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:[u.jsx(o,{className:"h-4 w-4"}),r]},n))]}),u.jsxs("main",{className:"flex-1 overflow-auto p-8",children:[e==="status"&&u.jsx(Gg,{}),e==="profiles"&&u.jsx(D0,{}),e==="mcp"&&u.jsx(W0,{}),e==="secrets"&&u.jsx(Q0,{}),e==="rc"&&u.jsx(Y0,{}),e==="sync"&&u.jsx(G0,{}),e==="doctor"&&u.jsx(X0,{})]}),u.jsx(rg,{})]})}Wf(document.getElementById("root")).render(u.jsx(_.StrictMode,{children:u.jsx(J0,{})}));
@@ -1,6 +1,6 @@
1
1
  <!doctype html>
2
2
  <html lang="en" class="dark">
3
- <head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>ccprofiles</title> <script type="module" crossorigin src="./assets/index-dw8cq3Ri.js"></script>
3
+ <head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>ccprofiles</title> <script type="module" crossorigin src="./assets/index-DEiJLy_b.js"></script>
4
4
  <link rel="stylesheet" crossorigin href="./assets/index-B9Ee16GZ.css">
5
5
  </head>
6
6
  <body><div id="root"></div></body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-account-sync",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Manage multiple Claude Code accounts/profiles — MCP drift sync, keychain secrets, and encrypted LAN replication between machines. CLI: ccprofiles (alias clp).",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,7 +34,10 @@
34
34
  "node": ">=20"
35
35
  },
36
36
  "dependencies": {
37
- "ccprofiles-core": "^0.2.0",
37
+ "ccprofiles-core": "^0.3.0",
38
38
  "commander": "^12.1.0"
39
+ },
40
+ "scripts": {
41
+ "prepack": "node -e \"require('fs').copyFileSync('../../README.md','README.md')\""
39
42
  }
40
43
  }