Enable session persistence with --continue and instruct model to complete tool loops fully

This commit is contained in:
Adolfo Reyna
2026-08-07 19:36:36 -04:00
parent f0be1a8cdf
commit 116e2e3763
2 changed files with 17 additions and 7 deletions
+15 -6
View File
@@ -92,6 +92,7 @@ class OpenCodeLLM(FrameProcessor):
self._turn_task: asyncio.Task | None = None
self._history: list[dict[str, str]] = []
self._cli_path = find_opencode_cli() or "opencode"
self._has_session = False
async def process_frame(self, frame: Frame, direction: FrameDirection):
await super().process_frame(frame, direction)
@@ -154,19 +155,27 @@ class OpenCodeLLM(FrameProcessor):
await self.push_frame(LLMFullResponseStartFrame())
chunks: list[str] = []
# Use --continue for subsequent turns to persist tool session state
cmd = [
self._cli_path,
"run",
"-m", self._model,
"--dir", str(self._cwd),
"--auto",
]
if self._has_session:
cmd.append("--continue")
cmd.append(prompt_str)
try:
proc = await asyncio.create_subprocess_exec(
self._cli_path,
"run",
"-m", self._model,
"--dir", str(self._cwd),
"--auto",
prompt_str,
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
stdin=asyncio.subprocess.DEVNULL,
cwd=str(self._cwd),
)
self._has_session = True
async def _read_stderr(stream):
while True: