qlogicagent 0.2.1 → 0.4.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.
Files changed (226) hide show
  1. package/README.md +45 -45
  2. package/package.json +56 -42
  3. package/dist/agent/agent.d.ts +0 -43
  4. package/dist/agent/agent.js +0 -113
  5. package/dist/agent/tool-loop.d.ts +0 -64
  6. package/dist/agent/tool-loop.js +0 -575
  7. package/dist/agent/types.d.ts +0 -175
  8. package/dist/agent/types.js +0 -14
  9. package/dist/cli/main.d.ts +0 -11
  10. package/dist/cli/main.js +0 -23
  11. package/dist/cli/stdio-server.d.ts +0 -45
  12. package/dist/cli/stdio-server.js +0 -463
  13. package/dist/config/config.d.ts +0 -17
  14. package/dist/config/config.js +0 -21
  15. package/dist/contracts/hooks.d.ts +0 -120
  16. package/dist/contracts/hooks.js +0 -7
  17. package/dist/contracts/index.d.ts +0 -10
  18. package/dist/contracts/index.js +0 -10
  19. package/dist/contracts/planner.d.ts +0 -35
  20. package/dist/contracts/planner.js +0 -2
  21. package/dist/contracts/skill-candidate.d.ts +0 -63
  22. package/dist/contracts/skill-candidate.js +0 -195
  23. package/dist/contracts/todo.d.ts +0 -14
  24. package/dist/contracts/todo.js +0 -9
  25. package/dist/index.d.ts +0 -13
  26. package/dist/index.js +0 -15
  27. package/dist/llm/builtin-providers.d.ts +0 -10
  28. package/dist/llm/builtin-providers.js +0 -531
  29. package/dist/llm/index.d.ts +0 -15
  30. package/dist/llm/index.js +0 -14
  31. package/dist/llm/llm-client.d.ts +0 -43
  32. package/dist/llm/llm-client.js +0 -67
  33. package/dist/llm/model-catalog.d.ts +0 -53
  34. package/dist/llm/model-catalog.js +0 -191
  35. package/dist/llm/provider-def.d.ts +0 -59
  36. package/dist/llm/provider-def.js +0 -12
  37. package/dist/llm/provider-registry.d.ts +0 -54
  38. package/dist/llm/provider-registry.js +0 -147
  39. package/dist/llm/transport.d.ts +0 -62
  40. package/dist/llm/transport.js +0 -27
  41. package/dist/llm/transports/anthropic-messages.d.ts +0 -31
  42. package/dist/llm/transports/anthropic-messages.js +0 -293
  43. package/dist/llm/transports/openai-chat.d.ts +0 -36
  44. package/dist/llm/transports/openai-chat.js +0 -165
  45. package/dist/orchestration/agent-registry.d.ts +0 -41
  46. package/dist/orchestration/agent-registry.js +0 -116
  47. package/dist/orchestration/approval-aware-tool-plan.d.ts +0 -32
  48. package/dist/orchestration/approval-aware-tool-plan.js +0 -87
  49. package/dist/orchestration/context-compression.d.ts +0 -220
  50. package/dist/orchestration/context-compression.js +0 -583
  51. package/dist/orchestration/conversation-repair.d.ts +0 -61
  52. package/dist/orchestration/conversation-repair.js +0 -429
  53. package/dist/orchestration/curator-scheduler.d.ts +0 -119
  54. package/dist/orchestration/curator-scheduler.js +0 -135
  55. package/dist/orchestration/embedded-failover-policy.d.ts +0 -110
  56. package/dist/orchestration/embedded-failover-policy.js +0 -168
  57. package/dist/orchestration/error-classification.d.ts +0 -12
  58. package/dist/orchestration/error-classification.js +0 -77
  59. package/dist/orchestration/failover-classification.d.ts +0 -8
  60. package/dist/orchestration/failover-classification.js +0 -381
  61. package/dist/orchestration/failover-error.d.ts +0 -33
  62. package/dist/orchestration/failover-error.js +0 -198
  63. package/dist/orchestration/fork-subagent.d.ts +0 -100
  64. package/dist/orchestration/fork-subagent.js +0 -98
  65. package/dist/orchestration/index.d.ts +0 -120
  66. package/dist/orchestration/index.js +0 -267
  67. package/dist/orchestration/memory-flush-policy.d.ts +0 -57
  68. package/dist/orchestration/memory-flush-policy.js +0 -85
  69. package/dist/orchestration/memory-provider.d.ts +0 -14
  70. package/dist/orchestration/memory-provider.js +0 -2
  71. package/dist/orchestration/parallel-tool-calls.d.ts +0 -41
  72. package/dist/orchestration/parallel-tool-calls.js +0 -59
  73. package/dist/orchestration/prompt-cache-strategy.d.ts +0 -126
  74. package/dist/orchestration/prompt-cache-strategy.js +0 -228
  75. package/dist/orchestration/reactive-compact.d.ts +0 -73
  76. package/dist/orchestration/reactive-compact.js +0 -78
  77. package/dist/orchestration/retry-loop.d.ts +0 -22
  78. package/dist/orchestration/retry-loop.js +0 -24
  79. package/dist/orchestration/skill-candidate.d.ts +0 -52
  80. package/dist/orchestration/skill-candidate.js +0 -141
  81. package/dist/orchestration/skill-consolidation.d.ts +0 -123
  82. package/dist/orchestration/skill-consolidation.js +0 -220
  83. package/dist/orchestration/skill-improvement.d.ts +0 -59
  84. package/dist/orchestration/skill-improvement.js +0 -66
  85. package/dist/orchestration/skill-similarity.d.ts +0 -98
  86. package/dist/orchestration/skill-similarity.js +0 -131
  87. package/dist/orchestration/streaming-tool-executor.d.ts +0 -73
  88. package/dist/orchestration/streaming-tool-executor.js +0 -96
  89. package/dist/orchestration/team-orchestration.d.ts +0 -195
  90. package/dist/orchestration/team-orchestration.js +0 -369
  91. package/dist/orchestration/team-tool-loop-wiring.d.ts +0 -92
  92. package/dist/orchestration/team-tool-loop-wiring.js +0 -147
  93. package/dist/orchestration/tool-choice-policy.d.ts +0 -54
  94. package/dist/orchestration/tool-choice-policy.js +0 -164
  95. package/dist/orchestration/tool-loop-state.d.ts +0 -50
  96. package/dist/orchestration/tool-loop-state.js +0 -133
  97. package/dist/orchestration/tool-schema.d.ts +0 -39
  98. package/dist/orchestration/tool-schema.js +0 -297
  99. package/dist/orchestration/transcript-repair.d.ts +0 -42
  100. package/dist/orchestration/transcript-repair.js +0 -426
  101. package/dist/orchestration/turn-loop-guard.d.ts +0 -86
  102. package/dist/orchestration/turn-loop-guard.js +0 -92
  103. package/dist/orchestration/web-browser-policy.d.ts +0 -17
  104. package/dist/orchestration/web-browser-policy.js +0 -39
  105. package/dist/runtime/context-compression.d.ts +0 -61
  106. package/dist/runtime/context-compression.js +0 -274
  107. package/dist/runtime/hook-registry.d.ts +0 -12
  108. package/dist/runtime/hook-registry.js +0 -53
  109. package/dist/runtime/memory-hooks.d.ts +0 -23
  110. package/dist/runtime/memory-hooks.js +0 -65
  111. package/dist/runtime/tool-eligibility.d.ts +0 -59
  112. package/dist/runtime/tool-eligibility.js +0 -111
  113. package/dist/skills/index.d.ts +0 -108
  114. package/dist/skills/index.js +0 -82
  115. package/dist/skills/memory-extractor.d.ts +0 -64
  116. package/dist/skills/memory-extractor.js +0 -173
  117. package/dist/skills/memory-query-tool.d.ts +0 -43
  118. package/dist/skills/memory-query-tool.js +0 -127
  119. package/dist/skills/memory-store.d.ts +0 -66
  120. package/dist/skills/memory-store.js +0 -228
  121. package/dist/skills/memory-tool.d.ts +0 -67
  122. package/dist/skills/memory-tool.js +0 -192
  123. package/dist/skills/portable-tool.d.ts +0 -71
  124. package/dist/skills/portable-tool.js +0 -14
  125. package/dist/skills/qmemory-adapter.d.ts +0 -52
  126. package/dist/skills/qmemory-adapter.js +0 -165
  127. package/dist/skills/skill-frontmatter.d.ts +0 -19
  128. package/dist/skills/skill-frontmatter.js +0 -344
  129. package/dist/skills/skill-guard.d.ts +0 -23
  130. package/dist/skills/skill-guard.js +0 -229
  131. package/dist/skills/skill-loader.d.ts +0 -16
  132. package/dist/skills/skill-loader.js +0 -303
  133. package/dist/skills/skill-source.d.ts +0 -119
  134. package/dist/skills/skill-source.js +0 -126
  135. package/dist/skills/skill-types.d.ts +0 -199
  136. package/dist/skills/skill-types.js +0 -6
  137. package/dist/skills/think-tool.d.ts +0 -16
  138. package/dist/skills/think-tool.js +0 -59
  139. package/dist/skills/todo-tool.d.ts +0 -63
  140. package/dist/skills/todo-tool.js +0 -114
  141. package/dist/skills/tools/agent-tool.d.ts +0 -91
  142. package/dist/skills/tools/agent-tool.js +0 -142
  143. package/dist/skills/tools/apply-patch-tool.d.ts +0 -29
  144. package/dist/skills/tools/apply-patch-tool.js +0 -184
  145. package/dist/skills/tools/ask-user-tool.d.ts +0 -80
  146. package/dist/skills/tools/ask-user-tool.js +0 -121
  147. package/dist/skills/tools/brief-tool.d.ts +0 -74
  148. package/dist/skills/tools/brief-tool.js +0 -95
  149. package/dist/skills/tools/browser-tool.d.ts +0 -114
  150. package/dist/skills/tools/browser-tool.js +0 -155
  151. package/dist/skills/tools/checkpoint-tool.d.ts +0 -66
  152. package/dist/skills/tools/checkpoint-tool.js +0 -102
  153. package/dist/skills/tools/config-tool.d.ts +0 -63
  154. package/dist/skills/tools/config-tool.js +0 -143
  155. package/dist/skills/tools/cron-tool.d.ts +0 -116
  156. package/dist/skills/tools/cron-tool.js +0 -175
  157. package/dist/skills/tools/edit-tool.d.ts +0 -43
  158. package/dist/skills/tools/edit-tool.js +0 -70
  159. package/dist/skills/tools/exec-tool.d.ts +0 -102
  160. package/dist/skills/tools/exec-tool.js +0 -133
  161. package/dist/skills/tools/image-generate-tool.d.ts +0 -62
  162. package/dist/skills/tools/image-generate-tool.js +0 -67
  163. package/dist/skills/tools/instructions-tool.d.ts +0 -103
  164. package/dist/skills/tools/instructions-tool.js +0 -187
  165. package/dist/skills/tools/lsp-tool.d.ts +0 -153
  166. package/dist/skills/tools/lsp-tool.js +0 -227
  167. package/dist/skills/tools/mcp-client-types.d.ts +0 -269
  168. package/dist/skills/tools/mcp-client-types.js +0 -53
  169. package/dist/skills/tools/mcp-tool.d.ts +0 -249
  170. package/dist/skills/tools/mcp-tool.js +0 -503
  171. package/dist/skills/tools/memory-tool.d.ts +0 -74
  172. package/dist/skills/tools/memory-tool.js +0 -88
  173. package/dist/skills/tools/monitor-tool.d.ts +0 -113
  174. package/dist/skills/tools/monitor-tool.js +0 -131
  175. package/dist/skills/tools/music-generate-tool.d.ts +0 -55
  176. package/dist/skills/tools/music-generate-tool.js +0 -62
  177. package/dist/skills/tools/notify-tool.d.ts +0 -53
  178. package/dist/skills/tools/notify-tool.js +0 -62
  179. package/dist/skills/tools/patch-tool.d.ts +0 -45
  180. package/dist/skills/tools/patch-tool.js +0 -505
  181. package/dist/skills/tools/pdf-tool.d.ts +0 -66
  182. package/dist/skills/tools/pdf-tool.js +0 -88
  183. package/dist/skills/tools/plan-mode-tool.d.ts +0 -59
  184. package/dist/skills/tools/plan-mode-tool.js +0 -122
  185. package/dist/skills/tools/read-tool.d.ts +0 -51
  186. package/dist/skills/tools/read-tool.js +0 -84
  187. package/dist/skills/tools/repl-tool.d.ts +0 -70
  188. package/dist/skills/tools/repl-tool.js +0 -69
  189. package/dist/skills/tools/search-tool.d.ts +0 -112
  190. package/dist/skills/tools/search-tool.js +0 -225
  191. package/dist/skills/tools/send-message-tool.d.ts +0 -51
  192. package/dist/skills/tools/send-message-tool.js +0 -76
  193. package/dist/skills/tools/skill-list-tool.d.ts +0 -33
  194. package/dist/skills/tools/skill-list-tool.js +0 -54
  195. package/dist/skills/tools/skill-manage-tool.d.ts +0 -73
  196. package/dist/skills/tools/skill-manage-tool.js +0 -153
  197. package/dist/skills/tools/skill-view-tool.d.ts +0 -37
  198. package/dist/skills/tools/skill-view-tool.js +0 -72
  199. package/dist/skills/tools/sleep-tool.d.ts +0 -49
  200. package/dist/skills/tools/sleep-tool.js +0 -81
  201. package/dist/skills/tools/structured-output-tool.d.ts +0 -116
  202. package/dist/skills/tools/structured-output-tool.js +0 -176
  203. package/dist/skills/tools/task-tool.d.ts +0 -104
  204. package/dist/skills/tools/task-tool.js +0 -161
  205. package/dist/skills/tools/team-tool.d.ts +0 -89
  206. package/dist/skills/tools/team-tool.js +0 -105
  207. package/dist/skills/tools/tool-search-tool.d.ts +0 -51
  208. package/dist/skills/tools/tool-search-tool.js +0 -110
  209. package/dist/skills/tools/tts-tool.d.ts +0 -38
  210. package/dist/skills/tools/tts-tool.js +0 -45
  211. package/dist/skills/tools/video-edit-tool.d.ts +0 -69
  212. package/dist/skills/tools/video-edit-tool.js +0 -74
  213. package/dist/skills/tools/video-generate-tool.d.ts +0 -62
  214. package/dist/skills/tools/video-generate-tool.js +0 -66
  215. package/dist/skills/tools/video-merge-tool.d.ts +0 -105
  216. package/dist/skills/tools/video-merge-tool.js +0 -92
  217. package/dist/skills/tools/video-upscale-tool.d.ts +0 -45
  218. package/dist/skills/tools/video-upscale-tool.js +0 -52
  219. package/dist/skills/tools/web-fetch-tool.d.ts +0 -78
  220. package/dist/skills/tools/web-fetch-tool.js +0 -92
  221. package/dist/skills/tools/web-search-tool.d.ts +0 -57
  222. package/dist/skills/tools/web-search-tool.js +0 -86
  223. package/dist/skills/tools/worktree-tool.d.ts +0 -69
  224. package/dist/skills/tools/worktree-tool.js +0 -147
  225. package/dist/skills/tools/write-tool.d.ts +0 -45
  226. package/dist/skills/tools/write-tool.js +0 -81
@@ -1,87 +0,0 @@
1
- function formatToolList(toolNames) {
2
- if (toolNames.length === 0) {
3
- return "no tools";
4
- }
5
- if (toolNames.length === 1) {
6
- return toolNames[0];
7
- }
8
- if (toolNames.length === 2) {
9
- return `${toolNames[0]} and ${toolNames[1]}`;
10
- }
11
- return `${toolNames.slice(0, -1).join(", ")}, and ${toolNames.at(-1)}`;
12
- }
13
- function requiresInteractiveApproval(capability) {
14
- if (!capability) {
15
- return false;
16
- }
17
- return capability.requiresApproval === true || capability.approvalMode === "user-confirm";
18
- }
19
- function buildEligibilityMap(eligibility) {
20
- return new Map((eligibility ?? []).map((entry) => [entry.toolName, entry]));
21
- }
22
- function requiresApprovalForTool(params) {
23
- const eligibility = params.eligibilityMap.get(params.toolName);
24
- if (eligibility?.approvalRequired !== undefined) {
25
- return eligibility.approvalRequired;
26
- }
27
- return requiresInteractiveApproval(params.capabilityMap.get(params.toolName));
28
- }
29
- export function summarizeApprovalAwareToolPlan(params) {
30
- const capabilityMap = new Map(params.toolCapabilities.map((capability) => [capability.name, capability]));
31
- const eligibilityMap = buildEligibilityMap(params.eligibility);
32
- const stepCount = params.batches.length;
33
- return params.batches.map((batch, index) => {
34
- const toolNames = batch.calls.map((call) => call.function.name);
35
- const approvalToolNames = batch.calls
36
- .map((call) => requiresApprovalForTool({
37
- toolName: call.function.name,
38
- capabilityMap,
39
- eligibilityMap,
40
- }) ? call.function.name : null)
41
- .filter((toolName) => Boolean(toolName));
42
- const approvalRequired = approvalToolNames.length > 0;
43
- const headline = batch.mode === "parallel"
44
- ? `Step ${index + 1}/${stepCount}: run ${toolNames.length} tools in parallel: ${formatToolList(toolNames)}.`
45
- : approvalRequired
46
- ? `Step ${index + 1}/${stepCount}: approval-gated execution for ${formatToolList(approvalToolNames)}.`
47
- : `Step ${index + 1}/${stepCount}: run ${formatToolList(toolNames)} serially.`;
48
- const detail = approvalRequired
49
- ? stepCount > index + 1
50
- ? "This step must be approved before later steps continue."
51
- : "This is the final planned step and requires approval before execution."
52
- : batch.mode === "parallel"
53
- ? "Parallel-safe tools are grouped to avoid unnecessary waiting."
54
- : "This step stays serial because the tool is not parallel-safe.";
55
- return {
56
- stepIndex: index + 1,
57
- stepCount,
58
- mode: batch.mode,
59
- callIds: batch.calls.map((call) => call.id),
60
- toolNames,
61
- approvalRequired,
62
- approvalToolNames,
63
- summary: `${headline} ${detail}`,
64
- };
65
- });
66
- }
67
- export function buildApprovalAwareReason(params) {
68
- if (!params.step) {
69
- return `semantic turn requested local tool: ${params.toolName}`;
70
- }
71
- const suffix = params.step.approvalRequired
72
- ? params.step.approvalToolNames.length > 1
73
- ? ` Approval is currently blocking ${formatToolList(params.step.approvalToolNames)}.`
74
- : " Approval is required before this step can continue."
75
- : "";
76
- return `${params.step.summary}${suffix}`;
77
- }
78
- export function buildApprovalStepContext(step) {
79
- if (!step) {
80
- return {};
81
- }
82
- return {
83
- stepIndex: step.stepIndex,
84
- stepTotal: step.stepCount,
85
- stepSummary: step.summary,
86
- };
87
- }
@@ -1,220 +0,0 @@
1
- export interface CompressibleMessage {
2
- role: string;
3
- content?: string | unknown;
4
- tool_call_id?: string;
5
- tool_calls?: unknown;
6
- name?: string;
7
- }
8
- export interface CompressionResult {
9
- messages: CompressibleMessage[];
10
- droppedCount: number;
11
- strategy: string;
12
- /** Phase 4: optional metrics from the compression pass */
13
- metrics?: CompressionMetrics;
14
- }
15
- export interface CompressionMetrics {
16
- tokensBefore: number;
17
- tokensAfter: number;
18
- compressionRatio: number;
19
- /** ms elapsed for this strategy pass */
20
- latencyMs: number;
21
- /** Whether an LLM call was made during this pass */
22
- usedLlm: boolean;
23
- /** Whether prompt cache was invalidated by compression */
24
- cacheInvalidated?: boolean;
25
- }
26
- export interface CompressionStrategy {
27
- compress(messages: CompressibleMessage[], budget: number): CompressionResult;
28
- }
29
- /**
30
- * Async compression strategy — required for LLM-based summarization.
31
- * Falls back to sync `compress` when the caller doesn't support async.
32
- */
33
- export interface AsyncCompressionStrategy extends CompressionStrategy {
34
- compressAsync(messages: CompressibleMessage[], budget: number): Promise<CompressionResult>;
35
- }
36
- export declare function isAsyncCompressionStrategy(s: CompressionStrategy): s is AsyncCompressionStrategy;
37
- /** Caller-provided LLM summarization function (wired by Hub). */
38
- export type SummarizeFn = (messages: CompressibleMessage[], instruction: string) => Promise<string>;
39
- export declare class SlidingWindowStrategy implements CompressionStrategy {
40
- private estimateTokens;
41
- constructor(estimateTokens: (msg: CompressibleMessage) => number);
42
- compress(messages: CompressibleMessage[], budget: number): CompressionResult;
43
- }
44
- export declare class SummarizeOldStrategy implements CompressionStrategy {
45
- private recentCount;
46
- private summarize;
47
- constructor(recentCount: number, summarize: (messages: CompressibleMessage[]) => string);
48
- compress(messages: CompressibleMessage[], _budget: number): CompressionResult;
49
- }
50
- export declare class ToolResultTrimStrategy implements CompressionStrategy {
51
- private maxToolResultChars;
52
- constructor(maxToolResultChars?: number);
53
- compress(messages: CompressibleMessage[], _budget: number): CompressionResult;
54
- }
55
- export declare function composeStrategies(...strategies: CompressionStrategy[]): CompressionStrategy;
56
- /**
57
- * Compose strategies with async support — if any strategy is async,
58
- * the pipeline becomes async.
59
- */
60
- export declare function composeAsyncStrategies(...strategies: CompressionStrategy[]): AsyncCompressionStrategy;
61
- /**
62
- * Build the structured 9-section summary instruction for the LLM.
63
- * Based on Claude Code's Full Compact mode, adapted for Hub.
64
- */
65
- export declare function buildStructuredSummaryPrompt(messagesToSummarize: CompressibleMessage[], opts?: {
66
- taskContext?: string;
67
- }): string;
68
- export interface HeadTailProtectionConfig {
69
- /** Number of initial user-assistant exchanges to protect (default: 1) */
70
- protectedHeadExchanges: number;
71
- /** Number of recent messages to always keep (default: 8 = ~4 exchanges) */
72
- protectedTailMessages: number;
73
- /** The summarization callback */
74
- summarize: SummarizeFn;
75
- /** Optional token estimator */
76
- estimateTokens?: (msg: CompressibleMessage) => number;
77
- /** Optional extra context for the summary prompt */
78
- taskContext?: string;
79
- }
80
- /**
81
- * Phase 2.2: Head/Tail protected summarization.
82
- *
83
- * Protects: system messages + first exchange + last N messages.
84
- * Compresses: middle section via LLM summarization.
85
- */
86
- export declare class HeadTailProtectedStrategy implements AsyncCompressionStrategy {
87
- private config;
88
- constructor(config: HeadTailProtectionConfig);
89
- compress(messages: CompressibleMessage[], _budget: number): CompressionResult;
90
- compressAsync(messages: CompressibleMessage[], budget: number): Promise<CompressionResult>;
91
- }
92
- export interface IncrementalCompactConfig {
93
- /** Messages newer than this count are never summarized (default: 12) */
94
- preserveRecentCount: number;
95
- /** Summarization callback */
96
- summarize: SummarizeFn;
97
- /** Token estimator */
98
- estimateTokens?: (msg: CompressibleMessage) => number;
99
- }
100
- /**
101
- * Phase 2.3: Incremental (partial) compaction.
102
- *
103
- * Only summarizes the oldest messages beyond the preserve window.
104
- * Avoids repeatedly re-summarizing already-compressed content.
105
- * If a previous summary marker exists, only new old messages are compressed.
106
- */
107
- export declare class IncrementalCompactStrategy implements AsyncCompressionStrategy {
108
- private config;
109
- constructor(config: IncrementalCompactConfig);
110
- compress(messages: CompressibleMessage[], _budget: number): CompressionResult;
111
- compressAsync(messages: CompressibleMessage[], budget: number): Promise<CompressionResult>;
112
- }
113
- export interface CacheAwareCompressionConfig {
114
- /** The inner strategy to delegate to */
115
- inner: CompressionStrategy;
116
- /** Token estimator */
117
- estimateTokens?: (msg: CompressibleMessage) => number;
118
- /**
119
- * Callback: notify when prompt cache was invalidated by compression.
120
- * Hub uses this to set pendingPostCompaction and track cache miss rate.
121
- */
122
- onCacheInvalidated?: (info: {
123
- droppedCount: number;
124
- strategy: string;
125
- }) => void;
126
- }
127
- /**
128
- * Phase 3: Cache-aware wrapper.
129
- *
130
- * Wraps any strategy and tracks whether compression invalidated the
131
- * provider prompt cache. System prompt prefix stability is preserved
132
- * by never modifying system[0] (the original system prompt).
133
- */
134
- export declare class CacheAwareCompressionStrategy implements AsyncCompressionStrategy {
135
- private config;
136
- constructor(config: CacheAwareCompressionConfig);
137
- compress(messages: CompressibleMessage[], budget: number): CompressionResult;
138
- compressAsync(messages: CompressibleMessage[], budget: number): Promise<CompressionResult>;
139
- }
140
- export interface AdaptiveBudgetConfig {
141
- /** Model context window size in tokens */
142
- modelContextWindow: number;
143
- /** Target usage ratio (0.0–1.0, default 0.75) — trigger compaction at this fraction */
144
- targetUsageRatio: number;
145
- /** Minimum guaranteed budget in tokens */
146
- minBudget: number;
147
- /** Maximum budget (usually = modelContextWindow) */
148
- maxBudget: number;
149
- }
150
- export declare const DEFAULT_ADAPTIVE_BUDGET_CONFIG: AdaptiveBudgetConfig;
151
- /**
152
- * Compute the adaptive token budget for a given model + message history.
153
- *
154
- * Adjusts based on model context window, and uses the target ratio
155
- * so compression triggers before hitting the hard limit.
156
- */
157
- export declare function computeAdaptiveBudget(config?: Partial<AdaptiveBudgetConfig>): number;
158
- /**
159
- * Decide which compression tier to use based on current token count vs budget.
160
- */
161
- export type CompressionTier = "none" | "trim-only" | "sliding-window" | "llm-summarize";
162
- export declare function selectCompressionTier(currentTokens: number, budget: number): CompressionTier;
163
- export interface CompressionEvent {
164
- timestamp: number;
165
- strategy: string;
166
- tokensBefore: number;
167
- tokensAfter: number;
168
- droppedCount: number;
169
- latencyMs: number;
170
- usedLlm: boolean;
171
- cacheInvalidated: boolean;
172
- tier: CompressionTier;
173
- }
174
- export interface CompressionMetricsSnapshot {
175
- totalCompressions: number;
176
- totalLlmCalls: number;
177
- totalCacheInvalidations: number;
178
- averageCompressionRatio: number;
179
- averageLatencyMs: number;
180
- totalTokensSaved: number;
181
- recentEvents: CompressionEvent[];
182
- }
183
- export declare class CompressionMetricsCollector {
184
- private events;
185
- private maxEvents;
186
- constructor(maxEvents?: number);
187
- record(event: CompressionEvent): void;
188
- snapshot(): CompressionMetricsSnapshot;
189
- reset(): void;
190
- }
191
- /**
192
- * A pluggable context engine. Only one can be active at a time.
193
- * The default engine uses the 4-layer compression funnel.
194
- */
195
- export interface ContextEngine {
196
- /** Unique engine identifier */
197
- readonly id: string;
198
- /** Human-readable label */
199
- readonly label: string;
200
- /** Compress messages for a turn */
201
- compressAsync(messages: CompressibleMessage[], budget: number, context?: {
202
- model?: string;
203
- sessionId?: string;
204
- }): Promise<CompressionResult>;
205
- }
206
- /**
207
- * Registry for context engines. Enforces single-active constraint.
208
- */
209
- export declare class ContextEngineRegistry {
210
- private engines;
211
- private activeId;
212
- register(engine: ContextEngine): void;
213
- activate(id: string): boolean;
214
- getActive(): ContextEngine | undefined;
215
- listEngines(): Array<{
216
- id: string;
217
- label: string;
218
- active: boolean;
219
- }>;
220
- }