diff --git a/sprints/maxsteps/opencode-02-maxsteps.md b/sprints/maxsteps/opencode-02-maxsteps.md new file mode 100644 index 000000000..e1de2b37b --- /dev/null +++ b/sprints/maxsteps/opencode-02-maxsteps.md @@ -0,0 +1,101 @@ +# Sprint: Agent MaxSteps Feature + +## Problem Statement +Users need the ability to limit the number of steps that agents (especially subagents) can take during execution, as outlined in [Issue #3631](https://github.com/sst/opencode/issues/3631). This feature will prevent runaway agent loops and give users better control over agent execution limits. + +## Context +### Existing System +OpenCode has an agentic loop system controlled in `packages/opencode/src/session/prompt.ts`. Currently, agents can run indefinitely without any step limits, which can lead to: +- Excessive resource consumption +- Runaway loops in faulty agent logic +- Unpredictable costs when using paid APIs +- Difficulty in debugging agent behavior + +### MaxSteps Feature Requirements +The maxSteps feature must: +- Allow optional step limits for agent definitions +- Work for both primary agents and subagents (primary use case is subagents) +- Stop execution when the limit is reached +- On the n-1 step, remove all tools from the request to force a text-only response +- Be configurable per agent definition +- Default to unlimited if not specified (backward compatibility) + +## Success Criteria +- [ ] Agent definitions accept optional `maxSteps` parameter +- [ ] Step counter tracks execution steps accurately +- [ ] Agent stops at maxSteps limit +- [ ] On step n-1, tools are removed from the request +- [ ] Final step produces a text-only response summarizing status +- [ ] Feature works for both primary and subagents +- [ ] No breaking changes to existing agent definitions +- [ ] Step limit is logged for debugging purposes +- [ ] Clear error/status message when limit is reached +- [ ] Tests cover various step limit scenarios +- [ ] Documentation updated with maxSteps usage + +## Technical Requirements + +### Agent Definition Schema +```typescript +interface AgentDefinition { + name: string; + description: string; + tools?: Tool[]; + maxSteps?: number; // New optional field + // ... other existing fields +} +``` + +### Implementation Location +- Primary implementation in: `packages/opencode/src/session/prompt.ts` +- Agent definition types updated +- Step counter logic added to agentic loop + +### Step Counting Logic +1. Initialize step counter when agent starts +2. Increment counter after each tool execution +3. Check if current step === maxSteps - 1 + - If true: Remove tools from next request +4. Check if current step === maxSteps + - If true: Stop execution and return final response + +### Edge Cases to Handle +- maxSteps = 0 (should be invalid) +- maxSteps = 1 (immediate text response) +- maxSteps = 2 (one tool call, then text) +- Nested subagent calls (each has own counter) +- Error handling when limit reached mid-operation + +## Testing Strategy +1. Unit tests for step counter logic +2. Integration tests with mock agents +3. Test various maxSteps values (1, 2, 10, undefined) +4. Test tool removal on n-1 step +5. Test nested agent scenarios +6. Test error cases and boundary conditions +7. Performance tests to ensure no overhead when maxSteps not used + +## Validation Checklist +- [ ] maxSteps parameter accepted in agent definitions +- [ ] Step counter increments correctly +- [ ] Execution stops at limit +- [ ] Tools removed on penultimate step +- [ ] Final response is text-only +- [ ] No regression in unlimited agents +- [ ] Logs show step count and limit +- [ ] Clear status message on limit reached +- [ ] Tests pass for all scenarios +- [ ] Documentation includes examples + +## Example Usage +```typescript +const limitedAgent = { + name: "limited-helper", + description: "An agent with step limits", + maxSteps: 5, // Will stop after 5 steps + tools: [/* ... tools ... */] +}; + +// On step 4, tools will be removed +// On step 5, execution stops with text response +``` \ No newline at end of file diff --git a/sprints/uninstaller/opencode-01-uninstaller.md b/sprints/uninstaller/opencode-01-uninstaller.md new file mode 100644 index 000000000..75d0c204c --- /dev/null +++ b/sprints/uninstaller/opencode-01-uninstaller.md @@ -0,0 +1,79 @@ +# Sprint: OpenCode Uninstaller Feature + +## Problem Statement +Users need a reliable way to completely remove OpenCode from their system, including all configuration files, cached data, and installed components, as outlined in [Issue #3900](https://github.com/sst/opencode/issues/3900). + +## Context +### Existing System +OpenCode is a CLI tool that installs various components and configurations across the system. Currently, there is no comprehensive uninstall command that cleanly removes all traces of the installation. + +### Uninstaller Feature Requirements +The uninstaller must provide a complete removal process that: +- Removes the OpenCode binary/executable +- Cleans up configuration files from user directories +- Removes cached data and temporary files +- Provides options for selective removal (keep configs, etc.) +- Confirms actions before destructive operations + +## Success Criteria +- [ ] Uninstall command (`opencode uninstall`) is available in the CLI +- [ ] Command removes OpenCode executable from installation path +- [ ] Configuration files in ~/.opencode are removed (with --all flag) +- [ ] Cache directories are cleaned up +- [ ] User is prompted for confirmation before removal +- [ ] Option to keep configuration files (--keep-config) +- [ ] Uninstaller provides clear feedback on what was removed +- [ ] Process is reversible by reinstalling OpenCode +- [ ] Exit code 0 on successful uninstallation +- [ ] Comprehensive error handling for permission issues +- [ ] Documentation updated with uninstall instructions + +## Technical Requirements + +### CLI Interface +```bash +opencode uninstall [options] + --all Remove everything including configs + --keep-config Keep configuration files + --force Skip confirmation prompts + --dry-run Show what would be removed without doing it +``` + +### File Locations to Handle +- **Binary**: `/usr/local/bin/opencode` or installation path +- **Config**: `~/.opencode/` directory +- **Cache**: `~/.cache/opencode/` directory +- **Temp**: `/tmp/opencode-*` files +- **Logs**: `~/.opencode/logs/` directory + +### Implementation Steps +1. Parse command arguments and flags +2. Identify all OpenCode-related files and directories +3. Show user what will be removed (with confirmation) +4. Remove files in correct order (temp -> cache -> config -> binary) +5. Verify removal and report status +6. Clean up any remaining symlinks or PATH entries + +### Error Handling +- Permission denied errors should suggest using sudo +- Missing files should not cause failure +- Partial uninstall should be reported clearly +- Network operations should have timeout handling + +## Testing Strategy +1. Install OpenCode in a test container +2. Create configuration and cache files +3. Run uninstall command with various flags +4. Verify complete removal of all components +5. Test edge cases (permissions, missing files, etc.) +6. Validate that reinstallation works after uninstall + +## Validation Checklist +- [ ] Binary file removed from system +- [ ] Config directory removed (when using --all) +- [ ] Cache directory cleaned up +- [ ] No orphaned files remain +- [ ] PATH environment cleaned if modified +- [ ] Exit codes match expected values +- [ ] Help text includes uninstall command +- [ ] Man page or docs updated \ No newline at end of file