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,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const BOT_SLOP_PATTERNS = [
|
|
4
|
+
{ id: 'emoji_spam', pattern: /(?:🚀|💡|🔥|⚡|🎯|💪|🙌|👀){3,}/g, reason: 'Excessive emoji spam' },
|
|
5
|
+
{ id: 'generic_opener', pattern: /^(?:Just|Excited to|Thrilled to|Happy to|Proud to) (?:\w+ )*?(?:launch|ship|release|publish|built|creat|announc)/i, reason: 'Generic shipped opener' },
|
|
6
|
+
{ id: 'hashtag_spam', pattern: /#[A-Za-z]+(?:\s+#[A-Za-z]+){5,}/g, reason: 'Too many hashtags' },
|
|
7
|
+
{ id: 'engagement_bait', pattern: /(?:Like if you agree|Retweet if|Share this|Follow for more|Drop a .* in the comments|Who else)/i, reason: 'Engagement bait' },
|
|
8
|
+
{ id: 'thread_bait', pattern: /^(?:Thread|🧵|A thread on|Here are \d+ (?:ways|tips|tricks|things|reasons))/i, reason: 'Thread bait opener' },
|
|
9
|
+
{ id: 'ai_generated_tell', pattern: /(?:In today's rapidly evolving|In this comprehensive|Without further ado|It's worth noting that|At the end of the day)/i, reason: 'AI-generated phrasing' },
|
|
10
|
+
{ id: 'fake_urgency', pattern: /(?:Don't miss out|Act now|Limited time|Last chance|You won't believe)/i, reason: 'Fake urgency' },
|
|
11
|
+
{ id: 'self_congratulation', pattern: /(?:We're proud to|I'm honored to|Humbled to|Grateful to announce)/i, reason: 'Self-congratulatory opener' },
|
|
12
|
+
{ id: 'empty_hype', pattern: /(?:game.?changer|revolutionary|disruptive|next.?gen|cutting.?edge|world.?class|best.?in.?class)/i, reason: 'Empty hype words' },
|
|
13
|
+
];
|
|
14
|
+
const MIN_POST_LENGTH = 30;
|
|
15
|
+
const MAX_POST_LENGTH = 2000;
|
|
16
|
+
function scanForSlop(postText) { const text = String(postText || ''); const findings = []; if (text.length < MIN_POST_LENGTH) findings.push({ id: 'too_short', reason: 'Too short' }); if (text.length > MAX_POST_LENGTH) findings.push({ id: 'too_long', reason: 'Too long' }); for (const p of BOT_SLOP_PATTERNS) { p.pattern.lastIndex = 0; if (p.pattern.test(text)) findings.push({ id: p.id, reason: p.reason }); } const words = text.split(/\s+/).filter(w => w.length > 3); const capsWords = words.filter(w => w === w.toUpperCase() && /[A-Z]/.test(w)); if (words.length > 5 && capsWords.length / words.length > 0.3) findings.push({ id: 'caps_shouting', reason: 'Too many ALL CAPS' }); return { allowed: findings.length === 0, findings, findingCount: findings.length, postLength: text.length }; }
|
|
17
|
+
function gatePost(postText) { const scan = scanForSlop(postText); if (!scan.allowed) { console.error('[social-quality-gate] BLOCKED:'); for (const f of scan.findings) console.error(' -', f.id, f.reason); } return scan; }
|
|
18
|
+
module.exports = { scanForSlop, gatePost, BOT_SLOP_PATTERNS, MIN_POST_LENGTH, MAX_POST_LENGTH };
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* social-reply-monitor.js
|
|
5
|
+
* Monitors Reddit, X.com, and LinkedIn for replies to our posts,
|
|
6
|
+
* then generates and posts contextual responses.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* node scripts/social-reply-monitor.js # Check all platforms
|
|
10
|
+
* node scripts/social-reply-monitor.js --platform=reddit # Check one platform
|
|
11
|
+
* node scripts/social-reply-monitor.js --dry-run # Preview replies without posting
|
|
12
|
+
*
|
|
13
|
+
* Env vars: see individual publisher modules.
|
|
14
|
+
* Reply generation uses smart templates (zero cost, no external API).
|
|
15
|
+
*
|
|
16
|
+
* State file: .thumbgate/reply-monitor-state.json — tracks which replies we've already responded to.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
require('dotenv').config();
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
const STATE_FILE = path.resolve(__dirname, '..', '.thumbgate', 'reply-monitor-state.json');
|
|
24
|
+
const REDDIT_API_BASE = 'https://oauth.reddit.com';
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// State management
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
function loadState() {
|
|
31
|
+
try {
|
|
32
|
+
if (fs.existsSync(STATE_FILE)) {
|
|
33
|
+
return JSON.parse(fs.readFileSync(STATE_FILE, 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
} catch { /* ignore */ }
|
|
36
|
+
return { repliedTo: {}, lastCheck: {} };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function saveState(state) {
|
|
40
|
+
const dir = path.dirname(STATE_FILE);
|
|
41
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
42
|
+
fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Reply generation (uses Gemini API for cost-effective generation)
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Draft file for human review (Reddit replies are NEVER auto-posted)
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
const DRAFT_FILE = path.resolve(__dirname, '..', '.thumbgate', 'reply-drafts.jsonl');
|
|
54
|
+
|
|
55
|
+
function saveDraft(draft) {
|
|
56
|
+
const dir = path.dirname(DRAFT_FILE);
|
|
57
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
58
|
+
fs.appendFileSync(DRAFT_FILE, JSON.stringify(draft) + '\n');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// Bot/hostile detection — skip comments that are calling us out
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
function isHostileOrMeta(comment) {
|
|
66
|
+
const lc = (comment || '').toLowerCase();
|
|
67
|
+
const hostile = [
|
|
68
|
+
'bot', 'spam', 'shill', 'promotional', 'reported',
|
|
69
|
+
'same answer', 'word for word', 'copy paste', 'running amok',
|
|
70
|
+
'smell these', 'not what i asked', 'didn\'t ask',
|
|
71
|
+
'auto-generated', 'ai generated', 'chatgpt', 'template',
|
|
72
|
+
];
|
|
73
|
+
return hostile.some(phrase => lc.includes(phrase));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Reply generation — context-aware, NOT canned templates
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Generate a contextual reply by actually reading the comment.
|
|
82
|
+
* Returns null if we should NOT reply (hostile, off-topic, or duplicate risk).
|
|
83
|
+
*/
|
|
84
|
+
async function generateReply(comment, context) {
|
|
85
|
+
const lc = (comment || '').toLowerCase();
|
|
86
|
+
|
|
87
|
+
// NEVER reply to hostile/meta comments calling out bots
|
|
88
|
+
if (isHostileOrMeta(comment)) {
|
|
89
|
+
console.log('[reply-monitor] Skipping hostile/meta comment — do not engage');
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// NEVER reply to our own comments
|
|
94
|
+
if (context.author === 'eazyigz123' || context.author === 'IgorGanapolsky') {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// NEVER reply with generic fluff — build reply from what they ACTUALLY said
|
|
99
|
+
const isQuestion = context.isQuestion || /\?/.test(comment);
|
|
100
|
+
const REPO = 'https://github.com/IgorGanapolsky/ThumbGate';
|
|
101
|
+
|
|
102
|
+
// Extract the specific topic they're asking about
|
|
103
|
+
const mentionsSetup = /install|setup|config|init|npx|how.+start/i.test(lc);
|
|
104
|
+
const mentionsHow = /how does|how do|explain|what is|can you describe/i.test(lc);
|
|
105
|
+
const mentionsGates = /gate|block|prevent|hook|intercept|firewall/i.test(lc);
|
|
106
|
+
const mentionsMemory = /memory|context|session|forget|amnesia|remember/i.test(lc);
|
|
107
|
+
const mentionsCursor = /cursor|windsurf|copilot|cline/i.test(lc);
|
|
108
|
+
const mentionsScaling = /scale|team|multi.?repo|collaborate|share/i.test(lc);
|
|
109
|
+
const mentionsSkeptical = /why not|already exist|what.+different|vs |compared to/i.test(lc);
|
|
110
|
+
const mentionsThanks = /thanks|thank you|cool|nice|interesting|awesome/i.test(lc);
|
|
111
|
+
|
|
112
|
+
// Build response that addresses THEIR specific point
|
|
113
|
+
if (mentionsSetup && isQuestion) {
|
|
114
|
+
return `\`npx thumbgate init\` auto-detects your agent and wires the hooks. Takes about 30 seconds. What agent are you using?`;
|
|
115
|
+
}
|
|
116
|
+
if (mentionsSkeptical) {
|
|
117
|
+
return `Fair question. The difference from rules files or memory tools: this physically blocks the action before execution, not after. The agent can't ignore a gate the way it can ignore a system prompt. Whether that tradeoff is worth it depends on how often your agent repeats mistakes.`;
|
|
118
|
+
}
|
|
119
|
+
if (mentionsHow && mentionsGates) {
|
|
120
|
+
return `PreToolUse hooks intercept the tool call before it runs. Each call is checked against prevention rules promoted from past failures. If it matches, the action is blocked — the agent has to try a different approach. The rules adapt over time via Thompson Sampling so false positives decrease.`;
|
|
121
|
+
}
|
|
122
|
+
if (mentionsScaling) {
|
|
123
|
+
return `For teams, the Pro tier syncs prevention rules across machines so everyone benefits from lessons learned on any repo. But the free local version covers solo dev workflows completely.`;
|
|
124
|
+
}
|
|
125
|
+
if (mentionsMemory && isQuestion) {
|
|
126
|
+
return `The key difference from memory tools: memory helps agents remember, but they can still ignore what they remember. Gates enforce — if there's a rule against force-pushing, the agent physically can't do it. It's enforcement, not suggestion.`;
|
|
127
|
+
}
|
|
128
|
+
if (mentionsCursor && isQuestion) {
|
|
129
|
+
return `Works with Cursor via MCP. The hooks are agent-agnostic — same prevention rules apply whether you're using Cursor, Claude Code, or Codex. What specific failure patterns are you hitting?`;
|
|
130
|
+
}
|
|
131
|
+
if (mentionsThanks && !isQuestion) {
|
|
132
|
+
// Don't reply to simple "thanks" — it looks desperate
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (isQuestion) {
|
|
136
|
+
// They asked something specific we didn't match — better to draft for human review
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
// Not a question, not hostile, not thanks — probably a statement. Don't reply.
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// Reddit: fetch replies and respond
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
async function getRedditToken() {
|
|
148
|
+
const { REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, REDDIT_PASSWORD } = process.env;
|
|
149
|
+
if (!REDDIT_CLIENT_ID || !REDDIT_CLIENT_SECRET || !REDDIT_USERNAME || !REDDIT_PASSWORD) {
|
|
150
|
+
throw new Error('Missing Reddit credentials (REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, REDDIT_PASSWORD)');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const credentials = Buffer.from(`${REDDIT_CLIENT_ID}:${REDDIT_CLIENT_SECRET}`).toString('base64');
|
|
154
|
+
const res = await fetch('https://www.reddit.com/api/v1/access_token', {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
headers: {
|
|
157
|
+
Authorization: `Basic ${credentials}`,
|
|
158
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
159
|
+
'User-Agent': `thumbgate/1.0 by ${REDDIT_USERNAME}`,
|
|
160
|
+
},
|
|
161
|
+
body: new URLSearchParams({ grant_type: 'password', username: REDDIT_USERNAME, password: REDDIT_PASSWORD }).toString(),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const json = await res.json();
|
|
165
|
+
if (json.error) throw new Error(`Reddit auth: ${json.error}`);
|
|
166
|
+
return json.access_token;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function checkRedditReplies(state, dryRun) {
|
|
170
|
+
console.log('[reply-monitor] Checking Reddit inbox...');
|
|
171
|
+
|
|
172
|
+
let token;
|
|
173
|
+
try {
|
|
174
|
+
token = await getRedditToken();
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.warn(`[reply-monitor] Reddit auth failed: ${err.message}`);
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const userAgent = `thumbgate/1.0 by ${process.env.REDDIT_USERNAME}`;
|
|
181
|
+
|
|
182
|
+
// Fetch inbox (comment replies)
|
|
183
|
+
const res = await fetch(`${REDDIT_API_BASE}/message/inbox?limit=25`, {
|
|
184
|
+
headers: {
|
|
185
|
+
Authorization: `Bearer ${token}`,
|
|
186
|
+
'User-Agent': userAgent,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (!res.ok) {
|
|
191
|
+
console.warn(`[reply-monitor] Reddit inbox fetch failed: ${res.status}`);
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const data = await res.json();
|
|
196
|
+
const replies = (data.data?.children || []).filter(
|
|
197
|
+
(c) => c.kind === 't1' && c.data.type === 'comment_reply'
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const results = [];
|
|
201
|
+
for (const reply of replies) {
|
|
202
|
+
const commentId = reply.data.name;
|
|
203
|
+
if (state.repliedTo[commentId]) continue; // Already replied
|
|
204
|
+
|
|
205
|
+
const commentBody = reply.data.body || '';
|
|
206
|
+
const postTitle = reply.data.link_title || '';
|
|
207
|
+
|
|
208
|
+
console.log(`[reply-monitor] New Reddit reply from u/${reply.data.author}: "${commentBody.slice(0, 80)}..."`);
|
|
209
|
+
|
|
210
|
+
const isQuestion = /\?/.test(commentBody);
|
|
211
|
+
const generatedReply = await generateReply(commentBody, {
|
|
212
|
+
platform: 'reddit',
|
|
213
|
+
postTitle,
|
|
214
|
+
isQuestion,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
if (!generatedReply) {
|
|
218
|
+
console.warn(`[reply-monitor] Could not generate reply for ${commentId}`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
console.log(`[reply-monitor] Generated reply: "${generatedReply.slice(0, 100)}..."`);
|
|
223
|
+
|
|
224
|
+
// Reddit is ALWAYS draft-only — never auto-post.
|
|
225
|
+
// Bot detection on Reddit is aggressive; human must review and post manually.
|
|
226
|
+
const draft = {
|
|
227
|
+
platform: 'reddit',
|
|
228
|
+
commentId,
|
|
229
|
+
author: reply.data.author,
|
|
230
|
+
subreddit: reply.data.subreddit,
|
|
231
|
+
theirComment: commentBody.slice(0, 500),
|
|
232
|
+
suggestedReply: generatedReply,
|
|
233
|
+
postTitle,
|
|
234
|
+
draftedAt: new Date().toISOString(),
|
|
235
|
+
status: 'pending_review',
|
|
236
|
+
};
|
|
237
|
+
saveDraft(draft);
|
|
238
|
+
state.repliedTo[commentId] = { at: new Date().toISOString(), platform: 'reddit', drafted: true };
|
|
239
|
+
results.push({ commentId, reply: generatedReply, posted: false, drafted: true });
|
|
240
|
+
console.log(`[reply-monitor] 📝 DRAFTED reply for ${commentId} (saved to .thumbgate/reply-drafts.jsonl — post manually)`);
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
state.lastCheck.reddit = new Date().toISOString();
|
|
245
|
+
return results;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
// X/Twitter: fetch mentions and respond
|
|
250
|
+
// ---------------------------------------------------------------------------
|
|
251
|
+
|
|
252
|
+
async function checkXReplies(state, dryRun) {
|
|
253
|
+
console.log('[reply-monitor] Checking X/Twitter mentions...');
|
|
254
|
+
|
|
255
|
+
const { X_API_KEY, X_API_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET } = process.env;
|
|
256
|
+
if (!X_API_KEY || !X_ACCESS_TOKEN) {
|
|
257
|
+
console.warn('[reply-monitor] X credentials not configured, skipping');
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Use the post-to-x module for OAuth signing
|
|
262
|
+
let xModule;
|
|
263
|
+
try {
|
|
264
|
+
xModule = require('./post-to-x.js');
|
|
265
|
+
} catch {
|
|
266
|
+
console.warn('[reply-monitor] Could not load post-to-x.js, skipping X');
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Search for recent mentions
|
|
271
|
+
let mentions;
|
|
272
|
+
try {
|
|
273
|
+
mentions = await xModule.searchTweets('thumbgate OR ThumbGate OR "pre-action gates"');
|
|
274
|
+
} catch (err) {
|
|
275
|
+
console.warn(`[reply-monitor] X search failed: ${err.message}`);
|
|
276
|
+
return [];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// searchTweets returns the array directly, not {data: [...]}
|
|
280
|
+
const mentionsList = Array.isArray(mentions) ? mentions : mentions?.data;
|
|
281
|
+
if (!mentionsList || mentionsList.length === 0) {
|
|
282
|
+
console.log('[reply-monitor] No X mentions found');
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const results = [];
|
|
287
|
+
const repliesSentThisRun = new Set(); // Track reply text to prevent duplicates
|
|
288
|
+
|
|
289
|
+
// Our own user ID — skip our own tweets
|
|
290
|
+
const OWN_USER_ID = process.env.X_USER_ID || '1733256637199073280';
|
|
291
|
+
|
|
292
|
+
for (const tweet of mentionsList) {
|
|
293
|
+
const tweetId = tweet.id;
|
|
294
|
+
if (state.repliedTo[`x_${tweetId}`]) continue;
|
|
295
|
+
|
|
296
|
+
// Skip our own tweets
|
|
297
|
+
if (tweet.author_id === OWN_USER_ID) {
|
|
298
|
+
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'own_tweet' };
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
console.log(`[reply-monitor] New X mention: "${tweet.text.slice(0, 80)}..."`);
|
|
303
|
+
|
|
304
|
+
const isQuestion = /\?/.test(tweet.text);
|
|
305
|
+
const generatedReply = await generateReply(tweet.text, {
|
|
306
|
+
platform: 'x',
|
|
307
|
+
isQuestion,
|
|
308
|
+
author: tweet.author_id,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
if (!generatedReply) {
|
|
312
|
+
// Mark as seen so we don't re-process, but don't reply
|
|
313
|
+
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'no_reply_generated' };
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Truncate to 280 chars for Twitter
|
|
318
|
+
const truncated = generatedReply.slice(0, 275) + (generatedReply.length > 275 ? '...' : '');
|
|
319
|
+
|
|
320
|
+
// DUPLICATE CHECK: don't post the same text twice in one run
|
|
321
|
+
if (repliesSentThisRun.has(truncated)) {
|
|
322
|
+
console.log(`[reply-monitor] Skipping duplicate reply for tweet ${tweetId}`);
|
|
323
|
+
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'duplicate' };
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
console.log(`[reply-monitor] Generated X reply: "${truncated.slice(0, 100)}..."`);
|
|
328
|
+
|
|
329
|
+
if (dryRun) {
|
|
330
|
+
results.push({ tweetId, reply: truncated, posted: false });
|
|
331
|
+
repliesSentThisRun.add(truncated);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
try {
|
|
336
|
+
await xModule.postTweet(truncated, tweetId);
|
|
337
|
+
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x' };
|
|
338
|
+
results.push({ tweetId, reply: truncated, posted: true });
|
|
339
|
+
repliesSentThisRun.add(truncated);
|
|
340
|
+
console.log(`[reply-monitor] Replied to tweet ${tweetId}`);
|
|
341
|
+
} catch (err) {
|
|
342
|
+
console.warn(`[reply-monitor] Failed to reply to tweet ${tweetId}: ${err.message}`);
|
|
343
|
+
// Still mark as seen to avoid retry spam
|
|
344
|
+
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'post_failed' };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
state.lastCheck.x = new Date().toISOString();
|
|
349
|
+
return results;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
// LinkedIn: check for comments on our posts
|
|
354
|
+
// ---------------------------------------------------------------------------
|
|
355
|
+
|
|
356
|
+
async function checkLinkedInReplies(state, dryRun) {
|
|
357
|
+
console.log('[reply-monitor] Checking LinkedIn comments...');
|
|
358
|
+
|
|
359
|
+
const { LINKEDIN_ACCESS_TOKEN, LINKEDIN_PERSON_URN } = process.env;
|
|
360
|
+
if (!LINKEDIN_ACCESS_TOKEN || !LINKEDIN_PERSON_URN) {
|
|
361
|
+
console.warn('[reply-monitor] LinkedIn credentials not configured, skipping');
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// LinkedIn's comment API is restrictive — log a note for now
|
|
366
|
+
console.log('[reply-monitor] LinkedIn comment monitoring requires Community Management API approval.');
|
|
367
|
+
console.log('[reply-monitor] Once approved, this will auto-fetch and reply to comments on our posts.');
|
|
368
|
+
|
|
369
|
+
state.lastCheck.linkedin = new Date().toISOString();
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// ---------------------------------------------------------------------------
|
|
374
|
+
// Main
|
|
375
|
+
// ---------------------------------------------------------------------------
|
|
376
|
+
|
|
377
|
+
async function monitor({ platforms, dryRun } = {}) {
|
|
378
|
+
const state = loadState();
|
|
379
|
+
const allPlatforms = platforms || ['reddit', 'x', 'linkedin'];
|
|
380
|
+
const allResults = {};
|
|
381
|
+
|
|
382
|
+
for (const platform of allPlatforms) {
|
|
383
|
+
try {
|
|
384
|
+
if (platform === 'reddit') allResults.reddit = await checkRedditReplies(state, dryRun);
|
|
385
|
+
else if (platform === 'x') allResults.x = await checkXReplies(state, dryRun);
|
|
386
|
+
else if (platform === 'linkedin') allResults.linkedin = await checkLinkedInReplies(state, dryRun);
|
|
387
|
+
} catch (err) {
|
|
388
|
+
console.error(`[reply-monitor] ${platform} error: ${err.message}`);
|
|
389
|
+
allResults[platform] = { error: err.message };
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
saveState(state);
|
|
394
|
+
|
|
395
|
+
const totalReplies = Object.values(allResults)
|
|
396
|
+
.flat()
|
|
397
|
+
.filter((r) => r && !r.error && r.posted).length;
|
|
398
|
+
console.log(`\n[reply-monitor] Done. ${totalReplies} replies posted.`);
|
|
399
|
+
|
|
400
|
+
return allResults;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
module.exports = { monitor, generateReply };
|
|
404
|
+
|
|
405
|
+
// ---------------------------------------------------------------------------
|
|
406
|
+
// CLI
|
|
407
|
+
// ---------------------------------------------------------------------------
|
|
408
|
+
if (require.main === module) {
|
|
409
|
+
const args = process.argv.slice(2);
|
|
410
|
+
const dryRun = args.includes('--dry-run');
|
|
411
|
+
|
|
412
|
+
function getArg(flag) {
|
|
413
|
+
const prefix = `${flag}=`;
|
|
414
|
+
const entry = args.find((a) => a.startsWith(prefix));
|
|
415
|
+
return entry ? entry.slice(prefix.length) : null;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const platformArg = getArg('--platform');
|
|
419
|
+
const platforms = platformArg ? [platformArg] : null;
|
|
420
|
+
|
|
421
|
+
// Load .env
|
|
422
|
+
const envPath = path.resolve(__dirname, '..', '.env');
|
|
423
|
+
if (fs.existsSync(envPath)) {
|
|
424
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
425
|
+
for (const line of envContent.split('\n')) {
|
|
426
|
+
const trimmed = line.trim();
|
|
427
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
428
|
+
const eqIdx = trimmed.indexOf('=');
|
|
429
|
+
if (eqIdx > 0) {
|
|
430
|
+
const key = trimmed.slice(0, eqIdx);
|
|
431
|
+
const value = trimmed.slice(eqIdx + 1);
|
|
432
|
+
if (!process.env[key]) process.env[key] = value;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
monitor({ platforms, dryRun })
|
|
438
|
+
.then((results) => {
|
|
439
|
+
console.log('\n[reply-monitor] Summary:', JSON.stringify(results, null, 2));
|
|
440
|
+
})
|
|
441
|
+
.catch((err) => {
|
|
442
|
+
console.error('[reply-monitor] Fatal:', err.message);
|
|
443
|
+
process.exit(1);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Status Dashboard
|
|
4
|
+
*
|
|
5
|
+
* CLI dashboard that reads feedback data and outputs a learning curve summary.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* node scripts/status-dashboard.js
|
|
9
|
+
*
|
|
10
|
+
* Exports:
|
|
11
|
+
* generateStatus(feedbackDir) — returns status object with approval rates,
|
|
12
|
+
* trends, failure domains, memory count, prevention rule count, and learning curve.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { getFeedbackPaths, readJSONL } = require('./feedback-loop');
|
|
18
|
+
|
|
19
|
+
function generateStatus(feedbackDir) {
|
|
20
|
+
const feedbackLogPath = path.join(feedbackDir, 'feedback-log.jsonl');
|
|
21
|
+
const memoryLogPath = path.join(feedbackDir, 'memory-log.jsonl');
|
|
22
|
+
const preventionRulesPath = path.join(feedbackDir, 'prevention-rules.md');
|
|
23
|
+
|
|
24
|
+
const entries = readJSONL(feedbackLogPath);
|
|
25
|
+
const totalSignals = entries.length;
|
|
26
|
+
const positive = entries.filter((e) => e.signal === 'positive').length;
|
|
27
|
+
const negative = entries.filter((e) => e.signal === 'negative').length;
|
|
28
|
+
const approvalRate = totalSignals > 0 ? Math.round((positive / totalSignals) * 100) : 0;
|
|
29
|
+
|
|
30
|
+
// Recent approval rate (last 20)
|
|
31
|
+
const recentWindow = 20;
|
|
32
|
+
const recent = entries.slice(-recentWindow);
|
|
33
|
+
const recentPositive = recent.filter((e) => e.signal === 'positive').length;
|
|
34
|
+
const recentApprovalRate = recent.length > 0 ? Math.round((recentPositive / recent.length) * 100) : 0;
|
|
35
|
+
|
|
36
|
+
// Trend
|
|
37
|
+
let trend = 'stable';
|
|
38
|
+
if (totalSignals >= recentWindow) {
|
|
39
|
+
const diff = recentApprovalRate - approvalRate;
|
|
40
|
+
if (diff > 5) trend = 'improving';
|
|
41
|
+
else if (diff < -5) trend = 'declining';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Top failure domains
|
|
45
|
+
const domainCounts = {};
|
|
46
|
+
entries
|
|
47
|
+
.filter((e) => e.signal === 'negative')
|
|
48
|
+
.forEach((e) => {
|
|
49
|
+
const domain = (e.richContext && e.richContext.domain) || inferDomainFromTags(e.tags);
|
|
50
|
+
domainCounts[domain] = (domainCounts[domain] || 0) + 1;
|
|
51
|
+
});
|
|
52
|
+
const topFailureDomains = Object.entries(domainCounts)
|
|
53
|
+
.map(([domain, count]) => ({ domain, count }))
|
|
54
|
+
.sort((a, b) => b.count - a.count);
|
|
55
|
+
|
|
56
|
+
// Memory count
|
|
57
|
+
const memoryEntries = readJSONL(memoryLogPath);
|
|
58
|
+
const memoryCount = memoryEntries.length;
|
|
59
|
+
|
|
60
|
+
// Prevention rule count
|
|
61
|
+
let preventionRuleCount = 0;
|
|
62
|
+
if (fs.existsSync(preventionRulesPath)) {
|
|
63
|
+
const rulesContent = fs.readFileSync(preventionRulesPath, 'utf-8');
|
|
64
|
+
const ruleHeaders = rulesContent.match(/^## /gm);
|
|
65
|
+
preventionRuleCount = ruleHeaders ? ruleHeaders.length : 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Learning curve — sliding windows of 10
|
|
69
|
+
const learningCurve = [];
|
|
70
|
+
const windowSize = 10;
|
|
71
|
+
for (let i = 0; i + windowSize <= entries.length; i++) {
|
|
72
|
+
const window = entries.slice(i, i + windowSize);
|
|
73
|
+
const windowPositive = window.filter((e) => e.signal === 'positive').length;
|
|
74
|
+
const windowRate = Math.round((windowPositive / windowSize) * 100);
|
|
75
|
+
learningCurve.push({ window: i, approvalRate: windowRate });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
totalSignals,
|
|
80
|
+
positive,
|
|
81
|
+
negative,
|
|
82
|
+
approvalRate,
|
|
83
|
+
recentApprovalRate,
|
|
84
|
+
trend,
|
|
85
|
+
topFailureDomains,
|
|
86
|
+
memoryCount,
|
|
87
|
+
preventionRuleCount,
|
|
88
|
+
learningCurve,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function inferDomainFromTags(tags) {
|
|
93
|
+
if (!Array.isArray(tags) || tags.length === 0) return 'general';
|
|
94
|
+
const tagSet = new Set(tags.map((t) => t.toLowerCase()));
|
|
95
|
+
if (tagSet.has('testing') || tagSet.has('test')) return 'testing';
|
|
96
|
+
if (tagSet.has('security')) return 'security';
|
|
97
|
+
if (tagSet.has('performance') || tagSet.has('perf')) return 'performance';
|
|
98
|
+
if (tagSet.has('ui') || tagSet.has('component')) return 'ui-components';
|
|
99
|
+
if (tagSet.has('api') || tagSet.has('endpoint')) return 'api-integration';
|
|
100
|
+
if (tagSet.has('git') || tagSet.has('commit')) return 'git-workflow';
|
|
101
|
+
if (tagSet.has('doc') || tagSet.has('readme')) return 'documentation';
|
|
102
|
+
if (tagSet.has('debug') || tagSet.has('debugging')) return 'debugging';
|
|
103
|
+
if (tagSet.has('arch') || tagSet.has('architecture')) return 'architecture';
|
|
104
|
+
if (tagSet.has('data') || tagSet.has('schema')) return 'data-modeling';
|
|
105
|
+
return 'general';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function printDashboard(status) {
|
|
109
|
+
console.log('╔══════════════════════════════════════════╗');
|
|
110
|
+
console.log('║ Feedback Tracking Dashboard ║');
|
|
111
|
+
console.log('╠══════════════════════════════════════════╣');
|
|
112
|
+
console.log(`║ Total Signals: ${String(status.totalSignals).padStart(6)} ║`);
|
|
113
|
+
console.log(`║ Positive: ${String(status.positive).padStart(6)} ║`);
|
|
114
|
+
console.log(`║ Negative: ${String(status.negative).padStart(6)} ║`);
|
|
115
|
+
console.log(`║ Approval Rate: ${String(status.approvalRate + '%').padStart(6)} ║`);
|
|
116
|
+
console.log(`║ Recent (last 20): ${String(status.recentApprovalRate + '%').padStart(6)} ║`);
|
|
117
|
+
console.log(`║ Trend: ${status.trend.padStart(6)} ║`);
|
|
118
|
+
console.log(`║ Memories: ${String(status.memoryCount).padStart(6)} ║`);
|
|
119
|
+
console.log(`║ Prevention Rules: ${String(status.preventionRuleCount).padStart(6)} ║`);
|
|
120
|
+
console.log('╠══════════════════════════════════════════╣');
|
|
121
|
+
|
|
122
|
+
if (status.topFailureDomains.length > 0) {
|
|
123
|
+
console.log('║ Top Failure Domains: ║');
|
|
124
|
+
status.topFailureDomains.slice(0, 5).forEach((d) => {
|
|
125
|
+
const line = ` ${d.domain}: ${d.count}`;
|
|
126
|
+
console.log(`║ ${line.padEnd(38)}║`);
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
console.log('║ No failure domains recorded ║');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
console.log('╠══════════════════════════════════════════╣');
|
|
133
|
+
console.log('║ Feedback Trend: ║');
|
|
134
|
+
if (status.learningCurve.length > 0) {
|
|
135
|
+
const step = Math.max(1, Math.floor(status.learningCurve.length / 5));
|
|
136
|
+
for (let i = 0; i < status.learningCurve.length; i += step) {
|
|
137
|
+
const point = status.learningCurve[i];
|
|
138
|
+
const bar = '█'.repeat(Math.floor(point.approvalRate / 5));
|
|
139
|
+
const line = ` w${String(point.window).padStart(3)}: ${bar} ${point.approvalRate}%`;
|
|
140
|
+
console.log(`║ ${line.padEnd(38)}║`);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
console.log('║ Not enough data for feedback trend ║');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('╚══════════════════════════════════════════╝');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (require.main === module) {
|
|
150
|
+
const { FEEDBACK_DIR } = getFeedbackPaths();
|
|
151
|
+
const status = generateStatus(FEEDBACK_DIR);
|
|
152
|
+
printDashboard(status);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = { generateStatus, printDashboard };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Statusline helper for most recent lesson.
|
|
6
|
+
* Called by statusline.sh — outputs JSON for the shell to consume.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { getStatusbarLessonData } = require('./lesson-inference');
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const data = getStatusbarLessonData();
|
|
13
|
+
process.stdout.write(JSON.stringify(data));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
process.stdout.write(JSON.stringify({ hasLesson: false, text: null, lessonId: null, error: e.message }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const { computeToolKpis, getAtRiskTools } = require('./tool-kpi-tracker');
|
|
4
|
+
const { checkSloViolations } = require('./slo-alert-engine');
|
|
5
|
+
const { computeAccessStats, detectAnomalies } = require('./access-anomaly-detector');
|
|
6
|
+
function getStatuslineTowerData({ periodHours = 24 } = {}) { const kpis = computeToolKpis({ periodHours }); const sloCheck = checkSloViolations({ periodHours }); const accessStats = computeAccessStats({ periodHours }); const anomalyCheck = detectAnomalies({ baselineHours: 168, recentHours: periodHours }); return { totalToolCalls: kpis.totalCalls, serverCount: kpis.servers.length, atRiskToolCount: getAtRiskTools({ periodHours }).length, sloViolations: sloCheck.violationCount, worstTool: sloCheck.violations.length > 0 ? sloCheck.violations[0].toolName : null, accessTotal: accessStats.total, accessFailed: accessStats.failed, accessFailRate: accessStats.failRate, anomalyCount: anomalyCheck.anomalies.length, hasAnomalies: anomalyCheck.hasAnomalies }; }
|
|
7
|
+
if (require.main === module) { try { process.stdout.write(JSON.stringify(getStatuslineTowerData())); } catch (e) { process.stdout.write(JSON.stringify({ error: e.message })); } }
|
|
8
|
+
module.exports = { getStatuslineTowerData };
|