Menu

Development Workflow

Relevant source files

Purpose and Scope

This document describes the development workflow for Prompt Optimizer, including environment setup, build processes, development commands, and testing procedures. It focuses on the practical aspects of working with the monorepo structure and building the various platform targets.

For information about the overall project structure and package organization, see Project Structure and Packages. For deployment procedures, see Deployment and Operations.


Prerequisites and Environment Setup

Required Tools

ToolVersion RequirementPurpose
Node.js^18.0.0 || ^20.0.0 || ^22.0.0Runtime environment
pnpm10.6.1Package manager (enforced)
TypeScript^5.8.2Type checking and compilation

The project enforces pnpm as the package manager through the packageManager field and engine constraints that reject npm and yarn with Chinese error messages.

Sources: package.json5-10

Initial Setup

The pnpm install command triggers workspace dependency resolution across all packages defined in pnpm-workspace.yaml.

Sources: package.json34


Monorepo Package Dependency Graph

The project uses pnpm workspaces to manage a monorepo with six packages. Build order matters due to inter-package dependencies.

Dependency Chain:

  1. core has no dependencies on other workspace packages
  2. ui depends on core (workspace:*)
  3. web and extension depend on ui (workspace:*)
  4. desktop copies the built web package
  5. mcp-server depends on core but builds independently

Sources: package.json12-19 packages/core/package.json2 packages/ui/package.json2-32 packages/desktop/package.json24


Build Commands

Root-Level Build Scripts

CommandDescriptionScript Chain
pnpm run buildFull production buildbuild:corebuild:uibuild:parallel
pnpm run build:coreBuild core package onlypnpm -F @prompt-optimizer/core build
pnpm run build:uiBuild UI package onlypnpm -F @prompt-optimizer/ui build
pnpm run build:parallelBuild web and extension in parallelUses npm-run-all --parallel
pnpm run build:webBuild web applicationpnpm -F @prompt-optimizer/web build
pnpm run build:extBuild browser extensionpnpm -F @prompt-optimizer/extension build
pnpm run build:desktopFull desktop buildbuild:corebuild:uibuild:webbuild:desktop-only
pnpm run mcp:buildBuild MCP serverpnpm --filter @prompt-optimizer/mcp-server build

The desktop build has a special process that copies web artifacts:

Sources: package.json12-42 packages/desktop/package.json11-12


Development Commands

Development Server Workflows

The project provides multiple development workflows optimized for different scenarios:

CommandUse CaseParallel Processes
pnpm run devWeb application developmentUI watch mode + Web dev server
pnpm run dev:freshClean start web developmentRuns cleanpnpm-installdev
pnpm run dev:extExtension developmentSingle process: extension dev mode
pnpm run dev:desktopElectron app developmentWeb dev server + Electron dev mode
pnpm run dev:desktop:freshClean start desktop developmentRuns cleanpnpm-installdev:desktop
pnpm run mcp:devMCP server developmentSingle process: MCP server in dev mode

Concurrent Development Processes

The development commands use concurrently with the -k flag (kill all on first exit) and custom prefixes:

Web Development:

Desktop Development:

The UI package builds in watch mode, detecting changes and rebuilding automatically. The web/desktop packages run Vite dev servers with hot module replacement (HMR).

Sources: package.json20-26 packages/ui/package.json24


Package-Specific Build Configuration

Core Package Build (tsup)

The core package uses tsup for fast TypeScript bundling:

Export Configuration:

This dual-format output enables compatibility with both ESM and CommonJS consumers.

Sources: packages/core/package.json9-18

UI Package Build (Vite Library Mode)

The UI package builds Vue components and exports them as a library:

Export Configuration:

The CSS export allows consuming applications to import styles separately.

Sources: packages/ui/package.json6-25

Desktop Package Build Process

The desktop package has a unique two-stage build:

Key Points:

  1. The web application is built with --base=./ for relative path resolution
  2. A Node.js inline script copies packages/web/dist/ to packages/desktop/web-dist/
  3. electron-builder packages the Electron main/preload scripts with the copied web files
  4. Multi-platform artifacts are generated based on the build.win, build.mac, build.linux configuration

Sources: packages/desktop/package.json11-89


Testing Strategy

Test Framework Configuration

Test Commands

CommandScopeDescription
pnpm testAll packagesRuns pnpm -r test --run --passWithNoTests
pnpm test:e2eRootExecutes Playwright E2E tests
pnpm test:e2e:uiRootOpens Playwright UI mode
pnpm test:e2e:debugRootRuns Playwright in debug mode
pnpm --filter @prompt-optimizer/core testCore packageRuns vitest in core package
pnpm --filter @prompt-optimizer/core test:watchCore packageRuns vitest in watch mode
pnpm --filter @prompt-optimizer/core test:unitCore packageRuns only unit tests
pnpm --filter @prompt-optimizer/core test:integrationCore packageRuns only integration tests

The -r flag in the root test command runs tests recursively across all workspace packages that have a test script defined.

Sources: package.json27-30 packages/core/package.json19-23

Test Organization in Core Package

The core package separates unit and integration tests:

packages/core/tests/ ├── unit/ # Fast, isolated tests └── integration/ # Tests requiring external services 

This separation allows running fast unit tests during development and slower integration tests in CI.

Sources: packages/core/package.json22-23


Cleaning and Maintenance

Clean Commands

CommandTargetDescription
pnpm run cleanAllRuns clean:dist and clean:vite
pnpm run clean:distBuild outputsRemoves dist/ from all packages and web-dist/ from desktop
pnpm run clean:viteVite cacheRemoves .vite/ cache directories from all packages

Cleaned Directories:

  • packages/core/dist
  • packages/ui/dist
  • packages/web/dist
  • packages/extension/dist
  • packages/desktop/dist
  • packages/desktop/web-dist
  • packages/*/node_modules/.vite

The clean:dist command uses rimraf for cross-platform directory removal.

Sources: package.json31-33


Version Management

Version Synchronization

The project uses a custom version synchronization script to keep all package versions aligned:

Version Workflow:

The version script in package.json has a hook that automatically runs version:sync and stages changes:

Sources: package.json35-39


Common Development Workflows

Starting Fresh Development

Working on Core Services

Testing a Specific Package

Building for Production

Extension Development

Sources: package.json20-26 packages/extension/public/manifest.json1-34


Linting and Code Quality

Linting Commands

The linting configuration uses:

  • eslint with TypeScript support (@typescript-eslint/parser, @typescript-eslint/eslint-plugin)
  • Vue plugin (eslint-plugin-vue)
  • Custom .eslintrc.json configuration in the UI package

Sources: package.json44-45 packages/ui/package.json28-50


Package Manager Enforcement

The project strictly enforces pnpm through multiple mechanisms:

Engine Constraints

Package Manager Field

This field enables Corepack (Node.js 16.9+) to automatically use the correct pnpm version.

PNPM-Specific Configuration

The onlyBuiltDependencies optimization prevents unnecessary native module rebuilds for packages other than Electron.

Sources: package.json5-95