Skip to content

feat(cli): estimate and hint about Code context at Plan exit#12134

Open
cbrunnkvist wants to merge 9 commits into
Kilo-Org:mainfrom
cbrunnkvist:fix/plan-followup-code-context
Open

feat(cli): estimate and hint about Code context at Plan exit#12134
cbrunnkvist wants to merge 9 commits into
Kilo-Org:mainfrom
cbrunnkvist:fix/plan-followup-code-context

Conversation

@cbrunnkvist

@cbrunnkvist cbrunnkvist commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Closes #12135 by making the plan handoff prompt context-aware: before a finalized plan is implemented, Kilo estimates how much of the configured Code-mode model context the current session has already used.

With that estimate available, the prompt can also recommend a fresh session when continuing would be close to the automatic compaction threshold—a small but meaningful quality-of-life improvement for longer planning sessions.

Implementation

Before presenting the follow-up prompt, Kilo compares the assistant message’s token count with the configured Code-mode model’s available context and surfaces the result in the options:

  • Continue here shows the estimated context usage, for example: using 86% of Code mode context.
  • Start new session is marked (Recommended) when the estimate reaches the configured auto-compaction threshold (compaction.threshold_percent).

Screenshot

Screenshot 2026-07-12 at 12 54 34

Notes

@cbrunnkvist cbrunnkvist changed the title fix(cli): estimate Code context at plan exit fix(cli): estimate and hint about Code context at Plan exit Jul 12, 2026
@cbrunnkvist
cbrunnkvist force-pushed the fix/plan-followup-code-context branch from a9ee845 to 66f93c9 Compare July 12, 2026 11:31
@cbrunnkvist
cbrunnkvist marked this pull request as ready for review July 12, 2026 11:31
Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review at HEAD a8fa452b66af5d9a286e528a77e6e59aedaf94e2 (one new commit since the last review: "fix(plan): preserve follow-up event routing").

The new commit fully resolves the previously flagged WARNING on plan-followup.ts about publishing TuiEvent.SessionSelect through the proper pipeline:

  • Bus.publish is replaced with EventV2Bridge.Service.use((events) => events.publish(TuiEvent.SessionSelect, ...)), with InstanceRef provided via Effect.provideService, matching the established pattern used elsewhere (kilocode/config/report.ts, kilocode/config/config.ts, bus/index.ts).
  • Existing tests (plan-followup.test.ts) already subscribe to TuiEvent.SessionSelect and exercise this delivery path.

The commit also adds a reasonable optimization: resolveCodeModel is now only called eagerly when KiloSessionOverflow.count(assistant.info.tokens) is truthy (avoiding unnecessary model resolution when there's nothing to estimate), falling back to resolveCodeModel lazily when the user picks "Continue". This is consistent with estimate()'s own early-return-on-zero-tokens behavior and introduces no new issue.

No new issues found in the incremental diff.

Files Reviewed (2 files in incremental diff)
  • packages/opencode/src/kilocode/plan-followup.ts - 0 issues (previous WARNING resolved)
  • packages/opencode/test/tool/__snapshots__/parameters.test.ts.snap - generated snapshot, no issues
Previous Review Summaries (5 snapshots, latest commit 50895ae)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 50895ae)

Status: No Issues Found | Recommendation: Merge

Re-verified at HEAD 50895ae86fa70a5fb9c4dd1ebc9c6373cc9f71f5 (unchanged since the last review — no new commits). All four previously flagged WARNINGs on plan-followup.ts remain resolved:

  • The displayed percentage and the KiloSessionOverflow.limit() threshold both derive from model.limit.input || model.limit.context.
  • The fresh-session recommendation compares against KiloSessionOverflow.limit()'s usable-limit fallback instead of requiring an explicit compaction.threshold_percent.
  • Dynamic descriptions stay localized via descriptionKey/descriptionArgs, threaded through the schema, VS Code tr()/QuestionDock, and the JetBrains QuestionOption/KiloBundle.optional() path, with matching translations for every locale.
  • TuiEvent.SessionSelect is published via Bus.publish(Instance.current, ...), restoring delivery to the TUI.

No new issues found.

Files Reviewed (57 files)
  • .changeset/estimate-code-context-at-plan-exit.md
  • packages/kilo-i18n/src/*.ts (20 locales)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloCliDataParser.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloCliDataParserTest.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/plugin/KiloBundle.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/controller/SessionController.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/model/Question.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/views/question/QuestionView.kt
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle*.properties (all locales)
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/dto/ChatDto.kt
  • packages/kilo-vscode/tests/unit/plan-followup-locale-keys.test.ts
  • packages/kilo-vscode/tests/unit/question-dock-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/question-dock-utils.ts
  • packages/kilo-vscode/webview-ui/src/types/messages/questions.ts
  • packages/opencode/src/kilocode/plan-followup.ts - 0 issues (4 previous WARNINGs resolved)
  • packages/opencode/src/question/index.ts
  • packages/opencode/test/kilocode/plan-followup.test.ts
  • packages/opencode/test/kilocode/question-option-schema.test.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts - generated artifact
  • packages/sdk/openapi.json - generated artifact

Previous review (commit 076088d)

Status: No Issues Found | Recommendation: Merge

Full re-review (previous incremental base commit no longer resolvable, likely due to a rebase). All four previously flagged WARNINGs on plan-followup.ts are now fixed:

  • The displayed percentage and the KiloSessionOverflow.limit() threshold now both derive from model.limit.input || model.limit.context.
  • The fresh-session recommendation now compares against KiloSessionOverflow.limit()'s usable-limit fallback instead of requiring an explicit compaction.threshold_percent, so the default config can recommend a new session.
  • Dynamic descriptions stay localized: new descriptionKeys (plan.followup.answer.newSession.recommended.description, plan.followup.answer.continue.estimated.description) plus a new descriptionArgs field carry the percentage through the Option schema, VS Code tr()/QuestionDock, and the JetBrains QuestionOption/KiloBundle.optional() path, with matching translations added for every locale.
  • TuiEvent.SessionSelect is published via Bus.publish(Instance.current, ...) instead of the async EventV2Bridge import path, so the legacy bus event reaches the TUI again.

No new issues found in the added descriptionArgs plumbing (schema, webview, JetBrains parser/DTO/view) or the isolated test mocks.

Files Reviewed (57 files)
  • .changeset/estimate-code-context-at-plan-exit.md
  • packages/kilo-i18n/src/*.ts (20 locales)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloCliDataParser.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloCliDataParserTest.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/plugin/KiloBundle.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/controller/SessionController.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/model/Question.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/views/question/QuestionView.kt
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle*.properties (all locales)
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/dto/ChatDto.kt
  • packages/kilo-vscode/tests/unit/plan-followup-locale-keys.test.ts
  • packages/kilo-vscode/tests/unit/question-dock-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/question-dock-utils.ts
  • packages/kilo-vscode/webview-ui/src/types/messages/questions.ts
  • packages/opencode/src/kilocode/plan-followup.ts - 0 issues (4 previous WARNINGs resolved)
  • packages/opencode/src/question/index.ts
  • packages/opencode/test/kilocode/plan-followup.test.ts
  • packages/opencode/test/kilocode/question-option-schema.test.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts - generated artifact
  • packages/sdk/openapi.json - generated artifact

Previous review (commit 974406b)

Status: No Issues Found | Recommendation: Merge

Incremental review vs 9d0f9e17: the previously flagged legacy session-select event drop is now fixed — plan-followup.ts publishes TuiEvent.SessionSelect via Bus.publish(Instance.current, ...) directly instead of the async EventV2Bridge import path, matching the pattern used elsewhere in the codebase (suggestion/index.ts, network.ts). Existing tests already subscribe via Bus.subscribe(TuiEvent.SessionSelect, ...), so this now exercises the real event path. The remaining SDK diffs (types.gen.ts, openapi.json) are generated-artifact reordering with no semantic changes.

Files Reviewed (3 files)
  • packages/opencode/src/kilocode/plan-followup.ts - 0 issues (previous WARNING resolved)
  • packages/sdk/js/src/v2/gen/types.gen.ts - generated artifact, no review needed
  • packages/sdk/openapi.json - generated artifact, no review needed

Previous review (commit 9d0f9e1)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/plan-followup.ts 447 Legacy session-select event is dropped by EventV2 bridge

Fix these issues in Kilo Cloud

Files Reviewed (57 files)
  • packages/kilo-i18n/src/ar.ts - 0 issues
  • packages/kilo-i18n/src/br.ts - 0 issues
  • packages/kilo-i18n/src/bs.ts - 0 issues
  • packages/kilo-i18n/src/da.ts - 0 issues
  • packages/kilo-i18n/src/de.ts - 0 issues
  • packages/kilo-i18n/src/en.ts - 0 issues
  • packages/kilo-i18n/src/es.ts - 0 issues
  • packages/kilo-i18n/src/fr.ts - 0 issues
  • packages/kilo-i18n/src/it.ts - 0 issues
  • packages/kilo-i18n/src/ja.ts - 0 issues
  • packages/kilo-i18n/src/ko.ts - 0 issues
  • packages/kilo-i18n/src/nl.ts - 0 issues
  • packages/kilo-i18n/src/no.ts - 0 issues
  • packages/kilo-i18n/src/pl.ts - 0 issues
  • packages/kilo-i18n/src/ru.ts - 0 issues
  • packages/kilo-i18n/src/th.ts - 0 issues
  • packages/kilo-i18n/src/tr.ts - 0 issues
  • packages/kilo-i18n/src/uk.ts - 0 issues
  • packages/kilo-i18n/src/zh.ts - 0 issues
  • packages/kilo-i18n/src/zht.ts - 0 issues
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloCliDataParser.kt - 0 issues
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloCliDataParserTest.kt - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/plugin/KiloBundle.kt - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/controller/SessionController.kt - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/model/Question.kt - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/views/question/QuestionView.kt - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_ar.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_bs.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_da.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_de.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_es.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_fr.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_ja.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_ko.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_nl.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_no.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_pl.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_pt_BR.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_ru.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_th.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_tr.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_uk.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_zh_CN.properties - 0 issues
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_zh_TW.properties - 0 issues
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/dto/ChatDto.kt - 0 issues
  • packages/kilo-vscode/tests/unit/plan-followup-locale-keys.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/question-dock-utils.test.ts - 0 issues
  • packages/kilo-vscode/webview-ui/src/components/chat/QuestionDock.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/src/components/chat/question-dock-utils.ts - 0 issues
  • packages/kilo-vscode/webview-ui/src/types/messages/questions.ts - 0 issues
  • packages/opencode/src/kilocode/plan-followup.ts - 1 issue
  • packages/opencode/src/question/index.ts - 0 issues
  • packages/opencode/test/kilocode/plan-followup.test.ts - 0 issues
  • packages/opencode/test/kilocode/question-option-schema.test.ts - 0 issues
  • packages/sdk/js/src/v2/gen/types.gen.ts - 0 issues
  • packages/sdk/openapi.json - 0 issues

Previous review (commit 66f93c9)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/plan-followup.ts 243 Percentage ignores explicit model input limits
packages/opencode/src/kilocode/plan-followup.ts 249 Default compaction limit never triggers recommendation
packages/opencode/src/kilocode/plan-followup.ts 376 Dynamic descriptions bypass localization

Fix these issues in Kilo Cloud

Files Reviewed (3 files)
  • .changeset/estimate-code-context-at-plan-exit.md - 0 issues
  • packages/opencode/src/kilocode/plan-followup.ts - 3 issues
  • packages/opencode/test/kilocode/plan-followup.test.ts - 0 issues

Reviewed by claude-sonnet-5 · Input: 32 · Output: 6.3K · Cached: 758.8K

Review guidance: REVIEW.md from base branch main

Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

Okay @kilocode-bot I think you ought to be done with your review now..?

@kilo-code-bot

kilo-code-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request.

@cbrunnkvist

cbrunnkvist commented Jul 15, 2026 via email

Copy link
Copy Markdown
Contributor Author

@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

@kilocode-bot I need a fresh account-link URL; the previous link expired.

@kilo-code-bot

kilo-code-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request.

@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

@kilocode-bot I need a fresh account-link URL; the previous link expired.

@kilo-code-bot

kilo-code-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request.

@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

(this link dance is ridiculous)

@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

Access Denied

You are not a member of the organization that owns this GitHub integration.

OH NOW I GET IT, it's not for commoners. Well, never mind then @kilocode-bot.

@kilo-code-bot

kilo-code-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request.

@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

@kilocode-bot you must cancel runs/87060187791 now. The workflow has been going for 1d+ and obviously not getting anywhere.

@kilo-code-bot

kilo-code-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request.

@cbrunnkvist
cbrunnkvist marked this pull request as draft July 15, 2026 16:08
@cbrunnkvist
cbrunnkvist marked this pull request as ready for review July 15, 2026 16:08
@cbrunnkvist
cbrunnkvist force-pushed the fix/plan-followup-code-context branch from 974406b to 076088d Compare July 16, 2026 07:13
@cbrunnkvist
cbrunnkvist force-pushed the fix/plan-followup-code-context branch from 076088d to 50895ae Compare July 16, 2026 08:31
@cbrunnkvist cbrunnkvist changed the title fix(cli): estimate and hint about Code context at Plan exit feat(cli): estimate and hint about Code context at Plan exit Jul 16, 2026
@cbrunnkvist

Copy link
Copy Markdown
Contributor Author

I vote we rename this clanker always-has-to-have-the-last-word-bot 😜

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.

No Code context usage estimate at Plan follow-up step

1 participant