@task-mcp/shared 1.0.4 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/algorithms/critical-path.d.ts.map +1 -1
- package/dist/algorithms/critical-path.js +50 -26
- package/dist/algorithms/critical-path.js.map +1 -1
- package/dist/algorithms/dependency-integrity.d.ts +73 -0
- package/dist/algorithms/dependency-integrity.d.ts.map +1 -0
- package/dist/algorithms/dependency-integrity.js +189 -0
- package/dist/algorithms/dependency-integrity.js.map +1 -0
- package/dist/algorithms/index.d.ts +2 -0
- package/dist/algorithms/index.d.ts.map +1 -1
- package/dist/algorithms/index.js +2 -0
- package/dist/algorithms/index.js.map +1 -1
- package/dist/algorithms/tech-analysis.d.ts +106 -0
- package/dist/algorithms/tech-analysis.d.ts.map +1 -0
- package/dist/algorithms/tech-analysis.js +296 -0
- package/dist/algorithms/tech-analysis.js.map +1 -0
- package/dist/algorithms/tech-analysis.test.d.ts +2 -0
- package/dist/algorithms/tech-analysis.test.d.ts.map +1 -0
- package/dist/algorithms/tech-analysis.test.js +338 -0
- package/dist/algorithms/tech-analysis.test.js.map +1 -0
- package/dist/algorithms/topological-sort.d.ts.map +1 -1
- package/dist/algorithms/topological-sort.js +60 -8
- package/dist/algorithms/topological-sort.js.map +1 -1
- package/dist/schemas/inbox.d.ts +55 -0
- package/dist/schemas/inbox.d.ts.map +1 -0
- package/dist/schemas/inbox.js +25 -0
- package/dist/schemas/inbox.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -1
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +9 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/project.d.ts +154 -41
- package/dist/schemas/project.d.ts.map +1 -1
- package/dist/schemas/project.js +38 -33
- package/dist/schemas/project.js.map +1 -1
- package/dist/schemas/response-format.d.ts +80 -0
- package/dist/schemas/response-format.d.ts.map +1 -0
- package/dist/schemas/response-format.js +17 -0
- package/dist/schemas/response-format.js.map +1 -0
- package/dist/schemas/task.d.ts +592 -94
- package/dist/schemas/task.d.ts.map +1 -1
- package/dist/schemas/task.js +124 -64
- package/dist/schemas/task.js.map +1 -1
- package/dist/schemas/view.d.ts +128 -37
- package/dist/schemas/view.d.ts.map +1 -1
- package/dist/schemas/view.js +38 -24
- package/dist/schemas/view.js.map +1 -1
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/date.js +17 -2
- package/dist/utils/date.js.map +1 -1
- package/dist/utils/hierarchy.d.ts +75 -0
- package/dist/utils/hierarchy.d.ts.map +1 -0
- package/dist/utils/hierarchy.js +179 -0
- package/dist/utils/hierarchy.js.map +1 -0
- package/dist/utils/id.d.ts +51 -1
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +124 -4
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/id.test.d.ts +2 -0
- package/dist/utils/id.test.d.ts.map +1 -0
- package/dist/utils/id.test.js +228 -0
- package/dist/utils/id.test.js.map +1 -0
- package/dist/utils/index.d.ts +4 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/natural-language.d.ts +45 -0
- package/dist/utils/natural-language.d.ts.map +1 -1
- package/dist/utils/natural-language.js +86 -0
- package/dist/utils/natural-language.js.map +1 -1
- package/dist/utils/projection.d.ts +65 -0
- package/dist/utils/projection.d.ts.map +1 -0
- package/dist/utils/projection.js +181 -0
- package/dist/utils/projection.js.map +1 -0
- package/dist/utils/projection.test.d.ts +2 -0
- package/dist/utils/projection.test.d.ts.map +1 -0
- package/dist/utils/projection.test.js +400 -0
- package/dist/utils/projection.test.js.map +1 -0
- package/package.json +2 -2
- package/src/algorithms/critical-path.ts +56 -24
- package/src/algorithms/dependency-integrity.ts +270 -0
- package/src/algorithms/index.ts +28 -0
- package/src/algorithms/tech-analysis.test.ts +413 -0
- package/src/algorithms/tech-analysis.ts +412 -0
- package/src/algorithms/topological-sort.ts +66 -9
- package/src/schemas/inbox.ts +32 -0
- package/src/schemas/index.ts +31 -0
- package/src/schemas/project.ts +43 -40
- package/src/schemas/response-format.ts +108 -0
- package/src/schemas/task.ts +145 -77
- package/src/schemas/view.ts +43 -33
- package/src/utils/date.ts +18 -2
- package/src/utils/hierarchy.ts +224 -0
- package/src/utils/id.test.ts +281 -0
- package/src/utils/id.ts +139 -4
- package/src/utils/index.ts +46 -2
- package/src/utils/natural-language.ts +113 -0
- package/src/utils/projection.test.ts +505 -0
- package/src/utils/projection.ts +251 -0
|
@@ -1,6 +1,118 @@
|
|
|
1
1
|
import type { Priority, TaskCreateInput } from "../schemas/task.js";
|
|
2
|
+
import type { InboxCreateInput } from "../schemas/inbox.js";
|
|
2
3
|
import { parseRelativeDate, formatDate } from "./date.js";
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Maximum allowed input length for natural language parsing.
|
|
7
|
+
* Prevents DoS attacks from extremely long input strings.
|
|
8
|
+
*/
|
|
9
|
+
export const MAX_INPUT_LENGTH = 1000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when input validation fails
|
|
13
|
+
*/
|
|
14
|
+
export class InputValidationError extends Error {
|
|
15
|
+
constructor(message: string) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "InputValidationError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Validates input string length
|
|
23
|
+
* @throws {InputValidationError} if input exceeds MAX_INPUT_LENGTH
|
|
24
|
+
*/
|
|
25
|
+
function validateInputLength(input: string): void {
|
|
26
|
+
if (input.length > MAX_INPUT_LENGTH) {
|
|
27
|
+
throw new InputValidationError(
|
|
28
|
+
`Input exceeds maximum length of ${MAX_INPUT_LENGTH} characters (received ${input.length})`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Target type for parsed input
|
|
35
|
+
*/
|
|
36
|
+
export type ParseTarget = "task" | "inbox";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extended parse result with target information
|
|
40
|
+
*/
|
|
41
|
+
export interface ParsedInput {
|
|
42
|
+
target: ParseTarget;
|
|
43
|
+
task?: TaskCreateInput;
|
|
44
|
+
inbox?: InboxCreateInput;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parse natural language input with target detection
|
|
49
|
+
*
|
|
50
|
+
* Target keywords:
|
|
51
|
+
* - >>inbox, >>메모, >>아이디어 → capture to inbox
|
|
52
|
+
* - >>task, >>태스크 (default) → create task
|
|
53
|
+
*
|
|
54
|
+
* Examples:
|
|
55
|
+
* - "API 리팩토링 아이디어 >>inbox #backend"
|
|
56
|
+
* - "Review PR tomorrow #dev !high" (default: task)
|
|
57
|
+
* - "새 기능 구상 >>메모"
|
|
58
|
+
*/
|
|
59
|
+
export function parseInput(input: string): ParsedInput {
|
|
60
|
+
validateInputLength(input);
|
|
61
|
+
let remaining = input.trim();
|
|
62
|
+
let target: ParseTarget = "task";
|
|
63
|
+
|
|
64
|
+
// Detect target keywords (>>inbox, >>task, >>메모, >>아이디어, >>태스크)
|
|
65
|
+
const targetMatch = remaining.match(/>>(inbox|task|메모|아이디어|태스크)/i);
|
|
66
|
+
if (targetMatch) {
|
|
67
|
+
const keyword = targetMatch[1]!.toLowerCase();
|
|
68
|
+
if (keyword === "inbox" || keyword === "메모" || keyword === "아이디어") {
|
|
69
|
+
target = "inbox";
|
|
70
|
+
} else {
|
|
71
|
+
target = "task";
|
|
72
|
+
}
|
|
73
|
+
remaining = remaining.replace(targetMatch[0], "").trim();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (target === "inbox") {
|
|
77
|
+
return {
|
|
78
|
+
target: "inbox",
|
|
79
|
+
inbox: parseInboxInput(remaining),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
target: "task",
|
|
85
|
+
task: parseTaskInput(remaining),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Parse natural language inbox input
|
|
91
|
+
*
|
|
92
|
+
* Examples:
|
|
93
|
+
* - "GraphQL 도입 검토 #backend #연구"
|
|
94
|
+
* - "성능 개선 아이디어 #performance"
|
|
95
|
+
*/
|
|
96
|
+
export function parseInboxInput(input: string): InboxCreateInput {
|
|
97
|
+
validateInputLength(input);
|
|
98
|
+
let remaining = input.trim();
|
|
99
|
+
const result: InboxCreateInput = { content: "" };
|
|
100
|
+
|
|
101
|
+
// Extract tags (#dev, #backend, #개발)
|
|
102
|
+
const tagMatches = remaining.match(/#([\p{L}\p{N}_]+)/gu);
|
|
103
|
+
if (tagMatches) {
|
|
104
|
+
result.tags = tagMatches.map((m) => m.slice(1));
|
|
105
|
+
for (const match of tagMatches) {
|
|
106
|
+
remaining = remaining.replace(match, "").trim();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Clean up and set content
|
|
111
|
+
result.content = remaining.replace(/\s+/g, " ").trim();
|
|
112
|
+
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
4
116
|
/**
|
|
5
117
|
* Parse natural language task input
|
|
6
118
|
*
|
|
@@ -11,6 +123,7 @@ import { parseRelativeDate, formatDate } from "./date.js";
|
|
|
11
123
|
* - "Write tests every Monday #testing"
|
|
12
124
|
*/
|
|
13
125
|
export function parseTaskInput(input: string): TaskCreateInput {
|
|
126
|
+
validateInputLength(input);
|
|
14
127
|
let remaining = input.trim();
|
|
15
128
|
const result: TaskCreateInput = { title: "" };
|
|
16
129
|
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
projectTask,
|
|
4
|
+
projectTasks,
|
|
5
|
+
projectTasksPaginated,
|
|
6
|
+
projectProject,
|
|
7
|
+
projectProjects,
|
|
8
|
+
projectInboxItem,
|
|
9
|
+
projectInboxItems,
|
|
10
|
+
formatResponse,
|
|
11
|
+
applyPagination,
|
|
12
|
+
truncate,
|
|
13
|
+
summarizeList,
|
|
14
|
+
} from "./projection.js";
|
|
15
|
+
import type { Task } from "../schemas/task.js";
|
|
16
|
+
import type { Project } from "../schemas/project.js";
|
|
17
|
+
import type { InboxItem } from "../schemas/inbox.js";
|
|
18
|
+
|
|
19
|
+
// Test fixtures
|
|
20
|
+
const createTask = (overrides: Partial<Task> = {}): Task => {
|
|
21
|
+
const base: Task = {
|
|
22
|
+
id: "task-1",
|
|
23
|
+
projectId: "project-1",
|
|
24
|
+
title: "Test Task",
|
|
25
|
+
status: "pending",
|
|
26
|
+
priority: "medium",
|
|
27
|
+
createdAt: "2025-01-01T00:00:00.000Z",
|
|
28
|
+
updatedAt: "2025-01-01T00:00:00.000Z",
|
|
29
|
+
dueDate: "2025-01-15",
|
|
30
|
+
tags: ["test", "unit"],
|
|
31
|
+
contexts: ["work"],
|
|
32
|
+
parentId: "parent-1",
|
|
33
|
+
description: "This is a test task with a long description",
|
|
34
|
+
estimate: { expected: 60, optimistic: 30, pessimistic: 120 },
|
|
35
|
+
dependencies: [{ taskId: "dep-1", type: "blocked_by" }],
|
|
36
|
+
};
|
|
37
|
+
return { ...base, ...overrides };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const createProject = (overrides: Partial<Project> = {}): Project => ({
|
|
41
|
+
id: "proj-1",
|
|
42
|
+
name: "Test Project",
|
|
43
|
+
status: "active",
|
|
44
|
+
createdAt: "2025-01-01T00:00:00.000Z",
|
|
45
|
+
updatedAt: "2025-01-01T00:00:00.000Z",
|
|
46
|
+
completionPercentage: 50,
|
|
47
|
+
description: "A test project",
|
|
48
|
+
totalTasks: 10,
|
|
49
|
+
completedTasks: 5,
|
|
50
|
+
...overrides,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const createInboxItem = (overrides: Partial<InboxItem> = {}): InboxItem => ({
|
|
54
|
+
id: "inbox-1",
|
|
55
|
+
content: "Quick idea for later",
|
|
56
|
+
status: "pending",
|
|
57
|
+
capturedAt: "2025-01-01T00:00:00.000Z",
|
|
58
|
+
tags: ["idea"],
|
|
59
|
+
source: "cli",
|
|
60
|
+
...overrides,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("projectTask", () => {
|
|
64
|
+
test("concise format returns only 4 essential fields", () => {
|
|
65
|
+
const task = createTask();
|
|
66
|
+
const result = projectTask(task, "concise");
|
|
67
|
+
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
id: "task-1",
|
|
70
|
+
title: "Test Task",
|
|
71
|
+
status: "pending",
|
|
72
|
+
priority: "medium",
|
|
73
|
+
});
|
|
74
|
+
expect(Object.keys(result)).toHaveLength(4);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("standard format returns 8 common fields", () => {
|
|
78
|
+
const task = createTask();
|
|
79
|
+
const result = projectTask(task, "standard");
|
|
80
|
+
|
|
81
|
+
expect(result).toEqual({
|
|
82
|
+
id: "task-1",
|
|
83
|
+
title: "Test Task",
|
|
84
|
+
status: "pending",
|
|
85
|
+
priority: "medium",
|
|
86
|
+
dueDate: "2025-01-15",
|
|
87
|
+
tags: ["test", "unit"],
|
|
88
|
+
contexts: ["work"],
|
|
89
|
+
parentId: "parent-1",
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("detailed format returns full task", () => {
|
|
94
|
+
const task = createTask();
|
|
95
|
+
const result = projectTask(task, "detailed");
|
|
96
|
+
|
|
97
|
+
expect(result).toBe(task); // Same reference
|
|
98
|
+
expect(result).toHaveProperty("description");
|
|
99
|
+
expect(result).toHaveProperty("estimate");
|
|
100
|
+
expect(result).toHaveProperty("dependencies");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("concise format omits undefined optional fields", () => {
|
|
104
|
+
// Create task without optional fields by deleting them
|
|
105
|
+
const task = createTask();
|
|
106
|
+
delete (task as Record<string, unknown>)["dueDate"];
|
|
107
|
+
delete (task as Record<string, unknown>)["tags"];
|
|
108
|
+
const result = projectTask(task, "concise");
|
|
109
|
+
|
|
110
|
+
expect(result).not.toHaveProperty("dueDate");
|
|
111
|
+
expect(result).not.toHaveProperty("tags");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("projectTasks", () => {
|
|
116
|
+
test("projects all tasks without limit", () => {
|
|
117
|
+
const tasks = [createTask({ id: "t1" }), createTask({ id: "t2" }), createTask({ id: "t3" })];
|
|
118
|
+
const result = projectTasks(tasks, "concise");
|
|
119
|
+
|
|
120
|
+
expect(result).toHaveLength(3);
|
|
121
|
+
expect(result[0]).toEqual({ id: "t1", title: "Test Task", status: "pending", priority: "medium" });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("limits tasks when limit provided", () => {
|
|
125
|
+
const tasks = [
|
|
126
|
+
createTask({ id: "t1" }),
|
|
127
|
+
createTask({ id: "t2" }),
|
|
128
|
+
createTask({ id: "t3" }),
|
|
129
|
+
createTask({ id: "t4" }),
|
|
130
|
+
createTask({ id: "t5" }),
|
|
131
|
+
];
|
|
132
|
+
const result = projectTasks(tasks, "concise", 2);
|
|
133
|
+
|
|
134
|
+
expect(result).toHaveLength(2);
|
|
135
|
+
expect(result.map((t) => t.id)).toEqual(["t1", "t2"]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("returns all tasks if limit exceeds length", () => {
|
|
139
|
+
const tasks = [createTask({ id: "t1" }), createTask({ id: "t2" })];
|
|
140
|
+
const result = projectTasks(tasks, "concise", 100);
|
|
141
|
+
|
|
142
|
+
expect(result).toHaveLength(2);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("returns empty array for empty input", () => {
|
|
146
|
+
const result = projectTasks([], "concise");
|
|
147
|
+
expect(result).toEqual([]);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("projectTasksPaginated", () => {
|
|
152
|
+
test("returns paginated response with correct metadata", () => {
|
|
153
|
+
const tasks = Array.from({ length: 50 }, (_, i) => createTask({ id: `t${i}` }));
|
|
154
|
+
const result = projectTasksPaginated(tasks, "concise", 10, 0);
|
|
155
|
+
|
|
156
|
+
expect(result.items).toHaveLength(10);
|
|
157
|
+
expect(result.total).toBe(50);
|
|
158
|
+
expect(result.limit).toBe(10);
|
|
159
|
+
expect(result.offset).toBe(0);
|
|
160
|
+
expect(result.hasMore).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("returns correct page with offset", () => {
|
|
164
|
+
const tasks = Array.from({ length: 50 }, (_, i) => createTask({ id: `t${i}` }));
|
|
165
|
+
const result = projectTasksPaginated(tasks, "concise", 10, 20);
|
|
166
|
+
|
|
167
|
+
expect(result.items).toHaveLength(10);
|
|
168
|
+
expect(result.items[0]?.id).toBe("t20");
|
|
169
|
+
expect(result.offset).toBe(20);
|
|
170
|
+
expect(result.hasMore).toBe(true);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("hasMore is false on last page", () => {
|
|
174
|
+
const tasks = Array.from({ length: 25 }, (_, i) => createTask({ id: `t${i}` }));
|
|
175
|
+
const result = projectTasksPaginated(tasks, "concise", 10, 20);
|
|
176
|
+
|
|
177
|
+
expect(result.items).toHaveLength(5);
|
|
178
|
+
expect(result.hasMore).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("enforces max limit of 100", () => {
|
|
182
|
+
const tasks = Array.from({ length: 200 }, (_, i) => createTask({ id: `t${i}` }));
|
|
183
|
+
const result = projectTasksPaginated(tasks, "concise", 150, 0);
|
|
184
|
+
|
|
185
|
+
expect(result.items).toHaveLength(100);
|
|
186
|
+
expect(result.limit).toBe(100);
|
|
187
|
+
expect(result.hasMore).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("uses default limit of 20", () => {
|
|
191
|
+
const tasks = Array.from({ length: 50 }, (_, i) => createTask({ id: `t${i}` }));
|
|
192
|
+
const result = projectTasksPaginated(tasks, "concise");
|
|
193
|
+
|
|
194
|
+
expect(result.items).toHaveLength(20);
|
|
195
|
+
expect(result.limit).toBe(20);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("projectProject", () => {
|
|
200
|
+
test("concise format returns essential fields", () => {
|
|
201
|
+
const project = createProject();
|
|
202
|
+
const result = projectProject(project, "concise");
|
|
203
|
+
|
|
204
|
+
expect(result).toEqual({
|
|
205
|
+
id: "proj-1",
|
|
206
|
+
name: "Test Project",
|
|
207
|
+
status: "active",
|
|
208
|
+
completionPercentage: 50,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("concise format omits undefined completionPercentage", () => {
|
|
213
|
+
// Create project without completionPercentage by deleting it
|
|
214
|
+
const project = createProject();
|
|
215
|
+
delete (project as Record<string, unknown>)["completionPercentage"];
|
|
216
|
+
const result = projectProject(project, "concise");
|
|
217
|
+
|
|
218
|
+
expect(result).not.toHaveProperty("completionPercentage");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("standard format includes more fields", () => {
|
|
222
|
+
const project = createProject();
|
|
223
|
+
const result = projectProject(project, "standard");
|
|
224
|
+
|
|
225
|
+
expect(result).toHaveProperty("id");
|
|
226
|
+
expect(result).toHaveProperty("name");
|
|
227
|
+
expect(result).toHaveProperty("status");
|
|
228
|
+
expect(result).toHaveProperty("completionPercentage");
|
|
229
|
+
expect(result).toHaveProperty("description");
|
|
230
|
+
expect(result).toHaveProperty("totalTasks");
|
|
231
|
+
expect(result).toHaveProperty("completedTasks");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("detailed format returns full project", () => {
|
|
235
|
+
const project = createProject();
|
|
236
|
+
const result = projectProject(project, "detailed");
|
|
237
|
+
|
|
238
|
+
expect(result).toBe(project);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("projectProjects", () => {
|
|
243
|
+
test("projects all projects without limit", () => {
|
|
244
|
+
const projects = [createProject({ id: "p1" }), createProject({ id: "p2" })];
|
|
245
|
+
const result = projectProjects(projects, "concise");
|
|
246
|
+
|
|
247
|
+
expect(result).toHaveLength(2);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("limits projects when limit provided", () => {
|
|
251
|
+
const projects = [
|
|
252
|
+
createProject({ id: "p1" }),
|
|
253
|
+
createProject({ id: "p2" }),
|
|
254
|
+
createProject({ id: "p3" }),
|
|
255
|
+
];
|
|
256
|
+
const result = projectProjects(projects, "concise", 1);
|
|
257
|
+
|
|
258
|
+
expect(result).toHaveLength(1);
|
|
259
|
+
expect(result[0]?.id).toBe("p1");
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe("projectInboxItem", () => {
|
|
264
|
+
test("concise format returns 3 essential fields", () => {
|
|
265
|
+
const item = createInboxItem();
|
|
266
|
+
const result = projectInboxItem(item, "concise");
|
|
267
|
+
|
|
268
|
+
expect(result).toEqual({
|
|
269
|
+
id: "inbox-1",
|
|
270
|
+
content: "Quick idea for later",
|
|
271
|
+
status: "pending",
|
|
272
|
+
});
|
|
273
|
+
expect(Object.keys(result)).toHaveLength(3);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("standard format includes capturedAt and tags", () => {
|
|
277
|
+
const item = createInboxItem();
|
|
278
|
+
const result = projectInboxItem(item, "standard");
|
|
279
|
+
|
|
280
|
+
expect(result).toEqual({
|
|
281
|
+
id: "inbox-1",
|
|
282
|
+
content: "Quick idea for later",
|
|
283
|
+
status: "pending",
|
|
284
|
+
capturedAt: "2025-01-01T00:00:00.000Z",
|
|
285
|
+
tags: ["idea"],
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test("detailed format returns full item", () => {
|
|
290
|
+
const item = createInboxItem();
|
|
291
|
+
const result = projectInboxItem(item, "detailed");
|
|
292
|
+
|
|
293
|
+
expect(result).toBe(item);
|
|
294
|
+
expect(result).toHaveProperty("source");
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe("projectInboxItems", () => {
|
|
299
|
+
test("projects and limits inbox items", () => {
|
|
300
|
+
const items = [
|
|
301
|
+
createInboxItem({ id: "i1" }),
|
|
302
|
+
createInboxItem({ id: "i2" }),
|
|
303
|
+
createInboxItem({ id: "i3" }),
|
|
304
|
+
];
|
|
305
|
+
const result = projectInboxItems(items, "concise", 2);
|
|
306
|
+
|
|
307
|
+
expect(result).toHaveLength(2);
|
|
308
|
+
expect(result.map((i) => i.id)).toEqual(["i1", "i2"]);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
describe("formatResponse", () => {
|
|
313
|
+
test("returns JSON for concise format", () => {
|
|
314
|
+
const data = { id: "1", name: "test" };
|
|
315
|
+
const result = formatResponse(data, "concise");
|
|
316
|
+
|
|
317
|
+
expect(result).toBe(JSON.stringify(data));
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("returns JSON for standard format", () => {
|
|
321
|
+
const data = [{ id: "1" }, { id: "2" }];
|
|
322
|
+
const result = formatResponse(data, "standard");
|
|
323
|
+
|
|
324
|
+
expect(result).toBe(JSON.stringify(data));
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("uses detailedFormatter for detailed format", () => {
|
|
328
|
+
const data = { id: "1", name: "test" };
|
|
329
|
+
const formatter = (d: typeof data | (typeof data)[]) => {
|
|
330
|
+
if (Array.isArray(d)) return d.map((i) => `${i.id}`).join(",");
|
|
331
|
+
return `ID: ${d.id}, Name: ${d.name}`;
|
|
332
|
+
};
|
|
333
|
+
const result = formatResponse(data, "detailed", formatter);
|
|
334
|
+
|
|
335
|
+
expect(result).toBe("ID: 1, Name: test");
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("falls back to JSON if no detailedFormatter provided", () => {
|
|
339
|
+
const data = { id: "1" };
|
|
340
|
+
const result = formatResponse(data, "detailed");
|
|
341
|
+
|
|
342
|
+
expect(result).toBe(JSON.stringify(data));
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe("applyPagination", () => {
|
|
347
|
+
test("applies limit and offset correctly", () => {
|
|
348
|
+
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
349
|
+
const result = applyPagination(items, 3, 2);
|
|
350
|
+
|
|
351
|
+
expect(result.items).toEqual([3, 4, 5]);
|
|
352
|
+
expect(result.hasMore).toBe(true);
|
|
353
|
+
expect(result.total).toBe(10);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("enforces max limit of 100", () => {
|
|
357
|
+
const items = Array.from({ length: 200 }, (_, i) => i);
|
|
358
|
+
const result = applyPagination(items, 150);
|
|
359
|
+
|
|
360
|
+
expect(result.items).toHaveLength(100);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test("enforces min limit of 1", () => {
|
|
364
|
+
const items = [1, 2, 3];
|
|
365
|
+
const result = applyPagination(items, 0);
|
|
366
|
+
|
|
367
|
+
expect(result.items).toHaveLength(1);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("handles negative offset as 0", () => {
|
|
371
|
+
const items = [1, 2, 3];
|
|
372
|
+
const result = applyPagination(items, 10, -5);
|
|
373
|
+
|
|
374
|
+
expect(result.items).toEqual([1, 2, 3]);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test("uses default values", () => {
|
|
378
|
+
const items = Array.from({ length: 50 }, (_, i) => i);
|
|
379
|
+
const result = applyPagination(items);
|
|
380
|
+
|
|
381
|
+
expect(result.items).toHaveLength(20);
|
|
382
|
+
expect(result.items[0]).toBe(0);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("truncate", () => {
|
|
387
|
+
test("returns original string if under max length", () => {
|
|
388
|
+
const result = truncate("short", 100);
|
|
389
|
+
expect(result).toBe("short");
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("truncates and adds ellipsis", () => {
|
|
393
|
+
const result = truncate("this is a very long string", 10);
|
|
394
|
+
expect(result).toBe("this is...");
|
|
395
|
+
expect(result.length).toBe(10);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test("uses default max length of 100", () => {
|
|
399
|
+
const longString = "a".repeat(150);
|
|
400
|
+
const result = truncate(longString);
|
|
401
|
+
|
|
402
|
+
expect(result.length).toBe(100);
|
|
403
|
+
expect(result.endsWith("...")).toBe(true);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test("handles empty string", () => {
|
|
407
|
+
const result = truncate("");
|
|
408
|
+
expect(result).toBe("");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test("handles string exactly at max length", () => {
|
|
412
|
+
const str = "a".repeat(100);
|
|
413
|
+
const result = truncate(str, 100);
|
|
414
|
+
|
|
415
|
+
expect(result).toBe(str);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe("summarizeList", () => {
|
|
420
|
+
test("returns displayed items and remaining count", () => {
|
|
421
|
+
const items = [
|
|
422
|
+
{ id: "1", name: "A" },
|
|
423
|
+
{ id: "2", name: "B" },
|
|
424
|
+
{ id: "3", name: "C" },
|
|
425
|
+
{ id: "4", name: "D" },
|
|
426
|
+
{ id: "5", name: "E" },
|
|
427
|
+
{ id: "6", name: "F" },
|
|
428
|
+
{ id: "7", name: "G" },
|
|
429
|
+
];
|
|
430
|
+
|
|
431
|
+
const result = summarizeList(items, 3, (i) => i.id);
|
|
432
|
+
|
|
433
|
+
expect(result.displayed).toHaveLength(3);
|
|
434
|
+
expect(result.remaining).toBe(4);
|
|
435
|
+
expect(result.remainingIds).toEqual(["4", "5", "6", "7"]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test("returns all items if under maxDisplay", () => {
|
|
439
|
+
const items = [{ id: "1" }, { id: "2" }];
|
|
440
|
+
const result = summarizeList(items, 5, (i) => i.id);
|
|
441
|
+
|
|
442
|
+
expect(result.displayed).toHaveLength(2);
|
|
443
|
+
expect(result.remaining).toBe(0);
|
|
444
|
+
expect(result.remainingIds).toEqual([]);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test("uses default maxDisplay of 5", () => {
|
|
448
|
+
const items = Array.from({ length: 10 }, (_, i) => ({ id: `${i}` }));
|
|
449
|
+
const result = summarizeList(items, undefined, (i) => i.id);
|
|
450
|
+
|
|
451
|
+
expect(result.displayed).toHaveLength(5);
|
|
452
|
+
expect(result.remaining).toBe(5);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test("handles empty list", () => {
|
|
456
|
+
const result = summarizeList([], 5, (i: { id: string }) => i.id);
|
|
457
|
+
|
|
458
|
+
expect(result.displayed).toEqual([]);
|
|
459
|
+
expect(result.remaining).toBe(0);
|
|
460
|
+
expect(result.remainingIds).toEqual([]);
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// Token efficiency verification tests
|
|
465
|
+
describe("token efficiency", () => {
|
|
466
|
+
test("concise task is significantly smaller than full task", () => {
|
|
467
|
+
const task = createTask({
|
|
468
|
+
description: "A very long description ".repeat(10),
|
|
469
|
+
estimate: { expected: 60, optimistic: 30, pessimistic: 120 },
|
|
470
|
+
dependencies: [
|
|
471
|
+
{ taskId: "d1", type: "blocked_by" },
|
|
472
|
+
{ taskId: "d2", type: "blocked_by" },
|
|
473
|
+
],
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const concise = projectTask(task, "concise");
|
|
477
|
+
const full = projectTask(task, "detailed");
|
|
478
|
+
|
|
479
|
+
const conciseSize = JSON.stringify(concise).length;
|
|
480
|
+
const fullSize = JSON.stringify(full).length;
|
|
481
|
+
|
|
482
|
+
// Concise should be at least 50% smaller
|
|
483
|
+
expect(conciseSize).toBeLessThan(fullSize * 0.5);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test("concise list is significantly smaller than full list", () => {
|
|
487
|
+
const tasks = Array.from({ length: 20 }, (_, i) =>
|
|
488
|
+
createTask({
|
|
489
|
+
id: `task-${i}`,
|
|
490
|
+
title: `Task ${i}: Do something important`,
|
|
491
|
+
description: "Detailed description of what needs to be done ".repeat(5),
|
|
492
|
+
estimate: { expected: 60, optimistic: 30, pessimistic: 120 },
|
|
493
|
+
})
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
const concise = projectTasks(tasks, "concise");
|
|
497
|
+
const full = projectTasks(tasks, "detailed");
|
|
498
|
+
|
|
499
|
+
const conciseSize = JSON.stringify(concise).length;
|
|
500
|
+
const fullSize = JSON.stringify(full).length;
|
|
501
|
+
|
|
502
|
+
// For list of 20 tasks, concise should be 70%+ smaller
|
|
503
|
+
expect(conciseSize).toBeLessThan(fullSize * 0.4);
|
|
504
|
+
});
|
|
505
|
+
});
|