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.mdunder<cwd>/.pi/. The global config lives underagent_dir()(~/.rpi/agent), which IS.rpi— seeconfig.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 asSYSTEM.md— project<cwd>/.pi/APPEND_SYSTEM.mdoverrides 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_
system_ prompt_ file - Discover
SYSTEM.md: project<cwd>/.pi/SYSTEM.mdoverrides global<agent_dir>/SYSTEM.md(mirrors pidiscoverSystemPromptFileresource-loader.ts:1022-1034). Returns the first existing file in that order, orNone. - 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. - 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>/.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_
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 whenagent_dir()can’t be resolved (no home dir).