Skip to content

Feat/opencode systemd integration#135

Closed
linuxdevel wants to merge 9 commits intorohitg00:mainfrom
linuxdevel:feat/opencode-systemd-integration
Closed

Feat/opencode systemd integration#135
linuxdevel wants to merge 9 commits intorohitg00:mainfrom
linuxdevel:feat/opencode-systemd-integration

Conversation

@linuxdevel
Copy link
Copy Markdown

@linuxdevel linuxdevel commented Apr 13, 2026

This pull request introduces major improvements to OpenCode and Claude integrations with agentmemory, enhances health monitoring, and adds planning documentation for upcoming dashboard and circuit breaker work. The most significant changes include new agentmemory integration plugins and hooks for OpenCode and Claude, improved health memory reporting, and detailed plans for reducing dashboard flicker and improving circuit breaker accuracy.

Agentmemory Integration for OpenCode and Claude:

  • Added a comprehensive OpenCode plugin (integrations/opencode/plugin.js) that connects to the agentmemory backend, handling session lifecycle, context enrichment, and tool usage observation for memory-aware actions.
  • Introduced new shell hooks for Claude (integrations/claude-code/hooks/agentmemory-pretool.sh, agentmemory-posttool.sh, agentmemory-prompt.sh) to call agentmemory REST APIs for tool context enrichment, observation, and session context injection. [1] [2] [3]
  • Added OpenCode skill instructions (integrations/opencode/instructions-agentmemory-skills.md) describing when to use explicit agentmemory skills versus plugin-driven recall/capture.
  • Updated the OpenCode installer documentation and logic to automate plugin and skill deployment, and to merge configuration safely. [1] [2]

Health Monitoring Enhancements:

  • Improved memory health reporting by including Node.js heap size limit (heapLimit) in the health snapshot and using it for more accurate memory usage thresholds. [1] [2] [3] [4]

Dashboard and Circuit Breaker Planning:

  • Added detailed design and implementation plans for making the dashboard live updates flicker-free and improving circuit breaker accuracy, including test-driven development steps and manual verification instructions. [1] [2]

Documentation and Usability:

  • Expanded the README.md to clarify OpenCode agentmemory installation steps and configuration merging, ensuring users understand the deployment and update process.

Agentmemory Integration:

  • Implemented a robust OpenCode plugin for agentmemory session, context, and tool observation (integrations/opencode/plugin.js).
  • Added Claude shell hooks for pre-tool, post-tool, and prompt events to integrate with agentmemory REST API (integrations/claude-code/hooks/agentmemory-pretool.sh, agentmemory-posttool.sh, agentmemory-prompt.sh). [1] [2] [3]
  • Created OpenCode instructions for explicit memory skills use (integrations/opencode/instructions-agentmemory-skills.md).
  • Automated OpenCode plugin/skill deployment and config merging, with helper utilities (src/integrations/opencode-installer.js).

Health Monitoring:

  • Enhanced health snapshot to report heap size limit and use it for memory threshold calculation (src/health/monitor.ts, src/health/thresholds.ts). [1] [2] [3] [4]

Planning and Documentation:

  • Added design and implementation plans for flicker-free dashboard updates and more accurate circuit breaker state (docs/plans/2026-04-13-dashboard-live-updates-and-circuit-breaker-design.md, docs/plans/2026-04-13-dashboard-live-updates-and-circuit-breaker-plan.md). [1] [2]
  • Clarified OpenCode agentmemory installer usage and configuration in README.md.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added automated installer script for streamlined deployment and configuration
    • Integrated AgentMemory with Claude Code through new integration hooks
    • Added OpenCode plugin for automatic context enrichment and memory capture
    • Introduced explicit memory operation skills (remember, recall, forget, session-history)
    • Enhanced dashboard rendering with incremental updates to reduce flickering
    • Added graph-building capability to API
  • Bug Fixes

    • Improved circuit breaker state tracking and failure window management
    • Enhanced memory utilization monitoring with heap limit awareness
  • Documentation

    • Updated setup instructions with new installer-based configuration workflow
    • Added design documentation for dashboard and system improvements

OpenCode was still using standalone JSON storage, so its MCP traffic and automatic context hooks did not share state with the systemd agentmemory service.

Route stdio MCP through the deployed REST endpoints and ship the OpenCode plugin plus installer so local deployments point both paths at the same backend.
Install script now deploys Claude Code hooks (prompt/pretool/posttool)
and merges MCP + hook entries into ~/.claude/settings.json, matching
the OpenCode plugin's REST-based observe/context/enrich pattern against
the systemd-managed backend at 127.0.0.1:3111.
Install script now copies plugin/ (with 4 skills: remember, recall,
forget, session-history) into Claude Code's plugin cache, registers it
in installed_plugins.json, and enables it in settings.json. Idempotent.
OpenCode setup only enabled the plugin and MCP bridge, so explicit memory actions were not available as native skills and the generated config assumed one user's Node path.

Install namespaced agentmemory skills plus an instruction file during setup, and keep the generated OpenCode config portable across local installs.
The OpenCode skill installer change should not carry docs/plans files on this feature branch.

Remove the plan documents and the ignore rule that was only added to support them.
Viewer UI calls graph/build to populate knowledge graph from existing
memories, but no handler existed. Adds endpoint that batches all stored
memories through graph extraction to seed the graph on first load.
- messages.transform hook now falls back to cached activeSessionId
  since opencode doesn't pass sessionID in the hook input
- Added process exit handler to call /session/end on SIGINT/SIGTERM,
  which triggers server-side auto-crystallization
The installer now adds a Stop hook that calls session-end.mjs,
which triggers /session/end → auto-crystallization pipeline.
Avoid full dashboard redraws and use heap limits so live health stays accurate after refreshes and restarts.

Limit half-open breaker probes and expire stale failures so provider errors do not inflate dashboard failure state.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 37f809a0-d69d-4bc2-9ef9-0d677feedaec

📥 Commits

Reviewing files that changed from the base of the PR and between 3935aec and 616b5dc.

📒 Files selected for processing (26)
  • README.md
  • docs/plans/2026-04-13-dashboard-live-updates-and-circuit-breaker-design.md
  • docs/plans/2026-04-13-dashboard-live-updates-and-circuit-breaker-plan.md
  • install-agentmemory.sh
  • integrations/claude-code/hooks/agentmemory-posttool.sh
  • integrations/claude-code/hooks/agentmemory-pretool.sh
  • integrations/claude-code/hooks/agentmemory-prompt.sh
  • integrations/opencode/instructions-agentmemory-skills.md
  • integrations/opencode/plugin.js
  • src/health/monitor.ts
  • src/health/thresholds.ts
  • src/integrations/opencode-installer.js
  • src/mcp/rest-client.ts
  • src/mcp/standalone.ts
  • src/providers/circuit-breaker.ts
  • src/triggers/api.ts
  • src/types.ts
  • src/viewer/document.ts
  • src/viewer/index.html
  • test/circuit-breaker.test.ts
  • test/health-thresholds.test.ts
  • test/mcp-standalone.test.ts
  • test/opencode-installer.test.ts
  • test/opencode-plugin.test.ts
  • test/viewer-document.test.ts
  • test/viewer-security.test.ts

📝 Walkthrough

Walkthrough

This pull request introduces comprehensive AgentMemory integration infrastructure: a Bash installer (install-agentmemory.sh) for deploying the service and configuring integrations, OpenCode and Claude Code hook plugins that connect external tools to AgentMemory via REST APIs, MCP infrastructure updates to proxy tool and resource operations, circuit-breaker improvements for accurate state tracking, and refactored dashboard rendering for incremental updates instead of full DOM replacement.

Changes

Cohort / File(s) Summary
Installer & Deployment
install-agentmemory.sh, README.md
New 553-line Bash installer automates building AgentMemory, deploying runtime artifacts to /opt/agentmemory, and configuring OpenCode/Claude Code integrations. README updated to document the install flow with Node binary paths, root vs non-root modes, and systemd service setup.
OpenCode Integration
integrations/opencode/plugin.js, integrations/opencode/instructions-agentmemory-skills.md, src/integrations/opencode-installer.js
New OpenCode plugin (254 lines) manages session lifecycle, injects context, enriches tool operations, and observes tool outcomes via REST calls to AgentMemory. Installer module provides skill spec building, frontmatter rewriting, and config merging. Instructions document defines user-facing memory operation skills.
Claude Code Hooks
integrations/claude-code/hooks/agentmemory-*.sh
Three new Bash hook scripts (pre-tool, post-tool, prompt) POST enrichment and observation data to AgentMemory for session tracking and context injection during Claude Code tool execution.
MCP Infrastructure
src/mcp/rest-client.ts, src/mcp/standalone.ts
New REST client module centralizes HTTP operations (timeout, auth, error handling) for AgentMemory service. Standalone MCP bridge refactored to proxy tools/list, tools/call, and new resources/prompts methods to REST endpoints instead of local execution.
Health & Monitoring
src/health/monitor.ts, src/health/thresholds.ts, src/types.ts
Extended HealthSnapshot.memory with optional heapLimit field; health evaluation now uses heap limit when available instead of solely heap total for memory percentage calculations.
Circuit Breaker
src/providers/circuit-breaker.ts
Added failure expiry logic via expireFailures(now) to clear stale failures after the configured window elapses; introduced halfOpenProbeInFlight to enforce single-probe semantics during half-open state.
Dashboard Rendering
src/viewer/index.html, src/viewer/document.ts
Refactored dashboard rendering from monolithic DOM replacement to incremental patching: ensureDashboardShell() creates fixed containers once, setDashboardSection() updates individual sections, and syncDashboard() with scheduled refresh (debounced 250ms) replaces immediate reloads from websocket/timer events. Template lookup order adjusted to prioritize deployed template.
API Enhancements
src/triggers/api.ts
New api::graph-build HTTP trigger (POST /agentmemory/graph/build) loads memories from KV, batches them via getGraphBatchSize(), and calls mem::graph-extract per batch, accumulating and returning node/edge counts.
Planning & Design Docs
docs/plans/2026-04-13-dashboard-*.md
Two new planning documents: one outlines dashboard live-update architecture (stable DOM, in-place patching) and circuit-breaker state semantics (expiring stale failures, counting end-to-end failures); the other details implementation tasks, verification steps, and handoff criteria.
Test Coverage
test/*.test.ts
Added/expanded test suites for circuit-breaker half-open probing and failure expiry, health threshold evaluation with heap limits, MCP standalone REST proxying and error handling, OpenCode plugin hook execution and session/context management, OpenCode installer config merging and skill spec building, and viewer template selection and dashboard markup.

Sequence Diagram(s)

sequenceDiagram
    participant OpenCode as OpenCode Client
    participant Plugin as AgentMemory Plugin
    participant Service as AgentMemory Service
    participant KV as Session/Memory Store

    Note over OpenCode,KV: Session Initialization
    OpenCode->>Plugin: Chat started, system.transform hook
    Plugin->>Service: POST /agentmemory/session/start<br/>{sessionId, project, cwd}
    Service->>KV: Create/retrieve session
    Service-->>Plugin: {context: "..."}
    Plugin->>OpenCode: Inject context into system prompt

    Note over OpenCode,KV: Message Processing
    OpenCode->>Plugin: User sends message, messages.transform hook
    Plugin->>Service: POST /agentmemory/context<br/>{sessionId, project, cwd, budget, prompt}
    Service->>KV: Query relevant memories
    Service-->>Plugin: {context: "..."}
    Plugin->>OpenCode: Prepend context to user message

    Note over OpenCode,KV: Tool Execution
    OpenCode->>Plugin: Tool.execute.before: Read/Edit/Grep
    Plugin->>Service: POST /agentmemory/enrich<br/>{sessionId, files, terms, toolName}
    Service->>KV: Analyze file/term context
    Service-->>Plugin: {enhancedContext: "..."}

    OpenCode->>OpenCode: Execute tool with context
    
    OpenCode->>Plugin: Tool.execute.after with result
    Plugin->>Service: POST /agentmemory/observe<br/>{hookType, sessionId, tool_input, tool_output}
    Service->>KV: Store observation, update graphs

    Note over OpenCode,KV: Session Cleanup
    OpenCode->>Plugin: Process exit/SIGINT/SIGTERM
    Plugin->>Service: POST /agentmemory/session/end<br/>{sessionId}
    Service->>KV: Finalize session, persist summaries
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through circuits true,
Sessions bloom, and context flows through—
Dashboards patch, not fully rebuild,
Failures age, their windows refilled,
OpenCode springs to life anew! 🌱

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@linuxdevel linuxdevel closed this Apr 13, 2026
@yogeek
Copy link
Copy Markdown

yogeek commented Apr 15, 2026

@linuxdevel why is it closed please ?
I was interested in having a more native opencode integration (hooks instead of simple MCP)

@linuxdevel
Copy link
Copy Markdown
Author

@yogeek I closed it because the PR was meant for my local fork. Sorry. My fork also has alot of other changes..

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.

2 participants