Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions internal/setup/assets/openclaw/hooks/mnemon-prime/handler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { readFileSync } from "fs";
import { existsSync, readFileSync } from "fs";
import { homedir } from "os";
import { join } from "path";
import { execSync } from "child_process";

const GUIDE_PATH = join(homedir(), ".mnemon", "prompt", "guide.md");
const LEGACY_GUIDE_PATH = join(homedir(), ".mnemon", "prompt", "guide.md");

function guidePath() {
const dataRoot = process.env.MNEMON_DATA_DIR || join(homedir(), ".mnemon");
const scopedPath = join(dataRoot, "prompt", "guide.md");
if (!existsSync(scopedPath) && existsSync(LEGACY_GUIDE_PATH)) {
return LEGACY_GUIDE_PATH;
}
return scopedPath;
}

const handler = async (event) => {
if (event.type !== "agent" || event.action !== "bootstrap") return;
Expand All @@ -30,7 +39,7 @@ const handler = async (event) => {

// Inject behavioral guide
try {
const guide = readFileSync(GUIDE_PATH, "utf-8");
const guide = readFileSync(guidePath(), "utf-8");
if (guide) parts.push(guide);
} catch {
// guide.md not found — skill-only mode, no guide injection
Expand Down
4 changes: 2 additions & 2 deletions internal/setup/claude.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type HookSelection struct {
}

// promptDir returns the directory where mnemon prompt files (guide.md,
// skill.md) are written and read. Resolution follows the same convention as
// the --data-dir flag: MNEMON_DATA_DIR env var if set, else ~/.mnemon.
// skill.md) are written and read. Resolution follows MNEMON_DATA_DIR if set,
// else ~/.mnemon.
func promptDir() (string, error) {
if env := os.Getenv("MNEMON_DATA_DIR"); env != "" {
return filepath.Join(env, "prompt"), nil
Expand Down
17 changes: 17 additions & 0 deletions internal/setup/openclaw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"github.com/mnemon-dev/mnemon/internal/setup/assets"
)

func TestOpenClawRegisterPluginWritesSelection(t *testing.T) {
Expand Down Expand Up @@ -89,3 +92,17 @@ func TestRemoveOpenClawPluginEntryRemovesEmptyConfig(t *testing.T) {
t.Fatalf("expected empty config file removal, got err=%v", err)
}
}

func TestOpenClawPrimeHookResolvesMnemonDataDir(t *testing.T) {
handler := string(assets.OpenClawHookHandler)
for _, want := range []string{
"process.env.MNEMON_DATA_DIR",
"LEGACY_GUIDE_PATH",
"existsSync(scopedPath)",
"readFileSync(guidePath()",
} {
if !strings.Contains(handler, want) {
t.Fatalf("OpenClaw prime hook missing %q", want)
}
}
}
Loading