Skip to content

Commit 0f9c2c5

Browse files
thdxrOpenCode
andcommitted
Add flag system and auto-share functionality
- Add Flag module for environment variable configuration - Implement OPENCODE_AUTO_SHARE flag to automatically share new sessions - Update session creation to conditionally auto-share based on flag 🤖 Generated with [OpenCode](https://opencode.ai) Co-Authored-By: OpenCode <noreply@opencode.ai>
1 parent 6a261de commit 0f9c2c5

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/opencode/src/flag/flag.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export namespace Flag {
2+
export const OPENCODE_AUTO_SHARE = truthy("OPENCODE_AUTO_SHARE")
3+
4+
function truthy(key: string) {
5+
const value = process.env[key]?.toLowerCase()
6+
return value === "true" || value === "1"
7+
}
8+
}

packages/opencode/src/session/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { MCP } from "../mcp"
2727
import { NamedError } from "../util/error"
2828
import type { Tool } from "../tool/tool"
2929
import { SystemPrompt } from "./system"
30+
import { Flag } from "../flag/flag"
3031

3132
export namespace Session {
3233
const log = Log.create({ service: "session" })
@@ -92,6 +93,12 @@ export namespace Session {
9293
log.info("created", result)
9394
state().sessions.set(result.id, result)
9495
await Storage.writeJSON("session/info/" + result.id, result)
96+
if (!result.parentID && Flag.OPENCODE_AUTO_SHARE)
97+
share(result.id).then((share) => {
98+
update(result.id, (draft) => {
99+
draft.share = share
100+
})
101+
})
95102
Bus.publish(Event.Updated, {
96103
info: result,
97104
})

0 commit comments

Comments
 (0)