@walkhi/code-relax 0.1.0-beta.12 → 0.1.0-beta.13

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.
@@ -15,8 +15,9 @@ import fs from 'node:fs';
15
15
  import { spawn } from 'node:child_process';
16
16
  import { setTimeout as delay } from 'node:timers/promises';
17
17
  import { requestRecovery, recoveryStatus, recoveryWarning } from '../src/shared-recovery.mjs';
18
- import { configureManagedEnvironment, clearManagedEnvironment } from '../src/platform/windows/user-environment.mjs';
18
+ import { configureManagedEnvironment, clearManagedEnvironment, readManagedEnvironment } from '../src/platform/windows/user-environment.mjs';
19
19
  import { resolveCodexRuntime } from '../src/platform/windows/codex-runtime.mjs';
20
+ import { managedAppServerUrl } from '../src/managed-app-server.mjs';
20
21
  import { controlRequest } from '../src/service-control.mjs';
21
22
  import { processAlive } from '../src/background-process.mjs';
22
23
 
@@ -74,8 +75,33 @@ async function main() {
74
75
  if (command.startsWith('autostart-')) {
75
76
  const installation = readRecord(path.join(serviceRoot, 'installation.json'));
76
77
  if (!installation?.nodeExecutable) throw new Error('请先执行 setup。');
77
- const result = await residentStartup({ serviceRoot, nodeExecutable: installation.nodeExecutable }, command.slice('autostart-'.length));
78
- console.log(json ? JSON.stringify(result) : `登录启动:${result.enabled ? '已启用' : '已关闭'}`); return;
78
+ const action = command.slice('autostart-'.length);
79
+ let environment;
80
+ if (action === 'disable') {
81
+ environment = await clearManagedEnvironment(stateRoot);
82
+ const current = await readManagedEnvironment();
83
+ if (current.userValue === managedAppServerUrl || (!current.userValue && current.machineValue === managedAppServerUrl)) {
84
+ throw new Error('Desktop 仍会连接 Code Relax 内核;请先处理非本包管理的 CODEX_APP_SERVER_WS_URL,未关闭登录启动。');
85
+ }
86
+ }
87
+ if (action === 'enable') {
88
+ const running = await service.status();
89
+ if (!running.running) await service.start();
90
+ const deadline = Date.now() + 35000;
91
+ while (true) {
92
+ const ready = await service.status();
93
+ if (ready.running && ready.managedAppServer?.ready) break;
94
+ if (Date.now() >= deadline) throw new Error('Codex 内核未就绪,未启用 Desktop 自动接入。');
95
+ await delay(250);
96
+ }
97
+ }
98
+ const result = await residentStartup({ serviceRoot, nodeExecutable: installation.nodeExecutable }, action);
99
+ if (action === 'enable' && (await desktopHost.inspect()).desktop) environment = await configureManagedEnvironment(stateRoot);
100
+ const output = { ...result, ...(environment ? { environment } : {}) };
101
+ const environmentText = environment?.preserved ? ';用户自定义的 Desktop 地址已保留,请自行核对' :
102
+ environment?.removed ? ';已清除 Code Relax 设置的 Desktop 地址' :
103
+ environment?.configured ? ';已配置 Desktop 接入地址' : '';
104
+ console.log(json ? JSON.stringify(output) : `登录启动:${result.enabled ? '已启用' : '已关闭'}${environmentText}`); return;
79
105
  }
80
106
  if (command === 'shared-recover' || command === 'shared-recovery-status') {
81
107
  if (command === 'shared-recover' && !flags.includes('--confirm')) throw new Error(recoveryWarning + ' 使用 --confirm 确认。');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@walkhi/code-relax",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.13",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "scripts": {