← Catalog

@alexleekt/pi-shared

The glue that holds the monorepo together. Shared types and utilities for Pi extensions.

Extension

Install

Install with PiG

pig install npm:@alexleekt/pi-shared

Install with Pi

pi install npm:@alexleekt/pi-shared
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "skills": [
    "skills/prompt-eval"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.3 (README.md). PiG does not review it.

@alexleekt/pi-shared

npm License: MIT

The glue that holds the monorepo together.

Shared types and utilities for Pi extensions in this monorepo.

Exports

PathDescription
@alexleekt/pi-shared/sessionmanageSessionSubscription() — per-session subscription lifecycle helper
@alexleekt/pi-shared/typesShared Pi extension type definitions
@alexleekt/pi-shared/prompt-evalGeneralized prompt evaluation framework

@alexleekt/pi-shared/prompt-eval

A reusable framework for evaluating LLM prompts against test cases. Extracted from pi-heading's duplicated prompt-eval-*.ts scripts.

Core types

export interface EvalSuite<T extends TestCase = TestCase> {
  name: string;
  testCases: T[];
  promptBuilder: (testCase: T) => PromptMessage;   // { system, user, maxTokens }
  extractMode: "json" | "raw";
  scorers: Scorer<T>[];
  modelConfig?: ModelConfig;
}

export type Scorer<T extends TestCase = TestCase> = (params: {
  text: string;      // extracted result
  raw: string;       // raw LLM output
  testCase: T;
}) => ScoreResult;

Key functions

FunctionPurpose
runSuite(suite, model)Evaluate all test cases, score outputs, print progress
generateReport(results, suite, model)Build markdown report string
callLLM(system, user, model, config?)Call local proxy with retry
extractResult(raw)Parse {"result": "..."} or fall back to raw
optimizeSuite(factory, promptPath, config)Iterative prompt optimization loop

Built-in scorers

scorers.wordCount(max)
scorers.withinLimit(max)
scorers.noMetaCommentary()
scorers.noQuotes()
scorers.noMarkdown()
scorers.validJson()
scorers.presentContinuous()
scorers.pastTense()
scorers.noTrailingPeriod()
scorers.concise(threshold)
scorers.alignsWithExpected(field, threshold)
scorers.echoesGoal(goalField, threshold)
scorers.specificConcrete()
scorers.noVagueFiller()

Iterative optimization

import { optimizeSuite } from "@alexleekt/pi-shared/prompt-eval";

const result = await optimizeSuite(
  (promptText) => mySuiteFactory(promptText),   // factory builds EvalSuite from prompt text
  "/path/to/prompt.md",                         // file to mutate in-place
  {
    desirableOutcome: "Concise past-tense summaries under 12 words, no meta-commentary",
    targetPassRate: 85,
    maxIterations: 5,
    evalModel: "firepass",
    criticModel: "firepass",
  }
);

The optimization loop:

  1. Load prompt from file
  2. Run suite → check pass rate
  3. If below target, collect top N failing cases
  4. Call critic LLM with failures + desirable outcome description
  5. Write revised prompt back to file
  6. Repeat until target met or max iterations

License

MIT