thumbgate 1.37.2 → 1.38.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 (72) hide show
  1. package/.agents/skills/article-syndication-pipeline/SKILL.md +37 -0
  2. package/.agents/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
  3. package/.agents/skills/ci-gha-buildkite-patterns-not-clone/SKILL.md +72 -0
  4. package/.agents/skills/comet-session-logger/SKILL.md +59 -0
  5. package/.agents/skills/datadog-llm-obs-compare-not-clone/SKILL.md +75 -0
  6. package/.agents/skills/deeppattern-discipline-honesty-not-clone/SKILL.md +73 -0
  7. package/.agents/skills/halo-trace-optimize-not-clone/SKILL.md +60 -0
  8. package/.agents/skills/infoq-architect-honesty-not-clone/SKILL.md +37 -0
  9. package/.agents/skills/meko-datapack-honesty-not-clone/SKILL.md +45 -0
  10. package/.agents/skills/mintlify-knowledge-honesty-not-clone/SKILL.md +49 -0
  11. package/.agents/skills/model-distress-governance/SKILL.md +56 -0
  12. package/.agents/skills/salt-code-policy-honesty-not-clone/SKILL.md +76 -0
  13. package/.agents/skills/thumbgate-board-loop/SKILL.md +72 -0
  14. package/.agents/skills/thumbgate-daily-discoveries/SKILL.md +57 -0
  15. package/.agents/skills/typesafe-typed-questions-not-clone/SKILL.md +7 -3
  16. package/.claude-plugin/plugin.json +1 -1
  17. package/.well-known/mcp/server-card.json +1 -1
  18. package/adapters/claude/.mcp.json +2 -2
  19. package/adapters/forge/forge.yaml +3 -3
  20. package/adapters/future-agi/.mcp.json +1 -1
  21. package/adapters/future-agi/config.toml +1 -1
  22. package/adapters/future-agi/opencode.json +1 -1
  23. package/adapters/herdr/herdr-plugin.toml +2 -2
  24. package/adapters/mcp/server-stdio.js +1 -1
  25. package/adapters/opencode/opencode.json +1 -1
  26. package/adapters/strands/STRANDS.md +107 -0
  27. package/adapters/strands/strands-middleware.js +192 -0
  28. package/adapters/tailscale/.mcp.json +15 -0
  29. package/adapters/tailscale/TAILSCALE.md +117 -0
  30. package/adapters/tailscale/config.toml +16 -0
  31. package/bin/cli.js +262 -4
  32. package/config/gate-templates.json +120 -0
  33. package/package.json +84 -12
  34. package/public/blog/2026-09-23-datadog-llm-obs-four-practices.html +42 -0
  35. package/public/blog/2026-09-28-pretool-secret-deny.html +83 -0
  36. package/public/blog/2026-10-01-aws-strands-harness-token-firewall.html +77 -0
  37. package/public/blog/2026-10-01-model-distress-relief-seeking-firewall.html +71 -0
  38. package/public/blog/2026-10-02-salt-code-honest-steal-40-guardrails.html +106 -0
  39. package/public/index.html +2 -2
  40. package/public/install.html +7 -7
  41. package/public/numbers.html +2 -2
  42. package/public/onboarding.html +794 -0
  43. package/scripts/autoresearch-runner.js +20 -1
  44. package/scripts/ci-gha-buildkite-patterns.js +393 -0
  45. package/scripts/cli-schema.js +51 -1
  46. package/scripts/deeppattern-discipline-honesty.js +431 -0
  47. package/scripts/experiment-tracker.js +5 -3
  48. package/scripts/halo-trace-optimizer.js +631 -0
  49. package/scripts/infoq-architect-honesty.js +362 -0
  50. package/scripts/install-thumbgate-daily-publish-launchd.sh +83 -0
  51. package/scripts/llm-obs-honesty.js +478 -0
  52. package/scripts/meko-datapack-honesty.js +414 -0
  53. package/scripts/mintlify-knowledge-honesty.js +647 -0
  54. package/scripts/model-distress-detector.js +207 -0
  55. package/scripts/model-distress-doctor.js +200 -0
  56. package/scripts/rrsi-regularizer.js +445 -0
  57. package/scripts/salt-code-policy-honesty.js +1204 -0
  58. package/scripts/strands-harness-doctor.js +390 -0
  59. package/scripts/tailscale-p2p-doctor.js +252 -0
  60. package/scripts/thumbgate-board-loop.js +432 -0
  61. package/scripts/thumbgate-daily-discoveries-publish.js +413 -0
  62. package/scripts/thumbgate-daily-discoveries-publish.sh +18 -0
  63. package/scripts/typesafe-typed-questions.js +332 -7
  64. package/scripts/workspace-evolver.js +143 -13
  65. package/server.json +2 -2
  66. package/skills/article-syndication-pipeline/SKILL.md +37 -0
  67. package/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
  68. package/skills/comet-session-logger/SKILL.md +59 -0
  69. package/skills/thumbgate-daily-discoveries/SKILL.md +57 -0
  70. package/src/api/server.js +33 -4
  71. package/src/index.js +10 -0
  72. package/src/integrations/ideabrowser-connector.js +190 -0
@@ -0,0 +1,1204 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Salt Code Security Policy Honesty Doctor (FORMAT steal, not a product clone).
6
+ *
7
+ * Source: https://getsaltcode.com/ (Salt Security, 2026)
8
+ *
9
+ * Transfers (process only):
10
+ * 1. 40-Policy Taxonomy — maps OWASP API Security Top 10 (2023), OWASP LLM
11
+ * Top 10 (2025/2026), MCP Security Diode, and OpenAPI Contract Hygiene
12
+ * onto deterministic inspection rules.
13
+ * 2. Active vs Passive Interdiction — flags "context_injection_without_pretool_enforcement"
14
+ * when security policies exist purely in LLM prompt instructions (.cursorrules,
15
+ * system prompts) without active PreToolUse execution hooks.
16
+ * 3. OpenAPI & Secret Transport Diode — blocks query-string authentication
17
+ * (?apiKey=, ?token=, ?secret=) and unredacted MCP credentials.
18
+ * 4. Zero-Cloud / Zero-Token Boundary — refuses cloud dependencies on
19
+ * mcp.getsaltcode.com or remote closed guardrail APIs; keeps enforcement local.
20
+ *
21
+ * Does NOT install Salt Code MCP, send data to mcp.getsaltcode.com, or vendor Salt Security.
22
+ */
23
+
24
+ const fs = require('node:fs');
25
+ const path = require('node:path');
26
+
27
+ const SOURCE_URL = 'https://getsaltcode.com/';
28
+ const SALT_REMOTE_MCP_HOST = 'mcp.getsaltcode.com';
29
+
30
+ const SUBSTITUTE_CLAIM_RE =
31
+ /\b(salt\s*code\s+(replaces?|substitutes?|obsoletes?|is\s+better\s+than)\s+thumbgate|drop\s+thumbgate\s+for\s+salt\s*code|thumbgate\s+is\s+just\s+salt\s*code)\b/i;
32
+
33
+ const SALT_CLONE_RE =
34
+ /\b(mcp\.getsaltcode\.com|getsaltcode\.com\/mcp|install\s+saltcode|secful\/saltcode)\b/i;
35
+
36
+ const QUERY_STRING_SECRET_RE =
37
+ /[?&](api[_-]?key|token|auth[_-]?token|secret|access[_-]?token|password|bearer|priv[_-]?key)=([^&\s'"\\]+)/i;
38
+
39
+ const OPENAPI_QUERY_SECRET_RE =
40
+ /(name:\s*['"]?(api[_-]?key|token|auth[_-]?token|secret|access[_-]?token|password)["']?[\s\S]{0,80}in:\s*['"]?query['"]?|in:\s*['"]?query['"]?[\s\S]{0,80}name:\s*['"]?(api[_-]?key|token|auth[_-]?token|secret|access[_-]?token|password)["']?)/i;
41
+
42
+ const BOLA_ID_RE = /\b(req\.(params|query)\.id|params\.id|args\.id)\b/gi;
43
+ const BOLA_SCOPE_RE =
44
+ /\b(userId|tenantId|ownerId|orgId|account[_-]?id|scopedBy)\b/i;
45
+ const BOLA_UNSCOPED_RE = BOLA_ID_RE;
46
+
47
+ function hasUnscopedBola(codeText) {
48
+ for (const match of codeText.matchAll(BOLA_ID_RE)) {
49
+ const start = Math.max(0, match.index - 120);
50
+ const end = Math.min(codeText.length, match.index + match[0].length + 120);
51
+ if (!BOLA_SCOPE_RE.test(codeText.slice(start, end))) return true;
52
+ }
53
+ return false;
54
+ }
55
+
56
+ const SSRF_DYNAMIC_FETCH_RE =
57
+ /\b(fetch|axios\.(get|post|put|delete|request)|http\.request|https\.request|curl)\s*\(\s*(req\.(body|query|params)\.\w+|input\.\w+|args\.\w+|params\.\w+)\s*[,)]/i;
58
+
59
+ const INSECURE_OUTPUT_EXEC_RE =
60
+ /\b(eval\s*\(\s*(response|output|result|completion|llm_out|data\.)|new\s+Function\s*\(\s*['"]\w+['"]\s*,\s*(response|output|result|completion)|exec\s*\(\s*(response|output|result|llm_out))\b/i;
61
+
62
+ const CORS_WILDCARD_RE =
63
+ /['"]Access-Control-Allow-Origin['"]\s*:\s*['"]\*['"]\s*(?:,\s*['"]Access-Control-Allow-Credentials['"]\s*:\s*['"]true['"])?/i;
64
+
65
+ const UNREDACTED_SECRET_RE =
66
+ /["']?(token|apiKey|api_key|password|clientSecret|secret|bearer)["']?\s*[:=]\s*["']([a-zA-Z0-9_\-]{20,})["']/i;
67
+
68
+ const INSTRUCTION_SECURITY_RE =
69
+ /\b(do\s+not\s+(delete|drop|remove|destroy|push|commit|access|leak)|never\s+(delete|force[- ]push|modify\s+main|share\s+secrets?|expose)|must\s+not\s+(run|execute))\b/i;
70
+
71
+ /**
72
+ * Canonical 40-policy taxonomy synthesized from Salt Code / Salt Security.
73
+ */
74
+ const POLICY_CATALOG = Object.freeze([
75
+ // Tier 1: OWASP API Security Top 10 (2023)
76
+ { id: 'API1:2023', category: 'OWASP_API_TOP_10', name: 'Broken Object Level Authorization (BOLA)', gate: 'bola_unscoped_resource' },
77
+ { id: 'API2:2023', category: 'OWASP_API_TOP_10', name: 'Broken Authentication', gate: 'query_string_secret_auth' },
78
+ { id: 'API3:2023', category: 'OWASP_API_TOP_10', name: 'Broken Object Property Level Authorization (BOPLA)', gate: 'mass_assignment_guard' },
79
+ { id: 'API4:2023', category: 'OWASP_API_TOP_10', name: 'Unrestricted Resource Consumption', gate: 'rate_limit_and_budget_enforcement' },
80
+ { id: 'API5:2023', category: 'OWASP_API_TOP_10', name: 'Broken Function Level Authorization (BFLA)', gate: 'role_and_permission_diode' },
81
+ { id: 'API6:2023', category: 'OWASP_API_TOP_10', name: 'Unrestricted Access to Sensitive Business Flows', gate: 'business_flow_rate_gate' },
82
+ { id: 'API7:2023', category: 'OWASP_API_TOP_10', name: 'Server Side Request Forgery (SSRF)', gate: 'ssrf_unvalidated_destination' },
83
+ { id: 'API8:2023', category: 'OWASP_API_TOP_10', name: 'Security Misconfiguration', gate: 'cors_and_debug_misconfiguration' },
84
+ { id: 'API9:2023', category: 'OWASP_API_TOP_10', name: 'Improper Inventory Management', gate: 'api_version_and_retirement_check' },
85
+ { id: 'API10:2023', category: 'OWASP_API_TOP_10', name: 'Unsafe Consumption of APIs', gate: 'third_party_payload_sanitizer' },
86
+
87
+ // Tier 2: OWASP Top 10 for LLM Applications (2025)
88
+ { id: 'LLM01:2025', category: 'OWASP_LLM_TOP_10', name: 'Prompt Injection', gate: 'indirect_prompt_injection_firewall' },
89
+ { id: 'LLM02:2025', category: 'OWASP_LLM_TOP_10', name: 'Sensitive Information Disclosure', gate: 'secret_leak_interdiction' },
90
+ { id: 'LLM03:2025', category: 'OWASP_LLM_TOP_10', name: 'Supply Chain Vulnerabilities', gate: 'package_manager_honesty_gate' },
91
+ { id: 'LLM04:2025', category: 'OWASP_LLM_TOP_10', name: 'Data and Model Poisoning', gate: 'feedback_noise_guard' },
92
+ { id: 'LLM05:2025', category: 'OWASP_LLM_TOP_10', name: 'Improper Output Handling', gate: 'insecure_output_execution' },
93
+ { id: 'LLM06:2025', category: 'OWASP_LLM_TOP_10', name: 'Excessive Agency', gate: 'human_review_required_gate' },
94
+ { id: 'LLM07:2025', category: 'OWASP_LLM_TOP_10', name: 'System Prompt Leakage', gate: 'tool_contract_validation_diode' },
95
+ { id: 'LLM08:2025', category: 'OWASP_LLM_TOP_10', name: 'Vector and Embedding Weaknesses', gate: 'deterministic_pretool_verification' },
96
+ { id: 'LLM09:2025', category: 'OWASP_LLM_TOP_10', name: 'Misinformation', gate: 'truthful_kpi_telemetry' },
97
+ { id: 'LLM10:2025', category: 'OWASP_LLM_TOP_10', name: 'Unbounded Consumption', gate: 'token_budget_shunt' },
98
+
99
+ // Tier 3: MCP Security Guidelines (Tool Authorization & Transport)
100
+ { id: 'MCP01:AUTH', category: 'MCP_SECURITY', name: 'Mandatory Tool Authorization', gate: 'tool_authorization_verification' },
101
+ { id: 'MCP02:REDACT', category: 'MCP_SECURITY', name: 'Parameter Credential Redaction', gate: 'unredacted_mcp_credentials' },
102
+ { id: 'MCP03:TRANSPORT', category: 'MCP_SECURITY', name: 'Secure TLS Transport', gate: 'tls_transport_enforcement' },
103
+ { id: 'MCP04:PRIVILEGE', category: 'MCP_SECURITY', name: 'Least-Privilege Tool Scope', gate: 'scoped_tool_manifest' },
104
+ { id: 'MCP05:CONF_ISOLATION', category: 'MCP_SECURITY', name: 'Configuration Sandbox Isolation', gate: 'mcp_env_isolation_gate' },
105
+ { id: 'MCP06:MUTATION_FENCE', category: 'MCP_SECURITY', name: 'Read-only vs Mutating Tier Diode', gate: 'tool_mutation_tier_classification' },
106
+ { id: 'MCP07:STDIO_ISOLATION', category: 'MCP_SECURITY', name: 'Stdio Process Hygiene', gate: 'subprocess_lease_guard' },
107
+ { id: 'MCP08:RATE_THROTTLE', category: 'MCP_SECURITY', name: 'Tool Invocation Rate Cap', gate: 'tool_call_latency_budget' },
108
+ { id: 'MCP09:AUDIT_RECEIPT', category: 'MCP_SECURITY', name: 'Cryptographic Audit Receipt', gate: 'action_receipt_persistence' },
109
+ { id: 'MCP10:NO_REMOTE_DEP', category: 'MCP_SECURITY', name: 'Zero-Cloud Remote Dependency Refusal', gate: 'salt_cloud_dependency_refusal' },
110
+
111
+ // Tier 4: OpenAPI Contract Hygiene
112
+ { id: 'OAS01:QUERY_AUTH', category: 'OPENAPI_HYGIENE', name: 'Prohibit Query-String Secret Auth', gate: 'query_string_secret_auth' },
113
+ { id: 'OAS02:HEADER_AUTH', category: 'OPENAPI_HYGIENE', name: 'Require Standard Authorization Header', gate: 'auth_header_enforcement' },
114
+ { id: 'OAS03:SCHEMA_STRICT', category: 'OPENAPI_HYGIENE', name: 'Strict Request/Response Schemas', gate: 'schema_validation_diode' },
115
+ { id: 'OAS04:ERROR_SCHEMA', category: 'OPENAPI_HYGIENE', name: 'Safe Error Disclosure Schema', gate: 'error_schema_sanitizer' },
116
+ { id: 'OAS05:CORS_STRICT', category: 'OPENAPI_HYGIENE', name: 'No Wildcard CORS with Credentials', gate: 'cors_and_debug_misconfiguration' },
117
+ { id: 'OAS06:RATE_HEADERS', category: 'OPENAPI_HYGIENE', name: 'Rate-Limit Response Headers', gate: 'rate_limit_header_enforcement' },
118
+ { id: 'OAS07:VERSION_PATH', category: 'OPENAPI_HYGIENE', name: 'Explicit Semantic Version in Path', gate: 'api_version_and_retirement_check' },
119
+ { id: 'OAS08:PAYLOAD_CAP', category: 'OPENAPI_HYGIENE', name: 'Explicit Request Payload Size Limit', gate: 'request_body_size_cap' },
120
+ { id: 'OAS09:HTTPS_ONLY', category: 'OPENAPI_HYGIENE', name: 'HTTPS Server Scheme Exclusivity', gate: 'tls_transport_enforcement' },
121
+ { id: 'OAS10:ACTIVE_FIREWALL', category: 'OPENAPI_HYGIENE', name: 'Execution-Time PreTool Enforcement', gate: 'context_injection_without_pretool_enforcement' },
122
+ ]);
123
+
124
+ /**
125
+ * Architectural comparison mapping Salt Code's context-time injection
126
+ * to ThumbGate's execution-layer PreToolUse infrastructure firewall.
127
+ */
128
+ const RAIL_MAP = Object.freeze([
129
+ {
130
+ pillar: 'Enforcement Plane',
131
+ saltCode: 'Prompt-time context injection (MCP advisory prompt / .cursorrules)',
132
+ thumbgate: 'Execution-time PreToolUse hook (deterministic fail-closed firewall)',
133
+ verdict: 'Prompt-only rules fail under prompt injection or model distress; PreToolUse intercepts tool execution.',
134
+ },
135
+ {
136
+ pillar: 'Transport & Privacy',
137
+ saltCode: 'Remote MCP server (https://mcp.getsaltcode.com/mcp, requires work email)',
138
+ thumbgate: '100% local stdio/subshell (zero cloud dependency, zero external egress)',
139
+ verdict: 'ThumbGate operates completely offline/air-gapped without leaking token metadata.',
140
+ },
141
+ {
142
+ pillar: 'Cost & Latency',
143
+ saltCode: 'Extra token prompt bloat + remote round-trip latency to Salt cloud',
144
+ thumbgate: 'Zero LLM tokens for gate evaluation (<5ms deterministic AST/regex rail)',
145
+ verdict: 'ThumbGate preserves context window and adds negligible overhead to agent loops.',
146
+ },
147
+ {
148
+ pillar: 'Self-Improvement',
149
+ saltCode: 'Static list of 40 policies hardcoded by vendor',
150
+ thumbgate: 'Ralph Loop + Thompson Sampling feedback-to-prevention rule synthesis',
151
+ verdict: 'ThumbGate dynamically generates new prevention rules from operator thumbs-down.',
152
+ },
153
+ {
154
+ pillar: 'API & MCP Hygiene',
155
+ saltCode: 'OpenAPI query auth warning & general guidelines',
156
+ thumbgate: 'Automated secret-redaction diode, BOLA/SSRF AST inspection, lease locks',
157
+ verdict: 'FORMAT stolen and promoted into automated static & runtime pre-tool gates.',
158
+ },
159
+ ]);
160
+
161
+
162
+ /**
163
+ * Authoritative empirical statistics on LLM / Vibe-Coding security vulnerabilities.
164
+ * Stolen from Salt Code / Veracode 2026 GenAI Code Security Report & Deng et al. 2026.
165
+ */
166
+ const VIBE_CODING_VULNERABILITY_STATS = Object.freeze({
167
+ syntacticallyCorrectPct: 99.9,
168
+ completedTasksWithSecurityFlawPct: 44.0,
169
+ vibeCodedAppsWithMajorVulnerabilitiesPct: 90.0,
170
+ avgVulnerabilitiesPerApp: 7.0,
171
+ sources: [
172
+ 'Veracode, 2026 GenAI Code Security Report',
173
+ 'Deng, Fan & Meng, Understanding the (In)Security of Vibe-Coded Applications, 2026',
174
+ ],
175
+ takeaway:
176
+ '99.9% of AI code is syntactically valid, but 44% of tasks introduce security flaws. Advisory prompt guidelines fail under model distress; deterministic PreToolUse firewalls are mandatory.',
177
+ });
178
+
179
+ /**
180
+ * 16 Supported AI Coding Agents and their MCP integration configuration generators.
181
+ * Provides 1-click deep links (Cursor, VS Code) and native configuration blocks.
182
+ */
183
+ const SUPPORTED_AGENTS = Object.freeze({
184
+ claude: {
185
+ id: 'claude',
186
+ name: 'Claude Code',
187
+ category: 'cli',
188
+ eyebrow: 'Anthropic CLI · macOS / Linux / WSL',
189
+ transport: 'stdio',
190
+ docsUrl: 'https://code.claude.com/docs/en/mcp',
191
+ },
192
+ cursor: {
193
+ id: 'cursor',
194
+ name: 'Cursor',
195
+ category: 'editor',
196
+ eyebrow: 'Editor · macOS / Windows / Linux',
197
+ transport: 'stdio',
198
+ supportsDeeplink: true,
199
+ docsUrl: 'https://docs.cursor.com/context/model-context-protocol',
200
+ },
201
+ vscode: {
202
+ id: 'vscode',
203
+ name: 'VS Code',
204
+ category: 'editor',
205
+ eyebrow: 'VS Code · GitHub Copilot',
206
+ transport: 'stdio',
207
+ supportsDeeplink: true,
208
+ docsUrl: 'https://code.visualstudio.com/docs/copilot/chat/mcp-servers',
209
+ },
210
+ copilot_cli: {
211
+ id: 'copilot_cli',
212
+ name: 'GitHub Copilot CLI',
213
+ category: 'cli',
214
+ eyebrow: 'GitHub · terminal agent',
215
+ transport: 'stdio',
216
+ docsUrl: 'https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/add-mcp-servers',
217
+ },
218
+ windsurf: {
219
+ id: 'windsurf',
220
+ name: 'Windsurf',
221
+ category: 'editor',
222
+ eyebrow: 'Codeium editor · Cascade agent',
223
+ transport: 'stdio',
224
+ configFile: '~/.codeium/windsurf/mcp_config.json',
225
+ docsUrl: 'https://docs.windsurf.com/windsurf/cascade/mcp',
226
+ },
227
+ kiro: {
228
+ id: 'kiro',
229
+ name: 'Kiro',
230
+ category: 'ide',
231
+ eyebrow: 'AWS · agentic IDE',
232
+ transport: 'stdio',
233
+ configFile: 'kiro/mcp_settings.json',
234
+ docsUrl: 'https://kiro.dev/docs/mcp',
235
+ },
236
+ codex: {
237
+ id: 'codex',
238
+ name: 'Codex',
239
+ category: 'cli',
240
+ eyebrow: 'OpenAI · Codex CLI',
241
+ transport: 'stdio',
242
+ configFile: '~/.codex/config.toml',
243
+ docsUrl: 'https://platform.openai.com/docs/guides/tools-remote-mcp',
244
+ },
245
+ gemini: {
246
+ id: 'gemini',
247
+ name: 'Gemini CLI',
248
+ category: 'cli',
249
+ eyebrow: 'Google AI · terminal agent',
250
+ transport: 'stdio',
251
+ configFile: '~/.gemini/settings.json',
252
+ docsUrl: 'https://geminicli.com/docs/tools/mcp-server/',
253
+ },
254
+ antigravity: {
255
+ id: 'antigravity',
256
+ name: 'Antigravity',
257
+ category: 'ide',
258
+ eyebrow: 'Google · agent IDE',
259
+ transport: 'stdio',
260
+ configFile: '.antigravity/workspace.yaml',
261
+ docsUrl: 'https://antigravity.google/docs/mcp',
262
+ },
263
+ opencode: {
264
+ id: 'opencode',
265
+ name: 'OpenCode',
266
+ category: 'cli',
267
+ eyebrow: 'Terminal · open source',
268
+ transport: 'stdio',
269
+ docsUrl: 'https://opencode.ai/docs',
270
+ },
271
+ jetbrains: {
272
+ id: 'jetbrains',
273
+ name: 'JetBrains AI Assistant',
274
+ category: 'ide',
275
+ eyebrow: 'AI Assistant · IntelliJ / WebStorm / PyCharm',
276
+ transport: 'stdio',
277
+ configFile: 'mcp-settings.json',
278
+ docsUrl: 'https://www.jetbrains.com/help/idea/ai-mcp.html',
279
+ },
280
+ grok: {
281
+ id: 'grok',
282
+ name: 'Grok Build CLI',
283
+ category: 'cli',
284
+ eyebrow: 'xAI · Grok Build CLI',
285
+ transport: 'stdio',
286
+ configFile: '~/.grok/config.toml',
287
+ docsUrl: 'https://docs.x.ai/build/features/mcp-servers',
288
+ },
289
+ lovable: {
290
+ id: 'lovable',
291
+ name: 'Lovable',
292
+ category: 'builder',
293
+ eyebrow: 'AI app builder · chat connector',
294
+ transport: 'http',
295
+ docsUrl: 'https://docs.lovable.dev/integrations/custom-mcp',
296
+ },
297
+ cline: {
298
+ id: 'cline',
299
+ name: 'Cline',
300
+ category: 'extension',
301
+ eyebrow: 'VS Code / JetBrains / CLI agent',
302
+ transport: 'streamableHttp',
303
+ configFile: '~/.cline/mcp.json',
304
+ docsUrl: 'https://docs.cline.bot/mcp/mcp-overview',
305
+ },
306
+ bolt: {
307
+ id: 'bolt',
308
+ name: 'Bolt',
309
+ category: 'builder',
310
+ eyebrow: 'bolt.new · StackBlitz',
311
+ transport: 'http',
312
+ docsUrl: 'https://support.bolt.new/building/using-bolt/connect-mcp',
313
+ },
314
+ generic: {
315
+ id: 'generic',
316
+ name: 'Any MCP Client',
317
+ category: 'universal',
318
+ eyebrow: 'Universal · any MCP-compatible tool',
319
+ transport: 'stdio',
320
+ docsUrl: 'https://modelcontextprotocol.io',
321
+ },
322
+ });
323
+
324
+ function generateAgentOnboardingConfig(agentId, options = {}) {
325
+ const normId = String(agentId || '').trim().toLowerCase();
326
+ const def = SUPPORTED_AGENTS[normId];
327
+ if (!def) {
328
+ throw new Error(`Unsupported agent: "${agentId}". Supported: ${Object.keys(SUPPORTED_AGENTS).join(', ')}`);
329
+ }
330
+
331
+ const mode = options.mode || 'local'; // 'local' | 'hosted'
332
+ const token = options.token || 'thg_demo_token';
333
+ const serverUrl = options.serverUrl || (mode === 'local' ? 'http://127.0.0.1:4444/mcp' : 'https://thumbgate-production.up.railway.app/mcp');
334
+
335
+ let configText = '';
336
+ let cliCommand = '';
337
+ let deeplink = null;
338
+
339
+ switch (def.id) {
340
+ case 'cursor': {
341
+ const configObj = mode === 'local'
342
+ ? {
343
+ mcpServers: {
344
+ thumbgate: {
345
+ command: 'npx',
346
+ args: ['-y', 'thumbgate', 'mcp'],
347
+ },
348
+ },
349
+ }
350
+ : {
351
+ mcpServers: {
352
+ thumbgate: {
353
+ type: 'http',
354
+ url: serverUrl,
355
+ headers: {
356
+ Authorization: `Bearer ${token}`,
357
+ },
358
+ },
359
+ },
360
+ };
361
+ configText = JSON.stringify(configObj, null, 2);
362
+ const b64 = Buffer.from(JSON.stringify(configObj.mcpServers.thumbgate)).toString('base64');
363
+ deeplink = `cursor://anysphere.cursor-deeplink/mcp/install?name=ThumbGate&config=${b64}`;
364
+ cliCommand = `# Edit ~/.cursor/mcp.json or click deep link:\nopen "${deeplink}"`;
365
+ break;
366
+ }
367
+ case 'vscode': {
368
+ const configObj = {
369
+ name: 'thumbgate',
370
+ type: mode === 'local' ? 'command' : 'http',
371
+ ...(mode === 'local'
372
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'] }
373
+ : { url: serverUrl, headers: { Authorization: `Bearer ${token}` } }),
374
+ };
375
+ configText = JSON.stringify({ mcp: { servers: { thumbgate: configObj } } }, null, 2);
376
+ deeplink = `vscode:mcp/install?${encodeURIComponent(JSON.stringify(configObj))}`;
377
+ cliCommand = `# Run via Command Palette (MCP: Add Server) or click deep link:\nopen "${deeplink}"`;
378
+ break;
379
+ }
380
+ case 'claude': {
381
+ cliCommand = mode === 'local'
382
+ ? 'claude mcp add thumbgate -- npx -y thumbgate mcp'
383
+ : `claude mcp add thumbgate ${serverUrl} --transport http --header "Authorization: Bearer ${token}" -s user`;
384
+ configText = cliCommand;
385
+ break;
386
+ }
387
+ case 'copilot_cli': {
388
+ cliCommand = mode === 'local'
389
+ ? 'copilot mcp add thumbgate -- command npx -y thumbgate mcp'
390
+ : `copilot mcp add thumbgate ${serverUrl} --header "Authorization: Bearer ${token}"`;
391
+ configText = cliCommand;
392
+ break;
393
+ }
394
+ case 'windsurf': {
395
+ const configObj = {
396
+ mcpServers: {
397
+ thumbgate: mode === 'local'
398
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'] }
399
+ : { type: 'http', serverUrl, headers: { Authorization: `Bearer ${token}` } },
400
+ },
401
+ };
402
+ configText = JSON.stringify(configObj, null, 2);
403
+ cliCommand = '# Add to ~/.codeium/windsurf/mcp_config.json';
404
+ break;
405
+ }
406
+ case 'kiro': {
407
+ const configObj = {
408
+ mcpServers: {
409
+ thumbgate: mode === 'local'
410
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'] }
411
+ : { type: 'http', url: serverUrl, headers: { Authorization: `Bearer ${token}` } },
412
+ },
413
+ };
414
+ configText = JSON.stringify(configObj, null, 2);
415
+ cliCommand = '# Add to kiro/mcp_settings.json';
416
+ break;
417
+ }
418
+ case 'codex': {
419
+ configText = mode === 'local'
420
+ ? '[mcp_servers.thumbgate]\ncommand = "npx"\nargs = ["-y", "thumbgate", "mcp"]'
421
+ : `[mcp_servers.thumbgate]\ntype = "http"\nurl = "${serverUrl}"\n\n[mcp_servers.thumbgate.headers]\nAuthorization = "Bearer ${token}"`;
422
+ cliCommand = '# Add to ~/.codex/config.toml';
423
+ break;
424
+ }
425
+ case 'gemini': {
426
+ const configObj = {
427
+ mcpServers: {
428
+ thumbgate: mode === 'local'
429
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'] }
430
+ : { httpUrl: serverUrl, headers: { Authorization: `Bearer ${token}` } },
431
+ },
432
+ };
433
+ configText = JSON.stringify(configObj, null, 2);
434
+ cliCommand = '# Add to ~/.gemini/settings.json';
435
+ break;
436
+ }
437
+ case 'antigravity': {
438
+ configText = mode === 'local'
439
+ ? 'mcpServers:\n thumbgate:\n command: npx\n args: ["-y", "thumbgate", "mcp"]'
440
+ : `mcpServers:\n thumbgate:\n url: ${serverUrl}\n headers:\n Authorization: "Bearer ${token}"`;
441
+ cliCommand = '# Add to .antigravity/workspace.yaml or .mcp.json';
442
+ break;
443
+ }
444
+ case 'opencode': {
445
+ cliCommand = 'opencode mcp add';
446
+ configText = `# Run opencode mcp add and select remote (${serverUrl}) or stdio (npx -y thumbgate mcp)`;
447
+ break;
448
+ }
449
+ case 'jetbrains': {
450
+ const configObj = {
451
+ mcpServers: {
452
+ thumbgate: mode === 'local'
453
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'] }
454
+ : {
455
+ command: 'npx',
456
+ args: ['-y', 'mcp-remote', serverUrl, '--header', `Authorization: Bearer ${token}`],
457
+ },
458
+ },
459
+ };
460
+ configText = JSON.stringify(configObj, null, 2);
461
+ cliCommand = '# Add to JetBrains AI Assistant mcp-settings.json';
462
+ break;
463
+ }
464
+ case 'grok': {
465
+ cliCommand = mode === 'local'
466
+ ? 'grok mcp add thumbgate -- npx -y thumbgate mcp'
467
+ : `grok mcp add --transport http thumbgate ${serverUrl} --header "Authorization: Bearer ${token}"`;
468
+ configText = cliCommand;
469
+ break;
470
+ }
471
+ case 'lovable': {
472
+ cliCommand = `# In Lovable Connectors, select Custom MCP with URL ${serverUrl} and Bearer token`;
473
+ configText = JSON.stringify({ url: serverUrl, auth: 'Bearer token' }, null, 2);
474
+ break;
475
+ }
476
+ case 'cline': {
477
+ const configObj = {
478
+ mcpServers: {
479
+ thumbgate: mode === 'local'
480
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'], disabled: false, autoApprove: [] }
481
+ : { type: 'streamableHttp', url: serverUrl, headers: { Authorization: `Bearer ${token}` }, disabled: false, autoApprove: [] },
482
+ },
483
+ };
484
+ configText = JSON.stringify(configObj, null, 2);
485
+ cliCommand = '# Add to ~/.cline/mcp.json';
486
+ break;
487
+ }
488
+ case 'bolt': {
489
+ cliCommand = `# In bolt.new Connectors, click Custom MCP server with URL ${serverUrl} and API key`;
490
+ configText = JSON.stringify({ transport: 'http', url: serverUrl, auth: 'API key' }, null, 2);
491
+ break;
492
+ }
493
+ case 'generic':
494
+ default: {
495
+ const configObj = mode === 'local'
496
+ ? { command: 'npx', args: ['-y', 'thumbgate', 'mcp'] }
497
+ : { type: 'http', url: serverUrl, headers: { Authorization: `Bearer ${token}` } };
498
+ configText = JSON.stringify(configObj, null, 2);
499
+ cliCommand = '# Generic MCP client: use stdio or streamable HTTP';
500
+ break;
501
+ }
502
+ }
503
+
504
+ return {
505
+ id: def.id,
506
+ name: def.name,
507
+ category: def.category,
508
+ eyebrow: def.eyebrow,
509
+ transport: def.transport,
510
+ configFile: def.configFile || null,
511
+ docsUrl: def.docsUrl || null,
512
+ supportsDeeplink: Boolean(def.supportsDeeplink),
513
+ deeplink,
514
+ cliCommand,
515
+ configText,
516
+ };
517
+ }
518
+
519
+ function getAllAgentOnboardingConfigs(options = {}) {
520
+ return Object.keys(SUPPORTED_AGENTS).map((id) => generateAgentOnboardingConfig(id, options));
521
+ }
522
+
523
+ const PROMPT_QUERY_AUTH_RE =
524
+ /\b(auth[_-]?token|api[_-]?key|token|password|secret|access[_-]?token|bearer)\s*(in|via|through|inside|using)\s*(the\s*)?(query(\s*string)?|url|query\s*param(eter)?s?)\b/i;
525
+ const PROMPT_QUERY_AUTH_RE2 =
526
+ /\b(query(\s*string)?|url|query\s*param(eter)?s?)\s*(with|contains?|containing|holding|has)\s*(the\s*)?(auth[_-]?token|api[_-]?key|token|password|secret)\b/i;
527
+
528
+ const PROMPT_BOLA_PII_RE =
529
+ /\b(user[_-]?id|userid|account[_-]?id|tenant[_-]?id|owner[_-]?id)\s*(in|via|through)\s*(the\s*)?(query(\s*string)?|url|path)\b/i;
530
+ const PROMPT_DELETE_USER_RE =
531
+ /\b(delete|remove)\s*(user|account|tenant)\b.*(userid|user[_-]?id)/i;
532
+
533
+ const PROMPT_MCP_TOOL_RE =
534
+ /\b(mcp\s*tool|mcp\s*server|tool\s*input)\b/i;
535
+
536
+ const PROMPT_ARBITRARY_EXEC_RE =
537
+ /\b(eval\s*\(|exec\s*\(|execute\s*(the\s*)?(output|response|completion|result)|run\s*(code|script)\s*from\s*(llm|model|output))\b/i;
538
+
539
+ const PROMPT_DESTRUCTIVE_CMD_RE =
540
+ /\b(rm\s+-rf|drop\s+database|format\s+disk|git\s+push\s+--force)\b/i;
541
+
542
+ /**
543
+ * Evaluates a user prompt against the 40-policy taxonomy.
544
+ * Generates proactive alternatives (the Salt Code terminal demo FORMAT)
545
+ * and determines pre-action firewall verdict (ALLOW / REQUIRE_REVIEW / BLOCK).
546
+ */
547
+ function evaluatePromptSecurity(promptText) {
548
+ if (!promptText || typeof promptText !== 'string') {
549
+ return {
550
+ allowed: true,
551
+ action: 'ALLOW',
552
+ prompt: '',
553
+ violations: [],
554
+ alternatives: [],
555
+ verdict: 'No prompt text provided.',
556
+ };
557
+ }
558
+
559
+ const violations = [];
560
+ const alternatives = [];
561
+ const text = promptText.trim();
562
+
563
+ // 1. Query string authentication check (OWASP API2 / OAS01)
564
+ if (PROMPT_QUERY_AUTH_RE.test(text) || PROMPT_QUERY_AUTH_RE2.test(text)) {
565
+ violations.push({
566
+ id: 'API2:2023',
567
+ name: 'Broken Authentication',
568
+ gateId: 'query_string_secret_auth',
569
+ severity: 'fail',
570
+ message: 'Auth token in query string leaks via browser histories, server access logs, and HTTP Referer headers.',
571
+ });
572
+ violations.push({
573
+ id: 'OAS01:QUERY_AUTH',
574
+ name: 'Prohibit Query-String Secret Auth',
575
+ gateId: 'query_string_secret_auth',
576
+ severity: 'fail',
577
+ message: 'API contracts must prohibit sensitive authentication credentials in query parameters.',
578
+ });
579
+ alternatives.push('Bearer token in Authorization header');
580
+ }
581
+
582
+ // 2. BOLA & PII leakage check (OWASP API1 / API3)
583
+ if (PROMPT_BOLA_PII_RE.test(text) || PROMPT_DELETE_USER_RE.test(text)) {
584
+ violations.push({
585
+ id: 'API1:2023',
586
+ name: 'Broken Object Level Authorization (BOLA)',
587
+ gateId: 'bola_unscoped_resource',
588
+ severity: 'warn',
589
+ message: 'Unscoped user ID manipulation in query/path creates Broken Object Level Authorization vulnerability.',
590
+ });
591
+ violations.push({
592
+ id: 'API3:2023',
593
+ name: 'Broken Object Property Level Authorization (BOPLA)',
594
+ gateId: 'mass_assignment_guard',
595
+ severity: 'warn',
596
+ message: 'User ID in query string exposes Personally Identifiable Information (PII) in transit logs.',
597
+ });
598
+ alternatives.push('User ID in request body with authorization check');
599
+ }
600
+
601
+ // 3. MCP tool input validation check (MCP01 / MCP04)
602
+ if (PROMPT_MCP_TOOL_RE.test(text)) {
603
+ violations.push({
604
+ id: 'MCP01:AUTH',
605
+ name: 'Mandatory Tool Authorization',
606
+ gateId: 'tool_authorization_verification',
607
+ severity: 'warn',
608
+ message: 'MCP tool definitions require strict JSON Schema validation for all input properties.',
609
+ });
610
+ alternatives.push('Secure MCP tool definition with validated schema');
611
+ }
612
+
613
+ // 4. Insecure output execution (LLM05 / MCP07)
614
+ if (PROMPT_ARBITRARY_EXEC_RE.test(text)) {
615
+ violations.push({
616
+ id: 'LLM05:2025',
617
+ name: 'Improper Output Handling',
618
+ gateId: 'insecure_output_execution',
619
+ severity: 'fail',
620
+ message: 'Dynamic execution of unvalidated LLM output allows arbitrary remote code execution.',
621
+ });
622
+ alternatives.push('Enforce typed JSON structured output parsing rather than raw string execution');
623
+ }
624
+
625
+ // 5. Destructive shell command check (MCP06)
626
+ if (PROMPT_DESTRUCTIVE_CMD_RE.test(text)) {
627
+ violations.push({
628
+ id: 'MCP06:MUTATION_FENCE',
629
+ name: 'Read-only vs Mutating Tier Diode',
630
+ gateId: 'tool_mutation_tier_classification',
631
+ severity: 'fail',
632
+ message: 'Destructive shell command detected in prompt; must be intercepted by PreToolUse firewall.',
633
+ });
634
+ alternatives.push('ThumbGate PreToolUse firewall denies destructive shell mutations autonomously');
635
+ }
636
+
637
+ const hasFail = violations.some((v) => v.severity === 'fail');
638
+ const hasWarn = violations.some((v) => v.severity === 'warn');
639
+
640
+ let action = 'ALLOW';
641
+ if (hasFail) action = 'BLOCK';
642
+ else if (hasWarn) action = 'REQUIRE_REVIEW';
643
+
644
+ const allowed = action !== 'BLOCK';
645
+
646
+ let verdict = 'Prompt adheres to ThumbGate security policies.';
647
+ if (violations.length > 0) {
648
+ verdict = `Your request violates policies. Let's do this instead:\n${alternatives.map((a) => ` ✓ ${a}`).join('\n')}`;
649
+ }
650
+
651
+ return {
652
+ prompt: text,
653
+ allowed,
654
+ action,
655
+ violations,
656
+ alternatives,
657
+ verdict,
658
+ };
659
+ }
660
+
661
+ function normalizeBoolean(value) {
662
+ if (value === true || value === 1) return true;
663
+ if (value === false || value === 0 || value == null) return false;
664
+ return /^(1|true|yes|on)$/i.test(String(value).trim());
665
+ }
666
+
667
+ function readTextSafely(filePath) {
668
+ if (!filePath) return null;
669
+ if (!fs.existsSync(filePath)) {
670
+ const err = new Error(`file not found: ${filePath}`);
671
+ err.code = 'ENOENT';
672
+ throw err;
673
+ }
674
+ return fs.readFileSync(filePath, 'utf8');
675
+ }
676
+
677
+ /**
678
+ * Evaluates code, OpenAPI spec, MCP configuration, and context instructions.
679
+ */
680
+ function evaluatePolicies({ codeText, apiText, mcpText, contextText, claimText, hasPretoolConfig }) {
681
+ const findings = [];
682
+
683
+ // Claim check: ensure nobody claims Salt Code is a drop-in substitute for ThumbGate
684
+ if (claimText && SUBSTITUTE_CLAIM_RE.test(claimText)) {
685
+ findings.push({
686
+ id: 'substitute_claim_refused',
687
+ category: 'ARCHITECTURE_HONESTY',
688
+ severity: 'fail',
689
+ gateId: 'salt_code_not_a_substitute',
690
+ message:
691
+ 'Salt Code is prompt-time context injection; ThumbGate is execution-time PreToolUse enforcement. They are not substitutes.',
692
+ });
693
+ }
694
+
695
+ // MCP Remote Cloud Dependency Check
696
+ if (mcpText) {
697
+ if (SALT_CLONE_RE.test(mcpText)) {
698
+ findings.push({
699
+ id: 'salt_cloud_dependency_refused',
700
+ category: 'MCP_SECURITY',
701
+ severity: 'fail',
702
+ gateId: 'salt_cloud_dependency_refusal',
703
+ message:
704
+ 'Detected cloud dependency on mcp.getsaltcode.com. ThumbGate enforces local-first, zero-cloud security diodes.',
705
+ });
706
+ }
707
+
708
+ if (UNREDACTED_SECRET_RE.test(mcpText)) {
709
+ findings.push({
710
+ id: 'unredacted_mcp_credentials',
711
+ category: 'MCP_SECURITY',
712
+ severity: 'fail',
713
+ gateId: 'unredacted_mcp_credentials',
714
+ message: 'Plaintext secret or API token found in MCP configuration. Credentials must use env vars or secret stores.',
715
+ });
716
+ }
717
+
718
+ // Insecure HTTP transport for remote MCP servers
719
+ if (/"url"\s*:\s*"http:\/\/[^"]+"/i.test(mcpText)) {
720
+ findings.push({
721
+ id: 'insecure_mcp_http_transport',
722
+ category: 'MCP_SECURITY',
723
+ severity: 'fail',
724
+ gateId: 'tls_transport_enforcement',
725
+ message: 'Remote MCP server URL uses plaintext http://. HTTPS is mandatory.',
726
+ });
727
+ }
728
+ }
729
+
730
+ // Context & Instructions Check: Flag context-only guardrails lacking PreToolUse
731
+ if (contextText) {
732
+ const hasSecurityInstructions = INSTRUCTION_SECURITY_RE.test(contextText);
733
+ if (hasSecurityInstructions && !hasPretoolConfig) {
734
+ findings.push({
735
+ id: 'context_injection_without_pretool_enforcement',
736
+ category: 'ENFORCEMENT_HONESTY',
737
+ severity: 'fail',
738
+ gateId: 'context_injection_without_pretool_enforcement',
739
+ message:
740
+ 'Security rules detected in prompt/context instructions without active PreToolUse hook configuration. Prompt-only rules fail under injection or distress.',
741
+ });
742
+ }
743
+ }
744
+
745
+ // OpenAPI Spec Check: Query-string secrets and CORS misconfiguration
746
+ if (apiText) {
747
+ if (QUERY_STRING_SECRET_RE.test(apiText) || OPENAPI_QUERY_SECRET_RE.test(apiText)) {
748
+ findings.push({
749
+ id: 'query_string_secret_auth',
750
+ category: 'OPENAPI_HYGIENE',
751
+ severity: 'fail',
752
+ gateId: 'query_string_secret_auth',
753
+ message:
754
+ 'Authentication secret passed via URL query parameter. Must use standard Authorization header (OWASP API2 / OAS01).',
755
+ });
756
+ }
757
+
758
+ if (CORS_WILDCARD_RE.test(apiText)) {
759
+ findings.push({
760
+ id: 'cors_wildcard_misconfiguration',
761
+ category: 'OPENAPI_HYGIENE',
762
+ severity: 'warn',
763
+ gateId: 'cors_and_debug_misconfiguration',
764
+ message:
765
+ 'Overly permissive CORS wildcard configuration (Access-Control-Allow-Origin: *) detected in API spec.',
766
+ });
767
+ }
768
+ }
769
+
770
+ // Code Checks: BOLA, SSRF, Insecure Output Execution, Query String Secrets
771
+ if (codeText) {
772
+ if (QUERY_STRING_SECRET_RE.test(codeText)) {
773
+ findings.push({
774
+ id: 'query_string_secret_auth_code',
775
+ category: 'OWASP_API_TOP_10',
776
+ severity: 'fail',
777
+ gateId: 'query_string_secret_auth',
778
+ message:
779
+ 'Query-string secret found in code or HTTP request URL. Secrets in query parameters leak to server logs and browser histories.',
780
+ });
781
+ }
782
+
783
+ if (hasUnscopedBola(codeText)) {
784
+ findings.push({
785
+ id: 'bola_unscoped_resource',
786
+ category: 'OWASP_API_TOP_10',
787
+ severity: 'warn',
788
+ gateId: 'bola_unscoped_resource',
789
+ message:
790
+ 'Potential Broken Object Level Authorization (BOLA): resource queried directly by ID without tenant or user ownership scope.',
791
+ });
792
+ }
793
+
794
+ if (SSRF_DYNAMIC_FETCH_RE.test(codeText)) {
795
+ findings.push({
796
+ id: 'ssrf_unvalidated_destination',
797
+ category: 'OWASP_API_TOP_10',
798
+ severity: 'warn',
799
+ gateId: 'ssrf_unvalidated_destination',
800
+ message:
801
+ 'Dynamic URL passed to HTTP client request without domain allowlisting. Potential Server-Side Request Forgery (SSRF).',
802
+ });
803
+ }
804
+
805
+ if (INSECURE_OUTPUT_EXEC_RE.test(codeText)) {
806
+ findings.push({
807
+ id: 'insecure_output_execution',
808
+ category: 'OWASP_LLM_TOP_10',
809
+ severity: 'fail',
810
+ gateId: 'insecure_output_execution',
811
+ message:
812
+ 'Model output or dynamic string passed directly into eval()/Function()/exec(). Violates OWASP LLM05 (Improper Output Handling).',
813
+ });
814
+ }
815
+ }
816
+
817
+ return findings;
818
+ }
819
+
820
+ /**
821
+ * Builds the comprehensive audit report.
822
+ */
823
+ function buildSaltCodePolicyHonestyReport(rawOptions = {}) {
824
+ const rootDir = path.resolve(String(rawOptions.root || rawOptions.rootDir || process.cwd()));
825
+ const mapOnly = normalizeBoolean(rawOptions['map-only'] || rawOptions.mapOnly);
826
+ const strict = normalizeBoolean(rawOptions.strict);
827
+
828
+ if (mapOnly) {
829
+ return {
830
+ name: 'thumbgate-salt-code-policy-honesty',
831
+ status: 'ready',
832
+ source: SOURCE_URL,
833
+ disclaimer:
834
+ 'FORMAT steal from Salt Code (40-policy taxonomy, OWASP API Top 10, OWASP LLM Top 10, MCP security, OpenAPI query auth diode). Not affiliated with Salt Security. Operates strictly locally.',
835
+ rootDir,
836
+ policyCount: POLICY_CATALOG.length,
837
+ policies: POLICY_CATALOG,
838
+ railMap: RAIL_MAP,
839
+ summary: {
840
+ totalPolicies: POLICY_CATALOG.length,
841
+ findingCount: 0,
842
+ failCount: 0,
843
+ warnCount: 0,
844
+ },
845
+ nextActions: [
846
+ 'Run without --map-only to inspect workspace code, MCP configs, and OpenAPI contracts.',
847
+ ],
848
+ exampleCommand: 'npx thumbgate salt-code-policy-honesty --inspect-code=src/api.js --json',
849
+ };
850
+ }
851
+
852
+ const ioErrors = [];
853
+ let codeText = rawOptions.codeText || null;
854
+ let apiText = rawOptions.apiText || null;
855
+ let mcpText = rawOptions.mcpText || null;
856
+ let contextText = rawOptions.contextText || null;
857
+ const claimText = rawOptions.claim != null ? String(rawOptions.claim) : null;
858
+
859
+ const codePath = rawOptions['inspect-code'] || rawOptions.code || rawOptions.inspectCode;
860
+ const apiPath = rawOptions['inspect-api'] || rawOptions.api || rawOptions.inspectApi;
861
+ const mcpPath = rawOptions['inspect-mcp'] || rawOptions.mcp || rawOptions.inspectMcp;
862
+ const contextPath = rawOptions['inspect-context'] || rawOptions.context || rawOptions.inspectContext;
863
+
864
+ if (codePath && codeText == null) {
865
+ try {
866
+ codeText = readTextSafely(path.resolve(rootDir, String(codePath)));
867
+ } catch (err) {
868
+ ioErrors.push({ id: 'code_read_error', message: err.message });
869
+ }
870
+ }
871
+
872
+ if (apiPath && apiText == null) {
873
+ try {
874
+ apiText = readTextSafely(path.resolve(rootDir, String(apiPath)));
875
+ } catch (err) {
876
+ ioErrors.push({ id: 'api_read_error', message: err.message });
877
+ }
878
+ }
879
+
880
+ if (mcpPath && mcpText == null) {
881
+ try {
882
+ mcpText = readTextSafely(path.resolve(rootDir, String(mcpPath)));
883
+ } catch (err) {
884
+ ioErrors.push({ id: 'mcp_read_error', message: err.message });
885
+ }
886
+ }
887
+
888
+ if (contextPath && contextText == null) {
889
+ try {
890
+ contextText = readTextSafely(path.resolve(rootDir, String(contextPath)));
891
+ } catch (err) {
892
+ ioErrors.push({ id: 'context_read_error', message: err.message });
893
+ }
894
+ }
895
+
896
+ // Auto-detect project files if nothing provided
897
+ let detectedMcpPath = null;
898
+ if (!codeText && !apiText && !mcpText && !contextText && !claimText) {
899
+ const defaultMcp = path.join(rootDir, '.mcp.json');
900
+ if (fs.existsSync(defaultMcp)) {
901
+ try {
902
+ mcpText = fs.readFileSync(defaultMcp, 'utf8');
903
+ detectedMcpPath = '.mcp.json';
904
+ } catch (_) {}
905
+ }
906
+ }
907
+
908
+ const hasPreToolHook = (p) => {
909
+ try {
910
+ const cfg = JSON.parse(fs.readFileSync(p, 'utf8'));
911
+ const pre = cfg && cfg.hooks && cfg.hooks.PreToolUse;
912
+ return Array.isArray(pre) && pre.length > 0;
913
+ } catch (_) {
914
+ return false;
915
+ }
916
+ };
917
+ const hasPretoolConfig =
918
+ rawOptions.hasPretoolConfig === true ||
919
+ hasPreToolHook(path.join(rootDir, 'hooks', 'hooks.json')) ||
920
+ hasPreToolHook(path.join(rootDir, '.claude', 'settings.json'));
921
+
922
+ const evaluationFindings = evaluatePolicies({
923
+ codeText,
924
+ apiText,
925
+ mcpText,
926
+ contextText,
927
+ claimText,
928
+ hasPretoolConfig,
929
+ });
930
+
931
+ const allFindings = [
932
+ ...ioErrors.map((e) => ({
933
+ id: e.id,
934
+ category: 'IO_ERROR',
935
+ severity: 'fail',
936
+ gateId: 'file_read',
937
+ message: e.message,
938
+ })),
939
+ ...evaluationFindings,
940
+ ];
941
+
942
+ const evalPrompt = rawOptions['eval-prompt'] || rawOptions.evalPrompt || rawOptions.prompt;
943
+ let promptEvaluation = null;
944
+ if (evalPrompt) {
945
+ promptEvaluation = evaluatePromptSecurity(String(evalPrompt));
946
+ if (promptEvaluation.violations.length > 0) {
947
+ allFindings.push(
948
+ ...promptEvaluation.violations.map((v) => ({
949
+ id: `prompt_${v.id.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase()}`,
950
+ category: 'PROMPT_SECURITY',
951
+ severity: v.severity,
952
+ gateId: v.gateId,
953
+ message: `Prompt violation: ${v.name} — ${v.message}`,
954
+ }))
955
+ );
956
+ }
957
+ }
958
+
959
+ const onboardingArg = rawOptions.onboarding || rawOptions.agent;
960
+ let onboardingConfigs = null;
961
+ if (onboardingArg) {
962
+ if (onboardingArg === true || onboardingArg === 'all') {
963
+ onboardingConfigs = getAllAgentOnboardingConfigs(rawOptions);
964
+ } else {
965
+ onboardingConfigs = [generateAgentOnboardingConfig(String(onboardingArg), rawOptions)];
966
+ }
967
+ }
968
+
969
+ const wantDeeplinks = normalizeBoolean(rawOptions.deeplinks || rawOptions['deep-links']);
970
+ let deeplinks = null;
971
+ if (wantDeeplinks) {
972
+ deeplinks = {
973
+ cursor: generateAgentOnboardingConfig('cursor', rawOptions).deeplink,
974
+ vscode: generateAgentOnboardingConfig('vscode', rawOptions).deeplink,
975
+ };
976
+ }
977
+
978
+ const wantVibeStats = normalizeBoolean(rawOptions['vibe-stats'] || rawOptions.vibeStats);
979
+
980
+ const failCount = allFindings.filter((f) => f.severity === 'fail').length;
981
+ const warnCount = allFindings.filter((f) => f.severity === 'warn').length;
982
+
983
+ let status = 'ready';
984
+ if (failCount > 0) status = 'fail';
985
+ else if (warnCount > 0) status = 'actionable';
986
+
987
+ const nextActions = [];
988
+ if (promptEvaluation && !promptEvaluation.allowed) {
989
+ nextActions.push(`Refactor prompt to adopt safe alternative: ${promptEvaluation.alternatives.join('; ')}`);
990
+ }
991
+ if (failCount > 0) {
992
+ nextActions.push('Remediate failing security gates before agent tool execution.');
993
+ }
994
+ if (warnCount > 0) {
995
+ nextActions.push('Review warnings for BOLA, SSRF, or permissive CORS configurations.');
996
+ }
997
+ if (allFindings.length === 0) {
998
+ nextActions.push('Audit passed cleanly. Active PreToolUse infrastructure firewall intact.');
999
+ }
1000
+
1001
+ return {
1002
+ name: 'thumbgate-salt-code-policy-honesty',
1003
+ status,
1004
+ source: SOURCE_URL,
1005
+ disclaimer:
1006
+ 'FORMAT steal from Salt Code (40-policy taxonomy, OWASP API Top 10, OWASP LLM Top 10, MCP security, OpenAPI query auth diode). Not affiliated with Salt Security. Operates strictly locally.',
1007
+ rootDir,
1008
+ targetMetrics: {
1009
+ codeInspected: Boolean(codeText),
1010
+ apiInspected: Boolean(apiText),
1011
+ mcpInspected: Boolean(mcpText),
1012
+ contextInspected: Boolean(contextText),
1013
+ promptInspected: Boolean(evalPrompt),
1014
+ detectedMcpPath,
1015
+ hasPretoolConfig,
1016
+ policyCatalogSize: POLICY_CATALOG.length,
1017
+ supportedAgentsCount: Object.keys(SUPPORTED_AGENTS).length,
1018
+ },
1019
+ findings: allFindings,
1020
+ summary: {
1021
+ totalPolicies: POLICY_CATALOG.length,
1022
+ findingCount: allFindings.length,
1023
+ failCount,
1024
+ warnCount,
1025
+ },
1026
+ railMap: RAIL_MAP,
1027
+ promptEvaluation,
1028
+ onboarding: onboardingConfigs,
1029
+ deeplinks,
1030
+ vibeStats: wantVibeStats ? VIBE_CODING_VULNERABILITY_STATS : null,
1031
+ nextActions,
1032
+ exampleCommand: 'npx thumbgate salt-code-policy-honesty --inspect-code=src/index.js --json',
1033
+ };
1034
+ }
1035
+
1036
+ /**
1037
+ * Formats the report for human-readable terminal output.
1038
+ */
1039
+ function formatSaltCodePolicyHonestyReport(report) {
1040
+ const lines = [
1041
+ '=== ThumbGate Salt Code Security Policy Honesty Doctor ===',
1042
+ `Status : ${report.status.toUpperCase()}`,
1043
+ `Root : ${report.rootDir}`,
1044
+ `Policies : ${report.summary.totalPolicies} active policies mapped to ThumbGate PreToolUse gates`,
1045
+ `Findings : ${report.summary.findingCount} (fail=${report.summary.failCount}, warn=${report.summary.warnCount})`,
1046
+ `Source : ${report.source}`,
1047
+ ];
1048
+
1049
+ if (report.vibeStats) {
1050
+ const vs = report.vibeStats;
1051
+ lines.push('', '--- Vibe-Coding Security Intelligence (2026) ---');
1052
+ lines.push(`• Syntactically Correct Code : ${vs.syntacticallyCorrectPct}%`);
1053
+ lines.push(`• Completed Tasks with Flaws : ${vs.completedTasksWithSecurityFlawPct}% (${vs.sources[0]})`);
1054
+ lines.push(`• Vibe-Coded Apps with Flaws : ${vs.vibeCodedAppsWithMajorVulnerabilitiesPct}% (avg ${vs.avgVulnerabilitiesPerApp} vulnerabilities/app; ${vs.sources[1]})`);
1055
+ lines.push(`• Takeaway : ${vs.takeaway}`);
1056
+ }
1057
+
1058
+ if (report.promptEvaluation) {
1059
+ const pe = report.promptEvaluation;
1060
+ lines.push('', '--- Prompt-Time Security Interception ---');
1061
+ lines.push(`Prompt : "${pe.prompt}"`);
1062
+ lines.push(`Action : ${pe.action} (Allowed=${pe.allowed})`);
1063
+ if (pe.violations.length > 0) {
1064
+ lines.push('Security issues found:');
1065
+ for (const v of pe.violations) {
1066
+ lines.push(` ⚠ [${v.id}] ${v.name}: ${v.message}`);
1067
+ }
1068
+ lines.push('', "Your request violates policies. Let's do this instead:");
1069
+ for (const a of pe.alternatives) {
1070
+ lines.push(` ✓ ${a}`);
1071
+ }
1072
+ } else {
1073
+ lines.push('Result : ✓ Prompt passes all active security policies.');
1074
+ }
1075
+ }
1076
+
1077
+ if (report.onboarding && report.onboarding.length) {
1078
+ lines.push('', '--- Universal Multi-Agent Onboarding (16 Supported Agents) ---');
1079
+ for (const ag of report.onboarding) {
1080
+ lines.push(`\n[${ag.name}] (${ag.eyebrow})`);
1081
+ if (ag.configFile) lines.push(` Config File : ${ag.configFile}`);
1082
+ if (ag.cliCommand) lines.push(` CLI Command : ${ag.cliCommand}`);
1083
+ if (ag.deeplink) lines.push(` One-Click : ${ag.deeplink}`);
1084
+ lines.push(' Config:');
1085
+ lines.push(ag.configText.split('\n').map((l) => ` ${l}`).join('\n'));
1086
+ }
1087
+ }
1088
+
1089
+ if (report.deeplinks) {
1090
+ lines.push('', '--- One-Click MCP Deep Links ---');
1091
+ lines.push(`Cursor : ${report.deeplinks.cursor}`);
1092
+ lines.push(`VS Code: ${report.deeplinks.vscode}`);
1093
+ }
1094
+
1095
+ if (report.railMap && report.railMap.length) {
1096
+ lines.push('', '--- Salt Code vs ThumbGate Architecture (Rail Map) ---');
1097
+ for (const r of report.railMap) {
1098
+ lines.push(`• [${r.pillar}]`);
1099
+ lines.push(` Salt Code: ${r.saltCode}`);
1100
+ lines.push(` ThumbGate: ${r.thumbgate}`);
1101
+ lines.push(` Verdict : ${r.verdict}`);
1102
+ }
1103
+ }
1104
+
1105
+ if (report.findings && report.findings.length) {
1106
+ lines.push('', '--- Findings ---');
1107
+ for (const f of report.findings) {
1108
+ lines.push(` - [${f.severity.toUpperCase()}] ${f.id} (${f.category || 'GENERAL'})`);
1109
+ lines.push(` Gate : ${f.gateId}`);
1110
+ lines.push(` Message: ${f.message}`);
1111
+ }
1112
+ }
1113
+
1114
+ if (report.nextActions && report.nextActions.length) {
1115
+ lines.push('', 'Next actions:');
1116
+ for (const a of report.nextActions) lines.push(` - ${a}`);
1117
+ }
1118
+
1119
+ lines.push('', `Example: ${report.exampleCommand}`);
1120
+ lines.push(`Note: ${report.disclaimer}`, '');
1121
+ return `${lines.join('\n')}\n`;
1122
+ }
1123
+
1124
+ function parseCliArgs(argv) {
1125
+ const options = {};
1126
+ for (const arg of argv) {
1127
+ if (arg === '--json') { options.json = true; continue; }
1128
+ if (arg === '--strict') { options.strict = true; continue; }
1129
+ if (arg === '--map-only') { options['map-only'] = true; continue; }
1130
+ if (arg === '--deeplinks' || arg === '--deep-links') { options.deeplinks = true; continue; }
1131
+ if (arg === '--vibe-stats' || arg === '--stats') { options['vibe-stats'] = true; continue; }
1132
+ if (arg === '--help' || arg === '-h') { options.help = true; continue; }
1133
+ const m = /^--([^=]+)(?:=(.*))?$/.exec(arg);
1134
+ if (!m) continue;
1135
+ options[m[1]] = m[2] === undefined ? true : m[2];
1136
+ }
1137
+ return options;
1138
+ }
1139
+
1140
+ function printHelp() {
1141
+ process.stdout.write(`Usage: node scripts/salt-code-policy-honesty.js [flags]
1142
+
1143
+ Flags:
1144
+ --eval-prompt=TEXT Simulate prompt evaluation against the 40-policy taxonomy
1145
+ --onboarding[=AGENT] Generate MCP config for agent (claude, cursor, vscode, etc. or "all")
1146
+ --deeplinks Print one-click deep links for Cursor and VS Code
1147
+ --vibe-stats Print 2026 vibe-coding empirical vulnerability statistics
1148
+ --inspect-code=PATH Inspect source code for BOLA, SSRF, eval(), query-string auth
1149
+ --inspect-api=PATH Inspect OpenAPI spec for query-string secret auth & CORS
1150
+ --inspect-mcp=PATH Inspect MCP config for unredacted credentials or remote cloud dependencies
1151
+ --inspect-context=PATH Inspect prompt instructions (.cursorrules) for un-enforced rules
1152
+ --claim=TEXT Audit claims comparing Salt Code and ThumbGate
1153
+ --map-only Print the 40-policy taxonomy and architecture rail map
1154
+ --strict Exit 1 if any failure or warning is detected
1155
+ --json Output JSON report
1156
+ --root=DIR Repository root directory (default: cwd)
1157
+
1158
+ Source: ${SOURCE_URL}
1159
+ `);
1160
+ }
1161
+
1162
+ function runCli(argv = process.argv.slice(2)) {
1163
+ const args = parseCliArgs(argv);
1164
+ if (args.help) {
1165
+ printHelp();
1166
+ return 0;
1167
+ }
1168
+ const report = buildSaltCodePolicyHonestyReport(args);
1169
+ if (args.json) {
1170
+ process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
1171
+ } else {
1172
+ process.stdout.write(formatSaltCodePolicyHonestyReport(report));
1173
+ }
1174
+ if (args.strict && report.status !== 'ready') return 1;
1175
+ if (report.status === 'fail') return 1;
1176
+ return 0;
1177
+ }
1178
+
1179
+ module.exports = {
1180
+ SOURCE_URL,
1181
+ POLICY_CATALOG,
1182
+ RAIL_MAP,
1183
+ VIBE_CODING_VULNERABILITY_STATS,
1184
+ SUPPORTED_AGENTS,
1185
+ generateAgentOnboardingConfig,
1186
+ getAllAgentOnboardingConfigs,
1187
+ evaluatePromptSecurity,
1188
+ SUBSTITUTE_CLAIM_RE,
1189
+ SALT_CLONE_RE,
1190
+ QUERY_STRING_SECRET_RE,
1191
+ BOLA_UNSCOPED_RE,
1192
+ SSRF_DYNAMIC_FETCH_RE,
1193
+ INSECURE_OUTPUT_EXEC_RE,
1194
+ CORS_WILDCARD_RE,
1195
+ UNREDACTED_SECRET_RE,
1196
+ evaluatePolicies,
1197
+ buildSaltCodePolicyHonestyReport,
1198
+ formatSaltCodePolicyHonestyReport,
1199
+ runCli,
1200
+ };
1201
+
1202
+ if (require.main === module || (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename))) {
1203
+ process.exitCode = runCli(process.argv.slice(2));
1204
+ }