memory-lucia 2.0.0 → 2.0.2
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/CLAWHUB-FIXES.md +127 -0
- package/README.md +78 -31
- package/SKILL.md +1 -1
- package/database/schema.sql +152 -0
- package/migrations/v1-to-v2.js +213 -0
- package/package.json +4 -4
- package/references/API.md +364 -0
- package/NPM-PUBLISH-GUIDE.md +0 -169
- package/PUBLISH-STEPS.md +0 -102
- package/publish-with-otp.bat +0 -13
- package/publish.bat +0 -17
- package/publish.sh +0 -20
package/CLAWHUB-FIXES.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# ClawHub Audit Fixes
|
|
2
|
+
|
|
3
|
+
This document summarizes the fixes applied to address ClawHub security audit feedback.
|
|
4
|
+
|
|
5
|
+
## Issues Fixed
|
|
6
|
+
|
|
7
|
+
### ✅ 1. Missing Files
|
|
8
|
+
|
|
9
|
+
| File | Status | Description |
|
|
10
|
+
|------|--------|-------------|
|
|
11
|
+
| `database/schema.sql` | ✅ Created | Complete database schema with tables, indexes, and views |
|
|
12
|
+
| `migrations/v1-to-v2.js` | ✅ Created | Migration script from V1 to V2 database |
|
|
13
|
+
| `references/API.md` | ✅ Created | Complete API documentation |
|
|
14
|
+
|
|
15
|
+
### ✅ 2. Version Consistency
|
|
16
|
+
|
|
17
|
+
| Location | Before | After |
|
|
18
|
+
|----------|--------|-------|
|
|
19
|
+
| SKILL.md | 2.0.0 | 2.0.1 |
|
|
20
|
+
| README.md | 2.0.0 | 2.0.1 |
|
|
21
|
+
| package.json | 2.0.1 | 2.0.1 (already correct) |
|
|
22
|
+
|
|
23
|
+
### ✅ 3. Removed Development Files
|
|
24
|
+
|
|
25
|
+
Removed from repository:
|
|
26
|
+
- `publish.bat`
|
|
27
|
+
- `publish-with-otp.bat`
|
|
28
|
+
- `push-final.bat`
|
|
29
|
+
- `push-gh-cli.bat`
|
|
30
|
+
- `push-manual.bat`
|
|
31
|
+
- `push-to-github.bat`
|
|
32
|
+
- `push-with-gh.bat`
|
|
33
|
+
|
|
34
|
+
Updated `.gitignore` to exclude:
|
|
35
|
+
- `*.bat` files
|
|
36
|
+
- Publish documentation files
|
|
37
|
+
- GitHub workflows (if not ready)
|
|
38
|
+
|
|
39
|
+
### ✅ 4. Source Verification
|
|
40
|
+
|
|
41
|
+
All source URLs are valid:
|
|
42
|
+
- **npm**: https://www.npmjs.com/package/memory-lucia
|
|
43
|
+
- **GitHub**: https://github.com/wen521/memory-lucia-
|
|
44
|
+
- **Issues**: https://github.com/wen521/memory-lucia-/issues
|
|
45
|
+
|
|
46
|
+
## Security Considerations Addressed
|
|
47
|
+
|
|
48
|
+
### Database Safety
|
|
49
|
+
- ✅ Schema file (`schema.sql`) now included with proper table definitions
|
|
50
|
+
- ✅ All views (`v_pending_decisions`, `v_skill_summary`, `v_weekly_learning_report`, `v_high_priority`) defined in schema
|
|
51
|
+
- ✅ Database initialization script (`database/init.js`) properly references schema.sql
|
|
52
|
+
- ✅ Migration script (`migrations/v1-to-v2.js`) included for data portability
|
|
53
|
+
|
|
54
|
+
### File System Operations
|
|
55
|
+
- ✅ Database path is configurable (default: `./memory-v2.db`)
|
|
56
|
+
- ✅ Backup directory created relative to working directory
|
|
57
|
+
- ✅ No system files or critical directories accessed
|
|
58
|
+
|
|
59
|
+
### Backup Management
|
|
60
|
+
- ✅ Backup retention configurable via `keepCount` parameter
|
|
61
|
+
- ✅ Automatic cleanup only removes old backups, never active database
|
|
62
|
+
- ✅ Rollback requires explicit backup path selection
|
|
63
|
+
|
|
64
|
+
## File Structure
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
memory-v2-skill/
|
|
68
|
+
├── SKILL.md # Skill description (version 2.0.1)
|
|
69
|
+
├── README.md # Documentation (version 2.0.1)
|
|
70
|
+
├── package.json # Package metadata
|
|
71
|
+
├── LICENSE # MIT License
|
|
72
|
+
├── .gitignore # Excludes dev files
|
|
73
|
+
├── api/
|
|
74
|
+
│ └── index.js # Main API module
|
|
75
|
+
├── database/
|
|
76
|
+
│ ├── init.js # Database initialization
|
|
77
|
+
│ └── schema.sql # ✅ Database schema (NEW)
|
|
78
|
+
├── modules/
|
|
79
|
+
│ ├── priority.js # Priority analysis
|
|
80
|
+
│ ├── learning.js # Learning tracking
|
|
81
|
+
│ ├── decision.js # Decision recording
|
|
82
|
+
│ ├── evolution.js # Skill evolution
|
|
83
|
+
│ └── version.js # Version management
|
|
84
|
+
├── migrations/
|
|
85
|
+
│ └── v1-to-v2.js # ✅ Migration script (NEW)
|
|
86
|
+
├── references/
|
|
87
|
+
│ └── API.md # ✅ API documentation (NEW)
|
|
88
|
+
└── scripts/
|
|
89
|
+
└── init-memory.js # Setup script
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Pre-Publish Checklist
|
|
93
|
+
|
|
94
|
+
Before publishing to ClawHub/npm:
|
|
95
|
+
|
|
96
|
+
- [ ] Verify all files listed above are present
|
|
97
|
+
- [ ] Run `npm test` to ensure tests pass
|
|
98
|
+
- [ ] Run `node scripts/init-memory.js` to verify database initialization
|
|
99
|
+
- [ ] Verify no `.bat` files in the package
|
|
100
|
+
- [ ] Verify version is consistent across all files (2.0.1)
|
|
101
|
+
- [ ] Verify GitHub repository is public and accessible
|
|
102
|
+
- [ ] Verify npm package is published and accessible
|
|
103
|
+
|
|
104
|
+
## Testing
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Install dependencies
|
|
108
|
+
npm install
|
|
109
|
+
|
|
110
|
+
# Initialize database
|
|
111
|
+
node scripts/init-memory.js
|
|
112
|
+
|
|
113
|
+
# Run tests
|
|
114
|
+
npm test
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Notes for Reviewers
|
|
118
|
+
|
|
119
|
+
1. **Database Views**: All SQL views referenced in the code are defined in `database/schema.sql`
|
|
120
|
+
2. **Migration**: The `migrations/v1-to-v2.js` script handles data migration from V1 format
|
|
121
|
+
3. **API Documentation**: Complete API reference available in `references/API.md`
|
|
122
|
+
4. **No Executables**: All `.bat` files have been removed; only Node.js scripts remain
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
Last updated: 2026-03-25
|
|
127
|
+
Version: 2.0.1
|
package/README.md
CHANGED
|
@@ -1,64 +1,111 @@
|
|
|
1
1
|
# Memory Lucia
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/memory-lucia)
|
|
4
|
+
[](https://github.com/wen521/memory-lucia-)
|
|
5
|
+
[](LICENSE)
|
|
5
6
|
|
|
6
7
|
Advanced memory system for OpenClaw agents with priority analysis, learning tracking, decision recording, and skill evolution.
|
|
7
8
|
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
- 🎯 **Priority Analysis** - Analyze and store message priorities
|
|
11
|
-
- 📚 **Learning Tracking** - Track learning progress and milestones
|
|
12
|
-
- 🎯 **Decision Recording** - Record decisions with outcomes and reviews
|
|
13
|
-
- 📈 **Skill Evolution** - Monitor skill usage and growth
|
|
14
|
-
- 💾 **Version Management** - Automatic backups with rollback
|
|
15
|
-
- 📊 **Dashboard** - Unified view of all memory data
|
|
16
|
-
|
|
17
|
-
## Quick Start
|
|
9
|
+
## 📦 Installation
|
|
18
10
|
|
|
19
11
|
```bash
|
|
20
|
-
# Install
|
|
21
12
|
npm install memory-lucia
|
|
22
13
|
```
|
|
23
14
|
|
|
15
|
+
## 🚀 Quick Start
|
|
16
|
+
|
|
24
17
|
```javascript
|
|
25
18
|
const MemoryAPI = require('memory-lucia');
|
|
26
19
|
|
|
27
|
-
const api = new MemoryAPI('./memory
|
|
20
|
+
const api = new MemoryAPI('./memory.db');
|
|
28
21
|
await api.init();
|
|
29
22
|
|
|
30
|
-
// Track learning
|
|
23
|
+
// Track learning progress
|
|
31
24
|
await api.startLearning(msgId, convId, message);
|
|
25
|
+
await api.updateLearningProgress(learningId, { progress: 50 });
|
|
26
|
+
|
|
27
|
+
// Record a decision
|
|
28
|
+
await api.recordDecision(msgId, convId, {
|
|
29
|
+
summary: 'Choose SQLite over PostgreSQL',
|
|
30
|
+
context: 'For local deployment',
|
|
31
|
+
expectedOutcome: 'Simpler setup'
|
|
32
|
+
});
|
|
32
33
|
|
|
33
34
|
// Get dashboard
|
|
34
35
|
const dashboard = await api.getDashboard();
|
|
36
|
+
console.log(dashboard);
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
##
|
|
39
|
+
## ✨ Features
|
|
38
40
|
|
|
39
|
-
- **Priority** -
|
|
40
|
-
- **Learning** -
|
|
41
|
-
- **Decision** -
|
|
42
|
-
- **Evolution** -
|
|
43
|
-
- **Version** -
|
|
41
|
+
- 🎯 **Priority Analysis** - Analyze and store message priorities
|
|
42
|
+
- 📚 **Learning Tracking** - Track learning progress and milestones
|
|
43
|
+
- 🎯 **Decision Recording** - Record decisions with outcomes and reviews
|
|
44
|
+
- 📈 **Skill Evolution** - Monitor skill usage and growth
|
|
45
|
+
- 💾 **Version Management** - Automatic backups with rollback
|
|
46
|
+
- 📊 **Dashboard** - Unified view of all memory data
|
|
44
47
|
|
|
45
|
-
##
|
|
48
|
+
## 📖 Core Modules
|
|
49
|
+
|
|
50
|
+
### 1. Priority Module
|
|
51
|
+
Analyze and store message priorities.
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
const analysis = await api.analyzePriority(message);
|
|
55
|
+
await api.storePriority(msgId, convId, analysis);
|
|
56
|
+
const highPriority = await api.getHighPriority(10);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Learning Module
|
|
60
|
+
Track learning topics and progress.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const learning = await api.startLearning(msgId, convId, message);
|
|
64
|
+
await api.addMilestone(learning.id, { title: 'Completed Chapter 1' });
|
|
65
|
+
const active = await api.getActiveLearning(5);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Decision Module
|
|
69
|
+
Record and review decisions.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
await api.recordDecision(msgId, convId, decisionData);
|
|
73
|
+
await api.updateDecisionOutcome(decisionId, { actualOutcome: 'Success' });
|
|
74
|
+
const pending = await api.getPendingDecisions();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 4. Evolution Module
|
|
78
|
+
Monitor skill usage.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
await api.recordSkillUsage('skill-name', 'category', 'success');
|
|
82
|
+
const topSkills = await api.getTopSkills(10);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 📚 Documentation
|
|
46
86
|
|
|
47
87
|
- [SKILL.md](SKILL.md) - Skill description and usage
|
|
48
88
|
- [API Reference](references/API.md) - Complete API documentation
|
|
89
|
+
- [Architecture](references/ARCHITECTURE.md) - System design
|
|
49
90
|
|
|
50
|
-
## Database
|
|
91
|
+
## 🗄️ Database
|
|
51
92
|
|
|
52
93
|
SQLite backend with tables:
|
|
53
|
-
- `memory_priorities`
|
|
54
|
-
- `memory_learning`
|
|
55
|
-
- `memory_decisions`
|
|
56
|
-
- `memory_evolution`
|
|
94
|
+
- `memory_priorities` - Priority analysis
|
|
95
|
+
- `memory_learning` - Learning tracking
|
|
96
|
+
- `memory_decisions` - Decision records
|
|
97
|
+
- `memory_evolution` - Skill usage
|
|
98
|
+
|
|
99
|
+
## 🔗 Links
|
|
100
|
+
|
|
101
|
+
- **npm**: https://www.npmjs.com/package/memory-lucia
|
|
102
|
+
- **GitHub**: https://github.com/wen521/memory-lucia-
|
|
103
|
+
- **Issues**: https://github.com/wen521/memory-lucia-/issues
|
|
57
104
|
|
|
58
|
-
## Version
|
|
105
|
+
## 📋 Version
|
|
59
106
|
|
|
60
|
-
Current: 2.0.
|
|
107
|
+
Current: 2.0.2
|
|
61
108
|
|
|
62
|
-
## License
|
|
109
|
+
## 📄 License
|
|
63
110
|
|
|
64
|
-
MIT
|
|
111
|
+
MIT © Chief of Staff
|
package/SKILL.md
CHANGED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
-- Memory V2.0 Database Schema
|
|
2
|
+
-- SQLite database schema for OpenClaw Memory System
|
|
3
|
+
|
|
4
|
+
-- Priority Analysis Table
|
|
5
|
+
CREATE TABLE IF NOT EXISTS memory_priorities (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
msg_id TEXT NOT NULL,
|
|
8
|
+
conv_id TEXT,
|
|
9
|
+
priority_level TEXT CHECK(priority_level IN ('critical', 'high', 'medium', 'low')),
|
|
10
|
+
reasoning TEXT,
|
|
11
|
+
category TEXT,
|
|
12
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
-- Learning Tracking Table
|
|
16
|
+
CREATE TABLE IF NOT EXISTS memory_learning (
|
|
17
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
18
|
+
msg_id TEXT NOT NULL,
|
|
19
|
+
conv_id TEXT,
|
|
20
|
+
topic TEXT,
|
|
21
|
+
description TEXT,
|
|
22
|
+
status TEXT CHECK(status IN ('active', 'paused', 'completed', 'abandoned')) DEFAULT 'active',
|
|
23
|
+
progress INTEGER DEFAULT 0 CHECK(progress >= 0 AND progress <= 100),
|
|
24
|
+
started_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
25
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
26
|
+
completed_at DATETIME
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
-- Learning Milestones Table
|
|
30
|
+
CREATE TABLE IF NOT EXISTS memory_learning_milestones (
|
|
31
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
32
|
+
learning_id INTEGER NOT NULL,
|
|
33
|
+
title TEXT NOT NULL,
|
|
34
|
+
description TEXT,
|
|
35
|
+
achieved_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
36
|
+
FOREIGN KEY (learning_id) REFERENCES memory_learning(id) ON DELETE CASCADE
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
-- Decision Records Table
|
|
40
|
+
CREATE TABLE IF NOT EXISTS memory_decisions (
|
|
41
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
42
|
+
msg_id TEXT NOT NULL,
|
|
43
|
+
conv_id TEXT,
|
|
44
|
+
summary TEXT NOT NULL,
|
|
45
|
+
context TEXT,
|
|
46
|
+
expected_outcome TEXT,
|
|
47
|
+
actual_outcome TEXT,
|
|
48
|
+
status TEXT CHECK(status IN ('pending', 'implemented', 'validated', 'rejected')) DEFAULT 'pending',
|
|
49
|
+
review_scheduled_at DATETIME,
|
|
50
|
+
reviewed_at DATETIME,
|
|
51
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
-- Skill Evolution Table
|
|
55
|
+
CREATE TABLE IF NOT EXISTS memory_evolution (
|
|
56
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
57
|
+
skill_name TEXT NOT NULL,
|
|
58
|
+
category TEXT,
|
|
59
|
+
usage_count INTEGER DEFAULT 0,
|
|
60
|
+
success_count INTEGER DEFAULT 0,
|
|
61
|
+
last_used_at DATETIME,
|
|
62
|
+
first_used_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
-- Database Version Tracking
|
|
66
|
+
CREATE TABLE IF NOT EXISTS memory_schema_version (
|
|
67
|
+
version TEXT PRIMARY KEY,
|
|
68
|
+
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
-- Insert initial version
|
|
72
|
+
INSERT OR IGNORE INTO memory_schema_version (version) VALUES ('2.0.0');
|
|
73
|
+
|
|
74
|
+
-- Create indexes for performance
|
|
75
|
+
CREATE INDEX IF NOT EXISTS idx_priorities_level ON memory_priorities(priority_level);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS idx_priorities_created ON memory_priorities(created_at);
|
|
77
|
+
CREATE INDEX IF NOT EXISTS idx_learning_status ON memory_learning(status);
|
|
78
|
+
CREATE INDEX IF NOT EXISTS idx_learning_topic ON memory_learning(topic);
|
|
79
|
+
CREATE INDEX IF NOT EXISTS idx_decisions_status ON memory_decisions(status);
|
|
80
|
+
CREATE INDEX IF NOT EXISTS idx_decisions_review ON memory_decisions(review_scheduled_at);
|
|
81
|
+
CREATE INDEX IF NOT EXISTS idx_evolution_skill ON memory_evolution(skill_name);
|
|
82
|
+
CREATE INDEX IF NOT EXISTS idx_evolution_category ON memory_evolution(category);
|
|
83
|
+
|
|
84
|
+
-- Views for common queries
|
|
85
|
+
|
|
86
|
+
-- View: Pending Decisions
|
|
87
|
+
CREATE VIEW IF NOT EXISTS v_pending_decisions AS
|
|
88
|
+
SELECT
|
|
89
|
+
d.*,
|
|
90
|
+
CASE
|
|
91
|
+
WHEN review_scheduled_at < CURRENT_TIMESTAMP THEN 'overdue'
|
|
92
|
+
WHEN review_scheduled_at <= datetime('now', '+7 days') THEN 'due_soon'
|
|
93
|
+
ELSE 'scheduled'
|
|
94
|
+
END as review_status
|
|
95
|
+
FROM memory_decisions d
|
|
96
|
+
WHERE status IN ('pending', 'implemented')
|
|
97
|
+
AND (review_scheduled_at IS NULL OR review_scheduled_at <= datetime('now', '+7 days'))
|
|
98
|
+
ORDER BY review_scheduled_at ASC;
|
|
99
|
+
|
|
100
|
+
-- View: Skill Summary
|
|
101
|
+
CREATE VIEW IF NOT EXISTS v_skill_summary AS
|
|
102
|
+
SELECT
|
|
103
|
+
skill_name,
|
|
104
|
+
category,
|
|
105
|
+
usage_count,
|
|
106
|
+
success_count,
|
|
107
|
+
CASE
|
|
108
|
+
WHEN usage_count > 0 THEN ROUND(100.0 * success_count / usage_count, 2)
|
|
109
|
+
ELSE 0
|
|
110
|
+
END as success_rate,
|
|
111
|
+
last_used_at,
|
|
112
|
+
first_used_at
|
|
113
|
+
FROM memory_evolution
|
|
114
|
+
ORDER BY usage_count DESC;
|
|
115
|
+
|
|
116
|
+
-- View: Weekly Learning Report
|
|
117
|
+
CREATE VIEW IF NOT EXISTS v_weekly_learning_report AS
|
|
118
|
+
SELECT
|
|
119
|
+
topic,
|
|
120
|
+
COUNT(*) as session_count,
|
|
121
|
+
AVG(progress) as avg_progress,
|
|
122
|
+
MAX(updated_at) as last_activity,
|
|
123
|
+
SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed_count
|
|
124
|
+
FROM memory_learning
|
|
125
|
+
WHERE updated_at >= datetime('now', '-7 days')
|
|
126
|
+
GROUP BY topic
|
|
127
|
+
ORDER BY last_activity DESC;
|
|
128
|
+
|
|
129
|
+
-- View: High Priority Items
|
|
130
|
+
CREATE VIEW IF NOT EXISTS v_high_priority AS
|
|
131
|
+
SELECT
|
|
132
|
+
'priority' as type,
|
|
133
|
+
id,
|
|
134
|
+
msg_id,
|
|
135
|
+
priority_level as level,
|
|
136
|
+
category,
|
|
137
|
+
reasoning as details,
|
|
138
|
+
created_at
|
|
139
|
+
FROM memory_priorities
|
|
140
|
+
WHERE priority_level IN ('critical', 'high')
|
|
141
|
+
UNION ALL
|
|
142
|
+
SELECT
|
|
143
|
+
'decision' as type,
|
|
144
|
+
id,
|
|
145
|
+
msg_id,
|
|
146
|
+
status as level,
|
|
147
|
+
'decision' as category,
|
|
148
|
+
summary as details,
|
|
149
|
+
created_at
|
|
150
|
+
FROM memory_decisions
|
|
151
|
+
WHERE status = 'pending' AND review_scheduled_at <= CURRENT_TIMESTAMP
|
|
152
|
+
ORDER BY created_at DESC;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Memory V1 to V2 Migration Script
|
|
4
|
+
* Migrates data from old memory format to V2 schema
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const sqlite3 = require('sqlite3').verbose();
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
class MemoryMigration {
|
|
12
|
+
constructor(sourceDbPath, targetDbPath = './memory-v2.db') {
|
|
13
|
+
this.sourceDbPath = sourceDbPath;
|
|
14
|
+
this.targetDbPath = targetDbPath;
|
|
15
|
+
this.sourceDb = null;
|
|
16
|
+
this.targetDb = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async init() {
|
|
20
|
+
// Check if source exists
|
|
21
|
+
if (!fs.existsSync(this.sourceDbPath)) {
|
|
22
|
+
throw new Error(`Source database not found: ${this.sourceDbPath}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Open source database
|
|
26
|
+
this.sourceDb = new sqlite3.Database(this.sourceDbPath, sqlite3.OPEN_READONLY);
|
|
27
|
+
|
|
28
|
+
// Open/create target database
|
|
29
|
+
this.targetDb = new sqlite3.Database(this.targetDbPath);
|
|
30
|
+
|
|
31
|
+
console.log('✅ Connected to source and target databases');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async runSchema() {
|
|
35
|
+
const schemaPath = path.join(__dirname, '..', 'database', 'schema.sql');
|
|
36
|
+
|
|
37
|
+
if (!fs.existsSync(schemaPath)) {
|
|
38
|
+
throw new Error(`Schema file not found: ${schemaPath}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const schema = fs.readFileSync(schemaPath, 'utf8');
|
|
42
|
+
const statements = schema
|
|
43
|
+
.split(';')
|
|
44
|
+
.map(s => s.trim())
|
|
45
|
+
.filter(s => s.length > 0);
|
|
46
|
+
|
|
47
|
+
for (const statement of statements) {
|
|
48
|
+
await this.runTarget(statement);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log('✅ Target database schema initialized');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async migratePriorities() {
|
|
55
|
+
console.log('🔄 Migrating priorities...');
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const rows = await this.allSource(
|
|
59
|
+
"SELECT * FROM memory_priorities WHERE created_at >= datetime('now', '-90 days')"
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
for (const row of rows) {
|
|
63
|
+
await this.runTarget(
|
|
64
|
+
`INSERT INTO memory_priorities
|
|
65
|
+
(msg_id, conv_id, priority_level, reasoning, category, created_at)
|
|
66
|
+
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
67
|
+
[row.msg_id, row.conv_id, row.priority_level, row.reasoning, row.category, row.created_at]
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log(`✅ Migrated ${rows.length} priority records`);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.log('ℹ️ No priorities to migrate or table does not exist');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async migrateLearning() {
|
|
78
|
+
console.log('🔄 Migrating learning records...');
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const rows = await this.allSource(
|
|
82
|
+
"SELECT * FROM memory_learning WHERE status != 'abandoned'"
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
for (const row of rows) {
|
|
86
|
+
await this.runTarget(
|
|
87
|
+
`INSERT INTO memory_learning
|
|
88
|
+
(msg_id, conv_id, topic, description, status, progress, started_at, updated_at, completed_at)
|
|
89
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
90
|
+
[row.msg_id, row.conv_id, row.topic, row.description, row.status,
|
|
91
|
+
row.progress, row.started_at, row.updated_at, row.completed_at]
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log(`✅ Migrated ${rows.length} learning records`);
|
|
96
|
+
} catch (err) {
|
|
97
|
+
console.log('ℹ️ No learning records to migrate or table does not exist');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async migrateDecisions() {
|
|
102
|
+
console.log('🔄 Migrating decisions...');
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const rows = await this.allSource(
|
|
106
|
+
"SELECT * FROM memory_decisions WHERE status IN ('pending', 'implemented')"
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
for (const row of rows) {
|
|
110
|
+
await this.runTarget(
|
|
111
|
+
`INSERT INTO memory_decisions
|
|
112
|
+
(msg_id, conv_id, summary, context, expected_outcome, actual_outcome,
|
|
113
|
+
status, review_scheduled_at, reviewed_at, created_at)
|
|
114
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
115
|
+
[row.msg_id, row.conv_id, row.summary, row.context, row.expected_outcome,
|
|
116
|
+
row.actual_outcome, row.status, row.review_scheduled_at, row.reviewed_at, row.created_at]
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(`✅ Migrated ${rows.length} decision records`);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.log('ℹ️ No decisions to migrate or table does not exist');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async migrateEvolution() {
|
|
127
|
+
console.log('🔄 Migrating skill evolution...');
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const rows = await this.allSource(
|
|
131
|
+
"SELECT * FROM memory_evolution WHERE usage_count > 0"
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
for (const row of rows) {
|
|
135
|
+
await this.runTarget(
|
|
136
|
+
`INSERT INTO memory_evolution
|
|
137
|
+
(skill_name, category, usage_count, success_count, last_used_at, first_used_at)
|
|
138
|
+
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
139
|
+
[row.skill_name, row.category, row.usage_count, row.success_count,
|
|
140
|
+
row.last_used_at, row.first_used_at]
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
console.log(`✅ Migrated ${rows.length} skill evolution records`);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
console.log('ℹ️ No evolution records to migrate or table does not exist');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async runTarget(sql, params = []) {
|
|
151
|
+
return new Promise((resolve, reject) => {
|
|
152
|
+
this.targetDb.run(sql, params, function(err) {
|
|
153
|
+
if (err) reject(err);
|
|
154
|
+
else resolve({ id: this.lastID, changes: this.changes });
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async allSource(sql, params = []) {
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
this.sourceDb.all(sql, params, (err, rows) => {
|
|
162
|
+
if (err) reject(err);
|
|
163
|
+
else resolve(rows);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async close() {
|
|
169
|
+
if (this.sourceDb) {
|
|
170
|
+
await new Promise((resolve) => this.sourceDb.close(resolve));
|
|
171
|
+
}
|
|
172
|
+
if (this.targetDb) {
|
|
173
|
+
await new Promise((resolve) => this.targetDb.close(resolve));
|
|
174
|
+
}
|
|
175
|
+
console.log('✅ Database connections closed');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async migrate() {
|
|
179
|
+
try {
|
|
180
|
+
await this.init();
|
|
181
|
+
await this.runSchema();
|
|
182
|
+
await this.migratePriorities();
|
|
183
|
+
await this.migrateLearning();
|
|
184
|
+
await this.migrateDecisions();
|
|
185
|
+
await this.migrateEvolution();
|
|
186
|
+
|
|
187
|
+
console.log('\n🎉 Migration completed successfully!');
|
|
188
|
+
console.log(`📁 New database: ${path.resolve(this.targetDbPath)}`);
|
|
189
|
+
} catch (err) {
|
|
190
|
+
console.error('\n❌ Migration failed:', err.message);
|
|
191
|
+
process.exit(1);
|
|
192
|
+
} finally {
|
|
193
|
+
await this.close();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// CLI usage
|
|
199
|
+
if (require.main === module) {
|
|
200
|
+
const sourceDb = process.argv[2];
|
|
201
|
+
const targetDb = process.argv[3] || './memory-v2.db';
|
|
202
|
+
|
|
203
|
+
if (!sourceDb) {
|
|
204
|
+
console.log('Usage: node migrations/v1-to-v2.js <source-v1.db> [target-v2.db]');
|
|
205
|
+
console.log('Example: node migrations/v1-to-v2.js ./memory-v1.db ./memory-v2.db');
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const migration = new MemoryMigration(sourceDb, targetDb);
|
|
210
|
+
migration.migrate();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = MemoryMigration;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memory-lucia",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Advanced memory system for OpenClaw agents with priority analysis, learning tracking, decision recording, and skill evolution",
|
|
5
5
|
"main": "api/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/
|
|
29
|
+
"url": "https://github.com/wen521/memory-lucia-.git"
|
|
30
30
|
},
|
|
31
31
|
"bugs": {
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/wen521/memory-lucia-/issues"
|
|
33
33
|
},
|
|
34
|
-
"homepage": "https://github.com/
|
|
34
|
+
"homepage": "https://github.com/wen521/memory-lucia-#readme"
|
|
35
35
|
}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
# Memory V2 API Reference
|
|
2
|
+
|
|
3
|
+
Complete API documentation for the Memory V2 system.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Initialization](#initialization)
|
|
8
|
+
- [Priority Module](#priority-module)
|
|
9
|
+
- [Learning Module](#learning-module)
|
|
10
|
+
- [Decision Module](#decision-module)
|
|
11
|
+
- [Evolution Module](#evolution-module)
|
|
12
|
+
- [Dashboard](#dashboard)
|
|
13
|
+
- [Version Management](#version-management)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Initialization
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const MemoryAPI = require('./api');
|
|
21
|
+
|
|
22
|
+
// Create instance
|
|
23
|
+
const api = new MemoryAPI('./memory-v2.db');
|
|
24
|
+
|
|
25
|
+
// Initialize database
|
|
26
|
+
await api.init();
|
|
27
|
+
|
|
28
|
+
// Close when done
|
|
29
|
+
await api.close();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Priority Module
|
|
35
|
+
|
|
36
|
+
### analyzePriority(message)
|
|
37
|
+
Analyze a message and return priority assessment.
|
|
38
|
+
|
|
39
|
+
**Parameters:**
|
|
40
|
+
- `message` (string): The message to analyze
|
|
41
|
+
|
|
42
|
+
**Returns:**
|
|
43
|
+
```javascript
|
|
44
|
+
{
|
|
45
|
+
priority_level: 'critical' | 'high' | 'medium' | 'low',
|
|
46
|
+
reasoning: string,
|
|
47
|
+
category: string
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### storePriority(msgId, convId, analysis)
|
|
52
|
+
Store priority analysis in database.
|
|
53
|
+
|
|
54
|
+
**Parameters:**
|
|
55
|
+
- `msgId` (string): Message ID
|
|
56
|
+
- `convId` (string): Conversation ID
|
|
57
|
+
- `analysis` (object): Result from analyzePriority
|
|
58
|
+
|
|
59
|
+
**Returns:** `Promise<{id: number}>`
|
|
60
|
+
|
|
61
|
+
### getHighPriority(limit = 10)
|
|
62
|
+
Get recent high/critical priority items.
|
|
63
|
+
|
|
64
|
+
**Parameters:**
|
|
65
|
+
- `limit` (number): Maximum results
|
|
66
|
+
|
|
67
|
+
**Returns:** `Promise<Array>`
|
|
68
|
+
|
|
69
|
+
### getPriorityStats()
|
|
70
|
+
Get priority distribution statistics.
|
|
71
|
+
|
|
72
|
+
**Returns:**
|
|
73
|
+
```javascript
|
|
74
|
+
{
|
|
75
|
+
critical: number,
|
|
76
|
+
high: number,
|
|
77
|
+
medium: number,
|
|
78
|
+
low: number,
|
|
79
|
+
total: number
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Learning Module
|
|
86
|
+
|
|
87
|
+
### startLearning(msgId, convId, message)
|
|
88
|
+
Start tracking a new learning topic.
|
|
89
|
+
|
|
90
|
+
**Parameters:**
|
|
91
|
+
- `msgId` (string): Message ID
|
|
92
|
+
- `convId` (string): Conversation ID
|
|
93
|
+
- `message` (string): Message describing the learning topic
|
|
94
|
+
|
|
95
|
+
**Returns:**
|
|
96
|
+
```javascript
|
|
97
|
+
{
|
|
98
|
+
id: number,
|
|
99
|
+
topic: string,
|
|
100
|
+
status: 'active',
|
|
101
|
+
progress: 0
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### updateLearningProgress(learningId, updates)
|
|
106
|
+
Update learning progress.
|
|
107
|
+
|
|
108
|
+
**Parameters:**
|
|
109
|
+
- `learningId` (number): Learning record ID
|
|
110
|
+
- `updates` (object):
|
|
111
|
+
- `progress` (number): 0-100
|
|
112
|
+
- `status` (string): 'active' | 'paused' | 'completed' | 'abandoned'
|
|
113
|
+
|
|
114
|
+
### addMilestone(learningId, milestone)
|
|
115
|
+
Add a milestone to a learning record.
|
|
116
|
+
|
|
117
|
+
**Parameters:**
|
|
118
|
+
- `learningId` (number): Learning record ID
|
|
119
|
+
- `milestone` (object):
|
|
120
|
+
- `title` (string): Milestone title
|
|
121
|
+
- `description` (string): Optional description
|
|
122
|
+
|
|
123
|
+
### getActiveLearning(limit = 5)
|
|
124
|
+
Get currently active learning topics.
|
|
125
|
+
|
|
126
|
+
**Parameters:**
|
|
127
|
+
- `limit` (number): Maximum results
|
|
128
|
+
|
|
129
|
+
**Returns:** `Promise<Array>`
|
|
130
|
+
|
|
131
|
+
### getLearningStats()
|
|
132
|
+
Get learning statistics.
|
|
133
|
+
|
|
134
|
+
**Returns:**
|
|
135
|
+
```javascript
|
|
136
|
+
{
|
|
137
|
+
active: number,
|
|
138
|
+
completed: number,
|
|
139
|
+
total: number,
|
|
140
|
+
avg_progress: number
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Decision Module
|
|
147
|
+
|
|
148
|
+
### recordDecision(msgId, convId, decisionData)
|
|
149
|
+
Record a new decision.
|
|
150
|
+
|
|
151
|
+
**Parameters:**
|
|
152
|
+
- `msgId` (string): Message ID
|
|
153
|
+
- `convId` (string): Conversation ID
|
|
154
|
+
- `decisionData` (object):
|
|
155
|
+
- `summary` (string): Decision summary (required)
|
|
156
|
+
- `context` (string): Decision context
|
|
157
|
+
- `expectedOutcome` (string): Expected result
|
|
158
|
+
- `reviewDate` (string): ISO date for review
|
|
159
|
+
|
|
160
|
+
**Returns:** `Promise<{id: number}>`
|
|
161
|
+
|
|
162
|
+
### updateDecisionOutcome(decisionId, outcome)
|
|
163
|
+
Update the actual outcome of a decision.
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
- `decisionId` (number): Decision ID
|
|
167
|
+
- `outcome` (object):
|
|
168
|
+
- `actualOutcome` (string): What actually happened
|
|
169
|
+
- `status` (string): 'implemented' | 'validated' | 'rejected'
|
|
170
|
+
|
|
171
|
+
### getPendingDecisions()
|
|
172
|
+
Get decisions pending review or implementation.
|
|
173
|
+
|
|
174
|
+
**Returns:** `Promise<Array>`
|
|
175
|
+
|
|
176
|
+
### scheduleReview(decisionId, reviewDate)
|
|
177
|
+
Schedule a review for a decision.
|
|
178
|
+
|
|
179
|
+
**Parameters:**
|
|
180
|
+
- `decisionId` (number): Decision ID
|
|
181
|
+
- `reviewDate` (string): ISO date string
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Evolution Module
|
|
186
|
+
|
|
187
|
+
### recordSkillUsage(skillName, category, result)
|
|
188
|
+
Record skill usage.
|
|
189
|
+
|
|
190
|
+
**Parameters:**
|
|
191
|
+
- `skillName` (string): Name of the skill
|
|
192
|
+
- `category` (string): Skill category
|
|
193
|
+
- `result` (string): 'success' | 'failure'
|
|
194
|
+
|
|
195
|
+
### getTopSkills(limit = 10)
|
|
196
|
+
Get most frequently used skills.
|
|
197
|
+
|
|
198
|
+
**Parameters:**
|
|
199
|
+
- `limit` (number): Maximum results
|
|
200
|
+
|
|
201
|
+
**Returns:** `Promise<Array>`
|
|
202
|
+
|
|
203
|
+
### getSkillStats(skillName)
|
|
204
|
+
Get statistics for a specific skill.
|
|
205
|
+
|
|
206
|
+
**Parameters:**
|
|
207
|
+
- `skillName` (string): Skill name
|
|
208
|
+
|
|
209
|
+
**Returns:**
|
|
210
|
+
```javascript
|
|
211
|
+
{
|
|
212
|
+
skill_name: string,
|
|
213
|
+
category: string,
|
|
214
|
+
usage_count: number,
|
|
215
|
+
success_count: number,
|
|
216
|
+
success_rate: number,
|
|
217
|
+
last_used_at: string
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Dashboard
|
|
224
|
+
|
|
225
|
+
### getDashboard()
|
|
226
|
+
Get unified dashboard of all memory data.
|
|
227
|
+
|
|
228
|
+
**Returns:**
|
|
229
|
+
```javascript
|
|
230
|
+
{
|
|
231
|
+
summary: {
|
|
232
|
+
total_priorities: number,
|
|
233
|
+
total_learning: number,
|
|
234
|
+
total_decisions: number,
|
|
235
|
+
total_skills: number
|
|
236
|
+
},
|
|
237
|
+
recent: {
|
|
238
|
+
priorities: Array,
|
|
239
|
+
learning: Array,
|
|
240
|
+
decisions: Array
|
|
241
|
+
},
|
|
242
|
+
stats: {
|
|
243
|
+
priorities: Object,
|
|
244
|
+
learning: Object,
|
|
245
|
+
skills: Array
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Version Management
|
|
253
|
+
|
|
254
|
+
### createBackup(label)
|
|
255
|
+
Create a database backup.
|
|
256
|
+
|
|
257
|
+
**Parameters:**
|
|
258
|
+
- `label` (string): Optional label for the backup
|
|
259
|
+
|
|
260
|
+
**Returns:** `Promise<{backupPath: string}>`
|
|
261
|
+
|
|
262
|
+
### listBackups()
|
|
263
|
+
List all available backups.
|
|
264
|
+
|
|
265
|
+
**Returns:** `Promise<Array>`
|
|
266
|
+
|
|
267
|
+
### restoreBackup(backupPath)
|
|
268
|
+
Restore from a backup.
|
|
269
|
+
|
|
270
|
+
**Parameters:**
|
|
271
|
+
- `backupPath` (string): Path to backup file
|
|
272
|
+
|
|
273
|
+
**Returns:** `Promise<boolean>`
|
|
274
|
+
|
|
275
|
+
### cleanupBackups(keepCount = 10)
|
|
276
|
+
Clean up old backups, keeping only the specified number.
|
|
277
|
+
|
|
278
|
+
**Parameters:**
|
|
279
|
+
- `keepCount` (number): Number of backups to keep
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Database Views
|
|
284
|
+
|
|
285
|
+
The following SQL views are available for direct queries:
|
|
286
|
+
|
|
287
|
+
### v_pending_decisions
|
|
288
|
+
Decisions that need attention (pending, overdue, or due soon).
|
|
289
|
+
|
|
290
|
+
### v_skill_summary
|
|
291
|
+
Skill usage statistics with success rates.
|
|
292
|
+
|
|
293
|
+
### v_weekly_learning_report
|
|
294
|
+
Learning activity summary for the past week.
|
|
295
|
+
|
|
296
|
+
### v_high_priority
|
|
297
|
+
Combined view of high priority items and pending decisions.
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Error Handling
|
|
302
|
+
|
|
303
|
+
All API methods return Promises and may throw:
|
|
304
|
+
|
|
305
|
+
```javascript
|
|
306
|
+
try {
|
|
307
|
+
const result = await api.storePriority(msgId, convId, analysis);
|
|
308
|
+
} catch (err) {
|
|
309
|
+
console.error('API Error:', err.message);
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Common errors:
|
|
314
|
+
- Database not initialized
|
|
315
|
+
- Invalid parameters
|
|
316
|
+
- Constraint violations
|
|
317
|
+
- File system errors (backups)
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Examples
|
|
322
|
+
|
|
323
|
+
### Complete Workflow
|
|
324
|
+
|
|
325
|
+
```javascript
|
|
326
|
+
const MemoryAPI = require('./api');
|
|
327
|
+
const api = new MemoryAPI('./memory-v2.db');
|
|
328
|
+
|
|
329
|
+
async function example() {
|
|
330
|
+
await api.init();
|
|
331
|
+
|
|
332
|
+
// Record a decision
|
|
333
|
+
const decision = await api.recordDecision('msg-123', 'conv-456', {
|
|
334
|
+
summary: 'Use SQLite for local storage',
|
|
335
|
+
context: 'Need embedded database for skill',
|
|
336
|
+
expectedOutcome: 'Simpler deployment'
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// Start learning
|
|
340
|
+
const learning = await api.startLearning('msg-124', 'conv-456',
|
|
341
|
+
'Learning SQLite advanced features'
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
// Update progress
|
|
345
|
+
await api.updateLearningProgress(learning.id, { progress: 50 });
|
|
346
|
+
|
|
347
|
+
// Record skill usage
|
|
348
|
+
await api.recordSkillUsage('memory-v2', 'storage', 'success');
|
|
349
|
+
|
|
350
|
+
// Get dashboard
|
|
351
|
+
const dashboard = await api.getDashboard();
|
|
352
|
+
console.log(dashboard);
|
|
353
|
+
|
|
354
|
+
await api.close();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
example();
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## License
|
|
363
|
+
|
|
364
|
+
MIT
|
package/NPM-PUBLISH-GUIDE.md
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
# Memory V2 Skill - NPM 发布指南
|
|
2
|
-
|
|
3
|
-
> 将 Memory V2 发布为 npm 包,供 ClawHub Skill 使用
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 📋 发现:ClawHub Skill 格式
|
|
8
|
-
|
|
9
|
-
**ClawHub 上的 Skill 只有 SKILL.md**,代码通过 npm 安装。
|
|
10
|
-
|
|
11
|
-
### 标准结构
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
clawhub-skill/
|
|
15
|
-
└── SKILL.md # 只有描述文件
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### npm 包结构
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
memory-v2/ # npm 包
|
|
22
|
-
├── package.json
|
|
23
|
-
├── README.md
|
|
24
|
-
├── LICENSE
|
|
25
|
-
├── api/
|
|
26
|
-
│ └── index.js # 主入口
|
|
27
|
-
├── modules/ # 核心模块
|
|
28
|
-
└── ...
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## 🚀 发布流程
|
|
34
|
-
|
|
35
|
-
### 步骤 1: 准备 npm 包
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
cd memory-v2-skill
|
|
39
|
-
|
|
40
|
-
# 1. 确保 package.json 正确
|
|
41
|
-
# 2. 更新版本号
|
|
42
|
-
npm version 2.0.0
|
|
43
|
-
|
|
44
|
-
# 3. 创建 .npmignore
|
|
45
|
-
echo "tests/" > .npmignore
|
|
46
|
-
echo "backups/" >> .npmignore
|
|
47
|
-
echo "*.db" >> .npmignore
|
|
48
|
-
|
|
49
|
-
# 4. 发布到 npm
|
|
50
|
-
npm publish
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 步骤 2: 创建 ClawHub Skill
|
|
54
|
-
|
|
55
|
-
创建 `clawhub-memory-v2/` 目录,只包含 SKILL.md:
|
|
56
|
-
|
|
57
|
-
```yaml
|
|
58
|
-
---
|
|
59
|
-
name: memory-v2
|
|
60
|
-
description: |
|
|
61
|
-
Advanced memory system for OpenClaw agents with priority analysis,
|
|
62
|
-
learning tracking, decision recording, and skill evolution.
|
|
63
|
-
Use when: (1) Tracking learning progress and milestones, (2) Recording decisions with outcomes,
|
|
64
|
-
(3) Analyzing message priorities, (4) Monitoring skill usage and growth.
|
|
65
|
-
Requires: npm install memory-v2-skill
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
# Memory V2
|
|
69
|
-
|
|
70
|
-
## Installation
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
npm install memory-v2-skill
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Usage
|
|
77
|
-
|
|
78
|
-
```javascript
|
|
79
|
-
const MemoryAPI = require('memory-v2-skill');
|
|
80
|
-
|
|
81
|
-
const api = new MemoryAPI('./memory-v2.db');
|
|
82
|
-
await api.init();
|
|
83
|
-
|
|
84
|
-
// Track learning
|
|
85
|
-
await api.startLearning(msgId, convId, message);
|
|
86
|
-
|
|
87
|
-
// Record decision
|
|
88
|
-
await api.recordDecision(msgId, convId, decisionData);
|
|
89
|
-
|
|
90
|
-
// Get dashboard
|
|
91
|
-
const dashboard = await api.getDashboard();
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## API
|
|
95
|
-
|
|
96
|
-
See: https://github.com/YOUR_USERNAME/memory-v2-skill#api
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### 步骤 3: 打包并提交
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# 打包 ClawHub Skill
|
|
103
|
-
cd clawhub-memory-v2
|
|
104
|
-
zip ../memory-v2.skill SKILL.md
|
|
105
|
-
|
|
106
|
-
# 提交到 ClawHub
|
|
107
|
-
# 上传 memory-v2.skill 文件
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## 📦 两种发布方式对比
|
|
113
|
-
|
|
114
|
-
| 方式 | 适用场景 | 复杂度 |
|
|
115
|
-
|------|---------|--------|
|
|
116
|
-
| **npm + ClawHub** | 正式发布,用户易安装 | 高 |
|
|
117
|
-
| **GitHub 直接安装** | 快速分享,开发者使用 | 低 |
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## 🎯 推荐方案:GitHub 直接安装
|
|
122
|
-
|
|
123
|
-
对于 Memory V2,推荐直接 GitHub 安装:
|
|
124
|
-
|
|
125
|
-
### 用户使用
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
# 克隆到 skills 目录
|
|
129
|
-
cd ~/.openclaw/skills
|
|
130
|
-
git clone https://github.com/YOUR_USERNAME/memory-v2-skill.git memory-v2
|
|
131
|
-
|
|
132
|
-
# 安装依赖
|
|
133
|
-
cd memory-v2
|
|
134
|
-
npm install
|
|
135
|
-
|
|
136
|
-
# 使用
|
|
137
|
-
const MemoryAPI = require('memory-v2');
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 优点
|
|
141
|
-
- 无需 npm 账号
|
|
142
|
-
- 无需打包
|
|
143
|
-
- 用户可直接修改
|
|
144
|
-
- 适合自用和分享
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
## ✅ 当前状态
|
|
149
|
-
|
|
150
|
-
您的 `memory-v2-skill/` 已经可以直接使用:
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
# 本地测试
|
|
154
|
-
cd memory-v2-skill
|
|
155
|
-
npm install
|
|
156
|
-
node -e "const M = require('./api'); console.log('OK')"
|
|
157
|
-
|
|
158
|
-
# 打包 (zip 格式)
|
|
159
|
-
zip -r memory-v2.skill . -x "*.db" "node_modules/*"
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
**用户安装后可以直接使用!**
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
## 📚 参考
|
|
167
|
-
|
|
168
|
-
- npm 发布: https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry
|
|
169
|
-
- ClawHub: https://clawhub.com
|
package/PUBLISH-STEPS.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Memory Lucia 发布步骤
|
|
2
|
-
|
|
3
|
-
## 🚀 一键发布
|
|
4
|
-
|
|
5
|
-
在 `memory-v2-skill` 目录下执行:
|
|
6
|
-
|
|
7
|
-
### Windows
|
|
8
|
-
```bash
|
|
9
|
-
publish.bat
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
### Linux/Mac
|
|
13
|
-
```bash
|
|
14
|
-
bash publish.sh
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## 📋 手动发布步骤
|
|
20
|
-
|
|
21
|
-
### 步骤 1: 进入目录
|
|
22
|
-
```bash
|
|
23
|
-
cd C:\Users\snowya\.openclaw\workspace-chief_of_staff\memory-v2-skill
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### 步骤 2: 登录 npm
|
|
27
|
-
```bash
|
|
28
|
-
npm login --auth-type=legacy
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
**输入信息:**
|
|
32
|
-
- Username: `712724810@qq.com`
|
|
33
|
-
- Password: `Q6Ymk#x_4dqM#T@`
|
|
34
|
-
- Email: `712724810@qq.com`
|
|
35
|
-
- Enter one-time password: (如果开启 2FA,输入验证码)
|
|
36
|
-
|
|
37
|
-
### 步骤 3: 发布
|
|
38
|
-
```bash
|
|
39
|
-
npm publish --access=public
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## ✅ 验证发布
|
|
45
|
-
|
|
46
|
-
发布成功后,访问:
|
|
47
|
-
https://www.npmjs.com/package/memory-lucia
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## 📦 用户使用
|
|
52
|
-
|
|
53
|
-
发布后,用户可以直接安装:
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
npm install memory-lucia
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
const MemoryAPI = require('memory-lucia');
|
|
61
|
-
const api = new MemoryAPI('./memory.db');
|
|
62
|
-
await api.init();
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
## 🔧 如果发布失败
|
|
68
|
-
|
|
69
|
-
### 错误 1: 包名已存在
|
|
70
|
-
```bash
|
|
71
|
-
# 修改 package.json 中的 name
|
|
72
|
-
# 或者使用 scoped name: @yourname/memory-lucia
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### 错误 2: 未登录
|
|
76
|
-
```bash
|
|
77
|
-
npm login --auth-type=legacy
|
|
78
|
-
# 重新登录
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### 错误 3: 版本已存在
|
|
82
|
-
```bash
|
|
83
|
-
# 更新版本号
|
|
84
|
-
npm version patch # 2.0.0 -> 2.0.1
|
|
85
|
-
npm publish
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## 📊 发布信息
|
|
91
|
-
|
|
92
|
-
| 属性 | 值 |
|
|
93
|
-
|------|-----|
|
|
94
|
-
| 包名 | `memory-lucia` |
|
|
95
|
-
| 版本 | `2.0.0` |
|
|
96
|
-
| 大小 | 14.4 KB |
|
|
97
|
-
| 主入口 | `api/index.js` |
|
|
98
|
-
| 依赖 | `sqlite3` |
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
**执行 `publish.bat` 或 `publish.sh` 即可发布!**
|
package/publish-with-otp.bat
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
@echo off
|
|
2
|
-
echo 🚀 Publishing memory-lucia to npm...
|
|
3
|
-
echo.
|
|
4
|
-
echo This package requires 2FA authentication.
|
|
5
|
-
echo.
|
|
6
|
-
echo Please enter your 6-digit 2FA code from your Authenticator app:
|
|
7
|
-
set /p OTP="2FA Code: "
|
|
8
|
-
echo.
|
|
9
|
-
echo Publishing with OTP: %OTP%
|
|
10
|
-
npm publish --access=public --otp=%OTP%
|
|
11
|
-
echo.
|
|
12
|
-
echo ✅ Done!
|
|
13
|
-
pause
|
package/publish.bat
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
@echo off
|
|
2
|
-
echo 🚀 Publishing memory-lucia to npm...
|
|
3
|
-
echo.
|
|
4
|
-
|
|
5
|
-
echo Logging in to npm...
|
|
6
|
-
npm login --auth-type=legacy
|
|
7
|
-
|
|
8
|
-
echo.
|
|
9
|
-
echo Publishing package...
|
|
10
|
-
npm publish --access=public
|
|
11
|
-
|
|
12
|
-
echo.
|
|
13
|
-
echo ✅ Published!
|
|
14
|
-
echo.
|
|
15
|
-
echo Users can now install with:
|
|
16
|
-
echo npm install memory-lucia
|
|
17
|
-
pause
|
package/publish.sh
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# Memory Lucia Publish Script
|
|
3
|
-
|
|
4
|
-
echo "🚀 Publishing memory-lucia to npm..."
|
|
5
|
-
echo ""
|
|
6
|
-
|
|
7
|
-
# Login
|
|
8
|
-
echo "Logging in to npm..."
|
|
9
|
-
npm login --auth-type=legacy
|
|
10
|
-
|
|
11
|
-
# Publish
|
|
12
|
-
echo ""
|
|
13
|
-
echo "Publishing package..."
|
|
14
|
-
npm publish --access=public
|
|
15
|
-
|
|
16
|
-
echo ""
|
|
17
|
-
echo "✅ Published!"
|
|
18
|
-
echo ""
|
|
19
|
-
echo "Users can now install with:"
|
|
20
|
-
echo " npm install memory-lucia"
|