refactor: simplify agent discovery result handling#74
Open
ALX99 wants to merge 2 commits into
Open
Conversation
This was referenced Jul 5, 2026
5cf571d to
dd748db
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simplification
Removes the
neverthrowResultabstraction from the subagent discovery flow and replaces it with direct local return shapes:discoverAgents()now returns{ agents } | { error }.resolveAgent()now returnsAgentConfig | undefined.spawn_agentkeeps the same tool-boundary behavior by throwing the same registration and unknown-agent errors fromindex.ts.Why the current design is overcomplicated
neverthrowwas only used insidehome/.pi/agent/extensions/subagents/agents.tsfor two local call sites. The abstraction did not provide a meaningful extension point because both consumers immediately matched the value at the boundary and converted the result into normal control flow.For this repository, the extra
ok(...)/err(...)constructors and.match(...)calls added a second result-handling vocabulary without changing behavior or improving isolation.Behavioral contract
The following behavior must remain unchanged:
~/.pi/agent/extensions/subagents/agents/*.mdthroughgetAgentDir().agent_typevalues still throw from the pi tool boundary and include the requested name plus available agents.Before and after
Before:
agents.tsimportedok,err, andResultfromneverthrow.discoverAgents()returnedResult<AgentConfig[], DiscoverError>.resolveAgent()returnedResult<AgentConfig, { requested; available }>.index.tsused.match(...)twice to unwrap those local results.After:
agents.tsno longer importsneverthrow.discoverAgents()returns a local discriminated union,{ agents } | { error }.resolveAgent()returnsAgentConfig | undefined.index.tsuses normalifchecks and throws the same error strings at the same boundary.Evidence:
Resultvocabulary fromhome/.pi/agent/extensions/subagents/agents.ts..match(...)control flow fromhome/.pi/agent/extensions/subagents/index.ts.find(...)result instead of wrapping and immediately unwrapping it.neverthrowfrompackage.json/package-lock.jsoncan be done separately after local install validation.Validation
Commands run:
Static checks performed by inspection:
neverthrowwere inhome/.pi/agent/extensions/subagents/agents.ts,package.json, andpackage-lock.json.discoverAgents()still preserves all existing success and failure branches.resolveAgent()still uses the same exact name comparison against the same sortedagentsarray.index.tsstill throws through the pi tool boundary for discovery failures and unknownagent_typevalues.Expected validation for reviewer/local machine:
cd home/.pi/agent/extensions && npm run checkRisk assessment
Behavior-sensitive areas examined:
localeComparesort remains in place.The change is safe because it only removes a local result wrapper and leaves all IO, parsing, sorting, schema generation, execution, and rendering behavior unchanged.
Scope
Intentionally not simplified:
package.json/package-lock.jsondependency removal forneverthrow, because lockfile changes should be generated and validated withnpm installor equivalent local tooling.zodschemas, because they validate frontmatter and child process JSON at trust boundaries.