/** * trajectory-tree.ts — Execution-state-tree retrieval PROTOTYPE (MAGE-style). * * Research basis: MAGE (arXiv 2606.06090) observes that semantic-similarity * retrieval fragments decision trajectories on long-horizon tasks; retrieving * by POSITION in a hierarchical execution-state tree (the root→current path) * preserves coherence. This module mirrors ruflo's existing trajectory * recording (hooks_intelligence_trajectory-start/step/end) into such a tree * and offers position-based recall — NO embedding search anywhere. * * Structure: * session root ─ trajectory ─ step * └ trajectory (nested: a start while another is open * opens UNDER the open one) ─ step … * * - `trajectory-start` opens a node under the deepest open trajectory of the * session (or the session root). * - `trajectory-step` appends a step child; the step becomes the "current" * position of the session. * - `trajectory-end` closes the node; current returns to its parent. * - `recallPath({sessionId, depth})` returns the root→current path (the * MAGE-style working context) plus the most recent siblings of the current * node. * * PROTOTYPE LIMITATIONS (deliberate — see the feature spec): * - Persistence is a single best-effort JSON snapshot at * `.claude-flow/intelligence/trajectory-tree.json`, written on every * mutation. It sits ALONGSIDE the existing 'trajectories' memory-namespace * persistence; nothing is migrated and the semantic path is untouched. * - No concurrency control: two MCP server processes sharing a cwd will * last-writer-win the snapshot. * - No pruning/compaction: long-lived sessions grow the file unboundedly * (labels are truncated to 200 chars to bound row size, not row count). * - sessionId defaults to CLAUDE_FLOW_SESSION_ID or 'default'; hosts that * never set it collapse into one tree. * - Retrieval is position-only by design; hybrid position+semantic ranking * is future work. * * @module ruvector/trajectory-tree */ export type TreeNodeKind = 'session' | 'trajectory' | 'step'; export interface TreeNode { id: string; kind: TreeNodeKind; /** Task text (trajectory), action text (step), or session id — ≤200 chars. */ label: string; parentId: string | null; childIds: string[]; status: 'open' | 'closed'; openedAt: string; closedAt?: string; meta?: Record; } export interface RecallResult { sessionId: string; /** Root→current node path (the MAGE-style working context). */ path: TreeNode[]; /** Most recent siblings of the current node (excluding it), oldest→newest. */ siblings: TreeNode[]; /** Id of the current node (deepest position in the session). */ currentId: string | null; strategy: 'state-tree'; } export declare class TrajectoryTree { private nodes; /** sessionId → id of the deepest "current" node (step or open trajectory). */ private currentBySession; /** trajectoryId → sessionId, so step/end calls can omit the session. */ private trajectorySession; private readonly persistPath; constructor(persistPath?: string); private sessionRootId; private ensureSession; /** Deepest OPEN trajectory node on the current path of a session, if any. */ private deepestOpenTrajectory; openTrajectory(args: { sessionId: string; trajectoryId: string; task: string; agent?: string; }): TreeNode; appendStep(args: { trajectoryId: string; stepId: string; action: string; quality?: number; }): TreeNode | null; closeTrajectory(args: { trajectoryId: string; success?: boolean; }): TreeNode | null; /** * MAGE-style positional recall: the exact root→current path for a session, * plus the most recent siblings of the current node for local context. * * @param depth Max number of path nodes returned, counted from the CURRENT * node upward (deepest levels win). Default: full path. * @param siblingWindow Max recent siblings of the current node. Default 3. */ recallPath(args: { sessionId: string; depth?: number; siblingWindow?: number; }): RecallResult; get size(): number; private load; private save; } export declare function getTrajectoryTree(persistPath?: string): TrajectoryTree; /** Test/reset hook — drops the singleton so the next get() reloads from disk. */ export declare function resetTrajectoryTree(): void; export default TrajectoryTree; //# sourceMappingURL=trajectory-tree.d.ts.map