@winci/local-rag 0.2.3 → 0.2.4
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/package.json +1 -1
- package/src/cli/setup.ts +3 -2
- package/src/config/index.ts +25 -19
package/package.json
CHANGED
package/src/cli/setup.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync } from "fs";
|
|
|
2
2
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
3
3
|
import { join, resolve } from "path";
|
|
4
4
|
import { createInterface } from "readline";
|
|
5
|
-
import {
|
|
5
|
+
import { loadConfig } from "../config";
|
|
6
6
|
|
|
7
7
|
const MARKER = "<!-- local-rag -->";
|
|
8
8
|
|
|
@@ -69,7 +69,8 @@ export interface SetupResult {
|
|
|
69
69
|
export async function ensureConfig(projectDir: string): Promise<string | null> {
|
|
70
70
|
const configPath = join(projectDir, ".rag", "config.json");
|
|
71
71
|
if (existsSync(configPath)) return null;
|
|
72
|
-
|
|
72
|
+
// loadConfig auto-creates the file with defaults if missing
|
|
73
|
+
await loadConfig(projectDir);
|
|
73
74
|
return "Created .rag/config.json";
|
|
74
75
|
}
|
|
75
76
|
|
package/src/config/index.ts
CHANGED
|
@@ -23,28 +23,40 @@ export type RagConfig = z.infer<typeof RagConfigSchema>;
|
|
|
23
23
|
|
|
24
24
|
const DEFAULT_CONFIG: RagConfig = {
|
|
25
25
|
include: [
|
|
26
|
+
// Source code — AST-aware chunking
|
|
27
|
+
"**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx",
|
|
28
|
+
"**/*.py",
|
|
29
|
+
"**/*.go",
|
|
30
|
+
"**/*.rs",
|
|
31
|
+
"**/*.java",
|
|
32
|
+
// Source code — heuristic chunking
|
|
33
|
+
"**/*.c", "**/*.cpp", "**/*.h", "**/*.hpp",
|
|
34
|
+
"**/*.rb",
|
|
35
|
+
"**/*.swift",
|
|
26
36
|
// Markdown & plain text
|
|
27
|
-
"**/*.md", "**/*.txt",
|
|
37
|
+
"**/*.md", "**/*.mdx", "**/*.markdown", "**/*.txt",
|
|
28
38
|
// Build / task runners (no extension or prefix-named)
|
|
29
39
|
"**/Makefile", "**/makefile", "**/GNUmakefile",
|
|
30
40
|
"**/Dockerfile", "**/Dockerfile.*",
|
|
31
41
|
"**/Jenkinsfile", "**/Jenkinsfile.*",
|
|
32
42
|
"**/Vagrantfile", "**/Gemfile", "**/Rakefile",
|
|
33
43
|
"**/Brewfile", "**/Procfile",
|
|
44
|
+
// Shell & scripting
|
|
45
|
+
"**/*.sh", "**/*.bash", "**/*.zsh", "**/*.fish",
|
|
34
46
|
// Structured data & config
|
|
35
47
|
"**/*.yaml", "**/*.yml",
|
|
36
48
|
"**/*.json",
|
|
37
49
|
"**/*.toml",
|
|
38
50
|
"**/*.xml",
|
|
39
|
-
// Shell & scripting
|
|
40
|
-
"**/*.sh", "**/*.bash", "**/*.zsh",
|
|
41
51
|
// Infrastructure / schema languages
|
|
42
52
|
"**/*.tf",
|
|
43
53
|
"**/*.proto",
|
|
44
54
|
"**/*.graphql", "**/*.gql",
|
|
45
55
|
"**/*.sql",
|
|
46
56
|
"**/*.mod",
|
|
57
|
+
// API collections
|
|
47
58
|
"**/*.bru",
|
|
59
|
+
// Stylesheets
|
|
48
60
|
"**/*.css", "**/*.scss", "**/*.less",
|
|
49
61
|
],
|
|
50
62
|
exclude: ["node_modules/**", ".git/**", "dist/**", ".rag/**"],
|
|
@@ -60,28 +72,30 @@ const DEFAULT_CONFIG: RagConfig = {
|
|
|
60
72
|
};
|
|
61
73
|
|
|
62
74
|
/**
|
|
63
|
-
* Load config from .rag/config.json
|
|
64
|
-
*
|
|
65
|
-
*
|
|
75
|
+
* Load config from .rag/config.json.
|
|
76
|
+
* If the file doesn't exist, writes the defaults there first so users can
|
|
77
|
+
* edit the file directly — no hidden merge logic, what's on disk is what runs.
|
|
66
78
|
*/
|
|
67
79
|
export async function loadConfig(projectDir: string): Promise<RagConfig> {
|
|
68
|
-
const
|
|
80
|
+
const ragDir = join(projectDir, ".rag");
|
|
81
|
+
const configPath = join(ragDir, "config.json");
|
|
69
82
|
|
|
70
83
|
if (!existsSync(configPath)) {
|
|
84
|
+
await mkdir(ragDir, { recursive: true });
|
|
85
|
+
await writeFile(configPath, JSON.stringify(DEFAULT_CONFIG, null, 2) + "\n");
|
|
71
86
|
return { ...DEFAULT_CONFIG };
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
const raw = await readFile(configPath, "utf-8");
|
|
75
|
-
let
|
|
90
|
+
let parsed: unknown;
|
|
76
91
|
try {
|
|
77
|
-
|
|
92
|
+
parsed = JSON.parse(raw);
|
|
78
93
|
} catch {
|
|
79
94
|
log.warn(`Invalid JSON in ${configPath}, using defaults`, "config");
|
|
80
95
|
return { ...DEFAULT_CONFIG };
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
const
|
|
84
|
-
const result = RagConfigSchema.safeParse(merged);
|
|
98
|
+
const result = RagConfigSchema.safeParse(parsed);
|
|
85
99
|
|
|
86
100
|
if (!result.success) {
|
|
87
101
|
const issues = result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join(", ");
|
|
@@ -91,11 +105,3 @@ export async function loadConfig(projectDir: string): Promise<RagConfig> {
|
|
|
91
105
|
|
|
92
106
|
return result.data;
|
|
93
107
|
}
|
|
94
|
-
|
|
95
|
-
export async function writeDefaultConfig(projectDir: string): Promise<string> {
|
|
96
|
-
const ragDir = join(projectDir, ".rag");
|
|
97
|
-
await mkdir(ragDir, { recursive: true });
|
|
98
|
-
const configPath = join(ragDir, "config.json");
|
|
99
|
-
await writeFile(configPath, JSON.stringify(DEFAULT_CONFIG, null, 2) + "\n");
|
|
100
|
-
return configPath;
|
|
101
|
-
}
|