foliko 1.1.67 → 1.1.69

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 (157) hide show
  1. package/.claude/settings.local.json +19 -10
  2. package/.dockerignore +45 -45
  3. package/.env.example +56 -56
  4. package/CLAUDE.md +2 -2
  5. package/README.md +13 -13
  6. package/SPEC.md +3 -3
  7. package/cli/src/commands/chat.js +2 -20
  8. package/cli/src/commands/list.js +7 -6
  9. package/cli/src/commands/plugin.js +3 -2
  10. package/cli/src/daemon.js +2 -2
  11. package/cli/src/ui/chat-ui-old.js +15 -4
  12. package/cli/src/ui/chat-ui.js +236 -203
  13. package/cli/src/ui/footer-bar.js +20 -46
  14. package/cli/src/ui/message-bubble.js +24 -2
  15. package/cli/src/ui/status-bar.js +177 -0
  16. package/cli/src/utils/config.js +29 -0
  17. package/cli/src/utils/plugin-config.js +1 -1
  18. package/docker-compose.yml +33 -33
  19. package/docs/features.md +120 -120
  20. package/docs/quick-reference.md +160 -160
  21. package/docs/user-manual.md +1391 -1391
  22. package/examples/ambient-example.js +2 -2
  23. package/examples/bootstrap.js +3 -3
  24. package/examples/test-chat.js +1 -1
  25. package/examples/test-reload.js +1 -1
  26. package/examples/test-telegram.js +1 -1
  27. package/examples/test-tg-bot.js +1 -1
  28. package/examples/test-tg-simple.js +2 -2
  29. package/examples/test-tg.js +1 -1
  30. package/examples/test-think.js +1 -1
  31. package/examples/test-weixin-feishu.js +3 -3
  32. package/package.json +3 -1
  33. package/plugins/ambient-agent/index.js +1 -1
  34. package/plugins/audit-plugin.js +84 -29
  35. package/plugins/coordinator-plugin.js +14 -12
  36. package/plugins/data-splitter-plugin.js +323 -0
  37. package/plugins/default-plugins.js +23 -12
  38. package/plugins/email/index.js +1 -1
  39. package/plugins/extension-executor-plugin.js +87 -9
  40. package/plugins/feishu-plugin.js +118 -16
  41. package/plugins/file-system-plugin.js +68 -50
  42. package/plugins/gate-trading.js +10 -10
  43. package/plugins/install-plugin.js +7 -7
  44. package/plugins/memory-plugin.js +9 -12
  45. package/plugins/plugin-manager-plugin.js +12 -14
  46. package/plugins/python-executor-plugin.js +1 -1
  47. package/plugins/python-plugin-loader.js +1 -1
  48. package/plugins/qq-plugin.js +151 -24
  49. package/plugins/rules-plugin.js +8 -8
  50. package/plugins/scheduler-plugin.js +24 -20
  51. package/plugins/session-plugin.js +313 -397
  52. package/plugins/storage-plugin.js +235 -175
  53. package/plugins/subagent-plugin.js +17 -13
  54. package/plugins/telegram-plugin.js +116 -17
  55. package/plugins/think-plugin.js +64 -60
  56. package/plugins/tools-plugin.js +8 -8
  57. package/plugins/web-plugin.js +2 -2
  58. package/plugins/weixin-plugin.js +107 -24
  59. package/skills/find-skills/AGENTS.md +2 -2
  60. package/skills/find-skills/SKILL.md +133 -133
  61. package/skills/foliko-dev/AGENTS.md +236 -236
  62. package/skills/foliko-dev/SKILL.md +19 -19
  63. package/skills/mcp-usage/SKILL.md +200 -200
  64. package/skills/plugin-guide/SKILL.md +4 -4
  65. package/skills/python-plugin-dev/SKILL.md +5 -5
  66. package/skills/skill-guide/SKILL.md +104 -6
  67. package/skills/subagent-guide/SKILL.md +237 -237
  68. package/skills/workflow-guide/SKILL.md +646 -646
  69. package/src/capabilities/skill-manager.js +124 -17
  70. package/src/capabilities/workflow-engine.js +3 -3
  71. package/src/core/agent-chat.js +72 -26
  72. package/src/core/agent.js +17 -27
  73. package/src/core/branch-summary-auto.js +206 -0
  74. package/src/core/chat-session.js +45 -169
  75. package/src/core/command-registry.js +200 -0
  76. package/src/core/constants.js +198 -0
  77. package/src/core/context-compressor.js +702 -326
  78. package/src/core/context-manager.js +0 -1
  79. package/src/core/enhanced-context-compressor.js +210 -0
  80. package/src/core/framework.js +260 -84
  81. package/src/core/jsonl-storage.js +253 -0
  82. package/src/core/plugin-base.js +7 -5
  83. package/src/core/plugin-manager.js +15 -10
  84. package/src/core/provider-registry.js +159 -0
  85. package/src/core/provider.js +2 -0
  86. package/src/core/session-entry.js +225 -0
  87. package/src/core/session-manager.js +701 -0
  88. package/src/core/storage-manager.js +494 -0
  89. package/src/core/sub-agent-config.js +1 -1
  90. package/src/core/subagent.js +16 -135
  91. package/src/core/token-counter.js +177 -58
  92. package/src/core/tool-executor.js +2 -70
  93. package/src/core/ui-extension-context.js +174 -0
  94. package/src/executors/mcp-executor.js +27 -16
  95. package/src/utils/chat-queue.js +11 -22
  96. package/src/utils/data-splitter.js +345 -0
  97. package/src/utils/logger.js +152 -180
  98. package/src/utils/message-validator.js +283 -0
  99. package/src/utils/plugin-helpers.js +2 -2
  100. package/src/utils/retry.js +168 -22
  101. package/website_v2/docs/api.html +1 -1
  102. package/website_v2/docs/configuration.html +2 -2
  103. package/website_v2/docs/plugin-development.html +4 -4
  104. package/website_v2/docs/project-structure.html +2 -2
  105. package/website_v2/docs/skill-development.html +2 -2
  106. package/website_v2/index.html +1 -1
  107. package/website_v2/styles/animations.css +7 -7
  108. package/.agent/agents/backend-dev.md +0 -102
  109. package/.agent/agents/data-analyst.md +0 -117
  110. package/.agent/agents/devops.md +0 -115
  111. package/.agent/agents/frontend-dev.md +0 -94
  112. package/.agent/agents/network-requester.md +0 -44
  113. package/.agent/agents/poster-designer.md +0 -52
  114. package/.agent/agents/product-manager.md +0 -85
  115. package/.agent/agents/qa-engineer.md +0 -100
  116. package/.agent/agents/security-engineer.md +0 -99
  117. package/.agent/agents/team-lead.md +0 -137
  118. package/.agent/agents/ui-designer.md +0 -116
  119. package/.agent/data/default.json +0 -58
  120. package/.agent/data/email/processed-emails.json +0 -1
  121. package/.agent/data/plugins-state.json +0 -199
  122. package/.agent/data/scheduler/tasks.json +0 -1
  123. package/.agent/data/web/web-config.json +0 -5
  124. package/.agent/data/weixin/images/file_1776188148383jpg +0 -0
  125. package/.agent/data/weixin/images/file_1776188458326.jpg +0 -0
  126. package/.agent/data/weixin/images/file_1776188689423.jpg +0 -0
  127. package/.agent/data/weixin/images/file_1776188813604.jpg +0 -0
  128. package/.agent/data/weixin/images/file_1776189097450.jpg +0 -0
  129. package/.agent/data/weixin/videos/file_1776188318431.mp4 +0 -0
  130. package/.agent/data/weixin.json +0 -6
  131. package/.agent/mcp_config.json +0 -14
  132. package/.agent/memory/user/mof6gk94-kneeuh.md +0 -9
  133. package/.agent/package.json +0 -8
  134. package/.agent/plugins/marknative/README.md +0 -134
  135. package/.agent/plugins/marknative/fonts/SegoeUI Emoji.ttf +0 -0
  136. package/.agent/plugins/marknative/fonts.zip +0 -0
  137. package/.agent/plugins/marknative/index.js +0 -256
  138. package/.agent/plugins/marknative/package.json +0 -12
  139. package/.agent/plugins/test-plugin.py +0 -99
  140. package/.agent/plugins.json +0 -14
  141. package/.agent/python-scripts/test_sample.py +0 -24
  142. package/.agent/sessions/cli_default.json +0 -247
  143. package/.agent/skills/agent-browser/SKILL.md +0 -311
  144. package/.agent/skills/agent-browser/TEST_PLAN.md +0 -200
  145. package/.agent/skills/sysinfo/SKILL.md +0 -38
  146. package/.agent/skills/sysinfo/system-info.sh +0 -130
  147. package/.agent/skills/workflow/SKILL.md +0 -324
  148. package/.agent/test-agent.js +0 -35
  149. package/.agent/weixin.json +0 -6
  150. package/.agent/workflows/email-digest.json +0 -50
  151. package/.agent/workflows/file-backup.json +0 -21
  152. package/.agent/workflows/get-ip-notify.json +0 -32
  153. package/.agent/workflows/news-aggregator.json +0 -93
  154. package/.agent/workflows/news-dashboard-v2.json +0 -94
  155. package/.agent/workflows/notification-batch.json +0 -32
  156. package/src/core/session-context.js +0 -346
  157. package/src/core/session-storage.js +0 -295
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  const { RequestContext } = require('./request-context');
11
- const { SessionContext } = require('./session-context');
12
11
 
13
12
  class ContextManager {
14
13
  /**
@@ -0,0 +1,210 @@
1
+ /**
2
+ * EnhancedContextCompressor - 增强的上下文压缩器
3
+ * 整合 pi 的 compaction 逻辑,提供更智能的压缩策略
4
+ */
5
+
6
+ const {
7
+ ContextCompressor,
8
+ CompactionDetails,
9
+ CompactionResult,
10
+ prepareCompaction,
11
+ prepareBranchEntries,
12
+ collectEntriesForBranchSummary,
13
+ serializeConversation,
14
+ DEFAULT_COMPACTION_SETTINGS,
15
+ BRANCH_SUMMARY_PREAMBLE,
16
+ BRANCH_SUMMARY_PROMPT,
17
+ EntryTypes
18
+ } = require('./context-compressor');
19
+
20
+ const { logger } = require('../utils/logger');
21
+
22
+ class EnhancedContextCompressor {
23
+ /**
24
+ * @param {Object} config
25
+ * @param {Framework} config.framework - Framework 实例
26
+ * @param {Agent} [config.agent] - Agent 实例
27
+ * @param {string} [config.model] - 模型名称
28
+ * @param {Function} [config.onCompaction] - 压缩完成回调
29
+ * @param {Function} [config.onBranchSummary] - 分支摘要生成回调
30
+ */
31
+ constructor(config = {}) {
32
+ this.framework = config.framework;
33
+ this.agent = config.agent;
34
+
35
+ this.settings = {
36
+ ...DEFAULT_COMPACTION_SETTINGS,
37
+ ...config.settings
38
+ };
39
+
40
+ this._onCompaction = config.onCompaction || null;
41
+ this._onBranchSummary = config.onBranchSummary || null;
42
+
43
+ // 创建底层压缩器
44
+ this._compressor = new ContextCompressor({
45
+ agent: this.agent,
46
+ framework: this.framework,
47
+ model: config.model,
48
+ compactionSettings: this.settings,
49
+ enableSmartCompress: config.enableSmartCompress !== false
50
+ });
51
+ }
52
+
53
+ /**
54
+ * 执行智能压缩
55
+ * @param {string} sessionId - Session ID
56
+ * @param {Array} messages - 消息数组
57
+ * @param {Object} messageStore - 消息存储
58
+ * @param {Object} [options] - 选项
59
+ * @returns {Promise<{didCompact: boolean, reason?: string, summary?: string}>}
60
+ */
61
+ async smartCompact(sessionId, messages, messageStore, options = {}) {
62
+ const {
63
+ reserveTokens = this.settings.reserveTokens,
64
+ keepRecentTokens = this.settings.keepRecentTokens,
65
+ minTokensToCompact = 1000
66
+ } = options;
67
+
68
+ const totalTokens = this._estimateTokens(messages);
69
+ const effectiveLimit = totalTokens - reserveTokens;
70
+
71
+ // 检查是否需要压缩
72
+ if (totalTokens <= effectiveLimit) {
73
+ return { didCompact: false, reason: 'below_threshold' };
74
+ }
75
+
76
+ // 计算需要压缩的 token 数
77
+ const tokensToCompact = totalTokens - keepRecentTokens;
78
+ if (tokensToCompact < minTokensToCompact) {
79
+ return { didCompact: false, reason: 'too_small' };
80
+ }
81
+
82
+ // 执行压缩
83
+ try {
84
+ await this._compressor.compress(sessionId, messages, messageStore);
85
+
86
+ if (this._onCompaction) {
87
+ await this._onCompaction({
88
+ sessionId,
89
+ tokensBefore: totalTokens,
90
+ tokensAfter: this._estimateTokens(messages),
91
+ messagesCompressed: tokensToCompact
92
+ });
93
+ }
94
+
95
+ return {
96
+ didCompact: true,
97
+ tokensBefore: totalTokens,
98
+ tokensAfter: this._estimateTokens(messages)
99
+ };
100
+ } catch (err) {
101
+ logger.error('[EnhancedContextCompressor] Smart compact failed:', err.message);
102
+ return { didCompact: false, reason: 'error', error: err.message };
103
+ }
104
+ }
105
+
106
+ /**
107
+ * 准备分支摘要
108
+ * 当切换分支时,收集需要摘要的内容
109
+ * @param {SessionManager} session - Session 管理器
110
+ * @param {string} oldLeafId - 旧叶子节点 ID
111
+ * @param {string} targetId - 目标节点 ID
112
+ * @returns {Promise<{needsSummary: boolean, summary?: string, entriesCount?: number}>}
113
+ */
114
+ async prepareBranchSummary(session, oldLeafId, targetId) {
115
+ const { entries, commonAncestorId } = collectEntriesForBranchSummary(
116
+ session,
117
+ oldLeafId,
118
+ targetId
119
+ );
120
+
121
+ if (entries.length === 0) {
122
+ return { needsSummary: false };
123
+ }
124
+
125
+ // 检查 token 数量是否足够生成摘要
126
+ const prep = prepareBranchEntries(entries, 0);
127
+ if (prep.totalTokens < 500) {
128
+ return { needsSummary: false, reason: 'too_small' };
129
+ }
130
+
131
+ if (this._onBranchSummary) {
132
+ await this._onBranchSummary({
133
+ entries,
134
+ commonAncestorId,
135
+ totalTokens: prep.totalTokens
136
+ });
137
+ }
138
+
139
+ return {
140
+ needsSummary: true,
141
+ entriesCount: entries.length,
142
+ totalTokens: prep.totalTokens
143
+ };
144
+ }
145
+
146
+ /**
147
+ * 生成分支摘要
148
+ * @param {Array} messages - 消息数组
149
+ * @returns {Promise<string>} 摘要文本
150
+ */
151
+ async generateBranchSummary(messages) {
152
+ const conversation = serializeConversation(messages);
153
+
154
+ if (!this.framework) {
155
+ return `[Branch summary: ${messages.length} messages]`;
156
+ }
157
+
158
+ const subagent = this.framework.createSubAgent({
159
+ name: 'branch-summarizer',
160
+ systemPrompt: BRANCH_SUMMARY_PROMPT,
161
+ disableTools: true,
162
+ maxRetries: 0
163
+ });
164
+
165
+ try {
166
+ const result = await subagent.chat(BRANCH_SUMMARY_PREAMBLE + conversation);
167
+ if (result.success) {
168
+ return result.message;
169
+ }
170
+ throw new Error(result.error || 'Summary generation failed');
171
+ } catch (err) {
172
+ logger.warn('[EnhancedContextCompressor] Branch summary failed:', err.message);
173
+ return `[Branch summary: ${messages.length} messages]`;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * 获取压缩统计
179
+ */
180
+ getStats() {
181
+ return this._compressor.getStats();
182
+ }
183
+
184
+ /**
185
+ * 估算 token 数量
186
+ */
187
+ _estimateTokens(messages) {
188
+ let total = 0;
189
+ for (const msg of messages) {
190
+ const content = Array.isArray(msg.content)
191
+ ? msg.content.map(c => c.text || '').join('')
192
+ : (msg.content || '');
193
+ total += Math.ceil(content.length / 4); // 简单估算
194
+ }
195
+ return total;
196
+ }
197
+
198
+ /**
199
+ * 启用/禁用智能压缩
200
+ */
201
+ setSmartCompress(enabled) {
202
+ this._compressor._enableSmartCompress = enabled;
203
+ return this;
204
+ }
205
+ }
206
+
207
+ module.exports = {
208
+ EnhancedContextCompressor,
209
+ DEFAULT_COMPACTION_SETTINGS
210
+ };