Skip to content

(MOT-4172) iii-directory: user prompt library backend#564

Open
rohitg00 wants to merge 2 commits into
mainfrom
directory-prompt-library
Open

(MOT-4172) iii-directory: user prompt library backend#564
rohitg00 wants to merge 2 commits into
mainfrom
directory-prompt-library

Conversation

@rohitg00

@rohitg00 rohitg00 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What

The prompt library backend in the directory worker: named, user-authored prompts stored on disk, listed and fetched next to the worker-shipped templates, writable by agents and operators. Console picker UX comes separately on the injectable-view base; this PR is only the worker surface it needs.

  • New config: prompts_folder (default ~/.iii/prompts) and local_prompts_folder (default ./.iii/prompts), mirroring the skills folder pair. Local shadows global shadows worker-shipped on name collision.
  • directory::prompts::list now merges user library entries with worker-shipped templates and tags every row with source (user | worker) and kind (command | system, from frontmatter, default command); filterable by both. The kind split keeps slash-style message templates and full system prompts in one store without conflating them.
  • directory::prompts::get resolves through the same precedence and returns kind + source alongside the body.
  • New directory::prompts::save: name, description, body, kind; omit body and set from to fork an existing prompt under a new name. Atomic write, overwrite allowed (that is the edit path), fires directory::prompts::on-change. Agent-callable on purpose: an orchestrator authors a five-line system prompt for a sub-agent, saves it, and spawns children with it through the existing spawn options.system_prompt.
  • New directory::prompts::delete: requires exactly yes: true (worker lifecycle convention); refuses worker-shipped templates and project-local files, removes only prompts_folder entries. Fires on-change.
  • FsPrompt carries the frontmatter kind; new scan_user_prompts scans a flat library root with the same frontmatter and name rules as shipped prompts, minus the <ns>/prompts/ requirement.

Why

One override per provider exists today (the router knob), but there is no catalog: switching system prompts means pasting text by hand, and sub-agents have no way to get purpose-built minimal prompts. With the library, a stored system prompt applies rig-wide via the router knob, per session via send options, or per child via spawn options, and agents can author prompts as artifacts. Pairs with #558 (minimal core + playbooks) and the eval runner (#563) as the acceptance gate for any prompt that becomes a rig default.

Validation

254 lib tests pass (6 new: save/get round-trip with kind and source, fork seeding, kind and body rejection, delete confirmation + scope, local-shadows-global), clippy strict clean. Then live against a running rig (engine 0.21.6) with this build as a second directory worker:

  • save wrote ~/.iii/prompts/blog-writer.md with clean frontmatter; get returned kind: system, source: user; fork via from produced blog-writer-v2; both deletes removed exactly the library files.
  • End-to-end scenario: fetched the 76-character library prompt and started a session with it as the system prompt override. The agent answered: "My job is writing blog posts, and the only workers I know are web and state::set." Minimal single-purpose sub-agent prompts work through existing surfaces with zero harness changes.

Notes for review

  • list/get responses gained fields only; existing consumers keep working. The MCP worker's prompt picker sees user entries as ordinary prompts.
  • save writes only the global library; project-local files are hand-managed by design.
  • on-change payload follows the download shape (op + source), so existing subscribers need no changes.

Linear

Closes MOT-4172. Part of MOT-4169 and MOT-4157.

Summary by CodeRabbit

  • New Features

    • Added a prompt library with global and project-local storage, configurable via default prompt directories.
    • Prompts can be listed with optional filtering by prompt type and source.
    • Prompt details now include kind, source, full markdown body, and last modified time.
    • Added prompt save (with optional forking) and delete with explicit confirmation.
    • Local prompts take precedence over global and built-in templates; missing prompts return close-name suggestions.
    • Supported prompt kinds: command and system.
  • Bug Fixes

    • Strengthened validation for prompt names, descriptions, kinds, and required body content.
    • Prevented deletion of built-in or non-user prompts.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
workers Ready Ready Preview, Comment Jul 22, 2026 4:12pm
workers-tech-spec Ready Ready Preview, Comment Jul 22, 2026 4:12pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cecc48c1-4504-4348-9ad8-1d81a04455f3

📥 Commits

Reviewing files that changed from the base of the PR and between 6682500 and 34c26c8.

📒 Files selected for processing (2)
  • iii-directory/src/fs_source.rs
  • iii-directory/src/functions/prompts.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • iii-directory/src/functions/prompts.rs

📝 Walkthrough

Walkthrough

The prompt system adds configurable global and local libraries, frontmatter-based kinds and sources, precedence-aware listing and retrieval, plus registered save and delete APIs with validation and filesystem persistence.

Changes

Prompt library

Layer / File(s) Summary
Prompt roots and metadata
iii-directory/src/config.rs, iii-directory/src/fs_source.rs
Configurable global/local prompt folders are added, and shared filesystem parsing captures trimmed optional kind frontmatter.
Prompt API contracts and registration
iii-directory/src/functions/prompts.rs, iii-directory/src/functions/mod.rs
Prompt list/get models gain metadata and body fields, save/delete types and endpoints are added, and subscriber wiring is updated.
Prompt resolution and mutations
iii-directory/src/functions/prompts.rs
Prompt collection applies local, global, and worker precedence; get returns enriched content, save writes validated atomic markdown, and delete requires confirmation.
Prompt behavior validation
iii-directory/src/functions/prompts.rs
Temporary configurations and integration tests cover roundtrips, forking, validation failures, deletion, and precedence.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant PromptAPI
  participant PromptLibraries
  participant WorkerTemplates
  Caller->>PromptAPI: list or get prompt
  PromptAPI->>PromptLibraries: collect local and global prompts
  PromptAPI->>WorkerTemplates: collect shipped templates
  PromptLibraries-->>PromptAPI: classified prompt entries
  WorkerTemplates-->>PromptAPI: template entries
  PromptAPI-->>Caller: precedence-resolved prompt
Loading

Suggested reviewers: andersonleal, sergiofilhowz

Poem

A bunny now saves prompts with care,
In local and global folders there.
Kinds and sources hop in line,
Forks and deletes behave just fine.
“Precedence!” sings the hare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a user prompt library backend to iii-directory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch directory-prompt-library

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

skill-check — worker

0 verified, 47 skipped (no docs/).

Layer Result
structure
vale
ai
render

Four for four. Nicely done.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
iii-directory/src/fs_source.rs (1)

406-511: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Consider extracting the shared frontmatter-parsing body.

scan_user_prompts duplicates most of scan_prompts (read → split_frontmatterserde_yaml parse → name derivation → description validation → kind mapping). The only real differences are the has_prompts_segment gate and duplicate-detection. A shared parse_prompt_entry(abs) -> Result<FsPrompt, SkipReason> helper would keep the two scanners from drifting.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iii-directory/src/fs_source.rs` around lines 406 - 511, Extract the
duplicated prompt frontmatter processing from scan_user_prompts and scan_prompts
into a shared parse_prompt_entry helper returning Result<FsPrompt, SkipReason>.
Keep file reading, frontmatter splitting/parsing, name derivation and
validation, description validation, kind mapping, and error construction in the
helper; leave has_prompts_segment filtering and scanner-specific duplicate
detection in each caller.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iii-directory/src/functions/prompts.rs`:
- Around line 347-353: Update the frontmatter construction in the format! call
to pass req.name through yaml_quote, matching the existing description handling,
so PromptFrontmatter.name always deserializes as a string for names such as
numeric or boolean-looking values.
- Around line 394-396: Update yaml_quote to use a YAML-aware quoting/escaping
implementation instead of Rust’s {:?} formatting and newline replacement. Ensure
all control characters in the input produce valid YAML double-quoted escapes so
description values round-trip safely through frontmatter.

---

Nitpick comments:
In `@iii-directory/src/fs_source.rs`:
- Around line 406-511: Extract the duplicated prompt frontmatter processing from
scan_user_prompts and scan_prompts into a shared parse_prompt_entry helper
returning Result<FsPrompt, SkipReason>. Keep file reading, frontmatter
splitting/parsing, name derivation and validation, description validation, kind
mapping, and error construction in the helper; leave has_prompts_segment
filtering and scanner-specific duplicate detection in each caller.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b8faa56d-cf49-42e5-b1f2-9a0929ad04fe

📥 Commits

Reviewing files that changed from the base of the PR and between 7ff0617 and 6682500.

📒 Files selected for processing (4)
  • iii-directory/src/config.rs
  • iii-directory/src/fs_source.rs
  • iii-directory/src/functions/mod.rs
  • iii-directory/src/functions/prompts.rs

Comment thread iii-directory/src/functions/prompts.rs Outdated
Comment thread iii-directory/src/functions/prompts.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant