agent-things 0.0.0-stage → 1.2.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.
- package/LICENSE +21 -0
- package/NOTICE +5 -0
- package/README.md +221 -2
- package/README.zh-CN.md +222 -0
- package/bin/agent-things.cjs +8 -0
- package/bin/antigravity-session-status.cjs +96 -0
- package/bin/claude-session-status.cjs +55 -0
- package/bin/codex-session-status.cjs +287 -0
- package/mods/agent-things-ui/.claude-plugin/plugin.json +12 -0
- package/mods/agent-things-ui/SKILL.md +10 -0
- package/mods/agent-things-ui/hooks/controls.js +112 -0
- package/mods/agent-things-ui/hooks/foundation.js +431 -0
- package/mods/agent-things-ui/hooks/hooks.json +1 -0
- package/mods/agent-things-ui/hooks/presentation.js +223 -0
- package/mods/agent-things-ui/hooks/progress.js +1 -0
- package/mods/agent-things-ui/hooks/register.js +382 -0
- package/native/bin/bridge +0 -0
- package/native/bin/bridge.json +20 -0
- package/native/session-status-bridge.swift +280 -0
- package/outputs/antigravity-session-status.js +2476 -0
- package/outputs/codex-session-status.js +1761 -0
- package/package.json +75 -4
- package/scripts/build-antigravity-bundle.cjs +35 -0
- package/scripts/build-codex-bundle.cjs +31 -0
- package/scripts/build-native-bridge.cjs +55 -0
- package/scripts/build-shared-ui.cjs +16 -0
- package/scripts/setup-antigravity-service.cjs +71 -0
- package/scripts/setup-claude-service.cjs +21 -0
- package/skills/agent-things/SKILL.en.md +95 -0
- package/skills/agent-things/SKILL.md +99 -0
- package/skills/codex/things/SKILL.en.md +10 -0
- package/skills/codex/things/SKILL.md +10 -0
- package/skills/things/SKILL.en.md +10 -0
- package/skills/things/SKILL.md +10 -0
- package/skills/things/checklist.en.md +91 -0
- package/skills/things/checklist.md +95 -0
- package/src/analysis-app-server.cjs +74 -0
- package/src/analysis-assets/output.en.schema.json +93 -0
- package/src/analysis-assets/output.schema.json +93 -0
- package/src/analysis-assets/prompt.en.txt +17 -0
- package/src/analysis-assets/prompt.zh-CN.txt +18 -0
- package/src/analysis-budget.cjs +105 -0
- package/src/analysis-git.cjs +38 -0
- package/src/analysis-history.cjs +150 -0
- package/src/analysis-ledger.cjs +82 -0
- package/src/analysis-log.cjs +62 -0
- package/src/analysis-runner.cjs +203 -0
- package/src/analysis-service.cjs +197 -0
- package/src/analysis-source.cjs +72 -0
- package/src/antigravity-card.cjs +2063 -0
- package/src/antigravity-hook.cjs +138 -0
- package/src/antigravity-mcp-config.cjs +36 -0
- package/src/app-server.cjs +96 -0
- package/src/cdp.cjs +115 -0
- package/src/claude-inline-install.cjs +38 -0
- package/src/claude-mcp-config.cjs +29 -0
- package/src/cli/arguments.cjs +30 -0
- package/src/cli/environment-probe.cjs +130 -0
- package/src/cli/integration-state.cjs +15 -0
- package/src/cli/interactive-cli.cjs +236 -0
- package/src/cli/prompt-tui.cjs +420 -0
- package/src/cli/setup-orchestrator.cjs +449 -0
- package/src/codex-mcp-config.cjs +67 -0
- package/src/harnesses/antigravity/analysis-profile.cjs +41 -0
- package/src/harnesses/antigravity/antigravity-git.cjs +89 -0
- package/src/harnesses/antigravity/antigravity-harness.js +1477 -0
- package/src/harnesses/antigravity/antigravity-injector.cjs +104 -0
- package/src/harnesses/antigravity/antigravity-migration.cjs +235 -0
- package/src/harnesses/antigravity/antigravity-service.cjs +357 -0
- package/src/harnesses/antigravity/antigravity-title.cjs +155 -0
- package/src/harnesses/antigravity/gemini-runner.cjs +304 -0
- package/src/harnesses/antigravity/transcript-cleaner.cjs +129 -0
- package/src/harnesses/antigravity/transcript-source.cjs +100 -0
- package/src/harnesses/claude/claude-harness.js +93 -0
- package/src/harnesses/claude/claude-host-helper.cjs +176 -0
- package/src/harnesses/claude/claude-injector.cjs +95 -0
- package/src/harnesses/claude/claude-local-source.cjs +106 -0
- package/src/harnesses/claude/claude-navigation.cjs +99 -0
- package/src/harnesses/claude/claude-runner.cjs +74 -0
- package/src/harnesses/claude/claude-service.cjs +313 -0
- package/src/harnesses/claude/claude-source.cjs +70 -0
- package/src/harnesses/codex/codex-analysis.cjs +10 -0
- package/src/harnesses/codex/codex-card-bridge.js +123 -0
- package/src/harnesses/codex/codex-card-events.cjs +76 -0
- package/src/harnesses/codex/codex-card.cjs +169 -0
- package/src/harnesses/codex/codex-git.cjs +24 -0
- package/src/harnesses/codex/codex-harness.js +229 -0
- package/src/harnesses/codex/codex-local-card.js +97 -0
- package/src/harnesses/codex/codex-progress-context.cjs +84 -0
- package/src/harnesses/codex/codex-service.cjs +502 -0
- package/src/i18n.cjs +174 -0
- package/src/launchd.cjs +105 -0
- package/src/lifecycle-lock.cjs +13 -0
- package/src/local-progress-http.cjs +267 -0
- package/src/manual-status-agent.cjs +12 -0
- package/src/manual-status-startup.cjs +66 -0
- package/src/manual-status-store.cjs +466 -0
- package/src/mcp-stdio.cjs +67 -0
- package/src/model-router.cjs +63 -0
- package/src/native-bridge.cjs +17 -0
- package/src/npm-updates.cjs +228 -0
- package/src/plugins/things/assets/logo.svg +13 -0
- package/src/plugins/things/plugin.json +6 -0
- package/src/plugins/things/sidecars/things_board/app.js +447 -0
- package/src/plugins/things/sidecars/things_board/index.html +2141 -0
- package/src/plugins/things/sidecars/things_board/main.mjs +652 -0
- package/src/plugins/things/sidecars/things_board/package.json +6 -0
- package/src/plugins/things/sidecars/things_board/sidecar.json +21 -0
- package/src/plugins/things/sidecars/things_board/styles.css +560 -0
- package/src/plugins/things/sidecars/things_board/ui-i18n.mjs +434 -0
- package/src/progress-error.cjs +54 -0
- package/src/progress-tools.cjs +145 -0
- package/src/project-path.cjs +15 -0
- package/src/renderer-resource.cjs +17 -0
- package/src/request-budget.cjs +24 -0
- package/src/resolve.cjs +51 -0
- package/src/runtime-install.cjs +635 -0
- package/src/session-status-filter.cjs +136 -0
- package/src/session-status.js +992 -0
- package/src/session-view.cjs +34 -0
- package/src/startup/controller.cjs +354 -0
- package/src/startup/watch.cjs +126 -0
- package/src/state-file-lock.cjs +31 -0
- package/src/task-provenance.cjs +42 -0
- package/src/ui-foundation.cjs +435 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const { probeEnvironment, formatProbeText } = require('./environment-probe.cjs');
|
|
6
|
+
const { selectLanguageWithProbe, selectApps, askConfirm, selectMenu } = require('./prompt-tui.cjs');
|
|
7
|
+
const { readConfig, executeSetup, uninstallAll, DATA_DIR } = require('./setup-orchestrator.cjs');
|
|
8
|
+
const launchd = require('../launchd.cjs');
|
|
9
|
+
const { CdpSession, listTargets } = require('../cdp.cjs');
|
|
10
|
+
const { attachmentStatus } = require('../manual-status-agent.cjs');
|
|
11
|
+
const { requestProgressHttp } = require('../local-progress-http.cjs');
|
|
12
|
+
const { getUpdateInfo, startUpdate, verifyServices } = require('../npm-updates.cjs');
|
|
13
|
+
const { startupStatus } = require('../manual-status-startup.cjs');
|
|
14
|
+
const { portInUse } = require('../startup/watch.cjs');
|
|
15
|
+
const { COOLDOWN_MS } = require('../startup/controller.cjs');
|
|
16
|
+
const { detectSystemLang } = require('../i18n.cjs');
|
|
17
|
+
async function showUpdates(lang) {
|
|
18
|
+
const zh = lang === 'zh';
|
|
19
|
+
console.log(zh ? '\n正在检查 npm 最新版本…' : '\nChecking npm for updates…');
|
|
20
|
+
try {
|
|
21
|
+
const info = await getUpdateInfo({ force: true });
|
|
22
|
+
console.log(zh ? `当前安装版本:${info.currentVersion || '未安装'}` : `Installed version: ${info.currentVersion || 'not installed'}`);
|
|
23
|
+
if (['queued', 'checking', 'downloading', 'waiting', 'installing'].includes(info.update?.stage)) {
|
|
24
|
+
const stages = zh
|
|
25
|
+
? { queued: '等待启动', checking: '检查版本', downloading: '下载中', waiting: '等待分析结束', installing: '升级中' }
|
|
26
|
+
: { queued: 'queued', checking: 'checking', downloading: 'downloading', waiting: 'waiting for analysis', installing: 'installing' };
|
|
27
|
+
console.log(zh ? `升级正在后台进行:${stages[info.update.stage]}。终端可以关闭。` : `Update running in background: ${stages[info.update.stage] || info.update.stage}. You may close the terminal.`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (info.update?.stage === 'failed') console.log(zh ? `上次升级失败:${info.update.error}` : `Previous update failed: ${info.update.error}`);
|
|
31
|
+
if (info.checkError) { console.log(zh ? `检查失败:${info.checkError}。可稍后重试。` : `Check failed: ${info.checkError}. Try again later.`); return; }
|
|
32
|
+
if (!info.available) { console.log(zh ? '已是最新版本。' : 'Already up to date.'); return; }
|
|
33
|
+
console.log(zh ? `发现新版本 v${info.latestVersion}` : `New version available: v${info.latestVersion}`);
|
|
34
|
+
if (await askConfirm(zh ? '立即升级?将保留任务记录和应用选择。' : 'Upgrade now? Task records and app selections will be preserved.', false, lang)) {
|
|
35
|
+
await startUpdate();
|
|
36
|
+
console.log(zh ? '升级已交给后台执行,终端可以关闭。可在面板或此菜单查看结果。完成后请重新连接 MCP。' : 'Update started in the background. You may close the terminal and check the result in the panel or this menu. Reconnect MCP after completion.');
|
|
37
|
+
}
|
|
38
|
+
} catch (error) { console.log(zh ? `升级入口暂不可用:${error.message}` : `Update unavailable: ${error.message}`); }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function showCodexDiagnosis(app, attachment, enabled, running, zh) {
|
|
42
|
+
if (!enabled || !app.installed) return;
|
|
43
|
+
let startup;
|
|
44
|
+
try { startup = startupStatus(DATA_DIR); }
|
|
45
|
+
catch (error) { console.log(` ${zh ? '读取启动记录失败' : 'Cannot read startup history'}: ${error.message}`); }
|
|
46
|
+
const events = {
|
|
47
|
+
'quit-timeout': ['客户端退出较慢,正在继续等待退出以完成重开', 'Client is slow to quit; waiting to finish reopening'],
|
|
48
|
+
'quit-accepted': ['客户端已接受退出请求,等待进程结束', 'Client accepted the quit request; waiting for it to exit'],
|
|
49
|
+
'late-exit-observed': ['已检测到延迟退出,正在继续重开', 'Delayed exit detected; resuming reopening'],
|
|
50
|
+
'late-exit-replaced': ['已检测到另一个客户端进程,交接已结束', 'Another client process appeared; handoff ended'],
|
|
51
|
+
'late-exit-expired': ['延迟退出等待已到期,可重新打开客户端', 'Delayed-exit monitoring expired; open the client again'],
|
|
52
|
+
reopening: ['正在带调试端口重开客户端', 'Reopening the client with the debug port'],
|
|
53
|
+
'quit-refused': ['客户端未接受退出请求', 'Client declined the quit request'],
|
|
54
|
+
'skipped-cooldown': ['本次启动落在上次接管后的保护冷却期内', 'Launch fell within the cooldown after the previous handoff'],
|
|
55
|
+
'skipped-active-or-background': ['检测到客户端已在使用或位于后台,跳过接管', 'Client was active or in the background, so handoff was skipped'],
|
|
56
|
+
'another-instance-started': ['接管期间出现另一个客户端进程', 'Another client process appeared during handoff'],
|
|
57
|
+
'port-in-use': ['调试端口已被占用', 'Debug port was already in use'],
|
|
58
|
+
'launch-failed': ['带调试端口重开失败', 'Could not reopen with the debug port'],
|
|
59
|
+
'reopen-canceled': ['接管期间已有客户端启动', 'The client was already launching during handoff'],
|
|
60
|
+
observing: ['启动观察模式', 'Startup observation mode'],
|
|
61
|
+
watching: ['启动监听已就绪', 'Startup watcher ready'],
|
|
62
|
+
reopened: ['客户端已带调试端口重开', 'Client reopened with the debug port'],
|
|
63
|
+
};
|
|
64
|
+
if (startup?.event) {
|
|
65
|
+
const date = startup.updatedAt ? ` · ${new Date(startup.updatedAt).toLocaleString(zh ? 'zh-CN' : 'en-US')}` : '';
|
|
66
|
+
console.log(` ${zh ? '最近启动记录' : 'Last startup event'}: ${events[startup.event]?.[zh ? 0 : 1] || startup.event}${date}`);
|
|
67
|
+
}
|
|
68
|
+
let diagnosis;
|
|
69
|
+
if (!running) diagnosis = zh ? '插件后台未运行。请在管理菜单同步组件与技能。' : 'The plugin daemon is stopped. Sync components and skills from the menu.';
|
|
70
|
+
else if (attachment.authHealthy === false) diagnosis = zh ? '后台进程存在,但鉴权健康检查未通过。请在管理菜单同步组件并查看启动日志。' : 'The daemon process exists, but its authenticated health check failed. Sync components and inspect the startup log.';
|
|
71
|
+
else if (!app.running) diagnosis = zh ? '等待 ChatGPT.app 启动。' : 'Waiting for ChatGPT.app to launch.';
|
|
72
|
+
else if (!attachment.portOpen && await portInUse()) diagnosis = zh ? '39222 已被监听,但无法连接到调试接口。请检查端口占用。' : 'Port 39222 is listening, but its debugger is unreachable. Check which process owns the port.';
|
|
73
|
+
else if (!attachment.portOpen) {
|
|
74
|
+
const retry = startup?.lastAttemptAt && startup.lastAttemptAt + COOLDOWN_MS - Date.now();
|
|
75
|
+
diagnosis = zh ? '当前客户端没有开启 39222 调试端口。保存工作后完全退出 ChatGPT.app,再从原图标打开。' : 'The client has no debugger on port 39222. Save your work, fully quit ChatGPT.app, then open it again.';
|
|
76
|
+
if (retry > 0) diagnosis += zh ? ` 建议在 ${Math.ceil(retry / 1000)} 秒后重开。` : ` Reopen after ${Math.ceil(retry / 1000)} seconds.`;
|
|
77
|
+
} else if (!attachment.windows.length) diagnosis = zh ? '调试端口可连接,等待 Codex 主窗口。' : 'Debugger reachable. Waiting for a Codex main window.';
|
|
78
|
+
else if (!attachment.windows.some(window => window.version)) diagnosis = zh ? '已找到主窗口,界面组件尚未挂载。' : 'Main window found. The UI component has not attached yet.';
|
|
79
|
+
else diagnosis = zh ? '界面组件已挂载。' : 'UI component attached.';
|
|
80
|
+
console.log(` ${zh ? '诊断' : 'Diagnosis'}: ${diagnosis}`);
|
|
81
|
+
if (startup?.logDirectory) console.log(` ${zh ? '启动日志' : 'Startup log'}: ${path.join(startup.logDirectory, 'agent.log')}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function showHealthStatus(lang) {
|
|
85
|
+
const env = await probeEnvironment();
|
|
86
|
+
const config = readConfig();
|
|
87
|
+
const zh = (lang || config?.lang || 'zh') === 'zh';
|
|
88
|
+
lang = zh ? 'zh' : 'en';
|
|
89
|
+
console.log(zh ? '\nAgent Things 运行状态' : '\nAgent Things Health Check');
|
|
90
|
+
const codex = await attachmentStatus(39222);
|
|
91
|
+
let codexHealthy = false;
|
|
92
|
+
try { await requestProgressHttp(path.join(DATA_DIR, 'manual-state.json'), '/health', undefined, undefined, { timeoutMs: 1000 }); codexHealthy = true; } catch {}
|
|
93
|
+
codex.authHealthy = codexHealthy;
|
|
94
|
+
let agyHealthy = false, agyMounted = 0;
|
|
95
|
+
const agyState = path.join(os.homedir(), '.gemini/antigravity/session-status/manual-state.json');
|
|
96
|
+
try { await requestProgressHttp(agyState, '/health'); agyHealthy = true; } catch {}
|
|
97
|
+
if (env.antigravity.port) {
|
|
98
|
+
for (const target of await listTargets(env.antigravity.port, 1000).catch(() => [])) {
|
|
99
|
+
if (target.type !== 'page' || !/^(https?:\/\/(127\.0\.0\.1|localhost)|vscode-file:)/.test(target.url)) continue;
|
|
100
|
+
const session = new CdpSession(target, env.antigravity.port);
|
|
101
|
+
try {
|
|
102
|
+
await session.connect();
|
|
103
|
+
const { result } = await session.evaluate('window.__codexSessionStatus?.status().mounted || 0');
|
|
104
|
+
agyMounted += Number(result.value) || 0;
|
|
105
|
+
} catch {} finally { session.close(); }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const app of [env.codex, env.antigravity]) {
|
|
109
|
+
const enabled = config?.enabledApps.includes(app.id);
|
|
110
|
+
const job = launchd.printJob(app.id === 'codex' ? 'com.codexsessionstatus.agent' : 'com.antigravity.session-status');
|
|
111
|
+
const service = Boolean(job && /\bpid = [1-9]\d*/.test(job));
|
|
112
|
+
const mounted = app.id === 'codex' ? codex.mountedConversations || 0 : agyMounted;
|
|
113
|
+
let registered = false;
|
|
114
|
+
try {
|
|
115
|
+
if (app.id === 'codex') {
|
|
116
|
+
const content = fs.readFileSync(path.join(os.homedir(), '.codex/config.toml'), 'utf8');
|
|
117
|
+
registered = Boolean(content.match(/\[mcp_servers\.session_status\][\s\S]*?(?=\n\[|$)/)?.[0].includes('codex-session-status.cjs'));
|
|
118
|
+
} else {
|
|
119
|
+
const data = JSON.parse(fs.readFileSync(path.join(os.homedir(), '.gemini/antigravity/mcp_config.json'), 'utf8'));
|
|
120
|
+
registered = Object.values(data.mcpServers || {}).some(server => server.args?.some(arg => typeof arg === 'string' && arg.endsWith('antigravity-session-status.cjs')));
|
|
121
|
+
}
|
|
122
|
+
} catch {}
|
|
123
|
+
console.log(`${app.name}: ${formatProbeText(app, lang)}`);
|
|
124
|
+
console.log(zh
|
|
125
|
+
? ` 启用: ${enabled ? '是' : '否'};后台: ${service ? '运行' : '停止'};挂载标记: ${mounted};MCP配置: ${registered ? '已注册' : '未注册'}`
|
|
126
|
+
: ` Enabled: ${Boolean(enabled)}; daemon: ${service ? 'running' : 'stopped'}; mounted badges: ${mounted}; MCP configured: ${registered}`);
|
|
127
|
+
if (app.id === 'antigravity') console.log(zh ? ` 鉴权健康检查: ${agyHealthy ? '通过' : '不可用'}` : ` Authenticated health: ${agyHealthy ? 'OK' : 'unavailable'}`);
|
|
128
|
+
if (app.id === 'codex') console.log(zh ? ` 鉴权健康检查: ${codexHealthy ? '通过' : '不可用'}` : ` Authenticated health: ${codexHealthy ? 'OK' : 'unavailable'}`);
|
|
129
|
+
if (app.id === 'codex') await showCodexDiagnosis(app, codex, enabled, service, zh);
|
|
130
|
+
}
|
|
131
|
+
if (env.claude?.installed) {
|
|
132
|
+
const stateFile = require('../harnesses/claude/claude-service.cjs').DEFAULT_STATE_FILE;
|
|
133
|
+
let healthy = false, attachment = null;
|
|
134
|
+
try { await requestProgressHttp(stateFile, '/health'); healthy = true; } catch {}
|
|
135
|
+
try { attachment = JSON.parse(fs.readFileSync(path.join(path.dirname(stateFile), 'attachment.json'), 'utf8')); } catch {}
|
|
136
|
+
if (attachment?.checkedAt && Date.now() - Date.parse(attachment.checkedAt) > 10000) {
|
|
137
|
+
attachment = { state: zh ? '连接状态已过期' : 'connection status stale' };
|
|
138
|
+
}
|
|
139
|
+
const labels = zh
|
|
140
|
+
? { attached: '已连接', 'manual-debugger-required': '等待手动开启主进程调试器', error: attachment?.error || '连接失败' }
|
|
141
|
+
: { attached: 'attached', 'manual-debugger-required': 'enable Main Process Debugger', error: attachment?.error || 'connection failed' };
|
|
142
|
+
console.log(`Claude Desktop · Code: ${formatProbeText(env.claude, lang)}`);
|
|
143
|
+
console.log(zh ? ` 启用: ${config?.enabledApps.includes('claude') ? '是' : '否'};后台: ${healthy ? '运行' : '停止'};侧栏扩展: ${labels[attachment?.state] || attachment?.state || '等待连接'}`
|
|
144
|
+
: ` Enabled: ${Boolean(config?.enabledApps.includes('claude'))}; service: ${healthy}; sidebar extension: ${labels[attachment?.state] || attachment?.state || 'waiting'}`);
|
|
145
|
+
}
|
|
146
|
+
if (config?.enabledApps.includes('claude') && fs.existsSync(path.join(os.homedir(), '.claude/skills/agent-things-ui/.claude-plugin/plugin.json'))) console.log(zh ? 'Claude 会话卡片:已安装,使用 /things。' : 'Claude conversation card: installed, run /things.');
|
|
147
|
+
console.log(zh ? 'MCP宿主连接状态请在客户端确认;注册配置与实际连接分别判断。\n' : 'Confirm MCP host connection in the client; configuration and connection are separate checks.\n');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function completed(apps, zh) {
|
|
151
|
+
console.log(zh ? `\n配置已保存。启用应用:${apps.join(', ') || '无(已停用)'}` : `\nConfiguration saved. Enabled: ${apps.join(', ') || 'none (disabled)'}`);
|
|
152
|
+
console.log(zh ? '请在宿主中重新加载 MCP 配置。终端可以关闭。' : 'Reload MCP configuration in the host. You may close the terminal.');
|
|
153
|
+
if (apps.length) console.log(zh ? '正常打开应用后,可从运行状态页检查挂载。' : 'Open the app normally and check mounting from Health Check.');
|
|
154
|
+
if (apps.includes('codex')) console.log(zh ? 'ChatGPT.app 已打开但尚无标记时,请保存工作后正常退出,再从原图标打开。' : 'If ChatGPT.app is already open without badges, save your work, quit normally, and reopen its original icon.');
|
|
155
|
+
if (apps.includes('claude')) console.log(zh
|
|
156
|
+
? 'Claude Code:新会话会加载会话卡片;已有会话输入 /reload-plugins,再用 /things 打开。侧栏圆环可在开发者菜单手动开启 Enable Main Process Debugger 后挂载。'
|
|
157
|
+
: 'Claude Code: new sessions load the card; run /reload-plugins in existing sessions, then /things. For sidebar rings, manually enable Developer → Enable Main Process Debugger.');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function runInteractiveCli(options = {}) {
|
|
161
|
+
let config = readConfig();
|
|
162
|
+
if (options.all || options.yes) {
|
|
163
|
+
const env = await probeEnvironment();
|
|
164
|
+
const apps = [env.codex, env.antigravity, env.claude].filter(app => app?.installed).map(app => app.id);
|
|
165
|
+
const lang = options.lang || config?.lang || detectSystemLang();
|
|
166
|
+
if (!apps.length) {
|
|
167
|
+
throw new Error(lang === 'en'
|
|
168
|
+
? 'No supported applications detected. Install ChatGPT.app, Antigravity.app, or Claude.app first.'
|
|
169
|
+
: '未检测到支持的应用,请先安装 ChatGPT.app、Antigravity.app 或 Claude.app。');
|
|
170
|
+
}
|
|
171
|
+
await executeSetup({ lang, enabledApps: apps, autoRestartCodex: false, verify: verifyServices });
|
|
172
|
+
completed(apps, lang === 'zh');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!process.stdin.isTTY) throw new Error('Interactive mode requires a terminal; use setup --yes for automatic installation. / 交互模式需要终端;自动安装请使用 setup --yes。');
|
|
176
|
+
if (!config || config.installed === false || !fs.existsSync(path.join(DATA_DIR, 'runtime/bin/codex-session-status.cjs'))) {
|
|
177
|
+
const env = await probeEnvironment();
|
|
178
|
+
const defaultLang = config?.lang || detectSystemLang();
|
|
179
|
+
const lang = options.lang || await selectLanguageWithProbe(env, defaultLang);
|
|
180
|
+
if (lang === null) return;
|
|
181
|
+
const apps = await selectApps(env, lang, config?.installed === false ? null : config?.enabledApps || null);
|
|
182
|
+
if (apps === null || !apps.length) { console.log(lang === 'zh' ? '安装已取消。' : 'Setup cancelled.'); return; }
|
|
183
|
+
let restart = false;
|
|
184
|
+
if (apps.includes('codex') && env.codex.running && !env.codex.portActive) {
|
|
185
|
+
const answer = await askConfirm(lang === 'zh' ? '是否现在正常退出并重新打开 ChatGPT.app 以启用挂载?请先保存工作。' : 'Quit and reopen ChatGPT.app to enable mounting now? Save your work first.', false, lang);
|
|
186
|
+
if (answer === null) return;
|
|
187
|
+
restart = answer;
|
|
188
|
+
}
|
|
189
|
+
await executeSetup({ lang, enabledApps: apps, autoRestartCodex: restart, verify: verifyServices });
|
|
190
|
+
completed(apps, lang === 'zh');
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
let lang = options.lang || config.lang;
|
|
194
|
+
let zh = lang === 'zh';
|
|
195
|
+
await showHealthStatus(lang);
|
|
196
|
+
while (true) {
|
|
197
|
+
const items = [
|
|
198
|
+
{ label: zh ? '1. 查看运行状态' : '1. Health check', value: 'health' },
|
|
199
|
+
{ label: zh ? '2. 修改启用应用' : '2. Update enabled apps', value: 'apps' },
|
|
200
|
+
{ label: zh ? '3. 切换界面与分析语言(当前:简体中文)' : '3. Switch language (Current: English)', value: 'lang' },
|
|
201
|
+
{ label: zh ? '4. 检查更新 / 升级' : '4. Check for updates / upgrade', value: 'upgrade' },
|
|
202
|
+
{ label: zh ? '5. 同步组件与技能' : '5. Sync components and skills', value: 'sync' },
|
|
203
|
+
{ label: zh ? '6. 卸载' : '6. Uninstall', value: 'uninstall' },
|
|
204
|
+
{ label: zh ? '7. 退出' : '7. Exit', value: 'exit' },
|
|
205
|
+
];
|
|
206
|
+
const action = await selectMenu(zh ? `Agent Things 管理(已启用:${config.enabledApps.join(', ') || '无'})` : `Agent Things (Enabled: ${config.enabledApps.join(', ') || 'none'})`, items, lang);
|
|
207
|
+
if (action === null || action === 'exit') return;
|
|
208
|
+
if (action === 'health') { await showHealthStatus(lang); continue; }
|
|
209
|
+
if (action === 'upgrade') { await showUpdates(lang); continue; }
|
|
210
|
+
if (action === 'lang') {
|
|
211
|
+
const nextLang = await selectLanguageWithProbe(await probeEnvironment(), lang);
|
|
212
|
+
if (nextLang === null) continue;
|
|
213
|
+
await executeSetup({ lang: nextLang, enabledApps: config.enabledApps, autoRestartCodex: false, verify: verifyServices });
|
|
214
|
+
config = readConfig() || { ...config, lang: nextLang };
|
|
215
|
+
lang = config.lang || nextLang;
|
|
216
|
+
zh = lang === 'zh';
|
|
217
|
+
completed(config.enabledApps, zh);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (action === 'uninstall') {
|
|
221
|
+
if (await askConfirm(zh ? '卸载插件后台与入口,保留任务记录和备份?' : 'Uninstall services and integrations, preserving task records and backups?', false, lang)) {
|
|
222
|
+
await uninstallAll(); console.log(zh ? '卸载完成,记录与备份已保留。请重新加载宿主 MCP 配置。' : 'Uninstalled; records and backups preserved. Reload the host MCP configuration.'); return;
|
|
223
|
+
}
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
let apps = config.enabledApps;
|
|
227
|
+
if (action === 'apps') {
|
|
228
|
+
apps = await selectApps(await probeEnvironment(), lang, config.enabledApps);
|
|
229
|
+
if (apps === null) continue;
|
|
230
|
+
}
|
|
231
|
+
await executeSetup({ lang, enabledApps: apps, autoRestartCodex: false, verify: verifyServices });
|
|
232
|
+
config = readConfig();
|
|
233
|
+
completed(apps, zh);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
module.exports = { runInteractiveCli, showHealthStatus };
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { version } = require('../../package.json');
|
|
3
|
+
const readline = require('node:readline');
|
|
4
|
+
const { formatProbeText } = require('./environment-probe.cjs');
|
|
5
|
+
const { detectSystemLang } = require('../i18n.cjs');
|
|
6
|
+
|
|
7
|
+
// ANSI escape codes
|
|
8
|
+
const HIDE_CURSOR = '\x1b[?25l';
|
|
9
|
+
const SHOW_CURSOR = '\x1b[?25h';
|
|
10
|
+
const CLEAR_LINE = '\x1b[2K';
|
|
11
|
+
const CURSOR_UP = n => (n > 0 ? `\x1b[${n}A` : '');
|
|
12
|
+
const BOLD = '\x1b[1m';
|
|
13
|
+
const DIM = '\x1b[2m';
|
|
14
|
+
const CYAN = '\x1b[36m';
|
|
15
|
+
const GREEN = '\x1b[32m';
|
|
16
|
+
const YELLOW = '\x1b[33m';
|
|
17
|
+
const GRAY = '\x1b[90m';
|
|
18
|
+
const RESET = '\x1b[0m';
|
|
19
|
+
|
|
20
|
+
function getProbeIcon(item) {
|
|
21
|
+
if (!item.installed) return `${GRAY}✖${RESET}`;
|
|
22
|
+
if (item.id === 'codex' && item.running && !item.portActive) return `${YELLOW}!${RESET}`;
|
|
23
|
+
return `${GREEN}✔${RESET}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Screen 1: Select Language with dynamic environment preview
|
|
28
|
+
*/
|
|
29
|
+
async function selectLanguageWithProbe(env, defaultLang = detectSystemLang()) {
|
|
30
|
+
const stdin = process.stdin;
|
|
31
|
+
const stdout = process.stdout;
|
|
32
|
+
if (!stdin.isTTY) throw new Error('Interactive mode requires a terminal; use setup --yes for automatic installation. / 交互模式需要终端;自动安装请使用 setup --yes。');
|
|
33
|
+
const wasRaw = stdin.isRaw;
|
|
34
|
+
const systemLang = detectSystemLang();
|
|
35
|
+
|
|
36
|
+
const languages = [
|
|
37
|
+
{ code: 'zh', label: '简体中文 (Chinese)' },
|
|
38
|
+
{ code: 'en', label: 'English' },
|
|
39
|
+
];
|
|
40
|
+
let selectedIndex = defaultLang === 'en' ? 1 : 0;
|
|
41
|
+
let lastLineCount = 0;
|
|
42
|
+
|
|
43
|
+
function render() {
|
|
44
|
+
const currentLang = languages[selectedIndex].code;
|
|
45
|
+
const isZh = currentLang === 'zh';
|
|
46
|
+
|
|
47
|
+
const lines = [];
|
|
48
|
+
lines.push('');
|
|
49
|
+
lines.push(` ${CYAN}┌─────────────────────────────────────────────────────────────┐${RESET}`);
|
|
50
|
+
lines.push(` ${CYAN}│${RESET} ${BOLD}Agent Things v${version} (Things 3 for AI Coding Agents)${RESET} ${CYAN}│${RESET}`);
|
|
51
|
+
lines.push(` ${CYAN}└─────────────────────────────────────────────────────────────┘${RESET}`);
|
|
52
|
+
lines.push('');
|
|
53
|
+
lines.push(` ${BOLD}${isZh ? '? 请选择语言 / Select Language:' : '? Select Language / 请选择语言:'}${RESET}`);
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < languages.length; i++) {
|
|
56
|
+
const opt = languages[i];
|
|
57
|
+
const isSelected = i === selectedIndex;
|
|
58
|
+
const marker = isSelected ? `${CYAN}❯${RESET}` : ' ';
|
|
59
|
+
const bullet = isSelected ? `${CYAN}(●)${RESET}` : `${GRAY}( )${RESET}`;
|
|
60
|
+
const sysTag = opt.code === systemLang
|
|
61
|
+
? ` ${DIM}${isZh ? '(系统推荐 / System default)' : '(System default)'}${RESET}`
|
|
62
|
+
: '';
|
|
63
|
+
const text = (isSelected ? `${BOLD}${opt.label}${RESET}` : `${opt.label}`) + sysTag;
|
|
64
|
+
lines.push(` ${marker} ${bullet} ${text}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
lines.push('');
|
|
68
|
+
lines.push(` ${GRAY}─────────────────────────────────────────────────────────────${RESET}`);
|
|
69
|
+
lines.push(` ${DIM}${isZh ? '🔍 本机环境探测预览 (随语言联动):' : '🔍 Local Environment Preview (Synced with language):'}${RESET}`);
|
|
70
|
+
|
|
71
|
+
const targets = [env.codex, env.antigravity, env.claude, env.agy].filter(Boolean);
|
|
72
|
+
for (const item of targets) {
|
|
73
|
+
const icon = getProbeIcon(item);
|
|
74
|
+
const name = item.name.padEnd(18, ' ');
|
|
75
|
+
const desc = formatProbeText(item, currentLang);
|
|
76
|
+
lines.push(` ${icon} ${name} ${GRAY}${desc}${RESET}`);
|
|
77
|
+
}
|
|
78
|
+
lines.push(` ${GRAY}─────────────────────────────────────────────────────────────${RESET}`);
|
|
79
|
+
lines.push(` ${DIM}${isZh ? ' (使用 ↑/↓ 或 j/k 移动光标切换,按 <回车> 确认)' : ' (Use ↑/↓ or j/k to move cursor, press <Enter> to confirm)'}${RESET}`);
|
|
80
|
+
|
|
81
|
+
// If already rendered before, move cursor up and clear
|
|
82
|
+
if (lastLineCount > 0) {
|
|
83
|
+
stdout.write(CURSOR_UP(lastLineCount) + '\r');
|
|
84
|
+
}
|
|
85
|
+
for (const l of lines) {
|
|
86
|
+
stdout.write(CLEAR_LINE + l + '\n');
|
|
87
|
+
}
|
|
88
|
+
lastLineCount = lines.length;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
readline.emitKeypressEvents(stdin);
|
|
92
|
+
stdin.setRawMode(true);
|
|
93
|
+
stdout.write(HIDE_CURSOR);
|
|
94
|
+
render();
|
|
95
|
+
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
function onKeyPress(str, key) {
|
|
98
|
+
if (!key) return;
|
|
99
|
+
|
|
100
|
+
if (key.ctrl && key.name === 'c') {
|
|
101
|
+
cleanup(); stdout.write(SHOW_CURSOR);
|
|
102
|
+
reject(Object.assign(new Error(languages[selectedIndex].code === 'zh' ? '操作已取消。' : 'Cancelled.'), { code: 'CLI_CANCELLED' })); return;
|
|
103
|
+
}
|
|
104
|
+
if (key.name === 'escape') {
|
|
105
|
+
cleanup(); stdout.write(SHOW_CURSOR); resolve(null); return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (key.name === 'up' || key.name === 'k') {
|
|
109
|
+
selectedIndex = (selectedIndex - 1 + languages.length) % languages.length;
|
|
110
|
+
render();
|
|
111
|
+
} else if (key.name === 'down' || key.name === 'j') {
|
|
112
|
+
selectedIndex = (selectedIndex + 1) % languages.length;
|
|
113
|
+
render();
|
|
114
|
+
} else if (key.name === 'return' || key.name === 'enter') {
|
|
115
|
+
cleanup();
|
|
116
|
+
stdout.write(SHOW_CURSOR);
|
|
117
|
+
resolve(languages[selectedIndex].code);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function onEnd() { cleanup(); stdout.write(SHOW_CURSOR); reject(Object.assign(new Error(languages[selectedIndex].code === 'zh' ? '输入已结束,操作取消。' : 'Input ended; cancelled.'), { code: 'CLI_CANCELLED' })); }
|
|
122
|
+
function cleanup() {
|
|
123
|
+
stdin.removeListener('end', onEnd); stdin.removeListener('close', onEnd);
|
|
124
|
+
stdin.removeListener('keypress', onKeyPress);
|
|
125
|
+
if (!stdin.listenerCount('keypress')) stdin.pause();
|
|
126
|
+
if (stdin.isTTY) stdin.setRawMode(wasRaw);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
stdin.once('end', onEnd); stdin.once('close', onEnd);
|
|
130
|
+
stdin.on('keypress', onKeyPress);
|
|
131
|
+
stdin.resume();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Screen 2: Select Apps with select-all and invert shortcuts
|
|
137
|
+
*/
|
|
138
|
+
async function selectApps(env, lang = 'zh', enabledApps = null) {
|
|
139
|
+
const isZh = lang === 'zh';
|
|
140
|
+
const stdin = process.stdin;
|
|
141
|
+
const stdout = process.stdout;
|
|
142
|
+
if (!stdin.isTTY) throw new Error(isZh ? '交互模式需要终端;自动安装请使用 setup --yes。' : 'Interactive mode requires a terminal; use setup --yes for automatic installation.');
|
|
143
|
+
const wasRaw = stdin.isRaw;
|
|
144
|
+
|
|
145
|
+
const appOptions = [
|
|
146
|
+
{
|
|
147
|
+
id: 'codex',
|
|
148
|
+
name: 'Codex (ChatGPT)',
|
|
149
|
+
installed: env.codex?.installed ?? false,
|
|
150
|
+
detail: formatProbeText(env.codex, lang),
|
|
151
|
+
selected: Boolean(env.codex?.installed && (enabledApps === null || enabledApps.includes('codex'))),
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'antigravity',
|
|
155
|
+
name: 'Antigravity',
|
|
156
|
+
installed: env.antigravity?.installed ?? false,
|
|
157
|
+
detail: formatProbeText(env.antigravity, lang),
|
|
158
|
+
selected: Boolean(env.antigravity?.installed && (enabledApps === null || enabledApps.includes('antigravity'))),
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: 'claude', name: 'Claude Desktop · Code', installed: env.claude?.installed ?? false,
|
|
162
|
+
detail: formatProbeText(env.claude, lang),
|
|
163
|
+
selected: Boolean(env.claude?.installed && (enabledApps === null || enabledApps.includes('claude'))),
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
let focusIndex = 0;
|
|
168
|
+
let lastLineCount = 0;
|
|
169
|
+
|
|
170
|
+
function render() {
|
|
171
|
+
const lines = [];
|
|
172
|
+
lines.push('');
|
|
173
|
+
const promptTitle = isZh
|
|
174
|
+
? '? 请勾选需要启用“进度清单”的目标应用:'
|
|
175
|
+
: '? Select target applications to mount Progress Checklist:';
|
|
176
|
+
lines.push(` ${BOLD}${promptTitle}${RESET}`);
|
|
177
|
+
|
|
178
|
+
for (let i = 0; i < appOptions.length; i++) {
|
|
179
|
+
const app = appOptions[i];
|
|
180
|
+
const isFocused = i === focusIndex;
|
|
181
|
+
const marker = isFocused ? `${CYAN}❯${RESET}` : ' ';
|
|
182
|
+
const check = app.selected ? `${GREEN}[✔]${RESET}` : `${GRAY}[ ]${RESET}`;
|
|
183
|
+
const name = isFocused ? `${BOLD}${app.name}${RESET}` : app.name;
|
|
184
|
+
const statusNote = app.installed ? `${GRAY}(${app.detail})${RESET}` : `${GRAY}(${app.detail} - ${isZh ? '未安装' : 'Not installed'})${RESET}`;
|
|
185
|
+
lines.push(` ${marker} ${check} ${name} ${statusNote}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
lines.push('');
|
|
189
|
+
const tip = isZh
|
|
190
|
+
? '快捷键: <空格> 勾选/取消 | <a> 全选/全不选 | <回车> 确认安装'
|
|
191
|
+
: 'Keys: <Space> Toggle | <a> Select all / Clear all | <Enter> Confirm';
|
|
192
|
+
lines.push(` ${DIM}${tip}${RESET}`);
|
|
193
|
+
|
|
194
|
+
if (lastLineCount > 0) {
|
|
195
|
+
stdout.write(CURSOR_UP(lastLineCount) + '\r');
|
|
196
|
+
}
|
|
197
|
+
for (const l of lines) {
|
|
198
|
+
stdout.write(CLEAR_LINE + l + '\n');
|
|
199
|
+
}
|
|
200
|
+
lastLineCount = lines.length;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
readline.emitKeypressEvents(stdin);
|
|
204
|
+
stdin.setRawMode(true);
|
|
205
|
+
stdout.write(HIDE_CURSOR);
|
|
206
|
+
render();
|
|
207
|
+
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
function onKeyPress(str, key) {
|
|
210
|
+
if (!key) return;
|
|
211
|
+
|
|
212
|
+
if (key.ctrl && key.name === 'c') {
|
|
213
|
+
cleanup(); stdout.write(SHOW_CURSOR);
|
|
214
|
+
reject(Object.assign(new Error(isZh ? '操作已取消。' : 'Cancelled.'), { code: 'CLI_CANCELLED' })); return;
|
|
215
|
+
}
|
|
216
|
+
if (key.name === 'escape') {
|
|
217
|
+
cleanup(); stdout.write(SHOW_CURSOR); resolve(null); return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (key.name === 'up' || key.name === 'k') {
|
|
221
|
+
focusIndex = (focusIndex - 1 + appOptions.length) % appOptions.length;
|
|
222
|
+
render();
|
|
223
|
+
} else if (key.name === 'down' || key.name === 'j') {
|
|
224
|
+
focusIndex = (focusIndex + 1) % appOptions.length;
|
|
225
|
+
render();
|
|
226
|
+
} else if (key.name === 'space') {
|
|
227
|
+
const cur = appOptions[focusIndex];
|
|
228
|
+
if (cur.installed) cur.selected = !cur.selected;
|
|
229
|
+
render();
|
|
230
|
+
} else if (str === 'a' || str === 'A') {
|
|
231
|
+
const selectable = appOptions.filter(a => a.installed);
|
|
232
|
+
const allSelected = selectable.every(a => a.selected);
|
|
233
|
+
for (const app of appOptions) {
|
|
234
|
+
if (app.installed) app.selected = !allSelected;
|
|
235
|
+
}
|
|
236
|
+
render();
|
|
237
|
+
} else if (key.name === 'return' || key.name === 'enter') {
|
|
238
|
+
cleanup();
|
|
239
|
+
stdout.write(SHOW_CURSOR);
|
|
240
|
+
const chosen = appOptions.filter(a => a.selected).map(a => a.id);
|
|
241
|
+
resolve(chosen);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function onEnd() { cleanup(); stdout.write(SHOW_CURSOR); reject(Object.assign(new Error(isZh ? '输入已结束,操作取消。' : 'Input ended; cancelled.'), { code: 'CLI_CANCELLED' })); }
|
|
246
|
+
function cleanup() {
|
|
247
|
+
stdin.removeListener('end', onEnd); stdin.removeListener('close', onEnd);
|
|
248
|
+
stdin.removeListener('keypress', onKeyPress);
|
|
249
|
+
if (!stdin.listenerCount('keypress')) stdin.pause();
|
|
250
|
+
if (stdin.isTTY) stdin.setRawMode(wasRaw);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
stdin.once('end', onEnd); stdin.once('close', onEnd);
|
|
254
|
+
stdin.on('keypress', onKeyPress);
|
|
255
|
+
stdin.resume();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Ask simple confirm question
|
|
261
|
+
*/
|
|
262
|
+
async function askConfirm(question, defaultYes = true, lang = 'zh') {
|
|
263
|
+
const isZh = lang === 'zh';
|
|
264
|
+
const stdin = process.stdin;
|
|
265
|
+
const stdout = process.stdout;
|
|
266
|
+
if (!stdin.isTTY) throw new Error(isZh ? '交互模式需要终端;自动安装请使用 setup --yes。' : 'Interactive mode requires a terminal; use setup --yes for automatic installation.');
|
|
267
|
+
const wasRaw = stdin.isRaw;
|
|
268
|
+
|
|
269
|
+
let isYes = defaultYes;
|
|
270
|
+
let lastLineCount = 0;
|
|
271
|
+
|
|
272
|
+
function render() {
|
|
273
|
+
const lines = [];
|
|
274
|
+
const yesText = isYes ? `${BOLD}${CYAN}(●) ${isZh ? '是 (Yes)' : 'Yes'}${RESET}` : `${GRAY}( ) ${isZh ? '是 (Yes)' : 'Yes'}${RESET}`;
|
|
275
|
+
const noText = !isYes ? `${BOLD}${CYAN}(●) ${isZh ? '否 (No)' : 'No'}${RESET}` : `${GRAY}( ) ${isZh ? '否 (No)' : 'No'}${RESET}`;
|
|
276
|
+
lines.push('');
|
|
277
|
+
lines.push(` ${BOLD}${question}${RESET}`);
|
|
278
|
+
lines.push(` ${yesText} ${noText}`);
|
|
279
|
+
lines.push(` ${DIM}${isZh ? ' (使用 ←/→ 切换,按 <回车> 确认)' : ' (Use ←/→ to switch, press <Enter> to confirm)'}${RESET}`);
|
|
280
|
+
|
|
281
|
+
if (lastLineCount > 0) {
|
|
282
|
+
stdout.write(CURSOR_UP(lastLineCount) + '\r');
|
|
283
|
+
}
|
|
284
|
+
for (const l of lines) {
|
|
285
|
+
stdout.write(CLEAR_LINE + l + '\n');
|
|
286
|
+
}
|
|
287
|
+
lastLineCount = lines.length;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
readline.emitKeypressEvents(stdin);
|
|
291
|
+
stdin.setRawMode(true);
|
|
292
|
+
stdout.write(HIDE_CURSOR);
|
|
293
|
+
render();
|
|
294
|
+
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
function onKeyPress(str, key) {
|
|
297
|
+
if (!key) return;
|
|
298
|
+
|
|
299
|
+
if (key.ctrl && key.name === 'c') {
|
|
300
|
+
cleanup(); stdout.write(SHOW_CURSOR);
|
|
301
|
+
reject(Object.assign(new Error(isZh ? '操作已取消。' : 'Cancelled.'), { code: 'CLI_CANCELLED' })); return;
|
|
302
|
+
}
|
|
303
|
+
if (key.name === 'escape') {
|
|
304
|
+
cleanup(); stdout.write(SHOW_CURSOR); resolve(null); return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (key.name === 'left' || key.name === 'right' || key.name === 'tab') {
|
|
308
|
+
isYes = !isYes;
|
|
309
|
+
render();
|
|
310
|
+
} else if (key.name === 'return' || key.name === 'enter') {
|
|
311
|
+
cleanup();
|
|
312
|
+
stdout.write(SHOW_CURSOR);
|
|
313
|
+
resolve(isYes);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function onEnd() { cleanup(); stdout.write(SHOW_CURSOR); reject(Object.assign(new Error(isZh ? '输入已结束,操作取消。' : 'Input ended; cancelled.'), { code: 'CLI_CANCELLED' })); }
|
|
318
|
+
function cleanup() {
|
|
319
|
+
stdin.removeListener('end', onEnd); stdin.removeListener('close', onEnd);
|
|
320
|
+
stdin.removeListener('keypress', onKeyPress);
|
|
321
|
+
if (!stdin.listenerCount('keypress')) stdin.pause();
|
|
322
|
+
if (stdin.isTTY) stdin.setRawMode(wasRaw);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
stdin.once('end', onEnd); stdin.once('close', onEnd);
|
|
326
|
+
stdin.on('keypress', onKeyPress);
|
|
327
|
+
stdin.resume();
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Single-select menu for control hub
|
|
333
|
+
*/
|
|
334
|
+
async function selectMenu(title, options, lang = 'zh') {
|
|
335
|
+
const isZh = lang === 'zh';
|
|
336
|
+
const stdin = process.stdin;
|
|
337
|
+
const stdout = process.stdout;
|
|
338
|
+
if (!stdin.isTTY) throw new Error(isZh ? '交互模式需要终端;自动安装请使用 setup --yes。' : 'Interactive mode requires a terminal; use setup --yes for automatic installation.');
|
|
339
|
+
const wasRaw = stdin.isRaw;
|
|
340
|
+
|
|
341
|
+
let selectedIndex = 0;
|
|
342
|
+
let lastLineCount = 0;
|
|
343
|
+
|
|
344
|
+
function render() {
|
|
345
|
+
const lines = [];
|
|
346
|
+
lines.push('');
|
|
347
|
+
lines.push(` ${BOLD}${title}${RESET}`);
|
|
348
|
+
|
|
349
|
+
for (let i = 0; i < options.length; i++) {
|
|
350
|
+
const opt = options[i];
|
|
351
|
+
const isSelected = i === selectedIndex;
|
|
352
|
+
const marker = isSelected ? `${CYAN}❯${RESET}` : ' ';
|
|
353
|
+
const bullet = isSelected ? `${CYAN}●${RESET}` : `${GRAY}○${RESET}`;
|
|
354
|
+
const text = isSelected ? `${BOLD}${opt.label}${RESET}` : opt.label;
|
|
355
|
+
lines.push(` ${marker} ${bullet} ${text}`);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
lines.push('');
|
|
359
|
+
const tip = isZh ? ' (使用 ↑/↓ 移动光标,按 <回车> 确认)' : ' (Use ↑/↓ to move cursor, press <Enter> to confirm)';
|
|
360
|
+
lines.push(` ${DIM}${tip}${RESET}`);
|
|
361
|
+
|
|
362
|
+
if (lastLineCount > 0) {
|
|
363
|
+
stdout.write(CURSOR_UP(lastLineCount) + '\r');
|
|
364
|
+
}
|
|
365
|
+
for (const l of lines) {
|
|
366
|
+
stdout.write(CLEAR_LINE + l + '\n');
|
|
367
|
+
}
|
|
368
|
+
lastLineCount = lines.length;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
readline.emitKeypressEvents(stdin);
|
|
372
|
+
stdin.setRawMode(true);
|
|
373
|
+
stdout.write(HIDE_CURSOR);
|
|
374
|
+
render();
|
|
375
|
+
|
|
376
|
+
return new Promise((resolve, reject) => {
|
|
377
|
+
function onKeyPress(str, key) {
|
|
378
|
+
if (!key) return;
|
|
379
|
+
|
|
380
|
+
if (key.ctrl && key.name === 'c') {
|
|
381
|
+
cleanup(); stdout.write(SHOW_CURSOR);
|
|
382
|
+
reject(Object.assign(new Error(isZh ? '操作已取消。' : 'Cancelled.'), { code: 'CLI_CANCELLED' })); return;
|
|
383
|
+
}
|
|
384
|
+
if (key.name === 'escape') {
|
|
385
|
+
cleanup(); stdout.write(SHOW_CURSOR); resolve(null); return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (key.name === 'up' || key.name === 'k') {
|
|
389
|
+
selectedIndex = (selectedIndex - 1 + options.length) % options.length;
|
|
390
|
+
render();
|
|
391
|
+
} else if (key.name === 'down' || key.name === 'j') {
|
|
392
|
+
selectedIndex = (selectedIndex + 1) % options.length;
|
|
393
|
+
render();
|
|
394
|
+
} else if (key.name === 'return' || key.name === 'enter') {
|
|
395
|
+
cleanup();
|
|
396
|
+
stdout.write(SHOW_CURSOR);
|
|
397
|
+
resolve(options[selectedIndex].value);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function onEnd() { cleanup(); stdout.write(SHOW_CURSOR); reject(Object.assign(new Error(isZh ? '输入已结束,操作取消。' : 'Input ended; cancelled.'), { code: 'CLI_CANCELLED' })); }
|
|
402
|
+
function cleanup() {
|
|
403
|
+
stdin.removeListener('end', onEnd); stdin.removeListener('close', onEnd);
|
|
404
|
+
stdin.removeListener('keypress', onKeyPress);
|
|
405
|
+
if (!stdin.listenerCount('keypress')) stdin.pause();
|
|
406
|
+
if (stdin.isTTY) stdin.setRawMode(wasRaw);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
stdin.once('end', onEnd); stdin.once('close', onEnd);
|
|
410
|
+
stdin.on('keypress', onKeyPress);
|
|
411
|
+
stdin.resume();
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
module.exports = {
|
|
416
|
+
selectLanguageWithProbe,
|
|
417
|
+
selectApps,
|
|
418
|
+
askConfirm,
|
|
419
|
+
selectMenu,
|
|
420
|
+
};
|