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

Deferred (documented): .agents/skills + ~/.agents/skills; 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 rpi configuration directory.

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_prompt_templates_structured
Structured variant of dedupe_prompt_templates. PromptTemplate carries no file path, so the collision loser/winner paths fall back to the template name (documented divergence).
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.
dedupe_skills_structured
Structured variant of dedupe_skills: emits a [ResourceDiagnostic] per shadowed skill (winner/loser path) instead of a stringly-typed diagnostic. Callers that want to surface collisions in the UI (e.g. /reload) use this.
discover_append_system_prompt_file
Discover APPEND_SYSTEM.md using project-over-global precedence.
discover_system_prompt_file
Discover SYSTEM.md from the project .rpi/ directory or global agent dir.
discover_system_prompt_file_with_trust
Discover SYSTEM.md with explicit project trust control.
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 defaults stay lower precedence.
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/ and <agent_dir>/.
project_config_files
Resolve project config files. Only .rpi is read.
project_dir
Resolve the preferred project-local resource subdir <cwd>/.rpi/<sub>.
project_dirs
Resolve project-local resource dirs. Only .rpi is read.
project_extension_dirs
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, <agent_dir>/prompts].
skill_dirs
The ordered skill dirs for a project: configured project paths, then [<cwd>/.rpi/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).