mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* fix(project): refuse to re-init a project that lost its config.yaml Every project-mode command auto-initializes when .skillshare/config.yaml is missing. That is right for a repository with no project directory at all, and for the shared skills repo produced by 'init -p --config local', which gitignores config.yaml so each developer regenerates their own. It was wrong for the case in between. A .skillshare/ that already held skills or agents, whose config.yaml was simply gone, was re-initialized into an empty config. Every configured target was dropped, the target symlinks were left behind pointing at a project the config no longer described, and the command exited 0. Nothing said anything had happened. Add ensureProjectConfig, which replaces the open-coded auto-init at every project command entry point. It initializes as before when there is no project directory, and when config.yaml is gitignored, so both intentional cases keep working untouched. When the directory holds skills or agents and its config is neither present nor gitignored, it now returns an error pointing at version control or an explicit 'skillshare init -p' instead of writing over the project. The gitignore check is treated as inconclusive on error, so a repository that cannot be inspected is guarded rather than overwritten. * feat(project): support a visible skillshare/ project directory Project mode is identified only by .skillshare/config.yaml, and trash, backups, logs and audit-rules.yaml anchor to that same hidden directory. The sources option (#153) made project content relocatable, but the marker and operational state stay hidden, so repositories that treat skills as reviewable content still carry a hidden directory whose only job is to hold config.yaml. Resolve the project directory through a new leaf package that checks .skillshare/config.yaml first and skillshare/config.yaml second, and derive every config, state, source-default and gitignore path from the result. The hidden name wins whenever both exist, so an existing project never moves and no migration is needed. The package imports nothing else internal because internal/audit cannot import internal/config without a cycle. Add init -p --visible to create the visible layout. Default init -p behaviour and output are unchanged. Two ambiguities the visible name introduces: - The global config directory is also called skillshare (<config-home>/skillshare), so the two places that infer scope from a config path now exclude the global location by full path rather than by directory name. TestLogDir_Global asserted a fixture path without declaring a config home, which hid this; it now sets XDG_CONFIG_HOME. - An unrelated directory named skillshare/ must not be adopted as a partially initialized project, so the visible name is only claimed when it carries a marker of its own: a skills/ or agents/ directory, or a .gitignore that ignores config.yaml. The missing-config guard added in the previous commit is generalized to resolve through the new package, so it covers both layouts. The gitignored-config marker matters there too. A repository shared by 'init -p --visible --config local' before any skill was committed clones with nothing but that .gitignore, because git drops the empty skills/ and agents/ directories; recognizing it keeps the repair pointed at the visible directory instead of writing a hidden one beside it. Refs #256 * fix(project): reconcile visible directory support with main Consolidate the missing-config guard and regression tests already merged in #260. Preserve both directory layouts and document and test resyncing target links after a rename. Follow-up for #258. --------- Co-authored-by: Willie <egg358358@gmail.com>
This commit is contained in:
co-authored by
Willie
parent
ea442b9f52
commit
60e19f96d5
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"skillshare/internal/backup"
|
||||
"skillshare/internal/config"
|
||||
@@ -11,7 +10,7 @@ import (
|
||||
|
||||
// createAgentBackup backs up agent target directories.
|
||||
// Agent backups use "<target>-agents" as the backup entry name.
|
||||
// In project mode, backups are stored under .skillshare/backups/.
|
||||
// In project mode, backups are stored under <project-dir>/backups/.
|
||||
func createAgentBackup(mode runMode, cwd, targetName string, dryRun bool) error {
|
||||
backupDir, targets, err := resolveAgentBackupContext(mode, cwd)
|
||||
if err != nil {
|
||||
@@ -153,6 +152,6 @@ func resolveProjectAgentBackupContext(cwd string) (string, []agentTarget, error)
|
||||
}
|
||||
}
|
||||
|
||||
backupDir := filepath.Join(cwd, ".skillshare", "backups")
|
||||
backupDir := backup.ProjectBackupDir(cwd)
|
||||
return backupDir, targets, nil
|
||||
}
|
||||
|
||||
@@ -20,17 +20,21 @@ func writeSkill(t *testing.T, dir, name string) {
|
||||
}
|
||||
|
||||
func TestEnsureProjectConfig_AlreadyInitialized(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, ".skillshare")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte("targets: []\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, dirName := range []string{".skillshare", "skillshare"} {
|
||||
t.Run(dirName, func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, dirName)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte("targets: []\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ensureProjectConfig(root); err != nil {
|
||||
t.Errorf("ensureProjectConfig() = %v, want nil", err)
|
||||
if err := ensureProjectConfig(root); err != nil {
|
||||
t.Errorf("ensureProjectConfig() = %v, want nil", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,21 +54,50 @@ func TestEnsureProjectConfig_NoProjectStillInitializes(t *testing.T) {
|
||||
// The --config local shared skills repo gitignores config.yaml, so a fresh
|
||||
// clone legitimately has content but no config and must still regenerate one.
|
||||
func TestEnsureProjectConfig_SharedRepoStillRepairs(t *testing.T) {
|
||||
for _, dirName := range []string{".skillshare", "skillshare"} {
|
||||
t.Run(dirName, func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, dirName)
|
||||
writeSkill(t, filepath.Join(dir, "skills"), "shared-skill")
|
||||
if err := os.WriteFile(filepath.Join(dir, ".gitignore"), []byte("config.yaml\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ensureProjectConfig(root); err != nil {
|
||||
t.Fatalf("ensureProjectConfig() = %v, want nil for the shared-repo flow", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "config.yaml")); err != nil {
|
||||
t.Errorf("shared-repo repair did not write a config: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "skills", "shared-skill", "SKILL.md")); err != nil {
|
||||
t.Errorf("shared skill was disturbed: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A visible shared repo whose skills and agents were never committed clones
|
||||
// with nothing but the tracked .gitignore, because git drops empty directories.
|
||||
// The repair must still target that directory instead of starting a hidden one
|
||||
// alongside it.
|
||||
func TestEnsureProjectConfig_FreshCloneOfVisibleSharedRepo(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, ".skillshare")
|
||||
writeSkill(t, filepath.Join(dir, "skills"), "shared-skill")
|
||||
if err := os.WriteFile(filepath.Join(dir, ".gitignore"), []byte("config.yaml\n"), 0644); err != nil {
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, ".gitignore"), []byte("logs\ntrash\nbackups\nconfig.yaml\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ensureProjectConfig(root); err != nil {
|
||||
t.Fatalf("ensureProjectConfig() = %v, want nil for the shared-repo flow", err)
|
||||
t.Fatalf("ensureProjectConfig() = %v, want nil for a freshly cloned shared repository", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "config.yaml")); err != nil {
|
||||
t.Errorf("shared-repo repair did not write a config: %v", err)
|
||||
t.Errorf("no config written to the visible project directory: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "skills", "shared-skill", "SKILL.md")); err != nil {
|
||||
t.Errorf("shared skill was disturbed: %v", err)
|
||||
if _, err := os.Stat(filepath.Join(root, ".skillshare")); !os.IsNotExist(err) {
|
||||
t.Error("repair created a hidden project directory next to the visible one")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,39 +105,29 @@ func TestEnsureProjectConfig_SharedRepoStillRepairs(t *testing.T) {
|
||||
// config.yaml is simply missing and is not gitignored. Re-initializing would
|
||||
// replace it with an empty config and silently drop every configured target.
|
||||
func TestEnsureProjectConfig_RefusesToDiscardExistingProject(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, ".skillshare")
|
||||
writeSkill(t, filepath.Join(dir, "skills"), "demo")
|
||||
for _, dirName := range []string{".skillshare", "skillshare"} {
|
||||
t.Run(dirName, func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, dirName)
|
||||
writeSkill(t, filepath.Join(dir, "skills"), "demo")
|
||||
|
||||
err := ensureProjectConfig(root)
|
||||
if err == nil {
|
||||
t.Fatal("ensureProjectConfig() = nil, want an error for a content-bearing project without a config")
|
||||
}
|
||||
if !strings.Contains(err.Error(), ".skillshare") {
|
||||
t.Errorf("error %q does not name the project directory", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "init -p") {
|
||||
t.Errorf("error %q does not point at 'init -p'", err)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(dir, "config.yaml")); !os.IsNotExist(statErr) {
|
||||
t.Error("a config was written over an existing project")
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(dir, "skills", "demo", "SKILL.md")); statErr != nil {
|
||||
t.Errorf("existing skill was disturbed: %v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
// Agents alone are enough to make a project worth protecting.
|
||||
func TestEnsureProjectConfig_RefusesWhenOnlyAgentsExist(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, ".skillshare")
|
||||
writeSkill(t, filepath.Join(dir, "agents"), "demo-agent")
|
||||
|
||||
if err := ensureProjectConfig(root); err == nil {
|
||||
t.Fatal("ensureProjectConfig() = nil, want an error for a project holding only agents")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "config.yaml")); !os.IsNotExist(err) {
|
||||
t.Error("a config was written over an existing project")
|
||||
err := ensureProjectConfig(root)
|
||||
if err == nil {
|
||||
t.Fatal("ensureProjectConfig() = nil, want an error for a content-bearing project without a config")
|
||||
}
|
||||
if !strings.Contains(err.Error(), dirName) {
|
||||
t.Errorf("error %q does not name the project directory", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "init -p") {
|
||||
t.Errorf("error %q does not point at 'init -p'", err)
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(dir, "config.yaml")); !os.IsNotExist(statErr) {
|
||||
t.Error("a config was written over an existing project")
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(dir, "skills", "demo", "SKILL.md")); statErr != nil {
|
||||
t.Errorf("existing skill was disturbed: %v", statErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,3 +164,17 @@ func TestCmdStatusProject_DoesNotDiscardExistingProject(t *testing.T) {
|
||||
t.Errorf("existing skill was disturbed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Agents alone are enough to make a project worth protecting.
|
||||
func TestEnsureProjectConfig_RefusesWhenOnlyAgentsExist(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, ".skillshare")
|
||||
writeSkill(t, filepath.Join(dir, "agents"), "demo-agent")
|
||||
|
||||
if err := ensureProjectConfig(root); err == nil {
|
||||
t.Fatal("ensureProjectConfig() = nil, want an error for a project holding only agents")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "config.yaml")); !os.IsNotExist(err) {
|
||||
t.Error("a config was written over an existing project")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/projectdir"
|
||||
"skillshare/internal/ui"
|
||||
)
|
||||
|
||||
@@ -18,6 +19,7 @@ type projectInitOptions struct {
|
||||
selectArg string // Non-interactive selection for --discover
|
||||
mode string // default mode for new targets: merge|copy|symlink
|
||||
configMode string // "local" to gitignore config.yaml (shared skills repo)
|
||||
visible bool // create a visible skillshare/ directory instead of .skillshare/
|
||||
}
|
||||
|
||||
type detectedProjectTarget struct {
|
||||
@@ -40,6 +42,7 @@ func printProjectInitUsage() {
|
||||
fmt.Println(" --mode, -m <mode> Set sync mode (merge, copy, symlink; default: merge).")
|
||||
fmt.Println(" With --discover, applies only to newly added targets")
|
||||
fmt.Println(" --config local Gitignore config.yaml (each developer manages own targets)")
|
||||
fmt.Println(" --visible Create a visible skillshare/ directory instead of .skillshare/")
|
||||
fmt.Println(" --dry-run, -n Preview without making changes")
|
||||
fmt.Println(" --help, -h Show this help")
|
||||
fmt.Println()
|
||||
@@ -47,6 +50,7 @@ func printProjectInitUsage() {
|
||||
fmt.Println(" skillshare init -p")
|
||||
fmt.Println(" skillshare init -p --targets claude,cursor --mode copy")
|
||||
fmt.Println(" skillshare init -p --discover --select cursor --mode copy")
|
||||
fmt.Println(" skillshare init -p --visible")
|
||||
}
|
||||
|
||||
func parseProjectInitArgs(args []string) (projectInitOptions, bool, error) {
|
||||
@@ -56,6 +60,8 @@ func parseProjectInitArgs(args []string) (projectInitOptions, bool, error) {
|
||||
switch {
|
||||
case arg == "--dry-run" || arg == "-n":
|
||||
opts.dryRun = true
|
||||
case arg == "--visible":
|
||||
opts.visible = true
|
||||
case arg == "--help" || arg == "-h":
|
||||
return opts, true, nil
|
||||
case arg == "--discover" || arg == "-d":
|
||||
@@ -123,8 +129,17 @@ func cmdInitProject(args []string) error {
|
||||
}
|
||||
|
||||
func performProjectInit(root string, opts projectInitOptions) error {
|
||||
projectDir := filepath.Join(root, ".skillshare")
|
||||
configPath := config.ProjectConfigPath(root)
|
||||
// An already-initialized or partially-initialized project keeps its own
|
||||
// directory; only a brand new project honours --visible.
|
||||
projectDir, existing := projectdir.Find(root)
|
||||
if !existing {
|
||||
projectDir, existing = projectdir.FindPartial(root)
|
||||
}
|
||||
if !existing {
|
||||
projectDir = filepath.Join(root, projectdir.Name(opts.visible))
|
||||
}
|
||||
dirName := filepath.Base(projectDir)
|
||||
configPath := filepath.Join(projectDir, projectdir.ConfigFileName)
|
||||
partialInitRepair := false
|
||||
if info, err := os.Stat(projectDir); err == nil {
|
||||
if !info.IsDir() {
|
||||
@@ -146,7 +161,7 @@ func performProjectInit(root string, opts projectInitOptions) error {
|
||||
|
||||
sharedRepoFlow := false
|
||||
if partialInitRepair {
|
||||
gitignored, err := isConfigGitignored(root)
|
||||
gitignored, err := isConfigGitignored(projectDir)
|
||||
if err != nil {
|
||||
ui.Warning("Could not check for shared repo config: %v", err)
|
||||
}
|
||||
@@ -210,19 +225,19 @@ func performProjectInit(root string, opts projectInitOptions) error {
|
||||
|
||||
if opts.dryRun {
|
||||
ui.Header("Dry run complete (project)")
|
||||
ui.Info("Would create .skillshare/skills/")
|
||||
ui.Info("Would create %s/skills/", dirName)
|
||||
ui.Info("Would write config: %s", configPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Join(root, ".skillshare", "skills"), 0755); err != nil {
|
||||
return fmt.Errorf("failed to create .skillshare/skills: %w", err)
|
||||
if err := os.MkdirAll(filepath.Join(projectDir, "skills"), 0755); err != nil {
|
||||
return fmt.Errorf("failed to create %s/skills: %w", dirName, err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(root, ".skillshare", "agents"), 0755); err != nil {
|
||||
return fmt.Errorf("failed to create .skillshare/agents: %w", err)
|
||||
if err := os.MkdirAll(filepath.Join(projectDir, "agents"), 0755); err != nil {
|
||||
return fmt.Errorf("failed to create %s/agents: %w", dirName, err)
|
||||
}
|
||||
|
||||
if err := ensureProjectGitignore(root, opts.configMode == "local"); err != nil {
|
||||
if err := ensureProjectGitignore(projectDir, opts.configMode == "local"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -237,7 +252,7 @@ func performProjectInit(root string, opts projectInitOptions) error {
|
||||
BlockThreshold: "CRITICAL",
|
||||
},
|
||||
}
|
||||
if err := cfg.Save(root); err != nil {
|
||||
if err := cfg.SaveIn(projectDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -245,16 +260,16 @@ func performProjectInit(root string, opts projectInitOptions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ui.Success("Created .skillshare/config.yaml")
|
||||
ui.Success("Created .skillshare/skills/")
|
||||
ui.Success("Created %s/%s", dirName, projectdir.ConfigFileName)
|
||||
ui.Success("Created %s/skills/", dirName)
|
||||
if !sharedRepoFlow {
|
||||
ui.Success("Added %d target(s)", len(selected))
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
ui.Header("Initialized successfully (project)")
|
||||
ui.Success("Source: .skillshare/skills/")
|
||||
ui.Success("Config: %s", config.ProjectConfigPath(root))
|
||||
ui.Success("Source: %s/skills/", dirName)
|
||||
ui.Success("Config: %s", configPath)
|
||||
if opts.configMode == "local" {
|
||||
ui.Success("Config gitignored (each developer manages own targets)")
|
||||
}
|
||||
@@ -543,25 +558,26 @@ func findGroupedTarget(targets []detectedProjectTarget, name string) *detectedPr
|
||||
return nil
|
||||
}
|
||||
|
||||
// isConfigGitignored checks if config.yaml is gitignored in .skillshare/.gitignore,
|
||||
// indicating this is a shared skills repo where each developer manages their own config.
|
||||
func isConfigGitignored(root string) (bool, error) {
|
||||
path := filepath.Join(root, ".skillshare", ".gitignore")
|
||||
// isConfigGitignored checks if config.yaml is gitignored in the project
|
||||
// directory's .gitignore, indicating this is a shared skills repo where each
|
||||
// developer manages their own config.
|
||||
func isConfigGitignored(projectDir string) (bool, error) {
|
||||
path := filepath.Join(projectDir, ".gitignore")
|
||||
return install.GitignoreContains(path, "config.yaml")
|
||||
}
|
||||
|
||||
func ensureProjectGitignore(root string, gitignoreConfig bool) error {
|
||||
gitignoreDir := filepath.Join(root, ".skillshare")
|
||||
func ensureProjectGitignore(gitignoreDir string, gitignoreConfig bool) error {
|
||||
dirName := filepath.Base(gitignoreDir)
|
||||
gitignorePath := filepath.Join(gitignoreDir, ".gitignore")
|
||||
if _, err := os.Stat(gitignorePath); os.IsNotExist(err) {
|
||||
if err := os.WriteFile(gitignorePath, []byte(""), 0644); err != nil {
|
||||
return fmt.Errorf("failed to create .skillshare/.gitignore: %w", err)
|
||||
return fmt.Errorf("failed to create %s/.gitignore: %w", dirName, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Always ignore operational directories to avoid committing noise.
|
||||
if err := install.UpdateGitIgnoreBatch(gitignoreDir, []string{"logs", "trash", "backups"}); err != nil {
|
||||
return fmt.Errorf("failed to update .skillshare/.gitignore: %w", err)
|
||||
return fmt.Errorf("failed to update %s/.gitignore: %w", dirName, err)
|
||||
}
|
||||
|
||||
// --config local: gitignore config.yaml so each developer manages own targets.
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseProjectInitArgs_Visible(t *testing.T) {
|
||||
opts, showHelp, err := parseProjectInitArgs([]string{"--visible"})
|
||||
if err != nil {
|
||||
t.Fatalf("parseProjectInitArgs failed: %v", err)
|
||||
}
|
||||
if showHelp {
|
||||
t.Fatal("--visible should not request help")
|
||||
}
|
||||
if !opts.visible {
|
||||
t.Error("opts.visible = false, want true")
|
||||
}
|
||||
|
||||
opts, _, err = parseProjectInitArgs([]string{"--targets", "claude"})
|
||||
if err != nil {
|
||||
t.Fatalf("parseProjectInitArgs failed: %v", err)
|
||||
}
|
||||
if opts.visible {
|
||||
t.Error("opts.visible = true without --visible")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPerformProjectInit_Visible(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
|
||||
if err := performProjectInit(root, projectInitOptions{visible: true, targets: []string{"claude"}}); err != nil {
|
||||
t.Fatalf("performProjectInit failed: %v", err)
|
||||
}
|
||||
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
for _, sub := range []string{"config.yaml", "skills", "agents", ".gitignore"} {
|
||||
if _, err := os.Stat(filepath.Join(dir, sub)); err != nil {
|
||||
t.Errorf("missing %s in visible project directory: %v", sub, err)
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, ".skillshare")); !os.IsNotExist(err) {
|
||||
t.Error("--visible also created a hidden .skillshare directory")
|
||||
}
|
||||
if !projectConfigExists(root) {
|
||||
t.Error("visible project not detected by projectConfigExists")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPerformProjectInit_DefaultStaysHidden(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
|
||||
if err := performProjectInit(root, projectInitOptions{targets: []string{"claude"}}); err != nil {
|
||||
t.Fatalf("performProjectInit failed: %v", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(root, ".skillshare", "config.yaml")); err != nil {
|
||||
t.Errorf("default init did not create .skillshare/config.yaml: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "skillshare")); !os.IsNotExist(err) {
|
||||
t.Error("default init created a visible skillshare directory")
|
||||
}
|
||||
}
|
||||
|
||||
// A second init must report the existing project rather than creating the other
|
||||
// layout alongside it.
|
||||
func TestPerformProjectInit_VisibleProjectIsAlreadyInitialized(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
|
||||
if err := performProjectInit(root, projectInitOptions{visible: true, targets: []string{"claude"}}); err != nil {
|
||||
t.Fatalf("performProjectInit failed: %v", err)
|
||||
}
|
||||
|
||||
err := performProjectInit(root, projectInitOptions{targets: []string{"claude"}})
|
||||
if err == nil {
|
||||
t.Fatal("re-init of a visible project succeeded, want already-initialized error")
|
||||
}
|
||||
if _, statErr := os.Stat(filepath.Join(root, ".skillshare")); !os.IsNotExist(statErr) {
|
||||
t.Error("re-init created a hidden directory next to the visible project")
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,9 @@ import (
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/oplog"
|
||||
"skillshare/internal/projectdir"
|
||||
"skillshare/internal/ui"
|
||||
"skillshare/internal/utils"
|
||||
)
|
||||
|
||||
func cmdLog(args []string) error {
|
||||
@@ -264,7 +266,13 @@ func runLogStats(configPath string, auditOnly bool, f oplog.Filter) error {
|
||||
}
|
||||
|
||||
func isProjectLogConfig(configPath string) bool {
|
||||
return filepath.Base(filepath.Dir(configPath)) == ".skillshare"
|
||||
configDir := filepath.Dir(configPath)
|
||||
if !projectdir.IsName(filepath.Base(configDir)) {
|
||||
return false
|
||||
}
|
||||
// The visible project directory shares its name with the global config
|
||||
// directory, so exclude the global location by full path.
|
||||
return !utils.PathsEqual(configDir, config.BaseDir())
|
||||
}
|
||||
|
||||
// runLogTUIDispatch launches the interactive TUI with async log loading.
|
||||
|
||||
+17
-20
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"skillshare/internal/projectdir"
|
||||
"skillshare/internal/ui"
|
||||
)
|
||||
|
||||
@@ -57,44 +58,40 @@ func modeString(mode runMode) string {
|
||||
}
|
||||
|
||||
func projectConfigExists(root string) bool {
|
||||
_, err := os.Stat(filepath.Join(root, ".skillshare", "config.yaml"))
|
||||
return err == nil
|
||||
_, ok := projectdir.Find(root)
|
||||
return ok
|
||||
}
|
||||
|
||||
// ensureProjectConfig initializes a project when that is safe, and reports the
|
||||
// case where initializing would discard an existing project instead.
|
||||
//
|
||||
// Auto-init is intentional in two situations and both are preserved: a
|
||||
// repository with no .skillshare/ at all, and the shared skills repo produced
|
||||
// by 'init -p --config local', which gitignores config.yaml so every developer
|
||||
// regenerates their own.
|
||||
// repository with no project directory at all, and the shared skills repo
|
||||
// produced by 'init -p --config local', which gitignores config.yaml so every
|
||||
// developer regenerates their own.
|
||||
//
|
||||
// The case in between used to be silent. A .skillshare/ that already holds
|
||||
// skills or agents, whose config.yaml is simply gone, was re-initialized into
|
||||
// an empty config — dropping every configured target, leaving stale target
|
||||
// links, and exiting 0.
|
||||
// The case in between used to be silent. A project directory that already holds
|
||||
// skills or agents, whose config.yaml is simply gone, was re-initialized into an
|
||||
// empty config — dropping every configured target, leaving stale target links,
|
||||
// and exiting 0.
|
||||
func ensureProjectConfig(root string) error {
|
||||
if projectConfigExists(root) {
|
||||
return nil
|
||||
}
|
||||
dir := filepath.Join(root, ".skillshare")
|
||||
if info, err := os.Stat(dir); err == nil && info.IsDir() {
|
||||
// isConfigGitignored reports false whenever it cannot tell, so an
|
||||
// unreadable .gitignore falls through to the guard rather than the
|
||||
// shared-repo path.
|
||||
gitignored, _ := isConfigGitignored(root)
|
||||
if !gitignored && projectDirHasContent(dir) {
|
||||
if dir, ok := projectdir.FindPartial(root); ok {
|
||||
gitignored, err := isConfigGitignored(dir)
|
||||
if (err != nil || !gitignored) && projectDirHasContent(dir) {
|
||||
return fmt.Errorf(
|
||||
".skillshare/ in %s holds skills or agents but has no config.yaml\n"+
|
||||
"%s/ in %s holds skills or agents but has no %s\n"+
|
||||
"Restore it from version control, or run 'skillshare init -p' to write a new one",
|
||||
root)
|
||||
filepath.Base(dir), root, projectdir.ConfigFileName)
|
||||
}
|
||||
}
|
||||
return performProjectInit(root, projectInitOptions{})
|
||||
}
|
||||
|
||||
// projectDirHasContent reports whether .skillshare/ holds authored skills or
|
||||
// agents that a regenerated config would no longer describe.
|
||||
// projectDirHasContent reports whether the project directory holds authored
|
||||
// skills or agents that a regenerated config would no longer describe.
|
||||
func projectDirHasContent(dir string) bool {
|
||||
for _, name := range []string{"skills", "agents"} {
|
||||
entries, err := os.ReadDir(filepath.Join(dir, name))
|
||||
|
||||
@@ -193,7 +193,7 @@ func syncAgentsProject(projectRoot string, dryRun, force, jsonOutput bool, start
|
||||
|
||||
// Backup agent targets before sync (non-dry-run only).
|
||||
if !dryRun && !jsonOutput {
|
||||
backupDir := filepath.Join(projectRoot, ".skillshare", "backups")
|
||||
backupDir := backup.ProjectBackupDir(projectRoot)
|
||||
defer func() {
|
||||
if _, err := backup.CleanupInDir(backupDir, backup.DefaultCleanupConfig()); err != nil {
|
||||
ui.Warning("Failed to clean up old project agent backups: %v", err)
|
||||
|
||||
@@ -10,8 +10,13 @@ import (
|
||||
"sync"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"skillshare/internal/projectdir"
|
||||
)
|
||||
|
||||
// auditRulesFileName is the per-project audit rule override file, resolved
|
||||
// inside whichever project directory is active.
|
||||
const auditRulesFileName = "audit-rules.yaml"
|
||||
|
||||
// Severity levels for audit findings.
|
||||
const (
|
||||
SeverityCritical = "CRITICAL"
|
||||
@@ -191,7 +196,7 @@ func RulesWithProject(projectRoot string) ([]rule, error) {
|
||||
baseYAML = mergeYAMLRules(baseYAML, globalUserYAML)
|
||||
}
|
||||
|
||||
projectPath := filepath.Join(projectRoot, ".skillshare", "audit-rules.yaml")
|
||||
projectPath := filepath.Join(projectdir.Resolve(projectRoot), auditRulesFileName)
|
||||
projectYAML, err := loadUserRules(projectPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("project user rules: %w", err)
|
||||
@@ -383,7 +388,7 @@ func GlobalAuditRulesPath() string {
|
||||
|
||||
// ProjectAuditRulesPath returns the path to a project's audit-rules.yaml.
|
||||
func ProjectAuditRulesPath(projectRoot string) string {
|
||||
return filepath.Join(projectRoot, ".skillshare", "audit-rules.yaml")
|
||||
return filepath.Join(projectdir.Resolve(projectRoot), auditRulesFileName)
|
||||
}
|
||||
|
||||
// configDir returns the skillshare config directory without importing
|
||||
@@ -509,7 +514,7 @@ func disabledIDsForProject(projectRoot string) map[string]bool {
|
||||
if globalUser != nil {
|
||||
base = mergeYAMLRules(base, globalUser)
|
||||
}
|
||||
projectUser, _ := loadUserRules(filepath.Join(projectRoot, ".skillshare", "audit-rules.yaml"))
|
||||
projectUser, _ := loadUserRules(filepath.Join(projectdir.Resolve(projectRoot), auditRulesFileName))
|
||||
if projectUser != nil {
|
||||
base = mergeYAMLRules(base, projectUser)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package audit
|
||||
import (
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"skillshare/internal/projectdir"
|
||||
)
|
||||
|
||||
// CompiledRule is the public view of a rule for listing/display.
|
||||
@@ -45,7 +47,7 @@ func ListRulesWithProject(projectRoot string) ([]CompiledRule, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
projectPath := filepath.Join(projectRoot, ".skillshare", "audit-rules.yaml")
|
||||
projectPath := filepath.Join(projectdir.Resolve(projectRoot), auditRulesFileName)
|
||||
projectUser, err := loadUserRules(projectPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/projectdir"
|
||||
)
|
||||
|
||||
const stagingDirPrefix = ".snapshot-"
|
||||
@@ -22,7 +23,7 @@ func BackupDir() string {
|
||||
|
||||
// ProjectBackupDir returns the project-level backup directory path.
|
||||
func ProjectBackupDir(projectRoot string) string {
|
||||
return filepath.Join(projectRoot, ".skillshare", "backups")
|
||||
return filepath.Join(projectdir.Resolve(projectRoot), "backups")
|
||||
}
|
||||
|
||||
// Create creates a backup of the target directory using the global backup dir.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProjectBackupDir_FollowsProjectDirectory(t *testing.T) {
|
||||
t.Run("hidden default", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if got, want := ProjectBackupDir(root), filepath.Join(root, ".skillshare", "backups"); got != want {
|
||||
t.Errorf("ProjectBackupDir() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("visible directory", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte("targets: []\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got, want := ProjectBackupDir(root), filepath.Join(dir, "backups"); got != want {
|
||||
t.Errorf("ProjectBackupDir() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
+26
-13
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"skillshare/internal/projectdir"
|
||||
"skillshare/internal/utils"
|
||||
)
|
||||
|
||||
@@ -254,14 +255,19 @@ func PruneStaleSkills(skills []SkillEntry, live map[string]bool, skillsOnly bool
|
||||
}
|
||||
|
||||
// ProjectSources overrides default source directories for project resources.
|
||||
// Relative paths resolve from the project root, not from .skillshare/.
|
||||
// Relative paths resolve from the project root, not from the project directory.
|
||||
type ProjectSources struct {
|
||||
Skills string `yaml:"skills,omitempty"`
|
||||
Agents string `yaml:"agents,omitempty"`
|
||||
Extras string `yaml:"extras,omitempty"`
|
||||
}
|
||||
|
||||
// ProjectConfig holds project-level config (.skillshare/config.yaml).
|
||||
// ProjectDir returns the active project directory for the given root.
|
||||
func ProjectDir(projectRoot string) string {
|
||||
return projectdir.Resolve(projectRoot)
|
||||
}
|
||||
|
||||
// ProjectConfig holds project-level config (<project-dir>/config.yaml).
|
||||
type ProjectConfig struct {
|
||||
Sources ProjectSources `yaml:"sources,omitempty"`
|
||||
Targets []ProjectTargetEntry `yaml:"targets"`
|
||||
@@ -281,7 +287,7 @@ func (c *ProjectConfig) EffectiveSkillsSource(projectRoot string) string {
|
||||
if c.Sources.Skills != "" {
|
||||
return resolveProjectSourcePath(projectRoot, c.Sources.Skills)
|
||||
}
|
||||
return filepath.Join(projectRoot, ".skillshare", "skills")
|
||||
return filepath.Join(projectdir.Resolve(projectRoot), "skills")
|
||||
}
|
||||
|
||||
// EffectiveAgentsSource returns the resolved agents source directory.
|
||||
@@ -289,7 +295,7 @@ func (c *ProjectConfig) EffectiveAgentsSource(projectRoot string) string {
|
||||
if c.Sources.Agents != "" {
|
||||
return resolveProjectSourcePath(projectRoot, c.Sources.Agents)
|
||||
}
|
||||
return filepath.Join(projectRoot, ".skillshare", "agents")
|
||||
return filepath.Join(projectdir.Resolve(projectRoot), "agents")
|
||||
}
|
||||
|
||||
// EffectiveExtrasSource returns the resolved extras parent directory.
|
||||
@@ -297,17 +303,18 @@ func (c *ProjectConfig) EffectiveExtrasSource(projectRoot string) string {
|
||||
if c.Sources.Extras != "" {
|
||||
return resolveProjectSourcePath(projectRoot, c.Sources.Extras)
|
||||
}
|
||||
return filepath.Join(projectRoot, ".skillshare", "extras")
|
||||
return filepath.Join(projectdir.Resolve(projectRoot), "extras")
|
||||
}
|
||||
|
||||
// ProjectGitignoreTarget returns the directory containing the .gitignore to
|
||||
// manage and the entry prefix for skills inside sourcePath. When sourcePath is
|
||||
// under .skillshare/, it returns (.skillshare/, "skills"). When sourcePath is
|
||||
// elsewhere inside projectRoot, it returns (projectRoot, relative-path).
|
||||
// When sourcePath is outside projectRoot (e.g. absolute external path),
|
||||
// both return values are empty — callers must skip gitignore management.
|
||||
// under the project directory, it returns (project-dir, "skills"). When
|
||||
// sourcePath is elsewhere inside projectRoot, it returns (projectRoot,
|
||||
// relative-path). When sourcePath is outside projectRoot (e.g. absolute
|
||||
// external path), both return values are empty — callers must skip gitignore
|
||||
// management.
|
||||
func ProjectGitignoreTarget(projectRoot, sourcePath string) (gitignoreDir, entryPrefix string) {
|
||||
skillshareDir := filepath.Join(projectRoot, ".skillshare")
|
||||
skillshareDir := projectdir.Resolve(projectRoot)
|
||||
if rel, err := filepath.Rel(skillshareDir, sourcePath); err == nil && !strings.HasPrefix(rel, "..") {
|
||||
if rel == "." {
|
||||
return skillshareDir, ""
|
||||
@@ -342,7 +349,7 @@ func (c *ProjectConfig) EffectiveAzureHosts() []string {
|
||||
|
||||
// ProjectConfigPath returns the project config path for the given root.
|
||||
func ProjectConfigPath(projectRoot string) string {
|
||||
return filepath.Join(projectRoot, ".skillshare", "config.yaml")
|
||||
return projectdir.ConfigPath(projectRoot)
|
||||
}
|
||||
|
||||
// LoadProject loads the project config from the given root.
|
||||
@@ -412,9 +419,15 @@ func LoadProject(projectRoot string) (*ProjectConfig, error) {
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// Save writes the project config to the given root.
|
||||
// Save writes the project config to the active project directory under root.
|
||||
func (c *ProjectConfig) Save(projectRoot string) error {
|
||||
path := ProjectConfigPath(projectRoot)
|
||||
return c.SaveIn(ProjectDir(projectRoot))
|
||||
}
|
||||
|
||||
// SaveIn writes the project config into an explicit project directory. Use it
|
||||
// during init, when the directory is chosen rather than discovered.
|
||||
func (c *ProjectConfig) SaveIn(projectDir string) error {
|
||||
path := filepath.Join(projectDir, projectdir.ConfigFileName)
|
||||
dir := filepath.Dir(path)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return fmt.Errorf("failed to create project config directory: %w", err)
|
||||
|
||||
@@ -7,12 +7,13 @@ import (
|
||||
"strings"
|
||||
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/projectdir"
|
||||
)
|
||||
|
||||
// ReconcileProjectSkills scans the project source directory recursively for
|
||||
// remotely-installed skills (those with install metadata or tracked repos)
|
||||
// and ensures they are present in the MetadataStore.
|
||||
// It also updates .skillshare/.gitignore for each tracked skill.
|
||||
// It also updates the project directory's .gitignore for each tracked skill.
|
||||
func ReconcileProjectSkills(projectRoot string, projectCfg *ProjectConfig, store *install.MetadataStore, sourcePath string) error {
|
||||
if _, err := os.Stat(sourcePath); os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -158,7 +159,7 @@ func ReconcileProjectAgents(projectRoot string, store *install.MetadataStore, ag
|
||||
}
|
||||
|
||||
if len(gitignoreEntries) > 0 {
|
||||
if err := install.UpdateGitIgnoreBatch(filepath.Join(projectRoot, ".skillshare"), gitignoreEntries); err != nil {
|
||||
if err := install.UpdateGitIgnoreBatch(projectdir.Resolve(projectRoot), gitignoreEntries); err != nil {
|
||||
return fmt.Errorf("failed to update .skillshare/.gitignore for agents: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// writeVisibleProject creates a project marked by a visible skillshare/ directory.
|
||||
func writeVisibleProject(t *testing.T, root string) string {
|
||||
t.Helper()
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
configYAML := `targets:
|
||||
- claude
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte(configYAML), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func TestProjectConfigPath_VisibleDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := writeVisibleProject(t, root)
|
||||
|
||||
if got, want := ProjectConfigPath(root), filepath.Join(dir, "config.yaml"); got != want {
|
||||
t.Errorf("ProjectConfigPath() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectConfigPath_HiddenWinsOverVisible(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeVisibleProject(t, root)
|
||||
hidden := filepath.Join(root, ".skillshare")
|
||||
if err := os.MkdirAll(hidden, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(hidden, "config.yaml"), []byte("targets: []\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got, want := ProjectConfigPath(root), filepath.Join(hidden, "config.yaml"); got != want {
|
||||
t.Errorf("ProjectConfigPath() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadProject_VisibleDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeVisibleProject(t, root)
|
||||
|
||||
cfg, err := LoadProject(root)
|
||||
if err != nil {
|
||||
t.Fatalf("LoadProject failed: %v", err)
|
||||
}
|
||||
if len(cfg.Targets) != 1 || cfg.Targets[0].Name != "claude" {
|
||||
t.Fatalf("targets = %+v, want one claude target", cfg.Targets)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEffectiveSources_FollowVisibleDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := writeVisibleProject(t, root)
|
||||
|
||||
cfg, err := LoadProject(root)
|
||||
if err != nil {
|
||||
t.Fatalf("LoadProject failed: %v", err)
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
got string
|
||||
want string
|
||||
}{
|
||||
{"skills", cfg.EffectiveSkillsSource(root), filepath.Join(dir, "skills")},
|
||||
{"agents", cfg.EffectiveAgentsSource(root), filepath.Join(dir, "agents")},
|
||||
{"extras", cfg.EffectiveExtrasSource(root), filepath.Join(dir, "extras")},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if tc.got != tc.want {
|
||||
t.Errorf("%s source = %q, want %q", tc.name, tc.got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sources: must still win over the project directory default, and still resolve
|
||||
// from the project root rather than from the marker.
|
||||
func TestEffectiveSources_CustomSourcesStillWin(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
configYAML := `sources:
|
||||
skills: ./docs/skills
|
||||
targets:
|
||||
- claude
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte(configYAML), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg, err := LoadProject(root)
|
||||
if err != nil {
|
||||
t.Fatalf("LoadProject failed: %v", err)
|
||||
}
|
||||
if got, want := cfg.EffectiveSkillsSource(root), filepath.Join(root, "docs", "skills"); got != want {
|
||||
t.Errorf("skills source = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveIn_WritesToGivenDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
|
||||
cfg := &ProjectConfig{Targets: []ProjectTargetEntry{{Name: "claude"}}}
|
||||
if err := cfg.SaveIn(dir); err != nil {
|
||||
t.Fatalf("SaveIn failed: %v", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(dir, "config.yaml")); err != nil {
|
||||
t.Fatalf("config not written to %s: %v", dir, err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, ".skillshare")); !os.IsNotExist(err) {
|
||||
t.Error("SaveIn created a hidden directory")
|
||||
}
|
||||
|
||||
// The saved project must now resolve to the visible directory.
|
||||
if got, want := ProjectConfigPath(root), filepath.Join(dir, "config.yaml"); got != want {
|
||||
t.Errorf("ProjectConfigPath() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectGitignoreTarget_VisibleDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := writeVisibleProject(t, root)
|
||||
|
||||
gitignoreDir, prefix := ProjectGitignoreTarget(root, filepath.Join(dir, "skills"))
|
||||
if gitignoreDir != dir {
|
||||
t.Errorf("gitignoreDir = %q, want %q", gitignoreDir, dir)
|
||||
}
|
||||
if prefix != "skills" {
|
||||
t.Errorf("entryPrefix = %q, want %q", prefix, "skills")
|
||||
}
|
||||
}
|
||||
+23
-6
@@ -11,6 +11,8 @@ import (
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/projectdir"
|
||||
"skillshare/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,16 +31,31 @@ type Entry struct {
|
||||
}
|
||||
|
||||
// LogDir returns the logs directory derived from a config file path.
|
||||
// For project mode: .skillshare/logs/ (alongside project config)
|
||||
// For project mode: <project-dir>/logs/ (alongside project config)
|
||||
// For global mode: $XDG_STATE_HOME/skillshare/logs/
|
||||
func LogDir(configPath string) string {
|
||||
configDir := filepath.Dir(configPath)
|
||||
if filepath.Base(configDir) == ".skillshare" {
|
||||
return filepath.Join(configDir, "logs")
|
||||
if dir, ok := projectConfigDir(configPath); ok {
|
||||
return filepath.Join(dir, "logs")
|
||||
}
|
||||
return filepath.Join(config.StateDir(), "logs")
|
||||
}
|
||||
|
||||
// projectConfigDir returns the project directory holding configPath, if any.
|
||||
//
|
||||
// The visible project directory shares its name with the global config
|
||||
// directory (<config-home>/skillshare), so a name match alone is ambiguous and
|
||||
// the global location is excluded by full path.
|
||||
func projectConfigDir(configPath string) (string, bool) {
|
||||
configDir := filepath.Dir(configPath)
|
||||
if !projectdir.IsName(filepath.Base(configDir)) {
|
||||
return "", false
|
||||
}
|
||||
if utils.PathsEqual(configDir, config.BaseDir()) {
|
||||
return "", false
|
||||
}
|
||||
return configDir, true
|
||||
}
|
||||
|
||||
// Write appends a single JSONL entry to the named log file.
|
||||
func Write(configPath, filename string, e Entry) error {
|
||||
dir := LogDir(configPath)
|
||||
@@ -70,8 +87,8 @@ func Write(configPath, filename string, e Entry) error {
|
||||
}
|
||||
|
||||
func ensureProjectLogGitignore(configPath string) {
|
||||
configDir := filepath.Dir(configPath)
|
||||
if filepath.Base(configDir) != ".skillshare" {
|
||||
configDir, ok := projectConfigDir(configPath)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
_ = install.UpdateGitIgnore(configDir, "logs")
|
||||
|
||||
@@ -19,6 +19,7 @@ func tempConfigPath(t *testing.T) string {
|
||||
|
||||
func TestLogDir_Global(t *testing.T) {
|
||||
t.Setenv("XDG_STATE_HOME", "/custom/state")
|
||||
t.Setenv("XDG_CONFIG_HOME", "/home/user/.config")
|
||||
|
||||
got := LogDir("/home/user/.config/skillshare/config.yaml")
|
||||
want := "/custom/state/skillshare/logs"
|
||||
@@ -35,6 +36,17 @@ func TestLogDir_Project(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogDir_VisibleProject(t *testing.T) {
|
||||
t.Setenv("XDG_STATE_HOME", "/custom/state")
|
||||
t.Setenv("XDG_CONFIG_HOME", "/home/user/.config")
|
||||
|
||||
got := LogDir("/project/skillshare/config.yaml")
|
||||
want := "/project/skillshare/logs"
|
||||
if got != want {
|
||||
t.Errorf("LogDir(visible project) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteAndRead(t *testing.T) {
|
||||
cfgPath := tempConfigPath(t)
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
// Package projectdir resolves the directory that marks a skillshare project.
|
||||
//
|
||||
// A project root is identified by a config.yaml inside a recognized directory.
|
||||
// ".skillshare" is the default. "skillshare" is an alternative for repositories
|
||||
// that treat skills as reviewable content rather than tool state.
|
||||
//
|
||||
// The hidden name is always resolved first, so a repository that already has
|
||||
// .skillshare/ keeps working unchanged even if a visible directory also exists.
|
||||
//
|
||||
// This package has no dependencies on other internal packages so that every
|
||||
// layer (config, audit, trash, backup, oplog, CLI, server) can resolve project
|
||||
// paths the same way.
|
||||
package projectdir
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// Default is the directory name used by "skillshare init -p".
|
||||
Default = ".skillshare"
|
||||
|
||||
// Visible is the directory name used by "skillshare init -p --visible".
|
||||
Visible = "skillshare"
|
||||
|
||||
// ConfigFileName is the file whose presence marks a project directory.
|
||||
ConfigFileName = "config.yaml"
|
||||
)
|
||||
|
||||
// names lists recognized project directory names in resolution order.
|
||||
var names = []string{Default, Visible}
|
||||
|
||||
// Names returns the recognized project directory names in resolution order.
|
||||
func Names() []string {
|
||||
return append([]string(nil), names...)
|
||||
}
|
||||
|
||||
// IsName reports whether name is a recognized project directory name.
|
||||
func IsName(name string) bool {
|
||||
for _, candidate := range names {
|
||||
if name == candidate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Find returns the absolute path of the project directory under projectRoot
|
||||
// that holds a config.yaml. The second return value is false when projectRoot
|
||||
// is not an initialized project.
|
||||
func Find(projectRoot string) (string, bool) {
|
||||
for _, name := range names {
|
||||
dir := filepath.Join(projectRoot, name)
|
||||
if info, err := os.Stat(filepath.Join(dir, ConfigFileName)); err == nil && !info.IsDir() {
|
||||
return dir, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// FindPartial returns a project directory that exists but holds no config.yaml,
|
||||
// which is how a shared skills repository looks after a clone that gitignored
|
||||
// the config. Only the hidden default is accepted on name alone; the visible
|
||||
// name must also carry a marker of its own, so an unrelated directory called
|
||||
// "skillshare" is never mistaken for a project.
|
||||
//
|
||||
// Two markers count: a skills/ or agents/ directory, and a .gitignore that
|
||||
// ignores config.yaml. The second is needed because a repository shared before
|
||||
// any skill was committed clones with nothing else — git carries the .gitignore
|
||||
// but drops the empty skills/ and agents/ directories.
|
||||
func FindPartial(projectRoot string) (string, bool) {
|
||||
for _, name := range names {
|
||||
dir := filepath.Join(projectRoot, name)
|
||||
info, err := os.Stat(dir)
|
||||
if err != nil || !info.IsDir() {
|
||||
continue
|
||||
}
|
||||
if name == Default || hasResourceDir(dir) || hasGitignoredConfig(dir) {
|
||||
return dir, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func hasResourceDir(dir string) bool {
|
||||
for _, name := range []string{"skills", "agents"} {
|
||||
if info, err := os.Stat(filepath.Join(dir, name)); err == nil && info.IsDir() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// hasGitignoredConfig reports whether dir has a .gitignore listing config.yaml,
|
||||
// the marker written by "init -p --config local".
|
||||
//
|
||||
// This repeats what install.GitignoreContains does for that one pattern rather
|
||||
// than calling it, because this package must not depend on other internal
|
||||
// packages. An unreadable .gitignore is treated as absent: the marker only ever
|
||||
// widens what counts as a project, so failing to read it leaves the directory
|
||||
// unclaimed rather than claiming it wrongly.
|
||||
func hasGitignoredConfig(dir string) bool {
|
||||
f, err := os.Open(filepath.Join(dir, ".gitignore"))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
if strings.TrimSpace(scanner.Text()) == ConfigFileName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Resolve returns the project directory to use for projectRoot. An initialized
|
||||
// project resolves to its own directory; anything else resolves to the default
|
||||
// name so new projects keep the current layout.
|
||||
func Resolve(projectRoot string) string {
|
||||
if dir, ok := Find(projectRoot); ok {
|
||||
return dir
|
||||
}
|
||||
if dir, ok := FindPartial(projectRoot); ok {
|
||||
return dir
|
||||
}
|
||||
return filepath.Join(projectRoot, Default)
|
||||
}
|
||||
|
||||
// ConfigPath returns the project config path for projectRoot.
|
||||
func ConfigPath(projectRoot string) string {
|
||||
return filepath.Join(Resolve(projectRoot), ConfigFileName)
|
||||
}
|
||||
|
||||
// Name returns the directory name to create for a new project.
|
||||
func Name(visible bool) string {
|
||||
if visible {
|
||||
return Visible
|
||||
}
|
||||
return Default
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package projectdir
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func writeConfig(t *testing.T, dir string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, ConfigFileName), []byte("targets: []\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
create []string
|
||||
want string
|
||||
wantOK bool
|
||||
comment string
|
||||
}{
|
||||
{name: "hidden only", create: []string{Default}, want: Default, wantOK: true},
|
||||
{name: "visible only", create: []string{Visible}, want: Visible, wantOK: true},
|
||||
{
|
||||
name: "both present prefers hidden",
|
||||
create: []string{Default, Visible},
|
||||
want: Default,
|
||||
wantOK: true,
|
||||
comment: "back-compat: an existing project must never move",
|
||||
},
|
||||
{name: "neither present", create: nil, wantOK: false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
for _, name := range tt.create {
|
||||
writeConfig(t, filepath.Join(root, name))
|
||||
}
|
||||
|
||||
got, ok := Find(root)
|
||||
if ok != tt.wantOK {
|
||||
t.Fatalf("Find() ok = %v, want %v", ok, tt.wantOK)
|
||||
}
|
||||
if !tt.wantOK {
|
||||
return
|
||||
}
|
||||
if want := filepath.Join(root, tt.want); got != want {
|
||||
t.Errorf("Find() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindIgnoresConfigDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
// A directory named config.yaml is not a config file.
|
||||
if err := os.MkdirAll(filepath.Join(root, Default, ConfigFileName), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, ok := Find(root); ok {
|
||||
t.Error("Find() found a project where config.yaml is a directory")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveDefaultsToHidden(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
|
||||
if got, want := Resolve(root), filepath.Join(root, Default); got != want {
|
||||
t.Errorf("Resolve(empty root) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveUsesVisibleProject(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeConfig(t, filepath.Join(root, Visible))
|
||||
|
||||
if got, want := Resolve(root), filepath.Join(root, Visible); got != want {
|
||||
t.Errorf("Resolve() = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := ConfigPath(root), filepath.Join(root, Visible, ConfigFileName); got != want {
|
||||
t.Errorf("ConfigPath() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindPartial(t *testing.T) {
|
||||
t.Run("hidden directory without config", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, Default), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, ok := FindPartial(root)
|
||||
if !ok {
|
||||
t.Fatal("FindPartial() did not report a partial project")
|
||||
}
|
||||
if want := filepath.Join(root, Default); got != want {
|
||||
t.Errorf("FindPartial() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("visible directory needs a resource directory", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
// An unrelated directory that merely shares the name is not a project.
|
||||
if err := os.MkdirAll(filepath.Join(root, Visible, "docs"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, ok := FindPartial(root); ok {
|
||||
t.Error("FindPartial() claimed an unrelated skillshare/ directory")
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Join(root, Visible, "skills"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, ok := FindPartial(root)
|
||||
if !ok {
|
||||
t.Fatal("FindPartial() did not report a partial visible project")
|
||||
}
|
||||
if want := filepath.Join(root, Visible); got != want {
|
||||
t.Errorf("FindPartial() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
// A shared repo created before any skill was committed clones with only the
|
||||
// tracked .gitignore: git does not carry the empty skills/ and agents/.
|
||||
t.Run("visible directory with only a gitignored config", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeGitignore(t, filepath.Join(root, Visible), "logs\ntrash\nbackups\nconfig.yaml\n")
|
||||
|
||||
got, ok := FindPartial(root)
|
||||
if !ok {
|
||||
t.Fatal("FindPartial() did not report a freshly cloned shared repository")
|
||||
}
|
||||
if want := filepath.Join(root, Visible); got != want {
|
||||
t.Errorf("FindPartial() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("visible directory with an unrelated gitignore", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeGitignore(t, filepath.Join(root, Visible), "# config.yaml\nbuild/\nnotes.md\n")
|
||||
|
||||
if _, ok := FindPartial(root); ok {
|
||||
t.Error("FindPartial() claimed a skillshare/ directory whose .gitignore does not cover config.yaml")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func writeGitignore(t *testing.T, dir, content string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, ".gitignore"), []byte(content), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsName(t *testing.T) {
|
||||
for _, name := range []string{Default, Visible} {
|
||||
if !IsName(name) {
|
||||
t.Errorf("IsName(%q) = false, want true", name)
|
||||
}
|
||||
}
|
||||
for _, name := range []string{".claude", "skills", "", "Skillshare"} {
|
||||
if IsName(name) {
|
||||
t.Errorf("IsName(%q) = true, want false", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamesOrderAndIsolation(t *testing.T) {
|
||||
names := Names()
|
||||
if len(names) != 2 || names[0] != Default || names[1] != Visible {
|
||||
t.Fatalf("Names() = %v, want [%q %q]", names, Default, Visible)
|
||||
}
|
||||
|
||||
names[0] = "mutated"
|
||||
if Names()[0] != Default {
|
||||
t.Error("Names() returned a slice aliasing package state")
|
||||
}
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
if got := Name(false); got != Default {
|
||||
t.Errorf("Name(false) = %q, want %q", got, Default)
|
||||
}
|
||||
if got := Name(true); got != Visible {
|
||||
t.Errorf("Name(true) = %q, want %q", got, Visible)
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"skillshare/internal/git"
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/projectdir"
|
||||
"skillshare/internal/resource"
|
||||
"skillshare/internal/sync"
|
||||
"skillshare/internal/utils"
|
||||
@@ -27,7 +28,7 @@ func (s *Server) handleOverview(w http.ResponseWriter, r *http.Request) {
|
||||
agentsSource := s.agentsSource()
|
||||
extrasSource := s.cfg.EffectiveExtrasSource()
|
||||
if s.IsProjectMode() {
|
||||
extrasSource = filepath.Join(s.projectRoot, ".skillshare", "extras")
|
||||
extrasSource = filepath.Join(projectdir.Resolve(s.projectRoot), "extras")
|
||||
}
|
||||
cfgMode := s.cfg.Mode
|
||||
targetCount := len(s.cfg.Targets)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/projectdir"
|
||||
)
|
||||
|
||||
const defaultMaxAge = 7 * 24 * time.Hour // 7 days
|
||||
@@ -118,7 +119,7 @@ func TrashDir() string {
|
||||
|
||||
// ProjectTrashDir returns the project-level trash directory path.
|
||||
func ProjectTrashDir(root string) string {
|
||||
return filepath.Join(root, ".skillshare", "trash")
|
||||
return filepath.Join(projectdir.Resolve(root), "trash")
|
||||
}
|
||||
|
||||
// AgentTrashDir returns the global trash directory for agents.
|
||||
@@ -128,7 +129,7 @@ func AgentTrashDir() string {
|
||||
|
||||
// ProjectAgentTrashDir returns the project-level trash directory for agents.
|
||||
func ProjectAgentTrashDir(root string) string {
|
||||
return filepath.Join(root, ".skillshare", "trash", "agents")
|
||||
return filepath.Join(projectdir.Resolve(root), "trash", "agents")
|
||||
}
|
||||
|
||||
// MoveAgentToTrash moves an agent file (and its metadata) to the trash directory.
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package trash
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func markVisibleProject(t *testing.T, root string) string {
|
||||
t.Helper()
|
||||
dir := filepath.Join(root, "skillshare")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte("targets: []\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func TestProjectTrashDir_FollowsProjectDirectory(t *testing.T) {
|
||||
t.Run("hidden default", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if got, want := ProjectTrashDir(root), filepath.Join(root, ".skillshare", "trash"); got != want {
|
||||
t.Errorf("ProjectTrashDir() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("visible directory", func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := markVisibleProject(t, root)
|
||||
if got, want := ProjectTrashDir(root), filepath.Join(dir, "trash"); got != want {
|
||||
t.Errorf("ProjectTrashDir() = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := ProjectAgentTrashDir(root), filepath.Join(dir, "trash", "agents"); got != want {
|
||||
t.Errorf("ProjectAgentTrashDir() = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://raw.githubusercontent.com/runkids/skillshare/main/schemas/project-config.schema.json",
|
||||
"title": "Skillshare Project Configuration",
|
||||
"description": "Project-level configuration for skillshare. Location: .skillshare/config.yaml",
|
||||
"description": "Project-level configuration for skillshare. Location: .skillshare/config.yaml, or skillshare/config.yaml for a visible project directory.",
|
||||
"type": "object",
|
||||
"required": ["targets"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"sources": {
|
||||
"type": "object",
|
||||
"description": "Custom source directories for project resources. Each key overrides the default .skillshare/{key}/ path. Relative paths resolve from the project root.",
|
||||
"description": "Custom source directories for project resources. Each key overrides the default <project-dir>/{key}/ path. Relative paths resolve from the project root.",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"skills": {
|
||||
|
||||
@@ -5,7 +5,7 @@ description: |
|
||||
Use this skill whenever the user mentions "skillshare", runs skillshare commands,
|
||||
manages skills or agents (install, update, uninstall, sync, commit, audit, analyze, check, diff, search),
|
||||
or troubleshoots skill/agent configuration (orphaned symlinks, broken targets, sync
|
||||
issues). Covers both global (~/.config/skillshare/) and project (.skillshare/)
|
||||
issues). Covers both global (~/.config/skillshare/) and project (.skillshare/ or skillshare/)
|
||||
modes. Also use when: adding new AI tool targets (Claude, Cursor, Windsurf, etc.),
|
||||
setting target include/exclude filters or copy vs symlink mode, using backup/restore
|
||||
or trash recovery, piping skillshare output to scripts (--json), setting up CI/CD
|
||||
@@ -21,7 +21,7 @@ metadata:
|
||||
# Skillshare CLI
|
||||
|
||||
Global: `~/.config/skillshare/skills/` → all AI CLIs. Project: `.skillshare/skills/` → repo-local.
|
||||
Auto-detects project mode when `.skillshare/config.yaml` exists. Force with `-p` or `-g`.
|
||||
Auto-detects project mode from `.skillshare/config.yaml` or `skillshare/config.yaml` (hidden wins when both exist). Force with `-p` or `-g`.
|
||||
|
||||
## Recipes
|
||||
|
||||
@@ -29,6 +29,7 @@ Auto-detects project mode when `.skillshare/config.yaml` exists. Force with `-p`
|
||||
```bash
|
||||
skillshare init --no-copy --all-targets --git --skill # Fresh global setup
|
||||
skillshare init -p --targets "claude,cursor" # Fresh project setup
|
||||
skillshare init -p --visible # Use skillshare/ instead of .skillshare/
|
||||
skillshare init --copy-from claude --all-targets --git # Import from existing CLI
|
||||
skillshare init --discover --select "windsurf" # Add new AI tool later
|
||||
```
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//go:build !online
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/testutil"
|
||||
)
|
||||
|
||||
func TestSyncProject_VisibleDirectoryAfterRename(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
root := sb.SetupProjectDir("claude")
|
||||
sb.CreateProjectSkill(root, "demo", map[string]string{"SKILL.md": "# Demo"})
|
||||
sb.RunCLIInDir(root, "sync", "-p").AssertSuccess(t)
|
||||
|
||||
link := filepath.Join(root, ".claude", "skills", "demo", "SKILL.md")
|
||||
if _, err := os.ReadFile(link); err != nil {
|
||||
t.Fatalf("initial target is unreadable: %v", err)
|
||||
}
|
||||
if err := os.Rename(filepath.Join(root, ".skillshare"), filepath.Join(root, "skillshare")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.ReadFile(link); !os.IsNotExist(err) {
|
||||
t.Fatalf("expected old target link to break after rename, got %v", err)
|
||||
}
|
||||
|
||||
// Auto-detection must find the visible config and sync must repair old links.
|
||||
sb.RunCLIInDir(root, "sync").AssertSuccess(t)
|
||||
body, err := os.ReadFile(link)
|
||||
if err != nil || string(body) != "# Demo" {
|
||||
t.Fatalf("target was not repaired: body=%q err=%v", body, err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, ".skillshare")); !os.IsNotExist(err) {
|
||||
t.Fatalf("sync recreated the hidden project directory: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ When any AI CLI is detected, `init` automatically recommends the **universal** t
|
||||
:::
|
||||
|
||||
:::tip Agents source path
|
||||
The agents source defaults to `<source parent>/agents` (so `~/.config/skillshare/agents/` for the default install). Set `agents_source:` in `config.yaml` to override the location. Project mode always uses `.skillshare/agents/` and does not honor `agents_source`. Agent-capable targets (Claude, Cursor, Augment, OpenCode) pick agents up automatically once you run `skillshare sync`.
|
||||
The agents source defaults to `<source parent>/agents` (so `~/.config/skillshare/agents/` for the default install). Set `agents_source:` in `config.yaml` to override the location. Project mode always uses `agents/` inside the project directory and does not honor `agents_source`. Agent-capable targets (Claude, Cursor, Augment, OpenCode) pick agents up automatically once you run `skillshare sync`.
|
||||
:::
|
||||
|
||||
## Project Mode
|
||||
@@ -51,6 +51,7 @@ Initialize project-level skills with `-p`:
|
||||
```bash
|
||||
skillshare init -p # Interactive
|
||||
skillshare init -p --targets claude,cursor # Non-interactive
|
||||
skillshare init -p --visible # Use a visible skillshare/ directory
|
||||
```
|
||||
|
||||
### What Happens
|
||||
@@ -65,7 +66,7 @@ flowchart TD
|
||||
TITLE --> S1 --> S2 --> S3 --> S4
|
||||
```
|
||||
|
||||
After init, commit `.skillshare/` to git (both `skills/` and `agents/`). See [Project Setup](/docs/how-to/sharing/project-setup) for the full guide.
|
||||
After init, commit the project directory to git (both `skills/` and `agents/`). Use `--visible` to create `skillshare/` instead of `.skillshare/`. See [Project Setup](/docs/how-to/sharing/project-setup) for the full guide.
|
||||
|
||||
## Discover Mode
|
||||
|
||||
@@ -126,6 +127,7 @@ If you run `skillshare init` on an already-initialized setup without `--discover
|
||||
| `--discover, -d` | Detect and add new AI CLI targets to existing config |
|
||||
| `--select <list>` | Comma-separated targets to add (requires `--discover`) |
|
||||
| `--config local` | Gitignore `config.yaml` so each developer manages own targets (project mode only). See [Centralized Skills Repo](/docs/how-to/recipes/centralized-skills-repo) recipe. |
|
||||
| `--visible` | Create a visible `skillshare/` project directory instead of `.skillshare/` (project mode only). See [Project Skills](/docs/understand/project-skills#visible-project-directory). |
|
||||
| `--git-root <scope>` | Directory for `commit`/`push`/`pull` operations (`skills` default, `agents`, `extras`, `root`). `root` versions skills + agents + extras together in one repo with `config.yaml` auto-ignored. Also offered interactively during setup. Re-run `skillshare init --git-root <scope>` later to switch scope headlessly — it inits a repo at the new scope and persists the setting, but does not move existing history. |
|
||||
| `--subdir <name>` | Use a subdirectory as the source path (e.g. `skills`) |
|
||||
| `--dry-run, -n` | Preview without changes |
|
||||
|
||||
@@ -119,6 +119,45 @@ Symlinks in project mode use **relative paths** (e.g., `../../.skillshare/skills
|
||||
|
||||
---
|
||||
|
||||
## Visible Project Directory
|
||||
|
||||
Repositories that treat skills as reviewable content rather than tool state can use a visible `skillshare/` directory instead of the hidden `.skillshare/`:
|
||||
|
||||
```bash
|
||||
skillshare init -p --visible
|
||||
```
|
||||
|
||||
```
|
||||
<project-root>/
|
||||
├── skillshare/
|
||||
│ ├── config.yaml
|
||||
│ ├── skills/
|
||||
│ └── agents/
|
||||
└── src/
|
||||
```
|
||||
|
||||
Everything else is identical — `config.yaml`, `skills/`, `agents/`, `extras/`, and the operational `trash/`, `backups/` and `logs/` directories all live inside whichever project directory is in use.
|
||||
|
||||
Detection checks `.skillshare/config.yaml` first and `skillshare/config.yaml` second, so:
|
||||
|
||||
- Existing projects are unaffected.
|
||||
- If both directories exist, `.skillshare/` wins.
|
||||
- To move an existing project, run `mv .skillshare skillshare`, then `skillshare sync -p` to repair target symlinks that still point to the old directory. If your `sources` settings explicitly reference `.skillshare/`, update those paths in `config.yaml` before syncing.
|
||||
|
||||
`init -p` without `--visible` continues to create `.skillshare/`.
|
||||
|
||||
:::note
|
||||
The global config directory is also called `skillshare` (`~/.config/skillshare/`). Only a `skillshare/` directory inside a project root is treated as a project.
|
||||
:::
|
||||
|
||||
### Missing config
|
||||
|
||||
Project commands initialize a project automatically when there isn't one yet, and a [shared skills repo](/docs/how-to/recipes/centralized-skills-repo) using `--config local` regenerates its gitignored `config.yaml` the same way.
|
||||
|
||||
They stop short of one case: if the project directory already holds skills or agents but its `config.yaml` is missing, re-initializing would write an empty config and drop every configured target. Those commands report the problem instead, so you can restore `config.yaml` from version control or run `skillshare init -p` deliberately.
|
||||
|
||||
---
|
||||
|
||||
## Config Format
|
||||
|
||||
`.skillshare/config.yaml`:
|
||||
@@ -201,8 +240,8 @@ sources:
|
||||
|
||||
- **No alias with target paths.** `skillshare sync -p` rejects configs where a source resolves to the same directory as a target (or one contains the other). This prevents `sync --force` from wiping the configured source. For example, `sources.skills: .claude/skills` combined with a `claude` target is rejected with an `overlaps` error.
|
||||
- **External paths skip gitignore management.** When a source resolves outside the project root (an absolute path elsewhere on disk), skillshare does not add entries to the project's `.gitignore`. Manage ignore rules in the source directory yourself if needed.
|
||||
- **Operational dirs stay in `.skillshare/`.** Trash, backups, and operation logs always live under `.skillshare/` regardless of `sources` settings.
|
||||
- **`init -p` always seeds `.skillshare/{skills,agents}/`.** Custom sources take effect only after you edit `config.yaml`.
|
||||
- **Operational dirs stay in the project directory.** Trash, backups, and operation logs always live under the active project directory (`.skillshare/`, or `skillshare/` — see below) regardless of `sources` settings.
|
||||
- **`init -p` always seeds `{skills,agents}/` in the project directory.** Custom sources take effect only after you edit `config.yaml`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user