refactor: modularize kugetsu shell script
Split the monolithic kugetsu script into modular components: Modules created: - kugetsu-config.sh - Config/env loading and global variables - kugetsu-index.sh - Index.json read/write via JSON - kugetsu-worktree.sh - Git worktree operations - kugetsu-log.sh - Structured logging and notifications - kugetsu-session.sh - Session create/fork/destroy logic - kugetsu-queue-daemon.sh - Queue daemon subprocess Main script (kugetsu) is now a thin dispatcher that sources all modules. Acceptance Criteria: - All existing commands work exactly as before - Main script sources modules - Each module is independently testable Fixes #116
This commit is contained in:
57
skills/kugetsu/scripts/kugetsu-config.sh
Executable file
57
skills/kugetsu/scripts/kugetsu-config.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
KUGETSU_DIR="${KUGETSU_DIR:-$HOME/.kugetsu}"
|
||||
SESSIONS_DIR="$KUGETSU_DIR/sessions"
|
||||
WORKTREES_DIR="$KUGETSU_DIR/worktrees"
|
||||
REPOS_CONFIG="$KUGETSU_DIR/repos.json"
|
||||
INDEX_FILE="$KUGETSU_DIR/index.json"
|
||||
NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json"
|
||||
LOGS_DIR="$KUGETSU_DIR/logs"
|
||||
ENV_DIR="${ENV_DIR:-$KUGETSU_DIR/env}"
|
||||
VERBOSITY_DIR="$KUGETSU_DIR/verbosity"
|
||||
|
||||
MAX_CONCURRENT_AGENTS="${MAX_CONCURRENT_AGENTS:-3}"
|
||||
KUGETSU_VERBOSITY="${KUGETSU_VERBOSITY:-default}"
|
||||
CONTEXT_DIR="${CONTEXT_DIR:-$KUGETSU_DIR/context}"
|
||||
ENABLE_CONTEXT_DUMP="${ENABLE_CONTEXT_DUMP:-true}"
|
||||
WORKTREE_CHECK_PR_STATUS="${WORKTREE_CHECK_PR_STATUS:-true}"
|
||||
|
||||
QUEUE_DIR="${QUEUE_DIR:-$KUGETSU_DIR/queue}"
|
||||
QUEUE_ITEMS_DIR="${QUEUE_ITEMS_DIR:-$QUEUE_DIR/items}"
|
||||
QUEUE_DAEMON_PID_FILE="${QUEUE_DAEMON_PID_FILE:-$QUEUE_DIR/daemon.pid}"
|
||||
QUEUE_DAEMON_LOCK_FILE="${QUEUE_DAEMON_LOCK_FILE:-$QUEUE_DIR/daemon.lock}"
|
||||
QUEUE_DAEMON_LOG_FILE="${QUEUE_DAEMON_LOG_FILE:-$QUEUE_DIR/daemon.log}"
|
||||
QUEUE_DAEMON_INTERVAL_MINUTES="${QUEUE_DAEMON_INTERVAL_MINUTES:-5}"
|
||||
QUEUE_CLEANUP_AGE_DAYS="${QUEUE_CLEANUP_AGE_DAYS:-7}"
|
||||
TASK_TIMEOUT_HOURS="${TASK_TIMEOUT_HOURS:-1}"
|
||||
|
||||
# Load user config overrides (~/.kugetsu/config)
|
||||
if [ -f "$KUGETSU_DIR/config" ]; then
|
||||
source "$KUGETSU_DIR/config"
|
||||
fi
|
||||
|
||||
mask_sensitive_vars() {
|
||||
local line="$1"
|
||||
for var in GITEA_TOKEN GITHUB_TOKEN GITLAB_TOKEN API_KEY PASSWORD TOKEN SECRET; do
|
||||
if [[ "$line" =~ $var ]]; then
|
||||
line=$(echo "$line" | sed -E "s/=.*/=***MASKED***/")
|
||||
fi
|
||||
done
|
||||
echo "$line"
|
||||
}
|
||||
|
||||
load_agent_env() {
|
||||
local agent_type="${1:-base}"
|
||||
local env_file="$ENV_DIR/${agent_type}.env"
|
||||
|
||||
if [ -f "$env_file" ]; then
|
||||
set -a
|
||||
source "$env_file"
|
||||
set +a
|
||||
elif [ -f "$ENV_DIR/default.env" ]; then
|
||||
set -a
|
||||
source "$ENV_DIR/default.env"
|
||||
set +a
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user