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.
- package/README.md +47 -47
- package/dist/activity/stream.d.ts +29 -0
- package/dist/activity/stream.d.ts.map +1 -0
- package/dist/activity/stream.js +36 -0
- package/dist/activity/stream.js.map +1 -0
- package/dist/airlock/context.d.ts +12 -0
- package/dist/airlock/context.d.ts.map +1 -0
- package/dist/airlock/context.js +32 -0
- package/dist/airlock/context.js.map +1 -0
- package/dist/airlock/tools.d.ts +11 -0
- package/dist/airlock/tools.d.ts.map +1 -0
- package/dist/airlock/tools.js +25 -0
- package/dist/airlock/tools.js.map +1 -0
- package/dist/allowlist/engine.d.ts +12 -0
- package/dist/allowlist/engine.d.ts.map +1 -1
- package/dist/allowlist/engine.js +40 -15
- package/dist/allowlist/engine.js.map +1 -1
- package/dist/audit/api.d.ts +2 -0
- package/dist/audit/api.d.ts.map +1 -1
- package/dist/audit/api.js.map +1 -1
- package/dist/audit/db.d.ts +23 -0
- package/dist/audit/db.d.ts.map +1 -1
- package/dist/audit/db.js +92 -3
- package/dist/audit/db.js.map +1 -1
- package/dist/audit/logger.d.ts +8 -1
- package/dist/audit/logger.d.ts.map +1 -1
- package/dist/audit/logger.js +21 -0
- package/dist/audit/logger.js.map +1 -1
- package/dist/backend/airlock-adapter.d.ts +32 -0
- package/dist/backend/airlock-adapter.d.ts.map +1 -0
- package/dist/backend/airlock-adapter.js +318 -0
- package/dist/backend/airlock-adapter.js.map +1 -0
- package/dist/backend/cli/builder.d.ts.map +1 -1
- package/dist/backend/cli/builder.js +10 -3
- package/dist/backend/cli/builder.js.map +1 -1
- package/dist/backend/factory.d.ts +5 -1
- package/dist/backend/factory.d.ts.map +1 -1
- package/dist/backend/factory.js +5 -5
- package/dist/backend/factory.js.map +1 -1
- package/dist/backend/mcp-adapter.d.ts +1 -0
- package/dist/backend/mcp-adapter.d.ts.map +1 -1
- package/dist/backend/mcp-adapter.js +33 -4
- package/dist/backend/mcp-adapter.js.map +1 -1
- package/dist/backend/openapi/adapter.d.ts.map +1 -1
- package/dist/backend/openapi/adapter.js +66 -31
- package/dist/backend/openapi/adapter.js.map +1 -1
- package/dist/backend/types.d.ts +8 -0
- package/dist/backend/types.d.ts.map +1 -1
- package/dist/config/loader.d.ts +12 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +591 -23
- package/dist/config/loader.js.map +1 -1
- package/dist/config/profiles.d.ts +46 -3
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +377 -3
- package/dist/config/profiles.js.map +1 -1
- package/dist/config/schema.d.ts +6426 -803
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +499 -73
- package/dist/config/schema.js.map +1 -1
- package/dist/configure-cli/cli.d.ts.map +1 -1
- package/dist/configure-cli/cli.js +1 -2
- package/dist/configure-cli/cli.js.map +1 -1
- package/dist/configure-web/cli.d.ts +1 -0
- package/dist/configure-web/cli.d.ts.map +1 -1
- package/dist/configure-web/cli.js +261 -48
- package/dist/configure-web/cli.js.map +1 -1
- package/dist/discover/strategies/completion.d.ts.map +1 -1
- package/dist/discover/strategies/completion.js +3 -3
- package/dist/discover/strategies/completion.js.map +1 -1
- package/dist/gateway.d.ts +21 -1
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +345 -60
- package/dist/gateway.js.map +1 -1
- package/dist/hitl/api.d.ts +2 -0
- package/dist/hitl/api.d.ts.map +1 -1
- package/dist/hitl/api.js +8 -0
- package/dist/hitl/api.js.map +1 -1
- package/dist/hitl/approval-dashboard.d.ts +5 -9
- package/dist/hitl/approval-dashboard.d.ts.map +1 -1
- package/dist/hitl/approval-dashboard.js +8 -55
- package/dist/hitl/approval-dashboard.js.map +1 -1
- package/dist/hitl/approval-stream.d.ts +34 -0
- package/dist/hitl/approval-stream.d.ts.map +1 -0
- package/dist/hitl/approval-stream.js +111 -0
- package/dist/hitl/approval-stream.js.map +1 -0
- package/dist/hitl/batcher.d.ts +2 -0
- package/dist/hitl/batcher.d.ts.map +1 -1
- package/dist/hitl/batcher.js +16 -0
- package/dist/hitl/batcher.js.map +1 -1
- package/dist/hitl/engine.d.ts +16 -7
- package/dist/hitl/engine.d.ts.map +1 -1
- package/dist/hitl/engine.js +109 -35
- package/dist/hitl/engine.js.map +1 -1
- package/dist/hitl/formatter.d.ts.map +1 -1
- package/dist/hitl/formatter.js +2 -0
- package/dist/hitl/formatter.js.map +1 -1
- package/dist/hitl/provider-factory.d.ts +8 -2
- package/dist/hitl/provider-factory.d.ts.map +1 -1
- package/dist/hitl/provider-factory.js +23 -2
- package/dist/hitl/provider-factory.js.map +1 -1
- package/dist/hitl/providers/composite.d.ts +9 -0
- package/dist/hitl/providers/composite.d.ts.map +1 -1
- package/dist/hitl/providers/composite.js +14 -0
- package/dist/hitl/providers/composite.js.map +1 -1
- package/dist/hitl/providers/dashboard.d.ts +12 -2
- package/dist/hitl/providers/dashboard.d.ts.map +1 -1
- package/dist/hitl/providers/dashboard.js +11 -5
- package/dist/hitl/providers/dashboard.js.map +1 -1
- package/dist/hitl/providers/ios.d.ts +23 -0
- package/dist/hitl/providers/ios.d.ts.map +1 -0
- package/dist/hitl/providers/ios.js +183 -0
- package/dist/hitl/providers/ios.js.map +1 -0
- package/dist/hitl/providers/macos.d.ts.map +1 -1
- package/dist/hitl/providers/macos.js +8 -4
- package/dist/hitl/providers/macos.js.map +1 -1
- package/dist/hitl/providers/openclaw.js +2 -2
- package/dist/hitl/providers/openclaw.js.map +1 -1
- package/dist/hitl/providers/stdio.js +2 -2
- package/dist/hitl/providers/stdio.js.map +1 -1
- package/dist/hitl/providers/telegram.js +2 -2
- package/dist/hitl/providers/telegram.js.map +1 -1
- package/dist/hitl/providers/tui.d.ts.map +1 -1
- package/dist/hitl/providers/tui.js +8 -2
- package/dist/hitl/providers/tui.js.map +1 -1
- package/dist/hitl/providers/types.d.ts +14 -0
- package/dist/hitl/providers/types.d.ts.map +1 -1
- package/dist/hook/api.d.ts +2 -0
- package/dist/hook/api.d.ts.map +1 -1
- package/dist/hook/api.js.map +1 -1
- package/dist/hook/normalizer.js +2 -2
- package/dist/hook/normalizer.js.map +1 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/dist/introspect/cli.d.ts +55 -0
- package/dist/introspect/cli.d.ts.map +1 -0
- package/dist/introspect/cli.js +850 -0
- package/dist/introspect/cli.js.map +1 -0
- package/dist/middleware/chain-builder.d.ts +1 -1
- package/dist/middleware/chain-builder.d.ts.map +1 -1
- package/dist/middleware/chain-builder.js +8 -4
- package/dist/middleware/chain-builder.js.map +1 -1
- package/dist/middleware/core/allowlist.d.ts.map +1 -1
- package/dist/middleware/core/allowlist.js +15 -0
- package/dist/middleware/core/allowlist.js.map +1 -1
- package/dist/middleware/core/arg-policy.d.ts +2 -1
- package/dist/middleware/core/arg-policy.d.ts.map +1 -1
- package/dist/middleware/core/arg-policy.js +158 -46
- package/dist/middleware/core/arg-policy.js.map +1 -1
- package/dist/middleware/core/command-policy.d.ts +13 -0
- package/dist/middleware/core/command-policy.d.ts.map +1 -0
- package/dist/middleware/core/command-policy.js +94 -0
- package/dist/middleware/core/command-policy.js.map +1 -0
- package/dist/middleware/core/exec-policy.d.ts.map +1 -1
- package/dist/middleware/core/exec-policy.js +17 -1
- package/dist/middleware/core/exec-policy.js.map +1 -1
- package/dist/middleware/core/execute.d.ts +2 -0
- package/dist/middleware/core/execute.d.ts.map +1 -1
- package/dist/middleware/core/execute.js +79 -3
- package/dist/middleware/core/execute.js.map +1 -1
- package/dist/middleware/core/hitl-gate.d.ts.map +1 -1
- package/dist/middleware/core/hitl-gate.js +22 -4
- package/dist/middleware/core/hitl-gate.js.map +1 -1
- package/dist/middleware/core/schema-validator.d.ts.map +1 -1
- package/dist/middleware/core/schema-validator.js +7 -3
- package/dist/middleware/core/schema-validator.js.map +1 -1
- package/dist/middleware/detectors/injection-detector.d.ts.map +1 -1
- package/dist/middleware/detectors/injection-detector.js +2 -0
- package/dist/middleware/detectors/injection-detector.js.map +1 -1
- package/dist/middleware/detectors/sensitivity-classifier.js +1 -0
- package/dist/middleware/detectors/sensitivity-classifier.js.map +1 -1
- package/dist/middleware/post/canary-token-injector.d.ts +4 -1
- package/dist/middleware/post/canary-token-injector.d.ts.map +1 -1
- package/dist/middleware/post/canary-token-injector.js +6 -1
- package/dist/middleware/post/canary-token-injector.js.map +1 -1
- package/dist/middleware/post/output-injection-detector.d.ts.map +1 -1
- package/dist/middleware/post/output-injection-detector.js +1 -0
- package/dist/middleware/post/output-injection-detector.js.map +1 -1
- package/dist/middleware/post/untrusted-envelope.d.ts.map +1 -1
- package/dist/middleware/post/untrusted-envelope.js +14 -1
- package/dist/middleware/post/untrusted-envelope.js.map +1 -1
- package/dist/mobile/api.d.ts +20 -0
- package/dist/mobile/api.d.ts.map +1 -0
- package/dist/mobile/api.js +259 -0
- package/dist/mobile/api.js.map +1 -0
- package/dist/mobile/apns.d.ts +68 -0
- package/dist/mobile/apns.d.ts.map +1 -0
- package/dist/mobile/apns.js +322 -0
- package/dist/mobile/apns.js.map +1 -0
- package/dist/pool/client-credentials.d.ts +46 -0
- package/dist/pool/client-credentials.d.ts.map +1 -0
- package/dist/pool/client-credentials.js +204 -0
- package/dist/pool/client-credentials.js.map +1 -0
- package/dist/pool/credential-health.d.ts +54 -0
- package/dist/pool/credential-health.d.ts.map +1 -0
- package/dist/pool/credential-health.js +262 -0
- package/dist/pool/credential-health.js.map +1 -0
- package/dist/pool/http-client.d.ts +52 -2
- package/dist/pool/http-client.d.ts.map +1 -1
- package/dist/pool/http-client.js +302 -17
- package/dist/pool/http-client.js.map +1 -1
- package/dist/pool/oauth-provider.d.ts +23 -0
- package/dist/pool/oauth-provider.d.ts.map +1 -1
- package/dist/pool/oauth-provider.js +134 -6
- package/dist/pool/oauth-provider.js.map +1 -1
- package/dist/pool/oauth-timing.d.ts +3 -0
- package/dist/pool/oauth-timing.d.ts.map +1 -0
- package/dist/pool/oauth-timing.js +8 -0
- package/dist/pool/oauth-timing.js.map +1 -0
- package/dist/pool/pool.d.ts +8 -1
- package/dist/pool/pool.d.ts.map +1 -1
- package/dist/pool/pool.js +17 -4
- package/dist/pool/pool.js.map +1 -1
- package/dist/pool/sse-client.d.ts +10 -1
- package/dist/pool/sse-client.d.ts.map +1 -1
- package/dist/pool/sse-client.js +46 -5
- package/dist/pool/sse-client.js.map +1 -1
- package/dist/pool/status.d.ts +6 -0
- package/dist/pool/status.d.ts.map +1 -0
- package/dist/pool/status.js +2 -0
- package/dist/pool/status.js.map +1 -0
- package/dist/pool/stdio-client.d.ts +11 -1
- package/dist/pool/stdio-client.d.ts.map +1 -1
- package/dist/pool/stdio-client.js +39 -3
- package/dist/pool/stdio-client.js.map +1 -1
- package/dist/registry/airlock-policy.d.ts +3 -0
- package/dist/registry/airlock-policy.d.ts.map +1 -0
- package/dist/registry/airlock-policy.js +50 -0
- package/dist/registry/airlock-policy.js.map +1 -0
- package/dist/registry/registry.d.ts +49 -4
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +160 -19
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/sanitizer.d.ts +16 -1
- package/dist/registry/sanitizer.d.ts.map +1 -1
- package/dist/registry/sanitizer.js +70 -11
- package/dist/registry/sanitizer.js.map +1 -1
- package/dist/security/blocked-hosts.d.ts +2 -0
- package/dist/security/blocked-hosts.d.ts.map +1 -1
- package/dist/security/blocked-hosts.js +61 -7
- package/dist/security/blocked-hosts.js.map +1 -1
- package/dist/security/request.d.ts +2 -0
- package/dist/security/request.d.ts.map +1 -1
- package/dist/security/request.js +6 -2
- package/dist/security/request.js.map +1 -1
- package/dist/security/secrets.d.ts +12 -0
- package/dist/security/secrets.d.ts.map +1 -0
- package/dist/security/secrets.js +138 -0
- package/dist/security/secrets.js.map +1 -0
- package/dist/setup-openclaw/cli.js +1 -1
- package/dist/stdio-mode.d.ts.map +1 -1
- package/dist/stdio-mode.js +159 -28
- package/dist/stdio-mode.js.map +1 -1
- package/dist/tools/api.d.ts +5 -1
- package/dist/tools/api.d.ts.map +1 -1
- package/dist/tools/api.js +67 -8
- package/dist/tools/api.js.map +1 -1
- package/dist/tools/exec.d.ts +2 -1
- package/dist/tools/exec.d.ts.map +1 -1
- package/dist/tools/exec.js +4 -3
- package/dist/tools/exec.js.map +1 -1
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +4 -7
- package/dist/tools/http.js.map +1 -1
- package/dist/transport/agent-server.d.ts +4 -0
- package/dist/transport/agent-server.d.ts.map +1 -1
- package/dist/transport/agent-server.js +47 -12
- package/dist/transport/agent-server.js.map +1 -1
- package/dist/transport/http-server.d.ts +4 -0
- package/dist/transport/http-server.d.ts.map +1 -1
- package/dist/transport/http-server.js +69 -9
- package/dist/transport/http-server.js.map +1 -1
- package/dist/transport/keepalive.d.ts +27 -0
- package/dist/transport/keepalive.d.ts.map +1 -0
- package/dist/transport/keepalive.js +30 -0
- package/dist/transport/keepalive.js.map +1 -0
- package/dist/transport/session-limiter.d.ts +84 -0
- package/dist/transport/session-limiter.d.ts.map +1 -0
- package/dist/transport/session-limiter.js +189 -0
- package/dist/transport/session-limiter.js.map +1 -0
- package/dist/transport/sse-server.d.ts +4 -0
- package/dist/transport/sse-server.d.ts.map +1 -1
- package/dist/transport/sse-server.js +27 -9
- package/dist/transport/sse-server.js.map +1 -1
- package/dist/transport/stdio-server.d.ts.map +1 -1
- package/dist/transport/stdio-server.js +4 -0
- package/dist/transport/stdio-server.js.map +1 -1
- package/dist/util/atomic-file.d.ts +9 -0
- package/dist/util/atomic-file.d.ts.map +1 -0
- package/dist/util/atomic-file.js +39 -0
- package/dist/util/atomic-file.js.map +1 -0
- package/dist/util/id.d.ts +1 -1
- package/dist/util/id.d.ts.map +1 -1
- package/dist/util/id.js +3 -3
- package/dist/util/id.js.map +1 -1
- package/examples/airlock.yaml +55 -0
- package/examples/claude-code-setup.md +0 -2
- package/examples/docker-compose.yaml +4 -3
- package/examples/docker-gateway.yaml +8 -3
- package/examples/gateway.yaml +8 -5
- package/examples/profiles.yaml +0 -2
- package/extensions/openclaw/index.ts +9 -6
- package/extensions/openclaw/openclaw.plugin.json +5 -5
- package/package.json +5 -3
- package/schema.json +1194 -19
package/dist/config/loader.js
CHANGED
|
@@ -1,20 +1,92 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
|
+
import { isIP } from 'net';
|
|
2
3
|
import { parse as parseYaml } from 'yaml';
|
|
3
|
-
import { GatewayConfig, getBuiltinProviders } from './schema.js';
|
|
4
|
+
import { GatewayConfig, getBuiltinProviders, withEnvVarResolution } from './schema.js';
|
|
4
5
|
import { applyProfiles } from './profiles.js';
|
|
5
6
|
import { matches } from '../allowlist/pattern.js';
|
|
7
|
+
import { AIRLOCK_NON_ASK_TOOLS } from '../airlock/tools.js';
|
|
6
8
|
import { childLogger } from '../util/logger.js';
|
|
7
9
|
const log = childLogger('config');
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export function loadConfigDetailed(path, options = {}) {
|
|
11
|
+
let raw;
|
|
12
|
+
try {
|
|
13
|
+
raw = readFileSync(path, 'utf-8');
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
return {
|
|
17
|
+
diagnostics: [
|
|
18
|
+
{
|
|
19
|
+
level: 'error',
|
|
20
|
+
message: `Could not read config at ${path}: ${err instanceof Error ? err.message : String(err)}`,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = parseYaml(raw);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return {
|
|
31
|
+
diagnostics: [
|
|
32
|
+
{
|
|
33
|
+
level: 'error',
|
|
34
|
+
message: `Invalid YAML at ${path}: ${err instanceof Error ? err.message : String(err)}`,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const diagnostics = findUnknownKeyDiagnostics(parsed);
|
|
40
|
+
const resolveEnv = options.resolveEnv ?? true;
|
|
41
|
+
let result;
|
|
42
|
+
try {
|
|
43
|
+
result = withEnvVarResolution(resolveEnv, () => GatewayConfig.safeParse(parsed));
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
diagnostics.push({
|
|
47
|
+
level: 'error',
|
|
48
|
+
message: `Invalid config at ${path}:\n${err instanceof Error ? err.message : String(err)}`,
|
|
49
|
+
suggestion: resolveEnv
|
|
50
|
+
? 'Set the referenced environment variable, or run config check with --no-resolve for structural validation without secrets.'
|
|
51
|
+
: undefined,
|
|
52
|
+
});
|
|
53
|
+
return { diagnostics: dedupeDiagnostics(diagnostics) };
|
|
54
|
+
}
|
|
12
55
|
if (!result.success) {
|
|
13
|
-
|
|
56
|
+
diagnostics.push({
|
|
57
|
+
level: 'error',
|
|
58
|
+
message: `Invalid config at ${path}:\n${result.error.toString()}`,
|
|
59
|
+
});
|
|
60
|
+
return { diagnostics: dedupeDiagnostics(diagnostics) };
|
|
61
|
+
}
|
|
62
|
+
const rawConfig = structuredClone(result.data);
|
|
63
|
+
diagnostics.push(...validateConfig(result.data));
|
|
64
|
+
diagnostics.push(...validateRawArgDimensionUsage(result.data));
|
|
65
|
+
diagnostics.push(...validateYamlScalarFootguns(result.data));
|
|
66
|
+
if (!diagnostics.some((diagnostic) => diagnostic.level === 'error')) {
|
|
67
|
+
try {
|
|
68
|
+
applyProfiles(result.data);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
diagnostics.push({
|
|
72
|
+
level: 'error',
|
|
73
|
+
message: err instanceof Error ? err.message : String(err),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!diagnostics.some((diagnostic) => diagnostic.level === 'error')) {
|
|
78
|
+
diagnostics.push(...validateConfig(result.data));
|
|
79
|
+
diagnostics.push(...validateEffectiveArgRestrictions(rawConfig, result.data));
|
|
14
80
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
81
|
+
return {
|
|
82
|
+
config: result.data,
|
|
83
|
+
rawConfig,
|
|
84
|
+
diagnostics: dedupeDiagnostics(diagnostics),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function loadConfig(path, options = {}) {
|
|
88
|
+
const result = loadConfigDetailed(path, options);
|
|
89
|
+
for (const d of result.diagnostics) {
|
|
18
90
|
const ctx = d.agent ? { agent: d.agent } : {};
|
|
19
91
|
const msg = d.suggestion ? `${d.message}\n → ${d.suggestion}` : d.message;
|
|
20
92
|
if (d.level === 'error') {
|
|
@@ -27,12 +99,15 @@ export function loadConfig(path) {
|
|
|
27
99
|
log.info(ctx, msg);
|
|
28
100
|
}
|
|
29
101
|
}
|
|
30
|
-
const errors = diagnostics.filter((d) => d.level === 'error');
|
|
102
|
+
const errors = result.diagnostics.filter((d) => d.level === 'error');
|
|
31
103
|
if (errors.length > 0) {
|
|
32
104
|
throw new Error(`Config validation failed with ${errors.length} error(s):\n` +
|
|
33
105
|
errors.map((e) => ` - ${e.agent ? `[${e.agent}] ` : ''}${e.message}`).join('\n'));
|
|
34
106
|
}
|
|
35
|
-
|
|
107
|
+
if (!result.config) {
|
|
108
|
+
throw new Error(`Config validation failed without a parsed config.`);
|
|
109
|
+
}
|
|
110
|
+
return result.config;
|
|
36
111
|
}
|
|
37
112
|
export function validateConfig(config) {
|
|
38
113
|
const diagnostics = [];
|
|
@@ -41,15 +116,27 @@ export function validateConfig(config) {
|
|
|
41
116
|
const profileNames = new Set(Object.keys(config.profiles));
|
|
42
117
|
const sandboxPresetNames = new Set(Object.keys(config.sandbox_presets ?? {}));
|
|
43
118
|
const serverHost = config.server.host;
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
config.server.expose_tools_api ||
|
|
48
|
-
config.server.expose_hook_api;
|
|
119
|
+
const isLoopback = isLoopbackHost(serverHost);
|
|
120
|
+
const managementApiEnabled = config.server.management_api.enabled;
|
|
121
|
+
const managementApiSecret = config.server.management_api.api_secret;
|
|
49
122
|
const agentsWithoutTokens = Object.entries(config.agents)
|
|
50
123
|
.filter(([, agent]) => !agent.token)
|
|
51
124
|
.map(([agentId]) => agentId);
|
|
52
|
-
const requireAgentTokens = config.server.require_agent_tokens || !isLoopback;
|
|
125
|
+
const requireAgentTokens = config.server.require_agent_tokens || !isLoopback || managementApiEnabled;
|
|
126
|
+
if (config.server.expose_management_api !== undefined) {
|
|
127
|
+
diagnostics.push({
|
|
128
|
+
level: 'warn',
|
|
129
|
+
message: 'server.expose_management_api is deprecated.',
|
|
130
|
+
suggestion: 'Use server.management_api.enabled instead.',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (config.server.expose_hook_api !== undefined) {
|
|
134
|
+
diagnostics.push({
|
|
135
|
+
level: 'warn',
|
|
136
|
+
message: 'server.expose_hook_api is deprecated.',
|
|
137
|
+
suggestion: 'Use server.management_api.expose_hook_api instead.',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
53
140
|
if (!isLoopback && !config.server.auth_required) {
|
|
54
141
|
diagnostics.push({
|
|
55
142
|
level: 'error',
|
|
@@ -61,7 +148,7 @@ export function validateConfig(config) {
|
|
|
61
148
|
diagnostics.push({
|
|
62
149
|
level: 'error',
|
|
63
150
|
message: 'Per-agent tokens are required, but some agents have no token.',
|
|
64
|
-
suggestion: `Add token to agents: ${agentsWithoutTokens.join(', ')}.
|
|
151
|
+
suggestion: `Add token to agents: ${agentsWithoutTokens.join(', ')}. Per-agent tokens are required for non-loopback data-plane binds, explicit server.require_agent_tokens, and split management API mode.`,
|
|
65
152
|
});
|
|
66
153
|
}
|
|
67
154
|
if (config.server.auth_required) {
|
|
@@ -72,26 +159,92 @@ export function validateConfig(config) {
|
|
|
72
159
|
suggestion: `Set server.api_secret or add token to agents: ${agentsWithoutTokens.join(', ')}.`,
|
|
73
160
|
});
|
|
74
161
|
}
|
|
75
|
-
if (!config.server.api_secret &&
|
|
162
|
+
if (!managementApiSecret && !config.server.api_secret && managementApiEnabled) {
|
|
163
|
+
diagnostics.push({
|
|
164
|
+
level: 'error',
|
|
165
|
+
message: 'server.auth_required is true, but the control-plane management API is enabled without a credential.',
|
|
166
|
+
suggestion: 'Set server.management_api.api_secret, set server.api_secret as a temporary fallback, or disable server.management_api.enabled.',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (managementApiEnabled && !managementApiSecret && !config.server.api_secret) {
|
|
171
|
+
diagnostics.push({
|
|
172
|
+
level: 'error',
|
|
173
|
+
message: 'server.management_api.enabled requires server.management_api.api_secret or server.api_secret.',
|
|
174
|
+
suggestion: 'Set server.management_api.api_secret so control-plane requests require bearer-token auth.',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (managementApiEnabled && !managementApiSecret && config.server.api_secret) {
|
|
178
|
+
diagnostics.push({
|
|
179
|
+
level: 'warn',
|
|
180
|
+
message: 'management_api is using server.api_secret; set server.management_api.api_secret to separate the control-plane secret from the data-plane fallback.',
|
|
181
|
+
suggestion: 'Generate a fresh management secret, set server.management_api.api_secret, and update management clients to use it.',
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (managementApiEnabled &&
|
|
185
|
+
managementApiSecret &&
|
|
186
|
+
config.server.api_secret &&
|
|
187
|
+
managementApiSecret === config.server.api_secret) {
|
|
188
|
+
diagnostics.push({
|
|
189
|
+
level: 'warn',
|
|
190
|
+
message: 'server.management_api.api_secret matches server.api_secret; rotate one secret to separate the control-plane credential from the data-plane fallback.',
|
|
191
|
+
suggestion: 'Use different resolved values for server.management_api.api_secret and server.api_secret.',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (managementApiEnabled &&
|
|
195
|
+
!isLoopbackHost(config.server.management_api.host) &&
|
|
196
|
+
!config.server.management_api.insecure_remote_bind) {
|
|
197
|
+
diagnostics.push({
|
|
198
|
+
level: 'error',
|
|
199
|
+
message: 'server.management_api.host is non-loopback while insecure_remote_bind is false.',
|
|
200
|
+
suggestion: 'Keep server.management_api.host on 127.0.0.1/::1, or explicitly set server.management_api.insecure_remote_bind: true and restrict the control-plane port with network ACLs.',
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (managementApiEnabled && config.server.management_api.port === config.server.port) {
|
|
204
|
+
diagnostics.push({
|
|
205
|
+
level: 'error',
|
|
206
|
+
message: 'Control-plane and data-plane must not share a socket.',
|
|
207
|
+
suggestion: 'Set server.management_api.port to a different port than server.port so admin/audit/approval routes cannot co-host with agent MCP routes.',
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// A provider carries ONE identity. `oauth: true` is a user's (authorization code, browser flow);
|
|
211
|
+
// `client_credentials` is the application's (no user at all). Declaring both is not a merge — it
|
|
212
|
+
// is an unanswerable question about whose name an agent's writes land under, so reject it here
|
|
213
|
+
// rather than let whichever code path runs first decide silently.
|
|
214
|
+
for (const [providerId, provider] of Object.entries(config.providers)) {
|
|
215
|
+
if (provider === 'builtin' || provider.type !== 'http')
|
|
216
|
+
continue;
|
|
217
|
+
if (provider.oauth && provider.client_credentials) {
|
|
76
218
|
diagnostics.push({
|
|
77
219
|
level: 'error',
|
|
78
|
-
message:
|
|
79
|
-
suggestion: '
|
|
220
|
+
message: `Provider "${providerId}" sets both oauth: true and client_credentials.`,
|
|
221
|
+
suggestion: 'Pick one identity: oauth: true authenticates as a USER (browser flow), client_credentials authenticates as the APP. To have both, declare two providers.',
|
|
80
222
|
});
|
|
81
223
|
}
|
|
82
224
|
}
|
|
225
|
+
if (config.default_profile && !profileNames.has(config.default_profile)) {
|
|
226
|
+
diagnostics.push({
|
|
227
|
+
level: 'error',
|
|
228
|
+
code: 'unknown-profile-ref',
|
|
229
|
+
message: `default_profile references unknown profile "${config.default_profile}".`,
|
|
230
|
+
suggestion: `Add "${config.default_profile}" to your profiles block, or check for typos.`,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
83
233
|
for (const [agentId, agent] of Object.entries(config.agents)) {
|
|
84
234
|
// Check for unknown profile references
|
|
85
235
|
for (const ref of agent.extends) {
|
|
86
236
|
if (!profileNames.has(ref)) {
|
|
87
237
|
diagnostics.push({
|
|
88
238
|
level: 'error',
|
|
239
|
+
code: 'unknown-profile-ref',
|
|
89
240
|
agent: agentId,
|
|
90
241
|
message: `extends references unknown profile "${ref}".`,
|
|
91
242
|
suggestion: `Add "${ref}" to your profiles block, or check for typos.`,
|
|
92
243
|
});
|
|
93
244
|
}
|
|
94
245
|
}
|
|
246
|
+
diagnostics.push(...validateArgScopeRefs(config, agent.arg_scope, `agents.${agentId}.arg_scope`, agentId));
|
|
247
|
+
diagnostics.push(...validateArgPolicyRefs(config, agent.arg_policy, `agents.${agentId}.arg_policy`, agentId));
|
|
95
248
|
for (const presetName of agent.sandbox.presets) {
|
|
96
249
|
if (!sandboxPresetNames.has(presetName)) {
|
|
97
250
|
diagnostics.push({
|
|
@@ -103,6 +256,7 @@ export function validateConfig(config) {
|
|
|
103
256
|
}
|
|
104
257
|
}
|
|
105
258
|
for (const [toolName, override] of Object.entries(agent.tool_overrides)) {
|
|
259
|
+
diagnostics.push(...validateArgPolicyRefs(config, override.args ? { [toolName]: override.args } : undefined, `agents.${agentId}.tool_overrides.${toolName}.args`, agentId));
|
|
106
260
|
for (const presetName of override.sandbox_presets ?? []) {
|
|
107
261
|
if (!sandboxPresetNames.has(presetName)) {
|
|
108
262
|
diagnostics.push({
|
|
@@ -117,6 +271,9 @@ export function validateConfig(config) {
|
|
|
117
271
|
// Collect all referenced namespaces from allow/ask/deny
|
|
118
272
|
const allPatterns = [...agent.allow, ...agent.ask, ...agent.deny];
|
|
119
273
|
const referencedNamespaces = new Set();
|
|
274
|
+
const toolOverrideNamespaces = new Set(Object.keys(agent.tool_overrides)
|
|
275
|
+
.map((toolName) => toolName.split('/')[0])
|
|
276
|
+
.filter((namespace) => !!namespace));
|
|
120
277
|
for (const pattern of allPatterns) {
|
|
121
278
|
const ns = pattern.split('/')[0];
|
|
122
279
|
if (ns)
|
|
@@ -124,7 +281,7 @@ export function validateConfig(config) {
|
|
|
124
281
|
}
|
|
125
282
|
// Check for unknown providers
|
|
126
283
|
for (const ns of referencedNamespaces) {
|
|
127
|
-
if (!providerNames.has(ns)) {
|
|
284
|
+
if (!providerNames.has(ns) && !toolOverrideNamespaces.has(ns)) {
|
|
128
285
|
diagnostics.push({
|
|
129
286
|
level: 'error',
|
|
130
287
|
agent: agentId,
|
|
@@ -150,6 +307,15 @@ export function validateConfig(config) {
|
|
|
150
307
|
}
|
|
151
308
|
// Check for unreachable ask: ask pattern also matched by deny
|
|
152
309
|
for (const askPattern of agent.ask) {
|
|
310
|
+
const forbiddenAirlockTool = AIRLOCK_NON_ASK_TOOLS.find((tool) => matches(askPattern, tool));
|
|
311
|
+
if (forbiddenAirlockTool) {
|
|
312
|
+
diagnostics.push({
|
|
313
|
+
level: 'error',
|
|
314
|
+
agent: agentId,
|
|
315
|
+
message: `"${askPattern}" puts ${forbiddenAirlockTool} behind ask, which is not allowed.`,
|
|
316
|
+
suggestion: 'Move Airlock human-attention tools to allow or deny. They cannot require approval without creating recursive approval.',
|
|
317
|
+
});
|
|
318
|
+
}
|
|
153
319
|
for (const denyPattern of agent.deny) {
|
|
154
320
|
if (matches(denyPattern, askPattern) ||
|
|
155
321
|
matches(askPattern, denyPattern) ||
|
|
@@ -184,7 +350,7 @@ export function validateConfig(config) {
|
|
|
184
350
|
});
|
|
185
351
|
}
|
|
186
352
|
// Check empty agent
|
|
187
|
-
if (agent.allow.length === 0 && agent.ask.length === 0) {
|
|
353
|
+
if (agent.extends.length === 0 && agent.allow.length === 0 && agent.ask.length === 0) {
|
|
188
354
|
diagnostics.push({
|
|
189
355
|
level: 'info',
|
|
190
356
|
agent: agentId,
|
|
@@ -201,6 +367,32 @@ export function validateConfig(config) {
|
|
|
201
367
|
});
|
|
202
368
|
}
|
|
203
369
|
}
|
|
370
|
+
for (const [profileId, profile] of Object.entries(config.profiles)) {
|
|
371
|
+
for (const ref of profile.extends) {
|
|
372
|
+
if (!profileNames.has(ref)) {
|
|
373
|
+
diagnostics.push({
|
|
374
|
+
level: 'error',
|
|
375
|
+
code: 'unknown-profile-ref',
|
|
376
|
+
message: `Profile "${profileId}" extends unknown profile "${ref}".`,
|
|
377
|
+
suggestion: `Add "${ref}" to your profiles block, or check for typos.`,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
diagnostics.push(...validateArgScopeRefs(config, profile.arg_scope, `profiles.${profileId}.arg_scope`));
|
|
382
|
+
diagnostics.push(...validateArgPolicyRefs(config, profile.arg_policy, `profiles.${profileId}.arg_policy`));
|
|
383
|
+
for (const [toolName, override] of Object.entries(profile.tool_overrides)) {
|
|
384
|
+
diagnostics.push(...validateArgPolicyRefs(config, override.args ? { [toolName]: override.args } : undefined, `profiles.${profileId}.tool_overrides.${toolName}.args`));
|
|
385
|
+
for (const presetName of override.sandbox_presets ?? []) {
|
|
386
|
+
if (!sandboxPresetNames.has(presetName)) {
|
|
387
|
+
diagnostics.push({
|
|
388
|
+
level: 'error',
|
|
389
|
+
message: `profiles.${profileId}.tool_overrides.${toolName}.sandbox_presets references unknown sandbox preset "${presetName}".`,
|
|
390
|
+
suggestion: `Add "${presetName}" to the top-level sandbox_presets block, or check for typos.`,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
204
396
|
// Validate CLI configs
|
|
205
397
|
for (const [cliId, cli] of Object.entries(config.clis)) {
|
|
206
398
|
for (const [cmdName, cmd] of Object.entries(cli.commands)) {
|
|
@@ -225,6 +417,382 @@ export function validateConfig(config) {
|
|
|
225
417
|
}
|
|
226
418
|
return diagnostics;
|
|
227
419
|
}
|
|
420
|
+
function validateArgScopeRefs(config, argScope, location, agent) {
|
|
421
|
+
const diagnostics = [];
|
|
422
|
+
if (!argScope)
|
|
423
|
+
return diagnostics;
|
|
424
|
+
const providerNames = new Set(Object.keys(config.providers));
|
|
425
|
+
for (const [dimensionName, valueSetNames] of Object.entries(argScope)) {
|
|
426
|
+
const dimension = config.arg_dimensions[dimensionName];
|
|
427
|
+
if (!dimension) {
|
|
428
|
+
diagnostics.push({
|
|
429
|
+
level: 'error',
|
|
430
|
+
code: 'unknown-arg-dimension-ref',
|
|
431
|
+
agent,
|
|
432
|
+
message: `${location} references unknown arg_dimension "${dimensionName}".`,
|
|
433
|
+
suggestion: `Add "${dimensionName}" to arg_dimensions, or check for typos.`,
|
|
434
|
+
});
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
for (const valueSetName of valueSetNames) {
|
|
438
|
+
if (!config.value_sets[valueSetName]) {
|
|
439
|
+
diagnostics.push({
|
|
440
|
+
level: 'error',
|
|
441
|
+
code: 'unknown-value-set-ref',
|
|
442
|
+
agent,
|
|
443
|
+
message: `${location}.${dimensionName} references unknown value_set "${valueSetName}".`,
|
|
444
|
+
suggestion: `Add "${valueSetName}" to value_sets, or check for typos.`,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
for (const toolName of Object.keys(dimension.bindings)) {
|
|
449
|
+
const providerName = toolName.split('/')[0];
|
|
450
|
+
if (providerName && !providerNames.has(providerName)) {
|
|
451
|
+
diagnostics.push({
|
|
452
|
+
level: 'warn',
|
|
453
|
+
agent,
|
|
454
|
+
message: `arg_dimensions.${dimensionName}.bindings references tool "${toolName}" from unknown provider "${providerName}".`,
|
|
455
|
+
suggestion: 'Declare the provider, remove the binding, or leave it only if this config fragment is merged with providers elsewhere.',
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return diagnostics;
|
|
461
|
+
}
|
|
462
|
+
function validateArgPolicyRefs(config, argPolicy, location, agent) {
|
|
463
|
+
const diagnostics = [];
|
|
464
|
+
if (!argPolicy)
|
|
465
|
+
return diagnostics;
|
|
466
|
+
for (const [toolName, toolPolicy] of Object.entries(argPolicy)) {
|
|
467
|
+
for (const [argName, constraints] of Object.entries(toolPolicy)) {
|
|
468
|
+
for (const constraint of constraints) {
|
|
469
|
+
const valueSetName = constraint.in ?? constraint.glob_in ?? constraint.each_in;
|
|
470
|
+
if (valueSetName && !config.value_sets[valueSetName]) {
|
|
471
|
+
diagnostics.push({
|
|
472
|
+
level: 'error',
|
|
473
|
+
code: 'unknown-value-set-ref',
|
|
474
|
+
agent,
|
|
475
|
+
message: `${location}.${toolName}.${argName} references unknown value_set "${valueSetName}".`,
|
|
476
|
+
suggestion: `Add "${valueSetName}" to value_sets, or check for typos.`,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return diagnostics;
|
|
483
|
+
}
|
|
484
|
+
function validateRawArgDimensionUsage(config) {
|
|
485
|
+
const diagnostics = [];
|
|
486
|
+
const usedDimensions = new Set();
|
|
487
|
+
for (const [dimensionName, dimension] of Object.entries(config.arg_dimensions)) {
|
|
488
|
+
if (Object.keys(dimension.bindings).length === 0) {
|
|
489
|
+
diagnostics.push({
|
|
490
|
+
level: 'warn',
|
|
491
|
+
message: `arg_dimensions.${dimensionName}.bindings is empty.`,
|
|
492
|
+
suggestion: 'Add at least one tool-to-argument binding, or remove the dimension so arg_scope cannot resolve to a no-op.',
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
for (const agentName of Object.keys(config.agents)) {
|
|
497
|
+
for (const dimensionName of collectAgentArgScopeDimensions(config, agentName)) {
|
|
498
|
+
usedDimensions.add(dimensionName);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
for (const dimensionName of Object.keys(config.arg_dimensions)) {
|
|
502
|
+
if (!usedDimensions.has(dimensionName)) {
|
|
503
|
+
diagnostics.push({
|
|
504
|
+
level: 'warn',
|
|
505
|
+
message: `arg_dimensions.${dimensionName} is not used by any scoped agent.`,
|
|
506
|
+
suggestion: 'Attach it through an agent arg_scope or through a profile that at least one agent extends.',
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return diagnostics;
|
|
511
|
+
}
|
|
512
|
+
function validateEffectiveArgRestrictions(rawConfig, resolvedConfig) {
|
|
513
|
+
const diagnostics = [];
|
|
514
|
+
for (const [agentName, resolvedAgent] of Object.entries(resolvedConfig.agents)) {
|
|
515
|
+
const sources = collectAgentArgRestrictionSources(rawConfig, agentName);
|
|
516
|
+
if (sources.length === 0)
|
|
517
|
+
continue;
|
|
518
|
+
if (countArgPolicyConstraints(resolvedAgent.arg_policy) === 0) {
|
|
519
|
+
diagnostics.push({
|
|
520
|
+
level: 'error',
|
|
521
|
+
agent: agentName,
|
|
522
|
+
message: `Agent declares arg_scope/arg_policy via ${sources.join(', ')} but resolves to zero effective argument constraints.`,
|
|
523
|
+
suggestion: 'Check that arg_scope dimensions have bindings and referenced value_sets, or remove the no-op restriction.',
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return diagnostics;
|
|
528
|
+
}
|
|
529
|
+
function validateYamlScalarFootguns(config) {
|
|
530
|
+
const diagnostics = [];
|
|
531
|
+
const stringMatchedValueSets = collectStringMatchedValueSets(config);
|
|
532
|
+
for (const [valueSetName, locations] of stringMatchedValueSets) {
|
|
533
|
+
const valueSet = config.value_sets[valueSetName];
|
|
534
|
+
if (!valueSet)
|
|
535
|
+
continue;
|
|
536
|
+
valueSet.values.forEach((value, index) => {
|
|
537
|
+
if (!isUnquotedStringFootgun(value))
|
|
538
|
+
return;
|
|
539
|
+
diagnostics.push({
|
|
540
|
+
level: 'warn',
|
|
541
|
+
message: `value_sets.${valueSetName}[${index}] value ${String(value)} looks like an unquoted string while used by ${locations.join(', ')}.`,
|
|
542
|
+
suggestion: `Quote it (${quoteSuggestion(value)}) if it should match string tool arguments.`,
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
for (const source of collectArgPolicySources(config)) {
|
|
547
|
+
for (const [toolName, toolPolicy] of Object.entries(source.policy ?? {})) {
|
|
548
|
+
for (const [argName, constraints] of Object.entries(toolPolicy)) {
|
|
549
|
+
for (const constraint of constraints) {
|
|
550
|
+
if (!usesStringNormalizer(constraint.normalize))
|
|
551
|
+
continue;
|
|
552
|
+
const values = constraint.allow ?? constraint.each_allow;
|
|
553
|
+
if (!values)
|
|
554
|
+
continue;
|
|
555
|
+
values.forEach((value, index) => {
|
|
556
|
+
if (!isUnquotedStringFootgun(value))
|
|
557
|
+
return;
|
|
558
|
+
diagnostics.push({
|
|
559
|
+
level: 'warn',
|
|
560
|
+
agent: source.agent,
|
|
561
|
+
message: `${source.location}.${toolName}.${argName}[${index}] value ${String(value)} looks like an unquoted string while used with normalize: ${constraint.normalize?.join(', ')}.`,
|
|
562
|
+
suggestion: `Quote it (${quoteSuggestion(value)}) so string normalization can apply before matching.`,
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return diagnostics;
|
|
570
|
+
}
|
|
571
|
+
function collectAgentArgScopeDimensions(config, agentName) {
|
|
572
|
+
const agent = config.agents[agentName];
|
|
573
|
+
if (!agent)
|
|
574
|
+
return [];
|
|
575
|
+
const dimensions = new Set();
|
|
576
|
+
const visitedProfiles = new Set();
|
|
577
|
+
function visitProfile(profileName) {
|
|
578
|
+
if (visitedProfiles.has(profileName))
|
|
579
|
+
return;
|
|
580
|
+
visitedProfiles.add(profileName);
|
|
581
|
+
const profile = config.profiles[profileName];
|
|
582
|
+
if (!profile)
|
|
583
|
+
return;
|
|
584
|
+
for (const parentName of profile.extends)
|
|
585
|
+
visitProfile(parentName);
|
|
586
|
+
for (const dimensionName of Object.keys(profile.arg_scope ?? {}))
|
|
587
|
+
dimensions.add(dimensionName);
|
|
588
|
+
}
|
|
589
|
+
for (const profileName of agent.extends)
|
|
590
|
+
visitProfile(profileName);
|
|
591
|
+
for (const dimensionName of Object.keys(agent.arg_scope ?? {}))
|
|
592
|
+
dimensions.add(dimensionName);
|
|
593
|
+
return Array.from(dimensions);
|
|
594
|
+
}
|
|
595
|
+
function collectAgentArgRestrictionSources(config, agentName) {
|
|
596
|
+
const agent = config.agents[agentName];
|
|
597
|
+
if (!agent)
|
|
598
|
+
return [];
|
|
599
|
+
const sources = [];
|
|
600
|
+
const visitedProfiles = new Set();
|
|
601
|
+
function visitProfile(profileName) {
|
|
602
|
+
if (visitedProfiles.has(profileName))
|
|
603
|
+
return;
|
|
604
|
+
visitedProfiles.add(profileName);
|
|
605
|
+
const profile = config.profiles[profileName];
|
|
606
|
+
if (!profile)
|
|
607
|
+
return;
|
|
608
|
+
for (const parentName of profile.extends)
|
|
609
|
+
visitProfile(parentName);
|
|
610
|
+
if (profile.arg_scope)
|
|
611
|
+
sources.push(`profiles.${profileName}.arg_scope`);
|
|
612
|
+
if (profile.arg_policy)
|
|
613
|
+
sources.push(`profiles.${profileName}.arg_policy`);
|
|
614
|
+
}
|
|
615
|
+
for (const profileName of agent.extends)
|
|
616
|
+
visitProfile(profileName);
|
|
617
|
+
if (agent.arg_scope)
|
|
618
|
+
sources.push(`agents.${agentName}.arg_scope`);
|
|
619
|
+
if (agent.arg_policy)
|
|
620
|
+
sources.push(`agents.${agentName}.arg_policy`);
|
|
621
|
+
return sources;
|
|
622
|
+
}
|
|
623
|
+
function countArgPolicyConstraints(argPolicy) {
|
|
624
|
+
let count = 0;
|
|
625
|
+
for (const toolPolicy of Object.values(argPolicy ?? {})) {
|
|
626
|
+
for (const constraints of Object.values(toolPolicy)) {
|
|
627
|
+
count += constraints.length;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return count;
|
|
631
|
+
}
|
|
632
|
+
function collectStringMatchedValueSets(config) {
|
|
633
|
+
const valueSets = new Map();
|
|
634
|
+
function add(valueSetName, location) {
|
|
635
|
+
if (!valueSetName)
|
|
636
|
+
return;
|
|
637
|
+
const locations = valueSets.get(valueSetName) ?? [];
|
|
638
|
+
if (!locations.includes(location))
|
|
639
|
+
locations.push(location);
|
|
640
|
+
valueSets.set(valueSetName, locations);
|
|
641
|
+
}
|
|
642
|
+
for (const [agentName, agent] of Object.entries(config.agents)) {
|
|
643
|
+
collectArgScopeValueSets(config, agent.arg_scope, `agents.${agentName}.arg_scope`, add);
|
|
644
|
+
}
|
|
645
|
+
for (const [profileName, profile] of Object.entries(config.profiles)) {
|
|
646
|
+
collectArgScopeValueSets(config, profile.arg_scope, `profiles.${profileName}.arg_scope`, add);
|
|
647
|
+
}
|
|
648
|
+
for (const source of collectArgPolicySources(config)) {
|
|
649
|
+
for (const [toolName, toolPolicy] of Object.entries(source.policy ?? {})) {
|
|
650
|
+
for (const [argName, constraints] of Object.entries(toolPolicy)) {
|
|
651
|
+
for (const constraint of constraints) {
|
|
652
|
+
add(constraint.in, `${source.location}.${toolName}.${argName}.in`);
|
|
653
|
+
add(constraint.glob_in, `${source.location}.${toolName}.${argName}.glob_in`);
|
|
654
|
+
if (usesStringNormalizer(constraint.normalize)) {
|
|
655
|
+
add(constraint.each_in, `${source.location}.${toolName}.${argName}.each_in`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return valueSets;
|
|
662
|
+
}
|
|
663
|
+
function collectArgScopeValueSets(config, argScope, location, add) {
|
|
664
|
+
for (const [dimensionName, valueSetNames] of Object.entries(argScope ?? {})) {
|
|
665
|
+
const dimension = config.arg_dimensions[dimensionName];
|
|
666
|
+
const stringMatched = dimension?.match === 'in' ||
|
|
667
|
+
dimension?.match === 'glob_in' ||
|
|
668
|
+
usesStringNormalizer(dimension?.normalize);
|
|
669
|
+
if (!stringMatched)
|
|
670
|
+
continue;
|
|
671
|
+
for (const valueSetName of valueSetNames) {
|
|
672
|
+
add(valueSetName, `${location}.${dimensionName}`);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function collectArgPolicySources(config) {
|
|
677
|
+
const sources = [];
|
|
678
|
+
for (const [agentName, agent] of Object.entries(config.agents)) {
|
|
679
|
+
sources.push({
|
|
680
|
+
location: `agents.${agentName}.arg_policy`,
|
|
681
|
+
agent: agentName,
|
|
682
|
+
policy: agent.arg_policy,
|
|
683
|
+
});
|
|
684
|
+
for (const [toolName, override] of Object.entries(agent.tool_overrides)) {
|
|
685
|
+
if (!override.args)
|
|
686
|
+
continue;
|
|
687
|
+
sources.push({
|
|
688
|
+
location: `agents.${agentName}.tool_overrides.${toolName}.args`,
|
|
689
|
+
agent: agentName,
|
|
690
|
+
policy: { [toolName]: override.args },
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
for (const [profileName, profile] of Object.entries(config.profiles)) {
|
|
695
|
+
sources.push({ location: `profiles.${profileName}.arg_policy`, policy: profile.arg_policy });
|
|
696
|
+
}
|
|
697
|
+
return sources;
|
|
698
|
+
}
|
|
699
|
+
function usesStringNormalizer(normalizers) {
|
|
700
|
+
return !!normalizers?.some((normalizer) => ['phone', 'email', 'lower', 'trim'].includes(normalizer));
|
|
701
|
+
}
|
|
702
|
+
function isUnquotedStringFootgun(value) {
|
|
703
|
+
return typeof value === 'number' || typeof value === 'boolean';
|
|
704
|
+
}
|
|
705
|
+
function quoteSuggestion(value) {
|
|
706
|
+
if (typeof value === 'number' && Number.isInteger(value) && value > 1_000_000_000) {
|
|
707
|
+
return `"+${value}"`;
|
|
708
|
+
}
|
|
709
|
+
return `"${String(value)}"`;
|
|
710
|
+
}
|
|
711
|
+
function dedupeDiagnostics(diagnostics) {
|
|
712
|
+
const seen = new Set();
|
|
713
|
+
const result = [];
|
|
714
|
+
for (const diagnostic of diagnostics) {
|
|
715
|
+
const key = `${diagnostic.level}\0${diagnostic.agent ?? ''}\0${diagnostic.message}`;
|
|
716
|
+
if (seen.has(key))
|
|
717
|
+
continue;
|
|
718
|
+
seen.add(key);
|
|
719
|
+
result.push(diagnostic);
|
|
720
|
+
}
|
|
721
|
+
return result;
|
|
722
|
+
}
|
|
723
|
+
// Unknown-key detection is single-sourced from the zod schema: every config object is `.strict()`,
|
|
724
|
+
// so zod already rejects unrecognized keys. We run one structural (no-env) parse purely to harvest
|
|
725
|
+
// those `unrecognized_keys` issues and render them with friendly, path-aware messages. Adding a new
|
|
726
|
+
// config key therefore requires changing ONLY the schema — no parallel key list to keep in sync.
|
|
727
|
+
function findUnknownKeyDiagnostics(parsed) {
|
|
728
|
+
// resolveEnvVars=false so `${VAR}` placeholders pass through untouched — this validates shape
|
|
729
|
+
// without needing any secrets and never throws on a missing env var.
|
|
730
|
+
const structural = withEnvVarResolution(false, () => GatewayConfig.safeParse(parsed));
|
|
731
|
+
if (structural.success)
|
|
732
|
+
return [];
|
|
733
|
+
const found = [];
|
|
734
|
+
collectUnrecognizedKeys(structural.error, found);
|
|
735
|
+
const seen = new Set();
|
|
736
|
+
const diagnostics = [];
|
|
737
|
+
for (const { path, key } of found) {
|
|
738
|
+
const id = [...path, key].join('.');
|
|
739
|
+
if (seen.has(id))
|
|
740
|
+
continue;
|
|
741
|
+
seen.add(id);
|
|
742
|
+
diagnostics.push({
|
|
743
|
+
level: 'error',
|
|
744
|
+
message: unknownKeyMessage(key, path),
|
|
745
|
+
suggestion: unknownKeySuggestion(key, path),
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
return diagnostics;
|
|
749
|
+
}
|
|
750
|
+
// Recurse into `invalid_union` errors (e.g. providers, which is a z.union): an unknown key on a
|
|
751
|
+
// union member is reported inside that branch's nested error, not at the top level.
|
|
752
|
+
function collectUnrecognizedKeys(error, out) {
|
|
753
|
+
for (const issue of error.issues) {
|
|
754
|
+
if (issue.code === 'unrecognized_keys') {
|
|
755
|
+
const path = issue.path.map(String);
|
|
756
|
+
for (const key of issue.keys)
|
|
757
|
+
out.push({ path, key });
|
|
758
|
+
}
|
|
759
|
+
else if (issue.code === 'invalid_union') {
|
|
760
|
+
for (const unionError of issue.unionErrors)
|
|
761
|
+
collectUnrecognizedKeys(unionError, out);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function unknownKeyMessage(key, path) {
|
|
766
|
+
if (path[0] === 'profiles' && path.length === 2) {
|
|
767
|
+
return `Unrecognized key "${key}" in profile "${path[1]}".`;
|
|
768
|
+
}
|
|
769
|
+
if (path[0] === 'agents' && path.length === 2) {
|
|
770
|
+
return `Unrecognized key "${key}" in agent "${path[1]}".`;
|
|
771
|
+
}
|
|
772
|
+
return `Unknown config key "${[...path, key].join('.')}".`;
|
|
773
|
+
}
|
|
774
|
+
function unknownKeySuggestion(key, path) {
|
|
775
|
+
if (key === 'scope' && (path[0] === 'agents' || path[0] === 'profiles')) {
|
|
776
|
+
return 'Did you mean "arg_scope"?';
|
|
777
|
+
}
|
|
778
|
+
if (key === 'mcps')
|
|
779
|
+
return 'Use "providers" to declare MCP servers and builtins.';
|
|
780
|
+
if (key === 'hitl')
|
|
781
|
+
return 'Use "ask" for agent tool routing or "approvals" for approval providers.';
|
|
782
|
+
return undefined;
|
|
783
|
+
}
|
|
784
|
+
function isLoopbackHost(host) {
|
|
785
|
+
const normalized = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
|
|
786
|
+
if (normalized === 'localhost')
|
|
787
|
+
return true;
|
|
788
|
+
const ipVersion = isIP(normalized);
|
|
789
|
+
if (ipVersion === 6)
|
|
790
|
+
return normalized === '::1';
|
|
791
|
+
if (ipVersion !== 4)
|
|
792
|
+
return false;
|
|
793
|
+
const firstOctet = Number(normalized.split('.')[0]);
|
|
794
|
+
return firstOctet === 127;
|
|
795
|
+
}
|
|
228
796
|
/** Check if two glob patterns could match the same tool name */
|
|
229
797
|
function patternsOverlap(a, b) {
|
|
230
798
|
// If either is a wildcard that covers the other's namespace
|