@@ -4,42 +4,22 @@ import (
44 "fmt"
55 "log"
66 "os/exec"
7+ "strconv"
78 "strings"
89
10+ "github.com/cyber-shuttle/linkspan/subsystems/mount"
911 tunnel "github.com/cyber-shuttle/linkspan/subsystems/tunnel"
10- vscode "github.com/cyber-shuttle/linkspan/subsystems/vscode"
11- utils "github.com/cyber-shuttle/linkspan/utils"
1212)
1313
1414// registerBuiltinActions populates a Registry with all built-in action wrappers.
1515func registerBuiltinActions (r * Registry ) {
16- r .Register ("vscode.create_session" , actionVSCodeCreateSession )
1716 r .Register ("tunnel.devtunnel_create" , actionDevTunnelCreate )
1817 r .Register ("tunnel.devtunnel_forward" , actionDevTunnelForward )
1918 r .Register ("tunnel.devtunnel_delete" , actionDevTunnelDelete )
2019 r .Register ("tunnel.devtunnel_connect" , actionDevTunnelConnect )
2120 r .Register ("tunnel.frp_proxy_create" , actionFrpProxyCreate )
2221 r .Register ("shell.exec" , actionShellExec )
23- }
24-
25- // --- vscode.create_session ---
26-
27- func actionVSCodeCreateSession (params map [string ]any ) (* ActionResult , error ) {
28- port , err := utils .GetAvailablePort ()
29- if err != nil {
30- return nil , fmt .Errorf ("get available port: %w" , err )
31- }
32-
33- sessionID := fmt .Sprintf ("wf-%d" , port )
34- addr := fmt .Sprintf (":%d" , port )
35-
36- vscode .StartSSHServerForVSCodeConnection (sessionID , addr )
37-
38- result := ActionResult {
39- "session_id" : sessionID ,
40- "bind_port" : port ,
41- }
42- return & result , nil
22+ r .Register ("mount.setup_overlay" , actionSetupOverlay )
4323}
4424
4525// --- tunnel.devtunnel_create ---
@@ -58,8 +38,9 @@ func actionDevTunnelCreate(params map[string]any) (*ActionResult, error) {
5838 return nil , fmt .Errorf ("tunnel.devtunnel_create: auth_token is required" )
5939 }
6040 serverPort := toInt (params ["server_port" ])
41+ sshPort := toInt (params ["ssh_port" ])
6142
62- conn , err := tunnel .DevTunnelCreate (tunnelName , expiration , authToken , serverPort )
43+ conn , err := tunnel .DevTunnelCreate (tunnelName , expiration , authToken , serverPort , sshPort )
6344 if err != nil {
6445 return nil , err
6546 }
@@ -69,6 +50,7 @@ func actionDevTunnelCreate(params map[string]any) (*ActionResult, error) {
6950 "tunnel_name" : conn .DevTunnelInfo .TunnelName ,
7051 "connection_url" : conn .ConnectionURL ,
7152 "token" : conn .Token ,
53+ "ssh_port" : sshPort ,
7254 }
7355 return & result , nil
7456}
@@ -123,13 +105,20 @@ func actionDevTunnelConnect(params map[string]any) (*ActionResult, error) {
123105 return nil , fmt .Errorf ("tunnel.devtunnel_connect: access_token is required" )
124106 }
125107
126- cmdID , err := tunnel .DevTunnelConnect (tunnelID , accessToken )
108+ cmdID , portMap , err := tunnel .DevTunnelConnect (tunnelID , accessToken )
127109 if err != nil {
128110 return nil , err
129111 }
130112
113+ // Convert port map to string-keyed map for template access
114+ portMapStr := make (map [string ]any )
115+ for remote , local := range portMap {
116+ portMapStr [strconv .Itoa (remote )] = local
117+ }
118+
131119 result := ActionResult {
132120 "command_id" : cmdID ,
121+ "port_map" : portMapStr ,
133122 }
134123 return & result , nil
135124}
@@ -183,6 +172,35 @@ func actionShellExec(params map[string]any) (*ActionResult, error) {
183172 return & result , nil
184173}
185174
175+ // --- mount.setup_overlay ---
176+
177+ func actionSetupOverlay (params map [string ]any ) (* ActionResult , error ) {
178+ sessionID , _ := params ["session_id" ].(string )
179+ if sessionID == "" {
180+ return nil , fmt .Errorf ("mount.setup_overlay: session_id is required" )
181+ }
182+ localWorkspace , _ := params ["local_workspace" ].(string )
183+ if localWorkspace == "" {
184+ return nil , fmt .Errorf ("mount.setup_overlay: local_workspace is required" )
185+ }
186+ localSshPort := toInt (params ["local_ssh_port" ])
187+ if localSshPort == 0 {
188+ return nil , fmt .Errorf ("mount.setup_overlay: local_ssh_port is required" )
189+ }
190+
191+ overlay , err := mount .SetupOverlay (sessionID , localSshPort , localWorkspace )
192+ if err != nil {
193+ return nil , fmt .Errorf ("mount.setup_overlay: %w" , err )
194+ }
195+
196+ result := ActionResult {
197+ "merged_path" : overlay .MergedDir ,
198+ "cache_path" : overlay .CacheDir ,
199+ "source_path" : overlay .SourceDir ,
200+ }
201+ return & result , nil
202+ }
203+
186204// --- helpers ---
187205
188206// toInt converts a param value to int, handling YAML's default float64/int types.
0 commit comments