Repository navigation
refactor: extract ambient Kilo UI controller - #37
Merged
Merged
Conversation
Typecheck is skipped for this commit because src/ambient-ui.ts and formatCredits do not exist yet.
Move footer reconciliation, status clearing, the stale-refresh revision guard and the usage/credits refresh into src/ambient-ui.ts, with visibility and footer decisions as pure functions. formatCredits moves to src/format.ts. The three copies of the refresh logic in session_start, model_select and turn_end become one controller method. The unreachable catch blocks around fetchKiloBalance and the redundant model_select provider check are removed; a single catch remains inside the controller so an injected balance fetcher can never reject a Pi lifecycle handler.
caseneuve
approved these changes
Oct 1, 2026
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.
Second slice of the
src/index.tsbreakup, after #36. This replaces the three copies of the usage-and-credits refresh insession_start,model_selectandturn_endwith one controller insrc/ambient-ui.ts. That controller covers the custom footer, the status updates and the check that drops stale results.formatCredits()moves tosrc/format.ts.catchblocks aroundfetchKiloBalance()and the redundantmodel_selectprovider check. Onecatchstays in the controller.model_selectnow checksctx.modelbefore refreshing usage and requesting the balance, not only before publishing credits. Pi updates the model before emitting the event, so in practice nothing changes.test/ambient-ui.test.tsandtest/format.test.ts. Existingtest/index.test.tstests pass unchanged.src/index.ts: 432 → 338 lines; uncovered branches 25 → 13.