@bolloon/bolloon-agent 0.3.30 → 0.3.32
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/dist/agents/pi-sdk-tools.js +128 -0
- package/dist/cli/ink-app.js +345 -2
- package/dist/cli/mention-data.js +238 -0
- package/dist/constraint-runtime/_archive_helper.d.ts +1 -0
- package/dist/constraint-runtime/_archive_helper.js +9 -0
- package/dist/constraint-runtime/agent/coordinator.d.ts +19 -0
- package/dist/constraint-runtime/agent/coordinator.js +48 -0
- package/dist/constraint-runtime/agent/index.d.ts +1 -0
- package/dist/constraint-runtime/agent/index.js +1 -0
- package/dist/constraint-runtime/assistant/index.d.ts +11 -0
- package/dist/constraint-runtime/assistant/index.js +12 -0
- package/dist/constraint-runtime/bootstrap/index.d.ts +11 -0
- package/dist/constraint-runtime/bootstrap/index.js +12 -0
- package/dist/constraint-runtime/bootstrap_graph.d.ts +4 -0
- package/dist/constraint-runtime/bootstrap_graph.js +13 -0
- package/dist/constraint-runtime/bridge/index.d.ts +11 -0
- package/dist/constraint-runtime/bridge/index.js +12 -0
- package/dist/constraint-runtime/buddy/index.d.ts +11 -0
- package/dist/constraint-runtime/buddy/index.js +12 -0
- package/dist/constraint-runtime/cli/index.d.ts +11 -0
- package/dist/constraint-runtime/cli/index.js +12 -0
- package/dist/constraint-runtime/command_graph.d.ts +7 -0
- package/dist/constraint-runtime/command_graph.js +10 -0
- package/dist/constraint-runtime/commands.d.ts +15 -0
- package/dist/constraint-runtime/commands.js +60 -0
- package/dist/constraint-runtime/components/index.d.ts +11 -0
- package/dist/constraint-runtime/components/index.js +12 -0
- package/dist/constraint-runtime/constants/index.d.ts +11 -0
- package/dist/constraint-runtime/constants/index.js +12 -0
- package/dist/constraint-runtime/constraint/budget.d.ts +11 -0
- package/dist/constraint-runtime/constraint/budget.js +22 -0
- package/dist/constraint-runtime/constraint/index.d.ts +3 -0
- package/dist/constraint-runtime/constraint/index.js +2 -0
- package/dist/constraint-runtime/constraint/permission.d.ts +9 -0
- package/dist/constraint-runtime/constraint/permission.js +20 -0
- package/dist/constraint-runtime/context.d.ts +12 -0
- package/dist/constraint-runtime/context.js +30 -0
- package/dist/constraint-runtime/coordinator/index.d.ts +11 -0
- package/dist/constraint-runtime/coordinator/index.js +12 -0
- package/dist/constraint-runtime/cost_hook.d.ts +2 -0
- package/dist/constraint-runtime/cost_hook.js +4 -0
- package/dist/constraint-runtime/cost_tracker.d.ts +5 -0
- package/dist/constraint-runtime/cost_tracker.js +8 -0
- package/dist/constraint-runtime/deferred_init.d.ts +8 -0
- package/dist/constraint-runtime/deferred_init.js +10 -0
- package/dist/constraint-runtime/direct_modes.d.ts +7 -0
- package/dist/constraint-runtime/direct_modes.js +6 -0
- package/dist/constraint-runtime/dynamic-tool-loader.d.ts +13 -0
- package/dist/constraint-runtime/dynamic-tool-loader.js +85 -0
- package/dist/constraint-runtime/entrypoints/index.d.ts +11 -0
- package/dist/constraint-runtime/entrypoints/index.js +12 -0
- package/dist/constraint-runtime/execution_registry.d.ts +20 -0
- package/dist/constraint-runtime/execution_registry.js +44 -0
- package/dist/constraint-runtime/history.d.ts +9 -0
- package/dist/constraint-runtime/history.js +9 -0
- package/dist/constraint-runtime/hooks/index.d.ts +11 -0
- package/dist/constraint-runtime/hooks/index.js +12 -0
- package/dist/constraint-runtime/index.d.ts +26 -0
- package/dist/constraint-runtime/index.js +26 -0
- package/dist/constraint-runtime/ink.d.ts +1 -0
- package/dist/constraint-runtime/ink.js +4 -0
- package/dist/constraint-runtime/keybindings/index.d.ts +11 -0
- package/dist/constraint-runtime/keybindings/index.js +12 -0
- package/dist/constraint-runtime/memdir/index.d.ts +11 -0
- package/dist/constraint-runtime/memdir/index.js +12 -0
- package/dist/constraint-runtime/migrations/index.d.ts +11 -0
- package/dist/constraint-runtime/migrations/index.js +12 -0
- package/dist/constraint-runtime/models.d.ts +42 -0
- package/dist/constraint-runtime/models.js +1 -0
- package/dist/constraint-runtime/moreright/index.d.ts +11 -0
- package/dist/constraint-runtime/moreright/index.js +12 -0
- package/dist/constraint-runtime/native_ts/index.d.ts +11 -0
- package/dist/constraint-runtime/native_ts/index.js +12 -0
- package/dist/constraint-runtime/output_styles/index.d.ts +11 -0
- package/dist/constraint-runtime/output_styles/index.js +12 -0
- package/dist/constraint-runtime/parity_audit.d.ts +11 -0
- package/dist/constraint-runtime/parity_audit.js +12 -0
- package/dist/constraint-runtime/plugins/index.d.ts +11 -0
- package/dist/constraint-runtime/plugins/index.js +12 -0
- package/dist/constraint-runtime/port_manifest.d.ts +7 -0
- package/dist/constraint-runtime/port_manifest.js +11 -0
- package/dist/constraint-runtime/prefetch.d.ts +8 -0
- package/dist/constraint-runtime/prefetch.js +9 -0
- package/dist/constraint-runtime/query.d.ts +6 -0
- package/dist/constraint-runtime/query.js +1 -0
- package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
- package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
- package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
- package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
- package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
- package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
- package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
- package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
- package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
- package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
- package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
- package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
- package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
- package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
- package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
- package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
- package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
- package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
- package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
- package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
- package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
- package/dist/constraint-runtime/remote/index.d.ts +11 -0
- package/dist/constraint-runtime/remote/index.js +12 -0
- package/dist/constraint-runtime/remote_runtime.d.ts +8 -0
- package/dist/constraint-runtime/remote_runtime.js +9 -0
- package/dist/constraint-runtime/runtime/index.d.ts +1 -0
- package/dist/constraint-runtime/runtime/index.js +1 -0
- package/dist/constraint-runtime/runtime/session.d.ts +22 -0
- package/dist/constraint-runtime/runtime/session.js +35 -0
- package/dist/constraint-runtime/schemas/index.d.ts +11 -0
- package/dist/constraint-runtime/schemas/index.js +12 -0
- package/dist/constraint-runtime/screens/index.d.ts +11 -0
- package/dist/constraint-runtime/screens/index.js +12 -0
- package/dist/constraint-runtime/server/index.d.ts +11 -0
- package/dist/constraint-runtime/server/index.js +12 -0
- package/dist/constraint-runtime/services/index.d.ts +11 -0
- package/dist/constraint-runtime/services/index.js +12 -0
- package/dist/constraint-runtime/session_store.d.ts +8 -0
- package/dist/constraint-runtime/session_store.js +22 -0
- package/dist/constraint-runtime/setup.d.ts +19 -0
- package/dist/constraint-runtime/setup.js +30 -0
- package/dist/constraint-runtime/skills/index.d.ts +1 -0
- package/dist/constraint-runtime/skills/index.js +1 -0
- package/dist/constraint-runtime/skills/skill-registry.d.ts +14 -0
- package/dist/constraint-runtime/skills/skill-registry.js +28 -0
- package/dist/constraint-runtime/state/index.d.ts +11 -0
- package/dist/constraint-runtime/state/index.js +12 -0
- package/dist/constraint-runtime/system_init.d.ts +1 -0
- package/dist/constraint-runtime/system_init.js +20 -0
- package/dist/constraint-runtime/thinking/engine.d.ts +20 -0
- package/dist/constraint-runtime/thinking/engine.js +42 -0
- package/dist/constraint-runtime/thinking/index.d.ts +1 -0
- package/dist/constraint-runtime/thinking/index.js +1 -0
- package/dist/constraint-runtime/tool_pool.d.ts +8 -0
- package/dist/constraint-runtime/tool_pool.js +8 -0
- package/dist/constraint-runtime/tools/OpenCLI/execAdapter.d.ts +9 -0
- package/dist/constraint-runtime/tools/OpenCLI/execAdapter.js +7 -0
- package/dist/constraint-runtime/tools/OpenCLI/listAdapters.d.ts +5 -0
- package/dist/constraint-runtime/tools/OpenCLI/listAdapters.js +7 -0
- package/dist/constraint-runtime/tools/OpenCLI/runCommand.d.ts +10 -0
- package/dist/constraint-runtime/tools/OpenCLI/runCommand.js +7 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/cancelOrder.d.ts +17 -0
- package/dist/constraint-runtime/{src/tools → tools}/PolymarketSDK/cancelOrder.js +4 -7
- package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.d.ts +50 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.js +78 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/createOrder.d.ts +31 -0
- package/dist/constraint-runtime/{src/tools → tools}/PolymarketSDK/createOrder.js +9 -12
- package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.d.ts +10 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.js +16 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.d.ts +16 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.js +25 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.d.ts +23 -0
- package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.js +24 -0
- package/dist/constraint-runtime/tools/SafeSDK/confirmTransaction.d.ts +10 -0
- package/dist/constraint-runtime/tools/SafeSDK/confirmTransaction.js +6 -0
- package/dist/constraint-runtime/tools/SafeSDK/createTransaction.d.ts +14 -0
- package/dist/constraint-runtime/tools/SafeSDK/createTransaction.js +8 -0
- package/dist/constraint-runtime/tools/SafeSDK/deploySafe.d.ts +10 -0
- package/dist/constraint-runtime/tools/SafeSDK/executeTransaction.d.ts +9 -0
- package/dist/constraint-runtime/tools/SafeSDK/executeTransaction.js +6 -0
- package/dist/constraint-runtime/tools/SafeSDK/getBalance.d.ts +7 -0
- package/dist/constraint-runtime/tools/SafeSDK/getBalance.js +6 -0
- package/dist/constraint-runtime/tools/SafeSDK/getPendingTransactions.d.ts +7 -0
- package/dist/constraint-runtime/tools/SafeSDK/getPendingTransactions.js +6 -0
- package/dist/constraint-runtime/tools/SafeSDK/proposeTransaction.d.ts +11 -0
- package/dist/constraint-runtime/tools/SafeSDK/proposeTransaction.js +6 -0
- package/dist/constraint-runtime/tools/WalletTools/autoPay.d.ts +26 -0
- package/dist/constraint-runtime/tools/WalletTools/createWallet.d.ts +7 -0
- package/dist/constraint-runtime/tools/WalletTools/getBalance.d.ts +11 -0
- package/dist/constraint-runtime/tools/WalletTools/importWallet.d.ts +10 -0
- package/dist/constraint-runtime/tools/WalletTools/sendTransaction.d.ts +20 -0
- package/dist/constraint-runtime/tools/WalletTools/signMessage.d.ts +10 -0
- package/dist/constraint-runtime/tools/WalletTools/transferToken.d.ts +17 -0
- package/dist/constraint-runtime/tools.d.ts +14 -0
- package/dist/constraint-runtime/tools.js +80 -0
- package/dist/constraint-runtime/transcript.d.ts +8 -0
- package/dist/constraint-runtime/transcript.js +19 -0
- package/dist/constraint-runtime/types/index.d.ts +11 -0
- package/dist/constraint-runtime/types/index.js +12 -0
- package/dist/constraint-runtime/upstream_proxy/index.d.ts +11 -0
- package/dist/constraint-runtime/upstream_proxy/index.js +12 -0
- package/dist/constraint-runtime/utils/index.d.ts +11 -0
- package/dist/constraint-runtime/utils/index.js +12 -0
- package/dist/constraint-runtime/vim/index.d.ts +11 -0
- package/dist/constraint-runtime/vim/index.js +12 -0
- package/dist/constraint-runtime/voice/index.d.ts +11 -0
- package/dist/constraint-runtime/voice/index.js +12 -0
- package/dist/index.js +7 -4
- package/dist/llm/config-store.js +39 -28
- package/dist/llm/pi-ai.js +64 -36
- package/dist/security/tool-gate.js +2 -0
- package/package.json +3 -2
- package/dist/constraint-runtime/src/tools/PolymarketSDK/clobShared.js +0 -104
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +0 -5
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +0 -19
- package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +0 -4
- /package/dist/constraint-runtime/{src/tools → tools}/SafeSDK/deploySafe.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/autoPay.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/createWallet.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/getBalance.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/importWallet.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/sendTransaction.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/signMessage.js +0 -0
- /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/transferToken.js +0 -0
|
@@ -948,6 +948,134 @@ export function registerBuiltinTools(ctx) {
|
|
|
948
948
|
}
|
|
949
949
|
}
|
|
950
950
|
});
|
|
951
|
+
// ============================================================
|
|
952
|
+
// Web 上网工具 (2026-08-04) — fetch_url + web_search
|
|
953
|
+
// 用 undici request (独立连接池, 与 pi-ai 一致, 避开全局 fetch 僵尸连接问题)
|
|
954
|
+
// ============================================================
|
|
955
|
+
ctx.tools.set('fetch_url', {
|
|
956
|
+
name: 'fetch_url',
|
|
957
|
+
description: '抓取一个 URL 的网页内容并转成纯文本. 适合查文档/新闻/API 页面. 返回前 4000 字符. HTML 自动去标签, JSON/文本原样返回. (走 curl, 兼容 TLS 指纹风控)',
|
|
958
|
+
parameters: { url: '完整 URL (必填, 含 https://)' },
|
|
959
|
+
execute: async (args) => {
|
|
960
|
+
try {
|
|
961
|
+
const url = String(args.url || '').trim();
|
|
962
|
+
if (!url)
|
|
963
|
+
return { success: false, error: 'url 必填' };
|
|
964
|
+
if (!/^https?:\/\//i.test(url))
|
|
965
|
+
return { success: false, error: 'url 必须以 http(s):// 开头' };
|
|
966
|
+
const { execFile } = await import('child_process');
|
|
967
|
+
const { promisify } = await import('util');
|
|
968
|
+
const pExecFile = promisify(execFile);
|
|
969
|
+
const { stdout, stderr } = await pExecFile('curl', [
|
|
970
|
+
'-sL', '--max-time', '25',
|
|
971
|
+
'-A', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36',
|
|
972
|
+
'-H', 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8',
|
|
973
|
+
url,
|
|
974
|
+
], { maxBuffer: 2 * 1024 * 1024, timeout: 30_000 });
|
|
975
|
+
if (!stdout && stderr)
|
|
976
|
+
return { success: false, error: `fetch_url 失败: ${String(stderr).slice(0, 200)}` };
|
|
977
|
+
const raw = stdout.slice(0, 60_000);
|
|
978
|
+
const trimmed = raw.trimStart();
|
|
979
|
+
let text;
|
|
980
|
+
if (trimmed.startsWith('<!doctype') || trimmed.startsWith('<html') || /^<\?xml/i.test(trimmed)) {
|
|
981
|
+
text = raw
|
|
982
|
+
.replace(/<script[\s\S]*?<\/script>/gi, ' ')
|
|
983
|
+
.replace(/<style[\s\S]*?<\/style>/gi, ' ')
|
|
984
|
+
.replace(/<[^>]+>/g, ' ')
|
|
985
|
+
.replace(/ /g, ' ').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'")
|
|
986
|
+
.replace(/\s+/g, ' ')
|
|
987
|
+
.trim();
|
|
988
|
+
}
|
|
989
|
+
else {
|
|
990
|
+
text = raw;
|
|
991
|
+
}
|
|
992
|
+
const out = text.slice(0, 4000);
|
|
993
|
+
return { success: true, output: `🌐 ${url} (${raw.length} bytes):\n${out}${text.length > 4000 ? '\n...(截断, 共 ' + text.length + ' 字符)' : ''}` };
|
|
994
|
+
}
|
|
995
|
+
catch (e) {
|
|
996
|
+
return { success: false, error: `fetch_url 失败: ${String(e?.message || e).slice(0, 200)}` };
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
ctx.tools.set('web_search', {
|
|
1001
|
+
name: 'web_search',
|
|
1002
|
+
description: '网页搜索. 无 key 时走 DuckDuckGo Instant Answer API + Wikipedia (知识/资讯查询可靠); 配置 TAVILY_API_KEY 时走 Tavily 完整搜索 (更全). 返回前 8 条标题+URL+摘要.',
|
|
1003
|
+
parameters: { query: '搜索词 (必填)' },
|
|
1004
|
+
execute: async (args) => {
|
|
1005
|
+
try {
|
|
1006
|
+
const query = String(args.query || '').trim();
|
|
1007
|
+
if (!query)
|
|
1008
|
+
return { success: false, error: 'query 必填' };
|
|
1009
|
+
const { execFile } = await import('child_process');
|
|
1010
|
+
const { promisify } = await import('util');
|
|
1011
|
+
const pExecFile = promisify(execFile);
|
|
1012
|
+
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36';
|
|
1013
|
+
const curlJson = async (url) => {
|
|
1014
|
+
const r = await pExecFile('curl', ['-s', '--max-time', '15', '-A', UA, url], { maxBuffer: 4 * 1024 * 1024, timeout: 20_000 });
|
|
1015
|
+
return JSON.parse(r.stdout);
|
|
1016
|
+
};
|
|
1017
|
+
// 引擎 0: Tavily (配了 TAVILY_API_KEY 时最完整)
|
|
1018
|
+
const tavilyKey = process.env.TAVILY_API_KEY || '';
|
|
1019
|
+
if (tavilyKey) {
|
|
1020
|
+
const r = await pExecFile('curl', [
|
|
1021
|
+
'-s', '--max-time', '20', '-A', UA,
|
|
1022
|
+
'-X', 'POST', 'https://api.tavily.com/search',
|
|
1023
|
+
'-H', 'Content-Type: application/json',
|
|
1024
|
+
'-d', JSON.stringify({ api_key: tavilyKey, query, max_results: 8, include_answer: true }),
|
|
1025
|
+
], { maxBuffer: 4 * 1024 * 1024, timeout: 25_000 });
|
|
1026
|
+
const d = JSON.parse(r.stdout);
|
|
1027
|
+
const results = d.results || [];
|
|
1028
|
+
if (results.length > 0) {
|
|
1029
|
+
const lines = results.slice(0, 8).map((x, i) => `${i + 1}. ${x.title}\n ${x.url}${x.content ? '\n ' + String(x.content).replace(/\s+/g, ' ').slice(0, 150) : ''}`);
|
|
1030
|
+
const answer = d.answer ? `\n📌 ${d.answer}\n` : '';
|
|
1031
|
+
return { success: true, output: `🔎 "${query}" 结果 ${results.length} 条 (Tavily):${answer}\n\n${lines.join('\n\n')}` };
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
// 引擎 1: DuckDuckGo Instant Answer API (摘要 + 相关主题)
|
|
1035
|
+
try {
|
|
1036
|
+
const ia = await curlJson(`https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_html=1`);
|
|
1037
|
+
const out = [];
|
|
1038
|
+
if (ia.AbstractText && ia.AbstractURL) {
|
|
1039
|
+
out.push(`📖 ${ia.AbstractText.slice(0, 400)}\n ${ia.AbstractURL}`);
|
|
1040
|
+
}
|
|
1041
|
+
const topics = Array.isArray(ia.RelatedTopics) ? ia.RelatedTopics : [];
|
|
1042
|
+
for (const t of topics) {
|
|
1043
|
+
if (out.length >= 8)
|
|
1044
|
+
break;
|
|
1045
|
+
if (t.Topics) { // 分类组
|
|
1046
|
+
for (const sub of t.Topics) {
|
|
1047
|
+
if (out.length >= 8)
|
|
1048
|
+
break;
|
|
1049
|
+
if (sub.Text && sub.FirstURL)
|
|
1050
|
+
out.push(`${out.length + 1}. ${sub.Text.slice(0, 200)}\n ${sub.FirstURL}`);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
else if (t.Text && t.FirstURL) {
|
|
1054
|
+
out.push(`${out.length + 1}. ${t.Text.slice(0, 200)}\n ${t.FirstURL}`);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (out.length > 0) {
|
|
1058
|
+
return { success: true, output: `🔎 "${query}" (DuckDuckGo):\n\n${out.join('\n\n')}` };
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
catch { /* fallback */ }
|
|
1062
|
+
// 引擎 2: Wikipedia 搜索 API
|
|
1063
|
+
try {
|
|
1064
|
+
const wiki = await curlJson(`https://zh.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(query)}&format=json&srlimit=5`);
|
|
1065
|
+
const hits = wiki?.query?.search || [];
|
|
1066
|
+
if (hits.length > 0) {
|
|
1067
|
+
const lines = hits.map((h, i) => `${i + 1}. ${h.title}\n https://zh.wikipedia.org/wiki/${encodeURIComponent(h.title.replace(/ /g, '_'))}\n ${String(h.snippet || '').replace(/<[^>]+>/g, '').slice(0, 120)}`);
|
|
1068
|
+
return { success: true, output: `🔎 "${query}" (维基百科 ${hits.length} 条):\n\n${lines.join('\n\n')}` };
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
catch { /* fallback */ }
|
|
1072
|
+
return { success: true, output: `🔎 "${query}" 无结果 (免费引擎无匹配, 可配 TAVILY_API_KEY 提升覆盖)` };
|
|
1073
|
+
}
|
|
1074
|
+
catch (e) {
|
|
1075
|
+
return { success: false, error: `web_search 失败: ${String(e?.message || e).slice(0, 200)}` };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
951
1079
|
ctx.tools.set('git_log', {
|
|
952
1080
|
name: 'git_log',
|
|
953
1081
|
description: '查看 git log. 默认 --oneline -10. 支持过滤和范围.',
|
package/dist/cli/ink-app.js
CHANGED
|
@@ -3,11 +3,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
* ink-app.tsx — Ink (React for CLI) 渲染入口
|
|
4
4
|
*
|
|
5
5
|
* 用 Yoga flexbox 布局实现: 内容置顶, 输入栏固定底部, 状态栏固定
|
|
6
|
+
*
|
|
7
|
+
* 2026-08-05: @ / # 弹出选择窗 — 输入 @ 命中智能体, / 命中命令+技能+插件, # 命中文件
|
|
8
|
+
* ↑/↓ 导航, Tab/Enter 选中, Esc 关闭, 弹出窗打开时 TextInput 让出焦点 (focus=false)
|
|
6
9
|
*/
|
|
7
|
-
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
10
|
+
import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
|
8
11
|
import { render, Box, Text, useInput, useApp } from 'ink';
|
|
9
12
|
import TextInput from 'ink-text-input';
|
|
10
13
|
import { brandArtLines, boxTop, boxRow, boxBottom, dispWidth } from './loading-tui.js';
|
|
14
|
+
import { loadAgents, loadCommands, loadSkills, loadPlugins, loadFiles, getMention, matchFileScore, } from './mention-data.js';
|
|
11
15
|
// ─── 组件: Logo Box ──────────────────────────────────────────────────────────
|
|
12
16
|
const LogoBox = ({ width }) => {
|
|
13
17
|
const art = brandArtLines();
|
|
@@ -24,6 +28,17 @@ const Messages = ({ msgs }) => (_jsx(Box, { flexDirection: "column", flexGrow: 1
|
|
|
24
28
|
const clean = m.replace(/\x1b\[[0-9;]*m/g, '');
|
|
25
29
|
return clean.trim() ? _jsx(Text, { children: clean ? m : '' }, i) : null;
|
|
26
30
|
}) }));
|
|
31
|
+
const MentionPopup = ({ title, items, sel, width, loading }) => {
|
|
32
|
+
const MAX_ROWS = 8;
|
|
33
|
+
const shown = items.slice(0, MAX_ROWS);
|
|
34
|
+
const innerW = Math.max(width - 2, 10);
|
|
35
|
+
return (_jsxs(Box, { flexDirection: "column", width: width, children: [_jsx(Text, { color: "cyan", bold: true, children: `╭─ ${title} ${'─'.repeat(Math.max(2, innerW - dispWidth(title) - 4))}╮` }), loading && items.length === 0 ? (_jsx(Text, { color: "dim", children: "\u2502 \u626B\u63CF\u4E2D..." })) : !loading && items.length === 0 ? (_jsx(Text, { color: "dim", children: "\u2502 \u65E0\u5339\u914D" })) : (shown.map((it, i) => {
|
|
36
|
+
const active = i === sel;
|
|
37
|
+
const label = it.kind === 'file' ? it.label : `${it.kind === 'skill' ? '⚡' : it.kind === 'plugin' ? '🔌' : ''}${it.label}`;
|
|
38
|
+
const hint = it.hint ? `${it.hint}` : it.kind === 'file' ? '文件' : '';
|
|
39
|
+
return (_jsxs(Box, { width: innerW, children: [_jsx(Text, { color: active ? 'black' : undefined, backgroundColor: active ? 'cyan' : undefined, children: `${active ? '❯ ' : ' '}${label}` }), _jsx(Text, { color: active ? 'black' : 'dim', backgroundColor: active ? 'cyan' : undefined, dimColor: !active, children: ` ${hint}` })] }, `${it.kind}:${it.label}`));
|
|
40
|
+
})), items.length > MAX_ROWS && (_jsxs(Text, { color: "dim", children: ["\u2502 \u8FD8\u6709 ", items.length - MAX_ROWS, " \u9879..."] })), _jsx(Text, { color: "cyan", children: `╰${'─'.repeat(innerW)}╯` })] }));
|
|
41
|
+
};
|
|
27
42
|
const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH }) => {
|
|
28
43
|
const [input, setInput] = useState('');
|
|
29
44
|
const [msgs, setMsgs] = useState([]);
|
|
@@ -34,6 +49,206 @@ const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH
|
|
|
34
49
|
// 双击 Esc 退出当前进程 (500ms 窗口内第二次按下)
|
|
35
50
|
const lastEscRef = useRef(0);
|
|
36
51
|
const C_WARN_ANSI = '\x1b[38;2;245;158;11m'; // #f59e0b
|
|
52
|
+
// ── @ / # 弹出窗状态 ──────────────────────────────────────────────────────
|
|
53
|
+
const mention = useMemo(() => getMention(input), [input]);
|
|
54
|
+
const mentionKey = mention ? `${mention.kind}:${mention.start}` : null;
|
|
55
|
+
const [items, setItems] = useState([]);
|
|
56
|
+
const [sel, setSel] = useState(0);
|
|
57
|
+
const [dismissed, setDismissed] = useState(null);
|
|
58
|
+
const [loadingFiles, setLoadingFiles] = useState(false);
|
|
59
|
+
// Tab 补齐弹窗 (非 @ / # 触发的普通 token 补齐): { start, items }
|
|
60
|
+
const [tabState, setTabState] = useState(null);
|
|
61
|
+
const agentCache = useRef(null);
|
|
62
|
+
const skillCache = useRef(null);
|
|
63
|
+
const pluginCache = useRef(null);
|
|
64
|
+
const fileCache = useRef(null);
|
|
65
|
+
// ── 输入历史 (↑/↓ 切换) ───────────────────────────────────────────────────
|
|
66
|
+
const historyRef = useRef([]);
|
|
67
|
+
const historyIdxRef = useRef(-1); // -1 = 正在编辑新草稿
|
|
68
|
+
const draftRef = useRef('');
|
|
69
|
+
// 加载当前 mention 的候选 (agent/command 缓存一次; file 每次打开重扫)
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (tabState) {
|
|
72
|
+
setItems(tabState.items);
|
|
73
|
+
setSel(0);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!mention || !mentionKey) {
|
|
77
|
+
setItems([]);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (dismissed === mentionKey) {
|
|
81
|
+
setItems([]);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
let cancelled = false;
|
|
85
|
+
if (mention.kind === 'agent') {
|
|
86
|
+
if (agentCache.current) {
|
|
87
|
+
setItems(agentCache.current);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
loadAgents()
|
|
91
|
+
.then(list => { agentCache.current = list; if (!cancelled)
|
|
92
|
+
setItems(list); })
|
|
93
|
+
.catch(() => { if (!cancelled)
|
|
94
|
+
setItems([]); });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (mention.kind === 'command') {
|
|
98
|
+
// 命令立即显示, 技能/插件异步合并
|
|
99
|
+
const base = loadCommands();
|
|
100
|
+
setItems(base);
|
|
101
|
+
const skillsP = skillCache.current
|
|
102
|
+
? Promise.resolve(skillCache.current)
|
|
103
|
+
: loadSkills().then(s => { skillCache.current = s; return s; });
|
|
104
|
+
const pluginsP = pluginCache.current
|
|
105
|
+
? Promise.resolve(pluginCache.current)
|
|
106
|
+
: loadPlugins().then(p => { pluginCache.current = p; return p; });
|
|
107
|
+
Promise.all([skillsP, pluginsP])
|
|
108
|
+
.then(([sk, pl]) => {
|
|
109
|
+
if (cancelled)
|
|
110
|
+
return;
|
|
111
|
+
const merged = [...base];
|
|
112
|
+
for (const it of [...sk, ...pl]) {
|
|
113
|
+
if (!merged.some(m => m.kind === it.kind && m.label === it.label))
|
|
114
|
+
merged.push(it);
|
|
115
|
+
}
|
|
116
|
+
setItems(merged);
|
|
117
|
+
})
|
|
118
|
+
.catch(() => { });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// file: 每次打开重扫 (cwd 可能变化)
|
|
122
|
+
setLoadingFiles(true);
|
|
123
|
+
loadFiles(mention.query)
|
|
124
|
+
.then(list => { if (!cancelled) {
|
|
125
|
+
fileCache.current = list;
|
|
126
|
+
setItems(list);
|
|
127
|
+
setLoadingFiles(false);
|
|
128
|
+
} })
|
|
129
|
+
.catch(() => { if (!cancelled) {
|
|
130
|
+
setItems([]);
|
|
131
|
+
setLoadingFiles(false);
|
|
132
|
+
} });
|
|
133
|
+
}
|
|
134
|
+
setSel(0);
|
|
135
|
+
return () => { cancelled = true; };
|
|
136
|
+
}, [mentionKey, dismissed, tabState]);
|
|
137
|
+
// 按查询过滤 + 排序
|
|
138
|
+
const filtered = useMemo(() => {
|
|
139
|
+
if (tabState)
|
|
140
|
+
return items; // Tab 补齐: 已按前缀过滤好
|
|
141
|
+
if (!mention)
|
|
142
|
+
return [];
|
|
143
|
+
const q = mention.query.toLowerCase();
|
|
144
|
+
if (!q)
|
|
145
|
+
return items;
|
|
146
|
+
if (mention.kind === 'file') {
|
|
147
|
+
return items
|
|
148
|
+
.filter(it => matchFileScore(it.label.toLowerCase(), q) >= 0)
|
|
149
|
+
.sort((a, b) => matchFileScore(a.label.toLowerCase(), q) - matchFileScore(b.label.toLowerCase(), q));
|
|
150
|
+
}
|
|
151
|
+
return items.filter(it => it.label.toLowerCase().includes(q));
|
|
152
|
+
}, [items, mention, tabState]);
|
|
153
|
+
const popupOpen = !!(tabState || (mention && dismissed !== mentionKey));
|
|
154
|
+
const safeSel = Math.min(sel, Math.max(0, filtered.length - 1));
|
|
155
|
+
const popupTitle = tabState ? 'Tab 补齐'
|
|
156
|
+
: mention?.kind === 'agent' ? '@ 智能体'
|
|
157
|
+
: mention?.kind === 'file' ? '# 文件'
|
|
158
|
+
: '/ 命令 · 技能 · 插件';
|
|
159
|
+
// 在指定 start 位置插入补齐文本 (函数式更新, 闭包安全)
|
|
160
|
+
const insertAt = useCallback((start, it) => {
|
|
161
|
+
setInput(cur => {
|
|
162
|
+
if (start > cur.length)
|
|
163
|
+
return cur;
|
|
164
|
+
let insertText;
|
|
165
|
+
if (it.kind === 'agent')
|
|
166
|
+
insertText = '@' + it.insert + ' ';
|
|
167
|
+
else if (it.kind === 'file')
|
|
168
|
+
insertText = '#' + it.insert + ' ';
|
|
169
|
+
else if (it.kind === 'skill')
|
|
170
|
+
insertText = 'use_skill ' + it.insert + ' ';
|
|
171
|
+
else
|
|
172
|
+
insertText = '/' + it.insert + ' ';
|
|
173
|
+
return cur.slice(0, start) + insertText;
|
|
174
|
+
});
|
|
175
|
+
// TextInput 内部 cursorOffset 在值被重写后不重置 (2026-08-05 实测),
|
|
176
|
+
// 插入后强制重挂载让光标回到末尾; 仅此一处重挂载, 避免输入丢失窗口
|
|
177
|
+
setTiKey(k => k + 1);
|
|
178
|
+
}, []);
|
|
179
|
+
// 接受当前选中项 → 替换 token 插入输入
|
|
180
|
+
// 函数式更新 + 从最新 state 重新推导 mention (useInput 闭包可能陈旧, 2026-08-05)
|
|
181
|
+
const acceptMention = useCallback((it) => {
|
|
182
|
+
if (tabState) {
|
|
183
|
+
insertAt(tabState.start, it);
|
|
184
|
+
setTabState(null);
|
|
185
|
+
setDismissed(null);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setInput(cur => {
|
|
189
|
+
const m = getMention(cur);
|
|
190
|
+
if (!m)
|
|
191
|
+
return cur;
|
|
192
|
+
let insertText;
|
|
193
|
+
if (it.kind === 'agent')
|
|
194
|
+
insertText = '@' + it.insert + ' ';
|
|
195
|
+
else if (it.kind === 'file')
|
|
196
|
+
insertText = '#' + it.insert + ' ';
|
|
197
|
+
else if (it.kind === 'skill')
|
|
198
|
+
insertText = 'use_skill ' + it.insert + ' ';
|
|
199
|
+
else
|
|
200
|
+
insertText = '/' + it.insert + ' ';
|
|
201
|
+
return cur.slice(0, m.start) + insertText;
|
|
202
|
+
});
|
|
203
|
+
setTiKey(k => k + 1);
|
|
204
|
+
setDismissed(null);
|
|
205
|
+
}, [tabState, insertAt]);
|
|
206
|
+
// Tab 命令补齐: 无触发符的普通 token 也补 (命令/技能/插件/智能体/文件)
|
|
207
|
+
const doTabCompletion = useCallback(() => {
|
|
208
|
+
const m = input.match(/(^|\s)([^\s]*)$/);
|
|
209
|
+
if (!m)
|
|
210
|
+
return;
|
|
211
|
+
const [, pre, token] = m;
|
|
212
|
+
const start = (m.index || 0) + pre.length;
|
|
213
|
+
const q = token.toLowerCase();
|
|
214
|
+
const items = [];
|
|
215
|
+
const add = (list) => {
|
|
216
|
+
for (const it of list) {
|
|
217
|
+
if (items.some(x => x.kind === it.kind && x.label === it.label))
|
|
218
|
+
continue;
|
|
219
|
+
if (it.label.toLowerCase().startsWith(q))
|
|
220
|
+
items.push(it);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
if (q) {
|
|
224
|
+
add(loadCommands());
|
|
225
|
+
if (skillCache.current)
|
|
226
|
+
add(skillCache.current);
|
|
227
|
+
if (pluginCache.current)
|
|
228
|
+
add(pluginCache.current);
|
|
229
|
+
if (agentCache.current)
|
|
230
|
+
add(agentCache.current);
|
|
231
|
+
if (fileCache.current)
|
|
232
|
+
add(fileCache.current);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// 空 token: 命令 + 技能 + 插件
|
|
236
|
+
add(loadCommands());
|
|
237
|
+
if (skillCache.current)
|
|
238
|
+
add(skillCache.current);
|
|
239
|
+
if (pluginCache.current)
|
|
240
|
+
add(pluginCache.current);
|
|
241
|
+
}
|
|
242
|
+
if (items.length === 1) {
|
|
243
|
+
insertAt(start, items[0]);
|
|
244
|
+
setTabState(null);
|
|
245
|
+
}
|
|
246
|
+
else if (items.length > 1) {
|
|
247
|
+
setTabState({ start, items });
|
|
248
|
+
setSel(0);
|
|
249
|
+
}
|
|
250
|
+
}, [input, insertAt]);
|
|
251
|
+
const [tiKey, setTiKey] = useState(0);
|
|
37
252
|
// 全局: 思考动画控制
|
|
38
253
|
useEffect(() => {
|
|
39
254
|
globalThis.__inkSetThinking = (v) => setThinking(v);
|
|
@@ -53,6 +268,14 @@ const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH
|
|
|
53
268
|
const trimmed = value.trim();
|
|
54
269
|
if (!trimmed)
|
|
55
270
|
return;
|
|
271
|
+
// 入历史 (去重最近一条, 上限 100)
|
|
272
|
+
const hist = historyRef.current;
|
|
273
|
+
if (hist[hist.length - 1] !== trimmed)
|
|
274
|
+
hist.push(trimmed);
|
|
275
|
+
if (hist.length > 100)
|
|
276
|
+
hist.shift();
|
|
277
|
+
historyIdxRef.current = -1;
|
|
278
|
+
draftRef.current = '';
|
|
56
279
|
setInput('');
|
|
57
280
|
// 用户消息由 processInput 统一通过 appendLine(renderUserMessage) 显示
|
|
58
281
|
onPrompt(trimmed);
|
|
@@ -69,6 +292,97 @@ const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH
|
|
|
69
292
|
requestExit();
|
|
70
293
|
return;
|
|
71
294
|
}
|
|
295
|
+
// ── 弹出窗打开: 全键接管 (TextInput focus=false 不处理) ──
|
|
296
|
+
if (popupOpen) {
|
|
297
|
+
if (key.upArrow) {
|
|
298
|
+
setSel(s => Math.max(0, s - 1));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (key.downArrow) {
|
|
302
|
+
setSel(s => Math.min(filtered.length - 1, s + 1));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if ((key.tab || key.return) && filtered.length > 0) {
|
|
306
|
+
const it = filtered[safeSel];
|
|
307
|
+
if (it)
|
|
308
|
+
acceptMention(it);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (key.escape) {
|
|
312
|
+
if (tabState)
|
|
313
|
+
setTabState(null);
|
|
314
|
+
else
|
|
315
|
+
setDismissed(mentionKey);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (key.backspace || key.delete) {
|
|
319
|
+
setInput(cur => cur.slice(0, -1));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
// 粘贴/连发 chunk: Ink 把一次 stdin read 当单个 keypress (2026-08-05 实测)
|
|
323
|
+
// ① 连续退格 (\x7f×N) → 删 N 个字符
|
|
324
|
+
// ② 混合 chunk (退格+控制符, 含 ESC 序列) → 退格部分生效, ESC 序列忽略
|
|
325
|
+
// ③ 可打印 chunk (CJK/粘贴) → 整串追加
|
|
326
|
+
// 全部用函数式更新 — useInput 闭包可能陈旧 (实测), 函数式取最新 state
|
|
327
|
+
if (/^\x7f+$/.test(_input)) {
|
|
328
|
+
setInput(cur => cur.slice(0, Math.max(0, cur.length - _input.length)));
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (/[\x00-\x1f\x7f]/.test(_input)) {
|
|
332
|
+
// 混合 chunk (退格+可打印): 逐字符处理; 含 ESC 序列 → 忽略整块 (箭头等由 TextInput 处理)
|
|
333
|
+
if (_input.includes('\u001b'))
|
|
334
|
+
return;
|
|
335
|
+
setInput(cur => {
|
|
336
|
+
let out = cur;
|
|
337
|
+
for (const ch of _input) {
|
|
338
|
+
if (ch === '\x7f')
|
|
339
|
+
out = out.slice(0, -1);
|
|
340
|
+
else if (/[\x00-\x1f]/.test(ch))
|
|
341
|
+
continue;
|
|
342
|
+
else
|
|
343
|
+
out += ch;
|
|
344
|
+
}
|
|
345
|
+
return out;
|
|
346
|
+
});
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (_input && !key.ctrl && !key.meta) {
|
|
350
|
+
setInput(cur => cur + _input);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
return; // 其余键忽略
|
|
354
|
+
}
|
|
355
|
+
// ── 正常模式 ──
|
|
356
|
+
// Tab 命令补齐 (无触发符的普通 token 也补)
|
|
357
|
+
if (key.tab) {
|
|
358
|
+
doTabCompletion();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
// ↑/↓ 切换输入历史 (TextInput 本身忽略 up/down, 无冲突)
|
|
362
|
+
if (key.upArrow) {
|
|
363
|
+
const hist = historyRef.current;
|
|
364
|
+
if (hist.length === 0)
|
|
365
|
+
return;
|
|
366
|
+
if (historyIdxRef.current === -1)
|
|
367
|
+
draftRef.current = input;
|
|
368
|
+
if (historyIdxRef.current < hist.length - 1) {
|
|
369
|
+
historyIdxRef.current += 1;
|
|
370
|
+
setInput(hist[hist.length - 1 - historyIdxRef.current]);
|
|
371
|
+
setTiKey(k => k + 1);
|
|
372
|
+
}
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (key.downArrow) {
|
|
376
|
+
if (historyIdxRef.current === -1)
|
|
377
|
+
return;
|
|
378
|
+
historyIdxRef.current -= 1;
|
|
379
|
+
if (historyIdxRef.current === -1)
|
|
380
|
+
setInput(draftRef.current);
|
|
381
|
+
else
|
|
382
|
+
setInput(historyRef.current[historyRef.current.length - 1 - historyIdxRef.current]);
|
|
383
|
+
setTiKey(k => k + 1);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
72
386
|
// 双击 Esc 退出当前进程: 第一击提示, 500ms 内第二击退出
|
|
73
387
|
if (key.escape) {
|
|
74
388
|
const now = Date.now();
|
|
@@ -80,6 +394,21 @@ const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH
|
|
|
80
394
|
inkAppendLine(`${C_WARN_ANSI}⚠ 再按一次 Esc 退出当前进程\x1b[0m`);
|
|
81
395
|
}
|
|
82
396
|
}
|
|
397
|
+
// 防御: 控制字符 chunk (TextInput 会把整 chunk 当字符追加, 2026-08-05 实测)
|
|
398
|
+
// setTimeout(0) 保证我们的纠正落在 TextInput 的 onChange 之后 (无论监听器顺序)
|
|
399
|
+
// \x7f×N → 先剥掉 TextInput 追加的垃圾, 再删 N 个真实字符
|
|
400
|
+
if (/^\x7f+$/.test(_input)) {
|
|
401
|
+
const n = _input.length;
|
|
402
|
+
setTimeout(() => setInput(cur => {
|
|
403
|
+
const cleaned = cur.replace(/[\x00-\x1f\x7f]+$/, '');
|
|
404
|
+
return cleaned.slice(0, Math.max(0, cleaned.length - n));
|
|
405
|
+
}), 0);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (/[\x00-\x1f\x7f]/.test(_input)) {
|
|
409
|
+
setTimeout(() => setInput(cur => cur.replace(/[\x00-\x1f\x7f]+$/, '')), 0);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
83
412
|
// TextInput handles actual input; useInput only for Ctrl+C / Esc
|
|
84
413
|
});
|
|
85
414
|
// 自动更新状态栏 (每秒)
|
|
@@ -91,6 +420,19 @@ const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH
|
|
|
91
420
|
}, 1000);
|
|
92
421
|
return () => clearInterval(timer);
|
|
93
422
|
}, [getStatusUpdate]);
|
|
423
|
+
// 调试/测试钩子: 输入变化时通知外部 (pty 测试用)
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
globalThis.__inkOnInput?.(input);
|
|
426
|
+
}, [input]);
|
|
427
|
+
// 调试/测试钩子: 弹出窗状态 (pty 测试用)
|
|
428
|
+
useEffect(() => {
|
|
429
|
+
globalThis.__inkOnPopup?.({
|
|
430
|
+
open: popupOpen,
|
|
431
|
+
key: mentionKey,
|
|
432
|
+
count: filtered.length,
|
|
433
|
+
items: filtered.slice(0, 5).map(i => i.kind + ':' + i.label),
|
|
434
|
+
});
|
|
435
|
+
}, [popupOpen, mentionKey, filtered]);
|
|
94
436
|
// 思考动画 — kaomoji 旋转
|
|
95
437
|
const KAOMOJI = ['(`・ω・´)', '(´・_・`)', '(。•́︿•̀。)', 'ᕙ(▀̿̿Ĺ̯̿̿▀̿ ̿)ᕗ', '(◕‿◕)'];
|
|
96
438
|
useEffect(() => {
|
|
@@ -101,8 +443,9 @@ const InkApp = ({ onPrompt, initialStatus, getStatusUpdate, terminalW, terminalH
|
|
|
101
443
|
}, 600);
|
|
102
444
|
return () => clearInterval(timer);
|
|
103
445
|
}, [thinking]);
|
|
104
|
-
return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsxs(Box, { flexGrow: 1, flexDirection: "column", justifyContent: "flex-start", children: [_jsx(LogoBox, { width: terminalW }), _jsx(Messages, { msgs: msgs }), thinking && (_jsx(Box, { children: _jsxs(Text, { color: "yellow", children: [KAOMOJI[thinkingIdx.current], " \u601D\u8003\u4E2D..."] }) }))] }), _jsx(Box, { children: _jsx(Text, { bold: true, color: "white", children: '─'.repeat(terminalW) }) }), _jsx(Box, { children: _jsx(Text, { children: status }) }), _jsx(Box, { children: _jsx(Text, { bold: true, color: "white", children: '─'.repeat(terminalW) }) }), _jsxs(Box, { children: [_jsx(Text, { bold: true, color: "green", children: "\u276F " }), _jsx(TextInput, { value: input, onChange: setInput, onSubmit: onSubmit, placeholder: "\u8F93\u5165\u6D88\u606F...
|
|
446
|
+
return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsxs(Box, { flexGrow: 1, flexDirection: "column", justifyContent: "flex-start", children: [_jsx(LogoBox, { width: terminalW }), _jsx(Messages, { msgs: msgs }), thinking && (_jsx(Box, { children: _jsxs(Text, { color: "yellow", children: [KAOMOJI[thinkingIdx.current], " \u601D\u8003\u4E2D..."] }) }))] }), _jsx(Box, { children: _jsx(Text, { bold: true, color: "white", children: '─'.repeat(terminalW) }) }), _jsx(Box, { children: _jsx(Text, { children: status }) }), _jsx(Box, { children: _jsx(Text, { bold: true, color: "white", children: '─'.repeat(terminalW) }) }), popupOpen && (tabState || mention) && (_jsx(MentionPopup, { title: popupTitle, items: filtered, sel: safeSel, width: terminalW, loading: loadingFiles })), _jsxs(Box, { children: [_jsx(Text, { bold: true, color: "green", children: "\u276F " }), _jsx(TextInput, { value: input, onChange: setInput, onSubmit: onSubmit, focus: !popupOpen, placeholder: "\u8F93\u5165\u6D88\u606F... @\u667A\u80FD\u4F53 /\u547D\u4EE4 #\u6587\u4EF6 \u00B7 Esc \u53CC\u51FB\u9000\u51FA \u00B7 /queue \u6392\u961F \u00B7 !\u7EC8\u7AEF\u547D\u4EE4" }, tiKey)] }), _jsx(Box, { children: _jsx(Text, { bold: true, color: "white", children: '─'.repeat(terminalW) }) })] }));
|
|
105
447
|
};
|
|
448
|
+
export { InkApp };
|
|
106
449
|
// ─── 启动 ────────────────────────────────────────────────────────────────────
|
|
107
450
|
let _inkInstance = null;
|
|
108
451
|
export function startInk(onPrompt, initialStatus, getStatusUpdate) {
|