Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Deploy CLI SDK

A Go library of commands, TUIs and helpers for the Bluelink CLI (`apps/cli` in bluelink) and
the Celerity CLI (`apps/cli` in celerity). The Bluelink CLI passes a `commands.CLIConfig`
(see `commands/config.go`) and registers stage, deploy, destroy, instances, state and cleanup
with `commands.Setup*Command`; its own `validate` runs `tui/validateui`. The Celerity CLI so
far uses only `config`, `styles`, `engine` and `tui/precommand`, with its own validate TUI,
and its stage, deploy and destroy aren't wired to this SDK yet.

## Workspace

This repo is one of NewStack's. NewStack's maintainers develop it alongside the others in a
shared workspace, using the NewStack Claude Code plugin for how work is planned, reviewed,
committed and coordinated across repos. The plugin isn't public, and nothing here depends on it:
this file and the repo's own docs cover what a contribution needs.

## Layout

| Path | Holds |
|---|---|
| `commands/` | Command setup, `CLIConfig`, flag and environment variable binding |
| `tui/<name>ui/` | One Bubble Tea app per command or view (`stageui`, `deployui`, `destroyui`, `validateui`, `driftui`, `inspectui`, `listui`, `cleanupui`, `stateexportui`, `stateimportui`); `tui/shared`, `tui/preflight` and the `*util` packages hold what they share |
| `tui/precommand/` | The `PreCommandStep` interface a CLI implements to run a step before a command |
| `ui/` | Reusable components: blueprint and file selection, `splitpane` |
| `headless/`, `jsonout/` | Plain output without a terminal; `--json` output |
| `engine/`, `config/` | Deploy engine client setup; CLI and deploy config loading |
| `stateio/` | State export and import between the engine's memfile or postgres store and export files, local or on S3, GCS or Azure Blob |
| `styles/` | Styles and the Bluelink and Celerity palettes |
| `diagutils/`, `consts/`, `strings/` | Diagnostic formatting, shared constants, string helpers |
| `testutils/` | Test helpers, including a fake deploy engine and `teatest` helpers |

## Checks

Commands are in [CONTRIBUTING.md](CONTRIBUTING.md).

- **Tools:** Go (`go.mod`), `staticcheck` on `PATH` (CI installs `@latest`, so a local copy
can disagree), Node with Yarn 4 for commitlint (`yarn` first; the tracked `.yarnrc.yml`
makes it create `node_modules`). Integration tests also need docker, the `aws` CLI, `jq`
and `curl`; without `jq` or `curl`, the run waits and then fails with "LocalStack readiness
timed out".
- **Lint:** `bash scripts/lint.sh` runs `staticcheck` and `go vet` per package.
- **Tests:** `bash scripts/run-tests.sh` runs every package except `stateio` and `testutils`
with `-race` and coverage. `stateio`'s unit tests run only with `--integration`, and
`go test ./...` fails there without the stack. `--update-snapshots` is accepted, but no
tests use snapshots.
- `--integration` adds `stateio`. It downloads the `libs/blueprint-state` version pinned in
`go.mod`, copies its postgres migrations into `stateio/postgres/` (gitignored), starts
`stateio/docker-compose.test-deps.yml` (LocalStack on 4580, fake-gcs-server on 8185,
Azurite on 10003, postgres on 45434), and stops it on exit.
- Set `AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test`, as CI does. Without them the
script's `aws` calls and the Go S3 client use the shell's credentials (against LocalStack
only), and with none at all the S3 seeding step fails.
- Run one stack at a time: the container names are fixed, so a second checkout's run
clashes with the first. The ports don't clash with Bluelink's stacks.
- **Trying a change in a CLI:** there's no `go.work` here, so point the CLI's module at this
checkout with a temporary `replace`, or a `go.work` outside both repos, and don't commit
either. Bluelink's root `go.work` is committed and doesn't include this repo.
- **Gates:**
- With `git config core.hooksPath .githooks`, pre-commit runs `scripts/lint.sh` over the
whole module on every commit, and commit-msg runs commitlint.
- CI (`ci.yml`) runs lint, `run-tests.sh --integration` and SonarCloud on pull requests and
pushes to `main`. `codeql.yml` runs CodeQL on the same triggers and weekly;
`infrastructure-security.yml` runs actionlint when a workflow or shell script changes,
and weekly.

## Compatibility

- **Go API:** pre-1.0 (`bump-minor-pre-major`, so a `feat` or a breaking change bumps the
minor version). Each CLI pins its own version in `go.mod`, and the pins can differ. A
breaking change says in its PR what each CLI must change when it bumps.
- **Command behaviour:** flags, environment variables
(`<EnvVarPrefix>_<COMMAND>[_<SUBCOMMAND>]_<FLAG>`, bound per flag in `commands/`; not every
flag has one), headless output and `--json` output are what CLI users and their scripts see. Additive only; the CLI docs in bluelink-docs and
celerity-docs (`content/docs/cli/`) describe them.
- **Bluelink libraries:** `libs/blueprint`, `libs/blueprint-state`, `libs/common` and
`libs/deploy-engine-client` are pinned in `go.mod`, so a change in bluelink reaches this
repo only by release and bump. Renovate raises those bumps as bluelink releases and merges
them itself when CI passes. Read the pinned code from the module cache
(`go list -m -f '{{.Dir}}' <module>`), not a checkout.
- **Persisted state:** none of its own. `stateio` reads and writes the engine's memfile and
postgres stores and export files in blueprint-state's format, so it follows bluelink's
stance on persisted state.

## Conventions

- Commits: [COMMIT_GUIDELINES.md](COMMIT_GUIDELINES.md), with the types in
`commitlint.config.js`. Scopes are allowed but unused; release-please releases the whole
module as one package.
- Releases: release-please opens the release pull request; merging it tags `vX.Y.Z`. Don't
edit `CHANGELOG.md` or `.release-please-manifest.json` by hand.
- Dependency updates: Renovate (`renovate.json`, run hourly by `renovate.yml`).
- Anything specific to one CLI goes through `CLIConfig` or a factory it passes in (such as
`PreflightFactory`), not a check for the CLI's name.

## Safety

- Don't create tags or releases, or merge release pull requests.
- Don't run commands from this SDK against a running deploy engine unless asked: the
maintainer's engine may be serving runs against real cloud accounts.
- `state import` and `state export` bypass the engine and work on the store named in the
engine config file directly; don't point them at the maintainer's engine config.

## Known mistakes

<!-- One line per mistake an agent has made here, phrased as the rule that prevents it. -->
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
6 changes: 3 additions & 3 deletions COMMIT_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ a base for more advanced tooling to allow for efficient searches for decisions a

### Commit types

**The following commit types are supported in the Bluelink project:**
**The following commit types are supported in this repo:**

- `fix:` - Should be used for any bug fixes.
- `revert:` - Should be used for any commits that revert changes.
- `wip:` - Should be used for commits that contain work in progress.
- `feat:` - Should be used for any new features added, regardless of the size of the feature.
- `chore:` - Should be used for tasks such as releases or patching dependencies.
- `chore:` - Should be used for tasks such as releases.
- `ci:` - Should be used for any work on GitHub Action workflows or scripts used in CI.
- `docs:`- Should be used for adding or modifying documentation.
- `style:` - Should be used for code formatting commits and linting fixes.
Expand All @@ -27,7 +27,7 @@ a base for more advanced tooling to allow for efficient searches for decisions a

### Example commit

#### With commit scope
#### Example

```bash
git commit -m 'feat: add select component with preview
Expand Down
18 changes: 11 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ git config core.hooksPath .githooks

### Requirements

- [Go](https://go.dev/doc/install) >= 1.24.4
- [Go](https://go.dev/doc/install) >= 1.26.4 (`go.mod`)
- [Node.js](https://nodejs.org/en/download/) >= 22.20.0
- [Yarn](https://yarnpkg.com/getting-started/install) >= 4.3.1
- [Yarn](https://yarnpkg.com/getting-started/install) 4 (`packageManager` in `package.json`)

### NPM dependencies

Expand Down Expand Up @@ -44,17 +44,21 @@ To run unit tests only (without integration tests):
bash scripts/run-tests.sh
```

To update test snapshots (if any):
To run tests for a specific package:

```bash
bash scripts/run-tests.sh --update-snapshots
go test -v ./styles/...
go test -v ./config/...
```

To run tests for a specific package:
`stateio`'s tests, unit tests included, need the integration stack, so `go test ./...` fails
there without it; use `bash scripts/run-tests.sh --integration` for that package.

The integration run needs docker, the `aws` CLI, `jq` and `curl`, and test credentials for
LocalStack, as CI sets them:

```bash
go test -v ./styles/...
go test -v ./config/...
AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test bash scripts/run-tests.sh --integration
```

## Linting
Expand Down
Loading