thumbgate 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/README.md +134 -0
- package/.claude-plugin/bundle/icon.png +0 -0
- package/.claude-plugin/bundle/icon.svg +18 -0
- package/.claude-plugin/bundle/server/index.js +24 -0
- package/.claude-plugin/marketplace.json +36 -0
- package/.claude-plugin/plugin.json +21 -0
- package/.well-known/mcp/server-card.json +231 -0
- package/LICENSE +21 -0
- package/README.md +375 -0
- package/adapters/README.md +9 -0
- package/adapters/amp/skills/thumbgate-feedback/SKILL.md +22 -0
- package/adapters/chatgpt/INSTALL.md +83 -0
- package/adapters/chatgpt/openapi.yaml +1281 -0
- package/adapters/claude/.mcp.json +14 -0
- package/adapters/codex/config.toml +9 -0
- package/adapters/gemini/function-declarations.json +224 -0
- package/adapters/mcp/server-stdio.js +788 -0
- package/adapters/opencode/opencode.json +15 -0
- package/bin/cli.js +1484 -0
- package/bin/memory.sh +64 -0
- package/bin/obsidian-sync.sh +20 -0
- package/bin/postinstall.js +37 -0
- package/config/build-metadata.json +4 -0
- package/config/e2e-critical-flows.json +45 -0
- package/config/gate-templates.json +77 -0
- package/config/gates/claim-verification.json +29 -0
- package/config/gates/computer-use.json +39 -0
- package/config/gates/default.json +117 -0
- package/config/github-about.json +25 -0
- package/config/mcp-allowlists.json +135 -0
- package/config/model-tiers.json +33 -0
- package/config/partner-routing.json +132 -0
- package/config/policy-bundles/constrained-v1.json +64 -0
- package/config/policy-bundles/default-v1.json +91 -0
- package/config/rubrics/default-v1.json +52 -0
- package/config/skill-packs/react-testing.json +23 -0
- package/config/skill-packs/stripe-integration/references/api-spec.json +1 -0
- package/config/skill-packs/stripe-integration/references/webhook-guide.md +3 -0
- package/config/skill-specs/pr-reviewer.json +9 -0
- package/config/skill-specs/release-status.json +9 -0
- package/config/skill-specs/ticket-triage.json +9 -0
- package/config/subagent-profiles.json +32 -0
- package/config/tessl-tiles.json +29 -0
- package/config/thumbgate-settings.managed.json +12 -0
- package/openapi/openapi.yaml +1281 -0
- package/package.json +283 -0
- package/plugins/amp-skill/INSTALL.md +52 -0
- package/plugins/amp-skill/SKILL.md +64 -0
- package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +22 -0
- package/plugins/claude-codex-bridge/.mcp.json +12 -0
- package/plugins/claude-codex-bridge/INSTALL.md +43 -0
- package/plugins/claude-codex-bridge/README.md +46 -0
- package/plugins/claude-codex-bridge/scripts/codex-bridge.js +288 -0
- package/plugins/claude-codex-bridge/skills/adversarial-review/SKILL.md +24 -0
- package/plugins/claude-codex-bridge/skills/result/SKILL.md +22 -0
- package/plugins/claude-codex-bridge/skills/review/SKILL.md +28 -0
- package/plugins/claude-codex-bridge/skills/second-pass/SKILL.md +27 -0
- package/plugins/claude-codex-bridge/skills/setup/SKILL.md +21 -0
- package/plugins/claude-codex-bridge/skills/status/SKILL.md +19 -0
- package/plugins/claude-skill/INSTALL.md +55 -0
- package/plugins/claude-skill/SKILL.md +46 -0
- package/plugins/codex-profile/.codex-plugin/plugin.json +43 -0
- package/plugins/codex-profile/.mcp.json +12 -0
- package/plugins/codex-profile/AGENTS.md +20 -0
- package/plugins/codex-profile/INSTALL.md +66 -0
- package/plugins/codex-profile/README.md +37 -0
- package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +23 -0
- package/plugins/cursor-marketplace/CHANGELOG.md +30 -0
- package/plugins/cursor-marketplace/LICENSE +21 -0
- package/plugins/cursor-marketplace/README.md +124 -0
- package/plugins/cursor-marketplace/agents/reliability-reviewer.md +31 -0
- package/plugins/cursor-marketplace/assets/logo-400x400.png +0 -0
- package/plugins/cursor-marketplace/commands/capture-feedback.md +33 -0
- package/plugins/cursor-marketplace/commands/check-gates.md +25 -0
- package/plugins/cursor-marketplace/commands/show-lessons.md +27 -0
- package/plugins/cursor-marketplace/hooks/hooks.json +10 -0
- package/plugins/cursor-marketplace/mcp.json +12 -0
- package/plugins/cursor-marketplace/rules/feedback-capture.mdc +34 -0
- package/plugins/cursor-marketplace/rules/pre-action-gates.mdc +30 -0
- package/plugins/cursor-marketplace/rules/session-continuity.mdc +28 -0
- package/plugins/cursor-marketplace/scripts/gate-check.sh +11 -0
- package/plugins/cursor-marketplace/skills/capture-feedback/SKILL.md +47 -0
- package/plugins/cursor-marketplace/skills/prevention-rules/SKILL.md +31 -0
- package/plugins/cursor-marketplace/skills/recall-context/SKILL.md +30 -0
- package/plugins/cursor-marketplace/skills/search-lessons/SKILL.md +33 -0
- package/plugins/gemini-extension/INSTALL.md +92 -0
- package/plugins/gemini-extension/gemini_prompt.txt +14 -0
- package/plugins/gemini-extension/tool_contract.json +45 -0
- package/plugins/opencode-profile/INSTALL.md +57 -0
- package/public/assets/instagram-card.png +0 -0
- package/public/assets/tiktok-agent-memory.mp4 +0 -0
- package/public/blog.html +400 -0
- package/public/dashboard.html +1093 -0
- package/public/guide.html +317 -0
- package/public/index.html +1014 -0
- package/public/learn/agent-harness-pattern.html +180 -0
- package/public/learn/ai-agent-persistent-memory.html +202 -0
- package/public/learn/learn.css +45 -0
- package/public/learn/mcp-pre-action-gates-explained.html +172 -0
- package/public/learn/stop-ai-agent-force-push.html +134 -0
- package/public/learn/vibe-coding-safety-net.html +142 -0
- package/public/learn.html +213 -0
- package/public/lessons.html +650 -0
- package/public/vercel.json +8 -0
- package/scripts/__pycache__/train_from_feedback.cpython-312.pyc +0 -0
- package/scripts/a2ui-engine.js +73 -0
- package/scripts/access-anomaly-detector.js +12 -0
- package/scripts/adk-consolidator.js +266 -0
- package/scripts/agent-readiness.js +220 -0
- package/scripts/agent-security-hardening.js +227 -0
- package/scripts/agentic-data-pipeline.js +847 -0
- package/scripts/analytics-report.js +328 -0
- package/scripts/analytics-window.js +158 -0
- package/scripts/async-job-runner.js +1001 -0
- package/scripts/audit-trail.js +398 -0
- package/scripts/auto-promote-gates.js +299 -0
- package/scripts/auto-wire-hooks.js +312 -0
- package/scripts/autonomous-sales-agent.js +39 -0
- package/scripts/autoresearch-runner.js +216 -0
- package/scripts/background-agent-governance.js +237 -0
- package/scripts/behavioral-extraction.js +97 -0
- package/scripts/belief-update.js +84 -0
- package/scripts/billing.js +2438 -0
- package/scripts/bot-detector.js +50 -0
- package/scripts/budget-guard.js +173 -0
- package/scripts/build-claude-mcpb.js +189 -0
- package/scripts/build-metadata.js +97 -0
- package/scripts/check-congruence.js +322 -0
- package/scripts/cli-feedback.js +135 -0
- package/scripts/cli-telemetry.js +87 -0
- package/scripts/cloudflare-dynamic-sandbox.js +315 -0
- package/scripts/code-reasoning.js +350 -0
- package/scripts/codegraph-context.js +466 -0
- package/scripts/commercial-offer.js +56 -0
- package/scripts/computer-use-firewall.js +250 -0
- package/scripts/context-engine.js +694 -0
- package/scripts/contextfs.js +1287 -0
- package/scripts/conversation-context.js +119 -0
- package/scripts/creator-campaigns.js +239 -0
- package/scripts/daemon-manager.js +108 -0
- package/scripts/daily-digest.js +11 -0
- package/scripts/dashboard-render-spec.js +395 -0
- package/scripts/dashboard.js +1058 -0
- package/scripts/data-governance.js +173 -0
- package/scripts/delegation-runtime.js +900 -0
- package/scripts/deploy-gcp.sh +44 -0
- package/scripts/deploy-policy.js +263 -0
- package/scripts/disagreement-mining.js +315 -0
- package/scripts/dispatch-brief.js +159 -0
- package/scripts/distribution-surfaces.js +44 -0
- package/scripts/dpo-optimizer.js +209 -0
- package/scripts/ephemeral-agent-store.js +219 -0
- package/scripts/eval-harness.js +56 -0
- package/scripts/evolution-state.js +241 -0
- package/scripts/experiment-tracker.js +267 -0
- package/scripts/export-databricks-bundle.js +242 -0
- package/scripts/export-dpo-pairs.js +345 -0
- package/scripts/export-kto-pairs.js +310 -0
- package/scripts/export-training.js +448 -0
- package/scripts/failure-diagnostics.js +558 -0
- package/scripts/feedback-attribution.js +313 -0
- package/scripts/feedback-fallback.js +111 -0
- package/scripts/feedback-history-distiller.js +391 -0
- package/scripts/feedback-inbox-read.js +162 -0
- package/scripts/feedback-loop.js +1887 -0
- package/scripts/feedback-paths.js +145 -0
- package/scripts/feedback-quality.js +139 -0
- package/scripts/feedback-root-consolidator.js +238 -0
- package/scripts/feedback-schema.js +426 -0
- package/scripts/feedback-session.js +286 -0
- package/scripts/feedback-to-memory.js +185 -0
- package/scripts/feedback-to-rules.js +163 -0
- package/scripts/filesystem-search.js +404 -0
- package/scripts/funnel-analytics.js +35 -0
- package/scripts/gate-satisfy.js +42 -0
- package/scripts/gate-stats.js +116 -0
- package/scripts/gate-templates.js +70 -0
- package/scripts/gates-engine.js +816 -0
- package/scripts/generate-paperbanana-diagrams.sh +99 -0
- package/scripts/generate-pretool-hook.sh +40 -0
- package/scripts/github-about.js +350 -0
- package/scripts/github-outreach.js +65 -0
- package/scripts/gtm-revenue-loop.js +520 -0
- package/scripts/hallucination-detector.js +226 -0
- package/scripts/hf-papers.js +317 -0
- package/scripts/history-distiller.js +200 -0
- package/scripts/hook-auto-capture.sh +95 -0
- package/scripts/hook-stop-pr-thread-check.sh +68 -0
- package/scripts/hook-stop-self-score.sh +51 -0
- package/scripts/hook-stop-verify-deploy.sh +31 -0
- package/scripts/hook-thumbgate-cache-updater.js +48 -0
- package/scripts/hook-verify-before-done.sh +20 -0
- package/scripts/hosted-config.js +170 -0
- package/scripts/hybrid-feedback-context.js +676 -0
- package/scripts/install-mcp.js +159 -0
- package/scripts/intent-router.js +392 -0
- package/scripts/internal-agent-bootstrap.js +490 -0
- package/scripts/jsonl-watcher.js +155 -0
- package/scripts/lesson-db.js +613 -0
- package/scripts/lesson-inference.js +315 -0
- package/scripts/lesson-retrieval.js +95 -0
- package/scripts/lesson-rotation.js +137 -0
- package/scripts/lesson-search.js +644 -0
- package/scripts/lesson-synthesis.js +196 -0
- package/scripts/license.js +50 -0
- package/scripts/local-model-profile.js +383 -0
- package/scripts/markdown-escape.js +12 -0
- package/scripts/marketing-experiment.js +671 -0
- package/scripts/mcp-config.js +149 -0
- package/scripts/mcp-policy.js +99 -0
- package/scripts/memalign-recall.js +111 -0
- package/scripts/memory-firewall.js +222 -0
- package/scripts/memory-migration.js +296 -0
- package/scripts/meta-policy.js +194 -0
- package/scripts/metered-billing.js +16 -0
- package/scripts/model-tier-router.js +301 -0
- package/scripts/money-watcher.js +71 -0
- package/scripts/multi-hop-recall.js +240 -0
- package/scripts/natural-language-harness.js +330 -0
- package/scripts/obsidian-export.js +712 -0
- package/scripts/operational-dashboard.js +103 -0
- package/scripts/operational-summary.js +93 -0
- package/scripts/optimize-context.js +17 -0
- package/scripts/org-dashboard.js +201 -0
- package/scripts/partner-orchestration.js +146 -0
- package/scripts/per-step-scoring.js +165 -0
- package/scripts/perplexity-marketing.js +466 -0
- package/scripts/pii-scanner.js +153 -0
- package/scripts/plan-gate.js +154 -0
- package/scripts/post-everywhere.js +308 -0
- package/scripts/post-to-x-retry.sh +22 -0
- package/scripts/post-to-x.js +369 -0
- package/scripts/pr-manager.js +236 -0
- package/scripts/predictive-insights.js +356 -0
- package/scripts/principle-extractor.js +162 -0
- package/scripts/pro-features.js +40 -0
- package/scripts/pro-local-dashboard.js +174 -0
- package/scripts/problem-detail.js +53 -0
- package/scripts/product-feedback.js +134 -0
- package/scripts/profile-router.js +245 -0
- package/scripts/prompt-dlp.js +221 -0
- package/scripts/prompt-guard.js +83 -0
- package/scripts/prove-adapters.js +863 -0
- package/scripts/prove-attribution.js +365 -0
- package/scripts/prove-automation.js +653 -0
- package/scripts/prove-autoresearch.js +304 -0
- package/scripts/prove-claim-verification.js +277 -0
- package/scripts/prove-cloudflare-sandbox.js +163 -0
- package/scripts/prove-data-pipeline.js +410 -0
- package/scripts/prove-data-quality.js +227 -0
- package/scripts/prove-evolution.js +352 -0
- package/scripts/prove-harnesses.js +287 -0
- package/scripts/prove-intelligence.js +259 -0
- package/scripts/prove-lancedb.js +371 -0
- package/scripts/prove-local-intelligence.js +342 -0
- package/scripts/prove-loop-closure.js +263 -0
- package/scripts/prove-predictive-insights.js +357 -0
- package/scripts/prove-runtime.js +350 -0
- package/scripts/prove-seo-gsd.js +234 -0
- package/scripts/prove-settings.js +279 -0
- package/scripts/prove-subway-upgrades.js +277 -0
- package/scripts/prove-tessl.js +229 -0
- package/scripts/prove-training-export.js +327 -0
- package/scripts/prove-workflow-contract.js +116 -0
- package/scripts/prove-xmemory.js +332 -0
- package/scripts/publish-decision.js +133 -0
- package/scripts/pulse.js +80 -0
- package/scripts/rate-limiter.js +125 -0
- package/scripts/reddit-dm-outreach.js +182 -0
- package/scripts/reddit-monitor-cron.sh +26 -0
- package/scripts/reflector-agent.js +221 -0
- package/scripts/reminder-engine.js +132 -0
- package/scripts/revenue-status.js +472 -0
- package/scripts/risk-scorer.js +458 -0
- package/scripts/rlaif-self-audit.js +129 -0
- package/scripts/rubric-engine.js +230 -0
- package/scripts/schedule-manager.js +251 -0
- package/scripts/secret-scanner.js +414 -0
- package/scripts/self-heal.js +147 -0
- package/scripts/self-healing-check.js +188 -0
- package/scripts/semantic-layer.js +98 -0
- package/scripts/seo-gsd.js +1153 -0
- package/scripts/settings-hierarchy.js +214 -0
- package/scripts/shieldcortex-memory-firewall-runner.mjs +53 -0
- package/scripts/skill-exporter.js +262 -0
- package/scripts/skill-generator.js +446 -0
- package/scripts/skill-materializer.js +134 -0
- package/scripts/skill-packs.js +136 -0
- package/scripts/skill-proposer.js +99 -0
- package/scripts/skill-quality-tracker.js +284 -0
- package/scripts/slo-alert-engine.js +14 -0
- package/scripts/slow-loop.js +72 -0
- package/scripts/social-analytics/db/schema.sql +32 -0
- package/scripts/social-analytics/digest.js +256 -0
- package/scripts/social-analytics/generate-instagram-card.js +97 -0
- package/scripts/social-analytics/instagram-thumbgate-post.js +73 -0
- package/scripts/social-analytics/mcp-server.js +289 -0
- package/scripts/social-analytics/normalizer.js +580 -0
- package/scripts/social-analytics/notify.js +162 -0
- package/scripts/social-analytics/poll-all.js +107 -0
- package/scripts/social-analytics/pollers/github.js +195 -0
- package/scripts/social-analytics/pollers/instagram.js +253 -0
- package/scripts/social-analytics/pollers/linkedin.js +330 -0
- package/scripts/social-analytics/pollers/plausible.js +247 -0
- package/scripts/social-analytics/pollers/reddit.js +306 -0
- package/scripts/social-analytics/pollers/threads.js +233 -0
- package/scripts/social-analytics/pollers/tiktok.js +203 -0
- package/scripts/social-analytics/pollers/x.js +227 -0
- package/scripts/social-analytics/pollers/youtube.js +304 -0
- package/scripts/social-analytics/pollers/zernio.js +180 -0
- package/scripts/social-analytics/publish-instagram-thumbgate.js +85 -0
- package/scripts/social-analytics/publishers/devto.js +122 -0
- package/scripts/social-analytics/publishers/instagram.js +317 -0
- package/scripts/social-analytics/publishers/linkedin.js +294 -0
- package/scripts/social-analytics/publishers/reddit.js +390 -0
- package/scripts/social-analytics/publishers/threads.js +275 -0
- package/scripts/social-analytics/publishers/tiktok.js +217 -0
- package/scripts/social-analytics/publishers/x.js +259 -0
- package/scripts/social-analytics/publishers/youtube.js +223 -0
- package/scripts/social-analytics/publishers/zernio.js +209 -0
- package/scripts/social-analytics/run-digest.js +34 -0
- package/scripts/social-analytics/store.js +257 -0
- package/scripts/social-analytics/utm.js +143 -0
- package/scripts/social-pipeline.js +2628 -0
- package/scripts/social-quality-gate.js +18 -0
- package/scripts/social-reply-monitor.js +445 -0
- package/scripts/status-dashboard.js +155 -0
- package/scripts/statusline-lesson.js +16 -0
- package/scripts/statusline-tower.js +8 -0
- package/scripts/statusline.sh +116 -0
- package/scripts/stripe-live-status.js +115 -0
- package/scripts/subagent-profiles.js +79 -0
- package/scripts/sync-gh-secrets-from-env.sh +70 -0
- package/scripts/sync-github-about.js +52 -0
- package/scripts/sync-version.js +451 -0
- package/scripts/synthetic-dpo.js +234 -0
- package/scripts/telemetry-analytics.js +821 -0
- package/scripts/tessl-export.js +371 -0
- package/scripts/test-coverage.js +120 -0
- package/scripts/thompson-sampling.js +417 -0
- package/scripts/thumbgate-search.js +189 -0
- package/scripts/tool-kpi-tracker.js +12 -0
- package/scripts/tool-registry.js +811 -0
- package/scripts/train_from_feedback.py +910 -0
- package/scripts/user-profile.js +78 -0
- package/scripts/validate-feedback.js +580 -0
- package/scripts/validate-workflow-contract.js +287 -0
- package/scripts/vector-store.js +198 -0
- package/scripts/verification-loop.js +291 -0
- package/scripts/verify-obsidian-setup.sh +269 -0
- package/scripts/verify-run.js +269 -0
- package/scripts/webhook-delivery.js +62 -0
- package/scripts/weekly-auto-post.js +124 -0
- package/scripts/workflow-runs.js +154 -0
- package/scripts/workflow-sprint-intake.js +475 -0
- package/scripts/workspace-evolver.js +374 -0
- package/scripts/x-autonomous-marketing.js +139 -0
- package/scripts/xmemory-lite.js +405 -0
- package/skills/agent-memory/SKILL.md +97 -0
- package/skills/solve-architecture-autonomy/SKILL.md +17 -0
- package/skills/solve-architecture-autonomy/tool.js +33 -0
- package/skills/thumbgate/SKILL.md +114 -0
- package/skills/thumbgate-feedback/SKILL.md +49 -0
- package/src/api/server.js +4208 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const BOT_PATTERNS = [
|
|
4
|
+
/bot/i, /crawl/i, /spider/i, /slurp/i, /mediapartners/i,
|
|
5
|
+
/Googlebot/i, /Bingbot/i, /DuckDuckBot/i, /Baiduspider/i,
|
|
6
|
+
/YandexBot/i, /facebookexternalhit/i, /Twitterbot/i,
|
|
7
|
+
/LinkedInBot/i, /WhatsApp/i, /Discordbot/i, /TelegramBot/i,
|
|
8
|
+
/Applebot/i, /PetalBot/i, /SemrushBot/i, /AhrefsBot/i,
|
|
9
|
+
/MJ12bot/i, /DotBot/i, /Bytespider/i,
|
|
10
|
+
/GPTBot/i, /ChatGPT/i, /Claude-SearchBot/i, /Anthropic/i, /Perplexity/i,
|
|
11
|
+
/Google-Extended/i, /CCBot/i, /cohere-ai/i,
|
|
12
|
+
/HeadlessChrome/i, /PhantomJS/i, /Puppeteer/i, /Playwright/i,
|
|
13
|
+
/python-requests/i, /node-fetch/i, /wget/i,
|
|
14
|
+
/Scrapy/i, /HttpClient/i, /Go-http-client/i,
|
|
15
|
+
/UptimeRobot/i, /Pingdom/i, /StatusCake/i,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const OWNER_EMAILS = ['iganapolsky@gmail.com', 'ig5973700@gmail.com'];
|
|
19
|
+
|
|
20
|
+
function classifyVisitor(req) {
|
|
21
|
+
const ua = (req.headers && req.headers['user-agent']) || '';
|
|
22
|
+
const email = req.email || (req.query && req.query.email) || '';
|
|
23
|
+
|
|
24
|
+
for (const pattern of BOT_PATTERNS) {
|
|
25
|
+
if (pattern.test(ua)) {
|
|
26
|
+
return { type: 'bot', reason: `UA matches: ${pattern}`, userAgent: ua };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (!ua || ua.length < 10) {
|
|
30
|
+
return { type: 'bot', reason: 'Empty or short user-agent', userAgent: ua };
|
|
31
|
+
}
|
|
32
|
+
for (const ownerEmail of OWNER_EMAILS) {
|
|
33
|
+
if (email && email.toLowerCase().includes(ownerEmail.toLowerCase())) {
|
|
34
|
+
return { type: 'owner', reason: `Email matches: ${ownerEmail}`, userAgent: ua };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { type: 'real_user', reason: 'No bot pattern matched', userAgent: ua };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function shouldExcludeFromAnalytics(req) {
|
|
41
|
+
const classification = req.visitorClass || classifyVisitor(req);
|
|
42
|
+
return classification.type === 'bot';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function botFilterMiddleware(req, res, next) {
|
|
46
|
+
req.visitorClass = classifyVisitor(req);
|
|
47
|
+
next();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { classifyVisitor, botFilterMiddleware, shouldExcludeFromAnalytics, BOT_PATTERNS, OWNER_EMAILS };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const PROJECT_ROOT = path.join(__dirname, '..');
|
|
6
|
+
const FEEDBACK_DIR = process.env.THUMBGATE_FEEDBACK_DIR || path.join(PROJECT_ROOT, '.claude', 'memory', 'feedback');
|
|
7
|
+
const LEDGER_PATH = path.join(FEEDBACK_DIR, 'budget-ledger.json');
|
|
8
|
+
const LOCK_PATH = `${LEDGER_PATH}.lock`;
|
|
9
|
+
|
|
10
|
+
function parseMonthlyBudget(rawValue) {
|
|
11
|
+
const parsed = Number(rawValue);
|
|
12
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
13
|
+
throw new Error(`Invalid THUMBGATE_MONTHLY_BUDGET_USD value: '${rawValue}'`);
|
|
14
|
+
}
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getMonthlyBudget() {
|
|
19
|
+
const rawValue = process.env.THUMBGATE_MONTHLY_BUDGET_USD || '10';
|
|
20
|
+
return parseMonthlyBudget(rawValue);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function currentMonthKey() {
|
|
24
|
+
const now = new Date();
|
|
25
|
+
return `${now.getUTCFullYear()}-${String(now.getUTCMonth() + 1).padStart(2, '0')}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function loadLedger() {
|
|
29
|
+
if (!fs.existsSync(LEDGER_PATH)) return { months: {} };
|
|
30
|
+
return JSON.parse(fs.readFileSync(LEDGER_PATH, 'utf-8'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function saveLedger(ledger) {
|
|
34
|
+
fs.mkdirSync(path.dirname(LEDGER_PATH), { recursive: true });
|
|
35
|
+
fs.writeFileSync(LEDGER_PATH, `${JSON.stringify(ledger, null, 2)}\n`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function blockMs(ms) {
|
|
39
|
+
const start = Date.now();
|
|
40
|
+
while (Date.now() - start < ms) {
|
|
41
|
+
// Intentional synchronous short wait while lock clears.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function acquireLock({ timeoutMs = 5000, staleMs = 15000 } = {}) {
|
|
46
|
+
const startedAt = Date.now();
|
|
47
|
+
fs.mkdirSync(path.dirname(LOCK_PATH), { recursive: true });
|
|
48
|
+
|
|
49
|
+
while (true) {
|
|
50
|
+
try {
|
|
51
|
+
return fs.openSync(LOCK_PATH, 'wx');
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (err.code !== 'EEXIST') throw err;
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const stat = fs.statSync(LOCK_PATH);
|
|
57
|
+
if (Date.now() - stat.mtimeMs > staleMs) {
|
|
58
|
+
fs.rmSync(LOCK_PATH, { force: true });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
// lock disappeared between retries
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Date.now() - startedAt > timeoutMs) {
|
|
66
|
+
throw new Error('Could not acquire budget ledger lock');
|
|
67
|
+
}
|
|
68
|
+
blockMs(20);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function releaseLock(lockFd) {
|
|
74
|
+
try {
|
|
75
|
+
fs.closeSync(lockFd);
|
|
76
|
+
} finally {
|
|
77
|
+
fs.rmSync(LOCK_PATH, { force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function addSpend({ amountUsd, source, note }) {
|
|
82
|
+
if (!Number.isFinite(amountUsd) || amountUsd < 0) {
|
|
83
|
+
throw new Error('amountUsd must be a non-negative number');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const budgetUsd = getMonthlyBudget();
|
|
87
|
+
const lockFd = acquireLock();
|
|
88
|
+
try {
|
|
89
|
+
const ledger = loadLedger();
|
|
90
|
+
const month = currentMonthKey();
|
|
91
|
+
if (!ledger.months[month]) {
|
|
92
|
+
ledger.months[month] = {
|
|
93
|
+
totalUsd: 0,
|
|
94
|
+
entries: [],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const nextTotal = ledger.months[month].totalUsd + amountUsd;
|
|
99
|
+
if (nextTotal > budgetUsd) {
|
|
100
|
+
throw new Error(`Budget exceeded: ${nextTotal.toFixed(2)} > ${budgetUsd.toFixed(2)} USD/month`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ledger.months[month].totalUsd = nextTotal;
|
|
104
|
+
ledger.months[month].entries.push({
|
|
105
|
+
ts: new Date().toISOString(),
|
|
106
|
+
source: source || 'unknown',
|
|
107
|
+
note: note || '',
|
|
108
|
+
amountUsd,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
saveLedger(ledger);
|
|
112
|
+
return {
|
|
113
|
+
month,
|
|
114
|
+
totalUsd: ledger.months[month].totalUsd,
|
|
115
|
+
budgetUsd,
|
|
116
|
+
};
|
|
117
|
+
} finally {
|
|
118
|
+
releaseLock(lockFd);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getBudgetStatus() {
|
|
123
|
+
const budgetUsd = getMonthlyBudget();
|
|
124
|
+
const ledger = loadLedger();
|
|
125
|
+
const month = currentMonthKey();
|
|
126
|
+
const total = ledger.months[month] ? ledger.months[month].totalUsd : 0;
|
|
127
|
+
return {
|
|
128
|
+
month,
|
|
129
|
+
totalUsd: total,
|
|
130
|
+
budgetUsd,
|
|
131
|
+
remainingUsd: Math.max(0, budgetUsd - total),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function runCli() {
|
|
136
|
+
const args = process.argv.slice(2);
|
|
137
|
+
if (args.includes('--status')) {
|
|
138
|
+
console.log(JSON.stringify(getBudgetStatus(), null, 2));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const addArg = args.find((a) => a.startsWith('--add='));
|
|
143
|
+
if (!addArg) {
|
|
144
|
+
console.log('Usage: node scripts/budget-guard.js --status');
|
|
145
|
+
console.log('Usage: node scripts/budget-guard.js --add=0.15 --source=paperbanana --note="diagram generation"');
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const amountUsd = Number(addArg.replace('--add=', ''));
|
|
150
|
+
const sourceArg = args.find((a) => a.startsWith('--source='));
|
|
151
|
+
const noteArg = args.find((a) => a.startsWith('--note='));
|
|
152
|
+
|
|
153
|
+
const result = addSpend({
|
|
154
|
+
amountUsd,
|
|
155
|
+
source: sourceArg ? sourceArg.replace('--source=', '') : 'unknown',
|
|
156
|
+
note: noteArg ? noteArg.replace('--note=', '') : '',
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
console.log(JSON.stringify(result, null, 2));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = {
|
|
163
|
+
addSpend,
|
|
164
|
+
getBudgetStatus,
|
|
165
|
+
getMonthlyBudget,
|
|
166
|
+
parseMonthlyBudget,
|
|
167
|
+
LEDGER_PATH,
|
|
168
|
+
LOCK_PATH,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (require.main === module) {
|
|
172
|
+
runCli();
|
|
173
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { execFileSync } = require('child_process');
|
|
7
|
+
const {
|
|
8
|
+
getClaudePluginVersionedAssetName,
|
|
9
|
+
} = require('./distribution-surfaces');
|
|
10
|
+
|
|
11
|
+
const PROJECT_ROOT = path.join(__dirname, '..');
|
|
12
|
+
const DEFAULT_OUTPUT_DIR = path.join(PROJECT_ROOT, '.artifacts', 'claude-desktop');
|
|
13
|
+
const RUNTIME_COPY_PATHS = [
|
|
14
|
+
'bin',
|
|
15
|
+
'src',
|
|
16
|
+
'scripts',
|
|
17
|
+
'adapters',
|
|
18
|
+
'config',
|
|
19
|
+
'plugins',
|
|
20
|
+
'skills',
|
|
21
|
+
'openapi',
|
|
22
|
+
'public',
|
|
23
|
+
'.well-known',
|
|
24
|
+
'.claude-plugin',
|
|
25
|
+
'README.md',
|
|
26
|
+
'LICENSE',
|
|
27
|
+
'SECURITY.md',
|
|
28
|
+
'server.json',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
function readJson(relativePath) {
|
|
32
|
+
return JSON.parse(fs.readFileSync(path.join(PROJECT_ROOT, relativePath), 'utf8'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function readText(relativePath) {
|
|
36
|
+
return fs.readFileSync(path.join(PROJECT_ROOT, relativePath), 'utf8');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function copyEntry(relativePath, stageDir) {
|
|
40
|
+
const sourcePath = path.join(PROJECT_ROOT, relativePath);
|
|
41
|
+
if (!fs.existsSync(sourcePath)) return;
|
|
42
|
+
|
|
43
|
+
const targetPath = path.join(stageDir, relativePath);
|
|
44
|
+
const stat = fs.statSync(sourcePath);
|
|
45
|
+
if (stat.isDirectory()) {
|
|
46
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
47
|
+
fs.cpSync(sourcePath, targetPath, { recursive: true });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
52
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function exec(command, args, options = {}) {
|
|
56
|
+
return execFileSync(command, args, {
|
|
57
|
+
cwd: PROJECT_ROOT,
|
|
58
|
+
stdio: 'inherit',
|
|
59
|
+
...options,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function buildClaudeMcpbManifest() {
|
|
64
|
+
const packageJson = readJson('package.json');
|
|
65
|
+
const pluginManifest = readJson('.claude-plugin/plugin.json');
|
|
66
|
+
const marketplace = readJson('.claude-plugin/marketplace.json');
|
|
67
|
+
const { TOOLS } = require(path.join(PROJECT_ROOT, 'scripts', 'tool-registry'));
|
|
68
|
+
|
|
69
|
+
const repositoryUrl = String(pluginManifest.repository || packageJson.repository.url).replace(/\.git$/, '');
|
|
70
|
+
const privacyPolicyUrl = `${packageJson.homepage}/privacy`;
|
|
71
|
+
const marketplaceEntry = marketplace.plugins[0];
|
|
72
|
+
const readme = readText('.claude-plugin/README.md')
|
|
73
|
+
.split('\n')
|
|
74
|
+
.slice(0, 6)
|
|
75
|
+
.join(' ')
|
|
76
|
+
.replace(/\s+/g, ' ')
|
|
77
|
+
.trim();
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
manifest_version: '0.3',
|
|
81
|
+
name: pluginManifest.name,
|
|
82
|
+
display_name: 'ThumbGate',
|
|
83
|
+
version: packageJson.version,
|
|
84
|
+
description: marketplaceEntry.description,
|
|
85
|
+
long_description: readme,
|
|
86
|
+
author: {
|
|
87
|
+
name: pluginManifest.author.name,
|
|
88
|
+
url: repositoryUrl,
|
|
89
|
+
},
|
|
90
|
+
repository: {
|
|
91
|
+
type: 'git',
|
|
92
|
+
url: repositoryUrl,
|
|
93
|
+
},
|
|
94
|
+
homepage: packageJson.homepage,
|
|
95
|
+
documentation: `${repositoryUrl}/blob/main/docs/CLAUDE_DESKTOP_EXTENSION.md`,
|
|
96
|
+
support: `${repositoryUrl}/issues`,
|
|
97
|
+
icon: 'icon.png',
|
|
98
|
+
server: {
|
|
99
|
+
type: 'node',
|
|
100
|
+
entry_point: 'server/index.js',
|
|
101
|
+
mcp_config: {
|
|
102
|
+
command: 'node',
|
|
103
|
+
args: ['${__dirname}/server/index.js'],
|
|
104
|
+
env: {},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
tools: TOOLS.map((tool) => ({
|
|
108
|
+
name: tool.name,
|
|
109
|
+
description: tool.description,
|
|
110
|
+
})),
|
|
111
|
+
tools_generated: true,
|
|
112
|
+
keywords: pluginManifest.keywords,
|
|
113
|
+
license: packageJson.license,
|
|
114
|
+
privacy_policies: [privacyPolicyUrl],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function stageClaudeMcpbBundle(outputDir = DEFAULT_OUTPUT_DIR) {
|
|
119
|
+
const packageJson = readJson('package.json');
|
|
120
|
+
const stageDir = path.join(outputDir, 'bundle');
|
|
121
|
+
const outputFile = path.join(outputDir, getClaudePluginVersionedAssetName(packageJson.version));
|
|
122
|
+
|
|
123
|
+
fs.rmSync(outputDir, { recursive: true, force: true });
|
|
124
|
+
fs.mkdirSync(path.join(stageDir, 'server'), { recursive: true });
|
|
125
|
+
|
|
126
|
+
for (const relativePath of RUNTIME_COPY_PATHS) {
|
|
127
|
+
copyEntry(relativePath, stageDir);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
copyEntry('package.json', stageDir);
|
|
131
|
+
copyEntry('package-lock.json', stageDir);
|
|
132
|
+
|
|
133
|
+
fs.writeFileSync(
|
|
134
|
+
path.join(stageDir, 'server', 'index.js'),
|
|
135
|
+
readText('.claude-plugin/bundle/server/index.js')
|
|
136
|
+
);
|
|
137
|
+
fs.writeFileSync(
|
|
138
|
+
path.join(stageDir, 'icon.png'),
|
|
139
|
+
fs.readFileSync(path.join(PROJECT_ROOT, '.claude-plugin', 'bundle', 'icon.png'))
|
|
140
|
+
);
|
|
141
|
+
fs.writeFileSync(
|
|
142
|
+
path.join(stageDir, 'README.md'),
|
|
143
|
+
readText('.claude-plugin/README.md')
|
|
144
|
+
);
|
|
145
|
+
fs.writeFileSync(
|
|
146
|
+
path.join(stageDir, 'manifest.json'),
|
|
147
|
+
JSON.stringify(buildClaudeMcpbManifest(), null, 2) + '\n'
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
stageDir,
|
|
152
|
+
outputFile,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function buildClaudeMcpb(outputDir = DEFAULT_OUTPUT_DIR) {
|
|
157
|
+
const { stageDir, outputFile } = stageClaudeMcpbBundle(outputDir);
|
|
158
|
+
|
|
159
|
+
exec('npm', ['ci', '--omit=dev'], { cwd: stageDir });
|
|
160
|
+
exec('npx', ['-y', '@anthropic-ai/mcpb', 'pack', stageDir, outputFile], { cwd: PROJECT_ROOT });
|
|
161
|
+
|
|
162
|
+
const info = execFileSync('npx', ['-y', '@anthropic-ai/mcpb', 'info', outputFile], {
|
|
163
|
+
cwd: PROJECT_ROOT,
|
|
164
|
+
encoding: 'utf8',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
process.stdout.write(info);
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
stageDir,
|
|
171
|
+
outputFile,
|
|
172
|
+
info,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (require.main === module) {
|
|
177
|
+
const outputDir = process.argv[2]
|
|
178
|
+
? path.resolve(process.cwd(), process.argv[2])
|
|
179
|
+
: DEFAULT_OUTPUT_DIR;
|
|
180
|
+
const { outputFile } = buildClaudeMcpb(outputDir);
|
|
181
|
+
console.log(`Built Claude Desktop bundle: ${outputFile}`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
module.exports = {
|
|
185
|
+
DEFAULT_OUTPUT_DIR,
|
|
186
|
+
buildClaudeMcpbManifest,
|
|
187
|
+
stageClaudeMcpbBundle,
|
|
188
|
+
buildClaudeMcpb,
|
|
189
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const PROJECT_ROOT = path.resolve(__dirname, '..');
|
|
5
|
+
const DEFAULT_BUILD_METADATA_PATH = path.join(PROJECT_ROOT, 'config', 'build-metadata.json');
|
|
6
|
+
|
|
7
|
+
function normalizeNullableText(value) {
|
|
8
|
+
if (typeof value !== 'string') {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const trimmed = value.trim();
|
|
13
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function resolveBuildMetadata({ env = process.env, filePath } = {}) {
|
|
17
|
+
const resolvedPath =
|
|
18
|
+
normalizeNullableText(filePath) ||
|
|
19
|
+
normalizeNullableText(env.THUMBGATE_BUILD_METADATA_PATH) ||
|
|
20
|
+
DEFAULT_BUILD_METADATA_PATH;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(fs.readFileSync(resolvedPath, 'utf8'));
|
|
24
|
+
return {
|
|
25
|
+
path: resolvedPath,
|
|
26
|
+
buildSha: normalizeNullableText(parsed.buildSha),
|
|
27
|
+
generatedAt: normalizeNullableText(parsed.generatedAt),
|
|
28
|
+
};
|
|
29
|
+
} catch {
|
|
30
|
+
return {
|
|
31
|
+
path: resolvedPath,
|
|
32
|
+
buildSha: null,
|
|
33
|
+
generatedAt: null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function writeBuildMetadataFile({ sha, outputPath, generatedAt = new Date().toISOString() }) {
|
|
39
|
+
const buildSha = normalizeNullableText(sha);
|
|
40
|
+
if (!buildSha) {
|
|
41
|
+
throw new Error('A non-empty build SHA is required.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const targetPath = normalizeNullableText(outputPath) || DEFAULT_BUILD_METADATA_PATH;
|
|
45
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
46
|
+
const payload = {
|
|
47
|
+
buildSha,
|
|
48
|
+
generatedAt,
|
|
49
|
+
};
|
|
50
|
+
fs.writeFileSync(targetPath, `${JSON.stringify(payload, null, 2)}\n`);
|
|
51
|
+
return {
|
|
52
|
+
path: targetPath,
|
|
53
|
+
...payload,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseArgs(argv) {
|
|
58
|
+
const options = {
|
|
59
|
+
sha: null,
|
|
60
|
+
outputPath: null,
|
|
61
|
+
generatedAt: null,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
65
|
+
const arg = argv[index];
|
|
66
|
+
if (arg === '--sha') {
|
|
67
|
+
options.sha = argv[index + 1] || null;
|
|
68
|
+
index += 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (arg === '--output') {
|
|
72
|
+
options.outputPath = argv[index + 1] || null;
|
|
73
|
+
index += 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (arg === '--generated-at') {
|
|
77
|
+
options.generatedAt = argv[index + 1] || null;
|
|
78
|
+
index += 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return options;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (require.main === module) {
|
|
88
|
+
const { sha, outputPath, generatedAt } = parseArgs(process.argv.slice(2));
|
|
89
|
+
const result = writeBuildMetadataFile({ sha, outputPath, generatedAt: generatedAt || undefined });
|
|
90
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
DEFAULT_BUILD_METADATA_PATH,
|
|
95
|
+
resolveBuildMetadata,
|
|
96
|
+
writeBuildMetadataFile,
|
|
97
|
+
};
|