create-merlin-brain 3.15.1 → 3.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,11 +28,16 @@ ensure_session_file() {
|
|
|
28
28
|
|
|
29
29
|
# Core event logger — all specialized loggers call this
|
|
30
30
|
# Usage: log_event "type" '{"key":"value"}'
|
|
31
|
+
# CRITICAL: Must NEVER fail (return non-zero) because callers run under
|
|
32
|
+
# set -e and a failure here kills the entire hook before it can output
|
|
33
|
+
# its additionalContext JSON. This was the root cause of Merlin going
|
|
34
|
+
# silent — the session-start hook died inside log_event before reaching
|
|
35
|
+
# the printf that outputs the boot sequence enforcement.
|
|
31
36
|
log_event() {
|
|
32
37
|
local etype="${1:-unknown}" edata="${2:-{}}"
|
|
33
|
-
ensure_session_file || return 1
|
|
38
|
+
ensure_session_file || return 0 # was return 1 — killed callers under set -e
|
|
34
39
|
local evt
|
|
35
|
-
evt=$(printf '{"type":"%s","ts":"%s","data":%s}' "$etype" "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" "$edata")
|
|
40
|
+
evt=$(printf '{"type":"%s","ts":"%s","data":%s}' "$etype" "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" "$edata") || return 0
|
|
36
41
|
if command -v jq >/dev/null 2>&1; then
|
|
37
42
|
local tmp; tmp=$(mktemp 2>/dev/null || echo "/tmp/merlin-evt-$$")
|
|
38
43
|
jq --argjson e "$evt" '.events += [$e]' "${MERLIN_SESSION_FILE}" > "$tmp" 2>/dev/null \
|
|
@@ -40,6 +45,7 @@ log_event() {
|
|
|
40
45
|
else
|
|
41
46
|
echo "$evt" >> "${MERLIN_SESSION_FILE}.log" 2>/dev/null
|
|
42
47
|
fi
|
|
48
|
+
return 0 # never fail
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
# Specialized loggers — thin wrappers for structured events
|
|
@@ -80,14 +80,16 @@ _merlin_cleanup_stale &
|
|
|
80
80
|
AGENT_ID="${CLAUDE_AGENT_ID:-unknown}"
|
|
81
81
|
AGENT_TYPE="${CLAUDE_AGENT_TYPE:-main}"
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
# Analytics calls MUST NOT kill the script — the additionalContext output
|
|
84
|
+
# at the end is critical for Merlin enforcement. Use || true on every call.
|
|
85
|
+
ensure_session_file || true
|
|
84
86
|
cwd="${PWD:-$(pwd)}"
|
|
85
|
-
log_event "session_start" "$(printf '{"cwd":"%s","agent_id":"%s","agent_type":"%s"}' "$cwd" "$AGENT_ID" "$AGENT_TYPE")"
|
|
87
|
+
log_event "session_start" "$(printf '{"cwd":"%s","agent_id":"%s","agent_type":"%s"}' "$cwd" "$AGENT_ID" "$AGENT_TYPE")" || true
|
|
86
88
|
|
|
87
89
|
# Warm up Sights context in background
|
|
88
90
|
if command -v merlin >/dev/null 2>&1; then
|
|
89
91
|
merlin context "session start" >/dev/null 2>&1 &
|
|
90
|
-
record_sights_call
|
|
92
|
+
record_sights_call || true
|
|
91
93
|
fi
|
|
92
94
|
|
|
93
95
|
# ── 2. Agent sync (background, max once/hour) ──────────────────
|
|
@@ -184,7 +186,9 @@ _merlin_check_voice_mode() {
|
|
|
184
186
|
command -v jq >/dev/null 2>&1 || return 0
|
|
185
187
|
local voice
|
|
186
188
|
voice=$(jq -r '.voice_mode_concise // false' "${settings_file}" 2>/dev/null) || return 0
|
|
187
|
-
[
|
|
189
|
+
# CRITICAL: [ x = y ] && cmd returns 1 when false, which under set -e kills
|
|
190
|
+
# the calling script. Use if/then instead.
|
|
191
|
+
if [ "${voice}" = "true" ]; then export MERLIN_VOICE_MODE=1; fi
|
|
188
192
|
}
|
|
189
193
|
_merlin_check_voice_mode
|
|
190
194
|
|
|
@@ -25,8 +25,8 @@ if [ -n "$input" ] && command -v jq >/dev/null 2>&1; then
|
|
|
25
25
|
task_desc=$(echo "$input" | jq -r '.task // .description // empty' 2>/dev/null || true)
|
|
26
26
|
fi
|
|
27
27
|
|
|
28
|
-
# Log subagent start event
|
|
29
|
-
log_event "subagent_start" "$(printf '{"task":"%s"}' "${task_desc:-unknown}")"
|
|
28
|
+
# Log subagent start event (|| true: never kill script before additionalContext output)
|
|
29
|
+
log_event "subagent_start" "$(printf '{"task":"%s"}' "${task_desc:-unknown}")" || true
|
|
30
30
|
|
|
31
31
|
# If Merlin CLI available, fetch context for the task and output as JSON
|
|
32
32
|
if [ -n "$task_desc" ] && command -v merlin >/dev/null 2>&1; then
|
package/package.json
CHANGED