refactor(agent-snapshot): optimize code architecture and reduce duplication#1709
Open
refactor(agent-snapshot): optimize code architecture and reduce duplication#1709
Conversation
✅ Deploy Preview for agent-tars-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for tarko ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
dc6c5de to
acaf9e8
Compare
- Remove complex prototype chain manipulation from AgentSnapshot constructor - Simplify AgentSnapshot to focus on core snapshot generation and replay functionality - Add generic verification method to reduce code duplication in SnapshotManager - Consolidate repeated file path operations with helper methods - Improve README with comprehensive documentation and examples - Remove unnecessary type assertions and comments - Maintain API compatibility while improving internal structure Breaking Changes: None - all public APIs remain unchanged
…cation - Remove custom diff implementation, use existing snapshot-diff library - Extract ToolCallTracker utility to eliminate code duplication between hooks - Improve type safety by replacing 'any' with 'unknown' types - Simplify hook management with helper methods in AgentHookBase - Remove redundant comments and improve code clarity - Optimize CLI command handling in AgentSnapshotRunner - Maintain all existing Public APIs without breaking changes
- Fix loop count mismatch in streaming mode by fully consuming streams - Track agent_run_end events to ensure complete execution - Add wait time for background processing and cleanup handlers - Improve error handling and logging for streaming responses Resolves issue where AgentSnapshot.replay() didn't wait for complete agent execution in streaming mode
51e7657 to
debf493
Compare
- Use proper type casting for async iterator checks - Add unknown type conversion to satisfy TypeScript compiler - Improve type safety in stream consumption logic Fixes build errors in agent-snapshot package
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.
Summary
Comprehensive refactoring of
@tarko/agent-snapshotpackage to improve code quality, maintainability, and architectural consistency while preserving all public APIs.Key Improvements
🔧 Code Quality & Architecture
ToolCallTrackerutility classsnapshot-difflibraryanytypes withunknownAgentHookBase📦 Bundle Optimization
🧹 Code Cleanup
AgentSnapshotRunnerTechnical Details
New Components
ToolCallTracker: Shared utility for managing tool call lifecycle across hooksstoreOriginalHooks()andinstallNewHooks()helpersRefactored Components
AgentSnapshotNormalizer: Uses existingsnapshot-diffinstead of custom implementationAgentHookBase: Simplified hook lifecycle managementAgentSnapshotRunner: Cleaner CLI command processingType Safety Improvements
anytypes replaced withunknownfor better type safetyTesting
Checklist