Huawei Cloud Agent Integration (OpenViking Long-Term Memory)
Overview
Integrate and unbind OpenViking long-term memory with coding agents. Most agents run in bwrap sandboxes under /root/job-envs/sandboxes/ and use their native mechanism — MCP (mcp__openviking__* tools) or the HTTP memory provider — so the integration survives agent upgrades and matches how each agent natively consumes memory.
Integration writes are template-level persistent for sandbox agents: config is injected into the agent's start.sh / config templates under /root/template/<agent>/, so a sandbox stop + start (which re-runs start.sh) preserves the integration.
What Good Looks Like
scripts/status.sh reports all 8 agents as ✓ (template + live).
scripts/verify_mcp.sh passes the full MCP handshake (initialize → tools/list → health) against http://127.0.0.1:1933/mcp.
- Restarting a sandbox does not lose the integration (template-level persistence, not live-only).
- Agents surface OpenViking tools natively:
mcp__openviking__* for MCP-based agents, dual-channel (MCP + native viking_*) for JiuwenSwarm.
- Unbinding removes every trace: template blocks, live config, skills/AGENTS.md, config backups, and openviking keys in settings.json.
- User authorization (
confirm) is required for every mutation — nothing changes silently.
Supported Agents
| Agent |
Native mechanism |
Persistence |
| CodeArts CLI |
MCP in .codeartsdoer/codearts_cli.json + 4-section prompt (aligned with official openviking-memory skill semantics) |
Template start.sh + live sandbox |
| OpenCode |
Official @openviking/opencode-plugin (installed on demand: npm domestic mirror first, on-demand GitHub raw mirror fallback; deployed from $RUNTIME/opencode/openviking-plugin/; @opencode-ai/plugin SDK via npm) + official openviking-config.json fields |
Template start.sh (on-demand plugin install) |
| OpenClaw |
Official clawhub:@openviking/openclaw-plugin + openviking setup --json contract (domestic npm mirror fallback → on-demand source build fallback) + contextEngine slot |
Template start.sh |
| Hermes |
Official built-in memory provider (memory.provider: openviking, no MCP SDK) |
Template start.sh + live sandbox |
| JiuwenSwarm |
Dual-channel: native memory provider (memory.engine: both + memory.external.provider: openviking, HTTP REST) + MCP server (streamable-http, 13 tools incl. search/recall/find) + auto_memory_enabled: true |
Template start.sh + live config.yaml |
| KimiCode |
MCP via mcp.json |
Template start.sh + live mcp.json |
| DeepSeek Harness (dsh) |
Official @openviking/dsh-memory-plugin bundle (installed on demand from volcengine/OpenViking via the domestic GitHub raw mirror list; self-contained peers + ESM-safe peer dep sync) installed into web/dsh-tui profile node_modules + dsh.profile.bundles |
Template start.sh |
| Prime Agent |
Official @openviking/pi-coding-agent-extension (installed on demand from volcengine/OpenViking via the domestic GitHub raw mirror list, incl. tests/) |
Template start.sh + live extensions dir |
Per-agent config files, injection blocks, and recall quotas: references/agent-configs.md.
Prerequisites
- OpenViking server running and accessible (default
http://127.0.0.1:1933):curl -s http://127.0.0.1:1933/health
# {"status":"ok","healthy":true,"version":"0.4.x","auth_mode":"dev"}
- Agent sandboxes exist under
/root/job-envs/sandboxes/ (managed by job-env-manager).
- Host tools:
curl, python3, bash. OpenCode/OpenClaw additionally need npm (domestic-first registry configured by the skill).
- This skill operates on local bwrap sandboxes and the local hwcloud config only — no Huawei Cloud IAM policies required (see references/iam-policies.md).
参数确认 (Required Inputs)
| Parameter |
Required |
Description |
Example |
--agent <name> |
Yes (unless --all) |
Target agent: codearts, opencode, openclaw, hermes, jiuwenswarm, kimicode, deepseek-harness, prime-agent |
--agent opencode |
--all |
Yes (unless --agent) |
Operate on all 8 agents |
--all |
--endpoint <url> |
No |
OpenViking server URL (default http://127.0.0.1:1933) |
--endpoint http://192.168.1.100:1933 |
--api-key <key> |
No |
OpenViking API key (dev mode needs none). Never echo in chat or logs |
--api-key sk-xxx |
--dry-run |
No |
Show changes without applying them |
--dry-run |
--yes / -y |
No |
Skip authorization prompt (automation only) |
--yes |
--json |
No |
status.sh: machine-readable output |
--json |
Dependencies
- OpenViking server ≥ 0.4.x on
127.0.0.1:1933 (MCP endpoint /mcp, streamable HTTP).
- npm (domestic-first registries:
mirrors.huaweicloud.com/repository/npm/ → registry.npmmirror.com → registry.npmjs.org) for OpenCode @opencode-ai/plugin SDK + @openviking/opencode-plugin, and OpenClaw plugin installs (ClawHub primary, npm mirrors as fallback, on-demand source build as third fallback).
- No MCP SDK needed for Hermes — Hermes has a built-in OpenViking memory provider over HTTP REST (official
05-hermes.md).
- openclaw CLI inside sandbox for
openclaw openviking setup/status (official JSON contract).
- dsh CLI (
/root/runtime/deepseek-harness/bin/dsh) for DeepSeek Harness, plus the official @openviking/dsh-memory-plugin bundle installed on demand from volcengine/OpenViking (domestic GitHub raw mirror list first; self-contained peer deps for @deepseek-ai/dsh-llm/dsh-tools plus all transitive @deepseek-ai/* packages synced as ESM-safe real copies (not symlinks — Node.js v22 ESM resolver does not follow symlinks for bare specifier imports)) — installed into web/dsh-tui profile node_modules + dsh.profile.bundles, no pnpm needed.
- API script conventions are Bash +
curl + python3 only.
Plugin Sources (on-demand, domestic-first)
The skill ships no plugin code — industry convention is to install dependent plugins at
integrate time from the ecosystem registry. Every integrate.sh run provisions the plugins
it needs on demand (see scripts/common.sh):
- npm-published plugins (
@openviking/opencode-plugin, @openviking/openclaw-plugin)
are installed via npm install using the domestic-first registry list
(mirrors.huaweicloud.com/repository/npm/ → registry.npmmirror.com →
registry.npmjs.org); the first reachable registry wins.
- GitHub-only plugins (
@openviking/dsh-memory-plugin,
@openviking/pi-coding-agent-extension — not yet on npm) are fetched from the official
volcengine/OpenViking repo through the domestic-first raw mirror list
(ghfast.top → gh-proxy.com → raw.githubusercontent.com), with the GitHub API used
only for commit/tree metadata (domestic proxies 403 on the API).
- Source check is retained — every downloaded file is verified byte-for-byte against
the authoritative GitHub blob SHA from the official tree, so content is only accepted
if it matches upstream regardless of which mirror served the bytes.
- Changed-files-only download — the GitHub tree API is used to diff the previously
installed commit vs upstream; only changed/new files are downloaded
(with retry/backoff). If nothing under the plugin dir changed, only the recorded
.openviking-sync commit is bumped — no download.
- Offline resilience — installed copies live under
/root/runtime/ (outside the
skill). If upstream is unreachable, the existing installed copy is reused as-is (warn),
so integration never breaks on network hiccups.
- Fallthrough for OpenCode/OpenClaw — plugin runtime installs sit at
/root/runtime/opencode/openviking-plugin and /root/runtime/openclaw/openviking-plugin-source
respectively, giving each agent npm first → on-demand runtime copy semantics.
- Cache-first on sandbox restart (stop+start / undeploy+deploy) — template
start.sh blocks use a 3-tier cache strategy to avoid re-downloading plugins on
every boot:
- Tier 1 (already installed): Plugin already in sandbox
node_modules → skip
entirely (survives stop+start). Logs cache hit.
- Tier 2 (runtime cache): Copy from
/root/runtime/<agent>/... persistent
cache → no network call (survives undeploy+deploy, since /root/runtime/ is
outside the sandbox lifecycle).
- Tier 3 (online fallback):
npm install / ClawHub → only on first integrate
or cache miss. Logs Cache miss.
- DeepSeek Harness peer deps: The 193-package
@deepseek-ai/* sync loop is
guarded by a .openviking-peers-synced marker file — if present, the entire
copy loop is skipped. Marker is written after first sync completes.
- Prime Agent: Already optimized via
diff -q check (no change needed).
核心命令
| 功能 |
命令 |
| 查看集成状态 |
scripts/status.sh(--json 机器可读,--agent <name> 指定 Agent) |
| 验证 MCP 端点 |
scripts/verify_mcp.sh |
| 集成单个 Agent |
scripts/integrate.sh --agent <name> [--endpoint URL] [--api-key KEY] [--dry-run] [--yes] |
| 集成全部 Agent |
scripts/integrate.sh --all |
| 解绑单个 Agent |
scripts/unbind.sh --agent <name> [--dry-run] [--yes] |
| 解绑全部 Agent |
scripts/unbind.sh --all |
Workflow
Task 1: Check Integration Status
SKILL_DIR=/root/.agents/skills/huawei-cloud-openviking-agent-integration
$SKILL_DIR/scripts/status.sh # human-readable
$SKILL_DIR/scripts/status.sh --json # machine-readable
Status values per agent:
template + live — fully integrated and active
template only — will activate on next restart
live only — will be lost on restart (needs template fix)
Task 2: Verify MCP Endpoint
$SKILL_DIR/scripts/verify_mcp.sh
Performs the full MCP protocol handshake (initialize → notifications/initialized → tools/list → tools/call health) and lists the OpenViking tools (find, search, recall, read, list, remember, add_resource, …).
Task 3: Integrate a Single Agent
$SKILL_DIR/scripts/integrate.sh --agent opencode # interactive (asks for confirmation)
$SKILL_DIR/scripts/integrate.sh --agent opencode --endpoint URL --api-key KEY
$SKILL_DIR/scripts/integrate.sh --agent opencode --dry-run # preview only
$SKILL_DIR/scripts/integrate.sh --agent opencode --yes # automation only
Task 4: Integrate All Agents
$SKILL_DIR/scripts/integrate.sh --all
Task 5: Unbind a Single Agent
$SKILL_DIR/scripts/unbind.sh --agent opencode
$SKILL_DIR/scripts/unbind.sh --agent opencode --dry-run
$SKILL_DIR/scripts/unbind.sh --agent opencode --yes
Task 6: Unbind All Agents
$SKILL_DIR/scripts/unbind.sh --all
Task 7: Rebuild OpenClaw Sandbox (Apply Template Changes)
OpenClaw's gateway runs in an ephemeral bwrap; stop + start re-runs start.sh, which reinstalls the plugin and applies endpoint config. Do:
curl -s -X POST $BASE/envs/openclaw/stop (poll until stopped)
curl -s -X POST $BASE/envs/openclaw/start (poll until running)
- Verify:
scripts/integrate.sh --agent openclaw --dry-run reports endpoint configured
Full restart/rebuild scripts (including the stop → delete → create → deploy fallback) and live-config verification from outside bwrap: references/related-commands.md.
Authorization Model
Both integrate.sh and unbind.sh require explicit user confirmation before modifying any agent configuration:
━━━ Authorization Required ━━━
Action: Integrate OpenViking MCP
Agent: opencode
Details: Add OpenViking MCP to OpenCode template start.sh (persistent across restarts)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Type 'confirm' to proceed:
- The user must type exactly
confirm; any other input aborts.
--yes / -y skips the prompt (for automation only).
--dry-run shows what would happen without requiring authorization.
- Never integrate or unbind without explicit user confirmation — see references/guardrails.md for the full rules.
Safety Rules
- Authorization is mandatory — never integrate or unbind without explicit user confirmation.
- Do not fabricate integration state — always run
status.sh to verify before reporting.
- Never edit agent configs directly on the host — all changes go through the skill scripts.
- No API keys in logs —
--api-key values must never appear in output or logs.
- Dry-run first for unfamiliar targets.
- Slow responses are not an integration bug — check model API TTFB before blaming MCP (see references/troubleshooting.md).
Validation Rules
Quick verification after any integration or unbinding:
$SKILL_DIR/scripts/status.sh # all agents green
$SKILL_DIR/scripts/verify_mcp.sh # MCP handshake passes
Acceptance criteria for each workflow (integrate/unbind per agent): references/acceptance-criteria.md.
Step-by-step verification methods: references/verification-method.md.
References
| Document |
Description |
| agent-configs.md |
Per-agent config files, injection blocks, persistence patterns, recall quotas, MCP tools |
| guardrails.md |
Safety and authorization rules |
| troubleshooting.md |
Common failure scenarios, slow-response diagnostics (model TTFB vs network vs MCP), and fixed unbind cleanup issues |
| iam-policies.md |
Equivalent access controls (no Huawei Cloud IAM needed) |
| verification-method.md |
Step-by-step verification for each workflow |
| related-commands.md |
Restart/rebuild scripts, inspection commands, live-config verification |
| acceptance-criteria.md |
Acceptance criteria for integration/unbinding |
| demo/example-input.json |
Example input for the integration workflow |
Scripts (OO Architecture)
The scripts use an object-oriented design with a base class, registry pattern,
and per-agent subclasses. Adding a new agent = create one file in agents/.
scripts/
lib/ ── Framework (shared infrastructure)
ui.sh Logging, authorization, dry-run, i18n
json.sh JSON read/write/has/remove helpers
plugins.sh Plugin provisioning (npm + GitHub, SHA-1 verified)
base.sh Agent base class: sandbox discovery, backup, confirm,
template injection, health check, default interface
registry.sh Agent registry: auto-discover, list, validate, dispatch
agents/ ── Agent subclasses (one file per agent)
codearts.sh CodeArts CLI — MCP in codearts_cli.json
opencode.sh OpenCode — plugin + openviking-config.json
openclaw.sh OpenClaw — ClawHub plugin + contextEngine
hermes.sh Hermes — built-in memory provider
jiuwenswarm.sh JiuwenSwarm — dual-channel (provider + MCP)
kimicode.sh KimiCode — MCP via mcp.json
deepseek_harness.sh DeepSeek Harness — dsh-memory-plugin bundle
prime_agent.sh Prime Agent — pi-coding-agent-extension
integrate.sh Thin entry point → registry dispatch (80 lines, was 1919)
unbind.sh Thin entry point → registry dispatch (74 lines, was 1084)
status.sh Thin entry point → registry dispatch (122 lines, was 345)
unset.sh Alias for unbind.sh
verify_mcp.sh MCP protocol handshake (unchanged)
common.sh Backward-compat shim → sources lib/*.sh
OO Design
- Base class (
lib/base.sh): defines agent::discover_sandbox, agent::backup_config,
agent::confirm, agent::has_injection, check_ov_health, create_ov_config, and
default interface stubs (agent::default_integrate/unbind/status).
- Agent metadata via associative array
AGENT_META[name, sandbox_pattern, template_path, mechanism, ...],
populated by each subclass's agent_<name>_register().
- Registry (
lib/registry.sh): registry_discover() auto-sources all agents/*.sh,
registry_dispatch(agent, method) calls agent_<name>_<method>() with fallback to base.
- Subclass override: each
agents/<name>.sh defines agent_<name>_integrate/unbind/status,
calling base class methods for shared operations (backup, confirm, sandbox lookup).
- Entry points (integrate/unbind/status.sh): parse CLI args → discover agents → dispatch.
No agent-specific logic in entry points — all in subclasses.
All scripts are idempotent and create .bak.<timestamp> backups before each modification.
1---
2name: huawei-cloud-openviking-agent-integration
3description: |
4 Integrate and unbind OpenViking long-term memory with coding agents. Supports 8 agents (CodeArts CLI, OpenCode, OpenClaw, Hermes, JiuwenSwarm, KimiCode, DeepSeek Harness, Prime Agent) via their native mechanism — MCP, HTTP memory provider, TypeScript extension hooks, or settings.json config. Both integration and unbinding require explicit user authorization.
5 Use this skill when the user wants to: (1) integrate OpenViking memory into a coding agent, (2) unbind OpenViking from a coding agent, (3) check the integration status of all agents, (4) verify the OpenViking MCP endpoint, (5) rebuild the OpenClaw sandbox to apply template changes.
6 Trigger words: "OpenViking integration", "agent memory binding", "MCP setup", "OpenViking MCP", "integrate OpenViking", "unbind OpenViking", "记忆集成", "记忆解绑", "OpenViking 集成", "OpenViking 解绑", "agent long-term memory", "context database".
7tags:
8 - openviking
9 - database
10 - agent
11metadata:
12 version: 1.2.0
13 license: MIT
14 category: devtools
15---
16
17# Huawei Cloud Agent Integration (OpenViking Long-Term Memory)
18
19## Overview
20
21Integrate and unbind OpenViking long-term memory with coding agents. Most agents run in bwrap sandboxes under `/root/job-envs/sandboxes/` and use their **native mechanism** — MCP (`mcp__openviking__*` tools) or the HTTP memory provider — so the integration survives agent upgrades and matches how each agent natively consumes memory.
22
23
24Integration writes are **template-level persistent** for sandbox agents: config is injected into the agent's `start.sh` / config templates under `/root/template/<agent>/`, so a sandbox `stop + start` (which re-runs `start.sh`) preserves the integration.
25
26
27## What Good Looks Like
28
29- `scripts/status.sh` reports all 8 agents as `✓` (template + live).
30- `scripts/verify_mcp.sh` passes the full MCP handshake (initialize → tools/list → health) against `http://127.0.0.1:1933/mcp`.
31- Restarting a sandbox does **not** lose the integration (template-level persistence, not live-only).
32- Agents surface OpenViking tools natively: `mcp__openviking__*` for MCP-based agents, dual-channel (MCP + native viking_*) for JiuwenSwarm.
33- Unbinding removes every trace: template blocks, live config, skills/AGENTS.md, config backups, and openviking keys in settings.json.
34- User authorization (`confirm`) is required for every mutation — nothing changes silently.
35
36## Supported Agents
37
38| Agent | Native mechanism | Persistence |
39|-------|------------------|-------------|
40| CodeArts CLI | MCP in `.codeartsdoer/codearts_cli.json` + 4-section prompt (aligned with official `openviking-memory` skill semantics) | Template start.sh + live sandbox |
41| OpenCode | Official `@openviking/opencode-plugin` (installed on demand: npm domestic mirror first, on-demand GitHub raw mirror fallback; deployed from `$RUNTIME/opencode/openviking-plugin/`; `@opencode-ai/plugin` SDK via npm) + official `openviking-config.json` fields | Template start.sh (on-demand plugin install) |
42| OpenClaw | Official `clawhub:@openviking/openclaw-plugin` + `openviking setup --json` contract (domestic npm mirror fallback → on-demand source build fallback) + `contextEngine` slot | Template start.sh |
43| Hermes | Official built-in memory provider (`memory.provider: openviking`, no MCP SDK) | Template start.sh + live sandbox |
44| JiuwenSwarm | Dual-channel: native memory provider (`memory.engine: both` + `memory.external.provider: openviking`, HTTP REST) **+ MCP server** (`streamable-http`, 13 tools incl. `search`/`recall`/`find`) + `auto_memory_enabled: true` | Template start.sh + live config.yaml |
45| KimiCode | MCP via `mcp.json` | Template start.sh + live mcp.json |
46| DeepSeek Harness (dsh) | Official `@openviking/dsh-memory-plugin` bundle (installed on demand from `volcengine/OpenViking` via the domestic GitHub raw mirror list; self-contained peers + ESM-safe peer dep sync) installed into `web`/`dsh-tui` profile node_modules + `dsh.profile.bundles` | Template start.sh |
47| Prime Agent | Official `@openviking/pi-coding-agent-extension` (installed on demand from `volcengine/OpenViking` via the domestic GitHub raw mirror list, incl. tests/) | Template start.sh + live extensions dir |
48
49Per-agent config files, injection blocks, and recall quotas: [references/agent-configs.md](references/agent-configs.md).
50
51## Prerequisites
52
53- OpenViking server running and accessible (default `http://127.0.0.1:1933`):
54 ```bash
55 curl -s http://127.0.0.1:1933/health
56 # {"status":"ok","healthy":true,"version":"0.4.x","auth_mode":"dev"}
57 ```
58- Agent sandboxes exist under `/root/job-envs/sandboxes/` (managed by job-env-manager).
59- Host tools: `curl`, `python3`, `bash`. OpenCode/OpenClaw additionally need `npm` (domestic-first registry configured by the skill).
60- This skill operates on local bwrap sandboxes and the local hwcloud config only — no Huawei Cloud IAM policies required (see [references/iam-policies.md](references/iam-policies.md)).
61
62## 参数确认 (Required Inputs)
63
64| Parameter | Required | Description | Example |
65|-----------|----------|-------------|---------|
66| `--agent <name>` | Yes (unless `--all`) | Target agent: `codearts`, `opencode`, `openclaw`, `hermes`, `jiuwenswarm`, `kimicode`, `deepseek-harness`, `prime-agent` | `--agent opencode` |
67| `--all` | Yes (unless `--agent`) | Operate on all 8 agents | `--all` |
68| `--endpoint <url>` | No | OpenViking server URL (default `http://127.0.0.1:1933`) | `--endpoint http://192.168.1.100:1933` |
69| `--api-key <key>` | No | OpenViking API key (dev mode needs none). Never echo in chat or logs | `--api-key sk-xxx` |
70| `--dry-run` | No | Show changes without applying them | `--dry-run` |
71| `--yes` / `-y` | No | Skip authorization prompt (automation only) | `--yes` |
72| `--json` | No | `status.sh`: machine-readable output | `--json` |
73
74## Dependencies
75
76- **OpenViking server** ≥ 0.4.x on `127.0.0.1:1933` (MCP endpoint `/mcp`, streamable HTTP).
77- **npm** (domestic-first registries: `mirrors.huaweicloud.com/repository/npm/` → `registry.npmmirror.com` → `registry.npmjs.org`) for OpenCode `@opencode-ai/plugin` SDK + `@openviking/opencode-plugin`, and OpenClaw plugin installs (ClawHub primary, npm mirrors as fallback, on-demand source build as third fallback).
78- **No MCP SDK needed for Hermes** — Hermes has a built-in OpenViking memory provider over HTTP REST (official `05-hermes.md`).
79- **openclaw CLI inside sandbox** for `openclaw openviking setup/status` (official JSON contract).
80- **dsh CLI** (`/root/runtime/deepseek-harness/bin/dsh`) for DeepSeek Harness, plus the official `@openviking/dsh-memory-plugin` bundle installed on demand from `volcengine/OpenViking` (domestic GitHub raw mirror list first; self-contained peer deps for `@deepseek-ai/dsh-llm`/`dsh-tools` plus all transitive `@deepseek-ai/*` packages synced as ESM-safe real copies (not symlinks — Node.js v22 ESM resolver does not follow symlinks for bare specifier imports)) — installed into `web`/`dsh-tui` profile `node_modules` + `dsh.profile.bundles`, no pnpm needed.
81- API script conventions are Bash + `curl` + `python3` only.
82
83## Plugin Sources (on-demand, domestic-first)
84
85The skill ships **no plugin code** — industry convention is to install dependent plugins at
86integrate time from the ecosystem registry. Every `integrate.sh` run provisions the plugins
87it needs on demand (see `scripts/common.sh`):
88
891. **npm-published plugins** (`@openviking/opencode-plugin`, `@openviking/openclaw-plugin`)
90 are installed via `npm install` using the **domestic-first registry list**
91 (`mirrors.huaweicloud.com/repository/npm/` → `registry.npmmirror.com` →
92 `registry.npmjs.org`); the first reachable registry wins.
932. **GitHub-only plugins** (`@openviking/dsh-memory-plugin`,
94 `@openviking/pi-coding-agent-extension` — not yet on npm) are fetched from the official
95 `volcengine/OpenViking` repo through the **domestic-first raw mirror list**
96 (`ghfast.top` → `gh-proxy.com` → `raw.githubusercontent.com`), with the GitHub API used
97 only for commit/tree metadata (domestic proxies 403 on the API).
983. **Source check is retained** — every downloaded file is verified **byte-for-byte against
99 the authoritative GitHub blob SHA** from the official tree, so content is only accepted
100 if it matches upstream regardless of which mirror served the bytes.
1014. **Changed-files-only download** — the GitHub tree API is used to diff the previously
102 installed commit vs upstream; only changed/new files are downloaded
103 (with retry/backoff). If nothing under the plugin dir changed, only the recorded
104 `.openviking-sync` commit is bumped — no download.
1055. **Offline resilience** — installed copies live under `/root/runtime/` (outside the
106 skill). If upstream is unreachable, the existing installed copy is reused as-is (warn),
107 so integration never breaks on network hiccups.
1086. **Fallthrough for OpenCode/OpenClaw** — plugin runtime installs sit at
109 `/root/runtime/opencode/openviking-plugin` and `/root/runtime/openclaw/openviking-plugin-source`
110 respectively, giving each agent `npm first → on-demand runtime copy` semantics.
1117. **Cache-first on sandbox restart** (stop+start / undeploy+deploy) — template
112 `start.sh` blocks use a 3-tier cache strategy to avoid re-downloading plugins on
113 every boot:
114 - **Tier 1 (already installed)**: Plugin already in sandbox `node_modules` → skip
115 entirely (survives stop+start). Logs `cache hit`.
116 - **Tier 2 (runtime cache)**: Copy from `/root/runtime/<agent>/...` persistent
117 cache → no network call (survives undeploy+deploy, since `/root/runtime/` is
118 outside the sandbox lifecycle).
119 - **Tier 3 (online fallback)**: `npm install` / ClawHub → only on first integrate
120 or cache miss. Logs `Cache miss`.
121 - **DeepSeek Harness peer deps**: The 193-package `@deepseek-ai/*` sync loop is
122 guarded by a `.openviking-peers-synced` marker file — if present, the entire
123 copy loop is skipped. Marker is written after first sync completes.
124 - **Prime Agent**: Already optimized via `diff -q` check (no change needed).
125
126## 核心命令
127
128| 功能 | 命令 |
129|------|------|
130| 查看集成状态 | `scripts/status.sh`(`--json` 机器可读,`--agent <name>` 指定 Agent) |
131| 验证 MCP 端点 | `scripts/verify_mcp.sh` |
132| 集成单个 Agent | `scripts/integrate.sh --agent <name> [--endpoint URL] [--api-key KEY] [--dry-run] [--yes]` |
133| 集成全部 Agent | `scripts/integrate.sh --all` |
134| 解绑单个 Agent | `scripts/unbind.sh --agent <name> [--dry-run] [--yes]` |
135| 解绑全部 Agent | `scripts/unbind.sh --all` |
136
137## Workflow
138
139### Task 1: Check Integration Status
140
141```bash
142SKILL_DIR=/root/.agents/skills/huawei-cloud-openviking-agent-integration
143$SKILL_DIR/scripts/status.sh # human-readable
144$SKILL_DIR/scripts/status.sh --json # machine-readable
145```
146
147Status values per agent:
148- `template + live` — fully integrated and active
149- `template only` — will activate on next restart
150- `live only` — will be **lost on restart** (needs template fix)
151
152### Task 2: Verify MCP Endpoint
153
154```bash
155$SKILL_DIR/scripts/verify_mcp.sh
156```
157
158Performs the full MCP protocol handshake (initialize → notifications/initialized → tools/list → tools/call health) and lists the OpenViking tools (find, search, recall, read, list, remember, add_resource, …).
159
160### Task 3: Integrate a Single Agent
161
162```bash
163$SKILL_DIR/scripts/integrate.sh --agent opencode # interactive (asks for confirmation)
164$SKILL_DIR/scripts/integrate.sh --agent opencode --endpoint URL --api-key KEY
165$SKILL_DIR/scripts/integrate.sh --agent opencode --dry-run # preview only
166$SKILL_DIR/scripts/integrate.sh --agent opencode --yes # automation only
167```
168
169### Task 4: Integrate All Agents
170
171```bash
172$SKILL_DIR/scripts/integrate.sh --all
173```
174
175### Task 5: Unbind a Single Agent
176
177```bash
178$SKILL_DIR/scripts/unbind.sh --agent opencode
179$SKILL_DIR/scripts/unbind.sh --agent opencode --dry-run
180$SKILL_DIR/scripts/unbind.sh --agent opencode --yes
181```
182
183### Task 6: Unbind All Agents
184
185```bash
186$SKILL_DIR/scripts/unbind.sh --all
187```
188
189### Task 7: Rebuild OpenClaw Sandbox (Apply Template Changes)
190
191OpenClaw's gateway runs in an ephemeral bwrap; `stop + start` re-runs `start.sh`, which reinstalls the plugin and applies endpoint config. Do:
192
1931. `curl -s -X POST $BASE/envs/openclaw/stop` (poll until `stopped`)
1942. `curl -s -X POST $BASE/envs/openclaw/start` (poll until `running`)
1953. Verify: `scripts/integrate.sh --agent openclaw --dry-run` reports endpoint configured
196
197Full restart/rebuild scripts (including the `stop → delete → create → deploy` fallback) and live-config verification from outside bwrap: [references/related-commands.md](references/related-commands.md).
198
199
200## Authorization Model
201
202Both `integrate.sh` and `unbind.sh` require explicit user confirmation before modifying any agent configuration:
203
204```
205━━━ Authorization Required ━━━
206 Action: Integrate OpenViking MCP
207 Agent: opencode
208 Details: Add OpenViking MCP to OpenCode template start.sh (persistent across restarts)
209━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
210
211Type 'confirm' to proceed:
212```
213
214- The user must type exactly `confirm`; any other input aborts.
215- `--yes` / `-y` skips the prompt (for automation only).
216- `--dry-run` shows what would happen without requiring authorization.
217- Never integrate or unbind without explicit user confirmation — see [references/guardrails.md](references/guardrails.md) for the full rules.
218
219## Safety Rules
220
221- **Authorization is mandatory** — never integrate or unbind without explicit user confirmation.
222- **Do not fabricate integration state** — always run `status.sh` to verify before reporting.
223- **Never edit agent configs directly on the host** — all changes go through the skill scripts.
224- **No API keys in logs** — `--api-key` values must never appear in output or logs.
225- **Dry-run first** for unfamiliar targets.
226- **Slow responses are not an integration bug** — check model API TTFB before blaming MCP (see [references/troubleshooting.md](references/troubleshooting.md)).
227
228## Validation Rules
229
230Quick verification after any integration or unbinding:
231
232```bash
233$SKILL_DIR/scripts/status.sh # all agents green
234$SKILL_DIR/scripts/verify_mcp.sh # MCP handshake passes
235```
236
237Acceptance criteria for each workflow (integrate/unbind per agent): [references/acceptance-criteria.md](references/acceptance-criteria.md).
238Step-by-step verification methods: [references/verification-method.md](references/verification-method.md).
239
240## References
241
242| Document | Description |
243|----------|-------------|
244| [agent-configs.md](references/agent-configs.md) | Per-agent config files, injection blocks, persistence patterns, recall quotas, MCP tools |
245| [guardrails.md](references/guardrails.md) | Safety and authorization rules |
246| [troubleshooting.md](references/troubleshooting.md) | Common failure scenarios, slow-response diagnostics (model TTFB vs network vs MCP), and fixed unbind cleanup issues |
247| [iam-policies.md](references/iam-policies.md) | Equivalent access controls (no Huawei Cloud IAM needed) |
248| [verification-method.md](references/verification-method.md) | Step-by-step verification for each workflow |
249| [related-commands.md](references/related-commands.md) | Restart/rebuild scripts, inspection commands, live-config verification |
250| [acceptance-criteria.md](references/acceptance-criteria.md) | Acceptance criteria for integration/unbinding |
251| [demo/example-input.json](demo/example-input.json) | Example input for the integration workflow |
252
253## Scripts (OO Architecture)
254
255The scripts use an **object-oriented design** with a base class, registry pattern,
256and per-agent subclasses. Adding a new agent = create one file in `agents/`.
257
258```
259scripts/
260 lib/ ── Framework (shared infrastructure)
261 ui.sh Logging, authorization, dry-run, i18n
262 json.sh JSON read/write/has/remove helpers
263 plugins.sh Plugin provisioning (npm + GitHub, SHA-1 verified)
264 base.sh Agent base class: sandbox discovery, backup, confirm,
265 template injection, health check, default interface
266 registry.sh Agent registry: auto-discover, list, validate, dispatch
267 agents/ ── Agent subclasses (one file per agent)
268 codearts.sh CodeArts CLI — MCP in codearts_cli.json
269 opencode.sh OpenCode — plugin + openviking-config.json
270 openclaw.sh OpenClaw — ClawHub plugin + contextEngine
271 hermes.sh Hermes — built-in memory provider
272 jiuwenswarm.sh JiuwenSwarm — dual-channel (provider + MCP)
273 kimicode.sh KimiCode — MCP via mcp.json
274 deepseek_harness.sh DeepSeek Harness — dsh-memory-plugin bundle
275 prime_agent.sh Prime Agent — pi-coding-agent-extension
276 integrate.sh Thin entry point → registry dispatch (80 lines, was 1919)
277 unbind.sh Thin entry point → registry dispatch (74 lines, was 1084)
278 status.sh Thin entry point → registry dispatch (122 lines, was 345)
279 unset.sh Alias for unbind.sh
280 verify_mcp.sh MCP protocol handshake (unchanged)
281 common.sh Backward-compat shim → sources lib/*.sh
282```
283
284### OO Design
285
286- **Base class** (`lib/base.sh`): defines `agent::discover_sandbox`, `agent::backup_config`,
287 `agent::confirm`, `agent::has_injection`, `check_ov_health`, `create_ov_config`, and
288 default interface stubs (`agent::default_integrate/unbind/status`).
289- **Agent metadata** via associative array `AGENT_META[name, sandbox_pattern, template_path, mechanism, ...]`,
290 populated by each subclass's `agent_<name>_register()`.
291- **Registry** (`lib/registry.sh`): `registry_discover()` auto-sources all `agents/*.sh`,
292 `registry_dispatch(agent, method)` calls `agent_<name>_<method>()` with fallback to base.
293- **Subclass override**: each `agents/<name>.sh` defines `agent_<name>_integrate/unbind/status`,
294 calling base class methods for shared operations (backup, confirm, sandbox lookup).
295- **Entry points** (integrate/unbind/status.sh): parse CLI args → discover agents → dispatch.
296 No agent-specific logic in entry points — all in subclasses.
297
298All scripts are idempotent and create `.bak.<timestamp>` backups before each modification.