feat(opencode): trim old tool output and media in one batch at a token mark
Long V4 runs resend their whole history and only compact near the model window, and prune runs only when a turn ends, so a single long run never prunes. compaction.prune_at runs the existing prune inside the loop once the context reaches that many tokens, and compaction.keep_media keeps the latest N tool results with screenshots whole and clears everything older in one batch, so the prompt cache is rewritten rarely instead of every step. Without prune_at nothing changes: prune still runs only when a turn ends with its token-window rules. Tests cover the mark, the batch and the default (the existing config-dependent prune test also fails on main in this environment); typecheck passes and the prompt suite fails identically on main and this branch.
Summary by cubic
Adds compaction.prune_at and compaction.keep_media options so long runs can trim old tool output and media in one batch inside the loop instead of only pruning when a turn ends. Without prune_at, behavior is unchanged and prune still runs only at turn end with its existing token-window rules.
- The in-loop prune fires once context reaches
prune_attokens and clears everything older than the latestkeep_media(default: 2) completed tool results with media, rewriting the prompt cache rarely. - A trim frees context that the last finished message's token usage does not reflect, so the next pass skips the overflow check to avoid compacting on stale numbers.
- Screenshots and other media count toward the token estimate at a fixed 1,500 tokens each.