diff --git a/tests/integration/sync_extras_test.go b/tests/integration/sync_extras_test.go index 6a0779f1f..daef30460 100644 --- a/tests/integration/sync_extras_test.go +++ b/tests/integration/sync_extras_test.go @@ -5,6 +5,7 @@ package integration import ( "os" "path/filepath" + "strings" "testing" "skillshare/internal/testutil" @@ -407,3 +408,115 @@ extras: // Sync auto-creates missing extras source directories (same as target dirs) result.AssertAnyOutputContains(t, "Created source directory") } + +func TestSyncExtras_FlattenMerge(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.CreateSkill("placeholder", map[string]string{ + "SKILL.md": "# Placeholder", + }) + targetPath := sb.CreateTarget("claude") + + sourceRoot := filepath.Dir(sb.SourcePath) + agentsSource := filepath.Join(sourceRoot, "extras", "agents") + os.MkdirAll(filepath.Join(agentsSource, "curriculum"), 0755) + os.MkdirAll(filepath.Join(agentsSource, "software"), 0755) + os.WriteFile(filepath.Join(agentsSource, "curriculum", "tactician.md"), []byte("# Tactician"), 0644) + os.WriteFile(filepath.Join(agentsSource, "software", "implementer.md"), []byte("# Implementer"), 0644) + os.WriteFile(filepath.Join(agentsSource, "reviewer.md"), []byte("# Reviewer"), 0644) + + agentsTarget := filepath.Join(sb.Home, ".claude", "agents") + os.MkdirAll(agentsTarget, 0755) + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: + claude: + path: ` + targetPath + ` +extras: + - name: agents + targets: + - path: ` + agentsTarget + ` + flatten: true +`) + + result := sb.RunCLI("sync", "extras") + result.AssertSuccess(t) + result.AssertAnyOutputContains(t, "3 files") + + for _, name := range []string{"tactician.md", "implementer.md", "reviewer.md"} { + if !sb.IsSymlink(filepath.Join(agentsTarget, name)) { + t.Errorf("%s should be a flat symlink in target", name) + } + } + if _, err := os.Stat(filepath.Join(agentsTarget, "curriculum")); !os.IsNotExist(err) { + t.Error("curriculum/ should not exist in target") + } +} + +func TestSyncExtras_FlattenCollision(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.CreateSkill("placeholder", map[string]string{ + "SKILL.md": "# Placeholder", + }) + targetPath := sb.CreateTarget("claude") + + sourceRoot := filepath.Dir(sb.SourcePath) + agentsSource := filepath.Join(sourceRoot, "extras", "agents") + os.MkdirAll(filepath.Join(agentsSource, "team-a"), 0755) + os.MkdirAll(filepath.Join(agentsSource, "team-b"), 0755) + os.WriteFile(filepath.Join(agentsSource, "team-a", "agent.md"), []byte("# Team A"), 0644) + os.WriteFile(filepath.Join(agentsSource, "team-b", "agent.md"), []byte("# Team B"), 0644) + + agentsTarget := filepath.Join(sb.Home, ".claude", "agents") + os.MkdirAll(agentsTarget, 0755) + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: + claude: + path: ` + targetPath + ` +extras: + - name: agents + targets: + - path: ` + agentsTarget + ` + flatten: true +`) + + result := sb.RunCLI("sync", "extras") + result.AssertSuccess(t) + result.AssertAnyOutputContains(t, "flatten conflict") + + if !sb.IsSymlink(filepath.Join(agentsTarget, "agent.md")) { + t.Error("agent.md should be a symlink") + } +} + +func TestSyncExtras_FlattenConfigRoundTrip(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.CreateSkill("placeholder", map[string]string{ + "SKILL.md": "# Placeholder", + }) + targetPath := sb.CreateTarget("claude") + + agentsTarget := filepath.Join(sb.Home, ".claude", "agents") + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: + claude: + path: ` + targetPath + ` +extras: + - name: agents + targets: + - path: ` + agentsTarget + ` + flatten: true +`) + + content := sb.ReadFile(sb.ConfigPath) + if !strings.Contains(content, "flatten: true") { + t.Error("config should contain flatten: true") + } +} diff --git a/ui/src/api/client.ts b/ui/src/api/client.ts index 2f4f0e442..7cd0e9cfd 100644 --- a/ui/src/api/client.ts +++ b/ui/src/api/client.ts @@ -72,6 +72,7 @@ function createSSEStream( export interface ExtraTarget { path: string; mode: string; + flatten: boolean; status: string; // "synced" | "drift" | "not synced" | "no source" } @@ -351,10 +352,10 @@ export const api = { }), deleteExtra: (name: string) => apiFetch<{ success: boolean }>(`/extras/${encodeURIComponent(name)}`, { method: 'DELETE' }), - setExtraMode: (name: string, target: string, mode: string) => + setExtraMode: (name: string, target: string, mode: string, flatten?: boolean) => apiFetch<{ success: boolean }>(`/extras/${encodeURIComponent(name)}/mode`, { method: 'PATCH', - body: JSON.stringify({ target, mode }), + body: JSON.stringify({ target, mode, ...(flatten !== undefined && { flatten }) }), }), // Log diff --git a/ui/src/lib/fieldDocs.ts b/ui/src/lib/fieldDocs.ts index f1318941a..33c7124b5 100644 --- a/ui/src/lib/fieldDocs.ts +++ b/ui/src/lib/fieldDocs.ts @@ -105,6 +105,11 @@ export const fieldDocs: Record = { allowedValues: ['merge', 'symlink', 'copy'], example: 'mode: merge', }, + 'extras.targets.flatten': { + description: 'When true, files from subdirectories are synced directly into the target root. Cannot be used with symlink mode.', + type: 'boolean', + example: 'flatten: true', + }, // --- Audit --- audit: { diff --git a/ui/src/pages/ExtrasPage.tsx b/ui/src/pages/ExtrasPage.tsx index ddd27407f..0ea40e3f6 100644 --- a/ui/src/pages/ExtrasPage.tsx +++ b/ui/src/pages/ExtrasPage.tsx @@ -23,6 +23,7 @@ import { PageSkeleton } from '../components/Skeleton'; interface TargetEntry { path: string; mode: string; + flatten: boolean; } const MODE_OPTIONS = [ @@ -41,12 +42,12 @@ function AddExtraModal({ const { toast } = useToast(); const [name, setName] = useState(''); const [source, setSource] = useState(''); - const [targets, setTargets] = useState([{ path: '', mode: 'merge' }]); + const [targets, setTargets] = useState([{ path: '', mode: 'merge', flatten: false }]); const [saving, setSaving] = useState(false); - const addTarget = () => setTargets((prev) => [...prev, { path: '', mode: 'merge' }]); + const addTarget = () => setTargets((prev) => [...prev, { path: '', mode: 'merge', flatten: false }]); - const updateTarget = (i: number, field: keyof TargetEntry, value: string) => { + const updateTarget = (i: number, field: keyof TargetEntry, value: string | boolean) => { setTargets((prev) => prev.map((t, idx) => (idx === i ? { ...t, [field]: value } : t))); }; @@ -69,7 +70,7 @@ function AddExtraModal({ await api.createExtra({ name: name.trim(), ...(source.trim() && { source: source.trim() }), - targets: validTargets.map((t) => ({ path: t.path.trim(), mode: t.mode })), + targets: validTargets.map((t) => ({ path: t.path.trim(), mode: t.mode, flatten: t.flatten })), }); toast(`Extra "${name.trim()}" created`, 'success'); onCreated(); @@ -139,10 +140,25 @@ function AddExtraModal({
updateTarget(i, 'flatten', e.target.checked)} + disabled={saving || t.mode === 'symlink'} + className="accent-primary" + /> + + Flatten + + {targets.length > 1 && ( } @@ -196,7 +212,7 @@ function ExtraCard({ onSync: (name: string) => Promise; onForceSync: (name: string) => Promise; onRemove: (name: string) => void; - onModeChange: (name: string, target: string, mode: string) => Promise; + onModeChange: (name: string, target: string, mode: string, flatten?: boolean) => Promise; }) { const [syncing, setSyncing] = useState(false); const [changingMode, setChangingMode] = useState(null); @@ -293,6 +309,26 @@ function ExtraCard({ {t.status}
+