@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.
Files changed (35) 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/daemon/supervisor.d.ts +0 -6
  17. package/dist/daemon/supervisor.js +10 -2
  18. package/dist/dsh-plugin/lib/client.js +713 -289
  19. package/dist/dsh-plugin/lib/index.js +7 -2
  20. package/dist/dsh-plugin/package.json +1 -1
  21. package/dist/dsh-plugin/runtime.json +1 -1
  22. package/dist/editor/compat.d.ts +6 -0
  23. package/dist/editor/compat.js +18 -0
  24. package/dist/editor/daemon.js +27 -0
  25. package/dist/editor/mcp.js +99 -2
  26. package/dist/editor/service.d.ts +57 -1
  27. package/dist/editor/service.js +174 -7
  28. package/dist/editor/todos.d.ts +67 -0
  29. package/dist/editor/todos.js +293 -0
  30. package/dist/editor-ui/mcp-app.html +262 -253
  31. package/dist/integrations/dsh/host.js +10 -2
  32. package/dist/utils/tiptapMarkdown.js +15 -1
  33. package/dist/vendor/electron/shared/task-priority.d.ts +42 -0
  34. package/dist/vendor/electron/shared/task-priority.js +186 -0
  35. package/package.json +1 -1
@@ -2,7 +2,8 @@ import crypto from 'node:crypto';
2
2
  import { DinoxError } from '../../utils/errors.js';
3
3
  import { generateId } from '../../utils/id.js';
4
4
  import { convertMarkdownToNoteContent } from '../../utils/tiptapMarkdown.js';
5
- import { normalizeStoredImageWidthPercent } from '../../utils/tiptapMarkdownSchemaUtils.js';
5
+ import { normalizeStoredImageWidthPercent, serializeMarkdownAttributes } from '../../utils/tiptapMarkdownSchemaUtils.js';
6
+ import { formatTaskPriorityCookie, normalizeTaskPriority } from '../../vendor/electron/shared/task-priority.js';
6
7
  import { escapeLiteralMarkdownText } from '../../utils/tiptapMarkdownSyntax.js';
7
8
  const CONTENT_TEXT_MAX_LENGTH = 300;
8
9
  const MAX_REPLACE_BLOCK_RANGE = 50;
@@ -463,8 +464,11 @@ function inlineMarkdown(nodes) {
463
464
  }
464
465
  if (node.type === 'location')
465
466
  return [stringAttr(node, 'name'), stringAttr(node, 'address')].filter(Boolean).join(' ');
466
- if (node.type === 'time')
467
- return stringAttr(node, 'iso') || stringAttr(node, 'displayFormat');
467
+ if (node.type === 'time') {
468
+ // Same `[time …]` shortcode the app and desktop write, so the due time survives a Markdown round trip.
469
+ const attrs = serializeMarkdownAttributes({ iso: stringAttr(node, 'iso'), displayFormat: stringAttr(node, 'displayFormat') }, ['iso', 'displayFormat']);
470
+ return attrs ? `[time ${attrs}]` : '';
471
+ }
468
472
  if (node.type === 'inlineMath')
469
473
  return `$${stringAttr(node, 'text') || stringAttr(node, 'latex') || stringAttr(node, 'code') || extractPlainText(node)}$`;
470
474
  return extractPlainText(node);
@@ -507,7 +511,7 @@ function taskListToMarkdown(node, depth) {
507
511
  return childBlocks(node).map((item) => {
508
512
  const checked = item.attrs?.checked === true ? 'x' : ' ';
509
513
  const [first, ...rest] = childBlocks(item);
510
- const prefix = `${' '.repeat(depth)}- [${checked}] `;
514
+ const prefix = `${' '.repeat(depth)}- [${checked}] ${formatTaskPriorityCookie(normalizeTaskPriority(item.attrs?.priority))}`;
511
515
  const head = first ? blockToMarkdown(first, depth + 1).replace(/\n/g, '\n ') : '';
512
516
  const tail = rest.map((child) => blockToMarkdown(child, depth + 1)).filter(Boolean).join('\n');
513
517
  return [prefix + head, tail].filter(Boolean).join('\n');
@@ -189,7 +189,9 @@ const GENERATED_COMMAND_SECTIONS = {
189
189
  intro: 'Use these generated commands as the canonical mutation interfaces for todo workflows.',
190
190
  notes: [
191
191
  'Run the same command with `--sync-timeout 20000 --dry-run --format json` first and keep the host timeout 5-10 seconds higher.',
192
- 'For append, prefer explicit `--note-id` unless the user confirms the default target behavior.',
192
+ 'For append without `--note-id`/`--parent`, tasks go to the daily todo note for today (or `--date`), which is created when that day has none; prefer an explicit target when the user names a note.',
193
+ 'Use `--items` for structured tasks (priority, schedule, subtasks); `--priority`/`--due`/`--time` apply to plain `--task`/`--tasks` text.',
194
+ 'Checking a task also checks its subtasks; unchecking one also unchecks its checked parents. Report `cascaded_task_ids` to the user.',
193
195
  'For update, pass the `note_id` returned by todo search as `--note-id` when available; broad task lookup is bounded and refuses truncated results. Legacy ids bind to the searched task snapshot, so search again after the note changes.',
194
196
  ],
195
197
  },
@@ -1,8 +1,6 @@
1
1
  type JsonRecord = Record<string, unknown>;
2
2
  type TodoTaskItemNode = {
3
3
  type: 'taskItem';
4
- id: string;
5
- checked: boolean;
6
4
  attrs: {
7
5
  id: string;
8
6
  checked: boolean;
@@ -10,6 +8,10 @@ type TodoTaskItemNode = {
10
8
  };
11
9
  content: unknown[];
12
10
  };
11
+ type TodoTaskIndexEntry = TodoTaskItemNode & {
12
+ id: string;
13
+ checked: boolean;
14
+ };
13
15
  export type ApplyTaskCheckedStatusResult = {
14
16
  nextDoc: JsonRecord;
15
17
  taskOrder: string[];
@@ -20,7 +22,7 @@ export type ApplyTaskCheckedStatusResult = {
20
22
  export declare function parseTiptapDocFromDb(rawContentJson: string | null): JsonRecord;
21
23
  export declare function createTodoDocFromTasks(taskTexts: string[]): JsonRecord;
22
24
  export declare function appendTasksToDoc(doc: JsonRecord, taskTexts: string[]): JsonRecord;
23
- export declare function deriveImageDetailFromContentJson(doc: JsonRecord, noteId: string): TodoTaskItemNode[];
25
+ export declare function deriveImageDetailFromContentJson(doc: JsonRecord, noteId: string): TodoTaskIndexEntry[];
24
26
  export declare function buildAppendMarkdown(existingMarkdown: string | null, taskTexts: string[]): string;
25
27
  export declare function buildCreateMarkdown(taskTexts: string[]): string;
26
28
  export declare function buildContentTextPreview(contentMd: string): string;
@@ -160,7 +160,8 @@ export function applyTaskCheckedStatus(doc, noteId, taskId, checked) {
160
160
  let attrs = null;
161
161
  if (!explicitTaskId) {
162
162
  attrs = ensureNodeAttrs(node);
163
- node.id = currentTaskId;
163
+ if ('id' in node)
164
+ node.id = currentTaskId;
164
165
  attrs.id = currentTaskId;
165
166
  }
166
167
  if (currentTaskId === normalizedTaskId) {
@@ -171,8 +172,11 @@ export function applyTaskCheckedStatus(doc, noteId, taskId, checked) {
171
172
  if (previousChecked !== checked) {
172
173
  statusChangedCount += 1;
173
174
  }
174
- node.id = currentTaskId;
175
- node.checked = checked;
175
+ // Legacy copies outside attrs are kept in step, never added.
176
+ if ('id' in node)
177
+ node.id = currentTaskId;
178
+ if ('checked' in node)
179
+ node.checked = checked;
176
180
  attrs.id = currentTaskId;
177
181
  attrs.checked = checked;
178
182
  }
@@ -228,8 +232,6 @@ function buildTaskItemNodes(taskTexts) {
228
232
  const taskId = generateId();
229
233
  return {
230
234
  type: 'taskItem',
231
- id: taskId,
232
- checked: false,
233
235
  attrs: {
234
236
  id: taskId,
235
237
  checked: false,
@@ -1,24 +1,26 @@
1
1
  import type { AbstractPowerSyncDatabase } from '@powersync/common';
2
2
  import type { ResolvedDinoxConfig } from '../../config/types.js';
3
3
  import type { DryRunPreview } from '../../utils/dryRun.js';
4
+ import { type AppendTodoTasksOptions, type TodoTaskUpdate } from './repo.js';
5
+ import type { TodoDraftItem } from './taskPatch.js';
4
6
  export declare function buildTodoAppendDryRunPreview(args: {
5
7
  db: AbstractPowerSyncDatabase;
6
8
  config: ResolvedDinoxConfig;
7
9
  offline: boolean;
8
- noteId?: string;
9
- taskTexts: string[];
10
- }): Promise<DryRunPreview>;
10
+ } & Omit<AppendTodoTasksOptions, 'userId'>): Promise<DryRunPreview>;
11
11
  export declare function buildTodoCreateDryRunPreview(args: {
12
12
  config: ResolvedDinoxConfig;
13
13
  offline: boolean;
14
14
  title?: string;
15
- taskTexts: string[];
15
+ taskTexts?: string[];
16
+ items?: TodoDraftItem[];
16
17
  }): Promise<DryRunPreview>;
17
18
  export declare function buildTodoUpdateDryRunPreview(args: {
18
19
  db: AbstractPowerSyncDatabase;
19
20
  config: ResolvedDinoxConfig;
20
21
  offline: boolean;
21
- taskId: string;
22
+ taskId?: string;
22
23
  noteId?: string;
23
- checked: boolean;
24
- }): Promise<DryRunPreview>;
24
+ checked?: boolean;
25
+ updates?: TodoTaskUpdate[];
26
+ } & Pick<TodoTaskUpdate, 'priority' | 'schedule'>): Promise<DryRunPreview>;
@@ -1,6 +1,5 @@
1
1
  import { DinoxError } from '../../utils/errors.js';
2
- import { applyTaskCheckedStatus, buildSummaryTitle, normalizeTaskTexts, patchTaskMarkdownByOrder, parseTiptapDocFromDb, } from './contentModel.js';
3
- import { getLatestTodoAppendTarget, getTodoAppendTargetById, loadTodoTaskCandidatesByTaskId, validateTodoAppendTarget, } from './repo.js';
2
+ import { planTodoAppend, planTodoUpdates, previewCreateTodoNote, } from './repo.js';
4
3
  function buildExecutionWarnings(config, offline) {
5
4
  const warnings = [];
6
5
  if (offline) {
@@ -9,129 +8,143 @@ function buildExecutionWarnings(config, offline) {
9
8
  return warnings;
10
9
  }
11
10
  export async function buildTodoAppendDryRunPreview(args) {
12
- const normalizedTaskTexts = normalizeTaskTexts(args.taskTexts);
13
- const explicitNoteId = typeof args.noteId === 'string' ? args.noteId.trim() : '';
14
- const source = explicitNoteId ? 'explicit' : 'latest_non_empty_image_detail';
15
- const target = explicitNoteId
16
- ? await getTodoAppendTargetById(args.db, explicitNoteId)
17
- : await getLatestTodoAppendTarget(args.db);
18
- if (!target) {
19
- if (explicitNoteId) {
20
- throw new DinoxError(`Note not found: ${explicitNoteId}`);
21
- }
22
- throw new DinoxError('No eligible note found for append. Try `dino todo create ...` first.');
23
- }
24
- validateTodoAppendTarget(target);
11
+ const { db, config, offline, ...options } = args;
12
+ const plan = await planTodoAppend(db, options);
13
+ const taskTexts = plan.tasks.map((task) => task.text);
14
+ const noteId = plan.kind === 'append' ? plan.target.id : null;
15
+ const title = plan.kind === 'append' ? (plan.target.title ?? '').trim() : plan.title;
25
16
  return {
26
17
  dry_run: true,
27
18
  command: 'dino todo append',
28
19
  action: 'append_todo_tasks',
29
20
  risk: 'write',
30
- summary: `Append ${normalizedTaskTexts.length} task(s) to note "${(target.title ?? '').trim()}".`,
31
- warnings: buildExecutionWarnings(args.config, args.offline),
21
+ summary: plan.kind === 'create_daily'
22
+ ? `Create the daily todo note "${title}" with ${plan.tasks.length} task(s).`
23
+ : plan.source === 'task'
24
+ ? `Add ${plan.tasks.length} subtask(s) under task ${plan.parentTaskId} in note "${title}".`
25
+ : `Append ${plan.tasks.length} task(s) to note "${title}".`,
26
+ warnings: buildExecutionWarnings(config, offline),
32
27
  inputs: {
33
- note_id: explicitNoteId || null,
34
- source,
35
- task_count: normalizedTaskTexts.length,
36
- task_texts: normalizedTaskTexts,
28
+ note_id: options.noteId?.trim() || null,
29
+ parent_task_id: options.parentTaskId?.trim() || null,
30
+ date: options.date?.trim() || null,
31
+ source: plan.source,
32
+ task_count: plan.tasks.length,
33
+ task_texts: taskTexts,
37
34
  },
38
35
  targets: [
39
36
  {
40
- id: target.id,
41
- title: (target.title ?? '').trim(),
42
- source,
37
+ id: noteId,
38
+ title,
39
+ source: plan.source,
40
+ created: plan.kind === 'create_daily',
43
41
  },
44
42
  ],
45
43
  changes: {
46
- appended_count: normalizedTaskTexts.length,
47
- task_texts: normalizedTaskTexts,
44
+ appended_count: plan.tasks.length,
45
+ created: plan.kind === 'create_daily',
46
+ day_key: plan.dayKey,
47
+ task_texts: taskTexts,
48
+ // Ids are generated per run; the real write assigns fresh ones.
49
+ tasks: plan.tasks.map(({ task_id: _taskId, ...task }) => task),
48
50
  },
49
51
  };
50
52
  }
51
53
  export async function buildTodoCreateDryRunPreview(args) {
52
- const normalizedTaskTexts = normalizeTaskTexts(args.taskTexts);
53
- const resolvedTitle = args.title?.trim() || buildSummaryTitle(normalizedTaskTexts);
54
+ const preview = previewCreateTodoNote({ title: args.title, taskTexts: args.taskTexts, items: args.items });
55
+ const taskTexts = preview.tasks.map((task) => task.text);
54
56
  return {
55
57
  dry_run: true,
56
58
  command: 'dino todo create',
57
59
  action: 'create_todo_note',
58
60
  risk: 'write',
59
- summary: `Create a new todo note titled "${resolvedTitle}" with ${normalizedTaskTexts.length} task(s).`,
61
+ summary: `Create a new todo note titled "${preview.title}" with ${preview.created_count} task(s).`,
60
62
  warnings: buildExecutionWarnings(args.config, args.offline),
61
63
  inputs: {
62
- title: resolvedTitle,
63
- task_count: normalizedTaskTexts.length,
64
- task_texts: normalizedTaskTexts,
64
+ title: preview.title,
65
+ task_count: preview.created_count,
66
+ task_texts: taskTexts,
65
67
  },
66
68
  changes: {
67
- title: resolvedTitle,
68
- created_count: normalizedTaskTexts.length,
69
- task_texts: normalizedTaskTexts,
69
+ title: preview.title,
70
+ created_count: preview.created_count,
71
+ task_texts: taskTexts,
72
+ tasks: preview.tasks.map(({ task_id: _taskId, ...task }) => task),
70
73
  },
71
74
  };
72
75
  }
73
76
  export async function buildTodoUpdateDryRunPreview(args) {
74
- const taskId = args.taskId.trim();
75
- if (!taskId) {
76
- throw new DinoxError('taskId is required');
77
+ const single = args.updates === undefined;
78
+ const updates = args.updates ?? [{
79
+ taskId: args.taskId ?? '',
80
+ ...(args.noteId !== undefined ? { noteId: args.noteId } : {}),
81
+ ...(args.checked !== undefined ? { checked: args.checked } : {}),
82
+ ...(args.priority !== undefined ? { priority: args.priority } : {}),
83
+ ...(args.schedule !== undefined ? { schedule: args.schedule } : {}),
84
+ }];
85
+ if (single && !args.taskId?.trim()) {
86
+ throw new DinoxError('taskId is required', { code: 'INVALID_ARGUMENT' });
77
87
  }
78
- const candidates = await loadTodoTaskCandidatesByTaskId(args.db, taskId, { noteId: args.noteId });
79
- const matches = [];
80
- for (const candidate of candidates) {
81
- try {
82
- const noteId = (candidate.id ?? '').trim();
83
- if (!noteId) {
84
- continue;
85
- }
86
- const doc = parseTiptapDocFromDb(candidate.content_json);
87
- const applied = applyTaskCheckedStatus(doc, noteId, taskId, args.checked);
88
- if (applied.matchedIndices.length === 0) {
89
- continue;
90
- }
91
- matches.push({
92
- applied,
93
- contentMd: candidate.content_md,
94
- noteId,
95
- title: (candidate.title ?? '').trim(),
96
- checked: applied.matchedCheckedStates[0] ?? args.checked,
97
- });
88
+ const plans = await planTodoUpdates(args.db, updates);
89
+ const tasks = plans.flatMap((plan) => plan.outcome.results.map((result) => ({
90
+ note_id: plan.noteId,
91
+ note_title: (plan.row.title ?? '').trim(),
92
+ ...result,
93
+ updated: plan.write !== null && (result.checked_from !== result.checked_to
94
+ || result.priority_from !== result.priority_to
95
+ || JSON.stringify(result.due_from) !== JSON.stringify(result.due_to)
96
+ || result.cascaded_task_ids.length > 0),
97
+ })));
98
+ const warnings = buildExecutionWarnings(args.config, args.offline);
99
+ if (single) {
100
+ const task = tasks[0];
101
+ const patch = updates[0];
102
+ const changes = {};
103
+ if (patch.checked !== undefined) {
104
+ changes.checked_from = task.checked_from;
105
+ changes.checked_to = task.checked_to;
98
106
  }
99
- catch {
100
- continue;
107
+ if (patch.priority !== undefined) {
108
+ changes.priority_from = task.priority_from;
109
+ changes.priority_to = task.priority_to;
101
110
  }
111
+ if (patch.schedule !== undefined) {
112
+ changes.due_from = task.due_from;
113
+ changes.due_to = task.due_to;
114
+ }
115
+ if (task.cascaded_task_ids.length > 0)
116
+ changes.cascaded_task_ids = task.cascaded_task_ids;
117
+ changes.updated = task.updated;
118
+ return {
119
+ dry_run: true,
120
+ command: 'dino todo update',
121
+ action: 'update_todo_status',
122
+ risk: 'write',
123
+ summary: `Update task ${task.task_id} in note "${task.note_title}".`,
124
+ warnings,
125
+ inputs: {
126
+ task_id: task.task_id,
127
+ note_id: args.noteId?.trim() || null,
128
+ ...(patch.checked !== undefined ? { status_to: patch.checked ? 'completed' : 'uncompleted' } : {}),
129
+ ...(patch.priority !== undefined ? { priority_to: patch.priority ?? 'none' } : {}),
130
+ ...(patch.schedule !== undefined ? { schedule: patch.schedule } : {}),
131
+ },
132
+ targets: [{ note_id: task.note_id, title: task.note_title }],
133
+ changes,
134
+ };
102
135
  }
103
- if (matches.length === 0) {
104
- throw new DinoxError(`Task not found: ${taskId}`);
105
- }
106
- if (matches.length > 1) {
107
- throw new DinoxError(`Task id is not unique; found in multiple notes: ${matches.map((item) => item.noteId).join(', ')}`);
108
- }
109
- const match = matches[0];
110
- const nextContentMd = patchTaskMarkdownByOrder(match.contentMd, match.applied.taskOrder, match.applied.matchedIndices, args.checked);
111
- const updated = match.applied.statusChangedCount > 0
112
- || nextContentMd !== (match.contentMd ?? '');
113
136
  return {
114
137
  dry_run: true,
115
138
  command: 'dino todo update',
116
139
  action: 'update_todo_status',
117
140
  risk: 'write',
118
- summary: `Mark task ${taskId} as ${args.checked ? 'completed' : 'uncompleted'} in note "${match.title}".`,
119
- warnings: buildExecutionWarnings(args.config, args.offline),
120
- inputs: {
121
- task_id: taskId,
122
- note_id: args.noteId?.trim() || null,
123
- status_to: args.checked ? 'completed' : 'uncompleted',
124
- },
125
- targets: [
126
- {
127
- note_id: match.noteId,
128
- title: match.title,
129
- },
130
- ],
141
+ summary: `Update ${tasks.length} task(s) across ${plans.length} note(s).`,
142
+ warnings,
143
+ inputs: { update_count: updates.length },
144
+ targets: plans.map((plan) => ({ note_id: plan.noteId, title: (plan.row.title ?? '').trim() })),
131
145
  changes: {
132
- checked_from: match.checked,
133
- checked_to: args.checked,
134
- updated,
146
+ updated_count: tasks.filter((task) => task.updated).length,
147
+ tasks,
135
148
  },
136
149
  };
137
150
  }