exai 1.0.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 +117 -0
- package/dist/ai/config.d.ts +60 -0
- package/dist/ai/config.d.ts.map +1 -0
- package/dist/ai/config.js +217 -0
- package/dist/ai/config.js.map +1 -0
- package/dist/ai/contants.d.ts +4 -0
- package/dist/ai/contants.d.ts.map +1 -0
- package/dist/ai/contants.js +4 -0
- package/dist/ai/contants.js.map +1 -0
- package/dist/ai/context-gatherer.d.ts +39 -0
- package/dist/ai/context-gatherer.d.ts.map +1 -0
- package/dist/ai/context-gatherer.js +107 -0
- package/dist/ai/context-gatherer.js.map +1 -0
- package/dist/ai/folder-filter.d.ts +17 -0
- package/dist/ai/folder-filter.d.ts.map +1 -0
- package/dist/ai/folder-filter.js +76 -0
- package/dist/ai/folder-filter.js.map +1 -0
- package/dist/ai/openrouter.d.ts +42 -0
- package/dist/ai/openrouter.d.ts.map +1 -0
- package/dist/ai/openrouter.js +224 -0
- package/dist/ai/openrouter.js.map +1 -0
- package/dist/ai/query-cache.d.ts +49 -0
- package/dist/ai/query-cache.d.ts.map +1 -0
- package/dist/ai/query-cache.js +274 -0
- package/dist/ai/query-cache.js.map +1 -0
- package/dist/ai/tree-generator.d.ts +21 -0
- package/dist/ai/tree-generator.d.ts.map +1 -0
- package/dist/ai/tree-generator.js +141 -0
- package/dist/ai/tree-generator.js.map +1 -0
- package/dist/cli.d.ts +24 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +548 -0
- package/dist/cli.js.map +1 -0
- package/dist/context/compat.d.ts +8 -0
- package/dist/context/compat.d.ts.map +1 -0
- package/dist/context/compat.js +8 -0
- package/dist/context/compat.js.map +1 -0
- package/dist/context/compress.d.ts +27 -0
- package/dist/context/compress.d.ts.map +1 -0
- package/dist/context/compress.js +162 -0
- package/dist/context/compress.js.map +1 -0
- package/dist/context/filter.d.ts +25 -0
- package/dist/context/filter.d.ts.map +1 -0
- package/dist/context/filter.js +175 -0
- package/dist/context/filter.js.map +1 -0
- package/dist/context/gather.d.ts +97 -0
- package/dist/context/gather.d.ts.map +1 -0
- package/dist/context/gather.js +155 -0
- package/dist/context/gather.js.map +1 -0
- package/dist/context/index.d.ts +10 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +10 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/reader.d.ts +49 -0
- package/dist/context/reader.d.ts.map +1 -0
- package/dist/context/reader.js +148 -0
- package/dist/context/reader.js.map +1 -0
- package/dist/context/tree.d.ts +22 -0
- package/dist/context/tree.d.ts.map +1 -0
- package/dist/context/tree.js +72 -0
- package/dist/context/tree.js.map +1 -0
- package/dist/factory/connection-factory.d.ts +16 -0
- package/dist/factory/connection-factory.d.ts.map +1 -0
- package/dist/factory/connection-factory.js +91 -0
- package/dist/factory/connection-factory.js.map +1 -0
- package/dist/factory/element-factory.d.ts +16 -0
- package/dist/factory/element-factory.d.ts.map +1 -0
- package/dist/factory/element-factory.js +78 -0
- package/dist/factory/element-factory.js.map +1 -0
- package/dist/factory/image-factory.d.ts +38 -0
- package/dist/factory/image-factory.d.ts.map +1 -0
- package/dist/factory/image-factory.js +169 -0
- package/dist/factory/image-factory.js.map +1 -0
- package/dist/factory/index.d.ts +9 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory/index.js +9 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/factory/node-factory.d.ts +24 -0
- package/dist/factory/node-factory.d.ts.map +1 -0
- package/dist/factory/node-factory.js +85 -0
- package/dist/factory/node-factory.js.map +1 -0
- package/dist/factory/text-factory.d.ts +42 -0
- package/dist/factory/text-factory.d.ts.map +1 -0
- package/dist/factory/text-factory.js +148 -0
- package/dist/factory/text-factory.js.map +1 -0
- package/dist/generator/excalidraw-generator.d.ts +17 -0
- package/dist/generator/excalidraw-generator.d.ts.map +1 -0
- package/dist/generator/excalidraw-generator.js +189 -0
- package/dist/generator/excalidraw-generator.js.map +1 -0
- package/dist/generator/index.d.ts +5 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +5 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/arrow-router.d.ts +48 -0
- package/dist/layout/arrow-router.d.ts.map +1 -0
- package/dist/layout/arrow-router.js +103 -0
- package/dist/layout/arrow-router.js.map +1 -0
- package/dist/layout/elk-layout.d.ts +11 -0
- package/dist/layout/elk-layout.d.ts.map +1 -0
- package/dist/layout/elk-layout.js +295 -0
- package/dist/layout/elk-layout.js.map +1 -0
- package/dist/layout/index.d.ts +6 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +6 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/parser/dot-parser.d.ts +23 -0
- package/dist/parser/dot-parser.d.ts.map +1 -0
- package/dist/parser/dot-parser.js +277 -0
- package/dist/parser/dot-parser.js.map +1 -0
- package/dist/parser/dsl-parser.d.ts +31 -0
- package/dist/parser/dsl-parser.d.ts.map +1 -0
- package/dist/parser/dsl-parser.js +455 -0
- package/dist/parser/dsl-parser.js.map +1 -0
- package/dist/parser/index.d.ts +7 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +7 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/json-parser.d.ts +16 -0
- package/dist/parser/json-parser.d.ts.map +1 -0
- package/dist/parser/json-parser.js +76 -0
- package/dist/parser/json-parser.js.map +1 -0
- package/dist/types/dsl.d.ts +194 -0
- package/dist/types/dsl.d.ts.map +1 -0
- package/dist/types/dsl.js +14 -0
- package/dist/types/dsl.js.map +1 -0
- package/dist/types/excalidraw.d.ts +190 -0
- package/dist/types/excalidraw.d.ts.map +1 -0
- package/dist/types/excalidraw.js +36 -0
- package/dist/types/excalidraw.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# exai
|
|
2
|
+
|
|
3
|
+
CLI that turns natural language into Excalidraw flowcharts. Point it at your codebase, describe what you want, get a `.excalidraw` file.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
exai ai "visualize the auth flow" -c ./src -o auth.excalidraw
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i -g exai
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or from source:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/KailasMahavarkar/exai.git
|
|
19
|
+
cd exai
|
|
20
|
+
npm install && npm run bundle
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
Get an API key from [openrouter.ai/keys](https://openrouter.ai/keys), then either:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
export OPENROUTER_API_KEY="sk-or-v1-..."
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or use a config file:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
exai init # creates exai.config.json
|
|
35
|
+
# add your apiKey, then:
|
|
36
|
+
exai ai "prompt" --config-path ./exai.config.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Config
|
|
40
|
+
|
|
41
|
+
One file controls everything. Generate it with `exai init`.
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"model": "moonshotai/kimi-k2.5",
|
|
46
|
+
"filterModel": "moonshotai/kimi-k2.5",
|
|
47
|
+
"apiKey": "sk-or-v1-...",
|
|
48
|
+
"temperature": 0,
|
|
49
|
+
|
|
50
|
+
"format": "dsl",
|
|
51
|
+
"output": "flowchart.excalidraw",
|
|
52
|
+
"direction": "TB",
|
|
53
|
+
"spacing": 50,
|
|
54
|
+
|
|
55
|
+
"context": ["./src"],
|
|
56
|
+
"exclude": ["dist", "coverage", "*.lock"],
|
|
57
|
+
"allowTestFiles": false,
|
|
58
|
+
"maxFileSize": 65536,
|
|
59
|
+
"maxDepth": 6,
|
|
60
|
+
"maxTreeItems": 1000,
|
|
61
|
+
|
|
62
|
+
"compress": true,
|
|
63
|
+
"compressMode": "balanced",
|
|
64
|
+
"compressOptions": {
|
|
65
|
+
"removeComments": true,
|
|
66
|
+
"minifyWhitespace": true,
|
|
67
|
+
"extractSignaturesOnly": false,
|
|
68
|
+
"maxFileLines": 100,
|
|
69
|
+
"preserveImports": true,
|
|
70
|
+
"preserveExports": true,
|
|
71
|
+
"preserveTypes": true,
|
|
72
|
+
"preserveFunctionSignatures": true
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
"cache": true,
|
|
76
|
+
"cacheTtlDays": 7,
|
|
77
|
+
"cacheMaxEntries": 100,
|
|
78
|
+
|
|
79
|
+
"verbose": false
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
All fields optional. CLI flags override config values.
|
|
84
|
+
|
|
85
|
+
## Commands
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# AI generation
|
|
89
|
+
exai ai "<prompt>" [options]
|
|
90
|
+
|
|
91
|
+
# Create from DSL/JSON/DOT
|
|
92
|
+
exai create [input] [options]
|
|
93
|
+
|
|
94
|
+
# Parse without generating
|
|
95
|
+
exai parse <input>
|
|
96
|
+
|
|
97
|
+
# Cache management
|
|
98
|
+
exai cache stats
|
|
99
|
+
exai cache clear
|
|
100
|
+
|
|
101
|
+
# Generate starter config
|
|
102
|
+
exai init [path]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## DSL Syntax
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
(Start) -> [Process] -> {Decision?}
|
|
109
|
+
{Decision?} -> "yes" -> [[Save to DB]] -> (End)
|
|
110
|
+
{Decision?} -> "no" -> [Retry] -> (Start)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`[rect]` `{diamond}` `(ellipse)` `[[database]]` `->` `-->` `-> "label" ->`
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Config File Support
|
|
3
|
+
*
|
|
4
|
+
* One config file to control the entire pipeline:
|
|
5
|
+
* - AI/LLM settings (model, filterModel, apiKey, temperature)
|
|
6
|
+
* - Output settings (format, output, direction, spacing)
|
|
7
|
+
* - Context gathering (context paths, exclude, allowTestFiles, maxFileSize, maxDepth, maxTreeItems)
|
|
8
|
+
* - Compression (compress, compressMode, compressOptions)
|
|
9
|
+
* - Cache (cache, cacheTtlDays, cacheMaxEntries)
|
|
10
|
+
* - Misc (verbose)
|
|
11
|
+
*
|
|
12
|
+
* All fields optional. Priority: CLI flags > config file > env vars > hardcoded defaults.
|
|
13
|
+
*/
|
|
14
|
+
export interface ConfigCompressOptions {
|
|
15
|
+
removeComments?: boolean;
|
|
16
|
+
minifyWhitespace?: boolean;
|
|
17
|
+
extractSignaturesOnly?: boolean;
|
|
18
|
+
maxFileLines?: number;
|
|
19
|
+
preserveImports?: boolean;
|
|
20
|
+
preserveExports?: boolean;
|
|
21
|
+
preserveTypes?: boolean;
|
|
22
|
+
preserveFunctionSignatures?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface CliConfig {
|
|
25
|
+
model?: string;
|
|
26
|
+
filterModel?: string;
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
temperature?: number;
|
|
29
|
+
format?: string;
|
|
30
|
+
output?: string;
|
|
31
|
+
direction?: string;
|
|
32
|
+
spacing?: number;
|
|
33
|
+
context?: string[];
|
|
34
|
+
exclude?: string[];
|
|
35
|
+
allowTestFiles?: boolean;
|
|
36
|
+
maxFileSize?: number;
|
|
37
|
+
maxDepth?: number;
|
|
38
|
+
maxTreeItems?: number;
|
|
39
|
+
compress?: boolean;
|
|
40
|
+
compressMode?: string;
|
|
41
|
+
compressOptions?: ConfigCompressOptions;
|
|
42
|
+
cache?: boolean;
|
|
43
|
+
cacheTtlDays?: number;
|
|
44
|
+
cacheMaxEntries?: number;
|
|
45
|
+
verbose?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load and validate a CLI config file.
|
|
49
|
+
*
|
|
50
|
+
* - Resolves configPath relative to CWD
|
|
51
|
+
* - Resolves `context` paths relative to the config file's directory
|
|
52
|
+
* - Throws on missing file or invalid JSON
|
|
53
|
+
*/
|
|
54
|
+
export declare function loadConfig(configPath: string): CliConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Default config template for `init` command.
|
|
57
|
+
* Shows every available option with sensible defaults.
|
|
58
|
+
*/
|
|
59
|
+
export declare const CONFIG_TEMPLATE: CliConfig;
|
|
60
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/ai/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC;AAID,MAAM,WAAW,SAAS;IAExB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,qBAAqB,CAAC;IAGxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA0ED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAyExD;AAID;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,SAyC7B,CAAC"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Config File Support
|
|
3
|
+
*
|
|
4
|
+
* One config file to control the entire pipeline:
|
|
5
|
+
* - AI/LLM settings (model, filterModel, apiKey, temperature)
|
|
6
|
+
* - Output settings (format, output, direction, spacing)
|
|
7
|
+
* - Context gathering (context paths, exclude, allowTestFiles, maxFileSize, maxDepth, maxTreeItems)
|
|
8
|
+
* - Compression (compress, compressMode, compressOptions)
|
|
9
|
+
* - Cache (cache, cacheTtlDays, cacheMaxEntries)
|
|
10
|
+
* - Misc (verbose)
|
|
11
|
+
*
|
|
12
|
+
* All fields optional. Priority: CLI flags > config file > env vars > hardcoded defaults.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync, existsSync } from 'fs';
|
|
15
|
+
import { resolve, dirname } from 'path';
|
|
16
|
+
// ── Validation helpers ──────────────────────────────────────────────────────
|
|
17
|
+
const KNOWN_KEYS = new Set([
|
|
18
|
+
// AI / LLM
|
|
19
|
+
'model', 'filterModel', 'apiKey', 'temperature',
|
|
20
|
+
// Output
|
|
21
|
+
'format', 'output', 'direction', 'spacing',
|
|
22
|
+
// Context
|
|
23
|
+
'context', 'exclude', 'allowTestFiles', 'maxFileSize', 'maxDepth', 'maxTreeItems',
|
|
24
|
+
// Compression
|
|
25
|
+
'compress', 'compressMode', 'compressOptions',
|
|
26
|
+
// Cache
|
|
27
|
+
'cache', 'cacheTtlDays', 'cacheMaxEntries',
|
|
28
|
+
// Misc
|
|
29
|
+
'verbose',
|
|
30
|
+
]);
|
|
31
|
+
const COMPRESS_OPTION_KEYS = new Set([
|
|
32
|
+
'removeComments', 'minifyWhitespace', 'extractSignaturesOnly', 'maxFileLines',
|
|
33
|
+
'preserveImports', 'preserveExports', 'preserveTypes', 'preserveFunctionSignatures',
|
|
34
|
+
]);
|
|
35
|
+
function assertString(obj, key) {
|
|
36
|
+
if (typeof obj[key] !== 'string')
|
|
37
|
+
throw new Error(`Config "${key}" must be a string`);
|
|
38
|
+
return obj[key];
|
|
39
|
+
}
|
|
40
|
+
function assertNumber(obj, key) {
|
|
41
|
+
if (typeof obj[key] !== 'number')
|
|
42
|
+
throw new Error(`Config "${key}" must be a number`);
|
|
43
|
+
return obj[key];
|
|
44
|
+
}
|
|
45
|
+
function assertBoolean(obj, key) {
|
|
46
|
+
if (typeof obj[key] !== 'boolean')
|
|
47
|
+
throw new Error(`Config "${key}" must be a boolean`);
|
|
48
|
+
return obj[key];
|
|
49
|
+
}
|
|
50
|
+
function assertStringArray(obj, key) {
|
|
51
|
+
const val = obj[key];
|
|
52
|
+
if (!Array.isArray(val) || !val.every(v => typeof v === 'string')) {
|
|
53
|
+
throw new Error(`Config "${key}" must be an array of strings`);
|
|
54
|
+
}
|
|
55
|
+
return val;
|
|
56
|
+
}
|
|
57
|
+
function parseCompressOptions(obj) {
|
|
58
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
59
|
+
throw new Error('Config "compressOptions" must be an object');
|
|
60
|
+
}
|
|
61
|
+
const raw = obj;
|
|
62
|
+
const unknowns = Object.keys(raw).filter(k => !COMPRESS_OPTION_KEYS.has(k));
|
|
63
|
+
if (unknowns.length > 0) {
|
|
64
|
+
console.warn(`Warning: Unknown compressOptions keys ignored: ${unknowns.join(', ')}`);
|
|
65
|
+
}
|
|
66
|
+
const result = {};
|
|
67
|
+
if (raw.removeComments !== undefined)
|
|
68
|
+
result.removeComments = assertBoolean(raw, 'removeComments');
|
|
69
|
+
if (raw.minifyWhitespace !== undefined)
|
|
70
|
+
result.minifyWhitespace = assertBoolean(raw, 'minifyWhitespace');
|
|
71
|
+
if (raw.extractSignaturesOnly !== undefined)
|
|
72
|
+
result.extractSignaturesOnly = assertBoolean(raw, 'extractSignaturesOnly');
|
|
73
|
+
if (raw.maxFileLines !== undefined)
|
|
74
|
+
result.maxFileLines = assertNumber(raw, 'maxFileLines');
|
|
75
|
+
if (raw.preserveImports !== undefined)
|
|
76
|
+
result.preserveImports = assertBoolean(raw, 'preserveImports');
|
|
77
|
+
if (raw.preserveExports !== undefined)
|
|
78
|
+
result.preserveExports = assertBoolean(raw, 'preserveExports');
|
|
79
|
+
if (raw.preserveTypes !== undefined)
|
|
80
|
+
result.preserveTypes = assertBoolean(raw, 'preserveTypes');
|
|
81
|
+
if (raw.preserveFunctionSignatures !== undefined)
|
|
82
|
+
result.preserveFunctionSignatures = assertBoolean(raw, 'preserveFunctionSignatures');
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
// ── Main loader ─────────────────────────────────────────────────────────────
|
|
86
|
+
/**
|
|
87
|
+
* Load and validate a CLI config file.
|
|
88
|
+
*
|
|
89
|
+
* - Resolves configPath relative to CWD
|
|
90
|
+
* - Resolves `context` paths relative to the config file's directory
|
|
91
|
+
* - Throws on missing file or invalid JSON
|
|
92
|
+
*/
|
|
93
|
+
export function loadConfig(configPath) {
|
|
94
|
+
const absolutePath = resolve(configPath);
|
|
95
|
+
if (!existsSync(absolutePath)) {
|
|
96
|
+
throw new Error(`Config file not found: ${absolutePath}`);
|
|
97
|
+
}
|
|
98
|
+
let raw;
|
|
99
|
+
try {
|
|
100
|
+
raw = readFileSync(absolutePath, 'utf-8');
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
throw new Error(`Failed to read config file: ${absolutePath}`);
|
|
104
|
+
}
|
|
105
|
+
let parsed;
|
|
106
|
+
try {
|
|
107
|
+
parsed = JSON.parse(raw);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
throw new Error(`Invalid JSON in config file: ${absolutePath}`);
|
|
111
|
+
}
|
|
112
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
113
|
+
throw new Error(`Config file must contain a JSON object: ${absolutePath}`);
|
|
114
|
+
}
|
|
115
|
+
const obj = parsed;
|
|
116
|
+
// Warn about unknown keys
|
|
117
|
+
const unknownKeys = Object.keys(obj).filter(k => !KNOWN_KEYS.has(k));
|
|
118
|
+
if (unknownKeys.length > 0) {
|
|
119
|
+
console.warn(`Warning: Unknown config keys ignored: ${unknownKeys.join(', ')}`);
|
|
120
|
+
}
|
|
121
|
+
const config = {};
|
|
122
|
+
const configDir = dirname(absolutePath);
|
|
123
|
+
// AI / LLM
|
|
124
|
+
if (obj.model !== undefined)
|
|
125
|
+
config.model = assertString(obj, 'model');
|
|
126
|
+
if (obj.filterModel !== undefined)
|
|
127
|
+
config.filterModel = assertString(obj, 'filterModel');
|
|
128
|
+
if (obj.apiKey !== undefined)
|
|
129
|
+
config.apiKey = assertString(obj, 'apiKey');
|
|
130
|
+
if (obj.temperature !== undefined)
|
|
131
|
+
config.temperature = assertNumber(obj, 'temperature');
|
|
132
|
+
// Output
|
|
133
|
+
if (obj.format !== undefined)
|
|
134
|
+
config.format = assertString(obj, 'format');
|
|
135
|
+
if (obj.output !== undefined)
|
|
136
|
+
config.output = assertString(obj, 'output');
|
|
137
|
+
if (obj.direction !== undefined)
|
|
138
|
+
config.direction = assertString(obj, 'direction');
|
|
139
|
+
if (obj.spacing !== undefined)
|
|
140
|
+
config.spacing = assertNumber(obj, 'spacing');
|
|
141
|
+
// Context gathering
|
|
142
|
+
if (obj.context !== undefined) {
|
|
143
|
+
const paths = assertStringArray(obj, 'context');
|
|
144
|
+
config.context = paths.map((p) => resolve(configDir, p));
|
|
145
|
+
}
|
|
146
|
+
if (obj.exclude !== undefined)
|
|
147
|
+
config.exclude = assertStringArray(obj, 'exclude');
|
|
148
|
+
if (obj.allowTestFiles !== undefined)
|
|
149
|
+
config.allowTestFiles = assertBoolean(obj, 'allowTestFiles');
|
|
150
|
+
if (obj.maxFileSize !== undefined)
|
|
151
|
+
config.maxFileSize = assertNumber(obj, 'maxFileSize');
|
|
152
|
+
if (obj.maxDepth !== undefined)
|
|
153
|
+
config.maxDepth = assertNumber(obj, 'maxDepth');
|
|
154
|
+
if (obj.maxTreeItems !== undefined)
|
|
155
|
+
config.maxTreeItems = assertNumber(obj, 'maxTreeItems');
|
|
156
|
+
// Compression
|
|
157
|
+
if (obj.compress !== undefined)
|
|
158
|
+
config.compress = assertBoolean(obj, 'compress');
|
|
159
|
+
if (obj.compressMode !== undefined)
|
|
160
|
+
config.compressMode = assertString(obj, 'compressMode');
|
|
161
|
+
if (obj.compressOptions !== undefined)
|
|
162
|
+
config.compressOptions = parseCompressOptions(obj.compressOptions);
|
|
163
|
+
// Cache
|
|
164
|
+
if (obj.cache !== undefined)
|
|
165
|
+
config.cache = assertBoolean(obj, 'cache');
|
|
166
|
+
if (obj.cacheTtlDays !== undefined)
|
|
167
|
+
config.cacheTtlDays = assertNumber(obj, 'cacheTtlDays');
|
|
168
|
+
if (obj.cacheMaxEntries !== undefined)
|
|
169
|
+
config.cacheMaxEntries = assertNumber(obj, 'cacheMaxEntries');
|
|
170
|
+
// Misc
|
|
171
|
+
if (obj.verbose !== undefined)
|
|
172
|
+
config.verbose = assertBoolean(obj, 'verbose');
|
|
173
|
+
return config;
|
|
174
|
+
}
|
|
175
|
+
// ── Default template ────────────────────────────────────────────────────────
|
|
176
|
+
/**
|
|
177
|
+
* Default config template for `init` command.
|
|
178
|
+
* Shows every available option with sensible defaults.
|
|
179
|
+
*/
|
|
180
|
+
export const CONFIG_TEMPLATE = {
|
|
181
|
+
// AI / LLM
|
|
182
|
+
model: 'moonshotai/kimi-k2.5',
|
|
183
|
+
filterModel: 'moonshotai/kimi-k2.5',
|
|
184
|
+
temperature: 0,
|
|
185
|
+
// Output
|
|
186
|
+
format: 'dsl',
|
|
187
|
+
output: 'flowchart.excalidraw',
|
|
188
|
+
direction: 'TB',
|
|
189
|
+
spacing: 50,
|
|
190
|
+
// Context gathering
|
|
191
|
+
context: ['./src'],
|
|
192
|
+
exclude: ['dist', 'coverage', '*.lock'],
|
|
193
|
+
allowTestFiles: false,
|
|
194
|
+
maxFileSize: 65536,
|
|
195
|
+
maxDepth: 6,
|
|
196
|
+
maxTreeItems: 1000,
|
|
197
|
+
// Compression
|
|
198
|
+
compress: true,
|
|
199
|
+
compressMode: 'balanced',
|
|
200
|
+
compressOptions: {
|
|
201
|
+
removeComments: true,
|
|
202
|
+
minifyWhitespace: true,
|
|
203
|
+
extractSignaturesOnly: false,
|
|
204
|
+
maxFileLines: 100,
|
|
205
|
+
preserveImports: true,
|
|
206
|
+
preserveExports: true,
|
|
207
|
+
preserveTypes: true,
|
|
208
|
+
preserveFunctionSignatures: true,
|
|
209
|
+
},
|
|
210
|
+
// Cache
|
|
211
|
+
cache: true,
|
|
212
|
+
cacheTtlDays: 7,
|
|
213
|
+
cacheMaxEntries: 100,
|
|
214
|
+
// Misc
|
|
215
|
+
verbose: false,
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/ai/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAoDxC,+EAA+E;AAE/E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS;IACjC,WAAW;IACX,OAAO,EA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OAAO,EAAE,CAAC,OAAO,CAAC;IAClB,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC;IACvC,cAAc,EAAE,KAAK;IACrB,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,CAAC;IACX,YAAY,EAAE,IAAI;IAElB,cAAc;IACd,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,UAAU;IACxB,eAAe,EAAE;QACf,cAAc,EAAE,IAAI;QACpB,gBAAgB,EAAE,IAAI;QACtB,qBAAqB,EAAE,KAAK;QAC5B,YAAY,EAAE,GAAG;QACjB,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,IAAI;QACnB,0BAA0B,EAAE,IAAI;KACjC;IAED,QAAQ;IACR,KAAK,EAAE,IAAI;IACX,YAAY,EAAE,CAAC;IACf,eAAe,EAAE,GAAG;IAEpB,OAAO;IACP,OAAO,EAAE,KAAK;CACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contants.d.ts","sourceRoot":"","sources":["../../src/ai/contants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,kDAAkD,CAAC;AAClF,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,mBAAmB,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contants.js","sourceRoot":"","sources":["../../src/ai/contants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,+CAA+C,CAAC;AAClF,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAC;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Gatherer - Thin CLI adapter over the context module.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Wraps the context module with OpenRouter-based AI filtering (folder-filter.ts)
|
|
6
|
+
* - Caches full pipeline results keyed on paths + options
|
|
7
|
+
* - Forwards all options to the context module
|
|
8
|
+
*/
|
|
9
|
+
import type { GatherResult as ModuleGatherResult, CompressOptions } from '../context/index.js';
|
|
10
|
+
export interface ContextOptions {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
/** Model for AI folder filtering (separate from generation model) */
|
|
13
|
+
filterModel?: string;
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
compress?: boolean;
|
|
16
|
+
compressOptions?: CompressOptions;
|
|
17
|
+
useCache?: boolean;
|
|
18
|
+
excludePatterns?: string[];
|
|
19
|
+
allowTestFiles?: boolean;
|
|
20
|
+
maxFileSize?: number;
|
|
21
|
+
/** Max tree depth (default: 6) */
|
|
22
|
+
maxDepth?: number;
|
|
23
|
+
/** Max tree items before truncation (default: 1000) */
|
|
24
|
+
maxTreeItems?: number;
|
|
25
|
+
/** Cache TTL in days (default: 7) */
|
|
26
|
+
cacheTtlDays?: number;
|
|
27
|
+
/** Max cache entries (default: 100) */
|
|
28
|
+
cacheMaxEntries?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ContextResult extends ModuleGatherResult {
|
|
31
|
+
fromCache: boolean;
|
|
32
|
+
cacheKey: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Gather context using the full pipeline:
|
|
36
|
+
* validate → pre-filter → tree → AI filter → read → compress → markdown
|
|
37
|
+
*/
|
|
38
|
+
export declare function gatherContext(paths: string[], options?: ContextOptions): Promise<ContextResult>;
|
|
39
|
+
//# sourceMappingURL=context-gatherer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-gatherer.d.ts","sourceRoot":"","sources":["../../src/ai/context-gatherer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,YAAY,IAAI,kBAAkB,EAAE,eAAe,EAAc,MAAM,qBAAqB,CAAC;AAO3G,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,aAAc,SAAQ,kBAAkB;IACvD,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAyDD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAsDxB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Gatherer - Thin CLI adapter over the context module.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Wraps the context module with OpenRouter-based AI filtering (folder-filter.ts)
|
|
6
|
+
* - Caches full pipeline results keyed on paths + options
|
|
7
|
+
* - Forwards all options to the context module
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
10
|
+
import { createHash } from 'crypto';
|
|
11
|
+
import { tmpdir } from 'os';
|
|
12
|
+
import { validatePaths, gatherContext as gatherContextModule } from '../context/index.js';
|
|
13
|
+
import { filterFolders } from './folder-filter.js';
|
|
14
|
+
const CACHE_DIR = `${tmpdir()}/exai-cache`;
|
|
15
|
+
// ── Cache helpers ─────────────────────────────────────────────────────────────
|
|
16
|
+
function generateCacheKey(paths, options) {
|
|
17
|
+
const keyParts = [
|
|
18
|
+
[...paths].sort().join('|'),
|
|
19
|
+
options.compress ?? true,
|
|
20
|
+
options.allowTestFiles ?? false,
|
|
21
|
+
options.maxFileSize ?? 0,
|
|
22
|
+
options.maxDepth ?? 0,
|
|
23
|
+
options.maxTreeItems ?? 0,
|
|
24
|
+
(options.excludePatterns ?? []).sort().join(','),
|
|
25
|
+
JSON.stringify(options.compressOptions ?? {}),
|
|
26
|
+
];
|
|
27
|
+
return createHash('sha256').update(keyParts.join(':::')).digest('hex') + '_ctx.cache';
|
|
28
|
+
}
|
|
29
|
+
function getCached(cacheKey, verbose) {
|
|
30
|
+
try {
|
|
31
|
+
const cachePath = `${CACHE_DIR}/${cacheKey}`;
|
|
32
|
+
if (existsSync(cachePath)) {
|
|
33
|
+
if (verbose)
|
|
34
|
+
console.log(` Context cache hit: ${cacheKey}`);
|
|
35
|
+
return JSON.parse(readFileSync(cachePath, 'utf-8'));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (verbose)
|
|
40
|
+
console.log(` Context cache read error: ${error}`);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
function writeCache(cacheKey, result, verbose) {
|
|
45
|
+
try {
|
|
46
|
+
if (!existsSync(CACHE_DIR))
|
|
47
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
48
|
+
writeFileSync(`${CACHE_DIR}/${cacheKey}`, JSON.stringify(result), 'utf-8');
|
|
49
|
+
if (verbose)
|
|
50
|
+
console.log(` Context cached: ${CACHE_DIR}/${cacheKey}`);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (verbose)
|
|
54
|
+
console.log(` Context cache write error: ${error}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// ── AI filter factory ─────────────────────────────────────────────────────────
|
|
58
|
+
function createAiFilter(apiKey, verbose = false, useCache = true, filterModel) {
|
|
59
|
+
return async (tree) => {
|
|
60
|
+
const result = await filterFolders(tree, apiKey, filterModel, verbose, useCache);
|
|
61
|
+
return result.excludePatterns;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ── Main entry point ──────────────────────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* Gather context using the full pipeline:
|
|
67
|
+
* validate → pre-filter → tree → AI filter → read → compress → markdown
|
|
68
|
+
*/
|
|
69
|
+
export async function gatherContext(paths, options = {}) {
|
|
70
|
+
const { apiKey, filterModel, verbose = false, compress = true, compressOptions, useCache = true, excludePatterns = [], allowTestFiles = false, maxFileSize, maxDepth, maxTreeItems, } = options;
|
|
71
|
+
if (verbose) {
|
|
72
|
+
console.log(` Received ${paths.length} context path(s) to analyze:`);
|
|
73
|
+
paths.forEach(p => console.log(` - ${p}`));
|
|
74
|
+
}
|
|
75
|
+
// Validate paths (delegates to context module)
|
|
76
|
+
const validatedPaths = validatePaths(paths);
|
|
77
|
+
// Check cache (key includes all options that affect output)
|
|
78
|
+
const cacheKey = generateCacheKey(validatedPaths, options);
|
|
79
|
+
if (useCache) {
|
|
80
|
+
const cached = getCached(cacheKey, verbose);
|
|
81
|
+
if (cached) {
|
|
82
|
+
if (verbose)
|
|
83
|
+
console.log(` Using cached context (${(cached.markdown.length / 1024).toFixed(1)}KB)`);
|
|
84
|
+
return { ...cached, fromCache: true, cacheKey };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Run full pipeline via context module
|
|
88
|
+
const result = await gatherContextModule(validatedPaths, {
|
|
89
|
+
excludePatterns,
|
|
90
|
+
aiFilter: createAiFilter(apiKey, verbose, useCache, filterModel),
|
|
91
|
+
compress,
|
|
92
|
+
compressOptions,
|
|
93
|
+
allowTestFiles,
|
|
94
|
+
maxFileSize,
|
|
95
|
+
verbose,
|
|
96
|
+
treeOptions: {
|
|
97
|
+
maxDepth,
|
|
98
|
+
maxItems: maxTreeItems,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
// Cache the full result
|
|
102
|
+
if (useCache) {
|
|
103
|
+
writeCache(cacheKey, result, verbose);
|
|
104
|
+
}
|
|
105
|
+
return { ...result, fromCache: false, cacheKey };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=context-gatherer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-gatherer.js","sourceRoot":"","sources":["../../src/ai/context-gatherer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,aAAa,IAAI,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,SAAS,GAAG,GAAG,MAAM,EAAE,aAAa,CAAC;AA8B3C,iFAAiF;AAEjF,SAAS,gBAAgB,CAAC,KAAe,EAAE,OAAuB;IAChE,MAAM,QAAQ,GAAG;QACf,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3B,OAAO,CAAC,QAAQ,IAAI,IAAI;QACxB,OAAO,CAAC,cAAc,IAAI,KAAK;QAC/B,OAAO,CAAC,WAAW,IAAI,CAAC;QACxB,OAAO,CAAC,QAAQ,IAAI,CAAC;QACrB,OAAO,CAAC,YAAY,IAAI,CAAC;QACzB,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,C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,EAAE,CAAC;YACX,IAAI,OAAO;gBAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACrG,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAClD,CAAC;IACH,CAAC;IAED,uCAAuC;IACvC,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,cAAc,EAAE;QACvD,eAAe;QACf,QAAQ,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC;QAChE,QAAQ;QACR,eAAe;QACf,cAAc;QACd,WAAW;QACX,OAAO;QACP,WAAW,EAAE;YACX,QAAQ;YACR,QAAQ,EAAE,YAAY;SACvB;KACF,CAAC,CAAC;IAEH,wBAAwB;IACxB,IAAI,QAAQ,EAAE,CAAC;QACb,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folder Filter - Uses lightweight AI to intelligently exclude folders from context
|
|
3
|
+
*
|
|
4
|
+
* Uses callLLM() from openrouter.ts as the base API call.
|
|
5
|
+
*/
|
|
6
|
+
interface FilterResult {
|
|
7
|
+
excludePatterns: string[];
|
|
8
|
+
analysisTime: number;
|
|
9
|
+
fromCache?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ask AI model to filter folders from a tree structure.
|
|
13
|
+
* Uses callLLM() as the underlying API call.
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterFolders(treeStructure: string, apiKey?: string, model?: string, verbose?: boolean, useCache?: boolean): Promise<FilterResult>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=folder-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folder-filter.d.ts","sourceRoot":"","sources":["../../src/ai/folder-filter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2BH,UAAU,YAAY;IACpB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,GAAE,MAAsB,EAC7B,OAAO,GAAE,OAAe,EACxB,QAAQ,GAAE,OAAc,GACvB,OAAO,CAAC,YAAY,CAAC,CAqDvB"}
|