Skip to content

Commit 27498f9

Browse files
authored
fix: openclaw improve config setup (#258)
1 parent 1530c09 commit 27498f9

4 files changed

Lines changed: 71 additions & 7 deletions

File tree

hindsight-embed/hindsight_embed/daemon_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _find_hindsight_api_command() -> list[str]:
4141
# Fall back to uvx for installed version
4242
# Allow version override via environment variable (defaults to matching embed version)
4343
from . import __version__
44+
4445
api_version = os.getenv("HINDSIGHT_EMBED_API_VERSION", __version__)
4546
return ["uvx", f"hindsight-api@{api_version}"]
4647

hindsight-integrations/openclaw/install.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
set -e
33

4-
echo "🚀 Installing Hindsight Memory Plugin for Moltbot..."
4+
echo "🚀 Installing Hindsight Memory Plugin for OpenClaw..."
55

66
# Get the directory where this script is located
77
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8-
INSTALL_DIR="$HOME/.clawdbot/extensions/hindsight-openclaw"
8+
INSTALL_DIR="$HOME/.openclaw/extensions/hindsight-openclaw"
99

1010
# Check Node version
1111
if ! command -v node &> /dev/null; then
@@ -25,7 +25,7 @@ rm -rf "$INSTALL_DIR"
2525
mkdir -p "$INSTALL_DIR"
2626

2727
# Copy files
28-
cp -r dist package.json clawdbot.plugin.json README.md "$INSTALL_DIR/"
28+
cp -r dist package.json openclaw.plugin.json README.md "$INSTALL_DIR/"
2929

3030
# Install dependencies in deployed location
3131
echo "📥 Installing dependencies..."
@@ -41,9 +41,9 @@ echo "1. Make sure you have an OpenAI API key set:"
4141
echo " export OPENAI_API_KEY=\"sk-your-key-here\""
4242
echo ""
4343
echo "2. Enable the plugin:"
44-
echo " clawdbot plugins enable hindsight-openclaw"
44+
echo " openclaw plugins enable hindsight-openclaw"
4545
echo ""
4646
echo "3. Start OpenClaw:"
47-
echo " clawdbot start"
47+
echo " openclaw gateway"
4848
echo ""
4949
echo "On first start, uvx will automatically download hindsight-embed (no manual install needed)"

hindsight-integrations/openclaw/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hindsight-integrations/openclaw/src/embed-manager.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class HindsightEmbedManager {
4848
env['HINDSIGHT_EMBED_LLM_MODEL'] = this.llmModel;
4949
}
5050

51+
// Write env vars to ~/.hindsight/config.env for daemon persistence
52+
await this.writeConfigEnv(env);
53+
5154
// Start hindsight-embed daemon (it manages itself)
5255
const embedPackage = this.embedVersion ? `hindsight-embed@${this.embedVersion}` : 'hindsight-embed@latest';
5356
const startDaemon = spawn(
@@ -145,4 +148,64 @@ export class HindsightEmbedManager {
145148
isRunning(): boolean {
146149
return this.process !== null;
147150
}
151+
152+
private async writeConfigEnv(env: NodeJS.ProcessEnv): Promise<void> {
153+
const hindsightDir = join(homedir(), '.hindsight');
154+
const embedConfigPath = join(hindsightDir, 'embed');
155+
156+
// Ensure directory exists
157+
await fs.mkdir(hindsightDir, { recursive: true });
158+
159+
// Read existing config to preserve extra settings
160+
let existingContent = '';
161+
let extraSettings: string[] = [];
162+
try {
163+
existingContent = await fs.readFile(embedConfigPath, 'utf-8');
164+
// Extract non-LLM settings (like FORCE_CPU flags)
165+
const lines = existingContent.split('\n');
166+
for (const line of lines) {
167+
const trimmed = line.trim();
168+
if (trimmed && !trimmed.startsWith('#') &&
169+
!trimmed.startsWith('HINDSIGHT_EMBED_LLM_') &&
170+
!trimmed.startsWith('HINDSIGHT_EMBED_BANK_ID') &&
171+
!trimmed.startsWith('HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT')) {
172+
extraSettings.push(line);
173+
}
174+
}
175+
} catch {
176+
// File doesn't exist yet, that's fine
177+
}
178+
179+
// Build config file with header
180+
const configLines: string[] = [
181+
'# Hindsight Embed Configuration',
182+
'# Generated by OpenClaw Hindsight plugin',
183+
'',
184+
];
185+
186+
// Add LLM config
187+
if (env.HINDSIGHT_EMBED_LLM_PROVIDER) {
188+
configLines.push(`HINDSIGHT_EMBED_LLM_PROVIDER=${env.HINDSIGHT_EMBED_LLM_PROVIDER}`);
189+
}
190+
if (env.HINDSIGHT_EMBED_LLM_MODEL) {
191+
configLines.push(`HINDSIGHT_EMBED_LLM_MODEL=${env.HINDSIGHT_EMBED_LLM_MODEL}`);
192+
}
193+
if (env.HINDSIGHT_EMBED_LLM_API_KEY) {
194+
configLines.push(`HINDSIGHT_EMBED_LLM_API_KEY=${env.HINDSIGHT_EMBED_LLM_API_KEY}`);
195+
}
196+
if (env.HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT) {
197+
configLines.push(`HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT=${env.HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT}`);
198+
}
199+
200+
// Add extra settings if they exist
201+
if (extraSettings.length > 0) {
202+
configLines.push('');
203+
configLines.push('# Additional settings');
204+
configLines.push(...extraSettings);
205+
}
206+
207+
// Write to file
208+
await fs.writeFile(embedConfigPath, configLines.join('\n') + '\n', 'utf-8');
209+
console.log(`[Hindsight] Wrote config to ${embedConfigPath}`);
210+
}
148211
}

0 commit comments

Comments
 (0)