{"id":50838193,"url":"https://github.com/bencode/kg","last_synced_at":"2026-06-14T05:30:34.573Z","repository":{"id":362608155,"uuid":"1259916967","full_name":"bencode/kg","owner":"bencode","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-05T03:15:43.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-05T05:07:49.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bencode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-05T01:44:24.000Z","updated_at":"2026-06-05T03:15:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bencode/kg","commit_stats":null,"previous_names":["bencode/kg"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/bencode/kg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bencode","download_url":"https://codeload.github.com/bencode/kg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fkg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34310801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-14T05:30:34.035Z","updated_at":"2026-06-14T05:30:34.564Z","avatar_url":"https://github.com/bencode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kg\n\nKnowledge graph over a markdown vault. **Files are the truth** — the graph\nlives in plain JSON under `\u003cvault\u003e/meta/kg/` (a hash↔path registry, an L1\nconcept table, and per-document L2 metadata with verbatim source anchors).\nThe SQLite index and the local viewer are rebuildable layers on top.\n\n```\n\u003cvault\u003e/meta/kg/registry.jsonl       # {hash, path, title, mtime, size} per doc\n\u003cvault\u003e/meta/kg/concepts.json        # L1 concept table (controlled vocabulary)\n\u003cvault\u003e/meta/kg/metadata/\u003chash\u003e.json # L2 mentions/relations, named by content hash\n~/.cache/kg/\u003csha1(vault)\u003e.db         # derived SQLite index — delete freely\n```\n\nKey properties:\n\n- **Hash-as-identity**: docs are referenced by content sha256, never by path.\n  Renames only rewrite the registry; content edits orphan the old metadata\n  (surfaced by `kg pending` / `kg gc`) so each doc version is extracted once.\n- **Anti-hallucination anchors**: every mention/relation carries a verbatim\n  `anchor.quote` validated as a literal substring of the source on import.\n- **Two trust tiers**: `deterministic` edges (md links, arXiv ids) vs `llm`\n  edges (extracted, with confidence).\n\n## Install\n\nThree ways, easiest first:\n\n1. **Single-file binary** (no runtime needed at all):\n   ```bash\n   pnpm install \u0026\u0026 pnpm -C packages/kg compile   # → dist-bin/kg (~60MB)\n   ./dist-bin/kg db stats \u003cvault\u003e\n   ```\n   Ship that one file to users — sqlite, jieba dict, and the viewer UI are all\n   embedded.\n2. **Bun** (runs TypeScript directly, no build step):\n   ```bash\n   bun packages/kg/src/cli.ts \u003ccommand\u003e ...\n   ```\n3. **Node ≥ 22.5** (npm ecosystem; on 22.x add `--experimental-sqlite`):\n   ```bash\n   pnpm install \u0026\u0026 pnpm build      # tsc → packages/kg/dist\n   node packages/kg/dist/cli.js \u003ccommand\u003e ...\n   ```\n\nThe sqlite layer auto-selects `bun:sqlite` or `node:sqlite` at runtime; index\nfiles are interchangeable between the two.\n\nDev: `pnpm test` (vitest, node path) and `pnpm -C packages/kg test:bun`\n(bun path) run the same suite. After editing `packages/kg/viewer/`, run\n`pnpm -C packages/kg embed` to refresh the binary-embedded copies.\n\n## CLI\n\n```bash\nKG=\"bun packages/kg/src/cli.ts\"   # or node packages/kg/dist/cli.js, or dist-bin/kg\n\n# Phase 1 — pure files\n$KG scan \u003cvault\u003e [--scope knowledge]      # hash ledger: new/changed/deleted\n                                          # default scope: meta/kg/config.json, else all\n$KG pending \u003cvault\u003e                       # docs awaiting extraction\n$KG concept import \u003cvault\u003e \u003cjson|-\u003e      # merge L1 concepts (alias-dedup)\n$KG metadata import \u003cvault\u003e \u003cjson|-\u003e     # validate anchors + write L2\n$KG extract-structural \u003cvault\u003e \u003cpath\u003e --write   # deterministic links/[[wiki-links]]/arXiv\n$KG extract-structural \u003cvault\u003e --pending --write  # batch over all pending docs\n\n# Phase 2 — SQLite graph index (rebuildable)\n$KG db build \u003cvault\u003e\n$KG search \"\u003cquery\u003e\" \u003cvault\u003e              # jieba-tokenized FTS5\n$KG entity \u003cname\u003e \u003cvault\u003e                 # edges + anchors + source docs\n$KG neighbors \u003cname\u003e \u003cvault\u003e --depth 2\n$KG paths \u003ca\u003e \u003cb\u003e \u003cvault\u003e\n$KG export \u003cvault\u003e --method deterministic\n\n# Agent QA (no server needed)\n$KG qa \"\u003cquestion\u003e\" \u003cvault\u003e               # entities + shortest path + FTS hits\n$KG locate \u003chash\u003e \"\u003cquote\u003e\" \u003cvault\u003e       # quote → line number\n$KG doc-info \u003chash\u003e \u003cvault\u003e               # hash → path + metadata + editor url\n\n# Phase 3 — local viewer (127.0.0.1 only)\n$KG serve \u003cvault\u003e --port 8765\n```\n\nAll commands print JSON. Exit codes: 0 ok · 1 usage/IO · 2 validation ·\n3 index missing · 4 index stale.\n\n## Viewer\n\n`kg serve` is one process serving both the static UI and the JSON API\n(same-origin fetch, no CORS). Pages: home / entity hub / document reading view\nwith `?cite=` quote highlighting / graph (ego focus + skeleton overview).\nNorth star: every claim links back to its verbatim source line.\n\nA future React viewer will live in `web/` and build into `packages/kg/viewer/`\n— the server contract doesn't change.\n\n## Claude Code plugin\n\nThis repo doubles as a Claude Code plugin (`.claude-plugin/plugin.json` +\n`skills/kg/SKILL.md`). The skill teaches the agent the extraction contract:\nthe LLM reads documents and emits metadata JSON; the CLI only does\ndeterministic file IO and anchor validation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencode%2Fkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbencode%2Fkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencode%2Fkg/lists"}