@@ -98,10 +98,6 @@ func (d *Daemon) handleFSHome(_ context.Context, _ json.RawMessage) (any, error)
9898 return map [string ]string {"path" : defaultFSHome ()}, nil
9999}
100100
101- type fsReadResult struct {
102- Content string `json:"content"`
103- }
104-
105101func (d * Daemon ) handleFSRead (_ context.Context , params json.RawMessage ) (any , error ) {
106102 var p rpc.FSReadParams
107103 if err := unmarshalParams (params , & p ); err != nil {
@@ -126,7 +122,7 @@ func (d *Daemon) handleFSRead(_ context.Context, params json.RawMessage) (any, e
126122 if err != nil {
127123 return nil , fmt .Errorf ("cannot read file: %w" , err )
128124 }
129- return fsReadResult {Content : string (data )}, nil
125+ return rpc. FSReadResult {Content : string (data )}, nil
130126}
131127
132128func (d * Daemon ) handleFSWrite (_ context.Context , params json.RawMessage ) (any , error ) {
@@ -187,16 +183,28 @@ func (d *Daemon) handleFSRm(_ context.Context, params json.RawMessage) (any, err
187183 return nil , fmt .Errorf ("cannot access path: %w" , err )
188184 }
189185 if info .IsDir () {
190- // Only remove empty directories to avoid accidental data loss
191- entries , err := os .ReadDir (absPath )
192- if err != nil {
193- return nil , fmt .Errorf ("cannot read directory: %w" , err )
194- }
195- if len (entries ) > 0 {
196- return nil , fmt .Errorf ("directory not empty: %s" , p .Path )
197- }
198- if err := os .Remove (absPath ); err != nil {
199- return nil , fmt .Errorf ("cannot remove directory: %w" , err )
186+ if p .Recurse {
187+ if err := os .RemoveAll (absPath ); err != nil {
188+ return nil , fmt .Errorf ("cannot remove directory tree: %w" , err )
189+ }
190+ } else {
191+ entries , err := os .ReadDir (absPath )
192+ if err != nil {
193+ return nil , fmt .Errorf ("cannot read directory: %w" , err )
194+ }
195+ if len (entries ) > 0 {
196+ if p .Force {
197+ if err := os .RemoveAll (absPath ); err != nil {
198+ return nil , fmt .Errorf ("cannot force remove directory: %w" , err )
199+ }
200+ } else {
201+ return nil , fmt .Errorf ("directory not empty: %s" , p .Path )
202+ }
203+ } else {
204+ if err := os .Remove (absPath ); err != nil {
205+ return nil , fmt .Errorf ("cannot remove directory: %w" , err )
206+ }
207+ }
200208 }
201209 } else {
202210 if err := os .Remove (absPath ); err != nil {
@@ -234,10 +242,6 @@ func (d *Daemon) handleFSMv(_ context.Context, params json.RawMessage) (any, err
234242
235243// ── 新增:reveal ──
236244
237- type fsRevealResult struct {
238- Status string `json:"status"`
239- }
240-
241245// handleFSReveal opens the file's parent directory in the native file manager,
242246// and on macOS also highlights/selects the file.
243247func (d * Daemon ) handleFSReveal (_ context.Context , params json.RawMessage ) (any , error ) {
@@ -276,7 +280,7 @@ func (d *Daemon) handleFSReveal(_ context.Context, params json.RawMessage) (any,
276280 }
277281 }
278282
279- return fsRevealResult {Status : "ok" }, nil
283+ return rpc. FSRevealResult {Status : "ok" }, nil
280284}
281285
282286// ── HTTP download ──
0 commit comments