@avasis-ai/synthcode 1.0.0

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +292 -0
  3. package/dist/chunk-53ZOIXM4.js +624 -0
  4. package/dist/chunk-53ZOIXM4.js.map +1 -0
  5. package/dist/chunk-BWXHO6UJ.js +115 -0
  6. package/dist/chunk-BWXHO6UJ.js.map +1 -0
  7. package/dist/chunk-CARUMOML.js +123 -0
  8. package/dist/chunk-CARUMOML.js.map +1 -0
  9. package/dist/chunk-DGUM43GV.js +11 -0
  10. package/dist/chunk-DGUM43GV.js.map +1 -0
  11. package/dist/chunk-F34HO4RA.js +487 -0
  12. package/dist/chunk-F34HO4RA.js.map +1 -0
  13. package/dist/chunk-FK7S2S7V.js +132 -0
  14. package/dist/chunk-FK7S2S7V.js.map +1 -0
  15. package/dist/chunk-MQ7XP6VT.js +174 -0
  16. package/dist/chunk-MQ7XP6VT.js.map +1 -0
  17. package/dist/chunk-TLPOO6C3.js +176 -0
  18. package/dist/chunk-TLPOO6C3.js.map +1 -0
  19. package/dist/chunk-W6OLZ2OI.js +56 -0
  20. package/dist/chunk-W6OLZ2OI.js.map +1 -0
  21. package/dist/cli/index.cjs +151 -0
  22. package/dist/cli/index.cjs.map +1 -0
  23. package/dist/cli/index.d.cts +1 -0
  24. package/dist/cli/index.d.ts +1 -0
  25. package/dist/cli/index.js +8 -0
  26. package/dist/cli/index.js.map +1 -0
  27. package/dist/cli/run.cjs +128 -0
  28. package/dist/cli/run.cjs.map +1 -0
  29. package/dist/cli/run.d.cts +1 -0
  30. package/dist/cli/run.d.ts +1 -0
  31. package/dist/cli/run.js +126 -0
  32. package/dist/cli/run.js.map +1 -0
  33. package/dist/index-D-K6sx8s.d.cts +8 -0
  34. package/dist/index-D-K6sx8s.d.ts +8 -0
  35. package/dist/index.cjs +2909 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +274 -0
  38. package/dist/index.d.ts +274 -0
  39. package/dist/index.js +1048 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/llm/index.cjs +531 -0
  42. package/dist/llm/index.cjs.map +1 -0
  43. package/dist/llm/index.d.cts +70 -0
  44. package/dist/llm/index.d.ts +70 -0
  45. package/dist/llm/index.js +24 -0
  46. package/dist/llm/index.js.map +1 -0
  47. package/dist/mcp/index.cjs +323 -0
  48. package/dist/mcp/index.cjs.map +1 -0
  49. package/dist/mcp/index.d.cts +39 -0
  50. package/dist/mcp/index.d.ts +39 -0
  51. package/dist/mcp/index.js +11 -0
  52. package/dist/mcp/index.js.map +1 -0
  53. package/dist/memory/index.cjs +146 -0
  54. package/dist/memory/index.cjs.map +1 -0
  55. package/dist/memory/index.d.cts +51 -0
  56. package/dist/memory/index.d.ts +51 -0
  57. package/dist/memory/index.js +10 -0
  58. package/dist/memory/index.js.map +1 -0
  59. package/dist/tools/fuzzy-edit.cjs +200 -0
  60. package/dist/tools/fuzzy-edit.cjs.map +1 -0
  61. package/dist/tools/fuzzy-edit.d.cts +9 -0
  62. package/dist/tools/fuzzy-edit.d.ts +9 -0
  63. package/dist/tools/fuzzy-edit.js +12 -0
  64. package/dist/tools/fuzzy-edit.js.map +1 -0
  65. package/dist/tools/index.cjs +1032 -0
  66. package/dist/tools/index.cjs.map +1 -0
  67. package/dist/tools/index.d.cts +4 -0
  68. package/dist/tools/index.d.ts +4 -0
  69. package/dist/tools/index.js +39 -0
  70. package/dist/tools/index.js.map +1 -0
  71. package/dist/types-C11cw5ZD.d.cts +177 -0
  72. package/dist/types-C11cw5ZD.d.ts +177 -0
  73. package/dist/utils-TF4TBXQJ.js +10 -0
  74. package/dist/utils-TF4TBXQJ.js.map +1 -0
  75. package/dist/web-fetch-B42QzYD2.d.cts +85 -0
  76. package/dist/web-fetch-EDdhxmEf.d.ts +85 -0
  77. package/package.json +134 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AVASIS AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,292 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/hero.png?v=7" alt="SynthCode" width="1200">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <img src="https://img.shields.io/npm/v/@avasis-ai/synthcode?style=flat-square&color=black&logo=osi" alt="npm">
7
+ <img src="https://img.shields.io/npm/l/@avasis-ai/synthcode?style=flat-square&color=black&logo=osi" alt="MIT">
8
+ <img src="https://img.shields.io/badge/TypeScript-5.9+-3178C6?style=flat-square" alt="TypeScript">
9
+ <img src="https://img.shields.io/badge/95_tests-4CAF50?style=flat-square" alt="tests">
10
+ <img src="https://img.shields.io/badge/zero_deps-6C6C6C?style=flat-square" alt="zero deps">
11
+ <img src="https://img.shields.io/badge/PRs_Welcome-brightgreen?style=flat-square&logo=osi" alt="PRs Welcome">
12
+ </p>
13
+
14
+ <p align="center">
15
+ <b>Built from publicly available source. Clean-room implementation. Zero copied code.</b>
16
+ </p>
17
+
18
+ ---
19
+
20
+ Claude Code's architecture was published on GitHub. The internet went wild. While everyone was reading the source, we studied the patterns and built something better.
21
+
22
+ **SynthCode** is the production-grade agent framework Claude Code should have been: lightweight, model-agnostic, TypeScript-first, MIT licensed.
23
+
24
+ ## Why SynthCode?
25
+
26
+ The best agent frameworks aren't walled gardens. They're composable, transparent, and work with any model you choose. SynthCode extracts the battle-tested agentic patterns from publicly available source and combines them with the best ideas from the open-source ecosystem.
27
+
28
+ - **Zero runtime dependencies** -- only peer deps on `@anthropic-ai/sdk`, `openai`, and `zod` (all optional)
29
+ - **Works with Claude, GPT, Ollama** -- swap providers with one line, or bring your own
30
+ - **8 built-in tools** -- Bash, FileRead, FileWrite, FileEdit (8-strategy fuzzy engine), Glob, Grep, WebFetch, MCP
31
+ - **Battle-tested agent loop** -- doom-loop detection, retry with backoff, token-aware compaction
32
+ - **Permissions engine** -- pattern-based allow/deny/ask with wildcard support
33
+ - **Sub-agent delegation** -- fork agents, nest them as tools, isolate permissions
34
+ - **Structured output** -- Zod-validated responses via `structured()` or `structuredViaTool()`
35
+ - **34KB ESM bundle** -- smaller than most single-file utilities
36
+
37
+ ## Quick Start
38
+
39
+ ```bash
40
+ npx @avasis-ai/synthcode "Explain this codebase" --ollama qwen3:32b
41
+ ```
42
+
43
+ Zero config. Auto-detects Ollama, Anthropic, or OpenAI from environment variables.
44
+
45
+ ## In Code
46
+
47
+ ```typescript
48
+ import { Agent, BashTool, FileReadTool, OllamaProvider } from "@avasis-ai/synthcode";
49
+
50
+ const agent = new Agent({
51
+ model: new OllamaProvider({ model: "qwen3:32b" }),
52
+ tools: [BashTool, FileReadTool],
53
+ });
54
+
55
+ for await (const event of agent.run("List all TypeScript files in src/")) {
56
+ if (event.type === "text") process.stdout.write(event.text);
57
+ if (event.type === "tool_use") console.log(` [${event.name}]`);
58
+ }
59
+ ```
60
+
61
+ ## Architecture
62
+
63
+ <p align="center">
64
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/architecture.png?v=7" alt="Architecture" width="800">
65
+ </p>
66
+
67
+ ```
68
+ User Prompt
69
+ |
70
+ v
71
+ [Agent] --> [Agent Loop]
72
+ |
73
+ +-- Context Check --> Compact / Prune
74
+ +-- Permission Check --> Allow / Deny / Ask
75
+ +-- LLM Call (any provider)
76
+ +-- Tool Orchestration (concurrent + serial)
77
+ +-- Doom Loop Detection
78
+ +-- Hook System (turn/tool/error/compact)
79
+ |
80
+ v
81
+ Response + Tool Results
82
+ ```
83
+
84
+ ## Features
85
+
86
+ <p align="center">
87
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/features.png?v=7" alt="Features" width="900">
88
+ </p>
89
+
90
+ | Feature | SynthCode | Claude Code | OpenCode | Codex |
91
+ |---------|-----------|-------------|----------|-------|
92
+ | Open Source | MIT | Proprietary | MIT | MIT |
93
+ | Multi-Provider | Claude, GPT, Ollama, Custom | Claude only | Claude only | Claude only |
94
+ | Built-in Tools | 8 | 12 | 5 | 6 |
95
+ | Fuzzy Edit Engine | 8 strategies | Unknown | 1 strategy | Unknown |
96
+ | Context Compaction | Token-aware | Yes | Basic | Yes |
97
+ | Doom Loop Detection | Yes | Unknown | No | Unknown |
98
+ | Sub-agent Delegation | Yes with isolation | Yes | No | Yes |
99
+ | MCP Support | Yes | Yes | No | No |
100
+ | Zero Runtime Deps | Yes | No | No | No |
101
+
102
+ ## Tools
103
+
104
+ <p align="center">
105
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/tools.png?v=7" alt="Tools" width="900">
106
+ </p>
107
+
108
+ ### FileEdit: 8-Strategy Fuzzy Engine
109
+
110
+ When an LLM's edit doesn't match exactly, SynthCode tries 8 fuzzy matching strategies before giving up:
111
+
112
+ 1. Exact match
113
+ 2. Line-trimmed (ignore leading/trailing whitespace per line)
114
+ 3. Block anchor (match first/last line, fuzzy-match middle)
115
+ 4. Whitespace-normalized (collapse all whitespace to single spaces)
116
+ 5. Indentation-flexible (strip common indentation)
117
+ 6. Escape-normalized (`\n` -> newline, `\"` -> quote)
118
+ 7. Trimmed boundary (trim the search string)
119
+ 8. Context-aware (first/last line anchors with proportional middle matching)
120
+
121
+ ## Providers
122
+
123
+ <p align="center">
124
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/models.png?v=7" alt="Models" width="900">
125
+ </p>
126
+
127
+ ```typescript
128
+ // Claude
129
+ import { AnthropicProvider } from "@avasis-ai/synthcode/llm";
130
+ new AnthropicProvider({ apiKey: "...", model: "claude-sonnet-4-20250514" });
131
+
132
+ // GPT
133
+ import { OpenAIProvider } from "@avasis-ai/synthcode/llm";
134
+ new OpenAIProvider({ apiKey: "...", model: "gpt-4o" });
135
+
136
+ // Ollama (local, free)
137
+ import { OllamaProvider } from "@avasis-ai/synthcode/llm";
138
+ new OllamaProvider({ model: "qwen3:32b" });
139
+
140
+ // Custom
141
+ import { createProvider } from "@avasis-ai/synthcode/llm";
142
+ createProvider({ provider: "custom", model: "my-model", chat: async (req) => ({ content: [], usage: { inputTokens: 0, outputTokens: 0 }, stopReason: "end_turn" }) });
143
+ ```
144
+
145
+ ## Advanced
146
+
147
+ ### Structured Output with Zod
148
+
149
+ ```typescript
150
+ const result = await agent.structured<{ files: string[]; totalLines: number }>(
151
+ "Analyze this project structure",
152
+ z.object({ files: z.array(z.string()), totalLines: z.number() }),
153
+ );
154
+ ```
155
+
156
+ ### Sub-agent Delegation
157
+
158
+ ```typescript
159
+ const researcher = new Agent({
160
+ model: provider,
161
+ tools: [GlobTool, GrepTool, FileReadTool],
162
+ systemPrompt: "You are a code researcher. Find and analyze code patterns.",
163
+ });
164
+
165
+ const tool = await researcher.asTool({ name: "research", description: "Research the codebase" });
166
+ agent.addTool(tool);
167
+ ```
168
+
169
+ ### Hooks
170
+
171
+ ```typescript
172
+ const agent = new Agent({
173
+ model: provider,
174
+ tools: [BashTool],
175
+ hooks: {
176
+ onToolUse: async (name, input) => {
177
+ console.log(`Tool called: ${name}`);
178
+ return { allow: true, input };
179
+ },
180
+ onError: async (error, turn) => {
181
+ console.error(`Error on turn ${turn}: ${error.message}`);
182
+ return { retry: error.message.includes("429"), message: "Retrying..." };
183
+ },
184
+ },
185
+ } as any);
186
+ ```
187
+
188
+ ## Benchmarks
189
+
190
+ <p align="center">
191
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/benchmarks.png?v=7" alt="Benchmarks" width="800">
192
+ </p>
193
+
194
+ Measured on Apple M4 Pro, Node 22. These are real numbers from `npx @avasis-ai/synthcode test:benchmark`.
195
+
196
+ | Metric | Ops/sec |
197
+ |--------|---------|
198
+ | Token estimation (1KB) | 383K |
199
+ | Context check (100 msgs) | 614K |
200
+ | Tool registry lookup (10K) | 20M |
201
+ | Permission check (10K) | 497M |
202
+ | Compact (500 msgs) | 0.7ms |
203
+
204
+ ## Bundle Size
205
+
206
+ <p align="center">
207
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/images/bundle-chart.png?v=7" alt="Bundle Size" width="800">
208
+ </p>
209
+
210
+ | Framework | ESM | Gzipped |
211
+ |-----------|-----|---------|
212
+ | **SynthCode** | **34KB** | **8.7KB** |
213
+ | OpenAI SDK | 100KB+ | 25KB+ |
214
+ | Anthropic SDK | 500KB+ | 120KB+ |
215
+ | Vercel AI SDK | 2MB+ | 400KB+ |
216
+
217
+ ## Stress Tested
218
+
219
+ 70 concurrent agents on a single machine. Zero failures.
220
+
221
+ | Test | Agents | Model | Result |
222
+ |------|--------|-------|--------|
223
+ | Basic tasks + math | 50 | qwen3.5:35b | 50/50 pass |
224
+ | Mixed operations | 20 | qwen3-coder-next:latest (79B) | 20/20 pass |
225
+
226
+ ## CLI
227
+
228
+ ```bash
229
+ # Auto-detect provider from env vars
230
+ npx @avasis-ai/synthcode "What files are in this project?"
231
+
232
+ # Use Ollama (local, free)
233
+ npx @avasis-ai/synthcode "Refactor this function" --ollama qwen3:32b
234
+
235
+ # Use Anthropic
236
+ npx @avasis-ai/synthcode "Fix the bug" --anthropic claude-sonnet-4-20250514
237
+
238
+ # Use OpenAI
239
+ npx @avasis-ai/synthcode "Write tests" --openai gpt-4o
240
+
241
+ # Options
242
+ npx @avasis-ai/synthcode "prompt" --max-turns 20 --system "You are an expert" --json
243
+ ```
244
+
245
+ <p align="center">
246
+ <img src="https://raw.githubusercontent.com/avasis-ai/synthcode/main/docs/demo.gif?v=7" alt="Demo" width="700">
247
+ </p>
248
+
249
+ ## Scaffolding
250
+
251
+ ```bash
252
+ npx @avasis-ai/synthcode init my-agent
253
+ cd my-agent
254
+ npm start "Hello world"
255
+ ```
256
+
257
+ Creates a ready-to-run agent project with TypeScript, Vitest, and all 8 tools wired up.
258
+
259
+ ## Install
260
+
261
+ ```bash
262
+ npm install @avasis-ai/synthcode zod
263
+ ```
264
+
265
+ Peer dependencies (install what you need):
266
+
267
+ ```bash
268
+ npm install @anthropic-ai/sdk # for Claude
269
+ npm install openai # for GPT
270
+ # Ollama: no extra package needed
271
+ ```
272
+
273
+ ## API
274
+
275
+ ```typescript
276
+ import {
277
+ Agent, BashTool, FileReadTool, FileWriteTool, FileEditTool,
278
+ GlobTool, GrepTool, WebFetchTool,
279
+ AnthropicProvider, OpenAIProvider, OllamaProvider,
280
+ ContextManager, PermissionEngine, CostTracker,
281
+ MCPClient, HookRunner,
282
+ InMemoryStore, SQLiteStore,
283
+ } from "@avasis-ai/synthcode";
284
+ ```
285
+
286
+ ## Contributing
287
+
288
+ PRs welcome. This is MIT licensed. Build whatever you want.
289
+
290
+ ## License
291
+
292
+ MIT