Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cae63b1
feat: implement manual sync strategy with subtle UI notification
jchris Sep 17, 2025
d9b310e
feat: add type safety to ManualRedirectStrategy and export ImgGenModa…
jchris Sep 17, 2025
e952bfa
feat: add ToCloudAttachable return type to toCloud function
jchris Sep 22, 2025
9bbc130
ci: add root validation step and fail-fast behavior to publishing wor…
jchris Sep 22, 2025
178be9f
feat: export toCloud function from use-vibes package
jchris Sep 22, 2025
3c07016
docs: improve formatting and readability of publishing workflow docum…
jchris Sep 22, 2025
21d6732
docs: add use-vibes module architecture and enhanced useFireproof imp…
jchris Sep 23, 2025
79cd634
feat: add automatic vibes-login-link button integration with implicit…
jchris Sep 23, 2025
61ab0e9
feat: auto-generate ledger names from origin and database name for en…
jchris Sep 23, 2025
4433455
ci: replace pnpm check with pnpm build in publish workflow validation…
jchris Sep 23, 2025
613b98f
refactor: wrap enableSync and disableSync in useCallback with proper …
jchris Sep 23, 2025
cff6a8b
chore: move generateLedgerName into strategy
necrodome Sep 23, 2025
c2efbb9
chore: remove generateLedgerName function and simplify toCloud usage
necrodome Sep 24, 2025
c91ca18
fix: remove early return statement in ImageGeneratorExample component
jchris Sep 25, 2025
49a0bba
fix: update dashboardURI in toCloud for auto-select
necrodome Sep 25, 2025
39176cb
chore: update @fireproof/core-cli to v0.23.13 across all packages
jchris Sep 25, 2025
7d4b6e0
chore: add TypeScript parser options to ESLint config for project res…
jchris Sep 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/use-vibes-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ jobs:

- uses: ./actions/base

- name: validate-all-packages
shell: bash
run: |
set -e
echo "Running root validation before publishing..."
pnpm build
echo "✅ All packages validated successfully"

- uses: ./use-vibes/actions/publish
with:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
187 changes: 187 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,190 @@ This repository uses PNPM workspaces to manage a monorepo structure with multipl
- Specific workspace: `pnpm add <package> --filter <workspace-name>`
- **Script execution**: Scripts in root package.json often delegate to specific workspace packages
- **Shared dependencies**: Common dependencies are hoisted to the root `node_modules` when possible

## CI/CD Architecture and Tag-Based Publishing

### GitHub Actions Structure

The repository uses a complex CI/CD system with multiple workflows and composite actions:

```
.github/workflows/
├── use-vibes-publish.yaml # Main workflow triggered by use-vibes@* tags
└── [other workflows...]

actions/
├── base/ # Base setup actions
├── core-publish/ # Generic publishing action
└── [other shared actions...]

use-vibes/actions/
└── publish/ # use-vibes specific publishing action
└── action.yaml
```

### Tag-Based Trigger System

**Tag Pattern**: `use-vibes@v0.12.6-dev` triggers the use-vibes publishing workflow

The workflow in `.github/workflows/use-vibes-publish.yaml`:

1. Triggers on pushes to `use-vibes@*` tags
2. Calls base setup action (`./actions/base`)
3. Calls use-vibes publish action (`./use-vibes/actions/publish`)

### Multi-Package Publishing Process

**CRITICAL ISSUE**: The publishing action runs **three independent steps** that don't fail-fast:

1. **publish-call-ai** (working-directory: `call-ai/pkg`)
2. **publish-base** (working-directory: `use-vibes/base`)
3. **publish-use-vibes** (working-directory: `use-vibes/pkg`)

**Problem**: If step 2 fails with TypeScript errors, steps 1 and 3 still publish successfully, creating **partial releases** with broken packages on npm.

### Build Failure Analysis

When `use-vibes@v0.12.6-dev` was tagged:

- ✅ `call-ai@0.12.6-dev` published successfully
- ❌ `@vibes.diy/use-vibes-base@0.12.6-dev` failed with TS2742 error
- ✅ `use-vibes@0.12.6-dev` published anyway (depends on broken base package)

### Prevention Strategy

**Always run `pnpm check` before tagging** - this would catch the TypeScript error:

```bash
# This runs: format && build && test && lint
pnpm check

# Only create tag if check passes
git tag use-vibes@v0.12.6-dev2
git push origin use-vibes@v0.12.6-dev2
```

### Workflow Improvements (IMPLEMENTED)

✅ **Fixed CI/CD Issues** - The following improvements have been implemented:

1. **Added root validation step** - `pnpm check` now runs before any publishing attempts
2. **Added fail-fast behavior** - All bash scripts use `set -e` to exit on first error
3. **Atomic publishing** - If any step fails, the entire workflow stops

**New Workflow Order**:

1. Checkout code
2. Setup base environment
3. **Run `pnpm check`** (format + build + test + lint) - **STOPS HERE IF ANY PACKAGE HAS ISSUES**
4. Publish call-ai (only if validation passes)
5. Publish use-vibes/base (only if call-ai succeeds)
6. Publish use-vibes/pkg (only if base succeeds)

### Package Version Coordination

- All packages extract version from the same git tag (`use-vibes@v0.12.6-dev`)
- Package.json versions remain at `0.0.0` as placeholders
- CI dynamically sets version during build process
- Dependency relationships: `use-vibes` → `@vibes.diy/use-vibes-base` → `call-ai`

## Use-Vibes Module Architecture

### Enhanced useFireproof Hook Strategy

From commit `8509d99` (Sept 17, 2025), use-vibes provides an **enhanced version** of `useFireproof` that serves as a drop-in replacement with additional sync capabilities.

#### Original vs Enhanced Behavior

```typescript
// Original use-fireproof behavior:
const { database, useLiveQuery } = useFireproof("mydb");

// Enhanced use-vibes behavior (drop-in replacement):
const { database, useLiveQuery, enableSync, disableSync, syncEnabled } =
useFireproof("mydb");
```

#### Key Enhancements Added

1. **Local-first behavior** - starts without sync by default
2. **ManualRedirectStrategy** - custom auth strategy with subtle UI overlay
3. **enableSync()** function - allows users to manually trigger sync
4. **disableSync()** function - allows users to disable sync
5. **syncEnabled** state - tracks current sync status
6. **Persistent preferences** - remembers sync choice in localStorage

### Module Integration Architecture

```
use-vibes/pkg/index.ts (public API)
├── Re-exports from @vibes.diy/use-vibes-base
└── Adds RuntimeError interface

@vibes.diy/use-vibes-base/index.ts (core implementation)
├── Enhanced useFireproof hook (wraps original)
├── toCloud helper (with ManualRedirectStrategy)
├── ManualRedirectStrategy class
├── ImgGen components and utilities
└── Re-exports from use-fireproof + call-ai
```

### Enhanced useFireproof Implementation Details

The use-vibes `useFireproof` is a **wrapper** around the original that adds:

1. **Automatic ManualRedirectStrategy injection** - uses custom auth flow instead of default redirect
2. **Conditional sync** - only attaches cloud sync when explicitly enabled by user
3. **State management** - tracks manual vs automatic sync states using React state
4. **UI automation** - programmatically triggers auth popups via DOM manipulation
5. **Persistence** - uses localStorage to remember user's sync preference across sessions
6. **Dual attachment modes** - supports both original flow (for returning users) and manual flow (for first-time)

### Drop-in Replacement Strategy

For users who change their import from `use-fireproof` to `use-vibes`, the enhanced version provides:

- **Same API surface** - all original useFireproof functionality preserved
- **Implicit cloud sync** - cloud sync is always enabled (no need for `{ attach: toCloud() }`)
- **Enhanced defaults** - better auth UX with ManualRedirectStrategy
- **Optional sync features** - `enableSync`/`disableSync` available but not required
- **Backward compatibility** - existing code continues to work without changes
- **Progressive enhancement** - users can opt-in to new sync features when ready

#### Enhanced Button Integration

```typescript
// Simple API - no manual sync config needed:
const { database, useLiveQuery, enableSync, syncEnabled } =
useFireproof("db-name");
```

**Key Enhancement:**

- No need to manually pass `{ attach: toCloud() }` parameter
- Automatic `vibes-login-link` button detection and wiring
- **Automatic ledger naming**: Generates cloud ledger names like `https-myapp-com-kanban-board`
- **Environment isolation**: Different origins (localhost vs production) get separate ledgers
- ManualRedirectStrategy provides better auth UX
- **Respects user preferences**: Only enables sync when user clicks the button or has previously enabled it
- Sync state is managed through localStorage (`wasSyncEnabled` preference)

#### Automatic Button Integration

The enhanced `useFireproof` automatically detects and wires up a button with `id="vibes-login-link"`:

- **Button Detection**: Searches for `#vibes-login-link` on component mount
- **Event Handling**: Connects button clicks to the `enableSync()` function
- **Multiple Instances**: Each `useFireproof` hook adds its own event listener
- **Clean Cleanup**: Event listeners are properly removed on component unmount
- **Graceful Degradation**: Works without the button (no errors if not found)

This allows vibes runtime containers to provide a login button that automatically triggers sync for all active `useFireproof` instances.

### ManualRedirectStrategy Features

- **Subtle UI overlay** - bottom-right notification instead of full-screen redirect
- **Custom CSS animations** - slide-up animation with modern styling
- **Programmatic auth** - JavaScript-triggered popup instead of page redirect
- **Better UX** - non-blocking authentication flow
- **Configurable** - custom overlay HTML and CSS can be provided
2 changes: 1 addition & 1 deletion call-ai/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"license": "Apache-2.0",
"devDependencies": {
"@fireproof/core-cli": "^0.23.11",
"@fireproof/core-cli": "^0.23.13",
"@types/node": "^24.0.15",
"typescript": "^5.8.3"
},
Expand Down
2 changes: 1 addition & 1 deletion call-ai/tests/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"license": "Apache-2.0",
"devDependencies": {
"@fireproof/core-cli": "^0.23.11",
"@fireproof/core-cli": "^0.23.13",
"@playwright/test": "^1.54.1",
"@types/node": "^24.0.15",
"tsx": "^4.20.3",
Expand Down
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const opts = tseslint.config(
globals: {
queueMicrotask: "readonly",
},
parserOptions: {
tsconfigRootDir: import.meta.dirname,
project: true,
},
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@eslint/js": "^9.31.0",
"@fireproof/core-cli": "^0.23.11",
"@fireproof/core-cli": "^0.23.13",
"@playwright/test": "^1.55.0",
"@types/deno": "^2.3.0",
"@types/node": "^24.1.0",
Expand Down
Loading