codeimpact 0.4.0 → 0.4.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/dist/index.js CHANGED
@@ -8203,7 +8203,13 @@ var init_workspace2 = __esm({
8203
8203
  ".git/**",
8204
8204
  "coverage/**",
8205
8205
  ".next/**",
8206
- "build/**"
8206
+ "build/**",
8207
+ "venv/**",
8208
+ ".venv/**",
8209
+ "env/**",
8210
+ "__pycache__/**",
8211
+ "vendor/**",
8212
+ "knowledge/**"
8207
8213
  ],
8208
8214
  markers: {
8209
8215
  start: "<!-- code-impact:auto-start -->",
@@ -11379,22 +11385,31 @@ function parseYarnLock(lockPath) {
11379
11385
  }
11380
11386
  function detectFromManifests(projectPath) {
11381
11387
  const techs = [];
11382
- const pkgPath = join30(projectPath, "package.json");
11383
- if (existsSync29(pkgPath)) {
11384
- try {
11385
- const pkg = JSON.parse(readFileSync24(pkgPath, "utf-8"));
11386
- const allDeps = {
11387
- ...pkg.dependencies,
11388
- ...pkg.devDependencies
11389
- };
11390
- for (const [name, versionRange] of Object.entries(allDeps)) {
11391
- techs.push({
11392
- name,
11393
- version: cleanSemverRange(versionRange),
11394
- source: "package.json"
11395
- });
11388
+ const pkgPaths = [
11389
+ join30(projectPath, "package.json"),
11390
+ ...["frontend", "backend", "client", "server", "web", "app"].map((d) => join30(projectPath, d, "package.json"))
11391
+ ];
11392
+ const seenPkgs = /* @__PURE__ */ new Set();
11393
+ for (const pkgPath of pkgPaths) {
11394
+ if (existsSync29(pkgPath)) {
11395
+ try {
11396
+ const pkg = JSON.parse(readFileSync24(pkgPath, "utf-8"));
11397
+ const allDeps = {
11398
+ ...pkg.dependencies,
11399
+ ...pkg.devDependencies
11400
+ };
11401
+ for (const [name, versionRange] of Object.entries(allDeps)) {
11402
+ if (!seenPkgs.has(name)) {
11403
+ seenPkgs.add(name);
11404
+ techs.push({
11405
+ name,
11406
+ version: cleanSemverRange(versionRange),
11407
+ source: "package.json"
11408
+ });
11409
+ }
11410
+ }
11411
+ } catch {
11396
11412
  }
11397
- } catch {
11398
11413
  }
11399
11414
  }
11400
11415
  const reqPath = join30(projectPath, "requirements.txt");
@@ -11917,10 +11932,15 @@ var init_feature_detector = __esm({
11917
11932
  ".next",
11918
11933
  ".nuxt",
11919
11934
  ".output",
11920
- // Dependencies
11935
+ // Dependencies / virtual environments
11921
11936
  "node_modules",
11922
11937
  ".yarn",
11923
11938
  ".pnpm-store",
11939
+ "venv",
11940
+ ".venv",
11941
+ "env",
11942
+ "virtualenv",
11943
+ "ENV",
11924
11944
  // CI / config
11925
11945
  ".github",
11926
11946
  ".gitlab",
@@ -28307,8 +28327,21 @@ var EXCLUDED_PATH_PATTERNS = [
28307
28327
  ".pytest_cache",
28308
28328
  "vendor/",
28309
28329
  ".venv/",
28310
- "venv/"
28330
+ "venv/",
28331
+ "env/",
28332
+ "knowledge/"
28311
28333
  ];
28334
+ function PATH_EXCLUSION_SQL(col = "path") {
28335
+ return `${col} NOT LIKE '%node_modules%'
28336
+ AND ${col} NOT LIKE '%.git%'
28337
+ AND ${col} NOT LIKE '%/dist/%'
28338
+ AND ${col} NOT LIKE '%/build/%'
28339
+ AND ${col} NOT LIKE '%/venv/%'
28340
+ AND ${col} NOT LIKE '%/.venv/%'
28341
+ AND ${col} NOT LIKE '%/env/%'
28342
+ AND ${col} NOT LIKE '%__pycache__%'
28343
+ AND ${col} NOT LIKE '%/knowledge/%'`;
28344
+ }
28312
28345
  var Tier2Storage = class {
28313
28346
  db;
28314
28347
  constructor(db) {
@@ -28365,10 +28398,7 @@ var Tier2Storage = class {
28365
28398
  size_bytes as sizeBytes, line_count as lineCount,
28366
28399
  last_modified as lastModified, indexed_at as indexedAt
28367
28400
  FROM files
28368
- WHERE path NOT LIKE '%node_modules%'
28369
- AND path NOT LIKE '%.git%'
28370
- AND path NOT LIKE '%/dist/%'
28371
- AND path NOT LIKE '%/build/%'
28401
+ WHERE ${PATH_EXCLUSION_SQL("path")}
28372
28402
  ORDER BY path
28373
28403
  `);
28374
28404
  return stmt.all();
@@ -28376,10 +28406,7 @@ var Tier2Storage = class {
28376
28406
  getFileCount() {
28377
28407
  const stmt = this.db.prepare(`
28378
28408
  SELECT COUNT(*) as count FROM files
28379
- WHERE path NOT LIKE '%node_modules%'
28380
- AND path NOT LIKE '%.git%'
28381
- AND path NOT LIKE '%/dist/%'
28382
- AND path NOT LIKE '%/build/%'
28409
+ WHERE ${PATH_EXCLUSION_SQL("path")}
28383
28410
  `);
28384
28411
  const result = stmt.get();
28385
28412
  return result.count;
@@ -28387,10 +28414,7 @@ var Tier2Storage = class {
28387
28414
  getTotalLines() {
28388
28415
  const stmt = this.db.prepare(`
28389
28416
  SELECT COALESCE(SUM(line_count), 0) as total FROM files
28390
- WHERE path NOT LIKE '%node_modules%'
28391
- AND path NOT LIKE '%.git%'
28392
- AND path NOT LIKE '%/dist/%'
28393
- AND path NOT LIKE '%/build/%'
28417
+ WHERE ${PATH_EXCLUSION_SQL("path")}
28394
28418
  `);
28395
28419
  const result = stmt.get();
28396
28420
  return result.total;
@@ -28399,10 +28423,7 @@ var Tier2Storage = class {
28399
28423
  const stmt = this.db.prepare(`
28400
28424
  SELECT DISTINCT language FROM files
28401
28425
  WHERE language IS NOT NULL
28402
- AND path NOT LIKE '%node_modules%'
28403
- AND path NOT LIKE '%.git%'
28404
- AND path NOT LIKE '%/dist/%'
28405
- AND path NOT LIKE '%/build/%'
28426
+ AND ${PATH_EXCLUSION_SQL("path")}
28406
28427
  ORDER BY language
28407
28428
  `);
28408
28429
  const results = stmt.all();
@@ -28740,10 +28761,7 @@ var Tier2Storage = class {
28740
28761
  FROM symbols s
28741
28762
  JOIN files f ON s.file_id = f.id
28742
28763
  WHERE s.name LIKE ?
28743
- AND f.path NOT LIKE '%node_modules%'
28744
- AND f.path NOT LIKE '%.git%'
28745
- AND f.path NOT LIKE '%/dist/%'
28746
- AND f.path NOT LIKE '%/build/%'
28764
+ AND ${PATH_EXCLUSION_SQL("f.path")}
28747
28765
  `;
28748
28766
  const params = [`%${name}%`];
28749
28767
  if (kind) {
@@ -28774,10 +28792,7 @@ var Tier2Storage = class {
28774
28792
  FROM symbols s
28775
28793
  JOIN files f ON s.file_id = f.id
28776
28794
  WHERE s.name = ?
28777
- AND f.path NOT LIKE '%node_modules%'
28778
- AND f.path NOT LIKE '%.git%'
28779
- AND f.path NOT LIKE '%/dist/%'
28780
- AND f.path NOT LIKE '%/build/%'
28795
+ AND ${PATH_EXCLUSION_SQL("f.path")}
28781
28796
  `;
28782
28797
  const params = [name];
28783
28798
  if (kind) {
@@ -28805,10 +28820,7 @@ var Tier2Storage = class {
28805
28820
  const stmt = this.db.prepare(`
28806
28821
  SELECT COUNT(*) as count FROM symbols s
28807
28822
  JOIN files f ON s.file_id = f.id
28808
- WHERE f.path NOT LIKE '%node_modules%'
28809
- AND f.path NOT LIKE '%.git%'
28810
- AND f.path NOT LIKE '%/dist/%'
28811
- AND f.path NOT LIKE '%/build/%'
28823
+ WHERE ${PATH_EXCLUSION_SQL("f.path")}
28812
28824
  `);
28813
28825
  const result = stmt.get();
28814
28826
  return result.count;
@@ -28920,10 +28932,7 @@ var Tier2Storage = class {
28920
28932
  e.local_name as localName, e.is_default as isDefault, e.line_number as lineNumber
28921
28933
  FROM exports e
28922
28934
  JOIN files f ON e.file_id = f.id
28923
- WHERE f.path NOT LIKE '%node_modules%'
28924
- AND f.path NOT LIKE '%.git%'
28925
- AND f.path NOT LIKE '%/dist/%'
28926
- AND f.path NOT LIKE '%/build/%'
28935
+ WHERE ${PATH_EXCLUSION_SQL("f.path")}
28927
28936
  ORDER BY f.path, e.line_number
28928
28937
  `);
28929
28938
  const rows = stmt.all();
@@ -28947,10 +28956,7 @@ var Tier2Storage = class {
28947
28956
  i.is_namespace as isNamespace, i.line_number as lineNumber
28948
28957
  FROM imports i
28949
28958
  JOIN files f ON i.file_id = f.id
28950
- WHERE f.path NOT LIKE '%node_modules%'
28951
- AND f.path NOT LIKE '%.git%'
28952
- AND f.path NOT LIKE '%/dist/%'
28953
- AND f.path NOT LIKE '%/build/%'
28959
+ WHERE ${PATH_EXCLUSION_SQL("f.path")}
28954
28960
  ORDER BY f.path, i.line_number
28955
28961
  `);
28956
28962
  const rows = stmt.all();
@@ -29154,12 +29160,69 @@ var Tier2Storage = class {
29154
29160
  );
29155
29161
  return result?.path || null;
29156
29162
  }
29163
+ // Cached path aliases from tsconfig/jsconfig
29164
+ pathAliases = null;
29165
+ /**
29166
+ * Load path aliases from tsconfig.json/jsconfig.json.
29167
+ * Caches result for subsequent calls.
29168
+ */
29169
+ getPathAliases(projectPath) {
29170
+ if (this.pathAliases) return this.pathAliases;
29171
+ this.pathAliases = /* @__PURE__ */ new Map();
29172
+ const commonAliases = {
29173
+ "@": "src",
29174
+ "~": "src",
29175
+ "#": "src"
29176
+ };
29177
+ for (const [alias, target] of Object.entries(commonAliases)) {
29178
+ this.pathAliases.set(alias, target);
29179
+ }
29180
+ if (projectPath) {
29181
+ const { existsSync: existsSync38, readFileSync: readFileSync31 } = __require("fs");
29182
+ const { join: join39 } = __require("path");
29183
+ for (const configFile of ["tsconfig.json", "jsconfig.json"]) {
29184
+ const configPath = join39(projectPath, configFile);
29185
+ if (existsSync38(configPath)) {
29186
+ try {
29187
+ const raw = readFileSync31(configPath, "utf-8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
29188
+ const config2 = JSON.parse(raw);
29189
+ const baseUrl = config2.compilerOptions?.baseUrl || ".";
29190
+ if (config2.compilerOptions?.paths) {
29191
+ for (const [alias, targets] of Object.entries(config2.compilerOptions.paths)) {
29192
+ const aliasKey = alias.replace("/*", "").replace("*", "");
29193
+ const target = targets[0];
29194
+ if (target) {
29195
+ const targetPath = target.replace("/*", "").replace("*", "").replace("./", "");
29196
+ const resolved = baseUrl === "." ? targetPath : `${baseUrl}/${targetPath}`;
29197
+ this.pathAliases.set(aliasKey, resolved);
29198
+ }
29199
+ }
29200
+ }
29201
+ break;
29202
+ } catch {
29203
+ }
29204
+ }
29205
+ }
29206
+ }
29207
+ return this.pathAliases;
29208
+ }
29157
29209
  /**
29158
29210
  * Resolve an import path to a file record in the database.
29159
29211
  * Used by indexer to build the dependencies table.
29160
29212
  */
29161
- resolveImportToFile(sourceFilePath, importPath) {
29162
- if (!importPath.startsWith(".") && !importPath.startsWith("/")) return null;
29213
+ resolveImportToFile(sourceFilePath, importPath, projectPath) {
29214
+ if (!importPath.startsWith(".") && !importPath.startsWith("/")) {
29215
+ const aliases = this.getPathAliases(projectPath);
29216
+ let resolved2 = false;
29217
+ for (const [alias, target] of aliases) {
29218
+ if (importPath === alias || importPath.startsWith(alias + "/")) {
29219
+ importPath = importPath.replace(alias, target);
29220
+ resolved2 = true;
29221
+ break;
29222
+ }
29223
+ }
29224
+ if (!resolved2) return null;
29225
+ }
29163
29226
  const sourceDir = sourceFilePath.split(/[/\\]/).slice(0, -1).join("/");
29164
29227
  let resolved = importPath;
29165
29228
  if (importPath.startsWith("./")) {
@@ -30480,7 +30543,7 @@ var Indexer = class extends EventEmitter2 {
30480
30543
  language,
30481
30544
  stats.size,
30482
30545
  lineCount,
30483
- Math.floor(stats.mtimeMs)
30546
+ Math.floor(stats.mtimeMs / 1e3)
30484
30547
  );
30485
30548
  const embedding = await this.embeddingGenerator.embed(content);
30486
30549
  this.tier2.upsertEmbedding(fileId, embedding);
@@ -30505,7 +30568,7 @@ var Indexer = class extends EventEmitter2 {
30505
30568
  if (parsed.imports.length > 0) {
30506
30569
  this.tier2.clearDependencies(fileId);
30507
30570
  for (const imp of parsed.imports) {
30508
- const targetFile = this.tier2.resolveImportToFile(relativePath, imp.importedFrom);
30571
+ const targetFile = this.tier2.resolveImportToFile(relativePath, imp.importedFrom, this.config.projectPath);
30509
30572
  if (targetFile) {
30510
30573
  this.tier2.addDependency(fileId, targetFile.id, "imports");
30511
30574
  }
@@ -31024,7 +31087,18 @@ ${body}`.trim();
31024
31087
  async extractFromComments() {
31025
31088
  const decisions = [];
31026
31089
  const patterns = ["**/*.ts", "**/*.js", "**/*.py", "**/*.go", "**/*.java", "**/*.rs"];
31027
- const ignorePatterns = ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/build/**"];
31090
+ const ignorePatterns = [
31091
+ "**/node_modules/**",
31092
+ "**/.git/**",
31093
+ "**/dist/**",
31094
+ "**/build/**",
31095
+ "**/venv/**",
31096
+ "**/.venv/**",
31097
+ "**/env/**",
31098
+ "**/__pycache__/**",
31099
+ "**/vendor/**",
31100
+ "**/knowledge/**"
31101
+ ];
31028
31102
  for (const pattern of patterns) {
31029
31103
  try {
31030
31104
  const files = await glob2(pattern, {
@@ -31075,7 +31149,7 @@ ${body}`.trim();
31075
31149
  try {
31076
31150
  const files = await glob2(pattern, {
31077
31151
  cwd: this.projectPath,
31078
- ignore: ["**/node_modules/**"],
31152
+ ignore: ["**/node_modules/**", "**/venv/**", "**/.venv/**", "**/env/**", "**/knowledge/**"],
31079
31153
  absolute: true,
31080
31154
  nodir: true
31081
31155
  });
@@ -31927,6 +32001,12 @@ var ProjectManager = class {
31927
32001
  "**/build/**",
31928
32002
  "**/.next/**",
31929
32003
  "**/coverage/**",
32004
+ "**/venv/**",
32005
+ "**/.venv/**",
32006
+ "**/env/**",
32007
+ "**/__pycache__/**",
32008
+ "**/vendor/**",
32009
+ "**/knowledge/**",
31930
32010
  "**/*.min.js",
31931
32011
  "**/*.min.css",
31932
32012
  "**/*.map",
@@ -34538,8 +34618,11 @@ ${decisionList}
34538
34618
  const rows = this.db.prepare(
34539
34619
  `SELECT path FROM files WHERE language IS NOT NULL`
34540
34620
  ).all();
34621
+ const excludeDirs = ["knowledge/", ".code-impact/", "node_modules/", "venv/", ".venv/", "env/", "__pycache__/"];
34541
34622
  for (const row of rows) {
34542
- const parts = row.path.replace(/\\/g, "/").split("/");
34623
+ const normalized = row.path.replace(/\\/g, "/");
34624
+ if (excludeDirs.some((d) => normalized.includes(d))) continue;
34625
+ const parts = normalized.split("/");
34543
34626
  if (parts.length < 2) continue;
34544
34627
  const dir = parts.slice(0, -1).join("/");
34545
34628
  const existing = groups.get(dir) || [];
@@ -41333,6 +41416,7 @@ var CodeVerifier = class {
41333
41416
  this.nodeModulesPath = join15(projectPath, "node_modules");
41334
41417
  this.loadPackageJson();
41335
41418
  }
41419
+ subPackageJsons = [];
41336
41420
  loadPackageJson() {
41337
41421
  const packageJsonPath = join15(this.projectPath, "package.json");
41338
41422
  if (existsSync16(packageJsonPath)) {
@@ -41342,6 +41426,16 @@ var CodeVerifier = class {
41342
41426
  this.packageJson = null;
41343
41427
  }
41344
41428
  }
41429
+ const subDirs = ["frontend", "backend", "client", "server", "web", "app", "packages"];
41430
+ for (const sub of subDirs) {
41431
+ const subPath = join15(this.projectPath, sub, "package.json");
41432
+ if (existsSync16(subPath)) {
41433
+ try {
41434
+ this.subPackageJsons.push(JSON.parse(readFileSync12(subPath, "utf-8")));
41435
+ } catch {
41436
+ }
41437
+ }
41438
+ }
41345
41439
  }
41346
41440
  /**
41347
41441
  * Run full verification on code
@@ -41729,15 +41823,17 @@ var CodeVerifier = class {
41729
41823
  }
41730
41824
  getPackageDependencies() {
41731
41825
  const deps = /* @__PURE__ */ new Set();
41732
- if (!this.packageJson) return deps;
41733
- const allDeps = {
41734
- ...this.packageJson.dependencies || {},
41735
- ...this.packageJson.devDependencies || {},
41736
- ...this.packageJson.peerDependencies || {},
41737
- ...this.packageJson.optionalDependencies || {}
41738
- };
41739
- for (const pkg of Object.keys(allDeps)) {
41740
- deps.add(pkg);
41826
+ const pkgs = this.packageJson ? [this.packageJson, ...this.subPackageJsons] : this.subPackageJsons;
41827
+ for (const pkg of pkgs) {
41828
+ const allDeps = {
41829
+ ...pkg.dependencies || {},
41830
+ ...pkg.devDependencies || {},
41831
+ ...pkg.peerDependencies || {},
41832
+ ...pkg.optionalDependencies || {}
41833
+ };
41834
+ for (const name of Object.keys(allDeps)) {
41835
+ deps.add(name);
41836
+ }
41741
41837
  }
41742
41838
  return deps;
41743
41839
  }
@@ -44299,7 +44395,6 @@ var PlatformRuleSync = class {
44299
44395
  results.push(writeManagedFile(join17(this.projectPath, ".cursor", "rules", "codeimpact.mdc"), cursorSection, options));
44300
44396
  const claudeSection = renderPlatformSection("claude", paths, skillIndex, guidance);
44301
44397
  results.push(writeManagedFile(join17(this.projectPath, "CLAUDE.md"), claudeSection, options));
44302
- results.push(writeManagedFile(join17(this.projectPath, "Cloud.md"), claudeSection, options));
44303
44398
  const codexSection = renderPlatformSection("codex", paths, skillIndex, guidance);
44304
44399
  results.push(writeManagedFile(join17(this.projectPath, "AGENTS.md"), codexSection, options));
44305
44400
  results.push(writeManagedFile(join17(this.projectPath, "CODEX.md"), codexSection, options));
@@ -54157,7 +54252,7 @@ function getDefaultConfig(projectPath) {
54157
54252
  watchIgnore: [
54158
54253
  // ===== CodeImpact =====
54159
54254
  "**/.codeimpact/**",
54160
- "**/.codeimpact/**",
54255
+ "**/knowledge/**",
54161
54256
  // ===== Version Control =====
54162
54257
  "**/.git/**",
54163
54258
  "**/.svn/**",