@ory/amp 0.11.0 → 0.12.0

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/README.md CHANGED
@@ -1,117 +1,137 @@
1
1
  # Ory Agent Plugin: Amp
2
2
 
3
- [Ory](https://ory.com) bundled into [Amp](https://ampcode.com) (Sourcegraph's coding agent): skills that scaffold Ory authentication into your codebase, a local Ory stack you can spin up in one command, and (when pointed at an Ory project) authentication, authorization, and audit for every tool Amp runs.
3
+ Security and developer experience for [Amp](https://ampcode.com) (Sourcegraph's coding agent), powered by [Ory](https://ory.com).
4
4
 
5
- You don't need an Ory account or any prior Ory experience to start.
5
+ **Security.** Amp runs real actions on your machine — editing files, running shell commands, calling APIs. The plugin gives every session a verifiable identity (you sign in once; Amp and any sub-agents it spawns each get their own), checks every tool call against permissions you control, and records each decision as an audit trace you can ship to your observability stack. It starts in watch mode so nothing is blocked on day one, and if Ory is ever unreachable it steps aside rather than locking you out.
6
6
 
7
- ## New to Ory?
7
+ **Developer experience.** A single command installs the plugin and walks you through connecting — choose Ory Network, a local Docker stack, or audit-only, and it wires up the project, sign-in client, login, and permissions for you. It also helps you build Ory into your own app: ask in plain language to scaffold login, registration, and recovery pages, run a local Ory, or manage identities and permissions through the bundled MCP server.
8
8
 
9
- [Ory](https://www.ory.com/docs/) is an open-source identity and access platform — login, registration, sessions, social sign-in, multi-factor auth, and fine-grained permissions, so you don't have to build any of that yourself. Two things make it easy to try with no prior experience:
9
+ ## What you'll need
10
10
 
11
- - **Ory Elements** are prebuilt, themeable UI components for the auth pages. The scaffolding skills wire them into your app for you.
12
- - **The local Ory stack** is a complete Ory running on your laptop in Docker — no account, no signup, no API key.
11
+ - [Amp](https://ampcode.com), installed
12
+ - Node.js **22 or newer**
13
+ - [Docker](https://docs.docker.com/get-docker/) — only if you want to run Ory locally
14
+ - macOS or Linux (Windows works via WSL2)
13
15
 
14
- ## What this plugin does
16
+ ## Get started
15
17
 
16
- Two independent things, and you can use either on its own:
18
+ Run one command. It installs the plugin and walks you through connecting:
17
19
 
18
- 1. **Build auth into your app.** Have Amp scaffold Ory login, registration, social sign-in, and permissions into the project you're working on, backed by the local stack. This needs nothing but Docker.
19
- 2. **Govern the agent itself.** Authenticate Amp's own session and authorize every tool it runs against Ory Permissions, with a full audit trail. See [Agent security](#agent-security).
20
+ ```bash
21
+ npx -y -p @ory/amp ory-amp install
22
+ ```
20
23
 
21
- ## Prerequisites
24
+ You'll be asked how you want to connect — **press Enter for the default**:
22
25
 
23
- - [Amp](https://ampcode.com) installed
24
- - Node.js **≥ 22**
25
- - [Docker](https://docs.docker.com/get-docker/) (only needed for the local Ory stack)
26
- - macOS or Linux. Windows works via WSL2.
26
+ - **Ory Network** *(default)* — sign in, or create a free account, in your browser. The project, keys, permissions, and login are all set up for you. Nothing to configure by hand.
27
+ - **Local** — run a complete Ory on your laptop with Docker. No account, no signup, no keys. Great for trying it out.
28
+ - **Audit-only** skip Ory entirely and just log what Amp does.
27
29
 
28
- ## Install
30
+ That's it. Confirm everything landed with:
29
31
 
30
32
  ```bash
31
- npx -y -p @ory/amp ory-amp install
33
+ npx -y -p @ory/amp ory-amp status
32
34
  ```
33
35
 
34
- `install` performs two registrations and materializes the Ory skills:
36
+ `status` is your one-stop check: what's configured, who's signed in, which tools are covered by permissions, whether the plugin is wired into Amp, and recent activity.
35
37
 
36
- 1. Registers the Ory **permission delegate** in Amp's settings (`~/.config/amp/settings.json`) under the flat top-level `amp.permissions` key as `{ tool: "*", action: "delegate", to: "ory-amp-permission" }` this is the blocking gate.
37
- 2. Writes the **in-process plugin** loader at `<project>/.amp/plugins/ory.ts` so Amp's Bun TypeScript runtime discovers it for session auth and audit tracing.
38
+ Re-run install with `--reconfigure` to change your connection later, or `--no-configure` to skip the wizard and configure by hand.
38
39
 
39
- The Ory skill playbooks land under `<project>/.agents/skills/` (Amp's project skills directory).
40
+ ## What you get
40
41
 
41
- ```bash
42
- npx -y -p @ory/amp ory-amp status # confirm delegate + plugin registration
43
- npx -y -p @ory/amp ory-amp uninstall # remove the delegate, plugin, and skills
44
- ```
42
+ Once connected, every tool Amp runs is governed by Ory — three things happen automatically:
45
43
 
46
- `status` prints configuration, user and agent identity, per-tool permission coverage, whether the delegate and in-process plugin are registered, and a tail of recent debug logs.
44
+ - **Who's driving.** You sign in once in your browser; Amp gets its own identity too, and registers it automatically on first run. No tokens to copy around, and the "who acted on whose behalf" trail stays queryable later.
45
+ - **What it's allowed to do.** Before a tool runs, Ory checks whether it's permitted. It starts in **watch mode** — nothing is blocked, you just *see* what would be — so it never gets in your way on day one.
46
+ - **A record of everything.** Every decision (allowed, denied, skipped) is logged as a trace you can send to a viewer like Jaeger or Honeycomb, or just a file.
47
47
 
48
- ## Quickstart (≈ 3 minutes)
48
+ If Ory is ever slow or unreachable, the plugin gets out of the way and lets Amp keep working — so it can't lock you out.
49
49
 
50
- From any project where you'd like Ory authentication, inside Amp:
50
+ ### See what's happening
51
51
 
52
- 1. **Start a local Ory instance.** Ask Amp *"start the local Ory stack"* or invoke the `ory-local-up` skill. A banner prints the seeded test user's email and password — note them.
53
- 2. **Scaffold Ory into your project.** Ask Amp *"add Ory auth to this app"* (the `ory-auth-setup` skill). It installs Ory Elements, wires the SDK, and generates the login / registration / recovery / settings pages, all targeting the local stack.
54
- 3. **Sign in.** Start your app, visit the login page, and sign in with the seeded credentials. You now have a real Ory session backed by a real Ory stack — locally, offline, zero configuration.
52
+ Everything the plugin does is observable out of the box no configuration required:
55
53
 
56
- Continue to [Agent security](#agent-security) when you're ready to enforce.
54
+ - **Status at a glance.** `npx -y -p @ory/amp ory-amp status` shows what's configured, who's signed in, how many built-in tools your permissions cover, and the most recent tool-call activity.
55
+ - **Live traces.** Every tool call is recorded as an OpenTelemetry-style span. Watch them stream as the agent works:
57
56
 
58
- ## How the integration works
57
+ ```bash
58
+ npx -y -p @ory/amp ory-amp watch
59
+ ```
59
60
 
60
- Amp's Ory integration is a **hybrid** of two mechanisms:
61
+ Spans are also written to `~/.config/ory-agent-plugins/amp/ory-agent-trace.ndjson` (NDJSON, one span per line) — tail that file, or point `OTEL_EXPORTER_OTLP_ENDPOINT` at a collector to ship them straight to Jaeger, Honeycomb, or Grafana.
62
+ - **Debug log.** For a verbose play-by-play, set `ORY_AGENT_DEBUG=true`; structured logs land in `~/.config/ory-agent-plugins/amp/ory-agent-debug.log`.
61
63
 
62
- - **Blocking gate — a permission delegate helper (`ory-amp-permission`).** Registered in `amp.permissions`, Amp invokes it per tool call with the tool params on stdin and decides by **exit code**: `0` = allow, `1` = ask, `≥2` = reject (stderr is surfaced to the model). This is the only part that can block. Amp enforces a 10-second delegate timeout and treats a delegate that outlives it as a reject, so the delegate applies its own deadline to the Ory permission check (default 5 seconds, configurable via `ORY_AMP_CHECK_TIMEOUT_MS`) and fails open (allows) when the check is slow, hanging, or unreachable.
63
- - **Advisory in-process plugin (`.amp/plugins/ory.ts`).** Discovered by Amp's Bun runtime, it handles session-start auth (advisory — it cannot hard-block at session start) and post-tool audit tracing.
64
+ ### Ready to enforce?
64
65
 
65
- The phases map as:
66
+ When the watch-mode logs look right, turn on blocking with one command (setup already granted you the built-in tools):
66
67
 
67
- - **Session start** (in-process plugin) — run the user and agent auth gates; advisory.
68
- - **Per-tool decision** (delegate) check the tool against Ory Permissions; in enforce mode a deny exits `2` (reject), in observe mode it records a `permission.observe_deny` span and allows (exit `0`).
69
- - **Post-tool** (in-process plugin) — trace-only audit spans.
68
+ ```bash
69
+ npx -y -p @ory/amp ory-amp permissions enforce
70
+ ```
70
71
 
71
- The plugin is **fail-open** on its own infrastructure failures (network errors, rate limits, missing config): the agent always starts, and enforcement is only as strong as your permission grants.
72
+ Now a denied tool is actually blocked and Amp shows why. Go back to watch mode anytime with `permissions observe`. Use `permissions status` to see what's covered and `permissions bootstrap` to (re-)grant the built-in tools.
72
73
 
73
- ## Agent security
74
+ <details>
75
+ <summary>How the plugin plugs into Amp</summary>
74
76
 
75
- Once pointed at an Ory project (local or hosted), Amp's session and every tool call can be governed by Ory.
77
+ Amp gets the plugin in two pieces that work together:
76
78
 
77
- - **Authentication.** The human at the keyboard (the **user**) authenticates interactively via Ory Identities when user login is on (`ORY_USER_LOGIN=true`, off by default browser PKCE flow on first session, persisted thereafter). The Amp process (the **agent**) gets its own OAuth2 identity via [Dynamic Client Registration (RFC 7591)](https://datatracker.ietf.org/doc/html/rfc7591) on first run.
78
- - **Authorization.** Before any tool runs, the delegate checks [Ory Permissions](https://www.ory.com/docs/keto) (Zanzibar-style relations) against the user's subject and rejects on `deny`.
79
- - **Audit.** Every decision is recorded as a structured trace span (NDJSON file and/or OTLP export).
79
+ - **A permission gate** registered in Amp's settings (`~/.config/amp/settings.json`) under the `amp.permissions` key. Before every tool call, Amp hands the tool and its params to this gate and reads the answer from its **exit code**: `0` = allow, `1` = ask, `≥2` = reject (the reason on stderr is shown to Amp). This is the piece that can actually block.
80
+ - **An in-process plugin** at `<project>/.amp/plugins/ory.ts`, which Amp's built-in TypeScript runtime loads to sign you in at the start of a session and record what happened after each tool runs. It can't block from there, so it's advisory only the gate above does the blocking.
80
81
 
81
- ### Permission modes: observe enforce
82
+ Amp gives the gate 10 seconds to answer and treats a slower gate as a reject, so the plugin sets its own shorter deadline (5 seconds, adjustable with `ORY_AMP_CHECK_TIMEOUT_MS`) and lets the tool through if the Ory check is slow, stuck, or unreachable — it never leaves you hanging.
82
83
 
83
- After install the integration runs in **observe mode**: every tool call is checked, but a deny is recorded as a `permission.observe_deny` audit span and the tool runs anyway.
84
+ The Ory skills land under `<project>/.agents/skills/`. `uninstall` removes the gate, the plugin, and the skills.
84
85
 
85
- ```bash
86
- # Grant the current user `use` on every built-in tool (idempotent):
87
- npx -y -p @ory/amp ory-amp permissions bootstrap
86
+ </details>
88
87
 
89
- # See allowed/denied per tool:
90
- npx -y -p @ory/amp ory-amp permissions status
88
+ ## Also: add login to your own app
91
89
 
92
- # Turn on hard blocking once the observe-mode logs look right:
93
- npx -y -p @ory/amp ory-amp permissions enforce
94
- ```
90
+ Beyond securing Amp, the plugin helps you build Ory into whatever you're working on. The Ory skills are **model-invoked** just ask Amp in plain language and the right one takes over (Amp doesn't use slash commands for these). Ask Amp *"add Ory login to this app"* and it scaffolds the login, registration, recovery, and settings pages (using [Ory Elements](https://github.com/ory/elements)) wired to a local Ory — no signup or keys needed. Start that local Ory by asking *"start the local Ory stack"* (it prints a test email + password to sign in with).
91
+
92
+ More bundled **skills** cover login and social sign-in (Google, GitHub, Apple…), permissions onboarding, and playbooks for wiring Ory into your own agents, E2B sandboxes, or Temporal workers.
95
93
 
96
- Switch back any time with `permissions observe`. To disable Ory entirely (audit logging only), run `ory-amp configure --audit-only`.
94
+ The local Ory runs entirely on your laptop: the Ory APIs at `http://localhost:4000`, a login UI on `:4455` (not `:3000`, to avoid clashing with Next.js dev servers), the Ory Console on `:4100`, and a trace viewer (Jaeger) on `:16686`.
97
95
 
98
- ## Pointing at a real Ory project
96
+ ## Configure by hand (CI / advanced)
99
97
 
100
- The Quickstart uses the local stack. To point at a hosted [Ory Network](https://console.ory.sh) project:
98
+ The guided setup covers most people. For scripted or CI setups, or to point at an existing Ory Network project, configure directly. Settings are saved to `~/.config/ory-agent-plugins/config.json` and shared across all your Ory agent plugins; environment variables win when both are set.
101
99
 
102
100
  ```bash
103
101
  npx -y -p @ory/amp ory-amp configure \
104
- --project-url https://<id>.projects.oryapis.com \
105
- --oauth2-client-id <public OAuth2 client id>
102
+ --project-url https://<slug>.projects.oryapis.com \
103
+ --oauth2-client-id <sign-in client id> \
104
+ --user-login
105
+ ```
106
+
107
+ Amp's own identity registers itself automatically on first run — nothing to create. The `--oauth2-client-id` is the one piece browser sign-in needs (the public client registered with the four loopback callback URLs `http://127.0.0.1:47823..47826/callback`); the guided setup makes it for you. Pass `--api-key ory_pat_...` only to override Amp's auto-created identity with a static token. For logging-only with no checks, use `--audit-only`. The matching env vars are `ORY_PROJECT_URL`, `ORY_OAUTH2_CLIENT_ID`, `ORY_USER_LOGIN`, and `ORY_AGENT_API_KEY`.
108
+
109
+ With nothing configured, the plugin still loads and runs in **pass-through mode**: skills and logging work, but no checks run and nothing is blocked. Perfectly fine if you only want the app-building features.
110
+
111
+ ## Commands
112
+
106
113
  ```
114
+ ory-amp install | uninstall Install/remove; --reconfigure re-runs setup, --no-configure skips it
115
+ ory-amp status Show configuration, identities, permission coverage, and recent activity
116
+ ory-amp watch Tail the live trace stream (OTel spans)
117
+ ory-amp permissions <cmd> status | bootstrap | observe (watch) | enforce (block)
118
+ ory-amp configure <flags> Point at a project by hand (--project-url, --oauth2-client-id, --user-login, --audit-only)
119
+ ory-amp agent <status|unregister> Manage Amp's own auto-created identity
120
+ ```
121
+
122
+ All prefixed with `npx -y -p @ory/amp`.
107
123
 
108
- `--oauth2-client-id` is required whenever `--project-url` is set — the user PKCE flow needs a public OAuth2 client registered with the four loopback redirect URIs (`http://127.0.0.1:47823..47826/callback`). See the [repo README](../../README.md) and [`AGENTS.md`](../../AGENTS.md) for the full environment-variable reference and permission-mode semantics. Config is shared across every Ory agent plugin at `~/.config/ory-agent-plugins/config.json`.
124
+ ## Troubleshooting
109
125
 
110
- Without configuration the plugin still loads cleanly and runs in **pass-through mode**: skills work, but nothing is blocked.
126
+ - **Local Ory fails to start** make sure Docker is running and ports `4000`, `4100`, `4455`, and `16686` are free.
127
+ - **Browser sign-in loops** — reset with `ory-amp agent unregister` and try again.
128
+ - **`npx` grabbed an old version** — force the latest: `npx -y -p @ory/amp@latest ory-amp …`.
129
+ - **A tool check feels slow** — the plugin gives up on a stalled Ory check and lets the tool through; tune the deadline with `ORY_AMP_CHECK_TIMEOUT_MS`.
130
+ - **Want to see what's happening** — `npx -y -p @ory/amp ory-amp status` for a snapshot, `npx -y -p @ory/amp ory-amp watch` for the live trace stream, or set `ORY_AGENT_DEBUG=true` for a verbose log. Traces and logs live under `~/.config/ory-agent-plugins/amp/` (see [See what's happening](#see-whats-happening)).
111
131
 
112
- ## Links
132
+ ## Learn more
113
133
 
114
- - [Ory documentation](https://www.ory.com/docs/)
134
+ - [Ory documentation](https://www.ory.com/docs/) · [Ory Console](https://console.ory.sh) · [Ory Elements](https://github.com/ory/elements)
115
135
  - [Amp documentation](https://ampcode.com)
116
136
  - [Repo README](../../README.md) and [AGENTS.md](../../AGENTS.md) — full env-var and permission-mode reference
117
137
 
package/dist/cli/main.js CHANGED
@@ -52,14 +52,19 @@ function main() {
52
52
  const [command, ...args] = process.argv.slice(2);
53
53
  switch (command) {
54
54
  case "install":
55
+ (0, argus_1.beginDeferNextSteps)();
55
56
  install(args);
56
- postInstallPermissions("ory-amp", "amp").then(() => process.exit(0), (err) => {
57
+ (0, argus_1.runPostInstall)("ory-amp", "amp", args).then(() => process.exit(0), (err) => {
57
58
  console.error(err.message ?? err);
58
59
  process.exit(1);
59
60
  });
60
61
  break;
61
62
  case "uninstall":
62
63
  uninstall(args);
64
+ (0, argus_1.clearCredentialsForUninstall)().then(() => process.exit(0), (err) => {
65
+ console.error(err.message ?? err);
66
+ process.exit(1);
67
+ });
63
68
  break;
64
69
  case "configure":
65
70
  (0, argus_1.runConfigureCommand)("ory-amp", args);
@@ -91,6 +96,9 @@ function main() {
91
96
  process.exit(1);
92
97
  });
93
98
  break;
99
+ case "watch":
100
+ (0, argus_1.runWatchCommand)("amp", args);
101
+ break;
94
102
  case "help":
95
103
  case "--help":
96
104
  case "-h":
@@ -117,12 +125,6 @@ function uninstall(args) {
117
125
  process.argv = ["node", "setup.js", "--uninstall", ...args];
118
126
  require("./setup.js");
119
127
  }
120
- async function postInstallPermissions(binName, harness) {
121
- const bootstrapped = await (0, argus_1.maybeAutoBootstrap)(binName, harness);
122
- (0, argus_1.printPermissionsOnboardingHelp)(binName, harness, {
123
- bootstrappedAutomatically: bootstrapped,
124
- });
125
- }
126
128
  function parseProjectDir(args) {
127
129
  const idx = args.indexOf("--project-dir");
128
130
  if (idx !== -1 && args[idx + 1])
@@ -175,6 +177,7 @@ Commands:
175
177
  (status, bootstrap, observe, enforce)
176
178
  setup [--project-dir <path>] Write config directly (fallback)
177
179
  status [--project-dir <path>] Show plugin configuration and status
180
+ watch [trace-file] Tail the trace stream (OTel spans) live
178
181
  local <cmd> Manage local Ory dev environment
179
182
  (up, down, status, seed, logs, env, configure, reset)
180
183
 
@@ -184,7 +187,7 @@ After installing, the Ory integration runs in two parts:
184
187
 
185
188
  Examples:
186
189
  npx -y -p @ory/amp ory-amp install
187
- npx -y -p @ory/amp ory-amp configure --project-url https://<id>.projects.oryapis.com
190
+ npx -y -p @ory/amp ory-amp configure --project-url https://<slug>.projects.oryapis.com
188
191
  npx -y -p @ory/amp ory-amp permissions bootstrap
189
192
  npx -y -p @ory/amp ory-amp status
190
193
  `);
package/dist/cli/setup.js CHANGED
@@ -192,6 +192,18 @@ function main() {
192
192
  console.log(` Delegate: ${DELEGATE_BIN} (tool: "*", action: delegate)`);
193
193
  console.log(`Ory in-process plugin written to ${pluginFile}`);
194
194
  console.log(`Ory skills installed under ${skillsDir}`);
195
- (0, argus_1.printNextSteps)("Amp", "npx ory-amp-setup --uninstall");
195
+ (0, argus_1.printNextSteps)("Amp", "npx -y -p @ory/amp ory-amp-setup --uninstall", {
196
+ binName: "ory-amp",
197
+ harness: "amp",
198
+ });
196
199
  }
197
200
  main();
201
+ // When invoked directly as the `-setup` bin with `--uninstall`, also clear
202
+ // stored Ory credentials. When required by the plugin's main CLI, that
203
+ // command owns the purge, so the `require.main` guard prevents a double run.
204
+ if (require.main === module && process.argv.includes("--uninstall")) {
205
+ (0, argus_1.clearCredentialsForUninstall)().then(() => process.exit(0), (err) => {
206
+ console.error(err.message ?? err);
207
+ process.exit(1);
208
+ });
209
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ory/amp",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Ory plugin for Amp (Sourcegraph's coding agent): a permission delegate that authorizes every tool call plus an in-process plugin for session auth and audit tracing",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://ory.com",
@@ -67,7 +67,7 @@
67
67
  "!dist/**/*.tsbuildinfo"
68
68
  ],
69
69
  "dependencies": {
70
- "@ory/argus": "0.11.0"
70
+ "@ory/argus": "0.12.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "typescript": "^6.0.2",