Skip to content

Dianel555/DSkills / skills/agent-wiki

agent-wiki

Unverified

Incremental LLM-friendly wiki generator for Obsidian note vaults. Use when: (1) Building wiki from notes, (2) Ingesting notes to wiki, (3) Obsidian LLM wiki, (4) Incremental knowledge base management. Triggers: 'build wiki from notes', 'ingest notes to wiki', 'Obsidian LLM wiki', 'incremental knowledge base'.

FileKindSize
.env.exampleother408 B
README.mdmarkdown15.3 KB
SKILL.mdskill md23.3 KB
pyproject.tomlmanifest2.1 KB
references/cli-matrix.mdmarkdown5.9 KB
references/homepage.mdmarkdown6.1 KB
references/index-schema.mdmarkdown6.9 KB
references/site-export.mdmarkdown3.1 KB
references/topic-authoring.mdmarkdown5.1 KB
scripts/agent_wiki/__init__.pyscript103 B
scripts/agent_wiki/authors.pyscript3.9 KB
scripts/agent_wiki/bases.pyscript4.0 KB
scripts/agent_wiki/batch.pyscript3.7 KB
scripts/agent_wiki/boundary.pyscript55.8 KB
scripts/agent_wiki/cache.pyscript5.5 KB
scripts/agent_wiki/canvas.pyscript8.0 KB
scripts/agent_wiki/cleanup.pyscript2.4 KB
scripts/agent_wiki/cli.pyscript97 B
scripts/agent_wiki/commands.pyscript28.3 KB
scripts/agent_wiki/config.pyscript4.2 KB
scripts/agent_wiki/coverage.pyscript2.1 KB
scripts/agent_wiki/frontmatter.pyscript1.6 KB
scripts/agent_wiki/home.pyscript7.9 KB
scripts/agent_wiki/keywords.pyscript2.0 KB
scripts/agent_wiki/links.pyscript14.7 KB
scripts/agent_wiki/plugins.pyscript2.1 KB
scripts/agent_wiki/quality.pyscript7.6 KB
scripts/agent_wiki/scanner.pyscript6.7 KB
scripts/agent_wiki/site.pyscript39.2 KB
scripts/agent_wiki/source_type.pyscript3.2 KB
scripts/agent_wiki/wiki_index.pyscript17.4 KB
scripts/agent_wiki/worklist.pyscript5.7 KB
scripts/agent_wiki_cli.pyscript5.5 KB
templates/home/academic.mdmarkdown2.9 KB
templates/home/dashboard.mdmarkdown2.7 KB
templates/home/magazine.mdmarkdown2.5 KB
templates/query/research.mdmarkdown787 B
tests/conftest.pyscript177 B
tests/fixtures/sample_vault/attachments/image.pngbinary26 B
tests/fixtures/sample_vault/课程/双缝实验.mdmarkdown47 B
tests/fixtures/sample_vault/课程/量子力学.mdmarkdown75 B
tests/test_alias_resolution.pyscript7.5 KB
tests/test_authors.pyscript2.2 KB
tests/test_backlinks.pyscript7.0 KB
tests/test_bases.pyscript4.7 KB
tests/test_batch.pyscript3.0 KB
tests/test_benchmark_index.pyscript2.1 KB
tests/test_boundary_platform.pyscript695 B
tests/test_cache.pyscript2.1 KB
tests/test_cache_strict.pyscript2.1 KB
tests/test_canvas.pyscript8.3 KB
tests/test_capture.pyscript5.5 KB
tests/test_cleanup.pyscript1.2 KB
tests/test_cleanup_init_strict.pyscript2.1 KB
tests/test_cli.pyscript6.2 KB
tests/test_config.pyscript2.0 KB
tests/test_coverage.pyscript7.2 KB
tests/test_e2e.pyscript2.5 KB
tests/test_evaluate_enhancements.pyscript14.7 KB
tests/test_featured_base.pyscript4.3 KB
tests/test_final_security_review.pyscript6.6 KB
tests/test_frontmatter.pyscript1.1 KB
tests/test_gen_home.pyscript4.9 KB
tests/test_gen_site_cli.pyscript3.9 KB
tests/test_home.pyscript7.7 KB
tests/test_immutability.pyscript1.4 KB
tests/test_immutability_capture.pyscript2.4 KB
tests/test_index_capture.pyscript4.5 KB
tests/test_index_cli.pyscript5.4 KB
tests/test_index_extension.pyscript17.0 KB
tests/test_index_source_count.pyscript3.0 KB
tests/test_package_structure.pyscript3.4 KB
tests/test_plugins.pyscript3.1 KB
tests/test_quality.pyscript21.3 KB
tests/test_quality_cli.pyscript5.5 KB
tests/test_quality_prose_weight.pyscript3.8 KB
tests/test_quality_script_fairness.pyscript4.7 KB
tests/test_quality_tier_refactor.pyscript4.0 KB
tests/test_scanner.pyscript2.6 KB
tests/test_scanner_fast_path.pyscript3.5 KB
tests/test_scanner_strict.pyscript2.1 KB
tests/test_secure_temporary_writes.pyscript978 B
tests/test_site.pyscript20.2 KB
tests/test_site_import_isolation.pyscript3.9 KB
tests/test_site_slug_refactor.pyscript3.6 KB
tests/test_source_type.pyscript3.5 KB
tests/test_status_metrics.pyscript4.1 KB
tests/test_status_quality.pyscript5.3 KB
tests/test_status_worklist.pyscript3.0 KB
tests/test_structure.pyscript501 B
tests/test_topic_category.pyscript4.2 KB
tests/test_topic_path_boundary.pyscript2.2 KB
tests/test_vault_boundary.pyscript24.3 KB
tests/test_wiki_index.pyscript13.3 KB
tests/test_worklist.pyscript12.3 KB
tests/test_worklist_cli.pyscript1.9 KB

tests/test_evaluate_enhancements.py

View on GitHub
"""TDD regression tests for the academic/Obsidian evaluation roadmap."""

from __future__ import annotations

import json
from pathlib import Path

import pytest
from agent_wiki import commands, config, frontmatter, links, site, wiki_index, worklist


def _init(vault: Path) -> None:
    config.topics_dir(vault).mkdir(parents=True, exist_ok=True)


def _page(vault: Path, name: str, meta: dict, body: str = "x") -> Path:
    path = config.topics_dir(vault) / name
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(frontmatter.dump(meta, body), encoding="utf-8")
    return path


def test_link_parser_preserves_fragments_embeds_and_ignores_code() -> None:
    refs = links.parse(
        "Outside [[Paper#Methods|method]] and [paper](Paper.md#Results).\n"
        "![[attachments/figure.png|300]]\n\n"
        "```md\n[[Not a relation]]\n```\n\n"
        "Inline `[[Also not a relation]]`."
    )

    assert [(ref.target, ref.fragment, ref.embed, ref.syntax) for ref in refs] == [
        ("Paper", "Methods", False, "wikilink"),
        ("Paper.md", "Results", False, "markdown"),
        ("attachments/figure.png", "", True, "wikilink"),
    ]


def test_link_parser_handles_markdown_boundaries_and_comments() -> None:
    refs = links.parse(
        "``code ` [[code-span]]`` [[real]]\n"
        "```md\n[[fenced]]\n``` not-a-close\n[[still-fenced]]\n```\n"
        "[[real-two]]\n<!-- [[comment]]\n[[comment-two]]\n[also-comment](Comment.md) -->\n"
        "`<!-- [[inline-comment]] -->` [[real-three]]\n"
        "[ref](https://example.org/Function_(mathematics))\n"
        "![pdf](<paper_(v1).pdf#page=3> \"title\")"
    )

    assert [(ref.target, ref.fragment, ref.embed, ref.syntax) for ref in refs] == [
        ("real", "", False, "wikilink"),
        ("real-two", "", False, "wikilink"),
        ("real-three", "", False, "wikilink"),
        ("https://example.org/Function_(mathematics)", "", False, "markdown"),
        ("paper_(v1).pdf", "page=3", True, "markdown"),
    ]
    inline = "`<!-- [[inline-comment]] -->`"
    assert links.rewrite(inline, lambda _ref: "BROKEN") == inline


def test_index_records_canonical_link_details_and_ignores_code(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(
        tmp_path,
        "A.md",
        {"title": "A"},
        "[[B#Methods|method]] [B](B.md#Results)\n\n```md\n[[Fake]]\n```",
    )

    entry = wiki_index.rebuild(tmp_path)[0]["topics"]["A.md"]
    assert entry["links"] == ["B", "B.md"]
    assert entry["link_records"] == [
        {
            "target": "B",
            "label": "method",
            "fragment": "Methods",
            "embed": False,
            "syntax": "wikilink",
        },
        {
            "target": "B.md",
            "label": "B",
            "fragment": "Results",
            "embed": False,
            "syntax": "markdown",
        },
    ]


def test_incremental_rebuild_invalidates_old_index_schema(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "[B](B.md#Methods)")
    initial, _ = wiki_index.rebuild(tmp_path)
    old_entry = dict(initial["topics"]["A.md"])
    old_entry.pop("link_records", None)
    for field in ("citekey", "doi", "library_id", "review_status", "reviewed_at"):
        old_entry.pop(field, None)
    old_entry["links"] = []
    config.index_path(tmp_path).write_text(
        json.dumps({"version": 1, "topics": {"A.md": old_entry}, "queries": {}, "alias_index": {}}),
        encoding="utf-8",
    )

    rebuilt, _ = wiki_index.rebuild(tmp_path, incremental=True)

    assert rebuilt["version"] != 1
    assert rebuilt["topics"]["A.md"]["link_records"] == [
        {
            "target": "B.md",
            "label": "B",
            "fragment": "Methods",
            "embed": False,
            "syntax": "markdown",
        }
    ]


def test_incremental_rebuild_rejects_incomplete_current_entry(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "[B](B.md#Methods)")
    initial, _ = wiki_index.rebuild(tmp_path)
    incomplete = dict(initial["topics"]["A.md"])
    incomplete.pop("link_records")
    config.index_path(tmp_path).write_text(
        json.dumps(
            {
                "version": wiki_index.INDEX_VERSION,
                "topics": {"A.md": incomplete},
                "queries": {},
                "alias_index": {},
            }
        ),
        encoding="utf-8",
    )

    rebuilt, _ = wiki_index.rebuild(tmp_path, incremental=True)

    assert rebuilt["topics"]["A.md"]["link_records"]


def test_incremental_rebuild_rejects_malformed_current_entry(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "[[B]]")
    initial, _ = wiki_index.rebuild(tmp_path)
    malformed = dict(initial["topics"]["A.md"])
    malformed["aliases"] = 1
    config.index_path(tmp_path).write_text(
        json.dumps(
            {
                "version": wiki_index.INDEX_VERSION,
                "topics": {"A.md": malformed},
                "queries": {},
                "alias_index": {},
            }
        ),
        encoding="utf-8",
    )

    rebuilt, _ = wiki_index.rebuild(tmp_path, incremental=True)

    assert rebuilt["topics"]["A.md"]["aliases"] == []
    assert rebuilt["topics"]["A.md"]["link_records"]


def test_worklist_resolves_alias_and_does_not_report_code_links(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "[[Bee#Methods]]\n```md\n[[Missing]]\n```")
    _page(tmp_path, "B.md", {"title": "B", "aliases": ["Bee"]})

    result = worklist.compute_worklist(tmp_path)

    assert result["wanted"] == []
    assert result["unresolved"] == []


def test_canvas_resolves_alias_and_fragment_links(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "[[Bee#Methods]]")
    _page(tmp_path, "B.md", {"title": "B", "aliases": ["Bee"]})
    data, errors = wiki_index.rebuild(tmp_path)

    assert errors == []
    from agent_wiki import canvas

    assert canvas.neighbors("A.md", data) == {"B.md"}


def test_link_resolver_accepts_explicit_wiki_query_paths(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "[[wiki/queries/report]]")
    queries = config.queries_dir(tmp_path)
    queries.mkdir(parents=True, exist_ok=True)
    (queries / "report.md").write_text(frontmatter.dump({"title": "Report"}, "body"), encoding="utf-8")

    data, errors = wiki_index.rebuild(tmp_path)

    assert errors == []
    entry = data["topics"]["A.md"]
    resolution = links.resolve("wiki/queries/report", set(data["topics"]), set(data["queries"]), data["alias_index"])
    assert resolution.status == "resolved"
    assert resolution.key == "queries/report.md"
    assert links.from_entry(entry)[0].target == "wiki/queries/report"


def test_site_preserves_heading_fragment_and_renders_image_embed(tmp_path: Path) -> None:
    pytest.importorskip("markdown")
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "A"}, "See [[B#Methods|methods]].\n\n![[attachments/figure.png]]")
    _page(tmp_path, "B.md", {"title": "B"}, "## Methods\n\nDetails")
    (tmp_path / "attachments").mkdir()
    (tmp_path / "attachments" / "figure.png").write_bytes(b"png")

    site.generate_site(tmp_path)
    rendered = (config.wiki_root(tmp_path) / "site" / "A.html").read_text(encoding="utf-8")

    assert 'href="B.html#h-methods"' in rendered
    assert 'src="../../attachments/figure.png"' in rendered
    assert '<span class="wikilink wikilink--missing"' not in rendered


def test_site_preserves_external_fragments_and_special_heading_ids(tmp_path: Path) -> None:
    pytest.importorskip("markdown")
    _init(tmp_path)
    _page(
        tmp_path,
        "A.md",
        {"title": "A"},
        "[[B#Methods & Results|internal]]\n\n"
        "[external](https://example.org/doc#section)\n\n"
        "[pdf](paper.pdf#page=3)",
    )
    _page(tmp_path, "B.md", {"title": "B"}, "## Methods & Results\n\nbody")

    site.generate_site(tmp_path)
    rendered_a = (config.wiki_root(tmp_path) / "site" / "A.html").read_text(encoding="utf-8")
    rendered_b = (config.wiki_root(tmp_path) / "site" / "B.html").read_text(encoding="utf-8")

    assert 'href="https://example.org/doc#section"' in rendered_a
    assert 'href="../../paper.pdf#page=3"' in rendered_a
    assert 'href="B.html#h-methods_&amp;_results"' in rendered_a
    assert 'id="h-methods_&amp;_results"' in rendered_b


def test_site_does_not_reinterpret_search_text_as_html(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(tmp_path, "A.md", {"title": "<em>literal</em>"}, "Content")
    site.generate_site(tmp_path)
    rendered = (config.wiki_root(tmp_path) / "site" / "index.html").read_text(encoding="utf-8")

    assert "innerHTML" not in rendered


def test_site_sanitizes_raw_html_and_unsafe_urls(tmp_path: Path) -> None:
    pytest.importorskip("markdown")
    _init(tmp_path)
    _page(
        tmp_path,
        "A.md",
        {"title": "A"},
        '<script>alert("x")</script>\n\n<div onclick="alert(1)">safe text</div>\n\n[bad](javascript:alert(1))',
    )
    site.generate_site(tmp_path)
    rendered = (config.wiki_root(tmp_path) / "site" / "A.html").read_text(encoding="utf-8")

    article = rendered.split('<main id="main-article"', 1)[1].split("</main>", 1)[0]
    lowered = article.lower()
    assert "<script" not in lowered
    assert "onclick" not in lowered
    assert "javascript:" not in lowered
    assert "safe text" in article


def test_site_escapes_raw_text_payloads(tmp_path: Path) -> None:
    pytest.importorskip("markdown")
    _init(tmp_path)
    _page(
        tmp_path,
        "A.md",
        {"title": "A"},
        '<script><img src=x onerror="alert(1)"></script>\n\n'
        '<style><img src=x onerror="alert(2)"></style>\n\n'
        '<textarea><img src=x onerror="alert(3)"></textarea>\n\n'
        '<script/><img src=x onerror="alert(4)">',
    )
    site.generate_site(tmp_path)
    rendered = (config.wiki_root(tmp_path) / "site" / "A.html").read_text(encoding="utf-8")
    article = rendered.split('<main id="main-article"', 1)[1].split("</main>", 1)[0]

    assert "<script" not in article.lower()
    assert "<style" not in article.lower()
    assert "<textarea" not in article.lower()
    assert "<img" not in article.lower()


def test_research_metadata_is_normalized_without_affecting_plain_notes(tmp_path: Path) -> None:
    _init(tmp_path)
    _page(
        tmp_path,
        "paper.md",
        {
            "title": "Paper",
            "citekey": "smith2024",
            "doi": "10.1234/example",
            "library_id": "zotero:ABC",
            "review_status": "needs_review",
            "reviewed_at": "2026-09-05",
        },
    )
    _page(tmp_path, "plain.md", {"title": "Plain"})

    topics = wiki_index.rebuild(tmp_path)[0]["topics"]
    assert topics["paper.md"]["citekey"] == "smith2024"
    assert topics["paper.md"]["doi"] == "10.1234/example"
    assert topics["paper.md"]["library_id"] == "zotero:ABC"
    assert topics["paper.md"]["review_status"] == "needs_review"
    assert topics["plain.md"]["citekey"] == ""


def test_static_site_includes_query_reports_and_search_metadata(tmp_path: Path) -> None:
    pytest.importorskip("markdown")
    _init(tmp_path)
    _page(tmp_path, "topic.md", {"title": "Topic"})
    queries = config.queries_dir(tmp_path)
    queries.mkdir(parents=True, exist_ok=True)
    (queries / "report.md").write_text(
        frontmatter.dump(
            {
                "title": "Report",
                "authors": ["Ada"],
                "year_start": 2024,
                "keywords": ["Survey"],
                "summary": "A research report",
            },
            "Evidence [^1].\n\n[^1]: Page 4.",
        ),
        encoding="utf-8",
    )

    site.generate_site(tmp_path)
    site_dir = config.wiki_root(tmp_path) / "site"
    index_html = (site_dir / "index.html").read_text(encoding="utf-8")

    assert (site_dir / "queries_report.html").exists()
    assert "Report" in index_html
    assert "ada" in index_html and "2024" in index_html and "survey" in index_html
    report_html = (site_dir / "queries_report.html").read_text(encoding="utf-8")
    assert "Page 4." in report_html
    assert "fn" in report_html


def test_source_change_is_a_distinct_worklist_reason(tmp_path: Path) -> None:
    _init(tmp_path)
    source = tmp_path / "paper.md"
    source.write_text("old", encoding="utf-8")
    topic = _page(
        tmp_path,
        "topic.md",
        {"title": "Topic", "sources": ["paper.md"]},
        "## A\n\nword " * 100 + "\n\n## B\n\nword " * 100,
    )
    from agent_wiki import cache

    data = cache.empty_schema()
    stat = source.stat()
    cache.upsert(data, "paper.md", cache.sha256_file(source), stat.st_mtime_ns, stat.st_size, ["topic.md"])
    source.write_text("new", encoding="utf-8")

    result = worklist.compute_worklist(tmp_path)
    stale = next(item for item in result["stale"] if item["path"] == "topic.md")
    assert stale["reason"] == "source_changed"
    assert "source_changed" in stale["reasons"]
    assert topic.exists()


def test_source_change_marks_query_for_review(tmp_path: Path) -> None:
    _init(tmp_path)
    source = tmp_path / "paper.md"
    source.write_text("old", encoding="utf-8")
    queries = config.queries_dir(tmp_path)
    queries.mkdir(parents=True, exist_ok=True)
    (queries / "report.md").write_text(
        frontmatter.dump({"title": "Report", "sources": ["paper.md"]}, "Evidence"),
        encoding="utf-8",
    )
    from agent_wiki import cache

    data = cache.empty_schema()
    stat = source.stat()
    cache.upsert(data, "paper.md", cache.sha256_file(source), stat.st_mtime_ns, stat.st_size, [])
    source.write_text("new", encoding="utf-8")

    result = worklist.compute_worklist(tmp_path)
    assert result["review"] == [{"path": "queries/report.md", "kind": "query", "reason": "source_changed"}]


def test_status_marks_changed_query_site_stale(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
    _init(tmp_path)
    _page(tmp_path, "topic.md", {"title": "Topic"})
    query = config.queries_dir(tmp_path) / "report.md"
    query.parent.mkdir(parents=True, exist_ok=True)
    query.write_text(frontmatter.dump({"title": "Report"}, "body"), encoding="utf-8")
    args = type("Args", (), {"vault": str(tmp_path), "format": "json", "verbose": False})()
    commands.cmd_gen_site(args)
    capsys.readouterr()
    import time
    time.sleep(0.01)
    query.touch()
    commands.cmd_status(args)
    status = json.loads(capsys.readouterr().out)
    assert status["site_stale"] is True
    assert status["review_count"] == 0


def test_research_query_template_is_reproducible() -> None:
    template = Path(__file__).parents[1] / "templates" / "query" / "research.md"
    text = template.read_text(encoding="utf-8")
    for heading in ("研究问题", "检索记录", "证据矩阵", "争议", "下一步阅读"):
        assert heading in text
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