fallbackFullInstall performs a full skills install (npx -y skills add -g -y) when incremental sync is not possible. On success it writes a state file so that subsequent syncs can use incremental mode. When official is non-nil the state records the full official list; otherwise a minimal sta
(opts SyncOptions, reason string, official []string)
| 404 | // records the full official list; otherwise a minimal state (version only) is |
| 405 | // written to break the fallback loop. |
| 406 | func fallbackFullInstall(opts SyncOptions, reason string, official []string) *SyncResult { |
| 407 | installResult := opts.Runner.InstallAllSkills() |
| 408 | if installResult == nil { |
| 409 | return &SyncResult{ |
| 410 | Action: "fallback_failed", |
| 411 | Err: fmt.Errorf("full skills install failed: empty result (reason: %s)", reason), |
| 412 | Detail: reason, |
| 413 | Force: opts.Force, |
| 414 | } |
| 415 | } |
| 416 | if installResult.Err != nil { |
| 417 | return &SyncResult{ |
| 418 | Action: "fallback_failed", |
| 419 | Err: fmt.Errorf("full skills install failed: %w (reason: %s)", installResult.Err, reason), |
| 420 | Detail: reason + "\n" + resultDetail(installResult), |
| 421 | Force: opts.Force, |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | state := SkillsState{ |
| 426 | Version: opts.Version, |
| 427 | OfficialSkills: official, |
| 428 | UpdatedSkills: official, |
| 429 | AddedOfficialSkills: official, |
| 430 | SkippedDeletedSkills: []string{}, |
| 431 | UpdatedAt: opts.Now().UTC().Format(time.RFC3339), |
| 432 | } |
| 433 | if writeErr := WriteState(state); writeErr != nil { |
| 434 | return &SyncResult{ |
| 435 | Action: "fallback_synced", |
| 436 | Official: official, |
| 437 | Updated: official, |
| 438 | Added: official, |
| 439 | SkippedDeleted: []string{}, |
| 440 | Detail: reason + "\nstate write failed: " + writeErr.Error(), |
| 441 | Force: opts.Force, |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | return &SyncResult{ |
| 446 | Action: "fallback_synced", |
| 447 | Official: official, |
| 448 | Updated: official, |
| 449 | Added: official, |
| 450 | SkippedDeleted: []string{}, |
| 451 | Detail: reason, |
| 452 | Force: opts.Force, |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | func resultDetail(result *selfupdate.NpmResult) string { |
| 457 | if result == nil { |
no test coverage detected