Skip to content

[FEAT] codelens orient — 10-second codebase orientation brief #160

Description

@Wolfvin

Background

Currently CodeLens is a deep analysis tool (taint, callgraph, secrets, dead-code). There is no command that answers the first questions a developer asks when entering an unfamiliar repo:

  • What framework/stack is this?
  • How do I run, build, and test it?
  • Where do I start reading?
  • What CI/Docker infrastructure exists?

Codeglance solves exactly this problem — a zero-setup, pure-static "repo orientation brief" in under 1 second. Its approach is fully portable to Python static analysis with no new hard dependencies.

Goal

Add a codelens orient command that produces a single structured brief covering framework detection, run/build/test command extraction, entry point detection, important file ranking, and CI/Docker detection — all in one output.

codelens orient .
codelens orient . --format json
codelens orient . --format compact   # for LLM context generation

Sub-Features to Implement

A. Framework Detection

  • Detect 20+ frameworks across Node.js (Next.js, React, Express, Prisma, Jest), Python (FastAPI, Django, Pydantic), Go (Gin, GORM), Rust (Axum, Tokio), Java (Spring Boot)
  • Source of truth: dependencies, , , , ,
  • Output:
  • Implementation: data-driven lookup table (framework name → package keys). Adding a new framework = 1 entry in the table.

B. Run/Build/Test Command Extraction

  • Extract commands from: scripts, , , ,
  • Infer semantic kind:
  • Output:

C. Entry Point Detection

  • Per-ecosystem candidate path lists (e.g., , , , , )
  • Check "main" and "bin" fields first
  • Return up to 8 files with type:

D. Start Here File Ranking

  • Score every source file on: filename patterns (e.g. , , score high), directory depth (shallower = higher), line count (50–500 lines optimal), directory context (, , score high)
  • Skip: test files, migrations, generated code, config-only files
  • Return top 8 files with per-file reasoning string

E. CI/Docker Detection

  • Count files
  • Detect presence + required env vars
  • Detect / presence
  • Detect test framework and linter from config files

Output Schema

{
  "framework": {
    "ecosystem": "Node.js",
    "primary": "Next.js 14",
    "secondary": ["Prisma", "TailwindCSS", "Jest"],
    "summary": "Full-stack React app with ORM and CSS framework"
  },
  "commands": [
    { "kind": "dev", "command": "npm run dev", "description": "Start development server" },
    { "kind": "test", "command": "npm test", "description": "Run test suite" }
  ],
  "entry_points": [
    { "path": "src/index.ts", "type": "server" },
    { "path": "next.config.js", "type": "config" }
  ],
  "start_here": [
    { "path": "src/app/page.tsx", "score": 87, "reason": "Top-level route, shallow depth, 120 lines" },
    { "path": "src/lib/api.ts", "score": 74, "reason": "API surface, lib/ directory" }
  ],
  "infra": {
    "ci": true,
    "ci_count": 2,
    "docker": true,
    "env_file": true,
    "test_framework": "jest",
    "linter": "eslint"
  }
}

Architecture

  • New file: scripts/commands/orient.py
  • New file: scripts/orient/framework_db.py — framework lookup table (ecosystem → package keys → framework name)
  • New file: scripts/orient/file_ranker.py — Start Here scoring logic
  • New file: scripts/orient/manifest_parser.py — command extraction from package.json, Makefile, pyproject.toml, etc.
  • Register in scripts/command_registry.py under orient
  • Run sync_command_count.py --apply after registering

Definition of Done

  • codelens orient . produces structured output for a Node.js repo, a Python repo, and a Go repo (use repo's own source as test fixture)
  • --format json and --format compact work (compact = single-line brief ≤300 tokens for LLM context)
  • Framework detection covers at minimum: Next.js, React, Express, FastAPI, Django, Flask, Gin, Axum, Spring Boot
  • Start Here ranking returns ≤8 files, skips tests/generated/migrations
  • CI/Docker detection reads from filesystem only (no subprocess)
  • sync_command_count.py --apply run after registration
  • File headers (@WHO, @WHAT, @PART, @ENTRY) on all new files
  • @FLOW: ORIENT, @CALLS, @MUTATES on entry function

Reference Implementation

mansoor-mamnoon/codeglance — TypeScript, MIT. Framework definitions in src/analyzers/framework-detector.ts. File ranker in src/analyzers/start-here.ts. Port logic, not code — rewrite in Python idioms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions