Skip to content

Add token economy composer mode / 增加省 token 协作模式#4151

Merged
esengine merged 2 commits into
main-v2from
feature/token-economy-mode
Jun 12, 2026
Merged

Add token economy composer mode / 增加省 token 协作模式#4151
esengine merged 2 commits into
main-v2from
feature/token-economy-mode

Conversation

@SivanCola

@SivanCola SivanCola commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

#4071 has already landed in main-v2. This PR is now rebased directly on the latest main-v2 and should be reviewed as the follow-up delta that adds a desktop/composer token economy mode. The goal is to keep the first provider-visible request lean for economy sessions while preserving the existing full/default request shape.

What changed

  • Added a TokenMode boot profile:
    • full / empty keeps the existing default capability surface.
    • economy keeps only core coding tools visible at boot and moves optional sources behind connect_tool_source.
  • Added connect_tool_source for economy mode to enable optional capabilities on demand:
    • skills
    • MCP servers, including enabled built-in MCP servers
    • CodeGraph
    • LSP
    • web_fetch
    • install_source
    • task
  • Kept cache-sensitive behavior explicit:
    • full mode and default mode now have a request snapshot regression test that compares the system prompt, tool schema order, and complete provider-visible schemas.
    • economy mode has a fixed first-request tool list/order regression test.
    • skills index, MCP tools, CodeGraph steering, LSP tools, task, web_fetch, and install_source are hidden from the economy first request until explicitly enabled.
  • Added desktop tab support for token mode:
    • persisted per tab only when set to economy
    • inherited by new blank sessions
    • included in Meta and TabMeta
    • rebuilds the controller when changed so the provider sees the new request profile
    • rejects switching while a turn is running
  • Reworked composer state into a single ComposerProfile model:
    • keeps collaboration mode, tool approval mode, token mode, goal, and goal draft state independent
    • prevents stale backend tab/meta hydration from erasing a pending local plan/token/goal selection
    • replaces the narrower goalDraftMode helper and test
  • Added desktop UI affordances:
    • token saver item in the collaboration menu
    • active token saver chip in the composer control row
    • localized English and Chinese copy
    • CSS sizing so plan/goal/token chips do not truncate or shift the toolbar
  • Added docs:
    • docs/COLLABORATION_MODES.zh-CN.md
    • docs/TOOL_APPROVAL_MODES.zh-CN.md
    • linked both from docs/GUIDE.zh-CN.md

Cache behavior

This intentionally creates two stable request profiles rather than mutating the existing full profile:

  • Existing default/full mode should keep the same provider-visible system prompt and tool schemas.
  • Economy mode uses a smaller first-request prefix by omitting optional skills/MCP/CodeGraph/LSP/tool schemas up front.
  • Optional capabilities are enabled only after connect_tool_source, so later turns pay for them only when the task actually needs them.

Rebase update

After #4071 was merged, this branch was rebased with only the token economy commit on top of the latest main-v2. The PR diff now excludes the history/memory retrieval implementation from #4071 and contains only the token economy follow-up changes.

Validation

Passed:

  • git diff --check
  • go test ./internal/boot -count=1
  • go test ./... from desktop/
  • pnpm --dir desktop/frontend test:typecheck
  • pnpm --dir desktop/frontend test
  • pnpm --dir desktop/frontend check:css

Local environment notes:

  • go test ./... with the normal user environment failed only because machine-local MCP configuration polluted internal/control TestRemoveMCPServerRemovesUnconnectedLazyPlaceholder.
  • Re-running go test ./... with an isolated home removed that MCP-config failure; the remaining local failures were macOS sandbox confinement tests (internal/sandbox TestSandboxEnforcesWrites and internal/tool/builtin TestBashSandboxConfinement) where this host did not deny writes outside the sandbox root. Those failures are unrelated to this token economy change.

@SivanCola SivanCola requested a review from esengine as a code owner June 12, 2026 08:10
@github-actions github-actions Bot added desktop Wails desktop app (desktop/**) skills Skill system (internal/skill, internal/tool) config Configuration & setup (internal/config) labels Jun 12, 2026
Base automatically changed from feature/history-memory-retrieval to main-v2 June 12, 2026 08:12
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 12, 2026
@SivanCola SivanCola force-pushed the feature/token-economy-mode branch from af98812 to 254f870 Compare June 12, 2026 08:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af98812842

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread desktop/app.go Outdated
Comment thread internal/boot/token_profile.go Outdated
Comment thread internal/boot/boot.go
Comment thread desktop/frontend/src/lib/useController.ts
@github-actions github-actions Bot added the agent Core agent loop (internal/agent, internal/control) label Jun 12, 2026
@esengine esengine merged commit 8572ae5 into main-v2 Jun 12, 2026
13 checks passed
@esengine esengine deleted the feature/token-economy-mode branch June 12, 2026 08:46
@esengine

Copy link
Copy Markdown
Owner

Merged — another excellent one, and thanks for the clean rebase onto main-v2 after #4071 landed.

I measured the effect end-to-end: economy cuts the first-request prefix ~56% on a lean project (37 tools / ~11.8k tok → 20 / ~5.2k) and more as skills/MCP/CodeGraph/LSP stack up — the economy prefix stays flat while full grows. That's exactly the lever this project is built around.

What I appreciated most: the default/full profile is provably byte-identical (full == default on the complete provider-visible schemas, not just names), so existing users' cache is untouched — and you fenced both profiles with regression tests. The connect-on-demand round-trip is the right tradeoff for the lean-coding common case.

One note for the record (not a change request): in economy the agent spends a turn on connect_tool_source before using an optional source, so very tool-heavy sessions recover less of the saving — might be worth a sentence in the docs if you revisit. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) config Configuration & setup (internal/config) desktop Wails desktop app (desktop/**) skills Skill system (internal/skill, internal/tool) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants