Skip to main content

Module resource_dirs

Module resource_dirs 

Source
Expand description

Resource-directory resolution + project-wins dedupe for skills and prompt templates. Mirrors the precedence contract from pi’s DefaultResourceLoader/package-manager (resource-loader.ts:676-681, package-manager.ts:178-181): resources are ranked project=0/1 < user=2/3 < package=4, and addSkills/dedupePrompts are first-registration-wins on name → loading project before global means project wins on collision (skills.ts:399-428), with a collision diagnostic naming the winner (kept) and loser (dropped) paths.

rpi’s library loaders (rpi_harness::skills::load_skills, rpi_harness::prompt_templates::load_prompt_templates) are append-only (no dedup-by-name) — they correctly mirror pi’s per-directory discovery (SKILL.md-first / root-.md / subdir recursion for skills; non-recursive .md children for prompts) but leave the cross-directory merge to the caller. This module is that caller-side merge: load project dir then global dir, then dedupe first-wins-by-name so project wins.

Trust gate (v1 divergence): pi gates project .pi/SYSTEM.md / .pi/APPEND_SYSTEM.md (and some project resources) behind settingsManager.isProjectTrusted(). rpi v1 has no trust prompt (config.rs:349: “does not gate any project resources behind trust in v1”), so project resources are read unconditionally here. A copied .pi/ directory drops in and works (the documented intent). Full trust gating is deferred.

Deferred (documented): pi’s .agents/skills + ~/.agents/skills + package-installed skills/prompts (4 discovery roots in pi; rpi v1 mirrors the two primary: project .pi/<sub> + user agent_dir()<sub>); worktree shadowed-context-file dedup (findShadowedContextFile); full structured winner/loser collision diagnostics (rpi v1 encodes collisions as a SkillDiagnostic/PromptTemplateDiagnostic with a descriptive message).

Constants§

PROJECT_CONFIG_DIR_NAME
The project-local config dir name. Mirrors pi’s .pi/ (NOT .rpi/) so a copied pi project directory drops in and works: skills under <cwd>/.pi/skills, prompts under <cwd>/.pi/prompts, SYSTEM.md/APPEND_SYSTEM.md under <cwd>/.pi/. The global config lives under agent_dir() (~/.rpi/agent), which IS .rpi — see config.rs.

Functions§

dedupe_prompt_templates
Dedupe prompt templates by name, first-wins. Mirrors pi dedupePrompts (resource-loader.ts:969-993): the first template with a given name is kept; later duplicates emit a collision diagnostic. Load paths in project→global order so project wins.
dedupe_skills
Dedupe skills by name, first-wins. Mirrors pi addSkills (skills.ts:399-428): the first skill with a given name is kept; later duplicates emit a collision diagnostic naming the winner (kept) and loser (dropped) paths. Load dirs in project→global order so project wins.
discover_append_system_prompt_file
Discover APPEND_SYSTEM.md: same precedence as SYSTEM.md — project <cwd>/.pi/APPEND_SYSTEM.md overrides global <agent_dir>/APPEND_SYSTEM.md (mirrors pi discoverAppendSystemPromptFile resource-loader.ts:1036-1048). Returns the first existing file in that order, or None. The discovered content is appended to the system prompt (pi appendSystemPrompt :525-542).
discover_system_prompt_file
Discover SYSTEM.md: project <cwd>/.pi/SYSTEM.md overrides global <agent_dir>/SYSTEM.md (mirrors pi discoverSystemPromptFile resource-loader.ts:1022-1034). Returns the first existing file in that order, or None.
global_config_file
Global config file under <agent_dir>/<name> (~/.rpi/agent/SYSTEM.md).
global_dir
Resolve the global resource subdir <agent_dir>/<sub> (e.g. ~/.rpi/agent/skills). Returns None if the agent dir can’t be resolved (no home dir + no RPI_CODING_AGENT_DIR) — callers then proceed project-only.
load_prompt_templates_with_precedence
Load prompt templates from paths (dirs or .md files) in order, then dedupe first-wins-by-name. Missing paths are skipped silently. Pass paths in project→global order so project wins on name collisions.
load_skills_with_precedence
Load skills from dirs in order, then dedupe first-wins-by-name. Missing directories are skipped silently by the underlying loader (NotFound → continue, mirroring pi). Pass dirs in project→global order so project wins on name collisions.
project_config_file
The candidate context/SYSTEM/APPEND filenames live directly under <cwd>/.pi/ and <agent_dir>/ (no skills/prompts subdir). Re-exports the harness context-file candidates for the system/append discovery path so callers share one source of truth.
project_dir
Resolve the project-local resource subdir <cwd>/.pi/<sub>.
prompt_template_dirs
The ordered prompt-template paths for a project: [<cwd>/.pi/prompts, <agent_dir>/prompts].
skill_dirs
The ordered skill dirs for a project: [<cwd>/.pi/skills, <agent_dir>/skills]. The global dir is omitted when agent_dir() can’t be resolved (no home dir).