An autonomous document intelligence workspace that ingests meeting notes and research files, distils them into actionable insights, and prioritises the next best tasks with an outcome-driven agent running on Mastra.
- Highlights
- System Overview
- How It Works
- Agent Instructions & Tools
- Getting Started
- Development & Quality
- Project Structure
- Deployment
- Resources
- Multi-format ingestion (PDF, DOCX, TXT, Markdown) with deduplication and OCR fallback.
- Outcome-aware scoring blends AI summaries with the current strategic outcome and reflections.
- Mastra-powered agent orchestrates prioritisation using semantic search, dependency detection, and clustering tools.
- Realtime dashboard surfaces document status, queue load, and prioritised plans.
- Built with Next.js 15, React 19, Tailwind, and Supabase for storage, vector search, and telemetry.
- App Router in
app/renders the upload flow (app/page.tsx) and dashboard (app/dashboard/page.tsx). - UI primitives live in
app/components/andcomponents/ui/, using shadcn + Radix. - Client-side polling keeps file status fresh via
/api/statusand/api/agent/sessionsendpoints.
- API routes under
app/api/handle uploads, processing, exports, and agent control planes. - Supabase stores raw uploads (
storage/notes), structured outputs (processed_documents), task embeddings, outcomes, reflections, and agent sessions. - Service layer in
lib/services/converts files, calls OpenAI, filters actions, computes embeddings, and manages concurrency.
lib/mastra/agents/taskOrchestrator.tsdefines the Task Orchestration Agent, its behaviour contract, and tool usage rules.- Tools are registered in
lib/mastra/tools/index.tsand instrumented throughlib/mastra/init.tsfor telemetry defined inlib/mastra/config.ts. lib/mastra/services/agentOrchestration.tsassembles context, launches the agent run, normalises the trace, and persists results back to Supabase.
- Upload & Validation –
app/api/upload/route.tsvalidates file size/type, computes a content hash, stores the blob in Supabase, and enqueues the job vialib/services/processingQueue.ts(max three concurrent conversions). - Processing Trigger – background workers call
app/api/process/route.ts, which loads metadata and the binary asset, flips document status toprocessing, and logs the run. - Format Normalisation –
lib/services/noteProcessor.tsconverts PDF/DOCX/TXT to Markdown, applying OCR fallback when native text is thin. - AI Extraction –
lib/services/aiSummarizer.tsdrives OpenAI to extract topics, decisions, actions, and metrics, with retry handling for invalid JSON and forced test flags. - Outcome Scoring & Filtering –
scoreActionsWithSemanticSimilarityinlib/services/aiSummarizer.tsranks actions against the active outcome fromuser_outcomes;lib/services/filteringService.tstrims actions that exceed capacity or violate state preferences. - Embeddings & Storage –
lib/services/embeddingService.tsandlib/services/embeddingQueue.tsbuild task embeddings, store them throughlib/services/vectorStorage.ts, and update Supabase tables (task_embeddings,processed_documents). - Dashboard Surface – the dashboard (
app/dashboard/page.tsx) reads document status via/api/documents, exports via/api/export, and shares queue telemetry fromapp/api/status/route.ts.
- Trigger – POST
/api/agent/prioritize(app/api/agent/prioritize/route.ts) validates the active outcome, opens anagent_sessionsrecord, and schedules orchestration. - Context Assembly –
lib/mastra/services/agentOrchestration.tsgathers the active outcome, recent reflections (lib/services/reflectionService.ts), and up to 200 candidate tasks sourced from embeddings or raw structured outputs. - Agent Instructions –
taskOrchestratorAgentinlib/mastra/agents/taskOrchestrator.tsreceives a strict instruction block covering reasoning cadence, tool parameter schemas, and expected JSON output. - Tool Execution – Tools defined in
lib/mastra/tools/*.ts(semantic search, document context, dependency detection, clustering, graph query) are auto-registered vialib/mastra/init.ts; telemetry spans capture retries, latency, and outputs. - Result Parsing –
lib/mastra/services/resultParser.tsvalidates agent JSON, repairs partial traces, computes execution metadata, and persists an ordered plan + execution waves back to the originating session. - Session Consumption – The client polls
/api/agent/sessions/[sessionId]and/api/agent/sessions/latestto show progress, fallback plans, or surfaced errors, and stores execution metrics for analytics.
lib/mastra/agents/taskOrchestrator.ts– canonical prompt for the prioritisation agent, including mandatory behaviours and schema expectations.AGENTS.md– repository-level guardrails covering directory layout, testing guidance, and security posture for any new agent work.specs/– feature specs and planning artifacts referenced during orchestration to capture business rules; seespecs/files for requirement IDs..claude/– archived agent transcripts that can be replayed when diagnosing regressions or tuning reasoning strategies.
| Tool | Location | Purpose |
|---|---|---|
semantic-search |
lib/mastra/tools/semanticSearch.ts |
Finds the most relevant tasks and embeddings for an outcome query. |
get-document-context |
lib/mastra/tools/getDocumentContext.ts |
Fetches Markdown/context chunks for selected task IDs. |
detect-dependencies |
lib/mastra/tools/detectDependencies.ts |
Infers prerequisite chains between tasks using AI and stored metadata. |
query-task-graph |
lib/mastra/tools/queryTaskGraph.ts |
Reads previously persisted relationships to avoid redundant inference. |
cluster-by-similarity |
lib/mastra/tools/clusterBySimilarity.ts |
Groups tasks into execution waves based on semantic similarity thresholds. |
- Telemetry:
lib/mastra/config.tsenables console telemetry with rate limits and slow-run alerts; instrumentation lives inlib/mastra/init.ts. - Quick health check:
npx tsx scripts/test-mastra.tsensures tools register correctly and telemetry emits traces. - Contract tests:
__tests__/contract/mastra-tools.test.tsand__tests__/integration/tool-execution.test.ts(see repository guidelines) mirror runtime expectations for the agent layer.
- Node.js 18 or newer.
- pnpm/nvm/yarn/npm (project uses npm scripts).
- Supabase project with storage bucket
notesand Postgres schema fromsupabase/migrations/. - OpenAI API key with access to the deployed model family.
-
Clone the repository and move into the workspace.
git clone <repository-url> cd notes npm install
-
Copy environment defaults and supply credentials.
cp .env.local.example .env.local
Required variables:
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_supabase_anon_key OPENAI_API_KEY=your_openai_api_key
-
Apply database migrations using the Supabase CLI (≥1.188).
supabase db push # or supabase migration upEnsure the
notesstorage bucket is created (supabase/migrations/20241004082124_create-notes-bucket.sql). -
Start the development server.
npm run dev
Visit
http://localhost:3000to upload documents and monitor prioritisation sessions.
npm run lint– ESLint + Prettier (TypeScript strict mode).npm run test– Vitest in watch mode; for single pass usenpm run test:run.npm run test:ui– launches the Vitest UI dashboard.- Integration specs that stress Tinypool threads:
npm run test:run -- --pool=threads --poolOptions.threads.minThreads=1 --poolOptions.threads.maxThreads=1. - Explorer scripts live in
scripts/(e.g.scripts/test-mastra.tsfor agent health).
Testing guidelines:
- Unit tests sit alongside services/components; contract and integration suites live in
__tests__/contract/and__tests__/integration/respectively. - Target ≥80 % coverage, adding regression specs for every bug fix or retry logic tweak.
- Supabase-dependent tests require
NEXT_PUBLIC_SUPABASE_URL+NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY; mock external APIs where possible.
notes/
├── app/ # Next.js App Router, API routes, and shared UI
│ ├── api/ # Upload, process, export, agent, status endpoints
│ ├── components/ # Feature-specific UI blocks
│ └── dashboard/ # Outcome and document dashboards
├── lib/
│ ├── mastra/ # Agents, tool registry, orchestration services
│ ├── services/ # File conversion, AI summarisation, embeddings, queues
│ ├── schemas/ # Zod schemas + helpers
│ └── hooks/ # Client-side data hooks
├── __tests__/ # Contract + integration suites
├── specs/ # Feature specs & runbooks
├── supabase/ # SQL migrations and storage policies
├── docs/ # Additional guidance and design notes
└── scripts/ # Mastra diagnostics and utilities
- Configure environment variables (
NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY,OPENAI_API_KEY) in your hosting provider. - Build with
npm run buildand serve vianpm run start. - Vercel is the quickest path (Next.js 15 native); Netlify, Railway, DO App Platform, and AWS Amplify are also supported.
- Ensure Supabase Row Level Security policies mirror the migrations shipped in
supabase/migrations/to protect uploaded assets and agent traces.
- Specs & planning artifacts –
specs/ - Agent transcripts & debugging context –
.claude/ - Implementation examples & standards –
IMPLEMENTATION_EXAMPLES.md,standards.md - Mobile QA and visual baselines –
MOBILE_RESPONSIVENESS_REPORT.md,VISUAL_COMPARISON.md - Need to validate Mastra wiring?
npx tsx scripts/test-mastra.ts
Built with ❤️ using Next.js 15, React 19, TypeScript, Supabase, and Mastra.