@memnexus-ai/mx-agent-cli 0.1.264 → 0.1.265
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.
- package/dist/agent-config/hooks/auto-capture-session-end.sh +82 -1
- package/dist/agent-config/hooks/ci-validate-hook.sh +77 -0
- package/dist/agent-config/hooks/coordination-midsession-drain.sh +79 -0
- package/dist/agent-config/hooks/delegation-audit.sh +79 -0
- package/dist/agent-config/hooks/deploy-verification-reminder.sh +79 -0
- package/dist/agent-config/hooks/gh-pr-edit-guard.sh +79 -0
- package/dist/agent-config/hooks/git-mutation-guard.sh +79 -0
- package/dist/agent-config/hooks/iteration-log-check.sh +79 -0
- package/dist/agent-config/hooks/memory-checkpoint-reminder.sh +79 -0
- package/dist/agent-config/hooks/mx-guard-hook.sh +77 -0
- package/dist/agent-config/hooks/named-memory-write-guard.sh +79 -0
- package/dist/agent-config/hooks/observability-sync.sh +77 -0
- package/dist/agent-config/hooks/session-idle-gate.sh +79 -0
- package/dist/agent-config/hooks/workflow-dispatch-guard.sh +77 -0
- package/dist/agent-config/hooks/worktree-guard.sh +79 -0
- package/package.json +1 -1
|
@@ -35,6 +35,85 @@
|
|
|
35
35
|
# - CLAUDE_WORKTREE_PATH: Absolute path to worktree (e.g., /workspace/.worktrees/foo)
|
|
36
36
|
# - CLAUDE_WORKTREE_NAME: Worktree name (e.g., foo)
|
|
37
37
|
|
|
38
|
+
MXHT_HOOK=worktree-guard MXHT_EVENT=PreToolUse MXHT_TOOL=Bash
|
|
39
|
+
# >>> SHARED hook-timing probe v1
|
|
40
|
+
# Diagnostic instrumentation: records how long THIS hook ran, so hook time can be
|
|
41
|
+
# separated from time spent waiting on the API when a session stalls mid-stream.
|
|
42
|
+
# Appends one line to a local, gitignored log. Read it with
|
|
43
|
+
# mx-agent-system/scripts/hook-timing-report.sh. Nothing is transmitted anywhere.
|
|
44
|
+
#
|
|
45
|
+
# FAIL SILENT IS DELIBERATE HERE, and it is the opposite of this repo's usual
|
|
46
|
+
# fail-loud direction. Do not "correct" it to fail-loud by applying the fleet
|
|
47
|
+
# default. A diagnostic that can break the gate it observes is worse than no
|
|
48
|
+
# diagnostic: an unwritable path or a full disk would otherwise take out every
|
|
49
|
+
# guard on the PreToolUse path at once. Every step below is guarded and every
|
|
50
|
+
# failure path is a silent no-op that leaves the hook's behaviour untouched.
|
|
51
|
+
#
|
|
52
|
+
# NEAR-ZERO OVERHEAD: bash builtins only on the hot path ($EPOCHREALTIME, printf
|
|
53
|
+
# -T, one read, one append). No subprocess, no network, no JSON parsing, and the
|
|
54
|
+
# hook's stdin is never touched (the hook owns it). mkdir runs at most once per
|
|
55
|
+
# worktree. Kill switch: MX_HOOK_TIMING=0.
|
|
56
|
+
MXHT_T0="${EPOCHREALTIME:-}"
|
|
57
|
+
_mxht_emit() {
|
|
58
|
+
[ -z "${MXHT_DONE:-}" ] || return 0 # an ERR trap that exits fires EXIT too
|
|
59
|
+
MXHT_DONE=1
|
|
60
|
+
[ "${MX_HOOK_TIMING:-1}" != "0" ] || return 0
|
|
61
|
+
[ -n "${MXHT_T0:-}" ] && [ -n "${EPOCHREALTIME:-}" ] || return 0
|
|
62
|
+
local root="${CLAUDE_PROJECT_DIR:-${CLAUDE_WORKTREE_PATH:-}}"
|
|
63
|
+
[ -n "$root" ] && [ -d "$root" ] || return 0
|
|
64
|
+
local dir="$root/.mx-hook-timing"
|
|
65
|
+
[ -d "$dir" ] || mkdir -p "$dir" 2>/dev/null || return 0
|
|
66
|
+
# EPOCHREALTIME is seconds.microseconds; the separator is locale-dependent, so
|
|
67
|
+
# strip both forms and subtract as plain integer microseconds.
|
|
68
|
+
local dur=-1
|
|
69
|
+
{ dur=$(( ${EPOCHREALTIME//[.,]/} - ${MXHT_T0//[.,]/} )); } 2>/dev/null
|
|
70
|
+
[ "$dur" -ge 0 ] 2>/dev/null || return 0
|
|
71
|
+
local stamp hour
|
|
72
|
+
printf -v stamp '%(%Y-%m-%d %H:%M:%S)T' -1
|
|
73
|
+
printf -v hour '%(%H)T' -1
|
|
74
|
+
# BOUNDED BY CONSTRUCTION: a 24-slot ring, one file per hour-of-day, so the log
|
|
75
|
+
# is at most 24 files each holding one hour of this machine's hook calls. The
|
|
76
|
+
# first writer into a slot on a new day truncates it instead of appending —
|
|
77
|
+
# detected by reading the slot's first line, which is a builtin read (no stat,
|
|
78
|
+
# no rm, no find, no cron). Two writers can race that truncation and lose a
|
|
79
|
+
# line or two at an hour boundary; that is acceptable for a sampling diagnostic.
|
|
80
|
+
local f="$dir/h$hour.log" first="" line
|
|
81
|
+
# THE SLOT MUST BE AN ORDINARY FILE, OR NOT EXIST YET (security review, #4848).
|
|
82
|
+
# Anything else is a silent no-op. Two concrete failures if this check is
|
|
83
|
+
# dropped: a FIFO at the slot makes the `read` below block until the hook's
|
|
84
|
+
# settings.json timeout kills it, and a PreToolUse guard killed that way loses
|
|
85
|
+
# its exit 2 — the command it meant to block then runs; a symlink at the slot
|
|
86
|
+
# sends the day-rollover truncation onto the symlink's target. The `-e || -L`
|
|
87
|
+
# wrapper is what lets a not-yet-created slot through (-e is false for a
|
|
88
|
+
# dangling symlink, so -L is needed to catch that case too).
|
|
89
|
+
if [ -e "$f" ] || [ -L "$f" ]; then
|
|
90
|
+
[ -f "$f" ] && [ ! -L "$f" ] || return 0
|
|
91
|
+
fi
|
|
92
|
+
[ -r "$f" ] && { read -r first < "$f"; } 2>/dev/null
|
|
93
|
+
printf -v line '%s dur_us=%s hook=%s event=%s ppid=%s tool=%s\n' \
|
|
94
|
+
"$stamp" "$dur" "${MXHT_HOOK:--}" "${MXHT_EVENT:--}" "$PPID" "${MXHT_TOOL:--}"
|
|
95
|
+
# One printf of ~90 bytes to an O_APPEND fd is atomic under PIPE_BUF, so
|
|
96
|
+
# concurrent hooks cannot interleave partial lines.
|
|
97
|
+
# The 2>/dev/null wraps the GROUP, not the printf: a failing redirection is
|
|
98
|
+
# reported by the shell before an inner 2>/dev/null would be in effect, and a
|
|
99
|
+
# "Permission denied" on stderr from a PreToolUse hook is surfaced to the model.
|
|
100
|
+
if [ "${first%% *}" = "${stamp%% *}" ]; then
|
|
101
|
+
{ printf '%s' "$line" >>"$f"; } 2>/dev/null
|
|
102
|
+
else
|
|
103
|
+
{ printf '%s' "$line" >"$f"; } 2>/dev/null
|
|
104
|
+
fi
|
|
105
|
+
}
|
|
106
|
+
# `|| :` IS LOAD-BEARING — do not simplify to `trap _mxht_emit EXIT`. The hooks
|
|
107
|
+
# this block is inlined into run under `set -e`, and the EXIT trap runs with
|
|
108
|
+
# errexit still in force. Without `|| :`, a non-zero return from the probe — the
|
|
109
|
+
# final printf failing on an unwritable slot is the reachable case — replaces the
|
|
110
|
+
# hook's own exit status: a PreToolUse guard's exit 2 becomes exit 1, which the
|
|
111
|
+
# harness reads as "error", not "block", so the command it meant to block runs.
|
|
112
|
+
# Pinned verbatim by hook-timing-parity.test.sh.
|
|
113
|
+
trap '_mxht_emit || :' EXIT
|
|
114
|
+
# <<< SHARED hook-timing probe v1
|
|
115
|
+
|
|
116
|
+
|
|
38
117
|
set -euo pipefail
|
|
39
118
|
|
|
40
119
|
# Read the tool input from stdin (JSON format)
|