@action-llama/action-llama 0.4.12 → 0.5.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/AGENTS.md ADDED
@@ -0,0 +1,420 @@
1
+ # Action Llama Project
2
+
3
+ This is an Action Llama project. It runs automated development agents triggered by cron schedules or webhooks.
4
+
5
+ ## Project Structure
6
+
7
+ Each agent is a directory containing:
8
+
9
+ - `agent-config.toml` — credentials, model, schedule, webhooks, params
10
+ - `PLAYBOOK.md` — the system prompt (playbook) that defines what the agent does
11
+ - `Dockerfile` (optional) — custom Docker image extending the base `al-agent:latest` (e.g. to install extra tools like `gh`)
12
+
13
+ ## Creating an Agent
14
+
15
+ 1. Create a directory for your agent (e.g. `my-agent/`)
16
+ 2. Add `agent-config.toml` with credentials, model config, and a schedule or webhook trigger
17
+ 3. Add `PLAYBOOK.md` with the playbook — step-by-step instructions the LLM follows each run
18
+ 4. If running in Docker mode and your agent needs tools beyond what the base image provides (git, curl, openssh-client, node), add a `Dockerfile` — see Docker Mode section below
19
+ 5. Verify with `npx al status`
20
+ 6. Run with `npx al start`
21
+
22
+ ## Credential Reference
23
+
24
+ Credentials are managed by the user via `al doctor` or `al creds add` and stored in `~/.action-llama-credentials/<type>/<instance>/<field>`. Reference them in `credentials` arrays as `"type:instance"` (e.g. `"github_token:default"`). The `:default` instance suffix can be omitted.
25
+
26
+ | Type | What it is | Fields | Runtime injection | What it enables |
27
+ |------|-----------|--------|-------------------|----------------|
28
+ | `anthropic_key` | Anthropic API key or OAuth token | `token` | Read directly by the agent SDK (not an env var) | LLM access (Anthropic models) |
29
+ | `openai_key` | OpenAI API key | `token` | Read directly by the agent SDK | LLM access (OpenAI models) |
30
+ | `groq_key` | Groq API key | `token` | Read directly by the agent SDK | LLM access (Groq models) |
31
+ | `google_key` | Google Gemini API key | `token` | Read directly by the agent SDK | LLM access (Gemini models) |
32
+ | `xai_key` | xAI API key | `token` | Read directly by the agent SDK | LLM access (Grok models) |
33
+ | `mistral_key` | Mistral API key | `token` | Read directly by the agent SDK | LLM access (Mistral models) |
34
+ | `openrouter_key` | OpenRouter API key | `token` | Read directly by the agent SDK | LLM access (OpenRouter multi-provider) |
35
+ | `custom_key` | Custom provider API key | `token` | Read directly by the agent SDK | LLM access (custom providers) |
36
+ | `github_token` | GitHub PAT (repo + workflow scopes) | `token` | `GITHUB_TOKEN` and `GH_TOKEN` env vars | `gh` CLI, `git` over HTTPS, GitHub API |
37
+ | `git_ssh` | SSH private key + git identity | `id_rsa`, `username`, `email` | SSH key mounted as file; `GIT_SSH_COMMAND` configured automatically; `GIT_AUTHOR_NAME`/`GIT_AUTHOR_EMAIL`/`GIT_COMMITTER_NAME`/`GIT_COMMITTER_EMAIL` set from `username`/`email` | `git clone`/`push` over SSH — **required for pushing to repos** |
38
+ | `sentry_token` | Sentry auth token | `token` | `SENTRY_AUTH_TOKEN` env var | Sentry API via `curl` |
39
+ | `github_webhook_secret` | Shared HMAC secret | `secret` | Used by gateway only (not injected into agents) | Validates GitHub webhook payloads |
40
+ | `sentry_client_secret` | Sentry client secret | `secret` | Used by gateway only (not injected into agents) | Validates Sentry webhook payloads |
41
+
42
+ **IMPORTANT:** Agents MUST NEVER ask users for credentials directly (API keys, tokens, passwords, etc.). Agents MUST NEVER run `al doctor` or interact with the credential system on behalf of the user. If a credential is missing at runtime, the agent should report the error and stop — the user will run `al doctor` and `al start` themselves.
43
+
44
+ ## Runtime Context
45
+
46
+ Every agent prompt has these XML blocks injected automatically at runtime:
47
+
48
+ ### `<agent-config>`
49
+
50
+ JSON object containing the agent's custom `[params]` from `agent-config.toml`. Example:
51
+
52
+ ```json
53
+ {"repos":["acme/app"],"triggerLabel":"agent","assignee":"bot-user"}
54
+ ```
55
+
56
+ (In this example, `repos` is a custom param defined in `[params]` — not a built-in field.)
57
+
58
+ ### `<credential-context>`
59
+
60
+ Lists which env vars and tools are available based on the agent's `credentials` array. Includes anti-exfiltration policy. The agent can rely on env vars like `GITHUB_TOKEN`, `GH_TOKEN`, `SENTRY_AUTH_TOKEN` being already set — it does NOT need to set them.
61
+
62
+ ### `<webhook-trigger>` (webhook runs only)
63
+
64
+ JSON object with the webhook event details. Only present when the agent is triggered by a webhook (not on scheduled runs). Schema:
65
+
66
+ ```json
67
+ {
68
+ "source": "github",
69
+ "event": "issues",
70
+ "action": "labeled",
71
+ "repo": "acme/app",
72
+ "number": 42,
73
+ "title": "Add dark mode",
74
+ "body": "Issue description...",
75
+ "url": "https://github.com/acme/app/issues/42",
76
+ "author": "user",
77
+ "assignee": "bot-user",
78
+ "labels": ["agent"],
79
+ "branch": null,
80
+ "comment": null,
81
+ "sender": "user",
82
+ "timestamp": "2025-01-15T10:30:00Z"
83
+ }
84
+ ```
85
+
86
+ ### `<agent-trigger>` (agent-triggered runs only)
87
+
88
+ JSON object with the source agent name and context. Only present when the agent was triggered by another agent via a `[TRIGGER]` signal. Schema:
89
+
90
+ ```json
91
+ {
92
+ "source": "dev",
93
+ "context": "I just opened PR #42 on acme/app. Please review it."
94
+ }
95
+ ```
96
+
97
+ ### Triggering other agents
98
+
99
+ An agent can trigger another agent by including a `[TRIGGER]` block in its output:
100
+
101
+ ```
102
+ [TRIGGER: reviewer]
103
+ I just opened PR #42. Please review it.
104
+ URL: https://github.com/acme/app/pull/42
105
+ [/TRIGGER]
106
+ ```
107
+
108
+ The scheduler will run the target agent with the context injected as an `<agent-trigger>` block. Rules:
109
+ - An agent cannot trigger itself
110
+ - If the target is busy or does not exist, the trigger is skipped
111
+ - Trigger chains are limited by `maxTriggerDepth` in `config.toml` (default: 3)
112
+
113
+ ## Webhook Reference
114
+
115
+ ### How webhooks work
116
+
117
+ 1. Webhook sources are defined in the project's `config.toml` under `[webhooks.<name>]` with a provider type and optional credential
118
+ 2. The gateway receives an HTTP POST at `/webhooks/github` or `/webhooks/sentry`
119
+ 3. The payload is validated using the credential's HMAC secret (e.g. `github_webhook_secret` for GitHub)
120
+ 4. The gateway matches the event against all agents' `[[webhooks]]` entries (AND logic — all specified fields must match; omitted fields are not checked)
121
+ 5. Matching agents are triggered with a `<webhook-trigger>` block injected into their prompt
122
+
123
+ ### Defining webhook sources in `config.toml`
124
+
125
+ Webhook sources are defined once at the project level. Each source has a name, provider type, and optional credential instance for HMAC validation:
126
+
127
+ ```toml
128
+ [webhooks.my-github]
129
+ type = "github"
130
+ credential = "MyOrg" # credential instance name (github_webhook_secret:MyOrg)
131
+
132
+ [webhooks.my-sentry]
133
+ type = "sentry"
134
+ credential = "SentryProd" # credential instance name (sentry_client_secret:SentryProd)
135
+
136
+ [webhooks.unsigned-github]
137
+ type = "github" # no credential — accepts unsigned webhooks
138
+ ```
139
+
140
+ ### Agent webhook filters
141
+
142
+ Agents reference a webhook source by name and add filters:
143
+
144
+ | Field | Type | Description |
145
+ |-------|------|-------------|
146
+ | `source` | string | Name of a webhook source from `config.toml` (required) |
147
+ | `repos` | string[] | Filter to specific repos (owner/repo format) |
148
+ | `events` | string[] | Event types: `issues`, `pull_request`, `push`, `issue_comment`, etc. |
149
+ | `actions` | string[] | Event actions: `opened`, `labeled`, `closed`, `synchronize`, etc. |
150
+ | `labels` | string[] | Only trigger when the issue/PR has ALL of these labels |
151
+ | `assignee` | string | Only trigger when assigned to this user |
152
+ | `author` | string | Only trigger for events by this author |
153
+ | `branches` | string[] | Only trigger for pushes/PRs on these branches |
154
+ | `resources` | string[] | Sentry: `error`, `event_alert`, `metric_alert`, `issue`, `comment` |
155
+
156
+ ### GitHub webhook setup
157
+
158
+ In your GitHub repo settings, add a webhook:
159
+ - **Payload URL:** `http://<your-host>:8080/webhooks/github`
160
+ - **Content type:** `application/json`
161
+ - **Secret:** the same secret stored as the `github_webhook_secret` credential
162
+
163
+ ### TOML syntax for webhooks
164
+
165
+ Each webhook is a separate `[[webhooks]]` block (double brackets = array of tables). The `source` field references a webhook source defined in `config.toml`:
166
+
167
+ ```toml
168
+ # Each [[webhooks]] references a source from config.toml
169
+ [[webhooks]]
170
+ source = "my-github"
171
+ events = ["issues"]
172
+ actions = ["labeled"]
173
+ labels = ["agent"]
174
+
175
+ [[webhooks]]
176
+ source = "my-github"
177
+ events = ["pull_request"]
178
+ # repos = ["my-org/specific-repo"] # optional — filter to specific repos
179
+
180
+ [[webhooks]]
181
+ source = "my-sentry"
182
+ resources = ["error", "event_alert"]
183
+ ```
184
+
185
+ ## `agent-config.toml` Complete Reference
186
+
187
+ The config file uses TOML syntax. The agent name is derived from the directory name — do not include it in the config.
188
+
189
+ ### Minimal example (webhook-driven)
190
+
191
+ ```toml
192
+ credentials = ["github_token:default", "git_ssh:default"]
193
+
194
+ [[webhooks]]
195
+ source = "my-github"
196
+ events = ["issues"]
197
+ actions = ["labeled"]
198
+ labels = ["agent"]
199
+
200
+ [params]
201
+ triggerLabel = "agent"
202
+ assignee = "your-github-username"
203
+ ```
204
+
205
+ The `[model]` section is **optional** — agents inherit the default model from the project's `config.toml`. Only add `[model]` to an agent config if you want to override the default (e.g. use a different model or thinking level for that specific agent).
206
+
207
+ ### Full example (webhooks + params + model override + optional schedule)
208
+
209
+ ```toml
210
+ credentials = ["github_token:default", "git_ssh:default", "sentry_token:default"]
211
+ # schedule = "*/5 * * * *" # Optional: for scheduled polling in addition to webhooks
212
+
213
+ # Optional: override the project default model for this agent
214
+ [model]
215
+ provider = "anthropic"
216
+ model = "claude-sonnet-4-20250514"
217
+ thinkingLevel = "medium"
218
+ authType = "api_key"
219
+
220
+ [[webhooks]]
221
+ source = "my-github"
222
+ events = ["issues"]
223
+ actions = ["labeled"]
224
+ labels = ["agent"]
225
+
226
+ [[webhooks]]
227
+ source = "my-sentry"
228
+ resources = ["error", "event_alert"]
229
+
230
+ [params]
231
+ triggerLabel = "agent"
232
+ assignee = "bot-user"
233
+ sentryOrg = "acme"
234
+ sentryProjects = ["web-app", "api"]
235
+ # repos = ["fallback/repo"] # Optional: only needed if using schedule without webhook repo context
236
+ ```
237
+
238
+ ### Field reference
239
+
240
+ | Field | Type | Required | Description |
241
+ |-------|------|----------|-------------|
242
+ | `credentials` | string[] | Yes | Credential refs as `"type:instance"` (see Credential Reference above) |
243
+ | `schedule` | string | No* | Cron expression (e.g. "*/5 * * * *") |
244
+ | `model` | table | No | LLM model config — omit to inherit from project `config.toml` |
245
+ | `model.provider` | string | Yes* | "anthropic", "openai", "groq", "google", "xai", "mistral", "openrouter", or "custom" |
246
+ | `model.model` | string | Yes* | Model ID (e.g. "claude-sonnet-4-20250514") |
247
+ | `model.thinkingLevel` | string | No | off \| minimal \| low \| medium \| high \| xhigh (only relevant for models with reasoning support, e.g. Claude Sonnet/Opus; omit for other models) |
248
+ | `model.authType` | string | Yes* | api_key \| oauth_token \| pi_auth |
249
+ | `webhooks[].source` | string | Yes | Name of a webhook source from `config.toml` |
250
+ | `webhooks[].repos` | string[] | No | Filter to specific repos |
251
+ | `webhooks[].events` | string[] | No | GitHub event types: issues, pull_request, push |
252
+ | `webhooks[].actions` | string[] | No | GitHub actions: opened, labeled, closed |
253
+ | `webhooks[].labels` | string[] | No | Only trigger for issues/PRs with these labels |
254
+ | `webhooks[].resources` | string[] | No | Sentry resources: error, event_alert, metric_alert, issue, comment |
255
+ | `params.*` | any | No | Custom key-value pairs injected into the prompt |
256
+
257
+ *At least one of `schedule` or `webhooks` is required. *Required within `[model]` if the agent defines its own model block.
258
+
259
+ ### TOML syntax reminders
260
+
261
+ - Strings: `key = "value"`
262
+ - Arrays: `key = ["a", "b"]`
263
+ - Tables (objects): `[tableName]` on its own line, followed by key-value pairs
264
+ - Array of tables: `[[arrayName]]` on its own line — each block is one entry in the array
265
+ - Comments: `# comment`
266
+
267
+ ## Example Playbook
268
+
269
+ **Agent playbooks must be detailed and prescriptive with step-by-step commands. Copy this example and customize rather than writing from scratch.**
270
+
271
+ The following is a complete, working PLAYBOOK.md for a developer agent. Use it as a template for all new agents:
272
+
273
+ ```markdown
274
+ # Developer Agent
275
+
276
+ You are a developer agent. Your job is to pick up GitHub issues and implement the requested changes.
277
+
278
+ Your configuration is in the \`<agent-config>\` block at the start of your prompt.
279
+ Use those values for triggerLabel and assignee.
280
+
281
+ \`GITHUB_TOKEN\` is already set in your environment. Use \`gh\` CLI and \`git\` directly.
282
+ (Note: \`gh\` is not in the base Docker image — this agent needs a custom Dockerfile that installs it. See Docker Mode section.)
283
+
284
+ **You MUST complete ALL steps below.** Do not stop after reading the issue — you must implement, commit, push, and open a PR.
285
+
286
+ ## Repository Context
287
+
288
+ This agent infers the repository from the issue context instead of using hardcoded configuration.
289
+
290
+ **For webhook triggers:** The repository is extracted from the \`<webhook-trigger>\` block's \`repo\` field.
291
+
292
+ **For scheduled triggers:** The agent uses the \`repos\` parameter from \`<agent-config>\` as a fallback to check for work across configured repositories.
293
+
294
+ ## Setup — ensure labels exist
295
+
296
+ Before looking for work, ensure the required labels exist on the target repo. The repo is determined as follows:
297
+
298
+ - **Webhook mode:** Extract repo from \`<webhook-trigger>\` JSON block
299
+ - **Scheduled mode:** Use repos from \`<agent-config>\` params
300
+
301
+ Run the following (these are idempotent — they succeed silently if the label already exists):
302
+
303
+ \`\`\`
304
+ # For webhook triggers, use the repo from webhook context
305
+ # For scheduled triggers, iterate through configured repos
306
+ gh label create "<triggerLabel>" --repo <determined-repo> --color 0E8A16 --description "Trigger label for dev agent" --force
307
+ gh label create "in-progress" --repo <determined-repo> --color FBCA04 --description "Agent is working on this" --force
308
+ gh label create "agent-completed" --repo <determined-repo> --color 1D76DB --description "Agent has opened a PR" --force
309
+ \`\`\`
310
+
311
+ ## Finding work
312
+
313
+ **Webhook trigger:** When you receive a \`<webhook-trigger>\` block, extract the repository from the \`repo\` field and the issue details from the trigger context. Check the issue's labels and assignee against your \`triggerLabel\` and \`assignee\` params. If the issue matches (has your trigger label and is assigned to your assignee), proceed with implementation using the extracted repository. If it does not match, respond \`[SILENT]\` and stop.
314
+
315
+ **Scheduled trigger:** If \`repos\` parameter exists in \`<agent-config>\`, run \`gh issue list --repo <repo> --label <triggerLabel> --assignee <assignee> --state open --json number,title,body,comments,labels --limit 1\` for each configured repo. If no work found in any repo, respond \`[SILENT]\` and stop.
316
+
317
+ ## Workflow
318
+
319
+ **Important:** First determine the target repository from the trigger context (webhook \`repo\` field or configured \`repos\` parameter).
320
+
321
+ 1. **Claim the issue** — run \`gh issue edit <number> --repo <determined-repo> --add-label in-progress\` to mark it as claimed.
322
+
323
+ 2. **Clone and branch** — run \`git clone git@github.com:<determined-repo>.git /workspace/repo && cd /workspace/repo && git checkout -b agent/<number>\`.
324
+
325
+ 3. **Understand the issue** — read the title, body, and comments. Note file paths, acceptance criteria, and linked issues.
326
+
327
+ 4. **Read project conventions** — in the repo, read \`PLAYBOOK.md\`, \`CLAUDE.md\`, \`CONTRIBUTING.md\`, and \`README.md\` if they exist. Follow any conventions found there.
328
+
329
+ 5. **Implement changes** — work in the repo. Make the minimum necessary changes, follow existing patterns, and write or update tests if the project has a test suite.
330
+
331
+ 6. **Validate** — run the project's test suite and linters (e.g., \`npm test\`). Fix failures before proceeding.
332
+
333
+ 7. **Commit** — \`git add -A && git commit -m "fix: <description> (closes #<number>)"\`
334
+
335
+ 8. **Push** — \`git push -u origin agent/<number>\`
336
+
337
+ 9. **Create a PR** — run \`gh pr create --repo <determined-repo> --head agent/<number> --base main --title "<title>" --body "Closes #<number>\n\n<description>"\`.
338
+
339
+ 10. **Comment on the issue** — run \`gh issue comment <number> --repo <determined-repo> --body "PR created: <pr_url>"\`.
340
+
341
+ 11. **Mark done** — run \`gh issue edit <number> --repo <determined-repo> --remove-label in-progress --add-label agent-completed\`.
342
+
343
+ ## Rules
344
+
345
+ - Work on exactly ONE issue per run
346
+ - Never modify files outside the repo directory
347
+ - **You MUST complete steps 7-11.** Do not stop early.
348
+ - If tests fail after 2 attempts, create the PR anyway with a note about failing tests
349
+ - If the issue is unclear, comment asking for clarification and stop
350
+ ```
351
+
352
+ ## Docker Mode
353
+
354
+ Docker container isolation is enabled by default. Each agent run launches an isolated container with a read-only root filesystem, dropped capabilities, non-root user, and resource limits. Use `--no-docker` to disable it for development.
355
+
356
+ ### Base image
357
+
358
+ The base image (`al-agent:latest`) is built automatically on first run. It includes Node.js, git, curl, openssh-client, and ca-certificates — the minimum needed for any agent.
359
+
360
+ ### Custom agent images
361
+
362
+ If your agent needs extra tools (e.g. `gh` CLI, Python, `jq`), add a `Dockerfile` to the agent directory that extends the base image:
363
+
364
+ ```dockerfile
365
+ FROM al-agent:latest
366
+ USER root
367
+ RUN apt-get update && apt-get install -y --no-install-recommends gh && rm -rf /var/lib/apt/lists/*
368
+ USER node
369
+ ```
370
+
371
+ Agent images are built automatically on startup. If no `Dockerfile` is present, the agent uses the base image.
372
+
373
+ ### Container filesystem
374
+
375
+ | Path | Mode | Contents |
376
+ |------|------|----------|
377
+ | `/app` | read-only | Action Llama application + node_modules |
378
+ | `/credentials` | read-only | Mounted credential files (`/<type>/<instance>/<field>`) |
379
+ | `/workspace` | read-write (tmpfs, 2GB) | Working directory — repos are cloned here |
380
+ | `/tmp` | read-write (tmpfs, 512MB) | Temporary files |
381
+ | `/home/node` | read-write (tmpfs, 64MB) | User home — `.ssh/` for SSH keys |
382
+
383
+ ### Docker config options
384
+
385
+ | Key | Default | Description |
386
+ |-----|---------|-------------|
387
+ | `local.enabled` | `true` | Enable Docker container isolation |
388
+ | `local.image` | `"al-agent:latest"` | Base Docker image name |
389
+ | `local.memory` | `"4g"` | Memory limit per container |
390
+ | `local.cpus` | `2` | CPU limit per container |
391
+ | `local.timeout` | `3600` | Max container runtime in seconds |
392
+
393
+ ## Running Agents
394
+
395
+ Start all agents with `al start` (or `npx al start`). This starts the scheduler which runs all discovered agents on their configured schedules/webhooks. There is no per-agent start command — `al start` always starts the entire project.
396
+
397
+ ### Automatic re-runs
398
+
399
+ When a scheduled agent completes productive work (i.e. it does not respond with `[SILENT]`), the scheduler immediately re-runs it. This continues until the agent reports `[SILENT]` (no more work), hits an error, or reaches the `maxReruns` limit. This way an agent drains its work queue without waiting for the next cron tick.
400
+
401
+ Set `maxReruns` in `config.toml` to control the limit (default: 10):
402
+
403
+ ```toml
404
+ maxReruns = 5
405
+ maxTriggerDepth = 3 # max depth for agent-to-agent trigger chains (default: 3)
406
+ ```
407
+
408
+ Webhook-triggered and agent-triggered runs do not re-run — they respond to a single event.
409
+
410
+ ## Further Documentation
411
+
412
+ Full documentation is available on GitHub:
413
+
414
+ - [Creating Agents](https://github.com/Action-Llama/action-llama/blob/main/docs/creating-agents.md)
415
+ - [agent-config.toml Reference](https://github.com/Action-Llama/action-llama/blob/main/docs/agent-config-reference.md)
416
+ - [Credentials](https://github.com/Action-Llama/action-llama/blob/main/docs/credentials.md)
417
+ - [Webhooks](https://github.com/Action-Llama/action-llama/blob/main/docs/webhooks.md)
418
+ - [Docker](https://github.com/Action-Llama/action-llama/blob/main/docs/docker.md) — custom Dockerfiles, standalone images, troubleshooting
419
+ - [CLI Commands](https://github.com/Action-Llama/action-llama/blob/main/docs/commands.md)
420
+ - [Example Agents](https://github.com/Action-Llama/action-llama/blob/main/docs/examples/dev-agent.md) — dev, reviewer, devops
@@ -1,2 +1,4 @@
1
1
  export declare function list(): Promise<void>;
2
+ export declare function add(ref: string): Promise<void>;
3
+ export declare function rm(ref: string): Promise<void>;
2
4
  //# sourceMappingURL=creds.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"creds.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/creds.ts"],"names":[],"mappings":"AAIA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuD1C"}
1
+ {"version":3,"file":"creds.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/creds.ts"],"names":[],"mappings":"AAOA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA+D1C;AAED,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBpD;AAED,wBAAsB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBnD"}
@@ -1,6 +1,9 @@
1
- import { readdirSync, statSync } from "fs";
1
+ import { readdirSync, statSync, rmSync } from "fs";
2
2
  import { resolve } from "path";
3
3
  import { CREDENTIALS_DIR } from "../../shared/paths.js";
4
+ import { resolveCredential, getBuiltinCredential, listBuiltinCredentialIds } from "../../credentials/registry.js";
5
+ import { promptCredential } from "../../credentials/prompter.js";
6
+ import { parseCredentialRef, credentialExists, writeCredentialFields, credentialDir } from "../../shared/credentials.js";
4
7
  export async function list() {
5
8
  let entries;
6
9
  try {
@@ -37,6 +40,11 @@ export async function list() {
37
40
  catch {
38
41
  continue;
39
42
  }
43
+ if (instances.length === 0)
44
+ continue;
45
+ const def = getBuiltinCredential(type);
46
+ const label = def ? def.label : type;
47
+ console.log(`\n ${label} (${type})`);
40
48
  for (const instance of instances.sort()) {
41
49
  const instanceDir = resolve(typeDir, instance);
42
50
  let fields;
@@ -55,8 +63,52 @@ export async function list() {
55
63
  }
56
64
  const ref = instance === "default" ? type : `${type}:${instance}`;
57
65
  const fieldList = fields.sort().join(", ");
58
- console.log(` ${ref} (${fieldList})`);
66
+ console.log(` ${ref} (${fieldList})`);
67
+ }
68
+ }
69
+ console.log();
70
+ }
71
+ export async function add(ref) {
72
+ const { type, instance } = parseCredentialRef(ref);
73
+ let def;
74
+ try {
75
+ def = resolveCredential(type);
76
+ }
77
+ catch {
78
+ const known = listBuiltinCredentialIds().join(", ");
79
+ console.error(`Unknown credential type "${type}". Known types:\n ${known}`);
80
+ process.exit(1);
81
+ }
82
+ if (credentialExists(type, instance)) {
83
+ console.log(`Credential "${ref}" already exists. Re-running setup to update it.\n`);
84
+ }
85
+ const result = await promptCredential(def, instance);
86
+ if (!result || Object.keys(result.values).length === 0) {
87
+ console.log("Aborted.");
88
+ return;
89
+ }
90
+ writeCredentialFields(type, instance, result.values);
91
+ console.log(`\nCredential "${ref}" saved.`);
92
+ }
93
+ export async function rm(ref) {
94
+ const { type, instance } = parseCredentialRef(ref);
95
+ if (!credentialExists(type, instance)) {
96
+ console.error(`Credential "${ref}" not found.`);
97
+ process.exit(1);
98
+ }
99
+ const dir = credentialDir(type, instance);
100
+ rmSync(dir, { recursive: true, force: true });
101
+ // Clean up empty type directory
102
+ const typeDir = resolve(CREDENTIALS_DIR, type);
103
+ try {
104
+ const remaining = readdirSync(typeDir);
105
+ if (remaining.length === 0) {
106
+ rmSync(typeDir, { recursive: true, force: true });
59
107
  }
60
108
  }
109
+ catch {
110
+ // Ignore — type dir may already be gone
111
+ }
112
+ console.log(`Credential "${ref}" removed.`);
61
113
  }
62
114
  //# sourceMappingURL=creds.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"creds.js","sourceRoot":"","sources":["../../../src/cli/commands/creds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,IAAI;IACxB,IAAI,OAAiB,CAAC;IACtB,IAAI,CAAC;QACH,OAAO,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;YAClD,IAAI,CAAC;gBACH,OAAO,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;YAC7D,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,2BAA2B,eAAe,EAAE,CAAC,CAAC;QAC1D,OAAO;IACT,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,2BAA2B,eAAe,EAAE,CAAC,CAAC;QAC1D,OAAO;IACT,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,OA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E,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAc1D,wBAAsB,OAAO,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuK5G;AAID,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9F"}
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/doctor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAc1D,wBAAsB,OAAO,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgL5G;AAID,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9F"}
@@ -3,7 +3,7 @@ import { existsSync } from "fs";
3
3
  import { confirm } from "@inquirer/prompts";
4
4
  import { execFileSync } from "child_process";
5
5
  import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
6
- import { IAMClient, CreateRoleCommand, PutRolePolicyCommand } from "@aws-sdk/client-iam";
6
+ import { IAMClient, CreateRoleCommand, PutRolePolicyCommand, GetRoleCommand } from "@aws-sdk/client-iam";
7
7
  import { discoverAgents, loadAgentConfig, loadGlobalConfig } from "../../shared/config.js";
8
8
  import { resolveCredential } from "../../credentials/registry.js";
9
9
  import { promptCredential } from "../../credentials/prompter.js";
@@ -29,17 +29,21 @@ export async function execute(opts) {
29
29
  }
30
30
  // Collect all credential refs from agents (including webhook secrets)
31
31
  const credentialRefs = new Set();
32
+ const globalConfig = loadGlobalConfig(projectPath);
33
+ const webhookSources = globalConfig.webhooks ?? {};
32
34
  for (const name of agents) {
33
35
  const config = loadAgentConfig(projectPath, name);
34
36
  for (const ref of config.credentials) {
35
37
  credentialRefs.add(ref);
36
38
  }
37
- // Derive webhook secret credential refs from triggers
39
+ // Derive webhook secret credential refs from global webhook sources
38
40
  for (const trigger of config.webhooks || []) {
39
- const credType = WEBHOOK_SECRET_TYPES[trigger.type];
40
- if (credType) {
41
- const instance = trigger.source || "default";
42
- credentialRefs.add(`${credType}:${instance}`);
41
+ const sourceConfig = webhookSources[trigger.source];
42
+ if (!sourceConfig)
43
+ continue;
44
+ const credType = WEBHOOK_SECRET_TYPES[sourceConfig.type];
45
+ if (credType && sourceConfig.credential) {
46
+ credentialRefs.add(`${credType}:${sourceConfig.credential}`);
43
47
  }
44
48
  }
45
49
  }
@@ -151,6 +155,11 @@ export async function execute(opts) {
151
155
  // Reconcile IAM
152
156
  console.log(`\nReconciling cloud IAM...`);
153
157
  await reconcileCloudIam(projectPath, cloudConfig);
158
+ // Validate IAM roles exist for ECS mode
159
+ if (cloudConfig.provider === "ecs") {
160
+ console.log(`\nValidating ECS IAM roles...`);
161
+ await validateEcsRoles(projectPath, cloudConfig);
162
+ }
154
163
  }
155
164
  }
156
165
  // --- Cloud IAM reconciliation ---
@@ -456,4 +465,51 @@ function listGsmFields(gcpProject, prefix, type, instance) {
456
465
  return [];
457
466
  }
458
467
  }
468
+ async function validateEcsRoles(projectPath, cloud) {
469
+ const { awsRegion } = cloud;
470
+ if (!awsRegion) {
471
+ throw new Error("cloud.awsRegion is required for ECS validation");
472
+ }
473
+ const agents = discoverAgents(projectPath);
474
+ if (agents.length === 0)
475
+ return;
476
+ const iamClient = new IAMClient({ region: awsRegion });
477
+ const missing = [];
478
+ for (const name of agents) {
479
+ const roleName = AWS_CONSTANTS.taskRoleName(name);
480
+ try {
481
+ await iamClient.send(new GetRoleCommand({ RoleName: roleName }));
482
+ console.log(` [ok] ${roleName}`);
483
+ }
484
+ catch (err) {
485
+ if (err.name === "NoSuchEntityException") {
486
+ missing.push(roleName);
487
+ console.log(` [MISSING] ${roleName}`);
488
+ }
489
+ else {
490
+ console.log(` [ERROR] ${roleName}: ${err.message}`);
491
+ }
492
+ }
493
+ }
494
+ if (missing.length > 0) {
495
+ console.log(`\n${missing.length} IAM task role(s) are missing.`);
496
+ console.log("These roles are automatically created when you run 'al doctor -c'.");
497
+ console.log("If they're still missing, you may need to create them manually:");
498
+ for (const role of missing) {
499
+ console.log(` aws iam create-role --role-name ${role} --assume-role-policy-document file://ecs-trust.json`);
500
+ }
501
+ console.log("\nECS task trust policy (save as ecs-trust.json):");
502
+ console.log(JSON.stringify({
503
+ Version: "2012-10-17",
504
+ Statement: [{
505
+ Effect: "Allow",
506
+ Principal: { Service: "ecs-tasks.amazonaws.com" },
507
+ Action: "sts:AssumeRole",
508
+ }],
509
+ }, null, 2));
510
+ }
511
+ else {
512
+ console.log(`All ${agents.length} IAM task role(s) exist.`);
513
+ }
514
+ }
459
515
  //# sourceMappingURL=doctor.js.map