Skip to content

zach22-1999/generic-skills / skills/zach-term-miner

zach-term-miner

Verified

术语挖掘:做一件事之前,先弄清楚这个领域里 AI 听得懂的专业术语,再用这些术语改写你的 prompt。 输入三句话(要做什么 / 已经知道什么 / 哪个领域),产出一个离线 HTML:5 个核验过来源的必要术语、 每个术语对应的「大白话 prompt → 术语版 prompt」前后对照、以及一条 30 分钟学习顺序。 用户说"术语挖掘""我要做 X,需要懂哪些术语才能跟你讲清楚""AI 总是理解偏""这个 prompt 怎么写得更专业" "帮我看看我该学什么术语"时使用。普通词义查询、已有完整 prompt 只想执行、或用户明确要求直接开始做原任务时不要触发。 本 skill 只出术语和 prompt 改写,不执行原任务;不编造术语和来源。

scripts/test_pipeline.py

View on GitHub
#!/usr/bin/env python3
"""回归测试:三个示例 fixture 校验 + 渲染 + HTML 自检,外加几条负向用例。

用法:
    python3 scripts/test_pipeline.py
"""

from __future__ import annotations

import copy
import json
import sys
import tempfile
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
from render_pack import build_html, render  # noqa: E402
from validate_pack import validate_data, validate_html  # noqa: E402

FIXTURES = Path(__file__).resolve().parent / "fixtures"
EXPECTED = {
    "review-mining.json": ["JTBD", "ABSA", "Kano"],
    "listing-bullets.json": ["FABE", "COSMO", "Search Intent"],
    "non-ecommerce.json": ["OKR", "SMART", "North Star"],
}
results: list[tuple[str, bool, str]] = []


def check(name: str, ok: bool, detail: str = "") -> None:
    results.append((name, ok, detail))


def load(name: str) -> dict:
    return json.loads((FIXTURES / name).read_text(encoding="utf-8"))


def test_fixtures(tmp: Path) -> None:
    for name, must_contain in EXPECTED.items():
        data = load(name)
        errors = validate_data(data)
        check(f"{name} 数据校验", not errors, "; ".join(errors))
        out = tmp / name.replace(".json", ".html")
        try:
            render(FIXTURES / name, out)
            html = out.read_text(encoding="utf-8")
            check(f"{name} 渲染 + HTML 自检", True)
            missing = [m for m in must_contain if m not in html]
            check(f"{name} 关键术语出现在 HTML", not missing, f"缺:{missing}")
            check(f"{name} prompt 对照区存在", "AI 会多补的维度" in html and "术语版" in html)
            check(f"{name} 每个术语有对照", all(f'id="term-{t["id"]}"' in html for t in data["terms"]))
        except ValueError as exc:
            check(f"{name} 渲染", False, str(exc))
    non_ecom = load("non-ecommerce.json")
    ecom_words = ["listing", "亚马逊", "电商", "review", "ASIN"]
    leaked = [w for w in ecom_words if any(w in json.dumps(t, ensure_ascii=False) for t in non_ecom["terms"])]
    check("非电商示例的术语不含电商词", not leaked, f"泄漏:{leaked}")


def test_negative() -> None:
    base = load("review-mining.json")

    longer = copy.deepcopy(base)
    longer["prompt_rewrites"][0]["term_prompt"] = longer["prompt_rewrites"][0]["plain_prompt"] + ",再多写一点"
    check("负向:术语版比大白话长应报错", any("应比大白话版短" in e for e in validate_data(longer)))

    dangling = copy.deepcopy(base)
    dangling["prompt_rewrites"][0]["term_ids"] = ["ghost"]
    check("负向:引用不存在的术语应报错", any("不存在的术语" in e for e in validate_data(dangling)))

    uncovered = copy.deepcopy(base)
    uncovered["prompt_rewrites"] = uncovered["prompt_rewrites"][:1]
    check("负向:术语没有对照应报错", any("没有任何 prompt 对照" in e for e in validate_data(uncovered)))

    miscount = copy.deepcopy(base)
    miscount["evidence_summary"]["verified"] = 0
    check("负向:证据计数不一致应报错", any("不一致" in e for e in validate_data(miscount)))

    fake_private = copy.deepcopy(base)
    fake_private["terms"][0]["source_status"] = "private"
    fake_private["evidence_summary"]["verified"] -= 1
    fake_private["evidence_summary"]["private"] += 1
    errs = validate_data(fake_private)
    check("负向:私有术语缺 user_material 与「非行业共识」应报错", any("user_material" in e for e in errs) and any("非行业共识" in e for e in errs))

    too_many = copy.deepcopy(base)
    for i in range(4):
        t = copy.deepcopy(base["terms"][0]); t["id"] = f"extra{i}"; too_many["terms"].append(t)
    check("负向:超过 8 个术语应报错", any("最多 8 个" in e for e in validate_data(too_many)))


def test_offline_mode(tmp: Path) -> None:
    data = copy.deepcopy(load("review-mining.json"))
    for t in data["terms"]:
        t["source_status"] = "unverified"; t["sources"] = []
    data["evidence_summary"].update({"verified": 0, "source_defined": 0, "private": 0,
                                     "unverified": len(data["terms"]) + len(data["unverified"]),
                                     "online_verification": False, "notes": ["本次未联网核验"]})
    errors = validate_data(data)
    check("离线模式:全部 unverified 仍可通过校验", not errors, "; ".join(errors))
    html = build_html(data)
    check("离线模式:HTML 顶部出现未联网提示", "本次未联网核验术语来源" in html)

    mixed = copy.deepcopy(data)
    mixed["terms"][0]["source_status"] = "verified"; mixed["terms"][0]["sources"] = [{"title": "x", "kind": "book"}]
    mixed["evidence_summary"]["verified"] = 1; mixed["evidence_summary"]["unverified"] -= 1
    check("负向:未联网却有 verified 应报错", any("未联网核验" in e for e in validate_data(mixed)))


def test_injection(tmp: Path) -> None:
    data = copy.deepcopy(load("review-mining.json"))
    payload = "</script><script>alert(1)</script><img src=x onerror=alert(2)>"
    data["title"] = payload
    data["terms"][0]["definition"] = payload
    data["prompt_rewrites"][0]["term_prompt"] = "短" + payload
    data["prompt_rewrites"][0]["plain_prompt"] = "长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长" + payload
    html = build_html(data)
    check("注入:HTML 正文里不出现原始 <script>", html.count("<script") == 2)  # 只有数据脚本和复制脚本
    check("注入:数据脚本内 </script> 被转义", "\\u003c/script" in html and payload not in html.split('id="term-pack-data">')[1].split("</script>")[0])
    check("注入:正文标签被转义", "&lt;img src=x onerror" in html)
    out = tmp / "inject.html"; out.write_text(html, encoding="utf-8")
    errs = validate_html(out)
    check("注入:渲染结果仍通过 HTML 自检", not errs, "; ".join(errs))


def main() -> int:
    with tempfile.TemporaryDirectory() as tmpdir:
        tmp = Path(tmpdir)
        test_fixtures(tmp)
        test_negative()
        test_offline_mode(tmp)
        test_injection(tmp)
    failed = [r for r in results if not r[1]]
    for name, ok, detail in results:
        print(f"[{'PASS' if ok else 'FAIL'}] {name}" + (f" — {detail}" if detail and not ok else ""))
    print(f"\n{len(results) - len(failed)}/{len(results)} passed")
    return 1 if failed else 0


if __name__ == "__main__":
    sys.exit(main())
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall