agents-reverse-engineer 0.1.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/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/change-detection/detector.d.ts +24 -0
- package/dist/change-detection/detector.d.ts.map +1 -0
- package/dist/change-detection/detector.js +114 -0
- package/dist/change-detection/detector.js.map +1 -0
- package/dist/change-detection/index.d.ts +9 -0
- package/dist/change-detection/index.d.ts.map +1 -0
- package/dist/change-detection/index.js +8 -0
- package/dist/change-detection/index.js.map +1 -0
- package/dist/change-detection/types.d.ts +39 -0
- package/dist/change-detection/types.d.ts.map +1 -0
- package/dist/change-detection/types.js +5 -0
- package/dist/change-detection/types.js.map +1 -0
- package/dist/cli/discover.d.ts +52 -0
- package/dist/cli/discover.d.ts.map +1 -0
- package/dist/cli/discover.js +125 -0
- package/dist/cli/discover.js.map +1 -0
- package/dist/cli/generate.d.ts +41 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/cli/generate.js +179 -0
- package/dist/cli/generate.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +182 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +38 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +94 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/update.d.ts +28 -0
- package/dist/cli/update.d.ts.map +1 -0
- package/dist/cli/update.js +296 -0
- package/dist/cli/update.js.map +1 -0
- package/dist/config/defaults.d.ts +38 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +89 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/loader.d.ts +66 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +158 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +235 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +80 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/discovery/filters/binary.d.ts +46 -0
- package/dist/discovery/filters/binary.d.ts.map +1 -0
- package/dist/discovery/filters/binary.js +157 -0
- package/dist/discovery/filters/binary.js.map +1 -0
- package/dist/discovery/filters/custom.d.ts +26 -0
- package/dist/discovery/filters/custom.d.ts.map +1 -0
- package/dist/discovery/filters/custom.js +50 -0
- package/dist/discovery/filters/custom.js.map +1 -0
- package/dist/discovery/filters/gitignore.d.ts +24 -0
- package/dist/discovery/filters/gitignore.d.ts.map +1 -0
- package/dist/discovery/filters/gitignore.js +53 -0
- package/dist/discovery/filters/gitignore.js.map +1 -0
- package/dist/discovery/filters/index.d.ts +85 -0
- package/dist/discovery/filters/index.d.ts.map +1 -0
- package/dist/discovery/filters/index.js +98 -0
- package/dist/discovery/filters/index.js.map +1 -0
- package/dist/discovery/filters/vendor.d.ts +30 -0
- package/dist/discovery/filters/vendor.d.ts.map +1 -0
- package/dist/discovery/filters/vendor.js +57 -0
- package/dist/discovery/filters/vendor.js.map +1 -0
- package/dist/discovery/types.d.ts +66 -0
- package/dist/discovery/types.d.ts.map +1 -0
- package/dist/discovery/types.js +8 -0
- package/dist/discovery/types.js.map +1 -0
- package/dist/discovery/walker.d.ts +24 -0
- package/dist/discovery/walker.d.ts.map +1 -0
- package/dist/discovery/walker.js +35 -0
- package/dist/discovery/walker.js.map +1 -0
- package/dist/generation/budget/chunker.d.ts +38 -0
- package/dist/generation/budget/chunker.d.ts.map +1 -0
- package/dist/generation/budget/chunker.js +73 -0
- package/dist/generation/budget/chunker.js.map +1 -0
- package/dist/generation/budget/counter.d.ts +26 -0
- package/dist/generation/budget/counter.d.ts.map +1 -0
- package/dist/generation/budget/counter.js +45 -0
- package/dist/generation/budget/counter.js.map +1 -0
- package/dist/generation/budget/index.d.ts +4 -0
- package/dist/generation/budget/index.d.ts.map +1 -0
- package/dist/generation/budget/index.js +4 -0
- package/dist/generation/budget/index.js.map +1 -0
- package/dist/generation/budget/tracker.d.ts +63 -0
- package/dist/generation/budget/tracker.d.ts.map +1 -0
- package/dist/generation/budget/tracker.js +96 -0
- package/dist/generation/budget/tracker.js.map +1 -0
- package/dist/generation/complexity.d.ts +43 -0
- package/dist/generation/complexity.d.ts.map +1 -0
- package/dist/generation/complexity.js +156 -0
- package/dist/generation/complexity.js.map +1 -0
- package/dist/generation/detection/detector.d.ts +23 -0
- package/dist/generation/detection/detector.d.ts.map +1 -0
- package/dist/generation/detection/detector.js +62 -0
- package/dist/generation/detection/detector.js.map +1 -0
- package/dist/generation/detection/patterns.d.ts +21 -0
- package/dist/generation/detection/patterns.d.ts.map +1 -0
- package/dist/generation/detection/patterns.js +115 -0
- package/dist/generation/detection/patterns.js.map +1 -0
- package/dist/generation/executor.d.ts +95 -0
- package/dist/generation/executor.d.ts.map +1 -0
- package/dist/generation/executor.js +352 -0
- package/dist/generation/executor.js.map +1 -0
- package/dist/generation/orchestrator.d.ts +126 -0
- package/dist/generation/orchestrator.d.ts.map +1 -0
- package/dist/generation/orchestrator.js +222 -0
- package/dist/generation/orchestrator.js.map +1 -0
- package/dist/generation/prompts/builder.d.ts +31 -0
- package/dist/generation/prompts/builder.d.ts.map +1 -0
- package/dist/generation/prompts/builder.js +136 -0
- package/dist/generation/prompts/builder.js.map +1 -0
- package/dist/generation/prompts/index.d.ts +5 -0
- package/dist/generation/prompts/index.d.ts.map +1 -0
- package/dist/generation/prompts/index.js +4 -0
- package/dist/generation/prompts/index.js.map +1 -0
- package/dist/generation/prompts/templates.d.ts +11 -0
- package/dist/generation/prompts/templates.d.ts.map +1 -0
- package/dist/generation/prompts/templates.js +247 -0
- package/dist/generation/prompts/templates.js.map +1 -0
- package/dist/generation/prompts/types.d.ts +71 -0
- package/dist/generation/prompts/types.d.ts.map +1 -0
- package/dist/generation/prompts/types.js +23 -0
- package/dist/generation/prompts/types.js.map +1 -0
- package/dist/generation/types.d.ts +72 -0
- package/dist/generation/types.d.ts.map +1 -0
- package/dist/generation/types.js +5 -0
- package/dist/generation/types.js.map +1 -0
- package/dist/generation/writers/agents-md.d.ts +63 -0
- package/dist/generation/writers/agents-md.d.ts.map +1 -0
- package/dist/generation/writers/agents-md.js +235 -0
- package/dist/generation/writers/agents-md.js.map +1 -0
- package/dist/generation/writers/claude-md.d.ts +13 -0
- package/dist/generation/writers/claude-md.d.ts.map +1 -0
- package/dist/generation/writers/claude-md.js +33 -0
- package/dist/generation/writers/claude-md.js.map +1 -0
- package/dist/generation/writers/index.d.ts +5 -0
- package/dist/generation/writers/index.d.ts.map +1 -0
- package/dist/generation/writers/index.js +5 -0
- package/dist/generation/writers/index.js.map +1 -0
- package/dist/generation/writers/sum.d.ts +37 -0
- package/dist/generation/writers/sum.d.ts.map +1 -0
- package/dist/generation/writers/sum.js +98 -0
- package/dist/generation/writers/sum.js.map +1 -0
- package/dist/generation/writers/supplementary.d.ts +53 -0
- package/dist/generation/writers/supplementary.d.ts.map +1 -0
- package/dist/generation/writers/supplementary.js +195 -0
- package/dist/generation/writers/supplementary.js.map +1 -0
- package/dist/integration/detect.d.ts +28 -0
- package/dist/integration/detect.d.ts.map +1 -0
- package/dist/integration/detect.js +64 -0
- package/dist/integration/detect.js.map +1 -0
- package/dist/integration/generate.d.ts +36 -0
- package/dist/integration/generate.d.ts.map +1 -0
- package/dist/integration/generate.js +107 -0
- package/dist/integration/generate.js.map +1 -0
- package/dist/integration/templates.d.ts +42 -0
- package/dist/integration/templates.d.ts.map +1 -0
- package/dist/integration/templates.js +203 -0
- package/dist/integration/templates.js.map +1 -0
- package/dist/integration/types.d.ts +44 -0
- package/dist/integration/types.d.ts.map +1 -0
- package/dist/integration/types.js +8 -0
- package/dist/integration/types.js.map +1 -0
- package/dist/output/logger.d.ts +86 -0
- package/dist/output/logger.d.ts.map +1 -0
- package/dist/output/logger.js +107 -0
- package/dist/output/logger.js.map +1 -0
- package/dist/state/database.d.ts +9 -0
- package/dist/state/database.d.ts.map +1 -0
- package/dist/state/database.js +66 -0
- package/dist/state/database.js.map +1 -0
- package/dist/state/index.d.ts +8 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +7 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/migrations.d.ts +12 -0
- package/dist/state/migrations.d.ts.map +1 -0
- package/dist/state/migrations.js +39 -0
- package/dist/state/migrations.js.map +1 -0
- package/dist/state/types.d.ts +54 -0
- package/dist/state/types.d.ts.map +1 -0
- package/dist/state/types.js +2 -0
- package/dist/state/types.js.map +1 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/update/index.d.ts +10 -0
- package/dist/update/index.d.ts.map +1 -0
- package/dist/update/index.js +9 -0
- package/dist/update/index.js.map +1 -0
- package/dist/update/orchestrator.d.ts +91 -0
- package/dist/update/orchestrator.d.ts.map +1 -0
- package/dist/update/orchestrator.js +204 -0
- package/dist/update/orchestrator.js.map +1 -0
- package/dist/update/orphan-cleaner.d.ts +30 -0
- package/dist/update/orphan-cleaner.d.ts.map +1 -0
- package/dist/update/orphan-cleaner.js +151 -0
- package/dist/update/orphan-cleaner.js.map +1 -0
- package/dist/update/types.d.ts +59 -0
- package/dist/update/types.d.ts.map +1 -0
- package/dist/update/types.js +2 -0
- package/dist/update/types.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Coordinates the documentation generation workflow:
|
|
5
|
+
* - Discovers and prepares files for analysis
|
|
6
|
+
* - Detects file types
|
|
7
|
+
* - Creates analysis tasks with prompts
|
|
8
|
+
* - Tracks token budget
|
|
9
|
+
* - Creates directory-summary tasks for LLM-generated descriptions
|
|
10
|
+
*/
|
|
11
|
+
import type { Config } from '../config/schema.js';
|
|
12
|
+
import type { DiscoveryResult } from '../types/index.js';
|
|
13
|
+
import type { FileType } from './types.js';
|
|
14
|
+
import type { ComplexityMetrics } from './complexity.js';
|
|
15
|
+
/**
|
|
16
|
+
* A file prepared for analysis.
|
|
17
|
+
*/
|
|
18
|
+
export interface PreparedFile {
|
|
19
|
+
/** Absolute path to the file */
|
|
20
|
+
filePath: string;
|
|
21
|
+
/** Relative path from project root */
|
|
22
|
+
relativePath: string;
|
|
23
|
+
/** File content */
|
|
24
|
+
content: string;
|
|
25
|
+
/** Detected file type */
|
|
26
|
+
fileType: FileType;
|
|
27
|
+
/** Token count of content */
|
|
28
|
+
tokens: number;
|
|
29
|
+
/** Whether file needs chunking */
|
|
30
|
+
needsChunking: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Analysis task for a file or chunk.
|
|
34
|
+
*/
|
|
35
|
+
export interface AnalysisTask {
|
|
36
|
+
/** Type of task */
|
|
37
|
+
type: 'file' | 'chunk' | 'synthesis' | 'directory-summary';
|
|
38
|
+
/** File or directory path */
|
|
39
|
+
filePath: string;
|
|
40
|
+
/** System prompt */
|
|
41
|
+
systemPrompt: string;
|
|
42
|
+
/** User prompt */
|
|
43
|
+
userPrompt: string;
|
|
44
|
+
/** Estimated tokens for this task */
|
|
45
|
+
estimatedTokens: number;
|
|
46
|
+
/** Chunk info if applicable */
|
|
47
|
+
chunkInfo?: {
|
|
48
|
+
index: number;
|
|
49
|
+
total: number;
|
|
50
|
+
startLine: number;
|
|
51
|
+
endLine: number;
|
|
52
|
+
};
|
|
53
|
+
/** Directory info for directory-summary tasks */
|
|
54
|
+
directoryInfo?: {
|
|
55
|
+
/** Paths of .sum files in this directory */
|
|
56
|
+
sumFiles: string[];
|
|
57
|
+
/** Number of files analyzed */
|
|
58
|
+
fileCount: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Result of the generation planning process.
|
|
63
|
+
*/
|
|
64
|
+
export interface GenerationPlan {
|
|
65
|
+
/** Files to be analyzed */
|
|
66
|
+
files: PreparedFile[];
|
|
67
|
+
/** Analysis tasks to execute */
|
|
68
|
+
tasks: AnalysisTask[];
|
|
69
|
+
/** Complexity metrics */
|
|
70
|
+
complexity: ComplexityMetrics;
|
|
71
|
+
/** Whether to generate ARCHITECTURE.md */
|
|
72
|
+
generateArchitecture: boolean;
|
|
73
|
+
/** Whether to generate STACK.md */
|
|
74
|
+
generateStack: boolean;
|
|
75
|
+
/** Budget tracker state */
|
|
76
|
+
budget: {
|
|
77
|
+
total: number;
|
|
78
|
+
estimated: number;
|
|
79
|
+
remaining: number;
|
|
80
|
+
};
|
|
81
|
+
/** Files skipped due to budget */
|
|
82
|
+
skippedFiles: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Orchestrates the documentation generation workflow.
|
|
86
|
+
*/
|
|
87
|
+
export declare class GenerationOrchestrator {
|
|
88
|
+
private config;
|
|
89
|
+
private projectRoot;
|
|
90
|
+
private budgetTracker;
|
|
91
|
+
constructor(config: Config, projectRoot: string, totalFiles: number);
|
|
92
|
+
/**
|
|
93
|
+
* Prepare files for analysis by reading content and detecting types.
|
|
94
|
+
*/
|
|
95
|
+
prepareFiles(discoveryResult: DiscoveryResult): Promise<PreparedFile[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Create analysis tasks for files within budget.
|
|
98
|
+
*/
|
|
99
|
+
createTasks(files: PreparedFile[]): {
|
|
100
|
+
tasks: AnalysisTask[];
|
|
101
|
+
skipped: string[];
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Create directory-summary tasks for LLM-generated directory descriptions.
|
|
105
|
+
* These tasks run after all files in a directory are analyzed, allowing
|
|
106
|
+
* the LLM to synthesize a richer directory overview from the .sum files.
|
|
107
|
+
*/
|
|
108
|
+
createDirectorySummaryTasks(files: PreparedFile[]): AnalysisTask[];
|
|
109
|
+
/**
|
|
110
|
+
* Create a complete generation plan.
|
|
111
|
+
*/
|
|
112
|
+
createPlan(discoveryResult: DiscoveryResult): Promise<GenerationPlan>;
|
|
113
|
+
/**
|
|
114
|
+
* Check if package.json exists in project root.
|
|
115
|
+
*/
|
|
116
|
+
private hasPackageJson;
|
|
117
|
+
/**
|
|
118
|
+
* Get budget report.
|
|
119
|
+
*/
|
|
120
|
+
getBudgetReport(): import("./budget/tracker.js").BudgetReport;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a generation orchestrator with default config.
|
|
124
|
+
*/
|
|
125
|
+
export declare function createOrchestrator(config: Config, projectRoot: string, totalFiles: number): GenerationOrchestrator;
|
|
126
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/generation/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mBAAmB;IACnB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,mBAAmB,CAAC;IAC3D,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,YAAY,EAAE,MAAM,CAAC;I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AK,EAAE,YAAY,EAAE,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB;IA4ED;;;;OAIG;IACH,2BAA2B,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE;IAwClE;;OAEG;IACG,UAAU,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAmC3E;;OAEG;YACW,cAAc;IAS5B;;OAEG;IACH,eAAe;CAGhB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAExB"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Coordinates the documentation generation workflow:
|
|
5
|
+
* - Discovers and prepares files for analysis
|
|
6
|
+
* - Detects file types
|
|
7
|
+
* - Creates analysis tasks with prompts
|
|
8
|
+
* - Tracks token budget
|
|
9
|
+
* - Creates directory-summary tasks for LLM-generated descriptions
|
|
10
|
+
*/
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import { detectFileType } from './detection/detector.js';
|
|
14
|
+
import { BudgetTracker, countTokens, needsChunking, chunkFile } from './budget/index.js';
|
|
15
|
+
import { buildPrompt, buildChunkPrompt } from './prompts/index.js';
|
|
16
|
+
import { analyzeComplexity, shouldGenerateArchitecture, shouldGenerateStack } from './complexity.js';
|
|
17
|
+
/**
|
|
18
|
+
* Orchestrates the documentation generation workflow.
|
|
19
|
+
*/
|
|
20
|
+
export class GenerationOrchestrator {
|
|
21
|
+
config;
|
|
22
|
+
projectRoot;
|
|
23
|
+
budgetTracker;
|
|
24
|
+
constructor(config, projectRoot, totalFiles) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.projectRoot = projectRoot;
|
|
27
|
+
this.budgetTracker = new BudgetTracker(config.generation.tokenBudget, totalFiles);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Prepare files for analysis by reading content and detecting types.
|
|
31
|
+
*/
|
|
32
|
+
async prepareFiles(discoveryResult) {
|
|
33
|
+
const prepared = [];
|
|
34
|
+
for (const filePath of discoveryResult.files) {
|
|
35
|
+
try {
|
|
36
|
+
const content = await readFile(filePath, 'utf-8');
|
|
37
|
+
const tokens = countTokens(content);
|
|
38
|
+
const fileType = detectFileType(filePath, content);
|
|
39
|
+
const relativePath = path.relative(this.projectRoot, filePath);
|
|
40
|
+
prepared.push({
|
|
41
|
+
filePath,
|
|
42
|
+
relativePath,
|
|
43
|
+
content,
|
|
44
|
+
fileType,
|
|
45
|
+
tokens,
|
|
46
|
+
needsChunking: needsChunking(content, this.config.generation.chunkSize),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Skip files that can't be read (permission errors, etc.)
|
|
51
|
+
// Silently ignore - these files won't appear in the plan
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Sort by token count (smaller files first for breadth-first coverage)
|
|
55
|
+
return prepared.sort((a, b) => a.tokens - b.tokens);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create analysis tasks for files within budget.
|
|
59
|
+
*/
|
|
60
|
+
createTasks(files) {
|
|
61
|
+
const tasks = [];
|
|
62
|
+
const skipped = [];
|
|
63
|
+
for (const file of files) {
|
|
64
|
+
const promptOverhead = 600; // Approximate overhead for prompts
|
|
65
|
+
const estimatedTotal = file.tokens + promptOverhead;
|
|
66
|
+
if (!this.budgetTracker.canProcess(estimatedTotal)) {
|
|
67
|
+
this.budgetTracker.recordSkipped(file.relativePath);
|
|
68
|
+
skipped.push(file.relativePath);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (file.needsChunking) {
|
|
72
|
+
// Create chunk tasks
|
|
73
|
+
const chunks = chunkFile(file.content, {
|
|
74
|
+
chunkSize: this.config.generation.chunkSize,
|
|
75
|
+
});
|
|
76
|
+
for (const chunk of chunks) {
|
|
77
|
+
const chunkPrompt = buildChunkPrompt({
|
|
78
|
+
filePath: file.filePath,
|
|
79
|
+
content: chunk.content,
|
|
80
|
+
fileType: file.fileType,
|
|
81
|
+
chunkIndex: chunk.index,
|
|
82
|
+
totalChunks: chunks.length,
|
|
83
|
+
lineRange: { start: chunk.startLine, end: chunk.endLine },
|
|
84
|
+
});
|
|
85
|
+
tasks.push({
|
|
86
|
+
type: 'chunk',
|
|
87
|
+
filePath: file.relativePath,
|
|
88
|
+
systemPrompt: chunkPrompt.system,
|
|
89
|
+
userPrompt: chunkPrompt.user,
|
|
90
|
+
estimatedTokens: chunk.tokens + promptOverhead,
|
|
91
|
+
chunkInfo: {
|
|
92
|
+
index: chunk.index,
|
|
93
|
+
total: chunks.length,
|
|
94
|
+
startLine: chunk.startLine,
|
|
95
|
+
endLine: chunk.endLine,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Add synthesis task (will be executed after chunks)
|
|
100
|
+
tasks.push({
|
|
101
|
+
type: 'synthesis',
|
|
102
|
+
filePath: file.relativePath,
|
|
103
|
+
systemPrompt: '', // Will be set during execution
|
|
104
|
+
userPrompt: `Synthesize summaries for ${file.relativePath}`,
|
|
105
|
+
estimatedTokens: promptOverhead,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Single file task
|
|
110
|
+
const prompt = buildPrompt({
|
|
111
|
+
filePath: file.filePath,
|
|
112
|
+
content: file.content,
|
|
113
|
+
fileType: file.fileType,
|
|
114
|
+
});
|
|
115
|
+
tasks.push({
|
|
116
|
+
type: 'file',
|
|
117
|
+
filePath: file.relativePath,
|
|
118
|
+
systemPrompt: prompt.system,
|
|
119
|
+
userPrompt: prompt.user,
|
|
120
|
+
estimatedTokens: estimatedTotal,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
this.budgetTracker.recordProcessed(file.relativePath, estimatedTotal);
|
|
124
|
+
}
|
|
125
|
+
return { tasks, skipped };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create directory-summary tasks for LLM-generated directory descriptions.
|
|
129
|
+
* These tasks run after all files in a directory are analyzed, allowing
|
|
130
|
+
* the LLM to synthesize a richer directory overview from the .sum files.
|
|
131
|
+
*/
|
|
132
|
+
createDirectorySummaryTasks(files) {
|
|
133
|
+
const tasks = [];
|
|
134
|
+
// Group files by directory
|
|
135
|
+
const filesByDir = new Map();
|
|
136
|
+
for (const file of files) {
|
|
137
|
+
const dir = path.dirname(file.relativePath);
|
|
138
|
+
const dirFiles = filesByDir.get(dir) ?? [];
|
|
139
|
+
dirFiles.push(file);
|
|
140
|
+
filesByDir.set(dir, dirFiles);
|
|
141
|
+
}
|
|
142
|
+
// Create a directory-summary task for each directory with analyzed files
|
|
143
|
+
for (const [dir, dirFiles] of Array.from(filesByDir.entries())) {
|
|
144
|
+
const sumFilePaths = dirFiles.map(f => `${f.relativePath}.sum`);
|
|
145
|
+
const promptOverhead = 800; // Overhead for directory summary prompts
|
|
146
|
+
tasks.push({
|
|
147
|
+
type: 'directory-summary',
|
|
148
|
+
filePath: dir || '.',
|
|
149
|
+
systemPrompt: `You are generating a directory description for documentation.
|
|
150
|
+
Analyze the provided .sum file contents to create a concise, informative directory overview.
|
|
151
|
+
Focus on:
|
|
152
|
+
1. The primary purpose of this directory
|
|
153
|
+
2. How the files work together
|
|
154
|
+
3. Key patterns or conventions used
|
|
155
|
+
Keep the description to 1-3 sentences.`,
|
|
156
|
+
userPrompt: `Generate a directory description for "${dir || 'root'}" based on ${dirFiles.length} analyzed files.
|
|
157
|
+
The .sum files contain individual file summaries - synthesize them into a cohesive directory overview.`,
|
|
158
|
+
estimatedTokens: promptOverhead,
|
|
159
|
+
directoryInfo: {
|
|
160
|
+
sumFiles: sumFilePaths,
|
|
161
|
+
fileCount: dirFiles.length,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return tasks;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Create a complete generation plan.
|
|
169
|
+
*/
|
|
170
|
+
async createPlan(discoveryResult) {
|
|
171
|
+
const files = await this.prepareFiles(discoveryResult);
|
|
172
|
+
const complexity = analyzeComplexity(files.map(f => f.filePath), this.projectRoot);
|
|
173
|
+
const { tasks: fileTasks, skipped } = this.createTasks(files);
|
|
174
|
+
// Add directory-summary tasks for LLM-generated directory descriptions
|
|
175
|
+
// These run after file analysis to synthesize richer directory overviews
|
|
176
|
+
const dirTasks = this.createDirectorySummaryTasks(files);
|
|
177
|
+
const tasks = [...fileTasks, ...dirTasks];
|
|
178
|
+
// Check for package.json to determine STACK.md generation
|
|
179
|
+
const hasPackageJson = await this.hasPackageJson();
|
|
180
|
+
return {
|
|
181
|
+
files,
|
|
182
|
+
tasks,
|
|
183
|
+
complexity,
|
|
184
|
+
generateArchitecture: this.config.generation.generateArchitecture &&
|
|
185
|
+
shouldGenerateArchitecture(complexity),
|
|
186
|
+
generateStack: this.config.generation.generateStack &&
|
|
187
|
+
hasPackageJson &&
|
|
188
|
+
shouldGenerateStack(hasPackageJson),
|
|
189
|
+
budget: {
|
|
190
|
+
total: this.config.generation.tokenBudget,
|
|
191
|
+
estimated: this.budgetTracker.getReport().used,
|
|
192
|
+
remaining: this.budgetTracker.remaining,
|
|
193
|
+
},
|
|
194
|
+
skippedFiles: skipped,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Check if package.json exists in project root.
|
|
199
|
+
*/
|
|
200
|
+
async hasPackageJson() {
|
|
201
|
+
try {
|
|
202
|
+
await readFile(path.join(this.projectRoot, 'package.json'), 'utf-8');
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get budget report.
|
|
211
|
+
*/
|
|
212
|
+
getBudgetReport() {
|
|
213
|
+
return this.budgetTracker.getReport();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Create a generation orchestrator with default config.
|
|
218
|
+
*/
|
|
219
|
+
export function createOrchestrator(config, projectRoot, totalFiles) {
|
|
220
|
+
return new GenerationOrchestrator(config, projectRoot, totalFiles);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/generation/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AA2ErG;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACzB,MAAM,CAAS;IACf,WAAW,CAAS;IACpB,aAAa,CAAgB;IAErC,YAAY,MAAc,EAAE,WAAmB,EAAE,UAAkB;QACjE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CACpC,MAAM,CAAC,UAAU,CAAC,WAAW,EAC7B,UAAU,CACX,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,eAAgC;QACjD,MAAM,QAAQ,GAAmB,EAAE,CAAC;QAEpC,KAAK,MAAM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Ac,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAEnD,OAAO;YACL,KAAK;YACL,KAAK;YACL,UAAU;YACV,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB;gBAC/D,0BAA0B,CAAC,UAAU,CAAC;YACxC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa;gBACjD,cAAc;gBACd,mBAAmB,CAAC,cAAc,CAAC;YACrC,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW;gBACzC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,IAAI;gBAC9C,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,SAAS;aACxC;YACD,YAAY,EAAE,OAAO;SACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,cAAc;QAC1B,IAAI,CAAC;YACH,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC;YACrE,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;IACxC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,WAAmB,EACnB,UAAkB;IAElB,OAAO,IAAI,sBAAsB,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PromptContext, ChunkContext, SynthesisContext } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Detect language from file extension for syntax highlighting.
|
|
4
|
+
*/
|
|
5
|
+
export declare function detectLanguage(filePath: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Detect framework from file content for component templates.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectFramework(content: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Build a complete prompt for file analysis.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildPrompt(context: PromptContext): {
|
|
14
|
+
system: string;
|
|
15
|
+
user: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Build a prompt for summarizing a chunk of a large file.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildChunkPrompt(context: ChunkContext): {
|
|
21
|
+
system: string;
|
|
22
|
+
user: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Build a prompt for synthesizing chunk summaries into final summary.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildSynthesisPrompt(context: SynthesisContext): {
|
|
28
|
+
system: string;
|
|
29
|
+
user: string;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/generation/prompts/builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGhF;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA2BvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAcvD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CA0BA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CA2BA;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAgCA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { getTemplate } from './templates.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detect language from file extension for syntax highlighting.
|
|
5
|
+
*/
|
|
6
|
+
export function detectLanguage(filePath) {
|
|
7
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
8
|
+
const langMap = {
|
|
9
|
+
'.ts': 'typescript',
|
|
10
|
+
'.tsx': 'tsx',
|
|
11
|
+
'.js': 'javascript',
|
|
12
|
+
'.jsx': 'jsx',
|
|
13
|
+
'.py': 'python',
|
|
14
|
+
'.rb': 'ruby',
|
|
15
|
+
'.go': 'go',
|
|
16
|
+
'.rs': 'rust',
|
|
17
|
+
'.java': 'java',
|
|
18
|
+
'.kt': 'kotlin',
|
|
19
|
+
'.swift': 'swift',
|
|
20
|
+
'.cs': 'csharp',
|
|
21
|
+
'.php': 'php',
|
|
22
|
+
'.vue': 'vue',
|
|
23
|
+
'.svelte': 'svelte',
|
|
24
|
+
'.json': 'json',
|
|
25
|
+
'.yaml': 'yaml',
|
|
26
|
+
'.yml': 'yaml',
|
|
27
|
+
'.md': 'markdown',
|
|
28
|
+
'.css': 'css',
|
|
29
|
+
'.scss': 'scss',
|
|
30
|
+
'.html': 'html',
|
|
31
|
+
};
|
|
32
|
+
return langMap[ext] ?? 'text';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Detect framework from file content for component templates.
|
|
36
|
+
*/
|
|
37
|
+
export function detectFramework(content) {
|
|
38
|
+
if (content.includes("from 'react'") || content.includes('from "react"')) {
|
|
39
|
+
return 'React';
|
|
40
|
+
}
|
|
41
|
+
if (content.includes("from 'vue'") || content.includes('from "vue"')) {
|
|
42
|
+
return 'Vue';
|
|
43
|
+
}
|
|
44
|
+
if (content.includes("from 'svelte'") || content.includes('.svelte')) {
|
|
45
|
+
return 'Svelte';
|
|
46
|
+
}
|
|
47
|
+
if (content.includes('@angular')) {
|
|
48
|
+
return 'Angular';
|
|
49
|
+
}
|
|
50
|
+
return 'JavaScript';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build a complete prompt for file analysis.
|
|
54
|
+
*/
|
|
55
|
+
export function buildPrompt(context) {
|
|
56
|
+
const template = getTemplate(context.fileType);
|
|
57
|
+
const lang = detectLanguage(context.filePath);
|
|
58
|
+
const framework = detectFramework(context.content);
|
|
59
|
+
let userPrompt = template.userPrompt
|
|
60
|
+
.replace(/\{\{FILE_PATH\}\}/g, context.filePath)
|
|
61
|
+
.replace(/\{\{CONTENT\}\}/g, context.content)
|
|
62
|
+
.replace(/\{\{LANG\}\}/g, lang)
|
|
63
|
+
.replace(/\{\{FRAMEWORK\}\}/g, framework);
|
|
64
|
+
// Add context files if provided
|
|
65
|
+
if (context.contextFiles && context.contextFiles.length > 0) {
|
|
66
|
+
const contextSection = context.contextFiles
|
|
67
|
+
.map((f) => `\n### ${f.path}\n\`\`\`${detectLanguage(f.path)}\n${f.content}\n\`\`\``)
|
|
68
|
+
.join('\n');
|
|
69
|
+
userPrompt += `\n\n## Related Files\n${contextSection}`;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
system: template.systemPrompt,
|
|
73
|
+
user: userPrompt,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build a prompt for summarizing a chunk of a large file.
|
|
78
|
+
*/
|
|
79
|
+
export function buildChunkPrompt(context) {
|
|
80
|
+
const template = getTemplate(context.fileType);
|
|
81
|
+
const lang = detectLanguage(context.filePath);
|
|
82
|
+
const system = `${template.systemPrompt}
|
|
83
|
+
|
|
84
|
+
This is chunk ${context.chunkIndex + 1} of ${context.totalChunks} from a large file.
|
|
85
|
+
Focus on what THIS chunk contains. The chunks will be synthesized later.`;
|
|
86
|
+
const user = `Analyze this code chunk and generate a partial summary.
|
|
87
|
+
|
|
88
|
+
File: ${context.filePath} (lines ${context.lineRange.start}-${context.lineRange.end})
|
|
89
|
+
Chunk: ${context.chunkIndex + 1} of ${context.totalChunks}
|
|
90
|
+
|
|
91
|
+
\`\`\`${lang}
|
|
92
|
+
${context.content}
|
|
93
|
+
\`\`\`
|
|
94
|
+
|
|
95
|
+
Summarize what this chunk contains:
|
|
96
|
+
- Functions/classes defined
|
|
97
|
+
- Key logic and patterns
|
|
98
|
+
- Dependencies used
|
|
99
|
+
- Notable details
|
|
100
|
+
|
|
101
|
+
Keep it concise - this will be combined with other chunks.`;
|
|
102
|
+
return { system, user };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Build a prompt for synthesizing chunk summaries into final summary.
|
|
106
|
+
*/
|
|
107
|
+
export function buildSynthesisPrompt(context) {
|
|
108
|
+
const template = getTemplate(context.fileType);
|
|
109
|
+
const system = `${template.systemPrompt}
|
|
110
|
+
|
|
111
|
+
You are synthesizing chunk summaries into a final, cohesive summary.`;
|
|
112
|
+
const chunkSection = context.chunkSummaries
|
|
113
|
+
.map((summary, i) => `### Chunk ${i + 1}\n${summary}`)
|
|
114
|
+
.join('\n\n');
|
|
115
|
+
const user = `Synthesize these chunk summaries into a final summary for the file.
|
|
116
|
+
|
|
117
|
+
File: ${context.filePath}
|
|
118
|
+
File Type: ${context.fileType}
|
|
119
|
+
|
|
120
|
+
## Chunk Summaries
|
|
121
|
+
|
|
122
|
+
${chunkSection}
|
|
123
|
+
|
|
124
|
+
## Instructions
|
|
125
|
+
|
|
126
|
+
Create a unified summary (300-500 words) that:
|
|
127
|
+
1. Combines insights from all chunks
|
|
128
|
+
2. Eliminates redundancy
|
|
129
|
+
3. Presents a coherent overview of the entire file
|
|
130
|
+
4. Follows the format for ${context.fileType} files
|
|
131
|
+
|
|
132
|
+
Focus on:
|
|
133
|
+
${template.focusAreas.map((area) => `- ${area}`).join('\n')}`;
|
|
134
|
+
return { system, user };
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/generation/prompts/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACjD,MAAM,OAAO,GAA2B;QACtC,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,MAAM;QACf,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,QAAQ;QACnB,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,UAAU;QACjB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,MAAM;KAChB,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QACzE,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAA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QAAQ;;;;EAI3B,YAAY;;;;;;;;4BAQc,OAAO,CAAC,QAAQ;;;EAG1C,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAE5D,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { PromptTemplate, PromptContext, ChunkContext, SynthesisContext, } from './types.js';
|
|
2
|
+
export { SUMMARY_GUIDELINES } from './types.js';
|
|
3
|
+
export { TEMPLATES, getTemplate } from './templates.js';
|
|
4
|
+
export { buildPrompt, buildChunkPrompt, buildSynthesisPrompt, detectLanguage, detectFramework, } from './builder.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generation/prompts/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generation/prompts/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FileType } from '../types.js';
|
|
2
|
+
import type { PromptTemplate } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Map of file types to their prompt templates.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TEMPLATES: Record<FileType, PromptTemplate>;
|
|
7
|
+
/**
|
|
8
|
+
* Get the prompt template for a file type.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTemplate(fileType: FileType): PromptTemplate;
|
|
11
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/generation/prompts/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA8OjD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,CAYtD,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAE9D"}
|