Skip to content

Commit 6b532e6

Browse files
committed
chore: merge main into release for new releases
2 parents 1333d69 + 9d36203 commit 6b532e6

File tree

152 files changed

+4996
-1358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+4996
-1358
lines changed

.cursor/rules/design-system.mdc

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
description:
3-
globs: *.tsx
2+
description: Any time we are going to write react components and / or layouts
43
alwaysApply: false
54
---
65

@@ -28,10 +27,77 @@ Design System & Component Guidelines
2827

2928
## Layout & Spacing
3029

30+
- **Flexbox-First**: ALWAYS prefer flexbox with `gap` over hardcoded margins (`mt-`, `mb-`, `ml-`, `mr-`)
31+
- **Use Gaps, Not Margins**: Use `gap-2`, `gap-4`, `space-y-4` for spacing between elements
3132
- **Consistent Spacing**: Use standard Tailwind spacing scale (`space-y-4`, `gap-6`, etc.)
3233
- **Card-Based Layouts**: Prefer Card components for content organization
3334
- **Minimal Padding**: Use conservative padding - `p-3`, `p-4` rather than larger values
3435
- **Clean Separators**: Use subtle borders (`border-t`, `border-muted`) instead of heavy dividers
36+
- **NEVER Hardcode Margins**: Avoid `mt-4`, `mb-2`, `ml-3` unless absolutely necessary for exceptions
37+
38+
## Color & Visual Elements
39+
40+
- **Status Colors**:
41+
- Green for completed/success states
42+
- Blue for in-progress/info states
43+
- Yellow for warnings
44+
- Red for errors/destructive actions
45+
- **Subtle Indicators**: Use small colored dots (`w-2 h-2 rounded-full`) instead of large icons for status
46+
- **Minimal Shadows**: Prefer `hover:shadow-sm` over heavy shadow effects
47+
- **Progress Bars**: Keep thin (`h-1`, `h-2`) for minimal visual weight
48+
49+
## Interactive Elements
50+
51+
- **Subtle Hover States**: Use gentle transitions (`transition-shadow`, `hover:shadow-sm`)
52+
- **Consistent Button Sizing**: Prefer `size="sm"` for most buttons, `size="icon"` for icon-only
53+
- **Badge Usage**: Keep badges minimal with essential info only (percentages, short status)
54+
55+
## Data Display
56+
57+
- **Shared Design Language**: Ensure related components (cards, overviews, details) use consistent patterns
58+
- **Minimal Stats**: Present data cleanly without excessive decoration
59+
- **Contextual Icons**: Use small, relevant icons (`h-3 w-3`, `h-4 w-4`) sparingly for context
60+
61+
## Anti-Patterns to Avoid
62+
63+
- Large text sizes (`text-2xl+` except for main headings)
64+
- Heavy shadows or borders
65+
- Excessive use of colored backgrounds
66+
- Redundant badges or status indicators
67+
- Complex custom styling overrides
68+
- Non-semantic color usage (hardcoded hex values)
69+
- Cluttered layouts with too many visual elements
70+
Rule Name: design-system
71+
Description:
72+
Design System & Component Guidelines
73+
74+
## Design Philosophy
75+
76+
- **B2B, Modern, Flat, Minimal, Elegant**: All UI should follow a clean, professional aesthetic suitable for business applications
77+
- **Sleek & Minimal**: Avoid visual clutter, use whitespace effectively, keep interfaces clean
78+
- **Dark Mode First**: Always ensure components work seamlessly in both light and dark modes
79+
80+
## Component Usage
81+
82+
- **Adhere to Base Components**: Minimize custom overrides and stick to shadcn/ui base components whenever possible
83+
- **Semantic Color Classes**: Use semantic classes like `text-muted-foreground`, `bg-muted/50` instead of hardcoded colors
84+
- **Dark Mode Support**: Always use dark mode variants like `bg-green-50 dark:bg-green-950/20`, `text-green-600 dark:text-green-400`
85+
86+
## Typography & Sizing
87+
88+
- **Moderate Text Sizes**: Avoid overly large text - prefer `text-base`, `text-sm`, `text-xs` over `text-xl+`
89+
- **Consistent Hierarchy**: Use `font-medium`, `font-semibold` sparingly, prefer `font-normal` with size differentiation
90+
- **Tabular Numbers**: Use `tabular-nums` class for numeric data to ensure proper alignment
91+
92+
## Layout & Spacing
93+
94+
- **Flexbox-First**: ALWAYS prefer flexbox with `gap` over hardcoded margins (`mt-`, `mb-`, `ml-`, `mr-`)
95+
- **Use Gaps, Not Margins**: Use `gap-2`, `gap-4`, `space-y-4` for spacing between elements
96+
- **Consistent Spacing**: Use standard Tailwind spacing scale (`space-y-4`, `gap-6`, etc.)
97+
- **Card-Based Layouts**: Prefer Card components for content organization
98+
- **Minimal Padding**: Use conservative padding - `p-3`, `p-4` rather than larger values
99+
- **Clean Separators**: Use subtle borders (`border-t`, `border-muted`) instead of heavy dividers
100+
- **NEVER Hardcode Margins**: Avoid `mt-4`, `mb-2`, `ml-3` unless absolutely necessary for exceptions
35101

36102
## Color & Visual Elements
37103

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Enterprise API - Automation Versioning Endpoints
2+
3+
## Overview
4+
5+
Implement versioning for automation scripts. The Next.js app handles database operations (storing version metadata), while the Enterprise API handles S3 operations (copying/managing script files) and Redis operations (chat history).
6+
7+
## Context
8+
9+
### Current S3 Structure
10+
11+
- **Draft script**: `{orgId}/{taskId}/{automationId}.automation.js`
12+
- Scripts are stored in S3 via the enterprise API
13+
14+
### New S3 Structure for Versions
15+
16+
- **Draft script**: `{orgId}/{taskId}/{automationId}.draft.js`
17+
- **Published versions**: `{orgId}/{taskId}/{automationId}.v{version}.js`
18+
19+
**Migration Note**: Existing scripts at `{automationId}.automation.js` should be moved to `{automationId}.draft.js`
20+
21+
### Database (handled by Next.js app)
22+
23+
- `EvidenceAutomationVersion` table stores version metadata
24+
- Next.js app creates version records after enterprise API copies files
25+
26+
## Endpoints to Implement
27+
28+
### 1. Publish Draft Script
29+
30+
**Endpoint**: `POST /api/tasks-automations/publish`
31+
32+
**Purpose**: Create a new version by copying current draft script to a versioned S3 key.
33+
34+
**Request Body**:
35+
36+
```typescript
37+
{
38+
orgId: string;
39+
taskId: string;
40+
automationId: string;
41+
}
42+
```
43+
44+
**Process**:
45+
46+
1. Construct draft S3 key: `{orgId}/{taskId}/{automationId}.draft.js`
47+
2. Check if draft script exists in S3
48+
3. If not found, return error: `{ success: false, error: 'No draft script found to publish' }`
49+
4. Query database to get the next version number:
50+
- Find highest existing version for this `automationId`
51+
- Increment by 1 (or start at 1 if no versions exist)
52+
5. Construct version S3 key: `{orgId}/{taskId}/{automationId}.v{nextVersion}.js`
53+
6. Copy draft script to version key in S3
54+
7. Return success with the version number and scriptKey
55+
56+
**Response**:
57+
58+
```typescript
59+
{
60+
success: boolean;
61+
version?: number; // e.g., 1, 2, 3
62+
scriptKey?: string; // e.g., "org_xxx/tsk_xxx/aut_xxx.v1.js"
63+
error?: string;
64+
}
65+
```
66+
67+
**Note**: Enterprise API determines the version number server-side by querying the database, not from client input. This prevents version conflicts.
68+
69+
**Error Cases**:
70+
71+
- Draft script not found in S3
72+
- S3 copy operation fails
73+
- Invalid orgId/taskId/automationId
74+
75+
---
76+
77+
### 2. Restore Version to Draft
78+
79+
**Endpoint**: `POST /api/tasks-automations/restore-version`
80+
81+
**Purpose**: Replace current draft script with a published version's script. Chat history is preserved.
82+
83+
**Request Body**:
84+
85+
```typescript
86+
{
87+
orgId: string;
88+
taskId: string;
89+
automationId: string;
90+
version: number; // Which version to restore (e.g., 1, 2, 3)
91+
}
92+
```
93+
94+
**Process**:
95+
96+
1. Construct version S3 key: `{orgId}/{taskId}/{automationId}.v{version}.js`
97+
2. Check if version script exists in S3
98+
3. If not found, return error: `{ success: false, error: 'Version not found' }`
99+
4. Construct draft S3 key: `{orgId}/{taskId}/{automationId}.draft.js`
100+
5. Copy version script to draft key in S3 (overwrites current draft)
101+
6. Do NOT touch Redis chat history - it should persist
102+
7. Return success
103+
104+
**Response**:
105+
106+
```typescript
107+
{
108+
success: boolean;
109+
error?: string;
110+
}
111+
```
112+
113+
**Error Cases**:
114+
115+
- Version script not found in S3
116+
- S3 copy operation fails
117+
- Invalid version number
118+
119+
---
120+
121+
## Implementation Notes
122+
123+
### S3 Operations
124+
125+
- Use AWS S3 SDK's `copyObject` method to copy between keys
126+
- Bucket name should come from environment variables
127+
- Ensure proper error handling for S3 operations
128+
129+
### Authentication
130+
131+
- These endpoints should require authentication (API key or session)
132+
- Validate that the user has access to the organization/task/automation
133+
134+
### Redis Chat History
135+
136+
- **Important**: Do NOT clear or modify chat history when restoring versions
137+
- Chat history key format: `automation:{automationId}:chat`
138+
- Chat history persists regardless of which version is in the draft
139+
140+
### Example S3 Keys
141+
142+
For automation `aut_68e6a70803cf925eac17896a` in task `tsk_68e6a5c1e0b762e741c2e020`:
143+
144+
- **Draft**: `org_68e6a5c1d30338b3981c2104/tsk_68e6a5c1e0b762e741c2e020/aut_68e6a70803cf925eac17896a.draft.js`
145+
- **Version 1**: `org_68e6a5c1d30338b3981c2104/tsk_68e6a5c1e0b762e741c2e020/aut_68e6a70803cf925eac17896a.v1.js`
146+
- **Version 2**: `org_68e6a5c1d30338b3981c2104/tsk_68e6a5c1e0b762e741c2e020/aut_68e6a70803cf925eac17896a.v2.js`
147+
148+
### Integration Flow
149+
150+
#### Publishing a Version
151+
152+
1. User clicks "Publish" in Next.js UI with optional changelog
153+
2. Next.js calls `POST /api/tasks-automations/publish` (no version number in request)
154+
3. Enterprise API:
155+
- Queries database to get next version number
156+
- Copies draft → versioned S3 key
157+
- Returns version number and scriptKey
158+
4. Next.js saves version record to database with returned version number, scriptKey, and changelog
159+
160+
#### Restoring a Version
161+
162+
1. User clicks "Restore Version X" in Next.js UI
163+
2. Shows confirmation dialog warning current draft will be lost
164+
3. Next.js calls `POST /api/tasks-automations/restore-version`
165+
4. Enterprise API copies version script → draft S3 key
166+
5. Enterprise API returns success
167+
6. Next.js shows success message
168+
7. User can continue editing in builder with restored script
169+
170+
### Error Handling
171+
172+
- Return proper HTTP status codes (404 for not found, 400 for bad request, 500 for S3 errors)
173+
- Include descriptive error messages in response body
174+
- Log errors for debugging
175+
176+
### Testing Checklist
177+
178+
- [ ] Can publish a draft script as version 1
179+
- [ ] Can publish multiple versions (1, 2, 3...)
180+
- [ ] Cannot publish if no draft exists
181+
- [ ] Can restore version 1 to draft
182+
- [ ] Restoring doesn't affect chat history
183+
- [ ] S3 keys follow correct naming convention
184+
- [ ] Proper error messages when scripts don't exist

apps/api/Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
# Use Node.js runtime for production
22
FROM node:20-alpine
33

4-
# Install wget for health check
5-
RUN apk add --no-cache wget
4+
# Install required packages (wget for healthcheck, curl/bash for bun install, libc compat for prisma)
5+
RUN apk add --no-cache wget curl bash libc6-compat openssl
66

77
WORKDIR /app
88

9-
# Copy the entire pre-built bundle (no dependencies needed)
9+
# Copy manifests first and install production deps inside the image (avoid broken bun symlinks)
10+
COPY package.json ./
11+
12+
# Install bun and deps
13+
RUN curl -fsSL https://bun.sh/install | bash \
14+
&& export PATH="/root/.bun/bin:$PATH" \
15+
&& bun install --production --ignore-scripts
16+
17+
# Now copy the pre-built app contents (dist/, prisma/, etc.)
1018
COPY . .
1119

20+
# Generate Prisma client inside the image (ensures runtime client matches installed deps)
21+
RUN npx prisma generate
22+
1223
# Set environment variables
1324
ENV NODE_ENV=production
1425
ENV PORT=3333
1526

1627
# Create a non-root user for security
17-
RUN addgroup --system nestjs && adduser --system --ingroup nestjs nestjs
18-
19-
# Change ownership to nestjs user
20-
RUN chown -R nestjs:nestjs /app
28+
RUN addgroup --system nestjs && adduser --system --ingroup nestjs nestjs \
29+
&& chown -R nestjs:nestjs /app
2130

2231
USER nestjs
2332

apps/api/buildspec.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ phases:
2929

3030
# Install only API workspace dependencies
3131
- echo "Installing API dependencies only..."
32-
- bun install --filter=@comp/api --frozen-lockfile
32+
- bun install --filter=@comp/api --frozen-lockfile || bun install --filter=@comp/api --ignore-scripts || bun install --ignore-scripts
3333

3434
# Build NestJS application (prebuild automatically handles Prisma)
3535
- echo "Building NestJS application..."
@@ -66,12 +66,14 @@ phases:
6666
- '[ -f "../docker-build/src/main.js" ] || { echo "❌ main.js not found in docker-build/src"; exit 1; }'
6767

6868
# Copy entire node_modules for runtime (includes @trycompai/db from npm)
69-
- echo "Bundling all runtime dependencies..."
70-
- cp -r ../../node_modules ../docker-build/
69+
- echo "Skipping host node_modules copy; Dockerfile installs prod deps inside image"
7170

7271
# Copy Dockerfile
7372
- echo "Copying Dockerfile..."
7473
- cp Dockerfile ../docker-build/
74+
- echo "Copying package manifests for image install..."
75+
- cp package.json ../docker-build/
76+
- cp ../../bun.lock ../docker-build/ || true
7577

7678
# Build Docker image
7779
- echo "Building Docker image..."

apps/api/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"version": "0.0.1",
55
"author": "",
66
"dependencies": {
7+
"@prisma/client": "^6.13.0",
8+
"prisma": "^6.13.0",
79
"@aws-sdk/client-s3": "^3.859.0",
810
"@aws-sdk/s3-request-presigner": "^3.859.0",
911
"@nestjs/common": "^11.0.1",
@@ -14,6 +16,7 @@
1416
"@trycompai/db": "^1.3.7",
1517
"archiver": "^7.0.1",
1618
"axios": "^1.12.2",
19+
"better-auth": "^1.3.27",
1720
"class-transformer": "^0.5.1",
1821
"class-validator": "^0.14.2",
1922
"jose": "^6.0.12",
@@ -70,8 +73,8 @@
7073
"private": true,
7174
"scripts": {
7275
"build": "nest build",
73-
"build:docker": "prisma generate && nest build",
74-
"db:generate": "bun run db:getschema && prisma generate",
76+
"build:docker": "bunx prisma generate && nest build",
77+
"db:generate": "bun run db:getschema && bunx prisma generate",
7578
"db:getschema": "node ../../packages/db/scripts/combine-schemas.js && cp ../../packages/db/dist/schema.prisma prisma/schema.prisma",
7679
"db:migrate": "cd ../../packages/db && bunx prisma migrate dev && cd ../../apps/api",
7780
"dev": "nest start --watch",

apps/api/src/app.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { TasksModule } from './tasks/tasks.module';
1717
import { VendorsModule } from './vendors/vendors.module';
1818
import { ContextModule } from './context/context.module';
1919

20-
2120
@Module({
2221
imports: [
2322
ConfigModule.forRoot({

0 commit comments

Comments
 (0)