fix: Auto-detect project from CWD in task_list and epic_list

Previously these functions only filtered by project when explicitly
passed. Now they auto-detect from CWD using detectProjectFromCwd(),
matching the behavior of project_context.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-01-12 08:12:49 +02:00
parent 149ebdb95f
commit d474c1c368
2 changed files with 16 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
// CRUD operations for tasks // CRUD operations for tasks
import { query, queryOne, execute, getNextTaskId, getProjectKey } from '../db.js'; import { query, queryOne, execute, getNextTaskId, getProjectKey, detectProjectFromCwd } from '../db.js';
import { getEmbedding, formatEmbedding } from '../embeddings.js'; import { getEmbedding, formatEmbedding } from '../embeddings.js';
import type { Task, ChecklistItem, TaskLink } from '../types.js'; import type { Task, ChecklistItem, TaskLink } from '../types.js';
import { getRecentDelegations } from './delegations.js'; import { getRecentDelegations } from './delegations.js';
@@ -119,6 +119,7 @@ export async function taskAdd(args: TaskAddArgs): Promise<string> {
/** /**
* List tasks with filters * List tasks with filters
* Auto-detects project from CWD if not explicitly provided
*/ */
export async function taskList(args: TaskListArgs): Promise<string> { export async function taskList(args: TaskListArgs): Promise<string> {
const { project, status, type, priority, limit = 20 } = args; const { project, status, type, priority, limit = 20 } = args;
@@ -127,8 +128,10 @@ export async function taskList(args: TaskListArgs): Promise<string> {
const params: unknown[] = []; const params: unknown[] = [];
let paramIndex = 1; let paramIndex = 1;
if (project) { // Auto-detect project from CWD if not explicitly provided
const projectKey = await getProjectKey(project); const effectiveProject = project || detectProjectFromCwd();
if (effectiveProject) {
const projectKey = await getProjectKey(effectiveProject);
whereClause += ` AND project = $${paramIndex++}`; whereClause += ` AND project = $${paramIndex++}`;
params.push(projectKey); params.push(projectKey);
} }
@@ -159,7 +162,7 @@ export async function taskList(args: TaskListArgs): Promise<string> {
); );
if (tasks.length === 0) { if (tasks.length === 0) {
return `No tasks found${project ? ` for project ${project}` : ''}`; return `No tasks found${effectiveProject ? ` for project ${effectiveProject}` : ''}`;
} }
const lines = tasks.map(t => { const lines = tasks.map(t => {
@@ -168,7 +171,7 @@ export async function taskList(args: TaskListArgs): Promise<string> {
return `${statusIcon} ${t.priority} ${t.id}: ${t.title}${typeLabel}`; return `${statusIcon} ${t.priority} ${t.id}: ${t.title}${typeLabel}`;
}); });
return `Tasks${project ? ` (${project})` : ''}:\n\n${lines.join('\n')}`; return `Tasks${effectiveProject ? ` (${effectiveProject})` : ''}:\n\n${lines.join('\n')}`;
} }
/** /**

View File

@@ -1,6 +1,6 @@
// Epic operations for task management // Epic operations for task management
import { query, queryOne, execute, getProjectKey } from '../db.js'; import { query, queryOne, execute, getProjectKey, detectProjectFromCwd } from '../db.js';
import { getEmbedding, formatEmbedding } from '../embeddings.js'; import { getEmbedding, formatEmbedding } from '../embeddings.js';
import type { Epic, Task } from '../types.js'; import type { Epic, Task } from '../types.js';
@@ -71,6 +71,7 @@ export async function epicAdd(args: EpicAddArgs): Promise<string> {
/** /**
* List epics with filters * List epics with filters
* Auto-detects project from CWD if not explicitly provided
*/ */
export async function epicList(args: EpicListArgs): Promise<string> { export async function epicList(args: EpicListArgs): Promise<string> {
const { project, status, limit = 20 } = args; const { project, status, limit = 20 } = args;
@@ -79,8 +80,10 @@ export async function epicList(args: EpicListArgs): Promise<string> {
const params: unknown[] = []; const params: unknown[] = [];
let paramIndex = 1; let paramIndex = 1;
if (project) { // Auto-detect project from CWD if not explicitly provided
const projectKey = await getProjectKey(project); const effectiveProject = project || detectProjectFromCwd();
if (effectiveProject) {
const projectKey = await getProjectKey(effectiveProject);
whereClause += ` AND e.project = $${paramIndex++}`; whereClause += ` AND e.project = $${paramIndex++}`;
params.push(projectKey); params.push(projectKey);
} }
@@ -107,7 +110,7 @@ export async function epicList(args: EpicListArgs): Promise<string> {
); );
if (epics.length === 0) { if (epics.length === 0) {
return `No epics found${project ? ` for project ${project}` : ''}`; return `No epics found${effectiveProject ? ` for project ${effectiveProject}` : ''}`;
} }
const lines = epics.map(e => { const lines = epics.map(e => {
@@ -116,7 +119,7 @@ export async function epicList(args: EpicListArgs): Promise<string> {
return `${statusIcon} ${e.id}: ${e.title}${progress}`; return `${statusIcon} ${e.id}: ${e.title}${progress}`;
}); });
return `Epics${project ? ` (${project})` : ''}:\n\n${lines.join('\n')}`; return `Epics${effectiveProject ? ` (${effectiveProject})` : ''}:\n\n${lines.join('\n')}`;
} }
/** /**