repo-nexus 0.9.26 → 0.9.28

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/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  A lightweight, zero-dependency and AI-First **Nexus Repository (Virtual Meta Repository Orchestrator)** for multi-repo workspaces. Repo Nexus organizes independent Git repositories into a unified **nexus repository** and **meta repository** workspace—sharing compiled AI context instructions (`.rnex/ai-instructions.md`) **without Git submodules, monorepo migrations, or symlink fragility**.
16
16
 
17
- - **No Git Submodules or Nested Git Collisions**: Member repositories are physically cloned into your configured `repos_dir` (default: `./repos/`) and strictly ignored by workspace Git. Each repository maintains its own standalone history, remotes, branches, and commits with zero submodule friction.
17
+ - **No Git Submodules or Nested Git Collisions**: Member repositories are physically cloned into your configured `reposDir` (default: `./repos/`) and strictly ignored by workspace Git. Each repository maintains its own standalone history, remotes, branches, and commits with zero submodule friction.
18
18
  - **Unified Workspace for AI Coding Assistants**: Open one root folder to give Cursor, Claude Code, GitHub Copilot, Codex, or Antigravity complete cross-service visibility.
19
19
  - **Two-Level Configuration as Source of Truth**: Shared team manifest in `rnex.yaml` with machine-specific overrides in `.local.rnex.yaml` (highest priority).
20
20
  - **One Command Team Onboarding**: Teammates clone the **meta repository** (**meta repo** / **nexus repo**) and run `rnex clone` to clone and configure all member repositories in seconds.
@@ -51,7 +51,7 @@ A lightweight, zero-dependency and AI-First **Nexus Repository (Virtual Meta Rep
51
51
  | What It Is | What It Isn't |
52
52
  | :--- | :--- |
53
53
  | **A lightweight nexus repository & meta repository CLI** (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. |
54
- | **A Virtual Meta Repo & Nexus Repo orchestrator** managing autonomous member clones in your configured `repos_dir` (default: `./repos/`). | **NOT a build tool or monorepo orchestrator.** It doesn't replace tools like Nx, Turborepo, Cargo, or Gradle. |
54
+ | **A Virtual Meta Repo & Nexus Repo orchestrator** managing autonomous member clones in your configured `reposDir` (default: `./repos/`). | **NOT a build tool or monorepo orchestrator.** It doesn't replace tools like Nx, Turborepo, Cargo, or Gradle. |
55
55
  | **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. |
56
56
  | **Strictly encapsulated.** Internal rnex assets live exclusively in `.rnex/`. | **NOT invasive.** Member repositories remain 100% untouched and clean; zero `.rnex/` folders inside member trees. |
57
57
 
@@ -61,10 +61,10 @@ A lightweight, zero-dependency and AI-First **Nexus Repository (Virtual Meta Rep
61
61
  ## Context Sync & Key Principles
62
62
 
63
63
  1. **Configuration as Single Source of Truth**:
64
- 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`).
64
+ Every agent workflow and command starts by reading the configuration files. `.local.rnex.yaml` takes **highest priority** over `rnex.yaml`. Top-level `reposDir` configures where member repositories reside (default: `repos`).
65
65
 
66
66
  2. **No Git Submodules (Complete Repository Autonomy)**:
67
- Member repositories are cloned directly into your configured `repos_dir` (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.
67
+ Member repositories are cloned directly into your configured `reposDir` (default: `./repos/<name>`). The root workspace `.gitignore` dynamically ignores the configured `reposDir/`, ensuring the workspace repository never tracks or interferes with member Git histories, remotes, branches, or commits.
68
68
 
69
69
  3. **Enabled by Default with Two-Level Merging**:
70
70
  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`.
@@ -23,12 +23,12 @@ cmd_init() {
23
23
  -y|--yes) _non_interactive=1 ;;
24
24
  --hooks) _cli_hooks="true" ;;
25
25
  --no-hooks) _cli_no_hooks=1; _cli_hooks="false" ;;
26
- --repos-dir|--repos_dir)
26
+ --repos-dir)
27
27
  shift
28
28
  [ -n "${1:-}" ] || die "Option $1 requires a directory path"
29
29
  _cli_repos_dir="$1"
30
30
  ;;
31
- --repos-dir=*|--repos_dir=*)
31
+ --repos-dir=*)
32
32
  _cli_repos_dir="${1#*=}"
33
33
  ;;
34
34
  --plugin|--enable-plugin)
@@ -118,7 +118,7 @@ cmd_init() {
118
118
  [ -n "$_pdir" ] || _pdir="$(find_plugin_dir "$_p" 2>/dev/null || true)"
119
119
  _cfg_lines=""
120
120
  if [ -n "$_pdir" ] && [ -f "$_pdir/plugin.yaml" ]; then
121
- _cfg_lines="$(plugin_config_default_lines "$_pdir/plugin.yaml")"
121
+ _cfg_lines="$(plugin_config_default_lines "$_pdir/plugin.yaml" "$_init_repos_dir")"
122
122
  fi
123
123
  if [ -n "$_cfg_lines" ]; then
124
124
  _init_plugins="${_init_plugins} ${_p}:\n${_cfg_lines}\n"
@@ -174,10 +174,10 @@ cmd_init() {
174
174
  version: $RNEX_VERSION
175
175
 
176
176
  # Directory for member repository clones
177
- repos_dir: "$_init_repos_dir"
177
+ reposDir: "$_init_repos_dir"
178
178
 
179
179
  # VS Code / Cursor multi-root workspace file (default: false; e.g. true or workspace.code-workspace)
180
- code_workspace: ${_cli_code_workspace:-false}
180
+ codeWorkspace: ${_cli_code_workspace:-false}
181
181
 
182
182
  # Git Integration (Ignore rules & Git hooks)
183
183
  git:
@@ -191,11 +191,11 @@ git:
191
191
  $_hooks_block
192
192
 
193
193
  # Lifecycle Hooks
194
- rnex-hooks:
195
- before_sync: []
196
- after_sync: []
197
- before_clone: []
198
- after_clone: []
194
+ rnexHooks:
195
+ beforeSync: []
196
+ afterSync: []
197
+ beforeClone: []
198
+ afterClone: []
199
199
 
200
200
  # Workspace plugins
201
201
  plugins:
@@ -100,7 +100,7 @@ cmd_sync() {
100
100
  fi
101
101
  fi
102
102
 
103
- # 3.3. Reconcile member repos (<repos_dir> unlisted pruning & missing clone checks)
103
+ # 3.3. Reconcile member repos (<reposDir> unlisted pruning & missing clone checks)
104
104
  prune_unlisted_repos "$REPOS_DIR"
105
105
  yaml_list_repos | while read -r _name; do
106
106
  [ -n "$_name" ] || continue
@@ -115,9 +115,21 @@ cmd_sync() {
115
115
  # 3.4. Reconcile VS Code / Cursor multi-root workspace if configured
116
116
  sync_code_workspace
117
117
 
118
+ # 3.5. Validate configuration schema, deprecated keys, and declared plugins (Fail-Fast)
119
+ _sync_validation_failed=0
120
+ if command -v validate_workspace_config >/dev/null 2>&1; then
121
+ validate_workspace_config || _sync_validation_failed=1
122
+ fi
123
+ if command -v validate_configured_plugins >/dev/null 2>&1; then
124
+ validate_configured_plugins || _sync_validation_failed=1
125
+ fi
126
+
127
+ _sync_quiet="$_old_sync_quiet"
128
+ if [ "$_sync_validation_failed" -ne 0 ]; then
129
+ return 1
130
+ fi
118
131
  if [ "$_sync_quiet" -eq 0 ]; then
119
132
  log_ok "Sync complete — workspace, plugins, skills, and member repositories reconciled"
120
133
  fi
121
- _sync_quiet="$_old_sync_quiet"
122
134
  return 0
123
135
  }
package/lib/hooks.sh CHANGED
@@ -179,7 +179,7 @@ _run_hook_internal() {
179
179
  done
180
180
  fi
181
181
 
182
- # 2. Execute configured commands from rnex-hooks.<event_name>
182
+ # 2. Execute configured commands from rnexHooks.<hookName>
183
183
  if [ -z "$_hook_target_plugin" ] && [ "${_RNEX_INTERNAL_PLUGIN_ONLY:-0}" != "1" ] && [ "$_ignore_hooks" != "1" ]; then
184
184
  rnex_hooks_run_stage "$_hook_root" "$_hook_phase_cmd" "$@"
185
185
  fi
@@ -193,8 +193,8 @@ _run_hook_internal() {
193
193
  #
194
194
  # Summary:
195
195
  # Executes configured workspace lifecycle hook commands for a specified stage
196
- # (e.g., pre_sync, post_sync, after_sync, before_sync, after_init) strictly
197
- # declared in rnex.yaml or .local.rnex.yaml under rnex-hooks.<stage>.
196
+ # (e.g., preSync, postSync, afterSync, beforeSync, afterInit) strictly
197
+ # declared in rnex.yaml or .local.rnex.yaml under rnexHooks.<stage>.
198
198
  # Adheres to strict opt-in execution: if no hook commands are declared for
199
199
  # the stage, zero commands are executed.
200
200
  #
@@ -232,27 +232,32 @@ rnex_hooks_run_stage() {
232
232
  [ "${RNEX_IGNORE_HOOKS:-0}" = "1" ] && return 0
233
233
 
234
234
  _stage_norm="$(printf '%s' "$_rhrs_stage" | tr '-' '_')"
235
+ if command -v _yaml_to_camel >/dev/null 2>&1; then
236
+ _stage_camel="$(_yaml_to_camel "$_stage_norm")"
237
+ else
238
+ _stage_camel="$(printf '%s' "$_stage_norm" | awk -F'_' '{ out=$1; for(i=2;i<=NF;i++) if($i!="") out=out toupper(substr($i,1,1)) substr($i,2); print out }')"
239
+ fi
235
240
 
236
241
  # Re-entrant loop guard: skip re-entrant execution of this hook event
237
242
  case ":${RNEX_HOOK_ACTIVE:-}:" in
238
- *":${_stage_norm}:"*) return 0 ;;
243
+ *":${_stage_camel}:"*|*":${_stage_norm}:"*) return 0 ;;
239
244
  esac
240
245
 
241
246
  _stage_cmds=""
242
247
  if command -v rnex_yaml_get_rnex_hooks >/dev/null 2>&1; then
243
- _stage_cmds="$(rnex_yaml_get_rnex_hooks "$_rhrs_root" "$_stage_norm" 2>/dev/null || true)"
248
+ _stage_cmds="$(rnex_yaml_get_rnex_hooks "$_rhrs_root" "$_stage_camel" 2>/dev/null || true)"
244
249
  elif command -v yaml_get_rnex_hook_commands >/dev/null 2>&1; then
245
- _stage_cmds="$(yaml_get_rnex_hook_commands "$_stage_norm" 2>/dev/null || true)"
250
+ _stage_cmds="$(yaml_get_rnex_hook_commands "$_stage_camel" 2>/dev/null || true)"
246
251
  fi
247
252
 
248
253
  [ -n "$_stage_cmds" ] || return 0
249
254
 
250
255
  _prev_active="${RNEX_HOOK_ACTIVE:-}"
251
- export RNEX_HOOK_ACTIVE="${RNEX_HOOK_ACTIVE:+${RNEX_HOOK_ACTIVE}:}${_stage_norm}"
256
+ export RNEX_HOOK_ACTIVE="${RNEX_HOOK_ACTIVE:+${RNEX_HOOK_ACTIVE}:}${_stage_camel}"
252
257
 
253
258
  _is_blocking=0
254
- case "$_stage_norm" in
255
- before_*|pre_*) _is_blocking=1 ;;
259
+ case "$_stage_camel" in
260
+ before*|pre*) _is_blocking=1 ;;
256
261
  esac
257
262
 
258
263
  # shellcheck disable=SC2031
@@ -283,7 +288,7 @@ rnex_hooks_run_stage() {
283
288
  RNEX_CONFIG_MERGED="$_rhrs_config"
284
289
  RNEX_CMD="$_rhrs_cmd"
285
290
  RNEX_ARGS="$_rhrs_args"
286
- RNEX_HOOK_EVENT="$_stage_norm"
291
+ RNEX_HOOK_EVENT="$_stage_camel"
287
292
  RNEX_HOOK_ARGS="$_rhrs_args"
288
293
  RNEX_QUIET="$_rhrs_quiet"
289
294
  RNEX_PROVIDER_SKILL_DIRS="$_rhrs_skill_dirs"
@@ -300,7 +305,7 @@ rnex_hooks_run_stage() {
300
305
  RNEX_CONFIG_MERGED="$_rhrs_config"
301
306
  RNEX_CMD="$_rhrs_cmd"
302
307
  RNEX_ARGS="$_rhrs_args"
303
- RNEX_HOOK_EVENT="$_stage_norm"
308
+ RNEX_HOOK_EVENT="$_stage_camel"
304
309
  RNEX_HOOK_ARGS="$_rhrs_args"
305
310
  RNEX_QUIET="$_rhrs_quiet"
306
311
  RNEX_PROVIDER_SKILL_DIRS="$_rhrs_skill_dirs"
package/lib/plugins.sh CHANGED
@@ -409,94 +409,154 @@ plugin_list_instructions() {
409
409
  ' "$_pdir/plugin.yaml"
410
410
  }
411
411
 
412
- # Substitute configurable placeholders declared in plugin.yaml config_defaults in template destination paths.
413
- plugin_resolve_placeholders() {
414
- _p="$1"; _pd="$2"; _str="$3"
415
- _res="$(printf '%s' "$_str" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -d "'\"")"
412
+ # Escape \, &, and | characters in a string for safe use as a POSIX sed replacement.
413
+ #
414
+ # @param $1 raw_value Unescaped replacement value.
415
+ # @returns Escaped string on stdout.
416
+ # @pure
417
+ _sed_escape_replacement() {
418
+ printf '%s' "$1" | sed -e 's/[\\&|]/\\&/g'
419
+ }
416
420
 
417
- if [ -f "$_pd/plugin.yaml" ]; then
418
- _keys="$(awk '
419
- /^config_defaults:[ ]*$/ || /^config_defaults:[ ]*#/ { in_c=1; next }
420
- in_c && /^[^ #]/ { exit }
421
- in_c && /^[ ]*[a-zA-Z0-9_.-]+:[ ]*/ {
421
+ # Extract direct scalar configuration key names declared under config_defaults: in
422
+ # a plugin manifest, skipping structured sequence/map keys (sources, hooks).
423
+ #
424
+ # @param $1 manifest_file Path to plugin.yaml.
425
+ # @returns Newline-separated key names on stdout.
426
+ # @pure
427
+ _plugin_config_default_keys() {
428
+ _pcdk_file="$1"
429
+ [ -f "$_pcdk_file" ] || return 0
430
+ awk '
431
+ /^config_defaults:[ ]*(#.*)?$/ { in_c=1; def_indent=-1; next }
432
+ in_c && /^[^ #]/ { exit }
433
+ in_c && /^[ ]*(#|$)/ { next }
434
+ in_c {
435
+ match($0, /^[ ]*/)
436
+ ind = RLENGTH
437
+ if (def_indent == -1) def_indent = ind
438
+ if (ind == def_indent && $0 ~ /^[ ]*[a-zA-Z0-9_.-]+:[ ]*/) {
422
439
  k = $0
423
440
  sub(/^[ ]*/, "", k)
424
441
  sub(/:.*/, "", k)
425
- print k
442
+ if (k != "sources" && k != "hooks") print k
426
443
  }
427
- ' "$_pd/plugin.yaml")"
428
-
429
- for _k in $_keys; do
430
- _v="$(yaml_plugin_get "$_p" "$_k" 2>/dev/null || true)"
431
- if [ -z "$_v" ]; then
432
- _v="$(awk -v k="$_k" '
433
- /^config_defaults:[ ]*$/ || /^config_defaults:[ ]*#/ { in_c=1; next }
434
- in_c && /^[^ #]/ { exit }
435
- in_c && $0 ~ ("^[ ]*" k ":") {
436
- sub("^[ ]*" k ":[ ]*", "")
437
- sub(/[ ]*#.*/, "")
438
- gsub(/["\047]/, "")
439
- print
440
- exit
441
- }
442
- ' "$_pd/plugin.yaml")"
444
+ }
445
+ ' "$_pcdk_file"
446
+ }
447
+
448
+ # Resolve a single scalar plugin configuration value, preferring workspace YAML
449
+ # overrides (.local.rnex.yaml > rnex.yaml) and falling back to plugin.yaml defaults.
450
+ # Normalizes *_dir / dir values as clean relative paths.
451
+ #
452
+ # @param $1 plugin_name Target plugin name.
453
+ # @param $2 plugin_dir Resolved plugin directory.
454
+ # @param $3 key_name Configuration key name.
455
+ # @returns Resolved string value on stdout.
456
+ # @pure
457
+ _plugin_resolve_scalar_value() {
458
+ _prsv_p="$1"; _prsv_pd="$2"; _prsv_k="$3"
459
+ _prsv_v="$(yaml_plugin_get "$_prsv_p" "$_prsv_k" 2>/dev/null || true)"
460
+ if [ -z "$_prsv_v" ] && [ -f "$_prsv_pd/plugin.yaml" ]; then
461
+ _prsv_v="$(awk -v k="$_prsv_k" '
462
+ /^config_defaults:[ ]*(#.*)?$/ { in_c=1; next }
463
+ in_c && /^[^ #]/ { exit }
464
+ in_c && $0 ~ ("^[ ]*" k ":") {
465
+ sub("^[ ]*" k ":[ ]*", "")
466
+ sub(/[ ]*#.*/, "")
467
+ gsub(/["\047]/, "")
468
+ print
469
+ exit
470
+ }
471
+ ' "$_prsv_pd/plugin.yaml")"
472
+ fi
473
+ case "$_prsv_k" in
474
+ *Dir|*_dir|dir) _prsv_v="$(normalize_rel_path "$_prsv_v")" ;;
475
+ esac
476
+ printf '%s' "$_prsv_v"
477
+ }
478
+
479
+ # Substitute configurable placeholders declared in plugin.yaml config_defaults
480
+ # and core workspace metadata ({reposDir}, {plugin_dir}) in template paths.
481
+ #
482
+ # @param $1 plugin_name Target plugin name.
483
+ # @param $2 plugin_dir Resolved plugin directory.
484
+ # @param $3 input_str Path or string containing {placeholder} tokens.
485
+ # @returns Resolved relative path string on stdout.
486
+ # @pure
487
+ plugin_resolve_placeholders() {
488
+ _p="$1"; _pd="$2"; _str="$3"
489
+ _res="$(printf '%s' "$_str" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -d "'\"")"
490
+
491
+ if [ -f "$_pd/plugin.yaml" ]; then
492
+ for _k in $(_plugin_config_default_keys "$_pd/plugin.yaml"); do
493
+ _v="$(_plugin_resolve_scalar_value "$_p" "$_pd" "$_k")"
494
+ if [ -n "$_v" ]; then
495
+ _v_esc="$(_sed_escape_replacement "$_v")"
496
+ _res="$(printf '%s' "$_res" | sed -e "s|{$_k}|$_v_esc|g")"
443
497
  fi
444
- case "$_k" in
445
- *_dir|dir)
446
- _v="$(normalize_rel_path "$_v")"
447
- ;;
448
- esac
449
- [ -n "$_v" ] && _res="$(printf '%s' "$_res" | sed -e "s|{$_k}|$_v|g")"
450
498
  done
451
499
  fi
452
500
 
501
+ _rdir_v="$(normalize_rel_path "$(_plugin_repos_rel_dir)")"
502
+ if [ -n "$_rdir_v" ]; then
503
+ _rdir_esc="$(_sed_escape_replacement "$_rdir_v")"
504
+ _res="$(printf '%s' "$_res" | sed -e "s|{reposDir}|$_rdir_esc|g")"
505
+ fi
506
+ _pdir_esc="$(_sed_escape_replacement ".rnex/plugins/$_p")"
507
+ _res="$(printf '%s' "$_res" | sed -e "s|{plugin_dir}|$_pdir_esc|g")"
508
+
453
509
  _res="$(printf '%s' "$_res" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -d "'\"" | sed -e 's#^\./##')"
454
510
 
455
511
  printf '%s' "$_res"
456
512
  }
457
513
 
514
+ # Instantiate a Markdown template or AI asset file by resolving all workspace,
515
+ # manifest, and plugin config placeholders into concrete values.
516
+ # Fast-paths to raw copy when the source file contains no {placeholder} tokens.
517
+ #
518
+ # @param $1 plugin_name Target plugin name.
519
+ # @param $2 plugin_dir Resolved source plugin directory.
520
+ # @param $3 src_file Source file path.
521
+ # @param $4 dest_file Destination file path.
522
+ # @returns 0 on success.
523
+ # @sideEffects Writes instantiated file to $4.
458
524
  plugin_instantiate_template() {
459
525
  _p="$1"; _pd="$2"; _src="$3"; _dest="$4"
460
526
 
461
- # {sources}: human-readable list of configured intake sources (sed-escaped)
527
+ # Fast path: avoid spawning awk/sed when source file has no {placeholder} tokens
528
+ if ! grep -qE '\{[a-zA-Z0-9_-]+\}' "$_src" 2>/dev/null; then
529
+ cp "$_src" "$_dest"
530
+ return 0
531
+ fi
532
+
533
+ # Core workspace & plugin metadata placeholders (sed-escaped)
534
+ _r_val="$(normalize_rel_path "$(_plugin_repos_rel_dir)")"
535
+ _r_val="$(_sed_escape_replacement "$_r_val")"
536
+
537
+ _sd_val="$(normalize_rel_path "$(plugin_get_skill_dir "$_p" 2>/dev/null || true)")"
538
+ _sd_val="$(_sed_escape_replacement "$_sd_val")"
539
+
540
+ _if_val=""
541
+ [ -f "$_pd/plugin.yaml" ] && _if_val="$(normalize_rel_path "$(plugin_get_field "$_pd" "instruction_file" 2>/dev/null || true)")"
542
+ _if_val="$(_sed_escape_replacement "$_if_val")"
543
+
544
+ _pdir_val="$(_sed_escape_replacement ".rnex/plugins/$_p")"
545
+
546
+ # {sources}: human-readable list of resolved intake sources (or "(none configured)")
462
547
  _s_val="$(plugin_sources_display "$_p" 2>/dev/null || true)"
463
- _s_val="$(printf '%s' "$_s_val" | sed -e 's/[\\&|]/\\&/g')"
548
+ [ -n "$_s_val" ] || _s_val="(none configured)"
549
+ _s_val="$(_sed_escape_replacement "$_s_val")"
464
550
 
465
551
  # {today}: current UTC date (ISO-8601, YYYY-MM-DD)
466
552
  _t_val="$(date -u +%Y-%m-%d 2>/dev/null || date +%Y-%m-%d 2>/dev/null || date +%F 2>/dev/null || echo "2026-10-15")"
467
553
 
468
554
  cp "$_src" "$_dest"
469
555
  if [ -f "$_pd/plugin.yaml" ]; then
470
- _keys="$(awk '
471
- /^config_defaults:[ ]*$/ || /^config_defaults:[ ]*#/ { in_c=1; next }
472
- in_c && /^[^ #]/ { exit }
473
- in_c && /^[ ]*[a-zA-Z0-9_.-]+:[ ]*/ {
474
- k = $0
475
- sub(/^[ ]*/, "", k)
476
- sub(/:.*/, "", k)
477
- print k
478
- }
479
- ' "$_pd/plugin.yaml")"
480
- for _k in $_keys; do
481
- _v="$(yaml_plugin_get "$_p" "$_k" 2>/dev/null || true)"
482
- if [ -z "$_v" ]; then
483
- _v="$(awk -v k="$_k" '
484
- /^config_defaults:[ ]*$/ || /^config_defaults:[ ]*#/ { in_c=1; next }
485
- in_c && /^[^ #]/ { exit }
486
- in_c && $0 ~ ("^[ ]*" k ":") {
487
- sub("^[ ]*" k ":[ ]*", "")
488
- sub(/[ ]*#.*/, "")
489
- gsub(/["\047]/, "")
490
- print
491
- exit
492
- }
493
- ' "$_pd/plugin.yaml")"
494
- fi
495
- case "$_k" in
496
- *_dir|dir) _v="$(normalize_rel_path "$_v")" ;;
497
- esac
556
+ for _k in $(_plugin_config_default_keys "$_pd/plugin.yaml"); do
557
+ _v="$(_plugin_resolve_scalar_value "$_p" "$_pd" "$_k")"
498
558
  if [ -n "$_v" ]; then
499
- _v_esc="$(printf '%s' "$_v" | sed -e 's/[\\&|]/\\&/g')"
559
+ _v_esc="$(_sed_escape_replacement "$_v")"
500
560
  _tmp_inst="$(mktemp)"
501
561
  sed -e "s|{$_k}|$_v_esc|g" "$_dest" > "$_tmp_inst" && mv "$_tmp_inst" "$_dest"
502
562
  fi
@@ -504,14 +564,25 @@ plugin_instantiate_template() {
504
564
  fi
505
565
 
506
566
  _tmp_inst="$(mktemp)"
507
- sed -e "s|{sources}|$_s_val|g" \
567
+ sed -e "s|{reposDir}|$_r_val|g" \
568
+ -e "s|{skill_dir}|$_sd_val|g" \
569
+ -e "s|{instruction_file}|$_if_val|g" \
570
+ -e "s|{plugin_dir}|$_pdir_val|g" \
571
+ -e "s|{sources}|$_s_val|g" \
508
572
  -e "s|{today}|$_t_val|g" \
509
573
  "$_dest" > "$_tmp_inst" && mv "$_tmp_inst" "$_dest"
510
574
  }
511
575
 
512
- # Deterministically sync plugin asset directories and manifest files into destination
576
+ # Deterministically sync plugin asset directories and manifest files into destination.
577
+ # Compiles AI-facing Markdown files via plugin_instantiate_template so runtime agent
578
+ # artifacts under .rnex/plugins/<name>/ contain concrete workspace paths without placeholders.
579
+ #
580
+ # @param $1 src_dir Resolved plugin source directory.
581
+ # @param $2 dest_dir Target scoped directory (.rnex/plugins/<name>).
582
+ # @param $3 plugin_name Optional explicit plugin name (defaults to basename of dest_dir).
583
+ # @sideEffects Reconciles destination tree and projected files.
513
584
  sync_plugin_bundle() {
514
- _spb_src="$1"; _spb_dest="$2"
585
+ _spb_src="$1"; _spb_dest="$2"; _spb_pname="${3:-$(basename "$2")}"
515
586
  [ -n "$_spb_src" ] && [ -n "$_spb_dest" ] || return 0
516
587
  [ "$_spb_src" != "$_spb_dest" ] || return 0
517
588
 
@@ -523,6 +594,11 @@ sync_plugin_bundle() {
523
594
  cp -R "$_spb_src/$_sub"/. "$_spb_dest/$_sub"/ 2>/dev/null || true
524
595
  if [ "$_sub" = "hooks" ] || [ "$_sub" = "commands" ] || [ "$_sub" = "bin" ]; then
525
596
  chmod +x "$_spb_dest/$_sub"/* 2>/dev/null || true
597
+ elif [ "$_sub" = "rules" ] || [ "$_sub" = "workflows" ] || [ "$_sub" = "instructions" ] || [ "$_sub" = "skills" ] || [ "$_sub" = "agents" ]; then
598
+ find "$_spb_src/$_sub" -type f -name '*.md' 2>/dev/null | while IFS= read -r _spb_md; do
599
+ _spb_rel="${_spb_md#"$_spb_src"/}"
600
+ plugin_instantiate_template "$_spb_pname" "$_spb_src" "$_spb_md" "$_spb_dest/$_spb_rel"
601
+ done
526
602
  fi
527
603
  else
528
604
  rm -rf "${_spb_dest:?}/$_sub"
@@ -531,7 +607,14 @@ sync_plugin_bundle() {
531
607
  _spb_ai_fn="${RNEX_PLUGIN_AI_FILENAME:-ai-instructions.md}"
532
608
  for _meta in plugin.yaml instructions.md README.md "$_spb_ai_fn"; do
533
609
  if [ -f "$_spb_src/$_meta" ]; then
534
- cp "$_spb_src/$_meta" "$_spb_dest/$_meta"
610
+ case "$_meta" in
611
+ instructions.md|"$_spb_ai_fn")
612
+ plugin_instantiate_template "$_spb_pname" "$_spb_src" "$_spb_src/$_meta" "$_spb_dest/$_meta"
613
+ ;;
614
+ *)
615
+ cp "$_spb_src/$_meta" "$_spb_dest/$_meta"
616
+ ;;
617
+ esac
535
618
  elif [ "$_meta" = "$_spb_ai_fn" ]; then
536
619
  # Prune stale projected ai-instructions.md if removed from source plugin
537
620
  rm -f "${_spb_dest:?}/$_meta" 2>/dev/null || true
@@ -579,24 +662,14 @@ sync_plugins() {
579
662
 
580
663
  # OWASP A03 / Path Traversal Guard: plugin name must strictly match allowlist
581
664
  case "$_pname" in
582
- *[!a-zA-Z0-9._-]*|"")
583
- log_warn "Skipping invalid plugin name containing disallowed characters: '$_pname'"
584
- continue
585
- ;;
586
- .|..)
587
- log_warn "Skipping invalid plugin name: '$_pname'"
588
- continue
589
- ;;
665
+ *[!a-zA-Z0-9._-]*|""|.|..) continue ;;
590
666
  esac
591
667
 
592
668
  _pdir="$(plugin_resolve_dir "$_pname" 2>/dev/null || true)"
593
669
  [ -n "$_pdir" ] || _pdir="$(find_plugin_dir "$_pname" 2>/dev/null || true)"
594
- if [ -z "$_pdir" ]; then
595
- log_warn "Plugin '$_pname' declared in config but not found on disk"
596
- continue
597
- fi
670
+ [ -n "$_pdir" ] || continue
598
671
 
599
- sync_plugin_bundle "$_pdir" "$NEXUS_DIR/.rnex/plugins/$_pname"
672
+ sync_plugin_bundle "$_pdir" "$NEXUS_DIR/.rnex/plugins/$_pname" "$_pname"
600
673
 
601
674
  # Provision explicit directory sources declared under plugins.<name>.sources (e.g. ./docs)
602
675
  for _sdir in $(plugin_source_dirs "$_pname" 2>/dev/null); do
@@ -642,6 +715,40 @@ sync_plugins() {
642
715
  done
643
716
  }
644
717
 
718
+ # Validate all plugin entries declared in rnex.yaml and .local.rnex.yaml.
719
+ # Enforces name allowlisting (OWASP A03) and verifies every configured plugin
720
+ # resolves to a valid directory, emitting non-suppressible stderr errors when
721
+ # stale or nonexistent plugins (e.g. removed names) remain in config.
722
+ #
723
+ # @returns 0 if all configured plugins resolve; 1 if any unknown plugin is declared.
724
+ # @sideEffects Emits diagnostic errors via log_err (stderr).
725
+ validate_configured_plugins() {
726
+ _vcp_rc=0
727
+ _vcp_list="$(yaml_list_plugins 2>/dev/null || true)"
728
+ [ -n "$_vcp_list" ] || return 0
729
+
730
+ while IFS= read -r _vcp_name || [ -n "$_vcp_name" ]; do
731
+ [ -n "$_vcp_name" ] || continue
732
+
733
+ case "$_vcp_name" in
734
+ *[!a-zA-Z0-9._-]*|""|.|..)
735
+ log_err "Invalid plugin name '$_vcp_name' declared in configuration (disallowed characters or path traversal rejected)."
736
+ continue
737
+ ;;
738
+ esac
739
+
740
+ _vcp_dir="$(plugin_resolve_dir "$_vcp_name" 2>/dev/null || true)"
741
+ [ -n "$_vcp_dir" ] || _vcp_dir="$(find_plugin_dir "$_vcp_name" 2>/dev/null || true)"
742
+ if [ -z "$_vcp_dir" ]; then
743
+ log_err "Unknown plugin '$_vcp_name' declared in configuration: plugin does not exist in built-in plugins or via a valid 'path:'. Remove or update 'plugins.$_vcp_name'."
744
+ _vcp_rc=1
745
+ fi
746
+ done <<EOF_VCP
747
+ $_vcp_list
748
+ EOF_VCP
749
+ return "$_vcp_rc"
750
+ }
751
+
645
752
  # ----------------------------------------------------------------------------
646
753
  # Plugin source resolution (directories + POSIX glob patterns)
647
754
  # ----------------------------------------------------------------------------
@@ -688,13 +795,32 @@ _src_is_file_like() {
688
795
  return 1
689
796
  }
690
797
 
798
+ # Expand workspace placeholders (e.g. {reposDir}) inside a configured plugin source
799
+ # specification and normalize it as a clean relative entry.
800
+ #
801
+ # @param $1 raw_entry Source specification string.
802
+ # @param $2 repos_dir Optional relative member repos directory override.
803
+ # @returns Normalized source specification on stdout.
804
+ # @pure
805
+ _plugin_expand_source_entry() {
806
+ _pese_val="$1"
807
+ _pese_rdir="${2:-$(_plugin_repos_rel_dir)}"
808
+ case "$_pese_val" in
809
+ *"{reposDir}"*)
810
+ _pese_esc="$(_sed_escape_replacement "$_pese_rdir")"
811
+ _pese_val="$(printf '%s' "$_pese_val" | sed -e "s|{reposDir}|$_pese_esc|g")"
812
+ ;;
813
+ esac
814
+ _src_normalize_entry "$_pese_val"
815
+ }
816
+
691
817
  # List explicit directory sources of a plugin that rnex may provision (mkdir).
692
818
  # Skips glob patterns, file entries, absolute paths, '..' traversal, the workspace
693
819
  # root, and paths inside the member repositories directory.
694
820
  plugin_source_dirs() {
695
821
  _psd_rdir="$(_plugin_repos_rel_dir)"
696
822
  get_plugin_config_list "$1" "sources" 2>/dev/null | while IFS= read -r _psd_e || [ -n "$_psd_e" ]; do
697
- _psd_e="$(_src_normalize_entry "$_psd_e")"
823
+ _psd_e="$(_plugin_expand_source_entry "$_psd_e" "$_psd_rdir")"
698
824
  case "$_psd_e" in
699
825
  ''|.|/*|..|../*|*/..|*/../*) continue ;;
700
826
  esac
@@ -708,8 +834,9 @@ plugin_source_dirs() {
708
834
 
709
835
  # Human-readable source list for templates, e.g.: `docs/`, `repos/**/README.md`
710
836
  plugin_sources_display() {
837
+ _psy_rdir="$(_plugin_repos_rel_dir)"
711
838
  get_plugin_config_list "$1" "sources" 2>/dev/null | while IFS= read -r _psy_e || [ -n "$_psy_e" ]; do
712
- _psy_e="$(_src_normalize_entry "$_psy_e")"
839
+ _psy_e="$(_plugin_expand_source_entry "$_psy_e" "$_psy_rdir")"
713
840
  [ -n "$_psy_e" ] || continue
714
841
  if _src_is_file_like "$_psy_e"; then
715
842
  printf '\140%s\140\n' "$_psy_e"
package/lib/repos.sh CHANGED
@@ -42,12 +42,12 @@ ensure_repos_dir() {
42
42
  [ -f "$REPOS_DIR/.gitkeep" ] || touch "$REPOS_DIR/.gitkeep"
43
43
  }
44
44
 
45
- # Reconcile the repositories root directory (<repos_dir>) by detecting and
46
- # pruning unlisted or deleted repository directories so that <repos_dir>
45
+ # Reconcile the repositories root directory (<reposDir>) by detecting and
46
+ # pruning unlisted or deleted repository directories so that <reposDir>
47
47
  # contains strictly the repositories currently declared in configuration.
48
48
  #
49
49
  # Responsibility:
50
- # Audits all subdirectories within the active <repos_dir>. Any directory
50
+ # Audits all subdirectories within the active <reposDir>. Any directory
51
51
  # that does not match the resolved path of a repository registered in
52
52
  # rnex.yaml or .local.rnex.yaml is recognized as deleted/unlisted and purged.
53
53
  #
package/lib/workspace.sh CHANGED
@@ -185,7 +185,7 @@ _load_repos_dir() {
185
185
 
186
186
  _load_code_workspace() {
187
187
  _cw="${1:-}"
188
- [ -n "$_cw" ] || _cw="$(yaml_get_top_level "code_workspace")"
188
+ [ -n "$_cw" ] || _cw="$(yaml_get_top_level "codeWorkspace")"
189
189
  case "$_cw" in
190
190
  true|yes|1)
191
191
  _ws_basename="$(basename "$NEXUS_DIR")"