Home / Function/ run() — dead-code-hunter Function Reference

run() — dead-code-hunter Function Reference

Architecture documentation for the run() function in index.ts from the dead-code-hunter codebase.

Entity Profile

Dependency Diagram

graph TD
  0c3136ed_f7b1_d5d1_589e_7b15515e6598["run()"]
  1916269f_4df6_c8ce_0c1a_a8a66a4fb245["index.ts"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|defined in| 1916269f_4df6_c8ce_0c1a_a8a66a4fb245
  aa9f9c43_acc5_99f2_5a98_904088e2f599["createZipArchive()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| aa9f9c43_acc5_99f2_5a98_904088e2f599
  5032be21_fd5a_3dd2_6900_284dc360386a["generateIdempotencyKey()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 5032be21_fd5a_3dd2_6900_284dc360386a
  9e6e1b2a_ab53_bba7_59da_9202ddc5c9a5["pollForResult()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 9e6e1b2a_ab53_bba7_59da_9202ddc5c9a5
  8fb39060_bdfd_d045_ece4_18fee517d989["filterByIgnorePatterns()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 8fb39060_bdfd_d045_ece4_18fee517d989
  2d958612_175d_170b_d202_1d8d208cb116["getChangedFiles()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 2d958612_175d_170b_d202_1d8d208cb116
  9e5350ec_72a9_b03d_0141_b564a058f5a8["filterByChangedFiles()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 9e5350ec_72a9_b03d_0141_b564a058f5a8
  96354862_3d3e_920a_e420_3c1b0ee82eec["formatPrComment()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 96354862_3d3e_920a_e420_3c1b0ee82eec
  78e42b23_047d_0841_e86a_607eff1a77ba["safeSerialize()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| 78e42b23_047d_0841_e86a_607eff1a77ba
  c44865c2_fc6d_0cfb_72be_2814706bb941["redactSensitive()"]
  0c3136ed_f7b1_d5d1_589e_7b15515e6598 -->|calls| c44865c2_fc6d_0cfb_72be_2814706bb941
  style 0c3136ed_f7b1_d5d1_589e_7b15515e6598 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/index.ts lines 191–367

async function run(): Promise<void> {
  try {
    const apiKey = core.getInput('supermodel-api-key', { required: true }).trim();

    if (!apiKey.startsWith('smsk_')) {
      core.warning('API key format looks incorrect. Get your key at https://dashboard.supermodeltools.com');
    }

    const commentOnPr = core.getBooleanInput('comment-on-pr');
    const failOnDeadCode = core.getBooleanInput('fail-on-dead-code');
    const ignorePatterns: string[] = JSON.parse(core.getInput('ignore-patterns') || '[]');

    const workspacePath = process.env.GITHUB_WORKSPACE || process.cwd();

    core.info('Dead Code Hunter starting...');

    // Step 1: Create zip archive
    const zipPath = await createZipArchive(workspacePath);

    // Step 2: Generate idempotency key
    const idempotencyKey = await generateIdempotencyKey(workspacePath);

    // Step 3: Call Supermodel dead code analysis API
    core.info('Analyzing codebase with Supermodel...');

    const config = new Configuration({
      basePath: process.env.SUPERMODEL_BASE_URL || 'https://api.supermodeltools.com',
      apiKey: apiKey,
    });

    const api = new DefaultApi(config);

    const zipBuffer = await fs.readFile(zipPath);
    const zipBlob = new Blob([zipBuffer], { type: 'application/zip' });

    const result = await pollForResult(api, idempotencyKey, zipBlob);

    // Step 4: Apply client-side ignore patterns
    let candidates = filterByIgnorePatterns(result.deadCodeCandidates, ignorePatterns);

    // Step 5: Scope to PR diff when running on a pull request
    const token = core.getInput('github-token') || process.env.GITHUB_TOKEN;
    let changedFiles: Set<string> | null = null;

    if (github.context.payload.pull_request && token) {
      changedFiles = await getChangedFiles(token);
      if (changedFiles) {
        const totalBeforeScoping = candidates.length;
        candidates = filterByChangedFiles(candidates, changedFiles);
        core.info(`Scoped to PR: ${candidates.length} findings in changed files (${totalBeforeScoping} total across repo, ${changedFiles.size} files in PR)`);
      }
    }

    core.info(`Found ${candidates.length} potentially unused code elements (${result.metadata.totalDeclarations} declarations analyzed)`);
    core.info(`Analysis method: ${result.metadata.analysisMethod}`);
    core.info(`Alive: ${result.metadata.aliveCode}, Entry points: ${result.entryPoints.length}, Root files: ${result.metadata.rootFilesCount ?? 'n/a'}`);
    for (const dc of candidates) {
      core.info(`  [${dc.confidence}] ${dc.type} ${dc.name} @ ${dc.file}:${dc.line} — ${dc.reason}`);
    }

    // Step 6: Set outputs
    core.setOutput('dead-code-count', candidates.length);
    core.setOutput('dead-code-json', JSON.stringify(candidates));

    // Step 7: Post PR comment if enabled
    if (commentOnPr && github.context.payload.pull_request) {
      if (token) {
        const octokit = github.getOctokit(token);
        const comment = formatPrComment(candidates, result.metadata);

        await octokit.rest.issues.createComment({
          owner: github.context.repo.owner,
          repo: github.context.repo.repo,
          issue_number: github.context.payload.pull_request.number,
          body: comment,
        });

        core.info('Posted findings to PR');
      } else {
        core.warning('GITHUB_TOKEN not available, skipping PR comment');
      }

Domain

Subdomains

Defined In

Frequently Asked Questions

What does run() do?
run() is a function in the dead-code-hunter codebase, defined in src/index.ts.
Where is run() defined?
run() is defined in src/index.ts at line 191.
What does run() call?
run() calls 9 function(s): createZipArchive, filterByChangedFiles, filterByIgnorePatterns, formatPrComment, generateIdempotencyKey, getChangedFiles, pollForResult, redactSensitive, and 1 more.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free