sparkecoder 0.1.58 → 0.1.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +74 -27
  3. package/dist/agent/index.js.map +1 -1
  4. package/dist/cli.js +88 -34
  5. package/dist/cli.js.map +1 -1
  6. package/dist/{index-DqLDYWhb.d.ts → index-Csad1Nx4.d.ts} +5 -5
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +87 -33
  9. package/dist/index.js.map +1 -1
  10. package/dist/{search-DINnDTgj.d.ts → search-BETuS1vh.d.ts} +1 -1
  11. package/dist/server/index.js +87 -33
  12. package/dist/server/index.js.map +1 -1
  13. package/dist/skills/default/browser.md +143 -0
  14. package/dist/skills/default/code-review.md +122 -0
  15. package/dist/skills/default/debugging.md +105 -0
  16. package/dist/skills/default/refactoring.md +197 -0
  17. package/dist/tools/index.d.ts +18 -3
  18. package/dist/tools/index.js +74 -27
  19. package/dist/tools/index.js.map +1 -1
  20. package/package.json +4 -1
  21. package/src/skills/default/browser.md +143 -0
  22. package/src/skills/default/code-review.md +122 -0
  23. package/src/skills/default/debugging.md +105 -0
  24. package/src/skills/default/refactoring.md +197 -0
  25. package/web/.next/BUILD_ID +1 -1
  26. package/web/.next/standalone/web/.next/BUILD_ID +1 -1
  27. package/web/.next/standalone/web/.next/build-manifest.json +2 -2
  28. package/web/.next/standalone/web/.next/prerender-manifest.json +3 -3
  29. package/web/.next/standalone/web/.next/server/app/_global-error.html +2 -2
  30. package/web/.next/standalone/web/.next/server/app/_global-error.rsc +1 -1
  31. package/web/.next/standalone/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  32. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  33. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  34. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  35. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  36. package/web/.next/standalone/web/.next/server/app/_not-found.html +1 -1
  37. package/web/.next/standalone/web/.next/server/app/_not-found.rsc +1 -1
  38. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  39. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  40. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  41. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  42. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  43. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  44. package/web/.next/standalone/web/.next/server/app/docs/installation.html +2 -2
  45. package/web/.next/standalone/web/.next/server/app/docs/installation.rsc +1 -1
  46. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_full.segment.rsc +1 -1
  47. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_head.segment.rsc +1 -1
  48. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_index.segment.rsc +1 -1
  49. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_tree.segment.rsc +1 -1
  50. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation/__PAGE__.segment.rsc +1 -1
  51. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation.segment.rsc +1 -1
  52. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs.segment.rsc +1 -1
  53. package/web/.next/standalone/web/.next/server/app/docs/skills.html +2 -2
  54. package/web/.next/standalone/web/.next/server/app/docs/skills.rsc +1 -1
  55. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_full.segment.rsc +1 -1
  56. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_head.segment.rsc +1 -1
  57. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_index.segment.rsc +1 -1
  58. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_tree.segment.rsc +1 -1
  59. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills/__PAGE__.segment.rsc +1 -1
  60. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills.segment.rsc +1 -1
  61. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs.segment.rsc +1 -1
  62. package/web/.next/standalone/web/.next/server/app/docs/tools.html +2 -2
  63. package/web/.next/standalone/web/.next/server/app/docs/tools.rsc +1 -1
  64. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_full.segment.rsc +1 -1
  65. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_head.segment.rsc +1 -1
  66. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_index.segment.rsc +1 -1
  67. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_tree.segment.rsc +1 -1
  68. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools/__PAGE__.segment.rsc +1 -1
  69. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools.segment.rsc +1 -1
  70. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs.segment.rsc +1 -1
  71. package/web/.next/standalone/web/.next/server/app/docs.html +2 -2
  72. package/web/.next/standalone/web/.next/server/app/docs.rsc +1 -1
  73. package/web/.next/standalone/web/.next/server/app/docs.segments/_full.segment.rsc +1 -1
  74. package/web/.next/standalone/web/.next/server/app/docs.segments/_head.segment.rsc +1 -1
  75. package/web/.next/standalone/web/.next/server/app/docs.segments/_index.segment.rsc +1 -1
  76. package/web/.next/standalone/web/.next/server/app/docs.segments/_tree.segment.rsc +1 -1
  77. package/web/.next/standalone/web/.next/server/app/docs.segments/docs/__PAGE__.segment.rsc +1 -1
  78. package/web/.next/standalone/web/.next/server/app/docs.segments/docs.segment.rsc +1 -1
  79. package/web/.next/standalone/web/.next/server/app/index.html +1 -1
  80. package/web/.next/standalone/web/.next/server/app/index.rsc +1 -1
  81. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p/__PAGE__.segment.rsc +1 -1
  82. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p.segment.rsc +1 -1
  83. package/web/.next/standalone/web/.next/server/app/index.segments/_full.segment.rsc +1 -1
  84. package/web/.next/standalone/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  85. package/web/.next/standalone/web/.next/server/app/index.segments/_index.segment.rsc +1 -1
  86. package/web/.next/standalone/web/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  87. package/web/.next/standalone/web/.next/server/pages/404.html +1 -1
  88. package/web/.next/standalone/web/.next/server/pages/500.html +2 -2
  89. package/web/.next/standalone/web/.next/server/server-reference-manifest.js +1 -1
  90. package/web/.next/standalone/web/.next/server/server-reference-manifest.json +1 -1
  91. /package/web/.next/standalone/web/.next/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_buildManifest.js +0 -0
  92. /package/web/.next/standalone/web/.next/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_clientMiddlewareManifest.json +0 -0
  93. /package/web/.next/standalone/web/.next/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_ssgManifest.js +0 -0
  94. /package/web/.next/standalone/web/.next/static/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_buildManifest.js +0 -0
  95. /package/web/.next/standalone/web/.next/static/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_clientMiddlewareManifest.json +0 -0
  96. /package/web/.next/standalone/web/.next/static/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_ssgManifest.js +0 -0
  97. /package/web/.next/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_buildManifest.js +0 -0
  98. /package/web/.next/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_clientMiddlewareManifest.json +0 -0
  99. /package/web/.next/static/{TuFKgULSvgTGHxXzZoeMo → R5xiWSOp_Nqqe_js-LROo}/_ssgManifest.js +0 -0
@@ -0,0 +1,143 @@
1
+ ---
2
+ name: Browser Automation
3
+ description: Web browser automation using agent-browser for navigation, interaction, screenshots, and testing
4
+ ---
5
+
6
+ # Browser Automation Skill
7
+
8
+ Use `agent-browser` for all web browser automation tasks including navigation, form filling, clicking, screenshots, and testing.
9
+
10
+ ## Setup
11
+
12
+ If Chromium hasn't been installed yet, run:
13
+ ```bash
14
+ agent-browser install
15
+ ```
16
+
17
+ ## Core Workflow
18
+
19
+ Every browser automation follows this pattern:
20
+
21
+ ```bash
22
+ # 1. Navigate to a page
23
+ agent-browser open <url>
24
+
25
+ # 2. Snapshot to get element refs
26
+ agent-browser snapshot -i
27
+
28
+ # 3. Interact using refs from the snapshot
29
+ agent-browser click @e2
30
+ agent-browser fill @e3 "text"
31
+
32
+ # 4. Re-snapshot after page changes
33
+ agent-browser snapshot -i
34
+
35
+ # 5. Close when done
36
+ agent-browser close
37
+ ```
38
+
39
+ ## Element Refs
40
+
41
+ The `snapshot -i` command returns a compact accessibility tree where each interactive element has a unique ref like `@e1`, `@e2`. Use these refs for all interactions - they are deterministic and point to the exact element from the snapshot.
42
+
43
+ ```bash
44
+ agent-browser snapshot -i
45
+ # Output:
46
+ # @e1 [heading] "Example Domain"
47
+ # @e2 [link] "More information..."
48
+ # @e3 [textbox] "Email"
49
+ # @e4 [button] "Submit"
50
+ ```
51
+
52
+ ## Common Commands
53
+
54
+ ### Navigation
55
+ ```bash
56
+ agent-browser open example.com
57
+ agent-browser open example.com --headed # Show browser window for debugging
58
+ agent-browser back # Go back
59
+ agent-browser forward # Go forward
60
+ agent-browser reload # Reload page
61
+ ```
62
+
63
+ ### Interaction
64
+ ```bash
65
+ agent-browser click @e2 # Click by ref
66
+ agent-browser fill @e3 "test@example.com" # Fill input
67
+ agent-browser select @e4 "option1" # Select dropdown option
68
+ agent-browser check @e5 # Check checkbox
69
+ agent-browser uncheck @e5 # Uncheck checkbox
70
+ agent-browser hover @e2 # Hover over element
71
+ agent-browser focus @e3 # Focus element
72
+ ```
73
+
74
+ ### Reading Content
75
+ ```bash
76
+ agent-browser get text @e1 # Get text content of element
77
+ agent-browser get value @e3 # Get input value
78
+ agent-browser get attribute @e2 href # Get attribute value
79
+ agent-browser snapshot # Full page accessibility tree
80
+ agent-browser snapshot -i # Interactive elements only
81
+ ```
82
+
83
+ ### Screenshots
84
+ ```bash
85
+ agent-browser screenshot # Save to temp directory
86
+ agent-browser screenshot page.png # Save to specific path
87
+ agent-browser screenshot --fullpage # Full page screenshot
88
+ ```
89
+
90
+ After taking a screenshot, use `read_file` to view it:
91
+ ```
92
+ read_file({ path: "page.png" })
93
+ ```
94
+ The `read_file` tool supports images (png, jpg, gif, webp) and will display them visually so you can analyze the page.
95
+
96
+ ### Waiting
97
+ ```bash
98
+ agent-browser wait @e1 # Wait for element to appear
99
+ agent-browser wait --load networkidle # Wait for network idle
100
+ agent-browser wait --url "**/dashboard" # Wait for URL pattern
101
+ agent-browser wait 2000 # Wait milliseconds
102
+ ```
103
+
104
+ ### Sessions
105
+ ```bash
106
+ agent-browser sessions # List active sessions
107
+ agent-browser close # Close current session
108
+ agent-browser close --all # Close all sessions
109
+ ```
110
+
111
+ ## Command Chaining
112
+
113
+ Chain commands with `&&` when you don't need intermediate output:
114
+
115
+ ```bash
116
+ # Open, wait, and snapshot in one call
117
+ agent-browser open example.com && agent-browser wait --load networkidle && agent-browser snapshot -i
118
+
119
+ # Fill a form
120
+ agent-browser fill @e1 "user@example.com" && agent-browser fill @e2 "password" && agent-browser click @e3
121
+ ```
122
+
123
+ Run commands separately when you need to parse output first (e.g., snapshot to discover refs before interacting).
124
+
125
+ ## CSS Selectors
126
+
127
+ CSS selectors and semantic locators also work:
128
+
129
+ ```bash
130
+ agent-browser click "#submit"
131
+ agent-browser fill "#email" "test@example.com"
132
+ agent-browser find role button click --name "Submit"
133
+ ```
134
+
135
+ ## Best Practices
136
+
137
+ 1. **Always snapshot before interacting** - You need refs to click/fill elements
138
+ 2. **Re-snapshot after navigation or page changes** - Refs become stale after the page changes
139
+ 3. **Use `--headed` for debugging** - Shows the browser window so you can see what's happening
140
+ 4. **Use `wait` for dynamic content** - Pages with async loading need waits before snapshots
141
+ 5. **Chain when possible** - Reduces round trips for simple sequences
142
+ 6. **Close when done** - Always close the browser session when finished
143
+ 7. **Use refs over CSS selectors** - Refs from snapshots are more reliable and context-efficient
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: Code Review
3
+ description: Best practices and checklist for reviewing code changes
4
+ ---
5
+
6
+ # Code Review Skill
7
+
8
+ This skill provides guidelines and checklists for conducting thorough code reviews.
9
+
10
+ ## Code Review Checklist
11
+
12
+ ### Functionality
13
+ - [ ] Does the code do what it's supposed to do?
14
+ - [ ] Are edge cases handled properly?
15
+ - [ ] Is error handling appropriate and complete?
16
+ - [ ] Are there any obvious bugs or logic errors?
17
+
18
+ ### Code Quality
19
+ - [ ] Is the code readable and self-documenting?
20
+ - [ ] Are variable and function names descriptive?
21
+ - [ ] Is there appropriate commenting for complex logic?
22
+ - [ ] Does the code follow DRY (Don't Repeat Yourself) principles?
23
+ - [ ] Is the code modular and well-organized?
24
+
25
+ ### Style & Consistency
26
+ - [ ] Does the code follow the project's style guide?
27
+ - [ ] Is formatting consistent with the rest of the codebase?
28
+ - [ ] Are imports organized properly?
29
+ - [ ] Is there consistent use of language features?
30
+
31
+ ### Performance
32
+ - [ ] Are there any obvious performance issues?
33
+ - [ ] Are database queries optimized?
34
+ - [ ] Is there unnecessary computation in loops?
35
+ - [ ] Are resources properly managed (memory, connections, etc.)?
36
+
37
+ ### Security
38
+ - [ ] Is user input validated and sanitized?
39
+ - [ ] Are there any SQL injection vulnerabilities?
40
+ - [ ] Are secrets/credentials properly handled?
41
+ - [ ] Is authentication/authorization implemented correctly?
42
+ - [ ] Are there any XSS vulnerabilities?
43
+
44
+ ### Testing
45
+ - [ ] Are there adequate unit tests?
46
+ - [ ] Do tests cover edge cases?
47
+ - [ ] Are tests readable and maintainable?
48
+ - [ ] Do all tests pass?
49
+
50
+ ### Documentation
51
+ - [ ] Is public API documented?
52
+ - [ ] Are complex algorithms explained?
53
+ - [ ] Is README updated if needed?
54
+ - [ ] Are breaking changes documented?
55
+
56
+ ## Review Process
57
+
58
+ ### 1. Understand the Context
59
+ - Read the PR description and related issues
60
+ - Understand the motivation for the change
61
+ - Check if the approach aligns with project architecture
62
+
63
+ ### 2. High-Level Review
64
+ - Review the overall structure and approach
65
+ - Check if the solution is appropriate for the problem
66
+ - Look for architectural concerns
67
+
68
+ ### 3. Detailed Review
69
+ - Go through each file change
70
+ - Check for bugs, edge cases, and logic errors
71
+ - Verify code quality and style
72
+
73
+ ### 4. Run the Code
74
+ - Pull the branch and test locally if possible
75
+ - Verify the functionality works as expected
76
+ - Test edge cases and error scenarios
77
+
78
+ ### 5. Provide Feedback
79
+ - Be specific and constructive
80
+ - Explain why something is an issue
81
+ - Suggest alternatives when requesting changes
82
+ - Praise good solutions and improvements
83
+
84
+ ## Giving Good Feedback
85
+
86
+ ### Do
87
+ - Be respectful and constructive
88
+ - Focus on the code, not the person
89
+ - Ask questions to understand intent
90
+ - Provide specific suggestions
91
+ - Acknowledge good work
92
+
93
+ ### Don't
94
+ - Be condescending or dismissive
95
+ - Nitpick on trivial issues
96
+ - Request changes for personal preference
97
+ - Leave vague comments like "fix this"
98
+
99
+ ### Comment Examples
100
+
101
+ **Good:**
102
+ ```
103
+ Consider using a Map instead of an object here for better performance
104
+ with frequent lookups. Maps have O(1) lookup time and handle
105
+ non-string keys better.
106
+ ```
107
+
108
+ **Bad:**
109
+ ```
110
+ This is wrong.
111
+ ```
112
+
113
+ ## Common Issues to Watch For
114
+
115
+ 1. **Null/Undefined Checks** - Missing null checks that could cause runtime errors
116
+ 2. **Resource Leaks** - Connections, file handles, or memory not properly released
117
+ 3. **Race Conditions** - Concurrent access issues in async code
118
+ 4. **Error Swallowing** - Catching errors without proper handling or logging
119
+ 5. **Magic Numbers** - Unexplained numeric constants
120
+ 6. **Copy-Paste Code** - Duplicated logic that should be extracted
121
+ 7. **Over-Engineering** - Unnecessary complexity for simple problems
122
+ 8. **Under-Engineering** - Missing error handling, validation, or edge cases
@@ -0,0 +1,105 @@
1
+ ---
2
+ name: Debugging
3
+ description: Systematic approaches for debugging code issues and errors
4
+ ---
5
+
6
+ # Debugging Skill
7
+
8
+ This skill provides systematic approaches for debugging code issues and errors.
9
+
10
+ ## Debugging Process
11
+
12
+ ### 1. Reproduce the Issue
13
+ - Identify the exact steps to reproduce the bug
14
+ - Note any error messages, stack traces, or unexpected behavior
15
+ - Determine if the issue is consistent or intermittent
16
+
17
+ ### 2. Gather Information
18
+ - Read relevant log files and error output
19
+ - Check recent code changes (use `git log` and `git diff`)
20
+ - Review configuration files and environment variables
21
+ - Examine the state of the system when the error occurs
22
+
23
+ ### 3. Isolate the Problem
24
+ - Use binary search to narrow down the problematic code
25
+ - Create minimal reproduction cases
26
+ - Test individual components in isolation
27
+ - Check for common culprits:
28
+ - Null/undefined values
29
+ - Type mismatches
30
+ - Race conditions
31
+ - Resource leaks
32
+ - Configuration errors
33
+
34
+ ### 4. Form and Test Hypotheses
35
+ - Based on gathered information, form theories about the cause
36
+ - Test each hypothesis methodically
37
+ - Keep track of what you've tried and the results
38
+ - Don't assume - verify each step
39
+
40
+ ### 5. Fix and Verify
41
+ - Make the minimal change needed to fix the issue
42
+ - Write tests to prevent regression
43
+ - Verify the fix doesn't introduce new problems
44
+ - Document the root cause and solution
45
+
46
+ ## Common Debugging Techniques
47
+
48
+ ### Console/Log Debugging
49
+ ```javascript
50
+ console.log('Variable value:', variable);
51
+ console.log('Reached checkpoint:', checkpointName);
52
+ console.trace('Stack trace at this point');
53
+ ```
54
+
55
+ ### Binary Search Debugging
56
+ - Comment out half the suspect code
57
+ - If the problem persists, the bug is in the remaining half
58
+ - Repeat until you isolate the problematic line
59
+
60
+ ### Rubber Duck Debugging
61
+ - Explain the code line by line to yourself (or a rubber duck)
62
+ - Often the act of explaining reveals the issue
63
+
64
+ ### Git Bisect
65
+ ```bash
66
+ git bisect start
67
+ git bisect bad # Current commit is broken
68
+ git bisect good <commit> # Known good commit
69
+ # Git will checkout commits for you to test
70
+ ```
71
+
72
+ ## Error Categories
73
+
74
+ ### Syntax Errors
75
+ - Missing brackets, quotes, or semicolons
76
+ - Typos in variable/function names
77
+ - Invalid language constructs
78
+
79
+ ### Runtime Errors
80
+ - Null pointer exceptions
81
+ - Division by zero
82
+ - Array index out of bounds
83
+ - Type errors
84
+
85
+ ### Logic Errors
86
+ - Incorrect algorithm implementation
87
+ - Wrong conditional logic
88
+ - Off-by-one errors
89
+ - State management issues
90
+
91
+ ### Integration Errors
92
+ - API contract mismatches
93
+ - Configuration problems
94
+ - Dependency version conflicts
95
+ - Environment differences
96
+
97
+ ## Best Practices
98
+
99
+ 1. **Don't panic** - Take a systematic approach
100
+ 2. **Read the error message** - It often tells you exactly what's wrong
101
+ 3. **Check the obvious first** - Typos, syntax, configuration
102
+ 4. **Use version control** - `git diff` to see recent changes
103
+ 5. **Keep notes** - Document what you've tried and learned
104
+ 6. **Take breaks** - Fresh eyes often spot issues faster
105
+ 7. **Ask for help** - A second perspective can be invaluable
@@ -0,0 +1,197 @@
1
+ ---
2
+ name: Refactoring
3
+ description: Patterns and techniques for safely improving code structure
4
+ ---
5
+
6
+ # Refactoring Skill
7
+
8
+ This skill provides patterns and techniques for safely improving code structure without changing behavior.
9
+
10
+ ## Refactoring Principles
11
+
12
+ ### 1. Make it Work, Make it Right, Make it Fast
13
+ - First, get the code working correctly
14
+ - Then, clean up and improve structure
15
+ - Finally, optimize for performance if needed
16
+
17
+ ### 2. Small, Incremental Changes
18
+ - Make one small change at a time
19
+ - Test after each change
20
+ - Commit frequently to track progress
21
+
22
+ ### 3. Preserve Behavior
23
+ - The external behavior should remain unchanged
24
+ - Tests should pass before and after refactoring
25
+ - If no tests exist, write them first
26
+
27
+ ## Common Refactoring Patterns
28
+
29
+ ### Extract Function
30
+ **When:** A code block can be grouped and named
31
+ ```javascript
32
+ // Before
33
+ function processOrder(order) {
34
+ // ... lots of code ...
35
+ let total = 0;
36
+ for (const item of order.items) {
37
+ total += item.price * item.quantity;
38
+ }
39
+ // ... more code ...
40
+ }
41
+
42
+ // After
43
+ function calculateTotal(items) {
44
+ return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
45
+ }
46
+
47
+ function processOrder(order) {
48
+ // ... lots of code ...
49
+ const total = calculateTotal(order.items);
50
+ // ... more code ...
51
+ }
52
+ ```
53
+
54
+ ### Extract Variable
55
+ **When:** An expression is complex or used multiple times
56
+ ```javascript
57
+ // Before
58
+ if (order.items.length > 0 && order.status === 'pending' && order.total > 100) {
59
+ applyDiscount(order);
60
+ }
61
+
62
+ // After
63
+ const isEligibleForDiscount =
64
+ order.items.length > 0 &&
65
+ order.status === 'pending' &&
66
+ order.total > 100;
67
+
68
+ if (isEligibleForDiscount) {
69
+ applyDiscount(order);
70
+ }
71
+ ```
72
+
73
+ ### Replace Conditional with Polymorphism
74
+ **When:** Multiple conditionals check the same type
75
+ ```javascript
76
+ // Before
77
+ function getArea(shape) {
78
+ switch (shape.type) {
79
+ case 'circle': return Math.PI * shape.radius ** 2;
80
+ case 'rectangle': return shape.width * shape.height;
81
+ case 'triangle': return (shape.base * shape.height) / 2;
82
+ }
83
+ }
84
+
85
+ // After
86
+ class Circle {
87
+ getArea() { return Math.PI * this.radius ** 2; }
88
+ }
89
+ class Rectangle {
90
+ getArea() { return this.width * this.height; }
91
+ }
92
+ class Triangle {
93
+ getArea() { return (this.base * this.height) / 2; }
94
+ }
95
+ ```
96
+
97
+ ### Replace Magic Numbers with Constants
98
+ **When:** Numeric literals appear in code
99
+ ```javascript
100
+ // Before
101
+ if (user.age >= 18) {
102
+ allowAccess();
103
+ }
104
+
105
+ // After
106
+ const MINIMUM_AGE = 18;
107
+ if (user.age >= MINIMUM_AGE) {
108
+ allowAccess();
109
+ }
110
+ ```
111
+
112
+ ### Introduce Parameter Object
113
+ **When:** Multiple parameters are often passed together
114
+ ```javascript
115
+ // Before
116
+ function createUser(firstName, lastName, email, phone, address, city, country) {
117
+ // ...
118
+ }
119
+
120
+ // After
121
+ function createUser(personalInfo, contactInfo) {
122
+ // ...
123
+ }
124
+ ```
125
+
126
+ ### Replace Nested Conditionals with Guard Clauses
127
+ **When:** Code has deep nesting from conditionals
128
+ ```javascript
129
+ // Before
130
+ function getPayAmount(employee) {
131
+ if (employee.isSeparated) {
132
+ return separatedAmount();
133
+ } else {
134
+ if (employee.isRetired) {
135
+ return retiredAmount();
136
+ } else {
137
+ return normalPayAmount();
138
+ }
139
+ }
140
+ }
141
+
142
+ // After
143
+ function getPayAmount(employee) {
144
+ if (employee.isSeparated) return separatedAmount();
145
+ if (employee.isRetired) return retiredAmount();
146
+ return normalPayAmount();
147
+ }
148
+ ```
149
+
150
+ ## Refactoring Process
151
+
152
+ ### 1. Ensure Test Coverage
153
+ - Write tests for existing behavior if none exist
154
+ - All tests should pass before starting
155
+
156
+ ### 2. Identify Code Smells
157
+ - Long functions
158
+ - Large classes
159
+ - Duplicate code
160
+ - Complex conditionals
161
+ - Long parameter lists
162
+ - Feature envy
163
+ - Primitive obsession
164
+
165
+ ### 3. Apply Appropriate Refactoring
166
+ - Choose the right pattern for the smell
167
+ - Make small, incremental changes
168
+ - Run tests after each change
169
+
170
+ ### 4. Review and Iterate
171
+ - Check if the code is clearer
172
+ - Look for further improvements
173
+ - Ensure performance hasn't degraded
174
+
175
+ ## Code Smells Reference
176
+
177
+ | Smell | Description | Common Refactorings |
178
+ |-------|-------------|---------------------|
179
+ | Long Method | Function does too much | Extract Function |
180
+ | Large Class | Class has too many responsibilities | Extract Class |
181
+ | Duplicate Code | Same code in multiple places | Extract Function, Template Method |
182
+ | Long Parameter List | Too many function parameters | Introduce Parameter Object |
183
+ | Feature Envy | Method uses other class's data too much | Move Method |
184
+ | Data Clumps | Same data items often appear together | Extract Class |
185
+ | Primitive Obsession | Overuse of primitives instead of objects | Replace Primitive with Object |
186
+ | Switch Statements | Complex switch/case logic | Replace with Polymorphism |
187
+ | Speculative Generality | Unused abstraction for "future" use | Remove |
188
+ | Dead Code | Unreachable or unused code | Remove |
189
+
190
+ ## Safety Checklist
191
+
192
+ - [ ] Tests exist and pass before starting
193
+ - [ ] Making one small change at a time
194
+ - [ ] Running tests after each change
195
+ - [ ] Committing after each successful refactoring
196
+ - [ ] External behavior is preserved
197
+ - [ ] No new features added during refactoring
@@ -1,7 +1,7 @@
1
1
  import * as ai from 'ai';
2
2
  import { ToolSet } from 'ai';
3
- import { B as BashToolProgress, W as WriteFileProgress, S as SearchToolProgress } from '../search-DINnDTgj.js';
4
- export { b as BashToolOptions, d as SearchToolOptions, e as WriteFileToolOptions, c as createBashTool, f as createSearchTool, a as createWriteFileTool } from '../search-DINnDTgj.js';
3
+ import { B as BashToolProgress, W as WriteFileProgress, S as SearchToolProgress } from '../search-BETuS1vh.js';
4
+ export { b as BashToolOptions, d as SearchToolOptions, e as WriteFileToolOptions, c as createBashTool, f as createSearchTool, a as createWriteFileTool } from '../search-BETuS1vh.js';
5
5
 
6
6
  interface ReadFileToolOptions {
7
7
  workingDirectory: string;
@@ -11,6 +11,17 @@ declare function createReadFileTool(options: ReadFileToolOptions): ai.Tool<{
11
11
  startLine?: number | undefined;
12
12
  endLine?: number | undefined;
13
13
  }, {
14
+ success: boolean;
15
+ path: string;
16
+ relativePath: string;
17
+ content: string;
18
+ mediaType: string;
19
+ imageData: string;
20
+ sizeBytes: number;
21
+ lineCount?: undefined;
22
+ wasTruncated?: undefined;
23
+ error?: undefined;
24
+ } | {
14
25
  success: boolean;
15
26
  path: string;
16
27
  relativePath: string;
@@ -18,6 +29,8 @@ declare function createReadFileTool(options: ReadFileToolOptions): ai.Tool<{
18
29
  lineCount: number;
19
30
  wasTruncated: boolean;
20
31
  sizeBytes: number;
32
+ mediaType?: undefined;
33
+ imageData?: undefined;
21
34
  error?: undefined;
22
35
  } | {
23
36
  success: boolean;
@@ -25,9 +38,11 @@ declare function createReadFileTool(options: ReadFileToolOptions): ai.Tool<{
25
38
  content: null;
26
39
  path?: undefined;
27
40
  relativePath?: undefined;
41
+ mediaType?: undefined;
42
+ imageData?: undefined;
43
+ sizeBytes?: undefined;
28
44
  lineCount?: undefined;
29
45
  wasTruncated?: undefined;
30
- sizeBytes?: undefined;
31
46
  }>;
32
47
 
33
48
  interface TodoToolOptions {