aws-cli-agent 0.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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +373 -0
- package/dist/agent.d.ts +40 -0
- package/dist/agent.js +293 -0
- package/dist/audit.d.ts +39 -0
- package/dist/audit.js +33 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +179 -0
- package/dist/config.d.ts +43 -0
- package/dist/config.js +131 -0
- package/dist/history.d.ts +34 -0
- package/dist/history.js +71 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/logger.d.ts +29 -0
- package/dist/logger.js +68 -0
- package/dist/paths.d.ts +23 -0
- package/dist/paths.js +36 -0
- package/dist/providers.d.ts +16 -0
- package/dist/providers.js +59 -0
- package/dist/reasoning.d.ts +59 -0
- package/dist/reasoning.js +125 -0
- package/dist/tools/aws-cli.d.ts +48 -0
- package/dist/tools/aws-cli.js +279 -0
- package/dist/tools/bash.d.ts +47 -0
- package/dist/tools/bash.js +197 -0
- package/dist/tools/history.d.ts +18 -0
- package/dist/tools/history.js +27 -0
- package/dist/tools/index.d.ts +157 -0
- package/dist/tools/index.js +43 -0
- package/dist/tools/profiles.d.ts +7 -0
- package/dist/tools/profiles.js +37 -0
- package/dist/tools/prompt.d.ts +37 -0
- package/dist/tools/prompt.js +145 -0
- package/dist/usage.d.ts +39 -0
- package/dist/usage.js +28 -0
- package/package.json +73 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
|
|
5
|
+
versioning follows [SemVer](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.4.0] - 2026-05-17
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Initial official release. Agentic AI assistant that turns natural-language requests into AWS CLI commands and runs them locally.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aws-cli-agent 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,373 @@
|
|
|
1
|
+
# aws-cli-agent (`aca`)
|
|
2
|
+
|
|
3
|
+
> Agentic AI assistant that turns natural-language requests into AWS CLI commands and runs them locally.
|
|
4
|
+
|
|
5
|
+
You describe what you want in plain English. The agent searches your local history, lists your AWS profiles, runs read-only discovery calls to resolve resources, prompts you for anything ambiguous, and executes the final command — after asking for permission.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Interactive session to an instance the agent has to look up
|
|
11
|
+
aca "start ssm session to instance my-instance in my-account"
|
|
12
|
+
|
|
13
|
+
# Use the AWS CLI's table output for human consumption
|
|
14
|
+
aca "print tags of gitlab instance as table"
|
|
15
|
+
|
|
16
|
+
# Cross-resource composition: instances, their IAM roles, and the attached policies
|
|
17
|
+
aca "list ec2 instance id, name, instance profile arn plus the iam policies in the attached iam role as json in my-account"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The first example is interactive — the agent runs a read-only `describe-instances` to resolve the name, then prompts before opening the SSM session. The second produces a table on stdout, pipeable to `less` or `grep`. The third is the kind of request where the agent will most likely build a bash script with `jq` plumbing rather than chain individual AWS CLI calls.
|
|
21
|
+
|
|
22
|
+
## ⚠️ Warning — read before using
|
|
23
|
+
|
|
24
|
+
`aca` runs real AWS CLI commands against your real AWS accounts. Treat it accordingly.
|
|
25
|
+
|
|
26
|
+
- **The agent executes AWS CLI commands on your behalf.** Commands run with whatever credentials and roles your local `aws` CLI is configured to use. Anything you can do interactively, `aca` can do. Anything an attacker who got your credentials could do, a hallucinating model could do too.
|
|
27
|
+
- **Models hallucinate.** The agent is instructed not to guess and to ask for missing information, but model behavior is statistical, not contractual. A misinterpreted request can produce an unintended command. Always read the `Reason:` / `Command:` block before pressing `y`.
|
|
28
|
+
- **Auto-approve is dangerous.** `autoApprove.readOnly: true` (the default) skips the prompt only for non-mutating commands (`describe-*`, `list-*`, `get-*`, `s3 ls`). `autoApprove.all: true` skips the prompt for **every** command — a misrouted `delete-*` or `terminate-*` can ruin your weekend or your career. Set it only in tightly scoped one-off workflows, never as a persistent default.
|
|
29
|
+
- **Bash scripts are arbitrary code.** When the agent generates a bash script for multi-account or composition workflows, the script can do anything your shell can. Read it before you press execute. The "save to disk" option exists so you can review it in your editor first; use it when in doubt.
|
|
30
|
+
- **Watch the bill.** Every invocation sends a prompt to your LLM provider and pays for tokens. Token totals per run are logged in `usage.log` (`cat ~/.local/state/aws-cli-agent/usage.log | jq -s 'map(.totalTokens) | add'`). Caching is on by default and cuts ~25-40% off input costs for frequent users; if you invoke `aca` rarely (once an hour or less) the cache writes don't pay back and you can set `caching: false`.
|
|
31
|
+
- **Your prompts go to the model provider.** AWS CLI output is fed back to the model as part of subsequent steps. That means resource names, instance IDs, tag values, and any other data that appears in command output is transmitted to Anthropic / OpenAI / Google / Bedrock (depending on your provider choice). The provider does not retain this data beyond the request itself (and the cache TTL, ~5 minutes for cached prefixes), but **confirm this is compatible with the policies you have to respect** before pointing `aca` at sensitive accounts.
|
|
32
|
+
- **Provider terms apply.** When you use a provider, you agree to that provider's terms of service. For Bedrock, that's AWS's own terms (data stays in your AWS account boundary). For Anthropic / OpenAI / Google, that's their respective enterprise / API terms. Read them.
|
|
33
|
+
- **Audit log is your friend.** Every executed command — including its stdout, stderr, and exit code — lands in `audit.log` (JSONL). If you ever need to reconstruct what happened, it's all there. Don't disable `logging.auditLog` unless you have a specific reason.
|
|
34
|
+
- **No warranty.** **You use this agent at your own risk.** The authors are not responsible for unintended AWS API calls, deleted resources, exceeded budgets, or any other damage caused by using this tool. If you wouldn't run `aws` commands blindly from a script you found in someone's gist, don't run `aca` blindly either.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g aws-cli-agent
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Two binaries are installed: `aws-cli-agent` (full name) and `aca` (short alias). They're identical.
|
|
43
|
+
|
|
44
|
+
Requirements:
|
|
45
|
+
- Node.js ≥ 20
|
|
46
|
+
- AWS CLI v2 on `$PATH`
|
|
47
|
+
- An API key for one supported provider (Anthropic / OpenAI / Google),
|
|
48
|
+
**or** AWS credentials with Bedrock model access if you choose the Bedrock provider
|
|
49
|
+
|
|
50
|
+
## Setup
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 1. Create the config file with sane defaults
|
|
54
|
+
aca config
|
|
55
|
+
|
|
56
|
+
# 2. Set the API key for your chosen provider (env var only — never in config)
|
|
57
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
58
|
+
# or OPENAI_API_KEY=...
|
|
59
|
+
# or GOOGLE_GENERATIVE_AI_API_KEY=...
|
|
60
|
+
# (Bedrock needs no API key — uses your AWS credential chain)
|
|
61
|
+
|
|
62
|
+
# 3. Try it
|
|
63
|
+
aca "list all s3 buckets in account my-staging"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
Config file: `$XDG_CONFIG_HOME/aws-cli-agent/config.json` (defaults to `~/.config/aws-cli-agent/config.json`).
|
|
69
|
+
|
|
70
|
+
Default contents (created by `aca config`):
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"provider": "anthropic",
|
|
75
|
+
"model": "claude-sonnet-4-5-20250929",
|
|
76
|
+
"maxSteps": 15,
|
|
77
|
+
"logging": {
|
|
78
|
+
"level": "error",
|
|
79
|
+
"auditLog": true,
|
|
80
|
+
"reasoningLog": false,
|
|
81
|
+
"usageLog": true
|
|
82
|
+
},
|
|
83
|
+
"caching": true,
|
|
84
|
+
"verbose": false,
|
|
85
|
+
"autoApprove": {
|
|
86
|
+
"readOnly": true,
|
|
87
|
+
"all": false
|
|
88
|
+
},
|
|
89
|
+
"forceInteractive": false,
|
|
90
|
+
"historyLimit": 200
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Optional fields (omit if you don't need them):
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"apiKeyEnv": "MY_CUSTOM_ANTHROPIC_KEY",
|
|
99
|
+
"defaultRegion": "eu-west-1",
|
|
100
|
+
"scriptFolder": "/home/me/aws-scripts",
|
|
101
|
+
"bedrock": {
|
|
102
|
+
"region": "us-east-1",
|
|
103
|
+
"profile": "shared-services"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Top-level keys
|
|
109
|
+
|
|
110
|
+
| Key | Default | Meaning |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `provider` | `anthropic` | LLM provider: `anthropic` \| `openai` \| `google` \| `bedrock` |
|
|
113
|
+
| `model` | `claude-sonnet-4-5-20250929` | Model identifier (Bedrock uses fully-qualified IDs — see below) |
|
|
114
|
+
| `apiKeyEnv` | — | Override the env var name that holds the API key (ignored for `bedrock`) |
|
|
115
|
+
| `bedrock` | — | Bedrock-specific settings (see below). Only used when `provider = "bedrock"`. |
|
|
116
|
+
| `defaultRegion` | — | AWS region injected into every AWS CLI command when the agent didn't specify one |
|
|
117
|
+
| `caching` | `true` | Enable prompt caching for providers that support it. See "Prompt caching" below. |
|
|
118
|
+
| `maxSteps` | `15` | Hard cap on agent reasoning/tool steps per request (range 1-50) |
|
|
119
|
+
| `logging` | see below | All logging knobs |
|
|
120
|
+
| `verbose` | `false` | Echo agent reasoning to the console as it runs |
|
|
121
|
+
| `autoApprove.readOnly` | `true` | Skip prompt for read-only AWS CLI commands (`describe-*` / `list-*` / `get-*` / `s3 ls`) |
|
|
122
|
+
| `autoApprove.all` | `false` | Skip prompt for **all AWS CLI commands** including mutating ones. Does NOT apply to bash scripts — those always prompt. |
|
|
123
|
+
| `forceInteractive` | `false` | Run every AWS CLI command with inherited stdio. Persistent equivalent of `--interactive`/`-i`. Almost always leave unset and use the CLI flag for one-offs. |
|
|
124
|
+
| `historyLimit` | `200` | Max history entries kept in memory for context |
|
|
125
|
+
| `scriptFolder` | `$XDG_DATA_HOME/aws-cli-agent/scripts` | Where saved bash scripts are written |
|
|
126
|
+
|
|
127
|
+
### Logging
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
"logging": {
|
|
131
|
+
"level": "error",
|
|
132
|
+
"auditLog": true,
|
|
133
|
+
"reasoningLog": false,
|
|
134
|
+
"usageLog": true
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Key | Default | Meaning |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `logging.level` | `error` | General-log verbosity: `silent` \| `error` \| `warn` \| `info` \| `debug` \| `trace`. Override per run with `--log-level`. |
|
|
141
|
+
| `logging.auditLog` | `true` | Write `audit.log` — JSONL trail of every executed command/script with full stdout/stderr/exit code. Bash scripts also log full source. |
|
|
142
|
+
| `logging.reasoningLog` | `false` | Write `reasoning.log` — text record of agent reasoning steps and tool calls. |
|
|
143
|
+
| `logging.usageLog` | `true` | Write `usage.log` — one JSONL entry per `aca` invocation with token totals (input + completion + total + cache hit/miss). |
|
|
144
|
+
|
|
145
|
+
Logs are file-only. None of these settings affect what's printed to the console — that's a separate concern handled by `verbose` (reasoning lines) and the CLI's normal output (the AWS CLI's stdout passthrough plus approval prompts). To watch operational logs live in a separate terminal: `tail -f ~/.local/state/aws-cli-agent/general.log`.
|
|
146
|
+
|
|
147
|
+
### `defaultRegion` and `--region`
|
|
148
|
+
|
|
149
|
+
If `defaultRegion` is set, `aca` appends `--region <value>` to every AWS CLI command the agent runs — **only when the agent didn't already specify a region itself**. The agent's choice (driven by the user's prompt or history) always wins. Override per run with `--region`.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
aca --region eu-west-1 "list ec2 instances in my-staging"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Bedrock
|
|
156
|
+
|
|
157
|
+
When `provider = "bedrock"`, configure region and (optionally) profile via the nested `bedrock` object:
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"provider": "bedrock",
|
|
162
|
+
"model": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
|
|
163
|
+
"bedrock": {
|
|
164
|
+
"region": "us-east-1",
|
|
165
|
+
"profile": "shared-services"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- **Model IDs**: Bedrock uses fully-qualified inference-profile IDs. The `us.` / `eu.` / `apac.` prefix is required for most newer Anthropic models. Use `aws bedrock list-inference-profiles --region <region>` to discover what your account can invoke.
|
|
171
|
+
- **`bedrock.profile`** is independent from operational profiles. The agent calls Bedrock under `bedrock.profile`, but each AWS CLI command it issues uses its own `--profile` (resolved from the user's prompt / history). This is the right pattern when one account holds Bedrock entitlements and other accounts hold workloads.
|
|
172
|
+
- If `bedrock.region` is unset, falls back to `AWS_REGION` / `AWS_DEFAULT_REGION` env vars.
|
|
173
|
+
|
|
174
|
+
### Prompt caching
|
|
175
|
+
|
|
176
|
+
`aca` sends the same system prompt on every step of every invocation — roughly 3,300 tokens of stable content. When `caching: true` (the default), this prefix is marked cacheable on providers that support it:
|
|
177
|
+
|
|
178
|
+
| Provider | Caching behavior |
|
|
179
|
+
|---|---|
|
|
180
|
+
| **Anthropic (direct)** | Cached via `cache_control: ephemeral`. Reads cost ~10% of normal input tokens. Writes cost ~125%. TTL ~5 minutes. |
|
|
181
|
+
| **Bedrock (Anthropic models)** | Cached via Bedrock's `cachePoint` API. Same economics as Anthropic-direct. Other Bedrock models (Nova, Llama) may or may not support caching depending on the underlying model. |
|
|
182
|
+
| **OpenAI** | Auto-caches any prompt over 1,024 tokens; the `caching` flag is ignored (and unnecessary). |
|
|
183
|
+
| **Google Gemini** | Caching API isn't wired up in this version. The `caching` flag is silently ignored. |
|
|
184
|
+
|
|
185
|
+
The token counts written to `usage.log` include cache hit/miss accounting where available:
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"promptTokens": 7914,
|
|
190
|
+
"completionTokens": 188,
|
|
191
|
+
"totalTokens": 8102,
|
|
192
|
+
"cacheReadTokens": 3305,
|
|
193
|
+
"cacheWriteTokens": 0
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Only the system prompt is cached. Tool definitions are part of the request body the provider re-tokenizes on every call — the AI SDK doesn't propagate tool-level cache markers in the Bedrock provider, so we can't extend the cache prefix that far in this version. The realistic cost reduction is therefore around 25-40% of the input token bill on warm-cache runs (the system prompt is ~3,300 of the ~7,000-9,000 input tokens a typical run sends).
|
|
198
|
+
|
|
199
|
+
Disable with `caching: false` if you run `aca` rarely (once an hour or less), since first-call cache writes cost slightly more than uncached prompts.
|
|
200
|
+
|
|
201
|
+
### Bash scripts: execute or save
|
|
202
|
+
|
|
203
|
+
When the agent generates a bash script (e.g. for org-wide queries), `aca` shows the full script and offers a three-way choice:
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
What would you like to do with this script?
|
|
207
|
+
❯ Execute now
|
|
208
|
+
Save to disk (/home/me/.local/share/aws-cli-agent/scripts/2026-05-14_19-12-44_list-aurora.sh)
|
|
209
|
+
Cancel
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- **Execute** — write to temp, run, audit, delete.
|
|
213
|
+
- **Save** — write to `scriptFolder` (default `$XDG_DATA_HOME/aws-cli-agent/scripts`) with mode 0700. The full path is shown both in the prompt and in stdout after the run.
|
|
214
|
+
- **Cancel** — nothing executed, nothing saved.
|
|
215
|
+
|
|
216
|
+
The prompt is **always** shown for scripts, even when `autoApprove.all` is on. Scripts are arbitrary code with shell-level capability — the auto-approve switch deliberately doesn't apply to them. `autoApprove` still affects individual AWS CLI commands as documented above.
|
|
217
|
+
|
|
218
|
+
## CLI options
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
aca [options] [request...]
|
|
222
|
+
|
|
223
|
+
Options:
|
|
224
|
+
-v, --verbose echo agent reasoning to the console as it runs
|
|
225
|
+
--log-level <level> override logging.level for this run:
|
|
226
|
+
silent | error | warn | info | debug | trace
|
|
227
|
+
--auto-approve auto-approve all commands and scripts (dangerous)
|
|
228
|
+
--profile <name> hint the agent to use this AWS profile
|
|
229
|
+
--region <name> override defaultRegion for this run
|
|
230
|
+
-i, --interactive force AWS CLI commands to inherit your terminal
|
|
231
|
+
(for shells, port-forwards, log tails — common
|
|
232
|
+
patterns auto-detect; this is the manual override)
|
|
233
|
+
|
|
234
|
+
Commands:
|
|
235
|
+
run <request...> (default) execute a natural-language request
|
|
236
|
+
config print path to config file (creates defaults if missing)
|
|
237
|
+
history [-n <count>] print recent history entries
|
|
238
|
+
paths print paths used by aws-cli-agent
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Interactive prompting
|
|
242
|
+
|
|
243
|
+
The agent can ask you questions mid-reasoning when it's missing information.
|
|
244
|
+
You'll see prompts like:
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
? Agent needs input:
|
|
248
|
+
? Which profile? (Use arrow keys)
|
|
249
|
+
❯ prod-us-east-1
|
|
250
|
+
staging-us-east-1
|
|
251
|
+
dev-eu-west-1
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Four question kinds are supported:
|
|
255
|
+
|
|
256
|
+
- **choice** — pick one from a finite list (used for profiles, buckets,
|
|
257
|
+
matched resources). Arrow keys + Enter.
|
|
258
|
+
- **text** — free-form input, optionally with a default value.
|
|
259
|
+
- **confirm** — yes/no decision before risky actions.
|
|
260
|
+
- **secret** — hidden input for short secrets like MFA codes. Long-lived AWS
|
|
261
|
+
credentials never come through here; those come from your AWS profile.
|
|
262
|
+
|
|
263
|
+
For requests that need multiple values up front (e.g. source profile +
|
|
264
|
+
target profile + region for a cross-account copy), the agent asks them in
|
|
265
|
+
sequence as one batched conversation rather than across multiple model
|
|
266
|
+
calls.
|
|
267
|
+
|
|
268
|
+
The agent is instructed to **ask rather than guess** whenever a required
|
|
269
|
+
value is unclear. If you find it guessing wrong on your particular workflow,
|
|
270
|
+
make the request more specific or check `~/.local/state/aws-cli-agent/reasoning.log`
|
|
271
|
+
to see where it inferred the value from.
|
|
272
|
+
|
|
273
|
+
## Where state lives (XDG)
|
|
274
|
+
|
|
275
|
+
Two directories under XDG. State (logs, history) is co-located in one place; user-curated data (saved scripts) lives separately:
|
|
276
|
+
|
|
277
|
+
| Purpose | Path |
|
|
278
|
+
|---|---|
|
|
279
|
+
| Config | `$XDG_CONFIG_HOME/aws-cli-agent/config.json` |
|
|
280
|
+
| State (history, all logs) | `$XDG_STATE_HOME/aws-cli-agent/` |
|
|
281
|
+
| Saved scripts (default) | `$XDG_DATA_HOME/aws-cli-agent/scripts/` |
|
|
282
|
+
|
|
283
|
+
State directory contents:
|
|
284
|
+
```
|
|
285
|
+
~/.local/state/aws-cli-agent/
|
|
286
|
+
├── history.jsonl # past requests, for context
|
|
287
|
+
├── general.log # general operational log
|
|
288
|
+
├── audit.log # JSONL audit trail of every executed command
|
|
289
|
+
├── reasoning.log # text log of agent reasoning per step
|
|
290
|
+
└── usage.log # JSONL token totals per invocation
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Run `aca paths` to see the actual resolved locations on your system.
|
|
294
|
+
|
|
295
|
+
## Architecture
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
your machine
|
|
299
|
+
┌────────────────────────────────────────────────────────┐
|
|
300
|
+
│ │
|
|
301
|
+
│ you type a request in the terminal │
|
|
302
|
+
│ │ │
|
|
303
|
+
│ ▼ │
|
|
304
|
+
│ ┌──────────────────────┐ │
|
|
305
|
+
│ │ agent loop │ │
|
|
306
|
+
│ │ (Vercel AI SDK, │ │
|
|
307
|
+
│ │ streamText) │ │
|
|
308
|
+
│ └──────────┬───────────┘ │
|
|
309
|
+
│ │ │
|
|
310
|
+
│ selects a tool to call: │
|
|
311
|
+
│ - query_history │
|
|
312
|
+
│ - list_aws_profiles │
|
|
313
|
+
│ - prompt_user / prompt_user_multi │
|
|
314
|
+
│ - execute_aws_command │
|
|
315
|
+
│ - execute_bash_script │
|
|
316
|
+
│ │ │
|
|
317
|
+
│ ▼ │
|
|
318
|
+
│ ┌──────────────────────┐ │
|
|
319
|
+
│ │ approval gate │ │
|
|
320
|
+
│ │ (skipped if │ │
|
|
321
|
+
│ │ auto-approved or │ │
|
|
322
|
+
│ │ read-only tool) │ │
|
|
323
|
+
│ └──────────┬───────────┘ │
|
|
324
|
+
│ │ y │
|
|
325
|
+
│ ▼ │
|
|
326
|
+
│ ┌──────────────────────┐ │
|
|
327
|
+
│ │ aws CLI subprocess │ ◀── credentials │
|
|
328
|
+
│ │ │ from ~/.aws │
|
|
329
|
+
│ └──────────┬───────────┘ (profiles, │
|
|
330
|
+
│ │ SSO cache) │
|
|
331
|
+
│ ▼ │
|
|
332
|
+
│ stdout printed verbatim to terminal │
|
|
333
|
+
│ │
|
|
334
|
+
│ │
|
|
335
|
+
│ state on disk (XDG paths): │
|
|
336
|
+
│ config.json history.jsonl │
|
|
337
|
+
│ general.log audit.log │
|
|
338
|
+
│ reasoning.log usage.log │
|
|
339
|
+
│ saved scripts/ │
|
|
340
|
+
│ │
|
|
341
|
+
└─────────────────────┬──────────────────────────────────┘
|
|
342
|
+
│
|
|
343
|
+
messages + tool definitions (HTTPS)
|
|
344
|
+
│
|
|
345
|
+
▼
|
|
346
|
+
┌────────────────────────────────────────────────────────┐
|
|
347
|
+
│ LLM provider │
|
|
348
|
+
│ Anthropic · OpenAI · Google · Bedrock │
|
|
349
|
+
│ prompt cache (~5 min TTL) — system prompt only │
|
|
350
|
+
└────────────────────────────────────────────────────────┘
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
**The agent loop.** `aca` uses the Vercel AI SDK's `streamText` to run a multi-step reasoning loop, hard-capped by `maxSteps`. Each step: the model emits reasoning text (streamed live to the console when `verbose` is on), decides on a tool call, the host runs the tool (with approval if needed), and the result feeds back into the next step's prompt. The loop terminates when the model emits a final text response with no tool call, or when `maxSteps` is reached.
|
|
354
|
+
|
|
355
|
+
**Stateless server-side, with one caveat.** Each call to the LLM provider includes the full conversation history — system prompt, tool definitions, original user request, every prior step's reasoning and tool results. The provider doesn't retain conversation state between calls. **One exception:** when prompt caching is enabled, the provider temporarily stores the cached prefix (the system prompt, ~3,300 tokens) for ~5 minutes so subsequent calls within that window can replay it cheaply. Nothing else is retained.
|
|
356
|
+
|
|
357
|
+
**Local-only state.** Everything `aca` remembers is on your machine. History (`history.jsonl`), logs (`general.log`, `audit.log`, `reasoning.log`, `usage.log`), and config all live under XDG paths. Saved scripts go to `$XDG_DATA_HOME/aws-cli-agent/scripts/` by default. No remote backend, no telemetry.
|
|
358
|
+
|
|
359
|
+
**Tools as the safety boundary.** The model can only affect the outside world through tools. Two of them — `execute_aws_command` and `execute_bash_script` — are the destructive paths. Both prompt for user approval by default; read-only AWS CLI commands may auto-approve depending on `autoApprove.readOnly`; bash scripts **always** prompt regardless of auto-approve settings.
|
|
360
|
+
|
|
361
|
+
**stdout vs. stderr discipline.** `aca` reserves stdout exclusively for the AWS CLI's verbatim output. Everything `aca` itself emits — approval prompts, reasoning lines, agent narrative, error summaries, status footers — goes to stderr. The discipline means you can pipe `aca` like the underlying `aws` command:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
aca "list buckets in my-staging" | jq -r '.[].Name' # works
|
|
365
|
+
aca "list ec2 instances" > instances.json # works
|
|
366
|
+
aca ... 2>/dev/null # silence the agent's chrome
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Without this rule, the approval prompts and reasoning lines would land in the next process's stdin and corrupt downstream tools. With it, the agent is invisible to pipelines — exactly as if you'd run the `aws` command directly.
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
MIT
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Logger } from './logger.js';
|
|
2
|
+
import type { Config } from './config.js';
|
|
3
|
+
import type { History } from './history.js';
|
|
4
|
+
import type { AuditLogger } from './audit.js';
|
|
5
|
+
import type { ReasoningLogger } from './reasoning.js';
|
|
6
|
+
import type { UsageLogger } from './usage.js';
|
|
7
|
+
export type RunResult = {
|
|
8
|
+
/** Model's free-form text. Useful only for the "no command ran" error path. */
|
|
9
|
+
text: string;
|
|
10
|
+
steps: number;
|
|
11
|
+
/**
|
|
12
|
+
* All commands the agent attempted, including ones the user declined or
|
|
13
|
+
* cancelled. Used for the history log (the trail is more useful with all
|
|
14
|
+
* attempts visible). For the user-facing "ran N commands" footer, use
|
|
15
|
+
* `executedCommandCount` instead.
|
|
16
|
+
*/
|
|
17
|
+
commands: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Count of commands that actually ran (executed and produced an exit
|
|
20
|
+
* code, whether 0 or non-zero). Excludes declines/cancellations so the
|
|
21
|
+
* footer doesn't claim "ran 2 commands" when one was just refused.
|
|
22
|
+
*/
|
|
23
|
+
executedCommandCount: number;
|
|
24
|
+
profile: string | null;
|
|
25
|
+
/** The verbatim stdout of the last execute_* call when it succeeded, or null. */
|
|
26
|
+
finalOutput: string | null;
|
|
27
|
+
/** The verbatim stderr of the last execute_* call if it failed, or null. */
|
|
28
|
+
finalError: string | null;
|
|
29
|
+
/** Did the last execute_* call run successfully? */
|
|
30
|
+
ranCommand: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare function runAgent(opts: {
|
|
33
|
+
input: string;
|
|
34
|
+
config: Config;
|
|
35
|
+
logger: Logger;
|
|
36
|
+
history: History;
|
|
37
|
+
audit: AuditLogger;
|
|
38
|
+
reasoning: ReasoningLogger;
|
|
39
|
+
usage: UsageLogger;
|
|
40
|
+
}): Promise<RunResult>;
|