@ory/claude-agent-sdk 0.10.0 → 0.11.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.
package/README.md CHANGED
@@ -24,7 +24,7 @@ query({ prompt, options: { canUseTool: oryCanUseTool() } });
24
24
 
25
25
  `createOryHooks` runs the Ory session gates on `SessionStart`, authorizes on `PreToolUse`
26
26
  (a deny returns `permissionDecision: "deny"`, blocking the tool), records `tool.complete` on
27
- `PostToolUse`, and writes an agent→subagent delegation tuple when the `Task` tool spawns a
27
+ `PostToolUse`, and writes an agent→subagent delegation permission when the `Task` tool spawns a
28
28
  typed sub-agent. In **observe** mode (default) denies are logged but tools run; in **enforce**
29
29
  mode (`ORY_PERMISSION_MODE=enforce`) they're blocked.
30
30
 
package/dist/index.js CHANGED
@@ -18,20 +18,36 @@ exports.createOryHooks = createOryHooks;
18
18
  exports.oryCanUseTool = oryCanUseTool;
19
19
  const argus_1 = require("@ory/argus");
20
20
  const HARNESS = "claude-agent-sdk";
21
+ /**
22
+ * Extract the sub-agent type from a `Task`/`Agent` PreToolUse payload.
23
+ *
24
+ * In the real Claude PreToolUse contract `subagent_type` is a field of the
25
+ * Task tool's `tool_input`, so that is the primary location. A top-level
26
+ * `subagent_type` is kept as a harmless fallback for older payload shapes.
27
+ */
28
+ function resolveSubAgentType(input) {
29
+ const toolInput = input.tool_input;
30
+ if (typeof toolInput === "object" &&
31
+ toolInput !== null &&
32
+ typeof toolInput.subagent_type === "string") {
33
+ return toolInput.subagent_type;
34
+ }
35
+ return typeof input.subagent_type === "string" ? input.subagent_type : undefined;
36
+ }
21
37
  function lazySession(client, projectUrl) {
22
- let started = false;
23
- return async () => {
24
- if (started)
25
- return;
26
- started = true;
27
- try {
28
- await (0, argus_1.sessionStart)(client, { harness: HARNESS, projectUrl });
29
- }
30
- catch (err) {
38
+ let sessionPromise;
39
+ // Cache the in-flight promise (not a boolean) so concurrent first calls all
40
+ // await the same session start instead of racing past a still-running gate.
41
+ // Fail-open: a rejection is logged, never rethrown, and clears the cache so
42
+ // a later call can retry.
43
+ return () => {
44
+ sessionPromise ??= (0, argus_1.sessionStart)(client, { harness: HARNESS, projectUrl }).then(() => undefined, (err) => {
45
+ sessionPromise = undefined;
31
46
  client.logger.warn("session_start.failed", {
32
47
  message: err instanceof Error ? err.message : String(err),
33
48
  });
34
- }
49
+ });
50
+ return sessionPromise;
35
51
  };
36
52
  }
37
53
  /**
@@ -49,12 +65,15 @@ function createOryHooks(options = {}) {
49
65
  await ensureSession();
50
66
  const input = raw;
51
67
  const toolName = input.tool_name;
52
- if ((toolName === "Task" || toolName === "Agent") && typeof input.subagent_type === "string") {
53
- await (0, argus_1.registerSubagent)(client, {
54
- harness: HARNESS,
55
- subAgentType: input.subagent_type,
56
- projectUrl: options.projectUrl,
57
- }).catch(() => undefined);
68
+ if (toolName === "Task" || toolName === "Agent") {
69
+ const subAgentType = resolveSubAgentType(input);
70
+ if (subAgentType) {
71
+ await (0, argus_1.registerSubagent)(client, {
72
+ harness: HARNESS,
73
+ subAgentType,
74
+ projectUrl: options.projectUrl,
75
+ }).catch(() => undefined);
76
+ }
58
77
  }
59
78
  const result = await (0, argus_1.gate)(client, {
60
79
  harness: HARNESS,
package/dist/types.d.ts CHANGED
@@ -8,8 +8,16 @@
8
8
  export interface PreToolUseHookInput {
9
9
  hook_event_name?: "PreToolUse";
10
10
  tool_name: string;
11
+ /**
12
+ * Tool arguments. For the `Task`/`Agent` sub-agent tool this carries the
13
+ * `subagent_type` field — sub-agent detection reads it from here.
14
+ */
11
15
  tool_input?: unknown;
12
- /** Present on the `Task` sub-agent tool. */
16
+ /**
17
+ * Legacy fallback location for the sub-agent type. The real PreToolUse
18
+ * contract delivers `subagent_type` inside `tool_input`, not at the top
19
+ * level; this is only consulted when `tool_input` doesn't carry it.
20
+ */
13
21
  subagent_type?: string;
14
22
  session_id?: string;
15
23
  [key: string]: unknown;
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@ory/claude-agent-sdk",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Ory Agent Security for the Anthropic Claude Agent SDK — per-tool authorization, tracing, and identity propagation via PreToolUse hooks and canUseTool. Built on @ory/argus.",
5
5
  "license": "Apache-2.0",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "registry": "https://registry.npmjs.org/",
9
+ "provenance": true
10
+ },
6
11
  "main": "dist/index.js",
7
12
  "types": "dist/index.d.ts",
8
13
  "exports": {
@@ -25,7 +30,7 @@
25
30
  "ai"
26
31
  ],
27
32
  "dependencies": {
28
- "@ory/argus": "0.10.0"
33
+ "@ory/argus": "0.11.1"
29
34
  },
30
35
  "devDependencies": {
31
36
  "typescript": "^6.0.2",