@compilr-dev/agents 0.0.1
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 +1277 -0
- package/dist/agent.d.ts +1272 -0
- package/dist/agent.js +1912 -0
- package/dist/anchors/builtin.d.ts +24 -0
- package/dist/anchors/builtin.js +61 -0
- package/dist/anchors/index.d.ts +6 -0
- package/dist/anchors/index.js +5 -0
- package/dist/anchors/manager.d.ts +115 -0
- package/dist/anchors/manager.js +412 -0
- package/dist/anchors/types.d.ts +168 -0
- package/dist/anchors/types.js +10 -0
- package/dist/context/index.d.ts +12 -0
- package/dist/context/index.js +10 -0
- package/dist/context/manager.d.ts +224 -0
- package/dist/context/manager.js +770 -0
- package/dist/context/types.d.ts +377 -0
- package/dist/context/types.js +7 -0
- package/dist/costs/index.d.ts +8 -0
- package/dist/costs/index.js +7 -0
- package/dist/costs/tracker.d.ts +121 -0
- package/dist/costs/tracker.js +295 -0
- package/dist/costs/types.d.ts +157 -0
- package/dist/costs/types.js +8 -0
- package/dist/errors.d.ts +178 -0
- package/dist/errors.js +249 -0
- package/dist/guardrails/builtin.d.ts +27 -0
- package/dist/guardrails/builtin.js +223 -0
- package/dist/guardrails/index.d.ts +6 -0
- package/dist/guardrails/index.js +5 -0
- package/dist/guardrails/manager.d.ts +117 -0
- package/dist/guardrails/manager.js +288 -0
- package/dist/guardrails/types.d.ts +159 -0
- package/dist/guardrails/types.js +7 -0
- package/dist/hooks/index.d.ts +31 -0
- package/dist/hooks/index.js +29 -0
- package/dist/hooks/manager.d.ts +147 -0
- package/dist/hooks/manager.js +600 -0
- package/dist/hooks/types.d.ts +368 -0
- package/dist/hooks/types.js +12 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +73 -0
- package/dist/mcp/client.d.ts +93 -0
- package/dist/mcp/client.js +287 -0
- package/dist/mcp/errors.d.ts +60 -0
- package/dist/mcp/errors.js +78 -0
- package/dist/mcp/index.d.ts +43 -0
- package/dist/mcp/index.js +45 -0
- package/dist/mcp/manager.d.ts +120 -0
- package/dist/mcp/manager.js +276 -0
- package/dist/mcp/tools.d.ts +54 -0
- package/dist/mcp/tools.js +99 -0
- package/dist/mcp/types.d.ts +150 -0
- package/dist/mcp/types.js +40 -0
- package/dist/memory/index.d.ts +8 -0
- package/dist/memory/index.js +7 -0
- package/dist/memory/loader.d.ts +114 -0
- package/dist/memory/loader.js +463 -0
- package/dist/memory/types.d.ts +182 -0
- package/dist/memory/types.js +8 -0
- package/dist/messages/index.d.ts +82 -0
- package/dist/messages/index.js +155 -0
- package/dist/permissions/index.d.ts +5 -0
- package/dist/permissions/index.js +4 -0
- package/dist/permissions/manager.d.ts +125 -0
- package/dist/permissions/manager.js +379 -0
- package/dist/permissions/types.d.ts +162 -0
- package/dist/permissions/types.js +7 -0
- package/dist/providers/claude.d.ts +90 -0
- package/dist/providers/claude.js +348 -0
- package/dist/providers/index.d.ts +8 -0
- package/dist/providers/index.js +11 -0
- package/dist/providers/mock.d.ts +133 -0
- package/dist/providers/mock.js +204 -0
- package/dist/providers/types.d.ts +168 -0
- package/dist/providers/types.js +4 -0
- package/dist/rate-limit/index.d.ts +45 -0
- package/dist/rate-limit/index.js +47 -0
- package/dist/rate-limit/limiter.d.ts +104 -0
- package/dist/rate-limit/limiter.js +326 -0
- package/dist/rate-limit/provider-wrapper.d.ts +112 -0
- package/dist/rate-limit/provider-wrapper.js +201 -0
- package/dist/rate-limit/retry.d.ts +108 -0
- package/dist/rate-limit/retry.js +287 -0
- package/dist/rate-limit/types.d.ts +181 -0
- package/dist/rate-limit/types.js +22 -0
- package/dist/rehearsal/file-analyzer.d.ts +22 -0
- package/dist/rehearsal/file-analyzer.js +351 -0
- package/dist/rehearsal/git-analyzer.d.ts +22 -0
- package/dist/rehearsal/git-analyzer.js +472 -0
- package/dist/rehearsal/index.d.ts +35 -0
- package/dist/rehearsal/index.js +36 -0
- package/dist/rehearsal/manager.d.ts +100 -0
- package/dist/rehearsal/manager.js +290 -0
- package/dist/rehearsal/types.d.ts +235 -0
- package/dist/rehearsal/types.js +8 -0
- package/dist/skills/index.d.ts +160 -0
- package/dist/skills/index.js +282 -0
- package/dist/state/agent-state.d.ts +41 -0
- package/dist/state/agent-state.js +88 -0
- package/dist/state/checkpointer.d.ts +110 -0
- package/dist/state/checkpointer.js +362 -0
- package/dist/state/errors.d.ts +66 -0
- package/dist/state/errors.js +88 -0
- package/dist/state/index.d.ts +35 -0
- package/dist/state/index.js +37 -0
- package/dist/state/serializer.d.ts +55 -0
- package/dist/state/serializer.js +172 -0
- package/dist/state/types.d.ts +312 -0
- package/dist/state/types.js +14 -0
- package/dist/tools/builtin/bash-output.d.ts +61 -0
- package/dist/tools/builtin/bash-output.js +90 -0
- package/dist/tools/builtin/bash.d.ts +150 -0
- package/dist/tools/builtin/bash.js +354 -0
- package/dist/tools/builtin/edit.d.ts +50 -0
- package/dist/tools/builtin/edit.js +215 -0
- package/dist/tools/builtin/glob.d.ts +62 -0
- package/dist/tools/builtin/glob.js +244 -0
- package/dist/tools/builtin/grep.d.ts +74 -0
- package/dist/tools/builtin/grep.js +363 -0
- package/dist/tools/builtin/index.d.ts +44 -0
- package/dist/tools/builtin/index.js +69 -0
- package/dist/tools/builtin/kill-shell.d.ts +44 -0
- package/dist/tools/builtin/kill-shell.js +80 -0
- package/dist/tools/builtin/read-file.d.ts +57 -0
- package/dist/tools/builtin/read-file.js +184 -0
- package/dist/tools/builtin/shell-manager.d.ts +176 -0
- package/dist/tools/builtin/shell-manager.js +337 -0
- package/dist/tools/builtin/task.d.ts +202 -0
- package/dist/tools/builtin/task.js +350 -0
- package/dist/tools/builtin/todo.d.ts +207 -0
- package/dist/tools/builtin/todo.js +453 -0
- package/dist/tools/builtin/utils.d.ts +27 -0
- package/dist/tools/builtin/utils.js +70 -0
- package/dist/tools/builtin/web-fetch.d.ts +96 -0
- package/dist/tools/builtin/web-fetch.js +290 -0
- package/dist/tools/builtin/write-file.d.ts +54 -0
- package/dist/tools/builtin/write-file.js +147 -0
- package/dist/tools/define.d.ts +60 -0
- package/dist/tools/define.js +65 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +37 -0
- package/dist/tools/registry.d.ts +79 -0
- package/dist/tools/registry.js +151 -0
- package/dist/tools/types.d.ts +59 -0
- package/dist/tools/types.js +4 -0
- package/dist/tracing/hooks.d.ts +58 -0
- package/dist/tracing/hooks.js +377 -0
- package/dist/tracing/index.d.ts +51 -0
- package/dist/tracing/index.js +55 -0
- package/dist/tracing/logging.d.ts +78 -0
- package/dist/tracing/logging.js +310 -0
- package/dist/tracing/manager.d.ts +160 -0
- package/dist/tracing/manager.js +468 -0
- package/dist/tracing/otel.d.ts +102 -0
- package/dist/tracing/otel.js +246 -0
- package/dist/tracing/types.d.ts +346 -0
- package/dist/tracing/types.js +38 -0
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.js +44 -0
- package/package.json +79 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anchors - Critical information that survives context compaction
|
|
3
|
+
*
|
|
4
|
+
* Anchors are pieces of information that:
|
|
5
|
+
* 1. Never get compacted - Survive all context management
|
|
6
|
+
* 2. Always re-injected - Present in every LLM call
|
|
7
|
+
* 3. Scoped - Session, persistent, or temporary
|
|
8
|
+
* 4. Prioritized - Critical, safety, or informational
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Priority levels for anchors
|
|
12
|
+
* - critical: Must remember, highest priority (e.g., "we just implemented X")
|
|
13
|
+
* - safety: Check before acting (e.g., "verify before git reset")
|
|
14
|
+
* - info: Useful context (e.g., "modified files this session")
|
|
15
|
+
*/
|
|
16
|
+
export type AnchorPriority = 'critical' | 'safety' | 'info';
|
|
17
|
+
/**
|
|
18
|
+
* Scope determines anchor lifetime
|
|
19
|
+
* - session: Lives for the current session only
|
|
20
|
+
* - persistent: Saved to disk, survives across sessions
|
|
21
|
+
* - temporary: Auto-expires after a duration or event
|
|
22
|
+
*/
|
|
23
|
+
export type AnchorScope = 'session' | 'persistent' | 'temporary';
|
|
24
|
+
/**
|
|
25
|
+
* An anchor - critical information that survives context compaction
|
|
26
|
+
*/
|
|
27
|
+
export interface Anchor {
|
|
28
|
+
/**
|
|
29
|
+
* Unique identifier for this anchor
|
|
30
|
+
*/
|
|
31
|
+
id: string;
|
|
32
|
+
/**
|
|
33
|
+
* The content to remember (injected into every LLM call)
|
|
34
|
+
*/
|
|
35
|
+
content: string;
|
|
36
|
+
/**
|
|
37
|
+
* Priority level determines display order and emphasis
|
|
38
|
+
*/
|
|
39
|
+
priority: AnchorPriority;
|
|
40
|
+
/**
|
|
41
|
+
* Scope determines lifetime and persistence behavior
|
|
42
|
+
*/
|
|
43
|
+
scope: AnchorScope;
|
|
44
|
+
/**
|
|
45
|
+
* When this anchor was created
|
|
46
|
+
*/
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
/**
|
|
49
|
+
* When this anchor expires (for temporary anchors)
|
|
50
|
+
*/
|
|
51
|
+
expiresAt?: Date;
|
|
52
|
+
/**
|
|
53
|
+
* Optional tags for filtering and grouping
|
|
54
|
+
*/
|
|
55
|
+
tags?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* Optional metadata for custom use
|
|
58
|
+
*/
|
|
59
|
+
metadata?: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Input for adding a new anchor (id and createdAt are auto-generated if not provided)
|
|
63
|
+
*/
|
|
64
|
+
export interface AnchorInput {
|
|
65
|
+
id?: string;
|
|
66
|
+
content: string;
|
|
67
|
+
priority: AnchorPriority;
|
|
68
|
+
scope: AnchorScope;
|
|
69
|
+
expiresAt?: Date;
|
|
70
|
+
tags?: string[];
|
|
71
|
+
metadata?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Options for querying anchors
|
|
75
|
+
*/
|
|
76
|
+
export interface AnchorQueryOptions {
|
|
77
|
+
/**
|
|
78
|
+
* Filter by priority level
|
|
79
|
+
*/
|
|
80
|
+
priority?: AnchorPriority;
|
|
81
|
+
/**
|
|
82
|
+
* Filter by scope
|
|
83
|
+
*/
|
|
84
|
+
scope?: AnchorScope;
|
|
85
|
+
/**
|
|
86
|
+
* Filter by tags (anchors must have ALL specified tags)
|
|
87
|
+
*/
|
|
88
|
+
tags?: string[];
|
|
89
|
+
/**
|
|
90
|
+
* Include expired temporary anchors (default: false)
|
|
91
|
+
*/
|
|
92
|
+
includeExpired?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Options for clearing anchors
|
|
96
|
+
*/
|
|
97
|
+
export interface AnchorClearOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Clear only anchors with this scope
|
|
100
|
+
*/
|
|
101
|
+
scope?: AnchorScope;
|
|
102
|
+
/**
|
|
103
|
+
* Clear only anchors with these tags
|
|
104
|
+
*/
|
|
105
|
+
tags?: string[];
|
|
106
|
+
/**
|
|
107
|
+
* Clear only expired anchors
|
|
108
|
+
*/
|
|
109
|
+
expiredOnly?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Configuration for the AnchorManager
|
|
113
|
+
*/
|
|
114
|
+
export interface AnchorManagerOptions {
|
|
115
|
+
/**
|
|
116
|
+
* Maximum number of anchors to keep (default: 20)
|
|
117
|
+
* When exceeded, oldest low-priority anchors are removed first
|
|
118
|
+
*/
|
|
119
|
+
maxAnchors?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Maximum tokens budget for anchors (default: 2000)
|
|
122
|
+
* Anchors exceeding this budget are truncated or removed
|
|
123
|
+
*/
|
|
124
|
+
maxTokens?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Path for persisting anchors (for scope: 'persistent')
|
|
127
|
+
* If not provided, persistent anchors work like session anchors
|
|
128
|
+
*/
|
|
129
|
+
persistPath?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Include built-in default safety anchors (default: true)
|
|
132
|
+
*/
|
|
133
|
+
includeDefaults?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Token estimator function (default: rough estimate based on chars)
|
|
136
|
+
*/
|
|
137
|
+
estimateTokens?: (content: string) => number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Serialized anchor for persistence
|
|
141
|
+
*/
|
|
142
|
+
export interface SerializedAnchor {
|
|
143
|
+
id: string;
|
|
144
|
+
content: string;
|
|
145
|
+
priority: AnchorPriority;
|
|
146
|
+
scope: AnchorScope;
|
|
147
|
+
createdAt: string;
|
|
148
|
+
expiresAt?: string;
|
|
149
|
+
tags?: string[];
|
|
150
|
+
metadata?: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Event types for anchor operations
|
|
154
|
+
*/
|
|
155
|
+
export type AnchorEventType = 'anchor:added' | 'anchor:removed' | 'anchor:expired' | 'anchor:budget_exceeded' | 'anchor:persisted' | 'anchor:loaded';
|
|
156
|
+
/**
|
|
157
|
+
* Anchor event payload
|
|
158
|
+
*/
|
|
159
|
+
export interface AnchorEvent {
|
|
160
|
+
type: AnchorEventType;
|
|
161
|
+
anchor?: Anchor;
|
|
162
|
+
anchors?: Anchor[];
|
|
163
|
+
message?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Event handler for anchor events
|
|
167
|
+
*/
|
|
168
|
+
export type AnchorEventHandler = (event: AnchorEvent) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anchors - Critical information that survives context compaction
|
|
3
|
+
*
|
|
4
|
+
* Anchors are pieces of information that:
|
|
5
|
+
* 1. Never get compacted - Survive all context management
|
|
6
|
+
* 2. Always re-injected - Present in every LLM call
|
|
7
|
+
* 3. Scoped - Session, persistent, or temporary
|
|
8
|
+
* 4. Prioritized - Critical, safety, or informational
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Management Module
|
|
3
|
+
*
|
|
4
|
+
* Provides context window management for agents, including:
|
|
5
|
+
* - Token tracking
|
|
6
|
+
* - Filtering (truncate large content)
|
|
7
|
+
* - Compaction (save to files, replace with references)
|
|
8
|
+
* - Summarization (compress history when near limit)
|
|
9
|
+
*/
|
|
10
|
+
export { ContextManager, DEFAULT_CONTEXT_CONFIG } from './manager.js';
|
|
11
|
+
export type { ContextManagerOptions } from './manager.js';
|
|
12
|
+
export type { ContextCategory, BudgetAllocation, CategoryBudgetInfo, PreflightResult, VerbosityLevel, VerbosityConfig, ContextConfig, FilteringConfig, CompactionConfig, SummarizationConfig, CompactionResult, SummarizationResult, FilteringResult, ContextEvent, ContextEventHandler, ContextStats, } from './types.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Management Module
|
|
3
|
+
*
|
|
4
|
+
* Provides context window management for agents, including:
|
|
5
|
+
* - Token tracking
|
|
6
|
+
* - Filtering (truncate large content)
|
|
7
|
+
* - Compaction (save to files, replace with references)
|
|
8
|
+
* - Summarization (compress history when near limit)
|
|
9
|
+
*/
|
|
10
|
+
export { ContextManager, DEFAULT_CONTEXT_CONFIG } from './manager.js';
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContextManager - Manages agent context windows
|
|
3
|
+
*
|
|
4
|
+
* Handles token tracking, compaction, summarization, and filtering
|
|
5
|
+
* to keep agent context within limits while preserving important information.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const contextManager = new ContextManager({
|
|
10
|
+
* provider,
|
|
11
|
+
* maxContextTokens: 200000,
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // Check if action needed
|
|
15
|
+
* if (contextManager.needsSummarization()) {
|
|
16
|
+
* await contextManager.summarize(messages);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { Message, LLMProvider } from '../providers/types.js';
|
|
21
|
+
import type { ContextConfig, ContextStats, CompactionResult, SummarizationResult, ContextEventHandler, ContextCategory, CategoryBudgetInfo, BudgetAllocation, PreflightResult, VerbosityLevel } from './types.js';
|
|
22
|
+
/**
|
|
23
|
+
* Default budget allocation
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_BUDGET_ALLOCATION: BudgetAllocation;
|
|
26
|
+
/**
|
|
27
|
+
* Default context configuration
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_CONTEXT_CONFIG: ContextConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Options for creating a ContextManager
|
|
32
|
+
*/
|
|
33
|
+
export interface ContextManagerOptions {
|
|
34
|
+
/**
|
|
35
|
+
* LLM provider (for token counting)
|
|
36
|
+
*/
|
|
37
|
+
provider: LLMProvider;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration overrides
|
|
40
|
+
*/
|
|
41
|
+
config?: Partial<ContextConfig>;
|
|
42
|
+
/**
|
|
43
|
+
* Event handler for context events
|
|
44
|
+
*/
|
|
45
|
+
onEvent?: ContextEventHandler;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* ContextManager tracks and manages context window usage
|
|
49
|
+
*/
|
|
50
|
+
export declare class ContextManager {
|
|
51
|
+
private readonly provider;
|
|
52
|
+
private readonly config;
|
|
53
|
+
private readonly onEvent?;
|
|
54
|
+
private cachedTokenCount;
|
|
55
|
+
private turnCount;
|
|
56
|
+
private compactionCount;
|
|
57
|
+
private summarizationCount;
|
|
58
|
+
private lastCompactionTurn;
|
|
59
|
+
private categoryUsage;
|
|
60
|
+
constructor(options: ContextManagerOptions);
|
|
61
|
+
/**
|
|
62
|
+
* Merge partial config with defaults
|
|
63
|
+
*/
|
|
64
|
+
private mergeConfig;
|
|
65
|
+
/**
|
|
66
|
+
* Emit a context event
|
|
67
|
+
*/
|
|
68
|
+
private emit;
|
|
69
|
+
/**
|
|
70
|
+
* Count tokens in messages using the provider
|
|
71
|
+
*/
|
|
72
|
+
countTokens(messages: Message[]): Promise<number>;
|
|
73
|
+
/**
|
|
74
|
+
* Update token count for messages
|
|
75
|
+
*/
|
|
76
|
+
updateTokenCount(messages: Message[]): Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Get current token count (cached)
|
|
79
|
+
*/
|
|
80
|
+
getTokenCount(): number;
|
|
81
|
+
/**
|
|
82
|
+
* Get context utilization (0.0 - 1.0)
|
|
83
|
+
*/
|
|
84
|
+
getUtilization(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Get maximum context tokens
|
|
87
|
+
*/
|
|
88
|
+
getMaxTokens(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Increment turn count (call after each assistant response)
|
|
91
|
+
*/
|
|
92
|
+
incrementTurn(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Check if compaction is needed
|
|
95
|
+
*/
|
|
96
|
+
needsCompaction(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Check if summarization is needed (more aggressive than compaction)
|
|
99
|
+
*/
|
|
100
|
+
needsSummarization(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Check if content should be filtered before adding
|
|
103
|
+
*/
|
|
104
|
+
shouldFilter(tokenCount: number): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Get context statistics
|
|
107
|
+
*/
|
|
108
|
+
getStats(messageCount: number): ContextStats;
|
|
109
|
+
/**
|
|
110
|
+
* Get the current configuration
|
|
111
|
+
*/
|
|
112
|
+
getConfig(): ContextConfig;
|
|
113
|
+
/**
|
|
114
|
+
* Get budget information for a specific category
|
|
115
|
+
*/
|
|
116
|
+
getCategoryBudget(category: ContextCategory): CategoryBudgetInfo;
|
|
117
|
+
/**
|
|
118
|
+
* Get budget information for all categories
|
|
119
|
+
*/
|
|
120
|
+
getAllBudgets(): Record<ContextCategory, CategoryBudgetInfo>;
|
|
121
|
+
/**
|
|
122
|
+
* Update token usage for a category
|
|
123
|
+
*/
|
|
124
|
+
updateCategoryUsage(category: ContextCategory, tokens: number): void;
|
|
125
|
+
/**
|
|
126
|
+
* Add tokens to a category
|
|
127
|
+
*/
|
|
128
|
+
addToCategory(category: ContextCategory, tokens: number): void;
|
|
129
|
+
/**
|
|
130
|
+
* Check if a specific category needs compaction
|
|
131
|
+
*/
|
|
132
|
+
categoryNeedsCompaction(category: ContextCategory): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Compact only a specific category
|
|
135
|
+
*
|
|
136
|
+
* This is more targeted than full compaction - only affects messages
|
|
137
|
+
* in the specified category, leaving others untouched.
|
|
138
|
+
*/
|
|
139
|
+
compactCategory(messages: Message[], category: ContextCategory, saveToFile: (content: string, index: number) => Promise<string>): Promise<{
|
|
140
|
+
messages: Message[];
|
|
141
|
+
result: CompactionResult;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Determine which category a message belongs to
|
|
145
|
+
*/
|
|
146
|
+
private categorizeMessage;
|
|
147
|
+
/**
|
|
148
|
+
* Estimate tokens for a string content
|
|
149
|
+
*/
|
|
150
|
+
estimateTokens(content: string): number;
|
|
151
|
+
/**
|
|
152
|
+
* Check if content can be added to a category
|
|
153
|
+
*
|
|
154
|
+
* Returns a pre-flight result with recommendations for action.
|
|
155
|
+
*/
|
|
156
|
+
canAddContent(estimatedTokens: number, category: ContextCategory): PreflightResult;
|
|
157
|
+
/**
|
|
158
|
+
* Get current verbosity level based on context utilization
|
|
159
|
+
*
|
|
160
|
+
* Tools should adapt their output based on this level.
|
|
161
|
+
*/
|
|
162
|
+
getVerbosityLevel(): VerbosityLevel;
|
|
163
|
+
/**
|
|
164
|
+
* Check if we're in minimal mode (critical context pressure)
|
|
165
|
+
*/
|
|
166
|
+
isMinimalMode(): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Check if emergency summarization is needed
|
|
169
|
+
*/
|
|
170
|
+
needsEmergencySummarization(): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Filter large content before adding to context
|
|
173
|
+
*
|
|
174
|
+
* Returns the filtered content and metadata about what was done.
|
|
175
|
+
* The caller is responsible for saving to file if needed.
|
|
176
|
+
*/
|
|
177
|
+
filterContent(content: string, type: 'tool_result' | 'file' | 'error'): {
|
|
178
|
+
content: string;
|
|
179
|
+
filtered: boolean;
|
|
180
|
+
originalLength: number;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Compact old messages by replacing large content with file references
|
|
184
|
+
*
|
|
185
|
+
* This is a placeholder - actual implementation requires file system access
|
|
186
|
+
* which will be provided by the Agent or CLI layer.
|
|
187
|
+
*/
|
|
188
|
+
compact(messages: Message[], saveToFile: (content: string, index: number) => Promise<string>): Promise<{
|
|
189
|
+
messages: Message[];
|
|
190
|
+
result: CompactionResult;
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Summarize conversation history
|
|
194
|
+
*
|
|
195
|
+
* This is a placeholder - actual implementation requires LLM call
|
|
196
|
+
* which will be orchestrated by the Agent layer.
|
|
197
|
+
*/
|
|
198
|
+
summarize(messages: Message[], generateSummary: (messages: Message[]) => Promise<string>): Promise<{
|
|
199
|
+
messages: Message[];
|
|
200
|
+
result: SummarizationResult;
|
|
201
|
+
}>;
|
|
202
|
+
/**
|
|
203
|
+
* Summarize with support for multiple rounds and emergency mode
|
|
204
|
+
*
|
|
205
|
+
* Will perform multiple summarization rounds if needed to reach target utilization.
|
|
206
|
+
* Throws ContextOverflowError if unable to reduce context sufficiently.
|
|
207
|
+
*/
|
|
208
|
+
summarizeWithRetry(messages: Message[], generateSummary: (messages: Message[]) => Promise<string>, options?: {
|
|
209
|
+
emergency?: boolean;
|
|
210
|
+
maxRounds?: number;
|
|
211
|
+
targetUtilization?: number;
|
|
212
|
+
}): Promise<{
|
|
213
|
+
messages: Message[];
|
|
214
|
+
result: SummarizationResult;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Check context and emit warning if needed
|
|
218
|
+
*/
|
|
219
|
+
checkAndWarn(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Reset context manager state (for new conversations)
|
|
222
|
+
*/
|
|
223
|
+
reset(): void;
|
|
224
|
+
}
|