@bolloon/bolloon-agent 0.3.29 → 0.3.31

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.
Files changed (217) hide show
  1. package/dist/agents/pi-sdk-tools.js +128 -0
  2. package/dist/constraint-runtime/_archive_helper.d.ts +1 -0
  3. package/dist/constraint-runtime/_archive_helper.js +9 -0
  4. package/dist/constraint-runtime/agent/coordinator.d.ts +19 -0
  5. package/dist/constraint-runtime/agent/coordinator.js +48 -0
  6. package/dist/constraint-runtime/agent/index.d.ts +1 -0
  7. package/dist/constraint-runtime/agent/index.js +1 -0
  8. package/dist/constraint-runtime/assistant/index.d.ts +11 -0
  9. package/dist/constraint-runtime/assistant/index.js +12 -0
  10. package/dist/constraint-runtime/bootstrap/index.d.ts +11 -0
  11. package/dist/constraint-runtime/bootstrap/index.js +12 -0
  12. package/dist/constraint-runtime/bootstrap_graph.d.ts +4 -0
  13. package/dist/constraint-runtime/bootstrap_graph.js +13 -0
  14. package/dist/constraint-runtime/bridge/index.d.ts +11 -0
  15. package/dist/constraint-runtime/bridge/index.js +12 -0
  16. package/dist/constraint-runtime/buddy/index.d.ts +11 -0
  17. package/dist/constraint-runtime/buddy/index.js +12 -0
  18. package/dist/constraint-runtime/cli/index.d.ts +11 -0
  19. package/dist/constraint-runtime/cli/index.js +12 -0
  20. package/dist/constraint-runtime/command_graph.d.ts +7 -0
  21. package/dist/constraint-runtime/command_graph.js +10 -0
  22. package/dist/constraint-runtime/commands.d.ts +15 -0
  23. package/dist/constraint-runtime/commands.js +60 -0
  24. package/dist/constraint-runtime/components/index.d.ts +11 -0
  25. package/dist/constraint-runtime/components/index.js +12 -0
  26. package/dist/constraint-runtime/constants/index.d.ts +11 -0
  27. package/dist/constraint-runtime/constants/index.js +12 -0
  28. package/dist/constraint-runtime/constraint/budget.d.ts +11 -0
  29. package/dist/constraint-runtime/constraint/budget.js +22 -0
  30. package/dist/constraint-runtime/constraint/index.d.ts +3 -0
  31. package/dist/constraint-runtime/constraint/index.js +2 -0
  32. package/dist/constraint-runtime/constraint/permission.d.ts +9 -0
  33. package/dist/constraint-runtime/constraint/permission.js +20 -0
  34. package/dist/constraint-runtime/context.d.ts +12 -0
  35. package/dist/constraint-runtime/context.js +30 -0
  36. package/dist/constraint-runtime/coordinator/index.d.ts +11 -0
  37. package/dist/constraint-runtime/coordinator/index.js +12 -0
  38. package/dist/constraint-runtime/cost_hook.d.ts +2 -0
  39. package/dist/constraint-runtime/cost_hook.js +4 -0
  40. package/dist/constraint-runtime/cost_tracker.d.ts +5 -0
  41. package/dist/constraint-runtime/cost_tracker.js +8 -0
  42. package/dist/constraint-runtime/deferred_init.d.ts +8 -0
  43. package/dist/constraint-runtime/deferred_init.js +10 -0
  44. package/dist/constraint-runtime/direct_modes.d.ts +7 -0
  45. package/dist/constraint-runtime/direct_modes.js +6 -0
  46. package/dist/constraint-runtime/dynamic-tool-loader.d.ts +13 -0
  47. package/dist/constraint-runtime/dynamic-tool-loader.js +85 -0
  48. package/dist/constraint-runtime/entrypoints/index.d.ts +11 -0
  49. package/dist/constraint-runtime/entrypoints/index.js +12 -0
  50. package/dist/constraint-runtime/execution_registry.d.ts +20 -0
  51. package/dist/constraint-runtime/execution_registry.js +44 -0
  52. package/dist/constraint-runtime/history.d.ts +9 -0
  53. package/dist/constraint-runtime/history.js +9 -0
  54. package/dist/constraint-runtime/hooks/index.d.ts +11 -0
  55. package/dist/constraint-runtime/hooks/index.js +12 -0
  56. package/dist/constraint-runtime/index.d.ts +26 -0
  57. package/dist/constraint-runtime/index.js +26 -0
  58. package/dist/constraint-runtime/ink.d.ts +1 -0
  59. package/dist/constraint-runtime/ink.js +4 -0
  60. package/dist/constraint-runtime/keybindings/index.d.ts +11 -0
  61. package/dist/constraint-runtime/keybindings/index.js +12 -0
  62. package/dist/constraint-runtime/memdir/index.d.ts +11 -0
  63. package/dist/constraint-runtime/memdir/index.js +12 -0
  64. package/dist/constraint-runtime/migrations/index.d.ts +11 -0
  65. package/dist/constraint-runtime/migrations/index.js +12 -0
  66. package/dist/constraint-runtime/models.d.ts +42 -0
  67. package/dist/constraint-runtime/models.js +1 -0
  68. package/dist/constraint-runtime/moreright/index.d.ts +11 -0
  69. package/dist/constraint-runtime/moreright/index.js +12 -0
  70. package/dist/constraint-runtime/native_ts/index.d.ts +11 -0
  71. package/dist/constraint-runtime/native_ts/index.js +12 -0
  72. package/dist/constraint-runtime/output_styles/index.d.ts +11 -0
  73. package/dist/constraint-runtime/output_styles/index.js +12 -0
  74. package/dist/constraint-runtime/parity_audit.d.ts +11 -0
  75. package/dist/constraint-runtime/parity_audit.js +12 -0
  76. package/dist/constraint-runtime/plugins/index.d.ts +11 -0
  77. package/dist/constraint-runtime/plugins/index.js +12 -0
  78. package/dist/constraint-runtime/port_manifest.d.ts +7 -0
  79. package/dist/constraint-runtime/port_manifest.js +11 -0
  80. package/dist/constraint-runtime/prefetch.d.ts +8 -0
  81. package/dist/constraint-runtime/prefetch.js +9 -0
  82. package/dist/constraint-runtime/query.d.ts +6 -0
  83. package/dist/constraint-runtime/query.js +1 -0
  84. package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
  85. package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
  86. package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
  87. package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
  88. package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
  89. package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
  90. package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
  91. package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
  92. package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
  93. package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
  94. package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
  95. package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
  96. package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
  97. package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
  98. package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
  99. package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
  100. package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
  101. package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
  102. package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
  103. package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
  104. package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
  105. package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
  106. package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
  107. package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
  108. package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
  109. package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
  110. package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
  111. package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
  112. package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
  113. package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
  114. package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
  115. package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
  116. package/dist/constraint-runtime/remote/index.d.ts +11 -0
  117. package/dist/constraint-runtime/remote/index.js +12 -0
  118. package/dist/constraint-runtime/remote_runtime.d.ts +8 -0
  119. package/dist/constraint-runtime/remote_runtime.js +9 -0
  120. package/dist/constraint-runtime/runtime/index.d.ts +1 -0
  121. package/dist/constraint-runtime/runtime/index.js +1 -0
  122. package/dist/constraint-runtime/runtime/session.d.ts +22 -0
  123. package/dist/constraint-runtime/runtime/session.js +35 -0
  124. package/dist/constraint-runtime/schemas/index.d.ts +11 -0
  125. package/dist/constraint-runtime/schemas/index.js +12 -0
  126. package/dist/constraint-runtime/screens/index.d.ts +11 -0
  127. package/dist/constraint-runtime/screens/index.js +12 -0
  128. package/dist/constraint-runtime/server/index.d.ts +11 -0
  129. package/dist/constraint-runtime/server/index.js +12 -0
  130. package/dist/constraint-runtime/services/index.d.ts +11 -0
  131. package/dist/constraint-runtime/services/index.js +12 -0
  132. package/dist/constraint-runtime/session_store.d.ts +8 -0
  133. package/dist/constraint-runtime/session_store.js +22 -0
  134. package/dist/constraint-runtime/setup.d.ts +19 -0
  135. package/dist/constraint-runtime/setup.js +30 -0
  136. package/dist/constraint-runtime/skills/index.d.ts +1 -0
  137. package/dist/constraint-runtime/skills/index.js +1 -0
  138. package/dist/constraint-runtime/skills/skill-registry.d.ts +14 -0
  139. package/dist/constraint-runtime/skills/skill-registry.js +28 -0
  140. package/dist/constraint-runtime/state/index.d.ts +11 -0
  141. package/dist/constraint-runtime/state/index.js +12 -0
  142. package/dist/constraint-runtime/system_init.d.ts +1 -0
  143. package/dist/constraint-runtime/system_init.js +20 -0
  144. package/dist/constraint-runtime/thinking/engine.d.ts +20 -0
  145. package/dist/constraint-runtime/thinking/engine.js +42 -0
  146. package/dist/constraint-runtime/thinking/index.d.ts +1 -0
  147. package/dist/constraint-runtime/thinking/index.js +1 -0
  148. package/dist/constraint-runtime/tool_pool.d.ts +8 -0
  149. package/dist/constraint-runtime/tool_pool.js +8 -0
  150. package/dist/constraint-runtime/tools/OpenCLI/execAdapter.d.ts +9 -0
  151. package/dist/constraint-runtime/tools/OpenCLI/execAdapter.js +7 -0
  152. package/dist/constraint-runtime/tools/OpenCLI/listAdapters.d.ts +5 -0
  153. package/dist/constraint-runtime/tools/OpenCLI/listAdapters.js +7 -0
  154. package/dist/constraint-runtime/tools/OpenCLI/runCommand.d.ts +10 -0
  155. package/dist/constraint-runtime/tools/OpenCLI/runCommand.js +7 -0
  156. package/dist/constraint-runtime/tools/PolymarketSDK/cancelOrder.d.ts +17 -0
  157. package/dist/constraint-runtime/{src/tools → tools}/PolymarketSDK/cancelOrder.js +4 -7
  158. package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.d.ts +50 -0
  159. package/dist/constraint-runtime/tools/PolymarketSDK/clobShared.js +78 -0
  160. package/dist/constraint-runtime/tools/PolymarketSDK/createOrder.d.ts +31 -0
  161. package/dist/constraint-runtime/{src/tools → tools}/PolymarketSDK/createOrder.js +9 -12
  162. package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.d.ts +10 -0
  163. package/dist/constraint-runtime/tools/PolymarketSDK/getMarket.js +16 -0
  164. package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.d.ts +16 -0
  165. package/dist/constraint-runtime/tools/PolymarketSDK/getOrders.js +25 -0
  166. package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.d.ts +23 -0
  167. package/dist/constraint-runtime/tools/PolymarketSDK/listMarkets.js +24 -0
  168. package/dist/constraint-runtime/tools/SafeSDK/confirmTransaction.d.ts +10 -0
  169. package/dist/constraint-runtime/tools/SafeSDK/confirmTransaction.js +6 -0
  170. package/dist/constraint-runtime/tools/SafeSDK/createTransaction.d.ts +14 -0
  171. package/dist/constraint-runtime/tools/SafeSDK/createTransaction.js +8 -0
  172. package/dist/constraint-runtime/tools/SafeSDK/deploySafe.d.ts +10 -0
  173. package/dist/constraint-runtime/tools/SafeSDK/executeTransaction.d.ts +9 -0
  174. package/dist/constraint-runtime/tools/SafeSDK/executeTransaction.js +6 -0
  175. package/dist/constraint-runtime/tools/SafeSDK/getBalance.d.ts +7 -0
  176. package/dist/constraint-runtime/tools/SafeSDK/getBalance.js +6 -0
  177. package/dist/constraint-runtime/tools/SafeSDK/getPendingTransactions.d.ts +7 -0
  178. package/dist/constraint-runtime/tools/SafeSDK/getPendingTransactions.js +6 -0
  179. package/dist/constraint-runtime/tools/SafeSDK/proposeTransaction.d.ts +11 -0
  180. package/dist/constraint-runtime/tools/SafeSDK/proposeTransaction.js +6 -0
  181. package/dist/constraint-runtime/tools/WalletTools/autoPay.d.ts +26 -0
  182. package/dist/constraint-runtime/tools/WalletTools/createWallet.d.ts +7 -0
  183. package/dist/constraint-runtime/tools/WalletTools/getBalance.d.ts +11 -0
  184. package/dist/constraint-runtime/tools/WalletTools/importWallet.d.ts +10 -0
  185. package/dist/constraint-runtime/tools/WalletTools/sendTransaction.d.ts +20 -0
  186. package/dist/constraint-runtime/tools/WalletTools/signMessage.d.ts +10 -0
  187. package/dist/constraint-runtime/tools/WalletTools/transferToken.d.ts +17 -0
  188. package/dist/constraint-runtime/tools.d.ts +14 -0
  189. package/dist/constraint-runtime/tools.js +80 -0
  190. package/dist/constraint-runtime/transcript.d.ts +8 -0
  191. package/dist/constraint-runtime/transcript.js +19 -0
  192. package/dist/constraint-runtime/types/index.d.ts +11 -0
  193. package/dist/constraint-runtime/types/index.js +12 -0
  194. package/dist/constraint-runtime/upstream_proxy/index.d.ts +11 -0
  195. package/dist/constraint-runtime/upstream_proxy/index.js +12 -0
  196. package/dist/constraint-runtime/utils/index.d.ts +11 -0
  197. package/dist/constraint-runtime/utils/index.js +12 -0
  198. package/dist/constraint-runtime/vim/index.d.ts +11 -0
  199. package/dist/constraint-runtime/vim/index.js +12 -0
  200. package/dist/constraint-runtime/voice/index.d.ts +11 -0
  201. package/dist/constraint-runtime/voice/index.js +12 -0
  202. package/dist/llm/config-store.js +39 -28
  203. package/dist/llm/pi-ai.js +83 -36
  204. package/dist/security/tool-gate.js +4 -18
  205. package/package.json +3 -2
  206. package/dist/constraint-runtime/src/tools/PolymarketSDK/clobShared.js +0 -104
  207. package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +0 -5
  208. package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +0 -19
  209. package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +0 -4
  210. /package/dist/constraint-runtime/{src/tools → tools}/SafeSDK/deploySafe.js +0 -0
  211. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/autoPay.js +0 -0
  212. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/createWallet.js +0 -0
  213. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/getBalance.js +0 -0
  214. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/importWallet.js +0 -0
  215. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/sendTransaction.js +0 -0
  216. /package/dist/constraint-runtime/{src/tools → tools}/WalletTools/signMessage.js +0 -0
  217. /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(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/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. 支持过滤和范围.',
@@ -0,0 +1 @@
1
+ export declare function loadArchiveMetadata(packageName: string): Record<string, unknown>;
@@ -0,0 +1,9 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+ export function loadArchiveMetadata(packageName) {
7
+ const snapshotPath = path.join(__dirname, 'reference_data', 'subsystems', `${packageName}.json`);
8
+ return JSON.parse(fs.readFileSync(snapshotPath, 'utf-8'));
9
+ }
@@ -0,0 +1,19 @@
1
+ export interface SubTask {
2
+ id: string;
3
+ description: string;
4
+ priority: number;
5
+ }
6
+ export interface AgentResult {
7
+ taskId: string;
8
+ output: string;
9
+ success: boolean;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export declare class AgentCoordinator {
13
+ private engine;
14
+ constructor(maxDepth?: number);
15
+ dispatch(prompt: string, parallelCount?: number): Promise<AgentResult[]>;
16
+ private splitTask;
17
+ private executeTask;
18
+ private aggregate;
19
+ }
@@ -0,0 +1,48 @@
1
+ import { DeepThinkingEngine } from '../thinking/engine.js';
2
+ export class AgentCoordinator {
3
+ engine;
4
+ constructor(maxDepth = 3) {
5
+ this.engine = new DeepThinkingEngine(maxDepth);
6
+ }
7
+ async dispatch(prompt, parallelCount = 3) {
8
+ const tasks = this.splitTask(prompt, parallelCount);
9
+ const results = await Promise.all(tasks.map(task => this.executeTask(task)));
10
+ return this.aggregate(results);
11
+ }
12
+ splitTask(prompt, count) {
13
+ const words = prompt.split(/\s+/);
14
+ const chunkSize = Math.ceil(words.length / count);
15
+ const chunks = [];
16
+ for (let i = 0; i < count; i++) {
17
+ const chunk = words.slice(i * chunkSize, (i + 1) * chunkSize).join(' ');
18
+ if (chunk) {
19
+ chunks.push({
20
+ id: `task-${i}`,
21
+ description: chunk,
22
+ priority: i
23
+ });
24
+ }
25
+ }
26
+ return chunks;
27
+ }
28
+ async executeTask(task) {
29
+ try {
30
+ const thinkResult = await this.engine.think(task.description);
31
+ return {
32
+ taskId: task.id,
33
+ output: thinkResult.finalOutput,
34
+ success: true
35
+ };
36
+ }
37
+ catch (error) {
38
+ return {
39
+ taskId: task.id,
40
+ output: String(error),
41
+ success: false
42
+ };
43
+ }
44
+ }
45
+ aggregate(results) {
46
+ return results.sort((a, b) => a.taskId.localeCompare(b.taskId));
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ export { AgentCoordinator, type SubTask, type AgentResult } from './coordinator.js';
@@ -0,0 +1 @@
1
+ export { AgentCoordinator } from './coordinator.js';
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('assistant');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('bootstrap');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,4 @@
1
+ export interface BootstrapGraph {
2
+ stages: string[];
3
+ }
4
+ export declare function buildBootstrapGraph(): BootstrapGraph;
@@ -0,0 +1,13 @@
1
+ export function buildBootstrapGraph() {
2
+ return {
3
+ stages: [
4
+ 'top-level prefetch side effects',
5
+ 'warning handler and environment guards',
6
+ 'CLI parser and pre-action trust gate',
7
+ 'setup() + commands/agents parallel load',
8
+ 'deferred init after trust',
9
+ 'mode routing: local / remote / ssh / teleport / direct-connect / deep-link',
10
+ 'query engine submit loop',
11
+ ],
12
+ };
13
+ }
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('bridge');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('buddy');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('cli');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,7 @@
1
+ import { PortingModule } from './models.js';
2
+ export interface CommandGraph {
3
+ builtins: PortingModule[];
4
+ pluginLike: PortingModule[];
5
+ skillLike: PortingModule[];
6
+ }
7
+ export declare function buildCommandGraph(): CommandGraph;
@@ -0,0 +1,10 @@
1
+ import { getCommands } from './commands.js';
2
+ export function buildCommandGraph() {
3
+ const commands = getCommands();
4
+ return {
5
+ builtins: commands.filter(m => !m.sourceHint.toLowerCase().includes('plugin') &&
6
+ !m.sourceHint.toLowerCase().includes('skills')),
7
+ pluginLike: commands.filter(m => m.sourceHint.toLowerCase().includes('plugin')),
8
+ skillLike: commands.filter(m => m.sourceHint.toLowerCase().includes('skills')),
9
+ };
10
+ }
@@ -0,0 +1,15 @@
1
+ import { PortingModule } from './models.js';
2
+ export interface CommandExecution {
3
+ name: string;
4
+ sourceHint: string;
5
+ prompt: string;
6
+ handled: boolean;
7
+ message: string;
8
+ }
9
+ export declare const PORTED_COMMANDS: PortingModule[];
10
+ export { PortingModule };
11
+ export declare function builtInCommandNames(): Set<string>;
12
+ export declare function getCommand(name: string): PortingModule | undefined;
13
+ export declare function getCommands(includePluginCommands?: boolean, includeSkillCommands?: boolean): PortingModule[];
14
+ export declare function findCommands(query: string, limit?: number): PortingModule[];
15
+ export declare function executeCommand(name: string, prompt?: string): CommandExecution;
@@ -0,0 +1,60 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+ const SNAPSHOT_PATH = path.join(__dirname, 'reference_data', 'commands_snapshot.json');
7
+ function loadCommandSnapshot() {
8
+ try {
9
+ if (!fs.existsSync(SNAPSHOT_PATH)) {
10
+ console.warn(`[commands] Snapshot not found: ${SNAPSHOT_PATH}, using empty list`);
11
+ return [];
12
+ }
13
+ const raw = JSON.parse(fs.readFileSync(SNAPSHOT_PATH, 'utf-8'));
14
+ return raw.map((e) => ({
15
+ name: e.name,
16
+ responsibility: e.responsibility,
17
+ sourceHint: e.source_hint,
18
+ status: 'mirrored',
19
+ }));
20
+ }
21
+ catch (error) {
22
+ console.warn(`[commands] Failed to load snapshot: ${error}, using empty list`);
23
+ return [];
24
+ }
25
+ }
26
+ export const PORTED_COMMANDS = loadCommandSnapshot();
27
+ export function builtInCommandNames() {
28
+ return new Set(PORTED_COMMANDS.map(m => m.name));
29
+ }
30
+ export function getCommand(name) {
31
+ const needle = name.toLowerCase();
32
+ return PORTED_COMMANDS.find(m => m.name.toLowerCase() === needle);
33
+ }
34
+ export function getCommands(includePluginCommands = true, includeSkillCommands = true) {
35
+ let commands = [...PORTED_COMMANDS];
36
+ if (!includePluginCommands) {
37
+ commands = commands.filter(m => !m.sourceHint.toLowerCase().includes('plugin'));
38
+ }
39
+ if (!includeSkillCommands) {
40
+ commands = commands.filter(m => !m.sourceHint.toLowerCase().includes('skills'));
41
+ }
42
+ return commands;
43
+ }
44
+ export function findCommands(query, limit = 20) {
45
+ const needle = query.toLowerCase();
46
+ return PORTED_COMMANDS.filter(m => m.name.toLowerCase().includes(needle) || m.sourceHint.toLowerCase().includes(needle)).slice(0, limit);
47
+ }
48
+ export function executeCommand(name, prompt = '') {
49
+ const module = getCommand(name);
50
+ if (!module) {
51
+ return { name, sourceHint: '', prompt, handled: false, message: `Unknown mirrored command: ${name}` };
52
+ }
53
+ return {
54
+ name: module.name,
55
+ sourceHint: module.sourceHint,
56
+ prompt,
57
+ handled: true,
58
+ message: `Mirrored command '${module.name}' from ${module.sourceHint} would handle prompt.`,
59
+ };
60
+ }
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('components');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,11 @@
1
+ export declare const ARCHIVE_NAME: string;
2
+ export declare const MODULE_COUNT: number;
3
+ export declare const SAMPLE_FILES: string[];
4
+ export declare const PORTING_NOTE: string;
5
+ declare const _default: {
6
+ ARCHIVE_NAME: string;
7
+ MODULE_COUNT: number;
8
+ PORTING_NOTE: string;
9
+ SAMPLE_FILES: string[];
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { loadArchiveMetadata } from '../_archive_helper.js';
2
+ const SNAPSHOT = loadArchiveMetadata('constants');
3
+ export const ARCHIVE_NAME = SNAPSHOT['archive_name'];
4
+ export const MODULE_COUNT = SNAPSHOT['module_count'];
5
+ export const SAMPLE_FILES = SNAPSHOT['sample_files'];
6
+ export const PORTING_NOTE = `Python placeholder package for '${ARCHIVE_NAME}' with ${MODULE_COUNT} archived module references.`;
7
+ export default {
8
+ ARCHIVE_NAME,
9
+ MODULE_COUNT,
10
+ PORTING_NOTE,
11
+ SAMPLE_FILES,
12
+ };
@@ -0,0 +1,11 @@
1
+ import { UsageSummary } from '../models.js';
2
+ export declare class BudgetTracker {
3
+ maxBudgetTokens: number;
4
+ maxTurns: number;
5
+ compactAfterTurns: number;
6
+ constructor(maxBudgetTokens?: number, maxTurns?: number, compactAfterTurns?: number);
7
+ addTurn(inputTokens: number, outputTokens: number): UsageSummary;
8
+ isBudgetExceeded(usage: UsageSummary): boolean;
9
+ isTurnLimitExceeded(currentTurns: number): boolean;
10
+ shouldCompact(turnCount: number): boolean;
11
+ }
@@ -0,0 +1,22 @@
1
+ export class BudgetTracker {
2
+ maxBudgetTokens;
3
+ maxTurns;
4
+ compactAfterTurns;
5
+ constructor(maxBudgetTokens = 2000, maxTurns = 8, compactAfterTurns = 12) {
6
+ this.maxBudgetTokens = maxBudgetTokens;
7
+ this.maxTurns = maxTurns;
8
+ this.compactAfterTurns = compactAfterTurns;
9
+ }
10
+ addTurn(inputTokens, outputTokens) {
11
+ return { inputTokens, outputTokens };
12
+ }
13
+ isBudgetExceeded(usage) {
14
+ return usage.inputTokens + usage.outputTokens > this.maxBudgetTokens;
15
+ }
16
+ isTurnLimitExceeded(currentTurns) {
17
+ return currentTurns >= this.maxTurns;
18
+ }
19
+ shouldCompact(turnCount) {
20
+ return turnCount > this.compactAfterTurns;
21
+ }
22
+ }
@@ -0,0 +1,3 @@
1
+ export { ToolPermissionContext } from './permission.js';
2
+ export { BudgetTracker } from './budget.js';
3
+ export type { UsageSummary } from '../models.js';
@@ -0,0 +1,2 @@
1
+ export { ToolPermissionContext } from './permission.js';
2
+ export { BudgetTracker } from './budget.js';
@@ -0,0 +1,9 @@
1
+ import { PermissionDenial } from '../models.js';
2
+ export declare class ToolPermissionContext {
3
+ private denyTools;
4
+ private denyPrefixes;
5
+ private constructor();
6
+ static fromIterables(denyTools?: string[], denyPrefixes?: string[]): ToolPermissionContext;
7
+ blocks(name: string): boolean;
8
+ createDenial(toolName: string, reason: string): PermissionDenial;
9
+ }
@@ -0,0 +1,20 @@
1
+ export class ToolPermissionContext {
2
+ denyTools;
3
+ denyPrefixes;
4
+ constructor(denyTools, denyPrefixes) {
5
+ this.denyTools = denyTools;
6
+ this.denyPrefixes = denyPrefixes;
7
+ }
8
+ static fromIterables(denyTools = [], denyPrefixes = []) {
9
+ return new ToolPermissionContext(new Set(denyTools.map(t => t.toLowerCase())), denyPrefixes);
10
+ }
11
+ blocks(name) {
12
+ const lower = name.toLowerCase();
13
+ if (this.denyTools.has(lower))
14
+ return true;
15
+ return this.denyPrefixes.some(p => lower.startsWith(p.toLowerCase()));
16
+ }
17
+ createDenial(toolName, reason) {
18
+ return { toolName, reason };
19
+ }
20
+ }
@@ -0,0 +1,12 @@
1
+ export interface PortContext {
2
+ sourceRoot: string;
3
+ testsRoot: string;
4
+ assetsRoot: string;
5
+ archiveRoot: string;
6
+ pythonFileCount: number;
7
+ testFileCount: number;
8
+ assetFileCount: number;
9
+ archiveAvailable: boolean;
10
+ }
11
+ export declare function buildPortContext(base?: string): PortContext;
12
+ export declare function renderContext(context: PortContext): string;
@@ -0,0 +1,30 @@
1
+ import * as path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ const __filename = fileURLToPath(import.meta.url);
4
+ const __dirname = path.dirname(__filename);
5
+ export function buildPortContext(base) {
6
+ const root = base || __dirname;
7
+ const srcRoot = path.join(root, 'src');
8
+ const testsRoot = path.join(root, 'tests');
9
+ const assetsRoot = path.join(root, 'assets');
10
+ const archiveRoot = path.join(root, 'archive');
11
+ return {
12
+ sourceRoot: srcRoot,
13
+ testsRoot: testsRoot,
14
+ assetsRoot: assetsRoot,
15
+ archiveRoot: archiveRoot,
16
+ pythonFileCount: 0,
17
+ testFileCount: 0,
18
+ assetFileCount: 0,
19
+ archiveAvailable: false,
20
+ };
21
+ }
22
+ export function renderContext(context) {
23
+ return [
24
+ `Source root: ${context.sourceRoot}`,
25
+ `Test root: ${context.testsRoot}`,
26
+ `Assets root: ${context.assetsRoot}`,
27
+ `Archive root: ${context.archiveRoot}`,
28
+ `Archive available: ${context.archiveAvailable}`,
29
+ ].join('\n');
30
+ }