@ory/opencode 0.8.2 → 0.9.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 +97 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
You don't need an Ory account or any prior Ory experience to start.
|
|
6
6
|
|
|
7
|
+
## New to Ory?
|
|
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:
|
|
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.
|
|
13
|
+
|
|
14
|
+
This plugin does two independent things, and you can use either on its own:
|
|
15
|
+
|
|
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
|
+
|
|
7
21
|
## Prerequisites
|
|
8
22
|
|
|
9
23
|
- [OpenCode](https://opencode.ai) installed
|
|
@@ -66,10 +80,11 @@ From any project where you'd like Ory authentication, inside OpenCode:
|
|
|
66
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:
|
|
67
81
|
|
|
68
82
|
```bash
|
|
69
|
-
export ORY_USER_LOGIN=
|
|
83
|
+
export ORY_USER_LOGIN=true
|
|
84
|
+
export ORY_OAUTH2_CLIENT_ID=<value printed by `local up`>
|
|
70
85
|
```
|
|
71
86
|
|
|
72
|
-
User login is off by default.
|
|
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.)
|
|
73
88
|
|
|
74
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.
|
|
75
90
|
|
|
@@ -79,11 +94,16 @@ That's the full Ory DX path. Stop here if you're just evaluating the plugin. Con
|
|
|
79
94
|
|
|
80
95
|
Each skill is a vetted, end-to-end playbook. Ask OpenCode in natural language or invoke a skill directly:
|
|
81
96
|
|
|
97
|
+
**Start here — add Ory auth to your app:**
|
|
98
|
+
|
|
82
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.
|
|
83
100
|
- **`ory-login-flow`** — login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
|
|
84
101
|
- **`ory-social-login`** — Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
|
|
85
102
|
- **`ory-local-dev`** — drive the local Ory stack from within OpenCode to prototype and test without a remote project.
|
|
86
|
-
|
|
103
|
+
|
|
104
|
+
**Going further:**
|
|
105
|
+
|
|
106
|
+
- **`ory-permissions-onboarding`** — bootstrap permissions for built-in tools, switch between observe and enforce mode, troubleshoot denials.
|
|
87
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.
|
|
88
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.
|
|
89
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.
|
|
@@ -92,7 +112,7 @@ Each skill is a vetted, end-to-end playbook. Ask OpenCode in natural language or
|
|
|
92
112
|
|
|
93
113
|
### Ory MCP server
|
|
94
114
|
|
|
95
|
-
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,
|
|
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.
|
|
96
116
|
|
|
97
117
|
### Local Ory stack
|
|
98
118
|
|
|
@@ -102,36 +122,93 @@ Bundled and registered by the Ory installer. Exposes the Ory CLI and the Ory Net
|
|
|
102
122
|
/ory:temporal-up # start a local Temporal dev server (for ory-temporal-worker)
|
|
103
123
|
```
|
|
104
124
|
|
|
105
|
-
`local-up`
|
|
125
|
+
`local-up` runs a complete Ory on your laptop: the Ory APIs (Identities, OAuth2, Permissions) at `http://localhost:4000`, a login UI on `:3000`, and Jaeger (the trace viewer) on `:16686`. A test user identity is seeded and its credentials are printed for you. Use it to:
|
|
106
126
|
|
|
107
127
|
- **Learn Ory hands-on** without signing up for a hosted project.
|
|
108
|
-
- **Prototype** flows (login, social, MFA, recovery,
|
|
128
|
+
- **Prototype** flows (login, social, MFA, recovery, permissions) against a real Ory backend.
|
|
109
129
|
- **Test** an auth integration end-to-end before pushing anything to a real environment.
|
|
110
130
|
- **Develop** your application against the same identity, OAuth2, and permission surfaces you'll ship with.
|
|
111
131
|
|
|
112
132
|
## Pointing at a real Ory project
|
|
113
133
|
|
|
114
|
-
The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the plugin at it:
|
|
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:
|
|
115
135
|
|
|
116
136
|
```bash
|
|
117
137
|
npx -y -p @ory/opencode ory-opencode configure \
|
|
118
138
|
--project-url https://<id>.projects.oryapis.com \
|
|
119
|
-
--
|
|
139
|
+
--oauth2-client-id <public OAuth2 client id>
|
|
120
140
|
```
|
|
121
141
|
|
|
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:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
npx -y -p @ory/opencode ory-opencode configure --audit-only
|
|
150
|
+
```
|
|
151
|
+
|
|
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
|
+
|
|
122
154
|
Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine.
|
|
123
155
|
|
|
124
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.
|
|
125
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:
|
|
163
|
+
|
|
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.
|
|
170
|
+
|
|
171
|
+
Create the client with the [Ory CLI](https://www.ory.com/docs/guides/cli/installation):
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
ory create oauth2-client --project <project-id> \
|
|
175
|
+
--name "ory-agent-plugin" \
|
|
176
|
+
--grant-type authorization_code,refresh_token \
|
|
177
|
+
--response-type code \
|
|
178
|
+
--scope openid,offline_access \
|
|
179
|
+
--token-endpoint-auth-method none \
|
|
180
|
+
--redirect-uri http://127.0.0.1:47823/callback \
|
|
181
|
+
--redirect-uri http://127.0.0.1:47824/callback \
|
|
182
|
+
--redirect-uri http://127.0.0.1:47825/callback \
|
|
183
|
+
--redirect-uri http://127.0.0.1:47826/callback
|
|
184
|
+
```
|
|
185
|
+
|
|
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
|
+
|
|
126
203
|
## Agent security
|
|
127
204
|
|
|
128
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.
|
|
129
206
|
|
|
130
|
-
- **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when user login is enabled (`ORY_USER_LOGIN=
|
|
131
|
-
- **Authorization.** When OpenCode prompts for permission to use a tool, the plugin checks [Ory Permissions](https://www.ory.com/docs/keto) (Zanzibar-style
|
|
132
|
-
- **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
|
|
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 and returns `allow` / `deny`. 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.
|
|
133
210
|
|
|
134
|
-
The plugin is **fail-open** on its own infrastructure failures (network errors, rate limits, missing config), so enforcement is only as strong as your
|
|
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.
|
|
135
212
|
|
|
136
213
|
### Enable enforcement
|
|
137
214
|
|
|
@@ -140,12 +217,15 @@ After install the plugin runs in **observe mode**: every tool call is checked ag
|
|
|
140
217
|
1. **Turn on user login.** It's off by default. In your shell:
|
|
141
218
|
|
|
142
219
|
```bash
|
|
143
|
-
export ORY_USER_LOGIN=
|
|
220
|
+
export ORY_USER_LOGIN=true
|
|
221
|
+
export ORY_OAUTH2_CLIENT_ID=<public OAuth2 client id>
|
|
144
222
|
```
|
|
145
223
|
|
|
146
224
|
The next OpenCode session refreshes or prompts for PKCE login. Subsequent sessions reuse the persisted token until it expires.
|
|
147
225
|
|
|
148
|
-
|
|
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, …):
|
|
149
229
|
|
|
150
230
|
```bash
|
|
151
231
|
npx -y -p @ory/opencode ory-opencode permissions bootstrap
|
|
@@ -159,7 +239,7 @@ After install the plugin runs in **observe mode**: every tool call is checked ag
|
|
|
159
239
|
npx -y -p @ory/opencode ory-opencode permissions status
|
|
160
240
|
```
|
|
161
241
|
|
|
162
|
-
Add
|
|
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"*).
|
|
163
243
|
|
|
164
244
|
4. **Promote to enforce.** Once the observe-mode logs look right, switch over:
|
|
165
245
|
|
|
@@ -173,7 +253,7 @@ After install the plugin runs in **observe mode**: every tool call is checked ag
|
|
|
173
253
|
|
|
174
254
|
```
|
|
175
255
|
npx -y -p @ory/opencode ory-opencode install | uninstall [--project-dir <path>]
|
|
176
|
-
npx -y -p @ory/opencode ory-opencode configure [--project-url <url>] [--api-key <key>] [--audit-only]
|
|
256
|
+
npx -y -p @ory/opencode ory-opencode configure [--project-url <url> --oauth2-client-id <id>] [--api-key <key>] [--audit-only]
|
|
177
257
|
npx -y -p @ory/opencode ory-opencode agent <status|unregister> Manage the agent's OAuth2 identity
|
|
178
258
|
npx -y -p @ory/opencode ory-opencode permissions <status|bootstrap|observe|enforce>
|
|
179
259
|
npx -y -p @ory/opencode ory-opencode local <up|down|status|seed|logs|env|configure|reset>
|
|
@@ -183,7 +263,7 @@ npx -y -p @ory/opencode ory-opencode status [--projec
|
|
|
183
263
|
Highlights:
|
|
184
264
|
|
|
185
265
|
- `agent status` — show the current persisted DCR identity for the agent.
|
|
186
|
-
- `permissions observe` / `permissions enforce` — switch between "log denies, allow through" (the install default) and "block denies." `permissions bootstrap` writes `use`
|
|
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.
|
|
187
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`.
|
|
188
268
|
- `local seed` / `local env` — reseed the test user, or print env vars for pointing other tools at the local stack.
|
|
189
269
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ory/opencode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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,7 @@
|
|
|
63
63
|
"!dist/**/*.tsbuildinfo"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@ory/argus": "0.
|
|
66
|
+
"@ory/argus": "0.9.1"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=22"
|