Commit Graph

29 Commits

Author SHA1 Message Date
Christian Gick
9042bf0878 fix(CF-816): Self-healing session number sequence to prevent drift
session_sequences table fell behind when sessions were inserted with
explicit session_number (e.g., retro imports), causing duplicate key
violations on next auto-assigned number. Function now syncs forward
by checking MAX(session_number) before assigning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 07:48:54 +02:00
Christian Gick
63cba97b56 feat(CF-762): Add Jira integration for session tracking
Sessions now auto-create CF Jira issues on start and post full session
output as comments on end, transitioning the issue to Done.

- Add src/services/jira.ts with createSessionIssue, addComment, transitionToDone
- Update session_start to create CF Jira issue and store key in sessions table
- Update session_end to post session output and close Jira issue
- Add migration 031 to archive local task tables (moved to Jira Cloud)
- Update .env.example with Jira Cloud env vars

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 07:23:18 +02:00
Christian Gick
1227e5b339 feat(CF-762): Complete Jira migration - consolidate projects, cleanup
- Remove task CRUD/epic/search/relation/version tools (moved to Jira)
- Add migration scripts: migrate-tasks-to-jira, jira-admin, prepare-all-projects
- Add consolidate-projects.ts for merging duplicate Jira projects
- Add validate-migration.ts for post-migration integrity checks
- Add jira_issue_key columns migration (030)
- Consolidate 11 duplicate projects (LIT→LITE, CARD→CS, etc.)
- Delete 92 placeholder issues, 11 empty source projects
- Remove SG project completely
- 2,798 tasks migrated across 46 Jira projects

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 12:33:49 +02:00
Christian Gick
6cbb5ce6cb feat(CF-314): Add planning_mode_required field and smart planning mode support
Adds DB column, TypeScript types, MCP tool schemas, and CRUD handlers
for planning_mode_required (NULL=auto-detect, true=always, false=never).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 20:30:36 +02:00
Christian Gick
e04a8ab524 feat(CF-580): Implement transcript-based session recovery for MCP
Add direct transcript ingestion and orphan recovery using Claude Code's JSONL
transcripts instead of relying on daemon-based note synchronization.

Changes:

1. **Database migration** (027_session_transcript_storage.sql):
   - Add transcript_jsonl, transcript_ingested_at, transcript_file_path columns
   - Add indexes for efficient ingestion tracking

2. **Transcript parser utility** (src/utils/transcript-parser.ts):
   - parseTranscriptFile(): Parse JSONL line-by-line, handle corrupt lines
   - encodeWorkingDir(): Convert paths to Claude Code directory encoding
   - findOrphanedTranscripts(): Scan for stale transcript files
   - ingestTranscriptToDatabase(): Main ingestion function for Node.js

3. **Orphan recovery enhancement** (src/tools/sessions.ts):
   - sessionRecoverOrphaned() now tries transcript ingestion first
   - Finds most recently modified JSONL in project directory
   - Falls back to legacy notes.md recovery for backward compatibility
   - Properly handles path encoding (/ and . → -)

Benefits:
- No daemon needed for recovery (Phase 2 will remove LaunchAgent)
- Full transcript audit trail stored in database
- Immediate recovery capability for orphaned sessions
- Cleaner architecture (no markdown parsing complexity)
- Compatible with Claude Code's UUID-based session files

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-29 17:53:37 +02:00
Christian Gick
30650cf47f feat(CF-580): Add schema support and metadata tracking for session notes recovery
- Migration 025: Add 'abandoned' status to sessions CHECK constraint (fixes blocking issue)
- Migration 026: Add recovery metadata columns (recovered_from, recovered_at) to track note recovery source
- Update sessionRecoverOrphaned to recover notes from temp files when marking sessions abandoned
- Update notes-parser to track recovery source and timestamp for analytics

These changes complete Priority 3, 5 and part of Priority 1 for CF-572 Session Notes Loss fix.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-29 17:12:21 +02:00
Christian Gick
3e20a8ea3c feat(CF-524): Add project_archive MCP method
Implements complete project archival workflow:
- Migration 024: Add archival fields to projects table
- New project-archive.ts tool coordinating:
  * Tarball creation via shell
  * S3 upload with vault credentials
  * Database metadata tracking
  * Optional local deletion
  * Cleanup of temp files
- Registered in tool definitions and handlers

Replaces manual archival process used for Fireberries/CyprusPulse.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-27 20:45:56 +02:00
Christian Gick
a6d24ab86c fix(CF-518): Add ON UPDATE CASCADE to all projects foreign keys
Fixes task project rename command by adding ON UPDATE CASCADE to all foreign key constraints that reference projects(key).

Updated 10 FK constraints: task_sequences, epic_sequences, versions, epics, tasks, project_locks, project_archives, sessions, session_sequences, project_documentation.

Migration drops old constraints and adds new ones with both ON DELETE CASCADE and ON UPDATE CASCADE (except sessions which uses ON DELETE SET NULL).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-27 19:14:00 +02:00
Christian Gick
2b97a48614 feat: Add 'done' status with 7-day auto-close workflow
Added 'done' status to task lifecycle for verification period before completion.

**Changes:**
- Added 'done' to task_status enum (pending, open, in_progress, testing, blocked, done, completed)
- Added auto_close_at timestamp column for scheduling auto-close
- Created index for efficient cron job queries

**Workflow:**
1. Task marked 'done' → auto_close_at = NOW() + 7 days
2. Cron job runs daily to check tasks past auto_close_at
3. If no related issues → auto-close to 'completed'
4. If related issues → keep as 'done' (prevents premature closure)

**Lifecycle:**
  open → in_progress → done (7-day verification) → completed (auto-closed)

task:CF-454

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 14:57:46 +02:00
Christian Gick
cbe2e1068d feat: Add more link types to task system
New link types added:
- depends_on: Task depends on another task to complete first
- needs: Task needs another task (weaker dependency)
- implements: Task implements a feature/requirement
- fixes: Task fixes an issue identified in another task
- causes: Task causes/introduces issue in another task
- subtask_of: Task is a subtask of another (parent-child)

Preserves existing types: blocks, relates_to, duplicates

Changes:
- Migration 021 updates database constraint
- Updated TypeScript types and MCP tool schema
- Applied to production database

Implements CF-385

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-24 16:59:22 +02:00
Christian Gick
3da714e8bf fix: Add 'pending' status to task status enum
Resolves MCP error when trying to set status="pending" on tasks.

Changes:
- Migration 019: Add 'pending' to tasks.status CHECK constraint
- Update task_update tool schema to accept 'pending' status
- Update task_list tool schema to filter by 'pending' status

Status meanings:
- pending: Created, awaiting approval or dependencies
- open: Approved and ready to start
- in_progress: Currently being worked on
- testing: Implementation complete, being tested
- blocked: Stuck waiting for something
- completed: Done

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-20 18:04:05 +02:00
Christian Gick
7be5878d35 feat(CF-166): Add investigation workflow with auto-linking
Implements comprehensive investigation task management:

**Schema Changes (Migration 020):**
- Add 'investigation' task type to tasks table
- Add investigation_parent_id and auto_link_enabled columns to session_context
- Add auto_linked and linked_at columns to task_links for tracking
- Create indexes for efficient auto-linking queries

**Auto-Linking Logic:**
1. Investigation Parent Linking: Tasks auto-link to active investigation
2. Current Task Linking: Tasks link to current working task
3. Time-Based Linking: Tasks within 1 hour auto-link (fallback)

**New Tool:**
- task_investigate: Start investigation workflow, sets session context

**Documentation:**
- Add comprehensive investigation workflow guide to README
- Include examples and session context explanation

All checklist items completed:
✓ Investigation task type in schema
✓ Session context table enhancements
✓ Auto-linking implementation
✓ task_investigate command
✓ Documentation updates

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 19:15:25 +02:00
Christian Gick
caf9356aad feat(CF-282, CF-278): Add session context and task-session linking
**CF-282: Session Reference in Tasks**
- Add session_id column to tasks table (migration 019)
- Store session_id when creating tasks in taskAdd()
- Display session_id in taskShow() output
- Create index for performance
- Backfill existing tasks from task_activity

**CF-278: Enhanced Session Context**
- Updated session-start to load memories (via DB query)
- Performance: 2-3.6s (target <5s) ✓

Changes:
- migrations/019_add_session_id_to_tasks.sql: New migration
- src/tools/crud.ts: taskAdd and taskShow modifications

Requires: Claude Code restart to load new code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 18:48:43 +02:00
Christian Gick
16c579e6d5 Add deployment tracking schema (Migration 018)
Creates deployments and deployment_logs tables for tracking all
deployment types (Docker, MCP, iOS/macOS, services). Includes
deployment status, timing, git integration, and structured logging.

Also adds run-migration.mjs helper for running migrations against
PostgreSQL database.

Part of CF-290, completes CF-291.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 16:05:19 +02:00
Christian Gick
eb6b51837f Add Phase 3 migration: project documentation
- migrate-project-docs-batch.mjs: 60 files across 23 projects
- migrate-cf-docs-batch.mjs: ClaudeFramework documentation
- migrate-plans-batch.mjs: Session plan files
- 017_fix_archives_embedding_dimension.sql: Fix vector dimension
- run-migration.js: Node.js migration runner utility

Total migrated: 332 files, 8.85MB with semantic embeddings

Fixes: CF-277
2026-01-19 14:09:03 +02:00
Christian Gick
1231835e02 Add project_archives table and MCP tools (CF-264)
- Created migration 009: project_archives table with semantic search
- Implemented archives.ts: archiveAdd, archiveSearch, archiveList, archiveGet
- Registered archive tools in index.ts and tools/index.ts
- Archive types: session, research, audit, investigation, completed, migration
- Uses project_key (TEXT) FK to projects table
- Tested: archive_add and archive_list working correctly

Replaces filesystem archives with database-backed storage.
Eliminates context pollution from Glob/Grep operations.

Task: CF-264
Session: session_20260119111342_66de546b

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 11:38:48 +02:00
Christian Gick
3745a13eaf Add session documentation system (migration + MCP tools)
Phase 1-2 complete: Database schema + 9 MCP tools for session docs

Database Changes (migration 016):
- session_notes table (accomplishments, decisions, gotchas, etc.)
- session_plans table (plan mode plans with lifecycle tracking)
- project_documentation table (persistent project docs)
- sessions.documentation column (auto-generated markdown)
- HNSW indexes for semantic search across all doc types

MCP Tools Added (session-docs.ts):
1. session_note_add - Add structured notes to session
2. session_notes_list - List notes by type
3. session_plan_save - Save plan with embedding
4. session_plan_update_status - Track plan lifecycle
5. session_plan_list - List session plans
6. project_doc_upsert - Create/update project docs
7. project_doc_get - Get specific doc by type
8. project_doc_list - List all project docs
9. session_documentation_generate - Auto-generate markdown

Replaces: CLAUDE.md files, ~/.claude/plans/ directory

Next: Update session-start/end scripts for temp file management

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 10:13:57 +02:00
Christian Gick
afce0bd3e5 Migrate embeddings from Gemini to local mxbai-embed-large
Switch from external Gemini API (3072 dims, $0.15/1M tokens) to local
Ollama mxbai-embed-large (1024 dims, free) for cost savings and HNSW
index support.

Changes:
- Updated embeddings.ts: model 'mxbai-embed-large', API URL fixed
- Updated migration 015: vector(1024) with HNSW index
- Regenerated 268 tool_docs embeddings with new model

Benefits:
- Free embeddings (no API costs)
- HNSW index enabled (1024 < 2000 dim limit)
- Fast similarity search (O(log n) vs O(n))
- No external API dependency

Trade-offs:
- 5% quality loss (MTEB 64.68 vs ~70 Gemini)
- Uses local compute (1.2GB RAM, <1s per embedding)

Task: CF-251

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 09:40:02 +02:00
Christian Gick
0aa10d3003 Add tool documentation MCP tools for queryable TOOLS.md replacement
- Created tool_docs table with pgvector support (migration 015)
- Added 5 MCP tools: tool_doc_add, tool_doc_search, tool_doc_get, tool_doc_list, tool_doc_export
- Imported 268 tools from TOOLS.md to database
- Enables semantic search for tool documentation (when embeddings available)
- Reduces context pollution (TOOLS.md is 11,769 lines, now queryable)

Task: CF-249

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 09:15:34 +02:00
Christian Gick
90bb7e94f0 Add session-aware task context and auto-linking (CF-166 Phase 2)
Enhancements:

1. Session Context Table
   - Migration 014: session_context table
   - Tracks current working task per session
   - Auto-updated on task status changes

2. Auto-Linking to Current Working Task
   - When task status → in_progress: sets as current_task_id
   - When task status → completed: clears current_task_id
   - New tasks auto-link to current working task with 'relates_to'
   - Shows auto-link message during task creation

3. Session ID Resolution
   - Fixed path: ~/.cache/session-memory/current_session
   - Falls back to environment variable CLAUDE_SESSION_ID
   - Generates timestamp-based ID if unavailable

Example Flow:
```
1. task update CF-123 --status in_progress
   → Sets CF-123 as current working task

2. task add --title "Related work"
   → Created: CF-124
   🔗 Auto-linked to: CF-123 (current working task)

3. task update CF-123 --status completed
   → Clears current working task
```

Files Changed:
- migrations/014_session_context.sql (new, 33 lines)
- src/tools/crud.ts (auto-linking logic, session context management)

Benefits:
- Zero manual linking for related work
- Session context preserved automatically
- Investigation workflows auto-organized
- Retroactive work tracking prevented

Note: Requires MCP server restart to take effect.

Remaining CF-166 Features (Phase 3):
- task investigate command
- Investigation workflow helper
- Task creation reminders

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-17 08:44:19 +02:00
Christian Gick
f7f9cfe3d8 Add investigation type and duplicate detection (CF-166 Phase 1)
Enhancements:

1. Investigation Task Type
   - Added 'investigation' to task type enum
   - Migration 013: Updated PostgreSQL constraint
   - Updated TypeScript schemas (task_add, task_list, task_update)
   - Enables tracking research/debugging workflows

2. Duplicate Detection
   - Enhanced task_add to check for similar tasks before creating
   - Uses pgvector semantic search (>70% similarity threshold)
   - Warns about potential duplicates with similarity scores
   - Suggests linking command for related tasks
   - Gracefully handles when embeddings unavailable

Example Output:
```
Created: CF-123
  Title: Fix API rate limiting
  Type: task
  Priority: P2
  Project: CF

⚠️  Similar tasks found:
  - CF-120: Add rate limit monitoring (85% match, in_progress)
  - CF-115: Implement API throttling (72% match, open)

Consider linking with: task link <from> <to> relates_to
```

Benefits:
- Prevents accidental duplicate tasks
- Surfaces related work automatically
- Reduces manual task linking
- Investigation type for research workflows

Files Changed:
- migrations/013_investigation_type.sql (new)
- src/tools/crud.ts (duplicate detection logic)
- src/tools/index.ts (investigation type in enums)

Remaining CF-166 Features (Phase 2):
- Session-aware task context
- Automatic linking within session
- Investigation workflow helper
- Task creation reminders

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-17 08:38:18 +02:00
Christian Gick
00de7f1299 Add database migrations for session context system
Phase 1: Database Schema Implementation
- Migration 010: Sessions table with bulletproof auto-incrementing
  - Unique session IDs across all projects
  - Per-project session numbers (1, 2, 3, ...)
  - Atomic sequence generation (no race conditions)
  - Session-task and session-commit linking
  - Semantic search with pgvector HNSW indexes

- Migration 011: Memories table with enhanced schema
  - Migrated existing session_memories to memories
  - Added session_id and task_id foreign keys
  - Renamed columns for consistency
  - HNSW indexing for semantic search

- Migration 012: Builds table for CI/CD tracking
  - Links builds to sessions and versions
  - Tracks build status, timing, and metadata

All migrations tested and verified on agiliton database.

Related: CF-167 (Fix shared session-summary.md file conflict)
2026-01-17 07:41:03 +02:00
Christian Gick
4fb557c624 feat: Add impact analysis for component dependency tracking
- New tables: components, component_dependencies, component_files,
  verification_checks, change_impacts, impact_analysis_runs
- 8 new MCP tools: component_register, component_list,
  component_add_dependency, component_add_file, component_add_check,
  impact_analysis, impact_learn, component_graph
- Seed data: 17 components, 9 dependencies, 12 file patterns, 5 checks
- Historical impacts from session 397 issues recorded

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 07:20:00 +02:00
Christian Gick
5015b1416f feat: Add version management, session tracking, and commit linking
Phase 1: Version Management
- Migration 006: Add git_tag, git_sha columns to versions
- New tools: version_add, version_list, version_show, version_update,
  version_release, version_assign_task
- Links versions to git tags for release tracking

Phase 2: Session/Task Activity Tracking
- Migration 007: Create task_activity table
- Track task changes per session (created, updated, status_change, closed)
- Session ID from env/cache file (usage-stats format)
- New tool: session_tasks to query tasks by session

Phase 3: Commit-Task Linking
- Migration 008: Create task_commits junction table
- New tools: task_commit_add, task_commit_remove, task_commits_list,
  task_link_commits (batch parsing)
- Stores SHA references only (Gitea MCP owns full data)
- Commits shown in task_show output

17 new MCP tools total. All migrations applied to docker-host postgres.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 10:28:21 +02:00
Christian Gick
e12cccf718 fix: Add missing updated_at column to epics table
epic_close was failing with "column updated_at does not exist".
Migration adds the column with default NOW() and backfills
existing rows from created_at.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 09:48:08 +02:00
Christian Gick
837fb8060c feat: Add project lock mechanism for session exclusivity
New MCP tools:
- project_lock: Lock a project for exclusive session access
- project_unlock: Release a project lock
- project_lock_status: Check lock status for project(s)

Features:
- Automatic lock expiration (default 2h)
- Session ownership verification
- Force unlock option for emergencies
- Lock extension on re-lock by same session

Migration 004: project_locks table with expiry tracking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 09:22:26 +02:00
Christian Gick
fe2cd82587 fix: Add embedding column to epics table
Migration 003: enables semantic search for epics
- ALTER TABLE epics ADD COLUMN embedding vector(1024)
- HNSW index for similarity search

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 09:16:37 +02:00
Christian Gick
29cd754e39 fix: Add missing 001 base schema migration
Creates core tables for task-mcp:
- projects, task_sequences, epic_sequences
- tasks with vector(1024) embedding for semantic search
- epics, versions, task_checklist, task_links
- HNSW index for fast vector similarity search

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 17:21:40 +02:00
Christian Gick
df3e557c87 feat: Add task_delegations schema (Session 374)
- task_delegations table for tracking delegation metadata per task
- task_learning_effectiveness table for per-task learning tracking
- Indexes for efficient querying by task_id, status, backend

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 10:32:10 +02:00