@dinoxx/dinox-cli 2.18.4 → 2.19.0
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/commands/notes/contentEngine.js +8 -4
- package/dist/commands/schema/renderSkills.js +3 -1
- package/dist/commands/todo/contentModel.d.ts +5 -3
- package/dist/commands/todo/contentModel.js +7 -5
- package/dist/commands/todo/dryRun.d.ts +9 -7
- package/dist/commands/todo/dryRun.js +99 -86
- package/dist/commands/todo/index.js +279 -93
- package/dist/commands/todo/repo.d.ts +128 -7
- package/dist/commands/todo/repo.js +474 -130
- package/dist/commands/todo/taskModel.d.ts +20 -1
- package/dist/commands/todo/taskModel.js +153 -20
- package/dist/commands/todo/taskPatch.d.ts +119 -0
- package/dist/commands/todo/taskPatch.js +502 -0
- package/dist/commands/todo/taskText.d.ts +26 -0
- package/dist/commands/todo/taskText.js +221 -0
- package/dist/daemon/supervisor.d.ts +0 -6
- package/dist/daemon/supervisor.js +10 -2
- package/dist/dsh-plugin/lib/client.js +713 -289
- package/dist/dsh-plugin/lib/index.js +7 -2
- package/dist/dsh-plugin/package.json +1 -1
- package/dist/dsh-plugin/runtime.json +1 -1
- package/dist/editor/compat.d.ts +6 -0
- package/dist/editor/compat.js +18 -0
- package/dist/editor/daemon.js +27 -0
- package/dist/editor/mcp.js +99 -2
- package/dist/editor/service.d.ts +57 -1
- package/dist/editor/service.js +174 -7
- package/dist/editor/todos.d.ts +67 -0
- package/dist/editor/todos.js +293 -0
- package/dist/editor-ui/mcp-app.html +262 -253
- package/dist/integrations/dsh/host.js +10 -2
- package/dist/utils/tiptapMarkdown.js +15 -1
- package/dist/vendor/electron/shared/task-priority.d.ts +42 -0
- package/dist/vendor/electron/shared/task-priority.js +186 -0
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { AppendTodoTasksResult, SearchedTodoResponse, TodoSearchWire, TodoTaskRestore, TodoTaskUpdate, UpdateTodoTasksResult } from '../commands/todo/repo.js';
|
|
2
|
+
import type { TodoDraftItem } from '../commands/todo/taskPatch.js';
|
|
3
|
+
/**
|
|
4
|
+
* The editor panel's todo route: which inline tasks (taskItem nodes across all
|
|
5
|
+
* notes) the list shows. Kept on the editor session so every panel of the
|
|
6
|
+
* session, and the model, agree on it.
|
|
7
|
+
*/
|
|
8
|
+
export type TodoStatus = 'uncompleted' | 'completed' | 'all';
|
|
9
|
+
export type TodoPriority = 'high' | 'medium' | 'low' | 'none';
|
|
10
|
+
export type TodoFilter = {
|
|
11
|
+
status: TodoStatus;
|
|
12
|
+
query: string;
|
|
13
|
+
tags: string[];
|
|
14
|
+
priority: TodoPriority[];
|
|
15
|
+
/** Local dates (YYYY-MM-DD); a task matches when its schedule overlaps them. */
|
|
16
|
+
from: string | null;
|
|
17
|
+
to: string | null;
|
|
18
|
+
};
|
|
19
|
+
export type TodoList = Pick<SearchedTodoResponse, 'tasks'> & {
|
|
20
|
+
total: number;
|
|
21
|
+
hasMore: boolean;
|
|
22
|
+
filter: TodoFilter;
|
|
23
|
+
/** Subtasks the AI proposed, waiting for the user in the panel. */
|
|
24
|
+
suggestions?: TodoSuggestion[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Subtasks the AI proposes for one task. Nothing is written until the user
|
|
28
|
+
* accepts them in the panel, where they show under the task.
|
|
29
|
+
*/
|
|
30
|
+
export type TodoSuggestion = {
|
|
31
|
+
id: string;
|
|
32
|
+
taskId: string;
|
|
33
|
+
noteId: string | null;
|
|
34
|
+
/** One sentence on why or how, shown above the subtasks. */
|
|
35
|
+
note: string;
|
|
36
|
+
items: TodoDraftItem[];
|
|
37
|
+
at: string;
|
|
38
|
+
};
|
|
39
|
+
/** What the daemon gives the editor service: the CLI's own todo search and update. */
|
|
40
|
+
export type EditorTodos = {
|
|
41
|
+
search(wire: TodoSearchWire): Promise<SearchedTodoResponse>;
|
|
42
|
+
update(updates: TodoTaskUpdate[]): Promise<UpdateTodoTasksResult>;
|
|
43
|
+
/** New tasks at the end of today's daily note (created when missing), or under `target`'s task. */
|
|
44
|
+
append(items: TodoDraftItem[], target?: {
|
|
45
|
+
parentTaskId: string;
|
|
46
|
+
noteId?: string;
|
|
47
|
+
}): Promise<AppendTodoTasksResult>;
|
|
48
|
+
/** Exact restore without cascade, or removal of tasks just added: the panel's undo. */
|
|
49
|
+
restore(entries: TodoTaskRestore[]): Promise<UpdateTodoTasksResult>;
|
|
50
|
+
};
|
|
51
|
+
export declare const DEFAULT_TODO_FILTER: TodoFilter;
|
|
52
|
+
/** Validates a filter from the model or the panel; anything missing takes the default. */
|
|
53
|
+
export declare function parseTodoFilter(raw: unknown, base?: TodoFilter): TodoFilter;
|
|
54
|
+
export declare function todoSearchWire(filter: TodoFilter): TodoSearchWire;
|
|
55
|
+
export declare function toTodoList(response: SearchedTodoResponse, filter: TodoFilter): TodoList;
|
|
56
|
+
/**
|
|
57
|
+
* Task changes from the panel or the model. Each names a task by its stable
|
|
58
|
+
* taskId; `due: null` clears the due time and `priority: null` the priority.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseTodoUpdates(raw: unknown): TodoTaskUpdate[];
|
|
61
|
+
/** Tasks typed into the panel's quick add: `[{text, priority?, due?: {date, time?}}]`. */
|
|
62
|
+
export declare function parseTodoAppend(raw: unknown): TodoDraftItem[];
|
|
63
|
+
/** The model's proposal: `{taskId, noteId?, note?, subtasks: [{text, priority?, due?}]}`. */
|
|
64
|
+
export declare function parseTodoSuggest(input: Record<string, unknown>): Omit<TodoSuggestion, 'id' | 'at'>;
|
|
65
|
+
export declare function parseTodoRestore(raw: unknown): TodoTaskRestore[];
|
|
66
|
+
/** The list as compact lines the model can act on by task id. */
|
|
67
|
+
export declare function formatTodoList(list: TodoList, max?: number): string;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { DinoxError } from '../utils/errors.js';
|
|
2
|
+
export const DEFAULT_TODO_FILTER = { status: 'uncompleted', query: '', tags: [], priority: [], from: null, to: null };
|
|
3
|
+
const STATUSES = ['uncompleted', 'completed', 'all'];
|
|
4
|
+
const PRIORITIES = ['high', 'medium', 'low', 'none'];
|
|
5
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
|
+
const TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
7
|
+
const LIST_LIMIT = 300;
|
|
8
|
+
const SCAN_LIMIT = 2000;
|
|
9
|
+
const MAX_UPDATES = 50;
|
|
10
|
+
function invalid(message) {
|
|
11
|
+
return new DinoxError(message, { code: 'INVALID_ARGUMENT', recoverable: true });
|
|
12
|
+
}
|
|
13
|
+
function text(value, name, max) {
|
|
14
|
+
if (value === undefined || value === null)
|
|
15
|
+
return '';
|
|
16
|
+
if (typeof value !== 'string')
|
|
17
|
+
throw invalid(`${name} must be a string`);
|
|
18
|
+
if (value.length > max)
|
|
19
|
+
throw invalid(`${name} is too long`);
|
|
20
|
+
return value.trim();
|
|
21
|
+
}
|
|
22
|
+
function localDate(value, name) {
|
|
23
|
+
const date = text(value, name, 10);
|
|
24
|
+
if (!date)
|
|
25
|
+
return null;
|
|
26
|
+
const parsed = DATE.test(date) ? new Date(`${date}T00:00:00`) : null;
|
|
27
|
+
if (!parsed || Number.isNaN(parsed.getTime()) || formatLocalDate(parsed) !== date)
|
|
28
|
+
throw invalid(`${name} must be a YYYY-MM-DD date`);
|
|
29
|
+
return date;
|
|
30
|
+
}
|
|
31
|
+
function formatLocalDate(date) {
|
|
32
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
33
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
34
|
+
}
|
|
35
|
+
/** Validates a filter from the model or the panel; anything missing takes the default. */
|
|
36
|
+
export function parseTodoFilter(raw, base = DEFAULT_TODO_FILTER) {
|
|
37
|
+
if (raw === undefined || raw === null)
|
|
38
|
+
return { ...base };
|
|
39
|
+
if (typeof raw !== 'object' || Array.isArray(raw))
|
|
40
|
+
throw invalid('filter must be an object');
|
|
41
|
+
const input = raw;
|
|
42
|
+
const status = input.status === undefined ? base.status : input.status;
|
|
43
|
+
if (!STATUSES.includes(status))
|
|
44
|
+
throw invalid(`status must be one of ${STATUSES.join(', ')}`);
|
|
45
|
+
const list = (value, name) => {
|
|
46
|
+
if (value === undefined || value === null)
|
|
47
|
+
return [];
|
|
48
|
+
const items = Array.isArray(value) ? value : [value];
|
|
49
|
+
if (items.length > 20)
|
|
50
|
+
throw invalid(`${name} has too many values`);
|
|
51
|
+
return items.map(item => text(item, name, 100)).filter(Boolean);
|
|
52
|
+
};
|
|
53
|
+
const tags = input.tags === undefined ? base.tags : [...new Set(list(input.tags, 'tags').map(tag => tag.replace(/^#/, '')))];
|
|
54
|
+
const priority = input.priority === undefined ? base.priority : [...new Set(list(input.priority, 'priority'))];
|
|
55
|
+
for (const value of priority)
|
|
56
|
+
if (!PRIORITIES.includes(value))
|
|
57
|
+
throw invalid(`priority must be one of ${PRIORITIES.join(', ')}`);
|
|
58
|
+
const from = input.from === undefined ? base.from : localDate(input.from, 'from');
|
|
59
|
+
const to = input.to === undefined ? base.to : localDate(input.to, 'to');
|
|
60
|
+
if (from && to && from > to)
|
|
61
|
+
throw invalid('from must not be after to');
|
|
62
|
+
return {
|
|
63
|
+
status: status,
|
|
64
|
+
query: input.query === undefined ? base.query : text(input.query, 'query', 500),
|
|
65
|
+
tags,
|
|
66
|
+
priority: priority,
|
|
67
|
+
from,
|
|
68
|
+
to,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function todoSearchWire(filter) {
|
|
72
|
+
return {
|
|
73
|
+
query: filter.query,
|
|
74
|
+
includeDeleted: false,
|
|
75
|
+
taskStatus: filter.status,
|
|
76
|
+
taskTagFilter: filter.tags,
|
|
77
|
+
...(filter.priority.length ? { taskPriorityFilter: filter.priority } : {}),
|
|
78
|
+
limit: LIST_LIMIT,
|
|
79
|
+
scanLimit: SCAN_LIMIT,
|
|
80
|
+
includeEditText: true,
|
|
81
|
+
...(filter.from ? { startDate: new Date(`${filter.from}T00:00:00`).toISOString() } : {}),
|
|
82
|
+
...(filter.to ? { endDate: new Date(`${filter.to}T23:59:59.999`).toISOString() } : {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function toTodoList(response, filter) {
|
|
86
|
+
return { tasks: response.tasks, total: response.meta.total_count, hasMore: response.meta.has_more, filter };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Task changes from the panel or the model. Each names a task by its stable
|
|
90
|
+
* taskId; `due: null` clears the due time and `priority: null` the priority.
|
|
91
|
+
*/
|
|
92
|
+
export function parseTodoUpdates(raw) {
|
|
93
|
+
if (!Array.isArray(raw) || !raw.length)
|
|
94
|
+
throw invalid('updates must be a non-empty array');
|
|
95
|
+
if (raw.length > MAX_UPDATES)
|
|
96
|
+
throw invalid(`At most ${MAX_UPDATES} updates at a time`);
|
|
97
|
+
return raw.map((entry, index) => {
|
|
98
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
99
|
+
throw invalid(`updates[${index}] must be an object`);
|
|
100
|
+
const input = entry;
|
|
101
|
+
const taskId = text(input.taskId, `updates[${index}].taskId`, 200);
|
|
102
|
+
if (!taskId)
|
|
103
|
+
throw invalid(`updates[${index}].taskId is required`);
|
|
104
|
+
const update = { taskId };
|
|
105
|
+
const noteId = text(input.noteId, `updates[${index}].noteId`, 200);
|
|
106
|
+
if (noteId)
|
|
107
|
+
update.noteId = noteId;
|
|
108
|
+
if (input.checked !== undefined) {
|
|
109
|
+
if (typeof input.checked !== 'boolean')
|
|
110
|
+
throw invalid(`updates[${index}].checked must be true or false`);
|
|
111
|
+
update.checked = input.checked;
|
|
112
|
+
}
|
|
113
|
+
if (input.priority !== undefined) {
|
|
114
|
+
if (input.priority !== null && input.priority !== 'none' && !['high', 'medium', 'low'].includes(input.priority)) {
|
|
115
|
+
throw invalid(`updates[${index}].priority must be high, medium, low or null`);
|
|
116
|
+
}
|
|
117
|
+
update.priority = input.priority === null || input.priority === 'none' ? null : input.priority;
|
|
118
|
+
}
|
|
119
|
+
if (input.due !== undefined) {
|
|
120
|
+
if (input.due === null) {
|
|
121
|
+
update.schedule = null;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const due = input.due;
|
|
125
|
+
const date = localDate(typeof due === 'string' ? due : due?.date, `updates[${index}].due.date`);
|
|
126
|
+
if (!date)
|
|
127
|
+
throw invalid(`updates[${index}].due.date is required`);
|
|
128
|
+
const time = typeof due === 'object' ? text(due.time, `updates[${index}].due.time`, 5) : '';
|
|
129
|
+
if (time && !TIME.test(time))
|
|
130
|
+
throw invalid(`updates[${index}].due.time must be HH:mm`);
|
|
131
|
+
update.schedule = { date, time: time || null };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (input.text !== undefined) {
|
|
135
|
+
const words = text(input.text, `updates[${index}].text`, 2000).replace(/\s+/g, ' ');
|
|
136
|
+
if (!words)
|
|
137
|
+
throw invalid(`updates[${index}].text cannot be empty`);
|
|
138
|
+
update.text = words;
|
|
139
|
+
}
|
|
140
|
+
if (update.checked === undefined && update.priority === undefined && update.schedule === undefined && update.text === undefined) {
|
|
141
|
+
throw invalid(`updates[${index}] changes nothing`);
|
|
142
|
+
}
|
|
143
|
+
return update;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const MAX_APPEND = 20;
|
|
147
|
+
const POINT_FORMATS = ['date', 'datetime', 'datetime-seconds', 'time'];
|
|
148
|
+
function priorityValue(value, name) {
|
|
149
|
+
if (value === null || value === 'none')
|
|
150
|
+
return null;
|
|
151
|
+
if (!['high', 'medium', 'low'].includes(value))
|
|
152
|
+
throw invalid(`${name} must be high, medium, low or null`);
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
/** Tasks typed into the panel's quick add: `[{text, priority?, due?: {date, time?}}]`. */
|
|
156
|
+
export function parseTodoAppend(raw) {
|
|
157
|
+
if (!Array.isArray(raw) || !raw.length)
|
|
158
|
+
throw invalid('items must be a non-empty array');
|
|
159
|
+
if (raw.length > MAX_APPEND)
|
|
160
|
+
throw invalid(`At most ${MAX_APPEND} tasks at a time`);
|
|
161
|
+
return raw.map((entry, index) => {
|
|
162
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
163
|
+
throw invalid(`items[${index}] must be an object`);
|
|
164
|
+
const input = entry;
|
|
165
|
+
const taskText = text(input.text, `items[${index}].text`, 2000).replace(/\s*\n\s*/g, ' ');
|
|
166
|
+
if (!taskText)
|
|
167
|
+
throw invalid(`items[${index}].text is required`);
|
|
168
|
+
const item = { text: taskText };
|
|
169
|
+
if (input.priority !== undefined)
|
|
170
|
+
item.priority = priorityValue(input.priority, `items[${index}].priority`);
|
|
171
|
+
if (input.due !== undefined && input.due !== null) {
|
|
172
|
+
const due = input.due;
|
|
173
|
+
const date = localDate(due?.date, `items[${index}].due.date`);
|
|
174
|
+
if (!date)
|
|
175
|
+
throw invalid(`items[${index}].due.date is required`);
|
|
176
|
+
const time = text(due.time, `items[${index}].due.time`, 5);
|
|
177
|
+
if (time && !TIME.test(time))
|
|
178
|
+
throw invalid(`items[${index}].due.time must be HH:mm`);
|
|
179
|
+
item.schedule = { date, time: time || null };
|
|
180
|
+
}
|
|
181
|
+
return item;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The panel's undo: put tasks back to the values a change reported as `*_from`
|
|
186
|
+
* (`due` is the exact time point it had), or remove tasks it just added.
|
|
187
|
+
*/
|
|
188
|
+
const MAX_SUGGESTED = 12;
|
|
189
|
+
/** The model's proposal: `{taskId, noteId?, note?, subtasks: [{text, priority?, due?}]}`. */
|
|
190
|
+
export function parseTodoSuggest(input) {
|
|
191
|
+
const taskId = text(input.taskId, 'taskId', 200);
|
|
192
|
+
if (!taskId)
|
|
193
|
+
throw invalid('taskId is required');
|
|
194
|
+
const noteId = text(input.noteId, 'noteId', 200) || null;
|
|
195
|
+
const note = text(input.note, 'note', 500).replace(/\s+/g, ' ');
|
|
196
|
+
if (Array.isArray(input.subtasks) && input.subtasks.length > MAX_SUGGESTED)
|
|
197
|
+
throw invalid(`At most ${MAX_SUGGESTED} subtasks`);
|
|
198
|
+
const items = parseTodoAppend(input.subtasks).map(item => ({ ...item, text: item.text.slice(0, 500) }));
|
|
199
|
+
return { taskId, noteId, note, items };
|
|
200
|
+
}
|
|
201
|
+
const MAX_PARAGRAPH_BYTES = 64 * 1024;
|
|
202
|
+
const BLOCK_TYPES = new Set(['taskList', 'taskItem', 'bulletList', 'orderedList', 'listItem', 'paragraph', 'heading', 'blockquote', 'codeBlock']);
|
|
203
|
+
/** A task's first paragraph as a text edit found it: inline nodes only, so undo cannot smuggle in blocks. */
|
|
204
|
+
function restoreParagraph(value, name) {
|
|
205
|
+
const node = value;
|
|
206
|
+
if (!node || typeof node !== 'object' || Array.isArray(node) || node.type !== 'paragraph')
|
|
207
|
+
throw invalid(`${name} must be a paragraph node`);
|
|
208
|
+
if (node.content !== undefined && !Array.isArray(node.content))
|
|
209
|
+
throw invalid(`${name}.content must be an array`);
|
|
210
|
+
if (JSON.stringify(node).length > MAX_PARAGRAPH_BYTES)
|
|
211
|
+
throw invalid(`${name} is too large`);
|
|
212
|
+
for (const child of (node.content ?? [])) {
|
|
213
|
+
const type = child && typeof child === 'object' ? child.type : undefined;
|
|
214
|
+
if (typeof type !== 'string' || BLOCK_TYPES.has(type))
|
|
215
|
+
throw invalid(`${name} may only hold inline nodes`);
|
|
216
|
+
}
|
|
217
|
+
return node;
|
|
218
|
+
}
|
|
219
|
+
export function parseTodoRestore(raw) {
|
|
220
|
+
if (!Array.isArray(raw) || !raw.length)
|
|
221
|
+
throw invalid('entries must be a non-empty array');
|
|
222
|
+
if (raw.length > MAX_UPDATES * 4)
|
|
223
|
+
throw invalid('Too many entries');
|
|
224
|
+
return raw.map((entry, index) => {
|
|
225
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
226
|
+
throw invalid(`entries[${index}] must be an object`);
|
|
227
|
+
const input = entry;
|
|
228
|
+
const taskId = text(input.taskId, `entries[${index}].taskId`, 200);
|
|
229
|
+
const noteId = text(input.noteId, `entries[${index}].noteId`, 200);
|
|
230
|
+
if (!taskId || !noteId)
|
|
231
|
+
throw invalid(`entries[${index}] needs taskId and noteId`);
|
|
232
|
+
const restore = { taskId, noteId };
|
|
233
|
+
if (input.remove === true)
|
|
234
|
+
return { ...restore, remove: true };
|
|
235
|
+
if (input.checked !== undefined) {
|
|
236
|
+
if (typeof input.checked !== 'boolean')
|
|
237
|
+
throw invalid(`entries[${index}].checked must be true or false`);
|
|
238
|
+
restore.checked = input.checked;
|
|
239
|
+
}
|
|
240
|
+
if (input.priority !== undefined)
|
|
241
|
+
restore.priority = priorityValue(input.priority, `entries[${index}].priority`);
|
|
242
|
+
if (input.due !== undefined) {
|
|
243
|
+
if (input.due === null) {
|
|
244
|
+
restore.dueAt = null;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const due = input.due;
|
|
248
|
+
const iso = text(due?.iso, `entries[${index}].due.iso`, 40);
|
|
249
|
+
if (!iso || Number.isNaN(new Date(iso).getTime()))
|
|
250
|
+
throw invalid(`entries[${index}].due.iso must be a date-time`);
|
|
251
|
+
if (!POINT_FORMATS.includes(due.displayFormat))
|
|
252
|
+
throw invalid(`entries[${index}].due.displayFormat is invalid`);
|
|
253
|
+
restore.dueAt = { iso, displayFormat: due.displayFormat };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (input.paragraph !== undefined)
|
|
257
|
+
restore.paragraph = restoreParagraph(input.paragraph, `entries[${index}].paragraph`);
|
|
258
|
+
if (restore.checked === undefined && restore.priority === undefined && restore.dueAt === undefined && restore.paragraph === undefined) {
|
|
259
|
+
throw invalid(`entries[${index}] changes nothing`);
|
|
260
|
+
}
|
|
261
|
+
return restore;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const PRIORITY_MARK = { high: '!!!', medium: '!!', low: '!' };
|
|
265
|
+
function dueText(task) {
|
|
266
|
+
const point = task.due_time;
|
|
267
|
+
if (!point)
|
|
268
|
+
return '';
|
|
269
|
+
const date = new Date(point.iso);
|
|
270
|
+
if (Number.isNaN(date.getTime()))
|
|
271
|
+
return '';
|
|
272
|
+
const day = formatLocalDate(date);
|
|
273
|
+
return point.displayFormat !== 'date' ? `${day} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}` : day;
|
|
274
|
+
}
|
|
275
|
+
/** The list as compact lines the model can act on by task id. */
|
|
276
|
+
export function formatTodoList(list, max = 40) {
|
|
277
|
+
const { filter } = list;
|
|
278
|
+
const scope = [
|
|
279
|
+
filter.status === 'all' ? 'all tasks' : `${filter.status} tasks`,
|
|
280
|
+
filter.query ? `matching "${filter.query}"` : '',
|
|
281
|
+
filter.tags.length ? `tagged ${filter.tags.map(tag => `#${tag}`).join(' ')}` : '',
|
|
282
|
+
filter.priority.length ? `priority ${filter.priority.join('/')}` : '',
|
|
283
|
+
filter.from || filter.to ? `scheduled ${filter.from ?? '…'} to ${filter.to ?? '…'}` : '',
|
|
284
|
+
].filter(Boolean).join(', ');
|
|
285
|
+
const lines = [`${list.total}${list.hasMore ? '+' : ''} ${scope}.`];
|
|
286
|
+
for (const task of list.tasks.slice(0, max)) {
|
|
287
|
+
const extras = [PRIORITY_MARK[task.priority ?? ''], dueText(task) && `due ${dueText(task)}`, `in "${task.note_title || 'Untitled'}"`].filter(Boolean).join(' · ');
|
|
288
|
+
lines.push(`${' '.repeat(Math.min(task.depth, 4))}- [${task.checked ? 'x' : ' '}] ${task.text} (${extras}) [${task.task_id}]`);
|
|
289
|
+
}
|
|
290
|
+
if (list.tasks.length > max)
|
|
291
|
+
lines.push(`… ${list.tasks.length - max} more in the panel.`);
|
|
292
|
+
return lines.join('\n');
|
|
293
|
+
}
|