Skip to content
Merged
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@posthog/context-mill",
"version": "1.2.0",
"private": true,
"type": "module",
"description": "PostHog Context Mill: assembling and packaging context for AI agents and LLMs",
"scripts": {
"build": "node scripts/build.js",
Expand All @@ -16,6 +17,9 @@
"archiver": "^7.0.1",
"vitest": "^2.0.0"
},
"engines": {
"node": ">=20.11.0"
},
"dependencies": {
"gray-matter": "^4.0.3",
"js-yaml": "^4.1.1"
Expand Down
16 changes: 8 additions & 8 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* - Individual skill ZIPs ({skill-id}.zip)
*/

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const archiver = require('archiver');
const { generateAllSkills, loadSkillsConfig, fetchDoc } = require('./lib/skill-generator');
const { generateMarketplace } = require('./lib/marketplace-generator');
const { REPO_URL } = require('./lib/constants');
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import archiver from 'archiver';
import { generateAllSkills, loadSkillsConfig, fetchDoc } from './lib/skill-generator.js';
import { generateMarketplace } from './lib/marketplace-generator.js';
import { REPO_URL } from './lib/constants.js';

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

Expand Down Expand Up @@ -148,7 +148,7 @@ async function main() {
console.log('Building resources...');
console.log(`Version: ${BUILD_VERSION}\n`);

const repoRoot = path.join(__dirname, '..');
const repoRoot = path.join(import.meta.dirname, '..');
const configDir = path.join(repoRoot, 'transformation-config');
const distDir = path.join(repoRoot, 'dist');
const skillsDir = path.join(distDir, 'skills');
Expand Down
26 changes: 13 additions & 13 deletions scripts/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
* pnpm run dev:local-resources (and update wrangler --var flag)
*/

const http = require('http');
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
import http from 'http';
import fs from 'fs';
import path from 'path';
import { spawn } from 'child_process';

const PORT = process.env.PORT || 8765;
const DIST_DIR = path.join(__dirname, '..', 'dist');
const DIST_DIR = path.join(import.meta.dirname, '..', 'dist');
const SKILLS_ZIP_PATH = path.join(DIST_DIR, 'skills-mcp-resources.zip');
const SKILLS_DIR = path.join(DIST_DIR, 'skills');

// Directories to watch for changes
const WATCH_DIRS = [
path.join(__dirname, '..', 'llm-prompts'),
path.join(__dirname, '..', 'transformation-config'),
path.join(__dirname, '..', 'mcp-commands'),
path.join(__dirname, '..', 'basics'),
path.join(import.meta.dirname, '..', 'llm-prompts'),
path.join(import.meta.dirname, '..', 'transformation-config'),
path.join(import.meta.dirname, '..', 'mcp-commands'),
path.join(import.meta.dirname, '..', 'basics'),
];

let isRebuilding = false;
Expand All @@ -53,7 +53,7 @@ function rebuild() {

const buildProcess = spawn('npm', ['run', 'build'], {
stdio: 'inherit',
cwd: path.join(__dirname, '..'),
cwd: path.join(import.meta.dirname, '..'),
env: { ...process.env, SKILLS_BASE_URL: localSkillsUrl },
shell: true
});
Expand Down Expand Up @@ -83,11 +83,11 @@ function setupWatchers() {

WATCH_DIRS.forEach(dir => {
if (!fs.existsSync(dir)) {
console.log(` ⚠️ ${path.relative(path.join(__dirname, '..'), dir)} (not found, skipping)`);
console.log(` ⚠️ ${path.relative(path.join(import.meta.dirname, '..'), dir)} (not found, skipping)`);
return;
}

console.log(` 📁 ${path.relative(path.join(__dirname, '..'), dir)}`);
console.log(` 📁 ${path.relative(path.join(import.meta.dirname, '..'), dir)}`);

// Watch recursively
fs.watch(dir, { recursive: true }, (eventType, filename) => {
Expand Down Expand Up @@ -200,7 +200,7 @@ async function main() {
await new Promise((resolve) => {
const buildProcess = spawn('npm', ['run', 'build'], {
stdio: 'inherit',
cwd: path.join(__dirname, '..'),
cwd: path.join(import.meta.dirname, '..'),
env: { ...process.env, SKILLS_BASE_URL: localSkillsUrl },
shell: true
});
Expand Down
6 changes: 1 addition & 5 deletions scripts/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
* Shared constants for build scripts
*/

const REPO_URL = 'https://github.com/PostHog/context-mill';

module.exports = {
REPO_URL,
};
export const REPO_URL = 'https://github.com/PostHog/context-mill';
12 changes: 6 additions & 6 deletions scripts/lib/example-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Reads configuration from transformation-config/skip-patterns.yaml
*/

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const { composePlugins, ignoreLinePlugin, ignoreFilePlugin, ignoreBlockPlugin } = require('../plugins/index');
const { REPO_URL } = require('./constants');
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import { composePlugins, ignoreLinePlugin, ignoreFilePlugin, ignoreBlockPlugin } from '../plugins/index.js';
import { REPO_URL } from './constants.js';

/**
* Load skip patterns from YAML config
Expand Down Expand Up @@ -182,7 +182,7 @@ function processExample({ examplePath, displayName, id, repoRoot, skipPatterns,
*/
const defaultPlugins = [ignoreFilePlugin, ignoreBlockPlugin, ignoreLinePlugin];

module.exports = {
export {
loadSkipPatterns,
mergeSkipPatterns,
processExample,
Expand Down
8 changes: 4 additions & 4 deletions scripts/lib/marketplace-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Configuration is driven by transformation-config/marketplace.yaml.
*/

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';

/**
* Load marketplace config from YAML
Expand Down Expand Up @@ -253,4 +253,4 @@ function generateMarketplace({ skills, tempDir, version, outputDir, configDir })
return { marketplaceDir, pluginCount: allPluginNames.length, skillCount: allSkillEntries.length };
}

module.exports = { generateMarketplace };
export { generateMarketplace };
12 changes: 6 additions & 6 deletions scripts/lib/skill-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* - Commandments (based on tags)
*/

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const matter = require('gray-matter');
const { processExample, loadSkipPatterns, mergeSkipPatterns, defaultPlugins } = require('./example-processor');
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import matter from 'gray-matter';
import { processExample, loadSkipPatterns, mergeSkipPatterns, defaultPlugins } from './example-processor.js';

/**
* Load YAML config file
Expand Down Expand Up @@ -670,7 +670,7 @@ async function generateAllSkills({
}));
}

module.exports = {
export {
loadSkillsConfig,
loadCommandments,
loadSkillTemplate,
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/tests/skill-config-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'path';
import { tmpdir } from 'os';
import yaml from 'js-yaml';

const { loadSkillsConfig } = require('../skill-generator.js');
import { loadSkillsConfig } from '../skill-generator.js';

function createFixture(tree, baseDir) {
for (const [name, content] of Object.entries(tree)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdirSync, writeFileSync, readFileSync, existsSync, mkdtempSync, rmSync
import { join } from 'path';
import { tmpdir } from 'os';

const { expandSkillGroups, generateSkill } = require('../skill-generator.js');
import { expandSkillGroups, generateSkill } from '../skill-generator.js';

function createFixture(tree, baseDir) {
for (const [name, content] of Object.entries(tree)) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/tests/skill-group-expander.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';

const { expandSkillGroups } = require('../skill-generator.js');
import { expandSkillGroups } from '../skill-generator.js';

function createFixture(tree, baseDir) {
for (const [name, content] of Object.entries(tree)) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/tests/skill-template-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';

const { loadSkillTemplate } = require('../skill-generator.js');
import { loadSkillTemplate } from '../skill-generator.js';

function createFixture(tree, baseDir) {
for (const [name, content] of Object.entries(tree)) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/ignore-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ const ignoreBlockPlugin = {
},
};

module.exports = ignoreBlockPlugin;
export default ignoreBlockPlugin;
2 changes: 1 addition & 1 deletion scripts/plugins/ignore-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ const ignoreFilePlugin = {
},
};

module.exports = ignoreFilePlugin;
export default ignoreFilePlugin;
2 changes: 1 addition & 1 deletion scripts/plugins/ignore-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ const ignoreLinePlugin = {
},
};

module.exports = ignoreLinePlugin;
export default ignoreLinePlugin;
8 changes: 4 additions & 4 deletions scripts/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Plugin system for content transformation
*/

const ignoreLinePlugin = require('./ignore-line');
const ignoreFilePlugin = require('./ignore-file');
const ignoreBlockPlugin = require('./ignore-block');
import ignoreLinePlugin from './ignore-line.js';
import ignoreFilePlugin from './ignore-file.js';
import ignoreBlockPlugin from './ignore-block.js';

/**
* Compose multiple plugins into a single transformation function
Expand Down Expand Up @@ -33,7 +33,7 @@ function composePlugins(plugins = []) {
};
}

module.exports = {
export {
composePlugins,
ignoreLinePlugin,
ignoreFilePlugin,
Expand Down
Loading