@@ -8,9 +8,16 @@ type AgentModelInfo = { id: string; name?: string };
88export type SessionConfig = {
99 agentMode : string ;
1010 model : string ;
11+ cwd : string ;
1112} ;
1213
1314const CUSTOM_MODEL_VALUE = "__custom__" ;
15+ const DEFAULT_CWD = "/" ;
16+ const LAST_CWD_KEY = "sandbox-agent-inspector-last-cwd" ;
17+
18+ type InspectorRuntimeConfig = {
19+ defaultCwd ?: string ;
20+ } ;
1421
1522const agentLabels : Record < string , string > = {
1623 claude : "Claude Code" ,
@@ -29,6 +36,56 @@ const agentLogos: Record<string, string> = {
2936 pi : `${ import . meta. env . BASE_URL } logos/pi.svg` ,
3037} ;
3138
39+ function normalizeCwd ( value : string | null | undefined ) {
40+ if ( ! value ) {
41+ return null ;
42+ }
43+
44+ const trimmed = value . trim ( ) ;
45+ return trimmed ? trimmed : null ;
46+ }
47+
48+ function getQueryDefaultCwd ( ) {
49+ if ( typeof window === "undefined" ) {
50+ return null ;
51+ }
52+
53+ const params = new URLSearchParams ( window . location . search ) ;
54+ return normalizeCwd ( params . get ( "cwd" ) ) ?? normalizeCwd ( params . get ( "defaultCwd" ) ) ;
55+ }
56+
57+ function getRuntimeDefaultCwd ( ) {
58+ if ( typeof window === "undefined" ) {
59+ return null ;
60+ }
61+
62+ const runtimeWindow = window as typeof window & {
63+ __SANDBOX_AGENT_INSPECTOR_CONFIG__ ?: InspectorRuntimeConfig ;
64+ } ;
65+ return normalizeCwd ( runtimeWindow . __SANDBOX_AGENT_INSPECTOR_CONFIG__ ?. defaultCwd ) ;
66+ }
67+
68+ function getStoredCwd ( ) {
69+ if ( typeof window === "undefined" ) {
70+ return null ;
71+ }
72+
73+ try {
74+ return normalizeCwd ( window . localStorage . getItem ( LAST_CWD_KEY ) ) ;
75+ } catch { }
76+
77+ return null ;
78+ }
79+
80+ function getInitialCwd ( ) {
81+ return (
82+ getQueryDefaultCwd ( ) ??
83+ getRuntimeDefaultCwd ( ) ??
84+ getStoredCwd ( ) ??
85+ DEFAULT_CWD
86+ ) ;
87+ }
88+
3289const SessionCreateMenu = ( {
3390 agents,
3491 agentsLoading,
@@ -58,6 +115,7 @@ const SessionCreateMenu = ({
58115 const [ selectedModel , setSelectedModel ] = useState ( "" ) ;
59116 const [ customModel , setCustomModel ] = useState ( "" ) ;
60117 const [ isCustomModel , setIsCustomModel ] = useState ( false ) ;
118+ const [ cwd , setCwd ] = useState ( getInitialCwd ) ;
61119 const [ creating , setCreating ] = useState ( false ) ;
62120
63121 // Reset state when menu closes
@@ -69,6 +127,7 @@ const SessionCreateMenu = ({
69127 setSelectedModel ( "" ) ;
70128 setCustomModel ( "" ) ;
71129 setIsCustomModel ( false ) ;
130+ setCwd ( getInitialCwd ( ) ) ;
72131 setCreating ( false ) ;
73132 }
74133 } , [ open ] ) ;
@@ -138,12 +197,17 @@ const SessionCreateMenu = ({
138197 } ;
139198
140199 const resolvedModel = isCustomModel ? customModel : selectedModel ;
200+ const resolvedCwd = cwd . trim ( ) || getInitialCwd ( ) ;
141201
142202 const handleCreate = async ( ) => {
143203 if ( ! selectedAgent ) return ;
144204 setCreating ( true ) ;
145205 try {
146- await onCreateSession ( selectedAgent , { agentMode, model : resolvedModel } ) ;
206+ try {
207+ window . localStorage . setItem ( LAST_CWD_KEY , resolvedCwd ) ;
208+ } catch { }
209+
210+ await onCreateSession ( selectedAgent , { agentMode, model : resolvedModel , cwd : resolvedCwd } ) ;
147211 onClose ( ) ;
148212 } catch ( error ) {
149213 console . error ( "[SessionCreateMenu] Failed to create session:" , error ) ;
@@ -286,6 +350,19 @@ const SessionCreateMenu = ({
286350 </ select >
287351 </ div >
288352 ) }
353+ < div className = "setup-field" >
354+ < span className = "setup-label" > Working directory</ span >
355+ < input
356+ className = "setup-input mono"
357+ type = "text"
358+ value = { cwd }
359+ onChange = { ( e ) => setCwd ( e . target . value ) }
360+ placeholder = { DEFAULT_CWD }
361+ spellCheck = { false }
362+ autoCapitalize = "off"
363+ autoCorrect = "off"
364+ />
365+ </ div >
289366 </ div >
290367
291368 < div className = "session-create-actions" >
0 commit comments