@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
100 lines (99 loc) • 3.64 kB
TypeScript
import { type DreamCounts, type DreamDrop, type DreamMode, type DreamOutcome } from "./apply.js";
import { type CollectOptions } from "./collect.js";
import { type DreamPhase } from "./prompt.js";
import type { DreamChange, DreamChangeset } from "./types.js";
export interface DreamConfig {
enabled: boolean;
mode: DreamMode;
cadence: "nightly" | "idle" | "weekly" | "manual";
window: string;
idleMinutes: number;
lookbackHours: number;
maxChanges: number;
injectBudgetKB: number;
phases: DreamPhase[];
model: string;
}
export declare const DREAM_CONFIG_DEFAULTS: DreamConfig;
/** Coerce raw values (from the `dreaming` config domain or a caller) onto the defaults; anything malformed falls back. */
export declare function normalizeDreamConfig(raw: Record<string, unknown>): DreamConfig;
/** The project's resolved `dreaming.*` settings (defaults → global → project), via the shared config resolver. */
export declare function readDreamConfig(phrenPath: string, project: string): DreamConfig;
/** The JSON object in a model reply, tolerating a code fence or stray prose around it. */
export declare function parseChangesetJson(output: string): {
ok: true;
value: {
changes: unknown[];
notes: string;
};
} | {
ok: false;
error: string;
};
export interface ValidationContext {
fids: Set<string>;
truths: string[];
topics: Set<string>;
phases: DreamPhase[];
maxChanges: number;
mode?: DreamMode;
}
/** Keep the well-formed, allowed, evidenced changes up to maxChanges; say why each other one was dropped. */
export declare function validateChanges(rawChanges: unknown[], ctx: ValidationContext): {
changes: DreamChange[];
dropped: DreamDrop[];
};
export interface DreamRunnerRequest {
prompt: string;
cwd: string;
model?: string;
timeoutSeconds: number;
signal?: AbortSignal;
}
export interface DreamRunnerResult {
ok: boolean;
output: string;
model?: string;
costUSD?: number;
durationMs?: number;
}
/** Runs the model once. The default is the project's helper (`claude -p`, read-only). */
export type DreamRunner = (request: DreamRunnerRequest, project: string, phrenPath: string) => Promise<DreamRunnerResult>;
export type DreamStatus = "ok" | "disabled" | "busy" | "empty" | "failed";
export interface DreamOptions {
trigger?: "manual" | "scheduled";
dryRun?: boolean;
mode?: DreamMode;
now?: Date;
/** Run even when dreaming is disabled, or when nothing happened in the window (a manual `--force`). */
force?: boolean;
phrenPath?: string;
runner?: DreamRunner;
/** Overrides on the resolved config (tests, CLI flags). */
config?: Partial<DreamConfig>;
/** Overrides on collection (tests: transcript roots, project folders, git). */
collect?: Partial<Omit<CollectOptions, "from" | "to">>;
timeoutSeconds?: number;
signal?: AbortSignal;
}
export interface DreamResult {
status: DreamStatus;
project: string;
mode: DreamMode;
dryRun: boolean;
runId?: string;
message: string;
warnings?: string[];
changeset?: DreamChangeset;
outcomes: DreamOutcome[];
dropped: DreamDrop[];
counts?: DreamCounts;
/** dreams/<runId>.json, when recorded. */
record?: string;
model?: string;
costUSD?: number;
}
export declare const defaultDreamRunner: DreamRunner;
export declare function newRunId(now: Date): string;
export declare function dreamLockPath(phrenPath: string, project: string): string;
export declare function dream(project: string, opts?: DreamOptions): Promise<DreamResult>;