thumbgate 1.3.0 → 1.4.1

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 (156) hide show
  1. package/.claude-plugin/README.md +25 -0
  2. package/.claude-plugin/marketplace.json +32 -13
  3. package/.claude-plugin/plugin.json +15 -2
  4. package/.well-known/llms.txt +60 -0
  5. package/.well-known/mcp/server-card.json +1 -1
  6. package/README.md +242 -126
  7. package/adapters/README.md +1 -1
  8. package/adapters/chatgpt/INSTALL.md +59 -4
  9. package/adapters/chatgpt/openapi.yaml +168 -0
  10. package/adapters/claude/.mcp.json +2 -2
  11. package/adapters/codex/config.toml +2 -2
  12. package/adapters/mcp/server-stdio.js +84 -1
  13. package/adapters/opencode/opencode.json +1 -1
  14. package/bin/cli.js +204 -13
  15. package/bin/postinstall.js +8 -2
  16. package/config/budget.json +18 -0
  17. package/config/gates/code-edit.json +61 -0
  18. package/config/gates/db-write.json +61 -0
  19. package/config/gates/default.json +154 -3
  20. package/config/gates/deploy.json +61 -0
  21. package/config/github-about.json +2 -1
  22. package/config/merge-quality-checks.json +23 -0
  23. package/openapi/openapi.yaml +168 -0
  24. package/package.json +47 -11
  25. package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +1 -1
  26. package/plugins/claude-codex-bridge/.mcp.json +1 -1
  27. package/plugins/claude-codex-bridge/scripts/codex-bridge.js +1 -3
  28. package/plugins/codex-profile/.codex-plugin/plugin.json +1 -1
  29. package/plugins/codex-profile/.mcp.json +1 -1
  30. package/plugins/codex-profile/INSTALL.md +27 -4
  31. package/plugins/codex-profile/README.md +33 -9
  32. package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +1 -1
  33. package/plugins/opencode-profile/INSTALL.md +1 -1
  34. package/public/blog.html +73 -0
  35. package/public/compare/mem0.html +189 -0
  36. package/public/compare/speclock.html +180 -0
  37. package/public/compare.html +10 -2
  38. package/public/guide.html +2 -2
  39. package/public/guides/claude-code-prevent-repeated-mistakes.html +161 -0
  40. package/public/guides/codex-cli-guardrails.html +158 -0
  41. package/public/guides/cursor-prevent-repeated-mistakes.html +161 -0
  42. package/public/guides/pre-action-gates.html +162 -0
  43. package/public/guides/stop-repeated-ai-agent-mistakes.html +159 -0
  44. package/public/index.html +172 -65
  45. package/public/lessons.html +33 -24
  46. package/public/llm-context.md +140 -0
  47. package/public/pro.html +24 -22
  48. package/scripts/access-anomaly-detector.js +1 -1
  49. package/scripts/adk-consolidator.js +1 -5
  50. package/scripts/agent-security-hardening.js +4 -6
  51. package/scripts/agentic-data-pipeline.js +1 -3
  52. package/scripts/async-job-runner.js +1 -5
  53. package/scripts/audit-trail.js +1 -5
  54. package/scripts/auto-promote-gates.js +5 -3
  55. package/scripts/background-agent-governance.js +2 -10
  56. package/scripts/billing-setup.js +109 -0
  57. package/scripts/billing.js +2 -16
  58. package/scripts/budget-enforcer.js +173 -0
  59. package/scripts/build-claude-mcpb.js +71 -5
  60. package/scripts/build-codex-plugin.js +152 -0
  61. package/scripts/check-congruence.js +132 -14
  62. package/scripts/commercial-offer.js +5 -7
  63. package/scripts/content-engine/linkedin-content-generator.js +154 -0
  64. package/scripts/content-engine/output/linkedin-memento-validation.md +17 -0
  65. package/scripts/content-engine/output/linkedin-posts-2026-04-09.md +175 -0
  66. package/scripts/content-engine/reddit-thread-finder.js +154 -0
  67. package/scripts/context-engine.js +21 -6
  68. package/scripts/contextfs.js +1 -21
  69. package/scripts/dashboard.js +20 -0
  70. package/scripts/decision-journal.js +341 -0
  71. package/scripts/delegation-runtime.js +1 -5
  72. package/scripts/distribution-surfaces.js +54 -0
  73. package/scripts/document-intake.js +927 -0
  74. package/scripts/ephemeral-agent-store.js +1 -8
  75. package/scripts/evolution-state.js +1 -5
  76. package/scripts/experiment-tracker.js +1 -5
  77. package/scripts/export-databricks-bundle.js +1 -5
  78. package/scripts/export-hf-dataset.js +1 -5
  79. package/scripts/export-training.js +1 -5
  80. package/scripts/feedback-attribution.js +1 -16
  81. package/scripts/feedback-history-distiller.js +1 -16
  82. package/scripts/feedback-loop.js +1 -5
  83. package/scripts/feedback-root-consolidator.js +2 -21
  84. package/scripts/feedback-session.js +49 -0
  85. package/scripts/feedback-to-rules.js +215 -36
  86. package/scripts/filesystem-search.js +1 -9
  87. package/scripts/fs-utils.js +104 -0
  88. package/scripts/gates-engine.js +200 -11
  89. package/scripts/github-about.js +32 -8
  90. package/scripts/gtm-revenue-loop.js +1 -5
  91. package/scripts/harness-selector.js +148 -0
  92. package/scripts/hosted-config.js +2 -0
  93. package/scripts/hosted-job-launcher.js +1 -5
  94. package/scripts/hybrid-feedback-context.js +33 -49
  95. package/scripts/intervention-policy.js +58 -1
  96. package/scripts/lesson-db.js +3 -18
  97. package/scripts/lesson-inference.js +194 -16
  98. package/scripts/lesson-retrieval.js +60 -24
  99. package/scripts/llm-client.js +59 -0
  100. package/scripts/managed-lesson-agent.js +183 -0
  101. package/scripts/marketing-experiment.js +8 -22
  102. package/scripts/meta-agent-loop.js +624 -0
  103. package/scripts/metered-billing.js +1 -1
  104. package/scripts/money-watcher.js +1 -4
  105. package/scripts/obsidian-export.js +1 -5
  106. package/scripts/operational-integrity.js +15 -3
  107. package/scripts/operational-summary.js +41 -5
  108. package/scripts/org-dashboard.js +6 -1
  109. package/scripts/per-step-scoring.js +2 -4
  110. package/scripts/pr-manager.js +201 -19
  111. package/scripts/pro-features.js +3 -2
  112. package/scripts/prompt-dlp.js +3 -3
  113. package/scripts/prove-adapters.js +1 -5
  114. package/scripts/prove-attribution.js +1 -5
  115. package/scripts/prove-automation.js +1 -3
  116. package/scripts/prove-cloudflare-sandbox.js +1 -3
  117. package/scripts/prove-data-pipeline.js +1 -3
  118. package/scripts/prove-intelligence.js +1 -3
  119. package/scripts/prove-lancedb.js +1 -5
  120. package/scripts/prove-local-intelligence.js +1 -3
  121. package/scripts/prove-packaged-runtime.js +75 -9
  122. package/scripts/prove-predictive-insights.js +1 -3
  123. package/scripts/prove-training-export.js +1 -3
  124. package/scripts/prove-workflow-contract.js +1 -5
  125. package/scripts/ralph-loop.js +376 -0
  126. package/scripts/ralph-mode-ci.js +331 -0
  127. package/scripts/rate-limiter.js +3 -1
  128. package/scripts/reddit-dm-outreach.js +14 -4
  129. package/scripts/rotate-stripe-webhook-secret.js +314 -0
  130. package/scripts/schedule-manager.js +3 -5
  131. package/scripts/security-scanner.js +448 -0
  132. package/scripts/self-distill-agent.js +579 -0
  133. package/scripts/semantic-dedup.js +115 -0
  134. package/scripts/skill-exporter.js +1 -3
  135. package/scripts/skill-generator.js +1 -5
  136. package/scripts/social-analytics/engagement-audit.js +1 -18
  137. package/scripts/social-analytics/pollers/linkedin.js +26 -16
  138. package/scripts/social-analytics/publishers/linkedin.js +1 -1
  139. package/scripts/social-analytics/publishers/zernio.js +51 -0
  140. package/scripts/social-pipeline.js +1 -3
  141. package/scripts/social-post-hourly.js +47 -4
  142. package/scripts/statusline-links.js +6 -5
  143. package/scripts/statusline.sh +29 -153
  144. package/scripts/sync-branch-protection.js +340 -0
  145. package/scripts/tessl-export.js +1 -3
  146. package/scripts/thumbgate-search.js +32 -1
  147. package/scripts/tool-kpi-tracker.js +1 -1
  148. package/scripts/tool-registry.js +106 -2
  149. package/scripts/vector-store.js +1 -5
  150. package/scripts/weekly-auto-post.js +1 -1
  151. package/scripts/workflow-sentinel.js +91 -0
  152. package/skills/thumbgate/SKILL.md +1 -1
  153. package/src/api/server.js +296 -7
  154. package/scripts/__pycache__/train_from_feedback.cpython-312.pyc +0 -0
  155. package/scripts/social-analytics/db/social-analytics.db-shm +0 -0
  156. /package/scripts/social-analytics/db/{social-analytics.db-wal → analytics.sqlite} +0 -0
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const https = require('node:https');
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+ const { spawnSync } = require('node:child_process');
8
+
9
+ const DEFAULT_ENDPOINT_URL = 'https://thumbgate-production.up.railway.app/v1/billing/webhook';
10
+ const REQUIRED_EVENTS = ['checkout.session.completed', 'customer.subscription.deleted'];
11
+ const FIXED_GH_BINARIES = ['/usr/bin/gh', '/usr/local/bin/gh', '/opt/homebrew/bin/gh'];
12
+ const SECRET_PATTERN = /\b(?:sk|rk)_(?:live|test)_\w+|\bwhsec_\w+/g;
13
+
14
+ function redact(value) {
15
+ return String(value || '').replaceAll(SECRET_PATTERN, '[REDACTED]');
16
+ }
17
+
18
+ function encodeForm(params) {
19
+ const pairs = [];
20
+ for (const [key, value] of Object.entries(params || {})) {
21
+ if (Array.isArray(value)) {
22
+ for (const item of value) {
23
+ const arrayKey = `${key}[]`;
24
+ pairs.push(`${encodeURIComponent(arrayKey)}=${encodeURIComponent(String(item))}`);
25
+ }
26
+ continue;
27
+ }
28
+ if (value !== undefined && value !== null) {
29
+ pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
30
+ }
31
+ }
32
+ return pairs.join('&');
33
+ }
34
+
35
+ function assertLiveStripeKey(apiKey, requireLive = true) {
36
+ if (!apiKey) {
37
+ throw new Error('STRIPE_SECRET_KEY is required.');
38
+ }
39
+ if (requireLive && !/^(sk|rk)_live_/.test(apiKey)) {
40
+ throw new Error('Refusing to rotate production webhook with a non-live Stripe key.');
41
+ }
42
+ }
43
+
44
+ function stripeRequest({ method = 'GET', path, apiKey, body, request = https.request }) {
45
+ return new Promise((resolve, reject) => {
46
+ const payload = body ? encodeForm(body) : '';
47
+ const req = request({
48
+ hostname: 'api.stripe.com',
49
+ path,
50
+ method,
51
+ headers: {
52
+ Authorization: `Bearer ${apiKey}`,
53
+ 'Content-Type': 'application/x-www-form-urlencoded',
54
+ 'Content-Length': Buffer.byteLength(payload),
55
+ },
56
+ }, (res) => {
57
+ let raw = '';
58
+ res.setEncoding('utf8');
59
+ res.on('data', (chunk) => { raw += chunk; });
60
+ res.on('end', () => {
61
+ let parsed = {};
62
+ try {
63
+ parsed = raw ? JSON.parse(raw) : {};
64
+ } catch {
65
+ reject(new Error(`Stripe returned non-JSON response (${res.statusCode}): ${redact(raw)}`));
66
+ return;
67
+ }
68
+ if (res.statusCode < 200 || res.statusCode >= 300) {
69
+ const message = parsed.error?.message ? parsed.error.message : raw;
70
+ reject(new Error(`Stripe API ${method} ${path} failed (${res.statusCode}): ${redact(message)}`));
71
+ return;
72
+ }
73
+ resolve(parsed);
74
+ });
75
+ });
76
+ req.on('error', reject);
77
+ req.end(payload);
78
+ });
79
+ }
80
+
81
+ async function listWebhookEndpoints(apiKey, options = {}) {
82
+ const requestStripe = options.stripeRequest || stripeRequest;
83
+ const endpoints = [];
84
+ let startingAfter = '';
85
+ for (;;) {
86
+ const suffix = startingAfter
87
+ ? `&starting_after=${encodeURIComponent(startingAfter)}`
88
+ : '';
89
+ const response = await requestStripe({
90
+ apiKey,
91
+ path: `/v1/webhook_endpoints?limit=100${suffix}`,
92
+ });
93
+ endpoints.push(...(Array.isArray(response.data) ? response.data : []));
94
+ if (!response.has_more || endpoints.length === 0) {
95
+ return endpoints;
96
+ }
97
+ startingAfter = endpoints.at(-1).id;
98
+ }
99
+ }
100
+
101
+ async function createWebhookEndpoint({ apiKey, endpointUrl, timestamp, stripeRequest: requestStripe = stripeRequest }) {
102
+ const endpoint = await requestStripe({
103
+ method: 'POST',
104
+ path: '/v1/webhook_endpoints',
105
+ apiKey,
106
+ body: {
107
+ url: endpointUrl,
108
+ enabled_events: REQUIRED_EVENTS,
109
+ description: `ThumbGate billing webhook rotated ${timestamp}`,
110
+ },
111
+ });
112
+ if (!endpoint.id || !endpoint.secret) {
113
+ throw new Error('Stripe webhook endpoint creation did not return both id and signing secret.');
114
+ }
115
+ return endpoint;
116
+ }
117
+
118
+ async function disableWebhookEndpoint({ apiKey, endpointId, stripeRequest: requestStripe = stripeRequest }) {
119
+ return requestStripe({
120
+ method: 'POST',
121
+ path: `/v1/webhook_endpoints/${encodeURIComponent(endpointId)}`,
122
+ apiKey,
123
+ body: { disabled: true },
124
+ });
125
+ }
126
+
127
+ function resolveGhBinary(options = {}) {
128
+ const accessSync = options.accessSync || fs.accessSync;
129
+ const candidates = options.candidates || FIXED_GH_BINARIES;
130
+
131
+ for (const candidate of candidates) {
132
+ try {
133
+ accessSync(candidate, fs.constants.X_OK);
134
+ return candidate;
135
+ } catch {
136
+ // Try the next fixed, system-owned path.
137
+ }
138
+ }
139
+
140
+ throw new Error(`Unable to locate GH CLI in fixed paths: ${candidates.join(', ')}`);
141
+ }
142
+
143
+ function runGh(args, { token, input, ghBinary, accessSync, spawnSyncImpl = spawnSync } = {}) {
144
+ const result = spawnSyncImpl(ghBinary || resolveGhBinary({ accessSync }), args, {
145
+ input,
146
+ encoding: 'utf8',
147
+ env: {
148
+ ...process.env,
149
+ GH_TOKEN: token || process.env.GH_TOKEN || process.env.GITHUB_TOKEN || '',
150
+ },
151
+ });
152
+ if (result.status !== 0) {
153
+ throw new Error(`gh ${args.join(' ')} failed: ${redact(result.stderr || result.stdout)}`);
154
+ }
155
+ return result.stdout.trim();
156
+ }
157
+
158
+ function getSecretUpdatedAt({ repo, token, secretName, runner = runGh }) {
159
+ return runner([
160
+ 'api',
161
+ `repos/${repo}/actions/secrets/${secretName}`,
162
+ '--jq',
163
+ '.updated_at',
164
+ ], { token });
165
+ }
166
+
167
+ function setGithubSecret({ repo, token, name, value, runner = runGh }) {
168
+ runner(['secret', 'set', name, '--repo', repo], { token, input: value });
169
+ }
170
+
171
+ function setGithubVariable({ repo, token, name, value, runner = runGh }) {
172
+ runner(['variable', 'set', name, '--repo', repo, '--body', value], { token });
173
+ }
174
+
175
+ function findSameUrlEndpoints(endpoints, endpointUrl, excludeId) {
176
+ return endpoints.filter((endpoint) => endpoint?.id
177
+ && endpoint.id !== excludeId
178
+ && endpoint?.url === endpointUrl
179
+ && endpoint?.status !== 'disabled');
180
+ }
181
+
182
+ function resolveRequireLiveStripeKey(options) {
183
+ if (Object.hasOwn(options, 'requireLive')) {
184
+ return options.requireLive;
185
+ }
186
+ const envModes = {
187
+ false: false,
188
+ true: true,
189
+ };
190
+ return envModes[process.env.REQUIRE_LIVE_STRIPE_KEY] ?? true;
191
+ }
192
+
193
+ async function rotateStripeWebhookSecret(options = {}) {
194
+ const endpointUrl = options.endpointUrl || process.env.STRIPE_WEBHOOK_ENDPOINT_URL || DEFAULT_ENDPOINT_URL;
195
+ const repo = Object.hasOwn(options, 'repo') ? options.repo : process.env.GITHUB_REPOSITORY;
196
+ const stripeKey = options.stripeKey || process.env.STRIPE_SECRET_KEY;
197
+ const githubToken = options.githubToken || process.env.GH_ADMIN_TOKEN || process.env.THUMBGATE_MAINTENANCE_GH_TOKEN;
198
+ const timestamp = options.timestamp || new Date().toISOString();
199
+ const requireLive = resolveRequireLiveStripeKey(options);
200
+ const dryRun = options.dryRun === true || process.env.DRY_RUN === 'true';
201
+ const stripe = {
202
+ listWebhookEndpoints: options.listWebhookEndpoints || listWebhookEndpoints,
203
+ createWebhookEndpoint: options.createWebhookEndpoint || createWebhookEndpoint,
204
+ disableWebhookEndpoint: options.disableWebhookEndpoint || disableWebhookEndpoint,
205
+ };
206
+ const github = {
207
+ getSecretUpdatedAt: options.getSecretUpdatedAt || getSecretUpdatedAt,
208
+ setGithubSecret: options.setGithubSecret || setGithubSecret,
209
+ setGithubVariable: options.setGithubVariable || setGithubVariable,
210
+ };
211
+
212
+ assertLiveStripeKey(stripeKey, requireLive);
213
+ if (!repo) {
214
+ throw new Error('GITHUB_REPOSITORY is required.');
215
+ }
216
+ if (dryRun || githubToken) {
217
+ // Dry runs only need Stripe read access; real rotations also need GitHub secret write access.
218
+ } else {
219
+ throw new Error('THUMBGATE_MAINTENANCE_GH_TOKEN is required to update GitHub Secrets and Variables.');
220
+ }
221
+
222
+ const before = await stripe.listWebhookEndpoints(stripeKey);
223
+ const replacementCandidates = findSameUrlEndpoints(before, endpointUrl);
224
+ if (dryRun) {
225
+ return {
226
+ dryRun: true,
227
+ endpointUrl,
228
+ matchingEnabledEndpoints: replacementCandidates.map((endpoint) => endpoint.id),
229
+ requiredEvents: REQUIRED_EVENTS,
230
+ };
231
+ }
232
+
233
+ const endpoint = await stripe.createWebhookEndpoint({ apiKey: stripeKey, endpointUrl, timestamp });
234
+ github.setGithubSecret({
235
+ repo,
236
+ token: githubToken,
237
+ name: 'STRIPE_WEBHOOK_SECRET',
238
+ value: endpoint.secret,
239
+ });
240
+ github.setGithubVariable({
241
+ repo,
242
+ token: githubToken,
243
+ name: 'STRIPE_WEBHOOK_SECRET_ROTATED_AT',
244
+ value: timestamp,
245
+ });
246
+
247
+ const stripeSecretUpdatedAt = github.getSecretUpdatedAt({
248
+ repo,
249
+ token: githubToken,
250
+ secretName: 'STRIPE_SECRET_KEY',
251
+ });
252
+ if (stripeSecretUpdatedAt) {
253
+ github.setGithubVariable({
254
+ repo,
255
+ token: githubToken,
256
+ name: 'STRIPE_SECRET_KEY_ROTATED_AT',
257
+ value: stripeSecretUpdatedAt,
258
+ });
259
+ }
260
+
261
+ const disabledEndpointIds = [];
262
+ for (const oldEndpoint of findSameUrlEndpoints(before, endpointUrl, endpoint.id)) {
263
+ await stripe.disableWebhookEndpoint({ apiKey: stripeKey, endpointId: oldEndpoint.id });
264
+ disabledEndpointIds.push(oldEndpoint.id);
265
+ }
266
+
267
+ return {
268
+ dryRun: false,
269
+ endpointUrl,
270
+ newEndpointId: endpoint.id,
271
+ disabledEndpointIds,
272
+ requiredEvents: REQUIRED_EVENTS,
273
+ rotatedAt: timestamp,
274
+ stripeSecretKeyRotatedAt: stripeSecretUpdatedAt || null,
275
+ };
276
+ }
277
+
278
+ async function main() {
279
+ try {
280
+ const result = await rotateStripeWebhookSecret();
281
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
282
+ } catch (err) {
283
+ process.stderr.write(`${redact(err?.message ? err.message : err)}\n`);
284
+ process.exit(1);
285
+ }
286
+ }
287
+
288
+ function isCliInvocation(argv = process.argv) {
289
+ return path.resolve(argv[1] || '') === __filename;
290
+ }
291
+
292
+ if (isCliInvocation()) {
293
+ main();
294
+ }
295
+
296
+ module.exports = {
297
+ DEFAULT_ENDPOINT_URL,
298
+ REQUIRED_EVENTS,
299
+ assertLiveStripeKey,
300
+ createWebhookEndpoint,
301
+ disableWebhookEndpoint,
302
+ encodeForm,
303
+ findSameUrlEndpoints,
304
+ getSecretUpdatedAt,
305
+ listWebhookEndpoints,
306
+ redact,
307
+ resolveGhBinary,
308
+ resolveRequireLiveStripeKey,
309
+ rotateStripeWebhookSecret,
310
+ runGh,
311
+ setGithubSecret,
312
+ setGithubVariable,
313
+ stripeRequest,
314
+ };
@@ -6,13 +6,11 @@ const path = require('path');
6
6
  const os = require('os');
7
7
  const { execSync } = require('child_process');
8
8
  const { buildAgenticDataPipelineJobSpec } = require('./agentic-data-pipeline');
9
+ const { ensureDir } = require('./fs-utils');
9
10
 
10
11
  const SCHEDULES_DIR = path.join(os.homedir(), '.thumbgate', 'schedules');
11
12
  const PLIST_PREFIX = 'com.thumbgate.schedule';
12
13
 
13
- function ensureDir() {
14
- if (!fs.existsSync(SCHEDULES_DIR)) fs.mkdirSync(SCHEDULES_DIR, { recursive: true });
15
- }
16
14
 
17
15
  function escapePlistString(value) {
18
16
  return String(value || '')
@@ -153,7 +151,7 @@ function buildAgenticDataPipelineSchedule(params = {}) {
153
151
  }
154
152
 
155
153
  function createSchedule(params) {
156
- ensureDir();
154
+ ensureDir(SCHEDULES_DIR);
157
155
 
158
156
  const id = params.id || params.name || `sched_${Date.now()}`;
159
157
  const calendarInterval = parseCronSpec(params.schedule);
@@ -214,7 +212,7 @@ function createSchedule(params) {
214
212
  }
215
213
 
216
214
  function listSchedules() {
217
- ensureDir();
215
+ ensureDir(SCHEDULES_DIR);
218
216
  const files = fs.readdirSync(SCHEDULES_DIR).filter(f => f.endsWith('.json'));
219
217
  return files.map(f => {
220
218
  try {