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/render_pack.py

View on GitHub
#!/usr/bin/env python3
"""把校验通过的 term_prompt_pack JSON 渲染成单文件离线 HTML。只依赖 Python 标准库。

用法:
    python3 scripts/render_pack.py pack.json output.html
"""

from __future__ import annotations

import argparse
import html
import json
import os
import sys
import tempfile
from pathlib import Path

from validate_pack import DATA_SCRIPT_ID, ROOT_ID, load_json, validate_data, validate_html

STATUS_LABEL = {
    "verified": "已核验",
    "source_defined": "有来源",
    "private": "非行业共识",
    "unverified": "待核验",
}
SOURCE_KIND_LABEL = {
    "paper": "论文/标准",
    "standard": "标准",
    "book": "著作",
    "official": "官方文档",
    "secondary": "二手解释",
    "user_material": "用户材料",
}

CSS = """
:root{color-scheme:light dark;--bg:#f6f4ee;--card:#fffdf8;--ink:#1c1f1d;--muted:#5f6663;--line:#d9d4c7;--accent:#1f6f5c;--accent-soft:#e3efe9;--warn:#8a5a12;--warn-soft:#f6e8cf;--code:#f0ede4;--shadow:0 10px 30px rgba(20,30,25,.08)}
@media (prefers-color-scheme:dark){:root{--bg:#161a18;--card:#1f2523;--ink:#eef1ec;--muted:#a3aca6;--line:#36403b;--accent:#7cc8b0;--accent-soft:#213a32;--warn:#e0a85a;--warn-soft:#3f3118;--code:#252c29;--shadow:0 10px 30px rgba(0,0,0,.35)}}
*{box-sizing:border-box}html{scroll-behavior:smooth}
body{margin:0;background:var(--bg);color:var(--ink);font-family:ui-sans-serif,-apple-system,"PingFang SC","Noto Sans SC","Segoe UI",sans-serif;line-height:1.7;font-size:16px}
main{max-width:860px;margin:0 auto;padding:32px 20px 80px}
h1{font-size:1.75rem;line-height:1.3;margin:0 0 12px}h2{font-size:1.2rem;margin:0 0 14px;padding-top:6px}h3{font-size:1.02rem;margin:0 0 6px}
p{margin:0 0 10px}.muted{color:var(--muted)}
.eyebrow{font-size:.78rem;letter-spacing:.12em;text-transform:uppercase;color:var(--accent);font-weight:700;margin:0 0 6px}
section{margin:0 0 36px}
.badges{display:flex;flex-wrap:wrap;gap:8px;margin:14px 0 0}
.badge{display:inline-block;padding:3px 10px;border-radius:999px;font-size:.8rem;border:1px solid var(--line);background:var(--card)}
.badge.accent{background:var(--accent-soft);border-color:transparent;color:var(--accent);font-weight:600}
.banner{background:var(--warn-soft);color:var(--warn);border:1px solid color-mix(in srgb,var(--warn) 40%,transparent);border-radius:12px;padding:12px 16px;margin:18px 0 0;font-weight:600}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:18px 20px;margin:0 0 14px;box-shadow:var(--shadow);break-inside:avoid}
.card .head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start;flex-wrap:wrap}
.status{font-size:.78rem;padding:2px 9px;border-radius:999px;border:1px solid var(--line);white-space:nowrap}
.status.verified{background:var(--accent-soft);color:var(--accent);border-color:transparent}
.status.private,.status.unverified{background:var(--warn-soft);color:var(--warn);border-color:transparent}
dl{display:grid;grid-template-columns:max-content 1fr;gap:6px 14px;margin:0}dt{color:var(--muted);font-size:.9rem}dd{margin:0}
.sources{margin:10px 0 0;padding:0;list-style:none;font-size:.88rem;color:var(--muted)}.sources li{margin:2px 0}
.compare{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin:10px 0}
@media (max-width:640px){.compare{grid-template-columns:1fr}dl{grid-template-columns:1fr}dt{margin-top:6px}}
.prompt{background:var(--code);border:1px solid var(--line);border-radius:10px;padding:12px 14px;position:relative}
.prompt .label{font-size:.78rem;color:var(--muted);margin:0 0 6px;display:flex;justify-content:space-between;align-items:center}
.prompt pre{margin:0;white-space:pre-wrap;word-break:break-word;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.9rem;line-height:1.6}
.prompt.term{border-color:var(--accent)}
button.copy{font:inherit;font-size:.76rem;padding:2px 9px;border-radius:8px;border:1px solid var(--line);background:var(--card);color:var(--ink);cursor:pointer}
button.copy:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
ul.dims{margin:8px 0 0;padding-left:20px}ul.dims li{margin:3px 0}
ol.path{margin:0;padding-left:22px}ol.path li{margin:0 0 10px}.minutes{color:var(--accent);font-weight:600;margin-right:6px}
.assump{margin:8px 0 0;padding-left:20px;color:var(--muted);font-size:.92rem}
footer{color:var(--muted);font-size:.82rem;border-top:1px solid var(--line);padding-top:14px}
@media print{body{background:#fff;color:#000}main{padding:0;max-width:none}.card{box-shadow:none;border-color:#bbb}button.copy{display:none}section{break-inside:auto}h2{break-after:avoid}.prompt{border-color:#999}}
"""

JS = """
document.addEventListener('click',function(e){var b=e.target.closest('button.copy');if(!b)return;var pre=b.closest('.prompt').querySelector('pre');var text=pre.textContent;var done=function(){b.textContent='已复制';setTimeout(function(){b.textContent='复制';},1500);};
if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(text).then(done,function(){fallback();});}else{fallback();}
function fallback(){var r=document.createRange();r.selectNodeContents(pre);var s=window.getSelection();s.removeAllRanges();s.addRange(r);try{document.execCommand('copy');done();}catch(err){b.textContent='请手动复制';}}});
"""


def esc(value: object) -> str:
    return html.escape(str(value), quote=True)


def safe_json(data: dict) -> str:
    return (
        json.dumps(data, ensure_ascii=False, separators=(",", ":"))
        .replace("&", "\\u0026")
        .replace("<", "\\u003c")
        .replace(">", "\\u003e")
        .replace("
", "\\u2028")
        .replace("
", "\\u2029")
    )


def render_sources(sources: list[dict]) -> str:
    if not sources:
        return ""
    items = []
    for src in sources:
        bits = [esc(src.get("title", ""))]
        meta = [SOURCE_KIND_LABEL.get(src.get("kind", ""), esc(src.get("kind", "")))]
        if src.get("author"):
            meta.append(esc(src["author"]))
        if src.get("year"):
            meta.append(esc(src["year"]))
        bits.append(f"({','.join(meta)})")
        if src.get("url"):
            bits.append(f' <span class="muted">{esc(src["url"])}</span>')
        items.append(f"<li>{''.join(bits)}</li>")
    return f'<ul class="sources">{"".join(items)}</ul>'


def render_terms(terms: list[dict]) -> str:
    cards = []
    for index, term in enumerate(terms, 1):
        status = term["source_status"]
        cards.append(
            f'<article class="card" id="term-{esc(term["id"])}">'
            f'<div class="head"><h3>{index}. {esc(term["term"])} <span class="muted">· {esc(term["chinese_name"])}</span></h3>'
            f'<span class="status {esc(status)}">{STATUS_LABEL.get(status, esc(status))}</span></div>'
            f"<dl><dt>一句话定义</dt><dd>{esc(term['definition'])}</dd>"
            f"<dt>为什么影响这个任务</dt><dd>{esc(term['why_for_this_task'])}</dd></dl>"
            f"{render_sources(term.get('sources', []))}</article>"
        )
    return "".join(cards)


def render_rewrites(rewrites: list[dict], term_map: dict[str, dict]) -> str:
    blocks = []
    for index, rw in enumerate(rewrites, 1):
        names = "、".join(term_map[t]["term"] for t in rw["term_ids"] if t in term_map)
        dims = "".join(f"<li>{esc(d)}</li>" for d in rw["added_dimensions"])
        blocks.append(
            f'<article class="card"><h3>对照 {index}:用上 {esc(names)}</h3>'
            f'<div class="compare">'
            f'<div class="prompt plain"><p class="label"><span>大白话版</span><button class="copy" type="button">复制</button></p><pre>{esc(rw["plain_prompt"])}</pre></div>'
            f'<div class="prompt term"><p class="label"><span>术语版</span><button class="copy" type="button">复制</button></p><pre>{esc(rw["term_prompt"])}</pre></div>'
            f"</div><p><strong>AI 会多补的维度</strong></p><ul class=\"dims\">{dims}</ul></article>"
        )
    return "".join(blocks)


def render_path(steps: list[dict], term_map: dict[str, dict]) -> str:
    items = []
    for step in steps:
        term = term_map.get(step["term_id"], {})
        items.append(
            f'<li><span class="minutes">{esc(step["minutes"])} 分钟</span><strong>{esc(term.get("term", step["term_id"]))}</strong>'
            f'<span class="muted"> · {esc(term.get("chinese_name", ""))}</span><br>{esc(step["why_this_order"])}</li>'
        )
    total = sum(int(s["minutes"]) for s in steps)
    return f'<p class="muted">合计约 {total} 分钟</p><ol class="path">{"".join(items)}</ol>'


def render_unverified(items: list[dict]) -> str:
    if not items:
        return '<p class="muted">没有待核验的术语。</p>'
    lis = "".join(f"<li><strong>{esc(i['term'])}</strong>:{esc(i['reason'])}</li>" for i in items)
    return f'<ul class="dims">{lis}</ul>'


def build_html(data: dict) -> str:
    task = data["task"]
    summary = data["evidence_summary"]
    term_map = {t["id"]: t for t in data["terms"]}
    badges = [
        f'<span class="badge accent">{len(data["terms"])} 个术语</span>',
        f'<span class="badge">已核验 {summary["verified"]}</span>',
        f'<span class="badge">有来源 {summary["source_defined"]}</span>',
        f'<span class="badge">待核验 {summary["unverified"]}</span>',
        f'<span class="badge">{len(data["prompt_rewrites"])} 组 prompt 对照</span>',
    ]
    banner = ""
    if not summary["online_verification"]:
        banner = '<div class="banner">本次未联网核验术语来源。清单里的术语请自行确认定义与出处后再用。</div>'
    assumptions = ""
    if task["assumptions"]:
        assumptions = "<p><strong>我的假设(你没说、我补的)</strong></p><ul class=\"assump\">" + "".join(
            f"<li>{esc(a)}</li>" for a in task["assumptions"]
        ) + "</ul>"
    notes = ""
    if summary["notes"]:
        notes = "<ul class=\"assump\">" + "".join(f"<li>{esc(n)}</li>" for n in summary["notes"]) + "</ul>"
    return f"""<!DOCTYPE html>
<html lang="{esc(data['locale'])}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; connect-src 'none'; form-action 'none'; base-uri 'none'">
<title>{esc(data['title'])}</title>
<style>{CSS}</style>
</head>
<body>
<main id="{ROOT_ID}">
<section>
<p class="eyebrow">术语挖掘 · 30 秒摘要</p>
<h1>{esc(data['title'])}</h1>
<p>{esc(data['summary'])}</p>
<div class="badges">{''.join(badges)}</div>
{banner}
</section>
<section>
<h2>你的任务</h2>
<div class="card"><dl>
<dt>要做什么</dt><dd>{esc(task['goal'])}</dd>
<dt>已经知道什么</dt><dd>{esc(task['known'])}</dd>
<dt>哪个领域</dt><dd>{esc(task['domain'])}</dd>
</dl>{assumptions}</div>
</section>
<section>
<h2>必要术语</h2>
<p class="muted">只列会改变 AI 输出方式的词。定义来自来源,「为什么影响这个任务」是本次判断。</p>
{render_terms(data['terms'])}
</section>
<section>
<h2>prompt 前后对照</h2>
<p class="muted">左边是不懂术语时的写法,右边是加了术语之后的写法。右边可以直接复制去用。</p>
{render_rewrites(data['prompt_rewrites'], term_map)}
</section>
<section>
<h2>30 分钟学习顺序</h2>
{render_path(data['learning_path'], term_map)}
</section>
<section>
<h2>待核验</h2>
{render_unverified(data['unverified'])}
{notes}
</section>
<footer>由 zach-term-miner 生成 · {esc(data['generated_at'])} · {esc(data['artifact_id'])} · 单文件离线页面,不联网</footer>
</main>
<script type="application/json" id="{DATA_SCRIPT_ID}">{safe_json(data)}</script>
<script>{JS}</script>
</body>
</html>
"""


def render(data_path: Path, output_path: Path) -> None:
    data = load_json(data_path)
    errors = validate_data(data)
    if errors:
        raise ValueError("数据校验失败:\n- " + "\n- ".join(errors))
    html_text = build_html(data)
    output_path.parent.mkdir(parents=True, exist_ok=True)
    fd, temp_name = tempfile.mkstemp(prefix=f".{output_path.name}.", dir=output_path.parent)
    try:
        with os.fdopen(fd, "w", encoding="utf-8") as handle:
            handle.write(html_text)
        temp_path = Path(temp_name)
        html_errors = validate_html(temp_path)
        if html_errors:
            raise ValueError("HTML 校验失败:\n- " + "\n- ".join(html_errors))
        os.replace(temp_path, output_path)
        os.chmod(output_path, 0o644)
    except Exception:
        Path(temp_name).unlink(missing_ok=True)
        raise


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("json_file", type=Path)
    parser.add_argument("output_html", type=Path)
    args = parser.parse_args()
    try:
        render(args.json_file, args.output_html)
    except ValueError as exc:
        print(f"ERROR: {exc}", file=sys.stderr)
        return 1
    print(f"RENDERED: {args.output_html}")
    return 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