Skip to content

feat: openclaw-embedded plugin — aligned with official plugin guide#26

Open
yilu331 wants to merge 78 commits intomainfrom
feat/openclaw-embedded-plugin
Open

feat: openclaw-embedded plugin — aligned with official plugin guide#26
yilu331 wants to merge 78 commits intomainfrom
feat/openclaw-embedded-plugin

Conversation

@yilu331
Copy link
Copy Markdown
Collaborator

@yilu331 yilu331 commented Apr 16, 2026

Summary

New self-contained Reflexio integration plugin at integrations/openclaw-embedded/. Delivers user profile and playbook capabilities entirely within Openclaw's native primitives (hooks, sub-agents, memory, heartbeat) with no Reflexio server dependency.

The plugin follows the official Openclaw plugin building guide — skills declared in manifest, config via api.pluginConfig, tools registered via api.registerTool(), and sub-agents injected via extraSystemPrompt.

Architecture

plugin/                          # Installed to ~/.openclaw/extensions/reflexio-embedded/
├── index.ts                     # Entry: hooks + 7 registered tools
├── openclaw.plugin.json         # Manifest with skills declaration
├── skills/                      # Auto-served via manifest
│   ├── reflexio-embedded/       # Main skill (profile/playbook detection)
│   └── reflexio-consolidate/    # On-demand consolidation
├── hook/
│   ├── handler.ts               # TTL sweep, extractor spawn, bootstrap reminder
│   └── setup.ts                 # HEARTBEAT.md append on first load
├── lib/                         # Deterministic control flow
│   ├── write-profile.ts         # validate → preprocess → search → judge → write → delete
│   ├── write-playbook.ts        # Same flow for playbooks
│   ├── dedup.ts                 # Query preprocessing + contradiction judgment via LLM
│   ├── search.ts                # Memory search with preprocessing
│   ├── io.ts                    # Atomic file I/O (nanoid, frontmatter, TTL)
│   └── openclaw-cli.ts          # CommandRunner type + openclaw CLI wrappers
├── agents/                      # Sub-agent definitions (injected via extraSystemPrompt)
├── prompts/                     # Prompt templates (read from extension dir at runtime)
└── HEARTBEAT.md                 # Structured heartbeat task for consolidation check

Registered Tools

Tool Purpose
reflexio_write_profile Write profile with dedup + contradiction detection
reflexio_write_playbook Write playbook with dedup
reflexio_search Preprocessed memory search
reflexio_consolidation_check Heartbeat: returns OK or ALERT
reflexio_consolidation_mark_done Mark consolidation complete
reflexio_run_consolidation Spawn consolidator sub-agent

Key Design Decisions

  • Skills in manifest"skills": ["./skills"] enables auto-discovery and auto-cleanup on uninstall
  • No workspace file copying — everything served from extension dir; openclaw plugins uninstall cleans up completely
  • api.pluginConfig — users override config via openclaw.json, not by editing plugin files
  • before_prompt_build — uses recommended hook (not deprecated before_agent_start) for prompt injection
  • Heartbeat over cron — consolidation triggered by heartbeat check (adaptive, no cron registration needed)
  • extraSystemPrompt injection — sub-agent definitions loaded from extension dir at runtime, no workspace/agents/ copy
  • allowImportingTsExtensions.ts import extensions (not .js) since plugin ships as TypeScript with noEmit
  • CommandRunner DIapi.runtime.system.runCommandWithTimeout injected; tests use mock runner

Testing

  • 47 vitest tests (io, dedup, search, write-profile, write-playbook)
  • Hook smoke test
  • Manual test plan in TESTING.md

Test Plan

  • npm test — 47 tests pass
  • bash scripts/install.sh — plugin installs, skills auto-available
  • openclaw plugins uninstall reflexio-embedded — zero orphaned files
  • Flow A: in-session profile capture works
  • Flow B: in-session playbook capture works
  • Flow C: session-end batch extraction works
  • Heartbeat consolidation check returns OK/ALERT correctly

yilu331 added 30 commits April 16, 2026 16:32
…leanup trap

- Normalize --supersedes spacing via [[:space:]]*,[[:space:]]* so pre-spaced
  inputs like 'prof_a, prof_b' no longer produce '[prof_a,  prof_b]' (double
  space). Split 'local' from assignment so subshell failures are not masked.
- Add EXIT trap in write_profile and write_playbook to clean up the .tmp.$$
  scratch file if the script aborts after tmp creation but before 'mv' (e.g.
  disk full, EINTR, failed rename). The trap is cleared after a successful
  mv so it does not fire on the subsequent successful exit. RETURN trap does
  not fire under 'set -e' when a command aborts the shell, so EXIT is used.
- Add bats test that simulates 'mv' failure via a PATH-overridden stub and
  asserts no .tmp.* files remain after the failed run.
@yilu331 yilu331 changed the title feat: openclaw-embedded plugin feat: openclaw-embedded plugin with reflexio.ts CLI Apr 18, 2026
yilu331 added 21 commits April 17, 2026 19:22
…ng await/runner in CLI

- Pass workspace from resolveAgentWorkspaceDir to writeProfile/writePlaybook
  tool handlers so writes target the correct agent workspace instead of /
- Add WORKSPACE env fallback in deleteTarget resolution for both write-profile
  and write-playbook
- Make standalone CLI async with proper await on all async function calls
- Add CommandRunner implementation via child_process execSync for CLI context
- Pass runner to all three CLI commands (writeProfile, writePlaybook, search)
- Fix search() call to pass all 4 required args
… not SDK's resolveAgentWorkspaceDir which needs agentId we don't have
… guide alignment

- Move plugin runtime + workspace resources into plugin/ subdirectory
- Declare skills in openclaw.plugin.json manifest (auto-served from extension dir)
- Use api.pluginConfig instead of reading config.json from disk
- Use before_prompt_build hook (replaces deprecated before_agent_start for prompts)
- Add extraSystemPrompt injection for sub-agents (no workspace/agents copy needed)
- Add reflexio_run_consolidation tool to spawn consolidator from extension dir
- Replace cron job with heartbeat-based consolidation check
- Add compat/build sections to package.json for ClawHub publishing
- Move dev files (tests, types, vitest config) outside plugin/
- Simplify install.sh and uninstall.sh (no manual workspace file copying)
@yilu331 yilu331 changed the title feat: openclaw-embedded plugin with reflexio.ts CLI feat: openclaw-embedded plugin — aligned with official plugin guide Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant