thumbgate 1.39.1 → 1.40.2

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 (199) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.well-known/llms.txt +2 -2
  3. package/.well-known/mcp/server-card.json +1 -1
  4. package/README.md +5 -4
  5. package/adapters/claude/.mcp.json +6 -2
  6. package/adapters/codex/config.toml +5 -0
  7. package/adapters/forge/forge.yaml +4 -4
  8. package/adapters/future-agi/.mcp.json +1 -1
  9. package/adapters/future-agi/config.toml +1 -1
  10. package/adapters/future-agi/opencode.json +1 -1
  11. package/adapters/herdr/herdr-plugin.toml +2 -2
  12. package/adapters/mcp/server-stdio.js +82 -7
  13. package/adapters/opencode/opencode.json +1 -1
  14. package/bin/cli.js +128 -15
  15. package/config/brand-standards.json +131 -0
  16. package/config/gates/default.json +18 -1
  17. package/config/github-about.json +1 -1
  18. package/config/mcp-allowlists.json +16 -3
  19. package/config/merge-quality-checks.json +1 -0
  20. package/config/post-deploy-marketing-pages.json +3 -3
  21. package/config/schemas/task-outcome-receipt.schema.json +9 -0
  22. package/openapi/openapi.yaml +7 -3
  23. package/package.json +98 -31
  24. package/public/about.html +2 -2
  25. package/public/admin.html +771 -0
  26. package/public/agent-manager.html +3 -3
  27. package/public/agents-cost-savings.html +1 -1
  28. package/public/ai-malpractice-prevention.html +12 -12
  29. package/public/architecture.html +0 -1
  30. package/public/assets/diagrams/decision.svg +3 -3
  31. package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
  32. package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
  33. package/public/blog/git-at-agent-scale.html +2 -2
  34. package/public/blog/inside-your-boundary.html +1 -1
  35. package/public/blog/process-over-outcome-gates.html +1 -1
  36. package/public/case-studies.html +1 -2
  37. package/public/codex-enterprise.html +1 -1
  38. package/public/codex-plugin.html +1 -1
  39. package/public/dashboard.html +773 -481
  40. package/public/diagnostic.html +8 -3
  41. package/public/enterprise-governance.html +26 -174
  42. package/public/eval-scorecard.html +3 -4
  43. package/public/eval-scorecard.json +2 -2
  44. package/public/evaluations.html +0 -1
  45. package/public/founders.html +3 -3
  46. package/public/gaming-playbook.html +4 -4
  47. package/public/guide.html +3 -5
  48. package/public/index.html +181 -205
  49. package/public/install.html +12 -11
  50. package/public/js/buyer-intent.js +49 -8
  51. package/public/lessons.html +103 -46
  52. package/public/numbers.html +32 -33
  53. package/public/operator-framework.html +44 -72
  54. package/public/peter.html +3 -3
  55. package/public/platform-partners.html +1 -1
  56. package/public/pricing.html +61 -327
  57. package/public/pro.html +3 -1
  58. package/public/project-switcher.js +76 -0
  59. package/public/whitepaper.html +1 -2
  60. package/scripts/activation-quickstart.js +15 -3
  61. package/scripts/activation-tracker.js +280 -3
  62. package/scripts/agent-action-inventory.js +235 -143
  63. package/scripts/agent-operations-planner.js +1 -1
  64. package/scripts/agent-readiness.js +36 -6
  65. package/scripts/agentic-prompt-pipelines.js +901 -0
  66. package/scripts/analytics-report.js +363 -0
  67. package/scripts/analytics-window.js +7 -1
  68. package/scripts/async-job-runner.js +66 -11
  69. package/scripts/audit-trail.js +37 -24
  70. package/scripts/auto-context-packs.js +249 -0
  71. package/scripts/auto-promote-gates.js +37 -27
  72. package/scripts/backfill-lesson-scopes.js +122 -0
  73. package/scripts/billing-setup.js +137 -0
  74. package/scripts/billing.js +889 -132
  75. package/scripts/bot-detection.js +112 -0
  76. package/scripts/brand-standards-gate.js +571 -0
  77. package/scripts/chatgpt-ads-readiness-pack.js +1 -1
  78. package/scripts/check-update.js +236 -0
  79. package/scripts/cli-schema.js +1 -1
  80. package/scripts/commercial-offer.js +2 -2
  81. package/scripts/contextfs.js +9 -3
  82. package/scripts/conversion-rate-stats.js +442 -0
  83. package/scripts/cost-cli.js +147 -0
  84. package/scripts/creator-campaigns.js +239 -0
  85. package/scripts/cross-encoder-reranker.js +4 -0
  86. package/scripts/cuda-gate-batch.js +560 -0
  87. package/scripts/daemon-manager.js +108 -0
  88. package/scripts/dashboard-chat.js +11 -0
  89. package/scripts/dashboard.js +576 -169
  90. package/scripts/decision-journal.js +7 -4
  91. package/scripts/delegation-runtime.js +1036 -0
  92. package/scripts/dispatch-brief.js +159 -0
  93. package/scripts/distribution-surfaces.js +110 -0
  94. package/scripts/docker-sandbox-planner.js +3 -3
  95. package/scripts/egm-goldfish-packet.js +95 -0
  96. package/scripts/embeddinggemma-adapter.js +407 -0
  97. package/scripts/export-dpo-pairs.js +12 -7
  98. package/scripts/feedback-aggregate.js +4 -0
  99. package/scripts/feedback-attribution.js +6 -4
  100. package/scripts/feedback-history-distiller.js +18 -6
  101. package/scripts/feedback-loop.js +255 -89
  102. package/scripts/feedback-paths.js +8 -1
  103. package/scripts/feedback-sanitizer.js +5 -0
  104. package/scripts/feedback-scope.js +106 -0
  105. package/scripts/feedback-session.js +8 -2
  106. package/scripts/filesystem-search.js +13 -8
  107. package/scripts/financial-control-plane.js +707 -45
  108. package/scripts/funnel-analytics.js +35 -0
  109. package/scripts/gate-semantic-layer.js +292 -0
  110. package/scripts/gate-stats.js +8 -2
  111. package/scripts/gates-engine.js +694 -230
  112. package/scripts/generate-eval-scorecard.js +0 -1
  113. package/scripts/harness-tool-names.js +31 -5
  114. package/scripts/hybrid-feedback-context.js +5 -2
  115. package/scripts/implementation-notes.js +241 -0
  116. package/scripts/intent-router.js +518 -0
  117. package/scripts/intervention-policy.js +2 -1
  118. package/scripts/latency-budget.js +164 -0
  119. package/scripts/lesson-canonical.js +2 -2
  120. package/scripts/lesson-db.js +55 -14
  121. package/scripts/lesson-graph.js +2 -1
  122. package/scripts/lesson-retrieval.js +95 -9
  123. package/scripts/lesson-search.js +86 -22
  124. package/scripts/lesson-synthesis.js +21 -5
  125. package/scripts/mailer/index.js +17 -1
  126. package/scripts/mailer/resend-mailer.js +213 -179
  127. package/scripts/mcp-writeguard.js +158 -0
  128. package/scripts/migrate-project-scope.js +209 -0
  129. package/scripts/model-candidates.js +414 -0
  130. package/scripts/openrouter-armor-partnership-diode.js +2419 -0
  131. package/scripts/operational-dashboard.js +172 -0
  132. package/scripts/operational-integrity.js +436 -3
  133. package/scripts/operational-summary.js +190 -0
  134. package/scripts/operator-artifacts.js +622 -0
  135. package/scripts/optimize-context.js +17 -0
  136. package/scripts/override-audit.js +2 -0
  137. package/scripts/owner-admin.js +338 -0
  138. package/scripts/pr-manager.js +194 -1
  139. package/scripts/predictive-insights.js +449 -0
  140. package/scripts/profound-aeo-citation-engine.js +583 -0
  141. package/scripts/progressive-signoff.js +260 -0
  142. package/scripts/project-catalog.js +243 -0
  143. package/scripts/project-dashboard.js +61 -0
  144. package/scripts/project-evidence.js +172 -0
  145. package/scripts/project-identity.js +182 -0
  146. package/scripts/project-scope.js +381 -0
  147. package/scripts/prompt-guard.js +446 -52
  148. package/scripts/proof-report.js +232 -0
  149. package/scripts/provider-action-normalizer.js +14 -6
  150. package/scripts/pulse.js +80 -0
  151. package/scripts/rate-limiter.js +41 -0
  152. package/scripts/rrsi-doctor.js +2698 -0
  153. package/scripts/secret-redaction.js +171 -25
  154. package/scripts/secret-scanner.js +101 -42
  155. package/scripts/self-protection.js +2 -2
  156. package/scripts/seo-gsd.js +14 -14
  157. package/scripts/session-context-dedupe.js +66 -0
  158. package/scripts/session-report.js +120 -0
  159. package/scripts/settings-hierarchy.js +4 -2
  160. package/scripts/statusline-meta.js +34 -23
  161. package/scripts/subagent-profiles.js +79 -0
  162. package/scripts/task-outcomes.js +29 -2
  163. package/scripts/telemetry-analytics.js +238 -13
  164. package/scripts/third-author-cli.js +118 -0
  165. package/scripts/third-author-governance.js +437 -0
  166. package/scripts/thumbgate-dream.js +878 -0
  167. package/scripts/thumbgate-search.js +23 -9
  168. package/scripts/tool-kpi-tracker.js +5 -2
  169. package/scripts/tool-registry.js +42 -1
  170. package/scripts/triage-savings-calculator.js +1 -1
  171. package/scripts/vector-store.js +4 -1
  172. package/scripts/verified-lessons.js +270 -0
  173. package/scripts/verify-marketing-pages-deployed.js +2 -2
  174. package/scripts/workflow-sentinel.js +29 -10
  175. package/server.json +2 -2
  176. package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
  177. package/src/api/server.js +2371 -451
  178. package/src/feedback.js +21 -0
  179. package/src/hermes-sync-plane.js +2 -1
  180. package/src/index.js +2 -0
  181. package/src/lesson-search.js +9 -0
  182. package/src/mckinsey-top-company-ai-coding.js +493 -0
  183. package/src/mcp/server.js +3 -0
  184. package/src/mcp-writeguard.js +772 -11
  185. package/src/openshell-lovable-engine.js +1475 -0
  186. package/src/task-outcome.js +3 -0
  187. package/config/evals/agent-safety-eval.json +0 -447
  188. package/config/evals/retrieval-ranking-golden.json +0 -522
  189. package/config/progressive/01-wire-only.json +0 -11
  190. package/config/progressive/02-dashboard-empty-ok.json +0 -10
  191. package/config/progressive/03-one-lesson.json +0 -10
  192. package/config/progressive/04-warn-fires.json +0 -11
  193. package/config/progressive/05-strict-optional.json +0 -11
  194. package/config/progressive/README.md +0 -15
  195. package/public/assets/diagrams/agent-integration.png +0 -0
  196. package/public/assets/diagrams/thumbgate-architecture.png +0 -0
  197. package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
  198. package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
  199. package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
@@ -1,461 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * thumbgate-daily-discoveries-publish.js
6
- *
7
- * Daily autonomous publishing engine for ThumbGate news and technical discoveries.
8
- * Scheduled to run once per day at 9:00 AM EST via crontab / launchd.
9
- *
10
- * Capabilities:
11
- * 1. Harvests latest technical discoveries (git innovations, format steals, pre-action rules).
12
- * 2. Pulls live metrics (active gates, prevented failures, adherence rate).
13
- * 3. Formats an in-depth, SEO-optimized technical post with code snippets and architecture notes.
14
- * 4. Enforces full UTM attribution and /go/:slug tracked redirect links for revenue observability.
15
- * 5. Generates public canonical HTML page under public/blog/ ensuring valid canonical target.
16
- * 6. Coordinates fleet lease before writing to shared Obsidian Vault.
17
- * 7. Acquires atomic run lock to prevent duplicate execution across cron and launchd.
18
- * 8. Dispatches to Dev.to with canonical_url, holding ambiguous attempts until their outcome is reconciled.
19
- * 9. Records idempotent receipts to .thumbgate/daily-discoveries-ledger.jsonl.
20
- *
21
- * Usage:
22
- * node scripts/thumbgate-daily-discoveries-publish.js --dry-run
23
- * node scripts/thumbgate-daily-discoveries-publish.js --json
24
- * node scripts/thumbgate-daily-discoveries-publish.js --force
25
- */
26
-
27
- const fs = require('node:fs');
28
- const path = require('node:path');
29
- const { execSync } = require('node:child_process');
30
- const { buildUTMLink } = require('./social-analytics/utm');
31
-
32
- const REPO_ROOT = path.resolve(process.env.THUMBGATE_PUBLISH_ROOT || path.join(__dirname, '..'));
33
- const MARKETING_DIR = path.join(REPO_ROOT, 'docs', 'marketing', 'daily-discoveries');
34
- const PUBLIC_BLOG_DIR = path.join(REPO_ROOT, 'public', 'blog');
35
- const LEDGER_PATH = path.join(REPO_ROOT, '.thumbgate', 'daily-discoveries-ledger.jsonl');
36
- const LOCK_PATH = path.join(REPO_ROOT, '.thumbgate', 'daily-discoveries.lock');
37
- const VAULT_DIR = process.env.VAULT_DIR || path.join(process.env.HOME || '', 'Documents', 'Igor');
38
-
39
- const CURATED_TOPICS = require('./daily-discoveries-topics.json');
40
-
41
- function getFormattedDate(date = new Date()) {
42
- const yyyy = date.getFullYear();
43
- const mm = String(date.getMonth() + 1).padStart(2, '0');
44
- const dd = String(date.getDate()).padStart(2, '0');
45
- return `${yyyy}-${mm}-${dd}`;
46
- }
47
-
48
- function selectTopicForDay(date = new Date()) {
49
- const startOfYear = new Date(date.getFullYear(), 0, 1);
50
- const dayOfYear = Math.floor((date - startOfYear) / (24 * 60 * 60 * 1000));
51
- const index = Math.abs(dayOfYear % CURATED_TOPICS.length);
52
- return CURATED_TOPICS[index];
53
- }
54
-
55
- function getRecentGitCommit() {
56
- const gitBin = fs.existsSync('/usr/bin/git') ? '/usr/bin/git' : 'git';
57
- try {
58
- const log = execSync(`${gitBin} log -1 --format="%h - %s" origin/main 2>/dev/null || ${gitBin} log -1 --format="%h - %s"`, {
59
- cwd: REPO_ROOT,
60
- encoding: 'utf8',
61
- }).trim();
62
- return log;
63
- } catch {
64
- // Staging outside a Git checkout still produces a usable draft.
65
- return 'Tip of main';
66
- }
67
- }
68
-
69
- function generatePostContent(topic, dateStr, gitCommit) {
70
- const campaign = 'daily_technical_discoveries';
71
- const source = 'daily_discoveries';
72
- const medium = 'article';
73
- const contentId = topic.slug;
74
-
75
- const siteUrl = buildUTMLink('https://thumbgate.ai', { source, medium, campaign, content: contentId });
76
- const proUrl = buildUTMLink('https://thumbgate.ai/go/pro', { source, medium, campaign, content: contentId });
77
- const docsUrl = buildUTMLink('https://thumbgate.ai/docs', { source, medium, campaign, content: contentId });
78
- const githubUrl = buildUTMLink('https://github.com/IgorGanapolsky/ThumbGate', { source, medium, campaign, content: contentId });
79
- const canonicalUrl = `https://thumbgate.ai/blog/${dateStr}-${topic.slug}`;
80
-
81
- return `# ${topic.title}
82
-
83
- > **ThumbGate Engineering Daily** | ${dateStr}
84
- > *Author:* Igor Ganapolsky ([@IgorGanapolsky](https://github.com/IgorGanapolsky))
85
- > *Verified on Commit:* \`${gitCommit}\`
86
- > *Canonical URL:* \`${canonicalUrl}\`
87
-
88
- ---
89
-
90
- ## Executive Summary
91
-
92
- ${topic.tagline}
93
-
94
- Autonomous AI coding agents are rapidly moving from conversational prototypes to multi-tool execution engines with file system access, terminal execution, and external API integrations. However, without pre-action safety guarantees, agents remain vulnerable to untrusted context manipulation, hallucinated actions, and cascading production errors.
95
-
96
- At **[ThumbGate](${siteUrl})**, we treat agent reliability not as a prompting exercise, but as an infrastructure firewall. Here is our latest technical discovery and implementation pattern from production.
97
-
98
- ---
99
-
100
- ## The Failure Mode
101
-
102
- ${topic.problem}
103
-
104
- When an agentic system relies purely on instructions:
105
- - Malicious or malformed inputs blend directly into execution context.
106
- - System prompt instructions degrade as context windows expand.
107
- - Execution boundaries blur between what the agent *reads* and what the agent *executes*.
108
-
109
- ---
110
-
111
- ## Architectural Resolution
112
-
113
- ${topic.solution}
114
-
115
- ### Enforcement Code Pattern
116
-
117
- \`\`\`javascript
118
- ${topic.codeSnippet}
119
- \`\`\`
120
-
121
- By enforcing this check in the **PreToolUse** hook lifecycle, the agent runtime intercepts and validates commands in under 5ms, long before any shell or network call can execute.
122
-
123
- ---
124
-
125
- ## Key Engineering Takeaways
126
-
127
- 1. **Deterministic Over Heuristic:** Safety boundaries must execute as deterministic code gates rather than polite LLM suggestions.
128
- 2. **Attributed Observability:** Every blocked action produces an idempotent outcome receipt with verifiable execution evidence.
129
- 3. **Continuous Learning:** Thumbs-up/down signals feed directly into local lesson stores, generating progressive prevention rules over time.
130
-
131
- ---
132
-
133
- ## Learn More & Try ThumbGate
134
-
135
- - **GitHub Repository (Open Source):** [ThumbGate GitHub](${githubUrl})
136
- - **Production Platform:** [ThumbGate Infrastructure Firewall](${siteUrl})
137
- - **Try ThumbGate Pro:** [Upgrade & Access Live Gates](${proUrl})
138
- - **Documentation & MCP Integration:** [ThumbGate Docs](${docsUrl})
139
- `;
140
- }
141
-
142
- function renderBlogHtml(topic, dateStr, markdownContent) {
143
- const slug = `${dateStr}-${topic.slug}`;
144
- const title = String(topic.title || '').replaceAll('"', '"');
145
- const tagline = String(topic.tagline || '').replaceAll('"', '"');
146
- const canonicalUrl = `https://thumbgate.ai/blog/${slug}`;
147
-
148
- return `<!DOCTYPE html>
149
- <html lang="en">
150
- <head>
151
- <meta charset="UTF-8">
152
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
153
- <title>${title} | ThumbGate</title>
154
- <link rel="canonical" href="${canonicalUrl}">
155
- <meta name="description" content="${tagline}">
156
- <meta property="og:title" content="${title}">
157
- <meta property="og:description" content="${tagline}">
158
- <meta property="og:url" content="${canonicalUrl}">
159
- <link rel="stylesheet" href="/style.css">
160
- </head>
161
- <body class="blog-post-page">
162
- <main class="container">
163
- <article class="post-content">
164
- <h1>${topic.title}</h1>
165
- <p class="post-meta">Published on ${dateStr} by Igor Ganapolsky</p>
166
- <section class="post-body">
167
- <p class="lead">${topic.tagline}</p>
168
- <h2>The Failure Mode</h2>
169
- <p>${topic.problem}</p>
170
- <h2>Architectural Resolution</h2>
171
- <p>${topic.solution}</p>
172
- <pre><code>${String(topic.codeSnippet || '').replaceAll('<', '&lt;').replaceAll('>', '&gt;')}</code></pre>
173
- </section>
174
- <footer class="post-footer">
175
- <a href="https://thumbgate.ai/go/pro?utm_source=blog&utm_medium=article&utm_campaign=${slug}" class="cta-btn">Upgrade to ThumbGate Pro</a>
176
- </footer>
177
- </article>
178
- </main>
179
- </body>
180
- </html>`;
181
- }
182
-
183
- function acquireRunLock() {
184
- fs.mkdirSync(path.dirname(LOCK_PATH), { recursive: true });
185
- try {
186
- const fd = fs.openSync(LOCK_PATH, 'wx');
187
- fs.writeFileSync(fd, `${process.pid}\n`, 'utf8');
188
- fs.closeSync(fd);
189
- return true;
190
- } catch (err) {
191
- if (err.code === 'EEXIST') {
192
- try {
193
- const stats = fs.statSync(LOCK_PATH);
194
- // Stale lock reclamation (> 30m)
195
- if (Date.now() - stats.mtimeMs > 30 * 60 * 1000) {
196
- fs.unlinkSync(LOCK_PATH);
197
- return acquireRunLock();
198
- }
199
- } catch {
200
- // A changed or unreadable lock cannot grant this process ownership.
201
- }
202
- return false;
203
- }
204
- return false;
205
- }
206
- }
207
-
208
- function releaseRunLock() {
209
- try {
210
- if (fs.existsSync(LOCK_PATH)) {
211
- fs.unlinkSync(LOCK_PATH);
212
- }
213
- } catch {
214
- // Keep an unreleasable lock in place so later runs remain blocked.
215
- }
216
- }
217
-
218
- function canWriteToSharedVault(vaultDir) {
219
- if (!fs.existsSync(vaultDir)) return false;
220
- const claimsDir = path.join(vaultDir, 'Agents', 'Claims');
221
- const runningJobsDir = path.join(vaultDir, 'Agent-Jobs', 'running');
222
- for (const dir of [claimsDir, runningJobsDir]) {
223
- if (fs.existsSync(dir)) {
224
- try {
225
- const entries = fs.readdirSync(dir);
226
- for (const entry of entries) {
227
- if (entry.toLowerCase().includes('daily-discoveries')) {
228
- return false;
229
- }
230
- }
231
- } catch {
232
- // Unreadable coordination claims cannot authorize a vault write.
233
- return false;
234
- }
235
- }
236
- }
237
- return true;
238
- }
239
-
240
- function hasPublicationReceipt(receipt) {
241
- if (!receipt || !Number.isSafeInteger(receipt.id) || receipt.id <= 0 || typeof receipt.url !== 'string') return false;
242
- try {
243
- const url = new URL(receipt.url);
244
- return url.protocol === 'https:' && url.hostname === 'dev.to' && url.pathname !== '/';
245
- } catch {
246
- // Invalid URLs cannot serve as proof of remote publication.
247
- return false;
248
- }
249
- }
250
-
251
- function getPublicationStatus(dateStr) {
252
- if (!fs.existsSync(LEDGER_PATH)) return null;
253
- let status = null;
254
- const lines = fs.readFileSync(LEDGER_PATH, 'utf8').trim().split('\n');
255
- for (const line of lines) {
256
- let item;
257
- try {
258
- item = JSON.parse(line);
259
- } catch {
260
- continue;
261
- }
262
- if (!item || item.date !== dateStr) continue;
263
- if (item.status === 'publication_unknown') status = 'publication_unknown';
264
- if (item.status === 'published' && hasPublicationReceipt(item.devto)) status = 'published';
265
- }
266
- return status;
267
- }
268
-
269
- function hasAlreadyPublishedToday(dateStr) {
270
- return getPublicationStatus(dateStr) === 'published';
271
- }
272
-
273
- function recordLedgerEntry(entry) {
274
- fs.mkdirSync(path.dirname(LEDGER_PATH), { recursive: true });
275
- fs.appendFileSync(LEDGER_PATH, JSON.stringify(entry) + '\n', 'utf8');
276
- }
277
-
278
- async function runDailyPublish(options = {}) {
279
- const now = new Date();
280
- const dateStr = getFormattedDate(now);
281
- const dryRun = options.dryRun === true;
282
- const force = options.force === true;
283
- const topic = selectTopicForDay(now);
284
- const gitCommit = getRecentGitCommit();
285
- const content = generatePostContent(topic, dateStr, gitCommit);
286
- const canonicalUrl = `https://thumbgate.ai/blog/${dateStr}-${topic.slug}`;
287
-
288
- const filename = `${dateStr}-${topic.slug}.md`;
289
- const stagedPath = path.join(MARKETING_DIR, filename);
290
- const publicBlogHtmlPath = path.join(PUBLIC_BLOG_DIR, `${dateStr}-${topic.slug}.html`);
291
-
292
- const outputs = [];
293
-
294
- if (dryRun) {
295
- return {
296
- status: 'dry_run_preview',
297
- date: dateStr,
298
- topic: topic.slug,
299
- title: topic.title,
300
- commit: gitCommit,
301
- canonicalUrl,
302
- stagedPath,
303
- dryRun: true,
304
- previewSnippet: content.slice(0, 300) + '...',
305
- };
306
- }
307
-
308
- // Acquire atomic process lock to prevent duplicate runs
309
- if (!acquireRunLock()) {
310
- return {
311
- status: 'locked',
312
- reason: 'Another daily publish process holds the active run lock. Skipping duplicate execution.',
313
- date: dateStr,
314
- };
315
- }
316
-
317
- try {
318
- const publicationStatus = getPublicationStatus(dateStr);
319
- if (publicationStatus === 'publication_unknown') {
320
- return {
321
- status: 'publication_unknown',
322
- reason: 'A prior Dev.to attempt has an unknown outcome. Reconcile its remote publication before retrying; --force cannot override this hold.',
323
- date: dateStr,
324
- canonicalUrl,
325
- };
326
- }
327
- if (!force && publicationStatus === 'published') {
328
- return {
329
- status: 'skipped',
330
- reason: `Already published daily discovery for ${dateStr}. Use --force to override.`,
331
- date: dateStr,
332
- };
333
- }
334
-
335
- // 1. Stage local marketing markdown
336
- fs.mkdirSync(MARKETING_DIR, { recursive: true });
337
- fs.writeFileSync(stagedPath, content, 'utf8');
338
- outputs.push({ type: 'local_file', path: stagedPath });
339
-
340
- // 2. Generate public canonical HTML page
341
- fs.mkdirSync(PUBLIC_BLOG_DIR, { recursive: true });
342
- fs.writeFileSync(publicBlogHtmlPath, renderBlogHtml(topic, dateStr, content), 'utf8');
343
- outputs.push({ type: 'public_html', path: publicBlogHtmlPath });
344
-
345
- // 3. Sync to Obsidian Vault if present and safe
346
- const vaultDiscoveryDir = path.join(VAULT_DIR, 'Research', 'Daily-Discoveries');
347
- if (fs.existsSync(VAULT_DIR)) {
348
- if (canWriteToSharedVault(VAULT_DIR)) {
349
- fs.mkdirSync(vaultDiscoveryDir, { recursive: true });
350
- const vaultPath = path.join(vaultDiscoveryDir, filename);
351
- fs.writeFileSync(vaultPath, content, 'utf8');
352
- outputs.push({ type: 'obsidian_vault', path: vaultPath });
353
- } else {
354
- outputs.push({ type: 'obsidian_vault_skipped', reason: 'Active foreign vault claim detected.' });
355
- }
356
- }
357
-
358
- // 4. Attempt Dev.to publish if API key is present
359
- let devtoResult = null;
360
- if (process.env.DEVTO_API_KEY) {
361
- const { publishArticle } = require('./social-analytics/publishers/devto');
362
- recordLedgerEntry({
363
- date: dateStr,
364
- topic: topic.slug,
365
- title: topic.title,
366
- status: 'publication_unknown',
367
- attemptedAt: now.toISOString(),
368
- canonicalUrl,
369
- outputs,
370
- devto: null,
371
- reason: 'Dev.to publication attempt started. Reconcile the remote outcome if no confirmed receipt follows.',
372
- });
373
- const res = await publishArticle({
374
- title: topic.title,
375
- body_markdown: content,
376
- tags: topic.tags,
377
- published: true,
378
- canonical_url: canonicalUrl,
379
- });
380
- if (!hasPublicationReceipt(res)) {
381
- const reason = 'Dev.to accepted the request without a valid publication receipt. Reconcile the remote outcome before retrying.';
382
- return { status: 'publication_unknown', reason, date: dateStr, canonicalUrl, stagedPath, publicBlogHtmlPath, dryRun: false };
383
- }
384
- devtoResult = { id: res.id, url: res.url };
385
- outputs.push({ type: 'devto', url: res.url });
386
- }
387
-
388
- const status = devtoResult ? 'published' : 'staged';
389
- recordLedgerEntry({
390
- date: dateStr,
391
- topic: topic.slug,
392
- title: topic.title,
393
- status,
394
- ...(devtoResult ? { publishedAt: now.toISOString() } : { stagedAt: now.toISOString() }),
395
- canonicalUrl,
396
- outputs,
397
- devto: devtoResult,
398
- });
399
-
400
- return {
401
- status,
402
- date: dateStr,
403
- topic: topic.slug,
404
- title: topic.title,
405
- commit: gitCommit,
406
- canonicalUrl,
407
- stagedPath,
408
- publicBlogHtmlPath,
409
- dryRun: false,
410
- };
411
- } finally {
412
- releaseRunLock();
413
- }
414
- }
415
-
416
- async function main() {
417
- const args = new Set(process.argv.slice(2));
418
- const dryRun = args.has('--dry-run');
419
- const json = args.has('--json');
420
- const force = args.has('--force');
421
-
422
- try {
423
- const result = await runDailyPublish({ dryRun, force });
424
- if (json) {
425
- process.stdout.write(JSON.stringify(result, null, 2) + '\n');
426
- } else {
427
- console.log(`[ThumbGate Daily Discoveries] Status: ${result.status}`);
428
- console.log(` Topic: ${result.title}`);
429
- console.log(` Date: ${result.date}`);
430
- if (result.canonicalUrl) console.log(` Canonical URL: ${result.canonicalUrl}`);
431
- if (result.stagedPath) console.log(` Staged: ${result.stagedPath}`);
432
- if (dryRun) {
433
- console.log('\n--- Preview ---');
434
- console.log(result.previewSnippet);
435
- }
436
- }
437
- } catch (err) {
438
- console.error(`[ThumbGate Daily Discoveries] Error: ${err.message}`);
439
- process.exit(1);
440
- }
441
- }
442
-
443
- if (require.main === module) {
444
- void main();
445
- }
446
-
447
- module.exports = {
448
- selectTopicForDay,
449
- generatePostContent,
450
- renderBlogHtml,
451
- runDailyPublish,
452
- buildUTMLink,
453
- getFormattedDate,
454
- acquireRunLock,
455
- releaseRunLock,
456
- canWriteToSharedVault,
457
- hasAlreadyPublishedToday,
458
- getRecentGitCommit,
459
- recordLedgerEntry,
460
- CURATED_TOPICS,
461
- };
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env bash
2
- # thumbgate-daily-discoveries-publish.sh
3
- # Automated daily publishing of ThumbGate news & technical discoveries.
4
- # Invoked daily at 9:00 AM EST via crontab / launchd.
5
-
6
- set -euo pipefail
7
-
8
- export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
9
-
10
- REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
11
- cd "$REPO_DIR"
12
-
13
- echo "=== [$(date -u +"%Y-%m-%dT%H:%M:%SZ")] ThumbGate Daily Publishing Started ==="
14
-
15
- # Execute node publishing script
16
- node scripts/thumbgate-daily-discoveries-publish.js "$@"
17
-
18
- echo "=== [$(date -u +"%Y-%m-%dT%H:%M:%SZ")] ThumbGate Daily Publishing Completed ==="