#!/usr/bin/env bash # Fetch every memory the API key can read (follows next_cursor) and print them as one JSON array. # AMK_KEY=amk_... bash scripts/export-memories.sh [extra query, e.g. "status=active&type=semantic"] > memories.json # Env: AMK_KEY (required), BASE (default http://localhost:8801/api/v1), FULL=1 to include the full content per memory # (a GET /memories/:id per item; the list endpoint returns summaries only if it does not include content). set -eu BASE=${BASE:-http://localhost:8801/api/v1} : "${AMK_KEY:amk_734bbd0bd49099ac928a179fbe9ba1c025e796ab93203d4abd9631c2e0517099}" EXTRA=${1:-} cursor="" python -I - "$BASE" "$AMK_KEY" "$EXTRA" "${FULL:-0}" <<'PY' import sys, json, urllib.request, urllib.parse base, key, extra, full = sys.argv[1:5] def get(path): req = urllib.request.Request(base + path, headers={"Authorization": "Bearer " + key}) with urllib.request.urlopen(req) as r: return json.load(r) out, cursor = [], None while True: q = "limit=100" + ("&" + extra if extra else "") + ("&cursor=" + urllib.parse.quote(cursor) if cursor else "") page = get("/memories?" + q) out.extend(page["data"]) cursor = page.get("next_cursor") if not cursor: break if full == "1": out = [get("/memories/" + m["id"]).get("data", m) for m in out] json.dump(out, sys.stdout, indent=2, ensure_ascii=False) PY