|
@@ -6,6 +6,7 @@ import { Provider } from "../../provider/provider"
|
|
|
import { Session } from "../../session"
|
|
import { Session } from "../../session"
|
|
|
import { Share } from "../../share/share"
|
|
import { Share } from "../../share/share"
|
|
|
import { Message } from "../../session/message"
|
|
import { Message } from "../../session/message"
|
|
|
|
|
+import { UI } from "../ui"
|
|
|
|
|
|
|
|
export const RunCommand = {
|
|
export const RunCommand = {
|
|
|
command: "run [message..]",
|
|
command: "run [message..]",
|
|
@@ -31,52 +32,25 @@ export const RunCommand = {
|
|
|
? await Session.get(args.session)
|
|
? await Session.get(args.session)
|
|
|
: await Session.create()
|
|
: await Session.create()
|
|
|
|
|
|
|
|
- const styles = {
|
|
|
|
|
- TEXT_HIGHLIGHT: "\x1b[96m",
|
|
|
|
|
- TEXT_HIGHLIGHT_BOLD: "\x1b[96m\x1b[1m",
|
|
|
|
|
- TEXT_DIM: "\x1b[90m",
|
|
|
|
|
- TEXT_DIM_BOLD: "\x1b[90m\x1b[1m",
|
|
|
|
|
- TEXT_NORMAL: "\x1b[0m",
|
|
|
|
|
- TEXT_NORMAL_BOLD: "\x1b[1m",
|
|
|
|
|
- TEXT_WARNING: "\x1b[93m",
|
|
|
|
|
- TEXT_WARNING_BOLD: "\x1b[93m\x1b[1m",
|
|
|
|
|
- TEXT_DANGER: "\x1b[91m",
|
|
|
|
|
- TEXT_DANGER_BOLD: "\x1b[91m\x1b[1m",
|
|
|
|
|
- TEXT_SUCCESS: "\x1b[92m",
|
|
|
|
|
- TEXT_SUCCESS_BOLD: "\x1b[92m\x1b[1m",
|
|
|
|
|
- TEXT_INFO: "\x1b[94m",
|
|
|
|
|
- TEXT_INFO_BOLD: "\x1b[94m\x1b[1m",
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- let isEmpty = false
|
|
|
|
|
- function stderr(...message: string[]) {
|
|
|
|
|
- isEmpty = true
|
|
|
|
|
- Bun.stderr.write(message.join(" "))
|
|
|
|
|
- Bun.stderr.write("\n")
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- function empty() {
|
|
|
|
|
- stderr("" + styles.TEXT_NORMAL)
|
|
|
|
|
- isEmpty = true
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- stderr(styles.TEXT_HIGHLIGHT_BOLD + "◍ OpenCode", version)
|
|
|
|
|
- empty()
|
|
|
|
|
- stderr(styles.TEXT_NORMAL_BOLD + "> ", message)
|
|
|
|
|
- empty()
|
|
|
|
|
- stderr(
|
|
|
|
|
- styles.TEXT_INFO_BOLD +
|
|
|
|
|
|
|
+ UI.print(UI.Style.TEXT_HIGHLIGHT_BOLD + "◍ OpenCode", version)
|
|
|
|
|
+ UI.empty()
|
|
|
|
|
+ UI.print(UI.Style.TEXT_NORMAL_BOLD + "> ", message)
|
|
|
|
|
+ UI.empty()
|
|
|
|
|
+ UI.print(
|
|
|
|
|
+ UI.Style.TEXT_INFO_BOLD +
|
|
|
"~ https://dev.opencode.ai/s?id=" +
|
|
"~ https://dev.opencode.ai/s?id=" +
|
|
|
session.id.slice(-8),
|
|
session.id.slice(-8),
|
|
|
)
|
|
)
|
|
|
- empty()
|
|
|
|
|
|
|
+ UI.empty()
|
|
|
|
|
|
|
|
function printEvent(color: string, type: string, title: string) {
|
|
function printEvent(color: string, type: string, title: string) {
|
|
|
- stderr(
|
|
|
|
|
|
|
+ UI.print(
|
|
|
color + `|`,
|
|
color + `|`,
|
|
|
- styles.TEXT_NORMAL + styles.TEXT_DIM + ` ${type.padEnd(7, " ")}`,
|
|
|
|
|
|
|
+ UI.Style.TEXT_NORMAL + UI.Style.TEXT_DIM + ` ${type.padEnd(7, " ")}`,
|
|
|
"",
|
|
"",
|
|
|
- styles.TEXT_NORMAL + title,
|
|
|
|
|
|
|
+ UI.Style.TEXT_NORMAL + title,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,25 +61,21 @@ export const RunCommand = {
|
|
|
part.toolInvocation.state === "result"
|
|
part.toolInvocation.state === "result"
|
|
|
) {
|
|
) {
|
|
|
if (part.toolInvocation.toolName === "opencode_todowrite") return
|
|
if (part.toolInvocation.toolName === "opencode_todowrite") return
|
|
|
- const messages = await Session.messages(session.id)
|
|
|
|
|
- const metadata =
|
|
|
|
|
- messages[messages.length - 1].metadata.tool[
|
|
|
|
|
- part.toolInvocation.toolCallId
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+
|
|
|
const args = part.toolInvocation.args as any
|
|
const args = part.toolInvocation.args as any
|
|
|
const tool = part.toolInvocation.toolName
|
|
const tool = part.toolInvocation.toolName
|
|
|
|
|
|
|
|
if (tool === "opencode_edit")
|
|
if (tool === "opencode_edit")
|
|
|
- printEvent(styles.TEXT_SUCCESS_BOLD, "Edit", args.filePath)
|
|
|
|
|
|
|
+ printEvent(UI.Style.TEXT_SUCCESS_BOLD, "Edit", args.filePath)
|
|
|
if (tool === "opencode_bash")
|
|
if (tool === "opencode_bash")
|
|
|
- printEvent(styles.TEXT_WARNING_BOLD, "Execute", args.command)
|
|
|
|
|
|
|
+ printEvent(UI.Style.TEXT_WARNING_BOLD, "Execute", args.command)
|
|
|
if (tool === "opencode_read")
|
|
if (tool === "opencode_read")
|
|
|
- printEvent(styles.TEXT_INFO_BOLD, "Read", args.filePath)
|
|
|
|
|
|
|
+ printEvent(UI.Style.TEXT_INFO_BOLD, "Read", args.filePath)
|
|
|
if (tool === "opencode_write")
|
|
if (tool === "opencode_write")
|
|
|
- printEvent(styles.TEXT_SUCCESS_BOLD, "Create", args.filePath)
|
|
|
|
|
|
|
+ printEvent(UI.Style.TEXT_SUCCESS_BOLD, "Create", args.filePath)
|
|
|
if (tool === "opencode_glob")
|
|
if (tool === "opencode_glob")
|
|
|
printEvent(
|
|
printEvent(
|
|
|
- styles.TEXT_INFO_BOLD,
|
|
|
|
|
|
|
+ UI.Style.TEXT_INFO_BOLD,
|
|
|
"Glob",
|
|
"Glob",
|
|
|
args.pattern + (args.path ? " in " + args.path : ""),
|
|
args.pattern + (args.path ? " in " + args.path : ""),
|
|
|
)
|
|
)
|
|
@@ -113,17 +83,17 @@ export const RunCommand = {
|
|
|
|
|
|
|
|
if (part.type === "text") {
|
|
if (part.type === "text") {
|
|
|
if (part.text.includes("\n")) {
|
|
if (part.text.includes("\n")) {
|
|
|
- empty()
|
|
|
|
|
- stderr(part.text)
|
|
|
|
|
- empty()
|
|
|
|
|
|
|
+ UI.empty()
|
|
|
|
|
+ UI.print(part.text)
|
|
|
|
|
+ UI.empty()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- printEvent(styles.TEXT_NORMAL_BOLD, "Text", part.text)
|
|
|
|
|
|
|
+ printEvent(UI.Style.TEXT_NORMAL_BOLD, "Text", part.text)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const { providerID, modelID } = await Provider.defaultModel()
|
|
const { providerID, modelID } = await Provider.defaultModel()
|
|
|
- const result = await Session.chat({
|
|
|
|
|
|
|
+ await Session.chat({
|
|
|
sessionID: session.id,
|
|
sessionID: session.id,
|
|
|
providerID,
|
|
providerID,
|
|
|
modelID,
|
|
modelID,
|
|
@@ -134,7 +104,7 @@ export const RunCommand = {
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
})
|
|
})
|
|
|
- empty()
|
|
|
|
|
|
|
+ UI.empty()
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|