Skip to content

Commit f005b75

Browse files
Grivnclaude
andcommitted
Refine OpenClaw plugin: version patching, config schema, always-on skill load
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0018ae0 commit f005b75

6 files changed

Lines changed: 72 additions & 44 deletions

File tree

cmd/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func installOpenClaw(env *setup.Environment) error {
335335
fmt.Println("\n[4/4] Plugin")
336336
sel := selectOpenClawOptionalHooks()
337337

338-
if path, err := setup.OpenClawWritePlugin(configDir); err != nil {
338+
if path, err := setup.OpenClawWritePlugin(configDir, version); err != nil {
339339
setup.StatusError(0, 0, "Plugin", err)
340340
} else {
341341
setup.StatusOK(0, 0, "Plugin", path)

internal/setup/assets/assets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var OpenClawHookHandler []byte
3232
//go:embed openclaw/plugin/package.json
3333
var OpenClawPluginPackage []byte
3434

35-
//go:embed openclaw/plugin/openclaw-plugin.json
35+
//go:embed openclaw/plugin/openclaw.plugin.json
3636
var OpenClawPluginManifest []byte
3737

3838
//go:embed openclaw/plugin/index.js

internal/setup/assets/openclaw/plugin/index.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,30 @@ export default function register(api) {
2525
}
2626

2727
// ── before_prompt_build ───────────────────────────────────────
28-
// Injects reminders only — the LLM decides whether to recall/remember.
29-
// No direct mnemon execution here (CLI-in-the-loop: LLM drives the CLI).
30-
if (remind || nudge || compact) {
31-
api.on("before_prompt_build", async () => {
32-
const parts = [];
33-
34-
// Compact flag: was compaction triggered since last turn?
35-
if (compact && existsSync(COMPACT_FLAG)) {
36-
try { unlinkSync(COMPACT_FLAG); } catch { /* ignore */ }
37-
parts.push(
38-
"[mnemon] Context compaction starting. Review this session and remember the most valuable insights (up to 5) before context is compressed. Delegate to Task sub-agents now."
39-
);
40-
}
41-
42-
if (remind) {
43-
parts.push(
44-
"[mnemon] Evaluate: recall needed? After responding, evaluate: remember needed?"
45-
);
46-
}
47-
48-
if (nudge) {
49-
parts.push(
50-
"[mnemon] Consider: does this exchange warrant a remember sub-agent?"
51-
);
52-
}
53-
54-
if (parts.length === 0) return;
55-
return { prependContext: parts.join("\n\n") };
56-
});
57-
}
28+
// Always load the mnemon skill; optionally inject remind/nudge/compact hints.
29+
api.on("before_prompt_build", async () => {
30+
const parts = ["[mnemon] load mnemon skill"];
31+
32+
// Compact flag: was compaction triggered since last turn?
33+
if (compact && existsSync(COMPACT_FLAG)) {
34+
try { unlinkSync(COMPACT_FLAG); } catch { /* ignore */ }
35+
parts.push(
36+
"[mnemon] Context compaction starting. Review this session and remember the most valuable insights (up to 5) before context is compressed. Delegate to Task sub-agents now."
37+
);
38+
}
39+
40+
if (remind) {
41+
parts.push(
42+
"[mnemon] Evaluate: recall needed? After responding, evaluate: remember needed?"
43+
);
44+
}
45+
46+
if (nudge) {
47+
parts.push(
48+
"[mnemon] Consider: does this exchange warrant a remember sub-agent?"
49+
);
50+
}
51+
52+
return { prependContext: parts.join("\n\n") };
53+
});
5854
}

internal/setup/assets/openclaw/plugin/openclaw-plugin.json

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": "mnemon",
3+
"name": "mnemon",
4+
"version": "",
5+
"description": "LLM-supervised persistent memory — recall before responding, remember after",
6+
"hooks": [
7+
"before_prompt_build",
8+
"agent_end"
9+
],
10+
"entry": "index.js",
11+
"configSchema": {
12+
"type": "object",
13+
"additionalProperties": false,
14+
"properties": {
15+
"compact": {
16+
"type": "boolean"
17+
},
18+
"nudge": {
19+
"type": "boolean"
20+
},
21+
"remind": {
22+
"type": "boolean"
23+
}
24+
}
25+
}
26+
}

internal/setup/openclaw.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,33 @@ func OpenClawWriteHook(configDir string) (string, error) {
3939
}
4040

4141
// OpenClawWritePlugin writes the mnemon plugin to the OpenClaw extensions directory.
42-
func OpenClawWritePlugin(configDir string) (string, error) {
42+
// ver is the mnemon version string (e.g. from ldflags); it replaces the
43+
// embedded manifest's static version field so the installed plugin always
44+
// reflects the running binary.
45+
func OpenClawWritePlugin(configDir, ver string) (string, error) {
4346
pluginDir := filepath.Join(configDir, "extensions", "mnemon")
4447
if err := os.MkdirAll(pluginDir, 0755); err != nil {
4548
return "", err
4649
}
50+
51+
// Patch manifest version when a real version is available.
52+
manifest := assets.OpenClawPluginManifest
53+
if ver != "" && ver != "dev" {
54+
var m map[string]any
55+
if err := json.Unmarshal(manifest, &m); err == nil {
56+
m["version"] = ver
57+
if patched, err := json.MarshalIndent(m, "", " "); err == nil {
58+
manifest = append(patched, '\n')
59+
}
60+
}
61+
}
62+
4763
files := []struct {
4864
name string
4965
data []byte
5066
}{
5167
{"package.json", assets.OpenClawPluginPackage},
52-
{"openclaw-plugin.json", assets.OpenClawPluginManifest},
68+
{"openclaw.plugin.json", manifest},
5369
{"index.js", assets.OpenClawPluginIndex},
5470
}
5571
for _, f := range files {

0 commit comments

Comments
 (0)