go-agent/codex/code/scripts/detect-module.sh
Snider 61e01bfdf1 feat: initial go-agent — agentci + jobrunner + plugins marketplace
Consolidates three codebases into a single agent orchestration repo:

- agentci (from go-scm): Clotho dual-run verification, agent config,
  SSH security (sanitisation, secure commands, token masking)
- jobrunner (from go-scm): Poll-dispatch-report pipeline with 7 handlers
  (dispatch, completion, auto-merge, publish draft, dismiss reviews,
  send fix command, tick parent epic)
- plugins marketplace (from agentic/plugins): 27 Claude/Codex/Gemini
  plugins with shared MCP server

All 150+ tests passing across 6 packages.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-21 15:47:19 +00:00

51 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
#
# Detects the current module and sets environment variables for other tools.
# Intended to be run once per session via a hook.
# --- Detection Logic ---
MODULE_NAME=""
MODULE_TYPE="unknown"
# 1. Check for composer.json (PHP)
if [ -f "composer.json" ]; then
MODULE_TYPE="php"
# Use jq, but check if it is installed first
if command -v jq >/dev/null 2>&1; then
MODULE_NAME=$(jq -r ".name // empty" composer.json)
fi
fi
# 2. Check for go.mod (Go)
if [ -f "go.mod" ]; then
MODULE_TYPE="go"
MODULE_NAME=$(grep "^module" go.mod | awk '{print $2}')
fi
# 3. If name is still empty, try git remote
if [ -z "$MODULE_NAME" ] || [ "$MODULE_NAME" = "unknown" ]; then
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
GIT_REMOTE=$(git remote get-url origin 2>/dev/null)
if [ -n "$GIT_REMOTE" ]; then
MODULE_NAME=$(basename "$GIT_REMOTE" .git)
fi
fi
fi
# 4. As a last resort, use the current directory name
if [ -z "$MODULE_NAME" ] || [ "$MODULE_NAME" = "unknown" ]; then
MODULE_NAME=$(basename "$PWD")
fi
# --- Store Context ---
# Create a file with the context variables to be sourced by other scripts.
mkdir -p .claude-plugin/.tmp
CONTEXT_FILE=".claude-plugin/.tmp/module_context.sh"
echo "export CLAUDE_CURRENT_MODULE=\"$MODULE_NAME\"" > "$CONTEXT_FILE"
echo "export CLAUDE_MODULE_TYPE=\"$MODULE_TYPE\"" >> "$CONTEXT_FILE"
# --- User-facing Message ---
# Print a confirmation message to stderr.
echo "Workspace context loaded: Module='$MODULE_NAME', Type='$MODULE_TYPE'" >&2