@@ -2,8 +2,10 @@ package acpinstall
22
33import (
44 "fmt"
5+ "log"
56 "os/exec"
67 "runtime"
8+ "strings"
79 "sync"
810)
911
@@ -90,6 +92,54 @@ func Update(agentID string) error {
9092 return install (info )
9193}
9294
95+ // UpdateAllInstalled checks all known adapters and updates the ones already installed.
96+ // Runs updates concurrently. Logs progress to stdout.
97+ func UpdateAllInstalled () {
98+ var wg sync.WaitGroup
99+
100+ // Special case: opencode uses its own upgrade command
101+ if _ , err := exec .LookPath ("opencode" ); err == nil {
102+ wg .Add (1 )
103+ go func () {
104+ defer wg .Done ()
105+ log .Printf ("[acpinstall] updating opencode (opencode upgrade)..." )
106+ cmd := exec .Command ("opencode" , "upgrade" )
107+ output , err := cmd .CombinedOutput ()
108+ if err != nil {
109+ log .Printf ("[acpinstall] update opencode failed: %v: %s" , err , strings .TrimSpace (string (output )))
110+ } else {
111+ log .Printf ("[acpinstall] opencode updated" )
112+ }
113+ }()
114+ }
115+
116+ for _ , info := range adapters {
117+ if _ , err := exec .LookPath (info .BinaryName ); err != nil {
118+ continue // not installed, skip
119+ }
120+
121+ wg .Add (1 )
122+ go func (info AdapterInfo ) {
123+ defer wg .Done ()
124+ log .Printf ("[acpinstall] updating %s (%s)..." , info .ID , info .Package )
125+ if err := updateOne (& info ); err != nil {
126+ log .Printf ("[acpinstall] update %s failed: %v" , info .ID , err )
127+ } else {
128+ log .Printf ("[acpinstall] %s updated" , info .ID )
129+ }
130+ }(info )
131+ }
132+
133+ wg .Wait ()
134+ }
135+
136+ func updateOne (info * AdapterInfo ) error {
137+ installMu .Lock ()
138+ defer installMu .Unlock ()
139+
140+ return install (info )
141+ }
142+
93143func install (info * AdapterInfo ) error {
94144 switch info .Manager {
95145 case "npm" :
@@ -113,7 +163,11 @@ func npmInstallGlobal(pkg string) error {
113163 } else {
114164 cmd = exec .Command (npm , "install" , "-g" , pkg )
115165 }
116- return cmd .Run ()
166+ output , err := cmd .CombinedOutput ()
167+ if err != nil {
168+ return fmt .Errorf ("%w: %s" , err , strings .TrimSpace (string (output )))
169+ }
170+ return nil
117171}
118172
119173func pipInstall (pkg string ) error {
@@ -124,5 +178,9 @@ func pipInstall(pkg string) error {
124178 }
125179 }
126180 cmd := exec .Command (pip , "install" , "--upgrade" , pkg )
127- return cmd .Run ()
181+ output , err := cmd .CombinedOutput ()
182+ if err != nil {
183+ return fmt .Errorf ("%w: %s" , err , strings .TrimSpace (string (output )))
184+ }
185+ return nil
128186}
0 commit comments