brief_data.py

scripts/brief_data.py

Pull the real figures an internal brief quotes, from a built index.

inject

None brief_data.inject(Path db, str name, Path repo, Path page)

Inject a full tool reply into the brief, HTML-escaped.

scripts/brief_data.py:171

Show on the map →

Called by main

Calls none

Source · 37 lines
def inject(db: Path, name: str, repo: Path, page: Path) -> None:
    """Escaped, and by script rather than by hand: a 600-line payload pasted through an editor
    is a payload nobody re-derives, and any `<` in it would silently become markup.

    @brief Replace the page's marker with the escaped reply.
    @return None.
    @version 1
    """
    import html

    from clew.mcp_server.tools_query import QueryTools

    tools = QueryTools(lambda: db, lambda: repo, lambda: [])
    payload = json.dumps(tools.dossier(name), indent=2, default=str)

    ## RENDER FROM A TEMPLATE, NEVER IN PLACE. Substituting into the output file consumes its
    ## own markers, so the second run has nothing to substitute and silently emits the first
    ## run's page — which is exactly what happened, and it looked like the edit had not landed.
    template = page.parent / "brief.tmpl.html"
    source = template if template.is_file() else page
    text = source.read_text(encoding="utf-8")

    maze = page.parent / "maze.html"
    if maze.is_file():
        text = text.replace("MAZE_HERE", maze.read_text(encoding="utf-8"))
    text = text.replace("FULL_DOSSIER_HERE", html.escape(payload))

    for marker in ("MAZE_HERE", "FULL_DOSSIER_HERE"):
        if marker in text:
            print(f"WARNING: {marker} still unsubstituted")

    page.write_text(text, encoding="utf-8")
    print(
        f"rendered {source.name} -> {page.name}: maze + {len(payload.splitlines())} dossier lines"
    )

Activity · 16 steps
lines 179–179import htmllines 181–181from clew.mcp_server.tools_query import QueryToolslines 183–183tools = QueryTools(lambda: db, lambda: repo, lambda: [])lines 184–184payload = json.dumps(tools.dossier(name), indent=2, default=str)lines 189–189template = page.parent / "brief.tmpl.html"lines 190–190source = template if template.is_file() else pagelines 191–191text = source.read_text(encoding="utf-8")lines 193–193maze = page.parent / "maze.html"lines 194–194◇ if maze.is_file()lines 195–195text = text.replace("MAZE_HERE", maze.read_text(encoding="utf-8"))lines 196–196text = text.replace("FULL_DOSSIER_HERE", html.escape(payload))lines 198–198◇ for marker in ("MAZE_HERE", "FULL_DOSSIER_HERE")lines 199–199◇ if marker in textlines 200–200print(f"WARNING: {marker} still unsubstituted")lines 202–202page.write_text(text, encoding="utf-8")lines 203–205print( f"rendered {source.name} -> {page.name}: maze + {len(payload.splitlines())} dossier lines" )

Flows

main

int brief_data.main()

Entry point.

scripts/brief_data.py:212

Source · 28 lines
def main() -> int:
    """@brief Dispatch a subcommand against a database.
    @return Exit status.
    @version 1
    """
    ap = argparse.ArgumentParser(description=__doc__)
    ap.add_argument(
        "command", choices=("inventory", "threads", "locks", "one", "wire", "wiresearch", "inject")
    )
    ap.add_argument("--db", required=True, type=Path)
    ap.add_argument("--name", default="")
    ap.add_argument("--repo", default=Path("."), type=Path)
    ap.add_argument("--page", default=Path(".claude/tmp/clew-brief.html"), type=Path)
    args = ap.parse_args()

    if args.command == "one":
        one(args.db, args.name)
    elif args.command == "wire":
        wire(args.db, args.name, args.repo)
    elif args.command == "wiresearch":
        wiresearch(args.db, args.name, args.repo)
    elif args.command == "inject":
        inject(args.db, args.name, args.repo, args.page)
    else:
        {"inventory": inventory, "threads": threads, "locks": locks}[args.command](args.db)
    return 0

Activity · 18 steps
lines 217–217ap = argparse.ArgumentParser(description=__doc__)lines 218–220ap.add_argument( "command", choices=("inventory", "threads", "locks", "one", "wire", "wiresearch", "inject") )lines 221–221ap.add_argument("--db", required=True, type=Path)lines 222–222ap.add_argument("--name", default="")lines 223–223ap.add_argument("--repo", default=Path("."), type=Path)lines 224–224ap.add_argument("--page", default=Path(".claude/tmp/clew-brief.html"), type=Path)lines 225–225args = ap.parse_args()lines 227–227◇ if args.command == "one"lines 228–228one(args.db, args.name)lines 229–229◇ elif args.command == "wire"lines 230–230wire(args.db, args.name, args.repo)lines 231–231◇ elif args.command == "wiresearch"lines 232–232wiresearch(args.db, args.name, args.repo)lines 233–233◇ elif args.command == "inject"lines 234–234inject(args.db, args.name, args.repo, args.page)lines 235–235elselines 236–236{"inventory": inventory, "threads": threads, "locks": locks}[args.command](args.db)lines 237–237return 0

Flows

one

None brief_data.one(Path db, str name)

Print one symbol's dossier, trimmed to the panels a brief shows.

scripts/brief_data.py:100

Source · 22 lines
def one(db: Path, name: str) -> None:
    """@brief Emit a trimmed dossier for one symbol.
    @return None.
    @version 1
    """
    d = q.dossier(db, name)
    if d is None:
        print(f"{name}: not indexed")
        return
    fn = d.function
    print(f"subject   {d.subject}\nkind      {d.kind}")
    if fn is None:
        return
    print(f"file      {fn.file}:{fn.line_start}-{fn.line_end}")
    print(f"brief     {fn.brief}")
    print(f"liveness  {fn.liveness}")
    print(f"threads   {[t.name for t in fn.threads]}")
    print(f"locks     {[getattr(s, 'lock', s) for s in fn.locks_held]}")
    print(f"callers   {[e.name for e in fn.callers][:8]}")
    print(f"callees   {[e.name for e in fn.callees][:8]}")

Activity · 15 steps
lines 105–105d = q.dossier(db, name)lines 106–106◇ if d is Nonelines 107–107print(f"{name}: not indexed")lines 108–108returnlines 109–109fn = d.functionlines 110–110print(f"subject {d.subject}\nkind {d.kind}")lines 111–111◇ if fn is Nonelines 112–112returnlines 113–113print(f"file {fn.file}:{fn.line_start}-{fn.line_end}")lines 114–114print(f"brief {fn.brief}")lines 115–115print(f"liveness {fn.liveness}")lines 116–116print(f"threads {[t.name for t in fn.threads]}")lines 117–117print(f"locks {[getattr(s, 'lock', s) for s in fn.locks_held]}")lines 118–118print(f"callers {[e.name for e in fn.callers][:8]}")lines 119–119print(f"callees {[e.name for e in fn.callees][:8]}")

Flows

wire

None brief_data.wire(Path db, str name, Path repo)

Print the exact MCP tool reply for one subject.

scripts/brief_data.py:129

Source · 16 lines
def wire(db: Path, name: str, repo: Path) -> None:
    """THE SERVED PAYLOAD, not the library return value. `QueryTools.dossier` is what the MCP
    tool call resolves to, so its dict is byte-for-byte what a client receives once serialized —
    including the `target` stamp and any staleness block. Calling it here avoids needing the
    long-running server to have the target registered.

    @brief Emit the exact dossier tool reply.
    @return None.
    @version 1
    """
    from clew.mcp_server.tools_query import QueryTools

    tools = QueryTools(lambda: db, lambda: repo, lambda: [])
    print(json.dumps(tools.dossier(name), indent=2, default=str))

Activity · 3 steps
lines 139–139from clew.mcp_server.tools_query import QueryToolslines 141–141tools = QueryTools(lambda: db, lambda: repo, lambda: [])lines 142–142print(json.dumps(tools.dossier(name), indent=2, default=str))

Flows

wiresearch

None brief_data.wiresearch(Path db, str corpus, Path repo)

Print the exact MCP search reply for one corpus.

scripts/brief_data.py:152

Show on the map →

Called by main

Calls none

Source · 11 lines
def wiresearch(db: Path, corpus: str, repo: Path) -> None:
    """@brief Emit the exact search tool reply for a corpus.
    @return None.
    @version 1
    """
    from clew.mcp_server.tools_query import QueryTools

    tools = QueryTools(lambda: db, lambda: repo, lambda: [])
    print(json.dumps(tools.search(corpus=corpus), indent=2, default=str))

Activity · 3 steps
lines 157–157from clew.mcp_server.tools_query import QueryToolslines 159–159tools = QueryTools(lambda: db, lambda: repo, lambda: [])lines 160–160print(json.dumps(tools.search(corpus=corpus), indent=2, default=str))

Flows