Repository navigation
Conversation
Report the current request as instructions, tool definitions, and conversation without starting a model request. Split conversation into user input, AI answers, thinking, tool calls, tool output, compaction summaries, and injected context, and show free space plus the configured compaction reserve. Expose an optional command-context snapshot so commands can read the effective system prompt, registered tools, MCP server names, messages, context window, and reserve tokens without re-deriving them.
li-xiu-qi
requested review from
MelodyVAR,
Uking-xxx,
ZouR-Ma and
liuedcson
as code owners
October 26, 2026 16:41
li-xiu-qi
marked this pull request as draft
October 26, 2026 17:00
…point Ask the Step token-count endpoint for instructions, tool definitions, the full conversation, and each conversation category. Allocate structural children from those counts and fall back to local estimates when the endpoint is unavailable.
li-xiu-qi
marked this pull request as ready for review
October 26, 2026 17:40
Borrow the Step 3.7 tokenizer for non-Step models and fall back to local structural estimates whenever Step tokenization is unavailable or any segment fails. Remove the mixed source label so the report header is either token-count API or estimated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #161
Problem
Issue #161 asks for a way to see what is consuming the current context window. The existing
/usageview reports cumulative token and cost totals, but it does not show the composition of the request that will be sent next: instructions, tool definitions, and conversation are not separated, and there is no view of free space or the configured compaction reserve.Changes
Add a read-only
/context [all]command that reports the composition of the current request without starting a model turn./context all, or pressingain the TUI panel, to expand individual skills, context files, and tools.step-3.7-flash) so/contextdoes not need a provider-specific counter. The command sends segmented payloads for instructions, tool definitions, the full conversation, and each conversation category; these are tokenizer requests, not model generations.ExtensionCommandContext.getContextReportSnapshot()so commands can read the effective system prompt, base prompt options, registered tool catalog, MCP server names, active messages, context window, and reserve tokens without re-deriving them.reserveTokenstoContextUsageso extension consumers can see the configured compaction reserve, or zero when automatic compaction is disabled.Behavior and compatibility
/context [all].ctx.getContextReportSnapshot()in command contexts. It returnsundefinedwhen the host does not provide a snapshot, so existing extension hosts remain source-compatible.ContextUsagegains an optionalreserveTokensfield. Existing consumers that read onlytokens,contextWindow, andpercentare unaffected./contextmay call the Step token-count endpoint, including for non-Step active models. It never calls a chat, responses, or messages generation endpoint, and it never mutates session state./usageremains the owner of those views.Validation
Run from the repository root on Windows with Node.js v24.21.0:
pnpm run check— passed. This includes Biome, TypeScript, dependency and boundary checks, and the browser smoke check.pnpm exec vitest --run test/context-report.test.ts test/token-count.test.tsinpackages/coding-agent— passed, 19 tests.pnpm exec vitest --run test/skills.test.tsinpackages/coding-agent— passed, 30 tests.pnpm exec vitest --run test/extensions-runner.test.ts test/extensions-tool-catalog.test.ts test/extension-tool-availability.test.ts test/runtime-info-extension.test.ts test/step-capabilities-extension.test.ts test/agent-session-stats.test.ts test/trigger-compact-extension.test.ts test/suite/agent-session-auto-clm.test.ts test/suite/agent-session-live-context.test.ts test/step-usage-lifecycle.test.tsinpackages/coding-agent— passed, 170 tests, 1 skipped.pnpm exec vitest --run test/step-slash-commands.test.ts -t "registers product adapters without replacing Pi's native commands"inpackages/coding-agent— passed.npm run build:unbundledinpackages/coding-agentandnpm run buildinapps/cli— passed.pnpm run check:browser-smoke— passed.Limitations
./test.shwas not run locally; CI is pending.test/step-slash-commands.test.tsare unrelated to this change: they assert forward-slash diagnostic paths and create a diagnostics filename containing control characters. They reproduce on the current branch without the/contexttoken-count changes.total_tokens/input_tokenstotals, not a native per-section response. This PR therefore requests segmented totals and allocates structural children from those counts. Category totals can differ from the full-request total by message-role and tool-schema overhead; the full-request total remains the displayed group total.toolsfield probe first and a serialized JSON fallback second, because the public token-count documentation does not state whethertoolsis included.