@ory/gemini-cli 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,98 +2,186 @@
2
2
 
3
3
  [Ory](https://ory.com) bundled into [Gemini CLI](https://github.com/google-gemini/gemini-cli): skills and TOML slash 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 Gemini runs.
4
4
 
5
- ## Install
5
+ You don't need an Ory account or any prior Ory experience to start.
6
+
7
+ ## Prerequisites
6
8
 
7
- Try these in order; the first that works is the simplest path:
9
+ - [Gemini CLI](https://github.com/google-gemini/gemini-cli) 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.
8
13
 
9
- **1. Google's public extension registry.** Find **Ory Agent Extension** and install:
14
+ ## Install
15
+
16
+ In your shell:
10
17
 
11
18
  ```bash
12
19
  gemini extensions install ory-agent-extension
13
20
  ```
14
21
 
15
- **2. The Ory-hosted extension source:**
22
+ That's it — skills, TOML slash commands, hooks, and the Ory MCP server are now registered.
23
+
24
+ <details>
25
+ <summary>Alternative install paths</summary>
26
+
27
+ If the public extension registry isn't available, either of these registers the same extension:
16
28
 
17
29
  ```bash
30
+ # Ory-hosted extension source
18
31
  gemini extensions install https://github.com/ory/gemini-cli-extension
19
32
  ```
20
33
 
21
- **3. The Ory installer.** No prior `npm install` required:
22
-
23
34
  ```bash
35
+ # Direct installer, no prior npm install required
24
36
  npx @ory/gemini-cli install
25
37
  npx @ory/gemini-cli uninstall
26
38
  ```
27
39
 
28
- Every flow installs the same extension: skills, TOML slash commands, hooks, and the Ory MCP server. If the `gemini` binary isn't on your `PATH`, `npx -y -p @ory/gemini-cli ory-gemini-setup` writes the extension config directly.
40
+ If the `gemini` binary isn't on your `PATH`, `npx -y -p @ory/gemini-cli ory-gemini-setup` writes the extension config directly.
29
41
 
30
- ## Developer experience
42
+ </details>
31
43
 
32
- This extension 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.
44
+ ## Quickstart (≈ 3 minutes)
33
45
 
34
- ### Skills for scaffolding Ory into your application
46
+ From any project where you'd like Ory authentication, inside Gemini CLI:
47
+
48
+ 1. **Start a local Ory instance.** Ask Gemini *"start the local Ory stack"* or run:
35
49
 
36
- Ask Gemini to add Ory auth to your codebase. The extension bundles four skills that the model auto-invokes by description:
50
+ ```
51
+ /ory:local-up
52
+ ```
37
53
 
38
- - **`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.
39
- - **`ory-login-flow`**: login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
40
- - **`ory-social-login`**: Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
41
- - **`ory-local-dev`**: drive the local Ory stack (below) from within Gemini to prototype and test against without a remote project.
54
+ A banner prints the seeded test user's email and password. Note them you'll log in with them in step 3.
42
55
 
43
- Skills are versioned with the extension so guidance stays in sync as Ory APIs evolve.
56
+ 2. **Scaffold Ory into your project.** Ask Gemini *"add Ory auth to this app"* or invoke the `ory-auth-setup` skill.
57
+
58
+ Gemini 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.
59
+
60
+ 3. **Sign in.** Start your app, visit the login page Gemini 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.
61
+
62
+ That's the full Ory DX path. Stop here if you're just evaluating the extension. Continue to [Agent security](#agent-security) when you're ready to enforce.
63
+
64
+ ## What's included
65
+
66
+ ### Skills for scaffolding Ory into your application
67
+
68
+ The extension bundles four skills that Gemini auto-invokes by description. Ask Gemini in natural language or invoke a skill directly:
69
+
70
+ - **`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.
71
+ - **`ory-login-flow`** — login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
72
+ - **`ory-social-login`** — Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
73
+ - **`ory-local-dev`** — drive the local Ory stack from within Gemini to prototype and test without a remote project.
44
74
 
45
75
  ### Ory MCP server
46
76
 
47
- Bundled and registered automatically. It exposes the Ory CLI and the Ory Network REST API as MCP tools so Gemini 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.
77
+ Bundled and registered automatically. Exposes the Ory CLI and the Ory Network REST API as MCP tools so Gemini 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.
48
78
 
49
- ### Local Ory stack in one command
79
+ ### Local Ory stack
50
80
 
51
81
  ```
52
82
  /ory:local-up # start a local Ory instance in Docker
53
83
  /ory:local-down # tear it all down
54
84
  ```
55
85
 
56
- `local up` runs a local Ory instance in Docker, covering everything the extension 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:
86
+ `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:
57
87
 
58
88
  - **Learn Ory hands-on** without signing up for a hosted project.
59
- - **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend in your local dev loop.
89
+ - **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend.
60
90
  - **Test** an auth integration end-to-end before pushing anything to a real environment.
61
91
  - **Develop** your application against the same identity, OAuth2, and permission surfaces you'll ship with.
62
92
 
63
- Point `ORY_PROJECT_URL` at `http://localhost:4000` (or run `npx -y -p @ory/gemini-cli ory-gemini configure`) and the security features below run against the local stack.
93
+ ## Pointing at a real Ory project
64
94
 
65
- ## Configure
95
+ The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the extension at it:
66
96
 
67
97
  ```bash
68
- npx -y -p @ory/gemini-cli ory-gemini configure --project-url https://<id>.projects.oryapis.com --api-key ory_pat_...
98
+ npx -y -p @ory/gemini-cli ory-gemini configure \
99
+ --project-url https://<id>.projects.oryapis.com \
100
+ --api-key ory_pat_...
69
101
  ```
70
102
 
71
- Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin or extension on the machine. Without it the extension still loads cleanly and runs in **pass-through mode**: skills and commands work, but nothing is blocked.
103
+ Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin or extension on the machine.
104
+
105
+ Without configuration the extension 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.
72
106
 
73
- ## Agent security (Argus)
107
+ ## Agent security
74
108
 
75
- Once the extension is pointed at an Ory project (local or hosted), Gemini's session and every tool call are governed by Ory.
109
+ Once the extension is pointed at an Ory project (local or hosted), Gemini's session and every tool call can be governed by Ory.
76
110
 
77
- - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when `ORY_AUTH_GATE=1`. The Gemini process (the **agent**) gets its own OAuth2 identity, self-registered via Dynamic Client Registration on first run.
78
- - **Authorization.** Before any tool runs, the extension checks Ory Permissions against the user's subject and blocks the call on `deny`. MCP tool calls additionally get a server-level check.
79
- - **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.
111
+ - **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when `ORY_AUTH_GATE=1` is set. The Gemini 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.
112
+ - **Authorization.** Before any tool runs, the extension 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.
113
+ - **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 useragent delegation is written to Ory as a relation tuple so *"agent X acting on behalf of user Y"* stays queryable after tokens expire.
80
114
 
81
- The extension 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.
115
+ The extension 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.
82
116
 
83
- ## CLI
117
+ ### Enable enforcement
118
+
119
+ After install the extension 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.
120
+
121
+ 1. **Turn on the user gate.** In your shell:
122
+
123
+ ```bash
124
+ export ORY_AUTH_GATE=1
125
+ ```
126
+
127
+ The next Gemini session opens a browser for PKCE login. Subsequent sessions reuse the persisted token until it expires.
128
+
129
+ 2. **Bootstrap tuples for the built-in tools.** One idempotent command grants the current user `use` on every tool Gemini ships with (read_file, write_file, shell, …):
130
+
131
+ ```bash
132
+ npx -y -p @ory/gemini-cli ory-gemini permissions bootstrap
133
+ ```
134
+
135
+ 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.
136
+
137
+ 3. **Check coverage.** `permissions status` probes every tool in the harness's catalog and prints allowed / denied per tool:
138
+
139
+ ```bash
140
+ npx -y -p @ory/gemini-cli ory-gemini permissions status
141
+ ```
142
+
143
+ Add tuples for any MCP server tools or custom commands by hand, or via the Ory MCP server from inside Gemini (*"grant me use on the shell tool"*).
144
+
145
+ 4. **Promote to enforce.** Once the observe-mode logs look right, switch over:
146
+
147
+ ```bash
148
+ npx -y -p @ory/gemini-cli ory-gemini permissions enforce
149
+ ```
150
+
151
+ Denies now block the tool call; Gemini 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`.
152
+
153
+ ## CLI reference
84
154
 
85
155
  ```
86
156
  npx -y -p @ory/gemini-cli ory-gemini install [--link]
87
157
  npx -y -p @ory/gemini-cli ory-gemini uninstall
88
158
  npx -y -p @ory/gemini-cli ory-gemini configure [--project-url <url>] [--api-key <key>] [--audit-only]
89
159
  npx -y -p @ory/gemini-cli ory-gemini agent <status|unregister> Manage the agent's OAuth2 identity
160
+ npx -y -p @ory/gemini-cli ory-gemini permissions <status|bootstrap|observe|enforce>
90
161
  npx -y -p @ory/gemini-cli ory-gemini local <up|down|status|seed|logs|env|configure|reset>
91
162
  npx -y -p @ory/gemini-cli ory-gemini status
92
163
  ```
93
164
 
165
+ Highlights:
166
+
167
+ - `agent status` — show the current persisted DCR identity for the agent.
168
+ - `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.
169
+ - `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`.
170
+ - `local seed` / `local env` — reseed the test user, or print env vars for pointing other tools at the local stack.
171
+
172
+ ## Troubleshooting
173
+
174
+ - **`/ory:local-up` fails.** Make sure Docker is running and ports `3000`, `4000`, `4100`, and `16686` are free.
175
+ - **PKCE login loops.** Clear persisted state with `npx -y -p @ory/gemini-cli ory-gemini agent unregister` and retry.
176
+ - **`npx` fetches an old version.** Force a fresh fetch: `npx -y -p @ory/gemini-cli@latest ory-gemini …`.
177
+ - **Need more signal.** Set `ORY_AGENT_DEBUG=true` and `ORY_AGENT_LOG_FILE=/tmp/ory.log` to capture structured logs.
178
+
94
179
  ## Links
95
180
 
96
- - [ory.com](https://ory.com)
181
+ - [Ory documentation](https://www.ory.com/docs/)
182
+ - [Ory Network console](https://console.ory.sh)
183
+ - [Ory Elements](https://github.com/ory/elements)
184
+ - [Gemini CLI documentation](https://github.com/google-gemini/gemini-cli)
97
185
 
98
186
  ## License
99
187
 
package/dist/cli/main.js CHANGED
@@ -56,6 +56,10 @@ function main() {
56
56
  switch (command) {
57
57
  case "install":
58
58
  install(args);
59
+ postInstallPermissions("ory-gemini", "gemini-cli").then(() => process.exit(0), (err) => {
60
+ console.error(err.message ?? err);
61
+ process.exit(1);
62
+ });
59
63
  break;
60
64
  case "uninstall":
61
65
  uninstall(args);
@@ -69,6 +73,12 @@ function main() {
69
73
  process.exit(1);
70
74
  });
71
75
  break;
76
+ case "permissions":
77
+ (0, argus_1.runPermissionsCommand)("ory-gemini", "gemini-cli", args).then((code) => process.exit(code), (err) => {
78
+ console.error(err.message ?? err);
79
+ process.exit(1);
80
+ });
81
+ break;
72
82
  case "setup":
73
83
  require("./setup.js");
74
84
  break;
@@ -155,6 +165,12 @@ function manualSetup(args) {
155
165
  process.argv = ["node", "setup.js", ...args];
156
166
  require("./setup.js");
157
167
  }
168
+ async function postInstallPermissions(binName, harness) {
169
+ const bootstrapped = await (0, argus_1.maybeAutoBootstrap)(binName, harness);
170
+ (0, argus_1.printPermissionsOnboardingHelp)(binName, harness, {
171
+ bootstrappedAutomatically: bootstrapped,
172
+ });
173
+ }
158
174
  function status() {
159
175
  console.log("Ory Agent Plugin Status (Gemini CLI)");
160
176
  console.log("====================================");
@@ -183,6 +199,7 @@ Commands:
183
199
  install [--link] Install the Ory extension into Gemini CLI
184
200
  uninstall Remove the Ory extension from Gemini CLI
185
201
  configure Set or view Ory project URL and API key
202
+ permissions <cmd> Manage permission mode and tool tuples (status, bootstrap, observe, enforce)
186
203
  setup [--project-dir] Write hooks directly to settings.json (fallback)
187
204
  status Show plugin status and configuration
188
205
  local <cmd> Manage local Ory dev environment (up, down, status, seed, ...)
package/dist/handlers.js CHANGED
@@ -167,42 +167,67 @@ async function handleBeforeTool(input, client) {
167
167
  subject,
168
168
  spanAttributes: { toolName },
169
169
  });
170
- if (!mcpResult.allowed) {
170
+ const mcpAttrs = {
171
+ toolName,
172
+ mcpServer: mcpTool.serverName,
173
+ mcpTool: mcpTool.toolName,
174
+ ...inputSummary,
175
+ };
176
+ const decision = (0, argus_1.applyPermissionMode)(client, mcpResult.allowed, {
177
+ object: mcpTool.serverName,
178
+ relation: "use",
179
+ subjectId,
180
+ spanAttributes: mcpAttrs,
181
+ });
182
+ if (decision.kind === "allow") {
183
+ client.tracer.record("tool.invoke", "ok", { attributes: mcpAttrs });
184
+ return {};
185
+ }
186
+ if (decision.kind === "observe") {
171
187
  client.tracer.record("tool.block", "denied", {
172
- attributes: { toolName, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName, ...inputSummary, ...(0, argus_1.alertAttributes)(true) },
188
+ attributes: { ...mcpAttrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
189
+ });
190
+ client.tracer.record("tool.invoke", "ok", {
191
+ attributes: { ...mcpAttrs, allowed: false, observed: true },
173
192
  });
174
- return {
175
- decision: "deny",
176
- reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, mcp: mcpTool }),
177
- systemMessage: (0, argus_1.formatDenialSummary)({ tool: toolName, subjectId, mcp: mcpTool }),
178
- };
193
+ return {};
179
194
  }
180
- client.tracer.record("tool.invoke", "ok", {
181
- attributes: { toolName, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName, ...inputSummary },
182
- });
183
- return {};
184
- }
185
- const namespace = resolveNamespace();
186
- const result = await client.checkPermission({
187
- namespace,
188
- object: toolName,
189
- relation: "use",
190
- ...subject,
191
- }, { spanAttributes: { toolName } });
192
- if (!result.allowed) {
193
195
  client.tracer.record("tool.block", "denied", {
194
- attributes: { toolName, ...inputSummary, allowed: result.allowed, ...(0, argus_1.alertAttributes)(true) },
196
+ attributes: { ...mcpAttrs, allowed: false, ...(0, argus_1.alertAttributes)(true) },
195
197
  });
196
198
  return {
197
199
  decision: "deny",
198
- reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, namespace }),
199
- systemMessage: (0, argus_1.formatDenialSummary)({ tool: toolName, subjectId, namespace }),
200
+ reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, mcp: mcpTool }),
201
+ systemMessage: (0, argus_1.formatDenialSummary)({ tool: toolName, subjectId, mcp: mcpTool }),
200
202
  };
201
203
  }
202
- client.tracer.record("tool.invoke", "ok", {
203
- attributes: { toolName, ...inputSummary, allowed: result.allowed },
204
+ const namespace = resolveNamespace();
205
+ const decision = await (0, argus_1.checkAndDecide)(client, { namespace, object: toolName, relation: "use", ...subject }, { spanAttributes: { toolName } });
206
+ if (decision.kind === "fail_open") {
207
+ return handlePermissionError(decision.error, toolName, client);
208
+ }
209
+ const attrs = { toolName, ...inputSummary };
210
+ if (decision.kind === "allow") {
211
+ client.tracer.record("tool.invoke", "ok", { attributes: { ...attrs, allowed: true } });
212
+ return {};
213
+ }
214
+ if (decision.kind === "observe") {
215
+ client.tracer.record("tool.block", "denied", {
216
+ attributes: { ...attrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
217
+ });
218
+ client.tracer.record("tool.invoke", "ok", {
219
+ attributes: { ...attrs, allowed: false, observed: true },
220
+ });
221
+ return {};
222
+ }
223
+ client.tracer.record("tool.block", "denied", {
224
+ attributes: { ...attrs, allowed: false, ...(0, argus_1.alertAttributes)(true) },
204
225
  });
205
- return {};
226
+ return {
227
+ decision: "deny",
228
+ reason: (0, argus_1.formatDenialMessage)({ tool: toolName, subjectId, namespace }),
229
+ systemMessage: (0, argus_1.formatDenialSummary)({ tool: toolName, subjectId, namespace }),
230
+ };
206
231
  }
207
232
  catch (err) {
208
233
  return handlePermissionError(err, toolName, client);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ory/gemini-cli",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Ory extension for Gemini CLI: 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",
@@ -69,7 +69,7 @@
69
69
  "gemini-extension"
70
70
  ],
71
71
  "dependencies": {
72
- "@ory/argus": "0.1.2"
72
+ "@ory/argus": "0.2.0"
73
73
  },
74
74
  "engines": {
75
75
  "node": ">=24"