Skip to content

refactor(skills): apply simplify-pass cleanups across the stack#2612

Merged
k11kirky merged 2 commits into
mainfrom
posthog-code/skills-08-simplify
Jun 12, 2026
Merged

refactor(skills): apply simplify-pass cleanups across the stack#2612
k11kirky merged 2 commits into
mainfrom
posthog-code/skills-08-simplify

Conversation

@k11kirky

@k11kirky k11kirky commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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?

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

React Doctor could not complete this scan.

No React dependency found in /tmp/react-doctor-baseline-dDuqUI/package.json. Add "react" to dependencies (or peerDependencies) and re-run.

Reviewed by React Doctor for commit 82345cb.

@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "refactor(skills): apply simplify-pass cl..." | Re-trigger Greptile

@k11kirky k11kirky marked this pull request as ready for review June 11, 2026 13:57
@k11kirky k11kirky force-pushed the posthog-code/skills-07-codex branch from 17de255 to 24695c3 Compare June 12, 2026 07:50
@k11kirky k11kirky force-pushed the posthog-code/skills-08-simplify branch from 840c76b to 8583731 Compare June 12, 2026 07:50
@k11kirky k11kirky force-pushed the posthog-code/skills-07-codex branch from 24695c3 to bf96408 Compare June 12, 2026 08:19
@k11kirky k11kirky force-pushed the posthog-code/skills-08-simplify branch from 8583731 to 46f11a8 Compare June 12, 2026 08:19
@k11kirky k11kirky added the Create Release This will trigger a new release label Jun 12, 2026 — with Graphite App

k11kirky commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

@k11kirky k11kirky force-pushed the posthog-code/skills-08-simplify branch from 46f11a8 to e502baf Compare June 12, 2026 11:43
@k11kirky k11kirky force-pushed the posthog-code/skills-07-codex branch from bf96408 to 3f66898 Compare June 12, 2026 11:43
@k11kirky k11kirky changed the base branch from posthog-code/skills-07-codex to graphite-base/2612 June 12, 2026 13:02
@k11kirky k11kirky changed the base branch from graphite-base/2612 to main June 12, 2026 13:10
k11kirky added 2 commits June 12, 2026 13:11
Reuse:
- stripFrontmatter moves to @posthog/shared (CRLF-aware), replacing the
  diverging workspace-server and UI copies so render and export agree.
- getUserSkillsDir() and isProbablyText() in skill-discovery replace
  eight inline path joins and two binary heuristics across skills,
  skills-marketplace, and posthog-plugin.
- ReplaceSkillDialog replaces three identical confirm-overwrite
  AlertDialogs; SkillListCard replaces three hand-rolled card rows
  (local, team, marketplace); installsFormatter is shared.
- skillErrors.ts centralizes the "already exists" conflict detection
  (one place to keep in sync with the throw sites across the tRPC
  boundary) and toast descriptions via shared getErrorMessage.

Simplification:
- teamSkillsKeys gains an `all` root key; mutations stop hardcoding
  the raw string. saveManifest router forwards input directly.
- dedupeCodexSkills checks mirrored copies by directory name only
  (the mirror state stores directory names).
- Dead resolveLlmSkill / LlmSkillResolveResponse removed from
  api-client until a version-history UI needs them.

Efficiency:
- The team listing query key is now stable: installedLocally marking
  is a pure core function (markInstalledTeamSkills) applied in the
  hook, so local skill changes no longer refetch the team list.
- exportSkill reads, installTeamSkill writes, and the codex mirror
  copy/remove phases now run their per-file work in parallel.

Generated-By: PostHog Code
Task-Id: f4e84f1a-19c9-490c-9b98-47787a7dddcf
…rt tests hermetic

Review feedback on #2610/#2611: the "already exists" overwrite detection
now keys off SKILL_EXISTS_MARKER in @posthog/shared, used verbatim by the
server messages and the UI matcher, so a reword cannot silently break the
overwrite dialog; getUserSkillsDir is mocked in skills.test.ts so the
codex-import and team-install tests run fully against temp dirs instead
of early-returning when the real home directory has a colliding skill.

Generated-By: PostHog Code
Task-Id: f4e84f1a-19c9-490c-9b98-47787a7dddcf
@k11kirky k11kirky force-pushed the posthog-code/skills-08-simplify branch from e502baf to 82345cb Compare June 12, 2026 13:11
@k11kirky k11kirky merged commit c477788 into main Jun 12, 2026
24 checks passed
@k11kirky k11kirky deleted the posthog-code/skills-08-simplify branch June 12, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Create Release This will trigger a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants