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.pidirectory 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 asSYSTEM.md— project<cwd>/.rpi/APPEND_SYSTEM.mdoverrides<cwd>/.pi/APPEND_SYSTEM.md, and both override global<agent_dir>/APPEND_SYSTEM.md(mirrors pidiscoverAppendSystemPromptFileresource-loader.ts:1036-1048). Returns the first existing file in that order, orNone. The discovered content is appended to the system prompt (piappendSystemPrompt:525-542). - discover_
append_ system_ prompt_ file_ with_ packages - Discover
APPEND_SYSTEM.mdwith already-resolved package resources. - discover_
system_ prompt_ file - Discover
SYSTEM.md: project<cwd>/.rpi/SYSTEM.mdoverrides the legacy<cwd>/.pi/SYSTEM.md, and both override global<agent_dir>/SYSTEM.md(mirrors pidiscoverSystemPromptFileresource-loader.ts:1022-1034). Returns the first existing file in that order, orNone. - discover_
system_ prompt_ file_ with_ packages - Discover
SYSTEM.mdwith 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
.rpiremains ahead of legacy.pidefaults. - 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). ReturnsNoneif the agent dir can’t be resolved (no home dir + noRPI_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.mdfiles) 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
dirsin 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>/(noskills/promptssubdir). 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:
.rpifirst, then the original Pi.pilayout 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-localso 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 whenagent_dir()can’t be resolved (no home dir).