[PR #7278] fix(cli): count the full-output envelope for TOON/YAML token counts #7805

Open
opened 2026-11-05 01:47:47 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7278
Author: @sx4im
Created: 10/26/2026
Status: 🔄 Open

Base: main ← Head: fix/7271-token-count-full-output


📝 Commits (1)

  • 96b7b1d fix(cli): count the full-output envelope for TOON/YAML token counts

📊 Changes

2 files changed (+70 additions, -2 deletions)

View changed files

📝 src/cli/cliResultOutput.ts (+5 -2)
➕ tests/boundary/cli/cliFullOutputTokenCount.test.ts (+65 -0)

📄 Description

Summary

Fixes #7271. evidence-import --format toon --full-output --token-count reported 13 while the emitted document estimates to 31. YAML behaved the same way.

Problem and expected behavior

With --token-count --full-output, TOON and YAML results were handed to Incur before the envelope-aware count branch, so Incur counted only the selected data. docs/cli.md:1085 says the count covers the selected emitted document, including a requested full-output envelope and metadata. The count must cover the envelope.

Change and scope

One condition in src/cli/cliResultOutput.ts: a full-output token count no longer delegates to Incur for TOON/YAML, so it runs through the envelope-aware count branch that JSON and Markdown already use. Bare counts still delegate to Incur and are unchanged. Nothing else changes. Scope decision: not applicable, ordinary fix within existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the CLI result output boundary (src/cli/cliResultOutput.ts); the consumer is the Incur formatter.
  • Contribution scope fit and linked maintainer decision: ordinary fix, no scope decision required.
  • CLI and MCP/tool-catalog contract: --token-count values change for TOON/YAML full output only (13 to 31 in the repro). Bare counts, JSON, and Markdown are unchanged. No MCP surface change.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

No target interaction: this changes only how a CLI token count is computed.

Evidence and regression coverage

  • Tests added: tests/boundary/cli/cliFullOutputTokenCount.test.ts, 2 tests, both pass. They pin the full-output envelope count for TOON and YAML.
  • Base reproduction: the issue's source CLI replay on an empty evidence bundle, before and after. Before: toon full 13 vs emitted 31, yaml full 13 vs 31, bare and JSON/Markdown controls matched. After: all 8 format/full combinations match (toon full 31/31, yaml full 31/31, controls unchanged).
  • User-visible CLI/MCP output: the counts above are the output. --token-count now prints 31 for the repro case.
  • Remaining proof gaps: full check:pr not run; CI on this PR covers the rest. Verified on Linux, Node 24.22.1; the issue was reported on macOS arm64, Node 26, but the changed path is platform-independent.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • Issue replay before fix: toon/yaml full 13 vs emitted 31, controls matched.
  • Issue replay after fix: all 8 format/full combinations match.
  • npm run test:focused -- tests/boundary/cli/cliFullOutputTokenCount.test.ts: 2 passed.
  • npm run test:focused -- tests/boundary/cli/cliOutput.test.ts: 61 passed (an earlier parallel run showed 2 subprocess deadline timeouts; rerun alone passed 61/61, so those were load flakiness).
  • npm run verify:test-discovery: 2582 test files, exactly once.
  • npm run check:fast: typecheck and lint pass.
  • Prettier check on both changed files: pass.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. This corrects a count to match the documented contract; callers that budgeted on the undercount will see larger, correct numbers.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable, CLI output only, verified on Linux.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none, no target interaction, no new I/O.

Author readiness

Human owner: @sx4im

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/7278 **Author:** [@sx4im](https://github.com/sx4im) **Created:** 10/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/7271-token-count-full-output` --- ### 📝 Commits (1) - [`96b7b1d`](https://github.com/morluto/rea/commit/96b7b1d256f2f0bd23c088c2560af0633d3d197c) fix(cli): count the full-output envelope for TOON/YAML token counts ### 📊 Changes **2 files changed** (+70 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/cli/cliResultOutput.ts` (+5 -2) ➕ `tests/boundary/cli/cliFullOutputTokenCount.test.ts` (+65 -0) </details> ### 📄 Description ## Summary Fixes #7271. `evidence-import --format toon --full-output --token-count` reported 13 while the emitted document estimates to 31. YAML behaved the same way. ## Problem and expected behavior With `--token-count --full-output`, TOON and YAML results were handed to Incur before the envelope-aware count branch, so Incur counted only the selected data. docs/cli.md:1085 says the count covers the selected emitted document, including a requested full-output envelope and metadata. The count must cover the envelope. ## Change and scope One condition in `src/cli/cliResultOutput.ts`: a full-output token count no longer delegates to Incur for TOON/YAML, so it runs through the envelope-aware count branch that JSON and Markdown already use. Bare counts still delegate to Incur and are unchanged. Nothing else changes. Scope decision: not applicable, ordinary fix within existing boundaries. ## Contract and boundary impact - Semantic owner and earliest changed stage: the CLI result output boundary (`src/cli/cliResultOutput.ts`); the consumer is the Incur formatter. - Contribution scope fit and linked maintainer decision: ordinary fix, no scope decision required. - CLI and MCP/tool-catalog contract: `--token-count` values change for TOON/YAML full output only (13 to 31 in the repro). Bare counts, JSON, and Markdown are unchanged. No MCP surface change. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. No target interaction: this changes only how a CLI token count is computed. ## Evidence and regression coverage - Tests added: `tests/boundary/cli/cliFullOutputTokenCount.test.ts`, 2 tests, both pass. They pin the full-output envelope count for TOON and YAML. - Base reproduction: the issue's source CLI replay on an empty evidence bundle, before and after. Before: toon full 13 vs emitted 31, yaml full 13 vs 31, bare and JSON/Markdown controls matched. After: all 8 format/full combinations match (toon full 31/31, yaml full 31/31, controls unchanged). - User-visible CLI/MCP output: the counts above are the output. `--token-count` now prints 31 for the repro case. - Remaining proof gaps: full `check:pr` not run; CI on this PR covers the rest. Verified on Linux, Node 24.22.1; the issue was reported on macOS arm64, Node 26, but the changed path is platform-independent. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [ ] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - Issue replay before fix: toon/yaml full 13 vs emitted 31, controls matched. - Issue replay after fix: all 8 format/full combinations match. - `npm run test:focused -- tests/boundary/cli/cliFullOutputTokenCount.test.ts`: 2 passed. - `npm run test:focused -- tests/boundary/cli/cliOutput.test.ts`: 61 passed (an earlier parallel run showed 2 subprocess deadline timeouts; rerun alone passed 61/61, so those were load flakiness). - `npm run verify:test-discovery`: 2582 test files, exactly once. - `npm run check:fast`: typecheck and lint pass. - Prettier check on both changed files: pass. ## Compatibility, safety, and release - Breaking changes or migration steps: none. This corrects a count to match the documented contract; callers that budgeted on the undercount will see larger, correct numbers. - Real Hopper/Ghidra, browser, or OS coverage: not applicable, CLI output only, verified on Linux. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none, no target interaction, no new I/O. ## Author readiness Human owner: @sx4im - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7805
No description provided.