loom-claw 0.1.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/README.md +414 -0
- package/index.ts +1164 -0
- package/openclaw.plugin.json +38 -0
- package/package.json +52 -0
- package/src/client.ts +245 -0
- package/src/config.ts +53 -0
- package/src/engine.ts +387 -0
- package/src/types.ts +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
# Loom Memory Plugin for OpenClaw
|
|
2
|
+
|
|
3
|
+
Structured long-term memory for OpenClaw using loom. Automatically extracts key information from conversations into schema-based memory and injects relevant context back into the model prompt.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### 1. Install & configure Loom
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
cd Loom
|
|
11
|
+
pip install -e .
|
|
12
|
+
loom init # generates configs/loom.yaml and template files
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Open `configs/loom.yaml` and fill in the `llm` section (or copy `.env.example` to `.env` and edit):
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
# configs/loom.yaml
|
|
19
|
+
llm:
|
|
20
|
+
api_key: "your-api-key"
|
|
21
|
+
model: "google/gemini-2.5-flash" # any OpenAI-compatible model
|
|
22
|
+
base_url: "https://openrouter.ai/api/v1" # OpenRouter / OpenAI / local endpoint
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> **Supported providers:** OpenAI (`https://api.openai.com/v1`), OpenRouter (`https://openrouter.ai/api/v1`), or any OpenAI-compatible endpoint.
|
|
26
|
+
|
|
27
|
+
### 2. Start the Loom backend
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
loom serve # foreground (Ctrl+C to stop)
|
|
31
|
+
# or
|
|
32
|
+
loom serve start # background daemon (recommended)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The server runs at `http://localhost:8666` by default. Use `loom serve status` to verify.
|
|
36
|
+
|
|
37
|
+
### 3. Install OpenClaw (if not already installed)
|
|
38
|
+
|
|
39
|
+
If you don't have OpenClaw yet, install it first:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Recommended: one-line installer (auto-detects OS, installs Node if needed)
|
|
43
|
+
curl -fsSL https://openclaw.ai/install.sh | bash
|
|
44
|
+
|
|
45
|
+
# Or via npm / pnpm / bun if you manage Node yourself
|
|
46
|
+
npm install -g openclaw@latest
|
|
47
|
+
openclaw onboard --install-daemon
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Verify the installation:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
openclaw --version
|
|
54
|
+
openclaw doctor # check for config issues
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> See the [OpenClaw Install Guide](https://docs.openclaw.ai/install) for all install methods (Docker, Nix, from source, etc.).
|
|
58
|
+
|
|
59
|
+
### 4. Install the plugin
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
openclaw plugins install --link /path/to/Loom/loom-openclaw-plugin
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 5. Start (or restart) OpenClaw
|
|
66
|
+
|
|
67
|
+
If the Gateway is **not running**, start it:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
openclaw gateway
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
If the Gateway is **already running**, restart it to load the new plugin:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
openclaw gateway restart
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 6. Verify
|
|
80
|
+
|
|
81
|
+
Confirm the plugin is loaded and the Gateway is healthy:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Check the plugin is registered
|
|
85
|
+
openclaw plugins list --enabled
|
|
86
|
+
|
|
87
|
+
# Inspect plugin details
|
|
88
|
+
openclaw plugins inspect loom-claw
|
|
89
|
+
|
|
90
|
+
# Check Gateway health
|
|
91
|
+
openclaw gateway status
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Then open a chat and run `/loom status` — you should see Loom connection info and schema overview. The plugin will automatically extract and recall structured memories each turn.
|
|
95
|
+
|
|
96
|
+
## AI-Assisted Setup
|
|
97
|
+
|
|
98
|
+
You can let an AI agent handle the entire setup process for you.
|
|
99
|
+
|
|
100
|
+
**Option A: Via any LLM agent (OpenClaw, Telegram, etc.)**
|
|
101
|
+
|
|
102
|
+
Send this prompt to your agent:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
Read https://github.com/TeamEcho-AI/Loom/blob/main/skills/loom-setup/SKILL.md and follow it to install and configure Loom for OpenClaw. When done, summarize what you can do.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The agent will fetch the setup guide, then walk you through environment checks, LLM configuration, service startup, plugin installation, and verification step by step.
|
|
109
|
+
|
|
110
|
+
**Option B: Via Claude Code**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
claude skill install ./skills/loom-setup
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Once installed, say “help me run Loom” or “I want to add memory to OpenClaw” and the skill will trigger automatically.
|
|
117
|
+
|
|
118
|
+
## Features
|
|
119
|
+
|
|
120
|
+
- **Auto-extract** and **auto-recall** — the Loom CM agent extracts information from conversations into structured schemas and injects relevant data into the system prompt each turn
|
|
121
|
+
- **Schema-based memory** — organizes knowledge into typed domains and fields rather than flat text, enabling precise recall and structured reasoning
|
|
122
|
+
- **Multi-schema management** — create, switch, backup, and restore independent schema files for different contexts or personas
|
|
123
|
+
- **Template system** — bootstrap schemas from built-in, shared, or custom templates; create and manage templates via slash commands
|
|
124
|
+
- **Agent tools** — 5 registered tools let the LLM inspect, recall, build, forget, and update memory on demand
|
|
125
|
+
- **Slash commands** — full `/loom` command suite for manual memory management
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
## Prerequisites
|
|
129
|
+
|
|
130
|
+
| Requirement | Version | Check |
|
|
131
|
+
| --- | --- | --- |
|
|
132
|
+
| Python | 3.10+ | `python --version` |
|
|
133
|
+
| Node.js | 22.14+ (24 recommended) | `node --version` |
|
|
134
|
+
| Loom | latest | `loom --version` |
|
|
135
|
+
| OpenClaw | latest | `openclaw --version` |
|
|
136
|
+
|
|
137
|
+
### Loom backend setup
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
cd Loom
|
|
141
|
+
pip install -e .
|
|
142
|
+
loom init
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Configure your LLM provider by editing `configs/loom.yaml`:
|
|
146
|
+
|
|
147
|
+
```yaml
|
|
148
|
+
llm:
|
|
149
|
+
api_key: "your-api-key"
|
|
150
|
+
model: "google/gemini-2.5-flash"
|
|
151
|
+
base_url: "https://openrouter.ai/api/v1"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Alternatively, copy `.env.example` to `.env` and fill in `API_KEY`, `MODEL`, `BASE_URL`. Values in `.env` override `loom.yaml`.
|
|
155
|
+
|
|
156
|
+
Start the server:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
loom serve # foreground
|
|
160
|
+
loom serve start # background daemon
|
|
161
|
+
loom serve start --autostart # daemon + auto-start on boot
|
|
162
|
+
loom serve status # check if running
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The backend runs on `http://localhost:8666` by default.
|
|
166
|
+
|
|
167
|
+
### OpenClaw installation
|
|
168
|
+
|
|
169
|
+
If OpenClaw is not yet installed:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
curl -fsSL https://openclaw.ai/install.sh | bash
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Or install manually via npm:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npm install -g openclaw@latest
|
|
179
|
+
openclaw onboard --install-daemon
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
See the [OpenClaw Install Guide](https://docs.openclaw.ai/install) for Docker, Nix, and other options.
|
|
183
|
+
|
|
184
|
+
## Installation
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
openclaw plugins install --link /path/to/Loom/loom-openclaw-plugin
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The installer automatically registers the plugin as the active Context Engine. **A Gateway restart is required** to load the plugin:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# If the Gateway is already running as a service
|
|
194
|
+
openclaw gateway restart
|
|
195
|
+
|
|
196
|
+
# Or start it fresh
|
|
197
|
+
openclaw gateway
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
To configure the context engine slot manually, add to your `openclaw.json`:
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"plugins": {
|
|
205
|
+
"slots": {
|
|
206
|
+
"contextEngine": "loom-claw"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Verify installation
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# Plugin should appear in the loaded list
|
|
216
|
+
openclaw plugins list --enabled
|
|
217
|
+
|
|
218
|
+
# Detailed plugin info (config schema, status, capabilities)
|
|
219
|
+
openclaw plugins inspect loom-claw
|
|
220
|
+
|
|
221
|
+
# Gateway health check
|
|
222
|
+
openclaw gateway status
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Once the Gateway is running, open a chat and send `/loom status` to confirm end-to-end connectivity with the Loom backend.
|
|
226
|
+
|
|
227
|
+
> See [OpenClaw Plugin docs](https://docs.openclaw.ai/tools/plugin) for full plugin management commands, and [Gateway CLI](https://docs.openclaw.ai/cli/gateway) for service lifecycle.
|
|
228
|
+
|
|
229
|
+
## Configuration
|
|
230
|
+
|
|
231
|
+
Configure in `openclaw.json` under `plugins.entries.loom-claw.config`:
|
|
232
|
+
|
|
233
|
+
| Option | Default | Description |
|
|
234
|
+
| --- | --- | --- |
|
|
235
|
+
| `loomBaseUrl` | `http://localhost:8666` | Loom backend URL |
|
|
236
|
+
| `sessionId` | `default` | Loom session ID |
|
|
237
|
+
| `schemaId` | `default` | Shared schema file ID for cross-session memory |
|
|
238
|
+
| `schemaTemplate` | — | Initial template: `general`, `roleplay`, or any custom template |
|
|
239
|
+
| `buildEveryNTurns` | `1` | Run memory extraction every N conversation turns (same concept as Loom `build_every_n_turns`) |
|
|
240
|
+
|
|
241
|
+
Example `openclaw.json`:
|
|
242
|
+
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"plugins": {
|
|
246
|
+
"entries": {
|
|
247
|
+
"loom-claw": {
|
|
248
|
+
"enabled": true,
|
|
249
|
+
"config": {
|
|
250
|
+
"loomBaseUrl": "http://localhost:8666",
|
|
251
|
+
"sessionId": "default",
|
|
252
|
+
"schemaId": "default",
|
|
253
|
+
"schemaTemplate": "general",
|
|
254
|
+
"buildEveryNTurns": 1
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Slash Commands
|
|
263
|
+
|
|
264
|
+
The plugin registers the `/loom` command with the following subcommands:
|
|
265
|
+
|
|
266
|
+
**View & Recall**
|
|
267
|
+
|
|
268
|
+
| Command | Description |
|
|
269
|
+
| --- | --- |
|
|
270
|
+
| `/loom` or `/loom status` | Show connection status and schema overview |
|
|
271
|
+
| `/loom inspect` | View schema structure with field values |
|
|
272
|
+
| `/loom recall` | Recall all stored memory data |
|
|
273
|
+
|
|
274
|
+
**Memory Management**
|
|
275
|
+
|
|
276
|
+
| Command | Description |
|
|
277
|
+
| --- | --- |
|
|
278
|
+
| `/loom forget <domain>` | Delete a specific schema domain |
|
|
279
|
+
| `/loom forget --all` | Clear all memory |
|
|
280
|
+
| `/loom reset` | Backup current schema and start fresh |
|
|
281
|
+
|
|
282
|
+
**Schema Files**
|
|
283
|
+
|
|
284
|
+
| Command | Description |
|
|
285
|
+
| --- | --- |
|
|
286
|
+
| `/loom schemas` | List all schema files and backups |
|
|
287
|
+
| `/loom new [name]` | Create a new blank schema and switch to it |
|
|
288
|
+
| `/loom switch <schema_id>` | Switch to an existing schema |
|
|
289
|
+
| `/loom restore <backup_id>` | Restore a schema from backup |
|
|
290
|
+
|
|
291
|
+
**Template Management**
|
|
292
|
+
|
|
293
|
+
| Command | Description |
|
|
294
|
+
| --- | --- |
|
|
295
|
+
| `/loom templates` | List all available templates (grouped by source) |
|
|
296
|
+
| `/loom templates show <name>` | Preview template domains and fields |
|
|
297
|
+
| `/loom templates use <name>` | Create a schema from template and switch to it |
|
|
298
|
+
| `/loom templates create` | Show format help for creating custom templates |
|
|
299
|
+
| `/loom templates create <definition>` | Create a custom template (compact text or `--json`) |
|
|
300
|
+
| `/loom templates delete <name>` | Delete a custom template |
|
|
301
|
+
| `/loom templates help` | Show template command help |
|
|
302
|
+
|
|
303
|
+
**Configuration**
|
|
304
|
+
|
|
305
|
+
| Command | Description |
|
|
306
|
+
| --- | --- |
|
|
307
|
+
| `/loom config` | View current runtime configuration |
|
|
308
|
+
| `/loom config buildEveryNTurns <N>` | Update extraction frequency at runtime |
|
|
309
|
+
| `/loom help` | Show help |
|
|
310
|
+
|
|
311
|
+
## Agent Tools
|
|
312
|
+
|
|
313
|
+
Five tools are registered for the OpenClaw agent to use during conversations:
|
|
314
|
+
|
|
315
|
+
| Tool | Description |
|
|
316
|
+
| --- | --- |
|
|
317
|
+
| `loom_inspect` | Inspect schema structure and field values |
|
|
318
|
+
| `loom_recall` | Recall all schema memory data |
|
|
319
|
+
| `loom_build` | Manually trigger information extraction and storage |
|
|
320
|
+
| `loom_forget` | Delete a specific domain or clear all memory |
|
|
321
|
+
| `loom_update` | Trigger schema update from session chat history |
|
|
322
|
+
|
|
323
|
+
## Creating Custom Templates
|
|
324
|
+
|
|
325
|
+
You can create custom templates directly from the chat using the compact text format:
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
/loom templates create game_character RPG character memory
|
|
329
|
+
character: name | character name, class | class, level | level, skills | skills
|
|
330
|
+
story: main_quest | main quest, side_quests | side quests, achievements | achievements
|
|
331
|
+
social: friends | friends, guild | guild, reputation | reputation
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Format rules:
|
|
335
|
+
- First line: `template_name description` (name allows letters, numbers, underscores, hyphens)
|
|
336
|
+
- Following lines: `domain_name: field1 | description, field2 | description`
|
|
337
|
+
- Fields separated by `,`, field name and description separated by `|`
|
|
338
|
+
|
|
339
|
+
Alternatively, use JSON format:
|
|
340
|
+
|
|
341
|
+
```
|
|
342
|
+
/loom templates create --json {"_meta":{"name":"my_template","description":"..."},"domain1":{"data":{...},"_mutable":true}}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Context Engine Lifecycle
|
|
346
|
+
|
|
347
|
+
| OpenClaw Hook | Plugin Behavior | Loom API |
|
|
348
|
+
| --- | --- | --- |
|
|
349
|
+
| `bootstrap` | Verify backend, create session, load template | `POST /api/sessions`, `GET /api/schemas/recall-all` |
|
|
350
|
+
| `assemble` | Fetch schema data and inject into system prompt | `GET /api/schemas/recall-all` |
|
|
351
|
+
| `afterTurn` | Format new messages, call build to extract info | `POST /api/build` |
|
|
352
|
+
| `compact` | Delegate to runtime | — |
|
|
353
|
+
|
|
354
|
+
## Data Flow
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
User message → OpenClaw agent
|
|
358
|
+
↓
|
|
359
|
+
[assemble] → GET /api/schemas/recall-all
|
|
360
|
+
↓ → schema data injected into system prompt
|
|
361
|
+
Model generates response
|
|
362
|
+
↓
|
|
363
|
+
[afterTurn] → POST /api/build
|
|
364
|
+
→ CM Agent extracts information
|
|
365
|
+
→ Updates schema
|
|
366
|
+
→ Available on next assemble
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Data Storage
|
|
370
|
+
|
|
371
|
+
Loom stores data under the OpenClaw [Agent Workspace](https://docs.openclaw.ai/concepts/agent-workspace):
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
~/.openclaw/workspace/loom/
|
|
375
|
+
├── schemas/ # Schema files (shared across sessions)
|
|
376
|
+
│ ├── default.json
|
|
377
|
+
│ └── backups/ # Auto-created on reset
|
|
378
|
+
│ └── default_20260314_180736.json
|
|
379
|
+
└── sessions/ # Loom session files
|
|
380
|
+
└── default.json
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Configure the paths in `configs/loom.yaml`:
|
|
384
|
+
|
|
385
|
+
```yaml
|
|
386
|
+
persistence:
|
|
387
|
+
session_dir: "~/.openclaw/workspace/loom/sessions"
|
|
388
|
+
schemas_dir: "~/.openclaw/workspace/loom/schemas"
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Development
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Install dependencies
|
|
395
|
+
npm install
|
|
396
|
+
|
|
397
|
+
# Type check
|
|
398
|
+
npm run typecheck
|
|
399
|
+
|
|
400
|
+
# Run tests
|
|
401
|
+
npm test
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
To develop with a local link:
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
openclaw plugins install --link /path/to/Loom/loom-openclaw-plugin
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Changes to the TypeScript source are picked up on the next gateway restart.
|
|
411
|
+
|
|
412
|
+
## License
|
|
413
|
+
|
|
414
|
+
MIT
|