@ory/opencode 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 +114 -32
- package/dist/cli/main.js +17 -0
- package/dist/plugin.js +86 -45
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,15 +2,29 @@
|
|
|
2
2
|
|
|
3
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.
|
|
4
4
|
|
|
5
|
+
You don't need an Ory account or any prior Ory experience to start.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- [OpenCode](https://opencode.ai) installed
|
|
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
|
-
|
|
16
|
+
Add the plugin to your `opencode.json`:
|
|
8
17
|
|
|
9
18
|
```json
|
|
10
19
|
{ "plugin": ["@ory/opencode"] }
|
|
11
20
|
```
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
OpenCode fetches the plugin from npm on next launch.
|
|
23
|
+
|
|
24
|
+
<details>
|
|
25
|
+
<summary>Alternative install paths</summary>
|
|
26
|
+
|
|
27
|
+
The Ory installer registers the plugin **and** the Ory MCP server in one step, with no prior `npm install` required:
|
|
14
28
|
|
|
15
29
|
```bash
|
|
16
30
|
npx @ory/opencode install # writes opencode.json + MCP config
|
|
@@ -20,80 +34,148 @@ npx @ory/opencode uninstall
|
|
|
20
34
|
|
|
21
35
|
Either flow drops the Ory skill catalog into `.opencode/skills/` and the local-stack commands into `.opencode/commands/ory/`.
|
|
22
36
|
|
|
23
|
-
|
|
37
|
+
</details>
|
|
24
38
|
|
|
25
|
-
|
|
39
|
+
## Quickstart (≈ 3 minutes)
|
|
26
40
|
|
|
27
|
-
|
|
41
|
+
From any project where you'd like Ory authentication, inside OpenCode:
|
|
42
|
+
|
|
43
|
+
1. **Start a local Ory instance.** Ask OpenCode *"start the local Ory stack"* or run:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
/ory:local-up
|
|
47
|
+
```
|
|
28
48
|
|
|
29
|
-
|
|
49
|
+
A banner prints the seeded test user's email and password. Note them — you'll log in with them in step 3.
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
- **`ory-login-flow`**: login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
|
|
33
|
-
- **`ory-social-login`**: Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
|
|
34
|
-
- **`ory-local-dev`**: drive the local Ory stack (below) from within OpenCode to prototype and test against without a remote project.
|
|
51
|
+
2. **Scaffold Ory into your project.** Ask OpenCode *"add Ory auth to this app"* or invoke the `ory-auth-setup` skill.
|
|
35
52
|
|
|
36
|
-
|
|
53
|
+
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.
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
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.
|
|
58
|
+
|
|
59
|
+
## What's included
|
|
60
|
+
|
|
61
|
+
### Skills for scaffolding Ory into your application
|
|
62
|
+
|
|
63
|
+
Each skill is a vetted, end-to-end playbook. Ask OpenCode in natural language or invoke a skill directly:
|
|
64
|
+
|
|
65
|
+
- **`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.
|
|
66
|
+
- **`ory-login-flow`** — login, registration, recovery, verification, and settings pages with Ory Elements. Next.js App Router and React SPA variants.
|
|
67
|
+
- **`ory-social-login`** — Google, GitHub, Apple, Microsoft, Discord, and other OIDC providers with Jsonnet data mappers.
|
|
68
|
+
- **`ory-local-dev`** — drive the local Ory stack from within OpenCode to prototype and test without a remote project.
|
|
37
69
|
|
|
38
70
|
### Ory MCP server
|
|
39
71
|
|
|
40
|
-
Bundled and registered by the Ory installer.
|
|
72
|
+
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, permission tuples, and configuration without ever leaving the chat. Useful for seeding test data, verifying a scaffolded integration, or running one-off admin tasks.
|
|
41
73
|
|
|
42
|
-
### Local Ory stack
|
|
74
|
+
### Local Ory stack
|
|
43
75
|
|
|
44
76
|
```
|
|
45
77
|
/ory:local-up # start a local Ory instance in Docker
|
|
46
78
|
/ory:local-down # tear it all down
|
|
47
79
|
```
|
|
48
80
|
|
|
49
|
-
`local
|
|
81
|
+
`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:
|
|
50
82
|
|
|
51
83
|
- **Learn Ory hands-on** without signing up for a hosted project.
|
|
52
|
-
- **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend
|
|
84
|
+
- **Prototype** flows (login, social, MFA, recovery, permission tuples) against a real Ory backend.
|
|
53
85
|
- **Test** an auth integration end-to-end before pushing anything to a real environment.
|
|
54
86
|
- **Develop** your application against the same identity, OAuth2, and permission surfaces you'll ship with.
|
|
55
87
|
|
|
56
|
-
|
|
88
|
+
## Pointing at a real Ory project
|
|
57
89
|
|
|
58
|
-
|
|
90
|
+
The Quickstart uses the local stack. If you have a hosted [Ory Network](https://console.ory.sh) project, point the plugin at it:
|
|
59
91
|
|
|
60
92
|
```bash
|
|
61
|
-
npx -y -p @ory/opencode ory-opencode configure
|
|
93
|
+
npx -y -p @ory/opencode ory-opencode configure \
|
|
94
|
+
--project-url https://<id>.projects.oryapis.com \
|
|
95
|
+
--api-key ory_pat_...
|
|
62
96
|
```
|
|
63
97
|
|
|
64
|
-
Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine.
|
|
98
|
+
Config is saved to `~/.config/ory-agent-plugins/config.json` and shared across every Ory agent plugin on the machine.
|
|
65
99
|
|
|
66
|
-
|
|
100
|
+
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.
|
|
67
101
|
|
|
68
|
-
|
|
102
|
+
## Agent security
|
|
69
103
|
|
|
70
|
-
|
|
71
|
-
- **Authorization.** When OpenCode prompts for permission to use a tool, the plugin checks Ory Permissions 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.
|
|
72
|
-
- **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
|
+
Once the plugin is pointed at an Ory project (local or hosted), OpenCode's session and every tool call can be governed by Ory.
|
|
73
105
|
|
|
74
|
-
|
|
106
|
+
- **Authentication.** Two identities. The human at the keyboard (the **user**) authenticates interactively via Ory Identities when `ORY_AUTH_GATE=1` is set. 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.
|
|
107
|
+
- **Authorization.** When OpenCode prompts for permission to use a tool, the plugin checks [Ory Permissions](https://www.ory.com/docs/keto) (Zanzibar-style relation tuples) 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.
|
|
108
|
+
- **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.
|
|
75
109
|
|
|
76
|
-
|
|
110
|
+
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.
|
|
77
111
|
|
|
78
|
-
|
|
79
|
-
import { createOryPlugin } from "@ory/opencode";
|
|
112
|
+
### Enable enforcement
|
|
80
113
|
|
|
81
|
-
|
|
82
|
-
```
|
|
114
|
+
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.
|
|
83
115
|
|
|
84
|
-
|
|
116
|
+
1. **Turn on the user gate.** In your shell:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
export ORY_AUTH_GATE=1
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The next OpenCode session refreshes or prompts for PKCE login. Subsequent sessions reuse the persisted token until it expires.
|
|
123
|
+
|
|
124
|
+
2. **Bootstrap tuples for the built-in tools.** One idempotent command grants the current user `use` on every tool OpenCode ships with (read, write, edit, bash, …):
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npx -y -p @ory/opencode ory-opencode permissions bootstrap
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
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.
|
|
131
|
+
|
|
132
|
+
3. **Check coverage.** `permissions status` probes every tool in the harness's catalog and prints allowed / denied per tool:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npx -y -p @ory/opencode ory-opencode permissions status
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Add tuples 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"*).
|
|
139
|
+
|
|
140
|
+
4. **Promote to enforce.** Once the observe-mode logs look right, switch over:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npx -y -p @ory/opencode ory-opencode permissions enforce
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
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`.
|
|
147
|
+
|
|
148
|
+
## CLI reference
|
|
85
149
|
|
|
86
150
|
```
|
|
87
151
|
npx -y -p @ory/opencode ory-opencode install | uninstall [--project-dir <path>]
|
|
88
152
|
npx -y -p @ory/opencode ory-opencode configure [--project-url <url>] [--api-key <key>] [--audit-only]
|
|
89
153
|
npx -y -p @ory/opencode ory-opencode agent <status|unregister> Manage the agent's OAuth2 identity
|
|
154
|
+
npx -y -p @ory/opencode ory-opencode permissions <status|bootstrap|observe|enforce>
|
|
90
155
|
npx -y -p @ory/opencode ory-opencode local <up|down|status|seed|logs|env|configure|reset>
|
|
91
156
|
npx -y -p @ory/opencode ory-opencode status [--project-dir <path>]
|
|
92
157
|
```
|
|
93
158
|
|
|
159
|
+
Highlights:
|
|
160
|
+
|
|
161
|
+
- `agent status` — show the current persisted DCR identity for the agent.
|
|
162
|
+
- `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.
|
|
163
|
+
- `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`.
|
|
164
|
+
- `local seed` / `local env` — reseed the test user, or print env vars for pointing other tools at the local stack.
|
|
165
|
+
|
|
166
|
+
## Troubleshooting
|
|
167
|
+
|
|
168
|
+
- **`/ory:local-up` fails.** Make sure Docker is running and ports `3000`, `4000`, `4100`, and `16686` are free.
|
|
169
|
+
- **PKCE login loops.** Clear persisted state with `npx -y -p @ory/opencode ory-opencode agent unregister` and retry.
|
|
170
|
+
- **`npx` fetches an old version.** Force a fresh fetch: `npx -y -p @ory/opencode@latest ory-opencode …`.
|
|
171
|
+
- **Need more signal.** Set `ORY_AGENT_DEBUG=true` and `ORY_AGENT_LOG_FILE=/tmp/ory.log` to capture structured logs.
|
|
172
|
+
|
|
94
173
|
## Links
|
|
95
174
|
|
|
96
|
-
- [
|
|
175
|
+
- [Ory documentation](https://www.ory.com/docs/)
|
|
176
|
+
- [Ory Network console](https://console.ory.sh)
|
|
177
|
+
- [Ory Elements](https://github.com/ory/elements)
|
|
178
|
+
- [OpenCode documentation](https://opencode.ai)
|
|
97
179
|
|
|
98
180
|
## License
|
|
99
181
|
|
package/dist/cli/main.js
CHANGED
|
@@ -51,6 +51,10 @@ function main() {
|
|
|
51
51
|
switch (command) {
|
|
52
52
|
case "install":
|
|
53
53
|
install(args);
|
|
54
|
+
postInstallPermissions("ory-opencode", "opencode").then(() => process.exit(0), (err) => {
|
|
55
|
+
console.error(err.message ?? err);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
|
54
58
|
break;
|
|
55
59
|
case "uninstall":
|
|
56
60
|
uninstall(args);
|
|
@@ -64,6 +68,12 @@ function main() {
|
|
|
64
68
|
process.exit(1);
|
|
65
69
|
});
|
|
66
70
|
break;
|
|
71
|
+
case "permissions":
|
|
72
|
+
(0, argus_1.runPermissionsCommand)("ory-opencode", "opencode", args).then((code) => process.exit(code), (err) => {
|
|
73
|
+
console.error(err.message ?? err);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
67
77
|
case "status":
|
|
68
78
|
status(args);
|
|
69
79
|
break;
|
|
@@ -85,6 +95,12 @@ function main() {
|
|
|
85
95
|
process.exit(1);
|
|
86
96
|
}
|
|
87
97
|
}
|
|
98
|
+
async function postInstallPermissions(binName, harness) {
|
|
99
|
+
const bootstrapped = await (0, argus_1.maybeAutoBootstrap)(binName, harness);
|
|
100
|
+
(0, argus_1.printPermissionsOnboardingHelp)(binName, harness, {
|
|
101
|
+
bootstrappedAutomatically: bootstrapped,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
88
104
|
function parseProjectDir(args) {
|
|
89
105
|
const idx = args.indexOf("--project-dir");
|
|
90
106
|
if (idx !== -1 && args[idx + 1])
|
|
@@ -185,6 +201,7 @@ Commands:
|
|
|
185
201
|
install [--project-dir <path>] Register the Ory plugin in opencode.json
|
|
186
202
|
uninstall [--project-dir <path>] Remove the Ory plugin from opencode.json
|
|
187
203
|
configure Set or view Ory project URL and API key
|
|
204
|
+
permissions <cmd> Manage permission mode and tool tuples (status, bootstrap, observe, enforce)
|
|
188
205
|
status [--project-dir <path>] Show plugin configuration and status
|
|
189
206
|
local <cmd> Manage local Ory dev environment (up, down, status, seed, ...)
|
|
190
207
|
|
package/dist/plugin.js
CHANGED
|
@@ -201,16 +201,30 @@ function createPermissionHandler(client, _options) {
|
|
|
201
201
|
subject,
|
|
202
202
|
spanAttributes: { toolName: input.toolID },
|
|
203
203
|
});
|
|
204
|
-
|
|
204
|
+
const decision = (0, argus_1.applyPermissionMode)(client, mcpResult.allowed, {
|
|
205
|
+
object: mcpTool.serverName,
|
|
206
|
+
relation: "use",
|
|
207
|
+
subjectId: (0, argus_1.subjectLabel)(subject),
|
|
208
|
+
spanAttributes: { toolName: input.toolID, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName },
|
|
209
|
+
});
|
|
210
|
+
output.status = decision.kind === "deny" ? "deny" : "allow";
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const decision = await (0, argus_1.checkAndDecide)(client, { namespace: resolveNamespace(), object: input.toolID, relation: "use", ...subject }, { spanAttributes: { toolName: input.toolID } });
|
|
214
|
+
if (decision.kind === "fail_open") {
|
|
215
|
+
const code = decision.error.code;
|
|
216
|
+
if (code === "network_error" || code === "rate_limited") {
|
|
217
|
+
client.logger.warn("permission.fallback", {
|
|
218
|
+
toolID: input.toolID,
|
|
219
|
+
code,
|
|
220
|
+
});
|
|
221
|
+
// Leave output.status as "ask" (default)
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
output.status = "ask";
|
|
205
225
|
return;
|
|
206
226
|
}
|
|
207
|
-
|
|
208
|
-
namespace: resolveNamespace(),
|
|
209
|
-
object: input.toolID,
|
|
210
|
-
relation: "use",
|
|
211
|
-
...subject,
|
|
212
|
-
}, { spanAttributes: { toolName: input.toolID } });
|
|
213
|
-
output.status = result.allowed ? "allow" : "deny";
|
|
227
|
+
output.status = decision.kind === "deny" ? "deny" : "allow";
|
|
214
228
|
}
|
|
215
229
|
catch (err) {
|
|
216
230
|
if (isOryError(err) && (err.code === "network_error" || err.code === "rate_limited")) {
|
|
@@ -256,63 +270,90 @@ function createToolBeforeHandler(client) {
|
|
|
256
270
|
subject,
|
|
257
271
|
spanAttributes: { toolName: input.tool },
|
|
258
272
|
});
|
|
259
|
-
|
|
273
|
+
const mcpAttrs = {
|
|
274
|
+
toolName: input.tool,
|
|
275
|
+
mcpServer: mcpTool.serverName,
|
|
276
|
+
mcpTool: mcpTool.toolName,
|
|
277
|
+
...inputSummary,
|
|
278
|
+
};
|
|
279
|
+
const decision = (0, argus_1.applyPermissionMode)(client, mcpResult.allowed, {
|
|
280
|
+
object: mcpTool.serverName,
|
|
281
|
+
relation: "use",
|
|
282
|
+
subjectId,
|
|
283
|
+
spanAttributes: mcpAttrs,
|
|
284
|
+
});
|
|
285
|
+
if (decision.kind === "allow") {
|
|
286
|
+
client.tracer.record("tool.invoke", "ok", { attributes: mcpAttrs });
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (decision.kind === "observe") {
|
|
260
290
|
client.tracer.record("tool.block", "denied", {
|
|
261
|
-
attributes: {
|
|
262
|
-
});
|
|
263
|
-
const message = (0, argus_1.formatDenialMessage)({
|
|
264
|
-
tool: input.tool,
|
|
265
|
-
subjectId,
|
|
266
|
-
mcp: mcpTool,
|
|
291
|
+
attributes: { ...mcpAttrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
|
|
267
292
|
});
|
|
268
|
-
client.
|
|
269
|
-
|
|
270
|
-
subjectId,
|
|
271
|
-
message,
|
|
272
|
-
});
|
|
273
|
-
// OpenCode has no native block signal in tool.execute.before;
|
|
274
|
-
// throwing aborts execution (documented .env-protection pattern)
|
|
275
|
-
// and surfaces error.message back to the agent.
|
|
276
|
-
throw new argus_1.OryDenialError({
|
|
277
|
-
tool: input.tool,
|
|
278
|
-
subjectId,
|
|
279
|
-
mcp: mcpTool,
|
|
293
|
+
client.tracer.record("tool.invoke", "ok", {
|
|
294
|
+
attributes: { ...mcpAttrs, allowed: false, observed: true },
|
|
280
295
|
});
|
|
296
|
+
return;
|
|
281
297
|
}
|
|
282
|
-
client.tracer.record("tool.invoke", "ok", {
|
|
283
|
-
attributes: { toolName: input.tool, mcpServer: mcpTool.serverName, mcpTool: mcpTool.toolName, ...inputSummary },
|
|
284
|
-
});
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const namespace = resolveNamespace();
|
|
288
|
-
const result = await client.checkPermission({
|
|
289
|
-
namespace,
|
|
290
|
-
object: input.tool,
|
|
291
|
-
relation: "use",
|
|
292
|
-
...subject,
|
|
293
|
-
}, { spanAttributes: { toolName: input.tool } });
|
|
294
|
-
if (!result.allowed) {
|
|
295
298
|
client.tracer.record("tool.block", "denied", {
|
|
296
|
-
attributes: {
|
|
299
|
+
attributes: { ...mcpAttrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
|
|
297
300
|
});
|
|
298
301
|
const message = (0, argus_1.formatDenialMessage)({
|
|
299
302
|
tool: input.tool,
|
|
300
303
|
subjectId,
|
|
301
|
-
|
|
304
|
+
mcp: mcpTool,
|
|
302
305
|
});
|
|
303
306
|
client.logger.warn("tool.denied", {
|
|
304
307
|
tool: input.tool,
|
|
305
308
|
subjectId,
|
|
306
309
|
message,
|
|
307
310
|
});
|
|
311
|
+
// OpenCode has no native block signal in tool.execute.before;
|
|
312
|
+
// throwing aborts execution (documented .env-protection pattern)
|
|
313
|
+
// and surfaces error.message back to the agent.
|
|
308
314
|
throw new argus_1.OryDenialError({
|
|
309
315
|
tool: input.tool,
|
|
310
316
|
subjectId,
|
|
311
|
-
|
|
317
|
+
mcp: mcpTool,
|
|
312
318
|
});
|
|
313
319
|
}
|
|
314
|
-
|
|
315
|
-
|
|
320
|
+
const namespace = resolveNamespace();
|
|
321
|
+
const decision = await (0, argus_1.checkAndDecide)(client, { namespace, object: input.tool, relation: "use", ...subject }, { spanAttributes: { toolName: input.tool } });
|
|
322
|
+
if (decision.kind === "fail_open") {
|
|
323
|
+
handlePermissionError(decision.error, input.tool, client);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const attrs = { toolName: input.tool, ...inputSummary };
|
|
327
|
+
if (decision.kind === "allow") {
|
|
328
|
+
client.tracer.record("tool.invoke", "ok", { attributes: { ...attrs, allowed: true } });
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (decision.kind === "observe") {
|
|
332
|
+
client.tracer.record("tool.block", "denied", {
|
|
333
|
+
attributes: { ...attrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
|
|
334
|
+
});
|
|
335
|
+
client.tracer.record("tool.invoke", "ok", {
|
|
336
|
+
attributes: { ...attrs, allowed: false, observed: true },
|
|
337
|
+
});
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
client.tracer.record("tool.block", "denied", {
|
|
341
|
+
attributes: { ...attrs, allowed: false, ...(0, argus_1.alertAttributes)(false) },
|
|
342
|
+
});
|
|
343
|
+
const message = (0, argus_1.formatDenialMessage)({
|
|
344
|
+
tool: input.tool,
|
|
345
|
+
subjectId,
|
|
346
|
+
namespace,
|
|
347
|
+
});
|
|
348
|
+
client.logger.warn("tool.denied", {
|
|
349
|
+
tool: input.tool,
|
|
350
|
+
subjectId,
|
|
351
|
+
message,
|
|
352
|
+
});
|
|
353
|
+
throw new argus_1.OryDenialError({
|
|
354
|
+
tool: input.tool,
|
|
355
|
+
subjectId,
|
|
356
|
+
namespace,
|
|
316
357
|
});
|
|
317
358
|
}
|
|
318
359
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ory/opencode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"!dist/**/*.tsbuildinfo"
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@ory/argus": "0.
|
|
67
|
+
"@ory/argus": "0.2.0"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=24"
|