Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Stop the CLI build from sharing the server package's dist (#4756)
Nick Gomezc9fe8ab39b39
diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex 7b2e9e181..2c8704999 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -42,7 +42,7 @@"scripts": {"build:cli": "rm -rf dist && tsdown","build:app": "cp -r ../app/dist dist/public",- "build:skill-asset": "tsx ../server/scripts/build-skill-bundles.ts && mkdir -p dist/assets/skills && cp -R ../server/dist/assets/skills/. dist/assets/skills/",+ "build:skill-asset": "tsx scripts/build-skill-assets.ts","build:notices": "mkdir -p dist && cp ../../THIRD_PARTY_NOTICES.md dist/THIRD_PARTY_NOTICES.md","build:license": "mkdir -p dist && cp ../../LICENSE dist/LICENSE","build:native": "mkdir -p dist/native && cp ../native-config/index.js ../native-config/index.d.ts ../native-config/package.json dist/native/ && (cp ../native-config/*.node dist/native/ 2>/dev/null || true)",diff --git a/packages/cli/scripts/build-skill-assets.test.ts b/packages/cli/scripts/build-skill-assets.test.tsnew file mode 100644index 000000000..b28669730--- /dev/null+++ b/packages/cli/scripts/build-skill-assets.test.ts@@ -0,0 +1,109 @@+import {+ cpSync,+ existsSync,+ mkdirSync,+ mkdtempSync,+ readdirSync,+ readFileSync,+ rmSync,+} from 'node:fs';+import { tmpdir } from 'node:os';+import { dirname, join, sep } from 'node:path';+import { fileURLToPath } from 'node:url';+import { BUNDLE_IDS } from '@inkeep/open-knowledge-server';+import { afterAll, beforeAll, describe, expect, it } from 'vitest';+import { composeSkillAssets, resolveSkillAssetPaths } from './build-skill-assets.ts';++const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');+const SERVER_ROOT = join(PACKAGE_ROOT, '..', 'server');+const SOURCE_SKILLS = join(SERVER_ROOT, 'assets', 'skills');+const SOURCE_PACKS = join(SOURCE_SKILLS, 'packs');+const SHIPPED_SKILLS = join(PACKAGE_ROOT, 'dist', 'assets', 'skills');+const DECOMPOSED_MEMBER = join('packs', 'software-lifecycle', 'write-a-spec', 'SKILL.md');++let scratchServerRoot: string;+let scratchCliRoot: string;+let scratchSkills: string;+let scratchRoot: string;++function sourcePackIds(): string[] {+ return readdirSync(SOURCE_PACKS, { withFileTypes: true })+ .filter((entry) => entry.isDirectory())+ .map((entry) => entry.name)+ .sort();+}++beforeAll(() => {+ scratchRoot = mkdtempSync(join(tmpdir(), 'ok-cli-skill-assets-'));+ scratchServerRoot = join(scratchRoot, 'server');+ scratchCliRoot = join(scratchRoot, 'cli');+ scratchSkills = join(scratchCliRoot, 'dist', 'assets', 'skills');+ mkdirSync(join(scratchServerRoot, 'assets'), { recursive: true });+ cpSync(SOURCE_SKILLS, join(scratchServerRoot, 'assets', 'skills'), { recursive: true });+ mkdirSync(scratchCliRoot, { recursive: true });+ composeSkillAssets(resolveSkillAssetPaths(scratchCliRoot));+});++afterAll(() => {+ if (scratchRoot) rmSync(scratchRoot, { recursive: true, force: true });+});++describe('composing skill assets for a cli package root', () => {+ it('writes every bundle under that package root', () => {+ for (const bundle of BUNDLE_IDS) {+ expect(existsSync(join(scratchSkills, bundle, 'SKILL.md'))).toBe(true);+ }+ });++ it('writes every source pack under that package root', () => {+ const packs = sourcePackIds();+ expect(packs.length).toBeGreaterThan(0);+ for (const pack of packs) {+ expect(existsSync(join(scratchSkills, 'packs', pack, 'SKILL.md'))).toBe(true);+ }+ });++ it('writes the decomposed member skills, not just the pack roots', () => {+ const member = join(scratchSkills, DECOMPOSED_MEMBER);+ expect(existsSync(member)).toBe(true);+ expect(readFileSync(member, 'utf-8').length).toBeGreaterThan(0);+ });++ it('never brings the server package dist into existence', () => {+ expect(existsSync(join(scratchSkills, 'discovery', 'SKILL.md'))).toBe(true);+ expect(existsSync(join(scratchServerRoot, 'dist'))).toBe(false);+ });+});++describe('the default skill-asset paths', () => {+ it('reads the server package source assets, never a dist tree', () => {+ const { skillsDir } = resolveSkillAssetPaths();+ expect(skillsDir).toBe(join(SERVER_ROOT, 'assets', 'skills'));+ expect(skillsDir.split(sep)).not.toContain('dist');+ });++ it('writes into the cli package dist', () => {+ expect(resolveSkillAssetPaths().distDir).toBe(SHIPPED_SKILLS);+ });+});++describe('the shipped build:skill-asset step', () => {+ it('runs the cli composer and nothing else', () => {+ const manifest = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf-8')) as {+ scripts: Record<string, string>;+ };+ expect(manifest.scripts['build:skill-asset']).toBe('tsx scripts/build-skill-assets.ts');+ });++ it('leaves every bundle, pack and decomposed member in the built cli dist', () => {+ for (const bundle of BUNDLE_IDS) {+ expect(existsSync(join(SHIPPED_SKILLS, bundle, 'SKILL.md'))).toBe(true);+ }+ const packs = sourcePackIds();+ expect(packs.length).toBeGreaterThan(0);+ for (const pack of packs) {+ expect(existsSync(join(SHIPPED_SKILLS, 'packs', pack, 'SKILL.md'))).toBe(true);+ }+ expect(existsSync(join(SHIPPED_SKILLS, DECOMPOSED_MEMBER))).toBe(true);+ });+});diff --git a/packages/cli/scripts/build-skill-assets.ts b/packages/cli/scripts/build-skill-assets.tsnew file mode 100644index 000000000..985b77b56--- /dev/null+++ b/packages/cli/scripts/build-skill-assets.ts@@ -0,0 +1,30 @@+#!/usr/bin/env -S npx tsx+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';+import {+ buildPackSkills,+ buildSkillBundles,+ type SkillBundlePaths,+} from '../../server/scripts/build-skill-bundles.ts';++const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');++export function resolveSkillAssetPaths(packageRoot: string = PACKAGE_ROOT): SkillBundlePaths {+ return {+ skillsDir: join(packageRoot, '..', 'server', 'assets', 'skills'),+ distDir: join(packageRoot, 'dist', 'assets', 'skills'),+ };+}++export function composeSkillAssets(paths: SkillBundlePaths): string[] {+ return [+ ...buildSkillBundles(paths).map((composed) => composed.bundle),+ ...buildPackSkills(paths),+ ];+}++if (import.meta.main) {+ const paths = resolveSkillAssetPaths();+ const built = composeSkillAssets(paths);+ console.log(`[build-skill-assets] composed ${built.length} skill asset(s) → ${paths.distDir}`);+}diff --git a/packages/cli/scripts/verify-package-surface.mjs b/packages/cli/scripts/verify-package-surface.mjsindex f485f458a..8b623cfa7 100644--- a/packages/cli/scripts/verify-package-surface.mjs+++ b/packages/cli/scripts/verify-package-surface.mjs@@ -11,6 +11,11 @@ export const REQUIRED_PACK_FILES = ['dist/THIRD_PARTY_NOTICES.md','dist/native/native-config.win32-x64-msvc.node','dist/native/native-config.win32-arm64-msvc.node',+ 'dist/assets/skills/discovery/SKILL.md',+ 'dist/assets/skills/project/SKILL.md',+ 'dist/assets/skills/write-skill/SKILL.md',+ 'dist/assets/skills/packs/knowledge-base/SKILL.md',+ 'dist/assets/skills/packs/software-lifecycle/write-a-spec/SKILL.md',];export const REQUIRED_KEYWORDS = ['knowledge-base', 'markdown', 'local-first', 'mcp', 'ai', 'cli'];diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.jsonindex 507e0efc9..7e0489e2c 100644--- a/packages/cli/tsconfig.json+++ b/packages/cli/tsconfig.json@@ -5,6 +5,6 @@"noEmit": true,"allowImportingTsExtensions": true},- "include": ["src", "*.ts"],+ "include": ["src", "scripts/build-skill-assets.ts", "*.ts"],"exclude": ["node_modules", "dist", "**/*.test.ts"]}diff --git a/packages/server/scripts/build-skill-bundles.ts b/packages/server/scripts/build-skill-bundles.tsindex 34d476ac4..14ca1a5a8 100644--- a/packages/server/scripts/build-skill-bundles.ts+++ b/packages/server/scripts/build-skill-bundles.ts@@ -107,6 +107,11 @@ interface ComposedBundle {readonly outputPath: string;}+/*+ * WARN: `packages/cli/scripts/build-skill-assets.ts` calls `buildSkillBundles`+ * and `buildPackSkills` by relative path and depends on both signatures, so a+ * change to either one has to land in that consumer in the same edit.+ *//*** Compose every bundle and write the result to `distDir/<bundle>/SKILL.md`.* Returns one entry per bundle. The dist tree is wiped + recreated so a