feat(#37-41): Add domains, ideas, relationships, agents, widgets schema

Schema additions for issues #37-41:

New models:
- Domain (#37): Life domains (work, marriage, homelab, etc.)
- Idea (#38): Brain dumps with pgvector embeddings
- Relationship (#39): Generic entity linking (blocks, depends_on)
- Agent (#40): ClawdBot agent tracking with metrics
- AgentSession (#40): Conversation session tracking
- WidgetDefinition (#41): HUD widget registry
- UserLayout (#41): Per-user dashboard configuration

Updated models:
- Task, Event, Project: Added domainId foreign key
- User, Workspace: Added new relations

New enums:
- IdeaStatus: CAPTURED, PROCESSING, ACTIONABLE, ARCHIVED, DISCARDED
- RelationshipType: BLOCKS, BLOCKED_BY, DEPENDS_ON, etc.
- AgentStatus: IDLE, WORKING, WAITING, ERROR, TERMINATED
- EntityType: Added IDEA, DOMAIN

Migration: 20260129182803_add_domains_ideas_agents_widgets
This commit is contained in:
Jason Woltje
2026-01-29 12:29:21 -06:00
parent a220c2dc0a
commit 973502f26e
308 changed files with 18374 additions and 113 deletions

View File

@@ -0,0 +1,95 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import CallbackPage from "./page";
// Mock next/navigation
const mockPush = vi.fn();
const mockSearchParams = new Map<string, string>();
vi.mock("next/navigation", () => ({
useRouter: () => ({
push: mockPush,
}),
useSearchParams: () => ({
get: (key: string) => mockSearchParams.get(key),
}),
}));
// Mock auth context
vi.mock("@/lib/auth/auth-context", () => ({
useAuth: vi.fn(() => ({
refreshSession: vi.fn(),
})),
}));
const { useAuth } = await import("@/lib/auth/auth-context");
describe("CallbackPage", () => {
beforeEach(() => {
mockPush.mockClear();
mockSearchParams.clear();
vi.mocked(useAuth).mockReturnValue({
refreshSession: vi.fn(),
user: null,
isLoading: false,
isAuthenticated: false,
signOut: vi.fn(),
});
});
it("should render processing message", () => {
render(<CallbackPage />);
expect(
screen.getByText(/completing authentication/i)
).toBeInTheDocument();
});
it("should redirect to tasks page on success", async () => {
const mockRefreshSession = vi.fn().mockResolvedValue(undefined);
vi.mocked(useAuth).mockReturnValue({
refreshSession: mockRefreshSession,
user: null,
isLoading: false,
isAuthenticated: false,
signOut: vi.fn(),
});
render(<CallbackPage />);
await waitFor(() => {
expect(mockRefreshSession).toHaveBeenCalled();
expect(mockPush).toHaveBeenCalledWith("/tasks");
});
});
it("should redirect to login on error parameter", async () => {
mockSearchParams.set("error", "access_denied");
mockSearchParams.set("error_description", "User cancelled");
render(<CallbackPage />);
await waitFor(() => {
expect(mockPush).toHaveBeenCalledWith("/login?error=access_denied");
});
});
it("should handle refresh session errors gracefully", async () => {
const mockRefreshSession = vi
.fn()
.mockRejectedValue(new Error("Session error"));
vi.mocked(useAuth).mockReturnValue({
refreshSession: mockRefreshSession,
user: null,
isLoading: false,
isAuthenticated: false,
signOut: vi.fn(),
});
render(<CallbackPage />);
await waitFor(() => {
expect(mockRefreshSession).toHaveBeenCalled();
expect(mockPush).toHaveBeenCalledWith("/login?error=session_failed");
});
});
});

View File

@@ -0,0 +1,59 @@
"use client";
import { Suspense, useEffect } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { useAuth } from "@/lib/auth/auth-context";
function CallbackContent() {
const router = useRouter();
const searchParams = useSearchParams();
const { refreshSession } = useAuth();
useEffect(() => {
async function handleCallback() {
// Check for OAuth errors
const error = searchParams.get("error");
if (error) {
console.error("OAuth error:", error, searchParams.get("error_description"));
router.push(`/login?error=${error}`);
return;
}
// Refresh the session to load the authenticated user
try {
await refreshSession();
router.push("/tasks");
} catch (error) {
console.error("Session refresh failed:", error);
router.push("/login?error=session_failed");
}
}
handleCallback();
}, [router, searchParams, refreshSession]);
return (
<div className="flex min-h-screen flex-col items-center justify-center p-8">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900 mx-auto mb-4"></div>
<h1 className="text-2xl font-semibold mb-2">Completing authentication...</h1>
<p className="text-gray-600">You will be redirected shortly.</p>
</div>
</div>
);
}
export default function CallbackPage() {
return (
<Suspense fallback={
<div className="flex min-h-screen flex-col items-center justify-center p-8">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900 mx-auto mb-4"></div>
<h1 className="text-2xl font-semibold mb-2">Loading...</h1>
</div>
</div>
}>
<CallbackContent />
</Suspense>
);
}

View File

@@ -0,0 +1,39 @@
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import LoginPage from "./page";
// Mock next/navigation
vi.mock("next/navigation", () => ({
useRouter: () => ({
push: vi.fn(),
}),
}));
describe("LoginPage", () => {
it("should render the login page with title", () => {
render(<LoginPage />);
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
"Welcome to Mosaic Stack"
);
});
it("should display the description", () => {
render(<LoginPage />);
const descriptions = screen.getAllByText(/Your personal assistant platform/i);
expect(descriptions.length).toBeGreaterThan(0);
expect(descriptions[0]).toBeInTheDocument();
});
it("should render the sign in button", () => {
render(<LoginPage />);
const buttons = screen.getAllByRole("button", { name: /sign in/i });
expect(buttons.length).toBeGreaterThan(0);
expect(buttons[0]).toBeInTheDocument();
});
it("should have proper layout styling", () => {
const { container } = render(<LoginPage />);
const main = container.querySelector("main");
expect(main).toHaveClass("flex", "min-h-screen");
});
});

View File

@@ -0,0 +1,20 @@
import { LoginButton } from "@/components/auth/LoginButton";
export default function LoginPage() {
return (
<main className="flex min-h-screen flex-col items-center justify-center p-8 bg-gray-50">
<div className="w-full max-w-md space-y-8">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4">Welcome to Mosaic Stack</h1>
<p className="text-lg text-gray-600">
Your personal assistant platform. Organize tasks, events, and
projects with a PDA-friendly approach.
</p>
</div>
<div className="bg-white p-8 rounded-lg shadow-md">
<LoginButton />
</div>
</div>
</main>
);
}

View File

@@ -0,0 +1,27 @@
"use client";
import { Calendar } from "@/components/calendar/Calendar";
import { mockEvents } from "@/lib/api/events";
export default function CalendarPage() {
// TODO: Replace with real API call when backend is ready
// const { data: events, isLoading } = useQuery({
// queryKey: ["events"],
// queryFn: fetchEvents,
// });
const events = mockEvents;
const isLoading = false;
return (
<main className="container mx-auto px-4 py-8">
<div className="mb-8">
<h1 className="text-3xl font-bold text-gray-900">Calendar</h1>
<p className="text-gray-600 mt-2">
View your schedule at a glance
</p>
</div>
<Calendar events={events} isLoading={isLoading} />
</main>
);
}

View File

@@ -0,0 +1,37 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/lib/auth/auth-context";
import { Navigation } from "@/components/layout/Navigation";
import type { ReactNode } from "react";
export default function AuthenticatedLayout({ children }: { children: ReactNode }) {
const router = useRouter();
const { isAuthenticated, isLoading } = useAuth();
useEffect(() => {
if (!isLoading && !isAuthenticated) {
router.push("/login");
}
}, [isAuthenticated, isLoading, router]);
if (isLoading) {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900"></div>
</div>
);
}
if (!isAuthenticated) {
return null;
}
return (
<div className="min-h-screen bg-gray-50">
<Navigation />
<div className="pt-16">{children}</div>
</div>
);
}

View File

@@ -0,0 +1,30 @@
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import TasksPage from "./page";
// Mock the TaskList component
vi.mock("@/components/tasks/TaskList", () => ({
TaskList: ({ tasks, isLoading }: { tasks: unknown[]; isLoading: boolean }) => (
<div data-testid="task-list">
{isLoading ? "Loading" : `${tasks.length} tasks`}
</div>
),
}));
describe("TasksPage", () => {
it("should render the page title", () => {
render(<TasksPage />);
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Tasks");
});
it("should render the TaskList component", () => {
render(<TasksPage />);
expect(screen.getByTestId("task-list")).toBeInTheDocument();
});
it("should have proper layout structure", () => {
const { container } = render(<TasksPage />);
const main = container.querySelector("main");
expect(main).toBeInTheDocument();
});
});

View File

@@ -0,0 +1,27 @@
"use client";
import { TaskList } from "@/components/tasks/TaskList";
import { mockTasks } from "@/lib/api/tasks";
export default function TasksPage() {
// TODO: Replace with real API call when backend is ready
// const { data: tasks, isLoading } = useQuery({
// queryKey: ["tasks"],
// queryFn: fetchTasks,
// });
const tasks = mockTasks;
const isLoading = false;
return (
<main className="container mx-auto px-4 py-8">
<div className="mb-8">
<h1 className="text-3xl font-bold text-gray-900">Tasks</h1>
<p className="text-gray-600 mt-2">
Organize your work at your own pace
</p>
</div>
<TaskList tasks={tasks} isLoading={isLoading} />
</main>
);
}

View File

@@ -1,5 +1,7 @@
import type { Metadata } from "next";
import type { ReactNode } from "react";
import { AuthProvider } from "@/lib/auth/auth-context";
import { ErrorBoundary } from "@/components/error-boundary";
import "./globals.css";
export const metadata: Metadata = {
@@ -10,7 +12,11 @@ export const metadata: Metadata = {
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
<body>
<ErrorBoundary>
<AuthProvider>{children}</AuthProvider>
</ErrorBoundary>
</body>
</html>
);
}

View File

@@ -1,22 +1,42 @@
import { describe, expect, it, afterEach } from "vitest";
import { render, screen, cleanup } from "@testing-library/react";
import { describe, expect, it, vi, beforeEach } from "vitest";
import { render } from "@testing-library/react";
import Home from "./page";
afterEach(() => {
cleanup();
});
// Mock Next.js navigation
const mockPush = vi.fn();
vi.mock("next/navigation", () => ({
useRouter: () => ({
push: mockPush,
replace: vi.fn(),
prefetch: vi.fn(),
}),
}));
// Mock auth context
vi.mock("@/lib/auth/auth-context", () => ({
useAuth: () => ({
user: null,
isLoading: false,
isAuthenticated: false,
signOut: vi.fn(),
refreshSession: vi.fn(),
}),
}));
describe("Home", () => {
it("should render the title", () => {
render(<Home />);
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Mosaic Stack");
beforeEach(() => {
mockPush.mockClear();
});
it("should render the buttons", () => {
it("should render loading spinner", () => {
const { container } = render(<Home />);
// The home page shows a loading spinner while redirecting
const spinner = container.querySelector(".animate-spin");
expect(spinner).toBeInTheDocument();
});
it("should redirect unauthenticated users to login", () => {
render(<Home />);
const buttons = screen.getAllByRole("button");
expect(buttons.length).toBe(2);
expect(buttons[0]).toHaveTextContent("Get Started");
expect(buttons[1]).toHaveTextContent("Learn More");
expect(mockPush).toHaveBeenCalledWith("/login");
});
});

View File

@@ -1,14 +1,26 @@
import { Button } from "@mosaic/ui";
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/lib/auth/auth-context";
export default function Home() {
const router = useRouter();
const { isAuthenticated, isLoading } = useAuth();
useEffect(() => {
if (!isLoading) {
if (isAuthenticated) {
router.push("/tasks");
} else {
router.push("/login");
}
}
}, [isAuthenticated, isLoading, router]);
return (
<main className="flex min-h-screen flex-col items-center justify-center p-24">
<h1 className="text-4xl font-bold mb-8">Mosaic Stack</h1>
<p className="text-lg text-gray-600 mb-8">Welcome to the Mosaic Stack monorepo</p>
<div className="flex gap-4">
<Button variant="primary">Get Started</Button>
<Button variant="secondary">Learn More</Button>
</div>
</main>
<div className="flex min-h-screen items-center justify-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900"></div>
</div>
);
}