:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): install the whole team skill body, not the first page (#96268)
posthog[bot]01a3327e0088
diff --git a/products/desktop/packages/api-client/src/posthog-client.test.ts b/products/desktop/packages/api-client/src/posthog-client.test.tsindex ce764e7dfdb3..267a084f486b 100644--- a/products/desktop/packages/api-client/src/posthog-client.test.ts+++ b/products/desktop/packages/api-client/src/posthog-client.test.ts@@ -84,6 +84,75 @@ describe("PostHogAPIClient", () => {});});+ describe("getLlmSkillByName", () => {+ // The endpoint pages a body over 8,000 characters, so a single request+ // returns instructions that stop mid-skill.+ it("follows body_next_offset until the whole body is fetched", async () => {+ const body = `${"x".repeat(8000)}final instruction`;+ const fetch = vi.fn().mockImplementation((url: URL) => {+ const offset = Number(url.searchParams.get("body_offset") ?? "0");+ const page = body.slice(offset, offset + 8000);+ const next = offset + 8000 < body.length ? offset + 8000 : null;+ return Promise.resolve(+ new Response(+ JSON.stringify({+ name: "pr-shepherd",+ version: 3,+ body: page,+ body_total_length: body.length,+ body_next_offset: next,+ files: [],+ }),+ { status: 200, headers: { "Content-Type": "application/json" } },+ ),+ );+ });+ const client = new PostHogAPIClient(+ "https://app.posthog.test",+ async () => "token",+ async () => "token",+ 42,+ { fetch },+ );++ const skill = await client.getLlmSkillByName("pr-shepherd");++ expect(skill.body).toBe(body);+ // The continuation pins the version, so a publish between pages cannot+ // splice two bodies together.+ const second = fetch.mock.calls[1][0] as URL;+ expect(second.searchParams.get("body_offset")).toBe("8000");+ expect(second.searchParams.get("version")).toBe("3");+ });++ it("rejects a body that arrives shorter than the server reports", async () => {+ const fetch = vi.fn().mockResolvedValue(+ new Response(+ JSON.stringify({+ name: "pr-shepherd",+ version: 3,+ body: "# Body",+ body_total_length: 9689,+ body_next_offset: null,+ files: [],+ }),+ { status: 200, headers: { "Content-Type": "application/json" } },+ ),+ );+ const client = new PostHogAPIClient(+ "https://app.posthog.test",+ async () => "token",+ async () => "token",+ 42,+ { fetch },+ );++ await expect(client.getLlmSkillByName("pr-shepherd")).rejects.toThrow(+ "got 6 of 9689 characters",+ );+ });+ });+describe("getInsightDefinition", () => {it("loads the saved insight with a blocking refresh and returns its result", async () => {const fetch = vi.fn().mockResolvedValue(diff --git a/products/desktop/packages/api-client/src/posthog-client.ts b/products/desktop/packages/api-client/src/posthog-client.tsindex 1ddfec31f32a..e7d86314ec1b 100644--- a/products/desktop/packages/api-client/src/posthog-client.ts+++ b/products/desktop/packages/api-client/src/posthog-client.ts@@ -531,6 +531,10 @@ export interface LlmSkillListItem {export interface LlmSkill extends LlmSkillListItem {/** The SKILL.md markdown content. */body: string;+ /** Length of the whole body, whatever slice of it `body` holds. */+ body_total_length?: number;+ /** Offset of the next body page, or null once `body` reaches the end. */+ body_next_offset?: number | null;/** Companion file manifest (paths only; fetch contents separately). */files: LlmSkillFileManifest[];}@@ -7022,11 +7026,49 @@ export class PostHogAPIClient {return data.results ?? [];}- /** Fetches the latest version of a team skill, including body and file manifest. */+ /**+ * Fetches the latest version of a team skill, including body and file manifest.+ * The endpoint caps an unpaged body at its own page length, so follow+ * `body_next_offset` to the end and return the whole body to every caller.+ */async getLlmSkillByName(name: string): Promise<LlmSkill> {+ const first = await this.getLlmSkillBodyPage(name);+ const pages = [first.body];+ let offset = first.body_next_offset;+ while (offset != null) {+ // Pin the version: a publish between pages would otherwise splice two bodies.+ const page = await this.getLlmSkillBodyPage(name, {+ offset,+ version: first.version,+ });+ pages.push(page.body);+ // An offset that does not advance would page forever; the length check below+ // then reports the short body.+ const next = page.body_next_offset;+ offset = next != null && next > offset ? next : null;+ }++ const body = pages.join("");+ const total = first.body_total_length;+ if (total != null && body.length !== total) {+ throw new Error(+ `Failed to fetch team skill: got ${body.length} of ${total} characters of the body of "${name}"`,+ );+ }+ return { ...first, body, body_next_offset: null };+ }++ private async getLlmSkillBodyPage(+ name: string,+ paging?: { offset: number; version: number },+ ): Promise<LlmSkill> {const teamId = await this.getTeamId();const urlPath = `/api/environments/${teamId}/llm_skills/name/${encodeURIComponent(name)}`;const url = new URL(`${this.api.baseUrl}${urlPath}`);+ if (paging) {+ url.searchParams.set("body_offset", String(paging.offset));+ url.searchParams.set("version", String(paging.version));+ }const response = await this.api.fetcher.fetch({method: "get",url,diff --git a/products/desktop/packages/core/src/skills/teamSkillsService.test.ts b/products/desktop/packages/core/src/skills/teamSkillsService.test.tsindex 05cca7102dd0..d55d1531ed62 100644--- a/products/desktop/packages/core/src/skills/teamSkillsService.test.ts+++ b/products/desktop/packages/core/src/skills/teamSkillsService.test.ts@@ -270,6 +270,23 @@ describe("TeamSkillsService.fetchSkillForInstall", () => {expect(client.getLlmSkillFile).toHaveBeenCalledTimes(2);});+ it("refuses to install a body that arrived incomplete", async () => {+ const client = {+ getLlmSkillByName: vi.fn().mockResolvedValue({+ name: "pr-shepherd",+ description: "Shepherds PRs",+ body: "# Body",+ body_total_length: 9689,+ files: [],+ }),+ getLlmSkillFile: vi.fn(),+ } as unknown as PostHogAPIClient;++ await expect(+ makeService().fetchSkillForInstall(client, "pr-shepherd"),+ ).rejects.toThrow("Only part of");+ });+it("maps disable-model-invocation metadata onto the exported skill", async () => {const client = {getLlmSkillByName: vi.fn().mockResolvedValue({diff --git a/products/desktop/packages/core/src/skills/teamSkillsService.ts b/products/desktop/packages/core/src/skills/teamSkillsService.tsindex 20ac3d288806..af96b163318f 100644--- a/products/desktop/packages/core/src/skills/teamSkillsService.ts+++ b/products/desktop/packages/core/src/skills/teamSkillsService.ts@@ -159,6 +159,16 @@ export class TeamSkillsService {name: string,): Promise<ExportedSkill> {const detail = await client.getLlmSkillByName(name);+ // A short body would silently replace an installed skill with truncated+ // instructions, so refuse the install instead of writing it.+ if (+ detail.body_total_length != null &&+ detail.body.length !== detail.body_total_length+ ) {+ throw new Error(+ `Only part of "${name}" arrived from PostHog, so it was not installed. Try again.`,+ );+ }// Ignored entries in legacy-published skills are dropped downstream// anyway; skipping the fetch avoids one request per junk file.const files = await Promise.all(