@dinoxx/dinox-cli 2.18.2 → 2.18.3

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.
@@ -4,7 +4,7 @@ import { registerCommandGroup } from '../descriptor/register.js';
4
4
  import { FORMAT_OPTIONS } from '../schema/globalOptions.js';
5
5
  const HOST_ARGUMENT = { syntax: '<host>', description: 'AI app to set the editor up in: dsh (DeepSeek Harness Desktop)' };
6
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' };
7
+ const DSH_OPTION = { flags: '--dsh <path>', description: 'Path to the dsh CLI (default: the launcher that ships with DeepSeek Harness Desktop, then PATH)', type: 'string' };
8
8
  const DRY_RUN_OPTION = { flags: '--dry-run', description: 'Show the planned changes without making them', type: 'boolean' };
9
9
  function hostOf(context) {
10
10
  const host = String(context.args.host ?? '').toLowerCase();
@@ -465,7 +465,7 @@ function printDaemonInstallResult(result) {
465
465
  printHumanReadableLine(`Installed ${result.service} service ${result.label}`);
466
466
  printHumanReadableLine(`Definition: ${result.definitionPath}`);
467
467
  printHumanReadableLine(`Log: ${result.logPath}`);
468
- printHumanReadableLine(`The daemon now starts at ${result.service === 'schtasks' ? 'logon (Task Scheduler)' : 'login'} and restarts after a crash.`);
468
+ printHumanReadableLine(`The daemon now starts at ${result.service === 'schtasks' ? 'logon' : 'login'} and restarts after a crash.`);
469
469
  if (result.service === 'systemd') {
470
470
  printHumanReadableLine('To keep it running after you log out, run `loginctl enable-linger`.');
471
471
  }
@@ -4,6 +4,7 @@ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from '
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { getDataDir } from '../config/paths.js';
7
+ import { decodeCommandOutput } from '../utils/consoleEncoding.js';
7
8
  import { DinoxError } from '../utils/errors.js';
8
9
  /** Set in the service definition so the daemon can report who supervises it. */
9
10
  export const DAEMON_SERVICE_ENV = 'DINOX_DAEMON_SUPERVISOR';
@@ -14,9 +15,10 @@ const COMMAND_TIMEOUT_MS = 15_000;
14
15
  const LAUNCHD_BOOTSTRAP_ATTEMPTS = 5;
15
16
  const LAUNCHD_BOOTSTRAP_RETRY_MS = 300;
16
17
  export const runServiceCommand = (command, args) => new Promise((resolve) => {
17
- execFile(command, args, { timeout: COMMAND_TIMEOUT_MS, encoding: 'utf8' }, (error, stdout, stderr) => {
18
+ execFile(command, args, { timeout: COMMAND_TIMEOUT_MS, encoding: 'buffer', windowsHide: true }, (error, stdout, stderr) => {
18
19
  const code = error ? (typeof error.code === 'number' ? error.code : 1) : 0;
19
- resolve({ code, stdout: stdout ?? '', stderr: stderr ?? (error ? String(error.message) : '') });
20
+ const err = stderr && stderr.length > 0 ? decodeCommandOutput(stderr) : '';
21
+ resolve({ code, stdout: stdout ? decodeCommandOutput(stdout) : '', stderr: err || (error ? String(error.message) : '') });
20
22
  });
21
23
  });
22
24
  /**
@@ -440,6 +442,13 @@ function readUtf16(filePath) {
440
442
  const content = readDefinition(filePath, 'utf16le');
441
443
  return content === null ? null : content.replace(/^\uFEFF/, '');
442
444
  }
445
+ const WINDOWS_RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
446
+ /**
447
+ * Windows: a Task Scheduler logon task, or, where creating one is denied
448
+ * (a logon trigger needs an elevated shell on many machines), the per-user
449
+ * `Run` registry value, which needs no rights. Either starts the same
450
+ * wscript launcher at logon; `kind` stays `schtasks` for both.
451
+ */
443
452
  class WindowsTaskService {
444
453
  label;
445
454
  run;
@@ -471,9 +480,16 @@ class WindowsTaskService {
471
480
  const launcher = readUtf16(this.definitionPath);
472
481
  return launcher === null ? null : parseWindowsLauncherCommand(launcher);
473
482
  }
474
- async isRegistered() {
483
+ launcherArgs() {
484
+ return ['//B', '//Nologo', this.definitionPath];
485
+ }
486
+ async isTaskRegistered() {
475
487
  return (await this.run('schtasks', ['/Query', '/TN', this.taskName])).code === 0;
476
488
  }
489
+ async isRunKeyRegistered() {
490
+ return (await this.run('reg', ['query', WINDOWS_RUN_KEY, '/v', this.label])).code === 0;
491
+ }
492
+ /** Registers the logon entry; returns which one was used. */
477
493
  async register() {
478
494
  if (!existsSync(this.wscriptPath)) {
479
495
  throw new DinoxError(`Windows Script Host (${this.wscriptPath}) is not available, so the daemon cannot start hidden at logon.`, {
@@ -483,10 +499,9 @@ class WindowsTaskService {
483
499
  }
484
500
  const xmlPath = path.join(this.launcherDir, `${this.label}.task.xml`);
485
501
  writeUtf16(xmlPath, renderWindowsTaskXml(this.userId, this.wscriptPath, this.definitionPath));
502
+ let created;
486
503
  try {
487
- const result = await this.run('schtasks', ['/Create', '/TN', this.taskName, '/XML', xmlPath, '/F']);
488
- if (result.code !== 0)
489
- throw failed(this.kind, 'create', result);
504
+ created = await this.run('schtasks', ['/Create', '/TN', this.taskName, '/XML', xmlPath, '/F']);
490
505
  }
491
506
  finally {
492
507
  try {
@@ -496,23 +511,38 @@ class WindowsTaskService {
496
511
  // Already gone.
497
512
  }
498
513
  }
499
- }
500
- async runTask() {
501
- const result = await this.run('schtasks', ['/Run', '/TN', this.taskName]);
514
+ if (created.code === 0) {
515
+ // A Run value from an earlier unelevated install would start a second launcher.
516
+ await this.run('reg', ['delete', WINDOWS_RUN_KEY, '/v', this.label, '/f']);
517
+ return 'task';
518
+ }
519
+ const command = [this.wscriptPath, ...this.launcherArgs()].map(quoteWindowsArg).join(' ');
520
+ const added = await this.run('reg', ['add', WINDOWS_RUN_KEY, '/v', this.label, '/t', 'REG_SZ', '/d', command, '/f']);
521
+ if (added.code !== 0)
522
+ throw failed(this.kind, 'create', created);
523
+ return 'run-key';
524
+ }
525
+ async launch(mode) {
526
+ if (mode === 'task') {
527
+ const result = await this.run('schtasks', ['/Run', '/TN', this.taskName]);
528
+ if (result.code !== 0)
529
+ throw failed(this.kind, 'run', result);
530
+ return;
531
+ }
532
+ // The launcher starts the supervisor without waiting and exits.
533
+ const result = await this.run(this.wscriptPath, this.launcherArgs());
502
534
  if (result.code !== 0)
503
535
  throw failed(this.kind, 'run', result);
504
536
  }
505
537
  async install(spec) {
506
538
  this.clearStopMarker();
507
539
  writeUtf16(this.definitionPath, this.render(spec));
508
- await this.register();
509
- await this.runTask();
540
+ await this.launch(await this.register());
510
541
  }
511
542
  async start() {
512
543
  this.clearStopMarker();
513
- if (!(await this.isRegistered()))
514
- await this.register();
515
- await this.runTask();
544
+ const mode = (await this.isTaskRegistered()) ? 'task' : (await this.isRunKeyRegistered()) ? 'run-key' : await this.register();
545
+ await this.launch(mode);
516
546
  }
517
547
  async stop() {
518
548
  mkdirSync(this.launcherDir, { recursive: true });
@@ -528,11 +558,16 @@ class WindowsTaskService {
528
558
  }
529
559
  async uninstall() {
530
560
  const installed = this.isInstalled();
531
- if (await this.isRegistered()) {
561
+ if (await this.isTaskRegistered()) {
532
562
  const result = await this.run('schtasks', ['/Delete', '/TN', this.taskName, '/F']);
533
563
  if (result.code !== 0)
534
564
  throw failed(this.kind, 'delete', result);
535
565
  }
566
+ if (await this.isRunKeyRegistered()) {
567
+ const result = await this.run('reg', ['delete', WINDOWS_RUN_KEY, '/v', this.label, '/f']);
568
+ if (result.code !== 0)
569
+ throw failed(this.kind, 'delete', result);
570
+ }
536
571
  if (installed)
537
572
  unlinkSync(this.definitionPath);
538
573
  return installed;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinox-editor-dsh",
3
- "version": "2.18.2",
3
+ "version": "2.18.3",
4
4
  "private": true,
5
5
  "description": "Dinox note editor for DeepSeek Harness Desktop (built by @dinoxx/dinox-cli)",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "node": "/opt/hostedtoolcache/node/22.13.0/x64/bin/node",
3
3
  "cli": "/home/runner/work/dinox-cli/dinox-cli/dist/dinox.js",
4
- "version": "2.18.2"
4
+ "version": "2.18.3"
5
5
  }
@@ -18,9 +18,18 @@ export type InstallOptions = {
18
18
  home?: string;
19
19
  /** Runs the dsh CLI (tests). */
20
20
  exec?: (file: string, args: string[]) => Promise<void>;
21
+ platform?: NodeJS.Platform;
22
+ /** Windows registry reader (tests); returns `reg query` output or null. */
23
+ queryRegistry?: (args: string[]) => string | null;
21
24
  };
25
+ /**
26
+ * The `@deepseek-ai/dsh` npm CLI refuses the `desktop` profile ("managed
27
+ * exclusively by the Electron application"); only Desktop's own launcher may
28
+ * change it. npm links that CLI (Unix) or writes a shim naming it (Windows).
29
+ */
30
+ export declare function isNpmDshCli(file: string): boolean;
22
31
  /** The dsh CLI that ships with Desktop matches its runtime; fall back to PATH. */
23
- export declare function findDshCli(options?: Pick<InstallOptions, 'dsh' | 'env'>): string | null;
32
+ export declare function findDshCli(options?: Pick<InstallOptions, 'dsh' | 'env' | 'platform' | 'queryRegistry'>): string | null;
24
33
  /**
25
34
  * On Windows the dsh CLI on PATH is an npm `dsh.cmd` shim, which `execFile`
26
35
  * cannot start directly (EINVAL since Node 20.12.2); route it through cmd.exe.
@@ -1,10 +1,11 @@
1
- import { execFile } from 'node:child_process';
1
+ import { execFile, execFileSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, realpathSync } from 'node:fs';
3
3
  import { rename, writeFile } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { promisify } from 'node:util';
7
7
  import { agentLaunch } from '../gateway/spawnAgent.js';
8
+ import { decodeCommandOutput } from '../utils/consoleEncoding.js';
8
9
  import { DinoxError } from '../utils/errors.js';
9
10
  import { getPackageVersion } from '../utils/version.js';
10
11
  import { editorPackageRoot } from './paths.js';
@@ -35,22 +36,91 @@ function checkProfileName(profile) {
35
36
  }
36
37
  return profile;
37
38
  }
39
+ /** Where Desktop keeps its own launcher, relative to the install directory. */
40
+ const WINDOWS_LAUNCHER = ['resources', 'runtime', 'cli', 'bin', 'dsh.cmd'];
41
+ function queryRegistry(args) {
42
+ try {
43
+ return decodeCommandOutput(execFileSync('reg', ['query', ...args], { timeout: 10_000, windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] }));
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ /** `name REG_SZ value` lines of `reg query` output. */
50
+ function registryValues(output, name) {
51
+ if (!output)
52
+ return [];
53
+ const pattern = new RegExp(`^\\s*${name}\\s+REG_(?:EXPAND_)?SZ\\s+(.+?)\\s*$`, 'gim');
54
+ return [...output.matchAll(pattern)].map(match => match[1].replace(/^"|"$/g, ''));
55
+ }
56
+ /**
57
+ * Windows: the launcher DeepSeek Harness Desktop installs, found through the
58
+ * PATH entry it registers, its uninstall entry, or the default install folders.
59
+ */
60
+ function* windowsDesktopLaunchers(env, query) {
61
+ const win = path.win32;
62
+ for (const dir of registryValues(query(['HKCU\\Software\\DeepSeekHarness\\Command', '/v', 'Directory']), 'Directory')) {
63
+ yield win.join(dir, 'dsh.cmd');
64
+ }
65
+ for (const base of [env.LOCALAPPDATA && win.join(env.LOCALAPPDATA, 'Programs'), env.ProgramFiles, env['ProgramFiles(x86)']]) {
66
+ if (base)
67
+ yield win.join(base, 'DeepSeek Harness', ...WINDOWS_LAUNCHER);
68
+ }
69
+ // Slowest: every installed program's uninstall entry.
70
+ for (const key of ['HKCU\\Software', 'HKLM\\Software', 'HKLM\\Software\\WOW6432Node']) {
71
+ for (const dir of registryValues(query([`${key}\\Microsoft\\Windows\\CurrentVersion\\Uninstall`, '/s', '/v', 'InstallLocation']), 'InstallLocation')) {
72
+ yield win.join(dir, ...WINDOWS_LAUNCHER);
73
+ }
74
+ }
75
+ }
76
+ /**
77
+ * The `@deepseek-ai/dsh` npm CLI refuses the `desktop` profile ("managed
78
+ * exclusively by the Electron application"); only Desktop's own launcher may
79
+ * change it. npm links that CLI (Unix) or writes a shim naming it (Windows).
80
+ */
81
+ export function isNpmDshCli(file) {
82
+ let real = file;
83
+ try {
84
+ real = realpathSync(file);
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ const marker = /node_modules[\\/]@deepseek-ai[\\/]dsh[\\/]/i;
90
+ if (marker.test(real))
91
+ return true;
92
+ if (!/\.(?:cmd|ps1)$/i.test(real) && path.basename(real) !== 'dsh')
93
+ return false;
94
+ try {
95
+ const content = readFileSync(real, 'utf8');
96
+ return content.length < 16_384 && marker.test(content) && !/dsh-desktop-host/i.test(content);
97
+ }
98
+ catch {
99
+ return false;
100
+ }
101
+ }
38
102
  /** The dsh CLI that ships with Desktop matches its runtime; fall back to PATH. */
39
103
  export function findDshCli(options = {}) {
40
104
  const env = options.env ?? process.env;
105
+ const platform = options.platform ?? process.platform;
41
106
  const explicit = options.dsh || env.DINOX_DSH_BIN;
42
107
  if (explicit)
43
108
  return existsSync(explicit) ? explicit : null;
44
- if (existsSync(DSH_APP_CLI))
45
- return DSH_APP_CLI;
46
- for (const dir of (env.PATH ?? '').split(path.delimiter)) {
109
+ const fromPath = [];
110
+ for (const dir of (env.PATH ?? env.Path ?? '').split(platform === 'win32' ? ';' : path.delimiter)) {
47
111
  if (!dir)
48
112
  continue;
49
- const candidate = path.join(dir, process.platform === 'win32' ? 'dsh.cmd' : 'dsh');
113
+ const candidate = platform === 'win32' ? path.win32.join(dir, 'dsh.cmd') : path.join(dir, 'dsh');
50
114
  if (existsSync(candidate))
51
- return candidate;
115
+ fromPath.push(candidate);
52
116
  }
53
- return null;
117
+ const desktop = platform === 'win32' ? windowsDesktopLaunchers(env, options.queryRegistry ?? queryRegistry) : [DSH_APP_CLI];
118
+ for (const file of desktop)
119
+ if (existsSync(file))
120
+ return file;
121
+ return fromPath.find(file => !isNpmDshCli(file))
122
+ ?? fromPath[0]
123
+ ?? null;
54
124
  }
55
125
  function readProfile(dir) {
56
126
  const file = path.join(dir, 'package.json');
@@ -100,12 +170,21 @@ function defaultExec(file, args) {
100
170
  throw new DinoxError(`dsh plugin failed: ${detail || error.message}`, { code: 'COMMAND_FAILED' });
101
171
  });
102
172
  }
103
- function requireDsh(options) {
173
+ function requireDsh(options, profile) {
104
174
  const cli = findDshCli(options);
175
+ const where = (options.platform ?? process.platform) === 'win32'
176
+ ? '<DeepSeek Harness install folder>\\resources\\runtime\\cli\\bin\\dsh.cmd'
177
+ : DSH_APP_CLI;
105
178
  if (!cli) {
106
179
  throw new DinoxError('DeepSeek Harness (dsh) was not found', {
107
180
  code: 'NOT_FOUND',
108
- suggestion: 'Install DeepSeek Harness Desktop, or pass --dsh <path-to-dsh-cli>',
181
+ suggestion: `Install DeepSeek Harness Desktop, or pass --dsh ${where}`,
182
+ });
183
+ }
184
+ if (profile.toLowerCase() === 'desktop' && isNpmDshCli(cli)) {
185
+ throw new DinoxError(`${cli} is the npm dsh CLI, which cannot change the desktop profile; only the dsh launcher that ships with DeepSeek Harness Desktop can`, {
186
+ code: 'PRECONDITION_FAILED',
187
+ suggestion: `Pass the Desktop launcher: dino editor install dsh --dsh "${where}"`,
109
188
  });
110
189
  }
111
190
  return cli;
@@ -117,7 +196,7 @@ export async function installDsh(options = {}) {
117
196
  if (!existsSync(manifest)) {
118
197
  throw new DinoxError(`The dsh plugin is not built (${dir})`, { code: 'PRECONDITION_FAILED', suggestion: 'Run pnpm build in the dinox-cli checkout' });
119
198
  }
120
- const cli = requireDsh(options);
199
+ const cli = requireDsh(options, profile);
121
200
  const profilePath = profileDir(profile, options);
122
201
  const before = readProfile(profilePath);
123
202
  const linked = linkTarget(before?.dependencies?.[DSH_PLUGIN_PACKAGE]);
@@ -182,7 +261,7 @@ export async function uninstallDsh(options = {}) {
182
261
  await writeProfile(profilePath, before);
183
262
  }
184
263
  if (installed) {
185
- cli = requireDsh(options);
264
+ cli = requireDsh(options, profile);
186
265
  await (options.exec ?? defaultExec)(cli, ['plugin', '--profile', profile, 'remove', DSH_PLUGIN_PACKAGE]);
187
266
  }
188
267
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Windows tools (schtasks, reg) print in the console's legacy code page (GBK on Chinese
3
+ * Windows), so UTF-8 decoding turned their errors into mojibake.
4
+ */
5
+ export declare function decodeCommandOutput(bytes: Buffer, platform?: NodeJS.Platform, locale?: string): string;
@@ -0,0 +1,27 @@
1
+ /** Legacy code pages Windows consoles print in, by UI language. */
2
+ const WINDOWS_CONSOLE_ENCODINGS = [
3
+ [/^zh-(?:TW|HK|MO|Hant)/i, 'big5'],
4
+ [/^zh/i, 'gbk'],
5
+ [/^ja/i, 'shift_jis'],
6
+ [/^ko/i, 'euc-kr'],
7
+ ];
8
+ /**
9
+ * Windows tools (schtasks, reg) print in the console's legacy code page (GBK on Chinese
10
+ * Windows), so UTF-8 decoding turned their errors into mojibake.
11
+ */
12
+ export function decodeCommandOutput(bytes, platform = process.platform, locale = Intl.DateTimeFormat().resolvedOptions().locale) {
13
+ try {
14
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
15
+ }
16
+ catch {
17
+ if (platform !== 'win32')
18
+ return bytes.toString('utf8');
19
+ const encoding = WINDOWS_CONSOLE_ENCODINGS.find(([pattern]) => pattern.test(locale))?.[1] ?? 'windows-1252';
20
+ try {
21
+ return new TextDecoder(encoding).decode(bytes);
22
+ }
23
+ catch {
24
+ return bytes.toString('latin1');
25
+ }
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dinoxx/dinox-cli",
3
- "version": "2.18.2",
3
+ "version": "2.18.3",
4
4
  "description": "Dinox CLI",
5
5
  "main": "dist/dinox.js",
6
6
  "scripts": {