Skip to content

Commit 0f90bbe

Browse files
committed
sample-services: split reset scripts between matcher and laptop hosts
1 parent a0fdefa commit 0f90bbe

3 files changed

Lines changed: 140 additions & 52 deletions

File tree

packages/agentmask/openclaw-plugin-discovery/VALIDATION.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
This document walks through end-to-end validation of the discovery
44
plugin against a running Phase 1 provider (MetaMask extension) and a
5-
Phase 2 matcher (daemon on VPS). Everything lives on a single VPS.
5+
Phase 2 matcher (daemon on VPS). The deployment is split across two
6+
hosts: matcher infrastructure on a VPS, and the MetaMask extension
7+
plus its sample-services daemon on the laptop.
68

79
## Topology
810

@@ -15,10 +17,6 @@ Phase 2 matcher (daemon on VPS). Everything lives on a single VPS.
1517
│ (subcluster running the matcher vat, │
1618
│ plus the llm-bridge process) │
1719
│ │
18-
│ sample-services daemon — OCAP_HOME=~/.ocap-services│
19-
│ (one subcluster per non-MetaMask service: │
20-
│ Echo, RandomNumber) │
21-
│ │
2220
│ consumer daemon — OCAP_HOME=~/.ocap-consumer │
2321
│ (no subclusters; hosts the openclaw plugin's │
2422
│ RPC target) │
@@ -28,19 +26,26 @@ Phase 2 matcher (daemon on VPS). Everything lives on a single VPS.
2826
└─────────────────────────────────────────────────────┘
2927
│ relay hints
3028
31-
Browser on laptop
32-
MetaMask extension with the PersonalMessageSigner
33-
provider vat, registered against the matcher
29+
Laptop
30+
┌─────────────────────────────────────────────────────┐
31+
│ MetaMask extension │
32+
│ with the PersonalMessageSigner provider vat, │
33+
│ registered against the matcher │
34+
│ │
35+
│ sample-services daemon — OCAP_HOME=~/.ocap-services│
36+
│ (one subcluster per non-MetaMask service: │
37+
│ Echo, RandomNumber) │
38+
└─────────────────────────────────────────────────────┘
3439
```
3540

36-
Three daemons live on the same VPS with different home directories
37-
so they don't clobber each other's state. The matcher uses the
38-
default `~/.ocap`; sample-services uses `~/.ocap-services`; the
39-
consumer uses `~/.ocap-consumer`. Every `ocap` invocation that wants
40-
a non-default daemon passes `--home <dir>`; invocations without
41-
`--home` hit the matcher. All three talk to each other (and to the
42-
browser-side PMS provider) over the relay, same as they would across
43-
machines — the shared VPS is purely for convenience during dev.
41+
The VPS hosts the matcher and consumer daemons in separate home
42+
directories so they don't clobber each other's state: the matcher uses
43+
the default `~/.ocap`, the consumer uses `~/.ocap-consumer`. Every
44+
`ocap` invocation that wants a non-default daemon passes
45+
`--home <dir>`; invocations without `--home` hit the matcher. The
46+
sample-services daemon lives on the laptop alongside the MetaMask
47+
extension and uses `~/.ocap-services`. All daemons (and the
48+
browser-side PMS provider) talk to each other over the relay.
4449

4550
## Prerequisites
4651

@@ -81,14 +86,19 @@ Four things must be live before starting this validation:
8186
`/v1/chat/completions` endpoint. That adds two requirements,
8287
described in the next two subsections.
8388

84-
3. **Sample-services daemon** on the VPS, started via
89+
3. **Sample-services daemon** on the laptop (the same machine as the
90+
MetaMask extension), started via
8591
`packages/sample-services/scripts/start-services.sh <matcher-url>`
8692
(or with `MATCHER_OCAP_URL` exported in the shell). It launches
8793
one subcluster per service: Echo and RandomNumber. Each
8894
subcluster's bootstrap registers with the matcher using the URL
89-
threaded through its vat parameters, so the matcher daemon log
90-
should grow two `[matcher] registered svc:N:` lines once this
91-
starts.
95+
threaded through its vat parameters, so the matcher daemon log on
96+
the VPS should grow two `[matcher] registered svc:N:` lines once
97+
this starts.
98+
99+
For the laptop-side reset-and-restart cycle (stop services, clear
100+
log, re-launch pointed at the current matcher URL), use
101+
`packages/sample-services/scripts/reset-services.sh <matcher-url>`.
92102
93103
4. **Provider extension** — MetaMask loaded in a browser with the
94104
matcher URL baked in via `.metamaskrc`
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
# Reset the laptop-side sample-services daemon for a fresh test cycle:
3+
#
4+
# - stop the sample-services daemon (~/.ocap-services);
5+
# - clear its log;
6+
# - bring it back up via start-services.sh, registering Echo and
7+
# RandomNumber with the supplied matcher URL.
8+
#
9+
# The matcher (which runs on the VPS) is reset separately by
10+
# reset-everything.sh on that side.
11+
#
12+
# The matcher OCAP URL is required and is resolved in this order:
13+
# 1. <matcher-url> (positional argument)
14+
# 2. $MATCHER_OCAP_URL (environment variable)
15+
#
16+
# Prereqs: the relay must already be reachable from this host
17+
# (`yarn ocap relay` locally, or a remote relay specified via
18+
# --relay / $OCAP_RELAY_MULTIADDR).
19+
#
20+
# Usage:
21+
# reset-services.sh [<matcher-url>] [--no-build]
22+
#
23+
# <matcher-url> OCAP URL of the matcher to register with. Falls back
24+
# to $MATCHER_OCAP_URL if omitted.
25+
# --no-build Skip building/bundling the sample-services vats
26+
# (passed through to start-services.sh).
27+
28+
set -euo pipefail
29+
30+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
31+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
32+
START_SERVICES_SCRIPT="$SCRIPT_DIR/start-services.sh"
33+
OCAP_BIN="$REPO_ROOT/packages/kernel-cli/dist/app.mjs"
34+
SERVICES_HOME="${OCAP_SERVICES_HOME:-${HOME}/.ocap-services}"
35+
36+
PASSTHROUGH_ARGS=()
37+
MATCHER_URL_ARG=""
38+
while [[ $# -gt 0 ]]; do
39+
case "$1" in
40+
--no-build)
41+
PASSTHROUGH_ARGS+=(--no-build); shift ;;
42+
--help|-h)
43+
sed -n '2,/^$/p' "$0" >&2; exit 0 ;;
44+
--*)
45+
echo "Error: unknown argument: $1" >&2; exit 1 ;;
46+
*)
47+
if [[ -z "$MATCHER_URL_ARG" ]]; then
48+
MATCHER_URL_ARG="$1"; shift
49+
else
50+
echo "Error: unexpected positional argument: $1" >&2; exit 1
51+
fi
52+
;;
53+
esac
54+
done
55+
56+
info() { echo "[reset-services] $*" >&2; }
57+
58+
MATCHER_URL="${MATCHER_URL_ARG:-${MATCHER_OCAP_URL:-}}"
59+
if [[ -z "$MATCHER_URL" ]]; then
60+
echo "[reset-services] ERROR: matcher URL required (pass as first argument or set \$MATCHER_OCAP_URL)." >&2
61+
exit 1
62+
fi
63+
64+
if [[ ! -f "$OCAP_BIN" ]]; then
65+
echo "[reset-services] ERROR: ocap CLI not found at $OCAP_BIN." >&2
66+
echo " Run 'yarn workspace @metamask/kernel-cli build' first." >&2
67+
exit 1
68+
fi
69+
70+
# ---------------------------------------------------------------------------
71+
# 1. Stop the services daemon.
72+
# ---------------------------------------------------------------------------
73+
74+
info "Stopping sample-services daemon (if running)..."
75+
node "$OCAP_BIN" --home "$SERVICES_HOME" daemon stop >/dev/null 2>&1 || true
76+
77+
# ---------------------------------------------------------------------------
78+
# 2. Clear the daemon log.
79+
# ---------------------------------------------------------------------------
80+
81+
info "Clearing daemon log..."
82+
rm -f "$SERVICES_HOME/daemon.log"
83+
84+
# ---------------------------------------------------------------------------
85+
# 3. Bring the services daemon back up.
86+
# ---------------------------------------------------------------------------
87+
88+
info "Starting sample-services daemon..."
89+
"$START_SERVICES_SCRIPT" "$MATCHER_URL" "${PASSTHROUGH_ARGS[@]}" >&2
90+
91+
cat <<EOF >&2
92+
93+
================================================================
94+
SERVICES RESET COMPLETE.
95+
96+
Echo and RandomNumber have re-registered with:
97+
$MATCHER_URL
98+
================================================================
99+
EOF

packages/service-matcher/scripts/reset-everything.sh

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
#!/usr/bin/env bash
22
# Reset everything VPS-side for a fresh test cycle:
33
#
4-
# - stop the matcher (~/.ocap), sample-services (~/.ocap-services),
5-
# and consumer (~/.ocap-consumer) daemons, plus the matcher's
6-
# llm-bridge subprocess; sweep up any orphan daemon-entry / bridge
7-
# processes;
8-
# - purge consumer + sample-services state and clear daemon logs in
9-
# all three homes (the matcher's state is purged by
10-
# start-matcher.sh as a side effect of its default behavior);
4+
# - stop both daemons (matcher under ~/.ocap, consumer under
5+
# ~/.ocap-consumer) and sweep up any orphan daemon-entry processes;
6+
# - purge consumer state and clear daemon logs in both homes
7+
# (the matcher's state is purged by start-matcher.sh as a side
8+
# effect of its default behavior);
119
# - bring the matcher back up via start-matcher.sh, capturing the
1210
# newly-issued OCAP URL on stdout;
13-
# - bring the sample-services daemon back up via start-services.sh,
14-
# pointed at that URL, so Echo and RandomNumber register;
1511
# - bring the consumer daemon back up with --local-relay;
1612
# - update the openclaw discovery plugin's matcherUrl config and
1713
# restart the gateway so the new URL takes effect.
@@ -25,28 +21,25 @@
2521
# Usage:
2622
# reset-everything.sh [--no-build]
2723
#
28-
# --no-build Skip building/bundling the matcher vat and the sample
29-
# services (passed through to start-matcher.sh and
30-
# start-services.sh).
24+
# --no-build Skip building/bundling the matcher vat (passed through
25+
# to start-matcher.sh).
3126

3227
set -euo pipefail
3328

3429
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
3530
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
36-
START_SERVICES_SCRIPT="$REPO_ROOT/packages/sample-services/scripts/start-services.sh"
3731
OCAP_BIN="$REPO_ROOT/packages/kernel-cli/dist/app.mjs"
3832
CONSUMER_HOME="${OCAP_CONSUMER_HOME:-${HOME}/.ocap-consumer}"
39-
SERVICES_HOME="${OCAP_SERVICES_HOME:-${HOME}/.ocap-services}"
4033
MATCHER_HOME="${HOME}/.ocap"
4134
LLM_BRIDGE_PID_PATH="$MATCHER_HOME/matcher-llm-bridge.pid"
4235
LLM_BRIDGE_LOG_PATH="$MATCHER_HOME/matcher-llm-bridge.log"
4336
LLM_SOCKET_PATH="$MATCHER_HOME/matcher-llm.sock"
4437

45-
PASSTHROUGH_ARGS=()
38+
START_MATCHER_ARGS=()
4639
while [[ $# -gt 0 ]]; do
4740
case "$1" in
4841
--no-build)
49-
PASSTHROUGH_ARGS+=(--no-build); shift ;;
42+
START_MATCHER_ARGS+=(--no-build); shift ;;
5043
--help|-h)
5144
sed -n '2,/^$/p' "$0" >&2; exit 0 ;;
5245
*)
@@ -69,9 +62,6 @@ fi
6962
info "Stopping consumer daemon (if running)..."
7063
node "$OCAP_BIN" --home "$CONSUMER_HOME" daemon stop >/dev/null 2>&1 || true
7164

72-
info "Stopping sample-services daemon (if running)..."
73-
node "$OCAP_BIN" --home "$SERVICES_HOME" daemon stop >/dev/null 2>&1 || true
74-
7565
info "Stopping matcher daemon (if running)..."
7666
node "$OCAP_BIN" --home "$MATCHER_HOME" daemon stop >/dev/null 2>&1 || true
7767

@@ -114,37 +104,26 @@ fi
114104
info "Purging consumer daemon state..."
115105
node "$OCAP_BIN" --home "$CONSUMER_HOME" daemon purge --force >/dev/null 2>&1 || true
116106

117-
info "Purging sample-services daemon state..."
118-
node "$OCAP_BIN" --home "$SERVICES_HOME" daemon purge --force >/dev/null 2>&1 || true
119-
120107
info "Clearing daemon and bridge logs..."
121108
rm -f \
122109
"$MATCHER_HOME/daemon.log" \
123110
"$CONSUMER_HOME/daemon.log" \
124-
"$SERVICES_HOME/daemon.log" \
125111
"$LLM_BRIDGE_LOG_PATH"
126112

127113
# ---------------------------------------------------------------------------
128114
# 6. Bring the matcher back up; capture the URL on stdout.
129115
# ---------------------------------------------------------------------------
130116

131117
info "Starting matcher..."
132-
MATCHER_URL="$("$SCRIPT_DIR/start-matcher.sh" "${PASSTHROUGH_ARGS[@]}")"
118+
MATCHER_URL="$("$SCRIPT_DIR/start-matcher.sh" "${START_MATCHER_ARGS[@]}")"
133119
if [[ -z "$MATCHER_URL" ]]; then
134120
echo "[reset] ERROR: start-matcher.sh produced no URL." >&2
135121
exit 1
136122
fi
137123
info "Matcher URL: $MATCHER_URL"
138124

139125
# ---------------------------------------------------------------------------
140-
# 7. Bring the sample-services daemon back up, pointed at the matcher.
141-
# ---------------------------------------------------------------------------
142-
143-
info "Starting sample-services daemon..."
144-
"$START_SERVICES_SCRIPT" "$MATCHER_URL" "${PASSTHROUGH_ARGS[@]}" >&2
145-
146-
# ---------------------------------------------------------------------------
147-
# 8. Bring the consumer daemon back up.
126+
# 7. Bring the consumer daemon back up.
148127
# ---------------------------------------------------------------------------
149128

150129
info "Starting consumer daemon (--local-relay)..."

0 commit comments

Comments
 (0)