@businesskit/agent 1.0.4 → 1.0.7

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 (190) 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 +62 -0
  5. package/AGENTS.md +105 -63
  6. package/CLAUDE.md +11 -84
  7. package/GEMINI.md +11 -34
  8. package/README.md +95 -154
  9. package/assets/logo.svg +3 -0
  10. package/bin/businesskit.js +45 -18
  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/brief.md +12 -0
  15. package/commands/capabilities.md +33 -0
  16. package/commands/chase.md +12 -0
  17. package/commands/check-stock.md +43 -0
  18. package/commands/create-component.md +109 -0
  19. package/commands/create-invoice.md +69 -0
  20. package/commands/create-new-bill.md +65 -0
  21. package/commands/create-page.md +124 -0
  22. package/commands/crm.md +13 -0
  23. package/commands/followups.md +13 -0
  24. package/commands/list-components.md +41 -0
  25. package/commands/list-content.md +46 -0
  26. package/commands/list-pages.md +45 -0
  27. package/commands/pipeline.md +13 -0
  28. package/commands/publish-page.md +64 -0
  29. package/commands/send-invoice.md +42 -0
  30. package/commands/seo-audit.md +36 -0
  31. package/commands/update-agent.md +33 -0
  32. package/commands/update-contact.md +46 -0
  33. package/commands/update-content.md +48 -0
  34. package/commands/update-page.md +56 -0
  35. package/commands/update-price.md +47 -0
  36. package/commands/write-blog.md +56 -0
  37. package/commands/write-docs.md +90 -0
  38. package/commands/write-guide.md +51 -0
  39. package/commands/write-newsletter.md +50 -0
  40. package/dist/server.js +4099 -0
  41. package/mcp_config.json +12 -0
  42. package/package.json +54 -25
  43. package/plugin.json +32 -0
  44. package/scripts/setup.sh +169 -0
  45. package/scripts/setup.ts +129 -0
  46. package/scripts/update.sh +56 -0
  47. package/server.json +21 -0
  48. package/skills/README.md +20 -27
  49. package/skills/billing/SKILL.md +64 -0
  50. package/skills/brand/SKILL.md +30 -86
  51. package/skills/cms/SKILL.md +111 -0
  52. package/skills/cms/references/cms-hubs.md +84 -0
  53. package/skills/cms/references/html-blocks.md +177 -0
  54. package/skills/copywriting/SKILL.md +1 -1
  55. package/skills/crm/SKILL.md +24 -0
  56. package/skills/docs/SKILL.md +65 -0
  57. package/skills/docs/references/how-to.md +155 -0
  58. package/skills/inbox/SKILL.md +49 -0
  59. package/skills/inventory/SKILL.md +69 -0
  60. package/skills/pages/SKILL.md +214 -0
  61. package/skills/pages/references/sections-catalog.json +1183 -0
  62. package/skills/social/SKILL.md +84 -211
  63. package/skills/social/evals/evals.json +66 -0
  64. package/skills/social/evals/rubric.md +26 -0
  65. package/skills/social/examples/repurposing-blog-to-social.md +93 -0
  66. package/skills/social/examples/weekly-content-calendar.md +30 -0
  67. package/skills/social/linkedin/SKILL.md +107 -0
  68. package/skills/social/linkedin/evals/evals.json +106 -0
  69. package/skills/social/linkedin/evals/rubric.md +28 -0
  70. package/skills/social/linkedin/examples/gasp-weekly-sprint.md +24 -0
  71. package/skills/social/linkedin/examples/growth-posts-by-format.md +140 -0
  72. package/skills/social/linkedin/references/gasp-funnel-and-calibration.md +90 -0
  73. package/skills/social/linkedin/references/six-growth-formats.md +114 -0
  74. package/skills/social/references/platforms.md +76 -0
  75. package/skills/social/references/post-templates.md +105 -0
  76. package/skills/social/references/reverse-engineering.md +62 -0
  77. package/src/data/sections-catalog.json +950 -0
  78. package/src/db.ts +170 -0
  79. package/src/server.ts +75 -0
  80. package/src/tools/content.ts +326 -0
  81. package/src/tools/crm.ts +1416 -0
  82. package/src/tools/domains.ts +89 -0
  83. package/src/tools/inbox.ts +270 -0
  84. package/src/tools/index.ts +116 -0
  85. package/src/tools/pages.ts +1217 -0
  86. package/src/tools/shop.ts +771 -0
  87. package/src/tools/system.ts +94 -0
  88. package/src/tools/types.ts +17 -0
  89. package/templates/antigravity.json +8 -0
  90. package/templates/claude-code.mcp.json +8 -0
  91. package/templates/cursor.mcp.json +8 -0
  92. package/templates/vscode.mcp.json +9 -0
  93. package/.claude/commands/analytics.md +0 -7
  94. package/.claude/commands/blog-writer.md +0 -9
  95. package/.claude/commands/cbo.md +0 -7
  96. package/.claude/commands/ceo.md +0 -10
  97. package/.claude/commands/cmo.md +0 -7
  98. package/.claude/commands/compress.md +0 -73
  99. package/.claude/commands/coo.md +0 -11
  100. package/.claude/commands/copywriter.md +0 -15
  101. package/.claude/commands/course-creator.md +0 -9
  102. package/.claude/commands/crm.md +0 -591
  103. package/.claude/commands/deep.md +0 -50
  104. package/.claude/commands/docs-writer.md +0 -8
  105. package/.claude/commands/forms-builder.md +0 -10
  106. package/.claude/commands/ingest.md +0 -110
  107. package/.claude/commands/jobs-manager.md +0 -8
  108. package/.claude/commands/kb.md +0 -107
  109. package/.claude/commands/newsletter-writer.md +0 -9
  110. package/.claude/commands/preserve.md +0 -64
  111. package/.claude/commands/resume.md +0 -67
  112. package/.claude/commands/scheduler.md +0 -8
  113. package/.claude/commands/seo.md +0 -60
  114. package/.claude/commands/social.md +0 -51
  115. package/.claude/commands/store-manager.md +0 -11
  116. package/.claude/settings.json +0 -16
  117. package/.claude/settings.local.json +0 -11
  118. package/.env.example +0 -12
  119. package/.mcp.json +0 -3
  120. package/HEARTBEAT.md +0 -105
  121. package/PLAN.md +0 -345
  122. package/PRD-Agent-Composition.md +0 -149
  123. package/PRD-Agent-Harness.md +0 -316
  124. package/REFERENCE.md +0 -160
  125. package/SOUL.md +0 -148
  126. package/SYSTEM.md +0 -71
  127. package/agents/_base.ts +0 -371
  128. package/agents/analytics/SOUL.md +0 -11
  129. package/agents/analytics/analytics.ts +0 -405
  130. package/agents/business/SOUL.md +0 -11
  131. package/agents/business/business.ts +0 -109
  132. package/agents/ceo/SOUL.md +0 -15
  133. package/agents/ceo/ceo.ts +0 -146
  134. package/agents/content/SOUL.md +0 -11
  135. package/agents/content/content.ts +0 -379
  136. package/agents/copywriting/SOUL.md +0 -11
  137. package/agents/copywriting/copywriting.ts +0 -89
  138. package/agents/courses/SOUL.md +0 -11
  139. package/agents/courses/courses.ts +0 -451
  140. package/agents/docs/SOUL.md +0 -11
  141. package/agents/docs/docs.ts +0 -77
  142. package/agents/forms/SOUL.md +0 -11
  143. package/agents/forms/forms.ts +0 -364
  144. package/agents/hiring/SOUL.md +0 -11
  145. package/agents/hiring/hiring.ts +0 -314
  146. package/agents/marketing/SOUL.md +0 -15
  147. package/agents/marketing/marketing.ts +0 -109
  148. package/agents/newsletter/SOUL.md +0 -11
  149. package/agents/newsletter/newsletter.ts +0 -91
  150. package/agents/operations/SOUL.md +0 -11
  151. package/agents/operations/operations.ts +0 -157
  152. package/agents/sales/SOUL.md +0 -44
  153. package/agents/sales/sales.ts +0 -883
  154. package/agents/scheduler/SOUL.md +0 -11
  155. package/agents/scheduler/scheduler.ts +0 -68
  156. package/agents/seo/SOUL.md +0 -11
  157. package/agents/seo/seo.ts +0 -288
  158. package/agents/social/SOUL.md +0 -11
  159. package/agents/social/social.ts +0 -744
  160. package/agents/store/SOUL.md +0 -11
  161. package/agents/store/store.ts +0 -514
  162. package/cli.ts +0 -144
  163. package/context/about-me.md +0 -96
  164. package/context/brand-voice.md +0 -127
  165. package/context/brand.md +0 -80
  166. package/context/business.md +0 -66
  167. package/context/working-style.md +0 -87
  168. package/lib/analytics.ts +0 -81
  169. package/lib/cms.ts +0 -88
  170. package/lib/db.adapter.ts +0 -30
  171. package/lib/db.ts +0 -63
  172. package/lib/enums.ts +0 -25
  173. package/lib/groups.ts +0 -122
  174. package/lib/id.ts +0 -43
  175. package/lib/kb.ts +0 -337
  176. package/lib/memory.ts +0 -219
  177. package/lib/pattern-detector.ts +0 -169
  178. package/lib/profile.ts +0 -155
  179. package/lib/schema.ts +0 -2015
  180. package/lib/slug.ts +0 -30
  181. package/lib/validate.ts +0 -33
  182. package/setup.ts +0 -141
  183. package/skills/agents/SKILL.md +0 -56
  184. package/skills/analytics/SKILL.md +0 -52
  185. package/skills/blog-writer/SKILL.md +0 -452
  186. package/skills/ceo/SKILL.md +0 -25
  187. package/skills/cmo/SKILL.md +0 -8
  188. package/skills/schema/SKILL.md +0 -86
  189. package/skills/store/SKILL.md +0 -62
  190. package/tsconfig.json +0 -14
@@ -1,451 +0,0 @@
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()
@@ -1,11 +0,0 @@
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
@@ -1,77 +0,0 @@
1
- /**
2
- * DOC — Docs Writer
3
- * "I make complex things simple. In writing."
4
- * Writes to: doc_collections (AUTOINCREMENT), doc_articles (AUTOINCREMENT)
5
- */
6
-
7
- import { BaseAgent, db, iso } from '../_base.ts'
8
- import { toSlug } from '../../lib/slug.ts'
9
-
10
- export class DocsWriter extends BaseAgent {
11
- readonly name = 'DOC'
12
- readonly title = 'Docs Writer'
13
-
14
- async createCollection(input: { slug: string; title: string; description?: string; icon?: string; sort_order?: number }) {
15
- const { lastInsertRowid } = await db.execute({
16
- sql: 'INSERT INTO doc_collections (slug,title,description,icon,sort_order,is_default,created_at) VALUES (?,?,?,?,?,0,?)',
17
- args: [input.slug, input.title, input.description ?? null, input.icon ?? null, input.sort_order ?? 0, iso()],
18
- })
19
- return Number(lastInsertRowid)
20
- }
21
-
22
- async listCollections() {
23
- const { rows } = await db.execute({ sql: 'SELECT * FROM doc_collections ORDER BY sort_order', args: [] })
24
- return rows
25
- }
26
-
27
- async createArticle(input: {
28
- collection_id: number; title: string; body: string
29
- excerpt?: string; slug?: string; publish?: boolean
30
- }) {
31
- await this.init()
32
- const slug = input.slug ?? toSlug(input.title)
33
- const ts = iso()
34
-
35
- const { lastInsertRowid } = await db.execute({
36
- sql: `INSERT INTO doc_articles (collection_id,profile_id,user_id,slug,title,excerpt,body,published,created_at,updated_at)
37
- VALUES (?,?,?,?,?,?,?,?,?,?)`,
38
- args: [input.collection_id, this.profileId, this.userId, slug, input.title,
39
- input.excerpt ?? null, input.body, input.publish ? 1 : 0, ts, ts],
40
- })
41
- return this.getArticle(Number(lastInsertRowid))
42
- }
43
-
44
- async getArticle(id: number) {
45
- const { rows: [r] } = await db.execute({ sql: 'SELECT * FROM doc_articles WHERE id=?', args: [id] })
46
- if (!r) throw new Error(`Article not found: ${id}`)
47
- return r
48
- }
49
-
50
- async listArticles(collectionId?: number, published?: boolean) {
51
- await this.init()
52
- let where = 'WHERE profile_id=?'
53
- const args: unknown[] = [this.profileId]
54
- if (collectionId !== undefined) { where += ' AND collection_id=?'; args.push(collectionId) }
55
- if (published !== undefined) { where += ' AND published=?'; args.push(published ? 1 : 0) }
56
- const { rows } = await db.execute({
57
- sql: `SELECT id,collection_id,title,slug,published,views FROM doc_articles ${where} ORDER BY updated_at DESC`,
58
- args,
59
- })
60
- return rows
61
- }
62
-
63
- async updateArticle(id: number, fields: { title?: string; body?: string; excerpt?: string; publish?: boolean }) {
64
- const sets = [`updated_at='${iso()}'`]
65
- const args: unknown[] = []
66
- if (fields.title !== undefined) { sets.push('title=?'); args.push(fields.title) }
67
- if (fields.body !== undefined) { sets.push('body=?'); args.push(fields.body) }
68
- if (fields.excerpt !== undefined) { sets.push('excerpt=?'); args.push(fields.excerpt) }
69
- if (fields.publish !== undefined) { sets.push('published=?'); args.push(fields.publish ? 1 : 0) }
70
- await db.execute({ sql: `UPDATE doc_articles SET ${sets.join(',')} WHERE id=?`, args: [...args, id] })
71
- return this.getArticle(id)
72
- }
73
-
74
- async publishArticle(id: number) { return this.updateArticle(id, { publish: true }) }
75
- }
76
-
77
- export const docsWriter = new DocsWriter()
@@ -1,11 +0,0 @@
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