Skip to content

Limit Pi skills to explicit prompt references#81

Merged
glittercowboy merged 1 commit intomainfrom
codex/skill-prompt-latency
Apr 28, 2026
Merged

Limit Pi skills to explicit prompt references#81
glittercowboy merged 1 commit intomainfrom
codex/skill-prompt-latency

Conversation

@glittercowboy
Copy link
Copy Markdown
Contributor

@glittercowboy glittercowboy commented Apr 28, 2026

Summary

  • Select Pi skill paths only when the prompt includes an explicit skill token such as /skill:project-skill.
  • Keep plain chat turns free of home/project skill catalog loading.
  • Cover plain prompts and explicit skill references with focused daemon tests.

Verification

  • go test ./... && go build ./...

Release

  • Runtime-affecting daemon change. After merge, tag the next daemon patch release: daemon/v0.3.17.

Summary by CodeRabbit

  • Improvements
    • PI now applies Claude skills only when a prompt explicitly references them, leaving skill selection unset otherwise.
    • Prompt parsing recognizes explicit /skill: and /namespace: tokens for accurate, targeted skill selection and to avoid unintended skill usage.
  • Tests
    • Added unit and integration tests confirming referenced skills are selected and non-referenced skills are omitted.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f1bde6e-8f32-4ed8-b1b8-6440c55a820b

📥 Commits

Reviewing files that changed from the base of the PR and between d18c014 and 565f780.

📒 Files selected for processing (4)
  • internal/session/actor.go
  • internal/session/actor_test.go
  • internal/skills/discovery.go
  • internal/skills/discovery_test.go

📝 Walkthrough

Walkthrough

Claude skill discovery and selection are now prompt-aware: the Pi executor only discovers and forwards Claude skill paths when the prompt contains explicit /skill: or /<namespace>: references; otherwise SkillPaths stays nil and no --skill flags are emitted.

Changes

Cohort / File(s) Summary
Skill Detection & Selection
internal/skills/discovery.go, internal/skills/discovery_test.go
Added regex-based PromptHasClaudeSkillReference() and SelectClaudeSkillsForPrompt() to detect /skill: and /<namespace>: tokens, extract identifiers, and return deduplicated matching protocol.Skill entries; tests validate token variants and edge cases.
Pi Executor Integration
internal/session/actor.go
Updated runPiExecutor() to derive a skillPrompt, default skillPaths to nil, and only perform discovery + selection (populating SkillPaths) when PromptHasClaudeSkillReference(prompt) is true.
Actor Tests
internal/session/actor_test.go
Reworked tests and helpers to collect multiple --skill args; added tests asserting referenced skills produce corresponding --skill flags and prompts without references emit zero --skill flags.

Sequence Diagram

sequenceDiagram
    participant User as "Prompt Input"
    participant RefCheck as "PromptHasClaudeSkillReference()"
    participant Discover as "Skill Discovery (FS)"
    participant Select as "SelectClaudeSkillsForPrompt()"
    participant Executor as "runPiExecutor()"
    participant Pi as "Pi Executor"

    User->>RefCheck: send prompt text
    RefCheck-->>Executor: boolean (hasReference)
    alt hasReference
        Executor->>Discover: enumerate available skills
        Discover->>Select: provide available skills + prompt
        Select->>Select: extract tokens, match names, dedupe
        Select-->>Executor: return filtered skills (paths)
        Executor->>Pi: invoke with --skill flags for each path
    else noReference
        Executor->>Executor: keep skillPaths = nil
        Executor->>Pi: invoke without --skill flags
    end
    Pi-->>Executor: return execution result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~23 minutes

Possibly related PRs

  • Pass Claude skills through Pi #79: Previously added unconditional discovery and always-passed Claude SKILL.md paths to runPiExecutor(); this PR narrows that behavior to only pass referenced skills.
  • Enable Pi skill discovery #77: Also modifies Pi skill-related flag handling and relates to enabling/disabling skill propagation to the Pi executor.

Poem

🐰 I sniff the prompt for /skill: cues,
nibble tokens, and chase tidy clues.
I pluck the paths that match the name,
skip the fluff, keep the game.
Off to Pi I hop, light and keen — carrot dream.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Limit Pi skills to explicit prompt references' directly and clearly summarizes the main change: restricting skill loading/selection to only when prompts explicitly reference skills via tokens like /skill:project-skill.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 codex/skill-prompt-latency

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/skills/discovery_test.go (1)

104-130: Add a regression case for path-like slash tokens.

Current coverage checks plain text and explicit tokens, but not prompts containing filesystem-like tokens (e.g., /tmp/file) that must not count as skill references.

✅ Suggested test addition
+func TestPromptHasClaudeSkillReferenceIgnoresPathLikeTokens(t *testing.T) {
+	if PromptHasClaudeSkillReference("open /tmp/notes.md") {
+		t.Fatal("expected false for path-like token without explicit skill directive")
+	}
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/skills/discovery_test.go` around lines 104 - 130, Add a regression
test to ensure SelectClaudeSkillsForPrompt does not treat filesystem-like slash
tokens as skill references: create a test (e.g.,
TestSelectClaudeSkillsForPromptIgnoresPathLikeTokens) with an available skills
slice including "project-skill" and others, call SelectClaudeSkillsForPrompt
with a prompt containing path-like strings such as "/tmp/file" or
"/var/log/app.log" alongside a real explicit skill token (e.g.,
"/skill:project-skill"), and assert that only the explicit token(s) are selected
(len(got) and got[*].Path checks) so path-like tokens are ignored; reference the
SelectClaudeSkillsForPrompt function and update discovery_test.go with this new
test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/skills/discovery.go`:
- Line 23: The current regex in skillRefPattern is too permissive and matches
any slash-prefixed token (e.g., /tmp); change skillRefPattern so it only matches
when the slash is followed by an explicit directive "skill:" or "namespace:"
(i.e., require "/skill:" or "/namespace:" after the slash) so that the discovery
logic that uses skillRefPattern (the skill discovery routine around the current
usage at lines ~72-87) only triggers for explicit skill/namespace directives;
update the pattern accordingly and run existing tests to ensure no other callers
rely on the old permissive matching.

---

Nitpick comments:
In `@internal/skills/discovery_test.go`:
- Around line 104-130: Add a regression test to ensure
SelectClaudeSkillsForPrompt does not treat filesystem-like slash tokens as skill
references: create a test (e.g.,
TestSelectClaudeSkillsForPromptIgnoresPathLikeTokens) with an available skills
slice including "project-skill" and others, call SelectClaudeSkillsForPrompt
with a prompt containing path-like strings such as "/tmp/file" or
"/var/log/app.log" alongside a real explicit skill token (e.g.,
"/skill:project-skill"), and assert that only the explicit token(s) are selected
(len(got) and got[*].Path checks) so path-like tokens are ignored; reference the
SelectClaudeSkillsForPrompt function and update discovery_test.go with this new
test.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 68fdaedb-cefa-4e7a-a048-9b3127f86888

📥 Commits

Reviewing files that changed from the base of the PR and between 416f674 and 5a3fb85.

📒 Files selected for processing (4)
  • internal/session/actor.go
  • internal/session/actor_test.go
  • internal/skills/discovery.go
  • internal/skills/discovery_test.go

Comment thread internal/skills/discovery.go Outdated
@glittercowboy glittercowboy force-pushed the codex/skill-prompt-latency branch from 5a3fb85 to f21f264 Compare April 28, 2026 17:49
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/session/actor.go`:
- Around line 610-615: The code is checking for Claude skill references against
the composed "prompt" (which includes injected context) instead of the raw user
prompt; update calls to use the user-facing prompt variable (e.g., task.Prompt
or userPrompt) when calling skills.PromptHasClaudeSkillReference and
skills.SelectClaudeSkillsForPrompt so token-gating only considers the user's
original text; leave skills.DiscoverClaudeSkills as-is. Ensure you reference the
user prompt variable consistently in both checks to prevent context-injected
"/skill:" matches from enabling discovery.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f40e9d5-99ee-4015-824e-b43ce596e8a4

📥 Commits

Reviewing files that changed from the base of the PR and between 5a3fb85 and f21f264.

📒 Files selected for processing (4)
  • internal/session/actor.go
  • internal/session/actor_test.go
  • internal/skills/discovery.go
  • internal/skills/discovery_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/skills/discovery.go
  • internal/skills/discovery_test.go

Comment thread internal/session/actor.go Outdated
@glittercowboy glittercowboy force-pushed the codex/skill-prompt-latency branch from f21f264 to d18c014 Compare April 28, 2026 17:54
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
internal/skills/discovery.go (1)

23-23: ⚠️ Potential issue | 🟠 Major

Restrict token matching to /skill: and /namespace: only.

Line 23 still matches arbitrary /<prefix>:... tokens (for example, /foo:bar), which can trigger skill discovery on plain prompts that were meant to stay catalog-free.

Suggested fix
-var skillRefPattern = regexp.MustCompile(`(?:^|\s)/(?:skill:([A-Za-z0-9:_-]+)|([A-Za-z0-9_-]+:[A-Za-z0-9:_-]+))`)
+var skillRefPattern = regexp.MustCompile(`(?:^|\s)/(?:skill:([A-Za-z0-9:_-]+)|(namespace:[A-Za-z0-9:_-]+))`)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/skills/discovery.go` at line 23, The regex stored in skillRefPattern
currently matches any "/prefix:token" and should be tightened to only trigger
for "/skill:" and "/namespace:"; update the regexp in
internal/skills/discovery.go (skillRefPattern) so it only recognizes leading
"/skill:..." or "/namespace:..." tokens (preserving the allowed character set
[A-Za-z0-9:_-] for the token) and keeps the same word-boundary or leading-space
behavior (i.e., still anchored with (?:^|\s)/).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@internal/skills/discovery.go`:
- Line 23: The regex stored in skillRefPattern currently matches any
"/prefix:token" and should be tightened to only trigger for "/skill:" and
"/namespace:"; update the regexp in internal/skills/discovery.go
(skillRefPattern) so it only recognizes leading "/skill:..." or "/namespace:..."
tokens (preserving the allowed character set [A-Za-z0-9:_-] for the token) and
keeps the same word-boundary or leading-space behavior (i.e., still anchored
with (?:^|\s)/).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f60498f0-006f-4a5a-996c-534e83502fef

📥 Commits

Reviewing files that changed from the base of the PR and between f21f264 and d18c014.

📒 Files selected for processing (4)
  • internal/session/actor.go
  • internal/session/actor_test.go
  • internal/skills/discovery.go
  • internal/skills/discovery_test.go

@glittercowboy glittercowboy force-pushed the codex/skill-prompt-latency branch from d18c014 to 565f780 Compare April 28, 2026 17:59
@glittercowboy glittercowboy merged commit ea08222 into main Apr 28, 2026
2 checks passed
@glittercowboy glittercowboy deleted the codex/skill-prompt-latency branch April 28, 2026 18:03
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