Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b20f916
docs: 修复文档巡检发现的 4 处错误
claude-code-best Apr 18, 2026
20d9c01
docs: 修正 Safety 和 Context 文档中的代码引用和类型错误
claude-code-best Apr 18, 2026
7e1954a
docs: 修复 introduction 文档中的错误路径和行号引用
claude-code-best Apr 18, 2026
d764acc
docs: 修复 conversation/features 文档中的错误
claude-code-best Apr 18, 2026
90825fa
docs: 修复文档巡检中的源码引用错误
claude-code-best Apr 18, 2026
72d5f3f
docs: 修正 tools/agent 文档中的文件路径和行号引用
claude-code-best Apr 18, 2026
a28a452
docs: 修正 feature 文档中的文件路径和行号引用
claude-code-best Apr 18, 2026
4a68966
docs: 修正顶层文档中的路径迁移和行号引用
claude-code-best Apr 18, 2026
7735a70
docs: 修正 task 文档中的文件扩展名和路径引用
claude-code-best Apr 18, 2026
4cc8573
docs: 补充 computer-use-tools-reference 缺失的 Windows 工具
claude-code-best Apr 18, 2026
635ef3d
docs: 修正 audit/bash-classifier/token-budget/tree-sitter 文档
claude-code-best Apr 18, 2026
8a62c03
docs: 修正 langfuse-monitoring AgentTool 路径迁移
claude-code-best Apr 18, 2026
64430e3
docs: 修正 bridgeApi 行号和 Tool.ts 行号引用
claude-code-best Apr 18, 2026
fb0aa4d
docs: 修正 Safety/Extensibility 文档中的工具路径迁移和行号引用
claude-code-best Apr 18, 2026
fccdcd7
docs: 修正 internals 文档引用计数和路径
claude-code-best Apr 18, 2026
f416889
docs: 修正工具文档中的行号引用
claude-code-best Apr 18, 2026
5079a17
docs: 修正 feature 文档中的状态、路径和计数
claude-code-best Apr 18, 2026
b048fdc
docs: 更新 the-loop 查询循环行号引用
claude-code-best Apr 18, 2026
6d36e92
docs: 补充 feature-flags-audit 完整 build 默认 feature 列表
claude-code-best Apr 18, 2026
b12bd29
docs: 修正 feature-flags-audit ConfigTool 路径迁移
claude-code-best Apr 18, 2026
7ed387a
docs: 修正 feature-flags-audit BashTool 路径迁移
claude-code-best Apr 18, 2026
6b44de2
docs: 修正 feature-flags-audit SkillTool 路径迁移
claude-code-best Apr 18, 2026
6fe085d
docs: 更新 feature-flags-audit WorkflowTool 状态为已实现
claude-code-best Apr 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/agent/sub-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ keywords: ["子 Agent", "AgentTool", "任务委派", "forkSubagent", "子进程
```
AI 生成 tool_use: { prompt: "修复 bug", subagent_type: "Explore" }
AgentTool.call() ← 入口(AgentTool.tsx:239
AgentTool.call() ← 入口(AgentTool.tsx:387
├── 解析 effectiveType(fork vs 命名 agent vs GP 回退)
├── filterDeniedAgents() ← 仅命名 Agent 路径执行:权限过滤
├── 检查 requiredMcpServers ← MCP 依赖验证(最长等 30s)
├── assembleToolPool(workerPermissionContext) ← 独立组装工具池
├── createAgentWorktree() ← 可选 worktree 隔离
runAgent() ← 核心执行(runAgent.ts:248
runAgent() ← 核心执行(runAgent.ts)
├── getAgentSystemPrompt() ← 构建 agent 专属 system prompt
├── initializeAgentMcpServers() ← agent 级 MCP 服务器
├── executeSubagentStartHooks() ← Hook 注入
Expand Down Expand Up @@ -54,7 +54,7 @@ Fork 实验的门控函数 `isForkSubagentEnabled()` 需要同时满足三个前
Fork 路径的设计核心是 **Prompt Cache 共享**:所有 fork 子进程共享父 Agent 的完整 `assistant` 消息(所有 `tool_use` 块),用相同的占位符 `tool_result` 填充,只有最后一个 `text` 块包含各自的指令。这使得 API 请求前缀字节完全一致,最大化缓存命中。

```typescript
// forkSubagent.ts:142 — 所有 fork 子进程的占位结果
// forkSubagent.ts:93 — 所有 fork 子进程的占位结果
const FORK_PLACEHOLDER_RESULT = 'Fork started — processing in background'

// buildForkedMessages() 构建:
Expand All @@ -63,7 +63,7 @@ const FORK_PLACEHOLDER_RESULT = 'Fork started — processing in background'

### Fork 递归防护

Fork 子进程保留 Agent 工具(为了 cache-identical tool defs),但通过两道防线防止递归 fork(`AgentTool.tsx:332`)
Fork 子进程保留 Agent 工具(为了 cache-identical tool defs),但通过两道防线防止递归 fork:

1. **`querySource` 检查**(压缩安全):`context.options.querySource === 'agent:builtin:fork'`
2. **消息扫描**(降级兜底):检测 `<fork-boilerplate>` 标签
Expand All @@ -88,7 +88,7 @@ Fork 子进程保留 Agent 工具(为了 cache-identical tool defs),但通

### 内置 Agent

系统预定义了几个内置 Agent(`src/tools/AgentTool/builtinAgents.ts`),各有明确的职责和模型配置:
系统预定义了几个内置 Agent(`packages/builtin-tools/src/tools/AgentTool/builtInAgents.ts`),各有明确的职责和模型配置:

| Agent | 模型 | 权限 | 用途 |
|-------|------|------|------|
Expand Down Expand Up @@ -119,7 +119,7 @@ const workerTools = assembleToolPool(workerPermissionContext, appState.mcp.tools

### 工具过滤的 resolveAgentTools

`runAgent.ts:500-502` 在工具组装后进一步过滤:
`runAgent.ts:508` 在工具组装后进一步过滤:

```typescript
const resolvedTools = useExactTools
Expand All @@ -142,7 +142,7 @@ const resolvedTools = useExactTools

## Worktree 隔离机制

`isolation: "worktree"` 参数让子 Agent 在独立的 git worktree 中工作(`AgentTool.tsx:590-593`):
`isolation: "worktree"` 参数让子 Agent 在独立的 git worktree 中工作(`AgentTool.tsx:863`):

```typescript
const slug = `agent-${earlyAgentId.slice(0, 8)}`
Expand Down Expand Up @@ -183,7 +183,7 @@ runAsyncAgentLifecycle() ← 后台执行(agentToolUtils.ts)

### 同步 Agent(前台运行)

同步 Agent 的关键特性是 **可后台化**(`AgentTool.tsx:818-833`):
同步 Agent 的关键特性是 **可后台化**(`AgentTool.tsx:1107`):

```typescript
const registration = registerAgentForeground({
Expand Down Expand Up @@ -218,7 +218,7 @@ const raceResult = await Promise.race([

## MCP 依赖的等待机制

如果 Agent 声明了 `requiredMcpServers`,`call()` 会等待这些服务器连接完成(`AgentTool.tsx:371-410`):
如果 Agent 声明了 `requiredMcpServers`,`call()` 会等待这些服务器连接完成(`AgentTool.tsx:576`):

```typescript
const MAX_WAIT_MS = 30_000 // 最长等 30 秒
Expand Down
4 changes: 2 additions & 2 deletions docs/agent/worktree-isolation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Worktree 文件统一存放在仓库根目录下的 `.claude/worktrees/`:

## 创建流程:EnterWorktreeTool

`EnterWorktreeTool`(`src/tools/EnterWorktreeTool/EnterWorktreeTool.ts`)的执行链路:
`EnterWorktreeTool`(`packages/builtin-tools/src/tools/EnterWorktreeTool/EnterWorktreeTool.ts`)的执行链路:

```
EnterWorktreeTool.call({ name? })
Expand Down Expand Up @@ -83,7 +83,7 @@ EnterWorktreeTool.call({ name? })

## 退出流程:ExitWorktreeTool

`ExitWorktreeTool`(`src/tools/ExitWorktreeTool/ExitWorktreeTool.ts`)支持两种退出策略:
`ExitWorktreeTool`(`packages/builtin-tools/src/tools/ExitWorktreeTool/ExitWorktreeTool.ts`)支持两种退出策略:

### keep:保留 worktree

Expand Down
8 changes: 4 additions & 4 deletions docs/auto-updater.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ useInterval(checkForUpdates, 30 * 60 * 1000); // 每 30 分钟

任何更新尝试之前,系统会依次检查:

1. **自动更新是否被禁用?** — `getAutoUpdaterDisabledReason()`(`src/utils/config.ts:1735`)
1. **自动更新是否被禁用?** — `getAutoUpdaterDisabledReason()`(`src/utils/config.ts:1737`)
- `NODE_ENV === 'development'`
- 设置了 `DISABLE_AUTOUPDATER` 环境变量
- 仅限必要流量模式
Expand Down Expand Up @@ -81,7 +81,7 @@ useInterval(checkForUpdates, 30 * 60 * 1000); // 每 30 分钟

`src/utils/autoUpdater.ts:70` — `assertMinVersion()`

`src/main.tsx:1775` 在启动时调用
定义于 `src/utils/autoUpdater.ts:70`,设计上在启动时调用(当前未接入启动流程)
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

启动流程描述前后矛盾:请同步更新流程图。

这里明确写了“当前未接入启动流程”,但流程图仍在 Line 283-285 把 assertMinVersion()migrateAutoUpdatesToSettings() 画成启动阶段必经步骤。请二选一统一描述,否则会误导排障与运维判断。

Also applies to: 203-203

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/auto-updater.md` at line 84, The docs state that
src/utils/autoUpdater.ts (defined at the referenced function) is "currently not
wired into startup", but the diagram still shows assertMinVersion() and
migrateAutoUpdatesToSettings() as mandatory startup steps; reconcile this by
updating the flowchart and accompanying text to match: either remove/assert
those functions from the startup path and mark them as "not called on startup"
or explicitly state they are invoked at startup and update the prose
accordingly; ensure references to assertMinVersion() and
migrateAutoUpdatesToSettings() in the diagram and text are consistent across the
document (also apply the same change where these functions are mentioned around
the other noted location).


```typescript
void assertMinVersion();
Expand Down Expand Up @@ -200,7 +200,7 @@ Windows 系统使用文件复制而非符号链接。

**文件**: `src/migrations/migrateAutoUpdatesToSettings.ts`

一次性将旧版 `globalConfig.autoUpdates = false` 迁移为 settings 中的 `DISABLE_AUTOUPDATER=1` 环境变量。 `src/main.tsx:325` 在启动时调用
一次性将旧版 `globalConfig.autoUpdates = false` 迁移为 settings 中的 `DISABLE_AUTOUPDATER=1` 环境变量。定义于 `src/migrations/migrateAutoUpdatesToSettings.ts`(当前未接入启动流程)

---

Expand Down Expand Up @@ -270,7 +270,7 @@ React hook `useUpdateNotification(updatedVersion)` — 确保每次 semver 变
| `src/utils/releaseNotes.ts` | Changelog 获取、缓存与展示 |
| `src/utils/semver.ts` | Semver 版本比较(Bun 原生 + npm 回退) |
| `src/utils/doctorDiagnostic.ts` | 安装类型检测与健康诊断 |
| `src/utils/config.ts:1735` | `getAutoUpdaterDisabledReason()` — 禁用检查逻辑 |
| `src/utils/config.ts:1737` | `getAutoUpdaterDisabledReason()` — 禁用检查逻辑 |
| `src/migrations/migrateAutoUpdatesToSettings.ts` | 旧版配置迁移 |
| `src/screens/Doctor.tsx` | Doctor 命令 UI,展示自动更新状态 |

Expand Down
4 changes: 2 additions & 2 deletions docs/context/compaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const messagesForCompact = microcompactResult.messages
MicroCompact 不压缩整个对话,而是**清除旧工具输出的内容**。它维护一个白名单:

```typescript
// src/services/compact/microCompact.ts:41-48
// src/services/compact/microCompact.ts:41-50
const COMPACTABLE_TOOLS = new Set([
FILE_READ_TOOL_NAME, // 'Read' - 文件读取
...SHELL_TOOL_NAMES, // 'Bash' - 命令输出
Expand Down Expand Up @@ -143,7 +143,7 @@ const stripped2 = stripReinjectedAttachments(stripped) // 移除会被重新注
压缩后,系统会从摘要中**重新注入关键上下文**:

```typescript
// compact.ts:124-132
// compact.ts:126-134
export const POST_COMPACT_TOKEN_BUDGET = 50_000 // 总预算
export const POST_COMPACT_MAX_FILES_TO_RESTORE = 5 // 最多恢复 5 个文件
export const POST_COMPACT_MAX_TOKENS_PER_FILE = 5_000 // 每文件 5K token
Expand Down
2 changes: 1 addition & 1 deletion docs/context/project-memory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Claude Code 的记忆系统是**纯文件**的——没有数据库、没有向
`MEMORY.md` 是记忆的入口索引,每次对话都完整加载到上下文中:

```typescript
// memdir.ts:35-38
// memdir.ts:34-38
export const ENTRYPOINT_NAME = 'MEMORY.md'
export const MAX_ENTRYPOINT_LINES = 200
export const MAX_ENTRYPOINT_BYTES = 25_000
Expand Down
10 changes: 5 additions & 5 deletions docs/context/system-prompt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ buildSystemPromptBlocks() → TextBlockParam[] (分块 + cache_control 标

1. **`getSystemPrompt()`**(`src/constants/prompts.ts:444`)—— 收集静态段 + 动态段,插入 `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` 分界标记
2. **`buildEffectiveSystemPrompt()`**(`src/utils/systemPrompt.ts:41`)—— 按 Override > Coordinator > Agent > Custom > Default 优先级选择
3. **`buildSystemPromptBlocks()`**(`src/services/api/claude.ts:3214`)—— 调用 `splitSysPromptPrefix()` 分块,为每个块附加 `cache_control`
3. **`buildSystemPromptBlocks()`**(`src/services/api/claude.ts:3279`)—— 调用 `splitSysPromptPrefix()` 分块,为每个块附加 `cache_control`

## SystemPrompt 品牌类型

```typescript
// src/utils/systemPromptType.ts:8
// packages/@ant/model-provider/src/types/systemPrompt.ts:4
export type SystemPrompt = readonly string[] & {
readonly __brand: 'SystemPrompt'
}
Expand Down Expand Up @@ -185,7 +185,7 @@ export function shouldUseGlobalCacheScope(): boolean {

### `getCacheControl()`:TTL 决策

`src/services/api/claude.ts:359` 生成的 `cache_control` 对象:
`src/services/api/claude.ts:348` 生成的 `cache_control` 对象:

```typescript
{
Expand All @@ -195,14 +195,14 @@ export function shouldUseGlobalCacheScope(): boolean {
}
```

1 小时 TTL 的判定逻辑(`should1hCacheTTL()`,第 394 行):
1 小时 TTL 的判定逻辑(`should1hCacheTTL()`,第 383 行):
- **Bedrock 用户**:通过环境变量 `ENABLE_PROMPT_CACHING_1H_BEDROCK` 启用
- **1P 用户**:通过 GrowthBook 配置的 `allowlist` 数组匹配 `querySource`,支持前缀通配符(如 `"repl_main_thread*"`)
- **会话级锁定**:资格判定结果在 bootstrap state 中缓存,防止 GrowthBook 配置中途变化导致同一会话内 TTL 不一致

### 缓存破坏:Session-Specific Guidance 的放置

`getSessionSpecificGuidanceSection()`(`src/constants/prompts.ts:352`)的内容必须放在 `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` **之后**。因为它包含:
`getSessionSpecificGuidanceSection()`(`src/constants/prompts.ts:354`)的内容必须放在 `SYSTEM_PROMPT_DYNAMIC_BOUNDARY` **之后**。因为它包含:
- 当前会话的 enabledTools 集合
- `isForkSubagentEnabled()` 的运行时判定
- `getIsNonInteractiveSession()` 的结果
Expand Down
9 changes: 6 additions & 3 deletions docs/conversation/streaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ message_stop ← 消息结束

### 事件处理状态机

`src/services/api/claude.ts` 中 `queryStreamRaw()` 函数的事件处理循环实现了一个基于 `switch(part.type)` 的状态机:
`src/services/api/claude.ts` 中 `queryModelWithStreaming()` 函数的事件处理循环实现了一个基于 `switch(part.type)` 的状态机:

| 事件类型 | 处理逻辑 | 状态变更 |
|----------|----------|----------|
Expand Down Expand Up @@ -167,10 +167,13 @@ UI 层通过 `useToolCallProgress` hook 实时展示命令输出,而不是等

| Provider | 流式协议 | 特殊处理 |
|----------|----------|----------|
| **Anthropic Direct** | 原生 SSE | 延迟最低,TTFT 最快 |
| **firstParty** (Anthropic Direct) | 原生 SSE | 延迟最低,TTFT 最快 |
| **AWS Bedrock** | AWS SDK 流式接口 | 需要额外的 beta header 和认证 |
| **Google Vertex** | gRPC → 事件流 | 通过 `getMergedBetas()` 适配 |
| **Azure** | Anthropic 兼容 API | 自定义 base URL |
| **foundry** | Anthropic 兼容 API | 内部部署 |
| **openai** | OpenAI 流式适配器 | 转换为 Anthropic 内部格式 |
| **gemini** | Gemini 流式适配器 | 转换为 Anthropic 内部格式 |
| **grok** (xAI) | Grok 流式适配器 | 转换为 Anthropic 内部格式 |
Comment on lines +170 to +176
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

Mirror the newly documented providers in the selection snippet.

Lines 170-176 now document foundry, openai, gemini, and grok, but the getAPIProvider() example below still only lists Anthropic/Bedrock/Vertex plus a generic third-party fallback. Add the new provider keys or clarify that they are auto-detected via base URL.

📝 Proposed docs fix
 // 根据 api_provider 配置选择:
-// "anthropic" → 直连
-// "bedrock"   → AWS SDK
-// "vertex"    → Google SDK
-// 第三方 base URL → 自动检测
+// "anthropic" / "firstParty" → Anthropic Direct
+// "bedrock"                  → AWS SDK
+// "vertex"                   → Google SDK
+// "foundry"                  → 内部 Anthropic-compatible endpoint
+// "openai"                   → OpenAI adapter
+// "gemini"                   → Gemini adapter
+// "grok"                     → xAI adapter
+// 第三方 base URL             → 自动检测

Also applies to: 184-190

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/conversation/streaming.mdx` around lines 170 - 176, Update the provider
selection example used by getAPIProvider() to match the table: include the keys
"foundry", "openai", "gemini", and "grok" alongside the existing
"firstParty"/"Anthropic", "awsBedrock"/"Bedrock" and "vertex"/"Vertex", or
alternatively add a short note in the example that these providers are
auto-detected via base URL detection; specifically modify the selection snippet
and the duplicate snippet at the later block (the example that calls
getAPIProvider()) so it either lists the new provider keys or documents the
base-URL auto-detection behavior to keep the example consistent with the table.


所有 Provider 通过统一的 `Stream<BetaRawMessageStreamEvent>` 抽象层屏蔽差异。上层代码(QueryEngine、REPL)不需要关心底层用的是哪个 Provider。

Expand Down
24 changes: 12 additions & 12 deletions docs/conversation/the-loop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ const toolUpdates = streamingToolExecutor

| 终止原因 | 触发位置 | 机制 |
|----------|---------|------|
| **blocking_limit** | 第 646 行 | Token 计数超过硬限制(非 autocompact 模式)→ 生成 PTL 错误消息 → 返回 |
| **image_error** | 第 980 行 | `ImageSizeError` / `ImageResizeError` 异常 → 直接返回 |
| **model_error** | 第 999 行 | `callModel()` 抛出不可恢复异常 → 生成错误消息 → 返回 |
| **aborted_streaming** | 第 1054 行 | `abortController.signal.aborted`(流式阶段)→ 为未完成的 tool_use 生成合成 tool_result → 返回 |
| **prompt_too_long** | 第 1178/1185 行 | 413 错误且 reactive compact 无法恢复 → 暂扣的错误消息被释放 → 返回 |
| **completed** | 第 1267 行 | API 错误(限流、认证失败等)导致无法继续 → 返回 |
| **stop_hook_prevented** | 第 1282 行 | Stop hook 返回 `preventContinuation: true` → 返回 |
| **completed** | 第 1360 行 | 正常完成:AI 未发出 tool_use → `needsFollowUp = false` → 经过 stop hooks → 返回 |
| **aborted_tools** | 第 1518 行 | `abortController.signal.aborted`(工具执行阶段)→ 返回 |
| **hook_stopped** | 第 1523 行 | 工具执行期间 hook 返回 `shouldPreventContinuation` → 返回 |
| **max_turns** | 第 1714 行 | 轮次计数超过 `maxTurns` 限制 → 返回 |
| **blocking_limit** | 第 686 行 | Token 计数超过硬限制(非 autocompact 模式)→ 生成 PTL 错误消息 → 返回 |
| **image_error** | 第 1021 行 | `ImageSizeError` / `ImageResizeError` 异常 → 直接返回 |
| **model_error** | 第 1040 行 | `callModel()` 抛出不可恢复异常 → 生成错误消息 → 返回 |
| **aborted_streaming** | 第 1095 行 | `abortController.signal.aborted`(流式阶段)→ 为未完成的 tool_use 生成合成 tool_result → 返回 |
| **prompt_too_long** | 第 1219/1226 行 | 413 错误且 reactive compact 无法恢复 → 暂扣的错误消息被释放 → 返回 |
| **completed** | 第 1308 行 | API 错误(限流、认证失败等)导致无法继续 → 返回 |
| **stop_hook_prevented** | 第 1323 行 | Stop hook 返回 `preventContinuation: true` → 返回 |
| **completed** | 第 1401 行 | 正常完成:AI 未发出 tool_use → `needsFollowUp = false` → 经过 stop hooks → 返回 |
| **aborted_tools** | 第 1559 行 | `abortController.signal.aborted`(工具执行阶段)→ 返回 |
| **hook_stopped** | 第 1564 行 | 工具执行期间 hook 返回 `shouldPreventContinuation` → 返回 |
| **max_turns** | 第 1755 行 | 轮次计数超过 `maxTurns` 限制 → 返回 |

## 继续条件(恢复路径)

Expand Down Expand Up @@ -158,7 +158,7 @@ type State = {
- **每一步都产生真实信息**:`runTools()` 返回的 `toolResults` 是 API 不可能预知的——命令输出、文件内容、错误信息
- **动态上下文管理**:每轮迭代前都重新评估压缩需求(autocompact → microcompact → snip),基于最新的 token 计数
- **错误即时恢复**:工具失败不需要推倒重来——stop hook 可以注入阻塞错误让 AI 修正策略
- **用户可控**:`abortController.signal` 在循环的多个检查点被检测(第 1018、1048、1488 行),用户按 ESC 可以优雅中断
- **用户可控**:`abortController.signal` 在循环的多个检查点被检测(第 1059、1095、1529 行),用户按 ESC 可以优雅中断
- **成本控制**:Token Budget 在每轮终止前检查,防止 AI 无效循环

## 一个完整的迭代示例
Expand Down
4 changes: 2 additions & 2 deletions docs/extensibility/custom-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Claude Code 的 Agent 不仅仅来自用户自定义——系统有三类来源

| 来源 | 位置 | 优先级 |
|------|------|--------|
| **Built-in** | `src/tools/AgentTool/built-in/` 硬编码 | 最低(可被覆盖) |
| **Built-in** | `packages/builtin-tools/src/tools/AgentTool/built-in/` 硬编码 | 最低(可被覆盖) |
| **Plugin** | 通过插件系统注册 | 中 |
| **User/Project/Policy** | `.claude/agents/*.md` 或 settings.json | 最高 |

Expand Down Expand Up @@ -127,7 +127,7 @@ color: "blue" # 终端中的 Agent 颜色标识
以内置 Explore Agent 为例:

```typescript
// src/tools/AgentTool/built-in/exploreAgent.ts
// packages/builtin-tools/src/tools/AgentTool/built-in/exploreAgent.ts
disallowedTools: [
'Agent', // 不能嵌套调用 Agent
'ExitPlanMode', // 不需要 plan mode
Expand Down
2 changes: 1 addition & 1 deletion docs/extensibility/hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ SDK 非交互模式下信任是隐式的(`getIsNonInteractiveSession()` 为 tr

## Session Hook 的生命周期

Agent 和 Skill 的前置 Hook 通过 `registerFrontmatterHooks()` 注册(调用位置:`src/tools/AgentTool/runAgent.ts`;定义位置:`src/utils/hooks/registerFrontmatterHooks.ts`),绑定到 agent 的 session ID。Agent 结束时通过 `clearSessionHooks()`(定义位置:`src/utils/hooks/sessionHooks.ts`)清理。
Agent 和 Skill 的前置 Hook 通过 `registerFrontmatterHooks()` 注册(调用位置:`packages/builtin-tools/src/tools/AgentTool/runAgent.ts`;定义位置:`src/utils/hooks/registerFrontmatterHooks.ts`),绑定到 agent 的 session ID。Agent 结束时通过 `clearSessionHooks()`(定义位置:`src/utils/hooks/sessionHooks.ts`)清理。

```typescript
// runAgent.ts — 注册 agent 的前置 Hook
Expand Down
2 changes: 1 addition & 1 deletion docs/extensibility/mcp-protocol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ timer.unref?.() // 不阻止进程退出

## 工具发现:从 MCP 到 Tool 接口

`fetchToolsForClient()`(`client.ts:1745-2000`)使用 `memoizeWithLRU` 缓存(上限 20),将 MCP 工具转换为 Claude Code 的统一 Tool 接口:
`fetchToolsForClient()`(`client.ts:1744-2000`)使用 `memoizeWithLRU` 缓存(上限 100),将 MCP 工具转换为 Claude Code 的统一 Tool 接口:

```typescript
const fullyQualifiedName = buildMcpToolName(client.name, tool.name)
Expand Down
4 changes: 2 additions & 2 deletions docs/extensibility/skills.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Skill 的核心洞见:**复杂任务的关键不在代码逻辑,而在 Promp

### 1. 内置命令(Built-in Commands)

硬编码在 `src/commands.ts:258` 的 `COMMANDS` memoize 数组中,包含 70+ 条命令(`/commit`、`/review`、`/compact` 等)。这些是 TypeScript 模块而非 Markdown,但实现了相同的 `Command` 接口(`src/types/command.ts`)。
硬编码在 `src/commands.ts:299` 的 `COMMANDS` memoize 数组中,包含 70+ 条命令(`/commit`、`/review`、`/compact` 等)。这些是 TypeScript 模块而非 Markdown,但实现了相同的 `Command` 接口(`src/types/command.ts`)。

### 2. Bundled Skills(编译时打包)

Expand Down Expand Up @@ -98,7 +98,7 @@ shell: ["bash"] # Shell 执行环境

## 两条执行路径:Inline vs Fork

SkillTool(`src/tools/SkillTool/SkillTool.ts:332`)在 `call()` 中根据 `command.context` 分流:
SkillTool(`packages/builtin-tools/src/tools/SkillTool/SkillTool.ts:332`)在 `call()` 中根据 `command.context` 分流:

### Inline 模式(默认)

Expand Down
8 changes: 4 additions & 4 deletions docs/external-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

- **端点**: `{region}-aiplatform.googleapis.com`
- **认证**: `GoogleAuth` + `cloud-platform` scope
- **文件**: `src/services/api/client.ts:228-298`
- **文件**: `src/services/api/client.ts:221-298`

### 4. Azure Foundry

Expand Down Expand Up @@ -129,12 +129,12 @@ WebSearch 工具支持直接抓取 Bing 搜索结果页面,也支持通过 Bra
- **Bing 端点**: `https://www.bing.com/search?q={query}&setmkt=en-US`
- **Brave 端点**: `https://api.search.brave.com/res/v1/llm/context?q={query}`
- **文件**:
- `src/tools/WebSearchTool/adapters/bingAdapter.ts`
- `src/tools/WebSearchTool/adapters/braveAdapter.ts`
- `packages/builtin-tools/src/tools/WebSearchTool/adapters/bingAdapter.ts`
- `packages/builtin-tools/src/tools/WebSearchTool/adapters/braveAdapter.ts`

另外还有 Domain Blocklist 查询:
- **端点**: `https://api.anthropic.com/api/web/domain_info?domain={domain}`
- **文件**: `src/tools/WebFetchTool/utils.ts`
- **文件**: `packages/builtin-tools/src/tools/WebFetchTool/utils.ts`
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

WebFetchTool 路径迁移在本文档内未完全同步。
这里已改为 packages/builtin-tools/...,但同文件的 Anthropic API 汇总表(Line 188)仍是 src/tools/WebFetchTool/utils.ts,会导致读者跳转混淆。

🛠️ Suggested doc fix
-| `/api/web/domain_info?domain={}` | 域名安全检查 | `src/tools/WebFetchTool/utils.ts` |
+| `/api/web/domain_info?domain={}` | 域名安全检查 | `packages/builtin-tools/src/tools/WebFetchTool/utils.ts` |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/external-dependencies.md` at line 137, The docs mention two different
locations for WebFetchTool which causes broken navigation: update the Anthropic
API summary entry in external-dependencies.md so its referenced path for
WebFetchTool matches the current path referenced elsewhere in the doc; ensure
every occurrence of "WebFetchTool" and the "Anthropic API" summary entry use the
same, up-to-date source location (so readers are directed to the correct utils
file) and verify links/anchors resolve after the change.


### 15. Google Cloud Storage (自动更新)

Expand Down
Loading
Loading