thumbgate 1.4.3 → 1.4.5
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/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/llms.txt +12 -8
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +18 -8
- package/adapters/README.md +1 -1
- package/adapters/claude/.mcp.json +2 -2
- package/adapters/codex/config.toml +2 -2
- package/adapters/mcp/server-stdio.js +1 -1
- package/adapters/opencode/opencode.json +1 -1
- package/config/github-about.json +2 -2
- package/package.json +158 -10
- package/scripts/billing.js +5 -2
- package/scripts/statusline.sh +1 -0
- package/src/api/server.js +113 -16
- package/src/index.js +3 -0
- package/.claude-plugin/bundle/icon.png +0 -0
- package/.claude-plugin/bundle/icon.svg +0 -18
- package/.claude-plugin/bundle/server/index.js +0 -24
- package/adapters/chatgpt/INSTALL.md +0 -158
- package/adapters/perplexity/.mcp.json +0 -36
- package/adapters/perplexity/config.toml +0 -16
- package/adapters/perplexity/opencode.json +0 -29
- package/bin/memory.sh +0 -64
- package/bin/obsidian-sync.sh +0 -20
- package/plugins/amp-skill/INSTALL.md +0 -52
- package/plugins/amp-skill/SKILL.md +0 -64
- package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +0 -22
- package/plugins/claude-codex-bridge/.mcp.json +0 -14
- package/plugins/claude-codex-bridge/INSTALL.md +0 -43
- package/plugins/claude-codex-bridge/README.md +0 -46
- package/plugins/claude-codex-bridge/scripts/codex-bridge.js +0 -286
- package/plugins/claude-codex-bridge/skills/adversarial-review/SKILL.md +0 -24
- package/plugins/claude-codex-bridge/skills/result/SKILL.md +0 -22
- package/plugins/claude-codex-bridge/skills/review/SKILL.md +0 -28
- package/plugins/claude-codex-bridge/skills/second-pass/SKILL.md +0 -27
- package/plugins/claude-codex-bridge/skills/setup/SKILL.md +0 -21
- package/plugins/claude-codex-bridge/skills/status/SKILL.md +0 -19
- package/plugins/claude-skill/INSTALL.md +0 -55
- package/plugins/claude-skill/SKILL.md +0 -46
- package/plugins/codex-profile/.codex-plugin/plugin.json +0 -43
- package/plugins/codex-profile/.mcp.json +0 -14
- package/plugins/codex-profile/AGENTS.md +0 -20
- package/plugins/codex-profile/INSTALL.md +0 -89
- package/plugins/codex-profile/README.md +0 -61
- package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +0 -23
- package/plugins/cursor-marketplace/CHANGELOG.md +0 -30
- package/plugins/cursor-marketplace/LICENSE +0 -21
- package/plugins/cursor-marketplace/README.md +0 -124
- package/plugins/cursor-marketplace/agents/reliability-reviewer.md +0 -31
- package/plugins/cursor-marketplace/assets/logo-400x400.png +0 -0
- package/plugins/cursor-marketplace/commands/capture-feedback.md +0 -33
- package/plugins/cursor-marketplace/commands/check-gates.md +0 -25
- package/plugins/cursor-marketplace/commands/show-lessons.md +0 -27
- package/plugins/cursor-marketplace/hooks/hooks.json +0 -10
- package/plugins/cursor-marketplace/mcp.json +0 -14
- package/plugins/cursor-marketplace/rules/feedback-capture.mdc +0 -34
- package/plugins/cursor-marketplace/rules/pre-action-gates.mdc +0 -30
- package/plugins/cursor-marketplace/rules/session-continuity.mdc +0 -28
- package/plugins/cursor-marketplace/scripts/gate-check.sh +0 -21
- package/plugins/cursor-marketplace/skills/capture-feedback/SKILL.md +0 -48
- package/plugins/cursor-marketplace/skills/prevention-rules/SKILL.md +0 -31
- package/plugins/cursor-marketplace/skills/recall-context/SKILL.md +0 -30
- package/plugins/cursor-marketplace/skills/search-lessons/SKILL.md +0 -33
- package/plugins/gemini-extension/INSTALL.md +0 -92
- package/plugins/gemini-extension/gemini_prompt.txt +0 -14
- package/plugins/gemini-extension/tool_contract.json +0 -45
- package/plugins/opencode-profile/INSTALL.md +0 -57
- package/public/assets/instagram-card.png +0 -0
- package/public/assets/tiktok-agent-memory.mp4 +0 -0
- package/public/blog.html +0 -474
- package/public/compare/mem0.html +0 -189
- package/public/compare/speclock.html +0 -180
- package/public/compare.html +0 -310
- package/public/dashboard.html +0 -1100
- package/public/guide.html +0 -317
- package/public/guides/claude-code-prevent-repeated-mistakes.html +0 -161
- package/public/guides/codex-cli-guardrails.html +0 -158
- package/public/guides/cursor-prevent-repeated-mistakes.html +0 -161
- package/public/guides/pre-action-gates.html +0 -162
- package/public/guides/stop-repeated-ai-agent-mistakes.html +0 -159
- package/public/index.html +0 -1225
- package/public/js/buyer-intent.js +0 -252
- package/public/learn/agent-harness-pattern.html +0 -180
- package/public/learn/ai-agent-persistent-memory.html +0 -203
- package/public/learn/learn.css +0 -45
- package/public/learn/mcp-pre-action-gates-explained.html +0 -172
- package/public/learn/stop-ai-agent-force-push.html +0 -134
- package/public/learn/vibe-coding-safety-net.html +0 -142
- package/public/learn.html +0 -274
- package/public/lessons.html +0 -967
- package/public/llm-context.md +0 -156
- package/public/pro.html +0 -1087
- package/public/vercel.json +0 -8
- package/scripts/a2ui-engine.js +0 -73
- package/scripts/adk-consolidator.js +0 -274
- package/scripts/agent-security-hardening.js +0 -225
- package/scripts/ai-search-visibility.js +0 -116
- package/scripts/autonomous-sales-agent.js +0 -39
- package/scripts/autoresearch-runner.js +0 -216
- package/scripts/background-agent-governance.js +0 -229
- package/scripts/behavioral-extraction.js +0 -93
- package/scripts/budget-enforcer.js +0 -173
- package/scripts/budget-guard.js +0 -173
- package/scripts/build-claude-mcpb.js +0 -255
- package/scripts/build-codex-plugin.js +0 -152
- package/scripts/capture-railway-diagnostics.sh +0 -97
- package/scripts/changeset-check.js +0 -372
- package/scripts/check-congruence.js +0 -443
- package/scripts/computer-use-firewall.js +0 -280
- package/scripts/content-engine/linkedin-content-generator.js +0 -154
- package/scripts/content-engine/output/linkedin-memento-validation.md +0 -17
- package/scripts/content-engine/output/linkedin-posts-2026-04-09.md +0 -175
- package/scripts/content-engine/reddit-thread-finder.js +0 -154
- package/scripts/context-engine.js +0 -710
- package/scripts/daily-digest.js +0 -11
- package/scripts/data-governance.js +0 -173
- package/scripts/deploy-gcp.sh +0 -44
- package/scripts/deploy-policy.js +0 -249
- package/scripts/disagreement-mining.js +0 -315
- package/scripts/dpo-optimizer.js +0 -206
- package/scripts/ensure-repo-bootstrap.js +0 -130
- package/scripts/ephemeral-agent-store.js +0 -212
- package/scripts/eval-harness.js +0 -56
- package/scripts/export-kto-pairs.js +0 -309
- package/scripts/export-training.js +0 -446
- package/scripts/feedback-fallback.js +0 -111
- package/scripts/feedback-inbox-read.js +0 -162
- package/scripts/feedback-root-consolidator.js +0 -233
- package/scripts/feedback-to-memory.js +0 -185
- package/scripts/gate-satisfy.js +0 -42
- package/scripts/generate-paperbanana-diagrams.sh +0 -99
- package/scripts/generate-pretool-hook.sh +0 -40
- package/scripts/github-about.js +0 -430
- package/scripts/github-outreach.js +0 -65
- package/scripts/gtm-revenue-loop.js +0 -535
- package/scripts/hallucination-detector.js +0 -226
- package/scripts/hf-papers.js +0 -317
- package/scripts/hook-auto-capture.sh +0 -100
- package/scripts/hook-stop-pr-thread-check.sh +0 -68
- package/scripts/hook-stop-self-score.sh +0 -51
- package/scripts/hook-stop-verify-deploy.sh +0 -31
- package/scripts/hook-verify-before-done.sh +0 -20
- package/scripts/managed-dpo-export.js +0 -91
- package/scripts/markdown-escape.js +0 -12
- package/scripts/marketing-experiment.js +0 -657
- package/scripts/memalign-recall.js +0 -111
- package/scripts/memory-migration.js +0 -296
- package/scripts/meta-policy.js +0 -190
- package/scripts/metered-billing.js +0 -16
- package/scripts/model-tier-router.js +0 -310
- package/scripts/money-watcher.js +0 -218
- package/scripts/multi-hop-recall.js +0 -240
- package/scripts/per-step-scoring.js +0 -163
- package/scripts/perplexity-command-center.js +0 -644
- package/scripts/perplexity-marketing.js +0 -454
- package/scripts/pii-scanner.js +0 -153
- package/scripts/plan-gate.js +0 -154
- package/scripts/post-everywhere.js +0 -341
- package/scripts/post-to-x-retry.sh +0 -22
- package/scripts/post-to-x.js +0 -369
- package/scripts/pr-manager.js +0 -421
- package/scripts/principle-extractor.js +0 -162
- package/scripts/pro-features.js +0 -41
- package/scripts/prompt-dlp.js +0 -222
- package/scripts/prove-adapters.js +0 -860
- package/scripts/prove-attribution.js +0 -361
- package/scripts/prove-automation.js +0 -651
- package/scripts/prove-autoresearch.js +0 -304
- package/scripts/prove-claim-verification.js +0 -277
- package/scripts/prove-cloudflare-sandbox.js +0 -161
- package/scripts/prove-data-pipeline.js +0 -408
- package/scripts/prove-data-quality.js +0 -227
- package/scripts/prove-evolution.js +0 -352
- package/scripts/prove-harnesses.js +0 -287
- package/scripts/prove-intelligence.js +0 -257
- package/scripts/prove-lancedb.js +0 -425
- package/scripts/prove-local-intelligence.js +0 -340
- package/scripts/prove-loop-closure.js +0 -263
- package/scripts/prove-packaged-runtime.js +0 -327
- package/scripts/prove-predictive-insights.js +0 -355
- package/scripts/prove-runtime.js +0 -363
- package/scripts/prove-seo-gsd.js +0 -234
- package/scripts/prove-settings.js +0 -279
- package/scripts/prove-subway-upgrades.js +0 -277
- package/scripts/prove-tessl.js +0 -229
- package/scripts/prove-training-export.js +0 -325
- package/scripts/prove-workflow-contract.js +0 -112
- package/scripts/prove-xmemory.js +0 -332
- package/scripts/publish-decision.js +0 -159
- package/scripts/ralph-loop.js +0 -376
- package/scripts/ralph-mode-ci.js +0 -434
- package/scripts/reddit-dm-outreach.js +0 -192
- package/scripts/reddit-monitor-cron.sh +0 -26
- package/scripts/reminder-engine.js +0 -132
- package/scripts/revenue-status.js +0 -472
- package/scripts/rotate-stripe-webhook-secret.js +0 -314
- package/scripts/schedule-manager.js +0 -249
- package/scripts/self-healing-check.js +0 -193
- package/scripts/session-analyzer.js +0 -533
- package/scripts/shieldcortex-memory-firewall-runner.mjs +0 -53
- package/scripts/skill-exporter.js +0 -260
- package/scripts/skill-materializer.js +0 -134
- package/scripts/skill-packs.js +0 -136
- package/scripts/skill-proposer.js +0 -99
- package/scripts/skill-quality-tracker.js +0 -282
- package/scripts/slow-loop.js +0 -72
- package/scripts/social-analytics/db/marketing-db.js +0 -179
- package/scripts/social-analytics/db/schema.sql +0 -55
- package/scripts/social-analytics/digest.js +0 -256
- package/scripts/social-analytics/engagement-audit.js +0 -185
- package/scripts/social-analytics/generate-instagram-card.js +0 -123
- package/scripts/social-analytics/generate-slides.js +0 -268
- package/scripts/social-analytics/instagram-thumbgate-post.js +0 -111
- package/scripts/social-analytics/install-growth-automation.js +0 -114
- package/scripts/social-analytics/load-env.js +0 -77
- package/scripts/social-analytics/mcp-server.js +0 -289
- package/scripts/social-analytics/normalizer.js +0 -580
- package/scripts/social-analytics/notify.js +0 -162
- package/scripts/social-analytics/poll-all.js +0 -107
- package/scripts/social-analytics/pollers/github.js +0 -195
- package/scripts/social-analytics/pollers/instagram.js +0 -253
- package/scripts/social-analytics/pollers/linkedin.js +0 -340
- package/scripts/social-analytics/pollers/plausible.js +0 -245
- package/scripts/social-analytics/pollers/reddit.js +0 -306
- package/scripts/social-analytics/pollers/threads.js +0 -233
- package/scripts/social-analytics/pollers/tiktok.js +0 -203
- package/scripts/social-analytics/pollers/x.js +0 -227
- package/scripts/social-analytics/pollers/youtube.js +0 -304
- package/scripts/social-analytics/pollers/zernio.js +0 -183
- package/scripts/social-analytics/post-video.js +0 -316
- package/scripts/social-analytics/publish-instagram-thumbgate.js +0 -104
- package/scripts/social-analytics/publish-thumbgate-launch.js +0 -322
- package/scripts/social-analytics/publishers/devto.js +0 -122
- package/scripts/social-analytics/publishers/instagram.js +0 -317
- package/scripts/social-analytics/publishers/linkedin.js +0 -294
- package/scripts/social-analytics/publishers/reddit.js +0 -385
- package/scripts/social-analytics/publishers/threads.js +0 -275
- package/scripts/social-analytics/publishers/tiktok.js +0 -217
- package/scripts/social-analytics/publishers/x.js +0 -259
- package/scripts/social-analytics/publishers/youtube.js +0 -223
- package/scripts/social-analytics/publishers/zernio.js +0 -568
- package/scripts/social-analytics/reconcile-thumbgate-campaign.js +0 -165
- package/scripts/social-analytics/run-digest.js +0 -34
- package/scripts/social-analytics/schedule-thumbgate-campaign.js +0 -275
- package/scripts/social-analytics/store.js +0 -455
- package/scripts/social-analytics/sync-launch-assets.js +0 -185
- package/scripts/social-analytics/utm.js +0 -143
- package/scripts/social-pipeline.js +0 -2626
- package/scripts/social-post-hourly.js +0 -228
- package/scripts/social-quality-gate.js +0 -134
- package/scripts/social-reply-monitor.js +0 -592
- package/scripts/status-dashboard.js +0 -155
- package/scripts/stripe-live-status.js +0 -115
- package/scripts/subagent-profiles.js +0 -79
- package/scripts/sync-branch-protection.js +0 -340
- package/scripts/sync-gh-secrets-from-env.sh +0 -70
- package/scripts/sync-github-about.js +0 -55
- package/scripts/sync-version.js +0 -479
- package/scripts/synthetic-dpo.js +0 -234
- package/scripts/tessl-export.js +0 -369
- package/scripts/test-coverage.js +0 -128
- package/scripts/thumbgate-bench.js +0 -494
- package/scripts/thumbgate_session_start.sh +0 -32
- package/scripts/train_from_feedback.py +0 -929
- package/scripts/validate-feedback.js +0 -581
- package/scripts/verify-obsidian-setup.sh +0 -269
- package/scripts/verify-run.js +0 -269
- package/scripts/weekly-auto-post.js +0 -124
- package/scripts/x-autonomous-marketing.js +0 -139
|
@@ -1,592 +0,0 @@
|
|
|
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
|
-
const fs = require('fs');
|
|
20
|
-
const path = require('path');
|
|
21
|
-
const { loadLocalEnv } = require('./social-analytics/load-env');
|
|
22
|
-
const { gateContextualReply, commentExplicitlyRequestsProduct } = require('./social-quality-gate');
|
|
23
|
-
|
|
24
|
-
const STATE_FILE = path.resolve(__dirname, '..', '.thumbgate', 'reply-monitor-state.json');
|
|
25
|
-
const REDDIT_API_BASE = 'https://oauth.reddit.com';
|
|
26
|
-
const DEFAULT_X_HANDLE = 'IgorGanapolsky';
|
|
27
|
-
|
|
28
|
-
loadLocalEnv();
|
|
29
|
-
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
// State management
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
function loadState() {
|
|
35
|
-
try {
|
|
36
|
-
if (fs.existsSync(STATE_FILE)) {
|
|
37
|
-
return JSON.parse(fs.readFileSync(STATE_FILE, 'utf8'));
|
|
38
|
-
}
|
|
39
|
-
} catch { /* ignore */ }
|
|
40
|
-
return { repliedTo: {}, lastCheck: {} };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function saveState(state) {
|
|
44
|
-
const dir = path.dirname(STATE_FILE);
|
|
45
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
46
|
-
fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Reply generation (uses Gemini API for cost-effective generation)
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
// ---------------------------------------------------------------------------
|
|
54
|
-
// Draft file for human review (Reddit replies are NEVER auto-posted)
|
|
55
|
-
// ---------------------------------------------------------------------------
|
|
56
|
-
|
|
57
|
-
const DRAFT_FILE = path.resolve(__dirname, '..', '.thumbgate', 'reply-drafts.jsonl');
|
|
58
|
-
|
|
59
|
-
function saveDraft(draft) {
|
|
60
|
-
const dir = path.dirname(DRAFT_FILE);
|
|
61
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
62
|
-
fs.appendFileSync(DRAFT_FILE, JSON.stringify(draft) + '\n');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function normalizeArray(value) {
|
|
66
|
-
if (value && Array.isArray(value.data)) {
|
|
67
|
-
return value.data;
|
|
68
|
-
}
|
|
69
|
-
return Array.isArray(value) ? value : [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function isRevenueRelevantXTweet(tweet = {}) {
|
|
73
|
-
const text = String(tweet.text || '').toLowerCase();
|
|
74
|
-
if (!text) return false;
|
|
75
|
-
return /thumbgate|thumbgate-production|checkout\/pro|workflow-sprint|pre-action gates|vibe coding/.test(text);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function buildOwnedConversationQuery(tweetId, username = DEFAULT_X_HANDLE) {
|
|
79
|
-
const normalizedId = String(tweetId || '').trim();
|
|
80
|
-
const normalizedUsername = String(username || DEFAULT_X_HANDLE).trim();
|
|
81
|
-
if (!normalizedId) {
|
|
82
|
-
return '';
|
|
83
|
-
}
|
|
84
|
-
return `conversation_id:${normalizedId} -from:${normalizedUsername}`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function collectXSearchCandidates(options = {}) {
|
|
88
|
-
const searchTweets = options.searchTweets;
|
|
89
|
-
if (typeof searchTweets !== 'function') {
|
|
90
|
-
return { tweets: [], searchMode: 'unavailable', queryLog: [] };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const username = options.username || process.env.X_USERNAME || DEFAULT_X_HANDLE;
|
|
94
|
-
const ownUserId = options.ownUserId || process.env.X_USER_ID || '1733256637199073280';
|
|
95
|
-
const queryLog = [];
|
|
96
|
-
const aggregate = [];
|
|
97
|
-
const seenTweetIds = new Set();
|
|
98
|
-
let ownedCandidates = [];
|
|
99
|
-
|
|
100
|
-
if (typeof options.fetchOwnedTweets === 'function') {
|
|
101
|
-
try {
|
|
102
|
-
const recentTweets = await options.fetchOwnedTweets();
|
|
103
|
-
ownedCandidates = normalizeArray(recentTweets)
|
|
104
|
-
.filter((tweet) => String(tweet.author_id || ownUserId) === ownUserId)
|
|
105
|
-
.filter(isRevenueRelevantXTweet)
|
|
106
|
-
.slice(0, 6);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
console.warn(`[reply-monitor] Could not fetch own X tweets: ${err.message}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
for (const tweet of ownedCandidates) {
|
|
113
|
-
const query = buildOwnedConversationQuery(tweet.id, username);
|
|
114
|
-
if (!query) continue;
|
|
115
|
-
queryLog.push(query);
|
|
116
|
-
const replies = normalizeArray(await searchTweets(query, { maxResults: 10 }));
|
|
117
|
-
for (const reply of replies) {
|
|
118
|
-
if (!reply || seenTweetIds.has(reply.id)) continue;
|
|
119
|
-
seenTweetIds.add(reply.id);
|
|
120
|
-
aggregate.push(reply);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (aggregate.length > 0) {
|
|
125
|
-
return {
|
|
126
|
-
tweets: aggregate,
|
|
127
|
-
ownTweets: ownedCandidates.map((tweet) => ({ id: tweet.id, text: tweet.text || '' })),
|
|
128
|
-
queryLog,
|
|
129
|
-
searchMode: 'owned_conversations',
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const fallbackQuery = 'thumbgate OR ThumbGate OR "pre-action gates"';
|
|
134
|
-
queryLog.push(fallbackQuery);
|
|
135
|
-
const fallbackTweets = normalizeArray(await searchTweets(fallbackQuery, { maxResults: 10 }));
|
|
136
|
-
return {
|
|
137
|
-
tweets: fallbackTweets,
|
|
138
|
-
ownTweets: ownedCandidates.map((tweet) => ({ id: tweet.id, text: tweet.text || '' })),
|
|
139
|
-
queryLog,
|
|
140
|
-
searchMode: 'keyword_fallback',
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// ---------------------------------------------------------------------------
|
|
145
|
-
// Bot/hostile detection — skip comments that are calling us out
|
|
146
|
-
// ---------------------------------------------------------------------------
|
|
147
|
-
|
|
148
|
-
function isHostileOrMeta(comment) {
|
|
149
|
-
const lc = (comment || '').toLowerCase();
|
|
150
|
-
const hostile = [
|
|
151
|
-
'bot', 'spam', 'shill', 'promotional', 'reported',
|
|
152
|
-
'same answer', 'word for word', 'copy paste', 'running amok',
|
|
153
|
-
'smell these', 'not what i asked', 'didn\'t ask',
|
|
154
|
-
'auto-generated', 'ai generated', 'chatgpt', 'template',
|
|
155
|
-
];
|
|
156
|
-
return hostile.some(phrase => lc.includes(phrase));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// ---------------------------------------------------------------------------
|
|
160
|
-
// Reply generation — context-aware, NOT canned templates
|
|
161
|
-
// ---------------------------------------------------------------------------
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Generate a contextual reply by actually reading the comment.
|
|
165
|
-
* Returns null if we should NOT reply (hostile, off-topic, or duplicate risk).
|
|
166
|
-
*/
|
|
167
|
-
async function generateReply(comment, context) {
|
|
168
|
-
const lc = (comment || '').toLowerCase();
|
|
169
|
-
|
|
170
|
-
// NEVER reply to hostile/meta comments calling out bots
|
|
171
|
-
if (isHostileOrMeta(comment)) {
|
|
172
|
-
console.log('[reply-monitor] Skipping hostile/meta comment — do not engage');
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// NEVER reply to our own comments
|
|
177
|
-
if (context.author === 'eazyigz123' || context.author === 'IgorGanapolsky') {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// NEVER reply with generic fluff — build reply from what they ACTUALLY said
|
|
182
|
-
const isQuestion = context.isQuestion || /\?/.test(comment);
|
|
183
|
-
const isReddit = context.platform === 'reddit';
|
|
184
|
-
const wantsProductDetails = commentExplicitlyRequestsProduct(comment);
|
|
185
|
-
|
|
186
|
-
// Extract the specific topic they're asking about
|
|
187
|
-
const mentionsSetup = /install|setup|config|init|npx|how.+start/i.test(lc);
|
|
188
|
-
const mentionsHow = /how does|how do|explain|what is|can you describe/i.test(lc);
|
|
189
|
-
const mentionsGates = /gate|block|prevent|hook|intercept|firewall/i.test(lc);
|
|
190
|
-
const mentionsMemory = /memory|context|session|forget|amnesia|remember/i.test(lc);
|
|
191
|
-
const mentionsCursor = /cursor|windsurf|copilot|cline/i.test(lc);
|
|
192
|
-
const mentionsScaling = /scale|team|multi.?repo|collaborate|share/i.test(lc);
|
|
193
|
-
const mentionsSkeptical = /why not|already exist|what.+different|vs |compared to/i.test(lc);
|
|
194
|
-
const mentionsThanks = /thanks|thank you|cool|nice|interesting|awesome/i.test(lc);
|
|
195
|
-
const mentionsSkillsProcess = /skill|template|process|workflow|review|sprint|implement|phase/i.test(lc);
|
|
196
|
-
const mentionsConflictingDocs = /context doc|context docs|conflicting|inconsisten|claude\.md|cursorrules|instruction/i.test(lc);
|
|
197
|
-
|
|
198
|
-
// Build response that addresses THEIR specific point
|
|
199
|
-
if (mentionsSkillsProcess || mentionsConflictingDocs) {
|
|
200
|
-
const reply = [
|
|
201
|
-
'That matches what I have seen too.',
|
|
202
|
-
'Smaller review/implement phases hold up much better than one giant instruction blob,',
|
|
203
|
-
'and conflicting context docs are where things usually start drifting.'
|
|
204
|
-
].join(' ');
|
|
205
|
-
const gate = gateContextualReply(comment, reply, context);
|
|
206
|
-
return gate.allowed ? reply : null;
|
|
207
|
-
}
|
|
208
|
-
if (mentionsSetup && isQuestion && !isReddit) {
|
|
209
|
-
return `\`npx thumbgate init\` auto-detects your agent and wires the hooks. Takes about 30 seconds. What agent are you using?`;
|
|
210
|
-
}
|
|
211
|
-
if (mentionsSkeptical) {
|
|
212
|
-
// Build a reply that mirrors the commenter's frame (memory, context docs, or general rules)
|
|
213
|
-
// so gateContextualReply's topic-overlap check passes.
|
|
214
|
-
let replyBase;
|
|
215
|
-
if (mentionsMemory) {
|
|
216
|
-
replyBase = 'The distinction from memory tools is enforcement: memory helps the agent remember a past mistake, but it can still repeat it. The gate stops the already-rejected move before it runs. Whether that extra step is worth the setup depends on how often your agent ignores its own memory.';
|
|
217
|
-
} else {
|
|
218
|
-
replyBase = 'The difference from cursorrules or instruction files is enforcement: the bad action gets stopped before execution instead of being added to context docs and then ignored anyway. Whether that tradeoff is worth it depends on how often your agent repeats the same mistake.';
|
|
219
|
-
}
|
|
220
|
-
const gate = gateContextualReply(comment, replyBase, context);
|
|
221
|
-
return gate.allowed ? replyBase : null;
|
|
222
|
-
}
|
|
223
|
-
if (mentionsGates && (mentionsHow || (!isReddit && !mentionsThanks))) {
|
|
224
|
-
// On X, engage on gate-topic statements too (not just "how does" questions).
|
|
225
|
-
// On Reddit, keep the old conservative behavior (questions only via mentionsHow).
|
|
226
|
-
if (isReddit && !mentionsHow) return null;
|
|
227
|
-
const reply = isReddit
|
|
228
|
-
? 'The short version is: the tool call gets checked before it runs. If it matches a previously rejected pattern, it is blocked and the agent has to try a different path.'
|
|
229
|
-
: '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 and the agent has to try a different approach. The rules adapt over time so false positives decrease.';
|
|
230
|
-
const gate = gateContextualReply(comment, reply, context);
|
|
231
|
-
return gate.allowed ? reply : null;
|
|
232
|
-
}
|
|
233
|
-
if (mentionsScaling) {
|
|
234
|
-
if (isReddit && !wantsProductDetails) {
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
const reply = 'For teams, the useful part is shared lessons instead of each developer relearning the same failure pattern alone. Solo workflows usually benefit first from the local version.';
|
|
238
|
-
const gate = gateContextualReply(comment, reply, context);
|
|
239
|
-
return gate.allowed ? reply : null;
|
|
240
|
-
}
|
|
241
|
-
if (mentionsMemory) {
|
|
242
|
-
// Engage on memory/context topics whether it's a question or a statement — both are worth a reply on X
|
|
243
|
-
if (isReddit && !isQuestion) return null; // Reddit: only reply to direct questions
|
|
244
|
-
const reply = 'The useful distinction is memory versus enforcement. Memory helps the agent remember, but it can still ignore that memory. Enforcement is what stops the already-rejected move from happening again.';
|
|
245
|
-
const gate = gateContextualReply(comment, reply, context);
|
|
246
|
-
return gate.allowed ? reply : null;
|
|
247
|
-
}
|
|
248
|
-
if (mentionsCursor && isQuestion && !isReddit) {
|
|
249
|
-
return 'Works with Cursor via MCP. The same prevention rules can apply across Cursor, Claude Code, and Codex. What specific failure patterns are you hitting?';
|
|
250
|
-
}
|
|
251
|
-
if (mentionsThanks && !isQuestion) {
|
|
252
|
-
// Don't reply to simple "thanks" — it looks desperate
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
if (isReddit && wantsProductDetails) {
|
|
256
|
-
const reply = 'Happy to share the repo or setup details if that would help. The main thing that worked for me was keeping accepted and rejected patterns outside the session so the next run starts with the same constraints.';
|
|
257
|
-
const gate = gateContextualReply(comment, reply, context);
|
|
258
|
-
return gate.allowed ? reply : null;
|
|
259
|
-
}
|
|
260
|
-
if (isQuestion) {
|
|
261
|
-
// They asked something specific we didn't match — signal to caller to save a draft for human review
|
|
262
|
-
return '__DRAFT__';
|
|
263
|
-
}
|
|
264
|
-
// Not a question, not hostile, not thanks — probably a statement. Don't reply.
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// ---------------------------------------------------------------------------
|
|
269
|
-
// Reddit: fetch replies and respond
|
|
270
|
-
// ---------------------------------------------------------------------------
|
|
271
|
-
|
|
272
|
-
async function getRedditToken() {
|
|
273
|
-
const { REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, REDDIT_PASSWORD } = process.env;
|
|
274
|
-
if (!REDDIT_CLIENT_ID || !REDDIT_CLIENT_SECRET || !REDDIT_USERNAME || !REDDIT_PASSWORD) {
|
|
275
|
-
throw new Error('Missing Reddit credentials (REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, REDDIT_PASSWORD)');
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const credentials = Buffer.from(`${REDDIT_CLIENT_ID}:${REDDIT_CLIENT_SECRET}`).toString('base64');
|
|
279
|
-
const res = await fetch('https://www.reddit.com/api/v1/access_token', {
|
|
280
|
-
method: 'POST',
|
|
281
|
-
headers: {
|
|
282
|
-
Authorization: `Basic ${credentials}`,
|
|
283
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
284
|
-
'User-Agent': `thumbgate/1.0 by ${REDDIT_USERNAME}`,
|
|
285
|
-
},
|
|
286
|
-
body: new URLSearchParams({ grant_type: 'password', username: REDDIT_USERNAME, password: REDDIT_PASSWORD }).toString(),
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
const json = await res.json();
|
|
290
|
-
if (json.error) throw new Error(`Reddit auth: ${json.error}`);
|
|
291
|
-
return json.access_token;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
async function checkRedditReplies(state, dryRun) {
|
|
295
|
-
console.log('[reply-monitor] Checking Reddit inbox...');
|
|
296
|
-
|
|
297
|
-
let token;
|
|
298
|
-
try {
|
|
299
|
-
token = await getRedditToken();
|
|
300
|
-
} catch (err) {
|
|
301
|
-
console.warn(`[reply-monitor] Reddit auth failed: ${err.message}`);
|
|
302
|
-
return [];
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const userAgent = `thumbgate/1.0 by ${process.env.REDDIT_USERNAME}`;
|
|
306
|
-
|
|
307
|
-
// Fetch inbox (comment replies)
|
|
308
|
-
const res = await fetch(`${REDDIT_API_BASE}/message/inbox?limit=25`, {
|
|
309
|
-
headers: {
|
|
310
|
-
Authorization: `Bearer ${token}`,
|
|
311
|
-
'User-Agent': userAgent,
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
if (!res.ok) {
|
|
316
|
-
console.warn(`[reply-monitor] Reddit inbox fetch failed: ${res.status}`);
|
|
317
|
-
return [];
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const data = await res.json();
|
|
321
|
-
const replies = (data.data?.children || []).filter(
|
|
322
|
-
(c) => c.kind === 't1' && c.data.type === 'comment_reply'
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
const results = [];
|
|
326
|
-
for (const reply of replies) {
|
|
327
|
-
const commentId = reply.data.name;
|
|
328
|
-
if (state.repliedTo[commentId]) continue; // Already replied
|
|
329
|
-
|
|
330
|
-
const commentBody = reply.data.body || '';
|
|
331
|
-
const postTitle = reply.data.link_title || '';
|
|
332
|
-
|
|
333
|
-
console.log(`[reply-monitor] New Reddit reply from u/${reply.data.author}: "${commentBody.slice(0, 80)}..."`);
|
|
334
|
-
|
|
335
|
-
const isQuestion = /\?/.test(commentBody);
|
|
336
|
-
const generatedReply = await generateReply(commentBody, {
|
|
337
|
-
platform: 'reddit',
|
|
338
|
-
postTitle,
|
|
339
|
-
isQuestion,
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
if (!generatedReply || generatedReply === '__DRAFT__') {
|
|
343
|
-
console.warn(`[reply-monitor] Could not generate reply for ${commentId}`);
|
|
344
|
-
continue;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
console.log(`[reply-monitor] Generated reply: "${generatedReply.slice(0, 100)}..."`);
|
|
348
|
-
|
|
349
|
-
// Reddit is ALWAYS draft-only — never auto-post.
|
|
350
|
-
// Bot detection on Reddit is aggressive; human must review and post manually.
|
|
351
|
-
const draft = {
|
|
352
|
-
platform: 'reddit',
|
|
353
|
-
commentId,
|
|
354
|
-
author: reply.data.author,
|
|
355
|
-
subreddit: reply.data.subreddit,
|
|
356
|
-
theirComment: commentBody.slice(0, 500),
|
|
357
|
-
suggestedReply: generatedReply,
|
|
358
|
-
postTitle,
|
|
359
|
-
draftedAt: new Date().toISOString(),
|
|
360
|
-
status: 'pending_review',
|
|
361
|
-
};
|
|
362
|
-
saveDraft(draft);
|
|
363
|
-
state.repliedTo[commentId] = { at: new Date().toISOString(), platform: 'reddit', drafted: true };
|
|
364
|
-
results.push({ commentId, reply: generatedReply, posted: false, drafted: true });
|
|
365
|
-
console.log(`[reply-monitor] 📝 DRAFTED reply for ${commentId} (saved to .thumbgate/reply-drafts.jsonl — post manually)`);
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
state.lastCheck.reddit = new Date().toISOString();
|
|
370
|
-
return results;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// ---------------------------------------------------------------------------
|
|
374
|
-
// X/Twitter: fetch mentions and respond
|
|
375
|
-
// ---------------------------------------------------------------------------
|
|
376
|
-
|
|
377
|
-
async function checkXReplies(state, dryRun) {
|
|
378
|
-
console.log('[reply-monitor] Checking X/Twitter mentions...');
|
|
379
|
-
|
|
380
|
-
const { X_API_KEY, X_API_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET } = process.env;
|
|
381
|
-
if (!X_API_KEY || !X_ACCESS_TOKEN) {
|
|
382
|
-
console.warn('[reply-monitor] X credentials not configured, skipping');
|
|
383
|
-
return [];
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// Use the post-to-x module for OAuth signing
|
|
387
|
-
let xModule;
|
|
388
|
-
let xPoller;
|
|
389
|
-
try {
|
|
390
|
-
xModule = require('./post-to-x.js');
|
|
391
|
-
xPoller = require('./social-analytics/pollers/x.js');
|
|
392
|
-
} catch {
|
|
393
|
-
console.warn('[reply-monitor] Could not load X modules, skipping X');
|
|
394
|
-
return [];
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
let searchResult;
|
|
398
|
-
try {
|
|
399
|
-
searchResult = await collectXSearchCandidates({
|
|
400
|
-
searchTweets: xModule.searchTweets,
|
|
401
|
-
fetchOwnedTweets: process.env.X_BEARER_TOKEN && process.env.X_USER_ID
|
|
402
|
-
? async () => {
|
|
403
|
-
const response = await xPoller.fetchUserTweets(process.env.X_BEARER_TOKEN, process.env.X_USER_ID);
|
|
404
|
-
return response && response.data;
|
|
405
|
-
}
|
|
406
|
-
: null,
|
|
407
|
-
ownUserId: process.env.X_USER_ID || '1733256637199073280',
|
|
408
|
-
username: process.env.X_USERNAME || DEFAULT_X_HANDLE,
|
|
409
|
-
});
|
|
410
|
-
} catch (err) {
|
|
411
|
-
console.warn(`[reply-monitor] X search failed: ${err.message}`);
|
|
412
|
-
return [];
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const mentionsList = normalizeArray(searchResult && searchResult.tweets);
|
|
416
|
-
if (!mentionsList || mentionsList.length === 0) {
|
|
417
|
-
console.log('[reply-monitor] No X mentions found');
|
|
418
|
-
return [];
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
console.log(`[reply-monitor] X candidate search mode: ${searchResult.searchMode}`);
|
|
422
|
-
|
|
423
|
-
const results = [];
|
|
424
|
-
const repliesSentThisRun = new Set(); // Track reply text to prevent duplicates
|
|
425
|
-
|
|
426
|
-
// Our own user ID — skip our own tweets
|
|
427
|
-
const OWN_USER_ID = process.env.X_USER_ID || '1733256637199073280';
|
|
428
|
-
|
|
429
|
-
for (const tweet of mentionsList) {
|
|
430
|
-
const tweetId = tweet.id;
|
|
431
|
-
if (state.repliedTo[`x_${tweetId}`]) continue;
|
|
432
|
-
|
|
433
|
-
// Skip our own tweets
|
|
434
|
-
if (tweet.author_id === OWN_USER_ID) {
|
|
435
|
-
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'own_tweet' };
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
console.log(`[reply-monitor] New X mention: "${tweet.text.slice(0, 80)}..."`);
|
|
440
|
-
|
|
441
|
-
const isQuestion = /\?/.test(tweet.text);
|
|
442
|
-
const generatedReply = await generateReply(tweet.text, {
|
|
443
|
-
platform: 'x',
|
|
444
|
-
isQuestion,
|
|
445
|
-
author: tweet.author_id,
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
if (!generatedReply) {
|
|
449
|
-
// Mark as seen so we don't re-process, but don't reply
|
|
450
|
-
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'no_reply_generated' };
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// Unmatched question — save a draft for human review rather than silently skipping
|
|
455
|
-
if (generatedReply === '__DRAFT__') {
|
|
456
|
-
const draft = {
|
|
457
|
-
platform: 'x',
|
|
458
|
-
tweetId,
|
|
459
|
-
author: tweet.author_id,
|
|
460
|
-
theirTweet: tweet.text.slice(0, 500),
|
|
461
|
-
suggestedReply: null,
|
|
462
|
-
draftedAt: new Date().toISOString(),
|
|
463
|
-
status: 'needs_human_reply',
|
|
464
|
-
reason: 'unmatched_question',
|
|
465
|
-
};
|
|
466
|
-
saveDraft(draft);
|
|
467
|
-
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', drafted: true, skipped: 'needs_human_reply' };
|
|
468
|
-
results.push({ tweetId, reply: null, posted: false, drafted: true });
|
|
469
|
-
console.log(`[reply-monitor] 📝 DRAFTED (needs human reply) for tweet ${tweetId} — saved to .thumbgate/reply-drafts.jsonl`);
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Truncate to 280 chars for Twitter
|
|
474
|
-
const truncated = generatedReply.slice(0, 275) + (generatedReply.length > 275 ? '...' : '');
|
|
475
|
-
|
|
476
|
-
// DUPLICATE CHECK: don't post the same text twice in one run
|
|
477
|
-
if (repliesSentThisRun.has(truncated)) {
|
|
478
|
-
console.log(`[reply-monitor] Skipping duplicate reply for tweet ${tweetId}`);
|
|
479
|
-
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'duplicate' };
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
console.log(`[reply-monitor] Generated X reply: "${truncated.slice(0, 100)}..."`);
|
|
484
|
-
|
|
485
|
-
if (dryRun) {
|
|
486
|
-
results.push({ tweetId, reply: truncated, posted: false });
|
|
487
|
-
repliesSentThisRun.add(truncated);
|
|
488
|
-
continue;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
try {
|
|
492
|
-
await xModule.postTweet(truncated, tweetId);
|
|
493
|
-
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x' };
|
|
494
|
-
results.push({ tweetId, reply: truncated, posted: true });
|
|
495
|
-
repliesSentThisRun.add(truncated);
|
|
496
|
-
console.log(`[reply-monitor] Replied to tweet ${tweetId}`);
|
|
497
|
-
} catch (err) {
|
|
498
|
-
console.warn(`[reply-monitor] Failed to reply to tweet ${tweetId}: ${err.message}`);
|
|
499
|
-
// Still mark as seen to avoid retry spam
|
|
500
|
-
state.repliedTo[`x_${tweetId}`] = { at: new Date().toISOString(), platform: 'x', skipped: 'post_failed' };
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
state.lastCheck.x = new Date().toISOString();
|
|
505
|
-
return results;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// ---------------------------------------------------------------------------
|
|
509
|
-
// LinkedIn: check for comments on our posts
|
|
510
|
-
// ---------------------------------------------------------------------------
|
|
511
|
-
|
|
512
|
-
async function checkLinkedInReplies(state, dryRun) {
|
|
513
|
-
console.log('[reply-monitor] Checking LinkedIn comments...');
|
|
514
|
-
|
|
515
|
-
const { LINKEDIN_ACCESS_TOKEN, LINKEDIN_PERSON_URN } = process.env;
|
|
516
|
-
if (!LINKEDIN_ACCESS_TOKEN || !LINKEDIN_PERSON_URN) {
|
|
517
|
-
console.warn('[reply-monitor] LinkedIn credentials not configured, skipping');
|
|
518
|
-
return [];
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// LinkedIn's comment API is restrictive — log a note for now
|
|
522
|
-
console.log('[reply-monitor] LinkedIn comment monitoring requires Community Management API approval.');
|
|
523
|
-
console.log('[reply-monitor] Once approved, this will auto-fetch and reply to comments on our posts.');
|
|
524
|
-
|
|
525
|
-
state.lastCheck.linkedin = new Date().toISOString();
|
|
526
|
-
return [];
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// ---------------------------------------------------------------------------
|
|
530
|
-
// Main
|
|
531
|
-
// ---------------------------------------------------------------------------
|
|
532
|
-
|
|
533
|
-
async function monitor({ platforms, dryRun } = {}) {
|
|
534
|
-
const state = loadState();
|
|
535
|
-
const allPlatforms = platforms || ['reddit', 'x', 'linkedin'];
|
|
536
|
-
const allResults = {};
|
|
537
|
-
|
|
538
|
-
for (const platform of allPlatforms) {
|
|
539
|
-
try {
|
|
540
|
-
if (platform === 'reddit') allResults.reddit = await checkRedditReplies(state, dryRun);
|
|
541
|
-
else if (platform === 'x') allResults.x = await checkXReplies(state, dryRun);
|
|
542
|
-
else if (platform === 'linkedin') allResults.linkedin = await checkLinkedInReplies(state, dryRun);
|
|
543
|
-
} catch (err) {
|
|
544
|
-
console.error(`[reply-monitor] ${platform} error: ${err.message}`);
|
|
545
|
-
allResults[platform] = { error: err.message };
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
saveState(state);
|
|
550
|
-
|
|
551
|
-
const totalReplies = Object.values(allResults)
|
|
552
|
-
.flat()
|
|
553
|
-
.filter((r) => r && !r.error && r.posted).length;
|
|
554
|
-
console.log(`\n[reply-monitor] Done. ${totalReplies} replies posted.`);
|
|
555
|
-
|
|
556
|
-
return allResults;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
module.exports = {
|
|
560
|
-
buildOwnedConversationQuery,
|
|
561
|
-
checkXReplies,
|
|
562
|
-
collectXSearchCandidates,
|
|
563
|
-
generateReply,
|
|
564
|
-
isRevenueRelevantXTweet,
|
|
565
|
-
monitor,
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
// ---------------------------------------------------------------------------
|
|
569
|
-
// CLI
|
|
570
|
-
// ---------------------------------------------------------------------------
|
|
571
|
-
if (require.main === module) {
|
|
572
|
-
const args = process.argv.slice(2);
|
|
573
|
-
const dryRun = args.includes('--dry-run');
|
|
574
|
-
|
|
575
|
-
function getArg(flag) {
|
|
576
|
-
const prefix = `${flag}=`;
|
|
577
|
-
const entry = args.find((a) => a.startsWith(prefix));
|
|
578
|
-
return entry ? entry.slice(prefix.length) : null;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
const platformArg = getArg('--platform');
|
|
582
|
-
const platforms = platformArg ? [platformArg] : null;
|
|
583
|
-
|
|
584
|
-
monitor({ platforms, dryRun })
|
|
585
|
-
.then((results) => {
|
|
586
|
-
console.log('\n[reply-monitor] Summary:', JSON.stringify(results, null, 2));
|
|
587
|
-
})
|
|
588
|
-
.catch((err) => {
|
|
589
|
-
console.error('[reply-monitor] Fatal:', err.message);
|
|
590
|
-
process.exit(1);
|
|
591
|
-
});
|
|
592
|
-
}
|