thumbgate 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.well-known/mcp/server-card.json +1 -1
  4. package/adapters/README.md +1 -1
  5. package/adapters/claude/.mcp.json +2 -2
  6. package/adapters/codex/config.toml +2 -2
  7. package/adapters/mcp/server-stdio.js +1 -1
  8. package/adapters/opencode/opencode.json +1 -1
  9. package/package.json +157 -9
  10. package/scripts/statusline.sh +1 -0
  11. package/src/api/server.js +113 -16
  12. package/src/index.js +3 -0
  13. package/.claude-plugin/bundle/icon.png +0 -0
  14. package/.claude-plugin/bundle/icon.svg +0 -18
  15. package/.claude-plugin/bundle/server/index.js +0 -24
  16. package/adapters/chatgpt/INSTALL.md +0 -158
  17. package/adapters/perplexity/.mcp.json +0 -36
  18. package/adapters/perplexity/config.toml +0 -16
  19. package/adapters/perplexity/opencode.json +0 -29
  20. package/bin/memory.sh +0 -64
  21. package/bin/obsidian-sync.sh +0 -20
  22. package/plugins/amp-skill/INSTALL.md +0 -52
  23. package/plugins/amp-skill/SKILL.md +0 -64
  24. package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +0 -22
  25. package/plugins/claude-codex-bridge/.mcp.json +0 -14
  26. package/plugins/claude-codex-bridge/INSTALL.md +0 -43
  27. package/plugins/claude-codex-bridge/README.md +0 -46
  28. package/plugins/claude-codex-bridge/scripts/codex-bridge.js +0 -286
  29. package/plugins/claude-codex-bridge/skills/adversarial-review/SKILL.md +0 -24
  30. package/plugins/claude-codex-bridge/skills/result/SKILL.md +0 -22
  31. package/plugins/claude-codex-bridge/skills/review/SKILL.md +0 -28
  32. package/plugins/claude-codex-bridge/skills/second-pass/SKILL.md +0 -27
  33. package/plugins/claude-codex-bridge/skills/setup/SKILL.md +0 -21
  34. package/plugins/claude-codex-bridge/skills/status/SKILL.md +0 -19
  35. package/plugins/claude-skill/INSTALL.md +0 -55
  36. package/plugins/claude-skill/SKILL.md +0 -46
  37. package/plugins/codex-profile/.codex-plugin/plugin.json +0 -43
  38. package/plugins/codex-profile/.mcp.json +0 -14
  39. package/plugins/codex-profile/AGENTS.md +0 -20
  40. package/plugins/codex-profile/INSTALL.md +0 -89
  41. package/plugins/codex-profile/README.md +0 -61
  42. package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +0 -23
  43. package/plugins/cursor-marketplace/CHANGELOG.md +0 -30
  44. package/plugins/cursor-marketplace/LICENSE +0 -21
  45. package/plugins/cursor-marketplace/README.md +0 -124
  46. package/plugins/cursor-marketplace/agents/reliability-reviewer.md +0 -31
  47. package/plugins/cursor-marketplace/assets/logo-400x400.png +0 -0
  48. package/plugins/cursor-marketplace/commands/capture-feedback.md +0 -33
  49. package/plugins/cursor-marketplace/commands/check-gates.md +0 -25
  50. package/plugins/cursor-marketplace/commands/show-lessons.md +0 -27
  51. package/plugins/cursor-marketplace/hooks/hooks.json +0 -10
  52. package/plugins/cursor-marketplace/mcp.json +0 -14
  53. package/plugins/cursor-marketplace/rules/feedback-capture.mdc +0 -34
  54. package/plugins/cursor-marketplace/rules/pre-action-gates.mdc +0 -30
  55. package/plugins/cursor-marketplace/rules/session-continuity.mdc +0 -28
  56. package/plugins/cursor-marketplace/scripts/gate-check.sh +0 -21
  57. package/plugins/cursor-marketplace/skills/capture-feedback/SKILL.md +0 -48
  58. package/plugins/cursor-marketplace/skills/prevention-rules/SKILL.md +0 -31
  59. package/plugins/cursor-marketplace/skills/recall-context/SKILL.md +0 -30
  60. package/plugins/cursor-marketplace/skills/search-lessons/SKILL.md +0 -33
  61. package/plugins/gemini-extension/INSTALL.md +0 -92
  62. package/plugins/gemini-extension/gemini_prompt.txt +0 -14
  63. package/plugins/gemini-extension/tool_contract.json +0 -45
  64. package/plugins/opencode-profile/INSTALL.md +0 -57
  65. package/public/assets/instagram-card.png +0 -0
  66. package/public/assets/tiktok-agent-memory.mp4 +0 -0
  67. package/public/blog.html +0 -474
  68. package/public/compare/mem0.html +0 -189
  69. package/public/compare/speclock.html +0 -180
  70. package/public/compare.html +0 -310
  71. package/public/dashboard.html +0 -1100
  72. package/public/guide.html +0 -317
  73. package/public/guides/claude-code-prevent-repeated-mistakes.html +0 -161
  74. package/public/guides/codex-cli-guardrails.html +0 -158
  75. package/public/guides/cursor-prevent-repeated-mistakes.html +0 -161
  76. package/public/guides/pre-action-gates.html +0 -162
  77. package/public/guides/stop-repeated-ai-agent-mistakes.html +0 -159
  78. package/public/index.html +0 -1225
  79. package/public/js/buyer-intent.js +0 -252
  80. package/public/learn/agent-harness-pattern.html +0 -180
  81. package/public/learn/ai-agent-persistent-memory.html +0 -203
  82. package/public/learn/learn.css +0 -45
  83. package/public/learn/mcp-pre-action-gates-explained.html +0 -172
  84. package/public/learn/stop-ai-agent-force-push.html +0 -134
  85. package/public/learn/vibe-coding-safety-net.html +0 -142
  86. package/public/learn.html +0 -274
  87. package/public/lessons.html +0 -967
  88. package/public/llm-context.md +0 -156
  89. package/public/pro.html +0 -1087
  90. package/public/vercel.json +0 -8
  91. package/scripts/a2ui-engine.js +0 -73
  92. package/scripts/adk-consolidator.js +0 -274
  93. package/scripts/agent-security-hardening.js +0 -225
  94. package/scripts/ai-search-visibility.js +0 -116
  95. package/scripts/autonomous-sales-agent.js +0 -39
  96. package/scripts/autoresearch-runner.js +0 -216
  97. package/scripts/background-agent-governance.js +0 -229
  98. package/scripts/behavioral-extraction.js +0 -93
  99. package/scripts/budget-enforcer.js +0 -173
  100. package/scripts/budget-guard.js +0 -173
  101. package/scripts/build-claude-mcpb.js +0 -255
  102. package/scripts/build-codex-plugin.js +0 -152
  103. package/scripts/capture-railway-diagnostics.sh +0 -97
  104. package/scripts/changeset-check.js +0 -372
  105. package/scripts/check-congruence.js +0 -443
  106. package/scripts/computer-use-firewall.js +0 -280
  107. package/scripts/content-engine/linkedin-content-generator.js +0 -154
  108. package/scripts/content-engine/output/linkedin-memento-validation.md +0 -17
  109. package/scripts/content-engine/output/linkedin-posts-2026-04-09.md +0 -175
  110. package/scripts/content-engine/reddit-thread-finder.js +0 -154
  111. package/scripts/context-engine.js +0 -710
  112. package/scripts/daily-digest.js +0 -11
  113. package/scripts/data-governance.js +0 -173
  114. package/scripts/deploy-gcp.sh +0 -44
  115. package/scripts/deploy-policy.js +0 -249
  116. package/scripts/disagreement-mining.js +0 -315
  117. package/scripts/dpo-optimizer.js +0 -206
  118. package/scripts/ensure-repo-bootstrap.js +0 -130
  119. package/scripts/ephemeral-agent-store.js +0 -212
  120. package/scripts/eval-harness.js +0 -56
  121. package/scripts/export-kto-pairs.js +0 -309
  122. package/scripts/export-training.js +0 -446
  123. package/scripts/feedback-fallback.js +0 -111
  124. package/scripts/feedback-inbox-read.js +0 -162
  125. package/scripts/feedback-root-consolidator.js +0 -233
  126. package/scripts/feedback-to-memory.js +0 -185
  127. package/scripts/gate-satisfy.js +0 -42
  128. package/scripts/generate-paperbanana-diagrams.sh +0 -99
  129. package/scripts/generate-pretool-hook.sh +0 -40
  130. package/scripts/github-about.js +0 -430
  131. package/scripts/github-outreach.js +0 -65
  132. package/scripts/gtm-revenue-loop.js +0 -535
  133. package/scripts/hallucination-detector.js +0 -226
  134. package/scripts/hf-papers.js +0 -317
  135. package/scripts/hook-auto-capture.sh +0 -100
  136. package/scripts/hook-stop-pr-thread-check.sh +0 -68
  137. package/scripts/hook-stop-self-score.sh +0 -51
  138. package/scripts/hook-stop-verify-deploy.sh +0 -31
  139. package/scripts/hook-verify-before-done.sh +0 -20
  140. package/scripts/managed-dpo-export.js +0 -91
  141. package/scripts/markdown-escape.js +0 -12
  142. package/scripts/marketing-experiment.js +0 -657
  143. package/scripts/memalign-recall.js +0 -111
  144. package/scripts/memory-migration.js +0 -296
  145. package/scripts/meta-policy.js +0 -190
  146. package/scripts/metered-billing.js +0 -16
  147. package/scripts/model-tier-router.js +0 -310
  148. package/scripts/money-watcher.js +0 -218
  149. package/scripts/multi-hop-recall.js +0 -240
  150. package/scripts/per-step-scoring.js +0 -163
  151. package/scripts/perplexity-command-center.js +0 -644
  152. package/scripts/perplexity-marketing.js +0 -454
  153. package/scripts/pii-scanner.js +0 -153
  154. package/scripts/plan-gate.js +0 -154
  155. package/scripts/post-everywhere.js +0 -341
  156. package/scripts/post-to-x-retry.sh +0 -22
  157. package/scripts/post-to-x.js +0 -369
  158. package/scripts/pr-manager.js +0 -421
  159. package/scripts/principle-extractor.js +0 -162
  160. package/scripts/pro-features.js +0 -41
  161. package/scripts/prompt-dlp.js +0 -222
  162. package/scripts/prove-adapters.js +0 -860
  163. package/scripts/prove-attribution.js +0 -361
  164. package/scripts/prove-automation.js +0 -651
  165. package/scripts/prove-autoresearch.js +0 -304
  166. package/scripts/prove-claim-verification.js +0 -277
  167. package/scripts/prove-cloudflare-sandbox.js +0 -161
  168. package/scripts/prove-data-pipeline.js +0 -408
  169. package/scripts/prove-data-quality.js +0 -227
  170. package/scripts/prove-evolution.js +0 -352
  171. package/scripts/prove-harnesses.js +0 -287
  172. package/scripts/prove-intelligence.js +0 -257
  173. package/scripts/prove-lancedb.js +0 -425
  174. package/scripts/prove-local-intelligence.js +0 -340
  175. package/scripts/prove-loop-closure.js +0 -263
  176. package/scripts/prove-packaged-runtime.js +0 -327
  177. package/scripts/prove-predictive-insights.js +0 -355
  178. package/scripts/prove-runtime.js +0 -363
  179. package/scripts/prove-seo-gsd.js +0 -234
  180. package/scripts/prove-settings.js +0 -279
  181. package/scripts/prove-subway-upgrades.js +0 -277
  182. package/scripts/prove-tessl.js +0 -229
  183. package/scripts/prove-training-export.js +0 -325
  184. package/scripts/prove-workflow-contract.js +0 -112
  185. package/scripts/prove-xmemory.js +0 -332
  186. package/scripts/publish-decision.js +0 -159
  187. package/scripts/ralph-loop.js +0 -376
  188. package/scripts/ralph-mode-ci.js +0 -434
  189. package/scripts/reddit-dm-outreach.js +0 -192
  190. package/scripts/reddit-monitor-cron.sh +0 -26
  191. package/scripts/reminder-engine.js +0 -132
  192. package/scripts/revenue-status.js +0 -472
  193. package/scripts/rotate-stripe-webhook-secret.js +0 -314
  194. package/scripts/schedule-manager.js +0 -249
  195. package/scripts/self-healing-check.js +0 -193
  196. package/scripts/session-analyzer.js +0 -533
  197. package/scripts/shieldcortex-memory-firewall-runner.mjs +0 -53
  198. package/scripts/skill-exporter.js +0 -260
  199. package/scripts/skill-materializer.js +0 -134
  200. package/scripts/skill-packs.js +0 -136
  201. package/scripts/skill-proposer.js +0 -99
  202. package/scripts/skill-quality-tracker.js +0 -282
  203. package/scripts/slow-loop.js +0 -72
  204. package/scripts/social-analytics/db/marketing-db.js +0 -179
  205. package/scripts/social-analytics/db/schema.sql +0 -55
  206. package/scripts/social-analytics/digest.js +0 -256
  207. package/scripts/social-analytics/engagement-audit.js +0 -185
  208. package/scripts/social-analytics/generate-instagram-card.js +0 -123
  209. package/scripts/social-analytics/generate-slides.js +0 -268
  210. package/scripts/social-analytics/instagram-thumbgate-post.js +0 -111
  211. package/scripts/social-analytics/install-growth-automation.js +0 -114
  212. package/scripts/social-analytics/load-env.js +0 -77
  213. package/scripts/social-analytics/mcp-server.js +0 -289
  214. package/scripts/social-analytics/normalizer.js +0 -580
  215. package/scripts/social-analytics/notify.js +0 -162
  216. package/scripts/social-analytics/poll-all.js +0 -107
  217. package/scripts/social-analytics/pollers/github.js +0 -195
  218. package/scripts/social-analytics/pollers/instagram.js +0 -253
  219. package/scripts/social-analytics/pollers/linkedin.js +0 -340
  220. package/scripts/social-analytics/pollers/plausible.js +0 -245
  221. package/scripts/social-analytics/pollers/reddit.js +0 -306
  222. package/scripts/social-analytics/pollers/threads.js +0 -233
  223. package/scripts/social-analytics/pollers/tiktok.js +0 -203
  224. package/scripts/social-analytics/pollers/x.js +0 -227
  225. package/scripts/social-analytics/pollers/youtube.js +0 -304
  226. package/scripts/social-analytics/pollers/zernio.js +0 -183
  227. package/scripts/social-analytics/post-video.js +0 -316
  228. package/scripts/social-analytics/publish-instagram-thumbgate.js +0 -104
  229. package/scripts/social-analytics/publish-thumbgate-launch.js +0 -322
  230. package/scripts/social-analytics/publishers/devto.js +0 -122
  231. package/scripts/social-analytics/publishers/instagram.js +0 -317
  232. package/scripts/social-analytics/publishers/linkedin.js +0 -294
  233. package/scripts/social-analytics/publishers/reddit.js +0 -385
  234. package/scripts/social-analytics/publishers/threads.js +0 -275
  235. package/scripts/social-analytics/publishers/tiktok.js +0 -217
  236. package/scripts/social-analytics/publishers/x.js +0 -259
  237. package/scripts/social-analytics/publishers/youtube.js +0 -223
  238. package/scripts/social-analytics/publishers/zernio.js +0 -568
  239. package/scripts/social-analytics/reconcile-thumbgate-campaign.js +0 -165
  240. package/scripts/social-analytics/run-digest.js +0 -34
  241. package/scripts/social-analytics/schedule-thumbgate-campaign.js +0 -275
  242. package/scripts/social-analytics/store.js +0 -455
  243. package/scripts/social-analytics/sync-launch-assets.js +0 -185
  244. package/scripts/social-analytics/utm.js +0 -143
  245. package/scripts/social-pipeline.js +0 -2626
  246. package/scripts/social-post-hourly.js +0 -228
  247. package/scripts/social-quality-gate.js +0 -134
  248. package/scripts/social-reply-monitor.js +0 -592
  249. package/scripts/status-dashboard.js +0 -155
  250. package/scripts/stripe-live-status.js +0 -115
  251. package/scripts/subagent-profiles.js +0 -79
  252. package/scripts/sync-branch-protection.js +0 -340
  253. package/scripts/sync-gh-secrets-from-env.sh +0 -70
  254. package/scripts/sync-github-about.js +0 -55
  255. package/scripts/sync-version.js +0 -479
  256. package/scripts/synthetic-dpo.js +0 -234
  257. package/scripts/tessl-export.js +0 -369
  258. package/scripts/test-coverage.js +0 -128
  259. package/scripts/thumbgate-bench.js +0 -494
  260. package/scripts/thumbgate_session_start.sh +0 -32
  261. package/scripts/train_from_feedback.py +0 -929
  262. package/scripts/validate-feedback.js +0 -581
  263. package/scripts/verify-obsidian-setup.sh +0 -269
  264. package/scripts/verify-run.js +0 -269
  265. package/scripts/weekly-auto-post.js +0 -124
  266. package/scripts/x-autonomous-marketing.js +0 -139
@@ -1,644 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('node:fs');
4
- const path = require('node:path');
5
-
6
- const { PROMPTS: VISIBILITY_PROMPTS } = require('./ai-search-visibility');
7
- const {
8
- PerplexityClient,
9
- extractAgentText,
10
- extractChatText,
11
- extractCitations,
12
- normalizeSearchResults,
13
- } = require('./perplexity-client');
14
-
15
- const DEFAULT_OUTPUT_ROOT = path.join(process.cwd(), '.thumbgate', 'perplexity');
16
- const DEFAULT_LEAD_LIMIT = 12;
17
- const DEFAULT_AGENT_MODEL = process.env.PERPLEXITY_AGENT_MODEL || 'openai/gpt-5.4';
18
-
19
- const PRODUCT = {
20
- name: 'ThumbGate',
21
- repo: 'https://github.com/IgorGanapolsky/ThumbGate',
22
- site: 'https://thumbgate-production.up.railway.app',
23
- checkout: 'https://thumbgate-production.up.railway.app/checkout/pro',
24
- promise: 'turn thumbs-up/down feedback into pre-action gates that stop AI agents from repeating mistakes',
25
- };
26
-
27
- const LEAD_SEARCH_QUERIES = [
28
- {
29
- label: 'agent reliability pain',
30
- query: 'AI coding agent repeats mistakes Claude Code Cursor Codex MCP guardrails',
31
- },
32
- {
33
- label: 'pre-action gate demand',
34
- query: 'pre tool use hook block bad tool calls AI agent safety developer workflow',
35
- },
36
- {
37
- label: 'team workflow hardening',
38
- query: 'AI coding agent broke production migration force push guardrail team workflow',
39
- },
40
- {
41
- label: 'memory and feedback loop',
42
- query: 'thumbs down feedback memory AI coding agents DPO preference learning developer tools',
43
- },
44
- {
45
- label: 'marketplace placement',
46
- query: 'Claude Code plugins MCP memory guardrails AI developer tools',
47
- },
48
- ];
49
-
50
- function parseArgs(argv = process.argv.slice(2)) {
51
- const opts = {
52
- command: 'full',
53
- dryRun: false,
54
- write: true,
55
- json: false,
56
- leadLimit: DEFAULT_LEAD_LIMIT,
57
- outDir: null,
58
- allowChatFallback: false,
59
- };
60
-
61
- for (const arg of argv) {
62
- if (!arg.startsWith('-') && opts.command === 'full') {
63
- opts.command = arg;
64
- } else if (arg === '--dry-run') {
65
- opts.dryRun = true;
66
- } else if (arg === '--no-write') {
67
- opts.write = false;
68
- } else if (arg === '--json') {
69
- opts.json = true;
70
- } else if (arg === '--allow-chat-fallback') {
71
- opts.allowChatFallback = true;
72
- } else if (arg.startsWith('--out-dir=')) {
73
- opts.outDir = arg.slice('--out-dir='.length);
74
- } else if (arg.startsWith('--limit=')) {
75
- opts.leadLimit = parsePositiveInt(arg.slice('--limit='.length), DEFAULT_LEAD_LIMIT);
76
- } else {
77
- throw new Error(`Unknown argument: ${arg}`);
78
- }
79
- }
80
-
81
- return opts;
82
- }
83
-
84
- function parsePositiveInt(value, fallback) {
85
- const parsed = Number.parseInt(String(value), 10);
86
- return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
87
- }
88
-
89
- function dateStamp(now = new Date()) {
90
- return now.toISOString().slice(0, 10);
91
- }
92
-
93
- function ensureDir(dir) {
94
- fs.mkdirSync(dir, { recursive: true });
95
- }
96
-
97
- function outputDirFor(opts = {}) {
98
- if (opts.outDir) return path.resolve(opts.outDir);
99
- return path.join(DEFAULT_OUTPUT_ROOT, dateStamp(opts.now));
100
- }
101
-
102
- function hasLiveAccess(ctx) {
103
- return !ctx.dryRun && ctx.client.hasApiKey();
104
- }
105
-
106
- function normalizeStatusResponse(response) {
107
- return String(response || '').replaceAll(/\s+/g, ' ').trim();
108
- }
109
-
110
- async function collectVisibility(ctx) {
111
- const results = [];
112
-
113
- for (const prompt of VISIBILITY_PROMPTS) {
114
- if (!hasLiveAccess(ctx)) {
115
- results.push({
116
- prompt,
117
- status: 'MANUAL',
118
- found: false,
119
- response: null,
120
- citations: [],
121
- });
122
- continue;
123
- }
124
-
125
- try {
126
- const response = await ctx.client.chatCompletion({
127
- model: 'sonar',
128
- messages: [{ role: 'user', content: prompt }],
129
- });
130
- const text = extractChatText(response);
131
- const found = /thumbgate/i.test(text);
132
- results.push({
133
- prompt,
134
- status: found ? 'FOUND' : 'MISSING',
135
- found,
136
- response: normalizeStatusResponse(text),
137
- citations: extractCitations(response),
138
- });
139
- } catch (err) {
140
- results.push({
141
- prompt,
142
- status: 'ERROR',
143
- found: false,
144
- response: null,
145
- citations: [],
146
- error: err.message,
147
- });
148
- }
149
- }
150
-
151
- const scored = scoreVisibility(results);
152
- return {
153
- date: dateStamp(ctx.now),
154
- mode: hasLiveAccess(ctx) ? 'live' : 'manual',
155
- prompts: VISIBILITY_PROMPTS.length,
156
- ...scored,
157
- results,
158
- };
159
- }
160
-
161
- function scoreVisibility(results) {
162
- const measured = results.filter((item) => item.status !== 'MANUAL');
163
- const found = measured.filter((item) => item.status === 'FOUND').length;
164
- const missing = measured.filter((item) => item.status === 'MISSING').length;
165
- const errors = measured.filter((item) => item.status === 'ERROR').length;
166
- const score = measured.length ? `${found}/${measured.length}` : 'manual';
167
- return { score, found, missing, errors, measured: measured.length };
168
- }
169
-
170
- async function discoverLeads(ctx) {
171
- const rawResults = [];
172
- const queryReports = [];
173
-
174
- for (const search of LEAD_SEARCH_QUERIES) {
175
- if (!hasLiveAccess(ctx)) {
176
- queryReports.push({ ...search, status: 'MANUAL', results: [] });
177
- continue;
178
- }
179
-
180
- try {
181
- const response = await ctx.client.search({
182
- query: search.query,
183
- maxResults: Math.min(10, ctx.leadLimit),
184
- maxTokensPerPage: 768,
185
- });
186
- const results = normalizeSearchResults(response).map((item) => ({
187
- ...item,
188
- queryLabel: search.label,
189
- query: search.query,
190
- }));
191
- rawResults.push(...results);
192
- queryReports.push({ ...search, status: 'OK', results });
193
- } catch (err) {
194
- queryReports.push({ ...search, status: 'ERROR', error: err.message, results: [] });
195
- }
196
- }
197
-
198
- const deduped = dedupeLeads(rawResults)
199
- .map(scoreLead)
200
- .sort((a, b) => b.score - a.score || a.title.localeCompare(b.title))
201
- .slice(0, ctx.leadLimit);
202
-
203
- return {
204
- date: dateStamp(ctx.now),
205
- mode: hasLiveAccess(ctx) ? 'live' : 'manual',
206
- queryCount: LEAD_SEARCH_QUERIES.length,
207
- leadCount: deduped.length,
208
- queries: queryReports.map((item) => ({
209
- label: item.label,
210
- query: item.query,
211
- status: item.status,
212
- resultCount: item.results.length,
213
- ...(item.error ? { error: item.error } : {}),
214
- })),
215
- leads: deduped,
216
- };
217
- }
218
-
219
- function canonicalLeadUrl(url) {
220
- try {
221
- const parsed = new URL(url);
222
- parsed.hash = '';
223
- const trackingKeys = [];
224
- for (const key of parsed.searchParams.keys()) {
225
- if (/^(utm$|utm_|fbclid$|gclid$|mc_cid$|mc_eid$)/i.test(key)) {
226
- trackingKeys.push(key);
227
- }
228
- }
229
- for (const key of trackingKeys) parsed.searchParams.delete(key);
230
- parsed.searchParams.sort();
231
- const cleanUrl = parsed.toString();
232
- return cleanUrl.endsWith('/') ? cleanUrl.slice(0, -1) : cleanUrl;
233
- } catch {
234
- return String(url || '').trim();
235
- }
236
- }
237
-
238
- function dedupeLeads(results) {
239
- const seen = new Map();
240
- for (const item of results) {
241
- const key = canonicalLeadUrl(item.url);
242
- if (!key) continue;
243
- const existing = seen.get(key);
244
- if (!existing) {
245
- seen.set(key, { ...item, url: key, queryLabels: [item.queryLabel] });
246
- } else if (!existing.queryLabels.includes(item.queryLabel)) {
247
- existing.queryLabels.push(item.queryLabel);
248
- }
249
- }
250
- return [...seen.values()];
251
- }
252
-
253
- function scoreLead(lead) {
254
- const text = `${lead.title} ${lead.snippet} ${lead.url}`.toLowerCase();
255
- const reasons = [];
256
- let score = 0;
257
-
258
- score += addScore(text, /\b(ai|llm|agent|coding agent|assistant)\b/, 3, reasons, 'AI-agent context');
259
- score += addScore(text, /\b(claude|codex|cursor|gemini|amp|mcp|pretooluse|tool call)\b/, 3, reasons, 'target ecosystem');
260
- score += addScore(text, /\b(repeat|mistake|broken|failure|guardrail|safety|block|prevent|hook)\b/, 4, reasons, 'clear pain signal');
261
- score += addScore(text, /\b(team|enterprise|production|workflow|devops|platform)\b/, 2, reasons, 'team workflow angle');
262
- score += addScore(text, /\b(reddit|news\.ycombinator|github\.com|stackoverflow|discord|forum|community)\b/, 2, reasons, 'community surface');
263
- score += addScore(text, /\b(price|buy|paid|tool|saas|plugin|marketplace)\b/, 2, reasons, 'commercial intent');
264
-
265
- if (lead.date && /2026|2025/.test(String(lead.date))) {
266
- score += 1;
267
- reasons.push('recent result');
268
- }
269
-
270
- return {
271
- ...lead,
272
- score,
273
- reasons,
274
- outreachAngle: buildOutreachAngle(lead, reasons),
275
- };
276
- }
277
-
278
- function addScore(text, regex, points, reasons, reason) {
279
- if (!regex.test(text)) return 0;
280
- reasons.push(reason);
281
- return points;
282
- }
283
-
284
- function buildOutreachAngle(lead, reasons) {
285
- if (reasons.includes('clear pain signal')) {
286
- return 'Lead with repeated-agent-mistake prevention and offer a concrete before/after gate example.';
287
- }
288
- if (reasons.includes('target ecosystem')) {
289
- return 'Lead with the exact install path for their agent ecosystem and show the first thumbs-down-to-gate loop.';
290
- }
291
- return 'Lead with ThumbGate as a lightweight reliability gateway for AI coding workflows.';
292
- }
293
-
294
- async function buildAgentBrief(ctx, inputs = {}) {
295
- const visibility = inputs.visibility || null;
296
- const leads = inputs.leads || null;
297
- const prompt = buildBriefPrompt({ visibility, leads });
298
-
299
- if (!hasLiveAccess(ctx)) {
300
- return {
301
- date: dateStamp(ctx.now),
302
- mode: 'manual',
303
- model: DEFAULT_AGENT_MODEL,
304
- content: formatManualBrief({ visibility, leads }),
305
- };
306
- }
307
-
308
- try {
309
- const response = await ctx.client.agentResponse({
310
- model: ctx.agentModel,
311
- input: prompt,
312
- instructions: 'You are ThumbGate revenue intelligence. Be specific, factual, and conversion-oriented. Prioritize actions that can create the first dollar or improve distribution quality.',
313
- tools: [{ type: 'web_search' }, { type: 'fetch_url' }],
314
- maxOutputTokens: 1800,
315
- });
316
- return {
317
- date: dateStamp(ctx.now),
318
- mode: 'live',
319
- model: ctx.agentModel,
320
- content: extractAgentText(response),
321
- rawUsage: response.usage || null,
322
- };
323
- } catch (err) {
324
- if (!ctx.allowChatFallback) {
325
- throw err;
326
- }
327
- const response = await ctx.client.chatCompletion({
328
- model: 'sonar-pro',
329
- messages: [{ role: 'user', content: prompt }],
330
- options: { web_search_options: { search_context_size: 'medium' } },
331
- });
332
- return {
333
- date: dateStamp(ctx.now),
334
- mode: 'chat-fallback',
335
- model: 'sonar-pro',
336
- content: extractChatText(response),
337
- fallbackReason: err.message,
338
- };
339
- }
340
- }
341
-
342
- function buildBriefPrompt({ visibility, leads }) {
343
- const visibilitySummary = visibility
344
- ? `Visibility score: ${visibility.score}; missing prompts: ${visibility.missing}; errors: ${visibility.errors}.`
345
- : 'Visibility report was not generated in this run.';
346
- const leadSummary = leads
347
- ? leads.leads.slice(0, 8).map((lead, index) => `${index + 1}. ${lead.title} (${lead.url}) score=${lead.score}`).join('\n')
348
- : 'Lead report was not generated in this run.';
349
-
350
- return `Create a ThumbGate Perplexity Max command brief.
351
-
352
- Product: ${PRODUCT.name}
353
- Promise: ${PRODUCT.promise}
354
- Repo: ${PRODUCT.repo}
355
- Site: ${PRODUCT.site}
356
- Checkout: ${PRODUCT.checkout}
357
-
358
- ${visibilitySummary}
359
-
360
- Top lead surfaces:
361
- ${leadSummary}
362
-
363
- Return:
364
- 1. The single highest-ROI acquisition action for the next 24 hours.
365
- 2. Three search/GEO gaps to fix in docs or landing copy.
366
- 3. Five outreach targets or communities with a specific angle.
367
- 4. One risk that could waste time or spend.
368
- 5. A concise action plan with owners and proof to collect.`;
369
- }
370
-
371
- function formatManualBrief({ visibility, leads }) {
372
- const visibilityScore = visibility?.score || 'manual';
373
- const leadCount = leads?.leadCount || 0;
374
- return [
375
- '# ThumbGate Perplexity Max Brief',
376
- '',
377
- `Generated: ${new Date().toISOString()}`,
378
- '',
379
- 'Mode: manual or dry-run. Set PERPLEXITY_API_KEY to generate a live Agent API brief.',
380
- '',
381
- `Visibility score: ${visibilityScore}`,
382
- `Lead count: ${leadCount}`,
383
- '',
384
- 'Next action: run `npm run perplexity:full` with PERPLEXITY_API_KEY configured, then inspect the top scored leads before posting or replying.',
385
- ].join('\n');
386
- }
387
-
388
- function buildMcpConfig() {
389
- return {
390
- source: 'https://github.com/perplexityai/modelcontextprotocol',
391
- claudeCode: 'claude mcp add perplexity --env PERPLEXITY_API_KEY="your_key_here" -- npx -y @perplexity-ai/mcp-server',
392
- codex: 'codex mcp add perplexity --env PERPLEXITY_API_KEY="your_key_here" -- npx -y @perplexity-ai/mcp-server',
393
- mcpServers: {
394
- perplexity: {
395
- command: 'npx',
396
- args: ['-y', '@perplexity-ai/mcp-server'],
397
- env: {
398
- PERPLEXITY_API_KEY: '${PERPLEXITY_API_KEY}',
399
- },
400
- },
401
- },
402
- };
403
- }
404
-
405
- function lessonsFromRun(run) {
406
- const lessons = [];
407
- const visibility = run.visibility;
408
- if (visibility) {
409
- for (const result of visibility.results || []) {
410
- if (result.status !== 'MISSING') continue;
411
- lessons.push({
412
- signal: 'down',
413
- domain: 'perplexity-visibility',
414
- context: `Perplexity answer for "${result.prompt}" did not mention ThumbGate.`,
415
- whatWentWrong: 'ThumbGate is not visible for a high-intent AI-agent reliability query.',
416
- whatToChange: 'Add or strengthen docs, landing-page copy, and citations for this exact query intent.',
417
- tags: ['perplexity', 'geo', 'visibility', 'acquisition'],
418
- createdAt: new Date().toISOString(),
419
- });
420
- }
421
- }
422
- const leads = run.leads?.leads || [];
423
- for (const lead of leads.slice(0, 5)) {
424
- lessons.push({
425
- signal: 'up',
426
- domain: 'perplexity-lead-discovery',
427
- context: `Perplexity surfaced ${lead.url} as a lead candidate with score ${lead.score}.`,
428
- whatWorked: lead.outreachAngle,
429
- tags: ['perplexity', 'lead', 'acquisition'],
430
- createdAt: new Date().toISOString(),
431
- });
432
- }
433
- return lessons;
434
- }
435
-
436
- async function runCommand(command = 'full', opts = {}) {
437
- const ctx = {
438
- now: opts.now || new Date(),
439
- dryRun: Boolean(opts.dryRun),
440
- write: opts.write !== false,
441
- outDir: outputDirFor(opts),
442
- leadLimit: parsePositiveInt(opts.leadLimit, DEFAULT_LEAD_LIMIT),
443
- allowChatFallback: Boolean(opts.allowChatFallback),
444
- agentModel: opts.agentModel || DEFAULT_AGENT_MODEL,
445
- client: opts.client || new PerplexityClient(opts.clientOptions || {}),
446
- };
447
-
448
- const run = {
449
- command,
450
- date: dateStamp(ctx.now),
451
- outputDir: ctx.outDir,
452
- dryRun: ctx.dryRun,
453
- hasApiKey: ctx.client.hasApiKey(),
454
- };
455
-
456
- switch (command) {
457
- case 'visibility':
458
- run.visibility = await collectVisibility(ctx);
459
- break;
460
- case 'leads':
461
- run.leads = await discoverLeads(ctx);
462
- break;
463
- case 'brief':
464
- run.brief = await buildAgentBrief(ctx);
465
- break;
466
- case 'mcp-config':
467
- run.mcpConfig = buildMcpConfig();
468
- break;
469
- case 'full':
470
- run.visibility = await collectVisibility(ctx);
471
- run.leads = await discoverLeads(ctx);
472
- run.brief = await buildAgentBrief(ctx, { visibility: run.visibility, leads: run.leads });
473
- run.mcpConfig = buildMcpConfig();
474
- break;
475
- default:
476
- throw new Error(`Unknown command: ${command}`);
477
- }
478
-
479
- run.lessons = lessonsFromRun(run);
480
- run.summary = buildSummary(run);
481
-
482
- if (ctx.write) {
483
- run.written = writeArtifacts(run, ctx.outDir);
484
- }
485
-
486
- return run;
487
- }
488
-
489
- function buildSummary(run) {
490
- return {
491
- command: run.command,
492
- date: run.date,
493
- dryRun: run.dryRun,
494
- hasApiKey: run.hasApiKey,
495
- visibilityScore: run.visibility?.score || null,
496
- leadCount: run.leads?.leadCount || 0,
497
- lessonCount: run.lessons?.length || 0,
498
- briefMode: run.brief?.mode || null,
499
- };
500
- }
501
-
502
- function writeArtifacts(run, outDir) {
503
- ensureDir(outDir);
504
- const written = [];
505
-
506
- written.push(writeJson(path.join(outDir, 'summary.json'), run.summary));
507
-
508
- if (run.visibility) {
509
- written.push(
510
- writeJson(path.join(outDir, 'visibility.json'), run.visibility),
511
- writeText(path.join(outDir, 'visibility.md'), formatVisibilityMarkdown(run.visibility))
512
- );
513
- }
514
- if (run.leads) {
515
- written.push(
516
- writeJson(path.join(outDir, 'leads.json'), run.leads),
517
- writeText(path.join(outDir, 'leads.md'), formatLeadsMarkdown(run.leads))
518
- );
519
- }
520
- if (run.brief) {
521
- written.push(writeText(path.join(outDir, 'agent-brief.md'), run.brief.content || ''));
522
- }
523
- if (run.mcpConfig) {
524
- written.push(writeJson(path.join(outDir, 'perplexity-mcp-config.json'), run.mcpConfig));
525
- }
526
- if (run.lessons?.length) {
527
- written.push(writeText(path.join(outDir, 'memory-lessons.jsonl'), run.lessons.map((item) => JSON.stringify(item)).join('\n') + '\n'));
528
- }
529
-
530
- return written;
531
- }
532
-
533
- function writeJson(filePath, value) {
534
- return writeText(filePath, JSON.stringify(value, null, 2) + '\n');
535
- }
536
-
537
- function writeText(filePath, value) {
538
- fs.writeFileSync(filePath, value, 'utf8');
539
- return filePath;
540
- }
541
-
542
- function formatVisibilityMarkdown(report) {
543
- const lines = [
544
- '# Perplexity Visibility Report',
545
- '',
546
- `Date: ${report.date}`,
547
- `Mode: ${report.mode}`,
548
- `Score: ${report.score}`,
549
- '',
550
- '| Status | Prompt | Notes |',
551
- '| --- | --- | --- |',
552
- ];
553
-
554
- for (const item of report.results) {
555
- const note = visibilityNote(item);
556
- lines.push(`| ${item.status} | ${escapeMarkdownTable(item.prompt)} | ${escapeMarkdownTable(note)} |`);
557
- }
558
- return lines.join('\n') + '\n';
559
- }
560
-
561
- function visibilityNote(item) {
562
- if (item.error) return item.error;
563
- if (item.found) return 'ThumbGate mentioned';
564
- if (item.status === 'MANUAL') return 'Manual check required';
565
- return 'ThumbGate missing';
566
- }
567
-
568
- function formatLeadsMarkdown(report) {
569
- const lines = [
570
- '# Perplexity Lead Discovery Report',
571
- '',
572
- `Date: ${report.date}`,
573
- `Mode: ${report.mode}`,
574
- `Leads: ${report.leadCount}`,
575
- '',
576
- '| Score | Lead | Reason | Angle |',
577
- '| ---: | --- | --- | --- |',
578
- ];
579
-
580
- for (const lead of report.leads) {
581
- const link = `[${escapeMarkdownLinkText(lead.title)}](${lead.url})`;
582
- lines.push(`| ${lead.score} | ${link} | ${escapeMarkdownTable(lead.reasons.join(', '))} | ${escapeMarkdownTable(lead.outreachAngle)} |`);
583
- }
584
- return lines.join('\n') + '\n';
585
- }
586
-
587
- function escapeMarkdownTable(value) {
588
- return String(value || '')
589
- .split('\\').join('\\\\')
590
- .split('|').join('\\|')
591
- .split('\r').join(' ')
592
- .split('\n').join(' ');
593
- }
594
-
595
- function escapeMarkdownLinkText(value) {
596
- return String(value || 'Untitled')
597
- .split('\\').join('\\\\')
598
- .split('[').join('\\[')
599
- .split(']').join('\\]');
600
- }
601
-
602
- function isCliEntrypoint(argv = process.argv) {
603
- return Boolean(argv[1] && path.resolve(argv[1]) === __filename);
604
- }
605
-
606
- async function main() {
607
- const opts = parseArgs();
608
- const run = await runCommand(opts.command, opts);
609
- if (opts.json) {
610
- console.log(JSON.stringify(run.summary, null, 2));
611
- return;
612
- }
613
- console.log(`Perplexity command center: ${run.command}`);
614
- console.log(`Output: ${run.outputDir}`);
615
- console.log(`Visibility: ${run.summary.visibilityScore || 'not run'}`);
616
- console.log(`Leads: ${run.summary.leadCount}`);
617
- console.log(`Lessons staged: ${run.summary.lessonCount}`);
618
- }
619
-
620
- module.exports = {
621
- LEAD_SEARCH_QUERIES,
622
- buildAgentBrief,
623
- buildBriefPrompt,
624
- buildMcpConfig,
625
- buildSummary,
626
- collectVisibility,
627
- dateStamp,
628
- dedupeLeads,
629
- discoverLeads,
630
- formatLeadsMarkdown,
631
- formatVisibilityMarkdown,
632
- isCliEntrypoint,
633
- lessonsFromRun,
634
- parseArgs,
635
- runCommand,
636
- scoreLead,
637
- };
638
-
639
- if (isCliEntrypoint()) {
640
- main().catch((err) => {
641
- console.error(`Perplexity command center failed: ${err.message}`);
642
- process.exit(1);
643
- });
644
- }