@businesskit/agent 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.json +16 -0
- package/.claude/settings.local.json +11 -0
- package/.env.example +10 -0
- package/CLAUDE.md +32 -13
- package/PLAN.md +95 -134
- package/REFERENCE.md +60 -24
- package/agents/_base.ts +352 -44
- package/agents/analytics/SOUL.md +11 -0
- package/agents/analytics/analytics.ts +405 -0
- package/agents/business/SOUL.md +11 -0
- package/agents/{csuite/cbo.ts → business/business.ts} +2 -2
- package/agents/ceo/SOUL.md +15 -0
- package/agents/{csuite → ceo}/ceo.ts +33 -8
- package/agents/content/SOUL.md +11 -0
- package/agents/content/content.ts +379 -0
- package/agents/copywriting/SOUL.md +11 -0
- package/agents/courses/SOUL.md +11 -0
- package/agents/courses/courses.ts +451 -0
- package/agents/docs/SOUL.md +11 -0
- package/agents/forms/SOUL.md +11 -0
- package/agents/forms/forms.ts +364 -0
- package/agents/hiring/SOUL.md +11 -0
- package/agents/hiring/hiring.ts +314 -0
- package/agents/marketing/SOUL.md +15 -0
- package/agents/{csuite/cmo.ts → marketing/marketing.ts} +3 -3
- package/agents/newsletter/SOUL.md +11 -0
- package/agents/operations/SOUL.md +11 -0
- package/agents/operations/operations.ts +157 -0
- package/agents/sales/SOUL.md +44 -0
- package/agents/sales/sales.ts +883 -0
- package/agents/scheduler/SOUL.md +11 -0
- package/agents/{growth → scheduler}/scheduler.ts +2 -2
- package/agents/seo/SOUL.md +11 -0
- package/agents/{growth/seo-agent.ts → seo/seo.ts} +60 -54
- package/agents/social/SOUL.md +11 -0
- package/agents/social/social.ts +744 -0
- package/agents/store/SOUL.md +11 -0
- package/agents/store/store.ts +514 -0
- package/cli.ts +44 -25
- package/lib/cms.ts +88 -0
- package/lib/db.ts +58 -11
- package/lib/enums.ts +25 -0
- package/lib/groups.ts +122 -0
- package/lib/id.ts +38 -10
- package/lib/profile.ts +44 -8
- package/lib/schema.ts +2015 -0
- package/lib/validate.ts +33 -0
- package/package.json +1 -1
- package/scripts/generate-schema.ts +244 -0
- package/setup.ts +16 -2
- package/skills/schema/SKILL.md +57 -16
- package/tsconfig.json +2 -1
- package/agents/creators/blog-writer.ts +0 -347
- package/agents/creators/course-creator.ts +0 -106
- package/agents/creators/crm-agent.ts +0 -479
- package/agents/creators/forms-builder.ts +0 -90
- package/agents/creators/jobs-manager.ts +0 -82
- package/agents/creators/store-manager.ts +0 -138
- package/agents/csuite/coo.ts +0 -115
- package/agents/growth/analytics-agent.ts +0 -52
- package/agents/growth/social-agent.ts +0 -346
- /package/{ingest.md → .claude/commands/ingest.md} +0 -0
- /package/agents/{creators/copywriter.ts → copywriting/copywriting.ts} +0 -0
- /package/agents/{creators/docs-writer.ts → docs/docs.ts} +0 -0
- /package/agents/{creators/newsletter-writer.ts → newsletter/newsletter.ts} +0 -0
- /package/{ABOUT-ME.md → context/about-me.md} +0 -0
- /package/{brand-voice.md → context/brand-voice.md} +0 -0
- /package/{working-style.md → context/working-style.md} +0 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Courses Agent — course-shaped products.
|
|
3
|
+
*
|
|
4
|
+
* A course is `products.type='course'` + `category_id='cat_18'`. StoreManager
|
|
5
|
+
* owns storage, slug, cms-row seeding, and analytics triggers. This agent
|
|
6
|
+
* owns the course-shaped layer on top: the **module → lesson** tree stored as
|
|
7
|
+
* JSON on products.lessons, the total_lessons scalar, and student progress
|
|
8
|
+
* reads from purchases.
|
|
9
|
+
*
|
|
10
|
+
* JSON shape on products.lessons (app-side canonical):
|
|
11
|
+
* [
|
|
12
|
+
* { id: 'module-…', title: 'Module 1', order: 0, lessons: [
|
|
13
|
+
* { id: 'lesson-…', title: 'Hello', content: '<p>…</p>', order: 0 },
|
|
14
|
+
* …
|
|
15
|
+
* ] },
|
|
16
|
+
* …
|
|
17
|
+
* ]
|
|
18
|
+
*
|
|
19
|
+
* total_lessons is the SUM of lessons across every module — not the module
|
|
20
|
+
* count. Order fields are 0-indexed and we rewrite them on every mutation so
|
|
21
|
+
* they stay contiguous.
|
|
22
|
+
*
|
|
23
|
+
* ID convention matches the app (`module-<ms>`, `lesson-<ms>`). If caller
|
|
24
|
+
* passes an id we keep it; otherwise we mint one.
|
|
25
|
+
*
|
|
26
|
+
* DB contract (businesskit-files/provision.ts):
|
|
27
|
+
* - products.lessons TEXT (JSON — see shape above)
|
|
28
|
+
* - products.total_lessons INTEGER
|
|
29
|
+
* - products.course_access_type 'open' | …
|
|
30
|
+
* - products.course_access_config TEXT (JSON)
|
|
31
|
+
* - purchases.course_progress TEXT (JSON — lesson_id → state)
|
|
32
|
+
* - purchases.course_completed INTEGER 0/1
|
|
33
|
+
* - purchases.course_completion_date INTEGER unix
|
|
34
|
+
*
|
|
35
|
+
* Triggers (product-triggers.ts): trg_product_insert /
|
|
36
|
+
* trg_product_update_published / trg_product_delete all fire through
|
|
37
|
+
* StoreManager. We never INSERT / DELETE products here.
|
|
38
|
+
*
|
|
39
|
+
* Timestamps on products are INTEGER unix seconds (now()).
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
import { BaseAgent, db, now } from '../_base.ts'
|
|
43
|
+
import { storeManager } from '../store/store.ts'
|
|
44
|
+
|
|
45
|
+
export interface Lesson {
|
|
46
|
+
id: string
|
|
47
|
+
title: string
|
|
48
|
+
content?: string
|
|
49
|
+
video_url?: string
|
|
50
|
+
duration_minutes?: number
|
|
51
|
+
free_preview?: boolean
|
|
52
|
+
order: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Module {
|
|
56
|
+
id: string
|
|
57
|
+
title: string
|
|
58
|
+
order: number
|
|
59
|
+
lessons: Lesson[]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type LessonInput = Omit<Lesson, 'id' | 'order'> & { id?: string }
|
|
63
|
+
export type ModuleInput = {
|
|
64
|
+
id?: string
|
|
65
|
+
title: string
|
|
66
|
+
lessons?: LessonInput[]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface CourseInput {
|
|
70
|
+
title: string
|
|
71
|
+
description?: string
|
|
72
|
+
excerpt?: string
|
|
73
|
+
price_cents: number
|
|
74
|
+
sale_price_cents?: number
|
|
75
|
+
currency?: string
|
|
76
|
+
thumbnail_url?: string
|
|
77
|
+
hero_image_url?: string
|
|
78
|
+
cover_video_url?: string
|
|
79
|
+
tags?: string[]
|
|
80
|
+
features?: string[]
|
|
81
|
+
button_text?: string
|
|
82
|
+
modules?: ModuleInput[]
|
|
83
|
+
course_access_type?: string
|
|
84
|
+
course_access_config?: Record<string, unknown>
|
|
85
|
+
collection_id?: string
|
|
86
|
+
seo_title?: string
|
|
87
|
+
seo_description?: string
|
|
88
|
+
publish?: boolean
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class CourseCreator extends BaseAgent {
|
|
92
|
+
readonly name = 'Courses'
|
|
93
|
+
readonly title = 'Course Creator'
|
|
94
|
+
|
|
95
|
+
// ── Create / lifecycle (delegates to StoreManager) ────────────────────────
|
|
96
|
+
|
|
97
|
+
async create(input: CourseInput) {
|
|
98
|
+
await this.init()
|
|
99
|
+
const modules = (input.modules ?? []).map((m, mi) => ({
|
|
100
|
+
id: m.id ?? moduleId(),
|
|
101
|
+
title: m.title,
|
|
102
|
+
order: mi,
|
|
103
|
+
lessons: (m.lessons ?? []).map((l, li) => ({
|
|
104
|
+
...l,
|
|
105
|
+
id: l.id ?? lessonId(),
|
|
106
|
+
order: li,
|
|
107
|
+
})),
|
|
108
|
+
})) as Module[]
|
|
109
|
+
|
|
110
|
+
// StoreManager inserts the product row, seeds cat_18 cms row, and lets
|
|
111
|
+
// trg_product_insert bump cms_analytics/profile_analytics. We pass the
|
|
112
|
+
// module tree via `lessons` — StoreManager JSON-encodes it verbatim.
|
|
113
|
+
const row = await storeManager.create({
|
|
114
|
+
...input,
|
|
115
|
+
type: 'course',
|
|
116
|
+
lessons: modules as unknown[],
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// total_lessons is SUM across modules, not module count. StoreManager
|
|
120
|
+
// doesn't know about the module shape, so we sync it here.
|
|
121
|
+
const total = countLessons(modules)
|
|
122
|
+
if (total) {
|
|
123
|
+
await db.write({
|
|
124
|
+
sql: `UPDATE products SET total_lessons=?, updated_at=?
|
|
125
|
+
WHERE id=? AND profile_id=?`,
|
|
126
|
+
args: [total, now(), row.id as string, this.profileId],
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await this.logMemory(
|
|
131
|
+
`${input.publish ? 'Published' : 'Drafted'} course "${input.title}"`,
|
|
132
|
+
{ id: row.id, modules: modules.length, lessons: total },
|
|
133
|
+
)
|
|
134
|
+
return this.get(row.id as string)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async publish(id: string) {
|
|
138
|
+
await this.assertCourse(id)
|
|
139
|
+
return storeManager.publish(id)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async unpublish(id: string) {
|
|
143
|
+
await this.assertCourse(id)
|
|
144
|
+
return storeManager.unpublish(id)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async archive(id: string) {
|
|
148
|
+
await this.assertCourse(id)
|
|
149
|
+
await storeManager.archive(id)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ── Reads ─────────────────────────────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
async get(id: string) {
|
|
155
|
+
const row = await storeManager.get(id)
|
|
156
|
+
if (row.type !== 'course') throw new Error(`Not a course: ${id}`)
|
|
157
|
+
return row
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async list(opts: { published?: boolean; include_hidden?: boolean; limit?: number } = {}) {
|
|
161
|
+
return storeManager.list({ ...opts, type: 'course' })
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async modules(courseId: string): Promise<Module[]> {
|
|
165
|
+
const course = await this.get(courseId)
|
|
166
|
+
return parseModules(course.lessons as string | null)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Flatten every lesson across every module — useful for progress views. */
|
|
170
|
+
async allLessons(courseId: string): Promise<Array<Lesson & { module_id: string }>> {
|
|
171
|
+
const modules = await this.modules(courseId)
|
|
172
|
+
return modules.flatMap(m => m.lessons.map(l => ({ ...l, module_id: m.id })))
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ── Module mutations ──────────────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
async addModule(courseId: string, mod: ModuleInput): Promise<Module[]> {
|
|
178
|
+
await this.assertCourse(courseId)
|
|
179
|
+
const modules = await this.modules(courseId)
|
|
180
|
+
const next: Module = {
|
|
181
|
+
id: mod.id ?? moduleId(),
|
|
182
|
+
title: mod.title,
|
|
183
|
+
order: modules.length,
|
|
184
|
+
lessons: (mod.lessons ?? []).map((l, i) => ({
|
|
185
|
+
...l,
|
|
186
|
+
id: l.id ?? lessonId(),
|
|
187
|
+
order: i,
|
|
188
|
+
})),
|
|
189
|
+
}
|
|
190
|
+
const updated = [...modules, next]
|
|
191
|
+
await this.writeModules(courseId, updated)
|
|
192
|
+
await this.logMemory(`Added module "${mod.title}"`, { courseId, moduleId: next.id })
|
|
193
|
+
return updated
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async updateModule(
|
|
197
|
+
courseId: string,
|
|
198
|
+
moduleId: string,
|
|
199
|
+
patch: Partial<Pick<Module, 'title'>>,
|
|
200
|
+
): Promise<Module[]> {
|
|
201
|
+
await this.assertCourse(courseId)
|
|
202
|
+
const modules = await this.modules(courseId)
|
|
203
|
+
const idx = modules.findIndex(m => m.id === moduleId)
|
|
204
|
+
if (idx === -1) throw new Error(`Module not found: ${moduleId}`)
|
|
205
|
+
modules[idx] = { ...modules[idx], ...patch }
|
|
206
|
+
await this.writeModules(courseId, modules)
|
|
207
|
+
return modules
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async removeModule(courseId: string, moduleId: string): Promise<Module[]> {
|
|
211
|
+
await this.assertCourse(courseId)
|
|
212
|
+
const modules = await this.modules(courseId)
|
|
213
|
+
const next = modules
|
|
214
|
+
.filter(m => m.id !== moduleId)
|
|
215
|
+
.map((m, i) => ({ ...m, order: i }))
|
|
216
|
+
if (next.length === modules.length) throw new Error(`Module not found: ${moduleId}`)
|
|
217
|
+
await this.writeModules(courseId, next)
|
|
218
|
+
await this.logMemory(`Removed module ${moduleId}`, { courseId })
|
|
219
|
+
return next
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Reorder modules. Pass the new full order as a list of module ids.
|
|
223
|
+
* Ids not present are dropped — pass the full list to preserve all. */
|
|
224
|
+
async reorderModules(courseId: string, orderedIds: string[]): Promise<Module[]> {
|
|
225
|
+
await this.assertCourse(courseId)
|
|
226
|
+
const modules = await this.modules(courseId)
|
|
227
|
+
const byId = new Map(modules.map(m => [m.id, m]))
|
|
228
|
+
const next: Module[] = []
|
|
229
|
+
for (let i = 0; i < orderedIds.length; i++) {
|
|
230
|
+
const m = byId.get(orderedIds[i])
|
|
231
|
+
if (m) next.push({ ...m, order: i })
|
|
232
|
+
}
|
|
233
|
+
await this.writeModules(courseId, next)
|
|
234
|
+
return next
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ── Lesson mutations (scoped to a module) ─────────────────────────────────
|
|
238
|
+
|
|
239
|
+
async addLesson(
|
|
240
|
+
courseId: string,
|
|
241
|
+
moduleId: string,
|
|
242
|
+
lesson: LessonInput,
|
|
243
|
+
): Promise<Module[]> {
|
|
244
|
+
await this.assertCourse(courseId)
|
|
245
|
+
const modules = await this.modules(courseId)
|
|
246
|
+
const m = modules.find(x => x.id === moduleId)
|
|
247
|
+
if (!m) throw new Error(`Module not found: ${moduleId}`)
|
|
248
|
+
|
|
249
|
+
const next: Lesson = {
|
|
250
|
+
...lesson,
|
|
251
|
+
id: lesson.id ?? lessonId(),
|
|
252
|
+
order: m.lessons.length,
|
|
253
|
+
}
|
|
254
|
+
m.lessons = [...m.lessons, next]
|
|
255
|
+
await this.writeModules(courseId, modules)
|
|
256
|
+
await this.logMemory(`Added lesson "${lesson.title}"`,
|
|
257
|
+
{ courseId, moduleId, lessonId: next.id })
|
|
258
|
+
return modules
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async updateLesson(
|
|
262
|
+
courseId: string,
|
|
263
|
+
moduleId: string,
|
|
264
|
+
lessonId: string,
|
|
265
|
+
patch: Partial<Omit<Lesson, 'id' | 'order'>>,
|
|
266
|
+
): Promise<Module[]> {
|
|
267
|
+
await this.assertCourse(courseId)
|
|
268
|
+
const modules = await this.modules(courseId)
|
|
269
|
+
const m = modules.find(x => x.id === moduleId)
|
|
270
|
+
if (!m) throw new Error(`Module not found: ${moduleId}`)
|
|
271
|
+
const idx = m.lessons.findIndex(l => l.id === lessonId)
|
|
272
|
+
if (idx === -1) throw new Error(`Lesson not found: ${lessonId}`)
|
|
273
|
+
m.lessons[idx] = { ...m.lessons[idx], ...patch }
|
|
274
|
+
await this.writeModules(courseId, modules)
|
|
275
|
+
return modules
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async removeLesson(
|
|
279
|
+
courseId: string,
|
|
280
|
+
moduleId: string,
|
|
281
|
+
lessonId: string,
|
|
282
|
+
): Promise<Module[]> {
|
|
283
|
+
await this.assertCourse(courseId)
|
|
284
|
+
const modules = await this.modules(courseId)
|
|
285
|
+
const m = modules.find(x => x.id === moduleId)
|
|
286
|
+
if (!m) throw new Error(`Module not found: ${moduleId}`)
|
|
287
|
+
const before = m.lessons.length
|
|
288
|
+
m.lessons = m.lessons
|
|
289
|
+
.filter(l => l.id !== lessonId)
|
|
290
|
+
.map((l, i) => ({ ...l, order: i }))
|
|
291
|
+
if (m.lessons.length === before) throw new Error(`Lesson not found: ${lessonId}`)
|
|
292
|
+
await this.writeModules(courseId, modules)
|
|
293
|
+
await this.logMemory(`Removed lesson ${lessonId}`, { courseId, moduleId })
|
|
294
|
+
return modules
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Reorder lessons inside a module. Ids not present are dropped. */
|
|
298
|
+
async reorderLessons(
|
|
299
|
+
courseId: string,
|
|
300
|
+
moduleId: string,
|
|
301
|
+
orderedIds: string[],
|
|
302
|
+
): Promise<Module[]> {
|
|
303
|
+
await this.assertCourse(courseId)
|
|
304
|
+
const modules = await this.modules(courseId)
|
|
305
|
+
const m = modules.find(x => x.id === moduleId)
|
|
306
|
+
if (!m) throw new Error(`Module not found: ${moduleId}`)
|
|
307
|
+
const byId = new Map(m.lessons.map(l => [l.id, l]))
|
|
308
|
+
m.lessons = orderedIds
|
|
309
|
+
.map((id, i) => {
|
|
310
|
+
const l = byId.get(id)
|
|
311
|
+
return l ? { ...l, order: i } : null
|
|
312
|
+
})
|
|
313
|
+
.filter(Boolean) as Lesson[]
|
|
314
|
+
await this.writeModules(courseId, modules)
|
|
315
|
+
return modules
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Move a lesson to a different module. Appends at end of the target
|
|
319
|
+
* module and compacts order on both sides. */
|
|
320
|
+
async moveLesson(
|
|
321
|
+
courseId: string,
|
|
322
|
+
lessonId: string,
|
|
323
|
+
fromModuleId: string,
|
|
324
|
+
toModuleId: string,
|
|
325
|
+
): Promise<Module[]> {
|
|
326
|
+
await this.assertCourse(courseId)
|
|
327
|
+
if (fromModuleId === toModuleId) return this.modules(courseId)
|
|
328
|
+
const modules = await this.modules(courseId)
|
|
329
|
+
const from = modules.find(m => m.id === fromModuleId)
|
|
330
|
+
const to = modules.find(m => m.id === toModuleId)
|
|
331
|
+
if (!from) throw new Error(`Source module not found: ${fromModuleId}`)
|
|
332
|
+
if (!to) throw new Error(`Target module not found: ${toModuleId}`)
|
|
333
|
+
|
|
334
|
+
const idx = from.lessons.findIndex(l => l.id === lessonId)
|
|
335
|
+
if (idx === -1) throw new Error(`Lesson not found in source module: ${lessonId}`)
|
|
336
|
+
const [lesson] = from.lessons.splice(idx, 1)
|
|
337
|
+
from.lessons = from.lessons.map((l, i) => ({ ...l, order: i }))
|
|
338
|
+
to.lessons = [...to.lessons, { ...lesson, order: to.lessons.length }]
|
|
339
|
+
|
|
340
|
+
await this.writeModules(courseId, modules)
|
|
341
|
+
return modules
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ── Student progress (reads from purchases) ───────────────────────────────
|
|
345
|
+
|
|
346
|
+
async students(courseId: string, opts: { completed?: boolean; limit?: number } = {}) {
|
|
347
|
+
await this.init()
|
|
348
|
+
await this.assertCourse(courseId)
|
|
349
|
+
let where = `WHERE product_id=? AND profile_id=?
|
|
350
|
+
AND payment_status='completed' AND status='active'`
|
|
351
|
+
const args: unknown[] = [courseId, this.profileId]
|
|
352
|
+
if (opts.completed !== undefined) {
|
|
353
|
+
where += ' AND course_completed=?'
|
|
354
|
+
args.push(opts.completed ? 1 : 0)
|
|
355
|
+
}
|
|
356
|
+
const { rows } = await db.execute({
|
|
357
|
+
sql: `SELECT id, email, customer_name,
|
|
358
|
+
course_progress, course_completed, course_completion_date,
|
|
359
|
+
last_accessed_at, access_count, created_at
|
|
360
|
+
FROM purchases ${where}
|
|
361
|
+
ORDER BY created_at DESC LIMIT ?`,
|
|
362
|
+
args: [...args, opts.limit ?? 100],
|
|
363
|
+
})
|
|
364
|
+
return rows
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async enrollmentStats(courseId: string) {
|
|
368
|
+
await this.init()
|
|
369
|
+
await this.assertCourse(courseId)
|
|
370
|
+
const { rows: [r] } = await db.execute({
|
|
371
|
+
sql: `SELECT
|
|
372
|
+
COUNT(*) AS enrolled,
|
|
373
|
+
SUM(CASE WHEN course_completed=1 THEN 1 ELSE 0 END) AS completed,
|
|
374
|
+
COALESCE(SUM(amount_cents), 0) AS revenue_cents
|
|
375
|
+
FROM purchases
|
|
376
|
+
WHERE product_id=? AND profile_id=?
|
|
377
|
+
AND payment_status='completed' AND status='active'`,
|
|
378
|
+
args: [courseId, this.profileId],
|
|
379
|
+
})
|
|
380
|
+
const enrolled = Number(r?.enrolled ?? 0)
|
|
381
|
+
const completed = Number(r?.completed ?? 0)
|
|
382
|
+
return {
|
|
383
|
+
enrolled,
|
|
384
|
+
completed,
|
|
385
|
+
completion_rate: enrolled ? completed / enrolled : 0,
|
|
386
|
+
revenue_cents: Number(r?.revenue_cents ?? 0),
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ── Private ───────────────────────────────────────────────────────────────
|
|
391
|
+
|
|
392
|
+
private async assertCourse(id: string): Promise<void> {
|
|
393
|
+
await this.init()
|
|
394
|
+
const { rows: [r] } = await db.execute({
|
|
395
|
+
sql: `SELECT type FROM products WHERE id=? AND profile_id=? LIMIT 1`,
|
|
396
|
+
args: [id, this.profileId],
|
|
397
|
+
})
|
|
398
|
+
if (!r) throw new Error(`Course not found (or not yours): ${id}`)
|
|
399
|
+
if (r.type !== 'course') throw new Error(`Not a course: ${id}`)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private async writeModules(courseId: string, modules: Module[]): Promise<void> {
|
|
403
|
+
await db.write({
|
|
404
|
+
sql: `UPDATE products
|
|
405
|
+
SET lessons=?, total_lessons=?, updated_at=?
|
|
406
|
+
WHERE id=? AND profile_id=?`,
|
|
407
|
+
args: [
|
|
408
|
+
JSON.stringify(modules),
|
|
409
|
+
countLessons(modules),
|
|
410
|
+
now(),
|
|
411
|
+
courseId, this.profileId,
|
|
412
|
+
],
|
|
413
|
+
})
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function countLessons(modules: Module[]): number {
|
|
418
|
+
return modules.reduce((sum, m) => sum + (m.lessons?.length ?? 0), 0)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function parseModules(raw: string | null): Module[] {
|
|
422
|
+
if (!raw) return []
|
|
423
|
+
try {
|
|
424
|
+
const parsed = JSON.parse(raw)
|
|
425
|
+
if (!Array.isArray(parsed)) return []
|
|
426
|
+
// Normalise — older rows might use `position` instead of `order`, or
|
|
427
|
+
// store a flat lesson array with no modules. Coerce to module shape.
|
|
428
|
+
return parsed.map((entry, i) => {
|
|
429
|
+
if (entry && typeof entry === 'object' && Array.isArray(entry.lessons)) {
|
|
430
|
+
return {
|
|
431
|
+
id: entry.id ?? moduleId(),
|
|
432
|
+
title: entry.title ?? `Module ${i + 1}`,
|
|
433
|
+
order: Number(entry.order ?? entry.position ?? i),
|
|
434
|
+
lessons: entry.lessons.map((l: Record<string, unknown>, li: number) => ({
|
|
435
|
+
...l,
|
|
436
|
+
order: Number(l.order ?? l.position ?? li),
|
|
437
|
+
})) as Lesson[],
|
|
438
|
+
} as Module
|
|
439
|
+
}
|
|
440
|
+
// Flat lesson — wrap as a single default module on first parse.
|
|
441
|
+
return null
|
|
442
|
+
}).filter(Boolean) as Module[]
|
|
443
|
+
} catch {
|
|
444
|
+
return []
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const moduleId = () => `module-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
449
|
+
const lessonId = () => `lesson-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
450
|
+
|
|
451
|
+
export const courseCreator = new CourseCreator()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# docs
|
|
2
|
+
|
|
3
|
+
Placeholder SOUL. See CLAUDE.md routing table and skills/docs/SKILL.md (if present) for scope.
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
- Load skills on demand
|
|
8
|
+
- Draft before publish
|
|
9
|
+
- Archive not delete (hidden=1)
|
|
10
|
+
- Log every action to agent_memory
|
|
11
|
+
- Push reports to agent_reports mid-session
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# forms
|
|
2
|
+
|
|
3
|
+
Placeholder SOUL. See CLAUDE.md routing table and skills/forms/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
|