@compilr-dev/agents 0.0.1 → 0.2.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/dist/agent.d.ts +188 -1
- package/dist/agent.js +284 -14
- package/dist/context/file-tracker.d.ts +156 -0
- package/dist/context/file-tracker.js +358 -0
- package/dist/context/file-tracking-hook.d.ts +29 -0
- package/dist/context/file-tracking-hook.js +103 -0
- package/dist/context/index.d.ts +5 -1
- package/dist/context/index.js +3 -0
- package/dist/context/manager.d.ts +69 -1
- package/dist/context/manager.js +304 -0
- package/dist/context/types.d.ts +95 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +11 -3
- package/dist/messages/index.d.ts +13 -0
- package/dist/messages/index.js +51 -0
- package/dist/permissions/manager.js +6 -1
- package/dist/providers/gemini.d.ts +91 -0
- package/dist/providers/gemini.js +138 -0
- package/dist/providers/index.d.ts +8 -0
- package/dist/providers/index.js +7 -3
- package/dist/providers/mock.js +8 -0
- package/dist/providers/ollama.d.ts +87 -0
- package/dist/providers/ollama.js +133 -0
- package/dist/providers/openai-compatible.d.ts +182 -0
- package/dist/providers/openai-compatible.js +357 -0
- package/dist/providers/openai.d.ts +93 -0
- package/dist/providers/openai.js +133 -0
- package/dist/skills/index.js +691 -0
- package/dist/tools/builtin/glob.d.ts +11 -0
- package/dist/tools/builtin/glob.js +44 -2
- package/dist/tools/builtin/grep.d.ts +11 -1
- package/dist/tools/builtin/grep.js +38 -2
- package/dist/tools/builtin/index.d.ts +6 -1
- package/dist/tools/builtin/index.js +7 -0
- package/dist/tools/builtin/suggest.d.ts +57 -0
- package/dist/tools/builtin/suggest.js +99 -0
- package/dist/tools/builtin/task.js +13 -8
- package/dist/tools/builtin/tool-names.d.ts +44 -0
- package/dist/tools/builtin/tool-names.js +51 -0
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +5 -1
- package/dist/tools/registry.d.ts +4 -0
- package/dist/tools/registry.js +9 -0
- package/package.json +2 -2
package/dist/agent.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { LLMProvider, Message, ChatOptions, StreamChunk } from './providers/types.js';
|
|
5
5
|
import type { Tool, ToolDefinition, ToolRegistry, ToolExecutionResult } from './tools/types.js';
|
|
6
|
-
import type { ContextStats, VerbosityLevel } from './context/types.js';
|
|
6
|
+
import type { ContextStats, VerbosityLevel, SmartCompactionResult } from './context/types.js';
|
|
7
7
|
import type { AgentState, Checkpointer, SessionMetadata } from './state/types.js';
|
|
8
8
|
import type { Anchor, AnchorInput, AnchorQueryOptions, AnchorClearOptions, AnchorManagerOptions } from './anchors/types.js';
|
|
9
9
|
import type { Guardrail, GuardrailInput, GuardrailResult, GuardrailManagerOptions } from './guardrails/types.js';
|
|
@@ -13,6 +13,7 @@ import type { UsageTrackerOptions, UsageStats, BudgetStatus, TokenUsage } from '
|
|
|
13
13
|
import type { HooksConfig } from './hooks/types.js';
|
|
14
14
|
import { PermissionManager } from './permissions/manager.js';
|
|
15
15
|
import { ContextManager } from './context/manager.js';
|
|
16
|
+
import { FileAccessTracker } from './context/file-tracker.js';
|
|
16
17
|
import { AnchorManager } from './anchors/manager.js';
|
|
17
18
|
import { GuardrailManager } from './guardrails/manager.js';
|
|
18
19
|
/**
|
|
@@ -125,6 +126,18 @@ export type AgentEvent = {
|
|
|
125
126
|
} | {
|
|
126
127
|
type: 'usage_budget_exceeded';
|
|
127
128
|
status: BudgetStatus;
|
|
129
|
+
} | {
|
|
130
|
+
type: 'suggest';
|
|
131
|
+
action: string;
|
|
132
|
+
reason?: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: 'iteration_limit_reached';
|
|
135
|
+
iteration: number;
|
|
136
|
+
maxIterations: number;
|
|
137
|
+
} | {
|
|
138
|
+
type: 'iteration_limit_extended';
|
|
139
|
+
newMaxIterations: number;
|
|
140
|
+
addedIterations: number;
|
|
128
141
|
};
|
|
129
142
|
/**
|
|
130
143
|
* Event handler function type
|
|
@@ -189,8 +202,36 @@ export interface AgentConfig {
|
|
|
189
202
|
* - 'error': Throw MaxIterationsError immediately
|
|
190
203
|
* - 'summarize': Generate a final summary response before throwing
|
|
191
204
|
* - 'continue': Return partial result without throwing (response will be empty)
|
|
205
|
+
*
|
|
206
|
+
* Note: If onIterationLimitReached callback is provided, it takes precedence.
|
|
192
207
|
*/
|
|
193
208
|
iterationLimitBehavior?: 'error' | 'summarize' | 'continue';
|
|
209
|
+
/**
|
|
210
|
+
* Callback invoked when the agent reaches its iteration limit.
|
|
211
|
+
* Allows the caller to decide whether to continue or stop.
|
|
212
|
+
*
|
|
213
|
+
* @param context - Information about the current state
|
|
214
|
+
* @returns Promise resolving to:
|
|
215
|
+
* - `false` to stop the agent gracefully
|
|
216
|
+
* - A positive number to continue with that many additional iterations
|
|
217
|
+
*
|
|
218
|
+
* If this callback is provided and returns a number, the agent will continue
|
|
219
|
+
* running with the extended iteration limit. This takes precedence over
|
|
220
|
+
* iterationLimitBehavior.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* onIterationLimitReached: async ({ iteration, toolCallCount }) => {
|
|
225
|
+
* const answer = await askUser(`Agent used ${iteration} iterations. Continue?`);
|
|
226
|
+
* return answer === 'yes' ? 50 : false; // Add 50 more or stop
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
onIterationLimitReached?: (context: {
|
|
231
|
+
iteration: number;
|
|
232
|
+
maxIterations: number;
|
|
233
|
+
toolCallCount: number;
|
|
234
|
+
}) => Promise<number | false>;
|
|
194
235
|
/**
|
|
195
236
|
* Chat options (model, temperature, etc.)
|
|
196
237
|
*/
|
|
@@ -199,6 +240,12 @@ export interface AgentConfig {
|
|
|
199
240
|
* Custom tool registry (optional, creates new one if not provided)
|
|
200
241
|
*/
|
|
201
242
|
toolRegistry?: ToolRegistry;
|
|
243
|
+
/**
|
|
244
|
+
* Default timeout for tool execution in milliseconds (default: 30000 = 30s).
|
|
245
|
+
* Set to 0 to disable timeout. Only used when toolRegistry is not provided.
|
|
246
|
+
* Sub-agents inherit this timeout from the parent agent.
|
|
247
|
+
*/
|
|
248
|
+
toolTimeoutMs?: number;
|
|
202
249
|
/**
|
|
203
250
|
* Context manager for tracking and managing context window usage.
|
|
204
251
|
* If not provided, context management is disabled.
|
|
@@ -428,6 +475,31 @@ export interface AgentConfig {
|
|
|
428
475
|
* ```
|
|
429
476
|
*/
|
|
430
477
|
hooks?: HooksConfig;
|
|
478
|
+
/**
|
|
479
|
+
* Enable file access tracking for context restoration hints.
|
|
480
|
+
*
|
|
481
|
+
* When enabled, the agent tracks which files were read, referenced (grep/glob),
|
|
482
|
+
* and modified during execution. After context compaction, these hints are
|
|
483
|
+
* injected to help the LLM understand what files it previously accessed.
|
|
484
|
+
*
|
|
485
|
+
* Requires contextManager to be set (hints are injected after compaction).
|
|
486
|
+
*
|
|
487
|
+
* @default false
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* const agent = new Agent({
|
|
492
|
+
* provider,
|
|
493
|
+
* contextManager: new ContextManager({ provider }),
|
|
494
|
+
* enableFileTracking: true, // Automatically track file accesses
|
|
495
|
+
* });
|
|
496
|
+
*
|
|
497
|
+
* // After compaction, the agent will inject hints like:
|
|
498
|
+
* // [Context compacted. Previously accessed files:]
|
|
499
|
+
* // Read (3 files): file1.ts (100 lines), file2.ts (50 lines)...
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
enableFileTracking?: boolean;
|
|
431
503
|
}
|
|
432
504
|
/**
|
|
433
505
|
* Options for a single run
|
|
@@ -449,6 +521,21 @@ export interface RunOptions {
|
|
|
449
521
|
* Event handler for this run (in addition to config handler)
|
|
450
522
|
*/
|
|
451
523
|
onEvent?: AgentEventHandler;
|
|
524
|
+
/**
|
|
525
|
+
* Filter tools for this run.
|
|
526
|
+
* - If provided, only these tool names will be available
|
|
527
|
+
* - Reduces token usage by not sending unused tool definitions
|
|
528
|
+
* - Tools must be registered with the agent
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* // Only allow file and search tools for this request
|
|
533
|
+
* await agent.run(message, {
|
|
534
|
+
* toolFilter: ['read_file', 'write_file', 'grep', 'glob'],
|
|
535
|
+
* });
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
toolFilter?: string[];
|
|
452
539
|
}
|
|
453
540
|
/**
|
|
454
541
|
* Agent run result
|
|
@@ -616,6 +703,7 @@ export declare class Agent {
|
|
|
616
703
|
private readonly contextManager?;
|
|
617
704
|
private readonly autoContextManagement;
|
|
618
705
|
private readonly onEvent?;
|
|
706
|
+
private readonly onIterationLimitReached?;
|
|
619
707
|
private readonly checkpointer?;
|
|
620
708
|
private readonly _sessionId;
|
|
621
709
|
private readonly autoCheckpoint;
|
|
@@ -655,6 +743,10 @@ export declare class Agent {
|
|
|
655
743
|
* Hooks manager for lifecycle hooks
|
|
656
744
|
*/
|
|
657
745
|
private readonly hooksManager?;
|
|
746
|
+
/**
|
|
747
|
+
* File access tracker for context restoration hints
|
|
748
|
+
*/
|
|
749
|
+
private readonly fileTracker?;
|
|
658
750
|
constructor(config: AgentConfig);
|
|
659
751
|
/**
|
|
660
752
|
* Create an agent with project memory loaded from files.
|
|
@@ -1033,6 +1125,11 @@ export declare class Agent {
|
|
|
1033
1125
|
* Get the current conversation history
|
|
1034
1126
|
*/
|
|
1035
1127
|
getHistory(): Message[];
|
|
1128
|
+
/**
|
|
1129
|
+
* Set the conversation history (for manual compaction/restoration)
|
|
1130
|
+
* Also updates the context manager's token count if configured.
|
|
1131
|
+
*/
|
|
1132
|
+
setHistory(messages: Message[]): Promise<this>;
|
|
1036
1133
|
/**
|
|
1037
1134
|
* Get the context manager (if configured)
|
|
1038
1135
|
*/
|
|
@@ -1045,6 +1142,96 @@ export declare class Agent {
|
|
|
1045
1142
|
* Get current verbosity level based on context pressure
|
|
1046
1143
|
*/
|
|
1047
1144
|
getVerbosityLevel(): VerbosityLevel;
|
|
1145
|
+
/**
|
|
1146
|
+
* Get the file access tracker (if file tracking is enabled)
|
|
1147
|
+
*/
|
|
1148
|
+
getFileTracker(): FileAccessTracker | undefined;
|
|
1149
|
+
/**
|
|
1150
|
+
* Format context restoration hints based on tracked file accesses.
|
|
1151
|
+
* Returns empty string if no files have been accessed or file tracking is disabled.
|
|
1152
|
+
*/
|
|
1153
|
+
formatRestorationHints(): string;
|
|
1154
|
+
/**
|
|
1155
|
+
* Inject context restoration hints into messages after compaction/summarization.
|
|
1156
|
+
* Modifies messages array in place if hints are available.
|
|
1157
|
+
*
|
|
1158
|
+
* @internal
|
|
1159
|
+
*/
|
|
1160
|
+
private injectRestorationHints;
|
|
1161
|
+
/**
|
|
1162
|
+
* Compact the conversation context to reduce token usage.
|
|
1163
|
+
*
|
|
1164
|
+
* This is the recommended way to trigger context compaction externally.
|
|
1165
|
+
* It handles:
|
|
1166
|
+
* 1. Summarizing older messages
|
|
1167
|
+
* 2. Repairing tool use/result pairing (prevents API errors)
|
|
1168
|
+
* 3. Injecting context restoration hints (if file tracking is enabled)
|
|
1169
|
+
* 4. Updating the conversation history
|
|
1170
|
+
*
|
|
1171
|
+
* @param options - Compaction options
|
|
1172
|
+
* @returns Compaction result with statistics
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```typescript
|
|
1176
|
+
* // Basic compaction
|
|
1177
|
+
* const result = await agent.compact();
|
|
1178
|
+
* console.log(`Reduced from ${result.originalTokens} to ${result.summaryTokens} tokens`);
|
|
1179
|
+
*
|
|
1180
|
+
* // Compaction without restoration hints
|
|
1181
|
+
* await agent.compact({ injectRestorationHints: false });
|
|
1182
|
+
*
|
|
1183
|
+
* // Emergency compaction (more aggressive)
|
|
1184
|
+
* await agent.compact({ emergency: true });
|
|
1185
|
+
* ```
|
|
1186
|
+
*/
|
|
1187
|
+
compact(options?: {
|
|
1188
|
+
/**
|
|
1189
|
+
* Inject file restoration hints after compaction.
|
|
1190
|
+
* Only applies if file tracking is enabled.
|
|
1191
|
+
* Default: true (if file tracking is enabled)
|
|
1192
|
+
*/
|
|
1193
|
+
injectRestorationHints?: boolean;
|
|
1194
|
+
/**
|
|
1195
|
+
* Use emergency mode (more aggressive summarization).
|
|
1196
|
+
* Default: auto-detect based on context utilization
|
|
1197
|
+
*/
|
|
1198
|
+
emergency?: boolean;
|
|
1199
|
+
/**
|
|
1200
|
+
* Target utilization after compaction (0-1).
|
|
1201
|
+
* Default: from context manager config (typically 0.5)
|
|
1202
|
+
*/
|
|
1203
|
+
targetUtilization?: number;
|
|
1204
|
+
/**
|
|
1205
|
+
* Use smart category-aware compaction instead of simple summarization.
|
|
1206
|
+
* Smart compaction:
|
|
1207
|
+
* - Preserves system and recent messages completely
|
|
1208
|
+
* - Saves large tool results to files
|
|
1209
|
+
* - Summarizes history with LLM
|
|
1210
|
+
* Default: true
|
|
1211
|
+
*/
|
|
1212
|
+
useSmartCompaction?: boolean;
|
|
1213
|
+
}): Promise<{
|
|
1214
|
+
/** Whether compaction was successful */
|
|
1215
|
+
success: boolean;
|
|
1216
|
+
/** Original token count */
|
|
1217
|
+
originalTokens: number;
|
|
1218
|
+
/** Token count after compaction */
|
|
1219
|
+
summaryTokens: number;
|
|
1220
|
+
/** Number of summarization rounds performed */
|
|
1221
|
+
rounds: number;
|
|
1222
|
+
/** Number of messages preserved (not summarized) */
|
|
1223
|
+
messagesPreserved: number;
|
|
1224
|
+
/** Whether restoration hints were injected */
|
|
1225
|
+
restorationHintsInjected: boolean;
|
|
1226
|
+
/** Number of orphaned tool_results removed */
|
|
1227
|
+
toolResultsRepaired: number;
|
|
1228
|
+
/** The generated summary (for debugging/display) */
|
|
1229
|
+
summary: string;
|
|
1230
|
+
/** Files created during smart compaction (tool results saved to files) */
|
|
1231
|
+
filesCreated?: string[];
|
|
1232
|
+
/** Category-specific statistics (only for smart compaction) */
|
|
1233
|
+
categoryStats?: SmartCompactionResult['categoryStats'];
|
|
1234
|
+
}>;
|
|
1048
1235
|
/**
|
|
1049
1236
|
* Serialize the current agent state to an AgentState object.
|
|
1050
1237
|
* This can be used for manual persistence or transferring state.
|