@vpxa/kb 0.1.1 → 0.1.2
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/packages/analyzers/dist/blast-radius-analyzer.js +13 -114
- package/packages/analyzers/dist/dependency-analyzer.js +11 -425
- package/packages/analyzers/dist/diagram-generator.js +4 -86
- package/packages/analyzers/dist/entry-point-analyzer.js +5 -239
- package/packages/analyzers/dist/index.js +1 -23
- package/packages/analyzers/dist/knowledge-producer.js +24 -113
- package/packages/analyzers/dist/pattern-analyzer.js +5 -359
- package/packages/analyzers/dist/regex-call-graph.js +1 -428
- package/packages/analyzers/dist/structure-analyzer.js +4 -258
- package/packages/analyzers/dist/symbol-analyzer.js +13 -442
- package/packages/analyzers/dist/ts-call-graph.js +1 -160
- package/packages/analyzers/dist/types.js +0 -1
- package/packages/chunker/dist/call-graph-extractor.js +1 -90
- package/packages/chunker/dist/chunker-factory.js +1 -36
- package/packages/chunker/dist/chunker.interface.js +0 -1
- package/packages/chunker/dist/code-chunker.js +14 -134
- package/packages/chunker/dist/generic-chunker.js +5 -72
- package/packages/chunker/dist/index.js +1 -21
- package/packages/chunker/dist/markdown-chunker.js +7 -119
- package/packages/chunker/dist/treesitter-chunker.js +8 -234
- package/packages/cli/dist/commands/analyze.js +3 -112
- package/packages/cli/dist/commands/context-cmds.js +1 -155
- package/packages/cli/dist/commands/environment.js +2 -204
- package/packages/cli/dist/commands/execution.js +1 -137
- package/packages/cli/dist/commands/graph.js +7 -81
- package/packages/cli/dist/commands/init.js +9 -87
- package/packages/cli/dist/commands/knowledge.js +1 -139
- package/packages/cli/dist/commands/search.js +8 -267
- package/packages/cli/dist/commands/system.js +4 -241
- package/packages/cli/dist/commands/workspace.js +2 -388
- package/packages/cli/dist/context.js +1 -14
- package/packages/cli/dist/helpers.js +3 -458
- package/packages/cli/dist/index.js +3 -69
- package/packages/cli/dist/kb-init.js +1 -82
- package/packages/cli/dist/types.js +0 -1
- package/packages/core/dist/constants.js +1 -43
- package/packages/core/dist/content-detector.js +1 -79
- package/packages/core/dist/errors.js +1 -40
- package/packages/core/dist/index.js +1 -9
- package/packages/core/dist/logger.js +1 -34
- package/packages/core/dist/types.js +0 -1
- package/packages/embeddings/dist/embedder.interface.js +0 -1
- package/packages/embeddings/dist/index.js +1 -5
- package/packages/embeddings/dist/onnx-embedder.js +1 -82
- package/packages/indexer/dist/file-hasher.js +1 -13
- package/packages/indexer/dist/filesystem-crawler.js +1 -125
- package/packages/indexer/dist/graph-extractor.js +1 -111
- package/packages/indexer/dist/incremental-indexer.js +1 -278
- package/packages/indexer/dist/index.js +1 -14
- package/packages/server/dist/api.js +1 -9
- package/packages/server/dist/config.js +1 -75
- package/packages/server/dist/curated-manager.js +9 -356
- package/packages/server/dist/index.js +1 -134
- package/packages/server/dist/replay-interceptor.js +1 -38
- package/packages/server/dist/resources/resources.js +2 -40
- package/packages/server/dist/server.js +1 -247
- package/packages/server/dist/tools/analyze.tools.js +1 -288
- package/packages/server/dist/tools/forge.tools.js +11 -499
- package/packages/server/dist/tools/forget.tool.js +3 -39
- package/packages/server/dist/tools/graph.tool.js +5 -110
- package/packages/server/dist/tools/list.tool.js +5 -53
- package/packages/server/dist/tools/lookup.tool.js +8 -51
- package/packages/server/dist/tools/onboard.tool.js +2 -112
- package/packages/server/dist/tools/produce.tool.js +4 -74
- package/packages/server/dist/tools/read.tool.js +4 -47
- package/packages/server/dist/tools/reindex.tool.js +2 -70
- package/packages/server/dist/tools/remember.tool.js +3 -42
- package/packages/server/dist/tools/replay.tool.js +6 -88
- package/packages/server/dist/tools/search.tool.js +17 -327
- package/packages/server/dist/tools/status.tool.js +3 -68
- package/packages/server/dist/tools/toolkit.tools.js +20 -1673
- package/packages/server/dist/tools/update.tool.js +3 -39
- package/packages/server/dist/tools/utility.tools.js +19 -456
- package/packages/store/dist/graph-store.interface.js +0 -1
- package/packages/store/dist/index.js +1 -9
- package/packages/store/dist/lance-store.js +1 -258
- package/packages/store/dist/sqlite-graph-store.js +8 -309
- package/packages/store/dist/store-factory.js +1 -14
- package/packages/store/dist/store.interface.js +0 -1
- package/packages/tools/dist/batch.js +1 -45
- package/packages/tools/dist/changelog.js +2 -112
- package/packages/tools/dist/check.js +2 -59
- package/packages/tools/dist/checkpoint.js +2 -43
- package/packages/tools/dist/codemod.js +2 -69
- package/packages/tools/dist/compact.js +3 -60
- package/packages/tools/dist/data-transform.js +1 -124
- package/packages/tools/dist/dead-symbols.js +2 -71
- package/packages/tools/dist/delegate.js +3 -128
- package/packages/tools/dist/diff-parse.js +3 -153
- package/packages/tools/dist/digest.js +7 -242
- package/packages/tools/dist/encode.js +1 -46
- package/packages/tools/dist/env-info.js +1 -58
- package/packages/tools/dist/eval.js +3 -79
- package/packages/tools/dist/evidence-map.js +3 -203
- package/packages/tools/dist/file-summary.js +2 -106
- package/packages/tools/dist/file-walk.js +1 -75
- package/packages/tools/dist/find-examples.js +3 -48
- package/packages/tools/dist/find.js +1 -120
- package/packages/tools/dist/forge-classify.js +2 -319
- package/packages/tools/dist/forge-ground.js +1 -184
- package/packages/tools/dist/git-context.js +3 -46
- package/packages/tools/dist/graph-query.js +1 -194
- package/packages/tools/dist/health.js +1 -118
- package/packages/tools/dist/http-request.js +1 -58
- package/packages/tools/dist/index.js +1 -273
- package/packages/tools/dist/lane.js +7 -227
- package/packages/tools/dist/measure.js +2 -119
- package/packages/tools/dist/onboard.js +42 -1136
- package/packages/tools/dist/parse-output.js +2 -158
- package/packages/tools/dist/process-manager.js +1 -69
- package/packages/tools/dist/queue.js +2 -126
- package/packages/tools/dist/regex-test.js +1 -39
- package/packages/tools/dist/rename.js +2 -70
- package/packages/tools/dist/replay.js +6 -108
- package/packages/tools/dist/schema-validate.js +1 -141
- package/packages/tools/dist/scope-map.js +1 -72
- package/packages/tools/dist/snippet.js +1 -80
- package/packages/tools/dist/stash.js +2 -60
- package/packages/tools/dist/stratum-card.js +5 -238
- package/packages/tools/dist/symbol.js +3 -87
- package/packages/tools/dist/test-run.js +2 -55
- package/packages/tools/dist/text-utils.js +2 -31
- package/packages/tools/dist/time-utils.js +1 -135
- package/packages/tools/dist/trace.js +2 -114
- package/packages/tools/dist/truncation.js +10 -41
- package/packages/tools/dist/watch.js +1 -61
- package/packages/tools/dist/web-fetch.js +9 -244
- package/packages/tools/dist/web-search.js +1 -46
- package/packages/tools/dist/workset.js +2 -77
- package/packages/tui/dist/App.js +260 -52468
- package/packages/tui/dist/index.js +286 -54551
- package/packages/tui/dist/panels/CuratedPanel.js +211 -34291
- package/packages/tui/dist/panels/LogPanel.js +259 -51703
- package/packages/tui/dist/panels/SearchPanel.js +212 -34824
- package/packages/tui/dist/panels/StatusPanel.js +211 -34304
|
@@ -1,258 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
lib: "Library code",
|
|
6
|
-
dist: "Build output",
|
|
7
|
-
build: "Build output",
|
|
8
|
-
test: "Tests",
|
|
9
|
-
tests: "Tests",
|
|
10
|
-
spec: "Tests",
|
|
11
|
-
__tests__: "Tests",
|
|
12
|
-
docs: "Documentation",
|
|
13
|
-
scripts: "Build/utility scripts",
|
|
14
|
-
config: "Configuration",
|
|
15
|
-
handlers: "Entry point handlers",
|
|
16
|
-
controllers: "HTTP controllers",
|
|
17
|
-
routes: "API routes",
|
|
18
|
-
middleware: "Middleware",
|
|
19
|
-
services: "Business logic services",
|
|
20
|
-
domain: "Domain/business logic",
|
|
21
|
-
infrastructure: "External integrations",
|
|
22
|
-
adapters: "Adapter implementations",
|
|
23
|
-
ports: "Port interfaces",
|
|
24
|
-
models: "Data models",
|
|
25
|
-
entities: "Domain entities",
|
|
26
|
-
repositories: "Data access",
|
|
27
|
-
utils: "Utilities",
|
|
28
|
-
helpers: "Helper functions",
|
|
29
|
-
types: "Type definitions",
|
|
30
|
-
interfaces: "Interface definitions",
|
|
31
|
-
constants: "Constants",
|
|
32
|
-
cdk: "CDK infrastructure",
|
|
33
|
-
stacks: "CDK stacks",
|
|
34
|
-
constructs: "CDK constructs",
|
|
35
|
-
lambdas: "Lambda functions",
|
|
36
|
-
components: "UI components",
|
|
37
|
-
hooks: "React hooks",
|
|
38
|
-
pages: "Page components",
|
|
39
|
-
layouts: "Layout components",
|
|
40
|
-
store: "State management",
|
|
41
|
-
assets: "Static assets",
|
|
42
|
-
styles: "Stylesheets",
|
|
43
|
-
fixtures: "Test fixtures",
|
|
44
|
-
mocks: "Test mocks",
|
|
45
|
-
migrations: "Database migrations"
|
|
46
|
-
};
|
|
47
|
-
const LANGUAGE_MAP = {
|
|
48
|
-
".ts": "TypeScript",
|
|
49
|
-
".tsx": "React TSX",
|
|
50
|
-
".js": "JavaScript",
|
|
51
|
-
".jsx": "React JSX",
|
|
52
|
-
".mjs": "ES Module",
|
|
53
|
-
".cjs": "CommonJS",
|
|
54
|
-
".json": "JSON",
|
|
55
|
-
".yaml": "YAML",
|
|
56
|
-
".yml": "YAML",
|
|
57
|
-
".md": "Markdown",
|
|
58
|
-
".mdx": "MDX",
|
|
59
|
-
".py": "Python",
|
|
60
|
-
".go": "Go",
|
|
61
|
-
".rs": "Rust",
|
|
62
|
-
".java": "Java",
|
|
63
|
-
".sh": "Shell",
|
|
64
|
-
".ps1": "PowerShell",
|
|
65
|
-
".css": "CSS",
|
|
66
|
-
".scss": "SCSS",
|
|
67
|
-
".html": "HTML",
|
|
68
|
-
".sql": "SQL",
|
|
69
|
-
".graphql": "GraphQL",
|
|
70
|
-
".proto": "Protocol Buffers",
|
|
71
|
-
".toml": "TOML",
|
|
72
|
-
".env": "Environment"
|
|
73
|
-
};
|
|
74
|
-
const DEFAULT_EXCLUDES = /* @__PURE__ */ new Set([
|
|
75
|
-
"node_modules",
|
|
76
|
-
".git",
|
|
77
|
-
"dist",
|
|
78
|
-
"build",
|
|
79
|
-
".next",
|
|
80
|
-
".nuxt",
|
|
81
|
-
"coverage",
|
|
82
|
-
".turbo",
|
|
83
|
-
".cache",
|
|
84
|
-
"__pycache__",
|
|
85
|
-
".venv",
|
|
86
|
-
".terraform",
|
|
87
|
-
"cdk.out"
|
|
88
|
-
]);
|
|
89
|
-
const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
90
|
-
// Code
|
|
91
|
-
".ts",
|
|
92
|
-
".tsx",
|
|
93
|
-
".js",
|
|
94
|
-
".jsx",
|
|
95
|
-
".mjs",
|
|
96
|
-
".cjs",
|
|
97
|
-
".java",
|
|
98
|
-
".kt",
|
|
99
|
-
".kts",
|
|
100
|
-
".scala",
|
|
101
|
-
".py",
|
|
102
|
-
".go",
|
|
103
|
-
".rs",
|
|
104
|
-
".rb",
|
|
105
|
-
".php",
|
|
106
|
-
".swift",
|
|
107
|
-
".cs",
|
|
108
|
-
".c",
|
|
109
|
-
".cpp",
|
|
110
|
-
".h",
|
|
111
|
-
".hpp",
|
|
112
|
-
".sh",
|
|
113
|
-
".bash",
|
|
114
|
-
".ps1",
|
|
115
|
-
".sql",
|
|
116
|
-
".graphql",
|
|
117
|
-
".gql",
|
|
118
|
-
".proto",
|
|
119
|
-
// Config
|
|
120
|
-
".json",
|
|
121
|
-
".yaml",
|
|
122
|
-
".yml",
|
|
123
|
-
".toml",
|
|
124
|
-
".env",
|
|
125
|
-
".ini",
|
|
126
|
-
".cfg",
|
|
127
|
-
".xml",
|
|
128
|
-
".pom",
|
|
129
|
-
".gradle",
|
|
130
|
-
".tf",
|
|
131
|
-
".hcl",
|
|
132
|
-
// Build/project
|
|
133
|
-
".lock",
|
|
134
|
-
".mjs"
|
|
135
|
-
]);
|
|
136
|
-
const COLLAPSED_DIRS = /* @__PURE__ */ new Set([
|
|
137
|
-
"__tests__",
|
|
138
|
-
"test",
|
|
139
|
-
"tests",
|
|
140
|
-
"spec",
|
|
141
|
-
"__mocks__",
|
|
142
|
-
"__fixtures__",
|
|
143
|
-
"fixtures",
|
|
144
|
-
"mocks"
|
|
145
|
-
]);
|
|
146
|
-
class StructureAnalyzer {
|
|
147
|
-
name = "structure";
|
|
148
|
-
async analyze(rootPath, options = {}) {
|
|
149
|
-
const { format = "markdown", maxDepth = 6, sourceOnly = false } = options;
|
|
150
|
-
const startTime = Date.now();
|
|
151
|
-
const tree = await this.buildTree(rootPath, 0, maxDepth, sourceOnly);
|
|
152
|
-
const stats = this.computeStats(tree);
|
|
153
|
-
const output = format === "json" ? JSON.stringify({ tree, stats }, null, 2) : this.formatMarkdown(tree, stats, rootPath);
|
|
154
|
-
return {
|
|
155
|
-
output,
|
|
156
|
-
data: { tree, stats },
|
|
157
|
-
meta: {
|
|
158
|
-
analyzedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
159
|
-
scope: rootPath,
|
|
160
|
-
fileCount: stats.totalFiles,
|
|
161
|
-
durationMs: Date.now() - startTime
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
async buildTree(dirPath, depth, maxDepth, sourceOnly) {
|
|
166
|
-
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
167
|
-
const children = [];
|
|
168
|
-
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
169
|
-
if (DEFAULT_EXCLUDES.has(entry.name)) continue;
|
|
170
|
-
if (entry.name.startsWith(".") && entry.name !== ".env.example") continue;
|
|
171
|
-
const fullPath = join(dirPath, entry.name);
|
|
172
|
-
if (entry.isDirectory() && depth < maxDepth) {
|
|
173
|
-
const subtree = await this.buildTree(fullPath, depth + 1, maxDepth, sourceOnly);
|
|
174
|
-
if (sourceOnly && (!subtree.children || subtree.children.length === 0)) continue;
|
|
175
|
-
children.push(subtree);
|
|
176
|
-
} else if (entry.isFile()) {
|
|
177
|
-
const ext = extname(entry.name).toLowerCase();
|
|
178
|
-
if (sourceOnly && ext && !SOURCE_EXTENSIONS.has(ext)) continue;
|
|
179
|
-
if (sourceOnly && !ext) continue;
|
|
180
|
-
const fileStat = await stat(fullPath);
|
|
181
|
-
children.push({
|
|
182
|
-
name: entry.name,
|
|
183
|
-
type: "file",
|
|
184
|
-
language: LANGUAGE_MAP[ext] ?? (ext || "unknown"),
|
|
185
|
-
size: fileStat.size
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const dirName = dirPath.split(/[/\\]/).pop() ?? dirPath;
|
|
190
|
-
return {
|
|
191
|
-
name: dirName,
|
|
192
|
-
type: "directory",
|
|
193
|
-
purpose: DIRECTORY_PURPOSES[dirName.toLowerCase()],
|
|
194
|
-
children
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
computeStats(tree) {
|
|
198
|
-
const languages = {};
|
|
199
|
-
let totalFiles = 0;
|
|
200
|
-
let totalSize = 0;
|
|
201
|
-
const walk = (node) => {
|
|
202
|
-
if (node.type === "file") {
|
|
203
|
-
totalFiles++;
|
|
204
|
-
totalSize += node.size ?? 0;
|
|
205
|
-
const lang = node.language ?? "unknown";
|
|
206
|
-
languages[lang] = (languages[lang] ?? 0) + 1;
|
|
207
|
-
}
|
|
208
|
-
node.children?.forEach(walk);
|
|
209
|
-
};
|
|
210
|
-
walk(tree);
|
|
211
|
-
return { totalFiles, totalSize, languages };
|
|
212
|
-
}
|
|
213
|
-
formatMarkdown(tree, stats, rootPath) {
|
|
214
|
-
const lines = [];
|
|
215
|
-
lines.push(`## Project Structure: ${rootPath}
|
|
216
|
-
`);
|
|
217
|
-
lines.push(
|
|
218
|
-
`**${stats.totalFiles} files** | Languages: ${Object.entries(stats.languages).map(([l, c]) => `${l} (${c})`).join(", ")}
|
|
219
|
-
`
|
|
220
|
-
);
|
|
221
|
-
lines.push("```");
|
|
222
|
-
this.renderTree(tree, "", lines);
|
|
223
|
-
lines.push("```");
|
|
224
|
-
return lines.join("\n");
|
|
225
|
-
}
|
|
226
|
-
renderTree(node, prefix, lines) {
|
|
227
|
-
const annotation = node.purpose ? ` \u2500\u2500 ${node.purpose}` : "";
|
|
228
|
-
if (node.type === "directory") {
|
|
229
|
-
const lowerName = node.name.toLowerCase();
|
|
230
|
-
if (COLLAPSED_DIRS.has(lowerName) && node.children) {
|
|
231
|
-
const count = this.countFiles(node);
|
|
232
|
-
lines.push(`${prefix}${node.name}/${annotation} (${count} files)`);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
lines.push(`${prefix}${node.name}/${annotation}`);
|
|
236
|
-
node.children?.forEach((child, i) => {
|
|
237
|
-
const isLast = i === (node.children?.length ?? 0) - 1;
|
|
238
|
-
const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
239
|
-
const nextPrefix = prefix + (isLast ? " " : "\u2502 ");
|
|
240
|
-
if (child.type === "directory") {
|
|
241
|
-
this.renderTree(child, nextPrefix, lines);
|
|
242
|
-
} else {
|
|
243
|
-
lines.push(`${prefix}${connector}${child.name}`);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
} else {
|
|
247
|
-
lines.push(`${prefix}${node.name}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
countFiles(node) {
|
|
251
|
-
if (node.type === "file") return 1;
|
|
252
|
-
return (node.children ?? []).reduce((sum, child) => sum + this.countFiles(child), 0);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
export {
|
|
256
|
-
StructureAnalyzer
|
|
257
|
-
};
|
|
258
|
-
//# sourceMappingURL=structure-analyzer.js.map
|
|
1
|
+
import{readdir as p,stat as m}from"node:fs/promises";import{extname as d,join as f}from"node:path";const h={src:"Application source",lib:"Library code",dist:"Build output",build:"Build output",test:"Tests",tests:"Tests",spec:"Tests",__tests__:"Tests",docs:"Documentation",scripts:"Build/utility scripts",config:"Configuration",handlers:"Entry point handlers",controllers:"HTTP controllers",routes:"API routes",middleware:"Middleware",services:"Business logic services",domain:"Domain/business logic",infrastructure:"External integrations",adapters:"Adapter implementations",ports:"Port interfaces",models:"Data models",entities:"Domain entities",repositories:"Data access",utils:"Utilities",helpers:"Helper functions",types:"Type definitions",interfaces:"Interface definitions",constants:"Constants",cdk:"CDK infrastructure",stacks:"CDK stacks",constructs:"CDK constructs",lambdas:"Lambda functions",components:"UI components",hooks:"React hooks",pages:"Page components",layouts:"Layout components",store:"State management",assets:"Static assets",styles:"Stylesheets",fixtures:"Test fixtures",mocks:"Test mocks",migrations:"Database migrations"},g={".ts":"TypeScript",".tsx":"React TSX",".js":"JavaScript",".jsx":"React JSX",".mjs":"ES Module",".cjs":"CommonJS",".json":"JSON",".yaml":"YAML",".yml":"YAML",".md":"Markdown",".mdx":"MDX",".py":"Python",".go":"Go",".rs":"Rust",".java":"Java",".sh":"Shell",".ps1":"PowerShell",".css":"CSS",".scss":"SCSS",".html":"HTML",".sql":"SQL",".graphql":"GraphQL",".proto":"Protocol Buffers",".toml":"TOML",".env":"Environment"},y=new Set(["node_modules",".git","dist","build",".next",".nuxt","coverage",".turbo",".cache","__pycache__",".venv",".terraform","cdk.out"]),S=new Set([".ts",".tsx",".js",".jsx",".mjs",".cjs",".java",".kt",".kts",".scala",".py",".go",".rs",".rb",".php",".swift",".cs",".c",".cpp",".h",".hpp",".sh",".bash",".ps1",".sql",".graphql",".gql",".proto",".json",".yaml",".yml",".toml",".env",".ini",".cfg",".xml",".pom",".gradle",".tf",".hcl",".lock",".mjs"]),T=new Set(["__tests__","test","tests","spec","__mocks__","__fixtures__","fixtures","mocks"]);class b{name="structure";async analyze(t,e={}){const{format:r="markdown",maxDepth:s=6,sourceOnly:c=!1}=e,n=Date.now(),i=await this.buildTree(t,0,s,c),o=this.computeStats(i);return{output:r==="json"?JSON.stringify({tree:i,stats:o},null,2):this.formatMarkdown(i,o,t),data:{tree:i,stats:o},meta:{analyzedAt:new Date().toISOString(),scope:t,fileCount:o.totalFiles,durationMs:Date.now()-n}}}async buildTree(t,e,r,s){const c=await p(t,{withFileTypes:!0}),n=[];for(const o of c.sort((l,a)=>l.name.localeCompare(a.name))){if(y.has(o.name)||o.name.startsWith(".")&&o.name!==".env.example")continue;const l=f(t,o.name);if(o.isDirectory()&&e<r){const a=await this.buildTree(l,e+1,r,s);if(s&&(!a.children||a.children.length===0))continue;n.push(a)}else if(o.isFile()){const a=d(o.name).toLowerCase();if(s&&a&&!S.has(a)||s&&!a)continue;const u=await m(l);n.push({name:o.name,type:"file",language:g[a]??(a||"unknown"),size:u.size})}}const i=t.split(/[/\\]/).pop()??t;return{name:i,type:"directory",purpose:h[i.toLowerCase()],children:n}}computeStats(t){const e={};let r=0,s=0;const c=n=>{if(n.type==="file"){r++,s+=n.size??0;const i=n.language??"unknown";e[i]=(e[i]??0)+1}n.children?.forEach(c)};return c(t),{totalFiles:r,totalSize:s,languages:e}}formatMarkdown(t,e,r){const s=[];return s.push(`## Project Structure: ${r}
|
|
2
|
+
`),s.push(`**${e.totalFiles} files** | Languages: ${Object.entries(e.languages).map(([c,n])=>`${c} (${n})`).join(", ")}
|
|
3
|
+
`),s.push("```"),this.renderTree(t,"",s),s.push("```"),s.join(`
|
|
4
|
+
`)}renderTree(t,e,r){const s=t.purpose?` \u2500\u2500 ${t.purpose}`:"";if(t.type==="directory"){const c=t.name.toLowerCase();if(T.has(c)&&t.children){const n=this.countFiles(t);r.push(`${e}${t.name}/${s} (${n} files)`);return}r.push(`${e}${t.name}/${s}`),t.children?.forEach((n,i)=>{const o=i===(t.children?.length??0)-1,l=o?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",a=e+(o?" ":"\u2502 ");n.type==="directory"?this.renderTree(n,a,r):r.push(`${e}${l}${n.name}`)})}else r.push(`${e}${t.name}`)}countFiles(t){return t.type==="file"?1:(t.children??[]).reduce((e,r)=>e+this.countFiles(r),0)}}export{b as StructureAnalyzer};
|