Commit c477788
authored
refactor(skills): apply simplify-pass cleanups across the stack (#2612)
## Problem
Several small pieces of logic were duplicated or misplaced across the skills feature, making it harder to maintain and extend. Specifically: the "already installed locally" marking was coupled to the team skills fetch, `stripFrontmatter` existed only in the UI package, error-handling patterns were repeated inline across many components, and the card row layout was copy-pasted across three different list surfaces.
## Changes
**Decouple local-install marking from the team skills fetch**
`listTeamSkills` no longer accepts `localSkillNames` and no longer marks skills as installed. A new pure function `markInstalledTeamSkills` handles that separately. `useTeamSkills` now fetches the team listing once and applies `markInstalledTeamSkills` in a `useMemo`, so local skill changes never trigger a refetch of the remote listing. The query key structure is also cleaned up with a shared `teamSkillsKeys.all` root so invalidations are consistent.
**Move `stripFrontmatter` to `@posthog/shared`**
The UI-local `stripFrontmatter.ts` is deleted. A CRLF-aware version now lives in `packages/shared/src/skills.ts` and is exported from the package index. All consumers (`SkillDetailPanel`, `MarketplaceSkillPanel`, `TeamSkillDetailPanel`, the workspace-server export path) import from `@posthog/shared`.
**Centralise skill error helpers**
A new `skillErrors.ts` module exposes `isSkillExistsError` and `skillErrorDescription`. All the scattered `error instanceof Error ? error.message : ""` / `.includes("already exists")` patterns across `SkillDetailPanel`, `TeamSkillDetailPanel`, `MarketplaceSkillPanel`, `SkillFileEditor`, `SkillManifestEditor`, `NewSkillDialog`, and `SkillFileEditor` are replaced with calls to these helpers.
**Extract `SkillListCard` shared component**
The identical card-row markup (icon box, title/subtitle text block, trailing slot, selection highlight) was duplicated in `SkillCard`, `TeamSkillsSection`, and `MarketplaceBrowse`. It is now a single `SkillListCard` component with `icon`, `title`, `subtitle`, `isSelected`, `onClick`, and `trailing` props.
**Extract `ReplaceSkillDialog` shared component**
The confirm-overwrite `AlertDialog` was duplicated in `MarketplaceSkillPanel`, `TeamSkillDetailPanel`, and `SkillDetailPanel`. It is now a single `ReplaceSkillDialog` component parameterised by `skillName`, `verb` ("Reinstalling" / "Importing"), and `onConfirm`.
**Consolidate `getUserSkillsDir` and `isProbablyText`**
Both helpers were defined inline in multiple workspace-server files. They now live in `skill-discovery.ts` and are imported wherever needed, removing the repeated `os.homedir()` path construction.
**Parallelise file I/O in the workspace server**
Sequential `for` loops in `mirrorUserSkillsToCodex`, `exportSkill`, and `installSkill` are replaced with `Promise.all` calls.
**Move `installsFormatter` to `useMarketplace.ts`**
The `Intl.NumberFormat` instance was duplicated in `MarketplaceBrowse` and `MarketplaceSkillPanel`; it is now exported once from `useMarketplace.ts`.
**Remove unused `resolveLlmSkill` API method**
`resolveLlmSkill` and its `LlmSkillResolveResponse` type are removed from the API client as they are no longer called anywhere.
## How did you test this?
- Updated unit tests for `TeamSkillsService.listTeamSkills` to reflect the removed `localSkillNames` parameter.
- Added a new `markInstalledTeamSkills` unit test covering name-based matching and unrelated local names.
- Existing tests for `publishSkill` and other service methods continue to pass.
## Automatic notifications
- [ ] Publish to changelog?
- [ ] Alert Sales and Marketing teams?1 parent 3e78bd5 commit c477788
28 files changed
Lines changed: 518 additions & 494 deletions
File tree
- packages
- api-client/src
- core/src/skills
- host-router/src/routers
- ui/src/features/skills
- workspace-server/src/services
- posthog-plugin
- skills-marketplace
- skills
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 192 | | |
205 | 193 | | |
206 | 194 | | |
| |||
3724 | 3712 | | |
3725 | 3713 | | |
3726 | 3714 | | |
3727 | | - | |
3728 | | - | |
3729 | | - | |
3730 | | - | |
3731 | | - | |
3732 | | - | |
3733 | | - | |
3734 | | - | |
3735 | | - | |
3736 | | - | |
3737 | | - | |
3738 | | - | |
3739 | | - | |
3740 | | - | |
3741 | | - | |
3742 | | - | |
3743 | 3715 | | |
3744 | 3716 | | |
3745 | 3717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | | - | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
47 | | - | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 69 | + | |
74 | 70 | | |
75 | 71 | | |
76 | 72 | | |
| |||
80 | 76 | | |
81 | 77 | | |
82 | 78 | | |
83 | | - | |
| 79 | + | |
84 | 80 | | |
85 | 81 | | |
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
89 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
90 | 107 | | |
91 | 108 | | |
92 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
38 | 56 | | |
39 | 57 | | |
40 | 58 | | |
| |||
63 | 81 | | |
64 | 82 | | |
65 | 83 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
69 | 87 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 88 | + | |
74 | 89 | | |
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
78 | | - | |
79 | 93 | | |
80 | 94 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 95 | + | |
84 | 96 | | |
85 | 97 | | |
86 | 98 | | |
| |||
151 | 163 | | |
152 | 164 | | |
153 | 165 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 166 | + | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
161 | 170 | | |
162 | 171 | | |
163 | 172 | | |
164 | 173 | | |
165 | | - | |
| 174 | + | |
166 | 175 | | |
167 | 176 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 66 | + | |
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
| |||
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
71 | | - | |
| 69 | + | |
72 | 70 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 71 | + | |
89 | 72 | | |
90 | 73 | | |
91 | 74 | | |
92 | 75 | | |
93 | 76 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
117 | 104 | | |
118 | 105 | | |
119 | 106 | | |
| |||
0 commit comments