Skip to content

Commit 3fd6e82

Browse files
cameronrsudo-tee
authored andcommitted
fix(core): create session if no current and no last
If we're not starting a new session, we don't have a current session and we don't have a last session, we have to create a new session. Without a session, submitting prompts fails silently.
1 parent ea40422 commit 3fd6e82

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lua/opencode/core.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ function M.open(opts)
7676
else
7777
if not state.active_session then
7878
state.active_session = session.get_last_workspace_session()
79+
if not state.active_session then
80+
state.active_session = M.create_new_session()
81+
end
7982
else
8083
if not state.display_route and are_windows_closed then
8184
-- We're not displaying /help or something like that but we have an active session

tests/unit/core_spec.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ describe('opencode.core', function()
170170
assert.is_false(input_focused)
171171
assert.is_true(output_focused)
172172
end)
173+
174+
it('creates a new session when no active session and no last session exists', function()
175+
state.windows = nil
176+
state.active_session = nil
177+
session.get_last_workspace_session:revert()
178+
stub(session, 'get_last_workspace_session').returns(nil)
179+
180+
core.open({ new_session = false, focus = 'input' })
181+
182+
assert.truthy(state.active_session)
183+
assert.truthy(state.active_session.id)
184+
end)
173185
end)
174186

175187
describe('select_session', function()

0 commit comments

Comments
 (0)