Context
Saat CodeLens ditest terhadap codebase nyata (Wolfvin/Coretax-Auto-Downloader, issue #876), ditemukan bug berikut:
processMenuImageUpload() di vps-deploy/api/kds/src/lib/uploads.ts selalu generate dua output: fullPath (dipakai) dan thumbPath (tidak pernah dikonsumsi caller manapun)
- Interface
ProcessedMenuImage punya field thumb yang di-assign tapi tidak pernah di-read oleh consumer
audit --check dead-code hanya menemukan menuImageUpload (unused variable) dan MENU_UPLOAD_DIR (unused export) — adjacent noise, bukan root cause
Root cause tidak terdeteksi karena CodeLens tidak punya kemampuan: cross-file tracking property/field yang di-set tapi tidak pernah di-read oleh consumer.
Tujuan
Tambah detector baru ke audit --check dead-code: unused return fields / dead output fields.
Pattern yang harus dideteksi:
// uploads.ts
interface ProcessedMenuImage {
fullPath: string // DIPAKAI — consumer akses .fullPath
thumbPath: string // TIDAK DIPAKAI — tidak ada consumer yang akses .thumbPath
}
async function processMenuImageUpload(): Promise<ProcessedMenuImage> {
// generate fullPath dan thumbPath, return keduanya
return { fullPath: "...", thumbPath: "..." }
}
// menu.ts (consumer)
const result = await processMenuImageUpload()
result.fullPath // <-- akses ini ada
// result.thumbPath <-- tidak pernah diakses di seluruh codebase
Detector harus output: "field thumbPath pada return type ProcessedMenuImage (uploads.ts:X) tidak pernah diakses oleh consumer manapun".
Algoritma yang Disarankan
- Collect return types: dari graph_nodes, cari semua interface/type alias yang dipakai sebagai return type fungsi
- Collect field definitions: untuk setiap interface, list semua field names
- Collect property accesses: scan semua file untuk pola
result.fieldName, obj.fieldName, destructuring { fieldName } — khususnya setelah call ke fungsi yang return interface tersebut
- Cross-reference: field yang ada di definition tapi tidak ditemukan di property accesses = dead output field
Constraint
- Implementasi masuk ke
scripts/commands/dead_code.py sebagai kategori baru: dead_output_fields
- Harus bekerja tanpa LSP (tree-sitter only) — LSP bisa dipakai sebagai enhancement via
--deep flag
- False positive acceptable di versi pertama, tapi harus ada confidence score
- Output format harus konsisten dengan kategori dead-code lain:
{file, line, name, type, severity, message, suggestion, confidence}
- Tambah
dead_output_fields ke stats by_category
Source of Truth
- Pattern dead-code detector yang sudah ada: baca
scripts/commands/dead_code.py
- Graph model: baca
scripts/graph_model.py — khususnya graph_nodes schema
- Cara akses graph: query SQLite
.codelens/codelens.db di workspace
Definition of Done
codelens audit <workspace> --check dead-code mendeteksi thumbPath di codebase vps-deploy/api/kds dari Wolfvin/Coretax-Auto-Downloader
- Output punya field
type: "dead_output_field" dengan confidence >= 0.6
by_category stats punya key dead_output_fields
- Tidak ada crash pada codebase TypeScript yang tidak punya interface dengan return type eksplisit
- Test case: minimal 1 unit test yang verify detection benar pada fixture TypeScript sederhana
Checklist Laporan Worker
Context
Saat CodeLens ditest terhadap codebase nyata (Wolfvin/Coretax-Auto-Downloader, issue #876), ditemukan bug berikut:
processMenuImageUpload()divps-deploy/api/kds/src/lib/uploads.tsselalu generate dua output:fullPath(dipakai) danthumbPath(tidak pernah dikonsumsi caller manapun)ProcessedMenuImagepunya fieldthumbyang di-assign tapi tidak pernah di-read oleh consumeraudit --check dead-codehanya menemukanmenuImageUpload(unused variable) danMENU_UPLOAD_DIR(unused export) — adjacent noise, bukan root causeRoot cause tidak terdeteksi karena CodeLens tidak punya kemampuan: cross-file tracking property/field yang di-set tapi tidak pernah di-read oleh consumer.
Tujuan
Tambah detector baru ke
audit --check dead-code: unused return fields / dead output fields.Pattern yang harus dideteksi:
Detector harus output: "field
thumbPathpada return typeProcessedMenuImage(uploads.ts:X) tidak pernah diakses oleh consumer manapun".Algoritma yang Disarankan
result.fieldName,obj.fieldName, destructuring{ fieldName }— khususnya setelah call ke fungsi yang return interface tersebutConstraint
scripts/commands/dead_code.pysebagai kategori baru:dead_output_fields--deepflag{file, line, name, type, severity, message, suggestion, confidence}dead_output_fieldske statsby_categorySource of Truth
scripts/commands/dead_code.pyscripts/graph_model.py— khususnyagraph_nodesschema.codelens/codelens.dbdi workspaceDefinition of Done
codelens audit <workspace> --check dead-codemendeteksithumbPathdi codebasevps-deploy/api/kdsdari Wolfvin/Coretax-Auto-Downloadertype: "dead_output_field"denganconfidence >= 0.6by_categorystats punya keydead_output_fieldsChecklist Laporan Worker
codelens audit vps-deploy/api/kds --check dead-code— apakah thumbPath terdeteksi?