From b7a9add89c8921af322ee5841f130f978989aee0 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sat, 4 Apr 2026 22:10:25 -0700 Subject: [PATCH] feat: shared routing config reader for cross-runtime skill routing New bin/gstack-routing-config with check and read commands. Reads from ~/.gstack/routing.yaml (shared config) or falls back to ## Skill routing section in CLAUDE.md/AGENTS.md. Both runtimes use the same routing table. Co-Authored-By: Claude Opus 4.6 (1M context) --- bin/gstack-routing-config | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 bin/gstack-routing-config diff --git a/bin/gstack-routing-config b/bin/gstack-routing-config new file mode 100755 index 00000000..7d89700f --- /dev/null +++ b/bin/gstack-routing-config @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# gstack-routing-config — read shared routing config for cross-runtime skill routing +# Usage: gstack-routing-config [check|read] +# +# check: exits 0 if routing config exists, 1 if not +# read: outputs routing rules as structured text +# +# Reads from ~/.gstack/routing.yaml (shared between gstack + OpenClaw). +# Falls back to CLAUDE.md/AGENTS.md "## Skill routing" section. +set -euo pipefail + +GSTACK_HOME="${GSTACK_HOME:-$HOME/.gstack}" +ROUTING_FILE="$GSTACK_HOME/routing.yaml" +CMD="${1:-check}" + +case "$CMD" in + check) + if [ -f "$ROUTING_FILE" ]; then + echo "ROUTING_CONFIG: $ROUTING_FILE" + exit 0 + fi + # Fallback: check CLAUDE.md or AGENTS.md + for f in CLAUDE.md AGENTS.md; do + if [ -f "$f" ] && grep -q "## Skill routing" "$f" 2>/dev/null; then + echo "ROUTING_CONFIG: $f (embedded)" + exit 0 + fi + done + echo "NO_ROUTING_CONFIG" + exit 1 + ;; + + read) + if [ -f "$ROUTING_FILE" ]; then + cat "$ROUTING_FILE" + exit 0 + fi + # Fallback: extract routing section from CLAUDE.md or AGENTS.md + for f in CLAUDE.md AGENTS.md; do + if [ -f "$f" ] && grep -q "## Skill routing" "$f" 2>/dev/null; then + # Extract from "## Skill routing" to next "## " heading or EOF + bun -e " + const text = await Bun.file('$f').text(); + const start = text.indexOf('## Skill routing'); + if (start === -1) process.exit(1); + const rest = text.slice(start); + const end = rest.indexOf('\n## ', 1); + console.log(end > 0 ? rest.slice(0, end).trim() : rest.trim()); + " 2>/dev/null || true + exit 0 + fi + done + echo "NO_ROUTING_CONFIG" + exit 1 + ;; + + *) + echo "Usage: gstack-routing-config [check|read]" >&2 + exit 1 + ;; +esac