Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

12.8 KB
Raw Blame
export const LEDGER_DIR: string;
export const GOALS_STALE_MS: number;
export const AGENT_WRITTEN_PROMPTS_FILE: string;
export interface RefreshNeeds {
  due: number; ungrouped: number; goalsStale: boolean; unplaced: number; otherChanged: boolean;
  /** Kept areas whose set of placed requests changed since this computer last grouped them into sub focuses. */
  subFocusDue: number;
  /** Kept areas whose last sub focus pass failed on the requests they hold now. Not part of `needed`: no scheduled run asks
   * them again until their requests change; the owner's Refresh does. */
  subFocusFailed: number;
  needed: boolean;
}
export interface LedgerDatabase { prepare(sql: string): { all(...params: unknown[]): any[]; get(...params: unknown[]): any } }
export interface SavedGoal {
  /** The item's work-state task. */
  taskKey: string; kind: 'focus-area' | 'ask';
  /** Saved under an old kind (priority, open ask) before the three tests; the next refresh sorts it again. */
  legacy: boolean;
  rank: number | null; title: string;
  /** A focus area's one-sentence goal (the only meaning of goal). */
  goal: string | null;
  /** An ask's focus area by the name it was saved with. focusAreaId is that area's my-focus id, or a focus area's own. */
  focusArea: string | null; focusAreaId: string | null;
  latestAt: string | null; timesAsked: number | null; evidence: Array<{ at: string; quote: string }>;
}
export interface SavedGoals { summary: string | null; generatedAt: string | null; mapPath: string | null; goals: SavedGoal[] }
export function readGoals(database: LedgerDatabase): SavedGoals;
export function readConversationProjects(database: LedgerDatabase, conversationKeys: string[]): Map<string, string>;
export function groupIdFor(anchorConversationKey: string): string;
export function refreshNeeds(options: { dir?: string; database: LedgerDatabase; now?: number; days?: number; localDeviceId: string }): RefreshNeeds;
/** With a shared writer registered, it commits the shared records and puts the file in place under its write lock.
 * readHash: the hash of the file `value` was built from (readHashOf); the shared write refuses it when the file changed since. */
export function writeJsonAtomic(path: string, value: unknown, options?: { readHash?: string }): void;
export function readLedger(dir?: string): Record<string, any>;
/** The hash of a ledger file's bytes (sha256), or 'missing'. */
export function ledgerFileHash(path: string): string;
/** What a write built from this readLedger result passes as readHash for the ledger file `name`. */
export function readHashOf(ledger: Record<string, any>, name: string): string;
export function readCandidates(database: LedgerDatabase, options: { sinceEpoch?: number; conversationKeys?: string[] | null; fullAsks?: boolean; recentAsks?: boolean; excludedPromptIds?: Set<number> | null }): any[];
export function ledgerSignature(dir?: string): string;
/** The decisions `apply` takes, merged into `stored` with projects and first asks read from the database; not written. */
export function applyDecisions(stored: Record<string, any> | null, decisions: unknown, options: { database: LedgerDatabase; now?: number; excludedPromptIds?: Set<number> | null; enrichGroupIds?: string[] | null }): Record<string, any>;
/** A judge's mid-band pick waiting for the owner's Join / Not this (request-judge.mjs). */
export interface RequestSuggestion { conversationKey: string; requestId: string; requestTitle: string; confidence: number; evidence: string; judge: string; at: string | null }
export function openSuggestions(ledger: Record<string, any> | null | undefined): RequestSuggestion[];
export function groupingInput(ledger: Record<string, any>, database: LedgerDatabase, options: { sinceEpoch: number; limit?: number; skip?: Set<string> | null }): GroupingInput;
export function runCli(argv: string[], options?: {
  dir?: string; database?: LedgerDatabase | null; now?: number; print?: (value: any) => void;
  /** The worker's sync device id ('' when cloud sync never started); required by focus-input, record-focus, sub-focus-input, record-sub-focus and refresh-needs. */
  localDeviceId?: string;
  /** record-focus and record-sub-focus: write the checked answer through the worker; throw a TypeError when refused before writing. */
  saveFocus?: ((body: import('./my-focus.mjs').RouterFocusBody) => { placed: number; focusAreaIds: string[] } | Promise<{ placed: number; focusAreaIds: string[] }>) | null;
  /** `judge`: the Jev judge for the `judge` command (undefined: from the install's settings; null: code links only). That command answers with a promise. */
  judge?: import('./request-judge.mjs').RequestJudge | null;
  /** After one rejected automatic progress review, bound its generated fields instead of rejecting the same group again. */
  coerceProgress?: boolean;
}): void | Promise<void>;
export interface FocusRequestRecord {
  anchor: string; groupId: string; title: string; firstAsk: string | null; state: string | null; summary: string | null; repo: string | null;
  /** How many conversations the request holds, and each one's opening ask. */
  conversations: number; conversationAsks: string[];
}
type FocusAreaRecord = { focusAreaId: string; name: string; goal: string | null; about: string | null; status: string };
export interface FocusInput { areas: FocusAreaRecord[]; dismissed: FocusAreaRecord[]; requests: FocusRequestRecord[]; remaining: number }
export interface OtherInput { areas: FocusAreaRecord[]; dismissed: FocusAreaRecord[]; other: FocusRequestRecord[]; due: boolean }
export const GROUPING_BATCH: number;
export const FOCUS_BATCH: number;
export const TITLE_BATCH: number;
/** The title code gives a request it starts (the judge, a declined suggestion): the first sentence of its opening ask,
 * cut as grouping-input shows the ask, copied. */
export function placeholderTitleFromAsk(askText: string | null | undefined): string;
/** Whether a title copies the opening ask: its placeholder, or words the ask starts with. */
export function copiesOpeningAsk(title: string, askText: string | null | undefined): boolean;
/** Whether a request still shows a title copied from its opening ask. */
export function hasPlaceholderTitle(group: { title: string; anchorAsk?: { text?: string | null } | null }): boolean;
/** title-input: requests still titled with their placeholder, as the focus step reads them, one batch at a time. */
export function titleInput(ledger: Record<string, any>, database: LedgerDatabase, options?: { limit?: number }): { requests: FocusRequestRecord[]; remaining: number };
/** coerce: the refresh's one retry drops a refused title or an unnamed request instead of refusing the whole answer. */
export function validateTitleAnswer(answer: unknown, input: { requests: Array<Pick<FocusRequestRecord, 'groupId' | 'title' | 'firstAsk'>> }, options?: { coerce?: boolean }): { titles: Array<{ groupId: string; title: string }> };
export function focusBasis(ledger: Record<string, any>, groupId: string): string;
export function focusInput(ledger: Record<string, any>, focus: ReturnType<typeof import('./my-focus.mjs').buildFocusAreas>, localDeviceId: string, database: LedgerDatabase, options?: { limit?: number }): FocusInput;
export function otherInput(ledger: Record<string, any>, focus: ReturnType<typeof import('./my-focus.mjs').buildFocusAreas>, localDeviceId: string, database: LedgerDatabase): OtherInput;
export function validateFocusAnswer(answer: unknown, input: FocusInput | OtherInput, ledger: Record<string, any>, options?: { other?: boolean }): import('./my-focus.mjs').RouterFocusBody;
/** A request as the sub focus step reads it. */
export interface SubFocusRequestRecord { anchor: string; title: string; summary: string | null }
/** sub-focus-input --area: one kept area, its live sub focuses with their members, and the requests to decide now. */
export interface SubFocusInput {
  area: { focusAreaId: string; name: string; goal: string | null };
  subFocuses: Array<{ subFocusId: string; name: string; members: SubFocusRequestRecord[] }>;
  /** New to the area, left ungrouped last time, or the router's members of a sub focus left with too few requests. */
  requests: SubFocusRequestRecord[];
  /** The anchors of `requests` the router left ungrouped last time: leaving one ungrouped again writes nothing. */
  alreadyUngrouped: string[];
  passHash: string;
}
/** One kept area as sub-focus-input lists it, with how many placed requests it holds that My Work shows (shownGroupIds). */
export interface SubFocusAreaEntry { focusAreaId: string; name: string; requests: number }
/** sub-focus-input with no area: the kept areas to group now (`due`), and those whose last pass failed on the requests they
 * hold now (`failed`), which only the owner's Refresh asks again. */
export interface SubFocusAreaListing { due: SubFocusAreaEntry[]; failed: SubFocusAreaEntry[] }
/** The ledger requests My Work shows as cards, from sessions and prompts only: one with a conversation holding a human ask
 * once agent-written prompts are left out, or one whose anchor conversation is not recorded here (shown from its stored
 * first ask). Not My Work's whole rule: a request whose asking conversations all carry an explicit work-state request_id,
 * or whose stored root is unknown and whose only asking conversation is from another root, is counted here with no card
 * there; and shared-only sessions, shared exclusions and My Work's 12,000-prompt load limit can differ either way. */
export function shownGroupIds(ledger: Record<string, any>, database: LedgerDatabase): Set<string>;
/** Counts only the requests shownGroupIds holds, the requests a sub focus card counts. */
export function subFocusInput(ledger: Record<string, any>, focus: ReturnType<typeof import('./my-focus.mjs').buildFocusAreas>, focusAreaId: string, database: LedgerDatabase): SubFocusInput;
/** coerce: the refresh's one retry drops what would be refused (naming each new group it dropped in droppedNewGroups) and
 * leaves a left-out request ungrouped. recordPass false: an earlier part of a large area, which does not record the pass. */
export function validateSubFocusAnswer(answer: unknown, input: SubFocusInput, options?: { coerce?: boolean; recordPass?: boolean; droppedNewGroups?: Set<string> }): import('./my-focus.mjs').RouterFocusBody & { subFocus: import('./my-focus.mjs').RouterSubFocusBody };
export function subFocusAnswerCounts(body: import('./my-focus.mjs').RouterFocusBody): { grouped: number; ungrouped: number; newSubFocuses: number };
export interface GroupingInput {
  root: string | null;
  conversations: Array<{ conversationKey: string; project: string; startedAt: string | null; openingAsk: string | null; workLists: string[] }>;
  openRequests: Array<{ groupId: string; title: string; anchor: string; anchorAsk: string | null; recentAsks: string[]; lastActivityAt: string | null }>;
  proposedLinks: Array<{ kind: string; conversations: string[]; evidence: string; groups: string[] }>;
  remaining: number;
}
/** coerce: the refresh's one retry cuts what would be refused, naming each changed group or ignore entry in coercedFields. */
export function validateGroupingAnswer<T>(answer: T, input: GroupingInput, options?: { coerce?: boolean; coercedFields?: Set<string> }): T;
export interface StoryPreference { preference: string; kind: string; supportCount: number; quotes: Array<{ quote: string; at: string | null }> }
export interface ValidatedStory { narrative: string; preferences: StoryPreference[] }
export function validateStory(story: any): ValidatedStory;
export function trimStoryPreferences(story: any, coercedFields?: Set<string>, droppedPreferences?: Set<string>): any;
export interface StoryPart { part: string; chars: number; words: number; budgetChars: number; budgetWords: number; overBudgetChars: number }
export interface StoryInput {
  groups: number; update: boolean; narrativeTarget: number; narrativeLimit: number;
  previousNarrativeChars: number; roomChars: number; condenseChars: number;
  previousParts: StoryPart[]; mergeOldestChapters: number;
  reviews: any[];
  /** The words of each rule the owner rejected in My Rules: never proposed again, in any wording. */
  dismissedRules: string[];
  previousStory: (Record<string, any> & { narrative: string; preferences: any[] }) | null;
}
export function storyInput(groups: number, reviews: any[], story: (Record<string, any> & { narrative: string; preferences?: any[]; writtenAt?: string }) | null, dismissedRules: string[]): StoryInput;
/** The words of each rule the owner rejected in My Rules (a dismissed learned rule), as its saved row keeps them. */
export function dismissedRuleStatements(database: LedgerDatabase, options?: { localDeviceId?: string }): string[];
export function applyGroupDecisions(
  stored: Record<string, unknown>, decisions: { groups: Array<Record<string, unknown>>; ignored?: string[] },
  now?: number, options?: { projectOf?: Map<string, string>; getProjectRoot?: (project: unknown) => string | null },
): Record<string, unknown>;