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.
- package/.claude/settings.local.json +19 -10
- package/.dockerignore +45 -45
- package/.env.example +56 -56
- package/CLAUDE.md +2 -2
- package/README.md +13 -13
- package/SPEC.md +3 -3
- package/cli/src/commands/chat.js +2 -20
- package/cli/src/commands/list.js +7 -6
- package/cli/src/commands/plugin.js +3 -2
- package/cli/src/daemon.js +2 -2
- package/cli/src/ui/chat-ui-old.js +15 -4
- package/cli/src/ui/chat-ui.js +236 -203
- package/cli/src/ui/footer-bar.js +20 -46
- package/cli/src/ui/message-bubble.js +24 -2
- package/cli/src/ui/status-bar.js +177 -0
- package/cli/src/utils/config.js +29 -0
- package/cli/src/utils/plugin-config.js +1 -1
- package/docker-compose.yml +33 -33
- package/docs/features.md +120 -120
- package/docs/quick-reference.md +160 -160
- package/docs/user-manual.md +1391 -1391
- package/examples/ambient-example.js +2 -2
- package/examples/bootstrap.js +3 -3
- package/examples/test-chat.js +1 -1
- package/examples/test-reload.js +1 -1
- package/examples/test-telegram.js +1 -1
- package/examples/test-tg-bot.js +1 -1
- package/examples/test-tg-simple.js +2 -2
- package/examples/test-tg.js +1 -1
- package/examples/test-think.js +1 -1
- package/examples/test-weixin-feishu.js +3 -3
- package/package.json +3 -1
- package/plugins/ambient-agent/index.js +1 -1
- package/plugins/audit-plugin.js +84 -29
- package/plugins/coordinator-plugin.js +14 -12
- package/plugins/data-splitter-plugin.js +323 -0
- package/plugins/default-plugins.js +23 -12
- package/plugins/email/index.js +1 -1
- package/plugins/extension-executor-plugin.js +87 -9
- package/plugins/feishu-plugin.js +118 -16
- package/plugins/file-system-plugin.js +68 -50
- package/plugins/gate-trading.js +10 -10
- package/plugins/install-plugin.js +7 -7
- package/plugins/memory-plugin.js +9 -12
- package/plugins/plugin-manager-plugin.js +12 -14
- package/plugins/python-executor-plugin.js +1 -1
- package/plugins/python-plugin-loader.js +1 -1
- package/plugins/qq-plugin.js +151 -24
- package/plugins/rules-plugin.js +8 -8
- package/plugins/scheduler-plugin.js +24 -20
- package/plugins/session-plugin.js +313 -397
- package/plugins/storage-plugin.js +235 -175
- package/plugins/subagent-plugin.js +17 -13
- package/plugins/telegram-plugin.js +116 -17
- package/plugins/think-plugin.js +64 -60
- package/plugins/tools-plugin.js +8 -8
- package/plugins/web-plugin.js +2 -2
- package/plugins/weixin-plugin.js +107 -24
- package/skills/find-skills/AGENTS.md +2 -2
- package/skills/find-skills/SKILL.md +133 -133
- package/skills/foliko-dev/AGENTS.md +236 -236
- package/skills/foliko-dev/SKILL.md +19 -19
- package/skills/mcp-usage/SKILL.md +200 -200
- package/skills/plugin-guide/SKILL.md +4 -4
- package/skills/python-plugin-dev/SKILL.md +5 -5
- package/skills/skill-guide/SKILL.md +104 -6
- package/skills/subagent-guide/SKILL.md +237 -237
- package/skills/workflow-guide/SKILL.md +646 -646
- package/src/capabilities/skill-manager.js +124 -17
- package/src/capabilities/workflow-engine.js +3 -3
- package/src/core/agent-chat.js +72 -26
- package/src/core/agent.js +17 -27
- package/src/core/branch-summary-auto.js +206 -0
- package/src/core/chat-session.js +45 -169
- package/src/core/command-registry.js +200 -0
- package/src/core/constants.js +198 -0
- package/src/core/context-compressor.js +702 -326
- package/src/core/context-manager.js +0 -1
- package/src/core/enhanced-context-compressor.js +210 -0
- package/src/core/framework.js +260 -84
- package/src/core/jsonl-storage.js +253 -0
- package/src/core/plugin-base.js +7 -5
- package/src/core/plugin-manager.js +15 -10
- package/src/core/provider-registry.js +159 -0
- package/src/core/provider.js +2 -0
- package/src/core/session-entry.js +225 -0
- package/src/core/session-manager.js +701 -0
- package/src/core/storage-manager.js +494 -0
- package/src/core/sub-agent-config.js +1 -1
- package/src/core/subagent.js +16 -135
- package/src/core/token-counter.js +177 -58
- package/src/core/tool-executor.js +2 -70
- package/src/core/ui-extension-context.js +174 -0
- package/src/executors/mcp-executor.js +27 -16
- package/src/utils/chat-queue.js +11 -22
- package/src/utils/data-splitter.js +345 -0
- package/src/utils/logger.js +152 -180
- package/src/utils/message-validator.js +283 -0
- package/src/utils/plugin-helpers.js +2 -2
- package/src/utils/retry.js +168 -22
- package/website_v2/docs/api.html +1 -1
- package/website_v2/docs/configuration.html +2 -2
- package/website_v2/docs/plugin-development.html +4 -4
- package/website_v2/docs/project-structure.html +2 -2
- package/website_v2/docs/skill-development.html +2 -2
- package/website_v2/index.html +1 -1
- package/website_v2/styles/animations.css +7 -7
- package/.agent/agents/backend-dev.md +0 -102
- package/.agent/agents/data-analyst.md +0 -117
- package/.agent/agents/devops.md +0 -115
- package/.agent/agents/frontend-dev.md +0 -94
- package/.agent/agents/network-requester.md +0 -44
- package/.agent/agents/poster-designer.md +0 -52
- package/.agent/agents/product-manager.md +0 -85
- package/.agent/agents/qa-engineer.md +0 -100
- package/.agent/agents/security-engineer.md +0 -99
- package/.agent/agents/team-lead.md +0 -137
- package/.agent/agents/ui-designer.md +0 -116
- package/.agent/data/default.json +0 -58
- package/.agent/data/email/processed-emails.json +0 -1
- package/.agent/data/plugins-state.json +0 -199
- package/.agent/data/scheduler/tasks.json +0 -1
- package/.agent/data/web/web-config.json +0 -5
- package/.agent/data/weixin/images/file_1776188148383jpg +0 -0
- package/.agent/data/weixin/images/file_1776188458326.jpg +0 -0
- package/.agent/data/weixin/images/file_1776188689423.jpg +0 -0
- package/.agent/data/weixin/images/file_1776188813604.jpg +0 -0
- package/.agent/data/weixin/images/file_1776189097450.jpg +0 -0
- package/.agent/data/weixin/videos/file_1776188318431.mp4 +0 -0
- package/.agent/data/weixin.json +0 -6
- package/.agent/mcp_config.json +0 -14
- package/.agent/memory/user/mof6gk94-kneeuh.md +0 -9
- package/.agent/package.json +0 -8
- package/.agent/plugins/marknative/README.md +0 -134
- package/.agent/plugins/marknative/fonts/SegoeUI Emoji.ttf +0 -0
- package/.agent/plugins/marknative/fonts.zip +0 -0
- package/.agent/plugins/marknative/index.js +0 -256
- package/.agent/plugins/marknative/package.json +0 -12
- package/.agent/plugins/test-plugin.py +0 -99
- package/.agent/plugins.json +0 -14
- package/.agent/python-scripts/test_sample.py +0 -24
- package/.agent/sessions/cli_default.json +0 -247
- package/.agent/skills/agent-browser/SKILL.md +0 -311
- package/.agent/skills/agent-browser/TEST_PLAN.md +0 -200
- package/.agent/skills/sysinfo/SKILL.md +0 -38
- package/.agent/skills/sysinfo/system-info.sh +0 -130
- package/.agent/skills/workflow/SKILL.md +0 -324
- package/.agent/test-agent.js +0 -35
- package/.agent/weixin.json +0 -6
- package/.agent/workflows/email-digest.json +0 -50
- package/.agent/workflows/file-backup.json +0 -21
- package/.agent/workflows/get-ip-notify.json +0 -32
- package/.agent/workflows/news-aggregator.json +0 -93
- package/.agent/workflows/news-dashboard-v2.json +0 -94
- package/.agent/workflows/notification-batch.json +0 -32
- package/src/core/session-context.js +0 -346
- package/src/core/session-storage.js +0 -295
|
@@ -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
|
+
};
|