Status: implemented. Tracks #2144. This document is authoritative for the terminal-authentication slice of
docs/features/acp-v1-reliability/.
DeepChat exposes ACP authentication for Registry and manual agents through a shared runtime and
typed desktop UI. The process initializer advertises clientCapabilities.auth.terminal only when
the desktop runtime can launch and present the interactive flow. AcpProcessHandle retains the
methods returned by initialize; a numeric auth_required response creates a caller-owned
challenge instead of requiring the user to restart the app or guess a login command.
AcpAuthService orchestrates method selection and recovery. AcpTerminalAuthRunner uses
node-pty to execute the agent's materialized command and arguments directly, while
AcpAuthDialog presents the terminal through xterm. Agent-requested terminal/* commands remain
a separate ACP session capability.
The normative references are:
Terminal authentication is currently a Preview capability carried by the v1 draft schema. The installed TypeScript SDK still marks the relevant generated types as unstable, so the feature must remain isolated behind capability negotiation and protocol-shaped tests.
After a terminal login process succeeds, DeepChat must not call authenticate with the
terminal method ID. Terminal authentication is an out-of-band flow:
- initialize and receive a
terminalauth method; - run the configured agent program interactively with the method's additional arguments and environment;
- treat only exit status
0as success; - reconnect and reinitialize the ACP agent;
- retry the operation that received
auth_required.
authenticate({ methodId }) remains valid only for an agent auth method, including a method with
no explicit type discriminator.
- Advertise
clientCapabilities.auth.terminal=trueonly when the bundled desktop runtime can direct-spawn and present the interactive login flow. - Preserve and expose all returned authentication methods without treating their presence as proof that authentication is required.
- Convert ACP error code
-32000into a typed, actionable auth-required state. - Let the user select among multiple methods and complete
agentorterminalauthentication. - Run terminal authentication with the exact materialized launch command used by the live ACP connection, base arguments followed by method arguments, and method environment overriding the base environment.
- Reconnect after successful terminal login and retry one blocked session preparation exactly once.
- Handle cancellation, non-zero exit, process failure, stale challenges, window closure, and app shutdown without leaking processes or retrying unexpectedly.
- Apply the same behavior to Registry and manual agents without agent-specific branches.
- Do not add MiniMax Code or any other agent as a DeepChat-specific built-in. Discovery remains an ACP Registry concern.
- Do not implement ACP v2.
- Do not parse terminal output to infer success. ACP defines the exit status as the interoperable signal.
- Do not collect or persist credentials in DeepChat. The interactive agent process owns them.
- Legacy
env_varauth descriptors remain unsupported, with guidance to use the existing manual environment override. - Do not automatically choose a method when the agent advertises more than one supported method.
- Do not automatically replay a user prompt. Only session preparation blocked before a prompt is eligible for the one-shot retry.
- Do not reuse
AcpTerminalManager; it implements agent-to-clientterminal/*requests inside an ACP session, not the client-owned out-of-band authentication process.
Direct ACP execution remains owned by AcpRuntimeOwner, AcpAgentRuntime, and
AcpAgentInstance. AcpProvider remains a compatibility adapter and must delegate authentication
to the shared runtime instead of adding a second flow.
NewThreadPage / AcpSettings / AcpAuthDialog
|
typed acpAuth routes
|
AcpRuntimeOwner
|
AcpProcessManager
/ \
live ACP connection AcpTerminalAuthRunner
\ /
reconnect + reinitialize
|
retry session preparation once
Only one new runtime unit is justified: AcpTerminalAuthRunner, a narrow PTY lifecycle wrapper.
Challenge state, method validation, connection replacement, and retry eligibility stay in
AcpProcessManager and the existing session/runtime layers.
The unused shell-injection behavior in AcpInitHelper must be retired or reduced to the new direct
PTY runner. DeepChat must not retain two competing interactive ACP launch paths.
AcpProcessManager receives an injected terminalAuthAvailable capability. Production composition
sets it only after the direct PTY runner and typed renderer surface are registered successfully;
tests can explicitly set it to false.
buildClientCapabilities({
enableFs: true,
enableTerminal: true,
enableTerminalAuth: terminalAuthAvailable
})Invariants:
auth.terminalis advertised duringinitialize, before an agent can return terminal methods.- The capability describes implemented client behavior; it is not enabled only after a login has already completed.
- If the runner cannot be constructed, DeepChat omits the capability and fails closed.
- Remote or headless callers may observe an auth-required state, but cannot start an interactive terminal flow without a live local renderer caller.
- Agent-requested
terminal/*support and terminal-auth support remain separate capabilities and code paths.
Authentication state is runtime-derived and scoped by (agentId, canonicalWorkdir, launchSignature). It is not persisted as an account truth because ACP does not expose an
authenticated-state query and agents may invalidate credentials independently.
type AcpAuthMethodView = {
id: string
name: string
description?: string
type: 'agent' | 'terminal' | 'unsupported'
}
type AcpAuthChallenge = {
id: string
agentId: string
agentName: string
workdir: string
methods: AcpAuthMethodView[]
origin: 'draft_session' | 'session_prepare' | 'settings_probe'
sessionId?: string
}
type AcpAuthRunState =
| 'required'
| 'running'
| 'reconnecting'
| 'succeeded'
| 'cancelled'
| 'failed'Rules:
- Missing
typeis normalized toagent. terminalis supported only when the capability was advertised and the descriptor came from the current live handle.- Legacy
env_varand unknown discriminators are preserved for diagnostics but normalized tounsupportedfor product control flow. authMethods.length > 0means methods are available; only ACP error code-32000means an operation currently requires authentication.- Challenges become stale when their connection exits, agent settings change, workdir changes, or
launchSignatureno longer matches. - At most one auth run may exist for an agent/workdir pair. Repeating the same challenge returns its current state to the owning renderer; a different challenge for the same scope is rejected.
The protocol connection and terminal-auth process must share one materialization function. Extract
the existing command rewrite, environment merge, PATH handling, Registry/toolchain settings, user
override, and cwd validation from spawnAgentProcess into a pure result:
type AcpMaterializedLaunch = {
command: string
args: string[]
env: Record<string, string>
cwd: string
}The immutable materialized launch snapshot and its separate launch signature are stored on the
initialized process handle. A terminal challenge uses that internal snapshot rather than exposing
it to the renderer or resolving settings again, which prevents a time-of-check / time-of-use change
between initialize and login.
For a selected terminal method, the runner executes the equivalent of:
pty.spawn(materialized.command, [...materialized.args, ...(method.args ?? [])], {
cwd: materialized.cwd,
env: { ...materialized.env, ...(method.env ?? {}) }
})The preview command shown to the user may be shell-escaped for display only. It must never be fed
back to a shell. The method cannot replace command, and neither arguments nor environment values
are interpolated.
Environment values and PTY output must not enter ordinary info logs. Diagnostics may record key names, argument counts, process IDs, exit status, and bounded error text, but not credential values or unredacted terminal transcripts.
AcpSessionManager identifies RequestError.code === -32000 before its existing resume/load/new
fallback logic. Auth-required errors must not be swallowed as an ordinary resume/load failure and
must not cause a fallback session/new call.
The session layer creates an AcpAuthChallenge from the current process handle and returns an
actionable state to the renderer. A newly created local draft remains reusable; no remote ACP
session has been created yet.
For type='agent' or an omitted type:
- validate the selected ID against the current handle's auth methods;
- call
connection.authenticate({ methodId })on the existing ACP connection; - mark the auth run successful only when the request succeeds;
- retry eligible session preparation once on the same connection;
- stop if the retry again returns
auth_requiredor any other error.
For type='terminal':
- validate caller ownership, challenge freshness, method ID, type, and launch signature;
- keep the existing protocol connection alive while a separate PTY process runs;
- direct-spawn the materialized command with base args plus method args and the merged env;
- stream PTY output only to the renderer that started the run and forward bounded user input;
- cap each PTY run at ten minutes; on timeout, cancellation, window closure, app shutdown, missing exit status, signal termination, or non-zero exit, terminate the PTY tree and do not retry;
- on exit status
0, dispose the old ACP process handle; - start a fresh connection with the same agent/workdir and run
initializeagain; - do not call
authenticatewith the terminal method ID; - retry eligible session preparation once;
- stop after that retry regardless of outcome, preventing authentication loops.
If reconnect fails, the run ends in failed; a zero terminal exit alone must not be reported as a
usable ACP connection.
The existing sessions.ensureAcpDraft path returns a discriminated result:
type EnsureAcpDraftResult =
| { status: 'ready'; session: SessionWithState }
| { status: 'auth_required'; session: SessionWithState; challenge: AcpAuthChallenge }After an auth route returns succeeded, NewThreadPage invokes the same idempotent draft ensure
operation once. It reuses the local draft and performs the normal resume/load/new decision against
the refreshed connection. The renderer must not loop automatically when the retry fails.
This slice automatically retries only the new-thread draft preparation path. An existing session can recover after authentication from ACP settings and a subsequent user action, but DeepChat must not automatically replay a prompt that may already have been handed to the agent.
Add an auth-specific contract rather than exposing raw ACP payloads to the renderer:
acpAuth.inspect: initialize or reuse a handle and return renderer-safe methods/status.acpAuth.start: select a method and run agent or terminal authentication.acpAuth.input: send bounded input to the caller-owned PTY run.acpAuth.cancel: cancel the caller-owned run.acpAuth.status: recover current state after a settings view remount.acpAuth.output: targeted PTY output event withrunIdand bounded data.acpAuth.stateChanged: targeted lifecycle event with no environment or transcript data.
Every mutation route must use RouteContext to bind the run to the initiating webContentsId.
Input, cancel, and output delivery must reject or ignore a different renderer. A destroyed initiating
window cancels its active PTY run.
Terminal-auth input and cancellation use the run-ID/caller-owned auth contract. The unscoped
acpTerminal.input/kill singleton routes are not exposed.
The primary onboarding surface is NewThreadPage, where the user has already selected an ACP agent
and a valid workdir. AcpSettings also exposes Check sign-in on installed Registry and manual
agent cards; when no configured or reusable workdir exists, the runtime uses its constrained ACP
temporary workdir.
Auth-required state:
+----------------------------------------------------+
| MiniMax Code needs sign-in |
| Choose how to authenticate before starting chat. |
| Method: [Log in from terminal v] |
| [Open terminal] [Cancel] |
+----------------------------------------------------+
Interactive terminal:
+----------------------------------------------------+
| Sign in to MiniMax Code [x] |
|----------------------------------------------------|
| $ interactive agent output... |
| > |
|----------------------------------------------------|
| Running [Cancel sign-in] |
+----------------------------------------------------+
UX rules:
- If exactly one supported method exists, preselect it; otherwise require an explicit selection.
- Unsupported/legacy methods remain visible but disabled with a concise explanation.
- Display
Signing in,Reconnecting,Ready,Cancelled, andFailedas distinct states. - Closing the dialog while the PTY is running cancels the process.
- A successful terminal exit displays
Reconnectinguntil the new ACP initialization succeeds. - Do not label the user authenticated merely because
initializereturned auth methods. - User-facing copy uses vue-i18n and the existing compact settings/onboarding visual language.
- Registry and manual agents use the same resolved launch pipeline.
- Existing pre-authenticated agents continue directly to session preparation.
- Agents that expose only
agentauth continue to use ACPauthenticatewithout a PTY. - Agents that do not advertise auth methods retain the current error path, augmented with a clear diagnostic that no supported method was supplied.
- Capability-disabled tests must prove no terminal method can enter product control flow.
- Updating an agent command, args, environment, installation, or workdir invalidates outstanding challenges and active warm handles through the existing launch-signature refresh path.
- Non-ACP providers and agent-requested terminal operations are unchanged.
- MiniMax Code (
mcode acp) is a manual interoperability sample until it is available through the official ACP Registry; no special source code or migration is added for it.
- A capable desktop initialization sends
clientCapabilities.auth.terminal=true; an injected unavailable runner omits it. - Terminal auth methods returned by
initializeare present in a renderer-safe auth challenge. - ACP error code
-32000from resume, load, or new session stops fallback and producesauth_required. - Selecting a terminal method direct-spawns the exact live command, appends method args to base args, applies method env last, preserves cwd, and never invokes a shell.
- DeepChat never calls ACP
authenticatefor a terminal method. - Exit
0disposes the old connection, reconnects, reinitializes, and retries session preparation once. - Non-zero exit, missing exit status, cancellation, caller destruction, stale challenge, reconnect failure, and second auth-required result do not retry.
- Multiple supported methods require user selection and the selected ID is revalidated in main.
- Only the initiating renderer can read output, send input, or cancel the run.
- No terminal transcript or auth environment value is persisted or written to ordinary logs.
- Registry and manual agents share the same implementation; no MiniMax-specific branch exists.
- Relevant main and renderer regression tests pass on macOS, Windows, and Linux CI targets.
| Risk | Mitigation |
|---|---|
| Preview schema changes in a later SDK | Keep schema handling localized, capability-gated, and covered by descriptor-shape tests |
| Shell injection through agent args | Direct node-pty.spawn(command, args) only; display strings are never executed |
| A settings edit changes the binary before login | Bind challenges to the immutable live launch signature and reject stale runs |
| Multiple windows race or read terminal output | Bind every run and event to the initiating webContentsId |
| Resume/load fallback hides auth required | Match numeric error code before fallback and surface one typed challenge |
| Exit zero but the new connection is unusable | Report success only after reconnect and initialize complete |
| Automatic retry loops | Close the resolved challenge before one explicit draft retry; a repeated auth-required response remains actionable but is not retried again |
| Secrets leak through logs | Log metadata only; never log env values or PTY transcripts |