stagent 0.6.3 → 0.8.0

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 (139) hide show
  1. package/README.md +21 -2
  2. package/dist/cli.js +226 -1
  3. package/docs/.coverage-gaps.json +66 -16
  4. package/docs/.last-generated +1 -1
  5. package/docs/features/dashboard-kanban.md +13 -7
  6. package/docs/features/settings.md +15 -3
  7. package/docs/features/tables.md +122 -0
  8. package/docs/index.md +3 -2
  9. package/docs/journeys/developer.md +26 -16
  10. package/docs/journeys/personal-use.md +23 -9
  11. package/docs/journeys/power-user.md +40 -14
  12. package/docs/journeys/work-use.md +43 -15
  13. package/docs/manifest.json +27 -17
  14. package/package.json +3 -1
  15. package/src/app/api/chat/entities/search/route.ts +12 -3
  16. package/src/app/api/projects/[id]/route.ts +37 -0
  17. package/src/app/api/projects/__tests__/delete-project.test.ts +12 -0
  18. package/src/app/api/snapshots/[id]/restore/route.ts +62 -0
  19. package/src/app/api/snapshots/[id]/route.ts +44 -0
  20. package/src/app/api/snapshots/route.ts +54 -0
  21. package/src/app/api/snapshots/settings/route.ts +67 -0
  22. package/src/app/api/tables/[id]/charts/[chartId]/route.ts +89 -0
  23. package/src/app/api/tables/[id]/charts/route.ts +72 -0
  24. package/src/app/api/tables/[id]/columns/route.ts +70 -0
  25. package/src/app/api/tables/[id]/export/route.ts +94 -0
  26. package/src/app/api/tables/[id]/history/route.ts +15 -0
  27. package/src/app/api/tables/[id]/import/route.ts +111 -0
  28. package/src/app/api/tables/[id]/route.ts +86 -0
  29. package/src/app/api/tables/[id]/rows/[rowId]/history/route.ts +32 -0
  30. package/src/app/api/tables/[id]/rows/[rowId]/route.ts +51 -0
  31. package/src/app/api/tables/[id]/rows/route.ts +101 -0
  32. package/src/app/api/tables/[id]/triggers/[triggerId]/route.ts +65 -0
  33. package/src/app/api/tables/[id]/triggers/route.ts +122 -0
  34. package/src/app/api/tables/route.ts +65 -0
  35. package/src/app/api/tables/templates/route.ts +92 -0
  36. package/src/app/globals.css +14 -0
  37. package/src/app/settings/page.tsx +2 -0
  38. package/src/app/tables/[id]/page.tsx +67 -0
  39. package/src/app/tables/page.tsx +21 -0
  40. package/src/app/tables/templates/page.tsx +19 -0
  41. package/src/components/book/book-reader.tsx +62 -9
  42. package/src/components/book/content-blocks.tsx +6 -1
  43. package/src/components/chat/chat-table-result.tsx +139 -0
  44. package/src/components/documents/document-browser.tsx +1 -1
  45. package/src/components/projects/project-form-sheet.tsx +3 -27
  46. package/src/components/schedules/schedule-form.tsx +5 -27
  47. package/src/components/settings/data-management-section.tsx +17 -12
  48. package/src/components/settings/database-snapshots-section.tsx +469 -0
  49. package/src/components/shared/app-sidebar.tsx +2 -0
  50. package/src/components/shared/document-picker-sheet.tsx +214 -11
  51. package/src/components/tables/table-browser.tsx +234 -0
  52. package/src/components/tables/table-cell-editor.tsx +226 -0
  53. package/src/components/tables/table-chart-builder.tsx +288 -0
  54. package/src/components/tables/table-chart-view.tsx +146 -0
  55. package/src/components/tables/table-column-header.tsx +103 -0
  56. package/src/components/tables/table-column-sheet.tsx +331 -0
  57. package/src/components/tables/table-create-sheet.tsx +240 -0
  58. package/src/components/tables/table-detail-sheet.tsx +144 -0
  59. package/src/components/tables/table-detail-tabs.tsx +278 -0
  60. package/src/components/tables/table-grid.tsx +61 -0
  61. package/src/components/tables/table-history-tab.tsx +148 -0
  62. package/src/components/tables/table-import-wizard.tsx +542 -0
  63. package/src/components/tables/table-list-table.tsx +95 -0
  64. package/src/components/tables/table-relation-combobox.tsx +217 -0
  65. package/src/components/tables/table-row-sheet.tsx +271 -0
  66. package/src/components/tables/table-spreadsheet.tsx +394 -0
  67. package/src/components/tables/table-template-gallery.tsx +162 -0
  68. package/src/components/tables/table-template-preview.tsx +219 -0
  69. package/src/components/tables/table-toolbar.tsx +79 -0
  70. package/src/components/tables/table-triggers-tab.tsx +446 -0
  71. package/src/components/tables/types.ts +6 -0
  72. package/src/components/tables/use-spreadsheet-keys.ts +171 -0
  73. package/src/components/tables/utils.ts +29 -0
  74. package/src/components/tasks/task-create-panel.tsx +5 -31
  75. package/src/components/tasks/task-edit-dialog.tsx +5 -27
  76. package/src/components/workflows/workflow-form-view.tsx +11 -35
  77. package/src/components/workflows/workflow-status-view.tsx +1 -1
  78. package/src/instrumentation.ts +3 -0
  79. package/src/lib/agents/__tests__/claude-agent.test.ts +5 -1
  80. package/src/lib/agents/claude-agent.ts +3 -1
  81. package/src/lib/agents/profiles/builtins/document-writer/SKILL.md +23 -0
  82. package/src/lib/agents/profiles/builtins/technical-writer/SKILL.md +10 -0
  83. package/src/lib/agents/profiles/builtins/technical-writer/profile.yaml +1 -1
  84. package/src/lib/agents/runtime/anthropic-direct.ts +29 -0
  85. package/src/lib/agents/runtime/openai-direct.ts +29 -0
  86. package/src/lib/book/chapter-generator.ts +81 -5
  87. package/src/lib/book/chapter-mapping.ts +58 -24
  88. package/src/lib/book/content.ts +83 -47
  89. package/src/lib/book/markdown-parser.ts +1 -1
  90. package/src/lib/book/reading-paths.ts +8 -8
  91. package/src/lib/book/types.ts +1 -1
  92. package/src/lib/book/update-detector.ts +4 -1
  93. package/src/lib/chat/stagent-tools.ts +2 -0
  94. package/src/lib/chat/tool-catalog.ts +34 -0
  95. package/src/lib/chat/tools/table-tools.ts +955 -0
  96. package/src/lib/chat/tools/workflow-tools.ts +9 -1
  97. package/src/lib/constants/table-status.ts +68 -0
  98. package/src/lib/data/__tests__/clear.test.ts +1 -1
  99. package/src/lib/data/clear.ts +45 -0
  100. package/src/lib/data/seed-data/__tests__/profiles.test.ts +28 -23
  101. package/src/lib/data/seed-data/conversations.ts +350 -42
  102. package/src/lib/data/seed-data/documents.ts +564 -591
  103. package/src/lib/data/seed-data/learned-context.ts +101 -22
  104. package/src/lib/data/seed-data/notifications.ts +344 -70
  105. package/src/lib/data/seed-data/profile-test-results.ts +92 -11
  106. package/src/lib/data/seed-data/profiles.ts +144 -46
  107. package/src/lib/data/seed-data/projects.ts +50 -18
  108. package/src/lib/data/seed-data/repo-imports.ts +28 -13
  109. package/src/lib/data/seed-data/schedules.ts +208 -41
  110. package/src/lib/data/seed-data/table-templates.ts +234 -0
  111. package/src/lib/data/seed-data/tasks.ts +614 -116
  112. package/src/lib/data/seed-data/usage-ledger.ts +182 -103
  113. package/src/lib/data/seed-data/user-tables.ts +203 -0
  114. package/src/lib/data/seed-data/views.ts +52 -7
  115. package/src/lib/data/seed-data/workflows.ts +231 -84
  116. package/src/lib/data/seed.ts +55 -14
  117. package/src/lib/data/tables.ts +417 -0
  118. package/src/lib/db/bootstrap.ts +227 -0
  119. package/src/lib/db/index.ts +9 -0
  120. package/src/lib/db/migrations/0019_add_tables_feature.sql +160 -0
  121. package/src/lib/db/migrations/0020_add_table_triggers.sql +19 -0
  122. package/src/lib/db/migrations/0021_add_row_history.sql +15 -0
  123. package/src/lib/db/schema.ts +368 -0
  124. package/src/lib/snapshots/auto-backup.ts +132 -0
  125. package/src/lib/snapshots/retention.ts +64 -0
  126. package/src/lib/snapshots/snapshot-manager.ts +429 -0
  127. package/src/lib/tables/computed.ts +61 -0
  128. package/src/lib/tables/context-builder.ts +139 -0
  129. package/src/lib/tables/formula-engine.ts +415 -0
  130. package/src/lib/tables/history.ts +115 -0
  131. package/src/lib/tables/import.ts +343 -0
  132. package/src/lib/tables/query-builder.ts +152 -0
  133. package/src/lib/tables/trigger-evaluator.ts +146 -0
  134. package/src/lib/tables/types.ts +141 -0
  135. package/src/lib/tables/validation.ts +119 -0
  136. package/src/lib/utils/stagent-paths.ts +20 -0
  137. package/src/lib/workflows/types.ts +1 -1
  138. package/tsconfig.json +3 -1
  139. /package/docs/features/{playbook.md → user-guide.md} +0 -0
@@ -5,7 +5,7 @@ export interface WorkflowSeed {
5
5
  projectId: string;
6
6
  name: string;
7
7
  definition: string;
8
- status: "draft" | "active" | "paused" | "completed";
8
+ status: "draft" | "active" | "paused" | "completed" | "failed";
9
9
  createdAt: Date;
10
10
  updatedAt: Date;
11
11
  }
@@ -13,152 +13,272 @@ export interface WorkflowSeed {
13
13
  export function createWorkflows(projectIds: string[]): WorkflowSeed[] {
14
14
  const now = Date.now();
15
15
  const DAY = 86_400_000;
16
- const [p1, p2, p3, p4, p5] = projectIds;
16
+ const [p1, p2, p3, p4, p5, p6, p7, p8] = projectIds;
17
17
 
18
- const portfolioRebalance: WorkflowDefinition = {
18
+ // P1: Product Launch Pipeline
19
+ const launchPipeline: WorkflowDefinition = {
20
+ pattern: "checkpoint",
21
+ steps: [
22
+ {
23
+ id: "research",
24
+ name: "Competitive & audience research",
25
+ prompt:
26
+ "Analyze 5 competing AI copilot products (Cursor, Windsurf, Cody, Tabnine, Copilot). Document positioning, pricing, feature gaps, and messaging angles we can own. Output a competitive matrix.",
27
+ },
28
+ {
29
+ id: "copy",
30
+ name: "Write launch copy variants",
31
+ prompt:
32
+ "Using competitive insights, write 3 hero headline variants, email subject lines for the 3-touch launch sequence, and a 280-char social post per channel (LinkedIn, Twitter). Follow the brand voice guide.",
33
+ requiresApproval: true,
34
+ },
35
+ {
36
+ id: "build",
37
+ name: "Build launch landing page",
38
+ prompt:
39
+ "Implement the approved hero section and feature grid as responsive React components using Tailwind CSS. Include OG meta tags, structured data, and conversion tracking pixels.",
40
+ requiresApproval: true,
41
+ },
42
+ {
43
+ id: "test",
44
+ name: "Configure A/B tests",
45
+ prompt:
46
+ "Set up A/B test for the top 2 hero variants. Configure event tracking for CTA clicks, scroll depth, time on page, and email signup conversion. Define a 7-day test window with 95% confidence threshold.",
47
+ },
48
+ ],
49
+ };
50
+
51
+ // P2: Weekly Content Cycle
52
+ const contentCycle: WorkflowDefinition = {
19
53
  pattern: "sequence",
20
54
  steps: [
21
55
  {
22
- id: "analyze",
23
- name: "Analyze current allocation",
56
+ id: "research",
57
+ name: "Keyword & topic research",
58
+ prompt:
59
+ "Pull this week's target keyword cluster from the editorial calendar. Research search volume, competition score, and top-ranking content. Identify 3 content gaps we can fill.",
60
+ },
61
+ {
62
+ id: "outline",
63
+ name: "Create article outline",
64
+ prompt:
65
+ "Build a structured outline: H1, 5-7 H2 sections, target 1,800 words, 3 internal link opportunities, and a CTA placement plan. Include the primary and 2 secondary keywords.",
66
+ },
67
+ {
68
+ id: "draft",
69
+ name: "Write first draft",
24
70
  prompt:
25
- "Read the portfolio holdings CSV and calculate current sector weights, position sizes, and concentration risks. Output a summary table.",
71
+ "Write the full article following the approved outline. Use clear topic sentences, include 2-3 data points per section, and end with a compelling CTA. Maintain a Flesch-Kincaid score under 45.",
26
72
  },
27
73
  {
28
- id: "compare",
29
- name: "Compare to target allocation",
74
+ id: "edit",
75
+ name: "Editorial review & polish",
30
76
  prompt:
31
- "Compare current allocation against the target: Tech ≤35%, Healthcare 15-20%, Finance 15-20%, Consumer 10-15%, Energy 5-10%, Cash 5%. Identify overweight and underweight sectors.",
77
+ "Review the draft for factual accuracy, brand voice consistency, SEO optimization (keyword density 1-2%), and readability. Fix any issues and prepare the final version with meta description and alt text.",
32
78
  },
33
79
  {
34
- id: "recommend",
35
- name: "Generate trade recommendations",
80
+ id: "distribute",
81
+ name: "Prepare distribution assets",
36
82
  prompt:
37
- "Based on the allocation gaps, recommend specific trades (buy/sell/trim) to rebalance. Minimize transaction count and tax impact. Output as a trade list.",
83
+ "Create a LinkedIn post (hook + 3 key takeaways), a newsletter intro paragraph, and a Twitter thread (5 tweets). Schedule all pieces in the content calendar.",
38
84
  },
39
85
  ],
40
86
  };
41
87
 
42
- const landingPageBuild: WorkflowDefinition = {
88
+ // P3: Customer Onboarding Flow
89
+ const onboardingFlow: WorkflowDefinition = {
43
90
  pattern: "checkpoint",
44
91
  steps: [
45
92
  {
46
- id: "research",
47
- name: "Research & competitive analysis",
93
+ id: "welcome",
94
+ name: "Send welcome sequence",
48
95
  prompt:
49
- "Audit 4 competitor landing pages (Notion, Linear, Vercel, Stripe). Document design patterns, CTAs, messaging, and identify gaps we can exploit.",
96
+ "Trigger the 3-email welcome sequence: Day 0 welcome + quick start guide, Day 2 feature spotlight, Day 5 'how are things going?' check-in. Personalize with company name and plan tier.",
50
97
  },
51
98
  {
52
- id: "copy",
53
- name: "Write copy variants",
99
+ id: "setup",
100
+ name: "Verify account setup",
54
101
  prompt:
55
- "Using competitive insights, write 3 hero headline variants with supporting copy. Follow the design brief brand voice. Include CTA text.",
102
+ "Check that the customer has completed key setup milestones: API key configured, first project created, first agent run completed. Flag any incomplete steps.",
56
103
  requiresApproval: true,
57
104
  },
58
105
  {
59
- id: "build",
60
- name: "Build responsive hero",
106
+ id: "training",
107
+ name: "Schedule training session",
61
108
  prompt:
62
- "Implement the approved hero section as a responsive React component using Tailwind CSS. Include animations, responsive breakpoints, and dark mode.",
63
- requiresApproval: true,
109
+ "Based on the customer's plan tier and team size, recommend a training path: self-serve docs for Starter, live walkthrough for Pro, dedicated onboarding call for Team. Book the session if applicable.",
64
110
  },
65
111
  {
66
- id: "test",
67
- name: "Set up A/B test",
112
+ id: "review",
113
+ name: "14-day health check",
68
114
  prompt:
69
- "Configure A/B test infrastructure for the top 2 hero variants. Set up event tracking for CTA clicks, scroll depth, and time on page.",
115
+ "At day 14, assess: login frequency, feature adoption depth, support tickets filed. Score as green/yellow/red and recommend next touchpoint. Escalate red accounts to CS manager.",
116
+ requiresApproval: true,
70
117
  },
71
118
  ],
72
119
  };
73
120
 
74
- const leadGenPipeline: WorkflowDefinition = {
121
+ // P4: Due Diligence Workflow
122
+ const dueDiligence: WorkflowDefinition = {
75
123
  pattern: "planner-executor",
76
124
  steps: [
77
125
  {
78
- id: "plan",
79
- name: "Plan outreach campaign",
126
+ id: "scope",
127
+ name: "Define analysis scope",
80
128
  prompt:
81
- "Given 15 qualified prospects across 8 companies, create a campaign plan: segment prospects by company size and role, assign email templates, set send schedule (stagger across 2 weeks), and define success metrics.",
129
+ "Review the investment memo and define the DD scope: financial analysis depth, market sizing approach, competitive landscape breadth, and key risk factors to investigate. Output a scoping document.",
82
130
  },
83
131
  {
84
- id: "personalize",
85
- name: "Personalize email sequences",
132
+ id: "financials",
133
+ name: "Financial deep dive",
86
134
  prompt:
87
- "For each prospect, fill in personalization tokens in the assigned template: company name, recent events (from LinkedIn/Crunchbase), team size, similar customer references. Output ready-to-send emails.",
135
+ "Analyze 3 years of financials: ARR growth, gross margins, net retention, burn rate, and runway. Model 3 scenarios (base, upside, downside) with key assumptions. Flag any accounting irregularities.",
88
136
  },
89
137
  {
90
- id: "enrich",
91
- name: "Enrich with company data",
138
+ id: "market",
139
+ name: "Market & TAM analysis",
92
140
  prompt:
93
- "For each prospect company, pull: funding stage, employee count, tech stack (from job postings), recent news. Append to prospect records.",
141
+ "Size the total addressable market using top-down and bottom-up approaches. Map the competitive landscape with positioning matrix. Identify market tailwinds and headwinds.",
94
142
  },
95
143
  {
96
- id: "schedule",
97
- name: "Schedule and send",
144
+ id: "competitive",
145
+ name: "Competitive positioning",
98
146
  prompt:
99
- "Schedule all personalized emails according to the campaign plan. Send Day 1 emails immediately, queue follow-ups at 3-day and 7-day intervals.",
147
+ "Deep-dive into 4-5 direct competitors: product comparison, pricing analysis, customer reviews, team strength, and funding history. Identify sustainable competitive advantages.",
148
+ },
149
+ {
150
+ id: "synthesis",
151
+ name: "Write DD memo",
152
+ prompt:
153
+ "Synthesize all findings into a structured DD memo: executive summary, investment thesis, financial highlights, market opportunity, competitive position, top risks with mitigants, and go/no-go recommendation.",
100
154
  },
101
155
  ],
102
156
  };
103
157
 
104
- const tripPlanning: WorkflowDefinition = {
158
+ // P5: Product Listing Optimizer
159
+ const listingOptimizer: WorkflowDefinition = {
105
160
  pattern: "sequence",
106
161
  steps: [
107
162
  {
108
- id: "flights",
109
- name: "Book flights",
163
+ id: "scrape",
164
+ name: "Scrape current listings",
110
165
  prompt:
111
- "Search for round-trip flights SFO→JFK departing March 15 AM, returning March 18 PM. Prefer United (status match). Budget: $700 max. Book Economy Plus with aisle seats.",
166
+ "Pull the current product listings for the top 20 SKUs by revenue. Capture title, description, bullet points, images count, price, and review score. Store as structured data.",
112
167
  },
113
168
  {
114
- id: "hotel",
115
- name: "Reserve hotel",
169
+ id: "analyze",
170
+ name: "Analyze listing performance",
116
171
  prompt:
117
- "Book hotel in Midtown Manhattan for 3 nights (Mar 15-18). Requirements: walking distance to Javits Center, standard king room, free cancellation. Budget: $300/night max.",
172
+ "Compare listing quality against top 3 competitors per SKU. Score each listing on: keyword coverage (title + bullets), image count, review volume, and A+ content presence. Rank by optimization opportunity.",
118
173
  },
119
174
  {
120
- id: "itinerary",
121
- name: "Create itinerary",
175
+ id: "rewrite",
176
+ name: "Generate optimized copy",
122
177
  prompt:
123
- "Build a day-by-day schedule combining: conference sessions, 3 client meetings (Acme Corp 350 5th Ave, DataFlow AI 85 Broad St, ScaleUp HQ 28 W 23rd St), team dinner, and ground transport estimates.",
178
+ "For the top 10 opportunity SKUs, rewrite titles (under 200 chars), 5 bullet points (keyword-rich), and product descriptions. Maintain brand voice while improving keyword density. A/B test the top 3.",
124
179
  },
125
180
  {
126
- id: "expenses",
127
- name: "Submit expense pre-approval",
181
+ id: "deploy",
182
+ name: "Stage updates for review",
128
183
  prompt:
129
- "Compile all costs (flights, hotel, per diem meals at $75/day, estimated ground transport $200, misc $100) into an expense pre-approval form. Submit for manager approval.",
184
+ "Prepare a change log with before/after for each listing update. Stage the changes in the CMS draft queue and notify the client for approval before going live.",
130
185
  },
131
186
  ],
132
187
  };
133
188
 
134
- const taxPrepWorkflow: WorkflowDefinition = {
189
+ // P6: HIPAA Content Review
190
+ const hipaaReview: WorkflowDefinition = {
135
191
  pattern: "checkpoint",
136
192
  steps: [
137
193
  {
138
- id: "gather",
139
- name: "Gather tax documents",
194
+ id: "draft",
195
+ name: "Draft marketing content",
140
196
  prompt:
141
- "Create a checklist of all required 2025 tax documents: W-2s, 1099s (INT, DIV, B, NEC), 1098 mortgage, charitable receipts, estimated tax payment records. Track status of each.",
197
+ "Write the campaign content: referral program landing page copy, 2 email templates for provider outreach, and 3 social media posts. Follow healthcare marketing guidelines no unsubstantiated claims.",
198
+ requiresApproval: true,
142
199
  },
143
200
  {
144
- id: "categorize",
145
- name: "Categorize deductions",
201
+ id: "compliance",
202
+ name: "HIPAA compliance check",
146
203
  prompt:
147
- "Sort all expenses into IRS-recognized categories: home office (simplified vs actual method), professional development, software/tools, charitable donations, health (HSA). Calculate subtotals.",
204
+ "Scan all content for PHI references, testimonial compliance, disclaimer requirements, and FDA marketing restrictions. Flag any language that could violate HIPAA, FTC, or state healthcare marketing laws.",
148
205
  requiresApproval: true,
149
206
  },
150
207
  {
151
- id: "calculate",
152
- name: "Calculate home office deduction",
208
+ id: "legal",
209
+ name: "Legal counsel review",
153
210
  prompt:
154
- "Compare simplified method ($5/sq ft × 150 sq ft = $750) vs actual expense method (pro-rata utilities, internet, depreciation). Recommend the higher-value method with documentation requirements.",
211
+ "Prepare the legal review package: all content pieces with compliance annotations, risk flags, and recommended disclaimer language. Route to legal@medreach.health for sign-off.",
155
212
  requiresApproval: true,
156
213
  },
157
214
  {
158
- id: "package",
159
- name: "Prepare CPA package",
215
+ id: "publish",
216
+ name: "Publish approved content",
160
217
  prompt:
161
- "Compile all documents, categorized deductions, and calculations into a CPA-ready package. Include summary cover sheet with key numbers: gross income, total deductions, estimated tax liability.",
218
+ "After legal approval, schedule publication: landing page goes live immediately, emails queued for Tuesday 10am send, social posts staggered across the week. Update the compliance audit log.",
219
+ requiresApproval: true,
220
+ },
221
+ ],
222
+ };
223
+
224
+ // P7: Weekly Deal Review
225
+ const dealReview: WorkflowDefinition = {
226
+ pattern: "sequence",
227
+ steps: [
228
+ {
229
+ id: "pull",
230
+ name: "Pull pipeline data",
231
+ prompt:
232
+ "Export this week's pipeline snapshot: all deals in stages 2-5, new opportunities, stage changes, and closed-won/lost. Include deal owner, amount, close date, and days in stage.",
233
+ },
234
+ {
235
+ id: "risk",
236
+ name: "Score deal risk",
237
+ prompt:
238
+ "For each open deal, calculate a risk score based on: days in current stage (>5 = elevated), champion engagement (email opens, meeting frequency), competitive mentions, and budget confirmation status.",
239
+ },
240
+ {
241
+ id: "coaching",
242
+ name: "Generate coaching notes",
243
+ prompt:
244
+ "For each rep, identify 1-2 coaching opportunities based on their deals: stalled deals needing executive sponsorship, missing next steps, or pricing objections that need a value sell approach.",
245
+ },
246
+ {
247
+ id: "summary",
248
+ name: "Write executive summary",
249
+ prompt:
250
+ "Compile the weekly operating note: pipeline created vs target, forecast by confidence bucket (committed/best-case/upside), top risks, and the 3 highest-leverage actions for leadership.",
251
+ },
252
+ ],
253
+ };
254
+
255
+ // P8: Monthly Compliance Audit
256
+ const complianceAudit: WorkflowDefinition = {
257
+ pattern: "planner-executor",
258
+ steps: [
259
+ {
260
+ id: "gather",
261
+ name: "Gather audit evidence",
262
+ prompt:
263
+ "Collect all governed execution logs, permission decisions, agent tool usage, and data access patterns for the audit period. Cross-reference against the SOC 2 control framework.",
264
+ },
265
+ {
266
+ id: "analyze",
267
+ name: "Analyze compliance gaps",
268
+ prompt:
269
+ "Compare execution logs against defined policies: tool approval rates, auto-approve bypass patterns, sensitive data access, and budget adherence. Identify gaps and rate severity (critical/high/medium/low).",
270
+ },
271
+ {
272
+ id: "report",
273
+ name: "Generate compliance report",
274
+ prompt:
275
+ "Write the monthly compliance report: executive summary, control effectiveness by category, gap analysis with remediation timelines, and trend analysis vs prior month. Include evidence references.",
276
+ },
277
+ {
278
+ id: "brief",
279
+ name: "Executive briefing",
280
+ prompt:
281
+ "Prepare a 1-page executive brief: overall compliance posture (green/yellow/red), top 3 findings, remediation progress on prior findings, and recommended policy updates.",
162
282
  },
163
283
  ],
164
284
  };
@@ -167,47 +287,74 @@ export function createWorkflows(projectIds: string[]): WorkflowSeed[] {
167
287
  {
168
288
  id: crypto.randomUUID(),
169
289
  projectId: p1,
170
- name: "Portfolio Rebalance Analysis",
171
- definition: JSON.stringify(portfolioRebalance),
172
- status: "completed",
173
- createdAt: new Date(now - 13 * DAY),
174
- updatedAt: new Date(now - 11 * DAY),
290
+ name: "Product Launch Pipeline",
291
+ definition: JSON.stringify(launchPipeline),
292
+ status: "active",
293
+ createdAt: new Date(now - 20 * DAY),
294
+ updatedAt: new Date(now - 1 * DAY),
175
295
  },
176
296
  {
177
297
  id: crypto.randomUUID(),
178
298
  projectId: p2,
179
- name: "Landing Page Build Pipeline",
180
- definition: JSON.stringify(landingPageBuild),
299
+ name: "Weekly Content Cycle",
300
+ definition: JSON.stringify(contentCycle),
181
301
  status: "active",
182
- createdAt: new Date(now - 11 * DAY),
302
+ createdAt: new Date(now - 17 * DAY),
183
303
  updatedAt: new Date(now - 1 * DAY),
184
304
  },
185
305
  {
186
306
  id: crypto.randomUUID(),
187
307
  projectId: p3,
188
- name: "Lead Generation Campaign",
189
- definition: JSON.stringify(leadGenPipeline),
190
- status: "paused",
191
- createdAt: new Date(now - 9 * DAY),
192
- updatedAt: new Date(now - 6 * DAY),
308
+ name: "Customer Onboarding Flow",
309
+ definition: JSON.stringify(onboardingFlow),
310
+ status: "active",
311
+ createdAt: new Date(now - 15 * DAY),
312
+ updatedAt: new Date(now - 2 * DAY),
193
313
  },
194
314
  {
195
315
  id: crypto.randomUUID(),
196
316
  projectId: p4,
197
- name: "NYC Trip Logistics",
198
- definition: JSON.stringify(tripPlanning),
317
+ name: "Due Diligence Workflow",
318
+ definition: JSON.stringify(dueDiligence),
199
319
  status: "completed",
200
- createdAt: new Date(now - 7 * DAY),
320
+ createdAt: new Date(now - 13 * DAY),
201
321
  updatedAt: new Date(now - 3 * DAY),
202
322
  },
203
323
  {
204
324
  id: crypto.randomUUID(),
205
325
  projectId: p5,
206
- name: "Tax Filing Workflow",
207
- definition: JSON.stringify(taxPrepWorkflow),
326
+ name: "Product Listing Optimizer",
327
+ definition: JSON.stringify(listingOptimizer),
208
328
  status: "active",
209
- createdAt: new Date(now - 5 * DAY),
329
+ createdAt: new Date(now - 11 * DAY),
330
+ updatedAt: new Date(now - 2 * DAY),
331
+ },
332
+ {
333
+ id: crypto.randomUUID(),
334
+ projectId: p6,
335
+ name: "HIPAA Content Review",
336
+ definition: JSON.stringify(hipaaReview),
337
+ status: "paused",
338
+ createdAt: new Date(now - 9 * DAY),
339
+ updatedAt: new Date(now - 4 * DAY),
340
+ },
341
+ {
342
+ id: crypto.randomUUID(),
343
+ projectId: p7,
344
+ name: "Weekly Deal Review",
345
+ definition: JSON.stringify(dealReview),
346
+ status: "draft",
347
+ createdAt: new Date(now - 7 * DAY),
210
348
  updatedAt: new Date(now - 1 * DAY),
211
349
  },
350
+ {
351
+ id: crypto.randomUUID(),
352
+ projectId: p8,
353
+ name: "Monthly Compliance Audit",
354
+ definition: JSON.stringify(complianceAudit),
355
+ status: "completed",
356
+ createdAt: new Date(now - 5 * DAY),
357
+ updatedAt: new Date(now - 3 * DAY),
358
+ },
212
359
  ];
213
360
  }
@@ -31,6 +31,8 @@ import { createLearnedContext } from "./seed-data/learned-context";
31
31
  import { createViews } from "./seed-data/views";
32
32
  import { createProfileTestResults } from "./seed-data/profile-test-results";
33
33
  import { createRepoImports } from "./seed-data/repo-imports";
34
+ import { createUserTables } from "./seed-data/user-tables";
35
+ import { createTable, addRows } from "@/lib/data/tables";
34
36
 
35
37
  /**
36
38
  * Clear all data, then seed with realistic sample data.
@@ -50,8 +52,22 @@ export async function seedSampleData() {
50
52
  }
51
53
  const projectIds = projectSeeds.map((p) => p.id);
52
54
 
53
- // 4. Insert tasks
54
- const taskSeeds = createTasks(projectIds);
55
+ // 4. Insert workflows BEFORE tasks (tasks reference workflowId)
56
+ const workflowSeeds = createWorkflows(projectIds);
57
+ for (const w of workflowSeeds) {
58
+ db.insert(workflows).values(w).run();
59
+ }
60
+ const workflowIds = workflowSeeds.map((w) => w.id);
61
+
62
+ // 5. Insert schedules BEFORE tasks (tasks reference scheduleId)
63
+ const scheduleSeeds = createSchedules(projectIds);
64
+ for (const schedule of scheduleSeeds) {
65
+ db.insert(schedules).values(schedule).run();
66
+ }
67
+ const scheduleIds = scheduleSeeds.map((s) => s.id);
68
+
69
+ // 6. Insert tasks (with workflow/schedule/profile references)
70
+ const taskSeeds = createTasks(projectIds, workflowIds, scheduleIds);
55
71
  for (const t of taskSeeds) {
56
72
  db.insert(tasks)
57
73
  .values({
@@ -62,6 +78,10 @@ export async function seedSampleData() {
62
78
  status: t.status,
63
79
  priority: t.priority,
64
80
  result: t.result,
81
+ agentProfile: t.agentProfile,
82
+ sourceType: t.sourceType,
83
+ workflowId: t.workflowId,
84
+ scheduleId: t.scheduleId,
65
85
  createdAt: t.createdAt,
66
86
  updatedAt: t.updatedAt,
67
87
  })
@@ -69,18 +89,6 @@ export async function seedSampleData() {
69
89
  }
70
90
  const taskIds = taskSeeds.map((t) => t.id);
71
91
 
72
- // 5. Insert workflows (one per project)
73
- const workflowSeeds = createWorkflows(projectIds);
74
- for (const w of workflowSeeds) {
75
- db.insert(workflows).values(w).run();
76
- }
77
-
78
- // 6. Insert schedules for recently added automation surfaces
79
- const scheduleSeeds = createSchedules(projectIds);
80
- for (const schedule of scheduleSeeds) {
81
- db.insert(schedules).values(schedule).run();
82
- }
83
-
84
92
  // 7. Write document files + insert records
85
93
  const docSeeds = await createDocuments(projectIds, taskIds);
86
94
  for (const d of docSeeds) {
@@ -160,6 +168,37 @@ export async function seedSampleData() {
160
168
  db.insert(repoImports).values(ri).run();
161
169
  }
162
170
 
171
+ // 17. Insert user-created tables with columns and rows
172
+ const userTableSeeds = createUserTables(projectIds);
173
+ let totalTableRows = 0;
174
+ for (const tableSeed of userTableSeeds) {
175
+ await createTable({
176
+ name: tableSeed.name,
177
+ description: tableSeed.description,
178
+ projectId: tableSeed.projectId,
179
+ source: tableSeed.source,
180
+ columns: tableSeed.columns.map((col, i) => ({
181
+ name: col.name,
182
+ displayName: col.displayName,
183
+ dataType: col.dataType,
184
+ position: i,
185
+ required: col.required ?? false,
186
+ config: col.config ?? undefined,
187
+ })),
188
+ });
189
+ // createTable generates its own ID; retrieve it by name+project
190
+ const { listTables } = await import("@/lib/data/tables");
191
+ const tables = await listTables({ projectId: tableSeed.projectId });
192
+ const created = tables.find((t) => t.name === tableSeed.name);
193
+ if (created && tableSeed.rows.length > 0) {
194
+ await addRows(
195
+ created.id,
196
+ tableSeed.rows.map((data) => ({ data }))
197
+ );
198
+ totalTableRows += tableSeed.rows.length;
199
+ }
200
+ }
201
+
163
202
  return {
164
203
  profiles: profileCount,
165
204
  projects: projectSeeds.length,
@@ -176,5 +215,7 @@ export async function seedSampleData() {
176
215
  views: viewSeeds.length,
177
216
  profileTestResults: testResultSeeds.length,
178
217
  repoImports: repoImportSeeds.length,
218
+ userTables: userTableSeeds.length,
219
+ userTableRows: totalTableRows,
179
220
  };
180
221
  }