@dinoxx/dinox-cli 2.16.1 → 2.18.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 (73) hide show
  1. package/dist/cli.js +2 -0
  2. package/dist/commands/editor/index.d.ts +4 -0
  3. package/dist/commands/editor/index.js +155 -0
  4. package/dist/commands/notes/contentPatch.d.ts +23 -0
  5. package/dist/commands/notes/contentPatch.js +37 -0
  6. package/dist/commands/schema/renderSkills.js +1 -0
  7. package/dist/commands/schema/spec.js +2 -0
  8. package/dist/daemon/server.d.ts +2 -1
  9. package/dist/daemon/server.js +22 -2
  10. package/dist/dsh-plugin/cordis.patch.yml +3 -0
  11. package/dist/dsh-plugin/lib/client.js +2145 -0
  12. package/dist/dsh-plugin/lib/index.js +369 -0
  13. package/dist/dsh-plugin/package.json +32 -0
  14. package/dist/dsh-plugin/runtime.json +5 -0
  15. package/dist/editor/anchor.d.ts +46 -0
  16. package/dist/editor/anchor.js +129 -0
  17. package/dist/editor/blockIds.d.ts +21 -0
  18. package/dist/editor/blockIds.js +51 -0
  19. package/dist/editor/blocks.d.ts +47 -0
  20. package/dist/editor/blocks.js +236 -0
  21. package/dist/editor/compat.d.ts +32 -0
  22. package/dist/editor/compat.js +392 -0
  23. package/dist/editor/daemon.d.ts +10 -0
  24. package/dist/editor/daemon.js +56 -0
  25. package/dist/editor/document.d.ts +74 -0
  26. package/dist/editor/document.js +88 -0
  27. package/dist/editor/i18n.d.ts +23 -0
  28. package/dist/editor/i18n.js +61 -0
  29. package/dist/editor/install.d.ts +72 -0
  30. package/dist/editor/install.js +239 -0
  31. package/dist/editor/mcp.d.ts +22 -0
  32. package/dist/editor/mcp.js +222 -0
  33. package/dist/editor/meta.d.ts +70 -0
  34. package/dist/editor/meta.js +163 -0
  35. package/dist/editor/paths.d.ts +2 -0
  36. package/dist/editor/paths.js +13 -0
  37. package/dist/editor/persistence.d.ts +4 -0
  38. package/dist/editor/persistence.js +35 -0
  39. package/dist/editor/saveGuard.d.ts +9 -0
  40. package/dist/editor/saveGuard.js +38 -0
  41. package/dist/editor/schema.d.ts +14 -0
  42. package/dist/editor/schema.js +38 -0
  43. package/dist/editor/service.d.ts +326 -0
  44. package/dist/editor/service.js +1007 -0
  45. package/dist/editor-ui/mcp-app.html +765 -0
  46. package/dist/gateway/adapters/acp.d.ts +8 -0
  47. package/dist/gateway/adapters/acp.js +38 -2
  48. package/dist/gateway/agentTaskHost.d.ts +135 -0
  49. package/dist/gateway/agentTaskHost.js +410 -0
  50. package/dist/gateway/config.js +2 -2
  51. package/dist/gateway/deviceHost.d.ts +6 -1
  52. package/dist/gateway/deviceHost.js +22 -4
  53. package/dist/gateway/mcpCommandTools.d.ts +1 -1
  54. package/dist/gateway/mcpCommandTools.js +2 -2
  55. package/dist/gateway/processTree.d.ts +15 -0
  56. package/dist/gateway/processTree.js +60 -0
  57. package/dist/gateway/protocol.js +2 -1
  58. package/dist/gateway/service.d.ts +1 -1
  59. package/dist/gateway/service.js +3 -1
  60. package/dist/gateway/taskJournal.d.ts +14 -0
  61. package/dist/gateway/taskJournal.js +47 -0
  62. package/dist/gateway/threadStore.d.ts +7 -1
  63. package/dist/gateway/threadStore.js +14 -3
  64. package/dist/gateway/types.d.ts +7 -3
  65. package/dist/gateway/types.js +3 -1
  66. package/dist/integrations/dsh/host.d.ts +53 -0
  67. package/dist/integrations/dsh/host.js +237 -0
  68. package/dist/integrations/dsh/mcpClient.d.ts +66 -0
  69. package/dist/integrations/dsh/mcpClient.js +192 -0
  70. package/dist/utils/errorCodes.d.ts +28 -0
  71. package/dist/utils/errorCodes.js +7 -0
  72. package/dist/vendor/electron/shared/remote-device-agent.d.ts +2 -0
  73. package/package.json +9 -2
@@ -0,0 +1,70 @@
1
+ import type { AbstractPowerSyncDatabase } from '@powersync/common';
2
+ import type { NotePropertiesPatch, NotePropertyValue, PropertyType } from '../vendor/electron/shared/index.js';
3
+ /**
4
+ * Everything around a note's body that the editor header shows and edits:
5
+ * title, tags, card boxes, starred, timestamps and property values.
6
+ */
7
+ export type EditorOption = {
8
+ id: string;
9
+ label: string;
10
+ color: string;
11
+ group?: string;
12
+ };
13
+ export type EditorBox = {
14
+ id: string;
15
+ name: string;
16
+ path: string;
17
+ color: string;
18
+ };
19
+ export type EditorProperty = {
20
+ key: string;
21
+ name: string;
22
+ type: PropertyType;
23
+ value: NotePropertyValue | null;
24
+ options?: EditorOption[];
25
+ };
26
+ export type EditorMeta = {
27
+ title: string;
28
+ tags: string[];
29
+ boxes: EditorBox[];
30
+ starred: boolean;
31
+ createdAt: string | null;
32
+ updatedAt: string | null;
33
+ version: number | null;
34
+ properties: EditorProperty[];
35
+ /** False when the stored property JSON is unreadable; property edits are refused. */
36
+ propertiesValid: boolean;
37
+ };
38
+ export type EditorCatalog = {
39
+ tags: string[];
40
+ boxes: EditorBox[];
41
+ properties: Array<{
42
+ key: string;
43
+ name: string;
44
+ type: PropertyType;
45
+ options?: EditorOption[];
46
+ }>;
47
+ };
48
+ export type EditorMetaPatch = {
49
+ title?: string;
50
+ tags?: string[];
51
+ boxes?: string[];
52
+ starred?: boolean;
53
+ /** Values to set; `null` clears the value but keeps the property on the note. */
54
+ properties?: NotePropertiesPatch;
55
+ /** Property keys to add as empty slots. */
56
+ declare?: string[];
57
+ /** Property keys to take off the note. */
58
+ remove?: string[];
59
+ };
60
+ /** Validates an untrusted patch from the panel. */
61
+ export declare function parseMetaPatch(input: unknown): EditorMetaPatch;
62
+ export declare function createMetaStore(db: AbstractPowerSyncDatabase, userId: string): {
63
+ meta: (noteId: string) => Promise<EditorMeta>;
64
+ catalog: () => Promise<EditorCatalog>;
65
+ update: (noteId: string, patch: EditorMetaPatch) => Promise<{
66
+ changed: string[];
67
+ meta: EditorMeta;
68
+ }>;
69
+ };
70
+ export type EditorMetaStore = ReturnType<typeof createMetaStore>;
@@ -0,0 +1,163 @@
1
+ import { listBoxes } from '../commands/boxes/repo.js';
2
+ import { parseStoredTags, parseZettelBoxIds } from '../commands/notes/repo/shared.js';
3
+ import { updateNote } from '../commands/notes/repo/write.js';
4
+ import { listProperties, readNoteProperties, setNoteProperties, updateNotePropertySlots } from '../commands/properties/repo.js';
5
+ import { canonicalizeTagPath, normalizeTagLookupKey } from '../commands/tags/model.js';
6
+ import { addTag, listTags } from '../commands/tags/repo.js';
7
+ import { DinoxError } from '../utils/errors.js';
8
+ const MAX_TITLE = 500;
9
+ const MAX_LIST = 100;
10
+ function version(value) {
11
+ const n = Number(value);
12
+ return value !== null && value !== undefined && Number.isFinite(n) ? n : null;
13
+ }
14
+ function options(list) {
15
+ return list?.filter(option => !option.archived).map(({ id, label, color, group }) => ({ id, label, color, ...(group ? { group } : {}) }));
16
+ }
17
+ function usage(message) {
18
+ return new DinoxError(message, { code: 'USAGE_ERROR', recoverable: false });
19
+ }
20
+ function stringList(value, label) {
21
+ if (!Array.isArray(value) || value.some(item => typeof item !== 'string'))
22
+ throw usage(`${label} must be a list of strings`);
23
+ if (value.length > MAX_LIST)
24
+ throw usage(`${label} has too many items`);
25
+ return value.map(item => item.trim()).filter(Boolean);
26
+ }
27
+ /** Validates an untrusted patch from the panel. */
28
+ export function parseMetaPatch(input) {
29
+ if (!input || typeof input !== 'object' || Array.isArray(input))
30
+ throw usage('patch must be an object');
31
+ const raw = input;
32
+ const patch = {};
33
+ if (raw.title !== undefined) {
34
+ if (typeof raw.title !== 'string')
35
+ throw usage('title must be a string');
36
+ patch.title = raw.title.replace(/[\r\n]+/g, ' ').trim().slice(0, MAX_TITLE);
37
+ }
38
+ if (raw.tags !== undefined)
39
+ patch.tags = stringList(raw.tags, 'tags');
40
+ if (raw.boxes !== undefined)
41
+ patch.boxes = stringList(raw.boxes, 'boxes');
42
+ if (raw.starred !== undefined)
43
+ patch.starred = Boolean(raw.starred);
44
+ if (raw.declare !== undefined)
45
+ patch.declare = stringList(raw.declare, 'declare');
46
+ if (raw.remove !== undefined)
47
+ patch.remove = stringList(raw.remove, 'remove');
48
+ if (raw.properties !== undefined) {
49
+ if (!raw.properties || typeof raw.properties !== 'object' || Array.isArray(raw.properties))
50
+ throw usage('properties must be an object');
51
+ patch.properties = raw.properties;
52
+ }
53
+ return patch;
54
+ }
55
+ export function createMetaStore(db, userId) {
56
+ const row = async (noteId) => {
57
+ const found = await db.getOptional('SELECT id, title, tags, zettel_boxes, starred_at, created_at, updated_at, version, is_del FROM c_note WHERE id = ?', [noteId]);
58
+ if (!found || Number(found.is_del ?? 0) !== 0) {
59
+ throw new DinoxError(`Note not found: ${noteId}`, { code: 'NOTE_NOT_FOUND', recoverable: true });
60
+ }
61
+ return found;
62
+ };
63
+ const boxesById = async () => new Map((await listBoxes(db)).map(box => [box.id, box]));
64
+ async function meta(noteId) {
65
+ const note = await row(noteId);
66
+ const [boxes, props, defs] = await Promise.all([
67
+ boxesById(),
68
+ readNoteProperties(db, { userId, noteId }).catch(() => null),
69
+ listProperties(db, { userId, limit: 5000 }).catch(() => []),
70
+ ]);
71
+ const byKey = new Map(defs.map(def => [def.key, def]));
72
+ return {
73
+ title: note.title?.trim() ?? '',
74
+ tags: parseStoredTags(note.tags),
75
+ boxes: parseZettelBoxIds(note.zettel_boxes).map(id => {
76
+ const box = boxes.get(id);
77
+ return { id, name: box?.name || '未知卡片盒', path: box?.path || '', color: box?.color || '' };
78
+ }),
79
+ starred: Boolean(note.starred_at),
80
+ createdAt: note.created_at ?? null,
81
+ updatedAt: note.updated_at ?? null,
82
+ version: version(note.version),
83
+ properties: (props?.entries ?? []).map(entry => {
84
+ const list = options(byKey.get(entry.key)?.options);
85
+ return { key: entry.key, name: entry.name, type: entry.type, value: entry.value, ...(list ? { options: list } : {}) };
86
+ }),
87
+ propertiesValid: props?.valid ?? false,
88
+ };
89
+ }
90
+ async function catalog() {
91
+ const [tags, boxes, defs] = await Promise.all([
92
+ listTags(db, { userId }),
93
+ listBoxes(db),
94
+ listProperties(db, { userId, limit: 5000 }),
95
+ ]);
96
+ return {
97
+ tags,
98
+ boxes: boxes.map(({ id, name, path, color }) => ({ id, name, path, color })),
99
+ properties: defs.map(def => {
100
+ const list = options(def.options);
101
+ return { key: def.key, name: def.name, type: def.type, ...(list ? { options: list } : {}) };
102
+ }),
103
+ };
104
+ }
105
+ /** Tags are matched to existing ones case-insensitively; unknown ones are created, like the desktop does. */
106
+ async function resolveTags(requested) {
107
+ const known = new Map((await listTags(db, { userId })).map(tag => [normalizeTagLookupKey(tag), tag]));
108
+ const result = [];
109
+ for (const raw of requested) {
110
+ const tag = canonicalizeTagPath(raw.replace(/^#/, ''));
111
+ if (!tag)
112
+ continue;
113
+ const key = normalizeTagLookupKey(tag);
114
+ let match = known.get(key);
115
+ if (!match) {
116
+ match = (await addTag(db, { name: tag, userId })).tag;
117
+ known.set(key, match);
118
+ }
119
+ if (!result.includes(match))
120
+ result.push(match);
121
+ }
122
+ return result;
123
+ }
124
+ async function update(noteId, patch) {
125
+ await row(noteId);
126
+ const changed = [];
127
+ const fields = { id: noteId };
128
+ if (patch.title !== undefined)
129
+ fields.title = patch.title;
130
+ if (patch.tags !== undefined)
131
+ fields.tags = await resolveTags(patch.tags);
132
+ if (patch.boxes !== undefined) {
133
+ const boxes = await boxesById();
134
+ const unknown = patch.boxes.filter(id => !boxes.has(id));
135
+ if (unknown.length)
136
+ throw new DinoxError(`Unknown card boxes: ${unknown.join(', ')}`, { code: 'USAGE_ERROR', recoverable: false });
137
+ fields.zettelBoxIds = patch.boxes;
138
+ }
139
+ if (patch.starred !== undefined)
140
+ fields.starred = patch.starred;
141
+ if (Object.keys(fields).length > 1) {
142
+ const result = await updateNote(db, fields);
143
+ changed.push(...result.changed);
144
+ }
145
+ if (patch.declare?.length) {
146
+ const result = await updateNotePropertySlots(db, { userId, noteId, operation: 'declare', keys: patch.declare });
147
+ if (result.changed)
148
+ changed.push('properties');
149
+ }
150
+ if (patch.properties && Object.keys(patch.properties).length) {
151
+ const result = await setNoteProperties(db, { userId, noteId, patch: patch.properties });
152
+ if (result.changed)
153
+ changed.push('properties');
154
+ }
155
+ if (patch.remove?.length) {
156
+ const result = await updateNotePropertySlots(db, { userId, noteId, operation: 'remove', keys: patch.remove });
157
+ if (result.changed)
158
+ changed.push('properties');
159
+ }
160
+ return { changed: [...new Set(changed)], meta: await meta(noteId) };
161
+ }
162
+ return { meta, catalog, update };
163
+ }
@@ -0,0 +1,2 @@
1
+ /** The dinox-cli package root (a checkout or the installed npm package). */
2
+ export declare function editorPackageRoot(): string;
@@ -0,0 +1,13 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ /** The dinox-cli package root (a checkout or the installed npm package). */
5
+ export function editorPackageRoot() {
6
+ let dir = path.dirname(fileURLToPath(import.meta.url));
7
+ for (let i = 0; i < 6; i++) {
8
+ if (existsSync(path.join(dir, 'package.json')) && (existsSync(path.join(dir, 'src')) || existsSync(path.join(dir, 'dist'))))
9
+ return dir;
10
+ dir = path.dirname(dir);
11
+ }
12
+ throw new Error('Cannot locate the dinox-cli package');
13
+ }
@@ -0,0 +1,4 @@
1
+ import type { EditorPersistence } from './service.js';
2
+ /** Editor sessions live beside the account's database: one file per user, never shared. */
3
+ export declare function editorSessionsPath(userId: string | null): string;
4
+ export declare function createFilePersistence(filePath: string): EditorPersistence;
@@ -0,0 +1,35 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { getPowerSyncDbPath } from '../config/paths.js';
5
+ const FILE_NAME = 'editor-sessions.json';
6
+ const FORMAT_VERSION = 1;
7
+ /** Editor sessions live beside the account's database: one file per user, never shared. */
8
+ export function editorSessionsPath(userId) {
9
+ return path.join(path.dirname(getPowerSyncDbPath(userId)), FILE_NAME);
10
+ }
11
+ export function createFilePersistence(filePath) {
12
+ return {
13
+ async load() {
14
+ try {
15
+ const parsed = JSON.parse(await readFile(filePath, 'utf8'));
16
+ return parsed.version === FORMAT_VERSION && Array.isArray(parsed.sessions) ? parsed.sessions : [];
17
+ }
18
+ catch {
19
+ return [];
20
+ }
21
+ },
22
+ async save(sessions) {
23
+ await mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
24
+ const tmp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
25
+ try {
26
+ await writeFile(tmp, JSON.stringify({ version: FORMAT_VERSION, sessions }), { mode: 0o600 });
27
+ await rename(tmp, filePath);
28
+ }
29
+ catch (error) {
30
+ await rm(tmp, { force: true });
31
+ throw error;
32
+ }
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,9 @@
1
+ import type { JSONContent } from '@tiptap/core';
2
+ import type { Schema } from '@tiptap/pm/model';
3
+ /**
4
+ * Refuses a document that would write content the editor could not have
5
+ * produced: node or mark types unknown to the schema that the stored note did
6
+ * not already contain, or an opaque wrapper that was never unwrapped.
7
+ * Deleting content is always allowed.
8
+ */
9
+ export declare function guardSave(stored: JSONContent, incoming: JSONContent, schema: Schema): void;
@@ -0,0 +1,38 @@
1
+ import { DinoxError } from '../utils/errors.js';
2
+ const OPAQUE_TYPES = new Set(['dxOpaqueBlock', 'dxOpaqueInline']);
3
+ function unknownTypes(doc, schema) {
4
+ const found = new Set();
5
+ const walk = (node) => {
6
+ const type = node.type ?? '';
7
+ if (!schema.nodes[type])
8
+ found.add(type);
9
+ for (const mark of node.marks ?? [])
10
+ if (!schema.marks[mark.type])
11
+ found.add(mark.type);
12
+ node.content?.forEach(walk);
13
+ };
14
+ walk(doc);
15
+ return found;
16
+ }
17
+ /**
18
+ * Refuses a document that would write content the editor could not have
19
+ * produced: node or mark types unknown to the schema that the stored note did
20
+ * not already contain, or an opaque wrapper that was never unwrapped.
21
+ * Deleting content is always allowed.
22
+ */
23
+ export function guardSave(stored, incoming, schema) {
24
+ if (!incoming || incoming.type !== 'doc' || !Array.isArray(incoming.content)) {
25
+ throw new DinoxError('Invalid note document: expected an object with type doc and array content', {
26
+ code: 'EDITOR_INVALID_DOCUMENT',
27
+ });
28
+ }
29
+ const before = unknownTypes(stored, schema);
30
+ for (const type of unknownTypes(incoming, schema)) {
31
+ if (OPAQUE_TYPES.has(type) || !before.has(type)) {
32
+ throw new DinoxError(`The document introduces content the editor cannot save: ${type}`, {
33
+ code: 'EDITOR_INVALID_DOCUMENT',
34
+ details: { type },
35
+ });
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,14 @@
1
+ import { type AnyExtension, type JSONContent } from '@tiptap/core';
2
+ import type { Node as PMNode, Schema } from '@tiptap/pm/model';
3
+ /**
4
+ * The editor's document model: exactly the CLI's Dinox Tiptap schema.
5
+ * Presentation (node views, labels) is layered on in the browser bundle and
6
+ * must never change node names, attributes or content expressions.
7
+ */
8
+ export declare function baseEditorExtensions(): AnyExtension[];
9
+ export declare function baseEditorSchema(): Schema;
10
+ /** The per-document schema (base + compatibility) and the document parsed with it. */
11
+ export declare function parseEditorDocument(document: JSONContent): {
12
+ schema: Schema;
13
+ node: PMNode;
14
+ };
@@ -0,0 +1,38 @@
1
+ import { getSchema } from '@tiptap/core';
2
+ import { createDinoxMarkdownExtensions } from '../utils/tiptapMarkdownSchema.js';
3
+ import { BlockIdAttribute } from './blockIds.js';
4
+ import { analyze, compatExtensions, wrapUnknown } from './compat.js';
5
+ /**
6
+ * The editor's document model: exactly the CLI's Dinox Tiptap schema.
7
+ * Presentation (node views, labels) is layered on in the browser bundle and
8
+ * must never change node names, attributes or content expressions.
9
+ */
10
+ export function baseEditorExtensions() {
11
+ return [
12
+ ...createDinoxMarkdownExtensions().map(extension => (extension.name === 'image' ? withImageCaption(extension) : extension)),
13
+ BlockIdAttribute,
14
+ ];
15
+ }
16
+ /**
17
+ * The desktop image node holds its caption as inline content
18
+ * (`content: "inline*"`); the editor must accept that or such notes fail to
19
+ * open. An image without a caption is unchanged.
20
+ */
21
+ function withImageCaption(extension) {
22
+ return extension.extend({
23
+ content: 'inline*',
24
+ renderHTML({ HTMLAttributes }) {
25
+ return ['figure', { 'data-type': 'image' }, ['img', HTMLAttributes], ['figcaption', 0]];
26
+ },
27
+ });
28
+ }
29
+ let cachedBaseSchema = null;
30
+ export function baseEditorSchema() {
31
+ return (cachedBaseSchema ??= getSchema(baseEditorExtensions()));
32
+ }
33
+ /** The per-document schema (base + compatibility) and the document parsed with it. */
34
+ export function parseEditorDocument(document) {
35
+ const base = baseEditorSchema();
36
+ const schema = getSchema([...baseEditorExtensions(), ...compatExtensions(analyze(document, base))]);
37
+ return { schema, node: schema.nodeFromJSON(wrapUnknown(document, schema)) };
38
+ }