@blackbelt-technology/pi-dashboard-skill-atlas-plugin 0.0.0-stage → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/package.json +104 -4
- package/src/client/AtlasSummary.tsx +108 -0
- package/src/client/RelationGlyph.tsx +13 -0
- package/src/client/SkillAtlasPage.tsx +278 -0
- package/src/client/SkillCardsView.tsx +76 -0
- package/src/client/SkillDetailPanel.tsx +125 -0
- package/src/client/SkillGraphView.tsx +248 -0
- package/src/client/SkillLinksView.tsx +48 -0
- package/src/client/atlas-api.ts +60 -0
- package/src/client/claims.tsx +92 -0
- package/src/client/graph-layout.ts +205 -0
- package/src/client/index.tsx +7 -0
- package/src/client/relation-style.ts +26 -0
- package/src/client/useSkillGraph.ts +72 -0
- package/src/i18n.ts +132 -0
- package/src/server/atlas-service.ts +249 -0
- package/src/server/index.ts +33 -0
- package/src/server/inputs.ts +44 -0
- package/src/server/routes.ts +42 -0
- package/src/shared/build-skill-graph.ts +182 -0
- package/src/shared/index.ts +6 -0
- package/src/shared/types.ts +69 -0
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @blackbelt-technology/pi-dashboard-skill-atlas-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Dashboard plugin: every skill pi loads in a folder (project atlas) or globally (global atlas), shown as cards, a force graph and a links table with typed relations:
|
|
4
|
+
|
|
5
|
+
| Relation | Rule |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `references` | Skill A's SKILL.md names skill B (hyphenated id, or `/skill:x`, `skill: x`, `x skill`). Directed. |
|
|
8
|
+
| `bundle` | Shipped by the same package (2–14 skills). |
|
|
9
|
+
| `shares-tool` | Both mention the same backticked `snake_case` tool token, used by only 2–6 skills. |
|
|
10
|
+
|
|
11
|
+
The graph is a pure function of the resolved skill state (`buildSkillGraph`, exported from `./shared`). The server rebuilds it only when a fingerprint of the skill files moves, and pushes `skill_atlas_changed` to open atlases after skills change or a session reloads.
|
|
12
|
+
|
|
13
|
+
## Surfaces
|
|
14
|
+
|
|
15
|
+
- Folder actions menu → **Skill Atlas** (project atlas, `/folder/:encodedCwd/atlas`).
|
|
16
|
+
- Settings ▸ Resources ▸ **Skill Atlas** and `/atlas` (global atlas).
|
|
17
|
+
- A summary section above the grid on the Folder and Global **Skills** pages.
|
|
18
|
+
|
|
19
|
+
## Server
|
|
20
|
+
|
|
21
|
+
`GET /api/plugins/skill-atlas/graph?scope=project|global&cwd=<abs>` — needs the host seams `getPiResources` and `onPiResourcesInvalidated` (dashboard ≥ 0.9). SKILL.md bodies never leave the server.
|
package/package.json
CHANGED
|
@@ -1,6 +1,106 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-skill-atlas-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Dashboard plugin showing every skill pi loads in a folder or globally as a typed relation graph (references, same package, shared tool), rebuilt automatically when skills change.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/BlackBeltTechnology/pi-agent-dashboard",
|
|
13
|
+
"directory": "packages/skill-atlas-plugin"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./src/client/index.tsx",
|
|
18
|
+
"default": "./src/client/index.tsx"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./src/client/index.tsx",
|
|
22
|
+
"default": "./src/client/index.tsx"
|
|
23
|
+
},
|
|
24
|
+
"./server": {
|
|
25
|
+
"types": "./src/server/index.ts",
|
|
26
|
+
"default": "./src/server/index.ts"
|
|
27
|
+
},
|
|
28
|
+
"./shared": {
|
|
29
|
+
"types": "./src/shared/index.ts",
|
|
30
|
+
"default": "./src/shared/index.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"src/",
|
|
35
|
+
"!**/AGENTS.md",
|
|
36
|
+
"!**/*.AGENTS.md",
|
|
37
|
+
"!**/__tests__",
|
|
38
|
+
"!**/*.test.ts",
|
|
39
|
+
"!**/*.test.tsx"
|
|
40
|
+
],
|
|
41
|
+
"pi-dashboard-plugin": {
|
|
42
|
+
"id": "skill-atlas",
|
|
43
|
+
"displayName": "Skill Atlas",
|
|
44
|
+
"i18nCatalog": "catalog",
|
|
45
|
+
"priority": 100,
|
|
46
|
+
"client": "./src/client/index.tsx",
|
|
47
|
+
"server": "./src/server/index.ts",
|
|
48
|
+
"claims": [
|
|
49
|
+
{
|
|
50
|
+
"slot": "resource-page-section",
|
|
51
|
+
"component": "SkillAtlasSection",
|
|
52
|
+
"resourceType": "skill"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"slot": "sidebar-folder-section",
|
|
56
|
+
"component": "FolderAtlasMenu"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"slot": "shell-overlay-route",
|
|
60
|
+
"component": "ProjectAtlasClaim",
|
|
61
|
+
"path": "/folder/:encodedCwd/atlas/*?",
|
|
62
|
+
"depth": 2,
|
|
63
|
+
"parentPath": "/folder/:encodedCwd",
|
|
64
|
+
"presentation": "content"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"slot": "shell-overlay-route",
|
|
68
|
+
"component": "GlobalAtlasClaim",
|
|
69
|
+
"path": "/atlas/*?",
|
|
70
|
+
"depth": 2,
|
|
71
|
+
"presentation": "content",
|
|
72
|
+
"parentPath": "/settings/skills"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"slot": "settings-section",
|
|
76
|
+
"component": "SkillAtlasSettings",
|
|
77
|
+
"nav": {
|
|
78
|
+
"group": "resources",
|
|
79
|
+
"label": "Skill Atlas",
|
|
80
|
+
"description": "Every skill pi loads, as a relation graph."
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"peerDependencies": {
|
|
86
|
+
"fastify": "^5.0.0",
|
|
87
|
+
"react": ">=18.0.0",
|
|
88
|
+
"react-dom": ">=18.0.0",
|
|
89
|
+
"wouter": ">=3.0.0"
|
|
90
|
+
},
|
|
91
|
+
"dependencies": {
|
|
92
|
+
"@blackbelt-technology/dashboard-plugin-runtime": "^0.9.0",
|
|
93
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.9.0",
|
|
94
|
+
"@fastify/rate-limit": "^11.2.0",
|
|
95
|
+
"@mdi/js": "^7.4.47",
|
|
96
|
+
"@mdi/react": "^1.6.1"
|
|
97
|
+
},
|
|
98
|
+
"devDependencies": {
|
|
99
|
+
"@types/react": "^19.0.0",
|
|
100
|
+
"@types/react-dom": "^19.0.0",
|
|
101
|
+
"fastify": "^5.0.0",
|
|
102
|
+
"react": "^19.0.0",
|
|
103
|
+
"react-dom": "^19.0.0",
|
|
104
|
+
"wouter": "^3.9.0"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact atlas summary: counts, per-relation counts with glyph + word, the
|
|
3
|
+
* five most-connected skills (each opens the atlas focused on it), and an
|
|
4
|
+
* "Open atlas" action. Empty scope renders nothing; degraded → warning line;
|
|
5
|
+
* error → alert + Retry. Used by the Skills-page section and the promoted
|
|
6
|
+
* settings entry. See change: add-skill-atlas-screen (ui-plan S1).
|
|
7
|
+
*/
|
|
8
|
+
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
9
|
+
import type React from "react";
|
|
10
|
+
import { useLocation } from "wouter";
|
|
11
|
+
import type { SkillAtlasScope } from "../shared/types.js";
|
|
12
|
+
import { atlasUrl } from "./atlas-api.js";
|
|
13
|
+
import { topByDegree } from "./graph-layout.js";
|
|
14
|
+
import { RelationGlyph } from "./RelationGlyph.js";
|
|
15
|
+
import { RELATION_STYLE, RELATION_TYPES } from "./relation-style.js";
|
|
16
|
+
import { useSkillGraph } from "./useSkillGraph.js";
|
|
17
|
+
|
|
18
|
+
export function AtlasSummary({ scope, cwd }: { scope: SkillAtlasScope; cwd?: string }): React.ReactElement | null {
|
|
19
|
+
const t = useT();
|
|
20
|
+
const [, navigate] = useLocation();
|
|
21
|
+
const { graph, loading, error, refetch } = useSkillGraph(scope, cwd);
|
|
22
|
+
const box = "rounded-lg bg-[var(--bg-tertiary)] border border-[var(--border-subtle)] p-3 mb-3";
|
|
23
|
+
const heading = (
|
|
24
|
+
<h2 className="text-[12px] font-semibold text-[var(--text-secondary)] m-0">{t("title", undefined, "Skill Atlas")}</h2>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (loading && !graph) {
|
|
28
|
+
return (
|
|
29
|
+
<section className={box} aria-busy="true" aria-label={t("title", undefined, "Skill Atlas")} data-testid="skill-atlas-summary-loading">
|
|
30
|
+
{heading}
|
|
31
|
+
<div className="mt-2 h-3 w-3/5 rounded bg-[var(--bg-hover)] motion-safe:animate-pulse" />
|
|
32
|
+
</section>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (error && !graph) {
|
|
36
|
+
return (
|
|
37
|
+
<section className={`${box} flex flex-wrap items-center gap-3`} data-testid="skill-atlas-summary-error">
|
|
38
|
+
<div className="flex-1 min-w-0 grid gap-1.5">
|
|
39
|
+
{heading}
|
|
40
|
+
<div role="alert" className="rounded-md border px-3 py-2 text-[12px] bg-[var(--severity-error-bg)] border-[var(--severity-error-border)] text-[var(--severity-error-fg)]">
|
|
41
|
+
{t("loadError", { error }, `Could not build the skill graph: ${error}`)}
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
<button type="button" onClick={refetch} className="focus-ring rounded-md border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-3 min-h-[44px] sm:min-h-[36px] text-[12px] font-semibold text-[var(--text-primary)]">
|
|
45
|
+
{t("retry", undefined, "Retry")}
|
|
46
|
+
</button>
|
|
47
|
+
</section>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (!graph || graph.skills.length === 0) return null;
|
|
51
|
+
|
|
52
|
+
const counts = Object.fromEntries(RELATION_TYPES.map((k) => [k, graph.links.filter((l) => l.type === k).length]));
|
|
53
|
+
const local = graph.skills.filter((s) => s.origin === "project").length;
|
|
54
|
+
const hubs = topByDegree(graph.skills, 5);
|
|
55
|
+
return (
|
|
56
|
+
<section className={`${box} grid gap-3 md:grid-cols-[1fr_auto] md:items-center`} aria-labelledby="skill-atlas-summary-h" data-testid="skill-atlas-summary">
|
|
57
|
+
<div className="grid gap-2 min-w-0">
|
|
58
|
+
<div className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
|
59
|
+
<h2 id="skill-atlas-summary-h" className="text-[12px] font-semibold text-[var(--text-secondary)] m-0">
|
|
60
|
+
{t("title", undefined, "Skill Atlas")}
|
|
61
|
+
</h2>
|
|
62
|
+
<span className="text-[12px] text-[var(--text-secondary)]">
|
|
63
|
+
{scope === "project"
|
|
64
|
+
? t("countsProject", { skills: graph.skills.length, links: graph.links.length, local }, `${graph.skills.length} skills · ${graph.links.length} links · ${local} from this folder`)
|
|
65
|
+
: t("counts", { skills: graph.skills.length, links: graph.links.length }, `${graph.skills.length} skills · ${graph.links.length} links`)}
|
|
66
|
+
</span>
|
|
67
|
+
</div>
|
|
68
|
+
{graph.degraded && (
|
|
69
|
+
<div className="rounded-md border px-3 py-2 text-[12px] bg-[var(--severity-warning-bg)] border-[var(--severity-warning-border)] text-[var(--severity-warning-fg)]" data-testid="skill-atlas-degraded">
|
|
70
|
+
{t("degraded", undefined, "pi's resolver was unavailable, so the list comes from a directory walk. It may differ from what pi loads.")}
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
<ul className="flex flex-wrap gap-x-3 gap-y-1 list-none m-0 p-0" aria-label={t("relations", undefined, "Relations")}>
|
|
74
|
+
{RELATION_TYPES.map((k) => (
|
|
75
|
+
<li key={k} className="inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]">
|
|
76
|
+
<RelationGlyph type={k} />
|
|
77
|
+
{t(RELATION_STYLE[k].labelKey, undefined, RELATION_STYLE[k].label)} <span>{counts[k]}</span>
|
|
78
|
+
</li>
|
|
79
|
+
))}
|
|
80
|
+
</ul>
|
|
81
|
+
{hubs.length > 0 && (
|
|
82
|
+
<div className="flex flex-wrap items-center gap-1.5">
|
|
83
|
+
<span className="text-[12px] text-[var(--text-secondary)]">{t("mostConnected", undefined, "Most connected:")}</span>
|
|
84
|
+
{hubs.map((h) => (
|
|
85
|
+
<button
|
|
86
|
+
key={h.id}
|
|
87
|
+
type="button"
|
|
88
|
+
data-testid={`skill-atlas-hub-${h.id}`}
|
|
89
|
+
onClick={() => navigate(atlasUrl(scope, cwd, h.id, 1))}
|
|
90
|
+
className="focus-ring inline-flex items-center gap-1 rounded-full border border-[var(--border-secondary)] bg-[var(--bg-secondary)] px-2.5 min-h-[44px] sm:min-h-[32px] text-[12px] font-semibold text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"
|
|
91
|
+
>
|
|
92
|
+
{h.id} <span className="font-normal text-[var(--text-secondary)]">{h.degree}</span>
|
|
93
|
+
</button>
|
|
94
|
+
))}
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
data-testid="skill-atlas-open"
|
|
101
|
+
onClick={() => navigate(atlasUrl(scope, cwd))}
|
|
102
|
+
className="focus-ring justify-self-start rounded-md border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-3 min-h-[44px] sm:min-h-[36px] text-[12px] font-semibold text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"
|
|
103
|
+
>
|
|
104
|
+
{t("openAtlas", undefined, "Open atlas →")}
|
|
105
|
+
</button>
|
|
106
|
+
</section>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Inline SVG line sample for a relation type (colour + dash). See change: add-skill-atlas-screen. */
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import type { SkillLinkType } from "../shared/types.js";
|
|
4
|
+
import { RELATION_STYLE } from "./relation-style.js";
|
|
5
|
+
|
|
6
|
+
export function RelationGlyph({ type }: { type: SkillLinkType }): React.ReactElement {
|
|
7
|
+
const s = RELATION_STYLE[type];
|
|
8
|
+
return (
|
|
9
|
+
<svg width="22" height="6" aria-hidden="true" className="shrink-0">
|
|
10
|
+
<line x1="1" y1="3" x2="21" y2="3" stroke={s.color} strokeWidth="2.5" strokeDasharray={s.dash} strokeLinecap="round" />
|
|
11
|
+
</svg>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full atlas page (project or global): header with scope + freshness status,
|
|
3
|
+
* APG tabs (Cards / Graph / Links), search, relation + origin toggles (a
|
|
4
|
+
* "Filters · N on" disclosure below `sm`), the active view and the detail
|
|
5
|
+
* panel. Graph dims non-matches; Cards/Links hide them and show
|
|
6
|
+
* "Showing N of M · Clear". Above GRAPH_NODE_CAP the Graph tab is disabled.
|
|
7
|
+
* Initial selection may come from `?sel=<id>&hops=<n>`.
|
|
8
|
+
* See change: add-skill-atlas-screen (ui-plan S2, design D9).
|
|
9
|
+
*/
|
|
10
|
+
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
11
|
+
import { mdiArrowLeft } from "@mdi/js";
|
|
12
|
+
import { Icon } from "@mdi/react";
|
|
13
|
+
import type React from "react";
|
|
14
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
15
|
+
import { useSearch } from "wouter";
|
|
16
|
+
import { GRAPH_NODE_CAP, type SkillAtlasScope, type SkillLinkType, type SkillNode, type SkillOrigin } from "../shared/types.js";
|
|
17
|
+
import { hopSet } from "./graph-layout.js";
|
|
18
|
+
import { ORIGIN_STYLE, ORIGIN_TYPES, RELATION_STYLE, RELATION_TYPES } from "./relation-style.js";
|
|
19
|
+
import { RelationGlyph } from "./RelationGlyph.js";
|
|
20
|
+
import { SkillCardsView } from "./SkillCardsView.js";
|
|
21
|
+
import { SkillDetailPanel } from "./SkillDetailPanel.js";
|
|
22
|
+
import { SkillGraphView } from "./SkillGraphView.js";
|
|
23
|
+
import { SkillLinksView } from "./SkillLinksView.js";
|
|
24
|
+
import { useSkillGraph } from "./useSkillGraph.js";
|
|
25
|
+
|
|
26
|
+
type View = "cards" | "graph" | "links";
|
|
27
|
+
const VIEWS: readonly View[] = ["cards", "graph", "links"];
|
|
28
|
+
const VIEW_LABEL: Record<View, readonly [string, string]> = { cards: ["viewCards", "Cards"], graph: ["viewGraph", "Graph"], links: ["viewLinks", "Links"] };
|
|
29
|
+
/** Static severity triples (Tailwind must see literal class names). */
|
|
30
|
+
const CALLOUT = {
|
|
31
|
+
warning: "bg-[var(--severity-warning-bg)] border-[var(--severity-warning-border)] text-[var(--severity-warning-fg)]",
|
|
32
|
+
info: "bg-[var(--severity-info-bg)] border-[var(--severity-info-border)] text-[var(--severity-info-fg)]",
|
|
33
|
+
error: "bg-[var(--severity-error-bg)] border-[var(--severity-error-border)] text-[var(--severity-error-fg)]",
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
export interface SkillAtlasPageProps {
|
|
37
|
+
scope: SkillAtlasScope;
|
|
38
|
+
cwd?: string;
|
|
39
|
+
onBack: () => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default function SkillAtlasPage({ scope, cwd, onBack }: SkillAtlasPageProps): React.ReactElement {
|
|
43
|
+
const t = useT();
|
|
44
|
+
const search = useSearch();
|
|
45
|
+
const initial = useMemo(() => new URLSearchParams(search), [search]);
|
|
46
|
+
const { graph, loading, updating, error, refetch } = useSkillGraph(scope, cwd);
|
|
47
|
+
const [view, setView] = useState<View>("graph");
|
|
48
|
+
const [query, setQuery] = useState("");
|
|
49
|
+
const [rel, setRel] = useState<Record<SkillLinkType, boolean>>({ references: true, bundle: true, "shares-tool": true });
|
|
50
|
+
const [org, setOrg] = useState<Record<SkillOrigin, boolean>>({ project: true, global: true, package: true });
|
|
51
|
+
const [selected, setSelected] = useState<string | null>(initial.get("sel"));
|
|
52
|
+
const [hops, setHops] = useState<number>(Number(initial.get("hops") ?? 0) || 0);
|
|
53
|
+
const [filtersOpen, setFiltersOpen] = useState(false);
|
|
54
|
+
const tabRefs = useRef<Record<View, HTMLButtonElement | null>>({ cards: null, graph: null, links: null });
|
|
55
|
+
|
|
56
|
+
const tooMany = (graph?.skills.length ?? 0) > GRAPH_NODE_CAP;
|
|
57
|
+
const activeView: View = tooMany && view === "graph" ? "cards" : view;
|
|
58
|
+
|
|
59
|
+
const visibleSkills = useMemo(() => (graph?.skills ?? []).filter((s) => org[s.origin]), [graph, org]);
|
|
60
|
+
const visibleIds = useMemo(() => new Set(visibleSkills.map((s) => s.id)), [visibleSkills]);
|
|
61
|
+
const visibleLinks = useMemo(
|
|
62
|
+
() => (graph?.links ?? []).filter((l) => rel[l.type] && visibleIds.has(l.source) && visibleIds.has(l.target)),
|
|
63
|
+
[graph, rel, visibleIds],
|
|
64
|
+
);
|
|
65
|
+
const q = query.trim().toLowerCase();
|
|
66
|
+
const matches = (s: SkillNode) => !q || s.id.toLowerCase().includes(q) || s.description.toLowerCase().includes(q);
|
|
67
|
+
const focus = selected && hops ? hopSet(visibleLinks, selected, hops) : null;
|
|
68
|
+
const keep = (s: SkillNode) => matches(s) && (!focus || focus.has(s.id));
|
|
69
|
+
const listedSkills = visibleSkills.filter(keep);
|
|
70
|
+
const listedIds = new Set(listedSkills.map((s) => s.id));
|
|
71
|
+
const listedLinks = visibleLinks.filter(
|
|
72
|
+
(l) =>
|
|
73
|
+
(matches(graph?.skills.find((s) => s.id === l.source) as SkillNode) || matches(graph?.skills.find((s) => s.id === l.target) as SkillNode)) &&
|
|
74
|
+
(!focus || (focus.has(l.source) && focus.has(l.target))),
|
|
75
|
+
);
|
|
76
|
+
const narrowed = activeView !== "graph" && (q || focus);
|
|
77
|
+
const selectedSkill = graph?.skills.find((s) => s.id === selected) ?? null;
|
|
78
|
+
|
|
79
|
+
// A skill removed by a live update clears the selection.
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (graph && selected && !graph.skills.some((s) => s.id === selected)) {
|
|
82
|
+
setSelected(null);
|
|
83
|
+
setHops(0);
|
|
84
|
+
}
|
|
85
|
+
}, [graph, selected]);
|
|
86
|
+
|
|
87
|
+
const select = (id: string | null) => {
|
|
88
|
+
setSelected(id);
|
|
89
|
+
if (!id) setHops(0);
|
|
90
|
+
};
|
|
91
|
+
const enabledViews = VIEWS.filter((v) => !(v === "graph" && tooMany));
|
|
92
|
+
const onTabKey = (e: React.KeyboardEvent, v: View) => {
|
|
93
|
+
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
|
|
94
|
+
const i = enabledViews.indexOf(v);
|
|
95
|
+
const next = enabledViews[(i + (e.key === "ArrowRight" ? 1 : enabledViews.length - 1)) % enabledViews.length];
|
|
96
|
+
setView(next);
|
|
97
|
+
tabRefs.current[next]?.focus();
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
};
|
|
100
|
+
const filtersOn = Object.values(rel).filter(Boolean).length + Object.values(org).filter(Boolean).length;
|
|
101
|
+
const chip =
|
|
102
|
+
"focus-ring inline-flex cursor-pointer select-none items-center gap-1.5 rounded-md border px-2.5 min-h-[44px] sm:min-h-[32px] text-[12px] font-semibold has-[:checked]:bg-[var(--tint-blue-bg)] has-[:checked]:border-[var(--tint-blue-border)] has-[:checked]:text-[var(--tint-blue-fg)] border-[var(--border-secondary)] bg-[var(--bg-tertiary)] text-[var(--text-primary)]";
|
|
103
|
+
const callout = (sev: keyof typeof CALLOUT) => `rounded-md border px-3 py-2 text-[12px] ${CALLOUT[sev]}`;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="flex h-full min-h-0 flex-col bg-[var(--bg-primary)] text-[var(--text-primary)]" data-testid="skill-atlas-page">
|
|
107
|
+
<header className="flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-[var(--border-primary)] px-4 py-3">
|
|
108
|
+
<button type="button" onClick={onBack} className="focus-ring inline-flex min-h-[32px] items-center gap-1 text-[12px] text-[var(--link)] hover:text-[var(--link-hover)]" data-testid="skill-atlas-back">
|
|
109
|
+
<Icon path={mdiArrowLeft} size={0.6} />
|
|
110
|
+
{t("back", undefined, "Back")}
|
|
111
|
+
</button>
|
|
112
|
+
<h1 className="m-0 text-lg font-semibold">{t("title", undefined, "Skill Atlas")}</h1>
|
|
113
|
+
<span
|
|
114
|
+
className={`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-semibold ${scope === "project" ? ORIGIN_STYLE.project.pill : ORIGIN_STYLE.global.pill}`}
|
|
115
|
+
data-testid="skill-atlas-scope"
|
|
116
|
+
>
|
|
117
|
+
{scope === "project"
|
|
118
|
+
? `${ORIGIN_STYLE.project.glyph} ${t("scopeProject", { folder: cwd?.split(/[\\/]/).filter(Boolean).pop() ?? "" }, `Project · ${cwd?.split(/[\\/]/).filter(Boolean).pop() ?? ""}`)}`
|
|
119
|
+
: `${ORIGIN_STYLE.global.glyph} ${t("scopeGlobal", undefined, "Global")}`}
|
|
120
|
+
</span>
|
|
121
|
+
{graph && (
|
|
122
|
+
<span className="text-[11px] text-[var(--text-secondary)]">
|
|
123
|
+
{t("counts", { skills: graph.skills.length, links: graph.links.length }, `${graph.skills.length} skills · ${graph.links.length} links`)}
|
|
124
|
+
</span>
|
|
125
|
+
)}
|
|
126
|
+
<span role="status" className="ml-auto inline-flex items-center gap-1.5 text-[12px] text-[var(--text-secondary)]" data-testid="skill-atlas-status">
|
|
127
|
+
<span aria-hidden="true" className="h-2 w-2 rounded-full" style={{ background: updating || loading ? "var(--status-working)" : "var(--status-idle)" }} />
|
|
128
|
+
{updating || loading ? t("statusUpdating", undefined, "Updating…") : t("statusFresh", undefined, "Up to date")}
|
|
129
|
+
</span>
|
|
130
|
+
</header>
|
|
131
|
+
|
|
132
|
+
{(graph?.degraded || tooMany || (error && graph)) && (
|
|
133
|
+
<div className="grid gap-2 px-4 pt-2">
|
|
134
|
+
{graph?.degraded && <div className={callout("warning")}>{t("degraded", undefined, "pi's resolver was unavailable, so the list comes from a directory walk. It may differ from what pi loads.")}</div>}
|
|
135
|
+
{tooMany && (
|
|
136
|
+
<div className={callout("info")} data-testid="skill-atlas-too-many">
|
|
137
|
+
{t("tooMany", { count: graph?.skills.length ?? 0, cap: GRAPH_NODE_CAP }, `${graph?.skills.length} skills is more than the graph can show legibly (limit ${GRAPH_NODE_CAP}). Use Cards or Links, or narrow with the filters.`)}
|
|
138
|
+
</div>
|
|
139
|
+
)}
|
|
140
|
+
{error && graph && <div role="alert" className={callout("error")}>{t("loadError", { error }, `Could not build the skill graph: ${error}`)}</div>}
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
143
|
+
|
|
144
|
+
<div className="flex flex-wrap items-center gap-2 border-b border-[var(--border-primary)] px-4 py-2">
|
|
145
|
+
<div role="tablist" aria-label={t("viewTabs", undefined, "Atlas view")} className="inline-flex overflow-hidden rounded-md border border-[var(--border-secondary)]">
|
|
146
|
+
{VIEWS.map((v) => {
|
|
147
|
+
const disabled = v === "graph" && tooMany;
|
|
148
|
+
return (
|
|
149
|
+
<button
|
|
150
|
+
key={v}
|
|
151
|
+
ref={(el) => {
|
|
152
|
+
tabRefs.current[v] = el;
|
|
153
|
+
}}
|
|
154
|
+
type="button"
|
|
155
|
+
role="tab"
|
|
156
|
+
id={`skill-atlas-tab-${v}`}
|
|
157
|
+
aria-controls="skill-atlas-panel"
|
|
158
|
+
aria-selected={activeView === v}
|
|
159
|
+
aria-disabled={disabled || undefined}
|
|
160
|
+
tabIndex={activeView === v ? 0 : -1}
|
|
161
|
+
onClick={() => !disabled && setView(v)}
|
|
162
|
+
onKeyDown={(e) => onTabKey(e, v)}
|
|
163
|
+
className={`focus-ring px-3 min-h-[44px] sm:min-h-[32px] text-[12px] font-semibold ${
|
|
164
|
+
activeView === v ? "bg-[var(--tint-blue-bg)] text-[var(--tint-blue-fg)]" : disabled ? "cursor-not-allowed bg-[var(--bg-tertiary)] text-[var(--text-muted)]" : "bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"
|
|
165
|
+
}`}
|
|
166
|
+
>
|
|
167
|
+
{t(VIEW_LABEL[v][0], undefined, VIEW_LABEL[v][1])}
|
|
168
|
+
</button>
|
|
169
|
+
);
|
|
170
|
+
})}
|
|
171
|
+
</div>
|
|
172
|
+
<label className="sr-only" htmlFor="skill-atlas-search">{t("searchLabel", undefined, "Search skills")}</label>
|
|
173
|
+
<input
|
|
174
|
+
id="skill-atlas-search"
|
|
175
|
+
type="search"
|
|
176
|
+
value={query}
|
|
177
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
178
|
+
placeholder={t("searchPlaceholder", undefined, "Search skills…")}
|
|
179
|
+
className="focus-ring min-h-[44px] sm:min-h-[36px] w-full max-w-xs flex-1 basis-56 rounded border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-3 py-1.5 text-sm"
|
|
180
|
+
/>
|
|
181
|
+
<button
|
|
182
|
+
type="button"
|
|
183
|
+
aria-expanded={filtersOpen}
|
|
184
|
+
aria-controls="skill-atlas-filters"
|
|
185
|
+
onClick={() => setFiltersOpen((o) => !o)}
|
|
186
|
+
className="focus-ring rounded-md border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-3 min-h-[44px] text-[12px] font-semibold sm:hidden"
|
|
187
|
+
data-testid="skill-atlas-filters-toggle"
|
|
188
|
+
>
|
|
189
|
+
{t("filtersOn", { count: filtersOn }, `Filters · ${filtersOn} on`)}
|
|
190
|
+
</button>
|
|
191
|
+
<div id="skill-atlas-filters" className={`${filtersOpen ? "flex" : "hidden"} w-full flex-col gap-2 sm:flex sm:w-auto sm:flex-row sm:flex-wrap sm:items-center`}>
|
|
192
|
+
<div role="group" aria-label={t("relations", undefined, "Relations")} className="flex flex-wrap items-center gap-1.5">
|
|
193
|
+
<span className="text-[12px] font-semibold text-[var(--text-secondary)]">{t("relations", undefined, "Relations")}</span>
|
|
194
|
+
{RELATION_TYPES.map((k) => (
|
|
195
|
+
<label key={k} className={chip}>
|
|
196
|
+
<input type="checkbox" className="m-0 accent-[var(--accent-primary)]" checked={rel[k]} onChange={(e) => setRel((r) => ({ ...r, [k]: e.target.checked }))} />
|
|
197
|
+
<RelationGlyph type={k} />
|
|
198
|
+
{t(RELATION_STYLE[k].labelKey, undefined, RELATION_STYLE[k].label)}
|
|
199
|
+
<span className="font-normal">{graph?.links.filter((l) => l.type === k).length ?? 0}</span>
|
|
200
|
+
</label>
|
|
201
|
+
))}
|
|
202
|
+
</div>
|
|
203
|
+
<div role="group" aria-label={t("origin", undefined, "Origin")} className="flex flex-wrap items-center gap-1.5">
|
|
204
|
+
<span className="text-[12px] font-semibold text-[var(--text-secondary)]">{t("origin", undefined, "Origin")}</span>
|
|
205
|
+
{ORIGIN_TYPES.filter((o) => scope === "project" || o !== "project").map((o) => (
|
|
206
|
+
<label key={o} className={chip}>
|
|
207
|
+
<input type="checkbox" className="m-0 accent-[var(--accent-primary)]" checked={org[o]} onChange={(e) => setOrg((r) => ({ ...r, [o]: e.target.checked }))} />
|
|
208
|
+
<span aria-hidden="true">{ORIGIN_STYLE[o].glyph}</span>
|
|
209
|
+
{t(ORIGIN_STYLE[o].labelKey, undefined, ORIGIN_STYLE[o].label)}
|
|
210
|
+
<span className="font-normal">{graph?.skills.filter((s) => s.origin === o).length ?? 0}</span>
|
|
211
|
+
</label>
|
|
212
|
+
))}
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
{narrowed && (
|
|
218
|
+
<div role="status" className="flex items-center gap-2 border-b border-[var(--border-subtle)] px-4 py-2 text-[12px] text-[var(--text-secondary)]" data-testid="skill-atlas-showing">
|
|
219
|
+
{t("showing", { shown: listedSkills.length, total: visibleSkills.length }, `Showing ${listedSkills.length} of ${visibleSkills.length} skills`)}
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
className="focus-ring min-h-[24px] font-semibold text-[var(--link)] hover:underline"
|
|
223
|
+
onClick={() => {
|
|
224
|
+
setQuery("");
|
|
225
|
+
setHops(0);
|
|
226
|
+
}}
|
|
227
|
+
>
|
|
228
|
+
{t("clear", undefined, "Clear")}
|
|
229
|
+
</button>
|
|
230
|
+
</div>
|
|
231
|
+
)}
|
|
232
|
+
|
|
233
|
+
<div className="flex min-h-0 flex-1 flex-col lg:flex-row">
|
|
234
|
+
<div id="skill-atlas-panel" role="tabpanel" aria-labelledby={`skill-atlas-tab-${activeView}`} className="relative min-h-[420px] min-w-0 flex-1 overflow-auto">
|
|
235
|
+
{!graph && loading && <div className="p-4 text-[12px] text-[var(--text-secondary)]" aria-busy="true">{t("loading", undefined, "Loading skills…")}</div>}
|
|
236
|
+
{!graph && error && (
|
|
237
|
+
<div className="m-4 flex items-start gap-2" role="alert">
|
|
238
|
+
<span className={`${callout("error")} flex-1`}>{t("loadError", { error }, `Could not build the skill graph: ${error}`)}</span>
|
|
239
|
+
<button type="button" onClick={refetch} className="focus-ring rounded-md border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-3 min-h-[44px] sm:min-h-[36px] text-[12px] font-semibold">
|
|
240
|
+
{t("retry", undefined, "Retry")}
|
|
241
|
+
</button>
|
|
242
|
+
</div>
|
|
243
|
+
)}
|
|
244
|
+
{graph && graph.skills.length === 0 && (
|
|
245
|
+
<div className="m-4 grid justify-items-center gap-2 rounded-xl border border-[var(--border-secondary)] bg-[var(--bg-secondary)] p-6 text-center" data-testid="skill-atlas-empty">
|
|
246
|
+
<h2 className="m-0 text-[15px] font-semibold">{t("emptyTitle", undefined, "No skills load here")}</h2>
|
|
247
|
+
<p className="m-0 text-[12px] text-[var(--text-secondary)]">{t("emptyBody", undefined, "pi found no skill with a description in this scope.")}</p>
|
|
248
|
+
</div>
|
|
249
|
+
)}
|
|
250
|
+
{graph && graph.skills.length > 0 && activeView === "graph" && (
|
|
251
|
+
<SkillGraphView
|
|
252
|
+
allSkills={graph.skills}
|
|
253
|
+
allLinks={graph.links}
|
|
254
|
+
skills={visibleSkills}
|
|
255
|
+
links={visibleLinks}
|
|
256
|
+
selected={selected}
|
|
257
|
+
hops={hops}
|
|
258
|
+
matches={matches}
|
|
259
|
+
query={q}
|
|
260
|
+
onSelect={select}
|
|
261
|
+
/>
|
|
262
|
+
)}
|
|
263
|
+
{graph && graph.skills.length > 0 && activeView === "cards" && (
|
|
264
|
+
<SkillCardsView skills={listedSkills} links={visibleLinks.filter((l) => listedIds.has(l.source) || listedIds.has(l.target))} selected={selected} onSelect={select} />
|
|
265
|
+
)}
|
|
266
|
+
{graph && graph.skills.length > 0 && activeView === "links" && <SkillLinksView links={listedLinks} onSelect={select} />}
|
|
267
|
+
</div>
|
|
268
|
+
<aside
|
|
269
|
+
aria-label={t("detailLabel", undefined, "Skill details")}
|
|
270
|
+
className={`flex-none overflow-auto border-[var(--border-primary)] p-3 lg:w-80 lg:border-l ${selected ? "order-first border-b lg:order-none lg:border-b-0" : "border-t lg:border-t-0"}`}
|
|
271
|
+
>
|
|
272
|
+
<SkillDetailPanel skill={selectedSkill} links={visibleLinks} hops={hops} onHops={setHops} onSelect={select} />
|
|
273
|
+
</aside>
|
|
274
|
+
</div>
|
|
275
|
+
</div>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cards view: visible skills grouped by origin (project, global) and package.
|
|
3
|
+
* Non-matching skills are HIDDEN by the caller (dimmed text would fail WCAG
|
|
4
|
+
* 1.4.3). See change: add-skill-atlas-screen (ui-plan S2).
|
|
5
|
+
*/
|
|
6
|
+
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
7
|
+
import type React from "react";
|
|
8
|
+
import type { SkillLink, SkillNode } from "../shared/types.js";
|
|
9
|
+
import { ORIGIN_STYLE, shortPkg } from "./relation-style.js";
|
|
10
|
+
|
|
11
|
+
export function SkillCardsView({
|
|
12
|
+
skills,
|
|
13
|
+
links,
|
|
14
|
+
selected,
|
|
15
|
+
onSelect,
|
|
16
|
+
}: {
|
|
17
|
+
skills: readonly SkillNode[];
|
|
18
|
+
links: readonly SkillLink[];
|
|
19
|
+
selected: string | null;
|
|
20
|
+
onSelect: (id: string) => void;
|
|
21
|
+
}): React.ReactElement {
|
|
22
|
+
const t = useT();
|
|
23
|
+
const out = new Map<string, number>();
|
|
24
|
+
const inn = new Map<string, number>();
|
|
25
|
+
for (const l of links) {
|
|
26
|
+
if (l.type !== "references") continue;
|
|
27
|
+
out.set(l.source, (out.get(l.source) ?? 0) + 1);
|
|
28
|
+
inn.set(l.target, (inn.get(l.target) ?? 0) + 1);
|
|
29
|
+
}
|
|
30
|
+
const groups = new Map<string, SkillNode[]>();
|
|
31
|
+
for (const s of skills) {
|
|
32
|
+
const key = s.origin === "package" ? `pkg:${s.pkg ?? ""}` : s.origin;
|
|
33
|
+
groups.set(key, [...(groups.get(key) ?? []), s]);
|
|
34
|
+
}
|
|
35
|
+
const rank = (k: string) => (k === "project" ? 0 : k === "global" ? 1 : 2);
|
|
36
|
+
const keys = [...groups.keys()].sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : 1));
|
|
37
|
+
return (
|
|
38
|
+
<div className="grid gap-4 p-4" data-testid="skill-atlas-cards">
|
|
39
|
+
{keys.map((k) => {
|
|
40
|
+
const origin = k.startsWith("pkg:") ? "package" : (k as "project" | "global");
|
|
41
|
+
const name = origin === "package" ? shortPkg(k.slice(4)) : t(ORIGIN_STYLE[origin].labelKey, undefined, ORIGIN_STYLE[origin].label);
|
|
42
|
+
const list = groups.get(k) ?? [];
|
|
43
|
+
return (
|
|
44
|
+
<section key={k}>
|
|
45
|
+
<h3 className="m-0 mb-2 flex items-center gap-1.5 text-[12px] font-semibold text-[var(--text-secondary)]">
|
|
46
|
+
<span aria-hidden="true">{ORIGIN_STYLE[origin].glyph}</span>
|
|
47
|
+
{name} <span className="font-normal">{list.length}</span>
|
|
48
|
+
</h3>
|
|
49
|
+
<div className="grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(260px,1fr))]">
|
|
50
|
+
{list.map((s) => (
|
|
51
|
+
<button
|
|
52
|
+
key={s.id}
|
|
53
|
+
type="button"
|
|
54
|
+
aria-pressed={s.id === selected}
|
|
55
|
+
data-testid={`skill-atlas-card-${s.id}`}
|
|
56
|
+
onClick={() => onSelect(s.id)}
|
|
57
|
+
className={`focus-ring flex flex-col gap-1.5 rounded-xl border bg-[var(--bg-secondary)] p-3 text-left shadow-[inset_0_1px_0_var(--elevation-rim),0_4px_8px_var(--shadow-card)] hover:bg-[var(--bg-hover)] ${
|
|
58
|
+
s.id === selected ? "border-[var(--tint-blue-border)]" : "border-[var(--border-secondary)]"
|
|
59
|
+
}`}
|
|
60
|
+
>
|
|
61
|
+
<span className="text-[13.5px] font-semibold text-[var(--text-primary)] break-words">{s.id}</span>
|
|
62
|
+
<span className="line-clamp-2 text-[12px] text-[var(--text-secondary)]">{s.description}</span>
|
|
63
|
+
<span className="flex gap-2.5 text-[11px] text-[var(--text-secondary)]">
|
|
64
|
+
<span title={t("refsOut", undefined, "names other skills")}>→ {out.get(s.id) ?? 0}</span>
|
|
65
|
+
<span title={t("refsIn", undefined, "named by other skills")}>← {inn.get(s.id) ?? 0}</span>
|
|
66
|
+
<span>{t("linksTotal", { count: s.degree }, `${s.degree} links total`)}</span>
|
|
67
|
+
</span>
|
|
68
|
+
</button>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
</section>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|