Skip to content

: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.

fix(context-layer): use checkout skills in local desktop (#86836)

Peter Kirkham843170d65898
diff --git a/products/desktop/package.json b/products/desktop/package.json
index 0a1127402dc3..1c4753d2ee7c 100644
--- a/products/desktop/package.json
+++ b/products/desktop/package.json
@@ -11,11 +11,11 @@
"preinstall": "node scripts/enforce-pnpm.mjs",
"postinstall": "bash scripts/ensure-phrocs.sh --update",
"bootstrap:cloud-task": "pnpm install --frozen-lockfile --prefer-offline --ignore-scripts && pnpm build:deps",
- "dev": "pnpm build:deps && bash scripts/ensure-phrocs.sh && bin/phrocs --config mprocs.yaml",
- "dev:mprocs": "pnpm build:deps && mprocs",
+ "dev": "pnpm skills:local && pnpm build:deps && bash scripts/ensure-phrocs.sh && bin/phrocs --config mprocs.yaml",
+ "dev:mprocs": "pnpm skills:local && pnpm build:deps && mprocs",
"dev:agent": "pnpm --filter agent dev",
"dev:git": "pnpm --filter @posthog/git dev",
- "dev:code": "pnpm --filter code start",
+ "dev:code": "pnpm skills:local && pnpm --filter code start",
"app:cdp": "node scripts/electron-cdp.mjs",
"build": "turbo build",
"build:deps": "turbo build --filter=@posthog/code^...",
@@ -36,6 +36,7 @@
"format": "biome format --write",
"clean": "pnpm -r clean",
"knip": "knip",
+ "skills:local": "node scripts/sync-local-skills.mjs",
"skills:pull": "node scripts/pull-skills.mjs",
"hosthog:build": "pnpm install --frozen-lockfile --ignore-scripts --filter @posthog/web... && SKIP_PRODUCT_ENGINEER_SKILLS_DOWNLOAD=1 pnpm exec turbo build --filter=@posthog/web && ln -sfn apps/web/dist dist"
},
diff --git a/products/desktop/packages/workspace-server/src/services/posthog-plugin/README.md b/products/desktop/packages/workspace-server/src/services/posthog-plugin/README.md
index 705e29af40a2..42b1de9a9e2f 100644
--- a/products/desktop/packages/workspace-server/src/services/posthog-plugin/README.md
+++ b/products/desktop/packages/workspace-server/src/services/posthog-plugin/README.md
@@ -69,17 +69,27 @@ Vite watches `plugins/posthog/` (and `local-skills/` in dev) for hot-reload.
### Testing with local skills
-1. Create a skill directory in `plugins/posthog/local-skills/`, e.g.:
+`pnpm dev` and `pnpm dev:code` sync the context layer skills from the current monorepo checkout into `plugins/posthog/local-skills/` before starting Desktop. This makes local agent sessions use the checked-out context layer skill sources instead of the production release.
+
+To refresh the overlay without restarting Desktop, run:
+
+```sh
+pnpm skills:local
+```
+
+For a Desktop-only skill that is not part of the monorepo skill build:
+
+1. Start Desktop once so the checkout skills are synced.
+2. Create a skill directory in `plugins/posthog/local-skills/`, e.g.:
```
plugins/posthog/local-skills/my-skill/SKILL.md
```
-2. Run `pnpm dev:code` — Vite watches and hot-reloads
-3. The local skill overrides any shipped or remote skill with the same name
+3. Vite watches the directory and hot-reloads the skill.
### Pulling remote skills locally for editing
```sh
-pnpm pull-skills
+pnpm skills:pull
```
Downloads the latest `skills.zip` into `plugins/posthog/local-skills/`. You can then edit them locally and Vite will pick up changes.
diff --git a/products/desktop/scripts/sync-local-skills.mjs b/products/desktop/scripts/sync-local-skills.mjs
new file mode 100644
index 000000000000..5104109947b9
--- /dev/null
+++ b/products/desktop/scripts/sync-local-skills.mjs
@@ -0,0 +1,62 @@
+#!/usr/bin/env node
+
+import { cp, mkdir, readdir, rm } from "node:fs/promises";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const REPOSITORY_DIR = resolve(__dirname, "../../..");
+const CHECKOUT_SKILLS_DIR = join(
+ REPOSITORY_DIR,
+ "products",
+ "context_layer",
+ "skills",
+);
+const LOCAL_SKILLS_DIR = join(
+ __dirname,
+ "..",
+ "plugins",
+ "posthog",
+ "local-skills",
+);
+
+export async function syncCheckoutSkills({
+ checkoutSkillsDir,
+ localSkillsDir,
+}) {
+ const entries = await readdir(checkoutSkillsDir);
+ if (entries.length === 0) {
+ throw new Error(`No checkout skills found at ${checkoutSkillsDir}`);
+ }
+
+ await mkdir(localSkillsDir, { recursive: true });
+ const localEntries = await readdir(localSkillsDir);
+ await Promise.all(
+ localEntries
+ .filter((entry) => entry.startsWith("context-layer-"))
+ .map((entry) =>
+ rm(join(localSkillsDir, entry), { recursive: true, force: true }),
+ ),
+ );
+ await Promise.all(
+ entries.map((entry) =>
+ cp(join(checkoutSkillsDir, entry), join(localSkillsDir, entry), {
+ recursive: true,
+ }),
+ ),
+ );
+}
+
+async function main() {
+ await syncCheckoutSkills({
+ checkoutSkillsDir: CHECKOUT_SKILLS_DIR,
+ localSkillsDir: LOCAL_SKILLS_DIR,
+ });
+ console.log(
+ `Context layer skills synced from this checkout to ${LOCAL_SKILLS_DIR}`,
+ );
+}
+
+if (fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
+ await main();
+}
diff --git a/products/desktop/scripts/sync-local-skills.test.mjs b/products/desktop/scripts/sync-local-skills.test.mjs
new file mode 100644
index 000000000000..5d4532462c38
--- /dev/null
+++ b/products/desktop/scripts/sync-local-skills.test.mjs
@@ -0,0 +1,54 @@
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, test } from "node:test";
+
+import { syncCheckoutSkills } from "./sync-local-skills.mjs";
+
+const temporaryDirectories = [];
+
+afterEach(async () => {
+ await Promise.all(
+ temporaryDirectories
+ .splice(0)
+ .map((directory) => rm(directory, { recursive: true, force: true })),
+ );
+});
+
+test("overrides context layer skills without removing other local skills", async () => {
+ const root = await mkdtemp(join(tmpdir(), "posthog-local-skills-"));
+ temporaryDirectories.push(root);
+ const checkoutSkillsDir = join(root, "checkout");
+ const localSkillsDir = join(root, "local");
+ await mkdir(join(checkoutSkillsDir, "context-layer-dreaming"), {
+ recursive: true,
+ });
+ await mkdir(join(localSkillsDir, "context-layer-dreaming"), {
+ recursive: true,
+ });
+ await mkdir(join(localSkillsDir, "production-only"), { recursive: true });
+ await writeFile(
+ join(checkoutSkillsDir, "context-layer-dreaming", "SKILL.md"),
+ "checkout version",
+ );
+ await writeFile(
+ join(localSkillsDir, "context-layer-dreaming", "SKILL.md"),
+ "production version",
+ );
+ await writeFile(join(localSkillsDir, "production-only", "SKILL.md"), "keep");
+
+ await syncCheckoutSkills({ checkoutSkillsDir, localSkillsDir });
+
+ assert.equal(
+ await readFile(
+ join(localSkillsDir, "context-layer-dreaming", "SKILL.md"),
+ "utf8",
+ ),
+ "checkout version",
+ );
+ assert.equal(
+ await readFile(join(localSkillsDir, "production-only", "SKILL.md"), "utf8"),
+ "keep",
+ );
+});