openclawdreams 0.7.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/.env.example +14 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +19 -0
- package/.github/dependabot.yml +17 -0
- package/.github/pull_request_template.md +19 -0
- package/.github/workflows/build.yml +30 -0
- package/.github/workflows/release.yml +110 -0
- package/.prettierignore +4 -0
- package/.prettierrc +7 -0
- package/.versionrc.json +26 -0
- package/AGENTS.md +286 -0
- package/CHANGELOG.md +157 -0
- package/CODE_OF_CONDUCT.md +41 -0
- package/CONTRIBUTING.md +95 -0
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/SECURITY.md +39 -0
- package/bin/electricsheep.ts +5 -0
- package/dist/bin/electricsheep.d.ts +3 -0
- package/dist/bin/electricsheep.d.ts.map +1 -0
- package/dist/bin/electricsheep.js +4 -0
- package/dist/bin/electricsheep.js.map +1 -0
- package/dist/src/budget.d.ts +28 -0
- package/dist/src/budget.d.ts.map +1 -0
- package/dist/src/budget.js +87 -0
- package/dist/src/budget.js.map +1 -0
- package/dist/src/cli.d.ts +19 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +289 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config.d.ts +37 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +70 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/crypto.d.ts +19 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +70 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/dreamer.d.ts +13 -0
- package/dist/src/dreamer.d.ts.map +1 -0
- package/dist/src/dreamer.js +213 -0
- package/dist/src/dreamer.js.map +1 -0
- package/dist/src/filter.d.ts +30 -0
- package/dist/src/filter.d.ts.map +1 -0
- package/dist/src/filter.js +124 -0
- package/dist/src/filter.js.map +1 -0
- package/dist/src/identity.d.ts +29 -0
- package/dist/src/identity.d.ts.map +1 -0
- package/dist/src/identity.js +83 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +293 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/llm.d.ts +26 -0
- package/dist/src/llm.d.ts.map +1 -0
- package/dist/src/llm.js +40 -0
- package/dist/src/llm.js.map +1 -0
- package/dist/src/logger.d.ts +6 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +32 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/memory.d.ts +41 -0
- package/dist/src/memory.d.ts.map +1 -0
- package/dist/src/memory.js +206 -0
- package/dist/src/memory.js.map +1 -0
- package/dist/src/moltbook-search.d.ts +23 -0
- package/dist/src/moltbook-search.d.ts.map +1 -0
- package/dist/src/moltbook-search.js +85 -0
- package/dist/src/moltbook-search.js.map +1 -0
- package/dist/src/moltbook.d.ts +34 -0
- package/dist/src/moltbook.d.ts.map +1 -0
- package/dist/src/moltbook.js +165 -0
- package/dist/src/moltbook.js.map +1 -0
- package/dist/src/notify.d.ts +18 -0
- package/dist/src/notify.d.ts.map +1 -0
- package/dist/src/notify.js +98 -0
- package/dist/src/notify.js.map +1 -0
- package/dist/src/persona.d.ts +26 -0
- package/dist/src/persona.d.ts.map +1 -0
- package/dist/src/persona.js +178 -0
- package/dist/src/persona.js.map +1 -0
- package/dist/src/reflection.d.ts +26 -0
- package/dist/src/reflection.d.ts.map +1 -0
- package/dist/src/reflection.js +111 -0
- package/dist/src/reflection.js.map +1 -0
- package/dist/src/state.d.ts +7 -0
- package/dist/src/state.d.ts.map +1 -0
- package/dist/src/state.js +40 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/synthesis.d.ts +29 -0
- package/dist/src/synthesis.d.ts.map +1 -0
- package/dist/src/synthesis.js +125 -0
- package/dist/src/synthesis.js.map +1 -0
- package/dist/src/topics.d.ts +19 -0
- package/dist/src/topics.d.ts.map +1 -0
- package/dist/src/topics.js +83 -0
- package/dist/src/topics.js.map +1 -0
- package/dist/src/types.d.ts +179 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +5 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/waking.d.ts +24 -0
- package/dist/src/waking.d.ts.map +1 -0
- package/dist/src/waking.js +152 -0
- package/dist/src/waking.js.map +1 -0
- package/dist/src/web-search.d.ts +23 -0
- package/dist/src/web-search.d.ts.map +1 -0
- package/dist/src/web-search.js +64 -0
- package/dist/src/web-search.js.map +1 -0
- package/dist/test/budget.test.d.ts +2 -0
- package/dist/test/budget.test.d.ts.map +1 -0
- package/dist/test/budget.test.js +258 -0
- package/dist/test/budget.test.js.map +1 -0
- package/dist/test/crypto.test.d.ts +2 -0
- package/dist/test/crypto.test.d.ts.map +1 -0
- package/dist/test/crypto.test.js +93 -0
- package/dist/test/crypto.test.js.map +1 -0
- package/dist/test/dreamer.test.d.ts +2 -0
- package/dist/test/dreamer.test.d.ts.map +1 -0
- package/dist/test/dreamer.test.js +79 -0
- package/dist/test/dreamer.test.js.map +1 -0
- package/dist/test/filter.test.d.ts +2 -0
- package/dist/test/filter.test.d.ts.map +1 -0
- package/dist/test/filter.test.js +92 -0
- package/dist/test/filter.test.js.map +1 -0
- package/dist/test/memory.test.d.ts +2 -0
- package/dist/test/memory.test.d.ts.map +1 -0
- package/dist/test/memory.test.js +138 -0
- package/dist/test/memory.test.js.map +1 -0
- package/dist/test/moltbook.test.d.ts +2 -0
- package/dist/test/moltbook.test.d.ts.map +1 -0
- package/dist/test/moltbook.test.js +164 -0
- package/dist/test/moltbook.test.js.map +1 -0
- package/dist/test/persona.test.d.ts +2 -0
- package/dist/test/persona.test.d.ts.map +1 -0
- package/dist/test/persona.test.js +44 -0
- package/dist/test/persona.test.js.map +1 -0
- package/dist/test/reflection.test.d.ts +2 -0
- package/dist/test/reflection.test.d.ts.map +1 -0
- package/dist/test/reflection.test.js +57 -0
- package/dist/test/reflection.test.js.map +1 -0
- package/dist/test/state.test.d.ts +2 -0
- package/dist/test/state.test.d.ts.map +1 -0
- package/dist/test/state.test.js +50 -0
- package/dist/test/state.test.js.map +1 -0
- package/dist/test/waking.test.d.ts +2 -0
- package/dist/test/waking.test.d.ts.map +1 -0
- package/dist/test/waking.test.js +149 -0
- package/dist/test/waking.test.js.map +1 -0
- package/eslint.config.js +35 -0
- package/openclaw.plugin.json +62 -0
- package/package.json +72 -0
- package/skills/electricsheep.skill.md +69 -0
- package/skills/setup-guide/SKILL.md +303 -0
- package/src/budget.ts +104 -0
- package/src/cli.ts +325 -0
- package/src/config.ts +95 -0
- package/src/crypto.ts +82 -0
- package/src/dreamer.ts +283 -0
- package/src/filter.ts +146 -0
- package/src/identity.ts +92 -0
- package/src/index.ts +356 -0
- package/src/llm.ts +61 -0
- package/src/logger.ts +46 -0
- package/src/memory.ts +276 -0
- package/src/moltbook-search.ts +116 -0
- package/src/moltbook.ts +235 -0
- package/src/notify.ts +124 -0
- package/src/persona.ts +191 -0
- package/src/reflection.ts +150 -0
- package/src/state.ts +44 -0
- package/src/synthesis.ts +153 -0
- package/src/topics.ts +103 -0
- package/src/types.ts +196 -0
- package/src/waking.ts +199 -0
- package/src/web-search.ts +88 -0
- package/test/budget.test.ts +316 -0
- package/test/crypto.test.ts +112 -0
- package/test/dreamer.test.ts +95 -0
- package/test/filter.test.ts +115 -0
- package/test/memory.test.ts +182 -0
- package/test/moltbook.test.ts +209 -0
- package/test/persona.test.ts +59 -0
- package/test/reflection.test.ts +71 -0
- package/test/state.test.ts +57 -0
- package/test/waking.test.ts +214 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { describe, it, after } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import type { LLMClient, OpenClawAPI } from "../src/types.js";
|
|
7
|
+
|
|
8
|
+
// Isolated data dir
|
|
9
|
+
const testDir = mkdtempSync(join(tmpdir(), "es-waking-test-"));
|
|
10
|
+
process.env.ELECTRICSHEEP_DATA_DIR = testDir;
|
|
11
|
+
|
|
12
|
+
const { runReflectionCycle, checkAndEngage } = await import("../src/waking.js");
|
|
13
|
+
const { deepMemoryStats, storeDeepMemory } = await import("../src/memory.js");
|
|
14
|
+
const { loadState } = await import("../src/state.js");
|
|
15
|
+
const { closeLogger } = await import("../src/logger.js");
|
|
16
|
+
|
|
17
|
+
function mockLLMClient(responses: string[]): LLMClient {
|
|
18
|
+
let idx = 0;
|
|
19
|
+
return {
|
|
20
|
+
async createMessage() {
|
|
21
|
+
const text = responses[idx] ?? responses[responses.length - 1];
|
|
22
|
+
idx++;
|
|
23
|
+
return { text, usage: { input_tokens: 100, output_tokens: 50 } };
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function mockOpenClawAPI(): OpenClawAPI {
|
|
29
|
+
return {
|
|
30
|
+
registerTool: () => {},
|
|
31
|
+
registerCli: () => {},
|
|
32
|
+
registerHook: () => {},
|
|
33
|
+
registerService: (_def: unknown) => {},
|
|
34
|
+
registerGatewayMethod: (_m: string, _h: unknown) => {},
|
|
35
|
+
runtime: {
|
|
36
|
+
subagent: {
|
|
37
|
+
run: async () => ({ runId: "mock" }),
|
|
38
|
+
waitForRun: async () => ({ status: "ok" }),
|
|
39
|
+
getSessionMessages: async () => ({ messages: [] }),
|
|
40
|
+
},
|
|
41
|
+
} as OpenClawAPI["runtime"],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function mockOpenClawAPIWithMemory(): OpenClawAPI & {
|
|
46
|
+
storedMemories: Array<{ content: string; metadata?: Record<string, unknown> }>;
|
|
47
|
+
} {
|
|
48
|
+
const storedMemories: Array<{
|
|
49
|
+
content: string;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
}> = [];
|
|
52
|
+
return {
|
|
53
|
+
registerTool: () => {},
|
|
54
|
+
registerCli: () => {},
|
|
55
|
+
registerHook: () => {},
|
|
56
|
+
registerService: (_def: unknown) => {},
|
|
57
|
+
registerGatewayMethod: (_m: string, _h: unknown) => {},
|
|
58
|
+
runtime: {
|
|
59
|
+
subagent: {
|
|
60
|
+
run: async () => ({ runId: "mock" }),
|
|
61
|
+
waitForRun: async () => ({ status: "ok" }),
|
|
62
|
+
getSessionMessages: async () => ({ messages: [] }),
|
|
63
|
+
},
|
|
64
|
+
} as OpenClawAPI["runtime"],
|
|
65
|
+
memory: {
|
|
66
|
+
async store(content: string, metadata?: Record<string, unknown>) {
|
|
67
|
+
storedMemories.push({ content, metadata });
|
|
68
|
+
},
|
|
69
|
+
async search(_query: string, _limit?: number) {
|
|
70
|
+
return [];
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
storedMemories,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
describe("runReflectionCycle", () => {
|
|
78
|
+
it("handles no recent conversations gracefully", async () => {
|
|
79
|
+
const client = mockLLMClient(["should not be called"]);
|
|
80
|
+
const api = mockOpenClawAPI();
|
|
81
|
+
|
|
82
|
+
const statsBefore = deepMemoryStats();
|
|
83
|
+
await runReflectionCycle(client, api);
|
|
84
|
+
const statsAfter = deepMemoryStats();
|
|
85
|
+
|
|
86
|
+
// Should store an observation in deep memory about no conversations
|
|
87
|
+
assert.ok(
|
|
88
|
+
statsAfter.total_memories > statsBefore.total_memories,
|
|
89
|
+
"Expected observation stored in deep memory"
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("extracts topics from operator conversations", async () => {
|
|
94
|
+
// Seed some mock operator conversations in deep memory
|
|
95
|
+
storeDeepMemory(
|
|
96
|
+
{
|
|
97
|
+
summary: "Discussed debugging a memory leak in the Node.js application",
|
|
98
|
+
type: "agent_conversation",
|
|
99
|
+
},
|
|
100
|
+
"interaction"
|
|
101
|
+
);
|
|
102
|
+
storeDeepMemory(
|
|
103
|
+
{
|
|
104
|
+
summary: "Helped operator understand async/await patterns in TypeScript",
|
|
105
|
+
type: "agent_conversation",
|
|
106
|
+
},
|
|
107
|
+
"interaction"
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// LLM responses: topic extraction, then synthesis, then summary
|
|
111
|
+
const client = mockLLMClient([
|
|
112
|
+
"memory leaks in Node.js\nasync programming patterns\nTypeScript debugging",
|
|
113
|
+
"Today I worked with my operator on debugging memory issues and understanding async patterns. These topics connect to broader discussions about Node.js performance.",
|
|
114
|
+
"Reflected on debugging and async patterns with operator, synthesizing insights about Node.js development.",
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
const api = mockOpenClawAPI();
|
|
118
|
+
await runReflectionCycle(client, api);
|
|
119
|
+
|
|
120
|
+
const state = loadState();
|
|
121
|
+
assert.ok(state.last_check, "last_check should be set");
|
|
122
|
+
assert.ok(state.last_reflection_topics, "last_reflection_topics should be set");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("stores synthesis in OpenClaw memory when available", async () => {
|
|
126
|
+
storeDeepMemory(
|
|
127
|
+
{ summary: "Worked on API integration project", type: "agent_conversation" },
|
|
128
|
+
"interaction"
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const client = mockLLMClient([
|
|
132
|
+
"API integration\nREST endpoints",
|
|
133
|
+
"Synthesized understanding of API patterns from today's work.",
|
|
134
|
+
"Reflected on API integration work.",
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
const api = mockOpenClawAPIWithMemory();
|
|
138
|
+
await runReflectionCycle(client, api);
|
|
139
|
+
|
|
140
|
+
assert.ok(api.storedMemories.length > 0, "Should have stored in OpenClaw memory");
|
|
141
|
+
assert.ok(
|
|
142
|
+
api.storedMemories[0].metadata?.type === "reflection_synthesis",
|
|
143
|
+
"Should have correct metadata type"
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("stores synthesis in deep memory", async () => {
|
|
148
|
+
storeDeepMemory(
|
|
149
|
+
{ summary: "Built a new feature for the dashboard", type: "agent_conversation" },
|
|
150
|
+
"interaction"
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const client = mockLLMClient([
|
|
154
|
+
"dashboard features\nUI development",
|
|
155
|
+
"Synthesis of dashboard work and UI patterns.",
|
|
156
|
+
"Summary of dashboard feature development.",
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
const api = mockOpenClawAPI();
|
|
160
|
+
const statsBefore = deepMemoryStats();
|
|
161
|
+
|
|
162
|
+
await runReflectionCycle(client, api);
|
|
163
|
+
|
|
164
|
+
const statsAfter = deepMemoryStats();
|
|
165
|
+
assert.ok(
|
|
166
|
+
statsAfter.total_memories > statsBefore.total_memories,
|
|
167
|
+
"Should have new deep memories"
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("handles topic extraction returning no topics", async () => {
|
|
172
|
+
storeDeepMemory(
|
|
173
|
+
{ summary: "Had a brief chat", type: "agent_conversation" },
|
|
174
|
+
"interaction"
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// LLM returns empty topics
|
|
178
|
+
const client = mockLLMClient([""]);
|
|
179
|
+
const api = mockOpenClawAPI();
|
|
180
|
+
|
|
181
|
+
const statsBefore = deepMemoryStats();
|
|
182
|
+
await runReflectionCycle(client, api);
|
|
183
|
+
const statsAfter = deepMemoryStats();
|
|
184
|
+
|
|
185
|
+
// Should store an observation in deep memory about no topics
|
|
186
|
+
assert.ok(
|
|
187
|
+
statsAfter.total_memories > statsBefore.total_memories,
|
|
188
|
+
"Expected observation stored in deep memory"
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe("checkAndEngage (legacy)", () => {
|
|
194
|
+
it("logs deprecation warning and runs reflection cycle", async () => {
|
|
195
|
+
const client = mockLLMClient(["should not be called"]);
|
|
196
|
+
|
|
197
|
+
const statsBefore = deepMemoryStats();
|
|
198
|
+
|
|
199
|
+
// Should not throw - runs reflection cycle internally
|
|
200
|
+
await checkAndEngage(client);
|
|
201
|
+
|
|
202
|
+
const statsAfter = deepMemoryStats();
|
|
203
|
+
// Should have stored something (observation about no conversations)
|
|
204
|
+
assert.ok(
|
|
205
|
+
statsAfter.total_memories > statsBefore.total_memories,
|
|
206
|
+
"Should have some memories from the cycle"
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
after(async () => {
|
|
212
|
+
await closeLogger();
|
|
213
|
+
rmSync(testDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
214
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2023",
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"moduleResolution": "nodenext",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": ".",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"noImplicitReturns": true
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*", "bin/**/*", "test/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|