goatchain-cli 0.0.2-beta.10

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/README.md ADDED
@@ -0,0 +1,368 @@
1
+ # GoatChain CLI 🐐
2
+
3
+ > Interactive AI agent CLI for software engineering tasks with built-in file operations, web search, and planning capabilities
4
+
5
+ [![npm version](https://badge.fury.io/js/goatchain-cli.svg)](https://badge.fury.io/js/goatchain-cli)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## ✨ Features
9
+
10
+ - **🤖 Interactive AI Agent** - Real-time conversation with AI assistant for coding tasks
11
+ - **📁 File Operations** - Read, write, edit files with built-in safety checks
12
+ - **🔍 Code Navigation** - Glob search, grep, and AST-aware code analysis
13
+ - **🌐 Web Search** - Integrated web search for up-to-date information
14
+ - **📋 Plan Mode** - Structured planning workflow (plan → confirm → execute)
15
+ - **💾 Session Management** - Save and restore conversation sessions
16
+ - **🔧 Tool Integration** - Built-in tools for common development tasks
17
+ - **🖼️ Image Support** - Attach and analyze images in conversations
18
+ - **⚙️ Configurable** - Flexible configuration via environment and config files
19
+
20
+ ## 🚀 Quick Start
21
+
22
+ ### Installation
23
+
24
+ ```bash
25
+ # Install globally via npm
26
+ npm install -g goatchain-cli
27
+
28
+ # Or use npx (recommended for first-time use)
29
+ npx goatchain-cli
30
+
31
+ # Or install locally in your project
32
+ npm install --save-dev goatchain-cli
33
+ ```
34
+
35
+ ### Basic Usage
36
+
37
+ ```bash
38
+ # Set your OpenAI API key
39
+ export OPENAI_API_KEY=your-api-key-here
40
+
41
+ # Start the CLI
42
+ goatchain
43
+
44
+ # Or with npx
45
+ npx goatchain-cli
46
+ ```
47
+
48
+ ### First Conversation
49
+
50
+ ```bash
51
+ $ goatchain
52
+ 🤖 GoatChain CLI v0.0.2-beta.6
53
+
54
+ Welcome! I'm your AI assistant. Type /help for commands or ask me anything.
55
+
56
+ > Can you help me understand this TypeScript project?
57
+ ```
58
+
59
+ ## 📦 Installation Methods
60
+
61
+ ### Method 1: Global Installation (Recommended)
62
+
63
+ ```bash
64
+ npm install -g goatchain-cli
65
+ ```
66
+
67
+ ### Method 2: Project-based Installation
68
+
69
+ ```bash
70
+ # Add to your project
71
+ npm install --save-dev goatchain-cli
72
+
73
+ # Run from project directory
74
+ npx goatchain
75
+ ```
76
+
77
+ ### Method 3: Direct from GitHub
78
+
79
+ ```bash
80
+ # Run directly from GitHub repository
81
+ npx github:zjywill/GoatChain#main:packages/cli
82
+ ```
83
+
84
+ ## ⚙️ Configuration
85
+
86
+ ### Environment Variables
87
+
88
+ ```bash
89
+ # Required: OpenAI API key
90
+ export OPENAI_API_KEY=sk-...
91
+
92
+ # Optional: Web search (Serper API)
93
+ export SERPER_API_KEY=your-serper-key
94
+
95
+ # Optional: Default model
96
+ export GOATCHAIN_MODEL=gpt-4o
97
+
98
+ # Optional: OpenAI-compatible base URL (e.g. DeepSeek / GLM)
99
+ export GOATCHAIN_OPENAI_BASE_URL=...
100
+
101
+ # Optional: Enable plan mode by default
102
+ export GOATCHAIN_PLAN_MODE=1
103
+ ```
104
+
105
+ ### Local Configuration File
106
+
107
+ Create `.goatchain/config.json` in your project:
108
+
109
+ ```json
110
+ {
111
+ "model": {
112
+ "provider": "openai",
113
+ "modelId": "gpt-4o"
114
+ },
115
+ "tools": {
116
+ "webSearch": {
117
+ "apiKey": "your-serper-key",
118
+ "numResults": 10
119
+ }
120
+ },
121
+ "planMode": "on"
122
+ }
123
+ ```
124
+
125
+ ## 🎯 Commands Reference
126
+
127
+ ### Core Commands
128
+
129
+ | Command | Description |
130
+ |---------|-------------|
131
+ | `/help` | Show help information |
132
+ | `/model <id>` | Switch model (e.g., `gpt-4o`, `gpt-3.5-turbo`) |
133
+ | `/plan [on|off|toggle]` | Toggle plan mode |
134
+ | `/approvals` | Select approval mode |
135
+ | `/set <key> <value>` | Set request parameters |
136
+ | `/unset <key>` | Clear a parameter |
137
+ | `/params` | Show current parameters |
138
+
139
+ ### Session Management
140
+
141
+ | Command | Description |
142
+ |---------|-------------|
143
+ | `/sessions` | List saved sessions |
144
+ | `/use <sessionId>` | Restore a session |
145
+ | `/save` | Save current session |
146
+ | `/new` | Start new conversation |
147
+ | `/status` | Show current status |
148
+
149
+ ### Tool Configuration
150
+
151
+ | Command | Description |
152
+ |---------|-------------|
153
+ | `/tools` | List enabled tools |
154
+ | `/base-url <url>` | Set API base URL |
155
+ | `/api-key <key>` | Set API key |
156
+ | `/web-search-key <key>` | Set web search API key |
157
+
158
+ ### OpenAI-Compatible Providers (DeepSeek / GLM)
159
+
160
+ GoatChain CLI uses an OpenAI-compatible client. To use other providers, set `/base-url` (or `GOATCHAIN_OPENAI_BASE_URL`) and provide the matching API key via `/api-key` (or `OPENAI_API_KEY`).
161
+
162
+ Examples of model ids you can select via `/model`:
163
+ - DeepSeek: `deepseek-chat`, `deepseek-reasoner`, `deepseek-v3.1`
164
+ - GLM: `glm-4-plus`, `glm-4-air`, `glm-4-flash`, `glm-4v-plus`
165
+
166
+ ## 🔧 Built-in Tools
167
+
168
+ ### File Operations
169
+
170
+ - **Read** - Read files and directories
171
+ - **Write** - Create new files
172
+ - **Edit** - Modify existing files
173
+ - **Glob** - Pattern-based file search
174
+ - **Grep** - Content search across files
175
+
176
+ ### Development Tools
177
+
178
+ - **WebSearch** - Internet search for current information
179
+ - **AskUserQuestion** - Interactive user prompts for decisions
180
+ - **TodoWrite** - Structured task planning
181
+ - **Bash** - Execute shell commands
182
+
183
+ ### Code Analysis
184
+
185
+ - **ast_grep_search** - AST-aware code pattern matching
186
+ - **ast_grep_replace** - AST-aware code refactoring
187
+
188
+ ## 📋 Plan Mode
189
+
190
+ Plan mode enables a structured workflow for complex tasks:
191
+
192
+ ```bash
193
+ # Enable plan mode
194
+ /plan on
195
+
196
+ # Workflow:
197
+ # 1. Agent explores codebase and researches request
198
+ # 2. May ask clarifying questions
199
+ # 3. Creates structured plan (3-8 steps)
200
+ # 4. You review and approve plan
201
+ # 5. Agent executes approved plan
202
+
203
+ # File modifications are blocked during planning phase
204
+ ```
205
+
206
+ ## 💾 Session Management
207
+
208
+ Sessions preserve conversation history and context:
209
+
210
+ ```bash
211
+ # List available sessions
212
+ /sessions
213
+
214
+ # Restore a specific session
215
+ /use session-id-here
216
+
217
+ # Save current session
218
+ /save
219
+
220
+ # Start fresh
221
+ /new
222
+ ```
223
+
224
+ Sessions are stored in `.goatchain/sessions/` (gitignored).
225
+
226
+ ## 🔍 Web Search Integration
227
+
228
+ Enable web search for current information:
229
+
230
+ ```bash
231
+ # Set web search API key
232
+ /web-search-key your-serper-api-key
233
+
234
+ # Or set environment variable
235
+ export SERPER_API_KEY=your-key
236
+
237
+ # Web search will be available for weather, news, and current events
238
+ ```
239
+
240
+ ## 🖼️ Image Support
241
+
242
+ Attach images to conversations for analysis:
243
+
244
+ ```bash
245
+ # The agent can analyze images you attach
246
+ # Supported formats: PNG, JPG, JPEG
247
+ ```
248
+
249
+ ## 🚀 Advanced Usage
250
+
251
+ ### Command Line Arguments
252
+
253
+ ```bash
254
+ # Set API key via command line
255
+ goatchain --api-key sk-...
256
+
257
+ # Specify model
258
+ goatchain --model gpt-4o
259
+
260
+ # Set custom base URL
261
+ goatchain --base-url https://api.openai.com/v1
262
+
263
+ # Configure request parameters
264
+ goatchain --max-tokens 2000 --temperature 0.7
265
+ ```
266
+
267
+ ### Integration with Projects
268
+
269
+ ```bash
270
+ # Run in specific directory
271
+ cd /path/to/your/project
272
+ goatchain
273
+
274
+ # The agent will automatically detect and analyze your codebase
275
+ ```
276
+
277
+ ### Environment-Specific Configuration
278
+
279
+ ```bash
280
+ # Development environment
281
+ export GOATCHAIN_PLAN_MODE=1
282
+ export GOATCHAIN_MODEL=gpt-4o
283
+
284
+ # Production-like environment (more conservative)
285
+ export GOATCHAIN_PLAN_MODE=0
286
+ export GOATCHAIN_MODEL=gpt-3.5-turbo
287
+ ```
288
+
289
+ ## 🛠️ Development
290
+
291
+ ### Building from Source
292
+
293
+ ```bash
294
+ # Clone the repository
295
+ git clone https://github.com/zjywill/GoatChain.git
296
+ cd GoatChain/packages/cli
297
+
298
+ # Install dependencies
299
+ npm install
300
+
301
+ # Build the project
302
+ npm run build
303
+
304
+ # Test the CLI
305
+ npm run smoke
306
+ ```
307
+
308
+ ### Project Structure
309
+
310
+ ```
311
+ packages/cli/
312
+ ├── src/
313
+ │ ├── index.ts # Main CLI entry point
314
+ │ ├── args.ts # Command line argument parsing
315
+ │ ├── sdk.ts # GoatChain SDK integration
316
+ │ ├── repl.ts # Interactive REPL implementation
317
+ │ ├── turn.ts # Turn processing logic
318
+ │ └── tools/ # Built-in tool implementations
319
+ ├── dist/ # Built output
320
+ └── package.json
321
+ ```
322
+
323
+ ## 🐛 Troubleshooting
324
+
325
+ ### Common Issues
326
+
327
+ **"API key not found"**
328
+ ```bash
329
+ # Set OpenAI API key
330
+ export OPENAI_API_KEY=your-key
331
+ ```
332
+
333
+ **"Model not available"**
334
+ ```bash
335
+ # Switch to available model
336
+ /model gpt-3.5-turbo
337
+ ```
338
+
339
+ **Web search not working**
340
+ ```bash
341
+ # Set Serper API key
342
+ /web-search-key your-key
343
+ ```
344
+
345
+ **File operations failing**
346
+ - Check file permissions
347
+ - Ensure files exist and are accessible
348
+ - Verify path correctness
349
+
350
+ ### Debug Mode
351
+
352
+ Enable verbose logging:
353
+ ```bash
354
+ export DEBUG=goatchain:*
355
+ goatchain
356
+ ```
357
+
358
+ ## 🤝 Contributing
359
+
360
+ Contributions are welcome! Please see the main [GoatChain repository](https://github.com/zjywill/GoatChain) for contribution guidelines.
361
+
362
+ ## 📄 License
363
+
364
+ MIT © [Simon He](https://github.com/Simon-He95)
365
+
366
+ ---
367
+
368
+ **Need help?** Type `/help` in the CLI or open an issue on GitHub.
@@ -0,0 +1,2 @@
1
+ import{Command as e,InvalidArgumentError as t}from"commander";function n(e){let t=String(e??``).trim().toLowerCase().replace(/[-\s]+/g,`_`);return t===`read`||t===`readonly`||t===`read_only`?`read_only`:t===`agent`||t===`default`?`agent`:t===`full`||t===`full_access`||t===`agent_full`||t===`agent_full_access`?`full_access`:`read_only`}function r(e){return e===`read_only`?`Read Only`:e===`agent`?`Agent (current)`:`Agent (full access)`}function i(e){return{strategy:`high_risk`,autoApprove:e.envAutoApprove===`1`||e.envAutoApprove===!0||e.mode!==`read_only`}}function a(e){return{allowOutsideWorkspace:e===`full_access`,allowNetwork:e===`full_access`||e===`read_only`}}function o(){return[``,`Interactive slash commands:`,` /help Show help`,` /clear Clear pending attachments`,` /approvals Select approval mode (interactive)`,` /model [id] Show/set model id`,` /workspace Switch workspace root (interactive)`,` /files Attach file(s) (interactive)`,` /images Attach image(s) (interactive)`,` /settings Base URL / API key / tokens`,` /config [--json] Print full config (secrets redacted)`,` /output Output & UX options`,` /agent Switch to agent mode (normal operation)`,` /plan Switch to plan mode (read-only planning with TodoWrite)`,` /diag Show last turn stop reason + tool calls`,` /diagnostics Alias for /diag`,` /edit Compose a message in $EDITOR`,` /multiline Start multiline input (.send/.cancel)`,` /set <k> <v> Set request param (maxTokens/temperature/topP/...)`,` /unset <k> Clear request param`,` /params Show current request params`,` /base-url <url> Set base URL (recreates client if needed)`,` /api-key <key> Set API key for this process (not printed)`,` /web-search-key <key> Set Serper API key for WebSearch tool (not printed)`,` /tools List enabled tools`,` /mcp [subcmd] MCP servers (connect/disconnect/tools)`,` /sessions List/pick/delete sessions`,` /use <sessionId> Switch session (restore history)`,` /rm <sessionId...> Delete session(s)`,` /save Save current session/config`,` /status Show current session/model info`,` /new Start a new conversation (clears history)`,` /compact Manually compress context (generate summary)`,` /exit Exit`,``,`Mentions:`,` @<query> Search workspace files/dirs (Enter inserts @path)`,``,`Keybindings:`,` (Type @ or / to show suggestions; filters as you type)`,` Tab Fill the selected suggestion`,` ↑/↓ Select a suggestion`,` Enter Run /command, or insert @workspace path selection`,` PgUp/PgDn/Home/End Scroll fullscreen log`,` Ctrl+K Open command palette`,` Ctrl+O Manage attachments`,` Ctrl+G Clear attachments`,``,`UI:`,` GOATCHAIN_UI=inline Disable fullscreen UI`,` GOATCHAIN_UI=legacy Disable interactive UI`,` GOATCHAIN_UI=full Force fullscreen UI`,` GOATCHAIN_THEME=dark Dark terminal theme (default)`,` GOATCHAIN_THEME=light Light terminal theme`,` GOATCHAIN_ANIMATE=0 Disable splash animation`,``,`Approvals:`,` GOATCHAIN_APPROVAL_MODE=read_only|agent|full_access`,` (You can also change this in-app via /approvals)`,``,`Image attachments:`,` (Also configurable via .goatchain/config.json -> ui.attachImages.*)`,` GOATCHAIN_ATTACH_IMAGES_NOTE_TEMPLATE=<text> Template supports {{items}}/{{count}}/{{json}}`,` GOATCHAIN_ATTACH_IMAGES_NOTE_POSITION=start|before_images|after_images|before_text|after_text|end`,` GOATCHAIN_ATTACH_IMAGES_IMAGES_POSITION=start|before_text|after_text|end`,` GOATCHAIN_ATTACH_IMAGES_DATA_URL_MODE=none|prefix|full`,` GOATCHAIN_ATTACH_IMAGES_MAX_DATA_URL_CHARS=8000`,``].join(`
2
+ `)}function s(e){return n=>{let r=Number(n);if(!Number.isFinite(r))throw new t(`Invalid ${e}: ${n}`);return r}}function c(e){return n=>{let r=Number.parseInt(n,10);if(!Number.isFinite(r))throw new t(`Invalid ${e}: ${n}`);return r}}function l(t){return new e().name(`goatchain`).description(`A tiny interactive chat CLI built on agent-loop`).argument(`[prompt...]`,`one-shot prompt (omit to start interactive mode)`).option(`-k, --api-key <key>`,`OpenAI API key (or set OPENAI_API_KEY)`).option(`-m, --model <id>`,`Default model id (OpenAI)`).option(`--system <prompt>`,`System prompt`).option(`--base-url <url>`,`Override OpenAI base URL (proxy)`).option(`--serper-api-key <key>`,`Serper API key (enables WebSearch tool)`).option(`--web-search-api-key <key>`,`Alias for --serper-api-key`).option(`--serper-api-endpoint <url>`,`Serper API endpoint (WebSearch tool)`).option(`--web-search-api-endpoint <url>`,`Alias for --serper-api-endpoint`).option(`--serper-num-results <n>`,`Serper number of results (WebSearch tool)`,c(`serper-num-results`)).option(`--web-search-num-results <n>`,`Alias for --serper-num-results`,c(`web-search-num-results`)).option(`--max-tokens <n>`,`Max completion tokens`,c(`max-tokens`)).option(`--temperature <n>`,`Temperature (0-2)`,s(`temperature`)).option(`--top-p <n>`,`Top-p (0-1)`,s(`top-p`)).option(`--presence-penalty <n>`,`Presence penalty (-2..2)`,s(`presence-penalty`)).option(`--frequency-penalty <n>`,`Frequency penalty (-2..2)`,s(`frequency-penalty`)).option(`--seed <n>`,`Random seed`,c(`seed`)).option(`--timeout-ms <n>`,`Request timeout in ms`,c(`timeout-ms`)).option(`--session <id>`,`Use a saved session id (optional)`).version(t,`-v, --version`,`Show version`).helpOption(`-h, --help`,`Show help`).showHelpAfterError().showSuggestionAfterError().addHelpText(`after`,o())}function u(e,t){let n=l(t);n.parse(e,{from:`user`});let r=n.opts(),i=Array.isArray(n.args)?n.args.join(` `).trim():``,a=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,o=e=>typeof e==`number`&&Number.isFinite(e)?Math.trunc(e):void 0;return{apiKey:typeof r.apiKey==`string`&&r.apiKey.trim()?r.apiKey:void 0,modelId:typeof r.model==`string`&&r.model.trim()?r.model:void 0,system:typeof r.system==`string`&&r.system.trim()?r.system:void 0,baseUrl:typeof r.baseUrl==`string`&&r.baseUrl.trim()?r.baseUrl:void 0,webSearchApiKey:typeof r.webSearchApiKey==`string`&&r.webSearchApiKey.trim()?r.webSearchApiKey:typeof r.serperApiKey==`string`&&r.serperApiKey.trim()?r.serperApiKey:void 0,webSearchApiEndpoint:typeof r.webSearchApiEndpoint==`string`&&r.webSearchApiEndpoint.trim()?r.webSearchApiEndpoint:typeof r.serperApiEndpoint==`string`&&r.serperApiEndpoint.trim()?r.serperApiEndpoint:void 0,webSearchNumResults:typeof r.webSearchNumResults==`number`&&Number.isFinite(r.webSearchNumResults)?Math.trunc(r.webSearchNumResults):o(r.serperNumResults),maxTokens:o(r.maxTokens),temperature:a(r.temperature),topP:a(r.topP),presencePenalty:a(r.presencePenalty),frequencyPenalty:a(r.frequencyPenalty),seed:o(r.seed),timeoutMs:o(r.timeoutMs),sessionId:typeof r.session==`string`&&r.session.trim()?r.session:void 0,prompt:i}}export{a,r as i,o as n,i as o,u as r,n as s,l as t};
@@ -0,0 +1 @@
1
+ import{createRequire as e}from"node:module";var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),c=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},l=(e,r,i)=>(i=e==null?{}:t(a(e)),c(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)),u=e(import.meta.url);export{u as n,l as r,s as t};
package/dist/cli.mjs ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { main } from './index.js'
3
+
4
+ await main(process.argv.slice(2))