wip: bash

This commit is contained in:
Dax Raad
2025-08-13 14:14:17 -04:00
parent 2e5fdd8cef
commit e729eed34d

View File

@@ -1,4 +1,5 @@
import path from "path" import path from "path"
import { exec } from "child_process"
import { Decimal } from "decimal.js" import { Decimal } from "decimal.js"
import { z, ZodSchema } from "zod" import { z, ZodSchema } from "zod"
import { import {
@@ -43,7 +44,6 @@ import { Plugin } from "../plugin"
import { Agent } from "../agent/agent" import { Agent } from "../agent/agent"
import { Permission } from "../permission" import { Permission } from "../permission"
import { Wildcard } from "../util/wildcard" import { Wildcard } from "../util/wildcard"
import { BashTool } from "../tool/bash"
import { ulid } from "ulid" import { ulid } from "ulid"
export namespace Session { export namespace Session {
@@ -967,7 +967,7 @@ export namespace Session {
content: x, content: x,
}), }),
), ),
...MessageV2.toModelMessage(msgs), ...MessageV2.toModelMessage(msgs.filter((m) => !(m.info.role === "assistant" && m.info.error))),
], ],
tools: model.info.tool_call === false ? undefined : tools, tools: model.info.tool_call === false ? undefined : tools,
model: wrapLanguageModel({ model: wrapLanguageModel({
@@ -1049,27 +1049,41 @@ export namespace Session {
}, },
} }
await updatePart(part) await updatePart(part)
const tool = await BashTool.init() const app = App.info()
const result = await tool.execute( const process = exec(input.command, {
{ cwd: app.path.cwd,
command: input.command, signal: abort.signal,
description: "User command", })
},
{ let output = ""
messageID: msg.id,
sessionID: input.sessionID, process.stdout?.on("data", (chunk) => {
abort: abort.signal, output += chunk.toString()
callID: part.callID, if (part.state.status === "running") {
agent: input.agent, part.state.metadata = {
metadata: async (e) => { output: output,
if (part.state.status === "running") { description: "",
part.state.title = e.title }
part.state.metadata = e.metadata updatePart(part)
await updatePart(part) }
} })
},
}, process.stderr?.on("data", (chunk) => {
) output += chunk.toString()
if (part.state.status === "running") {
part.state.metadata = {
output: output,
description: "",
}
updatePart(part)
}
})
await new Promise<void>((resolve) => {
process.on("close", () => {
resolve()
})
})
msg.time.completed = Date.now() msg.time.completed = Date.now()
await updateMessage(msg) await updateMessage(msg)
if (part.state.status === "running") { if (part.state.status === "running") {
@@ -1080,9 +1094,12 @@ export namespace Session {
end: Date.now(), end: Date.now(),
}, },
input: part.state.input, input: part.state.input,
title: result.title, title: "",
metadata: result.metadata, metadata: {
output: result.output, output,
description: "",
},
output,
} }
await updatePart(part) await updatePart(part)
} }