Skip to content

Conversation

@ulivz
Copy link
Member

@ulivz ulivz commented Sep 20, 2025

Summary

Refactor @tarko/agent-snapshot package to improve architecture, API design, and maintainability while maintaining backward compatibility.

Key Improvements

🏗️ Architecture Simplification

  • Removed complex prototype chain manipulation from AgentSnapshot class
  • Adopted composition over inheritance pattern
  • Simplified hook system with consistent error handling
  • Eliminated circular reference risks

🎯 API Design Enhancement

  • Renamed replay() to test() for clearer semantics (with backward compatibility)
  • Separated concerns: generate() for snapshot creation, test() for verification
  • Improved method signatures and return types
  • Added comprehensive configuration options

🔒 Type Safety Improvements

  • Enhanced interface definitions with strict typing
  • Fixed TypeScript compilation errors
  • Improved generic type constraints
  • Better error handling with proper types

📚 Documentation Overhaul

  • Complete README rewrite with practical examples
  • API reference documentation
  • Best practices guide
  • Integration examples for Vitest
  • Troubleshooting section

🧹 Code Quality

  • Streamlined AgentSnapshotRunner CLI interface
  • Improved error messages and logging
  • Better resource cleanup
  • Removed unused dependencies

Before/After Comparison

Before:

// Confusing API with mixed responsibilities
const snapshot = new AgentSnapshot(agent, options);
const result = await snapshot.replay(input);  // Non-intuitive naming

After:

// Clear, purpose-driven API
const snapshot = new AgentSnapshot(agent, options);
await snapshot.generate(input); // Clearly generates snapshot
const result = await snapshot.test(input);     // Clearly tests against snapshot

Backward Compatibility

  • replay() method preserved as deprecated alias for test()
  • All existing type exports maintained
  • Configuration options remain compatible
  • Snapshot file format unchanged

Technical Details

  • Build Size: Reduced from ~80kB to ~59.3kB (ESM)
  • Type Safety: All TypeScript errors resolved
  • Dependencies: Removed unused snapshot-diff dependency
  • Performance: Reduced memory footprint through better resource management

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

@netlify
Copy link

netlify bot commented Sep 20, 2025

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit cf3dada
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/68e4079c6a6e2a00089cc80d
😎 Deploy Preview https://deploy-preview-1593--agent-tars-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Sep 20, 2025

Deploy Preview for tarko ready!

Name Link
🔨 Latest commit cf3dada
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/68e4079cb27e8c000829b6ea
😎 Deploy Preview https://deploy-preview-1593--tarko.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

}

private ensureSnapshotDirectory(): void {
if (!fs.existsSync(this.snapshotPath)) {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

private ensureSnapshotDirectory(): void {
if (!fs.existsSync(this.snapshotPath)) {
fs.mkdirSync(this.snapshotPath, { recursive: true });

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
ulivz added 3 commits October 7, 2025 01:58
- Simplify AgentSnapshot class by removing prototype manipulation
- Rename test() method from replay() for clearer semantics
- Add comprehensive README with examples and best practices
- Improve type safety and error handling
- Streamline AgentSnapshotRunner CLI interface
@ulivz ulivz force-pushed the refactor/agent-snapshot-only branch from c0c6e16 to d314b1b Compare October 6, 2025 17:59
@ulivz
Copy link
Member Author

ulivz commented Oct 6, 2025

Closing this since the regression cost introduced by this reconstruction is too high

@ulivz ulivz closed this Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants