BubbleLab / rules
Cursor rule1.1k starsChanged 10 months agoApache-2.0View on GitHub
The project uses a custom type bundling system to provide full TypeScript IntelliSense support in the Monaco editor for @bubblelab/bubble-core and its dependencies. This is necessary because Monaco cannot directly resolve workspace packages or external dependencies. The Monaco editor (in apps/bubble-studio/src/components/MonacoEditor.tsx) loads the bundle: This makes all types available when users write: Problem: Using relative paths as cache keys caused collisions: - bubble-core/dist/index.d.ts → cached as "index.d.ts" - shared-schemas/dist/index.d.ts → same key "index.d.ts" - Second file would return the first…
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about bubblelabai/BubbleLab
The biggest 1 of 1 mention linking to the repository that our crawl found. Each line is their own headline.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository7 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/api.mdcCursor rule
- .cursor/rules/bubblelab.mdcCursor rule
- .cursor/rules/code-quality.mdcCursor rule
- .cursor/rules/commit.mdcCursor rule
- commitSkill
- create-bubbleSkill
The file
We split this bundling.mdc into the rules it gives an agent
10 rules. About 0 are common, 10 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
All bubble-core types and classes
- Distinctive: line 112
Solution: Use absolute file paths as cache keys:
- Distinctive: line 122
All external imports are removed from the bundle:
- Distinctive: line 169
Check browser console for fetch errors
- Distinctive: line 170
Look for "ServiceBubble declarations found" log
- Distinctive: line 174
If types are missing after changes:
- Distinctive: line 187
Import from shared-schemas instead
- Distinctive: line 204
When adding new types to shared-schemas:
- Distinctive: line 205
No changes needed! The bundler automatically includes them
- Distinctive: line 209
When adding new files to bubble-core:
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
alwaysApply: true
---
# Type Bundling for Monaco Editor
## Overview
The project uses a custom type bundling system to provide full TypeScript IntelliSense support in the Monaco editor for `@bubblelab/bubble-core` and its dependencies. This is necessary because Monaco cannot directly resolve workspace packages or external dependencies.
## Architecture
### Key Files
- **Bundler Script**: `packages/bubble-core/scripts/bubble-bundler.ts`
- Processes TypeScript declaration files (`.d.ts`)
- Inlines all dependencies into a single self-contained bundle
- Runs as part of the build process: `tsc && tsx scripts/bubble-bundler.ts`
- **Bundle Output**: `packages/bubble-core/dist/bubble-bundle.d.ts`
- Self-contained TypeScript declarations
- Includes Zod type stubs for type inference
- Contains inlined types from `@bubblelab/shared-schemas`
- All bubble-core types and classes
- **Monaco Integration**: `apps/bubble-studio/public/bubble-types.txt`
- Copy of the bundle served to the Monaco editor
- Loaded in `apps/bubble-studio/src/components/MonacoEditor.tsx`
### Bundling Process
1. **Compile TypeScript**
```bash
tsc # Generates .d.ts files in dist/
```
2. **Bundle Types**
- Start from `packages/bubble-core/dist/index.d.ts`
- Recursively process all imports:
- Relative imports (`./types/bubble.js`) → inline the file content
- External imports (`@bubblelab/shared-schemas`) → bundle separately then inline
- Zod imports → remove (custom stubs provided)
3. **Shared Schemas Handling**
- `@bubblelab/shared-schemas` is bundled separately via `bundleSharedSchemas()`
- Prevents cache key collisions (both packages have `index.d.ts`)
- Uses **absolute file paths** as cache keys to avoid conflicts
- Inlined content includes all shared types like:
- `BubbleOperationResult`
- `BubbleResult<T>`
- `BubbleTriggerEventRegistry`
- API schemas, credential types, etc.
4. **Bundle Structure**
```typescript
// Header comment
// Zod type stubs (for z.infer, z.ZodObject, etc.)
declare namespace z { ... }
// Inlined shared-schemas types
export interface BubbleOperationResult { ... }
export interface BubbleResult<T> { ... }
// Bubble-core types and classes
export class BubbleFlow { ... }
export class ServiceBubble { ... }
```
5. **Minification**
- Removes comments (except header)
- Compresses whitespace
- Reduces bundle size by ~30%
### Monaco Editor Integration
The Monaco editor (in `apps/bubble-studio/src/components/MonacoEditor.tsx`) loads the bundle:
```typescript
// 1. Fetch the bundle
const response = await fetch('/bubble-types.txt');
const bundledTypes = await response.text();
// 2. Wrap in module declaration
const moduleDeclaration = `
declare module '@bubblelab/bubble-core' {
${cleanedTypes.replace(/^/gm, ' ')}
}
`;
// 3. Add to Monaco's type system
monaco.languages.typescript.typescriptDefaults.addExtraLib(
moduleDeclaration,
'file:///node_modules/@types/nodex__bubble-core/index.d.ts'
);
```
This makes all types available when users write:
```typescript
import { BubbleFlow, ServiceBubble } from '@bubblelab/bubble-core';
```
## Important Implementation Details
### Cache Key Strategy
**Problem**: Using relative paths as cache keys caused collisions:
- `bubble-core/dist/index.d.ts` → cached as `"index.d.ts"`
- `shared-schemas/dist/index.d.ts` → same key `"index.d.ts"`
- Second file would return the first file's cached content!
**Solution**: Use absolute file paths as cache keys:
```typescript
const cacheKey = filePath; // Full absolute path
if (this.processedFiles.has(cacheKey)) {
return this.typeDefinitions.get(cacheKey) || '';
}
```
### External Import Handling
All external imports are removed from the bundle:
```typescript
if (!importPath.startsWith('.')) {
// Remove all external imports (zod, shared-schemas, etc)
processedContent = processedContent.replace(importStatement, '');
continue;
}
```
Why?
- **Zod**: Custom type stubs are provided (Monaco-friendly simplified versions)
- **@bubblelab/shared-schemas**: Bundled separately and inlined to avoid circular processing
### Type Re-exports
When `bubble-core/src/index.ts` does:
```typescript
export * from '@bubblelab/shared-schemas';
```
The bundler:
1. Compiles to `dist/index.d.ts` with the export statement
2. Detects the external import during bundling
3. Calls `bundleSharedSchemas()` to process shared-schemas separately
4. Inlines the shared-schemas content before bubble-core content
5. Removes the `export *` statement
Result: All types are available directly in the bundle without external dependencies.
## Troubleshooting
### Types Missing in Monaco
**Symptom**: `Cannot find name 'BubbleOperationResult'` or similar errors
**Check**:
1. Is the type defined in the bundle?
```bash
grep "interface BubbleOperationResult" packages/bubble-core/dist/bubble-bundle.d.ts
```
2. Was the bundle copied to bubble-studio?
```bash
diff packages/bubble-core/dist/bubble-bundle.d.ts apps/bubble-studio/public/bubble-types.txt
```
3. Is Monaco loading the bundle?
- Check browser console for fetch errors
- Look for "ServiceBubble declarations found" log
### Cache Issues
If types are missing after changes:
1. Delete `dist/` folder
2. Rebuild: `pnpm run build`
3. Restart dev server
### Duplicate Type Declarations
**Symptom**: `Module has already exported a member named 'X'`
**Cause**: Type defined in both shared-schemas and bubble-core
**Solution**:
- Remove from bubble-core
- Import from shared-schemas instead
- Bundler will inline it automatically
## Build Process
```bash
# In packages/bubble-core
pnpm run build
# This runs:
# 1. tsc (generates .d.ts files)
# 2. tsx scripts/bubble-bundler.ts (creates bundle)
# 3. tsx scripts/bubble-metadata-bundler.ts (creates bubbles.json)
```
## Maintenance
When adding new types to shared-schemas:
1. No changes needed! The bundler automatically includes them
2. Just rebuild bubble-core: `pnpm run build`
3. The bundle will include the new types
When adding new files to bubble-core:
1. Export from `src/index.ts`
2. Rebuild to update the bundle
3. Types automatically available in Monaco
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

