Skip to content

fix(search): search across all agents, add --agents filter - #85

Closed
mrrobertkent wants to merge 1 commit into
skilld-dev:mainfrom
mrrobertkent:fix/search-across-agents
Closed

fix(search): search across all agents, add --agents filter#85
mrrobertkent wants to merge 1 commit into
skilld-dev:mainfrom
mrrobertkent:fix/search-across-agents

Conversation

@mrrobertkent

Copy link
Copy Markdown
Contributor

Problem

skilld search reports nothing indexed when a project has more than one agent directory.

$ skilld search "config file" -p unlighthouse
▲  No docs indexed for "unlighthouse". Run `skilld add unlighthouse` first.

$ skilld list
unlighthouse-skilld  0.18.0  harlan-zw/unlighthouse/tree/v0.18.0/docs  today

$ ls ~/.skilld/references/unlighthouse@0.18.0/search.db
17915904 bytes, 357 documents indexed

readProjectLock resolved the lockfile through detectTargetAgent():

const agent = detectTargetAgent()
if (!agent)
  return null
return readLock(`${cwd}/${agents[agent].skillsDir}`)

detectTargetAgent() checks agent env vars first, then falls back to scanning the project and returns null when several match:

return projectMatches.length === 1 ? projectMatches[0]! : null

The project above has .claude/ and .agents/, so detection returns null, listLockPackages() returns [], and search bails. It only worked when run from inside an agent, where the env var short-circuits detection. From a plain terminal it always failed.

It also ignores agent: claude-code in the user's config.

Change

Indexes are keyed by package and version (getPackageDbPath(name, version)), never by agent, so restricting the lockfile to one agent only hides skills the project has. Reading one agent's dir was never the right question.

Merge every agent dir instead, deduplicated by the existing mergeLocks, which already prefers the most recent syncedAt per skill. A skill installed for two agents resolves to the same index, so the union is deduplicated by construction.

--agents narrows it when that is wanted:

skilld search "routing"                              # all agents
skilld search "routing" --agents claude-code
skilld search "routing" --agents claude-code,codex

Named --agents rather than --agent because the root command already owns -a/--agent as an enum, and citty validates parent args.

readProjectLock moves from commands/search-helpers.ts to core/skills.ts, which already imports the agent registry and owns the equivalent resolution for skill dirs. It is project state, not a search detail.

Testing

test/unit/project-lock.test.ts, 7 tests over a temp project: no lockfile, single agent, merge across agents, dedupe preferring newest syncedAt, agentFilter narrowing, unknown agent, and shared .skills dir taking precedence.

Test Files  56 passed (56)
     Tests  910 passed (910)

pnpm typecheck clean. Verified end to end against the reproduction above: default now returns results, --agents codex correctly reports nothing for a skill installed only under Claude Code, and an unknown id errors with the available list.

Docs

README updated: --agents in the command table, an example in the search block, and a note that search spans all agents by default.

`readProjectLock` resolved the lockfile via `detectTargetAgent()`, which returns
null when a project has more than one agent directory. Search then reported
nothing indexed even with a populated index on disk. Reproduces in any project
with, say, `.claude/` and `.agents/` when run from a shell with no agent env var
set, which is the normal case for a human in a terminal.

Indexes are keyed by package and version, never by agent, so scoping the
lockfile to one agent only hid skills the project has. Merge every agent dir
instead, deduplicated by `mergeLocks`, and add `--agents` to narrow when that is
wanted.

Moves `readProjectLock` from `commands/search-helpers.ts` to `core/skills.ts`,
alongside the other agent-aware project resolution.
@mrrobertkent

Copy link
Copy Markdown
Contributor Author

Closing in favour of a clean branch.

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