@task-mcp/shared 1.0.28 → 1.0.30

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.
Files changed (94) hide show
  1. package/dist/algorithms/index.d.ts +1 -1
  2. package/dist/algorithms/index.d.ts.map +1 -1
  3. package/dist/algorithms/index.js +1 -1
  4. package/dist/algorithms/index.js.map +1 -1
  5. package/dist/algorithms/topological-sort.d.ts +21 -1
  6. package/dist/algorithms/topological-sort.d.ts.map +1 -1
  7. package/dist/algorithms/topological-sort.js +12 -1
  8. package/dist/algorithms/topological-sort.js.map +1 -1
  9. package/dist/schemas/inbox.d.ts +2 -2
  10. package/dist/schemas/index.d.ts +1 -0
  11. package/dist/schemas/index.d.ts.map +1 -1
  12. package/dist/schemas/index.js +2 -0
  13. package/dist/schemas/index.js.map +1 -1
  14. package/dist/schemas/response-format.d.ts +11 -0
  15. package/dist/schemas/response-format.d.ts.map +1 -1
  16. package/dist/schemas/response-format.js.map +1 -1
  17. package/dist/schemas/session.d.ts +521 -0
  18. package/dist/schemas/session.d.ts.map +1 -0
  19. package/dist/schemas/session.js +79 -0
  20. package/dist/schemas/session.js.map +1 -0
  21. package/dist/schemas/state.d.ts +2 -2
  22. package/dist/schemas/task.d.ts +9 -0
  23. package/dist/schemas/task.d.ts.map +1 -1
  24. package/dist/schemas/task.js +23 -6
  25. package/dist/schemas/task.js.map +1 -1
  26. package/dist/schemas/view.d.ts +18 -18
  27. package/dist/utils/clustering.d.ts +60 -0
  28. package/dist/utils/clustering.d.ts.map +1 -0
  29. package/dist/utils/clustering.js +283 -0
  30. package/dist/utils/clustering.js.map +1 -0
  31. package/dist/utils/clustering.test.d.ts +2 -0
  32. package/dist/utils/clustering.test.d.ts.map +1 -0
  33. package/dist/utils/clustering.test.js +237 -0
  34. package/dist/utils/clustering.test.js.map +1 -0
  35. package/dist/utils/env.d.ts +24 -0
  36. package/dist/utils/env.d.ts.map +1 -0
  37. package/dist/utils/env.js +40 -0
  38. package/dist/utils/env.js.map +1 -0
  39. package/dist/utils/hierarchy.d.ts.map +1 -1
  40. package/dist/utils/hierarchy.js +13 -6
  41. package/dist/utils/hierarchy.js.map +1 -1
  42. package/dist/utils/index.d.ts +6 -2
  43. package/dist/utils/index.d.ts.map +1 -1
  44. package/dist/utils/index.js +24 -2
  45. package/dist/utils/index.js.map +1 -1
  46. package/dist/utils/intent-extractor.d.ts +30 -0
  47. package/dist/utils/intent-extractor.d.ts.map +1 -0
  48. package/dist/utils/intent-extractor.js +135 -0
  49. package/dist/utils/intent-extractor.js.map +1 -0
  50. package/dist/utils/intent-extractor.test.d.ts +2 -0
  51. package/dist/utils/intent-extractor.test.d.ts.map +1 -0
  52. package/dist/utils/intent-extractor.test.js +69 -0
  53. package/dist/utils/intent-extractor.test.js.map +1 -0
  54. package/dist/utils/natural-language.d.ts.map +1 -1
  55. package/dist/utils/natural-language.js +9 -8
  56. package/dist/utils/natural-language.js.map +1 -1
  57. package/dist/utils/natural-language.test.js +22 -0
  58. package/dist/utils/natural-language.test.js.map +1 -1
  59. package/dist/utils/plan-parser.d.ts +57 -0
  60. package/dist/utils/plan-parser.d.ts.map +1 -0
  61. package/dist/utils/plan-parser.js +371 -0
  62. package/dist/utils/plan-parser.js.map +1 -0
  63. package/dist/utils/projection.d.ts.map +1 -1
  64. package/dist/utils/projection.js +43 -1
  65. package/dist/utils/projection.js.map +1 -1
  66. package/dist/utils/projection.test.js +57 -7
  67. package/dist/utils/projection.test.js.map +1 -1
  68. package/dist/utils/terminal-ui.d.ts +129 -0
  69. package/dist/utils/terminal-ui.d.ts.map +1 -1
  70. package/dist/utils/terminal-ui.js +191 -0
  71. package/dist/utils/terminal-ui.js.map +1 -1
  72. package/dist/utils/terminal-ui.test.js +227 -0
  73. package/dist/utils/terminal-ui.test.js.map +1 -1
  74. package/package.json +2 -2
  75. package/src/algorithms/index.ts +3 -0
  76. package/src/algorithms/topological-sort.ts +31 -1
  77. package/src/schemas/index.ts +11 -0
  78. package/src/schemas/response-format.ts +15 -2
  79. package/src/schemas/session.ts +100 -0
  80. package/src/schemas/task.ts +33 -16
  81. package/src/utils/clustering.test.ts +285 -0
  82. package/src/utils/clustering.ts +336 -0
  83. package/src/utils/env.ts +41 -0
  84. package/src/utils/hierarchy.ts +17 -8
  85. package/src/utils/index.ts +48 -0
  86. package/src/utils/intent-extractor.test.ts +84 -0
  87. package/src/utils/intent-extractor.ts +156 -0
  88. package/src/utils/natural-language.test.ts +27 -0
  89. package/src/utils/natural-language.ts +10 -9
  90. package/src/utils/plan-parser.ts +466 -0
  91. package/src/utils/projection.test.ts +61 -7
  92. package/src/utils/projection.ts +44 -1
  93. package/src/utils/terminal-ui.test.ts +277 -0
  94. package/src/utils/terminal-ui.ts +315 -0
@@ -0,0 +1,466 @@
1
+ import type { Priority, WorkContext } from "../schemas/task.js";
2
+ import { extractMetadata } from "./natural-language.js";
3
+
4
+ /**
5
+ * Parsed task from plan text
6
+ */
7
+ export interface ParsedPlanTask {
8
+ title: string;
9
+ description?: string;
10
+ level: number; // 0 = root phase, 1 = section, 2 = task, 3 = subtask
11
+ tempId: string;
12
+ parentTempId?: string;
13
+ dependsOn?: string[];
14
+ workContext?: Partial<WorkContext>;
15
+ priority?: Priority;
16
+ tags?: string[];
17
+ }
18
+
19
+ /**
20
+ * Options for parsing plan text
21
+ */
22
+ export interface ParsePlanOptions {
23
+ /** Default priority for tasks without explicit priority (default: medium) */
24
+ defaultPriority?: Priority;
25
+ /** Parse natural language patterns like !high, #tag (default: true) */
26
+ parseNaturalLanguage?: boolean;
27
+ /** Infer dependencies from 'depends on', 'after' patterns (default: true) */
28
+ inferDependencies?: boolean;
29
+ }
30
+
31
+ /**
32
+ * Result of parsing plan text
33
+ */
34
+ export interface ParsePlanResult {
35
+ tasks: ParsedPlanTask[];
36
+ phases: string[];
37
+ warnings: string[];
38
+ }
39
+
40
+ /**
41
+ * Maximum input length to prevent DoS
42
+ */
43
+ const MAX_PLAN_LENGTH = 50000;
44
+
45
+ /**
46
+ * Preprocess input to remove code blocks and YAML frontmatter
47
+ */
48
+ function preprocessInput(input: string): string {
49
+ let result = input;
50
+
51
+ // Remove YAML frontmatter (--- at start of file)
52
+ // Must be at the very beginning of the document
53
+ const frontmatterMatch = result.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/);
54
+ if (frontmatterMatch) {
55
+ result = result.slice(frontmatterMatch[0].length);
56
+ }
57
+
58
+ // Remove fenced code blocks (``` or ~~~)
59
+ // Matches both backticks and tildes, with optional language identifier
60
+ result = result.replace(/^(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\1$/gm, "");
61
+
62
+ // Also handle code blocks that might not have matching closing fence
63
+ // (replace opening fence and content until next fence or end)
64
+ result = result.replace(/^(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?=\n(`{3,}|~{3,})|$)/gm, (match) => {
65
+ // Only remove if it looks like a code block (has content)
66
+ if (match.includes("\n")) {
67
+ return "";
68
+ }
69
+ return match;
70
+ });
71
+
72
+ return result;
73
+ }
74
+
75
+ /**
76
+ * Parse markdown/structured text into hierarchical tasks
77
+ *
78
+ * Parsing rules:
79
+ * - `# Header` → Top-level phase (level 0)
80
+ * - `## SubHeader` → Section (level 1)
81
+ * - `- Item` → Task (level based on indentation)
82
+ * - `depends on X`, `after X` → Dependency inference
83
+ * - `!high`, `#tag` → Natural language patterns
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const result = parsePlan(`
88
+ * # Phase 1: Setup
89
+ * - Create database schema !high
90
+ * - Define user table
91
+ * - Define session table
92
+ * - Setup API endpoints (depends on database)
93
+ * `);
94
+ * ```
95
+ */
96
+ export function parsePlan(input: string, options: ParsePlanOptions = {}): ParsePlanResult {
97
+ if (input.length > MAX_PLAN_LENGTH) {
98
+ return {
99
+ tasks: [],
100
+ phases: [],
101
+ warnings: [`Input exceeds maximum length of ${MAX_PLAN_LENGTH} characters`],
102
+ };
103
+ }
104
+
105
+ const {
106
+ defaultPriority = "medium",
107
+ parseNaturalLanguage = true,
108
+ inferDependencies = true,
109
+ } = options;
110
+
111
+ // Preprocess to remove code blocks and YAML frontmatter
112
+ const processedInput = preprocessInput(input);
113
+ const lines = processedInput.split("\n");
114
+ const tasks: ParsedPlanTask[] = [];
115
+ const phases: string[] = [];
116
+ const warnings: string[] = [];
117
+
118
+ let taskCounter = 0;
119
+ let currentPhase: { tempId: string; title: string } | null = null;
120
+ let currentSection: { tempId: string; level: number } | null = null;
121
+ const parentStack: Array<{ tempId: string; level: number; indent: number }> = [];
122
+
123
+ for (const line of lines) {
124
+ const trimmed = line.trim();
125
+
126
+ // Skip empty lines
127
+ if (!trimmed) continue;
128
+
129
+ // Parse H1 headers as phases (level 0)
130
+ const h1Match = trimmed.match(/^#\s+(.+)$/);
131
+ if (h1Match) {
132
+ const phaseTitle = h1Match[1]!.trim();
133
+ const tempId = `phase-${++taskCounter}`;
134
+ currentPhase = { tempId, title: phaseTitle };
135
+ phases.push(phaseTitle);
136
+
137
+ // Extract metadata if enabled
138
+ let title = phaseTitle;
139
+ let priority: Priority | undefined;
140
+ let tags: string[] | undefined;
141
+
142
+ if (parseNaturalLanguage) {
143
+ const metadata = extractMetadata(phaseTitle);
144
+ title = metadata.remaining || phaseTitle;
145
+ priority = metadata.priority;
146
+ tags = metadata.tags;
147
+ }
148
+
149
+ tasks.push({
150
+ title,
151
+ level: 0,
152
+ tempId,
153
+ priority: priority ?? "high",
154
+ ...(tags && tags.length > 0 && { tags }),
155
+ });
156
+
157
+ // Reset section and parent stack
158
+ currentSection = null;
159
+ parentStack.length = 0;
160
+ continue;
161
+ }
162
+
163
+ // Parse H2 headers as sections (level 1)
164
+ const h2Match = trimmed.match(/^##\s+(.+)$/);
165
+ if (h2Match) {
166
+ const sectionTitle = h2Match[1]!.trim();
167
+ const tempId = `section-${++taskCounter}`;
168
+
169
+ let title = sectionTitle;
170
+ let priority: Priority | undefined;
171
+ let tags: string[] | undefined;
172
+
173
+ if (parseNaturalLanguage) {
174
+ const metadata = extractMetadata(sectionTitle);
175
+ title = metadata.remaining || sectionTitle;
176
+ priority = metadata.priority;
177
+ tags = metadata.tags;
178
+ }
179
+
180
+ tasks.push({
181
+ title,
182
+ level: 1,
183
+ tempId,
184
+ ...(currentPhase && { parentTempId: currentPhase.tempId }),
185
+ priority: priority ?? defaultPriority,
186
+ ...(tags && tags.length > 0 && { tags }),
187
+ });
188
+
189
+ currentSection = { tempId, level: 1 };
190
+ parentStack.length = 0;
191
+ continue;
192
+ }
193
+
194
+ // Parse list items as tasks
195
+ const listMatch = line.match(/^(\s*)[-*]\s+(.+)$/);
196
+ if (listMatch) {
197
+ const indent = listMatch[1]!.length;
198
+ const content = listMatch[2]!.trim();
199
+ const tempId = `task-${++taskCounter}`;
200
+
201
+ // Determine parent based on indentation
202
+ let parentTempId: string | undefined;
203
+ let level: number;
204
+
205
+ // Pop parents from stack that have same or greater indentation
206
+ while (parentStack.length > 0 && parentStack[parentStack.length - 1]!.indent >= indent) {
207
+ parentStack.pop();
208
+ }
209
+
210
+ if (parentStack.length > 0) {
211
+ // Use the last item on stack as parent
212
+ const parent = parentStack[parentStack.length - 1]!;
213
+ parentTempId = parent.tempId;
214
+ level = Math.min(parent.level + 1, 3); // Max depth 3
215
+ } else if (currentSection) {
216
+ parentTempId = currentSection.tempId;
217
+ level = 2;
218
+ } else if (currentPhase) {
219
+ parentTempId = currentPhase.tempId;
220
+ level = 1;
221
+ } else {
222
+ level = 0;
223
+ }
224
+
225
+ // Extract metadata from content
226
+ let title = content;
227
+ let priority: Priority | undefined;
228
+ let tags: string[] | undefined;
229
+ let dependsOn: string[] | undefined;
230
+
231
+ if (parseNaturalLanguage) {
232
+ const metadata = extractMetadata(content);
233
+ title = metadata.remaining || content;
234
+ priority = metadata.priority;
235
+ tags = metadata.tags;
236
+ }
237
+
238
+ // Infer dependencies from text
239
+ if (inferDependencies) {
240
+ dependsOn = inferDependenciesFromText(title, tasks);
241
+ // Clean up dependency text from title
242
+ title = cleanDependencyText(title);
243
+ }
244
+
245
+ // Extract description from remaining parentheses (not dependency-related)
246
+ const descExtracted = extractDescription(title);
247
+ title = descExtracted.title;
248
+ const description = descExtracted.description;
249
+
250
+ const task: ParsedPlanTask = {
251
+ title,
252
+ level,
253
+ tempId,
254
+ ...(parentTempId && { parentTempId }),
255
+ ...(description && { description }),
256
+ priority: priority ?? defaultPriority,
257
+ ...(tags && tags.length > 0 && { tags }),
258
+ ...(dependsOn && dependsOn.length > 0 && { dependsOn }),
259
+ };
260
+
261
+ tasks.push(task);
262
+
263
+ // Push to parent stack for potential children
264
+ parentStack.push({ tempId, level, indent });
265
+ continue;
266
+ }
267
+
268
+ // Parse numbered list items
269
+ const numberedMatch = line.match(/^(\s*)(\d+)[.)]\s+(.+)$/);
270
+ if (numberedMatch) {
271
+ const indent = numberedMatch[1]!.length;
272
+ const content = numberedMatch[3]!.trim();
273
+ const tempId = `task-${++taskCounter}`;
274
+
275
+ // Same logic as unordered lists
276
+ while (parentStack.length > 0 && parentStack[parentStack.length - 1]!.indent >= indent) {
277
+ parentStack.pop();
278
+ }
279
+
280
+ let parentTempId: string | undefined;
281
+ let level: number;
282
+
283
+ if (parentStack.length > 0) {
284
+ const parent = parentStack[parentStack.length - 1]!;
285
+ parentTempId = parent.tempId;
286
+ level = Math.min(parent.level + 1, 3);
287
+ } else if (currentSection) {
288
+ parentTempId = currentSection.tempId;
289
+ level = 2;
290
+ } else if (currentPhase) {
291
+ parentTempId = currentPhase.tempId;
292
+ level = 1;
293
+ } else {
294
+ level = 0;
295
+ }
296
+
297
+ let title = content;
298
+ let priority: Priority | undefined;
299
+ let tags: string[] | undefined;
300
+ let dependsOn: string[] | undefined;
301
+
302
+ if (parseNaturalLanguage) {
303
+ const metadata = extractMetadata(content);
304
+ title = metadata.remaining || content;
305
+ priority = metadata.priority;
306
+ tags = metadata.tags;
307
+ }
308
+
309
+ if (inferDependencies) {
310
+ dependsOn = inferDependenciesFromText(title, tasks);
311
+ title = cleanDependencyText(title);
312
+ }
313
+
314
+ // Extract description from remaining parentheses
315
+ const descExtracted = extractDescription(title);
316
+ title = descExtracted.title;
317
+ const description = descExtracted.description;
318
+
319
+ tasks.push({
320
+ title,
321
+ level,
322
+ tempId,
323
+ ...(parentTempId && { parentTempId }),
324
+ ...(description && { description }),
325
+ priority: priority ?? defaultPriority,
326
+ ...(tags && tags.length > 0 && { tags }),
327
+ ...(dependsOn && dependsOn.length > 0 && { dependsOn }),
328
+ });
329
+
330
+ parentStack.push({ tempId, level, indent });
331
+ continue;
332
+ }
333
+ }
334
+
335
+ return { tasks, phases, warnings };
336
+ }
337
+
338
+ /**
339
+ * Infer dependencies from text patterns like "depends on X", "after X"
340
+ */
341
+ function inferDependenciesFromText(content: string, existingTasks: ParsedPlanTask[]): string[] {
342
+ const deps: string[] = [];
343
+ const lower = content.toLowerCase();
344
+
345
+ // Pattern: (depends on|after|requires|following) "phrase" or phrase
346
+ const patterns = [
347
+ /\(?\s*depends?\s+on\s+(.+?)\s*\)?/gi,
348
+ /\(?\s*after\s+(.+?)\s*\)?/gi,
349
+ /\(?\s*requires?\s+(.+?)\s*\)?/gi,
350
+ /\(?\s*following\s+(.+?)\s*\)?/gi,
351
+ /\(?\s*blocked\s+by\s+(.+?)\s*\)?/gi,
352
+ ];
353
+
354
+ for (const pattern of patterns) {
355
+ let match;
356
+ while ((match = pattern.exec(lower)) !== null) {
357
+ const depPhrase = match[1]!.trim();
358
+
359
+ // Try to find matching task by title
360
+ const found = existingTasks.find((t) => {
361
+ const taskTitle = t.title.toLowerCase();
362
+ return (
363
+ taskTitle.includes(depPhrase) ||
364
+ depPhrase.includes(taskTitle) ||
365
+ fuzzyMatch(taskTitle, depPhrase)
366
+ );
367
+ });
368
+
369
+ if (found && !deps.includes(found.tempId)) {
370
+ deps.push(found.tempId);
371
+ }
372
+ }
373
+ }
374
+
375
+ return deps;
376
+ }
377
+
378
+ /**
379
+ * Simple fuzzy matching for dependency detection
380
+ */
381
+ function fuzzyMatch(a: string, b: string): boolean {
382
+ // Remove common words and compare
383
+ const stopWords = ["the", "a", "an", "to", "for", "of", "in", "on", "at"];
384
+ const normalize = (s: string) =>
385
+ s
386
+ .toLowerCase()
387
+ .split(/\s+/)
388
+ .filter((w) => !stopWords.includes(w))
389
+ .join(" ");
390
+
391
+ const aNorm = normalize(a);
392
+ const bNorm = normalize(b);
393
+
394
+ // Check if significant overlap
395
+ const aWords = aNorm.split(" ");
396
+ const bWords = bNorm.split(" ");
397
+
398
+ const matches = aWords.filter((w) => bWords.includes(w));
399
+ return matches.length >= Math.min(2, Math.min(aWords.length, bWords.length));
400
+ }
401
+
402
+ /**
403
+ * Remove dependency text from title
404
+ */
405
+ function cleanDependencyText(title: string): string {
406
+ return title
407
+ .replace(/\(?\s*depends?\s+on\s+.+?\s*\)?/gi, "")
408
+ .replace(/\(?\s*after\s+.+?\s*\)?/gi, "")
409
+ .replace(/\(?\s*requires?\s+.+?\s*\)?/gi, "")
410
+ .replace(/\(?\s*following\s+.+?\s*\)?/gi, "")
411
+ .replace(/\(?\s*blocked\s+by\s+.+?\s*\)?/gi, "")
412
+ .replace(/\s+/g, " ")
413
+ .trim();
414
+ }
415
+
416
+ /**
417
+ * Extract description from title
418
+ *
419
+ * Patterns supported:
420
+ * - "제목: 설명" → colon separator
421
+ * - "제목 -- 설명" → double dash separator
422
+ * - "제목 (설명)" → parentheses (after dependency cleanup)
423
+ *
424
+ * @example
425
+ * extractDescription("API 구현: 라우팅, 인증 담당")
426
+ * // → { title: "API 구현", description: "라우팅, 인증 담당" }
427
+ *
428
+ * extractDescription("API 구현 (라우팅, 인증 담당)")
429
+ * // → { title: "API 구현", description: "라우팅, 인증 담당" }
430
+ */
431
+ function extractDescription(title: string): { title: string; description?: string } {
432
+ // Pattern 1: Colon separator (but not time like "10:30")
433
+ // Match "제목: 설명" but not "10:30" or "http://..."
434
+ const colonMatch = title.match(/^(.+?):\s+([^/].{5,})$/);
435
+ if (colonMatch && !/^\d+:\d+/.test(colonMatch[2]!)) {
436
+ return {
437
+ title: colonMatch[1]!.trim(),
438
+ description: colonMatch[2]!.trim(),
439
+ };
440
+ }
441
+
442
+ // Pattern 2: Double dash separator "제목 -- 설명"
443
+ const dashMatch = title.match(/^(.+?)\s+--\s+(.+)$/);
444
+ if (dashMatch) {
445
+ return {
446
+ title: dashMatch[1]!.trim(),
447
+ description: dashMatch[2]!.trim(),
448
+ };
449
+ }
450
+
451
+ // Pattern 3: Parentheses at end (only if not dependency-like)
452
+ // Already cleaned by cleanDependencyText, so remaining () is description
453
+ const parenMatch = title.match(/^(.+?)\s*\(([^)]+)\)\s*$/);
454
+ if (parenMatch) {
455
+ const content = parenMatch[2]!.trim();
456
+ // Skip if looks like a short annotation (single word, abbreviation)
457
+ if (content.length > 3 && content.includes(" ")) {
458
+ return {
459
+ title: parenMatch[1]!.trim(),
460
+ description: content,
461
+ };
462
+ }
463
+ }
464
+
465
+ return { title };
466
+ }
@@ -45,7 +45,7 @@ const createInboxItem = (overrides: Partial<InboxItem> = {}): InboxItem => ({
45
45
  });
46
46
 
47
47
  describe("formatTask", () => {
48
- test("concise format returns only 4 essential fields", () => {
48
+ test("concise format returns essential fields plus description for context", () => {
49
49
  const task = createTask();
50
50
  const result = formatTask(task, "concise");
51
51
 
@@ -54,11 +54,12 @@ describe("formatTask", () => {
54
54
  title: "Test Task",
55
55
  status: "pending",
56
56
  priority: "medium",
57
+ description: "This is a test task with a long description",
57
58
  });
58
- expect(Object.keys(result)).toHaveLength(4);
59
+ expect(Object.keys(result)).toHaveLength(5);
59
60
  });
60
61
 
61
- test("standard format returns 8 common fields", () => {
62
+ test("standard format returns common fields including description", () => {
62
63
  const task = createTask();
63
64
  const result = formatTask(task, "standard");
64
65
 
@@ -67,6 +68,7 @@ describe("formatTask", () => {
67
68
  title: "Test Task",
68
69
  status: "pending",
69
70
  priority: "medium",
71
+ description: "This is a test task with a long description",
70
72
  dueDate: "2025-01-15",
71
73
  tags: ["test", "unit"],
72
74
  contexts: ["work"],
@@ -94,6 +96,57 @@ describe("formatTask", () => {
94
96
  expect(result).not.toHaveProperty("dueDate");
95
97
  expect(result).not.toHaveProperty("tags");
96
98
  });
99
+
100
+ test("concise format includes workContext fields (intent, methodology, quality, patterns, criteria)", () => {
101
+ const task = createTask({
102
+ workContext: {
103
+ intent: "Migrate API layer to service pattern",
104
+ methodology: "TDD + iterative refactoring",
105
+ qualityLevel: "thorough",
106
+ patterns: {
107
+ parallelExecution: true,
108
+ testFirst: true,
109
+ },
110
+ acceptanceCriteria: ["All tests pass", "No type errors"],
111
+ },
112
+ });
113
+ const result = formatTask(task, "concise");
114
+
115
+ expect(result).toHaveProperty("intent", "Migrate API layer to service pattern");
116
+ expect(result).toHaveProperty("methodology", "TDD + iterative refactoring");
117
+ expect(result).toHaveProperty("quality", "thorough");
118
+ expect(result).toHaveProperty("patterns", { parallelExecution: true, testFirst: true });
119
+ expect(result).toHaveProperty("criteria", ["All tests pass", "No type errors"]);
120
+ });
121
+
122
+ test("standard format includes full workContext with patterns and criteria", () => {
123
+ const task = createTask({
124
+ workContext: {
125
+ intent: "Refactor module",
126
+ methodology: "Analyze → Extract → Test",
127
+ qualityLevel: "standard",
128
+ patterns: {
129
+ parallelExecution: true,
130
+ testFirst: true,
131
+ reviewRequired: false,
132
+ },
133
+ acceptanceCriteria: ["Tests pass", "No regressions"],
134
+ },
135
+ });
136
+ const result = formatTask(task, "standard");
137
+
138
+ expect(result).toHaveProperty("workContext");
139
+ const wc = (result as { workContext?: unknown }).workContext as Record<string, unknown>;
140
+ expect(wc["intent"]).toBe("Refactor module");
141
+ expect(wc["methodology"]).toBe("Analyze → Extract → Test");
142
+ expect(wc["qualityLevel"]).toBe("standard");
143
+ expect(wc["patterns"]).toEqual({
144
+ parallelExecution: true,
145
+ testFirst: true,
146
+ reviewRequired: false,
147
+ });
148
+ expect(wc["acceptanceCriteria"]).toEqual(["Tests pass", "No regressions"]);
149
+ });
97
150
  });
98
151
 
99
152
  describe("formatTasks", () => {
@@ -107,6 +160,7 @@ describe("formatTasks", () => {
107
160
  title: "Test Task",
108
161
  status: "pending",
109
162
  priority: "medium",
163
+ description: "This is a test task with a long description",
110
164
  });
111
165
  });
112
166
 
@@ -404,8 +458,8 @@ describe("token efficiency", () => {
404
458
  const conciseSize = JSON.stringify(concise).length;
405
459
  const fullSize = JSON.stringify(full).length;
406
460
 
407
- // Concise should be at least 50% smaller
408
- expect(conciseSize).toBeLessThan(fullSize * 0.5);
461
+ // Concise should be at least 40% smaller (now includes description for session context)
462
+ expect(conciseSize).toBeLessThan(fullSize * 0.6);
409
463
  });
410
464
 
411
465
  test("concise list is significantly smaller than full list", () => {
@@ -424,7 +478,7 @@ describe("token efficiency", () => {
424
478
  const conciseSize = JSON.stringify(concise).length;
425
479
  const fullSize = JSON.stringify(full).length;
426
480
 
427
- // For list of 20 tasks, concise should be 70%+ smaller
428
- expect(conciseSize).toBeLessThan(fullSize * 0.4);
481
+ // For list of 20 tasks, concise should be 40%+ smaller (now includes description)
482
+ expect(conciseSize).toBeLessThan(fullSize * 0.6);
429
483
  });
430
484
  });
@@ -36,13 +36,43 @@ export function formatTask(task: Task, format: ResponseFormat): TaskSummary | Ta
36
36
  status: task.status,
37
37
  priority: task.priority,
38
38
  };
39
- // Include intent + qualityLevel for quick context understanding
39
+ // Include description for session context (truncated for token efficiency)
40
+ // Skip if intent exists and provides enough context
41
+ if (task.description) {
42
+ const hasIntent = !!task.workContext?.intent;
43
+ // With intent: shorter description (100 chars), without: fuller context (200 chars)
44
+ const maxLen = hasIntent ? 100 : 200;
45
+ summary.description = truncate(task.description, maxLen);
46
+ }
47
+ // Include workContext fields for session resumption
40
48
  if (task.workContext?.intent) {
41
49
  summary.intent = task.workContext.intent;
42
50
  }
51
+ if (task.workContext?.methodology) {
52
+ summary.methodology = task.workContext.methodology;
53
+ }
43
54
  if (task.workContext?.qualityLevel) {
44
55
  summary.quality = task.workContext.qualityLevel;
45
56
  }
57
+ // Include patterns for execution guidance
58
+ if (task.workContext?.patterns) {
59
+ const p = task.workContext.patterns;
60
+ const patterns: {
61
+ parallelExecution?: boolean;
62
+ testFirst?: boolean;
63
+ reviewRequired?: boolean;
64
+ } = {};
65
+ if (p.parallelExecution !== undefined) patterns.parallelExecution = p.parallelExecution;
66
+ if (p.testFirst !== undefined) patterns.testFirst = p.testFirst;
67
+ if (p.reviewRequired !== undefined) patterns.reviewRequired = p.reviewRequired;
68
+ if (Object.keys(patterns).length > 0) {
69
+ summary.patterns = patterns;
70
+ }
71
+ }
72
+ // Include acceptance criteria for completion validation
73
+ if (task.workContext?.acceptanceCriteria?.length) {
74
+ summary.criteria = task.workContext.acceptanceCriteria;
75
+ }
46
76
  return summary;
47
77
  }
48
78
 
@@ -53,6 +83,7 @@ export function formatTask(task: Task, format: ResponseFormat): TaskSummary | Ta
53
83
  title: task.title,
54
84
  status: task.status,
55
85
  priority: task.priority,
86
+ ...(task.description !== undefined && { description: task.description }),
56
87
  ...(task.dueDate !== undefined && { dueDate: task.dueDate }),
57
88
  ...(task.tags !== undefined && { tags: task.tags }),
58
89
  ...(task.contexts !== undefined && { contexts: task.contexts }),
@@ -65,6 +96,18 @@ export function formatTask(task: Task, format: ResponseFormat): TaskSummary | Ta
65
96
  ...(wc.intent !== undefined && { intent: wc.intent }),
66
97
  ...(wc.methodology !== undefined && { methodology: wc.methodology }),
67
98
  ...(wc.qualityLevel !== undefined && { qualityLevel: wc.qualityLevel }),
99
+ ...(wc.patterns !== undefined && {
100
+ patterns: {
101
+ ...(wc.patterns.parallelExecution !== undefined && {
102
+ parallelExecution: wc.patterns.parallelExecution,
103
+ }),
104
+ ...(wc.patterns.testFirst !== undefined && { testFirst: wc.patterns.testFirst }),
105
+ ...(wc.patterns.reviewRequired !== undefined && {
106
+ reviewRequired: wc.patterns.reviewRequired,
107
+ }),
108
+ },
109
+ }),
110
+ ...(wc.acceptanceCriteria?.length && { acceptanceCriteria: wc.acceptanceCriteria }),
68
111
  };
69
112
  }
70
113
  return result;