diff --git a/.gitignore b/.gitignore index 3017d8f..9e9d696 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ node_modules dist build packages/cli-js/templates +packages/cli-js/core npm-debug.log # python diff --git a/packages/cli-js/package.json b/packages/cli-js/package.json index b051c14..6dfdbcd 100644 --- a/packages/cli-js/package.json +++ b/packages/cli-js/package.json @@ -14,20 +14,19 @@ "publishConfig": { "access": "public" }, - "files": ["dist", "templates", "README.md"], + "files": ["dist", "templates", "core", "README.md"], "bin": { "planforge": "dist/index.js" }, "scripts": { "check:templates": "node scripts/check-templates.js", - "build": "pnpm run check:templates && tsc && node scripts/copy-templates.js", + "build": "pnpm run check:templates && tsc && node scripts/copy-templates.js && node scripts/copy-core.js", "dev": "tsc --watch", "planforge": "node dist/index.js", "install:global": "pnpm run build && npm install -g .", "prepublishOnly": "pnpm run build" }, "dependencies": { - "@planforge/core": "file:../core", "@daun_jung/korean-romanizer": "^1.0.1", "commander": "^12.0.0", "fs-extra": "^11.2.0" diff --git a/packages/cli-js/pnpm-lock.yaml b/packages/cli-js/pnpm-lock.yaml index f777fb8..1f147ef 100644 --- a/packages/cli-js/pnpm-lock.yaml +++ b/packages/cli-js/pnpm-lock.yaml @@ -11,9 +11,6 @@ importers: '@daun_jung/korean-romanizer': specifier: ^1.0.1 version: 1.0.1 - '@planforge/core': - specifier: file:../core - version: file:../core commander: specifier: ^12.0.0 version: 12.1.0 @@ -37,9 +34,6 @@ packages: resolution: {integrity: sha512-V5eY5iB3kUt6u9uYcjilra9vkJ8cIdJpDYSNeaX9dle1qPPYqis+XrOn+Zf/+FsbxOLAL9WqMmkJEDwNOd+0OQ==} engines: {node: '>=14.0.0'} - '@planforge/core@file:../core': - resolution: {directory: ../core, type: directory} - '@types/fs-extra@11.0.4': resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==} @@ -79,8 +73,6 @@ snapshots: '@daun_jung/korean-romanizer@1.0.1': {} - '@planforge/core@file:../core': {} - '@types/fs-extra@11.0.4': dependencies: '@types/jsonfile': 6.1.4 diff --git a/packages/cli-js/scripts/copy-core.js b/packages/cli-js/scripts/copy-core.js new file mode 100644 index 0000000..1e84602 --- /dev/null +++ b/packages/cli-js/scripts/copy-core.js @@ -0,0 +1,23 @@ +/** + * Copy @planforge/core content (prompts, models.json) into packages/cli-js/core so the published npm package contains them. + * Run from packages/cli-js (e.g. node scripts/copy-core.js). + */ +import { cpSync, mkdirSync, existsSync } from "fs"; +import { resolve, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const repoRoot = resolve(__dirname, "..", "..", ".."); +const corePkg = resolve(repoRoot, "packages", "core"); +const dest = resolve(__dirname, "..", "core"); +const promptsSrc = resolve(corePkg, "prompts"); +const modelsSrc = resolve(corePkg, "models.json"); + +if (!existsSync(promptsSrc) || !existsSync(modelsSrc)) { + console.error("copy-core: packages/core/prompts or models.json not found"); + process.exit(1); +} +mkdirSync(dest, { recursive: true }); +cpSync(promptsSrc, resolve(dest, "prompts"), { recursive: true }); +cpSync(modelsSrc, resolve(dest, "models.json")); +console.log("copy-core: copied core to", dest); diff --git a/packages/cli-js/src/commands/model.ts b/packages/cli-js/src/commands/model.ts index 30f57bb..1023db6 100644 --- a/packages/cli-js/src/commands/model.ts +++ b/packages/cli-js/src/commands/model.ts @@ -32,7 +32,7 @@ export function loadModelsCatalog(): ModelsCatalog { const filePath = existsSync(path) ? path : existsSync(fallback) ? fallback : null; if (!filePath) { throw new Error( - `models.json not found. Tried: ${path} and ${fallback}. Check @planforge/core package or run from repo root.` + `models.json not found. Tried: ${path} and ${fallback}. Run pnpm run build in cli-js or reinstall planforge.` ); } return fs.readJsonSync(filePath) as ModelsCatalog; diff --git a/packages/cli-js/src/utils/paths.ts b/packages/cli-js/src/utils/paths.ts index 85aae43..a18b57f 100644 --- a/packages/cli-js/src/utils/paths.ts +++ b/packages/cli-js/src/utils/paths.ts @@ -5,10 +5,8 @@ import { existsSync } from "fs"; import { resolve, dirname } from "path"; import { fileURLToPath } from "url"; -import { createRequire } from "module"; const __dirname = dirname(fileURLToPath(import.meta.url)); -const require = createRequire(import.meta.url); /** * Find project root by walking up from cwd until we find planforge.json or .cursor/plans or .cursor/contexts. @@ -71,19 +69,22 @@ export function getTemplatesRoot(): string { } /** - * Resolve prompts directory from @planforge/core package (for planner/implementer system prompts). + * Resolve core root (prompts, models.json). Always uses the bundled copy at package root; no @planforge/core dependency. + */ +function getCoreRoot(): string { + return resolve(__dirname, "..", "..", "core"); +} + +/** + * Resolve prompts directory (planner/implementer system prompts). Uses bundled core from build. */ export function getPromptsDir(): string { - const corePackageJson = require.resolve("@planforge/core/package.json"); - const coreRoot = dirname(corePackageJson); - return resolve(coreRoot, "prompts"); + return resolve(getCoreRoot(), "prompts"); } /** - * Resolve models.json path from @planforge/core package (for planforge model command). + * Resolve models.json path (planforge model command). Uses bundled core from build. */ export function getModelsJsonPath(): string { - const corePackageJson = require.resolve("@planforge/core/package.json"); - const coreRoot = dirname(corePackageJson); - return resolve(coreRoot, "models.json"); + return resolve(getCoreRoot(), "models.json"); }