Skip to content

Commit e3b9105

Browse files
author
SqlRush
committed
Skip WebFetch head metadata text
1 parent 96ceec8 commit e3b9105

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
955955

956956
本轮补充:`WebFetch` 文本 body 现在会按 BOM、`Content-Type` charset 或 HTML `<meta charset>`/`http-equiv` charset 解码常见网页编码,包括 UTF-8/UTF-16LE/UTF-16BE、Latin-1 和 Windows-1252,并在 structured content 暴露归一化 `charset`
957957

958+
本轮补充:`WebFetch` HTML-to-text rendering 现在会先解析 `<base href>` 再跳过 `<head>` 子树,`<title>` 等 head-only metadata 不再污染 rendered body 或 prompt-focused excerpt,同时不破坏相对链接解析。
959+
958960
本轮补充:`WebSearch` JSON parser 现在会递归解包 `web``response``search``hits``documents``records``entries` 等常见搜索后端 wrapper,并继续保留 URL 去重和 allowed/blocked domain filter。
959961

960962
本轮补充:`WebSearch` JSON result parser 现在支持 `pageUrl`/`targetUrl`/`source_url`/`canonicalUrl`/`linkUrl`/`resultUrl`/`destinationUrl`/`clickUrl`/`finalUrl`/`formattedUrl` 等 URL aliases、`htmlTitle`/`htmlSnippet` 等 HTML 标记字段清理、嵌套 URL alias object,以及 `deepLinks`/`siteLinks` 子结果递归解析。

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ test/parity/ # golden tests against TS/official behavior
202202
- 本轮补充:WebFetch HTML-to-text rendering 现在会跳过 `hidden``aria-hidden="true"`、CSS `display:none`/`visibility:hidden` 的不可见元素子树,隐藏文本和图片说明不会进入 rendered body 或 prompt-focused excerpt。
203203
- 本轮补充:WebFetch HTML-to-text rendering 现在会为无可见文本但带 `aria-label`/`title` 的链接保留可访问名称和 resolved href,icon-only 链接可进入 rendered body 与 prompt-focused excerpt。
204204
- 本轮补充:WebFetch HTML-to-text rendering 现在按浏览器可见性处理 closed `<details>``<dialog>`:closed details 只渲染第一个 summary 子树,隐藏正文不会进入 excerpt;未带 `open` 的 dialog 会作为不可见子树跳过,open details/dialog 仍正常渲染。
205+
- 本轮补充:WebFetch HTML-to-text rendering 现在会先解析 `<base href>` 再跳过 `<head>` 子树,`<title>` 等 head-only metadata 不再污染 rendered body 或 prompt-focused excerpt,同时不破坏相对链接解析。
205206
- 本轮补充:WebSearch HTML 结果解析现在会按搜索页首个有效 `<base href>` 解析相对结果 anchor,覆盖镜像/自定义搜索页中浏览器可见结果 URL 与请求路径不一致的情况。
206207
- 本轮补充:WebSearch HTML 结果解析现在会读取 `application/ld+json` JSON-LD 结果,递归抽取 `@graph``ItemList.itemListElement.item`,支持 JSON-LD `@id` URL alias,并与后续 anchor 结果按 URL 去重。
207208
- 本轮补充:WebSearch HTML snippet 提取现在识别 Bing 风格 `b_caption`/`b_snippet` 以及常见搜索摘要 class,标题 anchor 后的可见摘要会进入文本输出和 structured result。

internal/tools/web/web_fetch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ func renderWebFetchBody(contentType string, body string, baseURL string) (string
444444
}
445445
stripped := removeHTMLWebFetchBlocks(body, "script", "style", "noscript", "template", "svg", "canvas")
446446
resolvedBaseURL := webFetchHTMLBaseURL(stripped, baseURL)
447+
stripped = removeHTMLWebFetchBlocks(stripped, "head")
447448
rendered := stripHTMLWebFetchTags(stripped, resolvedBaseURL)
448449
rendered = html.UnescapeString(rendered)
449450
return normalizeWebFetchText(rendered), true

internal/tools/web/web_fetch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestWebFetchRendersHTMLAndPromptExcerpt(t *testing.T) {
147147
_, _ = w.Write([]byte(`<!doctype html>
148148
<html>
149149
<head>
150-
<title>Plans</title>
150+
<title>Invisible beta pricing title leak</title>
151151
<script>window.secret = "script noise";</script>
152152
<style>body { color: red; }</style>
153153
</head>
@@ -185,11 +185,11 @@ func TestWebFetchRendersHTMLAndPromptExcerpt(t *testing.T) {
185185
if !ok || !strings.Contains(rendered, "Alpha plan") || !strings.Contains(rendered, "beta pricing plan") {
186186
t.Fatalf("rendered body = %#v", result.StructuredContent["rendered_body"])
187187
}
188-
if strings.Contains(rendered, "script noise") || strings.Contains(rendered, "color: red") {
188+
if strings.Contains(rendered, "script noise") || strings.Contains(rendered, "color: red") || strings.Contains(rendered, "Invisible beta pricing title leak") {
189189
t.Fatalf("rendered body leaked removed blocks: %#v", rendered)
190190
}
191191
excerpt, ok := result.StructuredContent["prompt_excerpt"].(string)
192-
if !ok || !strings.Contains(excerpt, "beta pricing plan") || strings.Contains(excerpt, "Alpha plan") {
192+
if !ok || !strings.Contains(excerpt, "beta pricing plan") || strings.Contains(excerpt, "Alpha plan") || strings.Contains(excerpt, "Invisible beta pricing title leak") {
193193
t.Fatalf("prompt excerpt = %#v", result.StructuredContent["prompt_excerpt"])
194194
}
195195
terms, ok := result.StructuredContent["prompt_terms"].([]string)

0 commit comments

Comments
 (0)