repo-nexus 0.9.1 → 0.9.4

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 (29) hide show
  1. package/lib/ai.sh +3 -3
  2. package/lib/plugins.sh +1 -1
  3. package/package.json +1 -1
  4. package/plugins/claude/plugin.yaml +1 -1
  5. package/plugins/codex/plugin.yaml +1 -1
  6. package/plugins/copilot/plugin.yaml +1 -1
  7. package/plugins/cursor/plugin.yaml +1 -1
  8. package/plugins/gemini/plugin.yaml +1 -1
  9. package/plugins/karpathy-llm/README.md +21 -28
  10. package/plugins/karpathy-llm/bin/ingest.sh +18 -128
  11. package/plugins/karpathy-llm/bin/lint.sh +34 -80
  12. package/plugins/karpathy-llm/hooks/_common.sh +4 -2
  13. package/plugins/karpathy-llm/hooks/after_sync.sh +5 -48
  14. package/plugins/karpathy-llm/hooks/post-sync.sh +13 -0
  15. package/plugins/karpathy-llm/instructions/rnex-scaffolding-meta-prompt.md +3 -3
  16. package/plugins/karpathy-llm/instructions/rnex-wiki-architecture.md +2 -2
  17. package/plugins/karpathy-llm/lib/agent_query_helpers.sh +14 -16
  18. package/plugins/karpathy-llm/lib/btree_helpers.sh +115 -207
  19. package/plugins/karpathy-llm/lib/config.sh +7 -20
  20. package/plugins/karpathy-llm/lib/graph_helpers.sh +91 -256
  21. package/plugins/karpathy-llm/lib/source_helpers.sh +292 -0
  22. package/plugins/karpathy-llm/plugin.yaml +1 -1
  23. package/plugins/karpathy-llm/rules/behavioral.md +5 -5
  24. package/plugins/karpathy-llm/skills/wiki-ingest.md +10 -12
  25. package/plugins/karpathy-llm/skills/wiki-lint.md +7 -7
  26. package/plugins/karpathy-llm/templates/_index.md +5 -7
  27. package/plugins/karpathy-llm/tests/test_plugin.sh +194 -164
  28. package/plugins/windsurf/plugin.yaml +1 -1
  29. package/plugins/karpathy-llm/templates/index.md +0 -20
package/lib/ai.sh CHANGED
@@ -441,9 +441,9 @@ render_ai_instructions() {
441
441
  printf 'Execute these steps in strict order:\n'
442
442
  _rai_n=1
443
443
  if [ "$_rai_kp" -eq 1 ]; then
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"
444
+ printf "1. **Step 1 — Query B-Tree Root Index & Graph**: Read \`%s/_index.md\` (compact B-Tree router <= 80 lines) to locate matching shard (\`repo-nexus*.md\` or \`repos-<member>*.md\`) or node identifiers.\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 source document needed without exhaustive reading.\n" "$_rai_wiki"
446
+ printf "3. **Step 3 — Read Authoritative Source Document**: Read only the 1–3 target source document(s) referenced in the shard. Do NOT browse raw intake sources%s or \`%s/\` blindly before completing Steps 1–2.\n" "${_rai_src_dirs:+ ($_rai_src_dirs)}" "$_rai_rd"
447
447
  _rai_n=4
448
448
  fi
449
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"
package/lib/plugins.sh CHANGED
@@ -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|.gitkeep) continue ;;
486
+ index.md|_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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-nexus",
3
- "version": "0.9.1",
3
+ "version": "0.9.4",
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.9.1
2
+ version: 0.9.4
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.9.1
2
+ version: 0.9.4
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.9.1
2
+ version: 0.9.4
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.9.1
2
+ version: 0.9.4
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.9.1
2
+ version: 0.9.4
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
@@ -22,17 +22,15 @@ Reference specification: [setup-karpathy-wiki.md](https://github.com/unoxen/ai-t
22
22
 
23
23
  ### 3. Zero-Dependency B-Tree & TSV Graph Architecture (`instructions/rnex-wiki-architecture.md`)
24
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).
25
+ * **Zero-Duplication In-Place Architecture:** Source files are indexed directly where they reside in the workspace (`README.md`, `docs/`, `RFC/`, `repos/<member>/...`). Zero redundant copies and zero symbolic links (`wiki/concepts/` and `wiki/repos/` are completely eradicated).
28
26
  * **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.
27
+ * **B-Tree Leaf Shards (`<wiki_dir>/_index/*.md`):** Lexicographically sorted catalogs (`repo-nexus.md`, `repo-nexus-<subscope>.md`, `repos-<member-repo>.md`). Automatically split into alphabetical sub-shards (`<shard>-a-m.md`, `<shard>-n-z.md`) when exceeding capacity thresholds.
30
28
  * **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`.
29
+ * **Audit Trail (`<wiki_dir>/_log.md`):** Shared append-only log recording ingest and lint operations across tracked wiki pages. Inspected via `tail -n 20 _log.md`.
32
30
 
33
31
  ### 4. Standardized Agent Skills (`skills/`)
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
+ * **`wiki-ingest.md` (User Skill: `rnex-karpathy-llm-wiki-ingest`):** Guides deterministic CLI in-place scanning, graph registration in `_graph/*.tsv`, B-Tree shard rebalancing, and direct AI enrichment of source documents.
33
+ * **`wiki-lint.md` (User Skill: `rnex-karpathy-llm-wiki-lint`):** Integrity audit protocol to validate paths, auto-heal legacy structures, assert zero symlinks, recompute graph edges, detect broken `[[wikilinks]]`, verify root line budget ($\le 80$ lines), purge legacy caches (`hot.md`, `index.md`, `concepts/`, `repos/`), and verify `LC_ALL=C` sort order.
36
34
 
37
35
  ---
38
36
 
@@ -49,7 +47,7 @@ Enabling the plugin (`rnex plugin enable karpathy-llm`) performs an exact, zero-
49
47
 
50
48
  ### Phase 2: Evolutionary Growth & Domain Specialization (Usage Phase)
51
49
  Once initialized, the workspace structure organically evolves according to actual domain needs and source materials:
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.
50
+ * **Source Ingestion (`rnex-karpathy-llm-wiki-ingest`)**: As raw source documents are deposited and ingested, authoritative documents are indexed directly in place, graph edges are registered in `_graph/*.tsv`, and B-Tree shards in `_index/*.md` and `_index.md` are automatically rebalanced.
53
51
  * **Customizable Guidelines**: Teams can tailor `rules/behavioral.md` and `instructions/rnex-wiki-architecture.md` for their specific conventions.
54
52
  * **Graph Maintenance (`rnex-karpathy-llm-wiki-lint`)**: The periodic lint workflow validates relation paths, verifies sort invariants, and flags broken wikilinks.
55
53
 
@@ -61,26 +59,21 @@ When enabled, the plugin scaffolds:
61
59
 
62
60
  ```text
63
61
  my-workspace/
64
- ├── docs/
65
- │ └── .gitkeep # Intake for unmodified source documents
62
+ ├── docs/ # Workspace documentation
63
+ │ └── .gitkeep
64
+ ├── repos/ # Member repositories (inspected in-place)
65
+ │ └── <member-repo>/
66
+ │ └── README.md
66
67
  ├── wiki/
67
68
  │ ├── _index.md # B-Tree Root Router (<= 80 lines)
68
69
  │ ├── _log.md # Ingestion & lint audit history
69
70
  │ ├── _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
71
+ │ │ ├── repo-nexus.md # (or repo-nexus-<subscope>.md, e.g. -a-m.md)
72
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
73
+ │ └── _graph/ # Sorted TSV Property Graph
74
+ │ ├── nodes.tsv
75
+ │ ├── edges_out.tsv
76
+ │ └── edges_in.tsv
84
77
  ├── .rnex/
85
78
  │ └── plugins/
86
79
  │ └── karpathy-llm/
@@ -90,21 +83,21 @@ my-workspace/
90
83
  │ ├── rules/
91
84
  │ │ └── behavioral.md # Cardinal principles & context engineering
92
85
  │ ├── skills/
93
- │ │ ├── wiki-ingest.md # 8-step decomposition & ingestion workflow
94
- │ │ └── wiki-lint.md # 10-step graph validation & maintenance workflow
86
+ │ │ ├── wiki-ingest.md # Deterministic in-place ingestion workflow
87
+ │ │ └── wiki-lint.md # Graph validation & B-tree rebalance workflow
95
88
  │ ├── bin/
96
89
  │ │ ├── ingest.sh # User-facing ingest command
97
90
  │ │ └── lint.sh # User-facing lint & migration command
98
91
  │ ├── lib/
99
92
  │ │ ├── config.sh # Plugin configuration loader
100
93
  │ │ ├── utils.sh # Pure slug and wikilink utilities
101
- │ │ ├── graph_helpers.sh # Adjacency graph compiler & ego traversal
94
+ │ │ ├── source_helpers.sh # In-place YAML source discovery & expansion
95
+ │ │ ├── graph_helpers.sh # Two-pass TSV property graph compiler
102
96
  │ │ ├── btree_helpers.sh # B-Tree shard compiler & rebalancer
103
97
  │ │ └── agent_query_helpers.sh# Internal O(log N) search and ego graph query
104
98
  │ └── templates/
105
99
  │ ├── _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
100
+ │ └── _log.md # Baseline audit log template
108
101
  └── rnex.yaml # Plugin configuration
109
102
  ```
110
103
 
@@ -3,13 +3,8 @@
3
3
  # =============================================================================
4
4
  # File: plugins/karpathy-llm/bin/ingest.sh
5
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.
6
+ # Single Responsibility: Ingest workspace source documentation directly in place
7
+ # into wiki/_graph/*.tsv and wiki/_index/*.md with zero symlinks.
13
8
  # =============================================================================
14
9
 
15
10
  set -e
@@ -21,6 +16,8 @@ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
21
16
  . "${PLUGIN_ROOT}/lib/config.sh"
22
17
  # shellcheck source=plugins/karpathy-llm/lib/utils.sh
23
18
  . "${PLUGIN_ROOT}/lib/utils.sh"
19
+ # shellcheck source=plugins/karpathy-llm/lib/source_helpers.sh
20
+ . "${PLUGIN_ROOT}/lib/source_helpers.sh"
24
21
  # shellcheck source=plugins/karpathy-llm/lib/graph_helpers.sh
25
22
  . "${PLUGIN_ROOT}/lib/graph_helpers.sh"
26
23
  # shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
@@ -28,96 +25,11 @@ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
28
25
  # shellcheck source=plugins/karpathy-llm/lib/agent_query_helpers.sh
29
26
  . "${PLUGIN_ROOT}/lib/agent_query_helpers.sh"
30
27
 
31
- load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}"
28
+ load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_ROOT:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}}"
32
29
 
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
30
  ensure_wiki_initialized
117
31
 
118
- # 2. Parse CLI arguments
119
32
  TARGET_FILE=""
120
- REPO_SCOPE=""
121
33
  QUIET=0
122
34
 
123
35
  while [ $# -gt 0 ]; do
@@ -131,7 +43,7 @@ while [ $# -gt 0 ]; do
131
43
  --repo|-r)
132
44
  shift
133
45
  [ $# -gt 0 ] || { printf 'Error [ingest]: Missing argument for --repo\n' >&2; exit 1; }
134
- REPO_SCOPE="$1"
46
+ # Repo scope is parsed into target manifest
135
47
  shift
136
48
  ;;
137
49
  --quiet|-q)
@@ -139,7 +51,7 @@ while [ $# -gt 0 ]; do
139
51
  shift
140
52
  ;;
141
53
  --help|-h)
142
- printf 'Usage: rnex plugin karpathy-llm ingest [<file_path>] [--file <path>] [--repo <name>] [--quiet]\n'
54
+ printf 'Usage: rnex plugin karpathy-llm ingest [<file_path>] [--file <path>] [--quiet]\n'
143
55
  exit 0
144
56
  ;;
145
57
  -*)
@@ -158,40 +70,18 @@ if [ -n "$TARGET_FILE" ]; then
158
70
  printf 'Error [ingest]: Expected a file path, but "%s" is a directory.\n' "$TARGET_FILE" >&2
159
71
  exit 1
160
72
  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"
73
+ if [ ! -f "$TARGET_FILE" ] || [ -L "$TARGET_FILE" ]; then
74
+ printf 'Error [ingest]: Target file not found or is a symlink: %s\n' "$TARGET_FILE" >&2
75
+ exit 1
76
+ fi
77
+ sync_wiki_indexes_and_graph "$TARGET_FILE"
78
+ append_wiki_log_entry "ingest" "Ingested single source file \`${TARGET_FILE}\` in place."
79
+ [ "$QUIET" = "1" ] || printf 'Successfully indexed %s into wiki.\n' "$TARGET_FILE"
165
80
  exit 0
166
81
  fi
167
82
 
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
83
+ # Full configured sources indexing
195
84
  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"
85
+ _total="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_NODES_TSV" 2>/dev/null || printf '0')"
86
+ append_wiki_log_entry "ingest" "Indexed ${_total} configured source files across workspace in place."
87
+ [ "$QUIET" = "1" ] || printf 'Completed wiki ingest (%s sources indexed in place).\n' "$_total"
@@ -3,11 +3,8 @@
3
3
  # =============================================================================
4
4
  # File: plugins/karpathy-llm/bin/lint.sh
5
5
  # Architectural Layer: Public Plugin CLI Command (lint)
6
- # Single Responsibility: Auto-heal legacy wiki directories (migrating legacy
7
- # overview/, entities/, and sources/ into concepts/ and repos/), rebuild and
8
- # verify B-Tree shards (_index/*.md) and TSV graph tables (_graph/*.tsv), and
9
- # validate graph edge symmetry and root index bounds.
10
- # Patterns Applied: Command Pattern, Linter / Verifier.
6
+ # Single Responsibility: Auto-heal wiki structure, remove legacy symlinks and
7
+ # directories, verify LC_ALL=C sort order, edge symmetry, and root bounds.
11
8
  # =============================================================================
12
9
 
13
10
  set -e
@@ -19,6 +16,8 @@ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
19
16
  . "${PLUGIN_ROOT}/lib/config.sh"
20
17
  # shellcheck source=plugins/karpathy-llm/lib/utils.sh
21
18
  . "${PLUGIN_ROOT}/lib/utils.sh"
19
+ # shellcheck source=plugins/karpathy-llm/lib/source_helpers.sh
20
+ . "${PLUGIN_ROOT}/lib/source_helpers.sh"
22
21
  # shellcheck source=plugins/karpathy-llm/lib/graph_helpers.sh
23
22
  . "${PLUGIN_ROOT}/lib/graph_helpers.sh"
24
23
  # shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
@@ -26,61 +25,11 @@ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
26
25
  # shellcheck source=plugins/karpathy-llm/lib/agent_query_helpers.sh
27
26
  . "${PLUGIN_ROOT}/lib/agent_query_helpers.sh"
28
27
 
29
- load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}"
30
-
31
- # -----------------------------------------------------------------------------
32
- # migrate_and_purge_legacy_wiki_artifacts
33
- # Summary: Migrates any Markdown files from legacy overview/, entities/, or
34
- # sources/ directories into concepts/ or repos/, and removes deprecated
35
- # files (hot.md, index.md, _index/overview*, _index/entities*, _index/sources*).
36
- # @returns: 0 on success.
37
- # @sideEffects: Moves legacy content files and deletes deprecated directories.
38
- # -----------------------------------------------------------------------------
39
- migrate_and_purge_legacy_wiki_artifacts() {
40
- # 1. Migrate legacy wiki/overview/*.md -> wiki/concepts/
41
- if [ -d "${RNEX_WIKI_ROOT}/overview" ]; then
42
- mkdir -p "$RNEX_WIKI_CONCEPTS_DIR"
43
- find "${RNEX_WIKI_ROOT}/overview" -type f -name '*.md' 2>/dev/null | while IFS= read -r _f; do
44
- [ -f "$_f" ] || continue
45
- mv "$_f" "${RNEX_WIKI_CONCEPTS_DIR}/$(basename "$_f")"
46
- done
47
- rm -rf "${RNEX_WIKI_ROOT}/overview"
48
- fi
49
-
50
- # 2. Migrate legacy wiki/entities/*.md -> wiki/repos/nexus/
51
- if [ -d "${RNEX_WIKI_ROOT}/entities" ]; then
52
- mkdir -p "${RNEX_WIKI_REPOS_DIR}/nexus"
53
- find "${RNEX_WIKI_ROOT}/entities" -type f -name '*.md' 2>/dev/null | while IFS= read -r _f; do
54
- [ -f "$_f" ] || continue
55
- mv "$_f" "${RNEX_WIKI_REPOS_DIR}/nexus/$(basename "$_f")"
56
- done
57
- rm -rf "${RNEX_WIKI_ROOT}/entities"
58
- fi
28
+ load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_ROOT:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}}"
59
29
 
60
- # 3. Migrate legacy wiki/sources/ -> wiki/repos/
61
- if [ -d "${RNEX_WIKI_ROOT}/sources" ]; then
62
- mkdir -p "${RNEX_WIKI_REPOS_DIR}/nexus"
63
- for _item in "${RNEX_WIKI_ROOT}/sources"/*; do
64
- [ -e "$_item" ] || continue
65
- if [ -d "$_item" ]; then
66
- _scope="$(basename "$_item")"
67
- mkdir -p "${RNEX_WIKI_REPOS_DIR}/${_scope}"
68
- cp -R "$_item"/. "${RNEX_WIKI_REPOS_DIR}/${_scope}/"
69
- elif [ -f "$_item" ]; then
70
- mv "$_item" "${RNEX_WIKI_REPOS_DIR}/nexus/$(basename "$_item")"
71
- fi
72
- done
73
- rm -rf "${RNEX_WIKI_ROOT}/sources"
74
- fi
75
-
76
- # 4. Purge deprecated hot.md and legacy root index.md
77
- rm -f "${RNEX_WIKI_ROOT}/hot.md" "${RNEX_WIKI_ROOT}/index.md"
78
- return 0
79
- }
80
-
81
- # 1. Parse arguments (--strict, --quiet, -q, etc.)
82
30
  QUIET=0
83
31
  STRICT=0
32
+
84
33
  while [ $# -gt 0 ]; do
85
34
  case "$1" in
86
35
  --strict)
@@ -104,14 +53,17 @@ while [ $# -gt 0 ]; do
104
53
  esac
105
54
  done
106
55
 
107
- # 2. Ensure structure & migrate legacy directories
108
56
  ensure_wiki_initialized
109
- migrate_and_purge_legacy_wiki_artifacts
110
-
111
- # 3. Rebuild and synchronize _graph/*.tsv, _index/*.md, and wiki/_index.md
57
+ purge_legacy_wiki_directories_and_symlinks
112
58
  sync_wiki_indexes_and_graph
113
59
 
114
- # 4. Verify LC_ALL=C sort invariants on all 3 TSV graph tables
60
+ # Invariant 1: Assert zero symlinks in wiki/
61
+ if [ -n "$(find "$RNEX_WIKI_ROOT" -type l 2>/dev/null)" ]; then
62
+ printf 'Error [lint]: Found forbidden symbolic links in wiki directory.\n' >&2
63
+ exit 1
64
+ fi
65
+
66
+ # Invariant 2: Verify LC_ALL=C sort order on TSV tables
115
67
  for _tsv in "$RNEX_WIKI_NODES_TSV" "$RNEX_WIKI_EDGES_OUT_TSV" "$RNEX_WIKI_EDGES_IN_TSV"; do
116
68
  if [ -f "$_tsv" ] && [ -s "$_tsv" ]; then
117
69
  if ! LC_ALL=C sort -c "$_tsv" 2>/dev/null; then
@@ -121,30 +73,32 @@ for _tsv in "$RNEX_WIKI_NODES_TSV" "$RNEX_WIKI_EDGES_OUT_TSV" "$RNEX_WIKI_EDGES_
121
73
  fi
122
74
  done
123
75
 
124
- # 5. Verify edge symmetry between edges_out.tsv and edges_in.tsv
125
- _out_cnt="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_EDGES_OUT_TSV")"
126
- _in_cnt="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_EDGES_IN_TSV")"
76
+ # Invariant 3: Verify edge symmetry
77
+ _out_cnt="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_EDGES_OUT_TSV" 2>/dev/null || printf '0')"
78
+ _in_cnt="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_EDGES_IN_TSV" 2>/dev/null || printf '0')"
127
79
  if [ "$_out_cnt" -ne "$_in_cnt" ]; then
128
80
  printf 'Error [lint]: Asymmetric edge tables (edges_out=%s, edges_in=%s)\n' "$_out_cnt" "$_in_cnt" >&2
129
81
  exit 1
130
82
  fi
131
83
 
132
- # 6. Verify root router line count bound
133
- _root_lines="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_INDEX_FILE")"
84
+ # Invariant 4: Verify root router bounds
85
+ _root_lines="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_INDEX_FILE" 2>/dev/null || printf '0')"
134
86
  if [ "$_root_lines" -gt "$RNEX_WIKI_BTREE_MAX_ROOT_LINES" ]; then
135
87
  printf 'Error [lint]: wiki/_index.md exceeds %s lines (%s lines)\n' \
136
88
  "$RNEX_WIKI_BTREE_MAX_ROOT_LINES" "$_root_lines" >&2
137
89
  exit 1
138
90
  fi
139
91
 
140
- # 7. Check for broken internal [[wikilinks]] and frontmatter sources if --strict is requested
92
+ # Invariant 5: If --strict is requested, detect broken wikilinks or missing frontmatter sources
141
93
  if [ "$STRICT" -eq 1 ]; then
142
- _broken_tmp="${RNEX_WIKI_GRAPH_DIR}/broken.tmp.$$"
94
+ _broken_tmp="${RNEX_WIKI_GRAPH_DIR}/.broken.tmp.$$"
143
95
  rm -f "$_broken_tmp"
144
96
 
145
- find "$RNEX_WIKI_CONCEPTS_DIR" "$RNEX_WIKI_REPOS_DIR" -type f -name '*.md' 2>/dev/null | while IFS= read -r _f; do
146
- [ -f "$_f" ] || continue
147
- _src_id="$(normalize_slug_id "$(basename "$_f" .md)")" || continue
97
+ # shellcheck disable=SC2094
98
+ while IFS="$(printf '\t')" read -r _src_id _src_shard _src_rel _src_title _src_sum; do
99
+ [ -n "$_src_rel" ] || continue
100
+ _src_abs="${RNEX_WORKSPACE_ROOT}/${_src_rel}"
101
+ [ -f "$_src_abs" ] || continue
148
102
 
149
103
  # Check frontmatter sources: [...]
150
104
  LC_ALL=C awk '
@@ -160,26 +114,26 @@ if [ "$STRICT" -eq 1 ]; then
160
114
  if (items[i] != "") print items[i]
161
115
  }
162
116
  }
163
- ' "$_f" | while IFS= read -r _s_path; do
117
+ ' "$_src_abs" < /dev/null | while IFS= read -r _s_path; do
164
118
  [ -n "$_s_path" ] || continue
165
119
  if [ ! -e "${RNEX_WORKSPACE_ROOT}/${_s_path}" ] && [ ! -e "$_s_path" ]; then
166
- printf 'Warning [lint]: Broken source reference "%s" in %s\n' "$_s_path" "$_f" >&2
120
+ printf 'Warning [lint]: Broken source reference "%s" in %s\n' "$_s_path" "$_src_rel" >&2
167
121
  echo "1" >> "$_broken_tmp"
168
122
  fi
169
123
  done
170
124
 
171
125
  # Check internal wikilinks
172
- extract_all_links_from_markdown "$_f" | while IFS= read -r _target; do
126
+ extract_all_links_from_markdown "$_src_abs" < /dev/null | while IFS= read -r _target; do
173
127
  [ -n "$_target" ] || continue
174
128
  if ! LC_ALL=C awk -F '\t' -v t="$_target" '
175
129
  $1 == t || $1 ~ ("-" t "$") { found=1; exit }
176
130
  END { exit !found }
177
- ' "$RNEX_WIKI_NODES_TSV"; then
178
- printf 'Warning [lint]: Broken link target [[%s]] referenced in %s\n' "$_target" "$_src_id" >&2
131
+ ' "$RNEX_WIKI_NODES_TSV" < /dev/null; then
132
+ printf 'Warning [lint]: Broken link target [[%s]] referenced in %s\n' "$_target" "$_src_rel" >&2
179
133
  echo "1" >> "$_broken_tmp"
180
134
  fi
181
135
  done
182
- done
136
+ done < "$RNEX_WIKI_NODES_TSV"
183
137
 
184
138
  if [ -f "$_broken_tmp" ]; then
185
139
  _broken_cnt="$(LC_ALL=C awk 'END { print NR+0 }' "$_broken_tmp")"
@@ -189,5 +143,5 @@ if [ "$STRICT" -eq 1 ]; then
189
143
  fi
190
144
  fi
191
145
 
192
- append_wiki_log_entry "lint" "Verified B-Tree shards (_index/) and symmetric graph tables (${_out_cnt} edges)."
193
- [ "$QUIET" = "1" ] || printf 'Wiki lint passed: %s edges verified, root _index.md is %s lines.\n' "$_out_cnt" "$_root_lines"
146
+ append_wiki_log_entry "lint" "Verified B-Tree shards and symmetric graph (${_out_cnt} edges, 0 symlinks)."
147
+ [ "$QUIET" = "1" ] || printf 'Wiki lint passed: %s edges verified, 0 symlinks, root is %s lines.\n' "$_out_cnt" "$_root_lines"
@@ -57,9 +57,13 @@ if [ -n "$_kl_plugin_lib" ]; then
57
57
  # shellcheck source=/dev/null
58
58
  . "$_kl_plugin_lib/utils.sh" 2>/dev/null || true
59
59
  # shellcheck source=/dev/null
60
+ . "$_kl_plugin_lib/source_helpers.sh" 2>/dev/null || true
61
+ # shellcheck source=/dev/null
60
62
  . "$_kl_plugin_lib/graph_helpers.sh" 2>/dev/null || true
61
63
  # shellcheck source=/dev/null
62
64
  . "$_kl_plugin_lib/btree_helpers.sh" 2>/dev/null || true
65
+ # shellcheck source=/dev/null
66
+ . "$_kl_plugin_lib/agent_query_helpers.sh" 2>/dev/null || true
63
67
  load_wiki_config_contract "$_root" 2>/dev/null || true
64
68
  fi
65
69
 
@@ -443,8 +447,6 @@ kl_ensure_wiki_files() {
443
447
  done
444
448
  if [ -n "$_kew_pdir" ] && [ -f "$_kew_pdir/templates/_index.md" ]; then
445
449
  cp "$_kew_pdir/templates/_index.md" "$_wiki_path/_index.md"
446
- elif [ -n "$_kew_pdir" ] && [ -f "$_kew_pdir/templates/index.md" ]; then
447
- cp "$_kew_pdir/templates/index.md" "$_wiki_path/_index.md"
448
450
  fi
449
451
  fi
450
452