Skip to content

Commit f1119cf

Browse files
taylaandclaude
andcommitted
fix: expand tilde paths in remote SSH commands
sqlite3 doesn't expand ~ when the path is shell-quoted. Added _quote_remote_path() helper that converts ~/... to "$HOME/..." for remote execution, allowing both shell expansion and safe quoting. Applied to all SSH commands in session-sync: _remote_sql(), _stream_sql_to_target(), pull delta dump, and sync delta dump. Fixes: "unable to open database ~/.config/studyctl/sessions.db" when using session-sync push/pull with named hosts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 906f974 commit f1119cf

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

  • packages/agent-session-tools/src/agent_session_tools

packages/agent-session-tools/src/agent_session_tools/sync.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,23 @@ def _resolve_remote(remote: str) -> tuple[str, str]:
144144
return host, db_path
145145

146146

147+
def _quote_remote_path(path: str) -> str:
148+
"""Quote a path for remote shell execution, expanding ~/."""
149+
if path.startswith("~/"):
150+
return f'"$HOME/{path[2:]}"'
151+
return shlex.quote(path)
152+
153+
147154
def _remote_sql(host: str, db_path: str, query: str) -> str:
148155
"""Execute a SQL query on the remote DB via SSH and return stdout."""
149156
_ensure_mux_dir()
157+
remote_path = _quote_remote_path(db_path)
150158
result = subprocess.run(
151159
[
152160
"ssh",
153161
*_SSH_MUX_OPTS,
154162
host,
155-
f"sqlite3 {shlex.quote(db_path)} {shlex.quote(query)}",
163+
f"sqlite3 {remote_path} {shlex.quote(query)}",
156164
],
157165
capture_output=True,
158166
text=True,
@@ -273,7 +281,13 @@ def _stream_sql_to_target(sql: str, target: Path | tuple[str, str]) -> bool:
273281
else:
274282
host, db_path = target
275283
result = subprocess.run(
276-
["ssh", *_SSH_MUX_OPTS, "-C", host, f"sqlite3 {shlex.quote(db_path)}"],
284+
[
285+
"ssh",
286+
*_SSH_MUX_OPTS,
287+
"-C",
288+
host,
289+
f"sqlite3 {_quote_remote_path(db_path)}",
290+
],
277291
input=sql,
278292
capture_output=True,
279293
text=True,
@@ -563,7 +577,13 @@ def sync(
563577
commands.append(f"SELECT * FROM {table};")
564578

565579
result = subprocess.run(
566-
["ssh", *_SSH_MUX_OPTS, "-C", host, f"sqlite3 {shlex.quote(remote_db)}"],
580+
[
581+
"ssh",
582+
*_SSH_MUX_OPTS,
583+
"-C",
584+
host,
585+
f"sqlite3 {_quote_remote_path(remote_db)}",
586+
],
567587
input="\n".join(commands),
568588
capture_output=True,
569589
text=True,

0 commit comments

Comments
 (0)