description, kind
| description | kind |
|---|---|
| Run a third-party CLI that keeps the user's account from a CLI app plugin: bounded commands by the CLI's absolute path, runtime context that gives the model that path, and one Host-owned account operation at a time for the Plugins page. | package-library |
@deepseek-ai/dsh-cli-account
English | 中文
Summary
CLI app plugins such as Feishu and WeCom use this library to run their vendor CLI and to check, connect, and cancel the account their Plugins page shows. CliCommandExecutor runs one command by the CLI's absolute path with a deadline, an output limit, and line callbacks, and registerCliPathContext gives the model the same path in runtime context. CliAccountRuntime runs one account operation at a time, offers authorization links only on trusted hosts, cancels only in the phases the plugin declares, and streams the account view. Each plugin keeps its own commands, parsing, and account states.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
When to use it
Use it in the Host row of a plugin whose vendor CLI signs the user in and keeps the credentials, so DSH only starts commands, shows their results, and owns their processes. The plugin's Plugins page mirrors the view with @deepseek-ai/dsh-client-ui-cli-account. A plugin that connects a hosted service over MCP uses the MCP manager instead, which owns OAuth itself.
Entry point
A plugin states its CLI path in runtime context, subclasses the runtime, runs each command through its control, and serves the runtime's methods over its own Remote:
import type { Context } from '@deepseek-ai/cordis'
import { CliAccountRuntime, CliCommandExecutor, exitFailure, registerCliPathContext, type CliOperationControl } from '@deepseek-ai/dsh-cli-account'
import type {} from '@deepseek-ai/dsh-subprocess'
declare const ctx: Context
const executable = '/opt/vendor/bin/vendor-cli'
class Account extends CliAccountRuntime<{ readonly state: 'unchecked' | 'out' | 'in' }, 'check', never> {
protected async perform(_kind: 'check', control: CliOperationControl<never, 'status'>, signal: AbortSignal): Promise<void> {
const result = await control.run('status', ['auth', 'status'], signal)
if (result.exitCode !== 0) throw new Error('vendor-cli: auth status failed')
this.publish({ state: result.stdout.trim() === 'authorized' ? 'in' : 'out' })
}
}
registerCliPathContext(ctx, { name: 'vendor:cli', product: 'Vendor', program: 'vendor-cli', executable })
const account = new Account({
name: 'vendor', logger: ctx.logger, account: { state: 'unchecked' }, check: 'check', cancellable: [],
authorizationHosts: ['vendor.example'], classify: exitFailure,
cli: new CliCommandExecutor(ctx.subprocess, { program: 'vendor-cli', executable, commandTimeoutMs: 30_000 }),
})
account.start(kind) returns the operation id and throws while another operation runs. account.follow(signal) yields the current CliAccountView, starting a check when no operation runs, then each changed view. account.cancel(id) stops the named operation only in a declared cancellable phase. account.dispose() cancels the active operation, waits for its process to exit, and disposes the executor. The contracts in src/runtime.ts, src/executor.ts, and src/context.ts are authoritative.
Runtime context
registerCliPathContext(ctx, cli) registers one required runtime-context entry that tells the model to run cli.program by cli.executable, the path the executor runs. With scripts, it also tells the model to prefix only the commands that run the skill's scripts with PATH="<executable directory>:$PATH", which changes PATH for that command only, and never to export PATH or run cli.program by name. With ready, the entry contributes nothing while ready() returns false. The text is never interpolated, and disposing the plugin removes the entry. Model Experience shows the text.
Commands, links, and failures
A command that does not wait for the user gets the plugin's commandTimeoutMs, including executable lookup; a command run with awaitsUser waits up to 10 minutes. The executor keeps at most 1 MiB of stdout and the last 4 KiB of stderr, both counted in UTF-8 bytes and the tail cut at a character boundary, and settles only after the process exits. It reads the pipes until they close, at most until 2 seconds after the subprocess runtime reports the exit, so the result does not wait for a descendant that inherited them to close them; what the descendant writes after that is dropped. onLine receives each line as the command writes it: \n, \r\n, and a lone \r each end a line, as in Node's readline, so a spinner the CLI redraws with \r after a link line does not hold the link back. The unterminated rest arrives at exit, and a line longer than its stream's limit is skipped whole rather than truncated. No line arrives after the command settles. A command rejects instead of returning its exit code when executable lookup or spawning fails, the deadline elapses, the process ends by a signal, or stdout exceeds 1 MiB; the plugin's classification then sees a null exit code.
offer(url) accepts only an HTTPS URL without credentials on one of the plugin's authorizationHosts or their subdomains, and returns whether it accepted the link. Write each host in lowercase ASCII, with an internationalized domain name in punycode, because the runtime compares it with the URL's normalized host name.
A failed operation logs and returns only the plugin's classification of its last command, { command, exitCode } plus allowlisted fields; exception messages and native output are neither logged nor returned, because they may contain credentials.
Shared config
Plugins with no other fields use CliAccountConfig as their Config:
| Field | Default | Meaning |
|---|---|---|
binDir |
defined by the plugin | Absolute directory holding the CLI executable |
commandTimeoutMs |
30000 |
Deadline for a command that does not wait for the user, including executable lookup |
Understand the implementation
Implementation internals — click to expand
The runtime owns the operation lifecycle and the plugin owns the meaning of each command. One active operation holds its abort controller, phase, and link; the runtime builds the view from them and notifies followers on every change, and a follower that reads late sees only the latest view. The executor verifies the configured absolute path through the subprocess runtime and spawns it without adding environment variables; the runtime context names the same path, so the plugin and the model's Shell commands run the same executable.
| File | Role |
|---|---|
src/executor.ts |
Bounded command execution and process ownership |
src/runtime.ts |
One-at-a-time operations, cancellation, link filtering, failure classification, and the follow stream |
src/context.ts |
The runtime-context entry that names the executable path |
src/types.ts |
The generic Remote view types |
src/index.ts |
The entry module and the shared config fields |
Further Exploration
- Connector packages — the group this library and the CLI app plugins belong to.
- CLI plugin page pieces — the browser half that mirrors the view.
- System prompt — the registry that orders and renders runtime context.
- Subprocess — the runtime that resolves and spawns the CLI.
Model Experience
CLI path
What the model sees
One required runtime-context entry, at context order 220, for each plugin that calls registerCliPathContext and whose ready is absent or returns true; it stays when optional runtime context is off. The second line appears only with scripts. The placeholders come from the call, and the quoted values are JSON strings.
Runtime-context entry
<Product> CLI: run `<program>` by its absolute path "<executable>"; the bare name may resolve to another installation or to none.
Scripts in the <Product> skill call `<program>` by name; prefix only the commands that run them with PATH="<executable directory>:$PATH", and never export PATH or run `<program>` by name yourself.
Token effect
One or two lines in each runtime-context snapshot for each registering plugin. A changed path, or an entry that appears or disappears, adds one snapshot.
KV Cache effect
The path is runtime context rather than system prompt, so the cached prompt prefix is the same for every installation path; a change appends one runtime-context snapshot after it.
Known Limitations and Deferred Work
- The 10-minute deadline for commands that wait for the user and the 1 MiB stdout limit are fixed; a CLI whose sign-in waits longer fails with a retryable result.
- Authorization hosts match their subdomains too; a plugin cannot restrict links to one exact host.
exitFailureclassifies by exit code alone; a plugin whose CLI reports structured errors writes its own allowlisting classifier.- The runtime context asks the model to run the CLI by its absolute path but cannot enforce it; a command that names the CLI by bare name runs whatever installation PATH resolves, or fails.
Dev Note
Working context for maintainers — click to expand
None.