thumbgate 1.4.2 → 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 (279) hide show
  1. package/.claude-plugin/README.md +45 -34
  2. package/.claude-plugin/marketplace.json +3 -3
  3. package/.claude-plugin/plugin.json +3 -3
  4. package/.well-known/llms.txt +1 -1
  5. package/.well-known/mcp/server-card.json +1 -1
  6. package/README.md +26 -2
  7. package/adapters/README.md +4 -1
  8. package/adapters/claude/.mcp.json +2 -2
  9. package/adapters/codex/config.toml +2 -2
  10. package/adapters/mcp/server-stdio.js +10 -4
  11. package/adapters/opencode/opencode.json +1 -1
  12. package/bin/cli.js +246 -90
  13. package/config/mcp-allowlists.json +11 -3
  14. package/package.json +184 -21
  15. package/scripts/audit-trail.js +25 -15
  16. package/scripts/auto-wire-hooks.js +127 -0
  17. package/scripts/cli-demo.js +102 -0
  18. package/scripts/cli-schema.js +285 -0
  19. package/scripts/cli-status.js +166 -0
  20. package/scripts/cross-encoder-reranker.js +235 -0
  21. package/scripts/explore-subcommands.js +277 -0
  22. package/scripts/explore.js +569 -0
  23. package/scripts/feedback-loop.js +20 -6
  24. package/scripts/lesson-inference.js +7 -1
  25. package/scripts/lesson-reranker.js +263 -0
  26. package/scripts/lesson-retrieval.js +34 -17
  27. package/scripts/lesson-search.js +69 -0
  28. package/scripts/perplexity-client.js +210 -0
  29. package/scripts/reflector-agent.js +2 -2
  30. package/scripts/statusline-local-stats.js +3 -1
  31. package/scripts/statusline.sh +12 -11
  32. package/src/api/server.js +178 -17
  33. package/src/index.js +3 -0
  34. package/.claude-plugin/bundle/icon.png +0 -0
  35. package/.claude-plugin/bundle/icon.svg +0 -18
  36. package/.claude-plugin/bundle/server/index.js +0 -24
  37. package/adapters/chatgpt/INSTALL.md +0 -138
  38. package/bin/memory.sh +0 -64
  39. package/bin/obsidian-sync.sh +0 -20
  40. package/plugins/amp-skill/INSTALL.md +0 -52
  41. package/plugins/amp-skill/SKILL.md +0 -64
  42. package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +0 -22
  43. package/plugins/claude-codex-bridge/.mcp.json +0 -14
  44. package/plugins/claude-codex-bridge/INSTALL.md +0 -43
  45. package/plugins/claude-codex-bridge/README.md +0 -46
  46. package/plugins/claude-codex-bridge/scripts/codex-bridge.js +0 -286
  47. package/plugins/claude-codex-bridge/skills/adversarial-review/SKILL.md +0 -24
  48. package/plugins/claude-codex-bridge/skills/result/SKILL.md +0 -22
  49. package/plugins/claude-codex-bridge/skills/review/SKILL.md +0 -28
  50. package/plugins/claude-codex-bridge/skills/second-pass/SKILL.md +0 -27
  51. package/plugins/claude-codex-bridge/skills/setup/SKILL.md +0 -21
  52. package/plugins/claude-codex-bridge/skills/status/SKILL.md +0 -19
  53. package/plugins/claude-skill/INSTALL.md +0 -55
  54. package/plugins/claude-skill/SKILL.md +0 -46
  55. package/plugins/codex-profile/.codex-plugin/plugin.json +0 -43
  56. package/plugins/codex-profile/.mcp.json +0 -14
  57. package/plugins/codex-profile/AGENTS.md +0 -20
  58. package/plugins/codex-profile/INSTALL.md +0 -89
  59. package/plugins/codex-profile/README.md +0 -61
  60. package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +0 -23
  61. package/plugins/cursor-marketplace/CHANGELOG.md +0 -30
  62. package/plugins/cursor-marketplace/LICENSE +0 -21
  63. package/plugins/cursor-marketplace/README.md +0 -124
  64. package/plugins/cursor-marketplace/agents/reliability-reviewer.md +0 -31
  65. package/plugins/cursor-marketplace/assets/logo-400x400.png +0 -0
  66. package/plugins/cursor-marketplace/commands/capture-feedback.md +0 -33
  67. package/plugins/cursor-marketplace/commands/check-gates.md +0 -25
  68. package/plugins/cursor-marketplace/commands/show-lessons.md +0 -27
  69. package/plugins/cursor-marketplace/hooks/hooks.json +0 -10
  70. package/plugins/cursor-marketplace/mcp.json +0 -14
  71. package/plugins/cursor-marketplace/rules/feedback-capture.mdc +0 -34
  72. package/plugins/cursor-marketplace/rules/pre-action-gates.mdc +0 -30
  73. package/plugins/cursor-marketplace/rules/session-continuity.mdc +0 -28
  74. package/plugins/cursor-marketplace/scripts/gate-check.sh +0 -21
  75. package/plugins/cursor-marketplace/skills/capture-feedback/SKILL.md +0 -48
  76. package/plugins/cursor-marketplace/skills/prevention-rules/SKILL.md +0 -31
  77. package/plugins/cursor-marketplace/skills/recall-context/SKILL.md +0 -30
  78. package/plugins/cursor-marketplace/skills/search-lessons/SKILL.md +0 -33
  79. package/plugins/gemini-extension/INSTALL.md +0 -92
  80. package/plugins/gemini-extension/gemini_prompt.txt +0 -14
  81. package/plugins/gemini-extension/tool_contract.json +0 -45
  82. package/plugins/opencode-profile/INSTALL.md +0 -57
  83. package/public/assets/instagram-card.png +0 -0
  84. package/public/assets/tiktok-agent-memory.mp4 +0 -0
  85. package/public/blog.html +0 -474
  86. package/public/compare/mem0.html +0 -189
  87. package/public/compare/speclock.html +0 -180
  88. package/public/compare.html +0 -310
  89. package/public/dashboard.html +0 -1100
  90. package/public/guide.html +0 -317
  91. package/public/guides/claude-code-prevent-repeated-mistakes.html +0 -161
  92. package/public/guides/codex-cli-guardrails.html +0 -158
  93. package/public/guides/cursor-prevent-repeated-mistakes.html +0 -161
  94. package/public/guides/pre-action-gates.html +0 -162
  95. package/public/guides/stop-repeated-ai-agent-mistakes.html +0 -159
  96. package/public/index.html +0 -1128
  97. package/public/js/buyer-intent.js +0 -252
  98. package/public/learn/agent-harness-pattern.html +0 -180
  99. package/public/learn/ai-agent-persistent-memory.html +0 -203
  100. package/public/learn/learn.css +0 -45
  101. package/public/learn/mcp-pre-action-gates-explained.html +0 -172
  102. package/public/learn/stop-ai-agent-force-push.html +0 -134
  103. package/public/learn/vibe-coding-safety-net.html +0 -142
  104. package/public/learn.html +0 -274
  105. package/public/lessons.html +0 -967
  106. package/public/llm-context.md +0 -140
  107. package/public/pro.html +0 -1087
  108. package/public/vercel.json +0 -8
  109. package/scripts/a2ui-engine.js +0 -73
  110. package/scripts/adk-consolidator.js +0 -274
  111. package/scripts/agent-security-hardening.js +0 -225
  112. package/scripts/ai-search-visibility.js +0 -142
  113. package/scripts/autonomous-sales-agent.js +0 -39
  114. package/scripts/autoresearch-runner.js +0 -216
  115. package/scripts/background-agent-governance.js +0 -229
  116. package/scripts/behavioral-extraction.js +0 -93
  117. package/scripts/budget-enforcer.js +0 -173
  118. package/scripts/budget-guard.js +0 -173
  119. package/scripts/build-claude-mcpb.js +0 -255
  120. package/scripts/build-codex-plugin.js +0 -152
  121. package/scripts/capture-railway-diagnostics.sh +0 -97
  122. package/scripts/changeset-check.js +0 -372
  123. package/scripts/check-congruence.js +0 -443
  124. package/scripts/computer-use-firewall.js +0 -280
  125. package/scripts/content-engine/linkedin-content-generator.js +0 -154
  126. package/scripts/content-engine/output/linkedin-memento-validation.md +0 -17
  127. package/scripts/content-engine/output/linkedin-posts-2026-04-09.md +0 -175
  128. package/scripts/content-engine/reddit-thread-finder.js +0 -154
  129. package/scripts/context-engine.js +0 -710
  130. package/scripts/daily-digest.js +0 -11
  131. package/scripts/data-governance.js +0 -173
  132. package/scripts/deploy-gcp.sh +0 -44
  133. package/scripts/deploy-policy.js +0 -249
  134. package/scripts/disagreement-mining.js +0 -315
  135. package/scripts/dpo-optimizer.js +0 -206
  136. package/scripts/ensure-repo-bootstrap.js +0 -130
  137. package/scripts/ephemeral-agent-store.js +0 -212
  138. package/scripts/eval-harness.js +0 -56
  139. package/scripts/export-kto-pairs.js +0 -309
  140. package/scripts/export-training.js +0 -446
  141. package/scripts/feedback-fallback.js +0 -111
  142. package/scripts/feedback-inbox-read.js +0 -162
  143. package/scripts/feedback-root-consolidator.js +0 -233
  144. package/scripts/feedback-to-memory.js +0 -185
  145. package/scripts/gate-satisfy.js +0 -42
  146. package/scripts/generate-paperbanana-diagrams.sh +0 -99
  147. package/scripts/generate-pretool-hook.sh +0 -40
  148. package/scripts/github-about.js +0 -430
  149. package/scripts/github-outreach.js +0 -65
  150. package/scripts/gtm-revenue-loop.js +0 -535
  151. package/scripts/hallucination-detector.js +0 -226
  152. package/scripts/hf-papers.js +0 -317
  153. package/scripts/hook-auto-capture.sh +0 -100
  154. package/scripts/hook-stop-pr-thread-check.sh +0 -68
  155. package/scripts/hook-stop-self-score.sh +0 -51
  156. package/scripts/hook-stop-verify-deploy.sh +0 -31
  157. package/scripts/hook-verify-before-done.sh +0 -20
  158. package/scripts/managed-dpo-export.js +0 -91
  159. package/scripts/markdown-escape.js +0 -12
  160. package/scripts/marketing-experiment.js +0 -657
  161. package/scripts/memalign-recall.js +0 -111
  162. package/scripts/memory-migration.js +0 -296
  163. package/scripts/meta-policy.js +0 -190
  164. package/scripts/metered-billing.js +0 -16
  165. package/scripts/model-tier-router.js +0 -310
  166. package/scripts/money-watcher.js +0 -218
  167. package/scripts/multi-hop-recall.js +0 -240
  168. package/scripts/per-step-scoring.js +0 -163
  169. package/scripts/perplexity-marketing.js +0 -466
  170. package/scripts/pii-scanner.js +0 -153
  171. package/scripts/plan-gate.js +0 -154
  172. package/scripts/post-everywhere.js +0 -341
  173. package/scripts/post-to-x-retry.sh +0 -22
  174. package/scripts/post-to-x.js +0 -369
  175. package/scripts/pr-manager.js +0 -421
  176. package/scripts/principle-extractor.js +0 -162
  177. package/scripts/pro-features.js +0 -41
  178. package/scripts/prompt-dlp.js +0 -222
  179. package/scripts/prove-adapters.js +0 -860
  180. package/scripts/prove-attribution.js +0 -361
  181. package/scripts/prove-automation.js +0 -651
  182. package/scripts/prove-autoresearch.js +0 -304
  183. package/scripts/prove-claim-verification.js +0 -277
  184. package/scripts/prove-cloudflare-sandbox.js +0 -161
  185. package/scripts/prove-data-pipeline.js +0 -408
  186. package/scripts/prove-data-quality.js +0 -227
  187. package/scripts/prove-evolution.js +0 -352
  188. package/scripts/prove-harnesses.js +0 -287
  189. package/scripts/prove-intelligence.js +0 -257
  190. package/scripts/prove-lancedb.js +0 -425
  191. package/scripts/prove-local-intelligence.js +0 -340
  192. package/scripts/prove-loop-closure.js +0 -263
  193. package/scripts/prove-packaged-runtime.js +0 -326
  194. package/scripts/prove-predictive-insights.js +0 -355
  195. package/scripts/prove-runtime.js +0 -363
  196. package/scripts/prove-seo-gsd.js +0 -234
  197. package/scripts/prove-settings.js +0 -279
  198. package/scripts/prove-subway-upgrades.js +0 -277
  199. package/scripts/prove-tessl.js +0 -229
  200. package/scripts/prove-training-export.js +0 -325
  201. package/scripts/prove-workflow-contract.js +0 -112
  202. package/scripts/prove-xmemory.js +0 -332
  203. package/scripts/publish-decision.js +0 -159
  204. package/scripts/ralph-loop.js +0 -376
  205. package/scripts/ralph-mode-ci.js +0 -331
  206. package/scripts/reddit-dm-outreach.js +0 -192
  207. package/scripts/reddit-monitor-cron.sh +0 -26
  208. package/scripts/reminder-engine.js +0 -132
  209. package/scripts/revenue-status.js +0 -472
  210. package/scripts/rotate-stripe-webhook-secret.js +0 -314
  211. package/scripts/schedule-manager.js +0 -249
  212. package/scripts/self-healing-check.js +0 -193
  213. package/scripts/shieldcortex-memory-firewall-runner.mjs +0 -53
  214. package/scripts/skill-exporter.js +0 -260
  215. package/scripts/skill-materializer.js +0 -134
  216. package/scripts/skill-packs.js +0 -136
  217. package/scripts/skill-proposer.js +0 -99
  218. package/scripts/skill-quality-tracker.js +0 -282
  219. package/scripts/slow-loop.js +0 -72
  220. package/scripts/social-analytics/db/analytics.sqlite +0 -0
  221. package/scripts/social-analytics/db/schema.sql +0 -32
  222. package/scripts/social-analytics/digest.js +0 -256
  223. package/scripts/social-analytics/engagement-audit.js +0 -185
  224. package/scripts/social-analytics/generate-instagram-card.js +0 -97
  225. package/scripts/social-analytics/instagram-thumbgate-post.js +0 -111
  226. package/scripts/social-analytics/install-growth-automation.js +0 -114
  227. package/scripts/social-analytics/load-env.js +0 -77
  228. package/scripts/social-analytics/mcp-server.js +0 -289
  229. package/scripts/social-analytics/normalizer.js +0 -580
  230. package/scripts/social-analytics/notify.js +0 -162
  231. package/scripts/social-analytics/poll-all.js +0 -107
  232. package/scripts/social-analytics/pollers/github.js +0 -195
  233. package/scripts/social-analytics/pollers/instagram.js +0 -253
  234. package/scripts/social-analytics/pollers/linkedin.js +0 -340
  235. package/scripts/social-analytics/pollers/plausible.js +0 -245
  236. package/scripts/social-analytics/pollers/reddit.js +0 -306
  237. package/scripts/social-analytics/pollers/threads.js +0 -233
  238. package/scripts/social-analytics/pollers/tiktok.js +0 -203
  239. package/scripts/social-analytics/pollers/x.js +0 -227
  240. package/scripts/social-analytics/pollers/youtube.js +0 -304
  241. package/scripts/social-analytics/pollers/zernio.js +0 -183
  242. package/scripts/social-analytics/publish-instagram-thumbgate.js +0 -104
  243. package/scripts/social-analytics/publish-thumbgate-launch.js +0 -322
  244. package/scripts/social-analytics/publishers/devto.js +0 -122
  245. package/scripts/social-analytics/publishers/instagram.js +0 -317
  246. package/scripts/social-analytics/publishers/linkedin.js +0 -294
  247. package/scripts/social-analytics/publishers/reddit.js +0 -385
  248. package/scripts/social-analytics/publishers/threads.js +0 -275
  249. package/scripts/social-analytics/publishers/tiktok.js +0 -217
  250. package/scripts/social-analytics/publishers/x.js +0 -259
  251. package/scripts/social-analytics/publishers/youtube.js +0 -223
  252. package/scripts/social-analytics/publishers/zernio.js +0 -539
  253. package/scripts/social-analytics/reconcile-thumbgate-campaign.js +0 -165
  254. package/scripts/social-analytics/run-digest.js +0 -34
  255. package/scripts/social-analytics/schedule-thumbgate-campaign.js +0 -275
  256. package/scripts/social-analytics/store.js +0 -455
  257. package/scripts/social-analytics/sync-launch-assets.js +0 -185
  258. package/scripts/social-analytics/utm.js +0 -143
  259. package/scripts/social-pipeline.js +0 -2626
  260. package/scripts/social-post-hourly.js +0 -228
  261. package/scripts/social-quality-gate.js +0 -134
  262. package/scripts/social-reply-monitor.js +0 -592
  263. package/scripts/status-dashboard.js +0 -155
  264. package/scripts/stripe-live-status.js +0 -115
  265. package/scripts/subagent-profiles.js +0 -79
  266. package/scripts/sync-branch-protection.js +0 -340
  267. package/scripts/sync-gh-secrets-from-env.sh +0 -70
  268. package/scripts/sync-github-about.js +0 -55
  269. package/scripts/sync-version.js +0 -479
  270. package/scripts/synthetic-dpo.js +0 -234
  271. package/scripts/tessl-export.js +0 -369
  272. package/scripts/test-coverage.js +0 -128
  273. package/scripts/thumbgate_session_start.sh +0 -32
  274. package/scripts/train_from_feedback.py +0 -929
  275. package/scripts/validate-feedback.js +0 -581
  276. package/scripts/verify-obsidian-setup.sh +0 -269
  277. package/scripts/verify-run.js +0 -269
  278. package/scripts/weekly-auto-post.js +0 -124
  279. package/scripts/x-autonomous-marketing.js +0 -139
@@ -1,142 +0,0 @@
1
- 'use strict';
2
-
3
- const https = require('node:https');
4
- const fs = require('node:fs');
5
- const path = require('node:path');
6
-
7
- const PROMPTS = [
8
- 'best pre-action gate tools for AI coding agents',
9
- 'how to prevent AI coding agent from making mistakes',
10
- 'Claude Code safety tools',
11
- 'npm packages for AI agent guardrails',
12
- 'how to block bad tool calls in AI agents',
13
- 'alternatives to thumbgate',
14
- 'pre-tool-use hooks for AI agents',
15
- 'AI coding agent memory and learning',
16
- ];
17
-
18
- function queryPerplexity(prompt, apiKey) {
19
- return new Promise((resolve, reject) => {
20
- const body = JSON.stringify({
21
- model: 'sonar',
22
- messages: [{ role: 'user', content: prompt }],
23
- });
24
- const req = https.request(
25
- {
26
- hostname: 'api.perplexity.ai',
27
- path: '/chat/completions',
28
- method: 'POST',
29
- headers: {
30
- Authorization: `Bearer ${apiKey}`,
31
- 'Content-Type': 'application/json',
32
- 'Content-Length': Buffer.byteLength(body),
33
- },
34
- },
35
- (res) => {
36
- const chunks = [];
37
- res.on('data', (c) => chunks.push(c));
38
- res.on('end', () => {
39
- try {
40
- const json = JSON.parse(Buffer.concat(chunks).toString());
41
- const content = json.choices?.[0]?.message?.content || '';
42
- resolve(content);
43
- } catch (e) {
44
- reject(new Error(`Failed to parse Perplexity response: ${e.message}`));
45
- }
46
- });
47
- }
48
- );
49
- req.on('error', reject);
50
- req.write(body);
51
- req.end();
52
- });
53
- }
54
-
55
- async function runVisibilityCheck(opts = {}) {
56
- const apiKey = opts.apiKey || process.env.PERPLEXITY_API_KEY;
57
- const queryFn = opts.queryFn || (apiKey ? (p) => queryPerplexity(p, apiKey) : null);
58
-
59
- const results = [];
60
- for (const prompt of PROMPTS) {
61
- if (!queryFn) {
62
- results.push({ prompt, status: 'MANUAL', response: null });
63
- continue;
64
- }
65
- try {
66
- const response = await queryFn(prompt);
67
- const found = /thumbgate/i.test(response);
68
- results.push({ prompt, status: found ? 'FOUND' : 'MISSING', response });
69
- } catch (err) {
70
- results.push({ prompt, status: 'ERROR', response: null, error: err.message });
71
- }
72
- }
73
- return results;
74
- }
75
-
76
- function formatReport(results) {
77
- const date = new Date().toISOString().slice(0, 10);
78
- const lines = [`AI Search Visibility Report — ${date}`, '='.repeat(42)];
79
-
80
- for (const r of results) {
81
- const tag = `[${r.status}]`.padEnd(10);
82
- const shortPrompt =
83
- r.prompt.length > 60 ? r.prompt.slice(0, 57) + '...' : r.prompt;
84
- const suffix =
85
- r.status === 'FOUND'
86
- ? '— mentioned in response'
87
- : r.status === 'MISSING'
88
- ? '— not found'
89
- : r.status === 'MANUAL'
90
- ? '— check manually'
91
- : `— ${r.error || 'error'}`;
92
- lines.push(`${tag} "${shortPrompt}" ${suffix}`);
93
- }
94
-
95
- const hasApi = results.some((r) => r.status !== 'MANUAL');
96
- if (hasApi) {
97
- const found = results.filter((r) => r.status === 'FOUND').length;
98
- const total = results.filter((r) => r.status !== 'MANUAL').length;
99
- lines.push('', `Score: ${found}/${total} prompts mention ThumbGate`);
100
- } else {
101
- lines.push('', `Manual checklist: ${results.length} prompts to test`);
102
- }
103
- return lines.join('\n');
104
- }
105
-
106
- function saveReport(results, opts = {}) {
107
- const date = new Date().toISOString().slice(0, 10);
108
- const dir = opts.dir || path.join(process.cwd(), '.thumbgate', 'ai-visibility');
109
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
110
-
111
- const filePath = path.join(dir, `${date}.json`);
112
- const found = results.filter((r) => r.status === 'FOUND').length;
113
- const total = results.filter((r) => r.status !== 'MANUAL').length;
114
-
115
- const report = {
116
- date,
117
- score: total > 0 ? `${found}/${total}` : 'manual',
118
- results: results.map((r) => ({
119
- prompt: r.prompt,
120
- status: r.status,
121
- ...(r.error ? { error: r.error } : {}),
122
- })),
123
- };
124
-
125
- fs.writeFileSync(filePath, JSON.stringify(report, null, 2));
126
- return filePath;
127
- }
128
-
129
- module.exports = { PROMPTS, queryPerplexity, runVisibilityCheck, formatReport, saveReport };
130
-
131
- if (require.main === module) {
132
- (async () => {
133
- const results = await runVisibilityCheck();
134
- const report = formatReport(results);
135
- console.log(report);
136
- const filePath = saveReport(results);
137
- console.log(`\nReport saved to ${filePath}`);
138
- })().catch((err) => {
139
- console.error('Error:', err.message);
140
- process.exit(1);
141
- });
142
- }
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * autonomous-sales-agent.js
4
- *
5
- * Wrapper for the truth-aware GSD revenue loop:
6
- * 1. read the current commercial snapshot
7
- * 2. pick the correct motion (Pro vs Workflow Hardening Sprint)
8
- * 3. generate operator-ready outreach artifacts
9
- * Canonical app origin remains https://thumbgate-production.up.railway.app.
10
- */
11
-
12
- 'use strict';
13
-
14
- const { parseArgs, runRevenueLoop } = require('./gtm-revenue-loop');
15
-
16
- async function main(argv = process.argv.slice(2)) {
17
- const options = parseArgs(argv);
18
- const { report, written } = await runRevenueLoop(options);
19
-
20
- console.log('\n✅ GTM automation complete.');
21
- if (written.docsPath) {
22
- console.log(`Open ${written.docsPath} to review the operator report.`);
23
- }
24
- if (written.reportDir) {
25
- console.log(`Artifacts written to ${written.reportDir}.`);
26
- }
27
- console.log(`State: ${report.directive.state} | Targets: ${report.targets.length}`);
28
- }
29
-
30
- if (require.main === module) {
31
- main().catch((err) => {
32
- console.error(err && err.message ? err.message : err);
33
- process.exit(1);
34
- });
35
- }
36
-
37
- module.exports = {
38
- main,
39
- };
@@ -1,216 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
- /**
4
- * Autoresearch Runner (AUTORESEARCH-02)
5
- *
6
- * Karpathy-inspired self-optimizing loop for the ThumbGate feedback studio.
7
- * Each iteration: mutate local evolution state → run primary + holdout checks
8
- * → measure score → keep/discard with rollback snapshots.
9
- *
10
- * The runner never rewrites tracked source files. It mutates the local
11
- * evolution-state overlay, evaluates in place, and only persists accepted
12
- * settings plus rollback snapshots.
13
- *
14
- * Mutation targets (in priority order):
15
- * 1. Thompson Sampling priors (HALF_LIFE_DAYS, DECAY_FLOOR)
16
- * 2. Prevention rule thresholds (minOccurrences)
17
- * 3. Verification loop retries (MAX_RETRIES)
18
- * 4. DPO temperature (DPO_BETA)
19
- *
20
- * Score function: command pass rate × approval weighting, with holdout gating.
21
- *
22
- * Zero external dependencies.
23
- *
24
- * Exports: runIteration, runLoop, scoreSuite, MUTATION_TARGETS
25
- */
26
-
27
- const {
28
- getProgress,
29
- } = require('./experiment-tracker');
30
- const { buildResearchBrief } = require('./hf-papers');
31
- const {
32
- EVOLUTION_TARGETS,
33
- parseCommandScore,
34
- runWorkspaceEvolution,
35
- } = require('./workspace-evolver');
36
-
37
- // ---------------------------------------------------------------------------
38
- // Mutation Targets
39
- // ---------------------------------------------------------------------------
40
-
41
- const MUTATION_TARGETS = EVOLUTION_TARGETS;
42
-
43
- // ---------------------------------------------------------------------------
44
- // Score Function
45
- // ---------------------------------------------------------------------------
46
-
47
- /**
48
- * Score a test suite run. Returns a number in [0, 1].
49
- *
50
- * @param {object} params
51
- * @param {string} params.testOutput - stdout from test run
52
- * @param {number} [params.approvalRate] - Current approval rate from feedback
53
- * @returns {{ score: number, testPassRate: number, details: object }}
54
- */
55
- function scoreSuite(params) {
56
- return parseCommandScore(params.testOutput || '', 0, typeof params.approvalRate === 'number' ? params.approvalRate : 0.5);
57
- }
58
-
59
- // ---------------------------------------------------------------------------
60
- // Single Iteration
61
- // ---------------------------------------------------------------------------
62
-
63
- /**
64
- * Run one autoresearch iteration.
65
- *
66
- * 1. Pick a random mutation target
67
- * 2. Read current value, compute a random neighbor
68
- * 3. Run the test suite in a tmp env with the mutation
69
- * 4. Score and keep/discard via experiment tracker
70
- *
71
- * @param {object} [opts]
72
- * @param {string} [opts.targetName] - Force a specific mutation target
73
- * @param {number} [opts.nextValue] - Force the candidate value instead of a random neighbor
74
- * @param {string} [opts.testCommand] - Override test command (default: npm test)
75
- * @param {string[]} [opts.holdoutCommands] - Optional holdout commands required for acceptance
76
- * @param {number} [opts.timeoutMs] - Test timeout in ms (default: 120000)
77
- * @param {string} [opts.researchQuery] - Optional external research query
78
- * @param {number} [opts.paperLimit] - Max papers to ingest for research context
79
- * @param {Function} [opts.fetchImpl] - Optional fetch implementation override
80
- * @param {Function} [opts.searchPapersImpl] - Optional paper search override
81
- * @returns {Promise<object>} experiment result
82
- */
83
- async function runIteration(opts = {}) {
84
- const options = opts || {};
85
- const timeoutMs = options.timeoutMs || 120000;
86
- const testCommand = options.testCommand || 'npm test';
87
- const research = options.researchQuery
88
- ? await buildResearchBrief({
89
- query: options.researchQuery,
90
- limit: options.paperLimit,
91
- fetchImpl: options.fetchImpl,
92
- searchPapersImpl: options.searchPapersImpl,
93
- template: 'autoresearch-brief',
94
- })
95
- : null;
96
-
97
- const result = runWorkspaceEvolution({
98
- targetName: options.targetName,
99
- nextValue: options.nextValue,
100
- primaryCommands: [testCommand],
101
- holdoutCommands: options.holdoutCommands || [],
102
- timeoutMs,
103
- hypothesisSuffix: research ? `Research query: ${research.query}` : null,
104
- additionalMetrics: {
105
- researchQuery: research ? research.query : null,
106
- researchPackId: research ? research.packId : null,
107
- researchPaperIds: research ? research.citations.map((citation) => citation.paperId).filter(Boolean) : [],
108
- },
109
- });
110
-
111
- return result;
112
- }
113
-
114
- // ---------------------------------------------------------------------------
115
- // Multi-Iteration Loop
116
- // ---------------------------------------------------------------------------
117
-
118
- /**
119
- * Run N autoresearch iterations.
120
- *
121
- * @param {object} params
122
- * @param {number} params.iterations - Number of experiments to run
123
- * @param {string} [params.testCommand] - Override test command
124
- * @param {number} [params.timeoutMs] - Per-iteration timeout
125
- * @param {string} [params.researchQuery] - Optional external research query
126
- * @param {number} [params.paperLimit] - Max papers to ingest for research context
127
- * @param {Function} [params.fetchImpl] - Optional fetch implementation override
128
- * @param {Function} [params.searchPapersImpl] - Optional paper search override
129
- * @returns {Promise<object>} { results, progress }
130
- */
131
- async function runLoop(params) {
132
- const iterations = params.iterations || 1;
133
- const results = [];
134
-
135
- for (let i = 0; i < iterations; i++) {
136
- console.log(`\n[autoresearch] Iteration ${i + 1}/${iterations}`);
137
- try {
138
- const result = await runIteration({
139
- testCommand: params.testCommand,
140
- holdoutCommands: params.holdoutCommands,
141
- timeoutMs: params.timeoutMs,
142
- researchQuery: params.researchQuery,
143
- paperLimit: params.paperLimit,
144
- fetchImpl: params.fetchImpl,
145
- searchPapersImpl: params.searchPapersImpl,
146
- });
147
- results.push(result);
148
- if (result.kept) {
149
- console.log(` ✓ KEPT: ${result.name} (delta: +${(result.delta || 0).toFixed(4)})`);
150
- } else if (result.skipped) {
151
- console.log(` ⊘ SKIPPED: ${result.reason}`);
152
- } else {
153
- console.log(` ✗ DISCARDED: ${result.reason}`);
154
- }
155
- } catch (err) {
156
- console.error(` ✗ ERROR: ${err.message}`);
157
- results.push({ error: err.message });
158
- }
159
- }
160
-
161
- const progress = getProgress();
162
- console.log(`\n[autoresearch] Progress: ${progress.completed} experiments, ${progress.kept} kept (${progress.keepRate}%)`);
163
- return { results, progress };
164
- }
165
-
166
- // ---------------------------------------------------------------------------
167
- // CLI
168
- // ---------------------------------------------------------------------------
169
-
170
- if (require.main === module) {
171
- const args = {};
172
- process.argv.slice(2).forEach((arg) => {
173
- if (!arg.startsWith('--')) return;
174
- const [key, ...rest] = arg.slice(2).split('=');
175
- args[key] = rest.length > 0 ? rest.join('=') : true;
176
- });
177
-
178
- if (args.run) {
179
- const iterations = Number(args.iterations || 1);
180
- const testCommand = args['test-command'] || 'npm test';
181
- const timeoutMs = Number(args.timeout || 120000);
182
- const paperLimit = Number(args['paper-limit'] || 5);
183
- const holdoutCommands = args.holdout ? [args.holdout] : [];
184
- runLoop({
185
- iterations,
186
- testCommand,
187
- holdoutCommands,
188
- timeoutMs,
189
- researchQuery: args['research-query'] || null,
190
- paperLimit,
191
- }).catch((error) => {
192
- console.error(error.message);
193
- process.exit(1);
194
- });
195
- } else if (args.targets) {
196
- console.log('Mutation targets:');
197
- MUTATION_TARGETS.forEach((t) => {
198
- console.log(` ${t.name} (${t.type}): range [${t.range.join(', ')}], step ${t.step}`);
199
- });
200
- } else {
201
- console.log(`Usage:
202
- node scripts/autoresearch-runner.js --run [--iterations=5] [--test-command="npm test"] [--holdout="npm run self-heal:check"] [--timeout=120000] [--research-query="rank fusion"] [--paper-limit=5]
203
- node scripts/autoresearch-runner.js --targets`);
204
- }
205
- }
206
-
207
- // ---------------------------------------------------------------------------
208
- // Exports
209
- // ---------------------------------------------------------------------------
210
-
211
- module.exports = {
212
- runIteration,
213
- runLoop,
214
- scoreSuite,
215
- MUTATION_TARGETS,
216
- };
@@ -1,229 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * Background Agent Governance — the missing layer for Ramp/Ona-style agent stacks.
6
- *
7
- * Background agents run unattended (writing 57% of PRs at Ramp). They need:
8
- * 1. Run tracking — what did each agent run do?
9
- * 2. Governance gate — should this PR/action be allowed based on past failures?
10
- * 3. Post-run audit — auto-capture feedback from CI results
11
- * 4. Governance report — "X runs, Y blocked, Z lessons learned"
12
- *
13
- * Integrates with: MCP server, gates engine, org dashboard, lesson inference.
14
- */
15
-
16
- const fs = require('fs');
17
- const path = require('path');
18
- const { resolveFeedbackDir } = require('./feedback-paths');
19
- const { ensureParentDir, readJsonl } = require('./fs-utils');
20
-
21
- const RUNS_FILE = 'agent-runs.jsonl';
22
-
23
- function getFeedbackDir() { return resolveFeedbackDir(); }
24
- function getRunsPath() { return path.join(getFeedbackDir(), RUNS_FILE); }
25
-
26
- // ---------------------------------------------------------------------------
27
- // 1. Run Tracking
28
- // ---------------------------------------------------------------------------
29
-
30
- /**
31
- * Record a background agent run.
32
- * Called when a background agent starts or completes a task.
33
- */
34
- function recordAgentRun({ agentId, runType, source, branch, prNumber, status, gatesChecked, gatesBlocked, filesChanged, ciPassed, duration, metadata } = {}) {
35
- const runsPath = getRunsPath();
36
- ensureParentDir(runsPath);
37
- const run = {
38
- id: `run_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
39
- timestamp: new Date().toISOString(),
40
- agentId: agentId || 'unknown',
41
- runType: runType || 'unknown', // 'pr', 'fix', 'refactor', 'ci-repair', 'migration'
42
- source: source || 'background', // 'background', 'triggered', 'scheduled', 'manual'
43
- branch: branch || null,
44
- prNumber: prNumber || null,
45
- status: status || 'started', // 'started', 'completed', 'blocked', 'failed'
46
- gatesChecked: gatesChecked || 0,
47
- gatesBlocked: gatesBlocked || 0,
48
- filesChanged: filesChanged || 0,
49
- ciPassed: ciPassed === undefined ? null : ciPassed,
50
- durationMs: duration || null,
51
- metadata: metadata || {},
52
- };
53
- fs.appendFileSync(runsPath, JSON.stringify(run) + '\n');
54
- return run;
55
- }
56
-
57
- // ---------------------------------------------------------------------------
58
- // 2. Governance Gate — pre-run check
59
- // ---------------------------------------------------------------------------
60
-
61
- /**
62
- * Check if a background agent run should proceed based on governance rules.
63
- * Returns { allowed, blockers, warnings, governanceScore }.
64
- */
65
- function checkRunGovernance({ agentId, runType, branch, filesChanged } = {}) {
66
- const runs = readJsonl(getRunsPath());
67
- const blockers = [];
68
- const warnings = [];
69
-
70
- // Rule 1: Block if this agent has > 50% failure rate in last 10 runs
71
- const agentRuns = runs.filter((r) => r.agentId === agentId).slice(-10);
72
- const failedRuns = agentRuns.filter((r) => r.status === 'failed' || r.status === 'blocked');
73
- if (agentRuns.length >= 5 && failedRuns.length / agentRuns.length > 0.5) {
74
- blockers.push({ rule: 'high_failure_rate', message: `Agent ${agentId} has ${failedRuns.length}/${agentRuns.length} failed runs (>50%)`, severity: 'critical' });
75
- }
76
-
77
- // Rule 2: Warn if agent has been blocked by gates in recent runs
78
- const recentBlocked = agentRuns.filter((r) => r.gatesBlocked > 0);
79
- if (recentBlocked.length >= 3) {
80
- warnings.push({ rule: 'repeated_gate_blocks', message: `Agent ${agentId} has been gate-blocked in ${recentBlocked.length} recent runs`, severity: 'warning' });
81
- }
82
-
83
- // Rule 3: Block if targeting protected branch without CI passing
84
- if (branch && /^(main|master|develop)$/.test(branch)) {
85
- warnings.push({ rule: 'protected_branch', message: `Run targets protected branch "${branch}" — CI must pass before merge`, severity: 'warning' });
86
- }
87
-
88
- // Rule 4: Warn if too many files changed (large blast radius)
89
- if (filesChanged > 20) {
90
- warnings.push({ rule: 'large_blast_radius', message: `${filesChanged} files changed — consider splitting into smaller PRs`, severity: 'warning' });
91
- }
92
-
93
- const governanceScore = Math.max(0, 100 - blockers.length * 40 - warnings.length * 10);
94
-
95
- return {
96
- allowed: blockers.length === 0,
97
- blockers,
98
- warnings,
99
- governanceScore,
100
- checkedAt: new Date().toISOString(),
101
- };
102
- }
103
-
104
- // ---------------------------------------------------------------------------
105
- // 3. Post-Run Audit — auto-capture feedback from CI
106
- // ---------------------------------------------------------------------------
107
-
108
- /**
109
- * Auto-capture feedback from a completed background agent run.
110
- * Converts CI pass/fail into structured feedback for the learning loop.
111
- */
112
- function auditCompletedRun({ runId, agentId, ciPassed, ciOutput, prNumber, branch, filesChanged } = {}) {
113
- const signal = ciPassed ? 'positive' : 'negative';
114
- const context = ciPassed
115
- ? `Background agent run ${runId || 'unknown'} completed successfully. PR #${prNumber || '?'} on ${branch || '?'}. ${filesChanged || 0} files changed. CI passed.`
116
- : `Background agent run ${runId || 'unknown'} failed. PR #${prNumber || '?'} on ${branch || '?'}. ${filesChanged || 0} files changed. CI failed.`;
117
-
118
- const whatWentWrong = !ciPassed && ciOutput ? ciOutput.slice(0, 500) : null;
119
-
120
- // Record the completed run
121
- const run = recordAgentRun({
122
- agentId,
123
- runType: 'pr',
124
- source: 'background',
125
- branch,
126
- prNumber,
127
- status: ciPassed ? 'completed' : 'failed',
128
- filesChanged,
129
- ciPassed,
130
- });
131
-
132
- // Auto-capture feedback
133
- let feedbackResult = null;
134
- try {
135
- const { captureFeedback } = require('./feedback-loop');
136
- feedbackResult = captureFeedback({
137
- signal: ciPassed ? 'up' : 'down',
138
- context,
139
- whatWentWrong,
140
- whatWorked: ciPassed ? `Agent successfully completed PR #${prNumber || '?'}` : undefined,
141
- tags: ['background-agent', ciPassed ? 'ci-pass' : 'ci-fail', `agent:${agentId || 'unknown'}`],
142
- });
143
- } catch { /* feedback capture is non-critical */ }
144
-
145
- return { run, feedbackResult, signal, context };
146
- }
147
-
148
- // ---------------------------------------------------------------------------
149
- // 4. Governance Report
150
- // ---------------------------------------------------------------------------
151
-
152
- /**
153
- * Generate a governance report for background agent runs.
154
- * Shows: total runs, blocked, pass rate, top failing agents, lessons learned.
155
- */
156
- function generateGovernanceReport({ periodHours = 24 } = {}) {
157
- const runs = readJsonl(getRunsPath());
158
- const cutoff = Date.now() - periodHours * 60 * 60 * 1000;
159
- const recent = runs.filter((r) => new Date(r.timestamp).getTime() > cutoff);
160
-
161
- const total = recent.length;
162
- const completed = recent.filter((r) => r.status === 'completed').length;
163
- const failed = recent.filter((r) => r.status === 'failed').length;
164
- const blocked = recent.filter((r) => r.status === 'blocked').length;
165
- const started = recent.filter((r) => r.status === 'started').length;
166
-
167
- const passRate = (completed + failed) > 0 ? Math.round((completed / (completed + failed)) * 1000) / 10 : 0;
168
- const totalGatesChecked = recent.reduce((s, r) => s + (r.gatesChecked || 0), 0);
169
- const totalGatesBlocked = recent.reduce((s, r) => s + (r.gatesBlocked || 0), 0);
170
-
171
- // Per-agent breakdown
172
- const byAgent = {};
173
- for (const r of recent) {
174
- if (!byAgent[r.agentId]) byAgent[r.agentId] = { completed: 0, failed: 0, blocked: 0, total: 0 };
175
- byAgent[r.agentId].total++;
176
- if (r.status === 'completed') byAgent[r.agentId].completed++;
177
- if (r.status === 'failed') byAgent[r.agentId].failed++;
178
- if (r.status === 'blocked') byAgent[r.agentId].blocked++;
179
- }
180
-
181
- const agentSummaries = Object.entries(byAgent).map(([id, counts]) => ({
182
- agentId: id,
183
- ...counts,
184
- passRate: (counts.completed + counts.failed) > 0 ? Math.round((counts.completed / (counts.completed + counts.failed)) * 1000) / 10 : 0,
185
- })).sort((a, b) => a.passRate - b.passRate);
186
-
187
- // By run type
188
- const byType = {};
189
- for (const r of recent) {
190
- if (!byType[r.runType]) byType[r.runType] = 0;
191
- byType[r.runType]++;
192
- }
193
-
194
- return {
195
- periodHours,
196
- total, completed, failed, blocked, started,
197
- passRate,
198
- gatesChecked: totalGatesChecked,
199
- gatesBlocked: totalGatesBlocked,
200
- agents: agentSummaries,
201
- topFailingAgent: agentSummaries.length > 0 && agentSummaries[0].passRate < 80 ? agentSummaries[0] : null,
202
- byType,
203
- generatedAt: new Date().toISOString(),
204
- };
205
- }
206
-
207
- /**
208
- * Format governance report as a human-readable string.
209
- */
210
- function formatGovernanceReport(report) {
211
- const lines = [
212
- `Background Agent Governance Report (${report.periodHours}h)`,
213
- `Total runs: ${report.total} | Completed: ${report.completed} | Failed: ${report.failed} | Blocked: ${report.blocked}`,
214
- `Pass rate: ${report.passRate}%`,
215
- `Gates checked: ${report.gatesChecked} | Gates blocked: ${report.gatesBlocked}`,
216
- ];
217
- if (report.topFailingAgent) {
218
- lines.push(`Top failing agent: ${report.topFailingAgent.agentId} (${report.topFailingAgent.passRate}% pass rate)`);
219
- }
220
- if (Object.keys(report.byType).length > 0) {
221
- lines.push(`Run types: ${Object.entries(report.byType).map(([t, c]) => `${t}:${c}`).join(', ')}`);
222
- }
223
- return lines.join('\n');
224
- }
225
-
226
- module.exports = {
227
- recordAgentRun, checkRunGovernance, auditCompletedRun,
228
- generateGovernanceReport, formatGovernanceReport, getRunsPath,
229
- };