Repository navigation
feat(ci,scripts): add Go and TypeScript similarity advisories to codequality - #1270
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an AST-normalized function similarity checking feature to the 'codequality' tool for both Go and TypeScript, leveraging Vertex AI ('gemini-embedding-2') and a local SQLite-backed vector cache to detect duplicate logic. A valid issue was identified in 'vertex.go' where slicing 'item.text' directly by byte index could cut a multi-byte UTF-8 character in half, and a code suggestion was provided to safely truncate the string using runes.
| } | ||
|
|
||
| func (c *VertexClient) embedSingle(ctx context.Context, item pendingItem) (CacheEntry, error) { | ||
| trimmed := item.text[:min(len(item.text), maxInstanceChars)] |
There was a problem hiding this comment.
Slicing item.text directly by byte index can cut a multi-byte UTF-8 character in half, resulting in an invalid UTF-8 string. Converting the string to a slice of runes before slicing ensures safe truncation of UTF-8 characters.
| trimmed := item.text[:min(len(item.text), maxInstanceChars)] | |
| runes := []rune(item.text) | |
| if len(runes) > maxInstanceChars { | |
| runes = runes[:maxInstanceChars] | |
| } | |
| trimmed := string(runes) |
e56b030 to
9cf27c2
Compare
…p TS AST tests without node_modules
Summary
Integrates multi-language (Go and TypeScript) AST-normalized semantic function similarity advisories into
scripts/codequalityusing Vertex AIgemini-embedding-2viagoogle.golang.org/genai, helping developers and AI agents spot existing shared helpers before duplicating logic across packages.Key Changes
scripts/codequality/internal/simcheck):LanguageAnalyzerinterface (FileInputbatch extraction, AST identifier normalization, corpus discovery, and shared-module classification) andRegistryso additional languages can be plugged into a single differential evaluation pipeline (evaluator.go).>= 3statements and>= 6code lines) against same-language production corpus units usingAST-Normcosine similarity (0.940general threshold,0.915boosted threshold for shared modules,0.960intra-change threshold).Advisory).vertex.go,cache.go):google.golang.org/genaiSDK (BackendVertexAI,Models.EmbedContent,gemini-embedding-2at768dimensions onlocations/global) with concurrent worker batching and automaticX-Goog-User-Projectquota-project header propagation.modernc.org/sqlite,~/.cache/khi/codesim/embeddings_v1.db) shared across workspaces for near-instant incremental runs.simcheck/langgo,simcheck/langts):langgo: Extracts Go functions, methods, and top-level KHI task closures (var xxxTask = Define...Task(...)) viago/ast, normalizing local/parameter/receiver identifiers while preserving external selector names and reusingastcheck/ruleAST helpers.langts: Drives theweb/node_modules/typescriptCompiler API in a single batchnodeinvocation (//go:embed extract_ts.js) to extract and AST-normalize TypeScript functions, class methods, and substantive Angular signal/computed/effect closures (web/src/app/{common,utils,shared}marked[shared]).codequalityCLI, Reporting & Docs:similaritySession(--similarity, defaulttrue,CODEQUALITY_SIMILARITY ?= true) across bothexecuteGoPipeline(including--fast) andexecuteTSPipeline, rendering advisory tables and code previews in terminal output andGITHUB_STEP_SUMMARY.scripts/make/testing.mk,.agents/rules/{go,ts}-coding-rule.md, and EN/JA development guides.Verification
make codequality-fast: PASS (0 violations, 95 new units checked against 2,444 corpus units,0 similar matches)make codequality-go CODEQUALITY_MAX=0: PASS (95.0%patch coverage,100.0%mutation score —370/370killed,0survived,0 violations)make codequality,make codequality-fast, andmake codequality-web)make build-go,make test-go,make lint-go,make lint-web,make pre-commit: PASS