@lumenflow/memory 2.10.0 → 2.11.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.
- package/package.json +2 -2
- package/dist/index.d.ts +0 -17
- package/dist/mem-checkpoint-core.d.ts +0 -91
- package/dist/mem-cleanup-core.d.ts +0 -202
- package/dist/mem-create-core.d.ts +0 -93
- package/dist/mem-export-core.d.ts +0 -33
- package/dist/mem-id.d.ts +0 -91
- package/dist/mem-init-core.d.ts +0 -93
- package/dist/mem-ready-core.d.ts +0 -56
- package/dist/mem-signal-core.d.ts +0 -132
- package/dist/mem-start-core.d.ts +0 -76
- package/dist/mem-summarize-core.d.ts +0 -105
- package/dist/mem-triage-core.d.ts +0 -127
- package/dist/memory-schema.d.ts +0 -150
- package/dist/memory-store.d.ts +0 -108
- package/dist/paths.d.ts +0 -28
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Signal Core Logic (WU-1473)
|
|
3
|
-
*
|
|
4
|
-
* Core logic for creating coordination signals between parallel agents.
|
|
5
|
-
* Enables sub-100ms agent communication via JSONL append operations.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Append-only writes for sub-100ms performance
|
|
9
|
-
* - WU-scoped signals for focused coordination
|
|
10
|
-
* - Lane-targeted signals for cross-team communication
|
|
11
|
-
* - Read/unread tracking for mem:inbox integration
|
|
12
|
-
*
|
|
13
|
-
* @see {@link tools/mem-signal.mjs} - CLI wrapper
|
|
14
|
-
* @see {@link tools/__tests__/mem-signal.test.mjs} - Tests
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Signal file name constant
|
|
18
|
-
*/
|
|
19
|
-
export declare const SIGNAL_FILE_NAME = "signals.jsonl";
|
|
20
|
-
/**
|
|
21
|
-
* Signal structure
|
|
22
|
-
*/
|
|
23
|
-
export interface Signal {
|
|
24
|
-
/** Unique signal identifier (sig-XXXXXXXX) */
|
|
25
|
-
id: string;
|
|
26
|
-
/** Signal content/message */
|
|
27
|
-
message: string;
|
|
28
|
-
/** ISO 8601 timestamp */
|
|
29
|
-
created_at: string;
|
|
30
|
-
/** Whether signal has been read */
|
|
31
|
-
read: boolean;
|
|
32
|
-
/** Optional WU ID scope */
|
|
33
|
-
wu_id?: string;
|
|
34
|
-
/** Optional target lane */
|
|
35
|
-
lane?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Result of creating a signal
|
|
39
|
-
*/
|
|
40
|
-
export interface CreateSignalResult {
|
|
41
|
-
/** Whether signal was created successfully */
|
|
42
|
-
success: boolean;
|
|
43
|
-
/** The created signal object */
|
|
44
|
-
signal: Signal;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Options for creating a signal
|
|
48
|
-
*/
|
|
49
|
-
export interface CreateSignalOptions {
|
|
50
|
-
/** Signal message content (required) */
|
|
51
|
-
message: string;
|
|
52
|
-
/** WU ID to scope signal to */
|
|
53
|
-
wuId?: string;
|
|
54
|
-
/** Lane to target signal to */
|
|
55
|
-
lane?: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Options for loading signals
|
|
59
|
-
*/
|
|
60
|
-
export interface LoadSignalsOptions {
|
|
61
|
-
/** Filter by WU ID */
|
|
62
|
-
wuId?: string;
|
|
63
|
-
/** Filter by lane */
|
|
64
|
-
lane?: string;
|
|
65
|
-
/** Only return unread signals */
|
|
66
|
-
unreadOnly?: boolean;
|
|
67
|
-
/** Only return signals created after this time */
|
|
68
|
-
since?: Date | string;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Result of marking signals as read
|
|
72
|
-
*/
|
|
73
|
-
export interface MarkAsReadResult {
|
|
74
|
-
/** Number of signals marked as read */
|
|
75
|
-
markedCount: number;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Creates a coordination signal between parallel agents.
|
|
79
|
-
*
|
|
80
|
-
* Signals are appended to signals.jsonl using append-only writes
|
|
81
|
-
* for sub-100ms performance. Signals can be scoped to a specific
|
|
82
|
-
* WU or targeted at a specific lane.
|
|
83
|
-
*
|
|
84
|
-
* @param {string} baseDir - Project base directory
|
|
85
|
-
* @param {CreateSignalOptions} options - Signal options
|
|
86
|
-
* @returns {Promise<CreateSignalResult>} Result with created signal
|
|
87
|
-
* @throws {Error} If message is missing or WU ID is invalid
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* const result = await createSignal('/project', {
|
|
91
|
-
* message: 'Starting feature implementation',
|
|
92
|
-
* wuId: 'WU-1473',
|
|
93
|
-
* lane: 'Operations: Tooling',
|
|
94
|
-
* });
|
|
95
|
-
*/
|
|
96
|
-
export declare function createSignal(baseDir: string, options: CreateSignalOptions): Promise<CreateSignalResult>;
|
|
97
|
-
/**
|
|
98
|
-
* Loads signals from the signals file with optional filtering.
|
|
99
|
-
*
|
|
100
|
-
* Signals are returned in chronological order (oldest first).
|
|
101
|
-
* Supports filtering by WU ID, lane, and read status.
|
|
102
|
-
*
|
|
103
|
-
* @param {string} baseDir - Project base directory
|
|
104
|
-
* @param {LoadSignalsOptions} [options={}] - Filter options
|
|
105
|
-
* @returns {Promise<Signal[]>} Array of signals matching filters
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* // Load all signals
|
|
109
|
-
* const all = await loadSignals('/project');
|
|
110
|
-
*
|
|
111
|
-
* // Load unread signals for a specific WU
|
|
112
|
-
* const unread = await loadSignals('/project', {
|
|
113
|
-
* wuId: 'WU-1473',
|
|
114
|
-
* unreadOnly: true,
|
|
115
|
-
* });
|
|
116
|
-
*/
|
|
117
|
-
export declare function loadSignals(baseDir: string, options?: LoadSignalsOptions): Promise<Signal[]>;
|
|
118
|
-
/**
|
|
119
|
-
* Marks signals as read by updating the signals file.
|
|
120
|
-
*
|
|
121
|
-
* Reads the entire file, updates the read status for matching IDs,
|
|
122
|
-
* and writes back. Only signals that were previously unread are counted.
|
|
123
|
-
*
|
|
124
|
-
* @param baseDir - Project base directory
|
|
125
|
-
* @param signalIds - Array of signal IDs to mark as read
|
|
126
|
-
* @returns Result with count of signals marked
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* const result = await markSignalsAsRead('/project', ['sig-abc12345', 'sig-def67890']);
|
|
130
|
-
* console.log(result.markedCount); // 2
|
|
131
|
-
*/
|
|
132
|
-
export declare function markSignalsAsRead(baseDir: string, signalIds: string[]): Promise<MarkAsReadResult>;
|
package/dist/mem-start-core.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Start Core (WU-1466)
|
|
3
|
-
*
|
|
4
|
-
* Core logic for creating session nodes linked to WUs.
|
|
5
|
-
* Called by wu:claim enhancement for context restoration after /clear.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Creates session nodes with WU reference
|
|
9
|
-
* - Stores agent type, start timestamp, context tier
|
|
10
|
-
* - Idempotent: multiple starts create separate sessions
|
|
11
|
-
* - Auto-initializes memory layer if not present
|
|
12
|
-
*
|
|
13
|
-
* @see {@link tools/mem-start.mjs} - CLI wrapper
|
|
14
|
-
* @see {@link tools/__tests__/mem-start.test.mjs} - Tests
|
|
15
|
-
* @see {@link tools/lib/memory-schema.mjs} - Schema definitions
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Session start options
|
|
19
|
-
*/
|
|
20
|
-
export interface StartSessionOptions {
|
|
21
|
-
/** Work Unit ID (required) */
|
|
22
|
-
wuId: string;
|
|
23
|
-
/** Agent type (defaults to 'unknown') */
|
|
24
|
-
agentType?: string;
|
|
25
|
-
/** Context tier (defaults to 'full') */
|
|
26
|
-
contextTier?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Session node structure
|
|
30
|
-
*/
|
|
31
|
-
interface SessionNode {
|
|
32
|
-
id: string;
|
|
33
|
-
type: 'session';
|
|
34
|
-
lifecycle: 'wu';
|
|
35
|
-
content: string;
|
|
36
|
-
created_at: string;
|
|
37
|
-
wu_id: string;
|
|
38
|
-
session_id: string;
|
|
39
|
-
metadata: {
|
|
40
|
-
agentType: string;
|
|
41
|
-
contextTier: string;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Session start result
|
|
46
|
-
*/
|
|
47
|
-
export interface StartSessionResult {
|
|
48
|
-
/** Whether the operation succeeded */
|
|
49
|
-
success: boolean;
|
|
50
|
-
/** Created session node */
|
|
51
|
-
session: SessionNode;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Creates a new session node linked to a WU.
|
|
55
|
-
*
|
|
56
|
-
* Creates a session-type memory node with:
|
|
57
|
-
* - Unique ID (mem-XXXX format)
|
|
58
|
-
* - Link to WU via wu_id field
|
|
59
|
-
* - Agent type and context tier in metadata
|
|
60
|
-
* - UUID session_id for unique identification
|
|
61
|
-
*
|
|
62
|
-
* @param baseDir - Base directory containing .lumenflow/memory/
|
|
63
|
-
* @param options - Session options
|
|
64
|
-
* @returns Result with created session node
|
|
65
|
-
* @throws If wuId is missing or invalid
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* const result = await startSession('/path/to/project', {
|
|
69
|
-
* wuId: 'WU-1234',
|
|
70
|
-
* agentType: 'general-purpose',
|
|
71
|
-
* contextTier: 'core',
|
|
72
|
-
* });
|
|
73
|
-
* console.log(result.session.id); // 'mem-a1b2'
|
|
74
|
-
*/
|
|
75
|
-
export declare function startSession(baseDir: string, options: StartSessionOptions): Promise<StartSessionResult>;
|
|
76
|
-
export {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Summarize Core (WU-1471)
|
|
3
|
-
*
|
|
4
|
-
* Rollup older memory nodes into summary nodes for compaction.
|
|
5
|
-
* Implements forgetting as first-class feature.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Aggregate checkpoint/note/discovery nodes into summaries
|
|
9
|
-
* - Mark originals for cleanup after summary creation
|
|
10
|
-
* - Respect lifecycle TTL (ephemeral, session, wu, project)
|
|
11
|
-
* - Support dry-run mode for preview
|
|
12
|
-
*
|
|
13
|
-
* @see {@link tools/mem-summarize.mjs} - CLI wrapper
|
|
14
|
-
* @see {@link tools/__tests__/mem-summarize.test.mjs} - Tests
|
|
15
|
-
*/
|
|
16
|
-
import { type MemoryNode } from './memory-schema.js';
|
|
17
|
-
/**
|
|
18
|
-
* Summarize options
|
|
19
|
-
*/
|
|
20
|
-
export interface SummarizeOptions {
|
|
21
|
-
/** WU ID to summarize (e.g., 'WU-1234') */
|
|
22
|
-
wuId: string;
|
|
23
|
-
/** If true, preview without modifications */
|
|
24
|
-
dryRun?: boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Summary node structure
|
|
28
|
-
*/
|
|
29
|
-
interface SummaryNode {
|
|
30
|
-
id: string;
|
|
31
|
-
type: 'summary';
|
|
32
|
-
lifecycle: 'project';
|
|
33
|
-
content: string;
|
|
34
|
-
created_at: string;
|
|
35
|
-
wu_id: string;
|
|
36
|
-
metadata: {
|
|
37
|
-
source_nodes: string[];
|
|
38
|
-
source_count: number;
|
|
39
|
-
summarized_at: string;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Summarize result
|
|
44
|
-
*/
|
|
45
|
-
export interface SummarizeResult {
|
|
46
|
-
/** Whether summarization succeeded */
|
|
47
|
-
success: boolean;
|
|
48
|
-
/** Created summary node */
|
|
49
|
-
summary: SummaryNode;
|
|
50
|
-
/** Node IDs marked for cleanup */
|
|
51
|
-
markedForCleanup: string[];
|
|
52
|
-
/** True if in dry-run mode */
|
|
53
|
-
dryRun?: boolean;
|
|
54
|
-
/** Ratio of source nodes to summary */
|
|
55
|
-
compactionRatio: number;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Filter nodes that can be summarized for a given WU.
|
|
59
|
-
*
|
|
60
|
-
* Excludes:
|
|
61
|
-
* - Nodes from different WUs
|
|
62
|
-
* - Ephemeral lifecycle nodes (already transient)
|
|
63
|
-
* - Already-summarized nodes (have summarized_into metadata)
|
|
64
|
-
* - Summary nodes themselves
|
|
65
|
-
*
|
|
66
|
-
* @param nodes - All memory nodes
|
|
67
|
-
* @param wuId - WU ID to filter by
|
|
68
|
-
* @returns Summarizable nodes
|
|
69
|
-
*/
|
|
70
|
-
export declare function filterSummarizableNodes(nodes: MemoryNode[], wuId: string): MemoryNode[];
|
|
71
|
-
/**
|
|
72
|
-
* Calculate compaction ratio (source nodes / summary nodes).
|
|
73
|
-
*
|
|
74
|
-
* @param sourceCount - Number of source nodes
|
|
75
|
-
* @param summaryCount - Number of summary nodes created
|
|
76
|
-
* @returns Compaction ratio (0 if invalid input)
|
|
77
|
-
*/
|
|
78
|
-
export declare function getCompactionRatio(sourceCount: number, summaryCount: number): number;
|
|
79
|
-
/**
|
|
80
|
-
* Summarize memory nodes for a closed WU.
|
|
81
|
-
*
|
|
82
|
-
* Aggregates checkpoint, note, and discovery nodes into a single
|
|
83
|
-
* summary node. Original nodes are marked for cleanup (unless
|
|
84
|
-
* they have project lifecycle).
|
|
85
|
-
*
|
|
86
|
-
* @param baseDir - Base directory containing .lumenflow/memory/
|
|
87
|
-
* @param options - Summarization options
|
|
88
|
-
* @returns Result with summary and cleanup info
|
|
89
|
-
* @throws If no summarizable nodes found for WU
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* // Summarize nodes for a completed WU
|
|
93
|
-
* const result = await summarizeWu(baseDir, { wuId: 'WU-1234' });
|
|
94
|
-
* console.log(`Created summary ${result.summary.id}`);
|
|
95
|
-
* console.log(`Compaction ratio: ${result.compactionRatio}:1`);
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* // Preview without modifications
|
|
99
|
-
* const preview = await summarizeWu(baseDir, {
|
|
100
|
-
* wuId: 'WU-1234',
|
|
101
|
-
* dryRun: true,
|
|
102
|
-
* });
|
|
103
|
-
*/
|
|
104
|
-
export declare function summarizeWu(baseDir: string, options: SummarizeOptions): Promise<SummarizeResult>;
|
|
105
|
-
export {};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Triage Core (WU-1470)
|
|
3
|
-
*
|
|
4
|
-
* Review discovery nodes and promote to WUs or archive.
|
|
5
|
-
*
|
|
6
|
-
* Features:
|
|
7
|
-
* - List open discovery nodes with deterministic ordering
|
|
8
|
-
* - Promote discovery to WU (integrates with wu:create)
|
|
9
|
-
* - Archive discovery without promotion
|
|
10
|
-
*
|
|
11
|
-
* @see {@link tools/mem-triage.mjs} - CLI wrapper
|
|
12
|
-
* @see {@link tools/__tests__/mem-triage.test.mjs} - Tests
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Memory node structure for triage operations
|
|
16
|
-
*/
|
|
17
|
-
interface TriageMemoryNode {
|
|
18
|
-
id: string;
|
|
19
|
-
type: string;
|
|
20
|
-
lifecycle: string;
|
|
21
|
-
content: string;
|
|
22
|
-
created_at: string;
|
|
23
|
-
updated_at?: string;
|
|
24
|
-
wu_id?: string;
|
|
25
|
-
session_id?: string;
|
|
26
|
-
metadata?: Record<string, unknown>;
|
|
27
|
-
tags?: string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Options for listing discoveries
|
|
31
|
-
*/
|
|
32
|
-
export interface ListOptions {
|
|
33
|
-
/** Filter by WU ID (or 'unlinked' for nodes without wu_id) */
|
|
34
|
-
wuId?: string;
|
|
35
|
-
/** Filter by tag */
|
|
36
|
-
tag?: string;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* List open discovery nodes.
|
|
40
|
-
*
|
|
41
|
-
* Returns unblocked, non-archived discovery nodes in deterministic order.
|
|
42
|
-
*
|
|
43
|
-
* @param baseDir - Base directory
|
|
44
|
-
* @param options - Filter options
|
|
45
|
-
* @returns Open discovery nodes
|
|
46
|
-
*/
|
|
47
|
-
export declare function listOpenDiscoveries(baseDir: string, options?: ListOptions): Promise<TriageMemoryNode[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Options for archiving a discovery
|
|
50
|
-
*/
|
|
51
|
-
export interface ArchiveOptions {
|
|
52
|
-
/** Node ID to archive */
|
|
53
|
-
nodeId: string;
|
|
54
|
-
/** Archive reason */
|
|
55
|
-
reason: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Result of archiving a discovery
|
|
59
|
-
*/
|
|
60
|
-
export interface ArchiveResult {
|
|
61
|
-
/** Whether archiving succeeded */
|
|
62
|
-
success: boolean;
|
|
63
|
-
/** Archived node ID */
|
|
64
|
-
nodeId: string;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Archive a discovery node without promotion.
|
|
68
|
-
*
|
|
69
|
-
* Sets metadata.status to 'archived' and records the reason.
|
|
70
|
-
*
|
|
71
|
-
* @param baseDir - Base directory
|
|
72
|
-
* @param options - Archive options
|
|
73
|
-
* @returns Archive result
|
|
74
|
-
* @throws If node not found, not a discovery, or already archived
|
|
75
|
-
*/
|
|
76
|
-
export declare function archiveDiscovery(baseDir: string, options: ArchiveOptions): Promise<ArchiveResult>;
|
|
77
|
-
/**
|
|
78
|
-
* Options for promoting a discovery to a WU
|
|
79
|
-
*/
|
|
80
|
-
export interface PromoteOptions {
|
|
81
|
-
/** Node ID to promote */
|
|
82
|
-
nodeId: string;
|
|
83
|
-
/** WU lane */
|
|
84
|
-
lane: string;
|
|
85
|
-
/** Custom WU title (defaults to discovery content) */
|
|
86
|
-
title?: string;
|
|
87
|
-
/** Explicit WU ID (defaults to next available) */
|
|
88
|
-
wuId?: string;
|
|
89
|
-
/** Priority override */
|
|
90
|
-
priority?: string;
|
|
91
|
-
/** If true, return spec without creating WU */
|
|
92
|
-
dryRun?: boolean;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* WU specification generated from promotion
|
|
96
|
-
*/
|
|
97
|
-
export interface WUSpec {
|
|
98
|
-
/** WU ID */
|
|
99
|
-
id: string;
|
|
100
|
-
/** WU title */
|
|
101
|
-
title: string;
|
|
102
|
-
/** WU lane */
|
|
103
|
-
lane: string;
|
|
104
|
-
/** WU priority */
|
|
105
|
-
priority: string;
|
|
106
|
-
/** WU notes with provenance */
|
|
107
|
-
notes: string;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Result of promoting a discovery
|
|
111
|
-
*/
|
|
112
|
-
export interface PromoteResult {
|
|
113
|
-
/** Whether promotion succeeded */
|
|
114
|
-
success: boolean;
|
|
115
|
-
/** Generated WU specification */
|
|
116
|
-
wuSpec: WUSpec;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Promote a discovery node to a WU.
|
|
120
|
-
*
|
|
121
|
-
* @param baseDir - Base directory
|
|
122
|
-
* @param options - Promote options
|
|
123
|
-
* @returns Promotion result
|
|
124
|
-
* @throws If node not found, not a discovery, or already closed
|
|
125
|
-
*/
|
|
126
|
-
export declare function promoteDiscovery(baseDir: string, options: PromoteOptions): Promise<PromoteResult>;
|
|
127
|
-
export {};
|
package/dist/memory-schema.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Schema (WU-1462)
|
|
3
|
-
*
|
|
4
|
-
* Zod schema for runtime validation of memory node structure.
|
|
5
|
-
* Foundation for the entire memory layer (INIT-007 Phase 1).
|
|
6
|
-
*
|
|
7
|
-
* Defines schemas for:
|
|
8
|
-
* - Memory nodes (5 types: session, discovery, checkpoint, note, summary)
|
|
9
|
-
* - Lifecycles (4 levels: ephemeral, session, wu, project)
|
|
10
|
-
* - Relationships (4 types: blocks, parent_child, related, discovered_from)
|
|
11
|
-
*
|
|
12
|
-
* @see {@link tools/lib/__tests__/memory-schema.test.mjs} - Tests
|
|
13
|
-
*/
|
|
14
|
-
import { z } from 'zod';
|
|
15
|
-
/**
|
|
16
|
-
* Memory node types
|
|
17
|
-
*
|
|
18
|
-
* - session: Session-level context (agent startup, context snapshot)
|
|
19
|
-
* - discovery: Found information (file locations, code patterns)
|
|
20
|
-
* - checkpoint: Progress marker (task milestone, state save)
|
|
21
|
-
* - note: Free-form annotation (observation, decision rationale)
|
|
22
|
-
* - summary: Condensed context (session summary, WU summary)
|
|
23
|
-
*/
|
|
24
|
-
export declare const MEMORY_NODE_TYPES: readonly ["session", "discovery", "checkpoint", "note", "summary"];
|
|
25
|
-
/**
|
|
26
|
-
* Memory lifecycle durations
|
|
27
|
-
*
|
|
28
|
-
* - ephemeral: Discarded immediately after use (scratch pad)
|
|
29
|
-
* - session: Lives for current agent session only
|
|
30
|
-
* - wu: Lives for WU duration (cleared on wu:done)
|
|
31
|
-
* - project: Persists across WUs (architectural knowledge)
|
|
32
|
-
*/
|
|
33
|
-
export declare const MEMORY_LIFECYCLES: readonly ["ephemeral", "session", "wu", "project"];
|
|
34
|
-
/**
|
|
35
|
-
* Relationship types between memory nodes
|
|
36
|
-
*
|
|
37
|
-
* - blocks: This node blocks another (dependency)
|
|
38
|
-
* - parent_child: Hierarchical relationship (session contains discoveries)
|
|
39
|
-
* - related: Semantic similarity or topical connection
|
|
40
|
-
* - discovered_from: Source attribution (discovered from another node)
|
|
41
|
-
*/
|
|
42
|
-
export declare const RELATIONSHIP_TYPES: readonly ["blocks", "parent_child", "related", "discovered_from"];
|
|
43
|
-
/**
|
|
44
|
-
* Regex patterns for memory validation
|
|
45
|
-
*/
|
|
46
|
-
export declare const MEMORY_PATTERNS: {
|
|
47
|
-
/** Memory ID format: mem-[a-z0-9]{4} */
|
|
48
|
-
MEMORY_ID: RegExp;
|
|
49
|
-
/** WU ID format (reused from wu-schema) */
|
|
50
|
-
WU_ID: RegExp;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Zod schema for Memory Node
|
|
54
|
-
*
|
|
55
|
-
* Validates memory nodes against the memory layer requirements.
|
|
56
|
-
* All memory operations should validate against this schema.
|
|
57
|
-
*/
|
|
58
|
-
export declare const MemoryNodeSchema: z.ZodObject<{
|
|
59
|
-
id: z.ZodString;
|
|
60
|
-
type: z.ZodEnum<{
|
|
61
|
-
session: "session";
|
|
62
|
-
discovery: "discovery";
|
|
63
|
-
checkpoint: "checkpoint";
|
|
64
|
-
note: "note";
|
|
65
|
-
summary: "summary";
|
|
66
|
-
}>;
|
|
67
|
-
lifecycle: z.ZodEnum<{
|
|
68
|
-
session: "session";
|
|
69
|
-
ephemeral: "ephemeral";
|
|
70
|
-
wu: "wu";
|
|
71
|
-
project: "project";
|
|
72
|
-
}>;
|
|
73
|
-
content: z.ZodString;
|
|
74
|
-
created_at: z.ZodString;
|
|
75
|
-
updated_at: z.ZodOptional<z.ZodString>;
|
|
76
|
-
wu_id: z.ZodOptional<z.ZodString>;
|
|
77
|
-
session_id: z.ZodOptional<z.ZodString>;
|
|
78
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
79
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
80
|
-
}, z.core.$strip>;
|
|
81
|
-
/**
|
|
82
|
-
* Zod schema for Relationship between memory nodes
|
|
83
|
-
*
|
|
84
|
-
* Validates relationships between memory nodes.
|
|
85
|
-
* Used for building the memory graph.
|
|
86
|
-
*/
|
|
87
|
-
export declare const RelationshipSchema: z.ZodObject<{
|
|
88
|
-
from_id: z.ZodString;
|
|
89
|
-
to_id: z.ZodString;
|
|
90
|
-
type: z.ZodEnum<{
|
|
91
|
-
blocks: "blocks";
|
|
92
|
-
parent_child: "parent_child";
|
|
93
|
-
related: "related";
|
|
94
|
-
discovered_from: "discovered_from";
|
|
95
|
-
}>;
|
|
96
|
-
created_at: z.ZodOptional<z.ZodString>;
|
|
97
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
-
}, z.core.$strip>;
|
|
99
|
-
/**
|
|
100
|
-
* TypeScript types inferred from schemas
|
|
101
|
-
*/
|
|
102
|
-
export type MemoryNode = z.infer<typeof MemoryNodeSchema>;
|
|
103
|
-
export type Relationship = z.infer<typeof RelationshipSchema>;
|
|
104
|
-
/**
|
|
105
|
-
* Validates memory node data against schema
|
|
106
|
-
*
|
|
107
|
-
* @param data - Data to validate
|
|
108
|
-
* @returns Validation result
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* const result = validateMemoryNode(nodeData);
|
|
112
|
-
* if (!result.success) {
|
|
113
|
-
* result.error.issues.forEach(issue => {
|
|
114
|
-
* console.error(`${issue.path.join('.')}: ${issue.message}`);
|
|
115
|
-
* });
|
|
116
|
-
* }
|
|
117
|
-
*/
|
|
118
|
-
export declare function validateMemoryNode(data: unknown): z.ZodSafeParseResult<{
|
|
119
|
-
id: string;
|
|
120
|
-
type: "session" | "discovery" | "checkpoint" | "note" | "summary";
|
|
121
|
-
lifecycle: "session" | "ephemeral" | "wu" | "project";
|
|
122
|
-
content: string;
|
|
123
|
-
created_at: string;
|
|
124
|
-
updated_at?: string;
|
|
125
|
-
wu_id?: string;
|
|
126
|
-
session_id?: string;
|
|
127
|
-
metadata?: Record<string, unknown>;
|
|
128
|
-
tags?: string[];
|
|
129
|
-
}>;
|
|
130
|
-
/**
|
|
131
|
-
* Validates relationship data against schema
|
|
132
|
-
*
|
|
133
|
-
* @param data - Data to validate
|
|
134
|
-
* @returns Validation result
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* const result = validateRelationship(relData);
|
|
138
|
-
* if (!result.success) {
|
|
139
|
-
* result.error.issues.forEach(issue => {
|
|
140
|
-
* console.error(`${issue.path.join('.')}: ${issue.message}`);
|
|
141
|
-
* });
|
|
142
|
-
* }
|
|
143
|
-
*/
|
|
144
|
-
export declare function validateRelationship(data: unknown): z.ZodSafeParseResult<{
|
|
145
|
-
from_id: string;
|
|
146
|
-
to_id: string;
|
|
147
|
-
type: "blocks" | "parent_child" | "related" | "discovered_from";
|
|
148
|
-
created_at?: string;
|
|
149
|
-
metadata?: Record<string, unknown>;
|
|
150
|
-
}>;
|
package/dist/memory-store.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Store (WU-1463)
|
|
3
|
-
*
|
|
4
|
-
* JSONL-based memory store with load, query, and append operations.
|
|
5
|
-
* Git-friendly format with one node per line for merge-safe diffs.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Append-only writes (no full file rewrite)
|
|
9
|
-
* - Indexed lookups by ID and WU
|
|
10
|
-
* - Deterministic queryReady() ordering by priority then createdAt
|
|
11
|
-
*
|
|
12
|
-
* @see {@link tools/lib/__tests__/memory-store.test.mjs} - Tests
|
|
13
|
-
* @see {@link tools/lib/memory-schema.mjs} - Schema definitions
|
|
14
|
-
*/
|
|
15
|
-
import { type MemoryNode } from './memory-schema.js';
|
|
16
|
-
/**
|
|
17
|
-
* Memory file name constant
|
|
18
|
-
*/
|
|
19
|
-
export declare const MEMORY_FILE_NAME = "memory.jsonl";
|
|
20
|
-
/**
|
|
21
|
-
* Indexed memory result from loadMemory
|
|
22
|
-
*/
|
|
23
|
-
export interface IndexedMemory {
|
|
24
|
-
/** All loaded nodes in file order */
|
|
25
|
-
nodes: MemoryNode[];
|
|
26
|
-
/** Nodes indexed by ID */
|
|
27
|
-
byId: Map<string, MemoryNode>;
|
|
28
|
-
/** Nodes indexed by WU ID */
|
|
29
|
-
byWu: Map<string, MemoryNode[]>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Loads memory from JSONL file and returns indexed nodes.
|
|
33
|
-
*
|
|
34
|
-
* Handles:
|
|
35
|
-
* - Missing file: returns empty result
|
|
36
|
-
* - Empty file: returns empty result
|
|
37
|
-
* - Empty lines: skipped gracefully
|
|
38
|
-
* - Malformed JSON: throws error with line info
|
|
39
|
-
* - Invalid nodes: throws validation error
|
|
40
|
-
*
|
|
41
|
-
* @param baseDir - Directory containing memory.jsonl
|
|
42
|
-
* @returns Indexed memory nodes
|
|
43
|
-
* @throws If file contains malformed JSON or invalid nodes
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* const memory = await loadMemory('/path/to/project');
|
|
47
|
-
* const node = memory.byId.get('mem-abc1');
|
|
48
|
-
* const wuNodes = memory.byWu.get('WU-1463') ?? [];
|
|
49
|
-
*/
|
|
50
|
-
export declare function loadMemory(baseDir: string): Promise<IndexedMemory>;
|
|
51
|
-
/**
|
|
52
|
-
* Appends a single node to the memory file.
|
|
53
|
-
*
|
|
54
|
-
* Uses append mode to avoid full file rewrite.
|
|
55
|
-
* Creates file if it doesn't exist.
|
|
56
|
-
* Validates node before appending.
|
|
57
|
-
*
|
|
58
|
-
* @param baseDir - Directory containing memory.jsonl
|
|
59
|
-
* @param node - Node to append
|
|
60
|
-
* @returns The appended node
|
|
61
|
-
* @throws If node fails validation
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* const node = await appendNode('/path/to/project', {
|
|
65
|
-
* id: 'mem-abc1',
|
|
66
|
-
* type: 'discovery',
|
|
67
|
-
* lifecycle: 'wu',
|
|
68
|
-
* content: 'Found relevant file',
|
|
69
|
-
* created_at: new Date().toISOString(),
|
|
70
|
-
* wu_id: 'WU-1463',
|
|
71
|
-
* });
|
|
72
|
-
*/
|
|
73
|
-
export declare function appendNode(baseDir: string, node: MemoryNode): Promise<MemoryNode>;
|
|
74
|
-
/**
|
|
75
|
-
* Queries nodes ready for processing by WU ID.
|
|
76
|
-
*
|
|
77
|
-
* Returns nodes linked to the WU in deterministic order:
|
|
78
|
-
* 1. Priority (P0 first, then P1, P2, P3; nodes without priority last)
|
|
79
|
-
* 2. Created timestamp (oldest first for same priority)
|
|
80
|
-
* 3. ID (for stable sort when priority and timestamp match)
|
|
81
|
-
*
|
|
82
|
-
* @param baseDir - Directory containing memory.jsonl
|
|
83
|
-
* @param wuId - WU ID to query (e.g., 'WU-1463')
|
|
84
|
-
* @returns Deterministically ordered nodes for WU
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* const ready = await queryReady('/path/to/project', 'WU-1463');
|
|
88
|
-
* // Process highest priority, oldest items first
|
|
89
|
-
* for (const node of ready) {
|
|
90
|
-
* await processNode(node);
|
|
91
|
-
* }
|
|
92
|
-
*/
|
|
93
|
-
export declare function queryReady(baseDir: string, wuId: string): Promise<MemoryNode[]>;
|
|
94
|
-
/**
|
|
95
|
-
* Queries all nodes linked to a WU ID.
|
|
96
|
-
*
|
|
97
|
-
* Returns nodes in file order (insertion order).
|
|
98
|
-
* Use queryReady() instead if you need deterministic priority ordering.
|
|
99
|
-
*
|
|
100
|
-
* @param baseDir - Directory containing memory.jsonl
|
|
101
|
-
* @param wuId - WU ID to query (e.g., 'WU-1463')
|
|
102
|
-
* @returns All nodes for WU in file order
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* const nodes = await queryByWu('/path/to/project', 'WU-1463');
|
|
106
|
-
* console.log(`Found ${nodes.length} nodes for WU-1463`);
|
|
107
|
-
*/
|
|
108
|
-
export declare function queryByWu(baseDir: string, wuId: string): Promise<MemoryNode[]>;
|