Added sharing config with auto/disabled options

Co-authored-by: thdxr <thdxr@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot] 2025-07-13 20:36:33 +00:00
parent 177bfed93e
commit 98dae7974f
3 changed files with 16 additions and 3 deletions

View file

@ -93,9 +93,11 @@ export const RunCommand = cmd({
UI.empty()
const cfg = await Config.get()
if (cfg.autoshare || Flag.OPENCODE_AUTO_SHARE || args.share) {
if (Config.isSharingEnabled(cfg) || Flag.OPENCODE_AUTO_SHARE || (args.share && cfg.sharing !== "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.sharing === "disabled") {
UI.println(UI.Style.TEXT_ERROR_BOLD + "! Sharing is disabled in configuration")
}
UI.empty()

View file

@ -117,7 +117,8 @@ export namespace Config {
$schema: z.string().optional().describe("JSON schema reference for configuration validation"),
theme: z.string().optional().describe("Theme name to use for the interface"),
keybinds: Keybinds.optional().describe("Custom keybind configurations"),
autoshare: z.boolean().optional().describe("Share newly created sessions automatically"),
sharing: z.enum(["auto", "disabled"]).optional().describe("Control sharing behavior: 'auto' enables automatic sharing, 'disabled' disables all sharing"),
autoshare: z.boolean().optional().describe("@deprecated Use 'sharing' field instead. Share newly created sessions automatically"),
autoupdate: z.boolean().optional().describe("Automatically update to the latest version"),
disabled_providers: z.array(z.string()).optional().describe("Disable providers that are loaded automatically"),
model: z.string().describe("Model to use in the format of provider/model, eg anthropic/claude-2").optional(),
@ -258,4 +259,14 @@ export namespace Config {
export function get() {
return state()
}
export function isSharingEnabled(config: Info): boolean {
// If sharing is explicitly set, use that value
if (config.sharing !== undefined) {
return config.sharing === "auto"
}
// Fall back to deprecated autoshare field for backward compatibility
return config.autoshare === true
}
}

View file

@ -145,7 +145,7 @@ export namespace Session {
state().sessions.set(result.id, result)
await Storage.writeJSON("session/info/" + result.id, result)
const cfg = await Config.get()
if (!result.parentID && (Flag.OPENCODE_AUTO_SHARE || cfg.autoshare))
if (!result.parentID && (Flag.OPENCODE_AUTO_SHARE || Config.isSharingEnabled(cfg)))
share(result.id).then((share) => {
update(result.id, (draft) => {
draft.share = share