@hiro-c/agent-gate 1.0.2 → 1.1.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
@@ -87,6 +87,7 @@ Full options: see [docs/config.md](docs/config.md) (TODO) or `AgentGatePluginCon
87
87
  | `AGENT_GATE_REASON_LANG` | AI reason language: `auto` (default) / `en` / `ja` / etc. |
88
88
  | `AGENT_GATE_LOG` | `1` writes decisions to `~/.agent-gate/log.jsonl` |
89
89
  | `AGENT_GATE_API_KEY` | Use Anthropic API directly instead of `claude` CLI |
90
+ | `AGENT_GATE_USE_SDK` | `1` prefers the Anthropic agent SDK over API/CLI (no API key needed; works best with daemon mode) |
90
91
  | `AGENT_GATE_DAEMON` | `1` routes through the daemon if it is running |
91
92
 
92
93
  ## Supported AI tools
@@ -12,6 +12,13 @@ export type ConfigOptions = {
12
12
  * - "en", "ja", "zh", "ko", etc.: write reasons in that language.
13
13
  */
14
14
  reasonLang?: string;
15
+ /**
16
+ * Prefer Anthropic's agent SDK (`@anthropic-ai/claude-agent-sdk`) as the
17
+ * first model client. Reuses the host process's Claude auth, removing
18
+ * the need for AGENT_GATE_API_KEY. The SDK has noticeable cold-start
19
+ * cost, so this is most useful when paired with `agent-gate daemon`.
20
+ */
21
+ useSdk?: boolean;
15
22
  };
16
23
  export declare class Config {
17
24
  readonly model: string;
@@ -20,6 +27,7 @@ export declare class Config {
20
27
  readonly disabled: boolean;
21
28
  readonly useSystemClaude: boolean;
22
29
  readonly reasonLang: string | undefined;
30
+ readonly useSdk: boolean;
23
31
  constructor(options?: ConfigOptions);
24
32
  get useApi(): boolean;
25
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/config/Config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,sBAAsB,CAAA;AAEhD,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,M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C1B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;gBAEZ,OAAO,CAAC,EAAE,aAAa;IAWnC,IAAI,MAAM,IAAI,OAAO,CAEpB;CACF"}
@@ -9,6 +9,7 @@ class Config {
9
9
  disabled;
10
10
  useSystemClaude;
11
11
  reasonLang;
12
+ useSdk;
12
13
  constructor(options) {
13
14
  this.model = options?.model ?? process.env.AGENT_GATE_MODEL ?? exports.DEFAULT_MODEL;
14
15
  this.apiKey = options?.apiKey ?? process.env.AGENT_GATE_API_KEY;
@@ -17,6 +18,7 @@ class Config {
17
18
  this.disabled = options?.disabled ?? process.env.AGENT_GATE_DISABLED === 'true';
18
19
  this.useSystemClaude = options?.useSystemClaude ?? process.env.USE_SYSTEM_CLAUDE === 'true';
19
20
  this.reasonLang = options?.reasonLang ?? process.env.AGENT_GATE_REASON_LANG;
21
+ this.useSdk = options?.useSdk ?? process.env.AGENT_GATE_USE_SDK === '1';
20
22
  }
21
23
  get useApi() {
22
24
  return this.apiKey !== undefined && this.apiKey !== '';
@@ -1 +1 @@
1
- {"version":3,"file":"processHookData.d.ts","sourceRoot":"","sources":["../../src/hooks/processHookData.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAIzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EACL,eAAe,EAEhB,MAAM,2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_1 = require("../validation/models/ClaudeCli");
12
12
  const AnthropicApi_1 = require("../validation/models/AnthropicApi");
13
13
  const CompositeModelClient_1 = require("../validation/models/CompositeModelClient");
14
+ const AgentSdkClient_1 = require("../validation/models/AgentSdkClient");
14
15
  const engine_1 = require("../deterministic/engine");
15
16
  const defaultRules_1 = require("../deterministic/defaultRules");
16
17
  const adapter_1 = require("../adapters/claude-code/adapter");
@@ -165,11 +166,20 @@ async function processHookData(input, deps) {
165
166
  return result;
166
167
  }
167
168
  function createModelClient(config, cwd) {
168
- // Build a fallback chain: the most-preferred client comes first, with
169
- // ClaudeCli as a secondary path. The CompositeModelClient tries each in
170
- // order; if the first fails, the next runs. The validator's outer
171
- // try/catch fail-opens when every client has failed.
169
+ // Build a fallback chain: the most-preferred client comes first.
170
+ // The CompositeModelClient tries each in order; if one fails, the next
171
+ // runs. The validator's outer try/catch fail-opens if every client has
172
+ // failed.
173
+ //
174
+ // Order: AgentSdkClient (when AGENT_GATE_USE_SDK=1) -> AnthropicApi
175
+ // (when an API key is set) -> ClaudeCli (always available as a fallback).
176
+ // AgentSdkClient is preferred when enabled because it reuses the host
177
+ // agent's existing Claude authentication, removing the need for a
178
+ // separate API key.
172
179
  const clients = [];
180
+ if (config.useSdk) {
181
+ clients.push(new AgentSdkClient_1.AgentSdkClient({ config }));
182
+ }
173
183
  if (config.useApi) {
174
184
  clients.push(new AnthropicApi_1.AnthropicApi(config));
175
185
  }
package/dist/index.d.ts CHANGED
@@ -20,6 +20,8 @@ export { cursorAdapter } from './adapters/cursor/adapter';
20
20
  export type { Adapter, ReadHistoryOptions } from './adapters/Adapter';
21
21
  export { CompositeModelClient } from './validation/models/CompositeModelClient';
22
22
  export type { CompositeModelClientOptions } from './validation/models/CompositeModelClient';
23
+ export { AgentSdkClient } from './validation/models/AgentSdkClient';
24
+ export type { AgentSdkClientOptions, AgentSdkQueryFn, } from './validation/models/AgentSdkClient';
23
25
  export { lintRuleSources } from './doctor/lintRuleSources';
24
26
  export { formatFindings } from './doctor/formatFindings';
25
27
  export type { Finding, FindingCode, Severity, } from './doctor/findings';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAClE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAG9D,YAAY,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,YAAY,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAC1D,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC9E,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAClE,YAAY,EACV,cAAc,EACd,YAAY,GACb,MAAM,kCAAkC,CAAA;AAGzC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAGnE,YAAY,EACV,iBAAiB,EACjB,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,8BAA8B,CAAA;AAGrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,YAAY,EAAE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EACV,qBAAqB,EACrB,eAAe,GAChB,MAAM,oCAAoC,CAAA;AAG3C,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,YAAY,EACV,OAAO,EACP,WAAW,EACX,QAAQ,GACT,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EACL,iBAAiB,IAAI,uBAAuB,GAC7C,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,aAAa,EACb,cAAc,EACd,mBAAmB,GACpB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,YAAY,EACV,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,IAAI,GACL,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processHookData = exports.validator = exports.collectRuleSources = exports.JsonlFileSink = exports.EventBus = exports.defaultDaemonSocketPath = exports.sendToDaemon = exports.DaemonServer = exports.formatFindings = exports.lintRuleSources = exports.CompositeModelClient = exports.cursorAdapter = exports.claudeCodeAdapter = exports.buildDefaultDeterministicRules = exports.defaultDeterministicRules = exports.forbidFilePathPattern = exports.forbidContentPattern = exports.forbidCommandPattern = exports.HookDataSchema = exports.loadPluginConfig = exports.loadAgentGateConfig = exports.defineConfig = exports.Config = void 0;
3
+ exports.processHookData = exports.validator = exports.collectRuleSources = exports.JsonlFileSink = exports.EventBus = exports.defaultDaemonSocketPath = exports.sendToDaemon = exports.DaemonServer = exports.formatFindings = exports.lintRuleSources = exports.AgentSdkClient = exports.CompositeModelClient = exports.cursorAdapter = exports.claudeCodeAdapter = exports.buildDefaultDeterministicRules = exports.defaultDeterministicRules = exports.forbidFilePathPattern = exports.forbidContentPattern = exports.forbidCommandPattern = exports.HookDataSchema = exports.loadPluginConfig = exports.loadAgentGateConfig = exports.defineConfig = exports.Config = void 0;
4
4
  // Config
5
5
  var Config_1 = require("./config/Config");
6
6
  Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return Config_1.Config; } });
@@ -28,6 +28,8 @@ Object.defineProperty(exports, "cursorAdapter", { enumerable: true, get: functio
28
28
  // Model clients (for users wiring up custom AI fallback chains)
29
29
  var CompositeModelClient_1 = require("./validation/models/CompositeModelClient");
30
30
  Object.defineProperty(exports, "CompositeModelClient", { enumerable: true, get: function () { return CompositeModelClient_1.CompositeModelClient; } });
31
+ var AgentSdkClient_1 = require("./validation/models/AgentSdkClient");
32
+ Object.defineProperty(exports, "AgentSdkClient", { enumerable: true, get: function () { return AgentSdkClient_1.AgentSdkClient; } });
31
33
  // Doctor (CLAUDE.md linter)
32
34
  var lintRuleSources_1 = require("./doctor/lintRuleSources");
33
35
  Object.defineProperty(exports, "lintRuleSources", { enumerable: true, get: function () { return lintRuleSources_1.lintRuleSources; } });
@@ -0,0 +1,40 @@
1
+ import { IModelClient } from '../../contracts/types/ModelClient';
2
+ import { Config } from '../../config/Config';
3
+ /**
4
+ * Shape of the `query` export from `@anthropic-ai/claude-agent-sdk`,
5
+ * as documented by Anthropic. The SDK returns an AsyncIterable of
6
+ * streamed messages and accepts a small set of options.
7
+ */
8
+ export type AgentSdkQueryFn = (args: {
9
+ prompt: string;
10
+ options?: {
11
+ model?: string;
12
+ allowedTools?: string[];
13
+ permissionMode?: 'default' | 'bypassPermissions' | 'dontAsk';
14
+ maxTurns?: number;
15
+ };
16
+ }) => AsyncIterable<unknown>;
17
+ export interface AgentSdkClientOptions {
18
+ config: Config;
19
+ /**
20
+ * Override the SDK loader. Production builds default to a dynamic
21
+ * import of `@anthropic-ai/claude-agent-sdk`; tests inject a fake.
22
+ */
23
+ loadQuery?: () => Promise<AgentSdkQueryFn>;
24
+ }
25
+ /**
26
+ * IModelClient that runs validation through Anthropic's agent SDK
27
+ * (`@anthropic-ai/claude-agent-sdk`). Reuses the host process's
28
+ * existing Claude authentication so no separate API key is required.
29
+ *
30
+ * Tradeoff: the SDK has noticeable cold-start cost on each call.
31
+ * Recommended paired with `agent-gate daemon` so the SDK initialization
32
+ * is amortized across hook invocations.
33
+ */
34
+ export declare class AgentSdkClient implements IModelClient {
35
+ private readonly config;
36
+ private readonly loadQuery;
37
+ constructor(opts: AgentSdkClientOptions);
38
+ ask(prompt: string): Promise<string>;
39
+ }
40
+ //# sourceMappingURL=AgentSdkClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentSdkClient.d.ts","sourceRoot":"","sources":["../../../src/validation/models/AgentSdkClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAG5C;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;QACvB,cAAc,CAAC,EAAE,SAAS,GAAG,mBAAmB,GAAG,SAAS,CAAA;QAC5D,QAAQ,CAAC,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,KAAK,aAAa,CAAC,OAAO,CAAC,CAAA;AAE5B,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAA;CAC3C;AAED;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgC;gBAE9C,IAAI,EAAE,qBAAqB;IAKjC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAgC3C"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentSdkClient = void 0;
4
+ const system_prompt_1 = require("../prompts/system-prompt");
5
+ /**
6
+ * IModelClient that runs validation through Anthropic's agent SDK
7
+ * (`@anthropic-ai/claude-agent-sdk`). Reuses the host process's
8
+ * existing Claude authentication so no separate API key is required.
9
+ *
10
+ * Tradeoff: the SDK has noticeable cold-start cost on each call.
11
+ * Recommended paired with `agent-gate daemon` so the SDK initialization
12
+ * is amortized across hook invocations.
13
+ */
14
+ class AgentSdkClient {
15
+ config;
16
+ loadQuery;
17
+ constructor(opts) {
18
+ this.config = opts.config;
19
+ this.loadQuery = opts.loadQuery ?? defaultLoadQuery;
20
+ }
21
+ async ask(prompt) {
22
+ let query;
23
+ try {
24
+ query = await this.loadQuery();
25
+ }
26
+ catch (e) {
27
+ const msg = e instanceof Error ? e.message : String(e);
28
+ throw new Error(`Agent SDK loader failed; install @anthropic-ai/claude-agent-sdk or fall back to another client. Underlying: ${msg}`);
29
+ }
30
+ const fullPrompt = `${(0, system_prompt_1.getSystemPrompt)(this.config.reasonLang)}\n\n${prompt}`;
31
+ let lastText = '';
32
+ for await (const message of query({
33
+ prompt: fullPrompt,
34
+ options: {
35
+ model: this.config.model,
36
+ allowedTools: [],
37
+ permissionMode: 'bypassPermissions',
38
+ maxTurns: 1,
39
+ },
40
+ })) {
41
+ const t = extractText(message);
42
+ if (t)
43
+ lastText = t;
44
+ }
45
+ if (!lastText) {
46
+ throw new Error('No response from agent SDK stream');
47
+ }
48
+ return lastText;
49
+ }
50
+ }
51
+ exports.AgentSdkClient = AgentSdkClient;
52
+ async function defaultLoadQuery() {
53
+ const mod = (await import('@anthropic-ai/claude-agent-sdk'));
54
+ if (typeof mod.query !== 'function') {
55
+ throw new Error('@anthropic-ai/claude-agent-sdk did not export query()');
56
+ }
57
+ return mod.query;
58
+ }
59
+ /**
60
+ * Pulls assistant text out of one streamed message. The SDK emits a
61
+ * mix of system / assistant / result envelopes; we cover the common
62
+ * shapes and ignore the rest.
63
+ */
64
+ function extractText(message) {
65
+ if (typeof message !== 'object' || message === null)
66
+ return null;
67
+ const m = message;
68
+ if (typeof m.result === 'string' && m.result.length > 0)
69
+ return m.result;
70
+ const inner = m.message;
71
+ if (typeof inner === 'object' && inner !== null) {
72
+ const content = inner.content;
73
+ if (Array.isArray(content)) {
74
+ const text = content
75
+ .map((c) => {
76
+ if (typeof c === 'object' && c !== null) {
77
+ const block = c;
78
+ if (typeof block.text === 'string')
79
+ return block.text;
80
+ }
81
+ return null;
82
+ })
83
+ .filter((s) => Boolean(s))
84
+ .join('\n');
85
+ if (text.length > 0)
86
+ return text;
87
+ }
88
+ }
89
+ if (typeof m.text === 'string' && m.text.length > 0)
90
+ return m.text;
91
+ return null;
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiro-c/agent-gate",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Runtime rule enforcer for AI coding agents. Reads CLAUDE.md / AGENTS.md / .cursorrules and enforces them via Claude Code and Cursor hooks, with a deterministic safety baseline.",
5
5
  "author": "Hiro-Chiba",
6
6
  "license": "MIT",
@@ -55,7 +55,7 @@
55
55
  "prepublishOnly": "npm run checks && npm run build"
56
56
  },
57
57
  "dependencies": {
58
- "@anthropic-ai/sdk": "^0.90.0",
58
+ "@anthropic-ai/sdk": "^0.93.0",
59
59
  "jiti": "^2.7.0",
60
60
  "zod": "^4.3.6"
61
61
  },
@@ -63,5 +63,8 @@
63
63
  "@types/node": "^25.6.0",
64
64
  "typescript": "^6.0.3",
65
65
  "vitest": "^4.1.4"
66
+ },
67
+ "optionalDependencies": {
68
+ "@anthropic-ai/claude-agent-sdk": "^0.3.0"
66
69
  }
67
70
  }