* feat(system-prompt): admit section updates incrementally * docs(system-prompt): accept retirement restart gap * test(system-prompt): cover retirement and reentry before admission * test(system-prompt): align rebase fixtures and persistence history * fix: align section prompt consumers and CI fixtures * test: pin credentials for section snapshot fixtures * test: align remaining snapshots with section admission * test: preserve section metadata in Web and PowerShell replays * refactor(system-prompt): retire sections through Cordis cleanup * chore: refresh section admission history after rebase * fix(system-prompt): advance admission head after compaction * fix(system-prompt): trim sections before admission hashing * docs: move system upgrade guides to current version * docs: add system message contribution cookbook * perf(system-prompt): avoid indexing history for admission * refactor(system-prompt): derive admission from logged sections * test(system-prompt): update lifecycle and compaction consumers * test(system-prompt): refresh CLI section event expectations * test(system-prompt): refresh question composer section metadata * feat(system-prompt): resolve same-name sections by scope * refactor(persona): use ordinary section registrations * refactor(system-prompt): clarify assembly and related control flow * test(system-prompt): reconcile rebased section snapshots * test(python): use current system text helper after rebase * test(system-prompt): refresh CLI expected section blocks * test(system-prompt): reconcile latest master integration * test(agent-loop): seed tools before deferred addition assertion * refactor(compaction): replace system heads when compacting prefixes * refactor(system-prompt): separate source text and notice attribution * fix(system-prompt): preserve legacy instructions in compaction snapshots * refactor(compaction): build system snapshots while reading the summary prefix * refactor(compaction): rebuild current system instructions * refactor(system-prompt): defer compaction rebuild to admission * refactor(system-prompt): remove redundant fixtures and setup * fix(plan-mode): announce committed user transitions * docs(system-prompt): reconcile section lifecycle and compaction design * refactor(system-prompt): consolidate projection version increments * fix(system-prompt): reconcile master integration and replay fixtures * docs(system-prompt): align upgrade guide with current release * refactor(system-prompt): make admission operations explicit * fix(system-prompt): reconcile master API and release changes * docs(system-prompt): regenerate catalogs after master refresh * refactor(llm-pi-ai): delegate text rendering to pi-ai * fix(llm-pi-ai): preserve blank lines between system text parts * refactor(system-prompt): remove redundant retirement metadata * refactor(system-prompt): own admission and use canonical surface targets * refactor(system-prompt): compare captured sections at commitment Assembly fixes section text and lifecycle; PromptAssembly.systemUpdates() compares them with the committed projection when the loop commits. This replaces SystemPrompt.admit(), needsRebuild() and isCurrent(), the SystemAdmission export, the loop's reassembly after compaction, and SessionSurface.systemHeadResetSeq. The projection records a pending rebuild as a boolean that an attributed reset clears. After a compaction inside a step, the rebuilt head uses the sections captured for that step; later source changes arrive as ordinary updates at the next step. * test: await the session read fixture and type a matcher for lint * test(tool-executor-ptc): describe same-name section override on executor replacement Duplicate section names no longer reject a scoped executor; the earlier registration is overridden and returns as an ordinary update when the executor leaves. * docs(upgrade-guide): move system-prompt integrations to v0.2.2-rc.3 The root version on master is 0.2.2-rc.3; verify-upgrade-guides rejects a guide added under an earlier version directory. * refactor(system-prompt): rebuild over system messages without sections A system message without source.sections now marks rebuilding pending, like a compaction summary. The next model attempt replaces the head with current sections and clears later system messages. This removes the separate legacy flag and its appended whole-prompt replacement and notice. Sessions written by earlier releases, migrated logs, and imported DeepSeek conversations take the same path, so the importer and its tests return to their master versions. * test(web): refresh the imported-conversation recording and drop a stray bytecode file The Web recording for a resumed DeepSeek import was recorded while the prompt was appended after the imported history; the head is replaced again, as on master. The .pyc under the macOS signing skill was staged by accident in an earlier merge. * refactor(session): scan system nodes on read surface.systemNodes is read only when a system rebuild is written. Scanning the current surface nodes on each read restores the surface fold's plan types and state to their master definitions, which no longer carry the system message. * refactor(session): rename SystemSurfaceNode.hasContent to isEmpty The flag reports that the logged content array has no blocks. isEmpty matches the documented "empty head" wording and covers a head that was written empty without ever being cleared. * refactor(llm): join system text through extractTextContent extractTextContent gains a trim option that trims each text block and omits blocks left empty. The DeepSeek serializer, the pi-ai converter, and the prompt inspector use it with a blank-line separator in place of three hand-written joins. The pi-ai converter now trims system and developer text like the other two, so whitespace-only blocks are omitted there as well. * test(snapshots): refresh the PowerShell and cordis-inspect recordings The two PowerShell scenarios still held the initial system message as one unattributed block; replay now writes one block per section with its attribution. The cordis-inspect-jsdoc recording embeds the API catalog, which names SystemSurfaceNode.isEmpty since the rename. * test(plan-mode,harness-dev-context): cover a rejected pre-step and a repeated legacy prompt A rejected pre-step must leave a queued plan-mode switch pending and unannounced until the next accepted step. A second unattributed system message with the same legacy paragraphs must keep the admitted paragraphs. * test(web): refresh Web recordings for section-attributed system messages Twenty-seven Web recordings still held the initial system message as one unattributed block. Replay now writes one text block per section with its attribution; twenty-six recordings differ only in that line. plan-review also records the plan-mode switch notice before the first prompt and appends a plan:status update on exit in place of a head replacement and a series header, so its expanded golden gains the notice row. The Creator persona test joins the system text blocks with blank lines, as the adapters do, before matching the persona line. * refactor(system-prompt): require the retry argument of systemUpdates The agent loop passes it on every attempt. A custom loop that omitted it on a retry received a full comparison in place of the pending rebuild, with no diagnostic; the type now makes each caller state which attempt it is. * docs(upgrade-guide): move the system prompt integrations guide to v0.2.2-rc.5 The root version is 0.2.2-rc.5 after the master merge, and verify-upgrade-guides rejects a guide added under an earlier version directory. * test(web): refresh the mention path presence recording for section-attributed system messages * test: align two specs that master left failing The DeepSeek settings spec waited for a saved notice carrying the provider label from before the rename to DeepSeek API. The Windows packaging workflow spec seeded one of the two helpers that the Stage workflow helpers step copies. * chore: remove a Python cache file committed by mistake
description, kind
| description | kind |
|---|---|
| Plan mode for users and maintainers choosing, configuring, or debugging the per-agent planning feature with deployment guidance, a /plan command, and a user-reviewed exit. | package-reference |
@deepseek-ai/dsh-plan-mode
English | 中文
Summary
Plan mode asks an agent to explore and design before execution, then presents the finished plan for your approval. Enter it with /plan, optionally with a message or ordered image and file attachments; leave with /plan off, approve the review to continue, or return feedback for more planning. Deployment-defined guidance controls planning behavior, but every tool remains available, so use sandbox mode and approval prompts for enforced limits. The active state survives session resume and forks. Choose it when you want a reviewed plan before the agent acts.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
When plan mode is active, the agent works under your instructions and presents its plan for review instead of executing right away. The common path: configure the guidance text, enter plan mode with /plan, and review the finished plan when the agent calls exit_plan_mode.
When to choose it
Choose plan mode when the agent should explore and design before executing and you want to approve the plan first. It does not restrict the agent: every tool stays callable, so use sandbox mode and approval prompts when you need enforced limits. Skip it when the agent should act on your requests immediately, without a planning phase.
Minimal configuration
The only required configuration is the guidance text the agent follows while planning; anything else you add fails at load.
- name: '@deepseek-ai/dsh-plan-mode'
config:
section: |
You are in plan mode. Explore and design before presenting the complete
plan through exit_plan_mode.
| Field | Default | Meaning |
|---|---|---|
section |
required | Conditional plan:policy guidance retained after the first plan-mode entry |
The generated configuration catalog is the exhaustive source for every accepted field and its JSDoc.
Entering and leaving plan mode
Type /plan to enter plan mode, or /plan <message> to enter with an instruction — the message becomes your next request under plan guidance. Type /plan off to leave plan mode directly; it also cancels a plan-mode entry that has not taken effect yet.
You can attach images and generic files to a /plan message, and they are included with your instruction in selection order. /plan off with attachments is rejected before the mode changes, so the draft and cards remain available. The /plan command is available wherever slash commands are supported, such as the Web client.
The reviewed exit
When the agent has a finished plan, it calls exit_plan_mode with the plan written as markdown and starting with a heading. You review that exact plan and choose Approve to leave plan mode, or Keep planning to send the agent back with feedback.
Choosing Keep planning (optionally with free-text feedback) sends the agent back to revise the plan; closing the review to type a message instead ends the agent's turn, and your next message starts the next request. If no interactive review is available, exit_plan_mode cannot run and you can still leave plan mode with /plan off.
Observing plan state
Interfaces can show whether plan mode is active and whether a mode change you requested is still waiting to take effect. The state is the same in every tab and survives restarts.
Understand the implementation
Implementation internals — click to expand
This section explains the design decisions behind the package and points at the code that realizes them; the observable behavior is fully covered in Use this package.
Design philosophy
Plan mode is a product package, not a capability seam: there is no swappable backend, so the state, guidance, command, and exit tool live in one place. The durable stance is one log-only whole-value-replace event, never a live mirror, so resume, fork, and compaction recover it by folding the log. Guidance is a soft layer — the package registers one prompt section and one tool, and restrains through text rather than filtering capabilities.
Durable state and step-boundary appends
The package persists one log-only whole-value event, plan/mode, and the last logged value is the state. A mode change appends immediately when no turn is open; during an open turn it stays pending until the next accepted in-turn pre-step — the only append point while an agent runs — and an append failure cannot block the turn. The set/get service methods and their exact return states live in src/index.ts and read the retained plan projection handle, acquired during activation.
The /plan command
The command child activates only when a commands service is composed. It maps bare /plan to active, the exact argument off to inactive without model input, and any other non-empty argument to active plus the trimmed text submitted through agent.steer() as the next step's ordinary logged user message. Admitted image and file blocks keep their selection order in that message; /plan off with attachments fails before any mode change. Entry points other than the command may drive ctx.planMode directly; the exact branch handling is in src/index.ts.
The exit tool
exit_plan_mode is disclosed progressively: it is admitted from the first step whose selected plan state is active and stays admitted for the rest of the Session, so entering plan mode the first time adds it together with the guidance, and later transitions change only the guidance; Native and PTC execution use the same admitted set. A call while plan mode is not committed fails with PlanModeError PLAN_NOT_ACTIVE, and a plan without a leading # heading fails with ToolArgsError before review. An approved review records a silent pending exit that the next accepted in-turn pre-step appends, keeping plan guidance for the rest of the current tool batch. Without a user-questions channel (ToolContextUnavailableError), or after a service reload while the review is pending (PLAN_REVIEW_INTERRUPTED), the call fails closed and /plan off remains the manual escape. src/error.ts lists the PlanModeError codes.
Session projection unit
The package requires ctx.sessionProjections and awaits registration of the plan unit during activation. Its prompt section is registered before that wait. Agent prompt assembly, the /plan command, and exit_plan_mode fail with PlanModeError PLAN_STATE_UNAVAILABLE while the reader is unavailable, so a restored plan cannot run without its guidance. Callers must await plugin activation before running an agent.
The unit turns logged /plan command runs into a candidate target, commits the logged state on plan/mode, and derives { active, pending } for view, where pending is true only while an unsettled or successful selection differs from the logged state — a pure replay quantity recoverable from the log alone. The key merges into SessionProjectionMap from src/types.ts; the framework drives the unit, and unloading the plugin fiber unregisters the key. State reads use the retained handle and remain available after unregistration.
Source map
| File | Role |
|---|---|
src/index.ts |
Plugin entry: Config schema, the ctx.planMode service, plan:policy section, /plan command, exit_plan_mode tool |
src/types.ts |
The plan projection-key declaration and PlanProjection wire value |
src/error.ts |
PlanModeError and its closed code union |
src/client.ts |
Client-namespace re-export of the types outlet |
The review intent carries the originating tool-call id, so the Web client can reopen the same submitted plan after the review closes. The complete Markdown remains in the existing native call or PTC dispatch log.
Further Exploration
Read these pages when the package-level contract is not enough. They move from the subsystem semantics to the generated catalogs and the design decision.
- Plan mode subsystem reference — how plan mode behaves, its configuration, and the exit tool's contract.
- plan/ package map — the group and its single package.
- exit_plan_mode tool catalog entry — the exact schema the model receives.
- Generated configuration catalog — every accepted config field and its meaning.
- archived Plan-specific collaboration state — the design decision behind plan mode.
Model Experience
Plan policy system prompt
What the model sees
The first entry introduces plan:policy: a conditional introduction followed by the configured section text. The policy remains registered after exit. A separate plan:status states whether plan mode is active; exit and reentry change only this status. After compaction, the service restores the policy and current status together.
Configuration example
You are in plan mode. Explore and design before presenting the complete plan through exit_plan_mode.
Token effect
Before first entry, plan mode contributes no text. Afterwards, the policy stays in history; each transition adds only a short status notice. Compaction introduces the retained policy and current status once.
KV Cache effect
Mode transitions append status without changing the earlier instruction prefix. The first entry also appends the policy. Provider cache reuse depends on the adapter’s representation.
Human command
What the model sees
/plan, /plan off, and their terminal results stay outside model history. A non-empty suffix other than the exact off argument becomes one user message through agent.steer() after plan mode is selected: admitted image and file blocks in selection order, then the trimmed text block. Bare /plan with admitted attachments steers one user message containing only those blocks. Every committed user-selected mode transition adds a logged user-switch notice, including entry before the first request. No-op selections and pending switches cancelled before commitment add none. An approved exit tool result explains its transition without an extra notice.
Token effect
The optional message costs the same history tokens as submitting that content separately. Each committed user-selected transition adds a short retained notice; attachments have their normal image and file-handle cost.
KV Cache effect
User content and switch notices append after the existing conversation prefix. Mode transitions append system status updates without rewriting the retained policy.
Exit tool schema and review exchange
What the model sees
The exit_plan_mode schema is offered from the first plan-mode entry in a Session; earlier calls return UNKNOWN_TOOL, calls after leaving plan mode fail as unavailable outside plan mode, and an approved in-mode review returns the canonical { approved: true } value and renders the existing confirmation text. Rejection remains a failed call with PLAN_REVISION_REQUESTED carrying review feedback. A dismissed review returns { approved: false }, renders a note that the user will reply, and concludes the turn without another model request.
Token effect
The schema is paid from the first entry on, according to ToolRuntime mode, and each plan argument and review result remains in conversation history.
KV Cache effect
The first entry into plan mode adds the exit tool through the route’s tool-update protocol; in-history and addition-only routes record the addition after cached history, while a route without tool updates resends its changed declaration list once. Later transitions leave the tool list unchanged. Plan arguments and review results extend the conversation normally.
Known Limitations and Deferred Work
These limits describe when plan mode does not behave as you might expect or needs extra care. They are current package constraints, not a roadmap.
- Guidance, not enforcement — plan mode restrains through text only; deployments that need enforced restrictions configure sandbox mode and approval policy independently.
- Pending selections are process-local — a selection made after the turn's final accepted pre-step is lost if the process exits before another accepted in-turn pre-step; the UI must reapply it.
- No creation-time plan option — forked agents inherit logged plan state, while newly spawned agents begin inactive.
- Subagents cannot open the review — a Session with subagent origin fails the
exit_plan_modecall and is told to include the unresolved decision in its final result; historical ordinary forks can open the review despite retained parent metadata. - One specialized review renderer — only the Web UI has a
plan-reviewpresentation; another interaction provider presents the same request through its generic option flow.
Dev Note
Working context for maintainers — click to expand
This Dev Note is working context for maintainers: open design questions and directions that are not decided. It is explicitly non-authoritative — shipped behavior, limits, and accepted rationale live in the sections above, the package code, and the linked Agent Note.
Future: a second collaboration mode
The design note rejected a generic named-mode registry because the product shipped only plan; a future collaboration state would establish a shared seam only from two concrete cases, and any extraction must keep plan/mode's log-only fold, the boundary append, and the reviewed exit intact.