@businesskit/agent 1.0.3 → 1.0.4
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.
- package/.claude/settings.json +16 -0
- package/.claude/settings.local.json +11 -0
- package/.env.example +10 -0
- package/CLAUDE.md +32 -13
- package/PLAN.md +95 -134
- package/REFERENCE.md +60 -24
- package/agents/_base.ts +352 -44
- package/agents/analytics/SOUL.md +11 -0
- package/agents/analytics/analytics.ts +405 -0
- package/agents/business/SOUL.md +11 -0
- package/agents/{csuite/cbo.ts → business/business.ts} +2 -2
- package/agents/ceo/SOUL.md +15 -0
- package/agents/{csuite → ceo}/ceo.ts +33 -8
- package/agents/content/SOUL.md +11 -0
- package/agents/content/content.ts +379 -0
- package/agents/copywriting/SOUL.md +11 -0
- package/agents/courses/SOUL.md +11 -0
- package/agents/courses/courses.ts +451 -0
- package/agents/docs/SOUL.md +11 -0
- package/agents/forms/SOUL.md +11 -0
- package/agents/forms/forms.ts +364 -0
- package/agents/hiring/SOUL.md +11 -0
- package/agents/hiring/hiring.ts +314 -0
- package/agents/marketing/SOUL.md +15 -0
- package/agents/{csuite/cmo.ts → marketing/marketing.ts} +3 -3
- package/agents/newsletter/SOUL.md +11 -0
- package/agents/operations/SOUL.md +11 -0
- package/agents/operations/operations.ts +157 -0
- package/agents/sales/SOUL.md +44 -0
- package/agents/sales/sales.ts +883 -0
- package/agents/scheduler/SOUL.md +11 -0
- package/agents/{growth → scheduler}/scheduler.ts +2 -2
- package/agents/seo/SOUL.md +11 -0
- package/agents/{growth/seo-agent.ts → seo/seo.ts} +60 -54
- package/agents/social/SOUL.md +11 -0
- package/agents/social/social.ts +744 -0
- package/agents/store/SOUL.md +11 -0
- package/agents/store/store.ts +514 -0
- package/cli.ts +44 -25
- package/lib/cms.ts +88 -0
- package/lib/db.ts +58 -11
- package/lib/enums.ts +25 -0
- package/lib/groups.ts +122 -0
- package/lib/id.ts +38 -10
- package/lib/profile.ts +44 -8
- package/lib/schema.ts +2015 -0
- package/lib/validate.ts +33 -0
- package/package.json +1 -1
- package/scripts/generate-schema.ts +244 -0
- package/setup.ts +16 -2
- package/skills/schema/SKILL.md +57 -16
- package/tsconfig.json +2 -1
- package/agents/creators/blog-writer.ts +0 -347
- package/agents/creators/course-creator.ts +0 -106
- package/agents/creators/crm-agent.ts +0 -479
- package/agents/creators/forms-builder.ts +0 -90
- package/agents/creators/jobs-manager.ts +0 -82
- package/agents/creators/store-manager.ts +0 -138
- package/agents/csuite/coo.ts +0 -115
- package/agents/growth/analytics-agent.ts +0 -52
- package/agents/growth/social-agent.ts +0 -346
- /package/{ingest.md → .claude/commands/ingest.md} +0 -0
- /package/agents/{creators/copywriter.ts → copywriting/copywriting.ts} +0 -0
- /package/agents/{creators/docs-writer.ts → docs/docs.ts} +0 -0
- /package/agents/{creators/newsletter-writer.ts → newsletter/newsletter.ts} +0 -0
- /package/{ABOUT-ME.md → context/about-me.md} +0 -0
- /package/{brand-voice.md → context/brand-voice.md} +0 -0
- /package/{working-style.md → context/working-style.md} +0 -0
|
@@ -0,0 +1,405 @@
|
|
|
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()
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { BaseAgent, db } from '../_base.ts'
|
|
9
|
-
import { analyticsAgent } from '../
|
|
10
|
-
import { storeManager } from '../
|
|
9
|
+
import { analyticsAgent } from '../analytics/analytics.ts'
|
|
10
|
+
import { storeManager } from '../store/store.ts'
|
|
11
11
|
|
|
12
12
|
export class CBO extends BaseAgent {
|
|
13
13
|
readonly name = 'REX'
|
|
@@ -0,0 +1,15 @@
|
|
|
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.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { BaseAgent, db } from '../_base.ts'
|
|
10
|
-
import { analyticsAgent } from '../
|
|
10
|
+
import { analyticsAgent } from '../analytics/analytics.ts'
|
|
11
11
|
|
|
12
12
|
export class CEO extends BaseAgent {
|
|
13
13
|
readonly name = 'ARIA'
|
|
@@ -35,12 +35,37 @@ export class CEO extends BaseAgent {
|
|
|
35
35
|
|
|
36
36
|
async fullInventory() {
|
|
37
37
|
await this.init()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
41
66
|
}
|
|
42
67
|
|
|
43
|
-
toMarkdown(briefing: Awaited<ReturnType<
|
|
68
|
+
toMarkdown(briefing: Awaited<ReturnType<CEO['weeklyBriefing']>>): string {
|
|
44
69
|
const { business, generated, revenue, traffic, top_products, inventory, recommendations } = briefing
|
|
45
70
|
return `# Weekly Briefing — ${business}
|
|
46
71
|
_${new Date(generated).toDateString()}_
|
|
@@ -100,10 +125,10 @@ ${recommendations.map((r, i) => `${i + 1}. ${r}`).join('\n')}
|
|
|
100
125
|
const recs: string[] = []
|
|
101
126
|
|
|
102
127
|
if (!snap.profile) recs.push('Connect ATLAS — no analytics data yet.')
|
|
103
|
-
if ((inventory.
|
|
128
|
+
if ((inventory.blog?.live ?? 0) < 3)
|
|
104
129
|
recs.push('Publish at least 3 blog posts. Consistency drives organic traffic.')
|
|
105
|
-
if ((inventory.
|
|
106
|
-
recs.push(`${inventory.
|
|
130
|
+
if ((inventory.blog?.drafts ?? 0) > 0)
|
|
131
|
+
recs.push(`${inventory.blog.drafts} draft post(s) ready. Ask BLAKE to review and publish.`)
|
|
107
132
|
|
|
108
133
|
const hasNoProduct = !snap.products.some(p => p.type === 'course')
|
|
109
134
|
if (hasNoProduct) recs.push('No courses yet. Ask SAGE to create one — courses drive 3–10x revenue per customer.')
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|