@@ -5,6 +5,7 @@ import { streamAgent, TASK_PROMPT } from "./agent";
55 import { getApiKey } from "./oauth";
66 import { onceEvery, secureRandomString, takeTail } from "./shared";
77 import { bash, runBashTool } from "./tool-bash";
8+import { edit, runEditTool } from "./tool-edit";
89 import { TextPill, theme } from "./tui-components";
910 import { Conversation } from "./tui-conversation";
1011 import { Editor } from "./tui-editor";
@@ -54,10 +55,10 @@ export function initTUI(state: TUIState, leave: (s: string) => void) {
5455 TextPill(state.options.model.name, theme.bblack, theme.bwhite),
5556 TextPill(`../${cwd}`, theme.bwhite, theme.bblack),
5657 VStack({ flex: 1 }, []),
58+ TextPill(state.activeState, theme.bwhite, theme.bblack),
5759 state.streaming
5860 ? TextPill(currentSpinner(), theme.bblack, theme.bwhite)
5961 : TextPill(currentSpinner(), theme.bwhite, theme.bblack),
60- TextPill(state.activeState, theme.bwhite, theme.bblack),
6162 ]),
6263
6364 Editor(
@@ -141,8 +142,12 @@ export async function streamTUI(state: TUIState) {
141142 if (state.streaming) return;
142143 state.streaming = true;
143144
145+ const lastTs = Date.now();
144146 const apiKey = await getApiKey(state.options);
145- const tools: ToolAndRunner[] = [{ tool: bash, runner: runBashTool }];
147+ const tools: ToolAndRunner[] = [
148+ { tool: bash, runner: runBashTool },
149+ { tool: edit, runner: runEditTool },
150+ ];
146151 const userPrompt = {
147152 role: "user",
148153 content: state.prompt || "",
@@ -163,7 +168,7 @@ export async function streamTUI(state: TUIState) {
163168 TASK_PROMPT,
164169 messages,
165170 state.options,
166- (ev, dur) => {
171+ (ev) => {
167172 switch (ev.type) {
168173 case "text_start":
169174 state.activeState = "answering";
@@ -184,9 +189,7 @@ export async function streamTUI(state: TUIState) {
184189 );
185190
186191 for (const call of newToolCalls) {
187- const toolMessage = createTUIToolMessage(call, {
188- durationMs: dur,
189- });
192+ const toolMessage = createTUIToolMessage(call);
190193 let found = false;
191194 state.messages = state.messages.map((msg) => {
192195 if (call.id === msg.id) {
@@ -216,14 +219,12 @@ export async function streamTUI(state: TUIState) {
216219 state.messages = state.messages.map((msg) => {
217220 if (call.id === msg.id) {
218221 updated = true;
219- return createTUIToolMessage(call, { ...msg, durationMs: dur });
222+ return createTUIToolMessage(call, msg);
220223 }
221224 return msg;
222225 });
223226 if (!updated) {
224- state.messages.push(
225- createTUIToolMessage(call, { durationMs: dur }),
226- );
227+ state.messages.push(createTUIToolMessage(call));
227228 }
228229 }
229230
@@ -242,18 +243,23 @@ export async function streamTUI(state: TUIState) {
242243 }
243244 },
244245
245- (tool, dur) => {
246+ (tool) => {
246247 // Append the output to the existing TUI messages
247248 state.messages = state.messages.map((msg) => {
248249 if (tool.toolCallId === msg.id) {
249- return createTUIToolMessage(tool, { ...msg, durationMs: dur });
250+ return createTUIToolMessage(tool, {
251+ ...msg,
252+ durationMs: Date.now() - msg.timestamp,
253+ });
250254 }
251255 return msg;
252256 });
253257 cel.render();
254258 },
255259
256- (msg, context, dur) => {
260+ (msg, context) => {
261+ const dur = Date.now() - lastTs;
262+
257263 if (msg.errorMessage) {
258264 state.messages.push({
259265 id: secureRandomString(8),