foliko 1.0.75 → 1.0.77

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 (89) hide show
  1. package/.claude/settings.local.json +159 -157
  2. package/.env.example +3 -1
  3. package/cli/bin/foliko.js +12 -12
  4. package/cli/src/commands/chat.js +143 -143
  5. package/cli/src/commands/list.js +93 -93
  6. package/cli/src/index.js +75 -75
  7. package/cli/src/ui/chat-ui.js +201 -201
  8. package/cli/src/utils/ansi.js +40 -40
  9. package/cli/src/utils/markdown.js +292 -292
  10. package/examples/ambient-example.js +194 -194
  11. package/examples/basic.js +115 -115
  12. package/examples/bootstrap.js +121 -121
  13. package/examples/mcp-example.js +56 -56
  14. package/examples/skill-example.js +49 -49
  15. package/examples/test-chat.js +137 -137
  16. package/examples/test-mcp.js +85 -85
  17. package/examples/test-reload.js +59 -59
  18. package/examples/test-telegram.js +50 -50
  19. package/examples/test-tg-bot.js +45 -45
  20. package/examples/test-tg-simple.js +47 -47
  21. package/examples/test-tg.js +62 -62
  22. package/examples/test-think.js +43 -43
  23. package/examples/test-web-plugin.js +103 -103
  24. package/examples/test-weixin-feishu.js +103 -103
  25. package/examples/workflow.js +158 -158
  26. package/package.json +81 -81
  27. package/plugins/ai-plugin.js +102 -102
  28. package/plugins/ambient-agent/EventWatcher.js +113 -113
  29. package/plugins/ambient-agent/ExplorerLoop.js +640 -640
  30. package/plugins/ambient-agent/GoalManager.js +197 -197
  31. package/plugins/ambient-agent/Reflector.js +95 -95
  32. package/plugins/ambient-agent/StateStore.js +90 -90
  33. package/plugins/ambient-agent/constants.js +101 -101
  34. package/plugins/ambient-agent/index.js +579 -579
  35. package/plugins/audit-plugin.js +187 -187
  36. package/plugins/default-plugins.js +662 -662
  37. package/plugins/email/constants.js +64 -64
  38. package/plugins/email/handlers.js +461 -461
  39. package/plugins/email/index.js +278 -278
  40. package/plugins/email/monitor.js +269 -269
  41. package/plugins/email/parser.js +138 -138
  42. package/plugins/email/reply.js +151 -151
  43. package/plugins/email/utils.js +124 -124
  44. package/plugins/feishu-plugin.js +481 -481
  45. package/plugins/file-system-plugin.js +826 -826
  46. package/plugins/install-plugin.js +199 -199
  47. package/plugins/python-executor-plugin.js +367 -367
  48. package/plugins/python-plugin-loader.js +481 -481
  49. package/plugins/rules-plugin.js +294 -294
  50. package/plugins/scheduler-plugin.js +691 -691
  51. package/plugins/session-plugin.js +369 -369
  52. package/plugins/shell-executor-plugin.js +197 -197
  53. package/plugins/storage-plugin.js +240 -240
  54. package/plugins/subagent-plugin.js +845 -845
  55. package/plugins/telegram-plugin.js +482 -482
  56. package/plugins/think-plugin.js +345 -345
  57. package/plugins/tools-plugin.js +196 -196
  58. package/plugins/web-plugin.js +606 -606
  59. package/plugins/weixin-plugin.js +545 -545
  60. package/src/capabilities/index.js +11 -11
  61. package/src/capabilities/skill-manager.js +609 -609
  62. package/src/capabilities/workflow-engine.js +1109 -1109
  63. package/src/core/agent-chat.js +882 -882
  64. package/src/core/agent.js +892 -892
  65. package/src/core/framework.js +465 -465
  66. package/src/core/index.js +19 -19
  67. package/src/core/plugin-base.js +219 -219
  68. package/src/core/plugin-manager.js +863 -863
  69. package/src/core/provider.js +114 -114
  70. package/src/core/sub-agent-config.js +264 -264
  71. package/src/core/system-prompt-builder.js +120 -120
  72. package/src/core/tool-registry.js +517 -517
  73. package/src/core/tool-router.js +297 -297
  74. package/src/executors/executor-base.js +58 -58
  75. package/src/executors/mcp-executor.js +741 -741
  76. package/src/index.js +25 -25
  77. package/src/utils/circuit-breaker.js +301 -301
  78. package/src/utils/error-boundary.js +363 -363
  79. package/src/utils/error.js +374 -374
  80. package/src/utils/event-emitter.js +97 -97
  81. package/src/utils/id.js +133 -133
  82. package/src/utils/index.js +217 -217
  83. package/src/utils/logger.js +181 -181
  84. package/src/utils/plugin-helpers.js +90 -90
  85. package/src/utils/retry.js +122 -122
  86. package/src/utils/sandbox.js +292 -292
  87. package/test/tool-registry-validation.test.js +218 -218
  88. package/website/script.js +136 -136
  89. package/foliko-1.0.75.tgz +0 -0
@@ -1,199 +1,199 @@
1
- /**
2
- * InstallPlugin - npm 包安装工具
3
- * 自动安装缺少的 node 模块到 .agent 目录或指定目录
4
- */
5
-
6
- const { execSync } = require('child_process')
7
- const fs = require('fs')
8
- const path = require('path')
9
- const { Plugin } = require('../src/core/plugin-base')
10
- const { logger } = require('../src/utils/logger')
11
- const log = logger.child('InstallPlugin')
12
- const { z } = require('zod')
13
-
14
- class InstallPlugin extends Plugin {
15
- constructor(config = {}) {
16
- super()
17
- this.name = 'install'
18
- this.version = '1.0.0'
19
- this.description = '自动安装 npm 包到指定目录'
20
-
21
- this._agentDir = config.agentDir || '.agent'
22
- this._nodeModulesDir = null
23
- this.system = true
24
- }
25
-
26
- install(framework) {
27
- this._framework = framework
28
- return this
29
- }
30
-
31
- start(framework) {
32
- // 确保 node_modules 目录存在
33
- this._nodeModulesDir = path.join(this._agentDir, 'node_modules')
34
- if (!fs.existsSync(this._nodeModulesDir)) {
35
- fs.mkdirSync(this._nodeModulesDir, { recursive: true })
36
- }
37
-
38
- // 注册 install 工具
39
- framework.registerTool({
40
- name: 'install',
41
- description: '安装 npm 包到指定目录',
42
- inputSchema: z.object({
43
- package: z.string().optional().describe('包名,如 lodash、lodash@4.17.21 或 @scope/package'),
44
- path: z.string().optional().describe('安装目标目录,如 .agent/plugins/my-plugin(默认为 .agent)'),
45
- file: z.string().optional().describe('本地 package.json 路径,从该文件安装所有依赖')
46
- }),
47
- execute: async (args) => {
48
- const { package: packageName, path: targetPath, file: packageJsonPath } = args
49
-
50
- // 优先处理 file 参数(从 package.json 安装)
51
- if (packageJsonPath) {
52
- const resolvedPath = path.resolve(process.cwd(), packageJsonPath)
53
- return this._installFromPackageJson(resolvedPath, targetPath)
54
- }
55
-
56
- // package 和 path 都提供
57
- if (packageName) {
58
- return this._installPackage(packageName, targetPath)
59
- }
60
-
61
- // 只有 path,安装该目录的 package.json
62
- if (targetPath) {
63
- const resolvedPath = path.resolve(process.cwd(), targetPath)
64
- const pkgJson = path.join(resolvedPath, 'package.json')
65
- if (fs.existsSync(pkgJson)) {
66
- return this._installFromPackageJson(pkgJson, targetPath)
67
- }
68
- return { success: false, error: `package.json not found at ${pkgJson}` }
69
- }
70
-
71
- // 什么都不提供,报错
72
- return { success: false, error: 'Must provide package name or package.json path' }
73
- }
74
- })
75
-
76
- return this
77
- }
78
-
79
- /**
80
- * 安装单个包到指定目录
81
- * @param {string} packageName - 包名
82
- * @param {string|null} targetPath - 目标目录,默认为 .agent
83
- */
84
- _installPackage(packageName, targetPath = null) {
85
- try {
86
- const installPath = targetPath
87
- ? path.resolve(process.cwd(), targetPath)
88
- : this._agentDir
89
-
90
- log.info(` Installing ${packageName} to ${installPath}...`)
91
-
92
- // 确保目标目录存在
93
- if (!fs.existsSync(installPath)) {
94
- fs.mkdirSync(installPath, { recursive: true })
95
- }
96
-
97
- // 使用 npm install 安装到指定目录
98
- execSync(`npm install ${packageName} --prefix "${installPath}"`, {
99
- stdio: 'inherit',
100
- cwd: installPath
101
- })
102
-
103
- log.info(` Successfully installed ${packageName}`)
104
-
105
- return {
106
- success: true,
107
- message: `Successfully installed ${packageName} to ${installPath}`
108
- }
109
- } catch (err) {
110
- return {
111
- success: false,
112
- error: `Failed to install ${packageName}: ${err.message}`
113
- }
114
- }
115
- }
116
-
117
- /**
118
- * 从 package.json 安装所有依赖
119
- * @param {string} packageJsonPath - package.json 路径
120
- * @param {string|null} targetPath - 目标目录,默认为 package.json 所在目录
121
- */
122
- _installFromPackageJson(packageJsonPath, targetPath = null) {
123
- try {
124
- const resolvedPkgPath = path.resolve(process.cwd(), packageJsonPath)
125
- const pkgDir = path.dirname(resolvedPkgPath)
126
- const installPath = targetPath
127
- ? path.resolve(process.cwd(), targetPath)
128
- : pkgDir
129
-
130
- log.info(` Installing dependencies from ${resolvedPkgPath} to ${installPath}...`)
131
-
132
- // 读取 package.json 获取要安装的包
133
- const pkg = JSON.parse(fs.readFileSync(resolvedPkgPath, 'utf-8'))
134
- const packages = []
135
-
136
- if (pkg.dependencies) {
137
- packages.push(...Object.keys(pkg.dependencies))
138
- }
139
- if (pkg.devDependencies) {
140
- packages.push(...Object.keys(pkg.devDependencies))
141
- }
142
-
143
- if (packages.length === 0) {
144
- return { success: true, message: 'No dependencies to install' }
145
- }
146
-
147
- // 确保目标目录存在
148
- if (!fs.existsSync(installPath)) {
149
- fs.mkdirSync(installPath, { recursive: true })
150
- }
151
-
152
- // 使用 npm install 安装
153
- execSync(`npm install --prefix "${installPath}" --no-save`, {
154
- stdio: 'inherit',
155
- cwd: pkgDir
156
- })
157
-
158
- log.info(` Successfully installed ${packages.length} packages`)
159
-
160
- return {
161
- success: true,
162
- message: `Successfully installed ${packages.length} dependencies to ${installPath}`
163
- }
164
- } catch (err) {
165
- return {
166
- success: false,
167
- error: `Failed to install from package.json: ${err.message}`
168
- }
169
- }
170
- }
171
-
172
- /**
173
- * 获取 node_modules 路径,供其他插件使用
174
- */
175
- getNodeModulesDir() {
176
- return this._nodeModulesDir
177
- }
178
-
179
- /**
180
- * 添加到 module.paths(让 require 能找到)
181
- */
182
- addToModulePaths() {
183
- if (this._nodeModulesDir && !module.paths.includes(this._nodeModulesDir)) {
184
- module.paths.unshift(this._nodeModulesDir)
185
- }
186
- }
187
-
188
- /**
189
- * 添加自定义路径到 module.paths
190
- * @param {string} dir - 目录路径
191
- */
192
- addCustomModulePath(dir) {
193
- if (dir && fs.existsSync(dir) && !module.paths.includes(dir)) {
194
- module.paths.unshift(dir)
195
- }
196
- }
197
- }
198
-
199
- module.exports = { InstallPlugin }
1
+ /**
2
+ * InstallPlugin - npm 包安装工具
3
+ * 自动安装缺少的 node 模块到 .agent 目录或指定目录
4
+ */
5
+
6
+ const { execSync } = require('child_process')
7
+ const fs = require('fs')
8
+ const path = require('path')
9
+ const { Plugin } = require('../src/core/plugin-base')
10
+ const { logger } = require('../src/utils/logger')
11
+ const log = logger.child('InstallPlugin')
12
+ const { z } = require('zod')
13
+
14
+ class InstallPlugin extends Plugin {
15
+ constructor(config = {}) {
16
+ super()
17
+ this.name = 'install'
18
+ this.version = '1.0.0'
19
+ this.description = '自动安装 npm 包到指定目录'
20
+
21
+ this._agentDir = config.agentDir || '.agent'
22
+ this._nodeModulesDir = null
23
+ this.system = true
24
+ }
25
+
26
+ install(framework) {
27
+ this._framework = framework
28
+ return this
29
+ }
30
+
31
+ start(framework) {
32
+ // 确保 node_modules 目录存在
33
+ this._nodeModulesDir = path.join(this._agentDir, 'node_modules')
34
+ if (!fs.existsSync(this._nodeModulesDir)) {
35
+ fs.mkdirSync(this._nodeModulesDir, { recursive: true })
36
+ }
37
+
38
+ // 注册 install 工具
39
+ framework.registerTool({
40
+ name: 'install',
41
+ description: '安装 npm 包到指定目录',
42
+ inputSchema: z.object({
43
+ package: z.string().optional().describe('包名,如 lodash、lodash@4.17.21 或 @scope/package'),
44
+ path: z.string().optional().describe('安装目标目录,如 .agent/plugins/my-plugin(默认为 .agent)'),
45
+ file: z.string().optional().describe('本地 package.json 路径,从该文件安装所有依赖')
46
+ }),
47
+ execute: async (args) => {
48
+ const { package: packageName, path: targetPath, file: packageJsonPath } = args
49
+
50
+ // 优先处理 file 参数(从 package.json 安装)
51
+ if (packageJsonPath) {
52
+ const resolvedPath = path.resolve(process.cwd(), packageJsonPath)
53
+ return this._installFromPackageJson(resolvedPath, targetPath)
54
+ }
55
+
56
+ // package 和 path 都提供
57
+ if (packageName) {
58
+ return this._installPackage(packageName, targetPath)
59
+ }
60
+
61
+ // 只有 path,安装该目录的 package.json
62
+ if (targetPath) {
63
+ const resolvedPath = path.resolve(process.cwd(), targetPath)
64
+ const pkgJson = path.join(resolvedPath, 'package.json')
65
+ if (fs.existsSync(pkgJson)) {
66
+ return this._installFromPackageJson(pkgJson, targetPath)
67
+ }
68
+ return { success: false, error: `package.json not found at ${pkgJson}` }
69
+ }
70
+
71
+ // 什么都不提供,报错
72
+ return { success: false, error: 'Must provide package name or package.json path' }
73
+ }
74
+ })
75
+
76
+ return this
77
+ }
78
+
79
+ /**
80
+ * 安装单个包到指定目录
81
+ * @param {string} packageName - 包名
82
+ * @param {string|null} targetPath - 目标目录,默认为 .agent
83
+ */
84
+ _installPackage(packageName, targetPath = null) {
85
+ try {
86
+ const installPath = targetPath
87
+ ? path.resolve(process.cwd(), targetPath)
88
+ : this._agentDir
89
+
90
+ log.info(` Installing ${packageName} to ${installPath}...`)
91
+
92
+ // 确保目标目录存在
93
+ if (!fs.existsSync(installPath)) {
94
+ fs.mkdirSync(installPath, { recursive: true })
95
+ }
96
+
97
+ // 使用 npm install 安装到指定目录
98
+ execSync(`npm install ${packageName} --prefix "${installPath}"`, {
99
+ stdio: 'inherit',
100
+ cwd: installPath
101
+ })
102
+
103
+ log.info(` Successfully installed ${packageName}`)
104
+
105
+ return {
106
+ success: true,
107
+ message: `Successfully installed ${packageName} to ${installPath}`
108
+ }
109
+ } catch (err) {
110
+ return {
111
+ success: false,
112
+ error: `Failed to install ${packageName}: ${err.message}`
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * 从 package.json 安装所有依赖
119
+ * @param {string} packageJsonPath - package.json 路径
120
+ * @param {string|null} targetPath - 目标目录,默认为 package.json 所在目录
121
+ */
122
+ _installFromPackageJson(packageJsonPath, targetPath = null) {
123
+ try {
124
+ const resolvedPkgPath = path.resolve(process.cwd(), packageJsonPath)
125
+ const pkgDir = path.dirname(resolvedPkgPath)
126
+ const installPath = targetPath
127
+ ? path.resolve(process.cwd(), targetPath)
128
+ : pkgDir
129
+
130
+ log.info(` Installing dependencies from ${resolvedPkgPath} to ${installPath}...`)
131
+
132
+ // 读取 package.json 获取要安装的包
133
+ const pkg = JSON.parse(fs.readFileSync(resolvedPkgPath, 'utf-8'))
134
+ const packages = []
135
+
136
+ if (pkg.dependencies) {
137
+ packages.push(...Object.keys(pkg.dependencies))
138
+ }
139
+ if (pkg.devDependencies) {
140
+ packages.push(...Object.keys(pkg.devDependencies))
141
+ }
142
+
143
+ if (packages.length === 0) {
144
+ return { success: true, message: 'No dependencies to install' }
145
+ }
146
+
147
+ // 确保目标目录存在
148
+ if (!fs.existsSync(installPath)) {
149
+ fs.mkdirSync(installPath, { recursive: true })
150
+ }
151
+
152
+ // 使用 npm install 安装
153
+ execSync(`npm install --prefix "${installPath}" --no-save`, {
154
+ stdio: 'inherit',
155
+ cwd: pkgDir
156
+ })
157
+
158
+ log.info(` Successfully installed ${packages.length} packages`)
159
+
160
+ return {
161
+ success: true,
162
+ message: `Successfully installed ${packages.length} dependencies to ${installPath}`
163
+ }
164
+ } catch (err) {
165
+ return {
166
+ success: false,
167
+ error: `Failed to install from package.json: ${err.message}`
168
+ }
169
+ }
170
+ }
171
+
172
+ /**
173
+ * 获取 node_modules 路径,供其他插件使用
174
+ */
175
+ getNodeModulesDir() {
176
+ return this._nodeModulesDir
177
+ }
178
+
179
+ /**
180
+ * 添加到 module.paths(让 require 能找到)
181
+ */
182
+ addToModulePaths() {
183
+ if (this._nodeModulesDir && !module.paths.includes(this._nodeModulesDir)) {
184
+ module.paths.unshift(this._nodeModulesDir)
185
+ }
186
+ }
187
+
188
+ /**
189
+ * 添加自定义路径到 module.paths
190
+ * @param {string} dir - 目录路径
191
+ */
192
+ addCustomModulePath(dir) {
193
+ if (dir && fs.existsSync(dir) && !module.paths.includes(dir)) {
194
+ module.paths.unshift(dir)
195
+ }
196
+ }
197
+ }
198
+
199
+ module.exports = { InstallPlugin }