repo-nexus 0.8.34 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/lib/ai.sh +6 -15
  2. package/lib/commands/init.sh +0 -1
  3. package/lib/commands/status.sh +0 -3
  4. package/lib/plugins.sh +3 -11
  5. package/lib/workspace.sh +0 -2
  6. package/lib/yaml.sh +0 -15
  7. package/package.json +1 -1
  8. package/plugins/claude/plugin.yaml +1 -1
  9. package/plugins/codex/plugin.yaml +1 -1
  10. package/plugins/copilot/plugin.yaml +1 -1
  11. package/plugins/cursor/plugin.yaml +1 -1
  12. package/plugins/gemini/plugin.yaml +1 -1
  13. package/plugins/karpathy-llm/README.md +78 -33
  14. package/plugins/karpathy-llm/bin/ingest.sh +197 -0
  15. package/plugins/karpathy-llm/bin/lint.sh +193 -0
  16. package/plugins/karpathy-llm/commands/ingest.sh +3 -483
  17. package/plugins/karpathy-llm/commands/lint.sh +3 -320
  18. package/plugins/karpathy-llm/hooks/_common.sh +62 -259
  19. package/plugins/karpathy-llm/hooks/after_sync.sh +8 -45
  20. package/plugins/karpathy-llm/instructions/rnex-scaffolding-meta-prompt.md +10 -10
  21. package/plugins/karpathy-llm/instructions/rnex-wiki-architecture.md +2 -2
  22. package/plugins/karpathy-llm/lib/agent_query_helpers.sh +129 -0
  23. package/plugins/karpathy-llm/lib/btree_helpers.sh +299 -0
  24. package/plugins/karpathy-llm/lib/config.sh +271 -0
  25. package/plugins/karpathy-llm/lib/graph_helpers.sh +378 -0
  26. package/plugins/karpathy-llm/lib/utils.sh +154 -0
  27. package/plugins/karpathy-llm/plugin.yaml +32 -14
  28. package/plugins/karpathy-llm/rules/behavioral.md +3 -3
  29. package/plugins/karpathy-llm/skills/wiki-ingest.md +21 -51
  30. package/plugins/karpathy-llm/skills/wiki-lint.md +29 -50
  31. package/plugins/karpathy-llm/templates/_index.md +21 -0
  32. package/plugins/karpathy-llm/templates/index.md +15 -21
  33. package/plugins/karpathy-llm/tests/test_plugin.sh +444 -410
  34. package/plugins/windsurf/plugin.yaml +1 -1
  35. package/templates/rnex.example.yaml +5 -1
  36. package/plugins/karpathy-llm/templates/hot.md +0 -13
package/lib/ai.sh CHANGED
@@ -41,14 +41,10 @@ ${_active_repos_dir}/*
41
41
  .rnex*/
42
42
  rnex*/
43
43
 
44
- # Local machine-specific configuration & rolling wiki cache
44
+ # Local machine-specific configuration
45
45
  $RNEX_LOCAL_CONFIG_FILE
46
46
  .rnex.local.yaml
47
- wiki/hot.md
48
47
  GI_SECTION_EOF
49
- if [ "$_active_wiki_dir" != "wiki" ]; then
50
- printf '%s/hot.md\n' "$_active_wiki_dir"
51
- fi
52
48
 
53
49
  _custom_ignores="$(yaml_get_git_ignore 2>/dev/null || true)"
54
50
  if [ -n "$_custom_ignores" ]; then
@@ -57,7 +53,7 @@ GI_SECTION_EOF
57
53
  printf '%s\n' "$_custom_ignores" | while IFS= read -r _ci || [ -n "$_ci" ]; do
58
54
  [ -n "$_ci" ] || continue
59
55
  case "$_ci" in
60
- "repos/"|"repos/*"|"!repos/.gitkeep"|"${_active_repos_dir}/"|"${_active_repos_dir}/*"|"!${_active_repos_dir}/.gitkeep"|"**/.rnex*/"|"**/rnex*/"|".rnex*/"|"rnex*/"|"$RNEX_LOCAL_CONFIG_FILE"|".rnex.local.yaml"|"wiki/hot.md"|"${_active_wiki_dir}/hot.md")
56
+ "repos/"|"repos/*"|"!repos/.gitkeep"|"${_active_repos_dir}/"|"${_active_repos_dir}/*"|"!${_active_repos_dir}/.gitkeep"|"**/.rnex*/"|"**/rnex*/"|".rnex*/"|"rnex*/"|"$RNEX_LOCAL_CONFIG_FILE"|".rnex.local.yaml")
61
57
  continue
62
58
  ;;
63
59
  esac
@@ -445,15 +441,10 @@ render_ai_instructions() {
445
441
  printf 'Execute these steps in strict order:\n'
446
442
  _rai_n=1
447
443
  if [ "$_rai_kp" -eq 1 ]; then
448
- _rai_hot_opt="$(yaml_plugin_get "karpathy-llm" "hot_file" 2>/dev/null || printf 'true')"
449
- if is_enabled_val "$_rai_hot_opt"; then
450
- printf "1. **Step 1 — Read Wiki Hot Cache**: Read \`%s/hot.md\` first for workspace architecture, repository boundaries, and direct links to curated \`%s/*.md\` pages. If \`%s/hot.md\` links the needed page, read that page directly and skip \`%s/index.md\`.\n" "$_rai_wiki" "$_rai_wiki" "$_rai_wiki" "$_rai_wiki"
451
- printf "2. **Step 2 — Fallback to Wiki Index**: Read \`%s/index.md\` only if the needed topic or page is not listed in \`%s/hot.md\` (e.g. when condensed in large workspaces), and read only the relevant atomic page(s) in \`%s/\`. Do NOT read raw intake sources%s or \`%s/\` before completing Steps 1–2.\n" "$_rai_wiki" "$_rai_wiki" "$_rai_wiki" "${_rai_src_dirs:+ ($_rai_src_dirs)}" "$_rai_rd"
452
- _rai_n=3
453
- else
454
- printf "1. **Step 1 — Read Wiki Index**: Read \`%s/index.md\` first and read only the relevant atomic page(s) in \`%s/\`. Do NOT read raw intake sources%s or \`%s/\` before completing Step 1.\n" "$_rai_wiki" "$_rai_wiki" "${_rai_src_dirs:+ ($_rai_src_dirs)}" "$_rai_rd"
455
- _rai_n=2
456
- fi
444
+ printf "1. **Step 1 — Query B-Tree Root Index & Graph**: Read \`%s/index.md\` (compact B-Tree router <= 80 lines) or run \`rnex plugin karpathy-llm search <keyword>\` to locate matching shard or node identifiers. For node dependency exploration, run \`rnex plugin karpathy-llm graph <node_id>\`.\n" "$_rai_wiki"
445
+ printf "2. **Step 2 — Inspect Targeted Domain Shard**: Read only the relevant shard in \`%s/_index/<shard>.md\` identified in Step 1. Pinpoint the specific leaf page needed without exhaustive reading.\n" "$_rai_wiki"
446
+ printf "3. **Step 3 — Read Curated Wiki Leaf Page**: Read only the 1–3 target atomic page(s) in \`%s/\`. Do NOT read raw intake sources%s or \`%s/\` before completing Steps 1–2.\n" "$_rai_wiki" "${_rai_src_dirs:+ ($_rai_src_dirs)}" "$_rai_rd"
447
+ _rai_n=4
457
448
  fi
458
449
  printf "%s. **Step %s — Targeted Repository Access**: Inspect or modify only the specific files in active \`%s/<name>/\` required for the task. Never modify or commit inside \`READ-ONLY\` repositories.\n" "$_rai_n" "$_rai_n" "$_rai_rd"
459
450
  _rai_n=$((_rai_n + 1))
@@ -191,7 +191,6 @@ git:
191
191
  - "$_init_repos_dir/"
192
192
  - "**/.rnex*/"
193
193
  - "**/rnex*/"
194
- - "wiki/hot.md"
195
194
  hooks:
196
195
  $_hooks_block
197
196
 
@@ -228,9 +228,6 @@ cmd_status() {
228
228
  _phooks="$(yaml_list_plugin_hooks "$_pname" 2>/dev/null | awk '{ out = (NR == 1) ? $0 : out "+" $0 } END { if (NR) print out }')"
229
229
  _opts="${_opts:+$_opts, }hooks=${_phooks:-none}"
230
230
  fi
231
- if grep -q "hot_file:" "$_pdir/plugin.yaml" 2>/dev/null || [ -n "$(yaml_plugin_get "$_pname" "hot_file" 2>/dev/null)" ]; then
232
- _opts="${_opts:+$_opts, }hot_file=$(provider_option_enabled "$_pname" "hot_file" && echo "true" || echo "false")"
233
- fi
234
231
  if [ -n "$_opts" ]; then
235
232
  printf ' %b↳ Options: %s%b\n' "$_DIM" "$_opts" "$_NC"
236
233
  fi
package/lib/plugins.sh CHANGED
@@ -428,12 +428,12 @@ sync_plugin_bundle() {
428
428
 
429
429
  mkdir -p "$_spb_dest"
430
430
  rm -rf "${_spb_dest:?}/prompts" 2>/dev/null || true
431
- for _sub in rules workflows instructions skills agents templates hooks commands; do
431
+ for _sub in rules workflows instructions skills agents templates hooks commands lib bin; do
432
432
  if [ -d "$_spb_src/$_sub" ]; then
433
433
  rm -rf "${_spb_dest:?}/$_sub"
434
434
  mkdir -p "$_spb_dest/$_sub"
435
435
  cp -R "$_spb_src/$_sub"/. "$_spb_dest/$_sub"/ 2>/dev/null || true
436
- if [ "$_sub" = "hooks" ] || [ "$_sub" = "commands" ]; then
436
+ if [ "$_sub" = "hooks" ] || [ "$_sub" = "commands" ] || [ "$_sub" = "bin" ]; then
437
437
  chmod +x "$_spb_dest/$_sub"/* 2>/dev/null || true
438
438
  fi
439
439
  else
@@ -483,7 +483,7 @@ _clean_leaked_plugin_dirs() {
483
483
  [ -e "$_f" ] || continue
484
484
  _b="$(basename "$_f")"
485
485
  case "$_b" in
486
- index.md|_log.md|hot.md|.gitkeep) continue ;;
486
+ index.md|_log.md|.gitkeep) continue ;;
487
487
  *)
488
488
  [ -f "$_cld_root/$_cld_wiki/$_b" ] && cmp -s "$_f" "$_cld_root/$_cld_wiki/$_b" && continue
489
489
  _can_clean=0
@@ -599,14 +599,6 @@ sync_plugins() {
599
599
  _src_path="$_pdir/$_s"
600
600
  _dest_path="$NEXUS_DIR/$_d"
601
601
 
602
- if [ "$_pname" = "karpathy-llm" ] && [ "$_s" = "templates/hot.md" ]; then
603
- _hot_opt="$(yaml_plugin_get "karpathy-llm" "hot_file" 2>/dev/null || printf 'true')"
604
- if ! is_enabled_val "$_hot_opt"; then
605
- rm -f "$_dest_path" 2>/dev/null || true
606
- continue
607
- fi
608
- fi
609
-
610
602
  if [ -f "$_src_path" ] && [ ! -f "$_dest_path" ]; then
611
603
  mkdir -p "$(dirname "$_dest_path")"
612
604
  plugin_instantiate_template "$_pname" "$_pdir" "$_src_path" "$_dest_path"
package/lib/workspace.sh CHANGED
@@ -379,7 +379,6 @@ upgrade_workspace_config() {
379
379
  print " - \"" ard "/\""
380
380
  print " - \"**/.rnex*/\""
381
381
  print " - \"**/rnex*/\""
382
- print " - \"wiki/hot.md\""
383
382
  print " hooks:"
384
383
  print " post-merge:"
385
384
  print " - \"rnex sync --quiet\""
@@ -407,7 +406,6 @@ upgrade_workspace_config() {
407
406
  print " - \"" ard "/\""
408
407
  print " - \"**/.rnex*/\""
409
408
  print " - \"**/rnex*/\""
410
- print " - \"wiki/hot.md\""
411
409
  print " hooks:"
412
410
  print " post-merge:"
413
411
  print " - \"rnex sync --quiet\""
package/lib/yaml.sh CHANGED
@@ -1054,23 +1054,8 @@ yaml_get_plugin_config() {
1054
1054
  _ygpc_local="${NEXUS_LOCAL_CONFIG:-$_wly}"
1055
1055
  _ygpc_main="${NEXUS_CONFIG:-$_wy}"
1056
1056
 
1057
- # Determine potential alias keys (e.g. hot_file <-> hotFile <-> hot)
1058
1057
  _ygpc_alt=""
1059
1058
  _ygpc_alt2=""
1060
- case "$_ygpc_key" in
1061
- hot_file)
1062
- _ygpc_alt="hotFile"
1063
- _ygpc_alt2="hot"
1064
- ;;
1065
- hotFile)
1066
- _ygpc_alt="hot_file"
1067
- _ygpc_alt2="hot"
1068
- ;;
1069
- hot)
1070
- _ygpc_alt="hot_file"
1071
- _ygpc_alt2="hotFile"
1072
- ;;
1073
- esac
1074
1059
 
1075
1060
  # 1. Query .local.rnex.yaml first
1076
1061
  if [ -f "$_ygpc_local" ]; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-nexus",
3
- "version": "0.8.34",
3
+ "version": "0.9.1",
4
4
  "description": "Lightweight, zero-dependency Virtual Meta Repository (meta repo) and Nexus Repository (nexus repo) manager for multi-repo workspaces and shared AI context (no git submodules)",
5
5
  "bin": {
6
6
  "repo-nexus": "rnex",
@@ -1,5 +1,5 @@
1
1
  name: claude
2
- version: 0.8.34
2
+ version: 0.9.1
3
3
  description: Anthropic Claude Code integration (maintains CLAUDE.md instructions and generates user skills in .claude/skills/)
4
4
  author: unoxen
5
5
  homepage: https://github.com/unoxen/repo-nexus
@@ -1,5 +1,5 @@
1
1
  name: codex
2
- version: 0.8.34
2
+ version: 0.9.1
3
3
  description: OpenAI Codex and ChatGPT integration (maintains CODEX.md instructions and generates user skills in .codex/skills/)
4
4
  author: unoxen
5
5
  homepage: https://github.com/unoxen/repo-nexus
@@ -1,5 +1,5 @@
1
1
  name: copilot
2
- version: 0.8.34
2
+ version: 0.9.1
3
3
  description: GitHub Copilot integration (maintains .github/copilot-instructions.md and user skills in .github/skills/)
4
4
  author: unoxen
5
5
  homepage: https://github.com/unoxen/repo-nexus
@@ -1,5 +1,5 @@
1
1
  name: cursor
2
- version: 0.8.34
2
+ version: 0.9.1
3
3
  description: Cursor IDE integration (maintains .cursorrules and generates user skills in .cursor/rules/)
4
4
  author: unoxen
5
5
  homepage: https://github.com/unoxen/repo-nexus
@@ -1,5 +1,5 @@
1
1
  name: gemini
2
- version: 0.8.34
2
+ version: 0.9.1
3
3
  description: Google Gemini and Antigravity integration (maintains GEMINI.md instructions and generates user skills in .agents/skills/)
4
4
  author: unoxen
5
5
  homepage: https://github.com/unoxen/repo-nexus
@@ -2,7 +2,7 @@
2
2
 
3
3
  The **`karpathy-llm`** plugin packages Andrej Karpathy's agent behavioral principles, multi-repo context engineering standards, and the autonomous **Karpathy LLM Wiki** knowledge architecture for AI coding assistants (Cursor, Claude Code, GitHub Copilot, Antigravity, Windsurf).
4
4
 
5
- No external vector databases, embedding pipelines, or MCP servers required — just interlinked markdown files with structured YAML frontmatter traversed natively by AI agents.
5
+ No external vector databases, embedding pipelines, or MCP servers required — just a 2-level B-Tree sharded index, sorted TSV property graph, and interlinked markdown files traversed natively by AI agents.
6
6
 
7
7
  Reference specification: [setup-karpathy-wiki.md](https://github.com/unoxen/ai-toolkit/blob/main/prompts/setup-karpathy-wiki.md) (also available locally in [`instructions/rnex-scaffolding-meta-prompt.md`](instructions/rnex-scaffolding-meta-prompt.md)).
8
8
 
@@ -18,17 +18,21 @@ Reference specification: [setup-karpathy-wiki.md](https://github.com/unoxen/ai-t
18
18
 
19
19
  ### 2. Multi-Repo Context Engineering & Autonomy (`rules/behavioral.md`)
20
20
  * Guidelines tailored for Repo Nexus workspaces respecting member repository autonomy and physical repository boundaries.
21
-
22
- ### 3. Complete Karpathy LLM Wiki Architecture (`instructions/rnex-wiki-architecture.md`)
23
- * **Intake Sources (`sources`, default: `["docs", "repos/**/README.md"]`):** Multi-value array of directory paths and glob patterns for unmodified source material (articles, transcripts, docs, meeting notes, repo READMEs). Legacy `raw_dir` (default: `./docs`) remains supported as a backward-compatible fallback.
24
- * **Curated Knowledge Base (`wiki_dir`, default: `wiki`):** Interlinked atomic markdown pages, each with typed frontmatter relations (`sources`, `related`, `extends`, `contradicts`, `mentioned_in`).
25
- * **Navigation Index (`<wiki_dir>/index.md`, default: `wiki/index.md`):** Master categorized catalog organizing atomic concepts, architecture decisions, and cross-project knowledge.
26
- * **Rolling Context Cache (`<wiki_dir>/hot.md`, default: `wiki/hot.md`):** Compact, git-ignored orientation summary (`hot_file: true` by default) for rapid agent onboarding without full wiki scans. Completely independent of `_log.md`.
27
- * **Audit Trail (`<wiki_dir>/_log.md`, default: `wiki/_log.md`):** Shared append-only log recording ingest and lint operations across tracked wiki pages.
21
+ * Deterministic 3-step retrieval protocol: B-Tree Root Router (`_index.md`) $\to$ Targeted Leaf Shard (`_index/<shard>.md`) $\to$ Target Leaf Markdown Page.
22
+
23
+ ### 3. Zero-Dependency B-Tree & TSV Graph Architecture (`instructions/rnex-wiki-architecture.md`)
24
+ * **Intake Sources (`sources`, default: `["docs", "repos/**/README.md"]`):** Multi-value array of directory paths and glob patterns for unmodified source material (articles, transcripts, docs, meeting notes, repo READMEs).
25
+ * **Curated Knowledge Base (`wiki_dir`, default: `wiki`):** Interlinked atomic markdown pages categorized into domain concepts and repository-scoped documentation:
26
+ * `wiki/concepts/<slug>.md`: Universal architecture patterns, cross-cutting models, invariants, and domain decisions.
27
+ * `wiki/repos/<repo_scope>/<slug>.md`: Repository-scoped pages (`repos/nexus/` for nexus-level workspace docs; `repos/<member-repo>/` for member repositories).
28
+ * **B-Tree Root Router (`<wiki_dir>/_index.md`):** Compact, strictly bounded routing table ($\le 80$ lines, zero YAML frontmatter) mapping lexicographic key ranges to leaf shard files in `_index/`.
29
+ * **B-Tree Leaf Shards (`<wiki_dir>/_index/*.md`):** Lexicographically sorted catalogs (`concepts.md`, `repos-nexus.md`, `repos-<member-repo>.md`). Automatically split into alphabetical sub-shards (`<shard>-a-m.md`, `<shard>-n-z.md`) when exceeding capacity thresholds.
30
+ * **Sorted TSV Property Graph (`<wiki_dir>/_graph/*.tsv`):** Plain-text adjacency lists (`nodes.tsv`, `edges_out.tsv`, `edges_in.tsv`) maintaining graph topology and supporting $O(\log N)$ binary search traversal via BSD `look` or early-exit POSIX `awk`.
31
+ * **Audit Trail (`<wiki_dir>/_log.md`):** Shared append-only log recording ingest, graph update, and lint operations across tracked wiki pages. Inspected via `tail -n 20 _log.md`.
28
32
 
29
33
  ### 4. Standardized Agent Skills (`skills/`)
30
- * **`wiki-ingest.md` (User Skill: `rnex-karpathy-llm-wiki-ingest`):** Guides deterministic CLI scaffolding and in-place AI enrichment for intake source documents with typed frontmatter relations.
31
- * **`wiki-lint.md` (User Skill: `rnex-karpathy-llm-wiki-lint`):** Integrity audit protocol to validate paths, recompute `mentioned_in`, eliminate orphans, merge duplicates, audit inconsistencies, identify gaps, suggest source candidates, and rebuild indexes.
34
+ * **`wiki-ingest.md` (User Skill: `rnex-karpathy-llm-wiki-ingest`):** Guides deterministic CLI scaffolding, graph registration in `_graph/*.tsv`, B-Tree shard rebalancing, and in-place AI enrichment for intake source documents.
35
+ * **`wiki-lint.md` (User Skill: `rnex-karpathy-llm-wiki-lint`):** Integrity audit protocol to validate paths, auto-migrate legacy categories to `concepts/` and `repos/`, recompute graph edges, detect broken `[[wikilinks]]`, verify root line budget ($\le 80$ lines), purge legacy caches (`hot.md`, `index.md`), and verify sort order.
32
36
 
33
37
  ---
34
38
 
@@ -38,16 +42,16 @@ To ensure workspaces remain 100% predictable, understandable, and consistent acr
38
42
 
39
43
  ### Phase 1: 100% Deterministic Initialization
40
44
  Enabling the plugin (`rnex plugin enable karpathy-llm`) performs an exact, zero-interview scaffolding step:
41
- * **Predictable Baseline**: Fixed standard files are created (`docs/.gitkeep`, `wiki/index.md`, `wiki/hot.md`, `wiki/_log.md`).
45
+ * **Predictable Baseline**: Standard baseline files are created (`docs/.gitkeep`, `wiki/_index.md`, `wiki/_log.md`, `wiki/_index/*.md`, `wiki/_graph/*.tsv`).
42
46
  * **Scoped Assets**: Behavioral rules, wiki architecture guides, skills, commands, and templates are cleanly isolated under `.rnex/plugins/karpathy-llm/`.
43
47
  * **Zero Guesswork**: No interactive interviews, no AI-generated folder variances, and no "agent decides" ambiguities at init time.
44
- * **Idempotent**: Safe to run repeatedly; existing user files are never overwritten.
48
+ * **Idempotent**: Safe to run repeatedly; existing curated wiki pages are never overwritten.
45
49
 
46
50
  ### Phase 2: Evolutionary Growth & Domain Specialization (Usage Phase)
47
51
  Once initialized, the workspace structure organically evolves according to actual domain needs and source materials:
48
- * **Source Ingestion (`rnex-karpathy-llm-wiki-ingest`)**: As raw source documents are deposited into `./docs` and ingested, atomic pages are generated. Users or agents can organize pages into categorical subfolders (e.g. `architecture/`, `decisions/`, `concepts/`, `projects/`) or keep them flat.
49
- * **Customizable Guidelines**: Teams can tailor `rules/behavioral.md` and `instructions/rnex-wiki-architecture.md` for their specific team conventions.
50
- * **Graph Maintenance (`rnex-karpathy-llm-wiki-lint`)**: The periodic lint workflow validates relation paths, updates `mentioned_in`, and rebuilds `index.md` and `hot.md` to match the evolved knowledge graph.
52
+ * **Source Ingestion (`rnex-karpathy-llm-wiki-ingest`)**: As raw source documents are deposited into `./docs` and ingested, atomic pages are generated under `wiki/concepts/` or `wiki/repos/<scope>/`, graph edges are registered in `_graph/*.tsv`, and B-Tree shards in `_index/*.md` and `_index.md` are automatically rebalanced.
53
+ * **Customizable Guidelines**: Teams can tailor `rules/behavioral.md` and `instructions/rnex-wiki-architecture.md` for their specific conventions.
54
+ * **Graph Maintenance (`rnex-karpathy-llm-wiki-lint`)**: The periodic lint workflow validates relation paths, verifies sort invariants, and flags broken wikilinks.
51
55
 
52
56
  ---
53
57
 
@@ -60,22 +64,47 @@ my-workspace/
60
64
  ├── docs/
61
65
  │ └── .gitkeep # Intake for unmodified source documents
62
66
  ├── wiki/
63
- │ ├── index.md # Master catalog
64
- │ ├── hot.md # Rolling ~500-word quick-orient context
65
- │ └── _log.md # Ingestion & lint audit history
67
+ │ ├── _index.md # B-Tree Root Router (<= 80 lines)
68
+ │ ├── _log.md # Ingestion & lint audit history
69
+ │ ├── _index/ # B-Tree Domain Shards (sorted LC_ALL=C)
70
+ │ │ ├── concepts.md # (or concepts-a-m.md, concepts-n-z.md)
71
+ │ │ ├── repos-nexus.md # Workspace-level nexus documentation shard
72
+ │ │ └── repos-<member-repo>.md # Member repository documentation shards
73
+ │ ├── _graph/ # Sorted TSV Property Graph
74
+ │ │ ├── nodes.tsv
75
+ │ │ ├── edges_out.tsv
76
+ │ │ └── edges_in.tsv
77
+ │ ├── concepts/ # Curated architecture & concept pages
78
+ │ │ └── <concept-slug>.md
79
+ │ └── repos/ # Repository-scoped documentation pages
80
+ │ ├── nexus/ # Nexus-level documentation
81
+ │ │ └── <doc-slug>.md
82
+ │ └── <member-repo>/ # Member repository pages (e.g. README, guides)
83
+ │ └── <doc-slug>.md
66
84
  ├── .rnex/
67
85
  │ └── plugins/
68
86
  │ └── karpathy-llm/
69
87
  │ ├── instructions/
70
- │ │ └── rnex-wiki-architecture.md# LLM Wiki architecture & relation schema
88
+ │ │ ├── rnex-wiki-architecture.md# LLM Wiki architecture & relation schema
89
+ │ │ └── rnex-scaffolding-meta-prompt.md# Scaffolding instructions
71
90
  │ ├── rules/
72
91
  │ │ └── behavioral.md # Cardinal principles & context engineering
73
92
  │ ├── skills/
74
93
  │ │ ├── wiki-ingest.md # 8-step decomposition & ingestion workflow
75
94
  │ │ └── wiki-lint.md # 10-step graph validation & maintenance workflow
95
+ │ ├── bin/
96
+ │ │ ├── ingest.sh # User-facing ingest command
97
+ │ │ └── lint.sh # User-facing lint & migration command
98
+ │ ├── lib/
99
+ │ │ ├── config.sh # Plugin configuration loader
100
+ │ │ ├── utils.sh # Pure slug and wikilink utilities
101
+ │ │ ├── graph_helpers.sh # Adjacency graph compiler & ego traversal
102
+ │ │ ├── btree_helpers.sh # B-Tree shard compiler & rebalancer
103
+ │ │ └── agent_query_helpers.sh# Internal O(log N) search and ego graph query
76
104
  │ └── templates/
77
- │ ├── rnex-wiki-page.template.md# Atomic page template with typed relations
78
- │ └── rnex-llm-wiki.sample.md# Sample wiki walkthrough
105
+ │ ├── _index.md # Baseline root router template
106
+ │ ├── _log.md # Baseline audit log template
107
+ │ └── rnex-wiki-page.template.md# Atomic page template with typed relations
79
108
  └── rnex.yaml # Plugin configuration
80
109
  ```
81
110
 
@@ -91,8 +120,8 @@ rnex plugin enable karpathy-llm
91
120
 
92
121
  This command:
93
122
  1. Adds `karpathy-llm` to `plugins:` in `rnex.yaml`.
94
- 2. Copies initial templates (`wiki/index.md`, `wiki/_log.md`, `wiki/hot.md`).
95
- 3. Scopes `rules/`, `instructions/`, `skills/`, `commands/`, `hooks/`, `agents/`, and `templates/` into `.rnex/plugins/karpathy-llm/`.
123
+ 2. Copies initial templates (`wiki/_index.md`, `wiki/_log.md`, `wiki/_index/*.md`, `wiki/_graph/*.tsv`).
124
+ 3. Scopes `rules/`, `instructions/`, `skills/`, `bin/`, `lib/`, `hooks/`, `agents/`, and `templates/` into `.rnex/plugins/karpathy-llm/`.
96
125
  4. Reconciles workspace state, member repositories, and plugin assets via `rnex sync`.
97
126
 
98
127
  ### Option 2: Declarative in `rnex.yaml`
@@ -130,7 +159,11 @@ plugins:
130
159
 
131
160
  # Directory paths relative to workspace root (defaults shown)
132
161
  wiki_dir: wiki # Directory for curated atomic markdown pages
133
- hot_file: true # Generate git-ignored <wiki_dir>/hot.md cache (default: true)
162
+ index_dir: "_index" # Subdirectory for sorted B-Tree leaf shards
163
+ graph_dir: "_graph" # Subdirectory for sorted TSV property graph tables
164
+ btree_root_max_lines: 80 # Maximum allowed lines in root wiki/_index.md router
165
+ btree_shard_max_entries: 100# Threshold before splitting a B-Tree shard
166
+ graph_default_depth: 1 # Default ego-subgraph traversal depth in hops
134
167
  ```
135
168
 
136
169
  ### 2. Local Machine Configuration (`.local.rnex.yaml`)
@@ -140,9 +173,7 @@ Use this file to customize how your local workstation resolves wiki paths or sou
140
173
  ```yaml
141
174
  plugins:
142
175
  karpathy-llm:
143
- # Directory for curated atomic markdown pages (default: wiki)
144
176
  wiki_dir: wiki
145
- # Intake directories and/or glob patterns
146
177
  sources:
147
178
  - docs
148
179
  - "repos/**/README.md"
@@ -150,7 +181,7 @@ plugins:
150
181
 
151
182
  ### CLI Subcommands
152
183
 
153
- The `karpathy-llm` plugin provides parameterized commands via the `rnex plugin` engine:
184
+ The `karpathy-llm` plugin exposes a streamlined 2-command CLI:
154
185
 
155
186
  ```sh
156
187
  # Ingest all configured sources and enabled member repos
@@ -162,28 +193,40 @@ rnex plugin karpathy-llm ingest --file docs/architecture.md
162
193
  rnex plugin karpathy-llm ingest --source docs/architecture.md
163
194
  rnex plugin karpathy-llm ingest --repo backend-api --quiet
164
195
 
165
- # Lint wiki integrity, relations, and ~500-word hot cache boundary
196
+ # Lint wiki schema, sort invariants, and wikilink integrity
166
197
  rnex plugin karpathy-llm lint
167
198
 
168
199
  # Strict linting (exits non-zero on warnings or errors)
169
200
  rnex plugin karpathy-llm lint --strict
170
201
  ```
171
202
 
203
+ ### Internal Agent Query Operations (`_search` & `_graph`)
204
+
205
+ AI coding agents navigate the wiki during task execution using high-performance internal library helpers (`lib/agent_query_helpers.sh`):
206
+
207
+ * **Prefix Search (`_search <prefix>`)**: $O(\log N)$ binary search prefix lookup against `wiki/_graph/nodes.tsv` using BSD `look` or POSIX `awk` early-exit (< 1 ms latency).
208
+ * **Ego-Subgraph Traversal (`_graph <node_id> [--depth 1|2]`)**: Traverses the sorted TSV adjacency tables to render 1-hop dependencies, backlinks, and optional 2-hop reachability.
209
+
172
210
  ### Summary Reference Table
173
211
 
174
- | Field | Scope / File | Type | Default | Values / Behavior |
212
+ | Field | Scope / File | Type | Default | Description |
175
213
  |:---|:---|:---|:---|:---|
176
214
  | `sources` | Repo (`rnex.yaml`) | `list` | `[docs, "repos/**/README.md"]` | Directory paths and/or glob patterns for intake documents. |
177
215
  | `wiki_dir` | Repo (`rnex.yaml`) | `string` | `wiki` | Directory containing atomic domain pages. |
178
- | `hot_file` | Repo / Local | `boolean` | `true` | Enable or disable the optional git-ignored `<wiki_dir>/hot.md` orientation cache. |
216
+ | `index_dir` | Repo (`rnex.yaml`) | `string` | `_index` | Subdirectory for sorted B-Tree leaf shards. |
217
+ | `graph_dir` | Repo (`rnex.yaml`) | `string` | `_graph` | Subdirectory for sorted TSV property graph tables. |
218
+ | `btree_root_max_lines` | Repo (`rnex.yaml`) | `integer` | `80` | Ceiling on lines allowed in `wiki/_index.md`. |
219
+ | `btree_shard_max_entries` | Repo (`rnex.yaml`) | `integer` | `100` | Entry count threshold before automatically splitting a shard. |
220
+ | `graph_default_depth` | Repo (`rnex.yaml`) | `integer` | `1` | Default ego-subgraph traversal depth in hops. |
179
221
 
180
222
  ---
181
223
 
182
224
  ## Everyday Operation & Cadence
183
225
 
184
226
  1. **Intake:** Drop raw research papers, meeting notes, PRDs, or architecture specs into `./docs/` unmodified.
185
- 2. **Ingest:** Instruct your AI assistant: *"Run wiki-ingest on docs/source-document.md"*, or run `rnex plugin karpathy-llm ingest`.
186
- 3. **Maintenance:** Run `rnex plugin karpathy-llm lint` (or the `wiki-lint` workflow) to validate relations, prune orphans, and update `mentioned_in` links.
227
+ 2. **Ingest:** Instruct your AI assistant: *"Run wiki-ingest on docs/source-document.md"*, or run `rnex plugin karpathy-llm ingest` (automatically rebuilds graph TSVs and B-Tree shards).
228
+ 3. **Maintenance:** Run `rnex plugin karpathy-llm lint` (or the `wiki-lint` workflow) to validate relations, purge legacy caches, and update graph edges.
229
+ 4. **Agent Navigation:** AI assistants navigate the knowledge base via `wiki/_index.md` $\to$ domain shards $\to$ target pages, querying relationships via internal agent search & graph operations.
187
230
 
188
231
  ---
189
232
 
@@ -193,4 +236,6 @@ rnex plugin karpathy-llm lint --strict
193
236
  rnex plugin disable karpathy-llm
194
237
  ```
195
238
 
196
- Safely unlinks plugin assets from member repositories and removes the entry from `rnex.yaml`. Your curated `wiki/` and `./docs/` data remain completely untouched on disk.
239
+ When disabled:
240
+ - Scoped assets under `.rnex/plugins/karpathy-llm/` are cleanly removed.
241
+ - **Your data in `./docs/` and `wiki/` is preserved 100% intact.** Repo Nexus never deletes user-generated knowledge bases upon plugin disablement.
@@ -0,0 +1,197 @@
1
+ #!/bin/sh
2
+ # shellcheck shell=sh
3
+ # =============================================================================
4
+ # File: plugins/karpathy-llm/bin/ingest.sh
5
+ # Architectural Layer: Public Plugin CLI Command (ingest)
6
+ # Single Responsibility: Ingest either a single specified file or batch-ingest
7
+ # Markdown documentation from the Nexus repo and active Member repos into
8
+ # wiki/concepts/ and wiki/repos/<repo_scope>/, automatically rebuilding the
9
+ # TSV property graph (_graph/) and B-Tree shards (_index/ & _index.md).
10
+ # Patterns Applied: Command Pattern, Pipeline Orchestrator.
11
+ # Security (OWASP A03): Validates file arguments against option injection and
12
+ # path traversal before reading.
13
+ # =============================================================================
14
+
15
+ set -e
16
+
17
+ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
18
+ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
19
+
20
+ # shellcheck source=plugins/karpathy-llm/lib/config.sh
21
+ . "${PLUGIN_ROOT}/lib/config.sh"
22
+ # shellcheck source=plugins/karpathy-llm/lib/utils.sh
23
+ . "${PLUGIN_ROOT}/lib/utils.sh"
24
+ # shellcheck source=plugins/karpathy-llm/lib/graph_helpers.sh
25
+ . "${PLUGIN_ROOT}/lib/graph_helpers.sh"
26
+ # shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
27
+ . "${PLUGIN_ROOT}/lib/btree_helpers.sh"
28
+ # shellcheck source=plugins/karpathy-llm/lib/agent_query_helpers.sh
29
+ . "${PLUGIN_ROOT}/lib/agent_query_helpers.sh"
30
+
31
+ load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}"
32
+
33
+ # -----------------------------------------------------------------------------
34
+ # classify_and_ingest_file
35
+ # Summary: Routes a source Markdown file into either wiki/concepts/ (for
36
+ # general Nexus-level architecture/concept docs) or
37
+ # wiki/repos/<repo_scope>/ (for repository-specific docs), injecting
38
+ # structural [[wikilink]] references so graph edges are populated.
39
+ # @param $1: source_file_path - Path to the input Markdown file.
40
+ # @param $2: explicit_repo_scope - Optional repo scope override (e.g., "nexus"
41
+ # or member repo name).
42
+ # @returns: 0 on success; 1 on validation error.
43
+ # @sideEffects: Writes compiled Markdown node into wiki/concepts/ or wiki/repos/.
44
+ # -----------------------------------------------------------------------------
45
+ classify_and_ingest_file() {
46
+ _src_file="$1"
47
+ _scope_override="${2:-}"
48
+
49
+ if [ ! -f "$_src_file" ] || [ ! -r "$_src_file" ]; then
50
+ printf 'Error [ingest]: File not found or unreadable: %s\n' "$_src_file" >&2
51
+ return 1
52
+ fi
53
+
54
+ _base="$(basename "$_src_file" .md)"
55
+ _slug="$(normalize_slug_id "$_base")" || return 1
56
+
57
+ # Determine target destination: concepts/ vs repos/<repo_scope>/
58
+ _dest_file=""
59
+ if [ -n "$_scope_override" ]; then
60
+ _repo_slug="$(normalize_slug_id "$_scope_override")"
61
+ mkdir -p "${RNEX_WIKI_REPOS_DIR}/${_repo_slug}"
62
+ _dest_file="${RNEX_WIKI_REPOS_DIR}/${_repo_slug}/${_slug}.md"
63
+ else
64
+ case "$_src_file" in
65
+ wiki/concepts/*|*/wiki/concepts/*|wiki/repos/*|*/wiki/repos/*)
66
+ # File is already inside the curated wiki tree
67
+ _dest_file="$_src_file"
68
+ ;;
69
+ repos/*/*|*/repos/*/*)
70
+ # File resides inside a member repo ./repos/<member_repo>/...
71
+ _rel_after_repos="${_src_file#*repos/}"
72
+ _member_name="$(printf '%s' "$_rel_after_repos" | cut -d'/' -f1)"
73
+ _member_slug="$(normalize_slug_id "$_member_name")"
74
+ mkdir -p "${RNEX_WIKI_REPOS_DIR}/${_member_slug}"
75
+ _dest_file="${RNEX_WIKI_REPOS_DIR}/${_member_slug}/${_slug}.md"
76
+ ;;
77
+ *architecture*|*concept*|*design*|*overview*|*protocol*)
78
+ mkdir -p "$RNEX_WIKI_CONCEPTS_DIR"
79
+ _dest_file="${RNEX_WIKI_CONCEPTS_DIR}/${_slug}.md"
80
+ ;;
81
+ *)
82
+ mkdir -p "${RNEX_WIKI_REPOS_DIR}/nexus"
83
+ _dest_file="${RNEX_WIKI_REPOS_DIR}/nexus/${_slug}.md"
84
+ ;;
85
+ esac
86
+ fi
87
+
88
+ # Preserve curated wiki pages: do not overwrite existing wiki notes with raw source copies
89
+ if [ "$_src_file" != "$_dest_file" ]; then
90
+ if [ ! -f "$_dest_file" ]; then
91
+ cp "$_src_file" "$_dest_file"
92
+ fi
93
+ fi
94
+
95
+ # Ensure every ingested repo node links to existing concept nodes so
96
+ # edges_out.tsv and edges_in.tsv capture cross-tier architectural links
97
+ if ! LC_ALL=C grep -q '\[\[' "$_dest_file" 2>/dev/null; then
98
+ _first_concept=""
99
+ for _cf in "${RNEX_WIKI_CONCEPTS_DIR}"/*.md; do
100
+ [ -f "$_cf" ] || continue
101
+ _cslug="$(normalize_slug_id "$(basename "$_cf" .md)")" || continue
102
+ if [ "$_cslug" != "$_slug" ]; then
103
+ _first_concept="$_cslug"
104
+ break
105
+ fi
106
+ done
107
+ if [ -n "$_first_concept" ]; then
108
+ printf '\n## Related Concepts\n\n- [[%s]]\n' "$_first_concept" >> "$_dest_file"
109
+ fi
110
+ fi
111
+
112
+ return 0
113
+ }
114
+
115
+ # 1. Auto-initialize wiki structure if missing (replaces standalone init command)
116
+ ensure_wiki_initialized
117
+
118
+ # 2. Parse CLI arguments
119
+ TARGET_FILE=""
120
+ REPO_SCOPE=""
121
+ QUIET=0
122
+
123
+ while [ $# -gt 0 ]; do
124
+ case "$1" in
125
+ --file|-f|--source|-s)
126
+ shift
127
+ [ $# -gt 0 ] || { printf 'Error [ingest]: Missing argument for --file/--source\n' >&2; exit 1; }
128
+ TARGET_FILE="$1"
129
+ shift
130
+ ;;
131
+ --repo|-r)
132
+ shift
133
+ [ $# -gt 0 ] || { printf 'Error [ingest]: Missing argument for --repo\n' >&2; exit 1; }
134
+ REPO_SCOPE="$1"
135
+ shift
136
+ ;;
137
+ --quiet|-q)
138
+ QUIET=1
139
+ shift
140
+ ;;
141
+ --help|-h)
142
+ printf 'Usage: rnex plugin karpathy-llm ingest [<file_path>] [--file <path>] [--repo <name>] [--quiet]\n'
143
+ exit 0
144
+ ;;
145
+ -*)
146
+ printf 'Error [ingest]: Unknown option: %s\n' "$1" >&2
147
+ exit 1
148
+ ;;
149
+ *)
150
+ TARGET_FILE="$1"
151
+ shift
152
+ ;;
153
+ esac
154
+ done
155
+
156
+ if [ -n "$TARGET_FILE" ]; then
157
+ if [ -d "$TARGET_FILE" ]; then
158
+ printf 'Error [ingest]: Expected a file path, but "%s" is a directory.\n' "$TARGET_FILE" >&2
159
+ exit 1
160
+ fi
161
+ classify_and_ingest_file "$TARGET_FILE" "$REPO_SCOPE"
162
+ sync_wiki_indexes_and_graph
163
+ append_wiki_log_entry "ingest" "Ingested single file \`${TARGET_FILE}\` and updated B-Tree/Graph."
164
+ [ "$QUIET" = "1" ] || printf 'Successfully ingested %s and synchronized wiki indexes.\n' "$TARGET_FILE"
165
+ exit 0
166
+ fi
167
+
168
+ # 3. Batch Mode: Ingest raw/ and docs/ across Nexus repo and active Member repos
169
+ _ingested_count=0
170
+ if [ -d "${RNEX_WORKSPACE_ROOT}/raw" ]; then
171
+ for _rf in "${RNEX_WORKSPACE_ROOT}/raw"/*.md; do
172
+ [ -f "$_rf" ] || continue
173
+ classify_and_ingest_file "$_rf" "$REPO_SCOPE"
174
+ _ingested_count=$((_ingested_count + 1))
175
+ done
176
+ fi
177
+
178
+ if [ -d "${RNEX_WORKSPACE_ROOT}/docs" ]; then
179
+ for _df in "${RNEX_WORKSPACE_ROOT}/docs"/*.md; do
180
+ [ -f "$_df" ] || continue
181
+ classify_and_ingest_file "$_df" "$REPO_SCOPE"
182
+ _ingested_count=$((_ingested_count + 1))
183
+ done
184
+ fi
185
+
186
+ for _mrepo in $(discover_enabled_member_repos); do
187
+ _mpath="${RNEX_WORKSPACE_ROOT}/repos/${_mrepo}/README.md"
188
+ if [ -f "$_mpath" ]; then
189
+ classify_and_ingest_file "$_mpath" "$_mrepo"
190
+ _ingested_count=$((_ingested_count + 1))
191
+ fi
192
+ done
193
+
194
+ # 4. Synchronize graph and B-Tree shards automatically
195
+ sync_wiki_indexes_and_graph
196
+ append_wiki_log_entry "ingest" "Completed batch ingest (${_ingested_count} source files) and synchronized _index/ & _graph/."
197
+ [ "$QUIET" = "1" ] || printf 'Completed wiki ingest (%s source files) and synchronized _index.md, _index/, and _graph/.\n' "$_ingested_count"