Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,149 changes: 1,149 additions & 0 deletions .claude/PRPs/issues/completed/issue-1572.md

Large diffs are not rendered by default.

731 changes: 731 additions & 0 deletions .claude/PRPs/issues/issue-1566.md

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/adapters/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,22 @@ export class GitHubAdapter implements WorkAdapter {
updates.body = request.description;
}

if (request.labels !== undefined) {
// Handle agent field updates by managing agent:* labels
if (request.agent !== undefined) {
// Fetch current issue to get existing labels
const currentIssue = await this.apiClient.getIssue(issueNumber);
const currentLabels = currentIssue.labels.map(l => l.name);

// Remove all agent:* labels
const labelsWithoutAgent = currentLabels.filter(name => !name.startsWith('agent:'));

// Add new agent label if provided (clearing if null/undefined)
if (request.agent) {
labelsWithoutAgent.push(`agent:${request.agent}`);
}

updates.labels = labelsWithoutAgent;
} else if (request.labels !== undefined) {
updates.labels = [...request.labels];
}

Expand Down
18 changes: 17 additions & 1 deletion src/adapters/github/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import { GitHubIssue } from './types.js';
* Converts GitHub Issue to WorkItem
*/
export function githubIssueToWorkItem(issue: GitHubIssue): WorkItem {
// Extract agent from agent:* label pattern
const agentLabel = issue.labels.find(label => label.name.startsWith('agent:'));
const agent = agentLabel ? agentLabel.name.substring(6) : undefined;

// Filter out agent:* labels from the labels array
const filteredLabels = issue.labels
.map(label => label.name)
.filter(name => !name.startsWith('agent:'));

return {
id: issue.number.toString(),
kind: 'task', // Default kind, could be enhanced with label mapping
Expand All @@ -17,7 +26,8 @@ export function githubIssueToWorkItem(issue: GitHubIssue): WorkItem {
state: issue.state === 'open' ? 'new' : 'closed',
priority: 'medium', // Default priority, could be enhanced with label mapping
assignee: issue.assignee?.login,
labels: [...issue.labels.map(label => label.name)], // Convert readonly to mutable
agent,
labels: [...filteredLabels], // Convert readonly to mutable
createdAt: issue.created_at,
updatedAt: issue.updated_at,
closedAt: issue.closed_at || undefined,
Expand Down Expand Up @@ -45,6 +55,12 @@ export function workItemToGitHubIssue(request: CreateWorkItemRequest): {
result.labels = [...request.labels];
}

if (request.agent) {
// Add agent:* label
result.labels = result.labels || [];
result.labels.push(`agent:${request.agent}`);
}

if (request.assignee) {
result.assignees = [request.assignee];
}
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/local-fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class LocalFsAdapter implements WorkAdapter {
state: 'new',
priority: request.priority || 'medium',
assignee: request.assignee,
agent: request.agent,
labels: request.labels || [],
createdAt: now,
updatedAt: now,
Expand Down Expand Up @@ -85,6 +86,7 @@ export class LocalFsAdapter implements WorkAdapter {
description: request.description ?? existing.description,
priority: request.priority ?? existing.priority,
assignee: request.assignee ?? existing.assignee,
agent: request.agent ?? existing.agent,
labels: request.labels ?? existing.labels,
updatedAt: now,
};
Expand Down
1 change: 1 addition & 0 deletions src/adapters/local-fs/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function saveWorkItem(
state: workItem.state,
priority: workItem.priority,
assignee: workItem.assignee,
agent: workItem.agent,
labels: workItem.labels,
createdAt: workItem.createdAt,
updatedAt: workItem.updatedAt,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default class Create extends BaseCommand {
char: 'a',
description: 'assignee username',
}),
agent: Flags.string({
description: 'agent identifier',
}),
labels: Flags.string({
char: 'l',
description: 'comma-separated labels',
Expand All @@ -63,6 +66,7 @@ export default class Create extends BaseCommand {
priority: flags.priority as Priority,
description: flags.description,
assignee: flags.assignee,
agent: flags.agent,
labels,
});

Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class Get extends BaseCommand {
this.log(`State: ${workItem.state}`);
this.log(`Priority: ${workItem.priority}`);
this.log(`Assignee: ${workItem.assignee || 'Unassigned'}`);
this.log(`Agent: ${workItem.agent || 'None'}`);
this.log(`Labels: ${workItem.labels.join(', ') || 'None'}`);
this.log(`Created: ${workItem.createdAt}`);
this.log(`Updated: ${workItem.updatedAt}`);
Expand Down
5 changes: 5 additions & 0 deletions src/cli/commands/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default class Set extends BaseCommand {
assignee: Flags.string({
description: 'update work item assignee',
}),
agent: Flags.string({
description: 'update work item agent',
}),
labels: Flags.string({
description: 'update work item labels (comma-separated)',
}),
Expand All @@ -53,12 +56,14 @@ export default class Set extends BaseCommand {
description?: string;
priority?: Priority;
assignee?: string;
agent?: string;
labels?: string[];
} = {};
if (flags.title) updateRequest.title = flags.title;
if (flags.description) updateRequest.description = flags.description;
if (flags.priority) updateRequest.priority = flags.priority as Priority;
if (flags.assignee) updateRequest.assignee = flags.assignee;
if (flags.agent) updateRequest.agent = flags.agent;
if (flags.labels)
updateRequest.labels = flags.labels.split(',').map(l => l.trim());

Expand Down
5 changes: 4 additions & 1 deletion src/cli/commands/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Unset extends BaseCommand {
field: Args.string({
description: 'field to clear',
required: true,
options: ['assignee', 'description'],
options: ['assignee', 'agent', 'description'],
}),
};

Expand All @@ -33,11 +33,14 @@ export default class Unset extends BaseCommand {
// Build update request to clear the field
const updateRequest: {
assignee?: string | undefined;
agent?: string | undefined;
description?: string | undefined;
} = {};

if (args.field === 'assignee') {
updateRequest.assignee = undefined;
} else if (args.field === 'agent') {
updateRequest.agent = undefined;
} else if (args.field === 'description') {
updateRequest.description = undefined;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ function getFieldValue(item: WorkItem, field: string): string | number | Date {
}
case 'assignee':
return item.assignee || '';
case 'agent':
return item.agent || '';
case 'createdAt':
return item.createdAt; // Return as string, conversion handled in evaluateCondition
case 'updatedAt':
Expand Down Expand Up @@ -632,6 +634,8 @@ function filterWorkItems(
return item.priority === value;
case 'assignee':
return item.assignee === value;
case 'agent':
return item.agent === value;
case 'id':
return item.id === value;
default:
Expand Down
3 changes: 3 additions & 0 deletions src/types/work-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface WorkItem {
readonly state: WorkItemState;
readonly priority: Priority;
readonly assignee?: string | undefined;
readonly agent?: string | undefined;
readonly labels: readonly string[];
readonly createdAt: string;
readonly updatedAt: string;
Expand All @@ -43,6 +44,7 @@ export interface CreateWorkItemRequest {
readonly description?: string | undefined;
readonly priority?: Priority | undefined;
readonly assignee?: string | undefined;
readonly agent?: string | undefined;
readonly labels?: readonly string[] | undefined;
}

Expand All @@ -51,5 +53,6 @@ export interface UpdateWorkItemRequest {
readonly description?: string | undefined;
readonly priority?: Priority | undefined;
readonly assignee?: string | undefined;
readonly agent?: string | undefined;
readonly labels?: readonly string[] | undefined;
}
67 changes: 67 additions & 0 deletions tests/unit/core/query-focused.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,71 @@ describe('Query System', () => {
expect(result).toHaveLength(0);
});
});

describe('Agent field support', () => {
const itemsWithAgent = [
{
id: 'TASK-001',
kind: 'task' as const,
title: 'Task 1',
state: 'new' as const,
priority: 'high' as const,
assignee: 'human',
agent: 'code-reviewer',
labels: [] as readonly string[],
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
},
{
id: 'TASK-002',
kind: 'task' as const,
title: 'Task 2',
state: 'new' as const,
priority: 'medium' as const,
assignee: 'human2',
agent: undefined,
labels: [] as readonly string[],
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
},
{
id: 'TASK-003',
kind: 'task' as const,
title: 'Task 3',
state: 'active' as const,
priority: 'high' as const,
assignee: 'human',
agent: 'test-agent',
labels: [] as readonly string[],
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
},
];

it('should filter by agent', () => {
const query = parseQuery('where agent=code-reviewer');
const result = executeQuery(itemsWithAgent, query);

expect(result).toHaveLength(1);
expect(result[0].id).toBe('TASK-001');
expect(result[0].agent).toBe('code-reviewer');
});

it('should combine agent and assignee filters', () => {
const query = parseQuery('where agent=code-reviewer AND assignee=human');
const result = executeQuery(itemsWithAgent, query);

expect(result).toHaveLength(1);
expect(result[0].id).toBe('TASK-001');
});

it('should filter by multiple agents using OR', () => {
const query = parseQuery('where agent=code-reviewer OR agent=test-agent');
const result = executeQuery(itemsWithAgent, query);

expect(result).toHaveLength(2);
expect(result[0].agent).toBe('code-reviewer');
expect(result[1].agent).toBe('test-agent');
});
});
});
2 changes: 2 additions & 0 deletions tests/unit/types/work-item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('WorkItem Types', () => {
state: 'new',
priority: 'medium',
assignee: 'testuser',
agent: 'test-agent',
labels: ['test', 'unit'],
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
Expand All @@ -55,6 +56,7 @@ describe('WorkItem Types', () => {
expect(workItem.title).toBe('Test task');
expect(workItem.state).toBe('new');
expect(workItem.priority).toBe('medium');
expect(workItem.agent).toBe('test-agent');
expect(workItem.labels).toEqual(['test', 'unit']);
});
});