@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
|
@@ -181,7 +181,7 @@ var ROUTE = "/dinox-editor";
|
|
|
181
181
|
var SESSION_PREFIX = "dsh:";
|
|
182
182
|
var MAX_BODY = 8 * 1024 * 1024;
|
|
183
183
|
var MAX_WAIT_MS = 25e3;
|
|
184
|
-
var UI_METHODS = /* @__PURE__ */ new Set(["sync", "save", "resolve", "search", "open", "log", "catalog", "updateMeta"]);
|
|
184
|
+
var UI_METHODS = /* @__PURE__ */ new Set(["sync", "save", "resolve", "search", "open", "log", "catalog", "updateMeta", "todos", "todoUpdate", "todoAppend", "todoRestore", "todoSuggestion"]);
|
|
185
185
|
var SESSION_META_KEY = "dinox.ai/editorSession";
|
|
186
186
|
function resolveRuntime(pluginLib = path.dirname(fileURLToPath(import.meta.url)), env = process.env) {
|
|
187
187
|
const fallbackCli = path.resolve(pluginLib, "..", "..", "dinox.js");
|
|
@@ -281,10 +281,15 @@ function isAppOnly(tool) {
|
|
|
281
281
|
const visibility = tool._meta?.ui?.visibility;
|
|
282
282
|
return Array.isArray(visibility) && !visibility.includes("model");
|
|
283
283
|
}
|
|
284
|
+
function sidebarHint(tool) {
|
|
285
|
+
if (tool.name === "dinox_todo_open") return " The list opens in the Dinox tab of the right sidebar.";
|
|
286
|
+
if (tool.name === "dinox_editor_open") return " The note opens in the Dinox tab of the right sidebar.";
|
|
287
|
+
return "";
|
|
288
|
+
}
|
|
284
289
|
function dshTool(tool, client) {
|
|
285
290
|
return {
|
|
286
291
|
name: tool.name,
|
|
287
|
-
description: `${tool.description ?? ""}
|
|
292
|
+
description: `${tool.description ?? ""}${sidebarHint(tool)}`.trim(),
|
|
288
293
|
parameters: toDshSchema(tool.inputSchema),
|
|
289
294
|
timeoutMs: 45e3,
|
|
290
295
|
output: {
|
package/dist/editor/compat.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ export declare function setLabelTranslator(translate: (text: string) => string):
|
|
|
27
27
|
* are dropped.
|
|
28
28
|
*/
|
|
29
29
|
export declare function wrapUnknown(doc: JSONContent, schema: Schema): JSONContent;
|
|
30
|
+
/**
|
|
31
|
+
* Older CLI builds wrote a task's id and state twice: in attrs and again on the
|
|
32
|
+
* node itself. Readers take the outer copy first, so it wins; the editor keeps
|
|
33
|
+
* them in attrs, which is where the Dinox apps read and write them.
|
|
34
|
+
*/
|
|
35
|
+
export declare function liftTaskFields(doc: JSONContent): JSONContent;
|
|
30
36
|
export declare function unwrapOpaque(doc: JSONContent): JSONContent;
|
|
31
37
|
export declare function losslessCompare(storedInput: any, roundTripped: JSONContent, schema: Schema): string[];
|
|
32
38
|
export declare function cleanForSave(doc: JSONContent, _schema?: Schema): JSONContent;
|
package/dist/editor/compat.js
CHANGED
|
@@ -285,6 +285,24 @@ export function wrapUnknown(doc, schema) {
|
|
|
285
285
|
return { ...doc, content: [{ type: 'paragraph' }] };
|
|
286
286
|
return prepare(doc, false) ?? doc;
|
|
287
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Older CLI builds wrote a task's id and state twice: in attrs and again on the
|
|
290
|
+
* node itself. Readers take the outer copy first, so it wins; the editor keeps
|
|
291
|
+
* them in attrs, which is where the Dinox apps read and write them.
|
|
292
|
+
*/
|
|
293
|
+
export function liftTaskFields(doc) {
|
|
294
|
+
const lift = (node) => {
|
|
295
|
+
if (!node || typeof node !== 'object')
|
|
296
|
+
return node;
|
|
297
|
+
let out = node;
|
|
298
|
+
if (node.type === 'taskItem' && (Object.hasOwn(node, 'id') || Object.hasOwn(node, 'checked'))) {
|
|
299
|
+
const { id, checked, ...rest } = node;
|
|
300
|
+
out = { ...rest, attrs: { ...node.attrs, ...(typeof id === 'string' && id ? { id } : {}), ...(typeof checked === 'boolean' ? { checked } : {}) } };
|
|
301
|
+
}
|
|
302
|
+
return Array.isArray(out.content) ? { ...out, content: out.content.map(lift) } : out;
|
|
303
|
+
};
|
|
304
|
+
return lift(doc);
|
|
305
|
+
}
|
|
288
306
|
export function unwrapOpaque(doc) {
|
|
289
307
|
if (['dxOpaqueBlock', 'dxOpaqueInline'].includes(doc.type ?? ''))
|
|
290
308
|
return JSON.parse(doc.attrs.raw);
|
package/dist/editor/daemon.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendTodoTasks, executeTodoSearch, restoreTodoTasks, updateTodoTasks } from '../commands/todo/repo.js';
|
|
1
2
|
import { waitForUploadQueueEmpty } from '../powersync/runtime.js';
|
|
2
3
|
import { DinoxError } from '../utils/errors.js';
|
|
3
4
|
import { createEditorStore } from './document.js';
|
|
@@ -12,10 +13,22 @@ export async function createDaemonEditorService(db, options) {
|
|
|
12
13
|
}),
|
|
13
14
|
persistence: createFilePersistence(editorSessionsPath(options.userId)),
|
|
14
15
|
watchNotes: onChange => db.onChange({ onChange }, { tables: ['c_note'], throttleMs: 200 }),
|
|
16
|
+
todos: {
|
|
17
|
+
search: wire => executeTodoSearch(db, wire),
|
|
18
|
+
update: updates => uploaded(updateTodoTasks(db, updates)),
|
|
19
|
+
append: (items, target) => uploaded(appendTodoTasks(db, { items, userId: options.userId, ...target })),
|
|
20
|
+
restore: entries => uploaded(restoreTodoTasks(db, entries)),
|
|
21
|
+
},
|
|
15
22
|
log: options.log,
|
|
16
23
|
});
|
|
17
24
|
await service.restore();
|
|
18
25
|
return service;
|
|
26
|
+
/** Like a note save: the change is local at once and uploads in the background. */
|
|
27
|
+
async function uploaded(write) {
|
|
28
|
+
const result = await write;
|
|
29
|
+
void waitForUploadQueueEmpty(db, 30_000).catch(() => undefined);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
19
32
|
}
|
|
20
33
|
export const EDITOR_METHODS = new Set([
|
|
21
34
|
'editor.open',
|
|
@@ -30,6 +43,13 @@ export const EDITOR_METHODS = new Set([
|
|
|
30
43
|
'editor.catalog',
|
|
31
44
|
'editor.updateMeta',
|
|
32
45
|
'editor.watchOpens',
|
|
46
|
+
'editor.showTodos',
|
|
47
|
+
'editor.todos',
|
|
48
|
+
'editor.todoUpdate',
|
|
49
|
+
'editor.todoAppend',
|
|
50
|
+
'editor.todoRestore',
|
|
51
|
+
'editor.todoSuggest',
|
|
52
|
+
'editor.todoSuggestion',
|
|
33
53
|
]);
|
|
34
54
|
/** Dispatches one `editor.*` daemon request. An explicit allowlist: never property lookup. */
|
|
35
55
|
export async function handleEditorRequest(service, method, params, signal) {
|
|
@@ -51,6 +71,13 @@ export async function handleEditorRequest(service, method, params, signal) {
|
|
|
51
71
|
case 'editor.catalog': return service.catalog();
|
|
52
72
|
case 'editor.updateMeta': return service.updateMeta(session, input);
|
|
53
73
|
case 'editor.watchOpens': return service.watchOpens(input, signal);
|
|
74
|
+
case 'editor.showTodos': return service.showTodos(session, input);
|
|
75
|
+
case 'editor.todos': return service.todos(session, input);
|
|
76
|
+
case 'editor.todoUpdate': return service.todoUpdate(session, input);
|
|
77
|
+
case 'editor.todoAppend': return service.todoAppend(session, input);
|
|
78
|
+
case 'editor.todoRestore': return service.todoRestore(session, input);
|
|
79
|
+
case 'editor.todoSuggest': return service.todoSuggest(session, input);
|
|
80
|
+
case 'editor.todoSuggestion': return service.todoSuggestion(session, input);
|
|
54
81
|
default: throw new DinoxError(`Unknown editor method: ${method}`, { code: 'USAGE_ERROR' });
|
|
55
82
|
}
|
|
56
83
|
}
|
package/dist/editor/mcp.js
CHANGED
|
@@ -7,18 +7,20 @@ import { z } from 'zod';
|
|
|
7
7
|
import { sendDaemonRequest } from '../daemon/client.js';
|
|
8
8
|
import { getPackageVersion } from '../utils/version.js';
|
|
9
9
|
import { editorPackageRoot } from './paths.js';
|
|
10
|
+
import { formatTodoList } from './todos.js';
|
|
10
11
|
export const EDITOR_RESOURCE_URI = 'ui://dinox/editor';
|
|
11
12
|
export const EDITOR_SESSION_META_KEY = 'dinox.ai/editorSession';
|
|
12
13
|
/** Hosts the editor's images load from. */
|
|
13
14
|
const IMAGE_DOMAINS = ['https://bitiful.chatgo.pro', 'https://*.chatgo.pro', 'https://*.dinox.info'];
|
|
14
|
-
const UI_METHODS = ['sync', 'save', 'resolve', 'search', 'open', 'log', 'catalog', 'updateMeta', 'watchOpens'];
|
|
15
|
+
const UI_METHODS = ['sync', 'save', 'resolve', 'search', 'open', 'log', 'catalog', 'updateMeta', 'watchOpens', 'todos', 'todoUpdate', 'todoAppend', 'todoRestore', 'todoSuggestion'];
|
|
15
16
|
const SYNC_TIMEOUT_GRACE_MS = 10_000;
|
|
16
17
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
17
18
|
const INSTRUCTIONS = "Co-edit the user's Dinox notes. dinox_editor_open shows a note in a panel beside the chat; the user edits it while " +
|
|
18
19
|
'you read it (dinox_editor_read) and propose changes (dinox_editor_suggest), which they accept or dismiss inline. ' +
|
|
19
20
|
'Address blocks by their [id]. Read only what you need: focus=true for the blocks at the user\'s cursor, since=<version> ' +
|
|
20
21
|
'for what changed after an earlier read. Prefer small {block, find, replace} edits over rewriting whole blocks, and send ' +
|
|
21
|
-
'related edits in one call. For feedback or reviews, leave comments instead of edits.'
|
|
22
|
+
'related edits in one call. For feedback or reviews, leave comments instead of edits. dinox_todo_open shows the user\'s ' +
|
|
23
|
+
'inline tasks (checklist items across all notes) in the same panel; change tasks with dinox_todo_update by their [task id], and propose subtasks with dinox_todo_suggest.';
|
|
22
24
|
const indent = (md) => md.replace(/\n/g, '\n ');
|
|
23
25
|
/** The read result as compact text: what a model reads best, at a fraction of the JSON size. */
|
|
24
26
|
export function formatRead(read) {
|
|
@@ -175,6 +177,98 @@ export function createEditorMcpServer(options = {}) {
|
|
|
175
177
|
return failure(error);
|
|
176
178
|
}
|
|
177
179
|
});
|
|
180
|
+
const priority = z.enum(['high', 'medium', 'low', 'none']);
|
|
181
|
+
const date = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
|
|
182
|
+
registerAppTool(server, 'dinox_todo_open', {
|
|
183
|
+
title: 'Show Dinox tasks',
|
|
184
|
+
description: 'Show the user\'s tasks (checklist items from all their Dinox notes) as a list in the editor panel, where they can ' +
|
|
185
|
+
'check them off, set priorities and due dates, and jump to the note a task lives in. Returns the listed tasks with ' +
|
|
186
|
+
'their ids. Filters left out show every open task.',
|
|
187
|
+
inputSchema: {
|
|
188
|
+
status: z.enum(['uncompleted', 'completed', 'all']).optional().describe('Default uncompleted'),
|
|
189
|
+
query: z.string().max(500).optional().describe('Words in the task text or its note title'),
|
|
190
|
+
tags: z.array(z.string().max(100)).max(20).optional().describe('Tags on the task or its note, without #'),
|
|
191
|
+
priority: z.array(priority).max(4).optional(),
|
|
192
|
+
from: date.optional().describe('Scheduled on or after this local date (YYYY-MM-DD)'),
|
|
193
|
+
to: date.optional().describe('Scheduled on or before this local date (YYYY-MM-DD)'),
|
|
194
|
+
},
|
|
195
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
196
|
+
_meta: { ui: { resourceUri: EDITOR_RESOURCE_URI } },
|
|
197
|
+
}, async (filter, extra) => {
|
|
198
|
+
try {
|
|
199
|
+
const session = sessionOf(extra);
|
|
200
|
+
const list = await call('editor.showTodos', { session, filter });
|
|
201
|
+
return {
|
|
202
|
+
content: [{ type: 'text', text: `Showing tasks in the editor panel. ${formatTodoList(list)}` }],
|
|
203
|
+
structuredContent: { session, todoSeq: list.todoSeq, total: list.total, filter: list.filter },
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
return failure(error);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
const due = z.object({
|
|
211
|
+
date: date.describe('Local date, YYYY-MM-DD'),
|
|
212
|
+
time: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/).optional().describe('HH:mm; leave out for all day'),
|
|
213
|
+
});
|
|
214
|
+
server.registerTool('dinox_todo_update', {
|
|
215
|
+
title: 'Update Dinox tasks',
|
|
216
|
+
description: 'Check off, reopen, reword, prioritize or reschedule tasks by their task id (from dinox_todo_open). Checking a task also ' +
|
|
217
|
+
'checks its subtasks; reopening one also reopens its checked parents. The panel shows the result.',
|
|
218
|
+
inputSchema: {
|
|
219
|
+
updates: z.array(z.object({
|
|
220
|
+
taskId: z.string().describe('Task id'),
|
|
221
|
+
noteId: z.string().optional().describe('The note the task is in, when known'),
|
|
222
|
+
checked: z.boolean().optional(),
|
|
223
|
+
priority: priority.nullable().optional().describe('none or null clears it'),
|
|
224
|
+
due: due.nullable().optional().describe('null clears the due date'),
|
|
225
|
+
text: z.string().min(1).max(2000).optional()
|
|
226
|
+
.describe('New task words, #tags written in place; only the changed part is rewritten, formatting elsewhere stays'),
|
|
227
|
+
})).min(1).max(50),
|
|
228
|
+
},
|
|
229
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
230
|
+
}, async ({ updates }, extra) => {
|
|
231
|
+
try {
|
|
232
|
+
const result = await call('editor.todoUpdate', { session: sessionOf(extra), updates, actor: 'ai' });
|
|
233
|
+
const cascaded = result.tasks.reduce((sum, task) => sum + task.cascaded_task_ids.length, 0);
|
|
234
|
+
return {
|
|
235
|
+
content: [{
|
|
236
|
+
type: 'text',
|
|
237
|
+
text: `Updated ${result.updated_count} of ${updates.length} task${updates.length === 1 ? '' : 's'}` +
|
|
238
|
+
(cascaded ? ` (${cascaded} related task${cascaded === 1 ? '' : 's'} changed with them)` : '') + '.',
|
|
239
|
+
}],
|
|
240
|
+
structuredContent: result,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
return failure(error);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
server.registerTool('dinox_todo_suggest', {
|
|
248
|
+
title: 'Suggest Dinox subtasks',
|
|
249
|
+
description: 'Propose subtasks that break one task down into concrete next actions. They show under the task in the panel\'s ' +
|
|
250
|
+
'todo list, and are added to the note only when the user accepts them (nothing is written by this call). A new ' +
|
|
251
|
+
'proposal for the same task replaces the earlier one.',
|
|
252
|
+
inputSchema: {
|
|
253
|
+
taskId: z.string().describe('The task to break down (id from dinox_todo_open)'),
|
|
254
|
+
noteId: z.string().optional().describe('The note the task is in, when known'),
|
|
255
|
+
note: z.string().max(500).optional().describe('One short sentence on the approach, shown above the subtasks'),
|
|
256
|
+
subtasks: z.array(z.object({
|
|
257
|
+
text: z.string().min(1).max(500).describe('One concrete action, in the user\'s language; #tags allowed'),
|
|
258
|
+
priority: priority.optional(),
|
|
259
|
+
due: due.optional(),
|
|
260
|
+
})).min(1).max(12),
|
|
261
|
+
},
|
|
262
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
263
|
+
}, async (input, extra) => {
|
|
264
|
+
try {
|
|
265
|
+
const result = await call('editor.todoSuggest', { session: sessionOf(extra), ...input });
|
|
266
|
+
return { content: [{ type: 'text', text: `Suggested ${result.count} subtask${result.count === 1 ? '' : 's'}; the user will accept or drop them in the panel.` }] };
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
return failure(error);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
178
272
|
registerAppTool(server, 'dinox_editor_rpc', {
|
|
179
273
|
title: 'Editor panel channel',
|
|
180
274
|
description: 'Used by the Dinox editor panel only.',
|
|
@@ -187,6 +281,9 @@ export function createEditorMcpServer(options = {}) {
|
|
|
187
281
|
try {
|
|
188
282
|
const session = typeof params.session === 'string' && params.session ? params.session : sessionOf(extra);
|
|
189
283
|
const longPoll = method === 'sync' || method === 'watchOpens';
|
|
284
|
+
// The panel's own task changes are the user's.
|
|
285
|
+
if (method === 'todoUpdate')
|
|
286
|
+
params = { ...params, actor: 'user' };
|
|
190
287
|
const waitMs = longPoll ? Math.min(25_000, Math.max(0, Number(params.waitMs) || 0)) : 0;
|
|
191
288
|
const value = await call(`editor.${method}`, { ...params, session }, { timeoutMs: waitMs + (longPoll ? SYNC_TIMEOUT_GRACE_MS : DEFAULT_TIMEOUT_MS) });
|
|
192
289
|
return json({ value });
|
package/dist/editor/service.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { JSONContent } from '@tiptap/core';
|
|
|
2
2
|
import { type Message } from './i18n.js';
|
|
3
3
|
import type { EditorNote, EditorSearchHit, EditorStore } from './document.js';
|
|
4
4
|
import { type EditorMeta } from './meta.js';
|
|
5
|
+
import { type EditorTodos, type TodoFilter, type TodoList, type TodoSuggestion } from './todos.js';
|
|
5
6
|
/**
|
|
6
7
|
* Shared state of every co-editing session, owned by the daemon so all hosts
|
|
7
8
|
* (Codex, dsh, ...) and every reload of a host see the same note, suggestions
|
|
@@ -154,8 +155,20 @@ type Session = {
|
|
|
154
155
|
remote: RemoteChange | null;
|
|
155
156
|
updatedAt: number;
|
|
156
157
|
saving: Promise<unknown> | null;
|
|
158
|
+
/** What the panel shows: the open note, or the todo list (the note stays loaded behind it). */
|
|
159
|
+
route: EditorRoute;
|
|
160
|
+
/** Bumped when the model asks for the todo list; a UI that has not shown it yet switches to it. */
|
|
161
|
+
todoSeq: number;
|
|
162
|
+
/** Highest todoSeq a mounted UI has displayed. */
|
|
163
|
+
todoAck: number;
|
|
164
|
+
todoFilter: TodoFilter;
|
|
165
|
+
/** Bumped when tasks may have changed, so a panel on the todo list reloads it. */
|
|
166
|
+
todoRev: number;
|
|
167
|
+
/** Subtasks the model proposed, until the user takes or drops them (not persisted). */
|
|
168
|
+
todoSuggestions: TodoSuggestion[];
|
|
157
169
|
};
|
|
158
|
-
export type
|
|
170
|
+
export type EditorRoute = 'note' | 'todo';
|
|
171
|
+
export type PersistedSession = Pick<Session, 'key' | 'noteId' | 'title' | 'knownHash' | 'knownVersion' | 'openSeq' | 'suggestions' | 'activity' | 'updatedAt'> & Partial<Pick<Session, 'version' | 'blockSeq' | 'route' | 'todoSeq' | 'todoFilter'>>;
|
|
159
172
|
export type EditorPersistence = {
|
|
160
173
|
load(): Promise<PersistedSession[]>;
|
|
161
174
|
save(sessions: PersistedSession[]): Promise<void>;
|
|
@@ -166,6 +179,8 @@ export type EditorServiceOptions = {
|
|
|
166
179
|
now?: () => number;
|
|
167
180
|
/** Subscribes to note changes; returns an unsubscribe function. */
|
|
168
181
|
watchNotes?: (onChange: () => void) => () => void;
|
|
182
|
+
/** The todo list behind the panel's todo route; without it the route is unavailable. */
|
|
183
|
+
todos?: EditorTodos;
|
|
169
184
|
log?: (message: string, details?: Record<string, unknown>) => void;
|
|
170
185
|
};
|
|
171
186
|
/** A whole-block replacement keeps the block's type, so a repeated `## ` or `- [ ] ` is dropped. */
|
|
@@ -190,6 +205,22 @@ export declare class EditorService {
|
|
|
190
205
|
}): Promise<OpenPayload & {
|
|
191
206
|
otherHits: EditorSearchHit[];
|
|
192
207
|
}>;
|
|
208
|
+
/**
|
|
209
|
+
* Shows the todo list in the panel (the open note stays loaded behind it)
|
|
210
|
+
* and returns what it shows. `filter` fields left out keep the current ones.
|
|
211
|
+
*/
|
|
212
|
+
showTodos(key: string, input?: {
|
|
213
|
+
filter?: unknown;
|
|
214
|
+
}): Promise<TodoList & {
|
|
215
|
+
todoSeq: number;
|
|
216
|
+
session: string;
|
|
217
|
+
}>;
|
|
218
|
+
/** Changes tasks by their stable ids, for the model or the panel; panels on the todo list reload. */
|
|
219
|
+
todoUpdate(key: string, input: Record<string, unknown>): Promise<import("../commands/todo/repo.js").UpdateTodoTasksResult>;
|
|
220
|
+
/** Quick add from the panel: tasks at the end of today's daily note. */
|
|
221
|
+
todoAppend(key: string, input: Record<string, unknown>): Promise<import("../commands/todo/repo.js").AppendTodoTasksResult>;
|
|
222
|
+
/** The panel's undo of its own change (exact values, no cascade). */
|
|
223
|
+
todoRestore(key: string, input: Record<string, unknown>): Promise<import("../commands/todo/repo.js").UpdateTodoTasksResult>;
|
|
193
224
|
/**
|
|
194
225
|
* What the model reads. Without arguments: the whole note as blocks (an
|
|
195
226
|
* outline around the user's cursor when it is long). With `since`: only
|
|
@@ -220,6 +251,21 @@ export declare class EditorService {
|
|
|
220
251
|
query?: unknown;
|
|
221
252
|
limit?: unknown;
|
|
222
253
|
}): Promise<EditorSearchHit[]>;
|
|
254
|
+
/** The todo list for the panel; a `filter` it sends becomes the session's, so a reopened panel keeps it. */
|
|
255
|
+
todos(key: string, input: Record<string, unknown>): Promise<TodoList>;
|
|
256
|
+
/**
|
|
257
|
+
* The model proposes subtasks for a task. They wait under the task in the
|
|
258
|
+
* panel (which switches to the todo list) until the user accepts or drops them.
|
|
259
|
+
*/
|
|
260
|
+
todoSuggest(key: string, input: Record<string, unknown>): Promise<{
|
|
261
|
+
id: string;
|
|
262
|
+
count: number;
|
|
263
|
+
}>;
|
|
264
|
+
/** The user's answer to a proposal: `accept` adds the subtasks it `keep`s (indexes; all by default). */
|
|
265
|
+
todoSuggestion(key: string, input: Record<string, unknown>): Promise<{
|
|
266
|
+
accepted: boolean;
|
|
267
|
+
result: import("../commands/todo/repo.js").AppendTodoTasksResult | null;
|
|
268
|
+
}>;
|
|
223
269
|
/**
|
|
224
270
|
* Mirrors the UI and long-polls for changes. A call that carries no updates
|
|
225
271
|
* and names the current `rev` waits up to `waitMs` for anything to change.
|
|
@@ -237,6 +283,11 @@ export declare class EditorService {
|
|
|
237
283
|
mirrorRev: string | null;
|
|
238
284
|
meta: EditorMeta | null;
|
|
239
285
|
metaSeq: number;
|
|
286
|
+
route: EditorRoute;
|
|
287
|
+
todoSeq: number;
|
|
288
|
+
todoRev: number;
|
|
289
|
+
todoFilter: TodoFilter;
|
|
290
|
+
todos: boolean;
|
|
240
291
|
}>;
|
|
241
292
|
save(key: string, input: Record<string, unknown>): Promise<{
|
|
242
293
|
status: "saved" | "unchanged";
|
|
@@ -271,6 +322,8 @@ export declare class EditorService {
|
|
|
271
322
|
opens: {
|
|
272
323
|
session: string;
|
|
273
324
|
openSeq: number;
|
|
325
|
+
todoSeq: number;
|
|
326
|
+
route: EditorRoute;
|
|
274
327
|
noteId: string | null;
|
|
275
328
|
title: string;
|
|
276
329
|
}[];
|
|
@@ -281,6 +334,9 @@ export declare class EditorService {
|
|
|
281
334
|
private blank;
|
|
282
335
|
private session;
|
|
283
336
|
private requireOpen;
|
|
337
|
+
private requireTodos;
|
|
338
|
+
/** Tells panels on the todo list that tasks may have changed. */
|
|
339
|
+
private touchTodos;
|
|
284
340
|
private payload;
|
|
285
341
|
private view;
|
|
286
342
|
/** A session restored after a daemon restart has no document until something needs it. */
|
package/dist/editor/service.js
CHANGED
|
@@ -5,6 +5,9 @@ import { isMessage, sourceText } from './i18n.js';
|
|
|
5
5
|
import { shortBlockId } from './blockIds.js';
|
|
6
6
|
import { reconcileBlocks, segmentDocument } from './blocks.js';
|
|
7
7
|
import { parseMetaPatch } from './meta.js';
|
|
8
|
+
import { DEFAULT_TODO_FILTER, parseTodoAppend, parseTodoFilter, parseTodoRestore, parseTodoSuggest, parseTodoUpdates, todoSearchWire, toTodoList } from './todos.js';
|
|
9
|
+
/** Pending subtask proposals kept per session. */
|
|
10
|
+
const MAX_TODO_SUGGESTIONS = 10;
|
|
8
11
|
const MAX_KEY_LENGTH = 200;
|
|
9
12
|
const MAX_ACTIVITY = 80;
|
|
10
13
|
const MAX_SUGGESTIONS = 50;
|
|
@@ -86,6 +89,10 @@ export class EditorService {
|
|
|
86
89
|
version: entry.version ?? 0,
|
|
87
90
|
floor: entry.version ?? 0,
|
|
88
91
|
blockSeq: entry.blockSeq ?? 0,
|
|
92
|
+
route: entry.route === 'todo' ? 'todo' : 'note',
|
|
93
|
+
todoSeq: entry.todoSeq ?? 0,
|
|
94
|
+
todoAck: entry.todoSeq ?? 0,
|
|
95
|
+
todoFilter: safeFilter(entry.todoFilter),
|
|
89
96
|
});
|
|
90
97
|
}
|
|
91
98
|
this.updateWatch();
|
|
@@ -123,6 +130,7 @@ export class EditorService {
|
|
|
123
130
|
upload: null,
|
|
124
131
|
remote: null,
|
|
125
132
|
openSeq: session.openSeq + 1,
|
|
133
|
+
route: 'note',
|
|
126
134
|
});
|
|
127
135
|
this.setMeta(session, meta);
|
|
128
136
|
this.adopt(session, note.document, null);
|
|
@@ -133,6 +141,56 @@ export class EditorService {
|
|
|
133
141
|
this.updateWatch();
|
|
134
142
|
return { ...this.payload(session, note), otherHits };
|
|
135
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Shows the todo list in the panel (the open note stays loaded behind it)
|
|
146
|
+
* and returns what it shows. `filter` fields left out keep the current ones.
|
|
147
|
+
*/
|
|
148
|
+
async showTodos(key, input = {}) {
|
|
149
|
+
const session = this.session(key);
|
|
150
|
+
const todos = this.requireTodos();
|
|
151
|
+
const filter = parseTodoFilter(input.filter, DEFAULT_TODO_FILTER);
|
|
152
|
+
const list = { ...toTodoList(await todos.search(todoSearchWire(filter)), filter), suggestions: session.todoSuggestions };
|
|
153
|
+
Object.assign(session, { route: 'todo', todoFilter: filter, todoSeq: session.todoSeq + 1 });
|
|
154
|
+
this.record(session, 'ai', 'open', { key: '打開了待辦清單' });
|
|
155
|
+
this.changed(session);
|
|
156
|
+
this.opensRev++;
|
|
157
|
+
this.wake(this.openWaiters);
|
|
158
|
+
this.updateWatch();
|
|
159
|
+
return { ...list, todoSeq: session.todoSeq, session: session.key };
|
|
160
|
+
}
|
|
161
|
+
/** Changes tasks by their stable ids, for the model or the panel; panels on the todo list reload. */
|
|
162
|
+
async todoUpdate(key, input) {
|
|
163
|
+
const session = this.session(key);
|
|
164
|
+
const todos = this.requireTodos();
|
|
165
|
+
const updates = parseTodoUpdates(input.updates);
|
|
166
|
+
const result = await todos.update(updates);
|
|
167
|
+
if (result.updated_count) {
|
|
168
|
+
const actor = input.actor === 'user' ? 'user' : 'ai';
|
|
169
|
+
this.record(session, actor, 'save', { key: '更新了 {n} 個待辦', params: { n: result.updated_count } });
|
|
170
|
+
}
|
|
171
|
+
this.touchTodos();
|
|
172
|
+
this.changed(session);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
/** Quick add from the panel: tasks at the end of today's daily note. */
|
|
176
|
+
async todoAppend(key, input) {
|
|
177
|
+
const session = this.session(key);
|
|
178
|
+
const result = await this.requireTodos().append(parseTodoAppend(input.items));
|
|
179
|
+
this.record(session, 'user', 'save', { key: '新增了 {n} 個待辦', params: { n: result.appended_count } });
|
|
180
|
+
this.touchTodos();
|
|
181
|
+
this.changed(session);
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
/** The panel's undo of its own change (exact values, no cascade). */
|
|
185
|
+
async todoRestore(key, input) {
|
|
186
|
+
const session = this.session(key);
|
|
187
|
+
const result = await this.requireTodos().restore(parseTodoRestore(input.entries));
|
|
188
|
+
if (result.updated_count)
|
|
189
|
+
this.record(session, 'user', 'save', { key: '復原了 {n} 個待辦', params: { n: result.updated_count } });
|
|
190
|
+
this.touchTodos();
|
|
191
|
+
this.changed(session);
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
136
194
|
/**
|
|
137
195
|
* What the model reads. Without arguments: the whole note as blocks (an
|
|
138
196
|
* outline around the user's cursor when it is long). With `since`: only
|
|
@@ -361,6 +419,64 @@ export class EditorService {
|
|
|
361
419
|
const limit = Math.max(1, Math.min(20, Number(input.limit) || 10));
|
|
362
420
|
return this.options.store.search(query, limit);
|
|
363
421
|
}
|
|
422
|
+
/** The todo list for the panel; a `filter` it sends becomes the session's, so a reopened panel keeps it. */
|
|
423
|
+
async todos(key, input) {
|
|
424
|
+
const session = this.session(key);
|
|
425
|
+
const todos = this.requireTodos();
|
|
426
|
+
const filter = parseTodoFilter(input.filter, session.todoFilter);
|
|
427
|
+
if (JSON.stringify(filter) !== JSON.stringify(session.todoFilter)) {
|
|
428
|
+
session.todoFilter = filter;
|
|
429
|
+
session.updatedAt = this.now();
|
|
430
|
+
this.schedulePersist();
|
|
431
|
+
}
|
|
432
|
+
return { ...toTodoList(await todos.search(todoSearchWire(filter)), filter), suggestions: session.todoSuggestions };
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* The model proposes subtasks for a task. They wait under the task in the
|
|
436
|
+
* panel (which switches to the todo list) until the user accepts or drops them.
|
|
437
|
+
*/
|
|
438
|
+
async todoSuggest(key, input) {
|
|
439
|
+
const session = this.session(key);
|
|
440
|
+
this.requireTodos();
|
|
441
|
+
const proposal = parseTodoSuggest(input);
|
|
442
|
+
const suggestion = { ...proposal, id: `ts${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`, at: new Date(this.now()).toISOString() };
|
|
443
|
+
// A new proposal for the same task replaces the old one.
|
|
444
|
+
session.todoSuggestions = [...session.todoSuggestions.filter(s => s.taskId !== suggestion.taskId), suggestion].slice(-MAX_TODO_SUGGESTIONS);
|
|
445
|
+
this.record(session, 'ai', 'suggest', { key: '建議了 {n} 個子待辦', params: { n: suggestion.items.length } });
|
|
446
|
+
if (session.route !== 'todo') {
|
|
447
|
+
Object.assign(session, { route: 'todo', todoSeq: session.todoSeq + 1 });
|
|
448
|
+
this.opensRev++;
|
|
449
|
+
this.wake(this.openWaiters);
|
|
450
|
+
this.updateWatch();
|
|
451
|
+
}
|
|
452
|
+
session.todoRev++;
|
|
453
|
+
this.changed(session);
|
|
454
|
+
return { id: suggestion.id, count: suggestion.items.length };
|
|
455
|
+
}
|
|
456
|
+
/** The user's answer to a proposal: `accept` adds the subtasks it `keep`s (indexes; all by default). */
|
|
457
|
+
async todoSuggestion(key, input) {
|
|
458
|
+
const session = this.session(key);
|
|
459
|
+
const suggestion = session.todoSuggestions.find(s => s.id === input.id);
|
|
460
|
+
if (!suggestion)
|
|
461
|
+
throw new DinoxError('This suggestion is no longer available.', { code: 'INVALID_ARGUMENT', recoverable: true });
|
|
462
|
+
let result = null;
|
|
463
|
+
if (input.accept === true) {
|
|
464
|
+
const keep = Array.isArray(input.keep) ? new Set(input.keep.filter((n) => Number.isInteger(n))) : null;
|
|
465
|
+
const items = suggestion.items.filter((_, index) => !keep || keep.has(index));
|
|
466
|
+
if (!items.length)
|
|
467
|
+
throw new DinoxError('Pick at least one subtask.', { code: 'INVALID_ARGUMENT', recoverable: true });
|
|
468
|
+
result = await this.requireTodos().append(items, { parentTaskId: suggestion.taskId, ...(suggestion.noteId ? { noteId: suggestion.noteId } : {}) });
|
|
469
|
+
this.record(session, 'user', 'accept', { key: '加入了 {n} 個子待辦', params: { n: result.appended_count } });
|
|
470
|
+
this.touchTodos();
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
this.record(session, 'user', 'reject', { key: '捨棄了 AI 建議的子待辦' });
|
|
474
|
+
}
|
|
475
|
+
session.todoSuggestions = session.todoSuggestions.filter(s => s.id !== suggestion.id);
|
|
476
|
+
session.todoRev++;
|
|
477
|
+
this.changed(session);
|
|
478
|
+
return { accepted: Boolean(result), result };
|
|
479
|
+
}
|
|
364
480
|
// ---- UI-facing -----------------------------------------------------------
|
|
365
481
|
/**
|
|
366
482
|
* Mirrors the UI and long-polls for changes. A call that carries no updates
|
|
@@ -401,9 +517,24 @@ export class EditorService {
|
|
|
401
517
|
// Mirror updates are the UI's own news: no rev bump, so its next poll can wait.
|
|
402
518
|
}
|
|
403
519
|
}
|
|
520
|
+
if (input.todoSeq !== undefined && Number(input.todoSeq) >= session.todoSeq && session.todoAck < session.todoSeq) {
|
|
521
|
+
session.todoAck = session.todoSeq;
|
|
522
|
+
this.opensRev++;
|
|
523
|
+
this.wake(this.openWaiters);
|
|
524
|
+
}
|
|
525
|
+
if ((input.route === 'note' || input.route === 'todo') && input.route !== session.route) {
|
|
526
|
+
// The user moved between the note and the todo list in the panel.
|
|
527
|
+
session.route = input.route;
|
|
528
|
+
updated = true;
|
|
529
|
+
session.updatedAt = this.now();
|
|
530
|
+
this.updateWatch();
|
|
531
|
+
this.schedulePersist();
|
|
532
|
+
}
|
|
404
533
|
const rev = Number(input.rev);
|
|
405
534
|
const waitMs = Math.max(0, Math.min(MAX_WAIT_MS, Number(input.waitMs) || 0));
|
|
406
|
-
|
|
535
|
+
// A UI that has not shown the latest todo request gets it now.
|
|
536
|
+
const todoSeen = input.todoSeq === undefined || Number(input.todoSeq) >= session.todoSeq;
|
|
537
|
+
if (!updated && waitMs > 0 && rev === session.rev && openSeq >= session.openSeq && todoSeen) {
|
|
407
538
|
await this.waitFor(this.waitersOf(key), waitMs, signal);
|
|
408
539
|
}
|
|
409
540
|
return this.view(session, openSeq);
|
|
@@ -535,8 +666,8 @@ export class EditorService {
|
|
|
535
666
|
if (waitMs > 0 && cursor === this.opensRev)
|
|
536
667
|
await this.waitFor(this.openWaiters, waitMs, signal);
|
|
537
668
|
const opens = [...this.sessions.values()]
|
|
538
|
-
.filter(s => s.noteId && s.ackSeq < s.openSeq)
|
|
539
|
-
.map(s => ({ session: s.key, openSeq: s.openSeq, noteId: s.noteId, title: s.title }));
|
|
669
|
+
.filter(s => (s.noteId && s.ackSeq < s.openSeq) || (s.route === 'todo' && s.todoAck < s.todoSeq))
|
|
670
|
+
.map(s => ({ session: s.key, openSeq: s.openSeq, todoSeq: s.todoSeq, route: s.route, noteId: s.noteId, title: s.title }));
|
|
540
671
|
return { cursor: this.opensRev, opens };
|
|
541
672
|
}
|
|
542
673
|
async close() {
|
|
@@ -625,6 +756,12 @@ export class EditorService {
|
|
|
625
756
|
remote: null,
|
|
626
757
|
updatedAt: this.now(),
|
|
627
758
|
saving: null,
|
|
759
|
+
route: 'note',
|
|
760
|
+
todoSeq: 0,
|
|
761
|
+
todoAck: 0,
|
|
762
|
+
todoFilter: { ...DEFAULT_TODO_FILTER },
|
|
763
|
+
todoRev: 0,
|
|
764
|
+
todoSuggestions: [],
|
|
628
765
|
};
|
|
629
766
|
}
|
|
630
767
|
session(key) {
|
|
@@ -647,6 +784,20 @@ export class EditorService {
|
|
|
647
784
|
}
|
|
648
785
|
return session;
|
|
649
786
|
}
|
|
787
|
+
requireTodos() {
|
|
788
|
+
if (!this.options.todos)
|
|
789
|
+
throw new DinoxError('This editor has no todo list.', { code: 'COMMAND_FAILED', recoverable: false });
|
|
790
|
+
return this.options.todos;
|
|
791
|
+
}
|
|
792
|
+
/** Tells panels on the todo list that tasks may have changed. */
|
|
793
|
+
touchTodos() {
|
|
794
|
+
for (const session of this.sessions.values()) {
|
|
795
|
+
if (session.route !== 'todo')
|
|
796
|
+
continue;
|
|
797
|
+
session.todoRev++;
|
|
798
|
+
this.changed(session);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
650
801
|
payload(session, note) {
|
|
651
802
|
return { ...note, openSeq: session.openSeq, session: session.key, meta: session.meta };
|
|
652
803
|
}
|
|
@@ -678,6 +829,11 @@ export class EditorService {
|
|
|
678
829
|
mirrorRev: session.mirrorRev,
|
|
679
830
|
meta: session.meta,
|
|
680
831
|
metaSeq: session.metaSeq,
|
|
832
|
+
route: session.route,
|
|
833
|
+
todoSeq: session.todoSeq,
|
|
834
|
+
todoRev: session.todoRev,
|
|
835
|
+
todoFilter: session.todoFilter,
|
|
836
|
+
todos: Boolean(this.options.todos),
|
|
681
837
|
...(openRequest ? { openRequest } : {}),
|
|
682
838
|
};
|
|
683
839
|
}
|
|
@@ -939,13 +1095,15 @@ export class EditorService {
|
|
|
939
1095
|
});
|
|
940
1096
|
}
|
|
941
1097
|
updateWatch() {
|
|
942
|
-
const anyOpen = [...this.sessions.values()].some(s => s.noteId);
|
|
1098
|
+
const anyOpen = [...this.sessions.values()].some(s => s.noteId || s.route === 'todo');
|
|
943
1099
|
if (anyOpen && !this.unwatch && this.options.watchNotes && !this.closed) {
|
|
944
1100
|
this.unwatch = this.options.watchNotes(() => {
|
|
945
1101
|
if (this.remoteTimer)
|
|
946
1102
|
clearTimeout(this.remoteTimer);
|
|
947
1103
|
this.remoteTimer = setTimeout(() => {
|
|
948
1104
|
this.remoteTimer = null;
|
|
1105
|
+
// Tasks live in notes: any note change may change the list.
|
|
1106
|
+
this.touchTodos();
|
|
949
1107
|
this.checkRemote().catch(error => this.options.log?.('remote check failed', { error: String(error) }));
|
|
950
1108
|
}, REMOTE_DEBOUNCE_MS);
|
|
951
1109
|
});
|
|
@@ -967,9 +1125,9 @@ export class EditorService {
|
|
|
967
1125
|
if (!this.options.persistence)
|
|
968
1126
|
return;
|
|
969
1127
|
const sessions = [...this.sessions.values()]
|
|
970
|
-
.filter(s => s.noteId)
|
|
971
|
-
.map(({ key, noteId, title, knownHash, knownVersion, openSeq, suggestions, activity, updatedAt, version, blockSeq }) => ({
|
|
972
|
-
key, noteId, title, knownHash, knownVersion, openSeq, version, blockSeq,
|
|
1128
|
+
.filter(s => s.noteId || s.todoSeq > 0)
|
|
1129
|
+
.map(({ key, noteId, title, knownHash, knownVersion, openSeq, suggestions, activity, updatedAt, version, blockSeq, route, todoSeq, todoFilter }) => ({
|
|
1130
|
+
key, noteId, title, knownHash, knownVersion, openSeq, version, blockSeq, route, todoSeq, todoFilter,
|
|
973
1131
|
suggestions: suggestions.filter(s => s.status === 'pending'),
|
|
974
1132
|
activity: activity.slice(-MAX_ACTIVITY),
|
|
975
1133
|
updatedAt,
|
|
@@ -1005,3 +1163,12 @@ function findBlock(blocks, id) {
|
|
|
1005
1163
|
function blockRef(blocks, value) {
|
|
1006
1164
|
return findBlock(blocks, value)?.id ?? value;
|
|
1007
1165
|
}
|
|
1166
|
+
/** A persisted filter from an older or damaged file falls back to the default. */
|
|
1167
|
+
function safeFilter(raw) {
|
|
1168
|
+
try {
|
|
1169
|
+
return parseTodoFilter(raw);
|
|
1170
|
+
}
|
|
1171
|
+
catch {
|
|
1172
|
+
return { ...DEFAULT_TODO_FILTER };
|
|
1173
|
+
}
|
|
1174
|
+
}
|