@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.
- package/README.md +74 -0
- package/dist/agent/llm-agent.d.ts +21 -0
- package/dist/agent/llm-agent.js +64 -15
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/subagent-orchestrator.js +4 -0
- package/dist/agent/subagent-orchestrator.js.map +1 -1
- package/dist/commands/mcp.js +10 -6
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/memory.d.ts +1 -0
- package/dist/commands/memory.js +285 -1
- package/dist/commands/memory.js.map +1 -1
- package/dist/hooks/use-enhanced-input.js +3 -1
- package/dist/hooks/use-enhanced-input.js.map +1 -1
- package/dist/hooks/use-input-handler.js +18 -7
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/client.js +52 -5
- package/dist/llm/client.js.map +1 -1
- package/dist/llm/tools.js +12 -2
- package/dist/llm/tools.js.map +1 -1
- package/dist/llm/types.d.ts +93 -1
- package/dist/llm/types.js +60 -0
- package/dist/llm/types.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +8 -3
- package/dist/mcp/client.js.map +1 -1
- package/dist/memory/context-generator.d.ts +84 -0
- package/dist/memory/context-generator.js +537 -0
- package/dist/memory/context-generator.js.map +1 -0
- package/dist/memory/context-injector.d.ts +83 -0
- package/dist/memory/context-injector.js +142 -0
- package/dist/memory/context-injector.js.map +1 -0
- package/dist/memory/context-store.d.ts +76 -0
- package/dist/memory/context-store.js +212 -0
- package/dist/memory/context-store.js.map +1 -0
- package/dist/memory/index.d.ts +42 -0
- package/dist/memory/index.js +47 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/schemas.d.ts +316 -0
- package/dist/memory/schemas.js +103 -0
- package/dist/memory/schemas.js.map +1 -0
- package/dist/memory/stats-collector.d.ts +73 -0
- package/dist/memory/stats-collector.js +170 -0
- package/dist/memory/stats-collector.js.map +1 -0
- package/dist/memory/types.d.ts +175 -0
- package/dist/memory/types.js +70 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/planner/task-planner.js +19 -2
- package/dist/planner/task-planner.js.map +1 -1
- package/dist/schemas/api-schemas.js +1 -1
- package/dist/schemas/api-schemas.js.map +1 -1
- package/dist/schemas/index.d.ts +4 -4
- package/dist/schemas/settings-schemas.d.ts +14 -0
- package/dist/schemas/settings-schemas.js +10 -0
- package/dist/schemas/settings-schemas.js.map +1 -1
- package/dist/tools/bash.js +28 -7
- package/dist/tools/bash.js.map +1 -1
- package/dist/ui/components/chat-history.js +4 -2
- package/dist/ui/components/chat-history.js.map +1 -1
- package/dist/ui/components/chat-interface.js +9 -4
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/toast-notification.d.ts +3 -0
- package/dist/ui/components/toast-notification.js +18 -12
- package/dist/ui/components/toast-notification.js.map +1 -1
- package/dist/utils/background-task-manager.js +31 -9
- package/dist/utils/background-task-manager.js.map +1 -1
- package/dist/utils/custom-instructions.js +9 -1
- package/dist/utils/custom-instructions.js.map +1 -1
- package/dist/utils/prompt-builder.d.ts +4 -0
- package/dist/utils/prompt-builder.js +15 -0
- package/dist/utils/prompt-builder.js.map +1 -1
- package/dist/utils/settings-manager.d.ts +16 -1
- package/dist/utils/settings-manager.js +49 -0
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/token-counter.js +4 -0
- package/dist/utils/token-counter.js.map +1 -1
- package/dist/utils/usage-tracker.d.ts +19 -0
- package/dist/utils/usage-tracker.js +22 -1
- package/dist/utils/usage-tracker.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Generator - Scans project and generates context for GLM caching
|
|
3
|
+
*
|
|
4
|
+
* Produces a standardized context string that z.ai can automatically cache
|
|
5
|
+
* when used as a consistent system prompt prefix.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import * as crypto from 'crypto';
|
|
10
|
+
import { MEMORY_DEFAULTS, DEFAULT_IGNORE_PATTERNS, DEFAULT_INCLUDE_FILES, DEFAULT_SCAN_DIRECTORIES, } from './types.js';
|
|
11
|
+
import { createTokenCounter } from '../utils/token-counter.js';
|
|
12
|
+
import { ProjectAnalyzer } from '../utils/project-analyzer.js';
|
|
13
|
+
/**
|
|
14
|
+
* ContextGenerator - Creates project memory context
|
|
15
|
+
*/
|
|
16
|
+
export class ContextGenerator {
|
|
17
|
+
projectRoot;
|
|
18
|
+
tokenCounter;
|
|
19
|
+
warnings = [];
|
|
20
|
+
constructor(projectRoot = process.cwd()) {
|
|
21
|
+
this.projectRoot = projectRoot;
|
|
22
|
+
this.tokenCounter = createTokenCounter();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate project memory from scanning the codebase
|
|
26
|
+
*/
|
|
27
|
+
async generate(options = {}) {
|
|
28
|
+
const { depth = MEMORY_DEFAULTS.DEPTH, maxTokens = MEMORY_DEFAULTS.MAX_TOKENS, verbose = false, } = options;
|
|
29
|
+
this.warnings = [];
|
|
30
|
+
try {
|
|
31
|
+
// Build source configuration
|
|
32
|
+
const source = this.buildSourceConfig(depth);
|
|
33
|
+
if (verbose) {
|
|
34
|
+
console.log(` Scanning ${source.directories.length} directories...`);
|
|
35
|
+
}
|
|
36
|
+
// Generate each section
|
|
37
|
+
const sections = {};
|
|
38
|
+
// 1. Directory structure
|
|
39
|
+
if (verbose)
|
|
40
|
+
console.log(' Generating directory structure...');
|
|
41
|
+
const structure = this.generateStructure(source.directories);
|
|
42
|
+
sections.structure = {
|
|
43
|
+
content: structure,
|
|
44
|
+
tokens: this.tokenCounter.countTokens(structure),
|
|
45
|
+
};
|
|
46
|
+
// 2. README content
|
|
47
|
+
if (verbose)
|
|
48
|
+
console.log(' Reading README...');
|
|
49
|
+
const readme = this.generateReadmeSummary();
|
|
50
|
+
if (readme) {
|
|
51
|
+
sections.readme = {
|
|
52
|
+
content: readme,
|
|
53
|
+
tokens: this.tokenCounter.countTokens(readme),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// 3. Config files summary
|
|
57
|
+
if (verbose)
|
|
58
|
+
console.log(' Analyzing config files...');
|
|
59
|
+
const config = this.generateConfigSummary(source.files);
|
|
60
|
+
if (config) {
|
|
61
|
+
sections.config = {
|
|
62
|
+
content: config,
|
|
63
|
+
tokens: this.tokenCounter.countTokens(config),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// 4. Architecture patterns
|
|
67
|
+
if (verbose)
|
|
68
|
+
console.log(' Detecting architecture patterns...');
|
|
69
|
+
const patterns = await this.generatePatternsSummary();
|
|
70
|
+
if (patterns) {
|
|
71
|
+
sections.patterns = {
|
|
72
|
+
content: patterns,
|
|
73
|
+
tokens: this.tokenCounter.countTokens(patterns),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Assemble final context
|
|
77
|
+
const formatted = this.assembleContext(sections, maxTokens);
|
|
78
|
+
const tokenEstimate = this.tokenCounter.countTokens(formatted);
|
|
79
|
+
// Calculate content hash
|
|
80
|
+
const contentHash = this.calculateHash(formatted);
|
|
81
|
+
// Build section token counts
|
|
82
|
+
const sectionTokens = {
|
|
83
|
+
structure: sections.structure?.tokens,
|
|
84
|
+
readme: sections.readme?.tokens,
|
|
85
|
+
config: sections.config?.tokens,
|
|
86
|
+
patterns: sections.patterns?.tokens,
|
|
87
|
+
};
|
|
88
|
+
// Create memory object
|
|
89
|
+
const memory = {
|
|
90
|
+
version: 1,
|
|
91
|
+
created_at: new Date().toISOString(),
|
|
92
|
+
updated_at: new Date().toISOString(),
|
|
93
|
+
project_root: this.projectRoot,
|
|
94
|
+
content_hash: contentHash,
|
|
95
|
+
source,
|
|
96
|
+
context: {
|
|
97
|
+
formatted,
|
|
98
|
+
token_estimate: tokenEstimate,
|
|
99
|
+
sections: sectionTokens,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
success: true,
|
|
104
|
+
memory,
|
|
105
|
+
warnings: this.warnings.length > 0 ? this.warnings : undefined,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: error instanceof Error ? error.message : 'Unknown generation error',
|
|
112
|
+
warnings: this.warnings.length > 0 ? this.warnings : undefined,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Build source configuration based on project structure
|
|
118
|
+
*/
|
|
119
|
+
buildSourceConfig(depth) {
|
|
120
|
+
// Find existing directories from defaults
|
|
121
|
+
const directories = [];
|
|
122
|
+
for (const defaultDir of DEFAULT_SCAN_DIRECTORIES) {
|
|
123
|
+
const fullPath = path.join(this.projectRoot, defaultDir.path);
|
|
124
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
|
|
125
|
+
directories.push({
|
|
126
|
+
path: defaultDir.path,
|
|
127
|
+
max_depth: Math.min(defaultDir.max_depth, depth),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// If no default directories found, scan from root with limited depth
|
|
132
|
+
if (directories.length === 0) {
|
|
133
|
+
directories.push({ path: '.', max_depth: Math.min(2, depth) });
|
|
134
|
+
}
|
|
135
|
+
// Find existing files from defaults
|
|
136
|
+
const files = [];
|
|
137
|
+
for (const defaultFile of DEFAULT_INCLUDE_FILES) {
|
|
138
|
+
const fullPath = path.join(this.projectRoot, defaultFile);
|
|
139
|
+
if (fs.existsSync(fullPath)) {
|
|
140
|
+
files.push(defaultFile);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
directories,
|
|
145
|
+
files,
|
|
146
|
+
ignore: [...DEFAULT_IGNORE_PATTERNS],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generate directory tree structure
|
|
151
|
+
*/
|
|
152
|
+
generateStructure(directories) {
|
|
153
|
+
const lines = ['## Directory Structure', '```'];
|
|
154
|
+
for (const dir of directories) {
|
|
155
|
+
const tree = this.buildTree(dir.path, dir.max_depth);
|
|
156
|
+
if (tree.length > 0) {
|
|
157
|
+
if (dir.path !== '.') {
|
|
158
|
+
lines.push(`${dir.path}/`);
|
|
159
|
+
}
|
|
160
|
+
lines.push(...tree);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
lines.push('```');
|
|
164
|
+
return lines.join('\n');
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Recursively build tree representation
|
|
168
|
+
*/
|
|
169
|
+
buildTree(dirPath, maxDepth, prefix = '', currentDepth = 0) {
|
|
170
|
+
if (currentDepth >= maxDepth)
|
|
171
|
+
return [];
|
|
172
|
+
const fullPath = path.join(this.projectRoot, dirPath);
|
|
173
|
+
if (!fs.existsSync(fullPath))
|
|
174
|
+
return [];
|
|
175
|
+
let entries;
|
|
176
|
+
try {
|
|
177
|
+
entries = fs.readdirSync(fullPath, { withFileTypes: true });
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
const lines = [];
|
|
183
|
+
// Filter and sort entries
|
|
184
|
+
const filtered = entries
|
|
185
|
+
.filter((e) => !this.shouldIgnore(e.name))
|
|
186
|
+
.sort((a, b) => {
|
|
187
|
+
// Directories first
|
|
188
|
+
if (a.isDirectory() && !b.isDirectory())
|
|
189
|
+
return -1;
|
|
190
|
+
if (!a.isDirectory() && b.isDirectory())
|
|
191
|
+
return 1;
|
|
192
|
+
return a.name.localeCompare(b.name);
|
|
193
|
+
});
|
|
194
|
+
// Limit entries per directory to avoid huge trees
|
|
195
|
+
const maxEntries = 30;
|
|
196
|
+
const limited = filtered.slice(0, maxEntries);
|
|
197
|
+
const hasMore = filtered.length > maxEntries;
|
|
198
|
+
limited.forEach((entry, index) => {
|
|
199
|
+
const isLast = index === limited.length - 1 && !hasMore;
|
|
200
|
+
const connector = isLast ? '└── ' : '├── ';
|
|
201
|
+
const childPrefix = isLast ? ' ' : '│ ';
|
|
202
|
+
const displayName = entry.name + (entry.isDirectory() ? '/' : '');
|
|
203
|
+
lines.push(`${prefix}${connector}${displayName}`);
|
|
204
|
+
if (entry.isDirectory() && currentDepth + 1 < maxDepth) {
|
|
205
|
+
const childPath = path.join(dirPath, entry.name);
|
|
206
|
+
const childLines = this.buildTree(childPath, maxDepth, prefix + childPrefix, currentDepth + 1);
|
|
207
|
+
lines.push(...childLines);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
if (hasMore) {
|
|
211
|
+
lines.push(`${prefix}└── ... (${filtered.length - maxEntries} more)`);
|
|
212
|
+
}
|
|
213
|
+
return lines;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if a file/directory should be ignored
|
|
217
|
+
*/
|
|
218
|
+
shouldIgnore(name) {
|
|
219
|
+
for (const pattern of DEFAULT_IGNORE_PATTERNS) {
|
|
220
|
+
if (pattern.startsWith('*.')) {
|
|
221
|
+
// Extension pattern
|
|
222
|
+
if (name.endsWith(pattern.slice(1)))
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
else if (name === pattern) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Generate README summary
|
|
233
|
+
*/
|
|
234
|
+
generateReadmeSummary() {
|
|
235
|
+
const readmePaths = ['README.md', 'readme.md', 'Readme.md', 'README.rst'];
|
|
236
|
+
for (const readmePath of readmePaths) {
|
|
237
|
+
const fullPath = path.join(this.projectRoot, readmePath);
|
|
238
|
+
if (fs.existsSync(fullPath)) {
|
|
239
|
+
try {
|
|
240
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
241
|
+
const maxSize = MEMORY_DEFAULTS.MAX_FILE_SIZE;
|
|
242
|
+
const truncated = content.slice(0, maxSize);
|
|
243
|
+
const isTruncated = content.length > maxSize;
|
|
244
|
+
const lines = [
|
|
245
|
+
'## README Summary',
|
|
246
|
+
'',
|
|
247
|
+
truncated.trim(),
|
|
248
|
+
];
|
|
249
|
+
if (isTruncated) {
|
|
250
|
+
lines.push('', '[...truncated]');
|
|
251
|
+
}
|
|
252
|
+
return lines.join('\n');
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
this.warnings.push(`Failed to read ${readmePath}: ${error}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Generate config files summary
|
|
263
|
+
*/
|
|
264
|
+
generateConfigSummary(files) {
|
|
265
|
+
const summaries = ['## Key Configuration'];
|
|
266
|
+
let hasContent = false;
|
|
267
|
+
for (const file of files) {
|
|
268
|
+
const fullPath = path.join(this.projectRoot, file);
|
|
269
|
+
if (!fs.existsSync(fullPath))
|
|
270
|
+
continue;
|
|
271
|
+
try {
|
|
272
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
273
|
+
const summary = this.summarizeConfigFile(file, content);
|
|
274
|
+
if (summary) {
|
|
275
|
+
summaries.push('', `### ${file}`, '', summary);
|
|
276
|
+
hasContent = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
this.warnings.push(`Failed to read ${file}: ${error}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return hasContent ? summaries.join('\n') : null;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Summarize a config file based on its type
|
|
287
|
+
*/
|
|
288
|
+
summarizeConfigFile(filename, content) {
|
|
289
|
+
const basename = path.basename(filename);
|
|
290
|
+
try {
|
|
291
|
+
if (basename === 'package.json') {
|
|
292
|
+
return this.summarizePackageJson(content);
|
|
293
|
+
}
|
|
294
|
+
if (basename === 'tsconfig.json') {
|
|
295
|
+
return this.summarizeTsConfig(content);
|
|
296
|
+
}
|
|
297
|
+
if (basename === 'pyproject.toml') {
|
|
298
|
+
return this.summarizePyproject(content);
|
|
299
|
+
}
|
|
300
|
+
if (basename === 'Cargo.toml') {
|
|
301
|
+
return this.summarizeCargoToml(content);
|
|
302
|
+
}
|
|
303
|
+
if (basename === 'go.mod') {
|
|
304
|
+
return this.summarizeGoMod(content);
|
|
305
|
+
}
|
|
306
|
+
if (basename.startsWith('docker-compose') || basename === 'Dockerfile') {
|
|
307
|
+
// Just show first few lines
|
|
308
|
+
const lines = content.split('\n').slice(0, 15);
|
|
309
|
+
return '```\n' + lines.join('\n') + '\n```';
|
|
310
|
+
}
|
|
311
|
+
if (basename === 'CUSTOM.md') {
|
|
312
|
+
// Show first portion of custom instructions
|
|
313
|
+
const truncated = content.slice(0, 1000);
|
|
314
|
+
return truncated + (content.length > 1000 ? '\n[...truncated]' : '');
|
|
315
|
+
}
|
|
316
|
+
// Default: show first 500 chars
|
|
317
|
+
const maxLen = 500;
|
|
318
|
+
const truncated = content.slice(0, maxLen);
|
|
319
|
+
return '```\n' + truncated + (content.length > maxLen ? '\n...' : '') + '\n```';
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Summarize package.json
|
|
327
|
+
*/
|
|
328
|
+
summarizePackageJson(content) {
|
|
329
|
+
const pkg = JSON.parse(content);
|
|
330
|
+
const parts = [];
|
|
331
|
+
if (pkg.name)
|
|
332
|
+
parts.push(`- **Name**: ${pkg.name}`);
|
|
333
|
+
if (pkg.version)
|
|
334
|
+
parts.push(`- **Version**: ${pkg.version}`);
|
|
335
|
+
if (pkg.description)
|
|
336
|
+
parts.push(`- **Description**: ${pkg.description}`);
|
|
337
|
+
if (pkg.type)
|
|
338
|
+
parts.push(`- **Type**: ${pkg.type}`);
|
|
339
|
+
if (pkg.bin)
|
|
340
|
+
parts.push(`- **CLI**: Yes`);
|
|
341
|
+
if (pkg.dependencies) {
|
|
342
|
+
const deps = Object.keys(pkg.dependencies);
|
|
343
|
+
const display = deps.slice(0, 10).join(', ');
|
|
344
|
+
const more = deps.length > 10 ? ` (+${deps.length - 10} more)` : '';
|
|
345
|
+
parts.push(`- **Dependencies**: ${display}${more}`);
|
|
346
|
+
}
|
|
347
|
+
if (pkg.devDependencies) {
|
|
348
|
+
const deps = Object.keys(pkg.devDependencies);
|
|
349
|
+
const display = deps.slice(0, 8).join(', ');
|
|
350
|
+
const more = deps.length > 8 ? ` (+${deps.length - 8} more)` : '';
|
|
351
|
+
parts.push(`- **Dev Dependencies**: ${display}${more}`);
|
|
352
|
+
}
|
|
353
|
+
if (pkg.scripts) {
|
|
354
|
+
const scripts = Object.keys(pkg.scripts).slice(0, 6);
|
|
355
|
+
parts.push(`- **Scripts**: ${scripts.join(', ')}`);
|
|
356
|
+
}
|
|
357
|
+
return parts.join('\n');
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Summarize tsconfig.json
|
|
361
|
+
*/
|
|
362
|
+
summarizeTsConfig(content) {
|
|
363
|
+
const config = JSON.parse(content);
|
|
364
|
+
const opts = config.compilerOptions || {};
|
|
365
|
+
const parts = [];
|
|
366
|
+
if (opts.target)
|
|
367
|
+
parts.push(`- **Target**: ${opts.target}`);
|
|
368
|
+
if (opts.module)
|
|
369
|
+
parts.push(`- **Module**: ${opts.module}`);
|
|
370
|
+
if (opts.moduleResolution)
|
|
371
|
+
parts.push(`- **Module Resolution**: ${opts.moduleResolution}`);
|
|
372
|
+
if (opts.strict !== undefined)
|
|
373
|
+
parts.push(`- **Strict**: ${opts.strict}`);
|
|
374
|
+
if (opts.outDir)
|
|
375
|
+
parts.push(`- **Output**: ${opts.outDir}`);
|
|
376
|
+
return parts.join('\n') || '(minimal configuration)';
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Summarize pyproject.toml (basic extraction)
|
|
380
|
+
*/
|
|
381
|
+
summarizePyproject(content) {
|
|
382
|
+
const parts = [];
|
|
383
|
+
// Simple regex extraction for common fields
|
|
384
|
+
const nameMatch = content.match(/name\s*=\s*"([^"]+)"/);
|
|
385
|
+
if (nameMatch)
|
|
386
|
+
parts.push(`- **Name**: ${nameMatch[1]}`);
|
|
387
|
+
const versionMatch = content.match(/version\s*=\s*"([^"]+)"/);
|
|
388
|
+
if (versionMatch)
|
|
389
|
+
parts.push(`- **Version**: ${versionMatch[1]}`);
|
|
390
|
+
const pythonMatch = content.match(/python\s*=\s*"([^"]+)"/);
|
|
391
|
+
if (pythonMatch)
|
|
392
|
+
parts.push(`- **Python**: ${pythonMatch[1]}`);
|
|
393
|
+
return parts.join('\n') || content.slice(0, 300);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Summarize Cargo.toml (basic extraction)
|
|
397
|
+
*/
|
|
398
|
+
summarizeCargoToml(content) {
|
|
399
|
+
const parts = [];
|
|
400
|
+
const nameMatch = content.match(/name\s*=\s*"([^"]+)"/);
|
|
401
|
+
if (nameMatch)
|
|
402
|
+
parts.push(`- **Name**: ${nameMatch[1]}`);
|
|
403
|
+
const versionMatch = content.match(/version\s*=\s*"([^"]+)"/);
|
|
404
|
+
if (versionMatch)
|
|
405
|
+
parts.push(`- **Version**: ${versionMatch[1]}`);
|
|
406
|
+
const editionMatch = content.match(/edition\s*=\s*"([^"]+)"/);
|
|
407
|
+
if (editionMatch)
|
|
408
|
+
parts.push(`- **Edition**: ${editionMatch[1]}`);
|
|
409
|
+
return parts.join('\n') || content.slice(0, 300);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Summarize go.mod
|
|
413
|
+
*/
|
|
414
|
+
summarizeGoMod(content) {
|
|
415
|
+
const parts = [];
|
|
416
|
+
const moduleMatch = content.match(/module\s+(\S+)/);
|
|
417
|
+
if (moduleMatch)
|
|
418
|
+
parts.push(`- **Module**: ${moduleMatch[1]}`);
|
|
419
|
+
const goMatch = content.match(/go\s+(\S+)/);
|
|
420
|
+
if (goMatch)
|
|
421
|
+
parts.push(`- **Go Version**: ${goMatch[1]}`);
|
|
422
|
+
return parts.join('\n') || content.slice(0, 300);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Generate architecture patterns summary using ProjectAnalyzer
|
|
426
|
+
*/
|
|
427
|
+
async generatePatternsSummary() {
|
|
428
|
+
try {
|
|
429
|
+
const analyzer = new ProjectAnalyzer(this.projectRoot);
|
|
430
|
+
const result = await analyzer.analyze();
|
|
431
|
+
if (!result.success || !result.projectInfo) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
const info = result.projectInfo;
|
|
435
|
+
const lines = ['## Architecture Patterns'];
|
|
436
|
+
if (info.projectType) {
|
|
437
|
+
lines.push(`- **Project Type**: ${info.projectType}`);
|
|
438
|
+
}
|
|
439
|
+
if (info.primaryLanguage) {
|
|
440
|
+
lines.push(`- **Primary Language**: ${info.primaryLanguage}`);
|
|
441
|
+
}
|
|
442
|
+
if (info.techStack && info.techStack.length > 0) {
|
|
443
|
+
lines.push(`- **Tech Stack**: ${info.techStack.join(', ')}`);
|
|
444
|
+
}
|
|
445
|
+
if (info.packageManager) {
|
|
446
|
+
lines.push(`- **Package Manager**: ${info.packageManager}`);
|
|
447
|
+
}
|
|
448
|
+
if (info.entryPoint) {
|
|
449
|
+
lines.push(`- **Entry Point**: ${info.entryPoint}`);
|
|
450
|
+
}
|
|
451
|
+
// Add conventions
|
|
452
|
+
if (info.conventions) {
|
|
453
|
+
const conv = info.conventions;
|
|
454
|
+
if (conv.moduleSystem)
|
|
455
|
+
lines.push(`- **Module System**: ${conv.moduleSystem.toUpperCase()}`);
|
|
456
|
+
if (conv.testFramework)
|
|
457
|
+
lines.push(`- **Test Framework**: ${conv.testFramework}`);
|
|
458
|
+
if (conv.validation)
|
|
459
|
+
lines.push(`- **Validation**: ${conv.validation}`);
|
|
460
|
+
if (conv.linter)
|
|
461
|
+
lines.push(`- **Linter**: ${conv.linter}`);
|
|
462
|
+
}
|
|
463
|
+
// Add directories
|
|
464
|
+
if (info.directories) {
|
|
465
|
+
const dirs = info.directories;
|
|
466
|
+
const dirList = [];
|
|
467
|
+
if (dirs.source)
|
|
468
|
+
dirList.push(`source: ${dirs.source}`);
|
|
469
|
+
if (dirs.tests)
|
|
470
|
+
dirList.push(`tests: ${dirs.tests}`);
|
|
471
|
+
if (dirList.length > 0) {
|
|
472
|
+
lines.push(`- **Key Directories**: ${dirList.join(', ')}`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return lines.length > 1 ? lines.join('\n') : null;
|
|
476
|
+
}
|
|
477
|
+
catch (error) {
|
|
478
|
+
this.warnings.push(`Pattern analysis failed: ${error}`);
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Assemble final context from sections, respecting token limit
|
|
484
|
+
*/
|
|
485
|
+
assembleContext(sections, maxTokens) {
|
|
486
|
+
const projectName = path.basename(this.projectRoot);
|
|
487
|
+
const header = `# Project: ${projectName}\n\n`;
|
|
488
|
+
let currentTokens = this.tokenCounter.countTokens(header);
|
|
489
|
+
const parts = [header];
|
|
490
|
+
// Priority order for sections
|
|
491
|
+
const priority = ['patterns', 'structure', 'config', 'readme'];
|
|
492
|
+
for (const key of priority) {
|
|
493
|
+
const section = sections[key];
|
|
494
|
+
if (!section)
|
|
495
|
+
continue;
|
|
496
|
+
if (currentTokens + section.tokens <= maxTokens) {
|
|
497
|
+
parts.push(section.content, '\n');
|
|
498
|
+
currentTokens += section.tokens;
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
// Try to fit partial content
|
|
502
|
+
const remaining = maxTokens - currentTokens - 50; // Buffer for truncation note
|
|
503
|
+
if (remaining > 200) {
|
|
504
|
+
const truncated = this.truncateToTokens(section.content, remaining);
|
|
505
|
+
parts.push(truncated, '\n[...truncated due to token limit]\n');
|
|
506
|
+
this.warnings.push(`Section '${key}' was truncated to fit token limit`);
|
|
507
|
+
}
|
|
508
|
+
break; // Stop adding more sections
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return parts.join('\n').trim();
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Truncate text to approximate token count
|
|
515
|
+
*/
|
|
516
|
+
truncateToTokens(text, maxTokens) {
|
|
517
|
+
// Rough estimate: ~4 chars per token
|
|
518
|
+
const estimatedChars = maxTokens * 4;
|
|
519
|
+
if (text.length <= estimatedChars)
|
|
520
|
+
return text;
|
|
521
|
+
// Find a good break point (end of line)
|
|
522
|
+
const truncated = text.slice(0, estimatedChars);
|
|
523
|
+
const lastNewline = truncated.lastIndexOf('\n');
|
|
524
|
+
if (lastNewline > estimatedChars * 0.8) {
|
|
525
|
+
return truncated.slice(0, lastNewline);
|
|
526
|
+
}
|
|
527
|
+
return truncated;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Calculate SHA-256 hash of content
|
|
531
|
+
*/
|
|
532
|
+
calculateHash(content) {
|
|
533
|
+
const hash = crypto.createHash('sha256').update(content).digest('hex');
|
|
534
|
+
return `sha256:${hash}`;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
//# sourceMappingURL=context-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-generator.js","sourceRoot":"","sources":["../../src/memory/context-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AASjC,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,eAAe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E,OAAO,UAAU,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 type { ProjectMemory } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Memory metadata for quick access without loading full context
|
|
10
|
+
*/
|
|
11
|
+
export interface MemoryMetadata {
|
|
12
|
+
exists: boolean;
|
|
13
|
+
tokenEstimate?: number;
|
|
14
|
+
updatedAt?: string;
|
|
15
|
+
contentHash?: string;
|
|
16
|
+
usageCount?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* ContextInjector - Manages memory context injection
|
|
20
|
+
*/
|
|
21
|
+
export declare class ContextInjector {
|
|
22
|
+
private store;
|
|
23
|
+
private cachedMemory;
|
|
24
|
+
private enabled;
|
|
25
|
+
constructor(projectRoot?: string);
|
|
26
|
+
/**
|
|
27
|
+
* Enable or disable memory injection
|
|
28
|
+
*/
|
|
29
|
+
setEnabled(enabled: boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* Check if memory injection is enabled
|
|
32
|
+
*/
|
|
33
|
+
isEnabled(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get project memory context string
|
|
36
|
+
* Returns null if no memory exists or injection is disabled
|
|
37
|
+
*/
|
|
38
|
+
getContext(): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Inject memory context into a system prompt
|
|
41
|
+
*
|
|
42
|
+
* Memory context is prepended as a prefix to enable z.ai
|
|
43
|
+
* automatic caching when the same prefix is used across requests.
|
|
44
|
+
*
|
|
45
|
+
* @param basePrompt - The base system prompt
|
|
46
|
+
* @returns Modified prompt with memory context prefix
|
|
47
|
+
*/
|
|
48
|
+
injectIntoPrompt(basePrompt: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Check if project memory exists
|
|
51
|
+
*/
|
|
52
|
+
hasMemory(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get memory metadata without loading full context
|
|
55
|
+
*/
|
|
56
|
+
getMetadata(): MemoryMetadata;
|
|
57
|
+
/**
|
|
58
|
+
* Get the full memory object (loads from disk if not cached)
|
|
59
|
+
*/
|
|
60
|
+
getMemory(): ProjectMemory | null;
|
|
61
|
+
/**
|
|
62
|
+
* Clear the cached memory
|
|
63
|
+
* Call this when memory is updated externally
|
|
64
|
+
*/
|
|
65
|
+
clearCache(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get estimated token count of the memory context
|
|
68
|
+
*/
|
|
69
|
+
getTokenEstimate(): number;
|
|
70
|
+
/**
|
|
71
|
+
* Format a reminder message about missing memory
|
|
72
|
+
* Returns null if memory exists
|
|
73
|
+
*/
|
|
74
|
+
getMissingMemoryHint(): string | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the default context injector instance
|
|
78
|
+
*/
|
|
79
|
+
export declare function getContextInjector(projectRoot?: string): ContextInjector;
|
|
80
|
+
/**
|
|
81
|
+
* Reset the default injector (mainly for testing)
|
|
82
|
+
*/
|
|
83
|
+
export declare function resetDefaultInjector(): void;
|