-
Notifications
You must be signed in to change notification settings - Fork 43
feat(skills): PostHog cloud team skills — read path #2609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const TEAM_SKILLS_SERVICE = Symbol.for( | ||
| "posthog.core.skills.teamSkillsService", | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { ContainerModule } from "inversify"; | ||
| import { TEAM_SKILLS_SERVICE } from "./identifiers"; | ||
| import { TeamSkillsService } from "./teamSkillsService"; | ||
|
|
||
| export const skillsCoreModule = new ContainerModule(({ bind }) => { | ||
| bind(TEAM_SKILLS_SERVICE).to(TeamSkillsService).inSingletonScope(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import type { | ||
| LlmSkillListItem, | ||
| PostHogAPIClient, | ||
| } from "@posthog/api-client/posthog-client"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { TeamSkillsService } from "./teamSkillsService"; | ||
|
|
||
| function makeItem(overrides: Partial<LlmSkillListItem>): LlmSkillListItem { | ||
| return { | ||
| id: "skill-1", | ||
| name: "pr-shepherd", | ||
| description: "Shepherds PRs", | ||
| allowed_tools: [], | ||
| metadata: {}, | ||
| version: 2, | ||
| is_latest: true, | ||
| latest_version: 2, | ||
| created_by: { email: "dev@posthog.com" }, | ||
| created_at: "2026-01-01T00:00:00Z", | ||
| updated_at: "2026-02-01T00:00:00Z", | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function makeClient(result: LlmSkillListItem[] | null): PostHogAPIClient { | ||
| return { | ||
| listLlmSkills: vi | ||
| .fn<PostHogAPIClient["listLlmSkills"]>() | ||
| .mockResolvedValue(result), | ||
| } satisfies Partial<PostHogAPIClient> as unknown as PostHogAPIClient; | ||
| } | ||
|
k11kirky marked this conversation as resolved.
|
||
|
|
||
| describe("TeamSkillsService.listTeamSkills", () => { | ||
| it("reports the feature as unavailable when the API returns null", async () => { | ||
| const listing = await new TeamSkillsService().listTeamSkills( | ||
| makeClient(null), | ||
| [], | ||
| ); | ||
|
|
||
| expect(listing).toEqual({ available: false, skills: [] }); | ||
| }); | ||
|
|
||
| it("maps team skills and marks ones that exist locally", async () => { | ||
| const client = makeClient([ | ||
| makeItem({}), | ||
| makeItem({ id: "skill-2", name: "release-notes", created_by: null }), | ||
| ]); | ||
|
|
||
| const listing = await new TeamSkillsService().listTeamSkills(client, [ | ||
| "release-notes", | ||
| "unrelated-local", | ||
| ]); | ||
|
|
||
| expect(listing.available).toBe(true); | ||
| expect(listing.skills).toEqual([ | ||
| { | ||
| id: "skill-1", | ||
| name: "pr-shepherd", | ||
| description: "Shepherds PRs", | ||
| version: 2, | ||
| updatedAt: "2026-02-01T00:00:00Z", | ||
| createdByEmail: "dev@posthog.com", | ||
| installedLocally: false, | ||
| }, | ||
| expect.objectContaining({ | ||
| name: "release-notes", | ||
| createdByEmail: null, | ||
| installedLocally: true, | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| it("drops non-latest versions", async () => { | ||
| const client = makeClient([ | ||
| makeItem({ is_latest: false, version: 1 }), | ||
| makeItem({ id: "skill-1b", version: 2 }), | ||
| ]); | ||
|
|
||
| const listing = await new TeamSkillsService().listTeamSkills(client, []); | ||
|
|
||
| expect(listing.skills).toHaveLength(1); | ||
| expect(listing.skills[0]?.id).toBe("skill-1b"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import type { | ||
| LlmSkillListItem, | ||
| PostHogAPIClient, | ||
| } from "@posthog/api-client/posthog-client"; | ||
| import { injectable } from "inversify"; | ||
|
|
||
| export interface TeamSkillInfo { | ||
| id: string; | ||
| name: string; | ||
| description: string; | ||
| version: number; | ||
| updatedAt: string; | ||
| createdByEmail: string | null; | ||
| /** A local skill with the same name already exists on this machine. */ | ||
| installedLocally: boolean; | ||
| } | ||
|
|
||
| export interface TeamSkillsListing { | ||
| /** False when the org does not have the team-skills feature enabled. */ | ||
| available: boolean; | ||
| skills: TeamSkillInfo[]; | ||
| } | ||
|
|
||
| @injectable() | ||
| export class TeamSkillsService { | ||
| /** | ||
| * Lists team skills merged with the local listing: the availability | ||
| * decision (flag off → absent group, no errors) and the "already | ||
| * installed locally" marking both live here, so the UI keeps one hook. | ||
| */ | ||
| async listTeamSkills( | ||
| client: PostHogAPIClient, | ||
| localSkillNames: string[], | ||
| ): Promise<TeamSkillsListing> { | ||
| const items = await client.listLlmSkills(); | ||
| if (items === null) { | ||
| return { available: false, skills: [] }; | ||
| } | ||
| const localNames = new Set(localSkillNames); | ||
| return { | ||
| available: true, | ||
| skills: items | ||
| .filter((item) => item.is_latest) | ||
| .map((item) => toTeamSkillInfo(item, localNames)), | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| function toTeamSkillInfo( | ||
| item: LlmSkillListItem, | ||
| localNames: Set<string>, | ||
| ): TeamSkillInfo { | ||
| return { | ||
| id: item.id, | ||
| name: item.name, | ||
| description: item.description, | ||
| version: item.latest_version ?? item.version, | ||
| updatedAt: item.updated_at, | ||
| createdByEmail: item.created_by?.email ?? null, | ||
| installedLocally: localNames.has(item.name), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.