feat: Add undo tool and JSON/YAML validation for edit/write tools (ARM-20) - #2
feat: Add undo tool and JSON/YAML validation for edit/write tools (ARM-20)#2agent-vera[bot] wants to merge 13 commits into
Conversation
Extract shared runAgentTask helper to eliminate ~40 lines of duplicated session logic. Change agent/delegate tool schemas from single `task` to `tasks` array, running them concurrently via Promise.allSettled with p-limit(3). Move p-limit to production dependencies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Spawn a fresh validator agent after the main agent finishes to review modified files, run build/tests, and fix issues. Enabled via VALIDATION_ENABLED=true env var. Integrated into headless, Linear, and GitHub handlers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add .pi/agents/validator.md with system prompt, model, and tool config - Rewrite validation.ts to load the agent definition and delegate to runAgentTask instead of manually spawning sessions - Filter validator out of delegation tools (like main) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace getModifiedFiles() with getWorkingTreeDiff() which returns combined staged + unstaged diffs plus untracked file names. The validator now receives the actual diff in a code block, giving it full context of what changed without needing to read every file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Parse PASS/FAIL status from validator report. On failure, feed the validator's report back to the main agent session (which is still alive) so it can address the issues with full conversation context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add `guidelines` frontmatter field to AgentDefinition, surfaced as `promptGuidelines` on the tool so the model knows WHEN to use each agent - Fix HTML comments before frontmatter delimiters that silently broke parseFrontmatter — descriptions, model, tools, and thinking config were all being ignored (falling back to defaults) - Add clear usage guidelines to architect and scout agent definitions - Strengthen delegation guidance in main agent system prompt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Scout and architect were missing web_search and web_fetch, limiting them to codebase-only analysis. Also add find/ls to main agent's tool docs and mention web tools in scout/architect body text. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The search tool handles both content search and file discovery (glob, type filters), making find and ls redundant. Also update the default fallback tool list in agent-session-runner. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…M-20) Undo: - New undo.ts tool: restores a file to its pre-edit state (one-level deep) - Shared previousVersions Map wired through builtin-tools.ts - edit.ts and write.ts snapshot file contents before every write - Undo clears its history after use; updates fileHashes for stale detection Validation: - New file-validation.ts: validates JSON (JSON.parse) and YAML (yaml.parse) - edit.ts and write.ts call validateFileContent() after every write - Non-blocking: appends a warning to success message if parse fails - No validation for non-JSON/YAML files (returns null) Tests: - undo.test.ts: restore, history clearing, hash updates, diff output - file-validation.test.ts: JSON/YAML valid/invalid, non-validatable files - edit.test.ts: previousVersions snapshots, validation warnings
|
@agent-vera please fix merge conflicts |
|
Merge conflicts resolved and pushed. Here's a summary of what was done: Merge Conflict Resolution SummaryResolved 10 conflicted files from merging Resolution decisions per file:
Additional fix (not in conflict markers):
🔍 Activity log (95 steps)✅ |
Resolve merge conflicts from master's .pi→.anton rename, search tool removal, parallel task output formatting, GitHub progress tracking, and agent-session-runner type improvements. Key resolution decisions: - .anton/agents/*.md: take master (directory rename + content updates) - builtin-tools.ts: keep PR's BuiltinToolMaps/undo/previousVersions, drop search/find/ls (search removed on master, find/ls not in package) - agent-session-runner.ts: take master (typed imports, onEvent, getModelDynamic), fix createBuiltinTool call to use BuiltinToolMaps - agent-tools.ts: take master output format, keep PR's validator filter - delegate.ts: take master (cleaner output format) - handler.ts: merge both — PR's validation pass + master's activitySummary - headless.ts: keep PR's validation pass - cron/executor.ts: update createBuiltinTool call to use BuiltinToolMaps - validator.md: move to .anton/agents/, remove search tool reference
|
|
|
@agent-vera please fix all the merge conflicts |
|
All done. Resolved all 10 merge conflicts, fixed 3 additional issues found during build verification, confirmed TypeScript compiles clean and all 25 tests pass, pushed the merge commit, and commented on the PR with a summary. 🔍 Activity log (101 steps)✅ |
Resolve merge conflicts: - src/agents/validator.md: moved to new src/agents/ location (renamed from .anton/agents/) - src/github/handler.ts: kept validation import, removed duplicate session import - src/headless.ts: kept both new master imports and branch validation import - src/linear/handler.ts: took master's refactored handler (validation was in old handler code, now needs runtime.ts) - src/tools/agent-session-runner.ts: kept BuiltinToolMaps + added langsmith import from master - src/tools/agent-tools.ts: deleted (removed in master, branch changes were trivial) - src/tools/builtin-tools.ts: kept BuiltinToolMaps with previousVersions for undo support - src/tools/cron/executor.ts: kept BuiltinToolMaps + master's registry-based custom tool resolution - src/tools/edit.ts: kept previousVersions.set() calls for undo snapshots - src/tools/write.ts: used node: prefixed imports from master + kept file-validation import - src/tools/workflow/engine-builtins.ts: updated to use BuiltinToolMaps - Fixed test type errors (TextContent | ImageContent union)
|
All merge conflicts resolved and pushed. Here's what I did: 10 conflicting files resolved:
Additional fixes:
Verification: TypeScript compiles clean ( |
|
Pushed. The CI failure was all Biome lint/formatting issues in the branch's new and modified files:
All fixed with 🔍 Activity log (17 steps)❌ |
- Use node: protocol for Node.js imports (file-validation.ts, undo.ts) - Fix import ordering (handler.ts, headless.ts, validation.ts, etc.) - Fix unused variables in tests (undo.test.ts, file-validation.test.ts) - Fix unused imports in edit.test.ts - Apply biome formatting across all changed files
Summary
Implements both features from ARM-20:
1. Undo Tool
src/tools/undo.ts: Standalone undo tool that restores a file to its pre-edit stateMap<string, string>builtin-tools.tsalongside read/edit/write so all tools share the samepreviousVersionsmapedit.tsandwrite.tssnapshot file contents intopreviousVersionsbefore every writefileHashesis updated for stale detection2. JSON/YAML Validation
src/tools/file-validation.ts: Post-write validator for JSON (JSON.parse) and YAML (yaml.parse)⚠️ Warningto the success message if the file doesn't parse — the write still succeedsnullfor non-JSON/YAML files (no validation attempted)Tests (25 new tests, all passing)
undo.test.ts: restore, history clearing, hash updates, diff output (5 tests)file-validation.test.ts: JSON/YAML valid/invalid, non-validatable file types (12 tests)edit.test.ts: previousVersions snapshots on edit/replace, validation warnings for JSON/YAML (8 tests)Files Changed
undo.ts,file-validation.ts,undo.test.ts,file-validation.test.ts,edit.test.tsedit.ts,write.ts,builtin-tools.tsCloses ARM-20