Files
Rusty Shackleford 4596c1e413 fix(install): require explicit force for JSON overwrites (#884)
* fix(install): require explicit force for JSON overwrites

Machine-readable output must not grant destructive consent. Preserve existing skills and agents unless force is explicit, and report existing skip decisions in the JSON result while retaining selection and audit behavior.

Cover edited copies in global and project modes, and update help, automation guidance, and translated command documentation.

Refs: #877

* fix(install): preserve previews and locked JSON copies

Read-only discovery must work before replacement consent, including existing
single skills and cross-path installs. Keep overwrite checks on write paths.

Require existing update or force intent to advance installed project copies
to a changed lock pin. Preserve ordinary CLI and dashboard lock following,
while JSON alone leaves local edits and incoming pins unchanged.

Cover existing-destination previews, edited locked copies and dashboard lock
following. Clarify translated docs and make the consent runbook step runnable.

Refs: #877

* fix(install): resolve installed names during previews

JSON previews must resolve recorded sources without requiring overwrite consent. Permit metadata lookup for dry runs and restore the original unforced preview regression in global and project modes.

* test(install): remove duplicate JSON consent runbook case

The global local-skill integration case already covers JSON overwrite refusal and explicit forced replacement. Remove the duplicate runbook step and restore its 18-step numbering while retaining the existing purity setup and assertion corrections.
2026-11-13 21:31:41 +08:00

93 lines
2.9 KiB
Go

package install
import "strings"
// SkillEntryDTO is a dependency-free copy of config.SkillEntry, used to avoid
// a circular import between install and config. The cmd layer converts
// config.SkillEntry → SkillEntryDTO before passing data through InstallContext.
type SkillEntryDTO struct {
Name string
Source string
Tracked bool
Group string
Branch string
}
// FullName returns the full relative path for the skill entry.
// If Group is set, returns "group/name"; otherwise returns Name.
func (s SkillEntryDTO) FullName() string {
if s.Group != "" {
return s.Group + "/" + s.Name
}
return s.Name
}
// EffectiveParts returns the effective (group, bareName) for this entry.
// If Group is set, returns (Group, Name).
// For backward compat, if Name contains "/" and Group is empty,
// splits at the last "/" to derive group and bare name.
func (s SkillEntryDTO) EffectiveParts() (group, name string) {
if s.Group != "" {
return s.Group, s.Name
}
if idx := strings.LastIndex(s.Name, "/"); idx >= 0 {
return s.Name[:idx], s.Name[idx+1:]
}
return "", s.Name
}
// InstallContext abstracts the behavioral differences between global and
// project install modes so that InstallFromConfig can be written once.
type InstallContext interface {
// SourcePath returns the skills directory
// (e.g. ~/.config/skillshare/skills or .skillshare/skills).
SourcePath() string
// ConfigSkills returns the remote skill entries from the config file.
ConfigSkills() []SkillEntryDTO
// Reconcile performs post-install config reconciliation
// (e.g. ReconcileGlobalSkills or ReconcileProjectSkills).
Reconcile() error
// PostInstallSkill is a per-skill hook called after a successful install.
// For example, project mode uses this to update .skillshare/.gitignore.
PostInstallSkill(displayName string) error
// Mode returns "global" or "project".
Mode() string
// GitLabHosts returns extra hostnames to treat as GitLab instances.
GitLabHosts() []string
// AzureHosts returns extra hostnames to treat as Azure DevOps on-premises instances.
AzureHosts() []string
// CNBHosts returns extra hostnames to treat as CNB instances.
CNBHosts() []string
// GiteaHosts returns extra hostnames to treat as Gitea instances.
GiteaHosts() []string
}
// ConfigInstallResult summarises the outcome of InstallFromConfig.
type ConfigInstallResult struct {
Installed int
Skipped int
// Tracked repos counted within Installed/Skipped, so the summary can tell
// a whole repo apart from a single skill.
InstalledRepos int
InstalledRepoSkills int // skills inside InstalledRepos
SkippedRepos int
InstalledSkills []string
SkippedSkills []string
FailedSkills []string
Failures []SkillFailure // why each FailedSkills entry failed
}
// SkillFailure is one skill that failed to install and the reason.
type SkillFailure struct {
Name string
Err error
}