Просмотр исходного кода

Add autoshare configuration and improve run command UI

Enables automatic session sharing via global config or flag, enhances UI with logo display and provider/model info positioning.

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <[email protected]>
Dax Raad 8 месяцев назад
Родитель
Сommit
b5a4439704

+ 27 - 20
packages/opencode/src/cli/cmd/run.ts

@@ -7,13 +7,9 @@ import { Share } from "../../share/share"
 import { Message } from "../../session/message"
 import { UI } from "../ui"
 import { VERSION } from "../version"
-
-const COLOR = [
-  UI.Style.TEXT_SUCCESS_BOLD,
-  UI.Style.TEXT_INFO_BOLD,
-  UI.Style.TEXT_HIGHLIGHT_BOLD,
-  UI.Style.TEXT_WARNING_BOLD,
-]
+import { cmd } from "./cmd"
+import { GlobalConfig } from "../../global/config"
+import { Flag } from "../../flag/flag"
 
 const TOOL: Record<string, [string, string]> = {
   opencode_todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD],
@@ -27,7 +23,7 @@ const TOOL: Record<string, [string, string]> = {
   opencode_write: ["Write", UI.Style.TEXT_SUCCESS_BOLD],
 }
 
-export const RunCommand = {
+export const RunCommand = cmd({
   command: "run [message..]",
   describe: "Run OpenCode with a message",
   builder: (yargs: Argv) => {
@@ -42,12 +38,12 @@ export const RunCommand = {
         describe: "Session ID to continue",
         type: "string",
       })
+      .option("share", {
+        type: "boolean",
+        describe: "Share the session",
+      })
   },
-  handler: async (args: {
-    message: string[]
-    session?: string
-    printLogs?: boolean
-  }) => {
+  handler: async (args) => {
     const message = args.message.join(" ")
     await App.provide(
       {
@@ -60,14 +56,27 @@ export const RunCommand = {
           ? await Session.get(args.session)
           : await Session.create()
 
-        UI.println(UI.Style.TEXT_HIGHLIGHT_BOLD + "◍  OpenCode", VERSION)
+        UI.empty()
+        UI.println(UI.logo())
         UI.empty()
         UI.println(UI.Style.TEXT_NORMAL_BOLD + "> ", message)
         UI.empty()
+
+        const cfg = await GlobalConfig.get()
+        if (cfg.autoshare || Flag.OPENCODE_AUTO_SHARE || args.share) {
+          await Session.share(session.id)
+          UI.println(
+            UI.Style.TEXT_INFO_BOLD +
+              "~  https://dev.opencode.ai/s/" +
+              session.id.slice(-8),
+          )
+        }
+        UI.empty()
+
+        const { providerID, modelID } = await Provider.defaultModel()
         UI.println(
-          UI.Style.TEXT_INFO_BOLD +
-            "~  https://dev.opencode.ai/s/" +
-            session.id.slice(-8),
+          UI.Style.TEXT_NORMAL_BOLD + "@ ",
+          UI.Style.TEXT_NORMAL + `${providerID}/${modelID}`,
         )
         UI.empty()
 
@@ -113,8 +122,6 @@ export const RunCommand = {
             printEvent(UI.Style.TEXT_NORMAL_BOLD, "Text", part.text)
           }
         })
-
-        const { providerID, modelID } = await Provider.defaultModel()
         await Session.chat({
           sessionID: session.id,
           providerID,
@@ -130,4 +137,4 @@ export const RunCommand = {
       },
     )
   },
-}
+})

+ 1 - 0
packages/opencode/src/global/config.ts

@@ -6,6 +6,7 @@ import path from "path"
 export namespace GlobalConfig {
   export const Info = z.object({
     autoupdate: z.boolean().optional(),
+    autoshare: z.boolean().optional(),
     provider: z.string().optional(),
     model: z.string().optional(),
   })

+ 3 - 1
packages/opencode/src/session/index.ts

@@ -30,6 +30,7 @@ import type { Tool } from "../tool/tool"
 import { SystemPrompt } from "./system"
 import { Flag } from "../flag/flag"
 import type { ModelsDev } from "../provider/models"
+import { GlobalConfig } from "../global/config"
 
 export namespace Session {
   const log = Log.create({ service: "session" })
@@ -95,7 +96,8 @@ export namespace Session {
     log.info("created", result)
     state().sessions.set(result.id, result)
     await Storage.writeJSON("session/info/" + result.id, result)
-    if (!result.parentID && Flag.OPENCODE_AUTO_SHARE)
+    const cfg = await GlobalConfig.get()
+    if (!result.parentID && (Flag.OPENCODE_AUTO_SHARE || cfg.autoshare))
       share(result.id).then((share) => {
         update(result.id, (draft) => {
           draft.share = share