npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@promptforgee/optimizer

v0.1.4

Published

PromptForge optimizer package

Downloads

469

Readme


Why this package exists

As prompts grow in complexity, they often accumulate filler words, redundant context, and weak constraints. This inflates token costs and can confuse LLMs, degrading output quality.

@promptforgee/optimizer takes a @promptforgee/core Prompt instance and returns a highly optimized equivalent. It trims the fat, deduplicates information, and transforms passive constraints into strict directives, ensuring your prompts are as lean and effective as possible.

Features

  • Token Reduction: Strips out filler words ("please", "can you", etc.) without losing intent.
  • Deduplication: Merges identical or highly similar context blocks and constraints.
  • Constraint Strengthening: Converts weak language ("try to avoid") into strict imperatives ("DO NOT").
  • Seamless Integration: Operates directly on Prompt instances from @promptforgee/core.

Installation

# npm
npm install @promptforgee/optimizer

# pnpm
pnpm add @promptforgee/optimizer

# yarn
yarn add @promptforgee/optimizer

# bun
bun add @promptforgee/optimizer

Quick Start

import { Prompt, MarkdownFormatter } from '@promptforgee/core';
import { optimizePrompt } from '@promptforgee/optimizer';

async function main() {
  // A poorly constructed, verbose prompt
  const messyPrompt = Prompt.create()
    .task('Can you please write a function to sort an array for me?')
    .constraint('Try to avoid using O(n^2) time complexity if you can.')
    .constraint("Please don't use O(n^2) time.") // Redundant
    .context('The array contains numbers.')
    .context('The array contains numbers.'); // Redundant

  console.log('--- Before Optimization ---');
  console.log(messyPrompt.build(new MarkdownFormatter()));

  // Optimize the prompt
  const optimizedPrompt = await optimizePrompt(messyPrompt);

  console.log('\n--- After Optimization ---');
  console.log(optimizedPrompt.build(new MarkdownFormatter()));
}

main();

API Overview

optimizePrompt(prompt: Prompt): Promise<Prompt>

The primary exported function. Accepts a Prompt instance and returns a new, optimized Prompt instance.

HeuristicOptimizer

The underlying optimizer class. Currently utilizes heuristic rules (Regex, deduplication logic) to clean the prompt state.

| Method | Description | | --------------------------- | --------------------------------------- | | .optimize(prompt: Prompt) | Returns an optimized Prompt instance. |

Real-world Example

Building a self-healing prompt pipeline where generated prompts are automatically cleaned before execution:

import { Prompt } from '@promptforgee/core';
import { optimizePrompt } from '@promptforgee/optimizer';

// User-provided inputs are often messy
function createQueryPrompt(userTask: string, extraContext: string[]) {
  const basePrompt = Prompt.create().task(userTask);

  extraContext.forEach((ctx) => basePrompt.context(ctx));

  // Clean up user messiness automatically
  return optimizePrompt(basePrompt);
}

Ecosystem

@promptforgee/optimizer is the refinement step in the PromptForge lifecycle.

@promptforgee/core (Builds the prompt) ↓ @promptforgee/analyzer (Analyzes the prompt) ↓ @promptforgee/optimizer (You are here) ↓ @promptforgee/registry (Stores the optimized prompt)

Documentation

For full documentation and advanced usage, visit promptforge.dev/docs/optimizer.

Examples

Check out our Examples directory for more real-world use cases.

Roadmap

  • 🚧 LLM-backed optimization engine for deep semantic deduplication.
  • 🚧 Configuration options to tune optimization aggressiveness.

Contributing

We welcome contributions! Please read our Contributing Guide to get started.

License

MIT © Omnikon-Org