@businesskit/agent 1.0.4 → 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 (153) 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 -84
  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/setup.sh +134 -0
  38. package/scripts/setup.ts +92 -0
  39. package/server.json +21 -0
  40. package/skills/README.md +19 -27
  41. package/skills/billing/SKILL.md +64 -0
  42. package/skills/brand/SKILL.md +30 -86
  43. package/skills/copywriting/SKILL.md +1 -1
  44. package/skills/crm/SKILL.md +38 -0
  45. package/skills/docs-cms/SKILL.md +53 -0
  46. package/skills/docs-cms/references/how-to.md +383 -0
  47. package/skills/inbox/SKILL.md +49 -0
  48. package/skills/inventory/SKILL.md +69 -0
  49. package/skills/pages/SKILL.md +169 -0
  50. package/skills/pages/references/sections-catalog.json +950 -0
  51. package/skills/social/SKILL.md +1 -1
  52. package/templates/antigravity.json +8 -0
  53. package/templates/claude-code.mcp.json +8 -0
  54. package/templates/cursor.mcp.json +8 -0
  55. package/templates/vscode.mcp.json +9 -0
  56. package/.claude/commands/analytics.md +0 -7
  57. package/.claude/commands/blog-writer.md +0 -9
  58. package/.claude/commands/cbo.md +0 -7
  59. package/.claude/commands/ceo.md +0 -10
  60. package/.claude/commands/cmo.md +0 -7
  61. package/.claude/commands/compress.md +0 -73
  62. package/.claude/commands/coo.md +0 -11
  63. package/.claude/commands/copywriter.md +0 -15
  64. package/.claude/commands/course-creator.md +0 -9
  65. package/.claude/commands/crm.md +0 -591
  66. package/.claude/commands/deep.md +0 -50
  67. package/.claude/commands/docs-writer.md +0 -8
  68. package/.claude/commands/forms-builder.md +0 -10
  69. package/.claude/commands/ingest.md +0 -110
  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/.claude/settings.json +0 -16
  80. package/.claude/settings.local.json +0 -11
  81. package/.env.example +0 -12
  82. package/.mcp.json +0 -3
  83. package/HEARTBEAT.md +0 -105
  84. package/PLAN.md +0 -345
  85. package/PRD-Agent-Composition.md +0 -149
  86. package/PRD-Agent-Harness.md +0 -316
  87. package/REFERENCE.md +0 -160
  88. package/SOUL.md +0 -148
  89. package/SYSTEM.md +0 -71
  90. package/agents/_base.ts +0 -371
  91. package/agents/analytics/SOUL.md +0 -11
  92. package/agents/analytics/analytics.ts +0 -405
  93. package/agents/business/SOUL.md +0 -11
  94. package/agents/business/business.ts +0 -109
  95. package/agents/ceo/SOUL.md +0 -15
  96. package/agents/ceo/ceo.ts +0 -146
  97. package/agents/content/SOUL.md +0 -11
  98. package/agents/content/content.ts +0 -379
  99. package/agents/copywriting/SOUL.md +0 -11
  100. package/agents/copywriting/copywriting.ts +0 -89
  101. package/agents/courses/SOUL.md +0 -11
  102. package/agents/courses/courses.ts +0 -451
  103. package/agents/docs/SOUL.md +0 -11
  104. package/agents/docs/docs.ts +0 -77
  105. package/agents/forms/SOUL.md +0 -11
  106. package/agents/forms/forms.ts +0 -364
  107. package/agents/hiring/SOUL.md +0 -11
  108. package/agents/hiring/hiring.ts +0 -314
  109. package/agents/marketing/SOUL.md +0 -15
  110. package/agents/marketing/marketing.ts +0 -109
  111. package/agents/newsletter/SOUL.md +0 -11
  112. package/agents/newsletter/newsletter.ts +0 -91
  113. package/agents/operations/SOUL.md +0 -11
  114. package/agents/operations/operations.ts +0 -157
  115. package/agents/sales/SOUL.md +0 -44
  116. package/agents/sales/sales.ts +0 -883
  117. package/agents/scheduler/SOUL.md +0 -11
  118. package/agents/scheduler/scheduler.ts +0 -68
  119. package/agents/seo/SOUL.md +0 -11
  120. package/agents/seo/seo.ts +0 -288
  121. package/agents/social/SOUL.md +0 -11
  122. package/agents/social/social.ts +0 -744
  123. package/agents/store/SOUL.md +0 -11
  124. package/agents/store/store.ts +0 -514
  125. package/cli.ts +0 -144
  126. package/context/about-me.md +0 -96
  127. package/context/brand-voice.md +0 -127
  128. package/context/brand.md +0 -80
  129. package/context/business.md +0 -66
  130. package/context/working-style.md +0 -87
  131. package/lib/analytics.ts +0 -81
  132. package/lib/cms.ts +0 -88
  133. package/lib/db.adapter.ts +0 -30
  134. package/lib/db.ts +0 -63
  135. package/lib/enums.ts +0 -25
  136. package/lib/groups.ts +0 -122
  137. package/lib/id.ts +0 -43
  138. package/lib/kb.ts +0 -337
  139. package/lib/memory.ts +0 -219
  140. package/lib/pattern-detector.ts +0 -169
  141. package/lib/profile.ts +0 -155
  142. package/lib/schema.ts +0 -2015
  143. package/lib/slug.ts +0 -30
  144. package/lib/validate.ts +0 -33
  145. package/setup.ts +0 -141
  146. package/skills/agents/SKILL.md +0 -56
  147. package/skills/analytics/SKILL.md +0 -52
  148. package/skills/blog-writer/SKILL.md +0 -452
  149. package/skills/ceo/SKILL.md +0 -25
  150. package/skills/cmo/SKILL.md +0 -8
  151. package/skills/schema/SKILL.md +0 -86
  152. package/skills/store/SKILL.md +0 -62
  153. package/tsconfig.json +0 -14
@@ -1,11 +0,0 @@
1
- # store
2
-
3
- Placeholder SOUL. See CLAUDE.md routing table and skills/store/SKILL.md (if present) for scope.
4
-
5
- ## Rules
6
-
7
- - Load skills on demand
8
- - Draft before publish
9
- - Archive not delete (hidden=1)
10
- - Log every action to agent_memory
11
- - Push reports to agent_reports mid-session
@@ -1,514 +0,0 @@
1
- /**
2
- * Store Agent — digital commerce. Every product type lives here.
3
- *
4
- * DB contract (businesskit-files/provision.ts):
5
- * - products: id, profile_id, user_id, category_id, type, title, slug (GLOBAL
6
- * unique), price_cents, currency, published, hidden,
7
- * type-specific fields (file_url, calendar_link, webinar_*,
8
- * event_settings, billing_interval, platform_*, cta_button),
9
- * seo_*, course_access_*, visibility, additional_details,
10
- * timestamps as INTEGER unix seconds
11
- * - product_analytics: 1 row per product, seeded by trg_product_insert
12
- * - purchases: append-only in practice (writes come from payment gateway);
13
- * we READ them here (sales, revenue, customers)
14
- * - profile_analytics: aggregate counters (total_products, total_sales,
15
- * total_earnings) maintained by triggers
16
- * - cms_analytics: per-category counters keyed on cms.category_id
17
- *
18
- * Triggers that fire on our writes (product-triggers.ts):
19
- * - trg_product_insert → +1 profile_analytics.total_products,
20
- * INSERT OR IGNORE product_analytics,
21
- * bumps cms_analytics for the matching
22
- * (profile_id, category_id) cms row
23
- * - trg_product_update_published → flips cms_analytics.total_published/draft
24
- * - trg_product_delete → decrements cms_analytics; we soft-delete
25
- * (hidden=1) instead
26
- * - trg_purchase_insert → product_analytics + profile_analytics
27
- * sales/revenue (READ side only — don't
28
- * manufacture purchases)
29
- *
30
- * Two things that differ from forms/hiring:
31
- * 1. products.slug is GLOBALLY unique (no profile scope). uniqueSlug without
32
- * a profileId does this.
33
- * 2. products timestamps are INTEGER unix seconds, not ISO. _base.publish/
34
- * archive default to ISO for string ids, so we override both.
35
- *
36
- * Product types → cms category mapping is critical. Without a matching cms row
37
- * (via ensureCmsRow), trg_product_insert's cms_analytics UPDATE finds nothing.
38
- */
39
-
40
- import { BaseAgent, db, ulid, now } from '../_base.ts'
41
- import { uniqueSlug } from '../../lib/slug.ts'
42
- import { ensureCmsRow, CATEGORY } from '../../lib/cms.ts'
43
-
44
- export type ProductType =
45
- | 'download' | 'course' | 'meeting' | 'webinar'
46
- | 'event' | 'listing' | 'sponsorship' | 'service' | 'booking'
47
-
48
- export type Visibility = 'published' | 'unlisted' | 'private'
49
- export type PurchaseStatus = 'active' | 'refunded' | 'cancelled' | 'expired'
50
-
51
- /** product.type → cms.category_id. Seeding this cms row is required for
52
- * trg_product_insert's cms_analytics UPDATE to land. */
53
- const TYPE_TO_CATEGORY: Record<ProductType, string> = {
54
- download: CATEGORY.DOWNLOADS,
55
- course: CATEGORY.COURSES,
56
- meeting: CATEGORY.MEETINGS,
57
- webinar: CATEGORY.WEBINARS,
58
- event: CATEGORY.EVENTS,
59
- listing: CATEGORY.LISTING,
60
- sponsorship: CATEGORY.SPONSORSHIP,
61
- service: CATEGORY.SERVICES,
62
- booking: CATEGORY.BOOKING,
63
- }
64
-
65
- const TYPE_TO_SLUG: Record<ProductType, string> = {
66
- download: 'downloads',
67
- course: 'courses',
68
- meeting: 'meetings',
69
- webinar: 'webinars',
70
- event: 'events',
71
- listing: 'listing',
72
- sponsorship: 'sponsorship',
73
- service: 'services',
74
- booking: 'booking',
75
- }
76
-
77
- export interface ProductInput {
78
- type: ProductType
79
- title: string
80
- description?: string
81
- excerpt?: string
82
- price_cents: number
83
- sale_price_cents?: number
84
- currency?: string
85
- thumbnail_url?: string
86
- hero_image_url?: string
87
- cover_video_url?: string
88
- tags?: string[]
89
- features?: string[]
90
- button_text?: string
91
- visibility?: Visibility
92
- max_sales?: number
93
- cta_button?: Record<string, unknown>
94
- additional_details?: unknown[]
95
-
96
- // type-specific (only the ones actually used are inserted)
97
- file_url?: string // download
98
- calendar_link?: string // meeting
99
- scheduling_provider?: string
100
- scheduling_metadata?: Record<string, unknown>
101
- duration_minutes?: number
102
- meeting_settings?: Record<string, unknown>
103
- webinar_link?: string // webinar
104
- webinar_platform?: string
105
- webinar_schedule?: Record<string, unknown>
106
- webinar_settings?: Record<string, unknown>
107
- event_settings?: Record<string, unknown> // event
108
- billing_interval?: 'month' | 'year' | 'once' // sponsorship
109
- platform_name?: string // sponsorship
110
- platform_url?: string // sponsorship
111
- post_frequency?: string // sponsorship
112
- lessons?: unknown[] // course (array)
113
- course_access_type?: string
114
- course_access_config?: Record<string, unknown>
115
-
116
- // nav / organisation
117
- category_id?: string // override auto-mapping if caller knows better
118
- collection_id?: string
119
- forms_id?: string
120
-
121
- // confirmation email overrides (per-product)
122
- confirmation_email_subject?: string
123
- confirmation_email_body?: string
124
-
125
- // SEO
126
- seo_title?: string
127
- seo_description?: string
128
- seo_og_image?: string
129
- seo_robots?: string
130
- seo_block_indexing?: boolean
131
-
132
- publish?: boolean
133
- }
134
-
135
- export interface ProductPatch extends Partial<Omit<ProductInput, 'type' | 'publish'>> {
136
- // type is immutable (would invalidate cms_analytics counters); re-create instead
137
- // publish is handled via publish()/unpublish() so cms_analytics flips
138
- }
139
-
140
- export class StoreManager extends BaseAgent {
141
- readonly name = 'Store'
142
- readonly title = 'Store Manager'
143
-
144
- // ── Products ──────────────────────────────────────────────────────────────
145
-
146
- async create(input: ProductInput) {
147
- await this.init()
148
-
149
- const categoryId = input.category_id ?? TYPE_TO_CATEGORY[input.type]
150
- if (!categoryId) throw new Error(`No cms category for product type: ${input.type}`)
151
-
152
- // Seed the cms row for this product type so trg_product_insert's
153
- // cms_analytics UPDATE has a row to hit.
154
- await ensureCmsRow(this.profileId, categoryId, {
155
- slug: TYPE_TO_SLUG[input.type] ?? input.type,
156
- title: TYPE_TO_SLUG[input.type] ?? input.type,
157
- })
158
-
159
- const id = ulid()
160
- const slug = await uniqueSlug('products', input.title) // GLOBAL unique
161
- const ts = now()
162
-
163
- if (input.price_cents < 0) throw new Error('price_cents must be ≥ 0')
164
- if (input.sale_price_cents !== undefined &&
165
- input.sale_price_cents < 0) throw new Error('sale_price_cents must be ≥ 0')
166
- if (input.sale_price_cents !== undefined &&
167
- input.sale_price_cents > input.price_cents) throw new Error('sale_price_cents must be ≤ price_cents')
168
-
169
- await db.write({
170
- sql: `INSERT INTO products (
171
- id, profile_id, user_id, type, category_id, title, slug,
172
- excerpt, description,
173
- price_cents, sale_price_cents, currency,
174
- thumbnail_url, hero_image_url, cover_video_url,
175
- tags, features, button_text, visibility, max_sales,
176
- cta_button, additional_details,
177
- file_url,
178
- calendar_link, scheduling_provider, scheduling_metadata,
179
- duration_minutes, meeting_settings,
180
- webinar_link, webinar_platform, webinar_schedule, webinar_settings,
181
- event_settings, billing_interval,
182
- platform_name, platform_url, post_frequency,
183
- lessons, course_access_type, course_access_config,
184
- collection_id, forms_id,
185
- confirmation_email_subject, confirmation_email_body,
186
- seo_title, seo_description, seo_og_image, seo_robots, seo_block_indexing,
187
- is_active, published, hidden,
188
- created_at, updated_at, published_at
189
- ) VALUES (
190
- ?,?,?,?,?,?,?,
191
- ?,?,
192
- ?,?,?,
193
- ?,?,?,
194
- ?,?,?,?,?,
195
- ?,?,
196
- ?,
197
- ?,?,?,
198
- ?,?,
199
- ?,?,?,?,
200
- ?,?,
201
- ?,?,?,
202
- ?,?,?,
203
- ?,?,
204
- ?,?,
205
- ?,?,?,?,?,
206
- 1,?,0,
207
- ?,?,?
208
- )`,
209
- args: [
210
- id, this.profileId, this.userId, input.type, categoryId, input.title, slug,
211
- input.excerpt ?? null, input.description ?? null,
212
- Math.round(input.price_cents),
213
- input.sale_price_cents !== undefined ? Math.round(input.sale_price_cents) : null,
214
- input.currency ?? 'usd',
215
- input.thumbnail_url ?? null, input.hero_image_url ?? null, input.cover_video_url ?? null,
216
- input.tags ? JSON.stringify(input.tags) : null,
217
- input.features ? JSON.stringify(input.features) : null,
218
- input.button_text ?? null, input.visibility ?? 'published',
219
- input.max_sales ?? null,
220
- JSON.stringify(input.cta_button ?? {}),
221
- JSON.stringify(input.additional_details ?? []),
222
- input.file_url ?? null,
223
- input.calendar_link ?? null, input.scheduling_provider ?? null,
224
- input.scheduling_metadata ? JSON.stringify(input.scheduling_metadata) : null,
225
- input.duration_minutes ?? null,
226
- input.meeting_settings ? JSON.stringify(input.meeting_settings) : null,
227
- input.webinar_link ?? null, input.webinar_platform ?? null,
228
- input.webinar_schedule ? JSON.stringify(input.webinar_schedule) : null,
229
- input.webinar_settings ? JSON.stringify(input.webinar_settings) : null,
230
- input.event_settings ? JSON.stringify(input.event_settings) : null,
231
- input.billing_interval ?? null,
232
- input.platform_name ?? null, input.platform_url ?? null, input.post_frequency ?? null,
233
- input.lessons ? JSON.stringify(input.lessons) : null,
234
- input.course_access_type ?? 'open',
235
- JSON.stringify(input.course_access_config ?? {}),
236
- input.collection_id ?? null, input.forms_id ?? null,
237
- input.confirmation_email_subject ?? null, input.confirmation_email_body ?? null,
238
- input.seo_title ?? null, input.seo_description ?? null, input.seo_og_image ?? null,
239
- input.seo_robots ?? null, input.seo_block_indexing ? 1 : 0,
240
- input.publish ? 1 : 0,
241
- ts, ts, input.publish ? ts : null,
242
- ],
243
- })
244
-
245
- await this.logMemory(
246
- `${input.publish ? 'Published' : 'Drafted'} ${input.type} "${input.title}"`,
247
- { id, slug, type: input.type, price_cents: input.price_cents },
248
- )
249
-
250
- return this.get(id)
251
- }
252
-
253
- async edit(id: string, patch: ProductPatch) {
254
- await this.init()
255
- const sets: string[] = ['updated_at=?']
256
- const args: unknown[] = [now()]
257
-
258
- // Plain scalar columns — iterate to keep the giant switch short
259
- const scalar: Array<[keyof ProductPatch, string]> = [
260
- ['title', 'title'],
261
- ['description', 'description'],
262
- ['excerpt', 'excerpt'],
263
- ['price_cents', 'price_cents'],
264
- ['sale_price_cents', 'sale_price_cents'],
265
- ['currency', 'currency'],
266
- ['thumbnail_url', 'thumbnail_url'],
267
- ['hero_image_url', 'hero_image_url'],
268
- ['cover_video_url', 'cover_video_url'],
269
- ['button_text', 'button_text'],
270
- ['visibility', 'visibility'],
271
- ['max_sales', 'max_sales'],
272
- ['file_url', 'file_url'],
273
- ['calendar_link', 'calendar_link'],
274
- ['scheduling_provider', 'scheduling_provider'],
275
- ['duration_minutes', 'duration_minutes'],
276
- ['webinar_link', 'webinar_link'],
277
- ['webinar_platform', 'webinar_platform'],
278
- ['billing_interval', 'billing_interval'],
279
- ['platform_name', 'platform_name'],
280
- ['platform_url', 'platform_url'],
281
- ['post_frequency', 'post_frequency'],
282
- ['course_access_type', 'course_access_type'],
283
- ['collection_id', 'collection_id'],
284
- ['forms_id', 'forms_id'],
285
- ['confirmation_email_subject', 'confirmation_email_subject'],
286
- ['confirmation_email_body', 'confirmation_email_body'],
287
- ['seo_title', 'seo_title'],
288
- ['seo_description', 'seo_description'],
289
- ['seo_og_image', 'seo_og_image'],
290
- ['seo_robots', 'seo_robots'],
291
- ]
292
- for (const [k, col] of scalar) {
293
- if (patch[k] !== undefined) { sets.push(`${col}=?`); args.push(patch[k] as never) }
294
- }
295
-
296
- // JSON columns
297
- const json: Array<[keyof ProductPatch, string]> = [
298
- ['tags', 'tags'],
299
- ['features', 'features'],
300
- ['cta_button', 'cta_button'],
301
- ['additional_details', 'additional_details'],
302
- ['scheduling_metadata', 'scheduling_metadata'],
303
- ['meeting_settings', 'meeting_settings'],
304
- ['webinar_schedule', 'webinar_schedule'],
305
- ['webinar_settings', 'webinar_settings'],
306
- ['event_settings', 'event_settings'],
307
- ['lessons', 'lessons'],
308
- ['course_access_config', 'course_access_config'],
309
- ]
310
- for (const [k, col] of json) {
311
- if (patch[k] !== undefined) { sets.push(`${col}=?`); args.push(JSON.stringify(patch[k])) }
312
- }
313
-
314
- // Booleans
315
- if (patch.seo_block_indexing !== undefined) {
316
- sets.push('seo_block_indexing=?')
317
- args.push(patch.seo_block_indexing ? 1 : 0)
318
- }
319
-
320
- if (sets.length === 1) return this.get(id)
321
-
322
- await db.write({
323
- sql: `UPDATE products SET ${sets.join(',')} WHERE id=? AND profile_id=?`,
324
- args: [...args, id, this.profileId],
325
- })
326
- return this.get(id)
327
- }
328
-
329
- async get(id: string) {
330
- await this.init()
331
- const { rows: [r] } = await db.execute({
332
- sql: `SELECT * FROM products WHERE id=? AND profile_id=? LIMIT 1`,
333
- args: [id, this.profileId],
334
- })
335
- if (!r) throw new Error(`Product not found: ${id}`)
336
- return r
337
- }
338
-
339
- async list(opts: {
340
- type?: ProductType
341
- published?: boolean
342
- include_hidden?: boolean
343
- limit?: number
344
- } = {}) {
345
- await this.init()
346
- let where = 'WHERE p.profile_id=?'
347
- const args: unknown[] = [this.profileId]
348
- if (!opts.include_hidden) where += ' AND p.hidden=0'
349
- if (opts.type) { where += ' AND p.type=?'; args.push(opts.type) }
350
- if (opts.published !== undefined){ where += ' AND p.published=?'; args.push(opts.published ? 1 : 0) }
351
-
352
- const { rows } = await db.execute({
353
- sql: `SELECT p.id, p.type, p.title, p.slug, p.price_cents, p.sale_price_cents,
354
- p.currency, p.published, p.visibility, p.created_at,
355
- pa.total_sales, pa.total_revenue_cents, pa.total_views
356
- FROM products p
357
- LEFT JOIN product_analytics pa ON pa.product_id = p.id
358
- ${where}
359
- ORDER BY p.created_at DESC LIMIT ?`,
360
- args: [...args, opts.limit ?? 50],
361
- })
362
- return rows
363
- }
364
-
365
- // products timestamps are INTEGER unix seconds; override _base.publish/archive
366
- // which default to ISO for string ids.
367
- async publish(id: string) {
368
- await this.init()
369
- const ts = now()
370
- await db.write({
371
- sql: `UPDATE products SET published=1, published_at=?, updated_at=?
372
- WHERE id=? AND profile_id=?`,
373
- args: [ts, ts, id, this.profileId],
374
- })
375
- return this.get(id)
376
- }
377
-
378
- async unpublish(id: string) {
379
- await this.init()
380
- await db.write({
381
- sql: `UPDATE products SET published=0, updated_at=? WHERE id=? AND profile_id=?`,
382
- args: [now(), id, this.profileId],
383
- })
384
- return this.get(id)
385
- }
386
-
387
- /** Soft archive (hidden=1). Never hard delete — trg_product_delete would
388
- * decrement cms_analytics and drop product_analytics history. */
389
- async archive(id: string) {
390
- await this.init()
391
- const ts = now()
392
- await db.write({
393
- sql: `UPDATE products SET hidden=1, archived_at=?, updated_at=?
394
- WHERE id=? AND profile_id=?`,
395
- args: [ts, ts, id, this.profileId],
396
- })
397
- }
398
-
399
- // ── Purchases (READ only — written by payment gateway / webhooks) ─────────
400
-
401
- async purchases(opts: {
402
- product_id?: string
403
- status?: PurchaseStatus
404
- payment_status?: string
405
- since_ts?: number
406
- limit?: number
407
- } = {}) {
408
- await this.init()
409
- let where = 'WHERE profile_id=?'
410
- const args: unknown[] = [this.profileId]
411
- if (opts.product_id) { where += ' AND product_id=?'; args.push(opts.product_id) }
412
- if (opts.status) { where += ' AND status=?'; args.push(opts.status) }
413
- if (opts.payment_status) { where += ' AND payment_status=?'; args.push(opts.payment_status) }
414
- if (opts.since_ts) { where += ' AND created_at>=?'; args.push(opts.since_ts) }
415
-
416
- const { rows } = await db.execute({
417
- sql: `SELECT id, product_id, email, customer_name, amount_cents, currency,
418
- payment_status, status, rating_star, created_at,
419
- utm_source, utm_medium, utm_campaign, country, city
420
- FROM purchases ${where}
421
- ORDER BY created_at DESC LIMIT ?`,
422
- args: [...args, opts.limit ?? 100],
423
- })
424
- return rows
425
- }
426
-
427
- async getPurchase(id: string) {
428
- await this.init()
429
- const { rows: [r] } = await db.execute({
430
- sql: `SELECT * FROM purchases WHERE id=? AND profile_id=? LIMIT 1`,
431
- args: [id, this.profileId],
432
- })
433
- if (!r) throw new Error(`Purchase not found: ${id}`)
434
- return r
435
- }
436
-
437
- // ── Summaries ─────────────────────────────────────────────────────────────
438
-
439
- /** Inventory grouped by product type (live vs drafts). */
440
- async storeOverview() {
441
- await this.init()
442
- const { rows } = await db.execute({
443
- sql: `SELECT type,
444
- COUNT(*) AS total,
445
- SUM(CASE WHEN published=1 AND hidden=0 THEN 1 ELSE 0 END) AS live,
446
- SUM(CASE WHEN published=0 AND hidden=0 THEN 1 ELSE 0 END) AS drafts
447
- FROM products
448
- WHERE profile_id=?
449
- GROUP BY type
450
- ORDER BY total DESC`,
451
- args: [this.profileId],
452
- })
453
- return rows
454
- }
455
-
456
- /** Top-selling products by total_revenue_cents (trigger-maintained). */
457
- async topProducts(limit = 10) {
458
- await this.init()
459
- const { rows } = await db.execute({
460
- sql: `SELECT p.id, p.title, p.type, p.slug,
461
- pa.total_sales, pa.total_revenue_cents
462
- FROM products p
463
- JOIN product_analytics pa ON pa.product_id = p.id
464
- WHERE p.profile_id=? AND p.hidden=0
465
- ORDER BY pa.total_revenue_cents DESC
466
- LIMIT ?`,
467
- args: [this.profileId, limit],
468
- })
469
- return rows
470
- }
471
-
472
- /** Revenue rollup for a window (default: last 30 days).
473
- * Uses raw purchases with payment_status='completed' AND status='active'
474
- * so refunds are excluded. */
475
- async revenueSummary(windowDays = 30) {
476
- await this.init()
477
- const since = now() - windowDays * 86400
478
- const { rows: [r] } = await db.execute({
479
- sql: `SELECT COUNT(*) AS sales,
480
- COALESCE(SUM(amount_cents), 0) AS revenue_cents,
481
- COUNT(DISTINCT email) AS customers
482
- FROM purchases
483
- WHERE profile_id=?
484
- AND payment_status='completed'
485
- AND status='active'
486
- AND created_at>=?`,
487
- args: [this.profileId, since],
488
- })
489
- return {
490
- window_days: windowDays,
491
- sales: Number(r?.sales ?? 0),
492
- revenue_cents: Number(r?.revenue_cents ?? 0),
493
- customers: Number(r?.customers ?? 0),
494
- }
495
- }
496
-
497
- /** Profile-wide totals from profile_analytics (trigger-maintained). */
498
- async lifetimeStats() {
499
- await this.init()
500
- const { rows: [r] } = await db.execute({
501
- sql: `SELECT total_products, total_sales, total_earnings, total_views
502
- FROM profile_analytics WHERE profile_id=? LIMIT 1`,
503
- args: [this.profileId],
504
- })
505
- return {
506
- total_products: Number(r?.total_products ?? 0),
507
- total_sales: Number(r?.total_sales ?? 0),
508
- total_earnings: Number(r?.total_earnings ?? 0),
509
- total_views: Number(r?.total_views ?? 0),
510
- }
511
- }
512
- }
513
-
514
- export const storeManager = new StoreManager()
package/cli.ts DELETED
@@ -1,144 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * cli.ts — BusinessKit Agent CLI
4
- *
5
- * Usage: npx businesskit-agent <agent> [command] [...args]
6
- *
7
- * Examples:
8
- * npx businesskit-agent ceo
9
- * npx businesskit-agent blog-writer create "My Post Title"
10
- * npx businesskit-agent scheduler hourly
11
- * npx businesskit-agent analytics-agent snapshot
12
- */
13
-
14
- import 'dotenv/config'
15
-
16
- const [, , agentName, command, ...args] = process.argv
17
-
18
- // Each agent lives at agents/<folder>/<folder>.ts.
19
- // Aliases (e.g. "cmo" -> "marketing") preserve legacy CLI entry points.
20
- const AGENTS: Record<string, string> = {
21
- ceo: 'ceo/ceo',
22
- marketing: 'marketing/marketing',
23
- cmo: 'marketing/marketing',
24
- operations: 'operations/operations',
25
- coo: 'operations/operations',
26
- business: 'business/business',
27
- cbo: 'business/business',
28
- sales: 'sales/sales',
29
- crm: 'sales/sales',
30
- 'crm-agent': 'sales/sales',
31
- content: 'content/content',
32
- 'blog-writer': 'content/content',
33
- newsletter: 'newsletter/newsletter',
34
- 'newsletter-writer': 'newsletter/newsletter',
35
- copywriting: 'copywriting/copywriting',
36
- copywriter: 'copywriting/copywriting',
37
- courses: 'courses/courses',
38
- 'course-creator': 'courses/courses',
39
- store: 'store/store',
40
- 'store-manager': 'store/store',
41
- hiring: 'hiring/hiring',
42
- 'jobs-manager': 'hiring/hiring',
43
- forms: 'forms/forms',
44
- 'forms-builder': 'forms/forms',
45
- docs: 'docs/docs',
46
- 'docs-writer': 'docs/docs',
47
- analytics: 'analytics/analytics',
48
- 'analytics-agent': 'analytics/analytics',
49
- seo: 'seo/seo',
50
- 'seo-agent': 'seo/seo',
51
- social: 'social/social',
52
- 'social-agent': 'social/social',
53
- scheduler: 'scheduler/scheduler',
54
- }
55
-
56
- if (!agentName || agentName === 'help') {
57
- printHelp()
58
- process.exit(0)
59
- }
60
-
61
- const path = AGENTS[agentName.toLowerCase()]
62
- if (!path) {
63
- console.error(`\nUnknown agent: "${agentName}"`)
64
- console.error('Run: npx businesskit-agent help\n')
65
- process.exit(1)
66
- }
67
-
68
- const mod = await import(`./agents/${path}.ts`)
69
- const exportKey = Object.keys(mod).find(k => typeof mod[k] === 'object' && mod[k] !== null)
70
- const agent = exportKey ? mod[exportKey] : null
71
-
72
- if (!agent) {
73
- console.error(`Could not load agent: ${agentName}`)
74
- process.exit(1)
75
- }
76
-
77
- const cmd = command ?? defaultCommand(agentName)
78
-
79
- if (typeof agent[cmd] !== 'function') {
80
- console.error(`\nAgent "${agentName}" has no command "${cmd}"`)
81
- const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(agent))
82
- .filter(m => m !== 'constructor' && !m.startsWith('_') && typeof agent[m] === 'function')
83
- console.error(`Available: ${methods.join(', ')}\n`)
84
- process.exit(1)
85
- }
86
-
87
- try {
88
- const result = await agent[cmd](...args)
89
- if (result !== undefined) console.log(JSON.stringify(result, null, 2))
90
- } catch (e) {
91
- console.error('\nError:', e instanceof Error ? e.message : e)
92
- process.exit(1)
93
- }
94
-
95
- function defaultCommand(name: string): string {
96
- const defaults: Record<string, string> = {
97
- ceo: 'weeklyBriefing',
98
- marketing: 'contentCalendar', cmo: 'contentCalendar',
99
- operations: 'draftPipeline', coo: 'draftPipeline',
100
- business: 'revenueReport', cbo: 'revenueReport',
101
- sales: 'pipelineSummary', crm: 'pipelineSummary',
102
- 'crm-agent': 'pipelineSummary',
103
- analytics: 'snapshot', 'analytics-agent': 'snapshot',
104
- seo: 'audit', 'seo-agent': 'audit',
105
- scheduler: 'daily',
106
- }
107
- return defaults[name] ?? 'list'
108
- }
109
-
110
- function printHelp() {
111
- console.log(`
112
- BusinessKit Agent CLI
113
-
114
- Usage: npx businesskit-agent <agent> [command] [args]
115
-
116
- C-Suite:
117
- ceo Weekly briefing (revenue, traffic, priorities)
118
- cmo Content calendar + growth strategy
119
- coo Draft pipeline + publish queue
120
- cbo Revenue report + pricing audit
121
-
122
- Creators:
123
- blog-writer List posts or create new (create "Title")
124
- newsletter-writer Subscriber stats or send newsletter
125
- copywriter List pages or create new
126
- course-creator List courses
127
- store-manager List products by type
128
- jobs-manager List job listings
129
- forms-builder List forms
130
- docs-writer List articles
131
- crm CRM contacts and pipeline
132
-
133
- Growth:
134
- analytics-agent Full analytics snapshot
135
- seo-agent SEO audit across all content
136
- social-agent Post content to social via n8n
137
- scheduler Run publish queue (hourly|daily|weekly)
138
-
139
- Setup:
140
- npx tsx setup.ts Verify Turso connection
141
-
142
- Requires TURSO_URL + TURSO_TOKEN in .env
143
- `)
144
- }