@dinoxx/dinox-cli 2.18.5 → 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.
Files changed (33) hide show
  1. package/dist/commands/notes/contentEngine.js +8 -4
  2. package/dist/commands/schema/renderSkills.js +3 -1
  3. package/dist/commands/todo/contentModel.d.ts +5 -3
  4. package/dist/commands/todo/contentModel.js +7 -5
  5. package/dist/commands/todo/dryRun.d.ts +9 -7
  6. package/dist/commands/todo/dryRun.js +99 -86
  7. package/dist/commands/todo/index.js +279 -93
  8. package/dist/commands/todo/repo.d.ts +128 -7
  9. package/dist/commands/todo/repo.js +474 -130
  10. package/dist/commands/todo/taskModel.d.ts +20 -1
  11. package/dist/commands/todo/taskModel.js +153 -20
  12. package/dist/commands/todo/taskPatch.d.ts +119 -0
  13. package/dist/commands/todo/taskPatch.js +502 -0
  14. package/dist/commands/todo/taskText.d.ts +26 -0
  15. package/dist/commands/todo/taskText.js +221 -0
  16. package/dist/dsh-plugin/lib/client.js +713 -289
  17. package/dist/dsh-plugin/lib/index.js +7 -2
  18. package/dist/dsh-plugin/package.json +1 -1
  19. package/dist/dsh-plugin/runtime.json +1 -1
  20. package/dist/editor/compat.d.ts +6 -0
  21. package/dist/editor/compat.js +18 -0
  22. package/dist/editor/daemon.js +27 -0
  23. package/dist/editor/mcp.js +99 -2
  24. package/dist/editor/service.d.ts +57 -1
  25. package/dist/editor/service.js +174 -7
  26. package/dist/editor/todos.d.ts +67 -0
  27. package/dist/editor/todos.js +293 -0
  28. package/dist/editor-ui/mcp-app.html +262 -253
  29. package/dist/integrations/dsh/host.js +10 -2
  30. package/dist/utils/tiptapMarkdown.js +15 -1
  31. package/dist/vendor/electron/shared/task-priority.d.ts +42 -0
  32. package/dist/vendor/electron/shared/task-priority.js +186 -0
  33. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
+ import { type TaskPriority } from '../../vendor/electron/shared/task-priority.js';
1
2
  export type TaskStatusFilter = 'all' | 'completed' | 'uncompleted';
3
+ /** `none` matches tasks without a priority. */
4
+ export type TaskPriorityFilter = TaskPriority | 'none';
2
5
  export type TaskTimeDisplayFormat = 'date' | 'datetime' | 'datetime-seconds' | 'time';
3
6
  export type TaskTimePoint = {
4
7
  iso: string;
@@ -11,8 +14,11 @@ export type TaskDateRangeFilter = {
11
14
  export type TodoTaskSourceRow = {
12
15
  id: string | null;
13
16
  title?: string | null;
17
+ /** Source of truth; `image_detail` is only read when this is missing or unreadable. */
18
+ content_json?: unknown;
14
19
  image_detail: unknown;
15
20
  tags: string | null;
21
+ zettel_boxes?: unknown;
16
22
  created_at: string | null;
17
23
  updated_at: string | null;
18
24
  };
@@ -21,6 +27,8 @@ export type FlattenedTask = {
21
27
  noteTitle: string;
22
28
  taskId: string;
23
29
  text: string;
30
+ /** The words as the editor's inline edit shows them (`#tags` in place). */
31
+ editText: string;
24
32
  checked: boolean;
25
33
  createdAt: Date;
26
34
  createdAtRaw: string | null;
@@ -28,10 +36,21 @@ export type FlattenedTask = {
28
36
  dueTime?: TaskTimePoint;
29
37
  tags?: string[];
30
38
  noteTags?: string[];
39
+ noteBoxIds?: string[];
40
+ priority: TaskPriority | null;
31
41
  depth: number;
32
42
  hasChildren: boolean;
33
43
  parentId: string | null;
34
44
  };
35
45
  export declare function buildTaskKey(noteId: string, taskId: string): string;
36
46
  export declare function extractFlattenedTasks(rows: TodoTaskSourceRow[]): FlattenedTask[];
37
- export declare function filterTasksForTodoList(allTasks: FlattenedTask[], query: string, taskStatus: TaskStatusFilter, taskTagFilter: string[], taskDateRange?: TaskDateRangeFilter): FlattenedTask[];
47
+ export declare function filterTasksForTodoList(allTasks: FlattenedTask[], query: string, taskStatus: TaskStatusFilter, taskTagFilter: string[], taskDateRange?: TaskDateRangeFilter, taskPriorityFilter?: TaskPriorityFilter[]): FlattenedTask[];
48
+ /**
49
+ * The app's schedule rule: an explicit start/due wins (date-only points cover the whole
50
+ * local day, time-only points sit on the note's day); an undated task lives on the local
51
+ * day its note was created. A task matches when its schedule overlaps the range.
52
+ */
53
+ export declare function resolveTaskScheduleMs(task: Pick<FlattenedTask, 'startTime' | 'dueTime' | 'createdAt'>): {
54
+ startMs: number;
55
+ endMs: number;
56
+ } | null;
@@ -1,4 +1,6 @@
1
+ import { normalizeTaskPriority } from '../../vendor/electron/shared/task-priority.js';
1
2
  import { buildLegacyTaskId } from './taskIdentity.js';
3
+ import { taskEditText } from './taskText.js';
2
4
  const DEFAULT_TASK_TIME_DISPLAY_FORMAT = 'datetime';
3
5
  export function buildTaskKey(noteId, taskId) {
4
6
  return `${noteId}:${taskId}`;
@@ -10,7 +12,7 @@ export function extractFlattenedTasks(rows) {
10
12
  if (!noteId) {
11
13
  continue;
12
14
  }
13
- const taskItems = parseImageDetailTaskItems(row.image_detail);
15
+ const taskItems = resolveNoteTaskItems(row);
14
16
  if (taskItems.length === 0) {
15
17
  continue;
16
18
  }
@@ -22,18 +24,29 @@ export function extractFlattenedTasks(rows) {
22
24
  createdAt,
23
25
  createdAtRaw,
24
26
  noteTags: parseNoteTags(row.tags),
27
+ noteBoxIds: parseNoteBoxIds(row.zettel_boxes),
25
28
  taskItems,
26
29
  preorderState,
27
30
  }));
28
31
  }
29
32
  extracted.sort((left, right) => right.createdAt.getTime() - left.createdAt.getTime());
30
- return flattenTasks(extracted);
33
+ // A task id copied into several places of one note is one task; the first occurrence wins.
34
+ const seen = new Set();
35
+ return flattenTasks(extracted).filter((task) => {
36
+ const key = buildTaskKey(task.noteId, task.taskId);
37
+ if (seen.has(key))
38
+ return false;
39
+ seen.add(key);
40
+ return true;
41
+ });
31
42
  }
32
- export function filterTasksForTodoList(allTasks, query, taskStatus, taskTagFilter, taskDateRange) {
43
+ export function filterTasksForTodoList(allTasks, query, taskStatus, taskTagFilter, taskDateRange, taskPriorityFilter = []) {
33
44
  let filteredTasks = allTasks;
45
+ // Like the app: the keyword matches the task text or the title of the note it lives in.
34
46
  const normalizedQuery = query.trim().toLocaleLowerCase();
35
47
  if (normalizedQuery) {
36
- filteredTasks = filteredTasks.filter((task) => task.text.toLocaleLowerCase().includes(normalizedQuery));
48
+ filteredTasks = filteredTasks.filter((task) => task.text.toLocaleLowerCase().includes(normalizedQuery)
49
+ || task.noteTitle.toLocaleLowerCase().includes(normalizedQuery));
37
50
  }
38
51
  if (taskStatus === 'completed') {
39
52
  filteredTasks = filteredTasks.filter((task) => task.checked);
@@ -41,8 +54,17 @@ export function filterTasksForTodoList(allTasks, query, taskStatus, taskTagFilte
41
54
  else if (taskStatus === 'uncompleted') {
42
55
  filteredTasks = filteredTasks.filter((task) => !task.checked);
43
56
  }
44
- if (taskTagFilter.length > 0) {
45
- filteredTasks = filteredTasks.filter((task) => taskTagFilter.every((tag) => task.tags?.some((taskTag) => taskTag.trim() === tag)));
57
+ // A task carries a tag through its own #hashtag or through the note's tags.
58
+ const wantedTags = taskTagFilter.map(normalizeTagKey).filter(Boolean);
59
+ if (wantedTags.length > 0) {
60
+ filteredTasks = filteredTasks.filter((task) => {
61
+ const have = new Set([...(task.tags ?? []), ...(task.noteTags ?? [])].map(normalizeTagKey));
62
+ return wantedTags.every((tag) => have.has(tag));
63
+ });
64
+ }
65
+ if (taskPriorityFilter.length > 0) {
66
+ const wanted = new Set(taskPriorityFilter);
67
+ filteredTasks = filteredTasks.filter((task) => wanted.has(task.priority ?? 'none'));
46
68
  }
47
69
  const range = resolveTaskDateRange(taskDateRange);
48
70
  if (range) {
@@ -50,6 +72,76 @@ export function filterTasksForTodoList(allTasks, query, taskStatus, taskTagFilte
50
72
  }
51
73
  return filteredTasks;
52
74
  }
75
+ function normalizeTagKey(tag) {
76
+ return tag.trim().replace(/^#+/, '').trim().toLocaleLowerCase();
77
+ }
78
+ /** Top-level task items of a note: from content_json (the source of truth), else image_detail. */
79
+ function resolveNoteTaskItems(row) {
80
+ const doc = parseContentJsonDoc(row.content_json);
81
+ if (doc)
82
+ return collectTopLevelTaskItems(doc);
83
+ return parseImageDetailTaskItems(row.image_detail);
84
+ }
85
+ function parseContentJsonDoc(raw) {
86
+ let value = raw;
87
+ if (typeof raw === 'string') {
88
+ const trimmed = raw.trim();
89
+ if (!trimmed)
90
+ return null;
91
+ try {
92
+ value = JSON.parse(trimmed);
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ }
98
+ if (!value || typeof value !== 'object')
99
+ return null;
100
+ const doc = value;
101
+ return doc.type === 'doc' && Array.isArray(doc.content) ? doc : null;
102
+ }
103
+ /** Outermost taskItems in document order (nested ones are reached through their parent). */
104
+ function collectTopLevelTaskItems(node) {
105
+ const out = [];
106
+ const visit = (value) => {
107
+ if (!value || typeof value !== 'object')
108
+ return;
109
+ const current = value;
110
+ if (current.type === 'taskItem') {
111
+ out.push(current);
112
+ return;
113
+ }
114
+ if (Array.isArray(current.content))
115
+ current.content.forEach(visit);
116
+ };
117
+ visit(node);
118
+ return out;
119
+ }
120
+ function parseNoteBoxIds(raw) {
121
+ let value = raw;
122
+ if (typeof raw === 'string') {
123
+ const trimmed = raw.trim();
124
+ if (!trimmed)
125
+ return undefined;
126
+ try {
127
+ value = JSON.parse(trimmed);
128
+ }
129
+ catch {
130
+ return undefined;
131
+ }
132
+ }
133
+ if (!Array.isArray(value))
134
+ return undefined;
135
+ const ids = uniqueTrimmedStrings(value.map((entry) => {
136
+ if (typeof entry === 'string')
137
+ return entry;
138
+ if (entry && typeof entry === 'object' && typeof entry.id === 'string') {
139
+ return entry.id;
140
+ }
141
+ return '';
142
+ }));
143
+ return ids.length > 0 ? ids : undefined;
144
+ }
53
145
  function parseImageDetailTaskItems(raw) {
54
146
  if (Array.isArray(raw)) {
55
147
  return pickTaskItems(raw);
@@ -236,7 +328,7 @@ function extractNestedTasks(content) {
236
328
  return nested;
237
329
  }
238
330
  function extractTasksFromDetailWithHierarchy(input) {
239
- const { noteId, noteTitle, createdAt, createdAtRaw, noteTags, taskItems, preorderState, depth = 0, } = input;
331
+ const { noteId, noteTitle, createdAt, createdAtRaw, noteTags, noteBoxIds, taskItems, preorderState, depth = 0, } = input;
240
332
  const result = [];
241
333
  for (const item of taskItems) {
242
334
  const preorderIndex = preorderState.nextIndex;
@@ -246,6 +338,7 @@ function extractTasksFromDetailWithHierarchy(input) {
246
338
  buildLegacyTaskId(noteId, preorderIndex, item);
247
339
  const checked = normalizeTaskChecked(item.checked) ?? normalizeTaskChecked(item.attrs?.checked) ?? false;
248
340
  const text = getTaskText(item).trim();
341
+ const editText = taskEditText(item);
249
342
  const tags = getTaskTags(item);
250
343
  const { startTime, dueTime } = getTaskTimeRange(item);
251
344
  const children = extractTasksFromDetailWithHierarchy({
@@ -254,6 +347,7 @@ function extractTasksFromDetailWithHierarchy(input) {
254
347
  createdAt,
255
348
  createdAtRaw,
256
349
  noteTags,
350
+ noteBoxIds,
257
351
  taskItems: extractNestedTasks(item.content),
258
352
  preorderState,
259
353
  depth: depth + 1,
@@ -263,6 +357,7 @@ function extractTasksFromDetailWithHierarchy(input) {
263
357
  noteTitle,
264
358
  taskId,
265
359
  text,
360
+ editText,
266
361
  checked,
267
362
  createdAt,
268
363
  createdAtRaw,
@@ -270,6 +365,8 @@ function extractTasksFromDetailWithHierarchy(input) {
270
365
  dueTime,
271
366
  tags: tags.length > 0 ? tags : undefined,
272
367
  noteTags,
368
+ noteBoxIds,
369
+ priority: normalizeTaskPriority(item.attrs?.priority),
273
370
  children,
274
371
  depth,
275
372
  });
@@ -284,6 +381,7 @@ function flattenTasks(tasks, parentId = null) {
284
381
  noteTitle: task.noteTitle,
285
382
  taskId: task.taskId,
286
383
  text: task.text,
384
+ editText: task.editText,
287
385
  checked: task.checked,
288
386
  createdAt: task.createdAt,
289
387
  createdAtRaw: task.createdAtRaw,
@@ -291,6 +389,8 @@ function flattenTasks(tasks, parentId = null) {
291
389
  dueTime: task.dueTime,
292
390
  tags: task.tags,
293
391
  noteTags: task.noteTags,
392
+ noteBoxIds: task.noteBoxIds,
393
+ priority: task.priority,
294
394
  depth: task.depth,
295
395
  hasChildren: task.children.length > 0,
296
396
  parentId,
@@ -322,20 +422,53 @@ function resolveTaskDateRange(taskDateRange) {
322
422
  endMs: Math.max(start.getTime(), end.getTime()),
323
423
  };
324
424
  }
425
+ /**
426
+ * The app's schedule rule: an explicit start/due wins (date-only points cover the whole
427
+ * local day, time-only points sit on the note's day); an undated task lives on the local
428
+ * day its note was created. A task matches when its schedule overlaps the range.
429
+ */
430
+ export function resolveTaskScheduleMs(task) {
431
+ const startPoint = task.startTime ?? task.dueTime;
432
+ const noteDate = task.createdAt;
433
+ if (!startPoint) {
434
+ if (Number.isNaN(noteDate.getTime()))
435
+ return null;
436
+ return { startMs: startOfLocalDayMs(noteDate), endMs: endOfLocalDayMs(noteDate) };
437
+ }
438
+ const endPoint = task.dueTime ?? startPoint;
439
+ const rawStart = resolveTaskTimePointMs(startPoint, noteDate);
440
+ const rawEnd = resolveTaskTimePointMs(endPoint, noteDate);
441
+ if (rawStart === null || rawEnd === null)
442
+ return null;
443
+ return {
444
+ startMs: startPoint.displayFormat === 'date' ? startOfLocalDayMs(new Date(rawStart)) : rawStart,
445
+ endMs: endPoint.displayFormat === 'date' ? endOfLocalDayMs(new Date(rawEnd)) : rawEnd,
446
+ };
447
+ }
448
+ function startOfLocalDayMs(value) {
449
+ const date = new Date(value);
450
+ date.setHours(0, 0, 0, 0);
451
+ return date.getTime();
452
+ }
453
+ function endOfLocalDayMs(value) {
454
+ const date = new Date(value);
455
+ date.setHours(24, 0, 0, 0);
456
+ return date.getTime() - 1;
457
+ }
458
+ function resolveTaskTimePointMs(point, noteDate) {
459
+ const pointMs = parseTaskPointMs(point);
460
+ if (pointMs === null)
461
+ return null;
462
+ if (point.displayFormat !== 'time')
463
+ return pointMs;
464
+ const pointDate = new Date(pointMs);
465
+ const inherited = new Date(noteDate);
466
+ inherited.setHours(pointDate.getHours(), pointDate.getMinutes(), pointDate.getSeconds(), pointDate.getMilliseconds());
467
+ return inherited.getTime();
468
+ }
325
469
  function isTaskInDateRange(task, range) {
326
- const dueMs = parseTaskPointMs(task.dueTime);
327
- if (dueMs !== null) {
328
- return dueMs >= range.startMs && dueMs <= range.endMs;
329
- }
330
- const startMs = parseTaskPointMs(task.startTime);
331
- if (startMs !== null) {
332
- return startMs >= range.startMs && startMs <= range.endMs;
333
- }
334
- const createdAtMs = task.createdAt.getTime();
335
- if (!Number.isNaN(createdAtMs) && createdAtMs >= range.startMs && createdAtMs <= range.endMs) {
336
- return true;
337
- }
338
- return false;
470
+ const schedule = resolveTaskScheduleMs(task);
471
+ return schedule !== null && schedule.startMs <= range.endMs && schedule.endMs >= range.startMs;
339
472
  }
340
473
  function parseTaskPointMs(point) {
341
474
  if (!point?.iso) {
@@ -0,0 +1,119 @@
1
+ import { type TaskPriority } from '../../vendor/electron/shared/task-priority.js';
2
+ import type { TaskTimePoint } from './taskModel.js';
3
+ type JsonNode = {
4
+ type?: unknown;
5
+ id?: unknown;
6
+ checked?: unknown;
7
+ text?: unknown;
8
+ attrs?: Record<string, unknown>;
9
+ content?: unknown[];
10
+ [key: string]: unknown;
11
+ };
12
+ export type { TaskPriority } from '../../vendor/electron/shared/task-priority.js';
13
+ export type TaskPatch = {
14
+ taskId: string;
15
+ checked?: boolean;
16
+ /** `null` clears the priority. */
17
+ priority?: TaskPriority | null;
18
+ /** `null` clears the due time; omitted leaves it untouched. */
19
+ dueAt?: TaskTimePoint | null;
20
+ /**
21
+ * `false` sets exactly this task's checked state without touching its subtasks or parents.
22
+ * Undo uses it to put back the states a cascade changed, task by task.
23
+ */
24
+ cascade?: boolean;
25
+ /** Deletes the task with its subtasks (undo of a task just added); an emptied list goes too. */
26
+ remove?: boolean;
27
+ /**
28
+ * The task's words (`#tags` written in place). Only the changed span is rewritten, so
29
+ * formatting, hashtags and the due time outside it stay exactly as they were.
30
+ */
31
+ text?: string;
32
+ /** Replaces the task's first paragraph verbatim (undo of a text edit). */
33
+ paragraph?: JsonNode;
34
+ };
35
+ export type TaskPatchResult = {
36
+ task_id: string;
37
+ checked_from: boolean;
38
+ checked_to: boolean;
39
+ priority_from: TaskPriority | null;
40
+ priority_to: TaskPriority | null;
41
+ due_from: TaskTimePoint | null;
42
+ due_to: TaskTimePoint | null;
43
+ /** Other tasks whose checked state flipped through the cascade (descendants or ancestors). */
44
+ cascaded_task_ids: string[];
45
+ /** The task was deleted. */
46
+ removed?: boolean;
47
+ /** Present when the patch edited the words. */
48
+ text_from?: string;
49
+ text_to?: string;
50
+ /** The first paragraph before a text edit, for an exact undo. */
51
+ paragraph_from?: unknown;
52
+ };
53
+ export type ApplyTaskPatchesOutcome = {
54
+ doc: JsonNode;
55
+ /** True when a patch changed the document (id materialization alone does not count). */
56
+ changed: boolean;
57
+ missingTaskIds: string[];
58
+ results: TaskPatchResult[];
59
+ /** Every task whose checked state flipped, for the legacy HTML `content` column. */
60
+ checkedChanges: Map<string, boolean>;
61
+ /** Preorder ids of every taskItem, matching content_md checklist line order. */
62
+ taskOrder: string[];
63
+ };
64
+ export declare function readTaskChecked(node: JsonNode): boolean;
65
+ export declare function readTaskDuePoint(taskItem: JsonNode): TaskTimePoint | null;
66
+ /**
67
+ * Apply task patches to a document, editing only the targeted taskItem nodes.
68
+ *
69
+ * Checked cascade (same rules as the app): checking a task checks all of its descendants;
70
+ * unchecking a task also unchecks its checked ancestors; parents never auto-complete.
71
+ */
72
+ export declare function applyTaskPatches(sourceDoc: unknown, noteId: string, patches: readonly TaskPatch[]): ApplyTaskPatchesOutcome;
73
+ /** Find a taskItem by id (explicit or legacy) inside an already-materialized document. */
74
+ export declare function findTaskItemById(doc: unknown, noteId: string, taskId: string): JsonNode | null;
75
+ /** Mirror checked-state changes into the legacy HTML `content` column (`<li data-id data-checked>`). */
76
+ export declare function patchLegacyHtmlChecked(html: string | null | undefined, changes: Map<string, boolean>): string | null;
77
+ export type TodoScheduleInput = {
78
+ date: string;
79
+ time?: string | null;
80
+ };
81
+ export declare function parseLocalDateKey(value: string): Date | null;
82
+ export declare function formatLocalDateKey(date: Date): string;
83
+ /** Resolve a local date (plus optional HH:mm) into the task due-time node, like the app. */
84
+ export declare function resolveTodoDuePoint(schedule: TodoScheduleInput): TaskTimePoint;
85
+ export type TodoDraftItem = {
86
+ text: string;
87
+ checked?: boolean;
88
+ priority?: TaskPriority | null;
89
+ schedule?: TodoScheduleInput | null;
90
+ subtasks?: TodoDraftItem[] | null;
91
+ };
92
+ export type CreatedTodoTask = {
93
+ task_id: string;
94
+ text: string;
95
+ checked: boolean;
96
+ priority: TaskPriority | null;
97
+ parent_task_id: string | null;
98
+ due_time: TaskTimePoint | null;
99
+ };
100
+ type NormalizedDraft = {
101
+ text: string;
102
+ checked: boolean;
103
+ priority: TaskPriority | null;
104
+ schedule: TodoScheduleInput | null;
105
+ subtasks: NormalizedDraft[];
106
+ };
107
+ export declare function normalizeTodoDrafts(items: readonly TodoDraftItem[]): NormalizedDraft[];
108
+ export declare function countDrafts(items: readonly NormalizedDraft[]): number;
109
+ /**
110
+ * Build a taskList block for new tasks (subtasks become a nested taskList inside their parent).
111
+ * `created` lists every task in document order, parents before children.
112
+ */
113
+ export declare function buildTaskListBlock(items: readonly NormalizedDraft[], options: {
114
+ parentTaskId: string | null;
115
+ created: CreatedTodoTask[];
116
+ defaultSchedule?: TodoScheduleInput;
117
+ }): JsonNode;
118
+ /** Append a block of new subtasks to a task's own nested list, so siblings stay in one list. */
119
+ export declare function appendSubtaskBlock(taskItem: JsonNode, block: JsonNode): void;