thumbgate 1.25.1 → 1.26.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thumbgate-marketplace",
3
- "version": "1.25.1",
3
+ "version": "1.26.0",
4
4
  "owner": {
5
5
  "name": "Igor Ganapolsky",
6
6
  "email": "ig5973700@gmail.com"
@@ -14,7 +14,7 @@
14
14
  "source": "npm",
15
15
  "package": "thumbgate"
16
16
  },
17
- "version": "1.25.1",
17
+ "version": "1.26.0",
18
18
  "author": {
19
19
  "name": "Igor Ganapolsky",
20
20
  "email": "ig5973700@gmail.com",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "thumbgate",
3
3
  "description": "One 👎 becomes a hard rule the agent cannot bypass. Captures thumbs-down feedback, distills it into PreToolUse Pre-Action Checks, enforced across every future Claude Code session.",
4
- "version": "1.25.1",
4
+ "version": "1.26.0",
5
5
  "author": {
6
6
  "name": "Igor Ganapolsky",
7
7
  "email": "ig5973700@gmail.com",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thumbgate",
3
- "version": "1.25.1",
3
+ "version": "1.26.0",
4
4
  "description": "ThumbGate — 👍👎 feedback that teaches your AI agent. Thumbs down a mistake, it never happens again.",
5
5
  "homepage": "https://thumbgate.ai",
6
6
  "transport": "stdio",
@@ -2,13 +2,13 @@
2
2
  "mcpServers": {
3
3
  "thumbgate": {
4
4
  "command": "npx",
5
- "args": ["--yes", "--package", "thumbgate@1.25.1", "thumbgate", "serve"]
5
+ "args": ["--yes", "--package", "thumbgate@1.26.0", "thumbgate", "serve"]
6
6
  }
7
7
  },
8
8
  "hooks": {
9
9
  "preToolUse": {
10
10
  "command": "npx",
11
- "args": ["--yes", "--package", "thumbgate@1.25.1", "thumbgate", "gate-check"]
11
+ "args": ["--yes", "--package", "thumbgate@1.26.0", "thumbgate", "gate-check"]
12
12
  }
13
13
  }
14
14
  }
@@ -133,6 +133,7 @@
133
133
  "context": { "type": "string" },
134
134
  "mcpProfile": { "type": "string" },
135
135
  "bundleId": { "type": "string" },
136
+ "enforcePlanQuality": { "type": "boolean" },
136
137
  "approved": { "type": "boolean" }
137
138
  },
138
139
  "required": ["intentId"]
@@ -216,7 +216,7 @@ const {
216
216
  finalizeSession: finalizeFeedbackSession,
217
217
  } = require('../../scripts/feedback-session');
218
218
 
219
- const SERVER_INFO = { name: 'thumbgate-mcp', version: '1.25.1' };
219
+ const SERVER_INFO = { name: 'thumbgate-mcp', version: '1.26.0' };
220
220
  const COMMERCE_CATEGORIES = [
221
221
  'product_recommendation',
222
222
  'brand_compliance',
@@ -637,7 +637,7 @@ function buildEstimateUncertaintyResponse(args = {}) {
637
637
 
638
638
  async function callTool(name, args = {}) {
639
639
  assertToolAllowed(name, getActiveMcpProfile());
640
- if (name !== 'workflow_sentinel') {
640
+ if (name !== 'workflow_sentinel' && process.env.THUMBGATE_DISABLE_MCP_FIREWALL !== '1') {
641
641
  const firewallResult = (await evaluateGatesAsync(name, args)) || evaluateSecretGuard({ tool_name: name, tool_input: args });
642
642
  if (firewallResult && firewallResult.decision === 'deny') {
643
643
  const err = new Error(`Action blocked by Semantic Firewall: ${firewallResult.message}`);
@@ -779,6 +779,7 @@ async function callToolInner(name, args) {
779
779
  bundleId: args.bundleId,
780
780
  partnerProfile: args.partnerProfile,
781
781
  delegationMode: args.delegationMode,
782
+ enforcePlanQuality: args.enforcePlanQuality === true,
782
783
  approved: args.approved === true,
783
784
  repoPath: args.repoPath,
784
785
  }));
@@ -7,7 +7,7 @@
7
7
  "npx",
8
8
  "--yes",
9
9
  "--package",
10
- "thumbgate@1.25.1",
10
+ "thumbgate@1.26.0",
11
11
  "thumbgate",
12
12
  "serve"
13
13
  ],
@@ -94,6 +94,8 @@ components:
94
94
  delegationMode:
95
95
  type: string
96
96
  enum: [off, auto, sequential]
97
+ enforcePlanQuality:
98
+ type: boolean
97
99
  approved:
98
100
  type: boolean
99
101
  repoPath:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thumbgate",
3
- "version": "1.25.1",
3
+ "version": "1.26.0",
4
4
  "description": "ThumbGate self-improving agent governance: thumbs-up/down turns every mistake into a prevention rule and blocks repeat patterns. 36 pre-action checks, budget enforcement, and self-protection for Claude Code, Cursor, Codex, Gemini CLI, and Amp.",
5
5
  "homepage": "https://thumbgate.ai",
6
6
  "repository": {
@@ -101,6 +101,7 @@
101
101
  "scripts/hybrid-feedback-context.js",
102
102
  "scripts/hybrid-supervisor-agent.js",
103
103
  "scripts/inference-cache-policy.js",
104
+ "scripts/install-shim.js",
104
105
  "scripts/install-mcp.js",
105
106
  "scripts/internal-agent-bootstrap.js",
106
107
  "scripts/intervention-policy.js",
@@ -136,6 +137,7 @@
136
137
  "scripts/oss-pr-opportunity-scout.js",
137
138
  "scripts/otel-declarative-config.js",
138
139
  "scripts/perplexity-client.js",
140
+ "scripts/plan-gate.js",
139
141
  "scripts/plausible-server-events.js",
140
142
  "scripts/pr-manager.js",
141
143
  "scripts/private-core-boundary.js",
@@ -189,6 +191,7 @@
189
191
  "scripts/thompson-sampling.js",
190
192
  "scripts/thumbgate-bench.js",
191
193
  "scripts/thumbgate-search.js",
194
+ "scripts/trajectory-scorer.js",
192
195
  "scripts/token-savings.js",
193
196
  "scripts/token-tco.js",
194
197
  "scripts/tool-registry.js",
@@ -340,7 +343,7 @@
340
343
  "social:prospect:bluesky:dry": "node scripts/social-bluesky-prospecting.js --dry-run",
341
344
  "social:reply-publish:bluesky:dry": "node scripts/social-reply-monitor-bluesky.js --publish-approved --dry-run",
342
345
  "test:python": "python3 -m pytest tests/*.py",
343
- "test": "npm run test:python && npm run test:schema && npm run test:loop && npm run test:dpo && npm run test:kto && npm run test:api && npm run test:proof && npm run test:e2e && npm run test:rlaif && npm run test:attribution && npm run test:quality && npm run test:intelligence && npm run test:training-export && npm run test:deployment && npm run test:operational-integrity && npm run test:workflow && npm run test:billing && npm run test:cli && npm run test:watcher && npm run test:autoresearch && npm run test:ops && npm run test:session-analyzer && npm run test:tessl && npm run test:gates && npm run test:evoskill && npm run test:gates-hardening && npm run test:workers && npm run test:social-analytics && npm run test:memalign && npm run test:xmemory-lite && npm run test:filesystem-search && npm run test:zernio && npm run test:platform-limits && npm run test:post-video && npm run test:post-everywhere-instagram && npm run test:post-everywhere-channels && npm run test:post-everywhere-zernio-default && npm run test:zernio-canonical-pollers && npm run test:zernio-status && npm run test:obsidian-export && npm run test:lesson-db && npm run test:lesson-rotation && npm run test:memory-dedup && npm run test:feedback-quality && npm run test:sync-version && npm run test:check-congruence && npm run test:tool-registry && npm run test:feedback-to-rules && npm run test:memory-firewall && npm run test:memory-scope-readiness && npm run test:belief-update && npm run test:hosted-config && npm run test:operational-summary && npm run test:operational-dashboard && npm run test:operator-artifacts && npm run test:operator-key-auth && npm run test:cloudflare-sandbox && npm run test:mcp-config && npm run test:mcp-tool-annotations && npm run test:mcp-oauth && npm run test:mcp-oauth-flow && npm run test:plan-gate && npm run test:pulse && npm run test:semantic-layer && npm run test:data-pipeline && npm run test:optimize-context && npm run test:principle-extractor && npm run test:analytics-window && npm run test:funnel-analytics && npm run test:experiment-tracker && npm run test:build-metadata && npm run test:context-engine && npm run test:hf-papers && npm run test:marketing-experiment && npm run test:seo-gsd && npm run test:verify-run && npm run test:export-dpo-pairs && npm run test:export-hf-dataset && npm run test:license && npm run test:bot-detector && npm run test:audit-pr-bot-contamination && npm run test:stripe-bootstrap-saas-catalog && npm run test:postinstall && npm run test:funnel-invariants && npm run test:cli-telemetry && npm run test:pro-parity && npm run test:model-tier-router && npm run test:computer-use-firewall && npm run test:skill-exporter && npm run test:statusline && npm run test:evolution && npm run test:org-dashboard && npm run test:multi-hop-recall && npm run test:synthetic-dpo && npm run test:thumbgate-skill && npm run test:learn-hub && npm run test:feedback-fallback && npm run test:metaclaw && npm run test:server-lock && npm run test:control-tower && npm run test:pii-scanner && npm run test:data-governance && npm run test:lesson-inference && npm run test:semantic-dedup && npm run test:fs-utils && npm run test:cli-schema && npm run test:explore && npm run test:lesson-reranker && npm run test:lesson-retrieval && npm run test:lesson-semantic-retrieval && npm run test:cross-encoder && npm run test:reflector-agent && npm run test:feedback-session && npm run test:feedback-history-distiller && npm run test:hallucination-detector && npm run test:history-distiller && npm run test:predictive-insights && npm run test:predictive-credible-range && npm run test:prove-predictive-insights && npm run test:statusbar-cli && npm run test:generate-instagram-card && npm run test:instagram-thumbgate-post && npm run test:publish-instagram-thumbgate && npm run test:lesson-synthesis && npm run test:lesson-canonical && npm run test:background-governance && npm run test:memory-migration && npm run test:prompt-dlp && npm run test:ephemeral-store && npm run test:agent-security && npm run test:skill-progressive && npm run test:per-step-scoring && npm run test:weekly-auto-post && npm run test:social-post-hourly && npm run test:social-quality-gate && npm run test:a2ui-engine && npm run test:gate-satisfy && npm run test:money-watcher && npm run test:budget && npm run test:quick-start && npm run test:utm && npm run test:product-feedback && npm run test:feedback-root-consolidator && npm run test:engagement-audit && npm run test:install-growth-automation && npm run test:publish-thumbgate-launch && npm run test:community-course-platform-launch-kit && npm run test:reconcile-thumbgate-campaign && npm run test:reddit-publisher && npm run test:schedule-thumbgate-campaign && npm run test:social-reply-monitor && npm run test:social-dedupe-cleanup && npm run test:sync-launch-assets && npm run test:ai-search-visibility && npm run test:perplexity && npm run test:security-scanner && npm run test:llm-client && npm run test:managed-lesson-agent && npm run test:self-distill && npm run test:meta-agent && npm run test:harness-selector && npm run test:thumbgate-bench && npm run test:seo-guides && npm run test:enforcement-loop && npm run test:cli-agent-experience && npm run test:bot-detection && npm run test:checkout-archived-product-guard && npm run test:postgres-guard && npm run test:checkout-bot-guard && npm run test:checkout-pro-confirmation-gate && npm run test:session-health && npm run test:session-episodes && npm run test:spec-gate && npm run test:decision-trace && npm run test:dashboard-insights && npm run test:telemetry-tracked-link-slug && npm run test:prompt-eval && npm run test:demo-voiceover && npm run test:gate-coherence && npm run test:gate-eval && npm run test:high-roi && npm run test:public-static-assets && npm run test:token-savings && npm run test:numbers-page && npm run test:workflow-gate-checkpoint && npm run test:lesson-export-import && npm run test:landing-page-claims && npm run test:competitive-positioning-marketing && npm run test:medium-weekly && npm run test:dashboard-deeplink-e2e && npm run test:public-package-parity && npm run test:token-savings-dashboard && npm run test:cursor-wiring && npm run test:pretooluse-injection && npm run test:recent-corrective-context && npm run test:durability-step && npm run test:mailer && npm run test:brand-assets && npm run test:enforcement-teeth && npm run test:bayes-optimal-gate && npm run test:swarm-coordinator && npm run test:session-report && npm run test:agent-reasoning-traces && npm run test:judge-reward && npm run test:llm-behavior-monitor && npm run test:prompting-os && npm run test:single-use-credential-gate && npm run test:structured-prompt-driven && npm run test:require-evidence-gate && npm run test:rule-validator && npm run test:bluesky-atproto && npm run test:social-reply-monitor-bluesky && npm run test:bluesky-delete-replies && npm run test:architect-kit-memory-bridge && npm run test:sonar-review-hotspots && npm run test:actionable-remediations && npm run test:gemini-embedding-policy && npm run test:agent-design-governance && npm run test:public-core-boundary && npm run test:hook-stop-verify-deploy && npm run test:hook-stop-anti-claim && npm run test:plausible-server-events && npm run test:activation-tracker && npm run test:unified-revenue-rollup && npm run test:conversion-rate-stats && npm run test:external-customer-audit && npm run test:telemetry-export && npm run test:stripe-checkout-diagnostic && npm run test:stripe-business-identity-probe && npm run test:revenue-observability-doctor && npm run test:public-bundle-ratchet && npm run test:stripe-payment-link-update && npm run test:ci-cd-hygiene-audit && npm run test:verify-marketing-pages-deployed && npm run test:install-email-capture && npm run test:install-shim && npm run test:hook-runtime-subcommands && npm run test:implementation-notes && npm run test:daily-block-cap && npm run test:free-to-paid-conversion-units && npm run test:metrics-real-endpoint && npm run test:cli-trial-and-help && npm run test:cost-cli && npm run test:silent-failure-cluster && npm run test:proof:truth && node --test tests/adaptive-reliability.test.js",
346
+ "test": "npm run test:python && npm run test:schema && npm run test:loop && npm run test:dpo && npm run test:kto && npm run test:api && npm run test:proof && npm run test:e2e && npm run test:rlaif && npm run test:attribution && npm run test:quality && npm run test:intelligence && npm run test:training-export && npm run test:deployment && npm run test:operational-integrity && npm run test:workflow && npm run test:billing && npm run test:cli && npm run test:watcher && npm run test:autoresearch && npm run test:ops && npm run test:session-analyzer && npm run test:tessl && npm run test:gates && npm run test:evoskill && npm run test:gates-hardening && npm run test:workers && npm run test:social-analytics && npm run test:memalign && npm run test:xmemory-lite && npm run test:filesystem-search && npm run test:zernio && npm run test:platform-limits && npm run test:post-video && npm run test:post-everywhere-instagram && npm run test:post-everywhere-channels && npm run test:post-everywhere-zernio-default && npm run test:zernio-canonical-pollers && npm run test:zernio-status && npm run test:obsidian-export && npm run test:lesson-db && npm run test:lesson-rotation && npm run test:memory-dedup && npm run test:feedback-quality && npm run test:sync-version && npm run test:check-congruence && npm run test:tool-registry && npm run test:feedback-to-rules && npm run test:memory-firewall && npm run test:memory-scope-readiness && npm run test:belief-update && npm run test:hosted-config && npm run test:operational-summary && npm run test:operational-dashboard && npm run test:operator-artifacts && npm run test:operator-key-auth && npm run test:cloudflare-sandbox && npm run test:mcp-config && npm run test:mcp-tool-annotations && npm run test:mcp-oauth && npm run test:mcp-oauth-flow && npm run test:plan-gate && npm run test:pulse && npm run test:semantic-layer && npm run test:data-pipeline && npm run test:optimize-context && npm run test:principle-extractor && npm run test:analytics-window && npm run test:funnel-analytics && npm run test:experiment-tracker && npm run test:build-metadata && npm run test:context-engine && npm run test:hf-papers && npm run test:marketing-experiment && npm run test:seo-gsd && npm run test:verify-run && npm run test:export-dpo-pairs && npm run test:export-hf-dataset && npm run test:license && npm run test:bot-detector && npm run test:audit-pr-bot-contamination && npm run test:stripe-bootstrap-saas-catalog && npm run test:postinstall && npm run test:funnel-invariants && npm run test:cli-telemetry && npm run test:pro-parity && npm run test:model-tier-router && npm run test:computer-use-firewall && npm run test:skill-exporter && npm run test:statusline && npm run test:evolution && npm run test:org-dashboard && npm run test:multi-hop-recall && npm run test:synthetic-dpo && npm run test:thumbgate-skill && npm run test:learn-hub && npm run test:feedback-fallback && npm run test:metaclaw && npm run test:server-lock && npm run test:control-tower && npm run test:pii-scanner && npm run test:data-governance && npm run test:lesson-inference && npm run test:semantic-dedup && npm run test:fs-utils && npm run test:cli-schema && npm run test:explore && npm run test:lesson-reranker && npm run test:lesson-retrieval && npm run test:lesson-semantic-retrieval && npm run test:cross-encoder && npm run test:reflector-agent && npm run test:feedback-session && npm run test:feedback-history-distiller && npm run test:hallucination-detector && npm run test:history-distiller && npm run test:predictive-insights && npm run test:predictive-credible-range && npm run test:prove-predictive-insights && npm run test:statusbar-cli && npm run test:generate-instagram-card && npm run test:instagram-thumbgate-post && npm run test:publish-instagram-thumbgate && npm run test:lesson-synthesis && npm run test:lesson-canonical && npm run test:background-governance && npm run test:memory-migration && npm run test:prompt-dlp && npm run test:ephemeral-store && npm run test:agent-security && npm run test:skill-progressive && npm run test:per-step-scoring && npm run test:weekly-auto-post && npm run test:social-post-hourly && npm run test:social-quality-gate && npm run test:a2ui-engine && npm run test:gate-satisfy && npm run test:money-watcher && npm run test:budget && npm run test:quick-start && npm run test:utm && npm run test:product-feedback && npm run test:feedback-root-consolidator && npm run test:engagement-audit && npm run test:install-growth-automation && npm run test:publish-thumbgate-launch && npm run test:community-course-platform-launch-kit && npm run test:reconcile-thumbgate-campaign && npm run test:reddit-publisher && npm run test:schedule-thumbgate-campaign && npm run test:social-reply-monitor && npm run test:social-dedupe-cleanup && npm run test:sync-launch-assets && npm run test:ai-search-visibility && npm run test:perplexity && npm run test:security-scanner && npm run test:llm-client && npm run test:managed-lesson-agent && npm run test:self-distill && npm run test:meta-agent && npm run test:harness-selector && npm run test:thumbgate-bench && npm run test:seo-guides && npm run test:enforcement-loop && npm run test:cli-agent-experience && npm run test:bot-detection && npm run test:checkout-archived-product-guard && npm run test:postgres-guard && npm run test:checkout-bot-guard && npm run test:checkout-pro-confirmation-gate && npm run test:session-health && npm run test:session-episodes && npm run test:spec-gate && npm run test:decision-trace && npm run test:dashboard-insights && npm run test:telemetry-tracked-link-slug && npm run test:prompt-eval && npm run test:demo-voiceover && npm run test:gate-coherence && npm run test:gate-eval && npm run test:high-roi && npm run test:public-static-assets && npm run test:token-savings && npm run test:numbers-page && npm run test:workflow-gate-checkpoint && npm run test:lesson-export-import && npm run test:landing-page-claims && npm run test:competitive-positioning-marketing && npm run test:medium-weekly && npm run test:dashboard-deeplink-e2e && npm run test:public-package-parity && npm run test:token-savings-dashboard && npm run test:cursor-wiring && npm run test:pretooluse-injection && npm run test:recent-corrective-context && npm run test:durability-step && npm run test:mailer && npm run test:brand-assets && npm run test:enforcement-teeth && npm run test:bayes-optimal-gate && npm run test:swarm-coordinator && npm run test:session-report && npm run test:agent-reasoning-traces && npm run test:judge-reward && npm run test:llm-behavior-monitor && npm run test:prompting-os && npm run test:single-use-credential-gate && npm run test:structured-prompt-driven && npm run test:require-evidence-gate && npm run test:rule-validator && npm run test:bluesky-atproto && npm run test:social-reply-monitor-bluesky && npm run test:bluesky-delete-replies && npm run test:architect-kit-memory-bridge && npm run test:sonar-review-hotspots && npm run test:actionable-remediations && npm run test:gemini-embedding-policy && npm run test:agent-design-governance && npm run test:public-core-boundary && npm run test:hook-stop-verify-deploy && npm run test:hook-stop-anti-claim && npm run test:plausible-server-events && npm run test:activation-tracker && npm run test:unified-revenue-rollup && npm run test:conversion-rate-stats && npm run test:external-customer-audit && npm run test:telemetry-export && npm run test:stripe-checkout-diagnostic && npm run test:stripe-business-identity-probe && npm run test:revenue-observability-doctor && npm run test:public-bundle-ratchet && npm run test:stripe-payment-link-update && npm run test:ci-cd-hygiene-audit && npm run test:verify-marketing-pages-deployed && npm run test:install-email-capture && npm run test:install-shim && npm run test:hook-runtime-subcommands && npm run test:implementation-notes && npm run test:daily-block-cap && npm run test:free-to-paid-conversion-units && npm run test:metrics-real-endpoint && npm run test:cli-trial-and-help && npm run test:cost-cli && npm run test:silent-failure-cluster && npm run test:proof:truth && node --test tests/adaptive-reliability.test.js && npm run test:mcp-oauth-reviewer",
344
347
  "test:hook-stop-verify-deploy": "node --test tests/hook-stop-verify-deploy.test.js",
345
348
  "test:hook-stop-anti-claim": "node --test tests/hook-stop-anti-claim.test.js",
346
349
  "test:plausible-server-events": "node --test tests/plausible-server-events.test.js tests/plausible-poller.test.js",
@@ -687,11 +690,12 @@
687
690
  "test:dashboard-page-clickability": "playwright test tests/e2e/dashboard-page-clickability.spec.js",
688
691
  "test:agent-manager-page-clickability": "playwright test tests/e2e/agent-manager-page-clickability.spec.js",
689
692
  "test:pricing-page-clickability": "playwright test tests/e2e/pricing-page-clickability.spec.js",
690
- "test:proof:truth": "node --test tests/knowledge-entropy.test.js tests/mcp-wiring-doctor.test.js tests/sequence-guard.test.js tests/slopsquat-guard.test.js tests/slopsquat-stress.test.js tests/truth-and-proof.test.js tests/wire-proof-gate.test.js tests/adaptive-reliability.test.js",
693
+ "test:proof:truth": "node --test tests/knowledge-entropy.test.js tests/mcp-wiring-doctor.test.js tests/sequence-guard.test.js tests/slopsquat-guard.test.js tests/slopsquat-stress.test.js tests/truth-and-proof.test.js tests/wire-proof-gate.test.js tests/adaptive-reliability.test.js tests/coderabbit-patterns.test.js",
691
694
  "build:grok-plugin": "node scripts/build-grok-plugin.js",
692
695
  "promote:launch": "node scripts/x-autonomous-marketing.js",
693
696
  "feedback:ingest": "node scripts/ingest-manual-feedback.js",
694
- "verify-proof": "node scripts/require-proof.js"
697
+ "verify-proof": "node scripts/require-proof.js",
698
+ "test:mcp-oauth-reviewer": "node --test tests/mcp-oauth-reviewer.test.js"
695
699
  },
696
700
  "keywords": [
697
701
  "mcp",
package/public/index.html CHANGED
@@ -20,7 +20,7 @@ __GOOGLE_SITE_VERIFICATION_META__
20
20
  <meta property="og:image" content="https://thumbgate.ai/og.png">
21
21
  <meta name="twitter:card" content="summary_large_image">
22
22
  <meta name="twitter:image" content="https://thumbgate.ai/og.png">
23
- <meta name="thumbgate-version" content="1.25.1">
23
+ <meta name="thumbgate-version" content="1.26.0">
24
24
  <meta name="keywords" content="ThumbGate, thumbgate, AI agent orchestration, AI experience orchestration, agentic development cycle, AC/DC framework, Guide Generate Verify Solve, agent enforcement layer, save LLM tokens, reduce Claude API cost, reduce OpenAI cost, AI agent token savings, prevent LLM retries, prevent hallucination retries, stop AI token waste, pre-action checks, agent governance, Claude Code, Cursor, Codex, Gemini, Amp, Cline, OpenCode, workflow hardening, context engineering, AI authenticity, brand authenticity AI">
25
25
  <link rel="canonical" href="__APP_ORIGIN__/">
26
26
  <link rel="alternate" type="text/markdown" title="ThumbGate LLM context" href="__APP_ORIGIN__/llm-context.md">
@@ -1586,7 +1586,7 @@ __GA_BOOTSTRAP__
1586
1586
  <a href="https://www.linkedin.com/in/igorganapolsky" target="_blank" rel="noopener">LinkedIn</a>
1587
1587
  <a href="/blog">Blog</a>
1588
1588
  </div>
1589
- <span class="footer-copy">© 2026 ThumbGate · MIT License · npm v1.25.1</span>
1589
+ <span class="footer-copy">© 2026 ThumbGate · MIT License · npm v1.26.0</span>
1590
1590
  </div>
1591
1591
  </footer>
1592
1592
 
@@ -25,7 +25,7 @@
25
25
  "alternateName": "thumbgate",
26
26
  "applicationCategory": "DeveloperApplication",
27
27
  "operatingSystem": "Cross-platform, Node.js >=18.18.0",
28
- "softwareVersion": "1.25.1",
28
+ "softwareVersion": "1.26.0",
29
29
  "url": "https://thumbgate.ai/numbers",
30
30
  "dateModified": "2026-05-07",
31
31
  "creator": {
@@ -202,7 +202,7 @@
202
202
  <main class="container">
203
203
  <h1>The Numbers</h1>
204
204
  <p class="subtitle">Generated first-party operational snapshot from the ThumbGate runtime. This is not customer traction, install volume, revenue, or proof that a configured gate has fired.</p>
205
- <div class="freshness">Updated: 2026-05-07 · Version 1.25.1</div>
205
+ <div class="freshness">Updated: 2026-05-07 · Version 1.26.0</div>
206
206
  <div class="truth-note"><strong>Read this first:</strong> configured checks are inventory. Recorded blocks and warnings are usage evidence. This snapshot currently reports 0 recorded hard-block event(s) and 0 recorded warning event(s).</div>
207
207
 
208
208
  <h2>Gate enforcement</h2>
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
4
7
  /**
5
8
  * Context Manager — Unified Context-Augmented Generation (CAG) Orchestrator
6
9
  *
@@ -248,6 +251,13 @@ function assembleUnifiedContext(params = {}) {
248
251
  reliabilityDirective = 'CAUTION: Conflicting past patterns detected for this action. Prioritize absolute ground truth verification over rapid completion.';
249
252
  }
250
253
 
254
+ // v1.26.0: CodeRabbit Planning Directive
255
+ const planPath = path.join(repoPath || process.cwd(), 'PLAN.md');
256
+ if (!fs.existsSync(planPath) && ['Bash', 'Write', 'Edit', 'Deploy'].includes(toolName)) {
257
+ const planReminder = 'ORCHESTRATION: High-risk action detected without a PLAN.md. Please document your intent, assumptions, and verification steps before proceeding.';
258
+ reliabilityDirective = reliabilityDirective ? `${reliabilityDirective}\n\n${planReminder}` : planReminder;
259
+ }
260
+
251
261
  const result = {
252
262
  tier,
253
263
  agentType: agentType || 'default',
@@ -55,6 +55,8 @@ const {
55
55
  const {
56
56
  evaluateSecurityScan,
57
57
  } = require('./security-scanner');
58
+ const { evaluatePlanGate } = require('./plan-gate');
59
+ const { getTrajectoryScore } = require('./trajectory-scorer');
58
60
  const { evaluateSequenceState } = loadOptionalModule('./sequence-guard', () => ({
59
61
  evaluateSequenceState: () => null,
60
62
  }));
@@ -91,6 +93,10 @@ const REMOTE_SIDE_EFFECT_BASH_PATTERN = /\b(?:git\s+push\b|gh\s+pr\s+(?:create|m
91
93
  const BOOSTED_RISK_BLOCK_SCORE = 0.8;
92
94
  const BOOSTED_RISK_MIN_EXAMPLES = 3;
93
95
  const PR_THREAD_RESOLUTION_ACTION = 'pr_thread_resolution_verified_after_commit';
96
+
97
+ function isRuntimePlanGateEnabled() {
98
+ return process.env.THUMBGATE_PLAN_GATE === '1' || process.env.THUMBGATE_PLAN_GATE === 'true';
99
+ }
94
100
  const PR_THREAD_RESOLUTION_CLAIM_PATTERN = '(?:thread|review|comment).*?(?:resolved|verified|checked|addressed|fixed)|(?:resolved|verified|checked|addressed|fixed).*?(?:thread|review|comment)';
95
101
  const PR_THREAD_RESOLUTION_REQUIRED_ACTIONS = ['pr_threads_checked', 'thread_resolution_verified'];
96
102
 
@@ -1512,6 +1518,23 @@ async function evaluateGatesAsync(toolName, toolInput, configPath) {
1512
1518
  return boostedRiskGuard;
1513
1519
  }
1514
1520
 
1521
+ // Tier 1b: Planning and Trajectory (v1.26.0 - CodeRabbit Pattern).
1522
+ // Keep runtime enforcement explicit so advisory planning checks do not mask
1523
+ // higher-priority deny/approve gates in established workflows.
1524
+ if (isRuntimePlanGateEnabled()) {
1525
+ const planGate = evaluatePlanGate(toolName, toolInput);
1526
+ if (planGate) {
1527
+ recordStat(planGate.gate, planGate.decision === 'deny' ? 'block' : 'warn');
1528
+ return planGate;
1529
+ }
1530
+
1531
+ const trajectory = getTrajectoryScore();
1532
+ if (trajectory.isDrifting) {
1533
+ recordStat('strategic-drift', 'block');
1534
+ return { decision: 'deny', gate: 'strategic-drift', message: trajectory.message, severity: 'high' };
1535
+ }
1536
+ }
1537
+
1515
1538
  // Fast-path: feedback/recall tools skip metric gates entirely (avoids Stripe API calls)
1516
1539
  const METRIC_SKIP_TOOLS = ['capture_feedback', 'feedback_stats', 'recall', 'feedback_summary', 'prevention_rules'];
1517
1540
  const skipMetrics = METRIC_SKIP_TOOLS.includes(toolName);
@@ -1709,6 +1732,23 @@ function evaluateGates(toolName, toolInput, configPath) {
1709
1732
  return boostedRiskGuard;
1710
1733
  }
1711
1734
 
1735
+ // Tier 1b: Planning and Trajectory (v1.26.0 - CodeRabbit Pattern).
1736
+ // Keep runtime enforcement explicit so advisory planning checks do not mask
1737
+ // higher-priority deny/approve gates in established workflows.
1738
+ if (isRuntimePlanGateEnabled()) {
1739
+ const planGate = evaluatePlanGate(toolName, toolInput);
1740
+ if (planGate) {
1741
+ recordStat(planGate.gate, planGate.decision === 'deny' ? 'block' : 'warn');
1742
+ return planGate;
1743
+ }
1744
+
1745
+ const trajectory = getTrajectoryScore();
1746
+ if (trajectory.isDrifting) {
1747
+ recordStat('strategic-drift', 'block');
1748
+ return { decision: 'deny', gate: 'strategic-drift', message: trajectory.message, severity: 'high' };
1749
+ }
1750
+ }
1751
+
1712
1752
  for (const gate of config.gates) {
1713
1753
  const matchDetails = matchGate(gate, toolName, toolInput);
1714
1754
  if (!matchDetails.matched) continue;
@@ -2135,10 +2175,7 @@ function buildRecentCorrectiveActionsContext(options = {}) {
2135
2175
  function buildRelevantLessonContext(toolName, toolInput) {
2136
2176
  if (!toolName) return null;
2137
2177
 
2138
- const { retrieveRelevantLessons, calculateRetrievalEntropy } = loadOptionalModule('./lesson-retrieval', () => ({
2139
- retrieveRelevantLessons: () => [],
2140
- calculateRetrievalEntropy: () => 0,
2141
- }));
2178
+ const { retrieveRelevantLessons, calculateRetrievalEntropy, filterTopP } = loadOptionalModule("./lesson-retrieval", () => ({ retrieveRelevantLessons: () => [], calculateRetrievalEntropy: () => 0, filterTopP: (l) => l }));
2142
2179
 
2143
2180
  // Extract a searchable action context from the tool input
2144
2181
  const actionContext = extractActionContext(toolName, toolInput);
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * install-shim.js — Install a stable shim at ~/.thumbgate/bin/thumbgate-hook
5
+ *
6
+ * The shim is a tiny shell script that always resolves thumbgate@latest,
7
+ * so hook commands in settings.local.json never go stale. This is the
8
+ * Volta-style pattern: a version-agnostic indirection layer that survives
9
+ * across thumbgate upgrades.
10
+ *
11
+ * The shim checks for a cached runtime binary first (fast path), and falls
12
+ * back to `npx --yes thumbgate@latest` (slow path, self-installs).
13
+ */
14
+
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+ const os = require('os');
18
+
19
+ const SHIM_DIR = path.join(os.homedir(), '.thumbgate', 'bin');
20
+ const SHIM_PATH = path.join(SHIM_DIR, 'thumbgate-hook');
21
+ const RUNTIME_BIN = path.join(os.homedir(), '.thumbgate', 'runtime', 'node_modules', '.bin', 'thumbgate');
22
+
23
+ /**
24
+ * The shim script. Key design choices:
25
+ * - Uses `exec` to replace the shell process (no zombie processes)
26
+ * - Fast path: if cached runtime binary exists, exec it directly
27
+ * - Slow path: npx --yes thumbgate@latest (auto-installs)
28
+ * - Background upgrade: after the fast path succeeds once, spawn a
29
+ * detached npm install to refresh the cache for next time
30
+ */
31
+ function shimContent() {
32
+ const escapedRuntimeBin = JSON.stringify(RUNTIME_BIN);
33
+ const escapedRuntimeDir = JSON.stringify(path.join(os.homedir(), '.thumbgate', 'runtime'));
34
+
35
+ return `#!/usr/bin/env bash
36
+ # ThumbGate hook shim — DO NOT EDIT
37
+ # Installed by: thumbgate init
38
+ # Purpose: version-agnostic hook entry point that always runs latest ThumbGate
39
+ # Pattern: Volta-style stable shim (see https://volta.sh)
40
+
41
+ set -euo pipefail
42
+
43
+ RUNTIME_BIN=${escapedRuntimeBin}
44
+ RUNTIME_DIR=${escapedRuntimeDir}
45
+
46
+ # Fast path: cached runtime binary exists and is executable
47
+ if [ -x "$RUNTIME_BIN" ]; then
48
+ # Spawn background upgrade (detached, no stdout/stderr, won't block hook)
49
+ ( nohup npm install --prefix "$RUNTIME_DIR" --no-save --omit=dev thumbgate@latest >/dev/null 2>&1 & ) 2>/dev/null || true
50
+ exec "$RUNTIME_BIN" "$@"
51
+ fi
52
+
53
+ # Slow path: no cached binary — install + exec via npx
54
+ mkdir -p "$RUNTIME_DIR"
55
+ exec npx --yes --package thumbgate@latest -- thumbgate "$@"
56
+ `;
57
+ }
58
+
59
+ function installShim() {
60
+ fs.mkdirSync(SHIM_DIR, { recursive: true });
61
+ fs.writeFileSync(SHIM_PATH, shimContent(), { mode: 0o755 });
62
+ return SHIM_PATH;
63
+ }
64
+
65
+ function shimInstalled() {
66
+ try {
67
+ return fs.existsSync(SHIM_PATH) && (fs.statSync(SHIM_PATH).mode & 0o111) !== 0;
68
+ } catch {
69
+ return false;
70
+ }
71
+ }
72
+
73
+ function shimPath() {
74
+ return SHIM_PATH;
75
+ }
76
+
77
+ module.exports = {
78
+ installShim,
79
+ shimInstalled,
80
+ shimPath,
81
+ shimContent,
82
+ SHIM_DIR,
83
+ SHIM_PATH,
84
+ };
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Plan Gate — implementing the CodeRabbit "Planning-First" pattern.
6
+ *
7
+ * 1. (Static) Validates structured 'PLAN.md' / 'PRD' content (used in loop-closure).
8
+ * 2. (Dynamic) Intercepts high-risk tool calls during agent execution.
9
+ */
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const RISK_TOOLS = ['Bash', 'Write', 'Edit', 'Deploy'];
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Gate validators (Legacy / Loop Closure)
18
+ // ---------------------------------------------------------------------------
19
+
20
+ function countTableRows(content, sectionHeading) {
21
+ const sectionRegex = new RegExp(
22
+ `#+\\s*${sectionHeading}[^\\n]*\\n([\\s\\S]*?)(?=\\n#+\\s|$)`,
23
+ );
24
+ const match = content.match(sectionRegex);
25
+ if (!match) return 0;
26
+
27
+ const lines = match[1].split('\n').filter((l) => l.trim().startsWith('|'));
28
+ // Subtract header row and separator row
29
+ const dataRows = lines.filter(
30
+ (l) => !/^\|\s*-+/.test(l.trim()) && !/^\|\s*:?-+/.test(l.trim()),
31
+ );
32
+ // First row is the header
33
+ return Math.max(0, dataRows.length - 1);
34
+ }
35
+
36
+ function countContracts(content) {
37
+ const sectionRegex = /#+\s*Contracts[^\n]*\n([\s\S]*?)(?=\n#+\s|$)/;
38
+ const match = content.match(sectionRegex);
39
+ if (!match) return 0;
40
+
41
+ const section = match[1];
42
+ // Find code blocks and look for interface/type keywords inside them
43
+ const codeBlockRegex = /```[\s\S]*?```/g;
44
+ let count = 0;
45
+ let blockMatch;
46
+ while ((blockMatch = codeBlockRegex.exec(section)) !== null) {
47
+ const block = blockMatch[0];
48
+ const interfaceMatches = block.match(/\b(interface|type)\s+\w+/g);
49
+ if (interfaceMatches) count += interfaceMatches.length;
50
+ }
51
+ return count;
52
+ }
53
+
54
+ function countValidationScenarios(content) {
55
+ const sectionRegex =
56
+ /#+\s*Validation\s+Checklist[^\n]*\n([\s\S]*?)(?=\n#+\s|$)/;
57
+ const match = content.match(sectionRegex);
58
+ if (!match) return 0;
59
+
60
+ const lines = match[1].split('\n');
61
+ return lines.filter((l) => /^\s*-\s*\[\s*\]/.test(l)).length;
62
+ }
63
+
64
+ function getStatus(content) {
65
+ const match = content.match(/#+\s*Status[^\n]*\n\s*(\S+)/);
66
+ return match ? match[1].trim() : null;
67
+ }
68
+
69
+ function validatePlan(content) {
70
+ const questionCount = countTableRows(content, 'Clarifying Questions Resolved');
71
+ const contractCount = countContracts(content);
72
+ const scenarioCount = countValidationScenarios(content);
73
+ const status = getStatus(content);
74
+
75
+ const gates = [
76
+ {
77
+ name: 'Clarifying Questions',
78
+ pass: questionCount >= 3,
79
+ detail: `${questionCount} questions resolved`,
80
+ },
81
+ {
82
+ name: 'Contracts Defined',
83
+ pass: contractCount >= 1,
84
+ detail: `${contractCount} interface${contractCount !== 1 ? 's' : ''} found`,
85
+ },
86
+ {
87
+ name: 'Validation Checklist',
88
+ pass: scenarioCount >= 2,
89
+ detail: `${scenarioCount} scenarios defined`,
90
+ },
91
+ {
92
+ name: 'Status',
93
+ pass: status !== 'COMPLETE',
94
+ detail:
95
+ status === 'COMPLETE'
96
+ ? 'COMPLETE (already finished — cannot re-approve)'
97
+ : `${status || 'UNKNOWN'} (not COMPLETE)`,
98
+ },
99
+ ];
100
+
101
+ const allPass = gates.every((g) => g.pass);
102
+ return { gates, allPass };
103
+ }
104
+
105
+ function formatReport(result) {
106
+ const lines = result.gates.map(
107
+ (g) => `${g.pass ? '✅' : '❌'} ${g.name}: ${g.detail}`,
108
+ );
109
+ lines.push('');
110
+ lines.push(
111
+ result.allPass
112
+ ? 'RESULT: PASS — all gates satisfied'
113
+ : 'RESULT: BLOCKED — resolve issues above before spawning agents',
114
+ );
115
+ return lines.join('\n');
116
+ }
117
+
118
+ // ---------------------------------------------------------------------------
119
+ // Dynamic Gating (CodeRabbit Orchestration Pattern)
120
+ // ---------------------------------------------------------------------------
121
+
122
+ /**
123
+ * Evaluates the planning state for the current tool call.
124
+ */
125
+ function evaluatePlanGate(toolName, toolInput, options = {}) {
126
+ if (!RISK_TOOLS.includes(toolName)) return null;
127
+
128
+ const projectRoot = options.projectRoot || process.cwd();
129
+ const planPath = path.join(projectRoot, 'PLAN.md');
130
+
131
+ // Tier 1: Existence Check
132
+ if (!fs.existsSync(planPath)) {
133
+ return {
134
+ decision: 'warn',
135
+ gate: 'plan-gate-missing',
136
+ message: '⚠️ THUMBGATE: High-risk tool call without a PLAN.md. Please create a plan documenting your intent and assumptions.',
137
+ severity: 'high'
138
+ };
139
+ }
140
+
141
+ // Tier 2: Alignment Check (Simple)
142
+ const planContent = fs.readFileSync(planPath, 'utf8');
143
+ const action = toolName === 'Bash' ? toolInput.command : toolInput.filePath;
144
+
145
+ if (action && !planContent.toLowerCase().includes(path.basename(action).toLowerCase())) {
146
+ return {
147
+ decision: 'warn',
148
+ gate: 'plan-gate-drift',
149
+ message: `⚠️ THUMBGATE: Strategic Drift detected. The action "${action}" is not mentioned in your PLAN.md.`,
150
+ severity: 'medium'
151
+ };
152
+ }
153
+
154
+ // Tier 3: Implicit Assumption Extraction
155
+ const assumptions = extractAssumptions(planContent);
156
+ if (assumptions.length > 0) {
157
+ return {
158
+ decision: 'warn',
159
+ gate: 'plan-gate-assumptions',
160
+ message: '🔍 THUMBGATE: Explicitly verify these implicit assumptions before proceeding:\n- ' + assumptions.join('\n- '),
161
+ severity: 'medium'
162
+ };
163
+ }
164
+
165
+ return null;
166
+ }
167
+
168
+ /**
169
+ * Scans plan content for "Assumes" or "Implicit" keywords.
170
+ */
171
+ function extractAssumptions(content) {
172
+ const lines = content.split('\n');
173
+ const assumptions = [];
174
+ const regex = /(?:assume|assumption|implicit|pre-requisite|depends on)s?[:\-]?\s*(.*)/i;
175
+
176
+ for (const line of lines) {
177
+ const match = line.match(regex);
178
+ if (match && match[1].trim()) {
179
+ assumptions.push(match[1].trim());
180
+ }
181
+ }
182
+ return assumptions.slice(0, 5);
183
+ }
184
+
185
+ // ---------------------------------------------------------------------------
186
+ // Main
187
+ // ---------------------------------------------------------------------------
188
+
189
+ function run() {
190
+ const args = process.argv.slice(2);
191
+ const jsonFlag = args.includes('--json');
192
+ const filePath = args.find((a) => a !== '--json');
193
+
194
+ if (!filePath) {
195
+ console.error('Usage: node scripts/plan-gate.js <plan-file.md> [--json]');
196
+ process.exit(1);
197
+ }
198
+
199
+ const resolved = path.resolve(filePath);
200
+ if (!fs.existsSync(resolved)) {
201
+ console.error(`File not found: ${resolved}`);
202
+ process.exit(1);
203
+ }
204
+
205
+ const content = fs.readFileSync(resolved, 'utf-8');
206
+ const result = validatePlan(content);
207
+
208
+ if (jsonFlag) {
209
+ console.log(JSON.stringify(result, null, 2));
210
+ } else {
211
+ console.log(formatReport(result));
212
+ }
213
+
214
+ process.exit(result.allPass ? 0 : 1);
215
+ }
216
+
217
+ // Export for testing
218
+ module.exports = {
219
+ validatePlan,
220
+ formatReport,
221
+ countTableRows,
222
+ countContracts,
223
+ countValidationScenarios,
224
+ getStatus,
225
+ evaluatePlanGate,
226
+ extractAssumptions,
227
+ };
228
+
229
+ // Run only when executed directly
230
+ if (require.main === module) {
231
+ run();
232
+ }
@@ -301,6 +301,24 @@ function getCalibration(model) {
301
301
  // Posterior Sampling
302
302
  // ---------------------------------------------------------------------------
303
303
 
304
+ /**
305
+ * Return the Beta posterior parameters after applying Thompson temperature
306
+ * scaling. The posterior mean is preserved while precision changes:
307
+ * lower temperatures sharpen the posterior, higher temperatures flatten it.
308
+ *
309
+ * @param {Object} params - Category posterior parameters
310
+ * @param {number} temperature - Scaling factor (default 1.0)
311
+ * @returns {{ alpha: number, beta: number }}
312
+ */
313
+ function getTemperatureScaledPosteriorParams(params, temperature = 1.0) {
314
+ const T = Math.max(0.01, Number(temperature) || 1.0);
315
+ const invT = 1.0 / T;
316
+ return {
317
+ alpha: Math.max(params.alpha * invT, 0.01),
318
+ beta: Math.max(params.beta * invT, 0.01),
319
+ };
320
+ }
321
+
304
322
  /**
305
323
  * Draw one sample from the Beta posterior for each category.
306
324
  * Supports temperature scaling to adjust exploitation vs exploration.
@@ -318,13 +336,9 @@ function getCalibration(model) {
318
336
  */
319
337
  function samplePosteriors(model, temperature = 1.0) {
320
338
  const samples = {};
321
- const T = Math.max(0.01, Number(temperature) || 1.0);
322
- const invT = 1.0 / T;
323
339
 
324
340
  for (const [cat, params] of Object.entries(model.categories || {})) {
325
- // Scale precision by inverse temperature
326
- const alpha = Math.max(params.alpha * invT, 0.01);
327
- const beta = Math.max(params.beta * invT, 0.01);
341
+ const { alpha, beta } = getTemperatureScaledPosteriorParams(params, temperature);
328
342
  samples[cat] = betaSample(alpha, beta);
329
343
  }
330
344
  return samples;
@@ -457,6 +471,7 @@ module.exports = {
457
471
  getReliability,
458
472
  isCalibrated,
459
473
  getCalibration,
474
+ getTemperatureScaledPosteriorParams,
460
475
  samplePosteriors,
461
476
  argmaxPosteriors,
462
477
  pickBestCategory,
@@ -476,6 +476,7 @@ const TOOLS = [
476
476
  bundleId: { type: 'string' },
477
477
  partnerProfile: { type: 'string' },
478
478
  delegationMode: { type: 'string', enum: ['off', 'auto', 'sequential'] },
479
+ enforcePlanQuality: { type: 'boolean' },
479
480
  approved: { type: 'boolean' },
480
481
  repoPath: { type: 'string' },
481
482
  },
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Trajectory Scorer — Strategic Drift Detection.
6
+ *
7
+ * Measures the "Semantic Distance" between the original user intent
8
+ * (from primer.md) and the current set of changed files.
9
+ *
10
+ * If the agent modifies too many unrelated files, it triggers a safety block.
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const { execSync } = require('child_process');
16
+
17
+ function getTrajectoryScore(options = {}) {
18
+ const projectRoot = options.projectRoot || process.cwd();
19
+ const primerPath = path.join(projectRoot, 'primer.md');
20
+
21
+ if (!fs.existsSync(primerPath)) return { score: 0, isDrifting: false, drift: false };
22
+
23
+ const intent = fs.readFileSync(primerPath, 'utf8').toLowerCase();
24
+
25
+ // Get currently modified files (unstaged + staged)
26
+ let changedFiles = options.changedFiles;
27
+ if (!changedFiles) {
28
+ try {
29
+ const output = execSync('git diff --name-only HEAD', { cwd: projectRoot, encoding: 'utf8' });
30
+ changedFiles = output.split('\n').filter(f => f.trim());
31
+ } catch {
32
+ return { score: 0, isDrifting: false, drift: false };
33
+ }
34
+ }
35
+
36
+ if (changedFiles.length === 0) return { score: 0, isDrifting: false, drift: false };
37
+
38
+ // Calculate drift: How many changed files are NOT mentioned in the intent?
39
+ let driftCount = 0;
40
+ for (const file of changedFiles) {
41
+ const base = path.basename(file).toLowerCase();
42
+ if (!intent.includes(base)) {
43
+ driftCount++;
44
+ }
45
+ }
46
+
47
+ const driftRatio = driftCount / changedFiles.length;
48
+ const isDrifting = driftRatio > 0.6 && changedFiles.length > 3;
49
+
50
+ return {
51
+ score: Number((1 - driftRatio).toFixed(2)),
52
+ changedCount: changedFiles.length,
53
+ driftCount,
54
+ isDrifting,
55
+ message: isDrifting
56
+ ? `🚫 THUMBGATE: Strategic Drift Detected. You have modified ${changedFiles.length} files, but ${driftCount} of them were not mentioned in the original intent. Please refocus or update the intent.`
57
+ : null
58
+ };
59
+ }
60
+
61
+ module.exports = {
62
+ getTrajectoryScore
63
+ };
package/src/api/server.js CHANGED
@@ -3662,6 +3662,49 @@ function extractApiKey(req) {
3662
3662
  return '';
3663
3663
  }
3664
3664
 
3665
+ /**
3666
+ * Map a ThumbGate key presented at the OAuth consent screen to a role.
3667
+ *
3668
+ * - When any key is configured (production), the presented key MUST match a
3669
+ * configured admin/operator/reviewer key; otherwise returns null (reject) so
3670
+ * the OAuth flow actually authenticates the holder.
3671
+ * - When NO keys are configured (insecure/dev mode, e.g. local tests), any
3672
+ * non-empty key is accepted as role 'dev' to preserve local development.
3673
+ *
3674
+ * 'reviewer' (THUMBGATE_REVIEWER_KEY) is a read-only, independently-revocable
3675
+ * credential safe to share with a directory reviewer — tool execution enforces
3676
+ * read-only for it (see the tools/call handler).
3677
+ */
3678
+ // Constant-time comparison of two API/OAuth bearer keys. We compare the raw
3679
+ // bytes with crypto.timingSafeEqual after an explicit equal-length guard
3680
+ // (timingSafeEqual throws on a length mismatch). No digest is taken: these are
3681
+ // high-entropy random credentials compared transiently at request time, not
3682
+ // user passwords stored at rest, so neither a KDF (bcrypt/scrypt/argon2) nor a
3683
+ // length-normalizing hash is appropriate — and hashing the credential here is
3684
+ // exactly what static analysis (correctly, for *stored* passwords) flags. The
3685
+ // only side-channel is whether the two keys share a length, which reveals
3686
+ // nothing useful about a random secret. Once lengths match, the byte compare
3687
+ // is constant-time and leaks no information about where they differ.
3688
+ function safeKeyEqual(a, b) {
3689
+ const x = Buffer.from(String(a || ''), 'utf8');
3690
+ const y = Buffer.from(String(b || ''), 'utf8');
3691
+ if (x.length === 0 || y.length === 0 || x.length !== y.length) return false;
3692
+ return require('crypto').timingSafeEqual(x, y);
3693
+ }
3694
+
3695
+ function resolveKeyRole(key) {
3696
+ const k = String(key || '').trim();
3697
+ const adminKey = String(process.env.THUMBGATE_API_KEY || '').trim();
3698
+ const operatorKey = String(process.env.THUMBGATE_OPERATOR_KEY || '').trim();
3699
+ const reviewerKey = String(process.env.THUMBGATE_REVIEWER_KEY || '').trim();
3700
+ const configured = [adminKey, operatorKey, reviewerKey].filter(Boolean);
3701
+ if (configured.length === 0) return k ? 'dev' : null;
3702
+ if (safeKeyEqual(k, adminKey)) return 'admin';
3703
+ if (safeKeyEqual(k, operatorKey)) return 'operator';
3704
+ if (safeKeyEqual(k, reviewerKey)) return 'reviewer';
3705
+ return null;
3706
+ }
3707
+
3665
3708
  /**
3666
3709
  * Admin-only guard for static THUMBGATE_API_KEY.
3667
3710
  * Billing keys are intentionally excluded from admin actions.
@@ -3883,7 +3926,8 @@ function createApiServer() {
3883
3926
  // operator/admin key — never "any non-empty bearer".
3884
3927
  const adminKey = String(process.env.THUMBGATE_API_KEY || '').trim();
3885
3928
  const operatorKey = String(process.env.THUMBGATE_OPERATOR_KEY || '').trim();
3886
- const rawKeyValid = Boolean(bearer) && ((adminKey && bearer === adminKey) || (operatorKey && bearer === operatorKey));
3929
+ const reviewerKey = String(process.env.THUMBGATE_REVIEWER_KEY || '').trim();
3930
+ const rawKeyValid = Boolean(bearer) && (safeKeyEqual(bearer, adminKey) || safeKeyEqual(bearer, operatorKey) || safeKeyEqual(bearer, reviewerKey));
3887
3931
  const authed = oauthSession
3888
3932
  ? mcpOauth.tokenAudienceValid(oauthSession, resourceUrl)
3889
3933
  : rawKeyValid;
@@ -3899,6 +3943,24 @@ function createApiServer() {
3899
3943
  }));
3900
3944
  return;
3901
3945
  }
3946
+ // The reviewer credential (THUMBGATE_REVIEWER_KEY) is read-only: it may
3947
+ // only invoke tools annotated readOnlyHint:true. This makes a credential
3948
+ // safe to share (e.g. with a directory reviewer) without granting the
3949
+ // ability to mutate shared server state.
3950
+ const effectiveKey = oauthSession ? String(oauthSession.boundKey || '') : bearer;
3951
+ const isReviewer = Boolean(reviewerKey) && safeKeyEqual(effectiveKey, reviewerKey);
3952
+ if (isReviewer) {
3953
+ const name = msg.params && msg.params.name;
3954
+ const tool = MCP_TOOLS.find((t) => t.name === name);
3955
+ const readOnly = Boolean(tool && tool.annotations && tool.annotations.readOnlyHint === true);
3956
+ if (!readOnly) {
3957
+ sendJson(res, 200, {
3958
+ jsonrpc: '2.0', id: msg.id,
3959
+ error: { code: -32002, message: `Tool "${name}" requires write access; the reviewer credential is read-only.` },
3960
+ });
3961
+ return;
3962
+ }
3963
+ }
3902
3964
  (async () => {
3903
3965
  try {
3904
3966
  const { callTool } = require('../../adapters/mcp/server-stdio');
@@ -5278,6 +5340,14 @@ ${hidden}
5278
5340
  const form = new URLSearchParams(body);
5279
5341
  const redirectUri = form.get('redirect_uri') || '';
5280
5342
  const state = form.get('state') || '';
5343
+ // Validate the presented ThumbGate key before issuing a code. When keys
5344
+ // are configured (production) the key MUST match a configured admin /
5345
+ // operator / reviewer key — otherwise OAuth would authenticate nobody.
5346
+ // In insecure/dev mode (no keys configured) any non-empty key is accepted.
5347
+ if (!resolveKeyRole(form.get('api_key') || '')) {
5348
+ sendJson(res, 400, { error: 'access_denied', error_description: 'invalid ThumbGate API key' });
5349
+ return;
5350
+ }
5281
5351
  const issued = mcpOauth.createAuthorizationCode(oauthStore, {
5282
5352
  clientId: form.get('client_id') || '',
5283
5353
  redirectUri,
@@ -6796,6 +6866,7 @@ ${hidden}
6796
6866
  bundleId: body.bundleId,
6797
6867
  partnerProfile: body.partnerProfile,
6798
6868
  delegationMode: body.delegationMode,
6869
+ enforcePlanQuality: body.enforcePlanQuality === true,
6799
6870
  approved: body.approved === true,
6800
6871
  repoPath: body.repoPath,
6801
6872
  });