Click a concept node to view it.
"""
def render_html(graph, name="OKF Bundle"):
data = json.dumps(graph, ensure_ascii=False).replace("", "<\\/")
return _HTML.replace("__NAME__", html.escape(name)).replace("__DATA__", data)
def main(argv=None):
ap = argparse.ArgumentParser(description="Visualize an OKF bundle as self-contained HTML.")
ap.add_argument("--bundle", required=True)
ap.add_argument("--out")
ap.add_argument("--name")
args = ap.parse_args(argv)
bundle = Path(args.bundle)
graph = build_graph(bundle)
out = Path(args.out) if args.out else bundle / "viz.html"
out.write_text(render_html(graph, args.name or bundle.name), encoding="utf-8")
print("Wrote %s (%d nodes, %d edges)" % (out, len(graph["nodes"]), len(graph["edges"])))
return 0
if __name__ == "__main__":
sys.exit(main())
```
- [ ] **Step 4: Run test to verify it passes**
Run: `python3 -m unittest tests.test_okf_viz -v`
Expected: PASS (4 tests OK)
- [ ] **Step 5: Smoke-test against a real Google bundle**
Run: `python3 okf_viz.py --bundle ~/Documents/reference-library/open-knowledge-format/okf/bundles/crypto_bitcoin --out /tmp/okf_btc_viz.html && echo OK`
Expected: prints `Wrote /tmp/okf_btc_viz.html (N nodes, M edges)` with N>0. Open in a browser to confirm a graph renders. (This is a manual visual check.)
- [ ] **Step 6: Commit**
```bash
git add custom-skills/97-ourdigital-okf/code/scripts/okf_viz.py custom-skills/97-ourdigital-okf/code/scripts/tests/test_okf_viz.py
git commit -m "feat(okf): add minimal okf_viz Cytoscape generator with tests"
```
---
## Task 7: Run the full test suite
- [ ] **Step 1: Run every test**
Run: `cd custom-skills/97-ourdigital-okf/code/scripts && python3 -m unittest discover -s tests -v`
Expected: all tests PASS (Google-bundle test passes or skips if fixtures absent).
- [ ] **Step 2: Commit any fixes** (only if changes were needed)
```bash
git add -A custom-skills/97-ourdigital-okf
git commit -m "test(okf): green full suite"
```
---
## Task 8: Reference docs (`code/references/`)
**Files:**
- Create: `code/references/okf-spec-v0.1.md`, `code/references/frontmatter-fields.md`
- [ ] **Step 1: Create `code/references/okf-spec-v0.1.md`**
Write a distilled, *actionable* version of OKF v0.1 (source: `~/Documents/reference-library/open-knowledge-format/okf/SPEC.md`). It MUST contain these sections with this content:
- **Bundle/Concept/Concept-ID definitions** (concept ID = path minus `.md`).
- **Reserved filenames table:** `index.md` (directory listing / progressive disclosure, no frontmatter except optional root `okf_version`), `log.md` (date-grouped `YYYY-MM-DD`, newest-first).
- **Frontmatter table:** `type` REQUIRED; `title`/`description`/`resource`/`tags`/`timestamp` recommended; arbitrary extra keys allowed.
- **Conventional body headings:** `# Schema`, `# Examples`, `# Citations`.
- **Cross-linking:** bundle-relative (`/path/concept.md`, leading `/`) recommended; relative (`./x.md`) allowed; broken links tolerated.
- **Conformance checklist (§9):** parseable frontmatter + non-empty `type` per concept; never reject for missing optional fields / unknown types / broken links / missing index.
- **Authoring rules for the producer** (numbered): one concept per file; pick descriptive `type` values; prefer structural markdown; cross-link related concepts; add `# Citations` when sourcing external claims; generate `index.md` per directory.
(The "OKF v0.1 at a glance" cheat-sheet in `~/Documents/reference-library/open-knowledge-format/README.md` is a ready source for the tables — adapt it.)
- [ ] **Step 2: Create `code/references/frontmatter-fields.md`**
A one-page field reference: for each of `type, title, description, resource, tags, timestamp` give purpose, requiredness, example value, and example `type` values (`BigQuery Table`, `BigQuery Dataset`, `Metric`, `Playbook`, `Reference`, `API Endpoint`).
- [ ] **Step 3: Commit**
```bash
git add custom-skills/97-ourdigital-okf/code/references
git commit -m "docs(okf): add distilled spec + frontmatter reference"
```
---
## Task 9: Templates (`code/assets/`)
**Files:**
- Create: `code/assets/concept.md`, `code/assets/index.md`, `code/assets/log.md`
- [ ] **Step 1: Create `code/assets/concept.md`**
```markdown
---
type: