@xdarkicex/openclaw-memory-libravdb 1.4.6 → 1.4.7

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.
Files changed (75) hide show
  1. package/HOOK.md +14 -0
  2. package/README.md +32 -2
  3. package/dist/cli.d.ts +39 -0
  4. package/dist/cli.js +208 -0
  5. package/dist/context-engine.d.ts +56 -0
  6. package/dist/context-engine.js +125 -0
  7. package/dist/dream-promotion.d.ts +47 -0
  8. package/dist/dream-promotion.js +363 -0
  9. package/dist/dream-routing.d.ts +6 -0
  10. package/dist/dream-routing.js +31 -0
  11. package/dist/durable-namespace.d.ts +6 -0
  12. package/dist/durable-namespace.js +24 -0
  13. package/dist/grpc-client.d.ts +23 -0
  14. package/dist/grpc-client.js +104 -0
  15. package/dist/index.d.ts +10 -0
  16. package/dist/index.js +40 -0
  17. package/dist/lifecycle-hooks.d.ts +4 -0
  18. package/dist/lifecycle-hooks.js +64 -0
  19. package/dist/markdown-hash.d.ts +3 -0
  20. package/dist/markdown-hash.js +82 -0
  21. package/dist/markdown-ingest.d.ts +43 -0
  22. package/dist/markdown-ingest.js +464 -0
  23. package/dist/memory-provider.d.ts +4 -0
  24. package/dist/memory-provider.js +13 -0
  25. package/dist/memory-runtime.d.ts +118 -0
  26. package/dist/memory-runtime.js +217 -0
  27. package/dist/plugin-runtime.d.ts +28 -0
  28. package/dist/plugin-runtime.js +127 -0
  29. package/dist/proto/intelligence_kernel/v1/kernel.proto +378 -0
  30. package/dist/recall-cache.d.ts +2 -0
  31. package/dist/recall-cache.js +30 -0
  32. package/dist/rpc-protobuf-codecs.d.ts +70 -0
  33. package/dist/rpc-protobuf-codecs.js +77 -0
  34. package/dist/rpc.d.ts +14 -0
  35. package/dist/rpc.js +121 -0
  36. package/dist/sidecar.d.ts +34 -0
  37. package/dist/sidecar.js +535 -0
  38. package/dist/types.d.ts +163 -0
  39. package/dist/types.js +1 -0
  40. package/docs/contributing.md +14 -13
  41. package/docs/install.md +7 -9
  42. package/docs/installation.md +23 -16
  43. package/docs/uninstall.md +1 -1
  44. package/index.js +2 -0
  45. package/openclaw.plugin.json +2 -2
  46. package/package.json +39 -16
  47. package/packaging/README.md +0 -71
  48. package/packaging/homebrew/libravdbd.rb.tmpl +0 -224
  49. package/packaging/launchd/com.xdarkicex.libravdbd.plist +0 -32
  50. package/packaging/systemd/libravdbd.service +0 -12
  51. package/src/cli.ts +0 -299
  52. package/src/comparison-experiments.ts +0 -128
  53. package/src/context-engine.ts +0 -1645
  54. package/src/continuity.ts +0 -93
  55. package/src/dream-promotion.ts +0 -492
  56. package/src/dream-routing.ts +0 -40
  57. package/src/durable-namespace.ts +0 -34
  58. package/src/index.ts +0 -47
  59. package/src/lifecycle-hooks.ts +0 -96
  60. package/src/markdown-hash.ts +0 -104
  61. package/src/markdown-ingest.ts +0 -627
  62. package/src/memory-provider.ts +0 -25
  63. package/src/memory-runtime.ts +0 -283
  64. package/src/openclaw-plugin-sdk.d.ts +0 -59
  65. package/src/plugin-runtime.ts +0 -119
  66. package/src/recall-cache.ts +0 -34
  67. package/src/recall-utils.ts +0 -131
  68. package/src/rpc.ts +0 -92
  69. package/src/scoring.ts +0 -632
  70. package/src/sidecar.ts +0 -583
  71. package/src/temporal.ts +0 -1031
  72. package/src/tokens.ts +0 -52
  73. package/src/types.ts +0 -278
  74. package/tsconfig.json +0 -20
  75. package/tsconfig.tests.json +0 -12
@@ -1,224 +0,0 @@
1
- class Libravdbd < Formula
2
- desc "Local LibraVDB daemon for the OpenClaw memory plugin"
3
- homepage "https://github.com/xDarkicex/openclaw-memory-libravdb"
4
- version "__VERSION__"
5
-
6
- on_macos do
7
- if Hardware::CPU.arm?
8
- url "https://github.com/xDarkicex/openclaw-memory-libravdb/releases/download/v#{version}/libravdbd-darwin-arm64"
9
- sha256 "__SHA256_DARWIN_ARM64__"
10
- else
11
- url "https://github.com/xDarkicex/openclaw-memory-libravdb/releases/download/v#{version}/libravdbd-darwin-amd64"
12
- sha256 "__SHA256_DARWIN_AMD64__"
13
- end
14
- end
15
-
16
- on_linux do
17
- if Hardware::CPU.arm?
18
- url "https://github.com/xDarkicex/openclaw-memory-libravdb/releases/download/v#{version}/libravdbd-linux-arm64"
19
- sha256 "__SHA256_LINUX_ARM64__"
20
- else
21
- url "https://github.com/xDarkicex/openclaw-memory-libravdb/releases/download/v#{version}/libravdbd-linux-amd64"
22
- sha256 "__SHA256_LINUX_AMD64__"
23
- end
24
- end
25
-
26
- if OS.mac?
27
- resource "onnxruntime" do
28
- url "https://github.com/microsoft/onnxruntime/releases/download/v1.23.0/onnxruntime-osx-universal2-1.23.0.tgz"
29
- sha256 "5e4365fb4a05aef353f6232b9a1848f37e608c421c9227e9224572205c0cfc08"
30
- end
31
- elsif OS.linux?
32
- if Hardware::CPU.arm?
33
- resource "onnxruntime" do
34
- url "https://github.com/microsoft/onnxruntime/releases/download/v1.23.0/onnxruntime-linux-aarch64-1.23.0.tgz"
35
- sha256 "0b9f47d140411d938e47915824d8daaa424df95a88b5f1fc843172a75168f7a0"
36
- end
37
- else
38
- resource "onnxruntime" do
39
- url "https://github.com/microsoft/onnxruntime/releases/download/v1.23.0/onnxruntime-linux-x64-1.23.0.tgz"
40
- sha256 "b6deea7f2e22c10c043019f294a0ea4d2a6c0ae52a009c34847640db75ec5580"
41
- end
42
- end
43
- end
44
-
45
- resource "nomic-embed-text-v1.5-model" do
46
- url "https://huggingface.co/nomic-ai/nomic-embed-text-v1.5/resolve/main/onnx/model.onnx"
47
- sha256 "147d5aa88c2101237358e17796cf3a227cead1ec304ec34b465bb08e9d952965"
48
- end
49
-
50
- resource "nomic-embed-text-v1.5-tokenizer" do
51
- url "https://huggingface.co/nomic-ai/nomic-embed-text-v1.5/resolve/main/tokenizer.json"
52
- sha256 "d241a60d5e8f04cc1b2b3e9ef7a4921b27bf526d9f6050ab90f9267a1f9e5c66"
53
- end
54
-
55
- resource "all-minilm-l6-v2-model" do
56
- url "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/onnx/model.onnx"
57
- sha256 "6fd5d72fe4589f189f8ebc006442dbb529bb7ce38f8082112682524616046452"
58
- end
59
-
60
- resource "all-minilm-l6-v2-tokenizer" do
61
- url "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer.json"
62
- sha256 "be50c3628f2bf5bb5e3a7f17b1f74611b2561a3a27eeab05e5aa30f411572037"
63
- end
64
-
65
- resource "t5-small-encoder" do
66
- url "https://huggingface.co/optimum/t5-small/resolve/main/encoder_model.onnx"
67
- sha256 "41d326633f1b85f526508cc0db78a5d40877c292c1b6dccae2eacd7d2a53480d"
68
- end
69
-
70
- resource "t5-small-decoder" do
71
- url "https://huggingface.co/optimum/t5-small/resolve/main/decoder_model.onnx"
72
- sha256 "0a1451011d61bcc796a87b7306c503562e910f110f884d0cc08532972c2cc584"
73
- end
74
-
75
- resource "t5-small-tokenizer" do
76
- url "https://huggingface.co/optimum/t5-small/resolve/main/tokenizer.json"
77
- sha256 "5f0ed8ab5b8cfa9812bb73752f1d80c292e52bcf5a87a144dc9ab2d251056cbb"
78
- end
79
-
80
- resource "t5-small-tokenizer-config" do
81
- url "https://huggingface.co/optimum/t5-small/resolve/main/tokenizer_config.json"
82
- sha256 "4969f8d76ef05a16553bd2b07b3501673ae8d36972aea88a0f78ad31a3ff2de9"
83
- end
84
-
85
- resource "t5-small-config" do
86
- url "https://huggingface.co/optimum/t5-small/resolve/main/config.json"
87
- sha256 "d112428e703aa7ea0d6b17a77e9739fcc15b87653779d9b7942d5ecbc61c00ed"
88
- end
89
-
90
- resource "provision" do
91
- url "https://github.com/xDarkicex/openclaw-memory-libravdb/releases/download/v__VERSION__/provision.sh"
92
- sha256 "__SHA256_PROVISION__"
93
- end
94
-
95
- def install
96
- bin.install Dir["libravdbd*"].first => "libravdbd"
97
-
98
- models_dir = prefix/"models"
99
- runtime_dir = models_dir/"onnxruntime"
100
- nomic_dir = models_dir/"nomic-embed-text-v1.5"
101
- minilm_dir = models_dir/"all-minilm-l6-v2"
102
- t5_dir = models_dir/"t5-small"
103
-
104
- runtime_dir.mkpath
105
- nomic_dir.mkpath
106
- minilm_dir.mkpath
107
- t5_dir.mkpath
108
-
109
- resource("onnxruntime").stage do
110
- # Homebrew may auto-strip the top-level dir from the tgz
111
- subdir = Dir["onnxruntime-*"].first
112
- if subdir
113
- cp_r "#{subdir}/.", runtime_dir
114
- else
115
- cp_r ".", runtime_dir
116
- end
117
- end
118
-
119
- resource("nomic-embed-text-v1.5-model").stage do
120
- cp "model.onnx", nomic_dir/"model.onnx"
121
- end
122
- resource("nomic-embed-text-v1.5-tokenizer").stage do
123
- cp "tokenizer.json", nomic_dir/"tokenizer.json"
124
- end
125
- write_embedding_manifest(nomic_dir, "nomic-embed-text-v1.5", 768)
126
-
127
- resource("all-minilm-l6-v2-model").stage do
128
- cp "model.onnx", minilm_dir/"model.onnx"
129
- end
130
- resource("all-minilm-l6-v2-tokenizer").stage do
131
- cp "tokenizer.json", minilm_dir/"tokenizer.json"
132
- end
133
- write_embedding_manifest(minilm_dir, "all-minilm-l6-v2", 384)
134
-
135
- resource("t5-small-encoder").stage do
136
- cp "encoder_model.onnx", t5_dir/"encoder_model.onnx"
137
- end
138
- resource("t5-small-decoder").stage do
139
- cp "decoder_model.onnx", t5_dir/"decoder_model.onnx"
140
- end
141
- resource("t5-small-tokenizer").stage do
142
- cp "tokenizer.json", t5_dir/"tokenizer.json"
143
- end
144
- resource("t5-small-tokenizer-config").stage do
145
- cp "tokenizer_config.json", t5_dir/"tokenizer_config.json"
146
- end
147
- resource("t5-small-config").stage do
148
- cp "config.json", t5_dir/"config.json"
149
- end
150
- write_summarizer_manifest(t5_dir, "t5-small")
151
-
152
- resource("provision").stage do
153
- libexec.install "provision.sh"
154
- end
155
- chmod 0755, libexec/"provision.sh"
156
- end
157
-
158
- def post_install
159
- (var/"clawdb").mkpath
160
- (var/"clawdb/run").mkpath
161
- end
162
-
163
- def caveats
164
- <<~EOS
165
- libravdbd requires ONNX embedding models to function. Models are
166
- automatically provisioned during `brew install`. To re-provision
167
- or repair assets manually:
168
-
169
- #{libexec}/provision.sh --target #{prefix}/models
170
-
171
- Data directory: #{var}/clawdb
172
- Database file: #{var}/clawdb/data.libravdb
173
- Socket directory: #{var}/clawdb/run
174
- EOS
175
- end
176
-
177
- private
178
-
179
- def write_embedding_manifest(dir, profile, dimensions)
180
- File.write(dir/"embedding.json", <<~JSON)
181
- {
182
- "backend": "onnx-local",
183
- "profile": "#{profile}",
184
- "family": "#{profile}",
185
- "model": "model.onnx",
186
- "tokenizer": "tokenizer.json",
187
- "dimensions": #{dimensions},
188
- "normalize": true,
189
- "inputNames": ["input_ids", "attention_mask", "token_type_ids"],
190
- "outputName": "last_hidden_state",
191
- "pooling": "mean",
192
- "addSpecialTokens": true
193
- }
194
- JSON
195
- end
196
-
197
- def write_summarizer_manifest(dir, profile)
198
- File.write(dir/"summarizer.json", <<~JSON)
199
- {
200
- "backend": "onnx-local",
201
- "profile": "#{profile}",
202
- "family": "#{profile}",
203
- "encoder": "encoder_model.onnx",
204
- "decoder": "decoder_model.onnx",
205
- "tokenizer": "tokenizer.json",
206
- "maxContextTokens": 512
207
- }
208
- JSON
209
- end
210
-
211
- service do
212
- run [opt_bin/"libravdbd", "serve"]
213
- environment_variables LIBRAVDB_RPC_ENDPOINT: "unix:#{var}/clawdb/run/libravdb.sock",
214
- LIBRAVDB_DB_PATH: "#{var}/clawdb/data.libravdb",
215
- LIBRAVDB_ONNX_RUNTIME: "#{opt_prefix}/models/onnxruntime/lib/libonnxruntime.dylib",
216
- LIBRAVDB_SUMMARIZER_BACKEND: "bundled"
217
- keep_alive true
218
- working_dir var/"clawdb"
219
- end
220
-
221
- test do
222
- assert_match "libravdbd", shell_output("#{bin}/libravdbd version")
223
- end
224
- end
@@ -1,32 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>Label</key>
6
- <string>com.xdarkicex.libravdbd</string>
7
- <key>ProgramArguments</key>
8
- <array>
9
- <string>__LIBRAVDBD_PATH__</string>
10
- <string>serve</string>
11
- </array>
12
- <key>EnvironmentVariables</key>
13
- <dict>
14
- <key>LIBRAVDB_RPC_ENDPOINT</key>
15
- <string>unix:__HOME__/.clawdb/run/libravdb.sock</string>
16
- <key>LIBRAVDB_DB_PATH</key>
17
- <string>__HOME__/.clawdb/data</string>
18
- <key>LIBRAVDB_ONNX_RUNTIME</key>
19
- <string>__ONNX_RUNTIME_LIB__</string>
20
- <key>LIBRAVDB_SUMMARIZER_BACKEND</key>
21
- <string>bundled</string>
22
- </dict>
23
- <key>RunAtLoad</key>
24
- <true/>
25
- <key>KeepAlive</key>
26
- <true/>
27
- <key>StandardOutPath</key>
28
- <string>__HOME__/Library/Logs/libravdbd.log</string>
29
- <key>StandardErrorPath</key>
30
- <string>__HOME__/Library/Logs/libravdbd.log</string>
31
- </dict>
32
- </plist>
@@ -1,12 +0,0 @@
1
- [Unit]
2
- Description=LibraVDB daemon (user)
3
- After=network.target
4
-
5
- [Service]
6
- ExecStart=%h/.local/bin/libravdbd serve
7
- Restart=on-failure
8
- RestartSec=5
9
- Environment=LIBRAVDB_RPC_ENDPOINT=unix:%h/.clawdb/run/libravdb.sock
10
-
11
- [Install]
12
- WantedBy=default.target
package/src/cli.ts DELETED
@@ -1,299 +0,0 @@
1
- import { createInterface } from "node:readline/promises";
2
- import { stdin, stdout } from "node:process";
3
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
4
- import { resolveDurableNamespace } from "./durable-namespace.js";
5
- import { promoteDreamDiaryFile } from "./dream-promotion.js";
6
- import type { PluginRuntime } from "./plugin-runtime.js";
7
- import type { LoggerLike, PluginConfig } from "./types.js";
8
-
9
- type StatusResult = {
10
- ok?: boolean;
11
- message?: string;
12
- turnCount?: number;
13
- memoryCount?: number;
14
- lifecycleHintCount?: number;
15
- gatingThreshold?: number;
16
- abstractiveReady?: boolean;
17
- embeddingProfile?: string;
18
- };
19
-
20
- type ExportResult = {
21
- records?: Array<{
22
- collection: string;
23
- id: string;
24
- text: string;
25
- metadata: Record<string, unknown>;
26
- }>;
27
- };
28
-
29
- type CliOptionBag = {
30
- dreamFile?: string;
31
- userId?: string;
32
- sessionKey?: string;
33
- sessionId?: string;
34
- limit?: string | number;
35
- yes?: boolean;
36
- };
37
-
38
- type JournalResult = {
39
- results?: Array<{
40
- id: string;
41
- metadata: Record<string, unknown>;
42
- }>;
43
- };
44
-
45
- type CliCommand = {
46
- commands?: CliCommand[];
47
- command(name: string): CliCommand;
48
- description(text: string): CliCommand;
49
- option(flags: string, description: string): CliCommand;
50
- requiredOption?(flags: string, description: string): CliCommand;
51
- action(handler: (opts?: CliOptionBag) => unknown): CliCommand;
52
- name?(): string;
53
- };
54
-
55
- type CliProgram = CliCommand;
56
-
57
- export function registerMemoryCli(
58
- api: OpenClawPluginApi,
59
- runtime: PluginRuntime,
60
- cfg: PluginConfig,
61
- logger: LoggerLike = console,
62
- ): void {
63
- if (!api.registerCli) {
64
- return;
65
- }
66
-
67
- api.registerCli(
68
- ({ program }) => {
69
- const root = ensureCommand(program, "memory")
70
- .description("Manage LibraVDB memory");
71
-
72
- ensureCommand(root, "status")
73
- .description("Show sidecar health, record counts, and active thresholds")
74
- .action(() => void runStatus(runtime, cfg, logger));
75
-
76
- const flush = ensureCommand(root, "flush")
77
- .description("Wipe a durable memory namespace after confirmation");
78
- if (flush.requiredOption) {
79
- flush.requiredOption("--user-id <userId>", "User id whose durable memory should be deleted");
80
- } else {
81
- flush.option("--user-id <userId>", "User id whose durable memory should be deleted");
82
- }
83
- flush.option("--session-key <sessionKey>", "Session key whose derived durable namespace should be deleted");
84
- flush
85
- .option("--yes", "Skip the confirmation prompt")
86
- .action((opts) => void runFlush(runtime, opts, logger));
87
-
88
- const exportCmd = ensureCommand(root, "export")
89
- .description("Stream stored memories as newline-delimited JSON");
90
- exportCmd.option("--user-id <userId>", "Restrict export to a single user namespace");
91
- exportCmd.option("--session-key <sessionKey>", "Restrict export to a derived session-key namespace");
92
- exportCmd.action((opts) => void runExport(runtime, opts, logger));
93
-
94
- const journal = ensureCommand(root, "journal")
95
- .description("Inspect internal lifecycle journal hints");
96
- journal.option("--session-id <sessionId>", "Restrict journal entries to one session id");
97
- journal.option("--limit <limit>", "Maximum journal entries to show");
98
- journal.action((opts) => void runJournal(runtime, opts, logger));
99
-
100
- const dreamPromote = ensureCommand(root, "dream-promote")
101
- .description("Promote vetted dream diary entries into the dedicated dream collection");
102
- if (dreamPromote.requiredOption) {
103
- dreamPromote.requiredOption("--user-id <userId>", "User id whose dream collection should receive the promotion");
104
- dreamPromote.requiredOption("--dream-file <path>", "Dream diary markdown file to promote from");
105
- } else {
106
- dreamPromote.option("--user-id <userId>", "User id whose dream collection should receive the promotion");
107
- dreamPromote.option("--dream-file <path>", "Dream diary markdown file to promote from");
108
- }
109
- dreamPromote.action((opts) => void runDreamPromote(runtime, opts, logger));
110
- },
111
- {
112
- descriptors: [
113
- {
114
- name: "memory",
115
- description: "Manage LibraVDB memory",
116
- hasSubcommands: true,
117
- },
118
- ],
119
- },
120
- );
121
- }
122
-
123
- function ensureCommand(parent: CliCommand, name: string): CliCommand {
124
- const existing = parent.commands?.find((command) => {
125
- if (typeof command.name === "function") {
126
- return command.name() === name;
127
- }
128
- return false;
129
- });
130
- if (existing) {
131
- return existing;
132
- }
133
- return parent.command(name);
134
- }
135
-
136
- async function runStatus(runtime: PluginRuntime, cfg: PluginConfig, logger: LoggerLike): Promise<void> {
137
- try {
138
- const rpc = await runtime.getRpc();
139
- const status = await rpc.call<StatusResult>("status", {});
140
- console.table({
141
- Sidecar: status.ok ? "running" : "down",
142
- "Turns stored": status.turnCount ?? 0,
143
- "Memories stored": status.memoryCount ?? 0,
144
- "Lifecycle hints": status.lifecycleHintCount ?? 0,
145
- "Gate threshold": status.gatingThreshold ?? cfg.ingestionGateThreshold ?? 0.35,
146
- "Abstractive model": status.abstractiveReady ? "ready" : "not provisioned",
147
- "Embedding profile": status.embeddingProfile ?? "unknown",
148
- Message: status.message ?? (status.ok ? "ok" : "unavailable"),
149
- });
150
- } catch (error) {
151
- logger.error(`LibraVDB status unavailable: ${formatError(error)}`);
152
- console.table({
153
- Sidecar: "down",
154
- "Turns stored": "n/a",
155
- "Memories stored": "n/a",
156
- "Lifecycle hints": "n/a",
157
- "Gate threshold": cfg.ingestionGateThreshold ?? 0.35,
158
- "Abstractive model": "unknown",
159
- "Embedding profile": "unknown",
160
- Message: formatError(error),
161
- });
162
- process.exitCode = 1;
163
- }
164
- }
165
-
166
- async function runFlush(runtime: PluginRuntime, opts: CliOptionBag | undefined, logger: LoggerLike): Promise<void> {
167
- const namespace = resolveCliNamespace(opts);
168
- if (!namespace) {
169
- logger.error("LibraVDB flush requires --user-id <userId> or --session-key <sessionKey>.");
170
- process.exitCode = 1;
171
- return;
172
- }
173
-
174
- if (!opts?.yes) {
175
- const confirmed = await confirm(`Delete durable memory namespace ${namespace}? [y/N] `);
176
- if (!confirmed) {
177
- console.log("Aborted.");
178
- return;
179
- }
180
- }
181
-
182
- try {
183
- const rpc = await runtime.getRpc();
184
- await rpc.call("flush_namespace", { namespace });
185
- console.log(`Deleted durable memory namespace ${namespace}.`);
186
- } catch (error) {
187
- logger.error(`LibraVDB flush failed: ${formatError(error)}`);
188
- process.exitCode = 1;
189
- }
190
- }
191
-
192
- async function runExport(runtime: PluginRuntime, opts: CliOptionBag | undefined, logger: LoggerLike): Promise<void> {
193
- try {
194
- const rpc = await runtime.getRpc();
195
- const result = await rpc.call<ExportResult>("export_memory", {
196
- namespace: resolveCliNamespace(opts),
197
- });
198
- for (const record of result.records ?? []) {
199
- stdout.write(`${JSON.stringify(record)}\n`);
200
- }
201
- } catch (error) {
202
- logger.error(`LibraVDB export failed: ${formatError(error)}`);
203
- process.exitCode = 1;
204
- }
205
- }
206
-
207
- async function runJournal(runtime: PluginRuntime, opts: CliOptionBag | undefined, logger: LoggerLike): Promise<void> {
208
- try {
209
- const rpc = await runtime.getRpc();
210
- const result = await rpc.call<JournalResult>("list_lifecycle_journal", {
211
- sessionId: opts?.sessionId?.trim() || undefined,
212
- limit: normalizeLimit(opts?.limit),
213
- });
214
- for (const record of result.results ?? []) {
215
- stdout.write(`${JSON.stringify(record)}\n`);
216
- }
217
- } catch (error) {
218
- logger.error(`LibraVDB journal lookup failed: ${formatError(error)}`);
219
- process.exitCode = 1;
220
- }
221
- }
222
-
223
- async function runDreamPromote(runtime: PluginRuntime, opts: CliOptionBag | undefined, logger: LoggerLike): Promise<void> {
224
- const userId = opts?.userId?.trim();
225
- const dreamFile = opts?.dreamFile?.trim();
226
- if (!userId || !dreamFile) {
227
- logger.error("LibraVDB dream-promote requires --user-id <userId> and --dream-file <path>.");
228
- process.exitCode = 1;
229
- return;
230
- }
231
-
232
- try {
233
- const rpc = await runtime.getRpc();
234
- const result = await promoteDreamDiaryFile(rpc, { userId, diaryPath: dreamFile });
235
- console.log(
236
- `Promoted ${result.promoted ?? 0} dream entr${(result.promoted ?? 0) === 1 ? "y" : "ies"}; rejected ${result.rejected ?? 0}.`,
237
- );
238
- } catch (error) {
239
- logger.error(`LibraVDB dream promotion failed: ${formatError(error)}`);
240
- process.exitCode = 1;
241
- }
242
- }
243
-
244
- async function confirm(prompt: string): Promise<boolean> {
245
- const rl = createInterface({ input: stdin, output: stdout });
246
- try {
247
- const answer = await rl.question(prompt);
248
- return answer.trim().toLowerCase() === "y";
249
- } finally {
250
- rl.close();
251
- }
252
- }
253
-
254
- function formatError(error: unknown): string {
255
- if (error instanceof Error && error.message.trim()) {
256
- return error.message;
257
- }
258
- return String(error);
259
- }
260
-
261
- function normalizeLimit(limit: string | number | undefined): number | undefined {
262
- if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) {
263
- return Math.floor(limit);
264
- }
265
- if (typeof limit === "string") {
266
- const parsed = Number.parseInt(limit, 10);
267
- if (Number.isFinite(parsed) && parsed > 0) {
268
- return parsed;
269
- }
270
- }
271
- return undefined;
272
- }
273
-
274
- function resolveCliNamespace(opts: CliOptionBag | undefined): string | undefined {
275
- const userId = opts?.userId?.trim();
276
- const sessionKey = opts?.sessionKey?.trim();
277
- if (!userId && !sessionKey) {
278
- return undefined;
279
- }
280
- return resolveDurableNamespace({ userId, sessionKey });
281
- }
282
-
283
- type CliRegistrar = {
284
- registerCli?(
285
- builder: (ctx: { program: CliProgram }) => void,
286
- opts?: {
287
- commands?: string[];
288
- descriptors?: Array<{
289
- name: string;
290
- description: string;
291
- hasSubcommands: boolean;
292
- }>;
293
- },
294
- ): void;
295
- };
296
-
297
- declare module "openclaw/plugin-sdk/plugin-entry" {
298
- interface OpenClawPluginApi extends CliRegistrar {}
299
- }
@@ -1,128 +0,0 @@
1
- export const COMPARISON_ABLATION_MODES = [
2
- "reserve_bump",
3
- "protected_pair_pack",
4
- "discriminative_affiliation",
5
- "witness_position_pastness",
6
- "contamination_penalty",
7
- "pair_score_on_witness",
8
- "comparison_blend",
9
- ] as const;
10
-
11
- export type ComparisonAblationMode = typeof COMPARISON_ABLATION_MODES[number];
12
-
13
- export interface ComparisonProfileSummary {
14
- ablationMode?: ComparisonAblationMode;
15
- rankTotalMs: number;
16
- decorateMs: number;
17
- slotCoverageMs: number;
18
- sideAffiliationMs: number;
19
- specificityMs: number;
20
- pairSelectionMs: number;
21
- greedyFillMs: number;
22
- recoveryPackingMs: number;
23
- debugBuildMs: number;
24
- rawCandidateCount: number;
25
- comparisonCandidateCount: number;
26
- side0AffiliatedCount: number;
27
- side1AffiliatedCount: number;
28
- normalizeTermsCalls: number;
29
- normalizeContentTermsCalls: number;
30
- estimateTokensCalls: number;
31
- sortCalls: number;
32
- totalSortedLength: number;
33
- }
34
-
35
- export interface ComparisonExperimentConfig {
36
- profilingEnabled: boolean;
37
- ablationMode: ComparisonAblationMode | null;
38
- disableReserveBump: boolean;
39
- disableProtectedPairPack: boolean;
40
- disableDiscriminativeAffiliation: boolean;
41
- disableWitnessPositionPastness: boolean;
42
- disableContaminationPenalty: boolean;
43
- disablePairScoreOnWitness: boolean;
44
- disableComparisonBlend: boolean;
45
- }
46
-
47
- export function resolveComparisonExperimentConfig(
48
- env: NodeJS.ProcessEnv = process.env,
49
- ): ComparisonExperimentConfig {
50
- const profilingEnabled = env.LONGMEMEVAL_PROFILE_COMPARISON === "1";
51
- const rawMode = env.LONGMEMEVAL_COMPARISON_PROFILE_MODE?.trim() ?? "";
52
- const ablationMode = COMPARISON_ABLATION_MODES.includes(rawMode as ComparisonAblationMode)
53
- ? rawMode as ComparisonAblationMode
54
- : null;
55
- return {
56
- profilingEnabled,
57
- ablationMode,
58
- disableReserveBump: ablationMode === "reserve_bump",
59
- disableProtectedPairPack: ablationMode === "protected_pair_pack",
60
- disableDiscriminativeAffiliation: ablationMode === "discriminative_affiliation",
61
- disableWitnessPositionPastness: ablationMode === "witness_position_pastness",
62
- disableContaminationPenalty: ablationMode === "contamination_penalty",
63
- disablePairScoreOnWitness: ablationMode === "pair_score_on_witness",
64
- disableComparisonBlend: ablationMode === "comparison_blend",
65
- };
66
- }
67
-
68
- export function createComparisonProfileSummary(
69
- ablationMode: ComparisonAblationMode | null,
70
- ): ComparisonProfileSummary {
71
- return {
72
- ablationMode: ablationMode ?? undefined,
73
- rankTotalMs: 0,
74
- decorateMs: 0,
75
- slotCoverageMs: 0,
76
- sideAffiliationMs: 0,
77
- specificityMs: 0,
78
- pairSelectionMs: 0,
79
- greedyFillMs: 0,
80
- recoveryPackingMs: 0,
81
- debugBuildMs: 0,
82
- rawCandidateCount: 0,
83
- comparisonCandidateCount: 0,
84
- side0AffiliatedCount: 0,
85
- side1AffiliatedCount: 0,
86
- normalizeTermsCalls: 0,
87
- normalizeContentTermsCalls: 0,
88
- estimateTokensCalls: 0,
89
- sortCalls: 0,
90
- totalSortedLength: 0,
91
- };
92
- }
93
-
94
- export function mergeComparisonProfileSummaries(
95
- profiles: ComparisonProfileSummary[],
96
- ): ComparisonProfileSummary | null {
97
- if (profiles.length === 0) {
98
- return null;
99
- }
100
-
101
- const merged = createComparisonProfileSummary(
102
- profiles.every((profile) => profile.ablationMode === profiles[0]!.ablationMode)
103
- ? (profiles[0]!.ablationMode ?? null)
104
- : null,
105
- );
106
- for (const profile of profiles) {
107
- merged.rankTotalMs += profile.rankTotalMs;
108
- merged.decorateMs += profile.decorateMs;
109
- merged.slotCoverageMs += profile.slotCoverageMs;
110
- merged.sideAffiliationMs += profile.sideAffiliationMs;
111
- merged.specificityMs += profile.specificityMs;
112
- merged.pairSelectionMs += profile.pairSelectionMs;
113
- merged.greedyFillMs += profile.greedyFillMs;
114
- merged.recoveryPackingMs += profile.recoveryPackingMs;
115
- merged.debugBuildMs += profile.debugBuildMs;
116
- merged.rawCandidateCount += profile.rawCandidateCount;
117
- merged.comparisonCandidateCount += profile.comparisonCandidateCount;
118
- merged.side0AffiliatedCount += profile.side0AffiliatedCount;
119
- merged.side1AffiliatedCount += profile.side1AffiliatedCount;
120
- merged.normalizeTermsCalls += profile.normalizeTermsCalls;
121
- merged.normalizeContentTermsCalls += profile.normalizeContentTermsCalls;
122
- merged.estimateTokensCalls += profile.estimateTokensCalls;
123
- merged.sortCalls += profile.sortCalls;
124
- merged.totalSortedLength += profile.totalSortedLength;
125
- }
126
-
127
- return merged;
128
- }