@agent-relay/continuity 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Continuity Manager
3
+ *
4
+ * Central service for managing session continuity.
5
+ * Coordinates ledger storage, handoff creation, and context injection.
6
+ */
7
+ import { type ParsedHandoffContent } from './parser.js';
8
+ import type { Ledger, Handoff, HandoffTrigger, ContinuityPaths, StartupContext, SaveLedgerOptions, SearchOptions, ContinuityCommand } from './types.js';
9
+ /**
10
+ * Options for ContinuityManager
11
+ */
12
+ export interface ContinuityManagerOptions {
13
+ /** Base directory for continuity data (default: ~/.agent-relay/continuity) */
14
+ basePath?: string;
15
+ /** Default CLI type for new ledgers */
16
+ defaultCli?: string;
17
+ }
18
+ /**
19
+ * ContinuityManager - Central service for session continuity
20
+ */
21
+ export declare class ContinuityManager {
22
+ private paths;
23
+ private ledgerStore;
24
+ private handoffStore;
25
+ private defaultCli;
26
+ private initialized;
27
+ constructor(options?: ContinuityManagerOptions);
28
+ /**
29
+ * Initialize the continuity system (create directories)
30
+ */
31
+ initialize(): Promise<void>;
32
+ /**
33
+ * Generate a session ID
34
+ */
35
+ private generateSessionId;
36
+ /**
37
+ * Generate a unique agent ID using UUID v4
38
+ */
39
+ generateAgentId(): string;
40
+ /**
41
+ * Get or create a ledger for an agent
42
+ */
43
+ getOrCreateLedger(agentName: string, cli?: string, agentId?: string): Promise<Ledger>;
44
+ /**
45
+ * Find a ledger by agent ID (for resume functionality)
46
+ */
47
+ findLedgerByAgentId(agentId: string): Promise<Ledger | null>;
48
+ /**
49
+ * Get a ledger for an agent (returns null if not exists)
50
+ */
51
+ getLedger(agentName: string): Promise<Ledger | null>;
52
+ /**
53
+ * Save a ledger, optionally creating a handoff
54
+ */
55
+ saveLedger(agentName: string, content: string | Partial<Ledger>, options?: SaveLedgerOptions): Promise<Ledger>;
56
+ /**
57
+ * Update specific fields in a ledger
58
+ */
59
+ updateLedger(agentName: string, updates: Partial<Omit<Ledger, 'agentName' | 'updatedAt'>>): Promise<Ledger | null>;
60
+ /**
61
+ * Add an uncertain item to the ledger
62
+ */
63
+ addUncertainItem(agentName: string, item: string): Promise<boolean>;
64
+ /**
65
+ * Delete a ledger
66
+ */
67
+ deleteLedger(agentName: string): Promise<boolean>;
68
+ /**
69
+ * Create a handoff from a ledger
70
+ */
71
+ createHandoffFromLedger(ledger: Ledger, triggerReason: HandoffTrigger): Promise<Handoff>;
72
+ /**
73
+ * Create a handoff from parsed content
74
+ */
75
+ createHandoff(agentName: string, content: string | ParsedHandoffContent, triggerReason?: HandoffTrigger): Promise<Handoff>;
76
+ /**
77
+ * Get the latest handoff for an agent
78
+ */
79
+ getLatestHandoff(agentName: string): Promise<Handoff | null>;
80
+ /**
81
+ * Get a handoff by ID
82
+ */
83
+ getHandoff(handoffId: string): Promise<Handoff | null>;
84
+ /**
85
+ * List handoffs for an agent
86
+ */
87
+ listHandoffs(agentName: string, limit?: number): Promise<Handoff[]>;
88
+ /**
89
+ * Search handoffs (basic text search - FTS to be added)
90
+ */
91
+ searchHandoffs(query: string, options?: SearchOptions): Promise<Handoff[]>;
92
+ /**
93
+ * Get startup context for an agent (for injection on spawn).
94
+ * Applies defensive filtering to remove any placeholder values.
95
+ */
96
+ getStartupContext(agentName: string): Promise<StartupContext | null>;
97
+ /**
98
+ * Filter placeholder values from a ledger (defensive)
99
+ */
100
+ private filterLedgerPlaceholders;
101
+ /**
102
+ * Filter placeholder values from a handoff (defensive)
103
+ */
104
+ private filterHandoffPlaceholders;
105
+ /**
106
+ * Filter placeholder values from ledger updates (for object input to saveLedger).
107
+ * This ensures placeholder values like "...", "task1", etc. don't get saved.
108
+ */
109
+ private filterUpdatesPlaceholders;
110
+ /**
111
+ * Format a ledger for display/injection
112
+ */
113
+ formatLedger(ledger: Ledger, compact?: boolean): string;
114
+ /**
115
+ * Format a handoff for display/injection
116
+ */
117
+ formatHandoff(handoff: Handoff, compact?: boolean): string;
118
+ /**
119
+ * Format search results
120
+ */
121
+ formatSearchResults(handoffs: Handoff[], query: string): string;
122
+ /**
123
+ * Get a brief status summary
124
+ */
125
+ getBriefStatus(agentName: string): Promise<string>;
126
+ /**
127
+ * Handle a continuity command from agent output
128
+ */
129
+ handleCommand(agentName: string, command: ContinuityCommand): Promise<string | null>;
130
+ /**
131
+ * Auto-save current state (called by wrapper on agent exit)
132
+ * @param agentName - Name of the agent
133
+ * @param reason - Why the save is happening
134
+ * @param sessionEndData - Optional data from [[SESSION_END]] block to populate handoff
135
+ */
136
+ autoSave(agentName: string, reason: 'crash' | 'restart' | 'session_end', sessionEndData?: {
137
+ summary?: string;
138
+ completedTasks?: string[];
139
+ }): Promise<void>;
140
+ /**
141
+ * Clean placeholder data from all ledgers.
142
+ * Removes known placeholder/template values that were incorrectly saved.
143
+ * Returns the number of ledgers that were cleaned.
144
+ */
145
+ cleanupPlaceholders(): Promise<{
146
+ cleaned: number;
147
+ agents: string[];
148
+ }>;
149
+ /**
150
+ * Clear all continuity data for an agent
151
+ */
152
+ clearAgent(agentName: string): Promise<void>;
153
+ /**
154
+ * List all agents with continuity data
155
+ */
156
+ listAgents(): Promise<string[]>;
157
+ /**
158
+ * Get continuity paths
159
+ */
160
+ getPaths(): ContinuityPaths;
161
+ }
162
+ /**
163
+ * Get the singleton ContinuityManager instance (sync version)
164
+ *
165
+ * Note: This is safe for most uses since ContinuityManager methods
166
+ * call initialize() internally. The race condition only matters
167
+ * if multiple calls happen before the first completes AND they
168
+ * pass different options (which is unlikely in practice).
169
+ */
170
+ export declare function getContinuityManager(options?: ContinuityManagerOptions): ContinuityManager;
171
+ /**
172
+ * Get the singleton ContinuityManager instance (async version)
173
+ *
174
+ * This is the thread-safe version that ensures only one instance
175
+ * is created even with concurrent calls. Use this in async contexts
176
+ * where race conditions are possible.
177
+ */
178
+ export declare function getContinuityManagerAsync(options?: ContinuityManagerOptions): Promise<ContinuityManager>;
179
+ /**
180
+ * Reset the singleton instance (for testing)
181
+ */
182
+ export declare function resetContinuityManager(): void;
183
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EAKL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAQrB,OAAO,KAAK,EACV,MAAM,EACN,OAAO,EACP,cAAc,EACd,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,GAAE,wBAA6B;IAiBlD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAUjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,eAAe,IAAI,MAAM;IASzB;;OAEG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAe3F;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKlE;;OAEG;IACG,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAK1D;;OAEG;IACG,UAAU,CACd,SAAS,EAAE,MAAM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