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
@@ -0,0 +1,771 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <meta name="robots" content="noindex,nofollow" />
7
+ <title>Owner console · ThumbGate</title>
8
+ <style nonce="__ADMIN_NONCE__">
9
+ :root {
10
+ color-scheme: dark;
11
+ --bg: #0c1017;
12
+ --panel: #141b26;
13
+ --line: #2b3749;
14
+ --ink: #edf2f8;
15
+ --muted: #a4b4c9;
16
+ --accent: #a3e8ce;
17
+ --warn: #ffd18a;
18
+ }
19
+ * {
20
+ box-sizing: border-box;
21
+ }
22
+ body {
23
+ margin: 0;
24
+ background: var(--bg);
25
+ color: var(--ink);
26
+ font:
27
+ 15px/1.6 system-ui,
28
+ sans-serif;
29
+ }
30
+ header,
31
+ main,
32
+ footer {
33
+ max-width: 1400px;
34
+ margin: auto;
35
+ padding: 24px 32px;
36
+ }
37
+ header {
38
+ display: flex;
39
+ justify-content: space-between;
40
+ align-items: center;
41
+ border-bottom: 1px solid var(--line);
42
+ gap: 16px;
43
+ }
44
+ h1 {
45
+ margin: 0;
46
+ font-size: 28px;
47
+ letter-spacing: -0.04em;
48
+ }
49
+ h2 {
50
+ margin: 0 0 8px;
51
+ font-size: 20px;
52
+ }
53
+ p {
54
+ margin: 8px 0;
55
+ }
56
+ .eyebrow {
57
+ font-size: 11px;
58
+ letter-spacing: 0.16em;
59
+ text-transform: uppercase;
60
+ color: var(--accent);
61
+ }
62
+ .muted,
63
+ small {
64
+ color: var(--muted);
65
+ }
66
+ a {
67
+ color: var(--accent);
68
+ }
69
+ button,
70
+ a.button {
71
+ font: inherit;
72
+ border: 1px solid var(--line);
73
+ background: var(--panel);
74
+ color: var(--ink);
75
+ border-radius: 8px;
76
+ padding: 9px 14px;
77
+ cursor: pointer;
78
+ text-decoration: none;
79
+ display: inline-block;
80
+ }
81
+ button:hover,
82
+ a.button:hover {
83
+ border-color: var(--accent);
84
+ }
85
+ button:focus-visible,
86
+ a:focus-visible {
87
+ outline: 3px solid var(--accent);
88
+ outline-offset: 3px;
89
+ }
90
+ button:disabled {
91
+ opacity: 0.5;
92
+ cursor: wait;
93
+ }
94
+ nav {
95
+ display: flex;
96
+ flex-wrap: wrap;
97
+ gap: 8px;
98
+ margin-bottom: 24px;
99
+ }
100
+ nav button[aria-current='true'] {
101
+ background: var(--accent);
102
+ color: var(--bg);
103
+ }
104
+ .panel {
105
+ background: var(--panel);
106
+ border: 1px solid var(--line);
107
+ border-radius: 14px;
108
+ padding: 24px;
109
+ margin-bottom: 20px;
110
+ }
111
+ .row {
112
+ display: flex;
113
+ align-items: center;
114
+ justify-content: space-between;
115
+ gap: 12px;
116
+ flex-wrap: wrap;
117
+ }
118
+ .cards {
119
+ display: grid;
120
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
121
+ gap: 14px;
122
+ margin: 20px 0;
123
+ }
124
+ .card {
125
+ padding: 18px;
126
+ background: var(--bg);
127
+ border: 1px solid var(--line);
128
+ border-radius: 10px;
129
+ }
130
+ .value {
131
+ font-size: 26px;
132
+ letter-spacing: -0.03em;
133
+ font-weight: 600;
134
+ overflow-wrap: anywhere;
135
+ }
136
+ .label {
137
+ font-size: 12px;
138
+ color: var(--muted);
139
+ }
140
+ .status {
141
+ border-radius: 99px;
142
+ padding: 3px 10px;
143
+ border: 1px solid var(--line);
144
+ font-size: 12px;
145
+ }
146
+ .status.partial,
147
+ .status.unavailable {
148
+ color: var(--warn);
149
+ }
150
+ .table-wrap {
151
+ overflow: auto;
152
+ margin: 18px 0;
153
+ }
154
+ table {
155
+ border-collapse: collapse;
156
+ width: 100%;
157
+ font-size: 13px;
158
+ text-align: left;
159
+ }
160
+ th,
161
+ td {
162
+ padding: 12px 10px;
163
+ border-bottom: 1px solid var(--line);
164
+ vertical-align: top;
165
+ overflow-wrap: anywhere;
166
+ max-width: 340px;
167
+ }
168
+ th {
169
+ font-size: 11px;
170
+ letter-spacing: 0.06em;
171
+ text-transform: uppercase;
172
+ color: var(--muted);
173
+ }
174
+ code {
175
+ font-size: 12px;
176
+ white-space: normal;
177
+ overflow-wrap: anywhere;
178
+ }
179
+ ul {
180
+ padding-left: 20px;
181
+ }
182
+ .notice {
183
+ padding: 14px;
184
+ border-left: 3px solid var(--warn);
185
+ background: #201d18;
186
+ }
187
+ .empty {
188
+ padding: 36px;
189
+ text-align: center;
190
+ color: var(--muted);
191
+ }
192
+ footer {
193
+ border-top: 1px solid var(--line);
194
+ font-size: 12px;
195
+ color: var(--muted);
196
+ }
197
+ [hidden] {
198
+ display: none !important;
199
+ }
200
+ @media (max-width: 640px) {
201
+ header,
202
+ main,
203
+ footer {
204
+ padding: 20px 16px;
205
+ }
206
+ .panel {
207
+ padding: 18px;
208
+ }
209
+ h1 {
210
+ font-size: 23px;
211
+ }
212
+ .cards {
213
+ grid-template-columns: 1fr 1fr;
214
+ }
215
+ }
216
+ </style>
217
+ </head>
218
+ <body>
219
+ <header>
220
+ <div>
221
+ <div class="eyebrow">ThumbGate / private</div>
222
+ <h1>Owner console</h1>
223
+ <p class="muted">Read-only business and runtime visibility.</p>
224
+ </div>
225
+ <div>
226
+ <a
227
+ class="button"
228
+ href="https://dashboard.stripe.com/"
229
+ target="_blank"
230
+ rel="noopener noreferrer"
231
+ >Open Stripe ↗</a
232
+ >
233
+ <button id="logout" type="button">Sign out</button>
234
+ </div>
235
+ </header>
236
+ <main>
237
+ <nav aria-label="Admin sections" id="sections"></nav>
238
+ <div id="content" aria-live="polite"></div>
239
+ </main>
240
+ <footer>
241
+ Customer data stays in this private view. Payments are charge records.
242
+ External booked revenue excludes identified internal and test purchases;
243
+ unknown identities remain excluded. Deployment time is only shown when
244
+ known.
245
+ </footer>
246
+ <script nonce="__ADMIN_NONCE__">
247
+ 'use strict';
248
+ const content = document.getElementById('content');
249
+ const sections = [
250
+ 'overview',
251
+ 'stripe',
252
+ 'data',
253
+ 'analytics',
254
+ 'observability',
255
+ ];
256
+ const titles = {
257
+ overview: 'Overview',
258
+ stripe: 'Stripe records',
259
+ data: 'Hosted data',
260
+ analytics: 'Analytics',
261
+ observability: 'Observability',
262
+ };
263
+ let current = 'overview';
264
+ let resource = 'customers';
265
+ let subscriptionId = null;
266
+ let nextCursor = null;
267
+ let activeLoad = 0;
268
+ function element(tag, text, className) {
269
+ const el = document.createElement(tag);
270
+ if (text !== undefined) el.textContent = String(text);
271
+ if (className) el.className = className;
272
+ return el;
273
+ }
274
+ function label(value) {
275
+ return String(value)
276
+ .replace(/([a-z])([A-Z])/g, '$1 $2')
277
+ .replaceAll('_', ' ');
278
+ }
279
+ function date(value) {
280
+ if (!value) return 'Unknown';
281
+ const d = new Date(typeof value === 'number' ? value * 1000 : value);
282
+ return Number.isNaN(d.getTime()) ? 'Unknown' : d.toLocaleString();
283
+ }
284
+ function money(value, currency) {
285
+ if (!Number.isSafeInteger(value) || !/^[a-z]{3}$/i.test(currency || ''))
286
+ return 'Unknown';
287
+ const code = currency.toUpperCase();
288
+ // Stripe charge exponents differ from Intl defaults for ISK, UGX and MGA.
289
+ // https://docs.stripe.com/currencies#special-cases
290
+ const zero = [
291
+ 'BIF',
292
+ 'CLP',
293
+ 'DJF',
294
+ 'GNF',
295
+ 'JPY',
296
+ 'KMF',
297
+ 'KRW',
298
+ 'MGA',
299
+ 'PYG',
300
+ 'RWF',
301
+ 'VND',
302
+ 'VUV',
303
+ 'XAF',
304
+ 'XOF',
305
+ 'XPF',
306
+ ];
307
+ const three = ['BHD', 'JOD', 'KWD', 'OMR', 'TND'];
308
+ const exponent = zero.includes(code) ? 0 : three.includes(code) ? 3 : 2;
309
+ const displayDigits = ['ISK', 'UGX'].includes(code) ? 0 : exponent;
310
+ return new Intl.NumberFormat(undefined, {
311
+ style: 'currency',
312
+ currency: code,
313
+ minimumFractionDigits: displayDigits,
314
+ maximumFractionDigits: displayDigits,
315
+ }).format(value / 10 ** exponent);
316
+ }
317
+ function recurringInterval(recurring) {
318
+ if (!recurring) return 'One-time';
319
+ const count =
320
+ Number.isInteger(recurring.interval_count) &&
321
+ recurring.interval_count > 0
322
+ ? recurring.interval_count
323
+ : 1;
324
+ const interval = recurring.interval || 'unknown interval';
325
+ return count === 1
326
+ ? 'Every ' + interval
327
+ : 'Every ' + count + ' ' + interval + 's';
328
+ }
329
+ function subscriptionItemsButton(record) {
330
+ const button = element('button', 'View all prices');
331
+ button.type = 'button';
332
+ button.addEventListener('click', () => {
333
+ resource = 'subscription-items';
334
+ subscriptionId = record.id;
335
+ load();
336
+ });
337
+ return button;
338
+ }
339
+ function cards(parent, values) {
340
+ const grid = element('div', undefined, 'cards');
341
+ for (const [key, value] of Object.entries(values)) {
342
+ const card = element('div', undefined, 'card');
343
+ card.append(
344
+ element(
345
+ 'div',
346
+ value === null || value === undefined ? 'Unknown' : value,
347
+ 'value',
348
+ ),
349
+ element('div', label(key), 'label'),
350
+ );
351
+ grid.append(card);
352
+ }
353
+ parent.append(grid);
354
+ }
355
+ function table(parent, columns, records) {
356
+ if (!records.length) {
357
+ parent.append(element('p', 'No records in this source.', 'empty'));
358
+ return;
359
+ }
360
+ const wrap = element('div', undefined, 'table-wrap');
361
+ const t = element('table');
362
+ const head = element('thead');
363
+ const row = element('tr');
364
+ columns.forEach(([name]) => row.append(element('th', name)));
365
+ head.append(row);
366
+ t.append(head);
367
+ const body = element('tbody');
368
+ for (const record of records) {
369
+ const tr = element('tr');
370
+ for (const [, read] of columns) {
371
+ const cell = element('td');
372
+ const value = read(record);
373
+ if (value instanceof Node) cell.append(value);
374
+ else cell.textContent = String(value ?? 'Unknown');
375
+ tr.append(cell);
376
+ }
377
+ body.append(tr);
378
+ }
379
+ t.append(body);
380
+ wrap.append(t);
381
+ parent.append(wrap);
382
+ }
383
+ function detail(parent, title, value) {
384
+ const block = element('details');
385
+ block.append(element('summary', title));
386
+ const rows = Object.entries(value || {}).map(([key, val]) => ({
387
+ key: label(key),
388
+ value: typeof val === 'object' ? JSON.stringify(val) : val,
389
+ }));
390
+ table(
391
+ block,
392
+ [
393
+ ['Metric', (r) => r.key],
394
+ ['Value', (r) => r.value],
395
+ ],
396
+ rows,
397
+ );
398
+ parent.append(block);
399
+ }
400
+ function count(v) {
401
+ return v?.total === null || v?.total === undefined
402
+ ? 'Unknown'
403
+ : String(v.total) + (v.complete ? '' : ' (partial)');
404
+ }
405
+ function render(parent, section, data) {
406
+ if (section === 'overview') {
407
+ cards(parent, {
408
+ version: data.health?.version,
409
+ build: data.health?.buildSha,
410
+ uptimeSeconds: Math.floor(data.health?.uptime || 0),
411
+ });
412
+ parent.append(
413
+ element(
414
+ 'p',
415
+ 'Select a section to load its current source. Stripe resources are fetched one page at a time.',
416
+ 'muted',
417
+ ),
418
+ );
419
+ }
420
+ if (section === 'stripe') {
421
+ const base = [
422
+ ['ID', (r) => r.id],
423
+ ['Class', (r) => r.classification],
424
+ [
425
+ 'Mode',
426
+ (r) =>
427
+ r.livemode === true
428
+ ? 'Live'
429
+ : r.livemode === false
430
+ ? 'Test'
431
+ : 'Unknown',
432
+ ],
433
+ ];
434
+ const cols = {
435
+ customers: [
436
+ ['Name', (r) => r.name],
437
+ ['Email', (r) => r.email],
438
+ ],
439
+ subscriptions: [
440
+ ['Customer', (r) => r.customerEmail || r.customer],
441
+ ['Status', (r) => r.status],
442
+ [
443
+ 'Renewal',
444
+ (r) =>
445
+ date(
446
+ r.current_period_end || r.items?.[0]?.current_period_end,
447
+ ),
448
+ ],
449
+ [
450
+ 'Prices',
451
+ (r) =>
452
+ (r.items || [])
453
+ .map(
454
+ (i) =>
455
+ i.price?.id +
456
+ ' · ' +
457
+ money(i.price?.unit_amount, i.price?.currency) +
458
+ ' · ' +
459
+ recurringInterval(i.price?.recurring) +
460
+ ' × ' +
461
+ (i.quantity ?? 1),
462
+ )
463
+ .join('; '),
464
+ ],
465
+ [
466
+ 'Cancel at period end',
467
+ (r) => (r.cancel_at_period_end ? 'Yes' : 'No'),
468
+ ],
469
+ ['All prices', subscriptionItemsButton],
470
+ ],
471
+ payments: [
472
+ ['Customer', (r) => r.customer],
473
+ ['Amount', (r) => money(r.amount, r.currency)],
474
+ ['Refunded', (r) => money(r.amount_refunded, r.currency)],
475
+ ['Status', (r) => r.status],
476
+ ['Created', (r) => date(r.created)],
477
+ ],
478
+ refunds: [
479
+ ['Charge', (r) => r.charge],
480
+ ['Amount', (r) => money(r.amount, r.currency)],
481
+ ['Status', (r) => r.status],
482
+ ],
483
+ products: [
484
+ ['Name', (r) => r.name],
485
+ ['Active', (r) => (r.active ? 'Yes' : 'No')],
486
+ ],
487
+ prices: [
488
+ ['Product', (r) => r.product],
489
+ ['Amount', (r) => money(r.unit_amount, r.currency)],
490
+ ['Interval', (r) => recurringInterval(r.recurring)],
491
+ ['Active', (r) => (r.active ? 'Yes' : 'No')],
492
+ ],
493
+ 'subscription-items': [
494
+ ['Price', (r) => r.price?.id],
495
+ ['Amount', (r) => money(r.price?.unit_amount, r.price?.currency)],
496
+ ['Interval', (r) => recurringInterval(r.price?.recurring)],
497
+ ['Quantity', (r) => r.quantity],
498
+ ['Renewal', (r) => date(r.current_period_end)],
499
+ ],
500
+ };
501
+ table(parent, [...base, ...cols[resource]], data.records || []);
502
+ }
503
+ if (section === 'data') {
504
+ cards(parent, {
505
+ knownAccounts: data.totalKnown,
506
+ completeAccountTotal: data.total,
507
+ });
508
+ if (!data.inventoryComplete)
509
+ parent.append(
510
+ element(
511
+ 'p',
512
+ 'Account inventory is incomplete. The known count is a lower bound; the complete total is unknown.',
513
+ 'notice',
514
+ ),
515
+ );
516
+ parent.append(
517
+ element(
518
+ 'p',
519
+ 'Current known accounts are not lifetime signups. Missing files are unknown. Project grouping is unavailable until project scope is integrated.',
520
+ 'muted',
521
+ ),
522
+ );
523
+ table(
524
+ parent,
525
+ [
526
+ ['Account', (r) => r.email || r.accountId],
527
+ ['Class', (r) => r.classification],
528
+ ['Active key', (r) => (r.hasActiveKey ? 'Yes' : 'No')],
529
+ ['Current session', (r) => (r.hasCurrentSession ? 'Yes' : 'No')],
530
+ [
531
+ 'Feedback by partition',
532
+ (r) =>
533
+ r.partitions
534
+ .map((p) => p.partition + ': ' + count(p.feedback))
535
+ .join('; '),
536
+ ],
537
+ [
538
+ 'Lessons by partition',
539
+ (r) =>
540
+ r.partitions
541
+ .map((p) => p.partition + ': ' + count(p.lessons))
542
+ .join('; '),
543
+ ],
544
+ [
545
+ 'Identity',
546
+ (r) => (r.possibleDuplicate ? 'Possible duplicate' : 'Known'),
547
+ ],
548
+ ],
549
+ data.records || [],
550
+ );
551
+ detail(parent, 'Unattributed legacy data', data.unattributedLegacy);
552
+ }
553
+ if (section === 'analytics') {
554
+ const external = data.revenue?.external || {};
555
+ cards(parent, {
556
+ visitors: data.trafficMetrics?.visitors,
557
+ checkoutStarts: data.trafficMetrics?.checkoutStarts,
558
+ emailSignups: data.signups?.emailSignups,
559
+ externalPaidOrders: external.paidOrders,
560
+ });
561
+ parent.append(
562
+ element('h3', 'External booked revenue · past 30 days'),
563
+ );
564
+ table(
565
+ parent,
566
+ [
567
+ ['Currency', (r) => r.currency],
568
+ ['Booked revenue', (r) => money(r.amount, r.currency)],
569
+ ],
570
+ Object.entries(external.bookedRevenueByCurrency || {}).map(
571
+ ([currency, amount]) => ({ currency, amount }),
572
+ ),
573
+ );
574
+ parent.append(
575
+ element(
576
+ 'p',
577
+ 'Shared CFO totals. Currencies stay separate. Broad accounting includes activity excluded from the external total.',
578
+ 'muted',
579
+ ),
580
+ );
581
+ for (const key of [
582
+ 'funnel',
583
+ 'signups',
584
+ 'trafficMetrics',
585
+ 'dataQuality',
586
+ 'attribution',
587
+ 'reconciliation',
588
+ ])
589
+ detail(parent, label(key), data[key]);
590
+ detail(
591
+ parent,
592
+ 'Internal, test and unknown exclusions',
593
+ external.excluded,
594
+ );
595
+ detail(
596
+ parent,
597
+ 'Broad accounting totals',
598
+ data.revenue?.broadAccounting,
599
+ );
600
+ }
601
+ if (section === 'observability') {
602
+ cards(parent, {
603
+ version: data.version,
604
+ build: data.buildSha,
605
+ uptimeSeconds: Math.floor(data.uptime || 0),
606
+ persistedTelemetryLastMinute: data.telemetry?.events,
607
+ });
608
+ parent.append(
609
+ element(
610
+ 'p',
611
+ 'Telemetry observed for ' +
612
+ (data.telemetry?.windowSeconds ?? 0) +
613
+ ' seconds; one-second precision. Process start ' +
614
+ date(data.processStartedAt) +
615
+ '. Deployment time unavailable. Error retention resets on restart.',
616
+ 'muted',
617
+ ),
618
+ );
619
+ detail(parent, 'Deployment identity', data.deployment);
620
+ detail(parent, 'Volume filesystem bytes', data.disk);
621
+ table(
622
+ parent,
623
+ [
624
+ ['Time', (r) => date(r.timestamp)],
625
+ ['Status', (r) => r.status],
626
+ ['Route category', (r) => r.route],
627
+ ],
628
+ data.recentErrors || [],
629
+ );
630
+ }
631
+ }
632
+ function controls() {
633
+ const nav = document.getElementById('sections');
634
+ nav.replaceChildren();
635
+ for (const section of sections) {
636
+ const button = element('button', titles[section]);
637
+ button.type = 'button';
638
+ button.setAttribute('aria-current', String(current === section));
639
+ button.addEventListener('click', () => {
640
+ current = section;
641
+ nextCursor = null;
642
+ controls();
643
+ load();
644
+ });
645
+ nav.append(button);
646
+ }
647
+ }
648
+ async function load(cursor = '') {
649
+ const request = ++activeLoad;
650
+ const panel = element('section', undefined, 'panel');
651
+ const heading = element('div', undefined, 'row');
652
+ heading.append(element('h2', titles[current]));
653
+ const refresh = element('button', 'Refresh');
654
+ refresh.type = 'button';
655
+ refresh.addEventListener('click', () => load());
656
+ heading.append(refresh);
657
+ panel.append(heading);
658
+ content.replaceChildren(panel);
659
+ if (current === 'stripe') {
660
+ const nav = element('nav');
661
+ nav.setAttribute('aria-label', 'Stripe resources');
662
+ for (const kind of [
663
+ 'customers',
664
+ 'subscriptions',
665
+ 'payments',
666
+ 'refunds',
667
+ 'products',
668
+ 'prices',
669
+ ]) {
670
+ const button = element('button', label(kind));
671
+ button.type = 'button';
672
+ button.setAttribute('aria-current', String(resource === kind));
673
+ button.addEventListener('click', () => {
674
+ resource = kind;
675
+ subscriptionId = null;
676
+ load();
677
+ });
678
+ nav.append(button);
679
+ }
680
+ panel.append(nav);
681
+ if (resource === 'subscription-items') {
682
+ panel.append(
683
+ element(
684
+ 'p',
685
+ 'All prices for subscription ' + subscriptionId,
686
+ 'muted',
687
+ ),
688
+ );
689
+ }
690
+ }
691
+ const loading = element('p', 'Loading current source…', 'muted');
692
+ panel.append(loading);
693
+ let url = '/v1/admin/' + current;
694
+ if (current === 'stripe') url += '/' + resource;
695
+ const query = new URLSearchParams();
696
+ if (resource === 'subscription-items' && current === 'stripe')
697
+ query.set('subscription', subscriptionId);
698
+ if (cursor)
699
+ query.set(current === 'stripe' ? 'starting_after' : 'cursor', cursor);
700
+ if (query.size) url += '?' + query;
701
+ try {
702
+ const response = await fetch(url, {
703
+ credentials: 'same-origin',
704
+ cache: 'no-store',
705
+ });
706
+ if (request !== activeLoad) return;
707
+ if (!response.ok)
708
+ throw new Error(
709
+ response.status === 404
710
+ ? 'This page is unavailable. Sign in through the usual ThumbGate login and try again.'
711
+ : response.status === 429
712
+ ? 'Another collection is running. Try again shortly.'
713
+ : 'Source request failed. Try again.',
714
+ );
715
+ const result = await response.json();
716
+ if (request !== activeLoad) return;
717
+ loading.remove();
718
+ const state = element(
719
+ 'span',
720
+ label(result.status),
721
+ 'status ' + result.status,
722
+ );
723
+ heading.append(state);
724
+ panel.append(
725
+ element(
726
+ 'p',
727
+ 'Source ' +
728
+ label(result.source) +
729
+ ' · collected ' +
730
+ date(result.generatedAt),
731
+ 'muted',
732
+ ),
733
+ );
734
+ if (result.warnings?.length)
735
+ panel.append(
736
+ element('p', result.warnings.map(label).join(' · '), 'notice'),
737
+ );
738
+ if (result.data) render(panel, current, result.data);
739
+ else
740
+ panel.append(
741
+ element(
742
+ 'p',
743
+ 'This source is unavailable. No zero total is inferred.',
744
+ 'empty',
745
+ ),
746
+ );
747
+ nextCursor = result.data?.nextCursor;
748
+ if (result.data?.hasMore && nextCursor) {
749
+ const more = element('button', 'Load next page');
750
+ more.type = 'button';
751
+ more.addEventListener('click', () => load(nextCursor));
752
+ panel.append(more);
753
+ }
754
+ } catch (error) {
755
+ if (request !== activeLoad) return;
756
+ loading.textContent = error.message;
757
+ loading.className = 'notice';
758
+ }
759
+ }
760
+ document.getElementById('logout').addEventListener('click', async () => {
761
+ const response = await fetch('/v1/auth/session', {
762
+ method: 'DELETE',
763
+ credentials: 'same-origin',
764
+ });
765
+ if (response.ok) location.assign('/');
766
+ });
767
+ controls();
768
+ load();
769
+ </script>
770
+ </body>
771
+ </html>