Skip to content

fix(agent): lazy-reload skill registry on CLI slash invocation miss (#57)#203

Merged
quangdang46 merged 1 commit into
masterfrom
fix/agent-cli-skill-lazy-reload
May 22, 2026
Merged

fix(agent): lazy-reload skill registry on CLI slash invocation miss (#57)#203
quangdang46 merged 1 commit into
masterfrom
fix/agent-cli-skill-lazy-reload

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

What

The TUI input path (src/tui/app/input.rs:2014-2038) already does a synchronous SkillRegistry::load_for_working_dir on a slash-skill miss so project-local skills installed under .jcode/skills/ work the moment skill_manage reload_all finishes. The CLI loop in src/agent/turn_execution.rs captured skills once at the top of the session and never refreshed it, so users in headless / non-TUI mode saw Unknown skill: /<name> even after a successful reload_all.

This addresses issue #57: #57

Changes

  • src/agent/turn_execution.rs: mirror the TUI lazy-reload pattern in the CLI loop:
    • On a slash miss, re-derive the registry from the session's working directory.
    • Replace the shared registry under try_write so subsequent invocations see the fresh snapshot.
    • Retry the lookup once before falling back to the "Unknown skill" path.
    • The "Available:" listing now uses current_skills_snapshot so it reflects whatever the lazy-reload just discovered, not the stale top-of-loop capture.

Tests

cargo check -p jcode --lib clean. The fix is symmetric with the TUI path that has its own coverage in src/tui/app/tests/remote_startup_input_03/. The CLI loop is interactive (stdin().read_line), making a focused unit test require pty plumbing that doesn't exist here today; the change itself is a small mechanical mirror of an existing, tested pattern.

Notes

The shared registry update uses try_write so a reader holding the lock at that exact moment doesn't deadlock the CLI loop — same defensive style as current_skills_snapshot.

The TUI input path (src/tui/app/input.rs) already does a synchronous
`SkillRegistry::load_for_working_dir` on a slash-skill miss so that
project-local skills installed under `.jcode/skills/` work the moment
`skill_manage reload_all` finishes. The CLI loop in
agent/turn_execution.rs captured `skills` once at the top of the
session and never refreshed it, so users in headless / non-TUI mode
saw "Unknown skill: /<name>" even after a successful reload_all.

Mirror the TUI behavior:
- On a slash miss, re-derive the registry from the session's working
  directory, replace the shared registry under try_write so subsequent
  invocations see the fresh snapshot, and retry the lookup once.
- After the print-Unknown branch, list available skills from the
  freshly-snapshotted registry (current_skills_snapshot) instead of
  the stale top-of-loop `skills` capture, so the user sees what
  *would* have been resolvable.

Closes #57
@quangdang46 quangdang46 merged commit 8073faa into master May 22, 2026
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