Cotton code
35 lines · 1.6 KB · ShellRaw
#!/usr/bin/env bash# Import (or upgrade in place) one tool package into a named database over MCP.##   scripts/dev/import-tool.sh <package.cottontool|package-dir> --database <id or name>## A directory is packed first with scripts/pack-tool.mjs. The package goes to# import_tool, which upgrades a tool already installed under its id in place and# makes the package's pictures the tool's pictures (replace_pictures) — the only# way a picture's bytes reach a database, since update_definition only names a# photo the database already holds. The writer is the dev Cotton MCP client:# COTTON_MCP_URL/COTTON_MCP_TOKEN or the memory-mirror config. The token is# never printed.set -euo pipefailroot="$(cd "$(dirname "$0")/../.." && pwd)"usage="usage: scripts/dev/import-tool.sh <package.cottontool|package-dir> --database <id or name>"source="${1:?$usage}"[ "${2:-}" = --database ] && [ -n "${3:-}" ] || { echo "$usage" >&2; exit 2; }database="$3"package="$source"if [ -d "$source" ]; then  scratch="$(mktemp -d)"  trap 'rm -rf "$scratch"' EXIT  package="$scratch/$(basename "$source").cottontool"  node "$root/scripts/pack-tool.mjs" "$source" "$package" >&2fipython3 -I -c 'import base64, json, syssys.path.insert(0, sys.argv[2])from cotton_client import Clientclient = Client(sys.argv[3])with open(sys.argv[1], "rb") as package:    encoded = base64.b64encode(package.read()).decode()answer = client.call("import_tool", {"bytes": encoded, "database": client.database})print(json.dumps({"imported": answer["tool_id"], "pictures": "replaced", "database": client.database}))' "$package" "$root/scripts/dev" "$database"