@dommaker/harness 0.8.3 → 0.9.0
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/README.md +127 -187
- package/bin/harness.js +15 -65
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +19 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/lifecycle.d.ts +68 -0
- package/dist/agents/lifecycle.d.ts.map +1 -0
- package/dist/agents/lifecycle.js +181 -0
- package/dist/agents/lifecycle.js.map +1 -0
- package/dist/agents/types.d.ts +42 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +6 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/architecture/cross-project-checker.d.ts +19 -1
- package/dist/architecture/cross-project-checker.d.ts.map +1 -1
- package/dist/architecture/cross-project-checker.js +72 -60
- package/dist/architecture/cross-project-checker.js.map +1 -1
- package/dist/cli/commands/acceptance.d.ts.map +1 -1
- package/dist/cli/commands/acceptance.js +1 -0
- package/dist/cli/commands/acceptance.js.map +1 -1
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +2 -4
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/command.d.ts +10 -3
- package/dist/cli/commands/command.d.ts.map +1 -1
- package/dist/cli/commands/command.js +7 -71
- package/dist/cli/commands/command.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +2 -3
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +2 -4
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +27 -63
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/security.d.ts +1 -1
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +40 -94
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +2 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/constraints/definitions.d.ts +39 -0
- package/dist/constraints/definitions.d.ts.map +1 -0
- package/dist/constraints/definitions.js +71 -0
- package/dist/constraints/definitions.js.map +1 -0
- package/dist/constraints/index.d.ts +5 -0
- package/dist/constraints/index.d.ts.map +1 -0
- package/dist/constraints/index.js +21 -0
- package/dist/constraints/index.js.map +1 -0
- package/dist/constraints/quality.d.ts +11 -0
- package/dist/constraints/quality.d.ts.map +1 -0
- package/dist/constraints/quality.js +257 -0
- package/dist/constraints/quality.js.map +1 -0
- package/dist/constraints/registry.d.ts +64 -0
- package/dist/constraints/registry.d.ts.map +1 -0
- package/dist/constraints/registry.js +167 -0
- package/dist/constraints/registry.js.map +1 -0
- package/dist/constraints/safety.d.ts +13 -0
- package/dist/constraints/safety.d.ts.map +1 -0
- package/dist/constraints/safety.js +103 -0
- package/dist/constraints/safety.js.map +1 -0
- package/dist/constraints/types.d.ts +53 -0
- package/dist/constraints/types.d.ts.map +1 -0
- package/dist/constraints/types.js +8 -0
- package/dist/constraints/types.js.map +1 -0
- package/dist/context/compaction.d.ts +57 -0
- package/dist/context/compaction.d.ts.map +1 -0
- package/dist/context/compaction.js +166 -0
- package/dist/context/compaction.js.map +1 -0
- package/dist/context/file-budget.d.ts +40 -0
- package/dist/context/file-budget.d.ts.map +1 -0
- package/dist/context/file-budget.js +147 -0
- package/dist/context/file-budget.js.map +1 -0
- package/dist/context/index.d.ts +15 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +31 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/knowledge-injector.d.ts +49 -0
- package/dist/context/knowledge-injector.d.ts.map +1 -0
- package/dist/context/knowledge-injector.js +122 -0
- package/dist/context/knowledge-injector.js.map +1 -0
- package/dist/context/progressive-loader.d.ts +0 -1
- package/dist/context/progressive-loader.d.ts.map +1 -1
- package/dist/context/progressive-loader.js +15 -32
- package/dist/context/progressive-loader.js.map +1 -1
- package/dist/context/session-manager.d.ts +67 -0
- package/dist/context/session-manager.d.ts.map +1 -0
- package/dist/context/session-manager.js +275 -0
- package/dist/context/session-manager.js.map +1 -0
- package/dist/context/token-pipeline.d.ts +55 -0
- package/dist/context/token-pipeline.d.ts.map +1 -0
- package/dist/context/token-pipeline.js +220 -0
- package/dist/context/token-pipeline.js.map +1 -0
- package/dist/context/tool-output-budget.d.ts +59 -0
- package/dist/context/tool-output-budget.d.ts.map +1 -0
- package/dist/context/tool-output-budget.js +177 -0
- package/dist/context/tool-output-budget.js.map +1 -0
- package/dist/context/types.d.ts +113 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/context/types.js +30 -0
- package/dist/context/types.js.map +1 -0
- package/dist/core/constraints/checker.d.ts +9 -1
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +72 -155
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +8 -10
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/interceptor.d.ts.map +1 -1
- package/dist/core/constraints/interceptor.js +2 -6
- package/dist/core/constraints/interceptor.js.map +1 -1
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +12 -30
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/session/clean-state.d.ts.map +1 -1
- package/dist/core/session/clean-state.js +6 -8
- package/dist/core/session/clean-state.js.map +1 -1
- package/dist/core/session/startup.d.ts.map +1 -1
- package/dist/core/session/startup.js +3 -5
- package/dist/core/session/startup.js.map +1 -1
- package/dist/core/spec/validator.d.ts.map +1 -1
- package/dist/core/spec/validator.js +2 -4
- package/dist/core/spec/validator.js.map +1 -1
- package/dist/core/validators/checkpoint.d.ts.map +1 -1
- package/dist/core/validators/checkpoint.js +3 -5
- package/dist/core/validators/checkpoint.js.map +1 -1
- package/dist/core/validators/passes-gate.d.ts +0 -4
- package/dist/core/validators/passes-gate.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.js +5 -13
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/dashboard/data.d.ts +39 -0
- package/dist/dashboard/data.d.ts.map +1 -0
- package/dist/dashboard/data.js +89 -0
- package/dist/dashboard/data.js.map +1 -0
- package/dist/dashboard/index.d.ts +4 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +20 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/dashboard/stats.d.ts +20 -0
- package/dist/dashboard/stats.d.ts.map +1 -0
- package/dist/dashboard/stats.js +115 -0
- package/dist/dashboard/stats.js.map +1 -0
- package/dist/dashboard/types.d.ts +98 -0
- package/dist/dashboard/types.d.ts.map +1 -0
- package/dist/dashboard/types.js +8 -0
- package/dist/dashboard/types.js.map +1 -0
- package/dist/failure/recorder.d.ts +4 -0
- package/dist/failure/recorder.d.ts.map +1 -1
- package/dist/failure/recorder.js +9 -11
- package/dist/failure/recorder.js.map +1 -1
- package/dist/gates/acceptance.d.ts.map +1 -1
- package/dist/gates/acceptance.js +2 -4
- package/dist/gates/acceptance.js.map +1 -1
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +0 -3
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +3 -5
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/review.d.ts.map +1 -1
- package/dist/gates/review.js +4 -6
- package/dist/gates/review.js.map +1 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +2 -4
- package/dist/gates/security.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/knowledge/import.d.ts +95 -0
- package/dist/knowledge/import.d.ts.map +1 -0
- package/dist/knowledge/import.js +429 -0
- package/dist/knowledge/import.js.map +1 -0
- package/dist/knowledge/index.d.ts +15 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +40 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/ingest.d.ts +30 -0
- package/dist/knowledge/ingest.d.ts.map +1 -0
- package/dist/knowledge/ingest.js +94 -0
- package/dist/knowledge/ingest.js.map +1 -0
- package/dist/knowledge/lifecycle-hooks.d.ts +62 -0
- package/dist/knowledge/lifecycle-hooks.d.ts.map +1 -0
- package/dist/knowledge/lifecycle-hooks.js +140 -0
- package/dist/knowledge/lifecycle-hooks.js.map +1 -0
- package/dist/knowledge/lifecycle.d.ts +43 -0
- package/dist/knowledge/lifecycle.d.ts.map +1 -0
- package/dist/knowledge/lifecycle.js +141 -0
- package/dist/knowledge/lifecycle.js.map +1 -0
- package/dist/knowledge/lint.d.ts +57 -0
- package/dist/knowledge/lint.d.ts.map +1 -0
- package/dist/knowledge/lint.js +235 -0
- package/dist/knowledge/lint.js.map +1 -0
- package/dist/knowledge/query.d.ts +33 -0
- package/dist/knowledge/query.d.ts.map +1 -0
- package/dist/knowledge/query.js +107 -0
- package/dist/knowledge/query.js.map +1 -0
- package/dist/knowledge/reference-tracker.d.ts +31 -0
- package/dist/knowledge/reference-tracker.d.ts.map +1 -0
- package/dist/knowledge/reference-tracker.js +124 -0
- package/dist/knowledge/reference-tracker.js.map +1 -0
- package/dist/knowledge/store.d.ts +42 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +278 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/knowledge/types.d.ts +103 -0
- package/dist/knowledge/types.d.ts.map +1 -0
- package/dist/knowledge/types.js +17 -0
- package/dist/knowledge/types.js.map +1 -0
- package/dist/llm/adapter.d.ts +36 -0
- package/dist/llm/adapter.d.ts.map +1 -0
- package/dist/llm/adapter.js +118 -0
- package/dist/llm/adapter.js.map +1 -0
- package/dist/llm/index.d.ts +3 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +19 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/types.d.ts +62 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/llm/types.js +8 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/monitoring/context-tracker.d.ts +38 -0
- package/dist/monitoring/context-tracker.d.ts.map +1 -0
- package/dist/monitoring/context-tracker.js +162 -0
- package/dist/monitoring/context-tracker.js.map +1 -0
- package/dist/monitoring/index.d.ts +3 -0
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +6 -0
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/knowledge-doctor.d.ts +78 -0
- package/dist/monitoring/knowledge-doctor.d.ts.map +1 -0
- package/dist/monitoring/knowledge-doctor.js +266 -0
- package/dist/monitoring/knowledge-doctor.js.map +1 -0
- package/dist/monitoring/knowledge-evolver.d.ts +72 -0
- package/dist/monitoring/knowledge-evolver.d.ts.map +1 -0
- package/dist/monitoring/knowledge-evolver.js +205 -0
- package/dist/monitoring/knowledge-evolver.js.map +1 -0
- package/dist/monitoring/performance-analyzer.d.ts.map +1 -1
- package/dist/monitoring/performance-analyzer.js +10 -4
- package/dist/monitoring/performance-analyzer.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +12 -5
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/safety/index.d.ts +6 -0
- package/dist/safety/index.d.ts.map +1 -0
- package/dist/safety/index.js +22 -0
- package/dist/safety/index.js.map +1 -0
- package/dist/safety/input-guardrail.d.ts +36 -0
- package/dist/safety/input-guardrail.d.ts.map +1 -0
- package/dist/safety/input-guardrail.js +118 -0
- package/dist/safety/input-guardrail.js.map +1 -0
- package/dist/safety/output-guardrail.d.ts +40 -0
- package/dist/safety/output-guardrail.d.ts.map +1 -0
- package/dist/safety/output-guardrail.js +150 -0
- package/dist/safety/output-guardrail.js.map +1 -0
- package/dist/safety/sandbox.d.ts +45 -0
- package/dist/safety/sandbox.d.ts.map +1 -0
- package/dist/safety/sandbox.js +134 -0
- package/dist/safety/sandbox.js.map +1 -0
- package/dist/safety/tool-guardrail.d.ts +51 -0
- package/dist/safety/tool-guardrail.d.ts.map +1 -0
- package/dist/safety/tool-guardrail.js +147 -0
- package/dist/safety/tool-guardrail.js.map +1 -0
- package/dist/safety/types.d.ts +104 -0
- package/dist/safety/types.d.ts.map +1 -0
- package/dist/safety/types.js +6 -0
- package/dist/safety/types.js.map +1 -0
- package/dist/tools/core/index.d.ts +13 -0
- package/dist/tools/core/index.d.ts.map +1 -0
- package/dist/tools/core/index.js +198 -0
- package/dist/tools/core/index.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +20 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +59 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +115 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +38 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +6 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/types/constraint.d.ts +4 -0
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/utils/exec.d.ts +11 -1
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +19 -1
- package/dist/utils/exec.js.map +1 -1
- package/dist/verification/index.d.ts +4 -0
- package/dist/verification/index.d.ts.map +1 -0
- package/dist/verification/index.js +20 -0
- package/dist/verification/index.js.map +1 -0
- package/dist/verification/loop.d.ts +30 -0
- package/dist/verification/loop.d.ts.map +1 -0
- package/dist/verification/loop.js +114 -0
- package/dist/verification/loop.js.map +1 -0
- package/dist/verification/rules-based.d.ts +40 -0
- package/dist/verification/rules-based.d.ts.map +1 -0
- package/dist/verification/rules-based.js +130 -0
- package/dist/verification/rules-based.js.map +1 -0
- package/dist/verification/types.d.ts +69 -0
- package/dist/verification/types.d.ts.map +1 -0
- package/dist/verification/types.js +6 -0
- package/dist/verification/types.js.map +1 -0
- package/package.json +1 -1
- package/dist/cli/commands/diagnose.d.ts +0 -16
- package/dist/cli/commands/diagnose.d.ts.map +0 -1
- package/dist/cli/commands/diagnose.js +0 -195
- package/dist/cli/commands/diagnose.js.map +0 -1
- package/dist/cli/commands/propose.d.ts +0 -18
- package/dist/cli/commands/propose.d.ts.map +0 -1
- package/dist/cli/commands/propose.js +0 -331
- package/dist/cli/commands/propose.js.map +0 -1
- package/dist/cli/commands/traces.d.ts +0 -15
- package/dist/cli/commands/traces.d.ts.map +0 -1
- package/dist/cli/commands/traces.js +0 -167
- package/dist/cli/commands/traces.js.map +0 -1
- package/dist/extensions/long-running/constraints.d.ts +0 -38
- package/dist/extensions/long-running/constraints.d.ts.map +0 -1
- package/dist/extensions/long-running/constraints.js +0 -153
- package/dist/extensions/long-running/constraints.js.map +0 -1
- package/dist/extensions/long-running/index.d.ts +0 -30
- package/dist/extensions/long-running/index.d.ts.map +0 -1
- package/dist/extensions/long-running/index.js +0 -50
- package/dist/extensions/long-running/index.js.map +0 -1
- package/dist/extensions/long-running/types.d.ts +0 -154
- package/dist/extensions/long-running/types.d.ts.map +0 -1
- package/dist/extensions/long-running/types.js +0 -9
- package/dist/extensions/long-running/types.js.map +0 -1
- package/dist/presets/long-running.d.ts +0 -33
- package/dist/presets/long-running.d.ts.map +0 -1
- package/dist/presets/long-running.js +0 -52
- package/dist/presets/long-running.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 约束分层类型定义
|
|
3
|
+
*
|
|
4
|
+
* 在原有 Constraint 基础上增加分层和退化元数据
|
|
5
|
+
*/
|
|
6
|
+
import type { Constraint, ConstraintLevel } from '../types/constraint';
|
|
7
|
+
/** 约束分层 */
|
|
8
|
+
export type ConstraintLayer = 'safety' | 'quality';
|
|
9
|
+
/** 退化状态 */
|
|
10
|
+
export type DeprecationStatus = 'active' | 'scheduled' | 'deprecated' | 'removed';
|
|
11
|
+
/** 退化计划 */
|
|
12
|
+
export interface DeprecationSchedule {
|
|
13
|
+
/** 目标级别(当前 → 目标) */
|
|
14
|
+
targetLevel: ConstraintLevel;
|
|
15
|
+
/** 触发条件:拦截率低于此值时触发退化 */
|
|
16
|
+
interceptRateThreshold?: number;
|
|
17
|
+
/** 计划退化日期 */
|
|
18
|
+
scheduledDate?: string;
|
|
19
|
+
/** 退化原因 */
|
|
20
|
+
reason: string;
|
|
21
|
+
/** 是否可回滚 */
|
|
22
|
+
rollbackable: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** 带分层元数据的约束 */
|
|
25
|
+
export interface LayeredConstraint extends Constraint {
|
|
26
|
+
/** 所属层 */
|
|
27
|
+
layer: ConstraintLayer;
|
|
28
|
+
/** 退化状态 */
|
|
29
|
+
deprecationStatus: DeprecationStatus;
|
|
30
|
+
/** 退化计划(quality 层才有) */
|
|
31
|
+
deprecationSchedule?: DeprecationSchedule;
|
|
32
|
+
/** 是否永久保留(safety 层) */
|
|
33
|
+
permanent?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** 约束拦截统计 */
|
|
36
|
+
export interface ConstraintStats {
|
|
37
|
+
constraintId: string;
|
|
38
|
+
triggerCount: number;
|
|
39
|
+
passCount: number;
|
|
40
|
+
interceptCount: number;
|
|
41
|
+
interceptRate: number;
|
|
42
|
+
lastTriggered?: string;
|
|
43
|
+
}
|
|
44
|
+
/** 约束层统计汇总 */
|
|
45
|
+
export interface LayerStats {
|
|
46
|
+
layer: ConstraintLayer;
|
|
47
|
+
totalConstraints: number;
|
|
48
|
+
active: number;
|
|
49
|
+
scheduled: number;
|
|
50
|
+
deprecated: number;
|
|
51
|
+
removed: number;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
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AS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/constraints/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话压缩
|
|
3
|
+
*
|
|
4
|
+
* 三档策略:eviction / summary / checkpoint
|
|
5
|
+
* 不调用 LLM,零 token 成本
|
|
6
|
+
*/
|
|
7
|
+
import type { CompactionConfig, CompactionLevel, SessionMessage } from './types';
|
|
8
|
+
export interface CompactionResult {
|
|
9
|
+
compacted: SessionMessage[];
|
|
10
|
+
summary?: string;
|
|
11
|
+
level: CompactionLevel;
|
|
12
|
+
originalTokens: number;
|
|
13
|
+
compactedTokens: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class SessionCompaction {
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config?: Partial<CompactionConfig>);
|
|
18
|
+
/**
|
|
19
|
+
* 检查是否需要压缩
|
|
20
|
+
*/
|
|
21
|
+
shouldCompact(messages: SessionMessage[], budget: number): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 执行压缩
|
|
24
|
+
*/
|
|
25
|
+
compact(messages: SessionMessage[], budget: number): CompactionResult;
|
|
26
|
+
/**
|
|
27
|
+
* 轻量压缩:按比例丢最早消息,保留 tool-call 边界对
|
|
28
|
+
*/
|
|
29
|
+
private evictionCompact;
|
|
30
|
+
/**
|
|
31
|
+
* 中等压缩:结构化总结 + 保留最近 N 轮
|
|
32
|
+
*/
|
|
33
|
+
private summaryCompact;
|
|
34
|
+
/**
|
|
35
|
+
* 重型压缩:checkpoint + 清空历史
|
|
36
|
+
*/
|
|
37
|
+
private checkpointCompact;
|
|
38
|
+
/**
|
|
39
|
+
* 生成结构化摘要(零 LLM 成本)
|
|
40
|
+
*/
|
|
41
|
+
generateStructuredSummary(messages: SessionMessage[]): string;
|
|
42
|
+
/**
|
|
43
|
+
* 保留 tool-call 边界对
|
|
44
|
+
*
|
|
45
|
+
* 如果 tool 结果被保留,对应的 tool 调用也要保留
|
|
46
|
+
*/
|
|
47
|
+
private preserveToolCallPairs;
|
|
48
|
+
/**
|
|
49
|
+
* 估算消息的 token 数
|
|
50
|
+
*/
|
|
51
|
+
private estimateMessages;
|
|
52
|
+
/**
|
|
53
|
+
* 获取配置
|
|
54
|
+
*/
|
|
55
|
+
getConfig(): CompactionConfig;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=compaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/context/compaction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGjF,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,eAAe,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAI9C;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAKlE;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB;IAerE;;OAEG;IACH,OAAO,CAAC,eAAe;IAyBvB;;OAEG;IACH,OAAO,CAAC,cAAc;IA2BtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;OAEG;IACH,yBAAyB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM;IA4B7D;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAkB7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;IACH,SAAS,IAAI,gBAAgB;CAG9B"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 会话压缩
|
|
4
|
+
*
|
|
5
|
+
* 三档策略:eviction / summary / checkpoint
|
|
6
|
+
* 不调用 LLM,零 token 成本
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SessionCompaction = void 0;
|
|
10
|
+
const token_budget_1 = require("./token-budget");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
class SessionCompaction {
|
|
13
|
+
config;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = { ...types_1.DEFAULT_COMPACTION_CONFIG, ...config };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 检查是否需要压缩
|
|
19
|
+
*/
|
|
20
|
+
shouldCompact(messages, budget) {
|
|
21
|
+
const totalTokens = this.estimateMessages(messages);
|
|
22
|
+
return totalTokens / budget > this.config.triggerRatio;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 执行压缩
|
|
26
|
+
*/
|
|
27
|
+
compact(messages, budget) {
|
|
28
|
+
const originalTokens = this.estimateMessages(messages);
|
|
29
|
+
switch (this.config.level) {
|
|
30
|
+
case 'eviction':
|
|
31
|
+
return this.evictionCompact(messages, budget, originalTokens);
|
|
32
|
+
case 'summary':
|
|
33
|
+
return this.summaryCompact(messages, budget, originalTokens);
|
|
34
|
+
case 'checkpoint':
|
|
35
|
+
return this.checkpointCompact(messages, budget, originalTokens);
|
|
36
|
+
default:
|
|
37
|
+
return this.evictionCompact(messages, budget, originalTokens);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 轻量压缩:按比例丢最早消息,保留 tool-call 边界对
|
|
42
|
+
*/
|
|
43
|
+
evictionCompact(messages, budget, originalTokens) {
|
|
44
|
+
const targetTokens = Math.floor(budget * 0.6); // 目标压缩到 60%
|
|
45
|
+
const keepRatio = targetTokens / originalTokens;
|
|
46
|
+
// 至少保留最近 2 条
|
|
47
|
+
const minKeep = Math.min(2, messages.length);
|
|
48
|
+
const keepCount = Math.max(minKeep, Math.floor(messages.length * keepRatio));
|
|
49
|
+
let compacted = messages.slice(-keepCount);
|
|
50
|
+
// 保留 tool-call 边界对
|
|
51
|
+
if (this.config.preserveToolCallPairs) {
|
|
52
|
+
compacted = this.preserveToolCallPairs(messages, compacted);
|
|
53
|
+
}
|
|
54
|
+
const compactedTokens = this.estimateMessages(compacted);
|
|
55
|
+
return {
|
|
56
|
+
compacted,
|
|
57
|
+
level: 'eviction',
|
|
58
|
+
originalTokens,
|
|
59
|
+
compactedTokens,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 中等压缩:结构化总结 + 保留最近 N 轮
|
|
64
|
+
*/
|
|
65
|
+
summaryCompact(messages, budget, originalTokens) {
|
|
66
|
+
const recentCount = Math.min(6, messages.length); // 保留最近 6 条
|
|
67
|
+
const recent = messages.slice(-recentCount);
|
|
68
|
+
const older = messages.slice(0, -recentCount);
|
|
69
|
+
// 生成结构化摘要
|
|
70
|
+
const summary = this.generateStructuredSummary(older);
|
|
71
|
+
// 摘要作为系统消息插入
|
|
72
|
+
const summarySessionMessage = {
|
|
73
|
+
role: 'assistant',
|
|
74
|
+
content: `[会话摘要]\n${summary}`,
|
|
75
|
+
timestamp: new Date().toISOString(),
|
|
76
|
+
};
|
|
77
|
+
const compacted = [summarySessionMessage, ...recent];
|
|
78
|
+
const compactedTokens = this.estimateMessages(compacted);
|
|
79
|
+
return {
|
|
80
|
+
compacted,
|
|
81
|
+
summary,
|
|
82
|
+
level: 'summary',
|
|
83
|
+
originalTokens,
|
|
84
|
+
compactedTokens,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 重型压缩:checkpoint + 清空历史
|
|
89
|
+
*/
|
|
90
|
+
checkpointCompact(messages, budget, originalTokens) {
|
|
91
|
+
const summary = this.generateStructuredSummary(messages);
|
|
92
|
+
const checkpointSessionMessage = {
|
|
93
|
+
role: 'assistant',
|
|
94
|
+
content: `[Checkpoint]\n${summary}\n\n[历史已压缩,共 ${messages.length} 条消息]`,
|
|
95
|
+
timestamp: new Date().toISOString(),
|
|
96
|
+
};
|
|
97
|
+
const compacted = [checkpointSessionMessage];
|
|
98
|
+
const compactedTokens = this.estimateMessages(compacted);
|
|
99
|
+
return {
|
|
100
|
+
compacted,
|
|
101
|
+
summary,
|
|
102
|
+
level: 'checkpoint',
|
|
103
|
+
originalTokens,
|
|
104
|
+
compactedTokens,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 生成结构化摘要(零 LLM 成本)
|
|
109
|
+
*/
|
|
110
|
+
generateStructuredSummary(messages) {
|
|
111
|
+
const sections = [];
|
|
112
|
+
// 提取用户目标
|
|
113
|
+
const userSessionMessages = messages.filter(m => m.role === 'user');
|
|
114
|
+
if (userSessionMessages.length > 0) {
|
|
115
|
+
sections.push(`用户目标: ${userSessionMessages[0].content.slice(0, 200)}`);
|
|
116
|
+
}
|
|
117
|
+
// 提取工具调用
|
|
118
|
+
const toolCalls = messages.filter(m => m.role === 'tool');
|
|
119
|
+
if (toolCalls.length > 0) {
|
|
120
|
+
sections.push(`工具调用: ${toolCalls.length} 次`);
|
|
121
|
+
}
|
|
122
|
+
// 提取关键信息
|
|
123
|
+
const assistantSessionMessages = messages.filter(m => m.role === 'assistant');
|
|
124
|
+
if (assistantSessionMessages.length > 0) {
|
|
125
|
+
const lastAssistant = assistantSessionMessages[assistantSessionMessages.length - 1];
|
|
126
|
+
sections.push(`最近响应: ${lastAssistant.content.slice(0, 200)}`);
|
|
127
|
+
}
|
|
128
|
+
sections.push(`消息总数: ${messages.length}`);
|
|
129
|
+
sections.push(`时间范围: ${messages[0]?.timestamp || 'N/A'} → ${messages[messages.length - 1]?.timestamp || 'N/A'}`);
|
|
130
|
+
return sections.join('\n');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 保留 tool-call 边界对
|
|
134
|
+
*
|
|
135
|
+
* 如果 tool 结果被保留,对应的 tool 调用也要保留
|
|
136
|
+
*/
|
|
137
|
+
preserveToolCallPairs(all, compacted) {
|
|
138
|
+
const compactedIds = new Set(compacted.map(m => m.toolCallId).filter(Boolean));
|
|
139
|
+
const result = [];
|
|
140
|
+
for (const msg of compacted) {
|
|
141
|
+
// 如果是 tool 结果,确保对应的 tool 调用也在
|
|
142
|
+
if (msg.role === 'tool' && msg.toolCallId) {
|
|
143
|
+
const paired = all.find(m => m.toolCallId === msg.toolCallId && m.role === 'assistant');
|
|
144
|
+
if (paired && !compacted.some(m => m === paired)) {
|
|
145
|
+
result.push(paired);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
result.push(msg);
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 估算消息的 token 数
|
|
154
|
+
*/
|
|
155
|
+
estimateMessages(messages) {
|
|
156
|
+
return messages.reduce((sum, m) => sum + token_budget_1.TokenEstimator.estimateText(m.content), 0);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 获取配置
|
|
160
|
+
*/
|
|
161
|
+
getConfig() {
|
|
162
|
+
return { ...this.config };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.SessionCompaction = SessionCompaction;
|
|
166
|
+
//# sourceMappingURL=compaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/context/compaction.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iDAAgD;AAEhD,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AAU,EAAE,CAAC;gBAC1C,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;gBACxF,IAAI,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC;oBACjD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,QAA0B;QACjD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,6BAAc,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACtF,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAtLD,8CAsLC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件读取预算
|
|
3
|
+
*
|
|
4
|
+
* 按行数、字节数、Token 数三重限制读取文件
|
|
5
|
+
* 超限时生成 continuationHint 提示 offset
|
|
6
|
+
*/
|
|
7
|
+
import type { FileBudgetConfig } from './types';
|
|
8
|
+
export interface FileCheckResult {
|
|
9
|
+
allowed: boolean;
|
|
10
|
+
reason?: string;
|
|
11
|
+
lineCount?: number;
|
|
12
|
+
byteCount?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface FileReadResult {
|
|
15
|
+
content: string;
|
|
16
|
+
truncated: boolean;
|
|
17
|
+
linesRead: number;
|
|
18
|
+
bytesRead: number;
|
|
19
|
+
tokensEstimate: number;
|
|
20
|
+
continuationHint?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class FileBudget {
|
|
23
|
+
private config;
|
|
24
|
+
constructor(config?: Partial<FileBudgetConfig>);
|
|
25
|
+
/**
|
|
26
|
+
* 检查文件是否在预算内(stat 检查)
|
|
27
|
+
*/
|
|
28
|
+
checkFile(filePath: string): FileCheckResult;
|
|
29
|
+
/**
|
|
30
|
+
* 按预算读取文件
|
|
31
|
+
*
|
|
32
|
+
* 三重限制:行数 → 字节数 → Token 数
|
|
33
|
+
*/
|
|
34
|
+
readWithBudget(filePath: string, config?: Partial<FileBudgetConfig>): FileReadResult;
|
|
35
|
+
/**
|
|
36
|
+
* 获取当前配置
|
|
37
|
+
*/
|
|
38
|
+
getConfig(): FileBudgetConfig;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=file-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-budget.d.ts","sourceRoot":"","sources":["../../src/context/file-budget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAI9C;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe;IAqB5C;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,cAAc;IAuEpF;;OAEG;IACH,SAAS,IAAI,gBAAgB;CAG9B"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 文件读取预算
|
|
4
|
+
*
|
|
5
|
+
* 按行数、字节数、Token 数三重限制读取文件
|
|
6
|
+
* 超限时生成 continuationHint 提示 offset
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.FileBudget = void 0;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const token_budget_1 = require("./token-budget");
|
|
45
|
+
const types_1 = require("./types");
|
|
46
|
+
class FileBudget {
|
|
47
|
+
config;
|
|
48
|
+
constructor(config) {
|
|
49
|
+
this.config = { ...types_1.DEFAULT_FILE_BUDGET, ...config };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 检查文件是否在预算内(stat 检查)
|
|
53
|
+
*/
|
|
54
|
+
checkFile(filePath) {
|
|
55
|
+
try {
|
|
56
|
+
const stat = fs.statSync(filePath);
|
|
57
|
+
if (stat.size > this.config.maxBytes) {
|
|
58
|
+
return {
|
|
59
|
+
allowed: false,
|
|
60
|
+
reason: `文件大小 ${(stat.size / 1024).toFixed(1)}KB 超过限制 ${(this.config.maxBytes / 1024).toFixed(1)}KB`,
|
|
61
|
+
byteCount: stat.size,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return { allowed: true, byteCount: stat.size };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
allowed: false,
|
|
69
|
+
reason: `无法读取文件: ${error.message}`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 按预算读取文件
|
|
75
|
+
*
|
|
76
|
+
* 三重限制:行数 → 字节数 → Token 数
|
|
77
|
+
*/
|
|
78
|
+
readWithBudget(filePath, config) {
|
|
79
|
+
const effectiveConfig = { ...this.config, ...config };
|
|
80
|
+
try {
|
|
81
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
82
|
+
const lines = content.split('\n');
|
|
83
|
+
let truncated = false;
|
|
84
|
+
let selectedLines = lines;
|
|
85
|
+
let continuationHint;
|
|
86
|
+
// 限制 1: 行数
|
|
87
|
+
if (lines.length > effectiveConfig.maxLines) {
|
|
88
|
+
selectedLines = lines.slice(0, effectiveConfig.maxLines);
|
|
89
|
+
truncated = true;
|
|
90
|
+
if (effectiveConfig.continuationHint) {
|
|
91
|
+
continuationHint = `文件被截断。已读取 ${effectiveConfig.maxLines} 行,共 ${lines.length} 行。使用 offset=${effectiveConfig.maxLines} 继续读取。`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
let result = selectedLines.join('\n');
|
|
95
|
+
// 限制 2: 字节数
|
|
96
|
+
const byteCount = Buffer.byteLength(result, 'utf-8');
|
|
97
|
+
if (byteCount > effectiveConfig.maxBytes) {
|
|
98
|
+
const encoder = new TextEncoder();
|
|
99
|
+
const bytes = encoder.encode(result);
|
|
100
|
+
const truncatedBytes = bytes.slice(0, effectiveConfig.maxBytes);
|
|
101
|
+
result = new TextDecoder().decode(truncatedBytes);
|
|
102
|
+
truncated = true;
|
|
103
|
+
if (!continuationHint && effectiveConfig.continuationHint) {
|
|
104
|
+
continuationHint = `文件内容被截断。已读取 ${effectiveConfig.maxBytes} 字节。`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// 限制 3: Token 数
|
|
108
|
+
const tokensEstimate = token_budget_1.TokenEstimator.estimateText(result);
|
|
109
|
+
if (tokensEstimate > effectiveConfig.maxTokenEstimate) {
|
|
110
|
+
// 按比例截断
|
|
111
|
+
const ratio = effectiveConfig.maxTokenEstimate / tokensEstimate;
|
|
112
|
+
const charLimit = Math.floor(result.length * ratio);
|
|
113
|
+
result = result.slice(0, charLimit);
|
|
114
|
+
truncated = true;
|
|
115
|
+
if (!continuationHint && effectiveConfig.continuationHint) {
|
|
116
|
+
continuationHint = `文件内容被截断。已读取约 ${effectiveConfig.maxTokenEstimate} tokens。`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
content: result,
|
|
121
|
+
truncated,
|
|
122
|
+
linesRead: selectedLines.length,
|
|
123
|
+
bytesRead: Buffer.byteLength(result, 'utf-8'),
|
|
124
|
+
tokensEstimate: token_budget_1.TokenEstimator.estimateText(result),
|
|
125
|
+
continuationHint,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
return {
|
|
130
|
+
content: '',
|
|
131
|
+
truncated: false,
|
|
132
|
+
linesRead: 0,
|
|
133
|
+
bytesRead: 0,
|
|
134
|
+
tokensEstimate: 0,
|
|
135
|
+
continuationHint: `无法读取文件: ${error.message}`,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 获取当前配置
|
|
141
|
+
*/
|
|
142
|
+
getConfig() {
|
|
143
|
+
return { ...this.config };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.FileBudget = FileBudget;
|
|
147
|
+
//# sourceMappingURL=file-budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-budget.js","sourceRoot":"","sources":["../../src/context/file-budget.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,iDAAgD;AAEhD,mCAA8C;AAkB9C,MAAa,UAAU;IACb,MAAM,CAAmB;IAEjC,YAAY,MAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,2BAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,QAAgB;QACxB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAA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AAC;gBACpC,SAAS,GAAG,IAAI,CAAC;gBAEjB,IAAI,CAAC,gBAAgB,IAAI,eAAe,CAAC,gBAAgB,EAAE,CAAC;oBAC1D,gBAAgB,GAAG,gBAAgB,eAAe,CAAC,gBAAgB,UAAU,CAAC;gBAChF,CAAC;YACH,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,MAAM;gBACf,SAAS;gBACT,SAAS,EAAE,aAAa,CAAC,MAAM;gBAC/B,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;gBAC7C,cAAc,EAAE,6BAAc,CAAC,YAAY,CAAC,MAAM,CAAC;gBACnD,gBAAgB;aACjB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,SAAS,EAAE,KAAK;gBAChB,SAAS,EAAE,CAAC;gBACZ,SAAS,EAAE,CAAC;gBACZ,cAAc,EAAE,CAAC;gBACjB,gBAAgB,EAAE,WAAY,KAAe,CAAC,OAAO,EAAE;aACxD,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAjHD,gCAiHC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上下文管理模块
|
|
3
|
+
*
|
|
4
|
+
* Phase 2: Token 流水线 + 预算 + 压缩
|
|
5
|
+
*/
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './token-budget';
|
|
8
|
+
export * from './progressive-loader';
|
|
9
|
+
export * from './file-budget';
|
|
10
|
+
export * from './tool-output-budget';
|
|
11
|
+
export * from './compaction';
|
|
12
|
+
export * from './token-pipeline';
|
|
13
|
+
export * from './session-manager';
|
|
14
|
+
export * from './knowledge-injector';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 上下文管理模块
|
|
4
|
+
*
|
|
5
|
+
* Phase 2: Token 流水线 + 预算 + 压缩
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./token-budget"), exports);
|
|
24
|
+
__exportStar(require("./progressive-loader"), exports);
|
|
25
|
+
__exportStar(require("./file-budget"), exports);
|
|
26
|
+
__exportStar(require("./tool-output-budget"), exports);
|
|
27
|
+
__exportStar(require("./compaction"), exports);
|
|
28
|
+
__exportStar(require("./token-pipeline"), exports);
|
|
29
|
+
__exportStar(require("./session-manager"), exports);
|
|
30
|
+
__exportStar(require("./knowledge-injector"), exports);
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,iDAA+B;AAC/B,uDAAqC;AACrC,gDAA8B;AAC9B,uDAAqC;AACrC,+CAA6B;AAC7B,mDAAiC;AACjC,oDAAkC;AAClC,uDAAqC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 知识注入器
|
|
3
|
+
*
|
|
4
|
+
* 将知识条目转换为 ContextSource,注入到 TokenPipeline 的 P3 位置
|
|
5
|
+
* 支持按阶段预算、类型过滤、去重
|
|
6
|
+
*/
|
|
7
|
+
import { KnowledgeQuery } from '../knowledge/query';
|
|
8
|
+
import type { KnowledgeEntry, KnowledgeType } from '../knowledge/types';
|
|
9
|
+
import type { ContextSource } from './types';
|
|
10
|
+
export interface InjectionConfig {
|
|
11
|
+
/** Token 预算(默认 800) */
|
|
12
|
+
budget: number;
|
|
13
|
+
/** 关注的知识类型 */
|
|
14
|
+
focusTypes?: KnowledgeType[];
|
|
15
|
+
/** 当前阶段 */
|
|
16
|
+
phase?: string;
|
|
17
|
+
/** 已注入的条目 ID(去重) */
|
|
18
|
+
exclude?: string[];
|
|
19
|
+
/** 是否注入摘要版本(已注入的条目) */
|
|
20
|
+
injectSummaryForExcluded?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface InjectionResult {
|
|
23
|
+
sources: ContextSource[];
|
|
24
|
+
tokensUsed: number;
|
|
25
|
+
entriesIncluded: number;
|
|
26
|
+
entriesExcluded: number;
|
|
27
|
+
entriesSummarized: number;
|
|
28
|
+
}
|
|
29
|
+
export declare class KnowledgeInjector {
|
|
30
|
+
private query;
|
|
31
|
+
constructor(query: KnowledgeQuery);
|
|
32
|
+
/**
|
|
33
|
+
* 注入知识到上下文
|
|
34
|
+
*/
|
|
35
|
+
inject(config: InjectionConfig): InjectionResult;
|
|
36
|
+
/**
|
|
37
|
+
* 将知识条目格式化为上下文内容
|
|
38
|
+
*/
|
|
39
|
+
formatEntry(entry: KnowledgeEntry): string;
|
|
40
|
+
/**
|
|
41
|
+
* 将知识条目格式化为摘要(一行)
|
|
42
|
+
*/
|
|
43
|
+
formatEntrySummary(entry: KnowledgeEntry): string;
|
|
44
|
+
/**
|
|
45
|
+
* 获取查询引擎
|
|
46
|
+
*/
|
|
47
|
+
getQuery(): KnowledgeQuery;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=knowledge-injector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-injector.d.ts","sourceRoot":"","sources":["../../src/context/knowledge-injector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAe,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,eAAe;IAC9B,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc;IACd,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,WAAW;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,uBAAuB;IACvB,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAiB;gBAElB,KAAK,EAAE,cAAc;IAIjC;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe;IA4FhD;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM;IAgB1C;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM;IAIjD;;OAEG;IACH,QAAQ,IAAI,cAAc;CAG3B"}
|