repo-nexus 0.8.8 → 0.8.12

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 (33) hide show
  1. package/README.md +6 -6
  2. package/lib/ai.sh +194 -83
  3. package/lib/commands/completion.sh +13 -0
  4. package/lib/commands/init.sh +31 -8
  5. package/lib/commands/repo.sh +5 -0
  6. package/lib/commands/status.sh +5 -3
  7. package/lib/commands/system.sh +1 -1
  8. package/lib/hooks.sh +3 -0
  9. package/lib/plugins.sh +9 -6
  10. package/lib/repos.sh +2 -10
  11. package/lib/sdk.sh +36 -7
  12. package/lib/workspace.sh +8 -8
  13. package/lib/yaml.sh +167 -0
  14. package/package.json +1 -1
  15. package/rnex +20 -0
  16. package/templates/ai-instructions.sample.md +21 -20
  17. package/templates/rnex-env.sh +46 -0
  18. package/templates/rnex.example.yaml +3 -1
  19. package/toolkit/plugins/claude/instructions/rnex-claude-integration.md +0 -17
  20. package/toolkit/plugins/codex/instructions/rnex-codex-integration.md +0 -16
  21. package/toolkit/plugins/copilot/instructions/rnex-copilot-integration.md +0 -16
  22. package/toolkit/plugins/cursor/instructions/rnex-cursor-integration.md +0 -16
  23. package/toolkit/plugins/gemini/instructions/rnex-gemini-integration.md +0 -17
  24. package/toolkit/plugins/karpathy-llm/hooks/_common.sh +11 -2
  25. package/toolkit/plugins/karpathy-llm/instructions/rnex-scaffolding-meta-prompt.md +1 -1
  26. package/toolkit/plugins/karpathy-llm/instructions/rnex-wiki-architecture.md +5 -63
  27. package/toolkit/plugins/karpathy-llm/rules/behavioral.md +3 -3
  28. package/toolkit/plugins/karpathy-llm/skills/wiki-ingest.md +4 -4
  29. package/toolkit/plugins/karpathy-llm/skills/wiki-lint.md +18 -5
  30. package/toolkit/plugins/windsurf/instructions/rnex-windsurf-integration.md +0 -16
  31. package/toolkit/skills/batch-exec.md +4 -4
  32. package/toolkit/skills/clone-sync.md +5 -5
  33. package/toolkit/skills/workspace-status.md +2 -2
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  A **Virtual Meta-Repo** companion for multi-repo workspaces and shared AI context. It organizes independent repositories into a unified workspace and shares lean routing instructions (`AGENTS.md`) **without Git submodules, monorepo migrations, or symlink fragility**.
13
13
 
14
- - **No Git Submodules or Nested Git Collisions**: Member repositories are physically cloned into `./repos/` and strictly ignored by workspace Git. Each repository maintains its own standalone history, remotes, branches, and commits with zero submodule friction.
14
+ - **No Git Submodules or Nested Git Collisions**: Member repositories are physically cloned into `./<repos_dir>/` (default: `./repos/`, configurable via `repos_dir`) and strictly ignored by workspace Git. Each repository maintains its own standalone history, remotes, branches, and commits with zero submodule friction.
15
15
  - **Unified Workspace for AI Coding Assistants**: Open one root folder to give Cursor, Claude Code, GitHub Copilot, Codex, or Antigravity complete cross-service visibility.
16
16
  - **Two-Level Configuration as Source of Truth**: Shared team manifest in `rnex.yaml` with machine-specific overrides in `.local.rnex.yaml` (highest priority).
17
17
  - **One Command Team Onboarding**: Teammates clone the meta-repo and run `rnex clone` to clone and configure all member repos in seconds.
@@ -50,19 +50,19 @@ A **Virtual Meta-Repo** companion for multi-repo workspaces and shared AI contex
50
50
  | What It Is | What It Isn't |
51
51
  | :--- | :--- |
52
52
  | **A lightweight companion utility** (modular pure POSIX `/bin/sh` CLI). | **NOT a replacement for your workspace or tools.** It doesn't replace VS Code, Cursor, JetBrains, or your terminal. |
53
- | **A Virtual Meta-Repo orchestrator** managing member clones in `./repos/`. | **NOT a build tool or monorepo orchestrator.** It doesn't replace tools like Nx, Turborepo, Cargo, or Gradle. |
53
+ | **A Virtual Meta-Repo orchestrator** managing member clones in `./<repos_dir>/` (default: `./repos/`). | **NOT a build tool or monorepo orchestrator.** It doesn't replace tools like Nx, Turborepo, Cargo, or Gradle. |
54
54
  | **Zero Git friction.** Repositories remain normal, autonomous Git repos. | **NOT Git submodules or subtrees.** No `.gitmodules` files, no detached HEADs, no commit coordination lock-in. |
55
- | **Strictly encapsulated.** Internal rnex assets live exclusively in `.rnex/`. | **NOT invasive.** Member repositories remain clean; workspace-related context is isolated to `repos/<name>/.rnex/`. |
55
+ | **Strictly encapsulated.** Internal rnex assets live exclusively in `.rnex/`. | **NOT invasive.** Member repositories remain clean; workspace-related context is isolated to `<repos_dir>/<name>/.rnex/`. |
56
56
 
57
57
  ---
58
58
 
59
59
  ## AGENTS.md Context Sync & Key Principles
60
60
 
61
61
  1. **Configuration as Single Source of Truth**:
62
- Every agent workflow and command starts by reading the configuration files. `.local.rnex.yaml` takes **highest priority** over `rnex.yaml`.
62
+ Every agent workflow and command starts by reading the configuration files. `.local.rnex.yaml` takes **highest priority** over `rnex.yaml`. Top-level `repos_dir` configures where member repositories reside (default: `repos`).
63
63
 
64
64
  2. **No Git Submodules (Complete Repository Autonomy)**:
65
- Member repositories are cloned directly into `./repos/<name>`. The root workspace `.gitignore` ignores `repos/`, ensuring the workspace repository never tracks or interferes with member Git histories, remotes, branches, or commits.
65
+ Member repositories are cloned directly into `./<repos_dir>/<name>` (default: `./repos/<name>`). The root workspace `.gitignore` dynamically ignores the configured `repos_dir/`, ensuring the workspace repository never tracks or interferes with member Git histories, remotes, branches, or commits.
66
66
 
67
67
  3. **Enabled by Default with Two-Level Merging**:
68
68
  Member repositories are enabled by default. Developers can selectively disable specific repositories locally in `.local.rnex.yaml` (`enabled: false`) without mutating the shared `rnex.yaml`. Disabled repositories are skipped by `clone` and `exec`.
@@ -71,7 +71,7 @@ A **Virtual Meta-Repo** companion for multi-repo workspaces and shared AI contex
71
71
  `AGENTS.md` (and related top-level instruction files) contains no inlined plugin rules or tool boilerplate. It acts solely as a lean navigation router directing AI agents to configuration files, scoped plugins, and member `.rnex/` contexts.
72
72
 
73
73
  5. **Strict File Encapsulation**:
74
- All `rnex`-managed internal files live exclusively in `.rnex/`. Member repositories isolate Repo Nexus assets in `repos/<name>/.rnex/`.
74
+ All `rnex`-managed internal files live exclusively in `.rnex/`. Member repositories isolate Repo Nexus assets in `<repos_dir>/<name>/.rnex/`.
75
75
 
76
76
  ---
77
77
 
package/lib/ai.sh CHANGED
@@ -11,12 +11,15 @@ GITIGNORE_MARKER_END="# REPO-NEXUS:END"
11
11
 
12
12
  # Emit the delimited Repo Nexus .gitignore section synced with git.ignore configuration.
13
13
  _build_rnex_gitignore_section() {
14
+ _active_repos_dir="$(yaml_get_repos_dir 2>/dev/null || printf 'repos')"
15
+ [ -n "$_active_repos_dir" ] || _active_repos_dir="repos"
14
16
  cat <<GI_SECTION_EOF
15
17
  $GITIGNORE_MARKER_START
16
18
  # Managed by Repo Nexus (rnex) — synced with git.ignore in workspace configuration
17
19
  # Member repos (managed by rnex, ignored at workspace level)
18
- repos/*
19
- !repos/.gitkeep
20
+ ${_active_repos_dir}/
21
+ ${_active_repos_dir}/*
22
+ !${_active_repos_dir}/.gitkeep
20
23
 
21
24
  # Recursive Repo Nexus directories (trailing slashes prevent ignoring rnex executable or rnex.yaml)
22
25
  **/.rnex*/
@@ -36,7 +39,7 @@ GI_SECTION_EOF
36
39
  printf '%s\n' "$_custom_ignores" | while IFS= read -r _ci || [ -n "$_ci" ]; do
37
40
  [ -n "$_ci" ] || continue
38
41
  case "$_ci" in
39
- "repos/"|"repos/*"|"!repos/.gitkeep"|"**/.rnex*/"|"**/rnex*/"|".rnex*/"|"rnex*/"|"$RNEX_LOCAL_CONFIG_FILE"|".rnex.local.yaml")
42
+ "repos/"|"repos/*"|"!repos/.gitkeep"|"${_active_repos_dir}/"|"${_active_repos_dir}/*"|"!${_active_repos_dir}/.gitkeep"|"**/.rnex*/"|"**/rnex*/"|".rnex*/"|"rnex*/"|"$RNEX_LOCAL_CONFIG_FILE"|".rnex.local.yaml")
40
43
  continue
41
44
  ;;
42
45
  esac
@@ -70,10 +73,12 @@ reconcile_gitignore() {
70
73
  _gi="$_dir/.gitignore"
71
74
  _sec_tmp="$(mktemp)"
72
75
  _build_rnex_gitignore_section > "$_sec_tmp"
76
+ _active_repos_dir="$(yaml_get_repos_dir 2>/dev/null || printf 'repos')"
77
+ [ -n "$_active_repos_dir" ] || _active_repos_dir="repos"
73
78
 
74
79
  if [ ! -f "$_gi" ]; then
75
80
  mv "$_sec_tmp" "$_gi"
76
- log_ok "Created .gitignore (ignoring repos/, recursive .rnex directories, and $RNEX_LOCAL_CONFIG_FILE)"
81
+ log_ok "Created .gitignore (ignoring ${_active_repos_dir}/, recursive .rnex directories, and $RNEX_LOCAL_CONFIG_FILE)"
77
82
  else
78
83
  # 1. Strip any legacy lint_trigger_counter entries if present
79
84
  if grep -q "lint_trigger_counter" "$_gi" 2>/dev/null; then
@@ -102,13 +107,14 @@ reconcile_gitignore() {
102
107
  else
103
108
  # 3. Upgrade legacy un-delimited .gitignore or append managed section to existing user .gitignore
104
109
  _user_tmp="$(mktemp)"
105
- awk -v local_cfg="$RNEX_LOCAL_CONFIG_FILE" '
110
+ awk -v local_cfg="$RNEX_LOCAL_CONFIG_FILE" -v ard="$_active_repos_dir" '
106
111
  /^[ ]*#[ ]*Member repos \(managed by rnex/ { next }
107
112
  /^[ ]*#[ ]*Recursive Repo Nexus directories/ { next }
108
113
  /^[ ]*#?[ ]*Repo Nexus internal state/ { next }
109
114
  /^[ ]*#[ ]*Local machine-specific configuration/ { next }
110
115
  /^[ ]*#[ ]*Custom entries from git\.ignore in workspace configuration/ { next }
111
- $0 == "repos/*" || $0 == "!repos/.gitkeep" { next }
116
+ $0 == "repos/*" || $0 == "!repos/.gitkeep" || $0 == "repos/" { next }
117
+ $0 == (ard "/*") || $0 == ("!" ard "/.gitkeep") || $0 == (ard "/") { next }
112
118
  $0 == "**/.rnex*/" || $0 == "**/rnex*/" || $0 == ".rnex*/" || $0 == "rnex*/" { next }
113
119
  $0 == ".rnex" || $0 == "rnex" { next }
114
120
  $0 == local_cfg || $0 == ".rnex.local.yaml" { next }
@@ -136,7 +142,8 @@ reconcile_gitignore() {
136
142
  # Universal search tool ignore file (ripgrep, Claude Code, VS Code, Zed)
137
143
  ensure_provider_ignore "$_dir/.ignore" \
138
144
  "Member repos (un-ignored for ripgrep, Claude Code, VS Code, and search tools)" \
139
- "Created .ignore (un-ignoring member repos for search tools)"
145
+ "Created .ignore (un-ignoring member repos for search tools)" \
146
+ "!${_active_repos_dir}/*"
140
147
  }
141
148
 
142
149
  # Clean managed Repo Nexus ignore block from .gitignore, removing file if empty
@@ -268,96 +275,200 @@ reconcile_ai_instructions_files() {
268
275
  done
269
276
  }
270
277
 
271
- # Compile the unified .rnex/ai-instructions.md file consumed by AI coding agents.
272
- # Aggregates sample template instructions and active plugin instruction sections.
273
- build_ai_instructions() {
274
- _dir="${1:-$NEXUS_DIR}"
275
- _ai_file="$_dir/.rnex/ai-instructions.md"
276
- mkdir -p "$_dir/.rnex"
278
+ # Return 0 if a plugin is an IDE/AI provider integration (explicitly declares
279
+ # type: provider or owns a top-level instruction file such as CLAUDE.md).
280
+ # Provider setup docs are never compiled into .rnex/ai-instructions.md.
281
+ plugin_is_provider() {
282
+ _pip_name="$1"
283
+ _pip_pdir="${2:-}"
284
+ [ -n "$_pip_pdir" ] || _pip_pdir="$(find_plugin_dir "$_pip_name" 2>/dev/null || true)"
285
+ if [ -n "$_pip_pdir" ] && [ -f "$_pip_pdir/plugin.yaml" ]; then
286
+ _pip_type="$(plugin_get_field "$_pip_pdir" "type" 2>/dev/null || true)"
287
+ case "$_pip_type" in
288
+ provider) return 0 ;;
289
+ workflow) return 1 ;;
290
+ esac
291
+ fi
292
+ [ -n "$(plugin_get_instruction_file "$_pip_name" "$_pip_pdir" 2>/dev/null || true)" ]
293
+ }
277
294
 
278
- _tmpl_file=""
279
- for _cand in \
280
- "$_dir/templates/ai-instructions.sample.md" \
281
- "$SCRIPT_LOCATION/templates/ai-instructions.sample.md" \
282
- "$(dirname "$SCRIPT_LOCATION")/templates/ai-instructions.sample.md"; do
283
- if [ -f "$_cand" ]; then
284
- _tmpl_file="$_cand"
285
- break
286
- fi
287
- done
295
+ # Escape a value for safe use inside a Markdown table cell.
296
+ _ai_md_cell() {
297
+ printf '%s' "$1" | sed -e 's/|/\\|/g'
298
+ }
288
299
 
289
- _out_tmp="$(mktemp)"
290
- if [ -n "$_tmpl_file" ]; then
291
- cat "$_tmpl_file" > "$_out_tmp"
292
- else
293
- cat > "$_out_tmp" <<'BASE_AI_EOF'
294
- # Multi-Repo AI Workspace Context
300
+ # Join newline-separated items into a "`a`, `b`" Markdown list on one line.
301
+ _ai_md_code_list() {
302
+ awk 'NF { printf "%s`%s`", (n++ ? ", " : ""), $0 } END { if (n) printf "\n" }'
303
+ }
295
304
 
296
- This workspace operates as a **Repo Nexus Virtual Meta-Repo** uniting independent repositories.
305
+ # Emit instruction files of enabled non-provider, non-built-in plugins (custom workflow plugins).
306
+ _ai_emit_workflow_plugin_instructions() {
307
+ _aewp_dir="$1"; _aewp_p="$2"
308
+ _aewp_pdir="$(find_plugin_dir "$_aewp_p" 2>/dev/null || true)"
309
+ _aewp_files=""
310
+ if [ -n "$_aewp_pdir" ] && [ -f "$_aewp_pdir/plugin.yaml" ]; then
311
+ for _aewp_item in $(plugin_list_instructions "$_aewp_pdir" 2>/dev/null || true); do
312
+ _aewp_src="$(printf '%s' "${_aewp_item%%:*}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
313
+ [ -n "$_aewp_src" ] || continue
314
+ if [ -f "$_aewp_dir/.rnex/plugins/$_aewp_p/$_aewp_src" ]; then
315
+ _aewp_files="${_aewp_files:+$_aewp_files }$_aewp_dir/.rnex/plugins/$_aewp_p/$_aewp_src"
316
+ elif [ -f "$_aewp_pdir/$_aewp_src" ]; then
317
+ _aewp_files="${_aewp_files:+$_aewp_files }$_aewp_pdir/$_aewp_src"
318
+ fi
319
+ done
320
+ fi
321
+ if [ -z "$_aewp_files" ]; then
322
+ if [ -f "$_aewp_dir/.rnex/plugins/$_aewp_p/instructions.md" ]; then
323
+ _aewp_files="$_aewp_dir/.rnex/plugins/$_aewp_p/instructions.md"
324
+ elif [ -n "$_aewp_pdir" ] && [ -f "$_aewp_pdir/instructions.md" ]; then
325
+ _aewp_files="$_aewp_pdir/instructions.md"
326
+ fi
327
+ fi
328
+ for _aewp_f in $_aewp_files; do
329
+ printf "\n### Plugin Directives (\`%s\`)\n" "$_aewp_p"
330
+ # Demote headings so plugin docs nest under Section 4.
331
+ sed -e 's/^\(#\{1,\}\) /\1## /' "$_aewp_f"
332
+ done
333
+ }
297
334
 
298
- ## Routing Protocol for AI Assistants
335
+ # Render the full deterministic contents of .rnex/ai-instructions.md to stdout.
336
+ # Output depends only on the merged configuration and RNEX_VERSION.
337
+ render_ai_instructions() {
338
+ _rai_dir="${1:-$NEXUS_DIR}"
339
+ _rai_old_nexus="${NEXUS_DIR:-}"
340
+ _rai_old_wy="${WORKSPACE_YAML:-}"
341
+ _rai_old_wly="${WORKSPACE_LOCAL_YAML:-}"
342
+ if [ -z "${NEXUS_DIR:-}" ] || [ "$_rai_dir" != "${NEXUS_DIR:-}" ]; then
343
+ NEXUS_DIR="$_rai_dir"
344
+ WORKSPACE_YAML="$_rai_dir/${RNEX_CONFIG_FILE:-rnex.yaml}"
345
+ WORKSPACE_LOCAL_YAML="$_rai_dir/${RNEX_LOCAL_CONFIG_FILE:-.local.rnex.yaml}"
346
+ fi
347
+ _rai_rd="$(yaml_get_repos_dir 2>/dev/null || true)"
348
+ [ -n "$_rai_rd" ] || _rai_rd="repos"
349
+ _rai_ws="$(yaml_get_top_level "name" 2>/dev/null || true)"
350
+ [ -n "$_rai_ws" ] || _rai_ws="$(basename "$_rai_dir")"
351
+ _rai_plugins="$(yaml_list_enabled_plugins_sorted 2>/dev/null || true)"
352
+
353
+ _rai_kp=0
354
+ _rai_wiki=""
355
+ _rai_src_dirs=""
356
+ if printf '%s\n' "$_rai_plugins" | grep -qx "karpathy-llm"; then
357
+ _rai_kp=1
358
+ _rai_wiki="$(yaml_get_merged_plugin_config "karpathy-llm" "wiki_dir" "wiki" 2>/dev/null | sed -n '1p')"
359
+ _rai_wiki="${_rai_wiki%/}"
360
+ [ -n "$_rai_wiki" ] || _rai_wiki="wiki"
361
+ _rai_src_dirs="$(yaml_get_merged_plugin_config "karpathy-llm" "sources" 2>/dev/null | grep -v '[*?]' | sed -e 's#/*$#/#' | _ai_md_code_list)"
362
+ fi
299
363
 
300
- ### Mandatory Session Startup
301
- Execute in sequence before task execution:
302
- 1. **Read Configuration First (Highest Priority)**: Read `.local.rnex.yaml` (if present) and `rnex.yaml` to identify active member repositories (`repos/`) and enabled plugins.
303
- 2. **Plugin & Skill Routing**: Inspect active plugin instructions under `.rnex/plugins/<plugin-name>/`, and core agentic skills under `.rnex/skills/` when relevant.
304
- 3. **Targeted Member Repository Access Only**: Navigate directly to specific files in `repos/<name>/` relevant to the user request. Avoid blind repository-wide scans or unbounded searches across `repos/`.
364
+ # Header & Section 1
365
+ printf '# Repo Nexus Workspace Instructions (rnex v%s)\n\n' "${RNEX_VERSION:-unknown}"
366
+ printf "> Pre-compiled from merged workspace configuration (\`.local.rnex.yaml\` > \`rnex.yaml\`).\n\n"
367
+ printf '## 1. Strict Operating Constraints\n'
368
+ printf -- '- **NO CONFIG READS**: DO NOT read or search for rnex.yaml or .local.rnex.yaml. The complete merged configuration is embedded in Section 2.\n'
369
+ printf -- '- **READ FILES ONCE**: Read each file at most once per session. Never re-read a file already in context.\n'
370
+ if [ "$_rai_kp" -eq 1 ]; then
371
+ printf -- "- **NO BLIND SCANS**: Never run broad directory scans or unbounded searches across \`%s/\`%s.\n" "$_rai_rd" "${_rai_src_dirs:+ or raw intake directories ($_rai_src_dirs)}"
372
+ else
373
+ printf -- "- **NO BLIND SCANS**: Never run broad directory scans or unbounded searches across \`%s/\`.\n" "$_rai_rd"
374
+ fi
305
375
 
306
- ## Subagents
307
- Autonomous subagents are defined under `.rnex/agents/` and active plugin agents under `.rnex/plugins/<plugin-name>/agents/`.
376
+ # Section 2
377
+ printf '\n## 2. Merged Workspace Configuration\n'
378
+ printf -- "- **Workspace**: \`%s\`\n" "$_rai_ws"
379
+ printf -- "- **Repositories Root**: \`%s/\`\n" "$_rai_rd"
380
+ _rai_pl="$(printf '%s\n' "$_rai_plugins" | _ai_md_code_list)"
381
+ printf -- '- **Enabled Plugins**: %s\n' "${_rai_pl:-_none_}"
382
+
383
+ _rai_rows=""
384
+ _rai_disabled=""
385
+ for _rai_r in $(yaml_list_all_repos_sorted 2>/dev/null || true); do
386
+ if ! is_enabled_val "$(yaml_get_merged_repo_field "$_rai_r" "enabled" "true")"; then
387
+ _rai_disabled="${_rai_disabled}${_rai_r}
388
+ "
389
+ continue
390
+ fi
391
+ _rai_br="$(yaml_get_merged_repo_field "$_rai_r" "branch" "main")"
392
+ _rai_mode="READ-WRITE"
393
+ is_truthy "$(yaml_get_merged_repo_field "$_rai_r" "readonly" "false")" && _rai_mode="READ-ONLY"
394
+ _rai_desc="$(_ai_md_cell "$(yaml_get_merged_repo_field "$_rai_r" "description" "")")"
395
+ _rai_rows="${_rai_rows}| \`${_rai_r}\` | \`${_rai_rd}/${_rai_r}/\` | \`${_rai_br}\` | \`${_rai_mode}\` | ${_rai_desc} |
396
+ "
397
+ done
308
398
 
309
- ## Member Repositories (`repos/<name>/`)
310
- Each member repository is an autonomous Git repository. Inspect only targeted files required for the task.
311
- If repository-specific context exists, it is stored under `repos/<name>/.rnex/`.
312
- Repositories marked `readonly: true` in configuration are reference-only: DO NOT modify, write to, or commit changes in read-only repositories; use them strictly for information, code exploration, and schema references.
399
+ printf '\n### Active Member Repositories\n'
400
+ if [ -n "$_rai_rows" ]; then
401
+ printf '| Repository | Path | Branch | Mode | Description |\n'
402
+ printf '| :--- | :--- | :--- | :--- | :--- |\n'
403
+ printf '%s' "$_rai_rows"
404
+ else
405
+ printf '_No active member repositories._\n'
406
+ fi
407
+ if [ -n "$_rai_disabled" ]; then
408
+ printf '\n- **Disabled Repositories (Do Not Access)**: %s\n' "$(printf '%s' "$_rai_disabled" | _ai_md_code_list)"
409
+ fi
313
410
 
314
- ## Workspace Maintenance
315
- When workspace configuration, routing blocks, plugin assets, or member repository structures require reconciliation or schema upgrades:
316
- - Run `rnex sync` (or `rnex status` to check workspace health).
317
- - Use `rnex sync -y` to non-destructively apply configuration version upgrades automatically.
411
+ if [ "$_rai_kp" -eq 1 ]; then
412
+ _rai_srcs="$(yaml_get_merged_plugin_config "karpathy-llm" "sources" 2>/dev/null | _ai_md_code_list)"
413
+ printf "\n### Resolved Knowledge Base (\`karpathy-llm\`)\n"
414
+ printf -- "- **Curated Wiki Path**: \`%s/\`\n" "$_rai_wiki"
415
+ printf -- "- **Raw Intake Sources**: %s *(read-only inputs used strictly during \`rnex plugin karpathy-llm ingest\`; do not browse during normal tasks)*\n" "${_rai_srcs:-_none_}"
416
+ fi
318
417
 
319
- ## Git Operations
320
- Commit and push changes directly within the respective member repository root (`repos/<name>/`). For read-only repositories (`readonly: true`), never commit, edit, or push changes.
321
- BASE_AI_EOF
418
+ # Section 3
419
+ printf '\n## 3. Mandatory Execution Sequence\n'
420
+ printf 'Execute these steps in strict order:\n'
421
+ _rai_n=1
422
+ if [ "$_rai_kp" -eq 1 ]; then
423
+ printf "1. **Step 1 — Read Wiki Hot Cache**: Read \`%s/hot.md\` first for workspace architecture, repository boundaries, and active contracts.\n" "$_rai_wiki"
424
+ printf "2. **Step 2 — Lookup Topic in Wiki Index**: If task details are not fully covered in \`%s/hot.md\`, read \`%s/index.md\` and read only the relevant atomic page(s) in \`%s/\`. Do NOT read raw intake sources%s or \`%s/\` before completing Steps 1–2.\n" "$_rai_wiki" "$_rai_wiki" "$_rai_wiki" "${_rai_src_dirs:+ ($_rai_src_dirs)}" "$_rai_rd"
425
+ _rai_n=3
426
+ fi
427
+ 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"
428
+ _rai_n=$((_rai_n + 1))
429
+ printf "%s. **Step %s — Git & Maintenance**: Commit and push inside \`%s/<name>/\`. Run \`rnex sync\` if workspace state changes.\n" "$_rai_n" "$_rai_n" "$_rai_rd"
430
+
431
+ # Section 4
432
+ printf '\n## 4. Coding & Wiki Directives\n'
433
+ if [ -d "$_rai_dir/.rnex/skills" ] && [ -n "$(ls -A "$_rai_dir/.rnex/skills" 2>/dev/null)" ]; then
434
+ printf -- "- **Skills**: \`.rnex/skills/\` (load a skill only when its task applies).\n"
435
+ fi
436
+ if [ -d "$_rai_dir/.rnex/agents" ] && [ -n "$(ls -A "$_rai_dir/.rnex/agents" 2>/dev/null)" ]; then
437
+ printf -- "- **Subagents**: \`.rnex/agents/\`.\n"
438
+ fi
439
+ if [ "$_rai_kp" -eq 1 ]; then
440
+ printf -- '- **Behavioral Rules**: (1) State assumptions and surface trade-offs before coding; (2) Prefer minimal, non-speculative code; (3) Make surgical edits touching only required lines; (4) Verify changes against concrete goals.\n'
441
+ printf -- "- **Wiki Operations**: Never edit \`%s/\` files ad-hoc. To ingest raw sources or validate wiki frontmatter/links, run \`rnex plugin karpathy-llm ingest\` or \`rnex plugin karpathy-llm lint\` (or load \`.rnex/plugins/karpathy-llm/skills/\` only when executing ingestion/linting).\n" "$_rai_wiki"
322
442
  fi
323
443
 
324
- for _p in $(yaml_list_plugins 2>/dev/null || true); do
325
- [ -n "$_p" ] || continue
326
- yaml_plugin_enabled "$_p" 2>/dev/null || continue
327
- _pdir="$(find_plugin_dir "$_p" 2>/dev/null || true)"
328
- _p_instr_files=""
329
- if [ -n "$_pdir" ] && [ -f "$_pdir/plugin.yaml" ]; then
330
- for _item in $(plugin_list_instructions "$_pdir" 2>/dev/null || true); do
331
- [ -n "$_item" ] || continue
332
- _src="${_item%%:*}"
333
- _src="$(printf '%s' "$_src" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
334
- _found=""
335
- if [ -f "$_dir/.rnex/plugins/$_p/$_src" ]; then
336
- _found="$_dir/.rnex/plugins/$_p/$_src"
337
- elif [ -f "$_pdir/$_src" ]; then
338
- _found="$_pdir/$_src"
339
- fi
340
- if [ -n "$_found" ]; then
341
- _p_instr_files="${_p_instr_files:+$_p_instr_files }$_found"
342
- fi
343
- done
344
- fi
444
+ for _rai_p in $_rai_plugins; do
445
+ [ "$_rai_p" = "karpathy-llm" ] && continue
446
+ plugin_is_provider "$_rai_p" && continue
447
+ _ai_emit_workflow_plugin_instructions "$_rai_dir" "$_rai_p"
448
+ done
345
449
 
346
- if [ -z "$_p_instr_files" ]; then
347
- if [ -f "$_dir/.rnex/plugins/$_p/instructions.md" ]; then
348
- _p_instr_files="$_dir/.rnex/plugins/$_p/instructions.md"
349
- elif [ -n "$_pdir" ] && [ -f "$_pdir/instructions.md" ]; then
350
- _p_instr_files="$_pdir/instructions.md"
351
- fi
352
- fi
450
+ NEXUS_DIR="$_rai_old_nexus"
451
+ WORKSPACE_YAML="$_rai_old_wy"
452
+ WORKSPACE_LOCAL_YAML="$_rai_old_wly"
453
+ }
353
454
 
354
- for _f in $_p_instr_files; do
355
- printf '\n\n' >> "$_out_tmp"
356
- cat "$_f" >> "$_out_tmp"
357
- done
358
- done
455
+ # Compile the unified .rnex/ai-instructions.md file consumed by AI coding agents.
456
+ # Writes atomically and only replaces the file when content changes.
457
+ build_ai_instructions() {
458
+ _dir="${1:-$NEXUS_DIR}"
459
+ _ai_file="$_dir/.rnex/ai-instructions.md"
460
+ mkdir -p "$_dir/.rnex"
461
+ _out_tmp="$(mktemp "$_dir/.rnex/.ai-instructions.XXXXXX")"
462
+ render_ai_instructions "$_dir" > "$_out_tmp"
463
+ if [ -f "$_ai_file" ] && cmp -s "$_out_tmp" "$_ai_file"; then
464
+ rm -f "$_out_tmp"
465
+ else
466
+ mv "$_out_tmp" "$_ai_file"
467
+ fi
468
+ }
359
469
 
360
- mv "$_out_tmp" "$_ai_file"
470
+ generate_ai_instructions() {
471
+ build_ai_instructions "$@"
361
472
  }
362
473
 
363
474
  # ---- Multi-Root IDE Workspace (.code-workspace) ----------------------------
@@ -30,6 +30,10 @@ _rnex_completions() {
30
30
  COMPREPLY=( $(compgen -W "$repo_subcommands" -- "$cur") )
31
31
  return 0
32
32
  ;;
33
+ init)
34
+ COMPREPLY=( $(compgen -W "-y --yes --repos-dir --code-workspace --hooks --no-hooks --copilot --claude --gemini --codex --cursor --windsurf --karpathy" -- "$cur") )
35
+ return 0
36
+ ;;
33
37
  sync)
34
38
  COMPREPLY=( $(compgen -W "-y --yes -q --quiet --upgrade" -- "$cur") )
35
39
  return 0
@@ -122,6 +126,11 @@ _rnex() {
122
126
  _describe -t repos 'repository' repos
123
127
  fi
124
128
  ;;
129
+ init)
130
+ local -a init_opts
131
+ init_opts=('(-y --yes)'{-y,--yes}'[Automatically answer yes to prompts]' '--repos-dir[Directory for member repository clones]:dir:_files -/' '--code-workspace[Configure multi-root workspace file]' '--hooks[Configure automated git hooks]' '--no-hooks[Disable automated git hooks]' '--copilot[Enable Copilot plugin]' '--claude[Enable Claude plugin]' '--gemini[Enable Gemini plugin]' '--codex[Enable Codex plugin]' '--cursor[Enable Cursor plugin]' '--windsurf[Enable Windsurf plugin]' '--karpathy[Enable Karpathy LLM Wiki plugin]')
132
+ _describe -t init_opts 'init option' init_opts
133
+ ;;
125
134
  sync)
126
135
  local -a sync_opts
127
136
  sync_opts=('(-y --yes)'{-y,--yes}'[Automatically answer yes to prompts]' '(-q --quiet)'{-q,--quiet}'[Suppress non-error output]' '--upgrade[Upgrade workspace configuration schema]')
@@ -161,6 +170,10 @@ EOF
161
170
  fish)
162
171
  cat <<'EOF'
163
172
  complete -c rnex -n "__fish_use_subcommand" -a init -d "Initialize a new workspace"
173
+ complete -c rnex -n "__fish_seen_subcommand_from init" -l repos-dir -d "Directory for member repository clones"
174
+ complete -c rnex -n "__fish_seen_subcommand_from init" -l code-workspace -d "Configure multi-root workspace file"
175
+ complete -c rnex -n "__fish_seen_subcommand_from init" -l hooks -d "Configure automated git hooks"
176
+ complete -c rnex -n "__fish_seen_subcommand_from init" -l no-hooks -d "Disable automated git hooks"
164
177
  complete -c rnex -n "__fish_use_subcommand" -a install -d "Install rnex globally"
165
178
  complete -c rnex -n "__fish_use_subcommand" -a repo -d "Member repository management"
166
179
  complete -c rnex -n "__fish_seen_subcommand_from repo" -a "add remove set clone status exec list"
@@ -16,12 +16,21 @@ cmd_init() {
16
16
  _cli_hooks=""
17
17
  _cli_no_hooks=0
18
18
  _cli_plugins=""
19
+ _cli_repos_dir=""
19
20
 
20
21
  while [ $# -gt 0 ]; do
21
22
  case "$1" in
22
23
  -y|--yes) _non_interactive=1 ;;
23
24
  --hooks) _cli_hooks="true" ;;
24
25
  --no-hooks) _cli_no_hooks=1; _cli_hooks="false" ;;
26
+ --repos-dir|--repos_dir)
27
+ shift
28
+ [ -n "${1:-}" ] || die "Option $1 requires a directory path"
29
+ _cli_repos_dir="$1"
30
+ ;;
31
+ --repos-dir=*|--repos_dir=*)
32
+ _cli_repos_dir="${1#*=}"
33
+ ;;
25
34
  --karpathy) _cli_plugins="${_cli_plugins:+$_cli_plugins }karpathy-llm" ;;
26
35
  --no-karpathy) _cli_plugins="$(printf '%s' " $_cli_plugins " | sed -e 's/ karpathy-llm / /g' -e 's/^ *//;s/ *$//')" ;;
27
36
  --plugin|--enable-plugin)
@@ -123,9 +132,21 @@ cmd_init() {
123
132
  fi
124
133
  done
125
134
 
135
+ _init_repos_dir="${_cli_repos_dir:-repos}"
136
+ while :; do
137
+ case "$_init_repos_dir" in
138
+ ./*) _init_repos_dir="${_init_repos_dir#./}" ;;
139
+ *) break ;;
140
+ esac
141
+ done
142
+ while [ "$_init_repos_dir" != "${_init_repos_dir%/}" ] && [ -n "${_init_repos_dir%/}" ]; do
143
+ _init_repos_dir="${_init_repos_dir%/}"
144
+ done
145
+ [ -n "$_init_repos_dir" ] || _init_repos_dir="repos"
146
+
126
147
  _existing_repos=""
127
- if [ -d "$_init_dir/repos" ]; then
128
- for _d in "$_init_dir/repos"/*; do
148
+ if [ -d "$_init_dir/$_init_repos_dir" ]; then
149
+ for _d in "$_init_dir/$_init_repos_dir"/*; do
129
150
  [ -d "$_d" ] || continue
130
151
  _r="$(basename "$_d")"
131
152
  case "$_r" in
@@ -156,7 +177,7 @@ cmd_init() {
156
177
  version: $RNEX_VERSION
157
178
 
158
179
  # Directory for member repository clones
159
- repos_dir: ./repos
180
+ repos_dir: "$_init_repos_dir"
160
181
 
161
182
  # VS Code / Cursor multi-root workspace file (default: false; e.g. true or workspace.code-workspace)
162
183
  code_workspace: ${_cli_code_workspace:-false}
@@ -164,7 +185,7 @@ code_workspace: ${_cli_code_workspace:-false}
164
185
  # Git Integration (Ignore rules & Git hooks)
165
186
  git:
166
187
  ignore:
167
- - "repos/"
188
+ - "$_init_repos_dir/"
168
189
  - "**/.rnex*/"
169
190
  - "**/rnex*/"
170
191
  hooks:
@@ -197,7 +218,9 @@ YAML_EOF
197
218
  reconcile_ai_instructions_files "$_init_dir"
198
219
 
199
220
  # ---- 3. Create repos directory with .gitkeep -----------------------------
200
- _repos_dir="$_init_dir/repos"
221
+ _active_rd="$(yaml_get_repos_dir 2>/dev/null || printf '%s' "${_init_repos_dir:-repos}")"
222
+ [ -n "$_active_rd" ] || _active_rd="${_init_repos_dir:-repos}"
223
+ _repos_dir="$_init_dir/$_active_rd"
201
224
  mkdir -p "$_repos_dir"
202
225
  [ -f "$_repos_dir/.gitkeep" ] || touch "$_repos_dir/.gitkeep"
203
226
 
@@ -205,8 +228,8 @@ YAML_EOF
205
228
  mkdir -p "$_init_dir/.rnex"
206
229
  mkdir -p "$_init_dir/.rnex/plugins"
207
230
  sync_plugins
208
- build_ai_instructions "$_init_dir"
209
231
  sync_skills
232
+ build_ai_instructions "$_init_dir"
210
233
 
211
234
  # ---- 5. Ensure repos/ and local configs are gitignored ---------
212
235
  reconcile_gitignore "$_init_dir"
@@ -217,7 +240,7 @@ YAML_EOF
217
240
  _load_code_workspace "$_cli_code_workspace"
218
241
  _cw_name="$CODE_WORKSPACE_FILE"
219
242
  if [ -n "$_cw_name" ]; then
220
- REPOS_DIR="$_init_dir/repos"
243
+ REPOS_DIR="$_repos_dir"
221
244
  sync_code_workspace
222
245
  fi
223
246
  REPOS_DIR="$_orig_repos"
@@ -234,7 +257,7 @@ YAML_EOF
234
257
  if [ "$_config_created" -eq 1 ]; then
235
258
  printf '\n'
236
259
  log_ok "Initialized Repo Nexus workspace at ${_BOLD}$_init_dir${_NC}"
237
- _created_items="$RNEX_CONFIG_FILE, .rnex/, and repos/"
260
+ _created_items="$RNEX_CONFIG_FILE, .rnex/, and ${_active_rd}/"
238
261
  [ -n "$_cw_name" ] && _created_items="$_created_items (and $_cw_name)"
239
262
  log_dim "Created $_created_items"
240
263
  printf '\n'
@@ -186,6 +186,7 @@ cmd_repo_add() {
186
186
  [ "$_readonly" = "true" ] && yaml_set_local "$_name" "readonly" "true"
187
187
  [ "$_enabled" = "false" ] && yaml_set_local "$_name" "enabled" "false"
188
188
  sync_repo_rnex "$_name"
189
+ build_ai_instructions "$NEXUS_DIR"
189
190
  sync_code_workspace
190
191
  run_hook "after_sync" "$@"
191
192
  printf '\n'
@@ -204,6 +205,7 @@ cmd_repo_add() {
204
205
  [ "$_readonly" = "true" ] && yaml_set "$_name" "readonly" "true"
205
206
  [ "$_enabled" = "false" ] && yaml_set "$_name" "enabled" "false"
206
207
  sync_repo_rnex "$_name"
208
+ build_ai_instructions "$NEXUS_DIR"
207
209
  sync_code_workspace
208
210
  run_hook "after_sync" "$@"
209
211
  printf '\n'
@@ -214,6 +216,7 @@ cmd_repo_add() {
214
216
 
215
217
  yaml_add_repo "$_name" "$_url" "$_enabled" "$_readonly" "$_branch"
216
218
  sync_repo_rnex "$_name"
219
+ build_ai_instructions "$NEXUS_DIR"
217
220
  sync_code_workspace
218
221
  run_hook "after_sync" "$@"
219
222
  printf '\n'
@@ -256,6 +259,7 @@ cmd_repo_remove() {
256
259
  else
257
260
  log_ok "Unregistered repo '$_name'"
258
261
  fi
262
+ build_ai_instructions "$NEXUS_DIR"
259
263
  sync_code_workspace
260
264
  run_hook "after_sync" "$@"
261
265
  }
@@ -338,6 +342,7 @@ cmd_repo_set() {
338
342
  if [ "$_enable_val" = "true" ]; then
339
343
  sync_repo_rnex "$_name"
340
344
  fi
345
+ build_ai_instructions "$NEXUS_DIR"
341
346
  sync_code_workspace
342
347
  run_hook "after_sync" "$@"
343
348
  }
@@ -66,9 +66,11 @@ cmd_status() {
66
66
  fi
67
67
 
68
68
  _gi="$NEXUS_DIR/.gitignore"
69
+ _repos_dir_name="$(yaml_get_repos_dir 2>/dev/null || printf 'repos')"
70
+ [ -n "$_repos_dir_name" ] || _repos_dir_name="repos"
69
71
  _gi_repos=0; _gi_local=0; _gi_has_counter=0; _gi_has_rnex=0; _gi_has_markers=0; _gi_custom_ok=1
70
72
  if [ -f "$_gi" ]; then
71
- grep -q '^repos' "$_gi" 2>/dev/null && _gi_repos=1
73
+ (grep -q "^${_repos_dir_name}/" "$_gi" 2>/dev/null || grep -q "^${_repos_dir_name}\*" "$_gi" 2>/dev/null || grep -q '^repos' "$_gi" 2>/dev/null) && _gi_repos=1
72
74
  grep -qF "$RNEX_LOCAL_CONFIG_FILE" "$_gi" 2>/dev/null && _gi_local=1
73
75
  grep -q "lint_trigger_counter" "$_gi" 2>/dev/null && _gi_has_counter=1
74
76
  grep -q '\*\*/\.rnex\*/' "$_gi" 2>/dev/null && _gi_has_rnex=1
@@ -91,9 +93,9 @@ cmd_status() {
91
93
  fi
92
94
 
93
95
  if [ "$_gi_repos" -eq 1 ] && [ "$_gi_local" -eq 1 ] && [ "$_gi_has_counter" -eq 0 ] && [ "$_gi_has_rnex" -eq 1 ] && [ "$_gi_has_markers" -eq 1 ] && [ "$_gi_custom_ok" -eq 1 ]; then
94
- printf ' %b✓%b Git Ignore: repos/, %s, and **/.rnex*/ ignored in .gitignore\n' "$_G" "$_NC" "$RNEX_LOCAL_CONFIG_FILE"
96
+ printf ' %b✓%b Git Ignore: %s/, %s, and **/.rnex*/ ignored in .gitignore\n' "$_G" "$_NC" "$_repos_dir_name" "$RNEX_LOCAL_CONFIG_FILE"
95
97
  else
96
- printf ' %b!%b Git Ignore: recommend running "rnex sync" to update .gitignore (repos/, local configs)\n' "$_Y" "$_NC"
98
+ printf ' %b!%b Git Ignore: recommend running "rnex sync" to update .gitignore (%s/, local configs)\n' "$_Y" "$_NC" "$_repos_dir_name"
97
99
  fi
98
100
 
99
101
  _git_dir=""
@@ -78,7 +78,7 @@ cmd_help() {
78
78
  -v, --version Show version
79
79
 
80
80
  WORKSPACE & SYSTEM SETUP
81
- init [-y] [--code-workspace [file]] [--hooks|--no-hooks] [--copilot] [--claude] [--gemini] [--codex] [--cursor] [--windsurf] [--karpathy] [dir]
81
+ init [-y] [--repos-dir <dir>] [--code-workspace [file]] [--hooks|--no-hooks] [--copilot] [--claude] [--gemini] [--codex] [--cursor] [--windsurf] [--karpathy] [dir]
82
82
  Initialize a new Repo Nexus workspace (default: AGENTS.md)
83
83
  install [dir] Install rnex & repo-nexus globally into ~/.local/bin (or custom dir)
84
84
  sync [-y] [--quiet] Reconcile workspace, plugins, skills, member .rnex directories, and compile AI instructions
package/lib/hooks.sh CHANGED
@@ -354,6 +354,9 @@ run_git_hook() {
354
354
  _is_blocking=0
355
355
  case "$_hook_name" in
356
356
  pre-commit|pre-push) _is_blocking=1 ;;
357
+ post-merge|post-checkout)
358
+ build_ai_instructions "$NEXUS_DIR" 2>/dev/null || true
359
+ ;;
357
360
  esac
358
361
 
359
362
  _stdin_data=""
package/lib/plugins.sh CHANGED
@@ -412,14 +412,17 @@ _src_has_glob() {
412
412
 
413
413
  # Workspace-relative member repositories directory (default: repos)
414
414
  _plugin_repos_rel_dir() {
415
- _prd="${REPOS_DIR:-}"
416
- if [ -n "$_prd" ]; then
417
- _prd="${_prd#"${NEXUS_DIR:-.}"/}"
415
+ if command -v yaml_get_repos_dir >/dev/null 2>&1; then
416
+ yaml_get_repos_dir
417
+ elif [ -n "${REPOS_DIR_REL:-}" ]; then
418
+ printf '%s' "$REPOS_DIR_REL"
419
+ elif [ -n "${REPOS_DIR:-}" ]; then
420
+ _prd="${REPOS_DIR#"${NEXUS_DIR:-.}"/}"
421
+ while [ "${_prd#./}" != "$_prd" ]; do _prd="${_prd#./}"; done
422
+ printf '%s' "${_prd%/}"
418
423
  else
419
- _prd="repos"
424
+ printf 'repos'
420
425
  fi
421
- while [ "${_prd#./}" != "$_prd" ]; do _prd="${_prd#./}"; done
422
- printf '%s' "${_prd%/}"
423
426
  }
424
427
 
425
428
  # Normalize a source entry: trim whitespace/CR, strip leading ./ and trailing /