@pi-unipi/core
v0.1.16
Published
Shared utilities, event types, and constants for Unipi extension suite
Maintainers
Readme
@pi-unipi/core
Shared infrastructure for every Unipi package. Provides constants, event types, and utility functions so packages can discover each other without tight coupling.
Other packages import from @pi-unipi/core to emit events, read module names, and use common file operations. Without it, each package would need its own event definitions and utilities.
Usage
import { UNIPI_EVENTS, MODULES, sanitize, emitEvent } from "@pi-unipi/core";
// Emit module ready event
emitEvent(pi, UNIPI_EVENTS.MODULE_READY, {
name: MODULES.WORKFLOW,
version: "1.0.0",
commands: ["brainstorm", "plan"],
tools: [],
});
// Use shared utilities
const safeName = sanitize("my/feature: branch");Exports
Constants
UNIPI_PREFIX— Command prefix (unipi:)MODULES— All module namesWORKFLOW_COMMANDS— Workflow command namesRALPH_COMMANDS— Ralph command namesRALPH_TOOLS— Ralph tool namesRALPH_DEFAULTS— Default ralph settingsRALPH_DIR— Ralph state directoryRALPH_COMPLETE_MARKER— Loop completion marker
Events
UNIPI_EVENTS— Event namesUnipiModuleEvent— Module ready/gone payloadUnipiWorkflowEvent— Workflow start/end payloadUnipiRalphLoopEvent— Ralph loop start/end payloadUnipiRalphIterationEvent— Ralph iteration payloadUnipiStatusRequestEvent/UnipiStatusResponseEvent— Status payloads
Utilities
sanitize(name)— Sanitize string for filenamesensureDir(path)— Create parent directoriestryDelete(path)— Safe file deletiontryRead(path)— Safe file readsafeMtimeMs(path)— File modification timetryRemoveDir(path)— Safe directory removalresolvePath(cwd, path)— Resolve relative/absolute pathsfileExists(path)— Check file existencewriteFile(path, content)— Write file with dir creationreadJson<T>(path)— Read JSON filewriteJson(path, data)— Write JSON filerandomId(length)— Generate random IDnow()— ISO timestampparseArgs(str)— Parse quoted argumentsgetPackageVersion(dir)— Read package versionisModuleAvailable(cwd, name)— Check if npm module existsemitEvent(pi, name, payload)— Safe event emission
How Packages Use Core
Every Unipi package depends on @pi-unipi/core. On load, each package:
- Imports
MODULESto register its own name - Imports
UNIPI_EVENTSto subscribe to lifecycle events - Calls
emitEvent(pi, UNIPI_EVENTS.MODULE_READY, ...)to announce itself - Uses utility functions for file I/O and path resolution
This creates a loose coupling — packages discover each other through events, not direct imports.
Configuration
Core has no configuration. It's a pure utility layer.
License
MIT
