TS/JS Duplication Stabilization Report
Date: 2026-03-06
Scope: TypeScript/JavaScript duplication cleanup only (safe mode)
Safety posture: no deletions, no entrypoint/port/URL changes
Step 1 — Duplication Clusters
Total TS/JS duplicate pairs detected: 295
Full duplication map:
Sample high-value clusters:
| Cluster ID | TS file | JS file | Import locations | Used by runtime? | Risk |
| --- | --- | --- | --- | --- | --- |
| C001 | services/svc-auth/src/security/jwt.ts | services/svc-auth/src/security/jwt.js | services/svc-auth/src/server.ts imports ./security/jwt | Yes (service runtime path) | High |
| C002 | services/svc-auth/src/security/password.ts | services/svc-auth/src/security/password.js | services/svc-auth/src/server.ts imports ./security/password | Yes | High |
| C003 | services/api/src/routes/tenders.ts | services/api/src/routes/tenders.js | services/api/src/server.ts mounts tendersRouter | Yes | High |
| C004 | services/api/src/routes/auctions.ts | services/api/src/routes/auctions.js | services/api/src/server.ts mounts auctionsRouter | Yes | High |
| C005 | services/svc-tenders/src/server.ts | services/svc-tenders/src/server.js | services/svc-tenders/package.json (dev ts, start dist) | Yes | Medium |
| C006 | packages/ai-layer/src/index.ts | packages/ai-layer/src/index.js | apps/web/src/app/api/ai/ask/route.ts imports @kvary/ai-layer | Yes | High |
| C007 | packages/memory-layer/src/index.ts | packages/memory-layer/src/index.js | apps/web/src/app/api/ai/ask/route.ts imports @kvary/memory-layer | Yes | High |
| C008 | packages/core/index.ts | packages/core/index.js | used via @kvary/core and core compat paths | Yes | High |
Step 2 — Canonical Source Classification
Heuristic used:
- If
.tsexists, treat TS as canonical source. - If package/service builds to
distand starts fromdist,src/*.jsis candidate artifact. - If package runs/exports from
src/*.ts, duplicatesrc/*.jsis treated asUNKNOWN.
Classification totals:
SAFE_TO_REMOVE_JS: 147UNKNOWN: 148RUNTIME_JS: 0 detected explicitly
Notes:
services/*pairs were classified asSAFE_TO_REMOVE_JS(builds todist, starts fromdist, dev runs TS entrypoint).packages/ai-layer,packages/memory-layer,packages/identity-infra, andpackages/corewere keptUNKNOWNdue activesrc-based runtime/export patterns.
Step 3 — Runtime Import Verification
Checks performed:
- explicit imports to
*.jsin TS sources - package scripts for
node src/*.js - service start scripts (
node dist/server.js) and dev scripts (ts-node(-dev)/tsxTS entrypoints)
Result:
- No explicit
RUNTIME_JS_DEPENDENCYdetected via source/package-script scan. - Runtime resolution expectation in services:
- prod:
dist/*.js - dev: TS entrypoint loaders (
ts-node-dev,ts-node,tsx)
- prod:
Reference:
Step 4 — Safe Build Structure Updates
Added "rootDir": "src" (while keeping existing "outDir": "dist") to:
services/api/tsconfig.jsonservices/svc-auth/tsconfig.jsonservices/svc-tenders/tsconfig.jsonservices/svc-risk/tsconfig.jsonservices/svc-kyc/tsconfig.jsonservices/svc-carbon/tsconfig.json
No boot logic changed.
Step 5 — Safe Import Redirects
No safe redirects applied in this pass because:
- no explicit
src/*.jsimport targets were found in TS code paths. - changing extensionless runtime resolution behavior was intentionally avoided in safe mode.
Step 6 — Legacy JS Marking
For services/*/src/*.js files that have sibling .ts canonical files, header added:
// @deprecated duplicate JS build artifact
// canonical source: file.ts
Marked files in services: 87
No deletions were performed.
Step 7 — Dry-run Removal Simulation
Candidate list generated only (not removed):
Candidates count: 147
Step 8 — Stabilization Output
Produced outputs:
- duplication clusters map (
TSV) - canonical classification
- safe-removal candidate list
- runtime JS dependency list
- commit plan below
Step 9 — Commit Plan
chore(stabilization): add TS/JS duplication analysis artifactschore(build): add rootDir=src to service tsconfigs with outDir=distrefactor(stabilization): mark service src JS duplicates as deprecated artifactschore(stabilization): add runtime-js dependency report + safe-removal dry-run listchore(stabilization): manual removal (optional, only after build/runtime parity check)
Safety Notes
- No files were deleted.
- No service ports/URLs/entrypoints were changed.
- No domain logic rewrites were done.
UNKNOWNclusters were intentionally not touched beyond reporting.