Skip to content

Commit a55495d

Browse files
krokokobgagentcursoragent
authored
feat(cli): operator commands for repos, platform introspection, and day-2 ops (#378) (#385)
* feat(cli): add additional commands * feat(cli): add additional commands * feat(cli): address self review * fix(cli): redact secret ARN in repo JSON output + address review feedback MAJOR (PR #385 review): - Redact github_token_secret_arn in repo list/onboard/offboard --output json (repo show already redacted; the sibling JSON paths emitted raw rows) - Correct docs over-claim that 'all operator commands accept --output json' (github set-token/set-webhook-secret + admin invite/delete/reset have no --output; admin list-users does) across README + USER_GUIDE + mirrors Minor: - Command-level tests for repo list/show/onboard/offboard JSON redaction + wiring - Fix stale ./QUICK_START.md links (.md -> .mdx) in DEPLOYMENT/DEVELOPER guides and REPO_ONBOARDING design doc - Extract duplicated documentClient/lowLevelClient into dynamo-clients.ts - webhook test: best-effort --repo validation degrades to a warning when AWS context is unavailable (pure --api-url + --secret path needs no AWS access) 563 tests pass, lint clean, docs mirrors re-synced (idempotent). * fix(deps): bump pydantic-settings to 2.14.2 for GHSA-4xgf-cpjx-pc3j Constrain the transitive mcp dependency to the patched release so security:deps passes on PR #385. Co-authored-by: Cursor <cursoragent@cursor.com> * docs(cli): address re-review — ADR-017, onboarding doc, link fixes Reconcile REPO_ONBOARDING.md with the operator CLI write path and add ADR-017 documenting the trade-off and deferred audit trail. Fix remaining QUICK_START.md → .mdx references and reject backslash in Cognito email lookup filter guard (+2 tests). Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: bgagent <bgagent@noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b8a9ba2 commit a55495d

65 files changed

Lines changed: 8507 additions & 1559 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Describe what you intend to contribute. This avoids duplicate work and gives mai
1414

1515
### 2. Set up your environment
1616

17-
Follow the [Quick Start](./docs/guides/QUICK_START.md) to clone, install, and build the project. See the [Developer guide](./docs/guides/DEVELOPER_GUIDE.md) for local testing and the development workflow.
17+
Follow the [Quick Start](./docs/guides/QUICK_START.mdx) to clone, install, and build the project. See the [Developer guide](./docs/guides/DEVELOPER_GUIDE.md) for local testing and the development workflow.
1818

1919
Use **[AGENTS.md](./AGENTS.md)** to understand where to make changes (CDK vs CLI vs agent vs docs), which tests to extend, and common pitfalls (generated docs, mirrored API types, `mise` tasks).
2020

agent/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies = [
5252
[tool.uv]
5353
constraint-dependencies = [
5454
"pyjwt>=2.13.0", # PYSEC-2026-175/177/178/179 — transitive via mcp; remove when mcp bumps floor (#267)
55+
"pydantic-settings>=2.14.2", # GHSA-4xgf-cpjx-pc3j — transitive via mcp; remove when mcp bumps floor
5556
]
5657

5758
[tool.bandit]

agent/uv.lock

Lines changed: 768 additions & 765 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/README.md

Lines changed: 179 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,30 @@ node cli/lib/bin/bgagent.js
1919
After deploying the stack (`cd cdk && npx cdk deploy`), extract the outputs and configure the CLI:
2020

2121
```bash
22-
# 1. Extract stack outputs into environment variables
23-
STACK_NAME="backgroundagent-dev"
24-
API_URL=$(aws cloudformation describe-stacks --stack-name $STACK_NAME \
25-
--query 'Stacks[0].Outputs[?OutputKey==`ApiUrl`].OutputValue' --output text)
26-
USER_POOL_ID=$(aws cloudformation describe-stacks --stack-name $STACK_NAME \
27-
--query 'Stacks[0].Outputs[?OutputKey==`UserPoolId`].OutputValue' --output text)
28-
APP_CLIENT_ID=$(aws cloudformation describe-stacks --stack-name $STACK_NAME \
29-
--query 'Stacks[0].Outputs[?OutputKey==`AppClientId`].OutputValue' --output text)
30-
31-
# 2. Configure the CLI
32-
bgagent configure \
33-
--api-url "$API_URL" \
34-
--region us-east-1 \
35-
--user-pool-id "$USER_POOL_ID" \
36-
--client-id "$APP_CLIENT_ID"
22+
# 1. Print stack outputs (replaces manual aws cloudformation describe-stacks)
23+
bgagent platform outputs --stack-name backgroundagent-dev
24+
25+
# 2. Store the GitHub PAT (replaces aws secretsmanager put-secret-value)
26+
bgagent github set-token --stack-name backgroundagent-dev
27+
28+
# 3. Configure the CLI (reads ApiUrl, UserPoolId, AppClientId from the stack)
29+
bgagent configure --region us-east-1 --stack-name backgroundagent-dev
3730

38-
# 3. Log in with your Cognito credentials
31+
# Or pass fields explicitly / use --from-bundle from `admin invite-user`
32+
33+
# 4. Log in with your Cognito credentials
3934
bgagent login --username you@example.com
4035

41-
# 4. Submit a task
36+
# 5. Submit a task
4237
bgagent submit --repo owner/repo --issue 42
4338

44-
# 5. Check status
39+
# 6. Check status
4540
bgagent list
4641
bgagent status <task-id>
4742
```
4843

44+
Operator commands (`platform`, `repo`, `github set-token`) use **operator AWS credentials** directly — Cognito login is not required.
45+
4946
## Commands
5047

5148
### `bgagent configure`
@@ -54,12 +51,16 @@ Save API endpoint and Cognito settings to `~/.bgagent/config.json`.
5451

5552
```
5653
bgagent configure \
57-
--api-url <url> API Gateway base URL (required)
58-
--region <region> AWS region (required)
59-
--user-pool-id <id> Cognito User Pool ID (required)
60-
--client-id <id> Cognito App Client ID (required)
54+
--stack-name <name> Read ApiUrl, UserPoolId, AppClientId from CloudFormation
55+
--from-bundle <base64> All four fields from `bgagent admin invite-user`
56+
--api-url <url> API Gateway base URL (override or manual configure)
57+
--region <region> AWS region (required with --stack-name if unset in env)
58+
--user-pool-id <id> Cognito User Pool ID
59+
--client-id <id> Cognito App Client ID
6160
```
6261

62+
First-time configure needs all four core fields. The easiest paths are `--stack-name backgroundagent-dev --region …` (same outputs as `bgagent platform outputs`) or `--from-bundle` after `admin invite-user`. Individual flags override stack-derived values.
63+
6364
### `bgagent login`
6465

6566
Authenticate with Cognito and cache tokens locally.
@@ -165,6 +166,162 @@ bgagent webhook revoke <webhook-id> \
165166
--output <text|json> Output format (default: text)
166167
```
167168

169+
## Operator commands
170+
171+
These commands support day-2 operations using **operator AWS credentials** (IAM profile or environment). They read CloudFormation outputs, DynamoDB, and Secrets Manager directly — no Cognito login required. The read-only and introspection commands (`platform`, `repo`, `runtime`, `ops`, `webhook test`, `admin list-users`) support `--output json` for scripting; the credential-writing commands (`github set-token`/`set-webhook-secret`, `admin invite-user`/`delete-user`/`reset-password`) do not.
172+
173+
Shared flags:
174+
175+
| Flag | Description |
176+
|------|-------------|
177+
| `--region <region>` | AWS region (defaults to `bgagent configure` region or `AWS_REGION`) |
178+
| `--stack-name <name>` | CloudFormation stack name (default: `backgroundagent-dev`) |
179+
180+
### `bgagent platform outputs`
181+
182+
Print CloudFormation stack outputs (`ApiUrl`, `UserPoolId`, `AppClientId`, `GitHubTokenSecretArn`, etc.).
183+
184+
```
185+
bgagent platform outputs \
186+
--output <text|json> Output format (default: text)
187+
```
188+
189+
### `bgagent platform doctor`
190+
191+
Smoke-check deployed platform readiness: Task API reachable, Cognito pool/client valid, platform GitHub token populated, at least one active onboarded repo, Bedrock model visible.
192+
193+
```
194+
bgagent platform doctor \
195+
--output <text|json> Output format (default: text)
196+
```
197+
198+
Exits with code 1 when any check fails (warnings are acceptable).
199+
200+
### `bgagent repo list`
201+
202+
List repositories onboarded via Blueprint constructs (reads `RepoTable`).
203+
204+
```
205+
bgagent repo list \
206+
--status <active|removed> Filter by status
207+
--output <text|json> Output format (default: text)
208+
```
209+
210+
### `bgagent repo show <owner/repo>`
211+
212+
Show full `RepoConfig` for a repository. Secret ARNs are redacted. When no per-blueprint token is configured, the output shows that the repo uses the **platform default** GitHub PAT (`GitHubTokenSecretArn`), not an empty/missing token.
213+
214+
```
215+
bgagent repo show owner/repo \
216+
--output <text|json> Output format (default: text)
217+
```
218+
219+
### `bgagent repo onboard <owner/repo>`
220+
221+
Register or re-activate a repository in `RepoTable` without a CDK redeploy. With no overrides, tasks use the platform `RuntimeArn` and `GitHubTokenSecretArn` (IAM already granted at deploy). Custom `--runtime-arn` / `--token-secret-arn` values require matching `TaskOrchestrator` IAM via CDK — the command prints notes explaining this. Prefer CDK `Blueprint` constructs for durable lifecycle, Cedar policies, and egress validation.
222+
223+
```
224+
bgagent repo onboard owner/repo \
225+
--compute-type <agentcore|ecs> \
226+
--runtime-arn <arn> AgentCore runtime override (agentcore only) \
227+
--model <model-id> \
228+
--token-secret-arn <arn> \
229+
--max-turns <n> \
230+
--poll-interval <ms> Default agent poll interval in milliseconds \
231+
--output <text|json>
232+
```
233+
234+
### `bgagent repo offboard <owner/repo>`
235+
236+
Soft-delete a repository (`status=removed` + TTL), matching Blueprint delete semantics. An existing Blueprint will re-activate the repo on the next CDK deploy.
237+
238+
```
239+
bgagent repo offboard owner/repo \
240+
--output <text|json>
241+
```
242+
243+
### `bgagent runtime status`
244+
245+
Show **per-blueprint** effective compute substrate and runtime ARN (merged with platform `RuntimeArn`), then probe unique AgentCore runtimes via the control-plane API. ECS blueprints are listed separately — they use the platform ECS cluster/task definition, not per-repo `runtime_arn`.
246+
247+
```
248+
bgagent runtime status \
249+
--repo <owner/repo> Limit to one repository \
250+
--output <text|json>
251+
```
252+
253+
### `bgagent ops stuck-tasks`
254+
255+
List tasks in `SUBMITTED`, `HYDRATING`, or `AWAITING_APPROVAL` older than the stranded-task reconciler thresholds (defaults: 1200s / 7200s). Text output includes Cognito email plus username UUID.
256+
257+
```
258+
bgagent ops stuck-tasks \
259+
--stranded-timeout <seconds> \
260+
--approval-timeout <seconds> \
261+
--output <text|json>
262+
```
263+
264+
### `bgagent ops concurrency`
265+
266+
Compare `UserConcurrencyTable` counters with live active task counts per user. Resolves Cognito usernames to email (same as `bgagent admin list-users`).
267+
268+
```
269+
bgagent ops concurrency \
270+
--limit <n> Per-user limit (default: 3) \
271+
--output <text|json>
272+
```
273+
274+
### `bgagent webhook test <webhook-id>`
275+
276+
Send a signed sample payload to `POST /v1/webhooks/tasks` (creates a real task — cancel afterward if this was only a connectivity check).
277+
278+
```
279+
bgagent webhook test <webhook-id> \
280+
--secret <secret> From `webhook create` output \
281+
--fetch-secret Read secret from Secrets Manager (operator IAM) \
282+
--repo <owner/repo> Target repo (defaults to first active repo) \
283+
--api-url <url> Defaults to configure api_url or stack ApiUrl \
284+
--output <text|json>
285+
```
286+
287+
### `bgagent github set-token`
288+
289+
Store a GitHub personal access token in Secrets Manager (interactive masked prompt).
290+
291+
```
292+
bgagent github set-token \
293+
--repo <owner/repo> Target a blueprint's per-repo token secret (when configured)
294+
--secret-arn <arn> Write to an explicit Secrets Manager ARN
295+
--region <region> AWS region (defaults to configured region)
296+
--stack-name <name> CloudFormation stack name (default: backgroundagent-dev)
297+
```
298+
299+
With no flags, writes to the platform default `GitHubTokenSecretArn` stack output. When `--repo` is used, the CLI reads `github_token_secret_arn` from `RepoTable` if the Blueprint configured `credentials.githubTokenSecretArn`; otherwise it falls back to the platform default with a notice.
300+
301+
### `bgagent github webhook-info` / `set-webhook-secret`
302+
303+
Configure the preview-deploy screenshot pipeline webhook. See [Deploy preview screenshots guide](../docs/guides/DEPLOY_PREVIEW_SCREENSHOTS_GUIDE.md).
304+
305+
### `bgagent admin invite-user` / `list-users` / `delete-user` / `reset-password`
306+
307+
Manage Cognito users with operator AWS credentials (`cognito-idp:Admin*` on the deployment user pool). Works **before** `bgagent configure` when `--stack-name` is passed (reads `UserPoolId` from CloudFormation).
308+
309+
```
310+
bgagent admin invite-user <email> \
311+
--stack-name backgroundagent-dev \
312+
--password <pwd> # optional; auto-generated if omitted
313+
314+
bgagent admin list-users \
315+
--output <text|json>
316+
317+
bgagent admin delete-user <email>
318+
319+
bgagent admin reset-password <email> \
320+
--password <pwd> # optional; auto-generated if omitted
321+
```
322+
323+
`invite-user` creates the user, sets a permanent password, and writes credentials plus an optional configure bundle to `~/.bgagent/invites/<email>.txt` (mode 0600). Replaces Quick Start Step 5 raw `aws cognito-idp` commands.
324+
168325
## Output formats
169326

170327
**Text mode** (default) prints human-readable output:

cli/package.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/bin/bgagent.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ import { makeLinearCommand } from '../commands/linear';
3232
import { makeListCommand } from '../commands/list';
3333
import { makeLoginCommand } from '../commands/login';
3434
import { makeNudgeCommand } from '../commands/nudge';
35+
import { makeOpsCommand } from '../commands/ops';
3536
import { makePendingCommand } from '../commands/pending';
37+
import { makePlatformCommand } from '../commands/platform';
3638
import { makePoliciesCommand } from '../commands/policies';
39+
import { makeRepoCommand } from '../commands/repo';
40+
import { makeRuntimeCommand } from '../commands/runtime';
3741
import { makeSlackCommand } from '../commands/slack';
3842
import { makeStatusCommand } from '../commands/status';
3943
import { makeSubmitCommand } from '../commands/submit';
@@ -74,6 +78,10 @@ program.addCommand(makeSlackCommand());
7478
program.addCommand(makeLinearCommand());
7579
program.addCommand(makeJiraCommand());
7680
program.addCommand(makeGithubCommand());
81+
program.addCommand(makePlatformCommand());
82+
program.addCommand(makeRepoCommand());
83+
program.addCommand(makeRuntimeCommand());
84+
program.addCommand(makeOpsCommand());
7785
program.addCommand(makeWatchCommand());
7886
program.addCommand(makeTraceCommand());
7987
program.addCommand(makeWebhookCommand());

0 commit comments

Comments
 (0)