@businesskit/agent 1.0.3 → 1.0.5

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 (130) 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 +32 -0
  5. package/AGENTS.md +94 -63
  6. package/CLAUDE.md +11 -65
  7. package/GEMINI.md +11 -34
  8. package/README.md +106 -153
  9. package/assets/logo.svg +3 -0
  10. package/bin/businesskit.js +11 -17
  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/capabilities.md +33 -0
  15. package/commands/check-stock.md +43 -0
  16. package/commands/create-component.md +109 -0
  17. package/commands/create-invoice.md +69 -0
  18. package/commands/create-new-bill.md +65 -0
  19. package/commands/create-page.md +96 -0
  20. package/commands/list-components.md +41 -0
  21. package/commands/list-content.md +46 -0
  22. package/commands/list-pages.md +45 -0
  23. package/commands/publish-page.md +64 -0
  24. package/commands/send-invoice.md +42 -0
  25. package/commands/seo-audit.md +36 -0
  26. package/commands/update-contact.md +46 -0
  27. package/commands/update-content.md +47 -0
  28. package/commands/update-page.md +55 -0
  29. package/commands/update-price.md +47 -0
  30. package/commands/write-blog.md +52 -0
  31. package/commands/write-docs.md +84 -0
  32. package/commands/write-guide.md +46 -0
  33. package/commands/write-newsletter.md +46 -0
  34. package/mcp_config.json +8 -0
  35. package/package.json +34 -23
  36. package/plugin.json +32 -0
  37. package/scripts/generate-schema.ts +244 -0
  38. package/scripts/setup.sh +134 -0
  39. package/scripts/setup.ts +92 -0
  40. package/server.json +21 -0
  41. package/skills/README.md +19 -27
  42. package/skills/billing/SKILL.md +64 -0
  43. package/skills/brand/SKILL.md +30 -86
  44. package/skills/copywriting/SKILL.md +1 -1
  45. package/skills/crm/SKILL.md +38 -0
  46. package/skills/docs-cms/SKILL.md +53 -0
  47. package/skills/docs-cms/references/how-to.md +383 -0
  48. package/skills/inbox/SKILL.md +49 -0
  49. package/skills/inventory/SKILL.md +69 -0
  50. package/skills/pages/SKILL.md +169 -0
  51. package/skills/pages/references/sections-catalog.json +950 -0
  52. package/skills/social/SKILL.md +1 -1
  53. package/templates/antigravity.json +8 -0
  54. package/templates/claude-code.mcp.json +8 -0
  55. package/templates/cursor.mcp.json +8 -0
  56. package/templates/vscode.mcp.json +9 -0
  57. package/.claude/commands/analytics.md +0 -7
  58. package/.claude/commands/blog-writer.md +0 -9
  59. package/.claude/commands/cbo.md +0 -7
  60. package/.claude/commands/ceo.md +0 -10
  61. package/.claude/commands/cmo.md +0 -7
  62. package/.claude/commands/compress.md +0 -73
  63. package/.claude/commands/coo.md +0 -11
  64. package/.claude/commands/copywriter.md +0 -15
  65. package/.claude/commands/course-creator.md +0 -9
  66. package/.claude/commands/crm.md +0 -591
  67. package/.claude/commands/deep.md +0 -50
  68. package/.claude/commands/docs-writer.md +0 -8
  69. package/.claude/commands/forms-builder.md +0 -10
  70. package/.claude/commands/jobs-manager.md +0 -8
  71. package/.claude/commands/kb.md +0 -107
  72. package/.claude/commands/newsletter-writer.md +0 -9
  73. package/.claude/commands/preserve.md +0 -64
  74. package/.claude/commands/resume.md +0 -67
  75. package/.claude/commands/scheduler.md +0 -8
  76. package/.claude/commands/seo.md +0 -60
  77. package/.claude/commands/social.md +0 -51
  78. package/.claude/commands/store-manager.md +0 -11
  79. package/.env.example +0 -2
  80. package/.mcp.json +0 -3
  81. package/ABOUT-ME.md +0 -96
  82. package/HEARTBEAT.md +0 -105
  83. package/PLAN.md +0 -384
  84. package/PRD-Agent-Composition.md +0 -149
  85. package/PRD-Agent-Harness.md +0 -316
  86. package/REFERENCE.md +0 -124
  87. package/SOUL.md +0 -148
  88. package/SYSTEM.md +0 -71
  89. package/agents/_base.ts +0 -63
  90. package/agents/creators/blog-writer.ts +0 -347
  91. package/agents/creators/copywriter.ts +0 -89
  92. package/agents/creators/course-creator.ts +0 -106
  93. package/agents/creators/crm-agent.ts +0 -479
  94. package/agents/creators/docs-writer.ts +0 -77
  95. package/agents/creators/forms-builder.ts +0 -90
  96. package/agents/creators/jobs-manager.ts +0 -82
  97. package/agents/creators/newsletter-writer.ts +0 -91
  98. package/agents/creators/store-manager.ts +0 -138
  99. package/agents/csuite/cbo.ts +0 -109
  100. package/agents/csuite/ceo.ts +0 -121
  101. package/agents/csuite/cmo.ts +0 -109
  102. package/agents/csuite/coo.ts +0 -115
  103. package/agents/growth/analytics-agent.ts +0 -52
  104. package/agents/growth/scheduler.ts +0 -68
  105. package/agents/growth/seo-agent.ts +0 -282
  106. package/agents/growth/social-agent.ts +0 -346
  107. package/brand-voice.md +0 -127
  108. package/cli.ts +0 -125
  109. package/context/brand.md +0 -80
  110. package/context/business.md +0 -66
  111. package/ingest.md +0 -110
  112. package/lib/analytics.ts +0 -81
  113. package/lib/db.adapter.ts +0 -30
  114. package/lib/db.ts +0 -16
  115. package/lib/id.ts +0 -15
  116. package/lib/kb.ts +0 -337
  117. package/lib/memory.ts +0 -219
  118. package/lib/pattern-detector.ts +0 -169
  119. package/lib/profile.ts +0 -119
  120. package/lib/slug.ts +0 -30
  121. package/setup.ts +0 -127
  122. package/skills/agents/SKILL.md +0 -56
  123. package/skills/analytics/SKILL.md +0 -52
  124. package/skills/blog-writer/SKILL.md +0 -452
  125. package/skills/ceo/SKILL.md +0 -25
  126. package/skills/cmo/SKILL.md +0 -8
  127. package/skills/schema/SKILL.md +0 -45
  128. package/skills/store/SKILL.md +0 -62
  129. package/tsconfig.json +0 -13
  130. package/working-style.md +0 -87
package/agents/_base.ts DELETED
@@ -1,63 +0,0 @@
1
- import { db } from '../lib/db.ts'
2
- import { getBrandContext, type BrandContext } from '../lib/profile.ts'
3
- import { ulid, now, iso } from '../lib/id.ts'
4
- import type { Client } from '@libsql/client'
5
-
6
- /** Singleton Turso client — agents may import `db` for raw queries */
7
- export { db, ulid, now, iso }
8
-
9
- /**
10
- * BaseAgent — extend this for every agent.
11
- *
12
- * Provides:
13
- * - this.ctx → BrandContext (profile, settings, credentials)
14
- * - this.profileId → enforced on every write
15
- * - this.userId → from profile
16
- * - this.archive() → soft delete (hidden=1) for any table
17
- * - this.publish() → flip published=1 for any table
18
- * - this.count() → content inventory for any table
19
- */
20
- export abstract class BaseAgent {
21
- protected ctx!: BrandContext
22
- protected db: Client
23
-
24
- constructor(injectedDB?: Client) {
25
- this.db = injectedDB ?? db
26
- }
27
-
28
- /** Call at the start of any agent method that needs the DB */
29
- protected async init() {
30
- if (!this.ctx) this.ctx = await getBrandContext(this.db)
31
- }
32
-
33
- protected get profileId() { return this.ctx.profile.id }
34
- protected get userId() { return this.ctx.profile.user_id }
35
-
36
- /** Soft delete — never hard delete */
37
- protected async archive(table: string, id: string | number) {
38
- const ts = typeof id === 'number'
39
- ? `updated_at='${iso()}'`
40
- : `updated_at=${now()}`
41
- await this.db.execute({ sql: `UPDATE ${table} SET hidden=1,${ts} WHERE id=?`, args: [id] })
42
- }
43
-
44
- /** Publish any content row */
45
- protected async publish(table: string, id: string | number) {
46
- const ts = typeof id === 'number'
47
- ? `updated_at='${iso()}'`
48
- : `updated_at=${now()}`
49
- await this.db.execute({ sql: `UPDATE ${table} SET published=1,${ts} WHERE id=?`, args: [id] })
50
- }
51
-
52
- /** Quick inventory: { total, live, drafts } */
53
- protected async count(table: string) {
54
- const { rows: [r] } = await this.db.execute({
55
- sql: `SELECT COUNT(*) total,
56
- SUM(CASE WHEN published=1 AND hidden=0 THEN 1 ELSE 0 END) live,
57
- SUM(CASE WHEN published=0 AND hidden=0 THEN 1 ELSE 0 END) drafts
58
- FROM ${table} WHERE profile_id=?`,
59
- args: [this.profileId],
60
- })
61
- return { total: Number(r?.total ?? 0), live: Number(r?.live ?? 0), drafts: Number(r?.drafts ?? 0) }
62
- }
63
- }
@@ -1,347 +0,0 @@
1
- /**
2
- * Blog Writer — SEObot-quality content agent
3
- *
4
- * Produces 8 content formats from content.ts:
5
- * posts → blog: listicle, how-to, checklist, qa, versus, roundup, news, ultimate-guide
6
- * compare → "X vs Y" programmatic SEO pages
7
- * alternative → "Best alternatives to X" pages
8
- * prompt → prompt library articles
9
- * notes → short-form notes
10
- * guides → long-form step-by-step guides
11
- * newsletter → email newsletter content
12
- *
13
- * Quality bar (from SEObot research):
14
- * - Min 1500 words for blog, 2500+ for ultimate-guide
15
- * - SEO title ≤60 chars, meta description ≤160 chars
16
- * - Excerpt is a hook sentence, not a summary
17
- * - internal_links: link to 2-3 related posts in same profile
18
- * - sources: cite real URLs when making factual claims
19
- * - content_type drives structure (listicle ≠ how-to ≠ qa)
20
- *
21
- * Tables written: posts, compare, alternative, prompt, notes, guides, newsletter
22
- */
23
-
24
- import { BaseAgent, db, ulid, iso } from '../_base.ts'
25
- import { logMemory } from '../../lib/memory.ts'
26
-
27
- export type ContentType =
28
- | 'blog' // generic post
29
- | 'listicle' // "Top 10 X" — numbered list with explanations
30
- | 'how-to' // "How to X" — step by step
31
- | 'checklist' // "X Checklist" — checkbox format
32
- | 'qa' // "What is X? FAQs" — question/answer pairs
33
- | 'versus' // "X vs Y" — comparison post (uses compare table)
34
- | 'roundup' // "Best X tools/resources" — curated list
35
- | 'news' // timely news summary with source links
36
- | 'ultimate-guide'// definitive long-form guide 2500+ words
37
- | 'programmatic' // template-based SEO at scale
38
-
39
- export type ContentTable =
40
- | 'posts' | 'compare' | 'alternative' | 'prompt'
41
- | 'notes' | 'guides' | 'newsletter'
42
-
43
- export interface WriteInput {
44
- title: string
45
- topic?: string // if different from title
46
- content_type?: ContentType
47
- table?: ContentTable // default: 'posts'
48
- target_keywords?: string[]
49
- word_count_target?: number // default varies by type
50
- collection_id?: string
51
- publish?: boolean // default: false (draft)
52
- }
53
-
54
- export interface WriteResult {
55
- id: string
56
- table: ContentTable
57
- slug: string
58
- title: string
59
- word_count: number
60
- content_type: ContentType
61
- seo_title: string
62
- seo_description: string
63
- published: boolean
64
- url: string
65
- }
66
-
67
- // Word count targets by content type
68
- const WORD_TARGETS: Record<ContentType, number> = {
69
- 'blog': 1500,
70
- 'listicle': 2000,
71
- 'how-to': 2000,
72
- 'checklist': 1200,
73
- 'qa': 1500,
74
- 'versus': 2000,
75
- 'roundup': 2000,
76
- 'news': 800,
77
- 'ultimate-guide': 3000,
78
- 'programmatic': 1000,
79
- }
80
-
81
- // Which table each type writes to by default
82
- const TYPE_TABLE: Partial<Record<ContentType, ContentTable>> = {
83
- 'versus': 'compare',
84
- }
85
-
86
- export class BlogWriter extends BaseAgent {
87
- readonly name = 'Blog Writer'
88
- readonly title = 'Blog Writer'
89
-
90
- // ── Write new content ───────────────────────────────────────────────────────
91
-
92
- async write(input: WriteInput): Promise<WriteResult> {
93
- await this.init()
94
-
95
- const contentType = input.content_type ?? 'blog'
96
- const table = input.table ?? TYPE_TABLE[contentType] ?? 'posts'
97
- const wordTarget = input.word_count_target ?? WORD_TARGETS[contentType]
98
- const slug = await this.makeSlug(input.title, table)
99
- const id = ulid()
100
- const now = iso()
101
- const keywords = input.target_keywords ?? []
102
-
103
- // Build content structure instructions per type
104
- const structureHint = this.structureForType(contentType, wordTarget, keywords)
105
-
106
- // Agent writes the actual content — this is the LLM's job
107
- // The method returns the structure; Claude fills in the words
108
- const content = await this.generateContent(input.title, input.topic ?? input.title, structureHint, keywords)
109
- const excerpt = await this.generateExcerpt(content, contentType)
110
- const seoTitle = await this.generateSEOTitle(input.title, keywords)
111
- const seoDesc = await this.generateSEODescription(content, keywords)
112
-
113
- const wordCount = this.countWords(content)
114
- const readingTime = Math.ceil(wordCount / 200)
115
-
116
- // Get internal links from existing posts
117
- const internalLinks = await this.findInternalLinks(input.title, keywords)
118
-
119
- if (table === 'posts') {
120
- await db.execute({
121
- sql: `INSERT INTO posts
122
- (id,profile_id,user_id,slug,title,content,excerpt,
123
- content_type,seo_title,seo_description,seo_keywords,
124
- word_count,reading_time_mins,internal_links,sources,
125
- published,hidden,collection_id,created_at,updated_at)
126
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,?,?,?)`,
127
- args: [
128
- id, this.profileId, this.userId, slug, input.title, content, excerpt,
129
- contentType, seoTitle, seoDesc,
130
- keywords.length ? JSON.stringify(keywords) : null,
131
- wordCount, readingTime,
132
- JSON.stringify(internalLinks), '[]',
133
- input.publish ? 1 : 0, null,
134
- input.collection_id ?? null, now, now,
135
- ],
136
- })
137
- } else {
138
- // compare, alternative, prompt, notes, guides, newsletter
139
- await db.execute({
140
- sql: `INSERT INTO ${table}
141
- (id,profile_id,user_id,slug,title,content,excerpt,
142
- published,hidden,collection_id,created_at,updated_at)
143
- VALUES (?,?,?,?,?,?,?,?,0,?,?,?)`,
144
- args: [
145
- id, this.profileId, this.userId, slug, input.title, content, excerpt,
146
- input.publish ? 1 : 0,
147
- input.collection_id ?? null, now, now,
148
- ],
149
- })
150
- }
151
-
152
- await logMemory('blog-writer',
153
- `${input.publish ? 'Published' : 'Drafted'} "${input.title}" (${contentType}, ${wordCount} words)`,
154
- { id, table, slug, content_type: contentType, word_count: wordCount }
155
- )
156
-
157
- return {
158
- id, table, slug, title: input.title,
159
- word_count: wordCount, content_type: contentType,
160
- seo_title: seoTitle, seo_description: seoDesc,
161
- published: !!input.publish,
162
- url: `https://${this.ctx.profile.slug}.businesskit.io/${table === 'posts' ? 'blog' : table}/${slug}`,
163
- }
164
- }
165
-
166
- // ── List + manage ───────────────────────────────────────────────────────────
167
-
168
- async listDrafts(table: ContentTable = 'posts') {
169
- await this.init()
170
- const { rows } = await db.execute({
171
- sql: `SELECT id,title,slug,content_type,word_count,created_at
172
- FROM ${table} WHERE profile_id=? AND published=0 AND hidden=0
173
- ORDER BY created_at DESC LIMIT 20`,
174
- args: [this.profileId],
175
- })
176
- return rows
177
- }
178
-
179
- async listPublished(table: ContentTable = 'posts', limit = 20) {
180
- await this.init()
181
- const { rows } = await db.execute({
182
- sql: `SELECT id,title,slug,content_type,word_count,created_at
183
- FROM ${table} WHERE profile_id=? AND published=1 AND hidden=0
184
- ORDER BY created_at DESC LIMIT ?`,
185
- args: [this.profileId, limit],
186
- })
187
- return rows
188
- }
189
-
190
- async publishContent(id: string, table: ContentTable = 'posts') {
191
- await this.init()
192
- await db.execute({
193
- sql: `UPDATE ${table} SET published=1,updated_at=? WHERE id=? AND profile_id=?`,
194
- args: [iso(), id, this.profileId],
195
- })
196
- const { rows: [r] } = await db.execute({
197
- sql: `SELECT title,slug FROM ${table} WHERE id=? LIMIT 1`,
198
- args: [id],
199
- })
200
- if (r) await logMemory('blog-writer', `Published "${r.title}"`, { id, table, slug: r.slug })
201
- }
202
-
203
- async unpublish(id: string, table: ContentTable = 'posts') {
204
- await this.init()
205
- await db.execute({
206
- sql: `UPDATE ${table} SET published=0,updated_at=? WHERE id=? AND profile_id=?`,
207
- args: [iso(), id, this.profileId],
208
- })
209
- }
210
-
211
- async archiveContent(id: string, table: ContentTable = 'posts') {
212
- await this.init()
213
- await db.execute({
214
- sql: `UPDATE ${table} SET hidden=1,updated_at=? WHERE id=? AND profile_id=?`,
215
- args: [iso(), id, this.profileId],
216
- })
217
- }
218
-
219
- // ── Content inventory across all tables ─────────────────────────────────────
220
-
221
- async inventory() {
222
- await this.init()
223
- const tables: ContentTable[] = ['posts', 'compare', 'alternative', 'prompt', 'notes', 'guides', 'newsletter']
224
- const results: Record<string, { published: number; drafts: number }> = {}
225
-
226
- for (const t of tables) {
227
- try {
228
- const { rows: [r] } = await db.execute({
229
- sql: `SELECT
230
- SUM(CASE WHEN published=1 AND hidden=0 THEN 1 ELSE 0 END) published,
231
- SUM(CASE WHEN published=0 AND hidden=0 THEN 1 ELSE 0 END) drafts
232
- FROM ${t} WHERE profile_id=?`,
233
- args: [this.profileId],
234
- })
235
- results[t] = { published: Number(r?.published ?? 0), drafts: Number(r?.drafts ?? 0) }
236
- } catch {
237
- results[t] = { published: 0, drafts: 0 }
238
- }
239
- }
240
- return results
241
- }
242
-
243
- // ── SEO quality audit ───────────────────────────────────────────────────────
244
-
245
- async seoAudit(table: ContentTable = 'posts') {
246
- await this.init()
247
- const { rows } = await db.execute({
248
- sql: `SELECT id,title,slug,excerpt,seo_title,seo_description,word_count,content_type
249
- FROM ${table} WHERE profile_id=? AND published=1 AND hidden=0`,
250
- args: [this.profileId],
251
- })
252
-
253
- const issues: Array<{ id: string; title: string; problems: string[] }> = []
254
- for (const r of rows) {
255
- const problems: string[] = []
256
- if (!r.excerpt) problems.push('missing excerpt')
257
- if (!r.seo_title) problems.push('missing seo_title')
258
- if (!r.seo_description) problems.push('missing seo_description')
259
- if (r.seo_title && String(r.seo_title).length > 60) problems.push('seo_title too long (>60)')
260
- if (r.seo_description && String(r.seo_description).length > 160) problems.push('seo_description too long (>160)')
261
- if (Number(r.word_count ?? 0) < 300) problems.push('too short (<300 words)')
262
- if (!r.slug || String(r.slug).includes(' ')) problems.push('bad slug')
263
- if (problems.length) issues.push({ id: r.id as string, title: r.title as string, problems })
264
- }
265
- return issues
266
- }
267
-
268
- // ── Private helpers ──────────────────────────────────────────────────────────
269
-
270
- private structureForType(type: ContentType, wordTarget: number, keywords: string[]): string {
271
- const kw = keywords.length ? `Target keywords: ${keywords.join(', ')}. ` : ''
272
-
273
- const structures: Record<ContentType, string> = {
274
- 'blog': `${kw}Write a comprehensive blog post. Intro hook → 3-5 main sections with H2s → conclusion with CTA. ~${wordTarget} words.`,
275
- 'listicle': `${kw}Write a numbered listicle. Hook intro → numbered items (each with H3, 2-3 sentences, practical tip) → summary. Aim for 7-15 items. ~${wordTarget} words.`,
276
- 'how-to': `${kw}Write a step-by-step how-to guide. Problem intro → numbered steps (each with H3, clear action, why it matters) → result/outcome. ~${wordTarget} words.`,
277
- 'checklist': `${kw}Write a practical checklist. Short intro → grouped checklist items with brief explanations → conclusion. Use clear imperative language. ~${wordTarget} words.`,
278
- '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.`,
279
- 'versus': `${kw}Write a versus comparison. TL;DR verdict first → feature table → pros/cons each option → who should use what → verdict. ~${wordTarget} words.`,
280
- 'roundup': `${kw}Write a curated roundup. Intro explaining criteria → each option with H3, 2-3 sentences, best for who → comparison table → top pick. ~${wordTarget} words.`,
281
- 'news': `${kw}Write a news article. Lead paragraph (who/what/when/where/why) → context → implications → sources cited. ~${wordTarget} words. Cite all facts.`,
282
- 'ultimate-guide':`${kw}Write a definitive ultimate guide. Executive summary → table of contents → deep-dive sections with H2+H3 hierarchy → examples → FAQs → conclusion. ~${wordTarget}+ words.`,
283
- 'programmatic': `${kw}Write an SEO-optimized page. Clear H1 → key info table → main content → FAQs → CTA. Concise and factual. ~${wordTarget} words.`,
284
- }
285
- return structures[type]
286
- }
287
-
288
- private async generateContent(title: string, topic: string, structure: string, keywords: string[]): Promise<string> {
289
- // In agent context: Claude IS the LLM. Claude writes this content directly.
290
- // This method returns the prompt structure; the agent fills it with real content.
291
- // When called from CLI or Claude Code, the agent generates and returns the content.
292
- return `<!-- Agent: generate ${structure} for title: "${title}" -->`
293
- }
294
-
295
- private async generateExcerpt(content: string, type: ContentType): Promise<string> {
296
- // Hook sentence, not a summary. Makes reader want to click.
297
- return `<!-- Agent: write a 1-sentence hook excerpt for this ${type} -->`
298
- }
299
-
300
- private async generateSEOTitle(title: string, keywords: string[]): Promise<string> {
301
- // ≤60 chars, includes primary keyword
302
- const kw = keywords[0] ?? ''
303
- const base = kw && !title.toLowerCase().includes(kw.toLowerCase())
304
- ? `${title} | ${kw}` : title
305
- return base.slice(0, 60)
306
- }
307
-
308
- private async generateSEODescription(content: string, keywords: string[]): Promise<string> {
309
- // ≤160 chars, compelling, includes keyword
310
- return `<!-- Agent: write 155-char meta description including: ${keywords.join(', ')} -->`
311
- }
312
-
313
- private async findInternalLinks(title: string, keywords: string[]): Promise<string[]> {
314
- // Find 2-3 related published posts in same profile
315
- try {
316
- const search = keywords[0] ?? title.split(' ')[0]
317
- const { rows } = await db.execute({
318
- sql: `SELECT slug,title FROM posts
319
- WHERE profile_id=? AND published=1 AND hidden=0
320
- AND (title LIKE ? OR slug LIKE ?)
321
- LIMIT 3`,
322
- args: [this.profileId, `%${search}%`, `%${search}%`],
323
- })
324
- return rows.map((r: any) => `/blog/${r.slug}`)
325
- } catch { return [] }
326
- }
327
-
328
- private async makeSlug(title: string, table: string): Promise<string> {
329
- const base = title.toLowerCase()
330
- .replace(/[^a-z0-9\s-]/g, '')
331
- .replace(/\s+/g, '-')
332
- .replace(/-+/g, '-')
333
- .slice(0, 80)
334
-
335
- const { rows: [exists] } = await db.execute({
336
- sql: `SELECT slug FROM ${table} WHERE profile_id=? AND slug=? LIMIT 1`,
337
- args: [this.profileId, base],
338
- })
339
- return exists ? `${base}-${Date.now().toString(36)}` : base
340
- }
341
-
342
- private countWords(content: string): number {
343
- return content.replace(/<[^>]+>/g, '').split(/\s+/).filter(Boolean).length
344
- }
345
- }
346
-
347
- export const blogWriter = new BlogWriter()
@@ -1,89 +0,0 @@
1
- /**
2
- * COPY — Copywriter
3
- * "Words that convert. Nothing more, nothing less."
4
- * Writes to: pages, product descriptions, link descriptions, profile bio/tagline
5
- */
6
-
7
- import { BaseAgent, db, ulid, now, iso } from '../_base.ts'
8
- import { uniqueSlug } from '../../lib/slug.ts'
9
-
10
- export interface PageInput {
11
- title: string; slug?: string; excerpt?: string; text_field?: string
12
- hero_section?: Record<string, unknown>; cta_section?: Record<string, unknown>
13
- testimonials?: unknown[]; faq?: unknown[]; pricing?: unknown[]
14
- intro_section?: Record<string, unknown>; about_section?: Record<string, unknown>
15
- publish?: boolean
16
- }
17
-
18
- export class Copywriter extends BaseAgent {
19
- readonly name = 'COPY'
20
- readonly title = 'Copywriter'
21
-
22
- async createPage(input: PageInput) {
23
- await this.init()
24
- const id = ulid()
25
- const slug = input.slug ?? await uniqueSlug('pages', input.title, this.profileId)
26
- const ts = now()
27
-
28
- await db.execute({
29
- sql: `INSERT INTO pages (id,profile_id,user_id,title,slug,excerpt,text_field,
30
- hero_section,cta_section,testimonials,faq,pricing,intro_section,about_section,
31
- published,hidden,created_at,updated_at)
32
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,?,?)`,
33
- args: [
34
- id, this.profileId, this.userId, input.title, slug,
35
- input.excerpt ?? null, input.text_field ?? null,
36
- input.hero_section ? JSON.stringify(input.hero_section) : null,
37
- input.cta_section ? JSON.stringify(input.cta_section) : null,
38
- input.testimonials ? JSON.stringify(input.testimonials) : null,
39
- input.faq ? JSON.stringify(input.faq) : null,
40
- input.pricing ? JSON.stringify(input.pricing) : null,
41
- input.intro_section ? JSON.stringify(input.intro_section) : null,
42
- input.about_section ? JSON.stringify(input.about_section) : null,
43
- input.publish ? 1 : 0, ts, ts,
44
- ],
45
- })
46
- return this.getPage(id)
47
- }
48
-
49
- async getPage(id: string) {
50
- const { rows: [r] } = await db.execute({ sql: 'SELECT * FROM pages WHERE id=?', args: [id] })
51
- if (!r) throw new Error(`Page not found: ${id}`)
52
- return r
53
- }
54
-
55
- async listPages() {
56
- await this.init()
57
- const { rows } = await db.execute({
58
- sql: 'SELECT id,title,slug,published,is_active FROM pages WHERE profile_id=? AND hidden=0 ORDER BY order_index',
59
- args: [this.profileId],
60
- })
61
- return rows
62
- }
63
-
64
- /** Update profile bio and tagline */
65
- async updateProfileCopy(fields: { bio?: string; tagline?: string; title?: string }) {
66
- await this.init()
67
- const sets = [`updated_at=${now()}`]
68
- const args: unknown[] = []
69
- if (fields.bio !== undefined) { sets.push('bio=?'); args.push(fields.bio) }
70
- if (fields.tagline !== undefined) { sets.push('tagline=?'); args.push(fields.tagline) }
71
- if (fields.title !== undefined) { sets.push('title=?'); args.push(fields.title) }
72
- await db.execute({ sql: `UPDATE profiles SET ${sets.join(',')} WHERE id=?`, args: [...args, this.profileId] })
73
- }
74
-
75
- /** Update a product's description and excerpt */
76
- async updateProductCopy(productId: string, fields: { description?: string; excerpt?: string; button_text?: string }) {
77
- const sets = [`updated_at=${now()}`]
78
- const args: unknown[] = []
79
- if (fields.description !== undefined) { sets.push('description=?'); args.push(fields.description) }
80
- if (fields.excerpt !== undefined) { sets.push('excerpt=?'); args.push(fields.excerpt) }
81
- if (fields.button_text !== undefined) { sets.push('button_text=?'); args.push(fields.button_text) }
82
- await db.execute({ sql: `UPDATE products SET ${sets.join(',')} WHERE id=?`, args: [...args, productId] })
83
- }
84
-
85
- async publishPage(id: string) { await super.publish('pages', id); return this.getPage(id) }
86
- async archivePage(id: string) { await super.archive('pages', id) }
87
- }
88
-
89
- export const copywriter = new Copywriter()
@@ -1,106 +0,0 @@
1
- /**
2
- * SAGE — Course Creator
3
- * "I structure knowledge into learnable paths."
4
- * Delegates storage to LEO (same products table, type='course').
5
- * Owns: lesson structure, curriculum, progress tracking reads.
6
- */
7
-
8
- import { BaseAgent, db, now } from '../_base.ts'
9
- import { storeManager } from './store-manager.ts'
10
-
11
- export interface Lesson {
12
- id: string
13
- title: string
14
- content?: string
15
- video_url?: string
16
- duration_minutes?: number
17
- position: number
18
- free_preview?: boolean
19
- }
20
-
21
- export interface CourseInput {
22
- title: string
23
- description?: string
24
- excerpt?: string
25
- price_cents: number
26
- sale_price_cents?: number
27
- thumbnail_url?: string
28
- lessons?: Lesson[]
29
- publish?: boolean
30
- }
31
-
32
- export class CourseCreator extends BaseAgent {
33
- readonly name = 'SAGE'
34
- readonly title = 'Course Creator'
35
-
36
- async create(input: CourseInput) {
37
- return storeManager.create({
38
- type: 'course',
39
- ...input,
40
- // lessons stored as JSON on the product row
41
- })
42
- }
43
-
44
- async addLesson(courseId: string, lesson: Omit<Lesson, 'position'>) {
45
- await this.init()
46
- const course = await storeManager.get(courseId)
47
- if (course.type !== 'course') throw new Error('Not a course')
48
-
49
- const lessons: Lesson[] = JSON.parse(course.lessons as string || '[]')
50
- const newLesson: Lesson = { ...lesson, position: lessons.length }
51
- lessons.push(newLesson)
52
-
53
- const ts = now()
54
- await db.execute({
55
- sql: 'UPDATE products SET lessons=?,total_lessons=?,updated_at=? WHERE id=?',
56
- args: [JSON.stringify(lessons), lessons.length, ts, courseId],
57
- })
58
- return storeManager.get(courseId)
59
- }
60
-
61
- async updateLesson(courseId: string, lessonId: string, fields: Partial<Lesson>) {
62
- await this.init()
63
- const course = await storeManager.get(courseId)
64
- const lessons: Lesson[] = JSON.parse(course.lessons as string || '[]')
65
- const idx = lessons.findIndex(l => l.id === lessonId)
66
- if (idx === -1) throw new Error(`Lesson not found: ${lessonId}`)
67
- lessons[idx] = { ...lessons[idx], ...fields }
68
-
69
- await db.execute({
70
- sql: 'UPDATE products SET lessons=?,updated_at=? WHERE id=?',
71
- args: [JSON.stringify(lessons), now(), courseId],
72
- })
73
- return storeManager.get(courseId)
74
- }
75
-
76
- async reorderLessons(courseId: string, orderedIds: string[]) {
77
- await this.init()
78
- const course = await storeManager.get(courseId)
79
- const lessons: Lesson[] = JSON.parse(course.lessons as string || '[]')
80
- const sorted = orderedIds
81
- .map((id, i) => { const l = lessons.find(x => x.id === id); return l ? { ...l, position: i } : null })
82
- .filter(Boolean) as Lesson[]
83
-
84
- await db.execute({
85
- sql: 'UPDATE products SET lessons=?,updated_at=? WHERE id=?',
86
- args: [JSON.stringify(sorted), now(), courseId],
87
- })
88
- }
89
-
90
- async listCourses(published?: boolean) {
91
- return storeManager.list({ type: 'course', published })
92
- }
93
-
94
- /** Students who purchased this course and their progress */
95
- async getStudents(courseId: string) {
96
- await this.init()
97
- const { rows } = await db.execute({
98
- sql: `SELECT email,customer_name,course_progress,course_completed,course_completion_date,created_at
99
- FROM purchases WHERE product_id=? AND profile_id=? ORDER BY created_at DESC`,
100
- args: [courseId, this.profileId],
101
- })
102
- return rows
103
- }
104
- }
105
-
106
- export const courseCreator = new CourseCreator()