@businesskit/agent 1.0.4 → 1.0.7

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 (190) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.cursor-plugin/plugin.json +25 -0
  3. package/.cursorrules +10 -0
  4. package/.superconsole-plugin/plugin.json +62 -0
  5. package/AGENTS.md +105 -63
  6. package/CLAUDE.md +11 -84
  7. package/GEMINI.md +11 -34
  8. package/README.md +95 -154
  9. package/assets/logo.svg +3 -0
  10. package/bin/businesskit.js +45 -18
  11. package/commands/add-contact.md +47 -0
  12. package/commands/add-inventory-from-invoice.md +80 -0
  13. package/commands/adjust-stock.md +46 -0
  14. package/commands/brief.md +12 -0
  15. package/commands/capabilities.md +33 -0
  16. package/commands/chase.md +12 -0
  17. package/commands/check-stock.md +43 -0
  18. package/commands/create-component.md +109 -0
  19. package/commands/create-invoice.md +69 -0
  20. package/commands/create-new-bill.md +65 -0
  21. package/commands/create-page.md +124 -0
  22. package/commands/crm.md +13 -0
  23. package/commands/followups.md +13 -0
  24. package/commands/list-components.md +41 -0
  25. package/commands/list-content.md +46 -0
  26. package/commands/list-pages.md +45 -0
  27. package/commands/pipeline.md +13 -0
  28. package/commands/publish-page.md +64 -0
  29. package/commands/send-invoice.md +42 -0
  30. package/commands/seo-audit.md +36 -0
  31. package/commands/update-agent.md +33 -0
  32. package/commands/update-contact.md +46 -0
  33. package/commands/update-content.md +48 -0
  34. package/commands/update-page.md +56 -0
  35. package/commands/update-price.md +47 -0
  36. package/commands/write-blog.md +56 -0
  37. package/commands/write-docs.md +90 -0
  38. package/commands/write-guide.md +51 -0
  39. package/commands/write-newsletter.md +50 -0
  40. package/dist/server.js +4099 -0
  41. package/mcp_config.json +12 -0
  42. package/package.json +54 -25
  43. package/plugin.json +32 -0
  44. package/scripts/setup.sh +169 -0
  45. package/scripts/setup.ts +129 -0
  46. package/scripts/update.sh +56 -0
  47. package/server.json +21 -0
  48. package/skills/README.md +20 -27
  49. package/skills/billing/SKILL.md +64 -0
  50. package/skills/brand/SKILL.md +30 -86
  51. package/skills/cms/SKILL.md +111 -0
  52. package/skills/cms/references/cms-hubs.md +84 -0
  53. package/skills/cms/references/html-blocks.md +177 -0
  54. package/skills/copywriting/SKILL.md +1 -1
  55. package/skills/crm/SKILL.md +24 -0
  56. package/skills/docs/SKILL.md +65 -0
  57. package/skills/docs/references/how-to.md +155 -0
  58. package/skills/inbox/SKILL.md +49 -0
  59. package/skills/inventory/SKILL.md +69 -0
  60. package/skills/pages/SKILL.md +214 -0
  61. package/skills/pages/references/sections-catalog.json +1183 -0
  62. package/skills/social/SKILL.md +84 -211
  63. package/skills/social/evals/evals.json +66 -0
  64. package/skills/social/evals/rubric.md +26 -0
  65. package/skills/social/examples/repurposing-blog-to-social.md +93 -0
  66. package/skills/social/examples/weekly-content-calendar.md +30 -0
  67. package/skills/social/linkedin/SKILL.md +107 -0
  68. package/skills/social/linkedin/evals/evals.json +106 -0
  69. package/skills/social/linkedin/evals/rubric.md +28 -0
  70. package/skills/social/linkedin/examples/gasp-weekly-sprint.md +24 -0
  71. package/skills/social/linkedin/examples/growth-posts-by-format.md +140 -0
  72. package/skills/social/linkedin/references/gasp-funnel-and-calibration.md +90 -0
  73. package/skills/social/linkedin/references/six-growth-formats.md +114 -0
  74. package/skills/social/references/platforms.md +76 -0
  75. package/skills/social/references/post-templates.md +105 -0
  76. package/skills/social/references/reverse-engineering.md +62 -0
  77. package/src/data/sections-catalog.json +950 -0
  78. package/src/db.ts +170 -0
  79. package/src/server.ts +75 -0
  80. package/src/tools/content.ts +326 -0
  81. package/src/tools/crm.ts +1416 -0
  82. package/src/tools/domains.ts +89 -0
  83. package/src/tools/inbox.ts +270 -0
  84. package/src/tools/index.ts +116 -0
  85. package/src/tools/pages.ts +1217 -0
  86. package/src/tools/shop.ts +771 -0
  87. package/src/tools/system.ts +94 -0
  88. package/src/tools/types.ts +17 -0
  89. package/templates/antigravity.json +8 -0
  90. package/templates/claude-code.mcp.json +8 -0
  91. package/templates/cursor.mcp.json +8 -0
  92. package/templates/vscode.mcp.json +9 -0
  93. package/.claude/commands/analytics.md +0 -7
  94. package/.claude/commands/blog-writer.md +0 -9
  95. package/.claude/commands/cbo.md +0 -7
  96. package/.claude/commands/ceo.md +0 -10
  97. package/.claude/commands/cmo.md +0 -7
  98. package/.claude/commands/compress.md +0 -73
  99. package/.claude/commands/coo.md +0 -11
  100. package/.claude/commands/copywriter.md +0 -15
  101. package/.claude/commands/course-creator.md +0 -9
  102. package/.claude/commands/crm.md +0 -591
  103. package/.claude/commands/deep.md +0 -50
  104. package/.claude/commands/docs-writer.md +0 -8
  105. package/.claude/commands/forms-builder.md +0 -10
  106. package/.claude/commands/ingest.md +0 -110
  107. package/.claude/commands/jobs-manager.md +0 -8
  108. package/.claude/commands/kb.md +0 -107
  109. package/.claude/commands/newsletter-writer.md +0 -9
  110. package/.claude/commands/preserve.md +0 -64
  111. package/.claude/commands/resume.md +0 -67
  112. package/.claude/commands/scheduler.md +0 -8
  113. package/.claude/commands/seo.md +0 -60
  114. package/.claude/commands/social.md +0 -51
  115. package/.claude/commands/store-manager.md +0 -11
  116. package/.claude/settings.json +0 -16
  117. package/.claude/settings.local.json +0 -11
  118. package/.env.example +0 -12
  119. package/.mcp.json +0 -3
  120. package/HEARTBEAT.md +0 -105
  121. package/PLAN.md +0 -345
  122. package/PRD-Agent-Composition.md +0 -149
  123. package/PRD-Agent-Harness.md +0 -316
  124. package/REFERENCE.md +0 -160
  125. package/SOUL.md +0 -148
  126. package/SYSTEM.md +0 -71
  127. package/agents/_base.ts +0 -371
  128. package/agents/analytics/SOUL.md +0 -11
  129. package/agents/analytics/analytics.ts +0 -405
  130. package/agents/business/SOUL.md +0 -11
  131. package/agents/business/business.ts +0 -109
  132. package/agents/ceo/SOUL.md +0 -15
  133. package/agents/ceo/ceo.ts +0 -146
  134. package/agents/content/SOUL.md +0 -11
  135. package/agents/content/content.ts +0 -379
  136. package/agents/copywriting/SOUL.md +0 -11
  137. package/agents/copywriting/copywriting.ts +0 -89
  138. package/agents/courses/SOUL.md +0 -11
  139. package/agents/courses/courses.ts +0 -451
  140. package/agents/docs/SOUL.md +0 -11
  141. package/agents/docs/docs.ts +0 -77
  142. package/agents/forms/SOUL.md +0 -11
  143. package/agents/forms/forms.ts +0 -364
  144. package/agents/hiring/SOUL.md +0 -11
  145. package/agents/hiring/hiring.ts +0 -314
  146. package/agents/marketing/SOUL.md +0 -15
  147. package/agents/marketing/marketing.ts +0 -109
  148. package/agents/newsletter/SOUL.md +0 -11
  149. package/agents/newsletter/newsletter.ts +0 -91
  150. package/agents/operations/SOUL.md +0 -11
  151. package/agents/operations/operations.ts +0 -157
  152. package/agents/sales/SOUL.md +0 -44
  153. package/agents/sales/sales.ts +0 -883
  154. package/agents/scheduler/SOUL.md +0 -11
  155. package/agents/scheduler/scheduler.ts +0 -68
  156. package/agents/seo/SOUL.md +0 -11
  157. package/agents/seo/seo.ts +0 -288
  158. package/agents/social/SOUL.md +0 -11
  159. package/agents/social/social.ts +0 -744
  160. package/agents/store/SOUL.md +0 -11
  161. package/agents/store/store.ts +0 -514
  162. package/cli.ts +0 -144
  163. package/context/about-me.md +0 -96
  164. package/context/brand-voice.md +0 -127
  165. package/context/brand.md +0 -80
  166. package/context/business.md +0 -66
  167. package/context/working-style.md +0 -87
  168. package/lib/analytics.ts +0 -81
  169. package/lib/cms.ts +0 -88
  170. package/lib/db.adapter.ts +0 -30
  171. package/lib/db.ts +0 -63
  172. package/lib/enums.ts +0 -25
  173. package/lib/groups.ts +0 -122
  174. package/lib/id.ts +0 -43
  175. package/lib/kb.ts +0 -337
  176. package/lib/memory.ts +0 -219
  177. package/lib/pattern-detector.ts +0 -169
  178. package/lib/profile.ts +0 -155
  179. package/lib/schema.ts +0 -2015
  180. package/lib/slug.ts +0 -30
  181. package/lib/validate.ts +0 -33
  182. package/setup.ts +0 -141
  183. package/skills/agents/SKILL.md +0 -56
  184. package/skills/analytics/SKILL.md +0 -52
  185. package/skills/blog-writer/SKILL.md +0 -452
  186. package/skills/ceo/SKILL.md +0 -25
  187. package/skills/cmo/SKILL.md +0 -8
  188. package/skills/schema/SKILL.md +0 -86
  189. package/skills/store/SKILL.md +0 -62
  190. package/tsconfig.json +0 -14
@@ -1,405 +0,0 @@
1
- /**
2
- * Analytics Agent — READ-ONLY cross-analytics.
3
- *
4
- * Aggregation tree (per businesskit-files/*):
5
- *
6
- * clicks_analytics ──▶ link_analytics ──▶ link_analytics_by_category
7
- * └──────────────────────▶ profile_analytics
8
- *
9
- * purchases ─────────▶ product_analytics ─▶ profile_analytics
10
- *
11
- * form_analytics ─────────────────────────▶ cms_analytics (cat_34)
12
- * job_analytics ──────────────────────────▶ cms_analytics (cat_31)
13
- * content_analytics ──────────────────────▶ cms_analytics (per category)
14
- *
15
- * profile_analytics = traffic + revenue rollup (1 row per profile)
16
- * cms_analytics = posts/submissions/applications/views rollup per CMS
17
- * category (cat_35 Blog, cat_34 Forms, cat_31 Jobs, etc.)
18
- *
19
- * Never writes. Never aggregates. Just reads the already-rolled-up counters
20
- * maintained by app-side aggregators + the DB triggers in product-triggers.ts
21
- * and content/forms/jobs trigger sets.
22
- *
23
- * This agent exposes ONE cross-business snapshot (crossSnapshot) and a few
24
- * focused read slices. Callers can ask ATLAS for any of them.
25
- */
26
-
27
- import { BaseAgent, db } from '../_base.ts'
28
-
29
- // ── Helpers ─────────────────────────────────────────────────────────────────
30
-
31
- const parseArr = (v: unknown): number[] => {
32
- try { const x = JSON.parse(v as string); return Array.isArray(x) ? x : [] }
33
- catch { return [] }
34
- }
35
- const parseObj = (v: unknown): Record<string, number> => {
36
- try { const x = JSON.parse(v as string); return x && typeof x === 'object' ? x : {} }
37
- catch { return {} }
38
- }
39
- const sum = (arr: number[]) => arr.reduce((a, b) => a + b, 0)
40
- const top = (obj: Record<string, number>, n = 5) =>
41
- Object.entries(obj).sort((a, b) => b[1] - a[1]).slice(0, n)
42
- .map(([key, value]) => ({ key, value }))
43
-
44
- function trend(series: number[]): { pct: number | null; direction: 'up' | 'down' | 'flat' | 'new' } {
45
- if (series.length < 2) return { pct: null, direction: 'new' }
46
- const half = Math.floor(series.length / 2)
47
- const recent = sum(series.slice(half))
48
- const prior = sum(series.slice(0, half))
49
- if (!prior) return { pct: null, direction: recent > 0 ? 'up' : 'flat' }
50
- const pct = Math.round(((recent - prior) / prior) * 100)
51
- return { pct, direction: pct > 0 ? 'up' : pct < 0 ? 'down' : 'flat' }
52
- }
53
-
54
- // CMS category ids used in cms_analytics rollups.
55
- // Subset that covers the main content types; extend as needed.
56
- const CMS_CATS = {
57
- cat_18: 'Courses',
58
- cat_19: 'Downloads',
59
- cat_20: 'Newsletter',
60
- cat_31: 'Jobs',
61
- cat_32: 'Docs',
62
- cat_34: 'Forms',
63
- cat_35: 'Blog',
64
- cat_36: 'Guides',
65
- cat_37: 'Notes',
66
- cat_45: 'Posts',
67
- cat_47: 'Pages',
68
- } as const
69
-
70
- // ── Types ───────────────────────────────────────────────────────────────────
71
-
72
- export interface CrossSnapshot {
73
- profile: ProfileRollup | null
74
- cms: CmsRollup[]
75
- top_products: Array<{
76
- id: string
77
- title: string
78
- type: string
79
- sales: number
80
- revenue_cents: number
81
- revenue_30d: number[]
82
- }>
83
- top_links: Array<{
84
- id: string
85
- title: string
86
- url: string
87
- clicks: number
88
- clicks_7d: number[]
89
- }>
90
- top_categories: Array<{
91
- category_id: string
92
- total_clicks: number
93
- total_links: number
94
- active_links: number
95
- }>
96
- }
97
-
98
- export interface ProfileRollup {
99
- total_views: number
100
- total_clicks: number
101
- total_sales: number
102
- total_earnings: number
103
- total_products: number
104
- total_links: number
105
- active_links: number
106
- revenue_7d: number[]
107
- revenue_30d: number[]
108
- revenue_12m: number[]
109
- revenue_30d_total: number
110
- revenue_trend: ReturnType<typeof trend>
111
- clicks_7d: number[]
112
- clicks_30d: number[]
113
- clicks_trend: ReturnType<typeof trend>
114
- top_countries: Array<{ key: string; value: number }>
115
- top_referrers: Array<{ key: string; value: number }>
116
- top_utm_sources: Array<{ key: string; value: number }>
117
- last_aggregated_at: number
118
- }
119
-
120
- export interface CmsRollup {
121
- category_id: string
122
- category_name: string
123
- total_posts: number
124
- total_published: number
125
- total_draft: number
126
- total_views: number
127
- total_reactions: number
128
- total_comments: number
129
- total_submissions: number // form_analytics bubbles here
130
- total_applications: number // job_analytics bubbles here
131
- }
132
-
133
- // ── Agent ───────────────────────────────────────────────────────────────────
134
-
135
- export class AnalyticsAgent extends BaseAgent {
136
- readonly name = 'Analytics'
137
- readonly title = 'Analytics Agent'
138
-
139
- /** One cross-business snapshot. Pulls from every rollup in parallel. */
140
- async crossSnapshot(): Promise<CrossSnapshot> {
141
- await this.init()
142
- const [profile, cms, topProducts, topLinks, topCategories] = await Promise.all([
143
- this.profileRollup(),
144
- this.cmsRollup(),
145
- this.topProducts(5),
146
- this.topLinks(10),
147
- this.topLinkCategories(5),
148
- ])
149
- return {
150
- profile,
151
- cms,
152
- top_products: topProducts,
153
- top_links: topLinks,
154
- top_categories: topCategories,
155
- }
156
- }
157
-
158
- /** profile_analytics row — traffic + revenue rollup across all products/links. */
159
- async profileRollup(): Promise<ProfileRollup | null> {
160
- await this.init()
161
- const { rows: [r] } = await db.execute({
162
- sql: `SELECT total_views, total_clicks, total_sales, total_earnings,
163
- total_products, total_links, active_links,
164
- revenue_7d, revenue_30d, revenue_12m,
165
- analytics_7d, analytics_30d,
166
- country_clicks, referrer_clicks, utm_source_clicks,
167
- last_aggregated_at
168
- FROM profile_analytics WHERE profile_id=? LIMIT 1`,
169
- args: [this.profileId],
170
- })
171
- if (!r) return null
172
-
173
- const revenue30d = parseArr(r.revenue_30d)
174
- const clicks30d = parseArr(r.analytics_30d)
175
- return {
176
- total_views: Number(r.total_views ?? 0),
177
- total_clicks: Number(r.total_clicks ?? 0),
178
- total_sales: Number(r.total_sales ?? 0),
179
- total_earnings: Number(r.total_earnings ?? 0),
180
- total_products: Number(r.total_products ?? 0),
181
- total_links: Number(r.total_links ?? 0),
182
- active_links: Number(r.active_links ?? 0),
183
- revenue_7d: parseArr(r.revenue_7d),
184
- revenue_30d: revenue30d,
185
- revenue_12m: parseArr(r.revenue_12m),
186
- revenue_30d_total: sum(revenue30d),
187
- revenue_trend: trend(revenue30d),
188
- clicks_7d: parseArr(r.analytics_7d),
189
- clicks_30d: clicks30d,
190
- clicks_trend: trend(clicks30d),
191
- top_countries: top(parseObj(r.country_clicks)),
192
- top_referrers: top(parseObj(r.referrer_clicks)),
193
- top_utm_sources: top(parseObj(r.utm_source_clicks)),
194
- last_aggregated_at: Number(r.last_aggregated_at ?? 0),
195
- }
196
- }
197
-
198
- /** cms_analytics rollup per category. forms / jobs / content feed into
199
- * total_submissions / total_applications / total_views / total_posts. */
200
- async cmsRollup(): Promise<CmsRollup[]> {
201
- await this.init()
202
- const { rows } = await db.execute({
203
- sql: `SELECT c.category_id,
204
- a.total_posts, a.total_published, a.total_draft,
205
- a.total_views, a.total_reactions, a.total_comments,
206
- a.total_submissions, a.total_applications
207
- FROM cms c
208
- LEFT JOIN cms_analytics a ON a.cms_id = c.id
209
- WHERE c.profile_id=?`,
210
- args: [this.profileId],
211
- })
212
- return rows.map(r => ({
213
- category_id: r.category_id as string,
214
- category_name: (CMS_CATS as Record<string, string>)[r.category_id as string]
215
- ?? (r.category_id as string),
216
- total_posts: Number(r.total_posts ?? 0),
217
- total_published: Number(r.total_published ?? 0),
218
- total_draft: Number(r.total_draft ?? 0),
219
- total_views: Number(r.total_views ?? 0),
220
- total_reactions: Number(r.total_reactions ?? 0),
221
- total_comments: Number(r.total_comments ?? 0),
222
- total_submissions: Number(r.total_submissions ?? 0),
223
- total_applications: Number(r.total_applications ?? 0),
224
- }))
225
- }
226
-
227
- /** product_analytics top-N by revenue (trigger-maintained from purchases). */
228
- async topProducts(limit = 5) {
229
- await this.init()
230
- const { rows } = await db.execute({
231
- sql: `SELECT pa.product_id, pa.total_sales, pa.total_revenue_cents,
232
- pa.revenue_30d, p.title, p.type
233
- FROM product_analytics pa
234
- JOIN products p ON p.id = pa.product_id
235
- WHERE pa.profile_id=? AND p.hidden=0
236
- ORDER BY pa.total_revenue_cents DESC
237
- LIMIT ?`,
238
- args: [this.profileId, limit],
239
- })
240
- return rows.map(r => ({
241
- id: r.product_id as string,
242
- title: r.title as string,
243
- type: r.type as string,
244
- sales: Number(r.total_sales ?? 0),
245
- revenue_cents: Number(r.total_revenue_cents ?? 0),
246
- revenue_30d: parseArr(r.revenue_30d),
247
- }))
248
- }
249
-
250
- /** link_analytics top-N by total_clicks (trigger-maintained from clicks_analytics). */
251
- async topLinks(limit = 10) {
252
- await this.init()
253
- const { rows } = await db.execute({
254
- sql: `SELECT la.link_id, la.total_clicks, la.analytics_7d, l.title, l.url
255
- FROM link_analytics la
256
- JOIN links l ON l.id = la.link_id
257
- WHERE la.profile_id=?
258
- ORDER BY la.total_clicks DESC
259
- LIMIT ?`,
260
- args: [this.profileId, limit],
261
- })
262
- return rows.map(r => ({
263
- id: r.link_id as string,
264
- title: r.title as string,
265
- url: r.url as string,
266
- clicks: Number(r.total_clicks ?? 0),
267
- clicks_7d: parseArr(r.analytics_7d),
268
- }))
269
- }
270
-
271
- /** link_analytics_by_category — where clicks split across categories. */
272
- async topLinkCategories(limit = 5) {
273
- await this.init()
274
- const { rows } = await db.execute({
275
- sql: `SELECT category_id, total_clicks, total_links, active_links
276
- FROM link_analytics_by_category
277
- WHERE profile_id=?
278
- ORDER BY total_clicks DESC
279
- LIMIT ?`,
280
- args: [this.profileId, limit],
281
- })
282
- return rows.map(r => ({
283
- category_id: r.category_id as string,
284
- total_clicks: Number(r.total_clicks ?? 0),
285
- total_links: Number(r.total_links ?? 0),
286
- active_links: Number(r.active_links ?? 0),
287
- }))
288
- }
289
-
290
- // ── Convenience reports (compose over crossSnapshot slices) ──────────────
291
-
292
- async revenueReport() {
293
- const [p, products] = await Promise.all([this.profileRollup(), this.topProducts(5)])
294
- return {
295
- total_revenue_cents: p?.total_earnings ?? 0,
296
- revenue_trend: p?.revenue_trend ?? trend([]),
297
- revenue_30d_cents: p?.revenue_30d_total ?? 0,
298
- revenue_30d_series: p?.revenue_30d ?? [],
299
- total_sales: p?.total_sales ?? 0,
300
- top_products: products,
301
- }
302
- }
303
-
304
- async trafficReport() {
305
- const [p, links, cats] = await Promise.all([
306
- this.profileRollup(),
307
- this.topLinks(10),
308
- this.topLinkCategories(5),
309
- ])
310
- return {
311
- total_views: p?.total_views ?? 0,
312
- total_clicks: p?.total_clicks ?? 0,
313
- clicks_trend: p?.clicks_trend ?? trend([]),
314
- clicks_30d: p?.clicks_30d ?? [],
315
- top_countries: p?.top_countries ?? [],
316
- top_referrers: p?.top_referrers ?? [],
317
- top_utms: p?.top_utm_sources ?? [],
318
- top_links: links,
319
- top_categories: cats,
320
- }
321
- }
322
-
323
- async contentReport() {
324
- const cms = await this.cmsRollup()
325
- return {
326
- by_category: cms,
327
- total_views: cms.reduce((a, c) => a + c.total_views, 0),
328
- total_submissions: cms.find(c => c.category_id === 'cat_34')?.total_submissions ?? 0,
329
- total_applications: cms.find(c => c.category_id === 'cat_31')?.total_applications ?? 0,
330
- blog_posts: cms.find(c => c.category_id === 'cat_35')?.total_published ?? 0,
331
- docs: cms.find(c => c.category_id === 'cat_32')?.total_published ?? 0,
332
- }
333
- }
334
-
335
- // ── Back-compat — CEO / Business / Marketing still call .snapshot() ──────
336
- // Old shape: { profile, products: [{id,title,type,sales,revenue,rev30d}],
337
- // links: [{id,title,url,clicks,last7d}],
338
- // forms: [{id,title,views,submissions}] }
339
- // profile.revenue_trend returned a string ('+25%' / 'new' / 'no data').
340
- async snapshot() {
341
- await this.init()
342
- const [profile, products, links, forms] = await Promise.all([
343
- this.profileRollup(),
344
- this.topProducts(50),
345
- this.topLinks(50),
346
- this.formsSummary(),
347
- ])
348
- const legacyTrend =
349
- !profile?.revenue_trend || profile.revenue_trend.direction === 'new'
350
- ? 'new'
351
- : profile.revenue_trend.pct === null
352
- ? 'no data'
353
- : `${profile.revenue_trend.pct >= 0 ? '+' : ''}${profile.revenue_trend.pct}%`
354
-
355
- return {
356
- profile: profile && {
357
- total_clicks: profile.total_clicks,
358
- total_sales: profile.total_sales,
359
- total_revenue: profile.total_earnings,
360
- revenue_30d: profile.revenue_30d,
361
- clicks_30d: profile.clicks_30d,
362
- revenue_trend: legacyTrend,
363
- top_countries: profile.top_countries.map(x => [x.key, x.value] as [string, number]),
364
- top_referrers: profile.top_referrers.map(x => [x.key, x.value] as [string, number]),
365
- },
366
- products: products.map(p => ({
367
- id: p.id,
368
- title: p.title,
369
- type: p.type,
370
- sales: p.sales,
371
- revenue: p.revenue_cents,
372
- rev30d: p.revenue_30d,
373
- })),
374
- links: links.map(l => ({
375
- id: l.id,
376
- title: l.title,
377
- url: l.url,
378
- clicks: l.clicks,
379
- last7d: l.clicks_7d,
380
- })),
381
- forms,
382
- }
383
- }
384
-
385
- /** form_analytics top (for snapshot() compat). */
386
- private async formsSummary() {
387
- const { rows } = await db.execute({
388
- sql: `SELECT f.id, f.title,
389
- fa.total_views AS views, fa.submissions
390
- FROM forms f
391
- LEFT JOIN form_analytics fa ON fa.form_id = f.id
392
- WHERE f.profile_id=? AND f.hidden=0
393
- ORDER BY fa.submissions DESC`,
394
- args: [this.profileId],
395
- })
396
- return rows.map(r => ({
397
- id: r.id as string,
398
- title: r.title as string,
399
- views: Number(r.views ?? 0),
400
- submissions: Number(r.submissions ?? 0),
401
- }))
402
- }
403
- }
404
-
405
- export const analyticsAgent = new AnalyticsAgent()
@@ -1,11 +0,0 @@
1
- # business
2
-
3
- Placeholder SOUL. See CLAUDE.md routing table and skills/business/SKILL.md (if present) for scope.
4
-
5
- ## Rules
6
-
7
- - Load skills on demand
8
- - Draft before publish
9
- - Archive not delete (hidden=1)
10
- - Log every action to agent_memory
11
- - Push reports to agent_reports mid-session
@@ -1,109 +0,0 @@
1
- /**
2
- * REX — Chief Business Officer
3
- * "Revenue is the scoreboard. I read it better than anyone."
4
- * Reads: product_analytics, purchases, profile_analytics
5
- * Outputs: revenue strategy, pricing recommendations, upsell opportunities
6
- */
7
-
8
- import { BaseAgent, db } from '../_base.ts'
9
- import { analyticsAgent } from '../analytics/analytics.ts'
10
- import { storeManager } from '../store/store.ts'
11
-
12
- export class CBO extends BaseAgent {
13
- readonly name = 'REX'
14
- readonly title = 'Chief Business Officer'
15
-
16
- async revenueReport() {
17
- await this.init()
18
- const { products, profile } = await analyticsAgent.snapshot()
19
-
20
- const totalRevenue = products.reduce((a, p) => a + p.revenue, 0)
21
- const totalSales = products.reduce((a, p) => a + p.sales, 0)
22
- const topProduct = products[0] ?? null
23
- const avgOrderValue = totalSales > 0 ? Math.round(totalRevenue / totalSales) : 0
24
-
25
- // Product type breakdown
26
- const byType = products.reduce<Record<string, { revenue: number; sales: number }>>((acc, p) => {
27
- if (!acc[p.type]) acc[p.type] = { revenue: 0, sales: 0 }
28
- acc[p.type].revenue += p.revenue
29
- acc[p.type].sales += p.sales
30
- return acc
31
- }, {})
32
-
33
- // Recent purchases for velocity signal
34
- const { rows: recentPurchases } = await db.execute({
35
- sql: `SELECT product_id, amount_cents, currency, created_at
36
- FROM purchases WHERE profile_id=? AND payment_status='completed'
37
- ORDER BY created_at DESC LIMIT 20`,
38
- args: [this.profileId],
39
- })
40
-
41
- return {
42
- total_revenue_cents: totalRevenue,
43
- total_sales: totalSales,
44
- avg_order_value_cents: avgOrderValue,
45
- revenue_trend: profile?.revenue_trend ?? 'no data',
46
- top_product: topProduct,
47
- by_type: byType,
48
- recent_purchases: recentPurchases,
49
- strategy: this.buildStrategy({ totalRevenue, totalSales, products, byType }),
50
- }
51
- }
52
-
53
- async pricingAudit() {
54
- await this.init()
55
- const products = await storeManager.list({ published: true })
56
- return products.map(p => ({
57
- id: p.id,
58
- title: p.title,
59
- type: p.type,
60
- price_cents: p.price_cents,
61
- price_usd: `$${((p.price_cents as number) / 100).toFixed(2)}`,
62
- }))
63
- }
64
-
65
- async conversionAnalysis() {
66
- await this.init()
67
- // Compare link_analytics clicks vs purchases per product
68
- const { rows } = await db.execute({
69
- sql: `SELECT p.id, p.title, p.type,
70
- pa.total_sales, pa.total_revenue_cents,
71
- pa.sales_30d
72
- FROM products p
73
- LEFT JOIN product_analytics pa ON pa.product_id = p.id
74
- WHERE p.profile_id=? AND p.published=1 AND p.hidden=0
75
- ORDER BY pa.total_revenue_cents DESC NULLS LAST`,
76
- args: [this.profileId],
77
- })
78
- return rows
79
- }
80
-
81
- private buildStrategy(ctx: {
82
- totalRevenue: number
83
- totalSales: number
84
- products: Array<{ type: string; revenue: number; title: string }>
85
- byType: Record<string, { revenue: number; sales: number }>
86
- }): string[] {
87
- const recs: string[] = []
88
- const { totalRevenue, totalSales, products, byType } = ctx
89
-
90
- if (totalRevenue === 0)
91
- recs.push('No revenue yet. Launch your first paid product — start with a service or 1:1 meeting for fastest validation.')
92
-
93
- if (!byType.course && totalRevenue > 0)
94
- recs.push('Add a course. Courses generate passive revenue without ongoing time cost.')
95
-
96
- if (!byType.sponsorship)
97
- recs.push('Open a sponsorship slot. If you have traffic, it monetizes immediately.')
98
-
99
- if (products[0] && products[0].revenue > 0)
100
- recs.push(`Upsell opportunity: bundle "${products[0].title}" with a service or course for a premium tier.`)
101
-
102
- if (totalSales > 10 && !byType.subscription)
103
- recs.push('You have traction. Add a subscription product to convert one-time buyers into recurring revenue.')
104
-
105
- return recs
106
- }
107
- }
108
-
109
- export const cbo = new CBO()
@@ -1,15 +0,0 @@
1
- # chief-of-staff
2
-
3
- Runs the operation. Weekly briefing, pending approvals, priorities, business pulse. Load HEARTBEAT.md first. Handles orchestration across all agents.
4
-
5
- ## Rules
6
-
7
- - Load skills on demand
8
- - Draft before publish
9
- - Archive not delete (hidden=1)
10
- - Log every action to agent_memory
11
- - Push reports to agent_reports mid-session
12
-
13
- ## Skills
14
-
15
- See skills/chief-of-staff/SKILL.md and CLAUDE.md skills table.
package/agents/ceo/ceo.ts DELETED
@@ -1,146 +0,0 @@
1
- /**
2
- * ARIA — Chief Executive Officer
3
- * "I see the whole board. I set the priorities. I brief the team."
4
- *
5
- * Orchestrates all other agents. Generates weekly briefing.
6
- * In Phase 3: runs on CF Workflows cron → n8n → email/Slack.
7
- */
8
-
9
- import { BaseAgent, db } from '../_base.ts'
10
- import { analyticsAgent } from '../analytics/analytics.ts'
11
-
12
- export class CEO extends BaseAgent {
13
- readonly name = 'ARIA'
14
- readonly title = 'Chief Executive Officer'
15
-
16
- async weeklyBriefing() {
17
- await this.init()
18
- const [snap, inventory] = await Promise.all([
19
- analyticsAgent.snapshot(),
20
- this.fullInventory(),
21
- ])
22
-
23
- const recs = this.recommendations(snap, inventory)
24
-
25
- return {
26
- business: this.ctx.profile.title,
27
- generated: new Date().toISOString(),
28
- revenue: this.formatRevenue(snap.profile),
29
- traffic: this.formatTraffic(snap.profile),
30
- top_products: snap.products.slice(0, 5),
31
- inventory,
32
- recommendations: recs,
33
- }
34
- }
35
-
36
- async fullInventory() {
37
- await this.init()
38
-
39
- // Content lives in unified `content` table — read trigger-maintained
40
- // cms_analytics counts (free; no per-row COUNT). Everything else uses
41
- // the live tables directly.
42
- const [contentRows, products, jobs, forms, pages] = await Promise.all([
43
- db.execute({
44
- sql: `SELECT cms.slug AS kind, a.total_posts, a.total_published, a.total_draft
45
- FROM cms
46
- LEFT JOIN cms_analytics a ON a.cms_id = cms.id
47
- WHERE cms.profile_id=?`,
48
- args: [this.profileId],
49
- }).then(r => r.rows),
50
- this.count('products'),
51
- this.count('job_listings'),
52
- this.count('forms'),
53
- this.count('pages'),
54
- ])
55
-
56
- const inv: Record<string, { total: number; live: number; drafts: number }> = {
57
- products: products, job_listings: jobs, forms: forms, pages: pages,
58
- }
59
- for (const r of contentRows) {
60
- const total = Number(r.total_posts ?? 0)
61
- const live = Number(r.total_published ?? 0)
62
- const draft = Number(r.total_draft ?? 0)
63
- if (total > 0) inv[String(r.kind)] = { total, live, drafts: draft }
64
- }
65
- return inv
66
- }
67
-
68
- toMarkdown(briefing: Awaited<ReturnType<CEO['weeklyBriefing']>>): string {
69
- const { business, generated, revenue, traffic, top_products, inventory, recommendations } = briefing
70
- return `# Weekly Briefing — ${business}
71
- _${new Date(generated).toDateString()}_
72
-
73
- ## Revenue
74
- - Total: ${revenue.total} | Last 30d: ${revenue.last30d} | Trend: ${revenue.trend}
75
-
76
- ## Traffic
77
- - Clicks: ${traffic.total.toLocaleString()} | Top: ${traffic.top_countries.map(([c]) => c).join(', ')}
78
-
79
- ## Content Inventory
80
- ${Object.entries(inventory).map(([t, v]) => `- **${t}**: ${v.live} live, ${v.drafts} drafts`).join('\n')}
81
-
82
- ## Top Products
83
- ${top_products.slice(0, 5).map(p => `- ${p.title}: $${(p.revenue / 100).toFixed(2)} (${p.sales} sales)`).join('\n') || '- none yet'}
84
-
85
- ## Recommendations
86
- ${recommendations.map((r, i) => `${i + 1}. ${r}`).join('\n')}
87
- `
88
- }
89
-
90
- /** Send briefing to n8n webhook (Phase 1: manual trigger, Phase 3: cron) */
91
- async sendBriefing() {
92
- await this.init()
93
- const { n8n_webhook_url } = this.ctx.credentials
94
- if (!n8n_webhook_url) return { ok: false, reason: 'No n8n webhook URL in credentials' }
95
-
96
- const briefing = await this.weeklyBriefing()
97
- const body = { event: 'weekly_briefing', ...briefing, markdown: this.toMarkdown(briefing) }
98
-
99
- try {
100
- const res = await fetch(n8n_webhook_url, {
101
- method: 'POST',
102
- headers: { 'Content-Type': 'application/json' },
103
- body: JSON.stringify(body),
104
- })
105
- return { ok: res.ok, status: res.status }
106
- } catch (e) {
107
- return { ok: false, reason: String(e) }
108
- }
109
- }
110
-
111
- private formatRevenue(p: Awaited<ReturnType<typeof analyticsAgent.snapshot>>['profile']) {
112
- const total = `$${((p?.total_revenue ?? 0) / 100).toFixed(2)}`
113
- const last30d = `$${((p?.revenue_30d.reduce((a, b) => a + b, 0) ?? 0) / 100).toFixed(2)}`
114
- return { total, last30d, trend: p?.revenue_trend ?? 'no data' }
115
- }
116
-
117
- private formatTraffic(p: Awaited<ReturnType<typeof analyticsAgent.snapshot>>['profile']) {
118
- return { total: p?.total_clicks ?? 0, top_countries: p?.top_countries ?? [] }
119
- }
120
-
121
- private recommendations(
122
- snap: Awaited<ReturnType<typeof analyticsAgent.snapshot>>,
123
- inventory: Record<string, { live: number; drafts: number }>
124
- ): string[] {
125
- const recs: string[] = []
126
-
127
- if (!snap.profile) recs.push('Connect ATLAS — no analytics data yet.')
128
- if ((inventory.blog?.live ?? 0) < 3)
129
- recs.push('Publish at least 3 blog posts. Consistency drives organic traffic.')
130
- if ((inventory.blog?.drafts ?? 0) > 0)
131
- recs.push(`${inventory.blog.drafts} draft post(s) ready. Ask BLAKE to review and publish.`)
132
-
133
- const hasNoProduct = !snap.products.some(p => p.type === 'course')
134
- if (hasNoProduct) recs.push('No courses yet. Ask SAGE to create one — courses drive 3–10x revenue per customer.')
135
-
136
- const noService = !snap.products.some(p => ['service', 'meeting'].includes(p.type))
137
- if (noService) recs.push('No services or 1:1 meetings. Ask LEO to add one — low effort, immediate revenue.')
138
-
139
- if (snap.products[0]?.revenue > 0)
140
- recs.push(`"${snap.products[0].title}" is top earner. Ask REX for an upsell strategy.`)
141
-
142
- return recs.length ? recs : ['All systems operational. Stay consistent.']
143
- }
144
- }
145
-
146
- export const ceo = new CEO()
@@ -1,11 +0,0 @@
1
- # content
2
-
3
- Placeholder SOUL. See CLAUDE.md routing table and skills/content/SKILL.md (if present) for scope.
4
-
5
- ## Rules
6
-
7
- - Load skills on demand
8
- - Draft before publish
9
- - Archive not delete (hidden=1)
10
- - Log every action to agent_memory
11
- - Push reports to agent_reports mid-session