Skip to content

feat: 大量系统提示词优化#446

Merged
claude-code-best merged 4 commits intomainfrom
feature/prompt-cut-down
May 10, 2026
Merged

feat: 大量系统提示词优化#446
claude-code-best merged 4 commits intomainfrom
feature/prompt-cut-down

Conversation

@claude-code-best
Copy link
Copy Markdown
Owner

@claude-code-best claude-code-best commented May 10, 2026


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced error boundary implementation for improved error handling across the application
  • Documentation

    • Refined system prompts for clearer tool guidance and better AI responses
    • Simplified memory system documentation and type definitions
    • Updated architectural and tool inventory guidance
  • Refactor

    • Optimized git status output handling
    • Improved deferred tools messaging structure
    • Enhanced communication style guidance in system prompts for better user interactions

Review Change Stack

claude-code-best and others added 4 commits May 9, 2026 17:14
- 合并 getOutputEfficiencySection + getSimpleToneAndStyleSection 为精简的 Communication style
- 精简 auto memory 指令:删除 4 种类型的详细说明和示例,仅保留核心 description
- 精简 Agent 工具:删除 forkExamples 和 currentExamples 大段示例
- 精简 Bash 工具:合并 sleep 相关指导
- 精简 EnterPlanMode/ExitPlanMode:删除详细 GOOD/BAD 示例
- gitStatus MAX_STATUS_CHARS 从 2000 降到 1000
- 同步更新 prompt engineering audit 测试断言

Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
- prependUserContext: 将 claudeMd 从通用 <system-reminder> 提取为独立的
  <project-instructions> 用户消息,不带免责声明,置于消息列表最前面
- queryModel: deferred tools 消息从 prepend 改为 append,避免抢占
  project-instructions 的最高权重位置;标签规范化为 <system-reminder>

Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
增强 SentryErrorBoundary 组件,捕获渲染错误时输出诊断信息
(错误消息 + component stack)到 stderr 和终端,而非静默返回
null。在 replLauncher 根节点和 Messages 组件层级包裹 Error
Boundary,防止 Ink 内部的 Error Boundary 直接终止进程。

Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
@mintlify
Copy link
Copy Markdown

mintlify Bot commented May 10, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ccb-863780bf 🟢 Ready View Preview May 10, 2026, 3:42 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

📝 Walkthrough

Walkthrough

This PR refactors the Sentry error boundary from TypeScript to TSX with enhanced error UI, updates multiple tool and system prompts for clarity, adjusts context and API message ordering, and refreshes repository documentation with expanded metadata and feature lists.

Changes

Sentry Error Boundary Refactoring

Layer / File(s) Summary
Component Types
src/components/SentryErrorBoundary.tsx
New Props interface with children and optional name; State interface tracks hasError, captured error, and errorInfo.
Error Catching & Reporting
src/components/SentryErrorBoundary.tsx
getDerivedStateFromError sets error state; componentDidCatch logs diagnostic, calls logError(), and reports to Sentry with componentBoundary and componentStack metadata. Error render shows Ink Box/Text UI with heading, message, and optional boundary name.
Migration
src/components/SentryErrorBoundary.ts
Removed old .ts version with prior error-suppression behavior.
Messages Integration
src/components/Messages.tsx
Imports SentryErrorBoundary and wraps main render tree as MessagesBoundary, replacing fragment root.
REPL Integration
src/replLauncher.tsx
App/REPL tree wrapped with SentryErrorBoundary as RootREPLBoundary in dynamic import.

Prompt Engineering & System Guidance

Layer / File(s) Summary
Agent Tool Guidance
packages/builtin-tools/src/tools/AgentTool/prompt.ts
Fork-mode "When to fork" section reworded; "Writing the prompt" section expanded with briefing checklists and simplified "Never delegate understanding" language.
Agent Prompt Assembly
packages/builtin-tools/src/tools/AgentTool/prompt.ts
getPrompt() removes conditional forkExamples/currentExamples append; FILE_WRITE_TOOL_NAME import removed (identifier still referenced in examples).
Agent Tests
packages/builtin-tools/src/tools/AgentTool/__tests__/prompt.test.ts
Background-task condition test validates absence of !forkEnabled; fork example block test removed.
Bash Tool Prompts
packages/builtin-tools/src/tools/BashTool/prompt.ts
getSimplePrompt() adds explicit run_in_background guidance and "Do not poll" instruction; MONITOR_TOOL conditional messaging adjusted.
EnterPlanMode Prompts
packages/builtin-tools/src/tools/EnterPlanModeTool/prompt.ts
External and ant prompts replace example-based guidance with numbered criteria lists; GOOD/BAD examples sections removed.
ExitPlanMode Prompt
packages/builtin-tools/src/tools/ExitPlanModeTool/prompt.ts
Trailing "## Examples" section removed.
System Prompt
src/constants/prompts.ts
getOutputEfficiencySection() replaces "Communicating with the user" with "Communication style" section emphasizing prose-first communication, emoji restrictions, and link formatting; getSimpleToneAndStyleSection() removed from assembled system prompt.
Memory Types
src/memdir/memoryTypes.ts
TYPES_SECTION_COMBINED and TYPES_SECTION_INDIVIDUAL simplified with concise descriptions; detailed sub-elements (when_to_save, how_to_use, examples) removed from individual types.
Audit Tests
src/constants/promptEngineeringAudit.runner.ts
Assertions updated to expect lowercase "don't restate", "report the outcome", "prose paragraphs", "describe the action in user terms", and revised conversation-end phrasing.

Context & API Message Ordering

Layer / File(s) Summary
Git Status Truncation
src/context.ts
MAX_STATUS_CHARS reduced from 2000 to 1000 characters.
Deferred Tools Ordering
src/services/api/claude.ts
Deferred-tools announcement moves from prepended to appended meta user message; wrapped with outer <system-reminder> tags.
Context Preparation
src/utils/api.ts
prependUserContext extracts claudeMd and emits as dedicated message in <project-instructions> tags; remaining context goes into <system-reminder> message.

Documentation & Metadata

Layer / File(s) Summary
Architecture Metadata
CLAUDE.md
Bun workspace package count and scripts/defines.ts version updated; src/main.tsx decompiled size refreshed.
Tool Inventory
CLAUDE.md
CORE_TOOLS whitelist description expanded; builtin-tools directory/tool count increased; searchExtraTools guidance updated with tool_result parameter note removed.
Workspace Packages
CLAUDE.md
Adds packages/mcp-client/ and packages/weixin/ entries; non-workspace package listings adjusted.
Build Features
CLAUDE.md
Default feature list expanded from ~19 to 65+ entries with additional named flags.
Removed Packages
CLAUDE.md
Explicitly marks packages/shell/, packages/swarm/, packages/mcp-server/, and packages/cc-knowledge/ as removed.
Integration Tests
CLAUDE.md
Documentation updated from 4 to 6 files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • KonghaYao

Poem

🐰 Errors now caught with Ink-drawn care,
Prompts refined with guidance fair,
Messages wrapped and context aligned,
Sentry and studio, seamlessly twined!
Hop-hop to safer, clearer code! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: 大量系统提示词优化' (feat: large-scale system prompt optimization) accurately describes the main changes in this PR, which focus on updating and optimizing system prompts across multiple files including tool prompts, communication style guidance, and memory type documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/prompt-cut-down

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 20.79208% with 80 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/components/SentryErrorBoundary.tsx 21.95% 32 Missing ⚠️
src/utils/api.ts 4.54% 21 Missing ⚠️
...uiltin-tools/src/tools/EnterPlanModeTool/prompt.ts 8.33% 11 Missing ⚠️
src/replLauncher.tsx 0.00% 6 Missing ⚠️
...ckages/builtin-tools/src/tools/AgentTool/prompt.ts 0.00% 5 Missing ⚠️
src/services/api/claude.ts 0.00% 4 Missing ⚠️
...ackages/builtin-tools/src/tools/BashTool/prompt.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/builtin-tools/src/tools/AgentTool/prompt.ts (1)

75-77: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update stale comment about fork-aware examples.

Line 76-Line 77 still states examples are swapped, but this function no longer appends example blocks. Please sync the comment with current behavior to avoid future confusion.

Suggested edit
-  // Fork subagent feature: when enabled, insert the "When to fork" section
-  // (fork semantics, directive-style prompts) and swap in fork-aware examples.
+  // Fork subagent feature: when enabled, insert the "When to fork" section
+  // (fork semantics, directive-style prompts).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/builtin-tools/src/tools/AgentTool/prompt.ts` around lines 75 - 77,
The comment above the forkEnabled declaration is stale: update the comment near
the isForkSubagentEnabled() call/const forkEnabled to reflect current behavior
(it only inserts the "When to fork" section and does not swap or append example
blocks anymore). Replace the phrase about swapping in "fork-aware examples" with
a short note that only the "When to fork" section is inserted when
isForkSubagentEnabled() returns true, referencing the isForkSubagentEnabled()
check and the forkEnabled variable so readers can locate the logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Messages.tsx`:
- Line 3: The import in Messages.tsx uses a relative path for
SentryErrorBoundary (import { SentryErrorBoundary } from
'./SentryErrorBoundary.js'), which violates the repo rule requiring src/*
aliases; update the import to use the tsconfig alias (e.g., import from
'src/components/SentryErrorBoundary') and remove the explicit .js extension if
not needed so the module resolution and linting conform to the project's
import-path policy.

In `@src/context.ts`:
- Line 20: The truncation notice string still refers to “2k characters” even
though the constant MAX_STATUS_CHARS was changed to 1000; update the message
(wherever the truncation notice is constructed/returned — reference the constant
MAX_STATUS_CHARS and the function or variable that emits the notice) to reflect
the new 1,000-character limit or, better, interpolate/format the message using
MAX_STATUS_CHARS so it stays correct when the constant changes (e.g., replace
the hardcoded “2k characters” text with a dynamic reference to MAX_STATUS_CHARS
or the value "1000").

In `@src/replLauncher.tsx`:
- Line 21: Replace the relative dynamic import in replLauncher.tsx that loads
'./components/SentryErrorBoundary.js' with the repo alias path under src (e.g.,
import from 'src/components/SentryErrorBoundary.js') so it follows the tsconfig
alias-only policy; update the import string inside the await import(...) call
where SentryErrorBoundary is imported.

---

Outside diff comments:
In `@packages/builtin-tools/src/tools/AgentTool/prompt.ts`:
- Around line 75-77: The comment above the forkEnabled declaration is stale:
update the comment near the isForkSubagentEnabled() call/const forkEnabled to
reflect current behavior (it only inserts the "When to fork" section and does
not swap or append example blocks anymore). Replace the phrase about swapping in
"fork-aware examples" with a short note that only the "When to fork" section is
inserted when isForkSubagentEnabled() returns true, referencing the
isForkSubagentEnabled() check and the forkEnabled variable so readers can locate
the logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39a3bb91-e2aa-4ee4-9f6d-97cfe6d34e3d

📥 Commits

Reviewing files that changed from the base of the PR and between 66b49d7 and 2006ab2.

📒 Files selected for processing (16)
  • CLAUDE.md
  • packages/builtin-tools/src/tools/AgentTool/__tests__/prompt.test.ts
  • packages/builtin-tools/src/tools/AgentTool/prompt.ts
  • packages/builtin-tools/src/tools/BashTool/prompt.ts
  • packages/builtin-tools/src/tools/EnterPlanModeTool/prompt.ts
  • packages/builtin-tools/src/tools/ExitPlanModeTool/prompt.ts
  • src/components/Messages.tsx
  • src/components/SentryErrorBoundary.ts
  • src/components/SentryErrorBoundary.tsx
  • src/constants/promptEngineeringAudit.runner.ts
  • src/constants/prompts.ts
  • src/context.ts
  • src/memdir/memoryTypes.ts
  • src/replLauncher.tsx
  • src/services/api/claude.ts
  • src/utils/api.ts
💤 Files with no reviewable changes (3)
  • src/components/SentryErrorBoundary.ts
  • packages/builtin-tools/src/tools/AgentTool/tests/prompt.test.ts
  • packages/builtin-tools/src/tools/ExitPlanModeTool/prompt.ts

@@ -1,5 +1,6 @@
import { feature } from 'bun:bundle';
import chalk from 'chalk';
import { SentryErrorBoundary } from './SentryErrorBoundary.js';
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use src/* alias for this new import path

Line 3 introduces a relative import from the src tree. This violates the repo import-path rule and can cause consistency/lint failures.

Suggested fix
-import { SentryErrorBoundary } from './SentryErrorBoundary.js';
+import { SentryErrorBoundary } from 'src/components/SentryErrorBoundary.js';

As per coding guidelines: “Import paths must use the src/* alias defined in tsconfig.json; do not use relative paths for imports from src directory”.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { SentryErrorBoundary } from './SentryErrorBoundary.js';
import { SentryErrorBoundary } from 'src/components/SentryErrorBoundary.js';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/Messages.tsx` at line 3, The import in Messages.tsx uses a
relative path for SentryErrorBoundary (import { SentryErrorBoundary } from
'./SentryErrorBoundary.js'), which violates the repo rule requiring src/*
aliases; update the import to use the tsconfig alias (e.g., import from
'src/components/SentryErrorBoundary') and remove the explicit .js extension if
not needed so the module resolution and linting conform to the project's
import-path policy.

Comment thread src/context.ts
import { logError } from './utils/log.js'

const MAX_STATUS_CHARS = 2000
const MAX_STATUS_CHARS = 1000
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update truncation notice to match new limit

MAX_STATUS_CHARS is now 1000 at Line 20, but the message at Line 88 still says “2k characters,” which is now inaccurate.

Suggested fix
-          '\n... (truncated because it exceeds 2k characters. If you need more information, run "git status" using BashTool)'
+          '\n... (truncated because it exceeds 1k characters. If you need more information, run "git status" using BashTool)'

Also applies to: 88-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/context.ts` at line 20, The truncation notice string still refers to “2k
characters” even though the constant MAX_STATUS_CHARS was changed to 1000;
update the message (wherever the truncation notice is constructed/returned —
reference the constant MAX_STATUS_CHARS and the function or variable that emits
the notice) to reflect the new 1,000-character limit or, better,
interpolate/format the message using MAX_STATUS_CHARS so it stays correct when
the constant changes (e.g., replace the hardcoded “2k characters” text with a
dynamic reference to MAX_STATUS_CHARS or the value "1000").

Comment thread src/replLauncher.tsx
renderAndRun: (root: Root, element: React.ReactNode) => Promise<void>,
): Promise<void> {
const { App } = await import('./components/App.js');
const { SentryErrorBoundary } = await import('./components/SentryErrorBoundary.js');
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Switch dynamic import to src/* alias

Line 21 uses a relative import for a module under src/. Please align it with the repo’s alias-only import policy.

Suggested fix
-  const { SentryErrorBoundary } = await import('./components/SentryErrorBoundary.js');
+  const { SentryErrorBoundary } = await import('src/components/SentryErrorBoundary.js');

As per coding guidelines: “Import paths must use the src/* alias defined in tsconfig.json; do not use relative paths for imports from src directory”.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { SentryErrorBoundary } = await import('./components/SentryErrorBoundary.js');
const { SentryErrorBoundary } = await import('src/components/SentryErrorBoundary.js');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/replLauncher.tsx` at line 21, Replace the relative dynamic import in
replLauncher.tsx that loads './components/SentryErrorBoundary.js' with the repo
alias path under src (e.g., import from 'src/components/SentryErrorBoundary.js')
so it follows the tsconfig alias-only policy; update the import string inside
the await import(...) call where SentryErrorBoundary is imported.

@claude-code-best claude-code-best merged commit 998890b into main May 10, 2026
9 checks passed
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