@dinoxx/dinox-cli 2.17.0 → 2.18.1

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 (79) hide show
  1. package/README.md +39 -11
  2. package/dist/cli.js +2 -0
  3. package/dist/commands/editor/index.d.ts +4 -0
  4. package/dist/commands/editor/index.js +155 -0
  5. package/dist/commands/notes/contentPatch.d.ts +23 -0
  6. package/dist/commands/notes/contentPatch.js +37 -0
  7. package/dist/commands/schema/renderSkills.js +1 -0
  8. package/dist/commands/schema/spec.js +2 -0
  9. package/dist/commands/update.d.ts +3 -0
  10. package/dist/commands/update.js +45 -2
  11. package/dist/daemon/server.d.ts +2 -1
  12. package/dist/daemon/server.js +22 -2
  13. package/dist/dinox.js +12 -1
  14. package/dist/dsh-plugin/cordis.patch.yml +3 -0
  15. package/dist/dsh-plugin/lib/client.js +2145 -0
  16. package/dist/dsh-plugin/lib/index.js +369 -0
  17. package/dist/dsh-plugin/package.json +32 -0
  18. package/dist/dsh-plugin/runtime.json +5 -0
  19. package/dist/editor/anchor.d.ts +46 -0
  20. package/dist/editor/anchor.js +129 -0
  21. package/dist/editor/blockIds.d.ts +21 -0
  22. package/dist/editor/blockIds.js +51 -0
  23. package/dist/editor/blocks.d.ts +47 -0
  24. package/dist/editor/blocks.js +236 -0
  25. package/dist/editor/compat.d.ts +32 -0
  26. package/dist/editor/compat.js +392 -0
  27. package/dist/editor/daemon.d.ts +10 -0
  28. package/dist/editor/daemon.js +56 -0
  29. package/dist/editor/document.d.ts +74 -0
  30. package/dist/editor/document.js +88 -0
  31. package/dist/editor/i18n.d.ts +23 -0
  32. package/dist/editor/i18n.js +61 -0
  33. package/dist/editor/install.d.ts +72 -0
  34. package/dist/editor/install.js +239 -0
  35. package/dist/editor/mcp.d.ts +22 -0
  36. package/dist/editor/mcp.js +222 -0
  37. package/dist/editor/meta.d.ts +70 -0
  38. package/dist/editor/meta.js +163 -0
  39. package/dist/editor/paths.d.ts +2 -0
  40. package/dist/editor/paths.js +13 -0
  41. package/dist/editor/persistence.d.ts +4 -0
  42. package/dist/editor/persistence.js +35 -0
  43. package/dist/editor/saveGuard.d.ts +9 -0
  44. package/dist/editor/saveGuard.js +38 -0
  45. package/dist/editor/schema.d.ts +14 -0
  46. package/dist/editor/schema.js +38 -0
  47. package/dist/editor/service.d.ts +326 -0
  48. package/dist/editor/service.js +1007 -0
  49. package/dist/editor-ui/mcp-app.html +765 -0
  50. package/dist/gateway/adapters/acp.d.ts +8 -0
  51. package/dist/gateway/adapters/acp.js +38 -2
  52. package/dist/gateway/agentTaskHost.d.ts +9 -3
  53. package/dist/gateway/agentTaskHost.js +45 -25
  54. package/dist/gateway/config.js +2 -2
  55. package/dist/gateway/deviceHost.d.ts +1 -1
  56. package/dist/gateway/deviceHost.js +8 -4
  57. package/dist/gateway/mcpCommandTools.d.ts +1 -1
  58. package/dist/gateway/mcpCommandTools.js +2 -2
  59. package/dist/gateway/processTree.d.ts +15 -0
  60. package/dist/gateway/processTree.js +60 -0
  61. package/dist/gateway/protocol.js +2 -1
  62. package/dist/gateway/service.d.ts +1 -1
  63. package/dist/gateway/service.js +2 -1
  64. package/dist/gateway/taskJournal.d.ts +14 -0
  65. package/dist/gateway/taskJournal.js +47 -0
  66. package/dist/gateway/threadStore.d.ts +7 -1
  67. package/dist/gateway/threadStore.js +14 -3
  68. package/dist/gateway/types.d.ts +7 -3
  69. package/dist/gateway/types.js +3 -1
  70. package/dist/integrations/dsh/host.d.ts +53 -0
  71. package/dist/integrations/dsh/host.js +237 -0
  72. package/dist/integrations/dsh/mcpClient.d.ts +66 -0
  73. package/dist/integrations/dsh/mcpClient.js +192 -0
  74. package/dist/utils/errorCodes.d.ts +28 -0
  75. package/dist/utils/errorCodes.js +7 -0
  76. package/dist/utils/nodeRuntime.d.ts +4 -0
  77. package/dist/utils/nodeRuntime.js +12 -0
  78. package/dist/vendor/electron/shared/remote-device-agent.d.ts +2 -0
  79. package/package.json +9 -2
package/README.md CHANGED
@@ -65,10 +65,16 @@ npm -v
65
65
 
66
66
  ### 2.2 安装 Dinox CLI
67
67
 
68
- 推荐直接全局安装:
68
+ 先确认 `node -v` 是 v22、v23、v24 或 v25,再全局安装。npm 11.16 及以后默认不编译 `better-sqlite3` 和 `sharp`,安装命令要放行这两个包:
69
69
 
70
70
  ```bash
71
- npm install -g @dinoxx/dinox-cli
71
+ npm install -g @dinoxx/dinox-cli@latest --allow-scripts=better-sqlite3,sharp
72
+ ```
73
+
74
+ `npm -v` 低于 11.16 时没有 `--allow-scripts`,去掉这个参数再装。用 pnpm 10.15 及以后时:
75
+
76
+ ```bash
77
+ pnpm add -g @dinoxx/dinox-cli@latest --allow-build=better-sqlite3 --allow-build=sharp
72
78
  ```
73
79
 
74
80
  安装完成后,验证是否成功:
@@ -79,14 +85,20 @@ dino info
79
85
 
80
86
  看到版本号就表示安装成功。
81
87
 
82
- > 说明:安装后通常可以使用 `dino` 或 `dinox` 两个命令名,本文统一使用 `dino`。
88
+ > 说明:安装后通常可以使用 `dino` 或 `dinox` 两个命令名,本文统一使用 `dino`。`dino` 用的是安装时 PATH 里的那个 `node`。
83
89
 
84
90
  ### 2.3 macOS 安装 Node.js(如果你还没装)
85
91
 
92
+ Homebrew 的 `node` 公式现在是 Node.js 26,CLI 不能用它。安装 Node.js 24:
93
+
86
94
  ```bash
87
- brew install node
95
+ brew install node@24
96
+ export PATH="$(brew --prefix node@24)/bin:$PATH"
97
+ node -v
88
98
  ```
89
99
 
100
+ `node -v` 应显示 v24。再执行上面的安装命令。
101
+
90
102
  ### 2.4 Windows 安装 Node.js(如果你还没装)
91
103
 
92
104
  PowerShell 中可使用:
@@ -103,6 +115,8 @@ winget install OpenJS.NodeJS.LTS
103
115
  dino update
104
116
  ```
105
117
 
118
+ 它会安装 `@latest`,所以可以从 1.x 升到 2.x。npm 11.16+ 会自动加上 `--allow-scripts=better-sqlite3,sharp`,pnpm 10.15+ 会自动加上 `--allow-build`。旧版 `dino update` 只在 1.x 里更新,版本停在 1.x 时改用上面的安装命令。
119
+
106
120
  它会自动根据你当前的安装方式选择合适的包管理器执行更新。升级完成后会检查本机已安装的 Agent:有 `claude` 但没有 ACP 命令时安装 `@agentclientprotocol/claude-agent-acp`,有 `codex` 时安装 `@agentclientprotocol/codex-acp`,有 `zcode` 时安装 `zcode-acp`,有 `pi` 时安装 `pi-acp`,有 `agy` 时安装 `agy-acp`,有 `muse` 时安装 `@bex-co/muse-code-acp`。已经装过的适配器会跳过;某个适配器安装失败只给出警告,不影响 CLI 升级本身。
107
121
 
108
122
  ---
@@ -1006,7 +1020,21 @@ schema 包含命令路径、风险级别、参数、选项、输出字段和示
1006
1020
 
1007
1021
  ## 8. 常见问题
1008
1022
 
1009
- ### Q1:报错 `Missing resolved userId for the current authorization`
1023
+ ### Q1:安装或升级后出现 `allowScripts` / `Ignored build scripts`,或者一用就报 `better-sqlite3`
1024
+
1025
+ 原因:本地数据库依赖 `better-sqlite3`,图片处理依赖 `sharp`。npm 11.16+ 和 pnpm 10.15+ 默认不运行这两个包的安装脚本,本机程序就没有装上。Node.js 26 也不在支持范围内,Homebrew 的 `brew install node` 现在装的就是 26。
1026
+
1027
+ 解决:换成 Node.js 24,再重新安装。
1028
+
1029
+ ```bash
1030
+ node -v
1031
+ npm install -g @dinoxx/dinox-cli@latest --allow-scripts=better-sqlite3,sharp
1032
+ dino info
1033
+ ```
1034
+
1035
+ `node -v` 必须是 v22 到 v25。黄字警告本身不是升级失败;版本号没有变成最新版时,用上面这条命令,不要继续用旧的 `dino update`。
1036
+
1037
+ ### Q2:报错 `Missing resolved userId for the current authorization`
1010
1038
 
1011
1039
  原因:你还没有完成登录,或当前 `DINOX_TOKEN` 环境变量覆盖了本地 token,CLI 需要先在线解析这个 token 对应的用户身份。
1012
1040
 
@@ -1025,7 +1053,7 @@ dino auth status --format json
1025
1053
  dino sync
1026
1054
  ```
1027
1055
 
1028
- ### Q2:创建笔记时报 `Unknown tags` 或 `Unknown zettel box names`
1056
+ ### Q3:创建笔记时报 `Unknown tags` 或 `Unknown zettel box names`
1029
1057
 
1030
1058
  原因:你引用了不存在的标签或卡片盒。
1031
1059
 
@@ -1036,7 +1064,7 @@ dino tag add "你的标签"
1036
1064
  dino box add "你的卡片盒"
1037
1065
  ```
1038
1066
 
1039
- ### Q3:我已经同步过了,能不能完全离线查询?
1067
+ ### Q4:我已经同步过了,能不能完全离线查询?
1040
1068
 
1041
1069
  可以。很多读命令都支持:
1042
1070
 
@@ -1053,7 +1081,7 @@ dino graph stats --offline --format json
1053
1081
 
1054
1082
  前提是:你之前至少成功同步过一次,本地缓存里已经有数据。
1055
1083
 
1056
- ### Q4:`note update` 为什么不是“追加标签”?
1084
+ ### Q5:`note update` 为什么不是“追加标签”?
1057
1085
 
1058
1086
  因为它的设计就是“全量替换”。
1059
1087
 
@@ -1071,7 +1099,7 @@ dino note update <note-id> --tags "工作,AI"
1071
1099
  dino note tag <note-id> --add "工作,AI"
1072
1100
  ```
1073
1101
 
1074
- ### Q5:`todo append` 不传 `--note-id` 时会发生什么?
1102
+ ### Q6:`todo append` 不传 `--note-id` 时会发生什么?
1075
1103
 
1076
1104
  CLI 会自动选一条最近的、适合追加任务的笔记作为目标。
1077
1105
 
@@ -1081,7 +1109,7 @@ CLI 会自动选一条最近的、适合追加任务的笔记作为目标。
1081
1109
  dino todo append --note-id <note-id> --task "补交报销单"
1082
1110
  ```
1083
1111
 
1084
- ### Q6:Windows 下 `@file` 参数解析不稳定怎么办?
1112
+ ### Q7:Windows 下 `@file` 参数解析不稳定怎么办?
1085
1113
 
1086
1114
  在 PowerShell 中,建议把 `@文件路径` 放进引号里。
1087
1115
 
@@ -1091,7 +1119,7 @@ dino todo append --note-id <note-id> --task "补交报销单"
1091
1119
  dino note create --title "测试" --content "@.\note.md" --type note
1092
1120
  ```
1093
1121
 
1094
- ### Q7:怎么知道某个命令到底支持哪些参数?
1122
+ ### Q8:怎么知道某个命令到底支持哪些参数?
1095
1123
 
1096
1124
  最直接的方法:
1097
1125
 
package/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import { registerAuthCommands } from './commands/auth/index.js';
3
3
  import { parseCommanderUsageError } from './utils/usageError.js';
4
4
  import { registerBatchCommand } from './commands/batch.js';
5
5
  import { registerMcpCommand } from './commands/mcp.js';
6
+ import { registerEditorCommands } from './commands/editor/index.js';
6
7
  import { registerBoxesCommand } from './commands/boxes/index.js';
7
8
  import { registerConfigCommands } from './commands/config/index.js';
8
9
  import { registerDaemonCommands } from './daemon/index.js';
@@ -111,6 +112,7 @@ export function createCli() {
111
112
  registerGraphCommands(program);
112
113
  registerInfoCommand(program);
113
114
  registerMcpCommand(program);
115
+ registerEditorCommands(program);
114
116
  registerMetaCommands(program);
115
117
  registerSyncCommand(program);
116
118
  registerUpdateCommand(program);
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import type { CommandGroupDescriptor } from '../descriptor/types.js';
3
+ export declare const editorCommandGroup: CommandGroupDescriptor;
4
+ export declare function registerEditorCommands(program: Command): void;
@@ -0,0 +1,155 @@
1
+ import { DinoxError } from '../../utils/errors.js';
2
+ import { getRequestedStructuredOutputFormat, printHumanReadableLine, printSuccess } from '../../utils/output.js';
3
+ import { registerCommandGroup } from '../descriptor/register.js';
4
+ import { FORMAT_OPTIONS } from '../schema/globalOptions.js';
5
+ const HOST_ARGUMENT = { syntax: '<host>', description: 'AI app to set the editor up in: dsh (DeepSeek Harness Desktop)' };
6
+ const PROFILE_OPTION = { flags: '--profile <name>', description: 'dsh profile to use', type: 'string', defaultValue: 'desktop' };
7
+ const DSH_OPTION = { flags: '--dsh <path>', description: 'Path to the dsh CLI (default: the one inside DeepSeek Harness.app, then PATH)', type: 'string' };
8
+ const DRY_RUN_OPTION = { flags: '--dry-run', description: 'Show the planned changes without making them', type: 'boolean' };
9
+ function hostOf(context) {
10
+ const host = String(context.args.host ?? '').toLowerCase();
11
+ if (host !== 'dsh') {
12
+ throw new DinoxError(`Unsupported editor host: ${host || '(none)'}`, {
13
+ code: 'INVALID_ARGUMENT',
14
+ suggestion: 'Use dsh. Codex runs `dino editor mcp` from its own MCP server config.',
15
+ });
16
+ }
17
+ return host;
18
+ }
19
+ function installOptions(context) {
20
+ return {
21
+ profile: typeof context.options.profile === 'string' ? context.options.profile : undefined,
22
+ dsh: typeof context.options.dsh === 'string' ? context.options.dsh : undefined,
23
+ dryRun: Boolean(context.options.dryRun),
24
+ };
25
+ }
26
+ function report(result, done, next) {
27
+ if (getRequestedStructuredOutputFormat()) {
28
+ printSuccess(result);
29
+ return;
30
+ }
31
+ if (!result.actions.length) {
32
+ printHumanReadableLine('Nothing to change.');
33
+ return;
34
+ }
35
+ printHumanReadableLine(result.dryRun ? 'Planned changes:' : done);
36
+ for (const action of result.actions)
37
+ printHumanReadableLine(` - ${action}`);
38
+ if (!result.dryRun && result.restartRequired && next)
39
+ printHumanReadableLine(next);
40
+ }
41
+ export const editorCommandGroup = {
42
+ name: 'editor',
43
+ description: 'Co-edit Dinox notes with an AI in the side panel of AI apps (Codex, DeepSeek Harness)',
44
+ commands: [
45
+ {
46
+ name: 'mcp',
47
+ description: 'Serve the Dinox note editor as an MCP App over stdio (add it to an MCP Apps client such as Codex)',
48
+ options: [
49
+ {
50
+ flags: '--session <name>',
51
+ description: 'Editor session this client shares; clients with the same name see the same open note',
52
+ type: 'string',
53
+ defaultValue: 'mcp',
54
+ },
55
+ ],
56
+ schema: {
57
+ path: 'editor.mcp',
58
+ risk: 'write',
59
+ auth: 'required',
60
+ globalOptions: [],
61
+ output: { type: 'structured', summary: 'MCP JSON-RPC over stdio until stdin closes', fields: [] },
62
+ examples: ['dino editor mcp', 'dino editor mcp --session codex'],
63
+ },
64
+ action: async (context) => {
65
+ const { serveEditorMcpOverStdio } = await import('../../editor/mcp.js');
66
+ await serveEditorMcpOverStdio({ session: String(context.options.session ?? 'mcp') });
67
+ },
68
+ },
69
+ {
70
+ name: 'install',
71
+ description: 'Add the Dinox editor to an AI app (dsh: link the editor plugin into a DeepSeek Harness Desktop profile)',
72
+ arguments: [HOST_ARGUMENT],
73
+ options: [PROFILE_OPTION, DSH_OPTION, DRY_RUN_OPTION],
74
+ schema: {
75
+ path: 'editor.install',
76
+ risk: 'write',
77
+ auth: 'none',
78
+ globalOptions: FORMAT_OPTIONS,
79
+ output: {
80
+ type: 'structured',
81
+ summary: 'What was (or would be) changed in the host app',
82
+ fields: ['host', 'profile', 'profilePath', 'plugin', 'dsh', 'dryRun', 'actions', 'changed', 'restartRequired', 'next'],
83
+ },
84
+ examples: ['dino editor install dsh --dry-run', 'dino editor install dsh --format json'],
85
+ },
86
+ action: async (context) => {
87
+ hostOf(context);
88
+ const { installDsh } = await import('../../editor/install.js');
89
+ const result = await installDsh(installOptions(context));
90
+ report(result, 'Installed the Dinox editor in DeepSeek Harness:', result.next);
91
+ },
92
+ },
93
+ {
94
+ name: 'uninstall',
95
+ description: 'Remove the Dinox editor from an AI app (dsh: take the plugin out of the profile)',
96
+ arguments: [HOST_ARGUMENT],
97
+ options: [PROFILE_OPTION, DSH_OPTION, DRY_RUN_OPTION],
98
+ schema: {
99
+ path: 'editor.uninstall',
100
+ risk: 'write',
101
+ auth: 'none',
102
+ globalOptions: FORMAT_OPTIONS,
103
+ output: {
104
+ type: 'structured',
105
+ summary: 'What was (or would be) removed from the host app',
106
+ fields: ['host', 'profile', 'profilePath', 'dryRun', 'actions', 'changed', 'restartRequired'],
107
+ },
108
+ examples: ['dino editor uninstall dsh --dry-run', 'dino editor uninstall dsh'],
109
+ },
110
+ action: async (context) => {
111
+ hostOf(context);
112
+ const { uninstallDsh } = await import('../../editor/install.js');
113
+ report(await uninstallDsh(installOptions(context)), 'Removed the Dinox editor from DeepSeek Harness:', 'Restart DeepSeek Harness Desktop.');
114
+ },
115
+ },
116
+ {
117
+ name: 'status',
118
+ description: 'Show where the Dinox editor is installed (dsh, Codex) and whether it matches this CLI',
119
+ options: [PROFILE_OPTION],
120
+ schema: {
121
+ path: 'editor.status',
122
+ risk: 'read',
123
+ auth: 'none',
124
+ globalOptions: FORMAT_OPTIONS,
125
+ output: {
126
+ type: 'structured',
127
+ summary: 'This CLI, whether the editor UI is built, and each host app\'s installation',
128
+ fields: ['cli', 'ui', 'hosts'],
129
+ },
130
+ examples: ['dino editor status', 'dino editor status --format json'],
131
+ },
132
+ action: async (context) => {
133
+ const { editorStatus } = await import('../../editor/install.js');
134
+ const status = editorStatus(installOptions(context));
135
+ if (getRequestedStructuredOutputFormat()) {
136
+ printSuccess(status);
137
+ return;
138
+ }
139
+ const [dsh, codex] = status.hosts;
140
+ printHumanReadableLine(`dino ${status.cli.version} · editor UI ${status.ui.built ? 'built' : 'not built (run pnpm build)'}`);
141
+ const dshState = !dsh.installed
142
+ ? (dsh.found ? 'not installed (dino editor install dsh)' : 'DeepSeek Harness not found')
143
+ : `installed in profile ${dsh.profile}` +
144
+ (dsh.bundled ? '' : ', but missing from its bundles (rerun dino editor install dsh)') +
145
+ (dsh.linkedToThisCli ? '' : ', points at another dino') +
146
+ (dsh.upToDate ? '' : `, plugin ${dsh.pluginVersion ?? 'unknown'} (rerun dino editor install dsh)`);
147
+ printHumanReadableLine(`dsh: ${dshState}`);
148
+ printHumanReadableLine(`codex: ${codex.configured ? `configured (${codex.servers.join(', ')})` : 'not configured'}`);
149
+ },
150
+ },
151
+ ],
152
+ };
153
+ export function registerEditorCommands(program) {
154
+ registerCommandGroup(program, editorCommandGroup);
155
+ }
@@ -89,3 +89,26 @@ export declare function applyNoteContentPatch(db: AbstractPowerSyncDatabase, inp
89
89
  readToken: string;
90
90
  operation: NoteContentPatchOperation;
91
91
  }): Promise<NoteContentPatchResult>;
92
+ /** Atomically replace a reviewed editor document, preserving derived note metadata. */
93
+ export declare function replaceNoteDocument(db: AbstractPowerSyncDatabase, input: {
94
+ id: string;
95
+ userId: string;
96
+ baseHash: string;
97
+ baseVersion: number | null;
98
+ document: unknown;
99
+ }): Promise<{
100
+ status: 'saved' | 'unchanged';
101
+ noteId: string;
102
+ title: string;
103
+ hash: string;
104
+ version: number | null;
105
+ updatedAt: string | null;
106
+ } | {
107
+ status: 'conflict';
108
+ noteId: string;
109
+ current: {
110
+ hash: string;
111
+ version: number | null;
112
+ updatedAt: string | null;
113
+ };
114
+ }>;
@@ -411,3 +411,40 @@ export async function applyNoteContentPatch(db, input) {
411
411
  saved: result.changed,
412
412
  };
413
413
  }
414
+ /** Atomically replace a reviewed editor document, preserving derived note metadata. */
415
+ export async function replaceNoteDocument(db, input) {
416
+ return withPowerSyncWriteTransaction(db, async (transaction) => {
417
+ const tx = transaction;
418
+ const row = await readNoteContentRow(tx, input.id);
419
+ const before = parseStoredNoteDocument({ contentJson: row.content_json, contentMd: row.content_md });
420
+ const current = { hash: getNoteContentHash(before), version: normalizeVersion(row.version), updatedAt: row.updated_at ?? null };
421
+ if (current.hash !== input.baseHash || current.version !== input.baseVersion) {
422
+ return { status: 'conflict', noteId: row.id, current };
423
+ }
424
+ if (!input.document || typeof input.document !== 'object' || Array.isArray(input.document)
425
+ || !('type' in input.document) || input.document.type !== 'doc'
426
+ || !('content' in input.document) || !Array.isArray(input.document.content)) {
427
+ throw new DinoxError('Invalid note document: expected an object with type doc and array content', { code: 'USAGE_ERROR' });
428
+ }
429
+ // projectNoteContent applies contentEngine's private normalizeDocument, then resolves hashtags.
430
+ const tagLookup = await loadTagReferenceLookup(tx, input.userId);
431
+ const options = { resolveHashtagReference: createHashtagReferenceResolver(tagLookup, { strictMissingPaths: false }) };
432
+ const projection = projectNoteContent(input.document, options);
433
+ const hash = getNoteContentHash(projection.document);
434
+ if (hash === current.hash) {
435
+ return { status: 'unchanged', noteId: row.id, title: row.title?.trim() ?? '', ...current };
436
+ }
437
+ await updateNoteContentProjection(tx, {
438
+ rowId: row.id,
439
+ contentMd: projection.contentMd, contentJson: projection.contentJson, contentText: projection.contentText,
440
+ tags: mergeProjectedTags(parseStoredTags(row.tags), projectNoteContent(before, options).hashtags, projection.hashtags),
441
+ images: projection.images, bidLinks: projection.bidLinks,
442
+ imageDetail: deriveImageDetailFromContentJson(projection.document, row.id),
443
+ expectedVersion: current.version ?? 0,
444
+ });
445
+ const saved = await readNoteContentRow(tx, row.id);
446
+ return { status: 'saved', noteId: row.id, title: saved.title?.trim() ?? '',
447
+ hash: getNoteContentHash(parseStoredNoteDocument({ contentJson: saved.content_json, contentMd: saved.content_md })),
448
+ version: normalizeVersion(saved.version), updatedAt: saved.updated_at ?? null };
449
+ });
450
+ }
@@ -14,6 +14,7 @@ const SECTION_ORDER = [
14
14
  { title: 'Schema', paths: ['schema'] },
15
15
  { title: 'Batch', paths: ['batch'] },
16
16
  { title: 'MCP Server', paths: ['mcp'] },
17
+ { title: 'Note Co-editing', paths: ['editor.mcp', 'editor.install', 'editor.uninstall', 'editor.status'] },
17
18
  { title: 'Update CLI', paths: ['update'] },
18
19
  { title: 'Agent Skills', paths: ['skills.doctor', 'skills.migrate'] },
19
20
  { title: 'Notes', paths: ['note.search', 'note.semantic', 'note.similar', 'note.context', 'note.get', 'note.preview', 'note.detail', 'note.export', 'note.content-read', 'note.create', 'note.update', 'note.tag', 'note.move', 'note.patch', 'note.bulk', 'note.star', 'note.unstar', 'note.delete'] },
@@ -7,6 +7,7 @@ import { commandSchemasFromGroupDescriptor } from '../descriptor/register.js';
7
7
  import { standaloneCommandSchemaFromDescriptor } from '../descriptor/register.js';
8
8
  import { configCommandGroup } from '../config/index.js';
9
9
  import { gatewayCommandGroup } from '../gateway/index.js';
10
+ import { editorCommandGroup } from '../editor/index.js';
10
11
  import { daemonCommandGroup } from '../../daemon/index.js';
11
12
  import { doctorCommandDescriptor } from '../doctor.js';
12
13
  import { graphCommandGroup } from '../graph/index.js';
@@ -47,6 +48,7 @@ export const COMMAND_SCHEMAS = [
47
48
  standaloneCommandSchemaFromDescriptor(syncCommandDescriptor),
48
49
  standaloneCommandSchemaFromDescriptor(batchCommandDescriptor),
49
50
  standaloneCommandSchemaFromDescriptor(mcpCommandDescriptor),
51
+ ...commandSchemasFromGroupDescriptor(editorCommandGroup),
50
52
  standaloneCommandSchemaFromDescriptor({ ...schemaCommandMetadata, action: async () => undefined }),
51
53
  standaloneCommandSchemaFromDescriptor(infoCommandDescriptor),
52
54
  standaloneCommandSchemaFromDescriptor(updateCommandDescriptor),
@@ -26,6 +26,9 @@ export declare function detectPackageManager(input?: {
26
26
  env?: NodeJS.ProcessEnv;
27
27
  scriptPath?: string;
28
28
  }): PackageManager;
29
+ export declare function versionAtLeast(version: string, minimum: string): boolean;
30
+ /** Lets native dependencies compile. npm 11.16+ and pnpm 10.15+ skip those scripts unless named. */
31
+ export declare function appendNativeBuildPermissions(pm: PackageManager, args: string[], toolVersion: string | null): string[];
29
32
  type UpdateSpawnSpec = {
30
33
  command: string;
31
34
  args: string[];
@@ -52,6 +52,36 @@ const PM_COMMANDS = {
52
52
  yarn: { bin: 'yarn', args: ['global', 'add', `${PACKAGE_NAME}@latest`] },
53
53
  bun: { bin: 'bun', args: ['add', '--global', `${PACKAGE_NAME}@latest`] },
54
54
  };
55
+ const NATIVE_BUILD_PACKAGES = 'better-sqlite3,sharp';
56
+ function versionParts(version) {
57
+ const [major = 0, minor = 0, patch = 0] = version
58
+ .trim()
59
+ .replace(/^v/, '')
60
+ .split('.')
61
+ .map((part) => Number(part.replace(/\D.*$/, '')) || 0);
62
+ return [major, minor, patch];
63
+ }
64
+ export function versionAtLeast(version, minimum) {
65
+ const current = versionParts(version);
66
+ const floor = versionParts(minimum);
67
+ for (let index = 0; index < current.length; index += 1) {
68
+ if (current[index] !== floor[index])
69
+ return current[index] > floor[index];
70
+ }
71
+ return true;
72
+ }
73
+ /** Lets native dependencies compile. npm 11.16+ and pnpm 10.15+ skip those scripts unless named. */
74
+ export function appendNativeBuildPermissions(pm, args, toolVersion) {
75
+ if (!toolVersion)
76
+ return args;
77
+ if (pm === 'npm' && versionAtLeast(toolVersion, '11.16.0')) {
78
+ return [...args, `--allow-scripts=${NATIVE_BUILD_PACKAGES}`];
79
+ }
80
+ if (pm === 'pnpm' && versionAtLeast(toolVersion, '10.15.0')) {
81
+ return [...args, '--allow-build=better-sqlite3', '--allow-build=sharp'];
82
+ }
83
+ return args;
84
+ }
55
85
  export function resolvePackageManagerSpawn(pm, args, platform = process.platform) {
56
86
  const usesWindowsCommandShim = platform === 'win32' && pm !== 'bun';
57
87
  if (usesWindowsCommandShim) {
@@ -131,8 +161,21 @@ function runPackageManager(pm, packageArgs, options) {
131
161
  });
132
162
  });
133
163
  }
134
- function runUpdate(pm, options) {
135
- return runPackageManager(pm, PM_COMMANDS[pm].args, options);
164
+ function readToolVersion(pm) {
165
+ const { command, args, shell } = resolvePackageManagerSpawn(pm, ['--version']);
166
+ return new Promise((resolve) => {
167
+ let stdout = '';
168
+ const child = spawn(command, args, { shell, stdio: ['ignore', 'pipe', 'ignore'] });
169
+ child.stdout?.on('data', (chunk) => {
170
+ stdout = appendBoundedOutput(stdout, chunk);
171
+ });
172
+ child.on('close', (code) => resolve(code === 0 ? stdout.trim() : null));
173
+ child.on('error', () => resolve(null));
174
+ });
175
+ }
176
+ async function runUpdate(pm, options) {
177
+ const toolVersion = pm === 'npm' || pm === 'pnpm' ? await readToolVersion(pm) : null;
178
+ return runPackageManager(pm, appendNativeBuildPermissions(pm, PM_COMMANDS[pm].args, toolVersion), options);
136
179
  }
137
180
  function adapterErrorMessage(error) {
138
181
  return error instanceof Error ? error.message : String(error);
@@ -27,6 +27,7 @@ export declare class DaemonServer {
27
27
  private reconnecting;
28
28
  private syncUnconfirmedSince;
29
29
  private gateways;
30
+ private editor;
30
31
  constructor(options?: {
31
32
  runtime?: {
32
33
  db: AbstractPowerSyncDatabase;
@@ -37,7 +38,7 @@ export declare class DaemonServer {
37
38
  onStopRequested?: (reason: string, details?: Record<string, unknown>) => void | Promise<void>;
38
39
  });
39
40
  initialize(): Promise<void>;
40
- handleRequest(req: DaemonRequest, onProgress?: (text: string) => void): Promise<DaemonResponse>;
41
+ handleRequest(req: DaemonRequest, onProgress?: (text: string) => void, signal?: AbortSignal): Promise<DaemonResponse>;
41
42
  private isCacheStale;
42
43
  start(port: number): Promise<void>;
43
44
  stop(): Promise<void>;
@@ -22,6 +22,7 @@ import { requestContext } from '../utils/requestContext.js';
22
22
  import { runWithRequestId } from '../requests/store.js';
23
23
  import { getDaemonInfo } from './client.js';
24
24
  import { GatewayService } from '../gateway/service.js';
25
+ import { createDaemonEditorService, EDITOR_METHODS, handleEditorRequest } from '../editor/daemon.js';
25
26
  import { readConversation } from '../gateway/conversationContext.js';
26
27
  const MAX_DAEMON_REQUEST_BYTES = 1 * 1024 * 1024;
27
28
  const DAEMON_HEALTH_CHECK_INTERVAL_MS = 60_000;
@@ -98,6 +99,7 @@ export class DaemonServer {
98
99
  reconnecting = false;
99
100
  syncUnconfirmedSince = null;
100
101
  gateways = null;
102
+ editor = null;
101
103
  constructor(options = {}) {
102
104
  this.options = options;
103
105
  if (options.runtime) {
@@ -144,15 +146,27 @@ export class DaemonServer {
144
146
  writeDaemonLogLine('dinox-gateway', 'start failed', { error: String(error) });
145
147
  });
146
148
  }
149
+ if (config.auth.userId) {
150
+ this.editor = await createDaemonEditorService(db, {
151
+ userId: config.auth.userId,
152
+ log: (message, details) => writeDaemonLogLine('dinox-editor', message, details),
153
+ }).catch((error) => {
154
+ writeDaemonLogLine('dinox-editor', 'start failed', { error: String(error) });
155
+ return null;
156
+ });
157
+ }
147
158
  // PowerSync keeps the local cache in sync continuously while connected,
148
159
  // so no background polling loop is needed here.
149
160
  }
150
- async handleRequest(req, onProgress) {
161
+ async handleRequest(req, onProgress, signal) {
151
162
  try {
152
163
  if (!this.db) {
153
164
  throw new Error('Database not initialized');
154
165
  }
155
166
  const { method, params } = req;
167
+ if (EDITOR_METHODS.has(method)) {
168
+ return { id: req.id, ok: true, result: await handleEditorRequest(this.editor, method, params, signal) };
169
+ }
156
170
  switch (method) {
157
171
  case 'command.execute': {
158
172
  const input = params;
@@ -328,7 +342,10 @@ export class DaemonServer {
328
342
  res.end(JSON.stringify(daemonRes));
329
343
  return;
330
344
  }
331
- const daemonRes = await this.handleRequest(daemonReq);
345
+ // Long-polling editor requests end early when their client goes away.
346
+ const aborted = new AbortController();
347
+ res.once('close', () => aborted.abort());
348
+ const daemonRes = await this.handleRequest(daemonReq, undefined, aborted.signal);
332
349
  res.writeHead(200, { 'Content-Type': 'application/json' });
333
350
  res.end(JSON.stringify(daemonRes));
334
351
  }
@@ -487,6 +504,9 @@ export class DaemonServer {
487
504
  const gateways = this.gateways;
488
505
  this.gateways = null;
489
506
  await gateways?.stop().catch(() => undefined);
507
+ const editor = this.editor;
508
+ this.editor = null;
509
+ await editor?.close().catch(() => undefined);
490
510
  const db = this.db;
491
511
  const releaseOwner = this.releaseOwner;
492
512
  if (db) {
package/dist/dinox.js CHANGED
@@ -3,7 +3,8 @@ import { commandExecutionTarget, tryForwardToDaemon } from './daemon/forward.js'
3
3
  import { applyDefaultFormat } from './utils/defaultFormat.js';
4
4
  import { getPackageVersion } from './utils/version.js';
5
5
  import { requestIdFromArgv, runWithRequestId } from './requests/store.js';
6
- import { isDinoxError } from './utils/errors.js';
6
+ import { DinoxError, isDinoxError } from './utils/errors.js';
7
+ import { NODE_INSTALL_SUGGESTION, unsupportedNodeMessage } from './utils/nodeRuntime.js';
7
8
  import { exitProcessAfterFlushing } from './utils/processExit.js';
8
9
  import { localCommandExecution } from './utils/requestContext.js';
9
10
  /** `--progress` before `--`: the daemon streams events back while it runs the command. */
@@ -16,6 +17,16 @@ let fatalError;
16
17
  try {
17
18
  argv = applyDefaultFormat(argv);
18
19
  const versionOnly = argv.length === 1 && ['--version', '-V'].includes(argv[0]);
20
+ if (!versionOnly) {
21
+ const nodeMessage = unsupportedNodeMessage(process.versions.node);
22
+ if (nodeMessage) {
23
+ throw new DinoxError(nodeMessage, {
24
+ code: 'PRECONDITION_FAILED',
25
+ suggestion: NODE_INSTALL_SUGGESTION,
26
+ recoverable: true,
27
+ });
28
+ }
29
+ }
19
30
  const forwarded = versionOnly
20
31
  ? { stdout: `${getPackageVersion()}\n`, stderr: '', exitCode: 0 }
21
32
  : await tryForwardToDaemon(argv, wantsProgress(argv) ? { onProgress: (text) => process.stderr.write(text) } : {});
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dinox-editor
3
+ name: 'dinox-editor-dsh'