# dsh-codebuddy2dsh **Repository Path**: lee-chen-guang/dsh-codebuddy2dsh ## Basic Information - **Project Name**: dsh-codebuddy2dsh - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-10-16 - **Last Updated**: 2026-11-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dsh-codebuddy2dsh Sign in to CodeBuddy / WorkBuddy straight from DeepSeek Harness and serve every account you own as its own model group — no desktop app required, and personal and enterprise identities side by side. --- ## The problem `dsh-workbuddy-connect` **reads** the desktop app's login file. That imposes two hard limits: 1. WorkBuddy must be installed and signed in before the plugin has anything to read. 2. The desktop app can only be signed in as one identity at a time, so a personal account and an enterprise account cannot both be live. Switching means switching in the app. When one phone number owns both a personal and a company account, that limit is the blocker. This plugin takes a different route: it speaks the CodeBuddy CLI's own login protocol and keeps credentials in its own vault. **One model group per account, all live at once.** ## How it differs | | dsh-workbuddy-connect | dsh-codebuddy2dsh | |---|---|---| | Credential source | Reads the desktop app's auth file | Signs in itself, stores its own vault | | Desktop app needed | **Yes** | **No** | | Accounts live at once | 1 | **N** (personal + every enterprise) | | Writes desktop app state | No (read-only) | No (fully isolated) | | Token custody | Desktop file + plugin copy | Plugin vault only | ## The protocol Not reverse-engineered by guesswork — read out of the `@genie/agent-cli` engine CodeBuddy ships. Everything goes to `copilot.tencent.com`: | Step | Request | Purpose | |---|---|---| | 1 | `POST /v2/plugin/auth/state?platform=cli` | Obtain a one-shot `state` and `authUrl` | | 2 | Open `authUrl` in a browser | Human sign-in (**the one manual step**) | | 3 | `GET /v2/plugin/auth/token?state=` | Exchange for `accessToken` + `refreshToken` | | 4 | `GET /v2/plugin/accounts` | The identity roster this sign-in reaches | | 5 | `POST /v2/plugin/login/enterprise[/]` | Mint one token per enterprise identity | Step 5 is what makes this possible: a single sign-in covers the personal account and every enterprise the phone number reaches, so no account needs its own login. Steady-state operation needs only step 6, `POST /v2/plugin/auth/token/refresh`. ## Install ```bash cd dsh-codebuddy2dsh pnpm install pnpm pack # install the tgz through DSH's plugin manager; the bundle patch registers it ``` The package exports `locale/en.json` and `locale/zh.json`. DSH uses the matching locale for the installed plugin title and description, with English as the fallback. The settings card reports the installed package version, the saved Git source ref, and the newest release tag. When a newer tag is available, **Update** asks DSH's native plugin manager to install that ref with the profile's existing source and reload the bundle. If the profile source or release check is unavailable, the card leaves the action disabled and shows the reason. ## Use ### First sign-in ```bash node lib/cli.js login ``` The command prints an approval URL and tries to open a browser. Finish the sign-in and it continues automatically, writing **every reachable account** into the vault. > One person may hold several `uid`s: a personal identity and an enterprise one are separate account entities with separate tokens. That is precisely why they can be live together. ### Inspect and forget ```bash node lib/cli.js list # every account; tokens are never printed node lib/cli.js forget # drop one account ``` ### In DSH Restart DSH after enabling. The model picker shows one group per account: ``` Model groups ├── cb2d-cn-3f2a1b8c Alice (personal) │ ├── auto │ └── deepseek-v4 └── cb2d-cn-9d4e7f12 Alice (Acme Corp) ├── auto └── deepseek-v4 ``` Each upstream model appears exactly once in the model picker. The conversation bar has a separate context selector whose choices follow each model's catalog declaration; when no choices are declared, only that model's actual input limit is shown. This is a DSH-local history and budgeting choice: the upstream request keeps the original model id and receives no synthetic context-size field. The picker intersects the broad gateway catalog with the current CLI agent roster, drops explicitly disabled rows, and rejects non-finite, non-positive, or non-integer token budgets. Picking a group spends that account's quota. Tokens, billing, catalogs, and context selections stay isolated between groups. ## Configuration Every option in `cordis.patch.yml` has a working default: | Field | Default | Meaning | |---|---|---| | `accounts` | `[]` | Only expose these accounts; empty means all in the vault | | `pollMs` | `30000` | Credential poll interval (ms) | | `refreshMarginMs` | `300000` | Refresh lead time before expiry | | `credentialsFile` | `~/.dsh/.codebuddy2dsh.json` | Vault path | | `platform` | `cli` | Sign-in platform tag | Filter by uid or `uid:enterpriseId`: ```yaml - insert: - id: codebuddy2dsh name: dsh-codebuddy2dsh config: accounts: - 00000000-0000-4000-8000-000000000000 ``` ## Token lifetime Measured on the CN gateway: - **accessToken**: 28 days (`expiresIn: 2419200`) - **refreshToken**: 30 days (`refreshExpiresIn: 2592000`) The plugin refreshes five minutes ahead of expiry and writes only its own vault. When the refresh token finally expires, run `login` again — the protocol requires human confirmation, and no workaround exists. ## Security design - **Tokens never enter DSH.** A loopback shim holds the bearer token and swaps it in on the way out; DSH only ever sees a per-run local secret. Tokens stay out of DSH's credential store, its settings, and any rendered UI. - **0600 vault, atomic writes.** Temp file plus rename, under a cross-process lock for the whole write. - **Token-free APIs.** The list view strips bearer tokens before they leave the process. - **Full isolation.** No CodeBuddy or WorkBuddy file is read or written, so signing in here cannot disturb either app. ## Development ```bash node --test test/plugin.test.mjs # offline suite (version, adapter, and loopback tests) node test/live-probe.mjs # live gateway probe (read-only, no credentials) node test/smoke-pi-ai-adapter.mjs # pi-ai streaming smoke test against an installed profile node --check lib/*.js # syntax check ``` The offline suite exercises request shapes, envelope parsing, localized metadata, independent context selections, and model-catalog parsing against a real loopback server, with no network. `smoke-pi-ai-adapter.mjs` is the runtime compatibility check the activation gate cannot provide: it loads the plugin, `@deepseek-ai/dsh-llm-pi-ai` and `@earendil-works/pi-ai` out of one real profile, then streams text and a split-argument tool call through a local fake gateway. Run it after a DSH update to prove the tree still works end to end without credentials. ## Debug logs Two records are always written, because each is bounded by an event rather than by traffic and each is what a support report is made of: the module-load record (one per load; it carries the resolved pi-ai binding, under `~/.dsh/dsh-codebuddy2dsh-adapter-debug.log`) and the upstream-rejection record (only when the gateway refuses a request, with the reason, under `~/.dsh/.codebuddy2dsh-shim-debug.log`). The per-request records — the adapter's three-phase dumps and the shim's one-line forward trace — are opt-in: `DSH_CODEBUDDY2DSH_DEBUG=1` in the host's environment (then reload). They used to be unconditional, and a day of ordinary use grew the adapter log past 40 MB. ## Coexistence with other pi-ai plugins The adapter binds `@deepseek-ai/dsh-llm-pi-ai` and its `@earendil-works/pi-ai` helpers through exact file-URL imports, walked over candidate trees in order: the profile's own tree first, then the running host's `app.asar/dsh` tree. Everything bound comes from one pi-ai identity on one supported release line (0.87.x, or 1.1.0 and newer below 2.0), so a stale pi-ai or adapter copy left in the profile's `node_modules` by another plugin — an older opencode bridge, for example — no longer blocks activation; the walk falls through to the next tree. The card's version endpoint reports the resolved paths and every candidate tried. When no candidate binds to a supported release line, the plugin refuses activation with an error listing each tree's version and how to clear the stale copies, instead of surfacing later as a generic `PI_AI_ERROR`. ## Known limits - **The first sign-in needs a human.** The protocol requires browser confirmation; the server offers no silent exchange. - **Depends on private endpoints.** `/v2/plugin/*` is a CLI-private implementation. When upstream changes it, the plugin fails with an explicit error rather than silently returning wrong data. - **The catalog is UA-partitioned.** The gateway serves a different roster per User-Agent; the plugin pins the CLI UA so that "listed" equals "usable". ## Disclaimer For personal study and research only, driving your own accounts on your own machine. Please respect the CodeBuddy / WorkBuddy terms of service.