Skip to content

Commit ade3caa

Browse files
Merge branch 'main' into feat/compute-strategy
2 parents 51882aa + 5bd0934 commit ade3caa

70 files changed

Lines changed: 3180 additions & 214 deletions

Some content is hidden

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

.cursor/rules/agent-runtime.mdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
description: Python agent runtime in isolated compute
3+
globs: agent/**/*.py
4+
alwaysApply: false
5+
---
6+
7+
# Agent runtime (`agent/`)
8+
9+
- **`entrypoint.py`** is the main task loop; prompts live under **`agent/prompts/`** with **`system_prompt.py`** for shared behavior.
10+
- Follow **`agent/README.md`** for GitHub PAT scopes, env vars, and local **`./agent/run.sh`** usage.
11+
- Use **`mise run quality`** in **`agent/`** (or root **`mise run build`**, which runs agent quality before CDK) after substantive changes.
12+
- Do not embed secrets; the stack supplies credentials via Secrets Manager / env as documented.
13+
- Prefer **`ruff`** / existing patterns; see **`pyproject.toml`** for **`ruff`** and **`pytest`** configuration.

.cursor/rules/cdk-handlers.mdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
description: CDK Lambda handlers and shared task pipeline conventions
3+
globs: cdk/src/handlers/**/*.ts
4+
alwaysApply: false
5+
---
6+
7+
# CDK handlers
8+
9+
- Prefer extending existing helpers in `cdk/src/handlers/shared/` (orchestration, validation, preflight) over duplicating logic.
10+
- When changing API shapes, edit **`cdk/src/handlers/shared/types.ts`** and mirror the same definitions in **`cli/src/types.ts`**.
11+
- Add or update Jest tests under **`cdk/test/handlers/`** or **`cdk/test/handlers/shared/`** next to the behavior you change (see **AGENTS.md** for a file map).
12+
- Use **`mise //cdk:test`** and **`mise //cdk:compile`** from the repo root instead of ad-hoc `jest` / `tsc` in the wrong directory.
13+
- Task lifecycle and admission behavior are described in **`docs/design/ORCHESTRATOR.md`**.

.cursor/rules/cli-package.mdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
description: bgagent CLI package conventions
3+
globs: cli/src/**/*.ts
4+
alwaysApply: false
5+
---
6+
7+
# CLI (`@backgroundagent/cli`)
8+
9+
- One command per file under **`cli/src/commands/`**; wire flags and options consistently with existing commands.
10+
- **`cli/src/types.ts`** must stay aligned with **`cdk/src/handlers/shared/types.ts`** when the REST API changes.
11+
- Console output is intentional: **`no-console`** is disabled for CLI sources.
12+
- The API base URL from deployment already includes the stage (e.g. **`/v1/`**); append only resource paths in **`api-client.ts`**.
13+
- Run **`mise //cli:build`** or **`cd cli && mise run test`** to verify changes.

.cursor/rules/docs-sources.mdc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: Authoritative docs live under guides/ and design/; Starlight is generated
3+
globs: docs/guides/**/*.md,docs/design/**/*.md
4+
alwaysApply: false
5+
---
6+
7+
# Documentation sources
8+
9+
- Edit **`docs/guides/`** and **`docs/design/`** (and root **`CONTRIBUTING.md`** when it affects the site). Do **not** hand-edit **`docs/src/content/docs/`** — that tree is produced by **`docs/scripts/sync-starlight.mjs`**.
10+
- After changing guides or design Markdown, run **`mise //docs:sync`** or **`mise //docs:build`** from the repo root.
11+
- **`AGENTS.md`** is the root entry for contributors and coding agents; keep it in sync conceptually when you change cross-cutting dev workflows.

.github/ISSUE_TEMPLATE/documentation.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ body:
99
attributes:
1010
value: |
1111
Thanks for helping improve the documentation. Relevant docs live in `docs/guides/`, `docs/design/`, and the repo README.
12+
- type: dropdown
13+
id: area
14+
attributes:
15+
label: Doc area
16+
description: What kind of documentation is affected?
17+
options:
18+
- User guide (`docs/guides/USER_GUIDE.md` or synced site)
19+
- Developer guide (`docs/guides/DEVELOPER_GUIDE.md` or synced site)
20+
- Design / architecture (`docs/design/`)
21+
- Roadmap or prompts (`docs/guides/`)
22+
- README / root docs
23+
- Other
24+
validations:
25+
required: true
1226
- type: textarea
1327
id: description
1428
attributes:

.github/ISSUE_TEMPLATE/rfc.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ body:
99
attributes:
1010
value: |
1111
Use this template for significant feature or design proposals. Please add as much detail as possible. See the [ROADMAP](https://github.com/krokoko/bgagent/blob/main/docs/guides/ROADMAP.md) and [design docs](https://github.com/krokoko/bgagent/tree/main/docs/design) for existing direction; your RFC should align or explain divergence.
12+
- type: dropdown
13+
id: area
14+
attributes:
15+
label: Primary area
16+
description: Which part of the repo does this RFC mainly affect?
17+
options:
18+
- CDK / infrastructure
19+
- Agent (Python runtime)
20+
- CLI (bgagent)
21+
- API or orchestration
22+
- Documentation
23+
- Tooling / CI
24+
- Cross-cutting / multiple
25+
validations:
26+
required: true
1227
- type: input
1328
id: relation
1429
attributes:

.github/pull_request_template.md

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

AGENTS.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,40 @@ You are an **AWS CDK (Cloud Development Kit) and TypeScript** expert. This proje
88

99
## Project knowledge
1010

11-
To get started and understand the developer flow, follow the [Developer guide](./docs/guides/DEVELOPER_GUIDE.md). For architecture and design, see [docs/design/](./docs/design/ARCHITECTURE.md).
11+
To get started and understand the developer flow, follow the [Developer guide](./docs/guides/DEVELOPER_GUIDE.md). For architecture and design, see [docs/design/](./docs/design/ARCHITECTURE.md). Task lifecycle and handler contracts are summarized in [Orchestrator design](./docs/design/ORCHESTRATOR.md) (including **API and agent contracts**).
12+
13+
### Where to make changes
14+
15+
Use this routing before editing so the right package and tests get updated:
16+
17+
| Change | Primary location | Also update |
18+
|--------|------------------|-------------|
19+
| REST API, Lambdas, task validation, orchestration | `cdk/src/handlers/`, `cdk/src/stacks/`, `cdk/src/constructs/` | Matching tests under `cdk/test/` |
20+
| Shared API request/response shapes | `cdk/src/handlers/shared/types.ts` | **`cli/src/types.ts`** (must stay in sync) |
21+
| `bgagent` CLI commands and HTTP client | `cli/src/`, `cli/test/` | `cli/src/types.ts` if API types change |
22+
| Agent runtime (clone, tools, prompts, container) | `agent/` (`entrypoint.py`, `prompts/`, `Dockerfile`, etc.) | `agent/tests/`, `agent/README.md` for env/PAT |
23+
| User-facing or design prose | `docs/guides/`, `docs/design/` | Run **`mise //docs:sync`** or **`mise //docs:build`** (do not edit `docs/src/content/docs/` by hand) |
24+
| Monorepo tasks, CI glue | Root `mise.toml`, `scripts/`, `.github/workflows/` ||
25+
26+
### CDK handler tests (quick map)
27+
28+
Colocated tests under `cdk/test/handlers/shared/` cover most shared logic:
29+
30+
- `validation.test.ts` — request validation
31+
- `preflight.test.ts` — preflight / admission checks
32+
- `create-task-core.test.ts` — task creation core path
33+
- `context-hydration.test.ts` — prompt / context assembly
34+
- `repo-config.test.ts`, `memory.test.ts`, `gateway.test.ts`, `response.test.ts`, `prompt-version.test.ts` — respective modules
35+
36+
Handler entry tests: `cdk/test/handlers/orchestrate-task.test.ts`, `create-task.test.ts`, `webhook-create-task.test.ts`. Construct wiring: `cdk/test/constructs/task-orchestrator.test.ts`, `task-api.test.ts`.
37+
38+
### Common mistakes
39+
40+
- Editing **`docs/src/content/docs/`** instead of **`docs/guides/`** or **`docs/design/`** — content is generated; sync from sources.
41+
- Changing **`cdk/.../types.ts`** without updating **`cli/src/types.ts`** — CLI and API drift.
42+
- Running raw **`jest`/`tsc`/`cdk`** from muscle memory — prefer **`mise //cdk:test`**, **`mise //cdk:compile`**, **`mise //cdk:synth`** (see [Commands you can use](#commands-you-can-use)).
43+
- **`MISE_EXPERIMENTAL=1`** — required for namespaced tasks like **`mise //cdk:build`** (see [CONTRIBUTING.md](./CONTRIBUTING.md)).
44+
- **`mise run build`** runs **`//agent:quality`** before CDK — the deployed image bundles **`agent/`**; agent changes belong in that tree.
1245

1346
### Tech stack
1447

@@ -24,7 +57,7 @@ To get started and understand the developer flow, follow the [Developer guide](.
2457
- **`scripts/`** (root) — Optional cross-package helpers; **`scripts/ci-build.sh`** runs the full monorepo build (same as CI).
2558
- **`cdk/`** — CDK app package (`@abca/cdk`): `cdk/src/`, `cdk/test/`, `cdk/cdk.json`, `cdk/tsconfig.json`, `cdk/tsconfig.dev.json`, and `cdk/.eslintrc.json`.
2659
- **`cli/`**`@backgroundagent/cli` — CLI tool for interacting with the deployed REST API (see below).
27-
- **`agent/`** — Python code that runs inside the agent compute environment (entrypoint, server, system prompt, Dockerfile, requirements).
60+
- **`agent/`** — Python code that runs inside the agent compute environment (entrypoint, server, system prompt, Dockerfile, requirements). The system prompt is refactored into `agent/prompts/` with a shared base template and per-task-type workflow variants (`new_task`, `pr_iteration`, `pr_review`).
2861
- **`docs/`** — Authoritative Markdown in `guides/` (developer, user, roadmap, prompt) and `design/`; assets in `diagrams/`, `imgs/`. The Starlight docs site lives here (`astro.config.mjs`, `package.json`); `src/content/docs/` is refreshed via `docs/scripts/sync-starlight.mjs`.
2962
- **`CONTRIBUTING.md`** — Contribution guidelines at the repository root.
3063
- **`package.json`** (root), **`yarn.lock`** — Yarn workspace root (minimal manifest); dependencies live in **`cdk/`**, **`cli/`**, and **`docs/`** package manifests.
@@ -40,7 +73,7 @@ The `@backgroundagent/cli` package provides the `bgagent` executable for submitt
4073
- `src/api-client.ts` — HTTP client wrapping `fetch` with auth header injection
4174
- `src/auth.ts` — Cognito login, token caching (`~/.bgagent/credentials.json`), auto-refresh
4275
- `src/config.ts` — Read/write `~/.bgagent/config.json`
43-
- `src/types.ts` — API request/response types (mirrored from `cdk/src/handlers/shared/types.ts`)
76+
- `src/types.ts` — API request/response types (mirrored from `cdk/src/handlers/shared/types.ts`), including `TaskType` (`new_task` | `pr_iteration` | `pr_review`)
4477
- `src/format.ts` — Output formatting (table, detail view, JSON)
4578
- `src/debug.ts` — Verbose/debug logging (`--verbose` flag)
4679
- `src/errors.ts``CliError` and `ApiError` classes

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ When filing an issue, please check [existing open](https://github.com/aws-sample
2222

2323
### Pull Request Checklist
2424

25+
When planning edits, use **[AGENTS.md](./AGENTS.md)** at the repo root for **where to change code** (CDK vs CLI vs agent vs docs), **which tests to extend**, and **common pitfalls** (generated docs, mirrored API types, `mise` tasks).
26+
2527
* [ ] Testing
2628
- Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
2729
- Integration test added (if adding a new pattern or making a significant update to an existing pattern)

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ Each task follows a **blueprint** — a hybrid workflow that mixes deterministic
4242

4343
1. **Admission** — the orchestrator validates the request, checks concurrency limits, and queues the task if needed.
4444
2. **Context hydration** — the platform gathers context: task description, GitHub issue body, repo-intrinsic knowledge (CLAUDE.md, README), and memory from past tasks on the same repo.
45-
3. **Agent execution** — the agent runs in an isolated MicroVM: clones the repo, creates a branch, edits code, commits, runs tests and lint. The orchestrator polls for completion without blocking compute.
46-
4. **Finalization** — the orchestrator infers the result (PR created or not), runs optional validation (lint, tests), extracts learnings into memory, and updates task status.
45+
3. **Pre-flight** — fail-closed readiness checks verify GitHub API reachability and repository access before consuming compute. Doomed tasks fail fast with a clear reason (`GITHUB_UNREACHABLE`, `REPO_NOT_FOUND_OR_NO_ACCESS`) instead of burning runtime.
46+
4. **Agent execution** — the agent runs in an isolated MicroVM with persistent session storage for select caches: clones the repo, creates a branch, edits code, commits, runs tests and lint. The orchestrator polls for completion without blocking compute.
47+
5. **Finalization** — the orchestrator infers the result (PR created or not), runs optional validation (lint, tests), extracts learnings into memory, and updates task status.
4748

4849
For the full architecture, see [ARCHITECTURE.md](./docs/design/ARCHITECTURE.md).
4950

@@ -58,7 +59,7 @@ ABCA is under active development. The platform ships iteratively — each iterat
5859
| **3a** | Done | Repo onboarding, per-repo GitHub App credentials, turn caps, prompt guide |
5960
| **3b** | Done | Memory Tier 1, insights, agent self-feedback, prompt versioning, commit attribution |
6061
| **3bis** | Done | Hardening — reconciler error tracking, error serialization, test coverage gaps |
61-
| **3c** | WIP | Deterministic validation, PR review task type, multi-modal input |
62+
| **3c** | WIP | Pre-flight checks, persistent session storage, deterministic validation, PR review task type, multi-modal input |
6263
| **3d** | Planned | Review feedback loop, PR outcome tracking, evaluation pipeline |
6364
| **4** | Planned | GitLab, visual proof, Slack, control panel, WebSocket streaming |
6465
| **5** | Planned | Pre-warming, multi-user/team, cost management, guardrails, alternate runtime |

0 commit comments

Comments
 (0)