Skip to content

feat(session): add compact action to session control tool - #2470

Open
1688mengdie wants to merge 2 commits into
GCWing:mainfrom
BitFun-SIG:pr-g6-compact-rebased
Open

feat(session): add compact action to session control tool#2470
1688mengdie wants to merge 2 commits into
GCWing:mainfrom
BitFun-SIG:pr-g6-compact-rebased

Conversation

@1688mengdie

Copy link
Copy Markdown

Summary

Add the compact action to the session control tool family so a caller can compact a session context to reduce its token footprint and surface the applied compaction statistics (tokens/ratio/summary).

Changes

  • Thread ContextCompactionOutcome through the manual compaction task so the finished outcome is returned instead of being discarded.
  • Add compact_session_with_outcome returning BitFunResult<ContextCompactionOutcome>; compact_session_manually delegates to it for the Desktop compatibility API.
  • Extend SessionControlAction with a Compact variant and its as_str mapping.
  • Allow compacting the caller's own session (the sole self-mutation exception) while keeping owner/creator/ancestor authorization inline.
  • Wire the Compact dispatch to the compact engine and return the applied stats.
  • Extend the tool input schema/description and add compact validation tests.

Testing

AI-assisted output. Test extent: 已测 (tested).

  • cargo check -p bitfun-core --jobs 4 EXIT 0.
  • cargo check -p bitfun-agent-runtime --jobs 4 EXIT 0.
  • cargo test -p bitfun-agent-runtime --features agent-runtime compact --jobs 4 (5 tests pass).
  • cargo test -p bitfun-core --features agent-runtime session_control_tool --jobs 4 (14 tests pass, incl validate_compact_*).
  • cargo test -p bitfun-core --features agent-runtime manual_compaction --jobs 4 (6 tests pass).
  • Verified by the project maintainer on a dev instance (real compact persistence through the full compressed chain).

Skipped: no full local CI — the complete build and broad test suite are covered by the repository CI against this PR. No UI change (backend tool), so no before/after screenshots; the low-risk manual verification path is to invoke the session control tool with the compact action against a persisted session on a dev instance.

Stacked PR note

This PR is stacked on the rename PR (pr-g6-rename-rebased). It is the second of two focused PRs for the session control tool family. The repository CI runs against this branch once the base rename PR is merged and this branch is retargeted to main; while based on another open feature branch, the full CI is carried by the rename PR as the primary working surface.

Commits

  • 53f570bb9 feat(session): add compact action to session control tool — add a compact action to the session control tool that returns the applied compaction statistics.

Closes #2469

user added 2 commits August 25, 2026 08:44
Extend the session control tool family with a rename action so a caller can
rename a persisted session title through the same AgentSessionManagementPort
channel used by the frontend renameChatSessionTitle.

- Extend SessionControlAction with a Rename variant and as_str mapping.
- Allow session_name as the required new title for rename (rejected for every
  other mutating action) and reject renaming the current session.
- Add session_control_renamed_result_message helper for the tool result text.
- Wire the Rename dispatch to reuse the upstream AgentSessionRenameRequest.
- Extend the tool input schema/description and add rename validation tests.

Test: cargo check -p bitfun-agent-runtime --jobs 4 EXIT 0; cargo check -p bitfun-core --jobs 4 EXIT 0; cargo test -p bitfun-agent-runtime --features agent-runtime rename --jobs 4 (7 tests pass); cargo test -p bitfun-core --features agent-runtime session_control_tool --jobs 4 (11 tests pass incl validate_rename_*).
AI: lightly tested (targeted cargo check + session_control/session_control_tool unit tests).
Add the compact action to the session control tool family so a caller can
compact a session context to reduce its token footprint and surface the
applied compaction statistics (tokens/ratio/summary).

- Thread ContextCompactionOutcome through the manual compaction task so the
  finished outcome is returned instead of being discarded (unit).
- Add compact_session_with_outcome returning BitFunResult<ContextCompactionOutcome>;
  compact_session_manually delegates to it for the Desktop compatibility API.
- Extend SessionControlAction with a Compact variant and its as_str mapping.
- Allow compacting the caller own session (the sole self-mutation exception)
  while keeping owner/creator/ancestor authorization inline.
- Wire the Compact dispatch to the compact engine and return the applied stats.
- Extend the tool input schema/description and add compact validation tests.

Test: cargo check -p bitfun-core --jobs 4 EXIT 0; cargo check -p bitfun-agent-runtime --jobs 4 EXIT 0; cargo test -p bitfun-agent-runtime --features agent-runtime compact --jobs 4 (5 tests pass); cargo test -p bitfun-core --features agent-runtime session_control_tool --jobs 4 (14 tests pass incl validate_compact_*); cargo test -p bitfun-core --features agent-runtime manual_compaction --jobs 4 (6 tests pass).
AI: lightly tested (targeted cargo check + compact/session_control_tool/manual_compaction unit tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(session): add compact action to session control tool

1 participant