@@ -129,7 +129,33 @@ func WriteRawInputOverHTTP(ctx context.Context, url string, msg string) error {
129129 return nil
130130}
131131
132- func runAttach (remoteUrl string ) error {
132+ func checkACPMode (remoteURL string ) (bool , error ) {
133+ resp , err := http .Get (remoteURL + "/status" )
134+ if err != nil {
135+ return false , xerrors .Errorf ("failed to check server status: %w" , err )
136+ }
137+ defer func () { _ = resp .Body .Close () }()
138+
139+ if resp .StatusCode != http .StatusOK {
140+ return false , xerrors .Errorf ("unexpected %d response from server: %s" , resp .StatusCode , resp .Status )
141+ }
142+
143+ var status httpapi.StatusResponse
144+ if err := json .NewDecoder (resp .Body ).Decode (& status .Body ); err != nil {
145+ return false , xerrors .Errorf ("failed to decode server status: %w" , err )
146+ }
147+
148+ return status .Body .Transport == httpapi .TransportACP , nil
149+ }
150+
151+ func runAttach (remoteURL string ) error {
152+ // Check if server is running in ACP mode (attach not supported)
153+ if isACP , err := checkACPMode (remoteURL ); err != nil {
154+ _ , _ = fmt .Fprintf (os .Stderr , "WARN: Unable to check server: %s" , err .Error ())
155+ } else if isACP {
156+ return xerrors .New ("attach is not yet supported in ACP mode" )
157+ }
158+
133159 ctx , cancel := context .WithCancel (context .Background ())
134160 defer cancel ()
135161 stdin := int (os .Stdin .Fd ())
@@ -152,7 +178,7 @@ func runAttach(remoteUrl string) error {
152178 readScreenErrCh := make (chan error , 1 )
153179 go func () {
154180 defer close (readScreenErrCh )
155- if err := ReadScreenOverHTTP (ctx , remoteUrl + "/internal/screen" , screenCh ); err != nil {
181+ if err := ReadScreenOverHTTP (ctx , remoteURL + "/internal/screen" , screenCh ); err != nil {
156182 if errors .Is (err , context .Canceled ) {
157183 return
158184 }
@@ -175,7 +201,7 @@ func runAttach(remoteUrl string) error {
175201 if input == "\x03 " {
176202 continue
177203 }
178- if err := WriteRawInputOverHTTP (ctx , remoteUrl + "/message" , input ); err != nil {
204+ if err := WriteRawInputOverHTTP (ctx , remoteURL + "/message" , input ); err != nil {
179205 writeRawInputErrCh <- xerrors .Errorf ("failed to write raw input: %w" , err )
180206 return
181207 }
0 commit comments