@link-assistant/agent 0.0.8
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/EXAMPLES.md +383 -0
- package/LICENSE +24 -0
- package/MODELS.md +95 -0
- package/README.md +388 -0
- package/TOOLS.md +134 -0
- package/package.json +89 -0
- package/src/agent/agent.ts +150 -0
- package/src/agent/generate.txt +75 -0
- package/src/auth/index.ts +64 -0
- package/src/bun/index.ts +96 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +119 -0
- package/src/cli/bootstrap.js +41 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/agent.ts +165 -0
- package/src/cli/cmd/cmd.ts +5 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/mcp.ts +80 -0
- package/src/cli/cmd/models.ts +58 -0
- package/src/cli/cmd/run.ts +359 -0
- package/src/cli/cmd/stats.ts +276 -0
- package/src/cli/error.ts +27 -0
- package/src/command/index.ts +73 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/config/config.ts +705 -0
- package/src/config/markdown.ts +41 -0
- package/src/file/ripgrep.ts +391 -0
- package/src/file/time.ts +38 -0
- package/src/file/watcher.ts +75 -0
- package/src/file.ts +6 -0
- package/src/flag/flag.ts +19 -0
- package/src/format/formatter.ts +248 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +52 -0
- package/src/id/id.ts +72 -0
- package/src/index.js +371 -0
- package/src/mcp/index.ts +289 -0
- package/src/patch/index.ts +622 -0
- package/src/project/bootstrap.ts +22 -0
- package/src/project/instance.ts +67 -0
- package/src/project/project.ts +105 -0
- package/src/project/state.ts +65 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +98 -0
- package/src/provider/opencode.js +47 -0
- package/src/provider/provider.ts +636 -0
- package/src/provider/transform.ts +241 -0
- package/src/server/project.ts +48 -0
- package/src/server/server.ts +249 -0
- package/src/session/agent.js +204 -0
- package/src/session/compaction.ts +249 -0
- package/src/session/index.ts +380 -0
- package/src/session/message-v2.ts +758 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +356 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex.txt +318 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/grok-code.txt +1 -0
- package/src/session/prompt/plan.txt +8 -0
- package/src/session/prompt/polaris.txt +107 -0
- package/src/session/prompt/qwen.txt +109 -0
- package/src/session/prompt/summarize-turn.txt +5 -0
- package/src/session/prompt/summarize.txt +10 -0
- package/src/session/prompt/title.txt +25 -0
- package/src/session/prompt.ts +1390 -0
- package/src/session/retry.ts +53 -0
- package/src/session/revert.ts +108 -0
- package/src/session/status.ts +75 -0
- package/src/session/summary.ts +179 -0
- package/src/session/system.ts +138 -0
- package/src/session/todo.ts +36 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/tool/bash.ts +193 -0
- package/src/tool/bash.txt +121 -0
- package/src/tool/batch.ts +173 -0
- package/src/tool/batch.txt +28 -0
- package/src/tool/codesearch.ts +123 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +604 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/glob.ts +65 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +116 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +110 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/patch.ts +188 -0
- package/src/tool/patch.txt +1 -0
- package/src/tool/read.ts +201 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +87 -0
- package/src/tool/task.ts +126 -0
- package/src/tool/task.txt +60 -0
- package/src/tool/todo.ts +39 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +66 -0
- package/src/tool/webfetch.ts +171 -0
- package/src/tool/webfetch.txt +14 -0
- package/src/tool/websearch.ts +133 -0
- package/src/tool/websearch.txt +11 -0
- package/src/tool/write.ts +33 -0
- package/src/tool/write.txt +8 -0
- package/src/util/binary.ts +41 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/error.ts +54 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +69 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +79 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/locale.ts +39 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +177 -0
- package/src/util/queue.ts +19 -0
- package/src/util/rpc.ts +42 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# @link-assistant/agent
|
|
2
|
+
|
|
3
|
+
**A minimal, public domain AI CLI agent compatible with OpenCode's JSON interface**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@link-assistant/agent)
|
|
6
|
+
[](http://unlicense.org/)
|
|
7
|
+
|
|
8
|
+
> 🚨 **SECURITY WARNING: 100% UNSAFE AND AUTONOMOUS** 🚨
|
|
9
|
+
>
|
|
10
|
+
> This agent operates with **ZERO RESTRICTIONS** and **FULL AUTONOMY**:
|
|
11
|
+
> - ❌ **No Sandbox** - Complete unrestricted file system access
|
|
12
|
+
> - ❌ **No Permissions System** - No approval required for any actions
|
|
13
|
+
> - ❌ **No Safety Guardrails** - Can execute ANY command with full privileges
|
|
14
|
+
> - ⚠️ **Autonomous Execution** - Makes decisions and executes actions independently
|
|
15
|
+
>
|
|
16
|
+
> **ONLY use in isolated environments** (VMs, Docker containers) where AI agents can have unrestricted access. **NOT SAFE** for personal computers, production servers, or systems with sensitive data.
|
|
17
|
+
|
|
18
|
+
> ⚠️ **Bun-only runtime** - This package requires [Bun](https://bun.sh) and does NOT support Node.js or Deno.
|
|
19
|
+
|
|
20
|
+
This is an MVP implementation of an OpenCode-compatible CLI agent, focused on maximum efficiency and unrestricted execution. We reproduce OpenCode's `run --format json --model opencode/grok-code` mode with:
|
|
21
|
+
|
|
22
|
+
- ✅ **JSON Input/Output**: Compatible with `opencode run --format json --model opencode/grok-code`
|
|
23
|
+
- ✅ **Plain Text Input**: Also accepts plain text messages (auto-converted to JSON format)
|
|
24
|
+
- ✅ **Flexible Model Selection**: Defaults to free OpenCode Zen Grok Code Fast 1, supports all [OpenCode Zen models](https://opencode.ai/docs/zen/)
|
|
25
|
+
- ✅ **No Restrictions**: Fully unrestricted file system and command execution access (no sandbox)
|
|
26
|
+
- ✅ **Minimal Footprint**: Built with Bun.sh for maximum efficiency
|
|
27
|
+
- ✅ **Full Tool Support**: 13 tools including websearch, codesearch, batch - all enabled by default
|
|
28
|
+
- ✅ **100% OpenCode Compatible**: All tool outputs match OpenCode's JSON format exactly
|
|
29
|
+
- ✅ **Internal HTTP Server**: Uses local HTTP server for session management (not exposed externally)
|
|
30
|
+
- ❌ **No TUI**: Pure JSON CLI interface only
|
|
31
|
+
- ❌ **No Sandbox**: Designed for VMs/containers where full access is acceptable
|
|
32
|
+
- ❌ **No LSP**: No Language Server Protocol support for diagnostics
|
|
33
|
+
- ❌ **No Permissions**: No permission system - full unrestricted access
|
|
34
|
+
- ❌ **No IDE Integration**: No IDE/editor integration features
|
|
35
|
+
- ❌ **No Plugins**: No plugin system
|
|
36
|
+
- ❌ **No Share**: No session sharing functionality
|
|
37
|
+
- ❌ **No External API**: Server runs only internally, not exposed to network
|
|
38
|
+
- ❌ **No ACP**: No Agent Client Protocol support
|
|
39
|
+
|
|
40
|
+
## Project Vision
|
|
41
|
+
|
|
42
|
+
We're creating a slimmed-down, public domain version of OpenCode CLI focused on the "agentic run mode" for use in virtual machines, Docker containers, and other environments where unrestricted AI agent access is acceptable. This is **not** for general desktop use - it's for isolated environments where you want maximum AI agent freedom.
|
|
43
|
+
|
|
44
|
+
**OpenCode Compatibility**: We maintain 100% compatibility with OpenCode's JSON event streaming format, so tools expecting `opencode run --format json --model opencode/grok-code` output will work with our agent-cli.
|
|
45
|
+
|
|
46
|
+
## Design Choices
|
|
47
|
+
|
|
48
|
+
### Why Bun-only? No Node.js or Deno support?
|
|
49
|
+
|
|
50
|
+
This agent is **exclusively built for Bun** for the following reasons:
|
|
51
|
+
|
|
52
|
+
1. **Faster Development**: No compilation step - direct execution with `bun run`
|
|
53
|
+
2. **Simpler Dependencies**: Fewer dev dependencies, no TypeScript compiler overhead
|
|
54
|
+
3. **Performance**: Bun's fast runtime and native ESM support
|
|
55
|
+
4. **Minimalism**: Single runtime target keeps the codebase simple
|
|
56
|
+
5. **Bun Ecosystem**: Leverages Bun-specific features and optimizations
|
|
57
|
+
|
|
58
|
+
**Not supporting Node.js or Deno is intentional** to keep the project focused and minimal. If you need Node.js/Deno compatibility, consider using [OpenCode](https://github.com/sst/opencode) instead.
|
|
59
|
+
|
|
60
|
+
### Architecture: Reproducing OpenCode's JSON Event Streaming
|
|
61
|
+
|
|
62
|
+
This agent-cli reproduces the core architecture of [OpenCode](https://github.com/sst/opencode)'s `run --format json` command:
|
|
63
|
+
|
|
64
|
+
- **Streaming JSON Events**: Instead of single responses, outputs real-time event stream
|
|
65
|
+
- **Event Types**: `tool_use`, `text`, `step_start`, `step_finish`, `error`
|
|
66
|
+
- **Session Management**: Each request gets a unique session ID
|
|
67
|
+
- **Tool Execution**: 13 tools with unrestricted access (bash, read, write, edit, list, glob, grep, websearch, codesearch, batch, task, todo, webfetch)
|
|
68
|
+
- **Compatible Format**: Events match OpenCode's JSON schema for interoperability
|
|
69
|
+
|
|
70
|
+
The agent streams events as they occur, providing the same real-time experience as OpenCode's JSON mode.
|
|
71
|
+
|
|
72
|
+
## Features
|
|
73
|
+
|
|
74
|
+
- **JSON Input/Output**: Accepts JSON via stdin, outputs JSON event streams (OpenCode-compatible)
|
|
75
|
+
- **Plain Text Input**: Also accepts plain text messages (auto-converted to JSON format)
|
|
76
|
+
- **Unrestricted Access**: Full file system and command execution access (no sandbox, no restrictions)
|
|
77
|
+
- **Tool Support**: 13 tools including websearch, codesearch, batch - all enabled by default
|
|
78
|
+
- **Flexible Model Selection**: Defaults to free Grok Code Fast 1, supports all [OpenCode Zen models](https://opencode.ai/docs/zen/) - see [MODELS.md](MODELS.md)
|
|
79
|
+
- **Bun.sh First**: Built with Bun for maximum efficiency and minimal resource usage
|
|
80
|
+
- **No TUI**: Pure JSON CLI interface for automation and integration
|
|
81
|
+
- **Public Domain**: Unlicense - use it however you want
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
**Requirements:**
|
|
86
|
+
- [Bun](https://bun.sh) >= 1.0.0 (Node.js and Deno are NOT supported)
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Install Bun first if you haven't already
|
|
90
|
+
curl -fsSL https://bun.sh/install | bash
|
|
91
|
+
|
|
92
|
+
# Install the package globally
|
|
93
|
+
bun install -g @link-assistant/agent
|
|
94
|
+
|
|
95
|
+
# Or install locally in your project
|
|
96
|
+
bun add @link-assistant/agent
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
After installation, the `agent` command will be available globally.
|
|
100
|
+
|
|
101
|
+
## Usage
|
|
102
|
+
|
|
103
|
+
### Simplest Examples
|
|
104
|
+
|
|
105
|
+
**Plain text (easiest):**
|
|
106
|
+
```bash
|
|
107
|
+
echo "hi" | agent
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Simple JSON message:**
|
|
111
|
+
```bash
|
|
112
|
+
echo '{"message":"hi"}' | agent
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**With custom model:**
|
|
116
|
+
```bash
|
|
117
|
+
echo "hi" | agent --model opencode/grok-code
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### More Examples
|
|
121
|
+
|
|
122
|
+
**Plain Text Input:**
|
|
123
|
+
```bash
|
|
124
|
+
echo "hello world" | agent
|
|
125
|
+
echo "search the web for TypeScript news" | agent
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**JSON Input with tool calls:**
|
|
129
|
+
```bash
|
|
130
|
+
echo '{"message":"run command","tools":[{"name":"bash","params":{"command":"ls -la"}}]}' | agent
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Using different models:**
|
|
134
|
+
```bash
|
|
135
|
+
# Default model (free Grok Code Fast 1)
|
|
136
|
+
echo "hi" | agent
|
|
137
|
+
|
|
138
|
+
# Other free models
|
|
139
|
+
echo "hi" | agent --model opencode/big-pickle
|
|
140
|
+
echo "hi" | agent --model opencode/gpt-5-nano
|
|
141
|
+
|
|
142
|
+
# Premium models (OpenCode Zen subscription)
|
|
143
|
+
echo "hi" | agent --model opencode/sonnet # Claude Sonnet 4.5
|
|
144
|
+
echo "hi" | agent --model opencode/haiku # Claude Haiku 4.5
|
|
145
|
+
echo "hi" | agent --model opencode/opus # Claude Opus 4.1
|
|
146
|
+
echo "hi" | agent --model opencode/gemini-3-pro # Gemini 3 Pro
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
See [MODELS.md](MODELS.md) for complete list of available models and pricing.
|
|
150
|
+
|
|
151
|
+
### CLI Options
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
agent [options]
|
|
155
|
+
|
|
156
|
+
Options:
|
|
157
|
+
--model Model to use in format providerID/modelID
|
|
158
|
+
Default: opencode/grok-code
|
|
159
|
+
--system-message Full override of the system message
|
|
160
|
+
--system-message-file Full override of the system message from file
|
|
161
|
+
--append-system-message Append to the default system message
|
|
162
|
+
--append-system-message-file Append to the default system message from file
|
|
163
|
+
--help Show help
|
|
164
|
+
--version Show version number
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Input Formats
|
|
168
|
+
|
|
169
|
+
**Plain Text (auto-converted):**
|
|
170
|
+
```bash
|
|
171
|
+
echo "your message here" | agent
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**JSON Format:**
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"message": "Your message here",
|
|
178
|
+
"tools": [
|
|
179
|
+
{
|
|
180
|
+
"name": "bash",
|
|
181
|
+
"params": { "command": "ls -la" }
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Supported Tools
|
|
188
|
+
|
|
189
|
+
All 13 tools are **enabled by default** with **no configuration required**. See [TOOLS.md](TOOLS.md) for complete documentation.
|
|
190
|
+
|
|
191
|
+
### File Operations
|
|
192
|
+
- **`read`** - Read file contents
|
|
193
|
+
- **`write`** - Write files
|
|
194
|
+
- **`edit`** - Edit files with string replacement
|
|
195
|
+
- **`list`** - List directory contents
|
|
196
|
+
|
|
197
|
+
### Search Tools
|
|
198
|
+
- **`glob`** - File pattern matching (`**/*.js`)
|
|
199
|
+
- **`grep`** - Text search with regex support
|
|
200
|
+
- **`websearch`** ✨ - Web search via Exa API (no config needed!)
|
|
201
|
+
- **`codesearch`** ✨ - Code search via Exa API (no config needed!)
|
|
202
|
+
|
|
203
|
+
### Execution Tools
|
|
204
|
+
- **`bash`** - Execute shell commands
|
|
205
|
+
- **`batch`** ✨ - Batch multiple tool calls (no config needed!)
|
|
206
|
+
- **`task`** - Launch subagent tasks
|
|
207
|
+
|
|
208
|
+
### Utility Tools
|
|
209
|
+
- **`todo`** - Task tracking
|
|
210
|
+
- **`webfetch`** - Fetch and process URLs
|
|
211
|
+
|
|
212
|
+
✨ = Always enabled (no experimental flags or environment variables needed)
|
|
213
|
+
|
|
214
|
+
## Examples
|
|
215
|
+
|
|
216
|
+
See [EXAMPLES.md](EXAMPLES.md) for detailed usage examples of each tool with both agent-cli and opencode commands.
|
|
217
|
+
|
|
218
|
+
## Testing
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Run all tests
|
|
222
|
+
bun test
|
|
223
|
+
|
|
224
|
+
# Run specific test file
|
|
225
|
+
bun test tests/websearch.tools.test.js
|
|
226
|
+
bun test tests/batch.tools.test.js
|
|
227
|
+
bun test tests/plaintext.input.test.js
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Maintenance
|
|
231
|
+
|
|
232
|
+
### Development
|
|
233
|
+
|
|
234
|
+
Run the agent in development mode:
|
|
235
|
+
```bash
|
|
236
|
+
bun run dev
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Or run directly:
|
|
240
|
+
```bash
|
|
241
|
+
bun run src/index.js
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Testing
|
|
245
|
+
|
|
246
|
+
Simply run:
|
|
247
|
+
```bash
|
|
248
|
+
bun test
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Bun automatically discovers and runs all `*.test.js` files in the project.
|
|
252
|
+
|
|
253
|
+
### Test Coverage
|
|
254
|
+
|
|
255
|
+
- ✅ 13 tool implementation tests
|
|
256
|
+
- ✅ Plain text input support test
|
|
257
|
+
- ✅ OpenCode compatibility tests for websearch/codesearch
|
|
258
|
+
- ✅ All tests pass with 100% OpenCode JSON format compatibility
|
|
259
|
+
|
|
260
|
+
### Publishing
|
|
261
|
+
|
|
262
|
+
To publish a new version to npm:
|
|
263
|
+
|
|
264
|
+
1. **Update version** in `package.json`:
|
|
265
|
+
```bash
|
|
266
|
+
# Update version field manually (e.g., 0.0.3 -> 0.0.4)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
2. **Commit changes**:
|
|
270
|
+
```bash
|
|
271
|
+
git add .
|
|
272
|
+
git commit -m "Release v0.0.4"
|
|
273
|
+
git push
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
3. **Publish to npm**:
|
|
277
|
+
```bash
|
|
278
|
+
npm publish
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
The package publishes source files directly (no build step required). Bun handles TypeScript execution natively.
|
|
282
|
+
|
|
283
|
+
## Key Features
|
|
284
|
+
|
|
285
|
+
### No Configuration Required
|
|
286
|
+
- **WebSearch/CodeSearch**: Work without `OPENCODE_EXPERIMENTAL_EXA` environment variable
|
|
287
|
+
- **Batch Tool**: Always enabled, no experimental flag needed
|
|
288
|
+
- **All Tools**: No config files, API keys handled automatically
|
|
289
|
+
|
|
290
|
+
### OpenCode 100% Compatible
|
|
291
|
+
- All tools produce JSON output matching OpenCode's exact format
|
|
292
|
+
- WebSearch and CodeSearch tools are verified 100% compatible
|
|
293
|
+
- Tool event structure matches OpenCode specifications
|
|
294
|
+
- Can be used as drop-in replacement for `opencode run --format json`
|
|
295
|
+
|
|
296
|
+
### Plain Text Support
|
|
297
|
+
Both plain text and JSON input work:
|
|
298
|
+
```bash
|
|
299
|
+
# Plain text
|
|
300
|
+
echo "hello" | bun run src/index.js
|
|
301
|
+
|
|
302
|
+
# JSON
|
|
303
|
+
echo '{"message":"hello"}' | bun run src/index.js
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Plain text is automatically converted to `{"message":"your text"}` format.
|
|
307
|
+
|
|
308
|
+
### JSON Event Streaming Output
|
|
309
|
+
JSON output is pretty-printed for easy readability while maintaining OpenCode compatibility:
|
|
310
|
+
```bash
|
|
311
|
+
echo "hi" | agent
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Output (pretty-printed JSON events):
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"type": "step_start",
|
|
318
|
+
"timestamp": 1763618628840,
|
|
319
|
+
"sessionID": "ses_560236487ffe3ROK1ThWvPwTEF",
|
|
320
|
+
"part": {
|
|
321
|
+
"id": "prt_a9fdca4e8001APEs6AriJx67me",
|
|
322
|
+
"type": "step-start",
|
|
323
|
+
...
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
{
|
|
327
|
+
"type": "text",
|
|
328
|
+
"timestamp": 1763618629886,
|
|
329
|
+
"sessionID": "ses_560236487ffe3ROK1ThWvPwTEF",
|
|
330
|
+
"part": {
|
|
331
|
+
"id": "prt_a9fdca85c001bVEimWb9L3ya6T",
|
|
332
|
+
"type": "text",
|
|
333
|
+
"text": "Hi! How can I help with your coding tasks today?",
|
|
334
|
+
...
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
{
|
|
338
|
+
"type": "step_finish",
|
|
339
|
+
"timestamp": 1763618629916,
|
|
340
|
+
"sessionID": "ses_560236487ffe3ROK1ThWvPwTEF",
|
|
341
|
+
"part": {
|
|
342
|
+
"id": "prt_a9fdca8ff0015cBrNxckAXI3aE",
|
|
343
|
+
"type": "step-finish",
|
|
344
|
+
"reason": "stop",
|
|
345
|
+
...
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Architecture
|
|
351
|
+
|
|
352
|
+
This agent-cli reproduces OpenCode's `run --format json` command architecture:
|
|
353
|
+
|
|
354
|
+
- **Streaming JSON Events**: Real-time event stream output
|
|
355
|
+
- **Event Types**: `tool_use`, `text`, `step_start`, `step_finish`, `error`
|
|
356
|
+
- **Session Management**: Unique session IDs for each request
|
|
357
|
+
- **Tool Execution**: 13 tools with unrestricted access
|
|
358
|
+
- **Compatible Format**: Events match OpenCode's JSON schema exactly
|
|
359
|
+
|
|
360
|
+
## Files
|
|
361
|
+
|
|
362
|
+
- `src/index.js` - Main entry point with JSON/plain text input support
|
|
363
|
+
- `src/session/agent.js` - Agent implementation
|
|
364
|
+
- `src/tool/` - Tool implementations
|
|
365
|
+
- `tests/` - Comprehensive test suite
|
|
366
|
+
- [MODELS.md](MODELS.md) - Available models and pricing
|
|
367
|
+
- [TOOLS.md](TOOLS.md) - Complete tool documentation
|
|
368
|
+
- [EXAMPLES.md](EXAMPLES.md) - Usage examples for each tool
|
|
369
|
+
|
|
370
|
+
## Reference Implementations
|
|
371
|
+
|
|
372
|
+
This repository includes official reference implementations as git submodules to provide best-in-class examples:
|
|
373
|
+
|
|
374
|
+
- **original-opencode** - [OpenCode](https://github.com/sst/opencode) - The original OpenCode implementation we maintain compatibility with
|
|
375
|
+
- **reference-gemini-cookbook** - [Google Gemini Cookbook](https://github.com/google-gemini/cookbook) - Official examples and guides for using the Gemini API
|
|
376
|
+
- **reference-gemini-cli** - [Google Gemini CLI](https://github.com/google-gemini/gemini-cli) - Official AI agent bringing Gemini directly to the terminal
|
|
377
|
+
- **reference-qwen3-coder** - [Qwen3-Coder](https://github.com/QwenLM/Qwen3-Coder) - Official Qwen3 code model from Alibaba Cloud
|
|
378
|
+
|
|
379
|
+
To initialize all submodules:
|
|
380
|
+
```bash
|
|
381
|
+
git submodule update --init --recursive
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
These reference implementations provide valuable insights into different approaches for building AI agents and can serve as learning resources for developers working with this codebase.
|
|
385
|
+
|
|
386
|
+
## License
|
|
387
|
+
|
|
388
|
+
Unlicense (Public Domain)
|
package/TOOLS.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Supported Tools
|
|
2
|
+
|
|
3
|
+
This document lists all tools supported by `@link-assistant/agent`. All tools are enabled by default and produce OpenCode-compatible JSON output.
|
|
4
|
+
|
|
5
|
+
> ⚠️ **Bun-only** - This package requires [Bun](https://bun.sh) and does NOT support Node.js or Deno.
|
|
6
|
+
|
|
7
|
+
## File Operations
|
|
8
|
+
|
|
9
|
+
### read
|
|
10
|
+
Reads file contents from the filesystem.
|
|
11
|
+
|
|
12
|
+
**Status:** ✅ Fully supported and tested
|
|
13
|
+
**Test:** [tests/read.tools.test.js](tests/read.tools.test.js)
|
|
14
|
+
|
|
15
|
+
### write
|
|
16
|
+
Writes content to files in the filesystem.
|
|
17
|
+
|
|
18
|
+
**Status:** ✅ Fully supported and tested
|
|
19
|
+
**Test:** [tests/write.tools.test.js](tests/write.tools.test.js)
|
|
20
|
+
|
|
21
|
+
### edit
|
|
22
|
+
Performs exact string replacements in files.
|
|
23
|
+
|
|
24
|
+
**Status:** ✅ Fully supported and tested
|
|
25
|
+
**Test:** [tests/edit.tools.test.js](tests/edit.tools.test.js)
|
|
26
|
+
|
|
27
|
+
### list (ls)
|
|
28
|
+
Lists files and directories.
|
|
29
|
+
|
|
30
|
+
**Status:** ✅ Fully supported and tested
|
|
31
|
+
**Test:** [tests/list.tools.test.js](tests/list.tools.test.js)
|
|
32
|
+
|
|
33
|
+
## Search Tools
|
|
34
|
+
|
|
35
|
+
### glob
|
|
36
|
+
Fast file pattern matching tool that works with any codebase size. Supports glob patterns like `**/*.js` or `src/**/*.ts`.
|
|
37
|
+
|
|
38
|
+
**Status:** ✅ Fully supported and tested
|
|
39
|
+
**Test:** [tests/glob.tools.test.js](tests/glob.tools.test.js)
|
|
40
|
+
|
|
41
|
+
### grep
|
|
42
|
+
Powerful search tool built on ripgrep. Supports full regex syntax and can filter by file type or glob pattern.
|
|
43
|
+
|
|
44
|
+
**Status:** ✅ Fully supported and tested
|
|
45
|
+
**Test:** [tests/grep.tools.test.js](tests/grep.tools.test.js)
|
|
46
|
+
|
|
47
|
+
### websearch
|
|
48
|
+
Searches the web using Exa API for current information. Always enabled, no environment variables required.
|
|
49
|
+
|
|
50
|
+
**Status:** ✅ Fully supported and tested
|
|
51
|
+
**Test:** [tests/websearch.tools.test.js](tests/websearch.tools.test.js)
|
|
52
|
+
**OpenCode Compatibility:** ✅ 100% compatible
|
|
53
|
+
|
|
54
|
+
### codesearch
|
|
55
|
+
Searches code repositories and documentation using Exa API. Always enabled.
|
|
56
|
+
|
|
57
|
+
**Status:** ✅ Fully supported and tested
|
|
58
|
+
**Test:** [tests/codesearch.tools.test.js](tests/codesearch.tools.test.js)
|
|
59
|
+
**OpenCode Compatibility:** ✅ 100% compatible
|
|
60
|
+
|
|
61
|
+
## Execution Tools
|
|
62
|
+
|
|
63
|
+
### bash
|
|
64
|
+
Executes bash commands in a persistent shell session with optional timeout.
|
|
65
|
+
|
|
66
|
+
**Status:** ✅ Fully supported and tested
|
|
67
|
+
**Test:** [tests/bash.tools.test.js](tests/bash.tools.test.js)
|
|
68
|
+
|
|
69
|
+
### batch
|
|
70
|
+
Batches multiple tool calls together for optimal performance. Executes multiple tools in a single operation. Always enabled.
|
|
71
|
+
|
|
72
|
+
**Status:** ✅ Fully supported and tested
|
|
73
|
+
**Test:** [tests/batch.tools.test.js](tests/batch.tools.test.js)
|
|
74
|
+
|
|
75
|
+
### task
|
|
76
|
+
Launches specialized agents to handle complex, multi-step tasks autonomously.
|
|
77
|
+
|
|
78
|
+
**Status:** ✅ Fully supported and tested
|
|
79
|
+
**Test:** [tests/task.tools.test.js](tests/task.tools.test.js)
|
|
80
|
+
|
|
81
|
+
## Utility Tools
|
|
82
|
+
|
|
83
|
+
### todo (todowrite/todoread)
|
|
84
|
+
Reads and writes TODO items for task tracking during execution.
|
|
85
|
+
|
|
86
|
+
**Status:** ✅ Fully supported and tested
|
|
87
|
+
**Test:** [tests/todo.tools.test.js](tests/todo.tools.test.js)
|
|
88
|
+
|
|
89
|
+
### webfetch
|
|
90
|
+
Fetches content from a specified URL and processes it using an AI model.
|
|
91
|
+
|
|
92
|
+
**Status:** ✅ Fully supported and tested
|
|
93
|
+
**Test:** [tests/webfetch.tools.test.js](tests/webfetch.tools.test.js)
|
|
94
|
+
|
|
95
|
+
## Testing
|
|
96
|
+
|
|
97
|
+
### Run All Tool Tests
|
|
98
|
+
```bash
|
|
99
|
+
bun test tests/*.tools.test.js
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Run Specific Tool Test
|
|
103
|
+
```bash
|
|
104
|
+
bun test tests/bash.tools.test.js
|
|
105
|
+
bun test tests/websearch.tools.test.js
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Test Coverage
|
|
109
|
+
Each tool test verifies:
|
|
110
|
+
- ✅ Correct JSON output structure
|
|
111
|
+
- ✅ OpenCode compatibility (where applicable)
|
|
112
|
+
- ✅ Proper input/output handling
|
|
113
|
+
- ✅ Error handling
|
|
114
|
+
|
|
115
|
+
## Key Features
|
|
116
|
+
|
|
117
|
+
### No Configuration Required
|
|
118
|
+
- All tools work without environment variables or configuration files
|
|
119
|
+
- WebSearch and CodeSearch work without `OPENCODE_EXPERIMENTAL_EXA`
|
|
120
|
+
- Batch tool is always enabled, no experimental flag needed
|
|
121
|
+
|
|
122
|
+
### OpenCode Compatible
|
|
123
|
+
- All tools produce JSON output compatible with OpenCode's format
|
|
124
|
+
- WebSearch and CodeSearch tools are 100% compatible with OpenCode output
|
|
125
|
+
- Tool event structure matches OpenCode specifications
|
|
126
|
+
|
|
127
|
+
### Plain Text Input Support
|
|
128
|
+
`@link-assistant/agent` also accepts plain text input (not just JSON):
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
echo "hello world" | agent
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Plain text is automatically converted to a message request.
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@link-assistant/agent",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "A minimal, public domain AI CLI agent compatible with OpenCode's JSON interface. Bun-only runtime.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agent": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "bun run src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"bun": ">=1.0.0"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/link-assistant/agent"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"ai",
|
|
22
|
+
"cli",
|
|
23
|
+
"agent",
|
|
24
|
+
"opencode",
|
|
25
|
+
"bun",
|
|
26
|
+
"assistant",
|
|
27
|
+
"json-interface"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"src/",
|
|
34
|
+
"README.md",
|
|
35
|
+
"MODELS.md",
|
|
36
|
+
"TOOLS.md",
|
|
37
|
+
"EXAMPLES.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@actions/core": "^1.11.1",
|
|
42
|
+
"@actions/github": "^6.0.1",
|
|
43
|
+
"@agentclientprotocol/sdk": "^0.5.1",
|
|
44
|
+
"@ai-sdk/mcp": "^0.0.8",
|
|
45
|
+
"@ai-sdk/xai": "^2.0.33",
|
|
46
|
+
"@hono/standard-validator": "^0.2.0",
|
|
47
|
+
"@hono/zod-validator": "^0.7.5",
|
|
48
|
+
"@modelcontextprotocol/sdk": "^1.22.0",
|
|
49
|
+
"@octokit/graphql": "^9.0.3",
|
|
50
|
+
"@octokit/rest": "^22.0.1",
|
|
51
|
+
"@openauthjs/openauth": "^0.4.3",
|
|
52
|
+
"@opencode-ai/sdk": "^1.0.78",
|
|
53
|
+
"@opentui/core": "^0.1.46",
|
|
54
|
+
"@opentui/solid": "^0.1.46",
|
|
55
|
+
"@parcel/watcher": "^2.5.1",
|
|
56
|
+
"@solid-primitives/event-bus": "^1.1.2",
|
|
57
|
+
"@zip.js/zip.js": "^2.8.10",
|
|
58
|
+
"ai": "6.0.0-beta.99",
|
|
59
|
+
"chokidar": "^4.0.3",
|
|
60
|
+
"clipboardy": "^5.0.0",
|
|
61
|
+
"command-stream": "^0.7.1",
|
|
62
|
+
"decimal.js": "^10.6.0",
|
|
63
|
+
"diff": "^8.0.2",
|
|
64
|
+
"fuzzysort": "^3.1.0",
|
|
65
|
+
"glob": "^10.0.0",
|
|
66
|
+
"gray-matter": "^4.0.3",
|
|
67
|
+
"hono": "^4.10.6",
|
|
68
|
+
"hono-openapi": "^1.1.1",
|
|
69
|
+
"ignore": "^7.0.5",
|
|
70
|
+
"jsonc-parser": "^3.3.1",
|
|
71
|
+
"minimatch": "^10.1.1",
|
|
72
|
+
"open": "^11.0.0",
|
|
73
|
+
"partial-json": "^0.1.7",
|
|
74
|
+
"remeda": "^2.32.0",
|
|
75
|
+
"solid-js": "^1.9.10",
|
|
76
|
+
"strip-ansi": "^7.1.2",
|
|
77
|
+
"test-anywhere": "^0.7.0",
|
|
78
|
+
"tree-sitter-bash": "^0.25.0",
|
|
79
|
+
"turndown": "^7.2.2",
|
|
80
|
+
"ulid": "^3.0.1",
|
|
81
|
+
"vscode-jsonrpc": "^8.2.1",
|
|
82
|
+
"vscode-languageserver-types": "^3.17.5",
|
|
83
|
+
"web-tree-sitter": "^0.25.10",
|
|
84
|
+
"xdg-basedir": "^5.1.0",
|
|
85
|
+
"yargs": "^18.0.0",
|
|
86
|
+
"zod": "^4.1.12"
|
|
87
|
+
},
|
|
88
|
+
"license": "Unlicense"
|
|
89
|
+
}
|