@titan-design/code-graph 0.4.0 → 0.6.0

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/README.md CHANGED
@@ -27,8 +27,8 @@ In: the parser (tree-sitter WASM for TypeScript, TSX and Python, since moved to
27
27
  `@titan-design/code-parser` and still re-exported here), the walk, the ts-morph
28
28
  extractor and its symbol layer, role classification, generated-file detection, id aliasing
29
29
  across git renames, the three-tier incremental reuse, and the metrics computed at index time
30
- (degree, utilization, loc, cyclomatic, cognitive, nesting, class count, lcom4, per-symbol
31
- complexity). `lcom.ts` came along despite being an analysis: `source-metrics.ts` calls it
30
+ (degree, utilization, loc, cyclomatic, cognitive, nesting, class count, lcom4, and per
31
+ symbol `symbol_cognitive`, `symbol_cyclomatic`, `symbol_loc` and `symbol_max_nesting`). `lcom.ts` came along despite being an analysis: `source-metrics.ts` calls it
32
32
  directly and lcom4 is a pure function of a file's bytes, so it belongs with the metrics that
33
33
  carry forward under reuse.
34
34
 
@@ -307,8 +307,11 @@ Dead-code and growth-risk metrics are computed at index time, like the source me
307
307
  carry forward for unchanged files. Both are sparse: a file gets a row only when a count is
308
308
  above zero.
309
309
 
310
- - Dead code, TypeScript only: `unreachable_statements` (after a `return`, `throw`, `break`
311
- or `continue` in the same block), `unused_locals`, and `unused_params` (trailing run only).
310
+ - Dead code, TypeScript and Python: `unreachable_statements` (after a `return`, `throw` or
311
+ `raise`, `break` or `continue` in the same block), `unused_locals`, and `unused_params`
312
+ (trailing run only). Python skips `self`, `cls`, `_`-prefixed names, `global` and
313
+ `nonlocal` names, and the parameters of stub bodies such as `@overload` signatures; a
314
+ `*args` or `**kwargs` ends the trailing run.
312
315
  - Growth risk, TypeScript and Python: `loop_depth` (at 2 or more), `recursive_functions`,
313
316
  and `search_in_loop` (`.includes`, `.find` and similar inside a loop). These are smells,
314
317
  not complexity bounds. Recursion and search match TypeScript call nodes only, so Python
package/dist/index.d.ts CHANGED
@@ -205,7 +205,7 @@ declare function runPrune(store: CodeGraphStore, options?: PruneOptions & {
205
205
  * index version is never reused, so a change to node/edge shape or to a metric's
206
206
  * value for the same bytes can never be carried forward from an incompatible graph.
207
207
  */
208
- declare const INDEX_VERSION = "0.15.0";
208
+ declare const INDEX_VERSION = "0.16.0";
209
209
  interface IndexOptions {
210
210
  /** Roots to walk. Node ids are still rooted at the git toplevel, so importers across roots share an id space. */
211
211
  paths: string[];
@@ -779,10 +779,10 @@ declare function buildIndexerMetrics(input: IndexerMetricsInput): GraphMetric[];
779
779
  */
780
780
  declare const DEAD_CODE_METRIC_NAMES: ReadonlySet<string>;
781
781
  /**
782
- * Per-file dead-code metrics for TypeScript files. Emitted sparsely — only when
783
- * a count is > 0 — so a clean file adds no rows (a full index and an incremental
784
- * re-index therefore produce the identical metric set). Non-TypeScript files are
785
- * skipped for now.
782
+ * Per-file dead-code metrics for TypeScript and Python files (Python since
783
+ * TP-318, in dead-code-python.ts). Emitted sparsely — only when a count is > 0 —
784
+ * so a clean file adds no rows (a full index and an incremental re-index
785
+ * therefore produce the identical metric set). Other languages are skipped.
786
786
  */
787
787
  declare function computeDeadCodeMetrics(files: readonly ParsedFile[], fileIdOf: (filePath: string) => string): GraphMetric[];
788
788
 
@@ -1206,6 +1206,14 @@ interface CheckViolation {
1206
1206
  threshold?: number;
1207
1207
  destinationId?: string;
1208
1208
  isCarryover?: boolean;
1209
+ /** Repo-relative file the violation sits in; a symbol's parent file. */
1210
+ path?: string;
1211
+ lineStart?: number;
1212
+ lineEnd?: number;
1213
+ symbol?: string;
1214
+ /** One line a reader can check without re-running the rule, such as `loc=412 (max 350)`. */
1215
+ evidence?: string;
1216
+ tool?: string;
1209
1217
  }
1210
1218
  interface CheckResult {
1211
1219
  snapshotId: number;
@@ -1236,6 +1244,34 @@ declare function violationKey(v: CheckViolation): string;
1236
1244
  /** {@link violationKey} with both node ids carried into another snapshot's id space; unmoved ids key as before. */
1237
1245
  declare function rebasedViolationKey(v: CheckViolation, resolve: (id: string) => string): string;
1238
1246
 
1247
+ /** One tool-neutral audit finding; every finding cites a path so a citation checker can verify it. */
1248
+ interface Finding {
1249
+ id: string;
1250
+ path: string;
1251
+ lineStart?: number;
1252
+ lineEnd?: number;
1253
+ symbol?: string;
1254
+ signal: string;
1255
+ value?: number;
1256
+ baseline?: number;
1257
+ threshold?: number;
1258
+ severity: Severity;
1259
+ evidence?: string;
1260
+ tool: string;
1261
+ }
1262
+ /** A diagnostic from an outside linter, shaped structurally so no linter package is imported. */
1263
+ interface ExternalDiagnostic {
1264
+ tool: string;
1265
+ rule: string;
1266
+ file: string;
1267
+ line: number;
1268
+ endLine?: number;
1269
+ message: string;
1270
+ severity: "error" | "warning";
1271
+ }
1272
+ declare function toFindings(result: CheckResult): Finding[];
1273
+ declare function externalToFinding(input: ExternalDiagnostic): Finding;
1274
+
1239
1275
  /** Glob when the pattern has a `*` (`**` crosses directories, `*` stays in a segment); otherwise a case-sensitive substring. */
1240
1276
  declare function patternToRegex(pattern: string): RegExp;
1241
1277
  declare function compilePatterns(patterns: readonly string[] | undefined): RegExp[];
@@ -1552,4 +1588,4 @@ declare function getConventionMap(store: CodeGraphStore, snapshotId: number, mod
1552
1588
  */
1553
1589
  declare function findConventions(store: CodeGraphStore, snapshotId: number, query: string, embedder: Embedder, model: string, opts?: FindConventionsOptions): Promise<ConventionQueryResult>;
1554
1590
 
1555
- export { ALIAS_BASE_ATTR, ALL_ROLES, type AliasChain, type AliasChainInput, type AliasChainOptions, type AliasLoader, type AliasResolution, COMMUNITY_SUMMARY_NAMESPACE, COVERAGE_METRIC_NAME, type CachedEmbedResult, type CheckDiff, type CheckResult, type CheckRule, type CheckRulesFile, type CheckSnapshotOptions, type CheckSnapshotResult, type CheckViolation, CodeGraphStore, type ConventionArea, type ConventionCorpus, type ConventionCoverage, type ConventionMap, type ConventionMatch, type ConventionOptions, type ConventionQueryResult, type ConventionSymbol, DEAD_CODE_METRIC_NAMES, DEFAULT_CHURN_WINDOWS, DOMAIN_DDL, type DeepAst, type DeepAstInput, type DiffCheckResultsOptions, type DiffSnapshotsOptions, type EdgeKind, type EmbedAttempt, type EmbedCoverage, type EmbedSnapshotResult, type EmbeddableSymbol, type FileFingerprint, type FindConventionsOptions, type FindSimilarOptions, type ForbidImportRule, GROWTH_RISK_METRIC_NAMES, type GraphDiff, type GraphDiffSummary, type GraphEdge, type GraphFragment, type GraphMetric, type GraphNode, type HistoryMetricsOptions, INDEX_VERSION, type IdAlias, type IdAliasReason, type IndexOptions, type IndexResult, type IstanbulCoverage, KIT, LanguageExtractor, type LanguageExtractorOptions, type LayeredDepsRule, type LineSpan, type Lineage, type LineageSnapshot, type LineageStep, type LinkMethod, type LinkTestsOptions, type LoadedHistory, METRIC_CATALOGUE, MIGRATIONS, type MemberInfo, type MetricAbsence, type MetricAggregate, type MetricDelta, type MetricDescriptor, type MetricDirection, type MetricMaxRule, type MetricMinRule, type MetricProductMaxRule, type MetricRollup, type MetricSource, type MetricUnit, type NoInternalOnlyBarrelsRule, type NodeKind, type NodeRename, type NodeRole, type PackageFlag, type PackageLayer, type PackageStats, type PageRankOptions, type PageRankResult, type PageRankRow, type PairCoupling, type PairFlag, type ParamInfo, type PartitionQualityInput, type PartitionQualityResult, type PriorSnapshotOptions, type PruneOptions, type PrunePlan, type PruneResult, PythonGraphExtractor, type ReadFile, type ReferenceEdgeLite, type RelevanceOptions, type ResolveAliasOptions, type ReuseBasis, type RuleStore, type RunChecksOptions, SCHEMA_VERSION, SNAPSHOT_SCOPED_TABLES, SOURCE_METRIC_NAMES, SYMBOL_EMBEDDING_NAMESPACE, SYMBOL_ID_SEP, type Severity, type SimilarCandidate, type SimilarResult, type SnapshotInsert, type SnapshotRow, type SnapshotSpec, type SourceLanguage, type SummarizeConventionsResult, type Summarizer, type SymbolConsumers, type SymbolCouplingOptions, type SymbolCouplingPair, type SymbolSpan, type TestCoverageOwnershipOptions, type TestSourceLink, type TopMetricRow, TsMorphGraphExtractor, type TsMorphGraphExtractorOptions, type UnchangedViolation, type ValidateRulesOptions, aggregateMetrics, aliasChain, annotateRoles, attributeCoverage, buildAliases, buildConventionAreas, buildEmbedText, buildFileModuleNodes, buildIndexerMetrics, buildLineage, canonicalEdgeKind, canonicalMetricName, canonicalRole, checkSnapshot, classifyRole, collectDeclaredNames, collectDeclaredSpans, compilePatterns, computeDeadCodeMetrics, computeDeepAst, computeGrowthRiskMetrics, computeMetrics, computePageRank, computePartitionQuality, computeRecencyWindows, computeRelevance, computeRoleHints, computeSourceMetrics, computeSymbolConsumers, computeSymbolCoupling, computeTestCoverageOwnership, createAliasChain, defaultTargetCount, describeMetric, describeMetrics, detectCommunities, detectGitHead, detectGitToplevel, detectRenames, diffCheckResults, diffSnapshots, edgeWeight, embedSnapshot, embedTextsCached, externalId, fileId, findConventions, findSimilarCapability, getConventionMap, getEdgeWeight, groupTestsBySource, hashContent, hashEmbedText, indexPaths, invertBuckets, isGeneratedByHeuristic, isGeneratedFile, isInsideGitRepo, lineagePath, linkTestsToSources, listEdges, listEdgesTouching, listEmbeddableSymbols, listMetrics, listMetricsForNode, listNodes, loadCheckRules, loadGeneratedPatterns, loadHistoryMetrics, loadLineage, matchesAny, moduleId, openCodeGraph, packageId, parentModuleId, parseSymbolId, patternToRegex, planPrune, priorSnapshotForRef, pruneDanglingReferences, readSourceFiles, rebasedViolationKey, resolveAlias, resolveBarrelEdges, resolveChurnWindows, resolveGitRef, resolveSnapshot, runChecks, runPrune, snapshotPageRank, snapshotReferenceEdges, snapshotRelevance, snapshotSymbolConsumers, snapshotSymbolCoupling, snapshotViolations, structuralSignature, summarizeConventions, symbolId, testCoverageCountMetrics, tryEmbedSnapshot, validateRules, violationKey, walkSourceFiles, windowSuffix };
1591
+ export { ALIAS_BASE_ATTR, ALL_ROLES, type AliasChain, type AliasChainInput, type AliasChainOptions, type AliasLoader, type AliasResolution, COMMUNITY_SUMMARY_NAMESPACE, COVERAGE_METRIC_NAME, type CachedEmbedResult, type CheckDiff, type CheckResult, type CheckRule, type CheckRulesFile, type CheckSnapshotOptions, type CheckSnapshotResult, type CheckViolation, CodeGraphStore, type ConventionArea, type ConventionCorpus, type ConventionCoverage, type ConventionMap, type ConventionMatch, type ConventionOptions, type ConventionQueryResult, type ConventionSymbol, DEAD_CODE_METRIC_NAMES, DEFAULT_CHURN_WINDOWS, DOMAIN_DDL, type DeepAst, type DeepAstInput, type DiffCheckResultsOptions, type DiffSnapshotsOptions, type EdgeKind, type EmbedAttempt, type EmbedCoverage, type EmbedSnapshotResult, type EmbeddableSymbol, type ExternalDiagnostic, type FileFingerprint, type FindConventionsOptions, type FindSimilarOptions, type Finding, type ForbidImportRule, GROWTH_RISK_METRIC_NAMES, type GraphDiff, type GraphDiffSummary, type GraphEdge, type GraphFragment, type GraphMetric, type GraphNode, type HistoryMetricsOptions, INDEX_VERSION, type IdAlias, type IdAliasReason, type IndexOptions, type IndexResult, type IstanbulCoverage, KIT, LanguageExtractor, type LanguageExtractorOptions, type LayeredDepsRule, type LineSpan, type Lineage, type LineageSnapshot, type LineageStep, type LinkMethod, type LinkTestsOptions, type LoadedHistory, METRIC_CATALOGUE, MIGRATIONS, type MemberInfo, type MetricAbsence, type MetricAggregate, type MetricDelta, type MetricDescriptor, type MetricDirection, type MetricMaxRule, type MetricMinRule, type MetricProductMaxRule, type MetricRollup, type MetricSource, type MetricUnit, type NoInternalOnlyBarrelsRule, type NodeKind, type NodeRename, type NodeRole, type PackageFlag, type PackageLayer, type PackageStats, type PageRankOptions, type PageRankResult, type PageRankRow, type PairCoupling, type PairFlag, type ParamInfo, type PartitionQualityInput, type PartitionQualityResult, type PriorSnapshotOptions, type PruneOptions, type PrunePlan, type PruneResult, PythonGraphExtractor, type ReadFile, type ReferenceEdgeLite, type RelevanceOptions, type ResolveAliasOptions, type ReuseBasis, type RuleStore, type RunChecksOptions, SCHEMA_VERSION, SNAPSHOT_SCOPED_TABLES, SOURCE_METRIC_NAMES, SYMBOL_EMBEDDING_NAMESPACE, SYMBOL_ID_SEP, type Severity, type SimilarCandidate, type SimilarResult, type SnapshotInsert, type SnapshotRow, type SnapshotSpec, type SourceLanguage, type SummarizeConventionsResult, type Summarizer, type SymbolConsumers, type SymbolCouplingOptions, type SymbolCouplingPair, type SymbolSpan, type TestCoverageOwnershipOptions, type TestSourceLink, type TopMetricRow, TsMorphGraphExtractor, type TsMorphGraphExtractorOptions, type UnchangedViolation, type ValidateRulesOptions, aggregateMetrics, aliasChain, annotateRoles, attributeCoverage, buildAliases, buildConventionAreas, buildEmbedText, buildFileModuleNodes, buildIndexerMetrics, buildLineage, canonicalEdgeKind, canonicalMetricName, canonicalRole, checkSnapshot, classifyRole, collectDeclaredNames, collectDeclaredSpans, compilePatterns, computeDeadCodeMetrics, computeDeepAst, computeGrowthRiskMetrics, computeMetrics, computePageRank, computePartitionQuality, computeRecencyWindows, computeRelevance, computeRoleHints, computeSourceMetrics, computeSymbolConsumers, computeSymbolCoupling, computeTestCoverageOwnership, createAliasChain, defaultTargetCount, describeMetric, describeMetrics, detectCommunities, detectGitHead, detectGitToplevel, detectRenames, diffCheckResults, diffSnapshots, edgeWeight, embedSnapshot, embedTextsCached, externalId, externalToFinding, fileId, findConventions, findSimilarCapability, getConventionMap, getEdgeWeight, groupTestsBySource, hashContent, hashEmbedText, indexPaths, invertBuckets, isGeneratedByHeuristic, isGeneratedFile, isInsideGitRepo, lineagePath, linkTestsToSources, listEdges, listEdgesTouching, listEmbeddableSymbols, listMetrics, listMetricsForNode, listNodes, loadCheckRules, loadGeneratedPatterns, loadHistoryMetrics, loadLineage, matchesAny, moduleId, openCodeGraph, packageId, parentModuleId, parseSymbolId, patternToRegex, planPrune, priorSnapshotForRef, pruneDanglingReferences, readSourceFiles, rebasedViolationKey, resolveAlias, resolveBarrelEdges, resolveChurnWindows, resolveGitRef, resolveSnapshot, runChecks, runPrune, snapshotPageRank, snapshotReferenceEdges, snapshotRelevance, snapshotSymbolConsumers, snapshotSymbolCoupling, snapshotViolations, structuralSignature, summarizeConventions, symbolId, testCoverageCountMetrics, toFindings, tryEmbedSnapshot, validateRules, violationKey, walkSourceFiles, windowSuffix };