repo-nexus 0.9.0 → 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.
- package/lib/ai.sh +3 -3
- package/lib/plugins.sh +1 -1
- package/package.json +2 -2
- package/plugins/claude/plugin.yaml +1 -1
- package/plugins/codex/plugin.yaml +1 -1
- package/plugins/copilot/plugin.yaml +1 -1
- package/plugins/cursor/plugin.yaml +1 -1
- package/plugins/gemini/plugin.yaml +1 -1
- package/plugins/karpathy-llm/README.md +48 -45
- package/plugins/karpathy-llm/bin/ingest.sh +85 -2
- package/plugins/karpathy-llm/bin/lint.sh +145 -2
- package/plugins/karpathy-llm/commands/ingest.sh +3 -461
- package/plugins/karpathy-llm/commands/lint.sh +3 -396
- package/plugins/karpathy-llm/hooks/_common.sh +7 -3
- package/plugins/karpathy-llm/hooks/after_sync.sh +5 -48
- package/plugins/karpathy-llm/hooks/post-sync.sh +13 -0
- package/plugins/karpathy-llm/instructions/rnex-scaffolding-meta-prompt.md +3 -3
- package/plugins/karpathy-llm/instructions/rnex-wiki-architecture.md +2 -2
- package/plugins/karpathy-llm/lib/agent_query_helpers.sh +127 -0
- package/plugins/karpathy-llm/lib/btree_helpers.sh +163 -226
- package/plugins/karpathy-llm/lib/config.sh +224 -103
- package/plugins/karpathy-llm/lib/graph_helpers.sh +149 -145
- package/plugins/karpathy-llm/lib/source_helpers.sh +292 -0
- package/plugins/karpathy-llm/lib/utils.sh +74 -65
- package/plugins/karpathy-llm/plugin.yaml +26 -19
- package/plugins/karpathy-llm/rules/behavioral.md +5 -5
- package/plugins/karpathy-llm/skills/wiki-ingest.md +20 -46
- package/plugins/karpathy-llm/skills/wiki-lint.md +29 -48
- package/plugins/karpathy-llm/templates/_index.md +19 -0
- package/plugins/karpathy-llm/tests/test_plugin.sh +444 -494
- package/plugins/windsurf/plugin.yaml +1 -1
- package/plugins/karpathy-llm/bin/graph.sh +0 -4
- package/plugins/karpathy-llm/bin/index.sh +0 -4
- package/plugins/karpathy-llm/bin/init.sh +0 -4
- package/plugins/karpathy-llm/bin/search.sh +0 -4
- package/plugins/karpathy-llm/commands/graph.sh +0 -91
- package/plugins/karpathy-llm/commands/index.sh +0 -205
- package/plugins/karpathy-llm/commands/init.sh +0 -114
- package/plugins/karpathy-llm/commands/search.sh +0 -96
- 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/
|
|
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
|
|
446
|
-
printf "3. **Step 3 — Read
|
|
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.
|
|
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",
|
|
@@ -64,4 +64,4 @@
|
|
|
64
64
|
"esbuild": "^0.25.0",
|
|
65
65
|
"vite": "^6.4.4"
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
@@ -18,19 +18,19 @@ 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
|
-
* Deterministic 3-step retrieval protocol: B-Tree Root Router (`
|
|
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
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
|
-
* **
|
|
26
|
-
* **B-Tree Root Router (`<wiki_dir>/
|
|
27
|
-
* **B-Tree Leaf Shards (`<wiki_dir>/_index/*.md`):** Lexicographically sorted catalogs (`
|
|
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).
|
|
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/`.
|
|
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.
|
|
28
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`.
|
|
29
|
-
* **Audit Trail (`<wiki_dir>/_log.md`):** Shared append-only log recording ingest
|
|
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`.
|
|
30
30
|
|
|
31
31
|
### 4. Standardized Agent Skills (`skills/`)
|
|
32
|
-
* **`wiki-ingest.md` (User Skill: `rnex-karpathy-llm-wiki-ingest`):** Guides deterministic CLI
|
|
33
|
-
* **`wiki-lint.md` (User Skill: `rnex-karpathy-llm-wiki-lint`):** Integrity audit protocol to validate paths, recompute graph edges, detect broken `[[wikilinks]]`, verify root line budget ($\le 80$ lines), purge legacy caches, 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.
|
|
34
34
|
|
|
35
35
|
---
|
|
36
36
|
|
|
@@ -40,14 +40,14 @@ To ensure workspaces remain 100% predictable, understandable, and consistent acr
|
|
|
40
40
|
|
|
41
41
|
### Phase 1: 100% Deterministic Initialization
|
|
42
42
|
Enabling the plugin (`rnex plugin enable karpathy-llm`) performs an exact, zero-interview scaffolding step:
|
|
43
|
-
* **Predictable Baseline**: Standard baseline files are created (`docs/.gitkeep`, `wiki/
|
|
43
|
+
* **Predictable Baseline**: Standard baseline files are created (`docs/.gitkeep`, `wiki/_index.md`, `wiki/_log.md`, `wiki/_index/*.md`, `wiki/_graph/*.tsv`).
|
|
44
44
|
* **Scoped Assets**: Behavioral rules, wiki architecture guides, skills, commands, and templates are cleanly isolated under `.rnex/plugins/karpathy-llm/`.
|
|
45
45
|
* **Zero Guesswork**: No interactive interviews, no AI-generated folder variances, and no "agent decides" ambiguities at init time.
|
|
46
46
|
* **Idempotent**: Safe to run repeatedly; existing curated wiki pages are never overwritten.
|
|
47
47
|
|
|
48
48
|
### Phase 2: Evolutionary Growth & Domain Specialization (Usage Phase)
|
|
49
49
|
Once initialized, the workspace structure organically evolves according to actual domain needs and source materials:
|
|
50
|
-
* **Source Ingestion (`rnex-karpathy-llm-wiki-ingest`)**: As raw source documents are deposited
|
|
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.
|
|
51
51
|
* **Customizable Guidelines**: Teams can tailor `rules/behavioral.md` and `instructions/rnex-wiki-architecture.md` for their specific conventions.
|
|
52
52
|
* **Graph Maintenance (`rnex-karpathy-llm-wiki-lint`)**: The periodic lint workflow validates relation paths, verifies sort invariants, and flags broken wikilinks.
|
|
53
53
|
|
|
@@ -59,16 +59,17 @@ When enabled, the plugin scaffolds:
|
|
|
59
59
|
|
|
60
60
|
```text
|
|
61
61
|
my-workspace/
|
|
62
|
-
├── docs/
|
|
63
|
-
│ └── .gitkeep
|
|
62
|
+
├── docs/ # Workspace documentation
|
|
63
|
+
│ └── .gitkeep
|
|
64
|
+
├── repos/ # Member repositories (inspected in-place)
|
|
65
|
+
│ └── <member-repo>/
|
|
66
|
+
│ └── README.md
|
|
64
67
|
├── wiki/
|
|
65
|
-
│ ├──
|
|
68
|
+
│ ├── _index.md # B-Tree Root Router (<= 80 lines)
|
|
66
69
|
│ ├── _log.md # Ingestion & lint audit history
|
|
67
70
|
│ ├── _index/ # B-Tree Domain Shards (sorted LC_ALL=C)
|
|
68
|
-
│ │ ├──
|
|
69
|
-
│ │
|
|
70
|
-
│ │ ├── entities.md
|
|
71
|
-
│ │ └── sources.md
|
|
71
|
+
│ │ ├── repo-nexus.md # (or repo-nexus-<subscope>.md, e.g. -a-m.md)
|
|
72
|
+
│ │ └── repos-<member-repo>.md # Member repository documentation shards
|
|
72
73
|
│ └── _graph/ # Sorted TSV Property Graph
|
|
73
74
|
│ ├── nodes.tsv
|
|
74
75
|
│ ├── edges_out.tsv
|
|
@@ -77,22 +78,26 @@ my-workspace/
|
|
|
77
78
|
│ └── plugins/
|
|
78
79
|
│ └── karpathy-llm/
|
|
79
80
|
│ ├── instructions/
|
|
80
|
-
│ │
|
|
81
|
+
│ │ ├── rnex-wiki-architecture.md# LLM Wiki architecture & relation schema
|
|
82
|
+
│ │ └── rnex-scaffolding-meta-prompt.md# Scaffolding instructions
|
|
81
83
|
│ ├── rules/
|
|
82
84
|
│ │ └── behavioral.md # Cardinal principles & context engineering
|
|
83
85
|
│ ├── skills/
|
|
84
|
-
│ │ ├── wiki-ingest.md #
|
|
85
|
-
│ │ └── wiki-lint.md #
|
|
86
|
-
│ ├──
|
|
87
|
-
│ │ ├──
|
|
88
|
-
│ │
|
|
89
|
-
│
|
|
90
|
-
│ │ ├──
|
|
91
|
-
│ │ ├──
|
|
92
|
-
│ │
|
|
86
|
+
│ │ ├── wiki-ingest.md # Deterministic in-place ingestion workflow
|
|
87
|
+
│ │ └── wiki-lint.md # Graph validation & B-tree rebalance workflow
|
|
88
|
+
│ ├── bin/
|
|
89
|
+
│ │ ├── ingest.sh # User-facing ingest command
|
|
90
|
+
│ │ └── lint.sh # User-facing lint & migration command
|
|
91
|
+
│ ├── lib/
|
|
92
|
+
│ │ ├── config.sh # Plugin configuration loader
|
|
93
|
+
│ │ ├── utils.sh # Pure slug and wikilink utilities
|
|
94
|
+
│ │ ├── source_helpers.sh # In-place YAML source discovery & expansion
|
|
95
|
+
│ │ ├── graph_helpers.sh # Two-pass TSV property graph compiler
|
|
96
|
+
│ │ ├── btree_helpers.sh # B-Tree shard compiler & rebalancer
|
|
97
|
+
│ │ └── agent_query_helpers.sh# Internal O(log N) search and ego graph query
|
|
93
98
|
│ └── templates/
|
|
94
|
-
│ ├──
|
|
95
|
-
│ └──
|
|
99
|
+
│ ├── _index.md # Baseline root router template
|
|
100
|
+
│ └── _log.md # Baseline audit log template
|
|
96
101
|
└── rnex.yaml # Plugin configuration
|
|
97
102
|
```
|
|
98
103
|
|
|
@@ -108,8 +113,8 @@ rnex plugin enable karpathy-llm
|
|
|
108
113
|
|
|
109
114
|
This command:
|
|
110
115
|
1. Adds `karpathy-llm` to `plugins:` in `rnex.yaml`.
|
|
111
|
-
2. Copies initial templates (`wiki/
|
|
112
|
-
3. Scopes `rules/`, `instructions/`, `skills/`, `
|
|
116
|
+
2. Copies initial templates (`wiki/_index.md`, `wiki/_log.md`, `wiki/_index/*.md`, `wiki/_graph/*.tsv`).
|
|
117
|
+
3. Scopes `rules/`, `instructions/`, `skills/`, `bin/`, `lib/`, `hooks/`, `agents/`, and `templates/` into `.rnex/plugins/karpathy-llm/`.
|
|
113
118
|
4. Reconciles workspace state, member repositories, and plugin assets via `rnex sync`.
|
|
114
119
|
|
|
115
120
|
### Option 2: Declarative in `rnex.yaml`
|
|
@@ -149,7 +154,7 @@ plugins:
|
|
|
149
154
|
wiki_dir: wiki # Directory for curated atomic markdown pages
|
|
150
155
|
index_dir: "_index" # Subdirectory for sorted B-Tree leaf shards
|
|
151
156
|
graph_dir: "_graph" # Subdirectory for sorted TSV property graph tables
|
|
152
|
-
btree_root_max_lines: 80 # Maximum allowed lines in root wiki/
|
|
157
|
+
btree_root_max_lines: 80 # Maximum allowed lines in root wiki/_index.md router
|
|
153
158
|
btree_shard_max_entries: 100# Threshold before splitting a B-Tree shard
|
|
154
159
|
graph_default_depth: 1 # Default ego-subgraph traversal depth in hops
|
|
155
160
|
```
|
|
@@ -169,7 +174,7 @@ plugins:
|
|
|
169
174
|
|
|
170
175
|
### CLI Subcommands
|
|
171
176
|
|
|
172
|
-
The `karpathy-llm` plugin
|
|
177
|
+
The `karpathy-llm` plugin exposes a streamlined 2-command CLI:
|
|
173
178
|
|
|
174
179
|
```sh
|
|
175
180
|
# Ingest all configured sources and enabled member repos
|
|
@@ -181,15 +186,6 @@ rnex plugin karpathy-llm ingest --file docs/architecture.md
|
|
|
181
186
|
rnex plugin karpathy-llm ingest --source docs/architecture.md
|
|
182
187
|
rnex plugin karpathy-llm ingest --repo backend-api --quiet
|
|
183
188
|
|
|
184
|
-
# Rebuild sorted TSV graph and B-Tree leaf shards
|
|
185
|
-
rnex plugin karpathy-llm index --rebuild
|
|
186
|
-
|
|
187
|
-
# Fast O(log N) prefix search over wiki nodes
|
|
188
|
-
rnex plugin karpathy-llm search <prefix>
|
|
189
|
-
|
|
190
|
-
# Query ego-subgraph dependencies and backlinks
|
|
191
|
-
rnex plugin karpathy-llm graph <node_id> [--depth 1|2]
|
|
192
|
-
|
|
193
189
|
# Lint wiki schema, sort invariants, and wikilink integrity
|
|
194
190
|
rnex plugin karpathy-llm lint
|
|
195
191
|
|
|
@@ -197,6 +193,13 @@ rnex plugin karpathy-llm lint
|
|
|
197
193
|
rnex plugin karpathy-llm lint --strict
|
|
198
194
|
```
|
|
199
195
|
|
|
196
|
+
### Internal Agent Query Operations (`_search` & `_graph`)
|
|
197
|
+
|
|
198
|
+
AI coding agents navigate the wiki during task execution using high-performance internal library helpers (`lib/agent_query_helpers.sh`):
|
|
199
|
+
|
|
200
|
+
* **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).
|
|
201
|
+
* **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.
|
|
202
|
+
|
|
200
203
|
### Summary Reference Table
|
|
201
204
|
|
|
202
205
|
| Field | Scope / File | Type | Default | Description |
|
|
@@ -205,7 +208,7 @@ rnex plugin karpathy-llm lint --strict
|
|
|
205
208
|
| `wiki_dir` | Repo (`rnex.yaml`) | `string` | `wiki` | Directory containing atomic domain pages. |
|
|
206
209
|
| `index_dir` | Repo (`rnex.yaml`) | `string` | `_index` | Subdirectory for sorted B-Tree leaf shards. |
|
|
207
210
|
| `graph_dir` | Repo (`rnex.yaml`) | `string` | `_graph` | Subdirectory for sorted TSV property graph tables. |
|
|
208
|
-
| `btree_root_max_lines` | Repo (`rnex.yaml`) | `integer` | `80` | Ceiling on lines allowed in `wiki/
|
|
211
|
+
| `btree_root_max_lines` | Repo (`rnex.yaml`) | `integer` | `80` | Ceiling on lines allowed in `wiki/_index.md`. |
|
|
209
212
|
| `btree_shard_max_entries` | Repo (`rnex.yaml`) | `integer` | `100` | Entry count threshold before automatically splitting a shard. |
|
|
210
213
|
| `graph_default_depth` | Repo (`rnex.yaml`) | `integer` | `1` | Default ego-subgraph traversal depth in hops. |
|
|
211
214
|
|
|
@@ -214,9 +217,9 @@ rnex plugin karpathy-llm lint --strict
|
|
|
214
217
|
## Everyday Operation & Cadence
|
|
215
218
|
|
|
216
219
|
1. **Intake:** Drop raw research papers, meeting notes, PRDs, or architecture specs into `./docs/` unmodified.
|
|
217
|
-
2. **Ingest:** Instruct your AI assistant: *"Run wiki-ingest on docs/source-document.md"*, or run `rnex plugin karpathy-llm ingest
|
|
218
|
-
3. **
|
|
219
|
-
4. **
|
|
220
|
+
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).
|
|
221
|
+
3. **Maintenance:** Run `rnex plugin karpathy-llm lint` (or the `wiki-lint` workflow) to validate relations, purge legacy caches, and update graph edges.
|
|
222
|
+
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.
|
|
220
223
|
|
|
221
224
|
---
|
|
222
225
|
|
|
@@ -1,4 +1,87 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# shellcheck shell=sh
|
|
3
|
-
#
|
|
4
|
-
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# File: plugins/karpathy-llm/bin/ingest.sh
|
|
5
|
+
# Architectural Layer: Public Plugin CLI Command (ingest)
|
|
6
|
+
# Single Responsibility: Ingest workspace source documentation directly in place
|
|
7
|
+
# into wiki/_graph/*.tsv and wiki/_index/*.md with zero symlinks.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
set -e
|
|
11
|
+
|
|
12
|
+
SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
|
|
13
|
+
PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
|
|
14
|
+
|
|
15
|
+
# shellcheck source=plugins/karpathy-llm/lib/config.sh
|
|
16
|
+
. "${PLUGIN_ROOT}/lib/config.sh"
|
|
17
|
+
# shellcheck source=plugins/karpathy-llm/lib/utils.sh
|
|
18
|
+
. "${PLUGIN_ROOT}/lib/utils.sh"
|
|
19
|
+
# shellcheck source=plugins/karpathy-llm/lib/source_helpers.sh
|
|
20
|
+
. "${PLUGIN_ROOT}/lib/source_helpers.sh"
|
|
21
|
+
# shellcheck source=plugins/karpathy-llm/lib/graph_helpers.sh
|
|
22
|
+
. "${PLUGIN_ROOT}/lib/graph_helpers.sh"
|
|
23
|
+
# shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
|
|
24
|
+
. "${PLUGIN_ROOT}/lib/btree_helpers.sh"
|
|
25
|
+
# shellcheck source=plugins/karpathy-llm/lib/agent_query_helpers.sh
|
|
26
|
+
. "${PLUGIN_ROOT}/lib/agent_query_helpers.sh"
|
|
27
|
+
|
|
28
|
+
load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_ROOT:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}}"
|
|
29
|
+
|
|
30
|
+
ensure_wiki_initialized
|
|
31
|
+
|
|
32
|
+
TARGET_FILE=""
|
|
33
|
+
QUIET=0
|
|
34
|
+
|
|
35
|
+
while [ $# -gt 0 ]; do
|
|
36
|
+
case "$1" in
|
|
37
|
+
--file|-f|--source|-s)
|
|
38
|
+
shift
|
|
39
|
+
[ $# -gt 0 ] || { printf 'Error [ingest]: Missing argument for --file/--source\n' >&2; exit 1; }
|
|
40
|
+
TARGET_FILE="$1"
|
|
41
|
+
shift
|
|
42
|
+
;;
|
|
43
|
+
--repo|-r)
|
|
44
|
+
shift
|
|
45
|
+
[ $# -gt 0 ] || { printf 'Error [ingest]: Missing argument for --repo\n' >&2; exit 1; }
|
|
46
|
+
# Repo scope is parsed into target manifest
|
|
47
|
+
shift
|
|
48
|
+
;;
|
|
49
|
+
--quiet|-q)
|
|
50
|
+
QUIET=1
|
|
51
|
+
shift
|
|
52
|
+
;;
|
|
53
|
+
--help|-h)
|
|
54
|
+
printf 'Usage: rnex plugin karpathy-llm ingest [<file_path>] [--file <path>] [--quiet]\n'
|
|
55
|
+
exit 0
|
|
56
|
+
;;
|
|
57
|
+
-*)
|
|
58
|
+
printf 'Error [ingest]: Unknown option: %s\n' "$1" >&2
|
|
59
|
+
exit 1
|
|
60
|
+
;;
|
|
61
|
+
*)
|
|
62
|
+
TARGET_FILE="$1"
|
|
63
|
+
shift
|
|
64
|
+
;;
|
|
65
|
+
esac
|
|
66
|
+
done
|
|
67
|
+
|
|
68
|
+
if [ -n "$TARGET_FILE" ]; then
|
|
69
|
+
if [ -d "$TARGET_FILE" ]; then
|
|
70
|
+
printf 'Error [ingest]: Expected a file path, but "%s" is a directory.\n' "$TARGET_FILE" >&2
|
|
71
|
+
exit 1
|
|
72
|
+
fi
|
|
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"
|
|
80
|
+
exit 0
|
|
81
|
+
fi
|
|
82
|
+
|
|
83
|
+
# Full configured sources indexing
|
|
84
|
+
sync_wiki_indexes_and_graph
|
|
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"
|
|
@@ -1,4 +1,147 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# shellcheck shell=sh
|
|
3
|
-
#
|
|
4
|
-
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# File: plugins/karpathy-llm/bin/lint.sh
|
|
5
|
+
# Architectural Layer: Public Plugin CLI Command (lint)
|
|
6
|
+
# Single Responsibility: Auto-heal wiki structure, remove legacy symlinks and
|
|
7
|
+
# directories, verify LC_ALL=C sort order, edge symmetry, and root bounds.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
set -e
|
|
11
|
+
|
|
12
|
+
SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
|
|
13
|
+
PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
|
|
14
|
+
|
|
15
|
+
# shellcheck source=plugins/karpathy-llm/lib/config.sh
|
|
16
|
+
. "${PLUGIN_ROOT}/lib/config.sh"
|
|
17
|
+
# shellcheck source=plugins/karpathy-llm/lib/utils.sh
|
|
18
|
+
. "${PLUGIN_ROOT}/lib/utils.sh"
|
|
19
|
+
# shellcheck source=plugins/karpathy-llm/lib/source_helpers.sh
|
|
20
|
+
. "${PLUGIN_ROOT}/lib/source_helpers.sh"
|
|
21
|
+
# shellcheck source=plugins/karpathy-llm/lib/graph_helpers.sh
|
|
22
|
+
. "${PLUGIN_ROOT}/lib/graph_helpers.sh"
|
|
23
|
+
# shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
|
|
24
|
+
. "${PLUGIN_ROOT}/lib/btree_helpers.sh"
|
|
25
|
+
# shellcheck source=plugins/karpathy-llm/lib/agent_query_helpers.sh
|
|
26
|
+
. "${PLUGIN_ROOT}/lib/agent_query_helpers.sh"
|
|
27
|
+
|
|
28
|
+
load_karpathy_wiki_config "${NEXUS_DIR:-${RNEX_ROOT:-${RNEX_WORKSPACE_ROOT:-$(pwd)}}}"
|
|
29
|
+
|
|
30
|
+
QUIET=0
|
|
31
|
+
STRICT=0
|
|
32
|
+
|
|
33
|
+
while [ $# -gt 0 ]; do
|
|
34
|
+
case "$1" in
|
|
35
|
+
--strict)
|
|
36
|
+
STRICT=1
|
|
37
|
+
shift
|
|
38
|
+
;;
|
|
39
|
+
--quiet|-q)
|
|
40
|
+
QUIET=1
|
|
41
|
+
shift
|
|
42
|
+
;;
|
|
43
|
+
--help|-h)
|
|
44
|
+
printf 'Usage: rnex plugin karpathy-llm lint [--strict] [--quiet]\n'
|
|
45
|
+
exit 0
|
|
46
|
+
;;
|
|
47
|
+
-*)
|
|
48
|
+
shift
|
|
49
|
+
;;
|
|
50
|
+
*)
|
|
51
|
+
shift
|
|
52
|
+
;;
|
|
53
|
+
esac
|
|
54
|
+
done
|
|
55
|
+
|
|
56
|
+
ensure_wiki_initialized
|
|
57
|
+
purge_legacy_wiki_directories_and_symlinks
|
|
58
|
+
sync_wiki_indexes_and_graph
|
|
59
|
+
|
|
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
|
|
67
|
+
for _tsv in "$RNEX_WIKI_NODES_TSV" "$RNEX_WIKI_EDGES_OUT_TSV" "$RNEX_WIKI_EDGES_IN_TSV"; do
|
|
68
|
+
if [ -f "$_tsv" ] && [ -s "$_tsv" ]; then
|
|
69
|
+
if ! LC_ALL=C sort -c "$_tsv" 2>/dev/null; then
|
|
70
|
+
printf 'Error [lint]: TSV file is not sorted in LC_ALL=C order: %s\n' "$_tsv" >&2
|
|
71
|
+
exit 1
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
74
|
+
done
|
|
75
|
+
|
|
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')"
|
|
79
|
+
if [ "$_out_cnt" -ne "$_in_cnt" ]; then
|
|
80
|
+
printf 'Error [lint]: Asymmetric edge tables (edges_out=%s, edges_in=%s)\n' "$_out_cnt" "$_in_cnt" >&2
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
|
|
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')"
|
|
86
|
+
if [ "$_root_lines" -gt "$RNEX_WIKI_BTREE_MAX_ROOT_LINES" ]; then
|
|
87
|
+
printf 'Error [lint]: wiki/_index.md exceeds %s lines (%s lines)\n' \
|
|
88
|
+
"$RNEX_WIKI_BTREE_MAX_ROOT_LINES" "$_root_lines" >&2
|
|
89
|
+
exit 1
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
# Invariant 5: If --strict is requested, detect broken wikilinks or missing frontmatter sources
|
|
93
|
+
if [ "$STRICT" -eq 1 ]; then
|
|
94
|
+
_broken_tmp="${RNEX_WIKI_GRAPH_DIR}/.broken.tmp.$$"
|
|
95
|
+
rm -f "$_broken_tmp"
|
|
96
|
+
|
|
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
|
|
102
|
+
|
|
103
|
+
# Check frontmatter sources: [...]
|
|
104
|
+
LC_ALL=C awk '
|
|
105
|
+
BEGIN { in_fm=0 }
|
|
106
|
+
/^---/ { in_fm = !in_fm; if (!in_fm) exit; next }
|
|
107
|
+
in_fm && /^[ ]*sources:[ ]*\[/ {
|
|
108
|
+
line = $0
|
|
109
|
+
sub(/^[ ]*sources:[ ]*\[/, "", line)
|
|
110
|
+
sub(/\].*$/, "", line)
|
|
111
|
+
n = split(line, items, ",")
|
|
112
|
+
for (i=1; i<=n; i++) {
|
|
113
|
+
gsub(/^[ "\x27]+|[ "\x27]+$/, "", items[i])
|
|
114
|
+
if (items[i] != "") print items[i]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
' "$_src_abs" < /dev/null | while IFS= read -r _s_path; do
|
|
118
|
+
[ -n "$_s_path" ] || continue
|
|
119
|
+
if [ ! -e "${RNEX_WORKSPACE_ROOT}/${_s_path}" ] && [ ! -e "$_s_path" ]; then
|
|
120
|
+
printf 'Warning [lint]: Broken source reference "%s" in %s\n' "$_s_path" "$_src_rel" >&2
|
|
121
|
+
echo "1" >> "$_broken_tmp"
|
|
122
|
+
fi
|
|
123
|
+
done
|
|
124
|
+
|
|
125
|
+
# Check internal wikilinks
|
|
126
|
+
extract_all_links_from_markdown "$_src_abs" < /dev/null | while IFS= read -r _target; do
|
|
127
|
+
[ -n "$_target" ] || continue
|
|
128
|
+
if ! LC_ALL=C awk -F '\t' -v t="$_target" '
|
|
129
|
+
$1 == t || $1 ~ ("-" t "$") { found=1; exit }
|
|
130
|
+
END { exit !found }
|
|
131
|
+
' "$RNEX_WIKI_NODES_TSV" < /dev/null; then
|
|
132
|
+
printf 'Warning [lint]: Broken link target [[%s]] referenced in %s\n' "$_target" "$_src_rel" >&2
|
|
133
|
+
echo "1" >> "$_broken_tmp"
|
|
134
|
+
fi
|
|
135
|
+
done
|
|
136
|
+
done < "$RNEX_WIKI_NODES_TSV"
|
|
137
|
+
|
|
138
|
+
if [ -f "$_broken_tmp" ]; then
|
|
139
|
+
_broken_cnt="$(LC_ALL=C awk 'END { print NR+0 }' "$_broken_tmp")"
|
|
140
|
+
rm -f "$_broken_tmp"
|
|
141
|
+
printf 'Error [lint]: Found %s unresolved reference(s).\n' "$_broken_cnt" >&2
|
|
142
|
+
exit 1
|
|
143
|
+
fi
|
|
144
|
+
fi
|
|
145
|
+
|
|
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"
|