kiro-memory 1.0.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/LICENSE +661 -0
- package/README.md +290 -0
- package/package.json +117 -0
- package/plugin/dist/cli/contextkit.js +1259 -0
- package/plugin/dist/hooks/agentSpawn.js +1187 -0
- package/plugin/dist/hooks/kiro-hooks.js +1184 -0
- package/plugin/dist/hooks/postToolUse.js +1219 -0
- package/plugin/dist/hooks/stop.js +1163 -0
- package/plugin/dist/hooks/userPromptSubmit.js +1152 -0
- package/plugin/dist/index.js +2103 -0
- package/plugin/dist/sdk/index.js +1083 -0
- package/plugin/dist/servers/mcp-server.js +266 -0
- package/plugin/dist/services/search/ChromaManager.js +357 -0
- package/plugin/dist/services/search/HybridSearch.js +502 -0
- package/plugin/dist/services/search/index.js +511 -0
- package/plugin/dist/services/sqlite/Database.js +625 -0
- package/plugin/dist/services/sqlite/Observations.js +46 -0
- package/plugin/dist/services/sqlite/Prompts.js +39 -0
- package/plugin/dist/services/sqlite/Search.js +143 -0
- package/plugin/dist/services/sqlite/Sessions.js +60 -0
- package/plugin/dist/services/sqlite/Summaries.js +44 -0
- package/plugin/dist/services/sqlite/index.js +951 -0
- package/plugin/dist/shared/paths.js +315 -0
- package/plugin/dist/types/worker-types.js +0 -0
- package/plugin/dist/utils/logger.js +222 -0
- package/plugin/dist/viewer.html +252 -0
- package/plugin/dist/viewer.js +23965 -0
- package/plugin/dist/worker-service.js +1782 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// src/services/sqlite/Search.ts
|
|
2
|
+
function searchObservationsFTS(db, query, filters = {}) {
|
|
3
|
+
const limit = filters.limit || 50;
|
|
4
|
+
try {
|
|
5
|
+
let sql = `
|
|
6
|
+
SELECT o.* FROM observations o
|
|
7
|
+
JOIN observations_fts fts ON o.id = fts.rowid
|
|
8
|
+
WHERE observations_fts MATCH ?
|
|
9
|
+
`;
|
|
10
|
+
const params = [query];
|
|
11
|
+
if (filters.project) {
|
|
12
|
+
sql += " AND o.project = ?";
|
|
13
|
+
params.push(filters.project);
|
|
14
|
+
}
|
|
15
|
+
if (filters.type) {
|
|
16
|
+
sql += " AND o.type = ?";
|
|
17
|
+
params.push(filters.type);
|
|
18
|
+
}
|
|
19
|
+
if (filters.dateStart) {
|
|
20
|
+
sql += " AND o.created_at_epoch >= ?";
|
|
21
|
+
params.push(filters.dateStart);
|
|
22
|
+
}
|
|
23
|
+
if (filters.dateEnd) {
|
|
24
|
+
sql += " AND o.created_at_epoch <= ?";
|
|
25
|
+
params.push(filters.dateEnd);
|
|
26
|
+
}
|
|
27
|
+
sql += " ORDER BY rank LIMIT ?";
|
|
28
|
+
params.push(limit);
|
|
29
|
+
const stmt = db.query(sql);
|
|
30
|
+
return stmt.all(...params);
|
|
31
|
+
} catch {
|
|
32
|
+
return searchObservationsLIKE(db, query, filters);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function searchObservationsLIKE(db, query, filters = {}) {
|
|
36
|
+
const limit = filters.limit || 50;
|
|
37
|
+
const pattern = `%${query}%`;
|
|
38
|
+
let sql = `
|
|
39
|
+
SELECT * FROM observations
|
|
40
|
+
WHERE (title LIKE ? OR text LIKE ? OR narrative LIKE ? OR concepts LIKE ?)
|
|
41
|
+
`;
|
|
42
|
+
const params = [pattern, pattern, pattern, pattern];
|
|
43
|
+
if (filters.project) {
|
|
44
|
+
sql += " AND project = ?";
|
|
45
|
+
params.push(filters.project);
|
|
46
|
+
}
|
|
47
|
+
if (filters.type) {
|
|
48
|
+
sql += " AND type = ?";
|
|
49
|
+
params.push(filters.type);
|
|
50
|
+
}
|
|
51
|
+
if (filters.dateStart) {
|
|
52
|
+
sql += " AND created_at_epoch >= ?";
|
|
53
|
+
params.push(filters.dateStart);
|
|
54
|
+
}
|
|
55
|
+
if (filters.dateEnd) {
|
|
56
|
+
sql += " AND created_at_epoch <= ?";
|
|
57
|
+
params.push(filters.dateEnd);
|
|
58
|
+
}
|
|
59
|
+
sql += " ORDER BY created_at_epoch DESC LIMIT ?";
|
|
60
|
+
params.push(limit);
|
|
61
|
+
const stmt = db.query(sql);
|
|
62
|
+
return stmt.all(...params);
|
|
63
|
+
}
|
|
64
|
+
function searchSummariesFiltered(db, query, filters = {}) {
|
|
65
|
+
const limit = filters.limit || 20;
|
|
66
|
+
const pattern = `%${query}%`;
|
|
67
|
+
let sql = `
|
|
68
|
+
SELECT * FROM summaries
|
|
69
|
+
WHERE (request LIKE ? OR learned LIKE ? OR completed LIKE ? OR notes LIKE ? OR next_steps LIKE ?)
|
|
70
|
+
`;
|
|
71
|
+
const params = [pattern, pattern, pattern, pattern, pattern];
|
|
72
|
+
if (filters.project) {
|
|
73
|
+
sql += " AND project = ?";
|
|
74
|
+
params.push(filters.project);
|
|
75
|
+
}
|
|
76
|
+
if (filters.dateStart) {
|
|
77
|
+
sql += " AND created_at_epoch >= ?";
|
|
78
|
+
params.push(filters.dateStart);
|
|
79
|
+
}
|
|
80
|
+
if (filters.dateEnd) {
|
|
81
|
+
sql += " AND created_at_epoch <= ?";
|
|
82
|
+
params.push(filters.dateEnd);
|
|
83
|
+
}
|
|
84
|
+
sql += " ORDER BY created_at_epoch DESC LIMIT ?";
|
|
85
|
+
params.push(limit);
|
|
86
|
+
const stmt = db.query(sql);
|
|
87
|
+
return stmt.all(...params);
|
|
88
|
+
}
|
|
89
|
+
function getObservationsByIds(db, ids) {
|
|
90
|
+
if (ids.length === 0) return [];
|
|
91
|
+
const placeholders = ids.map(() => "?").join(",");
|
|
92
|
+
const sql = `SELECT * FROM observations WHERE id IN (${placeholders}) ORDER BY created_at_epoch DESC`;
|
|
93
|
+
const stmt = db.query(sql);
|
|
94
|
+
return stmt.all(...ids);
|
|
95
|
+
}
|
|
96
|
+
function getTimeline(db, anchorId, depthBefore = 5, depthAfter = 5) {
|
|
97
|
+
const anchorStmt = db.query("SELECT created_at_epoch FROM observations WHERE id = ?");
|
|
98
|
+
const anchor = anchorStmt.get(anchorId);
|
|
99
|
+
if (!anchor) return [];
|
|
100
|
+
const anchorEpoch = anchor.created_at_epoch;
|
|
101
|
+
const beforeStmt = db.query(`
|
|
102
|
+
SELECT id, 'observation' as type, title, text as content, project, created_at, created_at_epoch
|
|
103
|
+
FROM observations
|
|
104
|
+
WHERE created_at_epoch < ?
|
|
105
|
+
ORDER BY created_at_epoch DESC
|
|
106
|
+
LIMIT ?
|
|
107
|
+
`);
|
|
108
|
+
const before = beforeStmt.all(anchorEpoch, depthBefore).reverse();
|
|
109
|
+
const selfStmt = db.query(`
|
|
110
|
+
SELECT id, 'observation' as type, title, text as content, project, created_at, created_at_epoch
|
|
111
|
+
FROM observations WHERE id = ?
|
|
112
|
+
`);
|
|
113
|
+
const self = selfStmt.all(anchorId);
|
|
114
|
+
const afterStmt = db.query(`
|
|
115
|
+
SELECT id, 'observation' as type, title, text as content, project, created_at, created_at_epoch
|
|
116
|
+
FROM observations
|
|
117
|
+
WHERE created_at_epoch > ?
|
|
118
|
+
ORDER BY created_at_epoch ASC
|
|
119
|
+
LIMIT ?
|
|
120
|
+
`);
|
|
121
|
+
const after = afterStmt.all(anchorEpoch, depthAfter);
|
|
122
|
+
return [...before, ...self, ...after];
|
|
123
|
+
}
|
|
124
|
+
function getProjectStats(db, project) {
|
|
125
|
+
const obsStmt = db.query("SELECT COUNT(*) as count FROM observations WHERE project = ?");
|
|
126
|
+
const sumStmt = db.query("SELECT COUNT(*) as count FROM summaries WHERE project = ?");
|
|
127
|
+
const sesStmt = db.query("SELECT COUNT(*) as count FROM sessions WHERE project = ?");
|
|
128
|
+
const prmStmt = db.query("SELECT COUNT(*) as count FROM prompts WHERE project = ?");
|
|
129
|
+
return {
|
|
130
|
+
observations: obsStmt.get(project)?.count || 0,
|
|
131
|
+
summaries: sumStmt.get(project)?.count || 0,
|
|
132
|
+
sessions: sesStmt.get(project)?.count || 0,
|
|
133
|
+
prompts: prmStmt.get(project)?.count || 0
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
getObservationsByIds,
|
|
138
|
+
getProjectStats,
|
|
139
|
+
getTimeline,
|
|
140
|
+
searchObservationsFTS,
|
|
141
|
+
searchObservationsLIKE,
|
|
142
|
+
searchSummariesFiltered
|
|
143
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/services/sqlite/Sessions.ts
|
|
2
|
+
function createSession(db, contentSessionId, project, userPrompt) {
|
|
3
|
+
const now = /* @__PURE__ */ new Date();
|
|
4
|
+
const result = db.run(
|
|
5
|
+
`INSERT INTO sessions (content_session_id, project, user_prompt, status, started_at, started_at_epoch)
|
|
6
|
+
VALUES (?, ?, ?, 'active', ?, ?)`,
|
|
7
|
+
[contentSessionId, project, userPrompt, now.toISOString(), now.getTime()]
|
|
8
|
+
);
|
|
9
|
+
return Number(result.lastInsertRowid);
|
|
10
|
+
}
|
|
11
|
+
function getSessionByContentId(db, contentSessionId) {
|
|
12
|
+
const query = db.query("SELECT * FROM sessions WHERE content_session_id = ?");
|
|
13
|
+
return query.get(contentSessionId);
|
|
14
|
+
}
|
|
15
|
+
function getSessionById(db, id) {
|
|
16
|
+
const query = db.query("SELECT * FROM sessions WHERE id = ?");
|
|
17
|
+
return query.get(id);
|
|
18
|
+
}
|
|
19
|
+
function updateSessionMemoryId(db, id, memorySessionId) {
|
|
20
|
+
db.run(
|
|
21
|
+
"UPDATE sessions SET memory_session_id = ? WHERE id = ?",
|
|
22
|
+
[memorySessionId, id]
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function completeSession(db, id) {
|
|
26
|
+
const now = /* @__PURE__ */ new Date();
|
|
27
|
+
db.run(
|
|
28
|
+
`UPDATE sessions
|
|
29
|
+
SET status = 'completed', completed_at = ?, completed_at_epoch = ?
|
|
30
|
+
WHERE id = ?`,
|
|
31
|
+
[now.toISOString(), now.getTime(), id]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function failSession(db, id) {
|
|
35
|
+
const now = /* @__PURE__ */ new Date();
|
|
36
|
+
db.run(
|
|
37
|
+
`UPDATE sessions
|
|
38
|
+
SET status = 'failed', completed_at = ?, completed_at_epoch = ?
|
|
39
|
+
WHERE id = ?`,
|
|
40
|
+
[now.toISOString(), now.getTime(), id]
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function getActiveSessions(db) {
|
|
44
|
+
const query = db.query("SELECT * FROM sessions WHERE status = 'active' ORDER BY started_at_epoch DESC");
|
|
45
|
+
return query.all();
|
|
46
|
+
}
|
|
47
|
+
function getSessionsByProject(db, project, limit = 100) {
|
|
48
|
+
const query = db.query("SELECT * FROM sessions WHERE project = ? ORDER BY started_at_epoch DESC LIMIT ?");
|
|
49
|
+
return query.all(project, limit);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
completeSession,
|
|
53
|
+
createSession,
|
|
54
|
+
failSession,
|
|
55
|
+
getActiveSessions,
|
|
56
|
+
getSessionByContentId,
|
|
57
|
+
getSessionById,
|
|
58
|
+
getSessionsByProject,
|
|
59
|
+
updateSessionMemoryId
|
|
60
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/services/sqlite/Summaries.ts
|
|
2
|
+
function createSummary(db, sessionId, project, request, investigated, learned, completed, nextSteps, notes) {
|
|
3
|
+
const now = /* @__PURE__ */ new Date();
|
|
4
|
+
const result = db.run(
|
|
5
|
+
`INSERT INTO summaries
|
|
6
|
+
(session_id, project, request, investigated, learned, completed, next_steps, notes, created_at, created_at_epoch)
|
|
7
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
8
|
+
[sessionId, project, request, investigated, learned, completed, nextSteps, notes, now.toISOString(), now.getTime()]
|
|
9
|
+
);
|
|
10
|
+
return Number(result.lastInsertRowid);
|
|
11
|
+
}
|
|
12
|
+
function getSummaryBySession(db, sessionId) {
|
|
13
|
+
const query = db.query("SELECT * FROM summaries WHERE session_id = ? ORDER BY created_at_epoch DESC LIMIT 1");
|
|
14
|
+
return query.get(sessionId);
|
|
15
|
+
}
|
|
16
|
+
function getSummariesByProject(db, project, limit = 50) {
|
|
17
|
+
const query = db.query(
|
|
18
|
+
"SELECT * FROM summaries WHERE project = ? ORDER BY created_at_epoch DESC LIMIT ?"
|
|
19
|
+
);
|
|
20
|
+
return query.all(project, limit);
|
|
21
|
+
}
|
|
22
|
+
function searchSummaries(db, searchTerm, project) {
|
|
23
|
+
const sql = project ? `SELECT * FROM summaries
|
|
24
|
+
WHERE project = ? AND (request LIKE ? OR learned LIKE ? OR completed LIKE ? OR notes LIKE ?)
|
|
25
|
+
ORDER BY created_at_epoch DESC` : `SELECT * FROM summaries
|
|
26
|
+
WHERE request LIKE ? OR learned LIKE ? OR completed LIKE ? OR notes LIKE ?
|
|
27
|
+
ORDER BY created_at_epoch DESC`;
|
|
28
|
+
const pattern = `%${searchTerm}%`;
|
|
29
|
+
const query = db.query(sql);
|
|
30
|
+
if (project) {
|
|
31
|
+
return query.all(project, pattern, pattern, pattern, pattern);
|
|
32
|
+
}
|
|
33
|
+
return query.all(pattern, pattern, pattern, pattern);
|
|
34
|
+
}
|
|
35
|
+
function deleteSummary(db, id) {
|
|
36
|
+
db.run("DELETE FROM summaries WHERE id = ?", [id]);
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
createSummary,
|
|
40
|
+
deleteSummary,
|
|
41
|
+
getSummariesByProject,
|
|
42
|
+
getSummaryBySession,
|
|
43
|
+
searchSummaries
|
|
44
|
+
};
|