@ory/argus 0.13.9 → 1.0.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.
Files changed (133) hide show
  1. package/README.md +31 -45
  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 +43 -97
  6. package/assets/skills/ory-e2b-sandbox/SKILL.md +18 -18
  7. package/assets/skills/ory-temporal-worker/SKILL.md +38 -42
  8. package/assets/skills/permissions-onboarding/SKILL.md +131 -104
  9. package/dist/adapters.d.ts +93 -30
  10. package/dist/adapters.js +464 -136
  11. package/dist/agent-auth.d.ts +258 -68
  12. package/dist/agent-auth.js +998 -202
  13. package/dist/auth-store.d.ts +37 -2
  14. package/dist/auth-store.js +37 -3
  15. package/dist/auth.d.ts +40 -4
  16. package/dist/auth.js +247 -19
  17. package/dist/bash-parser.d.ts +98 -0
  18. package/dist/bash-parser.js +396 -0
  19. package/dist/branding.d.ts +128 -0
  20. package/dist/branding.js +151 -0
  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 -278
  26. package/dist/client.d.ts +175 -138
  27. package/dist/client.js +672 -391
  28. package/dist/config.d.ts +249 -57
  29. package/dist/config.js +486 -62
  30. package/dist/context.d.ts +10 -0
  31. package/dist/context.js +21 -0
  32. package/dist/contract-suite.d.ts +8 -8
  33. package/dist/contract-suite.js +88 -69
  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 +31 -19
  47. package/dist/index.js +182 -31
  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.d.ts +14 -0
  54. package/dist/local/health.js +50 -4
  55. package/dist/local/index.d.ts +2 -2
  56. package/dist/local/index.js +24 -10
  57. package/dist/local/manager.d.ts +20 -1
  58. package/dist/local/manager.js +160 -39
  59. package/dist/local/ports.d.ts +158 -0
  60. package/dist/local/ports.js +443 -0
  61. package/dist/local/seed.d.ts +22 -25
  62. package/dist/local/seed.js +88 -56
  63. package/dist/logger.d.ts +54 -25
  64. package/dist/logger.js +329 -63
  65. package/dist/mcp.d.ts +2 -2
  66. package/dist/mcp.js +10 -5
  67. package/dist/mirror-bootstrap.d.ts +48 -0
  68. package/dist/mirror-bootstrap.js +254 -0
  69. package/dist/opl.d.ts +289 -0
  70. package/dist/opl.js +446 -0
  71. package/dist/permission-mode.d.ts +87 -0
  72. package/dist/permission-mode.js +307 -0
  73. package/dist/permissions-cli.d.ts +13 -49
  74. package/dist/permissions-cli.js +154 -348
  75. package/dist/permissions.d.ts +148 -38
  76. package/dist/permissions.js +591 -45
  77. package/dist/post-install.d.ts +33 -0
  78. package/dist/post-install.js +127 -0
  79. package/dist/read-credential.d.ts +65 -0
  80. package/dist/read-credential.js +86 -0
  81. package/dist/registry/cli.js +5 -2
  82. package/dist/registry/config.d.ts +0 -17
  83. package/dist/registry/config.js +0 -23
  84. package/dist/registry/index.d.ts +1 -1
  85. package/dist/registry/index.js +2 -2
  86. package/dist/registry/manager.d.ts +4 -21
  87. package/dist/registry/manager.js +83 -55
  88. package/dist/runtime-credential.d.ts +140 -0
  89. package/dist/runtime-credential.js +572 -0
  90. package/dist/runtime.d.ts +408 -0
  91. package/dist/runtime.js +748 -0
  92. package/dist/setup.d.ts +23 -28
  93. package/dist/setup.js +57 -84
  94. package/dist/status-cli.d.ts +29 -13
  95. package/dist/status-cli.js +124 -144
  96. package/dist/status-data.d.ts +195 -0
  97. package/dist/status-data.js +333 -0
  98. package/dist/status-system.d.ts +24 -0
  99. package/dist/status-system.js +56 -0
  100. package/dist/subject.d.ts +126 -20
  101. package/dist/subject.js +215 -30
  102. package/dist/testing.d.ts +74 -38
  103. package/dist/testing.js +185 -68
  104. package/dist/tool-catalog.d.ts +53 -11
  105. package/dist/tool-catalog.js +164 -13
  106. package/dist/tool-metadata.d.ts +7 -6
  107. package/dist/tool-metadata.js +6 -5
  108. package/dist/types.d.ts +11 -1
  109. package/dist/uninstall.d.ts +74 -19
  110. package/dist/uninstall.js +224 -49
  111. package/dist/user-login.d.ts +22 -16
  112. package/dist/user-login.js +67 -96
  113. package/dist/watch-cli.d.ts +6 -0
  114. package/dist/watch-cli.js +217 -0
  115. package/package.json +3 -11
  116. package/dist/dev.d.ts +0 -103
  117. package/dist/dev.js +0 -584
  118. package/dist/interactive-setup.d.ts +0 -165
  119. package/dist/interactive-setup.js +0 -1546
  120. package/dist/local/jaeger-main.d.ts +0 -13
  121. package/dist/local/jaeger-main.js +0 -85
  122. package/dist/local/jaeger.d.ts +0 -50
  123. package/dist/local/jaeger.js +0 -162
  124. package/dist/otel/exporter.d.ts +0 -17
  125. package/dist/otel/exporter.js +0 -12
  126. package/dist/otel/index.d.ts +0 -2
  127. package/dist/otel/index.js +0 -8
  128. package/dist/otel/otlp.d.ts +0 -103
  129. package/dist/otel/otlp.js +0 -385
  130. package/dist/tracer.d.ts +0 -190
  131. package/dist/tracer.js +0 -481
  132. package/dist/watch-sandbox.d.ts +0 -9
  133. package/dist/watch-sandbox.js +0 -81
@@ -2,15 +2,18 @@
2
2
  * Shared adapter primitives for Agent SDK integrations (and harness plugins).
3
3
  *
4
4
  * These extract the session-start sequencing and the `tool.invoke` / `tool.block` /
5
- * `tool.complete` span boilerplate that each integration would otherwise re-implement, so
5
+ * `tool.complete` activity boilerplate that each integration would otherwise re-implement, so
6
6
  * an SDK binding is a thin translation between the SDK's hook signature and these calls.
7
7
  * They are the TypeScript twin of `ory_argus.adapters` in the Python core.
8
8
  *
9
+ * - {@link withHookContext} — scope session state to one lifecycle invocation.
9
10
  * - {@link sessionStart} — run the user + agent auth gates and write the user→agent
10
11
  * delegation tuple; returns whether the session may proceed.
11
- * - {@link gate} — resolve the subject, run {@link gateToolCall}, record the spans, and
12
+ * - {@link createSessionStarter} — coalesce concurrent lazy SDK session starts.
13
+ * - {@link decideTool} — normalize native/MCP policy without execution activity.
14
+ * - {@link gate} — resolve the subject, run {@link gateToolCall}, record activity, and
12
15
  * return a normalized {@link GateResult}.
13
- * - {@link complete} — record the `tool.complete` span.
16
+ * - {@link complete} / {@link fail} — record safe terminal tool activity.
14
17
  * - {@link registerSubagent} — resolve a sub-agent identity + agent→subagent tuple.
15
18
  * - {@link wrapTool} — wrap a plain `execute(args)` with gate+complete, for SDKs whose
16
19
  * only veto point is the tool boundary (Vercel AI SDK, etc.).
@@ -20,8 +23,17 @@
20
23
  import type { OryAgentClient } from "./client.js";
21
24
  import { ensureAgentIdentity, ensureSubAgentIdentity } from "./agent-auth.js";
22
25
  import { ensureUserAuthenticated } from "./user-login.js";
23
- import { type PermissionDecision } from "./permissions.js";
26
+ import { type ModeDecision, type PermissionDecision, type PrincipalBlockSubjects } from "./permissions.js";
27
+ import { type DenialContext } from "./denial.js";
28
+ import { type McpToolIdentifier } from "./mcp.js";
29
+ import type { RuntimeCredential } from "./runtime-credential.js";
24
30
  export declare function resolveNamespace(): string;
31
+ export interface HookContextOptions {
32
+ sessionId?: string;
33
+ runtimeCredential?: RuntimeCredential;
34
+ }
35
+ /** Scope ambient session state to one lifecycle invocation. */
36
+ export declare function withHookContext<T>(client: OryAgentClient, opts: HookContextOptions, work: () => T): T;
25
37
  export interface SessionStartResult {
26
38
  proceed: boolean;
27
39
  userMode: string;
@@ -30,61 +42,100 @@ export interface SessionStartResult {
30
42
  }
31
43
  export interface SessionStartOptions {
32
44
  harness: string;
33
- allowBlock?: boolean;
45
+ sessionId?: string;
34
46
  projectUrl?: string;
35
47
  binName?: string;
36
48
  /** Injectable gates (tests). */
37
49
  userLogin?: typeof ensureUserAuthenticated;
38
50
  agentGate?: typeof ensureAgentIdentity;
51
+ /** Small, privacy-safe session metadata supported by the activity API. */
52
+ activityAttributes?: Record<string, unknown>;
39
53
  }
40
54
  /**
41
- * Run both auth gates and write the user→agent delegation tuple. `allowBlock` is advisory
42
- * for in-process SDK integrations (the agent can't be prevented from constructing), but the
43
- * user gate still runs, refreshes tokens, and records the `user.auth` span.
55
+ * Run both auth gates and write the user→agent delegation tuple. The user gate
56
+ * runs every session to establish/refresh the user identity, records the
57
+ * `user.auth` activity event, and never blocks enforcement is governed by
58
+ * `permissionMode` at tool-call time. `SessionStartResult.proceed` is therefore
59
+ * always `true`; it is retained only for a stable adapter shape.
44
60
  */
45
61
  export declare function sessionStart(client: OryAgentClient, opts: SessionStartOptions): Promise<SessionStartResult>;
62
+ /** Build a concurrency-safe, retryable lazy session-start trigger. */
63
+ export declare function createSessionStarter(client: OryAgentClient, opts: SessionStartOptions): () => Promise<void>;
46
64
  /**
47
- * Write the `user → agent` delegation tuple, at most once per install
48
- * (see {@link writeDelegationOnce}). Exported so harness plugins that run
49
- * their own session-start sequence (rather than {@link sessionStart}) share
50
- * the same write-once semantics instead of re-issuing the write every
51
- * session. No-op until both principals are populated.
65
+ * Record the `user → agent` delegation edge through the agent-security broker
66
+ * (see {@link OryAgentClient.recordDelegation}). Exported so harness plugins
67
+ * that run their own session-start sequence (rather than {@link sessionStart})
68
+ * record the edge the same way.
69
+ *
70
+ * The plugin supplies only the delegating user identity (resolved from the live
71
+ * principal, else the persisted delegation anchor) plus the harness and host;
72
+ * the broker owns the Keto tuple and its join-key encoding. The node id the
73
+ * broker returns (`agent:<join>`) is persisted so a later sub-agent
74
+ * registration — which may run in a separate subprocess with no live principal
75
+ * — can reference it verbatim as `delegated_by`. Best-effort and fail-open:
76
+ * any failure (including a 404 against the local stack, which has no broker) is
77
+ * logged and swallowed. No-op when Agent Security isn't connected (there is no
78
+ * broker to record against) and when no user identity resolves.
52
79
  */
53
- export declare function writeUserDelegatesAgent(client: OryAgentClient): Promise<void>;
80
+ export declare function writeUserDelegatesAgent(client: OryAgentClient, harness?: string, sessionId?: string): Promise<void>;
54
81
  export interface RegisterSubagentOptions {
55
82
  harness: string;
56
83
  subAgentType: string;
57
84
  projectUrl?: string;
58
85
  subAgentGate?: typeof ensureSubAgentIdentity;
86
+ /**
87
+ * Identifier for this individual spawn, where the harness exposes one
88
+ * (Cursor's `subagent_id`, Claude Code's `agent_id`, OpenClaw's `childRunId`).
89
+ * Distinguishes two concurrent sub-agents of the same type; absent on
90
+ * harnesses that expose no such id.
91
+ */
92
+ perSpawnId?: string;
93
+ sessionId?: string;
94
+ signal?: AbortSignal;
59
95
  }
60
96
  export declare function registerSubagent(client: OryAgentClient, opts: RegisterSubagentOptions): Promise<void>;
61
97
  /**
62
- * Write the `agent → subagent` delegation tuple, at most once per install
63
- * (see {@link writeDelegationOnce}). Exported so harness plugins that
64
- * resolve the sub-agent identity through their own event plumbing (rather
65
- * than {@link registerSubagent}) still share the write-once semantics.
66
- * No-op until the agent principal is populated.
98
+ * Record the `agent → subagent` delegation edge through the agent-security
99
+ * broker. Exported so harness plugins that resolve the sub-agent identity
100
+ * through their own event plumbing (rather than {@link registerSubagent})
101
+ * record the edge the same way.
102
+ *
103
+ * The broker builds the sub-agent node from the parent agent's delegation node
104
+ * (`delegated_by`) and the sub-agent type — so the plugin passes the node id
105
+ * the broker assigned to the `user → agent` edge (persisted at session start),
106
+ * echoed verbatim, and never reconstructs the join-key encoding itself.
107
+ * Best-effort and fail-open. No-op when Agent Security isn't connected and until the
108
+ * `user → agent` edge has been
109
+ * recorded (so the parent node id is available).
67
110
  */
68
- export declare function writeAgentDelegatesSubagent(client: OryAgentClient, subAgentSubject: string, subAgentType: string): Promise<void>;
111
+ export declare function writeAgentDelegatesSubagent(client: OryAgentClient, subAgentSubject: string, subAgentType: string, opts?: {
112
+ harness?: string;
113
+ sessionId?: string;
114
+ perSpawnId?: string;
115
+ agentToken?: string;
116
+ runtimeCredential?: RuntimeCredential;
117
+ signal?: AbortSignal;
118
+ }): Promise<void>;
69
119
  export interface GateResult {
70
120
  /** False only when the tool was hard-denied in enforce mode. */
71
121
  proceed: boolean;
72
122
  /** True only for that deny (and only when `canBlock`). */
73
123
  blocked: boolean;
74
- /** Discriminator: allow / observe / deny / fail_open / interactive / audit_only. */
124
+ /** Discriminator: allow / observe / deny / fail_open / interactive / not_connected. */
75
125
  kind: string;
76
126
  decision: ToolGateOutcomeLike;
77
127
  subject: string;
78
128
  namespace: string;
79
129
  denialMessage?: string;
130
+ denialContext?: DenialContext;
80
131
  }
81
132
  type ToolGateOutcomeLike = {
82
- kind: "audit_only";
83
- spanAttributes: Record<string, unknown>;
133
+ kind: "not_connected";
134
+ activityAttributes: Record<string, unknown>;
84
135
  } | {
85
136
  kind: "interactive";
86
- spanAttributes: Record<string, unknown>;
87
- } | PermissionDecision;
137
+ activityAttributes: Record<string, unknown>;
138
+ } | PermissionDecision | ModeDecision;
88
139
  export interface GateOptions {
89
140
  harness: string;
90
141
  toolName: string;
@@ -92,20 +143,32 @@ export interface GateOptions {
92
143
  subjectFallback?: string;
93
144
  /** Whether the calling integration can actually stop the tool. */
94
145
  canBlock?: boolean;
95
- extraSpanAttributes?: Record<string, unknown>;
146
+ extraActivityAttributes?: Record<string, unknown>;
147
+ /** Normalized MCP identity when this invocation targets an MCP server. */
148
+ mcpTool?: McpToolIdentifier;
149
+ /** Acting sub-agent principal context for explicit machine blocks. */
150
+ principals?: PrincipalBlockSubjects;
96
151
  }
97
152
  /**
98
- * Authorize a tool call, record the spans, and return a normalized {@link GateResult}.
99
- * Records `tool.invoke` on allow/observe and `tool.block` on deny/observe — identical span
100
- * semantics to the harness plugins.
153
+ * Authorize a tool call and return a normalized {@link GateResult} without
154
+ * recording execution activity. Permission-ask hooks use this when the harness
155
+ * separately reports actual execution; {@link gate} adds the standard events.
101
156
  */
157
+ export declare function decideTool(client: OryAgentClient, opts: GateOptions): Promise<GateResult>;
102
158
  export declare function gate(client: OryAgentClient, opts: GateOptions): Promise<GateResult>;
103
159
  export declare function complete(client: OryAgentClient, opts: {
104
160
  toolName: string;
161
+ input?: unknown;
105
162
  output?: unknown;
106
- extraSpanAttributes?: Record<string, unknown>;
163
+ extraActivityAttributes?: Record<string, unknown>;
107
164
  status?: "ok" | "error";
108
165
  }): void;
166
+ export declare function fail(client: OryAgentClient, opts: {
167
+ toolName: string;
168
+ input?: unknown;
169
+ error?: unknown;
170
+ extraActivityAttributes?: Record<string, unknown>;
171
+ }): void;
109
172
  export interface WrapToolOptions {
110
173
  harness: string;
111
174
  toolName: string;