@agi-cli/sdk 0.1.87 → 0.1.89

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agi-cli/sdk",
3
- "version": "0.1.87",
3
+ "version": "0.1.89",
4
4
  "description": "AI agent SDK for building intelligent assistants - tree-shakable and comprehensive",
5
5
  "author": "ntishxyz",
6
6
  "license": "MIT",
@@ -259,6 +259,12 @@ function applyHunkToLines(
259
259
  .map((line) => line.content);
260
260
 
261
261
  const removals = hunk.lines.filter((line) => line.kind === 'remove');
262
+ const additions = hunk.lines
263
+ .filter((line) => line.kind === 'add')
264
+ .map((line) => line.content);
265
+ const contextLines = hunk.lines
266
+ .filter((line) => line.kind === 'context')
267
+ .map((line) => line.content);
262
268
 
263
269
  const hasExpected = expected.length > 0;
264
270
  const initialHint =
@@ -29,9 +29,45 @@ You help with coding and build tasks.
29
29
  actual line from file ← Context (space prefix) - REQUIRED
30
30
  -line to remove ← Remove this line
31
31
  +line to add ← Add this line
32
- more context ← More context (space prefix)
32
+ more context ← More context (space prefix)
33
33
  ```
34
34
 
35
+ ## ⚠️ Why Patches Fail (Common Mistakes)
36
+
37
+ **Mistake 1: Patching from Memory** (Most Common)
38
+ - ❌ Creating patches based on what you remember from earlier
39
+ - ✅ ALWAYS read the file FIRST in this same turn, then create patch
40
+
41
+ **Mistake 2: Context Lines Don't Match File**
42
+ - ❌ Guessing or inventing what context lines look like
43
+ - ✅ Copy context lines EXACTLY character-for-character from the file you just read
44
+ - Context lines (space prefix) must exist in the actual file
45
+
46
+ **Mistake 3: Wrong Indentation**
47
+ - ❌ File uses 2 spaces; patch uses tabs or 4 spaces
48
+ - ✅ Match indentation exactly: if file uses spaces, patch uses spaces (same count)
49
+
50
+ **Mistake 4: Missing Markers**
51
+ - ❌ Forgot `*** End Patch` or malformed `*** Begin Patch`
52
+ - ✅ Always wrap: `*** Begin Patch` ... hunks ... `*** End Patch`
53
+
54
+ **Mistake 5: Hallucinated Code**
55
+ - ❌ Adding lines that "should" be there but aren't
56
+ - ✅ Only use lines that actually exist in the file
57
+
58
+ **Success Formula:**
59
+ 1. Read file with `read` tool
60
+ 2. Note exact indentation (spaces/tabs), line content
61
+ 3. Extract 2-3 context lines before/after your change
62
+ 4. Copy them EXACTLY into patch with space prefix
63
+ 5. Add your `-old` and `+new` lines
64
+ 6. Verify markers: `*** Begin Patch` and `*** End Patch`
65
+
66
+ **When Patch Fails:**
67
+ - Error means context didn't match or file changed
68
+ - Solution: Read the file AGAIN, check character-for-character
69
+ - If still failing repeatedly, use `edit` tool instead
70
+
35
71
  **Using the `edit` Tool** (Alternative):
36
72
  - Specify the file path and a list of operations
37
73
  - Operations are applied sequentially to the latest file state
@@ -15,7 +15,8 @@ You MUST call the `finish` tool at the end of every response to signal completio
15
15
  **IMPORTANT**: Do NOT call `finish` before streaming your response. Always stream your message first, then call `finish`. If you forget to call `finish`, the system will hang and not complete properly.
16
16
 
17
17
  File Editing Best Practices:
18
- - ALWAYS read a file immediately before using apply_patch on it - never patch from memory
18
+ - ⚠️ CRITICAL: ALWAYS read a file immediately before using apply_patch - never patch from memory
19
+ - Read the file in THIS turn, not from previous context or memory
19
20
  - When making multiple edits to the same file, combine them into a single edit operation with multiple ops
20
21
  - Each edit operation re-reads the file, so ops within a single edit call are applied sequentially to the latest content
21
22
  - If you need to make edits based on previous edits, ensure they're in the same edit call or re-read the file between calls
@@ -210,6 +210,28 @@ NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTAN
210
210
 
211
211
  IMPORTANT: Always use the update_plan tool to plan and track tasks throughout the conversation.
212
212
 
213
+ # Apply Patch Tool - Critical Guidelines for Claude
214
+
215
+ **⚠️ Claude-Specific Patch Failures:**
216
+
217
+ You (Claude/Sonnet) generally excel at using patches, but even you can fail when:
218
+ - Relying on memory from earlier in the conversation instead of fresh file reads
219
+ - Making assumptions about unchanged file state between operations
220
+ - Mixing tabs/spaces when file indentation isn't verified first
221
+
222
+ **Your Success Pattern (Follow This):**
223
+ 1. Read file with `read` tool immediately before patching
224
+ 2. Extract exact context lines (space prefix) from what you just read
225
+ 3. Match indentation character-for-character
226
+ 4. Use multiple `@@` hunks for multiple edits in same file
227
+ 5. Wrap in `*** Begin Patch` and `*** End Patch`
228
+
229
+ **If Patch Fails:**
230
+ - Don't retry with same context - read file AGAIN first
231
+ - Check that context lines exist exactly as written
232
+ - Verify indentation matches (spaces vs tabs)
233
+ - If failing 2+ times, switch to `edit` tool instead
234
+
213
235
  # Code References
214
236
 
215
237
  When referencing specific functions or pieces of code include the pattern `file_path:line_number` to allow the user to easily navigate to the source code location.
@@ -427,6 +427,38 @@ When using the shell, you must adhere to the following guidelines:
427
427
  - When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)
428
428
  - Read files in chunks with a max chunk size of 250 lines. Do not use python scripts to attempt to output larger chunks of a file. Command line output will be truncated after 10 kilobytes or 256 lines of output, regardless of the command used.
429
429
 
430
+ ## Apply Patch Tool - Critical Guidelines
431
+
432
+ **⚠️ Common Patch Failures Across All Models:**
433
+
434
+ Most patch failures happen because:
435
+ - Patches created from memory instead of reading file first
436
+ - Context lines guessed or invented rather than copied exactly
437
+ - Indentation mismatches (tabs vs spaces)
438
+ - Missing or malformed markers (`*** Begin Patch` / `*** End Patch`)
439
+ - Hallucinated code in context lines
440
+
441
+ **Universal Pre-Flight Checklist:**
442
+ Before calling `apply_patch`, verify ALL of these:
443
+ - [ ] File was read with `read` tool in THIS turn (not from memory)
444
+ - [ ] Context lines (space prefix) copied EXACTLY character-for-character
445
+ - [ ] Indentation verified (if file uses spaces, patch uses spaces)
446
+ - [ ] Wrapped in `*** Begin Patch` and `*** End Patch` markers
447
+ - [ ] Used correct directive: `*** Add/Update/Delete File: path`
448
+
449
+ **Success Formula:**
450
+ 1. Use `read` tool on target file
451
+ 2. Identify exact location to edit
452
+ 3. Extract 2-3 lines before/after as context (space prefix)
453
+ 4. Add `-old` lines to remove, `+new` lines to add
454
+ 5. Wrap in `*** Begin Patch` ... `*** End Patch`
455
+ 6. Verify all context matches file exactly
456
+
457
+ **If Patch Fails:**
458
+ - Error = context didn't match OR file content changed
459
+ - Solution: Read file AGAIN, verify context character-by-character
460
+ - After 2+ failures: use `edit` tool instead (more forgiving)
461
+
430
462
  ## `update_plan`
431
463
 
432
464
  A tool named `update_plan` is available to you. You can use it to keep an up‑to‑date, step‑by‑step plan for the task.
@@ -366,6 +366,37 @@ When using the shell, you must adhere to the following guidelines:
366
366
  - Shell commands should be reserved for execution, not discovery
367
367
  - Read files in chunks with a max chunk size of 250 lines. Do not use python scripts to attempt to output larger chunks of a file. Command line output will be truncated after 10 kilobytes or 256 lines of output, regardless of the command used.
368
368
 
369
+ ## Apply Patch Tool - Critical for GPT-4 Models
370
+
371
+ **⚠️ GPT-4 Common Patch Failures:**
372
+
373
+ GPT-4 models (especially GPT-4o) often fail patches by:
374
+ - Creating patches from memory instead of reading the file first
375
+ - Guessing at context lines that don't match the actual file
376
+ - Missing or malformed `*** End Patch` markers
377
+ - Mixing tabs/spaces without checking file's indentation
378
+
379
+ **Mandatory Pre-Flight Checklist (Check EVERY time):**
380
+ - [ ] Read the target file with `read` tool in THIS turn
381
+ - [ ] Copy context lines EXACTLY from what you just read
382
+ - [ ] Verify indentation (spaces vs tabs) matches the file
383
+ - [ ] Include `*** Begin Patch` and `*** End Patch` markers
384
+ - [ ] Use space prefix for context lines (NOT `@@` line - that's just a hint)
385
+
386
+ **GPT-4 Success Formula:**
387
+ 1. Call `read` on the file you want to patch
388
+ 2. Identify the exact lines to change
389
+ 3. Copy 2-3 surrounding lines AS-IS (space prefix)
390
+ 4. Add your `-removal` and `+addition` lines
391
+ 5. Wrap in `*** Begin Patch` ... `*** End Patch`
392
+ 6. Double-check markers and indentation before calling tool
393
+
394
+ **If Your Patch Fails:**
395
+ - You didn't read the file first, OR
396
+ - Context lines don't match file character-for-character
397
+ - Solution: Read file AGAIN, copy exact lines
398
+ - After 2 failures: switch to `edit` tool instead
399
+
369
400
  ## `update_plan`
370
401
 
371
402
  A tool named `update_plan` is available to you. You can use it to keep an up‑to‑date, step‑by‑step plan for the task.
@@ -862,6 +862,31 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
862
862
  output: 4096,
863
863
  },
864
864
  },
865
+ {
866
+ id: 'claude-haiku-4-5-20251001',
867
+ label: 'Claude Haiku 4.5',
868
+ modalities: {
869
+ input: ['text', 'image'],
870
+ output: ['text'],
871
+ },
872
+ toolCall: true,
873
+ reasoning: true,
874
+ attachment: true,
875
+ temperature: true,
876
+ knowledge: '2025-02-31',
877
+ releaseDate: '2025-10-15',
878
+ lastUpdated: '2025-10-15',
879
+ openWeights: false,
880
+ cost: {
881
+ input: 1,
882
+ output: 5,
883
+ cacheRead: 0.1,
884
+ },
885
+ limit: {
886
+ context: 200000,
887
+ output: 64000,
888
+ },
889
+ },
865
890
  {
866
891
  id: 'claude-opus-4-1-20250805',
867
892
  label: 'Claude Opus 4.1',
@@ -1311,9 +1336,9 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
1311
1336
  lastUpdated: '2025-09-25',
1312
1337
  openWeights: false,
1313
1338
  cost: {
1314
- input: 0.15,
1315
- output: 0.6,
1316
- cacheRead: 0.0375,
1339
+ input: 0.3,
1340
+ output: 2.5,
1341
+ cacheRead: 0.075,
1317
1342
  },
1318
1343
  limit: {
1319
1344
  context: 1048576,
@@ -1459,9 +1484,9 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
1459
1484
  lastUpdated: '2025-09-25',
1460
1485
  openWeights: false,
1461
1486
  cost: {
1462
- input: 0.15,
1463
- output: 0.6,
1464
- cacheRead: 0.0375,
1487
+ input: 0.3,
1488
+ output: 2.5,
1489
+ cacheRead: 0.075,
1465
1490
  },
1466
1491
  limit: {
1467
1492
  context: 1048576,
@@ -1600,6 +1625,31 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
1600
1625
  output: 128000,
1601
1626
  },
1602
1627
  },
1628
+ {
1629
+ id: 'anthropic/claude-4.5-haiku',
1630
+ label: 'Claude Haiku 4.5',
1631
+ modalities: {
1632
+ input: ['text', 'image'],
1633
+ output: ['text'],
1634
+ },
1635
+ toolCall: true,
1636
+ reasoning: true,
1637
+ attachment: true,
1638
+ temperature: true,
1639
+ knowledge: '2025-02-31',
1640
+ releaseDate: '2025-10-15',
1641
+ lastUpdated: '2025-10-15',
1642
+ openWeights: false,
1643
+ cost: {
1644
+ input: 1,
1645
+ output: 5,
1646
+ cacheRead: 0.1,
1647
+ },
1648
+ limit: {
1649
+ context: 200000,
1650
+ output: 64000,
1651
+ },
1652
+ },
1603
1653
  {
1604
1654
  id: 'anthropic/claude-opus-4',
1605
1655
  label: 'Claude Opus 4',
@@ -2062,6 +2112,81 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
2062
2112
  output: 65536,
2063
2113
  },
2064
2114
  },
2115
+ {
2116
+ id: 'google/gemini-2.5-flash-lite',
2117
+ label: 'Gemini 2.5 Flash Lite',
2118
+ modalities: {
2119
+ input: ['text', 'image', 'audio', 'video', 'pdf'],
2120
+ output: ['text'],
2121
+ },
2122
+ toolCall: true,
2123
+ reasoning: true,
2124
+ attachment: true,
2125
+ temperature: true,
2126
+ knowledge: '2025-01',
2127
+ releaseDate: '2025-06-17',
2128
+ lastUpdated: '2025-06-17',
2129
+ openWeights: false,
2130
+ cost: {
2131
+ input: 0.1,
2132
+ output: 0.4,
2133
+ cacheRead: 0.025,
2134
+ },
2135
+ limit: {
2136
+ context: 1048576,
2137
+ output: 65536,
2138
+ },
2139
+ },
2140
+ {
2141
+ id: 'google/gemini-2.5-flash-lite-preview-09-2025',
2142
+ label: 'Gemini 2.5 Flash Lite Preview 09-25',
2143
+ modalities: {
2144
+ input: ['text', 'image', 'audio', 'video', 'pdf'],
2145
+ output: ['text'],
2146
+ },
2147
+ toolCall: true,
2148
+ reasoning: true,
2149
+ attachment: true,
2150
+ temperature: true,
2151
+ knowledge: '2025-01',
2152
+ releaseDate: '2025-09-25',
2153
+ lastUpdated: '2025-09-25',
2154
+ openWeights: false,
2155
+ cost: {
2156
+ input: 0.1,
2157
+ output: 0.4,
2158
+ cacheRead: 0.025,
2159
+ },
2160
+ limit: {
2161
+ context: 1048576,
2162
+ output: 65536,
2163
+ },
2164
+ },
2165
+ {
2166
+ id: 'google/gemini-2.5-flash-preview-09-2025',
2167
+ label: 'Gemini 2.5 Flash Preview 09-25',
2168
+ modalities: {
2169
+ input: ['text', 'image', 'audio', 'video', 'pdf'],
2170
+ output: ['text'],
2171
+ },
2172
+ toolCall: true,
2173
+ reasoning: true,
2174
+ attachment: true,
2175
+ temperature: true,
2176
+ knowledge: '2025-01',
2177
+ releaseDate: '2025-09-25',
2178
+ lastUpdated: '2025-09-25',
2179
+ openWeights: false,
2180
+ cost: {
2181
+ input: 0.3,
2182
+ output: 2.5,
2183
+ cacheRead: 0.031,
2184
+ },
2185
+ limit: {
2186
+ context: 1048576,
2187
+ output: 65536,
2188
+ },
2189
+ },
2065
2190
  {
2066
2191
  id: 'google/gemini-2.5-pro',
2067
2192
  label: 'Gemini 2.5 Pro',
@@ -2957,6 +3082,31 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
2957
3082
  output: 128000,
2958
3083
  },
2959
3084
  },
3085
+ {
3086
+ id: 'openai/gpt-5-image',
3087
+ label: 'GPT-5 Image',
3088
+ modalities: {
3089
+ input: ['text', 'image', 'pdf'],
3090
+ output: ['text', 'image'],
3091
+ },
3092
+ toolCall: true,
3093
+ reasoning: true,
3094
+ attachment: true,
3095
+ temperature: true,
3096
+ knowledge: '2024-10-01',
3097
+ releaseDate: '2025-10-14',
3098
+ lastUpdated: '2025-10-14',
3099
+ openWeights: false,
3100
+ cost: {
3101
+ input: 5,
3102
+ output: 10,
3103
+ cacheRead: 1.25,
3104
+ },
3105
+ limit: {
3106
+ context: 400000,
3107
+ output: 128000,
3108
+ },
3109
+ },
2960
3110
  {
2961
3111
  id: 'openai/gpt-5-mini',
2962
3112
  label: 'GPT-5 Mini',
@@ -4152,6 +4302,34 @@ export const catalog: Record<ProviderId, ProviderCatalogEntry> = {
4152
4302
  npm: '@ai-sdk/anthropic',
4153
4303
  },
4154
4304
  },
4305
+ {
4306
+ id: 'claude-haiku-4-5',
4307
+ label: 'Claude Haiku 4.5',
4308
+ modalities: {
4309
+ input: ['text', 'image'],
4310
+ output: ['text'],
4311
+ },
4312
+ toolCall: true,
4313
+ reasoning: true,
4314
+ attachment: true,
4315
+ temperature: true,
4316
+ knowledge: '2025-02-31',
4317
+ releaseDate: '2025-10-15',
4318
+ lastUpdated: '2025-10-15',
4319
+ openWeights: false,
4320
+ cost: {
4321
+ input: 1,
4322
+ output: 1.25,
4323
+ cacheRead: 0.1,
4324
+ },
4325
+ limit: {
4326
+ context: 200000,
4327
+ output: 64000,
4328
+ },
4329
+ provider: {
4330
+ npm: '@ai-sdk/anthropic',
4331
+ },
4332
+ },
4155
4333
  {
4156
4334
  id: 'claude-opus-4-1',
4157
4335
  label: 'Claude Opus 4.1',