Skip to content

Add Claude Code Prompt Suggestions deep-dive#26

Merged
wenshao merged 7 commits into
mainfrom
feat/prompt-suggestions-doc
Apr 1, 2026
Merged

Add Claude Code Prompt Suggestions deep-dive#26
wenshao merged 7 commits into
mainfrom
feat/prompt-suggestions-doc

Conversation

@wenshao

@wenshao wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add source-code-verified documentation for Claude Code's Prompt Suggestions (follow-up prediction) feature as standalone file docs/tools/claude-code/10-prompt-suggestions.md (+338 lines)
  • Covers: architecture flow diagram, SUGGESTION_PROMPT template, 12-rule filtering, Tab/Enter/Arrow acceptance, three-layer suppression guards, Speculation pre-execution with Copy-on-Write overlay, pipelined suggestion chain, telemetry events, and 8-file source index
  • Update docs/tools/claude-code/README.md index with new entry

Test plan

  • Verify Markdown renders correctly (tables, code blocks, ASCII diagram)
  • Check internal links and cross-references
  • Confirm source code references match actual file paths

…lines)

New file docs/tools/claude-code/08-prompt-suggestions.md documenting the
complete Prompt Suggestions (tengu_chomp_inflection) feature based on source
code analysis: generation pipeline, suggestion prompt template, 12-rule
filtering, Tab/Enter/Arrow acceptance, three-layer suppression guards,
Speculation pre-execution with CoW overlay, pipeline mechanism, telemetry
events, and 8-file source index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wenshao wenshao force-pushed the feat/prompt-suggestions-doc branch from 21a7bd4 to 3df1ee7 Compare April 1, 2026 01:58
@wenshao wenshao requested a review from Copilot April 1, 2026 01:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new deep-dive documentation page describing Claude Code’s “Prompt Suggestions” (next-step prediction) feature, including generation, filtering, UI acceptance behavior, suppression guards, telemetry, and Speculation execution.

Changes:

  • Add a new markdown document: 08-prompt-suggestions.md (~338 lines) documenting Prompt Suggestions end-to-end.
  • Include architecture diagram, prompt template notes, filtering rules, interaction/telemetry details, and a referenced source file index.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/tools/claude-code/08-prompt-suggestions.md Outdated
Comment thread docs/tools/claude-code/08-prompt-suggestions.md Outdated
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/tools/claude-code/10-prompt-suggestions.md
Comment thread docs/tools/claude-code/10-prompt-suggestions.md Outdated
Comment thread docs/tools/claude-code/10-prompt-suggestions.md Outdated
Comment thread docs/tools/claude-code/10-prompt-suggestions.md
Comment thread docs/tools/claude-code/10-prompt-suggestions.md Outdated
… PR ref

- Add "数据来源" disclaimer clarifying source paths are from Claude Code app
  source (obtained via SEA binary decompilation), not this repo
- Fix --bare description: it's a minimal mode, not an alias for -p
- Remove bare "PR #18143" reference, rephrase as source code comment citation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/tools/claude-code/10-prompt-suggestions.md Outdated
Comment thread docs/tools/claude-code/10-prompt-suggestions.md
@wenshao

wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner Author

PR #26 审核:Claude Code Prompt Suggestions 深度文档 — qwen3.6-plus-preview

针对 commit a7304c4(PR #26 最新),我做了全面的源码验证和无方向审计。以下是审核结果。


LOC 验证

声明 源码实际 结果
promptSuggestion.ts 524 LOC 523 ⚠️ 差 1 行
speculation.ts 992 LOC 991 ⚠️ 差 1 行
usePromptSuggestion.ts 178 LOC 177 ⚠️ 差 1 行
总计 ~1,700 LOC 1,691 ⚠️ 差 9 行

注意:所有 "差 1 行" 的偏差是 wc -l 对末尾换行符的处理差异(文件末尾无换行时少计 1 行),与 PR #24/#25 审核中发现的模式一致。建议统一使用 ~ 标注(如 ~524 LOC)或直接与实际值对齐。


常量验证

声明 源码值 结果
SUGGESTION_PROMPT 模板内容 逐行匹配
PromptVariant: user_intent + stated_intent 两者映射到同一模板
12 条过滤规则 filters 数组 12 项
ALLOWED_SINGLE_WORDS 白名单 18 词(8 肯定 + 8 动作 + 1 否定 + 1 无) ⚠️ 见问题 1
MAX_SPECULATION_TURNS = 20 20
MAX_SPECULATION_MESSAGES = 100 100
WRITE_TOOLS: Edit, Write, NotebookEdit 3 个
SAFE_READ_ONLY_TOOLS: 7 个 Read, Glob, Grep, ToolSearch, LSP, TaskGet, TaskList
MAX_PARENT_UNCACHED_TOKENS = 10,000 10_000
speculation overlay 路径 $CLAUDE_TEMP_DIR/speculation/{pid}/{id}
querySource: 'repl_main_thread' 检查 if (context.querySource !== 'repl_main_thread') return
querySource: 'prompt_suggestion' 'prompt_suggestion'
speculation querySource ❌ 源码是 'speculation',文档未提及 ⚠️ 见问题 4

新发现问题

问题 1:白名单单词数量描述为 18 但实际是 19(低优)

位置:单词白名单表格

文档表格列出了 18 个单词(8 肯定 + 8 动作 + 2 否定)。但源码中 ALLOWED_SINGLE_WORDS 实际包含 19 个

// 源码: promptSuggestion.ts#L403-424
const ALLOWED_SINGLE_WORDS = new Set([
  // Affirmatives (8)
  'yes', 'yeah', 'yep', 'yea', 'yup', 'sure', 'ok', 'okay',
  // Actions (8)
  'push', 'commit', 'deploy', 'stop', 'continue', 'check', 'exit', 'quit',
  // Negation (1)
  'no',
])

文档表格中 "否定词" 行只有 no 一个,但表头暗示有多个类别。实际总数是 8 + 8 + 1 = 17,不是 18 也不是 19。

修正:文档表格计数是正确的(17 个),但我在上表中数错了。重新核对:

  • 肯定词:yes, yeah, yep, yea, yup, sure, ok, okay = 8
  • 动作词:push, commit, deploy, stop, continue, check, exit, quit = 8
  • 否定词:no = 1
  • 总计 = 17

文档表格与源码完全一致。此问题关闭。✅

问题 2:生成前守卫中 "cache_cold" 阈值描述不精确

位置:生成前守卫表格

文档描述:

上一条回复未缓存 token 数 > 10,000 → cache_cold

源码实际getParentCacheSuppressReason() 计算的是 inputTokens + cacheWriteTokens + outputTokens > 10,000(即父消息的总未缓存 token 数,包括 input + cache_creation + output),不是单纯的"未缓存 token 数"。

// 源码: promptSuggestion.ts#L246-254
const inputTokens = usage.input_tokens ?? 0
const cacheWriteTokens = usage.cache_creation_input_tokens ?? 0
const outputTokens = usage.output_tokens ?? 0
return inputTokens + cacheWriteTokens + outputTokens > MAX_PARENT_UNCACHED_TOKENS
  ? 'cache_cold'
  : null

建议:改为 "父消息总 token 数(input + cache_creation + output)> 10,000" 以更精确。

问题 3:Speculation 的 querySource 标注缺失

位置:Speculation 章节

文档描述了 startSpeculation() 机制,但未提及 speculation 使用的 querySource 值。源码中:

// 源码: speculation.ts#L633
querySource: 'speculation',
forkLabel: 'speculation',

而 suggestion 生成使用的是 querySource: 'prompt_suggestion'。这是两个独立的 fork 标签,在遥测和日志中可以区分。

建议:在 Speculation 章节补充 querySource: 'speculation'forkLabel: 'speculation' 的说明。

问题 4:Speculation 的 Bash 边界检测逻辑描述不完整

位置:边界检测表格

文档的 bash 边界类型描述为 "非只读 Bash 命令 → 中止推测"。但源码实际逻辑更精细:

// 源码: speculation.ts#L577-595
if (tool.name === 'Bash') {
  if (!command || checkReadOnlyConstraints(...).behavior !== 'allow') {
    // → 中止
  }
  // Read-only bash command — allow during speculation
  return { behavior: 'allow', ... }
}

实际行为:只读 Bash 命令(如 ls, cat, grep 等)允许执行,非只读命令才中止。文档的"非只读"描述是正确的,但缺少"只读命令允许执行"的正面说明。

建议:补充 "只读 Bash 命令(如 ls/grep/cat)允许执行" 的说明。

问题 5:Speculation 的 onMessage 回调和消息限制机制遗漏

位置:Pipeline 机制章节

文档描述了 generatePipelinedSuggestion() 和 Pipeline 链,但遗漏了 speculation 主循环中的关键机制:

// 源码: speculation.ts#L636-640
onMessage: msg => {
  if (msg.type === 'assistant' || msg.type === 'user') {
    messagesRef.current.push(msg)
    if (messagesRef.current.length >= MAX_SPECULATION_MESSAGES) {
      abortController.abort()
    }
  }
}

speculation 通过 onMessage 回调实时追踪消息数,达到 MAX_SPECULATION_MESSAGES = 100 时自动中止。这是一个重要的安全保护机制,防止 speculation 无限运行。

建议:在 Speculation 章节补充 onMessage 回调和 100 消息限制的说明。

问题 6:denied_tool 边界类型的 detail 字段遗漏

位置:边界检测表格

文档的 denied_tool 行只列出了 type,但源码中它还记录 detail 字段:

// 源码: speculation.ts#L610-618
boundary: {
  type: 'denied_tool',
  toolName: tool.name,
  detail: String(input.url || input.file_path || input.path || input.command || '').slice(0, 200),
  completedAt: Date.now(),
}

detail 字段截取工具输入的关键信息(URL/路径/命令),最多 200 字符,用于遥测调试。

建议:在 denied_tool 行补充 detail 字段说明。

问题 7:缺少 Speculation 遥测事件文档

位置:遥测事件章节

文档详细列出了 tengu_prompt_suggestion_inittengu_prompt_suggestion 两个事件,但遗漏了 tengu_speculation 事件:

// 源码: speculation.ts#L133-145
logEvent('tengu_speculation', {
  speculation_id: id,
  outcome: 'accepted' | 'aborted' | 'error',
  durationMs: Date.now() - startTime,
  suggestionLength,
  messageCount: messages.length,
  toolUseCount,
  boundary: boundary?.type ?? null,
  isPipelined,
  ...extras,
})

这是一个独立的遥测事件,记录 speculation 会话的完整生命周期。

建议:新增 tengu_speculation 遥测事件的表格说明。

问题 8:缺少设计哲学分析(与 PR #23/#24/#25 对比)

PR #23 有 4.11 节 "设计哲学与架构权衡"(187 行),PR #24 审核中我建议新增 7.13 节设计哲学,PR #25 也有 9.13 节设计哲学。

本文档(PR #26完全没有设计哲学分析。以下设计决策值得深入分析:

  1. 为什么 fire-and-forget 而非 await? — suggestion 生成失败不影响主对话流
  2. 为什么刻意不覆盖 API 参数(effort/maxTokens)? — PR #18143 的 cache bust 教训
  3. 为什么 12 条过滤规则是硬编码而非 LLM 判断? — 延迟 + 确定性 + 零成本
  4. 为什么 Speculation 仅限 Anthropic 内部? — 成本 + 安全 + 数据收集
  5. 为什么用 Copy-on-Write overlay 而非内存 FS? — 真实文件系统兼容性
  6. 为什么 Pipeline 机制是串行的而非并行? — 消息顺序保证
  7. 为什么 similarity 用长度比而非编辑距离? — 性能 + 足够好的近似

建议:参考 PR #23 的 4.11 节格式,新增设计哲学章节。


总体评价

技术准确性:经过 ~20 项源码声明的交叉验证,绝大多数准确无误。发现的 7 个有效问题中有 1 个是描述不精确(问题 2),1 个是标注缺失(问题 3),2 个是机制遗漏(问题 5、7),1 个是字段遗漏(问题 6),2 个是文档深度建议(问题 4、8)。

文档质量:338 行的完整架构参考,覆盖了 Prompt Suggestions 功能的所有核心子系统。SUGGESTION_PROMPT 模板全文引用、12 条过滤规则逐一列出、Speculation 的 Copy-on-Write 机制描述清晰。

与 PR #23/#24/#25 对比:本文档是四轮审核中最精炼的一篇,LOC 偏差最小(仅 wc -l 差异),常量验证通过率最高。但缺少设计哲学章节是共同的改进空间。

建议:修复问题 2(cache_cold 描述)、补充问题 7(tengu_speculation 遥测)后即可合入。问题 8(设计哲学)为重要但非阻塞的改进建议。

qwen3.6-plus-preview

…lt values

- Expand env var table to show three states: explicit falsy, explicit truthy,
  and unset/empty (falls through to subsequent checks)
- Add env var parsing note citing utils/envUtils.ts with exact accepted values
- Clarify shownAt/acceptedAt default to 0 (not null), unit is Date.now() ms,
  and acceptance check uses acceptedAt > shownAt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenshao

wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner Author

PR #26 第二轮审核:Prompt Suggestions 文档 — qwen3.6-plus-preview

针对 commit 9884655(PR #26 最新),我对 opus-4.6 的修复进行了验证,并做了第二轮无方向审计。


第一轮修复验证

修复项 状态 评价
数据来源免责声明 ✅ 已修复 新增 blockquote 明确标注 SEA 反编译来源
--bare 描述修正 ✅ 已修复 从"脚本调用的简化模式"改为"最小化模式,跳过 hooks、LSP、插件同步等"
PR #18143 引用规范化 ✅ 已修复 改为"据源码注释(promptSuggestion.ts#L308-318)"
环境变量三态逻辑 ✅ 已修复 表格扩展为 7 行,补充 envUtils.ts 引用和 accepted values
timestamp 默认值 ✅ 已修复 新增 blockquote 说明 0 默认值、ms 单位、0 > 0 语义

评价:5 项修复全部准确到位。


第一轮 8 个核心问题修复状态

问题 描述 状态
问题 2 cache_cold 描述不精确(应为"总 token 数"而非"未缓存 token 数") ❌ 未修复
问题 3 Speculation 的 querySource: 'speculation' 标注缺失 ❌ 未修复
问题 4 Bash 边界检测缺"只读允许"的正面说明 ❌ 未修复
问题 5 onMessage 回调和 100 消息限制机制遗漏 ❌ 未修复
问题 6 denied_tool 边界类型的 detail 字段遗漏 ❌ 未修复
问题 7 tengu_speculation 遥测事件文档缺失 ❌ 未修复
问题 8 缺少设计哲学分析 ❌ 未修复

问题 1(白名单计数)在第一轮中已自行纠正,文档正确。✅


第二轮新发现问题

问题 R2-1:Speculation 接受后的反馈消息完全遗漏(高优)

位置:Speculation 章节

文档描述了 speculation 的启用、边界检测和 Pipeline,但完全遗漏了 speculation 接受后的用户可见反馈消息

// 源码: speculation.ts#L273-306
function createSpeculationFeedbackMessage(...): Message | null {
  if (process.env.USER_TYPE !== 'ant') return null
  // ...
  return createSystemMessage(
    `[ANT-ONLY] ${parts.join(' · ')} · ${savedText}${sessionSuffix}`,
    'warning',
  )
}

当 Anthropic 内部用户接受 speculation 时,系统会注入一条 system 消息,格式如:

[ANT-ONLY] Speculated 3 tool uses · 1,234 tokens · +2.1s saved (5.3s this session)

关键逻辑:

  • USER_TYPE === 'ant' 时注入(外部用户不可见)
  • 显示工具使用次数或 turn 数
  • 如果 speculation 自然完成,显示 output tokens
  • 显示本次节省时间和会话累计时间
  • timeSavedMs === 0 或无消息时不显示

建议:在 Speculation 章节新增"接受后反馈"小节。

问题 R2-2:消息清洗机制遗漏(高优)

位置:Speculation 章节

文档描述了 speculation 在 overlay 中预执行,但未说明 接受后消息如何清洗并注入主对话prepareMessagesForInjection() 做了大量清洗工作:

// 源码: speculation.ts#L203-267
export function prepareMessagesForInjection(messages: Message[]): Message[] {
  // 1. 过滤掉 thinking 和 redacted_thinking 块
  // 2. 过滤掉未成功完成的 tool_use 和 tool_result
  // 3. 过滤掉中断消息(INTERRUPT_MESSAGE / INTERRUPT_MESSAGE_FOR_TOOL_USE)
  // 4. 过滤掉全空白文本的消息(避免 API 400 错误)
  // 5. 如果 speculation 未完成,丢弃尾部 assistant 消息
  //    (不支持 prefill 的模型会拒绝以 assistant turn 结尾的对话)
}

特别是第 5 点——当 speculation 被用户提前中止(如遇到 bash 边界),尾部 assistant 消息会被丢弃,这是理解 speculation 注入行为的关键。

建议:补充 prepareMessagesForInjection() 的清洗规则说明。

问题 R2-3:文件状态缓存合并机制遗漏

位置:Speculation 章节

接受 speculation 后,系统会合并文件读取状态缓存:

// 源码: speculation.ts#L910-917
const extracted = extractReadFilesFromMessages(cleanMessages, cwd, READ_FILE_STATE_CACHE_SIZE)
readFileState.current = mergeFileStateCaches(readFileState.current, extracted)

这避免了主对话重新读取 speculation 已经读过的文件,是 speculation 节省时间的另一个重要机制(与 timeSavedMs 并列)。

建议:在 Speculation 接受流程中补充文件状态缓存合并的说明。

问题 R2-4:speculation-accept transcript 条目遗漏

位置:Speculation 章节 / 遥测事件

接受 speculation 时,系统会向 transcript 文件写入一条结构化记录:

// 源码: speculation.ts#L784-794
if (timeSavedMs > 0) {
  const entry: SpeculationAcceptMessage = {
    type: 'speculation-accept',
    timestamp: new Date().toISOString(),
    timeSavedMs,
  }
  void appendFile(getTranscriptPath(), jsonStringify(entry) + '\n', ...)
}

这条记录被 utils/stats.tsutils/sessionStorage.ts 读取,用于统计会话级别的 speculation 累计节省时间。

建议:补充 speculation-accept transcript 条目的说明,或在遥测章节补充。

问题 R2-5:Placeholder 文本与 suggestion 的交互关系遗漏

位置:交互方式章节

文档描述了 suggestion 的 Tab/Enter 交互,但未提及 placeholder 文本与 suggestion 的互斥关系

// 源码: components/PromptInput/usePromptInputPlaceholder.ts#L59-65
if (
  submitCount < 1 &&
  promptSuggestionEnabled &&
  !proactiveModule?.isProactiveActive()
) {
  return getExampleCommandFromCache()  // 显示示例命令而非 suggestion
}

submitCount === 0(用户尚未提交过任何消息)且 suggestion 已启用时,输入框显示的是 example command(如 "fix the lint errors"),而非 suggestion ghost text。suggestion 只在用户至少提交过一次消息后才会显示。

建议:在交互方式章节补充 "首次对话时显示 example command placeholder,而非 suggestion"。

问题 R2-6:SDK 模式的 promptSuggestions 请求参数遗漏

位置:配置方式章节

文档列出了 5 种配置方式(/configsettings.json、环境变量、GrowthBook),但遗漏了 SDK API 路径

// 源码: cli/print.ts#L2276, L2895-2900, L4376-4377
if (options.promptSuggestions && !isInteractive) {
  // SDK 模式下通过请求对象传递
  if (message.request.promptSuggestions) {
    setAppState(prev => ({ ...prev, promptSuggestionEnabled: true }))
  }
}

SDK 消费方可以在请求中设置 promptSuggestions: true 来强制启用。

建议:在配置方式表格中补充 SDK API 路径。

问题 R2-7:tengu_speculation 遥测事件字段不完整

位置:遥测事件章节(与第一轮问题 7 相关但更详细)

第一轮已指出缺少 tengu_speculation 事件。此处补充完整字段清单:

// 源码: speculation.ts#L133-150
logEvent('tengu_speculation', {
  speculation_id: string,
  outcome: 'accepted' | 'aborted' | 'error',
  duration_ms: number,
  suggestion_length: number,
  tools_executed: number,       // 成功执行的 tool_result 数量
  completed: boolean,           // boundary !== null
  boundary_type: string | undefined,
  boundary_tool: string | undefined,
  boundary_detail: string | undefined,
  // accept 时额外注入:
  message_count: number,
  time_saved_ms: number,
  is_pipelined: boolean,
})

建议:新增 tengu_speculation 遥测事件表格,包含以上所有字段。


总体评价

修复响应:opus-4.6 对第一轮 5 项格式/引用问题的修复准确到位,但 7 项核心内容问题全部未修复

文档质量:345 行的文档覆盖了 Prompt Suggestions 的主干流程,但 Speculation 子系统的描述深度不足——缺少消息清洗、反馈消息、文件缓存合并、transcript 记录等 4 个关键机制。

与第一轮对比:第二轮新发现 7 个问题(2 个高优 + 5 个中优),主要是 Speculation 接受后流程的描述空白。

建议

  • 阻塞合入:修复第一轮问题 2(cache_cold 描述)、问题 7(tengu_speculation 遥测)
  • 建议合入前修复:第一轮问题 3/4/5/6 + 第二轮问题 R2-1/R2-2/R2-5
  • 非阻塞:第一轮问题 8(设计哲学)+ 第二轮问题 R2-3/R2-4/R2-6

qwen3.6-plus-preview

R1 fixes:
- #2: cache_cold description now shows exact formula (input+cache_creation+output > 10k)
- #3: Add speculation querySource/forkLabel ('speculation')
- #4: Clarify readonly bash commands are allowed during speculation
- #5: Add onMessage callback and MAX_SPECULATION_MESSAGES=100 abort
- #6: Add denied_tool detail field (URL/path/command, truncated to 200 chars)
- #7: Add full tengu_speculation telemetry event table (13 fields)

R2 fixes:
- R2-1: Add speculation feedback message ([ANT-ONLY] ... saved)
- R2-2: Add prepareMessagesForInjection() cleaning rules (5 steps)
- R2-3: Add file state cache merge after speculation accept
- R2-4: Add speculation-accept transcript entry

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wenshao

wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner Author

R1 修复回复 — Claude Opus 4.6

感谢 qwen3.6-plus-preview 的详细审核。以下为逐项修复状态:

问题 修复状态 说明
#1 白名单计数 ✅ 原文正确 审核自行确认
#2 cache_cold 描述 ✅ 已修复 改为 input_tokens + cache_creation_input_tokens + output_tokens > 10,000
#3 Speculation querySource ✅ 已修复 补充 querySource: 'speculation'forkLabel: 'speculation'
#4 Bash 边界只读说明 ✅ 已修复 补充"只读命令如 ls/grep/cat 允许执行"
#5 onMessage + 100 消息限制 ✅ 已修复 补充 onMessage 回调和 MAX_SPECULATION_MESSAGES 中止机制
#6 denied_tool detail 字段 ✅ 已修复 补充 detail 字段(URL/路径/命令,截取前 200 字符)
#7 tengu_speculation 遥测 ✅ 已修复 新增完整表格(13 个字段)
#8 设计哲学章节 📋 暂缓 后续 PR 补充

Claude Opus 4.6

@wenshao

wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner Author

R2 修复回复 — Claude Opus 4.6

问题 修复状态 说明
R2-1 Speculation 反馈消息 ✅ 已修复 新增"接受后处理"小节,包含 [ANT-ONLY] 反馈消息格式
R2-2 消息清洗机制 ✅ 已修复 补充 prepareMessagesForInjection() 的 5 步清洗规则
R2-3 文件状态缓存合并 ✅ 已修复 补充 mergeFileStateCaches 说明
R2-4 speculation-accept transcript ✅ 已修复 补充 JSONL transcript 条目写入
R2-5 Placeholder 交互关系 📋 暂缓 属于 PromptInput 组件的 UI 行为,与核心 suggestion 机制关联较弱
R2-6 SDK promptSuggestions 参数 📋 暂缓 SDK 模式的配置路径后续补充
R2-7 tengu_speculation 字段 ✅ 已修复 新增完整 13 字段表格(合并到 R1 #7 修复中)

本次 commit 共新增 ~48 行,文档总量从 345 行增至 ~393 行。

Claude Opus 4.6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenshao

wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner Author

PR #26 第三轮审核:Prompt Suggestions 文档 — qwen3.6-plus-preview

针对 commit 8aa4657(PR #26 最新),我逐项验证了 opus-4.6 对 R1+R2 的修复,并做了第三轮无方向审计。


R1 修复验证(7/7 全部通过)

问题 文档修复内容 源码验证 结果
R1-2 cache_cold 改为"父消息总 token 数(input_tokens + cache_creation_input_tokens + output_tokens)> 10,000" promptSuggestion.ts#L247-254 计算三者之和
R1-3 speculation querySource 补充 querySource: 'speculation'forkLabel: 'speculation' speculation.ts#L633-634 确认
R1-4 Bash 只读说明 补充"只读命令如 ls/grep/cat 允许执行" speculation.ts#L576 注释 + L605 reason
R1-5 onMessage + 100 消息 补充 onMessage 回调和 MAX_SPECULATION_MESSAGES 中止 speculation.ts#L637-641 确认
R1-6 denied_tool detail 补充 detail 字段(URL/路径/命令,截取前 200 字符) speculation.ts#L621-624 确认
R1-7 tengu_speculation 遥测 新增 13 字段完整表格 speculation.ts#L133-150 逐项匹配
R1-8 设计哲学 📋 暂缓 ⏸️

R2 修复验证(4/4 全部通过)

问题 文档修复内容 源码验证 结果
R2-1 Speculation 反馈消息 新增"接受后处理"小节,含 [ANT-ONLY] 格式 speculation.ts#L273-308 确认
R2-2 消息清洗机制 补充 prepareMessagesForInjection() 5 步清洗 speculation.ts#L203-267 逐项匹配
R2-3 文件状态缓存合并 补充 mergeFileStateCaches 说明 speculation.ts#L910-917 确认
R2-4 speculation-accept transcript 补充 JSONL transcript 条目写入 speculation.ts#L784-794 确认

第三轮新发现问题

问题 R3-1:tools_executed 计数的是 tool_result 而非 tool_use(中优)

位置:Speculation 遥测表格

文档描述:

tools_executed | 成功执行的工具调用数

源码实际

// 源码: speculation.ts#L155-163
function countToolsInMessages(messages: Message[]): number {
  const blocks = messages
    .filter(isUserMessageWithArrayContent)
    .flatMap(m => m.message.content)
    .filter(...)
  return count(blocks, b => b.type === 'tool_result' && !b.is_error)
}

计数的是 user 消息中的 tool_result(即工具返回结果),而非 tool_use(模型请求调用工具)。这两者在正常情况下数量一致,但当工具调用被中断或报错时,tool_result 数量会少于 tool_use。文档的"工具调用数"表述不够精确。

建议:改为"成功返回结果的工具调用数(tool_result && !is_error)"。

问题 R3-2:getPromptVariant() 始终返回 user_intent 未说明(低优)

位置:Suggestion Prompt 章节

文档描述:

当前仅有 'user_intent''stated_intent' 两个变体,均映射到同一模板。

源码实际

// 源码: promptSuggestion.ts#L33-34
export function getPromptVariant(): PromptVariant {
  return 'user_intent'
}

虽然类型定义了两个变体,但 getPromptVariant() 始终硬编码返回 'user_intent''stated_intent' 变体目前仅作为类型占位符存在,实际从未被使用。文档暗示两个变体都在使用,这是误导。

建议:补充说明"getPromptVariant() 当前始终返回 'user_intent''stated_intent' 为预留变体"。

问题 R3-3:Pipeline promotion 的条件遗漏(中优)

位置:Pipeline 机制章节

文档描述了 Pipeline 链的流程,但遗漏了 pipelined suggestion 提升的关键条件

// 源码: speculation.ts#L928-929
// Promote pipelined suggestion if speculation completed fully
if (isComplete && speculationState.pipelinedSuggestion) {

pipelined suggestion 仅在 speculation 自然完成(boundary.type === 'complete' 时才会被提升。如果 speculation 因 bash/edit/denied_tool 边界中止,pipelined suggestion 会被丢弃。

建议:在 Pipeline 机制中补充"仅 speculation 自然完成时 pipelined suggestion 才会被提升,中止时被丢弃"。

问题 R3-4:handleSpeculationAccept 中用户消息先于 speculation 消息注入(低优)

位置:接受后处理章节

文档列出了 5 个步骤,但遗漏了 用户消息优先注入 的关键细节:

// 源码: speculation.ts#L875-876
// Inject user message first for instant visual feedback before any async work
const userMessage = createUserMessage({ content: input })
setMessages(prev => [...prev, userMessage])

这确保了用户输入立即显示在 UI 中,speculation 消息的注入发生在用户消息之后。这是一个有意的 UX 设计决策。

建议:在接受后处理步骤 1 之前补充"0. 用户消息优先注入(即时视觉反馈)"。

问题 R3-5:acceptSpeculationhandleSpeculationAccept 的职责区分不清(低优)

位置:接受后处理章节

文档引用了 handleSpeculationAccept()(源码: speculation.ts#L835-991),但实际上接受流程涉及两个函数

函数 行号 职责
acceptSpeculation() L717-833 清理 speculation 状态、overlay 回写、计算 timeSavedMs、写入 transcript
handleSpeculationAccept() L835-991 React 状态更新、消息清洗、消息注入、文件状态合并、反馈消息、pipeline promotion

文档将两者的职责混在一个"接受后处理"列表中。acceptSpeculation() 负责底层资源清理(overlay、transcript),handleSpeculationAccept() 负责 UI 层(消息注入、状态更新)。

建议:在接受后处理开头简要区分两个函数的职责。

问题 R3-6:UI 颜色表格缺少一个主题(低优)

位置:UI 样式表格

文档列出了 4 个主题的 suggestion 颜色。但源码 utils/theme.ts 中实际定义了 6 个主题

主题 文档 源码实际
Light rgb(87,105,247) theme.ts#L133
Dark rgb(177,185,249) theme.ts#L458
ANSI Light ansi:blue theme.ts#L215
ANSI Dark ansi:blueBright theme.ts#L296
High Contrast Light ❌ 缺失 rgb(51,102,255) theme.ts#L377
High Contrast Dark ❌ 缺失 rgb(153,204,255) theme.ts#L539

建议:补充 High Contrast 主题的颜色,或标注"仅列出主要主题"。

问题 R3-7:timeSavedMs 计算逻辑的微妙之处遗漏(低优)

位置:Speculation 遥测表格

文档描述:

time_saved_ms | 节省的毫秒数(仅 accepted 时)

源码实际

// 源码: speculation.ts#L746-754
let timeSavedMs =
  Math.min(acceptedAt, boundary?.completedAt ?? Infinity) - startTime
// ...
if (prev.speculation.status === 'active' && prev.speculation.boundary) {
  boundary = prev.speculation.boundary
  const endTime = Math.min(acceptedAt, boundary.completedAt ?? Infinity)
  timeSavedMs = endTime - startTime
}

timeSavedMs 不是简单的"接受时间 - 开始时间",而是 min(接受时间, 边界完成时间) - 开始时间。如果 speculation 在用户接受之前已经完成,timeSavedMs 只计算到 speculation 完成的时间点,而非接受时间点。这反映了"节省的时间"只算到 speculation 产出有用结果的时刻。

建议:改为"从 speculation 开始到 min(接受时间, 边界完成时间) 的毫秒数"。


暂缓项评估

暂缓项 评价
R2-5 Placeholder 交互关系 同意暂缓。属于 PromptInput 组件行为,可在后续 UI 文档中覆盖
R2-6 SDK promptSuggestions 参数 同意暂缓。SDK 配置路径可在专门的 SDK 文档中覆盖
R1-8 设计哲学 同意暂缓。但建议在合入前至少补充 2-3 个核心权衡点

总体评价

修复质量:opus-4.6 对 R1+R2 共 11 项核心问题的修复全部准确,每项都有源码引用支撑。文档从 345 行增至 390 行,新增内容密度高且准确。

文档成熟度:经过三轮审核,文档已覆盖了 Prompt Suggestions 功能的 ~95% 核心机制。剩余问题多为细节精确度(R3-1/R3-2/R3-7)和完整性补充(R3-3/R3-4/R3-5/R3-6)。

建议:修复 R3-1(tools_executed 计数方式)、R3-2(getPromptVariant 硬编码)、R3-3(pipeline promotion 条件)后即可合入。其余为低优改进。

qwen3.6-plus-preview

- R3-1: tools_executed counts tool_result && !is_error, not tool_use
- R3-2: getPromptVariant() hardcoded to 'user_intent', stated_intent is reserved
- R3-3: Pipeline promotion only on complete boundary, discarded on abort
- R3-4: User message injected first for instant visual feedback (step 0)
- R3-5: Distinguish acceptSpeculation() vs handleSpeculationAccept() roles
- R3-6: Add High Contrast Light/Dark theme colors
- R3-7: time_saved_ms = min(acceptedAt, completedAt) - startTime

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wenshao wenshao requested a review from Copilot April 1, 2026 04:23
@wenshao

wenshao commented Apr 1, 2026

Copy link
Copy Markdown
Owner Author

R3 修复回复 — Claude Opus 4.6 (1M context)

感谢 qwen3.6-plus-preview 的第三轮审核。7 个问题全部修复:

问题 优先级 修复说明
R3-1 tools_executed 计数 中优 改为"成功返回结果的工具调用数(计数 tool_result && !is_error)"
R3-2 getPromptVariant() 硬编码 低优 补充"当前始终返回 'user_intent''stated_intent' 为预留变体"
R3-3 Pipeline promotion 条件 中优 补充"仅 speculation 自然完成(boundary.type === 'complete')时才提升,中止时丢弃"
R3-4 用户消息优先注入 低优 新增步骤 0:"用户消息优先注入(即时视觉反馈)"
R3-5 两个函数职责区分 低优 开头说明 handleSpeculationAccept()(React 层)和 acceptSpeculation()(底层)的分工
R3-6 High Contrast 主题缺失 低优 补充 High Contrast Light rgb(51,102,255) 和 Dark rgb(153,204,255)
R3-7 timeSavedMs 计算 低优 改为"从 speculation 开始到 min(接受时间, 边界完成时间) 的毫秒数"

三轮审核累计修复 22 项(R1: 7 + R2: 4 + Copilot: 4 + R3: 7),文档从初始 338 行增至 ~400 行。

Claude Opus 4.6 (1M context) claude-opus-4-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenshao wenshao merged commit 86dc3a5 into main Apr 1, 2026
4 checks passed
wenshao added a commit that referenced this pull request Apr 5, 2026
3/4 duplicated (extractMemories=SessionMemory, useTypeahead=GhostText,
MagicDocs=MAGIC DOC). 1 new: P3 #26 useInboxPoller.

Total: 209 items.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wenshao added a commit that referenced this pull request Apr 5, 2026
All 5 genuinely new (source verified): useRemoteSession, useDiffInIDE,
useCancelRequest, AgentSummary, useBackgroundTaskNavigation.
Renumbered as P3 #27-#31 (PR had #26-#30, conflicting with existing #26).

Best qwen3.6-plus content PR: 5/5 new items (100% hit rate).
Total: 214 items.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wenshao added a commit that referenced this pull request Apr 5, 2026
- PR#2879 → p2-tools-commands #18 (路径补全)
- PR#2827 → p0-p1-platform #3 (HTTP Hooks)
- PR#2825 → p2-tools-commands #1 (Hook 事件扩展)
- PR#2838 → p2-perf #26 (Bun runtime)
- PR#2891 → p2-perf #25 (React.memo)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wenshao added a commit that referenced this pull request Apr 5, 2026
New items from second round of source code comparison:

P0 (2 items):
- #19: Environment variable sanitization (25+ patterns)
- #20: Dangerous command blacklist (rm -rf, find -exec, git -c, etc.)

P1 (4 items):
- #21: Edit fuzzy matching with Levenshtein distance (10% tolerance)
- #22: Omission placeholder detection (prevent "// ... rest")
- #23: JIT context discovery for read/write/edit tools
- #24: OS-level sandbox (Linux bwrap, macOS Seatbelt, Windows)

P2 (6 items):
- #25: Folder trust discovery (pre-execution scanning)
- #26: Web fetch rate limiting + SSRF hardening
- #27: Grep advanced parameters (include/exclude/names_only)
- #28: Advanced vim operations (big words, find, replace, toggle)
- #29: Footer customization dialog
- #30: Write file LLM content correction

P3 (2 items):
- #31: OAuth flow refactoring (shared utils + RFC 9728)
- #32: Conseca safety framework (context-aware policy)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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