-
Notifications
You must be signed in to change notification settings - Fork 96
Add a Resume Session button to the transcript HTML toolbar #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,53 @@ def get_project_display_name( | |
| return best_working_dir(project_dir_name, working_directories)[0] | ||
|
|
||
|
|
||
| # The resume command is pasted into a shell, and transcript fields are | ||
| # untrusted input (same threat model as the HTML escaping in #245) — so | ||
| # both values are held to conservative charsets and the button is | ||
| # skipped entirely rather than risk smuggling shell syntax. | ||
| _RESUME_SESSION_ID_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*") | ||
| # Inside double quotes, cmd still expands %var% / delayed-expansion | ||
| # !var!, and PowerShell expands $var and `x escapes; a literal " would | ||
| # end the quoting altogether. | ||
| _WINDOWS_CWD_UNSAFE_RE = re.compile(r'["%!$`]') | ||
|
|
||
|
|
||
| def resume_command_for_session(session_id: str, cwd: Optional[str]) -> Optional[str]: | ||
| """Build a shell one-liner that resumes ``session_id`` in Claude Code. | ||
|
|
||
| ``cwd`` is the session's recorded working directory; the command | ||
| changes there first so ``claude -r`` runs in the right project. | ||
| Quoting follows the OS the *transcript* was recorded on (detected | ||
| from the path shape, like :func:`path_looks_absolute`), not the | ||
| host rendering the HTML — a Windows-recorded session must be | ||
| resumed in a Windows shell regardless of where the page is viewed. | ||
|
|
||
| Returns a bare ``claude -r`` command when no cwd was recorded, and | ||
| ``None`` (no button) when the session id or a Windows cwd contains | ||
| characters a shell could interpret. Newlines are rejected in every | ||
| position: pasting a multi-line clipboard can execute each line | ||
| immediately, so quoting alone is no defence. | ||
| """ | ||
| if not _RESUME_SESSION_ID_RE.fullmatch(session_id): | ||
| return None | ||
| if not cwd: | ||
| return f"claude -r {session_id}" | ||
| if "\n" in cwd or "\r" in cwd: | ||
| return None | ||
| from pathlib import PureWindowsPath | ||
|
|
||
| if PureWindowsPath(cwd).drive: | ||
| if _WINDOWS_CWD_UNSAFE_RE.search(cwd): | ||
| return None | ||
| # Windows shells (PowerShell 7+, cmd): double quotes handle | ||
| # spaces; backslashes are literal inside them. | ||
| return f'cd "{cwd}" && claude -r {session_id}' | ||
|
Comment on lines
+250
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Use a command that changes the Windows drive.
Generate syntax that works in each declared shell, such as 🤖 Prompt for AI Agents |
||
| # POSIX shells: shlex protects spaces and metacharacters. | ||
| import shlex | ||
|
|
||
| return f"cd {shlex.quote(cwd)} && claude -r {session_id}" | ||
|
|
||
|
|
||
| def path_looks_absolute(s: str) -> bool: | ||
| """True if ``s`` looks like an absolute path on either POSIX or | ||
| Windows. Decoupled from the host OS so JSONL-stored cwds don't | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the Stylelint font-family violation.
Line 374 quotes
SFMono-Regular, but the configured Stylelint rule rejects these quotes. Remove them so linting passes.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Stylelint (17.14.1)
[error] 374-374: Expected no quotes around "SFMono-Regular" (font-family-name-quotes)
(font-family-name-quotes)
🤖 Prompt for AI Agents
Source: Linters/SAST tools