Skip to content

report.ts: effectiveCompressedTokens carries two unused legacy params, forcing placeholder args at 7 call sites #47

Description

@ranxianglei

Context

v0.0.17, b9f9e99. effectiveCompressedTokens in src/report.ts:23-36 has this signature:

function effectiveCompressedTokens(
    block: CompressionBlock,
    _state: CompressionState,
    _countTokens: (t: string) => number,
): number {
    // block.compressedTokens already records the full input token count ...
    // Recursing into directBlockIds ... double-counts the consumed children,
    // so we return the block's own value directly.
    return block.compressedTokens;
}

Both _state and _countTokens are unused. The body is a single field read: return block.compressedTokens;.

Why it matters

Because of the wide signature, every one of the 7 call sites (src/report.ts:173, 184, 185, 190, 286, 287, 293, 306) has to thread state and countTokens through:

effectiveCompressedTokens(b, state, countTokens)   // repeated 8x

…even though those values are never used inside. It clutters the report code and makes a reader think the function does something stateful/token-aware (it does not).

The leading-underscore params + the comment explain why the recursion was removed, but they do not explain why the signature was kept wide. My guess: preserved for a possible future re-introduction of recursion. If so, that intent is worth a one-line comment; if not, the signature should narrow.

Suggested fix

Either:

  • (preferred) Narrow the signature to (block: CompressionBlock): number and simplify all 8 call sites to effectiveCompressedTokens(b) — or just inline b.compressedTokens at each site, since it is a single field read.
  • (minimal) Keep the signature, add a comment stating "signature retained so a future tier-aware recursion can be reintroduced without touching call sites" so the next reader is not puzzled.

Severity

Low — readability/maintenance only. No behavioral impact.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions