@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.
Files changed (136) hide show
  1. package/package.json +1 -1
  2. package/packages/analyzers/dist/blast-radius-analyzer.js +13 -114
  3. package/packages/analyzers/dist/dependency-analyzer.js +11 -425
  4. package/packages/analyzers/dist/diagram-generator.js +4 -86
  5. package/packages/analyzers/dist/entry-point-analyzer.js +5 -239
  6. package/packages/analyzers/dist/index.js +1 -23
  7. package/packages/analyzers/dist/knowledge-producer.js +24 -113
  8. package/packages/analyzers/dist/pattern-analyzer.js +5 -359
  9. package/packages/analyzers/dist/regex-call-graph.js +1 -428
  10. package/packages/analyzers/dist/structure-analyzer.js +4 -258
  11. package/packages/analyzers/dist/symbol-analyzer.js +13 -442
  12. package/packages/analyzers/dist/ts-call-graph.js +1 -160
  13. package/packages/analyzers/dist/types.js +0 -1
  14. package/packages/chunker/dist/call-graph-extractor.js +1 -90
  15. package/packages/chunker/dist/chunker-factory.js +1 -36
  16. package/packages/chunker/dist/chunker.interface.js +0 -1
  17. package/packages/chunker/dist/code-chunker.js +14 -134
  18. package/packages/chunker/dist/generic-chunker.js +5 -72
  19. package/packages/chunker/dist/index.js +1 -21
  20. package/packages/chunker/dist/markdown-chunker.js +7 -119
  21. package/packages/chunker/dist/treesitter-chunker.js +8 -234
  22. package/packages/cli/dist/commands/analyze.js +3 -112
  23. package/packages/cli/dist/commands/context-cmds.js +1 -155
  24. package/packages/cli/dist/commands/environment.js +2 -204
  25. package/packages/cli/dist/commands/execution.js +1 -137
  26. package/packages/cli/dist/commands/graph.js +7 -81
  27. package/packages/cli/dist/commands/init.js +9 -87
  28. package/packages/cli/dist/commands/knowledge.js +1 -139
  29. package/packages/cli/dist/commands/search.js +8 -267
  30. package/packages/cli/dist/commands/system.js +4 -241
  31. package/packages/cli/dist/commands/workspace.js +2 -388
  32. package/packages/cli/dist/context.js +1 -14
  33. package/packages/cli/dist/helpers.js +3 -458
  34. package/packages/cli/dist/index.js +3 -69
  35. package/packages/cli/dist/kb-init.js +1 -82
  36. package/packages/cli/dist/types.js +0 -1
  37. package/packages/core/dist/constants.js +1 -43
  38. package/packages/core/dist/content-detector.js +1 -79
  39. package/packages/core/dist/errors.js +1 -40
  40. package/packages/core/dist/index.js +1 -9
  41. package/packages/core/dist/logger.js +1 -34
  42. package/packages/core/dist/types.js +0 -1
  43. package/packages/embeddings/dist/embedder.interface.js +0 -1
  44. package/packages/embeddings/dist/index.js +1 -5
  45. package/packages/embeddings/dist/onnx-embedder.js +1 -82
  46. package/packages/indexer/dist/file-hasher.js +1 -13
  47. package/packages/indexer/dist/filesystem-crawler.js +1 -125
  48. package/packages/indexer/dist/graph-extractor.js +1 -111
  49. package/packages/indexer/dist/incremental-indexer.js +1 -278
  50. package/packages/indexer/dist/index.js +1 -14
  51. package/packages/server/dist/api.js +1 -9
  52. package/packages/server/dist/config.js +1 -75
  53. package/packages/server/dist/curated-manager.js +9 -356
  54. package/packages/server/dist/index.js +1 -134
  55. package/packages/server/dist/replay-interceptor.js +1 -38
  56. package/packages/server/dist/resources/resources.js +2 -40
  57. package/packages/server/dist/server.js +1 -247
  58. package/packages/server/dist/tools/analyze.tools.js +1 -288
  59. package/packages/server/dist/tools/forge.tools.js +11 -499
  60. package/packages/server/dist/tools/forget.tool.js +3 -39
  61. package/packages/server/dist/tools/graph.tool.js +5 -110
  62. package/packages/server/dist/tools/list.tool.js +5 -53
  63. package/packages/server/dist/tools/lookup.tool.js +8 -51
  64. package/packages/server/dist/tools/onboard.tool.js +2 -112
  65. package/packages/server/dist/tools/produce.tool.js +4 -74
  66. package/packages/server/dist/tools/read.tool.js +4 -47
  67. package/packages/server/dist/tools/reindex.tool.js +2 -70
  68. package/packages/server/dist/tools/remember.tool.js +3 -42
  69. package/packages/server/dist/tools/replay.tool.js +6 -88
  70. package/packages/server/dist/tools/search.tool.js +17 -327
  71. package/packages/server/dist/tools/status.tool.js +3 -68
  72. package/packages/server/dist/tools/toolkit.tools.js +20 -1673
  73. package/packages/server/dist/tools/update.tool.js +3 -39
  74. package/packages/server/dist/tools/utility.tools.js +19 -456
  75. package/packages/store/dist/graph-store.interface.js +0 -1
  76. package/packages/store/dist/index.js +1 -9
  77. package/packages/store/dist/lance-store.js +1 -258
  78. package/packages/store/dist/sqlite-graph-store.js +8 -309
  79. package/packages/store/dist/store-factory.js +1 -14
  80. package/packages/store/dist/store.interface.js +0 -1
  81. package/packages/tools/dist/batch.js +1 -45
  82. package/packages/tools/dist/changelog.js +2 -112
  83. package/packages/tools/dist/check.js +2 -59
  84. package/packages/tools/dist/checkpoint.js +2 -43
  85. package/packages/tools/dist/codemod.js +2 -69
  86. package/packages/tools/dist/compact.js +3 -60
  87. package/packages/tools/dist/data-transform.js +1 -124
  88. package/packages/tools/dist/dead-symbols.js +2 -71
  89. package/packages/tools/dist/delegate.js +3 -128
  90. package/packages/tools/dist/diff-parse.js +3 -153
  91. package/packages/tools/dist/digest.js +7 -242
  92. package/packages/tools/dist/encode.js +1 -46
  93. package/packages/tools/dist/env-info.js +1 -58
  94. package/packages/tools/dist/eval.js +3 -79
  95. package/packages/tools/dist/evidence-map.js +3 -203
  96. package/packages/tools/dist/file-summary.js +2 -106
  97. package/packages/tools/dist/file-walk.js +1 -75
  98. package/packages/tools/dist/find-examples.js +3 -48
  99. package/packages/tools/dist/find.js +1 -120
  100. package/packages/tools/dist/forge-classify.js +2 -319
  101. package/packages/tools/dist/forge-ground.js +1 -184
  102. package/packages/tools/dist/git-context.js +3 -46
  103. package/packages/tools/dist/graph-query.js +1 -194
  104. package/packages/tools/dist/health.js +1 -118
  105. package/packages/tools/dist/http-request.js +1 -58
  106. package/packages/tools/dist/index.js +1 -273
  107. package/packages/tools/dist/lane.js +7 -227
  108. package/packages/tools/dist/measure.js +2 -119
  109. package/packages/tools/dist/onboard.js +42 -1136
  110. package/packages/tools/dist/parse-output.js +2 -158
  111. package/packages/tools/dist/process-manager.js +1 -69
  112. package/packages/tools/dist/queue.js +2 -126
  113. package/packages/tools/dist/regex-test.js +1 -39
  114. package/packages/tools/dist/rename.js +2 -70
  115. package/packages/tools/dist/replay.js +6 -108
  116. package/packages/tools/dist/schema-validate.js +1 -141
  117. package/packages/tools/dist/scope-map.js +1 -72
  118. package/packages/tools/dist/snippet.js +1 -80
  119. package/packages/tools/dist/stash.js +2 -60
  120. package/packages/tools/dist/stratum-card.js +5 -238
  121. package/packages/tools/dist/symbol.js +3 -87
  122. package/packages/tools/dist/test-run.js +2 -55
  123. package/packages/tools/dist/text-utils.js +2 -31
  124. package/packages/tools/dist/time-utils.js +1 -135
  125. package/packages/tools/dist/trace.js +2 -114
  126. package/packages/tools/dist/truncation.js +10 -41
  127. package/packages/tools/dist/watch.js +1 -61
  128. package/packages/tools/dist/web-fetch.js +9 -244
  129. package/packages/tools/dist/web-search.js +1 -46
  130. package/packages/tools/dist/workset.js +2 -77
  131. package/packages/tui/dist/App.js +260 -52468
  132. package/packages/tui/dist/index.js +286 -54551
  133. package/packages/tui/dist/panels/CuratedPanel.js +211 -34291
  134. package/packages/tui/dist/panels/LogPanel.js +259 -51703
  135. package/packages/tui/dist/panels/SearchPanel.js +212 -34824
  136. package/packages/tui/dist/panels/StatusPanel.js +211 -34304
@@ -1,227 +1,7 @@
1
- import {
2
- cpSync,
3
- existsSync,
4
- mkdirSync,
5
- readdirSync,
6
- readFileSync,
7
- rmSync,
8
- statSync,
9
- writeFileSync
10
- } from "node:fs";
11
- import { join, relative, resolve } from "node:path";
12
- const LANES_DIR = ".kb-state/lanes";
13
- const LANE_META = ".lane-meta.json";
14
- function lanesRoot(cwd) {
15
- return resolve(cwd ?? process.cwd(), LANES_DIR);
16
- }
17
- function laneDir(name, cwd) {
18
- const root = lanesRoot(cwd);
19
- const dir = resolve(root, name);
20
- if (!dir.startsWith(resolve(root))) {
21
- throw new Error(`Invalid lane name: "${name}"`);
22
- }
23
- return dir;
24
- }
25
- function readMeta(name, cwd) {
26
- const metaPath = join(laneDir(name, cwd), LANE_META);
27
- if (!existsSync(metaPath)) {
28
- throw new Error(`Lane "${name}" does not exist`);
29
- }
30
- return JSON.parse(readFileSync(metaPath, "utf-8"));
31
- }
32
- function laneCreate(name, files, cwd) {
33
- const root = cwd ?? process.cwd();
34
- const dir = laneDir(name, cwd);
35
- if (existsSync(dir)) {
36
- throw new Error(`Lane "${name}" already exists`);
37
- }
38
- mkdirSync(dir, { recursive: true });
39
- const resolvedFiles = [];
40
- for (const file of files) {
41
- const absSource = resolve(root, file);
42
- if (!existsSync(absSource)) {
43
- throw new Error(`Source file does not exist: ${file}`);
44
- }
45
- const rel = relative(root, absSource).replace(/\\/g, "/");
46
- const dest = join(dir, rel);
47
- mkdirSync(join(dest, ".."), { recursive: true });
48
- cpSync(absSource, dest);
49
- resolvedFiles.push(rel);
50
- }
51
- const meta = {
52
- name,
53
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
54
- sourceFiles: resolvedFiles,
55
- rootPath: root
56
- };
57
- writeFileSync(join(dir, LANE_META), `${JSON.stringify(meta, null, 2)}
58
- `, "utf-8");
59
- return meta;
60
- }
61
- function laneList(cwd) {
62
- const root = lanesRoot(cwd);
63
- if (!existsSync(root)) return [];
64
- const entries = readdirSync(root);
65
- const result = [];
66
- for (const entry of entries) {
67
- const metaPath = join(root, entry, LANE_META);
68
- if (existsSync(metaPath)) {
69
- result.push(JSON.parse(readFileSync(metaPath, "utf-8")));
70
- }
71
- }
72
- return result;
73
- }
74
- function laneStatus(name, cwd) {
75
- const meta = readMeta(name, cwd);
76
- const dir = laneDir(name, cwd);
77
- const root = meta.rootPath;
78
- const entries = [];
79
- for (const file of meta.sourceFiles) {
80
- const originalPath = resolve(root, file);
81
- const lanePath = join(dir, file);
82
- if (!existsSync(lanePath)) {
83
- entries.push({ file, status: "deleted" });
84
- continue;
85
- }
86
- if (!existsSync(originalPath)) {
87
- entries.push({ file, status: "added" });
88
- continue;
89
- }
90
- const original = readFileSync(originalPath, "utf-8");
91
- const laneContent = readFileSync(lanePath, "utf-8");
92
- if (original === laneContent) {
93
- entries.push({ file, status: "unchanged" });
94
- } else {
95
- entries.push({ file, status: "modified" });
96
- }
97
- }
98
- const laneFiles = collectLaneFiles(dir);
99
- for (const laneFile of laneFiles) {
100
- if (!meta.sourceFiles.includes(laneFile)) {
101
- entries.push({ file: laneFile, status: "added" });
102
- }
103
- }
104
- return {
105
- name,
106
- entries,
107
- modified: entries.filter((e) => e.status === "modified").length,
108
- added: entries.filter((e) => e.status === "added").length,
109
- deleted: entries.filter((e) => e.status === "deleted").length
110
- };
111
- }
112
- function laneDiff(name, cwd) {
113
- const meta = readMeta(name, cwd);
114
- const dir = laneDir(name, cwd);
115
- const root = meta.rootPath;
116
- const entries = [];
117
- const allFiles = new Set(meta.sourceFiles);
118
- for (const f of collectLaneFiles(dir)) allFiles.add(f);
119
- for (const file of allFiles) {
120
- const originalPath = resolve(root, file);
121
- const lanePath = join(dir, file);
122
- const origExists = existsSync(originalPath);
123
- const laneExists = existsSync(lanePath);
124
- if (!laneExists && origExists) {
125
- entries.push({ file, status: "deleted" });
126
- continue;
127
- }
128
- if (laneExists && !origExists) {
129
- const content = readFileSync(lanePath, "utf-8");
130
- entries.push({
131
- file,
132
- status: "added",
133
- diff: content.split("\n").map((l) => `+${l}`).join("\n")
134
- });
135
- continue;
136
- }
137
- if (!laneExists || !origExists) continue;
138
- const original = readFileSync(originalPath, "utf-8");
139
- const laneContent = readFileSync(lanePath, "utf-8");
140
- if (original === laneContent) {
141
- entries.push({ file, status: "unchanged" });
142
- } else {
143
- entries.push({
144
- file,
145
- status: "modified",
146
- diff: simpleDiff(original, laneContent)
147
- });
148
- }
149
- }
150
- return {
151
- name,
152
- entries,
153
- modified: entries.filter((e) => e.status === "modified").length,
154
- added: entries.filter((e) => e.status === "added").length,
155
- deleted: entries.filter((e) => e.status === "deleted").length
156
- };
157
- }
158
- function laneMerge(name, cwd) {
159
- const meta = readMeta(name, cwd);
160
- const dir = laneDir(name, cwd);
161
- const root = meta.rootPath;
162
- const merged = [];
163
- const allFiles = new Set(meta.sourceFiles);
164
- for (const f of collectLaneFiles(dir)) allFiles.add(f);
165
- for (const file of allFiles) {
166
- const lanePath = join(dir, file);
167
- if (!existsSync(lanePath)) continue;
168
- const destPath = resolve(root, file);
169
- mkdirSync(join(destPath, ".."), { recursive: true });
170
- cpSync(lanePath, destPath);
171
- merged.push(file);
172
- }
173
- rmSync(dir, { recursive: true, force: true });
174
- return {
175
- name,
176
- filesMerged: merged.length,
177
- files: merged
178
- };
179
- }
180
- function laneDiscard(name, cwd) {
181
- const dir = laneDir(name, cwd);
182
- if (!existsSync(dir)) return false;
183
- rmSync(dir, { recursive: true, force: true });
184
- return true;
185
- }
186
- function collectLaneFiles(dir) {
187
- const files = [];
188
- function visit(current) {
189
- for (const entry of readdirSync(current)) {
190
- if (entry === LANE_META) continue;
191
- const full = join(current, entry);
192
- if (statSync(full).isDirectory()) {
193
- visit(full);
194
- } else {
195
- files.push(relative(dir, full).replace(/\\/g, "/"));
196
- }
197
- }
198
- }
199
- if (existsSync(dir)) visit(dir);
200
- return files.sort();
201
- }
202
- function simpleDiff(original, modified) {
203
- const origLines = original.split("\n");
204
- const modLines = modified.split("\n");
205
- const result = [];
206
- const maxLen = Math.max(origLines.length, modLines.length);
207
- for (let i = 0; i < maxLen; i++) {
208
- const orig = origLines[i];
209
- const mod = modLines[i];
210
- if (orig === mod) {
211
- result.push(` ${orig ?? ""}`);
212
- } else {
213
- if (orig !== void 0) result.push(`-${orig}`);
214
- if (mod !== void 0) result.push(`+${mod}`);
215
- }
216
- }
217
- return result.join("\n");
218
- }
219
- export {
220
- laneCreate,
221
- laneDiff,
222
- laneDiscard,
223
- laneList,
224
- laneMerge,
225
- laneStatus
226
- };
227
- //# sourceMappingURL=lane.js.map
1
+ import{cpSync as F,existsSync as u,mkdirSync as S,readdirSync as E,readFileSync as g,rmSync as P,statSync as R,writeFileSync as A}from"node:fs";import{join as l,relative as v,resolve as h}from"node:path";const N=".kb-state/lanes",L=".lane-meta.json";function w(n){return h(n??process.cwd(),N)}function p(n,r){const s=w(r),i=h(s,n);if(!i.startsWith(h(s)))throw new Error(`Invalid lane name: "${n}"`);return i}function x(n,r){const s=l(p(n,r),L);if(!u(s))throw new Error(`Lane "${n}" does not exist`);return JSON.parse(g(s,"utf-8"))}function I(n,r,s){const i=s??process.cwd(),o=p(n,s);if(u(o))throw new Error(`Lane "${n}" already exists`);S(o,{recursive:!0});const e=[];for(const t of r){const a=h(i,t);if(!u(a))throw new Error(`Source file does not exist: ${t}`);const c=v(i,a).replace(/\\/g,"/"),d=l(o,c);S(l(d,".."),{recursive:!0}),F(a,d),e.push(c)}const f={name:n,createdAt:new Date().toISOString(),sourceFiles:e,rootPath:i};return A(l(o,L),`${JSON.stringify(f,null,2)}
2
+ `,"utf-8"),f}function J(n){const r=w(n);if(!u(r))return[];const s=E(r),i=[];for(const o of s){const e=l(r,o,L);u(e)&&i.push(JSON.parse(g(e,"utf-8")))}return i}function k(n,r){const s=x(n,r),i=p(n,r),o=s.rootPath,e=[];for(const t of s.sourceFiles){const a=h(o,t),c=l(i,t);if(!u(c)){e.push({file:t,status:"deleted"});continue}if(!u(a)){e.push({file:t,status:"added"});continue}const d=g(a,"utf-8"),m=g(c,"utf-8");d===m?e.push({file:t,status:"unchanged"}):e.push({file:t,status:"modified"})}const f=y(i);for(const t of f)s.sourceFiles.includes(t)||e.push({file:t,status:"added"});return{name:n,entries:e,modified:e.filter(t=>t.status==="modified").length,added:e.filter(t=>t.status==="added").length,deleted:e.filter(t=>t.status==="deleted").length}}function _(n,r){const s=x(n,r),i=p(n,r),o=s.rootPath,e=[],f=new Set(s.sourceFiles);for(const t of y(i))f.add(t);for(const t of f){const a=h(o,t),c=l(i,t),d=u(a),m=u(c);if(!m&&d){e.push({file:t,status:"deleted"});continue}if(m&&!d){const $=g(c,"utf-8");e.push({file:t,status:"added",diff:$.split(`
3
+ `).map(b=>`+${b}`).join(`
4
+ `)});continue}if(!m||!d)continue;const M=g(a,"utf-8"),D=g(c,"utf-8");M===D?e.push({file:t,status:"unchanged"}):e.push({file:t,status:"modified",diff:j(M,D)})}return{name:n,entries:e,modified:e.filter(t=>t.status==="modified").length,added:e.filter(t=>t.status==="added").length,deleted:e.filter(t=>t.status==="deleted").length}}function T(n,r){const s=x(n,r),i=p(n,r),o=s.rootPath,e=[],f=new Set(s.sourceFiles);for(const t of y(i))f.add(t);for(const t of f){const a=l(i,t);if(!u(a))continue;const c=h(o,t);S(l(c,".."),{recursive:!0}),F(a,c),e.push(t)}return P(i,{recursive:!0,force:!0}),{name:n,filesMerged:e.length,files:e}}function W(n,r){const s=p(n,r);return u(s)?(P(s,{recursive:!0,force:!0}),!0):!1}function y(n){const r=[];function s(i){for(const o of E(i)){if(o===L)continue;const e=l(i,o);R(e).isDirectory()?s(e):r.push(v(n,e).replace(/\\/g,"/"))}}return u(n)&&s(n),r.sort()}function j(n,r){const s=n.split(`
5
+ `),i=r.split(`
6
+ `),o=[],e=Math.max(s.length,i.length);for(let f=0;f<e;f++){const t=s[f],a=i[f];t===a?o.push(` ${t??""}`):(t!==void 0&&o.push(`-${t}`),a!==void 0&&o.push(`+${a}`))}return o.join(`
7
+ `)}export{I as laneCreate,_ as laneDiff,W as laneDiscard,J as laneList,T as laneMerge,k as laneStatus};
@@ -1,119 +1,2 @@
1
- import { readdirSync, readFileSync, statSync } from "node:fs";
2
- import { extname, join, relative } from "node:path";
3
- const EXCLUDE_DIRS = /* @__PURE__ */ new Set([
4
- "node_modules",
5
- ".git",
6
- "dist",
7
- "build",
8
- "coverage",
9
- ".turbo",
10
- "cdk.out",
11
- ".cache"
12
- ]);
13
- const BRANCH_PATTERNS = [
14
- /\bif\s*\(/g,
15
- /\belse\s+if\b/g,
16
- /\bfor\s*\(/g,
17
- /\bwhile\s*\(/g,
18
- /\bcase\s+/g,
19
- /\bcatch\s*\(/g,
20
- /&&/g,
21
- /\|\|/g,
22
- /\?\?/g
23
- ];
24
- function measure(options) {
25
- const { path: inputPath, extensions = [".ts", ".tsx", ".js", ".jsx"] } = options;
26
- const filePaths = collectFiles(inputPath, extensions);
27
- const files = filePaths.map((fp) => {
28
- const content = readFileSync(fp, "utf8");
29
- return analyzeFile(relative(process.cwd(), fp), content);
30
- });
31
- files.sort((a, b) => b.complexity - a.complexity);
32
- const totalLines = files.reduce((s, f) => s + f.lines.total, 0);
33
- const totalCode = files.reduce((s, f) => s + f.lines.code, 0);
34
- const totalComplexity = files.reduce((s, f) => s + f.complexity, 0);
35
- const totalFunctions = files.reduce((s, f) => s + f.functions, 0);
36
- const maxFile = files[0] ?? { path: "", complexity: 0 };
37
- return {
38
- files,
39
- summary: {
40
- totalFiles: files.length,
41
- totalLines,
42
- totalCodeLines: totalCode,
43
- avgComplexity: files.length > 0 ? Math.round(totalComplexity / files.length * 10) / 10 : 0,
44
- maxComplexity: { file: maxFile.path, value: maxFile.complexity },
45
- totalFunctions
46
- }
47
- };
48
- }
49
- function analyzeFile(path, content) {
50
- const lines = content.split("\n");
51
- let blank = 0;
52
- let comment = 0;
53
- let inBlock = false;
54
- for (const line of lines) {
55
- const trimmed = line.trim();
56
- if (trimmed === "") {
57
- blank++;
58
- continue;
59
- }
60
- if (inBlock) {
61
- comment++;
62
- if (trimmed.includes("*/")) inBlock = false;
63
- continue;
64
- }
65
- if (trimmed.startsWith("//")) {
66
- comment++;
67
- continue;
68
- }
69
- if (trimmed.startsWith("/*")) {
70
- comment++;
71
- inBlock = !trimmed.includes("*/");
72
- }
73
- }
74
- let complexity = 1;
75
- for (const pattern of BRANCH_PATTERNS) {
76
- const matches = content.match(pattern);
77
- if (matches) complexity += matches.length;
78
- }
79
- const fnKeyword = content.match(/\bfunction\b/g)?.length ?? 0;
80
- const arrowFns = content.match(/=>\s*[{(]/g)?.length ?? 0;
81
- const functions = fnKeyword + arrowFns;
82
- const imports = content.match(/^\s*import\s/gm)?.length ?? 0;
83
- const exports = content.match(/^\s*export\s/gm)?.length ?? 0;
84
- return {
85
- path,
86
- lines: { total: lines.length, code: lines.length - blank - comment, blank, comment },
87
- complexity,
88
- functions,
89
- imports,
90
- exports
91
- };
92
- }
93
- function collectFiles(inputPath, extensions) {
94
- try {
95
- if (statSync(inputPath).isFile()) return [inputPath];
96
- } catch {
97
- throw new Error(`Path not found: ${inputPath}`);
98
- }
99
- const files = [];
100
- function walk(dir) {
101
- for (const entry of readdirSync(dir)) {
102
- if (EXCLUDE_DIRS.has(entry)) continue;
103
- const full = join(dir, entry);
104
- if (statSync(full).isDirectory()) {
105
- walk(full);
106
- } else if (extensions.includes(extname(entry).toLowerCase())) {
107
- files.push(full);
108
- }
109
- }
110
- }
111
- walk(inputPath);
112
- files.sort();
113
- return files;
114
- }
115
- export {
116
- analyzeFile,
117
- measure
118
- };
119
- //# sourceMappingURL=measure.js.map
1
+ import{readdirSync as h,readFileSync as x,statSync as p}from"node:fs";import{extname as b,join as d,relative as y}from"node:path";const F=new Set(["node_modules",".git","dist","build","coverage",".turbo","cdk.out",".cache"]),C=[/\bif\s*\(/g,/\belse\s+if\b/g,/\bfor\s*\(/g,/\bwhile\s*\(/g,/\bcase\s+/g,/\bcatch\s*\(/g,/&&/g,/\|\|/g,/\?\?/g];function R(r){const{path:s,extensions:o=[".ts",".tsx",".js",".jsx"]}=r,t=M(s,o).map(e=>{const n=x(e,"utf8");return w(y(process.cwd(),e),n)});t.sort((e,n)=>n.complexity-e.complexity);const i=t.reduce((e,n)=>e+n.lines.total,0),l=t.reduce((e,n)=>e+n.lines.code,0),u=t.reduce((e,n)=>e+n.complexity,0),f=t.reduce((e,n)=>e+n.functions,0),m=t[0]??{path:"",complexity:0};return{files:t,summary:{totalFiles:t.length,totalLines:i,totalCodeLines:l,avgComplexity:t.length>0?Math.round(u/t.length*10)/10:0,maxComplexity:{file:m.path,value:m.complexity},totalFunctions:f}}}function w(r,s){const o=s.split(`
2
+ `);let a=0,t=0,i=!1;for(const g of o){const c=g.trim();if(c===""){a++;continue}if(i){t++,c.includes("*/")&&(i=!1);continue}if(c.startsWith("//")){t++;continue}c.startsWith("/*")&&(t++,i=!c.includes("*/"))}let l=1;for(const g of C){const c=s.match(g);c&&(l+=c.length)}const u=s.match(/\bfunction\b/g)?.length??0,f=s.match(/=>\s*[{(]/g)?.length??0,m=u+f,e=s.match(/^\s*import\s/gm)?.length??0,n=s.match(/^\s*export\s/gm)?.length??0;return{path:r,lines:{total:o.length,code:o.length-a-t,blank:a,comment:t},complexity:l,functions:m,imports:e,exports:n}}function M(r,s){try{if(p(r).isFile())return[r]}catch{throw new Error(`Path not found: ${r}`)}const o=[];function a(t){for(const i of h(t)){if(F.has(i))continue;const l=d(t,i);p(l).isDirectory()?a(l):s.includes(b(i).toLowerCase())&&o.push(l)}}return a(r),o.sort(),o}export{w as analyzeFile,R as measure};