@businesskit/agent 1.0.2 → 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/.claude-plugin/marketplace.json +36 -0
- package/.claude-plugin/plugin.json +7 -28
- package/.env.example +10 -0
- package/CLAUDE.md +56 -195
- package/HEARTBEAT.md +81 -57
- package/PLAN.md +211 -119
- package/PRD-Agent-Composition.md +149 -0
- package/README.md +25 -11
- package/REFERENCE.md +160 -0
- package/SOUL.md +31 -0
- package/SYSTEM.md +22 -0
- 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/{.agents/skills/analytics.md → skills/analytics/SKILL.md} +6 -1
- package/{.agents/skills/brand.md → skills/brand/SKILL.md} +14 -1
- package/skills/ceo/SKILL.md +25 -0
- package/skills/cmo/SKILL.md +8 -0
- package/skills/humanizer/SKILL.md +270 -0
- package/skills/schema/SKILL.md +86 -0
- package/tsconfig.json +2 -1
- package/.agents/skills/schema.md +0 -45
- package/.agents/skills/store.md +0 -46
- package/.claude/skills/agents.md +0 -56
- package/.claude/skills/analytics.md +0 -7
- package/.claude/skills/brand.md +0 -44
- package/.claude/skills/humanizer.md +0 -474
- package/.claude/skills/schema.md +0 -45
- 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
- /package/{.claude/skills → skills}/README.md +0 -0
- /package/{.agents/skills/agents.md → skills/agents/SKILL.md} +0 -0
- /package/{.claude/skills/blog-writing.md → skills/blog-writer/SKILL.md} +0 -0
- /package/{.claude/skills/store-copywriting.md → skills/copywriting/SKILL.md} +0 -0
- /package/{.claude/skills/social-content.md → skills/social/SKILL.md} +0 -0
- /package/{.claude/skills → skills/social}/content-seo.md +0 -0
- /package/{.claude/skills/store.md → skills/store/SKILL.md} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1,514 @@
|
|
|
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
CHANGED
|
@@ -15,25 +15,42 @@ import 'dotenv/config'
|
|
|
15
15
|
|
|
16
16
|
const [, , agentName, command, ...args] = process.argv
|
|
17
17
|
|
|
18
|
+
// Each agent lives at agents/<folder>/<folder>.ts.
|
|
19
|
+
// Aliases (e.g. "cmo" -> "marketing") preserve legacy CLI entry points.
|
|
18
20
|
const AGENTS: Record<string, string> = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
|
|
30
|
-
'
|
|
31
|
-
|
|
32
|
-
'
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'
|
|
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',
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
if (!agentName || agentName === 'help') {
|
|
@@ -77,13 +94,15 @@ try {
|
|
|
77
94
|
|
|
78
95
|
function defaultCommand(name: string): string {
|
|
79
96
|
const defaults: Record<string, string> = {
|
|
80
|
-
|
|
81
|
-
'cmo
|
|
82
|
-
'coo
|
|
83
|
-
'cbo
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
'
|
|
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',
|
|
87
106
|
}
|
|
88
107
|
return defaults[name] ?? 'list'
|
|
89
108
|
}
|