openclawdreams 3.0.3 → 3.0.5
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/CHANGELOG.md +26 -0
- package/openclaw.plugin.json +6 -1
- package/package.json +1 -1
- package/dist/bin/electricsheep.d.ts +0 -3
- package/dist/bin/electricsheep.d.ts.map +0 -1
- package/dist/bin/electricsheep.js +0 -4
- package/dist/bin/electricsheep.js.map +0 -1
- package/dist/bin/openclawdreams.d.ts +0 -3
- package/dist/bin/openclawdreams.d.ts.map +0 -1
- package/dist/bin/openclawdreams.js +0 -4
- package/dist/bin/openclawdreams.js.map +0 -1
- package/dist/src/backfill.d.ts +0 -2
- package/dist/src/backfill.d.ts.map +0 -1
- package/dist/src/backfill.js +0 -63
- package/dist/src/backfill.js.map +0 -1
- package/dist/src/budget.d.ts +0 -28
- package/dist/src/budget.d.ts.map +0 -1
- package/dist/src/budget.js +0 -87
- package/dist/src/budget.js.map +0 -1
- package/dist/src/cli.d.ts +0 -19
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -584
- package/dist/src/cli.js.map +0 -1
- package/dist/src/config.d.ts +0 -74
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -169
- package/dist/src/config.js.map +0 -1
- package/dist/src/crypto.d.ts +0 -19
- package/dist/src/crypto.d.ts.map +0 -1
- package/dist/src/crypto.js +0 -70
- package/dist/src/crypto.js.map +0 -1
- package/dist/src/dreamer.d.ts +0 -68
- package/dist/src/dreamer.d.ts.map +0 -1
- package/dist/src/dreamer.js +0 -555
- package/dist/src/dreamer.js.map +0 -1
- package/dist/src/entropy.d.ts +0 -23
- package/dist/src/entropy.d.ts.map +0 -1
- package/dist/src/entropy.js +0 -188
- package/dist/src/entropy.js.map +0 -1
- package/dist/src/filter.d.ts +0 -30
- package/dist/src/filter.d.ts.map +0 -1
- package/dist/src/filter.js +0 -124
- package/dist/src/filter.js.map +0 -1
- package/dist/src/identity.d.ts +0 -29
- package/dist/src/identity.d.ts.map +0 -1
- package/dist/src/identity.js +0 -83
- package/dist/src/identity.js.map +0 -1
- package/dist/src/index.d.ts +0 -14
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -540
- package/dist/src/index.js.map +0 -1
- package/dist/src/ingestion.d.ts +0 -22
- package/dist/src/ingestion.d.ts.map +0 -1
- package/dist/src/ingestion.js +0 -101
- package/dist/src/ingestion.js.map +0 -1
- package/dist/src/llm.d.ts +0 -26
- package/dist/src/llm.d.ts.map +0 -1
- package/dist/src/llm.js +0 -40
- package/dist/src/llm.js.map +0 -1
- package/dist/src/logger.d.ts +0 -6
- package/dist/src/logger.d.ts.map +0 -1
- package/dist/src/logger.js +0 -32
- package/dist/src/logger.js.map +0 -1
- package/dist/src/memory.d.ts +0 -96
- package/dist/src/memory.d.ts.map +0 -1
- package/dist/src/memory.js +0 -467
- package/dist/src/memory.js.map +0 -1
- package/dist/src/meta-loop.d.ts +0 -23
- package/dist/src/meta-loop.d.ts.map +0 -1
- package/dist/src/meta-loop.js +0 -72
- package/dist/src/meta-loop.js.map +0 -1
- package/dist/src/moltbook-search.d.ts +0 -23
- package/dist/src/moltbook-search.d.ts.map +0 -1
- package/dist/src/moltbook-search.js +0 -85
- package/dist/src/moltbook-search.js.map +0 -1
- package/dist/src/moltbook.d.ts +0 -34
- package/dist/src/moltbook.d.ts.map +0 -1
- package/dist/src/moltbook.js +0 -192
- package/dist/src/moltbook.js.map +0 -1
- package/dist/src/nightmare.d.ts +0 -11
- package/dist/src/nightmare.d.ts.map +0 -1
- package/dist/src/nightmare.js +0 -126
- package/dist/src/nightmare.js.map +0 -1
- package/dist/src/notify.d.ts +0 -20
- package/dist/src/notify.d.ts.map +0 -1
- package/dist/src/notify.js +0 -95
- package/dist/src/notify.js.map +0 -1
- package/dist/src/persona.d.ts +0 -30
- package/dist/src/persona.d.ts.map +0 -1
- package/dist/src/persona.js +0 -292
- package/dist/src/persona.js.map +0 -1
- package/dist/src/reflection.d.ts +0 -26
- package/dist/src/reflection.d.ts.map +0 -1
- package/dist/src/reflection.js +0 -127
- package/dist/src/reflection.js.map +0 -1
- package/dist/src/rhythm.d.ts +0 -19
- package/dist/src/rhythm.d.ts.map +0 -1
- package/dist/src/rhythm.js +0 -130
- package/dist/src/rhythm.js.map +0 -1
- package/dist/src/state.d.ts +0 -7
- package/dist/src/state.d.ts.map +0 -1
- package/dist/src/state.js +0 -40
- package/dist/src/state.js.map +0 -1
- package/dist/src/synthesis.d.ts +0 -29
- package/dist/src/synthesis.d.ts.map +0 -1
- package/dist/src/synthesis.js +0 -144
- package/dist/src/synthesis.js.map +0 -1
- package/dist/src/topics.d.ts +0 -19
- package/dist/src/topics.d.ts.map +0 -1
- package/dist/src/topics.js +0 -84
- package/dist/src/topics.js.map +0 -1
- package/dist/src/types.d.ts +0 -253
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -5
- package/dist/src/types.js.map +0 -1
- package/dist/src/vocabulary.d.ts +0 -18
- package/dist/src/vocabulary.d.ts.map +0 -1
- package/dist/src/vocabulary.js +0 -121
- package/dist/src/vocabulary.js.map +0 -1
- package/dist/src/waking.d.ts +0 -27
- package/dist/src/waking.d.ts.map +0 -1
- package/dist/src/waking.js +0 -188
- package/dist/src/waking.js.map +0 -1
- package/dist/src/web-search.d.ts +0 -23
- package/dist/src/web-search.d.ts.map +0 -1
- package/dist/src/web-search.js +0 -64
- package/dist/src/web-search.js.map +0 -1
package/dist/src/rhythm.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cognitive Rhythm Report — weekly digest of dream and reflection activity.
|
|
3
|
-
*/
|
|
4
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
5
|
-
import { resolve } from "node:path";
|
|
6
|
-
import { getDreamsDir, getNightmaresDir } from "./config.js";
|
|
7
|
-
import { loadState } from "./state.js";
|
|
8
|
-
import { extractConcepts, computeJaccardOverlap } from "./entropy.js";
|
|
9
|
-
function getFilesInDateRange(dir, start, end) {
|
|
10
|
-
let files;
|
|
11
|
-
try {
|
|
12
|
-
files = readdirSync(dir).filter((f) => f.endsWith(".md"));
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
return files.filter((f) => {
|
|
18
|
-
const datePrefix = f.slice(0, 10);
|
|
19
|
-
return datePrefix >= start && datePrefix <= end;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function readFileContents(dir, files) {
|
|
23
|
-
return files.map((f) => {
|
|
24
|
-
try {
|
|
25
|
-
return readFileSync(resolve(dir, f), "utf-8");
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return "";
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function computeTopThemes(contents, limit) {
|
|
33
|
-
const freq = new Map();
|
|
34
|
-
for (const text of contents) {
|
|
35
|
-
for (const word of extractConcepts(text)) {
|
|
36
|
-
freq.set(word, (freq.get(word) ?? 0) + 1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return [...freq.entries()]
|
|
40
|
-
.sort((a, b) => b[1] - a[1])
|
|
41
|
-
.slice(0, limit)
|
|
42
|
-
.map(([word]) => word);
|
|
43
|
-
}
|
|
44
|
-
function computeToneTrajectory(contents, pastRealizations) {
|
|
45
|
-
if (contents.length < 2)
|
|
46
|
-
return "unknown";
|
|
47
|
-
const referenceConcepts = pastRealizations.length > 0 ? extractConcepts(pastRealizations.join(" ")) : [];
|
|
48
|
-
if (referenceConcepts.length === 0)
|
|
49
|
-
return "unknown";
|
|
50
|
-
const mid = Math.floor(contents.length / 2);
|
|
51
|
-
const firstHalf = contents.slice(0, mid);
|
|
52
|
-
const secondHalf = contents.slice(mid);
|
|
53
|
-
const avgOverlap = (texts) => {
|
|
54
|
-
if (texts.length === 0)
|
|
55
|
-
return 0;
|
|
56
|
-
const total = texts.reduce((sum, text) => sum + computeJaccardOverlap(extractConcepts(text), referenceConcepts), 0);
|
|
57
|
-
return total / texts.length;
|
|
58
|
-
};
|
|
59
|
-
const firstAvg = avgOverlap(firstHalf);
|
|
60
|
-
const secondAvg = avgOverlap(secondHalf);
|
|
61
|
-
const diff = secondAvg - firstAvg;
|
|
62
|
-
const threshold = 0.1 * Math.max(firstAvg, secondAvg, 0.01);
|
|
63
|
-
if (Math.abs(diff) <= threshold)
|
|
64
|
-
return "stable";
|
|
65
|
-
return diff < 0 ? "improving" : "declining";
|
|
66
|
-
}
|
|
67
|
-
function computeInsightDensity(contents) {
|
|
68
|
-
if (contents.length === 0)
|
|
69
|
-
return 0;
|
|
70
|
-
const total = contents.reduce((sum, text) => {
|
|
71
|
-
const unique = new Set(extractConcepts(text));
|
|
72
|
-
return sum + unique.size;
|
|
73
|
-
}, 0);
|
|
74
|
-
return Math.round((total / contents.length) * 100) / 100;
|
|
75
|
-
}
|
|
76
|
-
export function generateRhythmReport(dataDir, days = 7) {
|
|
77
|
-
const now = new Date();
|
|
78
|
-
const periodAgo = new Date(now);
|
|
79
|
-
periodAgo.setDate(periodAgo.getDate() - days);
|
|
80
|
-
const periodEnd = now.toISOString().slice(0, 10);
|
|
81
|
-
const periodStart = periodAgo.toISOString().slice(0, 10);
|
|
82
|
-
const dreamsDir = dataDir ? resolve(dataDir, "data", "dreams") : getDreamsDir();
|
|
83
|
-
const nightmaresDir = dataDir
|
|
84
|
-
? resolve(dataDir, "data", "nightmares")
|
|
85
|
-
: getNightmaresDir();
|
|
86
|
-
const dreamFiles = getFilesInDateRange(dreamsDir, periodStart, periodEnd);
|
|
87
|
-
const nightmareFiles = getFilesInDateRange(nightmaresDir, periodStart, periodEnd);
|
|
88
|
-
const dreamContents = readFileContents(dreamsDir, dreamFiles);
|
|
89
|
-
const allContents = [
|
|
90
|
-
...dreamContents,
|
|
91
|
-
...readFileContents(nightmaresDir, nightmareFiles),
|
|
92
|
-
];
|
|
93
|
-
const state = loadState();
|
|
94
|
-
const pastRealizations = state.past_realizations ?? [];
|
|
95
|
-
const dominantThemes = computeTopThemes(allContents, 5);
|
|
96
|
-
const toneTrajectory = computeToneTrajectory(allContents, pastRealizations);
|
|
97
|
-
const insightDensity = computeInsightDensity(allContents);
|
|
98
|
-
const entropyReprompts = state.entropy_reprompt_count ?? 0;
|
|
99
|
-
const metaLoopDepthPeak = state.meta_loop_depth ?? 0;
|
|
100
|
-
const totalReflections = state.checks_today ?? 0;
|
|
101
|
-
const themeStr = dominantThemes.length > 0 ? dominantThemes.join(", ") : "none detected";
|
|
102
|
-
const periodLabel = days === 1 ? "day" : `${days} days`;
|
|
103
|
-
const rawSummary = `Over the past ${periodLabel}, ${dreamFiles.length} dream(s) and ${nightmareFiles.length} nightmare(s) were recorded. ` +
|
|
104
|
-
`Dominant themes included ${themeStr}. ` +
|
|
105
|
-
`Tone trajectory: ${toneTrajectory}.`;
|
|
106
|
-
return {
|
|
107
|
-
period_start: periodStart,
|
|
108
|
-
period_end: periodEnd,
|
|
109
|
-
total_dreams: dreamFiles.length,
|
|
110
|
-
total_nightmares: nightmareFiles.length,
|
|
111
|
-
total_reflections: totalReflections,
|
|
112
|
-
dominant_themes: dominantThemes,
|
|
113
|
-
tone_trajectory: toneTrajectory,
|
|
114
|
-
insight_density: insightDensity,
|
|
115
|
-
entropy_reprompts: entropyReprompts,
|
|
116
|
-
meta_loop_depth_peak: metaLoopDepthPeak,
|
|
117
|
-
raw_summary: rawSummary,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
export function formatReportNotification(report) {
|
|
121
|
-
return [
|
|
122
|
-
`Weekly Rhythm Report (${report.period_start} to ${report.period_end})`,
|
|
123
|
-
`Dreams: ${report.total_dreams} | Nightmares: ${report.total_nightmares}`,
|
|
124
|
-
`Dominant themes: ${report.dominant_themes.length > 0 ? report.dominant_themes.join(", ") : "none"}`,
|
|
125
|
-
`Tone: ${report.tone_trajectory} | Insight density: ${report.insight_density} concepts/dream`,
|
|
126
|
-
`Entropy re-prompts: ${report.entropy_reprompts} | Meta-loop depth: ${report.meta_loop_depth_peak}`,
|
|
127
|
-
report.raw_summary,
|
|
128
|
-
].join("\n");
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=rhythm.js.map
|
package/dist/src/rhythm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rhythm.js","sourceRoot":"","sources":["../../src/rhythm.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAiBtE,SAAS,mBAAmB,CAAC,GAAW,EAAE,KAAa,EAAE,GAAW;IAClE,IAAI,KAAe,CAAC;IACpB,IAAI,CAAC;QACH,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAClC,OAAO,UAAU,IAAI,KAAK,IAAI,UAAU,IAAI,GAAG,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW,EAAE,KAAe;IACpD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACrB,IAAI,CAAC;YACH,O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iB,EAAE,gBAAgB;QACnC,oBAAoB,EAAE,iBAAiB;QACvC,WAAW,EAAE,UAAU;KACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAAoB;IAC3D,OAAO;QACL,yBAAyB,MAAM,CAAC,YAAY,OAAO,MAAM,CAAC,UAAU,GAAG;QACvE,WAAW,MAAM,CAAC,YAAY,kBAAkB,MAAM,CAAC,gBAAgB,EAAE;QACzE,oBAAoB,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;QACpG,SAAS,MAAM,CAAC,eAAe,uBAAuB,MAAM,CAAC,eAAe,iBAAiB;QAC7F,uBAAuB,MAAM,CAAC,iBAAiB,uBAAuB,MAAM,CAAC,oBAAoB,EAAE;QACnG,MAAM,CAAC,WAAW;KACnB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/src/state.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple state persistence with atomic writes and corruption recovery.
|
|
3
|
-
*/
|
|
4
|
-
import type { AgentState } from "./types.js";
|
|
5
|
-
export declare function loadState(): AgentState;
|
|
6
|
-
export declare function saveState(state: AgentState): void;
|
|
7
|
-
//# sourceMappingURL=state.d.ts.map
|
package/dist/src/state.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,SAAS,IAAI,UAAU,CAWtC;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAIjD"}
|
package/dist/src/state.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple state persistence with atomic writes and corruption recovery.
|
|
3
|
-
*/
|
|
4
|
-
import { readFileSync, writeFileSync, existsSync, renameSync, unlinkSync } from "node:fs";
|
|
5
|
-
import { getStateFile } from "./config.js";
|
|
6
|
-
import logger from "./logger.js";
|
|
7
|
-
export function loadState() {
|
|
8
|
-
if (!existsSync(getStateFile())) {
|
|
9
|
-
return {};
|
|
10
|
-
}
|
|
11
|
-
try {
|
|
12
|
-
return JSON.parse(readFileSync(getStateFile(), "utf-8"));
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
logger.error(`Corrupted state file, resetting to empty state: ${e}`);
|
|
16
|
-
return {};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export function saveState(state) {
|
|
20
|
-
const tmp = getStateFile() + ".tmp";
|
|
21
|
-
writeFileSync(tmp, JSON.stringify(state, null, 2));
|
|
22
|
-
renameSync(tmp, getStateFile());
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Clean up any leftover temp file from a previous crashed write.
|
|
26
|
-
* Called once at module load.
|
|
27
|
-
*/
|
|
28
|
-
function cleanupStaleTemp() {
|
|
29
|
-
const tmp = getStateFile() + ".tmp";
|
|
30
|
-
if (existsSync(tmp)) {
|
|
31
|
-
try {
|
|
32
|
-
unlinkSync(tmp);
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// best-effort
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
cleanupStaleTemp();
|
|
40
|
-
//# sourceMappingURL=state.js.map
|
package/dist/src/state.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC;QAChC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,mDAAmD,CAAC,EAAE,CAAC,CAAC;QACrE,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAiB;IACzC,MAAM,GAAG,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IACpC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB;IACvB,MAAM,GAAG,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IACpC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC;YACH,UAAU,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACP,cAAc;QAChB,CAAC;IACH,CAAC;AACH,CAAC;AAED,gBAAgB,EAAE,CAAC"}
|
package/dist/src/synthesis.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context synthesis module.
|
|
3
|
-
*
|
|
4
|
-
* Combines multiple sources (operator conversations, Moltbook community,
|
|
5
|
-
* web search) into a unified context for dream processing and reflection.
|
|
6
|
-
*/
|
|
7
|
-
import type { LLMClient, OpenClawAPI, ReflectionMode, SynthesisContext } from "./types.js";
|
|
8
|
-
/**
|
|
9
|
-
* Gather context from all available sources based on operator conversations.
|
|
10
|
-
*
|
|
11
|
-
* Flow:
|
|
12
|
-
* 1. Extract topics from recent operator conversations
|
|
13
|
-
* 2. Search Moltbook for related community content (if enabled)
|
|
14
|
-
* 3. Search web for related information (if enabled)
|
|
15
|
-
* 4. Return unified context object
|
|
16
|
-
*/
|
|
17
|
-
export declare function gatherContext(client: LLMClient, api: OpenClawAPI): Promise<SynthesisContext>;
|
|
18
|
-
/**
|
|
19
|
-
* Format the full synthesis context for LLM consumption.
|
|
20
|
-
*/
|
|
21
|
-
export declare function formatSynthesisContext(ctx: SynthesisContext): string;
|
|
22
|
-
/**
|
|
23
|
-
* Generate a synthesis of the gathered context.
|
|
24
|
-
*
|
|
25
|
-
* Takes all the context sources and produces a unified narrative that
|
|
26
|
-
* connects operator work with community and web knowledge.
|
|
27
|
-
*/
|
|
28
|
-
export declare function synthesizeContext(client: LLMClient, context: SynthesisContext, vocabularyHint?: string, mode?: ReflectionMode): Promise<string>;
|
|
29
|
-
//# sourceMappingURL=synthesis.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"synthesis.d.ts","sourceRoot":"","sources":["../../src/synthesis.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,cAAc,EACd,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,SAAS,EACjB,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,gBAAgB,CAAC,CA6D3B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,CAwBpE;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,gBAAgB,EACzB,cAAc,CAAC,EAAE,MAAM,EACvB,IAAI,GAAE,cAA4B,GACjC,OAAO,CAAC,MAAM,CAAC,CAyCjB"}
|
package/dist/src/synthesis.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context synthesis module.
|
|
3
|
-
*
|
|
4
|
-
* Combines multiple sources (operator conversations, Moltbook community,
|
|
5
|
-
* web search) into a unified context for dream processing and reflection.
|
|
6
|
-
*/
|
|
7
|
-
import { extractTopicsFromConversations } from "./topics.js";
|
|
8
|
-
import { searchWebForTopics, formatWebContext } from "./web-search.js";
|
|
9
|
-
import { searchMoltbookForTopics, formatMoltbookContext } from "./moltbook-search.js";
|
|
10
|
-
import { formatDeepMemoryContext } from "./memory.js";
|
|
11
|
-
import { callWithRetry, WAKING_RETRY_OPTS } from "./llm.js";
|
|
12
|
-
import { SYNTHESIS_PROMPT, SEEDING_PROMPT, renderTemplate } from "./persona.js";
|
|
13
|
-
import { getAgentIdentityBlock } from "./identity.js";
|
|
14
|
-
import { MAX_TOKENS_SYNTHESIS, getMoltbookEnabled, getWebSearchEnabled, } from "./config.js";
|
|
15
|
-
import logger from "./logger.js";
|
|
16
|
-
import { fetchCommunityPosts, formatCommunityContext } from "./ingestion.js";
|
|
17
|
-
/**
|
|
18
|
-
* Gather context from all available sources based on operator conversations.
|
|
19
|
-
*
|
|
20
|
-
* Flow:
|
|
21
|
-
* 1. Extract topics from recent operator conversations
|
|
22
|
-
* 2. Search Moltbook for related community content (if enabled)
|
|
23
|
-
* 3. Search web for related information (if enabled)
|
|
24
|
-
* 4. Return unified context object
|
|
25
|
-
*/
|
|
26
|
-
export async function gatherContext(client, api) {
|
|
27
|
-
logger.info("Starting context gathering from operator conversations");
|
|
28
|
-
// Step 1: Extract topics from operator conversations
|
|
29
|
-
const extracted = await extractTopicsFromConversations(client);
|
|
30
|
-
if (extracted.topics.length === 0) {
|
|
31
|
-
logger.info("No topics extracted, returning minimal context");
|
|
32
|
-
return {
|
|
33
|
-
operatorContext: formatDeepMemoryContext(),
|
|
34
|
-
topics: [],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
// Step 2: Search Moltbook (if enabled)
|
|
38
|
-
let moltbookContext;
|
|
39
|
-
if (getMoltbookEnabled()) {
|
|
40
|
-
try {
|
|
41
|
-
const moltbookResults = await searchMoltbookForTopics(extracted.topics);
|
|
42
|
-
moltbookContext = formatMoltbookContext(moltbookResults);
|
|
43
|
-
if (moltbookContext) {
|
|
44
|
-
logger.debug("Gathered Moltbook context");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
logger.warn(`Moltbook search failed: ${error}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Step 3: Search web (if enabled)
|
|
52
|
-
let webContext;
|
|
53
|
-
if (getWebSearchEnabled()) {
|
|
54
|
-
try {
|
|
55
|
-
const webResults = await searchWebForTopics(api, extracted.topics);
|
|
56
|
-
webContext = formatWebContext(webResults);
|
|
57
|
-
if (webContext) {
|
|
58
|
-
logger.debug("Gathered web context");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
logger.warn(`Web search failed: ${error}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Step 4: Fetch community posts (if enabled)
|
|
66
|
-
let communityContext;
|
|
67
|
-
try {
|
|
68
|
-
const communityPosts = await fetchCommunityPosts();
|
|
69
|
-
communityContext = formatCommunityContext(communityPosts) || undefined;
|
|
70
|
-
if (communityContext) {
|
|
71
|
-
logger.debug("Gathered community ingestion context");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
logger.warn(`Community ingestion failed: ${error}`);
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
operatorContext: formatDeepMemoryContext(),
|
|
79
|
-
moltbookContext: moltbookContext || undefined,
|
|
80
|
-
webContext: webContext || undefined,
|
|
81
|
-
communityContext,
|
|
82
|
-
topics: extracted.topics,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Format the full synthesis context for LLM consumption.
|
|
87
|
-
*/
|
|
88
|
-
export function formatSynthesisContext(ctx) {
|
|
89
|
-
const sections = [];
|
|
90
|
-
sections.push(`RECENT EXPERIENCES:\n${ctx.operatorContext}`);
|
|
91
|
-
if (ctx.topics.length > 0) {
|
|
92
|
-
sections.push(`TOPICS IDENTIFIED:\n${ctx.topics.map((t, i) => `${i + 1}. ${t}`).join("\n")}`);
|
|
93
|
-
}
|
|
94
|
-
if (ctx.moltbookContext) {
|
|
95
|
-
sections.push(ctx.moltbookContext);
|
|
96
|
-
}
|
|
97
|
-
if (ctx.webContext) {
|
|
98
|
-
sections.push(ctx.webContext);
|
|
99
|
-
}
|
|
100
|
-
if (ctx.communityContext) {
|
|
101
|
-
sections.push(ctx.communityContext);
|
|
102
|
-
}
|
|
103
|
-
return sections.join("\n\n---\n\n");
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Generate a synthesis of the gathered context.
|
|
107
|
-
*
|
|
108
|
-
* Takes all the context sources and produces a unified narrative that
|
|
109
|
-
* connects operator work with community and web knowledge.
|
|
110
|
-
*/
|
|
111
|
-
export async function synthesizeContext(client, context, vocabularyHint, mode = "synthesis") {
|
|
112
|
-
if (context.topics.length === 0) {
|
|
113
|
-
logger.info("No topics to synthesize");
|
|
114
|
-
return "";
|
|
115
|
-
}
|
|
116
|
-
const formattedContext = formatSynthesisContext(context);
|
|
117
|
-
const promptTemplate = mode === "seeding" ? SEEDING_PROMPT : SYNTHESIS_PROMPT;
|
|
118
|
-
const system = renderTemplate(promptTemplate, {
|
|
119
|
-
agent_identity: getAgentIdentityBlock(),
|
|
120
|
-
}) + (vocabularyHint ? "\n\n" + vocabularyHint : "");
|
|
121
|
-
try {
|
|
122
|
-
const { text } = await callWithRetry(client, {
|
|
123
|
-
maxTokens: MAX_TOKENS_SYNTHESIS,
|
|
124
|
-
system,
|
|
125
|
-
messages: [
|
|
126
|
-
{
|
|
127
|
-
role: "user",
|
|
128
|
-
content: `Here is the context from my recent work and searches:\n\n` +
|
|
129
|
-
`${formattedContext}\n\n` +
|
|
130
|
-
(mode === "seeding"
|
|
131
|
-
? `Review this context for open threads and unresolved tensions. What remains uncertain? What doesn't quite fit?`
|
|
132
|
-
: `Synthesize this into a coherent understanding. What patterns emerge? How does my work with my operator connect to what the community and world are saying?`),
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
}, WAKING_RETRY_OPTS);
|
|
136
|
-
logger.info(`Generated synthesis: ${text.length} chars`);
|
|
137
|
-
return text.trim();
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
logger.error(`Synthesis failed: ${error}`);
|
|
141
|
-
return "";
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=synthesis.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"synthesis.js","sourceRoot":"","sources":["../../src/synthesis.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,E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AAC,+GAA+G;4BACjH,CAAC,CAAC,4JAA4J,CAAC;iBACpK;aACF;SACF,EACD,iBAAiB,CAClB,CAAC;QAEF,MAAM,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,MAAM,QAAQ,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;QAC3C,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/src/topics.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Topic extraction from operator conversations.
|
|
3
|
-
*
|
|
4
|
-
* Analyzes recent deep memory entries (interaction category) to extract
|
|
5
|
-
* key themes and topics that can be used for contextual web and Moltbook searches.
|
|
6
|
-
*/
|
|
7
|
-
import type { LLMClient, DecryptedMemory, ExtractedTopics } from "./types.js";
|
|
8
|
-
/**
|
|
9
|
-
* Get recent operator conversation memories from deep memory.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getRecentConversations(limit?: number): DecryptedMemory[];
|
|
12
|
-
/**
|
|
13
|
-
* Extract topics from recent operator conversations using LLM.
|
|
14
|
-
*
|
|
15
|
-
* Analyzes conversation summaries to identify key themes, subjects,
|
|
16
|
-
* and topics that the agent and operator discussed or worked on.
|
|
17
|
-
*/
|
|
18
|
-
export declare function extractTopicsFromConversations(client: LLMClient, memories?: DecryptedMemory[]): Promise<ExtractedTopics>;
|
|
19
|
-
//# sourceMappingURL=topics.d.ts.map
|
package/dist/src/topics.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"topics.d.ts","sourceRoot":"","sources":["../../src/topics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE9E;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,GAAE,MAAW,GAAG,eAAe,EAAE,CAK5E;AAuBD;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,OAAO,CAAC,eAAe,CAAC,CAgD1B"}
|
package/dist/src/topics.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Topic extraction from operator conversations.
|
|
3
|
-
*
|
|
4
|
-
* Analyzes recent deep memory entries (interaction category) to extract
|
|
5
|
-
* key themes and topics that can be used for contextual web and Moltbook searches.
|
|
6
|
-
*/
|
|
7
|
-
import { getRecentDeepMemories } from "./memory.js";
|
|
8
|
-
import { callWithRetry, WAKING_RETRY_OPTS } from "./llm.js";
|
|
9
|
-
import { TOPIC_EXTRACTION_PROMPT, renderTemplate } from "./persona.js";
|
|
10
|
-
import { getAgentIdentityBlock } from "./identity.js";
|
|
11
|
-
import { MAX_TOKENS_TOPIC_EXTRACTION, MAX_TOPICS_PER_CYCLE } from "./config.js";
|
|
12
|
-
import logger from "./logger.js";
|
|
13
|
-
/**
|
|
14
|
-
* Get recent operator conversation memories from deep memory.
|
|
15
|
-
*/
|
|
16
|
-
export function getRecentConversations(limit = 10) {
|
|
17
|
-
return getRecentDeepMemories({
|
|
18
|
-
limit,
|
|
19
|
-
categories: ["interaction"],
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Format conversation memories into a string for LLM analysis.
|
|
24
|
-
*/
|
|
25
|
-
function formatConversationsForExtraction(memories) {
|
|
26
|
-
if (memories.length === 0) {
|
|
27
|
-
return "No recent conversations found.";
|
|
28
|
-
}
|
|
29
|
-
return memories
|
|
30
|
-
.map((m) => {
|
|
31
|
-
const time = m.timestamp.slice(0, 16).replace("T", " ");
|
|
32
|
-
const summary = m.content.text_summary || JSON.stringify(m.content).slice(0, 200);
|
|
33
|
-
const topicHint = m.content.topics && m.content.topics.length > 0
|
|
34
|
-
? ` [topics: ${m.content.topics.join(", ")}]`
|
|
35
|
-
: "";
|
|
36
|
-
return `[${time}] ${summary}${topicHint}`;
|
|
37
|
-
})
|
|
38
|
-
.join("\n\n");
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Extract topics from recent operator conversations using LLM.
|
|
42
|
-
*
|
|
43
|
-
* Analyzes conversation summaries to identify key themes, subjects,
|
|
44
|
-
* and topics that the agent and operator discussed or worked on.
|
|
45
|
-
*/
|
|
46
|
-
export async function extractTopicsFromConversations(client, memories) {
|
|
47
|
-
const sourceMemories = memories ?? getRecentConversations();
|
|
48
|
-
if (sourceMemories.length === 0) {
|
|
49
|
-
logger.info("No recent conversations to extract topics from");
|
|
50
|
-
return { topics: [], sourceMemories: [] };
|
|
51
|
-
}
|
|
52
|
-
const conversationContext = formatConversationsForExtraction(sourceMemories);
|
|
53
|
-
const system = renderTemplate(TOPIC_EXTRACTION_PROMPT, {
|
|
54
|
-
agent_identity: getAgentIdentityBlock(),
|
|
55
|
-
conversations: conversationContext,
|
|
56
|
-
});
|
|
57
|
-
try {
|
|
58
|
-
const { text } = await callWithRetry(client, {
|
|
59
|
-
maxTokens: MAX_TOKENS_TOPIC_EXTRACTION,
|
|
60
|
-
system,
|
|
61
|
-
messages: [
|
|
62
|
-
{
|
|
63
|
-
role: "user",
|
|
64
|
-
content: "Extract the key topics from my recent conversations with my operator. " +
|
|
65
|
-
"What subjects, themes, or areas did we work on or discuss?",
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
}, WAKING_RETRY_OPTS);
|
|
69
|
-
// Parse topics (one per line, strip formatting)
|
|
70
|
-
const topics = text
|
|
71
|
-
.trim()
|
|
72
|
-
.split("\n")
|
|
73
|
-
.map((line) => line.replace(/^[\s\-*•>\d.)+]+/, "").trim())
|
|
74
|
-
.filter((line) => line.length > 0)
|
|
75
|
-
.slice(0, MAX_TOPICS_PER_CYCLE);
|
|
76
|
-
logger.info(`Extracted ${topics.length} topics: ${topics.join("; ")}`);
|
|
77
|
-
return { topics, sourceMemories };
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
logger.error(`Topic extraction failed: ${error}`);
|
|
81
|
-
return { topics: [], sourceMemories };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=topics.js.map
|
package/dist/src/topics.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"topics.js","sourceRoot":"","sources":["../../src/topics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAgB,EAAE;IACvD,OAAO,qBAAqB,CAAC;QAC3B,KAAK;QACL,UAAU,EAAE,CAAC,aAAa,CAAC;KAC5B,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,gCAAgC,CAAC,QAA2B;IACnE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,gCAAgC,CAAC;IAC1C,CAAC;IAED,OAAO,QAAQ;SACZ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACxD,MAAM,OAAO,G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