Commit Graph

57 Commits

Author SHA1 Message Date
Jason Woltje
8dfada4bd3 Merge: Knowledge graph views - Entry-centered graphs and stats (closes #73, #74) 2026-01-29 23:39:27 -06:00
Jason Woltje
271fe7bd4c Merge: Valkey integration - Task queue service (closes #98) 2026-01-29 23:39:12 -06:00
Jason Woltje
652ba50a19 fix: code review cleanup - schema sync, type safety, null handling
- Sync KnowledgeLink schema with migration (add displayText, positionStart, positionEnd, resolved)
- Make targetId optional to support unresolved links
- Fix null handling in graph.service.ts (skip unresolved links)
- Add explicit types to frontend components (remove implicit any)
- Remove unused WikiLink import
- Add null-safe statusInfo check in EntryCard
2026-01-29 23:36:41 -06:00
Jason Woltje
562859202b fix: code review cleanup
- Replace all 'any' types with proper Prisma types
- Fix exactOptionalPropertyTypes compatibility
- Export AuthUser type from better-auth-request.interface
- Remove duplicate empty migration folder
- Ensure proper JSON handling with Prisma.InputJsonValue

All agent-tasks tests passing (18/18)
2026-01-29 23:35:40 -06:00
Jason Woltje
3ddafb898a fix: code review cleanup 2026-01-29 23:33:43 -06:00
Jason Woltje
da4fb72902 feat: add agent task schema and CRUD API (closes #96, closes #97) 2026-01-29 23:26:22 -06:00
Jason Woltje
6b776a74d2 feat: add Valkey integration for task queue (closes #98)
- Add ioredis package dependency for Redis-compatible operations
- Create ValkeyModule as global NestJS module
- Implement ValkeyService with task queue operations:
  - enqueue(task): Add tasks to FIFO queue
  - dequeue(): Get next task and update to PROCESSING status
  - getStatus(taskId): Retrieve task metadata and status
  - updateStatus(taskId, status): Update task state (COMPLETED/FAILED)
  - getQueueLength(): Monitor queue depth
  - clearQueue(): Queue management utility
  - healthCheck(): Verify Valkey connectivity
- Add TaskDto, EnqueueTaskDto, UpdateTaskStatusDto interfaces
- Implement TaskStatus enum (PENDING/PROCESSING/COMPLETED/FAILED)
- Add comprehensive test suite with in-memory Redis mock (20 tests)
- Integrate ValkeyModule into app.module.ts
- Valkey Docker Compose service already configured in docker-compose.yml
- VALKEY_URL environment variable already in .env.example
- Add detailed README with usage examples and API documentation

Technical Details:
- Uses FIFO queue (RPUSH/LPOP for strict ordering)
- Task metadata stored with 24-hour TTL
- Lifecycle hooks for connection management (onModuleInit/onModuleDestroy)
- Automatic retry with exponential backoff on connection errors
- Global module - no explicit imports needed

Tests verify:
- Connection initialization and health checks
- FIFO enqueue/dequeue behavior
- Status lifecycle transitions
- Concurrent task handling
- Queue management operations
- Complete task processing workflows
2026-01-29 23:25:33 -06:00
Jason Woltje
26a334c677 feat: add knowledge graph views and stats (closes #73, closes #74)
Issue #73 - Entry-Centered Graph View:
- Added GET /api/knowledge/entries/:id/graph endpoint with depth parameter
- Returns entry + connected nodes with link relationships
- Created GraphService for graph traversal using BFS
- Added EntryGraphViewer component for frontend
- Integrated graph view tab into entry detail page

Issue #74 - Graph Statistics Dashboard:
- Added GET /api/knowledge/stats endpoint
- Returns overview stats (entries, tags, links by status)
- Includes most connected entries, recent activity, tag distribution
- Created StatsDashboard component with visual stats
- Added route at /knowledge/stats

Backend:
- GraphService: BFS-based graph traversal with configurable depth
- StatsService: Parallel queries for comprehensive statistics
- GraphQueryDto: Validation for depth parameter (1-5)
- Entity types for graph nodes/edges and statistics
- Unit tests for both services

Frontend:
- EntryGraphViewer: Entry-centered graph visualization
- StatsDashboard: Statistics overview with charts
- Graph view tab on entry detail page
- API client functions for new endpoints
- TypeScript strict typing throughout
2026-01-29 23:25:29 -06:00
59aec28d5c Merge branch 'feature/29-cron-config' into develop
Implements cron job configuration for Mosaic Stack.

Features:
- CronSchedule model for scheduling recurring commands
- REST API endpoints for CRUD operations
- Scheduler worker that polls for due schedules
- WebSocket notifications when schedules execute
- MoltBot plugin skill definition

Issues:
- #29 Cron job configuration (p1 plugin)
- #115 Cron scheduler worker
- #116 Cron WebSocket notifications

Tests:
- 18 passing tests (cron.service + cron.scheduler)
2026-01-29 23:09:20 -06:00
5048d9eb01 feat(#115,#116): implement cron scheduler worker and WebSocket notifications
## Issues Addressed
- #115: Cron scheduler worker
- #116: Cron WebSocket notifications

## Changes

### CronSchedulerService (cron.scheduler.ts)
- Polls CronSchedule table every minute for due schedules
- Executes commands when schedules fire (placeholder for MoltBot integration)
- Updates lastRun/nextRun fields after execution
- Handles errors gracefully with logging
- Supports manual trigger for testing
- Start/stop lifecycle management

### WebSocket Integration
- Added emitCronExecuted() method to WebSocketGateway
- Emits workspace-scoped cron:executed events
- Payload includes: scheduleId, command, executedAt

### Tests
- cron.scheduler.spec.ts: 9 passing tests
- Tests cover: status, due schedule processing, manual trigger, scheduler lifecycle

## Technical Notes
- Placeholder triggerMoltBotCommand() needs actual implementation
- Uses setInterval for polling (could upgrade to cron-parser library)
- WebSocket rooms use workspace:{id} format (existing pattern)

## Files Changed
- apps/api/src/cron/cron.scheduler.ts (new)
- apps/api/src/cron/cron.scheduler.spec.ts (new)
- apps/api/src/cron/cron.module.ts (updated)
- apps/api/src/websocket/websocket.gateway.ts (updated)
2026-01-29 23:05:39 -06:00
2e6b7d4070 feat(#29): implement cron job configuration
- Add CronSchedule model to Prisma schema
- Implement CronService with CRUD operations
- Add REST API endpoints for cron management
- Create MoltBot plugin skill definition (SKILL.md)
- TDD: 9 passing tests for CronService
2026-01-29 23:00:48 -06:00
Jason Woltje
abbf886483 fix: resolve TypeScript errors in migrated components 2026-01-29 22:00:14 -06:00
Jason Woltje
532f5a39a0 feat(#41): implement widget system backend (closes #41) 2026-01-29 21:30:01 -06:00
Jason Woltje
0bd12b5751 docs(brain): add JSDoc documentation 2026-01-29 21:29:53 -06:00
Jason Woltje
f3bcb46ccd docs(websocket): add JSDoc documentation 2026-01-29 21:29:51 -06:00
Jason Woltje
163a148c11 docs(api): add API README 2026-01-29 21:29:50 -06:00
Jason Woltje
9de0b2f92f Merge PR #112: Knowledge Search Service (closes #112) 2026-01-29 21:01:45 -06:00
Jason Woltje
856b7a20e9 fix: address code review feedback
- Add explicit return types to all SearchController methods
- Import necessary types (PaginatedSearchResults, PaginatedEntries)
- Define RecentEntriesResponse interface for type safety
- Ensures compliance with TypeScript strict typing standards
2026-01-29 20:58:33 -06:00
Jason Woltje
c26b7d4e64 feat(knowledge): add search service 2026-01-29 20:35:07 -06:00
Jason Woltje
52aa1c4d06 Merge fix/controller-guards with conflict resolution 2026-01-29 20:30:57 -06:00
Jason Woltje
460bcd366c Merge remote-tracking branch 'origin/fix/rls-dto-errors' into develop 2026-01-29 20:30:20 -06:00
Jason Woltje
48abdbba8b fix(api): add WorkspaceGuard to controllers and fix route ordering 2026-01-29 20:15:33 -06:00
Jason Woltje
26a0df835f fix(api): fix RLS context, DTO validation, and error handling
- Wrap SET LOCAL in transactions for proper connection pooling
- Make workspaceId optional in query DTOs (derived from guards)
- Replace Error throws with UnauthorizedException in activity controller
- Update workspace guard to remove RLS context setting
- Document that services should use withUserContext/withUserTransaction
2026-01-29 20:14:27 -06:00
Jason Woltje
715481fbbb fix(database): add composite unique constraints for workspace isolation 2026-01-29 20:06:45 -06:00
Jason Woltje
540344d108 Merge develop to resolve conflicts 2026-01-29 19:45:29 -06:00
15e13129c7 Merge branch 'develop' into feature/82-personality 2026-01-30 01:43:40 +00:00
5a470a127f Merge branch 'develop' into feature/16-websocket 2026-01-30 01:43:06 +00:00
cb0a16effa Merge branch 'develop' into feature/know-link-resolution 2026-01-30 01:42:44 +00:00
Jason Woltje
1bd21b33d7 feat(#22): implement brain query API
- Create brain module with service, controller, and DTOs
- POST /api/brain/query - Structured queries for tasks, events, projects
- GET /api/brain/context - Get current workspace context for agents
- GET /api/brain/search - Search across all entities
- Support filters: status, priority, date ranges, assignee, etc.
- 41 tests covering service (27) and controller (14)
- Integrated with AuthGuard, WorkspaceGuard, PermissionGuard
2026-01-29 19:40:30 -06:00
Jason Woltje
8383a98070 feat(#82): add prompt formatter service to personality module
- Add PromptFormatterService for formatting system prompts based on personality
- Support context variable interpolation (userName, workspaceName, etc.)
- Add formality level modifiers (VERY_CASUAL to VERY_FORMAL)
- Add template validation for custom variables
- Add preview endpoint for formatted prompts
- Fix UpdatePersonalityDto to avoid @nestjs/mapped-types dependency
- Update PersonalitiesController with new endpoints
- Add comprehensive tests (33 passing tests)

Closes #82
2026-01-29 19:38:18 -06:00
Jason Woltje
10ed2cdb4f feat(#16): implement websocket real-time updates
- Add WebSocket gateway with workspace-scoped rooms
- Define event types: task.created, task.updated, task.deleted
- Define event types: event.created, event.updated, event.deleted
- Define event types: project.created, project.updated, project.deleted
- Add shared WebSocket types for type safety
- WebSocketModule already integrated in AppModule
2026-01-29 19:37:53 -06:00
Jason Woltje
24768bd664 feat(knowledge): add link resolution service
- Add resolveLinksFromContent() to parse wiki links from content and resolve them
- Add getBacklinks() to find all entries that link to a target entry
- Import parseWikiLinks from utils for content parsing
- Export new types: ResolvedLink, Backlink
- Add comprehensive tests for new functionality (27 tests total)
2026-01-29 19:34:57 -06:00
Jason Woltje
f706b3b982 feat(#21): implement ollama integration
- Add Ollama client library (ollama npm package)
- Create LlmService for chat completion and embeddings
- Support streaming responses via Server-Sent Events
- Add configuration via env vars (OLLAMA_HOST, OLLAMA_TIMEOUT)
- Create endpoints: GET /llm/health, GET /llm/models, POST /llm/chat, POST /llm/embed
- Replace old OllamaModule with new LlmModule
- Add comprehensive tests with >85% coverage

Closes #21
2026-01-29 19:28:31 -06:00
Jason Woltje
1cb54b56b0 Merge feature/82-personality-module (#82) into develop
Implements Personality Module:
- Personality model and Prisma migration
- CRUD API with controller and service
- Comprehensive test suite
- Integration with workspace
2026-01-29 17:59:28 -06:00
Jason Woltje
5dd46c85af feat(#82): implement Personality Module
- Add Personality model to Prisma schema with FormalityLevel enum
- Create migration and seed with 6 default personalities
- Implement CRUD API with TDD approach (97.67% coverage)
  * PersonalitiesService: findAll, findOne, findDefault, create, update, remove
  * PersonalitiesController: REST endpoints with auth guards
  * Comprehensive test coverage (21 passing tests)
- Add Personality types to shared package
- Create frontend components:
  * PersonalitySelector: dropdown for choosing personality
  * PersonalityPreview: preview personality style and system prompt
  * PersonalityForm: create/edit personalities with validation
  * Settings page: manage personalities with CRUD operations
- Integrate with Ollama API:
  * Support personalityId in chat endpoint
  * Auto-inject system prompt from personality
  * Fall back to default personality if not specified
- API client for frontend personality management

All tests passing with 97.67% backend coverage (exceeds 85% requirement)
2026-01-29 17:58:09 -06:00
Jason Woltje
5ce3bb0e28 Merge feature/41-widget-hud-system (#41) into develop
Implements Widget/HUD system:
- BaseWidget, WidgetRegistry, WidgetGrid
- TasksWidget, CalendarWidget, QuickCaptureWidget
- Layout persistence with useLayouts hooks
- Comprehensive test suite
2026-01-29 17:54:50 -06:00
Jason Woltje
14a1e218a5 feat(#41): implement Widget/HUD system
- BaseWidget wrapper with loading/error states
- WidgetRegistry for central widget management
- WidgetGrid with react-grid-layout integration
- TasksWidget, CalendarWidget, QuickCaptureWidget
- useLayouts hooks for layout persistence
- Comprehensive test suite (TDD approach)
2026-01-29 17:54:46 -06:00
Jason Woltje
3b113f87fd feat(#60): implement link resolution service
- Create LinkResolutionService with workspace-scoped link resolution
- Resolve links by: exact title match, slug match, fuzzy title match
- Handle ambiguous matches (return null if multiple matches)
- Support batch link resolution with deduplication
- Comprehensive test suite with 19 tests, all passing
- 100% coverage of public methods
- Integrate service with KnowledgeModule

Closes #60 (KNOW-008)
2026-01-29 17:50:57 -06:00
Jason Woltje
566bf1e7c5 Merge feature/15-gantt-chart (#15) into develop
Implements Gantt chart component:
- Task visualization with timeline bars
- PDA-friendly language (Target passed, not OVERDUE)
- 33 tests, 96% coverage
- Accessible with ARIA labels
- Demo page at /demo/gantt
2026-01-29 17:46:17 -06:00
Jason Woltje
9ff7718f9c feat(#15): implement Gantt chart component
- Create GanttChart component with timeline visualization
- Add task bars with status-based color coding
- Implement PDA-friendly language (Target passed vs OVERDUE)
- Support task click interactions
- Comprehensive test coverage (96.18%)
- 33 tests passing (22 component + 11 helper tests)
- Fully accessible with ARIA labels and keyboard navigation
- Demo page at /demo/gantt
- Responsive design with customizable height

Technical details:
- Uses Next.js 16 + React 19 + TypeScript
- Strict typing (NO any types)
- Helper functions to convert Task to GanttTask
- Timeline calculation with automatic range detection
- Status indicators: completed, in-progress, paused, not-started

Refs #15
2026-01-29 17:44:13 -06:00
Jason Woltje
1e5fcd19a4 feat(#59): implement wiki-link parser
- Created wiki-link-parser.ts utility for parsing [[links]] syntax
- Supports multiple formats: [[Page Name]], [[Page|display]], [[slug]]
- Returns parsed links with target, display text, and position info
- Handles edge cases: nested brackets, escaped brackets, code blocks
- Code block awareness: skips links in inline code, fenced blocks, and indented code
- Comprehensive test suite with 43 passing tests (100% coverage)
- Updated README.md with parser documentation

Implements KNOW-007 (Issue #59) - Wiki-style linking foundation
2026-01-29 17:42:49 -06:00
Jason Woltje
a5b984c7fd fix(knowledge): resolve TypeScript errors in tags service
- Fix updateData typing for partial updates
- Add slug field to CreateTagDto
- Build now passes

Note: tasks.controller.spec.ts needs test config update for WorkspaceGuard
2026-01-29 17:09:27 -06:00
Jason Woltje
5291fece26 feat(web): add workspace management UI (M2 #12)
- Create workspace listing page at /settings/workspaces
  - List all user workspaces with role badges
  - Create new workspace functionality
  - Display member count per workspace

- Create workspace detail page at /settings/workspaces/[id]
  - Workspace settings (name, ID, created date)
  - Member management with role editing
  - Invite member functionality
  - Delete workspace (owner only)

- Add workspace components:
  - WorkspaceCard: Display workspace info with role badge
  - WorkspaceSettings: Edit workspace settings and delete
  - MemberList: Display and manage workspace members
  - InviteMember: Send invitations with role selection

- Add WorkspaceMemberWithUser type to shared package
- Follow existing app patterns for styling and structure
- Use mock data (ready for API integration)
2026-01-29 16:59:26 -06:00
Jason Woltje
287a0e2556 feat(knowledge): add markdown rendering (KNOW-004)
- Install marked, marked-highlight, marked-gfm-heading-id, sanitize-html
- Create markdown utility with GFM support (tables, task lists, strikethrough)
- Add code syntax highlighting with highlight.js
- Implement XSS sanitization for security
- Update knowledge service to use markdown renderer
- Add comprehensive test suite (34 tests, all passing)
- Generate IDs for headers for deep linking
- Cache rendered HTML in database for performance
2026-01-29 16:57:57 -06:00
Jason Woltje
81d426453a fix(knowledge): fix type safety issues in entry CRUD API (KNOW-002)
- Remove @nestjs/swagger decorators (package not installed)
- Fix controller to use @Request() req for accessing workspaceId
- Fix service to properly handle nullable Prisma fields (summary)
- Fix update method to conditionally build update object
- Add missing tag DTOs to satisfy dependencies

Resolves compilation errors and ensures type safety.
2026-01-29 16:16:49 -06:00
Jason Woltje
f07f04404d feat(knowledge): add tag management API (KNOW-003)
- Add Tag DTOs (CreateTagDto, UpdateTagDto) with validation
- Implement TagsService with CRUD operations
- Add TagsController with authenticated endpoints
- Support automatic slug generation from tag names
- Add workspace isolation for tags
- Include entry count in tag responses
- Add findOrCreateTags method for entry creation/update
- Implement comprehensive test coverage (29 tests passing)

Endpoints:
- GET /api/knowledge/tags - List workspace tags
- POST /api/knowledge/tags - Create tag
- GET /api/knowledge/tags/:slug - Get tag by slug
- PUT /api/knowledge/tags/:slug - Update tag
- DELETE /api/knowledge/tags/:slug - Delete tag
- GET /api/knowledge/tags/:slug/entries - List entries with tag

Related: KNOW-003
2026-01-29 16:13:40 -06:00
Jason Woltje
244e50c806 feat(multi-tenant): add Team model and RLS policies
Implements #9, #10
- Team model with workspace membership
- TeamMember model with role-based access (OWNER, ADMIN, MEMBER)
- Row-Level Security policies for tenant isolation on 19 tables
- Helper functions: current_user_id(), is_workspace_member(), is_workspace_admin()
- Developer utilities in src/lib/db-context.ts for easy RLS integration
- Comprehensive documentation in docs/design/multi-tenant-rls.md

Database migrations:
- 20260129220941_add_team_model: Adds Team and TeamMember tables
- 20260129221004_add_rls_policies: Enables RLS and creates policies

Security features:
- Complete database-level tenant isolation
- Automatic query filtering based on workspace membership
- Defense-in-depth security with application and database layers
- Performance-optimized with indexes on workspace_id
2026-01-29 16:13:09 -06:00
Jason Woltje
1edea83e38 feat(knowledge): add database schema for Knowledge Module
Implements KNOW-001
- KnowledgeEntry, Version, Link, Tag, Embedding models
- Full indexes and constraints
- Seed data for testing
2026-01-29 16:07:58 -06:00
Jason Woltje
f47dd8bc92 feat: add domains, ideas, layouts, widgets API modules
- Add DomainsModule with full CRUD, search, and activity logging
- Add IdeasModule with quick capture endpoint
- Add LayoutsModule for user dashboard layouts
- Add WidgetsModule for widget definitions (read-only)
- Update ActivityService with domain/idea logging methods
- Register all new modules in AppModule
2026-01-29 13:47:03 -06:00
Jason Woltje
973502f26e 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
2026-01-29 12:29:21 -06:00