mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(ui): show local agent count in targets and fix agent batch uninstall
Add agentLocalCount to target API and CLI JSON output so the UI can display how many local (non-source) agents exist per target. - Add LocalCount to AgentSummary, computed via FindLocalAgents - Surface agentLocalCount in both CLI target list JSON and server API - Show local agent counts in target detail summaries (CLI + UI) - Collect button now appears for targets with local agents and routes to CollectPage with scope=agent query param - CollectPage reads scope from URL and auto-scans on mount - Fix BatchUninstallPage: agents tab was collapsing individual agent names into the repo name via buildApiNames(), causing 'agent not found' errors; now sends each agent flatName individually - Invalidate targets + diff queries after successful collect
This commit is contained in:
@@ -50,6 +50,13 @@
|
||||
- **Fix**: Redirect non-JSON commands to `/dev/null` (`ss extras remove ... >/dev/null 2>&1`) so that only the `--json` output remains in stdout. Alternative: split into separate steps (one for setup, one for JSON assertion)
|
||||
- **Runbooks affected**: extras_source_config_runbook.md (steps 6, 11)
|
||||
|
||||
### [gotcha] Expected lines starting with `no ...` can be parsed as negation
|
||||
|
||||
- **Context**: `target_local_agents_visibility_runbook.md` originally asserted `- no source agents yet (1 local)` for plain-text target output
|
||||
- **Discovery**: mdproof interpreted that Expected line as a negated substring assertion instead of a positive one because it began with `no`
|
||||
- **Fix**: Avoid bare Expected lines that start with `no`. Prefix them with stable surrounding text such as `Status: no source agents yet (1 local)` or switch to `regex:` / `jq:` assertions
|
||||
- **Runbooks affected**: `target_local_agents_visibility_runbook.md`
|
||||
|
||||
### [gotcha] Don't nest ssenv inside mdproof — use mdproof's own isolation
|
||||
|
||||
- **Context**: cli-e2e-test skill wraps mdproof inside `ssenv enter $ENV -- mdproof ...`, but mdproof.json has its own `setup` command that runs `ss init -g --force`
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
# CLI E2E Runbook: Target Local Agents Visibility
|
||||
|
||||
Validates that `ss target` output exposes local-only agents in both plain-text
|
||||
and JSON modes instead of collapsing them into a misleading "no agents" state.
|
||||
|
||||
**Origin**: v0.19.x — target agent summaries now report local agent counts when
|
||||
the source has zero agents, and the CLI needs regression coverage for that
|
||||
display contract.
|
||||
|
||||
## Scope
|
||||
|
||||
- Global `ss target claude -g` shows `no source agents yet (1 local)` when the
|
||||
Claude target has a local-only agent file
|
||||
- Global `ss target list --json -g` returns `agentLocalCount` alongside zero
|
||||
expected/linked counts for that case
|
||||
- Project `ss target claude -p` mirrors the same local-only agent summary
|
||||
- Project `ss target list --json -p` returns the same local-only agent metadata
|
||||
|
||||
## Environment
|
||||
|
||||
Run inside devcontainer via mdproof.
|
||||
Use explicit `-g` and `-p` flags to avoid auto-mode ambiguity.
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. Global target info shows local-only agents when source is empty
|
||||
|
||||
```bash
|
||||
set -e
|
||||
rm -f ~/.config/skillshare/agents/local-only.md ~/.claude/agents/local-only.md
|
||||
mkdir -p ~/.claude/agents
|
||||
|
||||
cat > ~/.claude/agents/local-only.md <<'EOF'
|
||||
---
|
||||
name: local-only
|
||||
description: Local-only target agent
|
||||
---
|
||||
# Local Only
|
||||
EOF
|
||||
|
||||
ss target claude -g
|
||||
```
|
||||
|
||||
Expected:
|
||||
- exit_code: 0
|
||||
- Agents:
|
||||
- .claude/agents
|
||||
- Status: no source agents yet (1 local)
|
||||
|
||||
### 2. Global target list JSON reports agentLocalCount for local-only agents
|
||||
|
||||
```bash
|
||||
set -e
|
||||
rm -f ~/.config/skillshare/agents/local-only.md ~/.claude/agents/local-only.md
|
||||
mkdir -p ~/.claude/agents
|
||||
|
||||
cat > ~/.claude/agents/local-only.md <<'EOF'
|
||||
---
|
||||
name: local-only
|
||||
description: Local-only target agent
|
||||
---
|
||||
# Local Only
|
||||
EOF
|
||||
|
||||
ss target list --json -g
|
||||
```
|
||||
|
||||
Expected:
|
||||
- exit_code: 0
|
||||
- jq: (.targets[] | select(.name == "claude").agentLocalCount) == 1
|
||||
- jq: (.targets[] | select(.name == "claude").agentExpectedCount) == 0
|
||||
- jq: (.targets[] | select(.name == "claude").agentLinkedCount) == 0
|
||||
- jq: (.targets[] | select(.name == "claude").agentPath | type) == "string"
|
||||
|
||||
### 3. Project target info shows local-only agents when project source is empty
|
||||
|
||||
```bash
|
||||
set -e
|
||||
PROJECT=/tmp/target-local-agents-project-info
|
||||
rm -rf "$PROJECT"
|
||||
mkdir -p "$PROJECT/.skillshare/skills" "$PROJECT/.skillshare/agents" "$PROJECT/.claude/agents"
|
||||
|
||||
cat > "$PROJECT/.skillshare/config.yaml" <<'EOF'
|
||||
targets:
|
||||
- claude
|
||||
EOF
|
||||
|
||||
cat > "$PROJECT/.claude/agents/local-only.md" <<'EOF'
|
||||
---
|
||||
name: local-only
|
||||
description: Local-only project target agent
|
||||
---
|
||||
# Local Only
|
||||
EOF
|
||||
|
||||
cd "$PROJECT"
|
||||
ss target claude -p
|
||||
```
|
||||
|
||||
Expected:
|
||||
- exit_code: 0
|
||||
- Agents:
|
||||
- .claude/agents
|
||||
- Status: no source agents yet (1 local)
|
||||
|
||||
### 4. Project target list JSON reports agentLocalCount for local-only agents
|
||||
|
||||
```bash
|
||||
set -e
|
||||
PROJECT=/tmp/target-local-agents-project-json
|
||||
rm -rf "$PROJECT"
|
||||
mkdir -p "$PROJECT/.skillshare/skills" "$PROJECT/.skillshare/agents" "$PROJECT/.claude/agents"
|
||||
|
||||
cat > "$PROJECT/.skillshare/config.yaml" <<'EOF'
|
||||
targets:
|
||||
- claude
|
||||
EOF
|
||||
|
||||
cat > "$PROJECT/.claude/agents/local-only.md" <<'EOF'
|
||||
---
|
||||
name: local-only
|
||||
description: Local-only project target agent
|
||||
---
|
||||
# Local Only
|
||||
EOF
|
||||
|
||||
cd "$PROJECT"
|
||||
ss target list --json -p
|
||||
```
|
||||
|
||||
Expected:
|
||||
- exit_code: 0
|
||||
- jq: .targets | length == 1
|
||||
- jq: (.targets[0].name) == "claude"
|
||||
- jq: (.targets[0].agentLocalCount) == 1
|
||||
- jq: (.targets[0].agentExpectedCount) == 0
|
||||
- jq: (.targets[0].agentLinkedCount) == 0
|
||||
- jq: (.targets[0].agentPath | endswith("/.claude/agents")) == true
|
||||
|
||||
## Pass Criteria
|
||||
|
||||
- Plain-text target info makes local-only agents visible in both global and
|
||||
project mode
|
||||
- JSON target list includes `agentLocalCount` for local-only agent targets
|
||||
- The CLI no longer implies "no agents" when the target actually contains local
|
||||
agent files
|
||||
@@ -452,6 +452,7 @@ type targetListJSONItem struct {
|
||||
AgentInclude []string `json:"agentInclude,omitempty"`
|
||||
AgentExclude []string `json:"agentExclude,omitempty"`
|
||||
AgentLinkedCount *int `json:"agentLinkedCount,omitempty"`
|
||||
AgentLocalCount *int `json:"agentLocalCount,omitempty"`
|
||||
AgentExpectedCount *int `json:"agentExpectedCount,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/sync"
|
||||
@@ -18,6 +19,7 @@ func applyTargetListAgentSummary(item *targetListJSONItem, summary *targetsummar
|
||||
item.AgentInclude = append([]string(nil), summary.Include...)
|
||||
item.AgentExclude = append([]string(nil), summary.Exclude...)
|
||||
item.AgentLinkedCount = intPtr(summary.ManagedCount)
|
||||
item.AgentLocalCount = intPtr(summary.LocalCount)
|
||||
item.AgentExpectedCount = intPtr(summary.ExpectedCount)
|
||||
}
|
||||
|
||||
@@ -97,19 +99,34 @@ func formatTargetAgentSyncSummary(summary *targetsummary.AgentSummary) string {
|
||||
}
|
||||
|
||||
if summary.ExpectedCount == 0 {
|
||||
if summary.ManagedCount > 0 {
|
||||
return fmt.Sprintf("no source agents yet (%d %s)", summary.ManagedCount, targetAgentCountLabel(summary.Mode))
|
||||
counts := joinAgentCounts(summary.ManagedCount, targetAgentCountLabel(summary.Mode), summary.LocalCount)
|
||||
if counts != "" {
|
||||
return fmt.Sprintf("no source agents yet (%s)", counts)
|
||||
}
|
||||
return "no source agents yet"
|
||||
}
|
||||
|
||||
summaryText := fmt.Sprintf("%d/%d %s", summary.ManagedCount, summary.ExpectedCount, targetAgentCountLabel(summary.Mode))
|
||||
if summary.LocalCount > 0 {
|
||||
summaryText += fmt.Sprintf(", %d local", summary.LocalCount)
|
||||
}
|
||||
if summary.Mode == "symlink" {
|
||||
return summaryText + " (directory symlink)"
|
||||
}
|
||||
return summaryText
|
||||
}
|
||||
|
||||
func joinAgentCounts(managed int, managedLabel string, local int) string {
|
||||
var parts []string
|
||||
if managed > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d %s", managed, managedLabel))
|
||||
}
|
||||
if local > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d local", local))
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
|
||||
func targetAgentCountLabel(mode string) string {
|
||||
if mode == "copy" {
|
||||
return "managed"
|
||||
|
||||
@@ -115,11 +115,57 @@ func TestTargetListJSON_IncludesAgentMetadata(t *testing.T) {
|
||||
if target.AgentLinkedCount == nil || *target.AgentLinkedCount != 1 {
|
||||
t.Fatalf("agent linked = %v, want 1", target.AgentLinkedCount)
|
||||
}
|
||||
if target.AgentLocalCount == nil || *target.AgentLocalCount != 0 {
|
||||
t.Fatalf("agent local = %v, want 0", target.AgentLocalCount)
|
||||
}
|
||||
if target.AgentExpectedCount == nil || *target.AgentExpectedCount != 1 {
|
||||
t.Fatalf("agent expected = %v, want 1", target.AgentExpectedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetListJSON_IncludesLocalOnlyAgentCount(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
targetPath := sb.CreateTarget("claude")
|
||||
writeGlobalTargetConfig(t, sb, "claude", targetPath, "")
|
||||
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
t.Fatalf("load config: %v", err)
|
||||
}
|
||||
|
||||
agentTarget := filepath.Join(sb.Home, ".claude", "agents")
|
||||
writeAgentFile(t, agentTarget, "local-only.md")
|
||||
|
||||
output := captureStdout(t, func() {
|
||||
if err := targetListJSON(cfg); err != nil {
|
||||
t.Fatalf("targetListJSON: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
var resp struct {
|
||||
Targets []targetListJSONItem `json:"targets"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(output), &resp); err != nil {
|
||||
t.Fatalf("decode json: %v\n%s", err, output)
|
||||
}
|
||||
if len(resp.Targets) != 1 {
|
||||
t.Fatalf("expected 1 target, got %d", len(resp.Targets))
|
||||
}
|
||||
|
||||
target := resp.Targets[0]
|
||||
if target.AgentLocalCount == nil || *target.AgentLocalCount != 1 {
|
||||
t.Fatalf("agent local = %v, want 1", target.AgentLocalCount)
|
||||
}
|
||||
if target.AgentLinkedCount == nil || *target.AgentLinkedCount != 0 {
|
||||
t.Fatalf("agent linked = %v, want 0", target.AgentLinkedCount)
|
||||
}
|
||||
if target.AgentExpectedCount == nil || *target.AgentExpectedCount != 0 {
|
||||
t.Fatalf("agent expected = %v, want 0", target.AgentExpectedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetList_TextOutputShowsSkillsAndAgentsSections(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
@@ -214,6 +260,28 @@ func TestRenderTargetDetail_AgentSection(t *testing.T) {
|
||||
},
|
||||
want: []string{"Skills:", "/tmp/custom/skills", "Sync:", "copied (2 managed, 0 local)", "Agents:", "/tmp/custom/agents", "2/2 managed", "No agent include/exclude filters"},
|
||||
},
|
||||
{
|
||||
name: "local-only agents are shown when source has none",
|
||||
item: targetTUIItem{
|
||||
name: "claude",
|
||||
displayPath: ".claude/skills",
|
||||
skillSync: "merged (0 shared, 0 local)",
|
||||
target: config.TargetConfig{
|
||||
Skills: &config.ResourceTargetConfig{
|
||||
Path: "/tmp/claude/skills",
|
||||
Mode: "merge",
|
||||
TargetNaming: "flat",
|
||||
},
|
||||
},
|
||||
agentSummary: &targetsummary.AgentSummary{
|
||||
DisplayPath: ".claude/agents",
|
||||
Path: "/tmp/claude/agents",
|
||||
Mode: "merge",
|
||||
LocalCount: 1,
|
||||
},
|
||||
},
|
||||
want: []string{"Agents:", ".claude/agents", "no source agents yet (1 local)", "No agent include/exclude filters"},
|
||||
},
|
||||
{
|
||||
name: "symlink agent target shows filters ignored warning",
|
||||
item: targetTUIItem{
|
||||
@@ -277,6 +345,50 @@ func TestRenderTargetDetail_AgentSection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatTargetAgentSyncSummary_IncludesLocalAgents(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
summary *targetsummary.AgentSummary
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "local only without source agents",
|
||||
summary: &targetsummary.AgentSummary{
|
||||
Mode: "merge",
|
||||
LocalCount: 1,
|
||||
},
|
||||
want: "no source agents yet (1 local)",
|
||||
},
|
||||
{
|
||||
name: "managed and local without source agents",
|
||||
summary: &targetsummary.AgentSummary{
|
||||
Mode: "copy",
|
||||
ManagedCount: 2,
|
||||
LocalCount: 1,
|
||||
},
|
||||
want: "no source agents yet (2 managed, 1 local)",
|
||||
},
|
||||
{
|
||||
name: "expected source agents with local suffix",
|
||||
summary: &targetsummary.AgentSummary{
|
||||
Mode: "merge",
|
||||
ManagedCount: 2,
|
||||
LocalCount: 1,
|
||||
ExpectedCount: 3,
|
||||
},
|
||||
want: "2/3 linked, 1 local",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := formatTargetAgentSyncSummary(tc.summary); got != tc.want {
|
||||
t.Fatalf("formatTargetAgentSyncSummary() = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetScopeOptions_DisablesAgentFiltersInSymlinkMode(t *testing.T) {
|
||||
item := targetTUIItem{
|
||||
name: "claude",
|
||||
|
||||
@@ -32,6 +32,7 @@ type targetItem struct {
|
||||
AgentInclude []string `json:"agentInclude,omitempty"`
|
||||
AgentExclude []string `json:"agentExclude,omitempty"`
|
||||
AgentLinkedCount *int `json:"agentLinkedCount,omitempty"`
|
||||
AgentLocalCount *int `json:"agentLocalCount,omitempty"`
|
||||
AgentExpectedCount *int `json:"agentExpectedCount,omitempty"`
|
||||
}
|
||||
|
||||
@@ -158,6 +159,7 @@ func (s *Server) handleListTargets(w http.ResponseWriter, r *http.Request) {
|
||||
item.AgentInclude = agentSummary.Include
|
||||
item.AgentExclude = agentSummary.Exclude
|
||||
item.AgentLinkedCount = intPtr(agentSummary.ManagedCount)
|
||||
item.AgentLocalCount = intPtr(agentSummary.LocalCount)
|
||||
item.AgentExpectedCount = intPtr(agentSummary.ExpectedCount)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ type targetAgentResponse struct {
|
||||
AgentInclude []string `json:"agentInclude"`
|
||||
AgentExclude []string `json:"agentExclude"`
|
||||
AgentLinkedCount *int `json:"agentLinkedCount"`
|
||||
AgentLocalCount *int `json:"agentLocalCount"`
|
||||
AgentExpectedCount *int `json:"agentExpectedCount"`
|
||||
}
|
||||
|
||||
@@ -114,6 +115,31 @@ func TestHandleListTargets_CustomAgentPathOverridesBuiltin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleListTargets_IncludesLocalAgentCount(t *testing.T) {
|
||||
home := filepath.Join(t.TempDir(), "home")
|
||||
if err := os.MkdirAll(home, 0755); err != nil {
|
||||
t.Fatalf("mkdir home: %v", err)
|
||||
}
|
||||
t.Setenv("HOME", home)
|
||||
|
||||
tgtPath := filepath.Join(t.TempDir(), "claude-skills")
|
||||
s, _ := newTestServerWithTargets(t, map[string]string{"claude": tgtPath})
|
||||
|
||||
agentTarget := filepath.Join(home, ".claude", "agents")
|
||||
addAgentFile(t, agentTarget, "local-only.md")
|
||||
|
||||
target := fetchTargetByName(t, s, "claude")
|
||||
if target.AgentLocalCount == nil || *target.AgentLocalCount != 1 {
|
||||
t.Fatalf("agent local = %v, want 1", target.AgentLocalCount)
|
||||
}
|
||||
if target.AgentLinkedCount == nil || *target.AgentLinkedCount != 0 {
|
||||
t.Fatalf("agent linked = %v, want 0", target.AgentLinkedCount)
|
||||
}
|
||||
if target.AgentExpectedCount == nil || *target.AgentExpectedCount != 0 {
|
||||
t.Fatalf("agent expected = %v, want 0", target.AgentExpectedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleListTargets_OmitsAgentsForUnsupportedTarget(t *testing.T) {
|
||||
tgtPath := filepath.Join(t.TempDir(), "custom-skills")
|
||||
s, _ := newTestServerWithTargets(t, map[string]string{"custom-tool": tgtPath})
|
||||
|
||||
@@ -22,6 +22,7 @@ type AgentSummary struct {
|
||||
Include []string
|
||||
Exclude []string
|
||||
ManagedCount int
|
||||
LocalCount int
|
||||
ExpectedCount int
|
||||
}
|
||||
|
||||
@@ -123,6 +124,7 @@ func (b *Builder) buildSummary(path, displayPath, mode string, include, exclude
|
||||
summary.ExpectedCount = len(expectedAgents)
|
||||
}
|
||||
summary.ManagedCount = countManagedAgents(path, mode, b.sourcePath, summary.ExpectedCount)
|
||||
summary.LocalCount = countLocalAgents(path, b.sourcePath)
|
||||
|
||||
return summary, nil
|
||||
}
|
||||
@@ -167,6 +169,18 @@ func countHealthyAgentLinks(dir string) int {
|
||||
return linked
|
||||
}
|
||||
|
||||
func countLocalAgents(targetPath, sourcePath string) int {
|
||||
if targetPath == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
localAgents, err := ssync.FindLocalAgents(targetPath, sourcePath)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return len(localAgents)
|
||||
}
|
||||
|
||||
func dirExists(path string) bool {
|
||||
info, err := os.Stat(path)
|
||||
return err == nil && info.IsDir()
|
||||
|
||||
@@ -616,6 +616,7 @@ export interface Target {
|
||||
agentInclude?: string[];
|
||||
agentExclude?: string[];
|
||||
agentLinkedCount?: number;
|
||||
agentLocalCount?: number;
|
||||
agentExpectedCount?: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +237,11 @@ export default function BatchUninstallPage() {
|
||||
for (const flatName of selected) {
|
||||
const skill = skillByFlatName.get(flatName);
|
||||
if (!skill) continue;
|
||||
// Agents don't support repo-level uninstall — send individual names
|
||||
if (activeTab === 'agents') {
|
||||
names.add(skill.flatName);
|
||||
continue;
|
||||
}
|
||||
const repo = getRepoName(skill);
|
||||
if (repo && !processedRepos.has(repo)) {
|
||||
processedRepos.add(repo);
|
||||
@@ -246,7 +251,7 @@ export default function BatchUninstallPage() {
|
||||
}
|
||||
}
|
||||
return Array.from(names);
|
||||
}, [selected, skillByFlatName, getRepoName]);
|
||||
}, [selected, skillByFlatName, getRepoName, activeTab]);
|
||||
|
||||
const hasRepoWarning = useMemo(() => {
|
||||
for (const flatName of selected) {
|
||||
|
||||
@@ -31,11 +31,18 @@ import KindBadge from '../components/KindBadge';
|
||||
import SegmentedControl from '../components/SegmentedControl';
|
||||
|
||||
type Phase = 'idle' | 'scanning' | 'scanned' | 'collecting' | 'done';
|
||||
type CollectScope = 'skill' | 'agent' | 'both';
|
||||
|
||||
function parseCollectScope(value: string | null): CollectScope | null {
|
||||
if (value === 'skill' || value === 'agent' || value === 'both') return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function CollectPage() {
|
||||
const queryClient = useQueryClient();
|
||||
const [searchParams] = useSearchParams();
|
||||
const presetTarget = searchParams.get('target') ?? undefined;
|
||||
const presetScope = parseCollectScope(searchParams.get('scope'));
|
||||
|
||||
const [phase, setPhase] = useState<Phase>('idle');
|
||||
const [force, setForce] = useState(false);
|
||||
@@ -45,7 +52,7 @@ export default function CollectPage() {
|
||||
const [result, setResult] = useState<CollectResult | null>(null);
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const { toast } = useToast();
|
||||
const [scope, setScope] = useState<'skill' | 'agent' | 'both'>('skill');
|
||||
const [scope, setScope] = useState<CollectScope>(presetScope ?? 'skill');
|
||||
|
||||
const scopeLabels = {
|
||||
skill: { noun: 'skill', nounPlural: 'skills', scanBtn: 'Scan for Local Skills', entity: 'Skills' },
|
||||
@@ -63,19 +70,26 @@ export default function CollectPage() {
|
||||
setResult(null);
|
||||
}, [scope]);
|
||||
|
||||
useEffect(() => {
|
||||
if (presetScope && presetScope !== scope) {
|
||||
setScope(presetScope);
|
||||
}
|
||||
}, [presetScope, scope]);
|
||||
|
||||
// Auto-scan when target query param is present
|
||||
useEffect(() => {
|
||||
if (presetTarget) {
|
||||
handleScan(presetTarget);
|
||||
handleScan(presetTarget, presetScope ?? scope);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [presetTarget]);
|
||||
}, [presetTarget, presetScope]);
|
||||
|
||||
const handleScan = async (targetFilter?: string) => {
|
||||
const handleScan = async (targetFilter?: string, scopeOverride?: CollectScope) => {
|
||||
const activeScope = scopeOverride ?? scope;
|
||||
setPhase('scanning');
|
||||
setResult(null);
|
||||
try {
|
||||
const res = await api.collectScan(targetFilter, scope === 'both' ? undefined : scope);
|
||||
const res = await api.collectScan(targetFilter, activeScope === 'both' ? undefined : activeScope);
|
||||
setScanTargets(res.targets);
|
||||
setTotalCount(res.totalCount);
|
||||
// Auto-select all
|
||||
@@ -112,6 +126,8 @@ export default function CollectPage() {
|
||||
setPhase('done');
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.skills.all });
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.overview });
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.targets.all });
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.diff() });
|
||||
} catch (e: unknown) {
|
||||
toast((e as Error).message, 'error');
|
||||
setPhase('scanned');
|
||||
|
||||
@@ -37,21 +37,57 @@ const AGENT_MODE_OPTIONS = [
|
||||
{ value: 'copy', label: 'Copy', description: 'Physical file copies instead of symlinks' },
|
||||
];
|
||||
|
||||
function targetAgentSummary(target: TargetType): { text: string; hasDrift: boolean } {
|
||||
export type CollectScope = 'skill' | 'agent' | 'both';
|
||||
|
||||
function pluralize(count: number, singular: string): string {
|
||||
return `${count} ${singular}${count === 1 ? '' : 's'}`;
|
||||
}
|
||||
|
||||
export function getTargetCollectScope(target: TargetType): CollectScope | null {
|
||||
const hasLocalSkills = target.localCount > 0;
|
||||
const hasLocalAgents = (target.agentLocalCount ?? 0) > 0;
|
||||
|
||||
if (hasLocalSkills && hasLocalAgents) return 'both';
|
||||
if (hasLocalAgents) return 'agent';
|
||||
if (hasLocalSkills) return 'skill';
|
||||
return null;
|
||||
}
|
||||
|
||||
export function targetAgentSummary(target: TargetType): { text: string; hasDrift: boolean } {
|
||||
const expected = target.agentExpectedCount ?? 0;
|
||||
const linked = target.agentLinkedCount ?? 0;
|
||||
const local = target.agentLocalCount ?? 0;
|
||||
const label = target.agentMode === 'copy' ? 'managed' : 'linked';
|
||||
const hasDrift = expected > 0 && linked !== expected;
|
||||
|
||||
if (expected === 0) {
|
||||
if (linked > 0) {
|
||||
return { text: `No source agents yet (${linked} ${label})`, hasDrift: false };
|
||||
const counts = [
|
||||
linked > 0 ? pluralize(linked, label) : null,
|
||||
local > 0 ? pluralize(local, 'local') : null,
|
||||
].filter(Boolean).join(', ');
|
||||
if (counts) {
|
||||
return { text: `No source agents yet (${counts})`, hasDrift: false };
|
||||
}
|
||||
return { text: 'No source agents yet', hasDrift: false };
|
||||
}
|
||||
|
||||
const suffix = target.agentMode === 'symlink' ? ' (directory symlink)' : '';
|
||||
return { text: `${linked}/${expected} ${label}${suffix}`, hasDrift };
|
||||
const localSuffix = local > 0 ? `, ${pluralize(local, 'local')}` : '';
|
||||
return { text: `${linked}/${expected} ${label}${suffix}${localSuffix}`, hasDrift };
|
||||
}
|
||||
|
||||
export function targetAgentAvailabilityText(target: TargetType): string {
|
||||
const expected = target.agentExpectedCount ?? 0;
|
||||
const local = target.agentLocalCount ?? 0;
|
||||
const agentFilters = (target.agentInclude?.length ?? 0) + (target.agentExclude?.length ?? 0);
|
||||
|
||||
if (expected === 0) {
|
||||
return local > 0 ? pluralize(local, 'local agent') : 'No agents';
|
||||
}
|
||||
|
||||
if (!agentFilters) return `All ${expected} agents`;
|
||||
const linked = target.agentLinkedCount ?? 0;
|
||||
return `${linked}/${expected} agents`;
|
||||
}
|
||||
|
||||
export default function TargetsPage() {
|
||||
@@ -71,7 +107,7 @@ export default function TargetsPage() {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [customMode, setCustomMode] = useState(false);
|
||||
const [removing, setRemoving] = useState<string | null>(null);
|
||||
const [collecting, setCollecting] = useState<string | null>(null);
|
||||
const [collecting, setCollecting] = useState<{ name: string; scope: CollectScope } | null>(null);
|
||||
const navigate = useNavigate();
|
||||
const { getTargetSummary } = useSyncMatrix();
|
||||
const { toast } = useToast();
|
||||
@@ -434,6 +470,7 @@ export default function TargetsPage() {
|
||||
const hasDrift = isMergeOrCopy && target.linkedCount < expectedCount;
|
||||
const agentSummary = targetAgentSummary(target);
|
||||
const agentFilters = (target.agentInclude?.length ?? 0) + (target.agentExclude?.length ?? 0);
|
||||
const collectScope = getTargetCollectScope(target);
|
||||
const visibleAgentInclude = (target.agentInclude ?? []).slice(0, 3);
|
||||
const visibleAgentExclude = (target.agentExclude ?? []).slice(0, Math.max(0, 3 - visibleAgentInclude.length));
|
||||
const overflowAgentFilters = agentFilters - (visibleAgentInclude.length + visibleAgentExclude.length);
|
||||
@@ -450,13 +487,13 @@ export default function TargetsPage() {
|
||||
<span className="font-bold text-pencil">{target.name}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
{(target.mode === 'merge' || target.mode === 'copy') && target.localCount > 0 && (
|
||||
{collectScope && (
|
||||
<IconButton
|
||||
icon={<ArrowDownToLine size={16} strokeWidth={2.5} />}
|
||||
label="Collect local skills"
|
||||
label={`Collect local ${collectScope === 'both' ? 'resources' : collectScope === 'agent' ? 'agents' : 'skills'}`}
|
||||
size="md"
|
||||
variant="outline"
|
||||
onClick={() => setCollecting(target.name)}
|
||||
onClick={() => setCollecting({ name: target.name, scope: collectScope })}
|
||||
className="hover:text-blue hover:border-blue"
|
||||
/>
|
||||
)}
|
||||
@@ -603,15 +640,7 @@ export default function TargetsPage() {
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 flex items-center gap-2 flex-wrap">
|
||||
<span className="text-sm text-pencil-light">
|
||||
{(() => {
|
||||
const expected = target.agentExpectedCount ?? 0;
|
||||
if (expected === 0) return 'No agents';
|
||||
if (!agentFilters) return `All ${expected} agents`;
|
||||
const linked = target.agentLinkedCount ?? 0;
|
||||
return `${linked}/${expected} agents`;
|
||||
})()}
|
||||
</span>
|
||||
<span className="text-sm text-pencil-light">{targetAgentAvailabilityText(target)}</span>
|
||||
{visibleAgentInclude.map((pattern, idx) => (
|
||||
<span
|
||||
key={`agent-inc-${idx}`}
|
||||
@@ -684,11 +713,19 @@ export default function TargetsPage() {
|
||||
{/* Confirm collect dialog */}
|
||||
<ConfirmDialog
|
||||
open={!!collecting}
|
||||
title="Collect Local Skills"
|
||||
message={`Scan "${collecting}" for local skills to collect back to source?`}
|
||||
title={`Collect Local ${collecting?.scope === 'both' ? 'Resources' : collecting?.scope === 'agent' ? 'Agents' : 'Skills'}`}
|
||||
message={collecting
|
||||
? `Scan "${collecting.name}" for local ${collecting.scope === 'both' ? 'resources' : collecting.scope === 'agent' ? 'agents' : 'skills'} to collect back to source?`
|
||||
: ''}
|
||||
confirmText="Scan"
|
||||
onConfirm={() => {
|
||||
if (collecting) navigate(`/collect?target=${encodeURIComponent(collecting)}`);
|
||||
if (collecting) {
|
||||
const params = new URLSearchParams({
|
||||
target: collecting.name,
|
||||
scope: collecting.scope,
|
||||
});
|
||||
navigate(`/collect?${params.toString()}`);
|
||||
}
|
||||
setCollecting(null);
|
||||
}}
|
||||
onCancel={() => setCollecting(null)}
|
||||
|
||||
Reference in New Issue
Block a user