cli-link 0.0.1 → 0.0.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.
package/README.md CHANGED
@@ -18,11 +18,11 @@ AgentPilot 是一个移动端优先的 AI 编程 Agent 控制台。它把运行
18
18
 
19
19
  | 对话页面 | 代码页面 |
20
20
  | --- | --- |
21
- | <img src="public/对话页面.png" alt="对话页面" width="280"> | <img src="public/代码页面.png" alt="代码页面" width="280"> |
21
+ | <img src="https://unpkg.com/cli-link@latest/dist/client/%E5%AF%B9%E8%AF%9D%E9%A1%B5%E9%9D%A2.png" alt="对话页面" width="280"> | <img src="https://unpkg.com/cli-link@latest/dist/client/%E4%BB%A3%E7%A0%81%E9%A1%B5%E9%9D%A2.png" alt="代码页面" width="280"> |
22
22
 
23
23
  | 历史记录 | 设置页面 |
24
24
  | --- | --- |
25
- | <img src="public/历史记录.png" alt="历史记录" width="280"> | <img src="public/设置页面.png" alt="设置页面" width="280"> |
25
+ | <img src="https://unpkg.com/cli-link@latest/dist/client/%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95.png" alt="历史记录" width="280"> | <img src="https://unpkg.com/cli-link@latest/dist/client/%E8%AE%BE%E7%BD%AE%E9%A1%B5%E9%9D%A2.png" alt="设置页面" width="280"> |
26
26
 
27
27
  ## 代码页面
28
28
 
@@ -73,9 +73,8 @@ RUNTIME
73
73
  CLI codex (codex)
74
74
 
75
75
  MACOS LONG TASKS
76
- 手机长时间遥控任务前,建议先开启 Mac 防休眠,避免息屏后任务中断。
77
- System Settings > Battery > Options >
78
- 开启“使用电源适配器供电且显示器关闭时,防止自动进入睡眠”。
76
+ 已启用 caffeinate -i,当前服务运行期间会阻止 Mac 空闲休眠。
77
+ 合盖或低电量等系统策略仍可能中断任务;长时间运行建议接入电源。
79
78
  ```
80
79
 
81
80
  默认行为:
@@ -196,13 +195,15 @@ VITE_ENABLE_PWA_DEV=true AGENTPILOT_HTTPS_KEY=/path/to/key.pem AGENTPILOT_HTTPS_
196
195
 
197
196
  ### 防止息屏后休眠
198
197
 
199
- 如果要离开电脑、从手机继续遥控长任务,建议先打开 macOS 的防休眠选项:
198
+ 通过 `npx cli-link` 启动时,AgentPilot 会在 macOS 上自动运行 `caffeinate -i -w <pid>`,在当前服务进程存活期间阻止 Mac 空闲休眠。服务退出后,配套的 `caffeinate` 进程会自动结束。
199
+
200
+ 这个机制主要防止“空闲后自动睡眠”。合盖、低电量、系统强制睡眠或断电仍可能中断任务;如果要离开电脑、从手机继续遥控长任务,建议接入电源,并按需开启 macOS 的防休眠选项:
200
201
 
201
202
  1. 打开 `系统设置` -> `电池` -> `选项...`。
202
203
  2. 开启“使用电源适配器供电且显示器关闭时,防止自动进入睡眠”。
203
204
  3. 点击“完成”。
204
205
 
205
- 这样电脑接入电源且显示器关闭后,AgentPilot 后端和底层 CLI 仍可以继续运行。
206
+ 这样电脑接入电源且显示器关闭后,AgentPilot 后端和底层 CLI 更不容易被系统睡眠中断。
206
207
 
207
208
 
208
209
  ## 安全风险与使用边界
package/bin/agentpilot.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { accessSync, constants, existsSync, readFileSync, statSync } from 'node:fs';
3
+ import { spawn } from 'node:child_process';
3
4
  import { randomBytes } from 'node:crypto';
4
5
  import { dirname, delimiter, isAbsolute, join, resolve } from 'node:path';
5
6
  import { fileURLToPath, pathToFileURL } from 'node:url';
@@ -163,6 +164,32 @@ function detectCli() {
163
164
  return null;
164
165
  }
165
166
 
167
+ function resolveCaffeinateCommand() {
168
+ if (isExecutable('/usr/bin/caffeinate')) return '/usr/bin/caffeinate';
169
+ if (commandExists('caffeinate')) return 'caffeinate';
170
+ return null;
171
+ }
172
+
173
+ function preventMacIdleSleep() {
174
+ if (process.platform !== 'darwin') return;
175
+ const caffeinateCommand = resolveCaffeinateCommand();
176
+ if (!caffeinateCommand) {
177
+ console.warn('[AgentPilot] caffeinate was not found. macOS idle sleep prevention is disabled.');
178
+ return;
179
+ }
180
+
181
+ const child = spawn(caffeinateCommand, ['-i', '-w', String(process.pid)], {
182
+ stdio: 'ignore',
183
+ });
184
+ if (child.pid) process.env.AGENTPILOT_CAFFEINATE = '1';
185
+
186
+ child.on('error', (err) => {
187
+ console.warn(`[AgentPilot] Failed to start caffeinate: ${err?.message || err}`);
188
+ });
189
+
190
+ child.unref();
191
+ }
192
+
166
193
  async function main() {
167
194
  const options = parseArgs(process.argv.slice(2));
168
195
  const pkg = readPackageJson();
@@ -187,6 +214,8 @@ async function main() {
187
214
  throw new Error('AgentPilot server build is missing. Run `pnpm build` before using the NPX entry.');
188
215
  }
189
216
 
217
+ preventMacIdleSleep();
218
+
190
219
  let cliType = options.cli;
191
220
  let cliCommand = options.cliCommand;
192
221
  if (cliType && cliType !== 'codex' && cliType !== 'claude') {
@@ -15,6 +15,7 @@ const HOST = process.env.HOST || '0.0.0.0';
15
15
  const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
16
16
  const STATIC_DIR = resolveStaticDir();
17
17
  const IS_NPX_ENTRY = process.env.AGENTPILOT_NPX === '1';
18
+ const MAC_IDLE_SLEEP_PREVENTED = process.env.AGENTPILOT_CAFFEINATE === '1';
18
19
  const AUTH_COOKIE_NAME = 'agentpilot_token';
19
20
  const AUTH_TOKEN = (process.env.AGENTPILOT_AUTH_TOKEN || '').trim();
20
21
  const AUTH_ENABLED = AUTH_TOKEN.length > 0;
@@ -2026,9 +2027,15 @@ function printMacSleepHint() {
2026
2027
  if (process.platform !== 'darwin')
2027
2028
  return;
2028
2029
  printSection('macOS long tasks');
2029
- console.log(` ${colorize('手机长时间遥控任务前,建议先开启 Mac 防休眠,避免息屏后任务中断。', terminalStyle.yellow)}`);
2030
- console.log(' System Settings > Battery > Options >');
2031
- console.log(' 开启“使用电源适配器供电且显示器关闭时,防止自动进入睡眠”。');
2030
+ if (MAC_IDLE_SLEEP_PREVENTED) {
2031
+ console.log(` ${colorize('已启用 caffeinate -i,当前服务运行期间会阻止 Mac 空闲休眠。', terminalStyle.green)}`);
2032
+ console.log(' 合盖或低电量等系统策略仍可能中断任务;长时间运行建议接入电源。');
2033
+ }
2034
+ else {
2035
+ console.log(` ${colorize('手机长时间遥控任务前,建议先开启 Mac 防休眠,避免息屏后任务中断。', terminalStyle.yellow)}`);
2036
+ console.log(' System Settings > Battery > Options >');
2037
+ console.log(' 开启“使用电源适配器供电且显示器关闭时,防止自动进入睡眠”。');
2038
+ }
2032
2039
  console.log('');
2033
2040
  }
2034
2041
  function printStartupInfo() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli-link",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "cli-link": "bin/agentpilot.js"