11import type { SessionState } from './types.ts' ;
2+ import { shellQuoteIfNeeded } from '../utils/shell-quote.ts' ;
23
34export type SessionRecoveryContext = 'device-in-use' | 'selector-conflict' ;
45
@@ -13,6 +14,7 @@ export function buildSessionRecoveryHint(
1314 session : SessionState ,
1415 context : SessionRecoveryContext ,
1516) : string {
17+ // Active recording state controls user recovery text; record-only ownership controls cleanup.
1618 if ( session . recording ) {
1719 return buildRecordingSessionRecoveryHint ( session , context ) ;
1820 }
@@ -23,15 +25,17 @@ function buildRecordingSessionRecoveryHint(
2325 session : SessionState ,
2426 context : SessionRecoveryContext ,
2527) : string {
26- const closeCommand = `agent-device close --session ${ session . name } ` ;
28+ const sessionArg = shellQuoteIfNeeded ( session . name ) ;
29+ const closeCommand = `agent-device close --session ${ sessionArg } ` ;
30+ const recordStopCommand = `agent-device record stop --session ${ sessionArg } ` ;
2731 const reuseText =
2832 context === 'selector-conflict'
29- ? `To keep using this device, rerun the command with --session ${ session . name } and remove conflicting device selectors.`
30- : `To keep using this device, reuse --session ${ session . name } for commands that should attach to the recording session.` ;
33+ ? `To keep using this device, rerun the command with --session ${ sessionArg } and remove conflicting device selectors.`
34+ : `To keep using this device, reuse --session ${ sessionArg } for commands that should attach to the recording session.` ;
3135
3236 return (
3337 `Recording session "${ session . name } " owns this device. ` +
34- `Run agent-device record stop --session ${ session . name } ; if the session still appears in agent-device session list, run ${ closeCommand } . ` +
38+ `Run ${ recordStopCommand } ; if the session still appears in agent-device session list, run ${ closeCommand } . ` +
3539 `${ reuseText } ` +
3640 `Run agent-device session list to inspect active sessions.`
3741 ) ;
@@ -41,18 +45,19 @@ function buildOpenSessionRecoveryHint(
4145 session : SessionState ,
4246 context : SessionRecoveryContext ,
4347) : string {
44- const closeCommand = `agent-device close --session ${ session . name } ` ;
48+ const sessionArg = shellQuoteIfNeeded ( session . name ) ;
49+ const closeCommand = `agent-device close --session ${ sessionArg } ` ;
4550 if ( context === 'selector-conflict' ) {
4651 return (
4752 `Run agent-device session list to inspect active sessions. ` +
48- `To reuse this device, rerun the command with --session ${ session . name } and remove conflicting device selectors. ` +
53+ `To reuse this device, rerun the command with --session ${ sessionArg } and remove conflicting device selectors. ` +
4954 `To switch devices, first run ${ closeCommand } , then open the desired device with a different --session name.`
5055 ) ;
5156 }
5257
5358 return (
5459 `Run agent-device session list to inspect active sessions. ` +
55- `To reuse this device, rerun the command with --session ${ session . name } . ` +
60+ `To reuse this device, rerun the command with --session ${ sessionArg } . ` +
5661 `To open a new session on this device, first run ${ closeCommand } .`
5762 ) ;
5863}
0 commit comments