@ory/opencode 0.11.1 → 0.12.1

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,52 +1,46 @@
1
1
  # Ory Agent Plugin: OpenCode
2
2
 
3
- [Ory](https://ory.com) bundled into [OpenCode](https://opencode.ai): skills and markdown commands 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 OpenCode runs.
3
+ Security and developer experience for [OpenCode](https://opencode.ai), 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.** OpenCode 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; OpenCode 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 — it provides 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 (login, registration, recovery, settings). 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. Everything in the Quickstart below works against it, fully offline.
11
+ - [OpenCode](https://opencode.ai), 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
- This plugin does two independent things, and you can use either on its own:
16
+ ## Get started
15
17
 
16
- 1. **Build auth into your app.** Have OpenCode scaffold Ory login, registration, social sign-in, and permissions into the project you're working on, backed by the local stack. This is the Quickstart below — it needs nothing but Docker.
17
- 2. **Govern the agent itself.** Authenticate OpenCode's own session and authorize every tool it runs against Ory Permissions, with a full audit trail. See [Agent security](#agent-security).
18
-
19
- If you're just exploring, do the Quickstart first.
20
-
21
- ## Prerequisites
22
-
23
- - [OpenCode](https://opencode.ai) 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.
27
-
28
- ## Install
29
-
30
- Run the installer from your project directory:
18
+ Run one command. It installs the plugin and walks you through connecting:
31
19
 
32
20
  ```bash
33
21
  npx -y -p @ory/opencode ory-opencode install
34
22
  ```
35
23
 
36
- This writes the plugin into `opencode.json`, registers the Ory MCP server, and drops the Ory skill catalog into `.opencode/skills/` and the local-stack slash commands into `.opencode/commands/ory/`. Run `npx -y -p @ory/opencode ory-opencode uninstall` to reverse it.
24
+ You'll be asked how you want to connect — **press Enter for the default**:
25
+
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 OpenCode does.
37
29
 
38
- Then confirm everything landed:
30
+ That's it. Confirm everything landed with:
39
31
 
40
32
  ```bash
41
33
  npx -y -p @ory/opencode ory-opencode status
42
34
  ```
43
35
 
44
- `status` is the single source of truth — it prints configuration, user and agent identity, per-tool permission coverage, plugin + skill registration, and a tail of recent debug logs. Unconfigured fields show inline as `(unset)`.
36
+ `status` is your one-stop check: what's configured, who's signed in, which tools are covered by permissions, and recent activity. Anything not set up yet shows as `(unset)`.
37
+
38
+ The installer registers the plugin in OpenCode's config (`opencode.json`) along with the Ory MCP server, a set of skills in `.opencode/skills/`, and the local-stack slash commands. Re-run install with `--reconfigure` to change your connection later, or `--no-configure` to skip the wizard. `ory-opencode uninstall` reverses it all.
45
39
 
46
40
  <details>
47
- <summary>Alternative install: edit opencode.json by hand</summary>
41
+ <summary>Prefer to register the plugin by hand?</summary>
48
42
 
49
- If you want only the plugin (no MCP server, no skills, no slash commands), add it directly to `opencode.json`:
43
+ OpenCode loads the plugin in-process from `opencode.json`. If you only want the plugin — no MCP server, skills, or slash commands, and no guided setup — add it directly:
50
44
 
51
45
  ```json
52
46
  {
@@ -55,120 +49,67 @@ If you want only the plugin (no MCP server, no skills, no slash commands), add i
55
49
  }
56
50
  ```
57
51
 
58
- OpenCode fetches the plugin from npm on next launch. The Quickstart below will not work via this path — `/ory:local-up` and the scaffolding skills only land on disk when you run the installer.
52
+ OpenCode fetches it from npm on next launch. Connect afterwards by running `ory-opencode install` (or `configure`) in a terminal — that's also what lands the skills and `/ory:` commands on disk.
59
53
 
60
54
  </details>
61
55
 
62
- ## Quickstart (≈ 3 minutes)
63
-
64
- From any project where you'd like Ory authentication, inside OpenCode:
65
-
66
- 1. **Start a local Ory instance.** Ask OpenCode *"start the local Ory stack"* or run:
67
-
68
- ```
69
- /ory:local-up
70
- ```
71
-
72
- A banner prints the seeded test user's email and password. Note them — you'll log in with them in step 3.
73
-
74
- 2. **Scaffold Ory into your project.** Ask OpenCode *"add Ory auth to this app"* or invoke the `ory-auth-setup` skill.
75
-
76
- OpenCode installs Ory Elements, wires the SDK, generates the login / registration / recovery / verification / settings pages, and sets up session middleware. It targets the local stack from step 1, so no signup or API key is needed.
77
-
78
- 3. **Sign in.** Start your app, visit the login page OpenCode added, and sign in with the seeded credentials. You now have a real Ory session backed by a real Ory stack — locally, offline, with zero configuration.
79
-
80
- 4. **Turn on Ory login for the OpenCode session itself.** *(Optional but recommended.)* Out of the box the plugin only governs your *app*. To also attach an Ory identity to *OpenCode's* session — so every tool call is attributed to you, not a fallback `session:<id>` subject — opt in to the user-login flow:
56
+ ## What you get
81
57
 
82
- ```bash
83
- export ORY_USER_LOGIN=true
84
- export ORY_OAUTH2_CLIENT_ID=<value printed by `local up`>
85
- ```
58
+ Once connected, every tool OpenCode runs is governed by Ory — three things happen automatically:
86
59
 
87
- User login is off by default. Both exports above are printed in the `local up` banner — copy them straight from there. `ORY_OAUTH2_CLIENT_ID` is required whenever `ORY_USER_LOGIN` is on: it identifies the public OAuth2 client the PKCE browser flow exchanges for a token. With both set, the next OpenCode session opens an Ory login in your browser; sign in with the same seeded credentials from step 1, and the token is reused on subsequent sessions until it expires. This is what makes `permissions enforce` (see [Agent security](#agent-security)) deny on the right identity later. (Note: OpenCode's session-start primitive can't hard-block, so the flow runs in advisory mode at session start — auth still happens and the audit trail is correct, but the session always proceeds. Per-tool enforcement at `permission.ask` is unaffected.)
60
+ - **Who's driving.** You sign in once in your browser; OpenCode gets its own identity too. No tokens to copy around, and the "who acted on whose behalf" trail stays queryable later — even after tokens expire. (One nuance: OpenCode can't hard-block at session start, so browser sign-in there is advisory — it still runs and records correctly, the session just always proceeds. Per-tool checks are unaffected.)
61
+ - **What it's allowed to do.** When OpenCode asks to use a tool, 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.
62
+ - **A record of everything.** Every decision (allowed, denied, skipped) is logged as a trace you can send to Jaeger, Honeycomb, Grafana, or just a file.
88
63
 
89
- That's the full Ory DX path. Stop here if you're just evaluating the plugin. Continue to [Agent security](#agent-security) when you're ready to enforce.
64
+ If Ory is ever unreachable, the plugin gets out of the way and lets OpenCode keep working — so it can't lock you out.
90
65
 
91
- ## What's included
66
+ ### See what's happening
92
67
 
93
- ### Skills for scaffolding Ory into your application
68
+ Everything the plugin does is observable out of the box — no configuration required:
94
69
 
95
- Each skill is a vetted, end-to-end playbook. Ask OpenCode in natural language or invoke a skill directly:
70
+ - **Status at a glance.** `npx -y -p @ory/opencode ory-opencode status` shows what's configured, who's signed in, how many built-in tools your permissions cover, and the most recent tool-call activity.
71
+ - **Live traces.** Every tool call is recorded as an OpenTelemetry-style span. Watch them stream as the agent works:
96
72
 
97
- **Start here — add Ory auth to your app:**
73
+ ```bash
74
+ npx -y -p @ory/opencode ory-opencode watch
75
+ ```
98
76
 
99
- - **`ory-auth-setup`** — full project setup. Install the Ory CLI, create an Ory Network project (or use the local one), add Ory Elements, configure the SDK, build the auth pages, wire session middleware.
100
- - **`ory-login-flow`** — login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
101
- - **`ory-social-login`** — Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
102
- - **`ory-local-dev`** — drive the local Ory stack from within OpenCode to prototype and test without a remote project.
77
+ Spans are also written to `~/.config/ory-agent-plugins/opencode/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.
78
+ - **Debug log.** For a verbose play-by-play, set `ORY_AGENT_DEBUG=true`; structured logs land in `~/.config/ory-agent-plugins/opencode/ory-agent-debug.log`.
103
79
 
104
- **Going further:**
80
+ ### Ready to enforce?
105
81
 
106
- - **`ory-permissions-onboarding`** — bootstrap permissions for built-in tools, switch between observe and enforce mode, troubleshoot denials.
107
- - **`ory-build-integration`** — pull the runnable subset of an `ory/integrates` template (webhook / config / http-event) into your own app and wire it to your Ory project — no contribution/registry concerns.
108
- - **`ory-contribute-integration`** — author a brand-new integration as a contribution to `ory/integrates`, including `registry.entry.yaml`, the `Maintained by:` footer, DCO sign-off, and registry regeneration.
109
- - **`ory-e2b-sandbox`** — scaffold an [E2B](https://e2b.dev) sandbox template that boots with this plugin preinstalled and registered, so every sandbox session is gated by Ory auth, permissions, and tracing without any per-sandbox setup.
110
- - **`ory-build-agent`** — drop `@ory/argus` directly into a custom agent you own (Claude Agent SDK, OpenAI Agents SDK, Mastra, Vercel AI SDK, PydanticAI, LangGraph, Mistral AI, or Salesforce Agentforce) so the user is authenticated, every tool call is authorized against Ory Permissions, and the lifecycle emits trace spans.
111
- - **`ory-temporal-worker`** — scaffold a [Temporal](https://temporal.io) TypeScript worker per the [official local-dev guide](https://docs.temporal.io/develop/typescript/set-up-your-local-typescript), with every Activity gated by an Ory permission check, the worker's agent identity resolved via DCR, and the full lifecycle emitting trace spans.
82
+ When the watch-mode logs look right, turn on blocking with one command (setup already granted you the built-in tools):
112
83
 
113
- ### Ory MCP server
114
-
115
- Bundled and registered by the Ory installer. Exposes the Ory CLI and the Ory Network REST API as MCP tools so OpenCode can manage identities, OAuth2 clients, projects, permissions, and configuration without ever leaving the chat. Useful for seeding test data, verifying a scaffolded integration, or running one-off admin tasks.
116
-
117
- ### Local Ory stack
118
-
119
- ```
120
- /ory:local-up # start a local Ory instance in Docker
121
- /ory:local-down # tear it all down
122
- /ory:temporal-up # start a local Temporal dev server (for ory-temporal-worker)
84
+ ```bash
85
+ npx -y -p @ory/opencode ory-opencode permissions enforce
123
86
  ```
124
87
 
125
- `local-up` runs a complete Ory on your laptop: the Ory APIs (Identities, OAuth2, Permissions) at `http://localhost:4000`, a login UI on `:4455` (not :3000, to avoid Next.js port conflicts), and Jaeger (the trace viewer) on `:16686`. A test user identity is seeded and its credentials are printed for you. Use it to:
88
+ Now a denied tool is actually blocked and OpenCode shows why. In watch mode, OpenCode's own permission prompt is left in place for you to answer; only an explicit allow or a block-mode deny changes that. 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 — or just ask OpenCode in chat, e.g. *"grant me use of the bash tool."*
126
89
 
127
- - **Learn Ory hands-on** without signing up for a hosted project.
128
- - **Prototype** flows (login, social, MFA, recovery, permissions) against a real Ory backend.
129
- - **Test** an auth integration end-to-end before pushing anything to a real environment.
130
- - **Develop** your application against the same identity, OAuth2, and permission surfaces you'll ship with.
90
+ ## Also: add login to your own app
131
91
 
132
- ## Pointing at a real Ory project
92
+ Beyond securing OpenCode, the plugin helps you build Ory into whatever you're working on. Ask OpenCode *"add Ory login to this app"* and it scaffolds the login, registration, recovery, verification, 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 with `/ory:local-up` (it prints a test email + password to sign in with) and tear it down with `/ory:local-down`.
133
93
 
134
- The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project (Ory's managed cloud), point the plugin at it with a single configure command. **The plugin requires `--oauth2-client-id` whenever `--project-url` is provided** — register the client first (see [Register the user OAuth2 client](#register-the-user-oauth2-client) below), then run:
94
+ Bundled **skills** (just ask in plain language) cover more: `ory-auth-setup`, `ory-login-flow`, `ory-social-login` (Google, GitHub, Apple…), `ory-permissions-onboarding`, and playbooks for wiring Ory into your own agents, E2B sandboxes, or Temporal workers. A built-in **Ory MCP server** lets OpenCode manage identities, projects, and permissions straight from chat.
135
95
 
136
- ```bash
137
- npx -y -p @ory/opencode ory-opencode configure \
138
- --project-url https://<id>.projects.oryapis.com \
139
- --oauth2-client-id <public OAuth2 client id>
140
- ```
96
+ ## Configure by hand (CI / advanced)
141
97
 
142
- - **`--project-url`** points the plugin at your project. The **agent identity** (machine credentials for OpenCode's outgoing Ory API calls) is created automatically on first run via OAuth2 Dynamic Client Registration ([RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591)) against the project's `/oauth2/register` endpoint — no manual step required for that one.
143
- - **`--oauth2-client-id`** is required because the **user** PKCE browser flow (triggered by `ORY_USER_LOGIN=true`) cannot self-register — you must register a public OAuth2 client ahead of time and supply its id here. The configure command refuses to save a project URL without it, so you don't end up with a silently-broken setup later. See [Register the user OAuth2 client](#register-the-user-oauth2-client) below for the exact CLI / Console steps.
144
- - **`--api-key ory_pat_...`** is optional — pass it only if you want to override the auto-registered agent identity with a static personal access token (operator override; rarely needed).
145
-
146
- If you only want audit logging (no auth or permission checks), substitute `--audit-only` — the OAuth2 client id is not required in that mode:
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.
147
99
 
148
100
  ```bash
149
- npx -y -p @ory/opencode ory-opencode configure --audit-only
101
+ npx -y -p @ory/opencode ory-opencode configure \
102
+ --project-url https://<slug>.projects.oryapis.com \
103
+ --oauth2-client-id <sign-in client id> \
104
+ --user-login
150
105
  ```
151
106
 
152
- The same settings can be supplied via environment variables (`ORY_PROJECT_URL`, `ORY_OAUTH2_CLIENT_ID`, `ORY_AGENT_API_KEY`) — env vars take precedence over the config file when both are set, which is what most CI / scripted setups want.
153
-
154
- Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine.
155
-
156
- Without configuration the plugin still loads cleanly and runs in **pass-through mode**: skills and commands work, but nothing is blocked. You can stay in pass-through mode indefinitely if you only want the DX features.
157
-
158
- ### Register the user OAuth2 client
159
-
160
- If you plan to turn on `ORY_USER_LOGIN=true` (recommended — it's what attributes every tool call to *you* rather than a fallback `session:<id>` subject), your hosted Ory project needs a **public** OAuth2 client (no client secret) registered ahead of time. The local stack provisions this for you automatically; against a hosted project you have to register it once yourself.
161
-
162
- The client must list **all four** loopback ports as redirect URIs:
107
+ OpenCode'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 guided setup makes it for you, or see below to do it by hand. For logging-only with no checks, use `--audit-only`. The equivalent env vars are `ORY_PROJECT_URL`, `ORY_OAUTH2_CLIENT_ID`, `ORY_USER_LOGIN`, and `ORY_AGENT_API_KEY`.
163
108
 
164
- - `http://127.0.0.1:47823/callback`
165
- - `http://127.0.0.1:47824/callback`
166
- - `http://127.0.0.1:47825/callback`
167
- - `http://127.0.0.1:47826/callback`
168
-
169
- The plugin walks the four ports at runtime so the login can survive any one of them being occupied — Ory rejects the callback if the port it lands on isn't on the registered list, so register all four.
109
+ <details>
110
+ <summary>Create the sign-in client by hand</summary>
170
111
 
171
- Create the client with the [Ory CLI](https://www.ory.com/docs/guides/cli/installation):
112
+ The guided setup normally does this. To do it yourself, create a **public** OAuth2 client (no secret) listing all four loopback URLs — the plugin tries each in turn so sign-in survives a busy port:
172
113
 
173
114
  ```bash
174
115
  ory create oauth2-client --project <project-id> \
@@ -183,103 +124,37 @@ ory create oauth2-client --project <project-id> \
183
124
  --redirect-uri http://127.0.0.1:47826/callback
184
125
  ```
185
126
 
186
- …or in the [Ory Console](https://console.ory.sh) under *OAuth2* → *Clients* → *Create client* (pick "Public client", set "Authorization Code" + "Refresh Token" grants, scopes `openid offline_access`, paste the four redirect URIs above). Then persist the issued id with the configure command (preferred — survives across sessions):
187
-
188
- ```bash
189
- npx -y -p @ory/opencode ory-opencode configure \
190
- --project-url https://<id>.projects.oryapis.com \
191
- --oauth2-client-id <client-id from the step above>
192
- ```
193
-
194
- …or set it in the environment alongside `ORY_USER_LOGIN`:
195
-
196
- ```bash
197
- export ORY_USER_LOGIN=true
198
- export ORY_OAUTH2_CLIENT_ID=<client-id from the step above>
199
- ```
200
-
201
- Headless / CI runs that already hold a session token can skip this entirely by setting `ORY_USER_SESSION_TOKEN` instead — no browser flow runs, so no OAuth2 client is needed.
202
-
203
- ## Agent security
204
-
205
- Once the plugin is pointed at an Ory project (local or hosted), OpenCode's session and every tool call can be governed by Ory.
206
-
207
- - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when user login is enabled (`ORY_USER_LOGIN=true`, off by default — browser PKCE flow on first session, persisted token thereafter). The OpenCode process (the **agent**) gets its own OAuth2 identity, self-registered via [Dynamic Client Registration (RFC 7591)](https://datatracker.ietf.org/doc/html/rfc7591) on first run.
208
- - **Authorization.** When OpenCode prompts for permission to use a tool, the plugin checks [Ory Permissions](https://www.ory.com/docs/keto) (Zanzibar-style relations) against the user's subject. In **enforce** mode a deny blocks the tool by throwing an `OryDenialError` (OpenCode surfaces the denial reason); in **observe** mode (default) the deny is recorded as a `permission.observe_deny` span and OpenCode's own permission prompt is left in place — the plugin only answers the prompt on an explicit Ory allow or an enforce-mode deny, never on an observe-mode deny or an infrastructure failure. A parallel pre-tool check is recorded as part of the audit trail. MCP tool calls additionally get a server-level check.
209
- - **Audit.** Every decision (allow, deny, fallback) is recorded as a structured trace span: NDJSON file output and/or OTLP/HTTP export to Jaeger, Honeycomb, Grafana, and similar collectors. The user → agent delegation is written to Ory as a relation so *"agent X acting on behalf of user Y"* stays queryable after tokens expire.
210
-
211
- The plugin is **fail-open** on its own infrastructure failures (network errors, rate limits, missing config), so enforcement is only as strong as your permission grants — grant explicit `use` on the tools each user should be able to run.
127
+ …or in the [Ory Console](https://console.ory.sh) under *OAuth2* → *Clients* → *Create client* (pick "Public client", "Authorization Code" + "Refresh Token" grants, scopes `openid offline_access`, and paste the four redirect URIs). Pass the resulting id to `configure --oauth2-client-id`. Running headless with a session token already? Set `ORY_USER_SESSION_TOKEN` and skip the browser step entirely.
212
128
 
213
- ### Enable enforcement
214
-
215
- After install the plugin runs in **observe mode**: every tool call is checked against Ory Permissions, but a deny is recorded as a `permission.observe_deny` audit span and the tool runs anyway (and at OpenCode's permission prompt, the native ask is left for the user to answer). This lets you see what *would* be blocked before turning on hard blocking.
216
-
217
- 1. **Turn on user login.** It's off by default. In your shell:
218
-
219
- ```bash
220
- export ORY_USER_LOGIN=true
221
- export ORY_OAUTH2_CLIENT_ID=<public OAuth2 client id>
222
- ```
223
-
224
- The next OpenCode session refreshes or prompts for PKCE login. Subsequent sessions reuse the persisted token until it expires.
225
-
226
- `ORY_OAUTH2_CLIENT_ID` is required when `ORY_USER_LOGIN` is on: PKCE needs a public OAuth2 client registered with the four loopback redirect URIs (`http://127.0.0.1:47823..47826/callback`) to exchange the authorization code for a token. The local stack provisions one and prints the export in its `local up` banner; for a hosted Ory project see [Register the user OAuth2 client](#register-the-user-oauth2-client) for the exact CLI / Console steps. Headless / CI runs can skip the browser flow entirely by pre-supplying `ORY_USER_SESSION_TOKEN` instead.
227
-
228
- 2. **Bootstrap permissions for the built-in tools.** One idempotent command grants the current user `use` on every tool OpenCode ships with (read, write, edit, bash, …):
229
-
230
- ```bash
231
- npx -y -p @ory/opencode ory-opencode permissions bootstrap
232
- ```
233
-
234
- If a user identity is already cached at install time, the installer runs this for you automatically — re-run after adding tools, switching subjects, or changing the namespace.
235
-
236
- 3. **Check coverage.** `permissions status` probes every tool in the harness's catalog and prints allowed / denied per tool:
237
-
238
- ```bash
239
- npx -y -p @ory/opencode ory-opencode permissions status
240
- ```
241
-
242
- Add permissions for any MCP server tools or custom commands by hand, or via the Ory MCP server from inside OpenCode (*"grant me use on the bash tool"*).
243
-
244
- 4. **Promote to enforce.** Once the observe-mode logs look right, switch over:
245
-
246
- ```bash
247
- npx -y -p @ory/opencode ory-opencode permissions enforce
248
- ```
129
+ </details>
249
130
 
250
- Denies now ask the harness to block via a thrown `OryDenialError`; OpenCode shows the denial reason and the decision is recorded as a `tool.block` trace span. Switch back any time with `permissions observe`.
131
+ With nothing configured, the plugin still loads and runs in **pass-through mode**: skills, commands, and logging work, but no checks run and nothing is blocked. Perfectly fine if you only want the app-building features.
251
132
 
252
- ## CLI reference
133
+ ## Commands
253
134
 
254
135
  ```
255
- npx -y -p @ory/opencode ory-opencode install | uninstall [--project-dir <path>]
256
- npx -y -p @ory/opencode ory-opencode configure [--project-url <url> --oauth2-client-id <id>] [--api-key <key>] [--audit-only]
257
- npx -y -p @ory/opencode ory-opencode agent <status|unregister> Manage the agent's OAuth2 identity
258
- npx -y -p @ory/opencode ory-opencode permissions <status|bootstrap|observe|enforce>
259
- npx -y -p @ory/opencode ory-opencode local <up|down|status|seed|logs|env|configure|reset>
260
- npx -y -p @ory/opencode ory-opencode status [--project-dir <path>]
136
+ ory-opencode install | uninstall Install/remove; --reconfigure re-runs setup, --no-configure skips it
137
+ ory-opencode status Show configuration, identities, permission coverage, recent activity
138
+ ory-opencode watch Tail the live trace stream (OTel spans)
139
+ ory-opencode permissions <cmd> status | bootstrap | observe (watch) | enforce (block)
140
+ ory-opencode configure <flags> Point at a project by hand (--project-url, --oauth2-client-id, --user-login, --audit-only)
141
+ ory-opencode agent <status|unregister> Manage OpenCode's own auto-created identity
142
+ ory-opencode local <up|down|status|…> Run / manage a local Ory in Docker
261
143
  ```
262
144
 
263
- Highlights:
264
-
265
- - `agent status` — show the current persisted DCR identity for the agent.
266
- - `permissions observe` / `permissions enforce` — switch between "log denies, allow through" (the install default) and "block denies." `permissions bootstrap` writes `use` permissions for the harness's built-in tools so the promotion path doesn't require hand-writing relations.
267
- - `configure --audit-only` — kill switch that disables Ory entirely (no auth, no permission checks; only audit logging of tool invocations). For phased rollouts, prefer `permissions observe` over `--audit-only`.
268
- - `local seed` / `local env` — reseed the test user, or print env vars for pointing other tools at the local stack.
145
+ All prefixed with `npx -y -p @ory/opencode`.
269
146
 
270
147
  ## Troubleshooting
271
148
 
272
- - **`/ory:local-up` fails.** Make sure Docker is running and ports `4455` (login UI), `4000`, `4100`, and `16686` are free.
273
- - **PKCE login loops.** Clear persisted state with `npx -y -p @ory/opencode ory-opencode agent unregister` and retry.
274
- - **`npx` fetches an old version.** Force a fresh fetch: `npx -y -p @ory/opencode@latest ory-opencode …`.
275
- - **`npm error code ENOVERSIONS` on install.** Your npm has a supply-chain freshness filter (`min-release-age`) that's hiding all `@ory/opencode` versions newer than its threshold. Either wait it out, or run the installer with `--min-release-age=0`: `npx -y --min-release-age=0 -p @ory/opencode ory-opencode install`.
276
- - **Need more signal.** Set `ORY_AGENT_DEBUG=true` and `ORY_AGENT_LOG_FILE=/tmp/ory.log` to capture structured logs.
149
+ - **`/ory:local-up` fails** — make sure Docker is running and ports `4000`, `4100`, `4455`, and `16686` are free.
150
+ - **Browser sign-in loops** — reset with `ory-opencode agent unregister` and try again.
151
+ - **`npx` grabbed an old version** — force the latest: `npx -y -p @ory/opencode@latest ory-opencode …`.
152
+ - **`npm error code ENOVERSIONS` on install** — your npm has a freshness filter hiding brand-new versions. Wait it out, or run `npx -y --min-release-age=0 -p @ory/opencode ory-opencode install`.
153
+ - **Want to see what's happening** — `npx -y -p @ory/opencode ory-opencode status` for a snapshot, `npx -y -p @ory/opencode ory-opencode 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/opencode/` (see [See what's happening](#see-whats-happening)).
277
154
 
278
- ## Links
155
+ ## Learn more
279
156
 
280
- - [Ory documentation](https://www.ory.com/docs/)
281
- - [Ory Network console](https://console.ory.sh)
282
- - [Ory Elements](https://github.com/ory/elements)
157
+ - [Ory documentation](https://www.ory.com/docs/) · [Ory Console](https://console.ory.sh) · [Ory Elements](https://github.com/ory/elements)
283
158
  - [OpenCode documentation](https://opencode.ai)
284
159
 
285
160
  ## License
package/dist/cli/main.js CHANGED
@@ -50,14 +50,19 @@ function main() {
50
50
  const [command, ...args] = process.argv.slice(2);
51
51
  switch (command) {
52
52
  case "install":
53
+ (0, argus_1.beginDeferNextSteps)();
53
54
  install(args);
54
- postInstallPermissions("ory-opencode", "opencode").then(() => process.exit(0), (err) => {
55
+ (0, argus_1.runPostInstall)("ory-opencode", "opencode", args).then(() => process.exit(0), (err) => {
55
56
  console.error(err.message ?? err);
56
57
  process.exit(1);
57
58
  });
58
59
  break;
59
60
  case "uninstall":
60
61
  uninstall(args);
62
+ (0, argus_1.clearCredentialsForUninstall)().then(() => process.exit(0), (err) => {
63
+ console.error(err.message ?? err);
64
+ process.exit(1);
65
+ });
61
66
  break;
62
67
  case "configure":
63
68
  (0, argus_1.runConfigureCommand)("ory-opencode", args);
@@ -86,6 +91,9 @@ function main() {
86
91
  process.exit(1);
87
92
  });
88
93
  break;
94
+ case "watch":
95
+ (0, argus_1.runWatchCommand)("opencode", args);
96
+ break;
89
97
  case "help":
90
98
  case "--help":
91
99
  case "-h":
@@ -98,12 +106,6 @@ function main() {
98
106
  process.exit(1);
99
107
  }
100
108
  }
101
- async function postInstallPermissions(binName, harness) {
102
- const bootstrapped = await (0, argus_1.maybeAutoBootstrap)(binName, harness);
103
- (0, argus_1.printPermissionsOnboardingHelp)(binName, harness, {
104
- bootstrappedAutomatically: bootstrapped,
105
- });
106
- }
107
109
  function parseProjectDir(args) {
108
110
  const idx = args.indexOf("--project-dir");
109
111
  if (idx !== -1 && args[idx + 1])
@@ -219,6 +221,7 @@ Commands:
219
221
  local <cmd> Manage local Ory dev environment
220
222
  (up, down, status, seed, logs, env, configure, reset)
221
223
  status [--project-dir <path>] Show plugin configuration and status
224
+ watch [trace-file] Tail the trace stream (OTel spans) live
222
225
 
223
226
  After installing, the plugin registers these OpenCode hooks:
224
227
  config Log resolved Ory config at startup
@@ -229,7 +232,7 @@ After installing, the plugin registers these OpenCode hooks:
229
232
 
230
233
  Examples:
231
234
  npx -y -p @ory/opencode ory-opencode install
232
- npx -y -p @ory/opencode ory-opencode configure --project-url https://<id>.projects.oryapis.com --api-key ory_pat_...
235
+ npx -y -p @ory/opencode ory-opencode configure --project-url https://<slug>.projects.oryapis.com --api-key ory_pat_...
233
236
  npx -y -p @ory/opencode ory-opencode permissions bootstrap
234
237
  npx -y -p @ory/opencode ory-opencode local up
235
238
  npx -y -p @ory/opencode ory-opencode status
package/dist/cli/setup.js CHANGED
@@ -142,6 +142,18 @@ function main() {
142
142
  (0, assets_js_1.installOpencodeOryAssets)(args.projectDir);
143
143
  console.log(`Ory plugin and MCP server configured in ${configPath}`);
144
144
  console.log(`Ory skills and commands installed to ${path.join(args.projectDir, ".opencode")}`);
145
- (0, argus_1.printNextSteps)("OpenCode", "npx ory-opencode-setup --uninstall");
145
+ (0, argus_1.printNextSteps)("OpenCode", "npx -y -p @ory/opencode ory-opencode-setup --uninstall", {
146
+ binName: "ory-opencode",
147
+ harness: "opencode",
148
+ });
146
149
  }
147
150
  main();
151
+ // When invoked directly as the `-setup` bin with `--uninstall`, also clear
152
+ // stored Ory credentials. When required by the plugin's main CLI, that
153
+ // command owns the purge, so the `require.main` guard prevents a double run.
154
+ if (require.main === module && process.argv.includes("--uninstall")) {
155
+ (0, argus_1.clearCredentialsForUninstall)().then(() => process.exit(0), (err) => {
156
+ console.error(err.message ?? err);
157
+ process.exit(1);
158
+ });
159
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ory/opencode",
3
- "version": "0.11.1",
3
+ "version": "0.12.1",
4
4
  "description": "Ory plugin for OpenCode: scaffolding skills, a local Ory instance, and authentication, authorization, and audit for every tool call",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://ory.com",
@@ -63,7 +63,8 @@
63
63
  "!dist/**/*.tsbuildinfo"
64
64
  ],
65
65
  "dependencies": {
66
- "@ory/argus": "0.11.1"
66
+ "reo-census": "^1.2.8",
67
+ "@ory/argus": "0.12.1"
67
68
  },
68
69
  "engines": {
69
70
  "node": ">=22"