Initial triage wiki

This commit is contained in:
MrARM
2026-07-06 20:06:06 -05:00
commit 8207a1e356
22 changed files with 5148 additions and 0 deletions

855
scripts/build_viewer.py Normal file
View File

@@ -0,0 +1,855 @@
#!/usr/bin/env python3
"""Build the self-contained HTML viewer for rootfs-triage-wiki."""
from __future__ import annotations
import json
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "viewer.html"
def read_text(path: Path) -> str:
return path.read_text(encoding="utf-8", errors="replace")
def title_for(path: Path, text: str) -> str:
match = re.search(r"^#\s+(.+?)\s*$", text, re.MULTILINE)
if match:
return match.group(1)
return path.stem.replace("-", " ").replace("_", " ").title()
def page_order() -> list[str]:
readme = read_text(ROOT / "README.md")
ordered = ["README.md"]
for target in re.findall(r"\[[^\]]+\]\(([^)#?]+)", readme):
target_path = ROOT / target
if target_path.suffix not in {".md", ".c"}:
continue
if target not in ordered and target_path.exists():
ordered.append(target)
for path in sorted(ROOT.glob("*.md")):
name = path.name
if name not in ordered:
ordered.append(name)
c_export = "conagent-pseudocode.c"
if (ROOT / c_export).exists() and c_export not in ordered:
ordered.append(c_export)
return ordered
def build_pages() -> list[dict[str, str]]:
pages = []
for name in page_order():
path = ROOT / name
text = read_text(path)
kind = "markdown" if path.suffix == ".md" else "source"
pages.append(
{
"path": name,
"title": title_for(path, text),
"kind": kind,
"text": text,
}
)
return pages
HTML_TEMPLATE = r"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pokemon Spike 3 Rootfs Triage Wiki</title>
<style>
:root {
--page: #f8f9fa;
--content: #ffffff;
--ink: #202122;
--muted: #54595d;
--line: #a2a9b1;
--soft-line: #c8ccd1;
--blue: #0645ad;
--blue-visited: #0b0080;
--tab: #36c;
--code-bg: #f1f2f3;
--sidebar: #f6f6f6;
--mark: #fff3cd;
--danger: #d73333;
}
* { box-sizing: border-box; }
html {
color: var(--ink);
background: var(--page);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
font-size: 15px;
line-height: 1.55;
}
body { margin: 0; min-width: 320px; }
a { color: var(--blue); text-decoration: none; }
a:visited { color: var(--blue-visited); }
a:hover { text-decoration: underline; }
.wiki-shell {
display: grid;
grid-template-columns: 184px minmax(0, 1fr);
min-height: 100vh;
}
.sidebar {
border-right: 1px solid var(--soft-line);
background: var(--sidebar);
padding: 14px 12px 24px;
}
.brand {
display: grid;
gap: 4px;
margin-bottom: 18px;
color: var(--ink);
}
.brand-mark {
width: 52px;
height: 52px;
border: 1px solid var(--line);
background:
linear-gradient(135deg, transparent 42%, rgba(0,0,0,.08) 42% 58%, transparent 58%),
radial-gradient(circle at 35% 35%, #fff 0 9px, #202122 10px 11px, transparent 12px),
linear-gradient(#d73333 0 50%, #fff 50% 100%);
border-radius: 50%;
box-shadow: inset 0 0 0 4px #fff;
}
.brand strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
line-height: 1.12;
font-weight: 400;
}
.brand span { color: var(--muted); font-size: 12px; }
.side-section {
margin-top: 18px;
padding-top: 9px;
border-top: 1px solid var(--soft-line);
}
.side-heading {
color: var(--muted);
font-size: 12px;
margin: 0 0 6px;
}
.page-list {
list-style: none;
margin: 0;
padding: 0;
font-size: 13px;
}
.page-list a {
display: block;
padding: 3px 0;
color: var(--blue);
}
.page-list a.active {
color: var(--ink);
font-weight: 600;
}
.main { min-width: 0; }
.topbar {
display: flex;
align-items: end;
justify-content: space-between;
gap: 18px;
min-height: 44px;
padding: 8px 28px 0;
background: linear-gradient(#ffffff 0%, #f8f9fa 100%);
border-bottom: 1px solid var(--line);
}
.tabs {
display: flex;
align-items: flex-end;
gap: 2px;
}
.tab {
border: 1px solid var(--line);
border-bottom: 0;
background: linear-gradient(#ffffff, #eaf3ff);
color: var(--tab);
font-size: 13px;
padding: 8px 12px 7px;
cursor: pointer;
min-height: 34px;
}
.tab.active {
background: var(--content);
color: var(--ink);
margin-bottom: -1px;
padding-bottom: 8px;
}
.search-wrap {
width: min(360px, 42vw);
position: relative;
padding-bottom: 7px;
}
.search-wrap input {
width: 100%;
border: 1px solid var(--line);
background: #fff;
padding: 7px 9px;
font: inherit;
font-size: 13px;
}
.search-results {
position: absolute;
z-index: 20;
top: calc(100% - 5px);
right: 0;
width: 100%;
max-height: 320px;
overflow: auto;
border: 1px solid var(--line);
background: #fff;
box-shadow: 0 6px 18px rgba(0,0,0,.16);
display: none;
}
.search-results.open { display: block; }
.search-results a {
display: block;
padding: 8px 10px;
border-bottom: 1px solid #eaecf0;
color: var(--ink);
}
.search-results a:hover { background: #f8f9fa; text-decoration: none; }
.search-results small { display: block; color: var(--muted); }
.article-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 220px;
gap: 24px;
align-items: start;
padding: 24px 28px 44px;
}
.article {
min-width: 0;
background: var(--content);
border: 1px solid var(--line);
border-top: 0;
padding: 24px 32px 34px;
}
.page-subtitle {
color: var(--muted);
font-size: 13px;
margin: -7px 0 20px;
border-bottom: 1px solid var(--line);
padding-bottom: 8px;
}
.wiki-content h1,
.wiki-content h2 {
font-family: Georgia, "Times New Roman", serif;
font-weight: 400;
line-height: 1.25;
border-bottom: 1px solid var(--line);
margin: 22px 0 12px;
padding-bottom: 4px;
}
.wiki-content h1 {
font-size: 31px;
margin-top: 0;
}
.wiki-content h2 { font-size: 23px; }
.wiki-content h3 { font-size: 18px; margin: 20px 0 8px; }
.wiki-content h4 { font-size: 15px; margin: 18px 0 6px; }
.wiki-content p { margin: 0 0 12px; }
.wiki-content ul,
.wiki-content ol {
margin: 0 0 13px 24px;
padding: 0;
}
.wiki-content li { margin: 3px 0; }
.wiki-content code,
.source-view code {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
font-size: .92em;
background: var(--code-bg);
padding: 1px 4px;
border-radius: 2px;
overflow-wrap: anywhere;
word-break: break-word;
}
.wiki-content pre,
.source-view pre {
background: var(--code-bg);
border: 1px solid var(--soft-line);
padding: 12px;
overflow: auto;
font-size: 13px;
line-height: 1.45;
max-width: 100%;
white-space: pre;
}
.wiki-content pre code,
.source-view pre code {
background: transparent;
padding: 0;
border-radius: 0;
overflow-wrap: normal;
word-break: normal;
}
.wiki-content table {
border-collapse: collapse;
margin: 12px 0 18px;
max-width: 100%;
table-layout: fixed;
width: 100%;
font-size: 14px;
}
.table-scroll {
max-width: 100%;
overflow-x: auto;
}
.table-scroll table {
min-width: 520px;
}
.wiki-content th,
.wiki-content td {
border: 1px solid var(--line);
padding: 7px 9px;
vertical-align: top;
overflow-wrap: anywhere;
word-break: break-word;
}
.wiki-content th {
background: #eaecf0;
text-align: left;
font-weight: 600;
}
.wiki-content tr:nth-child(even) td { background: #f8f9fa; }
.missing-link {
color: var(--danger);
border-bottom: 1px dotted var(--danger);
cursor: help;
}
.toc {
position: sticky;
top: 12px;
border: 1px solid var(--line);
background: var(--content);
padding: 12px;
font-size: 13px;
}
.toc h2,
.backlinks h2 {
font-size: 13px;
font-weight: 600;
margin: 0 0 8px;
padding: 0;
border: 0;
font-family: inherit;
}
.toc ol {
margin: 0 0 0 18px;
padding: 0;
}
.toc li { margin: 3px 0; }
.backlinks {
margin-top: 14px;
border-top: 1px solid var(--soft-line);
padding-top: 10px;
}
.backlinks ul {
margin: 0 0 0 18px;
padding: 0;
}
mark { background: var(--mark); padding: 0 2px; }
.footer {
color: var(--muted);
font-size: 12px;
border-top: 1px solid var(--soft-line);
margin-top: 28px;
padding-top: 10px;
}
@media (max-width: 900px) {
.wiki-shell { grid-template-columns: 1fr; }
.sidebar {
border-right: 0;
border-bottom: 1px solid var(--soft-line);
}
.brand { grid-template-columns: 42px minmax(0, 1fr); align-items: center; }
.brand-mark { width: 42px; height: 42px; }
.side-section { margin-top: 10px; }
.page-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 0 12px;
}
.topbar {
align-items: stretch;
flex-direction: column-reverse;
padding: 10px 14px 0;
gap: 8px;
}
.search-wrap { width: 100%; padding-bottom: 0; }
.article-layout {
display: block;
padding: 0 14px 28px;
}
.article {
padding: 18px 16px 26px;
border-top: 1px solid var(--line);
}
.wiki-content code {
word-break: break-all;
}
.wiki-content pre code {
word-break: normal;
}
.toc {
position: static;
margin: 14px 0;
}
}
</style>
</head>
<body>
<div class="wiki-shell">
<aside class="sidebar">
<a class="brand" href="#/README.md" aria-label="Open wiki home">
<span class="brand-mark" aria-hidden="true"></span>
<span>
<strong>Spike 3<br>Rootfs Wiki</strong>
<span>static evidence viewer</span>
</span>
</a>
<nav class="side-section" aria-label="Wiki pages">
<p class="side-heading">Navigation</p>
<ul class="page-list" id="page-list"></ul>
</nav>
<nav class="side-section" aria-label="Generated artifacts">
<p class="side-heading">Generated files</p>
<ul class="page-list" id="artifact-list"></ul>
</nav>
</aside>
<main class="main">
<div class="topbar">
<div class="tabs" role="tablist" aria-label="View mode">
<button class="tab active" id="read-tab" type="button">Article</button>
<button class="tab" id="source-tab" type="button">Source</button>
</div>
<div class="search-wrap">
<input id="search" type="search" autocomplete="off" placeholder="Search the wiki">
<div class="search-results" id="search-results"></div>
</div>
</div>
<div class="article-layout">
<article class="article">
<div id="article-view"></div>
<div class="footer">
Built from files in <code>rootfs-triage-wiki/</code>. This viewer is static and does not execute target rootfs binaries.
</div>
</article>
<aside class="toc" id="toc" aria-label="Contents"></aside>
</div>
</main>
</div>
<script id="wiki-data" type="application/json">__WIKI_DATA__</script>
<script>
const wiki = JSON.parse(document.getElementById("wiki-data").textContent);
const pageMap = new Map(wiki.pages.map((page) => [page.path, page]));
let currentPath = "README.md";
let viewMode = "article";
let headingIndex = [];
const pageList = document.getElementById("page-list");
const artifactList = document.getElementById("artifact-list");
const articleView = document.getElementById("article-view");
const tocView = document.getElementById("toc");
const searchInput = document.getElementById("search");
const searchResults = document.getElementById("search-results");
const readTab = document.getElementById("read-tab");
const sourceTab = document.getElementById("source-tab");
function escapeHtml(value) {
return String(value)
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#39;");
}
function escapeAttr(value) {
return escapeHtml(value).replaceAll("`", "&#96;");
}
function slugify(value) {
return value
.toLowerCase()
.replace(/<[^>]+>/g, "")
.replace(/`/g, "")
.replace(/&[a-z0-9#]+;/gi, "")
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "") || "section";
}
function splitFragment(href) {
const hash = href.indexOf("#");
if (hash === -1) return [href, ""];
return [href.slice(0, hash), href.slice(hash + 1)];
}
function routeFor(href, fromPath = currentPath) {
if (!href) return "#/" + fromPath;
if (/^(https?:|mailto:|tel:)/i.test(href)) return href;
const [rawPath, rawFragment] = splitFragment(href);
let target = rawPath || fromPath;
target = target.replace(/^\.\//, "");
if (target.includes("/")) {
const base = fromPath.split("/").slice(0, -1);
for (const part of target.split("/")) {
if (!part || part === ".") continue;
if (part === "..") base.pop();
else base.push(part);
}
target = base.join("/");
}
const fragment = rawFragment ? "#" + encodeURIComponent(rawFragment) : "";
if (pageMap.has(target)) return "#/" + target + fragment;
return href;
}
function renderInline(raw, fromPath = currentPath) {
let text = escapeHtml(raw);
text = text.replace(/`([^`]+)`/g, (match, code) => {
const decoded = code
.replaceAll("&lt;", "<")
.replaceAll("&gt;", ">")
.replaceAll("&quot;", '"')
.replaceAll("&#39;", "'")
.replaceAll("&amp;", "&");
if (pageMap.has(decoded)) {
return `<code><a href="${escapeAttr(routeFor(decoded, fromPath))}">${escapeHtml(decoded)}</a></code>`;
}
return `<code>${code}</code>`;
});
text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, label, href) => {
const route = routeFor(href, fromPath);
const external = /^(https?:|mailto:|tel:)/i.test(route);
const missing = route === href && !external && !href.startsWith("#") && /\.(md|c)(#.*)?$/i.test(href);
if (missing) {
return `<span class="missing-link" title="Target not embedded in viewer">${label}</span>`;
}
const targetAttrs = external ? ' target="_blank" rel="noopener noreferrer"' : "";
return `<a href="${escapeAttr(route)}"${targetAttrs}>${label}</a>`;
});
text = text.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
text = text.replace(/\*([^*]+)\*/g, "<em>$1</em>");
return text;
}
function parseTable(lines, start, fromPath) {
const rows = [];
let i = start;
while (i < lines.length && /^\s*\|.*\|\s*$/.test(lines[i])) {
rows.push(lines[i]);
i++;
}
if (rows.length < 2 || !/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(rows[1])) {
return null;
}
const split = (row) => row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((cell) => cell.trim());
const head = split(rows[0]);
const body = rows.slice(2).map(split);
let html = '<div class="table-scroll"><table><thead><tr>';
html += head.map((cell) => `<th>${renderInline(cell, fromPath)}</th>`).join("");
html += "</tr></thead><tbody>";
html += body.map((row) => `<tr>${row.map((cell) => `<td>${renderInline(cell, fromPath)}</td>`).join("")}</tr>`).join("");
html += "</tbody></table></div>";
return { html, next: i };
}
function flushParagraph(parts, out, fromPath) {
if (!parts.length) return;
out.push(`<p>${renderInline(parts.join(" "), fromPath)}</p>`);
parts.length = 0;
}
function renderMarkdown(markdown, fromPath) {
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
const out = [];
const paragraph = [];
headingIndex = [];
let listType = null;
let inFence = false;
let fenceLang = "";
let fenceLines = [];
function closeList() {
if (!listType) return;
out.push(`</${listType}>`);
listType = null;
}
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const fence = line.match(/^```([A-Za-z0-9_-]+)?\s*$/);
if (fence) {
if (inFence) {
out.push(`<pre><code class="language-${escapeAttr(fenceLang)}">${escapeHtml(fenceLines.join("\n"))}</code></pre>`);
inFence = false;
fenceLang = "";
fenceLines = [];
} else {
flushParagraph(paragraph, out, fromPath);
closeList();
inFence = true;
fenceLang = fence[1] || "";
}
continue;
}
if (inFence) {
fenceLines.push(line);
continue;
}
if (!line.trim()) {
flushParagraph(paragraph, out, fromPath);
closeList();
continue;
}
const table = parseTable(lines, i, fromPath);
if (table) {
flushParagraph(paragraph, out, fromPath);
closeList();
out.push(table.html);
i = table.next - 1;
continue;
}
const heading = line.match(/^(#{1,6})\s+(.+?)\s*#*\s*$/);
if (heading) {
flushParagraph(paragraph, out, fromPath);
closeList();
const level = heading[1].length;
const label = renderInline(heading[2], fromPath);
const id = slugify(heading[2]);
headingIndex.push({ level, label: heading[2], id });
out.push(`<h${level} id="${escapeAttr(id)}">${label}</h${level}>`);
continue;
}
const unordered = line.match(/^\s*[-*]\s+(.+)$/);
const ordered = line.match(/^\s*\d+\.\s+(.+)$/);
if (unordered || ordered) {
flushParagraph(paragraph, out, fromPath);
const type = unordered ? "ul" : "ol";
if (listType && listType !== type) closeList();
if (!listType) {
out.push(`<${type}>`);
listType = type;
}
out.push(`<li>${renderInline((unordered || ordered)[1], fromPath)}</li>`);
continue;
}
const quote = line.match(/^>\s?(.+)$/);
if (quote) {
flushParagraph(paragraph, out, fromPath);
closeList();
out.push(`<blockquote>${renderInline(quote[1], fromPath)}</blockquote>`);
continue;
}
closeList();
paragraph.push(line.trim());
}
if (inFence) {
out.push(`<pre><code class="language-${escapeAttr(fenceLang)}">${escapeHtml(fenceLines.join("\n"))}</code></pre>`);
}
flushParagraph(paragraph, out, fromPath);
closeList();
return out.join("\n");
}
function renderSource(page) {
const lang = page.path.endsWith(".c") ? "c" : "markdown";
headingIndex = [{ level: 2, label: "Raw source", id: "raw-source" }];
return `<h1>${escapeHtml(page.title)}</h1><p class="page-subtitle">Source view of <code>${escapeHtml(page.path)}</code></p><div class="source-view"><pre id="raw-source"><code class="language-${lang}">${escapeHtml(page.text)}</code></pre></div>`;
}
function makeToc(page) {
const headings = headingIndex.filter((heading) => heading.level > 1 && heading.level <= 3);
const backlinks = wiki.pages.filter((candidate) => {
if (candidate.path === page.path) return false;
return candidate.text.includes(`](${page.path}`) || candidate.text.includes("`" + page.path + "`");
});
let html = "";
if (headings.length) {
html += "<h2>Contents</h2><ol>";
html += headings.map((heading) => `<li><a href="#/${escapeAttr(page.path)}#${escapeAttr(heading.id)}">${escapeHtml(heading.label)}</a></li>`).join("");
html += "</ol>";
} else {
html += "<h2>Contents</h2><p>No headings.</p>";
}
if (backlinks.length) {
html += '<div class="backlinks"><h2>Referenced by</h2><ul>';
html += backlinks.map((source) => `<li><a href="#/${escapeAttr(source.path)}">${escapeHtml(source.title)}</a></li>`).join("");
html += "</ul></div>";
}
return html;
}
function parseRoute() {
let hash = window.location.hash || "#/README.md";
if (!hash.startsWith("#/")) hash = "#/README.md";
const withoutHash = hash.slice(2);
const fragmentIndex = withoutHash.indexOf("#");
const path = decodeURIComponent(fragmentIndex === -1 ? withoutHash : withoutHash.slice(0, fragmentIndex));
const fragment = fragmentIndex === -1 ? "" : decodeURIComponent(withoutHash.slice(fragmentIndex + 1));
return { path: pageMap.has(path) ? path : "README.md", fragment };
}
function setMode(mode) {
viewMode = mode;
readTab.classList.toggle("active", mode === "article");
sourceTab.classList.toggle("active", mode === "source");
renderPage();
}
function renderPage() {
const route = parseRoute();
currentPath = route.path;
const page = pageMap.get(currentPath) || pageMap.get("README.md");
document.title = `${page.title} - Pokemon Spike 3 Rootfs Triage Wiki`;
articleView.innerHTML = viewMode === "source" || page.kind === "source"
? renderSource(page)
: `<div class="wiki-content">${renderMarkdown(page.text, page.path)}</div>`;
tocView.innerHTML = makeToc(page);
document.querySelectorAll(".page-list a").forEach((link) => {
link.classList.toggle("active", link.dataset.path === currentPath);
});
if (route.fragment) {
const wanted = document.getElementById(route.fragment) || document.getElementById(slugify(route.fragment));
if (wanted) wanted.scrollIntoView({ block: "start" });
} else {
window.scrollTo({ top: 0 });
}
}
function renderNavigation() {
const pages = wiki.pages.filter((page) => page.kind === "markdown");
const artifacts = wiki.pages.filter((page) => page.kind !== "markdown");
pageList.innerHTML = pages.map((page) => `<li><a data-path="${escapeAttr(page.path)}" href="#/${escapeAttr(page.path)}">${escapeHtml(page.title)}</a></li>`).join("");
artifactList.innerHTML = artifacts.map((page) => `<li><a data-path="${escapeAttr(page.path)}" href="#/${escapeAttr(page.path)}">${escapeHtml(page.title)}</a></li>`).join("");
}
function search(query) {
const q = query.trim().toLowerCase();
if (!q) {
searchResults.classList.remove("open");
searchResults.innerHTML = "";
return;
}
const hits = [];
for (const page of wiki.pages) {
const titleHit = page.title.toLowerCase().includes(q);
const idx = page.text.toLowerCase().indexOf(q);
if (!titleHit && idx === -1) continue;
const start = Math.max(0, idx - 44);
const end = Math.min(page.text.length, idx + q.length + 74);
let snippet = idx === -1 ? page.path : page.text.slice(start, end).replace(/\s+/g, " ");
snippet = escapeHtml(snippet);
if (idx !== -1) {
snippet = snippet.replace(new RegExp(escapeHtml(q).replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "ig"), (m) => `<mark>${m}</mark>`);
}
hits.push({ page, snippet, titleHit });
}
searchResults.innerHTML = hits.slice(0, 12).map(({ page, snippet }) => (
`<a href="#/${escapeAttr(page.path)}"><strong>${escapeHtml(page.title)}</strong><small>${snippet}</small></a>`
)).join("") || '<a href="#/README.md"><strong>No matches</strong><small>Try a path, hash, service name, or binary name.</small></a>';
searchResults.classList.add("open");
}
readTab.addEventListener("click", () => setMode("article"));
sourceTab.addEventListener("click", () => setMode("source"));
window.addEventListener("hashchange", () => renderPage());
searchInput.addEventListener("input", (event) => search(event.target.value));
searchInput.addEventListener("keydown", (event) => {
if (event.key !== "Enter") return;
const first = searchResults.querySelector("a");
if (first) first.click();
});
document.addEventListener("click", (event) => {
if (!searchResults.contains(event.target) && event.target !== searchInput) {
searchResults.classList.remove("open");
}
});
renderNavigation();
renderPage();
</script>
</body>
</html>
"""
def main() -> None:
data = {"pages": build_pages()}
encoded = json.dumps(data, ensure_ascii=False, separators=(",", ":")).replace("</", "<\\/")
OUT.write_text(HTML_TEMPLATE.replace("__WIKI_DATA__", encoded), encoding="utf-8")
print(f"wrote {OUT.relative_to(ROOT.parent)}")
if __name__ == "__main__":
main()