diff --git a/AGENTS.md b/AGENTS.md new file mode 120000 index 0000000..681311e --- /dev/null +++ b/AGENTS.md @@ -0,0 +1 @@ +CLAUDE.md \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index 5678b03..95990af 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -16,13 +16,13 @@ not repeat them here. | e2e, live tier | `npm run test:e2e -- --grep @smoke` (`AGENTAGE_SITE_FQDN` = target; CI: dispatch `e2e.yml`) | | Pack smoke | `scripts/pack-smoke.sh`, `scripts/update-smoke.sh` (reads npm) on a packed tarball (`ci.yml`) | | Mutation check | `node scripts/mutate.mjs [ids]`; it edits `src`, so never run it beside verify | -| Release | dispatch `prepare-release.yml`; `release.yml` publishes on the merge (see README "Release") | +| Release | dispatch `prepare-release.yml`; `release.yml` publishes on the merge (see `docs/release.md`) | ## Where facts live Each row names the doc first, then the code that proves it. Read the doc before `src/`. -- Install, sign-in, command list, config dir: `README.md`; `src/program.ts`, `src/lib/fs/config.ts`. +- Install, sign-in, command list: `README.md`; config dir: `docs/reference.md` "Files"; `src/program.ts`, `src/lib/fs/config.ts`. - `setup`, `status`, `update`: `docs/reference.md` sections of those names; `src/commands/auth/`, `status/`, `update/`, `extension/setup.ts`. - The lifecycle (C1: install, list, update, disable, enable, configure, remove) and the move from @@ -125,11 +125,11 @@ Drives the built `dist/cli.js` as a subprocess. Tiers are tags in the test title auth and account routes; `e2e/registry/` npm serving `fixtures/`). `@p0` is the hermetic `setup --no-browser` sign-in round trip, also `@offline`. - `@smoke`: read-only against a live target; nothing signs in or writes. -- The agentage/e2e cli tier (`_e2e-cli.yml`, `--project=cli --grep @smoke`) runs on the packed +- The cli tier of the shared end-to-end gate (in a private repo) (`_e2e-cli.yml`, `--project=cli --grep @smoke`) runs on the packed cli: on every PR (`e2e.yml`, not required) and before each publish (`release.yml`, blocking). `scripts/candidate-registry.mjs` serves the tarball as npm `latest` on loopback. The tier reads prod, so a prod outage blocks a publish. A cli change that the tier pins (a help line, a renamed - command) needs its agentage/e2e test first, version-gated on the release that changes it. + command) needs its gate test first, version-gated on the release that changes it. ## Conventions diff --git a/README.md b/README.md index 29f1ff8..f873c78 100644 --- a/README.md +++ b/README.md @@ -2,171 +2,113 @@ ![Connect this machine to agentage from the terminal](https://github.com/agentage/cli/raw/master/docs/banner.svg) -The agentage CLI connects each machine you use to your agentage account, a shared place for your -AI tools. Use it from a terminal, a server or CI. It also installs extensions: npm packages that -add commands to `agentage`. You need Node.js 22 or newer. +The `agentage` command connects each machine you use to your agentage account and runs +extensions on it. It is also the tool to make and release your own extension. Use it from a +terminal, a server or CI. You need Node.js 22 or newer. ```bash -npm install -g @agentage/cli && agentage setup +npm i -g @agentage/cli +agentage setup # sign in in your browser, then start the local daemon ``` -## What is this? - -The CLI stays **small**: sign-in, status, update and an extension manager. Sign-in uses OAuth 2.1 -with PKCE: you type nothing into the terminal. Everything else, memory included, arrives as an -extension. - -## Get started - -`agentage setup` opens your browser for sign-in. Check the session with `agentage status`. -Installing and running extensions needs no sign-in. On a new machine, a signed-in `setup` installs -the extensions of your account's profile once; after that each machine keeps its own list. - -### On a server or in CI (no browser) - -`agentage setup --no-browser` prints the sign-in URL. Open it in a browser on this same machine, -because sign-in returns to `localhost`. On a server, use a personal access token from the -dashboard (**Settings**, then **API tokens**): - -```bash -AGENTAGE_TOKEN=aga_... agentage status -``` - -More: [docs/reference.md](docs/reference.md#token-auth-ci-and-headless). +Status: before 1.0. Extensions run on the local daemon (`127.0.0.1:4243`) of each machine. ## Commands -| Command | What it does | -| ----------------------------- | ---------------------------------------------------------------------------------- | -| `agentage setup` | Sign in, install your account's profile, show status, start the daemon | -| `agentage setup --no-browser` | Print the sign-in URL instead of opening a browser | -| `agentage setup --reauth` | Force a fresh sign-in | -| `agentage setup --disconnect` | Sign out and remove local credentials | -| `agentage status` | Version, update, target, sign-in, endpoint, then machine, profile, extensions | -| `agentage update` | Install the latest published version (`--check` only reports) | -| `agentage daemon status` | The local daemon on 127.0.0.1:4243 (`start`, `stop`, `restart`); `setup` starts it | -| `agentage extension ...` | Manage extensions, see [Extensions](#extensions) | -| any command with `--json` | One JSON object on stdout: `{ success, data }` or `{ success, error }` | - -More: [author commands](docs/extensions.md#author-commands) and -[the lifecycle](docs/reference.md#extension-lifecycle). - -## Extensions - -- A **profile** lists what your account wants: extensions, version ranges, and which are off - per machine. -- On a new machine, `setup` installs the profile's extensions through the daemon, once. No - command pushes your changes back to the account: each machine keeps its own list. -- `extension install`, `list`, `update`, `disable`, `enable`, `configure` and `remove` manage - one extension in the local daemon (`127.0.0.1:4243`), which runs each as its own process. -- Nothing installs on a timer: the machine changes only when you run a command. - -```bash -agentage extension install probe # the market's newest version, then it runs -agentage extension configure probe echo.prefix=hey # settings, no daemon restart -agentage extension list # id, version, source, state -agentage probe ping # run a command by its extension id -agentage extension remove probe # take it out again; --purge also deletes its data -``` - -Extensions run with your privileges, in the daemon and in the CLI process, so install only ones -you trust. npm runs with `--ignore-scripts`. The account token leaves the environment before -extension code loads. - -More: [docs/profiles.md](docs/profiles.md). - -### Write and run your own extension - -`create` needs git and network. `build --container`, `up --docker` and `release` also need -Docker and a committed tree; `release` needs the `gh` CLI. +Each command has `--help`. The full reference is [docs/reference.md](docs/reference.md). + +| Command | What it does | +| ------------------------------ | ------------------------------------------------------------------------ | +| `agentage setup` | Sign in and connect this machine to your account; start the daemon | +| `agentage status` | Show the cli, account, endpoint, machine, profile and extension status | +| `agentage update` | Update `@agentage/cli` to the latest published version | +| `agentage daemon` | Start, show, stop or restart the local daemon that runs extensions | +| `extension install ` | Install an extension (``, `@` or a folder) and run it | +| `extension list` | Show each installed extension: id, version, source, state | +| `extension update [id]` | Move each market extension, or one, to its newest version | +| `extension disable ` | Stop an extension, keep its data | +| `extension enable ` | Run a disabled extension again | +| `extension configure k=v` | Set settings (or `--secret` secrets) of an extension, no restart | +| `extension remove ` | Stop and remove an extension; its data stays unless `--purge` | +| `extension doctor` | Load every extension once and refresh its state: ok or failed | +| `extension create ` | Create `./extension-` from the extension template | +| `extension check [dir]` | Check that an extension package conforms, as every build does first | +| `extension build` | Build the extension package; `--container` builds one image of all parts | +| `extension release` | Release an extension in CI; `--changed` releases each changed extension | +| `extension up` | Run the working copy on the daemon and reload each change | +| `extension down` | Stop what `extension up` started here | +| `extension token` | Print a token from the dev issuer that `extension up --docker` started | + +`extension ...` means `agentage extension ...`. Add `--json` to most commands for one JSON object +on stdout: `{ success, data }` or `{ success: false, error }`. On a server with no browser, use a +personal access token: `AGENTAGE_TOKEN=aga_... agentage status`. + +## Make your first extension + +![Make your first extension: create, verify, check, merge, released](https://github.com/agentage/cli/raw/master/docs/first-extension.svg) + +You need git and network. Run these in an empty folder: ```bash -agentage extension create example api # makes ./extension-example with the api part -cd extension-example && npm ci # installs the pinned cli -npx agentage extension up # runs it on the daemon, reloads each saved change -npx agentage extension down # removes the row up added (its data stays) +agentage extension create my-ext +cd extension-my-ext +npm ci +npm run verify +npx agentage extension check # PASS my-ext 0.1.2 conforms (6 rules) +git init -b master && git add -A && git commit -m "feat: my-ext extension" ``` -In the extension folder, use `npx agentage`: the project's pinned cli and the global one can differ. - -More: [docs/extensions.md](docs/extensions.md#run-it-locally). - -## Where things live +`create` copies the template from `agentage/kit:template` and writes your id into every file. In +the folder, use `npx agentage`: it runs the cli version that the folder pins. The guide of the new +folder is its own `README.md`. `check` may end with an `update available` line when the cli that +runs it is older than the newest on npm. -Everything lives in the config directory, `~/.agentage` by default: +`create` builds the folder and gives it to the local daemon, so it runs at once. Add `--no-install` +to only create the files: CI and agents always do. Two more commands change the local daemon: +`npx agentage extension up` runs the folder there and reloads each change, and +`agentage extension install ./extension-my-ext` installs it there. -| Path | What | -| ------------------------------- | ----------------------------------------------------- | -| `~/.agentage/auth.json` | your sign-in, owner-only | -| `~/.agentage/profile.json` | the profile: what this account wants | -| `~/.agentage/machine.json` | this machine's id, name, dev extensions and account | -| `~/.agentage/installation.json` | this machine's extension list, written by the daemon | -| `~/.agentage/daemon.json` | the running daemon: pid, port, host token; owner-only | -| `~/.agentage/extensions/` | installed extensions, one tree per id and version | -| `~/.agentage/state/` | the last run of each extension | -| `~/.agentage/commands.json` | cli 0.51's command holders; read, never written | -| `~/.agentage/secrets.json` | extension secrets, owner-only | -| `~/.agentage/data//` | what each extension keeps | -| `~/.agentage/logs/` | `daemon.log` and each extension's log | +## How an extension is released -`status` writes `machine.json` even before you sign in. +Push the repo to GitHub. A release runs in CI in one of two modes: -To uninstall, run `agentage setup --disconnect`, then `npm uninstall -g @agentage/cli`, then -delete `~/.agentage`. +- A repo with one or several extensions: each merge to master runs `agentage extension release --changed`. This is what a new repo from `create` does. +- A repo with one extension can instead release by a pushed tag `v`: `agentage extension release`. -## How it works +With `--changed`, a changed extension gets a date version +`YYYY.MDD.N` (for example `2026.1122.1`), the tag `@`, its images and its records on +the GitHub release. A change only in a root `*.md` file, `docs/` or `.github/` releases nothing. +A `.release-ignore` file adds more patterns. The new package is private: it goes to npm only when +you remove `"private": true`. The rule in full: [docs/reference.md](docs/reference.md#extension-release). -- `setup` registers a one-off OAuth client and waits for the browser on a localhost callback. -- Tokens land in `~/.agentage/auth.json` (owner-only) and refresh automatically. -- `status` checks the session against the account's introspection endpoint. -- The daemon is the only background process. It starts when a command needs it and runs until - `agentage daemon stop`. Nothing installs on a timer. - -## Configuration - -| Env | Default | Purpose | -| ------------------------- | --------------------- | -------------------------------------------------- | -| `AGENTAGE_SITE_FQDN` | `agentage.io` | Target host | -| `AGENTAGE_CONFIG_DIR` | `~/.agentage` | Config and credentials directory | -| `AGENTAGE_TOKEN` | - | Personal access token for CI and headless machines | -| `AGENTAGE_EXTENSIONS_DIR` | `/extensions` | Where extensions are installed | -| `AGENTAGE_DAEMON_PORT` | `4243` | The daemon's port on 127.0.0.1 | -| `NO_COLOR` | - | Disable colored output | - -## Develop +## How to work on this repo ```bash npm ci -npm run verify -npm run build && npm run test:e2e -- --grep @offline +npm run verify # type-check, lint, format, test, build +npm run build && npm run test:e2e -- --grep @offline # e2e with a loopback npm registry ``` -Each e2e title under `e2e/core/` names a command and what must hold. The tests use a loopback -npm registry that serves `fixtures/`. +## How a change is released -## Release +A merge of a normal change releases nothing. The `chore(release): X.Y.Z` PR from +`prepare-release.yml` changes `package.json`; its merge runs `release.yml`, which publishes to npm +with OIDC trusted publishing and pushes the tag `vX.Y.Z`. Details: [docs/release.md](docs/release.md). -Dispatch `prepare-release.yml` (a weekly schedule also dispatches it). It opens a -`chore(release): X.Y.Z` PR and arms auto-merge. On the merge, `release.yml` runs verify and the -agentage/e2e cli tier on the packed cli, then publishes to npm with OIDC trusted publishing and -provenance, and pushes the tag `vX.Y.Z`. It skips a version already on npm. +## For agents -- The publish worked but the tag push failed: push the tag by hand on the release commit - (`git tag vX.Y.Z && git push origin vX.Y.Z`); never publish again. -- The cli tier failed: fix the cli or the e2e test, then dispatch `release.yml` again. -- `release.yml` runs only the `@smoke` tests of the agentage/e2e cli tier on the candidate. The - lifecycle, execution and reload tests of agentage/e2e run on its own PRs against the published - cli. -- Before the release PR merges, check: the PR checks of the release commit are green, and the cli - project of agentage/e2e passes in full against the packed tarball of that commit - (`AGENTAGE_CLI_TARBALL= npm run test:cli -- --retries=0`). +- Read [AGENTS.md](AGENTS.md) (the same file as `CLAUDE.md`): commands, layout and where each fact lives. +- Never run `setup`, `update`, `extension up` or `extension install` on a shared machine, and always add `--no-install` to `extension create`. +- Never publish to npm by hand: only `release.yml` publishes. -## Documentation +## Links -- [docs/reference.md](docs/reference.md): every flag, exit code and environment variable. -- [docs/profiles.md](docs/profiles.md): profiles, extension states, the plan and updates. +- [docs/reference.md](docs/reference.md): every flag, exit code, environment variable and file. - [docs/extensions.md](docs/extensions.md): write, check and run your own extension. +- [docs/profiles.md](docs/profiles.md): profiles, extension states, the plan and updates. +- [agentage/kit](https://github.com/agentage/kit): the kit and the extension template. +- [agentage/examples](https://github.com/agentage/examples): the probe and fixture extensions. ## License -MIT - see [LICENSE](./LICENSE). +MIT. See [LICENSE](LICENSE). diff --git a/docs/banner.svg b/docs/banner.svg index 5a21dc6..6d92cc4 100644 --- a/docs/banner.svg +++ b/docs/banner.svg @@ -70,5 +70,5 @@ signs in - one command connects any machine to your agentage account - browser sign-in, tokens for CI, extensions to follow + one command connects any machine to your agentage account - browser sign-in, tokens for CI, extensions on the local daemon diff --git a/docs/first-extension.svg b/docs/first-extension.svg new file mode 100644 index 0000000..36dd14c --- /dev/null +++ b/docs/first-extension.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + Make your first extension + + + CREATE + extension create my-ext + a new repo from + the kit template + + + VERIFY + npm run verify + type-check, lint, + test, build + + + CHECK + agentage extension check + the six rules + every build runs + + + MERGE + git push, then merge + to master; CI runs + release.yml + + + RELEASED + my-ext@2026.1122.1 + images and records; + npm only on purpose + a merge to master is the release: a date version YYYY.MDD.N and the tag <id>@<version>, nothing to tag by hand + diff --git a/docs/reference.md b/docs/reference.md index 3f62620..5ca24a5 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -520,8 +520,8 @@ every image by digest; `extension release` runs this. `--registry ` ## extension release ```bash -agentage extension release # in release.yml, on a v* tag push -agentage extension release --changed # in release.yml, on a push to master +agentage extension release # one extension: in release.yml, on a v* tag push +agentage extension release --changed # one or several: in release.yml, on a merge to master agentage extension release --changed --dry-run # what it would release; changes nothing ``` @@ -1063,3 +1063,34 @@ Otherwise it is `extensions` inside the config directory. The config directory i | `AGENTAGE_STARTED_BY` | `desktop` when the desktop starts the daemon (`startedBy` in `daemon.json`) | `cli` | | `AGENTAGE_SIGN_IN_RETURN` | `desktop`: the sign-in page ends with the deep link `agentage://signed-in` | unset | | `AGENTAGE_DAEMON_CLOCK_RATE` | Tests only: the test clock of the daemon it starts (`createDaemon({ clockRate })`) | unset | + +## Files + +Everything lives in the config directory, `~/.agentage` by default: + +| Path | What | +| ------------------------------- | ----------------------------------------------------- | +| `~/.agentage/auth.json` | your sign-in, owner-only | +| `~/.agentage/profile.json` | the profile: what this account wants | +| `~/.agentage/machine.json` | this machine's id, name, dev extensions and account | +| `~/.agentage/installation.json` | this machine's extension list, written by the daemon | +| `~/.agentage/daemon.json` | the running daemon: pid, port, host token; owner-only | +| `~/.agentage/extensions/` | installed extensions, one tree per id and version | +| `~/.agentage/state/` | the last run of each extension | +| `~/.agentage/commands.json` | cli 0.51's command holders; read, never written | +| `~/.agentage/secrets.json` | extension secrets, owner-only | +| `~/.agentage/data//` | what each extension keeps | +| `~/.agentage/logs/` | `daemon.log` and each extension's log | + +`status` writes `machine.json` even before you sign in. + +To uninstall, run `agentage setup --disconnect`, then `npm uninstall -g @agentage/cli`, then +delete `~/.agentage`. + +### How it works + +- `setup` registers a one-off OAuth client and waits for the browser on a localhost callback. +- Tokens land in `~/.agentage/auth.json` (owner-only) and refresh automatically. +- `status` checks the session against the account's introspection endpoint. +- The daemon is the only background process. It starts when a command needs it and runs until + `agentage daemon stop`. Nothing installs on a timer. diff --git a/docs/release.md b/docs/release.md new file mode 100644 index 0000000..d86dfed --- /dev/null +++ b/docs/release.md @@ -0,0 +1,19 @@ +# Release the cli + +How `@agentage/cli` itself is released. The short form is in the +[README](../README.md#how-a-change-is-released). + +Dispatch `prepare-release.yml` (a weekly schedule also dispatches it). It opens a +`chore(release): X.Y.Z` PR and arms auto-merge. On the merge, `release.yml` runs verify and the +cli tier of the shared end-to-end gate (in a private repo) on the packed cli, then publishes to npm with OIDC trusted publishing and +provenance, and pushes the tag `vX.Y.Z`. It skips a version already on npm. + +- The publish worked but the tag push failed: push the tag by hand on the release commit + (`git tag vX.Y.Z && git push origin vX.Y.Z`); never publish again. +- The cli tier failed: fix the cli or the e2e test, then dispatch `release.yml` again. +- `release.yml` runs only the `@smoke` tests of that cli tier on the candidate. The + lifecycle, execution and reload tests of the gate run on its own PRs against the published + cli. +- Before the release PR merges, check: the PR checks of the release commit are green, and the cli + project of the gate passes in full against the packed tarball of that commit + (`AGENTAGE_CLI_TARBALL= npm run test:cli -- --retries=0`). diff --git a/src/commands/extension/release-help.test.ts b/src/commands/extension/release-help.test.ts new file mode 100644 index 0000000..d877cb5 --- /dev/null +++ b/src/commands/extension/release-help.test.ts @@ -0,0 +1,14 @@ +import { Command } from 'commander'; +import { describe, expect, it } from 'vitest'; +import { addRelease } from './release.js'; + +describe('extension release --help', () => { + it('names both modes: the v* tag and --changed on a merge', () => { + const group = new Command('extension'); + addRelease(group, async () => {}); + const release = group.commands.find((c) => c.name() === 'release'); + expect(release?.description()).toBe( + 'Release an extension in CI: from its v* tag, or with --changed each changed one on a merge' + ); + }); +}); diff --git a/src/commands/extension/release.ts b/src/commands/extension/release.ts index 7493cca..ef6b485 100644 --- a/src/commands/extension/release.ts +++ b/src/commands/extension/release.ts @@ -101,7 +101,7 @@ export const addRelease = ( group .command('release') .description( - 'Release an extension from its v* tag in CI: guard, images, one image, records, npm package' + 'Release an extension in CI: from its v* tag, or with --changed each changed one on a merge' ) .option('--dir ', 'the extension package folder (default: the current folder)') .option(