@defai.digital/ax-cli 3.0.2 → 3.1.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 (81) hide show
  1. package/README.md +74 -0
  2. package/dist/agent/llm-agent.d.ts +21 -0
  3. package/dist/agent/llm-agent.js +64 -15
  4. package/dist/agent/llm-agent.js.map +1 -1
  5. package/dist/agent/subagent-orchestrator.js +4 -0
  6. package/dist/agent/subagent-orchestrator.js.map +1 -1
  7. package/dist/commands/mcp.js +10 -6
  8. package/dist/commands/mcp.js.map +1 -1
  9. package/dist/commands/memory.d.ts +1 -0
  10. package/dist/commands/memory.js +285 -1
  11. package/dist/commands/memory.js.map +1 -1
  12. package/dist/hooks/use-enhanced-input.js +3 -1
  13. package/dist/hooks/use-enhanced-input.js.map +1 -1
  14. package/dist/hooks/use-input-handler.js +18 -7
  15. package/dist/hooks/use-input-handler.js.map +1 -1
  16. package/dist/index.js +4 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/llm/client.js +52 -5
  19. package/dist/llm/client.js.map +1 -1
  20. package/dist/llm/tools.js +12 -2
  21. package/dist/llm/tools.js.map +1 -1
  22. package/dist/llm/types.d.ts +93 -1
  23. package/dist/llm/types.js +60 -0
  24. package/dist/llm/types.js.map +1 -1
  25. package/dist/mcp/client.d.ts +1 -1
  26. package/dist/mcp/client.js +8 -3
  27. package/dist/mcp/client.js.map +1 -1
  28. package/dist/memory/context-generator.d.ts +84 -0
  29. package/dist/memory/context-generator.js +537 -0
  30. package/dist/memory/context-generator.js.map +1 -0
  31. package/dist/memory/context-injector.d.ts +83 -0
  32. package/dist/memory/context-injector.js +142 -0
  33. package/dist/memory/context-injector.js.map +1 -0
  34. package/dist/memory/context-store.d.ts +76 -0
  35. package/dist/memory/context-store.js +212 -0
  36. package/dist/memory/context-store.js.map +1 -0
  37. package/dist/memory/index.d.ts +42 -0
  38. package/dist/memory/index.js +47 -0
  39. package/dist/memory/index.js.map +1 -0
  40. package/dist/memory/schemas.d.ts +316 -0
  41. package/dist/memory/schemas.js +103 -0
  42. package/dist/memory/schemas.js.map +1 -0
  43. package/dist/memory/stats-collector.d.ts +73 -0
  44. package/dist/memory/stats-collector.js +170 -0
  45. package/dist/memory/stats-collector.js.map +1 -0
  46. package/dist/memory/types.d.ts +175 -0
  47. package/dist/memory/types.js +70 -0
  48. package/dist/memory/types.js.map +1 -0
  49. package/dist/planner/task-planner.js +19 -2
  50. package/dist/planner/task-planner.js.map +1 -1
  51. package/dist/schemas/api-schemas.js +1 -1
  52. package/dist/schemas/api-schemas.js.map +1 -1
  53. package/dist/schemas/index.d.ts +4 -4
  54. package/dist/schemas/settings-schemas.d.ts +14 -0
  55. package/dist/schemas/settings-schemas.js +10 -0
  56. package/dist/schemas/settings-schemas.js.map +1 -1
  57. package/dist/tools/bash.js +28 -7
  58. package/dist/tools/bash.js.map +1 -1
  59. package/dist/ui/components/chat-history.js +4 -2
  60. package/dist/ui/components/chat-history.js.map +1 -1
  61. package/dist/ui/components/chat-interface.js +9 -4
  62. package/dist/ui/components/chat-interface.js.map +1 -1
  63. package/dist/ui/components/toast-notification.d.ts +3 -0
  64. package/dist/ui/components/toast-notification.js +18 -12
  65. package/dist/ui/components/toast-notification.js.map +1 -1
  66. package/dist/utils/background-task-manager.js +31 -9
  67. package/dist/utils/background-task-manager.js.map +1 -1
  68. package/dist/utils/custom-instructions.js +9 -1
  69. package/dist/utils/custom-instructions.js.map +1 -1
  70. package/dist/utils/prompt-builder.d.ts +4 -0
  71. package/dist/utils/prompt-builder.js +15 -0
  72. package/dist/utils/prompt-builder.js.map +1 -1
  73. package/dist/utils/settings-manager.d.ts +16 -1
  74. package/dist/utils/settings-manager.js +49 -0
  75. package/dist/utils/settings-manager.js.map +1 -1
  76. package/dist/utils/token-counter.js +4 -0
  77. package/dist/utils/token-counter.js.map +1 -1
  78. package/dist/utils/usage-tracker.d.ts +19 -0
  79. package/dist/utils/usage-tracker.js +22 -1
  80. package/dist/utils/usage-tracker.js.map +1 -1
  81. package/package.json +1 -1
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Context Injector - Injects project memory into system prompts
3
+ *
4
+ * Handles loading and injection of memory context as a prefix
5
+ * to enable z.ai automatic caching of repeated content.
6
+ */
7
+ import { ContextStore } from './context-store.js';
8
+ /**
9
+ * ContextInjector - Manages memory context injection
10
+ */
11
+ export class ContextInjector {
12
+ store;
13
+ cachedMemory = null;
14
+ enabled = true;
15
+ constructor(projectRoot = process.cwd()) {
16
+ this.store = new ContextStore(projectRoot);
17
+ }
18
+ /**
19
+ * Enable or disable memory injection
20
+ */
21
+ setEnabled(enabled) {
22
+ this.enabled = enabled;
23
+ }
24
+ /**
25
+ * Check if memory injection is enabled
26
+ */
27
+ isEnabled() {
28
+ return this.enabled;
29
+ }
30
+ /**
31
+ * Get project memory context string
32
+ * Returns null if no memory exists or injection is disabled
33
+ */
34
+ getContext() {
35
+ if (!this.enabled) {
36
+ return null;
37
+ }
38
+ // Use cached memory if available
39
+ if (this.cachedMemory) {
40
+ return this.cachedMemory.context.formatted;
41
+ }
42
+ // Load from store
43
+ const result = this.store.load();
44
+ if (!result.success) {
45
+ return null;
46
+ }
47
+ // Cache for subsequent calls
48
+ this.cachedMemory = result.data;
49
+ return result.data.context.formatted;
50
+ }
51
+ /**
52
+ * Inject memory context into a system prompt
53
+ *
54
+ * Memory context is prepended as a prefix to enable z.ai
55
+ * automatic caching when the same prefix is used across requests.
56
+ *
57
+ * @param basePrompt - The base system prompt
58
+ * @returns Modified prompt with memory context prefix
59
+ */
60
+ injectIntoPrompt(basePrompt) {
61
+ const memoryContext = this.getContext();
62
+ if (!memoryContext) {
63
+ return basePrompt;
64
+ }
65
+ // Use consistent separator for cache stability
66
+ const separator = '\n\n---\n\n';
67
+ return `${memoryContext}${separator}${basePrompt}`;
68
+ }
69
+ /**
70
+ * Check if project memory exists
71
+ */
72
+ hasMemory() {
73
+ return this.store.exists();
74
+ }
75
+ /**
76
+ * Get memory metadata without loading full context
77
+ */
78
+ getMetadata() {
79
+ return this.store.getMetadata();
80
+ }
81
+ /**
82
+ * Get the full memory object (loads from disk if not cached)
83
+ */
84
+ getMemory() {
85
+ if (this.cachedMemory) {
86
+ return this.cachedMemory;
87
+ }
88
+ const result = this.store.load();
89
+ if (!result.success) {
90
+ return null;
91
+ }
92
+ this.cachedMemory = result.data;
93
+ return result.data;
94
+ }
95
+ /**
96
+ * Clear the cached memory
97
+ * Call this when memory is updated externally
98
+ */
99
+ clearCache() {
100
+ this.cachedMemory = null;
101
+ }
102
+ /**
103
+ * Get estimated token count of the memory context
104
+ */
105
+ getTokenEstimate() {
106
+ const memory = this.getMemory();
107
+ return memory?.context.token_estimate ?? 0;
108
+ }
109
+ /**
110
+ * Format a reminder message about missing memory
111
+ * Returns null if memory exists
112
+ */
113
+ getMissingMemoryHint() {
114
+ if (this.hasMemory()) {
115
+ return null;
116
+ }
117
+ return 'No project memory found. Run "ax memory warmup" to improve context reuse.';
118
+ }
119
+ }
120
+ /**
121
+ * Singleton instance for convenience
122
+ */
123
+ let defaultInjector = null;
124
+ /**
125
+ * Get the default context injector instance
126
+ */
127
+ export function getContextInjector(projectRoot) {
128
+ if (projectRoot) {
129
+ return new ContextInjector(projectRoot);
130
+ }
131
+ if (!defaultInjector) {
132
+ defaultInjector = new ContextInjector();
133
+ }
134
+ return defaultInjector;
135
+ }
136
+ /**
137
+ * Reset the default injector (mainly for testing)
138
+ */
139
+ export function resetDefaultInjector() {
140
+ defaultInjector = null;
141
+ }
142
+ //# sourceMappingURL=context-injector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-injector.js","sourceRoot":"","sources":["../../src/memory/context-injector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAclD;;GAEG;AACH,MAAM,OAAO,eAAe;IAClB,KAAK,CAAe;IACpB,YAAY,GAAyB,IAAI,CAAC;IAC1C,OAAO,GAAY,IAAI,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1
+ /**
2
+ * Context Store - Handles reading and writing memory.json
3
+ *
4
+ * Provides atomic file operations and schema validation
5
+ */
6
+ import type { ProjectMemory, CacheStats } from './types.js';
7
+ /**
8
+ * Result type for store operations
9
+ */
10
+ export type StoreResult<T = void> = {
11
+ success: true;
12
+ data: T;
13
+ } | {
14
+ success: false;
15
+ error: string;
16
+ };
17
+ /**
18
+ * ContextStore - Manages persistence of project memory
19
+ */
20
+ export declare class ContextStore {
21
+ private memoryPath;
22
+ private configDir;
23
+ constructor(projectRoot?: string);
24
+ /**
25
+ * Get the path to memory.json
26
+ */
27
+ getMemoryPath(): string;
28
+ /**
29
+ * Get the config directory path
30
+ */
31
+ getConfigDir(): string;
32
+ /**
33
+ * Check if memory.json exists
34
+ */
35
+ exists(): boolean;
36
+ /**
37
+ * Check if .ax-cli directory exists
38
+ */
39
+ configDirExists(): boolean;
40
+ /**
41
+ * Load project memory from disk
42
+ */
43
+ load(): StoreResult<ProjectMemory>;
44
+ /**
45
+ * Save project memory to disk (atomic write)
46
+ */
47
+ save(memory: ProjectMemory): StoreResult<void>;
48
+ /**
49
+ * Update only the stats section of memory.json
50
+ */
51
+ updateStats(stats: Partial<CacheStats>): StoreResult<void>;
52
+ /**
53
+ * Increment usage count and record cache hit
54
+ */
55
+ recordUsage(promptTokens: number, cachedTokens: number): StoreResult<void>;
56
+ /**
57
+ * Delete memory.json
58
+ */
59
+ clear(): StoreResult<void>;
60
+ /**
61
+ * Get memory metadata without loading full context
62
+ * Useful for quick status checks
63
+ */
64
+ getMetadata(): {
65
+ exists: boolean;
66
+ tokenEstimate?: number;
67
+ updatedAt?: string;
68
+ contentHash?: string;
69
+ usageCount?: number;
70
+ };
71
+ }
72
+ export declare function getContextStore(projectRoot?: string): ContextStore;
73
+ /**
74
+ * Reset the default store (mainly for testing)
75
+ */
76
+ export declare function resetDefaultStore(): void;
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Context Store - Handles reading and writing memory.json
3
+ *
4
+ * Provides atomic file operations and schema validation
5
+ */
6
+ import * as fs from 'fs';
7
+ import * as path from 'path';
8
+ import { MEMORY_DEFAULTS } from './types.js';
9
+ import { safeValidateProjectMemory } from './schemas.js';
10
+ import { parseJsonFile } from '../utils/json-utils.js';
11
+ /**
12
+ * ContextStore - Manages persistence of project memory
13
+ */
14
+ export class ContextStore {
15
+ memoryPath;
16
+ configDir;
17
+ constructor(projectRoot = process.cwd()) {
18
+ this.configDir = path.join(projectRoot, MEMORY_DEFAULTS.CONFIG_DIR);
19
+ this.memoryPath = path.join(this.configDir, MEMORY_DEFAULTS.FILENAME);
20
+ }
21
+ /**
22
+ * Get the path to memory.json
23
+ */
24
+ getMemoryPath() {
25
+ return this.memoryPath;
26
+ }
27
+ /**
28
+ * Get the config directory path
29
+ */
30
+ getConfigDir() {
31
+ return this.configDir;
32
+ }
33
+ /**
34
+ * Check if memory.json exists
35
+ */
36
+ exists() {
37
+ return fs.existsSync(this.memoryPath);
38
+ }
39
+ /**
40
+ * Check if .ax-cli directory exists
41
+ */
42
+ configDirExists() {
43
+ return fs.existsSync(this.configDir);
44
+ }
45
+ /**
46
+ * Load project memory from disk
47
+ */
48
+ load() {
49
+ if (!this.exists()) {
50
+ return {
51
+ success: false,
52
+ error: `Memory file not found at ${this.memoryPath}. Run: ax memory warmup`,
53
+ };
54
+ }
55
+ // Parse JSON file
56
+ const parseResult = parseJsonFile(this.memoryPath);
57
+ if (!parseResult.success) {
58
+ return {
59
+ success: false,
60
+ error: `Failed to parse memory.json: ${parseResult.error}`,
61
+ };
62
+ }
63
+ // Validate schema
64
+ const validation = safeValidateProjectMemory(parseResult.data);
65
+ if (!validation.success) {
66
+ return {
67
+ success: false,
68
+ error: `Invalid memory.json schema: ${validation.error}`,
69
+ };
70
+ }
71
+ return { success: true, data: validation.data };
72
+ }
73
+ /**
74
+ * Save project memory to disk (atomic write)
75
+ */
76
+ save(memory) {
77
+ try {
78
+ // Ensure .ax-cli directory exists
79
+ if (!fs.existsSync(this.configDir)) {
80
+ fs.mkdirSync(this.configDir, { recursive: true });
81
+ }
82
+ // Validate before saving
83
+ const validation = safeValidateProjectMemory(memory);
84
+ if (!validation.success) {
85
+ return {
86
+ success: false,
87
+ error: `Invalid memory data: ${validation.error}`,
88
+ };
89
+ }
90
+ // Atomic write: write to temp file then rename
91
+ const tmpPath = `${this.memoryPath}.tmp`;
92
+ const content = JSON.stringify(memory, null, 2);
93
+ fs.writeFileSync(tmpPath, content, 'utf-8');
94
+ fs.renameSync(tmpPath, this.memoryPath);
95
+ return { success: true, data: undefined };
96
+ }
97
+ catch (error) {
98
+ // Clean up temp file if it exists
99
+ const tmpPath = `${this.memoryPath}.tmp`;
100
+ try {
101
+ if (fs.existsSync(tmpPath)) {
102
+ fs.unlinkSync(tmpPath);
103
+ }
104
+ }
105
+ catch {
106
+ // Ignore cleanup errors
107
+ }
108
+ return {
109
+ success: false,
110
+ error: error instanceof Error ? error.message : 'Unknown write error',
111
+ };
112
+ }
113
+ }
114
+ /**
115
+ * Update only the stats section of memory.json
116
+ */
117
+ updateStats(stats) {
118
+ const loadResult = this.load();
119
+ if (!loadResult.success) {
120
+ return { success: false, error: loadResult.error };
121
+ }
122
+ const memory = loadResult.data;
123
+ // Merge stats
124
+ memory.stats = {
125
+ ...memory.stats,
126
+ ...stats,
127
+ last_used_at: new Date().toISOString(),
128
+ };
129
+ // Update timestamp
130
+ memory.updated_at = new Date().toISOString();
131
+ return this.save(memory);
132
+ }
133
+ /**
134
+ * Increment usage count and record cache hit
135
+ */
136
+ recordUsage(promptTokens, cachedTokens) {
137
+ const loadResult = this.load();
138
+ if (!loadResult.success) {
139
+ // Don't fail if memory doesn't exist - just skip recording
140
+ return { success: true, data: undefined };
141
+ }
142
+ const memory = loadResult.data;
143
+ const currentStats = memory.stats || {};
144
+ return this.updateStats({
145
+ last_cached_tokens: cachedTokens,
146
+ last_prompt_tokens: promptTokens,
147
+ total_tokens_saved: (currentStats.total_tokens_saved || 0) + cachedTokens,
148
+ usage_count: (currentStats.usage_count || 0) + 1,
149
+ });
150
+ }
151
+ /**
152
+ * Delete memory.json
153
+ */
154
+ clear() {
155
+ if (!this.exists()) {
156
+ // Already cleared
157
+ return { success: true, data: undefined };
158
+ }
159
+ try {
160
+ fs.unlinkSync(this.memoryPath);
161
+ return { success: true, data: undefined };
162
+ }
163
+ catch (error) {
164
+ return {
165
+ success: false,
166
+ error: error instanceof Error ? error.message : 'Unknown delete error',
167
+ };
168
+ }
169
+ }
170
+ /**
171
+ * Get memory metadata without loading full context
172
+ * Useful for quick status checks
173
+ */
174
+ getMetadata() {
175
+ if (!this.exists()) {
176
+ return { exists: false };
177
+ }
178
+ const result = this.load();
179
+ if (!result.success) {
180
+ return { exists: false };
181
+ }
182
+ const memory = result.data;
183
+ return {
184
+ exists: true,
185
+ tokenEstimate: memory.context.token_estimate,
186
+ updatedAt: memory.updated_at,
187
+ contentHash: memory.content_hash,
188
+ usageCount: memory.stats?.usage_count,
189
+ };
190
+ }
191
+ }
192
+ /**
193
+ * Singleton instance for convenience
194
+ * Use this when you don't need to specify a custom project root
195
+ */
196
+ let defaultStore = null;
197
+ export function getContextStore(projectRoot) {
198
+ if (projectRoot) {
199
+ return new ContextStore(projectRoot);
200
+ }
201
+ if (!defaultStore) {
202
+ defaultStore = new ContextStore();
203
+ }
204
+ return defaultStore;
205
+ }
206
+ /**
207
+ * Reset the default store (mainly for testing)
208
+ */
209
+ export function resetDefaultStore() {
210
+ defaultStore = null;
211
+ }
212
+ //# sourceMappingURL=context-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-store.js","sourceRoot":"","sources":["../../src/memory/context-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,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,IAAI,CAAC;QAC3B,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc;YAC5C,SAAS,EAAE,MAAM,CAAC,UAAU;YAC5B,WAAW,EAAE,MAAM,CAAC,YAAY;YAChC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,WAAW;SACtC,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,IAAI,YAAY,GAAwB,IAAI,CAAC;AAE7C,MAAM,UAAU,eAAe,CAAC,WAAoB;IAClD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;IACpC,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Project Memory Module
3
+ *
4
+ * Provides functionality for creating and managing project context
5
+ * that enables z.ai GLM-4.6 implicit caching through consistent
6
+ * system prompt prefixes.
7
+ *
8
+ * Key Components:
9
+ * - ContextGenerator: Scans project and generates context
10
+ * - ContextStore: Reads/writes memory.json
11
+ * - ContextInjector: Injects context into system prompts
12
+ * - StatsCollector: Tracks cache performance metrics
13
+ *
14
+ * Usage:
15
+ * ```typescript
16
+ * import {
17
+ * ContextGenerator,
18
+ * ContextStore,
19
+ * ContextInjector,
20
+ * getContextInjector,
21
+ * } from './memory/index.js';
22
+ *
23
+ * // Generate memory
24
+ * const generator = new ContextGenerator(projectRoot);
25
+ * const result = await generator.generate({ depth: 3 });
26
+ *
27
+ * // Save memory
28
+ * const store = new ContextStore(projectRoot);
29
+ * store.save(result.memory);
30
+ *
31
+ * // Inject into prompts
32
+ * const injector = getContextInjector();
33
+ * const enhancedPrompt = injector.injectIntoPrompt(basePrompt);
34
+ * ```
35
+ */
36
+ export type { ProjectMemory, SourceConfig, DirectoryConfig, ContextData, ContextSections, CacheStats, WarmupOptions, WarmupResult, RefreshOptions, RefreshResult, StatusOptions, } from './types.js';
37
+ export { MEMORY_DEFAULTS, DEFAULT_IGNORE_PATTERNS, DEFAULT_INCLUDE_FILES, DEFAULT_SCAN_DIRECTORIES, } from './types.js';
38
+ export { ProjectMemorySchema, DirectoryConfigSchema, SourceConfigSchema, ContextDataSchema, ContextSectionsSchema, CacheStatsSchema, safeValidateProjectMemory, safeValidateCacheStats, safeValidateSourceConfig, } from './schemas.js';
39
+ export { ContextGenerator } from './context-generator.js';
40
+ export { ContextStore, getContextStore, resetDefaultStore, type StoreResult, } from './context-store.js';
41
+ export { ContextInjector, getContextInjector, resetDefaultInjector, type MemoryMetadata, } from './context-injector.js';
42
+ export { StatsCollector, getStatsCollector, resetDefaultCollector, type FormattedStats, } from './stats-collector.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Project Memory Module
3
+ *
4
+ * Provides functionality for creating and managing project context
5
+ * that enables z.ai GLM-4.6 implicit caching through consistent
6
+ * system prompt prefixes.
7
+ *
8
+ * Key Components:
9
+ * - ContextGenerator: Scans project and generates context
10
+ * - ContextStore: Reads/writes memory.json
11
+ * - ContextInjector: Injects context into system prompts
12
+ * - StatsCollector: Tracks cache performance metrics
13
+ *
14
+ * Usage:
15
+ * ```typescript
16
+ * import {
17
+ * ContextGenerator,
18
+ * ContextStore,
19
+ * ContextInjector,
20
+ * getContextInjector,
21
+ * } from './memory/index.js';
22
+ *
23
+ * // Generate memory
24
+ * const generator = new ContextGenerator(projectRoot);
25
+ * const result = await generator.generate({ depth: 3 });
26
+ *
27
+ * // Save memory
28
+ * const store = new ContextStore(projectRoot);
29
+ * store.save(result.memory);
30
+ *
31
+ * // Inject into prompts
32
+ * const injector = getContextInjector();
33
+ * const enhancedPrompt = injector.injectIntoPrompt(basePrompt);
34
+ * ```
35
+ */
36
+ export { MEMORY_DEFAULTS, DEFAULT_IGNORE_PATTERNS, DEFAULT_INCLUDE_FILES, DEFAULT_SCAN_DIRECTORIES, } from './types.js';
37
+ // Schemas
38
+ export { ProjectMemorySchema, DirectoryConfigSchema, SourceConfigSchema, ContextDataSchema, ContextSectionsSchema, CacheStatsSchema, safeValidateProjectMemory, safeValidateCacheStats, safeValidateSourceConfig, } from './schemas.js';
39
+ // Context Generator
40
+ export { ContextGenerator } from './context-generator.js';
41
+ // Context Store
42
+ export { ContextStore, getContextStore, resetDefaultStore, } from './context-store.js';
43
+ // Context Injector
44
+ export { ContextInjector, getContextInjector, resetDefaultInjector, } from './context-injector.js';
45
+ // Stats Collector
46
+ export { StatsCollector, getStatsCollector, resetDefaultCollector, } from './stats-collector.js';
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAiBH,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,UAAU;AACV,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAEtB,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAE5B,mBAAmB;AACnB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;AAE/B,kBAAkB;AAClB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC"}