scrape-review-schema

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
You are generating a review page that lets the user verify the proposed schema and extracted values in their browser.
Read
${CLAUDE_SKILL_DIR}/../scrape/references/python-environments.md
.
你需要生成一个审核页面,让用户可以在浏览器中验证提议的Schema和提取的值。
请阅读
${CLAUDE_SKILL_DIR}/../scrape/references/python-environments.md

Input

输入

The raw argument string is
$ARGUMENTS
. Split it into up to 5 positional arguments. The 1st, 2nd and 4th are whitespace-separated tokens; the 3rd and 5th are JSON literals that may contain whitespace — recognize their boundaries by matching brackets (and strip outer single/double quotes if the caller quoted them):
  1. spec_path: path to the spec folder, e.g.
    .scrape/books-toscrape
  2. work_path: path to the working directory, e.g.
    .scrape/.work/books-toscrape
  3. schema: JSON object literal with the proposed schema (starts with
    {
    , ends with the matching
    }
    )
  4. html_variant: which HTML to use —
    raw
    or
    rendered
  5. changes (optional): JSON array literal of change descriptions from the previous round (starts with
    [
    , ends with the matching
    ]
    ), e.g.
    ["Re-analyzed price across all pages","Dropped field isbn"]
The schema JSON uses JSON Schema format (see
${CLAUDE_SKILL_DIR}/../scrape/references/extraction-spec.md
for full details):
json
{
  "type": "object",
  "properties": {
    "price": {
      "type": "string",
      "description": "Product price"
    }
  }
}
Fields may also carry a
source
annotation: "requested" (user asked for it) or "discovered" (AI found it).
原始参数字符串为
$ARGUMENTS
。将其拆分为最多5个位置参数。 第1、2和4个参数是空格分隔的标记;第3和5个是可能包含空格的JSON字面量—— 通过匹配括号来识别它们的边界(如果调用者添加了外层单/双引号,请去除):
  1. spec_path:规范文件夹的路径,例如
    .scrape/books-toscrape
  2. work_path:工作目录的路径,例如
    .scrape/.work/books-toscrape
  3. schema:包含提议Schema的JSON对象字面量(以
    {
    开头,以匹配的
    }
    结尾)
  4. html_variant:使用哪种HTML ——
    raw
    rendered
  5. changes(可选):来自上一轮的变更描述JSON数组字面量(以
    [
    开头,以匹配的
    ]
    结尾),例如
    ["Re-analyzed price across all pages","Dropped field isbn"]
Schema JSON采用JSON Schema格式(详情请参见
${CLAUDE_SKILL_DIR}/../scrape/references/extraction-spec.md
):
json
{
  "type": "object",
  "properties": {
    "price": {
      "type": "string",
      "description": "Product price"
    }
  }
}
字段还可能带有
source
注释:"requested"(用户要求的)或 "discovered"(AI发现的)。

Process

流程

1. Read analysis data

1. 读取分析数据

List page subdirectories in
{spec_path}/pages/
(each subdirectory is a page). For each page, read
{spec_path}/pages/{page_id}/meta.json
for metadata and
{work_path}/analyze-page/{page_id}.{html_variant}.json
for analysis data.
列出
{spec_path}/pages/
中的页面子目录(每个子目录对应一个页面)。对于每个页面,读取
{spec_path}/pages/{page_id}/meta.json
获取元数据,读取
{work_path}/analyze-page/{page_id}.{html_variant}.json
获取分析数据。

2. Create temp directory

2. 创建临时目录

Create a temporary directory named
scrape-review-XXXXXX
(where
XXXXXX
is a random suffix). Keep track of the resulting path as
{review_dir}
and use it in subsequent steps.
创建一个名为
scrape-review-XXXXXX
的临时目录(其中
XXXXXX
是随机后缀)。记录生成的路径为
{review_dir}
,并在后续步骤中使用。

3. Copy static assets

3. 复制静态资源

Copy the bundled assets from this skill's directory to the temp dir:
  • review.html
  • style.css
  • review.js
Use
${CLAUDE_SKILL_DIR}/assets/
as the source path.
将本skill目录中的打包资源复制到临时目录:
  • review.html
  • style.css
  • review.js
使用
${CLAUDE_SKILL_DIR}/assets/
作为源路径。

4. Copy saved HTML pages

4. 复制保存的HTML页面

For each page directory in
{spec_path}/pages/
, copy the chosen variant's HTML to
{review_dir}/pages/{page_id}.html
:
bash
cp {spec_path}/pages/{page_id}/{html_variant}.html {review_dir}/pages/{page_id}.html
This flattens the directory structure for the review page's iframes.
对于
{spec_path}/pages/
中的每个页面目录,将所选变体的HTML复制到
{review_dir}/pages/{page_id}.html
bash
cp {spec_path}/pages/{page_id}/{html_variant}.html {review_dir}/pages/{page_id}.html
这会将目录结构扁平化,以便审核页面的iframe使用。

5. Generate data.js

5. 生成data.js

Build and write
{review_dir}/data.js
with all the data the review page needs. Use the literal placeholder
AGENT_PORT_PLACEHOLDER
for the port — the server replaces it after binding. If
changes
was passed (the optional 5th argument), include
REVIEW_CHANGES
so the page shows what the agent did:
javascript
const AGENT_URL = "http://127.0.0.1:AGENT_PORT_PLACEHOLDER/feedback";
const REVIEW_CHANGES = ["Re-analyzed price across all pages", "Dropped field isbn"];
const REVIEW_DATA = {
  fields: [
    {
      name: "price",
      type: "str",
      description: "Product price",
      source: "requested",
      values: {
        "detail-1": {"value": "$29.99", "url": "https://..."},
        "detail-2": {"value": "$49.99", "url": "https://..."}
      }
    }
  ],
  pages: {
    "detail-1": {
      url: "https://...",
      html_file: "pages/detail-1.html"
    }
  }
};
构建并写入
{review_dir}/data.js
,包含审核页面所需的所有数据。 使用字面占位符
AGENT_PORT_PLACEHOLDER
表示端口——服务器绑定后会替换它。如果传入了
changes
(可选的第5个参数),则包含
REVIEW_CHANGES
,以便页面显示agent执行的操作:
javascript
const AGENT_URL = "http://127.0.0.1:AGENT_PORT_PLACEHOLDER/feedback";
const REVIEW_CHANGES = ["Re-analyzed price across all pages", "Dropped field isbn"];
const REVIEW_DATA = {
  fields: [
    {
      name: "price",
      type: "str",
      description: "Product price",
      source: "requested",
      values: {
        "detail-1": {"value": "$29.99", "url": "https://..."},
        "detail-2": {"value": "$49.99", "url": "https://..."}
      }
    }
  ],
  pages: {
    "detail-1": {
      url: "https://...",
      html_file: "pages/detail-1.html"
    }
  }
};

6. Open in browser and wait for feedback

6. 在浏览器中打开并等待反馈

Run exactly the command below and wait for it to finish before doing anything else:
bash
FEEDBACK_FILE="{review_dir}/feedback.txt"
uv run "${CLAUDE_SKILL_DIR}/scripts/feedback-server.py" "{review_dir}" "${FEEDBACK_FILE}"
cat "${FEEDBACK_FILE}"
Report
{review_dir}
to the user in the message before running this command, in case they need to reopen it.
The script opens the review page in the browser, waits for the user to submit feedback, and exits by itself. Your only job is to wait for the command to finish, then read the feedback from
${FEEDBACK_FILE}
.
Return the feedback text to the caller.
运行以下命令,等待其完成后再执行其他操作:
bash
FEEDBACK_FILE="{review_dir}/feedback.txt"
uv run "${CLAUDE_SKILL_DIR}/scripts/feedback-server.py" "{review_dir}" "${FEEDBACK_FILE}"
cat "${FEEDBACK_FILE}"
在运行此命令前,向用户报告
{review_dir}
,以防他们需要重新打开该页面。
该脚本会在浏览器中打开审核页面,等待用户提交反馈,然后自动退出。你的任务只是等待命令完成,然后从
${FEEDBACK_FILE}
读取反馈。
将反馈文本返回给调用者。