airlock-bot 0.2.37 → 0.3.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 (305) hide show
  1. package/README.md +47 -47
  2. package/dist/activity/stream.d.ts +29 -0
  3. package/dist/activity/stream.d.ts.map +1 -0
  4. package/dist/activity/stream.js +36 -0
  5. package/dist/activity/stream.js.map +1 -0
  6. package/dist/airlock/context.d.ts +12 -0
  7. package/dist/airlock/context.d.ts.map +1 -0
  8. package/dist/airlock/context.js +32 -0
  9. package/dist/airlock/context.js.map +1 -0
  10. package/dist/airlock/tools.d.ts +11 -0
  11. package/dist/airlock/tools.d.ts.map +1 -0
  12. package/dist/airlock/tools.js +25 -0
  13. package/dist/airlock/tools.js.map +1 -0
  14. package/dist/allowlist/engine.d.ts +12 -0
  15. package/dist/allowlist/engine.d.ts.map +1 -1
  16. package/dist/allowlist/engine.js +40 -15
  17. package/dist/allowlist/engine.js.map +1 -1
  18. package/dist/audit/api.d.ts +2 -0
  19. package/dist/audit/api.d.ts.map +1 -1
  20. package/dist/audit/api.js.map +1 -1
  21. package/dist/audit/db.d.ts +23 -0
  22. package/dist/audit/db.d.ts.map +1 -1
  23. package/dist/audit/db.js +92 -3
  24. package/dist/audit/db.js.map +1 -1
  25. package/dist/audit/logger.d.ts +8 -1
  26. package/dist/audit/logger.d.ts.map +1 -1
  27. package/dist/audit/logger.js +21 -0
  28. package/dist/audit/logger.js.map +1 -1
  29. package/dist/backend/airlock-adapter.d.ts +32 -0
  30. package/dist/backend/airlock-adapter.d.ts.map +1 -0
  31. package/dist/backend/airlock-adapter.js +318 -0
  32. package/dist/backend/airlock-adapter.js.map +1 -0
  33. package/dist/backend/cli/builder.d.ts.map +1 -1
  34. package/dist/backend/cli/builder.js +10 -3
  35. package/dist/backend/cli/builder.js.map +1 -1
  36. package/dist/backend/factory.d.ts +5 -1
  37. package/dist/backend/factory.d.ts.map +1 -1
  38. package/dist/backend/factory.js +5 -5
  39. package/dist/backend/factory.js.map +1 -1
  40. package/dist/backend/mcp-adapter.d.ts +1 -0
  41. package/dist/backend/mcp-adapter.d.ts.map +1 -1
  42. package/dist/backend/mcp-adapter.js +33 -4
  43. package/dist/backend/mcp-adapter.js.map +1 -1
  44. package/dist/backend/openapi/adapter.d.ts.map +1 -1
  45. package/dist/backend/openapi/adapter.js +66 -31
  46. package/dist/backend/openapi/adapter.js.map +1 -1
  47. package/dist/backend/types.d.ts +8 -0
  48. package/dist/backend/types.d.ts.map +1 -1
  49. package/dist/config/loader.d.ts +12 -1
  50. package/dist/config/loader.d.ts.map +1 -1
  51. package/dist/config/loader.js +591 -23
  52. package/dist/config/loader.js.map +1 -1
  53. package/dist/config/profiles.d.ts +46 -3
  54. package/dist/config/profiles.d.ts.map +1 -1
  55. package/dist/config/profiles.js +377 -3
  56. package/dist/config/profiles.js.map +1 -1
  57. package/dist/config/schema.d.ts +6426 -803
  58. package/dist/config/schema.d.ts.map +1 -1
  59. package/dist/config/schema.js +499 -73
  60. package/dist/config/schema.js.map +1 -1
  61. package/dist/configure-cli/cli.d.ts.map +1 -1
  62. package/dist/configure-cli/cli.js +1 -2
  63. package/dist/configure-cli/cli.js.map +1 -1
  64. package/dist/configure-web/cli.d.ts +1 -0
  65. package/dist/configure-web/cli.d.ts.map +1 -1
  66. package/dist/configure-web/cli.js +261 -48
  67. package/dist/configure-web/cli.js.map +1 -1
  68. package/dist/discover/strategies/completion.d.ts.map +1 -1
  69. package/dist/discover/strategies/completion.js +3 -3
  70. package/dist/discover/strategies/completion.js.map +1 -1
  71. package/dist/gateway.d.ts +21 -1
  72. package/dist/gateway.d.ts.map +1 -1
  73. package/dist/gateway.js +345 -60
  74. package/dist/gateway.js.map +1 -1
  75. package/dist/hitl/api.d.ts +2 -0
  76. package/dist/hitl/api.d.ts.map +1 -1
  77. package/dist/hitl/api.js +8 -0
  78. package/dist/hitl/api.js.map +1 -1
  79. package/dist/hitl/approval-dashboard.d.ts +5 -9
  80. package/dist/hitl/approval-dashboard.d.ts.map +1 -1
  81. package/dist/hitl/approval-dashboard.js +8 -55
  82. package/dist/hitl/approval-dashboard.js.map +1 -1
  83. package/dist/hitl/approval-stream.d.ts +34 -0
  84. package/dist/hitl/approval-stream.d.ts.map +1 -0
  85. package/dist/hitl/approval-stream.js +111 -0
  86. package/dist/hitl/approval-stream.js.map +1 -0
  87. package/dist/hitl/batcher.d.ts +2 -0
  88. package/dist/hitl/batcher.d.ts.map +1 -1
  89. package/dist/hitl/batcher.js +16 -0
  90. package/dist/hitl/batcher.js.map +1 -1
  91. package/dist/hitl/engine.d.ts +16 -7
  92. package/dist/hitl/engine.d.ts.map +1 -1
  93. package/dist/hitl/engine.js +109 -35
  94. package/dist/hitl/engine.js.map +1 -1
  95. package/dist/hitl/formatter.d.ts.map +1 -1
  96. package/dist/hitl/formatter.js +2 -0
  97. package/dist/hitl/formatter.js.map +1 -1
  98. package/dist/hitl/provider-factory.d.ts +8 -2
  99. package/dist/hitl/provider-factory.d.ts.map +1 -1
  100. package/dist/hitl/provider-factory.js +23 -2
  101. package/dist/hitl/provider-factory.js.map +1 -1
  102. package/dist/hitl/providers/composite.d.ts +9 -0
  103. package/dist/hitl/providers/composite.d.ts.map +1 -1
  104. package/dist/hitl/providers/composite.js +14 -0
  105. package/dist/hitl/providers/composite.js.map +1 -1
  106. package/dist/hitl/providers/dashboard.d.ts +12 -2
  107. package/dist/hitl/providers/dashboard.d.ts.map +1 -1
  108. package/dist/hitl/providers/dashboard.js +11 -5
  109. package/dist/hitl/providers/dashboard.js.map +1 -1
  110. package/dist/hitl/providers/ios.d.ts +23 -0
  111. package/dist/hitl/providers/ios.d.ts.map +1 -0
  112. package/dist/hitl/providers/ios.js +183 -0
  113. package/dist/hitl/providers/ios.js.map +1 -0
  114. package/dist/hitl/providers/macos.d.ts.map +1 -1
  115. package/dist/hitl/providers/macos.js +8 -4
  116. package/dist/hitl/providers/macos.js.map +1 -1
  117. package/dist/hitl/providers/openclaw.js +2 -2
  118. package/dist/hitl/providers/openclaw.js.map +1 -1
  119. package/dist/hitl/providers/stdio.js +2 -2
  120. package/dist/hitl/providers/stdio.js.map +1 -1
  121. package/dist/hitl/providers/telegram.js +2 -2
  122. package/dist/hitl/providers/telegram.js.map +1 -1
  123. package/dist/hitl/providers/tui.d.ts.map +1 -1
  124. package/dist/hitl/providers/tui.js +8 -2
  125. package/dist/hitl/providers/tui.js.map +1 -1
  126. package/dist/hitl/providers/types.d.ts +14 -0
  127. package/dist/hitl/providers/types.d.ts.map +1 -1
  128. package/dist/hook/api.d.ts +2 -0
  129. package/dist/hook/api.d.ts.map +1 -1
  130. package/dist/hook/api.js.map +1 -1
  131. package/dist/hook/normalizer.js +2 -2
  132. package/dist/hook/normalizer.js.map +1 -1
  133. package/dist/index.js +28 -1
  134. package/dist/index.js.map +1 -1
  135. package/dist/introspect/cli.d.ts +55 -0
  136. package/dist/introspect/cli.d.ts.map +1 -0
  137. package/dist/introspect/cli.js +850 -0
  138. package/dist/introspect/cli.js.map +1 -0
  139. package/dist/middleware/chain-builder.d.ts +1 -1
  140. package/dist/middleware/chain-builder.d.ts.map +1 -1
  141. package/dist/middleware/chain-builder.js +8 -4
  142. package/dist/middleware/chain-builder.js.map +1 -1
  143. package/dist/middleware/core/allowlist.d.ts.map +1 -1
  144. package/dist/middleware/core/allowlist.js +15 -0
  145. package/dist/middleware/core/allowlist.js.map +1 -1
  146. package/dist/middleware/core/arg-policy.d.ts +2 -1
  147. package/dist/middleware/core/arg-policy.d.ts.map +1 -1
  148. package/dist/middleware/core/arg-policy.js +158 -46
  149. package/dist/middleware/core/arg-policy.js.map +1 -1
  150. package/dist/middleware/core/command-policy.d.ts +13 -0
  151. package/dist/middleware/core/command-policy.d.ts.map +1 -0
  152. package/dist/middleware/core/command-policy.js +94 -0
  153. package/dist/middleware/core/command-policy.js.map +1 -0
  154. package/dist/middleware/core/exec-policy.d.ts.map +1 -1
  155. package/dist/middleware/core/exec-policy.js +17 -1
  156. package/dist/middleware/core/exec-policy.js.map +1 -1
  157. package/dist/middleware/core/execute.d.ts +2 -0
  158. package/dist/middleware/core/execute.d.ts.map +1 -1
  159. package/dist/middleware/core/execute.js +79 -3
  160. package/dist/middleware/core/execute.js.map +1 -1
  161. package/dist/middleware/core/hitl-gate.d.ts.map +1 -1
  162. package/dist/middleware/core/hitl-gate.js +22 -4
  163. package/dist/middleware/core/hitl-gate.js.map +1 -1
  164. package/dist/middleware/core/schema-validator.d.ts.map +1 -1
  165. package/dist/middleware/core/schema-validator.js +7 -3
  166. package/dist/middleware/core/schema-validator.js.map +1 -1
  167. package/dist/middleware/detectors/injection-detector.d.ts.map +1 -1
  168. package/dist/middleware/detectors/injection-detector.js +2 -0
  169. package/dist/middleware/detectors/injection-detector.js.map +1 -1
  170. package/dist/middleware/detectors/sensitivity-classifier.js +1 -0
  171. package/dist/middleware/detectors/sensitivity-classifier.js.map +1 -1
  172. package/dist/middleware/post/canary-token-injector.d.ts +4 -1
  173. package/dist/middleware/post/canary-token-injector.d.ts.map +1 -1
  174. package/dist/middleware/post/canary-token-injector.js +6 -1
  175. package/dist/middleware/post/canary-token-injector.js.map +1 -1
  176. package/dist/middleware/post/output-injection-detector.d.ts.map +1 -1
  177. package/dist/middleware/post/output-injection-detector.js +1 -0
  178. package/dist/middleware/post/output-injection-detector.js.map +1 -1
  179. package/dist/middleware/post/untrusted-envelope.d.ts.map +1 -1
  180. package/dist/middleware/post/untrusted-envelope.js +14 -1
  181. package/dist/middleware/post/untrusted-envelope.js.map +1 -1
  182. package/dist/mobile/api.d.ts +20 -0
  183. package/dist/mobile/api.d.ts.map +1 -0
  184. package/dist/mobile/api.js +259 -0
  185. package/dist/mobile/api.js.map +1 -0
  186. package/dist/mobile/apns.d.ts +68 -0
  187. package/dist/mobile/apns.d.ts.map +1 -0
  188. package/dist/mobile/apns.js +322 -0
  189. package/dist/mobile/apns.js.map +1 -0
  190. package/dist/pool/client-credentials.d.ts +46 -0
  191. package/dist/pool/client-credentials.d.ts.map +1 -0
  192. package/dist/pool/client-credentials.js +204 -0
  193. package/dist/pool/client-credentials.js.map +1 -0
  194. package/dist/pool/credential-health.d.ts +54 -0
  195. package/dist/pool/credential-health.d.ts.map +1 -0
  196. package/dist/pool/credential-health.js +262 -0
  197. package/dist/pool/credential-health.js.map +1 -0
  198. package/dist/pool/http-client.d.ts +52 -2
  199. package/dist/pool/http-client.d.ts.map +1 -1
  200. package/dist/pool/http-client.js +302 -17
  201. package/dist/pool/http-client.js.map +1 -1
  202. package/dist/pool/oauth-provider.d.ts +23 -0
  203. package/dist/pool/oauth-provider.d.ts.map +1 -1
  204. package/dist/pool/oauth-provider.js +134 -6
  205. package/dist/pool/oauth-provider.js.map +1 -1
  206. package/dist/pool/oauth-timing.d.ts +3 -0
  207. package/dist/pool/oauth-timing.d.ts.map +1 -0
  208. package/dist/pool/oauth-timing.js +8 -0
  209. package/dist/pool/oauth-timing.js.map +1 -0
  210. package/dist/pool/pool.d.ts +8 -1
  211. package/dist/pool/pool.d.ts.map +1 -1
  212. package/dist/pool/pool.js +17 -4
  213. package/dist/pool/pool.js.map +1 -1
  214. package/dist/pool/sse-client.d.ts +10 -1
  215. package/dist/pool/sse-client.d.ts.map +1 -1
  216. package/dist/pool/sse-client.js +46 -5
  217. package/dist/pool/sse-client.js.map +1 -1
  218. package/dist/pool/status.d.ts +6 -0
  219. package/dist/pool/status.d.ts.map +1 -0
  220. package/dist/pool/status.js +2 -0
  221. package/dist/pool/status.js.map +1 -0
  222. package/dist/pool/stdio-client.d.ts +11 -1
  223. package/dist/pool/stdio-client.d.ts.map +1 -1
  224. package/dist/pool/stdio-client.js +39 -3
  225. package/dist/pool/stdio-client.js.map +1 -1
  226. package/dist/registry/airlock-policy.d.ts +3 -0
  227. package/dist/registry/airlock-policy.d.ts.map +1 -0
  228. package/dist/registry/airlock-policy.js +50 -0
  229. package/dist/registry/airlock-policy.js.map +1 -0
  230. package/dist/registry/registry.d.ts +49 -4
  231. package/dist/registry/registry.d.ts.map +1 -1
  232. package/dist/registry/registry.js +160 -19
  233. package/dist/registry/registry.js.map +1 -1
  234. package/dist/registry/sanitizer.d.ts +16 -1
  235. package/dist/registry/sanitizer.d.ts.map +1 -1
  236. package/dist/registry/sanitizer.js +70 -11
  237. package/dist/registry/sanitizer.js.map +1 -1
  238. package/dist/security/blocked-hosts.d.ts +2 -0
  239. package/dist/security/blocked-hosts.d.ts.map +1 -1
  240. package/dist/security/blocked-hosts.js +61 -7
  241. package/dist/security/blocked-hosts.js.map +1 -1
  242. package/dist/security/request.d.ts +2 -0
  243. package/dist/security/request.d.ts.map +1 -1
  244. package/dist/security/request.js +6 -2
  245. package/dist/security/request.js.map +1 -1
  246. package/dist/security/secrets.d.ts +12 -0
  247. package/dist/security/secrets.d.ts.map +1 -0
  248. package/dist/security/secrets.js +138 -0
  249. package/dist/security/secrets.js.map +1 -0
  250. package/dist/setup-openclaw/cli.js +1 -1
  251. package/dist/stdio-mode.d.ts.map +1 -1
  252. package/dist/stdio-mode.js +159 -28
  253. package/dist/stdio-mode.js.map +1 -1
  254. package/dist/tools/api.d.ts +5 -1
  255. package/dist/tools/api.d.ts.map +1 -1
  256. package/dist/tools/api.js +67 -8
  257. package/dist/tools/api.js.map +1 -1
  258. package/dist/tools/exec.d.ts +2 -1
  259. package/dist/tools/exec.d.ts.map +1 -1
  260. package/dist/tools/exec.js +4 -3
  261. package/dist/tools/exec.js.map +1 -1
  262. package/dist/tools/http.d.ts.map +1 -1
  263. package/dist/tools/http.js +4 -7
  264. package/dist/tools/http.js.map +1 -1
  265. package/dist/transport/agent-server.d.ts +4 -0
  266. package/dist/transport/agent-server.d.ts.map +1 -1
  267. package/dist/transport/agent-server.js +47 -12
  268. package/dist/transport/agent-server.js.map +1 -1
  269. package/dist/transport/http-server.d.ts +4 -0
  270. package/dist/transport/http-server.d.ts.map +1 -1
  271. package/dist/transport/http-server.js +69 -9
  272. package/dist/transport/http-server.js.map +1 -1
  273. package/dist/transport/keepalive.d.ts +27 -0
  274. package/dist/transport/keepalive.d.ts.map +1 -0
  275. package/dist/transport/keepalive.js +30 -0
  276. package/dist/transport/keepalive.js.map +1 -0
  277. package/dist/transport/session-limiter.d.ts +84 -0
  278. package/dist/transport/session-limiter.d.ts.map +1 -0
  279. package/dist/transport/session-limiter.js +189 -0
  280. package/dist/transport/session-limiter.js.map +1 -0
  281. package/dist/transport/sse-server.d.ts +4 -0
  282. package/dist/transport/sse-server.d.ts.map +1 -1
  283. package/dist/transport/sse-server.js +27 -9
  284. package/dist/transport/sse-server.js.map +1 -1
  285. package/dist/transport/stdio-server.d.ts.map +1 -1
  286. package/dist/transport/stdio-server.js +4 -0
  287. package/dist/transport/stdio-server.js.map +1 -1
  288. package/dist/util/atomic-file.d.ts +9 -0
  289. package/dist/util/atomic-file.d.ts.map +1 -0
  290. package/dist/util/atomic-file.js +39 -0
  291. package/dist/util/atomic-file.js.map +1 -0
  292. package/dist/util/id.d.ts +1 -1
  293. package/dist/util/id.d.ts.map +1 -1
  294. package/dist/util/id.js +3 -3
  295. package/dist/util/id.js.map +1 -1
  296. package/examples/airlock.yaml +55 -0
  297. package/examples/claude-code-setup.md +0 -2
  298. package/examples/docker-compose.yaml +4 -3
  299. package/examples/docker-gateway.yaml +8 -3
  300. package/examples/gateway.yaml +8 -5
  301. package/examples/profiles.yaml +0 -2
  302. package/extensions/openclaw/index.ts +9 -6
  303. package/extensions/openclaw/openclaw.plugin.json +5 -5
  304. package/package.json +5 -3
  305. package/schema.json +1194 -19
@@ -1,7 +1,20 @@
1
1
  import { homedir } from 'os';
2
2
  import { z } from 'zod';
3
3
  // Env var substitution helper
4
+ let resolveEnvVars = true;
5
+ export function withEnvVarResolution(resolve, fn) {
6
+ const previous = resolveEnvVars;
7
+ resolveEnvVars = resolve;
8
+ try {
9
+ return fn();
10
+ }
11
+ finally {
12
+ resolveEnvVars = previous;
13
+ }
14
+ }
4
15
  function substituteEnvVars(value) {
16
+ if (!resolveEnvVars)
17
+ return value;
5
18
  return value.replace(/\$\{([^}]+)\}/g, (_, varName) => {
6
19
  const val = process.env[varName];
7
20
  if (val === undefined) {
@@ -19,21 +32,108 @@ function expandTilde(value) {
19
32
  }
20
33
  const EnvString = z.string().transform(substituteEnvVars);
21
34
  const PathString = z.string().transform(expandTilde);
35
+ /**
36
+ * Operator-authored orientation text for a provider, surfaced to agents via the gateway's own
37
+ * server-level `instructions` (MCP `initialize`). Use it for the things a vendor's own docs can't
38
+ * know — house conventions, which IDs to use, which discovery calls lie.
39
+ *
40
+ * `instructions` is trusted (it comes from this config file, not the network) so it is never
41
+ * scrubbed or truncated. `upstream_instructions` controls whether the provider's OWN advertised
42
+ * instructions are included alongside it; set `ignore` to replace them outright.
43
+ */
44
+ const ProviderInstructionsFields = {
45
+ instructions: z.string().optional(),
46
+ // `.optional()` rather than `.default('include')` so the parsed shape of a provider that never
47
+ // mentions instructions is byte-identical to what it was before this feature existed. Absent
48
+ // means include; getProviderInstructions() applies the fallback.
49
+ upstream_instructions: z.enum(['include', 'ignore']).optional(),
50
+ };
51
+ /**
52
+ * A cheap, read-only call used to prove the provider's CREDENTIAL still works — as opposed to
53
+ * `mcpHealth`, which only proves the transport is reachable. The distinction is not academic: a
54
+ * Google Workspace sidecar answers MCP happily for weeks after its refresh token dies, so the
55
+ * gateway reported `ok` the entire time nobody could read mail.
56
+ *
57
+ * Pick the cheapest read the provider offers, and scope it tightly — this runs unattended.
58
+ *
59
+ * Classification: a thrown error or an `isError` result is a failure, and the failure text decides
60
+ * `auth_required` vs `error`. Providers that report expired credentials as a SUCCESSFUL text
61
+ * response (the Google sidecar's "ACTION REQUIRED: authorize…" is one) can't be caught that way,
62
+ * which is what `expect_contains` / `reject_contains` are for. Prefer `expect_contains` and anchor
63
+ * it on the shape of a healthy response: `reject_contains` matches the whole payload, so a probe
64
+ * that returns user data can trip on the phrase appearing in that data (an email subject line
65
+ * reading "Action Required" would do it).
66
+ */
67
+ export const CredentialProbeConfig = z
68
+ .object({
69
+ /** Provider-local tool name — unprefixed, e.g. `search_gmail_messages`. */
70
+ tool: z.string(),
71
+ args: z.record(z.unknown()).default({}),
72
+ /** Healthy responses must contain this substring; otherwise the credential is auth_required. */
73
+ expect_contains: z.string().optional(),
74
+ /** Healthy responses must NOT contain this substring. See the caveat above. */
75
+ reject_contains: z.string().optional(),
76
+ /** Cache TTL. Floored at a minute so a hot /health poll can't hammer a provider's API quota. */
77
+ interval_ms: z.number().int().min(60_000).default(900_000),
78
+ timeout_ms: z.number().int().min(1_000).default(15_000),
79
+ })
80
+ .strict();
81
+ const CredentialProbeFields = {
82
+ credential_probe: CredentialProbeConfig.optional(),
83
+ };
84
+ /**
85
+ * OAuth2 client-credentials grant — the gateway authenticates as the APPLICATION, with no user in
86
+ * the loop and no browser flow. Use it for provider-side bot/service identities: actions land as
87
+ * the app rather than as whoever last authorized it, which is what makes an autonomous agent's
88
+ * writes attributable.
89
+ *
90
+ * Distinct from `oauth: true`, which is the authorization-code flow and carries a USER's identity.
91
+ * The two are mutually exclusive (see the loader diagnostic) — a provider has one identity.
92
+ *
93
+ * Tokens are minted on demand, cached to disk, and re-minted proactively before expiry or reactively
94
+ * on a 401. Disk caching is load-bearing rather than an optimization: issuers cap how many tokens an
95
+ * app may hold at once (Linear allows 1000), so a gateway that minted on every restart would burn
96
+ * through that quota.
97
+ */
98
+ export const ClientCredentialsConfig = z
99
+ .object({
100
+ /** The issuer's token endpoint, e.g. `https://api.linear.app/oauth/token`. */
101
+ token_url: z.string().url(),
102
+ client_id: EnvString,
103
+ client_secret: EnvString,
104
+ /**
105
+ * Scopes to request, verbatim — the separator is the issuer's to define (Linear uses commas,
106
+ * the OAuth2 spec says spaces), so the string is passed through untouched. Omit to accept the
107
+ * issuer's default scopes. NOTE: some issuers revoke every live token when an app's scopes
108
+ * change, so treat this as a value that is changed deliberately, not tuned.
109
+ */
110
+ scope: z.string().optional(),
111
+ })
112
+ .strict();
22
113
  export const McpServerConfig = z.discriminatedUnion('type', [
23
- z.object({
114
+ z
115
+ .object({
24
116
  type: z.literal('stdio'),
25
117
  enabled: z.boolean().default(true),
26
118
  command: z.string(),
27
119
  args: z.array(z.string()).default([]),
28
120
  env: z.record(EnvString).optional(),
29
- }),
30
- z.object({
121
+ ...ProviderInstructionsFields,
122
+ ...CredentialProbeFields,
123
+ })
124
+ .strict(),
125
+ z
126
+ .object({
31
127
  type: z.literal('sse'),
32
128
  enabled: z.boolean().default(true),
33
129
  url: z.string().url(),
34
130
  headers: z.record(EnvString).optional(),
35
- }),
36
- z.object({
131
+ ...ProviderInstructionsFields,
132
+ ...CredentialProbeFields,
133
+ })
134
+ .strict(),
135
+ z
136
+ .object({
37
137
  type: z.literal('http'),
38
138
  enabled: z.boolean().default(true),
39
139
  url: z.string().url(),
@@ -43,12 +143,25 @@ export const McpServerConfig = z.discriminatedUnion('type', [
43
143
  oauth_callback_url: z.string().url().optional(),
44
144
  client_id: EnvString.optional(),
45
145
  client_secret: EnvString.optional(),
46
- }),
146
+ client_credentials: ClientCredentialsConfig.optional(),
147
+ /**
148
+ * Per-request MCP SDK deadline. The SDK otherwise imposes an invisible 60s default even when
149
+ * Airlock's outer call_execution_timeout_ms is higher, so slow but healthy providers can
150
+ * never use the operator-configured execution budget.
151
+ */
152
+ request_timeout_ms: z.number().int().positive().default(60_000),
153
+ ...ProviderInstructionsFields,
154
+ ...CredentialProbeFields,
155
+ })
156
+ .strict(),
47
157
  ]);
48
- export const BuiltinProviderConfig = z.object({
158
+ export const BuiltinProviderConfig = z
159
+ .object({
49
160
  type: z.literal('builtin'),
50
161
  enabled: z.boolean().default(true),
51
- });
162
+ ...ProviderInstructionsFields,
163
+ })
164
+ .strict();
52
165
  export const ProviderConfig = z.union([
53
166
  z.literal('builtin'),
54
167
  BuiltinProviderConfig,
@@ -64,6 +177,35 @@ export function getMcpConfigs(providers) {
64
177
  }
65
178
  return result;
66
179
  }
180
+ /**
181
+ * Credential probes for the providers that declare one, keyed by provider id. Providers without a
182
+ * probe are simply absent — the monitor still reports on them, using the transport's own OAuth
183
+ * state, and says `unknown` rather than guessing.
184
+ */
185
+ export function getCredentialProbes(providers) {
186
+ const result = {};
187
+ for (const [id, cfg] of Object.entries(getMcpConfigs(providers))) {
188
+ if (cfg.credential_probe)
189
+ result[id] = cfg.credential_probe;
190
+ }
191
+ return result;
192
+ }
193
+ /**
194
+ * Per-provider instruction settings, keyed by provider id. Providers declared as the bare string
195
+ * `'builtin'` carry no settings and fall back to the defaults.
196
+ */
197
+ export function getProviderInstructions(providers) {
198
+ const result = {};
199
+ for (const [id, cfg] of Object.entries(providers)) {
200
+ if (cfg === 'builtin')
201
+ continue;
202
+ result[id] = {
203
+ ...(cfg.instructions !== undefined && { instructions: cfg.instructions }),
204
+ upstream: cfg.upstream_instructions ?? 'include',
205
+ };
206
+ }
207
+ return result;
208
+ }
67
209
  /** Extract the set of builtin provider names (e.g. "exec", "http") */
68
210
  export function getBuiltinProviders(providers) {
69
211
  const result = new Set();
@@ -74,78 +216,190 @@ export function getBuiltinProviders(providers) {
74
216
  }
75
217
  return result;
76
218
  }
77
- export const SandboxFilesystemConfig = z.object({
219
+ export const SandboxFilesystemConfig = z
220
+ .object({
78
221
  allow_write: z.array(z.string()).default(['.', '/tmp']),
79
222
  deny_read: z.array(z.string()).default([]),
80
223
  deny_write: z.array(z.string()).default([]),
81
224
  allow_read: z.array(z.string()).optional(),
82
- });
83
- export const SandboxNetworkConfig = z.object({
225
+ })
226
+ .strict();
227
+ export const SandboxNetworkConfig = z
228
+ .object({
84
229
  allowed_domains: z.array(z.string()).default([]),
85
230
  denied_domains: z.array(z.string()).default([]),
86
- });
87
- export const SandboxOverrideConfig = z.object({
231
+ })
232
+ .strict();
233
+ export const SandboxOverrideConfig = z
234
+ .object({
88
235
  filesystem: SandboxFilesystemConfig.optional(),
89
236
  network: SandboxNetworkConfig.optional(),
90
- });
237
+ })
238
+ .strict();
91
239
  export const SandboxPresetRef = z
92
240
  .union([z.string(), z.array(z.string())])
93
241
  .transform((value) => (Array.isArray(value) ? value : [value]));
94
- export const SandboxConfig = z.object({
242
+ export const SandboxConfig = z
243
+ .object({
95
244
  enabled: z.boolean().default(false),
96
245
  presets: SandboxPresetRef.default([]),
97
246
  filesystem: SandboxFilesystemConfig.default({}),
98
247
  network: SandboxNetworkConfig.default({}),
99
248
  overrides: z.record(SandboxOverrideConfig).default({}),
100
- });
249
+ })
250
+ .strict();
251
+ export const ValueSetConfig = z
252
+ .union([
253
+ z.array(z.unknown()).nonempty(),
254
+ z
255
+ .object({
256
+ values: z.array(z.unknown()).nonempty(),
257
+ expose_values: z.boolean().default(true),
258
+ })
259
+ .strict(),
260
+ ])
261
+ .transform((value) => (Array.isArray(value) ? { values: value, expose_values: true } : value));
262
+ const NormalizerName = z.enum(['phone', 'email', 'lower', 'trim']);
101
263
  export const ToolArgConstraintConfig = z
102
264
  .object({
103
265
  allow: z.array(z.unknown()).optional(),
104
266
  equals: z.unknown().optional(),
267
+ in: z.string().optional(),
268
+ glob_in: z.string().optional(),
269
+ each_in: z.string().optional(),
270
+ glob_allow: z.array(z.string()).optional(),
271
+ each_allow: z.array(z.unknown()).optional(),
272
+ normalize: z.array(NormalizerName).optional(),
273
+ path: z.string().optional(),
274
+ required: z.boolean().optional(),
105
275
  label: z.string().optional(),
276
+ value_set: z.string().optional(),
277
+ expose_values: z.boolean().optional(),
106
278
  })
107
279
  .strict()
108
280
  .superRefine((value, ctx) => {
109
- const hasEquals = Object.prototype.hasOwnProperty.call(value, 'equals');
110
- const hasAllow = Object.prototype.hasOwnProperty.call(value, 'allow');
111
- if (!hasEquals && !hasAllow) {
281
+ const matcherKeys = [
282
+ 'equals',
283
+ 'allow',
284
+ 'in',
285
+ 'glob_in',
286
+ 'each_in',
287
+ 'glob_allow',
288
+ 'each_allow',
289
+ ];
290
+ const presentMatchers = matcherKeys.filter((key) => Object.prototype.hasOwnProperty.call(value, key));
291
+ if (presentMatchers.length === 0) {
292
+ ctx.addIssue({
293
+ code: z.ZodIssueCode.custom,
294
+ message: 'Argument policy constraint must define exactly one matcher.',
295
+ });
296
+ }
297
+ if (presentMatchers.length > 1) {
112
298
  ctx.addIssue({
113
299
  code: z.ZodIssueCode.custom,
114
- message: 'Argument policy constraint must define equals or allow.',
300
+ message: 'Argument policy constraint must define exactly one matcher.',
115
301
  });
116
302
  }
117
- if (hasAllow && value.allow?.length === 0) {
303
+ if (Object.prototype.hasOwnProperty.call(value, 'allow') && value.allow?.length === 0) {
118
304
  ctx.addIssue({
119
305
  code: z.ZodIssueCode.custom,
120
306
  path: ['allow'],
121
307
  message: 'Argument policy allow list must contain at least one value.',
122
308
  });
123
309
  }
310
+ if (Object.prototype.hasOwnProperty.call(value, 'glob_allow') &&
311
+ value.glob_allow?.length === 0) {
312
+ ctx.addIssue({
313
+ code: z.ZodIssueCode.custom,
314
+ path: ['glob_allow'],
315
+ message: 'Argument policy glob_allow list must contain at least one value.',
316
+ });
317
+ }
318
+ if (Object.prototype.hasOwnProperty.call(value, 'each_allow') &&
319
+ value.each_allow?.length === 0) {
320
+ ctx.addIssue({
321
+ code: z.ZodIssueCode.custom,
322
+ path: ['each_allow'],
323
+ message: 'Argument policy each_allow list must contain at least one value.',
324
+ });
325
+ }
124
326
  });
125
- export const ToolArgPolicyConfig = z.record(z.record(ToolArgConstraintConfig));
126
- export const ToolOverride = z.object({
327
+ export const ToolArgConstraintListConfig = z
328
+ .union([ToolArgConstraintConfig, z.array(ToolArgConstraintConfig).nonempty()])
329
+ .transform((value) => (Array.isArray(value) ? value : [value]));
330
+ export const ToolArgPolicyConfig = z.record(z.record(ToolArgConstraintListConfig));
331
+ // A command router for tools whose privilege lives inside a string argument — CLI-style dispatcher
332
+ // tools (e.g. an MCP that exposes one `exec`/`run` tool taking a command string, where read vs.
333
+ // write vs. admin is a substring of that argument, not a distinct tool name). Maps the arg's value
334
+ // to a decision by glob-matching it against allow/ask/deny lists. Precedence deny > ask > allow;
335
+ // anything unmatched is denied (fail-closed). Same shape and semantics as the `exec` sub-policy,
336
+ // generalized to any tool + arg. Composes through `extends` (the lists union across the chain).
337
+ export const CommandPolicyRuleConfig = z
338
+ .object({
339
+ allow: z.array(z.string()).default([]),
340
+ ask: z.array(z.string()).default([]),
341
+ deny: z.array(z.string()).default([]),
342
+ // Decision for a command that matches none of the lists. Defaults to `deny` (fail-closed).
343
+ // Set `ask` for the common "these specific commands run/ask, everything else needs approval"
344
+ // shape without a catch-all pattern that would shadow the narrower allow list.
345
+ default: z.enum(['allow', 'ask', 'deny']).optional(),
346
+ })
347
+ .strict()
348
+ .refine((rule) => rule.allow.length + rule.ask.length + rule.deny.length > 0 || rule.default !== undefined, {
349
+ message: 'Command policy rule must define at least one allow/ask/deny pattern or a default.',
350
+ });
351
+ // tool name → arg name → decision lists
352
+ export const CommandPolicyConfig = z.record(z.record(CommandPolicyRuleConfig));
353
+ export const ArgScopeConfig = z
354
+ .record(z.union([z.string(), z.array(z.string()).nonempty()]))
355
+ .transform((scope) => Object.fromEntries(Object.entries(scope).map(([dimension, value]) => [
356
+ dimension,
357
+ Array.isArray(value) ? value : [value],
358
+ ])));
359
+ export const ArgDimensionConfig = z
360
+ .object({
361
+ match: z.enum(['in', 'glob_in', 'each_in']).default('in'),
362
+ normalize: z.array(NormalizerName).optional(),
363
+ bindings: z.record(z.string()),
364
+ })
365
+ .strict();
366
+ export const ToolOverride = z
367
+ .object({
368
+ /** Replaces the upstream description entirely. */
127
369
  description: z.string().optional(),
370
+ /**
371
+ * Appended after whatever description survives (upstream, or `description` when set). Use this
372
+ * for house rules you want on top of the vendor's docs without restating them by hand.
373
+ */
374
+ description_append: z.string().optional(),
128
375
  alias_of: z.string().optional(),
129
376
  sandbox_presets: SandboxPresetRef.default([]),
130
377
  sandbox: SandboxOverrideConfig.optional(),
131
- args: z.record(ToolArgConstraintConfig).optional(),
132
- });
133
- export const AgentExecConfig = z.object({
378
+ args: z.record(ToolArgConstraintListConfig).optional(),
379
+ })
380
+ .strict();
381
+ export const AgentExecConfig = z
382
+ .object({
134
383
  allow: z.array(z.string()).default([]),
135
384
  ask: z.array(z.string()).default([]),
136
385
  deny: z.array(z.string()).default([]),
137
386
  env: z.record(z.string()).default({}),
138
387
  default_timeout_ms: z.number().default(30000),
139
- });
140
- export const AgentHttpConfig = z.object({
388
+ })
389
+ .strict();
390
+ export const AgentHttpConfig = z
391
+ .object({
141
392
  domain_allowlist: z.array(z.string()).default([]),
142
393
  max_response_bytes: z.number().default(1048576), // 1MB
143
394
  timeout_ms: z.number().default(30000),
144
- });
145
- export const RememberAllowRule = z.object({
395
+ })
396
+ .strict();
397
+ export const RememberAllowRule = z
398
+ .object({
146
399
  tool: z.string(),
147
400
  expires_at: z.string().optional(),
148
- });
401
+ })
402
+ .strict();
149
403
  export const MiddlewareItemConfig = z
150
404
  .object({
151
405
  name: z.enum([
@@ -182,71 +436,153 @@ export const MiddlewareItemConfig = z
182
436
  threshold_chars: z.number().optional(),
183
437
  })
184
438
  .strict();
185
- export const AgentConfig = z.object({
439
+ // Per-agent resource safeties (bulkheads) so one agent cannot exhaust the gateway and
440
+ // starve the others. Every field is optional; unset fields fall back to the global
441
+ // `security.limits` block, then to built-in defaults (see resolveLimits). All *_ms fields
442
+ // treat 0 as "disabled". These limits are deliberately HITL-aware: the idle reaper never
443
+ // touches a session with an in-flight request (a call parked on human approval keeps its
444
+ // request open), and call_execution_timeout_ms clocks ONLY downstream execution — never the
445
+ // approval wait, which happens in an earlier middleware.
446
+ export const LimitsConfig = z
447
+ .object({
448
+ // Max concurrent open MCP sessions a single agent may hold (per transport plane).
449
+ max_sessions_per_agent: z.number().int().positive().optional(),
450
+ // Absolute ceiling on open sessions across ALL agents (backstop for the whole box).
451
+ max_sessions_global: z.number().int().positive().optional(),
452
+ // Reap a session after this long with NO in-flight request. 0 = never reap on idle.
453
+ session_idle_ms: z.number().int().nonnegative().optional(),
454
+ // Hard cap on total session lifetime regardless of activity. 0 = no lifetime cap
455
+ // (default — an async task parked on approval for hours must survive).
456
+ session_max_lifetime_ms: z.number().int().nonnegative().optional(),
457
+ // Token-bucket rate limit on NEW sessions per agent: at most `new_session_max`
458
+ // initializations per `new_session_window_ms`. Stops reconnect/init storms at the door.
459
+ new_session_max: z.number().int().positive().optional(),
460
+ new_session_window_ms: z.number().int().positive().optional(),
461
+ // Max concurrently EXECUTING tool calls per agent (post-approval only; calls parked
462
+ // awaiting HITL do not count). Bounds event-loop / upstream-pool monopolization.
463
+ max_concurrent_calls_per_agent: z.number().int().positive().optional(),
464
+ // Deadline on a single downstream tool execution, excluding any HITL approval wait.
465
+ // 0 = disabled (default), so genuinely long async downstream calls are never severed.
466
+ call_execution_timeout_ms: z.number().int().nonnegative().optional(),
467
+ })
468
+ .strict();
469
+ export const AgentConfig = z
470
+ .object({
186
471
  token: EnvString.optional(),
187
472
  extends: z.array(z.string()).default([]),
473
+ // Opt out of the top-level `default_profile` (which every agent otherwise inherits).
474
+ // Set false for a locked-down agent that must get nothing implicitly. No effect when
475
+ // `default_profile` is unset.
476
+ inherit_default: z.boolean().default(true),
188
477
  allow: z.array(z.string()).default([]),
189
478
  remember_allow: z.array(RememberAllowRule).default([]),
190
479
  ask: z.array(z.string()).default([]),
191
480
  deny: z.array(z.string()).default([]),
192
481
  tool_overrides: z.record(ToolOverride).default({}),
193
482
  arg_policy: ToolArgPolicyConfig.optional(),
483
+ arg_scope: ArgScopeConfig.optional(),
484
+ command_policy: CommandPolicyConfig.optional(),
194
485
  exec: AgentExecConfig.default({}),
195
486
  http: AgentHttpConfig.default({}),
196
487
  sandbox: SandboxConfig.default({}),
197
488
  middleware: z.array(MiddlewareItemConfig).optional(),
198
- });
199
- export const ProfileConfig = z.object({
489
+ // Per-agent opt-in for the plain-HTTP tools API (POST /agents/:id/tools/invoke).
490
+ // Consulted ONLY when server.expose_tools_api is 'per-agent'. Lets service consumers
491
+ // (e.g. an ingestion job) use HTTP while interactive agents stay MCP-only.
492
+ expose_tools_api: z.boolean().default(false),
493
+ // Per-agent resource safeties; unset fields inherit from `security.limits` then defaults.
494
+ limits: LimitsConfig.optional(),
495
+ })
496
+ .strict();
497
+ export const ProfileConfig = z
498
+ .object({
200
499
  extends: z.array(z.string()).default([]),
201
500
  allow: z.array(z.string()).default([]),
202
501
  ask: z.array(z.string()).default([]),
203
502
  deny: z.array(z.string()).default([]),
204
- });
503
+ // Composes through `extends` alongside the permission lists, so a profile that grants a
504
+ // provider's tools can also carry the notes an agent needs to use them correctly.
505
+ tool_overrides: z.record(ToolOverride).default({}),
506
+ arg_policy: ToolArgPolicyConfig.optional(),
507
+ arg_scope: ArgScopeConfig.optional(),
508
+ command_policy: CommandPolicyConfig.optional(),
509
+ })
510
+ .strict();
205
511
  export const ApprovalProviderConfig = z.discriminatedUnion('type', [
206
- z.object({
512
+ z
513
+ .object({
207
514
  type: z.literal('telegram'),
208
515
  bot_token: EnvString,
209
516
  chat_id: EnvString,
210
- }),
211
- z.object({
517
+ })
518
+ .strict(),
519
+ z
520
+ .object({
212
521
  type: z.literal('openclaw'),
213
522
  gateway_url: z.string().default('ws://localhost:18789'),
214
523
  token: EnvString,
215
524
  session_key: z.string().default('main'),
216
- }),
217
- z.object({
525
+ })
526
+ .strict(),
527
+ z
528
+ .object({
218
529
  type: z.literal('slack'),
219
530
  webhook_url: EnvString,
220
- }),
221
- z.object({
531
+ })
532
+ .strict(),
533
+ z
534
+ .object({
222
535
  type: z.literal('webhook'),
223
536
  url: EnvString,
224
537
  headers: z.record(z.string()).default({}),
225
- }),
226
- z.object({
538
+ })
539
+ .strict(),
540
+ z
541
+ .object({
227
542
  type: z.literal('tui'),
228
- }),
229
- z.object({
543
+ })
544
+ .strict(),
545
+ z
546
+ .object({
230
547
  type: z.literal('macos'),
231
548
  sound: z.string().optional(), // macOS sound name, e.g. "Submarine", "Glass", "Ping"
232
- }),
233
- z.object({
549
+ })
550
+ .strict(),
551
+ z
552
+ .object({
234
553
  type: z.literal('dashboard'),
235
554
  host: z.string().default('127.0.0.1'),
236
555
  port: z.number().int().min(1).max(65535).default(4112),
237
- }),
238
- z.object({
556
+ })
557
+ .strict(),
558
+ z
559
+ .object({
560
+ type: z.literal('ios'),
561
+ team_id: EnvString,
562
+ key_id: EnvString,
563
+ key_path: PathString,
564
+ bundle_id: z.string(),
565
+ production: z.boolean().default(true),
566
+ interruption_level: z.enum(['passive', 'active', 'time-sensitive']).optional(),
567
+ })
568
+ .strict(),
569
+ z
570
+ .object({
239
571
  type: z.literal('stdio'),
240
- }),
572
+ })
573
+ .strict(),
241
574
  ]);
242
- export const ApprovalsConfig = z.object({
575
+ export const ApprovalsConfig = z
576
+ .object({
243
577
  provider: z
244
- .union([ApprovalProviderConfig, z.array(ApprovalProviderConfig).min(1)])
578
+ .union([ApprovalProviderConfig, z.array(ApprovalProviderConfig)])
245
579
  .default({ type: 'stdio' }),
246
580
  timeout_ms: z.number().int().min(0).default(300000), // 5 minutes; 0 = no timeout
247
581
  batch_window_ms: z.number().int().min(0).default(0),
248
- });
249
- export const SecurityConfig = z.object({
582
+ })
583
+ .strict();
584
+ export const SecurityConfig = z
585
+ .object({
250
586
  blocked_hosts: z
251
587
  .array(z.string())
252
588
  .default([
@@ -280,54 +616,119 @@ export const SecurityConfig = z.object({
280
616
  'fe80:*',
281
617
  ]),
282
618
  allowed_local: z.array(z.string()).default([]),
283
- });
284
- export const AuditConfig = z.object({
619
+ // Gateway-wide default resource safeties. Per-agent `limits` overrides these field-by-field.
620
+ limits: LimitsConfig.optional(),
621
+ })
622
+ .strict();
623
+ export const AuditConfig = z
624
+ .object({
285
625
  db_path: PathString.default('./audit.db'),
286
626
  retention_days: z.number().default(90),
287
627
  redact_fields: z
288
628
  .array(z.string())
289
629
  .default(['password', 'token', 'secret', 'key', 'authorization']),
290
- });
291
- export const ServerConfig = z.object({
630
+ })
631
+ .strict();
632
+ export const ManagementApiConfig = z
633
+ .object({
634
+ enabled: z.boolean().default(false),
635
+ api_secret: EnvString.optional(),
636
+ host: z.string().default('127.0.0.1'),
637
+ port: z.number().int().min(1).max(65535).default(4113),
638
+ insecure_remote_bind: z.boolean().default(false),
639
+ expose_hook_api: z.boolean().default(true),
640
+ })
641
+ .strict();
642
+ // HTTP tools-API exposure mode (POST /agents/:id/tools/invoke):
643
+ // 'all' — every agent gets the HTTP transport.
644
+ // 'none' — no agent gets it; a hard kill-switch that overrides per-agent opt-ins.
645
+ // 'per-agent' — each agent's `expose_tools_api` (default false) decides.
646
+ // Legacy booleans are accepted: true → 'all', false → 'none'.
647
+ export const ToolsApiMode = z.enum(['all', 'none', 'per-agent']);
648
+ const ToolsApiModeConfig = z.preprocess((v) => (v === true ? 'all' : v === false ? 'none' : v), ToolsApiMode);
649
+ export const ServerConfig = z
650
+ .object({
292
651
  port: z.number().int().min(1).max(65535).default(4111),
293
652
  host: z.string().default('127.0.0.1'),
294
653
  api_secret: EnvString.optional(),
295
654
  auth_required: z.boolean().default(false),
296
655
  require_agent_tokens: z.boolean().default(false),
297
656
  allowed_origins: z.array(z.string()).default([]),
298
- expose_management_api: z.boolean().default(true),
299
- expose_tools_api: z.boolean().default(true),
300
- expose_hook_api: z.boolean().default(true),
657
+ expose_tools_api: ToolsApiModeConfig.default('per-agent'),
658
+ management_api: ManagementApiConfig.default({}),
659
+ // Deprecated compatibility aliases. Runtime code must use management_api.
660
+ expose_management_api: z.boolean().optional(),
661
+ expose_hook_api: z.boolean().optional(),
662
+ })
663
+ .strict()
664
+ .transform((server) => {
665
+ const management_api = {
666
+ ...server.management_api,
667
+ ...(server.expose_management_api !== undefined
668
+ ? { enabled: server.expose_management_api }
669
+ : {}),
670
+ ...(server.expose_hook_api !== undefined ? { expose_hook_api: server.expose_hook_api } : {}),
671
+ };
672
+ return {
673
+ ...server,
674
+ management_api,
675
+ };
301
676
  });
677
+ export const LINT_RULE_IDS = [
678
+ 'dead-deny',
679
+ 'unused-profile',
680
+ 'unused-value-set',
681
+ 'unused-dimension',
682
+ 'empty-agent',
683
+ 'missing-env-ref',
684
+ 'unresolvable-ref',
685
+ 'unallocated-tool',
686
+ 'dead-allow',
687
+ ];
688
+ export const LintRuleIdConfig = z.enum(LINT_RULE_IDS);
689
+ export const LintRuleSeverityConfig = z.enum(['info', 'warn', 'error']);
690
+ export const LintConfig = z
691
+ .object({
692
+ disable: z.array(LintRuleIdConfig).default([]),
693
+ severity: z.record(LintRuleIdConfig, LintRuleSeverityConfig).default({}),
694
+ })
695
+ .strict();
302
696
  // --- CLI backend config ---
303
- export const CliParamConfig = z.object({
697
+ export const CliParamConfig = z
698
+ .object({
304
699
  type: z.enum(['string', 'number', 'boolean']),
305
700
  flag: z.string().regex(/^-/, 'Flag must start with a dash (e.g. -n, --verbose)').optional(),
306
701
  positional: z.boolean().default(false),
307
702
  required: z.boolean().default(false),
308
703
  default: z.union([z.string(), z.number(), z.boolean()]).optional(),
309
704
  description: z.string().optional(),
310
- });
311
- export const CliCommandConfig = z.object({
705
+ })
706
+ .strict();
707
+ export const CliCommandConfig = z
708
+ .object({
312
709
  exec: z.string(),
313
710
  description: z.string().optional(),
314
711
  params: z.record(CliParamConfig).default({}),
315
712
  cwd: PathString.optional(),
316
713
  timeout: z.number().default(30),
317
- });
318
- export const CliConfig = z.object({
714
+ })
715
+ .strict();
716
+ export const CliConfig = z
717
+ .object({
319
718
  discovered: PathString.optional(),
320
719
  shell: PathString.optional(),
321
720
  cwd: PathString.optional(),
322
721
  max_output_bytes: z.number().default(30_000),
323
722
  commands: z.record(CliCommandConfig).default({}),
324
- });
723
+ })
724
+ .strict();
325
725
  // --- OpenAPI backend config ---
326
726
  export const ApiAuthConfig = z.discriminatedUnion('type', [
327
- z.object({ type: z.literal('bearer'), token: EnvString }),
328
- z.object({ type: z.literal('header'), name: z.string(), value: EnvString }),
727
+ z.object({ type: z.literal('bearer'), token: EnvString }).strict(),
728
+ z.object({ type: z.literal('header'), name: z.string(), value: EnvString }).strict(),
329
729
  ]);
330
- export const ApiConfig = z.object({
730
+ export const ApiConfig = z
731
+ .object({
331
732
  spec: PathString,
332
733
  base_url: z.string().optional(),
333
734
  auth: ApiAuthConfig.optional(),
@@ -335,7 +736,8 @@ export const ApiConfig = z.object({
335
736
  exclude: z.array(z.string()).optional(),
336
737
  timeout_ms: z.number().default(30000),
337
738
  max_response_bytes: z.number().default(1048576),
338
- });
739
+ })
740
+ .strict();
339
741
  export const SandboxPresetConfig = SandboxOverrideConfig;
340
742
  function mergeSandboxOverride(base, override) {
341
743
  const result = {
@@ -451,7 +853,14 @@ function applySandboxPresetsToAgent(agent, sandboxPresets) {
451
853
  export const GatewayConfig = z
452
854
  .object({
453
855
  providers: z.record(ProviderConfig).default({}),
856
+ value_sets: z.record(ValueSetConfig).default({}),
857
+ arg_dimensions: z.record(ArgDimensionConfig).default({}),
454
858
  profiles: z.record(ProfileConfig).default({}),
859
+ // Optional profile that every agent inherits at lowest precedence, for DRY low-risk grants
860
+ // (e.g. self-inspection tools). Injected at the front of each agent's `extends`, so an agent
861
+ // can still override it (deny > ask > allow), and opt out entirely via `inherit_default: false`.
862
+ // The named profile may itself `extends` a chain, so one entry composes many.
863
+ default_profile: z.string().optional(),
455
864
  sandbox_presets: z.record(SandboxPresetConfig).default({}),
456
865
  clis: z.record(CliConfig).default({}),
457
866
  apis: z.record(ApiConfig).default({}),
@@ -460,12 +869,29 @@ export const GatewayConfig = z
460
869
  security: SecurityConfig.default({}),
461
870
  audit: AuditConfig.default({}),
462
871
  server: ServerConfig.default({}),
872
+ lint: LintConfig.default({}),
463
873
  })
874
+ .strict()
464
875
  .transform((config) => ({
465
876
  ...config,
466
877
  agents: Object.fromEntries(Object.entries(config.agents).map(([key, value]) => [
467
878
  key,
468
- applySandboxPresetsToAgent(value, config.sandbox_presets),
879
+ applyDefaultProfileToAgent(applySandboxPresetsToAgent(value, config.sandbox_presets), config.default_profile, config.profiles),
469
880
  ])),
470
881
  }));
882
+ // Prepend the top-level `default_profile` to an agent's `extends` so it resolves at lowest
883
+ // precedence and both the runtime resolver (applyProfiles) and the CLI `explain` path pick it up
884
+ // from one place. Skipped when: no default is configured, the agent opted out via
885
+ // `inherit_default: false`, the agent already extends it (avoid a duplicate in the extends tree),
886
+ // or the profile does not exist — the last case is surfaced as a single clear diagnostic by
887
+ // validateConfig rather than one confusing unknown-profile-ref per agent.
888
+ function applyDefaultProfileToAgent(agent, defaultProfile, profiles) {
889
+ if (!defaultProfile ||
890
+ !agent.inherit_default ||
891
+ !profiles[defaultProfile] ||
892
+ agent.extends.includes(defaultProfile)) {
893
+ return agent;
894
+ }
895
+ return { ...agent, extends: [defaultProfile, ...agent.extends] };
896
+ }
471
897
  //# sourceMappingURL=schema.js.map