Combined from three feature branches: - feature/hw-probe-agent-bootstrap: JSON hardware probe (clawdie-hw-probe), remove desktop icon, update START-HERE.txt - chore/0.12.0-model-fix-bump: deepseek-v4-pro model names, version 0.12.0 - feature/mother-mcp-infra: build-colibri.sh MCP tool, colibri-mcp-ssh wrapper
68 lines
2.8 KiB
Bash
Executable file
68 lines
2.8 KiB
Bash
Executable file
#!/bin/sh
|
|
# build-colibri MCP tool — build a colibri crate from any git branch.
|
|
#
|
|
# Accepts a JSON-RPC tools/call request on stdin, builds the requested
|
|
# crate, and returns the result as a JSON content block to stdout.
|
|
#
|
|
# Expected input (MCP tools/call):
|
|
# {"jsonrpc":"2.0","method":"tools/call","id":1,"params":{"name":"build_colibri","arguments":{"crate":"colibri-daemon","branch":"main","features":"","release":"true"}}}
|
|
#
|
|
# Parameters:
|
|
# crate — workspace member to build (default: colibri-daemon)
|
|
# branch — git branch/ref to check out (default: main)
|
|
# features — optional comma-separated features
|
|
# release — "true" for --release, anything else for debug (default: true)
|
|
#
|
|
# Output: MCP JSON-RPC response with text content block
|
|
# {"success":true,"binary":"/home/clawdie/ai/colibri/target/release/colibri-daemon","duration_s":25.4,"branch":"main","commit":"abc1234"}
|
|
# or
|
|
# {"success":false,"error":"build failed: ..."}
|
|
set -eu
|
|
|
|
REPO="/home/clawdie/ai/colibri"
|
|
CRATE_DEFAULT="colibri-daemon"
|
|
BRANCH_DEFAULT="main"
|
|
|
|
# Read JSON from stdin, extract arguments
|
|
INPUT=$(cat)
|
|
CRATE=$(echo "$INPUT" | jq -r '.params.arguments.crate // "'"$CRATE_DEFAULT"'"')
|
|
BRANCH=$(echo "$INPUT" | jq -r '.params.arguments.branch // "'"$BRANCH_DEFAULT"'"')
|
|
FEATURES=$(echo "$INPUT" | jq -r '.params.arguments.features // ""')
|
|
RELEASE=$(echo "$INPUT" | jq -r '.params.arguments.release // "true"')
|
|
ID=$(echo "$INPUT" | jq -r '.id // "1"')
|
|
|
|
# Build flags
|
|
CARGO_FLAGS=""
|
|
if [ "$RELEASE" = "true" ]; then
|
|
CARGO_FLAGS="--release"
|
|
fi
|
|
if [ -n "$FEATURES" ]; then
|
|
CARGO_FLAGS="$CARGO_FLAGS --features $FEATURES"
|
|
fi
|
|
|
|
START_TS=$(date +%s)
|
|
|
|
# Fetch and checkout
|
|
cd "$REPO"
|
|
git fetch origin 2>&1 || true
|
|
if ! git checkout "$BRANCH" 2>&1; then
|
|
printf '{"jsonrpc":"2.0","id":%s,"error":{"code":-1,"message":"git checkout failed: %s"}}\n' "$ID" "$BRANCH"
|
|
exit 1
|
|
fi
|
|
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
|
|
# Build
|
|
BUILD_LOG=$(mktemp)
|
|
if cargo build $CARGO_FLAGS -p "$CRATE" >"$BUILD_LOG" 2>&1; then
|
|
DURATION=$(( $(date +%s) - START_TS ))
|
|
BINARY=$(find target -maxdepth 3 -type f -name "$CRATE" -perm -111 | grep -v deps | head -1)
|
|
SIZE=$(stat -f '%z' "$BINARY" 2>/dev/null || echo "0")
|
|
cat "$BUILD_LOG" | tail -5 >&2 # send tail to stderr for logging
|
|
printf '{"jsonrpc":"2.0","id":%s,"result":{"content":[{"type":"text","text":"{\\"success\\":true,\\"binary\\":\\"%s\\",\\"duration_s\\":%s,\\"branch\\":\\"%s\\",\\"commit\\":\\"%s\\",\\"size_bytes\\":%s}"}]}}\n' \
|
|
"$ID" "$BINARY" "$DURATION" "$BRANCH" "$COMMIT" "$SIZE"
|
|
else
|
|
DURATION=$(( $(date +%s) - START_TS ))
|
|
ERROR=$(tail -20 "$BUILD_LOG" | head -10 | tr '\n' ' ' | sed 's/"/\\"/g')
|
|
printf '{"jsonrpc":"2.0","id":%s,"error":{"code":-1,"message":"build failed in %ss: %s"}}\n' "$ID" "$DURATION" "$ERROR"
|
|
fi
|
|
rm -f "$BUILD_LOG"
|