Skip to content

refactor(prompts): decouple allow_shell from static system-prompt prefix#2949

Merged
Hmbown merged 1 commit into
Hmbown:mainfrom
LeoAlex0:decouple-allow-shell-from-system-prompt
Jun 10, 2026
Merged

refactor(prompts): decouple allow_shell from static system-prompt prefix#2949
Hmbown merged 1 commit into
Hmbown:mainfrom
LeoAlex0:decouple-allow-shell-from-system-prompt

Conversation

@LeoAlex0

@LeoAlex0 LeoAlex0 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary · 概述

Move allow_shell from message[0] (static system prompt prefix) to the per-turn <runtime_prompt> tag alongside mode and approval.

allow_shell 从 message[0](静态 system prompt 前缀)移至每轮 <runtime_prompt> 标签,与 modeapproval 并列。

Motivation · 动机

The DeepSeek prefix cache keys on the byte-stable prefix of each request. When allow_shell was embedded in message[0], toggling shell access or switching modes forced a full prompt rebuild — losing cache and increasing latency.

By moving all three runtime flags (mode, approval, allow_shell) into the per-turn <runtime_prompt> tag, message[0] bytes remain stable regardless of shell-access state or mode switches. The model still sees the same Shell Policy reference (static text in the Runtime Policy Reference section), but the binary on/off flag is delivered per-turn.

DeepSeek 的 prefix cache 基于每次请求中字节稳定的前缀。当 allow_shell 嵌入 message[0] 时,切换 shell 访问或切换模式会迫使整个 prompt 重建,导致缓存丢失、延迟增加。

将三个运行时标志(modeapprovalallow_shell)全部放入每轮 <runtime_prompt> 标签后,message[0] 字节不再受 shell-access 状态或模式切换影响,保持稳定。模型仍能看到相同的 Shell Policy 参考(Runtime Policy Reference 中的静态文本),但二值开关按轮次传递。

Changes · 变更

  • Delete remove_shell_tool_guidance and 3 other dead functions (~60 lines)
  • Remove allow_shell field from PromptSessionContext and StaticPromptCtx
  • Remove dead shell_tools_available parameter from compose functions
  • Add Shell Policy section to Runtime Policy Reference (static text, always present)
  • Extend <runtime_prompt> tag with allow_shell="true|false" attribute
  • Update tests: omits→always_keeps assertions; 83/83 prompts tests pass
  • Drop dead compose_mode_prompt_with_approval_and_model

  • 删除 remove_shell_tool_guidance 等 4 个死函数(约 60 行)
  • PromptSessionContextStaticPromptCtx 中移除 allow_shell 字段
  • 移除 compose 函数中的死参数 shell_tools_available
  • 在 Runtime Policy Reference 中新增 Shell Policy 章节(静态文本,始终存在)
  • 扩展 <runtime_prompt> 标签,增加 allow_shell="true|false" 属性
  • 更新测试:omits→always_keeps 断言;83/83 prompts 测试通过
  • 删除死函数 compose_mode_prompt_with_approval_and_model

Net · 效果

message[0] bytes are now stable regardless of shell-access state. Mode/approval/shell flags all use the same per-turn tag pattern.

message[0] 字节现在不随 shell-access 状态变化,保持稳定。mode/approval/shell 三个标志统一使用每轮 tag 模式。

Files · 涉及文件

  • crates/tui/src/core/engine.rs — runtime_prompt_text signature, caller updates
  • crates/tui/src/prompts.rs — remove dead functions, add Shell Policy, update tests
  • crates/tui/src/tui/ui.rs — drop allow_shell from StaticPromptCtx call site

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@LeoAlex0 LeoAlex0 force-pushed the decouple-allow-shell-from-system-prompt branch from cc409b9 to 638b50c Compare June 9, 2026 17:26

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request decouples the allow_shell configuration from the static system prompt prefix, moving it instead to the per-turn <runtime_prompt> tag. This change prevents mutating the static system prompt when shell access is toggled, thereby preserving the DeepSeek prefix cache. As a result, the complex logic for dynamically removing shell tool guidance from the static prompt has been removed, and the static prompt now always includes full shell tool guidance. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@LeoAlex0 LeoAlex0 force-pushed the decouple-allow-shell-from-system-prompt branch from 638b50c to 6d44dad Compare June 9, 2026 17:32

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@LeoAlex0 LeoAlex0 force-pushed the decouple-allow-shell-from-system-prompt branch from 6d44dad to ed84ef1 Compare June 9, 2026 17:37

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Move allow_shell from message[0] (static system prompt) to the per-turn
<runtime_prompt> tag alongside mode and approval.  This preserves the
DeepSeek prefix cache across shell-access toggles and mode switches,
which previously forced YOLO entry/exit to rebuild the entire prompt.

Changes:
- Delete remove_shell_tool_guidance and 3 other dead functions (~60 lines)
- Remove allow_shell field from PromptSessionContext and StaticPromptCtx
- Remove shell_tools_available dead parameter from compose functions
- Add Shell Policy section to Runtime Policy Reference (static text)
- Extend <runtime_prompt> tag with allow_shell="true|false" attribute
- Update tests: omits→always_keeps, 83/83 prompts tests pass
- Drop dead compose_mode_prompt_with_approval_and_model

Net: message[0] bytes are now stable regardless of shell-access state.
Mode/approval/shell flags all use the same per-turn tag pattern.
@LeoAlex0 LeoAlex0 force-pushed the decouple-allow-shell-from-system-prompt branch from ed84ef1 to 9206eb9 Compare June 9, 2026 17:44

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@LeoAlex0 LeoAlex0 marked this pull request as ready for review June 9, 2026 17:51

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@Hmbown Hmbown merged commit f12863f into Hmbown:main Jun 10, 2026
9 checks passed
@Hmbown

Hmbown commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Merged — thank you @LeoAlex0. Reviewed in full: the inversion from prompt-redaction to runtime-gates + per-turn tag is the right architecture for prefix-cache stability, and deleting remove_shell_tool_guidance removes a whole class of byte-drift bugs. The Shell Policy reference section is a clean pattern for future flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants