@robota-sdk/agent-cli 3.0.0-beta.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Robota Contributors
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,254 @@
1
+ # @robota-sdk/agent-cli
2
+
3
+ AI coding assistant CLI built on Robota SDK. Loads AGENTS.md/CLAUDE.md for project context and provides tool-calling REPL with Claude Code-compatible permission modes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Global install
9
+ npm install -g @robota-sdk/agent-cli
10
+
11
+ # Or run directly with npx
12
+ npx @robota-sdk/agent-cli
13
+ ```
14
+
15
+ After installing globally, the `robota` command is available system-wide:
16
+
17
+ ```bash
18
+ robota # Interactive REPL
19
+ robota "prompt" # REPL with initial prompt
20
+ robota -p "List all files" # Print mode (one-shot, exit after response)
21
+ ```
22
+
23
+ ### Environment Variables
24
+
25
+ | Variable | Description | Required |
26
+ | ------------------- | ----------------- | -------- |
27
+ | `ANTHROPIC_API_KEY` | Anthropic API key | Yes |
28
+
29
+ Set your key before running:
30
+
31
+ ```bash
32
+ export ANTHROPIC_API_KEY=sk-ant-...
33
+ ```
34
+
35
+ ## Development Setup (Monorepo)
36
+
37
+ ```bash
38
+ # 1. Copy .env.example and add your Anthropic API key
39
+ cp packages/agent-cli/.env.example packages/agent-cli/.env
40
+ # Edit .env and set ANTHROPIC_API_KEY=sk-ant-...
41
+
42
+ # 2. Build dependencies and CLI
43
+ pnpm build:deps
44
+ pnpm --filter @robota-sdk/agent-cli build
45
+ ```
46
+
47
+ ## Usage (Monorepo)
48
+
49
+ ```bash
50
+ # From monorepo root
51
+ cd packages/agent-cli
52
+
53
+ # Development mode (no build needed, auto-loads .env)
54
+ pnpm dev
55
+
56
+ # Production mode (requires build)
57
+ pnpm start
58
+
59
+ # With arguments
60
+ pnpm dev -- --version
61
+ pnpm dev -- --permission-mode plan
62
+ pnpm dev -- -p "List all TypeScript files in src/"
63
+ ```
64
+
65
+ ## CLI Flags
66
+
67
+ ```
68
+ robota # Interactive REPL (default mode)
69
+ robota "prompt" # REPL with initial prompt
70
+ robota -p "prompt" # Print mode (one-shot, exit after response)
71
+ robota -c # Continue last session
72
+ robota -r <session-id> # Resume session by ID
73
+ robota --model <model> # Model override (e.g., claude-sonnet-4-6)
74
+ robota --permission-mode <mode> # plan | default | acceptEdits | bypassPermissions
75
+ robota --max-turns <n> # Limit agentic turns per interaction
76
+ robota --version # Show version
77
+ ```
78
+
79
+ ## Built-in Tools
80
+
81
+ The CLI provides 6 tools that the AI agent can invoke:
82
+
83
+ | Tool | Description | Primary Argument |
84
+ | ------- | ------------------------------------ | ---------------- |
85
+ | `Bash` | Execute shell commands | `command` |
86
+ | `Read` | Read file contents with line numbers | `filePath` |
87
+ | `Write` | Write content to a file | `filePath` |
88
+ | `Edit` | Replace a string in a file | `filePath` |
89
+ | `Glob` | Find files matching a pattern | `pattern` |
90
+ | `Grep` | Search file contents with regex | `pattern` |
91
+
92
+ ## Permission System
93
+
94
+ Every tool call passes through a three-step permission gate before execution:
95
+
96
+ 1. **Deny list** — if any deny pattern matches, the action is blocked immediately
97
+ 2. **Allow list** — if any allow pattern matches, the action is auto-approved
98
+ 3. **Mode policy** — the active permission mode determines the decision
99
+
100
+ When a tool requires approval, the user sees an interactive prompt:
101
+
102
+ ```
103
+ [Permission Required] Tool: Bash
104
+ Arguments: command: rm -rf dist
105
+ Allow? [y/N]
106
+ ```
107
+
108
+ - Type `y` or `yes` to approve
109
+ - Press Enter or type anything else to deny
110
+
111
+ If denied, the AI agent receives a "Permission denied" error and can adjust its approach.
112
+
113
+ ### Permission Modes
114
+
115
+ | Mode | Alias | Read/Glob/Grep | Write/Edit | Bash |
116
+ | ------------------- | -------- | :------------: | :--------: | :-----: |
117
+ | `plan` | safe | auto | deny | deny |
118
+ | `default` | moderate | auto | approve | approve |
119
+ | `acceptEdits` | full | auto | auto | approve |
120
+ | `bypassPermissions` | — | auto | auto | auto |
121
+
122
+ - **auto** — tool executes without prompting
123
+ - **approve** — user is prompted to allow or deny
124
+ - **deny** — tool is blocked silently (no prompt shown)
125
+
126
+ Unknown tools default to `approve` in most modes, `deny` in `plan` mode.
127
+
128
+ ### Changing Mode at Runtime
129
+
130
+ Use the `/mode` slash command in the REPL:
131
+
132
+ ```
133
+ > /mode # Show current mode
134
+ Current permission mode: default
135
+
136
+ > /mode plan # Switch to plan (read-only)
137
+ Permission mode set to: plan
138
+
139
+ > /mode bypassPermissions # Skip all prompts
140
+ Permission mode set to: bypassPermissions
141
+ ```
142
+
143
+ Or set it at startup:
144
+
145
+ ```bash
146
+ robota --permission-mode plan
147
+ ```
148
+
149
+ ### Permission Patterns (allow/deny lists)
150
+
151
+ Configure in `.robota/settings.json` or `.robota/settings.local.json`:
152
+
153
+ ```json
154
+ {
155
+ "permissions": {
156
+ "allow": ["Bash(pnpm *)", "Bash(git status)", "Read(/src/**)"],
157
+ "deny": ["Bash(rm -rf *)", "Write(.env)"]
158
+ }
159
+ }
160
+ ```
161
+
162
+ **Pattern syntax:**
163
+
164
+ - `ToolName` — match any invocation of that tool (e.g., `Bash`)
165
+ - `ToolName(pattern)` — match when the primary argument matches the glob (e.g., `Bash(pnpm *)`)
166
+ - `*` — zero or more characters (shell-style)
167
+ - `**` — one or more characters (recursive path matching)
168
+
169
+ **Evaluation order:** deny patterns are checked first, then allow patterns, then the mode policy. Deny always wins.
170
+
171
+ ## Slash Commands
172
+
173
+ | Command | Description |
174
+ | -------------- | ------------------------------- |
175
+ | `/help` | Show help |
176
+ | `/clear` | Clear conversation history |
177
+ | `/mode [mode]` | Show or change permission mode |
178
+ | `/resume` | List and resume a saved session |
179
+ | `/cost` | Show token usage |
180
+ | `/model` | Show current model |
181
+ | `/exit` | Exit CLI |
182
+
183
+ ## Configuration
184
+
185
+ Settings are loaded from (highest priority first):
186
+
187
+ 1. `.robota/settings.local.json` (local, gitignored)
188
+ 2. `.robota/settings.json` (project, shared)
189
+ 3. `~/.robota/settings.json` (user global)
190
+
191
+ ```json
192
+ {
193
+ "defaultMode": "default",
194
+ "provider": {
195
+ "name": "anthropic",
196
+ "model": "claude-sonnet-4-6",
197
+ "apiKey": "$ENV:ANTHROPIC_API_KEY"
198
+ },
199
+ "permissions": {
200
+ "allow": ["Bash(pnpm *)"],
201
+ "deny": ["Bash(rm -rf *)"]
202
+ }
203
+ }
204
+ ```
205
+
206
+ ### Environment Variables
207
+
208
+ | Variable | Description | Required |
209
+ | ------------------- | ----------------- | -------- |
210
+ | `ANTHROPIC_API_KEY` | Anthropic API key | Yes |
211
+
212
+ Copy `.env.example` to `.env` and set your key. The CLI reads `.env` automatically in dev mode.
213
+
214
+ ## Context Discovery
215
+
216
+ The CLI automatically discovers and loads:
217
+
218
+ - **AGENTS.md** — walking up from cwd to filesystem root
219
+ - **CLAUDE.md** — same walk-up discovery
220
+ - **Project metadata** — from `package.json`, `tsconfig.json`
221
+
222
+ All context is assembled into the system prompt for the AI assistant.
223
+
224
+ ## Architecture
225
+
226
+ ```
227
+ bin.ts → cli.ts (parseArgs, load config/context, create Session)
228
+ ├── config/config-loader.ts — settings file discovery + Zod validation
229
+ ├── context/context-loader.ts — AGENTS.md/CLAUDE.md walk-up discovery
230
+ ├── context/project-detector.ts — package.json/tsconfig detection
231
+ ├── context/system-prompt-builder.ts — system message assembly
232
+ ├── session.ts — Robota agent wrapper + permission enforcement
233
+ │ └── permissions/
234
+ │ ├── permission-gate.ts — 3-step evaluation (deny → allow → mode)
235
+ │ ├── permission-mode.ts — mode × tool policy matrix
236
+ │ └── permission-prompt.ts — interactive [y/N] prompt
237
+ ├── tools/ — 6 built-in tools (Bash, Read, Write, Edit, Glob, Grep)
238
+ ├── session-store.ts — JSON file-based session persistence
239
+ └── ui/ — Ink TUI components (App, MessageList, InputArea, etc.)
240
+ ```
241
+
242
+ Tool calls flow through the permission system:
243
+
244
+ ```
245
+ AI agent requests tool call
246
+ → Session.wrapToolWithPermission() intercepts execute()
247
+ → evaluatePermission(toolName, args, mode, allow/deny lists)
248
+ → deny list match? → blocked
249
+ → allow list match? → auto-approved
250
+ → mode policy lookup → auto | approve | deny
251
+ → if 'approve': promptForApproval() → user types y/N
252
+ → if allowed: original tool.execute() runs
253
+ → if denied: returns error result to AI agent
254
+ ```