openhorse 0.1.7 → 0.1.10
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/coordinator.d.ts +86 -0
- package/dist/agents/coordinator.d.ts.map +1 -0
- package/dist/agents/coordinator.js +251 -0
- package/dist/agents/coordinator.js.map +1 -0
- package/dist/agents/fork.d.ts +61 -0
- package/dist/agents/fork.d.ts.map +1 -0
- package/dist/agents/fork.js +169 -0
- package/dist/agents/fork.js.map +1 -0
- package/dist/agents/worker-pool.d.ts +72 -0
- package/dist/agents/worker-pool.d.ts.map +1 -0
- package/dist/agents/worker-pool.js +213 -0
- package/dist/agents/worker-pool.js.map +1 -0
- package/dist/cli.js +74 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +57 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/framework/query.d.ts +4 -0
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +29 -1
- package/dist/framework/query.js.map +1 -1
- package/dist/services/auth/auth.d.ts +121 -0
- package/dist/services/auth/auth.d.ts.map +1 -0
- package/dist/services/auth/auth.js +233 -0
- package/dist/services/auth/auth.js.map +1 -0
- package/dist/services/auth/aws.d.ts +27 -0
- package/dist/services/auth/aws.d.ts.map +1 -0
- package/dist/services/auth/aws.js +109 -0
- package/dist/services/auth/aws.js.map +1 -0
- package/dist/services/auth/index.d.ts +6 -0
- package/dist/services/auth/index.d.ts.map +1 -0
- package/dist/services/auth/index.js +17 -0
- package/dist/services/auth/index.js.map +1 -0
- package/dist/services/auto-fix/autoFixConfig.d.ts +33 -0
- package/dist/services/auto-fix/autoFixConfig.d.ts.map +1 -0
- package/dist/services/auto-fix/autoFixConfig.js +61 -0
- package/dist/services/auto-fix/autoFixConfig.js.map +1 -0
- package/dist/services/auto-fix/autoFixHook.d.ts +20 -0
- package/dist/services/auto-fix/autoFixHook.d.ts.map +1 -0
- package/dist/services/auto-fix/autoFixHook.js +89 -0
- package/dist/services/auto-fix/autoFixHook.js.map +1 -0
- package/dist/services/auto-fix/autoFixRunner.d.ts +60 -0
- package/dist/services/auto-fix/autoFixRunner.d.ts.map +1 -0
- package/dist/services/auto-fix/autoFixRunner.js +207 -0
- package/dist/services/auto-fix/autoFixRunner.js.map +1 -0
- package/dist/services/auto-fix/index.d.ts +7 -0
- package/dist/services/auto-fix/index.d.ts.map +1 -0
- package/dist/services/auto-fix/index.js +17 -0
- package/dist/services/auto-fix/index.js.map +1 -0
- package/dist/services/compact/auto-compact.d.ts +53 -0
- package/dist/services/compact/auto-compact.d.ts.map +1 -0
- package/dist/services/compact/auto-compact.js +114 -0
- package/dist/services/compact/auto-compact.js.map +1 -0
- package/dist/services/compact/compact.d.ts +51 -0
- package/dist/services/compact/compact.d.ts.map +1 -0
- package/dist/services/compact/compact.js +120 -0
- package/dist/services/compact/compact.js.map +1 -0
- package/dist/services/compact/index.d.ts +10 -0
- package/dist/services/compact/index.d.ts.map +1 -0
- package/dist/services/compact/index.js +23 -0
- package/dist/services/compact/index.js.map +1 -0
- package/dist/services/compact/micro-compact.d.ts +21 -0
- package/dist/services/compact/micro-compact.d.ts.map +1 -0
- package/dist/services/compact/micro-compact.js +99 -0
- package/dist/services/compact/micro-compact.js.map +1 -0
- package/dist/services/compact/summary-generator.d.ts +25 -0
- package/dist/services/compact/summary-generator.d.ts.map +1 -0
- package/dist/services/compact/summary-generator.js +128 -0
- package/dist/services/compact/summary-generator.js.map +1 -0
- package/dist/services/concurrent-sessions.d.ts +97 -0
- package/dist/services/concurrent-sessions.d.ts.map +1 -0
- package/dist/services/concurrent-sessions.js +263 -0
- package/dist/services/concurrent-sessions.js.map +1 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.d.ts +58 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.js +167 -0
- package/dist/services/diagnostic-tracking/diagnosticTracking.js.map +1 -0
- package/dist/services/diagnostic-tracking/formatter.d.ts +17 -0
- package/dist/services/diagnostic-tracking/formatter.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/formatter.js +78 -0
- package/dist/services/diagnostic-tracking/formatter.js.map +1 -0
- package/dist/services/diagnostic-tracking/index.d.ts +7 -0
- package/dist/services/diagnostic-tracking/index.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/index.js +19 -0
- package/dist/services/diagnostic-tracking/index.js.map +1 -0
- package/dist/services/diagnostic-tracking/types.d.ts +52 -0
- package/dist/services/diagnostic-tracking/types.d.ts.map +1 -0
- package/dist/services/diagnostic-tracking/types.js +27 -0
- package/dist/services/diagnostic-tracking/types.js.map +1 -0
- package/dist/services/mcp/index.d.ts +5 -0
- package/dist/services/mcp/index.d.ts.map +1 -0
- package/dist/services/mcp/index.js +16 -0
- package/dist/services/mcp/index.js.map +1 -0
- package/dist/services/mcp/transports.d.ts +104 -0
- package/dist/services/mcp/transports.d.ts.map +1 -0
- package/dist/services/mcp/transports.js +342 -0
- package/dist/services/mcp/transports.js.map +1 -0
- package/dist/services/session-memory/index.d.ts +6 -0
- package/dist/services/session-memory/index.d.ts.map +1 -0
- package/dist/services/session-memory/index.js +15 -0
- package/dist/services/session-memory/index.js.map +1 -0
- package/dist/services/session-memory/prompts.d.ts +23 -0
- package/dist/services/session-memory/prompts.d.ts.map +1 -0
- package/dist/services/session-memory/prompts.js +70 -0
- package/dist/services/session-memory/prompts.js.map +1 -0
- package/dist/services/session-memory/sessionMemory.d.ts +64 -0
- package/dist/services/session-memory/sessionMemory.d.ts.map +1 -0
- package/dist/services/session-memory/sessionMemory.js +243 -0
- package/dist/services/session-memory/sessionMemory.js.map +1 -0
- package/dist/services/smart-routing.d.ts +41 -0
- package/dist/services/smart-routing.d.ts.map +1 -0
- package/dist/services/smart-routing.js +134 -0
- package/dist/services/smart-routing.js.map +1 -0
- package/dist/tools/git.d.ts +14 -0
- package/dist/tools/git.d.ts.map +1 -0
- package/dist/tools/git.js +270 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +80 -14
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp.d.ts +18 -0
- package/dist/tools/lsp.d.ts.map +1 -0
- package/dist/tools/lsp.js +450 -0
- package/dist/tools/lsp.js.map +1 -0
- package/dist/tools/web.d.ts.map +1 -1
- package/dist/tools/web.js +70 -38
- package/dist/tools/web.js.map +1 -1
- package/dist/ui/command-panel.d.ts +5 -0
- package/dist/ui/command-panel.d.ts.map +1 -1
- package/dist/ui/command-panel.js +59 -18
- package/dist/ui/command-panel.js.map +1 -1
- package/dist/ui/markdown.d.ts +10 -4
- package/dist/ui/markdown.d.ts.map +1 -1
- package/dist/ui/markdown.js +91 -4
- package/dist/ui/markdown.js.map +1 -1
- package/dist/ui/progress.d.ts +34 -0
- package/dist/ui/progress.d.ts.map +1 -0
- package/dist/ui/progress.js +88 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/status-bar.d.ts.map +1 -1
- package/dist/ui/status-bar.js +10 -0
- package/dist/ui/status-bar.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* openhorse - AutoFix Runner
|
|
3
|
+
*
|
|
4
|
+
* 代码修改后自动运行 lint + test,检测并尝试修复错误。
|
|
5
|
+
*/
|
|
6
|
+
import type { AutoFixConfig, AutoFixTrigger } from './autoFixConfig';
|
|
7
|
+
export interface AutoFixResult {
|
|
8
|
+
success: boolean;
|
|
9
|
+
lintPassed: boolean;
|
|
10
|
+
testPassed: boolean;
|
|
11
|
+
buildPassed?: boolean;
|
|
12
|
+
errors: AutoFixError[];
|
|
13
|
+
fixAttempts: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
}
|
|
16
|
+
export interface AutoFixError {
|
|
17
|
+
type: 'lint' | 'test' | 'build';
|
|
18
|
+
file?: string;
|
|
19
|
+
line?: number;
|
|
20
|
+
message: string;
|
|
21
|
+
fixable: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface AutoFixContext {
|
|
24
|
+
projectPath: string;
|
|
25
|
+
changedFiles: string[];
|
|
26
|
+
trigger: AutoFixTrigger;
|
|
27
|
+
}
|
|
28
|
+
export declare class AutoFixRunner {
|
|
29
|
+
private config;
|
|
30
|
+
private projectPath;
|
|
31
|
+
private fixAttempts;
|
|
32
|
+
private lastRunTime;
|
|
33
|
+
constructor(projectPath?: string, config?: AutoFixConfig);
|
|
34
|
+
/**
|
|
35
|
+
* 运行 AutoFix
|
|
36
|
+
*/
|
|
37
|
+
run(context: AutoFixContext): Promise<AutoFixResult>;
|
|
38
|
+
/**
|
|
39
|
+
* 快速检查(仅 lint)
|
|
40
|
+
*/
|
|
41
|
+
quickCheck(files: string[]): Promise<{
|
|
42
|
+
passed: boolean;
|
|
43
|
+
errors: AutoFixError[];
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* 获取配置
|
|
47
|
+
*/
|
|
48
|
+
getConfig(): AutoFixConfig;
|
|
49
|
+
/**
|
|
50
|
+
* 启用/禁用
|
|
51
|
+
*/
|
|
52
|
+
setEnabled(enabled: boolean): void;
|
|
53
|
+
private runCommand;
|
|
54
|
+
private parseLintErrors;
|
|
55
|
+
private parseBuildErrors;
|
|
56
|
+
private parseTestErrors;
|
|
57
|
+
}
|
|
58
|
+
export declare function getAutoFixRunner(projectPath?: string, config?: AutoFixConfig): AutoFixRunner;
|
|
59
|
+
export declare function resetAutoFixRunner(): void;
|
|
60
|
+
//# sourceMappingURL=autoFixRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoFixRunner.d.ts","sourceRoot":"","sources":["../../../src/services/auto-fix/autoFixRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAOrE,MAAM,WAAW,aAAa;IAC5B,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,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,aAAa,CAK5F;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* openhorse - AutoFix Runner
|
|
4
|
+
*
|
|
5
|
+
* 代码修改后自动运行 lint + test,检测并尝试修复错误。
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AutoFixRunner = void 0;
|
|
9
|
+
exports.getAutoFixRunner = getAutoFixRunner;
|
|
10
|
+
exports.resetAutoFixRunner = resetAutoFixRunner;
|
|
11
|
+
const child_process_1 = require("child_process");
|
|
12
|
+
const autoFixConfig_1 = require("./autoFixConfig");
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// AutoFix Runner
|
|
15
|
+
// ============================================================================
|
|
16
|
+
class AutoFixRunner {
|
|
17
|
+
constructor(projectPath, config) {
|
|
18
|
+
this.fixAttempts = 0;
|
|
19
|
+
this.lastRunTime = 0;
|
|
20
|
+
this.projectPath = projectPath || process.cwd();
|
|
21
|
+
this.config = config || (0, autoFixConfig_1.detectAutoFixConfig)(this.projectPath);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 运行 AutoFix
|
|
25
|
+
*/
|
|
26
|
+
async run(context) {
|
|
27
|
+
if (!this.config.enabled) {
|
|
28
|
+
return {
|
|
29
|
+
success: true,
|
|
30
|
+
lintPassed: true,
|
|
31
|
+
testPassed: true,
|
|
32
|
+
errors: [],
|
|
33
|
+
fixAttempts: 0,
|
|
34
|
+
duration: 0,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const startTime = Date.now();
|
|
38
|
+
const errors = [];
|
|
39
|
+
let lintPassed = true;
|
|
40
|
+
let testPassed = true;
|
|
41
|
+
let buildPassed = true;
|
|
42
|
+
// 1. 运行 lint
|
|
43
|
+
if (this.config.lintCommand) {
|
|
44
|
+
const lintResult = await this.runCommand(this.config.lintCommand);
|
|
45
|
+
lintPassed = lintResult.success;
|
|
46
|
+
if (!lintResult.success) {
|
|
47
|
+
errors.push(...this.parseLintErrors(lintResult.output));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// 2. 运行 build(如果有)
|
|
51
|
+
if (this.config.buildCommand) {
|
|
52
|
+
const buildResult = await this.runCommand(this.config.buildCommand);
|
|
53
|
+
buildPassed = buildResult.success;
|
|
54
|
+
if (!buildResult.success) {
|
|
55
|
+
errors.push(...this.parseBuildErrors(buildResult.output));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// 3. 运行 test
|
|
59
|
+
if (this.config.testCommand) {
|
|
60
|
+
const testResult = await this.runCommand(this.config.testCommand);
|
|
61
|
+
testPassed = testResult.success;
|
|
62
|
+
if (!testResult.success) {
|
|
63
|
+
errors.push(...this.parseTestErrors(testResult.output));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const duration = Date.now() - startTime;
|
|
67
|
+
return {
|
|
68
|
+
success: lintPassed && testPassed && buildPassed,
|
|
69
|
+
lintPassed,
|
|
70
|
+
testPassed,
|
|
71
|
+
buildPassed,
|
|
72
|
+
errors,
|
|
73
|
+
fixAttempts: this.fixAttempts,
|
|
74
|
+
duration,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 快速检查(仅 lint)
|
|
79
|
+
*/
|
|
80
|
+
async quickCheck(files) {
|
|
81
|
+
if (!this.config.lintCommand) {
|
|
82
|
+
return { passed: true, errors: [] };
|
|
83
|
+
}
|
|
84
|
+
const lintResult = await this.runCommand(this.config.lintCommand);
|
|
85
|
+
const errors = lintResult.success ? [] : this.parseLintErrors(lintResult.output);
|
|
86
|
+
return {
|
|
87
|
+
passed: lintResult.success,
|
|
88
|
+
errors,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 获取配置
|
|
93
|
+
*/
|
|
94
|
+
getConfig() {
|
|
95
|
+
return this.config;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 启用/禁用
|
|
99
|
+
*/
|
|
100
|
+
setEnabled(enabled) {
|
|
101
|
+
this.config.enabled = enabled;
|
|
102
|
+
}
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// 内部方法
|
|
105
|
+
// ============================================================================
|
|
106
|
+
async runCommand(command) {
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
const [cmd, ...args] = command.split(' ');
|
|
109
|
+
(0, child_process_1.execFile)(cmd, args, {
|
|
110
|
+
cwd: this.projectPath,
|
|
111
|
+
timeout: this.config.timeout,
|
|
112
|
+
maxBuffer: 1024 * 1024,
|
|
113
|
+
}, (error, stdout, stderr) => {
|
|
114
|
+
const output = stdout.toString() + stderr.toString();
|
|
115
|
+
resolve({
|
|
116
|
+
success: !error,
|
|
117
|
+
output,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
parseLintErrors(output) {
|
|
123
|
+
const errors = [];
|
|
124
|
+
const lines = output.split('\n');
|
|
125
|
+
for (const line of lines) {
|
|
126
|
+
// ESLint 格式: /path/to/file.ts:10:5: error message
|
|
127
|
+
const match = line.match(/^([^:]+):(\d+):(\d+):\s+(.+)$/);
|
|
128
|
+
if (match) {
|
|
129
|
+
errors.push({
|
|
130
|
+
type: 'lint',
|
|
131
|
+
file: match[1],
|
|
132
|
+
line: parseInt(match[2]),
|
|
133
|
+
message: match[4],
|
|
134
|
+
fixable: line.includes('--fix'),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// 简化格式: error: message at file:line
|
|
138
|
+
const simpleMatch = line.match(/error:\s+(.+)\s+at\s+([^:]+):(\d+)/);
|
|
139
|
+
if (simpleMatch) {
|
|
140
|
+
errors.push({
|
|
141
|
+
type: 'lint',
|
|
142
|
+
file: simpleMatch[2],
|
|
143
|
+
line: parseInt(simpleMatch[3]),
|
|
144
|
+
message: simpleMatch[1],
|
|
145
|
+
fixable: false,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return errors;
|
|
150
|
+
}
|
|
151
|
+
parseBuildErrors(output) {
|
|
152
|
+
const errors = [];
|
|
153
|
+
const lines = output.split('\n');
|
|
154
|
+
for (const line of lines) {
|
|
155
|
+
// TypeScript 格式: src/file.ts(10,5): error TS1234: message
|
|
156
|
+
const match = line.match(/^([^(]+)\((\d+),(\d+)\):\s+error\s+TS\d+:\s+(.+)$/);
|
|
157
|
+
if (match) {
|
|
158
|
+
errors.push({
|
|
159
|
+
type: 'build',
|
|
160
|
+
file: match[1],
|
|
161
|
+
line: parseInt(match[2]),
|
|
162
|
+
message: match[4],
|
|
163
|
+
fixable: false,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return errors;
|
|
168
|
+
}
|
|
169
|
+
parseTestErrors(output) {
|
|
170
|
+
const errors = [];
|
|
171
|
+
const lines = output.split('\n');
|
|
172
|
+
for (const line of lines) {
|
|
173
|
+
// Jest 格式: FAIL src/test.ts
|
|
174
|
+
if (line.includes('FAIL') || line.includes('Error:')) {
|
|
175
|
+
errors.push({
|
|
176
|
+
type: 'test',
|
|
177
|
+
message: line.trim(),
|
|
178
|
+
fixable: false,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// Mocha 格式: AssertionError: ...
|
|
182
|
+
if (line.startsWith('AssertionError')) {
|
|
183
|
+
errors.push({
|
|
184
|
+
type: 'test',
|
|
185
|
+
message: line.trim(),
|
|
186
|
+
fixable: false,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return errors.slice(0, 10); // 限制数量
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.AutoFixRunner = AutoFixRunner;
|
|
194
|
+
// ============================================================================
|
|
195
|
+
// 单例
|
|
196
|
+
// ============================================================================
|
|
197
|
+
let autoFixRunner = null;
|
|
198
|
+
function getAutoFixRunner(projectPath, config) {
|
|
199
|
+
if (!autoFixRunner) {
|
|
200
|
+
autoFixRunner = new AutoFixRunner(projectPath, config);
|
|
201
|
+
}
|
|
202
|
+
return autoFixRunner;
|
|
203
|
+
}
|
|
204
|
+
function resetAutoFixRunner() {
|
|
205
|
+
autoFixRunner = null;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=autoFixRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoFixRunner.js","sourceRoot":"","sources":["../../../src/services/auto-fix/autoFixRunner.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA2PH,4CAKC;AAED,gDAEC;AAlQD,iDAAyC;AAEzC,mDAA8E;AA8B9E,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAa,aAAa;IAMxB,YAAY,WAAoB,EAAE,MAAsB;QAHhD,gBAAW,GAAW,CAAC,CAAC;QACxB,gBAAW,GAAW,CAAC,CAAC;QAG9B,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAA,mCAAmB,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,OAAuB;QAC/B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,IAAI;gBAChB,MAAM,EAAE,EAAE;gBACV,WAAW,EAAE,CAAC;gBACd,QAAQ,EAAE,CAAC;aACZ,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAmB,EAAE,CAAC;QAClC,IAAI,UAAU,G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AAgB,CAAC,EAAE,CAAC;gBACtC,MAAM,CAAC,IAAI,CAAC;oBACV,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE;oBACpB,OAAO,EAAE,KAAK;iBACf,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAE,OAAO;IACtC,CAAC;CACF;AA7MD,sCA6MC;AAED,+EAA+E;AAC/E,KAAK;AACL,+EAA+E;AAE/E,IAAI,aAAa,GAAyB,IAAI,CAAC;AAE/C,SAAgB,gBAAgB,CAAC,WAAoB,EAAE,MAAsB;IAC3E,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAgB,kBAAkB;IAChC,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* openhorse - AutoFix 服务入口
|
|
3
|
+
*/
|
|
4
|
+
export { AutoFixRunner, getAutoFixRunner, resetAutoFixRunner, type AutoFixResult, type AutoFixError, type AutoFixContext, } from './autoFixRunner';
|
|
5
|
+
export { DEFAULT_AUTOFIX_CONFIG, detectAutoFixConfig, type AutoFixConfig, type AutoFixTrigger, } from './autoFixConfig';
|
|
6
|
+
export { autoFixHook, shouldTriggerAutoFix, } from './autoFixHook';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/auto-fix/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,WAAW,EACX,oBAAoB,GACrB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* openhorse - AutoFix 服务入口
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.shouldTriggerAutoFix = exports.autoFixHook = exports.detectAutoFixConfig = exports.DEFAULT_AUTOFIX_CONFIG = exports.resetAutoFixRunner = exports.getAutoFixRunner = exports.AutoFixRunner = void 0;
|
|
7
|
+
var autoFixRunner_1 = require("./autoFixRunner");
|
|
8
|
+
Object.defineProperty(exports, "AutoFixRunner", { enumerable: true, get: function () { return autoFixRunner_1.AutoFixRunner; } });
|
|
9
|
+
Object.defineProperty(exports, "getAutoFixRunner", { enumerable: true, get: function () { return autoFixRunner_1.getAutoFixRunner; } });
|
|
10
|
+
Object.defineProperty(exports, "resetAutoFixRunner", { enumerable: true, get: function () { return autoFixRunner_1.resetAutoFixRunner; } });
|
|
11
|
+
var autoFixConfig_1 = require("./autoFixConfig");
|
|
12
|
+
Object.defineProperty(exports, "DEFAULT_AUTOFIX_CONFIG", { enumerable: true, get: function () { return autoFixConfig_1.DEFAULT_AUTOFIX_CONFIG; } });
|
|
13
|
+
Object.defineProperty(exports, "detectAutoFixConfig", { enumerable: true, get: function () { return autoFixConfig_1.detectAutoFixConfig; } });
|
|
14
|
+
var autoFixHook_1 = require("./autoFixHook");
|
|
15
|
+
Object.defineProperty(exports, "autoFixHook", { enumerable: true, get: function () { return autoFixHook_1.autoFixHook; } });
|
|
16
|
+
Object.defineProperty(exports, "shouldTriggerAutoFix", { enumerable: true, get: function () { return autoFixHook_1.shouldTriggerAutoFix; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/auto-fix/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAOyB;AANvB,8GAAA,aAAa,OAAA;AACb,iHAAA,gBAAgB,OAAA;AAChB,mHAAA,kBAAkB,OAAA;AAMpB,iDAKyB;AAJvB,uHAAA,sBAAsB,OAAA;AACtB,oHAAA,mBAAmB,OAAA;AAKrB,6CAGuB;AAFrB,0GAAA,WAAW,OAAA;AACX,mHAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* openhorse - 自动压缩触发器
|
|
3
|
+
*
|
|
4
|
+
* 监控对话长度,自动触发压缩。
|
|
5
|
+
*/
|
|
6
|
+
import type { Message } from '../llm';
|
|
7
|
+
export interface AutoCompactConfig {
|
|
8
|
+
/** 触发阈值 */
|
|
9
|
+
threshold?: number;
|
|
10
|
+
/** 压缩后保留消息数 */
|
|
11
|
+
maxMessages?: number;
|
|
12
|
+
/** 是否启用自动压缩 */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
/** 压缩回调(通知用户) */
|
|
15
|
+
onCompact?: (result: {
|
|
16
|
+
originalCount: number;
|
|
17
|
+
compactedCount: number;
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare class AutoCompact {
|
|
21
|
+
private config;
|
|
22
|
+
private lastCompactTime;
|
|
23
|
+
private compactCount;
|
|
24
|
+
constructor(config?: AutoCompactConfig);
|
|
25
|
+
/**
|
|
26
|
+
* 检查并触发自动压缩
|
|
27
|
+
*/
|
|
28
|
+
checkAndCompact(messages: Message[]): Promise<Message[]>;
|
|
29
|
+
/**
|
|
30
|
+
* 强制压缩
|
|
31
|
+
*/
|
|
32
|
+
forceCompact(messages: Message[]): Promise<Message[]>;
|
|
33
|
+
/**
|
|
34
|
+
* 获取压缩统计
|
|
35
|
+
*/
|
|
36
|
+
getStats(): {
|
|
37
|
+
compactCount: number;
|
|
38
|
+
lastCompactTime: number;
|
|
39
|
+
threshold: number;
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* 启用/禁用自动压缩
|
|
44
|
+
*/
|
|
45
|
+
setEnabled(enabled: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* 更新阈值
|
|
48
|
+
*/
|
|
49
|
+
setThreshold(threshold: number): void;
|
|
50
|
+
}
|
|
51
|
+
export declare function getAutoCompact(config?: AutoCompactConfig): AutoCompact;
|
|
52
|
+
export declare function resetAutoCompact(): void;
|
|
53
|
+
//# sourceMappingURL=auto-compact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-compact.d.ts","sourceRoot":"","sources":["../../../src/services/compact/auto-compact.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAOtC,MAAM,WAAW,iBAAiB;IAChC,WAAW;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB;IACjB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACjF;AAMD,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,YAAY,CAAa;gBAErB,MAAM,CAAC,EAAE,iBAAiB;IAStC;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAqC9D;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAkB3D;;OAEG;IACH,QAAQ,IAAI;QACV,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;KAClB;IASD;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAGtC;AAQD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAKtE;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* openhorse - 自动压缩触发器
|
|
4
|
+
*
|
|
5
|
+
* 监控对话长度,自动触发压缩。
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AutoCompact = void 0;
|
|
9
|
+
exports.getAutoCompact = getAutoCompact;
|
|
10
|
+
exports.resetAutoCompact = resetAutoCompact;
|
|
11
|
+
const compact_1 = require("./compact");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// 自动压缩器
|
|
14
|
+
// ============================================================================
|
|
15
|
+
class AutoCompact {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.lastCompactTime = 0;
|
|
18
|
+
this.compactCount = 0;
|
|
19
|
+
this.config = {
|
|
20
|
+
threshold: config?.threshold || 50,
|
|
21
|
+
maxMessages: config?.maxMessages || 20,
|
|
22
|
+
enabled: config?.enabled ?? true,
|
|
23
|
+
onCompact: config?.onCompact,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 检查并触发自动压缩
|
|
28
|
+
*/
|
|
29
|
+
async checkAndCompact(messages) {
|
|
30
|
+
if (!this.config.enabled) {
|
|
31
|
+
return messages;
|
|
32
|
+
}
|
|
33
|
+
// 检查是否需要压缩
|
|
34
|
+
if (!(0, compact_1.needsCompact)(messages, this.config.threshold)) {
|
|
35
|
+
return messages;
|
|
36
|
+
}
|
|
37
|
+
// 避免频繁压缩(至少间隔 30 秒)
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
if (now - this.lastCompactTime < 30000) {
|
|
40
|
+
return messages;
|
|
41
|
+
}
|
|
42
|
+
// 执行压缩
|
|
43
|
+
const result = await (0, compact_1.compactMessages)(messages, {
|
|
44
|
+
threshold: this.config.threshold,
|
|
45
|
+
maxMessages: this.config.maxMessages,
|
|
46
|
+
});
|
|
47
|
+
// 更新状态
|
|
48
|
+
this.lastCompactTime = now;
|
|
49
|
+
this.compactCount++;
|
|
50
|
+
// 通知回调
|
|
51
|
+
if (this.config.onCompact) {
|
|
52
|
+
this.config.onCompact({
|
|
53
|
+
originalCount: result.originalCount,
|
|
54
|
+
compactedCount: result.compactedCount,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return result.messages;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 强制压缩
|
|
61
|
+
*/
|
|
62
|
+
async forceCompact(messages) {
|
|
63
|
+
const result = await (0, compact_1.compactMessages)(messages, {
|
|
64
|
+
threshold: this.config.threshold,
|
|
65
|
+
maxMessages: this.config.maxMessages,
|
|
66
|
+
});
|
|
67
|
+
this.compactCount++;
|
|
68
|
+
if (this.config.onCompact) {
|
|
69
|
+
this.config.onCompact({
|
|
70
|
+
originalCount: result.originalCount,
|
|
71
|
+
compactedCount: result.compactedCount,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return result.messages;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 获取压缩统计
|
|
78
|
+
*/
|
|
79
|
+
getStats() {
|
|
80
|
+
return {
|
|
81
|
+
compactCount: this.compactCount,
|
|
82
|
+
lastCompactTime: this.lastCompactTime,
|
|
83
|
+
threshold: this.config.threshold || 50,
|
|
84
|
+
enabled: this.config.enabled ?? true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 启用/禁用自动压缩
|
|
89
|
+
*/
|
|
90
|
+
setEnabled(enabled) {
|
|
91
|
+
this.config.enabled = enabled;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 更新阈值
|
|
95
|
+
*/
|
|
96
|
+
setThreshold(threshold) {
|
|
97
|
+
this.config.threshold = threshold;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.AutoCompact = AutoCompact;
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// 单例
|
|
103
|
+
// ============================================================================
|
|
104
|
+
let autoCompactInstance = null;
|
|
105
|
+
function getAutoCompact(config) {
|
|
106
|
+
if (!autoCompactInstance) {
|
|
107
|
+
autoCompactInstance = new AutoCompact(config);
|
|
108
|
+
}
|
|
109
|
+
return autoCompactInstance;
|
|
110
|
+
}
|
|
111
|
+
function resetAutoCompact() {
|
|
112
|
+
autoCompactInstance = null;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=auto-compact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-compact.js","sourceRoot":"","sources":["../../../src/services/compact/auto-compact.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAyIH,wCAKC;AAED,4CAEC;AA/ID,uCAA+E;AAiB/E,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E,MAAa,WAAW;IAKtB,YAAY,MAA0B;QAH9B,oBAAe,GAAW,CAAC,CAAC;QAC5B,iBAAY,GAAW,CAAC,CAAC;QAG/B,IAAI,CAAC,MAAM,GAAG;YACZ,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,EAAE;YAClC,WAAW,EAAE,MAAM,EAAE,WAAW,IAAI,EAAE;YACtC,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,IAAI;YAChC,SAAS,EAAE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 长对话压缩服务,减少上下文长度同时保留关键信息。
|
|
5
|
+
* 参考 OpenClaude 的 compact/ 目录实现。
|
|
6
|
+
*/
|
|
7
|
+
import type { Message } from '../llm';
|
|
8
|
+
import { type SummaryOptions } from './summary-generator';
|
|
9
|
+
export interface CompactOptions {
|
|
10
|
+
/** 最大保留消息数 */
|
|
11
|
+
maxMessages?: number;
|
|
12
|
+
/** 是否保留工具调用 */
|
|
13
|
+
keepToolCalls?: boolean;
|
|
14
|
+
/** 是否保留系统消息 */
|
|
15
|
+
keepSystemMessage?: boolean;
|
|
16
|
+
/** 压缩阈值(消息数超过此值触发) */
|
|
17
|
+
threshold?: number;
|
|
18
|
+
/** 自定义摘要生成选项 */
|
|
19
|
+
summaryOptions?: SummaryOptions;
|
|
20
|
+
}
|
|
21
|
+
export interface CompactResult {
|
|
22
|
+
/** 压缩后的消息列表 */
|
|
23
|
+
messages: Message[];
|
|
24
|
+
/** 压缩前消息数 */
|
|
25
|
+
originalCount: number;
|
|
26
|
+
/** 压缩后消息数 */
|
|
27
|
+
compactedCount: number;
|
|
28
|
+
/** 压缩比率 */
|
|
29
|
+
ratio: number;
|
|
30
|
+
/** 摘要内容 */
|
|
31
|
+
summary: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 压缩消息历史
|
|
35
|
+
*
|
|
36
|
+
* 策略:
|
|
37
|
+
* 1. 保留 system 消息
|
|
38
|
+
* 2. 保留最近 N 条消息
|
|
39
|
+
* 3. 对早期消息生成摘要替换
|
|
40
|
+
*/
|
|
41
|
+
export declare function compactMessages(messages: Message[], options?: CompactOptions): Promise<CompactResult>;
|
|
42
|
+
/**
|
|
43
|
+
* 检查是否需要压缩
|
|
44
|
+
*/
|
|
45
|
+
export declare function needsCompact(messages: Message[], threshold?: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 快速压缩(不生成摘要,直接保留最近 N 条)
|
|
48
|
+
*/
|
|
49
|
+
export declare function quickCompact(messages: Message[], keepLast?: number): Message[];
|
|
50
|
+
export { CompactOptions as CompactConfig, CompactResult as CompactResultData };
|
|
51
|
+
//# sourceMappingURL=compact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../../src/services/compact/compact.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAM5E,MAAM,WAAW,cAAc;IAC7B,cAAc;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,aAAa;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;CACjB;AAiBD;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC,CA0ExB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAG7E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,GAAE,MAAW,GAAG,OAAO,EAAE,CAiBlF;AAMD,OAAO,EAAE,cAAc,IAAI,aAAa,EAAE,aAAa,IAAI,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* openhorse - Compact 服务
|
|
4
|
+
*
|
|
5
|
+
* 长对话压缩服务,减少上下文长度同时保留关键信息。
|
|
6
|
+
* 参考 OpenClaude 的 compact/ 目录实现。
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.compactMessages = compactMessages;
|
|
10
|
+
exports.needsCompact = needsCompact;
|
|
11
|
+
exports.quickCompact = quickCompact;
|
|
12
|
+
const summary_generator_1 = require("./summary-generator");
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// 默认配置
|
|
15
|
+
// ============================================================================
|
|
16
|
+
const DEFAULT_OPTIONS = {
|
|
17
|
+
maxMessages: 20,
|
|
18
|
+
keepToolCalls: true,
|
|
19
|
+
keepSystemMessage: true,
|
|
20
|
+
threshold: 50,
|
|
21
|
+
};
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Compact 实现
|
|
24
|
+
// ============================================================================
|
|
25
|
+
/**
|
|
26
|
+
* 压缩消息历史
|
|
27
|
+
*
|
|
28
|
+
* 策略:
|
|
29
|
+
* 1. 保留 system 消息
|
|
30
|
+
* 2. 保留最近 N 条消息
|
|
31
|
+
* 3. 对早期消息生成摘要替换
|
|
32
|
+
*/
|
|
33
|
+
async function compactMessages(messages, options) {
|
|
34
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
35
|
+
const originalCount = messages.length;
|
|
36
|
+
// 检查是否需要压缩
|
|
37
|
+
if (originalCount <= opts.threshold) {
|
|
38
|
+
return {
|
|
39
|
+
messages,
|
|
40
|
+
originalCount,
|
|
41
|
+
compactedCount: originalCount,
|
|
42
|
+
ratio: 1,
|
|
43
|
+
summary: '',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// 1. 保留 system 消息
|
|
47
|
+
const systemMessage = opts.keepSystemMessage
|
|
48
|
+
? messages.find(m => m.role === 'system')
|
|
49
|
+
: undefined;
|
|
50
|
+
// 2. 分离需要压缩的消息
|
|
51
|
+
const toCompact = opts.keepSystemMessage
|
|
52
|
+
? messages.filter(m => m.role !== 'system')
|
|
53
|
+
: messages;
|
|
54
|
+
// 3. 保留最近 maxMessages 条
|
|
55
|
+
const recentMessages = toCompact.slice(-opts.maxMessages);
|
|
56
|
+
const oldMessages = toCompact.slice(0, toCompact.length - opts.maxMessages);
|
|
57
|
+
// 4. 对早期消息生成摘要
|
|
58
|
+
const summary = await (0, summary_generator_1.summaryGenerator)(oldMessages, opts.summaryOptions);
|
|
59
|
+
// 5. 构建压缩后的消息列表
|
|
60
|
+
let compactedMessages = [];
|
|
61
|
+
if (systemMessage) {
|
|
62
|
+
compactedMessages.push(systemMessage);
|
|
63
|
+
}
|
|
64
|
+
// 添加摘要作为 user 消息(作为上下文背景)
|
|
65
|
+
if (summary) {
|
|
66
|
+
compactedMessages.push({
|
|
67
|
+
role: 'user',
|
|
68
|
+
content: `[Context Summary]\n${summary}`,
|
|
69
|
+
});
|
|
70
|
+
compactedMessages.push({
|
|
71
|
+
role: 'assistant',
|
|
72
|
+
content: 'I understand the context. I will continue the conversation with this background information.',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// 添加最近消息
|
|
76
|
+
compactedMessages.push(...recentMessages);
|
|
77
|
+
// 过滤工具调用(如果需要)
|
|
78
|
+
if (!opts.keepToolCalls) {
|
|
79
|
+
compactedMessages = compactedMessages.map(m => {
|
|
80
|
+
if (m.role === 'assistant' && m.tool_calls) {
|
|
81
|
+
return { ...m, tool_calls: undefined };
|
|
82
|
+
}
|
|
83
|
+
return m;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const compactedCount = compactedMessages.length;
|
|
87
|
+
const ratio = compactedCount / originalCount;
|
|
88
|
+
return {
|
|
89
|
+
messages: compactedMessages,
|
|
90
|
+
originalCount,
|
|
91
|
+
compactedCount,
|
|
92
|
+
ratio,
|
|
93
|
+
summary,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 检查是否需要压缩
|
|
98
|
+
*/
|
|
99
|
+
function needsCompact(messages, threshold) {
|
|
100
|
+
const limit = threshold || DEFAULT_OPTIONS.threshold;
|
|
101
|
+
return messages.length > limit;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 快速压缩(不生成摘要,直接保留最近 N 条)
|
|
105
|
+
*/
|
|
106
|
+
function quickCompact(messages, keepLast = 10) {
|
|
107
|
+
const systemMessage = messages.find(m => m.role === 'system');
|
|
108
|
+
// 过滤掉 system
|
|
109
|
+
const nonSystem = messages.filter(m => m.role !== 'system');
|
|
110
|
+
// 保留最近 keepLast 条
|
|
111
|
+
const recent = nonSystem.slice(-keepLast);
|
|
112
|
+
// 构建结果
|
|
113
|
+
const result = [];
|
|
114
|
+
if (systemMessage) {
|
|
115
|
+
result.push(systemMessage);
|
|
116
|
+
}
|
|
117
|
+
result.push(...recent);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=compact.js.map
|