@businesskit/agent 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.cursor-plugin/plugin.json +25 -0
  3. package/.cursorrules +10 -0
  4. package/.superconsole-plugin/plugin.json +32 -0
  5. package/AGENTS.md +94 -63
  6. package/CLAUDE.md +11 -65
  7. package/GEMINI.md +11 -34
  8. package/README.md +106 -153
  9. package/assets/logo.svg +3 -0
  10. package/bin/businesskit.js +11 -17
  11. package/commands/add-contact.md +47 -0
  12. package/commands/add-inventory-from-invoice.md +80 -0
  13. package/commands/adjust-stock.md +46 -0
  14. package/commands/capabilities.md +33 -0
  15. package/commands/check-stock.md +43 -0
  16. package/commands/create-component.md +109 -0
  17. package/commands/create-invoice.md +69 -0
  18. package/commands/create-new-bill.md +65 -0
  19. package/commands/create-page.md +96 -0
  20. package/commands/list-components.md +41 -0
  21. package/commands/list-content.md +46 -0
  22. package/commands/list-pages.md +45 -0
  23. package/commands/publish-page.md +64 -0
  24. package/commands/send-invoice.md +42 -0
  25. package/commands/seo-audit.md +36 -0
  26. package/commands/update-contact.md +46 -0
  27. package/commands/update-content.md +47 -0
  28. package/commands/update-page.md +55 -0
  29. package/commands/update-price.md +47 -0
  30. package/commands/write-blog.md +52 -0
  31. package/commands/write-docs.md +84 -0
  32. package/commands/write-guide.md +46 -0
  33. package/commands/write-newsletter.md +46 -0
  34. package/mcp_config.json +8 -0
  35. package/package.json +34 -23
  36. package/plugin.json +32 -0
  37. package/scripts/generate-schema.ts +244 -0
  38. package/scripts/setup.sh +134 -0
  39. package/scripts/setup.ts +92 -0
  40. package/server.json +21 -0
  41. package/skills/README.md +19 -27
  42. package/skills/billing/SKILL.md +64 -0
  43. package/skills/brand/SKILL.md +30 -86
  44. package/skills/copywriting/SKILL.md +1 -1
  45. package/skills/crm/SKILL.md +38 -0
  46. package/skills/docs-cms/SKILL.md +53 -0
  47. package/skills/docs-cms/references/how-to.md +383 -0
  48. package/skills/inbox/SKILL.md +49 -0
  49. package/skills/inventory/SKILL.md +69 -0
  50. package/skills/pages/SKILL.md +169 -0
  51. package/skills/pages/references/sections-catalog.json +950 -0
  52. package/skills/social/SKILL.md +1 -1
  53. package/templates/antigravity.json +8 -0
  54. package/templates/claude-code.mcp.json +8 -0
  55. package/templates/cursor.mcp.json +8 -0
  56. package/templates/vscode.mcp.json +9 -0
  57. package/.claude/commands/analytics.md +0 -7
  58. package/.claude/commands/blog-writer.md +0 -9
  59. package/.claude/commands/cbo.md +0 -7
  60. package/.claude/commands/ceo.md +0 -10
  61. package/.claude/commands/cmo.md +0 -7
  62. package/.claude/commands/compress.md +0 -73
  63. package/.claude/commands/coo.md +0 -11
  64. package/.claude/commands/copywriter.md +0 -15
  65. package/.claude/commands/course-creator.md +0 -9
  66. package/.claude/commands/crm.md +0 -591
  67. package/.claude/commands/deep.md +0 -50
  68. package/.claude/commands/docs-writer.md +0 -8
  69. package/.claude/commands/forms-builder.md +0 -10
  70. package/.claude/commands/jobs-manager.md +0 -8
  71. package/.claude/commands/kb.md +0 -107
  72. package/.claude/commands/newsletter-writer.md +0 -9
  73. package/.claude/commands/preserve.md +0 -64
  74. package/.claude/commands/resume.md +0 -67
  75. package/.claude/commands/scheduler.md +0 -8
  76. package/.claude/commands/seo.md +0 -60
  77. package/.claude/commands/social.md +0 -51
  78. package/.claude/commands/store-manager.md +0 -11
  79. package/.env.example +0 -2
  80. package/.mcp.json +0 -3
  81. package/ABOUT-ME.md +0 -96
  82. package/HEARTBEAT.md +0 -105
  83. package/PLAN.md +0 -384
  84. package/PRD-Agent-Composition.md +0 -149
  85. package/PRD-Agent-Harness.md +0 -316
  86. package/REFERENCE.md +0 -124
  87. package/SOUL.md +0 -148
  88. package/SYSTEM.md +0 -71
  89. package/agents/_base.ts +0 -63
  90. package/agents/creators/blog-writer.ts +0 -347
  91. package/agents/creators/copywriter.ts +0 -89
  92. package/agents/creators/course-creator.ts +0 -106
  93. package/agents/creators/crm-agent.ts +0 -479
  94. package/agents/creators/docs-writer.ts +0 -77
  95. package/agents/creators/forms-builder.ts +0 -90
  96. package/agents/creators/jobs-manager.ts +0 -82
  97. package/agents/creators/newsletter-writer.ts +0 -91
  98. package/agents/creators/store-manager.ts +0 -138
  99. package/agents/csuite/cbo.ts +0 -109
  100. package/agents/csuite/ceo.ts +0 -121
  101. package/agents/csuite/cmo.ts +0 -109
  102. package/agents/csuite/coo.ts +0 -115
  103. package/agents/growth/analytics-agent.ts +0 -52
  104. package/agents/growth/scheduler.ts +0 -68
  105. package/agents/growth/seo-agent.ts +0 -282
  106. package/agents/growth/social-agent.ts +0 -346
  107. package/brand-voice.md +0 -127
  108. package/cli.ts +0 -125
  109. package/context/brand.md +0 -80
  110. package/context/business.md +0 -66
  111. package/ingest.md +0 -110
  112. package/lib/analytics.ts +0 -81
  113. package/lib/db.adapter.ts +0 -30
  114. package/lib/db.ts +0 -16
  115. package/lib/id.ts +0 -15
  116. package/lib/kb.ts +0 -337
  117. package/lib/memory.ts +0 -219
  118. package/lib/pattern-detector.ts +0 -169
  119. package/lib/profile.ts +0 -119
  120. package/lib/slug.ts +0 -30
  121. package/setup.ts +0 -127
  122. package/skills/agents/SKILL.md +0 -56
  123. package/skills/analytics/SKILL.md +0 -52
  124. package/skills/blog-writer/SKILL.md +0 -452
  125. package/skills/ceo/SKILL.md +0 -25
  126. package/skills/cmo/SKILL.md +0 -8
  127. package/skills/schema/SKILL.md +0 -45
  128. package/skills/store/SKILL.md +0 -62
  129. package/tsconfig.json +0 -13
  130. package/working-style.md +0 -87
@@ -1,591 +0,0 @@
1
- # /crm — Agent-First CRM
2
-
3
- Full contact management, deal pipeline, outreach, proposals, invoices, and analytics.
4
- Reads/writes directly to Turso UserDB. DB triggers keep analytics accurate automatically.
5
-
6
- ---
7
-
8
- ## Architecture
9
-
10
- ```
11
- You/Agent writes → Turso DB → Triggers fire → crm_analytics always accurate
12
- → No app server needed
13
- ```
14
-
15
- **13 DB triggers** handle all scalar analytics in real-time:
16
-
17
- - Contact insert/convert/archive → funnel counts
18
- - Activity insert/approve/reject → agent metrics + approval queue
19
- - Deal insert/won/lost/update → pipeline + forecast
20
-
21
- **JSON breakdowns** (7d/30d/12m/lifetime/utm) aggregate on analytics page visit.
22
-
23
- ---
24
-
25
- ## Tables
26
-
27
- | Table | Purpose |
28
- |---|---|
29
- | `crm_contacts` | Leads, prospects, customers + full agent state |
30
- | `crm_deals` | Pipeline opportunities |
31
- | `crm_activities` | Append-only timeline (DMs, emails, calls, purchases) |
32
- | `crm_tasks` | Follow-up to-dos |
33
- | `crm_notes` | Rich-text notes per contact |
34
- | `crm_groups` | Named groups (Investors, Clients, VIP etc) |
35
- | `crm_templates` | Outreach templates with reply rate tracking |
36
- | `crm_proposals` | Client proposals with e-sign + payment |
37
- | `crm_invoices` | Invoices with line items |
38
- | `crm_analytics` | 1 row per profile, always current |
39
-
40
- ---
41
-
42
- ## Session start
43
-
44
- ```
45
- /crm
46
- ```
47
-
48
- Always run this first:
49
-
50
- ```ts
51
- // 1. Pipeline summary
52
- SELECT * FROM crm_analytics LIMIT 1
53
- // → total_contacts, open_deals, total_pending_approvals, forecast_this_month_cents
54
-
55
- // 2. Pending approvals (show these first — agent is waiting on you)
56
- SELECT a.*, c.first_name, c.last_name, c.platform
57
- FROM crm_activities a
58
- JOIN crm_contacts c ON c.id = a.contact_id
59
- WHERE a.approval_status = 'pending_approval'
60
- ORDER BY a.approval_requested_at DESC
61
- LIMIT 10
62
-
63
- // 3. Follow-ups due today
64
- SELECT t.*, c.first_name, c.last_name
65
- FROM crm_tasks t
66
- JOIN crm_contacts c ON c.id = t.contact_id
67
- WHERE t.status = 'open' AND t.due_at <= strftime('%s','now')
68
- ORDER BY t.due_at ASC
69
- LIMIT 10
70
-
71
- // 4. Hot leads ready for outreach
72
- SELECT id, first_name, last_name, company, platform, lead_score,
73
- pain_point, suggested_dm, outreach_status, agent_status
74
- FROM crm_contacts
75
- WHERE agent_status = 'outreach_ready'
76
- AND outreach_status = 'new'
77
- AND archived = 0
78
- ORDER BY lead_score DESC
79
- LIMIT 10
80
- ```
81
-
82
- ---
83
-
84
- ## Contacts
85
-
86
- ### Add a contact (manual)
87
-
88
- ```ts
89
- INSERT INTO crm_contacts (
90
- id, profile_id, first_name, last_name, email, company,
91
- platform, status, source, contact_type
92
- ) VALUES (?, ?, ?, ?, ?, ?, ?, 'lead', 'manual', 'professional')
93
- // trigger fires → crm_analytics.total_contacts + 1, total_leads + 1
94
- ```
95
-
96
- ### Research a lead (agent)
97
-
98
- ```ts
99
- // 1. Read existing context before acting
100
- SELECT * FROM crm_contacts WHERE id = ?
101
-
102
- // 2. Check agent_paused
103
- // if agent_paused = 1 AND (agent_paused_until IS NULL OR agent_paused_until > now()) → SKIP
104
-
105
- // 3. Check agent_instructions for per-contact overrides
106
-
107
- // 4. Update with research findings
108
- UPDATE crm_contacts SET
109
- bio = ?,
110
- recent_post = ?,
111
- recent_post_url = ?,
112
- pain_point = ?,
113
- audience_size = ?,
114
- company_size = ?,
115
- industry = ?,
116
- lead_score = ?,
117
- lead_score_reason = ?,
118
- icp_match = ?, -- 'strong'|'moderate'|'weak'|'unknown'
119
- urgency = ?,
120
- buying_intent = ?,
121
- social_links = ?, -- JSON [{platform, url, username, followers}]
122
- agent_status = 'enriched',
123
- agent_context = ?, -- JSON {summary, tone, preferred_channel, do_not_mention[]}
124
- agent_last_run_at = strftime('%s','now'),
125
- enriched_at = strftime('%s','now'),
126
- enrichment_source = 'agent',
127
- updated_at = strftime('%s','now')
128
- WHERE id = ?
129
- ```
130
-
131
- ### List contacts
132
-
133
- ```
134
- "Show my top leads"
135
- → SELECT ... WHERE agent_status = 'enriched' ORDER BY lead_score DESC LIMIT 20
136
-
137
- "Show leads ready for outreach"
138
- → SELECT ... WHERE agent_status = 'outreach_ready' AND outreach_status = 'new'
139
-
140
- "Show who replied"
141
- → SELECT ... WHERE outreach_status = 'replied'
142
-
143
- "Show prospects in Investors group"
144
- → SELECT ... WHERE groups LIKE '%grp_005%'
145
-
146
- "Show contacts from Twitter"
147
- → SELECT ... WHERE platform = 'twitter'
148
- ```
149
-
150
- ### Score a lead
151
-
152
- ```ts
153
- UPDATE crm_contacts SET
154
- lead_score = ?, -- 0-100
155
- lead_score_reason = ?,
156
- icp_match = ?,
157
- urgency = ?,
158
- buying_intent = ?,
159
- agent_status = 'outreach_ready',
160
- updated_at = strftime('%s','now')
161
- WHERE id = ?
162
- ```
163
-
164
- ### Update contact status
165
-
166
- ```ts
167
- UPDATE crm_contacts SET
168
- status = 'customer', -- trigger fires → total_customers+1, total_leads-1
169
- updated_at = strftime('%s','now')
170
- WHERE id = ?
171
- ```
172
-
173
- ---
174
-
175
- ## Outreach
176
-
177
- ### Draft a DM (agent, needs approval)
178
-
179
- ```ts
180
- // 1. Pull full context first
181
- SELECT c.*,
182
- (SELECT body FROM crm_activities WHERE contact_id = c.id ORDER BY occurred_at DESC LIMIT 1) as last_message,
183
- (SELECT title FROM crm_tasks WHERE contact_id = c.id AND status = 'open' ORDER BY due_at ASC LIMIT 1) as next_task
184
- FROM crm_contacts c WHERE c.id = ?
185
-
186
- // 2. Read agent_context + agent_instructions
187
- // 3. Pick best template
188
- SELECT * FROM crm_templates
189
- WHERE type = 'dm'
190
- AND (platform = ? OR platform IS NULL)
191
- ORDER BY reply_rate_pct DESC LIMIT 3
192
-
193
- // 4. Generate DM filling {{first_name}} {{company}} {{pain_point}} variables
194
-
195
- // 5. Save draft + log activity
196
- UPDATE crm_contacts SET
197
- suggested_dm = ?,
198
- outreach_status = 'dm_drafted',
199
- updated_at = strftime('%s','now')
200
- WHERE id = ?
201
-
202
- INSERT INTO crm_activities (
203
- id, profile_id, contact_id,
204
- type, direction, sender,
205
- body, metadata, searchable_context,
206
- approval_status, approval_requested_at
207
- ) VALUES (
208
- ?, ?, ?,
209
- 'dm', 'outbound', 'agent',
210
- ?, '{"platform":"twitter"}', ?,
211
- 'pending_approval', strftime('%s','now')
212
- )
213
- // trigger fires → total_pending_approvals + 1
214
- ```
215
-
216
- ### Approve a DM (you)
217
-
218
- ```ts
219
- UPDATE crm_activities SET
220
- approval_status = 'approved',
221
- approved_at = strftime('%s','now')
222
- WHERE id = ?
223
- // trigger fires → total_pending_approvals - 1, total_approved + 1
224
-
225
- UPDATE crm_contacts SET
226
- dm_sent = 1,
227
- dm_sent_at = strftime('%s','now'),
228
- outreach_status = 'dm_sent',
229
- last_contacted_at = strftime('%s','now'),
230
- last_activity_at = strftime('%s','now'),
231
- updated_at = strftime('%s','now')
232
- WHERE id = ?
233
- ```
234
-
235
- ### Reject a DM (you)
236
-
237
- ```ts
238
- UPDATE crm_activities SET
239
- approval_status = 'rejected'
240
- WHERE id = ?
241
- // trigger fires → total_pending_approvals - 1, total_rejected + 1
242
- ```
243
-
244
- ### Auto-approve mode (contact level)
245
-
246
- ```ts
247
- // Enable for a contact (agent sends without asking)
248
- UPDATE crm_contacts SET auto_approve = 1 WHERE id = ?
249
-
250
- // When auto_approve = 1, use approval_status = 'auto_sent' instead of 'pending_approval'
251
- // trigger fires → total_agent_actions + 1, but NOT total_pending_approvals
252
- ```
253
-
254
- ### Log a reply (contact replied)
255
-
256
- ```ts
257
- INSERT INTO crm_activities (
258
- id, profile_id, contact_id,
259
- type, direction, sender,
260
- body, metadata, searchable_context,
261
- approval_status
262
- ) VALUES (
263
- ?, ?, ?,
264
- 'dm', 'inbound', 'contact',
265
- ?, '{"platform":"twitter"}', ?,
266
- 'auto_sent'
267
- )
268
- // trigger fires → total_replies + 1
269
-
270
- UPDATE crm_contacts SET
271
- outreach_status = 'replied',
272
- reply_sentiment = ?, -- 'positive'|'neutral'|'negative'
273
- last_reply_at = strftime('%s','now'),
274
- last_reply_channel = 'dm',
275
- last_activity_at = strftime('%s','now'),
276
- conversation_thread = json_patch(conversation_thread, ?),
277
- updated_at = strftime('%s','now')
278
- WHERE id = ?
279
- ```
280
-
281
- ### Pause agent for a contact
282
-
283
- ```ts
284
- UPDATE crm_contacts SET
285
- agent_paused = 1,
286
- agent_paused_until = strftime('%s','now','+7 days'), -- NULL = forever
287
- updated_at = strftime('%s','now')
288
- WHERE id = ?
289
- ```
290
-
291
- ---
292
-
293
- ## Deals
294
-
295
- ### Create a deal
296
-
297
- ```ts
298
- INSERT INTO crm_deals (id, profile_id, contact_id, title, value_cents, stage, probability)
299
- VALUES (?, ?, ?, ?, ?, 'proposal', 70)
300
- // trigger fires → total_deals+1, open_deals+1, total_deal_value_cents + value
301
- ```
302
-
303
- ### Move deal stage
304
-
305
- ```ts
306
- UPDATE crm_deals SET
307
- stage = 'won', -- trigger fires → won_deals+1, open_deals-1
308
- closed_at = strftime('%s','now'),
309
- updated_at = strftime('%s','now')
310
- WHERE id = ?
311
- ```
312
-
313
- ### Update deal for forecast
314
-
315
- ```ts
316
- UPDATE crm_deals SET
317
- probability = 85, -- trigger fires → forecast recalculated
318
- expected_close_at = ?,
319
- value_cents = ?,
320
- updated_at = strftime('%s','now')
321
- WHERE id = ?
322
- ```
323
-
324
- ### Show pipeline
325
-
326
- ```ts
327
- SELECT d.*, c.first_name, c.last_name, c.company, c.avatar_url
328
- FROM crm_deals d
329
- JOIN crm_contacts c ON c.id = d.contact_id
330
- WHERE d.profile_id = ?
331
- AND d.stage NOT IN ('won','lost')
332
- ORDER BY d.value_cents DESC
333
- ```
334
-
335
- ---
336
-
337
- ## Tasks
338
-
339
- ### Create a follow-up task
340
-
341
- ```ts
342
- INSERT INTO crm_tasks (id, profile_id, contact_id, deal_id, title, due_at, priority)
343
- VALUES (?, ?, ?, ?, ?, strftime('%s','now','+2 days'), 'high')
344
- ```
345
-
346
- ### Complete a task
347
-
348
- ```ts
349
- UPDATE crm_tasks SET
350
- status = 'done',
351
- completed_at = strftime('%s','now'),
352
- updated_at = strftime('%s','now')
353
- WHERE id = ?
354
- ```
355
-
356
- ### Tasks due today
357
-
358
- ```ts
359
- SELECT t.*, c.first_name, c.last_name
360
- FROM crm_tasks t
361
- JOIN crm_contacts c ON c.id = t.contact_id
362
- WHERE t.profile_id = ?
363
- AND t.status = 'open'
364
- AND t.due_at <= strftime('%s','now')
365
- ORDER BY t.priority DESC, t.due_at ASC
366
- ```
367
-
368
- ---
369
-
370
- ## Proposals
371
-
372
- ### Create a proposal
373
-
374
- ```ts
375
- // 1. Get next proposal number
376
- UPDATE settings SET proposal_sequence = proposal_sequence + 1;
377
- SELECT proposal_sequence FROM settings LIMIT 1;
378
-
379
- INSERT INTO crm_proposals (
380
- id, profile_id, contact_id, deal_id,
381
- title, body, excerpt, public_slug,
382
- status, client_name, client_email, client_company,
383
- payment_required, payment_amount_cents, payment_currency,
384
- payment_processor, cta_label, cta_url,
385
- ai_generated, next_reminder_at
386
- ) VALUES (
387
- ?, ?, ?, ?,
388
- ?, ?, ?, ?, -- slug = crypto.randomUUID().slice(0,8)
389
- 'draft', ?, ?, ?,
390
- 1, ?, 'usd',
391
- 'stripe', 'Schedule Kickoff Call', ?,
392
- 1, strftime('%s','now','+3 days')
393
- )
394
- ```
395
-
396
- ### Send a proposal
397
-
398
- ```ts
399
- UPDATE crm_proposals SET
400
- status = 'sent',
401
- sent_at = strftime('%s','now'),
402
- payment_url = ?, -- Stripe/Paddle checkout URL
403
- payment_url_expires_at = strftime('%s','now','+24 hours'),
404
- updated_at = strftime('%s','now')
405
- WHERE id = ?
406
-
407
- // Log activity
408
- INSERT INTO crm_activities (id, profile_id, contact_id, type, direction, sender, subject, body, metadata, approval_status)
409
- VALUES (?, ?, ?, 'email', 'outbound', 'agent', 'Proposal sent', ?, '{"proposal_id":"?"}', 'auto_sent')
410
- ```
411
-
412
- ### Show proposals
413
-
414
- ```ts
415
- "Show all sent proposals"
416
- → SELECT p.*, c.first_name, c.last_name FROM crm_proposals p
417
- JOIN crm_contacts c ON c.id = p.contact_id
418
- WHERE p.profile_id = ? AND p.status = 'sent'
419
- ORDER BY p.sent_at DESC
420
-
421
- "Show proposals awaiting signature"
422
- → WHERE p.status IN ('sent','viewed')
423
-
424
- "Show paid proposals"
425
- → WHERE p.status = 'paid'
426
- ```
427
-
428
- ---
429
-
430
- ## Invoices
431
-
432
- ### Create an invoice
433
-
434
- ```ts
435
- // 1. Get next invoice number
436
- UPDATE settings SET invoice_sequence = invoice_sequence + 1;
437
- SELECT invoice_sequence FROM settings LIMIT 1;
438
- // format as INV-0001 (padded to 4 digits)
439
-
440
- INSERT INTO crm_invoices (
441
- id, profile_id, contact_id, deal_id, proposal_id,
442
- invoice_number, public_slug, status,
443
- client_name, client_email, client_company,
444
- line_items, subtotal_cents, total_cents, currency,
445
- issued_at, due_at, next_reminder_at, memo
446
- ) VALUES (
447
- ?, ?, ?, ?, ?,
448
- ?, ?, 'draft',
449
- ?, ?, ?,
450
- ?, ?, ?, 'usd',
451
- strftime('%s','now'), strftime('%s','now','+30 days'),
452
- strftime('%s','now','+3 days'), ?
453
- )
454
- ```
455
-
456
- ---
457
-
458
- ## Groups
459
-
460
- ### Create a group
461
-
462
- ```ts
463
- INSERT INTO crm_groups (id, profile_id, name, icon, color)
464
- VALUES (?, ?, 'Investors', '🤑', '#22c55e')
465
- ```
466
-
467
- ### Add contact to group
468
-
469
- ```ts
470
- // Read existing groups
471
- SELECT groups FROM crm_contacts WHERE id = ?
472
- // Append group ID to JSON array
473
- UPDATE crm_contacts SET
474
- groups = json_insert(groups, '$[#]', 'grp_005'),
475
- updated_at = strftime('%s','now')
476
- WHERE id = ?
477
-
478
- // Increment group counter
479
- UPDATE crm_groups SET contact_count = contact_count + 1 WHERE id = 'grp_005'
480
- ```
481
-
482
- ### List contacts in group
483
-
484
- ```ts
485
- SELECT * FROM crm_contacts
486
- WHERE profile_id = ?
487
- AND groups LIKE '%grp_005%'
488
- AND archived = 0
489
- ORDER BY lead_score DESC
490
- ```
491
-
492
- ---
493
-
494
- ## Analytics
495
-
496
- ### Read analytics (instant — always current)
497
-
498
- ```ts
499
- SELECT * FROM crm_analytics WHERE profile_id = ? LIMIT 1
500
- ```
501
-
502
- Returns:
503
-
504
- - `total_contacts`, `total_leads`, `total_customers` — contact funnel
505
- - `open_deals`, `won_deals`, `total_deal_value_cents` — deal pipeline
506
- - `forecast_this_month_cents`, `forecast_next_month_cents` — weighted forecast
507
- - `total_agent_actions`, `total_pending_approvals` — agent metrics
508
- - `total_replies`, `reply_rate_pct` — outreach performance
509
-
510
- ### Drift recovery (if analytics look wrong)
511
-
512
- ```ts
513
- // Run CRM_ANALYTICS_RESYNC_SQL from crm.ts
514
- // Or POST /api/crm/resync
515
- ```
516
-
517
- ---
518
-
519
- ## Context API (Sondex equivalent)
520
-
521
- Before every agent action on a contact, pull full context in one query:
522
-
523
- ```ts
524
- const [contact, activities, tasks, deals] = await Promise.all([
525
- db.execute({ sql: `SELECT * FROM crm_contacts WHERE id = ?`, args: [contactId] }),
526
- db.execute({
527
- sql: `SELECT type, sender, direction, body, subject, occurred_at, searchable_context
528
- FROM crm_activities WHERE contact_id = ?
529
- ORDER BY occurred_at DESC LIMIT 20`,
530
- args: [contactId]
531
- }),
532
- db.execute({
533
- sql: `SELECT title, due_at, priority FROM crm_tasks
534
- WHERE contact_id = ? AND status = 'open'
535
- ORDER BY due_at ASC LIMIT 5`,
536
- args: [contactId]
537
- }),
538
- db.execute({
539
- sql: `SELECT title, stage, value_cents, probability FROM crm_deals
540
- WHERE contact_id = ? AND stage NOT IN ('won','lost')`,
541
- args: [contactId]
542
- })
543
- ])
544
-
545
- // Build context for LLM
546
- const context = {
547
- contact: contact.rows[0],
548
- recent_activities: activities.rows,
549
- open_tasks: tasks.rows,
550
- open_deals: deals.rows,
551
- agent_context: JSON.parse(contact.rows[0].agent_context || '{}'),
552
- agent_instructions: contact.rows[0].agent_instructions,
553
- auto_approve: contact.rows[0].auto_approve
554
- }
555
- ```
556
-
557
- ---
558
-
559
- ## Agent Rules
560
-
561
- 1. **Always check `agent_paused`** before acting on a contact
562
- 2. **Always check `agent_instructions`** for per-contact overrides
563
- 3. **Always read context** before drafting (last 20 activities via `searchable_context`)
564
- 4. **Always set `sender` + `direction`** on activity insert (triggers depend on these)
565
- 5. **Always set `status`** on contact insert (trigger branches on this)
566
- 6. **Always update `last_activity_at`** on contact after activity insert
567
- 7. **Use `pending_approval`** unless `contact.auto_approve = 1`
568
- 8. **Use `auto_sent`** when `contact.auto_approve = 1` or you manually triggered it
569
- 9. **Never edit `crm_activities`** — append only, insert new rows
570
- 10. **Use `searchable_context`** for plain text summaries — avoids JSON parse on every query
571
-
572
- ---
573
-
574
- ## Connecting CRM to other tables
575
-
576
- ```ts
577
- // Contact → Purchases (by email)
578
- SELECT * FROM purchases WHERE email = ? ORDER BY created_at DESC
579
-
580
- // Contact → Subscribers (by email)
581
- SELECT * FROM subscribers WHERE email = ?
582
-
583
- // Contact → Form submissions (by email match)
584
- SELECT * FROM submissions WHERE answers LIKE '%' || ? || '%' LIMIT 10
585
-
586
- // Contact → Community member (by user_id)
587
- SELECT * FROM community_members WHERE user_id = ?
588
-
589
- // All cross-table joins use email or user_id as the bridge
590
- // user_id is identical in Central DB and UserDB (same ID, generated once)
591
- ```
@@ -1,50 +0,0 @@
1
- # /deep — Deep Mode
2
-
3
- Activates multi-step autonomous planning. CEO takes control and delegates to the full agent team.
4
-
5
- ## What happens
6
-
7
- 1. Load Turso session memory via `readProgress()` / `sessionContext()` from `lib/memory.ts` — last 20 actions in `memory_log`
8
- 2. CEO calls `analyticsAgent.snapshot()` — get current state of the business
9
- 3. CEO writes a structured todo plan based on: recent memory + analytics gaps + user's request
10
- 4. Execute each todo by delegating to the right agent:
11
- - Content → Blog Writer, Newsletter Writer, Course Creator, Store Manager
12
- - Distribution → Social Agent, Newsletter Writer
13
- - Intelligence → Analytics Agent, SEO Agent
14
- - Pipeline → COO (publish queue), Scheduler
15
- 5. After each completed action: `logAction(description)` or `logMemory(agent, action, metadata)` — writes to `memory_log` in Turso
16
- 6. At end of session: `setOpenItems([...])` — also stored in `memory_log` (via compatibility helpers)
17
-
18
- ## Todo format
19
-
20
- ```
21
- [ ] Read analytics + progress summary (CEO)
22
- [ ] Fix 3 posts missing SEO excerpts (SEO Agent)
23
- [ ] Draft blog post: "Email Marketing Tips" (Blog Writer)
24
- [ ] Audit all live products for copy quality (Copywriter)
25
- [ ] Schedule drafted post for Monday 9am (COO)
26
- [ ] Post product launch to LinkedIn + X (Social Agent)
27
- ```
28
-
29
- ## Delegation pattern
30
-
31
- CEO delegates to sub-agents with focused context — not the full history.
32
- Each sub-agent gets: the task description + just what it needs (brand context, relevant data).
33
- Results come back to CEO, logged to `memory_log`, todo marked complete.
34
-
35
- ## Ask user when
36
-
37
- - Approval needed before publishing or sending
38
- - Ambiguous brief ("write a post about our product" — which product?)
39
- - Price or schedule decision needed
40
- - Something unexpected found in analytics
41
-
42
- ## Harness mode
43
-
44
- For structured workflows (publish post, launch product, send newsletter) activate the harness:
45
-
46
- - `/blog-writer publish` → enforced 7-phase publish harness
47
- - `/store-manager launch` → enforced 7-phase launch harness
48
- - `/newsletter-writer send` → enforced 5-phase send harness
49
-
50
- See PRD-Agent-Harness.md for full harness architecture.
@@ -1,8 +0,0 @@
1
- # /docs-writer — Write Docs Article
2
-
3
- 1. `doc.listCollections()` → pick existing or create new collection
4
- 2. Ask: article title, body content or topic, publish now or draft?
5
- 3. Write 400+ words. Include step-by-step where relevant. Use headings.
6
- 4. `doc.createArticle({ collection_id, title, body, excerpt, publish })`
7
-
8
- New collection: `doc.createCollection({ slug, title, description, icon })`
@@ -1,10 +0,0 @@
1
- # /forms-builder — Build Form
2
-
3
- 1. Ask: what is this form for? (contact, survey, waitlist, application, quiz)
4
- 2. Ask: how many questions? Walk through each:
5
- - type: text | email | select | multiselect | rating | date | file | url
6
- - title, required (y/n), options (if select/multiselect)
7
- 3. Ask: custom thank-you message?
8
- 4. `felix.create({ title, questions, thank_you, publish })`
9
-
10
- Submissions: `felix.submissions(formId)` | Stats: in `form_analytics` table
@@ -1,8 +0,0 @@
1
- # /jobs-manager — Post Job Listing
2
-
3
- 1. Ask: title, company, location, location_type (remote/onsite/hybrid), employment_type
4
- 2. Ask: description (required), requirements, salary range (optional), expires_at
5
- 3. `job.create({ title, company, location, location_type, employment_type, description, ... })`
6
- 4. Confirm: title, slug, company, status.
7
-
8
- Applicants: `job.applications(jobId)` | Archive: `job.archive(id)`