|
| 1 | +--- |
| 2 | +name: okf-refactor |
| 3 | +description: Refactor existing knowledge into an Open Knowledge Format (OKF) bundle — convert loose notes, docs, READMEs, wikis, or a catalog/metadata export into markdown concept files with YAML frontmatter, index.md, and a knowledge graph. Use when migrating existing knowledge to OKF, normalizing a notes folder, or exporting a catalog to OKF. |
| 4 | +--- |
| 5 | + |
| 6 | +# okf-refactor — convert existing knowledge into an OKF bundle |
| 7 | + |
| 8 | +## Goal |
| 9 | + |
| 10 | +Take knowledge that already exists in some other shape — a folder of loose |
| 11 | +markdown notes, a wiki, README/docs, a data-catalog export, a database schema, a |
| 12 | +JSON/CSV metadata dump — and emit a conformant **OKF v0.1** bundle: a directory of |
| 13 | +one-concept-per-file markdown docs with YAML frontmatter, navigable `index.md` |
| 14 | +files, and a cross-linked knowledge graph. |
| 15 | + |
| 16 | +This skill depends on the **okf** skill for the format itself. Read |
| 17 | +`../okf/reference/SPEC.md` (the bundled OKF v0.1 spec) before refactoring — it is |
| 18 | +the source of truth. Use `../okf/scripts/validate_okf.py` to check the result. |
| 19 | + |
| 20 | +## Inputs and outputs |
| 21 | + |
| 22 | +- **Input** (`<src>`): a directory, file set, or export to read FROM. Treat it as |
| 23 | + immutable ground truth — never edit the source in place. |
| 24 | +- **Output** (`<out>`): the bundle directory to write TO. New, separate from `<src>`. |
| 25 | + |
| 26 | +Confirm both paths before writing. If `<out>` is omitted, default to |
| 27 | +`./bundles/<name>` and state the choice. |
| 28 | + |
| 29 | +## The refactor pass (run in order; plan before writing) |
| 30 | + |
| 31 | +1. **Survey the source.** Inventory every item of knowledge and its natural |
| 32 | + boundaries. Identify what each "thing" is (a table, an endpoint, a concept, a |
| 33 | + runbook) — that becomes a concept's `type`. Note relationships between things |
| 34 | + (foreign keys, "see also", parent/child) — those become cross-links. |
| 35 | + |
| 36 | +2. **Design the taxonomy = the directory layout.** Group concepts into top-level |
| 37 | + directories by `type` or domain (`tables/`, `datasets/`, `references/`, |
| 38 | + `concepts/`, `playbooks/`…). Start flat; nest only when a level earns it. |
| 39 | + Directories are the coarse taxonomy; frontmatter `tags` carry cross-cutting |
| 40 | + facets. |
| 41 | + |
| 42 | +3. **Map each source item to one concept doc.** Atomic — one concept per file, |
| 43 | + `<group>/<slug>.md`, kebab-case stable slug. Never pack two concepts into one |
| 44 | + file; split multi-topic source notes. |
| 45 | + |
| 46 | +4. **Write frontmatter for each concept.** Always set a non-empty `type`. Derive |
| 47 | + `title` and `description` (one line — this is what indexes show). Set |
| 48 | + `resource` to the canonical URI when the item has one. Map source metadata to |
| 49 | + `tags` and `timestamp`. Preserve any source-specific metadata as extra |
| 50 | + frontmatter keys (consumers tolerate unknown keys) rather than dropping it. |
| 51 | + |
| 52 | +5. **Write the body.** Move structured fields under `# Schema` (prefer a table), |
| 53 | + runnable usage under `# Examples`, and sources under `# Citations`. Keep prose |
| 54 | + tight; favor structural markdown. Do not invent facts not present in the source. |
| 55 | + |
| 56 | +6. **Wire the graph.** Convert every relationship into an inline markdown link |
| 57 | + using **absolute bundle-relative** paths (`[orders](/tables/orders.md)`). |
| 58 | + Ensure no concept is fully orphaned — each should link, or be linked by, at |
| 59 | + least one other where a real relationship exists. |
| 60 | + |
| 61 | +7. **Mint reference docs.** External authoritative sources cited by many concepts |
| 62 | + become standalone `references/<slug>.md` concept docs (with their own `type`, |
| 63 | + e.g. `Reference`), linked from `# Citations`. |
| 64 | + |
| 65 | +8. **Generate indexes.** Write an `index.md` per navigable directory (no |
| 66 | + frontmatter; group under `#` sections; copy each bullet's description from the |
| 67 | + linked concept). Write the bundle-root `index.md` with `okf_version: "0.1"` |
| 68 | + frontmatter linking the top-level groups. |
| 69 | + |
| 70 | +9. **Seed `log.md`.** At the root, record an `## <YYYY-MM-DD>` entry noting the |
| 71 | + `* **Initialization**: Refactored from <source>.` Use the real current date. |
| 72 | + |
| 73 | +10. **Validate.** Run `validate_okf.py <out>`. Fix every error. Broken |
| 74 | + cross-links are warnings (the spec tolerates them) — resolve the ones you can, |
| 75 | + report the rest. |
| 76 | + |
| 77 | +## Fidelity rules |
| 78 | + |
| 79 | +- **Lossless of meaning.** Restructuring may drop redundant words, never facts. |
| 80 | + If the source has metadata with no obvious home, keep it as a custom frontmatter |
| 81 | + key rather than discarding it. |
| 82 | +- **No invention.** Don't fabricate descriptions, schemas, or links the source |
| 83 | + doesn't support. Mark genuine gaps plainly instead of guessing. |
| 84 | +- **Source stays immutable.** All writes land in `<out>`; `<src>` is read-only. |
| 85 | +- **Idempotent-ish.** Re-running against the same source should converge on the |
| 86 | + same bundle, not accumulate duplicates. |
| 87 | + |
| 88 | +## Report |
| 89 | + |
| 90 | +After the pass, summarize: number of concepts emitted (by `type`/group), index and |
| 91 | +reference docs created, cross-links wired, and any unresolved gaps or broken links |
| 92 | +the source left dangling. Then show the bundle tree. |
| 93 | + |
| 94 | +## Checklist |
| 95 | + |
| 96 | +- [ ] Confirmed `<src>` (read-only) and `<out>` (new) paths. |
| 97 | +- [ ] Read ../okf/reference/SPEC.md before refactoring. |
| 98 | +- [ ] One concept per file; multi-topic notes split; stable kebab-case slugs. |
| 99 | +- [ ] Every concept has a non-empty `type`, plus `title` + `description`. |
| 100 | +- [ ] Relationships wired as absolute bundle-relative links; no true orphans. |
| 101 | +- [ ] Root index.md has `okf_version: "0.1"`; per-directory indexes generated. |
| 102 | +- [ ] log.md seeded with the initialization entry (real date). |
| 103 | +- [ ] validate_okf.py run; errors fixed; remaining broken links reported. |
| 104 | +- [ ] No facts invented; source-specific metadata preserved as custom keys. |
0 commit comments