@kisev/memomatic 1.0.0-dev.61.gdf462654550b → 1.0.0-dev.62.g445d44a8adf0
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/dist/executor.js +13 -3
- package/dist/ingest.js +30 -6
- package/package.json +2 -2
package/dist/executor.js
CHANGED
|
@@ -23,16 +23,26 @@ export class OpenCodeExecutor {
|
|
|
23
23
|
this.options = options;
|
|
24
24
|
}
|
|
25
25
|
async complete(request) {
|
|
26
|
-
const args = ["run", "--agent", "build"];
|
|
26
|
+
const args = ["run", "--agent", "build", "--format", "json"];
|
|
27
27
|
if (this.options.model)
|
|
28
28
|
args.push("--model", this.options.model);
|
|
29
29
|
if (this.options.variant)
|
|
30
30
|
args.push("--variant", this.options.variant);
|
|
31
|
-
args.push("--
|
|
31
|
+
args.push("--", `[memomatic-internal] ${request.system}\n\n${request.prompt}`);
|
|
32
32
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
33
33
|
const output = await this.spawnOnce(args);
|
|
34
34
|
try {
|
|
35
|
-
const
|
|
35
|
+
const texts = [];
|
|
36
|
+
for (const line of output.split("\n")) {
|
|
37
|
+
if (!line.trim())
|
|
38
|
+
continue;
|
|
39
|
+
const event = JSON.parse(line);
|
|
40
|
+
if (event.type === "error")
|
|
41
|
+
throw new Error("opencode returned an error event");
|
|
42
|
+
if (event.type === "text" && typeof event.part?.text === "string")
|
|
43
|
+
texts.push(event.part.text);
|
|
44
|
+
}
|
|
45
|
+
const parsed = extractJson(texts.join("\n"));
|
|
36
46
|
return JSON.stringify(parsed);
|
|
37
47
|
}
|
|
38
48
|
catch {
|
package/dist/ingest.js
CHANGED
|
@@ -27,9 +27,7 @@ export function sessionFacts(databaseFile, sessionId) {
|
|
|
27
27
|
.prepare("SELECT directory, title FROM session WHERE id = ?;")
|
|
28
28
|
.get(sessionId);
|
|
29
29
|
let firstMessage = null;
|
|
30
|
-
const rows = db
|
|
31
|
-
.prepare(`SELECT data FROM message WHERE session_id = ? ORDER BY time_created ASC LIMIT 20;`)
|
|
32
|
-
.all(sessionId);
|
|
30
|
+
const rows = readMessages(db, sessionId, 20);
|
|
33
31
|
for (const row of rows) {
|
|
34
32
|
try {
|
|
35
33
|
const parsed = JSON.parse(row.data);
|
|
@@ -64,6 +62,34 @@ export function sessionFacts(databaseFile, sessionId) {
|
|
|
64
62
|
db.close();
|
|
65
63
|
}
|
|
66
64
|
}
|
|
65
|
+
function readMessages(db, sessionId, limit = -1) {
|
|
66
|
+
const hasParts = db
|
|
67
|
+
.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'part'")
|
|
68
|
+
.get();
|
|
69
|
+
const rows = db
|
|
70
|
+
.prepare(`SELECT ${hasParts ? "id, " : ""}data FROM message WHERE session_id = ? ORDER BY time_created ASC LIMIT ?;`)
|
|
71
|
+
.all(sessionId, limit);
|
|
72
|
+
if (!hasParts)
|
|
73
|
+
return rows;
|
|
74
|
+
const parts = db.prepare("SELECT data FROM part WHERE message_id = ? ORDER BY time_created ASC, id ASC");
|
|
75
|
+
return rows.map((row) => {
|
|
76
|
+
try {
|
|
77
|
+
const message = JSON.parse(row.data);
|
|
78
|
+
message.parts = parts.all(row.id).flatMap((part) => {
|
|
79
|
+
try {
|
|
80
|
+
return [JSON.parse(part.data)];
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return { data: JSON.stringify(message) };
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return row;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
67
93
|
export function loadRecentSessions(databaseFile, afterTimeCreated, options = {
|
|
68
94
|
maxSessions: 20,
|
|
69
95
|
maxCharsPerSession: 24_000,
|
|
@@ -86,9 +112,7 @@ export function loadRecentSessions(databaseFile, afterTimeCreated, options = {
|
|
|
86
112
|
const messages = [];
|
|
87
113
|
let budget = options.maxCharsPerSession;
|
|
88
114
|
let internal = false;
|
|
89
|
-
const rows = db
|
|
90
|
-
.prepare(`SELECT data FROM message WHERE session_id = ? ORDER BY time_created ASC;`)
|
|
91
|
-
.all(session.id);
|
|
115
|
+
const rows = readMessages(db, session.id);
|
|
92
116
|
for (const row of rows) {
|
|
93
117
|
if (budget <= 0)
|
|
94
118
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kisev/memomatic",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.62.g445d44a8adf0",
|
|
4
4
|
"description": "Personal learning memory for agents: tiered Markdown corpus, rebuildable index, dream sweep.",
|
|
5
5
|
"homepage": "https://github.com/kisev/skills#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"pack:check": "node test/pack-allowlist.mjs"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@kisev/safe-fs": "1.0.0-dev.
|
|
37
|
+
"@kisev/safe-fs": "1.0.0-dev.62.g445d44a8adf0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "22.15.30",
|