-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
234 lines (221 loc) · 6.49 KB
/
config.ts
File metadata and controls
234 lines (221 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* Configuration loader
*/
import * as fs from "fs";
import * as path from "path";
import { logger } from "./utils/logger.js";
export interface ArchitectureConfig {
layers: LayerConfig[];
rules: RuleConfig[];
}
export interface LayerConfig {
id: string;
name: string;
paths: string[];
canImport: string[];
description?: string;
}
export interface RuleConfig {
id: string;
severity: "error" | "warn";
pattern: string;
description: string;
}
export interface ProgressConfig {
features: Array<{
id: string;
name: string;
status: "not-started" | "in-progress" | "blocked" | "completed";
priority: "low" | "medium" | "high";
description?: string;
tasks?: string[];
}>;
}
export interface Config {
architecture: ArchitectureConfig;
testing?: {
categories: Array<{
id: string;
patterns: string[];
}>;
/**
* Explicit test runner to invoke via `test_run` and `test:affected`.
* When omitted the runner is auto-detected from the test file extensions
* (e.g. .py → pytest, .rb → bundle exec rspec, .ts/.js → vitest).
* @example { "command": "pytest", "args": ["--tb=short"] }
*/
testRunner?: {
command: string;
args?: string[];
};
/**
* Glob patterns used by the architecture engine to discover source files.
* Defaults to ["src/**\/*.{ts,tsx}"] when not specified.
* @example ["src/**\/*.py", "lib/**\/*.py"]
*/
sourceGlobs?: string[];
/**
* Default file extension appended when generating new file paths (e.g. via
* arch_suggest). Defaults to ".ts". Use ".py", ".rb", ".go", etc. for
* non-TypeScript projects.
*/
defaultExtension?: string;
};
progress?: ProgressConfig;
}
// Generic TypeScript server defaults — create .lxdig/config.json at your project root
// to override with project-specific layers and rules.
// Tip: run arch_suggest to get placement guidance; update this file if suggestions
// look wrong (e.g. always "src/types/").
const DEFAULT_CONFIG: Config = {
architecture: {
layers: [
{
id: "types",
name: "Types",
paths: ["src/types/**"],
canImport: [],
description: "Shared type definitions — no runtime dependencies",
},
{
id: "utils",
name: "Utilities",
paths: ["src/utils/**", "src/lib/**", "src/helpers/**"],
canImport: ["types"],
description: "Stateless utility and helper functions",
},
{
id: "parsers",
name: "Parsers",
paths: ["src/parsers/**"],
canImport: ["types", "utils"],
description: "File parsers and language-specific analysis",
},
{
id: "graph",
name: "Graph",
paths: ["src/graph/**"],
canImport: ["types", "utils", "parsers"],
description: "Graph building, caching and Memgraph client",
},
{
id: "vector",
name: "Vector",
paths: ["src/vector/**"],
canImport: ["types", "utils", "graph"],
description: "Embedding engine and Qdrant client",
},
{
id: "engines",
name: "Engines",
paths: ["src/engines/**"],
canImport: ["types", "utils", "parsers", "graph", "vector"],
description: "Feature engines — architecture, community, docs, test, progress",
},
{
id: "tools",
name: "Tools",
paths: ["src/tools/**"],
canImport: ["types", "utils", "parsers", "graph", "vector", "engines"],
description: "MCP tool handlers — highest-level layer, may use all lower layers",
},
{
id: "server",
name: "Server",
paths: ["src/*.ts"],
canImport: ["types", "utils", "graph", "vector", "engines", "tools"],
description: "Server entry points — wires all layers together",
},
],
rules: [
{
id: "no-tools-in-engines",
severity: "error",
pattern: "engines imports from tools",
description: "Engines must not import from tool handlers",
},
{
id: "no-graph-in-parsers",
severity: "warn",
pattern: "parsers imports from graph",
description: "Parsers should be graph-agnostic for reuse and testability",
},
],
},
testing: {
categories: [
{
id: "unit",
patterns: ["**/__tests__/**/*.test.ts", "!**/*.integration.test.ts"],
},
{
id: "integration",
patterns: ["**/__tests__/**/*.integration.test.ts"],
},
],
},
progress: {
features: [
{
id: "phase-1",
name: "Code Graph MVP",
status: "completed",
priority: "high",
description: "Parse codebase and build graph",
tasks: ["parse-files", "build-graph", "validate-output"],
},
{
id: "phase-2",
name: "Architecture Validation",
status: "completed",
priority: "high",
description: "Layer validation and constraint checking",
tasks: ["layer-rules", "circular-detection", "pre-commit-hook"],
},
{
id: "phase-3",
name: "Test Intelligence",
status: "completed",
priority: "high",
description: "Test selection and execution",
tasks: ["test-extraction", "test-selection", "vitest-integration"],
},
{
id: "phase-4",
name: "MCP Tools",
status: "completed",
priority: "high",
description: "Wire all 14 MCP tools",
tasks: ["tool-schemas", "tool-handlers", "claude-integration"],
},
{
id: "phase-5",
name: "Progress Tracking",
status: "in-progress",
priority: "medium",
description: "Track features and tasks",
tasks: ["config-progress", "seed-nodes", "persistence"],
},
],
},
};
export async function loadConfig(): Promise<Config> {
const configPath = path.join(process.cwd(), ".lxdig", "config.json");
try {
if (fs.existsSync(configPath)) {
const data = fs.readFileSync(configPath, "utf-8");
return JSON.parse(data);
}
} catch (error) {
logger.warn("[Config] Error loading config file:", error);
}
return DEFAULT_CONFIG;
}
export function saveConfig(config: Config, configPath?: string): void {
const targetPath = configPath || path.join(process.cwd(), ".lxdig", "config.json");
const dir = path.dirname(targetPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(targetPath, JSON.stringify(config, null, 2));
}