### 1. Overall Summary
本次文档更新主要聚焦于**Hooks 的行为定义**、**子代理工具管理逻辑**以及**网络超时配置**的精确化,同时增强了针对 Windows 环境和沙盒权限错误的故障排除指导。
### 2. Key Themes across pages
* **Hooks 逻辑精细化**:大幅澄清了 `onFailure` 配置与退出码(exit code)的交互逻辑,明确了“非阻塞错误”在特定配置下如何转变为阻塞行为。同时,细化了 `PreToolUse` 钩子在权限审批中的边界(如无法绕过网络路径读取限制)。
* **子代理工具限制顺序**:明确了 `tools`(白名单)与 `disallowedTools`(黑名单)的执行顺序——系统会先应用黑名单,再从剩余池中解析白名单。
* **网络超时配置修正**:更新了流式请求空闲看门狗在 `Claude apps gateway` 会话中的行为描述,澄清了不同超时环境变量(如 `API_TIMEOUT_MS`)的具体作用范围。
* **故障排除增强**:新增了针对 Windows 钩子因缺少 Git Bash 而失败的解释,以及沙盒设置保存时的权限/语法错误指南。
### 3. Impact level
**Medium**
**Reasoning:** 虽然大部分是文档修缮和示例更新,但 Hooks 和子代理的配置逻辑澄清对于构建复杂自动化工作流或严格安全策略的开发者至关重要。这有助于解决边缘情况下的行为困惑,避免因理解偏差导致的配置错误。
### 4. Action items for developers
* **审查 Hooks 配置**:如果您使用了 `onFailure: "block"`,请重新评估钩子在非 0/2 退出码下的行为,确认其阻塞逻辑符合预期。
* **更新子代理定义**:检查子代理的 YAML 配置,确保 `disallowedTools` 和 `tools` 的组合逻辑(先移除再添加)符合您的安全策略。
* **Windows 环境调试**:如果在 Windows 上遇到钩子执行被阻塞的问题,请查阅新增的 "Failed hooks on Windows without Git Bash" 指南。
* **监控日志解析**:注意监控日志中 `PermissionModeChange` 事件,当由 SDK 通过 `setPermissionMode()` 触发时,`trigger` 字段将不再出现。
💭 Model Reasoning
1. **Analyze the Request:**
* **Role:** World-class programmer/developer tools expert.
* **Task:** Analyze documentation changes (8 pages, provided as diffs).
* **Output Format:** Markdown. Concise, insightful.
* **Language:** Chinese (as requested: "请用中文回复").
* **Specific Sections:**
1. Overall Summary.
2. Key Themes.
3. Impact Level.
4. Action Items.
2. **Analyze the Diffs Page by Page:**
* **Page: `cli-reference.md`**
* *Change:* Example for `--debug` filter changed from `--debug='!1p'` to `--debug='!mcp'`.
* *Context:* Debug filtering syntax.
* *Implication:* Minor typo fix or example update to be more relevant/accurate. `!1p` (likely meaning "exclude process 1"?) vs `!mcp` (exclude MCP logs).
* **Page: `costs.md`**
* *Change:* Removed a sentence about "resume from a summary" offer when resuming large sessions.
* *Context:* Cache misses and cost management.
* *Implication:* Documentation now aligns with current behavior (the automatic offer feature might have been removed or changed).
* **Page: `hooks.md`** (Significant changes)
* *Change 1:* Description of `onFailure` clarified: "What happens to the action..." -> "Whether the action that triggered the hook goes ahead...". Clarified that unset field = continue.
* *Change 2:* Logic for "Non-blocking error" updated. It now explicitly mentions hooks with `onFailure: "block"`. Previously, it implied setting it to block was the only way to block on non-0/2 codes. Now it says "except for hooks whose failure blocks the action".
* *Change 3:* Outcome matrix and logic refined. The explanation of how stdout/exit code interacts is more precise regarding blocking vs. non-blocking.
* *Theme:* Tightening up the semantics of Hook failure behavior, specifically around the `onFailure` property and exit codes.
* **Page: `hooks-guide.md`** (Significant changes)
* *Change 1:* Updated exit code behavior logic. Now explicitly references hooks that block the action (`onFailure: "block"`).
* *Change 2:* `PreToolUse` `"allow"` logic clarified. It doesn't bypass network path prompts, `requiresUserInteraction` MCP tools, or connector tools set to `ask`.
* *Change 3:* Added a new troubleshooting tip for Windows users: "blocking because Git Bash wasn't found".
* *Theme:* Clarifying Hook permissions and failure modes on Windows.
* **Page: `monitoring-usage.md`**
* *Change:* Description of `trigger` field for mode change events. Clarified it's absent when SDK sets the mode via `setPermissionMode()`.
* *Theme:* Telemetry/logging precision.
* **Page: `network-config.md`** (Technical details)
* *Change:* Refined description of "Streaming idle watchdogs".
* *Change:* `First-byte deadline` table updated to exclude "Claude apps gateway" session.
* *Change:* `Body idle timeout` updated to count the wait for response headers.
* *Change:* `API_TIMEOUT_MS` description updated regarding limits on header waits.
* *Theme:* Timeout behavior refinement for specific network configurations (gateways, proxies).
* **Page: `sandboxing.md`**
* *Change:* Added a new section explaining the error message "Sandbox settings not changed".
* *Context:* Troubleshooting permissions (EACCES, EPERM, EROFS) and JSON syntax errors when saving settings.
* *Theme:* Error handling and user guidance for Sandbox settings.
* **Page: `sub-agents.md`**
* *Change:* Updated `disallowedTools` anchor link to `#restrict-which-tools-a-subagent-can-use`.
* *Change:* Clarified tool restriction logic (`tools` vs `disallowedTools`). Order of operations clarified: denylist applied first, then allowlist.
* *Change:* Added a table explaining MCP server-level patterns (`mcp__<server>`).
* *Theme:* Better documentation for defining subagent capabilities.
3. **Synthesize and Translate to Chinese:**
* *Summary:* Updates focus on clarifying behaviors (hooks, timeouts, sub-agents) and fixing examples.
* *Themes:*
* **Hooks (钩子):** Precision in failure handling, exit codes, and permission interactions (especially `onFailure` and `PreToolUse`).
* **Sub-agents (子代理):** Clarified tool allowlist/denylist logic.
* **Networking & Timeouts (网络与超时):** Refined watchdog behavior for gateways.
* **Troubleshooting (故障排除):** Better error messages for Sandbox settings and Windows hooks.
* *Impact:* **Medium**. Changes are mostly clarifications and documentation precision, but the Hook and Sub-agent logic details are critical for advanced configuration.
* *Action Items:*
* Review `onFailure` hook settings if relying on specific exit code behaviors.
* Check sub-agent tool restrictions if using complex allow/deny lists.
* Update debugging scripts if using the specific `--debug` filter example (minor).
* Note the new Windows hook troubleshooting guide if deploying on Windows.
4. **Drafting the Response (Internal Monologue/Rough Draft in Chinese):**
* *Summary:* 本次更新主要澄清了 Hooks 的失败处理逻辑、子代理的工具限制顺序以及网络超时在特定环境下的行为,并增加了针对 Windows 和沙盒设置的故障排除指南。
* *Themes:*
* Hooks: `onFailure` 行为更清晰,`PreToolUse` 的权限控制更明确。
* Networking: `Claude apps gateway` 会话中的超时监控行为变更。
* Sub-agents: `tools` 和 `disallowedTools` 的应用顺序明确化(先拒绝后允许)。
* *Impact:* Medium. 主要是文档准确性提升,但对高级用户配置有实际影响。
* *Action Items:*
* 检查 Hooks 配置,特别是 `onFailure` 和退出码的结合使用。
* 确认子代理的工具列表配置逻辑是否符合预期。
* Windows 用户注意 Git Bash 相关的错误提示。
5. **Refining the Markdown:**
* Structure: Use the requested 4 sections.
* Tone: Professional, developer-focused.
*(Self-Correction during drafting)*: Make sure to mention the specific change in `hooks.md` regarding "Exit 2" vs "Other exit codes". The change emphasizes that non-blocking errors can become blocking if `onFailure` is set to "block". This is a nuanced logic correction.
6. **Final Polish (Chinese):**
* **Summary:** 本次文档更新主要聚焦于**Hooks 的行为定义**、**子代理工具管理逻辑**以及**网络超时配置**的精确化,同时增强了针对 Windows 环境和沙盒权限错误的故障排除指导。
* **Themes:**
* **Hooks 逻辑澄清**:细化了 `onFailure` 配置与退出码的交互逻辑,明确了 `PreToolUse` 钩子在权限审批中的限制(如网络路径读取、MCP 工具)。
* **子代理工具限制**:明确了 `tools`(白名单)与 `disallowedTools`(黑名单)的优先级执行顺序(先黑后白)。
* **网络超时细节**:更新了流式空闲看门狗在 `Claude apps gateway` 会话中的行为描述。
* **错误诊断增强**:新增了沙盒设置保存失败和 Windows 钩子找不到 Git Bash 的具体错误信息解释。
* **Impact:** **Medium**。尽管主要是文档修缮,但对 Hooks 和子代理的高级配置逻辑有实质性的澄清,有助于解决边缘情况下的行为困惑。
* **Action Items:**
* **审查 Hooks 配置**:如果您正在使用 `onFailure: "block"`,请重新评估钩子在不同退出码下的行为是否符合预期。
* **更新子代理定义**:检查子代理 YAML 配置,确保 `disallowedTools` 和 `tools` 的组合逻辑(先移除再添加)符合安全策略。
* **Windows 故障排查**:如果在 Windows 上遇到钩子阻塞问题,查阅新增的“Failed hooks on Windows without Git Bash”章节。
* **监控日志**:注意 SDK 触发的权限模式变更现在不会记录 `trigger` 字段。
7. **Final Output Generation.** (Proceed to generate the markdown).