mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-10 19:33:37 +08:00
merge: dmux worktree (selective install, orchestration, observer fixes)
This commit is contained in:
@@ -33,15 +33,6 @@ resolve_python_cmd() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# FIX: Windows Git Bash — probe Python install paths directly because
|
||||
# `command -v python` can hit the Microsoft Store alias instead.
|
||||
for win_py in /c/Users/"$USER"/AppData/Local/Programs/Python/Python3*/python; do
|
||||
if [ -x "$win_py" ]; then
|
||||
printf '%s\n' "$win_py"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
printf '%s\n' python3
|
||||
return 0
|
||||
@@ -83,62 +74,44 @@ if [ -n "$STDIN_CWD" ] && [ -d "$STDIN_CWD" ]; then
|
||||
fi
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# Configuration
|
||||
# Lightweight config and automated session guards
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
CONFIG_DIR="${HOME}/.claude/homunculus"
|
||||
MAX_FILE_SIZE_MB=10
|
||||
|
||||
# Skip if disabled globally
|
||||
# Skip if disabled
|
||||
if [ -f "$CONFIG_DIR/disabled" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# Automated session guards
|
||||
# Prevents observe.sh from firing on non-human sessions to avoid:
|
||||
# Prevent observe.sh from firing on non-human sessions to avoid:
|
||||
# - ECC observing its own Haiku observer sessions (self-loop)
|
||||
# - ECC observing other tools' automated sessions (e.g. claude-mem)
|
||||
# - All-night Haiku usage with no human activity
|
||||
# Run these before project detection so skipped sessions cannot mutate
|
||||
# project-scoped observer state.
|
||||
# ─────────────────────────────────────────────
|
||||
# - ECC observing other tools' automated sessions
|
||||
# - automated sessions creating project-scoped homunculus metadata
|
||||
|
||||
# Env-var checks first (cheapest — no subprocess spawning):
|
||||
|
||||
# Layer 1: CLAUDE_CODE_ENTRYPOINT — set by Claude Code itself to indicate how
|
||||
# it was invoked. Only interactive terminal sessions should continue; treat any
|
||||
# explicit non-cli entrypoint as automated so future entrypoint types fail closed
|
||||
# without requiring updates here.
|
||||
# Layer 1: entrypoint. Only interactive terminal sessions should continue.
|
||||
case "${CLAUDE_CODE_ENTRYPOINT:-cli}" in
|
||||
cli) ;;
|
||||
*) exit 0 ;;
|
||||
esac
|
||||
|
||||
# Layer 2: Respect ECC_HOOK_PROFILE=minimal — suppresses non-essential hooks
|
||||
# Layer 2: minimal hook profile suppresses non-essential hooks.
|
||||
[ "${ECC_HOOK_PROFILE:-standard}" = "minimal" ] && exit 0
|
||||
|
||||
# Layer 3: Cooperative skip env var — tools like claude-mem can set this
|
||||
# (export ECC_SKIP_OBSERVE=1) before spawning their automated sessions
|
||||
# Layer 3: cooperative skip env var for automated sessions.
|
||||
[ "${ECC_SKIP_OBSERVE:-0}" = "1" ] && exit 0
|
||||
|
||||
# Layer 4: Skip subagent sessions — agent_id is only present when a hook fires
|
||||
# inside a subagent (automated by definition, never a human interactive session).
|
||||
# Placed after env-var checks to avoid a Python subprocess on sessions that
|
||||
# already exit via Layers 1-3.
|
||||
# Layer 4: subagent sessions are automated by definition.
|
||||
_ECC_AGENT_ID=$(echo "$INPUT_JSON" | "$PYTHON_CMD" -c "import json,sys; print(json.load(sys.stdin).get('agent_id',''))" 2>/dev/null || true)
|
||||
[ -n "$_ECC_AGENT_ID" ] && exit 0
|
||||
|
||||
# Layer 5: CWD path exclusions — skip known observer-session directories.
|
||||
# Add custom paths via ECC_OBSERVE_SKIP_PATHS (comma-separated substrings).
|
||||
# Whitespace is trimmed from each pattern; empty patterns are skipped to
|
||||
# prevent an empty-string glob from matching every path.
|
||||
# Layer 5: known observer-session path exclusions.
|
||||
_ECC_SKIP_PATHS="${ECC_OBSERVE_SKIP_PATHS:-observer-sessions,.claude-mem}"
|
||||
if [ -n "$STDIN_CWD" ]; then
|
||||
IFS=',' read -ra _ECC_SKIP_ARRAY <<< "$_ECC_SKIP_PATHS"
|
||||
for _pattern in "${_ECC_SKIP_ARRAY[@]}"; do
|
||||
_pattern="${_pattern#"${_pattern%%[![:space:]]*}"}" # trim leading whitespace
|
||||
_pattern="${_pattern%"${_pattern##*[![:space:]]}"}" # trim trailing whitespace
|
||||
_pattern="${_pattern#"${_pattern%%[![:space:]]*}"}"
|
||||
_pattern="${_pattern%"${_pattern##*[![:space:]]}"}"
|
||||
[ -z "$_pattern" ] && continue
|
||||
case "$STDIN_CWD" in *"$_pattern"*) exit 0 ;; esac
|
||||
done
|
||||
@@ -156,20 +129,12 @@ SKILL_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
source "${SKILL_ROOT}/scripts/detect-project.sh"
|
||||
PYTHON_CMD="${CLV2_PYTHON_CMD:-$PYTHON_CMD}"
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# Configuration
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
OBSERVATIONS_FILE="${PROJECT_DIR}/observations.jsonl"
|
||||
|
||||
SENTINEL_FILE="${CLV2_OBSERVER_SENTINEL_FILE:-${PROJECT_ROOT:-$PROJECT_DIR}/.observer.lock}"
|
||||
|
||||
write_guard_sentinel() {
|
||||
printf '%s\n' 'observer paused: confirmation or permission prompt detected; rerun start-observer.sh --reset after reviewing observer.log' > "$SENTINEL_FILE"
|
||||
}
|
||||
|
||||
# Skip if a previous run already aborted due to confirmation/permission prompt.
|
||||
# This is the circuit-breaker — stops retrying after a non-interactive failure.
|
||||
if [ -f "$SENTINEL_FILE" ]; then
|
||||
echo "[observe] Skipping: previous run aborted due to confirmation/permission prompt. Remove ${SENTINEL_FILE} to re-enable." >&2
|
||||
exit 0
|
||||
fi
|
||||
MAX_FILE_SIZE_MB=10
|
||||
|
||||
# Auto-purge observation files older than 30 days (runs once per session)
|
||||
PURGE_MARKER="${PROJECT_DIR}/.last-purge"
|
||||
@@ -263,46 +228,46 @@ if [ -f "$OBSERVATIONS_FILE" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect confirmation/permission prompts in observer output and fail closed.
|
||||
# A non-interactive background observer must never ask for user confirmation.
|
||||
if echo "$PARSED" | grep -E -i -q "$CLV2_OBSERVER_PROMPT_PATTERN"; then
|
||||
echo "[observe] OBSERVER_ABORT: Confirmation or permission prompt detected in observer output. This observer run is non-actionable." >&2
|
||||
echo "[observe] Writing sentinel to suppress retries: ${SENTINEL_FILE}" >&2
|
||||
write_guard_sentinel
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Build and write observation (now includes project context)
|
||||
# Scrub common secret patterns from tool I/O before persisting
|
||||
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
export PROJECT_ID_ENV="$PROJECT_ID"
|
||||
export PROJECT_NAME_ENV="$PROJECT_NAME"
|
||||
export TIMESTAMP="$timestamp"
|
||||
|
||||
echo "$PARSED" | "$PYTHON_CMD" -c '
|
||||
import json, sys, os, re
|
||||
|
||||
parsed = json.load(sys.stdin)
|
||||
observation = {
|
||||
"timestamp": os.environ["TIMESTAMP"],
|
||||
"event": parsed["event"],
|
||||
"tool": parsed["tool"],
|
||||
"session": parsed["session"],
|
||||
"project_id": os.environ.get("PROJECT_ID_ENV", "global"),
|
||||
"project_name": os.environ.get("PROJECT_NAME_ENV", "global")
|
||||
"timestamp": os.environ["TIMESTAMP"],
|
||||
"event": parsed["event"],
|
||||
"tool": parsed["tool"],
|
||||
"session": parsed["session"],
|
||||
"project_id": os.environ.get("PROJECT_ID_ENV", "global"),
|
||||
"project_name": os.environ.get("PROJECT_NAME_ENV", "global")
|
||||
}
|
||||
|
||||
# Scrub secrets: match common key=value, key: value, and key"value patterns
|
||||
# Includes optional auth scheme (e.g., "Bearer", "Basic") before token
|
||||
_SECRET_RE = re.compile(
|
||||
r"(?i)(api[_-]?key|token|secret|password|authorization|credentials?|auth)"
|
||||
r"""(["'"'"'\s:=]+)"""
|
||||
r"([A-Za-z]+\s+)?"
|
||||
r"([A-Za-z0-9_\-/.+=]{8,})"
|
||||
r"(?i)(api[_-]?key|token|secret|password|authorization|credentials?|auth)"
|
||||
r"""(["'"'"'\s:=]+)"""
|
||||
r"([A-Za-z]+\s+)?"
|
||||
r"([A-Za-z0-9_\-/.+=]{8,})"
|
||||
)
|
||||
|
||||
def scrub(val):
|
||||
if val is None:
|
||||
return None
|
||||
return _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", str(val))
|
||||
if val is None:
|
||||
return None
|
||||
return _SECRET_RE.sub(lambda m: m.group(1) + m.group(2) + (m.group(3) or "") + "[REDACTED]", str(val))
|
||||
|
||||
if parsed["input"]:
|
||||
observation["input"] = scrub(parsed["input"])
|
||||
observation["input"] = scrub(parsed["input"])
|
||||
if parsed["output"] is not None:
|
||||
observation["output"] = scrub(parsed["output"])
|
||||
observation["output"] = scrub(parsed["output"])
|
||||
|
||||
print(json.dumps(observation))
|
||||
' >> "$OBSERVATIONS_FILE"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user