@element47/ag 4.4.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.
- package/README.md +316 -0
- package/dist/cli/parser.d.ts +6 -0
- package/dist/cli/parser.d.ts.map +1 -0
- package/dist/cli/parser.js +62 -0
- package/dist/cli/parser.js.map +1 -0
- package/dist/cli/repl.d.ts +16 -0
- package/dist/cli/repl.d.ts.map +1 -0
- package/dist/cli/repl.js +599 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +84 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/__tests__/agent.test.d.ts +2 -0
- package/dist/core/__tests__/agent.test.d.ts.map +1 -0
- package/dist/core/__tests__/agent.test.js +53 -0
- package/dist/core/__tests__/agent.test.js.map +1 -0
- package/dist/core/__tests__/config.test.d.ts +2 -0
- package/dist/core/__tests__/config.test.d.ts.map +1 -0
- package/dist/core/__tests__/config.test.js +58 -0
- package/dist/core/__tests__/config.test.js.map +1 -0
- package/dist/core/__tests__/constants.test.d.ts +2 -0
- package/dist/core/__tests__/constants.test.d.ts.map +1 -0
- package/dist/core/__tests__/constants.test.js +40 -0
- package/dist/core/__tests__/constants.test.js.map +1 -0
- package/dist/core/__tests__/context.test.d.ts +2 -0
- package/dist/core/__tests__/context.test.d.ts.map +1 -0
- package/dist/core/__tests__/context.test.js +120 -0
- package/dist/core/__tests__/context.test.js.map +1 -0
- package/dist/core/__tests__/environment.test.d.ts +2 -0
- package/dist/core/__tests__/environment.test.d.ts.map +1 -0
- package/dist/core/__tests__/environment.test.js +94 -0
- package/dist/core/__tests__/environment.test.js.map +1 -0
- package/dist/core/__tests__/permissions.test.d.ts +2 -0
- package/dist/core/__tests__/permissions.test.d.ts.map +1 -0
- package/dist/core/__tests__/permissions.test.js +66 -0
- package/dist/core/__tests__/permissions.test.js.map +1 -0
- package/dist/core/__tests__/registry.test.d.ts +2 -0
- package/dist/core/__tests__/registry.test.d.ts.map +1 -0
- package/dist/core/__tests__/registry.test.js +152 -0
- package/dist/core/__tests__/registry.test.js.map +1 -0
- package/dist/core/__tests__/streaming.test.d.ts +2 -0
- package/dist/core/__tests__/streaming.test.d.ts.map +1 -0
- package/dist/core/__tests__/streaming.test.js +54 -0
- package/dist/core/__tests__/streaming.test.js.map +1 -0
- package/dist/core/agent.d.ts +87 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +711 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/colors.d.ts +12 -0
- package/dist/core/colors.d.ts.map +1 -0
- package/dist/core/colors.js +37 -0
- package/dist/core/colors.js.map +1 -0
- package/dist/core/config.d.ts +13 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +30 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +26 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/context.d.ts +18 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +99 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/loader.d.ts +3 -0
- package/dist/core/loader.d.ts.map +1 -0
- package/dist/core/loader.js +39 -0
- package/dist/core/loader.js.map +1 -0
- package/dist/core/registry.d.ts +11 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +112 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/skills.d.ts +14 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +100 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/types.d.ts +64 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +7 -0
- package/dist/core/version.js.map +1 -0
- package/dist/memory/__tests__/memory.test.d.ts +2 -0
- package/dist/memory/__tests__/memory.test.d.ts.map +1 -0
- package/dist/memory/__tests__/memory.test.js +196 -0
- package/dist/memory/__tests__/memory.test.js.map +1 -0
- package/dist/memory/memory.d.ts +41 -0
- package/dist/memory/memory.d.ts.map +1 -0
- package/dist/memory/memory.js +206 -0
- package/dist/memory/memory.js.map +1 -0
- package/dist/tools/__tests__/bash.test.d.ts +2 -0
- package/dist/tools/__tests__/bash.test.d.ts.map +1 -0
- package/dist/tools/__tests__/bash.test.js +58 -0
- package/dist/tools/__tests__/bash.test.js.map +1 -0
- package/dist/tools/__tests__/file.test.d.ts +2 -0
- package/dist/tools/__tests__/file.test.d.ts.map +1 -0
- package/dist/tools/__tests__/file.test.js +115 -0
- package/dist/tools/__tests__/file.test.js.map +1 -0
- package/dist/tools/__tests__/git.test.d.ts +2 -0
- package/dist/tools/__tests__/git.test.d.ts.map +1 -0
- package/dist/tools/__tests__/git.test.js +19 -0
- package/dist/tools/__tests__/git.test.js.map +1 -0
- package/dist/tools/__tests__/grep.test.d.ts +2 -0
- package/dist/tools/__tests__/grep.test.d.ts.map +1 -0
- package/dist/tools/__tests__/grep.test.js +36 -0
- package/dist/tools/__tests__/grep.test.js.map +1 -0
- package/dist/tools/__tests__/memory-tool.test.d.ts +2 -0
- package/dist/tools/__tests__/memory-tool.test.d.ts.map +1 -0
- package/dist/tools/__tests__/memory-tool.test.js +39 -0
- package/dist/tools/__tests__/memory-tool.test.js.map +1 -0
- package/dist/tools/__tests__/plan.test.d.ts +2 -0
- package/dist/tools/__tests__/plan.test.d.ts.map +1 -0
- package/dist/tools/__tests__/plan.test.js +81 -0
- package/dist/tools/__tests__/plan.test.js.map +1 -0
- package/dist/tools/__tests__/schemas.test.d.ts +2 -0
- package/dist/tools/__tests__/schemas.test.d.ts.map +1 -0
- package/dist/tools/__tests__/schemas.test.js +40 -0
- package/dist/tools/__tests__/schemas.test.js.map +1 -0
- package/dist/tools/__tests__/web.test.d.ts +2 -0
- package/dist/tools/__tests__/web.test.d.ts.map +1 -0
- package/dist/tools/__tests__/web.test.js +51 -0
- package/dist/tools/__tests__/web.test.js.map +1 -0
- package/dist/tools/bash.d.ts +6 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +89 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/file.d.ts +7 -0
- package/dist/tools/file.d.ts.map +1 -0
- package/dist/tools/file.js +224 -0
- package/dist/tools/file.js.map +1 -0
- package/dist/tools/git.d.ts +3 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +220 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/grep.d.ts +8 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +265 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/memory.d.ts +3 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +33 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/tools/plan.d.ts +3 -0
- package/dist/tools/plan.d.ts.map +1 -0
- package/dist/tools/plan.js +60 -0
- package/dist/tools/plan.js.map +1 -0
- package/dist/tools/skill.d.ts +6 -0
- package/dist/tools/skill.d.ts.map +1 -0
- package/dist/tools/skill.js +20 -0
- package/dist/tools/skill.js.map +1 -0
- package/dist/tools/web.d.ts +3 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +187 -0
- package/dist/tools/web.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# ag
|
|
2
|
+
|
|
3
|
+
A persistent AI coding agent with memory. Any model via OpenRouter.
|
|
4
|
+
|
|
5
|
+
Built as a tool-calling loop with bash — inspired by [How does Claude Code actually work?](https://youtu.be/I82j7AzMU80). Features streaming responses, parallel tool execution, permission prompts, and persistent memory.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @iambarryking/ag # run directly (prompts for API key on first use)
|
|
11
|
+
npm install -g @iambarryking/ag # or install globally
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or from source:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone <repo>
|
|
18
|
+
cd simple-agent
|
|
19
|
+
npm install && npm run build && npm link
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
ag # interactive REPL (prompts before writes/commands)
|
|
26
|
+
ag -y # auto-approve all tool calls
|
|
27
|
+
ag "what files are here?" # one-shot mode (auto-approves)
|
|
28
|
+
ag -m openai/gpt-4o "help me" # specific model
|
|
29
|
+
ag -m openrouter/auto "help" # let OpenRouter pick
|
|
30
|
+
ag --stats # show memory status
|
|
31
|
+
ag --help # all options
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
On first run, `ag` prompts for your OpenRouter API key and saves it to `~/.ag/config.json`. You can also set it via environment variable:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export OPENROUTER_API_KEY=sk-or-v1-...
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## CLI Options
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
-m, --model <model> Model ID (default: anthropic/claude-sonnet-4.6)
|
|
44
|
+
-k, --key <key> API key (or set OPENROUTER_API_KEY)
|
|
45
|
+
-s, --system <prompt> Custom system prompt
|
|
46
|
+
-b, --base-url <url> API base URL (default: OpenRouter; use for local LLMs)
|
|
47
|
+
-n, --max-iterations <n> Max tool-call iterations (default: 25)
|
|
48
|
+
-y, --yes Auto-approve all tool calls (skip confirmation prompts)
|
|
49
|
+
--stats Show memory file paths and status
|
|
50
|
+
-h, --help Show help
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## REPL Commands
|
|
54
|
+
|
|
55
|
+
All commands follow the pattern: `/noun` to show, `/noun subcommand` to act.
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
/help Show all commands
|
|
59
|
+
/model Show current model
|
|
60
|
+
/model <name> Switch model (persists to config)
|
|
61
|
+
/model search [query] Browse OpenRouter models
|
|
62
|
+
/memory Show all memory + stats
|
|
63
|
+
/memory global Show global memory
|
|
64
|
+
/memory project Show project memory
|
|
65
|
+
/memory clear project|all Clear memory
|
|
66
|
+
/plan Show current plan
|
|
67
|
+
/plan list List all plans
|
|
68
|
+
/plan use <name> Activate an older plan
|
|
69
|
+
/context Show context window usage
|
|
70
|
+
/context compact Force context compaction now
|
|
71
|
+
/config Show config + file paths
|
|
72
|
+
/config set <k> <v> Set a config value
|
|
73
|
+
/tools List loaded tools
|
|
74
|
+
/skill List installed skills
|
|
75
|
+
/skill search [query] Search skills.sh registry
|
|
76
|
+
/skill add <source> Install skill from registry
|
|
77
|
+
/skill remove <name> Uninstall a skill
|
|
78
|
+
/exit Exit
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Tools
|
|
82
|
+
|
|
83
|
+
All action-based tools follow the pattern: `tool(action, ...params)`.
|
|
84
|
+
|
|
85
|
+
| Tool | Actions | Purpose |
|
|
86
|
+
|------|---------|---------|
|
|
87
|
+
| `bash` | — | Run any shell command (dangerous patterns blocked) |
|
|
88
|
+
| `file` | `read` · `list` · `write` · `edit` | Read, browse, create, and edit files |
|
|
89
|
+
| `memory` | `save` | Persist a fact to global or project memory |
|
|
90
|
+
| `plan` | `save`, `append`, `switch`, `list`, `read` | Manage task plans |
|
|
91
|
+
| `git` | `status`, `init`, `branch`, `commit`, `push` | Git workflow |
|
|
92
|
+
| `grep` | `search`, `find` | Search file contents (regex), find files by glob |
|
|
93
|
+
| `web` | `fetch`, `search` | Fetch web pages, search for current info |
|
|
94
|
+
| `skill` | — | Activate a skill by name |
|
|
95
|
+
|
|
96
|
+
## Custom Tools
|
|
97
|
+
|
|
98
|
+
Drop a `.mjs` file in a tools directory and it gets loaded at startup:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
~/.ag/tools/ # global (all projects)
|
|
102
|
+
.ag/tools/ # project-local (overrides global if same name)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Each file exports a default tool object:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
// ~/.ag/tools/weather.mjs
|
|
109
|
+
export default {
|
|
110
|
+
type: "function",
|
|
111
|
+
function: {
|
|
112
|
+
name: "weather",
|
|
113
|
+
description: "Get current weather for a city",
|
|
114
|
+
parameters: {
|
|
115
|
+
type: "object",
|
|
116
|
+
properties: { city: { type: "string", description: "City name" } },
|
|
117
|
+
required: ["city"]
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
execute: ({ city }) => {
|
|
121
|
+
// your logic here -- can be async
|
|
122
|
+
return `Weather in ${city}: sunny, 22C`;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
That's it. No config, no registry. Use `/tools` in the REPL to see what's loaded.
|
|
128
|
+
|
|
129
|
+
## Skills
|
|
130
|
+
|
|
131
|
+
Skills are reusable prompt instructions (with optional tools) that the agent activates on-demand. Browse and install from [skills.sh](https://skills.sh):
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
/skill search frontend # search the registry
|
|
135
|
+
/skill add anthropic/skills@frontend # install
|
|
136
|
+
/skill # list installed
|
|
137
|
+
/skill remove frontend # uninstall
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Skills are SKILL.md files with YAML frontmatter:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
~/.ag/skills/ # global (all projects)
|
|
144
|
+
.ag/skills/ # project-local (overrides global)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```markdown
|
|
148
|
+
---
|
|
149
|
+
name: my-skill
|
|
150
|
+
description: When to use this skill. The agent sees this to decide activation.
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
Your instructions here. The agent loads this content when the skill is activated.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Frontmatter fields: `name` (required), `description` (required), `tools: true` (look for tools.mjs alongside), `always: true` (always inject, don't wait for activation).
|
|
157
|
+
|
|
158
|
+
The agent sees skill names + descriptions in every prompt. When a task matches, it activates the skill automatically via the `skill` tool, loading the full instructions into context.
|
|
159
|
+
|
|
160
|
+
## Configuration
|
|
161
|
+
|
|
162
|
+
Persistent settings are stored in `~/.ag/config.json`:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"apiKey": "sk-or-v1-...",
|
|
167
|
+
"model": "anthropic/claude-sonnet-4.6",
|
|
168
|
+
"baseURL": "https://openrouter.ai/api/v1",
|
|
169
|
+
"maxIterations": 25,
|
|
170
|
+
"tavilyApiKey": "tvly-..."
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Set values via the REPL (`/config set model openai/gpt-4o`) or edit the file directly. CLI flags and environment variables always take priority over config file values.
|
|
175
|
+
|
|
176
|
+
For web search, get a free Tavily API key at [tavily.com](https://tavily.com) (no credit card needed). The agent prompts for it on first use, or set it manually:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
export TAVILY_API_KEY=tvly-...
|
|
180
|
+
# or in the REPL:
|
|
181
|
+
/config set tavilyApiKey tvly-...
|
|
182
|
+
/config set TAVILY_API_KEY tvly-... # env var name also works
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Memory
|
|
186
|
+
|
|
187
|
+
Three tiers, all plain markdown you can edit directly:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
~/.ag/
|
|
191
|
+
config.json # settings: API key, default model, base URL
|
|
192
|
+
memory.md # global: preferences, patterns
|
|
193
|
+
skills/ # installed skills (from skills.sh or manual)
|
|
194
|
+
frontend/SKILL.md
|
|
195
|
+
tools/ # custom tools (.mjs files)
|
|
196
|
+
projects/
|
|
197
|
+
<id>/
|
|
198
|
+
memory.md # project: architecture, decisions
|
|
199
|
+
plans/ # timestamped plan files
|
|
200
|
+
2026-04-13T12-31-22-add-auth.md
|
|
201
|
+
history.jsonl # conversation history
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
All memory is injected into the system prompt on every API call (capped at ~6000 chars total to avoid context bloat). The agent reads it automatically and writes via the `memory` and `plan` tools.
|
|
205
|
+
|
|
206
|
+
### Git workflow with memory
|
|
207
|
+
|
|
208
|
+
Save your ticket context and PR template to project memory, and the agent will use them when committing and pushing:
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
you> save to project memory: Current ticket: JIRA-123 Add user auth. PR template: ## What\n## Why\n## Testing
|
|
212
|
+
you> create a branch for this ticket and start working
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The agent sees your memory context and will name branches, write commit messages, and format PR descriptions accordingly.
|
|
216
|
+
|
|
217
|
+
## Local LLMs
|
|
218
|
+
|
|
219
|
+
Point `ag` at any OpenAI-compatible API:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
ag -b http://localhost:11434/v1 "hello" # Ollama
|
|
223
|
+
ag -b http://localhost:1234/v1 "hello" # LM Studio
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Or set it permanently:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# In the REPL:
|
|
230
|
+
/config set baseURL http://localhost:11434/v1
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Permissions
|
|
234
|
+
|
|
235
|
+
In REPL mode, ag prompts before executing mutating operations:
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
? bash: npm test (y/n) y
|
|
239
|
+
✓ [bash] All tests passed
|
|
240
|
+
? file(write): src/utils.ts (y/n) y
|
|
241
|
+
✓ [file] Wrote src/utils.ts (24 lines, 680B)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Always allowed (no prompt):** `file(read)`, `file(list)`, `grep(*)`, `memory(*)`, `plan(*)`, `skill(*)`, `git(status)`, `web(search)`
|
|
245
|
+
|
|
246
|
+
**Prompted:** `bash`, `file(write)`, `file(edit)`, `git(commit/push/branch)`, `web(fetch)`
|
|
247
|
+
|
|
248
|
+
**Always blocked:** `rm -rf /`, fork bombs, `sudo rm`, pipe-to-shell (enforced in code regardless of approval)
|
|
249
|
+
|
|
250
|
+
Skip prompts with `ag -y` or `--yes`. One-shot mode (`ag "query"`) auto-approves.
|
|
251
|
+
|
|
252
|
+
## Streaming
|
|
253
|
+
|
|
254
|
+
Responses stream token-by-token with progressive markdown rendering. Tool execution shows animated spinners:
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
⠋ thinking [1/25]
|
|
258
|
+
✓ [grep] src/agent.ts:42: export class Agent
|
|
259
|
+
⠋ thinking [2/25]
|
|
260
|
+
|
|
261
|
+
agent> The Agent class is defined in src/agent.ts...
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Tools execute in parallel when the model returns multiple tool calls.
|
|
265
|
+
|
|
266
|
+
## Workflow
|
|
267
|
+
|
|
268
|
+
- Environment context (date, OS, git branch, detected stack) is injected into every system prompt.
|
|
269
|
+
- A compact project file listing gives the model awareness of project structure.
|
|
270
|
+
- `tool_choice: "auto"` encourages tool use over conversational responses.
|
|
271
|
+
- Dangerous bash commands (`find ~`, `rm -rf /`, etc.) are blocked before execution.
|
|
272
|
+
- Tool results over 8KB are smart-truncated (first 50 + last 50 lines) to preserve context.
|
|
273
|
+
- For multi-step coding tasks, the agent creates a plan before starting and updates it as it goes.
|
|
274
|
+
- For simple questions, it just answers directly.
|
|
275
|
+
- At 25 iterations the REPL asks if you want to continue.
|
|
276
|
+
- At 90% context window usage, ag automatically summarizes older conversation messages to free space. Use `/compact` to trigger manually. Only message history is compacted — system prompt, tools, and skills are unaffected.
|
|
277
|
+
|
|
278
|
+
## When to use something else
|
|
279
|
+
|
|
280
|
+
- **Claude Code** -- if you have a subscription and want the full harness with MCP, sub-agents, and a polished UI. ag is not trying to replace it.
|
|
281
|
+
- **aider** -- if your workflow is git-centric (commit-per-change, diff-based editing).
|
|
282
|
+
- **Cursor / Windsurf** -- if you want IDE integration. ag is terminal-only.
|
|
283
|
+
|
|
284
|
+
ag is for when you want a hackable, persistent, model-agnostic agent you fully control.
|
|
285
|
+
|
|
286
|
+
## Architecture
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
src/
|
|
290
|
+
cli.ts # entry point
|
|
291
|
+
cli/parser.ts # arg parsing + help
|
|
292
|
+
cli/repl.ts # interactive REPL (unified /noun commands)
|
|
293
|
+
core/agent.ts # the loop + skill activation
|
|
294
|
+
core/config.ts # persistent config (~/.ag/config.json)
|
|
295
|
+
core/context.ts # context window usage tracking
|
|
296
|
+
core/skills.ts # skill discovery, parsing, loading
|
|
297
|
+
core/registry.ts # skills.sh search + GitHub install
|
|
298
|
+
core/types.ts # interfaces
|
|
299
|
+
core/colors.ts # ANSI colors (respects NO_COLOR)
|
|
300
|
+
core/version.ts # version from package.json
|
|
301
|
+
memory/memory.ts # three-tier file memory
|
|
302
|
+
tools/file.ts # file reading + directory listing
|
|
303
|
+
tools/bash.ts # shell execution (with command safeguards)
|
|
304
|
+
tools/memory.ts # memory tool
|
|
305
|
+
tools/plan.ts # plan management tool
|
|
306
|
+
tools/git.ts # git operations tool
|
|
307
|
+
tools/grep.ts # code search + file find
|
|
308
|
+
tools/web.ts # web fetch + search tool
|
|
309
|
+
tools/skill.ts # skill activation tool
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Zero npm dependencies. Node.js 18+ and TypeScript.
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/cli/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,GAAG;IAAE,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAkB/E;AAED,wBAAgB,QAAQ,IAAI,IAAI,CAkC/B"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export function parseArgs(args) {
|
|
2
|
+
const options = {};
|
|
3
|
+
const positional = [];
|
|
4
|
+
for (let i = 0; i < args.length; i++) {
|
|
5
|
+
const arg = args[i];
|
|
6
|
+
if ((arg === '--model' || arg === '-m') && i + 1 < args.length)
|
|
7
|
+
options.model = args[++i];
|
|
8
|
+
else if ((arg === '--key' || arg === '-k') && i + 1 < args.length)
|
|
9
|
+
options.key = args[++i];
|
|
10
|
+
else if ((arg === '--system' || arg === '-s') && i + 1 < args.length)
|
|
11
|
+
options.system = args[++i];
|
|
12
|
+
else if ((arg === '--base-url' || arg === '-b') && i + 1 < args.length)
|
|
13
|
+
options.baseURL = args[++i];
|
|
14
|
+
else if ((arg === '--max-iterations' || arg === '-n') && i + 1 < args.length)
|
|
15
|
+
options.maxIterations = parseInt(args[++i], 10);
|
|
16
|
+
else if (arg === '--stats')
|
|
17
|
+
options.stats = true;
|
|
18
|
+
else if (arg === '--yes' || arg === '-y')
|
|
19
|
+
options.yes = true;
|
|
20
|
+
else if (arg === '--help' || arg === '-h')
|
|
21
|
+
options.help = true;
|
|
22
|
+
else if (!arg.startsWith('-'))
|
|
23
|
+
positional.push(arg);
|
|
24
|
+
}
|
|
25
|
+
return { ...options, positional };
|
|
26
|
+
}
|
|
27
|
+
export function showHelp() {
|
|
28
|
+
console.log(`
|
|
29
|
+
ag - Persistent AI coding agent with memory and skills (any model via OpenRouter)
|
|
30
|
+
|
|
31
|
+
Usage:
|
|
32
|
+
ag # Interactive REPL
|
|
33
|
+
ag "what files are here?" # One-shot mode
|
|
34
|
+
ag --stats # Show memory stats
|
|
35
|
+
ag -m openai/gpt-4o "help me" # Use specific model
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
-m, --model <model> Model ID (default: anthropic/claude-sonnet-4.6)
|
|
39
|
+
-k, --key <key> API key (or set OPENROUTER_API_KEY)
|
|
40
|
+
-s, --system <prompt> Custom system prompt
|
|
41
|
+
-b, --base-url <url> API base URL (default: OpenRouter; use for local LLMs)
|
|
42
|
+
-n, --max-iterations <n> Max tool-call iterations (default: 25)
|
|
43
|
+
-y, --yes Auto-approve all tool calls (skip confirmation prompts)
|
|
44
|
+
--stats Show memory file locations and status
|
|
45
|
+
-h, --help Show this help
|
|
46
|
+
|
|
47
|
+
REPL commands:
|
|
48
|
+
/model [name|search] Show, switch, or browse models
|
|
49
|
+
/memory [global|project|clear] Show or manage memory
|
|
50
|
+
/plan [list|use <name>] Show or manage plans
|
|
51
|
+
/config [set <k> <v>] Show or set config
|
|
52
|
+
/tools List loaded tools
|
|
53
|
+
/skill [search|add|remove] Manage skills from skills.sh
|
|
54
|
+
/help Show all commands
|
|
55
|
+
/exit Exit
|
|
56
|
+
|
|
57
|
+
Install:
|
|
58
|
+
npx @iambarryking/ag # Run directly
|
|
59
|
+
npm install -g @iambarryking/ag # Install globally
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/cli/parser.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,OAAO,GAAe,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aACrF,IAAI,CAAC,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aACtF,IAAI,CAAC,GAAG,KAAK,UAAU,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aAC5F,IAAI,CAAC,GAAG,KAAK,YAAY,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aAC/F,IAAI,CAAC,GAAG,KAAK,kBAAkB,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;aACzH,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;aAC5C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;aACxD,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;aAC1D,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCb,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Interface } from 'node:readline';
|
|
2
|
+
import { Agent } from '../core/agent.js';
|
|
3
|
+
import type { ConfirmToolCall } from '../core/types.js';
|
|
4
|
+
export declare function createConfirmCallback(sharedRl?: Interface): ConfirmToolCall & {
|
|
5
|
+
pauseSpinner: (() => void) | null;
|
|
6
|
+
};
|
|
7
|
+
export declare class REPL {
|
|
8
|
+
private readonly agent;
|
|
9
|
+
private readonly rl;
|
|
10
|
+
private readonly confirmCb;
|
|
11
|
+
constructor(agent: Agent, confirmCb?: ReturnType<typeof createConfirmCallback>);
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
private handleCommand;
|
|
14
|
+
private ask;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=repl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../src/cli/repl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,SAAS,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,KAAK,EAA0B,MAAM,kBAAkB,CAAC;AAKjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAoBxD,wBAAgB,qBAAqB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,eAAe,GAAG;IAAE,YAAY,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAA;CAAE,CAuBnH;AAmBD,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkD;gBAEhE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC;IAcxE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YA6Id,aAAa;IAiT3B,OAAO,CAAC,GAAG;CAGZ"}
|