@ory/argus 0.14.0 → 1.0.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.
Files changed (150) hide show
  1. package/README.md +31 -46
  2. package/assets/commands/temporal-up.md +1 -1
  3. package/assets/skills/auth-setup/SKILL.md +1 -1
  4. package/assets/skills/local-dev/SKILL.md +17 -7
  5. package/assets/skills/ory-build-agent/SKILL.md +39 -91
  6. package/assets/skills/ory-e2b-sandbox/SKILL.md +18 -17
  7. package/assets/skills/ory-temporal-worker/SKILL.md +31 -33
  8. package/assets/skills/permissions-onboarding/SKILL.md +131 -104
  9. package/dist/adapters.d.ts +88 -32
  10. package/dist/adapters.js +443 -164
  11. package/dist/agent-auth.d.ts +226 -67
  12. package/dist/agent-auth.js +951 -205
  13. package/dist/auth-store.d.ts +37 -2
  14. package/dist/auth-store.js +37 -3
  15. package/dist/auth.d.ts +33 -4
  16. package/dist/auth.js +163 -20
  17. package/dist/bash-parser.d.ts +98 -0
  18. package/dist/bash-parser.js +396 -0
  19. package/dist/branding.d.ts +77 -16
  20. package/dist/branding.js +93 -23
  21. package/dist/build-info.json +4 -4
  22. package/dist/cli-invocation.d.ts +1 -1
  23. package/dist/cli-invocation.js +2 -1
  24. package/dist/cli.d.ts +20 -29
  25. package/dist/cli.js +271 -239
  26. package/dist/client.d.ts +175 -138
  27. package/dist/client.js +672 -391
  28. package/dist/config.d.ts +217 -54
  29. package/dist/config.js +461 -42
  30. package/dist/context.d.ts +10 -0
  31. package/dist/context.js +21 -0
  32. package/dist/contract-suite.d.ts +3 -5
  33. package/dist/contract-suite.js +75 -47
  34. package/dist/denial.d.ts +36 -3
  35. package/dist/denial.js +79 -10
  36. package/dist/event-reporter.d.ts +77 -0
  37. package/dist/event-reporter.js +776 -0
  38. package/dist/external-registrations-main.d.ts +10 -0
  39. package/dist/external-registrations-main.js +38 -0
  40. package/dist/external-registrations.d.ts +79 -0
  41. package/dist/external-registrations.js +188 -0
  42. package/dist/help-cli.d.ts +39 -0
  43. package/dist/help-cli.js +55 -0
  44. package/dist/hook-timeout.d.ts +64 -0
  45. package/dist/hook-timeout.js +88 -0
  46. package/dist/index.d.ts +28 -23
  47. package/dist/index.js +173 -58
  48. package/dist/lifecycle.d.ts +3 -3
  49. package/dist/lifecycle.js +38 -6
  50. package/dist/local/cli.js +11 -6
  51. package/dist/local/configs.d.ts +74 -18
  52. package/dist/local/configs.js +291 -84
  53. package/dist/local/health.js +7 -7
  54. package/dist/local/index.d.ts +2 -2
  55. package/dist/local/index.js +24 -10
  56. package/dist/local/manager.d.ts +20 -1
  57. package/dist/local/manager.js +159 -36
  58. package/dist/local/ports.d.ts +158 -0
  59. package/dist/local/ports.js +443 -0
  60. package/dist/local/seed.d.ts +13 -5
  61. package/dist/local/seed.js +62 -38
  62. package/dist/logger.d.ts +54 -25
  63. package/dist/logger.js +329 -63
  64. package/dist/mcp.d.ts +2 -2
  65. package/dist/mcp.js +10 -5
  66. package/dist/mirror-bootstrap.d.ts +48 -0
  67. package/dist/mirror-bootstrap.js +254 -0
  68. package/dist/opl.d.ts +289 -0
  69. package/dist/opl.js +446 -0
  70. package/dist/permission-mode.d.ts +87 -0
  71. package/dist/permission-mode.js +307 -0
  72. package/dist/permissions-cli.d.ts +13 -49
  73. package/dist/permissions-cli.js +154 -348
  74. package/dist/permissions.d.ts +148 -38
  75. package/dist/permissions.js +591 -45
  76. package/dist/post-install.d.ts +33 -0
  77. package/dist/post-install.js +127 -0
  78. package/dist/read-credential.d.ts +65 -0
  79. package/dist/read-credential.js +86 -0
  80. package/dist/registry/cli.js +5 -2
  81. package/dist/registry/config.d.ts +0 -17
  82. package/dist/registry/config.js +0 -23
  83. package/dist/registry/index.d.ts +1 -1
  84. package/dist/registry/index.js +2 -2
  85. package/dist/registry/manager.d.ts +4 -21
  86. package/dist/registry/manager.js +21 -37
  87. package/dist/runtime-credential.d.ts +140 -0
  88. package/dist/runtime-credential.js +572 -0
  89. package/dist/runtime.d.ts +413 -0
  90. package/dist/runtime.js +825 -0
  91. package/dist/setup.d.ts +23 -47
  92. package/dist/setup.js +59 -116
  93. package/dist/skills.js +0 -7
  94. package/dist/status-cli.d.ts +27 -11
  95. package/dist/status-cli.js +121 -115
  96. package/dist/status-data.d.ts +116 -17
  97. package/dist/status-data.js +121 -38
  98. package/dist/subject.d.ts +126 -20
  99. package/dist/subject.js +215 -30
  100. package/dist/testing.d.ts +74 -38
  101. package/dist/testing.js +185 -68
  102. package/dist/tool-catalog.d.ts +53 -11
  103. package/dist/tool-catalog.js +164 -13
  104. package/dist/tool-metadata.d.ts +7 -6
  105. package/dist/tool-metadata.js +6 -5
  106. package/dist/types.d.ts +11 -1
  107. package/dist/uninstall.d.ts +71 -34
  108. package/dist/uninstall.js +217 -85
  109. package/dist/user-login.d.ts +9 -10
  110. package/dist/user-login.js +56 -75
  111. package/dist/watch-cli.d.ts +6 -0
  112. package/dist/watch-cli.js +217 -0
  113. package/package.json +4 -27
  114. package/assets/commands/dashboard.md +0 -34
  115. package/dist/dashboard-cli.d.ts +0 -8
  116. package/dist/dashboard-cli.js +0 -70
  117. package/dist/dev.d.ts +0 -103
  118. package/dist/dev.js +0 -583
  119. package/dist/interactive-setup.d.ts +0 -286
  120. package/dist/interactive-setup.js +0 -1734
  121. package/dist/local/jaeger-main.d.ts +0 -13
  122. package/dist/local/jaeger-main.js +0 -85
  123. package/dist/local/jaeger.d.ts +0 -50
  124. package/dist/local/jaeger.js +0 -162
  125. package/dist/otel/exporter.d.ts +0 -17
  126. package/dist/otel/exporter.js +0 -12
  127. package/dist/otel/index.d.ts +0 -2
  128. package/dist/otel/index.js +0 -8
  129. package/dist/otel/otlp.d.ts +0 -103
  130. package/dist/otel/otlp.js +0 -385
  131. package/dist/project-api-key.d.ts +0 -69
  132. package/dist/project-api-key.js +0 -147
  133. package/dist/setup-actions.d.ts +0 -232
  134. package/dist/setup-actions.js +0 -507
  135. package/dist/tracer.d.ts +0 -190
  136. package/dist/tracer.js +0 -481
  137. package/dist/watch-sandbox.d.ts +0 -9
  138. package/dist/watch-sandbox.js +0 -81
  139. package/dist/web/api.d.ts +0 -33
  140. package/dist/web/api.js +0 -294
  141. package/dist/web/launch.d.ts +0 -11
  142. package/dist/web/launch.js +0 -96
  143. package/dist/web/server.d.ts +0 -20
  144. package/dist/web/server.js +0 -233
  145. package/dist/web/types.d.ts +0 -65
  146. package/dist/web/types.js +0 -2
  147. package/dist/webapp/assets/index-Wucl4SZs.css +0 -1
  148. package/dist/webapp/assets/index-m-GtEdq0.js +0 -49
  149. package/dist/webapp/favicon.ico +0 -0
  150. package/dist/webapp/index.html +0 -15
package/dist/client.d.ts CHANGED
@@ -1,23 +1,22 @@
1
1
  import { DebugLogger } from "./logger.js";
2
- import { Tracer } from "./tracer.js";
3
- import type { SpanExporter } from "./otel/exporter.js";
2
+ import { type EventReporterOptions } from "./event-reporter.js";
3
+ import type { SessionContext } from "./context.js";
4
+ import { type RuntimeCredential, type RuntimeRequestAuthenticator } from "./runtime-credential.js";
4
5
  import type { SessionInfo, OAuth2TokenInfo, PermissionCheck, PermissionResult, BatchPermissionResult, OryError } from "./types.js";
5
6
  export interface OryAgentConfig {
6
7
  /** Ory project URL, e.g. https://your-project.projects.oryapis.com */
7
8
  projectUrl: string;
8
- /** Ory API key for admin operations */
9
- apiKey?: string;
9
+ /** Agent Security broker URL. Defaults to projectUrl for shipped configs. */
10
+ agentSecurityUrl?: string;
10
11
  /** Which harness this client is running in */
11
12
  harness: string;
12
- /** Optional log file path for debug output */
13
+ /** Optional unified activity/debug NDJSON file path. */
13
14
  logFile?: string;
14
- /** Optional NDJSON trace file path for structured span output */
15
- traceFile?: string;
16
15
  /**
17
- * Permission-check subject namespace for the human user. When set, the
18
- * user is addressed as a SubjectSet `<namespace>:<subject>` (matching how
19
- * the tuples were written in Keto) rather than a direct SubjectID. Read by
20
- * {@link resolveUserSubject}; `ORY_USER_SUBJECT_NAMESPACE` overrides it.
16
+ * Overrides the namespace the human user is addressed under. Users are always
17
+ * addressed as a SubjectSet `<namespace>:<subject>` (matching how the tuples
18
+ * were written in Keto); this only overrides the namespace (default `User`).
19
+ * Read by {@link resolveUserSubject}; `ORY_USER_SUBJECT_NAMESPACE` overrides it.
21
20
  */
22
21
  userSubjectNamespace?: string;
23
22
  /**
@@ -25,15 +24,81 @@ export interface OryAgentConfig {
25
24
  * Set to 0 to disable caching. Default: 60_000 (1 minute).
26
25
  */
27
26
  sessionCacheTtlMs?: number;
28
- /** Optional span exporter (OTLP, vendor SDK, …) attached to the tracer. */
29
- exporter?: SpanExporter;
27
+ /** Noninteractive request authentication, e.g. a SPIFFE mTLS transport. */
28
+ runtimeRequestAuthenticator?: RuntimeRequestAuthenticator;
29
+ /** Optional stable runtime subject supplied by the custom integration. */
30
+ runtimeSubject?: string;
31
+ /** Disabled by default so direct/test clients never perform background network calls. */
32
+ eventReporter?: true | Omit<EventReporterOptions, "projectUrl" | "agentSecurityUrl" | "token" | "onUnauthorized" | "logger">;
33
+ }
34
+ /**
35
+ * Inputs for {@link OryAgentClient.recordDelegation}. The plugin supplies only
36
+ * the *semantic* ends of the edge; the agent-security broker owns the Keto
37
+ * tuple shape (namespace, `delegate` relation, and the
38
+ * `<identity>|<harness>|<host>` join-key encoding), so no tuple/join-key logic
39
+ * lives in the plugin.
40
+ */
41
+ export interface RecordDelegationInput {
42
+ /**
43
+ * Which edge to record. `agent` records `user → agent`; `subagent` records
44
+ * `agent → subagent`. Maps to the broker's `PRINCIPAL_KIND_AGENT` /
45
+ * `PRINCIPAL_KIND_SUBAGENT`.
46
+ */
47
+ kind: "agent" | "subagent";
48
+ /**
49
+ * Kratos identity the delegation is anchored to (→ `User:<identityId>`).
50
+ * Required for the `agent` edge; optional for `subagent` (the broker resolves
51
+ * the anchor from `delegatedBy`).
52
+ */
53
+ identityId?: string;
54
+ /** Host the runtime executes on — part of the `agent` edge join key. */
55
+ host?: string;
56
+ /**
57
+ * Sub-agent runtime type name (e.g. `"explore"`); required for the `subagent`
58
+ * edge. Sent as `principal.type_name`.
59
+ */
60
+ subAgentType?: string;
61
+ /**
62
+ * The parent agent's delegation node (`agent:<join>` or the bare join key),
63
+ * as returned in {@link RecordDelegationResult.nodeId} from the `agent` edge.
64
+ * Required for the `subagent` edge; echoed verbatim so the plugin never
65
+ * reconstructs the server's join-key encoding.
66
+ */
67
+ delegatedBy?: string;
68
+ /**
69
+ * The harness session this edge was recorded in — sent as
70
+ * `principal.session_id`, which is the field the broker's proto defines. The
71
+ * dynamic OAuth2 credential is keyed by this session, and the broker also
72
+ * needs the session to build the corresponding delegation node.
73
+ *
74
+ * Defaults to the client's ambient session ({@link OryAgentClient.sessionId},
75
+ * set by the harness's ambient session context); pass explicitly to override. Absent
76
+ * for a caller with no session concept, which the broker reads as "keep this
77
+ * runtime on one stable node" rather than inventing a session for it.
78
+ */
79
+ sessionId?: string;
80
+ /**
81
+ * Identifier for one *spawn* of a sub-agent, where the harness exposes one
82
+ * (Cursor's `subagent_id`, Claude Code's `agent_id`, OpenClaw's `childRunId`).
83
+ * Sent as `principal.per_spawn_id`; it is what distinguishes two concurrent
84
+ * same-type sub-agents. Absent on harnesses that expose no such id, in which
85
+ * case concurrent spawns of a type share a node.
86
+ */
87
+ perSpawnId?: string;
88
+ }
89
+ /** The delegation node the broker wrote, plus the resolved chain (root-first). */
90
+ export interface RecordDelegationResult {
91
+ /** The node id written: `agent:<join>` or `subagent:<join>|<type>`. */
92
+ nodeId: string;
93
+ /** Root-first chain, e.g. `["User:<id>", "agent:<join>"]`. */
94
+ delegationChain: string[];
30
95
  }
31
96
  /**
32
97
  * A principal known to the client. Either the human user (interactive
33
98
  * PKCE login) or the agent (machine credentials).
34
99
  */
35
100
  export interface PrincipalIdentity {
36
- /** Subject (sub claim or `session:<id>`) used in audit spans. */
101
+ /** Subject (sub claim or `session:<id>`) used in audit activity. */
37
102
  subject?: string;
38
103
  /** Bearer token. Agent's token authenticates outgoing API calls. */
39
104
  token?: string;
@@ -42,10 +107,12 @@ export declare class OryAgentClient {
42
107
  private frontend;
43
108
  private oauth2;
44
109
  private permission;
45
- private relationship;
46
110
  private config;
47
111
  readonly logger: DebugLogger;
48
- readonly tracer: Tracer;
112
+ private readonly eventReporter?;
113
+ private _runtimeCredential?;
114
+ private readonly _runtimeCredentialsBySession;
115
+ private readonly _runtimeCredentialsByPrincipalKey;
49
116
  private sessionCache;
50
117
  private sessionCacheTtlMs;
51
118
  /**
@@ -53,35 +120,57 @@ export declare class OryAgentClient {
53
120
  * Populated by `ensureUserAuthenticated` on session start.
54
121
  */
55
122
  private _userPrincipal;
123
+ private readonly _userPrincipalsBySession;
56
124
  /**
57
125
  * The AI agent process — the principal that authenticates outgoing
58
126
  * Ory API calls. Populated by `ensureAgentIdentity`.
59
127
  */
60
128
  private _agentPrincipal;
61
- /**
62
- * Admin credential — an Ory Network **project API key** (`ory_pat_…`) —
63
- * used to authenticate the Keto Permission and Relationship APIs.
64
- *
65
- * This is deliberately distinct from the agent principal's token. Ory
66
- * Network's permission APIs authenticate with a project API key and
67
- * **reject project-issued OAuth2 access tokens** (a DCR client-credentials
68
- * token is answered with `401 "Access token is not active"`). So when the
69
- * agent identity resolves to a DCR OAuth2 client — the default path — its
70
- * token cannot authenticate permission checks. Holding the admin key here
71
- * lets {@link buildApis} route Keto through it while the agent OAuth2 token
72
- * still authenticates the OAuth2 / Frontend APIs and carries attribution.
73
- *
74
- * When unset, Keto calls fall back to the agent token (legacy
75
- * single-credential behavior, unchanged for static-key deployments).
76
- */
77
- private _adminApiKey?;
129
+ private readonly _agentPrincipalsBySession;
130
+ private readonly _eventPrincipalsByKey;
78
131
  constructor(config: OryAgentConfig);
79
132
  /** Build a fresh set of Ory API instances using the current agent token. */
80
133
  private buildApis;
134
+ /** Canonical broker origin, with the shipped project URL fallback applied. */
135
+ get agentSecurityUrl(): string;
136
+ private buildBrokerPermissionTransport;
137
+ private postPermissionChecks;
138
+ private permissionPrincipal;
139
+ private subAgentTypeForClient;
81
140
  /** Snapshot of the current user principal. */
82
141
  get userPrincipal(): PrincipalIdentity;
142
+ /** Snapshot of the user principal bound to one session. */
143
+ userPrincipalForSession(sessionId?: string): PrincipalIdentity;
83
144
  /** Snapshot of the current agent principal. */
84
145
  get agentPrincipal(): PrincipalIdentity;
146
+ /** Active noninteractive broker credential. It is process memory only. */
147
+ get runtimeCredential(): RuntimeCredential | undefined;
148
+ get hasRuntimeCredential(): boolean;
149
+ setRuntimeCredential(credential: RuntimeCredential | undefined): void;
150
+ /** Retain an actor-scoped credential for deferred event delivery without activating it globally. */
151
+ rememberRuntimeCredential(credential: RuntimeCredential): void;
152
+ /** Run one hook with session/credential state isolated from concurrent hooks. */
153
+ withRuntimeContext<T>(context: SessionContext, work: () => T): T;
154
+ /** Snapshot of the agent principal bound to one session. */
155
+ agentPrincipalForSession(sessionId?: string): PrincipalIdentity;
156
+ private eventPrincipal;
157
+ /**
158
+ * The harness this client runs in (`"claude-code"`, `"codex"`, …). Exposed
159
+ * because persisted agent / sub-agent credentials and delegation anchors are
160
+ * keyed first by harness and then by session.
161
+ */
162
+ get harness(): string;
163
+ /**
164
+ * The harness session currently in scope, or `undefined` outside one.
165
+ *
166
+ * Read from standalone ambient session context, which every harness sets from its
167
+ * own session identifier at the top of a lifecycle invocation — so identity
168
+ * and delegation code can select the session's credential and node without
169
+ * each plugin threading the id through its own call chain.
170
+ */
171
+ get sessionId(): string | undefined;
172
+ /** Best-effort bounded flush for short-lived hook subprocesses and tests. */
173
+ flushEvents(timeoutMs?: number): Promise<void>;
85
174
  /**
86
175
  * Configured user-subject namespace (from config, resolved at construction).
87
176
  * `resolveUserSubject` uses this as the SubjectSet namespace when the
@@ -91,31 +180,23 @@ export declare class OryAgentClient {
91
180
  get userSubjectNamespace(): string | undefined;
92
181
  /**
93
182
  * Set or update the human user principal. The user is the subject of
94
- * permission checks but does not authenticate outgoing API calls.
95
- * Pass `{}` (or fields set to undefined) to clear.
96
- */
97
- setUserPrincipal(principal: PrincipalIdentity): void;
98
- /** Whether an admin API key is set for the Keto APIs (never exposes it). */
99
- get hasAdminApiKey(): boolean;
100
- /**
101
- * Set or update the admin API key (an Ory Network project API key) used to
102
- * authenticate the Keto Permission / Relationship APIs. Rebuilds those API
103
- * instances when the key changes; a no-op update leaves them alone so test
104
- * stubs survive. See {@link _adminApiKey} for why Keto needs a credential
105
- * distinct from the agent's OAuth2 token.
183
+ * permission checks. Its token does not authenticate agent-attributed calls
184
+ * (OAuth2 / Frontend / Relationship), but it *is* the fallback credential for
185
+ * Keto permission reads when no agent token is present (see `buildApis`) — so
186
+ * a change to the user token rebuilds the API instances, otherwise the
187
+ * rehydrated user token would never reach the Permission API in a fresh
188
+ * subprocess. Pass `{}` (or fields set to undefined) to clear.
106
189
  */
107
- setAdminApiKey(apiKey: string | undefined): void;
190
+ setUserPrincipal(principal: PrincipalIdentity, sessionId?: string | undefined): void;
108
191
  /**
109
192
  * Set or update the AI agent principal. The agent's token (when present)
110
- * authenticates outgoing calls to the OAuth2 / Frontend APIs and carries
111
- * audit attribution ("agent X acting on behalf of user Y"). Note the Keto
112
- * Permission / Relationship APIs authenticate with {@link _adminApiKey}
113
- * instead when one is set Ory Network rejects OAuth2 tokens there.
114
- * Rebuilds the underlying Ory API instances when the token actually changes
115
- * so subsequent calls pick it up; otherwise leaves the API instances alone
116
- * (so test stubs survive a no-op update).
193
+ * authenticates *every* outgoing Ory call OAuth2 / Frontend and Keto
194
+ * (Permission / Relationship) alike and carries audit attribution ("agent X
195
+ * acting on behalf of user Y"). Rebuilds the underlying Ory API instances when
196
+ * the token actually changes so subsequent calls pick it up; otherwise leaves
197
+ * the API instances alone (so test stubs survive a no-op update).
117
198
  */
118
- setAgentPrincipal(principal: PrincipalIdentity): void;
199
+ setAgentPrincipal(principal: PrincipalIdentity, sessionId?: string | undefined): void;
119
200
  /**
120
201
  * Verify an existing session token. Returns cached result if available.
121
202
  */
@@ -128,93 +209,55 @@ export declare class OryAgentClient {
128
209
  /**
129
210
  * Check if a subject has permission to perform an action.
130
211
  *
131
- * `options.spanAttributes` are merged into the `permission.check` trace
132
- * span so callers can attach harness-side context (toolName, mcpServer,
212
+ * `options.activityAttributes` are merged into the `permission.check` activity
213
+ * event so callers can attach harness-side context (toolName, mcpServer,
133
214
  * etc.) that the wire-level `PermissionCheck` shape doesn't carry.
215
+ *
216
+ * `options.informational` marks a check whose `false` result is *not* a
217
+ * denial — e.g. the permission-mode probe, where "enforce not granted" simply
218
+ * selects `observe`. Such an event ends `ok` (the read succeeded) rather than
219
+ * `denied`, so a reader watching activity doesn't mistake a routine mode read
220
+ * for a blocked tool. The boolean is still recorded as the `allowed`
221
+ * attribute either way.
134
222
  */
135
223
  checkPermission(check: PermissionCheck, options?: {
136
- spanAttributes?: Record<string, unknown>;
224
+ activityAttributes?: Record<string, unknown>;
225
+ informational?: boolean;
137
226
  }): Promise<PermissionResult>;
138
227
  /**
139
228
  * Check multiple permissions in a single request.
140
229
  *
141
- * `options.spanAttributes` are merged into the `permission.batch_check`
142
- * span same purpose as `checkPermission`'s spanAttributes.
230
+ * `options.activityAttributes` are merged into the `permission.batch_check`
231
+ * activity event, for the same purpose as `checkPermission`'s attributes.
143
232
  */
144
233
  batchCheckPermissions(checks: PermissionCheck[], options?: {
145
- spanAttributes?: Record<string, unknown>;
234
+ activityAttributes?: Record<string, unknown>;
146
235
  }): Promise<BatchPermissionResult>;
147
236
  /**
148
- * Create a relation tuple in Keto. Idempotent: a 409 (tuple already
149
- * exists) is swallowed and reported as success. All other errors are
150
- * classified and re-thrown callers wrap in fail-open semantics if
151
- * the tuple is non-critical (e.g. audit-only delegation tracking).
152
- *
153
- * `options.spanAttributes` are merged into the `relationship.create`
154
- * trace span so callers can attach context like `delegation: "user→agent"`.
155
- */
156
- createRelationship(check: PermissionCheck, options?: {
157
- spanAttributes?: Record<string, unknown>;
158
- }): Promise<{
159
- created: boolean;
160
- alreadyExisted: boolean;
161
- }>;
162
- /**
163
- * True if the *exact* relation tuple already exists in Keto. Queries the
164
- * relation-tuple listing API filtered by the tuple's own coordinates
165
- * (namespace/object/relation + subject), so — unlike `checkPermission` —
166
- * it does not follow subject-set expansion: it answers "is this literal
167
- * tuple stored?", not "does this permission resolve?". Throws a classified
168
- * {@link OryError} if the query itself fails.
169
- */
170
- relationshipExists(check: PermissionCheck): Promise<boolean>;
171
- /**
172
- * Idempotent relationship write. Keto's create API is **not** idempotent —
173
- * `PUT /admin/relation-tuples` inserts a fresh row on every call (each with
174
- * a new primary key) and never returns 409, so calling `createRelationship`
175
- * on repeated bootstraps / session starts accumulates duplicate tuples.
176
- * This reads the exact tuple first (via {@link relationshipExists}) and only
177
- * writes when it is absent — which also self-heals if the tuple was deleted
178
- * out of band.
237
+ * Record a delegation edge through the Ory Agent Security broker
238
+ * (`POST <agentSecurityUrl>/agent-security/v1/delegations:record`), authenticated
239
+ * with the process runtime credential. The broker constructs and writes the Keto tuple the plugin
240
+ * sends only the semantic inputs, so the join-key/tuple encoding stays
241
+ * server-side and cannot drift here. Returns the node id + chain the broker
242
+ * assigned. Throws a classified {@link OryError} on any non-2xx; callers wrap
243
+ * in fail-open semantics (delegation is audit-only).
179
244
  *
180
- * If the existence probe itself fails, the tuple is left untouched (we do
181
- * not write blind, to avoid re-introducing duplicates when the read path is
182
- * misbehaving) and the classified error is returned as `probeError`. Callers
183
- * that must guarantee the grant exists (e.g. install-time bootstrap) can
184
- * fall back to {@link createRelationship} when `probeError` is set.
185
- */
186
- ensureRelationship(check: PermissionCheck, options?: {
187
- spanAttributes?: Record<string, unknown>;
188
- }): Promise<{
189
- created: boolean;
190
- alreadyExisted: boolean;
191
- probeError?: OryError;
192
- }>;
193
- /**
194
- * Delete a relation tuple in Keto. Missing tuples (404) are treated as
195
- * success so callers can call this idempotently when unwinding state.
196
- */
197
- deleteRelationship(check: PermissionCheck, options?: {
198
- spanAttributes?: Record<string, unknown>;
199
- }): Promise<{
200
- deleted: boolean;
201
- notFound: boolean;
202
- }>;
203
- /**
204
- * Span attributes describing which principals were attached to the
205
- * client when the span was started. Useful for correlating audit logs
206
- * across the user/agent split.
245
+ * The broker exists only on hosted Ory; against the local dev stack the call
246
+ * returns 404 and callers treat it as a best-effort no-op.
207
247
  */
208
- private principalSpanAttributes;
248
+ recordDelegation(input: RecordDelegationInput, options?: {
249
+ fetchImpl?: typeof fetch;
250
+ activityAttributes?: Record<string, unknown>;
251
+ agentToken?: string;
252
+ runtimeCredential?: RuntimeCredential;
253
+ signal?: AbortSignal;
254
+ }): Promise<RecordDelegationResult>;
209
255
  /**
210
- * When a Keto call is auth-rejected while it was authenticated by something
211
- * other than an Ory Network project API key (`ory_pat_…`) — e.g. a DCR
212
- * OAuth2 access token — the credential *type* is wrong, not merely expired.
213
- * Ory Network's Permission / Relationship APIs only accept a project API
214
- * key. Emit an actionable hint so the failure isn't misread as a stale
215
- * session (the generic `session_inactive` classification of the raw 401).
256
+ * Activity attributes describing which principals are attached to the
257
+ * client. Useful for correlating audit logs
258
+ * across the user/agent split.
216
259
  */
217
- private warnIfKetoCredentialMismatch;
260
+ private principalActivityAttributes;
218
261
  /**
219
262
  * Classify an error from any Ory API call into a structured OryError.
220
263
  */
@@ -227,26 +270,20 @@ export declare class OryAgentClient {
227
270
  * Create a client from environment variables, falling back to the
228
271
  * shared config file at ~/.config/ory-agent-plugins/config.json.
229
272
  *
230
- * Resolution order for projectUrl and apiKey:
231
- * 1. Environment variables (ORY_PROJECT_URL, ORY_API_KEY)
273
+ * Resolution order for projectUrl:
274
+ * 1. Environment variables (ORY_PROJECT_URL / ORY_SDK_URL)
232
275
  * 2. Config file (~/.config/ory-agent-plugins/config.json)
233
276
  * 3. Placeholder (fail-open pass-through mode)
234
277
  */
235
- static fromEnv(harness: string): OryAgentClient;
278
+ static fromEnv(harness: string, runtime?: Pick<OryAgentConfig, "runtimeRequestAuthenticator" | "runtimeSubject">): OryAgentClient;
236
279
  }
237
- /** Default debug-log path under the shared per-harness data dir. */
280
+ /** Default unified activity/debug log path under the shared per-harness data dir. */
238
281
  export declare const DEFAULT_DEBUG_LOG_FILENAME = "ory-agent-debug.log";
239
- /** Default trace (NDJSON) path under the shared per-harness data dir. */
240
- export declare const DEFAULT_TRACE_FILENAME = "ory-agent-trace.ndjson";
241
282
  /**
242
- * Debug log path. Only written when `ORY_AGENT_DEBUG=true` (the logger gates
243
- * on that); defaulting the path just means an enabled debug session lands in a
244
- * file automatically — important for subprocess-hook harnesses whose stderr
245
- * the harness may swallow.
283
+ * Unified activity/debug log path. Activity is always appended; verbose
284
+ * debug/info/warn/error entries are appended only when `ORY_AGENT_DEBUG=true`.
246
285
  */
247
286
  export declare function resolveDebugLogPath(harness: string): string | undefined;
248
- /** Trace (NDJSON) path. Written on every recorded span when set. */
249
- export declare function resolveTraceFilePath(harness: string): string | undefined;
250
287
  /**
251
288
  * Pull the Ory backend request ID from a response headers bag (axios returns
252
289
  * lowercase header names). Returns undefined when not present.