diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index 3e7d82a0e..0daa510d1 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -93,11 +93,17 @@ export const RunCommand = cmd({ UI.empty() const cfg = await Config.get() - if (cfg.share === "auto" || Flag.OPENCODE_AUTO_SHARE || (args.share && cfg.share !== "disabled")) { - await Session.share(session.id) - UI.println(UI.Style.TEXT_INFO_BOLD + "~ https://opencode.ai/s/" + session.id.slice(-8)) - } else if (args.share && cfg.share === "disabled") { - UI.println(UI.Style.TEXT_ERROR_BOLD + "! Sharing is disabled in configuration") + if (cfg.share === "auto" || Flag.OPENCODE_AUTO_SHARE || args.share) { + try { + await Session.share(session.id) + UI.println(UI.Style.TEXT_INFO_BOLD + "~ https://opencode.ai/s/" + session.id.slice(-8)) + } catch (error) { + if (error instanceof Error && error.message.includes("disabled")) { + UI.println(UI.Style.TEXT_ERROR_BOLD + "! " + error.message) + } else { + throw error + } + } } UI.empty() diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index 35a5615b2..16b9de9d3 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -150,6 +150,8 @@ export namespace Session { update(result.id, (draft) => { draft.share = share }) + }).catch(() => { + // Silently ignore sharing errors during session creation }) Bus.publish(Event.Updated, { info: result, @@ -172,6 +174,11 @@ export namespace Session { } export async function share(id: string) { + const cfg = await Config.get() + if (cfg.share === "disabled") { + throw new Error("Sharing is disabled in configuration") + } + const session = await get(id) if (session.share) return session.share const share = await Share.create(id)