@businesskit/agent 1.0.0

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 (84) hide show
  1. package/.agents/skills/agents.md +56 -0
  2. package/.agents/skills/analytics.md +47 -0
  3. package/.agents/skills/brand.md +87 -0
  4. package/.agents/skills/schema.md +45 -0
  5. package/.agents/skills/store.md +46 -0
  6. package/.claude/commands/analytics.md +7 -0
  7. package/.claude/commands/blog-writer.md +9 -0
  8. package/.claude/commands/cbo.md +7 -0
  9. package/.claude/commands/ceo.md +10 -0
  10. package/.claude/commands/cmo.md +7 -0
  11. package/.claude/commands/compress.md +73 -0
  12. package/.claude/commands/coo.md +11 -0
  13. package/.claude/commands/copywriter.md +15 -0
  14. package/.claude/commands/course-creator.md +9 -0
  15. package/.claude/commands/crm.md +82 -0
  16. package/.claude/commands/deep.md +50 -0
  17. package/.claude/commands/docs-writer.md +8 -0
  18. package/.claude/commands/forms-builder.md +10 -0
  19. package/.claude/commands/jobs-manager.md +8 -0
  20. package/.claude/commands/kb.md +107 -0
  21. package/.claude/commands/newsletter-writer.md +9 -0
  22. package/.claude/commands/preserve.md +64 -0
  23. package/.claude/commands/resume.md +67 -0
  24. package/.claude/commands/scheduler.md +8 -0
  25. package/.claude/commands/seo.md +60 -0
  26. package/.claude/commands/social.md +51 -0
  27. package/.claude/commands/store-manager.md +11 -0
  28. package/.claude/skills/README.md +33 -0
  29. package/.claude/skills/agents.md +56 -0
  30. package/.claude/skills/analytics.md +7 -0
  31. package/.claude/skills/blog-writing.md +452 -0
  32. package/.claude/skills/brand.md +44 -0
  33. package/.claude/skills/content-seo.md +0 -0
  34. package/.claude/skills/humanizer.md +474 -0
  35. package/.claude/skills/schema.md +45 -0
  36. package/.claude/skills/social-content.md +278 -0
  37. package/.claude/skills/store-copywriting.md +519 -0
  38. package/.claude/skills/store.md +62 -0
  39. package/.claude-plugin/plugin.json +33 -0
  40. package/.cursorrules +0 -0
  41. package/.env.example +2 -0
  42. package/.mcp.json +3 -0
  43. package/AGENTS.md +63 -0
  44. package/CLAUDE.md +221 -0
  45. package/GEMINI.md +37 -0
  46. package/LICENSE +21 -0
  47. package/PLAN.md +253 -0
  48. package/PRD-Agent-Harness.md +316 -0
  49. package/README.md +237 -0
  50. package/SYSTEM.md +49 -0
  51. package/agents/_base.ts +63 -0
  52. package/agents/creators/blog-writer.ts +347 -0
  53. package/agents/creators/copywriter.ts +89 -0
  54. package/agents/creators/course-creator.ts +106 -0
  55. package/agents/creators/crm-agent.ts +479 -0
  56. package/agents/creators/docs-writer.ts +77 -0
  57. package/agents/creators/forms-builder.ts +90 -0
  58. package/agents/creators/jobs-manager.ts +82 -0
  59. package/agents/creators/newsletter-writer.ts +91 -0
  60. package/agents/creators/store-manager.ts +138 -0
  61. package/agents/csuite/cbo.ts +109 -0
  62. package/agents/csuite/ceo.ts +121 -0
  63. package/agents/csuite/cmo.ts +109 -0
  64. package/agents/csuite/coo.ts +115 -0
  65. package/agents/growth/analytics-agent.ts +52 -0
  66. package/agents/growth/scheduler.ts +68 -0
  67. package/agents/growth/seo-agent.ts +282 -0
  68. package/agents/growth/social-agent.ts +346 -0
  69. package/bin/businesskit.js +17 -0
  70. package/cli.ts +125 -0
  71. package/context/brand.md +80 -0
  72. package/context/business.md +66 -0
  73. package/lib/analytics.ts +81 -0
  74. package/lib/db.adapter.ts +30 -0
  75. package/lib/db.ts +16 -0
  76. package/lib/id.ts +15 -0
  77. package/lib/kb.ts +337 -0
  78. package/lib/memory.ts +219 -0
  79. package/lib/pattern-detector.ts +169 -0
  80. package/lib/profile.ts +119 -0
  81. package/lib/slug.ts +30 -0
  82. package/package.json +50 -0
  83. package/setup.ts +127 -0
  84. package/tsconfig.json +13 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * JOB — Jobs Manager
3
+ * "Every great team starts with a great listing."
4
+ * Writes to: job_listings, reads job_applications
5
+ */
6
+
7
+ import { BaseAgent, db, ulid, iso } from '../_base.ts'
8
+ import { uniqueSlug } from '../../lib/slug.ts'
9
+
10
+ export interface JobInput {
11
+ title: string; company: string; location: string
12
+ location_type: 'remote' | 'onsite' | 'hybrid'
13
+ employment_type: 'full-time' | 'part-time' | 'contract' | 'freelance'
14
+ description: string; excerpt?: string; requirements?: string
15
+ salary_min?: number; salary_max?: number; salary_currency?: string
16
+ image_url?: string; expires_at?: string; publish?: boolean
17
+ }
18
+
19
+ export class JobsManager extends BaseAgent {
20
+ readonly name = 'JOB'
21
+ readonly title = 'Jobs Manager'
22
+
23
+ async create(input: JobInput) {
24
+ await this.init()
25
+ const id = ulid()
26
+ const slug = await uniqueSlug('job_listings', input.title, this.profileId)
27
+ const ts = iso()
28
+
29
+ await db.execute({
30
+ sql: `INSERT INTO job_listings
31
+ (id,profile_id,user_id,title,company,location,location_type,
32
+ employment_type,description,excerpt,requirements,
33
+ salary_min,salary_max,salary_currency,slug,image_url,
34
+ expires_at,published,hidden,created_at,updated_at)
35
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,?,?)`,
36
+ args: [
37
+ id, this.profileId, this.userId,
38
+ input.title, input.company, input.location, input.location_type,
39
+ input.employment_type, input.description,
40
+ input.excerpt ?? null, input.requirements ?? null,
41
+ input.salary_min ?? null, input.salary_max ?? null,
42
+ input.salary_currency ?? 'USD', slug,
43
+ input.image_url ?? null, input.expires_at ?? null,
44
+ input.publish ? 1 : 0, ts, ts,
45
+ ],
46
+ })
47
+ return this.get(id)
48
+ }
49
+
50
+ async get(id: string) {
51
+ const { rows: [r] } = await db.execute({ sql: 'SELECT * FROM job_listings WHERE id=?', args: [id] })
52
+ if (!r) throw new Error(`Job not found: ${id}`)
53
+ return r
54
+ }
55
+
56
+ async list(opts: { published?: boolean } = {}) {
57
+ await this.init()
58
+ const args: unknown[] = [this.profileId]
59
+ let where = 'WHERE profile_id=? AND hidden=0'
60
+ if (opts.published !== undefined) { where += ' AND published=?'; args.push(opts.published ? 1 : 0) }
61
+ const { rows } = await db.execute({
62
+ sql: `SELECT id,title,company,location_type,employment_type,published,total_applicants
63
+ FROM job_listings ${where} ORDER BY created_at DESC`,
64
+ args,
65
+ })
66
+ return rows
67
+ }
68
+
69
+ async applications(jobId: string) {
70
+ const { rows } = await db.execute({
71
+ sql: 'SELECT id,full_name,email,city,country,created_at FROM job_applications WHERE job_id=? ORDER BY created_at DESC',
72
+ args: [jobId],
73
+ })
74
+ return rows
75
+ }
76
+
77
+ async publish(id: string) { await super.publish('job_listings', id); return this.get(id) }
78
+ async archive(id: string) { await super.archive('job_listings', id) }
79
+ async summary() { await this.init(); return this.count('job_listings') }
80
+ }
81
+
82
+ export const jobsManager = new JobsManager()
@@ -0,0 +1,91 @@
1
+ /**
2
+ * PEARL — Newsletter Writer
3
+ * "I turn your audience into a community."
4
+ * Reads: subscribers table
5
+ * Sends: via SES or Resend (credentials table)
6
+ * Posts: via n8n webhook for scheduling
7
+ */
8
+
9
+ import { BaseAgent, db } from '../_base.ts'
10
+
11
+ export interface NewsletterInput {
12
+ subject: string
13
+ preview_text?: string
14
+ body_html: string
15
+ body_text?: string // plain text fallback
16
+ schedule_at?: string // ISO — pass to n8n for scheduled send
17
+ }
18
+
19
+ export class NewsletterWriter extends BaseAgent {
20
+ readonly name = 'PEARL'
21
+ readonly title = 'Newsletter Writer'
22
+
23
+ async subscriberStats() {
24
+ await this.init()
25
+ const { rows: [r] } = await db.execute({
26
+ sql: `SELECT COUNT(*) total,
27
+ COUNT(CASE WHEN signup_timestamp > strftime('%s','now','-30 days') THEN 1 END) last_30d,
28
+ COUNT(CASE WHEN country IS NOT NULL THEN 1 END) with_location
29
+ FROM subscribers WHERE profile_id=?`,
30
+ args: [this.profileId],
31
+ })
32
+ return { total: Number(r?.total ?? 0), last30d: Number(r?.last_30d ?? 0) }
33
+ }
34
+
35
+ async listSubscribers(limit = 100) {
36
+ await this.init()
37
+ const { rows } = await db.execute({
38
+ sql: 'SELECT email,name,country,signup_timestamp FROM subscribers WHERE profile_id=? ORDER BY signup_timestamp DESC LIMIT ?',
39
+ args: [this.profileId, limit],
40
+ })
41
+ return rows
42
+ }
43
+
44
+ /**
45
+ * Send newsletter via n8n webhook.
46
+ * n8n handles actual delivery via SES / Resend / any ESP.
47
+ * Payload includes all subscriber data for n8n to iterate.
48
+ */
49
+ async send(input: NewsletterInput) {
50
+ await this.init()
51
+ const { n8n_webhook_url } = this.ctx.credentials
52
+ if (!n8n_webhook_url) return { ok: false, reason: 'No n8n webhook configured' }
53
+
54
+ const stats = await this.subscriberStats()
55
+
56
+ try {
57
+ const res = await fetch(n8n_webhook_url, {
58
+ method: 'POST',
59
+ headers: { 'Content-Type': 'application/json' },
60
+ body: JSON.stringify({
61
+ event: 'newsletter_send',
62
+ business: this.ctx.profile.title,
63
+ profile_id: this.profileId,
64
+ subject: input.subject,
65
+ preview_text: input.preview_text ?? null,
66
+ body_html: input.body_html,
67
+ body_text: input.body_text ?? null,
68
+ schedule_at: input.schedule_at ?? null,
69
+ subscriber_count: stats.total,
70
+ timestamp: new Date().toISOString(),
71
+ }),
72
+ })
73
+ return { ok: res.ok, status: res.status, subscriber_count: stats.total }
74
+ } catch (e) {
75
+ return { ok: false, reason: String(e) }
76
+ }
77
+ }
78
+
79
+ /** Top countries for newsletter targeting */
80
+ async audienceBreakdown() {
81
+ await this.init()
82
+ const { rows } = await db.execute({
83
+ sql: `SELECT country, COUNT(*) n FROM subscribers WHERE profile_id=? AND country IS NOT NULL
84
+ GROUP BY country ORDER BY n DESC LIMIT 10`,
85
+ args: [this.profileId],
86
+ })
87
+ return rows
88
+ }
89
+ }
90
+
91
+ export const newsletterWriter = new NewsletterWriter()
@@ -0,0 +1,138 @@
1
+ /**
2
+ * LEO — Store Manager
3
+ * "Every product type lives here. Digital commerce is my domain."
4
+ *
5
+ * Handles: digital downloads, courses (SAGE delegates here), 1:1 meetings,
6
+ * webinars, events, listings, sponsorships, services
7
+ * Writes to: products table
8
+ */
9
+
10
+ import { BaseAgent, db, ulid, now } from '../_base.ts'
11
+ import { uniqueSlug } from '../../lib/slug.ts'
12
+
13
+ export type ProductType =
14
+ | 'download' | 'course' | 'meeting' | 'webinar'
15
+ | 'event' | 'listing' | 'sponsorship' | 'service'
16
+
17
+ export interface ProductInput {
18
+ type: ProductType
19
+ title: string
20
+ description?: string
21
+ excerpt?: string
22
+ price_cents: number
23
+ sale_price_cents?: number
24
+ currency?: string
25
+ thumbnail_url?: string
26
+ // type-specific
27
+ file_url?: string // download
28
+ calendar_link?: string // meeting
29
+ scheduling_provider?: string
30
+ webinar_link?: string // webinar
31
+ webinar_platform?: string
32
+ webinar_schedule?: string // JSON schedule
33
+ webinar_settings?: string
34
+ event_settings?: string // event
35
+ meeting_settings?: string
36
+ billing_interval?: string // sponsorship: 'month'|'year'|'once'
37
+ features?: string[]
38
+ tags?: string[]
39
+ button_text?: string
40
+ platform_name?: string // listing
41
+ platform_url?: string
42
+ post_frequency?: string
43
+ cta_button?: Record<string, string>
44
+ publish?: boolean
45
+ }
46
+
47
+ export class StoreManager extends BaseAgent {
48
+ readonly name = 'LEO'
49
+ readonly title = 'Store Manager'
50
+
51
+ async create(input: ProductInput) {
52
+ await this.init()
53
+ const id = ulid()
54
+ const slug = await uniqueSlug('products', input.title) // global unique
55
+ const ts = now()
56
+
57
+ await db.execute({
58
+ sql: `INSERT INTO products
59
+ (id,profile_id,user_id,type,title,excerpt,description,
60
+ price_cents,sale_price_cents,currency,slug,thumbnail_url,
61
+ file_url,calendar_link,scheduling_provider,
62
+ webinar_link,webinar_platform,webinar_schedule,webinar_settings,
63
+ event_settings,meeting_settings,billing_interval,
64
+ features,tags,button_text,platform_name,platform_url,post_frequency,
65
+ cta_button,is_active,published,hidden,created_at,updated_at)
66
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,1,?,0,?,?)`,
67
+ args: [
68
+ id, this.profileId, this.userId,
69
+ input.type, input.title, input.excerpt ?? null, input.description ?? null,
70
+ input.price_cents, input.sale_price_cents ?? null, input.currency ?? 'usd',
71
+ slug, input.thumbnail_url ?? null,
72
+ input.file_url ?? null, input.calendar_link ?? null, input.scheduling_provider ?? null,
73
+ input.webinar_link ?? null, input.webinar_platform ?? null,
74
+ input.webinar_schedule ?? null, input.webinar_settings ?? null,
75
+ input.event_settings ?? null, input.meeting_settings ?? null,
76
+ input.billing_interval ?? null,
77
+ input.features ? JSON.stringify(input.features) : null,
78
+ input.tags ? JSON.stringify(input.tags) : null,
79
+ input.button_text ?? null,
80
+ input.platform_name ?? null, input.platform_url ?? null, input.post_frequency ?? null,
81
+ input.cta_button ? JSON.stringify(input.cta_button) : '{}',
82
+ input.publish ? 1 : 0, ts, ts,
83
+ ],
84
+ })
85
+
86
+ // Seed analytics row
87
+ await db.execute({
88
+ sql: `INSERT OR IGNORE INTO product_analytics (id,product_id,profile_id,created_at,updated_at)
89
+ VALUES (?,?,?,?,?)`,
90
+ args: [id, id, this.profileId, ts, ts],
91
+ })
92
+
93
+ return this.get(id)
94
+ }
95
+
96
+ async get(id: string) {
97
+ const { rows: [r] } = await db.execute({ sql: 'SELECT * FROM products WHERE id=?', args: [id] })
98
+ if (!r) throw new Error(`Product not found: ${id}`)
99
+ return r
100
+ }
101
+
102
+ async list(opts: { type?: ProductType; published?: boolean; limit?: number } = {}) {
103
+ await this.init()
104
+ const args: unknown[] = [this.profileId]
105
+ let where = 'WHERE profile_id=? AND hidden=0'
106
+ if (opts.type) { where += ' AND type=?'; args.push(opts.type) }
107
+ if (opts.published !== undefined) { where += ' AND published=?'; args.push(opts.published ? 1 : 0) }
108
+ const { rows } = await db.execute({
109
+ sql: `SELECT id,type,title,slug,price_cents,published FROM products
110
+ ${where} ORDER BY created_at DESC LIMIT ?`,
111
+ args: [...args, opts.limit ?? 50],
112
+ })
113
+ return rows
114
+ }
115
+
116
+ async publish(id: string) {
117
+ const ts = now()
118
+ await db.execute({
119
+ sql: 'UPDATE products SET published=1,published_at=?,updated_at=? WHERE id=?',
120
+ args: [ts, ts, id],
121
+ })
122
+ return this.get(id)
123
+ }
124
+
125
+ async archive(id: string) { await super.archive('products', id) }
126
+
127
+ async storeOverview() {
128
+ await this.init()
129
+ const { rows } = await db.execute({
130
+ sql: `SELECT type, COUNT(*) n, SUM(CASE WHEN published=1 THEN 1 ELSE 0 END) live
131
+ FROM products WHERE profile_id=? AND hidden=0 GROUP BY type ORDER BY n DESC`,
132
+ args: [this.profileId],
133
+ })
134
+ return rows
135
+ }
136
+ }
137
+
138
+ export const storeManager = new StoreManager()
@@ -0,0 +1,109 @@
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 '../growth/analytics-agent.ts'
10
+ import { storeManager } from '../creators/store-manager.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()
@@ -0,0 +1,121 @@
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 '../growth/analytics-agent.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
+ const tables = ['posts', 'products', 'job_listings', 'forms', 'pages']
39
+ const results = await Promise.all(tables.map(t => this.count(t)))
40
+ return Object.fromEntries(tables.map((t, i) => [t, results[i]]))
41
+ }
42
+
43
+ toMarkdown(briefing: Awaited<ReturnType<Aria['weeklyBriefing']>>): string {
44
+ const { business, generated, revenue, traffic, top_products, inventory, recommendations } = briefing
45
+ return `# Weekly Briefing — ${business}
46
+ _${new Date(generated).toDateString()}_
47
+
48
+ ## Revenue
49
+ - Total: ${revenue.total} | Last 30d: ${revenue.last30d} | Trend: ${revenue.trend}
50
+
51
+ ## Traffic
52
+ - Clicks: ${traffic.total.toLocaleString()} | Top: ${traffic.top_countries.map(([c]) => c).join(', ')}
53
+
54
+ ## Content Inventory
55
+ ${Object.entries(inventory).map(([t, v]) => `- **${t}**: ${v.live} live, ${v.drafts} drafts`).join('\n')}
56
+
57
+ ## Top Products
58
+ ${top_products.slice(0, 5).map(p => `- ${p.title}: $${(p.revenue / 100).toFixed(2)} (${p.sales} sales)`).join('\n') || '- none yet'}
59
+
60
+ ## Recommendations
61
+ ${recommendations.map((r, i) => `${i + 1}. ${r}`).join('\n')}
62
+ `
63
+ }
64
+
65
+ /** Send briefing to n8n webhook (Phase 1: manual trigger, Phase 3: cron) */
66
+ async sendBriefing() {
67
+ await this.init()
68
+ const { n8n_webhook_url } = this.ctx.credentials
69
+ if (!n8n_webhook_url) return { ok: false, reason: 'No n8n webhook URL in credentials' }
70
+
71
+ const briefing = await this.weeklyBriefing()
72
+ const body = { event: 'weekly_briefing', ...briefing, markdown: this.toMarkdown(briefing) }
73
+
74
+ try {
75
+ const res = await fetch(n8n_webhook_url, {
76
+ method: 'POST',
77
+ headers: { 'Content-Type': 'application/json' },
78
+ body: JSON.stringify(body),
79
+ })
80
+ return { ok: res.ok, status: res.status }
81
+ } catch (e) {
82
+ return { ok: false, reason: String(e) }
83
+ }
84
+ }
85
+
86
+ private formatRevenue(p: Awaited<ReturnType<typeof analyticsAgent.snapshot>>['profile']) {
87
+ const total = `$${((p?.total_revenue ?? 0) / 100).toFixed(2)}`
88
+ const last30d = `$${((p?.revenue_30d.reduce((a, b) => a + b, 0) ?? 0) / 100).toFixed(2)}`
89
+ return { total, last30d, trend: p?.revenue_trend ?? 'no data' }
90
+ }
91
+
92
+ private formatTraffic(p: Awaited<ReturnType<typeof analyticsAgent.snapshot>>['profile']) {
93
+ return { total: p?.total_clicks ?? 0, top_countries: p?.top_countries ?? [] }
94
+ }
95
+
96
+ private recommendations(
97
+ snap: Awaited<ReturnType<typeof analyticsAgent.snapshot>>,
98
+ inventory: Record<string, { live: number; drafts: number }>
99
+ ): string[] {
100
+ const recs: string[] = []
101
+
102
+ if (!snap.profile) recs.push('Connect ATLAS — no analytics data yet.')
103
+ if ((inventory.posts?.live ?? 0) < 3)
104
+ recs.push('Publish at least 3 blog posts. Consistency drives organic traffic.')
105
+ if ((inventory.posts?.drafts ?? 0) > 0)
106
+ recs.push(`${inventory.posts.drafts} draft post(s) ready. Ask BLAKE to review and publish.`)
107
+
108
+ const hasNoProduct = !snap.products.some(p => p.type === 'course')
109
+ if (hasNoProduct) recs.push('No courses yet. Ask SAGE to create one — courses drive 3–10x revenue per customer.')
110
+
111
+ const noService = !snap.products.some(p => ['service', 'meeting'].includes(p.type))
112
+ if (noService) recs.push('No services or 1:1 meetings. Ask LEO to add one — low effort, immediate revenue.')
113
+
114
+ if (snap.products[0]?.revenue > 0)
115
+ recs.push(`"${snap.products[0].title}" is top earner. Ask REX for an upsell strategy.`)
116
+
117
+ return recs.length ? recs : ['All systems operational. Stay consistent.']
118
+ }
119
+ }
120
+
121
+ export const ceo = new CEO()
@@ -0,0 +1,109 @@
1
+ /**
2
+ * NOVA — Chief Marketing Officer
3
+ * "Content without strategy is noise. I make it signal."
4
+ * Orchestrates: BLAKE, PEARL, COPY, HERMES, SCOUT
5
+ * Reads: all analytics, all published content
6
+ * Outputs: content calendar, campaign strategy, growth recommendations
7
+ */
8
+
9
+ import { BaseAgent, db } from '../_base.ts'
10
+ import { analyticsAgent } from '../growth/analytics-agent.ts'
11
+ import { blogWriter } from '../creators/blog-writer.ts'
12
+
13
+ export class CMO extends BaseAgent {
14
+ readonly name = 'NOVA'
15
+ readonly title = 'Chief Marketing Officer'
16
+
17
+ async contentCalendar(weeksAhead = 4) {
18
+ await this.init()
19
+ const { profile, products } = await analyticsAgent.snapshot()
20
+
21
+ const topProducts = products.slice(0, 3)
22
+ const weeks: Array<{ week: number; items: CalendarItem[] }> = []
23
+
24
+ for (let w = 1; w <= weeksAhead; w++) {
25
+ const items: CalendarItem[] = []
26
+
27
+ // Blog: 2 posts per week
28
+ items.push({ day: 'Monday', type: 'blog', agent: 'BLAKE',
29
+ suggestion: w % 2 === 0
30
+ ? `How-to guide related to ${topProducts[0]?.title ?? 'your main product'}`
31
+ : `Opinion/thought leadership in your niche` })
32
+ items.push({ day: 'Thursday', type: 'blog', agent: 'BLAKE',
33
+ suggestion: `Listicle or resource roundup for your audience` })
34
+
35
+ // Newsletter: 1 per week
36
+ items.push({ day: 'Wednesday', type: 'newsletter', agent: 'PEARL',
37
+ suggestion: `Weekly digest + feature one product or win` })
38
+
39
+ // Social: 3 posts per week via HERMES/n8n
40
+ items.push({ day: 'Tuesday', type: 'social', agent: 'HERMES',
41
+ suggestion: `Repurpose Monday blog post for LinkedIn/X` })
42
+ items.push({ day: 'Friday', type: 'social', agent: 'HERMES',
43
+ suggestion: `Behind-the-scenes or community engagement post` })
44
+
45
+ weeks.push({ week: w, items })
46
+ }
47
+
48
+ return {
49
+ business: this.ctx.profile.title,
50
+ weeks_ahead: weeksAhead,
51
+ calendar: weeks,
52
+ strategy: this.growthStrategy(profile, products),
53
+ }
54
+ }
55
+
56
+ async growthAudit() {
57
+ await this.init()
58
+ const snap = await analyticsAgent.snapshot()
59
+ const drafts = await blogWriter.list({ published: false })
60
+
61
+ const totalTraffic = snap.profile?.total_clicks ?? 0
62
+ const totalRevenue = snap.products.reduce((a, p) => a + p.revenue, 0)
63
+ const conversionRate = totalTraffic > 0
64
+ ? ((snap.profile?.total_sales ?? 0) / totalTraffic * 100).toFixed(2) + '%'
65
+ : 'no data'
66
+
67
+ return {
68
+ traffic: totalTraffic,
69
+ revenue: totalRevenue,
70
+ conversion_rate: conversionRate,
71
+ draft_count: drafts.length,
72
+ top_referrers: snap.profile?.top_referrers ?? [],
73
+ gaps: this.contentGaps(snap),
74
+ }
75
+ }
76
+
77
+ private contentGaps(snap: Awaited<ReturnType<typeof analyticsAgent.snapshot>>): string[] {
78
+ const gaps: string[] = []
79
+ const types = new Set(snap.products.map(p => p.type))
80
+
81
+ if (!types.has('course')) gaps.push('No course — add a course to build passive revenue')
82
+ if (!types.has('service')) gaps.push('No services — add a service offering for quick revenue')
83
+ if (!types.has('sponsorship')) gaps.push('Sponsorships page missing — monetize your audience directly')
84
+ if ((snap.profile?.total_clicks ?? 0) < 100) gaps.push('Traffic too low — prioritize SEO content (ask SCOUT + BLAKE)')
85
+ if (snap.links.length === 0) gaps.push('No link-in-bio links — add key links to drive traffic')
86
+
87
+ return gaps
88
+ }
89
+
90
+ private growthStrategy(
91
+ profile: Awaited<ReturnType<typeof analyticsAgent.snapshot>>['profile'],
92
+ products: Awaited<ReturnType<typeof analyticsAgent.snapshot>>['products']
93
+ ): string[] {
94
+ const recs: string[] = []
95
+ if ((profile?.total_clicks ?? 0) < 500)
96
+ recs.push('Focus: publish 2 SEO-optimized blog posts per week for the next 30 days.')
97
+ if (products.length === 0)
98
+ recs.push('No products live. Launch your first paid product this week — even a $9 download.')
99
+ if (products.length > 0 && (profile?.total_sales ?? 0) === 0)
100
+ recs.push('Products exist but no sales. Review pricing, add social proof, drive traffic via HERMES.')
101
+ return recs
102
+ }
103
+ }
104
+
105
+ interface CalendarItem {
106
+ day: string; type: 'blog' | 'newsletter' | 'social' | 'product'; agent: string; suggestion: string
107
+ }
108
+
109
+ export const cmo = new CMO()