repo-nexus 0.9.7 → 0.9.9
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 +10 -1
- package/package.json +1 -1
- 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 +42 -132
- package/plugins/karpathy-llm/agents/rnex-wiki-curator.agent.md +1 -1
- package/plugins/karpathy-llm/bin/ingest.sh +8 -16
- package/plugins/karpathy-llm/bin/lint.sh +11 -83
- package/plugins/karpathy-llm/hooks/_common.sh +12 -29
- package/plugins/karpathy-llm/hooks/after_sync.sh +1 -1
- package/plugins/karpathy-llm/hooks/post-sync.sh +1 -1
- package/plugins/karpathy-llm/instructions/rnex-scaffolding-meta-prompt.md +13 -22
- package/plugins/karpathy-llm/instructions/rnex-wiki-architecture.md +2 -2
- package/plugins/karpathy-llm/lib/btree_helpers.sh +147 -111
- package/plugins/karpathy-llm/lib/config.sh +39 -77
- package/plugins/karpathy-llm/lib/source_helpers.sh +124 -157
- package/plugins/karpathy-llm/lib/utils.sh +12 -115
- package/plugins/karpathy-llm/plugin.yaml +11 -48
- package/plugins/karpathy-llm/rules/behavioral.md +1 -1
- package/plugins/karpathy-llm/skills/wiki-ingest.md +16 -16
- package/plugins/karpathy-llm/skills/wiki-lint.md +17 -19
- package/plugins/karpathy-llm/tests/test_plugin.sh +185 -191
- package/plugins/windsurf/plugin.yaml +1 -1
- package/templates/rnex.example.yaml +2 -3
- package/plugins/karpathy-llm/lib/agent_query_helpers.sh +0 -127
- package/plugins/karpathy-llm/lib/graph_helpers.sh +0 -218
- package/plugins/karpathy-llm/templates/_index.md +0 -19
- package/plugins/karpathy-llm/templates/_log.md +0 -9
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
|
|
445
|
-
printf "2. **Step 2 — Inspect Targeted Domain Shard**: Read only the relevant shard in \`%s
|
|
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"
|
|
444
|
+
printf "1. **Step 1 — Query B-Tree Root Index**: Read \`%s/index.md\` (compact B-Tree router <= 80 lines) to locate matching shard (\`repo-nexus*.md\` or \`repos-<member>*.md\`).\n" "$_rai_wiki"
|
|
445
|
+
printf "2. **Step 2 — Inspect Targeted Domain Shard**: Read only the relevant shard in \`%s/<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 directly in place. 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
|
@@ -942,7 +942,7 @@ plugin_list_commands() {
|
|
|
942
942
|
gsub(/[ "]/, "", line)
|
|
943
943
|
print line
|
|
944
944
|
}
|
|
945
|
-
in_cmd && /^[ ]
|
|
945
|
+
in_cmd && /^[ ]{2,3}[a-zA-Z0-9_.-]+:[ ]*/ {
|
|
946
946
|
line = $0
|
|
947
947
|
sub(/^[ ]*/, "", line)
|
|
948
948
|
sub(/:.*/, "", line)
|
|
@@ -973,6 +973,15 @@ plugin_get_command_desc() {
|
|
|
973
973
|
sub(/^[^:]*:[ ]*/, "")
|
|
974
974
|
sub(/[ ]*#.*/, "")
|
|
975
975
|
gsub(/^["\047]|["\047]$/, "")
|
|
976
|
+
if (length($0) > 0) { print; exit }
|
|
977
|
+
in_sub = 1
|
|
978
|
+
next
|
|
979
|
+
}
|
|
980
|
+
in_sub && /^[ ]{2}[a-zA-Z0-9_.-]+:/ { exit }
|
|
981
|
+
in_sub && /^[ ]*description:[ ]*/ {
|
|
982
|
+
sub(/^[ ]*description:[ ]*/, "")
|
|
983
|
+
sub(/[ ]*#.*/, "")
|
|
984
|
+
gsub(/^["\047]|["\047]$/, "")
|
|
976
985
|
print
|
|
977
986
|
exit
|
|
978
987
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repo-nexus",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9",
|
|
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",
|
|
@@ -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 a
|
|
5
|
+
No external vector databases, embedding pipelines, or MCP servers required — just a zero-dependency flat B-Tree sharded index directly in `wiki/*.md`, organized by a bounded root router (`wiki/index.md`), and recorded in a chronological audit log (`wiki/log.md`).
|
|
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,38 +18,18 @@ 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 (`wiki/index.md`) $\to$ Targeted Leaf Shard (`wiki/<shard>.md`) $\to$ In-Place Source Document.
|
|
22
22
|
|
|
23
|
-
### 3. Zero-Dependency B-Tree
|
|
23
|
+
### 3. Zero-Dependency Flat B-Tree 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
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>/
|
|
27
|
-
* **
|
|
28
|
-
* **
|
|
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`.
|
|
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 `<wiki_dir>/`.
|
|
27
|
+
* **Flat Leaf Shards (`<wiki_dir>/repo-nexus*.md`, `<wiki_dir>/repos-*.md`):** Lexicographically sorted catalogs. Automatically split into alphabetical sub-shards (`<shard>-a-m.md`, `<shard>-n-z.md`) when exceeding capacity thresholds.
|
|
28
|
+
* **Chronological Audit Log (`<wiki_dir>/log.md`):** Shared append-only log recording ingest and lint operations across tracked wiki pages. Inspected via `tail -n 20 wiki/log.md`.
|
|
30
29
|
|
|
31
30
|
### 4. Standardized Agent Skills (`skills/`)
|
|
32
|
-
* **`wiki-ingest.md` (User Skill: `rnex-karpathy-llm-wiki-ingest`):** Guides deterministic CLI in-place scanning,
|
|
33
|
-
* **`wiki-lint.md` (User Skill: `rnex-karpathy-llm-wiki-lint`):** Integrity audit protocol to validate paths, auto-heal legacy structures
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## Deterministic Lifecycle: Initialization vs. Evolutionary Growth
|
|
38
|
-
|
|
39
|
-
To ensure workspaces remain 100% predictable, understandable, and consistent across all tools, the Karpathy LLM Wiki follows a strict two-phase lifecycle:
|
|
40
|
-
|
|
41
|
-
### Phase 1: 100% Deterministic Initialization
|
|
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/_index.md`, `wiki/_log.md`, `wiki/_index/*.md`, `wiki/_graph/*.tsv`).
|
|
44
|
-
* **Scoped Assets**: Behavioral rules, wiki architecture guides, skills, commands, and templates are cleanly isolated under `.rnex/plugins/karpathy-llm/`.
|
|
45
|
-
* **Zero Guesswork**: No interactive interviews, no AI-generated folder variances, and no "agent decides" ambiguities at init time.
|
|
46
|
-
* **Idempotent**: Safe to run repeatedly; existing curated wiki pages are never overwritten.
|
|
47
|
-
|
|
48
|
-
### Phase 2: Evolutionary Growth & Domain Specialization (Usage Phase)
|
|
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 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
|
-
* **Customizable Guidelines**: Teams can tailor `rules/behavioral.md` and `instructions/rnex-wiki-architecture.md` for their specific conventions.
|
|
52
|
-
* **Graph Maintenance (`rnex-karpathy-llm-wiki-lint`)**: The periodic lint workflow validates relation paths, verifies sort invariants, and flags broken wikilinks.
|
|
31
|
+
* **`wiki-ingest.md` (User Skill: `rnex-karpathy-llm-wiki-ingest`):** Guides deterministic CLI in-place scanning, flat B-Tree leaf shard rebalancing, root router compilation, and audit log updates.
|
|
32
|
+
* **`wiki-lint.md` (User Skill: `rnex-karpathy-llm-wiki-lint`):** Integrity audit protocol to validate paths, auto-heal legacy structures (`_graph/`, `_index/`, `concepts/`, `repos/`, `overview/`, `entities/`, `sources/`), purge legacy files (`hot.md`, `_index.md`, `_log.md`), assert zero symlinks, and verify root router bounds ($\le 80$ lines).
|
|
53
33
|
|
|
54
34
|
---
|
|
55
35
|
|
|
@@ -60,52 +40,42 @@ When enabled, the plugin scaffolds:
|
|
|
60
40
|
```text
|
|
61
41
|
my-workspace/
|
|
62
42
|
├── docs/ # Workspace documentation
|
|
63
|
-
│ └── .
|
|
43
|
+
│ └── architecture.md
|
|
64
44
|
├── repos/ # Member repositories (inspected in-place)
|
|
65
45
|
│ └── <member-repo>/
|
|
66
46
|
│ └── README.md
|
|
67
47
|
├── wiki/
|
|
68
|
-
│ ├──
|
|
69
|
-
│ ├──
|
|
70
|
-
│ ├──
|
|
71
|
-
│
|
|
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
|
|
48
|
+
│ ├── index.md # B-Tree Root Router (<= 80 lines)
|
|
49
|
+
│ ├── log.md # Ingestion & lint audit history
|
|
50
|
+
│ ├── repo-nexus.md # Nexus repo shard (or repo-nexus-a-m.md, etc.)
|
|
51
|
+
│ └── repos-<member-repo>.md # Member repo shard (e.g. repos-backend-apps.md)
|
|
77
52
|
├── .rnex/
|
|
78
53
|
│ └── plugins/
|
|
79
54
|
│ └── karpathy-llm/
|
|
80
55
|
│ ├── instructions/
|
|
81
|
-
│ │ ├── rnex-wiki-architecture.md
|
|
82
|
-
│ │ └── rnex-scaffolding-meta-prompt.md
|
|
56
|
+
│ │ ├── rnex-wiki-architecture.md
|
|
57
|
+
│ │ └── rnex-scaffolding-meta-prompt.md
|
|
83
58
|
│ ├── rules/
|
|
84
|
-
│ │ └── behavioral.md
|
|
59
|
+
│ │ └── behavioral.md
|
|
85
60
|
│ ├── skills/
|
|
86
|
-
│ │ ├── wiki-ingest.md
|
|
87
|
-
│ │ └── wiki-lint.md
|
|
61
|
+
│ │ ├── wiki-ingest.md
|
|
62
|
+
│ │ └── wiki-lint.md
|
|
88
63
|
│ ├── bin/
|
|
89
|
-
│ │ ├── ingest.sh
|
|
90
|
-
│ │ └── lint.sh
|
|
91
|
-
│
|
|
92
|
-
│
|
|
93
|
-
│
|
|
94
|
-
│
|
|
95
|
-
│
|
|
96
|
-
|
|
97
|
-
│ │ └── agent_query_helpers.sh# Internal O(log N) search and ego graph query
|
|
98
|
-
│ └── templates/
|
|
99
|
-
│ ├── _index.md # Baseline root router template
|
|
100
|
-
│ └── _log.md # Baseline audit log template
|
|
101
|
-
└── rnex.yaml # Plugin configuration
|
|
64
|
+
│ │ ├── ingest.sh
|
|
65
|
+
│ │ └── lint.sh
|
|
66
|
+
│ └── lib/
|
|
67
|
+
│ ├── config.sh
|
|
68
|
+
│ ├── utils.sh
|
|
69
|
+
│ ├── source_helpers.sh
|
|
70
|
+
│ └── btree_helpers.sh
|
|
71
|
+
└── rnex.yaml
|
|
102
72
|
```
|
|
103
73
|
|
|
104
74
|
---
|
|
105
75
|
|
|
106
76
|
## Enabling in Repo Nexus
|
|
107
77
|
|
|
108
|
-
###
|
|
78
|
+
### Via CLI
|
|
109
79
|
|
|
110
80
|
```bash
|
|
111
81
|
rnex plugin enable karpathy-llm
|
|
@@ -113,34 +83,14 @@ rnex plugin enable karpathy-llm
|
|
|
113
83
|
|
|
114
84
|
This command:
|
|
115
85
|
1. Adds `karpathy-llm` to `plugins:` in `rnex.yaml`.
|
|
116
|
-
2.
|
|
117
|
-
3.
|
|
118
|
-
4. Reconciles workspace state, member repositories, and plugin assets via `rnex sync`.
|
|
119
|
-
|
|
120
|
-
### Option 2: Declarative in `rnex.yaml`
|
|
121
|
-
|
|
122
|
-
Configure `karpathy-llm` under `plugins:` in `rnex.yaml`:
|
|
123
|
-
|
|
124
|
-
```yaml
|
|
125
|
-
plugins:
|
|
126
|
-
karpathy-llm: {}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Then reconcile workspace:
|
|
130
|
-
|
|
131
|
-
```bash
|
|
132
|
-
rnex sync
|
|
133
|
-
```
|
|
86
|
+
2. Scopes `rules/`, `instructions/`, `skills/`, `bin/`, `lib/`, and `hooks/` into `.rnex/plugins/karpathy-llm/`.
|
|
87
|
+
3. Reconciles workspace state, member repositories, and plugin assets via `rnex sync`.
|
|
134
88
|
|
|
135
89
|
---
|
|
136
90
|
|
|
137
91
|
## Configuration Reference
|
|
138
92
|
|
|
139
|
-
|
|
140
|
-
1. **Repo Config (`rnex.yaml`)**: Shared across your team and version-controlled. Configures repository-level structure, file paths, and indexing rules.
|
|
141
|
-
2. **Local Config (`.local.rnex.yaml`)**: Machine-specific and gitignored.
|
|
142
|
-
|
|
143
|
-
### 1. Shared Repo Configuration (`rnex.yaml`)
|
|
93
|
+
Configure `karpathy-llm` under `plugins:` in `rnex.yaml` or `.local.rnex.yaml`:
|
|
144
94
|
|
|
145
95
|
```yaml
|
|
146
96
|
plugins:
|
|
@@ -150,26 +100,12 @@ plugins:
|
|
|
150
100
|
- docs
|
|
151
101
|
- "repos/**/README.md"
|
|
152
102
|
|
|
153
|
-
# Directory paths relative to workspace root (defaults shown)
|
|
154
|
-
wiki_dir: wiki # Directory for curated
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
btree_root_max_lines: 80 # Maximum allowed lines in root wiki/
|
|
103
|
+
# Directory paths and control files relative to workspace root (defaults shown)
|
|
104
|
+
wiki_dir: wiki # Directory for curated flat markdown shards
|
|
105
|
+
index_file: "index.md" # B-Tree Root Router filename
|
|
106
|
+
log_file: "log.md" # Chronological audit log filename
|
|
107
|
+
btree_root_max_lines: 80 # Maximum allowed lines in root wiki/index.md router
|
|
158
108
|
btree_shard_max_entries: 100# Threshold before splitting a B-Tree shard
|
|
159
|
-
graph_default_depth: 1 # Default ego-subgraph traversal depth in hops
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### 2. Local Machine Configuration (`.local.rnex.yaml`)
|
|
163
|
-
|
|
164
|
-
Use this file to customize how your local workstation resolves wiki paths or sources:
|
|
165
|
-
|
|
166
|
-
```yaml
|
|
167
|
-
plugins:
|
|
168
|
-
karpathy-llm:
|
|
169
|
-
wiki_dir: wiki
|
|
170
|
-
sources:
|
|
171
|
-
- docs
|
|
172
|
-
- "repos/**/README.md"
|
|
173
109
|
```
|
|
174
110
|
|
|
175
111
|
### CLI Subcommands
|
|
@@ -180,46 +116,20 @@ The `karpathy-llm` plugin exposes a streamlined 2-command CLI:
|
|
|
180
116
|
# Ingest all configured sources and enabled member repos
|
|
181
117
|
rnex plugin karpathy-llm ingest
|
|
182
118
|
|
|
183
|
-
# Ingest a specific markdown source
|
|
119
|
+
# Ingest a specific markdown source file directly in place
|
|
184
120
|
rnex plugin karpathy-llm ingest docs/architecture.md
|
|
185
121
|
rnex plugin karpathy-llm ingest --file docs/architecture.md
|
|
186
|
-
rnex plugin karpathy-llm ingest --source docs/architecture.md
|
|
187
|
-
rnex plugin karpathy-llm ingest --repo backend-api --quiet
|
|
188
122
|
|
|
189
|
-
# Lint wiki
|
|
123
|
+
# Lint wiki structure, line budget, and zero-symlink invariants
|
|
190
124
|
rnex plugin karpathy-llm lint
|
|
191
|
-
|
|
192
|
-
# Strict linting (exits non-zero on warnings or errors)
|
|
193
|
-
rnex plugin karpathy-llm lint --strict
|
|
194
125
|
```
|
|
195
126
|
|
|
196
|
-
###
|
|
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
|
-
|
|
203
|
-
### Summary Reference Table
|
|
204
|
-
|
|
205
|
-
| Field | Scope / File | Type | Default | Description |
|
|
206
|
-
|:---|:---|:---|:---|:---|
|
|
207
|
-
| `sources` | Repo (`rnex.yaml`) | `list` | `[docs, "repos/**/README.md"]` | Directory paths and/or glob patterns for intake documents. |
|
|
208
|
-
| `wiki_dir` | Repo (`rnex.yaml`) | `string` | `wiki` | Directory containing atomic domain pages. |
|
|
209
|
-
| `index_dir` | Repo (`rnex.yaml`) | `string` | `_index` | Subdirectory for sorted B-Tree leaf shards. |
|
|
210
|
-
| `graph_dir` | Repo (`rnex.yaml`) | `string` | `_graph` | Subdirectory for sorted TSV property graph tables. |
|
|
211
|
-
| `btree_root_max_lines` | Repo (`rnex.yaml`) | `integer` | `80` | Ceiling on lines allowed in `wiki/_index.md`. |
|
|
212
|
-
| `btree_shard_max_entries` | Repo (`rnex.yaml`) | `integer` | `100` | Entry count threshold before automatically splitting a shard. |
|
|
213
|
-
| `graph_default_depth` | Repo (`rnex.yaml`) | `integer` | `1` | Default ego-subgraph traversal depth in hops. |
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
|
-
## Everyday Operation & Cadence
|
|
127
|
+
### Retrieval Protocol: How AI Agents Query the Wiki
|
|
218
128
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
129
|
+
AI coding assistants navigate the wiki using a deterministic 3-step retrieval protocol:
|
|
130
|
+
1. **Root Read:** Read `wiki/index.md` ($\le 80$ lines) to locate the relevant leaf shard.
|
|
131
|
+
2. **Shard Read:** Read the target shard in `wiki/` (`repo-nexus*.md` or `repos-<member>*.md`) to find the exact source file path and summary.
|
|
132
|
+
3. **In-Place Read:** Open and read the authoritative source file directly where it resides in the workspace. Discover backlinks and cross-references using standard workspace search tools (`grep`, `ripgrep`).
|
|
223
133
|
|
|
224
134
|
---
|
|
225
135
|
|
|
@@ -5,4 +5,4 @@ description: Autonomous knowledge librarian for the Karpathy LLM Wiki architectu
|
|
|
5
5
|
|
|
6
6
|
# Wiki Curator Agent
|
|
7
7
|
|
|
8
|
-
Autonomous knowledge librarian specialized in synthesizing unstructured source documents from the configured intake sources (`plugins.karpathy-llm.sources`, default: `docs`, `"repos/**/README.md"`; legacy `raw_dir`) into the
|
|
8
|
+
Autonomous knowledge librarian specialized in synthesizing unstructured source documents from the configured intake sources (`plugins.karpathy-llm.sources`, default: `docs`, `"repos/**/README.md"`; legacy `raw_dir`) into the flat Karpathy LLM Wiki B-Tree index under `plugins.karpathy-llm.wiki_dir` (default: `wiki`).
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# File: plugins/karpathy-llm/bin/ingest.sh
|
|
5
5
|
# Architectural Layer: Public Plugin CLI Command (ingest)
|
|
6
6
|
# Single Responsibility: Ingest workspace source documentation directly in place
|
|
7
|
-
# into
|
|
7
|
+
# into flat B-Tree shards (wiki/*.md) with zero symlinks and zero graphs.
|
|
8
8
|
# =============================================================================
|
|
9
9
|
|
|
10
10
|
set -e
|
|
@@ -18,16 +18,10 @@ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
|
|
|
18
18
|
. "${PLUGIN_ROOT}/lib/utils.sh"
|
|
19
19
|
# shellcheck source=plugins/karpathy-llm/lib/source_helpers.sh
|
|
20
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
21
|
# shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
|
|
24
22
|
. "${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
23
|
|
|
28
|
-
load_karpathy_wiki_config "${
|
|
29
|
-
|
|
30
|
-
ensure_wiki_initialized
|
|
24
|
+
load_karpathy_wiki_config "${RNEX_WORKSPACE_ROOT:-$(pwd)}"
|
|
31
25
|
|
|
32
26
|
TARGET_FILE=""
|
|
33
27
|
QUIET=0
|
|
@@ -43,7 +37,6 @@ while [ $# -gt 0 ]; do
|
|
|
43
37
|
--repo|-r)
|
|
44
38
|
shift
|
|
45
39
|
[ $# -gt 0 ] || { printf 'Error [ingest]: Missing argument for --repo\n' >&2; exit 1; }
|
|
46
|
-
# Repo scope is parsed into target manifest
|
|
47
40
|
shift
|
|
48
41
|
;;
|
|
49
42
|
--quiet|-q)
|
|
@@ -74,14 +67,13 @@ if [ -n "$TARGET_FILE" ]; then
|
|
|
74
67
|
printf 'Error [ingest]: Target file not found or is a symlink: %s\n' "$TARGET_FILE" >&2
|
|
75
68
|
exit 1
|
|
76
69
|
fi
|
|
77
|
-
|
|
70
|
+
compile_flat_btree_wiki
|
|
78
71
|
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"
|
|
72
|
+
[ "$QUIET" = "1" ] || printf 'Successfully indexed %s into flat wiki.\n' "$TARGET_FILE"
|
|
80
73
|
exit 0
|
|
81
74
|
fi
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[ "$QUIET" = "1" ] || printf 'Completed wiki ingest (%s sources indexed in place).\n' "$_total"
|
|
76
|
+
compile_flat_btree_wiki
|
|
77
|
+
_shard_count="$(find "${RNEX_WIKI_ROOT}" -maxdepth 1 -name '*.md' ! -name 'index.md' ! -name 'log.md' 2>/dev/null | wc -l | tr -d ' ')"
|
|
78
|
+
append_wiki_log_entry "ingest" "Rebalanced flat wiki B-Tree shards (${_shard_count} shards)."
|
|
79
|
+
[ "$QUIET" = "1" ] || printf 'Completed wiki ingest (%s shards updated in %s).\n' "$_shard_count" "$RNEX_WIKI_ROOT"
|
|
@@ -3,8 +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 wiki structure, remove legacy
|
|
7
|
-
#
|
|
6
|
+
# Single Responsibility: Auto-heal wiki structure, remove legacy artifacts,
|
|
7
|
+
# verify index line count bounds, and assert zero symlinks.
|
|
8
8
|
# =============================================================================
|
|
9
9
|
|
|
10
10
|
set -e
|
|
@@ -18,14 +18,10 @@ PLUGIN_ROOT="$(CDPATH='' cd -- "${SCRIPT_DIR}/.." && pwd)"
|
|
|
18
18
|
. "${PLUGIN_ROOT}/lib/utils.sh"
|
|
19
19
|
# shellcheck source=plugins/karpathy-llm/lib/source_helpers.sh
|
|
20
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
21
|
# shellcheck source=plugins/karpathy-llm/lib/btree_helpers.sh
|
|
24
22
|
. "${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
23
|
|
|
28
|
-
load_karpathy_wiki_config "${
|
|
24
|
+
load_karpathy_wiki_config "${RNEX_WORKSPACE_ROOT:-$(pwd)}"
|
|
29
25
|
|
|
30
26
|
QUIET=0
|
|
31
27
|
STRICT=0
|
|
@@ -53,9 +49,7 @@ while [ $# -gt 0 ]; do
|
|
|
53
49
|
esac
|
|
54
50
|
done
|
|
55
51
|
|
|
56
|
-
|
|
57
|
-
purge_legacy_wiki_directories_and_symlinks
|
|
58
|
-
sync_wiki_indexes_and_graph
|
|
52
|
+
compile_flat_btree_wiki
|
|
59
53
|
|
|
60
54
|
# Invariant 1: Assert zero symlinks in wiki/
|
|
61
55
|
if [ -n "$(find "$RNEX_WIKI_ROOT" -type l 2>/dev/null)" ]; then
|
|
@@ -63,85 +57,19 @@ if [ -n "$(find "$RNEX_WIKI_ROOT" -type l 2>/dev/null)" ]; then
|
|
|
63
57
|
exit 1
|
|
64
58
|
fi
|
|
65
59
|
|
|
66
|
-
# Invariant 2:
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
60
|
+
# Invariant 2: Assert no legacy _graph/ or _index/ directories
|
|
61
|
+
if [ -d "${RNEX_WIKI_ROOT}/_graph" ] || [ -d "${RNEX_WIKI_ROOT}/_index" ]; then
|
|
62
|
+
printf 'Error [lint]: Found deprecated _graph/ or _index/ directories.\n' >&2
|
|
81
63
|
exit 1
|
|
82
64
|
fi
|
|
83
65
|
|
|
84
|
-
# Invariant
|
|
66
|
+
# Invariant 3: Verify root router bounds (<= 80 lines)
|
|
85
67
|
_root_lines="$(LC_ALL=C awk 'END { print NR+0 }' "$RNEX_WIKI_INDEX_FILE" 2>/dev/null || printf '0')"
|
|
86
68
|
if [ "$_root_lines" -gt "$RNEX_WIKI_BTREE_MAX_ROOT_LINES" ]; then
|
|
87
|
-
printf 'Error [lint]: wiki/
|
|
69
|
+
printf 'Error [lint]: wiki/index.md exceeds %s lines (%s lines)\n' \
|
|
88
70
|
"$RNEX_WIKI_BTREE_MAX_ROOT_LINES" "$_root_lines" >&2
|
|
89
71
|
exit 1
|
|
90
72
|
fi
|
|
91
73
|
|
|
92
|
-
|
|
93
|
-
|
|
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"
|
|
74
|
+
append_wiki_log_entry "lint" "Verified flat wiki B-Tree shards (0 symlinks, root is ${_root_lines} lines)."
|
|
75
|
+
[ "$QUIET" = "1" ] || printf 'Wiki lint passed: 0 symlinks, 0 graphs, root index.md is %s lines.\n' "$_root_lines"
|
|
@@ -59,11 +59,7 @@ if [ -n "$_kl_plugin_lib" ]; then
|
|
|
59
59
|
# shellcheck source=/dev/null
|
|
60
60
|
. "$_kl_plugin_lib/source_helpers.sh" 2>/dev/null || true
|
|
61
61
|
# shellcheck source=/dev/null
|
|
62
|
-
. "$_kl_plugin_lib/graph_helpers.sh" 2>/dev/null || true
|
|
63
|
-
# shellcheck source=/dev/null
|
|
64
62
|
. "$_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
|
|
67
63
|
load_wiki_config_contract "$_root" 2>/dev/null || true
|
|
68
64
|
fi
|
|
69
65
|
|
|
@@ -423,7 +419,7 @@ kl_truncate_summary() {
|
|
|
423
419
|
'
|
|
424
420
|
}
|
|
425
421
|
|
|
426
|
-
# Ensure the configured wiki directory, B-Tree shards,
|
|
422
|
+
# Ensure the configured wiki directory, flat B-Tree shards, index.md, and log.md exist.
|
|
427
423
|
kl_ensure_wiki_files() {
|
|
428
424
|
if command -v load_wiki_config_contract >/dev/null 2>&1; then
|
|
429
425
|
load_wiki_config_contract "$_root" 2>/dev/null || true
|
|
@@ -431,40 +427,27 @@ kl_ensure_wiki_files() {
|
|
|
431
427
|
_wiki_path="${RNEX_WIKI_ROOT:-$_root/$_wiki}"
|
|
432
428
|
mkdir -p "$_wiki_path"
|
|
433
429
|
|
|
434
|
-
# Clean up legacy
|
|
435
|
-
rm -f "$_wiki_path/hot.md" 2>/dev/null || true
|
|
436
|
-
|
|
437
|
-
# Ensure B-Tree and Graph stores are initialized
|
|
438
|
-
if command -v init_wiki_btree_store >/dev/null 2>&1; then
|
|
439
|
-
init_wiki_btree_store || true
|
|
440
|
-
elif [ ! -f "$_wiki_path/_index.md" ]; then
|
|
441
|
-
_kew_pdir=""
|
|
442
|
-
for _kew_cand in "$_root/.rnex/plugins/karpathy-llm" "$_root/plugins/karpathy-llm"; do
|
|
443
|
-
if [ -d "$_kew_cand/templates" ]; then
|
|
444
|
-
_kew_pdir="$_kew_cand"
|
|
445
|
-
break
|
|
446
|
-
fi
|
|
447
|
-
done
|
|
448
|
-
if [ -n "$_kew_pdir" ] && [ -f "$_kew_pdir/templates/_index.md" ]; then
|
|
449
|
-
cp "$_kew_pdir/templates/_index.md" "$_wiki_path/_index.md"
|
|
450
|
-
fi
|
|
451
|
-
fi
|
|
430
|
+
# Clean up legacy artifacts
|
|
431
|
+
rm -f "$_wiki_path/hot.md" "$_wiki_path/_index.md" 2>/dev/null || true
|
|
432
|
+
rm -rf "$_wiki_path/_graph" "$_wiki_path/_index" 2>/dev/null || true
|
|
452
433
|
|
|
453
|
-
|
|
454
|
-
|
|
434
|
+
# Ensure flat B-Tree shards and root router are compiled
|
|
435
|
+
if command -v compile_flat_btree_wiki >/dev/null 2>&1; then
|
|
436
|
+
compile_flat_btree_wiki || true
|
|
455
437
|
fi
|
|
456
438
|
|
|
457
439
|
_kew_today="$(kl_today)"
|
|
458
|
-
if [ ! -f "$_wiki_path/
|
|
459
|
-
|
|
440
|
+
if [ -f "$_wiki_path/_log.md" ] && [ ! -f "$_wiki_path/log.md" ]; then
|
|
441
|
+
mv "$_wiki_path/_log.md" "$_wiki_path/log.md"
|
|
442
|
+
elif [ ! -f "$_wiki_path/log.md" ]; then
|
|
443
|
+
cat > "$_wiki_path/log.md" <<LOG_INIT
|
|
460
444
|
# Karpathy Wiki Operation Log
|
|
461
445
|
|
|
462
446
|
Append-only audit trail recording all ingest and maintenance runs.
|
|
463
447
|
|
|
464
448
|
---
|
|
465
449
|
|
|
466
|
-
|
|
467
|
-
* **Action:** Initialized Karpathy LLM Wiki architecture via \`karpathy-llm\` plugin.
|
|
450
|
+
- **${_kew_today}** | \`init\` | Initialized flat Karpathy LLM Wiki architecture via \`karpathy-llm\` plugin.
|
|
468
451
|
LOG_INIT
|
|
469
452
|
fi
|
|
470
453
|
}
|
|
@@ -50,7 +50,7 @@ fi
|
|
|
50
50
|
# Clean up obsolete leaked root ./raw and ./wiki directories if non-default paths are configured
|
|
51
51
|
command -v _clean_leaked_plugin_dirs >/dev/null 2>&1 && _clean_leaked_plugin_dirs "$_root" "$_raw" "$_wiki"
|
|
52
52
|
|
|
53
|
-
# Ensure configured wiki_dir and default control files (index.md,
|
|
53
|
+
# Ensure configured wiki_dir and default control files (index.md, log.md) exist
|
|
54
54
|
kl_ensure_wiki_files
|
|
55
55
|
|
|
56
56
|
# Clean up legacy staging directory only if empty or positively verified as managed duplicate copies
|