Skip to content

refactor: extract ambient Kilo UI controller - #37

Merged
filiplajszczak merged 2 commits into
masterfrom
refactor/extract-ambient-ui
Oct 1, 2026
Merged

filiplajszczak merged 2 commits into
masterfrom
refactor/extract-ambient-ui

Conversation

@filiplajszczak

Copy link
Copy Markdown
Contributor

Second slice of the src/index.ts breakup, after #36. This replaces the three copies of the usage-and-credits refresh in session_start, model_select and turn_end with one controller in src/ambient-ui.ts. That controller covers the custom footer, the status updates and the check that drops stale results. formatCredits() moves to src/format.ts.

  • Removes the unreachable catch blocks around fetchKiloBalance() and the redundant model_select provider check. One catch stays in the controller.
  • One small change: model_select now checks ctx.model before refreshing usage and requesting the balance, not only before publishing credits. Pi updates the model before emitting the event, so in practice nothing changes.
  • New tests: test/ambient-ui.test.ts and test/format.test.ts. Existing test/index.test.ts tests pass unchanged.
  • src/index.ts: 432 → 338 lines; uncovered branches 25 → 13.

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.
@filiplajszczak
filiplajszczak merged commit 4c361a6 into master Oct 1, 2026
3 checks passed
@caseneuve
caseneuve deleted the refactor/extract-ambient-ui branch October 2, 2026 08:43
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.

2 participants