Skip to content

Add output-inclusive token and cost estimation primitives #1357

@prompt-driven-github

Description

@prompt-driven-github

Implement the estimation foundations for pre-flight command cost previews.

Concrete files to investigate and update:

  • pdd/server/token_counter.py
  • pdd/prompts/server/token_counter_python.prompt
  • pdd/track_cost.py
  • pdd/prompts/track_cost_python.prompt
  • .pdd/llm_model.csv
  • existing token/cost tests under tests/

Scope:

  • Extend model pricing loading so .pdd/llm_model.csv reads both input and output pricing.
  • Add an output-inclusive cost estimate API such as estimate_completion_cost(input_tokens, predicted_output_tokens, model, pricing_csv).
  • Extend CostEstimate to expose input, output, and total cost while preserving existing callers.
  • Preserve unknown-pricing behavior: token counts/context can still be reported, but cost must be explicitly unknown.
  • Extend cost logging in pdd/track_cost.py so actual input_tokens and output_tokens can be recorded while preserving legacy CSV/header handling.

PDD Command Hint: change+sync

Acceptance criteria:

  • pdd/server/token_counter.py can compute deterministic input+output pricing from a fixture pricing CSV.
  • Unknown models return token metrics without silently inventing a price.
  • pdd/track_cost.py remains backward-compatible with legacy cost CSVs and supports new token-count columns.

Split Contract

Command sequence: change → sync
Allowed write set:

  • pdd/server/token_counter.py
  • pdd/prompts/server/token_counter_python.prompt
  • pdd/track_cost.py
  • pdd/prompts/track_cost_python.prompt
  • tests/test_token_counter.py
  • tests/test_track_cost.py
    Acceptance criteria:
  • Token-counter tests cover input and output rates from a fixture .pdd/llm_model.csv.
  • Unknown model pricing reports unknown cost rather than a guessed dollar value.
  • Cost logging accepts and preserves input_tokens and output_tokens columns without breaking legacy CSV handling.
    Independently mergeable: True
    Scope rule: Do not expand beyond this contract or implement sibling sub-issue work. If the contract is insufficient, report the gap instead.

PDD Command Hint: This is a new feature. Use change → sync (modify prompts, then generate and validate code).


Parent: #1347
Parent issue: #1347

Metadata

Metadata

Labels

pdd-effort-highPDD: request high reasoning effort (--time 0.85)

Type

No type
No fields configured for issues without a type.

Projects

Status
In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions