MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / resolveTaskForCli

Function resolveTaskForCli

src/cli/helpers/taskResolution.ts:22–79  ·  view source on GitHub ↗
(
	plugin: TaskNotesPlugin,
	input: CliTaskLookupInput
)

Source from the content-addressed store, hash-verified

20}
21
22export async function resolveTaskForCli(
23 plugin: TaskNotesPlugin,
24 input: CliTaskLookupInput
25): Promise<TaskInfo> {
26 const path = normalizeLookupValue(input.path);
27 const title = normalizeLookupValue(input.title);
28 const query = normalizeLookupValue(input.query);
29
30 if (path) {
31 const task = await plugin.cacheManager.getTaskInfo(path);
32 if (!task) {
33 throw new Error(`Task not found for path: ${path}`);
34 }
35
36 return task;
37 }
38
39 const allTasks = await plugin.cacheManager.getAllTasks();
40
41 if (title) {
42 const exactMatches = allTasks.filter((task) => task.title === title);
43 if (exactMatches.length === 1) {
44 return exactMatches[0];
45 }
46
47 if (exactMatches.length > 1) {
48 throw new Error(
49 `Multiple tasks matched title "${title}": ${formatAmbiguousTaskMatches(exactMatches)}`
50 );
51 }
52
53 throw new Error(`Task not found for title: ${title}`);
54 }
55
56 if (query) {
57 const loweredQuery = query.toLowerCase();
58 const matches = allTasks.filter((task) => {
59 return (
60 task.title.toLowerCase().includes(loweredQuery) ||
61 task.path.toLowerCase().includes(loweredQuery)
62 );
63 });
64
65 if (matches.length === 1) {
66 return matches[0];
67 }
68
69 if (matches.length > 1) {
70 throw new Error(
71 `Multiple tasks matched query "${query}": ${formatAmbiguousTaskMatches(matches)}`
72 );
73 }
74
75 throw new Error(`Task not found for query: ${query}`);
76 }
77
78 throw new Error("A task reference is required: pass path, title, or query");
79}

Callers 4

handlerFunction · 0.90
resolvePomodoroTaskFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90

Calls 4

normalizeLookupValueFunction · 0.85
getTaskInfoMethod · 0.65
getAllTasksMethod · 0.45

Tested by

no test coverage detected