Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
ci(plugins): validate, launcher tests, sandboxed e2e, release stamping (#1166)
AkitaOnRailse264d8e8eaaa
diff --git a/.github/workflows/plugins.yml b/.github/workflows/plugins.ymlnew file mode 100644index 00000000..062c1d1f--- /dev/null+++ b/.github/workflows/plugins.yml@@ -0,0 +1,132 @@+name: plugins++# The marketplace plugins (#1166): plugins/, the catalogs at the repository+# root, and everything they are generated from. The CLI suite in ci.yml+# already proves the committed tree equals `ai-memory render-plugins` and+# re-proves capture policy, scope routing and de-duplication through the+# launcher; this workflow adds what needs the real harness CLIs:+#+# * validate: `claude plugin validate --strict` on the catalog and the+# Claude Code plugin, with a pinned Claude Code CLI;+# * launcher: shellcheck and the POSIX launcher tests;+# * e2e: a credential-free `claude -p` that fires the plugin's hooks into a+# scratch ai-memory server, and a Codex install + trusted-hook run with+# the model provider on a closed port. No secret is used and no request+# needs to leave the runner.+#+# Every CLI runs in a scratch HOME / CLAUDE_CONFIG_DIR / CODEX_HOME.+on:+ pull_request:+ paths:+ - "plugins/**"+ - ".claude-plugin/**"+ - ".agents/plugins/**"+ - "crates/ai-memory-cli/templates/plugin/**"+ - "crates/ai-memory-cli/src/commands/render_plugins.rs"+ - "crates/ai-memory-cli/src/commands/render_shared.rs"+ - "crates/ai-memory-cli/src/commands/plugin_origin.rs"+ - "crates/ai-memory-cli/src/commands/hook.rs"+ - "crates/ai-memory-core/src/routing_skills/**"+ - "crates/ai-memory-core/src/routing_skills.rs"+ - "tests/hooks/test_plugin_launcher.sh"+ - "tests/e2e/claude_plugin_smoke.py"+ - "tests/e2e/codex_plugin_smoke.py"+ - "bin/ai-memory"+ - "bin/release"+ - ".github/workflows/plugins.yml"+ push:+ branches: [main]+ paths:+ - "plugins/**"+ - ".claude-plugin/**"+ - ".agents/plugins/**"+ - ".github/workflows/plugins.yml"+ workflow_dispatch:++env:+ CARGO_TERM_COLOR: always+ # Pinned harness CLIs: a new release is adopted deliberately, after its+ # plugin behaviour is re-checked.+ CLAUDE_CODE_VERSION: "2.1.296"+ CODEX_VERSION: "0.162.1"++permissions:+ contents: read++concurrency:+ group: plugins-${{ github.event.pull_request.number || github.sha }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}++jobs:+ validate:+ name: claude plugin validate+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0+ with:+ node-version: "24"+ - name: Install the pinned Claude Code CLI+ run: npm install --global --no-fund --no-audit "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}"+ - name: Validate the catalog and the Claude Code plugin+ env:+ DISABLE_AUTOUPDATER: "1"+ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1"+ run: |+ set -euo pipefail+ export HOME="$RUNNER_TEMP/home" CLAUDE_CONFIG_DIR="$RUNNER_TEMP/home/.claude"+ mkdir -p "$CLAUDE_CONFIG_DIR"+ claude plugin validate --strict .+ claude plugin validate --strict plugins/claude-code++ launcher:+ name: launcher (shellcheck + tests)+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ # shellcheck ships on the ubuntu runner image.+ - run: |+ shellcheck -s sh \+ crates/ai-memory-cli/templates/plugin/ai-memory-hook.sh \+ plugins/claude-code/scripts/ai-memory-hook \+ plugins/codex/scripts/ai-memory-hook \+ tests/hooks/test_plugin_launcher.sh+ - run: sh tests/hooks/test_plugin_launcher.sh++ e2e:+ name: sandboxed Claude Code and Codex runs+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ - uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable+ - uses: Swatinem/rust-cache@f0d9c3887740aee45f6153b24b3a6b815192ec16 # v2+ - run: cargo build --locked --bin ai-memory+ # The full drift test runs in ci.yml; this cheap check keeps a push to+ # main (where ci.yml's PR gate did not run) honest too.+ - name: Committed plugins equal the renderer output+ run: |+ set -euo pipefail+ target/debug/ai-memory render-plugins --out .+ git status --porcelain -- plugins .claude-plugin .agents+ test -z "$(git status --porcelain -- plugins .claude-plugin .agents)"+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0+ with:+ node-version: "24"+ - name: Install the pinned Claude Code and Codex CLIs+ run: |+ npm install --global --no-fund --no-audit \+ "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" "@openai/codex@${CODEX_VERSION}"+ - uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0+ with:+ enable-cache: false+ - name: Claude Code plugin hooks fire into a scratch server+ run: >+ uv run --no-project python tests/e2e/claude_plugin_smoke.py+ --ai-memory-bin "${{ github.workspace }}/target/debug/ai-memory"+ --plugin-dir plugins/claude-code+ --repo-root .+ - name: Codex plugin installs, and trusted hooks fire+ run: >+ uv run --no-project python tests/e2e/codex_plugin_smoke.py+ --ai-memory-bin "${{ github.workspace }}/target/debug/ai-memory"+ --repo-root .diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex c3fa6412..c692a0ef 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -57,6 +57,23 @@ jobs:echo "tag version v${tag_version} does not match Cargo.toml version ${manifest_version}" >&2exit 1fi+ # bin/release re-renders the marketplace plugins with the bump, so+ # the tag's catalogs point at the tag itself (#1166).+ for manifest in plugins/claude-code/.claude-plugin/plugin.json plugins/codex/.codex-plugin/plugin.json; do+ plugin_version="$(jq -r .version "$manifest")"+ if [ "$plugin_version" != "$tag_version" ]; then+ echo "$manifest has version ${plugin_version}, expected ${tag_version}; re-run render-plugins" >&2+ exit 1+ fi+ done+ for catalog in .claude-plugin/marketplace.json .agents/plugins/marketplace.json; do+ for ref in $(jq -r '.plugins[].source.ref' "$catalog"); do+ if [ "$ref" != "v${tag_version}" ]; then+ echo "$catalog points at ${ref}, expected v${tag_version}; re-run render-plugins" >&2+ exit 1+ fi+ done+ doneecho "version=${tag_version}" >> "$GITHUB_OUTPUT"binary:@@ -525,6 +542,17 @@ jobs:sha256sum ai-memory-hooks.tar.gz > ai-memory-hooks.tar.gz.sha256)+ # For Customize > Plugins > Upload plugin in the Claude desktop app and+ # Cowork: the plugin directory itself, launcher mode included.+ - name: Stage the Claude Code plugin zip+ run: |+ set -euo pipefail+ (cd plugins/claude-code && zip -qrX "$GITHUB_WORKSPACE/artifacts/ai-memory-claude-plugin.zip" .)+ (+ cd artifacts+ sha256sum ai-memory-claude-plugin.zip > ai-memory-claude-plugin.zip.sha256+ )+- name: Stage checksum-verified install scriptrun: |set -euo pipefaildiff --git a/bin/release b/bin/releaseindex 7f8980d9..c44d075c 100755--- a/bin/release+++ b/bin/release@@ -11,12 +11,15 @@# 3. Runs cargo-deny and cargo-audit (warn-only — a known advisory should# not block a release; the operator reviews the output).# 4. Updates [workspace.package] version in Cargo.toml.-# 5. Moves CHANGELOG.md [Unreleased] entries to a new [X.Y.Z] section+# 5. Re-renders the marketplace plugins (plugins/, .claude-plugin/,+# .agents/plugins/) so every plugin version is X.Y.Z and every catalog+# entry points at the vX.Y.Z tag this release creates.+# 6. Moves CHANGELOG.md [Unreleased] entries to a new [X.Y.Z] section# dated today.-# 6. Commits both files as "release: vX.Y.Z".-# 7. Creates an annotated git tag vX.Y.Z whose message is the changelog+# 7. Commits those files as "release: vX.Y.Z".+# 8. Creates an annotated git tag vX.Y.Z whose message is the changelog# entry for this version.-# 8. Prints next-step instructions: push the commit + tag, then deploy.+# 9. Prints next-step instructions: push the commit + tag, then deploy.## The script intentionally does NOT push to git remote or to Docker Hub.# Releases are operator-driven: review the tag locally before pushing.@@ -122,6 +125,14 @@ PYEOFecho "==> Syncing Cargo.lock"cargo update --workspace --offline 2>/dev/null || cargo update --workspace+# ── re-render the marketplace plugins ──────────────────────────────────────++# The renderer stamps the binary's own version, so it runs from a build of+# the bumped tree. The tag then carries catalogs that point at itself and+# nothing has to be pushed after the release (#1166).+echo "==> Re-rendering the marketplace plugins for ${VERSION}"+cargo run --quiet --locked --bin ai-memory -- render-plugins --out "$REPO_ROOT"+# ── update CHANGELOG.md ────────────────────────────────────────────────────echo "==> Updating CHANGELOG.md"@@ -181,7 +192,8 @@ fi# ── commit + tag ───────────────────────────────────────────────────────────echo "==> Committing release files"-git add "$CARGO_TOML" "$CHANGELOG" Cargo.lock+git add "$CARGO_TOML" "$CHANGELOG" Cargo.lock \+ "$REPO_ROOT/plugins" "$REPO_ROOT/.claude-plugin" "$REPO_ROOT/.agents/plugins"git commit -m "release: ${TAG}"echo "==> Extracting changelog entry for tag message"diff --git a/crates/ai-memory-cli/templates/plugin/ai-memory-hook.sh b/crates/ai-memory-cli/templates/plugin/ai-memory-hook.shindex 269bad94..7f7742ae 100644--- a/crates/ai-memory-cli/templates/plugin/ai-memory-hook.sh+++ b/crates/ai-memory-cli/templates/plugin/ai-memory-hook.sh@@ -16,6 +16,8 @@ event="${2:-}"reply_without_binary() {cat >/dev/nullif [ "$event" = "session-start" ]; then+ # The backticks are literal Markdown in the message, not a command.+ # shellcheck disable=SC2016printf '%s\n' '{"systemMessage":"ai-memory: the ai-memory binary was not found, so this session is not captured. Install it and run `ai-memory setup`: https://github.com/akitaonrails/ai-memory#install"}'elseprintf '{}\n'diff --git a/plugins/claude-code/scripts/ai-memory-hook b/plugins/claude-code/scripts/ai-memory-hookindex 269bad94..7f7742ae 100755--- a/plugins/claude-code/scripts/ai-memory-hook+++ b/plugins/claude-code/scripts/ai-memory-hook@@ -16,6 +16,8 @@ event="${2:-}"reply_without_binary() {cat >/dev/nullif [ "$event" = "session-start" ]; then+ # The backticks are literal Markdown in the message, not a command.+ # shellcheck disable=SC2016printf '%s\n' '{"systemMessage":"ai-memory: the ai-memory binary was not found, so this session is not captured. Install it and run `ai-memory setup`: https://github.com/akitaonrails/ai-memory#install"}'elseprintf '{}\n'diff --git a/plugins/codex/scripts/ai-memory-hook b/plugins/codex/scripts/ai-memory-hookindex 269bad94..7f7742ae 100755--- a/plugins/codex/scripts/ai-memory-hook+++ b/plugins/codex/scripts/ai-memory-hook@@ -16,6 +16,8 @@ event="${2:-}"reply_without_binary() {cat >/dev/nullif [ "$event" = "session-start" ]; then+ # The backticks are literal Markdown in the message, not a command.+ # shellcheck disable=SC2016printf '%s\n' '{"systemMessage":"ai-memory: the ai-memory binary was not found, so this session is not captured. Install it and run `ai-memory setup`: https://github.com/akitaonrails/ai-memory#install"}'elseprintf '{}\n'diff --git a/tests/e2e/claude_plugin_smoke.py b/tests/e2e/claude_plugin_smoke.pyindex 698134f2..3179e839 100644--- a/tests/e2e/claude_plugin_smoke.py+++ b/tests/e2e/claude_plugin_smoke.py@@ -88,6 +88,9 @@ class Sandbox:"LANG": "C.UTF-8","TERM": "dumb","CLAUDE_CONFIG_DIR": str(self.claude_dir),+ # No update checks or other background traffic from the CLI.+ "DISABLE_AUTOUPDATER": "1",+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",}env.update(extra)return envdiff --git a/tests/hooks/test_plugin_launcher.sh b/tests/hooks/test_plugin_launcher.shnew file mode 100755index 00000000..80b43a07--- /dev/null+++ b/tests/hooks/test_plugin_launcher.sh@@ -0,0 +1,150 @@+#!/bin/sh+# Tests for the marketplace plugin launcher (plugins/*/scripts/ai-memory-hook,+# rendered from crates/ai-memory-cli/templates/plugin/ai-memory-hook.sh).+# Run from the repo root:+#+# sh tests/hooks/test_plugin_launcher.sh+#+# A stub `ai-memory` records the argv, the origin variable and stdin it is+# handed, so these tests cover only the launcher: binary discovery, option+# precedence, the missing-binary path, the foreign-harness guard and the+# argument order the Docker wrapper relies on. What the real binary does+# with the event is covered by the CLI suite (tests/suite/plugins.rs).+# POSIX shell only; nothing leaves the temp directory.+set -eu++ROOT=$(cd "$(dirname "$0")/../.." && pwd)+LAUNCHER="$ROOT/plugins/claude-code/scripts/ai-memory-hook"+PASS=0+FAIL=0+TMP=$(mktemp -d)+trap 'rm -rf "$TMP"' EXIT++assert_eq() {+ desc="$1"; want="$2"; got="$3"+ if [ "$want" = "$got" ]; then+ PASS=$((PASS+1))+ printf ' ok %s\n' "$desc"+ else+ FAIL=$((FAIL+1))+ printf ' FAIL %s\n want=%s\n got =%s\n' "$desc" "$want" "$got"+ fi+}++# The stub binary: one argv element per line, then the origin and stdin.+STUB_DIR="$TMP/stub-bin"+mkdir -p "$STUB_DIR"+cat >"$STUB_DIR/ai-memory" <<EOF+#!/bin/sh+for arg in "\$@"; do printf '%s\n' "\$arg"; done >"$TMP/argv"+printf '%s' "\${AI_MEMORY_HOOK_ORIGIN:-}" >"$TMP/origin"+cat >"$TMP/stdin"+printf '{}\n'+EOF+chmod +x "$STUB_DIR/ai-memory"++# A sandboxed environment: no inherited plugin variables, a HOME with no+# ai-memory, and a PATH holding only the system tools unless a test adds one.+run_launcher() {+ rm -f "$TMP/argv" "$TMP/origin" "$TMP/stdin"+ env -i HOME="$TMP/home" PATH="${TEST_PATH:-/usr/bin:/bin}" "$@"+}++mkdir -p "$TMP/home"+PLUGIN_ROOT_DIR="$ROOT/plugins/claude-code"++# --- missing binary ---------------------------------------------------+# The launcher also looks in the system install locations, so a machine with+# ai-memory installed there cannot run the missing-binary cases.+SYSTEM_BIN=""+for candidate in /opt/homebrew/bin/ai-memory /usr/local/bin/ai-memory /usr/bin/ai-memory; do+ if [ -x "$candidate" ]; then SYSTEM_BIN="$candidate"; fi+done+if [ -n "$SYSTEM_BIN" ]; then+ printf ' skip missing-binary cases: %s exists\n' "$SYSTEM_BIN"+else+ out=$(printf '{"cwd":"/x"}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$TMP/missing" sh "$LAUNCHER" claude-code session-start)+ case "$out" in+ *'"systemMessage"'*'binary was not found'*) PASS=$((PASS+1)); printf ' ok %s\n' "session-start without a binary prints guidance" ;;+ *) FAIL=$((FAIL+1)); printf ' FAIL session-start guidance: %s\n' "$out" ;;+ esac+ out=$(printf '{}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" sh "$LAUNCHER" claude-code pre-tool-use)+ assert_eq "other events without a binary print {}" "{}" "$out"+ printf '{}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" sh "$LAUNCHER" claude-code stop >/dev/null+ assert_eq "exit status is 0 without a binary" "0" "$?"+ # More than a pipe buffer: a launcher that exits without reading would kill+ # the writer with SIGPIPE, and an agent writing the payload sees an error.+ rm -f "$TMP/writer-done"+ { head -c 300000 /dev/zero && : >"$TMP/writer-done"; } |+ run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" sh "$LAUNCHER" claude-code post-tool-use >/dev/null+ assert_eq "stdin is drained without a binary" "yes" "$([ -f "$TMP/writer-done" ] && echo yes || echo no)"+fi++# --- binary discovery and option precedence ---------------------------+printf '{"prompt":"p"}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$STUB_DIR/ai-memory" \+ CLAUDE_PLUGIN_OPTION_SERVER_URL="http://memory.example:1" \+ CLAUDE_PLUGIN_OPTION_DATA_DIR="/data dir" \+ sh "$LAUNCHER" claude-code user-prompt-submit >/dev/null+assert_eq "the subcommand comes first (Docker wrapper routing)" "hook" "$(head -n 1 "$TMP/argv")"+assert_eq "argv carries event, agent, server and data dir" \+ "hook|--event|user-prompt-submit|--agent|claude-code|--server-url|http://memory.example:1|--data-dir|/data dir" \+ "$(paste -sd '|' "$TMP/argv")"+assert_eq "the origin marks a plugin event" "claude-code-plugin" "$(cat "$TMP/origin")"+assert_eq "stdin reaches the binary unchanged" '{"prompt":"p"}' "$(cat "$TMP/stdin")"++printf '{}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$STUB_DIR/ai-memory" \+ sh "$LAUNCHER" claude-code stop >/dev/null+assert_eq "an unset server option passes an empty URL (the config decides)" \+ "hook|--event|stop|--agent|claude-code|--server-url|" "$(paste -sd '|' "$TMP/argv")"++printf '{}' | TEST_PATH="$STUB_DIR:/usr/bin:/bin" run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="ai-memory" sh "$LAUNCHER" claude-code stop >/dev/null+assert_eq "the default bin option resolves through PATH" "hook" "$(head -n 1 "$TMP/argv" 2>/dev/null || true)"++mkdir -p "$TMP/home/.local/bin"+cp "$STUB_DIR/ai-memory" "$TMP/home/.local/bin/ai-memory"+printf '{}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" sh "$LAUNCHER" claude-code stop >/dev/null+assert_eq "off PATH, ~/.local/bin/ai-memory is found (GUI-launched apps)" "hook" "$(head -n 1 "$TMP/argv" 2>/dev/null || true)"+rm -f "$TMP/home/.local/bin/ai-memory"++# --- foreign harnesses reading the Claude plugin ------------------------+printf '{}' | run_launcher DROID_PLUGIN_ROOT="$TMP" CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$STUB_DIR/ai-memory" sh "$LAUNCHER" claude-code stop >/dev/null+assert_eq "Droid is attributed to droid" "droid" "$(sed -n 5p "$TMP/argv")"+printf '{}' | run_launcher PLUGIN_ROOT="$TMP" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$STUB_DIR/ai-memory" sh "$LAUNCHER" claude-code stop >/dev/null+assert_eq "Codex reading the Claude plugin is attributed to codex" "codex" "$(sed -n 5p "$TMP/argv")"+out=$(printf '{}' | run_launcher CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$STUB_DIR/ai-memory" \+ sh "$LAUNCHER" claude-code stop)+assert_eq "an unknown host gets {}" "{}" "$out"+assert_eq "an unknown host never reaches the binary" "no" "$([ -f "$TMP/argv" ] && echo yes || echo no)"++# The Codex plugin's own launcher call is not second-guessed.+printf '{}' | run_launcher PLUGIN_ROOT="$ROOT/plugins/codex" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$STUB_DIR/ai-memory" \+ sh "$ROOT/plugins/codex/scripts/ai-memory-hook" codex session-start >/dev/null+assert_eq "the Codex plugin reports agent codex" "codex" "$(sed -n 5p "$TMP/argv")"+assert_eq "the Codex plugin marks its origin" "codex-plugin" "$(cat "$TMP/origin")"++out=$(printf '{}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" sh "$LAUNCHER" "" "")+assert_eq "missing arguments get {}" "{}" "$out"++# --- cost -------------------------------------------------------------+# Twenty missing-binary runs: the path a machine without ai-memory pays on+# every tool call. Whole seconds only in POSIX sh, so the bound is loose.+# An explicit missing path keeps this off any system install.+start=$(date +%s)+i=0+while [ "$i" -lt 20 ]; do+ printf '{}' | run_launcher CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT_DIR" \+ CLAUDE_PLUGIN_OPTION_AI_MEMORY_BIN="$TMP/missing" sh "$LAUNCHER" claude-code pre-tool-use >/dev/null+ i=$((i+1))+done+elapsed=$(( $(date +%s) - start ))+assert_eq "twenty missing-binary runs take under 3s" "yes" "$([ "$elapsed" -lt 3 ] && echo yes || echo no)"++printf '\n%d passed, %d failed\n' "$PASS" "$FAIL"+[ "$FAIL" -eq 0 ]