fix(agents): in_use_hints lists the processes holding the conversation file (lsof) (#78)
This commit is contained in:
1 parent
a3364e82e1
commit
c6eb4564d2
4 files changed
+312
-6
No files matched your search
@@ -13,6 +13,11 @@ _LEGACY_TABLES = (("message", "session_id"), ("messages", "session_id"), ("part"
|
||||
# (binary, HOME, XDG_DATA_HOME) -> the db `debug paths` printed for them.
|
||||
_DB_PATHS = {}
|
||||
|
||||
|
||||
def _is_shared_service(cmd: str) -> bool:
|
||||
"""The per-user opencode background service (`serve --service`)."""
|
||||
return "serve --service" in (cmd or "")
|
||||
|
||||
class OpenCodeAgentAdapter(BaseAgentAdapter):
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -250,6 +255,13 @@ class OpenCodeAgentAdapter(BaseAgentAdapter):
|
||||
found += rows if i == uuid else [f"{r} [child session {i}]" for r in rows]
|
||||
return found
|
||||
|
||||
def in_use_paths(self, uuid: str, ctx: DiscoveryContext) -> list:
|
||||
db = self._resolve_db(ctx)
|
||||
return [db] if db else []
|
||||
|
||||
def _holder_counts(self, cmd: str) -> bool:
|
||||
return not _is_shared_service(cmd)
|
||||
|
||||
def conversation_in_use(self, uuid: str, ctx: DiscoveryContext) -> bool:
|
||||
"""A process naming the session, or an opencode process holding the
|
||||
shared database. The per-user background service (`serve --service`)
|
||||
@@ -270,13 +282,14 @@ class OpenCodeAgentAdapter(BaseAgentAdapter):
|
||||
timeout=10).stdout
|
||||
except Exception:
|
||||
return True
|
||||
if cmd.strip() and "serve --service" not in cmd:
|
||||
if cmd.strip() and not _is_shared_service(cmd):
|
||||
return True
|
||||
return False
|
||||
|
||||
def in_use_hints(self, uuid: str, ctx: DiscoveryContext) -> list:
|
||||
db = self._resolve_db(ctx)
|
||||
return super().in_use_hints(uuid, ctx) + [
|
||||
f"another opencode session holding {self._resolve_db(ctx)}: lsof {self._resolve_db(ctx)}"]
|
||||
f"another opencode session holding {db}: lsof {db}"]
|
||||
|
||||
# opencode 2.x: the default agent is build (`--agent` is gone from the
|
||||
# TUI), and --standalone keeps the server a child of the pane's TUI
|
||||
|
||||
Reference in new issue
Block a user