thumbgate 1.39.1 → 1.40.1

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 (160) 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 +62 -28
  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 +159 -69
  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 +75 -60
  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-window.js +7 -1
  67. package/scripts/async-job-runner.js +66 -11
  68. package/scripts/audit-trail.js +37 -24
  69. package/scripts/auto-promote-gates.js +37 -27
  70. package/scripts/backfill-lesson-scopes.js +122 -0
  71. package/scripts/billing.js +889 -132
  72. package/scripts/bot-detection.js +112 -0
  73. package/scripts/brand-standards-gate.js +571 -0
  74. package/scripts/chatgpt-ads-readiness-pack.js +1 -1
  75. package/scripts/cli-schema.js +1 -1
  76. package/scripts/commercial-offer.js +2 -2
  77. package/scripts/contextfs.js +9 -3
  78. package/scripts/cross-encoder-reranker.js +4 -0
  79. package/scripts/dashboard-chat.js +11 -0
  80. package/scripts/dashboard.js +574 -167
  81. package/scripts/decision-journal.js +7 -4
  82. package/scripts/docker-sandbox-planner.js +3 -3
  83. package/scripts/export-dpo-pairs.js +12 -7
  84. package/scripts/feedback-aggregate.js +4 -0
  85. package/scripts/feedback-attribution.js +6 -4
  86. package/scripts/feedback-history-distiller.js +18 -6
  87. package/scripts/feedback-loop.js +255 -89
  88. package/scripts/feedback-paths.js +8 -1
  89. package/scripts/feedback-sanitizer.js +5 -0
  90. package/scripts/feedback-scope.js +106 -0
  91. package/scripts/feedback-session.js +8 -2
  92. package/scripts/filesystem-search.js +13 -8
  93. package/scripts/financial-control-plane.js +707 -45
  94. package/scripts/gate-stats.js +8 -2
  95. package/scripts/gates-engine.js +694 -230
  96. package/scripts/generate-eval-scorecard.js +0 -1
  97. package/scripts/harness-tool-names.js +31 -5
  98. package/scripts/hybrid-feedback-context.js +5 -2
  99. package/scripts/intervention-policy.js +2 -1
  100. package/scripts/lesson-canonical.js +2 -2
  101. package/scripts/lesson-db.js +55 -14
  102. package/scripts/lesson-graph.js +2 -1
  103. package/scripts/lesson-retrieval.js +95 -9
  104. package/scripts/lesson-search.js +86 -22
  105. package/scripts/lesson-synthesis.js +21 -5
  106. package/scripts/mailer/index.js +17 -1
  107. package/scripts/mailer/resend-mailer.js +213 -179
  108. package/scripts/migrate-project-scope.js +209 -0
  109. package/scripts/operational-integrity.js +436 -3
  110. package/scripts/override-audit.js +2 -0
  111. package/scripts/owner-admin.js +338 -0
  112. package/scripts/pr-manager.js +194 -1
  113. package/scripts/progressive-signoff.js +260 -0
  114. package/scripts/project-catalog.js +243 -0
  115. package/scripts/project-dashboard.js +61 -0
  116. package/scripts/project-evidence.js +172 -0
  117. package/scripts/project-identity.js +182 -0
  118. package/scripts/project-scope.js +381 -0
  119. package/scripts/prompt-guard.js +446 -52
  120. package/scripts/proof-report.js +232 -0
  121. package/scripts/provider-action-normalizer.js +14 -6
  122. package/scripts/rate-limiter.js +41 -0
  123. package/scripts/secret-redaction.js +171 -25
  124. package/scripts/secret-scanner.js +101 -42
  125. package/scripts/self-protection.js +2 -2
  126. package/scripts/seo-gsd.js +14 -14
  127. package/scripts/session-context-dedupe.js +66 -0
  128. package/scripts/settings-hierarchy.js +4 -2
  129. package/scripts/statusline-meta.js +34 -23
  130. package/scripts/task-outcomes.js +29 -2
  131. package/scripts/telemetry-analytics.js +238 -13
  132. package/scripts/thumbgate-search.js +23 -9
  133. package/scripts/tool-kpi-tracker.js +5 -2
  134. package/scripts/tool-registry.js +42 -1
  135. package/scripts/triage-savings-calculator.js +1 -1
  136. package/scripts/vector-store.js +4 -1
  137. package/scripts/verified-lessons.js +270 -0
  138. package/scripts/verify-marketing-pages-deployed.js +2 -2
  139. package/scripts/workflow-sentinel.js +29 -10
  140. package/server.json +2 -2
  141. package/src/api/server.js +2371 -451
  142. package/src/feedback.js +21 -0
  143. package/src/hermes-sync-plane.js +2 -1
  144. package/src/index.js +2 -0
  145. package/src/lesson-search.js +9 -0
  146. package/src/mckinsey-top-company-ai-coding.js +493 -0
  147. package/src/mcp/server.js +3 -0
  148. package/src/mcp-writeguard.js +772 -11
  149. package/src/openshell-lovable-engine.js +1475 -0
  150. package/src/task-outcome.js +3 -0
  151. package/config/evals/agent-safety-eval.json +0 -447
  152. package/config/evals/retrieval-ranking-golden.json +0 -522
  153. package/config/progressive/01-wire-only.json +0 -11
  154. package/config/progressive/02-dashboard-empty-ok.json +0 -10
  155. package/config/progressive/03-one-lesson.json +0 -10
  156. package/config/progressive/04-warn-fires.json +0 -11
  157. package/config/progressive/05-strict-optional.json +0 -11
  158. package/config/progressive/README.md +0 -15
  159. package/public/assets/diagrams/agent-integration.png +0 -0
  160. package/public/assets/diagrams/thumbgate-architecture.png +0 -0
@@ -34,7 +34,7 @@ const SECRET_FILE_PATTERNS = [
34
34
  { id: 'pypirc_file', label: 'Python package credentials file', regex: /(^|\/)\.pypirc$/i },
35
35
  // Do not match *.pub — public keys are routinely read for SSH setup.
36
36
  { id: 'ssh_private_key', label: 'SSH private key', regex: /(^|\/)(?:id_rsa|id_ed25519|id_dsa|id_ecdsa)$/i },
37
- { id: 'ssh_private_key_path', label: 'SSH private key path', regex: /(^|\/)\.ssh\/id_[A-Za-z0-9_-]+$/i },
37
+ { id: 'ssh_private_key_path', label: 'SSH private key path', regex: /(^|\/)\.ssh\/id_[a-z0-9_-]+$/i },
38
38
  { id: 'aws_credentials', label: 'AWS credentials file', regex: /(^|\/)\.aws\/credentials$/i },
39
39
  { id: 'kubeconfig', label: 'Kubernetes config', regex: /(^|\/)\.kube\/config$/i },
40
40
  { id: 'docker_config', label: 'Docker config credentials', regex: /(^|\/)\.docker\/config\.json$/i },
@@ -44,7 +44,46 @@ const SECRET_FILE_PATTERNS = [
44
44
 
45
45
  // Env vars that commonly hold secrets. Used to catch exfil when the secret
46
46
  // never appears as a literal in the command (e.g. echo $API_KEY | curl ...).
47
- const SECRET_ENV_VAR_PATTERN = /\$\{?(?:API[_-]?KEY|OPENAI_API_KEY|ANTHROPIC_API_KEY|GEMINI_API_KEY|AWS_SECRET_ACCESS_KEY|AWS_ACCESS_KEY_ID|AWS_SESSION_TOKEN|GITHUB_TOKEN|GH_TOKEN|STRIPE_SECRET_KEY|STRIPE_API_KEY|NPM_TOKEN|HF_TOKEN|HUGGINGFACE_TOKEN|DATABASE_URL|DB_PASSWORD|POSTGRES_PASSWORD|MYSQL_PWD|PRIVATE_KEY|SECRET_KEY|ACCESS_TOKEN|AUTH_TOKEN|CLIENT_SECRET|SLACK_BOT_TOKEN|DISCORD_TOKEN)(?!\w)/i;
47
+ const SECRET_ENV_VAR_NAMES = new Set([
48
+ 'API_KEY',
49
+ 'APIKEY',
50
+ 'API-KEY',
51
+ 'OPENAI_API_KEY',
52
+ 'ANTHROPIC_API_KEY',
53
+ 'GEMINI_API_KEY',
54
+ 'AWS_SECRET_ACCESS_KEY',
55
+ 'AWS_ACCESS_KEY_ID',
56
+ 'AWS_SESSION_TOKEN',
57
+ 'GITHUB_TOKEN',
58
+ 'GH_TOKEN',
59
+ 'STRIPE_SECRET_KEY',
60
+ 'STRIPE_API_KEY',
61
+ 'NPM_TOKEN',
62
+ 'HF_TOKEN',
63
+ 'HUGGINGFACE_TOKEN',
64
+ 'DATABASE_URL',
65
+ 'DB_PASSWORD',
66
+ 'POSTGRES_PASSWORD',
67
+ 'MYSQL_PWD',
68
+ 'PRIVATE_KEY',
69
+ 'SECRET_KEY',
70
+ 'ACCESS_TOKEN',
71
+ 'AUTH_TOKEN',
72
+ 'CLIENT_SECRET',
73
+ 'SLACK_BOT_TOKEN',
74
+ 'DISCORD_TOKEN',
75
+ ]);
76
+
77
+ function hasSecretEnvVarRef(text) {
78
+ const input = String(text || '');
79
+ const refRe = /\$\{?([a-z0-9_-]+)(?!\w)/gi;
80
+ let match = refRe.exec(input);
81
+ while (match) {
82
+ if (SECRET_ENV_VAR_NAMES.has(match[1].toUpperCase())) return true;
83
+ match = refRe.exec(input);
84
+ }
85
+ return false;
86
+ }
48
87
 
49
88
  const BASH_SECRET_READ_PREFIXES = [
50
89
  'cat',
@@ -221,6 +260,23 @@ function sonarScanFile(filePath) {
221
260
  };
222
261
  }
223
262
 
263
+ function isCodePropertyAccessValue(rawMatch, nextChar) {
264
+ const sepIdx = rawMatch.search(/[:=]/);
265
+ if (sepIdx === -1) return false;
266
+ const rhs = rawMatch.slice(sepIdx + 1).trim();
267
+ const isQuoted = (rhs.startsWith('"') && rhs.endsWith('"')) || (rhs.startsWith("'") && rhs.endsWith("'"));
268
+ if (isQuoted) return false;
269
+ if (nextChar === '(' && /^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(rhs)) return true;
270
+ return /^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)+$/.test(rhs);
271
+ }
272
+
273
+ function shouldSkipGenericAssignment(patternId, rawMatch, nextChar) {
274
+ if (patternId !== 'generic_assignment') return false;
275
+ const lowered = rawMatch.toLowerCase();
276
+ if (lowered.includes('sk_test_') || lowered.includes('test_token')) return true;
277
+ return isCodePropertyAccessValue(rawMatch, nextChar);
278
+ }
279
+
224
280
  function heuristicScanText(text, source = 'text') {
225
281
  const input = String(text || '');
226
282
  const findings = [];
@@ -228,20 +284,16 @@ function heuristicScanText(text, source = 'text') {
228
284
  pattern.regex.lastIndex = 0;
229
285
  let match = pattern.regex.exec(input);
230
286
  while (match) {
231
- // Safe test key bypass
232
- const matchedString = match[0].toLowerCase();
233
- if (pattern.id === 'generic_assignment' && (matchedString.includes('sk_test_') || matchedString.includes('test_token'))) {
234
- match = pattern.regex.exec(input);
235
- continue;
287
+ const nextChar = input[match.index + match[0].length] || '';
288
+ if (!shouldSkipGenericAssignment(pattern.id, match[0], nextChar)) {
289
+ findings.push({
290
+ id: pattern.id,
291
+ label: pattern.label,
292
+ source,
293
+ line: computeLineNumber(input, match.index),
294
+ reason: `${pattern.label} detected`,
295
+ });
236
296
  }
237
-
238
- findings.push({
239
- id: pattern.id,
240
- label: pattern.label,
241
- source,
242
- line: computeLineNumber(input, match.index),
243
- reason: `${pattern.label} detected`,
244
- });
245
297
  match = pattern.regex.exec(input);
246
298
  }
247
299
  }
@@ -706,9 +758,9 @@ function detectCommandSubstitutionExfil(command, cwd) {
706
758
  // $(cat .env), $(base64 .env), `cat .env`, <(cat .env) — secret not literal in curl argv.
707
759
  const findings = [];
708
760
  const patterns = [
709
- /\$\(\s*([a-z0-9._+-]+)\s+([^)]+)\)/gi,
710
- /`\s*([a-z0-9._+-]+)\s+([^`]+)`/gi,
711
- /<\(\s*([a-z0-9._+-]+)\s+([^)]+)\)/gi,
761
+ /\$\(\s*([a-z0-9._+-]+)\s+([^\s)][^)]*)\)/gi,
762
+ /`\s*([a-z0-9._+-]+)\s+([^\s`][^`]*)`/gi,
763
+ /<\(\s*([a-z0-9._+-]+)\s+([^\s)][^)]*)\)/gi,
712
764
  ];
713
765
  for (const pattern of patterns) {
714
766
  pattern.lastIndex = 0;
@@ -744,7 +796,7 @@ function detectCommandSubstitutionExfil(command, cwd) {
744
796
  function detectPipelineExfil(command, cwd) {
745
797
  // cat .env | nc … ; base64 .env | curl … ; echo $API_KEY | curl …
746
798
  const findings = [];
747
- const segments = String(command || '').split(/(?<![|])\|(?![|])/);
799
+ const segments = String(command || '').split(/(?<!\|)\|(?!\|)/);
748
800
  if (segments.length < 2) return findings;
749
801
 
750
802
  for (let i = 0; i < segments.length - 1; i += 1) {
@@ -762,8 +814,7 @@ function detectPipelineExfil(command, cwd) {
762
814
  });
763
815
  }
764
816
 
765
- SECRET_ENV_VAR_PATTERN.lastIndex = 0;
766
- if (SECRET_ENV_VAR_PATTERN.test(left) || SECRET_ENV_VAR_PATTERN.test(right)) {
817
+ if (hasSecretEnvVarRef(left) || hasSecretEnvVarRef(right)) {
767
818
  findings.push({
768
819
  id: 'secret_env_exfil',
769
820
  label: 'Secret environment variable',
@@ -775,7 +826,29 @@ function detectPipelineExfil(command, cwd) {
775
826
  return findings;
776
827
  }
777
828
 
778
- function detectScpRsyncExfil(command, cwd) {
829
+ function resolveTransferLocalSide(token) {
830
+ const str = String(token);
831
+ if (str.includes(':') && !str.startsWith('/')) {
832
+ return str.split(':').slice(1).join(':');
833
+ }
834
+ return token;
835
+ }
836
+
837
+ function collectTransferTokenFindings(tokens, verb, findings) {
838
+ for (const token of tokens) {
839
+ if (String(token).startsWith('-')) continue;
840
+ const localSide = resolveTransferLocalSide(token);
841
+ const pathFinding = classifySecretPathToken(localSide) || classifySecretPathToken(token);
842
+ if (!pathFinding) continue;
843
+ findings.push({
844
+ ...pathFinding,
845
+ source: 'transfer_exfil',
846
+ reason: `${pathFinding.label} referenced by ${verb} transfer`,
847
+ });
848
+ }
849
+ }
850
+
851
+ function detectScpRsyncExfil(command) {
779
852
  const findings = [];
780
853
  for (const segment of splitCommandSegments(command)) {
781
854
  const tokens = tokenizeCommand(segment);
@@ -783,20 +856,8 @@ function detectScpRsyncExfil(command, cwd) {
783
856
  let index = 0;
784
857
  while (isShellAssignment(tokens[index])) index += 1;
785
858
  const verb = path.basename(String(tokens[index] || '')).toLowerCase();
786
- if (verb !== 'scp' && verb !== 'rsync' && verb !== 'sftp') continue;
787
- for (const token of tokens.slice(index + 1)) {
788
- if (String(token).startsWith('-')) continue;
789
- // scp local secret → remote OR remote → local (still sensitive move)
790
- const localSide = String(token).includes(':') && !String(token).startsWith('/')
791
- ? String(token).split(':').slice(1).join(':')
792
- : token;
793
- const pathFinding = classifySecretPathToken(localSide) || classifySecretPathToken(token);
794
- if (!pathFinding) continue;
795
- findings.push({
796
- ...pathFinding,
797
- source: 'transfer_exfil',
798
- reason: `${pathFinding.label} referenced by ${verb} transfer`,
799
- });
859
+ if (verb === 'scp' || verb === 'rsync' || verb === 'sftp') {
860
+ collectTransferTokenFindings(tokens.slice(index + 1), verb, findings);
800
861
  }
801
862
  }
802
863
  return findings;
@@ -808,8 +869,7 @@ function detectEnvVarNetworkExfil(command) {
808
869
  // Require a parsed network/transfer verb or /dev/tcp — a URL in docs text alone
809
870
  // must not hard-deny (e.g. printf 'Set $OPENAI_API_KEY then visit https://…').
810
871
  const text = String(command || '');
811
- SECRET_ENV_VAR_PATTERN.lastIndex = 0;
812
- const hasEnvRef = SECRET_ENV_VAR_PATTERN.test(text)
872
+ const hasEnvRef = hasSecretEnvVarRef(text)
813
873
  || /\bprintenv\s+(?:API[_-]?KEY|OPENAI_API_KEY|ANTHROPIC_API_KEY|AWS_SECRET_ACCESS_KEY|GITHUB_TOKEN|GH_TOKEN|STRIPE_SECRET_KEY|NPM_TOKEN|ACCESS_TOKEN|CLIENT_SECRET)\b/i.test(text)
814
874
  || /\benv\s+(?:API[_-]?KEY|OPENAI_API_KEY|ANTHROPIC_API_KEY|AWS_SECRET_ACCESS_KEY|GITHUB_TOKEN)\b/i.test(text);
815
875
  if (!hasEnvRef) return [];
@@ -835,7 +895,7 @@ function detectRedirectExfil(command, cwd) {
835
895
  if (!hasNetwork) return findings;
836
896
 
837
897
  // stdin redirect from a secret path
838
- const redirectRe = /(?:^|[\s;|&])\d*\s*<\s*([^\s;|&><]+)/g;
898
+ const redirectRe = /(?<=^|[\s;|&0-9])<\s*([^\s;|&><]+)/g;
839
899
  let match = redirectRe.exec(text);
840
900
  while (match) {
841
901
  const pathFinding = classifySecretPathToken(match[1]);
@@ -848,7 +908,6 @@ function detectRedirectExfil(command, cwd) {
848
908
  }
849
909
  match = redirectRe.exec(text);
850
910
  }
851
-
852
911
  // Bash /dev/tcp with secret path anywhere in the same command
853
912
  if (/\/dev\/tcp\//i.test(text)) {
854
913
  const tokens = tokenizeCommand(text.replace(/[<>]/g, ' '));
@@ -945,7 +1004,7 @@ function detectArchivePipeExfil(command, cwd) {
945
1004
  if (!/\|/.test(text) && !segmentHasNetworkExfil(text) && !/https?:\/\//i.test(text)) {
946
1005
  return findings;
947
1006
  }
948
- const segments = text.split(/(?<![|])\|(?![|])/);
1007
+ const segments = text.split(/(?<!\|)\|(?!\|)/);
949
1008
  const left = segments[0] || text;
950
1009
  const archiveVerb = path.basename(String(tokenizeCommand(left)[0] || '')).toLowerCase();
951
1010
  if (!['tar', 'zip', 'gzip', 'pigz', '7z', 'rar'].includes(archiveVerb)) {
@@ -984,7 +1043,7 @@ function detectInterpreterExfil(command, cwd) {
984
1043
  && /(?:-c|-e|--eval)\b/i.test(text);
985
1044
  if (!isInterpreter) return [];
986
1045
 
987
- const touchesSecretPath = /\.env(?:\.[A-Za-z0-9_-]+)?|\.aws\/credentials|\.ssh\/id_|\.netrc|\.npmrc|application_default_credentials/i.test(text);
1046
+ const touchesSecretPath = /\.env(?:\.[a-z0-9_-]+)?|\.aws\/credentials|\.ssh\/id_|\.netrc|\.npmrc|application_default_credentials/i.test(text);
988
1047
  const touchesSecretEnv = /(?:API_KEY|OPENAI_API_KEY|AWS_SECRET|GITHUB_TOKEN|STRIPE_SECRET|os\.environ|process\.env)/i.test(text);
989
1048
  const touchesNetwork = /https?:\/\/|requests\.|urllib|fetch\(|http\.request|httpx\.|aiohttp|socket\.|urlopen/i.test(text);
990
1049
  if (!(touchesSecretPath || touchesSecretEnv) || !touchesNetwork) return [];
@@ -36,7 +36,7 @@ const SELF_GOVERNANCE_PATH_PATTERNS = [
36
36
  /(?:^|\/)thumbgate\.json$/i,
37
37
  ];
38
38
 
39
- const EDIT_LIKE_TOOLS = new Set(['Edit', 'Write', 'MultiEdit']);
39
+ const EDIT_LIKE_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
40
40
 
41
41
  /**
42
42
  * Returns the matched governance file path, or null. Accepts both camelCase
@@ -44,7 +44,7 @@ const EDIT_LIKE_TOOLS = new Set(['Edit', 'Write', 'MultiEdit']);
44
44
  */
45
45
  function selfProtectionTarget(toolName, toolInput) {
46
46
  if (!EDIT_LIKE_TOOLS.has(toolName)) return null;
47
- const filePath = String((toolInput && (toolInput.file_path || toolInput.filePath)) || '');
47
+ const filePath = String((toolInput && (toolInput.file_path || toolInput.filePath || toolInput.notebook_path || toolInput.notebookPath || toolInput.path)) || '');
48
48
  if (!filePath) return null;
49
49
  return SELF_GOVERNANCE_PATH_PATTERNS.some((re) => re.test(filePath)) ? filePath : null;
50
50
  }
@@ -784,7 +784,7 @@ const SEO_AGENT_SKILLS_GUARDRAILS_SPEC = Object.freeze({
784
784
  'Reviewer handoff gate: require the agent to summarize claim risk, source evidence, and next conversion path before a human approves.',
785
785
  ]],
786
786
  ['paragraphs', 'Where this creates revenue', [
787
- 'This turns SEO-agent interest into the same Workflow Hardening Sprint offer: harden one content workflow, prove one publish gate, and connect the page to checkout or team intake instead of shipping more ungoverned AI content.',
787
+ 'This turns SEO-agent interest into the same Setup Sprint offer: harden one content workflow, prove one publish gate, and connect the page to checkout or team intake instead of shipping more ungoverned AI content.',
788
788
  ]],
789
789
  ],
790
790
  faq: [
@@ -835,7 +835,7 @@ const CLAUDE_CODE_SKILLS_GUARDRAILS_SPEC = Object.freeze({
835
835
  'Require each skill to name inputs, forbidden actions, verification steps, and examples of good and bad execution.',
836
836
  'Capture thumbs-down failures from skill use and promote repeat patterns into ThumbGate prevention rules.',
837
837
  'Block risky actions when the current task claims a skill but skips its required verification.',
838
- 'Route buyers into the Workflow Hardening Sprint when one skill repeatedly fails in a shared repo.',
838
+ 'Route buyers into the Setup Sprint when one skill repeatedly fails in a shared repo.',
839
839
  ]],
840
840
  ['paragraphs', 'Where this creates revenue', [
841
841
  'This is a concrete sales bridge from Claude Code training content to ThumbGate: if a team is investing in skills, they already believe AI coding workflows can improve. ThumbGate sells the part that makes those workflows reliable across sessions and teammates.',
@@ -995,7 +995,7 @@ const DEEPSEEK_V4_RUNTIME_GUARDRAILS_SPEC = Object.freeze({
995
995
  'CLI path: npx thumbgate deepseek-v4-runtime-guardrails --context-tokens=900000 --hybrid-attention --speculative-decoding --accept-length=1.4 --precision-mode=fp8 --json.',
996
996
  ]],
997
997
  ['paragraphs', 'Where this creates revenue', [
998
- 'This gives ThumbGate a serious infrastructure story for teams moving beyond hosted APIs. The offer is a Workflow Hardening Sprint around one model-routing lane: prove the runtime change, gate the risks, and keep the agent from silently routing expensive work through an unverified path.',
998
+ 'This gives ThumbGate a serious infrastructure story for teams moving beyond hosted APIs. The offer is a Setup Sprint around one model-routing lane: prove the runtime change, gate the risks, and keep the agent from silently routing expensive work through an unverified path.',
999
999
  ]],
1000
1000
  ],
1001
1001
  faq: [
@@ -1047,7 +1047,7 @@ const CODE_KNOWLEDGE_GRAPH_GUARDRAILS_SPEC = Object.freeze({
1047
1047
  ]],
1048
1048
  ['paragraphs', 'Where this creates revenue', [
1049
1049
  'This is a strong engagement wedge for audiences already excited about codebase understanding. The public line is simple: Code graphs tell the agent what the system is; ThumbGate decides what the agent is allowed to do next.',
1050
- 'For teams, sell the Workflow Hardening Sprint around one graph-informed repeated failure: one central file, one risky refactor path, or one generated artifact that agents keep touching incorrectly.',
1050
+ 'For teams, sell the Setup Sprint around one graph-informed repeated failure: one central file, one risky refactor path, or one generated artifact that agents keep touching incorrectly.',
1051
1051
  ]],
1052
1052
  ],
1053
1053
  faq: [
@@ -1094,7 +1094,7 @@ const DEVELOPER_MACHINE_SUPPLY_CHAIN_GUARDRAILS_SPEC = Object.freeze({
1094
1094
  ]],
1095
1095
  ['paragraphs', 'Where this creates revenue', [
1096
1096
  'This is a strong security wedge for teams that already run scanners but still let agents execute local install/update commands. The offer is not "replace your scanner"; it is "connect scanner and incident lessons to pre-action enforcement."',
1097
- 'For the Workflow Hardening Sprint, pick one concrete local-risk pattern: package lifecycle scripts, one-shot installers, dependency bot autofixes, or unresolved credential exposure after a suspected compromise.',
1097
+ 'For the Setup Sprint, pick one concrete local-risk pattern: package lifecycle scripts, one-shot installers, dependency bot autofixes, or unresolved credential exposure after a suspected compromise.',
1098
1098
  ]],
1099
1099
  ],
1100
1100
  faq: [
@@ -1141,7 +1141,7 @@ const PROMPT_TRICKS_TO_WORKFLOW_RULES_SPEC = Object.freeze({
1141
1141
  ]],
1142
1142
  ['paragraphs', 'Where this creates revenue', [
1143
1143
  'This turns generic prompt advice into a buyer-ready diagnostic. The public offer is simple: send one messy AI-agent workflow and ThumbGate turns it into clear rules, examples, and pre-action checks.',
1144
- 'For teams, position the Workflow Hardening Sprint around the repeated failure they can already name. The deliverable is not a better pep talk for the model; it is enforcement that survives across sessions and agents.',
1144
+ 'For teams, position the Setup Sprint around the repeated failure they can already name. The deliverable is not a better pep talk for the model; it is enforcement that survives across sessions and agents.',
1145
1145
  ]],
1146
1146
  ],
1147
1147
  faq: [
@@ -1188,7 +1188,7 @@ const BACKGROUND_AGENT_GOVERNANCE_GUIDE_SPEC = Object.freeze({
1188
1188
  'A risk check command for dispatch systems: npx thumbgate background-governance --check --agent-id=builder --branch=main --files-changed=25 --json.',
1189
1189
  ]],
1190
1190
  ['paragraphs', 'Where this creates revenue', [
1191
- 'This is a clean Workflow Hardening Sprint wedge. The buyer does not need a broad platform migration; they need one background-agent workflow hardened from context intake to isolated execution to risk-tiered review.',
1191
+ 'This is a clean Setup Sprint wedge. The buyer does not need a broad platform migration; they need one background-agent workflow hardened from context intake to isolated execution to risk-tiered review.',
1192
1192
  'The promise stays honest: ThumbGate does not remove human review. It makes the review queue smaller, better labeled, and backed by evidence before a risky agent PR reaches a reviewer.',
1193
1193
  ]],
1194
1194
  ],
@@ -1202,7 +1202,7 @@ const BACKGROUND_AGENT_GOVERNANCE_GUIDE_SPEC = Object.freeze({
1202
1202
  'Check recent agent failure rate, prior gate blocks, target branch, expected blast radius, isolated execution environment, CI expectations, and the human context that authorized the task.',
1203
1203
  ],
1204
1204
  [
1205
- 'How does this connect to the Workflow Hardening Sprint?',
1205
+ 'How does this connect to the Setup Sprint?',
1206
1206
  'The sprint can harden one background-agent workflow end to end: context intake, pre-dispatch governance, sandbox routing, CI audit, prevention rules, and proof review.',
1207
1207
  ],
1208
1208
  ],
@@ -1225,7 +1225,7 @@ const AI_AGENT_GOVERNANCE_SPRINT_GUIDE_SPEC = Object.freeze({
1225
1225
  query: 'ai agent governance sprint',
1226
1226
  title: 'AI Agent Governance Sprint | 48-Hour Workflow Hardening',
1227
1227
  heroTitle: 'AI Agent Governance Sprint for One Risky Workflow',
1228
- heroSummary: 'ThumbGate turns one repeated AI-agent failure into approval boundaries, pre-action checks, rollback safety, and rollout proof in a focused 48-hour Workflow Hardening Sprint.',
1228
+ heroSummary: 'ThumbGate turns one repeated AI-agent failure into approval boundaries, pre-action checks, rollback safety, and rollout proof in a focused 48-hour Setup Sprint.',
1229
1229
  },
1230
1230
  takeaways: [
1231
1231
  'The fastest paid wedge is not a broad platform migration; it is one repo, one workflow owner, and one repeated failure that already has budget pressure.',
@@ -1255,7 +1255,7 @@ const AI_AGENT_GOVERNANCE_SPRINT_GUIDE_SPEC = Object.freeze({
1255
1255
  'A focused 48-hour implementation around one workflow: intake, governance mapping, pre-action checks, background-agent risk routing, rollback notes, and a proof pack for the buyer review.',
1256
1256
  ],
1257
1257
  [
1258
- 'How is this different from the Workflow Hardening Sprint?',
1258
+ 'How is this different from the Setup Sprint?',
1259
1259
  'It is the same Team conversion path positioned for buyers searching for AI agent governance. The deliverable remains narrow: one repeated failure hardened with approval boundaries, rollback safety, and rollout proof.',
1260
1260
  ],
1261
1261
  [
@@ -1293,7 +1293,7 @@ const AI_DEPLOYMENT_READINESS_GUIDE_SPEC = Object.freeze({
1293
1293
  takeaways: [
1294
1294
  'AI deployment readiness is about workflow controls, not just prompts, demos, or model selection.',
1295
1295
  'The high-ROI starting point is one priority workflow with mapped tools, data, owners, risky actions, and proof-backed gates.',
1296
- 'ThumbGate turns deployment demand into revenue through a $499 diagnostic, a $1500 Workflow Hardening Sprint, and Team seats at $49/seat/mo.',
1296
+ 'ThumbGate turns deployment demand into revenue through a $499 diagnostic, a $1500 Setup Sprint, and Team seats at $49/seat/mo.',
1297
1297
  ],
1298
1298
  sections: [
1299
1299
  ['paragraphs', 'Why deployment is now the buying category', [
@@ -1323,7 +1323,7 @@ const AI_DEPLOYMENT_READINESS_GUIDE_SPEC = Object.freeze({
1323
1323
  ],
1324
1324
  [
1325
1325
  'Can this start before procurement?',
1326
- 'Yes. Start with one $499 diagnostic or the Workflow Hardening Sprint intake. The point is to prove one workflow before asking a buyer to fund a broad platform rollout.',
1326
+ 'Yes. Start with one $499 diagnostic or the Setup Sprint intake. The point is to prove one workflow before asking a buyer to fund a broad platform rollout.',
1327
1327
  ],
1328
1328
  ],
1329
1329
  relatedPaths: ['/guides/ai-agent-governance-sprint', '/guides/background-agent-governance', '/guides/pre-action-checks'],
@@ -1371,7 +1371,7 @@ const MODEL_UPGRADE_EVALUATION_GUIDE_SPEC = Object.freeze({
1371
1371
  ]],
1372
1372
  ['paragraphs', 'Where this creates ROI', [
1373
1373
  'This gives platform teams a defensible answer to "should we move to GPT-5.5?" Run the candidate report, attach gate and benchmark evidence, and only then route high-value analytical or long-context agent tasks to the frontier tier.',
1374
- 'The commercial wedge is a Workflow Hardening Sprint focused on model routing: define which workflows deserve frontier spend, which stay on cheap tiers, and which require pre-action checks before a model can touch live systems.',
1374
+ 'The commercial wedge is a Setup Sprint focused on model routing: define which workflows deserve frontier spend, which stay on cheap tiers, and which require pre-action checks before a model can touch live systems.',
1375
1375
  ]],
1376
1376
  ],
1377
1377
  faq: [
@@ -1591,7 +1591,7 @@ const AI_RECOMMENDATION_VISIBILITY_GUIDE_SPECS = Object.freeze([
1591
1591
  sections: [
1592
1592
  ['paragraphs', 'Why conversational ads change the promotion plan', [
1593
1593
  'Search ads are moving toward generated answers and product recommendations inside the search conversation. A buyer may not click ten blue links before forming an opinion; the assistant-like surface may summarize the category, compare options, and mention a vendor in one flow.',
1594
- 'That means ThumbGate promotion has to be answer-shaped. The page must say exactly what ThumbGate is, which agent-risk problem it solves, which tools it supports, and what proof a buyer can verify before starting checkout or a Workflow Hardening Sprint.',
1594
+ 'That means ThumbGate promotion has to be answer-shaped. The page must say exactly what ThumbGate is, which agent-risk problem it solves, which tools it supports, and what proof a buyer can verify before starting checkout or a Setup Sprint.',
1595
1595
  ]],
1596
1596
  ['bullets', 'Buyer prompts ThumbGate should target', [
1597
1597
  'How do I stop Claude Code or Cursor from repeating risky mistakes?',
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ // Per-session dedupe for the static context ThumbGate hooks attach to every tool call
4
+ // (recent corrective actions, recurring failure patterns). The same text re-read on every
5
+ // call costs input tokens; inject it only when it changed since the last injection in the
6
+ // same session. Context matched to the current tool call is never routed through here.
7
+
8
+ const crypto = require('node:crypto');
9
+ const fs = require('node:fs');
10
+ const os = require('node:os');
11
+ const path = require('node:path');
12
+
13
+ function storeDir(options = {}) {
14
+ return options.dir || process.env.THUMBGATE_CONTEXT_DEDUPE_DIR
15
+ || path.join(os.tmpdir(), 'thumbgate-context-dedupe');
16
+ }
17
+
18
+ function safeSessionId(sessionId) {
19
+ return String(sessionId || '').replace(/[^a-zA-Z0-9_-]/g, '').slice(0, 80);
20
+ }
21
+
22
+ function hashText(text) {
23
+ return crypto.createHash('sha256').update(String(text)).digest('hex');
24
+ }
25
+
26
+ function readHash(file) {
27
+ try {
28
+ return JSON.parse(fs.readFileSync(file, 'utf8')).hash || '';
29
+ } catch {
30
+ return '';
31
+ }
32
+ }
33
+
34
+ /**
35
+ * @param {string} sessionId
36
+ * @param {string|null} text static context for this call
37
+ * @returns {string|null} text if it should be injected, null if identical to the last
38
+ * injection in this session. Without a session id nothing is deduped.
39
+ */
40
+ function dedupeSessionContext(sessionId, text, options = {}) {
41
+ if (typeof text !== 'string' || text.length === 0) return null;
42
+ const sid = safeSessionId(sessionId);
43
+ if (!sid) return text;
44
+ const file = path.join(storeDir(options), `${sid}.json`);
45
+ const hash = hashText(text);
46
+ if (readHash(file) === hash) return null;
47
+ try {
48
+ fs.mkdirSync(path.dirname(file), { recursive: true });
49
+ fs.writeFileSync(file, JSON.stringify({ hash, at: Date.now() }));
50
+ } catch {
51
+ // a failed write only means the next call injects again
52
+ }
53
+ return text;
54
+ }
55
+
56
+ function logInjection(entry, options = {}) {
57
+ try {
58
+ const dir = options.logDir || process.env.THUMBGATE_CONTEXT_DEDUPE_LOG_DIR || storeDir(options);
59
+ fs.mkdirSync(dir, { recursive: true });
60
+ fs.appendFileSync(path.join(dir, 'injection-bytes.jsonl'), `${JSON.stringify(entry)}\n`);
61
+ } catch {
62
+ // logging is best effort
63
+ }
64
+ }
65
+
66
+ module.exports = { dedupeSessionContext, logInjection, hashText };
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ const { tenantDataScope } = require('./feedback-scope');
5
+
4
6
  const fs = require('fs');
5
7
  const os = require('os');
6
8
  const path = require('path');
@@ -86,8 +88,8 @@ function getNestedValue(target, dottedPath) {
86
88
  }
87
89
 
88
90
  function resolveSettingsPaths(options = {}) {
89
- const projectRoot = options.projectRoot || PROJECT_ROOT;
90
- const homeDir = options.homeDir || process.env.HOME || os.homedir();
91
+ const projectRoot = tenantDataScope()?.feedbackDir || options.projectRoot || PROJECT_ROOT;
92
+ const homeDir = tenantDataScope()?.feedbackDir || options.homeDir || process.env.HOME || os.homedir();
91
93
 
92
94
  return {
93
95
  managed: path.join(projectRoot, 'config', 'thumbgate-settings.managed.json'),
@@ -1,39 +1,50 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const path = require('path');
5
- const { isProLicensed, isValidKey } = require('./license');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const { verifyLicense, isProLicensed, isValidKey } = require('./license');
7
+
8
+ function readDiskOperatorKey(homeDir) {
9
+ try {
10
+ const configPath = path.join(homeDir, '.config', 'thumbgate', 'operator.json');
11
+ if (!fs.existsSync(configPath)) return '';
12
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
13
+ return config.operatorKey || config.apiKey || '';
14
+ } catch {
15
+ // Ignore missing or unreadable operator.json on personal machines
16
+ return '';
17
+ }
18
+ }
19
+
20
+ function resolveActiveTier(licenseResult, apiKey, options, env, homeDir) {
21
+ if ((licenseResult.valid && licenseResult.tier === 'enterprise') || apiKey.startsWith('tg_ent_')) {
22
+ return 'Enterprise';
23
+ }
24
+ if (licenseResult.valid && licenseResult.tier === 'team') {
25
+ return 'Team';
26
+ }
27
+ if (isProLicensed({ ...options, env, homeDir }) || apiKey.startsWith('tg_pro_')) {
28
+ return 'Pro';
29
+ }
30
+ return 'Free';
31
+ }
6
32
 
7
33
  function getStatuslineMeta(options = {}) {
8
34
  const pkg = require(path.join(__dirname, '..', 'package.json'));
9
35
  const env = options.env || process.env;
10
36
  const homeDir = options.homeDir || env.HOME || env.USERPROFILE || '.';
11
- const fs = require('fs');
12
-
13
- // Enterprise detection based on key prefix
37
+
14
38
  let apiKey = env.THUMBGATE_OPERATOR_KEY || env.THUMBGATE_API_KEY || '';
15
- if (apiKey && !isValidKey(apiKey)) {
39
+ if (apiKey && !isValidKey(apiKey, { env, homeDir })) {
16
40
  apiKey = '';
17
41
  }
18
-
19
- // Fallback to reading from disk if not in env
20
42
  if (!apiKey) {
21
- try {
22
- const configPath = path.join(homeDir, '.config', 'thumbgate', 'operator.json');
23
- if (fs.existsSync(configPath)) {
24
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
25
- apiKey = config.operatorKey || config.apiKey || '';
26
- }
27
- } catch (_) { /* ignore disk read errors */ }
43
+ apiKey = readDiskOperatorKey(homeDir);
28
44
  }
29
45
 
30
- let activeTier = 'Free';
31
-
32
- if (apiKey.startsWith('tg_op_') || apiKey.startsWith('tg_creator_')) {
33
- activeTier = 'Enterprise';
34
- } else if (isProLicensed({ homeDir }) || apiKey.startsWith('tg_pro_')) {
35
- activeTier = 'Pro';
36
- }
46
+ const licenseResult = verifyLicense({ ...options, env, homeDir });
47
+ const activeTier = resolveActiveTier(licenseResult, apiKey, options, env, homeDir);
37
48
 
38
49
  return {
39
50
  version: String(pkg.version || '').trim() || 'unknown',
@@ -41,7 +52,7 @@ function getStatuslineMeta(options = {}) {
41
52
  };
42
53
  }
43
54
 
44
- if (require.main === module) {
55
+ if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename)) {
45
56
  process.stdout.write(JSON.stringify(getStatuslineMeta()));
46
57
  }
47
58
 
@@ -13,6 +13,7 @@ const crypto = require('node:crypto');
13
13
  const fs = require('node:fs');
14
14
  const path = require('node:path');
15
15
  const { getFeedbackPaths } = require('./feedback-paths');
16
+ const { projectForCapture, projectForRecord, matchesProject } = require('./project-identity');
16
17
  const { validateToolContract } = require('./tool-contract-validator');
17
18
 
18
19
  const OUTCOMES_FILE = 'task-outcome-receipts.jsonl';
@@ -145,8 +146,9 @@ function recordTaskOutcome(input = {}, options = {}) {
145
146
  throw error;
146
147
  }
147
148
 
149
+ Object.assign(receipt, projectForCapture({ ...input, ...options }, { hosted: Boolean(options.projectKey || options.hosted || require('./feedback-scope').tenantDataScope() || process.env.RAILWAY_PROJECT_ID || process.env.RAILWAY_ENVIRONMENT) }));
148
150
  const outcomesPath = getTaskOutcomesPath(options);
149
- const existing = readTaskOutcomes(options);
151
+ const existing = readTaskOutcomes({ ...options, projectKey: receipt.projectKey });
150
152
  const duplicate = existing.find((entry) => entry.idempotencyKey === receipt.idempotencyKey);
151
153
  if (duplicate) {
152
154
  if (duplicate.receiptHash !== receipt.receiptHash) {
@@ -160,6 +162,30 @@ function recordTaskOutcome(input = {}, options = {}) {
160
162
  fs.mkdirSync(path.dirname(outcomesPath), { recursive: true });
161
163
  fs.appendFileSync(outcomesPath, `${JSON.stringify(receipt)}\n`, 'utf8');
162
164
  recordOutcomeTrace(receipt, options);
165
+
166
+ // If task outcome succeeded and verified, verify any applied lessons
167
+ try {
168
+ const isSuccess = receipt.status === 'completed' && receipt.verification?.passed === true;
169
+ const lessonsToVerify = Array.isArray(input.appliedLessons)
170
+ ? input.appliedLessons
171
+ : Array.isArray(input.lessonIds)
172
+ ? input.lessonIds
173
+ : Array.isArray(input.metadata?.appliedLessons)
174
+ ? input.metadata.appliedLessons
175
+ : [];
176
+ if (isSuccess && lessonsToVerify.length > 0) {
177
+ const { verifyLesson } = require('./verified-lessons');
178
+ const checkCmd = receipt.verification?.verifier
179
+ || receipt.verification?.method
180
+ || (receipt.verification?.evidence && receipt.verification.evidence[0])
181
+ || 'task outcome verification passed';
182
+ for (const lessonId of lessonsToVerify) {
183
+ verifyLesson(lessonId, checkCmd, options);
184
+ }
185
+ }
186
+ } catch (_verErr) {
187
+ /* lesson verification on task outcome is non-blocking */
188
+ }
163
189
  return { recorded: true, duplicate: false, receipt };
164
190
  }
165
191
 
@@ -178,7 +204,8 @@ function readTaskOutcomes(options = {}) {
178
204
  .filter(Boolean)
179
205
  .flatMap((line) => {
180
206
  try {
181
- return [JSON.parse(line)];
207
+ const row = JSON.parse(line);
208
+ return matchesProject(projectForRecord(row), options.projectKey) ? [row] : [];
182
209
  } catch {
183
210
  return [];
184
211
  }