summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-26 17:31:50 -0400
committerDax Raad <[email protected]>2025-06-26 17:32:00 -0400
commit4bc651f9587802d35ad5458491691a6b5c6e7844 (patch)
tree8cceadd2f24683a37a96a62d9787fd7272cad207
parent3b6976a9c88351d30d93f55f478d65eaa0085da7 (diff)
downloadopencode-4bc651f9587802d35ad5458491691a6b5c6e7844.tar.gz
opencode-4bc651f9587802d35ad5458491691a6b5c6e7844.zip
fix: improve JSON formatting and add piped output support for run command
🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
-rw-r--r--packages/opencode/package.json3
-rw-r--r--packages/opencode/src/cli/cmd/run.ts21
2 files changed, 17 insertions, 7 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json
index 4ab50c72d..6ccf2f969 100644
--- a/packages/opencode/package.json
+++ b/packages/opencode/package.json
@@ -1,6 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
- "version": "0.0.5", "name": "opencode",
+ "version": "0.0.5",
+ "name": "opencode",
"type": "module",
"private": true,
"scripts": {
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts
index c9ce3d4a2..d811a51ef 100644
--- a/packages/opencode/src/cli/cmd/run.ts
+++ b/packages/opencode/src/cli/cmd/run.ts
@@ -79,6 +79,8 @@ export const RunCommand = cmd({
return
}
+ const isPiped = !process.stdout.isTTY
+
UI.empty()
UI.println(UI.logo())
UI.empty()
@@ -90,8 +92,8 @@ export const RunCommand = cmd({
await Session.share(session.id)
UI.println(
UI.Style.TEXT_INFO_BOLD +
- "~ https://opencode.ai/s/" +
- session.id.slice(-8),
+ "~ https://opencode.ai/s/" +
+ session.id.slice(-8),
)
}
UI.empty()
@@ -109,8 +111,8 @@ export const RunCommand = cmd({
UI.println(
color + `|`,
UI.Style.TEXT_NORMAL +
- UI.Style.TEXT_DIM +
- ` ${type.padEnd(7, " ")}`,
+ UI.Style.TEXT_DIM +
+ ` ${type.padEnd(7, " ")}`,
"",
UI.Style.TEXT_NORMAL + title,
)
@@ -134,7 +136,7 @@ export const RunCommand = cmd({
part.toolInvocation.toolName,
UI.Style.TEXT_INFO_BOLD,
]
- printEvent(color, tool, metadata?.title || 'Unknown')
+ printEvent(color, tool, metadata?.title || "Unknown")
}
if (part.type === "text") {
@@ -147,7 +149,8 @@ export const RunCommand = cmd({
printEvent(UI.Style.TEXT_NORMAL_BOLD, "Text", part.text)
}
})
- await Session.chat({
+
+ const result = await Session.chat({
sessionID: session.id,
providerID,
modelID,
@@ -158,8 +161,14 @@ export const RunCommand = cmd({
},
],
})
+
+ if (isPiped) {
+ const match = result.parts.findLast((x) => x.type === "text")
+ if (match) process.stdout.write(match.text)
+ }
UI.empty()
},
)
},
})
+