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,45 @@
|
|
|
1
|
+
import { encode, isWithinTokenLimit as checkLimit } from 'gpt-tokenizer';
|
|
2
|
+
/**
|
|
3
|
+
* Count tokens in content using BPE tokenization.
|
|
4
|
+
* Uses cl100k_base encoding (compatible with Claude/GPT-4).
|
|
5
|
+
*
|
|
6
|
+
* @param content - Text to count tokens in
|
|
7
|
+
* @returns Token count
|
|
8
|
+
*/
|
|
9
|
+
export function countTokens(content) {
|
|
10
|
+
return encode(content).length;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Check if content fits within token limit without fully encoding.
|
|
14
|
+
* More efficient than counting when you only need a boolean check.
|
|
15
|
+
*
|
|
16
|
+
* @param content - Text to check
|
|
17
|
+
* @param limit - Maximum allowed tokens
|
|
18
|
+
* @returns true if content is within limit
|
|
19
|
+
*/
|
|
20
|
+
export function isWithinLimit(content, limit) {
|
|
21
|
+
// checkLimit returns token count if within limit, false if exceeded
|
|
22
|
+
return checkLimit(content, limit) !== false;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Estimate prompt overhead for a given file type.
|
|
26
|
+
* Includes template tokens + system prompt portion.
|
|
27
|
+
*
|
|
28
|
+
* @param fileType - Type of file being summarized
|
|
29
|
+
* @returns Estimated overhead in tokens
|
|
30
|
+
*/
|
|
31
|
+
export function estimatePromptOverhead(fileType) {
|
|
32
|
+
// Base overhead for all prompts (system instructions, formatting)
|
|
33
|
+
const BASE_OVERHEAD = 500;
|
|
34
|
+
// Additional overhead by file type (templates vary in size)
|
|
35
|
+
const TYPE_OVERHEAD = {
|
|
36
|
+
component: 200,
|
|
37
|
+
service: 150,
|
|
38
|
+
api: 180,
|
|
39
|
+
model: 120,
|
|
40
|
+
schema: 100,
|
|
41
|
+
generic: 100,
|
|
42
|
+
};
|
|
43
|
+
return BASE_OVERHEAD + (TYPE_OVERHEAD[fileType] ?? 100);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../../../src/generation/budget/counter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AAChC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,KAAa;IAC1D,oEAAoE;IACpE,OAAO,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,KAAK,CAAC;AAC9C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,kEAAkE;IAClE,MAAM,aAAa,GAAG,GAAG,CAAC;IAE1B,4DAA4D;IAC5D,MAAM,aAAa,GAA2B;QAC5C,SAAS,EAAE,GAAG;QACd,OAAO,EAAE,GAAG;QACZ,GAAG,EAAE,GAAG;QACR,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,GAAG;KACb,CAAC;IAEF,OAAO,aAAa,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { countTokens, isWithinLimit, estimatePromptOverhead } from './counter.js';
|
|
2
|
+
export { BudgetTracker, type BudgetReport, type FileEstimate } from './tracker.js';
|
|
3
|
+
export { chunkFile, needsChunking, getTotalChunkTokens, type Chunk, type ChunkOptions } from './chunker.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generation/budget/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generation/budget/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,aAAa,EAAwC,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAiC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface BudgetReport {
|
|
2
|
+
totalBudget: number;
|
|
3
|
+
used: number;
|
|
4
|
+
remaining: number;
|
|
5
|
+
percentUsed: number;
|
|
6
|
+
filesProcessed: number;
|
|
7
|
+
filesRemaining: number;
|
|
8
|
+
averagePerFile: number;
|
|
9
|
+
exhausted: boolean;
|
|
10
|
+
completedFiles: string[];
|
|
11
|
+
skippedFiles: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface FileEstimate {
|
|
14
|
+
filePath: string;
|
|
15
|
+
tokens: number;
|
|
16
|
+
canProcess: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Tracks token budget across the entire project.
|
|
20
|
+
* Enforces budget limits and reports progress.
|
|
21
|
+
*/
|
|
22
|
+
export declare class BudgetTracker {
|
|
23
|
+
private totalBudget;
|
|
24
|
+
private used;
|
|
25
|
+
private filesProcessed;
|
|
26
|
+
private totalFiles;
|
|
27
|
+
private completedFiles;
|
|
28
|
+
private skippedFiles;
|
|
29
|
+
constructor(totalBudget: number, totalFiles: number);
|
|
30
|
+
/**
|
|
31
|
+
* Check if there's enough budget to process a file.
|
|
32
|
+
*/
|
|
33
|
+
canProcess(estimatedTokens: number): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get remaining budget.
|
|
36
|
+
*/
|
|
37
|
+
get remaining(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Estimate tokens for a file and check if it can be processed.
|
|
40
|
+
*/
|
|
41
|
+
estimate(filePath: string, content: string, promptOverhead: number): FileEstimate;
|
|
42
|
+
/**
|
|
43
|
+
* Record that a file was processed, consuming budget.
|
|
44
|
+
*/
|
|
45
|
+
recordProcessed(filePath: string, tokensUsed: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Record that a file was skipped due to budget constraints.
|
|
48
|
+
*/
|
|
49
|
+
recordSkipped(filePath: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Check if budget is exhausted (should stop processing).
|
|
52
|
+
*/
|
|
53
|
+
isExhausted(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Get a report of budget status.
|
|
56
|
+
*/
|
|
57
|
+
getReport(): BudgetReport;
|
|
58
|
+
/**
|
|
59
|
+
* Create a summary message for CLI output.
|
|
60
|
+
*/
|
|
61
|
+
getSummaryMessage(): string;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../../src/generation/budget/tracker.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,YAAY,CAAgB;gBAExB,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAKnD;;OAEG;IACH,UAAU,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO;IAI5C;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,YAAY;IAWjF;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAM3D;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIrC;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,SAAS,IAAI,YAAY;IAezB;;OAEG;IACH,iBAAiB,IAAI,MAAM;CAiB5B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { countTokens } from './counter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks token budget across the entire project.
|
|
4
|
+
* Enforces budget limits and reports progress.
|
|
5
|
+
*/
|
|
6
|
+
export class BudgetTracker {
|
|
7
|
+
totalBudget;
|
|
8
|
+
used = 0;
|
|
9
|
+
filesProcessed = 0;
|
|
10
|
+
totalFiles;
|
|
11
|
+
completedFiles = [];
|
|
12
|
+
skippedFiles = [];
|
|
13
|
+
constructor(totalBudget, totalFiles) {
|
|
14
|
+
this.totalBudget = totalBudget;
|
|
15
|
+
this.totalFiles = totalFiles;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if there's enough budget to process a file.
|
|
19
|
+
*/
|
|
20
|
+
canProcess(estimatedTokens) {
|
|
21
|
+
return this.remaining >= estimatedTokens;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get remaining budget.
|
|
25
|
+
*/
|
|
26
|
+
get remaining() {
|
|
27
|
+
return this.totalBudget - this.used;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Estimate tokens for a file and check if it can be processed.
|
|
31
|
+
*/
|
|
32
|
+
estimate(filePath, content, promptOverhead) {
|
|
33
|
+
const contentTokens = countTokens(content);
|
|
34
|
+
const totalTokens = contentTokens + promptOverhead;
|
|
35
|
+
return {
|
|
36
|
+
filePath,
|
|
37
|
+
tokens: totalTokens,
|
|
38
|
+
canProcess: this.canProcess(totalTokens),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Record that a file was processed, consuming budget.
|
|
43
|
+
*/
|
|
44
|
+
recordProcessed(filePath, tokensUsed) {
|
|
45
|
+
this.used += tokensUsed;
|
|
46
|
+
this.filesProcessed++;
|
|
47
|
+
this.completedFiles.push(filePath);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Record that a file was skipped due to budget constraints.
|
|
51
|
+
*/
|
|
52
|
+
recordSkipped(filePath) {
|
|
53
|
+
this.skippedFiles.push(filePath);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if budget is exhausted (should stop processing).
|
|
57
|
+
*/
|
|
58
|
+
isExhausted() {
|
|
59
|
+
return this.remaining <= 0;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get a report of budget status.
|
|
63
|
+
*/
|
|
64
|
+
getReport() {
|
|
65
|
+
return {
|
|
66
|
+
totalBudget: this.totalBudget,
|
|
67
|
+
used: this.used,
|
|
68
|
+
remaining: this.remaining,
|
|
69
|
+
percentUsed: this.totalBudget > 0 ? (this.used / this.totalBudget) * 100 : 0,
|
|
70
|
+
filesProcessed: this.filesProcessed,
|
|
71
|
+
filesRemaining: this.totalFiles - this.filesProcessed,
|
|
72
|
+
averagePerFile: this.filesProcessed > 0 ? this.used / this.filesProcessed : 0,
|
|
73
|
+
exhausted: this.isExhausted(),
|
|
74
|
+
completedFiles: [...this.completedFiles],
|
|
75
|
+
skippedFiles: [...this.skippedFiles],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a summary message for CLI output.
|
|
80
|
+
*/
|
|
81
|
+
getSummaryMessage() {
|
|
82
|
+
const report = this.getReport();
|
|
83
|
+
const lines = [
|
|
84
|
+
`Token budget: ${report.used.toLocaleString()} / ${report.totalBudget.toLocaleString()} (${report.percentUsed.toFixed(1)}%)`,
|
|
85
|
+
`Files processed: ${report.filesProcessed} / ${this.totalFiles}`,
|
|
86
|
+
];
|
|
87
|
+
if (report.skippedFiles.length > 0) {
|
|
88
|
+
lines.push(`Files skipped (budget): ${report.skippedFiles.length}`);
|
|
89
|
+
}
|
|
90
|
+
if (report.exhausted) {
|
|
91
|
+
lines.push('Budget exhausted - some files were not processed');
|
|
92
|
+
}
|
|
93
|
+
return lines.join('\n');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../../src/generation/budget/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAqB3C;;;GAGG;AACH,MAAM,OAAO,aAAa;IAChB,WAAW,CAAS;IACpB,IAAI,GAAW,CAAC,CAAC;IACjB,cAAc,GAAW,CAAC,CAAC;IAC3B,UAAU,CAAS;IACnB,cAAc,GAAa,EAAE,CAAC;IAC9B,YAAY,GAAa,EAAE,CAAC;IAEpC,YAAY,WAAmB,EAAE,UAAkB;QACjD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,eAAuB;QAChC,OAAO,IAAI,CAAC,SAAS,IAAI,eAAe,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,QAAgB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c,EAAE,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;YACxC,YAAY,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC;SACrC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG;YACZ,iBAAiB,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,MAAM,CAAC,WAAW,CAAC,cAAc,EAAE,KAAK,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;YAC5H,oBAAoB,MAAM,CAAC,cAAc,MAAM,IAAI,CAAC,UAAU,EAAE;SACjE,CAAC;QAEF,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,KAAK,CAAC,IAAI,CAAC,2BAA2B,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,KAAK,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics about codebase complexity.
|
|
3
|
+
*/
|
|
4
|
+
export interface ComplexityMetrics {
|
|
5
|
+
/** Total number of source files */
|
|
6
|
+
fileCount: number;
|
|
7
|
+
/** Maximum directory depth */
|
|
8
|
+
directoryDepth: number;
|
|
9
|
+
/** Detected architectural patterns */
|
|
10
|
+
architecturalPatterns: string[];
|
|
11
|
+
/** List of source file paths */
|
|
12
|
+
files: string[];
|
|
13
|
+
/** Unique directory paths */
|
|
14
|
+
directories: Set<string>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Analyze codebase complexity from discovered files.
|
|
18
|
+
*
|
|
19
|
+
* @param files - List of source file paths
|
|
20
|
+
* @param projectRoot - Project root directory
|
|
21
|
+
* @returns Complexity metrics
|
|
22
|
+
*/
|
|
23
|
+
export declare function analyzeComplexity(files: string[], projectRoot: string): ComplexityMetrics;
|
|
24
|
+
/**
|
|
25
|
+
* Determine if ARCHITECTURE.md should be generated.
|
|
26
|
+
*
|
|
27
|
+
* Triggers (any one fires):
|
|
28
|
+
* - 20+ source files
|
|
29
|
+
* - 3+ directory levels
|
|
30
|
+
* - Multiple architectural patterns detected
|
|
31
|
+
*/
|
|
32
|
+
export declare function shouldGenerateArchitecture(metrics: ComplexityMetrics): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Determine if STACK.md should be generated.
|
|
35
|
+
*
|
|
36
|
+
* Always generate if package.json exists (has dependencies to document).
|
|
37
|
+
*/
|
|
38
|
+
export declare function shouldGenerateStack(hasPackageJson: boolean): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a summary of why supplementary docs should/shouldn't be generated.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getComplexitySummary(metrics: ComplexityMetrics): string;
|
|
43
|
+
//# sourceMappingURL=complexity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complexity.d.ts","sourceRoot":"","sources":["../../src/generation/complexity.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,gCAAgC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,6BAA6B;IAC7B,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AA+GD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,MAAM,GAClB,iBAAiB,CAQnB;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAW9E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,OAAO,GAAG,OAAO,CAEpE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAcvE"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Architectural pattern definitions with detection heuristics.
|
|
4
|
+
*/
|
|
5
|
+
const PATTERN_DETECTORS = [
|
|
6
|
+
{
|
|
7
|
+
name: 'layered-architecture',
|
|
8
|
+
indicators: ['controllers/', 'services/', 'repositories/', 'dao/'],
|
|
9
|
+
minMatches: 2,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'clean-architecture',
|
|
13
|
+
indicators: ['domain/', 'application/', 'infrastructure/', 'usecases/'],
|
|
14
|
+
minMatches: 2,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'nextjs-convention',
|
|
18
|
+
indicators: ['/api/', '/pages/', '/app/', 'middleware.'],
|
|
19
|
+
minMatches: 2,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'presentational-container',
|
|
23
|
+
indicators: ['components/', 'containers/', 'views/'],
|
|
24
|
+
minMatches: 2,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'redux-pattern',
|
|
28
|
+
indicators: ['redux/', 'store/', 'slices/', 'reducers/', 'actions/'],
|
|
29
|
+
minMatches: 2,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'react-patterns',
|
|
33
|
+
indicators: ['hooks/', 'context/', 'providers/'],
|
|
34
|
+
minMatches: 2,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'microservices',
|
|
38
|
+
indicators: ['services/', 'gateway/', 'shared/', 'common/', 'packages/'],
|
|
39
|
+
minMatches: 3,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'feature-based',
|
|
43
|
+
indicators: ['features/', 'modules/', 'domains/'],
|
|
44
|
+
minMatches: 1,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'mvc-pattern',
|
|
48
|
+
indicators: ['models/', 'views/', 'controllers/'],
|
|
49
|
+
minMatches: 3,
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* Detect architectural patterns from file paths.
|
|
54
|
+
*/
|
|
55
|
+
function detectArchitecturalPatterns(files) {
|
|
56
|
+
const patterns = [];
|
|
57
|
+
const normalizedFiles = files.map(f => f.toLowerCase().replace(/\\/g, '/'));
|
|
58
|
+
for (const detector of PATTERN_DETECTORS) {
|
|
59
|
+
const matches = detector.indicators.filter(indicator => normalizedFiles.some(f => f.includes(indicator)));
|
|
60
|
+
if (matches.length >= detector.minMatches) {
|
|
61
|
+
patterns.push(detector.name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return patterns;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calculate maximum directory depth from file paths.
|
|
68
|
+
*/
|
|
69
|
+
function calculateDirectoryDepth(files, projectRoot) {
|
|
70
|
+
let maxDepth = 0;
|
|
71
|
+
for (const file of files) {
|
|
72
|
+
const relativePath = path.relative(projectRoot, file);
|
|
73
|
+
const depth = relativePath.split(path.sep).length - 1; // -1 for the file itself
|
|
74
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
75
|
+
}
|
|
76
|
+
return maxDepth;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract unique directories from file paths.
|
|
80
|
+
*/
|
|
81
|
+
function extractDirectories(files) {
|
|
82
|
+
const directories = new Set();
|
|
83
|
+
for (const file of files) {
|
|
84
|
+
let dir = path.dirname(file);
|
|
85
|
+
while (dir && dir !== '.') {
|
|
86
|
+
directories.add(dir);
|
|
87
|
+
const parent = path.dirname(dir);
|
|
88
|
+
if (parent === dir)
|
|
89
|
+
break; // Reached root
|
|
90
|
+
dir = parent;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return directories;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Analyze codebase complexity from discovered files.
|
|
97
|
+
*
|
|
98
|
+
* @param files - List of source file paths
|
|
99
|
+
* @param projectRoot - Project root directory
|
|
100
|
+
* @returns Complexity metrics
|
|
101
|
+
*/
|
|
102
|
+
export function analyzeComplexity(files, projectRoot) {
|
|
103
|
+
return {
|
|
104
|
+
fileCount: files.length,
|
|
105
|
+
directoryDepth: calculateDirectoryDepth(files, projectRoot),
|
|
106
|
+
architecturalPatterns: detectArchitecturalPatterns(files),
|
|
107
|
+
files,
|
|
108
|
+
directories: extractDirectories(files),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Determine if ARCHITECTURE.md should be generated.
|
|
113
|
+
*
|
|
114
|
+
* Triggers (any one fires):
|
|
115
|
+
* - 20+ source files
|
|
116
|
+
* - 3+ directory levels
|
|
117
|
+
* - Multiple architectural patterns detected
|
|
118
|
+
*/
|
|
119
|
+
export function shouldGenerateArchitecture(metrics) {
|
|
120
|
+
// Threshold: 20+ source files
|
|
121
|
+
if (metrics.fileCount >= 20)
|
|
122
|
+
return true;
|
|
123
|
+
// Threshold: 3+ directory levels
|
|
124
|
+
if (metrics.directoryDepth >= 3)
|
|
125
|
+
return true;
|
|
126
|
+
// Threshold: 2+ architectural patterns
|
|
127
|
+
if (metrics.architecturalPatterns.length >= 2)
|
|
128
|
+
return true;
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Determine if STACK.md should be generated.
|
|
133
|
+
*
|
|
134
|
+
* Always generate if package.json exists (has dependencies to document).
|
|
135
|
+
*/
|
|
136
|
+
export function shouldGenerateStack(hasPackageJson) {
|
|
137
|
+
return hasPackageJson;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Generate a summary of why supplementary docs should/shouldn't be generated.
|
|
141
|
+
*/
|
|
142
|
+
export function getComplexitySummary(metrics) {
|
|
143
|
+
const lines = [
|
|
144
|
+
`Files: ${metrics.fileCount}`,
|
|
145
|
+
`Directory depth: ${metrics.directoryDepth}`,
|
|
146
|
+
`Patterns detected: ${metrics.architecturalPatterns.length > 0 ? metrics.architecturalPatterns.join(', ') : 'none'}`,
|
|
147
|
+
];
|
|
148
|
+
if (shouldGenerateArchitecture(metrics)) {
|
|
149
|
+
lines.push('ARCHITECTURE.md: will be generated');
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
lines.push('ARCHITECTURE.md: not needed (below thresholds)');
|
|
153
|
+
}
|
|
154
|
+
return lines.join('\n');
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=complexity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complexity.js","sourceRoot":"","sources":["../../src/generation/complexity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAkBlC;;GAEG;AACH,MAAM,iBAAiB,GAIlB;IACH;QACE,IAAI,EAAE,sBAAsB;QAC5B,UAAU,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,CAAC;QAClE,UAAU,EAAE,CAAC;KACd;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,UAAU,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,CAAC;QACvE,UAAU,EAAE,CAAC;KACd;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,UAAU,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC;QACxD,UAAU,EAAE,CAAC;KACd;IACD;QACE,IAAI,EAAE,0BAA0B;QAChC,UAAU,EAAE,CAAC,aAAa,EAAE,aAAa,E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
1
|
+
/**
|
|
2
|
+
* File type detector
|
|
3
|
+
*
|
|
4
|
+
* Detects file type using a three-tier strategy:
|
|
5
|
+
* 1. File name patterns (tests, configs) - most specific
|
|
6
|
+
* 2. Parent directory name - fast path for standard structures
|
|
7
|
+
* 3. Content analysis - fallback for edge cases
|
|
8
|
+
*/
|
|
9
|
+
import type { FileType } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Detect file type using directory-first strategy with content fallback.
|
|
12
|
+
*
|
|
13
|
+
* Detection order:
|
|
14
|
+
* 1. File name patterns (tests, configs) - most specific
|
|
15
|
+
* 2. Parent directory name - fast path for standard structures
|
|
16
|
+
* 3. Content analysis - fallback for edge cases
|
|
17
|
+
*
|
|
18
|
+
* @param filePath - Path to the file (relative or absolute)
|
|
19
|
+
* @param content - File content for fallback detection
|
|
20
|
+
* @returns Detected FileType
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectFileType(filePath: string, content: string): FileType;
|
|
23
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../../src/generation/detection/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAsB5C;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CA0B1E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File type detector
|
|
3
|
+
*
|
|
4
|
+
* Detects file type using a three-tier strategy:
|
|
5
|
+
* 1. File name patterns (tests, configs) - most specific
|
|
6
|
+
* 2. Parent directory name - fast path for standard structures
|
|
7
|
+
* 3. Content analysis - fallback for edge cases
|
|
8
|
+
*/
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { DIRECTORY_PATTERNS, detectFromContent } from './patterns.js';
|
|
11
|
+
/**
|
|
12
|
+
* File name patterns that override directory detection
|
|
13
|
+
* These are checked first because they're the most specific indicators
|
|
14
|
+
*/
|
|
15
|
+
const TEST_FILE_PATTERNS = [
|
|
16
|
+
/\.test\.[jt]sx?$/,
|
|
17
|
+
/\.spec\.[jt]sx?$/,
|
|
18
|
+
/_test\.[jt]sx?$/,
|
|
19
|
+
];
|
|
20
|
+
const CONFIG_FILE_PATTERNS = [
|
|
21
|
+
/\.config\.[jt]s$/,
|
|
22
|
+
/\.config\.m?[jt]s$/,
|
|
23
|
+
/rc\.[jt]s$/,
|
|
24
|
+
/rc\.m?[jt]s$/,
|
|
25
|
+
/\.json$/,
|
|
26
|
+
/\.ya?ml$/,
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Detect file type using directory-first strategy with content fallback.
|
|
30
|
+
*
|
|
31
|
+
* Detection order:
|
|
32
|
+
* 1. File name patterns (tests, configs) - most specific
|
|
33
|
+
* 2. Parent directory name - fast path for standard structures
|
|
34
|
+
* 3. Content analysis - fallback for edge cases
|
|
35
|
+
*
|
|
36
|
+
* @param filePath - Path to the file (relative or absolute)
|
|
37
|
+
* @param content - File content for fallback detection
|
|
38
|
+
* @returns Detected FileType
|
|
39
|
+
*/
|
|
40
|
+
export function detectFileType(filePath, content) {
|
|
41
|
+
const fileName = path.basename(filePath);
|
|
42
|
+
// 1. File name patterns take precedence
|
|
43
|
+
if (TEST_FILE_PATTERNS.some((pattern) => pattern.test(fileName))) {
|
|
44
|
+
return 'test';
|
|
45
|
+
}
|
|
46
|
+
if (CONFIG_FILE_PATTERNS.some((pattern) => pattern.test(fileName))) {
|
|
47
|
+
return 'config';
|
|
48
|
+
}
|
|
49
|
+
// 2. Directory-based detection
|
|
50
|
+
const dirPath = path.dirname(filePath);
|
|
51
|
+
const pathParts = dirPath.split(path.sep);
|
|
52
|
+
// Check each directory level (inner to outer)
|
|
53
|
+
for (let i = pathParts.length - 1; i >= 0; i--) {
|
|
54
|
+
const dirName = pathParts[i].toLowerCase();
|
|
55
|
+
if (dirName && DIRECTORY_PATTERNS[dirName]) {
|
|
56
|
+
return DIRECTORY_PATTERNS[dirName];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// 3. Content-based fallback
|
|
60
|
+
return detectFromContent(content);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../src/generation/detection/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEtE;;;GAGG;AACH,MAAM,kBAAkB,GAAG;IACzB,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;CAClB,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,kBAAkB;IAClB,oBAAoB;IACpB,YAAY;IACZ,cAAc;IACd,SAAS;IACT,UAAU;CACX,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,OAAe;IAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEzC,wCAAwC;IACxC,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACnE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,+BAA+B;IAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE1C,8CAA8C;IAC9C,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,IAAI,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3C,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,4BAA4B;IAC5B,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File type detection patterns
|
|
3
|
+
*
|
|
4
|
+
* Directory-based patterns for fast detection, with content-based
|
|
5
|
+
* fallback for files in non-standard locations.
|
|
6
|
+
*/
|
|
7
|
+
import type { FileType } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Directory name -> FileType mapping (case-insensitive)
|
|
10
|
+
* Used for fast path detection when files are in standard directories
|
|
11
|
+
*/
|
|
12
|
+
export declare const DIRECTORY_PATTERNS: Record<string, FileType>;
|
|
13
|
+
/**
|
|
14
|
+
* Content-based detection patterns
|
|
15
|
+
* Used when directory doesn't match any known pattern
|
|
16
|
+
*
|
|
17
|
+
* @param content - File content to analyze
|
|
18
|
+
* @returns Detected file type or 'generic' if no pattern matches
|
|
19
|
+
*/
|
|
20
|
+
export declare function detectFromContent(content: string): FileType;
|
|
21
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../../src/generation/detection/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAqDvD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CA2E3D"}
|