@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.
Files changed (68) hide show
  1. package/.claude/settings.json +16 -0
  2. package/.claude/settings.local.json +11 -0
  3. package/.env.example +10 -0
  4. package/CLAUDE.md +32 -13
  5. package/PLAN.md +95 -134
  6. package/REFERENCE.md +60 -24
  7. package/agents/_base.ts +352 -44
  8. package/agents/analytics/SOUL.md +11 -0
  9. package/agents/analytics/analytics.ts +405 -0
  10. package/agents/business/SOUL.md +11 -0
  11. package/agents/{csuite/cbo.ts → business/business.ts} +2 -2
  12. package/agents/ceo/SOUL.md +15 -0
  13. package/agents/{csuite → ceo}/ceo.ts +33 -8
  14. package/agents/content/SOUL.md +11 -0
  15. package/agents/content/content.ts +379 -0
  16. package/agents/copywriting/SOUL.md +11 -0
  17. package/agents/courses/SOUL.md +11 -0
  18. package/agents/courses/courses.ts +451 -0
  19. package/agents/docs/SOUL.md +11 -0
  20. package/agents/forms/SOUL.md +11 -0
  21. package/agents/forms/forms.ts +364 -0
  22. package/agents/hiring/SOUL.md +11 -0
  23. package/agents/hiring/hiring.ts +314 -0
  24. package/agents/marketing/SOUL.md +15 -0
  25. package/agents/{csuite/cmo.ts → marketing/marketing.ts} +3 -3
  26. package/agents/newsletter/SOUL.md +11 -0
  27. package/agents/operations/SOUL.md +11 -0
  28. package/agents/operations/operations.ts +157 -0
  29. package/agents/sales/SOUL.md +44 -0
  30. package/agents/sales/sales.ts +883 -0
  31. package/agents/scheduler/SOUL.md +11 -0
  32. package/agents/{growth → scheduler}/scheduler.ts +2 -2
  33. package/agents/seo/SOUL.md +11 -0
  34. package/agents/{growth/seo-agent.ts → seo/seo.ts} +60 -54
  35. package/agents/social/SOUL.md +11 -0
  36. package/agents/social/social.ts +744 -0
  37. package/agents/store/SOUL.md +11 -0
  38. package/agents/store/store.ts +514 -0
  39. package/cli.ts +44 -25
  40. package/lib/cms.ts +88 -0
  41. package/lib/db.ts +58 -11
  42. package/lib/enums.ts +25 -0
  43. package/lib/groups.ts +122 -0
  44. package/lib/id.ts +38 -10
  45. package/lib/profile.ts +44 -8
  46. package/lib/schema.ts +2015 -0
  47. package/lib/validate.ts +33 -0
  48. package/package.json +1 -1
  49. package/scripts/generate-schema.ts +244 -0
  50. package/setup.ts +16 -2
  51. package/skills/schema/SKILL.md +57 -16
  52. package/tsconfig.json +2 -1
  53. package/agents/creators/blog-writer.ts +0 -347
  54. package/agents/creators/course-creator.ts +0 -106
  55. package/agents/creators/crm-agent.ts +0 -479
  56. package/agents/creators/forms-builder.ts +0 -90
  57. package/agents/creators/jobs-manager.ts +0 -82
  58. package/agents/creators/store-manager.ts +0 -138
  59. package/agents/csuite/coo.ts +0 -115
  60. package/agents/growth/analytics-agent.ts +0 -52
  61. package/agents/growth/social-agent.ts +0 -346
  62. /package/{ingest.md → .claude/commands/ingest.md} +0 -0
  63. /package/agents/{creators/copywriter.ts → copywriting/copywriting.ts} +0 -0
  64. /package/agents/{creators/docs-writer.ts → docs/docs.ts} +0 -0
  65. /package/agents/{creators/newsletter-writer.ts → newsletter/newsletter.ts} +0 -0
  66. /package/{ABOUT-ME.md → context/about-me.md} +0 -0
  67. /package/{brand-voice.md → context/brand-voice.md} +0 -0
  68. /package/{working-style.md → context/working-style.md} +0 -0
@@ -0,0 +1,379 @@
1
+ /**
2
+ * Content Agent — unified CMS writer (SEObot-quality).
3
+ *
4
+ * DB reality (see businesskit-files/content.ts):
5
+ * There is no `posts` / `notes` / `guides` / `compare` / `newsletter` table.
6
+ * Everything lives in ONE table: `content`. The "type" of content is
7
+ * encoded by `cms_id` (→ one row per section in the `cms` table, which in
8
+ * turn has a `category_id` like `cat_35` for blog, `cat_37` for notes, etc).
9
+ *
10
+ * Analytics are trigger-maintained:
11
+ * - content_analytics (1 row per content item) — scalar counts + JSON
12
+ * breakdowns. JSON is lazy-aggregated on dashboard page visit;
13
+ * `last_aggregated_at` throttles rebuilds. AGENTS MUST NOT REBUILD.
14
+ * - cms_analytics (1 row per cms page) — total_posts / total_draft /
15
+ * total_published maintained by trg_content_insert / update / delete.
16
+ *
17
+ * Supported kinds (pick one; maps to cms_id via category_id):
18
+ * blog, notes, guides, newsletter, compare, alternative, prompt, skills
19
+ *
20
+ * Quality bar (from SEObot research):
21
+ * - Min 1500 words for blog, 2500+ for ultimate-guide
22
+ * - SEO title ≤60 chars, meta description ≤160 chars
23
+ * - Excerpt is a hook sentence, not a summary
24
+ * - internal_links count maintained, sources JSON cited when factual
25
+ */
26
+
27
+ import { BaseAgent, db, ulid, iso } from '../_base.ts'
28
+ import { logMemory } from '../../lib/memory.ts'
29
+ import { ensureCmsRow } from '../../lib/cms.ts'
30
+
31
+ // ── Content "kinds" — the logical content type. Maps to cms_id at write. ────
32
+ // Kept as a stable public API so other agents (seo, operations, ceo, marketing)
33
+ // don't have to know about cms_id internals.
34
+ export type ContentKind =
35
+ | 'blog' | 'notes' | 'guides' | 'newsletter'
36
+ | 'compare' | 'alternative' | 'prompt' | 'skills'
37
+
38
+ // Back-compat alias — old callers said `ContentTable`, same values.
39
+ export type ContentTable = ContentKind
40
+
41
+ export type ContentType =
42
+ | 'blog'
43
+ | 'listicle'
44
+ | 'how-to'
45
+ | 'checklist'
46
+ | 'qa'
47
+ | 'versus'
48
+ | 'roundup'
49
+ | 'news'
50
+ | 'ultimate-guide'
51
+ | 'programmatic'
52
+
53
+ export interface WriteInput {
54
+ title: string
55
+ kind?: ContentKind // default: 'blog'
56
+ table?: ContentTable // back-compat alias for `kind`
57
+ topic?: string
58
+ content_type?: ContentType
59
+ target_keywords?: string[]
60
+ word_count_target?: number
61
+ collection_id?: string
62
+ publish?: boolean
63
+ }
64
+
65
+ export interface WriteResult {
66
+ id: string
67
+ kind: ContentKind
68
+ slug: string
69
+ title: string
70
+ word_count: number
71
+ content_type: ContentType
72
+ seo_title: string
73
+ seo_description: string
74
+ published: boolean
75
+ url: string
76
+ }
77
+
78
+ // Logical kind → category_id (seeded, stable — see DEFAULT_CMS_PAGES).
79
+ const KIND_CATEGORY: Record<ContentKind, string> = {
80
+ blog: 'cat_35',
81
+ notes: 'cat_37',
82
+ guides: 'cat_36',
83
+ newsletter: 'cat_20',
84
+ compare: 'cat_40',
85
+ alternative: 'cat_41',
86
+ prompt: 'cat_39',
87
+ skills: 'cat_38',
88
+ }
89
+
90
+ // Public URL path per kind — blog lives under /blog, everything else under /<kind>.
91
+ const KIND_ROUTE: Record<ContentKind, string> = {
92
+ blog: 'blog',
93
+ notes: 'notes',
94
+ guides: 'guides',
95
+ newsletter: 'n',
96
+ compare: 'compare',
97
+ alternative: 'alternative',
98
+ prompt: 'prompt',
99
+ skills: 'skills',
100
+ }
101
+
102
+ // Word-count target per content_type
103
+ const WORD_TARGETS: Record<ContentType, number> = {
104
+ 'blog': 1500,
105
+ 'listicle': 2000,
106
+ 'how-to': 2000,
107
+ 'checklist': 1200,
108
+ 'qa': 1500,
109
+ 'versus': 2000,
110
+ 'roundup': 2000,
111
+ 'news': 800,
112
+ 'ultimate-guide': 3000,
113
+ 'programmatic': 1000,
114
+ }
115
+
116
+ // `versus` is the content_type that belongs in the `compare` kind
117
+ const TYPE_KIND: Partial<Record<ContentType, ContentKind>> = {
118
+ 'versus': 'compare',
119
+ }
120
+
121
+ /** Resolve a cms_id for a logical content kind — creates missing rows on demand. */
122
+ export async function getCmsId(profileId: string, kind: ContentKind): Promise<string> {
123
+ return ensureCmsRow(profileId, KIND_CATEGORY[kind], {
124
+ slug: KIND_ROUTE[kind],
125
+ title: kind.charAt(0).toUpperCase() + kind.slice(1),
126
+ })
127
+ }
128
+
129
+ export class BlogWriter extends BaseAgent {
130
+ readonly name = 'Content'
131
+ readonly title = 'Content Agent'
132
+
133
+ // ── Write new content ──────────────────────────────────────────────────────
134
+
135
+ async write(input: WriteInput): Promise<WriteResult> {
136
+ await this.init()
137
+
138
+ const contentType = input.content_type ?? 'blog'
139
+ const kind = input.kind ?? input.table ?? TYPE_KIND[contentType] ?? 'blog'
140
+ const wordTarget = input.word_count_target ?? WORD_TARGETS[contentType]
141
+ const keywords = input.target_keywords ?? []
142
+
143
+ const cms_id = await getCmsId(this.profileId, kind)
144
+ const slug = await this.makeSlug(input.title, cms_id)
145
+ const id = ulid()
146
+ const ts = iso()
147
+
148
+ // Structural hint — Claude writes actual content when invoked via CLI/Code.
149
+ const structureHint = this.structureForType(contentType, wordTarget, keywords)
150
+ const content = await this.generateContent(input.title, input.topic ?? input.title, structureHint, keywords)
151
+ const excerpt = await this.generateExcerpt(content, contentType)
152
+ const seoTitle = await this.generateSEOTitle(input.title, keywords)
153
+ const seoDesc = await this.generateSEODescription(content, keywords)
154
+ const wordCount = this.countWords(content)
155
+ const readingTime = Math.ceil(wordCount / 200)
156
+ const internalLinks = await this.countInternalLinks(input.title, keywords)
157
+
158
+ await db.write({
159
+ sql: `INSERT INTO content
160
+ (id, cms_id, category_id, profile_id, user_id, slug, title,
161
+ content, excerpt, published, hidden, collection_id,
162
+ seo_title, seo_description, seo_keywords,
163
+ word_count, reading_time_mins, internal_links, sources,
164
+ created_at, updated_at)
165
+ VALUES (?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,?,?,'[]',?,?)`,
166
+ args: [
167
+ id, cms_id, KIND_CATEGORY[kind], this.profileId, this.userId, slug, input.title,
168
+ content, excerpt, input.publish ? 1 : 0,
169
+ input.collection_id ?? null,
170
+ seoTitle, seoDesc,
171
+ keywords.length ? JSON.stringify(keywords) : null,
172
+ wordCount, readingTime, internalLinks,
173
+ ts, ts,
174
+ ],
175
+ })
176
+
177
+ await logMemory(this.agentType,
178
+ `${input.publish ? 'Published' : 'Drafted'} "${input.title}" (${kind}/${contentType}, ${wordCount} words)`,
179
+ { id, kind, slug, content_type: contentType, word_count: wordCount })
180
+
181
+ return {
182
+ id, kind, slug, title: input.title,
183
+ word_count: wordCount, content_type: contentType,
184
+ seo_title: seoTitle, seo_description: seoDesc,
185
+ published: !!input.publish,
186
+ url: `https://${this.ctx.profile.slug}.businesskit.io/${KIND_ROUTE[kind]}/${slug}`,
187
+ }
188
+ }
189
+
190
+ // ── List + manage (unified table, filter by cms_id/kind) ──────────────────
191
+
192
+ async listDrafts(kind: ContentKind = 'blog') {
193
+ await this.init()
194
+ const cms_id = await getCmsId(this.profileId, kind)
195
+ const { rows } = await db.execute({
196
+ sql: `SELECT id, title, slug, word_count, created_at, updated_at
197
+ FROM content
198
+ WHERE profile_id=? AND cms_id=? AND published=0 AND hidden=0
199
+ ORDER BY updated_at DESC LIMIT 20`,
200
+ args: [this.profileId, cms_id],
201
+ })
202
+ return rows
203
+ }
204
+
205
+ async listPublished(kind: ContentKind = 'blog', limit = 20) {
206
+ await this.init()
207
+ const cms_id = await getCmsId(this.profileId, kind)
208
+ const { rows } = await db.execute({
209
+ sql: `SELECT id, title, slug, word_count, created_at, updated_at
210
+ FROM content
211
+ WHERE profile_id=? AND cms_id=? AND published=1 AND hidden=0
212
+ ORDER BY updated_at DESC LIMIT ?`,
213
+ args: [this.profileId, cms_id, limit],
214
+ })
215
+ return rows
216
+ }
217
+
218
+ /** Publish (trigger flips cms_analytics draft→published). */
219
+ async publishContent(id: string) {
220
+ await this.init()
221
+ await db.write({
222
+ sql: `UPDATE content SET published=1, updated_at=?
223
+ WHERE id=? AND profile_id=?`,
224
+ args: [iso(), id, this.profileId],
225
+ })
226
+ const { rows: [r] } = await db.execute({
227
+ sql: `SELECT title, slug FROM content WHERE id=? AND profile_id=? LIMIT 1`,
228
+ args: [id, this.profileId],
229
+ })
230
+ if (r) await logMemory(this.agentType, `Published "${r.title}"`, { id, slug: r.slug })
231
+ }
232
+
233
+ async unpublish(id: string) {
234
+ await this.init()
235
+ await db.write({
236
+ sql: `UPDATE content SET published=0, updated_at=?
237
+ WHERE id=? AND profile_id=?`,
238
+ args: [iso(), id, this.profileId],
239
+ })
240
+ }
241
+
242
+ /** Soft archive — never hard DELETE (that would fire trg_content_delete and
243
+ * decrement counters). hidden=1 keeps counters intact. */
244
+ async archiveContent(id: string) {
245
+ await this.init()
246
+ await db.write({
247
+ sql: `UPDATE content SET hidden=1, updated_at=?
248
+ WHERE id=? AND profile_id=?`,
249
+ args: [iso(), id, this.profileId],
250
+ })
251
+ }
252
+
253
+ // ── Content inventory — free via cms_analytics (trigger-maintained) ───────
254
+
255
+ async inventory() {
256
+ await this.init()
257
+ const { rows } = await db.execute({
258
+ sql: `SELECT c.slug AS kind, c.category_id,
259
+ a.total_posts, a.total_published, a.total_draft
260
+ FROM cms c
261
+ LEFT JOIN cms_analytics a ON a.cms_id = c.id
262
+ WHERE c.profile_id=?`,
263
+ args: [this.profileId],
264
+ })
265
+
266
+ const out: Record<string, { total: number; published: number; drafts: number }> = {}
267
+ for (const r of rows) {
268
+ const k = String(r.kind ?? r.category_id)
269
+ out[k] = {
270
+ total: Number(r.total_posts ?? 0),
271
+ published: Number(r.total_published ?? 0),
272
+ drafts: Number(r.total_draft ?? 0),
273
+ }
274
+ }
275
+ return out
276
+ }
277
+
278
+ // ── SEO quality audit ─────────────────────────────────────────────────────
279
+
280
+ async seoAudit(kind: ContentKind = 'blog') {
281
+ await this.init()
282
+ const cms_id = await getCmsId(this.profileId, kind)
283
+ const { rows } = await db.execute({
284
+ sql: `SELECT id, title, slug, excerpt, seo_title, seo_description, word_count
285
+ FROM content
286
+ WHERE profile_id=? AND cms_id=? AND published=1 AND hidden=0`,
287
+ args: [this.profileId, cms_id],
288
+ })
289
+
290
+ const issues: Array<{ id: string; title: string; problems: string[] }> = []
291
+ for (const r of rows) {
292
+ const problems: string[] = []
293
+ if (!r.excerpt) problems.push('missing excerpt')
294
+ if (!r.seo_title) problems.push('missing seo_title')
295
+ if (!r.seo_description) problems.push('missing seo_description')
296
+ if (r.seo_title && String(r.seo_title).length > 60) problems.push('seo_title too long (>60)')
297
+ if (r.seo_description && String(r.seo_description).length > 160) problems.push('seo_description too long (>160)')
298
+ if (Number(r.word_count ?? 0) < 300) problems.push('too short (<300 words)')
299
+ if (!r.slug || String(r.slug).includes(' ')) problems.push('bad slug')
300
+ if (problems.length) issues.push({ id: r.id as string, title: r.title as string, problems })
301
+ }
302
+ return issues
303
+ }
304
+
305
+ // ── Private helpers ───────────────────────────────────────────────────────
306
+
307
+ private structureForType(type: ContentType, wordTarget: number, keywords: string[]): string {
308
+ const kw = keywords.length ? `Target keywords: ${keywords.join(', ')}. ` : ''
309
+ const structures: Record<ContentType, string> = {
310
+ 'blog': `${kw}Write a comprehensive blog post. Intro hook → 3-5 main sections with H2s → conclusion with CTA. ~${wordTarget} words.`,
311
+ 'listicle': `${kw}Write a numbered listicle. Hook intro → numbered items (H3 each, 2-3 sentences, practical tip) → summary. 7-15 items. ~${wordTarget} words.`,
312
+ 'how-to': `${kw}Write a step-by-step how-to. Problem intro → numbered steps (H3 each, clear action, why it matters) → result. ~${wordTarget} words.`,
313
+ 'checklist': `${kw}Write a practical checklist. Short intro → grouped checklist items with brief explanations → conclusion. Imperative language. ~${wordTarget} words.`,
314
+ 'qa': `${kw}Write a Q&A article. Short intro → 8-12 questions as H2s with 2-4 sentence answers → summary. Address real search queries. ~${wordTarget} words.`,
315
+ 'versus': `${kw}Write a versus comparison. TL;DR verdict → feature table → pros/cons each option → who should use what → verdict. ~${wordTarget} words.`,
316
+ 'roundup': `${kw}Write a curated roundup. Criteria intro → each option (H3, 2-3 sentences, best for who) → comparison table → top pick. ~${wordTarget} words.`,
317
+ 'news': `${kw}Write a news article. Lead paragraph (who/what/when/where/why) → context → implications → sources cited. ~${wordTarget} words. Cite all facts.`,
318
+ 'ultimate-guide':`${kw}Write a definitive ultimate guide. Executive summary → TOC → deep-dive sections (H2+H3) → examples → FAQs → conclusion. ~${wordTarget}+ words.`,
319
+ 'programmatic': `${kw}Write an SEO-optimized page. Clear H1 → key info table → main content → FAQs → CTA. Concise, factual. ~${wordTarget} words.`,
320
+ }
321
+ return structures[type]
322
+ }
323
+
324
+ private async generateContent(_title: string, _topic: string, structure: string, _keywords: string[]): Promise<string> {
325
+ // Claude, the runtime LLM, fills this in when invoked via CLI / Code.
326
+ return `<!-- Agent: generate ${structure} -->`
327
+ }
328
+
329
+ private async generateExcerpt(_content: string, type: ContentType): Promise<string> {
330
+ return `<!-- Agent: write a 1-sentence hook excerpt for this ${type} -->`
331
+ }
332
+
333
+ private async generateSEOTitle(title: string, keywords: string[]): Promise<string> {
334
+ const kw = keywords[0] ?? ''
335
+ const base = kw && !title.toLowerCase().includes(kw.toLowerCase())
336
+ ? `${title} | ${kw}` : title
337
+ return base.slice(0, 60)
338
+ }
339
+
340
+ private async generateSEODescription(_content: string, keywords: string[]): Promise<string> {
341
+ return `<!-- Agent: write 155-char meta description including: ${keywords.join(', ')} -->`
342
+ }
343
+
344
+ /** Count of internal-link candidates — stored as an integer on content. */
345
+ private async countInternalLinks(title: string, keywords: string[]): Promise<number> {
346
+ try {
347
+ const search = keywords[0] ?? title.split(' ')[0]
348
+ const { rows: [r] } = await db.execute({
349
+ sql: `SELECT COUNT(*) AS n FROM content
350
+ WHERE profile_id=? AND published=1 AND hidden=0
351
+ AND (title LIKE ? OR slug LIKE ?)`,
352
+ args: [this.profileId, `%${search}%`, `%${search}%`],
353
+ })
354
+ return Math.min(3, Number(r?.n ?? 0))
355
+ } catch { return 0 }
356
+ }
357
+
358
+ private async makeSlug(title: string, cms_id: string): Promise<string> {
359
+ const base = title.toLowerCase()
360
+ .replace(/[^a-z0-9\s-]/g, '')
361
+ .replace(/\s+/g, '-')
362
+ .replace(/-+/g, '-')
363
+ .slice(0, 80)
364
+
365
+ // Unique index is (profile_id, category_id, slug). Dedupe per cms section.
366
+ const { rows: [exists] } = await db.execute({
367
+ sql: `SELECT slug FROM content
368
+ WHERE profile_id=? AND cms_id=? AND slug=? LIMIT 1`,
369
+ args: [this.profileId, cms_id, base],
370
+ })
371
+ return exists ? `${base}-${Date.now().toString(36)}` : base
372
+ }
373
+
374
+ private countWords(content: string): number {
375
+ return content.replace(/<[^>]+>/g, '').split(/\s+/).filter(Boolean).length
376
+ }
377
+ }
378
+
379
+ export const blogWriter = new BlogWriter()
@@ -0,0 +1,11 @@
1
+ # copywriting
2
+
3
+ Placeholder SOUL. See CLAUDE.md routing table and skills/copywriting/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
@@ -0,0 +1,11 @@
1
+ # courses
2
+
3
+ Placeholder SOUL. See CLAUDE.md routing table and skills/courses/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