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 SYSTEM.md / 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 .rpi/ or .pi/ directory drops in and works (the documented intent). Full trust gating is deferred.

Deferred (documented): pi’s .agents/skills + ~/.agents/skills (rpi package-installed static resources are handled by crate::packages); 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§

LEGACY_PROJECT_CONFIG_DIR_NAME
The upstream Pi project-local config dir, loaded after .rpi.
PROJECT_CONFIG_DIR_NAME
The preferred project-local config dir. rpi-owned resources live under <cwd>/.rpi; the legacy .pi directory remains a compatibility fallback.

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>/.rpi/APPEND_SYSTEM.md overrides <cwd>/.pi/APPEND_SYSTEM.md, and both override 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_append_system_prompt_file_with_packages
Discover APPEND_SYSTEM.md with already-resolved package resources.
discover_system_prompt_file
Discover SYSTEM.md: project <cwd>/.rpi/SYSTEM.md overrides the legacy <cwd>/.pi/SYSTEM.md, and both override global <agent_dir>/SYSTEM.md (mirrors pi discoverSystemPromptFile resource-loader.ts:1022-1034). Returns the first existing file in that order, or None.
discover_system_prompt_file_with_packages
Discover SYSTEM.md with already-resolved package resources. Package files are considered after project and global files, so installing a package cannot unexpectedly override a user’s project instructions.
extension_dirs
The ordered Rust extension directories for a project. Configured paths are added before conventional directories so an explicit project path can be used for development while .rpi remains ahead of legacy .pi defaults.
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.
global_extension_dirs
global_prompt_template_dirs
global_skill_dirs
Resource directories that do not depend on the current project. Used when the project trust gate denies local configuration/resources.
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>/.rpi/, <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_config_files
Resolve project config files in precedence order: preferred .rpi, then legacy .pi.
project_dir
Resolve the preferred project-local resource subdir <cwd>/.rpi/<sub>.
project_dirs
Resolve project-local resource dirs in precedence order: .rpi first, then the original Pi .pi layout for compatibility.
project_prompt_template_dirs
Project-only prompt-template directories, excluding user/global settings.
project_skill_dirs
Project-only skill directories, excluding user/global configuration. This is used by rpi dev-local so the current extension can be debugged with the skills in the current checkout without importing unrelated skills.
prompt_template_dirs
The ordered prompt-template paths for a project: configured paths, then [<cwd>/.rpi/prompts, <cwd>/.pi/prompts, <agent_dir>/prompts].
skill_dirs
The ordered skill dirs for a project: configured project paths, then [<cwd>/.rpi/skills, <cwd>/.pi/skills, <agent_dir>/skills], followed by configured and conventional global paths. The global dir is omitted when agent_dir() can’t be resolved (no home dir).