@@ -1,6 +1,6 @@
11 import { cel, HStack, ProcessTerminal, VStack } from "@cel-tui/core";
2-import simpleGit from "simple-git";
32 import { compactContext, streamAgent } from "./agent";
3+import { getBranchLabel } from "./git";
44 import {
55 buildSystemPrompt,
66 injectEnvReminder,
@@ -26,9 +26,6 @@ import { Editor } from "./tui-editor";
2626 import { mainMenu } from "./tui-overlay";
2727 import type { AgentContex, ToolAndRunner, TUIState } from "./types";
2828
29-// TODO: move all git things to `git.ts`
30-const git = simpleGit();
31-
3229 function clearOrAbort(state: TUIState) {
3330 // Are we mid stream? Abort it.
3431 if (state.streaming) {
@@ -161,6 +158,10 @@ async function streamAgentTUI(state: TUIState) {
161158 });
162159 state.prompt = "";
163160
161+ // Compact at 80k tokens, the dumb zone threshold.
162+ if (estimateTokens(JSON.stringify(state.messages)) > 80000)
163+ compactContext(state.messages);
164+
164165 const systemPrompt = await buildSystemPrompt(MAIN_PROMPT);
165166 const ctx: AgentContex = {
166167 systemPrompt,
@@ -217,16 +218,7 @@ async function streamAgentTUI(state: TUIState) {
217218 // I'm not sure since it we do, there is no trace in logs about compaction
218219 // and that would mean the logs don't repesent the truth. Confusing decision.
219220 await updateSession(state.sessionId, state.messages);
220-
221- // Compact after saving, if the next turn fails because of compaction, the session is recoverable.
222- // Compact at 80k tokens, the dumb zone threshold.
223- if (estimateTokens(JSON.stringify(state.messages)) > 80000)
224- compactContext(state.messages);
225221 }
226222
227- try {
228- const gitStatus = (await git.status()).isClean() ? "" : "*";
229- const gitBranch = (await git.branch()).current;
230- state.gitBranch = `${gitBranch}${gitStatus}`;
231- } catch (_) {}
223+ state.gitBranch = await getBranchLabel();
232224 }