Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions llm-prompts/basic-integration-v2/1.0-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Analyze project and plan events
description: Start the event tracking setup process by analyzing the project and creating an event tracking plan
next:
- 1.1-edit.md
---

We're making an event tracking plan for this project.

Before proceeding, find any existing `posthog.capture()` code. Make note of event name formatting.

From the project's file list, select between 10 and 15 files that might have interesting business value for event tracking, especially conversion and churn events. Also look for additional files related to login that could be used for identifying users, along with error handling. Read the files. If a file is already well-covered by PostHog events, replace it with another option. Do not spawn subagents.

Look for opportunities to track client-side events.

**IMPORTANT: Server-side events are REQUIRED** if the project includes any instrumentable server-side code. If the project has API routes (e.g., `app/api/**/route.ts`) or Server Actions, you MUST include server-side events for critical business operations like:

- Payment/checkout completion
- Webhook handlers
- Authentication endpoints

Do not skip server-side events - they capture actions that cannot be tracked client-side.

Create a new file with a JSON array at the root of the project: .posthog-events.json. It should include one object for each event we want to add: event name, event description, and the file path we want to place the event in. If events already exist, don't duplicate them; supplement them.

Track actions only, not pageviews. These can be captured automatically. Exceptions can be made for "viewed"-type events that correspond to the top of a conversion funnel.

As you review files, make an internal note of opportunities to identify users and catch errors. We'll need them for the next step.

## Status

Before beginning a phase of the setup, you will send a status message with the exact prefix '[STATUS]', as in:

[STATUS] Checking project structure.

Status to report in this phase:

- Checking project structure
- Verifying PostHog dependencies
- Generating events based on project
34 changes: 34 additions & 0 deletions llm-prompts/basic-integration-v2/1.1-edit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Implement PostHog
description: Implement PostHog event tracking in the identified files, following best practices and the example project
next:
- 1.2-revise.md
---

For each of the files and events noted in .posthog-events.json, make edits to capture events using PostHog. Make sure to set up any helper files needed. Carefully examine the included example project code: your implementation should match it as closely as possible. Do not spawn subagents.

Use environment variables for PostHog keys. Do not hardcode PostHog keys.

If a file already has existing integration code for other tools or services, don't overwrite or remove that code. Place PostHog code below it.

For each event, add useful properties, and use your access to the PostHog source code to ensure correctness. You also have access to documentation about creating new events with PostHog. Consider this documentation carefully and follow it closely before adding events. Your integration should be based on documented best practices. Carefully consider how the user project's framework version may impact the correct PostHog integration approach.

Remember that you can find the source code for any dependency in the node_modules directory. This may be necessary to properly populate property names. There are also example project code files available via the PostHog MCP; use these for reference.

Where possible, add calls for PostHog's identify() function on the client side upon events like logins and signups. Use the contents of login and signup forms to identify users on submit. If there is server-side code, pass the client-side session and distinct ID to the server-side code to identify the user. On the server side, make sure events have a matching distinct ID where relevant.

It's essential to do this in both client code and server code, so that user behavior from both domains is easy to correlate.

You should also add PostHog exception capture error tracking to these files where relevant.

Remember: Do not alter the fundamental architecture of existing files. Make your additions minimal and targeted.

Remember the documentation and example project resources you were provided at the beginning. Read them now.

## Status

Status to report in this phase:

- Inserting PostHog capture code
- A status message for each file whose edits you are planning, including a high level summary of changes
- A status message for each file you have edited
20 changes: 20 additions & 0 deletions llm-prompts/basic-integration-v2/1.2-revise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Review and fix errors
description: Review and fix any errors in the PostHog integration implementation
next:
- 1.3-conclude.md
---

Check the project for errors. Read the package.json file for any type checking or build scripts that may provide input about what to fix. Remember that you can find the source code for any dependency in the node_modules directory. Do not spawn subagents.

Ensure that any components created were actually used.

Once all other tasks are complete, run any linter or prettier-like scripts found in the package.json, but ONLY on the files you have edited or created during this session. Do not run formatting or linting across the entire project's codebase.

## Status

Status to report in this phase:

- Finding and correcting errors
- Report details of any errors you fix
- Linting, building and prettying
40 changes: 40 additions & 0 deletions llm-prompts/basic-integration-v2/1.3-conclude.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Create dashboard and wrap up
description: Review and fix any errors in the PostHog integration implementation
---

Use the PostHog MCP to create a new dashboard named "Analytics basics" based on the events created here. Make sure to use the exact same event names as implemented in the code. Populate it with up to five insights, with special emphasis on things like conversion funnels, churn events, and other business critical insights.

Check for the installed skills in `<installDir>/.claude/skills/<skillId>/` and add a note at the top about the PostHog SDK and version installed as: `This skill is intended for <packageName> version <version>.`.

Search for a file called `.posthog-events.json` and read it for available events. Do not spawn subagents.

Create the file posthog-setup-report.md. It should include a summary of the integration edits, a table with the event names, event descriptions, and files where events were added, along with a list of links for the dashboard and insights created. Follow this format:

<wizard-report>
# PostHog post-wizard report

The wizard has completed a deep integration of your project. [Detailed summary of changes]

[table of events/descriptions/files]

## Next steps

We've built some insights and a dashboard for you to keep an eye on user behavior, based on the events we just instrumented:

[links]

### Agent skill

We've left an agent skill folder in your project. You can use this context for further agent development when using Claude Code. This will help ensure the model provides the most up-to-date approaches for integrating PostHog.

</wizard-report>

Upon completion, remove .posthog-events.json.

## Status

Status to report in this phase:

- Configured dashboard: [insert PostHog dashboard URL]
- Created setup report: [insert full local file path]
2 changes: 2 additions & 0 deletions llm-prompts/basic-integration/1.3-conclude.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ description: Review and fix any errors in the PostHog integration implementation

Use the PostHog MCP to create a new dashboard named "Analytics basics" based on the events created here. Make sure to use the exact same event names as implemented in the code. Populate it with up to five insights, with special emphasis on things like conversion funnels, churn events, and other business critical insights.

Check for the installed skills in `<installDir>/.claude/skills/<skillId>/` and add a note at the top about the PostHog SDK and version installed as: `This skill is intended for <packageName> version <version>.`.

Search for a file called `.posthog-events.json` and read it for available events. Do not spawn subagents.

Create the file posthog-setup-report.md. It should include a summary of the integration edits, a table with the event names, event descriptions, and files where events were added, along with a list of links for the dashboard and insights created. Follow this format:
Expand Down
47 changes: 41 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const { REPO_URL } = require('./lib/constants');

const BUILD_VERSION = process.env.BUILD_VERSION || 'dev';

// Workflow category names — v1 is the default (continuation links in body),
// v2 has workflow[] frontmatter and no continuation links.
const V1_WORKFLOW_CATEGORY = 'basic-integration';
const V2_WORKFLOW_CATEGORY = 'basic-integration-v2';

/**
* Load URI schema configuration
*/
Expand Down Expand Up @@ -152,19 +157,33 @@ async function main() {
const configDir = path.join(repoRoot, 'transformation-config');
const distDir = path.join(repoRoot, 'dist');
const skillsDir = path.join(distDir, 'skills');
const skillsDirV2 = path.join(distDir, V2_WORKFLOW_CATEGORY);
const tempDir = path.join(distDir, 'skills-temp');
const tempDirV2 = path.join(distDir, 'skills-temp-v2');
const promptsDir = path.join(repoRoot, 'llm-prompts');

try {
fs.mkdirSync(skillsDir, { recursive: true });
fs.mkdirSync(skillsDirV2, { recursive: true });

// Generate skill packages via generator
// Generate v1 skills (basic-integration: continuation links in body, no workflow frontmatter)
const skills = await generateAllSkills({
repoRoot,
configDir,
outputDir: tempDir,
promptsDir,
version: BUILD_VERSION,
workflowCategories: [V1_WORKFLOW_CATEGORY],
});

// Generate v2 skills (workflow[] frontmatter, no continuation links)
await generateAllSkills({
repoRoot,
configDir,
outputDir: tempDirV2,
promptsDir,
version: BUILD_VERSION,
workflowCategories: [V2_WORKFLOW_CATEGORY],
});

// Load docs config
Expand All @@ -175,18 +194,25 @@ async function main() {

const uriSchema = loadUriSchema(configDir);

// Create ZIP for each skill
// Create ZIPs — v1 into dist/skills/, v2 into dist/basic-integration-v2/
console.log('\nCreating skill ZIPs...');
const skillZips = {};
for (const skill of skills) {
// v1
const skillDir = path.join(tempDir, skill.id);
const buffer = await zipSkillToBuffer(skillDir);
const filename = `${skill.id}.zip`;
skillZips[filename] = buffer;

const standaloneZipPath = path.join(skillsDir, filename);
fs.writeFileSync(standaloneZipPath, buffer);
fs.writeFileSync(path.join(skillsDir, filename), buffer);
console.log(` ✓ ${filename} (${(buffer.length / 1024).toFixed(1)} KB)`);

// v2 (separate from bundle — served independently)
const skillDirV2 = path.join(tempDirV2, skill.id);
if (fs.existsSync(skillDirV2)) {
const bufferV2 = await zipSkillToBuffer(skillDirV2);
fs.writeFileSync(path.join(skillsDirV2, filename), bufferV2);
console.log(` ✓ v2/${filename} (${(bufferV2.length / 1024).toFixed(1)} KB)`);
}
}

// Generate marketplace plugin directories (before tempDir cleanup)
Expand All @@ -200,6 +226,7 @@ async function main() {
});

fs.rmSync(tempDir, { recursive: true, force: true });
fs.rmSync(tempDirV2, { recursive: true, force: true });

// Fetch doc content directly (no generator, no ZIP)
const docContents = {};
Expand Down Expand Up @@ -231,14 +258,22 @@ async function main() {

// Generate skill-menu.json: condensed list grouped by category
// The wizard agent filters by category to keep context small
// v2 base: same host, /basic-integration-v2/ path instead of /skills/
const v2BaseUrl = process.env.SKILLS_BASE_URL
? process.env.SKILLS_BASE_URL.replace(/\/skills$/, `/${V2_WORKFLOW_CATEGORY}`)
: null;

const skillsByCategory = {};
for (const skill of skills) {
const cat = skill.group;
if (!skillsByCategory[cat]) skillsByCategory[cat] = [];
const downloadUrl = manifest.resources.find(r => r.id === skill.id)?.downloadUrl;
const downloadUrlV2 = v2BaseUrl ? `${v2BaseUrl}/${skill.id}.zip` : undefined;
skillsByCategory[cat].push({
id: skill.id,
name: skill.name,
downloadUrl: manifest.resources.find(r => r.id === skill.id)?.downloadUrl,
downloadUrl,
downloadUrlV2,
});
}
const skillMenu = {
Expand Down
11 changes: 5 additions & 6 deletions scripts/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,11 @@ function serveZip(res, zipPath, filename) {
*/
function createServer() {
const server = http.createServer((req, res) => {
// Serve individual skill ZIPs at /skills/{id}.zip
const skillMatch = req.url?.match(/^\/skills\/(.+\.zip)$/);
if (skillMatch) {
const skillFile = skillMatch[1];
const skillPath = path.join(SKILLS_DIR, skillFile);
serveZip(res, skillPath, skillFile);
// Serve any .zip file under dist/ (skills, basic-integration-v2, etc.)
const zipMatch = req.url?.match(/^\/(.+\.zip)$/);
if (zipMatch) {
const zipPath = path.join(DIST_DIR, zipMatch[1]);
serveZip(res, zipPath, zipMatch[1]);
return;
}

Expand Down
49 changes: 31 additions & 18 deletions scripts/lib/skill-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ function discoverWorkflows(promptsDir) {
order: orderInfo?.order ?? 0,
title: parsed.data.title || filename,
description: parsed.data.description || '',
next: parsed.data.next || [],
content: parsed.content,
fullPath: filePath,
});
Expand All @@ -388,23 +389,13 @@ function discoverWorkflows(promptsDir) {
return a.order - b.order;
});

// Link to next step within each category
for (let i = 0; i < workflows.length; i++) {
const current = workflows[i];
const next = workflows[i + 1];

if (next && next.category === current.category) {
current.nextFilename = `${next.category}-${next.filename}`;
}
}

return workflows;
}

/**
* Generate SKILL.md frontmatter
*/
function generateFrontmatter(skill, version) {
function generateFrontmatter(skill, version, workflows) {
const frontmatter = {
name: skill.id,
description: skill.description,
Expand All @@ -414,6 +405,17 @@ function generateFrontmatter(skill, version) {
},
};

// Only emit workflow[] frontmatter for v2 categories
const v2Workflows = workflows.filter(wf => wf.category.endsWith('-v2'));
if (v2Workflows.length > 0) {
frontmatter.workflow = v2Workflows.map(wf => ({
step_id: wf.filename.replace(/\.md$/, ''),
reference: `${wf.category}-${wf.filename}`,
title: wf.title,
next: (wf.next || []).map(f => `${wf.category}-${f}`),
}));
}

return '---\n' + yaml.dump(frontmatter) + '---\n\n';
}

Expand Down Expand Up @@ -522,12 +524,19 @@ async function generateSkill({
// Include relevant workflows (flattened with category prefix, linked to next step)
// Skip workflows for docs-only skills
if (skill.type !== 'docs-only') {
for (const workflow of workflows) {
for (let i = 0; i < workflows.length; i++) {
const workflow = workflows[i];
let content = fs.readFileSync(workflow.fullPath, 'utf8');

// Append continuation message if there's a next step
if (workflow.nextFilename) {
content += `\n\n---\n\n**Upon completion, continue with:** [${workflow.nextFilename}](${workflow.nextFilename})`;
// v2 categories: next steps defined in file frontmatter, emitted in SKILL.md workflow[].
// v1 categories: append continuation links in body (computed from ordering).
const isV2 = workflow.category.endsWith('-v2');
if (!isV2) {
const nextWf = workflows[i + 1];
if (nextWf && nextWf.category === workflow.category) {
const nextRef = `${nextWf.category}-${nextWf.filename}`;
content += `\n\n---\n\n**Upon completion, continue with:** [${nextRef}](${nextRef})`;
}
}

const filename = `${workflow.category}-${workflow.filename}`;
Expand Down Expand Up @@ -557,7 +566,7 @@ async function generateSkill({
const workflowText = formatWorkflowSteps(workflows);

// Build SKILL.md content
let skillContent = generateFrontmatter(skill, version);
let skillContent = generateFrontmatter(skill, version, skill.type === 'docs-only' ? [] : workflows);

// Apply template substitutions
let body = skillTemplate
Expand Down Expand Up @@ -590,6 +599,7 @@ async function generateAllSkills({
outputDir,
promptsDir,
version,
workflowCategories,
}) {
console.log('Loading configuration...');

Expand All @@ -601,9 +611,12 @@ async function generateAllSkills({
// Expand grouped skills into flat array
const skills = expandSkillGroups(skillsConfig, configDir);

// Discover workflows
// Discover workflows, optionally filtered to specific categories
console.log('Discovering workflows...');
const workflows = discoverWorkflows(promptsDir);
let workflows = discoverWorkflows(promptsDir);
if (workflowCategories) {
workflows = workflows.filter(wf => workflowCategories.includes(wf.category));
}
console.log(` Found ${workflows.length} workflow files`);

// Create output directory
Expand Down
Loading