thumbgate 1.39.1 → 1.40.2

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 (199) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.well-known/llms.txt +2 -2
  3. package/.well-known/mcp/server-card.json +1 -1
  4. package/README.md +5 -4
  5. package/adapters/claude/.mcp.json +6 -2
  6. package/adapters/codex/config.toml +5 -0
  7. package/adapters/forge/forge.yaml +4 -4
  8. package/adapters/future-agi/.mcp.json +1 -1
  9. package/adapters/future-agi/config.toml +1 -1
  10. package/adapters/future-agi/opencode.json +1 -1
  11. package/adapters/herdr/herdr-plugin.toml +2 -2
  12. package/adapters/mcp/server-stdio.js +82 -7
  13. package/adapters/opencode/opencode.json +1 -1
  14. package/bin/cli.js +128 -15
  15. package/config/brand-standards.json +131 -0
  16. package/config/gates/default.json +18 -1
  17. package/config/github-about.json +1 -1
  18. package/config/mcp-allowlists.json +16 -3
  19. package/config/merge-quality-checks.json +1 -0
  20. package/config/post-deploy-marketing-pages.json +3 -3
  21. package/config/schemas/task-outcome-receipt.schema.json +9 -0
  22. package/openapi/openapi.yaml +7 -3
  23. package/package.json +98 -31
  24. package/public/about.html +2 -2
  25. package/public/admin.html +771 -0
  26. package/public/agent-manager.html +3 -3
  27. package/public/agents-cost-savings.html +1 -1
  28. package/public/ai-malpractice-prevention.html +12 -12
  29. package/public/architecture.html +0 -1
  30. package/public/assets/diagrams/decision.svg +3 -3
  31. package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
  32. package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
  33. package/public/blog/git-at-agent-scale.html +2 -2
  34. package/public/blog/inside-your-boundary.html +1 -1
  35. package/public/blog/process-over-outcome-gates.html +1 -1
  36. package/public/case-studies.html +1 -2
  37. package/public/codex-enterprise.html +1 -1
  38. package/public/codex-plugin.html +1 -1
  39. package/public/dashboard.html +773 -481
  40. package/public/diagnostic.html +8 -3
  41. package/public/enterprise-governance.html +26 -174
  42. package/public/eval-scorecard.html +3 -4
  43. package/public/eval-scorecard.json +2 -2
  44. package/public/evaluations.html +0 -1
  45. package/public/founders.html +3 -3
  46. package/public/gaming-playbook.html +4 -4
  47. package/public/guide.html +3 -5
  48. package/public/index.html +181 -205
  49. package/public/install.html +12 -11
  50. package/public/js/buyer-intent.js +49 -8
  51. package/public/lessons.html +103 -46
  52. package/public/numbers.html +32 -33
  53. package/public/operator-framework.html +44 -72
  54. package/public/peter.html +3 -3
  55. package/public/platform-partners.html +1 -1
  56. package/public/pricing.html +61 -327
  57. package/public/pro.html +3 -1
  58. package/public/project-switcher.js +76 -0
  59. package/public/whitepaper.html +1 -2
  60. package/scripts/activation-quickstart.js +15 -3
  61. package/scripts/activation-tracker.js +280 -3
  62. package/scripts/agent-action-inventory.js +235 -143
  63. package/scripts/agent-operations-planner.js +1 -1
  64. package/scripts/agent-readiness.js +36 -6
  65. package/scripts/agentic-prompt-pipelines.js +901 -0
  66. package/scripts/analytics-report.js +363 -0
  67. package/scripts/analytics-window.js +7 -1
  68. package/scripts/async-job-runner.js +66 -11
  69. package/scripts/audit-trail.js +37 -24
  70. package/scripts/auto-context-packs.js +249 -0
  71. package/scripts/auto-promote-gates.js +37 -27
  72. package/scripts/backfill-lesson-scopes.js +122 -0
  73. package/scripts/billing-setup.js +137 -0
  74. package/scripts/billing.js +889 -132
  75. package/scripts/bot-detection.js +112 -0
  76. package/scripts/brand-standards-gate.js +571 -0
  77. package/scripts/chatgpt-ads-readiness-pack.js +1 -1
  78. package/scripts/check-update.js +236 -0
  79. package/scripts/cli-schema.js +1 -1
  80. package/scripts/commercial-offer.js +2 -2
  81. package/scripts/contextfs.js +9 -3
  82. package/scripts/conversion-rate-stats.js +442 -0
  83. package/scripts/cost-cli.js +147 -0
  84. package/scripts/creator-campaigns.js +239 -0
  85. package/scripts/cross-encoder-reranker.js +4 -0
  86. package/scripts/cuda-gate-batch.js +560 -0
  87. package/scripts/daemon-manager.js +108 -0
  88. package/scripts/dashboard-chat.js +11 -0
  89. package/scripts/dashboard.js +576 -169
  90. package/scripts/decision-journal.js +7 -4
  91. package/scripts/delegation-runtime.js +1036 -0
  92. package/scripts/dispatch-brief.js +159 -0
  93. package/scripts/distribution-surfaces.js +110 -0
  94. package/scripts/docker-sandbox-planner.js +3 -3
  95. package/scripts/egm-goldfish-packet.js +95 -0
  96. package/scripts/embeddinggemma-adapter.js +407 -0
  97. package/scripts/export-dpo-pairs.js +12 -7
  98. package/scripts/feedback-aggregate.js +4 -0
  99. package/scripts/feedback-attribution.js +6 -4
  100. package/scripts/feedback-history-distiller.js +18 -6
  101. package/scripts/feedback-loop.js +255 -89
  102. package/scripts/feedback-paths.js +8 -1
  103. package/scripts/feedback-sanitizer.js +5 -0
  104. package/scripts/feedback-scope.js +106 -0
  105. package/scripts/feedback-session.js +8 -2
  106. package/scripts/filesystem-search.js +13 -8
  107. package/scripts/financial-control-plane.js +707 -45
  108. package/scripts/funnel-analytics.js +35 -0
  109. package/scripts/gate-semantic-layer.js +292 -0
  110. package/scripts/gate-stats.js +8 -2
  111. package/scripts/gates-engine.js +694 -230
  112. package/scripts/generate-eval-scorecard.js +0 -1
  113. package/scripts/harness-tool-names.js +31 -5
  114. package/scripts/hybrid-feedback-context.js +5 -2
  115. package/scripts/implementation-notes.js +241 -0
  116. package/scripts/intent-router.js +518 -0
  117. package/scripts/intervention-policy.js +2 -1
  118. package/scripts/latency-budget.js +164 -0
  119. package/scripts/lesson-canonical.js +2 -2
  120. package/scripts/lesson-db.js +55 -14
  121. package/scripts/lesson-graph.js +2 -1
  122. package/scripts/lesson-retrieval.js +95 -9
  123. package/scripts/lesson-search.js +86 -22
  124. package/scripts/lesson-synthesis.js +21 -5
  125. package/scripts/mailer/index.js +17 -1
  126. package/scripts/mailer/resend-mailer.js +213 -179
  127. package/scripts/mcp-writeguard.js +158 -0
  128. package/scripts/migrate-project-scope.js +209 -0
  129. package/scripts/model-candidates.js +414 -0
  130. package/scripts/openrouter-armor-partnership-diode.js +2419 -0
  131. package/scripts/operational-dashboard.js +172 -0
  132. package/scripts/operational-integrity.js +436 -3
  133. package/scripts/operational-summary.js +190 -0
  134. package/scripts/operator-artifacts.js +622 -0
  135. package/scripts/optimize-context.js +17 -0
  136. package/scripts/override-audit.js +2 -0
  137. package/scripts/owner-admin.js +338 -0
  138. package/scripts/pr-manager.js +194 -1
  139. package/scripts/predictive-insights.js +449 -0
  140. package/scripts/profound-aeo-citation-engine.js +583 -0
  141. package/scripts/progressive-signoff.js +260 -0
  142. package/scripts/project-catalog.js +243 -0
  143. package/scripts/project-dashboard.js +61 -0
  144. package/scripts/project-evidence.js +172 -0
  145. package/scripts/project-identity.js +182 -0
  146. package/scripts/project-scope.js +381 -0
  147. package/scripts/prompt-guard.js +446 -52
  148. package/scripts/proof-report.js +232 -0
  149. package/scripts/provider-action-normalizer.js +14 -6
  150. package/scripts/pulse.js +80 -0
  151. package/scripts/rate-limiter.js +41 -0
  152. package/scripts/rrsi-doctor.js +2698 -0
  153. package/scripts/secret-redaction.js +171 -25
  154. package/scripts/secret-scanner.js +101 -42
  155. package/scripts/self-protection.js +2 -2
  156. package/scripts/seo-gsd.js +14 -14
  157. package/scripts/session-context-dedupe.js +66 -0
  158. package/scripts/session-report.js +120 -0
  159. package/scripts/settings-hierarchy.js +4 -2
  160. package/scripts/statusline-meta.js +34 -23
  161. package/scripts/subagent-profiles.js +79 -0
  162. package/scripts/task-outcomes.js +29 -2
  163. package/scripts/telemetry-analytics.js +238 -13
  164. package/scripts/third-author-cli.js +118 -0
  165. package/scripts/third-author-governance.js +437 -0
  166. package/scripts/thumbgate-dream.js +878 -0
  167. package/scripts/thumbgate-search.js +23 -9
  168. package/scripts/tool-kpi-tracker.js +5 -2
  169. package/scripts/tool-registry.js +42 -1
  170. package/scripts/triage-savings-calculator.js +1 -1
  171. package/scripts/vector-store.js +4 -1
  172. package/scripts/verified-lessons.js +270 -0
  173. package/scripts/verify-marketing-pages-deployed.js +2 -2
  174. package/scripts/workflow-sentinel.js +29 -10
  175. package/server.json +2 -2
  176. package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
  177. package/src/api/server.js +2371 -451
  178. package/src/feedback.js +21 -0
  179. package/src/hermes-sync-plane.js +2 -1
  180. package/src/index.js +2 -0
  181. package/src/lesson-search.js +9 -0
  182. package/src/mckinsey-top-company-ai-coding.js +493 -0
  183. package/src/mcp/server.js +3 -0
  184. package/src/mcp-writeguard.js +772 -11
  185. package/src/openshell-lovable-engine.js +1475 -0
  186. package/src/task-outcome.js +3 -0
  187. package/config/evals/agent-safety-eval.json +0 -447
  188. package/config/evals/retrieval-ranking-golden.json +0 -522
  189. package/config/progressive/01-wire-only.json +0 -11
  190. package/config/progressive/02-dashboard-empty-ok.json +0 -10
  191. package/config/progressive/03-one-lesson.json +0 -10
  192. package/config/progressive/04-warn-fires.json +0 -11
  193. package/config/progressive/05-strict-optional.json +0 -11
  194. package/config/progressive/README.md +0 -15
  195. package/public/assets/diagrams/agent-integration.png +0 -0
  196. package/public/assets/diagrams/thumbgate-architecture.png +0 -0
  197. package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
  198. package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
  199. package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
@@ -0,0 +1,437 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * scripts/third-author-governance.js
5
+ *
6
+ * "The Third Author" Governance Engine for ThumbGate.
7
+ * Stolen & improved from SCANOSS Earnie (October 2026).
8
+ *
9
+ * Core Concept:
10
+ * Your code got a third author:
11
+ * 1. The human engineer (reviewed, accountable).
12
+ * 2. Open source (packages, snippets, license obligations).
13
+ * 3. AI agents (faster than review, never learned your policy).
14
+ *
15
+ * One Policy, Three Checkpoints:
16
+ * - Checkpoint 1: MCP / PreToolUse Gate (<0.5ms on CPU; blocks bad installs before execution; suggests permissive alternatives).
17
+ * - Checkpoint 2: Git Pre-Commit Hook (blocks commit; points to `npx thumbgate explain <FINDING-ID>`).
18
+ * - Checkpoint 3: PR Gate (posts verdict: pass, warn, require approval, block).
19
+ *
20
+ * Four Risks, One Record (The BOM Quadrant):
21
+ * - Risk 1: AI Models (AIBOM - SDKs, model weights, framework dependencies).
22
+ * - Risk 2: Cryptography & PQC (CBOM - flags classical crypto that won't survive Shor's algorithm).
23
+ * - Risk 3: License Compliance (SBOM - blocks copyleft AGPL/GPL, suggests MIT/Apache alternatives).
24
+ * - Risk 4: Security Vulnerabilities (unpinned dependencies, latest tags, pipe-to-bash).
25
+ */
26
+
27
+ const fs = require('node:fs');
28
+ const path = require('node:path');
29
+ const crypto = require('node:crypto');
30
+
31
+ function resolveFindingsLedgerPath(cwd = process.cwd()) {
32
+ if (process.env.THUMBGATE_FINDINGS_LEDGER_PATH) {
33
+ return process.env.THUMBGATE_FINDINGS_LEDGER_PATH;
34
+ }
35
+ if (process.env.THUMBGATE_DATA_DIR) {
36
+ return path.join(process.env.THUMBGATE_DATA_DIR, 'findings-ledger.jsonl');
37
+ }
38
+ return path.join(cwd, '.thumbgate', 'findings-ledger.jsonl');
39
+ }
40
+
41
+ const FINDINGS_LEDGER_PATH = resolveFindingsLedgerPath();
42
+
43
+ // Author Classifications
44
+ const AUTHOR_HUMAN = 'human';
45
+ const AUTHOR_OPENSOURCE = 'opensource';
46
+ const AUTHOR_AGENT = 'ai_agent';
47
+
48
+ // Permissive Alternatives Database (for in-line agent redirection)
49
+ const PERMISSIVE_ALTERNATIVES = {
50
+ 'fast-charts': [
51
+ { name: 'chart.js', license: 'MIT', description: 'Simple yet flexible JavaScript charting' },
52
+ { name: 'recharts', license: 'MIT', description: 'Redefined chart library built on React components' }
53
+ ],
54
+ 'ag-grid-enterprise': [
55
+ { name: 'ag-grid-community', license: 'MIT', description: 'Free community edition of AG Grid' },
56
+ { name: '@tanstack/react-table', license: 'MIT', description: 'Headless UI for building powerful tables' }
57
+ ],
58
+ 'pdfmake-agpl': [
59
+ { name: 'pdf-lib', license: 'MIT', description: 'Create and modify PDF documents in JS' },
60
+ { name: 'jspdf', license: 'MIT', description: 'Client-side JavaScript PDF generator' }
61
+ ],
62
+ 'ghostscript': [
63
+ { name: 'mupdf', license: 'AGPL-3.0 (Caution)', description: 'Consider pdfium (Apache-2.0)' },
64
+ { name: 'pdfium', license: 'Apache-2.0', description: 'Google open source PDF renderer' }
65
+ ],
66
+ 'metabase': [
67
+ { name: 'apache-superset', license: 'Apache-2.0', description: 'Modern enterprise BI and data exploration platform' }
68
+ ]
69
+ };
70
+
71
+ // Cryptography & PQC Taxonomy
72
+ const CRYPTO_PQC_CATALOG = [
73
+ {
74
+ id: 'rsa-classical',
75
+ name: 'RSA (Rivest-Shamir-Adleman)',
76
+ pattern: /(crypto\.createPrivateKey|crypto\.generateKeyPairSync\s*\(\s*['"]rsa['"]|BEGIN RSA PRIVATE KEY|RS256|RSA-OAEP|RSA-PSS|\b\d+-bit RSA\b)/i,
77
+ status: 'VULNERABLE_TO_SHORS_ALGORITHM',
78
+ severity: 'high',
79
+ pqcTransition: 'Deprecated for long-term secrets. Migrate to ML-KEM (FIPS 203) for key encapsulation or ML-DSA (FIPS 204) for digital signatures.'
80
+ },
81
+ {
82
+ id: 'ecdsa-classical',
83
+ name: 'ECDSA / ECC (Classical Elliptic Curves)',
84
+ pattern: /\b(secp256k1|prime256v1|P-256|P-384|P-521)\b|crypto\.createECDH/i,
85
+ status: 'VULNERABLE_TO_SHORS_ALGORITHM',
86
+ severity: 'medium',
87
+ pqcTransition: 'Vulnerable to quantum attack. Transition to ML-DSA (FIPS 204 / Dilithium) or stateful hash-based signatures (SLH-DSA).'
88
+ },
89
+ {
90
+ id: 'broken-hash-md5-sha1',
91
+ name: 'Broken Cryptographic Hash (MD5 / SHA-1)',
92
+ pattern: /createHash\s*\(\s*['"](md5|sha1)['"]\s*\)|hashlib\.(md5|sha1)\b/i,
93
+ status: 'CLASSICALLY_BROKEN',
94
+ severity: 'critical',
95
+ pqcTransition: 'Broken collision resistance. Replace immediately with SHA-256, SHA-384, or SHA-3.'
96
+ },
97
+ {
98
+ id: 'pqc-post-quantum-native',
99
+ name: 'NIST Post-Quantum Cryptography (ML-KEM / ML-DSA)',
100
+ pattern: /\b(ML-KEM|ML-DSA|SLH-DSA|Kyber512|Kyber768|Kyber1024|Dilithium2|Dilithium3|Dilithium5|SPHINCS\+)\b/i,
101
+ status: 'QUANTUM_RESISTANT',
102
+ severity: 'info',
103
+ pqcTransition: 'Meets NIST FIPS 203 / 204 / 205 Post-Quantum Cryptography standards.'
104
+ }
105
+ ];
106
+
107
+ // Copyleft & Restrictive Licenses
108
+ const RESTRICTIVE_LICENSES = new Set([
109
+ 'agpl-1.0',
110
+ 'agpl-3.0',
111
+ 'gpl-1.0',
112
+ 'gpl-2.0',
113
+ 'gpl-3.0',
114
+ 'sspl-1.0',
115
+ 'eupl-1.2',
116
+ 'cc-by-nc-4.0',
117
+ 'commons-clause'
118
+ ]);
119
+
120
+ function generateFindingId(category) {
121
+ const prefix = category === 'license' ? 'TG-LIC' :
122
+ category === 'pqc' ? 'TG-PQC' :
123
+ category === 'aimodel' ? 'TG-AI' : 'TG-SEC';
124
+ const rand = crypto.randomBytes(3).toString('hex').toUpperCase();
125
+ return `${prefix}-${rand}`;
126
+ }
127
+
128
+ function classifyAuthor(context = {}) {
129
+ if (context.isAgent || process.env.THUMBGATE_SESSION_AGENT || process.env.CLAUDE_CODE || process.env.CURSOR_PROJECT_DIR) {
130
+ return AUTHOR_AGENT;
131
+ }
132
+ if (context.isVendor || context.path?.includes('node_modules') || context.path?.includes('vendor')) {
133
+ return AUTHOR_OPENSOURCE;
134
+ }
135
+ return AUTHOR_HUMAN;
136
+ }
137
+
138
+ function recordFinding(finding, cwd) {
139
+ try {
140
+ const targetPath = resolveFindingsLedgerPath(cwd);
141
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
142
+ fs.appendFileSync(targetPath, JSON.stringify({
143
+ timestamp: new Date().toISOString(),
144
+ ...finding
145
+ }) + '\n', 'utf8');
146
+ } catch (_) {}
147
+ }
148
+
149
+ function getFindingById(findingId, cwd) {
150
+ const primaryPath = resolveFindingsLedgerPath(cwd);
151
+ const candidates = [primaryPath];
152
+ const pkgFallback = path.join(__dirname, '..', '.thumbgate', 'findings-ledger.jsonl');
153
+ if (pkgFallback !== primaryPath) {
154
+ candidates.push(pkgFallback);
155
+ }
156
+
157
+ for (const p of candidates) {
158
+ if (!fs.existsSync(p)) continue;
159
+ try {
160
+ const lines = fs.readFileSync(p, 'utf8').trim().split('\n');
161
+ for (let i = lines.length - 1; i >= 0; i--) {
162
+ try {
163
+ const item = JSON.parse(lines[i]);
164
+ if (item.findingId === findingId) return item;
165
+ } catch (_) {}
166
+ }
167
+ } catch (_) {}
168
+ }
169
+ return null;
170
+ }
171
+
172
+ /**
173
+ * Checkpoint 1: MCP / PreToolUse Gate
174
+ * Evaluates proposed tool calls in sub-millisecond time.
175
+ */
176
+ function evaluateMcpPreToolUse({ toolName, toolInput, authorContext = {} }) {
177
+ const startTime = Date.now();
178
+ const author = classifyAuthor(authorContext);
179
+
180
+ if (toolName?.toLowerCase() === 'bash' || toolName?.toLowerCase() === 'terminal' || toolName?.toLowerCase() === 'run_command') {
181
+ const cmd = String(toolInput?.command || toolInput?.CommandLine || '');
182
+
183
+ // 1. Check for copyleft package installs
184
+ for (const [pkg, alts] of Object.entries(PERMISSIVE_ALTERNATIVES)) {
185
+ const pkgRegex = new RegExp(`\\b(npm\\s+i(nstall)?|yarn\\s+add|pnpm\\s+add|pip\\s+install)\\s+.*\\b${pkg}\\b`, 'i');
186
+ if (pkgRegex.test(cmd)) {
187
+ const findingId = generateFindingId('license');
188
+ const altText = alts.map(a => `${a.name} (${a.license}) - ${a.description}`).join('; ');
189
+ const reason = `[THIRD-AUTHOR:copyleft-license] Prohibited copyleft dependency '${pkg}' detected in proposed command. Author: ${author}. Suggested permissive alternatives: ${altText}`;
190
+
191
+ const finding = {
192
+ findingId,
193
+ checkpoint: 'mcp_pretooluse',
194
+ author,
195
+ category: 'license_compliance',
196
+ package: pkg,
197
+ severity: 'critical',
198
+ command: cmd,
199
+ decision: 'deny',
200
+ reason,
201
+ alternatives: alts
202
+ };
203
+ recordFinding(finding, authorContext.cwd);
204
+
205
+ return {
206
+ hookEventName: 'PreToolUse',
207
+ permissionDecision: 'deny',
208
+ permissionDecisionReason: reason,
209
+ findingId,
210
+ alternatives: alts,
211
+ evalLatencyMs: Date.now() - startTime
212
+ };
213
+ }
214
+ }
215
+
216
+ // 2. Check for pipe-to-bash unpinned supply chain downloads
217
+ const isStrict = process.env.THUMBGATE_STRICT_ENFORCEMENT === '1' ||
218
+ process.env.THUMBGATE_GOVERNANCE_MODE === 'live' ||
219
+ Boolean(authorContext.strict);
220
+
221
+ if (/\b(curl|wget)\b[^|]*\|\s*(sudo\s+)?(ba|z|da)?sh\b/i.test(cmd)) {
222
+ const isDeny = isStrict || /\bsudo\b/i.test(cmd);
223
+ const findingId = generateFindingId('security');
224
+ const reason = isDeny
225
+ ? `[THIRD-AUTHOR:untrusted-pipe-to-shell] Direct pipe from remote network curl/wget to shell execution blocked. Download and verify hash before running.`
226
+ : `[THIRD-AUTHOR:untrusted-pipe-to-shell] Warning: Direct pipe from remote network curl/wget to shell execution detected. Download and verify hash before running.`;
227
+ const finding = {
228
+ findingId,
229
+ checkpoint: 'mcp_pretooluse',
230
+ author,
231
+ category: 'security_vulnerabilities',
232
+ command: cmd,
233
+ decision: isDeny ? 'deny' : 'warn',
234
+ reason
235
+ };
236
+ recordFinding(finding, authorContext.cwd);
237
+
238
+ return {
239
+ hookEventName: 'PreToolUse',
240
+ permissionDecision: isDeny ? 'deny' : 'allow',
241
+ permissionDecisionReason: reason,
242
+ findingId,
243
+ author,
244
+ evalLatencyMs: Date.now() - startTime
245
+ };
246
+ }
247
+ }
248
+
249
+ return {
250
+ hookEventName: 'PreToolUse',
251
+ permissionDecision: 'allow',
252
+ author,
253
+ evalLatencyMs: Date.now() - startTime
254
+ };
255
+ }
256
+
257
+ /**
258
+ * Risk 2: Cryptography & PQC (Post-Quantum Cryptography) Audit
259
+ */
260
+ function scanCryptographyAndPqc(content, filePath = 'snippet') {
261
+ const findings = [];
262
+ for (const item of CRYPTO_PQC_CATALOG) {
263
+ if (item.pattern.test(content)) {
264
+ const findingId = generateFindingId('pqc');
265
+ findings.push({
266
+ findingId,
267
+ category: 'cryptography_pqc',
268
+ algorithm: item.name,
269
+ status: item.status,
270
+ severity: item.severity,
271
+ pqcTransition: item.pqcTransition,
272
+ filePath
273
+ });
274
+ }
275
+ }
276
+ return findings;
277
+ }
278
+
279
+ /**
280
+ * Risk 3: License Compliance Audit
281
+ */
282
+ function auditPackageLicenses(packageJsonContent, filePath = 'package.json') {
283
+ const findings = [];
284
+ try {
285
+ const pkg = typeof packageJsonContent === 'string' ? JSON.parse(packageJsonContent) : packageJsonContent;
286
+ const allDeps = {
287
+ ...(pkg.dependencies || {}),
288
+ ...(pkg.devDependencies || {}),
289
+ };
290
+
291
+ for (const dep of Object.keys(allDeps)) {
292
+ if (PERMISSIVE_ALTERNATIVES[dep]) {
293
+ const findingId = generateFindingId('license');
294
+ findings.push({
295
+ findingId,
296
+ category: 'license_compliance',
297
+ package: dep,
298
+ detectedLicense: 'AGPL-3.0 / Copyleft',
299
+ severity: 'critical',
300
+ filePath,
301
+ alternatives: PERMISSIVE_ALTERNATIVES[dep]
302
+ });
303
+ }
304
+ }
305
+ } catch (_) {}
306
+ return findings;
307
+ }
308
+
309
+ /**
310
+ * Checkpoint 2: Git Pre-Commit Hook Validator
311
+ */
312
+ function evaluatePreCommit({ stagedFiles = [], repoRoot = process.cwd() }) {
313
+ const findings = [];
314
+ for (const file of stagedFiles) {
315
+ const fullPath = path.resolve(repoRoot, file);
316
+ if (!fs.existsSync(fullPath)) continue;
317
+ try {
318
+ const content = fs.readFileSync(fullPath, 'utf8');
319
+
320
+ // 1. Scan for PQC and broken cryptography
321
+ const cryptoFindings = scanCryptographyAndPqc(content, file);
322
+ findings.push(...cryptoFindings);
323
+
324
+ // 2. Scan package.json for license risks
325
+ if (path.basename(file) === 'package.json') {
326
+ const licFindings = auditPackageLicenses(content, file);
327
+ findings.push(...licFindings);
328
+ }
329
+ } catch (_) {}
330
+ }
331
+
332
+ const criticalFindings = findings.filter(f => f.severity === 'critical');
333
+ const verdict = criticalFindings.length > 0 ? 'block' : (findings.length > 0 ? 'warn' : 'pass');
334
+
335
+ for (const f of findings) {
336
+ recordFinding({ ...f, checkpoint: 'pre-commit' });
337
+ }
338
+
339
+ return {
340
+ checkpoint: 'pre-commit',
341
+ verdict,
342
+ findingsCount: findings.length,
343
+ criticalCount: criticalFindings.length,
344
+ findings,
345
+ remediationCommand: findings.length > 0 ? `npx thumbgate explain ${findings[0].findingId}` : null
346
+ };
347
+ }
348
+
349
+ /**
350
+ * Checkpoint 3: PR Gate / CI Evaluator
351
+ */
352
+ function evaluatePrGate({ diffContent = '', prNumber = 0, author = AUTHOR_AGENT }) {
353
+ const cryptoFindings = scanCryptographyAndPqc(diffContent, `PR #${prNumber} diff`);
354
+ const critical = cryptoFindings.filter(f => f.severity === 'critical');
355
+
356
+ let verdict = 'pass';
357
+ if (critical.length > 0) {
358
+ verdict = 'block';
359
+ } else if (cryptoFindings.length > 0) {
360
+ verdict = 'require_approval';
361
+ }
362
+
363
+ return {
364
+ checkpoint: 'pull_request',
365
+ prNumber,
366
+ author,
367
+ verdict,
368
+ findings: cryptoFindings
369
+ };
370
+ }
371
+
372
+ /**
373
+ * Format Explain Finding Output
374
+ */
375
+ function formatExplainFinding(finding) {
376
+ if (!finding) {
377
+ return 'Finding not found in ThumbGate ledger.';
378
+ }
379
+
380
+ const lines = [
381
+ `============================================================`,
382
+ `ThumbGate Finding Evidence: ${finding.findingId}`,
383
+ `============================================================`,
384
+ `Category: ${finding.category || 'general'}`,
385
+ `Severity: ${(finding.severity || 'unknown').toUpperCase()}`,
386
+ `Checkpoint: ${finding.checkpoint || 'audit'}`,
387
+ `Author: ${finding.author || 'unknown'}`,
388
+ `Decision: ${finding.decision || finding.verdict || 'flagged'}`,
389
+ `Reason: ${finding.reason || finding.pqcTransition || 'Policy invariant violated'}`,
390
+ ``
391
+ ];
392
+
393
+ if (finding.command) {
394
+ lines.push(`Offending Command:`);
395
+ lines.push(` ${finding.command}`);
396
+ lines.push(``);
397
+ }
398
+
399
+ if (finding.alternatives && finding.alternatives.length > 0) {
400
+ lines.push(`Permissive Alternatives (Approved):`);
401
+ finding.alternatives.forEach(alt => {
402
+ lines.push(` • ${alt.name} [${alt.license}]: ${alt.description}`);
403
+ });
404
+ lines.push(``);
405
+ }
406
+
407
+ if (finding.pqcTransition) {
408
+ lines.push(`Post-Quantum Cryptography Guidance:`);
409
+ lines.push(` ${finding.pqcTransition}`);
410
+ lines.push(``);
411
+ }
412
+
413
+ lines.push(`Remediation:`);
414
+ lines.push(` Substitute the non-compliant dependency or algorithm with an approved alternative.`);
415
+ lines.push(`============================================================`);
416
+
417
+ return lines.join('\n');
418
+ }
419
+
420
+ module.exports = {
421
+ AUTHOR_HUMAN,
422
+ AUTHOR_OPENSOURCE,
423
+ AUTHOR_AGENT,
424
+ PERMISSIVE_ALTERNATIVES,
425
+ CRYPTO_PQC_CATALOG,
426
+ RESTRICTIVE_LICENSES,
427
+ classifyAuthor,
428
+ evaluateMcpPreToolUse,
429
+ scanCryptographyAndPqc,
430
+ auditPackageLicenses,
431
+ evaluatePreCommit,
432
+ evaluatePrGate,
433
+ getFindingById,
434
+ recordFinding,
435
+ formatExplainFinding,
436
+ resolveFindingsLedgerPath
437
+ };