@ory/codex 0.1.2 → 0.2.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
@@ -2,9 +2,18 @@
2
2
 
3
3
  [Ory](https://ory.com) bundled into [Codex](https://github.com/openai/codex): 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 Codex runs.
4
4
 
5
+ You don't need an Ory account or any prior Ory experience to start.
6
+
7
+ ## Prerequisites
8
+
9
+ - [Codex](https://github.com/openai/codex) installed and signed in
10
+ - Node.js **≥ 24**
11
+ - [Docker](https://docs.docker.com/get-docker/) (only needed for the local Ory stack)
12
+ - macOS or Linux. Windows works via WSL2.
13
+
5
14
  ## Install
6
15
 
7
- Codex loads hooks from its config. Install and register in one step, with no prior `npm install` required:
16
+ No prior `npm install` required:
8
17
 
9
18
  ```bash
10
19
  npx @ory/codex install # current project
@@ -12,30 +21,53 @@ npx @ory/codex install --global # all Codex projects
12
21
  npx @ory/codex uninstall
13
22
  ```
14
23
 
15
- `install` wires the Ory hooks into your Codex config non-destructively (existing hooks are preserved), registers the Ory MCP server, and drops the Ory skill catalog into `.codex/skills/`. If the installer can't locate your Codex config, `npx -y -p @ory/codex ory-codex-setup` writes it directly.
24
+ That's it — skills, hooks, and the Ory MCP server are now registered. Existing entries in your Codex config are preserved.
16
25
 
17
- ## Developer experience
26
+ <details>
27
+ <summary>Alternative install</summary>
18
28
 
19
- This plugin is a productivity layer for Ory itself. You don't need a real Ory project, an account, or any prior Ory experience to start using it.
29
+ If the installer can't locate your Codex config, this writes it directly:
20
30
 
21
- ### Skills for scaffolding Ory into your application
31
+ ```bash
32
+ npx -y -p @ory/codex ory-codex-setup
33
+ ```
34
+
35
+ </details>
36
+
37
+ ## Quickstart (≈ 3 minutes)
38
+
39
+ From any project where you'd like Ory authentication, inside Codex:
22
40
 
23
- Codex surfaces the skill catalog in `/skills` and auto-invokes by description. Ask Codex to add Ory auth to your codebase, or invoke a skill directly:
41
+ 1. **Start a local Ory instance.** Ask Codex *"start the local Ory stack"* or pick `ory-local-up` from the `/skills` menu.
24
42
 
25
- - **`ory-auth-setup`**: full project setup. Install the Ory CLI, create an Ory Network project, add Ory Elements, configure the SDK, build the auth pages, wire session middleware.
26
- - **`ory-login-flow`**: login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
27
- - **`ory-social-login`**: Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
28
- - **`ory-local-dev`**: drive the local Ory stack (below) from within Codex to prototype and test against without a remote project.
43
+ A banner prints the seeded test user's email and password. Note them — you'll log in with them in step 3.
29
44
 
30
- Skills are versioned with the plugin so guidance stays in sync as Ory APIs evolve.
45
+ 2. **Scaffold Ory into your project.** Ask Codex *"add Ory auth to this app"* or pick `ory-auth-setup` from `/skills`.
46
+
47
+ Codex 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.
48
+
49
+ 3. **Sign in.** Start your app, visit the login page Codex 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.
50
+
51
+ 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.
52
+
53
+ ## What's included
54
+
55
+ ### Skills for scaffolding Ory into your application
56
+
57
+ Codex surfaces the skill catalog in `/skills` and auto-invokes by description. Ask Codex in natural language or invoke a skill directly:
58
+
59
+ - **`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.
60
+ - **`ory-login-flow`** — login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
61
+ - **`ory-social-login`** — Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
62
+ - **`ory-local-dev`** — drive the local Ory stack from within Codex to prototype and test without a remote project.
31
63
 
32
64
  ### Ory MCP server
33
65
 
34
- Bundled and registered automatically. It exposes the Ory CLI and the Ory Network REST API as MCP tools so Codex can manage identities, OAuth2 clients, projects, permission tuples, and configuration without ever leaving the chat. Useful for seeding test data, verifying a scaffolded integration, or running one-off admin tasks.
66
+ Bundled and registered automatically. Exposes the Ory CLI and the Ory Network REST API as MCP tools so Codex can manage identities, OAuth2 clients, projects, permission tuples, and configuration without ever leaving the chat. Useful for seeding test data, verifying a scaffolded integration, or running one-off admin tasks.
35
67
 
36
- ### Local Ory stack in one command
68
+ ### Local Ory stack
37
69
 
38
- From Codex's `/skills` picker:
70
+ From Codex's `/skills` menu:
39
71
 
40
72
  ```
41
73
  ory-local-up # start a local Ory instance in Docker
@@ -44,46 +76,104 @@ ory-local-down # tear it all down
44
76
 
45
77
  Or via the CLI: `npx -y -p @ory/codex ory-codex local up | down`.
46
78
 
47
- `local up` runs a local Ory instance in Docker, covering everything the plugin and your scaffolded application need. It also brings up a login UI on `:3000` and Jaeger on `:16686`, all reachable through `http://localhost:4000`. A test user identity is seeded and the credentials are printed for you. Use it to:
79
+ `ory-local-up` brings up Ory Identities, OAuth2, and Permissions, plus a login UI on `:3000` and Jaeger on `:16686`, all reachable through `http://localhost:4000`. A test user identity is seeded and the credentials are printed for you. Use it to:
48
80
 
49
81
  - **Learn Ory hands-on** without signing up for a hosted project.
50
- - **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend in your local dev loop.
82
+ - **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend.
51
83
  - **Test** an auth integration end-to-end before pushing anything to a real environment.
52
84
  - **Develop** your application against the same identity, OAuth2, and permission surfaces you'll ship with.
53
85
 
54
- Point `ORY_PROJECT_URL` at `http://localhost:4000` (or run `npx -y -p @ory/codex ory-codex configure`) and the security features below run against the local stack.
86
+ ## Pointing at a real Ory project
55
87
 
56
- ## Configure
88
+ The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the plugin at it:
57
89
 
58
90
  ```bash
59
- npx -y -p @ory/codex ory-codex configure --project-url https://<id>.projects.oryapis.com --api-key ory_pat_...
91
+ npx -y -p @ory/codex ory-codex configure \
92
+ --project-url https://<id>.projects.oryapis.com \
93
+ --api-key ory_pat_...
60
94
  ```
61
95
 
62
- Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine. Without it the plugin still loads cleanly and runs in **pass-through mode**: skills work, but nothing is blocked.
96
+ Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine.
97
+
98
+ Without configuration the plugin still loads cleanly and runs in **pass-through mode**: skills work, but nothing is blocked. You can stay in pass-through mode indefinitely if you only want the DX features.
63
99
 
64
- ## Agent security (Argus)
100
+ ## Agent security
65
101
 
66
- Once the plugin is pointed at an Ory project (local or hosted), Codex's session and every tool call are governed by Ory.
102
+ Once the plugin is pointed at an Ory project (local or hosted), Codex's session and every tool call can be governed by Ory.
67
103
 
68
- - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when `ORY_AUTH_GATE=1`. The Codex process (the **agent**) gets its own OAuth2 identity, self-registered via Dynamic Client Registration on first run.
69
- - **Authorization.** Before any tool runs, the plugin checks Ory Permissions against the user's subject and blocks the call on `deny`. MCP tool calls additionally get a server-level check.
70
- - **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-to-agent delegation is written to Ory as a Zanzibar tuple so "agent X acting on behalf of user Y" stays queryable after tokens expire.
104
+ - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when `ORY_AUTH_GATE=1` is set. The Codex 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.
105
+ - **Authorization.** Before any tool runs, the plugin checks [Ory Permissions](https://www.ory.com/docs/keto) (Zanzibar-style relation tuples) against the user's subject and blocks the call on `deny`. MCP tool calls additionally get a server-level check.
106
+ - **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 tuple so *"agent X acting on behalf of user Y"* stays queryable after tokens expire.
71
107
 
72
- The plugin is **fail-open** on its own infrastructure failures (network errors, rate limits, missing config), so enforcement is only as strong as your tuples; grant explicit `invoke` relations for the tools each user should be able to run.
108
+ The plugin is **fail-open** on its own infrastructure failures (network errors, rate limits, missing config), so enforcement is only as strong as your tuples — grant explicit `invoke` relations for the tools each user should be able to run.
73
109
 
74
- ## CLI
110
+ ### Enable enforcement
111
+
112
+ 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. This lets you see what *would* be blocked before turning on hard blocking.
113
+
114
+ 1. **Turn on the user gate.** In your shell:
115
+
116
+ ```bash
117
+ export ORY_AUTH_GATE=1
118
+ ```
119
+
120
+ The next Codex session opens a browser for PKCE login. Subsequent sessions reuse the persisted token until it expires.
121
+
122
+ 2. **Bootstrap tuples for the built-in tools.** One idempotent command grants the current user `use` on every tool Codex ships with (shell, apply_patch, …):
123
+
124
+ ```bash
125
+ npx -y -p @ory/codex ory-codex permissions bootstrap
126
+ ```
127
+
128
+ 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.
129
+
130
+ 3. **Check coverage.** `permissions status` probes every tool in the harness's catalog and prints allowed / denied per tool:
131
+
132
+ ```bash
133
+ npx -y -p @ory/codex ory-codex permissions status
134
+ ```
135
+
136
+ Add tuples for any MCP server tools or custom commands by hand, or via the Ory MCP server from inside Codex (*"grant me use on the shell tool"*).
137
+
138
+ 4. **Promote to enforce.** Once the observe-mode logs look right, switch over:
139
+
140
+ ```bash
141
+ npx -y -p @ory/codex ory-codex permissions enforce
142
+ ```
143
+
144
+ Denies now block the tool call; Codex shows the denial reason and the decision is recorded as a `tool.block` trace span with `blocked: true`. Switch back any time with `permissions observe`.
145
+
146
+ ## CLI reference
75
147
 
76
148
  ```
77
149
  npx -y -p @ory/codex ory-codex install | uninstall [--global]
78
150
  npx -y -p @ory/codex ory-codex configure [--project-url <url>] [--api-key <key>] [--audit-only]
79
151
  npx -y -p @ory/codex ory-codex agent <status|unregister> Manage the agent's OAuth2 identity
152
+ npx -y -p @ory/codex ory-codex permissions <status|bootstrap|observe|enforce>
80
153
  npx -y -p @ory/codex ory-codex local <up|down|status|seed|logs|env|configure|reset>
81
154
  npx -y -p @ory/codex ory-codex status
82
155
  ```
83
156
 
157
+ Highlights:
158
+
159
+ - `agent status` — show the current persisted DCR identity for the agent.
160
+ - `permissions observe` / `permissions enforce` — switch between "log denies, allow through" (the install default) and "block denies." `permissions bootstrap` writes `use` tuples for the harness's built-in tools so the promotion path doesn't require hand-writing relationships.
161
+ - `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`.
162
+ - `local seed` / `local env` — reseed the test user, or print env vars for pointing other tools at the local stack.
163
+
164
+ ## Troubleshooting
165
+
166
+ - **`ory-local-up` fails.** Make sure Docker is running and ports `3000`, `4000`, `4100`, and `16686` are free.
167
+ - **PKCE login loops.** Clear persisted state with `npx -y -p @ory/codex ory-codex agent unregister` and retry.
168
+ - **`npx` fetches an old version.** Force a fresh fetch: `npx -y -p @ory/codex@latest ory-codex …`.
169
+ - **Need more signal.** Set `ORY_AGENT_DEBUG=true` and `ORY_AGENT_LOG_FILE=/tmp/ory.log` to capture structured logs.
170
+
84
171
  ## Links
85
172
 
86
- - [ory.com](https://ory.com)
173
+ - [Ory documentation](https://www.ory.com/docs/)
174
+ - [Ory Network console](https://console.ory.sh)
175
+ - [Ory Elements](https://github.com/ory/elements)
176
+ - [Codex documentation](https://github.com/openai/codex)
87
177
 
88
178
  ## License
89
179
 
package/dist/cli/main.js CHANGED
@@ -53,6 +53,10 @@ function main() {
53
53
  switch (command) {
54
54
  case "install":
55
55
  install(args);
56
+ postInstallPermissions("ory-codex", "codex").then(() => process.exit(0), (err) => {
57
+ console.error(err.message ?? err);
58
+ process.exit(1);
59
+ });
56
60
  break;
57
61
  case "uninstall":
58
62
  uninstall(args);
@@ -66,6 +70,12 @@ function main() {
66
70
  process.exit(1);
67
71
  });
68
72
  break;
73
+ case "permissions":
74
+ (0, argus_1.runPermissionsCommand)("ory-codex", "codex", args).then((code) => process.exit(code), (err) => {
75
+ console.error(err.message ?? err);
76
+ process.exit(1);
77
+ });
78
+ break;
69
79
  case "setup":
70
80
  require("./setup.js");
71
81
  break;
@@ -105,6 +115,12 @@ function manualSetup(isGlobal) {
105
115
  process.argv = ["node", "setup.js", ...setupArgs];
106
116
  require("./setup.js");
107
117
  }
118
+ async function postInstallPermissions(binName, harness) {
119
+ const bootstrapped = await (0, argus_1.maybeAutoBootstrap)(binName, harness);
120
+ (0, argus_1.printPermissionsOnboardingHelp)(binName, harness, {
121
+ bootstrappedAutomatically: bootstrapped,
122
+ });
123
+ }
108
124
  function status() {
109
125
  console.log("Ory Agent Plugin Status (Codex)");
110
126
  console.log("================================");
@@ -129,6 +145,7 @@ Commands:
129
145
  install [--global] Install the Ory hooks into Codex configuration
130
146
  uninstall Remove the Ory hooks from Codex configuration
131
147
  configure Set or view Ory project URL and API key
148
+ permissions <cmd> Manage permission mode and tool tuples (status, bootstrap, observe, enforce)
132
149
  setup [--global] Write hooks directly to config (fallback)
133
150
  status Show plugin status and configuration
134
151
  local <cmd> Manage local Ory dev environment (up, down, status, seed, ...)
package/dist/handlers.js CHANGED
@@ -180,40 +180,65 @@ async function handlePreToolUse(input, client) {
180
180
  subject,
181
181
  spanAttributes: { toolName },
182
182
  });
183
- if (!mcpResult.allowed) {
183
+ const mcpAttrs = {
184
+ toolName,
185
+ mcpServer: mcpTool.serverName,
186
+ mcpTool: mcpTool.toolName,
187
+ ...inputSummary,
188
+ };
189
+ const decision = (0, argus_1.applyPermissionMode)(client, mcpResult.allowed, {
190
+ object: mcpTool.serverName,
191
+ relation: "use",
192
+ subjectId,
193
+ spanAttributes: mcpAttrs,
194
+ });
195
+ if (decision.kind === "allow") {
196
+ client.tracer.record("tool.invoke", "ok", { attributes: mcpAttrs });
197
+ return {};
198
+ }
199
+ if (decision.kind === "observe") {
184
200
  client.tracer.record("tool.block", "denied", {
185
- attributes: { toolName, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName, ...inputSummary, ...(0, argus_1.alertAttributes)(true) },
201
+ attributes: { ...mcpAttrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
186
202
  });
187
- return {
188
- decision: "block",
189
- reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, mcp: mcpTool }),
190
- };
203
+ client.tracer.record("tool.invoke", "ok", {
204
+ attributes: { ...mcpAttrs, allowed: false, observed: true },
205
+ });
206
+ return {};
191
207
  }
192
- client.tracer.record("tool.invoke", "ok", {
193
- attributes: { toolName, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName, ...inputSummary },
194
- });
195
- return {};
196
- }
197
- const namespace = resolveNamespace();
198
- const result = await client.checkPermission({
199
- namespace,
200
- object: toolName,
201
- relation: "use",
202
- ...subject,
203
- }, { spanAttributes: { toolName } });
204
- if (!result.allowed) {
205
208
  client.tracer.record("tool.block", "denied", {
206
- attributes: { toolName, ...inputSummary, allowed: result.allowed, ...(0, argus_1.alertAttributes)(true) },
209
+ attributes: { ...mcpAttrs, allowed: false, ...(0, argus_1.alertAttributes)(true) },
207
210
  });
208
211
  return {
209
212
  decision: "block",
210
- reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, namespace }),
213
+ reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, mcp: mcpTool }),
211
214
  };
212
215
  }
213
- client.tracer.record("tool.invoke", "ok", {
214
- attributes: { toolName, ...inputSummary, allowed: result.allowed },
216
+ const namespace = resolveNamespace();
217
+ const decision = await (0, argus_1.checkAndDecide)(client, { namespace, object: toolName, relation: "use", ...subject }, { spanAttributes: { toolName } });
218
+ if (decision.kind === "fail_open") {
219
+ return handlePermissionError(decision.error, toolName, client);
220
+ }
221
+ const attrs = { toolName, ...inputSummary };
222
+ if (decision.kind === "allow") {
223
+ client.tracer.record("tool.invoke", "ok", { attributes: { ...attrs, allowed: true } });
224
+ return {};
225
+ }
226
+ if (decision.kind === "observe") {
227
+ client.tracer.record("tool.block", "denied", {
228
+ attributes: { ...attrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
229
+ });
230
+ client.tracer.record("tool.invoke", "ok", {
231
+ attributes: { ...attrs, allowed: false, observed: true },
232
+ });
233
+ return {};
234
+ }
235
+ client.tracer.record("tool.block", "denied", {
236
+ attributes: { ...attrs, allowed: false, ...(0, argus_1.alertAttributes)(true) },
215
237
  });
216
- return {};
238
+ return {
239
+ decision: "block",
240
+ reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, namespace }),
241
+ };
217
242
  }
218
243
  catch (err) {
219
244
  return handlePermissionError(err, toolName, client);
@@ -271,20 +296,34 @@ async function handlePermissionRequest(input, client) {
271
296
  subject,
272
297
  spanAttributes: { toolName },
273
298
  });
274
- return permissionRequestDecision(mcpResult.allowed ? "allow" : "deny", mcpResult.allowed
275
- ? "Ory MCP server permission granted"
276
- : (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, mcp: mcpTool }));
299
+ const decision = (0, argus_1.applyPermissionMode)(client, mcpResult.allowed, {
300
+ object: mcpTool.serverName,
301
+ relation: "use",
302
+ subjectId,
303
+ spanAttributes: { toolName, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName },
304
+ });
305
+ if (decision.kind === "deny") {
306
+ return permissionRequestDecision("deny", (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, mcp: mcpTool }));
307
+ }
308
+ return permissionRequestDecision("allow", decision.kind === "observe"
309
+ ? "Ory observe mode — denied by policy but allowed through"
310
+ : "Ory MCP server permission granted");
277
311
  }
278
312
  const namespace = resolveNamespace();
279
- const result = await client.checkPermission({
280
- namespace,
281
- object: toolName,
282
- relation: "use",
283
- ...subject,
284
- }, { spanAttributes: { toolName } });
285
- return permissionRequestDecision(result.allowed ? "allow" : "deny", result.allowed
286
- ? "Ory permission granted"
287
- : (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, namespace }));
313
+ const decision = await (0, argus_1.checkAndDecide)(client, { namespace, object: toolName, relation: "use", ...subject }, { spanAttributes: { toolName } });
314
+ if (decision.kind === "fail_open") {
315
+ const code = decision.error.code;
316
+ const reason = code === "network_error" || code === "rate_limited"
317
+ ? `Ory unavailable (${code}), falling back to user prompt`
318
+ : `Ory permission check failed: ${decision.error.message}`;
319
+ return permissionRequestFallback(reason);
320
+ }
321
+ if (decision.kind === "deny") {
322
+ return permissionRequestDecision("deny", (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, namespace }));
323
+ }
324
+ return permissionRequestDecision("allow", decision.kind === "observe"
325
+ ? "Ory observe mode — denied by policy but allowed through"
326
+ : "Ory permission granted");
288
327
  }
289
328
  catch (err) {
290
329
  const oryErr = err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ory/codex",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Ory plugin for Codex: 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",
@@ -67,7 +67,7 @@
67
67
  ".codex-plugin"
68
68
  ],
69
69
  "dependencies": {
70
- "@ory/argus": "0.1.2"
70
+ "@ory/argus": "0.2.0"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=24"