Fix code review issues: structured error returns, remove unused count, add JSDoc #14
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "issue-1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Code Review: issue-1 vs main
Date: 2025-07-24
Language: TypeScript (pi extension)
Files changed: 4
Lines added: +246 / Lines removed: -0
Files Under Review
.pi/extensions/pi-worktree.tsfindings.mdprogress.mdtask_plan.mdCritical (0)
None.
Major (2)
[MAJOR] Execute functions throw errors instead of returning structured error objects
File:
.pi/extensions/pi-worktree.tsLines: 97, 105, 113, 121, 138
Detail: All
execute()functions and the command handler usethrow new Error("not implemented"). Per AGENTS.md error handling pattern, tools should return structured objects:Even stub implementations should follow this pattern so the extension loads without unhandled exceptions. Throwing from an execute function will crash the tool invocation rather than surfacing a clean error to the user.
Fix: Replace
throw new Error("not implemented")with structured return objects that include a suggestion, e.g.:[MAJOR]
WorktreeListResult.countfield has no consumer and duplicates available infoFile:
.pi/extensions/pi-worktree.tsLine: 32
Detail: The interface defines
count: numberbut nothing in the scaffold uses it. Since callers can derive count fromworktrees.length, this field adds maintenance burden (must stay in sync) without clear value. If included for API convenience, document why it's separate from.length.Fix: Either remove
countfrom the interface or add a comment justifying its presence (e.g., "cached to avoid repeated .length calls" or "included for tool response schema consistency").Minor (3)
[MINOR]
WorktreeErrorinterface is defined but unusedFile:
.pi/extensions/pi-worktree.tsLines: 38–43
Detail: The
WorktreeErrorinterface (message,suggestion?) is well-designed and aligns with AGENTS.md conventions, but isn't referenced anywhere in the current code. It will be needed when implementing error returns.Fix: No action needed for scaffold phase — this is forward-looking type design. Confirm it's used when implementing actual tool logic.
[MINOR]
ExtensionContextimported but only used indirectly via type definitionsFile:
.pi/extensions/pi-worktree.tsLine: 16
Detail:
ExtensionContextis imported as a type and referenced in thepathExists()helper signature. This is correct forward-looking design — it will be needed when implementing file system checks. No issue, just noting for completeness.[MINOR] Tool definitions lack JSDoc comments unlike helper functions
File:
.pi/extensions/pi-worktree.tsLines: 95–123
Detail: Helper functions (
parseWorktreeList,pathExists,resolveWorktreeTarget) have thorough JSDoc with parameter descriptions and return types. The tool definitions (gitWorktreeCreateTool, etc.) have no comments. For a single-file extension, inline documentation helps future maintainers understand each tool's contract at a glance.Fix: Add brief JSDoc above each
defineTool()call summarizing its purpose and key behaviors:Suggestions (2)
[SUGGESTION] Consider adding a
pi.exec()usage example in comments for future implementersFile:
.pi/extensions/pi-worktree.tsDetail: AGENTS.md specifies "Git: native via
pi.exec("git", [...])" but the scaffold has no indication of how git commands will be invoked. A comment near the helper functions showing the expected pattern would reduce friction for the next implementation phase:[SUGGESTION]
task_plan.mdlists only Task 001 but milestone context references Tasks 1.1–1.3File:
task_plan.mdLines: 6, 12–14
Detail: The task table has one entry (Task 001) marked done, but the milestone context below references three subtasks (1.1: Create Extension File, 1.2: Register Tool Scaffolding, 1.3: Implement
git_worktree_list). This creates ambiguity about whether Task 001 encompasses all three or if 1.2 and 1.3 are still pending.Fix: Either expand the task table to list subtasks 1.1–1.3 separately with individual status, or clarify that Task 001 covers all three milestones.
Summary
⚡ No critical issues. Major issues should be addressed before the extension is loadable in pi — specifically, execute functions must return structured error objects instead of throwing to avoid unhandled exceptions at runtime.
Review Fix Plan
.pi/extensions/pi-worktree.tsthrow new Error()with structured{ content, isError: true }returns in all execute functions and command handlercountfield inWorktreeListResult.pi/extensions/pi-worktree.tscountfield.pi/extensions/pi-worktree.tsdefineTool()calltask_plan.mdTask 001: Execute stubs throw instead of returning errors
Severity: major
File:
.pi/extensions/pi-worktree.tsLines: 97, 105, 113, 121, 138
Issue: All five execute/handler functions use
throw new Error("not implemented"). When pi invokes a tool, an uncaught exception will crash the tool invocation rather than returning a clean error message to the user. AGENTS.md specifies the pattern: return{ content: [{ type: "text", text }], isError: true }.Fix: For each of the 4 tools and 1 command handler, replace the throw with:
Verification: Extension loads in pi without errors; calling any tool returns an error message instead of crashing.
Task 002: Unused
countfield inWorktreeListResultSeverity: major
File:
.pi/extensions/pi-worktree.tsLine: 32
Issue:
count: numberis defined but never populated or consumed. Callers can useworktrees.length. Dead fields create maintenance burden and confusion about whether they're intentional API design or leftover scaffolding.Fix: Remove the
countfield fromWorktreeListResult:Or add a comment if intentionally kept for API schema reasons.
Verification: No references to
.countin code; interface matches actual usage.Task 003: Tool definitions lack JSDoc
Severity: minor
File:
.pi/extensions/pi-worktree.tsLines: 95–123
Issue: Helper functions have thorough JSDoc but tool definitions don't. In a single-file extension, inline docs help readers scan the file and understand each tool's purpose without reading implementation details.
Fix: Add JSDoc above each
defineTool():Verification: Each tool definition has a JSDoc comment matching its description field.
Task 004: Task plan subtask ambiguity
Severity: suggestion
File:
task_plan.mdLines: 6, 12–14
Issue: The task table shows one completed Task 001, but the milestone context references three distinct subtasks (1.1, 1.2, 1.3). It's unclear whether all are done or only partially complete.
Fix: Expand the task table:
git_worktree_listVerification: Task plan clearly shows what's done vs pending within the issue scope.
- Replace throw Error() with { content, isError: true } in all execute functions and command handler - Remove unused count field from WorktreeListResult interface - Add JSDoc comments above all defineTool() calls - Clarify task_plan.md subtask structure (001.1-001.3)